@memberjunction/core
Advanced tools
Comparing version 2.23.2 to 2.24.0
@@ -337,9 +337,22 @@ import { EntityFieldInfo, EntityInfo, EntityFieldTSType, EntityPermissionType, RecordChange, ValidationResult, EntityRelationshipInfo } from './entityInfo'; | ||
NewRecord(newValues?: FieldValueCollection): boolean; | ||
private _pendingSave$; | ||
/** | ||
* Saves the current state of the object to the database. Uses the active provider to handle the actual saving of the record. If the record is new, it will be created, if it already exists, it will be updated. | ||
* Saves the current state of the object to the database. Uses the active provider to handle the actual saving of the record. | ||
* If the record is new, it will be created, if it already exists, it will be updated. | ||
* | ||
* Debounces multiple calls so that if Save() is called again while a save is in progress, | ||
* the second call will simply receive the same result as the first. | ||
* | ||
* @param options | ||
* @returns | ||
* @returns Promise<boolean> | ||
*/ | ||
Save(options?: EntitySaveOptions): Promise<boolean>; | ||
/** | ||
* Private, internal method to handle saving the current state of the object to the database. This method is called by the public facing Save() method | ||
* and is debounced to prevent multiple calls from being executed simultaneously. | ||
* @param options | ||
* @returns | ||
*/ | ||
private _InnerSave; | ||
/** | ||
* Internal helper method for the class and sub-classes - used to easily get the Active User which is either the ContextCurrentUser, if defined, or the Metadata.Provider.CurrentUser if not. | ||
@@ -346,0 +359,0 @@ */ |
@@ -295,2 +295,4 @@ "use strict"; | ||
this._compositeKey = null; | ||
// Holds the current pending save observable (if any) | ||
this._pendingSave$ = null; | ||
this._eventSubject = new rxjs_1.Subject(); | ||
@@ -698,7 +700,33 @@ this._EntityInfo = Entity; | ||
/** | ||
* Saves the current state of the object to the database. Uses the active provider to handle the actual saving of the record. If the record is new, it will be created, if it already exists, it will be updated. | ||
* Saves the current state of the object to the database. Uses the active provider to handle the actual saving of the record. | ||
* If the record is new, it will be created, if it already exists, it will be updated. | ||
* | ||
* Debounces multiple calls so that if Save() is called again while a save is in progress, | ||
* the second call will simply receive the same result as the first. | ||
* | ||
* @param options | ||
* @returns Promise<boolean> | ||
*/ | ||
async Save(options) { | ||
// If a save is already in progress, return its promise. | ||
if (this._pendingSave$) { | ||
return (0, rxjs_1.firstValueFrom)(this._pendingSave$); | ||
} | ||
// Create a new observable that debounces duplicative calls, and executes the save. | ||
this._pendingSave$ = (0, rxjs_1.of)(options).pipe( | ||
// Execute the actual save logic. | ||
(0, rxjs_1.switchMap)(opts => (0, rxjs_1.from)(this._InnerSave(opts))), | ||
// When the save completes (whether successfully or not), clear the pending save observable. | ||
(0, rxjs_1.finalize)(() => { this._pendingSave$ = null; }), | ||
// Ensure that all subscribers get the same result. | ||
(0, rxjs_1.shareReplay)(1)); | ||
return (0, rxjs_1.firstValueFrom)(this._pendingSave$); | ||
} | ||
/** | ||
* Private, internal method to handle saving the current state of the object to the database. This method is called by the public facing Save() method | ||
* and is debounced to prevent multiple calls from being executed simultaneously. | ||
* @param options | ||
* @returns | ||
*/ | ||
async Save(options) { | ||
async _InnerSave(options) { | ||
const currentResultCount = this.ResultHistory.length; | ||
@@ -705,0 +733,0 @@ const newResult = new BaseEntityResult(); |
{ | ||
"name": "@memberjunction/core", | ||
"version": "2.23.2", | ||
"version": "2.24.0", | ||
"description": "MemberJunction: Core Library including Metadata, Application, Entity Retrieval and Manipulation, and Utilities", | ||
@@ -22,3 +22,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@memberjunction/global": "2.23.2", | ||
"@memberjunction/global": "2.24.0", | ||
"rxjs": "^7.8.1", | ||
@@ -25,0 +25,0 @@ "zod": "^3.23.8" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
628940
9106
+ Added@memberjunction/global@2.24.0(transitive)
- Removed@memberjunction/global@2.23.2(transitive)