@hf-chimera/store 0.0.15 → 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 -42
- package/.changeset/README.md +0 -8
- package/CHANGELOG.md +0 -92
- package/dist/adapters/react.cjs +0 -122
- package/dist/adapters/react.cjs.map +0 -1
- package/dist/adapters/react.d.cts +0 -39
- package/dist/adapters/react.d.cts.map +0 -1
- package/dist/adapters/react.d.ts +0 -39
- package/dist/adapters/react.d.ts.map +0 -1
- package/dist/adapters/react.js +0 -92
- package/dist/adapters/react.js.map +0 -1
- package/dist/defaults-Bg1kIemd.cjs +0 -372
- package/dist/defaults-Bg1kIemd.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-B6sY7hiW.d.ts +0 -22
- package/dist/index-B6sY7hiW.d.ts.map +0 -1
- package/dist/index-CTTQ1Hr3.d.ts +0 -821
- package/dist/index-CTTQ1Hr3.d.ts.map +0 -1
- package/dist/index-CiER0sxG.d.cts +0 -22
- package/dist/index-CiER0sxG.d.cts.map +0 -1
- package/dist/index-CkaYmEhA.d.cts +0 -821
- package/dist/index-CkaYmEhA.d.cts.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -4
- package/dist/qb-PXzZgo2H.cjs +0 -50
- package/dist/qb-PXzZgo2H.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-TJG6k3Nr.cjs +0 -1771
- package/dist/src-TJG6k3Nr.cjs.map +0 -1
package/dist/src-TJG6k3Nr.cjs
DELETED
|
@@ -1,1771 +0,0 @@
|
|
|
1
|
-
const require_defaults = require('./defaults-Bg1kIemd.cjs');
|
|
2
|
-
|
|
3
|
-
//#region src/filter/errors.ts
|
|
4
|
-
var ChimeraFilterError = class extends require_defaults.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
|
|
18
|
-
const deepObjectAssign = (dst, srcObj, visited = /* @__PURE__ */ new WeakSet()) => {
|
|
19
|
-
for (const { 0: key, 1: srcVal } of Object.entries(srcObj)) {
|
|
20
|
-
if (srcVal === null || typeof srcVal !== "object" || Array.isArray(srcVal)) {
|
|
21
|
-
dst[key] = srcVal;
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
if (visited.has(srcVal)) {
|
|
25
|
-
dst[key] = srcVal;
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
visited.add(srcVal);
|
|
29
|
-
const destVal = dst[key];
|
|
30
|
-
dst[key] = destVal === null || typeof destVal !== "object" || Array.isArray(destVal) ? {} : destVal;
|
|
31
|
-
deepObjectAssign(dst[key], srcVal, visited);
|
|
32
|
-
visited.delete(srcVal);
|
|
33
|
-
}
|
|
34
|
-
return dst;
|
|
35
|
-
};
|
|
36
|
-
const deepObjectFreeze = (obj, frozenObjects = /* @__PURE__ */ new WeakSet()) => {
|
|
37
|
-
if (obj === null || typeof obj !== "object" || Object.isFrozen(obj) || frozenObjects.has(obj)) return obj;
|
|
38
|
-
frozenObjects.add(obj);
|
|
39
|
-
for (const value of Object.values(obj)) if (value && typeof value === "object") deepObjectFreeze(value, frozenObjects);
|
|
40
|
-
return Object.freeze(obj);
|
|
41
|
-
};
|
|
42
|
-
const TypedArray = Object.getPrototypeOf(Int8Array);
|
|
43
|
-
const deepObjectClone = (value, refs) => {
|
|
44
|
-
if (value === null) return null;
|
|
45
|
-
if (value === void 0) return void 0;
|
|
46
|
-
if (typeof value !== "object") return value;
|
|
47
|
-
if (refs) {
|
|
48
|
-
const ref = refs.get(value);
|
|
49
|
-
if (ref !== void 0) return ref;
|
|
50
|
-
}
|
|
51
|
-
if (value.constructor === Object) {
|
|
52
|
-
const keys$1 = Object.keys(value).concat(Object.getOwnPropertySymbols(value));
|
|
53
|
-
const length$1 = keys$1.length;
|
|
54
|
-
const clone$1 = {};
|
|
55
|
-
refs ??= /* @__PURE__ */ new Map();
|
|
56
|
-
refs.set(value, clone$1);
|
|
57
|
-
for (let i = 0; i < length$1; i++) clone$1[keys$1[i]] = deepObjectClone(value[keys$1[i]], refs);
|
|
58
|
-
return clone$1;
|
|
59
|
-
}
|
|
60
|
-
if (Array.isArray(value)) {
|
|
61
|
-
const length$1 = value.length;
|
|
62
|
-
const clone$1 = new Array(length$1);
|
|
63
|
-
refs ??= /* @__PURE__ */ new Map();
|
|
64
|
-
refs.set(value, clone$1);
|
|
65
|
-
for (let i = 0; i < length$1; i++) clone$1[i] = deepObjectClone(value[i], refs);
|
|
66
|
-
return clone$1;
|
|
67
|
-
}
|
|
68
|
-
if (value instanceof Date) return new value.constructor(value.valueOf());
|
|
69
|
-
if (value instanceof RegExp) return value.constructor;
|
|
70
|
-
if (value instanceof Map) {
|
|
71
|
-
const clone$1 = new value.constructor();
|
|
72
|
-
refs ??= /* @__PURE__ */ new Map();
|
|
73
|
-
refs.set(value, clone$1);
|
|
74
|
-
for (const entry of value.entries()) clone$1.set(entry[0], deepObjectClone(entry[1], refs));
|
|
75
|
-
return clone$1;
|
|
76
|
-
}
|
|
77
|
-
if (value instanceof Set) {
|
|
78
|
-
const clone$1 = new value.constructor();
|
|
79
|
-
refs ??= /* @__PURE__ */ new Map();
|
|
80
|
-
refs.set(value, clone$1);
|
|
81
|
-
for (const entry of value.values()) clone$1.add(deepObjectClone(entry, refs));
|
|
82
|
-
return clone$1;
|
|
83
|
-
}
|
|
84
|
-
if (value instanceof Error) {
|
|
85
|
-
const clone$1 = new value.constructor(value.message);
|
|
86
|
-
const keys$1 = Object.keys(value).concat(Object.getOwnPropertySymbols(value));
|
|
87
|
-
const length$1 = keys$1.length;
|
|
88
|
-
refs ??= /* @__PURE__ */ new Map();
|
|
89
|
-
refs.set(value, clone$1);
|
|
90
|
-
for (let i = 0; i < length$1; i++) clone$1[keys$1[i]] = deepObjectClone(value[keys$1[i]], refs);
|
|
91
|
-
return clone$1;
|
|
92
|
-
}
|
|
93
|
-
if (value instanceof ArrayBuffer) return value.slice();
|
|
94
|
-
if (value instanceof TypedArray) return value.slice();
|
|
95
|
-
if (value instanceof DataView) return new DataView(value.buffer.slice());
|
|
96
|
-
if (value instanceof WeakMap) return value;
|
|
97
|
-
if (value instanceof WeakSet) return value;
|
|
98
|
-
const clone = Object.create(value.constructor.prototype);
|
|
99
|
-
const keys = Object.keys(value).concat(Object.getOwnPropertySymbols(value));
|
|
100
|
-
const length = keys.length;
|
|
101
|
-
refs ??= /* @__PURE__ */ new Map();
|
|
102
|
-
refs.set(value, clone);
|
|
103
|
-
for (let i = 0; i < length; i++) clone[keys[i]] = deepObjectClone(value[keys[i]], refs);
|
|
104
|
-
return clone;
|
|
105
|
-
};
|
|
106
|
-
const compilePropertyGetter = ({ get }) => typeof get === "function" ? get : (e) => e[get];
|
|
107
|
-
const simplifyPropertyGetter = ({ key }) => key;
|
|
108
|
-
const makeCancellablePromise = (promise, controller = new AbortController()) => {
|
|
109
|
-
const signal = controller.signal;
|
|
110
|
-
const newPromise = promise.then((v) => signal.aborted ? new Promise(() => null) : v, (err) => {
|
|
111
|
-
return signal.aborted ? new Promise(() => null) : Promise.reject(err);
|
|
112
|
-
});
|
|
113
|
-
newPromise.cancel = () => controller.abort();
|
|
114
|
-
newPromise.cancelled = (cb) => signal.aborted ? queueMicrotask(cb) : signal.addEventListener("abort", cb);
|
|
115
|
-
if ("cancelled" in promise) {
|
|
116
|
-
promise.cancelled(() => newPromise.cancel());
|
|
117
|
-
controller.signal.addEventListener("abort", () => promise.cancel());
|
|
118
|
-
}
|
|
119
|
-
return newPromise;
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
//#endregion
|
|
123
|
-
//#region src/filter/constants.ts
|
|
124
|
-
const ChimeraOperatorSymbol = Symbol("ChimeraOperatorSymbol");
|
|
125
|
-
const ChimeraConjunctionSymbol = Symbol("ChimeraConjunctionSymbol");
|
|
126
|
-
|
|
127
|
-
//#endregion
|
|
128
|
-
//#region src/filter/filter.ts
|
|
129
|
-
const filterConjunctions = {
|
|
130
|
-
and: (operations) => operations.every((op) => op()),
|
|
131
|
-
not: (operations) => !operations.every((op) => op()),
|
|
132
|
-
or: (operations) => operations.some((op) => op())
|
|
133
|
-
};
|
|
134
|
-
const compileOperator = (config, { op, value, test }) => {
|
|
135
|
-
const operatorFunc = config.operators[op];
|
|
136
|
-
if (!operatorFunc) throw new ChimeraFilterOperatorNotFoundError(op);
|
|
137
|
-
const getter = compilePropertyGetter(value);
|
|
138
|
-
return (entity) => operatorFunc(getter(entity), test);
|
|
139
|
-
};
|
|
140
|
-
const compileConjunction = (config, { kind, operations }) => {
|
|
141
|
-
const conjunction = filterConjunctions[kind];
|
|
142
|
-
const compiledOperations = operations.map((operation) => {
|
|
143
|
-
switch (operation.type) {
|
|
144
|
-
case ChimeraOperatorSymbol: return compileOperator(config, operation);
|
|
145
|
-
case ChimeraConjunctionSymbol: return compileConjunction(config, operation);
|
|
146
|
-
default: throw new require_defaults.ChimeraInternalError(`Invalid filter operation ${operation.type}`);
|
|
147
|
-
}
|
|
148
|
-
}).filter(Boolean);
|
|
149
|
-
return (entity) => conjunction(compiledOperations.map((op) => () => op(entity)));
|
|
150
|
-
};
|
|
151
|
-
const simplifyOperator = ({ op, value, test }) => ({
|
|
152
|
-
key: simplifyPropertyGetter(value),
|
|
153
|
-
op,
|
|
154
|
-
test,
|
|
155
|
-
type: ChimeraOperatorSymbol
|
|
156
|
-
});
|
|
157
|
-
const compareSimplifiedOperator = (a, b) => a.key.localeCompare(b.key) || a.op.localeCompare(b.op) || JSON.stringify(a.test).localeCompare(JSON.stringify(b.test));
|
|
158
|
-
const compareSimplifiedOperation = (a, b) => {
|
|
159
|
-
if (a.type !== b.type) return a.type === ChimeraOperatorSymbol ? -1 : 1;
|
|
160
|
-
if (a.type === ChimeraOperatorSymbol && b.type === ChimeraOperatorSymbol) return compareSimplifiedOperator(a, b);
|
|
161
|
-
if (a.type === ChimeraConjunctionSymbol && b.type === ChimeraConjunctionSymbol) return compareSimplifiedConjunction(a, b);
|
|
162
|
-
return 0;
|
|
163
|
-
};
|
|
164
|
-
const compareSimplifiedConjunction = (a, b) => {
|
|
165
|
-
const kindCompare = a.kind.localeCompare(b.kind);
|
|
166
|
-
if (kindCompare !== 0) return kindCompare;
|
|
167
|
-
const aOps = a.operations;
|
|
168
|
-
const bOps = b.operations;
|
|
169
|
-
const minLength = Math.min(aOps.length, bOps.length);
|
|
170
|
-
for (let i = 0; i < minLength; i++) {
|
|
171
|
-
const aOp = aOps[i];
|
|
172
|
-
const bOp = bOps[i];
|
|
173
|
-
if (aOp && bOp) {
|
|
174
|
-
const compare = compareSimplifiedOperation(aOp, bOp);
|
|
175
|
-
if (compare !== 0) return compare;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return aOps.length - bOps.length;
|
|
179
|
-
};
|
|
180
|
-
const simplifyConjunction = ({ kind, operations }) => {
|
|
181
|
-
return {
|
|
182
|
-
kind,
|
|
183
|
-
operations: operations.map((op) => {
|
|
184
|
-
switch (op.type) {
|
|
185
|
-
case ChimeraOperatorSymbol: return simplifyOperator(op);
|
|
186
|
-
case ChimeraConjunctionSymbol: return simplifyConjunction(op);
|
|
187
|
-
default: throw new require_defaults.ChimeraInternalError(`Invalid filter operation ${op.type}`);
|
|
188
|
-
}
|
|
189
|
-
}).filter(Boolean).sort((a, b) => compareSimplifiedOperation(a, b)),
|
|
190
|
-
type: ChimeraConjunctionSymbol
|
|
191
|
-
};
|
|
192
|
-
};
|
|
193
|
-
const chimeraCreateOperator = (op, value, test) => ({
|
|
194
|
-
op,
|
|
195
|
-
test,
|
|
196
|
-
type: ChimeraOperatorSymbol,
|
|
197
|
-
value: typeof value === "string" ? {
|
|
198
|
-
get: value,
|
|
199
|
-
key: value
|
|
200
|
-
} : value
|
|
201
|
-
});
|
|
202
|
-
const chimeraCreateConjunction = (kind, operations) => ({
|
|
203
|
-
kind,
|
|
204
|
-
operations,
|
|
205
|
-
type: ChimeraConjunctionSymbol
|
|
206
|
-
});
|
|
207
|
-
const chimeraCreateNot = (operation) => ({
|
|
208
|
-
kind: "not",
|
|
209
|
-
operations: [operation],
|
|
210
|
-
type: ChimeraConjunctionSymbol
|
|
211
|
-
});
|
|
212
|
-
function chimeraIsConjunction(item) {
|
|
213
|
-
return item.type === ChimeraConjunctionSymbol;
|
|
214
|
-
}
|
|
215
|
-
function chimeraIsOperator(item) {
|
|
216
|
-
return item.type === ChimeraOperatorSymbol;
|
|
217
|
-
}
|
|
218
|
-
const compileFilter = (config, descriptor) => descriptor ? compileConjunction(config, descriptor) : () => true;
|
|
219
|
-
const simplifyFilter = (descriptor) => descriptor ? simplifyConjunction(descriptor) : null;
|
|
220
|
-
const isOperationSubset = (candidateOp, targetOp, getOperatorKey) => {
|
|
221
|
-
if (candidateOp.type !== targetOp.type) return false;
|
|
222
|
-
if (candidateOp.type === ChimeraOperatorSymbol && targetOp.type === ChimeraOperatorSymbol) return candidateOp.key === targetOp.key && candidateOp.op === targetOp.op && getOperatorKey(candidateOp) === getOperatorKey(targetOp);
|
|
223
|
-
if (candidateOp.type === ChimeraConjunctionSymbol && targetOp.type === ChimeraConjunctionSymbol) return isConjunctionSubset(candidateOp, targetOp, getOperatorKey);
|
|
224
|
-
return false;
|
|
225
|
-
};
|
|
226
|
-
const isConjunctionSubset = (candidate, target, getOperatorKey) => {
|
|
227
|
-
if (candidate.kind !== target.kind) return false;
|
|
228
|
-
switch (candidate.kind) {
|
|
229
|
-
case "and":
|
|
230
|
-
case "not": return candidate.operations.every((candidateOp) => target.operations.some((targetOp) => isOperationSubset(candidateOp, targetOp, getOperatorKey)));
|
|
231
|
-
case "or": return target.operations.every((targetOp) => candidate.operations.some((candidateOp) => isOperationSubset(candidateOp, targetOp, getOperatorKey)));
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
const isFilterSubset = (candidate, target, getOperatorKey) => {
|
|
235
|
-
if (candidate === null) return true;
|
|
236
|
-
if (target === null) return false;
|
|
237
|
-
return isConjunctionSubset(candidate, target, getOperatorKey);
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
//#endregion
|
|
241
|
-
//#region src/order/types.ts
|
|
242
|
-
let ChimeraOrderNulls = /* @__PURE__ */ function(ChimeraOrderNulls$1) {
|
|
243
|
-
ChimeraOrderNulls$1["First"] = "first";
|
|
244
|
-
ChimeraOrderNulls$1["Last"] = "last";
|
|
245
|
-
return ChimeraOrderNulls$1;
|
|
246
|
-
}({});
|
|
247
|
-
|
|
248
|
-
//#endregion
|
|
249
|
-
//#region src/order/order.ts
|
|
250
|
-
const compileOrderDescriptor = ({ key, desc, nulls }) => ({
|
|
251
|
-
desc,
|
|
252
|
-
get: compilePropertyGetter(key),
|
|
253
|
-
nulls
|
|
254
|
-
});
|
|
255
|
-
const chimeraCreateOrderBy = (key, desc = false, nulls = ChimeraOrderNulls.Last) => ({
|
|
256
|
-
desc,
|
|
257
|
-
key: typeof key === "string" ? {
|
|
258
|
-
get: key,
|
|
259
|
-
key
|
|
260
|
-
} : key,
|
|
261
|
-
nulls
|
|
262
|
-
});
|
|
263
|
-
const nullsComparator = (a, b, nulls) => {
|
|
264
|
-
return a == b ? 0 : (a == null ? -1 : 1) * (nulls === ChimeraOrderNulls.First ? 1 : -1);
|
|
265
|
-
};
|
|
266
|
-
const buildComparator = (comparator, orderBy) => {
|
|
267
|
-
if (!orderBy) return () => 0;
|
|
268
|
-
const compiledPriority = orderBy.map((ob) => compileOrderDescriptor(ob));
|
|
269
|
-
return (a, b) => {
|
|
270
|
-
let result = 0;
|
|
271
|
-
for (const descriptor of compiledPriority) {
|
|
272
|
-
const vA = descriptor.get(a);
|
|
273
|
-
const vB = descriptor.get(b);
|
|
274
|
-
if (vA == null || vB == null) {
|
|
275
|
-
result = nullsComparator(vA, vB, descriptor.nulls);
|
|
276
|
-
if (result) break;
|
|
277
|
-
continue;
|
|
278
|
-
}
|
|
279
|
-
result = comparator(descriptor.get(a), descriptor.get(b));
|
|
280
|
-
descriptor.desc && (result *= -1);
|
|
281
|
-
if (result) break;
|
|
282
|
-
}
|
|
283
|
-
return result;
|
|
284
|
-
};
|
|
285
|
-
};
|
|
286
|
-
const simplifyOrderBy = (orderBy) => orderBy ? orderBy.map((ob) => ({
|
|
287
|
-
desc: ob.desc,
|
|
288
|
-
field: ob.key.key,
|
|
289
|
-
nulls: ob.nulls
|
|
290
|
-
})) : null;
|
|
291
|
-
|
|
292
|
-
//#endregion
|
|
293
|
-
//#region src/shared/ChimeraEventEmitter/ChimeraEventEmitter.ts
|
|
294
|
-
var Events = function Events$1() {};
|
|
295
|
-
Events.prototype = Object.create(null);
|
|
296
|
-
var ChimeraEventEmitter = class {
|
|
297
|
-
_events;
|
|
298
|
-
_eventsCount;
|
|
299
|
-
constructor() {
|
|
300
|
-
this._events = new Events();
|
|
301
|
-
this._eventsCount = 0;
|
|
302
|
-
}
|
|
303
|
-
#addListener(event, fn, once) {
|
|
304
|
-
var listener = {
|
|
305
|
-
fn,
|
|
306
|
-
once
|
|
307
|
-
};
|
|
308
|
-
if (!this._events[event]) {
|
|
309
|
-
this._events[event] = listener;
|
|
310
|
-
this._eventsCount++;
|
|
311
|
-
} else if (!this._events[event].fn) this._events[event].push(listener);
|
|
312
|
-
else this._events[event] = [this._events[event], listener];
|
|
313
|
-
return this;
|
|
314
|
-
}
|
|
315
|
-
#clearEvent(event) {
|
|
316
|
-
if (--this._eventsCount === 0) this._events = new Events();
|
|
317
|
-
else delete this._events[event];
|
|
318
|
-
}
|
|
319
|
-
eventNames() {
|
|
320
|
-
return Object.keys(this._events);
|
|
321
|
-
}
|
|
322
|
-
listeners(event) {
|
|
323
|
-
var handlers = this._events[event];
|
|
324
|
-
if (!handlers) return [];
|
|
325
|
-
if (handlers.fn) return [handlers.fn];
|
|
326
|
-
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) ee[i] = handlers[i].fn;
|
|
327
|
-
return ee;
|
|
328
|
-
}
|
|
329
|
-
listenerCount(event) {
|
|
330
|
-
var listeners = this._events[event];
|
|
331
|
-
if (!listeners) return 0;
|
|
332
|
-
if (listeners.fn) return 1;
|
|
333
|
-
return listeners.length;
|
|
334
|
-
}
|
|
335
|
-
removeListener(event, fn, once) {
|
|
336
|
-
if (!this._events[event]) return this;
|
|
337
|
-
if (!fn) {
|
|
338
|
-
this.#clearEvent(event);
|
|
339
|
-
return this;
|
|
340
|
-
}
|
|
341
|
-
var listeners = this._events[event];
|
|
342
|
-
if (listeners.fn) {
|
|
343
|
-
if (listeners.fn === fn && (!once || listeners.once)) this.#clearEvent(event);
|
|
344
|
-
} else {
|
|
345
|
-
for (var i = 0, events = [], length = listeners.length; i < length; i++) if (listeners[i].fn !== fn || once && !listeners[i].once) events.push(listeners[i]);
|
|
346
|
-
if (events.length) this._events[event] = events.length === 1 ? events[0] : events;
|
|
347
|
-
else this.#clearEvent(event);
|
|
348
|
-
}
|
|
349
|
-
return this;
|
|
350
|
-
}
|
|
351
|
-
emit(event, arg) {
|
|
352
|
-
if (!this._events[event]) return false;
|
|
353
|
-
var listeners = this._events[event];
|
|
354
|
-
if (listeners.fn) {
|
|
355
|
-
if (listeners.once) this.removeListener(event, listeners.fn, true);
|
|
356
|
-
listeners.fn.call(this, arg);
|
|
357
|
-
} else for (var i = 0, length = listeners.length; i < length; i++) {
|
|
358
|
-
if (listeners[i].once) this.removeListener(event, listeners[i].fn, true);
|
|
359
|
-
listeners[i].fn.call(this, arg);
|
|
360
|
-
}
|
|
361
|
-
return true;
|
|
362
|
-
}
|
|
363
|
-
on(event, fn) {
|
|
364
|
-
return this.#addListener(event, fn, false);
|
|
365
|
-
}
|
|
366
|
-
once(event, fn) {
|
|
367
|
-
return this.#addListener(event, fn, true);
|
|
368
|
-
}
|
|
369
|
-
removeAllListeners(event) {
|
|
370
|
-
if (event) {
|
|
371
|
-
if (this._events[event]) this.#clearEvent(event);
|
|
372
|
-
} else {
|
|
373
|
-
this._events = new Events();
|
|
374
|
-
this._eventsCount = 0;
|
|
375
|
-
}
|
|
376
|
-
return this;
|
|
377
|
-
}
|
|
378
|
-
off = this.removeListener;
|
|
379
|
-
addListener = this.on;
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
//#endregion
|
|
383
|
-
//#region src/query/types.ts
|
|
384
|
-
let ChimeraQueryFetchingState = /* @__PURE__ */ function(ChimeraQueryFetchingState$1) {
|
|
385
|
-
/** Query just initialized. */
|
|
386
|
-
ChimeraQueryFetchingState$1["Initialized"] = "initialized";
|
|
387
|
-
/** Not used yet. */
|
|
388
|
-
ChimeraQueryFetchingState$1["Scheduled"] = "scheduled";
|
|
389
|
-
/** Fetching in progress. */
|
|
390
|
-
ChimeraQueryFetchingState$1["Fetching"] = "fetching";
|
|
391
|
-
/** Creating in progress */
|
|
392
|
-
ChimeraQueryFetchingState$1["Creating"] = "creating";
|
|
393
|
-
/** Updating in progress. */
|
|
394
|
-
ChimeraQueryFetchingState$1["Updating"] = "updating";
|
|
395
|
-
/** Deleting in progress. */
|
|
396
|
-
ChimeraQueryFetchingState$1["Deleting"] = "deleting";
|
|
397
|
-
/** Fetch requested after reaching the Fetched, Errored, or Prefetched states. */
|
|
398
|
-
ChimeraQueryFetchingState$1["Refetching"] = "refetching";
|
|
399
|
-
/** Data retrieved from existing queries without initiating a fetch. */
|
|
400
|
-
ChimeraQueryFetchingState$1["Prefetched"] = "prefetched";
|
|
401
|
-
/** Fetch ended successfully; data is ready for use. */
|
|
402
|
-
ChimeraQueryFetchingState$1["Fetched"] = "fetched";
|
|
403
|
-
/** Fetch ended with an error; no data is available. */
|
|
404
|
-
ChimeraQueryFetchingState$1["Errored"] = "errored";
|
|
405
|
-
/** Refetch ended with an error, but old data is still available. */
|
|
406
|
-
ChimeraQueryFetchingState$1["ReErrored"] = "reErrored";
|
|
407
|
-
/**
|
|
408
|
-
* Only for the item query, data is deleted, but the local value is still present,
|
|
409
|
-
* no longer allows updates, but `refetch` still works (in case of strange errors, allows recovering state)
|
|
410
|
-
*/
|
|
411
|
-
ChimeraQueryFetchingState$1["Deleted"] = "deleted";
|
|
412
|
-
/** Only for the item query, data was actualized from an external event */
|
|
413
|
-
ChimeraQueryFetchingState$1["Actualized"] = "actualized";
|
|
414
|
-
return ChimeraQueryFetchingState$1;
|
|
415
|
-
}({});
|
|
416
|
-
|
|
417
|
-
//#endregion
|
|
418
|
-
//#region src/query/constants.ts
|
|
419
|
-
const ChimeraGetParamsSym = Symbol("ChimeraGetParamsSym");
|
|
420
|
-
const ChimeraSetOneSym = Symbol("ChimeraSetOneSym");
|
|
421
|
-
const ChimeraSetManySym = Symbol("ChimeraSetManySym");
|
|
422
|
-
const ChimeraDeleteOneSym = Symbol("ChimeraDeleteOneSym");
|
|
423
|
-
const ChimeraDeleteManySym = Symbol("ChimeraDeleteManySym");
|
|
424
|
-
const ChimeraUpdateMixedSym = Symbol("ChimeraUpdateMixedSym");
|
|
425
|
-
const IN_PROGRESS_STATES = [
|
|
426
|
-
ChimeraQueryFetchingState.Scheduled,
|
|
427
|
-
ChimeraQueryFetchingState.Creating,
|
|
428
|
-
ChimeraQueryFetchingState.Fetching,
|
|
429
|
-
ChimeraQueryFetchingState.Refetching,
|
|
430
|
-
ChimeraQueryFetchingState.Updating,
|
|
431
|
-
ChimeraQueryFetchingState.Deleting
|
|
432
|
-
];
|
|
433
|
-
|
|
434
|
-
//#endregion
|
|
435
|
-
//#region src/query/ChimeraCollectionQuery.ts
|
|
436
|
-
var ChimeraCollectionQuery = class extends ChimeraEventEmitter {
|
|
437
|
-
#state;
|
|
438
|
-
#promise;
|
|
439
|
-
#lastError;
|
|
440
|
-
#items;
|
|
441
|
-
#config;
|
|
442
|
-
#idGetter;
|
|
443
|
-
#params;
|
|
444
|
-
#order;
|
|
445
|
-
#filter;
|
|
446
|
-
#emit(event, arg) {
|
|
447
|
-
queueMicrotask(() => super.emit(event, arg));
|
|
448
|
-
}
|
|
449
|
-
emit() {
|
|
450
|
-
throw new require_defaults.ChimeraInternalError("External events dispatching is not supported.");
|
|
451
|
-
}
|
|
452
|
-
#prepareRequestParams() {
|
|
453
|
-
return { controller: new AbortController() };
|
|
454
|
-
}
|
|
455
|
-
#readyItems(internalMessage) {
|
|
456
|
-
if (this.#items) return this.#items;
|
|
457
|
-
throw internalMessage ? new require_defaults.ChimeraInternalError(internalMessage) : new require_defaults.ChimeraQueryNotReadyError(this.#config.name);
|
|
458
|
-
}
|
|
459
|
-
#addItem(item) {
|
|
460
|
-
const items = this.#readyItems("Trying to update not ready collection");
|
|
461
|
-
const foundIndex = items.findIndex((el) => this.#order(el, item) > 0);
|
|
462
|
-
items.splice(foundIndex !== -1 ? foundIndex : items.length, 0, item);
|
|
463
|
-
this.#emit("itemAdded", {
|
|
464
|
-
instance: this,
|
|
465
|
-
item
|
|
466
|
-
});
|
|
467
|
-
}
|
|
468
|
-
#setItems(items) {
|
|
469
|
-
!this.#items && this.#emit("ready", { instance: this });
|
|
470
|
-
const oldItems = this.#items;
|
|
471
|
-
this.#items = items;
|
|
472
|
-
this.#emit("updated", {
|
|
473
|
-
instance: this,
|
|
474
|
-
items,
|
|
475
|
-
oldItems
|
|
476
|
-
});
|
|
477
|
-
}
|
|
478
|
-
#setNewItems(items) {
|
|
479
|
-
items.forEach((i) => void deepObjectFreeze(i));
|
|
480
|
-
this.#emit("selfUpdated", {
|
|
481
|
-
instance: this,
|
|
482
|
-
items,
|
|
483
|
-
oldItems: this.#items
|
|
484
|
-
});
|
|
485
|
-
this.#setItems(items);
|
|
486
|
-
}
|
|
487
|
-
#setPromise(promise) {
|
|
488
|
-
this.#promise?.cancel();
|
|
489
|
-
this.#promise = promise;
|
|
490
|
-
return promise;
|
|
491
|
-
}
|
|
492
|
-
#deleteAtIndex(index) {
|
|
493
|
-
if (index === -1) return;
|
|
494
|
-
const { 0: old } = this.#readyItems("Trying to update not ready collection").splice(index, 1);
|
|
495
|
-
this.#emit("itemDeleted", {
|
|
496
|
-
instance: this,
|
|
497
|
-
item: old
|
|
498
|
-
});
|
|
499
|
-
}
|
|
500
|
-
#deleteItem(item) {
|
|
501
|
-
this.#deleteAtIndex(this.#readyItems("Trying to update not ready collection").indexOf(item));
|
|
502
|
-
}
|
|
503
|
-
#deleteById(id) {
|
|
504
|
-
this.#deleteAtIndex(this.#readyItems("Trying to update not ready collection").findIndex((item) => this.#idGetter(item) === id));
|
|
505
|
-
}
|
|
506
|
-
#replaceItem(oldItem, newItem) {
|
|
507
|
-
const items = this.#readyItems("Trying to update not ready collection");
|
|
508
|
-
const index = items.indexOf(oldItem);
|
|
509
|
-
const old = items[index];
|
|
510
|
-
items[index] = newItem;
|
|
511
|
-
this.#emit("itemUpdated", {
|
|
512
|
-
instance: this,
|
|
513
|
-
newItem,
|
|
514
|
-
oldItem: old
|
|
515
|
-
});
|
|
516
|
-
}
|
|
517
|
-
#getById(id) {
|
|
518
|
-
return this.#readyItems("Trying to update not ready collection").find((item) => this.#idGetter(item) === id);
|
|
519
|
-
}
|
|
520
|
-
#setOne(item) {
|
|
521
|
-
const existingItem = this.#getById(this.#idGetter(item));
|
|
522
|
-
const nowMatches = this.#filter(item);
|
|
523
|
-
if (!(nowMatches || existingItem)) return;
|
|
524
|
-
if (existingItem) {
|
|
525
|
-
if (this.#order(existingItem, item) === 0) {
|
|
526
|
-
this.#replaceItem(existingItem, item);
|
|
527
|
-
return;
|
|
528
|
-
}
|
|
529
|
-
this.#deleteItem(existingItem);
|
|
530
|
-
}
|
|
531
|
-
nowMatches && this.#addItem(item);
|
|
532
|
-
}
|
|
533
|
-
#setNewOne(item) {
|
|
534
|
-
deepObjectFreeze(item);
|
|
535
|
-
this.#setOne(item);
|
|
536
|
-
}
|
|
537
|
-
#apply(input) {
|
|
538
|
-
return input.filter((item) => this.#filter(item)).sort((a, b) => this.#order(a, b));
|
|
539
|
-
}
|
|
540
|
-
#validate(input) {
|
|
541
|
-
if (this.#config.trustQuery && !this.#config.devMode) return input;
|
|
542
|
-
const prepared = this.#apply(input);
|
|
543
|
-
if (!this.#config.trustQuery) return prepared;
|
|
544
|
-
if (this.#config.devMode) {
|
|
545
|
-
for (let i = 0; i < input.length; i++) if (input[i] !== prepared[i]) {
|
|
546
|
-
console.warn(new require_defaults.ChimeraQueryTrustFetchedCollectionError(this.#config.name, input, prepared));
|
|
547
|
-
break;
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
return input;
|
|
551
|
-
}
|
|
552
|
-
#setError(error, source) {
|
|
553
|
-
this.#state = this.#items ? ChimeraQueryFetchingState.ReErrored : ChimeraQueryFetchingState.Errored;
|
|
554
|
-
this.#lastError = error;
|
|
555
|
-
this.#emit("error", {
|
|
556
|
-
error,
|
|
557
|
-
instance: this
|
|
558
|
-
});
|
|
559
|
-
throw source;
|
|
560
|
-
}
|
|
561
|
-
#watchPromise(promise, controller) {
|
|
562
|
-
return makeCancellablePromise(promise.then((response) => {
|
|
563
|
-
this.#setNewItems(this.#validate(response.data));
|
|
564
|
-
this.#state = ChimeraQueryFetchingState.Fetched;
|
|
565
|
-
return response;
|
|
566
|
-
}).catch((error) => this.#setError(error, new require_defaults.ChimeraQueryFetchingError(this.#config.name, error))), controller);
|
|
567
|
-
}
|
|
568
|
-
constructor(config, params, existingItems, order, filter, alreadyValid) {
|
|
569
|
-
super();
|
|
570
|
-
this.#config = config;
|
|
571
|
-
this.#params = params;
|
|
572
|
-
this.#promise = null;
|
|
573
|
-
this.#items = null;
|
|
574
|
-
this.#state = ChimeraQueryFetchingState.Initialized;
|
|
575
|
-
this.#idGetter = config.idGetter;
|
|
576
|
-
this.#filter = filter;
|
|
577
|
-
this.#order = order;
|
|
578
|
-
if (existingItems) {
|
|
579
|
-
const input = Array.from(existingItems);
|
|
580
|
-
this.#setItems(alreadyValid ? this.#validate(input) : this.#apply(input));
|
|
581
|
-
this.#state = ChimeraQueryFetchingState.Prefetched;
|
|
582
|
-
} else {
|
|
583
|
-
this.#state = ChimeraQueryFetchingState.Fetching;
|
|
584
|
-
const { controller } = this.#prepareRequestParams();
|
|
585
|
-
this.#setPromise(this.#watchPromise(makeCancellablePromise(config.collectionFetcher(params, { signal: controller.signal }), controller), controller));
|
|
586
|
-
}
|
|
587
|
-
this.#emit("initialized", { instance: this });
|
|
588
|
-
}
|
|
589
|
-
get [ChimeraGetParamsSym]() {
|
|
590
|
-
return this.#params;
|
|
591
|
-
}
|
|
592
|
-
[ChimeraSetOneSym](item) {
|
|
593
|
-
this.#items && this.#setOne(item);
|
|
594
|
-
}
|
|
595
|
-
[ChimeraDeleteOneSym](id) {
|
|
596
|
-
this.#items && this.#deleteById(id);
|
|
597
|
-
}
|
|
598
|
-
[ChimeraSetManySym](items) {
|
|
599
|
-
if (this.#items) for (const item of items) this.#setOne(item);
|
|
600
|
-
}
|
|
601
|
-
[ChimeraDeleteManySym](ids) {
|
|
602
|
-
if (this.#items) for (const id of ids) this.#deleteById(id);
|
|
603
|
-
}
|
|
604
|
-
[ChimeraUpdateMixedSym](toAdd, toDelete) {
|
|
605
|
-
if (this.#items) {
|
|
606
|
-
for (const id of toDelete) this.#deleteById(id);
|
|
607
|
-
for (const item of toAdd) this.#setOne(item);
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
get state() {
|
|
611
|
-
return this.#state;
|
|
612
|
-
}
|
|
613
|
-
get inProgress() {
|
|
614
|
-
return IN_PROGRESS_STATES.includes(this.#state);
|
|
615
|
-
}
|
|
616
|
-
get ready() {
|
|
617
|
-
return this.#items !== null;
|
|
618
|
-
}
|
|
619
|
-
get lastError() {
|
|
620
|
-
return this.#lastError;
|
|
621
|
-
}
|
|
622
|
-
/**
|
|
623
|
-
* Wait for the current progress process to complete (both success or error)
|
|
624
|
-
*/
|
|
625
|
-
get progress() {
|
|
626
|
-
return new Promise((res) => {
|
|
627
|
-
const resolve = () => queueMicrotask(() => res());
|
|
628
|
-
if (this.#promise) {
|
|
629
|
-
this.#promise.then(resolve, resolve);
|
|
630
|
-
this.#promise.cancelled(() => this.progress.then(resolve, resolve));
|
|
631
|
-
} else resolve();
|
|
632
|
-
});
|
|
633
|
-
}
|
|
634
|
-
/**
|
|
635
|
-
* Wait for the current progress process to complete, throw an error if it fails
|
|
636
|
-
*/
|
|
637
|
-
get result() {
|
|
638
|
-
return new Promise((res, rej) => {
|
|
639
|
-
const resolve = () => queueMicrotask(() => res());
|
|
640
|
-
if (this.#promise) {
|
|
641
|
-
this.#promise.then(resolve, rej);
|
|
642
|
-
this.#promise.cancelled(() => this.#promise ? this.result.then(res, rej) : rej("cancelled"));
|
|
643
|
-
} else resolve();
|
|
644
|
-
});
|
|
645
|
-
}
|
|
646
|
-
/** Return an item if it is ready, throw error otherwise */
|
|
647
|
-
getById(id) {
|
|
648
|
-
return this.#readyItems().find((item) => this.#idGetter(item) === id);
|
|
649
|
-
}
|
|
650
|
-
/** Return mutable ref to item by idx if it is ready, throw error otherwise */
|
|
651
|
-
mutableAt(idx) {
|
|
652
|
-
return deepObjectClone(this.#readyItems().at(idx));
|
|
653
|
-
}
|
|
654
|
-
/** Return mutable ref to item by [id] if it is ready, throw error otherwise */
|
|
655
|
-
mutableGetById(id) {
|
|
656
|
-
return deepObjectClone(this.#readyItems().find((item) => this.#idGetter(item) === id));
|
|
657
|
-
}
|
|
658
|
-
/**
|
|
659
|
-
* Trigger refetch, return existing refetch promise if already running
|
|
660
|
-
* @param force If true cancels any running process and starts a new one
|
|
661
|
-
* @throws {ChimeraQueryAlreadyRunningError} If deleting or updating already in progress
|
|
662
|
-
*/
|
|
663
|
-
refetch(force = false) {
|
|
664
|
-
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 require_defaults.ChimeraQueryAlreadyRunningError(this.#config.name, this.#state);
|
|
666
|
-
this.#state = ChimeraQueryFetchingState.Refetching;
|
|
667
|
-
const { controller } = this.#prepareRequestParams();
|
|
668
|
-
return this.#setPromise(this.#watchPromise(makeCancellablePromise(this.#config.collectionFetcher(this.#params, { signal: controller.signal }), controller), controller));
|
|
669
|
-
}
|
|
670
|
-
/**
|
|
671
|
-
* Update item using updated copy
|
|
672
|
-
* @param newItem new item to update
|
|
673
|
-
*/
|
|
674
|
-
update(newItem) {
|
|
675
|
-
const { controller } = this.#prepareRequestParams();
|
|
676
|
-
return this.#config.itemUpdater(newItem, { signal: controller.signal }).then((response) => {
|
|
677
|
-
const { data } = response;
|
|
678
|
-
this.#items && this.#setNewOne(data);
|
|
679
|
-
this.#emit("selfItemUpdated", {
|
|
680
|
-
instance: this,
|
|
681
|
-
item: data
|
|
682
|
-
});
|
|
683
|
-
return response;
|
|
684
|
-
});
|
|
685
|
-
}
|
|
686
|
-
/**
|
|
687
|
-
* Update item using updated copy
|
|
688
|
-
* @param newItems array of items to update
|
|
689
|
-
*/
|
|
690
|
-
batchedUpdate(newItems) {
|
|
691
|
-
const { controller } = this.#prepareRequestParams();
|
|
692
|
-
return this.#config.batchedUpdater(Array.from(newItems), { signal: controller.signal }).then((response) => {
|
|
693
|
-
const ready = this.ready;
|
|
694
|
-
response.data.forEach((item) => {
|
|
695
|
-
ready && this.#setNewOne(item);
|
|
696
|
-
this.#emit("selfItemUpdated", {
|
|
697
|
-
instance: this,
|
|
698
|
-
item
|
|
699
|
-
});
|
|
700
|
-
});
|
|
701
|
-
return response;
|
|
702
|
-
});
|
|
703
|
-
}
|
|
704
|
-
/**
|
|
705
|
-
* Delete item using its [id]
|
|
706
|
-
* @param id id of item to delete
|
|
707
|
-
*/
|
|
708
|
-
delete(id) {
|
|
709
|
-
const { controller } = this.#prepareRequestParams();
|
|
710
|
-
return this.#config.itemDeleter(id, { signal: controller.signal }).then((response) => {
|
|
711
|
-
const { result: { id: newId, success } } = response;
|
|
712
|
-
if (!this.#items) {
|
|
713
|
-
success && this.#emit("selfItemDeleted", {
|
|
714
|
-
id: newId,
|
|
715
|
-
instance: this
|
|
716
|
-
});
|
|
717
|
-
return response;
|
|
718
|
-
}
|
|
719
|
-
if (this.#config.trustQuery && !this.#config.devMode && success) {
|
|
720
|
-
this.#deleteById(newId);
|
|
721
|
-
this.#emit("selfItemDeleted", {
|
|
722
|
-
id: newId,
|
|
723
|
-
instance: this
|
|
724
|
-
});
|
|
725
|
-
return response;
|
|
726
|
-
}
|
|
727
|
-
if (id !== newId) {
|
|
728
|
-
this.#config.devMode && this.#config.trustQuery && console.warn(new require_defaults.ChimeraQueryTrustIdMismatchError(this.#config.name, id, newId));
|
|
729
|
-
if (!this.#config.trustQuery) {
|
|
730
|
-
success && this.#emit("selfItemDeleted", {
|
|
731
|
-
id: newId,
|
|
732
|
-
instance: this
|
|
733
|
-
});
|
|
734
|
-
throw new require_defaults.ChimeraQueryTrustIdMismatchError(this.#config.name, id, newId);
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
if (success) {
|
|
738
|
-
this.#deleteById(newId);
|
|
739
|
-
this.#emit("selfItemDeleted", {
|
|
740
|
-
id: newId,
|
|
741
|
-
instance: this
|
|
742
|
-
});
|
|
743
|
-
return response;
|
|
744
|
-
}
|
|
745
|
-
const error = new require_defaults.ChimeraQueryUnsuccessfulDeletionError(this.#config.name, id);
|
|
746
|
-
this.#state = ChimeraQueryFetchingState.ReErrored;
|
|
747
|
-
this.#lastError = error;
|
|
748
|
-
throw error;
|
|
749
|
-
}, (error) => this.#setError(error, new require_defaults.ChimeraQueryDeletingError(this.#config.name, error)));
|
|
750
|
-
}
|
|
751
|
-
/**
|
|
752
|
-
* Delete a list of items by their [id]s
|
|
753
|
-
* @param ids array of items to delete
|
|
754
|
-
*/
|
|
755
|
-
batchedDelete(ids) {
|
|
756
|
-
const { controller } = this.#prepareRequestParams();
|
|
757
|
-
return this.#config.batchedDeleter(Array.from(ids), { signal: controller.signal }).then((response) => {
|
|
758
|
-
this.#items && response.result.forEach(({ id: newId, success }) => {
|
|
759
|
-
if (success) {
|
|
760
|
-
this.#deleteById(newId);
|
|
761
|
-
this.#emit("selfItemDeleted", {
|
|
762
|
-
id: newId,
|
|
763
|
-
instance: this
|
|
764
|
-
});
|
|
765
|
-
} else {
|
|
766
|
-
const error = new require_defaults.ChimeraQueryUnsuccessfulDeletionError(this.#config.name, newId);
|
|
767
|
-
this.#state = ChimeraQueryFetchingState.ReErrored;
|
|
768
|
-
this.#lastError = error;
|
|
769
|
-
throw error;
|
|
770
|
-
}
|
|
771
|
-
});
|
|
772
|
-
return response;
|
|
773
|
-
}, (error) => this.#setError(error, new require_defaults.ChimeraQueryDeletingError(this.#config.name, error)));
|
|
774
|
-
}
|
|
775
|
-
/**
|
|
776
|
-
* Create new item using partial data
|
|
777
|
-
* @param item partial item data to create new item
|
|
778
|
-
*/
|
|
779
|
-
create(item) {
|
|
780
|
-
const { controller } = this.#prepareRequestParams();
|
|
781
|
-
return this.#config.itemCreator(item, { signal: controller.signal }).then((response) => {
|
|
782
|
-
const { data } = response;
|
|
783
|
-
this.#items && this.#setNewOne(data);
|
|
784
|
-
this.#emit("selfItemCreated", {
|
|
785
|
-
instance: this,
|
|
786
|
-
item: data
|
|
787
|
-
});
|
|
788
|
-
return response;
|
|
789
|
-
}, (error) => this.#setError(error, new require_defaults.ChimeraQueryFetchingError(this.#config.name, error)));
|
|
790
|
-
}
|
|
791
|
-
/**
|
|
792
|
-
* Create multiple items using partial data
|
|
793
|
-
* @param items array of partial item data to create new items
|
|
794
|
-
*/
|
|
795
|
-
batchedCreate(items) {
|
|
796
|
-
const { controller } = this.#prepareRequestParams();
|
|
797
|
-
return this.#config.batchedCreator(Array.from(items), { signal: controller.signal }).then((response) => {
|
|
798
|
-
this.#items && response.data.forEach((item) => {
|
|
799
|
-
this.#setNewOne(item);
|
|
800
|
-
this.#emit("selfItemCreated", {
|
|
801
|
-
instance: this,
|
|
802
|
-
item
|
|
803
|
-
});
|
|
804
|
-
});
|
|
805
|
-
return response;
|
|
806
|
-
}, (error) => this.#setError(error, new require_defaults.ChimeraQueryFetchingError(this.#config.name, error)));
|
|
807
|
-
}
|
|
808
|
-
/**
|
|
809
|
-
* Standard Array API without mutations
|
|
810
|
-
*/
|
|
811
|
-
get length() {
|
|
812
|
-
return this.#readyItems().length;
|
|
813
|
-
}
|
|
814
|
-
[Symbol.iterator]() {
|
|
815
|
-
return this.#readyItems()[Symbol.iterator]();
|
|
816
|
-
}
|
|
817
|
-
at(idx) {
|
|
818
|
-
return this.#readyItems().at(idx);
|
|
819
|
-
}
|
|
820
|
-
entries() {
|
|
821
|
-
return this.#readyItems().entries();
|
|
822
|
-
}
|
|
823
|
-
values() {
|
|
824
|
-
return this.#readyItems().values();
|
|
825
|
-
}
|
|
826
|
-
keys() {
|
|
827
|
-
return this.#readyItems().keys();
|
|
828
|
-
}
|
|
829
|
-
every(predicate) {
|
|
830
|
-
return this.#readyItems().every((item, idx) => predicate(item, idx, this));
|
|
831
|
-
}
|
|
832
|
-
some(predicate) {
|
|
833
|
-
return this.#readyItems().some((item, idx) => predicate(item, idx, this));
|
|
834
|
-
}
|
|
835
|
-
filter(predicate) {
|
|
836
|
-
return this.#readyItems().filter((item, idx) => predicate(item, idx, this));
|
|
837
|
-
}
|
|
838
|
-
find(predicate) {
|
|
839
|
-
return this.#readyItems().find((item, idx) => predicate(item, idx, this));
|
|
840
|
-
}
|
|
841
|
-
findIndex(predicate) {
|
|
842
|
-
return this.#readyItems().findIndex((item, idx) => predicate(item, idx, this));
|
|
843
|
-
}
|
|
844
|
-
findLast(predicate) {
|
|
845
|
-
return this.#readyItems().findLast((item, idx) => predicate(item, idx, this));
|
|
846
|
-
}
|
|
847
|
-
findLastIndex(predicate) {
|
|
848
|
-
return this.#readyItems().findLastIndex((item, idx) => predicate(item, idx, this));
|
|
849
|
-
}
|
|
850
|
-
forEach(cb) {
|
|
851
|
-
this.#readyItems().forEach((item, idx) => void cb(item, idx, this));
|
|
852
|
-
}
|
|
853
|
-
includes(item) {
|
|
854
|
-
return this.#readyItems().includes(item);
|
|
855
|
-
}
|
|
856
|
-
indexOf(item) {
|
|
857
|
-
return this.#readyItems().indexOf(item);
|
|
858
|
-
}
|
|
859
|
-
map(cb) {
|
|
860
|
-
return this.#readyItems().map((item, idx) => cb(item, idx, this));
|
|
861
|
-
}
|
|
862
|
-
reduce(cb, initialValue) {
|
|
863
|
-
return this.#readyItems().reduce((prev, cur, idx) => cb(prev, cur, idx, this), initialValue);
|
|
864
|
-
}
|
|
865
|
-
reduceRight(cb, initialValue) {
|
|
866
|
-
return this.#readyItems().reduceRight((prev, cur, idx) => cb(prev, cur, idx, this), initialValue);
|
|
867
|
-
}
|
|
868
|
-
slice(start, end) {
|
|
869
|
-
return this.#readyItems().slice(start, end);
|
|
870
|
-
}
|
|
871
|
-
toSorted(compareFn) {
|
|
872
|
-
return this.#readyItems().toSorted(compareFn);
|
|
873
|
-
}
|
|
874
|
-
toSpliced(start, deleteCount, ...items) {
|
|
875
|
-
return this.#readyItems().toSpliced(start, deleteCount, ...items);
|
|
876
|
-
}
|
|
877
|
-
toJSON() {
|
|
878
|
-
return Array.from(this.#readyItems());
|
|
879
|
-
}
|
|
880
|
-
toString() {
|
|
881
|
-
return this.#readyItems().toString();
|
|
882
|
-
}
|
|
883
|
-
};
|
|
884
|
-
|
|
885
|
-
//#endregion
|
|
886
|
-
//#region src/query/ChimeraItemQuery.ts
|
|
887
|
-
var ChimeraItemQuery = class extends ChimeraEventEmitter {
|
|
888
|
-
#item;
|
|
889
|
-
#mutable;
|
|
890
|
-
#state;
|
|
891
|
-
#promise;
|
|
892
|
-
#lastError;
|
|
893
|
-
#params;
|
|
894
|
-
#config;
|
|
895
|
-
#idGetter;
|
|
896
|
-
#emit(event, arg) {
|
|
897
|
-
queueMicrotask(() => super.emit(event, arg));
|
|
898
|
-
}
|
|
899
|
-
emit() {
|
|
900
|
-
throw new require_defaults.ChimeraInternalError("External events dispatching is not supported.");
|
|
901
|
-
}
|
|
902
|
-
#prepareRequestParams() {
|
|
903
|
-
return { controller: new AbortController() };
|
|
904
|
-
}
|
|
905
|
-
#setPromise(promise) {
|
|
906
|
-
this.#promise?.cancel();
|
|
907
|
-
this.#promise = promise;
|
|
908
|
-
return promise;
|
|
909
|
-
}
|
|
910
|
-
#readyItem(internalMessage) {
|
|
911
|
-
if (this.#item) return this.#item;
|
|
912
|
-
throw internalMessage ? new require_defaults.ChimeraInternalError(internalMessage) : new require_defaults.ChimeraQueryNotReadyError(this.#config.name);
|
|
913
|
-
}
|
|
914
|
-
#mutableItem(internalMessage) {
|
|
915
|
-
if (this.#state === ChimeraQueryFetchingState.Deleted) throw internalMessage ? new require_defaults.ChimeraInternalError(internalMessage) : new require_defaults.ChimeraQueryDeletedItemError(this.#config.name, this.#params.id);
|
|
916
|
-
return this.#readyItem(internalMessage);
|
|
917
|
-
}
|
|
918
|
-
#setMutable(item) {
|
|
919
|
-
if (item != null) if (this.#mutable) deepObjectAssign(this.#mutable, item);
|
|
920
|
-
else this.#mutable = deepObjectClone(item);
|
|
921
|
-
else this.#mutable = item;
|
|
922
|
-
}
|
|
923
|
-
#resetMutable() {
|
|
924
|
-
this.#setMutable(this.#readyItem(`Trying to reset mutable ref for empty item (${this.#config.name}[${this.#params.id}])`));
|
|
925
|
-
}
|
|
926
|
-
#setItem(item) {
|
|
927
|
-
!this.#item && this.#emit("ready", { instance: this });
|
|
928
|
-
const oldItem = this.#item;
|
|
929
|
-
this.#item = item;
|
|
930
|
-
this.#resetMutable();
|
|
931
|
-
this.#emit("updated", {
|
|
932
|
-
instance: this,
|
|
933
|
-
item,
|
|
934
|
-
oldItem
|
|
935
|
-
});
|
|
936
|
-
}
|
|
937
|
-
#setNewItem(item) {
|
|
938
|
-
deepObjectFreeze(item);
|
|
939
|
-
const oldItem = this.#item;
|
|
940
|
-
this.#setItem(item);
|
|
941
|
-
this.#emit("selfUpdated", {
|
|
942
|
-
instance: this,
|
|
943
|
-
item,
|
|
944
|
-
oldItem
|
|
945
|
-
});
|
|
946
|
-
}
|
|
947
|
-
#deleteItem() {
|
|
948
|
-
this.#state = ChimeraQueryFetchingState.Deleted;
|
|
949
|
-
this.#emit("deleted", {
|
|
950
|
-
id: this.#params.id,
|
|
951
|
-
instance: this
|
|
952
|
-
});
|
|
953
|
-
}
|
|
954
|
-
#setError(error, source) {
|
|
955
|
-
this.#state = this.#item ? ChimeraQueryFetchingState.ReErrored : ChimeraQueryFetchingState.Errored;
|
|
956
|
-
this.#lastError = error;
|
|
957
|
-
this.#emit("error", {
|
|
958
|
-
error,
|
|
959
|
-
instance: this
|
|
960
|
-
});
|
|
961
|
-
throw source;
|
|
962
|
-
}
|
|
963
|
-
#watchPromise(promise, controller) {
|
|
964
|
-
return makeCancellablePromise(promise.then(({ data }) => {
|
|
965
|
-
if (this.#config.trustQuery && !this.#config.devMode) {
|
|
966
|
-
this.#setNewItem(data);
|
|
967
|
-
this.#state = ChimeraQueryFetchingState.Fetched;
|
|
968
|
-
return { data };
|
|
969
|
-
}
|
|
970
|
-
const localId = this.#params.id;
|
|
971
|
-
const newId = this.#idGetter(data);
|
|
972
|
-
if (localId === newId || this.#state === ChimeraQueryFetchingState.Creating) {
|
|
973
|
-
this.#setNewItem(data);
|
|
974
|
-
if (this.#state === ChimeraQueryFetchingState.Creating) this.#emit("selfCreated", {
|
|
975
|
-
instance: this,
|
|
976
|
-
item: data
|
|
977
|
-
});
|
|
978
|
-
this.#state = ChimeraQueryFetchingState.Fetched;
|
|
979
|
-
} else {
|
|
980
|
-
this.#config.devMode && this.#config.trustQuery && console.warn(new require_defaults.ChimeraQueryTrustIdMismatchError(this.#config.name, localId, newId));
|
|
981
|
-
if (!this.#config.trustQuery) throw new require_defaults.ChimeraQueryTrustIdMismatchError(this.#config.name, localId, newId);
|
|
982
|
-
this.#setNewItem(data);
|
|
983
|
-
this.#params.id = newId;
|
|
984
|
-
this.#state = ChimeraQueryFetchingState.Fetched;
|
|
985
|
-
}
|
|
986
|
-
return { data };
|
|
987
|
-
}).catch((error) => this.#setError(error, new require_defaults.ChimeraQueryFetchingError(this.#config.name, error))), controller);
|
|
988
|
-
}
|
|
989
|
-
#updateItem(newItem) {
|
|
990
|
-
const newId = this.#idGetter(newItem);
|
|
991
|
-
const oldId = this.#idGetter(this.#readyItem(`Trying to update not ready item (${this.#config.name}[${this.#params.id}])`));
|
|
992
|
-
if (newId !== oldId && !this.#config.trustQuery) {
|
|
993
|
-
this.#resetMutable();
|
|
994
|
-
throw new require_defaults.ChimeraQueryIdMismatchError(this.#config.name, oldId, newId);
|
|
995
|
-
}
|
|
996
|
-
this.#state = ChimeraQueryFetchingState.Updating;
|
|
997
|
-
const { controller } = this.#prepareRequestParams();
|
|
998
|
-
return this.#setPromise(this.#watchPromise(makeCancellablePromise(this.#config.itemUpdater(newItem, { signal: controller.signal }), controller), controller));
|
|
999
|
-
}
|
|
1000
|
-
#requestDelete() {
|
|
1001
|
-
this.#state = ChimeraQueryFetchingState.Deleting;
|
|
1002
|
-
const { controller } = this.#prepareRequestParams();
|
|
1003
|
-
return this.#setPromise(makeCancellablePromise(makeCancellablePromise(this.#config.itemDeleter(this.#params.id, { signal: controller.signal }), controller).then(({ result }) => {
|
|
1004
|
-
const { id, success } = result;
|
|
1005
|
-
if (this.#config.trustQuery && !this.#config.devMode && success) {
|
|
1006
|
-
this.#deleteItem();
|
|
1007
|
-
return { result };
|
|
1008
|
-
}
|
|
1009
|
-
const localId = this.#params.id;
|
|
1010
|
-
if (localId !== id) {
|
|
1011
|
-
this.#config.devMode && this.#config.trustQuery && console.warn(new require_defaults.ChimeraQueryTrustIdMismatchError(this.#config.name, localId, id));
|
|
1012
|
-
if (!this.#config.trustQuery) throw new require_defaults.ChimeraQueryTrustIdMismatchError(this.#config.name, localId, id);
|
|
1013
|
-
}
|
|
1014
|
-
if (success) {
|
|
1015
|
-
this.#deleteItem();
|
|
1016
|
-
this.#emit("selfDeleted", {
|
|
1017
|
-
id,
|
|
1018
|
-
instance: this
|
|
1019
|
-
});
|
|
1020
|
-
} else {
|
|
1021
|
-
const error = new require_defaults.ChimeraQueryUnsuccessfulDeletionError(this.#config.name, this.#params.id);
|
|
1022
|
-
this.#state = ChimeraQueryFetchingState.ReErrored;
|
|
1023
|
-
this.#lastError = error;
|
|
1024
|
-
throw error;
|
|
1025
|
-
}
|
|
1026
|
-
return { result };
|
|
1027
|
-
}, (error) => this.#setError(error, new require_defaults.ChimeraQueryDeletingError(this.#config.name, error)))));
|
|
1028
|
-
}
|
|
1029
|
-
constructor(config, params, existingItem, toCreateItem) {
|
|
1030
|
-
super();
|
|
1031
|
-
this.#config = config;
|
|
1032
|
-
this.#idGetter = config.idGetter;
|
|
1033
|
-
this.#params = params;
|
|
1034
|
-
this.#promise = null;
|
|
1035
|
-
this.#item = null;
|
|
1036
|
-
this.#mutable = null;
|
|
1037
|
-
this.#state = ChimeraQueryFetchingState.Initialized;
|
|
1038
|
-
if (existingItem) {
|
|
1039
|
-
const item = existingItem;
|
|
1040
|
-
this.#setItem(item);
|
|
1041
|
-
if (config.devMode && this.#idGetter(item) !== params.id) {
|
|
1042
|
-
this.#state = ChimeraQueryFetchingState.Errored;
|
|
1043
|
-
throw new require_defaults.ChimeraInternalError(`Invalid item query [id] (changed from "${params.id}" to "${this.#idGetter(item)}")`);
|
|
1044
|
-
}
|
|
1045
|
-
this.#state = ChimeraQueryFetchingState.Prefetched;
|
|
1046
|
-
} else if (toCreateItem) {
|
|
1047
|
-
this.#state = ChimeraQueryFetchingState.Creating;
|
|
1048
|
-
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);
|
|
1051
|
-
return { data };
|
|
1052
|
-
}), controller));
|
|
1053
|
-
} else {
|
|
1054
|
-
this.#state = ChimeraQueryFetchingState.Fetching;
|
|
1055
|
-
const { controller } = this.#prepareRequestParams();
|
|
1056
|
-
this.#setPromise(this.#watchPromise(makeCancellablePromise(config.itemFetcher(params, { signal: controller.signal }), controller), controller));
|
|
1057
|
-
}
|
|
1058
|
-
this.#emit("initialized", { instance: this });
|
|
1059
|
-
}
|
|
1060
|
-
get [ChimeraGetParamsSym]() {
|
|
1061
|
-
return this.#params;
|
|
1062
|
-
}
|
|
1063
|
-
[ChimeraSetOneSym](item) {
|
|
1064
|
-
this.#setItem(item);
|
|
1065
|
-
!this.inProgress && (this.#state = ChimeraQueryFetchingState.Actualized);
|
|
1066
|
-
}
|
|
1067
|
-
[ChimeraDeleteOneSym](id) {
|
|
1068
|
-
if (id === this.#params.id) {
|
|
1069
|
-
this.#promise?.cancel();
|
|
1070
|
-
this.#promise = null;
|
|
1071
|
-
this.#deleteItem();
|
|
1072
|
-
}
|
|
1073
|
-
}
|
|
1074
|
-
get state() {
|
|
1075
|
-
return this.#state;
|
|
1076
|
-
}
|
|
1077
|
-
get inProgress() {
|
|
1078
|
-
return IN_PROGRESS_STATES.includes(this.#state);
|
|
1079
|
-
}
|
|
1080
|
-
get ready() {
|
|
1081
|
-
return this.#item !== null;
|
|
1082
|
-
}
|
|
1083
|
-
get lastError() {
|
|
1084
|
-
return this.#lastError;
|
|
1085
|
-
}
|
|
1086
|
-
get id() {
|
|
1087
|
-
return this.#params.id;
|
|
1088
|
-
}
|
|
1089
|
-
/** Return an item if it is ready, throw error otherwise */
|
|
1090
|
-
get data() {
|
|
1091
|
-
return this.#readyItem();
|
|
1092
|
-
}
|
|
1093
|
-
/** Get ref for an item that can be changed as a regular object. To send changes to updater, use <commit> method */
|
|
1094
|
-
get mutable() {
|
|
1095
|
-
this.#readyItem();
|
|
1096
|
-
return this.#mutable;
|
|
1097
|
-
}
|
|
1098
|
-
get promise() {
|
|
1099
|
-
return this.#promise;
|
|
1100
|
-
}
|
|
1101
|
-
/**
|
|
1102
|
-
* Wait for the current progress process to complete (both success or error)
|
|
1103
|
-
*/
|
|
1104
|
-
get progress() {
|
|
1105
|
-
return new Promise((res) => {
|
|
1106
|
-
const resolve = () => queueMicrotask(() => res());
|
|
1107
|
-
if (this.#promise) {
|
|
1108
|
-
this.#promise.then(resolve, resolve);
|
|
1109
|
-
this.#promise.cancelled(() => this.progress.then(resolve, resolve));
|
|
1110
|
-
} else resolve();
|
|
1111
|
-
});
|
|
1112
|
-
}
|
|
1113
|
-
/**
|
|
1114
|
-
* Wait for the current progress process to complete, throw an error if it fails
|
|
1115
|
-
*/
|
|
1116
|
-
get result() {
|
|
1117
|
-
return new Promise((res, rej) => {
|
|
1118
|
-
const resolve = () => queueMicrotask(() => res());
|
|
1119
|
-
if (this.#promise) {
|
|
1120
|
-
this.#promise.then(resolve, rej);
|
|
1121
|
-
this.#promise.cancelled(() => this.#promise ? this.result.then(res, rej) : rej("cancelled"));
|
|
1122
|
-
} else resolve();
|
|
1123
|
-
});
|
|
1124
|
-
}
|
|
1125
|
-
/**
|
|
1126
|
-
* Trigger refetch, return existing refetch promise if already running
|
|
1127
|
-
* @param force If true cancels any running process and starts a new one
|
|
1128
|
-
* @throws {ChimeraQueryAlreadyRunningError} If deleting or updating already in progress
|
|
1129
|
-
*/
|
|
1130
|
-
refetch(force = false) {
|
|
1131
|
-
if (!force && this.#promise && [ChimeraQueryFetchingState.Fetching, ChimeraQueryFetchingState.Refetching].includes(this.#state)) return this.#promise;
|
|
1132
|
-
if (this.#state === ChimeraQueryFetchingState.Creating) throw new require_defaults.ChimeraQueryNotCreatedError(this.#config.name);
|
|
1133
|
-
if (!force && [ChimeraQueryFetchingState.Updating, ChimeraQueryFetchingState.Deleting].includes(this.#state)) throw new require_defaults.ChimeraQueryAlreadyRunningError(this.#config.name, this.#state);
|
|
1134
|
-
this.#state = ChimeraQueryFetchingState.Refetching;
|
|
1135
|
-
const { controller } = this.#prepareRequestParams();
|
|
1136
|
-
return this.#setPromise(this.#watchPromise(makeCancellablePromise(this.#config.itemFetcher(this.#params, { signal: controller.signal }), controller), controller));
|
|
1137
|
-
}
|
|
1138
|
-
/**
|
|
1139
|
-
* Update item using updated copy, a running update process will be cancelled
|
|
1140
|
-
* @param newItem new item to replace existing
|
|
1141
|
-
* @param force if true cancels any running process including fetch and delete
|
|
1142
|
-
* @throws {ChimeraQueryAlreadyRunningError} If deleting or updating already in progress
|
|
1143
|
-
*/
|
|
1144
|
-
update(newItem, force = false) {
|
|
1145
|
-
if (this.#state === ChimeraQueryFetchingState.Creating) throw new require_defaults.ChimeraQueryNotCreatedError(this.#config.name);
|
|
1146
|
-
if (!force && [
|
|
1147
|
-
ChimeraQueryFetchingState.Fetching,
|
|
1148
|
-
ChimeraQueryFetchingState.Refetching,
|
|
1149
|
-
ChimeraQueryFetchingState.Deleting
|
|
1150
|
-
].includes(this.#state)) throw new require_defaults.ChimeraQueryAlreadyRunningError(this.#config.name, this.#state);
|
|
1151
|
-
this.#mutableItem();
|
|
1152
|
-
return this.#updateItem(newItem);
|
|
1153
|
-
}
|
|
1154
|
-
/**
|
|
1155
|
-
* Update item using function with draft item as argument
|
|
1156
|
-
* that can be used to patch item in place or return a patched value,
|
|
1157
|
-
* a running update process will be cancelled
|
|
1158
|
-
* @param mutator mutator function
|
|
1159
|
-
* @param force if true cancels any running process including fetch and delete
|
|
1160
|
-
* @throws {ChimeraQueryAlreadyRunningError} If deleting or updating already in progress
|
|
1161
|
-
*/
|
|
1162
|
-
mutate(mutator, force = false) {
|
|
1163
|
-
if (this.#state === ChimeraQueryFetchingState.Creating) throw new require_defaults.ChimeraQueryNotCreatedError(this.#config.name);
|
|
1164
|
-
if (!force && [
|
|
1165
|
-
ChimeraQueryFetchingState.Fetching,
|
|
1166
|
-
ChimeraQueryFetchingState.Refetching,
|
|
1167
|
-
ChimeraQueryFetchingState.Deleting
|
|
1168
|
-
].includes(this.#state)) throw new require_defaults.ChimeraQueryAlreadyRunningError(this.#config.name, this.#state);
|
|
1169
|
-
const item = deepObjectClone(this.#mutableItem());
|
|
1170
|
-
return this.#updateItem(mutator(item) ?? item);
|
|
1171
|
-
}
|
|
1172
|
-
/**
|
|
1173
|
-
* Commit updated value from mutable ref, a running update process will be canceled
|
|
1174
|
-
* @param force if true cancels any running process including fetch and delete
|
|
1175
|
-
* @throws {ChimeraQueryAlreadyRunningError} If deleting or updating already in progress
|
|
1176
|
-
*/
|
|
1177
|
-
commit(force = false) {
|
|
1178
|
-
if (this.#state === ChimeraQueryFetchingState.Creating) throw new require_defaults.ChimeraQueryNotCreatedError(this.#config.name);
|
|
1179
|
-
if (!force && [
|
|
1180
|
-
ChimeraQueryFetchingState.Fetching,
|
|
1181
|
-
ChimeraQueryFetchingState.Refetching,
|
|
1182
|
-
ChimeraQueryFetchingState.Deleting
|
|
1183
|
-
].includes(this.#state)) throw new require_defaults.ChimeraQueryAlreadyRunningError(this.#config.name, this.#state);
|
|
1184
|
-
this.#mutableItem();
|
|
1185
|
-
return this.#updateItem(this.#mutable);
|
|
1186
|
-
}
|
|
1187
|
-
/**
|
|
1188
|
-
* Request to delete the value.
|
|
1189
|
-
* Local copy will still be available if it was present.
|
|
1190
|
-
* A running delete process will be canceled
|
|
1191
|
-
* @param force if true cancels any running process including fetch and update
|
|
1192
|
-
* @throws {ChimeraQueryAlreadyRunningError} If deleting or updating already in progress
|
|
1193
|
-
*/
|
|
1194
|
-
delete(force = false) {
|
|
1195
|
-
if (this.#state === ChimeraQueryFetchingState.Creating) throw new require_defaults.ChimeraQueryNotCreatedError(this.#config.name);
|
|
1196
|
-
if (!force && [
|
|
1197
|
-
ChimeraQueryFetchingState.Fetching,
|
|
1198
|
-
ChimeraQueryFetchingState.Refetching,
|
|
1199
|
-
ChimeraQueryFetchingState.Updating
|
|
1200
|
-
].includes(this.#state)) throw new require_defaults.ChimeraQueryAlreadyRunningError(this.#config.name, this.#state);
|
|
1201
|
-
return this.#requestDelete();
|
|
1202
|
-
}
|
|
1203
|
-
toJSON() {
|
|
1204
|
-
return this.#readyItem();
|
|
1205
|
-
}
|
|
1206
|
-
toString() {
|
|
1207
|
-
return `${this.#readyItem()}`;
|
|
1208
|
-
}
|
|
1209
|
-
};
|
|
1210
|
-
|
|
1211
|
-
//#endregion
|
|
1212
|
-
//#region src/shared/ChimeraWeakValueMap/ChimeraWeakValueMap.ts
|
|
1213
|
-
var ChimeraWeakValueMap = class extends ChimeraEventEmitter {
|
|
1214
|
-
#map;
|
|
1215
|
-
#registry;
|
|
1216
|
-
#cleanupScheduled = false;
|
|
1217
|
-
#emit(event, arg) {
|
|
1218
|
-
queueMicrotask(() => super.emit(event, arg));
|
|
1219
|
-
}
|
|
1220
|
-
emit() {
|
|
1221
|
-
throw new require_defaults.ChimeraInternalError("External events dispatching is not supported.");
|
|
1222
|
-
}
|
|
1223
|
-
#scheduleCleanup() {
|
|
1224
|
-
if (this.#cleanupScheduled) return;
|
|
1225
|
-
this.#cleanupScheduled = true;
|
|
1226
|
-
(typeof requestIdleCallback !== "undefined" ? requestIdleCallback : (cb) => setTimeout(cb, 0))(() => {
|
|
1227
|
-
this.#cleanup();
|
|
1228
|
-
this.#cleanupScheduled = false;
|
|
1229
|
-
});
|
|
1230
|
-
}
|
|
1231
|
-
#cleanup() {
|
|
1232
|
-
for (const [key, weakRef] of this.#map.entries()) if (weakRef.deref() === void 0) {
|
|
1233
|
-
this.#map.delete(key);
|
|
1234
|
-
this.#emit("finalize", {
|
|
1235
|
-
instance: this,
|
|
1236
|
-
key
|
|
1237
|
-
});
|
|
1238
|
-
}
|
|
1239
|
-
}
|
|
1240
|
-
constructor(values) {
|
|
1241
|
-
super();
|
|
1242
|
-
this.#registry = new FinalizationRegistry((key) => {
|
|
1243
|
-
const weakRef = this.#map.get(key);
|
|
1244
|
-
if (weakRef && weakRef.deref() === void 0) {
|
|
1245
|
-
this.#map.delete(key);
|
|
1246
|
-
this.#emit("finalize", {
|
|
1247
|
-
instance: this,
|
|
1248
|
-
key
|
|
1249
|
-
});
|
|
1250
|
-
}
|
|
1251
|
-
});
|
|
1252
|
-
this.#map = new Map(values ? values.map(([k, v]) => {
|
|
1253
|
-
this.#registry.register(v, k, v);
|
|
1254
|
-
return [k, new WeakRef(v)];
|
|
1255
|
-
}) : null);
|
|
1256
|
-
}
|
|
1257
|
-
set(key, value) {
|
|
1258
|
-
const existingRef = this.#map.get(key);
|
|
1259
|
-
if (existingRef) {
|
|
1260
|
-
const existingValue = existingRef.deref();
|
|
1261
|
-
if (existingValue) this.#registry.unregister(existingValue);
|
|
1262
|
-
}
|
|
1263
|
-
this.#registry.register(value, key, value);
|
|
1264
|
-
this.#map.set(key, new WeakRef(value));
|
|
1265
|
-
this.#emit("set", {
|
|
1266
|
-
instance: this,
|
|
1267
|
-
key,
|
|
1268
|
-
value
|
|
1269
|
-
});
|
|
1270
|
-
return this;
|
|
1271
|
-
}
|
|
1272
|
-
delete(key) {
|
|
1273
|
-
if (!this.#map.has(key)) return false;
|
|
1274
|
-
const value = this.#map.get(key)?.deref();
|
|
1275
|
-
if (value === void 0) {
|
|
1276
|
-
this.#map.delete(key);
|
|
1277
|
-
this.#emit("finalize", {
|
|
1278
|
-
instance: this,
|
|
1279
|
-
key
|
|
1280
|
-
});
|
|
1281
|
-
return true;
|
|
1282
|
-
}
|
|
1283
|
-
this.#map.delete(key);
|
|
1284
|
-
this.#registry.unregister(value);
|
|
1285
|
-
this.#emit("delete", {
|
|
1286
|
-
instance: this,
|
|
1287
|
-
key,
|
|
1288
|
-
value
|
|
1289
|
-
});
|
|
1290
|
-
return true;
|
|
1291
|
-
}
|
|
1292
|
-
has(key) {
|
|
1293
|
-
const weakRef = this.#map.get(key);
|
|
1294
|
-
const value = weakRef?.deref();
|
|
1295
|
-
if (value === void 0 && weakRef) {
|
|
1296
|
-
this.#map.delete(key);
|
|
1297
|
-
this.#emit("finalize", {
|
|
1298
|
-
instance: this,
|
|
1299
|
-
key
|
|
1300
|
-
});
|
|
1301
|
-
this.#scheduleCleanup();
|
|
1302
|
-
}
|
|
1303
|
-
return value !== void 0;
|
|
1304
|
-
}
|
|
1305
|
-
forEach(callbackFn, thisArg) {
|
|
1306
|
-
this.#map.forEach((weakRef, k) => {
|
|
1307
|
-
const value = weakRef.deref();
|
|
1308
|
-
if (value !== void 0) callbackFn.call(thisArg, value, k, this);
|
|
1309
|
-
else {
|
|
1310
|
-
this.#map.delete(k);
|
|
1311
|
-
this.#emit("finalize", {
|
|
1312
|
-
instance: this,
|
|
1313
|
-
key: k
|
|
1314
|
-
});
|
|
1315
|
-
}
|
|
1316
|
-
});
|
|
1317
|
-
if (this.#map.size > 0) this.#scheduleCleanup();
|
|
1318
|
-
}
|
|
1319
|
-
get(key) {
|
|
1320
|
-
const weakRef = this.#map.get(key);
|
|
1321
|
-
const value = weakRef?.deref();
|
|
1322
|
-
if (value === void 0 && weakRef) {
|
|
1323
|
-
this.#map.delete(key);
|
|
1324
|
-
this.#emit("finalize", {
|
|
1325
|
-
instance: this,
|
|
1326
|
-
key
|
|
1327
|
-
});
|
|
1328
|
-
this.#scheduleCleanup();
|
|
1329
|
-
}
|
|
1330
|
-
return value;
|
|
1331
|
-
}
|
|
1332
|
-
get size() {
|
|
1333
|
-
this.#cleanup();
|
|
1334
|
-
return this.#map.size;
|
|
1335
|
-
}
|
|
1336
|
-
*entries() {
|
|
1337
|
-
for (const [k, weakRef] of this.#map.entries()) {
|
|
1338
|
-
const value = weakRef.deref();
|
|
1339
|
-
if (value !== void 0) yield [k, value];
|
|
1340
|
-
else {
|
|
1341
|
-
this.#map.delete(k);
|
|
1342
|
-
this.#emit("finalize", {
|
|
1343
|
-
instance: this,
|
|
1344
|
-
key: k
|
|
1345
|
-
});
|
|
1346
|
-
}
|
|
1347
|
-
}
|
|
1348
|
-
if (this.#map.size > 0) this.#scheduleCleanup();
|
|
1349
|
-
}
|
|
1350
|
-
*keys() {
|
|
1351
|
-
for (const [k, weakRef] of this.#map.entries()) if (weakRef.deref() !== void 0) yield k;
|
|
1352
|
-
else {
|
|
1353
|
-
this.#map.delete(k);
|
|
1354
|
-
this.#emit("finalize", {
|
|
1355
|
-
instance: this,
|
|
1356
|
-
key: k
|
|
1357
|
-
});
|
|
1358
|
-
}
|
|
1359
|
-
if (this.#map.size > 0) this.#scheduleCleanup();
|
|
1360
|
-
}
|
|
1361
|
-
*values() {
|
|
1362
|
-
for (const weakRef of this.#map.values()) {
|
|
1363
|
-
const value = weakRef.deref();
|
|
1364
|
-
if (value !== void 0) yield value;
|
|
1365
|
-
}
|
|
1366
|
-
this.#cleanup();
|
|
1367
|
-
}
|
|
1368
|
-
*[Symbol.iterator]() {
|
|
1369
|
-
yield* this.entries();
|
|
1370
|
-
}
|
|
1371
|
-
clear() {
|
|
1372
|
-
for (const weakRef of this.#map.values()) {
|
|
1373
|
-
const value = weakRef.deref();
|
|
1374
|
-
if (value !== void 0) this.#registry.unregister(value);
|
|
1375
|
-
}
|
|
1376
|
-
this.#map.clear();
|
|
1377
|
-
this.#emit("clear", { instance: this });
|
|
1378
|
-
}
|
|
1379
|
-
cleanup() {
|
|
1380
|
-
this.#cleanup();
|
|
1381
|
-
}
|
|
1382
|
-
get rawSize() {
|
|
1383
|
-
return this.#map.size;
|
|
1384
|
-
}
|
|
1385
|
-
};
|
|
1386
|
-
|
|
1387
|
-
//#endregion
|
|
1388
|
-
//#region src/store/ChimeraEntityRepository.ts
|
|
1389
|
-
var ChimeraEntityRepository = class extends ChimeraEventEmitter {
|
|
1390
|
-
#entityConfig;
|
|
1391
|
-
#filterConfig;
|
|
1392
|
-
#orderConfig;
|
|
1393
|
-
#idGetter;
|
|
1394
|
-
#itemsMap;
|
|
1395
|
-
#collectionQueryMap;
|
|
1396
|
-
#itemQueryMap;
|
|
1397
|
-
#emit(event, arg) {
|
|
1398
|
-
queueMicrotask(() => super.emit(event, arg));
|
|
1399
|
-
}
|
|
1400
|
-
emit() {
|
|
1401
|
-
throw new require_defaults.ChimeraInternalError("External events dispatching is not supported.");
|
|
1402
|
-
}
|
|
1403
|
-
#registerUpdate(item, skipItem) {
|
|
1404
|
-
const id = this.#idGetter(item);
|
|
1405
|
-
const oldItem = this.#itemsMap.get(id);
|
|
1406
|
-
this.#itemsMap.set(id, item);
|
|
1407
|
-
const itemQuery = this.#itemQueryMap.get(id);
|
|
1408
|
-
itemQuery && skipItem !== itemQuery && itemQuery[ChimeraSetOneSym](item);
|
|
1409
|
-
!oldItem && this.#emit("itemAdded", {
|
|
1410
|
-
instance: this,
|
|
1411
|
-
item
|
|
1412
|
-
});
|
|
1413
|
-
this.#emit("itemUpdated", {
|
|
1414
|
-
instance: this,
|
|
1415
|
-
item,
|
|
1416
|
-
oldItem: oldItem ?? null
|
|
1417
|
-
});
|
|
1418
|
-
}
|
|
1419
|
-
#registerDelete(id, skipItem) {
|
|
1420
|
-
const oldItem = this.#itemsMap.get(id);
|
|
1421
|
-
if (!oldItem) return;
|
|
1422
|
-
this.#itemsMap.delete(id);
|
|
1423
|
-
const itemQuery = this.#itemQueryMap.get(id);
|
|
1424
|
-
itemQuery && skipItem !== itemQuery && itemQuery[ChimeraDeleteOneSym](id);
|
|
1425
|
-
this.#emit("itemDeleted", {
|
|
1426
|
-
instance: this,
|
|
1427
|
-
oldItem: oldItem ?? null
|
|
1428
|
-
});
|
|
1429
|
-
}
|
|
1430
|
-
#propagateUpdateOne(item, { item: skipItem, collection: skipCollection } = {}) {
|
|
1431
|
-
this.#registerUpdate(item, skipItem);
|
|
1432
|
-
for (const c of this.#collectionQueryMap.values()) c !== skipCollection && c[ChimeraSetOneSym](item);
|
|
1433
|
-
}
|
|
1434
|
-
#propagateDeleteOne(id, { item: skipItem, collection: skipCollection } = {}) {
|
|
1435
|
-
this.#registerDelete(id, skipItem);
|
|
1436
|
-
for (const c of this.#collectionQueryMap.values()) c !== skipCollection && c[ChimeraDeleteOneSym](id);
|
|
1437
|
-
}
|
|
1438
|
-
#propagateUpdateMany(items, { item: skipItem, collection: skipCollection } = {}) {
|
|
1439
|
-
for (const item of items) this.#registerUpdate(item, skipItem);
|
|
1440
|
-
this.#emit("updated", {
|
|
1441
|
-
instance: this,
|
|
1442
|
-
items
|
|
1443
|
-
});
|
|
1444
|
-
for (const c of this.#collectionQueryMap.values()) c !== skipCollection && c[ChimeraSetManySym](items);
|
|
1445
|
-
}
|
|
1446
|
-
#propagateDeleteMany(ids, { item: skipItem, collection: skipCollection } = {}) {
|
|
1447
|
-
for (const id of ids) this.#registerDelete(id, skipItem);
|
|
1448
|
-
this.#emit("deleted", {
|
|
1449
|
-
ids,
|
|
1450
|
-
instance: this
|
|
1451
|
-
});
|
|
1452
|
-
for (const c of this.#collectionQueryMap.values()) c !== skipCollection && c[ChimeraDeleteManySym](ids);
|
|
1453
|
-
}
|
|
1454
|
-
#itemUpdateHandler(query, item) {
|
|
1455
|
-
this.#propagateUpdateOne(item, { item: query });
|
|
1456
|
-
}
|
|
1457
|
-
#itemDeleteHandler(query, id) {
|
|
1458
|
-
this.#itemQueryMap.delete(id);
|
|
1459
|
-
this.#propagateDeleteOne(id, { item: query });
|
|
1460
|
-
}
|
|
1461
|
-
#prepareItemQuery(query) {
|
|
1462
|
-
if (query.id !== "") this.#itemQueryMap.set(query.id, query);
|
|
1463
|
-
query.on("selfCreated", ({ instance }) => this.#itemQueryMap.set(instance.id, instance));
|
|
1464
|
-
query.on("selfUpdated", ({ instance, item }) => this.#itemUpdateHandler(instance, item));
|
|
1465
|
-
query.on("selfDeleted", ({ instance, id }) => this.#itemDeleteHandler(instance, id));
|
|
1466
|
-
return query;
|
|
1467
|
-
}
|
|
1468
|
-
#simplifyCollectionParams(params) {
|
|
1469
|
-
return {
|
|
1470
|
-
filter: simplifyFilter(params.filter),
|
|
1471
|
-
meta: params.meta,
|
|
1472
|
-
order: simplifyOrderBy(params.order)
|
|
1473
|
-
};
|
|
1474
|
-
}
|
|
1475
|
-
#getCollectionKey({ order, filter }) {
|
|
1476
|
-
return `ORDER<${order ? this.#orderConfig.getKey(order) : ""}>\nFILTER<${filter ? this.#filterConfig.getFilterKey(filter) : ""}>`;
|
|
1477
|
-
}
|
|
1478
|
-
#collectionUpdateHandler(query, items) {
|
|
1479
|
-
this.#propagateUpdateMany(items, { collection: query });
|
|
1480
|
-
}
|
|
1481
|
-
#collectionCreateHandler(query, item) {
|
|
1482
|
-
this.#propagateUpdateOne(item, { collection: query });
|
|
1483
|
-
}
|
|
1484
|
-
#collectionItemUpdated(query, item) {
|
|
1485
|
-
this.#propagateUpdateOne(item, { collection: query });
|
|
1486
|
-
}
|
|
1487
|
-
#collectionItemDeleted(query, id) {
|
|
1488
|
-
this.#propagateDeleteOne(id, { collection: query });
|
|
1489
|
-
}
|
|
1490
|
-
#prepareCollectionQuery(query) {
|
|
1491
|
-
this.#collectionQueryMap.set(this.#getCollectionKey(query[ChimeraGetParamsSym]), query);
|
|
1492
|
-
query.on("selfUpdated", ({ instance, items }) => this.#collectionUpdateHandler(instance, items));
|
|
1493
|
-
query.on("selfItemCreated", ({ instance, item }) => this.#collectionCreateHandler(instance, item));
|
|
1494
|
-
query.on("selfItemUpdated", ({ instance, item }) => this.#collectionItemUpdated(instance, item));
|
|
1495
|
-
query.on("selfItemDeleted", ({ instance, id }) => this.#collectionItemDeleted(instance, id));
|
|
1496
|
-
return query;
|
|
1497
|
-
}
|
|
1498
|
-
#getParentQuery(filter) {
|
|
1499
|
-
for (const q of this.#collectionQueryMap.values()) if (q.ready && isFilterSubset(q[ChimeraGetParamsSym].filter, filter, this.#filterConfig.getOperatorKey)) return q;
|
|
1500
|
-
return null;
|
|
1501
|
-
}
|
|
1502
|
-
constructor(config, filterConfig, orderConfig) {
|
|
1503
|
-
super();
|
|
1504
|
-
this.#entityConfig = config;
|
|
1505
|
-
this.#filterConfig = filterConfig;
|
|
1506
|
-
this.#orderConfig = orderConfig;
|
|
1507
|
-
this.#idGetter = config.idGetter;
|
|
1508
|
-
this.#itemsMap = new ChimeraWeakValueMap();
|
|
1509
|
-
this.#collectionQueryMap = new ChimeraWeakValueMap();
|
|
1510
|
-
this.#itemQueryMap = new ChimeraWeakValueMap();
|
|
1511
|
-
this.#emit("initialized", { instance: this });
|
|
1512
|
-
}
|
|
1513
|
-
[ChimeraSetOneSym](item) {
|
|
1514
|
-
this.#propagateUpdateOne(item);
|
|
1515
|
-
}
|
|
1516
|
-
[ChimeraDeleteOneSym](id) {
|
|
1517
|
-
this.#propagateDeleteOne(id);
|
|
1518
|
-
}
|
|
1519
|
-
[ChimeraSetManySym](items) {
|
|
1520
|
-
this.#propagateUpdateMany(items);
|
|
1521
|
-
}
|
|
1522
|
-
[ChimeraDeleteManySym](ids) {
|
|
1523
|
-
this.#propagateDeleteMany(ids);
|
|
1524
|
-
}
|
|
1525
|
-
[ChimeraUpdateMixedSym](toAdd, toDelete) {
|
|
1526
|
-
this.#propagateUpdateMany(toAdd);
|
|
1527
|
-
this.#propagateDeleteMany(toDelete);
|
|
1528
|
-
}
|
|
1529
|
-
createItem(item, meta) {
|
|
1530
|
-
return this.#prepareItemQuery(new ChimeraItemQuery(this.#entityConfig, {
|
|
1531
|
-
id: "",
|
|
1532
|
-
meta
|
|
1533
|
-
}, null, item));
|
|
1534
|
-
}
|
|
1535
|
-
getItem(id, meta) {
|
|
1536
|
-
const query = this.#itemQueryMap.get(id);
|
|
1537
|
-
if (query) return query;
|
|
1538
|
-
return this.#prepareItemQuery(new ChimeraItemQuery(this.#entityConfig, {
|
|
1539
|
-
id,
|
|
1540
|
-
meta
|
|
1541
|
-
}, this.#itemsMap.get(id) ?? null, null));
|
|
1542
|
-
}
|
|
1543
|
-
getCollection(params) {
|
|
1544
|
-
const simplifiedParams = this.#simplifyCollectionParams(params);
|
|
1545
|
-
const key = this.#getCollectionKey(simplifiedParams);
|
|
1546
|
-
const query = this.#collectionQueryMap.get(key);
|
|
1547
|
-
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 require_defaults.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(require_defaults.chimeraDefaultFilterConfig), filterConfig ?? {});
|
|
1585
|
-
this.#orderConfig = deepObjectAssign(deepObjectClone(require_defaults.chimeraDefaultOrderConfig), orderConfig ?? {});
|
|
1586
|
-
this.#debugConfig = deepObjectAssign(deepObjectClone(require_defaults.chimeraDefaultDebugConfig), debugConfig ?? {});
|
|
1587
|
-
const query = deepObjectAssign(deepObjectClone(require_defaults.chimeraDefaultQueryConfig), queryConfig?.defaults ?? {});
|
|
1588
|
-
this.#queryConfig = Object.fromEntries(Object.entries(queryConfig?.entities ?? require_defaults.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
|
-
}
|
|
1677
|
-
}
|
|
1678
|
-
};
|
|
1679
|
-
|
|
1680
|
-
//#endregion
|
|
1681
|
-
Object.defineProperty(exports, 'ChimeraCollectionQuery', {
|
|
1682
|
-
enumerable: true,
|
|
1683
|
-
get: function () {
|
|
1684
|
-
return ChimeraCollectionQuery;
|
|
1685
|
-
}
|
|
1686
|
-
});
|
|
1687
|
-
Object.defineProperty(exports, 'ChimeraFilterError', {
|
|
1688
|
-
enumerable: true,
|
|
1689
|
-
get: function () {
|
|
1690
|
-
return ChimeraFilterError;
|
|
1691
|
-
}
|
|
1692
|
-
});
|
|
1693
|
-
Object.defineProperty(exports, 'ChimeraFilterOperatorError', {
|
|
1694
|
-
enumerable: true,
|
|
1695
|
-
get: function () {
|
|
1696
|
-
return ChimeraFilterOperatorError;
|
|
1697
|
-
}
|
|
1698
|
-
});
|
|
1699
|
-
Object.defineProperty(exports, 'ChimeraFilterOperatorNotFoundError', {
|
|
1700
|
-
enumerable: true,
|
|
1701
|
-
get: function () {
|
|
1702
|
-
return ChimeraFilterOperatorNotFoundError;
|
|
1703
|
-
}
|
|
1704
|
-
});
|
|
1705
|
-
Object.defineProperty(exports, 'ChimeraItemQuery', {
|
|
1706
|
-
enumerable: true,
|
|
1707
|
-
get: function () {
|
|
1708
|
-
return ChimeraItemQuery;
|
|
1709
|
-
}
|
|
1710
|
-
});
|
|
1711
|
-
Object.defineProperty(exports, 'ChimeraOrderNulls', {
|
|
1712
|
-
enumerable: true,
|
|
1713
|
-
get: function () {
|
|
1714
|
-
return ChimeraOrderNulls;
|
|
1715
|
-
}
|
|
1716
|
-
});
|
|
1717
|
-
Object.defineProperty(exports, 'ChimeraQueryFetchingState', {
|
|
1718
|
-
enumerable: true,
|
|
1719
|
-
get: function () {
|
|
1720
|
-
return ChimeraQueryFetchingState;
|
|
1721
|
-
}
|
|
1722
|
-
});
|
|
1723
|
-
Object.defineProperty(exports, 'ChimeraStore', {
|
|
1724
|
-
enumerable: true,
|
|
1725
|
-
get: function () {
|
|
1726
|
-
return ChimeraStore;
|
|
1727
|
-
}
|
|
1728
|
-
});
|
|
1729
|
-
Object.defineProperty(exports, 'ChimeraWeakValueMap', {
|
|
1730
|
-
enumerable: true,
|
|
1731
|
-
get: function () {
|
|
1732
|
-
return ChimeraWeakValueMap;
|
|
1733
|
-
}
|
|
1734
|
-
});
|
|
1735
|
-
Object.defineProperty(exports, 'chimeraCreateConjunction', {
|
|
1736
|
-
enumerable: true,
|
|
1737
|
-
get: function () {
|
|
1738
|
-
return chimeraCreateConjunction;
|
|
1739
|
-
}
|
|
1740
|
-
});
|
|
1741
|
-
Object.defineProperty(exports, 'chimeraCreateNot', {
|
|
1742
|
-
enumerable: true,
|
|
1743
|
-
get: function () {
|
|
1744
|
-
return chimeraCreateNot;
|
|
1745
|
-
}
|
|
1746
|
-
});
|
|
1747
|
-
Object.defineProperty(exports, 'chimeraCreateOperator', {
|
|
1748
|
-
enumerable: true,
|
|
1749
|
-
get: function () {
|
|
1750
|
-
return chimeraCreateOperator;
|
|
1751
|
-
}
|
|
1752
|
-
});
|
|
1753
|
-
Object.defineProperty(exports, 'chimeraCreateOrderBy', {
|
|
1754
|
-
enumerable: true,
|
|
1755
|
-
get: function () {
|
|
1756
|
-
return chimeraCreateOrderBy;
|
|
1757
|
-
}
|
|
1758
|
-
});
|
|
1759
|
-
Object.defineProperty(exports, 'chimeraIsConjunction', {
|
|
1760
|
-
enumerable: true,
|
|
1761
|
-
get: function () {
|
|
1762
|
-
return chimeraIsConjunction;
|
|
1763
|
-
}
|
|
1764
|
-
});
|
|
1765
|
-
Object.defineProperty(exports, 'chimeraIsOperator', {
|
|
1766
|
-
enumerable: true,
|
|
1767
|
-
get: function () {
|
|
1768
|
-
return chimeraIsOperator;
|
|
1769
|
-
}
|
|
1770
|
-
});
|
|
1771
|
-
//# sourceMappingURL=src-TJG6k3Nr.cjs.map
|