@futdevpro/fsm-dynamo 1.20.184 → 1.20.186

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/build/_collections/utils/hu-calendar.util.d.ts +83 -0
  2. package/build/_collections/utils/hu-calendar.util.d.ts.map +1 -0
  3. package/build/_collections/utils/hu-calendar.util.js +163 -0
  4. package/build/_collections/utils/hu-calendar.util.js.map +1 -0
  5. package/build/_models/interfaces/hu-holiday.interface.d.ts +8 -0
  6. package/build/_models/interfaces/hu-holiday.interface.d.ts.map +1 -0
  7. package/build/_models/interfaces/hu-holiday.interface.js +3 -0
  8. package/build/_models/interfaces/hu-holiday.interface.js.map +1 -0
  9. package/build/_modules/data-handler/_models/data-handler.control-model.d.ts +28 -2
  10. package/build/_modules/data-handler/_models/data-handler.control-model.d.ts.map +1 -1
  11. package/build/_modules/data-handler/_models/data-handler.control-model.js +60 -8
  12. package/build/_modules/data-handler/_models/data-handler.control-model.js.map +1 -1
  13. package/build/_modules/data-handler/_models/data-list-handler.control-model.d.ts.map +1 -1
  14. package/build/_modules/data-handler/_models/data-list-handler.control-model.js +2 -1
  15. package/build/_modules/data-handler/_models/data-list-handler.control-model.js.map +1 -1
  16. package/build/_modules/ngx-models/_models/control-models/data-handler.control-model.d.ts +28 -2
  17. package/build/_modules/ngx-models/_models/control-models/data-handler.control-model.d.ts.map +1 -1
  18. package/build/_modules/ngx-models/_models/control-models/data-handler.control-model.js +63 -11
  19. package/build/_modules/ngx-models/_models/control-models/data-handler.control-model.js.map +1 -1
  20. package/build/index.d.ts +2 -0
  21. package/build/index.d.ts.map +1 -1
  22. package/build/index.js +2 -0
  23. package/build/index.js.map +1 -1
  24. package/build-esm/_collections/utils/hu-calendar.util.js +158 -0
  25. package/build-esm/_models/interfaces/hu-holiday.interface.js +1 -0
  26. package/build-esm/_modules/data-handler/_models/data-handler.control-model.js +60 -8
  27. package/build-esm/_modules/data-handler/_models/data-list-handler.control-model.js +2 -1
  28. package/build-esm/_modules/ngx-models/_models/control-models/data-handler.control-model.js +63 -11
  29. package/build-esm/index.js +2 -0
  30. package/package.json +1 -1
@@ -75,6 +75,11 @@ export class DyFM_DataHandler_ControlModel {
75
75
  dependency_DH;
76
76
  /** BFR-CREDIT-117 - a clear in progress (a cyclic dependency is cleared once). */
77
77
  isClearing = false;
78
+ /**
79
+ * BFR-FLEET-078 - the number of the latest load; a new load and a `clear()` move it. The answer of an older load
80
+ * (superseded by a newer one, or by a clear, e.g. a logout) changes nothing: no data, no loaded state.
81
+ */
82
+ loadGeneration = 0;
78
83
  /** BFR-ORGANIZER-040 - the dependency's current `_id`, as this handler's key (`undefined`: none). */
79
84
  dependencyLoadBy() {
80
85
  const data = this.dependency_DH?.data;
@@ -86,6 +91,18 @@ export class DyFM_DataHandler_ControlModel {
86
91
  ? data._id
87
92
  : undefined;
88
93
  }
94
+ /** BFR-FLEET-078 - whether the load of this generation was superseded (`undefined`: not a load, never). */
95
+ isSupersededLoad(generation) {
96
+ return generation !== undefined && generation !== this.loadGeneration;
97
+ }
98
+ /**
99
+ * BFR-FLEET-078 - what the caller of a superseded load gets: the newer load's result (it is in flight), else the
100
+ * current data (the newer load is done, or the handler was cleared).
101
+ */
102
+ async supersededResult() {
103
+ const inFlight = this.loadInProgress_BS.value;
104
+ return inFlight ? await inFlight.progress : this.data;
105
+ }
89
106
  /** @deprecated Use isDebugLogEnabled; debugLog remains the serialized compatibility key. */
90
107
  debugLog;
91
108
  /**
@@ -241,6 +258,8 @@ export class DyFM_DataHandler_ControlModel {
241
258
  async reloadData(loadBy, opts) {
242
259
  /** BFR-MASTERPROMPTER-128 — the missing-ID error of THIS call (silenced by `silentMissingId` in the catch too). */
243
260
  let missingIdError;
261
+ /** BFR-FLEET-078 — the generation of the load this call started or joined (`undefined`: none). */
262
+ let generation;
244
263
  try {
245
264
  const loadInProgress = this.loadInProgress_BS.value;
246
265
  const useLoadBy = loadBy ??
@@ -267,28 +286,38 @@ export class DyFM_DataHandler_ControlModel {
267
286
  // BFR-MASTERPROMPTER-074: a second call for the SAME key awaits the load in flight. Returning `this.data`
268
287
  // here handed the caller the not-yet-loaded (undefined / stale) value - measured: MP "Create Flow" during the
269
288
  // first `loadMyFlows()` got `undefined` and crashed on `myFlows.find`. Same contract as `getData()`.
289
+ // BFR-FLEET-078: the joined load is the latest one
290
+ generation = this.loadGeneration;
270
291
  return await loadInProgress.progress;
271
292
  }
272
293
  if (this.debugLog) {
273
294
  console.log(`DYNAMO DH.reloadData (${this.name}) DEBUG:` +
274
295
  `\n DataHandler reloadData... (using id: ${useLoadBy})`);
275
296
  }
276
- const loadProgress = this.doReloadDataBy(useLoadBy);
297
+ generation = ++this.loadGeneration;
298
+ const loadGeneration = generation;
299
+ const loadProgress = this.doReloadDataBy(useLoadBy, loadGeneration);
277
300
  this.loadInProgress_BS.next({
278
301
  loadBy: useLoadBy,
279
302
  progress: loadProgress
280
303
  });
281
304
  // clears the in-flight marker on BOTH outcomes; `.finally()` returned a derived promise that rejected unhandled on
282
- // every failed load (an "Uncaught (in promise)" beside the real error) — the caller already receives the error
305
+ // every failed load (an "Uncaught (in promise)" beside the real error) — the caller already receives the error.
306
+ // BFR-FLEET-078: only its own marker (a superseded load must not clear the newer load's)
283
307
  const clearInProgress = () => {
284
- this.loadInProgress_BS.next(false);
308
+ if (!this.isSupersededLoad(loadGeneration)) {
309
+ this.loadInProgress_BS.next(false);
310
+ }
285
311
  };
286
312
  loadProgress.then(clearInProgress, clearInProgress);
287
313
  return await loadProgress;
288
314
  }
289
315
  catch (error) {
290
- this.loadInProgress_BS.next(false);
291
- this.loaded_BS.next(false);
316
+ // BFR-FLEET-078: a superseded load (a newer one started, or the handler was cleared) fails only for its caller
317
+ if (!this.isSupersededLoad(generation)) {
318
+ this.loadInProgress_BS.next(false);
319
+ this.loaded_BS.next(false);
320
+ }
292
321
  // BFR-MASTERPROMPTER-128 — the silenced missing-ID error (the `getData` not-loaded-yet path) is not logged here
293
322
  // either: it still THROWS, only the "reloadData was UNSUCCESSFUL" line is left out
294
323
  const silenced = !!opts?.silentMissingId && !!missingIdError && error === missingIdError;
@@ -317,10 +346,16 @@ export class DyFM_DataHandler_ControlModel {
317
346
  return this.data;
318
347
  }
319
348
  }
320
- async doReloadDataBy(loadedBy) {
349
+ /**
350
+ * Loads by the key and applies the answer, unless the load was superseded meanwhile (BFR-FLEET-078).
351
+ *
352
+ * @param loadedBy the key
353
+ * @param generation the load's number (`reloadData` gives it; a direct call starts a new one)
354
+ */
355
+ async doReloadDataBy(loadedBy, generation = ++this.loadGeneration) {
321
356
  try {
322
357
  this.lastLoadedBy = loadedBy;
323
- return await this.processLoadResult(await this.get(loadedBy), loadedBy);
358
+ return await this.processLoadResult(await this.get(loadedBy), loadedBy, generation);
324
359
  }
325
360
  catch (error) {
326
361
  this.resolveWaitsOnLoad();
@@ -367,6 +402,9 @@ export class DyFM_DataHandler_ControlModel {
367
402
  }
368
403
  this.isClearing = true;
369
404
  try {
405
+ // BFR-FLEET-078: the answer of a load in flight is not applied any more, and a new load does not wait for it
406
+ this.loadGeneration++;
407
+ this.loadInProgress_BS.next(false);
370
408
  this.data_BS.next(undefined);
371
409
  this.lastLoadedBy = undefined;
372
410
  if (!dontClearDependents) {
@@ -379,13 +417,24 @@ export class DyFM_DataHandler_ControlModel {
379
417
  this.isClearing = false;
380
418
  }
381
419
  }
382
- async processLoadResult(result, loadedBy) {
420
+ /**
421
+ * Runs the post-processes on a loaded answer and applies it. BFR-FLEET-078: a superseded load stops before the
422
+ * next post-process (they reload or clear the dependents) and is not applied.
423
+ *
424
+ * @param result the answer of the `get`
425
+ * @param loadedBy the key
426
+ * @param generation the load's number (`undefined`: applied whatever happened meanwhile, as before)
427
+ */
428
+ async processLoadResult(result, loadedBy, generation) {
383
429
  if (this.debugLog) {
384
430
  console.log(`DYNAMO DH.processLoadResult (${this.name}) DEBUG:` +
385
431
  `\n DataHandler processLoadResult... (using id: ${loadedBy})` +
386
432
  `\n Result:`, result);
387
433
  }
388
434
  for (const postProcess of this.getPostProcesses) {
435
+ if (this.isSupersededLoad(generation)) {
436
+ return await this.supersededResult();
437
+ }
389
438
  if (this.debugLog) {
390
439
  console.log(`DYNAMO DH.processLoadResult (${this.name}) DEBUG:` +
391
440
  `\n Post process:`, postProcess);
@@ -396,6 +445,9 @@ export class DyFM_DataHandler_ControlModel {
396
445
  `\nPost process returned null or undefined!`, '\n\n', new Error());
397
446
  }
398
447
  }
448
+ if (this.isSupersededLoad(generation)) {
449
+ return await this.supersededResult();
450
+ }
399
451
  this.data_BS.next(result);
400
452
  this.loaded_BS.next(true);
401
453
  this.resolveWaitsOnLoad();
@@ -122,7 +122,8 @@ export class DyFM_DataListHandler_ControlModel extends DyFM_DataHandler {
122
122
  try {
123
123
  const setActiveItem = !this.activeItem_BS.value || this.activeItem_BS.value?._id !== loadBy;
124
124
  const dataList = await super.reloadData(loadBy);
125
- if (setActiveItem && dataList.length > 0) {
125
+ // BFR-FLEET-078: a load superseded by a clear returns the cleared (empty) data
126
+ if (setActiveItem && dataList?.length > 0) {
126
127
  this.setActiveItem(dataList[0]);
127
128
  }
128
129
  return dataList;
@@ -51,6 +51,11 @@ export class DyFM_DataHandler_ControlModel {
51
51
  dependency_DH;
52
52
  /** BFR-CREDIT-117 - a clear in progress (a cyclic dependency is cleared once). */
53
53
  isClearing = false;
54
+ /**
55
+ * BFR-FLEET-078 - the number of the latest load; a new load and a `clear()` move it. The answer of an older load
56
+ * (superseded by a newer one, or by a clear, e.g. a logout) changes nothing: no data, no loaded / failed state.
57
+ */
58
+ loadGeneration = 0;
54
59
  /** BFR-ORGANIZER-040 - the dependency's current `_id`, as this handler's key (`undefined`: none). */
55
60
  dependencyLoadBy() {
56
61
  const data = this.dependency_DH?.data;
@@ -62,6 +67,18 @@ export class DyFM_DataHandler_ControlModel {
62
67
  ? data._id
63
68
  : undefined;
64
69
  }
70
+ /** BFR-FLEET-078 - whether the load of this generation was superseded (`undefined`: not a load, never). */
71
+ isSupersededLoad(generation) {
72
+ return generation !== undefined && generation !== this.loadGeneration;
73
+ }
74
+ /**
75
+ * BFR-FLEET-078 - what the caller of a superseded load gets: the newer load's result (it is in flight), else the
76
+ * current data (the newer load is done, or the handler was cleared).
77
+ */
78
+ async supersededResult() {
79
+ const inFlight = this.loadInProgress_$();
80
+ return inFlight ? await inFlight.progress : this.data;
81
+ }
65
82
  loopSafetyCollection = [];
66
83
  loopSafetyTimeout = second;
67
84
  /** if set to 0, loop safety will be disabled */
@@ -248,6 +265,8 @@ export class DyFM_DataHandler_ControlModel {
248
265
  async reloadData(loadBy, opts) {
249
266
  /** BFR-MASTERPROMPTER-128 — the missing-ID error of THIS call (silenced by `silentMissingId` in the catch too). */
250
267
  let missingIdError;
268
+ /** BFR-FLEET-078 — the generation of the load this call started or joined (`undefined`: none). */
269
+ let generation;
251
270
  try {
252
271
  const loadInProgress = this.loadInProgress_$();
253
272
  const useLoadBy = loadBy ??
@@ -270,6 +289,8 @@ export class DyFM_DataHandler_ControlModel {
270
289
  // BFR-MASTERPROMPTER-074: a second call for the SAME key awaits the load in flight. Returning `this.data`
271
290
  // here handed the caller the not-yet-loaded (undefined / stale) value - measured: MP "Create Flow" during the
272
291
  // first `loadMyFlows()` got `undefined` and crashed on `myFlows.find`. Same contract as `getData()`.
292
+ // BFR-FLEET-078: the joined load is the latest one
293
+ generation = this.loadGeneration;
273
294
  return await loadInProgress.progress;
274
295
  }
275
296
  if (this.debugLog) {
@@ -278,28 +299,36 @@ export class DyFM_DataHandler_ControlModel {
278
299
  }
279
300
  // BFR-ORGANIZER-041: a new load is not failed (yet)
280
301
  this.loadError_$?.set(undefined);
281
- const loadProgress = this.doReloadDataBy(useLoadBy);
302
+ generation = ++this.loadGeneration;
303
+ const loadGeneration = generation;
304
+ const loadProgress = this.doReloadDataBy(useLoadBy, loadGeneration);
282
305
  this.loadInProgress_$.set({
283
306
  loadBy: useLoadBy,
284
307
  progress: loadProgress
285
308
  });
286
309
  // clears the in-flight marker on BOTH outcomes; `.finally()` returned a derived promise that rejected unhandled on
287
- // every failed load (an "Uncaught (in promise)" beside the real error) — the caller already receives the error
310
+ // every failed load (an "Uncaught (in promise)" beside the real error) — the caller already receives the error.
311
+ // BFR-FLEET-078: only its own marker (a superseded load must not clear the newer load's)
288
312
  const clearInProgress = () => {
289
- this.loadInProgress_$.set(false);
313
+ if (!this.isSupersededLoad(loadGeneration)) {
314
+ this.loadInProgress_$.set(false);
315
+ }
290
316
  };
291
317
  loadProgress.then(clearInProgress, clearInProgress);
292
318
  return await loadProgress;
293
319
  }
294
320
  catch (error) {
295
- this.loadInProgress_$.set(false);
296
- this.loaded_$.set(false);
297
321
  // BFR-MASTERPROMPTER-128 — the silenced missing-ID error (the `getData` not-loaded-yet path) is not logged here
298
322
  // either: it still THROWS, only the "reloadData was UNSUCCESSFUL" line is left out
299
323
  const silenced = !!opts?.silentMissingId && !!missingIdError && error === missingIdError;
300
- // BFR-ORGANIZER-041: a failed load is visible as such (the silenced missing ID is "not loaded yet")
301
- if (!silenced) {
302
- this.loadError_$?.set(error ?? new Error(`DynamoERROR (DH.reloadData): the load failed (${this.name})`));
324
+ // BFR-FLEET-078: a superseded load (a newer one started, or the handler was cleared) fails only for its caller
325
+ if (!this.isSupersededLoad(generation)) {
326
+ this.loadInProgress_$.set(false);
327
+ this.loaded_$.set(false);
328
+ // BFR-ORGANIZER-041: a failed load is visible as such (the silenced missing ID is "not loaded yet")
329
+ if (!silenced) {
330
+ this.loadError_$?.set(error ?? new Error(`DynamoERROR (DH.reloadData): the load failed (${this.name})`));
331
+ }
303
332
  }
304
333
  if (!error?.error?.handled && !silenced) {
305
334
  console.error(`DYNAMO DH.reloadData (${this.name}) ERROR: ` +
@@ -327,10 +356,16 @@ export class DyFM_DataHandler_ControlModel {
327
356
  return this.data;
328
357
  }
329
358
  }
330
- async doReloadDataBy(loadedBy) {
359
+ /**
360
+ * Loads by the key and applies the answer, unless the load was superseded meanwhile (BFR-FLEET-078).
361
+ *
362
+ * @param loadedBy the key
363
+ * @param generation the load's number (`reloadData` gives it; a direct call starts a new one)
364
+ */
365
+ async doReloadDataBy(loadedBy, generation = ++this.loadGeneration) {
331
366
  try {
332
367
  this.lastLoadedBy = loadedBy;
333
- return await this.processLoadResult(await this.get(loadedBy), loadedBy);
368
+ return await this.processLoadResult(await this.get(loadedBy), loadedBy, generation);
334
369
  }
335
370
  catch (error) {
336
371
  this.resolveWaitsOnLoad();
@@ -376,6 +411,9 @@ export class DyFM_DataHandler_ControlModel {
376
411
  }
377
412
  this.isClearing = true;
378
413
  try {
414
+ // BFR-FLEET-078: the answer of a load in flight is not applied any more, and a new load does not wait for it
415
+ this.loadGeneration++;
416
+ this.loadInProgress_$.set(false);
379
417
  this.data_$.set(undefined);
380
418
  this.lastLoadedBy = undefined;
381
419
  this.loadError_$?.set(undefined);
@@ -389,7 +427,15 @@ export class DyFM_DataHandler_ControlModel {
389
427
  this.isClearing = false;
390
428
  }
391
429
  }
392
- async processLoadResult(result, loadedBy) {
430
+ /**
431
+ * Runs the post-processes on a loaded answer and applies it. BFR-FLEET-078: a superseded load stops before the
432
+ * next post-process (they reload or clear the dependents) and is not applied.
433
+ *
434
+ * @param result the answer of the `get`
435
+ * @param loadedBy the key
436
+ * @param generation the load's number (`undefined`: applied whatever happened meanwhile, as before)
437
+ */
438
+ async processLoadResult(result, loadedBy, generation) {
393
439
  try {
394
440
  if (this.debugLog) {
395
441
  console.log(`DYNAMO DH.processLoadResult (${this.name}) DEBUG:` +
@@ -397,6 +443,9 @@ export class DyFM_DataHandler_ControlModel {
397
443
  `\n Result:`, result);
398
444
  }
399
445
  for (const postProcess of this.getPostProcesses) {
446
+ if (this.isSupersededLoad(generation)) {
447
+ return await this.supersededResult();
448
+ }
400
449
  if (this.debugLog) {
401
450
  console.log(`DYNAMO DH.processLoadResult (${this.name}) DEBUG:` +
402
451
  `\n Post process:`, postProcess);
@@ -407,6 +456,9 @@ export class DyFM_DataHandler_ControlModel {
407
456
  `\nPost process returned null or undefined!`, '\n\n', new Error());
408
457
  }
409
458
  }
459
+ if (this.isSupersededLoad(generation)) {
460
+ return await this.supersededResult();
461
+ }
410
462
  this.data_$.set(result);
411
463
  this.loaded_$.set(true);
412
464
  this.loadError_$?.set(undefined);
@@ -15,6 +15,7 @@ export * from './_collections/utils/log.util';
15
15
  export * from './_collections/utils/round-list.util';
16
16
  export * from './_collections/utils/secret-mask.util';
17
17
  export * from './_collections/utils/doc-only-path.util';
18
+ export * from './_collections/utils/hu-calendar.util';
18
19
  export * from './_collections/utils/object.util';
19
20
  export * from './_collections/utils/require-env.util';
20
21
  export * from './_collections/utils/stack.util';
@@ -86,6 +87,7 @@ export * from './_models/data-models/metadata.data-model';
86
87
  // models/INTERFACES
87
88
  export * from './_models/interfaces/box-bounds.interface';
88
89
  export * from './_models/interfaces/error-defaults.interface';
90
+ export * from './_models/interfaces/hu-holiday.interface';
89
91
  export * from './_models/interfaces/public-error-body.interface';
90
92
  export * from './_models/interfaces/operation-authz-result.interface';
91
93
  export * from './_models/interfaces/operation-authz.interface';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@futdevpro/fsm-dynamo",
3
- "version": "1.20.184",
3
+ "version": "1.20.186",
4
4
  "description": "Full Stack Model Collection for Dynamic (NodeJS-Typescript) Framework called Dynamo, by Future Development Ltd.",
5
5
  "DyBu_settings": {
6
6
  "packageType": "full-stack-package",