@hf-chimera/store 0.1.0 → 0.2.0
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.
- package/README.md +171 -360
- package/dist/defaults-CDnbUToo.cjs +175 -0
- package/dist/defaults-CDnbUToo.cjs.map +1 -0
- package/dist/defaults-DkrKTPXY.mjs +91 -0
- package/dist/defaults-DkrKTPXY.mjs.map +1 -0
- package/dist/defaults.cjs +3 -14
- package/dist/defaults.d.cts +16 -42
- package/dist/defaults.d.cts.map +1 -1
- package/dist/defaults.d.mts +33 -0
- package/dist/defaults.d.mts.map +1 -0
- package/dist/defaults.mjs +3 -0
- package/dist/index.cjs +1709 -23
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +634 -2
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +634 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/{src-C74sq0jQ.js → index.mjs} +252 -246
- package/dist/index.mjs.map +1 -0
- package/dist/types-CNGIuRUw.d.mts +117 -0
- package/dist/types-CNGIuRUw.d.mts.map +1 -0
- package/dist/types-CuI5yXiY.d.cts +117 -0
- package/dist/types-CuI5yXiY.d.cts.map +1 -0
- package/package.json +10 -51
- package/.changeset/README.md +0 -8
- package/CHANGELOG.md +0 -98
- package/dist/adapters/react.cjs +0 -70
- package/dist/adapters/react.cjs.map +0 -1
- package/dist/adapters/react.d.cts +0 -15
- package/dist/adapters/react.d.cts.map +0 -1
- package/dist/adapters/react.d.ts +0 -15
- package/dist/adapters/react.d.ts.map +0 -1
- package/dist/adapters/react.js +0 -69
- package/dist/adapters/react.js.map +0 -1
- package/dist/adapters/vue.cjs +0 -92
- package/dist/adapters/vue.cjs.map +0 -1
- package/dist/adapters/vue.d.cts +0 -19
- package/dist/adapters/vue.d.cts.map +0 -1
- package/dist/adapters/vue.d.ts +0 -19
- package/dist/adapters/vue.d.ts.map +0 -1
- package/dist/adapters/vue.js +0 -91
- package/dist/adapters/vue.js.map +0 -1
- package/dist/defaults-C48gY1ow.cjs +0 -372
- package/dist/defaults-C48gY1ow.cjs.map +0 -1
- package/dist/defaults-CLUQg2zK.js +0 -210
- package/dist/defaults-CLUQg2zK.js.map +0 -1
- package/dist/defaults.cjs.map +0 -1
- package/dist/defaults.d.ts +0 -59
- package/dist/defaults.d.ts.map +0 -1
- package/dist/defaults.js +0 -13
- package/dist/defaults.js.map +0 -1
- package/dist/index-BuYMaiND.d.ts +0 -22
- package/dist/index-BuYMaiND.d.ts.map +0 -1
- package/dist/index-C45y61aH.d.ts +0 -821
- package/dist/index-C45y61aH.d.ts.map +0 -1
- package/dist/index-DP6-nR2O.d.cts +0 -821
- package/dist/index-DP6-nR2O.d.cts.map +0 -1
- package/dist/index-FQNcJwA7.d.cts +0 -22
- package/dist/index-FQNcJwA7.d.cts.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -4
- package/dist/params-B-wurzdZ.d.ts +0 -8
- package/dist/params-B-wurzdZ.d.ts.map +0 -1
- package/dist/params-C5dnCvJr.cjs +0 -47
- package/dist/params-C5dnCvJr.cjs.map +0 -1
- package/dist/params-DmOyCS2B.js +0 -13
- package/dist/params-DmOyCS2B.js.map +0 -1
- package/dist/params-uxNE-e4a.d.cts +0 -8
- package/dist/params-uxNE-e4a.d.cts.map +0 -1
- package/dist/qb-D6vPK6P0.cjs +0 -50
- package/dist/qb-D6vPK6P0.cjs.map +0 -1
- package/dist/qb-pchs-vdM.js +0 -45
- package/dist/qb-pchs-vdM.js.map +0 -1
- package/dist/qb.cjs +0 -5
- package/dist/qb.d.cts +0 -3
- package/dist/qb.d.ts +0 -3
- package/dist/qb.js +0 -5
- package/dist/src-C74sq0jQ.js.map +0 -1
- package/dist/src-YxpDmKvq.cjs +0 -1771
- package/dist/src-YxpDmKvq.cjs.map +0 -1
|
@@ -1,20 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as ChimeraOrderError, c as ChimeraError, i as chimeraDefaultOrderConfig, l as ChimeraInternalError, m as chimeraDefaultDebugConfig, o as ChimeraOrderTypeComparisonError, s as ChimeraOrderTypeError, t as chimeraDefaultQueryEntityConfig, u as chimeraDefaultFilterConfig } from "./defaults-DkrKTPXY.mjs";
|
|
2
2
|
|
|
3
|
-
//#region src/
|
|
4
|
-
var ChimeraFilterError = class extends ChimeraError {};
|
|
5
|
-
var ChimeraFilterOperatorError = class extends ChimeraFilterError {
|
|
6
|
-
constructor(operator, message) {
|
|
7
|
-
super(`Operator "${operator}" ${message}`);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var ChimeraFilterOperatorNotFoundError = class extends ChimeraFilterOperatorError {
|
|
11
|
-
constructor(operator) {
|
|
12
|
-
super(operator, "not found");
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
//#endregion
|
|
17
|
-
//#region src/shared/shared.ts
|
|
3
|
+
//#region ../../src/shared/shared.ts
|
|
18
4
|
const deepObjectAssign = (dst, srcObj, visited = /* @__PURE__ */ new WeakSet()) => {
|
|
19
5
|
for (const { 0: key, 1: srcVal } of Object.entries(srcObj)) {
|
|
20
6
|
if (srcVal === null || typeof srcVal !== "object" || Array.isArray(srcVal)) {
|
|
@@ -120,12 +106,26 @@ const makeCancellablePromise = (promise, controller = new AbortController()) =>
|
|
|
120
106
|
};
|
|
121
107
|
|
|
122
108
|
//#endregion
|
|
123
|
-
//#region src/filter/constants.ts
|
|
109
|
+
//#region ../../src/filter/constants.ts
|
|
124
110
|
const ChimeraOperatorSymbol = Symbol("ChimeraOperatorSymbol");
|
|
125
111
|
const ChimeraConjunctionSymbol = Symbol("ChimeraConjunctionSymbol");
|
|
126
112
|
|
|
127
113
|
//#endregion
|
|
128
|
-
//#region src/filter/
|
|
114
|
+
//#region ../../src/filter/errors.ts
|
|
115
|
+
var ChimeraFilterError = class extends ChimeraError {};
|
|
116
|
+
var ChimeraFilterOperatorError = class extends ChimeraFilterError {
|
|
117
|
+
constructor(operator, message) {
|
|
118
|
+
super(`Operator "${operator}" ${message}`);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
var ChimeraFilterOperatorNotFoundError = class extends ChimeraFilterOperatorError {
|
|
122
|
+
constructor(operator) {
|
|
123
|
+
super(operator, "not found");
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region ../../src/filter/filter.ts
|
|
129
129
|
const filterConjunctions = {
|
|
130
130
|
and: (operations) => operations.every((op) => op()),
|
|
131
131
|
not: (operations) => !operations.every((op) => op()),
|
|
@@ -238,7 +238,7 @@ const isFilterSubset = (candidate, target, getOperatorKey) => {
|
|
|
238
238
|
};
|
|
239
239
|
|
|
240
240
|
//#endregion
|
|
241
|
-
//#region src/order/types.ts
|
|
241
|
+
//#region ../../src/order/types.ts
|
|
242
242
|
let ChimeraOrderNulls = /* @__PURE__ */ function(ChimeraOrderNulls$1) {
|
|
243
243
|
ChimeraOrderNulls$1["First"] = "first";
|
|
244
244
|
ChimeraOrderNulls$1["Last"] = "last";
|
|
@@ -246,7 +246,7 @@ let ChimeraOrderNulls = /* @__PURE__ */ function(ChimeraOrderNulls$1) {
|
|
|
246
246
|
}({});
|
|
247
247
|
|
|
248
248
|
//#endregion
|
|
249
|
-
//#region src/order/order.ts
|
|
249
|
+
//#region ../../src/order/order.ts
|
|
250
250
|
const compileOrderDescriptor = ({ key, desc, nulls }) => ({
|
|
251
251
|
desc,
|
|
252
252
|
get: compilePropertyGetter(key),
|
|
@@ -290,7 +290,7 @@ const simplifyOrderBy = (orderBy) => orderBy ? orderBy.map((ob) => ({
|
|
|
290
290
|
})) : null;
|
|
291
291
|
|
|
292
292
|
//#endregion
|
|
293
|
-
//#region src/shared/ChimeraEventEmitter/ChimeraEventEmitter.ts
|
|
293
|
+
//#region ../../src/shared/ChimeraEventEmitter/ChimeraEventEmitter.ts
|
|
294
294
|
var Events = function Events$1() {};
|
|
295
295
|
Events.prototype = Object.create(null);
|
|
296
296
|
var ChimeraEventEmitter = class {
|
|
@@ -380,7 +380,7 @@ var ChimeraEventEmitter = class {
|
|
|
380
380
|
};
|
|
381
381
|
|
|
382
382
|
//#endregion
|
|
383
|
-
//#region src/query/types.ts
|
|
383
|
+
//#region ../../src/query/types.ts
|
|
384
384
|
let ChimeraQueryFetchingState = /* @__PURE__ */ function(ChimeraQueryFetchingState$1) {
|
|
385
385
|
/** Query just initialized. */
|
|
386
386
|
ChimeraQueryFetchingState$1["Initialized"] = "initialized";
|
|
@@ -415,7 +415,7 @@ let ChimeraQueryFetchingState = /* @__PURE__ */ function(ChimeraQueryFetchingSta
|
|
|
415
415
|
}({});
|
|
416
416
|
|
|
417
417
|
//#endregion
|
|
418
|
-
//#region src/query/constants.ts
|
|
418
|
+
//#region ../../src/query/constants.ts
|
|
419
419
|
const ChimeraGetParamsSym = Symbol("ChimeraGetParamsSym");
|
|
420
420
|
const ChimeraSetOneSym = Symbol("ChimeraSetOneSym");
|
|
421
421
|
const ChimeraSetManySym = Symbol("ChimeraSetManySym");
|
|
@@ -432,13 +432,114 @@ const IN_PROGRESS_STATES = [
|
|
|
432
432
|
];
|
|
433
433
|
|
|
434
434
|
//#endregion
|
|
435
|
-
//#region src/query/
|
|
435
|
+
//#region ../../src/query/errors.ts
|
|
436
|
+
const formatDeepErrorMessage = (message, cause) => `${message}: ${cause instanceof Error ? `\n ${cause.stack}` : cause}`;
|
|
437
|
+
var ChimeraQueryError = class extends ChimeraError {
|
|
438
|
+
entityName;
|
|
439
|
+
constructor(entityName, message, options) {
|
|
440
|
+
super(message, options);
|
|
441
|
+
this.entityName = entityName;
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
var ChimeraQueryIdMismatchError = class extends ChimeraQueryError {
|
|
445
|
+
old;
|
|
446
|
+
new;
|
|
447
|
+
constructor(entityName, oldId, newId) {
|
|
448
|
+
super(entityName, `
|
|
449
|
+
Can't update "${entityName}" item if the change updates it's [id] (changed from "${oldId}" to "${newId}").
|
|
450
|
+
If such an update should not be an error, update <idGetter> field in "${entityName}" entity config to make Chimera get the [id] value properly.
|
|
451
|
+
`.trim());
|
|
452
|
+
this.old = oldId;
|
|
453
|
+
this.new = newId;
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
var ChimeraQueryNotSpecifiedError = class extends ChimeraQueryError {
|
|
457
|
+
methodName;
|
|
458
|
+
constructor(entityName, methodName) {
|
|
459
|
+
super(entityName, `<${methodName}> for entity "${entityName}" was not specified`);
|
|
460
|
+
this.methodName = methodName;
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
var ChimeraQueryTrustError = class extends ChimeraQueryError {
|
|
464
|
+
constructor(entityName, description) {
|
|
465
|
+
super(entityName, `
|
|
466
|
+
DO NOT IGNORE THIS ERROR OR YOUR PROD MAY BREAK!
|
|
467
|
+
|
|
468
|
+
Looks like your "${entityName}" query provider ${description}
|
|
469
|
+
|
|
470
|
+
By default Chimera tend to trust external query provider to avoid extra data processing.
|
|
471
|
+
If it is not your case, set field "trustQuery" to "false" in config defaults or for specific entity.
|
|
472
|
+
This error visible only if "devMode" is "true".
|
|
473
|
+
If you'll ignore it, your production may fail, because Chimera won't check the data correctness.
|
|
474
|
+
`.trim());
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
var ChimeraQueryTrustIdMismatchError = class extends ChimeraQueryTrustError {
|
|
478
|
+
old;
|
|
479
|
+
new;
|
|
480
|
+
constructor(entityName, oldId, newId) {
|
|
481
|
+
super(entityName, `
|
|
482
|
+
returned an item with [id] that not matches with the [id] of item that was updated (changed from "${oldId}" to "${newId}").
|
|
483
|
+
If it is not an error, update <idGetter> field in "${entityName}" entity config to make Chimera get the [id] value properly.
|
|
484
|
+
`.trim());
|
|
485
|
+
this.old = oldId;
|
|
486
|
+
this.new = newId;
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
var ChimeraQueryTrustFetchedCollectionError = class extends ChimeraQueryTrustError {
|
|
490
|
+
old;
|
|
491
|
+
new;
|
|
492
|
+
constructor(entityName, input, output) {
|
|
493
|
+
super(entityName, "returned not properly sorted or ordered collection.");
|
|
494
|
+
this.old = input;
|
|
495
|
+
this.new = output;
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
var ChimeraQueryFetchingError = class extends ChimeraQueryError {
|
|
499
|
+
constructor(entityName, cause) {
|
|
500
|
+
super(entityName, formatDeepErrorMessage("Something went wrong", cause), { cause });
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
var ChimeraQueryDeletingError = class extends ChimeraQueryError {
|
|
504
|
+
constructor(entityName, cause) {
|
|
505
|
+
super(entityName, formatDeepErrorMessage("Something went wrong", cause), { cause });
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
var ChimeraQueryNotReadyError = class extends ChimeraQueryError {
|
|
509
|
+
constructor(entityName) {
|
|
510
|
+
super(entityName, "Unable to get unready value.");
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
var ChimeraQueryDeletedItemError = class extends ChimeraQueryError {
|
|
514
|
+
constructor(entityName, id) {
|
|
515
|
+
super(entityName, `Unable to updated deleted item with [id] "${id}."`);
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
var ChimeraQueryUnsuccessfulDeletionError = class extends ChimeraQueryError {
|
|
519
|
+
constructor(entityName, id) {
|
|
520
|
+
super(entityName, `Item with [id] "${id}" was not deleted.`);
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
var ChimeraQueryAlreadyRunningError = class extends ChimeraQueryError {
|
|
524
|
+
constructor(entityName, status) {
|
|
525
|
+
super(entityName, `Unable to operate query. Other process already running ${status}.`);
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
var ChimeraQueryNotCreatedError = class extends ChimeraQueryError {
|
|
529
|
+
constructor(entityName) {
|
|
530
|
+
super(entityName, "Unable to operate not created item.");
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
//#endregion
|
|
535
|
+
//#region ../../src/query/ChimeraCollectionQuery.ts
|
|
436
536
|
var ChimeraCollectionQuery = class extends ChimeraEventEmitter {
|
|
437
537
|
#state;
|
|
438
538
|
#promise;
|
|
439
539
|
#lastError;
|
|
440
540
|
#items;
|
|
441
|
-
#
|
|
541
|
+
#entityConfig;
|
|
542
|
+
#debugConfig;
|
|
442
543
|
#idGetter;
|
|
443
544
|
#params;
|
|
444
545
|
#order;
|
|
@@ -454,7 +555,7 @@ var ChimeraCollectionQuery = class extends ChimeraEventEmitter {
|
|
|
454
555
|
}
|
|
455
556
|
#readyItems(internalMessage) {
|
|
456
557
|
if (this.#items) return this.#items;
|
|
457
|
-
throw internalMessage ? new ChimeraInternalError(internalMessage) : new ChimeraQueryNotReadyError(this.#
|
|
558
|
+
throw internalMessage ? new ChimeraInternalError(internalMessage) : new ChimeraQueryNotReadyError(this.#entityConfig.name);
|
|
458
559
|
}
|
|
459
560
|
#addItem(item) {
|
|
460
561
|
const items = this.#readyItems("Trying to update not ready collection");
|
|
@@ -501,7 +602,8 @@ var ChimeraCollectionQuery = class extends ChimeraEventEmitter {
|
|
|
501
602
|
this.#deleteAtIndex(this.#readyItems("Trying to update not ready collection").indexOf(item));
|
|
502
603
|
}
|
|
503
604
|
#deleteById(id) {
|
|
504
|
-
|
|
605
|
+
const name = this.#entityConfig.name;
|
|
606
|
+
this.#deleteAtIndex(this.#readyItems("Trying to update not ready collection").findIndex((item) => this.#idGetter(item, name) === id));
|
|
505
607
|
}
|
|
506
608
|
#replaceItem(oldItem, newItem) {
|
|
507
609
|
const items = this.#readyItems("Trying to update not ready collection");
|
|
@@ -515,10 +617,11 @@ var ChimeraCollectionQuery = class extends ChimeraEventEmitter {
|
|
|
515
617
|
});
|
|
516
618
|
}
|
|
517
619
|
#getById(id) {
|
|
518
|
-
|
|
620
|
+
const name = this.#entityConfig.name;
|
|
621
|
+
return this.#readyItems("Trying to update not ready collection").find((item) => this.#idGetter(item, name) === id);
|
|
519
622
|
}
|
|
520
623
|
#setOne(item) {
|
|
521
|
-
const existingItem = this.#getById(this.#idGetter(item));
|
|
624
|
+
const existingItem = this.#getById(this.#idGetter(item, this.#entityConfig.name));
|
|
522
625
|
const nowMatches = this.#filter(item);
|
|
523
626
|
if (!(nowMatches || existingItem)) return;
|
|
524
627
|
if (existingItem) {
|
|
@@ -538,12 +641,12 @@ var ChimeraCollectionQuery = class extends ChimeraEventEmitter {
|
|
|
538
641
|
return input.filter((item) => this.#filter(item)).sort((a, b) => this.#order(a, b));
|
|
539
642
|
}
|
|
540
643
|
#validate(input) {
|
|
541
|
-
if (this.#
|
|
644
|
+
if (this.#entityConfig.trustQuery && !this.#debugConfig.devMode) return input;
|
|
542
645
|
const prepared = this.#apply(input);
|
|
543
|
-
if (!this.#
|
|
544
|
-
if (this.#
|
|
646
|
+
if (!this.#entityConfig.trustQuery) return prepared;
|
|
647
|
+
if (this.#debugConfig.devMode) {
|
|
545
648
|
for (let i = 0; i < input.length; i++) if (input[i] !== prepared[i]) {
|
|
546
|
-
console.warn(new ChimeraQueryTrustFetchedCollectionError(this.#
|
|
649
|
+
console.warn(new ChimeraQueryTrustFetchedCollectionError(this.#entityConfig.name, input, prepared));
|
|
547
650
|
break;
|
|
548
651
|
}
|
|
549
652
|
}
|
|
@@ -563,11 +666,12 @@ var ChimeraCollectionQuery = class extends ChimeraEventEmitter {
|
|
|
563
666
|
this.#setNewItems(this.#validate(response.data));
|
|
564
667
|
this.#state = ChimeraQueryFetchingState.Fetched;
|
|
565
668
|
return response;
|
|
566
|
-
}).catch((error) => this.#setError(error, new ChimeraQueryFetchingError(this.#
|
|
669
|
+
}).catch((error) => this.#setError(error, new ChimeraQueryFetchingError(this.#entityConfig.name, error))), controller);
|
|
567
670
|
}
|
|
568
|
-
constructor(config, params, existingItems, order, filter, alreadyValid) {
|
|
671
|
+
constructor(config, debugConfig, params, existingItems, order, filter, alreadyValid) {
|
|
569
672
|
super();
|
|
570
|
-
this.#
|
|
673
|
+
this.#entityConfig = config;
|
|
674
|
+
this.#debugConfig = debugConfig;
|
|
571
675
|
this.#params = params;
|
|
572
676
|
this.#promise = null;
|
|
573
677
|
this.#items = null;
|
|
@@ -582,10 +686,13 @@ var ChimeraCollectionQuery = class extends ChimeraEventEmitter {
|
|
|
582
686
|
} else {
|
|
583
687
|
this.#state = ChimeraQueryFetchingState.Fetching;
|
|
584
688
|
const { controller } = this.#prepareRequestParams();
|
|
585
|
-
this.#setPromise(this.#watchPromise(makeCancellablePromise(config.collectionFetcher(params, { signal: controller.signal }), controller), controller));
|
|
689
|
+
this.#setPromise(this.#watchPromise(makeCancellablePromise(config.collectionFetcher(params, { signal: controller.signal }, this.#entityConfig.name), controller), controller));
|
|
586
690
|
}
|
|
587
691
|
this.#emit("initialized", { instance: this });
|
|
588
692
|
}
|
|
693
|
+
get name() {
|
|
694
|
+
return this.#entityConfig.name;
|
|
695
|
+
}
|
|
589
696
|
get [ChimeraGetParamsSym]() {
|
|
590
697
|
return this.#params;
|
|
591
698
|
}
|
|
@@ -645,7 +752,8 @@ var ChimeraCollectionQuery = class extends ChimeraEventEmitter {
|
|
|
645
752
|
}
|
|
646
753
|
/** Return an item if it is ready, throw error otherwise */
|
|
647
754
|
getById(id) {
|
|
648
|
-
|
|
755
|
+
const name = this.#entityConfig.name;
|
|
756
|
+
return this.#readyItems().find((item) => this.#idGetter(item, name) === id);
|
|
649
757
|
}
|
|
650
758
|
/** Return mutable ref to item by idx if it is ready, throw error otherwise */
|
|
651
759
|
mutableAt(idx) {
|
|
@@ -653,7 +761,8 @@ var ChimeraCollectionQuery = class extends ChimeraEventEmitter {
|
|
|
653
761
|
}
|
|
654
762
|
/** Return mutable ref to item by [id] if it is ready, throw error otherwise */
|
|
655
763
|
mutableGetById(id) {
|
|
656
|
-
|
|
764
|
+
const name = this.#entityConfig.name;
|
|
765
|
+
return deepObjectClone(this.#readyItems().find((item) => this.#idGetter(item, name) === id));
|
|
657
766
|
}
|
|
658
767
|
/**
|
|
659
768
|
* Trigger refetch, return existing refetch promise if already running
|
|
@@ -662,10 +771,10 @@ var ChimeraCollectionQuery = class extends ChimeraEventEmitter {
|
|
|
662
771
|
*/
|
|
663
772
|
refetch(force = false) {
|
|
664
773
|
if (!force && this.#promise && [ChimeraQueryFetchingState.Fetching, ChimeraQueryFetchingState.Refetching].includes(this.#state)) return this.#promise;
|
|
665
|
-
if (!force && [ChimeraQueryFetchingState.Updating, ChimeraQueryFetchingState.Deleting].includes(this.#state)) throw new ChimeraQueryAlreadyRunningError(this.#
|
|
774
|
+
if (!force && [ChimeraQueryFetchingState.Updating, ChimeraQueryFetchingState.Deleting].includes(this.#state)) throw new ChimeraQueryAlreadyRunningError(this.#entityConfig.name, this.#state);
|
|
666
775
|
this.#state = ChimeraQueryFetchingState.Refetching;
|
|
667
776
|
const { controller } = this.#prepareRequestParams();
|
|
668
|
-
return this.#setPromise(this.#watchPromise(makeCancellablePromise(this.#
|
|
777
|
+
return this.#setPromise(this.#watchPromise(makeCancellablePromise(this.#entityConfig.collectionFetcher(this.#params, { signal: controller.signal }, this.#entityConfig.name), controller), controller));
|
|
669
778
|
}
|
|
670
779
|
/**
|
|
671
780
|
* Update item using updated copy
|
|
@@ -673,7 +782,7 @@ var ChimeraCollectionQuery = class extends ChimeraEventEmitter {
|
|
|
673
782
|
*/
|
|
674
783
|
update(newItem) {
|
|
675
784
|
const { controller } = this.#prepareRequestParams();
|
|
676
|
-
return this.#
|
|
785
|
+
return this.#entityConfig.itemUpdater(newItem, { signal: controller.signal }, this.#entityConfig.name).then((response) => {
|
|
677
786
|
const { data } = response;
|
|
678
787
|
this.#items && this.#setNewOne(data);
|
|
679
788
|
this.#emit("selfItemUpdated", {
|
|
@@ -689,7 +798,7 @@ var ChimeraCollectionQuery = class extends ChimeraEventEmitter {
|
|
|
689
798
|
*/
|
|
690
799
|
batchedUpdate(newItems) {
|
|
691
800
|
const { controller } = this.#prepareRequestParams();
|
|
692
|
-
return this.#
|
|
801
|
+
return this.#entityConfig.batchedUpdater(Array.from(newItems), { signal: controller.signal }, this.#entityConfig.name).then((response) => {
|
|
693
802
|
const ready = this.ready;
|
|
694
803
|
response.data.forEach((item) => {
|
|
695
804
|
ready && this.#setNewOne(item);
|
|
@@ -706,8 +815,9 @@ var ChimeraCollectionQuery = class extends ChimeraEventEmitter {
|
|
|
706
815
|
* @param id id of item to delete
|
|
707
816
|
*/
|
|
708
817
|
delete(id) {
|
|
818
|
+
const name = this.#entityConfig.name;
|
|
709
819
|
const { controller } = this.#prepareRequestParams();
|
|
710
|
-
return this.#
|
|
820
|
+
return this.#entityConfig.itemDeleter(id, { signal: controller.signal }, name).then((response) => {
|
|
711
821
|
const { result: { id: newId, success } } = response;
|
|
712
822
|
if (!this.#items) {
|
|
713
823
|
success && this.#emit("selfItemDeleted", {
|
|
@@ -716,7 +826,7 @@ var ChimeraCollectionQuery = class extends ChimeraEventEmitter {
|
|
|
716
826
|
});
|
|
717
827
|
return response;
|
|
718
828
|
}
|
|
719
|
-
if (this.#
|
|
829
|
+
if (this.#entityConfig.trustQuery && !this.#debugConfig.devMode && success) {
|
|
720
830
|
this.#deleteById(newId);
|
|
721
831
|
this.#emit("selfItemDeleted", {
|
|
722
832
|
id: newId,
|
|
@@ -725,13 +835,13 @@ var ChimeraCollectionQuery = class extends ChimeraEventEmitter {
|
|
|
725
835
|
return response;
|
|
726
836
|
}
|
|
727
837
|
if (id !== newId) {
|
|
728
|
-
this.#
|
|
729
|
-
if (!this.#
|
|
838
|
+
this.#debugConfig.devMode && this.#entityConfig.trustQuery && console.warn(new ChimeraQueryTrustIdMismatchError(this.#entityConfig.name, id, newId));
|
|
839
|
+
if (!this.#entityConfig.trustQuery) {
|
|
730
840
|
success && this.#emit("selfItemDeleted", {
|
|
731
841
|
id: newId,
|
|
732
842
|
instance: this
|
|
733
843
|
});
|
|
734
|
-
throw new ChimeraQueryTrustIdMismatchError(this.#
|
|
844
|
+
throw new ChimeraQueryTrustIdMismatchError(this.#entityConfig.name, id, newId);
|
|
735
845
|
}
|
|
736
846
|
}
|
|
737
847
|
if (success) {
|
|
@@ -742,19 +852,20 @@ var ChimeraCollectionQuery = class extends ChimeraEventEmitter {
|
|
|
742
852
|
});
|
|
743
853
|
return response;
|
|
744
854
|
}
|
|
745
|
-
const error = new ChimeraQueryUnsuccessfulDeletionError(this.#
|
|
855
|
+
const error = new ChimeraQueryUnsuccessfulDeletionError(this.#entityConfig.name, id);
|
|
746
856
|
this.#state = ChimeraQueryFetchingState.ReErrored;
|
|
747
857
|
this.#lastError = error;
|
|
748
858
|
throw error;
|
|
749
|
-
}, (error) => this.#setError(error, new ChimeraQueryDeletingError(
|
|
859
|
+
}, (error) => this.#setError(error, new ChimeraQueryDeletingError(name, error)));
|
|
750
860
|
}
|
|
751
861
|
/**
|
|
752
862
|
* Delete a list of items by their [id]s
|
|
753
863
|
* @param ids array of items to delete
|
|
754
864
|
*/
|
|
755
865
|
batchedDelete(ids) {
|
|
866
|
+
const name = this.#entityConfig.name;
|
|
756
867
|
const { controller } = this.#prepareRequestParams();
|
|
757
|
-
return this.#
|
|
868
|
+
return this.#entityConfig.batchedDeleter(Array.from(ids), { signal: controller.signal }, name).then((response) => {
|
|
758
869
|
this.#items && response.result.forEach(({ id: newId, success }) => {
|
|
759
870
|
if (success) {
|
|
760
871
|
this.#deleteById(newId);
|
|
@@ -763,22 +874,23 @@ var ChimeraCollectionQuery = class extends ChimeraEventEmitter {
|
|
|
763
874
|
instance: this
|
|
764
875
|
});
|
|
765
876
|
} else {
|
|
766
|
-
const error = new ChimeraQueryUnsuccessfulDeletionError(this.#
|
|
877
|
+
const error = new ChimeraQueryUnsuccessfulDeletionError(this.#entityConfig.name, newId);
|
|
767
878
|
this.#state = ChimeraQueryFetchingState.ReErrored;
|
|
768
879
|
this.#lastError = error;
|
|
769
880
|
throw error;
|
|
770
881
|
}
|
|
771
882
|
});
|
|
772
883
|
return response;
|
|
773
|
-
}, (error) => this.#setError(error, new ChimeraQueryDeletingError(
|
|
884
|
+
}, (error) => this.#setError(error, new ChimeraQueryDeletingError(name, error)));
|
|
774
885
|
}
|
|
775
886
|
/**
|
|
776
887
|
* Create new item using partial data
|
|
777
888
|
* @param item partial item data to create new item
|
|
778
889
|
*/
|
|
779
890
|
create(item) {
|
|
891
|
+
const name = this.#entityConfig.name;
|
|
780
892
|
const { controller } = this.#prepareRequestParams();
|
|
781
|
-
return this.#
|
|
893
|
+
return this.#entityConfig.itemCreator(item, { signal: controller.signal }, name).then((response) => {
|
|
782
894
|
const { data } = response;
|
|
783
895
|
this.#items && this.#setNewOne(data);
|
|
784
896
|
this.#emit("selfItemCreated", {
|
|
@@ -786,15 +898,16 @@ var ChimeraCollectionQuery = class extends ChimeraEventEmitter {
|
|
|
786
898
|
item: data
|
|
787
899
|
});
|
|
788
900
|
return response;
|
|
789
|
-
}, (error) => this.#setError(error, new ChimeraQueryFetchingError(
|
|
901
|
+
}, (error) => this.#setError(error, new ChimeraQueryFetchingError(name, error)));
|
|
790
902
|
}
|
|
791
903
|
/**
|
|
792
904
|
* Create multiple items using partial data
|
|
793
905
|
* @param items array of partial item data to create new items
|
|
794
906
|
*/
|
|
795
907
|
batchedCreate(items) {
|
|
908
|
+
const name = this.#entityConfig.name;
|
|
796
909
|
const { controller } = this.#prepareRequestParams();
|
|
797
|
-
return this.#
|
|
910
|
+
return this.#entityConfig.batchedCreator(Array.from(items), { signal: controller.signal }, name).then((response) => {
|
|
798
911
|
this.#items && response.data.forEach((item) => {
|
|
799
912
|
this.#setNewOne(item);
|
|
800
913
|
this.#emit("selfItemCreated", {
|
|
@@ -803,7 +916,7 @@ var ChimeraCollectionQuery = class extends ChimeraEventEmitter {
|
|
|
803
916
|
});
|
|
804
917
|
});
|
|
805
918
|
return response;
|
|
806
|
-
}, (error) => this.#setError(error, new ChimeraQueryFetchingError(
|
|
919
|
+
}, (error) => this.#setError(error, new ChimeraQueryFetchingError(name, error)));
|
|
807
920
|
}
|
|
808
921
|
/**
|
|
809
922
|
* Standard Array API without mutations
|
|
@@ -883,7 +996,7 @@ var ChimeraCollectionQuery = class extends ChimeraEventEmitter {
|
|
|
883
996
|
};
|
|
884
997
|
|
|
885
998
|
//#endregion
|
|
886
|
-
//#region src/query/ChimeraItemQuery.ts
|
|
999
|
+
//#region ../../src/query/ChimeraItemQuery.ts
|
|
887
1000
|
var ChimeraItemQuery = class extends ChimeraEventEmitter {
|
|
888
1001
|
#item;
|
|
889
1002
|
#mutable;
|
|
@@ -891,7 +1004,8 @@ var ChimeraItemQuery = class extends ChimeraEventEmitter {
|
|
|
891
1004
|
#promise;
|
|
892
1005
|
#lastError;
|
|
893
1006
|
#params;
|
|
894
|
-
#
|
|
1007
|
+
#entityConfig;
|
|
1008
|
+
#debugConfig;
|
|
895
1009
|
#idGetter;
|
|
896
1010
|
#emit(event, arg) {
|
|
897
1011
|
queueMicrotask(() => super.emit(event, arg));
|
|
@@ -909,10 +1023,10 @@ var ChimeraItemQuery = class extends ChimeraEventEmitter {
|
|
|
909
1023
|
}
|
|
910
1024
|
#readyItem(internalMessage) {
|
|
911
1025
|
if (this.#item) return this.#item;
|
|
912
|
-
throw internalMessage ? new ChimeraInternalError(internalMessage) : new ChimeraQueryNotReadyError(this.#
|
|
1026
|
+
throw internalMessage ? new ChimeraInternalError(internalMessage) : new ChimeraQueryNotReadyError(this.#entityConfig.name);
|
|
913
1027
|
}
|
|
914
1028
|
#mutableItem(internalMessage) {
|
|
915
|
-
if (this.#state === ChimeraQueryFetchingState.Deleted) throw internalMessage ? new ChimeraInternalError(internalMessage) : new ChimeraQueryDeletedItemError(this.#
|
|
1029
|
+
if (this.#state === ChimeraQueryFetchingState.Deleted) throw internalMessage ? new ChimeraInternalError(internalMessage) : new ChimeraQueryDeletedItemError(this.#entityConfig.name, this.#params.id);
|
|
916
1030
|
return this.#readyItem(internalMessage);
|
|
917
1031
|
}
|
|
918
1032
|
#setMutable(item) {
|
|
@@ -921,7 +1035,7 @@ var ChimeraItemQuery = class extends ChimeraEventEmitter {
|
|
|
921
1035
|
else this.#mutable = item;
|
|
922
1036
|
}
|
|
923
1037
|
#resetMutable() {
|
|
924
|
-
this.#setMutable(this.#readyItem(`Trying to reset mutable ref for empty item (${this.#
|
|
1038
|
+
this.#setMutable(this.#readyItem(`Trying to reset mutable ref for empty item (${this.#entityConfig.name}[${this.#params.id}])`));
|
|
925
1039
|
}
|
|
926
1040
|
#setItem(item) {
|
|
927
1041
|
!this.#item && this.#emit("ready", { instance: this });
|
|
@@ -961,14 +1075,15 @@ var ChimeraItemQuery = class extends ChimeraEventEmitter {
|
|
|
961
1075
|
throw source;
|
|
962
1076
|
}
|
|
963
1077
|
#watchPromise(promise, controller) {
|
|
1078
|
+
const name = this.#entityConfig.name;
|
|
964
1079
|
return makeCancellablePromise(promise.then(({ data }) => {
|
|
965
|
-
if (this.#
|
|
1080
|
+
if (this.#entityConfig.trustQuery && !this.#debugConfig.devMode) {
|
|
966
1081
|
this.#setNewItem(data);
|
|
967
1082
|
this.#state = ChimeraQueryFetchingState.Fetched;
|
|
968
1083
|
return { data };
|
|
969
1084
|
}
|
|
970
1085
|
const localId = this.#params.id;
|
|
971
|
-
const newId = this.#idGetter(data);
|
|
1086
|
+
const newId = this.#idGetter(data, name);
|
|
972
1087
|
if (localId === newId || this.#state === ChimeraQueryFetchingState.Creating) {
|
|
973
1088
|
this.#setNewItem(data);
|
|
974
1089
|
if (this.#state === ChimeraQueryFetchingState.Creating) this.#emit("selfCreated", {
|
|
@@ -977,39 +1092,41 @@ var ChimeraItemQuery = class extends ChimeraEventEmitter {
|
|
|
977
1092
|
});
|
|
978
1093
|
this.#state = ChimeraQueryFetchingState.Fetched;
|
|
979
1094
|
} else {
|
|
980
|
-
this.#
|
|
981
|
-
if (!this.#
|
|
1095
|
+
this.#debugConfig.devMode && this.#entityConfig.trustQuery && console.warn(new ChimeraQueryTrustIdMismatchError(this.#entityConfig.name, localId, newId));
|
|
1096
|
+
if (!this.#entityConfig.trustQuery) throw new ChimeraQueryTrustIdMismatchError(this.#entityConfig.name, localId, newId);
|
|
982
1097
|
this.#setNewItem(data);
|
|
983
1098
|
this.#params.id = newId;
|
|
984
1099
|
this.#state = ChimeraQueryFetchingState.Fetched;
|
|
985
1100
|
}
|
|
986
1101
|
return { data };
|
|
987
|
-
}).catch((error) => this.#setError(error, new ChimeraQueryFetchingError(this.#
|
|
1102
|
+
}).catch((error) => this.#setError(error, new ChimeraQueryFetchingError(this.#entityConfig.name, error))), controller);
|
|
988
1103
|
}
|
|
989
1104
|
#updateItem(newItem) {
|
|
990
|
-
const
|
|
991
|
-
const
|
|
992
|
-
|
|
1105
|
+
const name = this.#entityConfig.name;
|
|
1106
|
+
const newId = this.#idGetter(newItem, name);
|
|
1107
|
+
const oldId = this.#idGetter(this.#readyItem(`Trying to update not ready item (${this.#entityConfig.name}[${this.#params.id}])`), name);
|
|
1108
|
+
if (newId !== oldId && !this.#entityConfig.trustQuery) {
|
|
993
1109
|
this.#resetMutable();
|
|
994
|
-
throw new ChimeraQueryIdMismatchError(this.#
|
|
1110
|
+
throw new ChimeraQueryIdMismatchError(this.#entityConfig.name, oldId, newId);
|
|
995
1111
|
}
|
|
996
1112
|
this.#state = ChimeraQueryFetchingState.Updating;
|
|
997
1113
|
const { controller } = this.#prepareRequestParams();
|
|
998
|
-
return this.#setPromise(this.#watchPromise(makeCancellablePromise(this.#
|
|
1114
|
+
return this.#setPromise(this.#watchPromise(makeCancellablePromise(this.#entityConfig.itemUpdater(newItem, { signal: controller.signal }, name), controller), controller));
|
|
999
1115
|
}
|
|
1000
1116
|
#requestDelete() {
|
|
1001
1117
|
this.#state = ChimeraQueryFetchingState.Deleting;
|
|
1002
1118
|
const { controller } = this.#prepareRequestParams();
|
|
1003
|
-
|
|
1119
|
+
const name = this.#entityConfig.name;
|
|
1120
|
+
return this.#setPromise(makeCancellablePromise(makeCancellablePromise(this.#entityConfig.itemDeleter(this.#params.id, { signal: controller.signal }, name), controller).then(({ result }) => {
|
|
1004
1121
|
const { id, success } = result;
|
|
1005
|
-
if (this.#
|
|
1122
|
+
if (this.#entityConfig.trustQuery && !this.#debugConfig.devMode && success) {
|
|
1006
1123
|
this.#deleteItem();
|
|
1007
1124
|
return { result };
|
|
1008
1125
|
}
|
|
1009
1126
|
const localId = this.#params.id;
|
|
1010
1127
|
if (localId !== id) {
|
|
1011
|
-
this.#
|
|
1012
|
-
if (!this.#
|
|
1128
|
+
this.#debugConfig.devMode && this.#entityConfig.trustQuery && console.warn(new ChimeraQueryTrustIdMismatchError(this.#entityConfig.name, localId, id));
|
|
1129
|
+
if (!this.#entityConfig.trustQuery) throw new ChimeraQueryTrustIdMismatchError(this.#entityConfig.name, localId, id);
|
|
1013
1130
|
}
|
|
1014
1131
|
if (success) {
|
|
1015
1132
|
this.#deleteItem();
|
|
@@ -1018,45 +1135,50 @@ var ChimeraItemQuery = class extends ChimeraEventEmitter {
|
|
|
1018
1135
|
instance: this
|
|
1019
1136
|
});
|
|
1020
1137
|
} else {
|
|
1021
|
-
const error = new ChimeraQueryUnsuccessfulDeletionError(this.#
|
|
1138
|
+
const error = new ChimeraQueryUnsuccessfulDeletionError(this.#entityConfig.name, this.#params.id);
|
|
1022
1139
|
this.#state = ChimeraQueryFetchingState.ReErrored;
|
|
1023
1140
|
this.#lastError = error;
|
|
1024
1141
|
throw error;
|
|
1025
1142
|
}
|
|
1026
1143
|
return { result };
|
|
1027
|
-
}, (error) => this.#setError(error, new ChimeraQueryDeletingError(this.#
|
|
1144
|
+
}, (error) => this.#setError(error, new ChimeraQueryDeletingError(this.#entityConfig.name, error)))));
|
|
1028
1145
|
}
|
|
1029
|
-
constructor(config, params, existingItem, toCreateItem) {
|
|
1146
|
+
constructor(config, debugConfig, params, existingItem, toCreateItem) {
|
|
1030
1147
|
super();
|
|
1031
|
-
this.#
|
|
1148
|
+
this.#entityConfig = config;
|
|
1149
|
+
this.#debugConfig = debugConfig;
|
|
1032
1150
|
this.#idGetter = config.idGetter;
|
|
1033
1151
|
this.#params = params;
|
|
1034
1152
|
this.#promise = null;
|
|
1035
1153
|
this.#item = null;
|
|
1036
1154
|
this.#mutable = null;
|
|
1037
1155
|
this.#state = ChimeraQueryFetchingState.Initialized;
|
|
1156
|
+
const name = config.name;
|
|
1038
1157
|
if (existingItem) {
|
|
1039
1158
|
const item = existingItem;
|
|
1040
1159
|
this.#setItem(item);
|
|
1041
|
-
if (
|
|
1160
|
+
if (debugConfig.devMode && this.#idGetter(item, name) !== params.id) {
|
|
1042
1161
|
this.#state = ChimeraQueryFetchingState.Errored;
|
|
1043
|
-
throw new ChimeraInternalError(`Invalid item query [id] (changed from "${params.id}" to "${this.#idGetter(item)}")`);
|
|
1162
|
+
throw new ChimeraInternalError(`Invalid item query [id] (changed from "${params.id}" to "${this.#idGetter(item, name)}")`);
|
|
1044
1163
|
}
|
|
1045
1164
|
this.#state = ChimeraQueryFetchingState.Prefetched;
|
|
1046
1165
|
} else if (toCreateItem) {
|
|
1047
1166
|
this.#state = ChimeraQueryFetchingState.Creating;
|
|
1048
1167
|
const { controller } = this.#prepareRequestParams();
|
|
1049
|
-
this.#setPromise(this.#watchPromise(makeCancellablePromise(config.itemCreator(toCreateItem, { signal: controller.signal }), controller).then(({ data }) => {
|
|
1050
|
-
this.#params.id = this.#idGetter(data);
|
|
1168
|
+
this.#setPromise(this.#watchPromise(makeCancellablePromise(config.itemCreator(toCreateItem, { signal: controller.signal }, name), controller).then(({ data }) => {
|
|
1169
|
+
this.#params.id = this.#idGetter(data, name);
|
|
1051
1170
|
return { data };
|
|
1052
1171
|
}), controller));
|
|
1053
1172
|
} else {
|
|
1054
1173
|
this.#state = ChimeraQueryFetchingState.Fetching;
|
|
1055
1174
|
const { controller } = this.#prepareRequestParams();
|
|
1056
|
-
this.#setPromise(this.#watchPromise(makeCancellablePromise(config.itemFetcher(params, { signal: controller.signal }), controller), controller));
|
|
1175
|
+
this.#setPromise(this.#watchPromise(makeCancellablePromise(config.itemFetcher(params, { signal: controller.signal }, name), controller), controller));
|
|
1057
1176
|
}
|
|
1058
1177
|
this.#emit("initialized", { instance: this });
|
|
1059
1178
|
}
|
|
1179
|
+
get name() {
|
|
1180
|
+
return this.#entityConfig.name;
|
|
1181
|
+
}
|
|
1060
1182
|
get [ChimeraGetParamsSym]() {
|
|
1061
1183
|
return this.#params;
|
|
1062
1184
|
}
|
|
@@ -1129,11 +1251,11 @@ var ChimeraItemQuery = class extends ChimeraEventEmitter {
|
|
|
1129
1251
|
*/
|
|
1130
1252
|
refetch(force = false) {
|
|
1131
1253
|
if (!force && this.#promise && [ChimeraQueryFetchingState.Fetching, ChimeraQueryFetchingState.Refetching].includes(this.#state)) return this.#promise;
|
|
1132
|
-
if (this.#state === ChimeraQueryFetchingState.Creating) throw new ChimeraQueryNotCreatedError(this.#
|
|
1133
|
-
if (!force && [ChimeraQueryFetchingState.Updating, ChimeraQueryFetchingState.Deleting].includes(this.#state)) throw new ChimeraQueryAlreadyRunningError(this.#
|
|
1254
|
+
if (this.#state === ChimeraQueryFetchingState.Creating) throw new ChimeraQueryNotCreatedError(this.#entityConfig.name);
|
|
1255
|
+
if (!force && [ChimeraQueryFetchingState.Updating, ChimeraQueryFetchingState.Deleting].includes(this.#state)) throw new ChimeraQueryAlreadyRunningError(this.#entityConfig.name, this.#state);
|
|
1134
1256
|
this.#state = ChimeraQueryFetchingState.Refetching;
|
|
1135
1257
|
const { controller } = this.#prepareRequestParams();
|
|
1136
|
-
return this.#setPromise(this.#watchPromise(makeCancellablePromise(this.#
|
|
1258
|
+
return this.#setPromise(this.#watchPromise(makeCancellablePromise(this.#entityConfig.itemFetcher(this.#params, { signal: controller.signal }, this.#entityConfig.name), controller), controller));
|
|
1137
1259
|
}
|
|
1138
1260
|
/**
|
|
1139
1261
|
* Update item using updated copy, a running update process will be cancelled
|
|
@@ -1142,12 +1264,12 @@ var ChimeraItemQuery = class extends ChimeraEventEmitter {
|
|
|
1142
1264
|
* @throws {ChimeraQueryAlreadyRunningError} If deleting or updating already in progress
|
|
1143
1265
|
*/
|
|
1144
1266
|
update(newItem, force = false) {
|
|
1145
|
-
if (this.#state === ChimeraQueryFetchingState.Creating) throw new ChimeraQueryNotCreatedError(this.#
|
|
1267
|
+
if (this.#state === ChimeraQueryFetchingState.Creating) throw new ChimeraQueryNotCreatedError(this.#entityConfig.name);
|
|
1146
1268
|
if (!force && [
|
|
1147
1269
|
ChimeraQueryFetchingState.Fetching,
|
|
1148
1270
|
ChimeraQueryFetchingState.Refetching,
|
|
1149
1271
|
ChimeraQueryFetchingState.Deleting
|
|
1150
|
-
].includes(this.#state)) throw new ChimeraQueryAlreadyRunningError(this.#
|
|
1272
|
+
].includes(this.#state)) throw new ChimeraQueryAlreadyRunningError(this.#entityConfig.name, this.#state);
|
|
1151
1273
|
this.#mutableItem();
|
|
1152
1274
|
return this.#updateItem(newItem);
|
|
1153
1275
|
}
|
|
@@ -1160,12 +1282,12 @@ var ChimeraItemQuery = class extends ChimeraEventEmitter {
|
|
|
1160
1282
|
* @throws {ChimeraQueryAlreadyRunningError} If deleting or updating already in progress
|
|
1161
1283
|
*/
|
|
1162
1284
|
mutate(mutator, force = false) {
|
|
1163
|
-
if (this.#state === ChimeraQueryFetchingState.Creating) throw new ChimeraQueryNotCreatedError(this.#
|
|
1285
|
+
if (this.#state === ChimeraQueryFetchingState.Creating) throw new ChimeraQueryNotCreatedError(this.#entityConfig.name);
|
|
1164
1286
|
if (!force && [
|
|
1165
1287
|
ChimeraQueryFetchingState.Fetching,
|
|
1166
1288
|
ChimeraQueryFetchingState.Refetching,
|
|
1167
1289
|
ChimeraQueryFetchingState.Deleting
|
|
1168
|
-
].includes(this.#state)) throw new ChimeraQueryAlreadyRunningError(this.#
|
|
1290
|
+
].includes(this.#state)) throw new ChimeraQueryAlreadyRunningError(this.#entityConfig.name, this.#state);
|
|
1169
1291
|
const item = deepObjectClone(this.#mutableItem());
|
|
1170
1292
|
return this.#updateItem(mutator(item) ?? item);
|
|
1171
1293
|
}
|
|
@@ -1175,12 +1297,12 @@ var ChimeraItemQuery = class extends ChimeraEventEmitter {
|
|
|
1175
1297
|
* @throws {ChimeraQueryAlreadyRunningError} If deleting or updating already in progress
|
|
1176
1298
|
*/
|
|
1177
1299
|
commit(force = false) {
|
|
1178
|
-
if (this.#state === ChimeraQueryFetchingState.Creating) throw new ChimeraQueryNotCreatedError(this.#
|
|
1300
|
+
if (this.#state === ChimeraQueryFetchingState.Creating) throw new ChimeraQueryNotCreatedError(this.#entityConfig.name);
|
|
1179
1301
|
if (!force && [
|
|
1180
1302
|
ChimeraQueryFetchingState.Fetching,
|
|
1181
1303
|
ChimeraQueryFetchingState.Refetching,
|
|
1182
1304
|
ChimeraQueryFetchingState.Deleting
|
|
1183
|
-
].includes(this.#state)) throw new ChimeraQueryAlreadyRunningError(this.#
|
|
1305
|
+
].includes(this.#state)) throw new ChimeraQueryAlreadyRunningError(this.#entityConfig.name, this.#state);
|
|
1184
1306
|
this.#mutableItem();
|
|
1185
1307
|
return this.#updateItem(this.#mutable);
|
|
1186
1308
|
}
|
|
@@ -1192,12 +1314,12 @@ var ChimeraItemQuery = class extends ChimeraEventEmitter {
|
|
|
1192
1314
|
* @throws {ChimeraQueryAlreadyRunningError} If deleting or updating already in progress
|
|
1193
1315
|
*/
|
|
1194
1316
|
delete(force = false) {
|
|
1195
|
-
if (this.#state === ChimeraQueryFetchingState.Creating) throw new ChimeraQueryNotCreatedError(this.#
|
|
1317
|
+
if (this.#state === ChimeraQueryFetchingState.Creating) throw new ChimeraQueryNotCreatedError(this.#entityConfig.name);
|
|
1196
1318
|
if (!force && [
|
|
1197
1319
|
ChimeraQueryFetchingState.Fetching,
|
|
1198
1320
|
ChimeraQueryFetchingState.Refetching,
|
|
1199
1321
|
ChimeraQueryFetchingState.Updating
|
|
1200
|
-
].includes(this.#state)) throw new ChimeraQueryAlreadyRunningError(this.#
|
|
1322
|
+
].includes(this.#state)) throw new ChimeraQueryAlreadyRunningError(this.#entityConfig.name, this.#state);
|
|
1201
1323
|
return this.#requestDelete();
|
|
1202
1324
|
}
|
|
1203
1325
|
toJSON() {
|
|
@@ -1209,7 +1331,7 @@ var ChimeraItemQuery = class extends ChimeraEventEmitter {
|
|
|
1209
1331
|
};
|
|
1210
1332
|
|
|
1211
1333
|
//#endregion
|
|
1212
|
-
//#region src/shared/ChimeraWeakValueMap/ChimeraWeakValueMap.ts
|
|
1334
|
+
//#region ../../src/shared/ChimeraWeakValueMap/ChimeraWeakValueMap.ts
|
|
1213
1335
|
var ChimeraWeakValueMap = class extends ChimeraEventEmitter {
|
|
1214
1336
|
#map;
|
|
1215
1337
|
#registry;
|
|
@@ -1385,11 +1507,12 @@ var ChimeraWeakValueMap = class extends ChimeraEventEmitter {
|
|
|
1385
1507
|
};
|
|
1386
1508
|
|
|
1387
1509
|
//#endregion
|
|
1388
|
-
//#region src/store/
|
|
1389
|
-
var
|
|
1510
|
+
//#region ../../src/entity-store/ChimeraEntityStore.ts
|
|
1511
|
+
var ChimeraEntityStore = class extends ChimeraEventEmitter {
|
|
1390
1512
|
#entityConfig;
|
|
1391
1513
|
#filterConfig;
|
|
1392
1514
|
#orderConfig;
|
|
1515
|
+
#debugConfig;
|
|
1393
1516
|
#idGetter;
|
|
1394
1517
|
#itemsMap;
|
|
1395
1518
|
#collectionQueryMap;
|
|
@@ -1401,7 +1524,7 @@ var ChimeraEntityRepository = class extends ChimeraEventEmitter {
|
|
|
1401
1524
|
throw new ChimeraInternalError("External events dispatching is not supported.");
|
|
1402
1525
|
}
|
|
1403
1526
|
#registerUpdate(item, skipItem) {
|
|
1404
|
-
const id = this.#idGetter(item);
|
|
1527
|
+
const id = this.#idGetter(item, this.#entityConfig.name);
|
|
1405
1528
|
const oldItem = this.#itemsMap.get(id);
|
|
1406
1529
|
this.#itemsMap.set(id, item);
|
|
1407
1530
|
const itemQuery = this.#itemQueryMap.get(id);
|
|
@@ -1468,12 +1591,12 @@ var ChimeraEntityRepository = class extends ChimeraEventEmitter {
|
|
|
1468
1591
|
#simplifyCollectionParams(params) {
|
|
1469
1592
|
return {
|
|
1470
1593
|
filter: simplifyFilter(params.filter),
|
|
1471
|
-
|
|
1472
|
-
|
|
1594
|
+
order: simplifyOrderBy(params.order),
|
|
1595
|
+
meta: params.meta
|
|
1473
1596
|
};
|
|
1474
1597
|
}
|
|
1475
1598
|
#getCollectionKey({ order, filter }) {
|
|
1476
|
-
return
|
|
1599
|
+
return `${this.#entityConfig.name}:ORDER<${order ? this.#orderConfig.getKey(order) : ""}>:FILTER<${filter ? this.#filterConfig.getFilterKey(filter) : ""}>`;
|
|
1477
1600
|
}
|
|
1478
1601
|
#collectionUpdateHandler(query, items) {
|
|
1479
1602
|
this.#propagateUpdateMany(items, { collection: query });
|
|
@@ -1499,43 +1622,47 @@ var ChimeraEntityRepository = class extends ChimeraEventEmitter {
|
|
|
1499
1622
|
for (const q of this.#collectionQueryMap.values()) if (q.ready && isFilterSubset(q[ChimeraGetParamsSym].filter, filter, this.#filterConfig.getOperatorKey)) return q;
|
|
1500
1623
|
return null;
|
|
1501
1624
|
}
|
|
1502
|
-
constructor(config, filterConfig, orderConfig) {
|
|
1625
|
+
constructor(config, filterConfig, orderConfig, debugConfig) {
|
|
1503
1626
|
super();
|
|
1504
1627
|
this.#entityConfig = config;
|
|
1505
1628
|
this.#filterConfig = filterConfig;
|
|
1506
1629
|
this.#orderConfig = orderConfig;
|
|
1507
|
-
this.#
|
|
1630
|
+
this.#debugConfig = debugConfig;
|
|
1631
|
+
this.#idGetter = typeof this.#entityConfig.idGetter === "function" ? this.#entityConfig.idGetter : (entity) => entity[this.#entityConfig.idGetter];
|
|
1508
1632
|
this.#itemsMap = new ChimeraWeakValueMap();
|
|
1509
1633
|
this.#collectionQueryMap = new ChimeraWeakValueMap();
|
|
1510
1634
|
this.#itemQueryMap = new ChimeraWeakValueMap();
|
|
1511
1635
|
this.#emit("initialized", { instance: this });
|
|
1512
1636
|
}
|
|
1513
|
-
|
|
1514
|
-
this.#
|
|
1637
|
+
get name() {
|
|
1638
|
+
return this.#entityConfig.name;
|
|
1515
1639
|
}
|
|
1516
|
-
|
|
1640
|
+
updateOne(TItem) {
|
|
1641
|
+
this.#propagateUpdateOne(TItem);
|
|
1642
|
+
}
|
|
1643
|
+
deleteOne(id) {
|
|
1517
1644
|
this.#propagateDeleteOne(id);
|
|
1518
1645
|
}
|
|
1519
|
-
|
|
1646
|
+
updateMany(items) {
|
|
1520
1647
|
this.#propagateUpdateMany(items);
|
|
1521
1648
|
}
|
|
1522
|
-
|
|
1649
|
+
deleteMany(ids) {
|
|
1523
1650
|
this.#propagateDeleteMany(ids);
|
|
1524
1651
|
}
|
|
1525
|
-
|
|
1652
|
+
updateMixed(toAdd, toDelete) {
|
|
1526
1653
|
this.#propagateUpdateMany(toAdd);
|
|
1527
1654
|
this.#propagateDeleteMany(toDelete);
|
|
1528
1655
|
}
|
|
1529
|
-
createItem(
|
|
1530
|
-
return this.#prepareItemQuery(new ChimeraItemQuery(this.#entityConfig, {
|
|
1656
|
+
createItem(TItem, meta) {
|
|
1657
|
+
return this.#prepareItemQuery(new ChimeraItemQuery(this.#entityConfig, this.#debugConfig, {
|
|
1531
1658
|
id: "",
|
|
1532
1659
|
meta
|
|
1533
|
-
}, null,
|
|
1660
|
+
}, null, TItem));
|
|
1534
1661
|
}
|
|
1535
1662
|
getItem(id, meta) {
|
|
1536
1663
|
const query = this.#itemQueryMap.get(id);
|
|
1537
1664
|
if (query) return query;
|
|
1538
|
-
return this.#prepareItemQuery(new ChimeraItemQuery(this.#entityConfig, {
|
|
1665
|
+
return this.#prepareItemQuery(new ChimeraItemQuery(this.#entityConfig, this.#debugConfig, {
|
|
1539
1666
|
id,
|
|
1540
1667
|
meta
|
|
1541
1668
|
}, this.#itemsMap.get(id) ?? null, null));
|
|
@@ -1545,138 +1672,17 @@ var ChimeraEntityRepository = class extends ChimeraEventEmitter {
|
|
|
1545
1672
|
const key = this.#getCollectionKey(simplifiedParams);
|
|
1546
1673
|
const query = this.#collectionQueryMap.get(key);
|
|
1547
1674
|
if (query) return query;
|
|
1548
|
-
return this.#prepareCollectionQuery(new ChimeraCollectionQuery(this.#entityConfig, simplifiedParams, this.#getParentQuery(simplifiedParams.filter), buildComparator(this.#orderConfig.primitiveComparator, params.order), compileFilter(this.#filterConfig, params.filter), false));
|
|
1549
|
-
}
|
|
1550
|
-
};
|
|
1551
|
-
|
|
1552
|
-
//#endregion
|
|
1553
|
-
//#region src/store/ChimeraStore.ts
|
|
1554
|
-
const resolveIdGetter = (key, def, val) => {
|
|
1555
|
-
if (val) return typeof val === "function" ? val : (v) => v[val];
|
|
1556
|
-
return typeof def === "function" ? (v) => def(key, v) : (v) => v[def];
|
|
1557
|
-
};
|
|
1558
|
-
var ChimeraStore = class extends ChimeraEventEmitter {
|
|
1559
|
-
#reposMap;
|
|
1560
|
-
#queryConfig;
|
|
1561
|
-
#filterConfig;
|
|
1562
|
-
#orderConfig;
|
|
1563
|
-
#debugConfig;
|
|
1564
|
-
#initialConfig;
|
|
1565
|
-
#emit(event, arg) {
|
|
1566
|
-
queueMicrotask(() => super.emit(event, arg));
|
|
1567
|
-
}
|
|
1568
|
-
emit() {
|
|
1569
|
-
throw new ChimeraInternalError("External events dispatching is not supported.");
|
|
1570
|
-
}
|
|
1571
|
-
#addRepository(entityName) {
|
|
1572
|
-
const repo = this.#reposMap[entityName] = new ChimeraEntityRepository(this.#queryConfig[entityName], this.#filterConfig, this.#orderConfig);
|
|
1573
|
-
repo.once("initialized", (e) => this.#emit("repositoryInitialized", {
|
|
1574
|
-
entityName,
|
|
1575
|
-
instance: this,
|
|
1576
|
-
repository: e.instance
|
|
1577
|
-
}));
|
|
1578
|
-
return repo;
|
|
1579
|
-
}
|
|
1580
|
-
constructor(config) {
|
|
1581
|
-
super();
|
|
1582
|
-
this.#initialConfig = deepObjectFreeze(deepObjectClone(config));
|
|
1583
|
-
const { query: queryConfig, order: orderConfig, filter: filterConfig, debug: debugConfig } = config;
|
|
1584
|
-
this.#filterConfig = deepObjectAssign(deepObjectClone(chimeraDefaultFilterConfig), filterConfig ?? {});
|
|
1585
|
-
this.#orderConfig = deepObjectAssign(deepObjectClone(chimeraDefaultOrderConfig), orderConfig ?? {});
|
|
1586
|
-
this.#debugConfig = deepObjectAssign(deepObjectClone(chimeraDefaultDebugConfig), debugConfig ?? {});
|
|
1587
|
-
const query = deepObjectAssign(deepObjectClone(chimeraDefaultQueryConfig), queryConfig?.defaults ?? {});
|
|
1588
|
-
this.#queryConfig = Object.fromEntries(Object.entries(queryConfig?.entities ?? chimeraDefaultQueryConfig.entities).map(([key, value]) => [key, {
|
|
1589
|
-
batchedCreator: value.batchedCreator ? value.batchedCreator : (...args) => query.batchedCreator(key, ...args),
|
|
1590
|
-
batchedDeleter: value.batchedDeleter ? value.batchedDeleter : (...args) => query.batchedDeleter(key, ...args),
|
|
1591
|
-
batchedUpdater: value.batchedUpdater ? value.batchedUpdater : (...args) => query.batchedUpdater(key, ...args),
|
|
1592
|
-
collectionFetcher: value.collectionFetcher ? value.collectionFetcher : (...args) => query.collectionFetcher(key, ...args),
|
|
1593
|
-
devMode: this.#debugConfig.devMode,
|
|
1594
|
-
idGetter: resolveIdGetter(key, query.idGetter, value.idGetter),
|
|
1595
|
-
itemCreator: value.itemCreator ? value.itemCreator : (...args) => query.itemCreator(key, ...args),
|
|
1596
|
-
itemDeleter: value.itemDeleter ? value.itemDeleter : (...args) => query.itemDeleter(key, ...args),
|
|
1597
|
-
itemFetcher: value.itemFetcher ? value.itemFetcher : (...args) => query.itemFetcher(key, ...args),
|
|
1598
|
-
itemUpdater: value.itemUpdater ? value.itemUpdater : (...args) => query.itemUpdater(key, ...args),
|
|
1599
|
-
name: key,
|
|
1600
|
-
trustQuery: value.trustQuery ?? query.trustQuery,
|
|
1601
|
-
updateDebounceTimeout: value.updateDebounceTimeout ?? query.updateDebounceTimeout
|
|
1602
|
-
}]));
|
|
1603
|
-
this.#reposMap = {};
|
|
1604
|
-
this.#emit("initialized", { instance: this });
|
|
1605
|
-
}
|
|
1606
|
-
get config() {
|
|
1607
|
-
return this.#initialConfig;
|
|
1608
|
-
}
|
|
1609
|
-
from(entityName) {
|
|
1610
|
-
return this.#reposMap[entityName] ?? this.#addRepository(entityName);
|
|
1611
|
-
}
|
|
1612
|
-
updateOne(entityName, item) {
|
|
1613
|
-
const repo = this.#reposMap[entityName];
|
|
1614
|
-
if (repo) {
|
|
1615
|
-
repo[ChimeraSetOneSym](item);
|
|
1616
|
-
this.#emit("itemUpdated", {
|
|
1617
|
-
entityName,
|
|
1618
|
-
instance: this,
|
|
1619
|
-
item,
|
|
1620
|
-
repository: repo
|
|
1621
|
-
});
|
|
1622
|
-
}
|
|
1623
|
-
}
|
|
1624
|
-
updateMany(entityName, items) {
|
|
1625
|
-
const repo = this.#reposMap[entityName];
|
|
1626
|
-
if (repo) {
|
|
1627
|
-
repo[ChimeraSetManySym](items);
|
|
1628
|
-
this.#emit("updated", {
|
|
1629
|
-
entityName,
|
|
1630
|
-
instance: this,
|
|
1631
|
-
items,
|
|
1632
|
-
repository: repo
|
|
1633
|
-
});
|
|
1634
|
-
}
|
|
1635
|
-
}
|
|
1636
|
-
deleteOne(entityName, id) {
|
|
1637
|
-
const repo = this.#reposMap[entityName];
|
|
1638
|
-
if (repo) {
|
|
1639
|
-
repo[ChimeraDeleteOneSym](id);
|
|
1640
|
-
this.#emit("itemDeleted", {
|
|
1641
|
-
entityName,
|
|
1642
|
-
id,
|
|
1643
|
-
instance: this,
|
|
1644
|
-
repository: repo
|
|
1645
|
-
});
|
|
1646
|
-
}
|
|
1647
|
-
}
|
|
1648
|
-
deleteMany(entityName, ids) {
|
|
1649
|
-
const repo = this.#reposMap[entityName];
|
|
1650
|
-
if (repo) {
|
|
1651
|
-
repo[ChimeraDeleteManySym](ids);
|
|
1652
|
-
this.#emit("deleted", {
|
|
1653
|
-
entityName,
|
|
1654
|
-
ids,
|
|
1655
|
-
instance: this,
|
|
1656
|
-
repository: repo
|
|
1657
|
-
});
|
|
1658
|
-
}
|
|
1659
|
-
}
|
|
1660
|
-
updateMixed(entityName, toAdd, toDelete) {
|
|
1661
|
-
const repo = this.#reposMap[entityName];
|
|
1662
|
-
if (repo) {
|
|
1663
|
-
repo[ChimeraUpdateMixedSym](toAdd, toDelete);
|
|
1664
|
-
this.#emit("deleted", {
|
|
1665
|
-
entityName,
|
|
1666
|
-
ids: toDelete,
|
|
1667
|
-
instance: this,
|
|
1668
|
-
repository: repo
|
|
1669
|
-
});
|
|
1670
|
-
this.#emit("updated", {
|
|
1671
|
-
entityName,
|
|
1672
|
-
instance: this,
|
|
1673
|
-
items: toAdd,
|
|
1674
|
-
repository: repo
|
|
1675
|
-
});
|
|
1676
|
-
}
|
|
1675
|
+
return this.#prepareCollectionQuery(new ChimeraCollectionQuery(this.#entityConfig, this.#debugConfig, simplifiedParams, this.#getParentQuery(simplifiedParams.filter), buildComparator(this.#orderConfig.primitiveComparator, params.order), compileFilter(this.#filterConfig, params.filter), false));
|
|
1677
1676
|
}
|
|
1678
1677
|
};
|
|
1678
|
+
function createChimeraEntityStore(entityConfig, filterConfig, orderConfig, debugConfig) {
|
|
1679
|
+
return new ChimeraEntityStore({
|
|
1680
|
+
...chimeraDefaultQueryEntityConfig,
|
|
1681
|
+
...entityConfig,
|
|
1682
|
+
idGetter: typeof entityConfig.idGetter === "function" ? entityConfig.idGetter : (entity) => entity[entityConfig.idGetter]
|
|
1683
|
+
}, filterConfig ?? chimeraDefaultFilterConfig, orderConfig ?? chimeraDefaultOrderConfig, debugConfig ?? chimeraDefaultDebugConfig);
|
|
1684
|
+
}
|
|
1679
1685
|
|
|
1680
1686
|
//#endregion
|
|
1681
|
-
export {
|
|
1682
|
-
//# sourceMappingURL=
|
|
1687
|
+
export { ChimeraCollectionQuery, ChimeraEntityStore, ChimeraError, ChimeraEventEmitter, ChimeraFilterError, ChimeraFilterOperatorError, ChimeraFilterOperatorNotFoundError, ChimeraInternalError, ChimeraItemQuery, ChimeraOrderError, ChimeraOrderNulls, ChimeraOrderTypeComparisonError, ChimeraOrderTypeError, ChimeraQueryError, ChimeraQueryFetchingState, ChimeraQueryIdMismatchError, ChimeraQueryNotSpecifiedError, ChimeraQueryTrustError, ChimeraQueryTrustFetchedCollectionError, ChimeraQueryTrustIdMismatchError, ChimeraWeakValueMap, chimeraCreateConjunction, chimeraCreateNot, chimeraCreateOperator, chimeraCreateOrderBy, chimeraIsConjunction, chimeraIsOperator, createChimeraEntityStore };
|
|
1688
|
+
//# sourceMappingURL=index.mjs.map
|