@olympeio/runtime-web 9.1.0-dev → 9.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@olympeio/runtime-web",
3
- "version": "9.1.0-dev",
3
+ "version": "9.1.2",
4
4
  "description": "Olympe Web Runtime Environment",
5
5
  "types": "types/index.d.ts",
6
6
  "dependencies": {
package/types/base.d.ts CHANGED
@@ -1,34 +1,74 @@
1
1
  // @ts-ignore
2
2
  import Observable from 'rxjs';
3
- import {Empty, PropertyModel, Query, QueryResult, QuerySingle} from "./cloud";
3
+ import {PropertyModel, Query, QueryResult, QuerySingle} from "./cloud";
4
4
 
5
5
  // **********************************
6
6
  // Primitives
7
7
  // **********************************
8
8
 
9
- declare type Class<T> = { new (): T };
10
-
9
+ declare type Class<T> = { new(): T };
10
+ /**
11
+ * A Tag can be either a `string`, a `HasTag` (CloudObject instance, Property, Relation, ...)
12
+ * or the class constructor for a `CloudObject`
13
+ */
11
14
  export type Tag = string | HasTag | Class<CloudObject>;
12
- export type List<T> = Array<T> | QueryResult<T>;
13
15
 
16
+ export type List<T> = Array<T> | (T extends CloudObject | CloudObject[] ? QueryResult<T> : never);
17
+
18
+ /**
19
+ * Generates a unique olympe tag used to identify `CloudObjects`
20
+ *
21
+ * @return {string} tag
22
+ */
14
23
  export function generateTag(): string;
24
+
25
+ /**
26
+ * Get the unique identifier of the specified Tag as a string
27
+ *
28
+ * If the given tag is a `CloudObject` instance, the tag of that instance is returned.
29
+ * If a class constructor is given, the tag of the corresponding `CloudObject` is returned.
30
+ *
31
+ * @param tag
32
+ * @return string tag of given input
33
+ */
15
34
  export function tagToString(tag: Tag): string;
16
35
 
36
+ /**
37
+ * The HasTag interface defines objects that have a tag.
38
+ * The tag of these objects must be returned by the override method: `getTag()`
39
+ */
17
40
  export interface HasTag {
41
+ /**
42
+ * @return tag of this instance
43
+ */
18
44
  getTag(): string;
19
45
  }
20
46
 
47
+ /**
48
+ * Softcoded application context
49
+ *
50
+ * Contexts have parents and children, they represent the lifecycle of bricks.
51
+ * They contain callbacks executed at specific time of the brick lifespan.
52
+ *
53
+ * Each time a brick is updated with new inputs, {@link clear} is called,
54
+ * executing all callbacks registered with {@link onClear}.
55
+ *
56
+ * When a brick is destroyed, {@link destroy} is called,
57
+ * executing all callbacks registered with {@link onClear} and {@link onDestroy}
58
+ */
21
59
  export abstract class Context {
22
60
  /**
23
61
  * Destroy the current context. It destroys all children context attached to this one and clear their values.
24
62
  * The context cannot be reused after calling this function.
25
63
  */
26
64
  destroy(): void;
65
+
27
66
  /**
28
67
  * Clear the current context: detach and destroys all children context.
29
68
  * The context can be reused.
30
69
  */
31
70
  clear(): void;
71
+
32
72
  /**
33
73
  * Register a callback to execute when the context is destroyed. Return the callback id.
34
74
  *
@@ -36,12 +76,14 @@ export abstract class Context {
36
76
  * @return the callback id
37
77
  */
38
78
  onDestroy(callback: () => void): string;
79
+
39
80
  /**
40
81
  * Remove a previously registered callback with {@link Context#onDestroy} method using its id.
41
82
  *
42
83
  * @param callbackId the id of the callback to unregister
43
84
  */
44
85
  offDestroy(callbackId: string): boolean;
86
+
45
87
  /**
46
88
  * Register a callback to execute every time the context is cleared.
47
89
  * This happens every time the brick is refreshed with new inputs and during the brick destruction.
@@ -60,58 +102,359 @@ export abstract class Context {
60
102
  offClear(id: string): void;
61
103
  }
62
104
 
105
+ /**
106
+ * A `CloudObject` is the base class for all objects that can be persisted and exchanged between Olympe applications.
107
+ * In essence, it represents a remote reference to an object in the data cloud.
108
+ * It is identified by its unique ID, or tag. From a `CloudObject` you can access related `CloudObjects`.
109
+ *
110
+ * A `CloudObject` can be instantiated via the [Tag]{@link Tag} of its model, and it can be instantiated multiple times with different properties values.
111
+ * *Data types* defined in DRAW are such `CloudObjects`, instances of Data types are also `CloudObjects`.
112
+ *
113
+ * **Example:**
114
+ * ```javascript
115
+ * const dcObject = olympe.dc.CloudObject.get(tag);
116
+ * ```
117
+ */
63
118
  export abstract class CloudObject implements HasTag {
119
+ /**
120
+ * The attributes of a CloudObject are called properties. Properties can be of different types,
121
+ * e.g. `Property<string>`, `Property<number>`, Property<Date>`.
122
+ *
123
+ * If a `Person` `CloudObject` has an `age` property, all the instances of `Person` can access
124
+ * the `age` property using the same tag, the tag of the `age` property. This method returns all
125
+ * properties defined by the Data Type associated to this class.
126
+ *
127
+ * @return All properties defined for a data type
128
+ */
64
129
  static getProperties(): Property<any>[];
65
- static getRelations<O extends CloudObject, D extends CloudObject>(this: Class<O>): Relation<O, D>[];
66
- static instancesOf<T extends CloudObject>(this: Class<T>): Query<T, Empty>;
67
130
 
131
+ /**
132
+ * Return all the relations whose origin OR destination is the `CloudObject` associated to this class.
133
+ *
134
+ * @return All relations defined on the current data type. It can be the destination or the origin of the relations.
135
+ */
136
+ static getRelations<O extends CloudObject, D extends CloudObject>(this: Class<O>): (Relation<O, D> | Relation<D, O>)[];
137
+
138
+ /**
139
+ * Return a query starting from all instances of this Data Type.
140
+ *
141
+ * @param model data type to get instances of
142
+ * @return A query starting from the instances of the specified model.
143
+ */
144
+ static instancesOf<T extends CloudObject>(model: Class<T> | Tag): Query<T, never>;
145
+
146
+ /**
147
+ * Get the CloudObject whose tag is specified.
148
+ *
149
+ * This only works if the `CloudObject` is already present in the local datacloud cache.
150
+ * (NB: you can use a {@link Query} to retrieve a distant `CloudObject`)
151
+ *
152
+ * @param tag tag of the `CloudObject`
153
+ * @return `CloudObject` specified by the tag
154
+ */
68
155
  static get<T extends CloudObject>(tag: Tag): T;
156
+ /**
157
+ * Create an instance of the specified data type (or `model`)
158
+ * in the local datacloud (not persisted) with the specified property values.
159
+ *
160
+ * If the model is not specified, it uses `this` DataType.
161
+ *
162
+ * @param properties mappings of (propertyTag -> propertyValue)
163
+ * @param model tag of the model of the `CloudObject` you want to create.
164
+ * @return newly created `CloudObject`
165
+ */
69
166
  static createWith<T>(this: Class<T>, properties: Map<Tag, any>, model?: Tag, source?: string): T;
167
+
168
+ /**
169
+ * Get this `CloudObject` class as a `CloudObject` instance.
170
+ *
171
+ * @return the current data type class as a CloudObject instance.
172
+ */
70
173
  static asInstance<T>(this: Class<T>): T;
71
174
 
175
+ /**
176
+ * Every `CloudObject` has a unique tag.
177
+ *
178
+ * @return tag of the CloudObject
179
+ */
72
180
  getTag(): string;
181
+
182
+ /**
183
+ * Every `CloudObject` can define a value for its `nameProperty`.
184
+ * This method returns the current value of that property for this instance.
185
+ *
186
+ * @return the value of the `name property` of `this`
187
+ */
73
188
  name(): string;
189
+
190
+ /**
191
+ * Every `CloudObject` has a model which defines relations and properties its instances may have.
192
+ *
193
+ * @return the tag of the model of this `CloudObject` instance
194
+ */
74
195
  getModelTag(): string;
196
+
197
+ /**
198
+ * Every `CloudObject` has a model which defines relations and properties its instances may have.
199
+ *
200
+ * @return the model of this `CloudObject` instance as a `CloudObject` instance
201
+ */
75
202
  getModel(): CloudObject;
76
- query(): Query<this, Empty>;
203
+
204
+ /**
205
+ * Create and return a query starting from this instance
206
+ *
207
+ * @return a query starting at this `CloudObject` instance
208
+ */
209
+ query(): Query<this, never>;
210
+
211
+ /**
212
+ * Return the persistence state of this instance.
213
+ *
214
+ * `CloudObject`s can either be volatile, and only live in the local cache. In this case,
215
+ * the `CloudObject` instance is *not* persisted. If a `CloudObject`is persisted, it is stored in an external data store.
216
+ * This means that the instance can be accessible through other Olympe VMs in the same environment.
217
+ *
218
+ * @return a boolean indicating if this object is persisted in a non-volatile way.
219
+ */
77
220
  isPersisted(): boolean;
78
221
  equals(object: any): boolean;
79
222
 
80
- follow<D extends CloudObject>(relation: Relation<this, D>): Query<D, Empty>;
223
+ /**
224
+ * Start a query from this instance and follow the relation given as argument.
225
+ * The query starts from this single instance, and follows a relation to an arbitrary
226
+ * number of destination instances. See [Query.follow]{@link Query#follow}
227
+ *
228
+ * The following are equivalent:
229
+ * ```javascript
230
+ * myCloudObject.follow(relation);
231
+ * myCloudObject.query().follow(relation);
232
+ * ```
233
+ *
234
+ * @param relation the relation to follow from the starting instance (`this`)
235
+ * @return query starting from `this` and following the relation `relation` as first step of the query
236
+ */
237
+ follow<D extends CloudObject>(relation: Relation<this, D>): Query<D, never>;
238
+
239
+ /**
240
+ * Start a `querySingle` from this instance that follows 0..1 relations
241
+ *
242
+ * The query starts from this instance, and follow the relation to a single
243
+ * destination instance. It is equivalent to `QuerySingle.from(this).follow(relation)`.
244
+ *
245
+ * @param relation to follow from this starting instance
246
+ * @return a query following 0-1 relations
247
+ */
81
248
  followSingle<D extends CloudObject>(relation: Relation<this, D>): QuerySingle<D>;
82
249
 
83
250
  // Properties getters
84
- get<T>(property: Property<T>): T | null;
85
- observe<T>(context: Context, property: Property<T>): Observable<T>;
251
+ /**
252
+ * Get the current value of the specified property for this `CloudObject` instance
253
+ *
254
+ * @param property property or property's tag
255
+ * @return property value
256
+ */
257
+ get<T>(property: Property<T> | Tag): T | null;
258
+
259
+ /**
260
+ * Get an observable to the current value of the specified property for this `CloudObject` instance.
261
+ *
262
+ * The observable gets the new value each time the property gets updated in the datacloud.
263
+ * The observable gets completed automatically once the specified context is [cleared]{@link Context#onClear}.
264
+ * If `waitForValue` is set to FALSE (TRUE by default), the first value received by the observable is null if there is no value at call time.
265
+ *
266
+ * @param context [context]{@link Context} to which the Observable is attached
267
+ * @param property property or property's tag to observe
268
+ * @param waitForValue [=true] whether the observable wait for a first value to get a value.
269
+ * @return Observable of property values
270
+ */
271
+ observe<T>(context: Context, property: Property<T> | Tag, waitForValue?: boolean): Observable<T>;
272
+
273
+ /**
274
+ * Get an observable to pair [property, value] for this `CloudObject` instance.
275
+ *
276
+ * The observable gets the new value each time any property gets updated in the datacloud.
277
+ * The observable gets completed automatically once the specified context is [cleared]{@link Context#onClear}.
278
+ *
279
+ * @param context [context]{@link Context} to which the Observable is attached
280
+ * @return Observable of property values
281
+ */
282
+ observeProperties<T>(context: Context): Observable<[Property<T>, T]>;
283
+
284
+ /**
285
+ * Create a Javascript object from this CloudObject current state.
286
+ * @param namesAsKey If true, use the property name instead of the property tag as keys of the generated object.
287
+ * @param inheritedProperties If false, do not including inherited property. By default, it includes them.
288
+ */
289
+ toObject(namesAsKey?: boolean, inheritedProperties?: boolean): Object;
86
290
 
87
291
  // Properties and Relations
292
+ /**
293
+ * Name property for all `CloudObjects`
294
+ */
88
295
  static nameProp: Property<string>;
89
- static instanceRel: Relation<CloudObject, CloudObject>;
296
+
297
+ /**
298
+ * Relation between a `CloudObject`and its model
299
+ * instance --modelRel-> model
300
+ */
90
301
  static modelRel: Relation<CloudObject, CloudObject>;
91
- static containsRel: Relation<CloudObject, CloudObject>;
302
+
303
+ /**
304
+ * Inverse relation of {@link modelRel} between a model and its instances
305
+ * Equivalent to `modelRel.getInverse()`
306
+ */
307
+ static instanceRel: Relation<CloudObject, CloudObject>;
308
+ /**
309
+ * Model `CloudObjects` can inherit relations and properties
310
+ * from another `CloudObject` model to mimic their behaviour.
311
+ *
312
+ * Relation from a model to the CloudObject model it extends.
313
+ * A --extendRel-> B
314
+ * A inherits B's properties and relations.
315
+ */
92
316
  static extendRel: Relation<CloudObject, CloudObject>;
317
+ /**
318
+ * Inverse relation of {@link extendRel}
319
+ */
93
320
  static extendedByRel: Relation<CloudObject, CloudObject>;
321
+ /**
322
+ * Relation between a container (a `CloudObject`) that has children (other `CloudObject`s)
323
+ *
324
+ * For example, from a folder to the contained elements or from a function to the elements needed for that function to run.
325
+ */
326
+ static containsRel: Relation<CloudObject, CloudObject>;
327
+ /**
328
+ * Relation between a model and the properties it defines.
329
+ */
94
330
  static propertyRel: Relation<CloudObject, PropertyModel>;
95
331
  }
96
332
 
333
+ /**
334
+ * A property of a model defines an attribute. A property has a `tag`.
335
+ * Each instance of a model can have value for these defined properties.
336
+ */
97
337
  export interface Property<T> extends HasTag {}
98
338
 
339
+ /**
340
+ * Relations are directed from A -> B and can be followed in either direction.
341
+ */
99
342
  export enum Direction {
343
+ /**
344
+ * For relation A -> B, go to A, the origin
345
+ */
100
346
  ORIGIN = '<',
347
+ /**
348
+ * For relation A -> B, go to B, the destination
349
+ */
101
350
  DESTINATION = '>'
102
351
  }
103
352
 
104
- export class Relation<O extends CloudObject, D extends CloudObject> implements HasTag {
105
- constructor(tag: Tag, direction?: Direction, origin?: Class<O>, destination?: Class<D>);
353
+ interface RelationConstructor {
354
+ /**
355
+ * Create a relation between two CloudObject classes
356
+ * @param tag tag of the relation to create
357
+ * @param direction whether the relation points to the origin or destination
358
+ */
359
+ new(tag: Tag, direction?: Direction): Relation<CloudObject, CloudObject>;
360
+
361
+ /**
362
+ * Create a relation between two CloudObject classes
363
+ * @param tag tag of the relation to create
364
+ * @param direction whether the relation points to the origin or destination
365
+ * @param origin origin class of the relation
366
+ * @param destination destination class of the relation
367
+ */
368
+ new<O extends CloudObject, D extends CloudObject>(tag: Tag, direction?: Direction, origin?: Class<O>, destination?: Class<D>): Relation<O, D>;
369
+ }
370
+
371
+ /**
372
+ * Global variable, constructor of class Relation.
373
+ */
374
+ export declare const Relation: RelationConstructor;
375
+
376
+ /**
377
+ * Relations can be defined between from a `CloudObject` to another, for example between two data types.
378
+ * Relations are directed and have two types: the origin type, the destination type.
379
+ *
380
+ * Defining a relation between two data types means that instances of these data types can be related with that relation.
381
+ */
382
+ export interface Relation<O extends CloudObject, D extends CloudObject> extends HasTag {
383
+
384
+ /**
385
+ * @return tag of the relation
386
+ */
106
387
  getTag(): string;
388
+
389
+ /**
390
+ * @return direction of the relation, whether it points to origin or destination
391
+ */
107
392
  getDirection(): Direction;
393
+
394
+ /**
395
+ * @return class type for the destination of the relation
396
+ */
108
397
  type(): Class<D>;
398
+
399
+ /**
400
+ * @return class type for the origin of the relation
401
+ */
109
402
  originType(): Class<O>;
403
+
404
+ /**
405
+ * @return inverse relation where newOrigin = oldDestination, newDestination = oldOrigin
406
+ */
110
407
  getInverse(): Relation<D, O>;
111
408
  }
112
409
 
410
+ /**
411
+ * Register the class constructor as the class associated to the specified tag.
412
+ *
413
+ * This creates the link between a class and an DataType in the database.
414
+ * Once this link is created, all the instances of the DataType (model)
415
+ * are instantiated as JS objects using the specified class (see [CloudObject.get]{@link CloudObject#get})
416
+ *
417
+ * @param tag tag of the DataType
418
+ * @param object `CloudObject` constructor
419
+ */
113
420
  export function register(tag: Tag, object: Class<CloudObject>): void;
421
+
422
+ /**
423
+ * Create a constant property object which has the specified tag and type to be used in coded bricks.
424
+ *
425
+ * @param tag the property tag
426
+ * @param type type the property holds values of
427
+ * @return newly defined property
428
+ */
114
429
  export function defineProperty<T>(tag: Tag, type?: Class<T>): Property<T>;
430
+
431
+ /**
432
+ * Create a constant relation object between two specified DataTypes.
433
+ *
434
+ * That constant is used especially to create queries see [Query.follow(relation)]{@link Query#follow}
435
+ *
436
+ * @param tag tag of the relation
437
+ * @param origin origin DataType of the relation
438
+ * @param destination destination DataType of the relation. Default is `CloudObject`
439
+ * @param direction direction of the relation, pointing towards origin or destination. Default is `DESTINATION`
440
+ * @return newly defined relation
441
+ */
115
442
  export function defineRelation<O extends CloudObject, D extends CloudObject>(tag: Tag, origin?: Class<O>, destination?: Class<D>, direction?: Direction): Relation<O, D>;
443
+ /**
444
+ * Create a constant relation object between two generic `CloudObjects`
445
+ *
446
+ * That constant is used especially to create queries see [Query.follow(relation)]{@link Query#follow}
447
+ *
448
+ * @param tag tag of the relation
449
+ * @param direction direction of the relation, pointing towards origin or destination. Default is `DESTINATION`
450
+ * @return newly defined relation
451
+ */
116
452
  export function defineRelation(tag: Tag, direction?: Direction): Relation<CloudObject, CloudObject>;
453
+
454
+ /**
455
+ * Returns a constant object corresponding to the specified relation going to the opposite direction
456
+ *
457
+ * @param relation relation to inverse
458
+ * @return inverse relation
459
+ */
117
460
  export function defineInverseRelation<O extends CloudObject, D extends CloudObject>(relation: Relation<O, D>): Relation<D, O>;