@statezero/core 0.2.60 → 0.2.62
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/dist/adaptors/vue/components/StateZeroDebugPanel.js +8 -8
- package/dist/flavours/django/manager.d.ts +9 -0
- package/dist/flavours/django/manager.js +13 -2
- package/dist/flavours/django/model.d.ts +6 -0
- package/dist/flavours/django/model.js +8 -0
- package/dist/flavours/django/queryExecutor.d.ts +2 -2
- package/dist/flavours/django/queryExecutor.js +6 -6
- package/dist/flavours/django/querySet.d.ts +13 -3
- package/dist/flavours/django/querySet.js +33 -4
- package/dist/syncEngine/registries/querysetStoreRegistry.js +2 -2
- package/package.json +1 -1
|
@@ -2932,11 +2932,11 @@ class Ce {
|
|
|
2932
2932
|
const r = async ({ ast: i, modelClass: l, canonical_id: a }) => {
|
|
2933
2933
|
const c = {
|
|
2934
2934
|
...i,
|
|
2935
|
-
type: "
|
|
2935
|
+
type: "read"
|
|
2936
2936
|
};
|
|
2937
2937
|
return (await V(
|
|
2938
2938
|
e,
|
|
2939
|
-
"
|
|
2939
|
+
"read",
|
|
2940
2940
|
c,
|
|
2941
2941
|
null,
|
|
2942
2942
|
// operationId
|
|
@@ -3441,15 +3441,15 @@ class hr {
|
|
|
3441
3441
|
* @template T The model type of the QuerySet
|
|
3442
3442
|
* @param {QuerySet<T>} qs
|
|
3443
3443
|
* The QuerySet to execute.
|
|
3444
|
-
* @param {string} [op="
|
|
3445
|
-
* The operation to perform. Defaults to `"
|
|
3444
|
+
* @param {string} [op="read"]
|
|
3445
|
+
* The operation to perform. Defaults to `"read"`, but could be overridden for other list‑style endpoints.
|
|
3446
3446
|
* @param {Object} [args={}]
|
|
3447
3447
|
* Additional arguments to pass through to the underlying API call (e.g. filters, pagination).
|
|
3448
3448
|
* @returns {LiveThenable<import('./makeLiveThenable').Result<T[]>>}
|
|
3449
3449
|
* A live‑thenable wrapping an array of primary‑key values for the fetched models. The live part remains
|
|
3450
3450
|
* synchronized with the in‑memory store.
|
|
3451
3451
|
*/
|
|
3452
|
-
static executeList(e, t = "
|
|
3452
|
+
static executeList(e, t = "read", s = {}) {
|
|
3453
3453
|
const r = x.getEntity(e), o = V(e, t, s).then((i) => {
|
|
3454
3454
|
const { data: l, included: a } = i.data;
|
|
3455
3455
|
we(j, a, e.ModelClass, e);
|
|
@@ -3762,7 +3762,7 @@ class hr {
|
|
|
3762
3762
|
* @param {Object} args - Additional arguments for the operation.
|
|
3763
3763
|
* @returns {Promise<any>} The operation result.
|
|
3764
3764
|
*/
|
|
3765
|
-
static execute(e, t = "
|
|
3765
|
+
static execute(e, t = "read", s = {}) {
|
|
3766
3766
|
if (e._remoteOnly)
|
|
3767
3767
|
return this.executeRemote(e, t, s);
|
|
3768
3768
|
switch (t) {
|
|
@@ -3793,7 +3793,7 @@ class hr {
|
|
|
3793
3793
|
return this.executeAgg(e, t, s);
|
|
3794
3794
|
case "exists":
|
|
3795
3795
|
return this.executeExists(e, t, s);
|
|
3796
|
-
case "
|
|
3796
|
+
case "read":
|
|
3797
3797
|
return this.executeList(e, t, s);
|
|
3798
3798
|
}
|
|
3799
3799
|
throw new Error(`Invalid operation type: ${t}`);
|
|
@@ -3806,7 +3806,7 @@ class hr {
|
|
|
3806
3806
|
* @param {Object} args - Additional arguments for the operation.
|
|
3807
3807
|
* @returns {Promise<any>} The raw API response data.
|
|
3808
3808
|
*/
|
|
3809
|
-
static executeRemote(e, t = "
|
|
3809
|
+
static executeRemote(e, t = "read", s = {}) {
|
|
3810
3810
|
return V(e, t, s);
|
|
3811
3811
|
}
|
|
3812
3812
|
}
|
|
@@ -157,6 +157,15 @@ export class Manager {
|
|
|
157
157
|
* and a boolean indicating whether it was created.
|
|
158
158
|
*/
|
|
159
159
|
updateOrCreate(lookupFields: any, defaults?: Object): Promise<ResultTuple>;
|
|
160
|
+
/**
|
|
161
|
+
* Reconstructs a QuerySet builder from a compiled AST dict.
|
|
162
|
+
* The returned QuerySet can be further chained with .filter(),
|
|
163
|
+
* .exclude(), .orderBy(), .search() before executing.
|
|
164
|
+
*
|
|
165
|
+
* @param {Object} ast - A compiled AST (from build() or compile()).
|
|
166
|
+
* @returns {QuerySet} A new QuerySet that can be chained further.
|
|
167
|
+
*/
|
|
168
|
+
hydrate(ast: Object): QuerySet<any>;
|
|
160
169
|
/**
|
|
161
170
|
* Executes a pre-compiled AST through the standard QueryExecutor path.
|
|
162
171
|
*
|
|
@@ -200,6 +200,17 @@ export class Manager {
|
|
|
200
200
|
async updateOrCreate(lookupFields, defaults = {}) {
|
|
201
201
|
return this.newQuerySet().updateOrCreate(lookupFields, defaults);
|
|
202
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Reconstructs a QuerySet builder from a compiled AST dict.
|
|
205
|
+
* The returned QuerySet can be further chained with .filter(),
|
|
206
|
+
* .exclude(), .orderBy(), .search() before executing.
|
|
207
|
+
*
|
|
208
|
+
* @param {Object} ast - A compiled AST (from build() or compile()).
|
|
209
|
+
* @returns {QuerySet} A new QuerySet that can be chained further.
|
|
210
|
+
*/
|
|
211
|
+
hydrate(ast) {
|
|
212
|
+
return this.QuerySetClass.hydrate(ast, this.ModelClass);
|
|
213
|
+
}
|
|
203
214
|
/**
|
|
204
215
|
* Executes a pre-compiled AST through the standard QueryExecutor path.
|
|
205
216
|
*
|
|
@@ -207,10 +218,10 @@ export class Manager {
|
|
|
207
218
|
* @returns {Promise<any>} The query result.
|
|
208
219
|
*/
|
|
209
220
|
execute(ast) {
|
|
210
|
-
const {
|
|
221
|
+
const { type, args, ...buildOutput } = ast;
|
|
211
222
|
const qs = new this.QuerySetClass(this.ModelClass, { serializerOptions: buildOutput.serializerOptions || {} });
|
|
212
223
|
qs._prebuiltAST = { ...buildOutput, serializerOptions: buildOutput.serializerOptions || {} };
|
|
213
|
-
return QueryExecutor.execute(qs,
|
|
224
|
+
return QueryExecutor.execute(qs, type, args || {});
|
|
214
225
|
}
|
|
215
226
|
/**
|
|
216
227
|
* Applies a search to the QuerySet using the specified search query and fields.
|
|
@@ -54,6 +54,12 @@ export class Model {
|
|
|
54
54
|
* @returns {Promise<any>} The query result.
|
|
55
55
|
*/
|
|
56
56
|
static execute(ast: import("./querySet.js").CompiledAST): Promise<any>;
|
|
57
|
+
/**
|
|
58
|
+
* Reconstructs a QuerySet builder from a compiled AST dict.
|
|
59
|
+
* @param {Object} ast - A compiled AST (from build() or compile()).
|
|
60
|
+
* @returns {QuerySet} A new QuerySet that can be chained further.
|
|
61
|
+
*/
|
|
62
|
+
static hydrate(ast: Object): QuerySet;
|
|
57
63
|
/**
|
|
58
64
|
* Get field permissions for the current user (cached on the class)
|
|
59
65
|
* @param {boolean} refresh - Force refresh the cached permissions
|
|
@@ -322,6 +322,14 @@ export class Model {
|
|
|
322
322
|
static execute(ast) {
|
|
323
323
|
return this.objects.execute(ast);
|
|
324
324
|
}
|
|
325
|
+
/**
|
|
326
|
+
* Reconstructs a QuerySet builder from a compiled AST dict.
|
|
327
|
+
* @param {Object} ast - A compiled AST (from build() or compile()).
|
|
328
|
+
* @returns {QuerySet} A new QuerySet that can be chained further.
|
|
329
|
+
*/
|
|
330
|
+
static hydrate(ast) {
|
|
331
|
+
return this.objects.hydrate(ast);
|
|
332
|
+
}
|
|
325
333
|
/**
|
|
326
334
|
* Get field permissions for the current user (cached on the class)
|
|
327
335
|
* @param {boolean} refresh - Force refresh the cached permissions
|
|
@@ -38,8 +38,8 @@ export class QueryExecutor {
|
|
|
38
38
|
* @template T The model type of the QuerySet
|
|
39
39
|
* @param {QuerySet<T>} qs
|
|
40
40
|
* The QuerySet to execute.
|
|
41
|
-
* @param {string} [op="
|
|
42
|
-
* The operation to perform. Defaults to `"
|
|
41
|
+
* @param {string} [op="read"]
|
|
42
|
+
* The operation to perform. Defaults to `"read"`, but could be overridden for other list‑style endpoints.
|
|
43
43
|
* @param {Object} [args={}]
|
|
44
44
|
* Additional arguments to pass through to the underlying API call (e.g. filters, pagination).
|
|
45
45
|
* @returns {LiveThenable<import('./makeLiveThenable').Result<T[]>>}
|
|
@@ -78,15 +78,15 @@ export class QueryExecutor {
|
|
|
78
78
|
* @template T The model type of the QuerySet
|
|
79
79
|
* @param {QuerySet<T>} qs
|
|
80
80
|
* The QuerySet to execute.
|
|
81
|
-
* @param {string} [op="
|
|
82
|
-
* The operation to perform. Defaults to `"
|
|
81
|
+
* @param {string} [op="read"]
|
|
82
|
+
* The operation to perform. Defaults to `"read"`, but could be overridden for other list‑style endpoints.
|
|
83
83
|
* @param {Object} [args={}]
|
|
84
84
|
* Additional arguments to pass through to the underlying API call (e.g. filters, pagination).
|
|
85
85
|
* @returns {LiveThenable<import('./makeLiveThenable').Result<T[]>>}
|
|
86
86
|
* A live‑thenable wrapping an array of primary‑key values for the fetched models. The live part remains
|
|
87
87
|
* synchronized with the in‑memory store.
|
|
88
88
|
*/
|
|
89
|
-
static executeList(qs, op = "
|
|
89
|
+
static executeList(qs, op = "read", args = {}) {
|
|
90
90
|
const live = querysetStoreRegistry.getEntity(qs);
|
|
91
91
|
const promise = makeApiCall(qs, op, args).then((resp) => {
|
|
92
92
|
const { data, included } = resp.data;
|
|
@@ -538,7 +538,7 @@ export class QueryExecutor {
|
|
|
538
538
|
* @param {Object} args - Additional arguments for the operation.
|
|
539
539
|
* @returns {Promise<any>} The operation result.
|
|
540
540
|
*/
|
|
541
|
-
static execute(querySet, operationType = "
|
|
541
|
+
static execute(querySet, operationType = "read", args = {}) {
|
|
542
542
|
if (querySet._remoteOnly) {
|
|
543
543
|
return this.executeRemote(querySet, operationType, args);
|
|
544
544
|
}
|
|
@@ -571,7 +571,7 @@ export class QueryExecutor {
|
|
|
571
571
|
return this.executeAgg(querySet, operationType, args);
|
|
572
572
|
case "exists":
|
|
573
573
|
return this.executeExists(querySet, operationType, args);
|
|
574
|
-
case "
|
|
574
|
+
case "read":
|
|
575
575
|
return this.executeList(querySet, operationType, args);
|
|
576
576
|
}
|
|
577
577
|
throw new Error(`Invalid operation type: ${operationType}`);
|
|
@@ -584,7 +584,7 @@ export class QueryExecutor {
|
|
|
584
584
|
* @param {Object} args - Additional arguments for the operation.
|
|
585
585
|
* @returns {Promise<any>} The raw API response data.
|
|
586
586
|
*/
|
|
587
|
-
static executeRemote(querySet, operationType = "
|
|
587
|
+
static executeRemote(querySet, operationType = "read", args = {}) {
|
|
588
588
|
return makeApiCall(querySet, operationType, args);
|
|
589
589
|
}
|
|
590
590
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* A compiled AST that can be serialized and later executed via Model.execute().
|
|
3
3
|
*
|
|
4
4
|
* @typedef {Object} CompiledAST
|
|
5
|
-
* @property {string}
|
|
5
|
+
* @property {string} type - The operation type (e.g. 'read', 'get', 'create').
|
|
6
6
|
* @property {Object} args - Operation-specific arguments.
|
|
7
7
|
* @property {Object|null} filter - The filter AST node.
|
|
8
8
|
* @property {Object|null} search - The search configuration.
|
|
@@ -16,6 +16,16 @@
|
|
|
16
16
|
* @template T
|
|
17
17
|
*/
|
|
18
18
|
export class QuerySet<T> {
|
|
19
|
+
/**
|
|
20
|
+
* Reconstructs a QuerySet builder from a compiled AST dict.
|
|
21
|
+
* The returned QuerySet can be further chained with .filter(),
|
|
22
|
+
* .exclude(), .orderBy(), .search() before executing.
|
|
23
|
+
*
|
|
24
|
+
* @param {Object} ast - A compiled AST (from build() or compile()).
|
|
25
|
+
* @param {Function} ModelClass - The model constructor.
|
|
26
|
+
* @returns {QuerySet} A new QuerySet that can be chained further.
|
|
27
|
+
*/
|
|
28
|
+
static hydrate(ast: Object, ModelClass: Function): QuerySet<any>;
|
|
19
29
|
/**
|
|
20
30
|
* Creates a new QuerySet.
|
|
21
31
|
*
|
|
@@ -335,9 +345,9 @@ export class QuerySet<T> {
|
|
|
335
345
|
*/
|
|
336
346
|
export type CompiledAST = {
|
|
337
347
|
/**
|
|
338
|
-
* - The operation type (e.g. '
|
|
348
|
+
* - The operation type (e.g. 'read', 'get', 'create').
|
|
339
349
|
*/
|
|
340
|
-
|
|
350
|
+
type: string;
|
|
341
351
|
/**
|
|
342
352
|
* - Operation-specific arguments.
|
|
343
353
|
*/
|
|
@@ -11,7 +11,7 @@ const clone = rfdc();
|
|
|
11
11
|
* A compiled AST that can be serialized and later executed via Model.execute().
|
|
12
12
|
*
|
|
13
13
|
* @typedef {Object} CompiledAST
|
|
14
|
-
* @property {string}
|
|
14
|
+
* @property {string} type - The operation type (e.g. 'read', 'get', 'create').
|
|
15
15
|
* @property {Object} args - Operation-specific arguments.
|
|
16
16
|
* @property {Object|null} filter - The filter AST node.
|
|
17
17
|
* @property {Object|null} search - The search configuration.
|
|
@@ -666,11 +666,11 @@ export class QuerySet {
|
|
|
666
666
|
* @returns {CompiledAST} The compiled AST.
|
|
667
667
|
*/
|
|
668
668
|
_compile(op, args = {}) {
|
|
669
|
-
return { op, args, ...this.build() };
|
|
669
|
+
return { type: op, args, ...this.build() };
|
|
670
670
|
}
|
|
671
671
|
get compile() {
|
|
672
672
|
return {
|
|
673
|
-
fetch: (args) => this._compile('
|
|
673
|
+
fetch: (args) => this._compile('read', args),
|
|
674
674
|
get: (args) => this._compile('get', args),
|
|
675
675
|
first: (args) => this._compile('first', args),
|
|
676
676
|
last: (args) => this._compile('last', args),
|
|
@@ -688,6 +688,35 @@ export class QuerySet {
|
|
|
688
688
|
updateOrCreate: (args) => this._compile('update_or_create', args),
|
|
689
689
|
};
|
|
690
690
|
}
|
|
691
|
+
/**
|
|
692
|
+
* Reconstructs a QuerySet builder from a compiled AST dict.
|
|
693
|
+
* The returned QuerySet can be further chained with .filter(),
|
|
694
|
+
* .exclude(), .orderBy(), .search() before executing.
|
|
695
|
+
*
|
|
696
|
+
* @param {Object} ast - A compiled AST (from build() or compile()).
|
|
697
|
+
* @param {Function} ModelClass - The model constructor.
|
|
698
|
+
* @returns {QuerySet} A new QuerySet that can be chained further.
|
|
699
|
+
*/
|
|
700
|
+
static hydrate(ast, ModelClass) {
|
|
701
|
+
const nodes = [];
|
|
702
|
+
// Restore filter tree as a single pre-built node
|
|
703
|
+
if (ast.filter) {
|
|
704
|
+
nodes.push(ast.filter);
|
|
705
|
+
}
|
|
706
|
+
// Restore search as a search node
|
|
707
|
+
if (ast.search) {
|
|
708
|
+
nodes.push({
|
|
709
|
+
type: "search",
|
|
710
|
+
searchQuery: ast.search.searchQuery,
|
|
711
|
+
searchFields: ast.search.searchFields,
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
return new QuerySet(ModelClass, {
|
|
715
|
+
nodes,
|
|
716
|
+
orderBy: ast.orderBy ? [...ast.orderBy] : undefined,
|
|
717
|
+
aggregations: ast.aggregations ? [...ast.aggregations] : [],
|
|
718
|
+
});
|
|
719
|
+
}
|
|
691
720
|
build() {
|
|
692
721
|
if (this._prebuiltAST)
|
|
693
722
|
return clone(this._prebuiltAST);
|
|
@@ -759,7 +788,7 @@ export class QuerySet {
|
|
|
759
788
|
...querySet._getConfig(),
|
|
760
789
|
materialized: true,
|
|
761
790
|
}, this);
|
|
762
|
-
return QueryExecutor.execute(materializedQs, "
|
|
791
|
+
return QueryExecutor.execute(materializedQs, "read");
|
|
763
792
|
}
|
|
764
793
|
/**
|
|
765
794
|
* Implements the async iterator protocol so that you can iterate over the QuerySet.
|
|
@@ -182,9 +182,9 @@ export class QuerysetStoreRegistry {
|
|
|
182
182
|
// queryset back to the registry / store
|
|
183
183
|
const payload = {
|
|
184
184
|
...ast,
|
|
185
|
-
type: '
|
|
185
|
+
type: 'read'
|
|
186
186
|
};
|
|
187
|
-
const response = await makeApiCall(queryset, '
|
|
187
|
+
const response = await makeApiCall(queryset, 'read', payload, null, // operationId
|
|
188
188
|
null, // beforeExit
|
|
189
189
|
canonical_id, // canonical_id for caching
|
|
190
190
|
{ namespace: 'sync', timeout: 30000 } // Sync ops on separate queue
|
package/package.json
CHANGED