@coasys/ad4m 0.10.1-rc9-dev → 0.10.1-release-candidate-2
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/lib/index.cjs +3179 -811
- package/lib/index.js +3171 -807
- package/lib/src/Literal.js +4 -1
- package/lib/src/ai/AIClient.d.ts +1 -1
- package/lib/src/ai/AIClient.js +6 -6
- package/lib/src/ai/AIResolver.d.ts +1 -1
- package/lib/src/ai/AIResolver.js +7 -4
- package/lib/src/index.d.ts +4 -3
- package/lib/src/index.js +4 -3
- package/lib/src/model/Ad4mModel.d.ts +609 -0
- package/lib/src/model/Ad4mModel.js +1048 -0
- package/lib/src/{subject → model}/Subject.d.ts +2 -2
- package/lib/src/{subject → model}/Subject.js +18 -18
- package/lib/src/model/decorators.d.ts +502 -0
- package/lib/src/model/decorators.js +683 -0
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +2 -2
- package/lib/src/neighbourhood/NeighbourhoodClient.js +16 -10
- package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +2 -2
- package/lib/src/neighbourhood/NeighbourhoodProxy.js +4 -4
- package/lib/src/neighbourhood/NeighbourhoodProxy.test.d.ts +1 -0
- package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +31 -0
- package/lib/src/neighbourhood/NeighbourhoodResolver.d.ts +2 -2
- package/lib/src/neighbourhood/NeighbourhoodResolver.js +6 -4
- package/lib/src/perspectives/PerspectiveClient.d.ts +18 -11
- package/lib/src/perspectives/PerspectiveClient.js +116 -49
- package/lib/src/perspectives/PerspectiveProxy.d.ts +471 -54
- package/lib/src/perspectives/PerspectiveProxy.js +579 -64
- package/lib/src/perspectives/PerspectiveResolver.d.ts +23 -9
- package/lib/src/perspectives/PerspectiveResolver.js +140 -46
- package/lib/src/runtime/RuntimeClient.d.ts +5 -1
- package/lib/src/runtime/RuntimeClient.js +48 -0
- package/lib/src/runtime/RuntimeResolver.d.ts +24 -0
- package/lib/src/runtime/RuntimeResolver.js +117 -0
- package/lib/src/schema.gql +25 -11
- package/lib/src/typeDefs.js +25 -11
- package/package.json +2 -1
- package/src/Literal.ts +4 -1
- package/src/ai/AIClient.ts +6 -6
- package/src/ai/AIResolver.ts +6 -3
- package/src/index.ts +4 -3
- package/src/model/Ad4mModel.ts +1206 -0
- package/src/{subject → model}/Subject.ts +16 -16
- package/src/{subject/SDNADecorators.ts → model/decorators.ts} +384 -50
- package/src/neighbourhood/NeighbourhoodClient.ts +16 -10
- package/src/neighbourhood/NeighbourhoodProxy.test.ts +45 -0
- package/src/neighbourhood/NeighbourhoodProxy.ts +4 -4
- package/src/neighbourhood/NeighbourhoodResolver.ts +2 -2
- package/src/perspectives/PerspectiveClient.ts +122 -51
- package/src/perspectives/PerspectiveProxy.ts +642 -77
- package/src/perspectives/PerspectiveResolver.ts +126 -23
- package/src/runtime/RuntimeClient.ts +52 -1
- package/src/runtime/RuntimeResolver.ts +77 -0
- package/lib/src/subject/SDNADecorators.d.ts +0 -188
- package/lib/src/subject/SDNADecorators.js +0 -360
- package/lib/src/subject/SubjectEntity.d.ts +0 -110
- package/lib/src/subject/SubjectEntity.js +0 -288
- package/src/subject/SubjectEntity.ts +0 -336
- package/yarn-error.log +0 -90
- /package/lib/src/{subject → model}/util.d.ts +0 -0
- /package/lib/src/{subject → model}/util.js +0 -0
- /package/src/{subject → model}/util.ts +0 -0
|
@@ -0,0 +1,609 @@
|
|
|
1
|
+
import { PerspectiveProxy } from "../perspectives/PerspectiveProxy";
|
|
2
|
+
type ValueTuple = [name: string, value: any, resolve?: boolean];
|
|
3
|
+
type WhereOps = {
|
|
4
|
+
not: string | number | boolean | string[] | number[];
|
|
5
|
+
between: [number, number];
|
|
6
|
+
lt: number;
|
|
7
|
+
lte: number;
|
|
8
|
+
gt: number;
|
|
9
|
+
gte: number;
|
|
10
|
+
};
|
|
11
|
+
type WhereCondition = string | number | boolean | string[] | number[] | {
|
|
12
|
+
[K in keyof WhereOps]?: WhereOps[K];
|
|
13
|
+
};
|
|
14
|
+
type Where = {
|
|
15
|
+
[propertyName: string]: WhereCondition;
|
|
16
|
+
};
|
|
17
|
+
type Order = {
|
|
18
|
+
[propertyName: string]: "ASC" | "DESC";
|
|
19
|
+
};
|
|
20
|
+
export type Query = {
|
|
21
|
+
source?: string;
|
|
22
|
+
properties?: string[];
|
|
23
|
+
collections?: string[];
|
|
24
|
+
where?: Where;
|
|
25
|
+
order?: Order;
|
|
26
|
+
offset?: number;
|
|
27
|
+
limit?: number;
|
|
28
|
+
count?: boolean;
|
|
29
|
+
};
|
|
30
|
+
export type AllInstancesResult = {
|
|
31
|
+
AllInstances: Ad4mModel[];
|
|
32
|
+
TotalCount?: number;
|
|
33
|
+
};
|
|
34
|
+
export type ResultsWithTotalCount<T> = {
|
|
35
|
+
results: T[];
|
|
36
|
+
totalCount?: number;
|
|
37
|
+
};
|
|
38
|
+
export type PaginationResult<T> = {
|
|
39
|
+
results: T[];
|
|
40
|
+
totalCount?: number;
|
|
41
|
+
pageSize: number;
|
|
42
|
+
pageNumber: number;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Base class for defining data models in AD4M.
|
|
46
|
+
*
|
|
47
|
+
* @description
|
|
48
|
+
* Ad4mModel provides the foundation for creating data models that are stored in AD4M perspectives.
|
|
49
|
+
* Each model instance is represented as a subgraph in the perspective, with properties and collections
|
|
50
|
+
* mapped to links in that graph. The class uses Prolog-based queries to efficiently search and filter
|
|
51
|
+
* instances based on their properties and relationships.
|
|
52
|
+
*
|
|
53
|
+
* Key concepts:
|
|
54
|
+
* - Each model instance has a unique base expression that serves as its identifier
|
|
55
|
+
* - Properties are stored as links with predicates defined by the `through` option
|
|
56
|
+
* - Collections represent one-to-many relationships as sets of links
|
|
57
|
+
* - Queries are translated to Prolog for efficient graph pattern matching
|
|
58
|
+
* - Changes are tracked through the perspective's subscription system
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* // Define a recipe model
|
|
63
|
+
* @ModelOptions({ name: "Recipe" })
|
|
64
|
+
* class Recipe extends Ad4mModel {
|
|
65
|
+
* // Required property with literal value
|
|
66
|
+
* @Property({
|
|
67
|
+
* through: "recipe://name",
|
|
68
|
+
* resolveLanguage: "literal"
|
|
69
|
+
* })
|
|
70
|
+
* name: string = "";
|
|
71
|
+
*
|
|
72
|
+
* // Optional property with custom initial value
|
|
73
|
+
* @Optional({
|
|
74
|
+
* through: "recipe://status",
|
|
75
|
+
* initial: "recipe://draft"
|
|
76
|
+
* })
|
|
77
|
+
* status: string = "";
|
|
78
|
+
*
|
|
79
|
+
* // Read-only computed property
|
|
80
|
+
* @ReadOnly({
|
|
81
|
+
* through: "recipe://rating",
|
|
82
|
+
* getter: `
|
|
83
|
+
* findall(Rating, triple(Base, "recipe://user_rating", Rating), Ratings),
|
|
84
|
+
* sum_list(Ratings, Sum),
|
|
85
|
+
* length(Ratings, Count),
|
|
86
|
+
* Value is Sum / Count
|
|
87
|
+
* `
|
|
88
|
+
* })
|
|
89
|
+
* averageRating: number = 0;
|
|
90
|
+
*
|
|
91
|
+
* // Collection of ingredients
|
|
92
|
+
* @Collection({ through: "recipe://ingredient" })
|
|
93
|
+
* ingredients: string[] = [];
|
|
94
|
+
*
|
|
95
|
+
* // Collection of comments that are instances of another model
|
|
96
|
+
* @Collection({
|
|
97
|
+
* through: "recipe://comment",
|
|
98
|
+
* where: { isInstance: Comment }
|
|
99
|
+
* })
|
|
100
|
+
* comments: Comment[] = [];
|
|
101
|
+
* }
|
|
102
|
+
*
|
|
103
|
+
* // Create and save a new recipe
|
|
104
|
+
* const recipe = new Recipe(perspective);
|
|
105
|
+
* recipe.name = "Chocolate Cake";
|
|
106
|
+
* recipe.ingredients = ["flour", "sugar", "cocoa"];
|
|
107
|
+
* await recipe.save();
|
|
108
|
+
*
|
|
109
|
+
* // Query recipes in different ways
|
|
110
|
+
* // Get all recipes
|
|
111
|
+
* const allRecipes = await Recipe.findAll(perspective);
|
|
112
|
+
*
|
|
113
|
+
* // Find recipes with specific criteria
|
|
114
|
+
* const desserts = await Recipe.findAll(perspective, {
|
|
115
|
+
* where: {
|
|
116
|
+
* status: "recipe://published",
|
|
117
|
+
* averageRating: { gt: 4 }
|
|
118
|
+
* },
|
|
119
|
+
* order: { name: "ASC" },
|
|
120
|
+
* limit: 10
|
|
121
|
+
* });
|
|
122
|
+
*
|
|
123
|
+
* // Use the fluent query builder
|
|
124
|
+
* const popularRecipes = await Recipe.query(perspective)
|
|
125
|
+
* .where({ averageRating: { gt: 4.5 } })
|
|
126
|
+
* .order({ averageRating: "DESC" })
|
|
127
|
+
* .limit(5)
|
|
128
|
+
* .get();
|
|
129
|
+
*
|
|
130
|
+
* // Subscribe to real-time updates
|
|
131
|
+
* await Recipe.query(perspective)
|
|
132
|
+
* .where({ status: "recipe://cooking" })
|
|
133
|
+
* .subscribe(recipes => {
|
|
134
|
+
* console.log("Currently being cooked:", recipes);
|
|
135
|
+
* });
|
|
136
|
+
*
|
|
137
|
+
* // Paginate results
|
|
138
|
+
* const { results, totalCount, pageNumber } = await Recipe.query(perspective)
|
|
139
|
+
* .where({ status: "recipe://published" })
|
|
140
|
+
* .paginate(10, 1);
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
export declare class Ad4mModel {
|
|
144
|
+
#private;
|
|
145
|
+
author: string;
|
|
146
|
+
timestamp: string;
|
|
147
|
+
private static classNamesByClass;
|
|
148
|
+
static getClassName(perspective: PerspectiveProxy): Promise<string>;
|
|
149
|
+
/**
|
|
150
|
+
* Constructs a new model instance.
|
|
151
|
+
*
|
|
152
|
+
* @param perspective - The perspective where this model will be stored
|
|
153
|
+
* @param baseExpression - Optional unique identifier for this instance
|
|
154
|
+
* @param source - Optional source expression this instance is linked to
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* // Create a new recipe with auto-generated base expression
|
|
159
|
+
* const recipe = new Recipe(perspective);
|
|
160
|
+
*
|
|
161
|
+
* // Create with specific base expression
|
|
162
|
+
* const recipe = new Recipe(perspective, "recipe://chocolate-cake");
|
|
163
|
+
*
|
|
164
|
+
* // Create with source link
|
|
165
|
+
* const recipe = new Recipe(perspective, undefined, "cookbook://desserts");
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
constructor(perspective: PerspectiveProxy, baseExpression?: string, source?: string);
|
|
169
|
+
/**
|
|
170
|
+
* Gets the base expression of the subject.
|
|
171
|
+
*/
|
|
172
|
+
get baseExpression(): string;
|
|
173
|
+
/**
|
|
174
|
+
* Protected getter for the perspective.
|
|
175
|
+
* Allows subclasses to access the perspective while keeping it private from external code.
|
|
176
|
+
*/
|
|
177
|
+
protected get perspective(): PerspectiveProxy;
|
|
178
|
+
static assignValuesToInstance(perspective: PerspectiveProxy, instance: Ad4mModel, values: ValueTuple[]): Promise<void>;
|
|
179
|
+
private getData;
|
|
180
|
+
static queryToProlog(perspective: PerspectiveProxy, query: Query, modelClassName?: string | null): Promise<string>;
|
|
181
|
+
static instancesFromPrologResult<T extends Ad4mModel>(this: typeof Ad4mModel & (new (...args: any[]) => T), perspective: PerspectiveProxy, query: Query, result: AllInstancesResult): Promise<ResultsWithTotalCount<T>>;
|
|
182
|
+
/**
|
|
183
|
+
* Gets all instances of the model in the perspective that match the query params.
|
|
184
|
+
*
|
|
185
|
+
* @param perspective - The perspective to search in
|
|
186
|
+
* @param query - Optional query parameters to filter results
|
|
187
|
+
* @returns Array of matching models
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* // Get all recipes
|
|
192
|
+
* const allRecipes = await Recipe.findAll(perspective);
|
|
193
|
+
*
|
|
194
|
+
* // Get recipes with specific criteria
|
|
195
|
+
* const recipes = await Recipe.findAll(perspective, {
|
|
196
|
+
* where: {
|
|
197
|
+
* name: "Pasta",
|
|
198
|
+
* rating: { gt: 4 }
|
|
199
|
+
* },
|
|
200
|
+
* order: { createdAt: "DESC" },
|
|
201
|
+
* limit: 10
|
|
202
|
+
* });
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
static findAll<T extends Ad4mModel>(this: typeof Ad4mModel & (new (...args: any[]) => T), perspective: PerspectiveProxy, query?: Query): Promise<T[]>;
|
|
206
|
+
/**
|
|
207
|
+
* Gets all instances with count of total matches without offset & limit applied.
|
|
208
|
+
*
|
|
209
|
+
* @param perspective - The perspective to search in
|
|
210
|
+
* @param query - Optional query parameters to filter results
|
|
211
|
+
* @returns Object containing results array and total count
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```typescript
|
|
215
|
+
* const { results, totalCount } = await Recipe.findAllAndCount(perspective, {
|
|
216
|
+
* where: { category: "Dessert" },
|
|
217
|
+
* limit: 10
|
|
218
|
+
* });
|
|
219
|
+
* console.log(`Showing 10 of ${totalCount} dessert recipes`);
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
static findAllAndCount<T extends Ad4mModel>(this: typeof Ad4mModel & (new (...args: any[]) => T), perspective: PerspectiveProxy, query?: Query): Promise<ResultsWithTotalCount<T>>;
|
|
223
|
+
/**
|
|
224
|
+
* Helper function for pagination with explicit page size and number.
|
|
225
|
+
*
|
|
226
|
+
* @param perspective - The perspective to search in
|
|
227
|
+
* @param pageSize - Number of items per page
|
|
228
|
+
* @param pageNumber - Which page to retrieve (1-based)
|
|
229
|
+
* @param query - Optional additional query parameters
|
|
230
|
+
* @returns Paginated results with metadata
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```typescript
|
|
234
|
+
* const page = await Recipe.paginate(perspective, 10, 1, {
|
|
235
|
+
* where: { category: "Main Course" }
|
|
236
|
+
* });
|
|
237
|
+
* console.log(`Page ${page.pageNumber} of recipes, ${page.results.length} items`);
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
static paginate<T extends Ad4mModel>(this: typeof Ad4mModel & (new (...args: any[]) => T), perspective: PerspectiveProxy, pageSize: number, pageNumber: number, query?: Query): Promise<PaginationResult<T>>;
|
|
241
|
+
static countQueryToProlog(perspective: PerspectiveProxy, query?: Query, modelClassName?: string | null): Promise<string>;
|
|
242
|
+
/**
|
|
243
|
+
* Gets a count of all matching instances.
|
|
244
|
+
*
|
|
245
|
+
* @param perspective - The perspective to search in
|
|
246
|
+
* @param query - Optional query parameters to filter results
|
|
247
|
+
* @returns Total count of matching entities
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```typescript
|
|
251
|
+
* const totalRecipes = await Recipe.count(perspective);
|
|
252
|
+
* const activeRecipes = await Recipe.count(perspective, {
|
|
253
|
+
* where: { status: "active" }
|
|
254
|
+
* });
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
static count(perspective: PerspectiveProxy, query?: Query): Promise<any>;
|
|
258
|
+
private setProperty;
|
|
259
|
+
private setCollectionSetter;
|
|
260
|
+
private setCollectionAdder;
|
|
261
|
+
private setCollectionRemover;
|
|
262
|
+
/**
|
|
263
|
+
* Saves the model instance to the perspective.
|
|
264
|
+
* Creates a new instance with the base expression and links it to the source.
|
|
265
|
+
*
|
|
266
|
+
* @param batchId - Optional batch ID for batch operations
|
|
267
|
+
* @throws Will throw if instance creation, linking, or updating fails
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* ```typescript
|
|
271
|
+
* const recipe = new Recipe(perspective);
|
|
272
|
+
* recipe.name = "Spaghetti";
|
|
273
|
+
* recipe.ingredients = ["pasta", "tomato sauce"];
|
|
274
|
+
* await recipe.save();
|
|
275
|
+
*
|
|
276
|
+
* // Or with batch operations:
|
|
277
|
+
* const batchId = await perspective.createBatch();
|
|
278
|
+
* await recipe.save(batchId);
|
|
279
|
+
* await perspective.commitBatch(batchId);
|
|
280
|
+
* ```
|
|
281
|
+
*/
|
|
282
|
+
save(batchId?: string): Promise<void>;
|
|
283
|
+
private innerUpdate;
|
|
284
|
+
/**
|
|
285
|
+
* Updates the model instance's properties and collections.
|
|
286
|
+
*
|
|
287
|
+
* @param batchId - Optional batch ID for batch operations
|
|
288
|
+
* @throws Will throw if property setting or collection updates fail
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* ```typescript
|
|
292
|
+
* const recipe = await Recipe.findAll(perspective)[0];
|
|
293
|
+
* recipe.rating = 5;
|
|
294
|
+
* recipe.ingredients.push("garlic");
|
|
295
|
+
* await recipe.update();
|
|
296
|
+
*
|
|
297
|
+
* // Or with batch operations:
|
|
298
|
+
* const batchId = await perspective.createBatch();
|
|
299
|
+
* await recipe.update(batchId);
|
|
300
|
+
* await perspective.commitBatch(batchId);
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
303
|
+
update(batchId?: string): Promise<void>;
|
|
304
|
+
/**
|
|
305
|
+
* Gets the model instance with all properties and collections populated.
|
|
306
|
+
*
|
|
307
|
+
* @returns The populated model instance
|
|
308
|
+
* @throws Will throw if data retrieval fails
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* ```typescript
|
|
312
|
+
* const recipe = new Recipe(perspective, existingId);
|
|
313
|
+
* await recipe.get();
|
|
314
|
+
* console.log(recipe.name, recipe.ingredients);
|
|
315
|
+
* ```
|
|
316
|
+
*/
|
|
317
|
+
get(): Promise<this>;
|
|
318
|
+
/**
|
|
319
|
+
* Deletes the model instance from the perspective.
|
|
320
|
+
*
|
|
321
|
+
* @param batchId - Optional batch ID for batch operations
|
|
322
|
+
* @throws Will throw if removal fails
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* ```typescript
|
|
326
|
+
* const recipe = await Recipe.findAll(perspective)[0];
|
|
327
|
+
* await recipe.delete();
|
|
328
|
+
*
|
|
329
|
+
* // Or with batch operations:
|
|
330
|
+
* const batchId = await perspective.createBatch();
|
|
331
|
+
* await recipe.delete(batchId);
|
|
332
|
+
* await perspective.commitBatch(batchId);
|
|
333
|
+
* ```
|
|
334
|
+
*/
|
|
335
|
+
delete(batchId?: string): Promise<void>;
|
|
336
|
+
/**
|
|
337
|
+
* Creates a query builder for fluent query construction.
|
|
338
|
+
*
|
|
339
|
+
* @param perspective - The perspective to query
|
|
340
|
+
* @param query - Optional initial query parameters
|
|
341
|
+
* @returns A new query builder instance
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* ```typescript
|
|
345
|
+
* const recipes = await Recipe.query(perspective)
|
|
346
|
+
* .where({ category: "Dessert" })
|
|
347
|
+
* .order({ rating: "DESC" })
|
|
348
|
+
* .limit(5)
|
|
349
|
+
* .run();
|
|
350
|
+
*
|
|
351
|
+
* // With real-time updates
|
|
352
|
+
* await Recipe.query(perspective)
|
|
353
|
+
* .where({ status: "cooking" })
|
|
354
|
+
* .subscribe(recipes => {
|
|
355
|
+
* console.log("Currently cooking:", recipes);
|
|
356
|
+
* });
|
|
357
|
+
* ```
|
|
358
|
+
*/
|
|
359
|
+
static query<T extends Ad4mModel>(this: typeof Ad4mModel & (new (...args: any[]) => T), perspective: PerspectiveProxy, query?: Query): ModelQueryBuilder<T>;
|
|
360
|
+
}
|
|
361
|
+
/** Query builder for Ad4mModel queries.
|
|
362
|
+
* Allows building queries with a fluent interface and either running them once
|
|
363
|
+
* or subscribing to updates.
|
|
364
|
+
*
|
|
365
|
+
* @example
|
|
366
|
+
* ```typescript
|
|
367
|
+
* const builder = Recipe.query(perspective)
|
|
368
|
+
* .where({ category: "Dessert" })
|
|
369
|
+
* .order({ rating: "DESC" })
|
|
370
|
+
* .limit(10);
|
|
371
|
+
*
|
|
372
|
+
* // Run once
|
|
373
|
+
* const recipes = await builder.run();
|
|
374
|
+
*
|
|
375
|
+
* // Or subscribe to updates
|
|
376
|
+
* await builder.subscribe(recipes => {
|
|
377
|
+
* console.log("Updated recipes:", recipes);
|
|
378
|
+
* });
|
|
379
|
+
* ```
|
|
380
|
+
*/
|
|
381
|
+
export declare class ModelQueryBuilder<T extends Ad4mModel> {
|
|
382
|
+
private perspective;
|
|
383
|
+
private queryParams;
|
|
384
|
+
private modelClassName;
|
|
385
|
+
private ctor;
|
|
386
|
+
constructor(perspective: PerspectiveProxy, ctor: typeof Ad4mModel, query?: Query);
|
|
387
|
+
/**
|
|
388
|
+
* Adds where conditions to the query.
|
|
389
|
+
*
|
|
390
|
+
* @param conditions - The conditions to filter by
|
|
391
|
+
* @returns The query builder for chaining
|
|
392
|
+
*
|
|
393
|
+
* @example
|
|
394
|
+
* ```typescript
|
|
395
|
+
* .where({
|
|
396
|
+
* category: "Dessert",
|
|
397
|
+
* rating: { gt: 4 },
|
|
398
|
+
* tags: ["vegan", "quick"],
|
|
399
|
+
* published: true
|
|
400
|
+
* })
|
|
401
|
+
* ```
|
|
402
|
+
*/
|
|
403
|
+
where(conditions: Where): ModelQueryBuilder<T>;
|
|
404
|
+
/**
|
|
405
|
+
* Sets the order for the query results.
|
|
406
|
+
*
|
|
407
|
+
* @param orderBy - The ordering criteria
|
|
408
|
+
* @returns The query builder for chaining
|
|
409
|
+
*
|
|
410
|
+
* @example
|
|
411
|
+
* ```typescript
|
|
412
|
+
* .order({ createdAt: "DESC" })
|
|
413
|
+
* ```
|
|
414
|
+
*/
|
|
415
|
+
order(orderBy: Order): ModelQueryBuilder<T>;
|
|
416
|
+
/**
|
|
417
|
+
* Sets the maximum number of results to return.
|
|
418
|
+
*
|
|
419
|
+
* @param limit - Maximum number of results
|
|
420
|
+
* @returns The query builder for chaining
|
|
421
|
+
*
|
|
422
|
+
* @example
|
|
423
|
+
* ```typescript
|
|
424
|
+
* .limit(10)
|
|
425
|
+
* ```
|
|
426
|
+
*/
|
|
427
|
+
limit(limit: number): ModelQueryBuilder<T>;
|
|
428
|
+
/**
|
|
429
|
+
* Sets the number of results to skip.
|
|
430
|
+
*
|
|
431
|
+
* @param offset - Number of results to skip
|
|
432
|
+
* @returns The query builder for chaining
|
|
433
|
+
*
|
|
434
|
+
* @example
|
|
435
|
+
* ```typescript
|
|
436
|
+
* .offset(20) // Skip first 20 results
|
|
437
|
+
* ```
|
|
438
|
+
*/
|
|
439
|
+
offset(offset: number): ModelQueryBuilder<T>;
|
|
440
|
+
/**
|
|
441
|
+
* Sets the source filter for the query.
|
|
442
|
+
*
|
|
443
|
+
* @param source - The source to filter by
|
|
444
|
+
* @returns The query builder for chaining
|
|
445
|
+
*
|
|
446
|
+
* @example
|
|
447
|
+
* ```typescript
|
|
448
|
+
* .source("ad4m://self")
|
|
449
|
+
* ```
|
|
450
|
+
*/
|
|
451
|
+
source(source: string): ModelQueryBuilder<T>;
|
|
452
|
+
/**
|
|
453
|
+
* Specifies which properties to include in the results.
|
|
454
|
+
*
|
|
455
|
+
* @param properties - Array of property names to include
|
|
456
|
+
* @returns The query builder for chaining
|
|
457
|
+
*
|
|
458
|
+
* @example
|
|
459
|
+
* ```typescript
|
|
460
|
+
* .properties(["name", "description", "rating"])
|
|
461
|
+
* ```
|
|
462
|
+
*/
|
|
463
|
+
properties(properties: string[]): ModelQueryBuilder<T>;
|
|
464
|
+
/**
|
|
465
|
+
* Specifies which collections to include in the results.
|
|
466
|
+
*
|
|
467
|
+
* @param collections - Array of collection names to include
|
|
468
|
+
* @returns The query builder for chaining
|
|
469
|
+
*
|
|
470
|
+
* @example
|
|
471
|
+
* ```typescript
|
|
472
|
+
* .collections(["ingredients", "steps"])
|
|
473
|
+
* ```
|
|
474
|
+
*/
|
|
475
|
+
collections(collections: string[]): ModelQueryBuilder<T>;
|
|
476
|
+
overrideModelClassName(className: string): ModelQueryBuilder<T>;
|
|
477
|
+
/**
|
|
478
|
+
* Executes the query once and returns the results.
|
|
479
|
+
*
|
|
480
|
+
* @returns Array of matching entities
|
|
481
|
+
*
|
|
482
|
+
* @example
|
|
483
|
+
* ```typescript
|
|
484
|
+
* const recipes = await Recipe.query(perspective)
|
|
485
|
+
* .where({ category: "Dessert" })
|
|
486
|
+
* .get();
|
|
487
|
+
* ```
|
|
488
|
+
*/
|
|
489
|
+
get(): Promise<T[]>;
|
|
490
|
+
/**
|
|
491
|
+
* Subscribes to the query and receives updates when results change.
|
|
492
|
+
*
|
|
493
|
+
* This method:
|
|
494
|
+
* 1. Creates and initializes a Prolog query subscription
|
|
495
|
+
* 2. Sets up the callback to process future updates
|
|
496
|
+
* 3. Returns the initial results immediately
|
|
497
|
+
*
|
|
498
|
+
* The subscription is guaranteed to be ready when this method returns,
|
|
499
|
+
* as it waits for the initialization process to complete.
|
|
500
|
+
*
|
|
501
|
+
* @param callback - Function to call with updated results
|
|
502
|
+
* @returns Initial results array
|
|
503
|
+
*
|
|
504
|
+
* @example
|
|
505
|
+
* ```typescript
|
|
506
|
+
* // Subscribe to cooking recipes
|
|
507
|
+
* const initialRecipes = await Recipe.query(perspective)
|
|
508
|
+
* .where({ status: "cooking" })
|
|
509
|
+
* .subscribe(recipes => {
|
|
510
|
+
* // This callback will be called with future updates
|
|
511
|
+
* console.log("Currently cooking:", recipes);
|
|
512
|
+
* });
|
|
513
|
+
*
|
|
514
|
+
* // initialRecipes contains the current state
|
|
515
|
+
* console.log("Initial recipes:", initialRecipes);
|
|
516
|
+
* ```
|
|
517
|
+
*/
|
|
518
|
+
subscribe(callback: (results: T[]) => void): Promise<T[]>;
|
|
519
|
+
/**
|
|
520
|
+
* Gets the total count of matching entities.
|
|
521
|
+
*
|
|
522
|
+
* @returns Total count
|
|
523
|
+
*
|
|
524
|
+
* @example
|
|
525
|
+
* ```typescript
|
|
526
|
+
* const totalDesserts = await Recipe.query(perspective)
|
|
527
|
+
* .where({ category: "Dessert" })
|
|
528
|
+
* .count();
|
|
529
|
+
* ```
|
|
530
|
+
*/
|
|
531
|
+
count(): Promise<number>;
|
|
532
|
+
/**
|
|
533
|
+
* Subscribes to count updates for matching entities.
|
|
534
|
+
*
|
|
535
|
+
* This method:
|
|
536
|
+
* 1. Creates and initializes a Prolog query subscription for the count
|
|
537
|
+
* 2. Sets up the callback to process future count updates
|
|
538
|
+
* 3. Returns the initial count immediately
|
|
539
|
+
*
|
|
540
|
+
* The subscription is guaranteed to be ready when this method returns,
|
|
541
|
+
* as it waits for the initialization process to complete.
|
|
542
|
+
*
|
|
543
|
+
* @param callback - Function to call with updated count
|
|
544
|
+
* @returns Initial count
|
|
545
|
+
*
|
|
546
|
+
* @example
|
|
547
|
+
* ```typescript
|
|
548
|
+
* // Subscribe to active recipe count
|
|
549
|
+
* const initialCount = await Recipe.query(perspective)
|
|
550
|
+
* .where({ status: "active" })
|
|
551
|
+
* .countSubscribe(count => {
|
|
552
|
+
* // This callback will be called when the count changes
|
|
553
|
+
* console.log("Active items:", count);
|
|
554
|
+
* });
|
|
555
|
+
*
|
|
556
|
+
* // initialCount contains the current count
|
|
557
|
+
* console.log("Initial count:", initialCount);
|
|
558
|
+
* ```
|
|
559
|
+
*/
|
|
560
|
+
countSubscribe(callback: (count: number) => void): Promise<number>;
|
|
561
|
+
/**
|
|
562
|
+
* Gets a page of results with pagination metadata.
|
|
563
|
+
*
|
|
564
|
+
* @param pageSize - Number of items per page
|
|
565
|
+
* @param pageNumber - Which page to retrieve (1-based)
|
|
566
|
+
* @returns Paginated results with metadata
|
|
567
|
+
*
|
|
568
|
+
* @example
|
|
569
|
+
* ```typescript
|
|
570
|
+
* const page = await Recipe.query(perspective)
|
|
571
|
+
* .where({ category: "Main" })
|
|
572
|
+
* .paginate(10, 1);
|
|
573
|
+
* console.log(`Page ${page.pageNumber}, ${page.results.length} of ${page.totalCount}`);
|
|
574
|
+
* ```
|
|
575
|
+
*/
|
|
576
|
+
paginate(pageSize: number, pageNumber: number): Promise<PaginationResult<T>>;
|
|
577
|
+
/**
|
|
578
|
+
* Subscribes to paginated results updates.
|
|
579
|
+
*
|
|
580
|
+
* This method:
|
|
581
|
+
* 1. Creates and initializes a Prolog query subscription for the paginated results
|
|
582
|
+
* 2. Sets up the callback to process future page updates
|
|
583
|
+
* 3. Returns the initial page immediately
|
|
584
|
+
*
|
|
585
|
+
* The subscription is guaranteed to be ready when this method returns,
|
|
586
|
+
* as it waits for the initialization process to complete.
|
|
587
|
+
*
|
|
588
|
+
* @param pageSize - Number of items per page
|
|
589
|
+
* @param pageNumber - Which page to retrieve (1-based)
|
|
590
|
+
* @param callback - Function to call with updated pagination results
|
|
591
|
+
* @returns Initial pagination results
|
|
592
|
+
*
|
|
593
|
+
* @example
|
|
594
|
+
* ```typescript
|
|
595
|
+
* // Subscribe to first page of main recipes
|
|
596
|
+
* const initialPage = await Recipe.query(perspective)
|
|
597
|
+
* .where({ category: "Main" })
|
|
598
|
+
* .paginateSubscribe(10, 1, page => {
|
|
599
|
+
* // This callback will be called when the page content changes
|
|
600
|
+
* console.log("Updated page:", page.results);
|
|
601
|
+
* });
|
|
602
|
+
*
|
|
603
|
+
* // initialPage contains the current page state
|
|
604
|
+
* console.log("Initial page:", initialPage.results);
|
|
605
|
+
* ```
|
|
606
|
+
*/
|
|
607
|
+
paginateSubscribe(pageSize: number, pageNumber: number, callback: (results: PaginationResult<T>) => void): Promise<PaginationResult<T>>;
|
|
608
|
+
}
|
|
609
|
+
export {};
|