@statezero/core 0.2.60 → 0.2.61

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.
@@ -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
  *
@@ -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
@@ -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
  *
@@ -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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statezero/core",
3
- "version": "0.2.60",
3
+ "version": "0.2.61",
4
4
  "type": "module",
5
5
  "module": "ESNext",
6
6
  "description": "The type-safe frontend client for StateZero - connect directly to your backend models with zero boilerplate",