@coasys/ad4m 0.12.0-rc1-dev.4 → 0.12.0-rc2

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.
Files changed (166) hide show
  1. package/lib/index.cjs +5052 -4446
  2. package/lib/index.js +5019 -4442
  3. package/lib/src/agent/AgentClient.d.ts +4 -0
  4. package/lib/src/agent/AgentClient.js +34 -0
  5. package/lib/src/index.d.ts +2 -3
  6. package/lib/src/index.js +2 -3
  7. package/lib/src/model/Ad4mModel.d.ts +8 -782
  8. package/lib/src/model/Ad4mModel.js +160 -2354
  9. package/lib/src/model/ModelQueryBuilder.d.ts +370 -0
  10. package/lib/src/model/ModelQueryBuilder.js +556 -0
  11. package/lib/src/model/decorators.d.ts +71 -23
  12. package/lib/src/model/decorators.js +133 -384
  13. package/lib/src/model/hydration.d.ts +102 -0
  14. package/lib/src/model/hydration.js +709 -0
  15. package/lib/src/model/index.d.ts +20 -0
  16. package/lib/src/model/index.js +20 -0
  17. package/lib/src/model/{schema/fromJSONSchema.d.ts → json-schema.d.ts} +45 -12
  18. package/lib/src/model/json-schema.js +326 -0
  19. package/lib/src/model/prolog-facts.d.ts +37 -0
  20. package/lib/src/model/{prolog/generatePrologFacts.js → prolog-facts.js} +47 -52
  21. package/lib/src/model/query-common.d.ts +14 -0
  22. package/lib/src/model/query-common.js +36 -0
  23. package/lib/src/model/query-prolog.d.ts +15 -0
  24. package/lib/src/model/query-prolog.js +140 -0
  25. package/lib/src/model/query-surreal.d.ts +44 -0
  26. package/lib/src/model/query-surreal.js +249 -0
  27. package/lib/src/model/relation-filtering.test.js +838 -0
  28. package/lib/src/model/sdna.d.ts +14 -0
  29. package/lib/src/model/sdna.js +141 -0
  30. package/lib/src/model/shacl-gen.d.ts +31 -0
  31. package/lib/src/model/shacl-gen.js +246 -0
  32. package/lib/src/model/surreal-utils.d.ts +42 -0
  33. package/lib/src/model/surreal-utils.js +128 -0
  34. package/lib/src/model/types.d.ts +75 -96
  35. package/lib/src/model/types.js +4 -4
  36. package/lib/src/model/util.d.ts +4 -5
  37. package/lib/src/model/util.js +12 -32
  38. package/lib/src/perspectives/PerspectiveClient.d.ts +1 -1
  39. package/lib/src/perspectives/PerspectiveProxy.d.ts +1 -1
  40. package/lib/src/perspectives/WakerSubscriptionManager.d.ts +79 -0
  41. package/lib/src/perspectives/WakerSubscriptionManager.js +196 -0
  42. package/lib/src/runtime/RuntimeResolver.d.ts +14 -0
  43. package/lib/src/runtime/RuntimeResolver.js +73 -0
  44. package/lib/src/schema.gql +14 -0
  45. package/lib/src/shacl/SHACLShape.d.ts +23 -0
  46. package/lib/src/shacl/SHACLShape.js +45 -0
  47. package/lib/src/typeDefs.js +14 -0
  48. package/package.json +13 -8
  49. package/src/agent/AgentClient.ts +45 -0
  50. package/src/index.ts +2 -3
  51. package/src/model/Ad4mModel.ts +1089 -3686
  52. package/src/model/ModelQueryBuilder.ts +617 -0
  53. package/src/model/Subject.ts +1 -1
  54. package/src/model/decorators.ts +218 -453
  55. package/src/model/hydration.ts +796 -0
  56. package/src/model/index.ts +21 -0
  57. package/src/model/json-schema.ts +424 -0
  58. package/src/model/prolog-facts.ts +145 -0
  59. package/src/model/query-common.ts +48 -0
  60. package/src/model/query-prolog.ts +148 -0
  61. package/src/model/query-surreal.ts +280 -0
  62. package/src/model/relation-filtering.test.ts +803 -0
  63. package/src/model/sdna.ts +170 -0
  64. package/src/model/shacl-gen.ts +292 -0
  65. package/src/model/surreal-utils.ts +147 -0
  66. package/src/model/types.ts +182 -0
  67. package/src/model/util.ts +13 -36
  68. package/src/perspectives/PerspectiveClient.ts +1 -1
  69. package/src/perspectives/PerspectiveProxy.ts +1 -1
  70. package/src/perspectives/WakerSubscriptionManager.ts +292 -0
  71. package/src/runtime/RuntimeResolver.ts +53 -0
  72. package/src/shacl/SHACLShape.ts +83 -0
  73. package/lib/src/Ad4mClient.test.js +0 -1204
  74. package/lib/src/Literal.test.d.ts +0 -1
  75. package/lib/src/Literal.test.js +0 -41
  76. package/lib/src/model/mutation.d.ts +0 -81
  77. package/lib/src/model/mutation.js +0 -317
  78. package/lib/src/model/parentUtils.d.ts +0 -32
  79. package/lib/src/model/parentUtils.js +0 -64
  80. package/lib/src/model/prolog/generatePrologFacts.d.ts +0 -36
  81. package/lib/src/model/prolog/index.d.ts +0 -1
  82. package/lib/src/model/prolog/index.js +0 -1
  83. package/lib/src/model/query/ModelQueryBuilder.d.ts +0 -82
  84. package/lib/src/model/query/ModelQueryBuilder.js +0 -115
  85. package/lib/src/model/query/QueryBuilder.d.ts +0 -101
  86. package/lib/src/model/query/QueryBuilder.js +0 -193
  87. package/lib/src/model/query/SurrealQueryBuilder.d.ts +0 -48
  88. package/lib/src/model/query/SurrealQueryBuilder.js +0 -371
  89. package/lib/src/model/query/fetchInstance.d.ts +0 -24
  90. package/lib/src/model/query/fetchInstance.js +0 -144
  91. package/lib/src/model/query/hydration.d.ts +0 -54
  92. package/lib/src/model/query/hydration.js +0 -214
  93. package/lib/src/model/query/operations.d.ts +0 -59
  94. package/lib/src/model/query/operations.js +0 -384
  95. package/lib/src/model/query/snapshot.d.ts +0 -59
  96. package/lib/src/model/query/snapshot.js +0 -106
  97. package/lib/src/model/query/surrealCompiler.d.ts +0 -42
  98. package/lib/src/model/query/surrealCompiler.js +0 -304
  99. package/lib/src/model/schema/fromJSONSchema.js +0 -264
  100. package/lib/src/model/schema/metadata.d.ts +0 -15
  101. package/lib/src/model/schema/metadata.js +0 -112
  102. package/lib/src/model/subscription.d.ts +0 -47
  103. package/lib/src/model/subscription.js +0 -231
  104. package/lib/src/model/transaction.d.ts +0 -27
  105. package/lib/src/model/transaction.js +0 -32
  106. package/lib/src/shims/reflect-metadata.d.ts +0 -0
  107. package/lib/src/shims/type-graphql.d.ts +0 -32
  108. package/lib/src/src/Ad4mClient.d.ts +0 -28
  109. package/lib/src/src/Address.d.ts +0 -1
  110. package/lib/src/src/DID.d.ts +0 -1
  111. package/lib/src/src/Exception.d.ts +0 -7
  112. package/lib/src/src/Literal.d.ts +0 -7
  113. package/lib/src/src/PubSub.d.ts +0 -17
  114. package/lib/src/src/SmartLiteral.d.ts +0 -12
  115. package/lib/src/src/agent/Agent.d.ts +0 -110
  116. package/lib/src/src/agent/AgentClient.d.ts +0 -62
  117. package/lib/src/src/agent/AgentResolver.d.ts +0 -30
  118. package/lib/src/src/agent/AgentStatus.d.ts +0 -8
  119. package/lib/src/src/ai/AIClient.d.ts +0 -32
  120. package/lib/src/src/ai/AIResolver.d.ts +0 -75
  121. package/lib/src/src/ai/Tasks.d.ts +0 -37
  122. package/lib/src/src/buildSchema.d.ts +0 -1
  123. package/lib/src/src/expression/Expression.d.ts +0 -28
  124. package/lib/src/src/expression/ExpressionClient.d.ts +0 -13
  125. package/lib/src/src/expression/ExpressionRef.d.ts +0 -9
  126. package/lib/src/src/expression/ExpressionResolver.d.ts +0 -10
  127. package/lib/src/src/index.d.ts +0 -35
  128. package/lib/src/src/jestSetup.d.ts +0 -1
  129. package/lib/src/src/language/Icon.d.ts +0 -4
  130. package/lib/src/src/language/Language.d.ts +0 -206
  131. package/lib/src/src/language/LanguageClient.d.ts +0 -17
  132. package/lib/src/src/language/LanguageContext.d.ts +0 -37
  133. package/lib/src/src/language/LanguageHandle.d.ts +0 -9
  134. package/lib/src/src/language/LanguageMeta.d.ts +0 -35
  135. package/lib/src/src/language/LanguageRef.d.ts +0 -6
  136. package/lib/src/src/language/LanguageResolver.d.ts +0 -19
  137. package/lib/src/src/links/Links.d.ts +0 -39
  138. package/lib/src/src/links/Links.test.d.ts +0 -1
  139. package/lib/src/src/model/Ad4mModel.d.ts +0 -1438
  140. package/lib/src/src/model/Ad4mModel.test.d.ts +0 -1
  141. package/lib/src/src/model/Subject.d.ts +0 -25
  142. package/lib/src/src/model/decorators.d.ts +0 -545
  143. package/lib/src/src/model/util.d.ts +0 -12
  144. package/lib/src/src/neighbourhood/Neighbourhood.d.ts +0 -10
  145. package/lib/src/src/neighbourhood/NeighbourhoodClient.d.ts +0 -25
  146. package/lib/src/src/neighbourhood/NeighbourhoodProxy.d.ts +0 -19
  147. package/lib/src/src/neighbourhood/NeighbourhoodProxy.test.d.ts +0 -1
  148. package/lib/src/src/neighbourhood/NeighbourhoodResolver.d.ts +0 -24
  149. package/lib/src/src/perspectives/LinkQuery.d.ts +0 -11
  150. package/lib/src/src/perspectives/Perspective.d.ts +0 -38
  151. package/lib/src/src/perspectives/Perspective.test.d.ts +0 -1
  152. package/lib/src/src/perspectives/PerspectiveClient.d.ts +0 -97
  153. package/lib/src/src/perspectives/PerspectiveDiff.d.ts +0 -9
  154. package/lib/src/src/perspectives/PerspectiveHandle.d.ts +0 -18
  155. package/lib/src/src/perspectives/PerspectiveProxy.d.ts +0 -865
  156. package/lib/src/src/perspectives/PerspectiveResolver.d.ts +0 -57
  157. package/lib/src/src/runtime/RuntimeClient.d.ts +0 -56
  158. package/lib/src/src/runtime/RuntimeResolver.d.ts +0 -132
  159. package/lib/src/src/shacl/SHACLFlow.d.ts +0 -171
  160. package/lib/src/src/shacl/SHACLFlow.test.d.ts +0 -1
  161. package/lib/src/src/shacl/SHACLShape.d.ts +0 -117
  162. package/lib/src/src/shacl/SHACLShape.test.d.ts +0 -1
  163. package/lib/src/src/typeDefs.d.ts +0 -1
  164. package/lib/src/src/unwrapApolloResult.d.ts +0 -2
  165. package/lib/src/src/utils.d.ts +0 -25
  166. /package/lib/src/{Ad4mClient.test.d.ts → model/relation-filtering.test.d.ts} +0 -0
@@ -1,115 +0,0 @@
1
- /**
2
- * Fluent query builder for Ad4mModel.
3
- *
4
- * Extracted from Ad4mModel.ts. The class holds a `Query` object and delegates
5
- * all execution to `Ad4mModel` static methods via the `ctor` constructor
6
- * reference, so there is no circular import (this module imports from the
7
- * Ad4mModel module, but Ad4mModel does not import from here — it re-exports
8
- * ModelQueryBuilder from its own file for backward compatibility).
9
- */
10
- import { createSubscription } from "../subscription";
11
- /**
12
- * Fluent builder for Ad4mModel queries.
13
- *
14
- * Create via `MyModel.query(perspective)`:
15
- * ```typescript
16
- * const posts = await Post.query(perspective)
17
- * .where({ published: true })
18
- * .order({ createdAt: "DESC" })
19
- * .limit(10)
20
- * .get();
21
- * ```
22
- */
23
- export class ModelQueryBuilder {
24
- constructor(perspective, ctor, query) {
25
- this.queryParams = {};
26
- this.modelClassName = null;
27
- this.perspective = perspective;
28
- this.ctor = ctor;
29
- if (query)
30
- this.queryParams = query;
31
- }
32
- where(conditions) {
33
- this.queryParams.where = conditions;
34
- return this;
35
- }
36
- order(orderBy) {
37
- this.queryParams.order = orderBy;
38
- return this;
39
- }
40
- limit(limit) {
41
- this.queryParams.limit = limit;
42
- return this;
43
- }
44
- offset(offset) {
45
- this.queryParams.offset = offset;
46
- return this;
47
- }
48
- properties(properties) {
49
- this.queryParams.properties = properties;
50
- return this;
51
- }
52
- /**
53
- * Eagerly load specific relations as full model instances.
54
- *
55
- * Key = relation field name on the model.
56
- * Value = `true` (all instances) or a `Query` to filter/order/limit the nested set.
57
- *
58
- * @example
59
- * ```typescript
60
- * Recipe.query(perspective)
61
- * .include({
62
- * comments: true,
63
- * tags: { where: { active: true }, limit: 5 },
64
- * })
65
- * .get();
66
- * ```
67
- */
68
- include(map) {
69
- this.queryParams.include = map;
70
- return this;
71
- }
72
- overrideModelClassName(className) {
73
- this.modelClassName = className;
74
- return this;
75
- }
76
- /** Executes the query and returns all matching instances. */
77
- async get() {
78
- return this.ctor.findAll(this.perspective, this.queryParams);
79
- }
80
- /** Returns the first matching instance, or `null` if none found. */
81
- async first() {
82
- return this.ctor.findOne(this.perspective, this.queryParams);
83
- }
84
- /** Returns the total count of matching entities. */
85
- async count() {
86
- return this.ctor.count(this.perspective, this.queryParams);
87
- }
88
- /** Returns a single page of results with pagination metadata. */
89
- async paginate(pageSize, pageNumber) {
90
- return this.ctor.paginate(this.perspective, pageSize, pageNumber, this.queryParams);
91
- }
92
- /**
93
- * Terminal: creates a live subscription using the query parameters accumulated
94
- * so far. Fires `callback` immediately with current results, then on every
95
- * relevant link change.
96
- *
97
- * Pass additional delivery options (`debounce`, `onError`) in `deliveryOpts`.
98
- * Call `sub.unsubscribe()` to detach.
99
- *
100
- * @example
101
- * ```typescript
102
- * const sub = Post.query(perspective)
103
- * .where({ published: true })
104
- * .order({ createdAt: "DESC" })
105
- * .live((posts) => setPosts(posts), { debounce: 300 });
106
- *
107
- * // cleanup:
108
- * sub.unsubscribe();
109
- * ```
110
- */
111
- live(callback, deliveryOpts) {
112
- const options = { ...this.queryParams, ...deliveryOpts };
113
- return createSubscription((p, q) => this.ctor.findAll(p, q ?? {}), () => this.ctor.getModelMetadata(), this.perspective, options, callback, this.ctor);
114
- }
115
- }
@@ -1,101 +0,0 @@
1
- /**
2
- * Fluent query builder for Ad4mModel.
3
- *
4
- * Extracted from Ad4mModel.ts. The class holds a `Query` object and delegates
5
- * all execution to `Ad4mModel` static methods via the `ctor` constructor
6
- * reference, so there is no circular import (this module imports from the
7
- * Ad4mModel module, but Ad4mModel does not import from here — it re-exports
8
- * ModelQueryBuilder from its own file for backward compatibility).
9
- */
10
- import { PerspectiveProxy } from "../../perspectives/PerspectiveProxy";
11
- import { Order, PaginationResult, Query, Where, IncludeMap, SubscribeOptions, Subscription } from "../types";
12
- export type Ad4mModelCtor<T> = typeof import("../Ad4mModel").Ad4mModel & (new (...args: any[]) => T);
13
- /**
14
- * Fluent builder for Ad4mModel queries.
15
- *
16
- * Create via `MyModel.query(perspective)`:
17
- * ```typescript
18
- * const posts = await Post.query(perspective)
19
- * .where({ published: true })
20
- * .order({ createdAt: "DESC" })
21
- * .limit(10)
22
- * .get();
23
- * ```
24
- */
25
- export declare class ModelQueryBuilder<T extends import("../Ad4mModel").Ad4mModel> {
26
- private perspective;
27
- private queryParams;
28
- private modelClassName;
29
- private ctor;
30
- private currentSubscription?;
31
- constructor(perspective: PerspectiveProxy, ctor: Ad4mModelCtor<T>, query?: Query);
32
- /**
33
- * Disposes of the current live subscription (if any).
34
- * Call when done to avoid memory leaks.
35
- */
36
- dispose(): void;
37
- where(conditions: Where): ModelQueryBuilder<T>;
38
- order(orderBy: Order): ModelQueryBuilder<T>;
39
- limit(limit: number): ModelQueryBuilder<T>;
40
- offset(offset: number): ModelQueryBuilder<T>;
41
- properties(properties: string[]): ModelQueryBuilder<T>;
42
- /**
43
- * Eagerly load specific relations as full model instances.
44
- *
45
- * Key = relation field name on the model.
46
- * Value = `true` (all instances) or a `Query` to filter/order/limit the nested set.
47
- *
48
- * @example
49
- * ```typescript
50
- * Recipe.query(perspective)
51
- * .include({
52
- * comments: true,
53
- * tags: { where: { active: true }, limit: 5 },
54
- * })
55
- * .get();
56
- * ```
57
- */
58
- include(map: IncludeMap): ModelQueryBuilder<T>;
59
- overrideModelClassName(className: string): ModelQueryBuilder<T>;
60
- /**
61
- * Executes the query once and returns the results.
62
- */
63
- get(): Promise<T[]>;
64
- /**
65
- * Subscribes to live updates and returns initial results.
66
- * Call `dispose()` when done.
67
- */
68
- subscribe(callback: (results: T[]) => void): Promise<T[]>;
69
- /** Returns the total count of matching entities. */
70
- count(): Promise<number>;
71
- /**
72
- * Subscribes to count updates. Call `dispose()` when done.
73
- */
74
- countSubscribe(callback: (count: number) => void): Promise<number>;
75
- /** Returns a single page of results with pagination metadata. */
76
- paginate(pageSize: number, pageNumber: number): Promise<PaginationResult<T>>;
77
- /**
78
- * Subscribes to paginated live updates. Call `dispose()` when done.
79
- */
80
- paginateSubscribe(pageSize: number, pageNumber: number, callback: (results: PaginationResult<T>) => void): Promise<PaginationResult<T>>;
81
- /**
82
- * Terminal: creates a live subscription using the query parameters accumulated
83
- * so far. Fires `callback` immediately with current results, then on every
84
- * relevant link change.
85
- *
86
- * Pass additional delivery options (`debounce`, `onError`) in `deliveryOpts`.
87
- * Call `sub.unsubscribe()` to detach.
88
- *
89
- * @example
90
- * ```typescript
91
- * const sub = Post.query(perspective)
92
- * .where({ published: true })
93
- * .order({ createdAt: "DESC" })
94
- * .live((posts) => setPosts(posts), { debounce: 300 });
95
- *
96
- * // cleanup:
97
- * sub.unsubscribe();
98
- * ```
99
- */
100
- live(callback: (results: T[]) => void, deliveryOpts?: Pick<SubscribeOptions, "debounce" | "onError">): Subscription;
101
- }
@@ -1,193 +0,0 @@
1
- /**
2
- * Fluent query builder for Ad4mModel.
3
- *
4
- * Extracted from Ad4mModel.ts. The class holds a `Query` object and delegates
5
- * all execution to `Ad4mModel` static methods via the `ctor` constructor
6
- * reference, so there is no circular import (this module imports from the
7
- * Ad4mModel module, but Ad4mModel does not import from here — it re-exports
8
- * ModelQueryBuilder from its own file for backward compatibility).
9
- */
10
- import { createSubscription } from "../subscription";
11
- /**
12
- * Fluent builder for Ad4mModel queries.
13
- *
14
- * Create via `MyModel.query(perspective)`:
15
- * ```typescript
16
- * const posts = await Post.query(perspective)
17
- * .where({ published: true })
18
- * .order({ createdAt: "DESC" })
19
- * .limit(10)
20
- * .get();
21
- * ```
22
- */
23
- export class ModelQueryBuilder {
24
- constructor(perspective, ctor, query) {
25
- this.queryParams = {};
26
- this.modelClassName = null;
27
- this.perspective = perspective;
28
- this.ctor = ctor;
29
- if (query)
30
- this.queryParams = query;
31
- }
32
- /**
33
- * Disposes of the current live subscription (if any).
34
- * Call when done to avoid memory leaks.
35
- */
36
- dispose() {
37
- if (this.currentSubscription) {
38
- this.currentSubscription.dispose();
39
- this.currentSubscription = undefined;
40
- }
41
- }
42
- where(conditions) {
43
- this.queryParams.where = conditions;
44
- return this;
45
- }
46
- order(orderBy) {
47
- this.queryParams.order = orderBy;
48
- return this;
49
- }
50
- limit(limit) {
51
- this.queryParams.limit = limit;
52
- return this;
53
- }
54
- offset(offset) {
55
- this.queryParams.offset = offset;
56
- return this;
57
- }
58
- properties(properties) {
59
- this.queryParams.properties = properties;
60
- return this;
61
- }
62
- /**
63
- * Eagerly load specific relations as full model instances.
64
- *
65
- * Key = relation field name on the model.
66
- * Value = `true` (all instances) or a `Query` to filter/order/limit the nested set.
67
- *
68
- * @example
69
- * ```typescript
70
- * Recipe.query(perspective)
71
- * .include({
72
- * comments: true,
73
- * tags: { where: { active: true }, limit: 5 },
74
- * })
75
- * .get();
76
- * ```
77
- */
78
- include(map) {
79
- this.queryParams.include = map;
80
- return this;
81
- }
82
- overrideModelClassName(className) {
83
- this.modelClassName = className;
84
- return this;
85
- }
86
- /**
87
- * Executes the query once and returns the results.
88
- */
89
- async get() {
90
- const surrealQuery = await this.ctor.queryToSurrealQL(this.perspective, this.queryParams);
91
- const result = await this.perspective.querySurrealDB(surrealQuery);
92
- const { results } = await this.ctor.instancesFromSurrealResult(this.perspective, this.queryParams, result);
93
- return results;
94
- }
95
- /**
96
- * Subscribes to live updates and returns initial results.
97
- * Call `dispose()` when done.
98
- */
99
- async subscribe(callback) {
100
- this.dispose();
101
- const surrealQuery = await this.ctor.queryToSurrealQL(this.perspective, this.queryParams);
102
- this.currentSubscription =
103
- await this.perspective.subscribeSurrealDB(surrealQuery);
104
- const processResults = async (result) => {
105
- const { results } = await this.ctor.instancesFromSurrealResult(this.perspective, this.queryParams, result);
106
- callback(results);
107
- };
108
- this.currentSubscription.onResult(processResults);
109
- const { results } = await this.ctor.instancesFromSurrealResult(this.perspective, this.queryParams, this.currentSubscription.result);
110
- return results;
111
- }
112
- /** Returns the total count of matching entities. */
113
- async count() {
114
- const surrealQuery = await this.ctor.queryToSurrealQL(this.perspective, this.queryParams);
115
- const result = await this.perspective.querySurrealDB(surrealQuery);
116
- const { totalCount } = await this.ctor.instancesFromSurrealResult(this.perspective, this.queryParams, result);
117
- return totalCount;
118
- }
119
- /**
120
- * Subscribes to count updates. Call `dispose()` when done.
121
- */
122
- async countSubscribe(callback) {
123
- this.dispose();
124
- const surrealQuery = await this.ctor.queryToSurrealQL(this.perspective, this.queryParams);
125
- this.currentSubscription =
126
- await this.perspective.subscribeSurrealDB(surrealQuery);
127
- const processResults = async (result) => {
128
- const { totalCount } = await this.ctor.instancesFromSurrealResult(this.perspective, this.queryParams, result);
129
- callback(totalCount);
130
- };
131
- this.currentSubscription.onResult(processResults);
132
- const { totalCount } = await this.ctor.instancesFromSurrealResult(this.perspective, this.queryParams, this.currentSubscription.result);
133
- return totalCount;
134
- }
135
- /** Returns a single page of results with pagination metadata. */
136
- async paginate(pageSize, pageNumber) {
137
- const paginationQuery = {
138
- ...this.queryParams,
139
- limit: pageSize,
140
- offset: pageSize * (pageNumber - 1),
141
- count: true,
142
- };
143
- const surrealQuery = await this.ctor.queryToSurrealQL(this.perspective, paginationQuery);
144
- const result = await this.perspective.querySurrealDB(surrealQuery);
145
- const { results, totalCount } = (await this.ctor.instancesFromSurrealResult(this.perspective, paginationQuery, result));
146
- return { results, totalCount, pageSize, pageNumber };
147
- }
148
- /**
149
- * Subscribes to paginated live updates. Call `dispose()` when done.
150
- */
151
- async paginateSubscribe(pageSize, pageNumber, callback) {
152
- this.dispose();
153
- const paginationQuery = {
154
- ...this.queryParams,
155
- limit: pageSize,
156
- offset: pageSize * (pageNumber - 1),
157
- count: true,
158
- };
159
- const surrealQuery = await this.ctor.queryToSurrealQL(this.perspective, paginationQuery);
160
- this.currentSubscription =
161
- await this.perspective.subscribeSurrealDB(surrealQuery);
162
- const processResults = async (result) => {
163
- const { results, totalCount } = (await this.ctor.instancesFromSurrealResult(this.perspective, paginationQuery, result));
164
- callback({ results, totalCount, pageSize, pageNumber });
165
- };
166
- this.currentSubscription.onResult(processResults);
167
- const { results, totalCount } = (await this.ctor.instancesFromSurrealResult(this.perspective, paginationQuery, this.currentSubscription.result));
168
- return { results, totalCount, pageSize, pageNumber };
169
- }
170
- /**
171
- * Terminal: creates a live subscription using the query parameters accumulated
172
- * so far. Fires `callback` immediately with current results, then on every
173
- * relevant link change.
174
- *
175
- * Pass additional delivery options (`debounce`, `onError`) in `deliveryOpts`.
176
- * Call `sub.unsubscribe()` to detach.
177
- *
178
- * @example
179
- * ```typescript
180
- * const sub = Post.query(perspective)
181
- * .where({ published: true })
182
- * .order({ createdAt: "DESC" })
183
- * .live((posts) => setPosts(posts), { debounce: 300 });
184
- *
185
- * // cleanup:
186
- * sub.unsubscribe();
187
- * ```
188
- */
189
- live(callback, deliveryOpts) {
190
- const options = { ...this.queryParams, ...deliveryOpts };
191
- return createSubscription((p, q) => this.ctor.findAll(p, q ?? {}), () => this.ctor.getModelMetadata(), this.perspective, options, callback);
192
- }
193
- }
@@ -1,48 +0,0 @@
1
- /**
2
- * Pure SurrealQL query-building functions for the AD4M model layer.
3
- *
4
- * All functions are stateless — they take `ModelMetadata` (and optionally a
5
- * `Query`) as plain data and return strings or booleans. No dependency on the
6
- * `Ad4mModel` class, which means they can be imported by tests and other
7
- * modules without pulling in the full class graph.
8
- *
9
- * `Ad4mModel` keeps thin static wrapper methods with the original signatures so
10
- * the public API is unchanged.
11
- */
12
- import { ModelMetadata, Query, Where, WhereCondition } from "../types";
13
- /**
14
- * Formats a value for use in SurrealQL queries.
15
- *
16
- * - Strings: wrapped in single quotes, special characters escaped
17
- * - Numbers / booleans: converted to string
18
- * - Arrays: recursively formatted, wrapped in `[...]`
19
- */
20
- export declare function formatSurrealValue(value: any): string;
21
- /**
22
- * Builds graph-traversal WHERE clause filters (`->link[WHERE ...]`).
23
- * Used by `buildSurrealQuery` — more efficient than subqueries because
24
- * SurrealDB can use graph indexes.
25
- */
26
- export declare function buildGraphTraversalWhereClause(metadata: ModelMetadata, where?: Where): string;
27
- /**
28
- * Builds a legacy subquery-based WHERE clause.
29
- * Kept for compatibility; prefer `buildGraphTraversalWhereClause`.
30
- */
31
- export declare function buildSurrealWhereClause(metadata: ModelMetadata, where?: Where): string;
32
- export declare function buildSurrealSelectFields(metadata: ModelMetadata, properties?: string[], relations?: string[]): string;
33
- export declare function buildSurrealSelectFieldsWithAggregation(metadata: ModelMetadata, properties?: string[], relations?: string[]): string;
34
- /**
35
- * Builds the SurrealQL SELECT query for a given model metadata + query params.
36
- * This is the extracted, pure-function form of `Ad4mModel.queryToSurrealQL`.
37
- */
38
- export declare function buildSurrealQuery(metadata: ModelMetadata, query: Query): string;
39
- /**
40
- * Builds a count query (same as `buildSurrealQuery` but without LIMIT/OFFSET).
41
- */
42
- export declare function buildSurrealCountQuery(metadata: ModelMetadata, query: Query): string;
43
- /**
44
- * Checks whether a single value satisfies a WhereCondition.
45
- * Used for post-query JavaScript filtering of operators that SurrealDB
46
- * cannot evaluate reliably (gt/gte/lt/lte/between/contains on literals).
47
- */
48
- export declare function matchesCondition(value: any, condition: WhereCondition): boolean;