@olympeio/runtime-node 9.10.5 → 9.11.1
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/import/olympe.dm/datamodel/.Primordial.newInst.json +1 -1
- package/import/olympe.dm/datamodel/05_permission_schema.updateInst.json +1 -1
- package/import/olympe.sc/datamodel/01_language.newInst.json +1 -1
- package/index.js +988 -940
- package/package.json +3 -2
- package/types/composition.d.ts +122 -0
- package/types/data-connector.d.ts +356 -0
- package/types/{base.d.ts → data.d.ts} +168 -158
- package/types/index.d.ts +9 -3
- package/types/legacy.d.ts +2 -1
- package/types/models.d.ts +203 -0
- package/types/{utils.d.ts → other.d.ts} +158 -285
- package/types/query.d.ts +726 -0
- package/types/runtime.d.ts +49 -35
- package/types/service.d.ts +190 -0
- package/types/transaction-advanced.d.ts +34 -0
- package/types/transaction.d.ts +266 -0
- package/types/cloud.d.ts +0 -1726
package/types/query.d.ts
ADDED
|
@@ -0,0 +1,726 @@
|
|
|
1
|
+
import { Class, Context } from "./other";
|
|
2
|
+
import { CloudObject, InstanceOrTag } from "./data";
|
|
3
|
+
import { FollowRule, RootQueryPart } from "./data-connector";
|
|
4
|
+
import { Property, Relation } from "./composition";
|
|
5
|
+
import { Source } from "./data-connector";
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
import { Observable } from "rxjs";
|
|
8
|
+
|
|
9
|
+
declare type ImplicitQueryOption = {
|
|
10
|
+
storeInCacheDB?: boolean // indicates if this follow rule query must be cached in browser DB (IndexedDB) for potential offline use. Default is false.
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
declare type QueryOptions = {
|
|
15
|
+
cacheBucketName?: string; // Name of the cache bucket - if provided, it means that the query must be cached under this name
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// ----------------------
|
|
19
|
+
// -- Database queries --
|
|
20
|
+
// ----------------------
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A QueryResult is a list of key-value pairs that has been generated as a result of a `Query`.
|
|
24
|
+
* It contains the result of a query at a specific time.
|
|
25
|
+
*
|
|
26
|
+
* The keys are tags (e.g. `myTag`) that correspond to a `CloudObject` (e.g. `myCloudObject`).
|
|
27
|
+
* When the {@link Query} contains more than one {@link Query.andReturn Query.andReturn()} clause,
|
|
28
|
+
* keys are composite tags (e.g. `'tag1.tag2.tag3'`) and values are tuples of `CloudObjects` (e.g. `[cloudObj1, cloudObj2, cloudObj3]`).
|
|
29
|
+
* Such a QueryResult can be obtained via:
|
|
30
|
+
* ```javascript
|
|
31
|
+
* Query.instancesOf(myModel1).andReturn.follow(myRelation1).andReturn.follow(myRelation2).andReturn().execute().
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* When a query is subscribed, the returned observable generates multiple QueryResults over time.
|
|
35
|
+
*
|
|
36
|
+
* A QueryResult can be easily manipulated and transformed to a standard Array.
|
|
37
|
+
*/
|
|
38
|
+
export class QueryResult<T extends CloudObject | CloudObject[]> {
|
|
39
|
+
/**
|
|
40
|
+
*@return empty `QueryResult`
|
|
41
|
+
*/
|
|
42
|
+
static empty(): QueryResult<any>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Symbol iterator for `for…in` syntactic sugar
|
|
46
|
+
*
|
|
47
|
+
* @return iterator over the key-values pairs of this `QueryResult`
|
|
48
|
+
*/
|
|
49
|
+
[Symbol.iterator](): IterableIterator<[string, T]>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Get an iterable iterator over the key-value pairs of this `QueryResult`
|
|
53
|
+
*
|
|
54
|
+
* @return iterator
|
|
55
|
+
*/
|
|
56
|
+
entries(): IterableIterator<[string, T]>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Get an iterable iterator over the values of this `QueryResult`
|
|
60
|
+
*
|
|
61
|
+
* @return iterator
|
|
62
|
+
*/
|
|
63
|
+
values(): IterableIterator<T>
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Get an iterable iterator over the keys of this `QueryResult`
|
|
67
|
+
*
|
|
68
|
+
* @return iterator
|
|
69
|
+
*/
|
|
70
|
+
keys(): IterableIterator<string>
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Get an array containing the values of this `QueryResult`
|
|
74
|
+
*
|
|
75
|
+
* @return array of this `QueryResult`'s values
|
|
76
|
+
*/
|
|
77
|
+
toArray(): T[];
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get the number of key-value pairs this `QueryResult` contains
|
|
81
|
+
*
|
|
82
|
+
* @return size of this `QueryResult`
|
|
83
|
+
*/
|
|
84
|
+
size(): number;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Check whether a key / value is contained in this `QueryResult`.
|
|
88
|
+
*
|
|
89
|
+
* Returns true if the cloud array contains an element with the specified key.
|
|
90
|
+
*
|
|
91
|
+
* If no corresponding key is found, returns true if the cloud array contains an element with the specified value.
|
|
92
|
+
*
|
|
93
|
+
* @param key the value to search for
|
|
94
|
+
* @return true if the value `key` is found
|
|
95
|
+
*/
|
|
96
|
+
has(key: T | string): boolean;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Get index of a value in the keys or values of this `QueryResult`.
|
|
100
|
+
*
|
|
101
|
+
* If the key is a string, retrieve the index from the `string` keys of this `QueryResult`.
|
|
102
|
+
*
|
|
103
|
+
* If the key is not a string, get the index from the `CloudObject` tuples
|
|
104
|
+
*
|
|
105
|
+
* @param key the value to find the index of
|
|
106
|
+
* @return index of the argument value or -1 if the value is not found
|
|
107
|
+
*/
|
|
108
|
+
indexOf(key: T | string): number;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Get the value corresponding to a given key
|
|
112
|
+
*
|
|
113
|
+
* @param key tag or composite tag
|
|
114
|
+
* @return matching tuple or `null`
|
|
115
|
+
*/
|
|
116
|
+
get(key: string): T | null;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Get the first value
|
|
120
|
+
*
|
|
121
|
+
* @return first value or `null` if empty
|
|
122
|
+
*/
|
|
123
|
+
getFirst(): T | null;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Get the value at the specified index
|
|
127
|
+
*
|
|
128
|
+
* @param index
|
|
129
|
+
* @return value at position `index` or `null` if index is out of bounds
|
|
130
|
+
*/
|
|
131
|
+
getAt(index: number): T | null;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Query Results, when used in a subscription, can be used to observe changes compare to the previous QueryResult.
|
|
135
|
+
* This method returns the values that have added from the previous QueryResult.
|
|
136
|
+
*
|
|
137
|
+
* @return array of added values (CloudObjects or tuples of CloudObjects)
|
|
138
|
+
*/
|
|
139
|
+
getAdded(): T[];
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Query Results, when used in a subscription, can be used to observe changes compare to the previous QueryResult.
|
|
143
|
+
* This method returns the values the keys (eg: tags) of values that have been removed from the previous QueryResult.
|
|
144
|
+
*
|
|
145
|
+
* @return array of removed keys (tags or tags concatenation (tuples))
|
|
146
|
+
*/
|
|
147
|
+
getRemoved(): string[];
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Returns an array equivalent to {@link QueryResult.toArray | this.toArray().push(...object)}
|
|
151
|
+
*
|
|
152
|
+
* This operation returns a new array and does not modify this QueryResult.
|
|
153
|
+
*
|
|
154
|
+
* @param object new values to push in the values array.
|
|
155
|
+
* @return new values array with new elements appended
|
|
156
|
+
*/
|
|
157
|
+
push(...object: T[]): T[];
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Returns the QueryResult values as an array whose last value has been removed.
|
|
161
|
+
*
|
|
162
|
+
* If {@link QueryResult.size} is 0 or 1, this method returns an empty array.
|
|
163
|
+
*
|
|
164
|
+
* This operation returns a new array and does not modify this QueryResult.
|
|
165
|
+
*
|
|
166
|
+
* @return new values array with last element removed
|
|
167
|
+
*/
|
|
168
|
+
pop(): T[];
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Returns the QueryResult values as an array whose first value has been removed.
|
|
172
|
+
*
|
|
173
|
+
* If {@link QueryResult.size} is 0 or 1, this method returns an empty array.
|
|
174
|
+
*
|
|
175
|
+
* This operation returns a new array and does not modify this QueryResult.
|
|
176
|
+
*
|
|
177
|
+
* @return new values array with first element removed
|
|
178
|
+
*/
|
|
179
|
+
shift(): T[];
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Returns an array containing the values matching the provided filter predicate.
|
|
183
|
+
*
|
|
184
|
+
* @param predicate filter {@link Predicate}
|
|
185
|
+
* @return array of matching values
|
|
186
|
+
*/
|
|
187
|
+
filter(predicate: (entry: T, index: number) => boolean): T[];
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Returns the first value matching the predicate, `null` otherwise.
|
|
191
|
+
*
|
|
192
|
+
* `find` calls `predicate` once for each element of the array until it returns true.
|
|
193
|
+
* If such an element is found, find immediately returns that element value.
|
|
194
|
+
*
|
|
195
|
+
* @param predicate
|
|
196
|
+
* @return the first value evaluating to true or `null`
|
|
197
|
+
*/
|
|
198
|
+
find(predicate: (entry: T, index: number) => boolean): T | null;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Execute the specified callback function for each value of this `QueryResult`
|
|
202
|
+
*
|
|
203
|
+
* @param callback
|
|
204
|
+
*/
|
|
205
|
+
forEach(callback: (entry: T, index: number) => void): void;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Execute the specified callback function for each value of this `QueryResult`.
|
|
209
|
+
* It returns a new array that contains the results of the callback execution.
|
|
210
|
+
*
|
|
211
|
+
* @param callback
|
|
212
|
+
* @return new array of transformed values
|
|
213
|
+
*/
|
|
214
|
+
map<S>(callback: (entry: T, index: number) => S): S[];
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Return a sorted copy of this QueryResult.
|
|
218
|
+
*
|
|
219
|
+
* The specified `comparator` used to determine the order of the QueryResult key-value pairs.
|
|
220
|
+
* It compares two QueryResult values and should return a negative number if the first value shall be present before the second, zero if they're at the same position, and a positive
|
|
221
|
+
* number otherwise.
|
|
222
|
+
*
|
|
223
|
+
* @param comparator comparator returning a negative, zero or positive number
|
|
224
|
+
* @return sorted copy of this QueryResult
|
|
225
|
+
*/
|
|
226
|
+
sort(comparator: (b1: T, b2: T) => number): QueryResult<T>;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Return a reduced value for this QueryResult.
|
|
230
|
+
*
|
|
231
|
+
* The specified `reducer` callback reduces the QueryResult values. Similar to `Array.reduce()`.
|
|
232
|
+
*
|
|
233
|
+
* @param reducer callback
|
|
234
|
+
* @param initial initial value of the accumulator
|
|
235
|
+
* @return accumulated result applying the `reducer` function iteratively
|
|
236
|
+
*/
|
|
237
|
+
reduce<S>(reducer: (accumulator: S, entry: T, index: number) => S, initial: S): S;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Return a new QueryResult that contains the concatenation of two or more QueryResults.
|
|
241
|
+
*
|
|
242
|
+
* Concatenating two QueryResults results in a new QueryResult with the following:
|
|
243
|
+
*
|
|
244
|
+
* - the keys of the QueryResults are concatenated
|
|
245
|
+
* - the values of the QueryResults are concatenated
|
|
246
|
+
* - the arrays returned by {@link QueryResult.getAdded} are concatenated
|
|
247
|
+
* - the arrays returned by {@link QueryResult.getRemoved} are concatenated
|
|
248
|
+
*
|
|
249
|
+
* Example :
|
|
250
|
+
* ```javascript
|
|
251
|
+
* const result1 = Query.fromInstances(myModel1).executeFromCache();
|
|
252
|
+
* // result1 is {tag1: cloudObj1, tag2: cloudObj2}
|
|
253
|
+
* const result2 = Query.fromInstances(myModel2).executeFromCache();
|
|
254
|
+
* // result2 is {tag3: cloudObj3}
|
|
255
|
+
* const concatenatedResult = result2.concat(result1);
|
|
256
|
+
* // concatenatedResult is {tag3: cloudObj3, tag1: cloudObj1, tag2: cloudObj2}
|
|
257
|
+
* ```
|
|
258
|
+
*
|
|
259
|
+
* @param others QueryResults to append to this `QueryResult`
|
|
260
|
+
* @return concatenated query results
|
|
261
|
+
*/
|
|
262
|
+
concat(...others: QueryResult<T>[]): QueryResult<T>;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Predicates are used to filter queries.
|
|
268
|
+
*
|
|
269
|
+
* Example:
|
|
270
|
+
* ```javascript
|
|
271
|
+
* const predicate = Predicate.equals(myNumberProperty, 1);
|
|
272
|
+
* const filteredQuery = Query.instancesOf(myModel).filter(predicate).andReturn();
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
export class Predicate {
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Create a predicate to match the specified object(s).
|
|
279
|
+
*
|
|
280
|
+
* @param tags the object or unique identifier (tag) of the objects to look for.
|
|
281
|
+
*/
|
|
282
|
+
static in(...tags: InstanceOrTag[]): Predicate;
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Create a predicate matching a specified property to a specified value.
|
|
286
|
+
*
|
|
287
|
+
* @param property the property to use for filtering
|
|
288
|
+
* @param value the value the property must match
|
|
289
|
+
* @return new Predicate with the equals operation
|
|
290
|
+
*/
|
|
291
|
+
static equals<T>(property: Property<T>, value: T): Predicate;
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Create a predicate matching a specified string property to a specified string.
|
|
295
|
+
*
|
|
296
|
+
* @param property the string property to use for filtering
|
|
297
|
+
* @param value the value the string property must match
|
|
298
|
+
* @param caseSensitive if the match must pay attention to case sensitivity, default value is true
|
|
299
|
+
* @return new Predicate with the contains string operation
|
|
300
|
+
*/
|
|
301
|
+
static contains(property: Property<string>, value: string, caseSensitive?: boolean): Predicate;
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Create a predicate matching a specified string property to a regular expression.
|
|
305
|
+
*
|
|
306
|
+
* @param property the string property to use for filtering
|
|
307
|
+
* @param value the regex or pattern the string property must match
|
|
308
|
+
* @param caseSensitive if the match must pay attention to case sensitivity, default value is true
|
|
309
|
+
* @return new Predicate with the match regex operation
|
|
310
|
+
*/
|
|
311
|
+
static regex(property: Property<string>, value: RegExp | string, caseSensitive?: boolean): Predicate;
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Create a predicate matching a specified number property to a numerical lower bound
|
|
315
|
+
*
|
|
316
|
+
* @param property the number property to user for filtering
|
|
317
|
+
* @param value the lower bound
|
|
318
|
+
* @param strict if the inequality is strict or not
|
|
319
|
+
* @return new Predicate with the greaterThan mathematical operation
|
|
320
|
+
*/
|
|
321
|
+
static greaterThan(property: Property<number>, value: number, strict?: boolean): Predicate;
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Create a predicate matching a specified number property to a numerical upper bound
|
|
325
|
+
*
|
|
326
|
+
* @param property the number property to user for filtering
|
|
327
|
+
* @param value the upper bound
|
|
328
|
+
* @param strict if the inequality is strict or not
|
|
329
|
+
* @return new Predicate with the smallerThan mathematical operation
|
|
330
|
+
*/
|
|
331
|
+
static smallerThan(property: Property<number>, value: number, strict?: boolean): Predicate;
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Create a predicate matching a specified number property to a number property lower bound
|
|
335
|
+
*
|
|
336
|
+
* @param property1 the number property to user for filtering
|
|
337
|
+
* @param property2 the lower bound number property
|
|
338
|
+
* @param strict if the inequality is strict or not
|
|
339
|
+
* @return new Predicate with the greaterThan mathematical operation
|
|
340
|
+
*/
|
|
341
|
+
static greaterThan(property1: Property<number>, property2: Property<number>, strict?: boolean): Predicate;
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Create a predicate matching a specified number property to a number property upper bound
|
|
345
|
+
*
|
|
346
|
+
* @param property1 the number property to user for filtering
|
|
347
|
+
* @param property2 the upper bound number property
|
|
348
|
+
* @param strict if the inequality is strict or not
|
|
349
|
+
* @return new Predicate with the smallerThan mathematical operation
|
|
350
|
+
*/
|
|
351
|
+
static smallerThan(property1: Property<number>, property2: Property<number>, strict?: boolean): Predicate;
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Create an AND composite predicate matching a specified set of predicates
|
|
355
|
+
*
|
|
356
|
+
* @param predicates list of predicates to match
|
|
357
|
+
* @return new Predicate that should match all specified predicates
|
|
358
|
+
*/
|
|
359
|
+
static and(...predicates: Predicate[]): Predicate;
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Create an OR composite predicate matching a specified set of predicates
|
|
363
|
+
*
|
|
364
|
+
* @param predicates list of predicates to match
|
|
365
|
+
* @return new Predicate that should match at least one specified predicate
|
|
366
|
+
*/
|
|
367
|
+
static or(...predicates: Predicate[]): Predicate;
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Create a NOT predicate matching the opposite of a specified predicate
|
|
371
|
+
*
|
|
372
|
+
* @param predicate the predicate to inverse
|
|
373
|
+
* @return new Predicate that match when the specified predicate does not
|
|
374
|
+
*/
|
|
375
|
+
static not(predicate: Predicate): Predicate;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* A Query is an immutable object used to build queries on the datacloud. It is a graph query builder.
|
|
382
|
+
* It starts from an `origin` InstanceOrTag (typically, the `InstanceOrTag` of a data type or of an instance).
|
|
383
|
+
* From there, it can follow relations between data types and filter results.
|
|
384
|
+
*
|
|
385
|
+
* Example:
|
|
386
|
+
*
|
|
387
|
+
* `origin --a--> X --b--> Y --c--> Z`
|
|
388
|
+
*
|
|
389
|
+
* Example:
|
|
390
|
+
*
|
|
391
|
+
* ```javascript
|
|
392
|
+
* Query.from(origin)
|
|
393
|
+
* .follow(a)
|
|
394
|
+
* .execute();
|
|
395
|
+
* ```
|
|
396
|
+
* This will return a Promise of a QueryResult whose values are of type X: `Promise<QueryResult<X>>`.
|
|
397
|
+
*
|
|
398
|
+
* A query defines a starting working set of nodes and operations that will mutate it.
|
|
399
|
+
* From our example,the working set is first the `origin` graph node. Then the `follow`
|
|
400
|
+
* operations create a new working set only containing the nodes related to the origin through relation *`a`*.
|
|
401
|
+
*
|
|
402
|
+
* Multiple relations can be followed at once to create the equivalent of JOIN operations in relational databases.
|
|
403
|
+
* ```javascript
|
|
404
|
+
* Query.from(origin)
|
|
405
|
+
* .follow(a).andReturn()
|
|
406
|
+
* .follow(b)
|
|
407
|
+
* .follow(c).andReturn()
|
|
408
|
+
* .execute();
|
|
409
|
+
* ```
|
|
410
|
+
* The next operation defines a working set containing the nodes related
|
|
411
|
+
* through relation *`b`* to nodes that are related through relation *`a`* to the origin.
|
|
412
|
+
* A similar operation is defined for relation `c`.
|
|
413
|
+
* At each level, "andReturn()" method can be called to add the current level to the result.
|
|
414
|
+
* This will return a Promise of a QueryResult whose values are of type [X, Z]: `Promise<QueryResult<[X, Z]>>`.
|
|
415
|
+
*
|
|
416
|
+
* Out of the 4 working sets created, only the second and fourth are flagged to be returned and part of the result.
|
|
417
|
+
* But the operations in the middle impact this result: e.g.,
|
|
418
|
+
* all returned tuples (t1, t2) are object that have an intermediate `i` of type Y.
|
|
419
|
+
* such that `t1 --b-> i --c-> t2` but the `i` was not flagged to be returned.
|
|
420
|
+
*
|
|
421
|
+
* Queries define a path from a starting point following a specific list of relations.
|
|
422
|
+
* As explained with our example, only nodes part of a full path can be returned.
|
|
423
|
+
*
|
|
424
|
+
*
|
|
425
|
+
* A query can be executed with 3 different ways:
|
|
426
|
+
* - execute(): it runs the query on the datacloud and return the result as a QueryResult.
|
|
427
|
+
* - observe(): it runs the query on the datacloud and subscribes to updates. It returns an Observable which provides a new QueryResult every time the result changes.
|
|
428
|
+
* - executeFromCache(): it runs the query on the *local* datacloud which may be incomplete view of the datacloud (it is the local cache). It is executed synchronously.
|
|
429
|
+
*/
|
|
430
|
+
export class Query<T extends CloudObject, R> {
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Create a query starting from the `CloudObject` specified tag.
|
|
434
|
+
* That `CloudObject` must already exist in the local database. In case you have the tag as a `string` and need to get
|
|
435
|
+
* the object from a remote database, use {@link Query.fromTag} instead.
|
|
436
|
+
*
|
|
437
|
+
* @param tag tag of the `CloudObject` the query is starting from
|
|
438
|
+
* @param source optional source of the data to answer the query
|
|
439
|
+
* @return an empty Query whose starting point is defined by a single `CloudObject`
|
|
440
|
+
*/
|
|
441
|
+
static from<T extends InstanceOrTag>(tag: T, source?: Source): Query<T extends CloudObject ? T : CloudObject, never>;
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Create a query starting from the `CloudObject` specified tag.
|
|
445
|
+
* The difference with {@link Query.from} method is that you specify the data type of the Tag: this allows to execute
|
|
446
|
+
* queries with a tag that is unknown by the local database, on the right remote database.
|
|
447
|
+
*
|
|
448
|
+
* @param tag tag of the `CloudObject` the query is starting from
|
|
449
|
+
* @param dataType data type of the `tag` `CloudObject`.
|
|
450
|
+
* @param source optional source of the data to answer the query
|
|
451
|
+
* @return an empty Query whose starting point is defined by a single `CloudObject`
|
|
452
|
+
*/
|
|
453
|
+
static fromTag<T extends CloudObject>(tag: string, dataType: Class<T> | InstanceOrTag, source?: Source): Query<T, never>;
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Create a query starting from the instances of the specified model. By default, it does include the instances of
|
|
457
|
+
* the models that inherit from the given one.
|
|
458
|
+
*
|
|
459
|
+
* @param model tag/class of the model to find the instances of
|
|
460
|
+
* @param includeInheritance if set to false, the result will not include instances of models that inherit from the given model.
|
|
461
|
+
* @param source optional source of the data to answer the query
|
|
462
|
+
* A source can be the orchestrator ('server'), local ('self') or
|
|
463
|
+
* an external data source (Tag of a `DBConnectorTag`)
|
|
464
|
+
* @return a new query object starting from model instances
|
|
465
|
+
*/
|
|
466
|
+
static instancesOf<T extends InstanceOrTag>(model: Class<T> | InstanceOrTag, includeInheritance?: boolean, source?: Source): Query<T extends CloudObject ? T : CloudObject, never>;
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Create a query starting from a specific root instance, then following relations based on a rule constraint.
|
|
470
|
+
* @param ctx Context in which the {@link Query} is observed
|
|
471
|
+
* @param root Starting point of the query. See `root` of {@link RootQueryPart}
|
|
472
|
+
* @param rule Discriminate which relations to follow
|
|
473
|
+
* @param source The tag of the source responsible for executing the query
|
|
474
|
+
* @param options options
|
|
475
|
+
*/
|
|
476
|
+
static followRule<T extends InstanceOrTag>(ctx: Context, root: T, rule: FollowRule, source?: Source, options?: ImplicitQueryOption): Observable<QueryResult<T extends CloudObject ? T : CloudObject>>;
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Instruct the query to follow a specified relation. This does not add any key-value pair to the result.
|
|
480
|
+
* (see {@link Query.andReturn}). This operation defines a new step in the path defined by our graph query.
|
|
481
|
+
*
|
|
482
|
+
* Example:
|
|
483
|
+
* Find the model of a single object.
|
|
484
|
+
* ```javascript
|
|
485
|
+
* Query.from(myTag).follow(CloudObject.modelRel).andReturn()
|
|
486
|
+
* ```
|
|
487
|
+
*
|
|
488
|
+
* @param relation relation to follow, specifies type and direction
|
|
489
|
+
* @param optional whether or not the relation creates a mandatory path in the graph to be part of the result.
|
|
490
|
+
* @return a new query object
|
|
491
|
+
*/
|
|
492
|
+
follow<D extends CloudObject>(relation: Relation<T, D>, optional?: boolean): Query<D, R>;
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Follow a relation recursively, see {@link Query.follow}.
|
|
496
|
+
* The relation that is followed is automatically recursively followed.
|
|
497
|
+
* All nodes that are recursively followed are part of the same step in the path defined by this graph query.
|
|
498
|
+
*
|
|
499
|
+
* @param relation relation to follow recursively, specifies type and direction.
|
|
500
|
+
* @param includeSelf if a starting node includes itself when the relation loops on itself. (default: false)
|
|
501
|
+
* @param optional whether or not the relation creates a mandatory path in the graph to be part of the result. (default: false)
|
|
502
|
+
* @return a new query object
|
|
503
|
+
*/
|
|
504
|
+
followRecursively<D extends CloudObject>(relation: Relation<T, D>, includeSelf?: boolean, optional?: boolean): Query<D, R>;
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* The Query.back() function is used to move the cursor of a query backwards to the previous level.
|
|
508
|
+
* This allows the query to start from the place where it was before a Query.follow() call,
|
|
509
|
+
* but with a different relation. The `times` parameter is optional and specifies the number of steps to go back.
|
|
510
|
+
* If hops is not specified, the default value of 1 is used.
|
|
511
|
+
* If a value equal to or smaller than 0 is specified, the output query is the same as the input query.
|
|
512
|
+
*
|
|
513
|
+
* Example:
|
|
514
|
+
* ```javascript
|
|
515
|
+
* const people = [
|
|
516
|
+
* \{ name: "Alice", children: ["Bob", "Carol"], siblings: ["David"] \},
|
|
517
|
+
* \{ name: "Bob", children: ["Emily"], siblings: ["Alice", "Carol", "David"] \},
|
|
518
|
+
* \{ name: "Carol", children: ["Frank"], siblings: ["Alice", "Bob", "David"] \},
|
|
519
|
+
* \{ name: "David", children: ["Greg"], siblings: ["Alice", "Bob", "Carol"] \},
|
|
520
|
+
* \{ name: "Emily", children: [], siblings: [] \},
|
|
521
|
+
* \{ name: "Frank", children: [], siblings: [] \},
|
|
522
|
+
* \{ name: "Greg", children: [], siblings: [] \}
|
|
523
|
+
* ];
|
|
524
|
+
*
|
|
525
|
+
* // Create a new query starting from Alice
|
|
526
|
+
* const aliceQuery = Query.from("Alice");
|
|
527
|
+
*
|
|
528
|
+
* // Follow the "children" relation to get Alice's children (Bob, Carol)
|
|
529
|
+
* const aliceChildrenQuery = aliceQuery.follow("children").andReturn();
|
|
530
|
+
*
|
|
531
|
+
* // Go back to the previous level and follow the "siblings" relation to get Alice's siblings (David)
|
|
532
|
+
* const aliceSiblingsQuery = aliceChildrenQuery.back().follow("siblings").andReturn();
|
|
533
|
+
*
|
|
534
|
+
* // Execute the query, the output is:
|
|
535
|
+
* Output: [ \{ sibling: 'David', child: 'Bob' \}, \{ sibling: 'David', child: 'Carol' \} ]
|
|
536
|
+
* ```
|
|
537
|
+
* @param times
|
|
538
|
+
* @return {!Query}
|
|
539
|
+
*/
|
|
540
|
+
back(times?: number): Query<CloudObject, R>;
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Add the current working set of nodes to the result.
|
|
544
|
+
*
|
|
545
|
+
* Example:
|
|
546
|
+
* Query returning the instances of a model and the model itself
|
|
547
|
+
* ```javascript
|
|
548
|
+
* Query
|
|
549
|
+
* .from(myModelTag).andReturn()
|
|
550
|
+
* .follow(CloudObject.modelRel.getInverse()).andReturn()
|
|
551
|
+
* .execute();
|
|
552
|
+
* ```
|
|
553
|
+
* The result tuples are [modelCloudObject, instance1], [modelCloudObject, instance2], ...
|
|
554
|
+
*
|
|
555
|
+
* @return a new query object with the current level flagged to be returned.
|
|
556
|
+
*/
|
|
557
|
+
andReturn(): Query<T, R extends never ? T : R extends CloudObject[] ? [...R, T] : [R, T]>;
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Define a filter operation on the current working set of nodes.
|
|
561
|
+
* It filters out instances that don't match the given {@link Predicate}
|
|
562
|
+
*
|
|
563
|
+
* @param predicate
|
|
564
|
+
* @return a new query object with the new filter operation
|
|
565
|
+
*/
|
|
566
|
+
filter(predicate: Predicate): Query<T, R>;
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Cast the type of the instances in the current working set of nodes
|
|
570
|
+
*
|
|
571
|
+
* @param type cast type for `CloudObjects`
|
|
572
|
+
* @return the
|
|
573
|
+
*/
|
|
574
|
+
cast<S extends CloudObject>(type: Class<S>): Query<S, R>;
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* Set the maximum number of tuples the executed query will return with an optional offset.
|
|
578
|
+
*
|
|
579
|
+
* Only the last call to limit matters.
|
|
580
|
+
*
|
|
581
|
+
* Example :
|
|
582
|
+
* ```javascript
|
|
583
|
+
* const queryLimited = query.limit(50).follow(myRel2).limit(100, 200).follow(myRel1);
|
|
584
|
+
* // is equivalent to
|
|
585
|
+
* const queryLimited2 = query.follow(myRel2).follow(myRel1).limit(100, 200);
|
|
586
|
+
* ```
|
|
587
|
+
* `queryLimited`, when executed, will return at most the 200th to the 299th (included) results.
|
|
588
|
+
*
|
|
589
|
+
* @param max maximum number of tuple to fetch from the final result
|
|
590
|
+
* @param offset number of skipped tuples for the final result
|
|
591
|
+
* @return new query with limit operation
|
|
592
|
+
*/
|
|
593
|
+
limit(max: number, offset?: number): Query<T, R>;
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* Sort the result tuples according to a property of a data type with a specified order.
|
|
597
|
+
**
|
|
598
|
+
* For the sortBy operator to be properly defined, the following must be true:
|
|
599
|
+
* - the property is defined on the instances that will be used for sorting.
|
|
600
|
+
* - the instances on which the sorting property is defined must be part of the result,
|
|
601
|
+
* i.e., `andReturn()` has been called before `sortBy()`.
|
|
602
|
+
*
|
|
603
|
+
* Only the last call to `sortBy` matters as it will be the last comparator set on the query.
|
|
604
|
+
* You should remove previous calls to `sortBy` for the same query.
|
|
605
|
+
*
|
|
606
|
+
* Example :
|
|
607
|
+
* ```javascript
|
|
608
|
+
* const sortQuery = Query
|
|
609
|
+
* .fromInstances(myModel1).andReturn()
|
|
610
|
+
* .sortBy(nameProperty)
|
|
611
|
+
* .follow(rel1).andReturn()
|
|
612
|
+
* .execute();
|
|
613
|
+
* ```
|
|
614
|
+
* This query fetches instances of a model, flags them as first element of result tuples.
|
|
615
|
+
* Then the query follows a relation to other instances and return them as second element of the result tuples.
|
|
616
|
+
* `sortBy` will sort the results according to the `nameProperty` of the first element in the result tuples in
|
|
617
|
+
* ascending order.
|
|
618
|
+
*
|
|
619
|
+
* @param property the property used for sorting
|
|
620
|
+
* @param order optional {@link Order.ASC} (default) or {@link Order.DESC} order
|
|
621
|
+
* @return new query with sort operation
|
|
622
|
+
*/
|
|
623
|
+
sortBy(property: Property<any>, order?: Order): Query<T, R>;
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* @return the query transformed as a tree of QueryPart. To be used by Data Source.
|
|
627
|
+
*/
|
|
628
|
+
parse(): RootQueryPart;
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* Execute the query asynchronously on the datacloud and deletes it afterward.
|
|
632
|
+
* In other words, one cannot call execute twice on the same `Query`.
|
|
633
|
+
*
|
|
634
|
+
* @param options options
|
|
635
|
+
* @return promise resolving to query result or failing otherwise.
|
|
636
|
+
*/
|
|
637
|
+
execute(options?: QueryOptions): Promise<QueryResult<R extends never ? T : R extends CloudObject | CloudObject[] ? R : never>>;
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* Get an observable to the current value of the QueryResult for this Query instance.
|
|
641
|
+
*
|
|
642
|
+
* The observable gets the new value each time data modification in the datacloud changes the result of the query.
|
|
643
|
+
*
|
|
644
|
+
* The observable gets completed automatically once the specified context is {@link Context.onClear | cleared}.
|
|
645
|
+
*
|
|
646
|
+
* @param context {@link Context} to which the Observable is attached
|
|
647
|
+
* @param options options
|
|
648
|
+
* @return Observable of QueryResult values
|
|
649
|
+
*/
|
|
650
|
+
observe(context: Context, options?: QueryOptions): Observable<QueryResult<R extends never ? T : R extends CloudObject | CloudObject[] ? R : never>>;
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* Execute synchronously the query on the local datacloud cache.
|
|
654
|
+
* `executeFromCache` can only be called once on a given `Query`.
|
|
655
|
+
*
|
|
656
|
+
* @return query result of the execution on the local cache
|
|
657
|
+
*/
|
|
658
|
+
executeFromCache(): QueryResult<R extends never ? T : R extends CloudObject | CloudObject[] ? R : never>;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* A QuerySingle is a Query which follows relations that should be unique between data types (0..1 and 1..1 cardinalities).
|
|
664
|
+
* It returns the instance related to the origin, following the specified relation(s).
|
|
665
|
+
*
|
|
666
|
+
* It acts as a syntactic sugar to avoid having a query result structure and get the first value out of it.
|
|
667
|
+
*
|
|
668
|
+
* A QuerySingle is immutable.
|
|
669
|
+
*/
|
|
670
|
+
export class QuerySingle<T extends CloudObject> {
|
|
671
|
+
/**
|
|
672
|
+
* Create a `query single` from a single node.
|
|
673
|
+
* See {@link Query.from}
|
|
674
|
+
*
|
|
675
|
+
* @param object starting node for the graph query single
|
|
676
|
+
* @return new query single only accepting 0..1 relations
|
|
677
|
+
*/
|
|
678
|
+
static from<T extends CloudObject>(object: InstanceOrTag): QuerySingle<T>;
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* Follow a 0..1 relation
|
|
682
|
+
* See {@link Query.follow | Query.follow()}
|
|
683
|
+
*
|
|
684
|
+
* @param relation relation to next node
|
|
685
|
+
* @return new query single with follow operation
|
|
686
|
+
*/
|
|
687
|
+
follow<D extends CloudObject>(relation: Relation<T, D>): QuerySingle<D>;
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* See {@link Query.cast | Query.cast()}
|
|
691
|
+
*
|
|
692
|
+
* @param type the new type
|
|
693
|
+
* @return query single on a node of the specified type
|
|
694
|
+
*/
|
|
695
|
+
cast<S extends CloudObject>(type: Class<S>): QuerySingle<S>;
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* Execute the query single, see {@link Query.execute | Query.execute()}
|
|
699
|
+
*
|
|
700
|
+
* @return promise containing the single result or `null`
|
|
701
|
+
*/
|
|
702
|
+
execute(): Promise<T | null>;
|
|
703
|
+
|
|
704
|
+
/**
|
|
705
|
+
* Execute the query single on the local data cloud,
|
|
706
|
+
* see {@link Query.executeFromCache | Query.executeFromCache()}
|
|
707
|
+
*
|
|
708
|
+
* @return single result value or `null`
|
|
709
|
+
*/
|
|
710
|
+
executeFromCache(): T | null;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* The sorting order for a {@link QueryPart}.
|
|
715
|
+
*/
|
|
716
|
+
export enum Order {
|
|
717
|
+
/**
|
|
718
|
+
* Ascending order.
|
|
719
|
+
*/
|
|
720
|
+
ASC,
|
|
721
|
+
/**
|
|
722
|
+
* Descending order.
|
|
723
|
+
*/
|
|
724
|
+
DESC
|
|
725
|
+
}
|
|
726
|
+
|