@olympeio/runtime-node 9.10.4 → 9.11.0

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/types/cloud.d.ts DELETED
@@ -1,1726 +0,0 @@
1
- // *********************************************
2
- //
3
- // Olympe Data cloud objects Public API
4
- //
5
- // *********************************************
6
-
7
- // @ts-ignore
8
- import {Observable} from 'rxjs';
9
- import {Readable} from 'stream';
10
- import {Context, CloudObject, Relation, Property, InstanceOrTag, Class} from "./base";
11
- import {Brick, BrickContext} from './runtime';
12
- import {Color} from "./utils";
13
-
14
- // --------------------------
15
- // -- Primitive data types --
16
- // --------------------------
17
- /**
18
- * A property model defines a property of a data type.
19
- * A property is defined by its type and the model it defines a property for.
20
- * */
21
- export class PropertyModel extends CloudObject {
22
- /**
23
- * Relation from the property model to the data type (model)
24
- * to which that property is attached.
25
- *
26
- * Example:
27
- *
28
- * ` myNumberPropertyModel --definingModelRel-> myDataTypeObject`
29
- */
30
- static definingModelRel: Relation<PropertyModel, CloudObject>;
31
-
32
- /**
33
- * Relation from the `PropertyModel` to its type.
34
- *
35
- * Example :
36
- *
37
- * `myNumberPropertyModel --typeRel-> Number`
38
- */
39
- static typeRel: Relation<PropertyModel, CloudObject>;
40
- }
41
-
42
- export type FollowRule = Property<number>;
43
-
44
- /**
45
- * A relation model defines a relation between two data types.
46
- * It defines what data types is the origin and the destination of the relation.
47
- *
48
- * It also defines follow rules properties on the relation.
49
- * */
50
- export class RelationModel extends CloudObject {
51
- /**
52
- * Relation from the origin data type to the RelationModel
53
- * */
54
- static originModelRel: Relation<RelationModel, CloudObject>;
55
- /**
56
- * Relation from a RelationModel to the destination data type
57
- * */
58
- static destinationModelRel: Relation<RelationModel, CloudObject>;
59
- /**
60
- * Property for the *dump* follow rule
61
- */
62
- static dumpFollowRuleProp: FollowRule;
63
- /**
64
- * Property for the *delete* follow rule
65
- */
66
- static deleteFollowRuleProp: FollowRule;
67
- /**
68
- * Property for the *runtime* follow rule
69
- */
70
- static runtimeFollowRuleProp: FollowRule;
71
- }
72
-
73
- /**
74
- * StringModel represents a {@apilink PropertyModel} for a string property of a data type.
75
- */
76
- export class StringModel extends CloudObject {
77
- static valueProp: Property<string>;
78
- }
79
-
80
- /**
81
- * NumberModel represents a {@apilink PropertyModel} for a number property of a data type.
82
- */
83
- export class NumberModel extends CloudObject {
84
- static valueProp: Property<number>;
85
- }
86
-
87
- /**
88
- * BooleanModel represents a {@apilink PropertyModel} for a boolean property of a data type.
89
- */
90
- export class BooleanModel extends CloudObject {
91
- static valueProp: Property<boolean>;
92
- }
93
-
94
- /**
95
- * DatetimeModel represents a {@apilink PropertyModel} for a datetime property of a data type.
96
- */
97
- export class DatetimeModel extends CloudObject {
98
- static valueProp: Property<Date>;
99
- }
100
-
101
- /**
102
- * ColorModel represents a {@apilink PropertyModel} for a color property of a data type.
103
- */
104
- export class ColorModel extends CloudObject {
105
- static valueProp: Property<Color>;
106
- }
107
-
108
- /**
109
- * File is the main class used to create business objects with a binary/string data content.
110
- * It is a Data Type so can be extended and associated to a data source.
111
- */
112
- export class File extends CloudObject {
113
-
114
- /**
115
- * @deprecated because conflict with {@apilink CloudObject.nameProp}. Use {@apilink File.fileNameProp} instead.
116
- */
117
- static nameProp: Property<string>;
118
- static fileNameProp: Property<string>;
119
- static creationDateProp: Property<Date>;
120
- static modificationDateProp: Property<Date>;
121
- static mimeTypeProp: Property<string>;
122
- static urlProp: Property<string>;
123
-
124
- /**
125
- * Set the binary content of a specified file
126
- * @param transaction transaction in which to create the file
127
- * @param file tag of the file
128
- * @param name file name
129
- * @param content byte content of the file
130
- * @param mimeType optional mime type of the file
131
- */
132
- static setContent(transaction: Transaction, file: InstanceOrTag, name: string, content: Uint8Array | ArrayBuffer, mimeType?: string): void;
133
-
134
- /**
135
- * Set the content of a `File` from a specified URL
136
- * @param transaction transaction in which to create the file
137
- * @param file tag of the file
138
- * @param name filename
139
- * @param url url to retrieve content from
140
- * @param mimeType optional mime type of the file
141
- */
142
- static setURLContent(transaction: Transaction, file: InstanceOrTag, name: string, url: string, mimeType?: string): void;
143
-
144
- /**
145
- * @deprecated Please use {@apilink File.setContent}
146
- * Create a `File` from its content
147
- *
148
- * @param transaction transaction in which to create the file
149
- * @param name filename
150
- * @param content byte content of the file
151
- * @param mimeType optional mime type of the file
152
- * @param source optional source where file will be stored ({@apilink {PredefinedDataSource}} or DBConnector tag)
153
- * @param tag optional tag for the file
154
- * @return tag string of the file
155
- */
156
- static createFromContent(transaction: Transaction, name: string, content: Uint8Array | ArrayBuffer, mimeType?: string, source?: Source, tag?: string): string;
157
-
158
- /**
159
- * @deprecated Please use {@apilink File.setURLContent}
160
- * Create a `File` from a specified URL
161
- * @param transaction transaction in which to create the file
162
- * @param name filename
163
- * @param url url to retrieve content from
164
- * @param mimeType optional mime type of the file
165
- * @param source optional source where file will be stored ({@apilink {PredefinedDataSource}} or DBConnector tag)
166
- * @param tag optional tag for the file
167
- * @return tag string of the file
168
- */
169
- static createFromURL(transaction: Transaction, name: string, url: string, mimeType?: string, source?: Source, tag?: string): string;
170
-
171
- /**
172
- * Gets the file content as an ArrayBuffer.
173
- *
174
- * @deprecated consider using the new `getContentAsBinary` method returning a Promise instead
175
- * @param onSuccess (deprecated) callback to execute when byte content has been retrieved successfully
176
- * @param onFailure (deprecated) callback to execute when content retrieval has failed
177
- */
178
- getContentAsBinary(onSuccess: (content: ArrayBuffer) => void, onFailure?: (errMsg: string) => void);
179
-
180
- /**
181
- * Gets the file content as an ArrayBuffer.
182
- *
183
- * @return promise resolving with the content as a byte array
184
- */
185
- getContentAsBinary():Promise<ArrayBuffer>;
186
-
187
- /**
188
- * Get the content of this file and returns it as an UTF-8 string.
189
- * **Note:** this method should be used only when the file is a text file.
190
- *
191
- * @deprecated consider using the new `getContentAsString` method returning a Promise instead
192
- * @param onSuccess (deprecated) callback to execute when string content has been retrieved successfully
193
- * @param onFailure (deprecated) callback to execute when content retrieval has failed
194
- */
195
- getContentAsString(onSuccess: (content: string) => void, onFailure?: (errMsg: string) => void);
196
-
197
- /**
198
- * Get the content of this file and returns it as an UTF-8 string.
199
- * **Note:** this method should be used only when the file is a text file.
200
- *
201
- * @return promise resolving with the content as a string
202
- */
203
- getContentAsString(): Promise<string>;
204
-
205
- /**
206
- * Gets the URL that gives direct access to the file content:
207
- * - For files that are external to Olympe, gives the normal URL
208
- * - For the files stored by Olympe, provides a dataURL, with the content embedded in Base64
209
- *
210
- * @deprecated consider using the new `getContentUrl` method returning a Promise instead
211
- * @param onSuccess (deprecated) callback to execute when content has been retrieved successfully
212
- * @param onFailure (deprecated) callback to execute when content retrieval has failed
213
- */
214
- getContentUrl(onSuccess: (content: string) => void, onFailure?: () => void);
215
-
216
- /**
217
- * Gets the URL that gives direct access to the file content:
218
- * - For files that are external to Olympe, gives the normal URL
219
- * - For the files stored by Olympe, provides a dataURL, with the content embedded in Base64
220
- *
221
- * @return promise resolving with the content as a string
222
- */
223
- getContentUrl(): Promise<string>;
224
-
225
- /**
226
- * Save this file with specified name
227
- *
228
- * @param name filename
229
- */
230
- saveAs(name: string): void;
231
- }
232
-
233
- /**
234
- * User object for authentication purposes
235
- */
236
- export class User extends CloudObject {
237
- static loginProp: Property<string>;
238
- static saltProp: Property<string>;
239
- static verifierProp: Property<string>;
240
- static SAMLnameIdProp: Property<string>;
241
- }
242
-
243
- /**
244
- * An Enum is an ordered list of string key-values mappings
245
- */
246
- export class Enum extends CloudObject {
247
- /**
248
- * Create an empty `Enum?` without any value
249
- *
250
- * See {@apilink EnumValue.createValue} to create values for an Enum.
251
- *
252
- * @param transaction transaction in which to create the Enum
253
- * @param name optional name of the Enum
254
- * @return string tag of the Enum object
255
- */
256
- create(transaction: Transaction, name?: string): string;
257
-
258
- /**
259
- * Get the values defined for this `Enum`
260
- */
261
- getValues(): QueryResult<EnumValue>;
262
- }
263
-
264
- /**
265
- * An `EnumValue` is a single value part of an `Enum`.
266
- * It has a `string` name, a rank (its position in the Enum list).
267
- *
268
- * The values for `EnumValue` are always stringified.
269
- */
270
- export class EnumValue extends CloudObject {
271
- /**
272
- * Add a `EnumValue` to a specified `Enum`
273
- *
274
- * @param transaction transaction in which to add the EnumValue to the Enum
275
- * @param enumModel `EnumModel` containing the specified `EnumValue`
276
- * @param value value of the `EnumValue`
277
- * @param name name of the `EnumValue`
278
- * @param rank position of the `EnumValue` in the `Enum`
279
- */
280
- static createValue(transaction: Transaction, enumModel: InstanceOrTag, value: string, name?: string, rank?: number): string;
281
-
282
- /**
283
- * Name property for an EnumValue
284
- */
285
- static nameProp: Property<string>;
286
- /**
287
- * Value property for an EnumValue
288
- */
289
- static valueProp: Property<string>;
290
- /**
291
- * Rank property for an EnumValue
292
- */
293
- static rankProp: Property<number>;
294
- }
295
-
296
- // -------------------------
297
- // -- Workflow data types --
298
- // -------------------------
299
-
300
- /**
301
- * A `Workflow` is a sequence of {@apilink WorkflowState} in which instances of a model goes through.
302
- * {@apilink WorkflowState} are linked by {@apilink WorkflowTransition} that can have an optional _process function_.
303
- * The `Workflow` also historize the {@apilink WorkflowState} of the instance and optionally serialize the object itself in a {@apilink WorkflowObjectState}.
304
- */
305
- export class Workflow extends CloudObject {
306
- /** Is the instance serialization enabled or not */
307
- static serializationEnabledProp: Property<boolean>;
308
- /** The model to which the `Workflow` is associated */
309
- static dataTypeRel: Relation<Workflow, CloudObject>;
310
- /** The {@apilink WorkflowState} that are in the `Workflow` */
311
- static statesRel: Relation<Workflow, WorkflowState>;
312
- /** The initial {@apilink WorkflowState} of the `Workflow` */
313
- static initialStateRel: Relation<Workflow, WorkflowState>;
314
- }
315
-
316
- /**
317
- * A `WorkflowState` defines a state in a {@apilink Workflow}.
318
- */
319
- export class WorkflowState extends CloudObject { /* empty */ }
320
-
321
- /**
322
- * A `WorkflowTransition` defines a transition between 2 {@apilink WorkflowState}.
323
- * It has a direction (`fromStateRel` to `toStateRel`) and can have an optional _process function_.
324
- * The _process function_ (`processRefProp`) is automatically triggered when the transition occurs.
325
- */
326
- export class WorkflowTransition extends CloudObject {
327
- /**
328
- * The `WorkflowTransition` optional _process function_.
329
- * It has this signature: (ControlFlow, CloudObject, User, Map) -> (ControlFlow, ErrorFlow)
330
- */
331
- static processRefProp: Property<Brick>;
332
- /** The {@apilink WorkflowState} from which this transition starts */
333
- static fromStateRel: Relation<WorkflowTransition, WorkflowState>;
334
- /** The {@apilink WorkflowState} to which this transition ends */
335
- static toStateRel: Relation<WorkflowTransition, WorkflowState>;
336
- }
337
-
338
- /**
339
- * A `WorkflowObjectState` represents the state of an instance at a certain point in time.
340
- * It is automatically created when initializing a {@apilink Workflow} on an instance or when triggering a {@apilink WorkflowTransition}.
341
- */
342
- export class WorkflowObjectState extends CloudObject {
343
- /** The name of the {@apilink Workflow} associated */
344
- static workflowProp: Property<string>;
345
- /** The name of the {@apilink WorkflowState} */
346
- static stateProp: Property<string>;
347
- /** The name (login) of the {@apilink User} */
348
- static assigneeProp: Property<string>;
349
- /** The point in time of this object state */
350
- static dateTimeProp: Property<Date>;
351
- /** If the {@apilink Workflow} has serialization enabled, the object's property are saved here in JSON */
352
- static serializedObjectProp: Property<string>;
353
- /** The related instance this object state represents */
354
- static objectRel: Relation<WorkflowObjectState, CloudObject>;
355
- /** The related instance this object state represents. This relation only reference the current state */
356
- static currentObjectRel: Relation<WorkflowObjectState, CloudObject>;
357
- }
358
-
359
- // -------------------------
360
- // -- Theme data types --
361
- // -------------------------
362
-
363
- /**
364
- * Theme object describing the main visual properties used by components
365
- */
366
- export class Theme extends CloudObject {
367
- static nameProp: Property<string>;
368
- static primaryColorProp: Property<string>;
369
- static secondaryColorProp: Property<string>;
370
- static errorColorProp: Property<string>;
371
- static warningColorProp: Property<string>;
372
- static infoColorProp: Property<string>;
373
- static successColorProp: Property<string>;
374
- static fontFamilyProp: Property<string>;
375
- }
376
-
377
- // ---------------------------
378
- // -- Database transactions --
379
- // ---------------------------
380
-
381
- /**
382
- * Transactions are the unique way to apply a list of operations to the datacloud.
383
- * A transaction can be merged into another transaction so that both are executed as a single set of operations.
384
- *
385
- * All the operations for a transaction are executed atomically. Either all operations succeed, or none is applied.
386
- *
387
- *
388
- * There are 5 types of basic operations :
389
- * - Create instance: create a node in the database with specified properties.
390
- * - Update instance property: update an existing node in the database.
391
- * - Delete instance: delete a node from the database. Delete only works if all the relations are removed too. Cascade delete can be activated.
392
- * - Create relation: create a relation of a specific type between 2 existing node.
393
- * - Delete relation: remove the specified relation between 2 specified nodes.
394
- *
395
- * In most cases, we apply the Transactions operations using the "execute()" method. The transaction size is limited but in real-time.
396
- * It notifies observers of the data in real-time.
397
- *
398
- * Larger transactions with big set of operations (batch updates) must be executed using "executeAsLarge()" method. However, no notification will be generated.
399
- *
400
- * Callbacks can be registered on transaction using "afterExecution()" method. They are executed once the transaction is applied.
401
- *
402
- * Example of transaction:
403
- *
404
- * ```javascript
405
- * const tx = new Transaction(true);
406
- * const myNewInstanceTag = tx.create(<myModelTag>);
407
- * tx.update(myNewInstanceTag, <myPropertyTag>, <myPropertyValue>)
408
- * .execute()
409
- * .then(() => {
410
- * // success tx case
411
- * })
412
- * .catch((err) => {
413
- * // error during tx case
414
- * })
415
- * ```
416
- *
417
- * Concurrency transactions do not guarantee their execution order.
418
- */
419
- export class Transaction {
420
-
421
- /**
422
- * Create a new transaction object.
423
- *
424
- * @param persist if set to `true`, will persist to the data source the objects {@apilink Transaction.create} created in that transaction. (Default = `true`)
425
- */
426
- constructor(persist?: boolean);
427
-
428
- /**
429
- * Get the transaction id attached to this transaction
430
- * @return this transaction id
431
- */
432
- getId(): string;
433
-
434
- // Operations
435
- /**
436
- * Create a new instance.
437
- *
438
- * A custom map can specify property values for the instance.
439
- *
440
- * A source can be the orchestrator ({@apilink {PredefinedDataSource.SERVER}}), local ({@apilink {PredefinedDataSource.SELF}}) or
441
- * an external data source (tag of DBConnector). The source is where
442
- * the object is persisted and its true value outside local scopes.
443
- *
444
- * @param model tag of the model of the instance to be created
445
- * @param properties custom map from tag to their value for properties of the instance to be created
446
- * @param source optional source of the instance
447
- * @param tag optional tag of the instance to be created and must be unique
448
- * @return the tag of the instance to be created
449
- */
450
- create(model: InstanceOrTag, properties?: Map<InstanceOrTag, any>, source?: Source, tag?: string): string;
451
-
452
- /**
453
- * Update the property of an instance
454
- *
455
- * @param instance tag of the instance to be updated
456
- * @param property the property to be updated
457
- * @param value the value of the property to be updated to
458
- * @return this transaction
459
- */
460
- update<T>(instance: InstanceOrTag, property?: Property<T>, value?: T): this;
461
-
462
- /**
463
- * Update multiple properties of a single instance
464
- *
465
- * @param instance tag of the instance to be updated
466
- * @param properties map of properties to update
467
- * @return this transaction
468
- */
469
- multiUpdate(instance: InstanceOrTag, properties: Map<InstanceOrTag, any>): this;
470
-
471
- /**
472
- * Delete an instance
473
- *
474
- * @param instance tag of the instance to be deleted
475
- * @return this transaction
476
- */
477
- delete(instance: InstanceOrTag): this;
478
-
479
- /**
480
- * Create relation between two instances
481
- *
482
- * @param relation tag of the relation to be created
483
- * @param from tag of the ORIGIN instance of the relation
484
- * @param to tag ofo the DESTINATION instance of the relation
485
- * @return this transaction with the create relation operation registered
486
- */
487
- createRelation(relation: InstanceOrTag, from: InstanceOrTag, to: InstanceOrTag): this;
488
-
489
- /**
490
- * Delete a relation between two specified instances.
491
- *
492
- * The relation is only deleted for the relation parameter direction.
493
- *
494
- * @param relation tag of the relation to be deleted
495
- * @param from origin instance tag
496
- * @param to destination instance tag
497
- * @return this transaction
498
- */
499
- deleteRelation(relation: InstanceOrTag, from: InstanceOrTag, to: InstanceOrTag): this;
500
-
501
- /**
502
- * Delete any number of the relation starting from specified node.
503
- *
504
- * The specified node might be the origin or (exclusive) the destination of the relation.
505
- *
506
- * For the relations :
507
- * ```
508
- * - a - [rel1] -> b,
509
- * - c - [inverseRel(rel1)] -> a,
510
- * - a - [rel1] -> d,
511
- * - a - [rel2] -> d
512
- * ```
513
- * `tx.deleteAllRelation(rel1, a)` will remove the first and third relations
514
- *
515
- * @param relation deleted relation, indicates relation tag *and* direction
516
- * @param origin starting node
517
- */
518
- deleteAllRelations(relation: Relation<any, any>, origin: InstanceOrTag): this;
519
-
520
- /**
521
- * Set the specified instance to be persisted or not in this transaction.
522
- * Default value of persist is true.
523
- *
524
- * @param instance the instance to be persisted
525
- * @param persist determine if the specified instance should be persisted or not (true by default).
526
- * @return this transaction
527
- */
528
- persist(instance: InstanceOrTag, persist?: boolean): this;
529
-
530
- /**
531
- * Change the persistence mode for a single instance in this transaction
532
- *
533
- * @deprecated use {@apilink Transaction.persist} instead
534
- * @param instance the instance to be persisted
535
- * @param persist the persisting mode
536
- * @return this transaction
537
- */
538
- persistInstance(instance: InstanceOrTag, persist?: boolean): this;
539
-
540
- /**
541
- * Change the source of all instances created in this transaction
542
- *
543
- * `source` can be specified as :
544
- * 1. a predefined source type {@apilink {PredefinedDataSource}}
545
- * 2. an external data source (Tag of a `DBConnector`)
546
- *
547
- * The source of a data object is where the object is persisted.
548
- *
549
- * By default, the `source` is the default source configured in the project.
550
- *
551
- * @param source the new source for instances
552
- * @return this transaction
553
- */
554
- setSource(source: Source): this;
555
-
556
- /**
557
- * Retrieve the tag of the model of the instance tag
558
- * from the created instances in this transaction
559
- * or from the local database.
560
- *
561
- * @param tag the instance to find the model of
562
- * @return the tag of the model of the given instance
563
- */
564
- model(tag: InstanceOrTag): string | null;
565
-
566
- /**
567
- * Add all operations of another transaction into this transaction
568
- *
569
- * @param otherTransaction the other transaction to add operations from
570
- * @return this transaction
571
- */
572
- merge(otherTransaction: Transaction): this;
573
-
574
- // Execution methods
575
- /**
576
- * Set a callback to be executed after all the operations
577
- * in the transaction were executed successfully
578
- *
579
- * @param callback the callback to be executed
580
- * @return this transaction
581
- */
582
- afterExecution(callback: (success: boolean, message?: string) => void): this;
583
-
584
- /**
585
- * Execute atomically the transaction at the data sources. Return the transaction result if succeeds.
586
- *
587
- * @return promise resolving with the corresponding TransactionResult if the transaction succeeds,
588
- * rejecting if the transaction fails
589
- */
590
- execute(): Promise<TransactionResult>;
591
-
592
- /**
593
- * Execute atomically a transaction at the data source and returns the transaction result if succeeds.
594
- * The `large` mode sends the transaction over HTTP, this has the following incidence:
595
- * - Quicker processing of transaction
596
- * - Allows transactions with no limit of size
597
- * - Cannot be used when logged as Guest
598
- *
599
- * @return promise resolving with the corresponding TransactionResult if the transaction succeeds,
600
- * rejecting if the transaction fails.
601
- */
602
- executeAsLarge(): Promise<TransactionResult>;
603
-
604
- /**
605
- * Start a transaction using an existing transaction in the provided context
606
- * or a new one if there is none.
607
- *
608
- * @param $ context in which the transaction executes
609
- * @return transaction
610
- */
611
- static from($: BrickContext): Transaction;
612
-
613
- /**
614
- * Execute a given transaction if there is no open transaction in the context.
615
- *
616
- * @param $ context
617
- * @param transaction transaction to process
618
- * @return boolean indicating if the argument transaction has been processed
619
- */
620
- static process($: BrickContext, transaction: Transaction): Promise<boolean>;
621
- }
622
-
623
- /**
624
- * Predefined data sources that can be used for {@apilink Transaction.setSource}.
625
- */
626
- export enum PredefinedDataSource {
627
- /**
628
- * Local DataSource. By using this source, objects are not persisted
629
- */
630
- SELF = 'self',
631
- /**
632
- * Embedded Graph Database
633
- */
634
- SERVER = 'server'
635
- }
636
-
637
- /**
638
- * When manipulating CloudObjects, sometimes it is required to manually set the data source of that object.
639
- * `Source` determines where the object comes from: what data source is the owner of the object across the ecosystem.
640
- */
641
-
642
- export type Source = PredefinedDataSource | string;
643
-
644
- /**
645
- * A transaction result is the object received after a transaction has been executed successfully.
646
- * It provides information about what has been done.
647
- */
648
- export class TransactionResult {
649
-
650
- /**
651
- * Return the ordered list of CloudObjects created in this transaction.
652
- *
653
- * @return the list of CloudObjects instances
654
- */
655
- getCreatedObjects(): CloudObject[];
656
- }
657
-
658
- /**
659
- * BurstTransactions are designed to continuously apply high rates of updates on properties (FIFO ordering).
660
- * The only operation supported by BurstTransactions is to update properties of an instance.
661
- *
662
- * Unlike classical Transactions, a burst transaction preserves the order of update operations and
663
- * is designed to handle many updates per second for smooth shared animations.
664
- *
665
- * Example of use:
666
- * A marker representing a red dot on the screen which coordinate properties are controlled by motion sensors of an IoT device
667
- * should use BurstTransaction instead of a bunch of continuous classical Transaction to have fluid movements on the screen.
668
- */
669
- export class BurstTransaction {
670
- constructor();
671
-
672
- /**
673
- * Push all property values from specified Observable to update specified object
674
- *
675
- * @param object the object to update
676
- * @param values observable mapping properties to new values
677
- */
678
- push<T>(object: CloudObject, values: Observable<Map<Property<T>, T>>): void;
679
-
680
- /**
681
- * Commit and close the burst transaction
682
- *
683
- * @return A `Promise` completing with commit success/failure
684
- */
685
- complete(): Promise<void>;
686
- }
687
-
688
- // ----------------------
689
- // -- Database queries --
690
- // ----------------------
691
-
692
- /**
693
- * A QueryResult is a list of key-value pairs that has been generated as a result of a `Query`.
694
- * It contains the result of a query at a specific time.
695
- *
696
- * The keys are tags (e.g. `myTag`) that correspond to a `CloudObject` (e.g. `myCloudObject`).
697
- * When the {@apilink Query} contains more than one {@apilink Query.andReturn Query.andReturn()} clause,
698
- * keys are composite tags (e.g. `'tag1.tag2.tag3'`) and values are tuples of `CloudObjects` (e.g. `[cloudObj1, cloudObj2, cloudObj3]`).
699
- * Such a QueryResult can be obtained via:
700
- * ```javascript
701
- * Query.instancesOf(myModel1).andReturn.follow(myRelation1).andReturn.follow(myRelation2).andReturn().execute().
702
- * ```
703
- *
704
- * When a query is subscribed, the returned observable generates multiple QueryResults over time.
705
- *
706
- * A QueryResult can be easily manipulated and transformed to a standard Array.
707
- */
708
- export class QueryResult<T extends CloudObject | CloudObject[]> {
709
- /**
710
- *@return empty `QueryResult`
711
- */
712
- static empty(): QueryResult<any>;
713
-
714
- /**
715
- * Symbol iterator for `for…in` syntactic sugar
716
- *
717
- * @return iterator over the key-values pairs of this `QueryResult`
718
- */
719
- [Symbol.iterator](): IterableIterator<[string, T]>;
720
-
721
- /**
722
- * Get an iterable iterator over the key-value pairs of this `QueryResult`
723
- *
724
- * @return iterator
725
- */
726
- entries(): IterableIterator<[string, T]>;
727
-
728
- /**
729
- * Get an iterable iterator over the values of this `QueryResult`
730
- *
731
- * @return iterator
732
- */
733
- values(): IterableIterator<T>
734
-
735
- /**
736
- * Get an iterable iterator over the keys of this `QueryResult`
737
- *
738
- * @return iterator
739
- */
740
- keys(): IterableIterator<string>
741
-
742
- /**
743
- * Get an array containing the values of this `QueryResult`
744
- *
745
- * @return array of this `QueryResult`'s values
746
- */
747
- toArray(): T[];
748
-
749
- /**
750
- * Get the number of key-value pairs this `QueryResult` contains
751
- *
752
- * @return size of this `QueryResult`
753
- */
754
- size(): number;
755
-
756
- /**
757
- * Check whether a key / value is contained in this `QueryResult`.
758
- *
759
- * Returns true if the cloud array contains an element with the specified key.
760
- *
761
- * If no corresponding key is found, returns true if the cloud array contains an element with the specified value.
762
- *
763
- * @param key the value to search for
764
- * @return true if the value `key` is found
765
- */
766
- has(key: T | string): boolean;
767
-
768
- /**
769
- * Get index of a value in the keys or values of this `QueryResult`.
770
- *
771
- * If the key is a string, retrieve the index from the `string` keys of this `QueryResult`.
772
- *
773
- * If the key is not a string, get the index from the `CloudObject` tuples
774
- *
775
- * @param key the value to find the index of
776
- * @return index of the argument value or -1 if the value is not found
777
- */
778
- indexOf(key: T | string): number;
779
-
780
- /**
781
- * Get the value corresponding to a given key
782
- *
783
- * @param key tag or composite tag
784
- * @return matching tuple or `null`
785
- */
786
- get(key: string): T | null;
787
-
788
- /**
789
- * Get the first value
790
- *
791
- * @return first value or `null` if empty
792
- */
793
- getFirst(): T | null;
794
-
795
- /**
796
- * Get the value at the specified index
797
- *
798
- * @param index
799
- * @return value at position `index` or `null` if index is out of bounds
800
- */
801
- getAt(index: number): T | null;
802
-
803
- /**
804
- * Query Results, when used in a subscription, can be used to observe changes compare to the previous QueryResult.
805
- * This method returns the values that have added from the previous QueryResult.
806
- *
807
- * @return array of added values (CloudObjects or tuples of CloudObjects)
808
- */
809
- getAdded(): T[];
810
-
811
- /**
812
- * Query Results, when used in a subscription, can be used to observe changes compare to the previous QueryResult.
813
- * This method returns the values the keys (eg: tags) of values that have been removed from the previous QueryResult.
814
- *
815
- * @return array of removed keys (tags or tags concatenation (tuples))
816
- */
817
- getRemoved(): string[];
818
-
819
- /**
820
- * Returns an array equivalent to {@apilink QueryResult.toArray | this.toArray().push(...object)}
821
- *
822
- * This operation returns a new array and does not modify this QueryResult.
823
- *
824
- * @param object new values to push in the values array.
825
- * @return new values array with new elements appended
826
- */
827
- push(...object: T[]): T[];
828
-
829
- /**
830
- * Returns the QueryResult values as an array whose last value has been removed.
831
- *
832
- * If {@apilink QueryResult.size} is 0 or 1, this method returns an empty array.
833
- *
834
- * This operation returns a new array and does not modify this QueryResult.
835
- *
836
- * @return new values array with last element removed
837
- */
838
- pop(): T[];
839
-
840
- /**
841
- * Returns the QueryResult values as an array whose first value has been removed.
842
- *
843
- * If {@apilink QueryResult.size} is 0 or 1, this method returns an empty array.
844
- *
845
- * This operation returns a new array and does not modify this QueryResult.
846
- *
847
- * @return new values array with first element removed
848
- */
849
- shift(): T[];
850
-
851
- /**
852
- * Returns an array containing the values matching the provided filter predicate.
853
- *
854
- * @param predicate filter {@apilink Predicate}
855
- * @return array of matching values
856
- */
857
- filter(predicate: (entry: T, index: number) => boolean): T[];
858
-
859
- /**
860
- * Returns the first value matching the predicate, `null` otherwise.
861
- *
862
- * `find` calls `predicate` once for each element of the array until it returns true.
863
- * If such an element is found, find immediately returns that element value.
864
- *
865
- * @param predicate
866
- * @return the first value evaluating to true or `null`
867
- */
868
- find(predicate: (entry: T, index: number) => boolean): T | null;
869
-
870
- /**
871
- * Execute the specified callback function for each value of this `QueryResult`
872
- *
873
- * @param callback
874
- */
875
- forEach(callback: (entry: T, index: number) => void): void;
876
-
877
- /**
878
- * Execute the specified callback function for each value of this `QueryResult`.
879
- * It returns a new array that contains the results of the callback execution.
880
- *
881
- * @param callback
882
- * @return new array of transformed values
883
- */
884
- map<S>(callback: (entry: T, index: number) => S): S[];
885
-
886
- /**
887
- * Return a sorted copy of this QueryResult.
888
- *
889
- * The specified `comparator` used to determine the order of the QueryResult key-value pairs.
890
- * 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
891
- * number otherwise.
892
- *
893
- * @param comparator comparator returning a negative, zero or positive number
894
- * @return sorted copy of this QueryResult
895
- */
896
- sort(comparator: (b1: T, b2: T) => number): QueryResult<T>;
897
-
898
- /**
899
- * Return a reduced value for this QueryResult.
900
- *
901
- * The specified `reducer` callback reduces the QueryResult values. Similar to `Array.reduce()`.
902
- *
903
- * @param reducer callback
904
- * @param initial initial value of the accumulator
905
- * @return accumulated result applying the `reducer` function iteratively
906
- */
907
- reduce<S>(reducer: (accumulator: S, entry: T, index: number) => S, initial: S): S;
908
-
909
- /**
910
- * Return a new QueryResult that contains the concatenation of two or more QueryResults.
911
- *
912
- * Concatenating two QueryResults results in a new QueryResult with the following:
913
- *
914
- * - the keys of the QueryResults are concatenated
915
- * - the values of the QueryResults are concatenated
916
- * - the arrays returned by {@apilink QueryResult.getAdded} are concatenated
917
- * - the arrays returned by {@apilink QueryResult.getRemoved} are concatenated
918
- *
919
- * Example : ```javascript
920
- * const result1 = Query.fromInstances(myModel1).executeFromCache();
921
- * // result1 is {tag1: cloudObj1, tag2: cloudObj2}
922
- * const result2 = Query.fromInstances(myModel2).executeFromCache();
923
- * // result2 is {tag3: cloudObj3}
924
- * const concatenatedResult = result2.concat(result1);
925
- * // concatenatedResult is {tag3: cloudObj3, tag1: cloudObj1, tag2: cloudObj2}
926
- * ```
927
- *
928
- * @param others QueryResults to append to this `QueryResult`
929
- * @return concatenated query results
930
- */
931
- concat(...others: QueryResult<T>[]): QueryResult<T>;
932
- }
933
-
934
- declare type QueryOptions = {
935
- cacheBucketName?: string; // Name of the cache bucket - if provided, it means that the query must be cached under this name
936
- }
937
-
938
- declare type ImplicitQueryOption = {
939
- storeInCacheDB?: boolean // indicates if this follow rule query must be cached in browser DB (IndexedDB) for potential offline use. Default is false.
940
- }
941
-
942
- /**
943
- * A Query is an immutable object used to build queries on the datacloud. It is a graph query builder.
944
- * It starts from an `origin` InstanceOrTag (typically, the `InstanceOrTag` of a data type or of an instance).
945
- * From there, it can follow relations between data types and filter results.
946
- *
947
- * Example:
948
- *
949
- * `origin --a--> X --b--> Y --c--> Z`
950
- *
951
- * Example:
952
- *
953
- * ```javascript
954
- * Query.from(origin)
955
- * .follow(a)
956
- * .execute();
957
- * ```
958
- * This will return a Promise of a QueryResult whose values are of type X: `Promise<QueryResult<X>>`.
959
- *
960
- * A query defines a starting working set of nodes and operations that will mutate it.
961
- * From our example,the working set is first the `origin` graph node. Then the `follow`
962
- * operations create a new working set only containing the nodes related to the origin through relation *`a`*.
963
- *
964
- * Multiple relations can be followed at once to create the equivalent of JOIN operations in relational databases.
965
- * ```javascript
966
- * Query.from(origin)
967
- * .follow(a).andReturn()
968
- * .follow(b)
969
- * .follow(c).andReturn()
970
- * .execute();
971
- * ```
972
- * The next operation defines a working set containing the nodes related
973
- * through relation *`b`* to nodes that are related through relation *`a`* to the origin.
974
- * A similar operation is defined for relation `c`.
975
- * At each level, "andReturn()" method can be called to add the current level to the result.
976
- * This will return a Promise of a QueryResult whose values are of type [X, Z]: `Promise<QueryResult<[X, Z]>>`.
977
- *
978
- * Out of the 4 working sets created, only the second and fourth are flagged to be returned and part of the result.
979
- * But the operations in the middle impact this result: e.g.,
980
- * all returned tuples (t1, t2) are object that have an intermediate `i` of type Y.
981
- * such that `t1 --b-> i --c-> t2` but the `i` was not flagged to be returned.
982
- *
983
- * Queries define a path from a starting point following a specific list of relations.
984
- * As explained with our example, only nodes part of a full path can be returned.
985
- *
986
- *
987
- * A query can be executed with 3 different ways:
988
- * - execute(): it runs the query on the datacloud and return the result as a QueryResult.
989
- * - 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.
990
- * - 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.
991
- */
992
- export class Query<T extends CloudObject, R> {
993
-
994
- /**
995
- * Create a query starting from the `CloudObject` specified tag.
996
- * That `CloudObject` must already exist in the local database. In case you have the tag as a `string` and need to get
997
- * the object from a remote database, use {@apilink Query.fromTag} instead.
998
- *
999
- * @param tag tag of the `CloudObject` the query is starting from
1000
- * @param source optional source of the data to answer the query
1001
- * @return an empty Query whose starting point is defined by a single `CloudObject`
1002
- */
1003
- static from<T extends InstanceOrTag>(tag: T, source?: Source): Query<T extends CloudObject ? T : CloudObject, never>;
1004
-
1005
- /**
1006
- * Create a query starting from the `CloudObject` specified tag.
1007
- * The difference with {@apilink Query.from} method is that you specify the data type of the Tag: this allows to execute
1008
- * queries with a tag that is unknown by the local database, on the right remote database.
1009
- *
1010
- * @param tag tag of the `CloudObject` the query is starting from
1011
- * @param dataType data type of the `tag` `CloudObject`.
1012
- * @param source optional source of the data to answer the query
1013
- * @return an empty Query whose starting point is defined by a single `CloudObject`
1014
- */
1015
- static fromTag<T extends CloudObject>(tag: string, dataType: Class<T> | InstanceOrTag, source?: Source): Query<T, never>;
1016
-
1017
- /**
1018
- * Create a query starting from the instances of the specified model. By default, it does include the instances of
1019
- * the models that inherit from the given one.
1020
- *
1021
- * @param model tag/class of the model to find the instances of
1022
- * @param includeInheritance if set to false, the result will not include instances of models that inherit from the given model.
1023
- * @param source optional source of the data to answer the query
1024
- * A source can be the orchestrator ('server'), local ('self') or
1025
- * an external data source (Tag of a `DBConnectorTag`)
1026
- * @return a new query object starting from model instances
1027
- */
1028
- static instancesOf<T extends InstanceOrTag>(model: Class<T> | InstanceOrTag, includeInheritance?: boolean, source?: Source): Query<T extends CloudObject ? T : CloudObject, never>;
1029
-
1030
- /**
1031
- * Create a query starting from a specific root instance, then following relations based on a rule constraint.
1032
- * @param ctx Context in which the {@apilink Query} is observed
1033
- * @param root Starting point of the query. See `root` of {@apilink RootQueryPart}
1034
- * @param rule Discriminate which relations to follow
1035
- * @param source The tag of the source responsible for executing the query
1036
- * @param options options
1037
- */
1038
- static followRule<T extends InstanceOrTag>(ctx: Context, root: T, rule: FollowRule, source?: Source, options?: ImplicitQueryOption): Observable<QueryResult<T extends CloudObject ? T : CloudObject>>;
1039
-
1040
- /**
1041
- * Instruct the query to follow a specified relation. This does not add any key-value pair to the result.
1042
- * (see {@apilink Query.andReturn}). This operation defines a new step in the path defined by our graph query.
1043
- *
1044
- * Example:
1045
- * Find the model of a single object.
1046
- * ```javascript
1047
- * Query.from(myTag).follow(CloudObject.modelRel).andReturn()
1048
- * ```
1049
- *
1050
- * @param relation relation to follow, specifies type and direction
1051
- * @param optional whether or not the relation creates a mandatory path in the graph to be part of the result.
1052
- * @return a new query object
1053
- */
1054
- follow<D extends CloudObject>(relation: Relation<T, D>, optional?: boolean): Query<D, R>;
1055
-
1056
- /**
1057
- * Follow a relation recursively, see {@apilink Query.follow}.
1058
- * The relation that is followed is automatically recursively followed.
1059
- * All nodes that are recursively followed are part of the same step in the path defined by this graph query.
1060
- *
1061
- * @param relation relation to follow recursively, specifies type and direction.
1062
- * @param includeSelf if a starting node includes itself when the relation loops on itself. (default: false)
1063
- * @param optional whether or not the relation creates a mandatory path in the graph to be part of the result. (default: false)
1064
- * @return a new query object
1065
- */
1066
- followRecursively<D extends CloudObject>(relation: Relation<T, D>, includeSelf?: boolean, optional?: boolean): Query<D, R>;
1067
-
1068
- /**
1069
- * The Query.back() function is used to move the cursor of a query backwards to the previous level.
1070
- * This allows the query to start from the place where it was before a Query.follow() call,
1071
- * but with a different relation. The `times` parameter is optional and specifies the number of steps to go back.
1072
- * If hops is not specified, the default value of 1 is used.
1073
- * If a value <= 0 is specified, the output query is the same as the input query.
1074
- *
1075
- * Example:
1076
- * const people = [
1077
- * \{ name: "Alice", children: ["Bob", "Carol"], siblings: ["David"] \},
1078
- * \{ name: "Bob", children: ["Emily"], siblings: ["Alice", "Carol", "David"] \},
1079
- * \{ name: "Carol", children: ["Frank"], siblings: ["Alice", "Bob", "David"] \},
1080
- * \{ name: "David", children: ["Greg"], siblings: ["Alice", "Bob", "Carol"] \},
1081
- * \{ name: "Emily", children: [], siblings: [] \},
1082
- * \{ name: "Frank", children: [], siblings: [] \},
1083
- * \{ name: "Greg", children: [], siblings: [] \}
1084
- * ];
1085
- *
1086
- * // Create a new query starting from Alice
1087
- * const aliceQuery = Query.from("Alice");
1088
- *
1089
- * // Follow the "children" relation to get Alice's children (Bob, Carol)
1090
- * const aliceChildrenQuery = aliceQuery.follow("children").andReturn();
1091
- *
1092
- * // Go back to the previous level and follow the "siblings" relation to get Alice's siblings (David)
1093
- * const aliceSiblingsQuery = aliceChildrenQuery.back().follow("siblings").andReturn();
1094
- *
1095
- * // Execute the query, the output is:
1096
- * Output: [ \{ sibling: 'David', child: 'Bob' \}, \{ sibling: 'David', child: 'Carol' \} ]
1097
- * @param times
1098
- * @return {!Query}
1099
- */
1100
- back(times?: number): Query<CloudObject, R>;
1101
-
1102
- /**
1103
- * Add the current working set of nodes to the result.
1104
- *
1105
- * Example:
1106
- * Query returning the instances of a model and the model itself
1107
- * ```javascript
1108
- * Query
1109
- * .from(myModelTag).andReturn()
1110
- * .follow(CloudObject.modelRel.getInverse()).andReturn()
1111
- * .execute();
1112
- * ```
1113
- * The result tuples are [modelCloudObject, instance1], [modelCloudObject, instance2], ...
1114
- *
1115
- * @return a new query object with the current level flagged to be returned.
1116
- */
1117
- andReturn(): Query<T, R extends never ? T : R extends CloudObject[] ? [...R, T] : [R, T]>;
1118
-
1119
- /**
1120
- * Define a filter operation on the current working set of nodes.
1121
- * It filters out instances that don't match the given {@apilink Predicate}
1122
- *
1123
- * @param predicate
1124
- * @return a new query object with the new filter operation
1125
- */
1126
- filter(predicate: Predicate): Query<T, R>;
1127
-
1128
- /**
1129
- * Cast the type of the instances in the current working set of nodes
1130
- *
1131
- * @param type cast type for `CloudObjects`
1132
- * @return the
1133
- */
1134
- cast<S extends CloudObject>(type: Class<S>): Query<S, R>;
1135
-
1136
- /**
1137
- * Set the maximum number of tuples the executed query will return with an optional offset.
1138
- *
1139
- * Only the last call to limit matters.
1140
- *
1141
- * Example :
1142
- * ```javascript
1143
- * const queryLimited = query.limit(50).follow(myRel2).limit(100, 200).follow(myRel1);
1144
- * // is equivalent to
1145
- * const queryLimited2 = query.follow(myRel2).follow(myRel1).limit(100, 200);
1146
- * ```
1147
- * `queryLimited`, when executed, will return at most the 200th to the 299th (included) results.
1148
- *
1149
- * @param max maximum number of tuple to fetch from the final result
1150
- * @param offset number of skipped tuples for the final result
1151
- * @return new query with limit operation
1152
- */
1153
- limit(max: number, offset?: number): Query<T, R>;
1154
-
1155
- /**
1156
- * Sort the result tuples according to a property of a data type with a specified order.
1157
- **
1158
- * For the sortBy operator to be properly defined, the following must be true:
1159
- * - the property is defined on the instances that will be used for sorting.
1160
- * - the instances on which the sorting property is defined must be part of the result,
1161
- * i.e., `andReturn()` has been called before `sortBy()`.
1162
- *
1163
- * Only the last call to `sortBy` matters as it will be the last comparator set on the query.
1164
- * You should remove previous calls to `sortBy` for the same query.
1165
- *
1166
- * Example :
1167
- * ```javascript
1168
- * const sortQuery = Query
1169
- * .fromInstances(myModel1).andReturn()
1170
- * .sortBy(nameProperty)
1171
- * .follow(rel1).andReturn()
1172
- * .execute();
1173
- * ```
1174
- * This query fetches instances of a model, flags them as first element of result tuples.
1175
- * Then the query follows a relation to other instances and return them as second element of the result tuples.
1176
- * `sortBy` will sort the results according to the `nameProperty` of the first element in the result tuples in
1177
- * ascending order.
1178
- *
1179
- * @param property the property used for sorting
1180
- * @param order optional {@apilink Order.ASC} (default) or {@apilink Order.DESC} order
1181
- * @return new query with sort operation
1182
- */
1183
- sortBy(property: Property<any>, order?: Order): Query<T, R>;
1184
-
1185
- /**
1186
- * @return the query transformed as a tree of QueryPart. To be used by Data Source.
1187
- */
1188
- parse(): RootQueryPart;
1189
-
1190
- /**
1191
- * Execute the query asynchronously on the datacloud and deletes it afterward.
1192
- * In other words, one cannot call execute twice on the same `Query`.
1193
- *
1194
- * @param options options
1195
- * @return promise resolving to query result or failing otherwise.
1196
- */
1197
- execute(options?: QueryOptions): Promise<QueryResult<R extends never ? T : R extends CloudObject | CloudObject[] ? R : never>>;
1198
-
1199
- /**
1200
- * Get an observable to the current value of the QueryResult for this Query instance.
1201
- *
1202
- * The observable gets the new value each time data modification in the datacloud changes the result of the query.
1203
- *
1204
- * The observable gets completed automatically once the specified context is {@apilink Context.onClear | cleared}.
1205
- *
1206
- * @param context {@apilink Context} to which the Observable is attached
1207
- * @param options options
1208
- * @return Observable of QueryResult values
1209
- */
1210
- observe(context: Context, options?: QueryOptions): Observable<QueryResult<R extends never ? T : R extends CloudObject | CloudObject[] ? R : never>>;
1211
-
1212
- /**
1213
- * Execute synchronously the query on the local datacloud cache.
1214
- * `executeFromCache` can only be called once on a given `Query`.
1215
- *
1216
- * @return query result of the execution on the local cache
1217
- */
1218
- executeFromCache(): QueryResult<R extends never ? T : R extends CloudObject | CloudObject[] ? R : never>;
1219
- }
1220
-
1221
- /**
1222
- * A QuerySingle is a Query which follows relations that should be unique between data types (0..1 and 1..1 cardinalities).
1223
- * It returns the instance related to the origin, following the specified relation(s).
1224
- *
1225
- * It acts as a syntactic sugar to avoid having a query result structure and get the first value out of it.
1226
- *
1227
- * A QuerySingle is immutable.
1228
- */
1229
- export class QuerySingle<T extends CloudObject> {
1230
- /**
1231
- * Create a `query single` from a single node.
1232
- * See {@apilink Query.from}
1233
- *
1234
- * @param object starting node for the graph query single
1235
- * @return new query single only accepting 0..1 relations
1236
- */
1237
- static from<T extends CloudObject>(object: InstanceOrTag): QuerySingle<T>;
1238
-
1239
- /**
1240
- * Follow a 0..1 relation
1241
- * See {@apilink Query.follow | Query.follow()}
1242
- *
1243
- * @param relation relation to next node
1244
- * @return new query single with follow operation
1245
- */
1246
- follow<D extends CloudObject>(relation: Relation<T, D>): QuerySingle<D>;
1247
-
1248
- /**
1249
- * See {@apilink Query.cast | Query.cast()}
1250
- *
1251
- * @param type the new type
1252
- * @return query single on a node of the specified type
1253
- */
1254
- cast<S extends CloudObject>(type: Class<S>): QuerySingle<S>;
1255
-
1256
- /**
1257
- * Execute the query single, see {@apilink Query.execute | Query.execute()}
1258
- *
1259
- * @return promise containing the single result or `null`
1260
- */
1261
- execute(): Promise<T | null>;
1262
-
1263
- /**
1264
- * Execute the query single on the local data cloud,
1265
- * see {@apilink Query.executeFromCache | Query.executeFromCache()}
1266
- *
1267
- * @return single result value or `null`
1268
- */
1269
- executeFromCache(): T | null;
1270
- }
1271
-
1272
- /**
1273
- * Predicates are used to filter queries.
1274
- *
1275
- * Example:
1276
- * ```javascript
1277
- * const predicate = Predicate.equals(myNumberProperty, 1);
1278
- * const filteredQuery = Query.instancesOf(myModel).filter(predicate).andReturn();
1279
- * ```
1280
- */
1281
- export class Predicate {
1282
-
1283
- /**
1284
- * Create a predicate to match the specified object(s).
1285
- *
1286
- * @param tags the object or unique identifier (tag) of the objects to look for.
1287
- */
1288
- static in(...tags: InstanceOrTag[]): Predicate;
1289
-
1290
- /**
1291
- * Create a predicate matching a specified property to a specified value.
1292
- *
1293
- * @param property the property to use for filtering
1294
- * @param value the value the property must match
1295
- * @return new Predicate with the equals operation
1296
- */
1297
- static equals<T>(property: Property<T>, value: T): Predicate;
1298
-
1299
- /**
1300
- * Create a predicate matching a specified string property to a specified string.
1301
- *
1302
- * @param property the string property to use for filtering
1303
- * @param value the value the string property must match
1304
- * @param caseSensitive if the match must pay attention to case sensitivity, default value is true
1305
- * @return new Predicate with the contains string operation
1306
- */
1307
- static contains(property: Property<string>, value: string, caseSensitive?: boolean): Predicate;
1308
-
1309
- /**
1310
- * Create a predicate matching a specified string property to a regular expression.
1311
- *
1312
- * @param property the string property to use for filtering
1313
- * @param value the regex or pattern the string property must match
1314
- * @param caseSensitive if the match must pay attention to case sensitivity, default value is true
1315
- * @return new Predicate with the match regex operation
1316
- */
1317
- static regex(property: Property<string>, value: RegExp | string, caseSensitive?: boolean): Predicate;
1318
-
1319
- /**
1320
- * Create a predicate matching a specified number property to a numerical lower bound
1321
- *
1322
- * @param property the number property to user for filtering
1323
- * @param value the lower bound
1324
- * @param strict if the inequality is strict or not
1325
- * @return new Predicate with the greaterThan mathematical operation
1326
- */
1327
- static greaterThan(property: Property<number>, value: number, strict?: boolean): Predicate;
1328
-
1329
- /**
1330
- * Create a predicate matching a specified number property to a numerical upper bound
1331
- *
1332
- * @param property the number property to user for filtering
1333
- * @param value the upper bound
1334
- * @param strict if the inequality is strict or not
1335
- * @return new Predicate with the smallerThan mathematical operation
1336
- */
1337
- static smallerThan(property: Property<number>, value: number, strict?: boolean): Predicate;
1338
-
1339
- /**
1340
- * Create a predicate matching a specified number property to a number property lower bound
1341
- *
1342
- * @param property1 the number property to user for filtering
1343
- * @param property2 the lower bound number property
1344
- * @param strict if the inequality is strict or not
1345
- * @return new Predicate with the greaterThan mathematical operation
1346
- */
1347
- static greaterThan(property1: Property<number>, property2: Property<number>, strict?: boolean): Predicate;
1348
-
1349
- /**
1350
- * Create a predicate matching a specified number property to a number property upper bound
1351
- *
1352
- * @param property1 the number property to user for filtering
1353
- * @param property2 the upper bound number property
1354
- * @param strict if the inequality is strict or not
1355
- * @return new Predicate with the smallerThan mathematical operation
1356
- */
1357
- static smallerThan(property1: Property<number>, property2: Property<number>, strict?: boolean): Predicate;
1358
-
1359
- /**
1360
- * Create an AND composite predicate matching a specified set of predicates
1361
- *
1362
- * @param predicates list of predicates to match
1363
- * @return new Predicate that should match all specified predicates
1364
- */
1365
- static and(...predicates: Predicate[]): Predicate;
1366
-
1367
- /**
1368
- * Create an OR composite predicate matching a specified set of predicates
1369
- *
1370
- * @param predicates list of predicates to match
1371
- * @return new Predicate that should match at least one specified predicate
1372
- */
1373
- static or(...predicates: Predicate[]): Predicate;
1374
-
1375
- /**
1376
- * Create a NOT predicate matching the opposite of a specified predicate
1377
- *
1378
- * @param predicate the predicate to inverse
1379
- * @return new Predicate that match when the specified predicate does not
1380
- */
1381
- static not(predicate: Predicate): Predicate;
1382
- }
1383
-
1384
- /**
1385
- * The sorting order for a {@apilink QueryPart}.
1386
- */
1387
- export enum Order {
1388
- /**
1389
- * Ascending order.
1390
- */
1391
- ASC,
1392
- /**
1393
- * Descending order.
1394
- */
1395
- DESC
1396
- }
1397
-
1398
- /**
1399
- * A class representing the necessary operations to create the result of a query in the client database
1400
- * that emitted the query.
1401
- */
1402
- export class DataResult {
1403
-
1404
- /**
1405
- * Create a new {@apilink DataResult} instance from the specified {@apilink Query}.
1406
- * @param query The {@apilink Query} to create a {@apilink DataResult} from.
1407
- * @return A new {@apilink DataResult} instance.
1408
- */
1409
- static fromQuery(query: Query<CloudObject, any>): DataResult;
1410
-
1411
- /**
1412
- * Create a new Data Type instance with the specified {@apilink InstanceOrTag}, Data Type and properties.
1413
- * @param tag The unique identifier of the object instance to create.
1414
- * @param model The Data Type of the instance to create.
1415
- * @param properties The properties to set on the instance.
1416
- * @return This {@apilink DataResult} instance.
1417
- */
1418
- create(tag: InstanceOrTag, model: InstanceOrTag, properties?: Map<InstanceOrTag, any>): this;
1419
-
1420
- /**
1421
- * Create a relation between two instances with the specified {@apilink Relation}, `from`, and `to` instance tags.
1422
- * @param relation The type of relation to create.
1423
- * @param from The unique identifier of the source instance.
1424
- * @param to The unique identifier of the destination instance.
1425
- * @return This {@apilink DataResult} instance.
1426
- */
1427
- createRelation(relation: InstanceOrTag, from: InstanceOrTag, to: InstanceOrTag): this;
1428
- }
1429
-
1430
- /**
1431
- * Represents an operation that can be performed regarding data type instances.
1432
- */
1433
- export type Operation =
1434
- {
1435
- /** Creates a new instance of a data type with the given properties. */
1436
- type: 'CREATE',
1437
- /** The tag of the new instance. */
1438
- object: string,
1439
- /** The data type tag of the instance being created. */
1440
- model: string,
1441
- /** A map that maps the tag of a property to a new/updated value.
1442
- * You may need to parse this value to store it in your data source (e.g. JS date)
1443
- * */
1444
- properties?: Map<string, any>
1445
- } |
1446
- {
1447
- /** Updates an existing instance of a data type with the given properties. */
1448
- type: 'UPDATE',
1449
- /** The tag of the instance being updated. */
1450
- object: string,
1451
- /** The data type tag of the instance being updated. */
1452
- model: string,
1453
- /** A map that maps the tag of a property to a new/updated value.
1454
- * You may need to parse this value to store it in your data source (e.g. JS date)
1455
- * */
1456
- properties: Map<string, any>
1457
- } |
1458
- {
1459
- /** Deletes an existing instance of a data type. */
1460
- type: 'DELETE',
1461
- /** The tag of the instance being deleted. */
1462
- object: string,
1463
- /** The data type tag of the instance being deleted. */
1464
- model: string
1465
- } |
1466
- {
1467
- /** Creates a new relation between two instances of a data type. */
1468
- type: 'CREATE_RELATION',
1469
- /** The tag of the relation being created. */
1470
- relation: string,
1471
- /** The tag of the starting instance. */
1472
- from: string,
1473
- /** The tag of the ending instance. */
1474
- to: string,
1475
- /** The data type tag of the starting instance. */
1476
- fromModel: string,
1477
- /** The data type tag of the ending instance. */
1478
- toModel: string
1479
- } |
1480
- {
1481
- /** Deletes an existing relation between two instances of a data type. */
1482
- type: 'DELETE_RELATION',
1483
- /** The tag of the relation being deleted. */
1484
- relation: string,
1485
- /** The tag of the starting instance. */
1486
- from: string,
1487
- /** The tag of the ending instance. */
1488
- to: string,
1489
- /** The data type tag of the starting instance. */
1490
- fromModel: string,
1491
- /** The data type tag of the ending instance. */
1492
- toModel: string
1493
- };
1494
- /**
1495
- * Details for a predicate from the OLYMPE query API
1496
- */
1497
- export type ParsedPredicate =
1498
- {
1499
- /** Checks if the instance has any of the specified tags. */
1500
- name: 'IS',
1501
- /** An array of tags to check against. */
1502
- tags: string[]
1503
- } |
1504
- {
1505
- /** Checks if a string type property contains a specific string value. */
1506
- name: 'CONTAINS',
1507
- /** The tag of the property being checked. */
1508
- property: string,
1509
- /** The value being searched for. */
1510
- value: string,
1511
- /** Whether the search should be case-sensitive or not. */
1512
- caseSensitive: boolean
1513
- } |
1514
- {
1515
- /** Checks if a property equals a specific value. */
1516
- name: 'EQUALS',
1517
- /** The tag of the property being checked. */
1518
- property: string,
1519
- /** The value being compared to. */
1520
- value: any
1521
- } |
1522
- {
1523
- /** Checks if a property is greater than or less than a specific value. */
1524
- name: 'INEQUALITY_OPERATOR',
1525
- /** The tag of the property being compared. */
1526
- property: string,
1527
- /** The value being compared to. */
1528
- value: any,
1529
- /** The operator being used in the comparison (e.g. "<", ">"). */
1530
- operator: string,
1531
- /** Whether the comparison should be strict (e.g. "<" vs. "<="). */
1532
- strict: boolean
1533
- } |
1534
- {
1535
- /** Negates a predicate. */
1536
- name: 'NOT',
1537
- /** The predicate being negated. */
1538
- predicate: ParsedPredicate
1539
- } |
1540
- {
1541
- /** Checks if a property matches a regular expression pattern. */
1542
- name: 'REGEX',
1543
- /** The tag of the property being checked. */
1544
- property: string,
1545
- /** The regular expression pattern being matched. */
1546
- pattern: RegExp,
1547
- /** Whether the matching should be case-sensitive or not. */
1548
- caseSensitive: boolean
1549
- };
1550
-
1551
- /**
1552
- * The first part of a {@apilink Query}.
1553
- * It breaks down the starting point of the query.
1554
- */
1555
- export interface RootQueryPart extends QueryPart {
1556
- /**
1557
- * The tag of the starting point of a query built using {@apilink Query.from()}
1558
- * It is the tag of the instance where the first relation followed using {@apilink Query.follow()} starts from.
1559
- * For queries on instances of a data type, started with {@apilink Query.instancesOf()}, this will be null.
1560
- */
1561
- root?: string
1562
- /**
1563
- * The tag of the Data Type of the instance(s) determining the starting point of the query.
1564
- * It is the tag of the Data Type provided to {@apilink Query.instancesOf()}, or the Data Type of the root instance provided
1565
- * to {@apilink Query.from()}
1566
- */
1567
- dataType: string
1568
- /**
1569
- * Specifies whether instances of the data types inheriting from the root data type should be included in the query or not.
1570
- * It is always `false` if `root` is specified.
1571
- */
1572
- inheritance: boolean
1573
- /**
1574
- * Limits the number of results retrieved by the query.
1575
- */
1576
- limit: number
1577
- /**
1578
- * Skips a specified number of results retrieved by the query.
1579
- */
1580
- offset: number
1581
- }
1582
-
1583
- /**
1584
- * A part of a {@apilink Query} that specifies a relationship to traverse.
1585
- */
1586
- export interface QueryPart {
1587
- /**
1588
- * Determines whether the relationship should be traversed recursively and whether the starting object should be included.
1589
- * `false`: Traverse the relationship once.
1590
- * `'EXCLUDE_SELF'`: Traverse the relationship recursively, excluding the starting object.
1591
- * `'INCLUDE_SELF'`: Traverse the relationship recursively, including the starting object.
1592
- */
1593
- recursive: false | 'EXCLUDE_SELF' | 'INCLUDE_SELF',
1594
- /**
1595
- * Specifies a relationship to traverse in the query.
1596
- */
1597
- relation: Relation<any, any>
1598
- /**
1599
- * Determines whether the relationship this part specifies is optional or not to traverse.
1600
- * If `true`, result tuples may have a null if this relationship can not be followed from some data objects.
1601
- * If `false`, all result tuples must contain this relationship.
1602
- */
1603
- optional: boolean,
1604
- /**
1605
- * Determines whether the related objects should be included in the result tuples.
1606
- * If `true`, related objects will be included.
1607
- * If `false`, the related objects are not included.
1608
- * This does not impact whether the relationship is `optional` to be traversed.
1609
- */
1610
- returned: boolean,
1611
- /**
1612
- * Specify if the instances obtained by following the relation should satisfy some condition
1613
- * See {@apilink ParsedPredicate}
1614
- */
1615
- filter: ParsedPredicate[][],
1616
- /**
1617
- * Set a sorting order on the result tuples according to the related objects.
1618
- * It will sort using native order of the type of the property.
1619
- * For multiple parts with sort information, the latest part will prevail.
1620
- */
1621
- sort?: {property: Property<any>, order: Order}
1622
- /**
1623
- * Returns the remaining {@apilink QueryPart}s of the query, empty if no {@apilink QueryPart}s are left.
1624
- */
1625
- next: QueryPart[]
1626
- }
1627
- /**
1628
- * Represents a data source that can be used to retrieve, manipulate and store data outside the Olympe application environment.
1629
- * This class provides several methods for performing CRUD (create, read, update, delete) operations on data,
1630
- * as well as file upload and download functionality.
1631
- *
1632
- * To create a new data source, add a _Data Connector_ in your project in DRAW and download the boilerplate.
1633
- * Then implement or extend the required methods: `init`, `destroy`, `healthCheck`, `executeQuery` and `applyTransaction`
1634
- * For file capabilities, you must also implement: `uploadFileContent`, `downloadFileContent` and `deleteFileContent`
1635
- *
1636
- * The CORE library already provide some default connectors such as PostgreSQL and MSSQL.
1637
- * Their implementation is open source and available in [CORE on Github](https://github.com/olympeio/CORE/tree/master/src/core/data/connectors).
1638
- *
1639
- * @abstract
1640
- * @extends {@apilink CloudObject}
1641
- */
1642
- export abstract class DataSource extends CloudObject {
1643
-
1644
- /**
1645
- * Returns the tag of the data source.
1646
- * @return tag of the data source.
1647
- */
1648
- getId(): string;
1649
-
1650
- /**
1651
- * Retrieves the configuration value associated with the provided key in the data source oConfig.
1652
- * @param key - Key to retrieve the configuration value for.
1653
- * @return The configuration value associated with the provided key.
1654
- */
1655
- getConfig(key: string): any;
1656
-
1657
- /**
1658
- * Initializes the data source connection with custom parameters provided in oConfig.
1659
- * It can also perform a health check to ensure the connection is active.
1660
- * Subscribes to the {@apilink DataSource.observeDataTypes} observable to handle changes to the data types in the data source.
1661
- *
1662
- * @param context a context with the same livecycle as the Data Source
1663
- * @return A promise that resolves with void when initialization is complete. Reject if initialization did not complete.
1664
- */
1665
- protected init(context: BrickContext): Promise<void>;
1666
-
1667
- /**
1668
- * Performs a health check on the data source, checking if the connection is alive.
1669
- * @return A Promise that resolves when the health check is completed successfully, rejects otherwise.
1670
- */
1671
- protected healthCheck(): Promise<void>;
1672
-
1673
- /**
1674
- * Disconnects the data source.
1675
- * @return A Promise that resolves when the data source is destroyed.
1676
- */
1677
- protected destroy(): Promise<void>;
1678
-
1679
- /**
1680
- * Executes the provided {@apilink Query} once and returns a {@apilink DataResult}.
1681
- * @param query - The {@apilink Query} object to execute.
1682
- * @return A Promise that resolves with the {@apilink DataResult} object.
1683
- */
1684
- protected executeQuery(query: Query<CloudObject, any>): Promise<DataResult>;
1685
-
1686
- /**
1687
- * Applies the provided {@apilink Operation} array to the data source as one transaction
1688
- * @param transaction - The {@apilink Operation} array to apply.
1689
- * @param options the options
1690
- * @return A Promise that resolves when the transaction is completed. Rejects when the transaction fails.
1691
- */
1692
- protected applyTransaction(transaction: Operation[], options?: TransactionOptions): Promise<void>;
1693
-
1694
- /**
1695
- * Uploads one file's content to the data source.
1696
- * @param fileTag - The tag of the file.
1697
- * @param dataType - The file data type
1698
- * @param binary - The binary data of the file.
1699
- * @return A Promise that resolves when the file content is uploaded. Rejects otherwise.
1700
- */
1701
- protected uploadFileContent(fileTag: string, dataType: string, binary: Uint8Array): Promise<void>;
1702
-
1703
- /**
1704
- * Downloads one file's content from the data source.
1705
- * @param fileTag - The tag of the file.
1706
- * @param dataType - The file data type
1707
- * @return A Promise that resolves with the binary data of the file as an Uint8Array or a node Readable Stream. Rejects otherwise.
1708
- */
1709
- protected downloadFileContent(fileTag: string, dataType: string): Promise<Uint8Array | Readable>;
1710
-
1711
- /**
1712
- * Deletes file content from the data source.
1713
- * @param fileTag - The tag of the file.
1714
- * @param dataType - The file data type
1715
- * @return A Promise that resolves when the file content is successfully deleted. Rejects otherwise.
1716
- */
1717
- protected deleteFileContent(fileTag: string, dataType: string): Promise<void>;
1718
- }
1719
-
1720
- /**
1721
- * Additional options for transactions to be processed by a data source.
1722
- * - batch: if true, it means that the transaction has been executed using the {@apilink Transaction.executeAsLarge()} function.
1723
- */
1724
- export type TransactionOptions = {
1725
- batch: boolean
1726
- };