@olympeio/runtime-node 9.0.2 → 9.0.3
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/05_permission_schema.updateInst.json +1 -1
- package/import/olympe.dm/datamodel/06_structure.newInst.json +1 -1
- package/import/olympe.sc/datamodel/01_language.newInst.json +1 -1
- package/package.json +1 -1
- package/types/base.d.ts +316 -8
- package/types/cloud.d.ts +883 -34
package/types/cloud.d.ts
CHANGED
|
@@ -7,60 +7,173 @@
|
|
|
7
7
|
// @ts-ignore
|
|
8
8
|
import Observable from 'rxjs';
|
|
9
9
|
import {Context, CloudObject, Relation, Property, Tag, Class} from "./base";
|
|
10
|
-
import {
|
|
10
|
+
import {BrickContext} from './runtime';
|
|
11
11
|
import {Color} from "./utils";
|
|
12
12
|
|
|
13
13
|
// --------------------------
|
|
14
14
|
// -- Primitive data types --
|
|
15
15
|
// --------------------------
|
|
16
|
+
/**
|
|
17
|
+
* A property model defines a property of a data type.
|
|
18
|
+
* A property is defined by its type and the model it defines a property for.
|
|
19
|
+
* */
|
|
16
20
|
export class PropertyModel extends CloudObject {
|
|
21
|
+
/**
|
|
22
|
+
* Relation from the property model to the data type (model)
|
|
23
|
+
* to which that property is attached.
|
|
24
|
+
*
|
|
25
|
+
* Example:
|
|
26
|
+
*
|
|
27
|
+
* ` myNumberPropertyModel --definingModelRel-> myDataTypeObject`
|
|
28
|
+
*/
|
|
17
29
|
static definingModelRel: Relation<PropertyModel, CloudObject>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Relation from the `PropertyModel` to its type.
|
|
33
|
+
*
|
|
34
|
+
* Example :
|
|
35
|
+
*
|
|
36
|
+
* `myNumberPropertyModel --typeRel-> Number`
|
|
37
|
+
*/
|
|
18
38
|
static typeRel: Relation<PropertyModel, CloudObject>;
|
|
19
39
|
}
|
|
20
40
|
|
|
41
|
+
/**
|
|
42
|
+
* A relation model defines a relation between two data types.
|
|
43
|
+
* It defines what data types is the origin and the destination of the relation.
|
|
44
|
+
*
|
|
45
|
+
* It also defines follow rules properties on the relation.
|
|
46
|
+
* */
|
|
21
47
|
export class RelationModel extends CloudObject {
|
|
48
|
+
/**
|
|
49
|
+
* Relation from the origin data type to the RelationModel
|
|
50
|
+
* */
|
|
22
51
|
static originModelRel: Relation<CloudObject, RelationModel>;
|
|
52
|
+
/**
|
|
53
|
+
* Relation from a RelationModel to the destination data type
|
|
54
|
+
* */
|
|
23
55
|
static destinationModelRel: Relation<RelationModel, CloudObject>;
|
|
56
|
+
/**
|
|
57
|
+
* Property for the *dump* follow rule
|
|
58
|
+
*/
|
|
24
59
|
static dumpFollowRuleProp: Property<number>;
|
|
60
|
+
/**
|
|
61
|
+
* Property for the *delete* follow rule
|
|
62
|
+
*/
|
|
25
63
|
static deleteFollowRuleProp: Property<number>;
|
|
64
|
+
/**
|
|
65
|
+
* Property for the *runtime* follow rule
|
|
66
|
+
*/
|
|
26
67
|
static runtimeFollowRuleProp: Property<number>;
|
|
27
68
|
}
|
|
28
69
|
|
|
70
|
+
/**
|
|
71
|
+
* StringModel represents a {@link PropertyModel} for a string property of a data type.
|
|
72
|
+
*/
|
|
29
73
|
export class StringModel extends CloudObject {
|
|
30
74
|
static valueProp: Property<string>;
|
|
31
75
|
}
|
|
32
76
|
|
|
77
|
+
/**
|
|
78
|
+
* NumberModel represents a {@link PropertyModel} for a number property of a data type.
|
|
79
|
+
*/
|
|
33
80
|
export class NumberModel extends CloudObject {
|
|
34
81
|
static valueProp: Property<number>;
|
|
35
82
|
}
|
|
36
83
|
|
|
84
|
+
/**
|
|
85
|
+
* BooleanModel represents a {@link PropertyModel} for a boolean property of a data type.
|
|
86
|
+
*/
|
|
37
87
|
export class BooleanModel extends CloudObject {
|
|
38
88
|
static valueProp: Property<boolean>;
|
|
39
89
|
}
|
|
40
90
|
|
|
91
|
+
/**
|
|
92
|
+
* DatetimeModel represents a {@link PropertyModel} for a datetime property of a data type.
|
|
93
|
+
*/
|
|
41
94
|
export class DatetimeModel extends CloudObject {
|
|
42
95
|
static valueProp: Property<Date>;
|
|
43
96
|
}
|
|
44
97
|
|
|
98
|
+
/**
|
|
99
|
+
* ColorModel represents a {@link PropertyModel} for a color property of a data type.
|
|
100
|
+
*/
|
|
45
101
|
export class ColorModel extends CloudObject {
|
|
46
102
|
static valueProp: Property<Color>;
|
|
47
103
|
}
|
|
48
104
|
|
|
105
|
+
/**
|
|
106
|
+
* File with content as binary or string data
|
|
107
|
+
*/
|
|
49
108
|
export class File extends CloudObject {
|
|
109
|
+
|
|
50
110
|
static nameProp: Property<string>;
|
|
51
111
|
static creationDateProp: Property<Date>;
|
|
52
112
|
static modificationDateProp: Property<Date>;
|
|
53
113
|
static mimeTypeProp: Property<string>;
|
|
54
114
|
static urlProp: Property<string>;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Create a `File` from its content
|
|
118
|
+
*
|
|
119
|
+
* @param transaction transaction in which to create the file
|
|
120
|
+
* @param name filename
|
|
121
|
+
* @param content byte content of the file
|
|
122
|
+
* @param mimeType optional mime type of the file
|
|
123
|
+
* @param source optional source where file will be stored ('server', 'self' or DBConnector tag)
|
|
124
|
+
* @param tag optional tag for the file
|
|
125
|
+
* @return tag string of the file
|
|
126
|
+
*/
|
|
55
127
|
static createFromContent(transaction: Transaction, name: string, content: ArrayBuffer, mimeType?: string, source?: string, tag?: string): string;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Create a `File` from a specified URL
|
|
131
|
+
*
|
|
132
|
+
* @param transaction transaction in which to create the file
|
|
133
|
+
* @param name filename
|
|
134
|
+
* @param url url to retrieve content from
|
|
135
|
+
* @param mimeType optional mime type of the file
|
|
136
|
+
* @param source optional source where file will be stored ('server', 'self' or DBConnector tag)
|
|
137
|
+
* @param tag optional tag for the file
|
|
138
|
+
* @return tag string of the file
|
|
139
|
+
*/
|
|
56
140
|
static createFromURL(transaction: Transaction, name: string, url: string, mimeType?: string, source?: string, tag?: string): string;
|
|
57
141
|
|
|
142
|
+
/**
|
|
143
|
+
* Retrieve content from this file asynchronously
|
|
144
|
+
*
|
|
145
|
+
* @param onSuccess callback to execute when byte content has been retrieved successfully
|
|
146
|
+
* @param onFailure callback to execute when content retrieval has failed
|
|
147
|
+
*/
|
|
58
148
|
getContentAsBinary(onSuccess: (content: ArrayBuffer) => void, onFailure?: (string) => void): void;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Retrieve string content from this file asynchronously
|
|
152
|
+
*
|
|
153
|
+
* @param onSuccess callback to execute when string content has been retrieved successfully
|
|
154
|
+
* @param onFailure callback to execute when content retrieval has failed
|
|
155
|
+
*/
|
|
59
156
|
getContentAsString(onSuccess: (content: string) => void, onFailure?: (string) => void): void;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Retrieve string content from URL asynchronously
|
|
160
|
+
*
|
|
161
|
+
* @param onSuccess callback to execute when content has been retrieved successfully
|
|
162
|
+
* @param onFailure callback to execute when content retrieval has failed
|
|
163
|
+
*/
|
|
60
164
|
getContentUrl(onSuccess: (content: string) => void, onFailure?: () => void): void;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Save this file with specified name
|
|
168
|
+
*
|
|
169
|
+
* @param name filename
|
|
170
|
+
*/
|
|
61
171
|
saveAs(name: string): void;
|
|
62
172
|
}
|
|
63
173
|
|
|
174
|
+
/**
|
|
175
|
+
* User object for authentication purposes
|
|
176
|
+
*/
|
|
64
177
|
export class User extends CloudObject {
|
|
65
178
|
static loginProp: Property<string>;
|
|
66
179
|
static saltProp: Property<string>;
|
|
@@ -68,16 +181,56 @@ export class User extends CloudObject {
|
|
|
68
181
|
static SAMLNameIdProp: Property<string>;
|
|
69
182
|
}
|
|
70
183
|
|
|
184
|
+
/**
|
|
185
|
+
* An Enum is an ordered list of string key-values mappings
|
|
186
|
+
*/
|
|
71
187
|
export class Enum extends CloudObject {
|
|
188
|
+
/**
|
|
189
|
+
* Create an empty `Enum?` without any value
|
|
190
|
+
*
|
|
191
|
+
* See {@link EnumValue#createValue} to create values for an Enum.
|
|
192
|
+
*
|
|
193
|
+
* @param transaction transaction in which to create the Enum
|
|
194
|
+
* @param name optional name of the Enum
|
|
195
|
+
* @return string tag of the Enum object
|
|
196
|
+
*/
|
|
72
197
|
create(transaction: Transaction, name?: string): string;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Get the values defined for this `Enum`
|
|
201
|
+
*/
|
|
73
202
|
getValues(): QueryResult<EnumValue>;
|
|
74
203
|
}
|
|
75
204
|
|
|
205
|
+
/**
|
|
206
|
+
* An `EnumValue` is a single value part of an `Enum`.
|
|
207
|
+
* It has a `string` name, a rank (its position in the Enum list).
|
|
208
|
+
*
|
|
209
|
+
* The values for `EnumValue` are always stringified.
|
|
210
|
+
*/
|
|
76
211
|
export class EnumValue extends CloudObject {
|
|
212
|
+
/**
|
|
213
|
+
* Add a `EnumValue` to a specified `Enum`
|
|
214
|
+
*
|
|
215
|
+
* @param transaction transaction in which to add the EnumValue to the Enum
|
|
216
|
+
* @param enumModel `EnumModel` containing the specified `EnumValue`
|
|
217
|
+
* @param value value of the `EnumValue`
|
|
218
|
+
* @param name name of the `EnumValue`
|
|
219
|
+
* @param rank position of the `EnumValue` in the `Enum`
|
|
220
|
+
*/
|
|
77
221
|
static createValue(transaction: Transaction, enumModel: Tag, value: string, name?: string, rank?: number): string;
|
|
78
222
|
|
|
223
|
+
/**
|
|
224
|
+
* Name property for an EnumValue
|
|
225
|
+
*/
|
|
79
226
|
static nameProp: Property<string>;
|
|
227
|
+
/**
|
|
228
|
+
* Value property for an EnumValue
|
|
229
|
+
*/
|
|
80
230
|
static valueProp: Property<string>;
|
|
231
|
+
/**
|
|
232
|
+
* Rank property for an EnumValue
|
|
233
|
+
*/
|
|
81
234
|
static rankProp: Property<number>;
|
|
82
235
|
}
|
|
83
236
|
|
|
@@ -87,7 +240,10 @@ export class EnumValue extends CloudObject {
|
|
|
87
240
|
|
|
88
241
|
/**
|
|
89
242
|
* Transactions are the unique way to apply a list of operations to the datacloud.
|
|
90
|
-
* A transaction can be merged into another transaction
|
|
243
|
+
* A transaction can be merged into another transaction so that both are executed as a single set of operations.
|
|
244
|
+
*
|
|
245
|
+
* All the operations for a transaction are executed atomically. Either all operations succeed, or none is applied.
|
|
246
|
+
*
|
|
91
247
|
*
|
|
92
248
|
* There are 5 types of basic operations :
|
|
93
249
|
* - Create instance: create a node in the database with specified properties.
|
|
@@ -96,51 +252,226 @@ export class EnumValue extends CloudObject {
|
|
|
96
252
|
* - Create relation: create a relation of a specific type between 2 existing node.
|
|
97
253
|
* - Delete relation: remove the specified relation between 2 specified nodes.
|
|
98
254
|
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
255
|
+
* In most cases, we apply the Transactions operations using the "execute()" method. The transaction size is limited but in real-time.
|
|
256
|
+
* It notifies observers of the data in real-time.
|
|
101
257
|
*
|
|
102
|
-
*
|
|
258
|
+
* Larger transactions with big set of operations (batch updates) must be executed using "executeAsLarge()" method. However no notification will be generated.
|
|
103
259
|
*
|
|
104
260
|
* Callbacks can be registered on transaction using "afterExecution()" method. They are executed once the transaction is applied.
|
|
105
261
|
*
|
|
262
|
+
* Example of transaction:
|
|
263
|
+
*
|
|
264
|
+
* ```javascript
|
|
265
|
+
* const tx = new Transaction(true);
|
|
266
|
+
* const myNewInstanceTag = tx.create(<myModelTag>);
|
|
267
|
+
* tx.update(myNewInstanceTag, <myPropertyTag>, <myPropertyValue>)
|
|
268
|
+
* .execute()
|
|
269
|
+
* .then(() => {
|
|
270
|
+
* // success tx case
|
|
271
|
+
* })
|
|
272
|
+
* .catch((err) => {
|
|
273
|
+
* // error during tx case
|
|
274
|
+
* })
|
|
275
|
+
* ```
|
|
276
|
+
*
|
|
106
277
|
* Concurrency transactions do not guarantee their execution order.
|
|
107
278
|
*/
|
|
108
279
|
export class Transaction {
|
|
109
280
|
constructor(persist?: boolean);
|
|
110
281
|
|
|
282
|
+
/**
|
|
283
|
+
* Get the transaction id attached to this transaction
|
|
284
|
+
* @return this transaction id
|
|
285
|
+
*/
|
|
111
286
|
getId(): string;
|
|
112
287
|
|
|
113
288
|
// Operations
|
|
289
|
+
/**
|
|
290
|
+
* Create a new instance.
|
|
291
|
+
*
|
|
292
|
+
* A custom map can specify property values for the instance.
|
|
293
|
+
*
|
|
294
|
+
* A source can be the orchestrator ('server'), local ('self') or
|
|
295
|
+
* an external data source ('<DBConnectorTag>'). The source is where
|
|
296
|
+
* the object is persisted and its true value outside local scopes.
|
|
297
|
+
*
|
|
298
|
+
* @param model tag of the model of the instance to be created
|
|
299
|
+
* @param properties custom map from tag to their value for properties of the instance to be created
|
|
300
|
+
* @param source optional source of the instance
|
|
301
|
+
* @param tag optional tag of the instance to be created and must be unique
|
|
302
|
+
* @return the tag of the instance to be created
|
|
303
|
+
*/
|
|
114
304
|
create(model: Tag, properties?: Map<Tag, any>, source?: string, tag?: string): string;
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Update the property of an instance
|
|
308
|
+
*
|
|
309
|
+
* @param instance tag of the instance to be updated
|
|
310
|
+
* @param property the property to be updated
|
|
311
|
+
* @param value the value of the property to be updated to
|
|
312
|
+
* @return this transaction
|
|
313
|
+
*/
|
|
115
314
|
update<T>(instance: Tag, property?: Property<T>, value?: T): this;
|
|
116
|
-
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Update multiple properties of a single instance
|
|
318
|
+
*
|
|
319
|
+
* @param instance tag of the instance to be updated
|
|
320
|
+
* @param properties (<propertyTag>, <propertyValue>) map to update properties
|
|
321
|
+
* @return this transaction
|
|
322
|
+
*/
|
|
323
|
+
multiUpdate(instance: Tag, properties: Map<Tag, any>): this;
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Delete an instance
|
|
327
|
+
*
|
|
328
|
+
* @param instance tag of the instance to be deleted
|
|
329
|
+
* @return this transaction
|
|
330
|
+
*/
|
|
117
331
|
delete(instance: Tag): this;
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Create relation between two instances
|
|
335
|
+
*
|
|
336
|
+
* @param relation tag of the relation to be created
|
|
337
|
+
* @param from tag of the ORIGIN instance of the relation
|
|
338
|
+
* @param to tag ofo the DESTINATION instance of the relation
|
|
339
|
+
* @return this transaction with the create relation operation registered
|
|
340
|
+
*/
|
|
118
341
|
createRelation(relation: Tag, from: Tag, to: Tag): this;
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Delete a relation between two specified instances.
|
|
345
|
+
*
|
|
346
|
+
* The relation is only deleted for the relation parameter direction.
|
|
347
|
+
*
|
|
348
|
+
* @param relation tag of the relation to be deleted
|
|
349
|
+
* @param from origin instance tag
|
|
350
|
+
* @param to destination instance tag
|
|
351
|
+
* @return this transaction
|
|
352
|
+
*/
|
|
119
353
|
deleteRelation(relation: Tag, from: Tag, to: Tag): this;
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Delete any number of the relation starting from specified node.
|
|
357
|
+
*
|
|
358
|
+
* The specified node might be the origin or (exclusive) the destination of the relation.
|
|
359
|
+
*
|
|
360
|
+
* For the relations :
|
|
361
|
+
* ```
|
|
362
|
+
* - a - [rel1] -> b,
|
|
363
|
+
* - c - [inverseRel(rel1)] -> a,
|
|
364
|
+
* - a - [rel1] -> d,
|
|
365
|
+
* - a - [rel2] -> d
|
|
366
|
+
* ```
|
|
367
|
+
* `tx.deleteAllRelation(rel1, a)` will remove the first and third relations
|
|
368
|
+
*
|
|
369
|
+
* @param relation deleted relation, indicates relation tag *and* direction
|
|
370
|
+
* @param origin starting node
|
|
371
|
+
*/
|
|
120
372
|
deleteAllRelations(relation: Relation<any, any>, origin: Tag): this;
|
|
121
373
|
|
|
122
|
-
|
|
374
|
+
/**
|
|
375
|
+
* Change the persistence mode of all instances in this transaction
|
|
376
|
+
*
|
|
377
|
+
* @param persist whether instances are persisted outside
|
|
378
|
+
* the local datacloud
|
|
379
|
+
* @return this transaction
|
|
380
|
+
*/
|
|
123
381
|
persist(persist?: boolean): this;
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Change the persistence mode for a single instance in this transaction
|
|
385
|
+
*
|
|
386
|
+
* @param instance the instance to be persisted
|
|
387
|
+
* @param persist the persisting mode
|
|
388
|
+
* @return this transaction
|
|
389
|
+
*/
|
|
124
390
|
persistInstance(instance: Tag, persist?: boolean): this;
|
|
125
391
|
|
|
126
|
-
|
|
392
|
+
/**
|
|
393
|
+
* Change the source of all instances created in this transaction
|
|
394
|
+
*
|
|
395
|
+
* `source` can be specified as :
|
|
396
|
+
* 1. the orchestrator ('server'),
|
|
397
|
+
* 2. local ('self') or
|
|
398
|
+
* 3. an external data source ('<DBConnectorTag>')
|
|
399
|
+
*
|
|
400
|
+
* The source of a data object is where the object is persisted.
|
|
401
|
+
*
|
|
402
|
+
* By default, the `source` is the default source configured in the project.
|
|
403
|
+
*
|
|
404
|
+
* @param source the new source for instances
|
|
405
|
+
* @return this transaction
|
|
406
|
+
*/
|
|
127
407
|
setSource(source: string): this;
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Retrieve the tag of the model of the instance tag
|
|
411
|
+
* from the created instances in this transaction
|
|
412
|
+
* or from the local database.
|
|
413
|
+
*
|
|
414
|
+
* @param tag the instance to find the model of
|
|
415
|
+
* @return the tag of the model of the given instance
|
|
416
|
+
*/
|
|
128
417
|
model(tag: Tag): string;
|
|
129
418
|
|
|
419
|
+
/**
|
|
420
|
+
* Add all operations of another transaction into this transaction
|
|
421
|
+
*
|
|
422
|
+
* @param otherTransaction the other transaction to add operations from
|
|
423
|
+
* @return this transaction
|
|
424
|
+
*/
|
|
130
425
|
merge(otherTransaction: Transaction): this;
|
|
131
426
|
|
|
132
427
|
// Execution methods
|
|
428
|
+
/**
|
|
429
|
+
* Set a callback to be executed after all the operations
|
|
430
|
+
* in the transaction were executed successfully
|
|
431
|
+
*
|
|
432
|
+
* @param callback the callback to be executed
|
|
433
|
+
* @return this transaction
|
|
434
|
+
*/
|
|
133
435
|
afterExecution(callback: (success: boolean, message?: string) => void): this;
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Execute atomically the transaction at the source
|
|
439
|
+
*
|
|
440
|
+
* @return promise resolving if the transaction succeeds,
|
|
441
|
+
* rejecting if the transaction fails
|
|
442
|
+
*/
|
|
134
443
|
execute(): Promise<void>;
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Execute atomically a transaction at the source
|
|
447
|
+
* The `large` mode sends the transaction over HTTP
|
|
448
|
+
*
|
|
449
|
+
* @return promise resolving if the transaction succeeds,
|
|
450
|
+
* rejecting if the transaction fails.
|
|
451
|
+
*/
|
|
135
452
|
executeAsLarge(): Promise<void>;
|
|
136
453
|
|
|
137
|
-
|
|
454
|
+
/**
|
|
455
|
+
* Start a transaction using an existing transaction in the provided context
|
|
456
|
+
* or a new one if there is none.
|
|
457
|
+
*
|
|
458
|
+
* @param $ context in which the transaction executes
|
|
459
|
+
* @return transaction
|
|
460
|
+
*/
|
|
138
461
|
static from($: BrickContext): Transaction;
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Execute a given transaction if there is no open transaction in the context.
|
|
465
|
+
*
|
|
466
|
+
* @param $ context
|
|
467
|
+
* @param transaction transaction to process
|
|
468
|
+
* @return boolean indicating if the argument transaction has been processed
|
|
469
|
+
*/
|
|
139
470
|
static process($: BrickContext, transaction: Transaction): Promise<boolean>;
|
|
140
471
|
}
|
|
141
472
|
|
|
142
473
|
/**
|
|
143
|
-
* BurstTransactions are designed to apply
|
|
474
|
+
* BurstTransactions are designed to continuously apply high rates of updates on properties (FIFO ordering).
|
|
144
475
|
* The only operation supported by BurstTransactions is to update properties of an instance.
|
|
145
476
|
*
|
|
146
477
|
* Unlike classical Transactions, a burst transaction preserves the order of update operations and
|
|
@@ -153,10 +484,19 @@ export class Transaction {
|
|
|
153
484
|
export class BurstTransaction {
|
|
154
485
|
constructor();
|
|
155
486
|
|
|
156
|
-
|
|
487
|
+
/**
|
|
488
|
+
* Push all property values from specified Observable to update specified object
|
|
489
|
+
*
|
|
490
|
+
* @param object the object to update
|
|
491
|
+
* @param values observable of a `Map<Property<T>, T>` mapping properties to new values
|
|
492
|
+
*/
|
|
157
493
|
push<T>(object: CloudObject, values: Observable<Map<Property<T>, T>>): void;
|
|
158
494
|
|
|
159
|
-
|
|
495
|
+
/**
|
|
496
|
+
* Commit and close the burst transaction
|
|
497
|
+
*
|
|
498
|
+
* @return Promise<void> completing with commit success/failure
|
|
499
|
+
*/
|
|
160
500
|
complete(): Promise<void>;
|
|
161
501
|
}
|
|
162
502
|
|
|
@@ -166,65 +506,297 @@ export class BurstTransaction {
|
|
|
166
506
|
type Empty = [];
|
|
167
507
|
|
|
168
508
|
/**
|
|
169
|
-
* A
|
|
509
|
+
* A QueryResult is a list of key-value pairs that has been generated as a result of a `Query`.
|
|
510
|
+
* It contains the result of a query at a specific time.
|
|
170
511
|
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
512
|
+
* The keys are tags (e.g. `myTag`) that correspond to a `CloudObject` (e.g. `myCloudObject`).
|
|
513
|
+
* When the {@link Query} contains more than one [Query.andReturn()]{@link Query#andReturn} clause,
|
|
514
|
+
* keys are composite tags (e.g. `'tag1.tag2.tag3'`) and values are tuples of `CloudObjects` (e.g. `[cloudObj1, cloudObj2, cloudObj3]`).
|
|
515
|
+
* Such a QueryResult can be obtained via:
|
|
516
|
+
* ```javascript
|
|
517
|
+
* Query.instancesOf(myModel1).andReturn.follow(myRelation1).andReturn.follow(myRelation2).andReturn().execute().
|
|
518
|
+
* ```
|
|
173
519
|
*
|
|
174
|
-
*
|
|
520
|
+
* When a query is subscribed, the returned observable generates multiple QueryResults over time.
|
|
175
521
|
*
|
|
176
|
-
*
|
|
522
|
+
* A QueryResult can be easily manipulated and transformed to a standard Array.
|
|
177
523
|
*/
|
|
178
524
|
export class QueryResult<T> {
|
|
525
|
+
/**
|
|
526
|
+
*@return empty `QueryResult`
|
|
527
|
+
*/
|
|
179
528
|
static empty(): QueryResult<any>;
|
|
180
529
|
|
|
530
|
+
/**
|
|
531
|
+
* Symbol iterator for `for..in` syntactic sugar
|
|
532
|
+
*
|
|
533
|
+
* @return iterator over the key-values pairs of this `QueryResult`
|
|
534
|
+
*/
|
|
181
535
|
[Symbol.iterator](): IterableIterator<[string, T]>;
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Get an iterable iterator over the key-value pairs of this `QueryResult`
|
|
539
|
+
*
|
|
540
|
+
* @return iterator
|
|
541
|
+
*/
|
|
182
542
|
entries(): IterableIterator<[string, T]>;
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Get an iterable iterator over the values of this `QueryResult`
|
|
546
|
+
*
|
|
547
|
+
* @return iterator
|
|
548
|
+
*/
|
|
183
549
|
values(): IterableIterator<T>
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Get an iterable iterator over the keys of this `QueryResult`
|
|
553
|
+
*
|
|
554
|
+
* @return iterator
|
|
555
|
+
*/
|
|
184
556
|
keys(): IterableIterator<string>
|
|
185
557
|
|
|
558
|
+
/**
|
|
559
|
+
* Get an array containing the values of this `QueryResult`
|
|
560
|
+
*
|
|
561
|
+
* @return array of this `QueryResult`'s values
|
|
562
|
+
*/
|
|
186
563
|
toArray(): T[];
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* Get the number of key-value pairs this `QueryResult` contains
|
|
567
|
+
*
|
|
568
|
+
* @return size of this `QueryResult`
|
|
569
|
+
*/
|
|
187
570
|
size(): number;
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Check whether a key / value is contained in this `QueryResult`.
|
|
574
|
+
*
|
|
575
|
+
* Returns true if the cloud array contains an element with the specified key.
|
|
576
|
+
*
|
|
577
|
+
* If no corresponding key is found, returns true if the cloud array contains an element with the specified value.
|
|
578
|
+
*
|
|
579
|
+
* @param key the value to search for
|
|
580
|
+
* @return true if the value `key` is found
|
|
581
|
+
* @TODO why T, it's CloudObjects
|
|
582
|
+
*/
|
|
188
583
|
has(key: T | string): boolean;
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Get index of a value in the keys or values of this `QueryResult`.
|
|
587
|
+
*
|
|
588
|
+
* If the key is a string, retrieve the index from the `string` keys of this `QueryResult`.
|
|
589
|
+
*
|
|
590
|
+
* If the key is not a string, get the index from the `CloudObject` tuples
|
|
591
|
+
*
|
|
592
|
+
* @param key the value to find the index of
|
|
593
|
+
* @return index of the argument value or -1 if the value is not found
|
|
594
|
+
* TODO why T, it's CloudObjects
|
|
595
|
+
*/
|
|
189
596
|
indexOf(key: T | string): number;
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Get the value corresponding to a given key
|
|
600
|
+
*
|
|
601
|
+
* @param key tag or composite tag
|
|
602
|
+
* @return matching tuple or `null`
|
|
603
|
+
*/
|
|
190
604
|
get(key: string): T | null;
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Get the first value
|
|
608
|
+
*
|
|
609
|
+
* @return first value or `null` if empty
|
|
610
|
+
*/
|
|
191
611
|
getFirst(): T | null;
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* Get the value at the specified index
|
|
615
|
+
*
|
|
616
|
+
* @param index
|
|
617
|
+
* @return value at position `index` or `null` if index is out of bounds
|
|
618
|
+
*/
|
|
192
619
|
getAt(index: number): T | null;
|
|
193
620
|
|
|
621
|
+
/**
|
|
622
|
+
* Returns an array equivalent to [this.toArray().push(...object)]{@link toArray}
|
|
623
|
+
*
|
|
624
|
+
* This operation returns a new array and does not modify this QueryResult.
|
|
625
|
+
*
|
|
626
|
+
* @param object new values to push in the values array.
|
|
627
|
+
* @return new values array with new elements appended
|
|
628
|
+
*/
|
|
194
629
|
push(...object: T[]): T[];
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Returns the QueryResult values as an array whose last value has been removed.
|
|
633
|
+
*
|
|
634
|
+
* If [QueryResult.size()]{@link size} is 0 or 1, this method returns an empty array.
|
|
635
|
+
*
|
|
636
|
+
* This operation returns a new array and does not modify this QueryResult.
|
|
637
|
+
*
|
|
638
|
+
* @return new values array with last element removed
|
|
639
|
+
*/
|
|
195
640
|
pop(): T[];
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Returns the QueryResult values as an array whose first value has been removed.
|
|
644
|
+
*
|
|
645
|
+
* If [QueryResult.size()]{@link size} is 0 or 1, this method returns an empty array.
|
|
646
|
+
*
|
|
647
|
+
* This operation returns a new array and does not modify this QueryResult.
|
|
648
|
+
*
|
|
649
|
+
* @return new values array with first element removed
|
|
650
|
+
*/
|
|
196
651
|
shift(): T[];
|
|
197
652
|
|
|
198
|
-
|
|
653
|
+
/**
|
|
654
|
+
* Returns the new values added since the last `QueryResult` update.
|
|
655
|
+
* In other words, `getAdded` returns the new values that exists in this query result, but did not in the previous query result pushed by the Observable.
|
|
656
|
+
*
|
|
657
|
+
* This applies only when *observing* a [Query]{@link Query#observe}.
|
|
658
|
+
*
|
|
659
|
+
* @return values added
|
|
660
|
+
*/
|
|
199
661
|
getAdded(): T[];
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* Returns the keys of values removed since the last `QueryResult` update.
|
|
665
|
+
* In other words, `getRemoved` returns the old values that existed in the previous query result, but are no longer present in this query result pushed by the Observable.
|
|
666
|
+
*
|
|
667
|
+
* This applies only when *observing* a [Query]{@link Query#observe}.
|
|
668
|
+
*
|
|
669
|
+
* @return keys of the removed values
|
|
670
|
+
*/
|
|
200
671
|
getRemoved(): string[] | string[][];
|
|
201
672
|
|
|
673
|
+
/**
|
|
674
|
+
* Returns an array containing the values matching the provided filter predicate.
|
|
675
|
+
*
|
|
676
|
+
* @param predicate filter {@link Predicate}
|
|
677
|
+
* @return array of matching values
|
|
678
|
+
*/
|
|
202
679
|
filter(predicate: (entry: T) => boolean): T[];
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* Returns the first value matching the predicate, `null` otherwise.
|
|
683
|
+
*
|
|
684
|
+
* `find` calls `predicate` once for each element of the array until it returns true.
|
|
685
|
+
* If such an element is found, find immediately returns that element value.
|
|
686
|
+
*
|
|
687
|
+
* @param predicate
|
|
688
|
+
* @return the first value evaluating to true or `null`
|
|
689
|
+
*/
|
|
203
690
|
find(predicate: (entry: T) => boolean): T | null;
|
|
204
691
|
|
|
692
|
+
/**
|
|
693
|
+
* Execute the specified callback function for each value of this `QueryResult`
|
|
694
|
+
*
|
|
695
|
+
* @param callback
|
|
696
|
+
*/
|
|
205
697
|
forEach(callback: (entry: T) => void): void;
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* Execute the specified callback function for each value of this `QueryResult`.
|
|
701
|
+
* It returns a new array that contains the results of the callback execution.
|
|
702
|
+
*
|
|
703
|
+
* @param callback
|
|
704
|
+
* @return new array of transformed values
|
|
705
|
+
*/
|
|
206
706
|
map<S>(callback: (entry: T) => S): S[];
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* Return a sorted copy of this QueryResult.
|
|
710
|
+
*
|
|
711
|
+
* The specified `comparator` used to determine the order of the QueryResult key-value pairs.
|
|
712
|
+
* 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
|
|
713
|
+
* number otherwise.
|
|
714
|
+
*
|
|
715
|
+
* @param comparator comparator returning a negative, zero or positive number
|
|
716
|
+
* @return sorted copy of this QueryResult
|
|
717
|
+
*/
|
|
207
718
|
sort(comparator: (b1: T, b2: T) => number): QueryResult<T>;
|
|
719
|
+
|
|
720
|
+
/**
|
|
721
|
+
* Return a reduced value for this QueryResult.
|
|
722
|
+
*
|
|
723
|
+
* The specified `reducer` callback reduces the QueryResult values as [reduce]{@link Array#reduce}
|
|
724
|
+
*
|
|
725
|
+
* @param reducer callback
|
|
726
|
+
* @param initial initial value of the accumulator
|
|
727
|
+
* @return accumulated result applying the `reducer` function iteratively
|
|
728
|
+
*/
|
|
208
729
|
reduce<S>(reducer: (accumulator: S, entry: T) => S, initial: S): S;
|
|
730
|
+
|
|
731
|
+
/**
|
|
732
|
+
* Return a new QueryResult that contains the concatenation of two or more QueryResults.
|
|
733
|
+
*
|
|
734
|
+
* Concatenating two QueryResults results in a new QueryResult with the following:
|
|
735
|
+
*
|
|
736
|
+
* - the keys of the QueryResults are concatenated
|
|
737
|
+
* - the values of the QueryResults are concatenated
|
|
738
|
+
* - the arrays returned by {@link getAdded} are concatenated
|
|
739
|
+
* - the arrays returned by {@link getRemoved} are concatenated
|
|
740
|
+
*
|
|
741
|
+
* Example : ```javascript
|
|
742
|
+
* const result1 = Query.fromInstances(myModel1).executeFromCache();
|
|
743
|
+
* // result1 is {tag1: cloudObj1, tag2: cloudObj2}
|
|
744
|
+
* const result2 = Query.fromInstances(myModel2).executeFromCache();
|
|
745
|
+
* // result2 is {tag3: cloudObj3}
|
|
746
|
+
* const concatenatedResult = result2.concat(result1);
|
|
747
|
+
* // concatenatedResult is {tag3: cloudObj3, tag1: cloudObj1, tag2: cloudObj2}
|
|
748
|
+
* ```
|
|
749
|
+
*
|
|
750
|
+
* @param others QueryResults to append to this `QueryResult`
|
|
751
|
+
* @return concatenated query results
|
|
752
|
+
*/
|
|
209
753
|
concat(...others: QueryResult<T>[]): QueryResult<T>;
|
|
210
754
|
}
|
|
211
755
|
|
|
212
756
|
/**
|
|
213
757
|
* A Query is an immutable object used to build queries on the datacloud. It is a graph query builder.
|
|
214
|
-
*
|
|
758
|
+
* It starts from an `origin` Tag (typically, the `Tag` of a data type or of an instance).
|
|
759
|
+
* From there, it can follow relations between data types and filter results.
|
|
215
760
|
*
|
|
216
|
-
*
|
|
761
|
+
* Example:
|
|
762
|
+
*
|
|
763
|
+
* `origin --a--> X --b--> Y --c--> Z`
|
|
217
764
|
*
|
|
218
|
-
* At each level, "andReturn()" method can be called to add the current level to the result.
|
|
219
765
|
* Example:
|
|
220
766
|
*
|
|
767
|
+
* ```javascript
|
|
768
|
+
* Query.from(origin)
|
|
769
|
+
* .follow(a)
|
|
770
|
+
* .execute();
|
|
771
|
+
* ```
|
|
772
|
+
* This will return a Promise of a QueryResult whose values are of type X: `Promise<QueryResult<X>>`.
|
|
773
|
+
*
|
|
774
|
+
* A query defines a starting working set of nodes and operations that will mutate it.
|
|
775
|
+
* From our example,the working set is first the `origin` graph node. Then the `follow`
|
|
776
|
+
* operations create a new working set only containing the nodes related to the origin through relation *`a`*.
|
|
777
|
+
*
|
|
778
|
+
* Multiple relations can be followed at once to create the equivalent of JOIN operations in relational databases.
|
|
779
|
+
* ```javascript
|
|
221
780
|
* Query.from(origin)
|
|
222
781
|
* .follow(a).andReturn()
|
|
223
782
|
* .follow(b)
|
|
224
783
|
* .follow(c).andReturn()
|
|
225
784
|
* .execute();
|
|
785
|
+
* ```
|
|
786
|
+
* The next operation defines a working set containing the nodes related
|
|
787
|
+
* through relation *`b`* to nodes that are related through relation *`a`* to the origin.
|
|
788
|
+
* A similar operation is defined for relation `c`.
|
|
789
|
+
* At each level, "andReturn()" method can be called to add the current level to the result.
|
|
790
|
+
* This will return a Promise of a QueryResult whose values are of type [X, Z]: `Promise<QueryResult<[X, Z]>>`.
|
|
791
|
+
*
|
|
792
|
+
* Out of the 4 working sets created, only the second and fourth are flagged to be returned and part of the result.
|
|
793
|
+
* But the operations in the middle impact this result: e.g.,
|
|
794
|
+
* all returned tuples (t1, t2) are object that have an intermediate `i` of type Y.
|
|
795
|
+
* such that `t1 --b-> i --c-> t2` but the `i` was not flagged to be returned.
|
|
796
|
+
*
|
|
797
|
+
* Queries define a path from a starting point following a specific list of relations.
|
|
798
|
+
* As explained with our example, only nodes part of a full path can be returned.
|
|
226
799
|
*
|
|
227
|
-
* This will return a Promise of a of tuple [X, Z]: Promise<CloudArray<[X, Z]>>.
|
|
228
800
|
*
|
|
229
801
|
* A query can be executed with 3 different ways:
|
|
230
802
|
* - execute(): it runs the query on the datacloud and return the result as a QueryResult.
|
|
@@ -232,68 +804,345 @@ export class QueryResult<T> {
|
|
|
232
804
|
* - 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.
|
|
233
805
|
*/
|
|
234
806
|
export class Query<T extends CloudObject, R extends any[]> {
|
|
807
|
+
|
|
808
|
+
/**
|
|
809
|
+
* Create a query starting from the `CloudObject` specified tag
|
|
810
|
+
*
|
|
811
|
+
* @param tag tag of the `CloudObject` the query is starting from
|
|
812
|
+
* @return an empty Query whose starting point is defined by a single `CloudObject`
|
|
813
|
+
*/
|
|
235
814
|
static from<T extends CloudObject>(tag: Tag): Query<T, Empty>;
|
|
236
|
-
static instancesOf<T extends CloudObject>(model: Class<T>, source?: string): Query<T, Empty>;
|
|
237
815
|
|
|
238
|
-
|
|
816
|
+
/**
|
|
817
|
+
* Create a query starting from the instances of the specified model
|
|
818
|
+
*
|
|
819
|
+
* @param model tag/class of the model to find the instances of
|
|
820
|
+
* @param source optional source of the data to answer the query
|
|
821
|
+
* A source can be the orchestrator ('server'), local ('self') or
|
|
822
|
+
* an external data source ('<DBConnectorTag>')
|
|
823
|
+
* @return a new query object starting from model instances
|
|
824
|
+
*/
|
|
825
|
+
static instancesOf<T extends CloudObject>(model: Tag, source?: string): Query<T, Empty>;
|
|
826
|
+
|
|
827
|
+
/**
|
|
828
|
+
* Instruct the query to follow a specified relation. This does not add any key-value pair to the result.
|
|
829
|
+
* (see {@link andReturn}). This operation defines a new step in the path defined by our graph query.
|
|
830
|
+
*
|
|
831
|
+
* Example:
|
|
832
|
+
* Find the model of a single object.
|
|
833
|
+
* ```javascript
|
|
834
|
+
* Query.from(myTag).follow(CloudObject.modelRel).andReturn()
|
|
835
|
+
* ```
|
|
836
|
+
*
|
|
837
|
+
* @param relation relation to follow, specifies type and direction
|
|
838
|
+
* @return a new query object
|
|
839
|
+
*/
|
|
840
|
+
follow<D extends CloudObject>(relation: Relation<T, D>): Query<D, R>;
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* Follow a relation recursively, see {@link follow}.
|
|
844
|
+
* The relation that is followed is automatically recursively followed.
|
|
845
|
+
* All nodes that are recursively followed are part of the same step in the path defined by this graph query.
|
|
846
|
+
*
|
|
847
|
+
* @param relation relation to follow recursively, specifies type and direction
|
|
848
|
+
* @param includeSelf if a starting node includes itself when the relation loops on itself
|
|
849
|
+
* @return a new query object
|
|
850
|
+
*/
|
|
239
851
|
followRecursively<D extends CloudObject>(relation: Relation<T, D>, includeSelf?: boolean): Query<D, R>;
|
|
240
852
|
|
|
241
|
-
|
|
853
|
+
/**
|
|
854
|
+
* Add the current working set of nodes to the result.
|
|
855
|
+
*
|
|
856
|
+
* Example:
|
|
857
|
+
* Query returning the instances of a model and the model itself
|
|
858
|
+
* ```javascript
|
|
859
|
+
* Query
|
|
860
|
+
* .from(myModelTag).andReturn()
|
|
861
|
+
* .follow(CloudObject.modelRel.getInverse()).andReturn()
|
|
862
|
+
* .execute();
|
|
863
|
+
* ```
|
|
864
|
+
* The result tuples are [modelCloudObject, instance1], [modelCloudObject, instance2], ...
|
|
865
|
+
*
|
|
866
|
+
* @return a new query object with the current level flagged to be returned.
|
|
867
|
+
*/
|
|
868
|
+
andReturn(): Query<T, [...R, T]>;
|
|
242
869
|
|
|
870
|
+
/**
|
|
871
|
+
* Define a filter operation on the current working set of nodes.
|
|
872
|
+
* It filters out instances that don't match the given {@link Predicate}
|
|
873
|
+
*
|
|
874
|
+
* @param predicate
|
|
875
|
+
* @return a new query object with the new filter operation
|
|
876
|
+
*/
|
|
243
877
|
filter(predicate: Predicate): Query<T, R>;
|
|
878
|
+
|
|
879
|
+
/**
|
|
880
|
+
* Cast the type of the instances in the current working set of nodes
|
|
881
|
+
*
|
|
882
|
+
* @param type cast type for `CloudObjects`
|
|
883
|
+
* @return the
|
|
884
|
+
*/
|
|
244
885
|
cast<S extends CloudObject>(type: Class<S>): Query<S, R>;
|
|
245
886
|
|
|
246
|
-
|
|
887
|
+
/**
|
|
888
|
+
* Set the maximum number of tuples the executed query will return with an optional offset.
|
|
889
|
+
*
|
|
890
|
+
* Only the last call to limit matters.
|
|
891
|
+
*
|
|
892
|
+
* Example :
|
|
893
|
+
* ```javascript
|
|
894
|
+
* const queryLimited = query.limit(50).follow(myRel2).limit(100, 200).follow(myRel1);
|
|
895
|
+
* // is equivalent to
|
|
896
|
+
* const queryLimited2 = query.follow(myRel2).follow(myRel1).limit(100, 200);
|
|
897
|
+
* ```
|
|
898
|
+
* `queryLimited`, when executed, will return at most the 200th to the 299th (included) results.
|
|
899
|
+
*
|
|
900
|
+
* @param max maximum number of tuple to fetch from the final result
|
|
901
|
+
* @param offset number of skipped tuples for the final result
|
|
902
|
+
* @return new query with limit operation
|
|
903
|
+
*/
|
|
247
904
|
limit(max: number, offset?: number): Query<T, R>;
|
|
905
|
+
|
|
906
|
+
/**
|
|
907
|
+
* Sort the result tuples according to a property of a data type with a specified order.
|
|
908
|
+
**
|
|
909
|
+
* For the sortBy operator to be properly defined, the following must be true:
|
|
910
|
+
* - the property is defined on the instances that will be used for sorting.
|
|
911
|
+
* - the instances on which the sorting property is defined must be part of the result,
|
|
912
|
+
* i.e., `andReturn()` has been called before `sortBy()`.
|
|
913
|
+
*
|
|
914
|
+
* Only the last call to `sortBy` matters as it will be the last comparator set on the query.
|
|
915
|
+
* You should remove previous calls to `sortBy` for the same query.
|
|
916
|
+
*
|
|
917
|
+
* Example :
|
|
918
|
+
* ```javascript
|
|
919
|
+
* const sortQuery = Query
|
|
920
|
+
* .fromInstances(myModel1).andReturn()
|
|
921
|
+
* .sortBy(nameProperty)
|
|
922
|
+
* .follow(rel1).andReturn()
|
|
923
|
+
* .execute();
|
|
924
|
+
* ```
|
|
925
|
+
* This query fetches instances of a model, flags them as first element of result tuples.
|
|
926
|
+
* Then the query follows a relation to other instances and return them as second element of the result tuples.
|
|
927
|
+
* `sortBy` will sort the results according to the `nameProperty` of the first element in the result tuples in
|
|
928
|
+
* ascending order.
|
|
929
|
+
*
|
|
930
|
+
* @param property the property used for sorting
|
|
931
|
+
* @param order optional [Order.ASC]{@link Order#ASC} (default) or [Order.DESC]{@link Order#DESC} order
|
|
932
|
+
* @return new query with sort operation
|
|
933
|
+
*/
|
|
248
934
|
sortBy(property: Property<any>, order?: Order): Query<T, R>;
|
|
249
935
|
|
|
250
|
-
|
|
251
|
-
|
|
936
|
+
/**
|
|
937
|
+
* Execute the query asynchronously on the datacloud and deletes it afterwards.
|
|
938
|
+
* In other words, one cannot call execute twice on the same `Query`.
|
|
939
|
+
*
|
|
940
|
+
* @param context context in which the query must be executed. As this is an asynchronous operation,
|
|
941
|
+
* one has to provide a context that won't be destroyed before the query has a result.
|
|
942
|
+
* @return promise resolving to query result or failing otherwise.
|
|
943
|
+
*/
|
|
944
|
+
execute(context: Context): Promise<QueryResult<R>>;
|
|
945
|
+
|
|
946
|
+
/**
|
|
947
|
+
* Get an observable to the current value of the QueryResult for this Query instance.
|
|
948
|
+
*
|
|
949
|
+
* The observable gets the new value each time data modification in the datacloud changes the result of the query.
|
|
950
|
+
*
|
|
951
|
+
* The observable gets completed automatically once the specified context is [cleared]{@link Context#onClear}.
|
|
952
|
+
*
|
|
953
|
+
* @param context [context]{@link Context} to which the Observable is attached
|
|
954
|
+
* @return Observable of QueryResult values
|
|
955
|
+
*/
|
|
956
|
+
observe(context: Context): Observable<QueryResult<R>>;
|
|
252
957
|
|
|
253
|
-
|
|
958
|
+
/**
|
|
959
|
+
* Execute synchronously the query on the local datacloud cache.
|
|
960
|
+
* `executeFromCache` can only be called once on a given `Query`.
|
|
961
|
+
*
|
|
962
|
+
* @return query result of the execution on the local cache
|
|
963
|
+
*/
|
|
964
|
+
executeFromCache(): QueryResult<R>;
|
|
254
965
|
}
|
|
255
966
|
|
|
256
967
|
/**
|
|
257
|
-
* A QuerySingle is a Query which follows relations that should be unique between
|
|
258
|
-
* It returns the
|
|
968
|
+
* A QuerySingle is a Query which follows relations that should be unique between data types (0..1 and 1..1 cardinalities).
|
|
969
|
+
* It returns the instance related to the origin, following the specified relation(s).
|
|
259
970
|
*
|
|
260
|
-
* It acts as a syntactic sugar to avoid having a
|
|
971
|
+
* It acts as a syntactic sugar to avoid having a query result structure and get the first value out of it.
|
|
261
972
|
*
|
|
262
973
|
* A QuerySingle is immutable.
|
|
263
974
|
*/
|
|
264
975
|
export class QuerySingle<T extends CloudObject> {
|
|
976
|
+
/**
|
|
977
|
+
* Create a `query single` from a single node.
|
|
978
|
+
* See [Query.from]{@link Query#from}
|
|
979
|
+
*
|
|
980
|
+
* @param object starting node for the graph query single
|
|
981
|
+
* @return new query single only accepting 0..1 relations
|
|
982
|
+
*/
|
|
265
983
|
static from<T extends CloudObject>(object: Tag): QuerySingle<T>;
|
|
266
984
|
|
|
985
|
+
/**
|
|
986
|
+
* Follow a 0..1 relation
|
|
987
|
+
* See [Query.follow()]{@link Query#follow}
|
|
988
|
+
*
|
|
989
|
+
* @param relation relation to next node
|
|
990
|
+
* @return new query single with follow operation
|
|
991
|
+
*/
|
|
267
992
|
follow<D extends CloudObject>(relation: Relation<T, D>): QuerySingle<D>;
|
|
993
|
+
|
|
994
|
+
/**
|
|
995
|
+
* See [Query.cast()]{@link Query#cast}
|
|
996
|
+
*
|
|
997
|
+
* @param type the new type
|
|
998
|
+
* @return query single on a node of the specified type
|
|
999
|
+
*/
|
|
268
1000
|
cast<S extends CloudObject>(type: Class<S>): QuerySingle<S>;
|
|
269
1001
|
|
|
270
|
-
|
|
1002
|
+
/**
|
|
1003
|
+
* Execute the query single, see [Query.execute()]{@link Query#execute}
|
|
1004
|
+
*
|
|
1005
|
+
* @param context
|
|
1006
|
+
* @return promise containing the single result or `null`
|
|
1007
|
+
*/
|
|
1008
|
+
execute(context: Context): Promise<T | null>;
|
|
271
1009
|
|
|
272
|
-
|
|
1010
|
+
/**
|
|
1011
|
+
* Execute the query single on the local data cloud,
|
|
1012
|
+
* see [Query.executeFromCache()]{@link Query#executeFromCache}
|
|
1013
|
+
*
|
|
1014
|
+
* @return single result value or `null`
|
|
1015
|
+
*/
|
|
1016
|
+
executeFromCache(): T | null;
|
|
273
1017
|
}
|
|
274
1018
|
|
|
275
1019
|
/**
|
|
276
1020
|
* Predicates are used to filter queries.
|
|
1021
|
+
*
|
|
1022
|
+
* Example:
|
|
1023
|
+
* ```javascript
|
|
1024
|
+
* const predicate = Predicate.equals(myNumberProperty, 1);
|
|
1025
|
+
* const filteredQuery = Query.instancesOf(myModel).filter(predicate).andReturn();
|
|
1026
|
+
* ```
|
|
277
1027
|
*/
|
|
278
1028
|
export class Predicate {
|
|
1029
|
+
/**
|
|
1030
|
+
* Create a predicate matching a specified property to a specified value.
|
|
1031
|
+
*
|
|
1032
|
+
* @param property the property to use for filtering
|
|
1033
|
+
* @param value the value the property must match
|
|
1034
|
+
* @return new Predicate with the equals operation
|
|
1035
|
+
*/
|
|
279
1036
|
static equals<T>(property: Property<T>, value: T): Predicate;
|
|
1037
|
+
|
|
1038
|
+
/**
|
|
1039
|
+
* Create a predicate matching a specified string property to a specified string.
|
|
1040
|
+
*
|
|
1041
|
+
* @param property the string property to use for filtering
|
|
1042
|
+
* @param value the value the string property must match
|
|
1043
|
+
* @param caseSensitive if the match must pay attention to case sensitivity
|
|
1044
|
+
* @return new Predicate with the contains string operation
|
|
1045
|
+
*/
|
|
280
1046
|
static contains(property: Property<string>, value: string, caseSensitive?: boolean): Predicate;
|
|
1047
|
+
|
|
1048
|
+
/**
|
|
1049
|
+
* Create a predicate matching a specified string property to a regular expression.
|
|
1050
|
+
*
|
|
1051
|
+
* @param property the string property to use for filtering
|
|
1052
|
+
* @param value the regex the string property must match
|
|
1053
|
+
* @param caseSensitive if the match must pay attention to case sensitivity
|
|
1054
|
+
* @return new Predicate with the match regex operation
|
|
1055
|
+
*/
|
|
281
1056
|
static regex(property: Property<string>, value: RegExp, caseSensitive?: boolean): Predicate;
|
|
282
1057
|
|
|
1058
|
+
/**
|
|
1059
|
+
* Create a predicate matching a specified number property to a numerical lower bound
|
|
1060
|
+
*
|
|
1061
|
+
* @param property the number property to user for filtering
|
|
1062
|
+
* @param value the lower bound
|
|
1063
|
+
* @param strict if the inequality is strict or not
|
|
1064
|
+
* @return new Predicate with the greaterThan mathematical operation
|
|
1065
|
+
*/
|
|
283
1066
|
static greaterThan(property: Property<number>, value: number, strict?: boolean): Predicate;
|
|
1067
|
+
|
|
1068
|
+
/**
|
|
1069
|
+
* Create a predicate matching a specified number property to a numerical upper bound
|
|
1070
|
+
*
|
|
1071
|
+
* @param property the number property to user for filtering
|
|
1072
|
+
* @param value the upper bound
|
|
1073
|
+
* @param strict if the inequality is strict or not
|
|
1074
|
+
* @return new Predicate with the smallerThan mathematical operation
|
|
1075
|
+
*/
|
|
284
1076
|
static smallerThan(property: Property<number>, value: number, strict?: boolean): Predicate;
|
|
285
1077
|
|
|
1078
|
+
/**
|
|
1079
|
+
* Create a predicate matching a specified number property to a number property lower bound
|
|
1080
|
+
*
|
|
1081
|
+
* @param property1 the number property to user for filtering
|
|
1082
|
+
* @param property2 the lower bound number property
|
|
1083
|
+
* @param strict if the inequality is strict or not
|
|
1084
|
+
* @return new Predicate with the greaterThan mathematical operation
|
|
1085
|
+
*/
|
|
286
1086
|
static greaterThan(property1: Property<number>, property2: Property<number>, strict?: boolean): Predicate;
|
|
1087
|
+
|
|
1088
|
+
/**
|
|
1089
|
+
* Create a predicate matching a specified number property to a number property upper bound
|
|
1090
|
+
*
|
|
1091
|
+
* @param property1 the number property to user for filtering
|
|
1092
|
+
* @param property2 the upper bound number property
|
|
1093
|
+
* @param strict if the inequality is strict or not
|
|
1094
|
+
* @return new Predicate with the smallerThan mathematical operation
|
|
1095
|
+
*/
|
|
287
1096
|
static smallerThan(property1: Property<number>, property2: Property<number>, strict?: boolean): Predicate;
|
|
288
1097
|
|
|
1098
|
+
/**
|
|
1099
|
+
* Create an AND composite predicate matching a specified set of predicates
|
|
1100
|
+
*
|
|
1101
|
+
* @param predicates list of predicates to match
|
|
1102
|
+
* @return new Predicate that should match all specified predicates
|
|
1103
|
+
*/
|
|
289
1104
|
static and(...predicates: Predicate[]): Predicate;
|
|
1105
|
+
|
|
1106
|
+
/**
|
|
1107
|
+
* Create an OR composite predicate matching a specified set of predicates
|
|
1108
|
+
*
|
|
1109
|
+
* @param predicates list of predicates to match
|
|
1110
|
+
* @return new Predicate that should match at least one specified predicate
|
|
1111
|
+
*/
|
|
290
1112
|
static or(...predicates: Predicate[]): Predicate;
|
|
1113
|
+
|
|
1114
|
+
/**
|
|
1115
|
+
* Create a NOT predicate matching the opposite of a specified predicate
|
|
1116
|
+
*
|
|
1117
|
+
* @param predicate the predicate to inverse
|
|
1118
|
+
* @return new Predicate that match when the specified predicate does not
|
|
1119
|
+
*/
|
|
291
1120
|
static not(predicate: Predicate): Predicate;
|
|
292
1121
|
}
|
|
293
1122
|
|
|
1123
|
+
/**
|
|
1124
|
+
* Specific predicate class creator for filtering based on relations between objects
|
|
1125
|
+
*
|
|
1126
|
+
* A path is defined by a list of relations, and an object match the predicate if and only if the patch can be followed
|
|
1127
|
+
* to a destination (which might be specified)
|
|
1128
|
+
*/
|
|
294
1129
|
export class RelatedTo extends Predicate {
|
|
295
1130
|
constructor(destination?: Tag);
|
|
1131
|
+
|
|
1132
|
+
/**
|
|
1133
|
+
* Adds a relation to the path the RelatedTo predicate must match
|
|
1134
|
+
*
|
|
1135
|
+
* @param relation relation to add to the path
|
|
1136
|
+
* @return new RelatedTo predicate with additional relation to match in the path
|
|
1137
|
+
*/
|
|
296
1138
|
follow(relation: Relation<any, any>): RelatedTo;
|
|
1139
|
+
|
|
1140
|
+
/**
|
|
1141
|
+
* Adds a relation that can be followed recursively in the path for the RelatedTo predicate
|
|
1142
|
+
*
|
|
1143
|
+
* @param relation relation to add to the path that can be followed recursively
|
|
1144
|
+
* @return new RelatedTo predicate with additional relation that can be matched recursively in the path
|
|
1145
|
+
*/
|
|
297
1146
|
followRecursive(relation: Relation<any, any>): RelatedTo;
|
|
298
1147
|
}
|
|
299
1148
|
|