@olympeio/runtime-node 9.4.5 → 9.5.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/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "@olympeio/runtime-node",
3
- "version": "9.4.5",
3
+ "version": "9.5.0",
4
4
  "description": "Olympe Node Runtime Environment",
5
5
  "types": "types/index.d.ts",
6
6
  "dependencies": {
7
7
  "ws": "~8.11.0",
8
8
  "bufferutil": "~4.0.7",
9
9
  "utf-8-validate": "~5.0.10",
10
- "lowdb": "~1.0.0",
11
10
  "rxjs": "7.8.1",
12
11
  "fastify": "~3.29.4"
13
12
  },
package/types/base.d.ts CHANGED
@@ -7,10 +7,10 @@ import {PropertyModel, Query, QueryResult, QuerySingle, Source} from "./cloud";
7
7
  // **********************************
8
8
 
9
9
  /**
10
- * A Tag can be either a `string`, a `HasTag` (CloudObject instance, Property, Relation, ...)
11
- * or the class constructor for a `CloudObject`
10
+ * An InstanceOrTag is an alias for types that represent a CloudObject.
11
+ * It can be either a `string`, a `HasTag` (CloudObject instance, Property, Relation, ...) or the class constructor for a `CloudObject`
12
12
  */
13
- export type Tag = string | HasTag | typeof CloudObject;
13
+ export type InstanceOrTag = string | HasTag | typeof CloudObject;
14
14
 
15
15
  export type List<T> = Array<T> | (T extends CloudObject | CloudObject[] ? QueryResult<T> : never);
16
16
 
@@ -32,7 +32,7 @@ export function generateTag(): string;
32
32
  * @param tag
33
33
  * @return string tag of given input
34
34
  */
35
- export function tagToString(tag: Tag): string;
35
+ export function tagToString(tag: InstanceOrTag): string;
36
36
 
37
37
  /**
38
38
  * The HasTag interface defines objects that have a tag.
@@ -147,7 +147,7 @@ export abstract class CloudObject implements HasTag {
147
147
  * @param model data type to get instances of
148
148
  * @return A query starting from the instances of the specified model.
149
149
  */
150
- static instancesOf<T extends CloudObject>(model: Class<T> | Tag): Query<T, never>;
150
+ static instancesOf<T extends CloudObject>(model: Class<T> | InstanceOrTag): Query<T, never>;
151
151
 
152
152
  /**
153
153
  * Get the CloudObject whose tag is specified.
@@ -159,7 +159,7 @@ export abstract class CloudObject implements HasTag {
159
159
  * @param tag tag of the `CloudObject`
160
160
  * @return `CloudObject` specified by the tag
161
161
  */
162
- static get<T extends CloudObject>(tag: Tag): T;
162
+ static get<T extends CloudObject>(tag: InstanceOrTag): T;
163
163
 
164
164
  /**
165
165
  * Checks whether a `CloudObject` exists or not.
@@ -168,7 +168,7 @@ export abstract class CloudObject implements HasTag {
168
168
  * @param tag tag of the `CloudObject`
169
169
  * @return `true` if `tag` is valid and references a CloudObject.
170
170
  */
171
- static exists(tag: Tag): boolean;
171
+ static exists(tag: InstanceOrTag): boolean;
172
172
 
173
173
  /**
174
174
  * Create an instance of the specified data type (or `model`)
@@ -181,7 +181,7 @@ export abstract class CloudObject implements HasTag {
181
181
  * @param source
182
182
  * @return newly created `CloudObject`
183
183
  */
184
- static createWith<T>(this: Class<T>, properties: Map<Tag, any>, model?: Tag, source?: Source): T;
184
+ static createWith<T>(this: Class<T>, properties: Map<InstanceOrTag, any>, model?: InstanceOrTag, source?: Source): T;
185
185
 
186
186
  /**
187
187
  * Get this `CloudObject` class as a `CloudObject` instance.
@@ -277,7 +277,7 @@ export abstract class CloudObject implements HasTag {
277
277
  * @param property property or property's tag
278
278
  * @return property value
279
279
  */
280
- get<T>(property: Property<T> | Tag): T | null;
280
+ get<T>(property: Property<T> | InstanceOrTag): T | null;
281
281
 
282
282
  /**
283
283
  * Get an observable to the current value of the specified property for this `CloudObject` instance.
@@ -291,7 +291,7 @@ export abstract class CloudObject implements HasTag {
291
291
  * @param waitForValue [=true] whether the observable wait for a first value to get a value.
292
292
  * @return Observable of property values
293
293
  */
294
- observe<T>(context: Context, property: Property<T> | Tag, waitForValue?: boolean): Observable<T>;
294
+ observe<T>(context: Context, property: Property<T> | InstanceOrTag, waitForValue?: boolean): Observable<T>;
295
295
 
296
296
  /**
297
297
  * Get an observable to pair [property, value] for this `CloudObject` instance.
@@ -379,7 +379,7 @@ interface RelationConstructor {
379
379
  * @param tag tag of the relation to create
380
380
  * @param direction whether the relation points to the origin or destination
381
381
  */
382
- new(tag: Tag, direction?: Direction): Relation<CloudObject, CloudObject>;
382
+ new(tag: InstanceOrTag, direction?: Direction): Relation<CloudObject, CloudObject>;
383
383
 
384
384
  /**
385
385
  * Create a relation between two CloudObject classes
@@ -388,7 +388,7 @@ interface RelationConstructor {
388
388
  * @param origin origin class of the relation
389
389
  * @param destination destination class of the relation
390
390
  */
391
- new<O extends CloudObject, D extends CloudObject>(tag: Tag, direction?: Direction, origin?: Class<O>, destination?: Class<D>): Relation<O, D>;
391
+ new<O extends CloudObject, D extends CloudObject>(tag: InstanceOrTag, direction?: Direction, origin?: Class<O>, destination?: Class<D>): Relation<O, D>;
392
392
  }
393
393
 
394
394
  /**
@@ -440,7 +440,7 @@ export interface Relation<O extends CloudObject, D extends CloudObject> extends
440
440
  * @param tag tag of the DataType
441
441
  * @param object `CloudObject` constructor
442
442
  */
443
- export function register(tag: Tag, object: typeof CloudObject): void;
443
+ export function register(tag: InstanceOrTag, object: typeof CloudObject): void;
444
444
 
445
445
  /**
446
446
  * Create a constant property object which has the specified tag and type to be used in coded bricks.
@@ -449,7 +449,7 @@ export function register(tag: Tag, object: typeof CloudObject): void;
449
449
  * @param type type the property holds values of
450
450
  * @return newly defined property
451
451
  */
452
- export function defineProperty<T>(tag: Tag, type?: Class<T>): Property<T>;
452
+ export function defineProperty<T>(tag: InstanceOrTag, type?: Class<T>): Property<T>;
453
453
 
454
454
  /**
455
455
  * Create a constant relation object between two specified DataTypes.
@@ -462,7 +462,7 @@ export function defineProperty<T>(tag: Tag, type?: Class<T>): Property<T>;
462
462
  * @param direction direction of the relation, pointing towards origin or destination. Default is `DESTINATION`
463
463
  * @return newly defined relation
464
464
  */
465
- export function defineRelation<O extends CloudObject, D extends CloudObject>(tag: Tag, origin?: Class<O>, destination?: Class<D>, direction?: Direction): Relation<O, D>;
465
+ export function defineRelation<O extends CloudObject, D extends CloudObject>(tag: InstanceOrTag, origin?: Class<O>, destination?: Class<D>, direction?: Direction): Relation<O, D>;
466
466
  /**
467
467
  * Create a constant relation object between two generic `CloudObjects`
468
468
  *
@@ -472,7 +472,7 @@ export function defineRelation<O extends CloudObject, D extends CloudObject>(tag
472
472
  * @param direction direction of the relation, pointing towards origin or destination. Default is `DESTINATION`
473
473
  * @return newly defined relation
474
474
  */
475
- export function defineRelation(tag: Tag, direction?: Direction): Relation<CloudObject, CloudObject>;
475
+ export function defineRelation(tag: InstanceOrTag, direction?: Direction): Relation<CloudObject, CloudObject>;
476
476
 
477
477
  /**
478
478
  * Returns a constant object corresponding to the specified relation going to the opposite direction
package/types/cloud.d.ts CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  // @ts-ignore
8
8
  import Observable from 'rxjs';
9
- import {Context, CloudObject, Relation, Property, Tag, Class} from "./base";
9
+ import {Context, CloudObject, Relation, Property, InstanceOrTag, Class} from "./base";
10
10
  import {Brick, BrickContext} from './runtime';
11
11
  import {Color} from "./utils";
12
12
 
@@ -128,7 +128,7 @@ export class File extends CloudObject {
128
128
  * @param content byte content of the file
129
129
  * @param mimeType optional mime type of the file
130
130
  */
131
- static setContent(transaction: Transaction, file: Tag, name: string, content: Uint8Array | ArrayBuffer, mimeType?: string);
131
+ static setContent(transaction: Transaction, file: InstanceOrTag, name: string, content: Uint8Array | ArrayBuffer, mimeType?: string);
132
132
 
133
133
  /**
134
134
  * Set the content of a `File` from a specified URL
@@ -138,7 +138,7 @@ export class File extends CloudObject {
138
138
  * @param url url to retrieve content from
139
139
  * @param mimeType optional mime type of the file
140
140
  */
141
- static setURLContent(transaction: Transaction, file: Tag, name: string, url: string, mimeType?: string);
141
+ static setURLContent(transaction: Transaction, file: InstanceOrTag, name: string, url: string, mimeType?: string);
142
142
 
143
143
  /**
144
144
  * @deprecated Please use {@apilink File.setContent}
@@ -246,7 +246,7 @@ export class EnumValue extends CloudObject {
246
246
  * @param name name of the `EnumValue`
247
247
  * @param rank position of the `EnumValue` in the `Enum`
248
248
  */
249
- static createValue(transaction: Transaction, enumModel: Tag, value: string, name?: string, rank?: number): string;
249
+ static createValue(transaction: Transaction, enumModel: InstanceOrTag, value: string, name?: string, rank?: number): string;
250
250
 
251
251
  /**
252
252
  * Name property for an EnumValue
@@ -410,7 +410,7 @@ export class Transaction {
410
410
  * @param tag optional tag of the instance to be created and must be unique
411
411
  * @return the tag of the instance to be created
412
412
  */
413
- create(model: Tag, properties?: Map<Tag, any>, source?: Source, tag?: string): string;
413
+ create(model: InstanceOrTag, properties?: Map<InstanceOrTag, any>, source?: Source, tag?: string): string;
414
414
 
415
415
  /**
416
416
  * Update the property of an instance
@@ -420,7 +420,7 @@ export class Transaction {
420
420
  * @param value the value of the property to be updated to
421
421
  * @return this transaction
422
422
  */
423
- update<T>(instance: Tag, property?: Property<T>, value?: T): this;
423
+ update<T>(instance: InstanceOrTag, property?: Property<T>, value?: T): this;
424
424
 
425
425
  /**
426
426
  * Update multiple properties of a single instance
@@ -429,7 +429,7 @@ export class Transaction {
429
429
  * @param properties map of properties to update
430
430
  * @return this transaction
431
431
  */
432
- multiUpdate(instance: Tag, properties: Map<Tag, any>): this;
432
+ multiUpdate(instance: InstanceOrTag, properties: Map<InstanceOrTag, any>): this;
433
433
 
434
434
  /**
435
435
  * Delete an instance
@@ -437,7 +437,7 @@ export class Transaction {
437
437
  * @param instance tag of the instance to be deleted
438
438
  * @return this transaction
439
439
  */
440
- delete(instance: Tag): this;
440
+ delete(instance: InstanceOrTag): this;
441
441
 
442
442
  /**
443
443
  * Create relation between two instances
@@ -447,7 +447,7 @@ export class Transaction {
447
447
  * @param to tag ofo the DESTINATION instance of the relation
448
448
  * @return this transaction with the create relation operation registered
449
449
  */
450
- createRelation(relation: Tag, from: Tag, to: Tag): this;
450
+ createRelation(relation: InstanceOrTag, from: InstanceOrTag, to: InstanceOrTag): this;
451
451
 
452
452
  /**
453
453
  * Delete a relation between two specified instances.
@@ -459,7 +459,7 @@ export class Transaction {
459
459
  * @param to destination instance tag
460
460
  * @return this transaction
461
461
  */
462
- deleteRelation(relation: Tag, from: Tag, to: Tag): this;
462
+ deleteRelation(relation: InstanceOrTag, from: InstanceOrTag, to: InstanceOrTag): this;
463
463
 
464
464
  /**
465
465
  * Delete any number of the relation starting from specified node.
@@ -478,25 +478,27 @@ export class Transaction {
478
478
  * @param relation deleted relation, indicates relation tag *and* direction
479
479
  * @param origin starting node
480
480
  */
481
- deleteAllRelations(relation: Relation<any, any>, origin: Tag): this;
481
+ deleteAllRelations(relation: Relation<any, any>, origin: InstanceOrTag): this;
482
482
 
483
483
  /**
484
- * Change the persistence mode of all instances in this transaction
484
+ * Set the specified instance to be persisted or not in this transaction.
485
+ * Default value of persist is true.
485
486
  *
486
- * @param persist whether instances are persisted outside
487
- * the local datacloud
487
+ * @param instance the instance to be persisted
488
+ * @param persist determine if the specified instance should be persisted or not (true by default).
488
489
  * @return this transaction
489
490
  */
490
- persist(persist?: boolean): this;
491
+ persist(instance: InstanceOrTag, persist?: boolean): this;
491
492
 
492
493
  /**
493
494
  * Change the persistence mode for a single instance in this transaction
494
495
  *
496
+ * @deprecated use {@apilink Transaction.persist} instead
495
497
  * @param instance the instance to be persisted
496
498
  * @param persist the persisting mode
497
499
  * @return this transaction
498
500
  */
499
- persistInstance(instance: Tag, persist?: boolean): this;
501
+ persistInstance(instance: InstanceOrTag, persist?: boolean): this;
500
502
 
501
503
  /**
502
504
  * Change the source of all instances created in this transaction
@@ -522,7 +524,7 @@ export class Transaction {
522
524
  * @param tag the instance to find the model of
523
525
  * @return the tag of the model of the given instance
524
526
  */
525
- model(tag: Tag): string | null;
527
+ model(tag: InstanceOrTag): string | null;
526
528
 
527
529
  /**
528
530
  * Add all operations of another transaction into this transaction
@@ -873,6 +875,10 @@ export class QueryResult<T extends CloudObject | CloudObject[]> {
873
875
  concat(...others: QueryResult<T>[]): QueryResult<T>;
874
876
  }
875
877
 
878
+ interface QueryOptions {
879
+ cacheBucketName?: string; // Name of the cache bucket - if provided, it means that the query must be cached under this name
880
+ }
881
+
876
882
  /**
877
883
  * A Query is an immutable object used to build queries on the datacloud. It is a graph query builder.
878
884
  * It starts from an `origin` Tag (typically, the `Tag` of a data type or of an instance).
@@ -934,7 +940,7 @@ export class Query<T extends CloudObject, R> {
934
940
  * @param source optional source of the data to answer the query
935
941
  * @return an empty Query whose starting point is defined by a single `CloudObject`
936
942
  */
937
- static from<T extends Tag>(tag: T, source?: Source): Query<T extends CloudObject ? T : CloudObject, never>;
943
+ static from<T extends InstanceOrTag>(tag: T, source?: Source): Query<T extends CloudObject ? T : CloudObject, never>;
938
944
 
939
945
  /**
940
946
  * Create a query starting from the `CloudObject` specified tag.
@@ -946,7 +952,7 @@ export class Query<T extends CloudObject, R> {
946
952
  * @param source optional source of the data to answer the query
947
953
  * @return an empty Query whose starting point is defined by a single `CloudObject`
948
954
  */
949
- static fromTag<T extends CloudObject>(tag: string, dataType: Class<T> | Tag, source?: Source): Query<T, never>;
955
+ static fromTag<T extends CloudObject>(tag: string, dataType: Class<T> | InstanceOrTag, source?: Source): Query<T, never>;
950
956
 
951
957
  /**
952
958
  * Create a query starting from the instances of the specified model. By default, it does include the instances of
@@ -959,7 +965,7 @@ export class Query<T extends CloudObject, R> {
959
965
  * an external data source (Tag of a `DBConnectorTag`)
960
966
  * @return a new query object starting from model instances
961
967
  */
962
- static instancesOf<T extends Tag>(model: Class<T> | Tag, includeInheritance?: boolean, source?: Source): Query<T extends CloudObject ? T : CloudObject, never>;
968
+ static instancesOf<T extends InstanceOrTag>(model: Class<T> | InstanceOrTag, includeInheritance?: boolean, source?: Source): Query<T extends CloudObject ? T : CloudObject, never>;
963
969
 
964
970
  /**
965
971
  * Create a query starting from a specific root instance, then following relations based on a rule constraint.
@@ -967,8 +973,10 @@ export class Query<T extends CloudObject, R> {
967
973
  * @param root Starting point of the query. See `root` of {@apilink RootQueryPart}
968
974
  * @param rule Discriminate which relations to follow
969
975
  * @param source The tag of the source responsible for executing the query
976
+ * @param options options
977
+ * @param options.storeInCacheDB indicates if this follow rule query must be cached in browser DB (IndexedDB) for potential offline use. Default is false.
970
978
  */
971
- static followRule<T extends Tag>(ctx: Context, root: T, rule: FollowRule, source?: Source): Observable<QueryResult<T extends CloudObject ? T : CloudObject>>;
979
+ static followRule<T extends InstanceOrTag>(ctx: Context, root: T, rule: FollowRule, source?: Source, options?: {storeInCacheDB?: boolean}): Observable<QueryResult<T extends CloudObject ? T : CloudObject>>;
972
980
 
973
981
  /**
974
982
  * Instruct the query to follow a specified relation. This does not add any key-value pair to the result.
@@ -1121,14 +1129,13 @@ export class Query<T extends CloudObject, R> {
1121
1129
  parse(): RootQueryPart;
1122
1130
 
1123
1131
  /**
1124
- * Execute the query asynchronously on the datacloud and deletes it afterwards.
1132
+ * Execute the query asynchronously on the datacloud and deletes it afterward.
1125
1133
  * In other words, one cannot call execute twice on the same `Query`.
1126
1134
  *
1127
- * @param context context in which the query must be executed. As this is an asynchronous operation,
1128
- * one has to provide a context that won't be destroyed before the query has a result.
1135
+ * @param options options
1129
1136
  * @return promise resolving to query result or failing otherwise.
1130
1137
  */
1131
- execute(context: Context): Promise<QueryResult<R extends never ? T : R extends CloudObject | CloudObject[] ? R : never>>;
1138
+ execute(options?: QueryOptions): Promise<QueryResult<R extends never ? T : R extends CloudObject | CloudObject[] ? R : never>>;
1132
1139
 
1133
1140
  /**
1134
1141
  * Get an observable to the current value of the QueryResult for this Query instance.
@@ -1138,9 +1145,10 @@ export class Query<T extends CloudObject, R> {
1138
1145
  * The observable gets completed automatically once the specified context is {@apilink Context.onClear | cleared}.
1139
1146
  *
1140
1147
  * @param context {@apilink Context} to which the Observable is attached
1148
+ * @param options options
1141
1149
  * @return Observable of QueryResult values
1142
1150
  */
1143
- observe(context: Context): Observable<QueryResult<R extends never ? T : R extends CloudObject | CloudObject[] ? R : never>>;
1151
+ observe(context: Context, options?: QueryOptions): Observable<QueryResult<R extends never ? T : R extends CloudObject | CloudObject[] ? R : never>>;
1144
1152
 
1145
1153
  /**
1146
1154
  * Execute synchronously the query on the local datacloud cache.
@@ -1167,7 +1175,7 @@ export class QuerySingle<T extends CloudObject> {
1167
1175
  * @param object starting node for the graph query single
1168
1176
  * @return new query single only accepting 0..1 relations
1169
1177
  */
1170
- static from<T extends CloudObject>(object: Tag): QuerySingle<T>;
1178
+ static from<T extends CloudObject>(object: InstanceOrTag): QuerySingle<T>;
1171
1179
 
1172
1180
  /**
1173
1181
  * Follow a 0..1 relation
@@ -1219,7 +1227,7 @@ export class Predicate {
1219
1227
  *
1220
1228
  * @param tags the object or unique identifier (tag) of the objects to look for.
1221
1229
  */
1222
- static in(...tags: Tag[]): Predicate;
1230
+ static in(...tags: InstanceOrTag[]): Predicate;
1223
1231
 
1224
1232
  /**
1225
1233
  * Create a predicate matching a specified property to a specified value.
@@ -1235,7 +1243,7 @@ export class Predicate {
1235
1243
  *
1236
1244
  * @param property the string property to use for filtering
1237
1245
  * @param value the value the string property must match
1238
- * @param caseSensitive if the match must pay attention to case sensitivity, default value is false
1246
+ * @param caseSensitive if the match must pay attention to case sensitivity, default value is true
1239
1247
  * @return new Predicate with the contains string operation
1240
1248
  */
1241
1249
  static contains(property: Property<string>, value: string, caseSensitive?: boolean): Predicate;
@@ -1244,11 +1252,11 @@ export class Predicate {
1244
1252
  * Create a predicate matching a specified string property to a regular expression.
1245
1253
  *
1246
1254
  * @param property the string property to use for filtering
1247
- * @param value the regex the string property must match
1248
- * @param caseSensitive if the match must pay attention to case sensitivity, default value is false
1255
+ * @param value the regex or pattern the string property must match
1256
+ * @param caseSensitive if the match must pay attention to case sensitivity, default value is true
1249
1257
  * @return new Predicate with the match regex operation
1250
1258
  */
1251
- static regex(property: Property<string>, value: RegExp, caseSensitive?: boolean): Predicate;
1259
+ static regex(property: Property<string>, value: RegExp | string, caseSensitive?: boolean): Predicate;
1252
1260
 
1253
1261
  /**
1254
1262
  * Create a predicate matching a specified number property to a numerical lower bound
@@ -1278,7 +1286,7 @@ export class Predicate {
1278
1286
  * @param extend should the predicate also match against inherited models
1279
1287
  * @return new Predicate
1280
1288
  */
1281
- static instanceOf(expectedModel: Tag, extend: boolean): Predicate;
1289
+ static instanceOf(expectedModel: InstanceOrTag, extend: boolean): Predicate;
1282
1290
 
1283
1291
  /**
1284
1292
  * Create a predicate matching a specified number property to a number property lower bound
@@ -1359,7 +1367,7 @@ export class DataResult {
1359
1367
  * @param properties The properties to set on the instance.
1360
1368
  * @return This {@apilink DataResult} instance.
1361
1369
  */
1362
- create(tag: Tag, model: Tag, properties?: Map<Tag, any>): this;
1370
+ create(tag: InstanceOrTag, model: InstanceOrTag, properties?: Map<InstanceOrTag, any>): this;
1363
1371
 
1364
1372
  /**
1365
1373
  * Create a relation between two instances with the specified {@apilink Relation}, `from`, and `to` instance tags.
@@ -1368,7 +1376,7 @@ export class DataResult {
1368
1376
  * @param to The unique identifier of the destination instance.
1369
1377
  * @return This {@apilink DataResult} instance.
1370
1378
  */
1371
- createRelation(relation: Tag, from: Tag, to: Tag): this;
1379
+ createRelation(relation: InstanceOrTag, from: InstanceOrTag, to: InstanceOrTag): this;
1372
1380
  }
1373
1381
 
1374
1382
  /**
package/types/legacy.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // @ts-ignore
2
2
  import Observable from 'rxjs';
3
- import {CloudObject, Direction, HasTag, Property, Relation, Tag} from "./base";
3
+ import {CloudObject, Direction, HasTag, Property, Relation, InstanceOrTag} from "./base";
4
4
  import {Brick, VisualBrick} from "./runtime";
5
5
  /**
6
6
  * The entry of a brick is a static object linked to the brick class itself that is used to make the link between the
@@ -41,7 +41,7 @@ export type FunctionBrick = Brick;
41
41
  DATACLOUD
42
42
  ====================== */
43
43
 
44
- export type InstanceTag = Tag | Entry;
44
+ export type InstanceTag = InstanceOrTag | Entry;
45
45
 
46
46
  /** @deprecated */
47
47
  export function instanceToTag(instance: InstanceTag): string;
@@ -3,7 +3,7 @@
3
3
  // **********************************
4
4
  // @ts-ignore
5
5
  import Observable from 'rxjs';
6
- import {CloudObject, Context, Property, Tag} from "./base";
6
+ import {CloudObject, Context, Property, InstanceOrTag} from "./base";
7
7
 
8
8
  /**
9
9
  * Label of global properties used by convention through bricks and applications.
@@ -94,6 +94,14 @@ export class BrickContext extends Context {
94
94
  */
95
95
  trigger<T>(key: string | Property<T>): this;
96
96
 
97
+ /**
98
+ * Throw the specified error to this context. The error will be propagated until it finds an error handler.
99
+ *
100
+ * @param error the error to throw and propagate in the contexts hierarchy
101
+ * @return this context
102
+ */
103
+ throw(error: ErrorFlow | Error | string): this;
104
+
97
105
  /**
98
106
  * Run a runnable property and returns its context.
99
107
  *
@@ -138,7 +146,7 @@ export class BrickContext extends Context {
138
146
  *
139
147
  * @param modelTag tag of the "type" of context you want to find in the parent tree
140
148
  */
141
- getClosest(modelTag: Tag): BrickContext | null;
149
+ getClosest(modelTag: InstanceOrTag): BrickContext | null;
142
150
 
143
151
  /**
144
152
  * Listen to the creation of the context with the specified id.
package/types/utils.d.ts CHANGED
@@ -3,14 +3,14 @@
3
3
  // **********************************
4
4
 
5
5
  // @ts-ignore
6
- import {Observable} from "rxjs";
6
+ import { BehaviorSubject, Observable } from "rxjs";
7
7
  import {Context} from "./base";
8
8
 
9
9
  // -- Configuration --
10
10
  export class Config {
11
11
  /**
12
12
  * Return the value of the specified parameter.
13
- * Parameters can get their values from the oConfig.json file or be override from the URL / command that opened the application.
13
+ * Parameters can get their values from the oConfig.json file or be overridden from the URL / command that opened the application.
14
14
  *
15
15
  * @param id the parameter id
16
16
  */
@@ -40,6 +40,33 @@ export class Process {
40
40
  * @param callback the callback executed when the runtime terminates.
41
41
  */
42
42
  static onShutdown(callback: () => Promise<void>): () => void;
43
+
44
+ /**
45
+ * Static method that manually triggers a connection attempt to the server to go ONLINE.
46
+ * If you have called {@apilink Process.disconnect()} before, it will cancel the OFFLINE mode,
47
+ * next time the app will be opened, it will try to go ONLINE on its own.
48
+ *
49
+ * Returns a promise that resolves when the server connection is established. If it fails, the promise is rejected.
50
+ */
51
+ static connect(): Promise<void>;
52
+
53
+ /**
54
+ * Static method that manually close the connection to the server to go OFFLINE.
55
+ * Persists the offline status so the app restart offline after being closed.
56
+ * The only way to clean that status is to call {@apilink Process.connect()}.
57
+ *
58
+ * Returns a promise that resolves when the server connection is indeed disconnected and the state is OFFLINE.
59
+ * If the flag `offline.enabled` is not set to true, the promise is rejected.
60
+ */
61
+ static disconnect(): Promise<void>;
62
+
63
+ /**
64
+ * Static method that returns an observable on the connection state: the observable send TRUE if the process is considered
65
+ * as ONLINE and false if not.
66
+ *
67
+ * @param context the context of the brick to garbage collect the observable when not needed anymore.
68
+ */
69
+ static isOnline(context: Context): Observable<boolean>;
43
70
  }
44
71
 
45
72
  // -- Primitive types classes --
@@ -58,7 +85,7 @@ export class Color {
58
85
  /**
59
86
  * Error type used to propagate errors through flows between bricks.
60
87
  */
61
- export class ErrorFlow {
88
+ export class ErrorFlow extends Error {
62
89
  /**
63
90
  * Create a new Error object to be sent in an error flow
64
91
  *
@@ -76,6 +103,11 @@ export class ErrorFlow {
76
103
  * Return the code associated to this error
77
104
  */
78
105
  getCode(): number;
106
+
107
+ /**
108
+ * Return the stack with the hierarchy of bricks that run the one having thrown the error.
109
+ */
110
+ getStack(): string;
79
111
  }
80
112
 
81
113
  /**
@@ -278,6 +310,8 @@ export class Auth {
278
310
 
279
311
  /**
280
312
  * Return the current state of the authentication manager
313
+ *
314
+ * @deprecated use {@apilink Auth.isAuthenticated} instead
281
315
  * @return the current state
282
316
  */
283
317
  static getState(): AuthState;
@@ -304,6 +338,14 @@ export class Auth {
304
338
  */
305
339
  static refreshToken(): Promise<void>;
306
340
 
341
+ /**
342
+ * Returns an `Observable` that is updated each time the authentication status changes.
343
+ * If the user is authenticated, gets true, otherwise (e.g. Guest) get false.
344
+ * @param context The brick context
345
+ * @return An `Observable`
346
+ */
347
+ static isAuthenticated(context: Context): Observable<boolean>
348
+
307
349
  /**
308
350
  * Returns an `Observable` that is updated each time the user tag changes.
309
351
  * @param context The brick context
@@ -389,6 +431,60 @@ export class Auth {
389
431
  static logout(): Promise<void>;
390
432
  }
391
433
 
434
+ export class Cache {
435
+
436
+ /**
437
+ * Return the list of cache ids saved in previous execute or observe
438
+ */
439
+ static getCacheEntriesList(): Observable<Array<string>>;
440
+
441
+ /**
442
+ * Clear the cached data related to this cache id. If not cache id provided => clear all cache ids
443
+ */
444
+ static clearCache(id?: string): Promise<void>;
445
+
446
+ /**
447
+ * Return an Observable which gets TRUE if the Cache is processing some queries
448
+ * to keep the offline database up-to-date
449
+ */
450
+ static isProcessing(): Observable<boolean>
451
+
452
+ /**
453
+ * Return an Observable which emit a new value for each Error encountered when
454
+ * processing data results asynchronously
455
+ */
456
+ static getProcessingErrors(): Observable<boolean>
457
+
458
+ /**
459
+ * Return an observable which gets TRUE if one or more changes must be
460
+ * synced with remoted database
461
+ *
462
+ */
463
+ static hasPendingChanges(): Observable<boolean>;
464
+
465
+ /**
466
+ * Sync the local changes made offline with the online data source
467
+ * Returns an observable in the form [nbChanges, nbSyncedChanges]
468
+ */
469
+ static synchroniseChanges(): Observable<[number, number]>;
470
+
471
+ /**
472
+ * Return a string containing all changes and there related files. This method can be used to "backup" pending changes
473
+ * at any point in time before a synchronisation
474
+ */
475
+ static getPendingChanges(): Promise<string>;
476
+
477
+ /**
478
+ * Clear the list of pending changes without applying or syncing them.
479
+ */
480
+ static clearPendingChanges(): Promise<void>;
481
+
482
+ /**
483
+ * Load the given pending changes into the local offline database
484
+ */
485
+ static loadPendingChanges(data: string): Promise<void>;
486
+ }
487
+
392
488
  declare type SRPData = {
393
489
  username: string,
394
490
  login: string