@webda/models 0.0.0-stage → 4.0.0-beta.3
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/LICENSE +166 -0
- package/README.md +146 -2
- package/lib/index.d.ts +11 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -0
- package/lib/index.js.map +1 -0
- package/lib/mock.d.ts +72 -0
- package/lib/mock.d.ts.map +1 -0
- package/lib/mock.js +83 -0
- package/lib/mock.js.map +1 -0
- package/lib/model.model.d.ts +247 -0
- package/lib/model.model.d.ts.map +1 -0
- package/lib/model.model.js +277 -0
- package/lib/model.model.js.map +1 -0
- package/lib/relations.d.ts +705 -0
- package/lib/relations.d.ts.map +1 -0
- package/lib/relations.js +938 -0
- package/lib/relations.js.map +1 -0
- package/lib/repositories/abstract.d.ts +124 -0
- package/lib/repositories/abstract.d.ts.map +1 -0
- package/lib/repositories/abstract.js +249 -0
- package/lib/repositories/abstract.js.map +1 -0
- package/lib/repositories/conformance.d.ts +40 -0
- package/lib/repositories/conformance.d.ts.map +1 -0
- package/lib/repositories/conformance.js +38 -0
- package/lib/repositories/conformance.js.map +1 -0
- package/lib/repositories/event.d.ts +100 -0
- package/lib/repositories/event.d.ts.map +1 -0
- package/lib/repositories/event.js +226 -0
- package/lib/repositories/event.js.map +1 -0
- package/lib/repositories/hooks.d.ts +88 -0
- package/lib/repositories/hooks.d.ts.map +1 -0
- package/lib/repositories/hooks.js +105 -0
- package/lib/repositories/hooks.js.map +1 -0
- package/lib/repositories/memory.d.ts +208 -0
- package/lib/repositories/memory.d.ts.map +1 -0
- package/lib/repositories/memory.js +446 -0
- package/lib/repositories/memory.js.map +1 -0
- package/lib/repositories/repository.d.ts +238 -0
- package/lib/repositories/repository.d.ts.map +1 -0
- package/lib/repositories/repository.js +19 -0
- package/lib/repositories/repository.js.map +1 -0
- package/lib/storable.d.ts +200 -0
- package/lib/storable.d.ts.map +1 -0
- package/lib/storable.js +66 -0
- package/lib/storable.js.map +1 -0
- package/lib/types.d.ts +230 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +12 -0
- package/lib/types.js.map +1 -0
- package/package.json +60 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/repositories/memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,KAAK,EAAE,EAAE,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAc,aAAa,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEpG,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEzD;;;;;GAKG;AACH,MAAM,MAAM,KAAK,GAAG;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,KAAK,GAAG,MAAM,CAAA;KAAE,EAAE,CAAC;IACzD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,MAAM,EAAE;QACN,IAAI,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC;KAC9B,CAAC;CACH,CAAC;AAOF,qFAAqF;AACrF,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;IAC1B,OAAO,EAAE,CAAC,EAAE,CAAC;IACb,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AACF;;;GAGG;AACH,qBAAa,gBAAgB,CAC3B,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,GAAG,CAAC,MAAM,EAAE,MAAM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C,CAAC,CAAC,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC,EAClF,UAAU,EAAE,CAAC,EACb,KAAK,EAAE,MAAM,EACb,uBAAuB,CAAC,EAAE,GAAG,EAC7B,kBAAkB,CAAC,EAAE,GAAG,GACvB,OAAO,CAAC,IAAI,CAAC,CAaf;IAED,gBAAgB;IACV,eAAe,CAAC,CAAC,SAAS,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EACtG,UAAU,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC,EAClF,SAAS,EAAE,CAAC,EACZ,eAAe,CAAC,EAAE,CAAC,GAAG,IAAI,EAC1B,UAAU,CAAC,EAAE,GAAG,GACf,OAAO,CAAC,IAAI,CAAC,CAIf;IAED,8CAA8C;IAC9C,CAAC,UAAU,CAAC;QACV,KAAK;MAGL;CACH"}
|
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
import { deserialize, serialize, serializeRaw } from "@webda/serialize";
|
|
3
|
+
import { AbstractRepository } from "./abstract.js";
|
|
4
|
+
import { WEBDA_TEST } from "./repository.js";
|
|
5
|
+
/** Lazily-loaded WebdaQL module for query parsing */
|
|
6
|
+
let WebdaQL = null;
|
|
7
|
+
/**
|
|
8
|
+
* This is a simple in-memory repository implementation
|
|
9
|
+
* It is used for testing purposes only
|
|
10
|
+
*/
|
|
11
|
+
export class MemoryRepository extends AbstractRepository {
|
|
12
|
+
static { _a = WEBDA_TEST; }
|
|
13
|
+
/**
|
|
14
|
+
* @param model - The model class constructor
|
|
15
|
+
* @param pks - Primary key field names
|
|
16
|
+
* @param separator - Composite key separator (default: "_")
|
|
17
|
+
* @param map - Optional pre-existing Map to use as storage backend
|
|
18
|
+
*/
|
|
19
|
+
constructor(model, pks, separator, map) {
|
|
20
|
+
super(model, pks, separator);
|
|
21
|
+
/** Test utilities - clears all stored data */
|
|
22
|
+
this[_a] = {
|
|
23
|
+
clear: async () => {
|
|
24
|
+
this.storage.clear();
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
this.storage = map || new Map();
|
|
28
|
+
}
|
|
29
|
+
/** @override */
|
|
30
|
+
async get(primaryKey) {
|
|
31
|
+
const key = this.getPrimaryKey(primaryKey).toString();
|
|
32
|
+
const item = this.storage.get(key);
|
|
33
|
+
if (!item)
|
|
34
|
+
throw new Error(`Not found: ${key}`);
|
|
35
|
+
return this.deserialize(item);
|
|
36
|
+
}
|
|
37
|
+
/** @override */
|
|
38
|
+
async create(data, save = true) {
|
|
39
|
+
const item = this.buildItem(data);
|
|
40
|
+
// The key is read from the built item: a primary key generated by the model
|
|
41
|
+
// (e.g. UuidModel) must be the one used for storage
|
|
42
|
+
const key = this.getPrimaryKey(item).toString();
|
|
43
|
+
if (this.storage.has(key)) {
|
|
44
|
+
throw new Error(`Already exists: ${key}`);
|
|
45
|
+
}
|
|
46
|
+
if (save !== false) {
|
|
47
|
+
this.storage.set(key, this.serialize(item));
|
|
48
|
+
}
|
|
49
|
+
return item;
|
|
50
|
+
}
|
|
51
|
+
/** @override */
|
|
52
|
+
async update(data, conditionField, condition) {
|
|
53
|
+
const item = (await this.get(this.getPrimaryKey(data)));
|
|
54
|
+
this.checkCondition(item, conditionField, condition);
|
|
55
|
+
this.storage.set(this.getPrimaryKey(data).toString(), this.serialize(new this.model(data)));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Verify an optimistic locking condition on an item
|
|
59
|
+
* @param item - The item to check
|
|
60
|
+
* @param conditionField - Field to validate
|
|
61
|
+
* @param condition - Expected value
|
|
62
|
+
* @throws Error if the condition does not match
|
|
63
|
+
*/
|
|
64
|
+
checkCondition(item, conditionField, condition) {
|
|
65
|
+
if (conditionField) {
|
|
66
|
+
if (item[conditionField] !== condition) {
|
|
67
|
+
throw new Error(`Condition failed: ${conditionField} !== ${condition}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** @override */
|
|
72
|
+
async patch(primaryKey, data, conditionField, condition) {
|
|
73
|
+
const item = (await this.get(primaryKey));
|
|
74
|
+
this.checkCondition(item, conditionField, condition);
|
|
75
|
+
item.load(data);
|
|
76
|
+
this.storage.set(item.getPrimaryKey().toString(), this.serialize(item));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Serialize the object to a string
|
|
80
|
+
*
|
|
81
|
+
* This method is used to allow switching between different serialization methods
|
|
82
|
+
*
|
|
83
|
+
* The serialized payload is also stamped with a top-level `__type` field
|
|
84
|
+
* carrying the concrete model identifier when available
|
|
85
|
+
* (`item.constructor.Metadata?.Identifier`). This lets `query()` and external
|
|
86
|
+
* storage backends filter results by class without re-instantiating every
|
|
87
|
+
* item — important when a single underlying storage map is shared across a
|
|
88
|
+
* model and its subclasses (the common case in production where each
|
|
89
|
+
* registered model owns its own MemoryRepository pointing at the same Map).
|
|
90
|
+
*
|
|
91
|
+
* The stamp lives on the serializer envelope (sibling of `value` /
|
|
92
|
+
* `$serializer`), not inside `value`. `deserialize()` re-surfaces it on the
|
|
93
|
+
* reconstructed instance as a non-enumerable `__type` property so WebdaQL's
|
|
94
|
+
* filter eval can read it without it ever leaking into `JSON.stringify` or
|
|
95
|
+
* `Object.keys` output — keeping API responses and re-serialize cycles
|
|
96
|
+
* byte-identical for the model's own fields.
|
|
97
|
+
*
|
|
98
|
+
* Models that don't carry Metadata (plain unit-test classes that don't go
|
|
99
|
+
* through Application.setModelMetadata) simply skip the stamp; the resulting
|
|
100
|
+
* payload is byte-identical to the previous implementation.
|
|
101
|
+
*
|
|
102
|
+
* @param item to serialize
|
|
103
|
+
* @returns serialized object
|
|
104
|
+
*/
|
|
105
|
+
serialize(item) {
|
|
106
|
+
const typeIdentifier = item?.constructor?.Metadata?.Identifier;
|
|
107
|
+
if (!typeIdentifier) {
|
|
108
|
+
return serialize(item);
|
|
109
|
+
}
|
|
110
|
+
const raw = serializeRaw(item);
|
|
111
|
+
// serializeRaw returns either { value, $serializer } for objects with
|
|
112
|
+
// metadata, or just the raw value for primitives. Models always come back
|
|
113
|
+
// in the former shape; stamp __type at the envelope level (sibling of
|
|
114
|
+
// value/$serializer) so the deserializer never copies it onto the model.
|
|
115
|
+
if (raw && typeof raw === "object" && raw.value !== undefined) {
|
|
116
|
+
if (raw.__type === undefined) {
|
|
117
|
+
raw.__type = typeIdentifier;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return JSON.stringify(raw);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Unserialize the object from a string
|
|
124
|
+
*
|
|
125
|
+
* Beyond restoring the concrete type via `@webda/serialize`'s
|
|
126
|
+
* `$serializer.type` typeKey, this also surfaces the storage envelope's
|
|
127
|
+
* `__type` stamp on the in-memory instance as a NON-ENUMERABLE property. The
|
|
128
|
+
* non-enumerable bit keeps `__type` invisible to `JSON.stringify` and
|
|
129
|
+
* `Object.keys` (so API responses and re-serialize cycles are byte-identical
|
|
130
|
+
* for the model's own fields), while still being readable via direct
|
|
131
|
+
* property access — which is exactly how WebdaQL's filter eval reads it
|
|
132
|
+
* (`ComparisonExpression.getAttributeValue` walks `obj[name]`).
|
|
133
|
+
*
|
|
134
|
+
* Backward-compat: legacy rows written before the envelope-stamping was
|
|
135
|
+
* introduced won't carry `__type`. In that case we backfill from the
|
|
136
|
+
* repository's own `model.Metadata.Identifier` so they look like records of
|
|
137
|
+
* the parent class — which is exactly what `query()`'s prepended class
|
|
138
|
+
* filter expects (parent + descendants). Plain unit-test classes without
|
|
139
|
+
* Metadata get no stamp at all; their repos opt out of class filtering on
|
|
140
|
+
* the query side too (see `query`).
|
|
141
|
+
*
|
|
142
|
+
* @param item - the serialized string
|
|
143
|
+
* @returns the deserialized model instance
|
|
144
|
+
*/
|
|
145
|
+
deserialize(item) {
|
|
146
|
+
const instance = deserialize(item);
|
|
147
|
+
// Re-parse the envelope to read `__type` (the serializer's deserialize
|
|
148
|
+
// path strips it because it's not in `value`). This is cheap relative to
|
|
149
|
+
// deserialize itself.
|
|
150
|
+
let typeFromEnvelope;
|
|
151
|
+
try {
|
|
152
|
+
const raw = JSON.parse(item);
|
|
153
|
+
if (raw && typeof raw === "object") {
|
|
154
|
+
typeFromEnvelope = raw.__type;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
// Non-JSON or malformed; skip the stamp — instance is still usable.
|
|
159
|
+
}
|
|
160
|
+
const stamped = typeFromEnvelope ?? this.model?.Metadata?.Identifier;
|
|
161
|
+
if (stamped) {
|
|
162
|
+
Object.defineProperty(instance, "__type", {
|
|
163
|
+
value: stamped,
|
|
164
|
+
enumerable: false,
|
|
165
|
+
configurable: true,
|
|
166
|
+
writable: true
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
return instance;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Collect the WebdaQL class-filter identifier list — `this.model`'s
|
|
173
|
+
* identifier and every transitive descendant carried in `Metadata.Subclasses`.
|
|
174
|
+
*
|
|
175
|
+
* Returns `undefined` when the model carries no `Metadata` (plain unit-test
|
|
176
|
+
* classes that didn't go through `Application.setModelMetadata`). In that
|
|
177
|
+
* case `query()` skips the prepend and returns everything in storage,
|
|
178
|
+
* preserving the pre-fix behavior for those bare classes.
|
|
179
|
+
*
|
|
180
|
+
* @returns the list of identifiers to match, or `undefined` when no Metadata
|
|
181
|
+
*/
|
|
182
|
+
buildClassFilterIdentifiers() {
|
|
183
|
+
const meta = this.model?.Metadata;
|
|
184
|
+
if (!meta?.Identifier)
|
|
185
|
+
return undefined;
|
|
186
|
+
const ids = [meta.Identifier];
|
|
187
|
+
const subclasses = Array.isArray(meta.Subclasses) ? meta.Subclasses : [];
|
|
188
|
+
for (const sub of subclasses) {
|
|
189
|
+
const id = sub?.Metadata?.Identifier;
|
|
190
|
+
if (typeof id === "string" && !ids.includes(id))
|
|
191
|
+
ids.push(id);
|
|
192
|
+
}
|
|
193
|
+
return ids;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Build the WebdaQL class-filter clause `__type IN ['A', 'B', ...]` covering
|
|
197
|
+
* `this.model`'s identifier and every transitive descendant.
|
|
198
|
+
*
|
|
199
|
+
* Returns `undefined` when the model carries no `Metadata`.
|
|
200
|
+
*
|
|
201
|
+
* @returns the class-filter WebdaQL clause, or `undefined` when no Metadata
|
|
202
|
+
*/
|
|
203
|
+
buildClassFilter() {
|
|
204
|
+
const ids = this.buildClassFilterIdentifiers();
|
|
205
|
+
if (!ids)
|
|
206
|
+
return undefined;
|
|
207
|
+
// Single-quote each id; escape embedded single quotes by doubling them.
|
|
208
|
+
const literals = ids.map(id => `'${id.replace(/'/g, "''")}'`).join(", ");
|
|
209
|
+
return `__type IN [${literals}]`;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Add query support
|
|
213
|
+
*
|
|
214
|
+
* Class filtering: when several model classes share the same underlying
|
|
215
|
+
* storage Map (e.g. a model and its subclasses each registering their own
|
|
216
|
+
* repository pointing at the same `Map` via `MemoryStore.getRepository`),
|
|
217
|
+
* results are restricted to instances of `this.model` and its transitive
|
|
218
|
+
* descendants. The filter is applied as a real WebdaQL clause —
|
|
219
|
+
* `__type IN ['Webda/Post', 'Webda/BlogPost', ...]` — prepended to the
|
|
220
|
+
* caller's query via `WebdaQL.PrependCondition` (string path) or merged
|
|
221
|
+
* directly into the AST (parsed-Query path used by `iterate`). Each stored
|
|
222
|
+
* item carries its `__type` as a non-enumerable property courtesy of
|
|
223
|
+
* `deserialize`, so the WebdaQL filter eval reads it directly without
|
|
224
|
+
* leaking it to JSON serialization. There is no post-filter step.
|
|
225
|
+
*
|
|
226
|
+
* Models without `Metadata` (plain unit-test classes) opt out of the
|
|
227
|
+
* prepend — `buildClassFilterIdentifiers` returns `undefined` and the query
|
|
228
|
+
* runs as given. External storage backends that adopt the same `__type`
|
|
229
|
+
* stamping convention can use `buildClassFilter` to produce the equivalent
|
|
230
|
+
* server-side WHERE clause.
|
|
231
|
+
*
|
|
232
|
+
* @param query - the query string or parsed query
|
|
233
|
+
* @param params - values for the `?` or `:name` placeholders of a query string
|
|
234
|
+
* @returns the query results with optional continuation token
|
|
235
|
+
*/
|
|
236
|
+
async query(query, params) {
|
|
237
|
+
WebdaQL ??= await import("@webda/ql");
|
|
238
|
+
if (typeof query === "string" && params !== undefined) {
|
|
239
|
+
query = WebdaQL.bind(query, params);
|
|
240
|
+
}
|
|
241
|
+
const ids = this.buildClassFilterIdentifiers();
|
|
242
|
+
let parsed;
|
|
243
|
+
if (typeof query === "string") {
|
|
244
|
+
const merged = ids ? WebdaQL.PrependCondition(query, this.buildClassFilter()) : query;
|
|
245
|
+
parsed = WebdaQL.parse(merged);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
parsed = query;
|
|
249
|
+
if (ids) {
|
|
250
|
+
// Merge the class filter directly into the AST so callers like
|
|
251
|
+
// `iterate()` keep their per-page mutations on the parsed Query
|
|
252
|
+
// (notably `continuationToken`) — re-stringifying via toString() loses
|
|
253
|
+
// those because parse-tree-backed toString reflects the original
|
|
254
|
+
// source, not later runtime mutations.
|
|
255
|
+
const classClause = new WebdaQL.ComparisonExpression("IN", "__type", ids);
|
|
256
|
+
const current = parsed.filter;
|
|
257
|
+
if (current instanceof WebdaQL.AndExpression) {
|
|
258
|
+
// Avoid double-prepend across pages of `iterate()`.
|
|
259
|
+
const already = current.children.some((c) => c instanceof WebdaQL.ComparisonExpression && c.operator === "IN" && c.attribute?.[0] === "__type");
|
|
260
|
+
if (!already) {
|
|
261
|
+
current.children.unshift(classClause);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
parsed.filter = new WebdaQL.AndExpression([classClause, current]);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return MemoryRepository.simulateFind(parsed, [...this.storage.keys()], this);
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Allow to simulate a find on a list of uuids
|
|
273
|
+
* It is static to be reusable by other repository like FileRepository
|
|
274
|
+
* @param query - the parsed query
|
|
275
|
+
* @param uuids - the list of UIDs to search
|
|
276
|
+
* @param repository - the repository to fetch objects from
|
|
277
|
+
* @returns the query results with optional continuation token
|
|
278
|
+
*/
|
|
279
|
+
static async simulateFind(query, uuids, repository) {
|
|
280
|
+
const result = {
|
|
281
|
+
results: [],
|
|
282
|
+
continuationToken: undefined,
|
|
283
|
+
filter: true
|
|
284
|
+
};
|
|
285
|
+
let count = 0;
|
|
286
|
+
let limit = query.limit;
|
|
287
|
+
let offset = parseInt(query.continuationToken || "0");
|
|
288
|
+
const originalOffset = offset;
|
|
289
|
+
if (query.orderBy && query.orderBy.length) {
|
|
290
|
+
offset = 0;
|
|
291
|
+
// We need to retrieve everything to orderBy after
|
|
292
|
+
limit = Number.MAX_SAFE_INTEGER;
|
|
293
|
+
}
|
|
294
|
+
// Need to transfert to Array
|
|
295
|
+
for (const uuid of uuids) {
|
|
296
|
+
count++;
|
|
297
|
+
// Offset start
|
|
298
|
+
if (offset >= count) {
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
const obj = (await repository.get(uuid));
|
|
302
|
+
if (obj && query.filter.eval(obj)) {
|
|
303
|
+
result.results.push(obj);
|
|
304
|
+
if (result.results.length >= limit) {
|
|
305
|
+
result.continuationToken = count.toString();
|
|
306
|
+
return result;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
// Order by
|
|
311
|
+
if (query.orderBy && query.orderBy.length) {
|
|
312
|
+
// Sorting the results
|
|
313
|
+
result.results.sort((a, b) => {
|
|
314
|
+
let valA, valB;
|
|
315
|
+
for (const orderBy of query.orderBy) {
|
|
316
|
+
const invert = orderBy.direction === "ASC" ? 1 : -1;
|
|
317
|
+
valA = WebdaQL.ComparisonExpression.getAttributeValue(a, orderBy.field.split("."));
|
|
318
|
+
valB = WebdaQL.ComparisonExpression.getAttributeValue(b, orderBy.field.split("."));
|
|
319
|
+
if (valA === valB) {
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
if (typeof valA === "string") {
|
|
323
|
+
return valA.localeCompare(valB) * invert;
|
|
324
|
+
}
|
|
325
|
+
return (valA < valB ? -1 : 1) * invert;
|
|
326
|
+
}
|
|
327
|
+
return -1;
|
|
328
|
+
});
|
|
329
|
+
result.results = result.results.slice(originalOffset, query.limit + originalOffset);
|
|
330
|
+
if (result.results.length >= query.limit) {
|
|
331
|
+
result.continuationToken = (query.limit + originalOffset).toString();
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return result;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Add iterator support
|
|
338
|
+
* @param query - the query string
|
|
339
|
+
* @param params - values for the `?` or `:name` placeholders
|
|
340
|
+
*/
|
|
341
|
+
async *iterate(query, params) {
|
|
342
|
+
WebdaQL ??= await import("@webda/ql");
|
|
343
|
+
if (params !== undefined) {
|
|
344
|
+
query = WebdaQL.bind(query, params);
|
|
345
|
+
}
|
|
346
|
+
/* c8 ignore next */
|
|
347
|
+
const q = WebdaQL.parse(query); // Ensure it is valid
|
|
348
|
+
if (!q.limit) {
|
|
349
|
+
q.limit = 100; // Default pagination size
|
|
350
|
+
}
|
|
351
|
+
do {
|
|
352
|
+
const res = await this.query(q);
|
|
353
|
+
for (const i of res.results) {
|
|
354
|
+
yield i;
|
|
355
|
+
}
|
|
356
|
+
q.continuationToken = res.continuationToken;
|
|
357
|
+
} while (q.continuationToken);
|
|
358
|
+
}
|
|
359
|
+
/** @override */
|
|
360
|
+
async delete(primaryKey, _conditionField, _condition) {
|
|
361
|
+
this.storage.delete(this.getPrimaryKey(primaryKey).toString());
|
|
362
|
+
}
|
|
363
|
+
/** @override */
|
|
364
|
+
async exists(primaryKey) {
|
|
365
|
+
return this.storage.has(this.getPrimaryKey(primaryKey).toString());
|
|
366
|
+
}
|
|
367
|
+
/** @override */
|
|
368
|
+
async incrementAttributes(primaryKey, info, _conditionField, _condition) {
|
|
369
|
+
const item = (await this.get(primaryKey));
|
|
370
|
+
if (Array.isArray(info)) {
|
|
371
|
+
for (const entry of info) {
|
|
372
|
+
const prop = typeof entry === "string" ? entry : entry.property;
|
|
373
|
+
const inc = typeof entry === "string" ? 1 : (entry.value ?? 1);
|
|
374
|
+
const parts = prop.split(".");
|
|
375
|
+
let current = item;
|
|
376
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
377
|
+
const part = parts[i];
|
|
378
|
+
current[part] ??= {};
|
|
379
|
+
current = current[part];
|
|
380
|
+
}
|
|
381
|
+
const lastPart = parts[parts.length - 1];
|
|
382
|
+
current[lastPart] = (current[lastPart] || 0) + inc;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
for (const prop in info) {
|
|
387
|
+
const parts = prop.split(".");
|
|
388
|
+
let current = item;
|
|
389
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
390
|
+
const part = parts[i];
|
|
391
|
+
current[part] ??= {};
|
|
392
|
+
current = current[part];
|
|
393
|
+
}
|
|
394
|
+
const lastPart = parts[parts.length - 1];
|
|
395
|
+
current[lastPart] = (current[lastPart] || 0) + info[prop];
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
this.storage.set(this.getPrimaryKey(primaryKey).toString(), this.serialize(item));
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Verify a write condition on a collection item
|
|
402
|
+
* @param item - The array to check
|
|
403
|
+
* @param index - Index of the item in the array
|
|
404
|
+
* @param itemWriteConditionField - Field name to check on the item
|
|
405
|
+
* @param itemWriteCondition - Expected value for the field
|
|
406
|
+
* @throws Error if the condition does not match
|
|
407
|
+
*/
|
|
408
|
+
checkItemWriteCondition(item, index, itemWriteConditionField, itemWriteCondition) {
|
|
409
|
+
if ((Array.isArray(item) && index < item.length && item[index][itemWriteConditionField] === itemWriteCondition) ||
|
|
410
|
+
!itemWriteCondition) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
throw new Error("Item write condition failed");
|
|
414
|
+
}
|
|
415
|
+
/** @override */
|
|
416
|
+
async upsertItemToCollection(primaryKey, collection, item, index, itemWriteConditionField, itemWriteCondition) {
|
|
417
|
+
const obj = (await this.get(primaryKey));
|
|
418
|
+
obj[collection] ??= [];
|
|
419
|
+
this.checkItemWriteCondition(obj[collection], index, itemWriteConditionField, itemWriteCondition);
|
|
420
|
+
const arr = obj[collection];
|
|
421
|
+
if (typeof index === "number") {
|
|
422
|
+
arr[index] = item;
|
|
423
|
+
}
|
|
424
|
+
else {
|
|
425
|
+
arr.push(item);
|
|
426
|
+
}
|
|
427
|
+
this.storage.set(this.getPrimaryKey(primaryKey).toString(), this.serialize(obj));
|
|
428
|
+
}
|
|
429
|
+
/** @override */
|
|
430
|
+
async deleteItemFromCollection(primaryKey, collection, index, itemWriteConditionField, itemWriteCondition) {
|
|
431
|
+
const obj = (await this.get(primaryKey));
|
|
432
|
+
const arr = obj[collection];
|
|
433
|
+
this.checkItemWriteCondition(obj[collection], index, itemWriteConditionField, itemWriteCondition);
|
|
434
|
+
if (Array.isArray(arr) && index >= 0 && index < arr.length) {
|
|
435
|
+
arr.splice(index, 1);
|
|
436
|
+
this.storage.set(this.getPrimaryKey(primaryKey).toString(), this.serialize(obj));
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
/** @override */
|
|
440
|
+
async removeAttribute(primaryKey, attribute, _conditionField, _condition) {
|
|
441
|
+
const obj = (await this.get(primaryKey));
|
|
442
|
+
delete obj[attribute];
|
|
443
|
+
this.storage.set(this.getPrimaryKey(primaryKey).toString(), this.serialize(obj));
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
//# sourceMappingURL=memory.js.map
|
|
@@ -0,0 +1 @@
|
|
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