@@ -24,21 +24,6 @@ const jsondiffpatch = require('jsondiffpatch').create({
2424} ) ;
2525
2626
27- const Semaphore = ( n ) => ( {
28- n,
29- async down ( ) {
30- while ( this . n <= 0 ) await this . wait ( ) ;
31- this . n -- ;
32- } ,
33- up ( ) {
34- this . n ++ ;
35- } ,
36- async wait ( ) {
37- if ( this . n <= 0 ) return new Promise ( ( res , req ) => {
38- setImmediate ( async ( ) => res ( await this . wait ( ) ) )
39- } ) ;
40- } ,
41- } ) ;
4227Object . defineProperty ( Promise , 'retry' , {
4328 configurable : true ,
4429 writable : true ,
@@ -67,6 +52,7 @@ export class DatabaseConnection {
6752 public static mongodb_replace : ValueRecorder ;
6853 public static mongodb_delete : ValueRecorder ;
6954 public static mongodb_deletemany : ValueRecorder ;
55+ public static semaphore = Auth . Semaphore ( 1 ) ;
7056 constructor ( mongodburl : string , dbname : string ) {
7157 this . _dbname = dbname ;
7258 this . mongodburl = mongodburl ;
@@ -586,8 +572,8 @@ export class DatabaseConnection {
586572 const baseversion = basehist [ 0 ] . _version ;
587573 const history = await this . query < T > ( { id : id , "_version" : { $gt : baseversion , $lte : version } } , null , Config . history_delta_count , 0 , { _version : 1 } , collectionname + "_hist" , rootjwt , undefined , undefined , span ) ;
588574 for ( let delta of history ) {
589- if ( delta != null ) {
590- result = jsondiffpatch . patch ( result , delta ) ;
575+ if ( delta != null && ( delta as any ) . delta != null ) {
576+ result = jsondiffpatch . patch ( result , ( delta as any ) . delta ) ;
591577 }
592578 }
593579 }
@@ -1734,7 +1720,22 @@ export class DatabaseConnection {
17341720 Logger . otel . endSpan ( span ) ;
17351721 }
17361722 }
1737- private static InsertOrUpdateOneSemaphore = Semaphore ( 1 ) ;
1723+ public static Semaphore = ( n ) => ( {
1724+ n,
1725+ async down ( ) {
1726+ while ( this . n <= 0 ) await this . wait ( ) ;
1727+ this . n -- ;
1728+ } ,
1729+ up ( ) {
1730+ this . n ++ ;
1731+ } ,
1732+ async wait ( ) {
1733+ if ( this . n <= 0 ) return new Promise ( ( res , req ) => {
1734+ setImmediate ( async ( ) => res ( await this . wait ( ) ) )
1735+ } ) ;
1736+ } ,
1737+ } ) ;
1738+ private static InsertOrUpdateOneSemaphore = DatabaseConnection . Semaphore ( 1 ) ;
17381739 /**
17391740 * Insert or Update depending on document allready exists.
17401741 * @param {T } item Item to insert or update
@@ -2550,7 +2551,7 @@ export class DatabaseConnection {
25502551 Logger . otel . endTimer ( ot_end , DatabaseConnection . mongodb_insert , { collection : collectionname + '_hist' } ) ;
25512552 } ) ;
25522553 }
2553- if ( original != null && original . _version > 0 ) {
2554+ if ( original != null && original . _version >= 0 ) {
25542555 delta = jsondiffpatch . diff ( original , item ) ;
25552556 if ( NoderedUtil . IsNullUndefinded ( delta ) ) return 0 ;
25562557 const keys = Object . keys ( delta ) ;
0 commit comments