@statezero/core 0.2.55 → 0.2.58
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 +13 -6
- package/dist/cli/commands/syncModels.js +23 -1
- package/dist/flavours/django/errors.d.ts +3 -1
- package/dist/flavours/django/errors.js +5 -3
- package/dist/flavours/django/manager.d.ts +7 -0
- package/dist/flavours/django/manager.js +12 -0
- package/dist/flavours/django/model.d.ts +7 -0
- package/dist/flavours/django/model.js +9 -0
- package/dist/flavours/django/querySet.d.ts +69 -3
- package/dist/flavours/django/querySet.js +40 -1
- package/dist/models/backend1/django_app/author.schema.json +16 -16
- package/dist/models/backend1/django_app/book.schema.json +11 -11
- package/dist/models/backend1/django_app/composeditem.schema.json +3 -3
- package/dist/models/backend1/django_app/comprehensivemodel.schema.json +3 -3
- package/dist/models/backend1/django_app/dailyrate.schema.json +7 -7
- package/dist/models/backend1/django_app/errortestcompoundunique.schema.json +4 -4
- package/dist/models/backend1/django_app/errortestonetoonemodel.schema.json +2 -2
- package/dist/models/backend1/django_app/errortestprotectedchild.schema.json +2 -2
- package/dist/models/backend1/django_app/errortestuniquemodel.schema.json +1 -1
- package/dist/models/backend1/django_app/excludeditem.schema.json +2 -2
- package/dist/models/backend1/django_app/hfchild.schema.json +2 -2
- package/dist/models/backend1/django_app/hfparent.schema.json +2 -2
- package/dist/models/backend1/django_app/index.js +2 -0
- package/dist/models/backend1/django_app/m2mdepthtestlevel1.schema.json +2 -2
- package/dist/models/backend1/django_app/m2mdepthtestlevel2.schema.json +2 -2
- package/dist/models/backend1/django_app/m2mdepthtestlevel3.schema.json +2 -2
- package/dist/models/backend1/django_app/modelwithrestrictedfields.schema.json +2 -2
- package/dist/models/backend1/django_app/nodeleteitem.schema.json +2 -2
- package/dist/models/backend1/django_app/objectlevelitem.schema.json +2 -2
- package/dist/models/backend1/django_app/order.schema.json +6 -6
- package/dist/models/backend1/django_app/orderitem.schema.json +4 -4
- package/dist/models/backend1/django_app/product.schema.json +11 -11
- package/dist/models/backend1/django_app/readonlyitem.schema.json +2 -2
- package/dist/models/backend1/django_app/restrictedcreateitem.schema.json +2 -2
- package/dist/models/backend1/django_app/restrictededititem.schema.json +2 -2
- package/dist/models/backend1/django_app/restrictedfieldrelatedmodel.schema.json +2 -2
- package/dist/models/backend1/django_app/rowfiltereditem.schema.json +2 -2
- package/dist/models/backend1/django_app/tag.schema.json +10 -10
- package/dist/models/backend1/django_app/uuidmessage.d.ts +156 -0
- package/dist/models/backend1/django_app/uuidmessage.js +72 -0
- package/dist/models/backend1/django_app/uuidmessage.schema.json +136 -0
- package/dist/models/backend1/django_app/uuiduser.d.ts +92 -0
- package/dist/models/backend1/django_app/uuiduser.js +69 -0
- package/dist/models/backend1/django_app/uuiduser.schema.json +70 -0
- package/dist/models/default/django_app/author.schema.json +16 -16
- package/dist/models/default/django_app/book.schema.json +11 -11
- package/dist/models/default/django_app/composeditem.schema.json +3 -3
- package/dist/models/default/django_app/comprehensivemodel.schema.json +3 -3
- package/dist/models/default/django_app/dailyrate.schema.json +7 -7
- package/dist/models/default/django_app/errortestcompoundunique.schema.json +4 -4
- package/dist/models/default/django_app/errortestonetoonemodel.schema.json +2 -2
- package/dist/models/default/django_app/errortestprotectedchild.schema.json +2 -2
- package/dist/models/default/django_app/errortestuniquemodel.schema.json +1 -1
- package/dist/models/default/django_app/excludeditem.schema.json +2 -2
- package/dist/models/default/django_app/hfchild.schema.json +2 -2
- package/dist/models/default/django_app/hfparent.schema.json +2 -2
- package/dist/models/default/django_app/index.js +2 -0
- package/dist/models/default/django_app/m2mdepthtestlevel1.schema.json +2 -2
- package/dist/models/default/django_app/m2mdepthtestlevel2.schema.json +2 -2
- package/dist/models/default/django_app/m2mdepthtestlevel3.schema.json +2 -2
- package/dist/models/default/django_app/modelwithrestrictedfields.schema.json +2 -2
- package/dist/models/default/django_app/nodeleteitem.schema.json +2 -2
- package/dist/models/default/django_app/objectlevelitem.schema.json +2 -2
- package/dist/models/default/django_app/order.schema.json +6 -6
- package/dist/models/default/django_app/orderitem.schema.json +4 -4
- package/dist/models/default/django_app/product.schema.json +11 -11
- package/dist/models/default/django_app/readonlyitem.schema.json +2 -2
- package/dist/models/default/django_app/restrictedcreateitem.schema.json +2 -2
- package/dist/models/default/django_app/restrictededititem.schema.json +2 -2
- package/dist/models/default/django_app/restrictedfieldrelatedmodel.schema.json +2 -2
- package/dist/models/default/django_app/rowfiltereditem.schema.json +2 -2
- package/dist/models/default/django_app/tag.schema.json +10 -10
- package/dist/models/default/django_app/uuidmessage.d.ts +156 -0
- package/dist/models/default/django_app/uuidmessage.js +72 -0
- package/dist/models/default/django_app/uuidmessage.schema.json +136 -0
- package/dist/models/default/django_app/uuiduser.d.ts +92 -0
- package/dist/models/default/django_app/uuiduser.js +69 -0
- package/dist/models/default/django_app/uuiduser.schema.json +70 -0
- package/dist/syncEngine/stores/querysetStore.js +2 -1
- package/package.json +1 -1
|
@@ -927,9 +927,10 @@ class fe extends Error {
|
|
|
927
927
|
* @param {string} code - The error code.
|
|
928
928
|
* @param {IErrorDetail|Object|string} detail - The error details.
|
|
929
929
|
* @param {number} status - The HTTP status code.
|
|
930
|
+
* @param {Object} [data={}] - Additional structured data from the server.
|
|
930
931
|
*/
|
|
931
|
-
constructor(e, t, s, r) {
|
|
932
|
-
super(e), this.name = "StateZeroError", this.code = t, this.detail = s, this.status = r, Object.setPrototypeOf(this, new.target.prototype), As(this);
|
|
932
|
+
constructor(e, t, s, r, o = {}) {
|
|
933
|
+
super(e), this.name = "StateZeroError", this.code = t, this.detail = s, this.status = r, this.data = o, Object.setPrototypeOf(this, new.target.prototype), As(this);
|
|
933
934
|
}
|
|
934
935
|
/**
|
|
935
936
|
* Returns a full error message including the detail.
|
|
@@ -1029,7 +1030,7 @@ class U extends fe {
|
|
|
1029
1030
|
}
|
|
1030
1031
|
}
|
|
1031
1032
|
function Fs(n) {
|
|
1032
|
-
const { status: e, type: t, detail: s } = n;
|
|
1033
|
+
const { status: e, type: t, detail: s, data: r } = n;
|
|
1033
1034
|
if (t === void 0 && s === "Invalid token.")
|
|
1034
1035
|
return new lt(s, 403);
|
|
1035
1036
|
switch (t) {
|
|
@@ -1054,7 +1055,13 @@ function Fs(n) {
|
|
|
1054
1055
|
case "ValueError":
|
|
1055
1056
|
return new $e(s, e);
|
|
1056
1057
|
default:
|
|
1057
|
-
return e === 400 ? new $e(s, e) : e === 403 ? new lt(s, e) : e === 404 ? new It(s, e) : e === 409 ? new Nt(s, e) : new fe(
|
|
1058
|
+
return e === 400 ? new $e(s, e) : e === 403 ? new lt(s, e) : e === 404 ? new It(s, e) : e === 409 ? new Nt(s, e) : new fe(
|
|
1059
|
+
s || "Unknown error",
|
|
1060
|
+
t || "unknown",
|
|
1061
|
+
s,
|
|
1062
|
+
e,
|
|
1063
|
+
r || {}
|
|
1064
|
+
);
|
|
1058
1065
|
}
|
|
1059
1066
|
}
|
|
1060
1067
|
const xt = {
|
|
@@ -2673,8 +2680,8 @@ class ar {
|
|
|
2673
2680
|
_hasRecentOps(e) {
|
|
2674
2681
|
const t = e.operations, s = this.lastSync ?? this._createdAt;
|
|
2675
2682
|
for (let r = t.length - 1; r >= 0; r--)
|
|
2676
|
-
if (t[r].status !== C.REJECTED)
|
|
2677
|
-
return
|
|
2683
|
+
if (t[r].status !== C.REJECTED && (t[r].status !== C.CONFIRMED || t[r].timestamp >= s))
|
|
2684
|
+
return !0;
|
|
2678
2685
|
return !1;
|
|
2679
2686
|
}
|
|
2680
2687
|
/** Build set of PKs from ops newer than lastSync. Only used for no-offset querysets. */
|
|
@@ -248,7 +248,7 @@ const TS_DECLARATION_TEMPLATE = `/**
|
|
|
248
248
|
|
|
249
249
|
import { Model, Manager } from '{{modulePath}}';
|
|
250
250
|
import { StringOperators, NumberOperators, BooleanOperators, DateOperators } from '{{modulePath}}';
|
|
251
|
-
import { QuerySet, LiveQuerySet, LiveQuerySetOptions, MetricResult, ResultTuple, SerializerOptions, NestedPaths } from '{{modulePath}}';
|
|
251
|
+
import { QuerySet, LiveQuerySet, LiveQuerySetOptions, MetricResult, ResultTuple, SerializerOptions, NestedPaths, CompiledAST } from '{{modulePath}}';
|
|
252
252
|
|
|
253
253
|
// Re-export the real Manager for runtime use
|
|
254
254
|
import { Manager as RuntimeManager } from '{{modulePath}}';
|
|
@@ -387,6 +387,26 @@ export declare class {{className}}QuerySet extends QuerySet<any> {
|
|
|
387
387
|
delete(): Promise<[number, Record<string, number>]>;
|
|
388
388
|
exists(): Promise<boolean>;
|
|
389
389
|
fetch(serializerOptions?: SerializerOptions): Promise<{{className}}[]>;
|
|
390
|
+
|
|
391
|
+
// Compile
|
|
392
|
+
get compile(): {
|
|
393
|
+
fetch(args?: Record<string, any>): CompiledAST;
|
|
394
|
+
get(args?: Record<string, any>): CompiledAST;
|
|
395
|
+
first(args?: Record<string, any>): CompiledAST;
|
|
396
|
+
last(args?: Record<string, any>): CompiledAST;
|
|
397
|
+
count(args?: Record<string, any>): CompiledAST;
|
|
398
|
+
sum(args?: Record<string, any>): CompiledAST;
|
|
399
|
+
avg(args?: Record<string, any>): CompiledAST;
|
|
400
|
+
min(args?: Record<string, any>): CompiledAST;
|
|
401
|
+
max(args?: Record<string, any>): CompiledAST;
|
|
402
|
+
exists(args?: Record<string, any>): CompiledAST;
|
|
403
|
+
create(args?: Record<string, any>): CompiledAST;
|
|
404
|
+
bulkCreate(args?: Record<string, any>): CompiledAST;
|
|
405
|
+
update(args?: Record<string, any>): CompiledAST;
|
|
406
|
+
delete(args?: Record<string, any>): CompiledAST;
|
|
407
|
+
getOrCreate(args?: Record<string, any>): CompiledAST;
|
|
408
|
+
updateOrCreate(args?: Record<string, any>): CompiledAST;
|
|
409
|
+
};
|
|
390
410
|
}
|
|
391
411
|
|
|
392
412
|
/**
|
|
@@ -400,6 +420,7 @@ export declare class {{className}}Manager extends Manager {
|
|
|
400
420
|
get(filters?: {{className}}FilterData, serializerOptions?: SerializerOptions): Promise<{{className}}>;
|
|
401
421
|
create(data: {{className}}CreateData): Promise<{{className}}>;
|
|
402
422
|
delete(): Promise<[number, Record<string, number>]>;
|
|
423
|
+
execute(ast: CompiledAST): Promise<any>;
|
|
403
424
|
}
|
|
404
425
|
|
|
405
426
|
/**
|
|
@@ -471,6 +492,7 @@ export declare class {{className}} extends Model implements {{interfaceName}} {
|
|
|
471
492
|
|
|
472
493
|
constructor(data: Partial<{{interfaceName}}>);
|
|
473
494
|
serialize(): Partial<{{interfaceName}}>;
|
|
495
|
+
static execute(ast: CompiledAST): Promise<any>;
|
|
474
496
|
}
|
|
475
497
|
|
|
476
498
|
/**
|
|
@@ -28,11 +28,13 @@ export class StateZeroError extends Error {
|
|
|
28
28
|
* @param {string} code - The error code.
|
|
29
29
|
* @param {IErrorDetail|Object|string} detail - The error details.
|
|
30
30
|
* @param {number} status - The HTTP status code.
|
|
31
|
+
* @param {Object} [data={}] - Additional structured data from the server.
|
|
31
32
|
*/
|
|
32
|
-
constructor(message: string, code: string, detail: IErrorDetail | Object | string, status: number);
|
|
33
|
+
constructor(message: string, code: string, detail: IErrorDetail | Object | string, status: number, data?: Object);
|
|
33
34
|
code: string;
|
|
34
35
|
detail: string | Object | IErrorDetail;
|
|
35
36
|
status: number;
|
|
37
|
+
data: Object;
|
|
36
38
|
/**
|
|
37
39
|
* Returns a full error message including the detail.
|
|
38
40
|
*
|
|
@@ -21,13 +21,15 @@ export class StateZeroError extends Error {
|
|
|
21
21
|
* @param {string} code - The error code.
|
|
22
22
|
* @param {IErrorDetail|Object|string} detail - The error details.
|
|
23
23
|
* @param {number} status - The HTTP status code.
|
|
24
|
+
* @param {Object} [data={}] - Additional structured data from the server.
|
|
24
25
|
*/
|
|
25
|
-
constructor(message, code, detail, status) {
|
|
26
|
+
constructor(message, code, detail, status, data = {}) {
|
|
26
27
|
super(message);
|
|
27
28
|
this.name = "StateZeroError";
|
|
28
29
|
this.code = code;
|
|
29
30
|
this.detail = detail;
|
|
30
31
|
this.status = status;
|
|
32
|
+
this.data = data;
|
|
31
33
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
32
34
|
emitError(this);
|
|
33
35
|
}
|
|
@@ -169,7 +171,7 @@ export class ConfigError extends StateZeroError {
|
|
|
169
171
|
* @returns {StateZeroError} An instance of a StateZeroError subclass.
|
|
170
172
|
*/
|
|
171
173
|
export function parseStateZeroError(errorResponse) {
|
|
172
|
-
const { status, type, detail } = errorResponse;
|
|
174
|
+
const { status, type, detail, data } = errorResponse;
|
|
173
175
|
// Handle undefined type/status case (like in permission denied)
|
|
174
176
|
if (type === undefined && detail === 'Invalid token.') {
|
|
175
177
|
return new PermissionDenied(detail, 403);
|
|
@@ -209,6 +211,6 @@ export function parseStateZeroError(errorResponse) {
|
|
|
209
211
|
else if (status === 409) {
|
|
210
212
|
return new ConflictError(detail, status);
|
|
211
213
|
}
|
|
212
|
-
return new StateZeroError("Unknown error", "unknown", detail, status);
|
|
214
|
+
return new StateZeroError(detail || "Unknown error", type || "unknown", detail, status, data || {});
|
|
213
215
|
}
|
|
214
216
|
}
|
|
@@ -157,6 +157,13 @@ 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
|
+
* Executes a pre-compiled AST through the standard QueryExecutor path.
|
|
162
|
+
*
|
|
163
|
+
* @param {import('./querySet.js').CompiledAST} ast - A compiled AST from QuerySet.compile()
|
|
164
|
+
* @returns {Promise<any>} The query result.
|
|
165
|
+
*/
|
|
166
|
+
execute(ast: import("./querySet.js").CompiledAST): Promise<any>;
|
|
160
167
|
/**
|
|
161
168
|
* Applies a search to the QuerySet using the specified search query and fields.
|
|
162
169
|
*
|
|
@@ -200,6 +200,18 @@ export class Manager {
|
|
|
200
200
|
async updateOrCreate(lookupFields, defaults = {}) {
|
|
201
201
|
return this.newQuerySet().updateOrCreate(lookupFields, defaults);
|
|
202
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Executes a pre-compiled AST through the standard QueryExecutor path.
|
|
205
|
+
*
|
|
206
|
+
* @param {import('./querySet.js').CompiledAST} ast - A compiled AST from QuerySet.compile()
|
|
207
|
+
* @returns {Promise<any>} The query result.
|
|
208
|
+
*/
|
|
209
|
+
execute(ast) {
|
|
210
|
+
const { op, args, ...buildOutput } = ast;
|
|
211
|
+
const qs = new this.QuerySetClass(this.ModelClass, { serializerOptions: buildOutput.serializerOptions || {} });
|
|
212
|
+
qs._prebuiltAST = { ...buildOutput, serializerOptions: buildOutput.serializerOptions || {} };
|
|
213
|
+
return QueryExecutor.execute(qs, op, args || {});
|
|
214
|
+
}
|
|
203
215
|
/**
|
|
204
216
|
* Applies a search to the QuerySet using the specified search query and fields.
|
|
205
217
|
*
|
|
@@ -47,6 +47,13 @@ export class Model {
|
|
|
47
47
|
* @returns {Promise<boolean>} Promise that resolves to true if valid, throws error if invalid
|
|
48
48
|
*/
|
|
49
49
|
static validate(data: Object, validateType?: string, partial?: boolean): Promise<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* Executes a pre-compiled AST through the standard QueryExecutor path.
|
|
52
|
+
*
|
|
53
|
+
* @param {import('./querySet.js').CompiledAST} ast - A compiled AST from QuerySet.compile()
|
|
54
|
+
* @returns {Promise<any>} The query result.
|
|
55
|
+
*/
|
|
56
|
+
static execute(ast: import("./querySet.js").CompiledAST): Promise<any>;
|
|
50
57
|
/**
|
|
51
58
|
* Get field permissions for the current user (cached on the class)
|
|
52
59
|
* @param {boolean} refresh - Force refresh the cached permissions
|
|
@@ -313,6 +313,15 @@ export class Model {
|
|
|
313
313
|
throw new Error(`Validation failed: ${error.message}`);
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
|
+
/**
|
|
317
|
+
* Executes a pre-compiled AST through the standard QueryExecutor path.
|
|
318
|
+
*
|
|
319
|
+
* @param {import('./querySet.js').CompiledAST} ast - A compiled AST from QuerySet.compile()
|
|
320
|
+
* @returns {Promise<any>} The query result.
|
|
321
|
+
*/
|
|
322
|
+
static execute(ast) {
|
|
323
|
+
return this.objects.execute(ast);
|
|
324
|
+
}
|
|
316
325
|
/**
|
|
317
326
|
* Get field permissions for the current user (cached on the class)
|
|
318
327
|
* @param {boolean} refresh - Force refresh the cached permissions
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A compiled AST that can be serialized and later executed via Model.execute().
|
|
3
|
+
*
|
|
4
|
+
* @typedef {Object} CompiledAST
|
|
5
|
+
* @property {string} op - The operation type (e.g. 'list', 'get', 'create').
|
|
6
|
+
* @property {Object} args - Operation-specific arguments.
|
|
7
|
+
* @property {Object|null} filter - The filter AST node.
|
|
8
|
+
* @property {Object|null} search - The search configuration.
|
|
9
|
+
* @property {Array} aggregations - Aggregation operations.
|
|
10
|
+
* @property {Array<string>} [orderBy] - Ordering fields.
|
|
11
|
+
* @property {Object} serializerOptions - Serializer options.
|
|
12
|
+
*/
|
|
1
13
|
/**
|
|
2
14
|
* A QuerySet provides a fluent API for constructing and executing queries.
|
|
3
15
|
*
|
|
@@ -273,9 +285,30 @@ export class QuerySet<T> {
|
|
|
273
285
|
/**
|
|
274
286
|
* Builds the final query object to be sent to the backend (simple jsonable object format).
|
|
275
287
|
*
|
|
276
|
-
* @
|
|
277
|
-
|
|
278
|
-
|
|
288
|
+
* @param {string} op - The operation type.
|
|
289
|
+
* @param {Object} [args={}] - Operation-specific arguments.
|
|
290
|
+
* @returns {CompiledAST} The compiled AST.
|
|
291
|
+
*/
|
|
292
|
+
_compile(op: string, args?: Object): CompiledAST;
|
|
293
|
+
get compile(): {
|
|
294
|
+
fetch: (args: any) => CompiledAST;
|
|
295
|
+
get: (args: any) => CompiledAST;
|
|
296
|
+
first: (args: any) => CompiledAST;
|
|
297
|
+
last: (args: any) => CompiledAST;
|
|
298
|
+
count: (args: any) => CompiledAST;
|
|
299
|
+
sum: (args: any) => CompiledAST;
|
|
300
|
+
avg: (args: any) => CompiledAST;
|
|
301
|
+
min: (args: any) => CompiledAST;
|
|
302
|
+
max: (args: any) => CompiledAST;
|
|
303
|
+
exists: (args: any) => CompiledAST;
|
|
304
|
+
create: (args: any) => CompiledAST;
|
|
305
|
+
bulkCreate: (args: any) => CompiledAST;
|
|
306
|
+
update: (args: any) => CompiledAST;
|
|
307
|
+
delete: (args: any) => CompiledAST;
|
|
308
|
+
getOrCreate: (args: any) => CompiledAST;
|
|
309
|
+
updateOrCreate: (args: any) => CompiledAST;
|
|
310
|
+
};
|
|
311
|
+
build(): any;
|
|
279
312
|
/**
|
|
280
313
|
* Returns the current configuration of the QuerySet.
|
|
281
314
|
*
|
|
@@ -297,5 +330,38 @@ export class QuerySet<T> {
|
|
|
297
330
|
*/
|
|
298
331
|
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
299
332
|
}
|
|
333
|
+
/**
|
|
334
|
+
* A compiled AST that can be serialized and later executed via Model.execute().
|
|
335
|
+
*/
|
|
336
|
+
export type CompiledAST = {
|
|
337
|
+
/**
|
|
338
|
+
* - The operation type (e.g. 'list', 'get', 'create').
|
|
339
|
+
*/
|
|
340
|
+
op: string;
|
|
341
|
+
/**
|
|
342
|
+
* - Operation-specific arguments.
|
|
343
|
+
*/
|
|
344
|
+
args: Object;
|
|
345
|
+
/**
|
|
346
|
+
* - The filter AST node.
|
|
347
|
+
*/
|
|
348
|
+
filter: Object | null;
|
|
349
|
+
/**
|
|
350
|
+
* - The search configuration.
|
|
351
|
+
*/
|
|
352
|
+
search: Object | null;
|
|
353
|
+
/**
|
|
354
|
+
* - Aggregation operations.
|
|
355
|
+
*/
|
|
356
|
+
aggregations: any[];
|
|
357
|
+
/**
|
|
358
|
+
* - Ordering fields.
|
|
359
|
+
*/
|
|
360
|
+
orderBy?: string[] | undefined;
|
|
361
|
+
/**
|
|
362
|
+
* - Serializer options.
|
|
363
|
+
*/
|
|
364
|
+
serializerOptions: Object;
|
|
365
|
+
};
|
|
300
366
|
import { ModelSerializer } from "./serializers.js";
|
|
301
367
|
import { Model } from "./model.js";
|
|
@@ -7,6 +7,18 @@ import { v7 } from "uuid";
|
|
|
7
7
|
import hash from "object-hash";
|
|
8
8
|
import rfdc from "rfdc";
|
|
9
9
|
const clone = rfdc();
|
|
10
|
+
/**
|
|
11
|
+
* A compiled AST that can be serialized and later executed via Model.execute().
|
|
12
|
+
*
|
|
13
|
+
* @typedef {Object} CompiledAST
|
|
14
|
+
* @property {string} op - The operation type (e.g. 'list', 'get', 'create').
|
|
15
|
+
* @property {Object} args - Operation-specific arguments.
|
|
16
|
+
* @property {Object|null} filter - The filter AST node.
|
|
17
|
+
* @property {Object|null} search - The search configuration.
|
|
18
|
+
* @property {Array} aggregations - Aggregation operations.
|
|
19
|
+
* @property {Array<string>} [orderBy] - Ordering fields.
|
|
20
|
+
* @property {Object} serializerOptions - Serializer options.
|
|
21
|
+
*/
|
|
10
22
|
/**
|
|
11
23
|
* A QuerySet provides a fluent API for constructing and executing queries.
|
|
12
24
|
*
|
|
@@ -649,9 +661,36 @@ export class QuerySet {
|
|
|
649
661
|
/**
|
|
650
662
|
* Builds the final query object to be sent to the backend (simple jsonable object format).
|
|
651
663
|
*
|
|
652
|
-
* @
|
|
664
|
+
* @param {string} op - The operation type.
|
|
665
|
+
* @param {Object} [args={}] - Operation-specific arguments.
|
|
666
|
+
* @returns {CompiledAST} The compiled AST.
|
|
653
667
|
*/
|
|
668
|
+
_compile(op, args = {}) {
|
|
669
|
+
return { op, args, ...this.build() };
|
|
670
|
+
}
|
|
671
|
+
get compile() {
|
|
672
|
+
return {
|
|
673
|
+
fetch: (args) => this._compile('list', args),
|
|
674
|
+
get: (args) => this._compile('get', args),
|
|
675
|
+
first: (args) => this._compile('first', args),
|
|
676
|
+
last: (args) => this._compile('last', args),
|
|
677
|
+
count: (args) => this._compile('count', args),
|
|
678
|
+
sum: (args) => this._compile('sum', args),
|
|
679
|
+
avg: (args) => this._compile('avg', args),
|
|
680
|
+
min: (args) => this._compile('min', args),
|
|
681
|
+
max: (args) => this._compile('max', args),
|
|
682
|
+
exists: (args) => this._compile('exists', args),
|
|
683
|
+
create: (args) => this._compile('create', args),
|
|
684
|
+
bulkCreate: (args) => this._compile('bulk_create', args),
|
|
685
|
+
update: (args) => this._compile('update', args),
|
|
686
|
+
delete: (args) => this._compile('delete', args),
|
|
687
|
+
getOrCreate: (args) => this._compile('get_or_create', args),
|
|
688
|
+
updateOrCreate: (args) => this._compile('update_or_create', args),
|
|
689
|
+
};
|
|
690
|
+
}
|
|
654
691
|
build() {
|
|
692
|
+
if (this._prebuiltAST)
|
|
693
|
+
return clone(this._prebuiltAST);
|
|
655
694
|
let searchData = null;
|
|
656
695
|
const nonSearchNodes = [];
|
|
657
696
|
for (const node of this.nodes) {
|
|
@@ -5,33 +5,33 @@
|
|
|
5
5
|
"plural_title": "Authors",
|
|
6
6
|
"primary_key_field": "id",
|
|
7
7
|
"filterable_fields": [
|
|
8
|
-
"metadata",
|
|
9
|
-
"rating",
|
|
10
|
-
"name",
|
|
11
|
-
"created_at",
|
|
12
8
|
"salary",
|
|
13
|
-
"
|
|
9
|
+
"is_active",
|
|
14
10
|
"slug",
|
|
15
|
-
"
|
|
16
|
-
"
|
|
11
|
+
"name",
|
|
12
|
+
"rating",
|
|
17
13
|
"uuid",
|
|
14
|
+
"bio",
|
|
15
|
+
"birth_date",
|
|
16
|
+
"email",
|
|
18
17
|
"age",
|
|
18
|
+
"created_at",
|
|
19
19
|
"id",
|
|
20
|
-
"
|
|
21
|
-
"
|
|
20
|
+
"website",
|
|
21
|
+
"metadata"
|
|
22
22
|
],
|
|
23
23
|
"searchable_fields": [
|
|
24
24
|
"bio",
|
|
25
|
-
"
|
|
26
|
-
"
|
|
25
|
+
"email",
|
|
26
|
+
"name"
|
|
27
27
|
],
|
|
28
28
|
"ordering_fields": [
|
|
29
|
-
"rating",
|
|
30
|
-
"name",
|
|
31
|
-
"created_at",
|
|
32
29
|
"salary",
|
|
30
|
+
"name",
|
|
31
|
+
"rating",
|
|
32
|
+
"birth_date",
|
|
33
33
|
"age",
|
|
34
|
-
"
|
|
34
|
+
"created_at"
|
|
35
35
|
],
|
|
36
36
|
"properties": {
|
|
37
37
|
"id": {
|
|
@@ -235,7 +235,7 @@
|
|
|
235
235
|
"format": null,
|
|
236
236
|
"max_length": 32,
|
|
237
237
|
"choices": null,
|
|
238
|
-
"default": "
|
|
238
|
+
"default": "79fc79e3-5653-4c96-8419-a5a18616bc2e",
|
|
239
239
|
"validators": [],
|
|
240
240
|
"max_digits": null,
|
|
241
241
|
"decimal_places": null,
|
|
@@ -5,31 +5,31 @@
|
|
|
5
5
|
"plural_title": "Books",
|
|
6
6
|
"primary_key_field": "id",
|
|
7
7
|
"filterable_fields": [
|
|
8
|
-
"weight",
|
|
9
8
|
"last_updated",
|
|
10
|
-
"
|
|
9
|
+
"description",
|
|
10
|
+
"publish_date",
|
|
11
11
|
"pages",
|
|
12
|
-
"author",
|
|
13
|
-
"price",
|
|
14
12
|
"title",
|
|
15
13
|
"isbn",
|
|
16
|
-
"
|
|
14
|
+
"price",
|
|
17
15
|
"id",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
16
|
+
"weight",
|
|
17
|
+
"author",
|
|
18
|
+
"metadata",
|
|
19
|
+
"is_published"
|
|
20
20
|
],
|
|
21
21
|
"searchable_fields": [
|
|
22
|
-
"isbn",
|
|
23
22
|
"title",
|
|
23
|
+
"isbn",
|
|
24
24
|
"description"
|
|
25
25
|
],
|
|
26
26
|
"ordering_fields": [
|
|
27
|
-
"weight",
|
|
28
27
|
"last_updated",
|
|
28
|
+
"publish_date",
|
|
29
29
|
"pages",
|
|
30
|
-
"price",
|
|
31
30
|
"title",
|
|
32
|
-
"
|
|
31
|
+
"price",
|
|
32
|
+
"weight"
|
|
33
33
|
],
|
|
34
34
|
"properties": {
|
|
35
35
|
"id": {
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
"plural_title": "Comprehensive Models",
|
|
6
6
|
"primary_key_field": "id",
|
|
7
7
|
"filterable_fields": [
|
|
8
|
-
"
|
|
9
|
-
"
|
|
8
|
+
"char_field",
|
|
9
|
+
"int_field"
|
|
10
10
|
],
|
|
11
11
|
"searchable_fields": [
|
|
12
12
|
"char_field",
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
"format": "date-time",
|
|
106
106
|
"max_length": null,
|
|
107
107
|
"choices": null,
|
|
108
|
-
"default": "2026-02-
|
|
108
|
+
"default": "2026-02-28T23:13:32.583653+00:00",
|
|
109
109
|
"validators": [],
|
|
110
110
|
"max_digits": null,
|
|
111
111
|
"decimal_places": null,
|
|
@@ -5,16 +5,16 @@
|
|
|
5
5
|
"plural_title": "Daily Rates",
|
|
6
6
|
"primary_key_field": "id",
|
|
7
7
|
"filterable_fields": [
|
|
8
|
-
"min_stay_arrival",
|
|
9
|
-
"price",
|
|
10
|
-
"rate_plan",
|
|
11
|
-
"min_stay_through",
|
|
12
|
-
"stop_sell",
|
|
13
8
|
"closed_to_arrival",
|
|
14
|
-
"
|
|
9
|
+
"min_stay_through",
|
|
10
|
+
"min_stay_arrival",
|
|
11
|
+
"closed_to_departure",
|
|
15
12
|
"date",
|
|
13
|
+
"max_stay",
|
|
14
|
+
"price",
|
|
16
15
|
"id",
|
|
17
|
-
"
|
|
16
|
+
"stop_sell",
|
|
17
|
+
"rate_plan"
|
|
18
18
|
],
|
|
19
19
|
"searchable_fields": [],
|
|
20
20
|
"ordering_fields": [
|
|
@@ -5,18 +5,18 @@
|
|
|
5
5
|
"plural_title": "Error Test Compound Uniques",
|
|
6
6
|
"primary_key_field": "id",
|
|
7
7
|
"filterable_fields": [
|
|
8
|
+
"rank",
|
|
8
9
|
"label",
|
|
9
10
|
"id",
|
|
10
|
-
"group"
|
|
11
|
-
"rank"
|
|
11
|
+
"group"
|
|
12
12
|
],
|
|
13
13
|
"searchable_fields": [
|
|
14
14
|
"label",
|
|
15
15
|
"group"
|
|
16
16
|
],
|
|
17
17
|
"ordering_fields": [
|
|
18
|
-
"
|
|
19
|
-
"
|
|
18
|
+
"rank",
|
|
19
|
+
"group"
|
|
20
20
|
],
|
|
21
21
|
"properties": {
|
|
22
22
|
"id": {
|