@olympeio/runtime-node 9.0.0 → 9.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@olympeio/runtime-node",
3
- "version": "9.0.0",
3
+ "version": "9.0.3",
4
4
  "description": "Olympe Node Runtime Environment",
5
5
  "types": "types/index.d.ts",
6
6
  "dependencies": {
package/types/base.d.ts CHANGED
@@ -6,29 +6,69 @@ import {Empty, PropertyModel, Query, QueryResult, QuerySingle} from "./cloud";
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>;
15
+
12
16
  export type List<T> = Array<T> | QueryResult<T>;
13
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,57 +102,324 @@ 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: Tag): Query<T, Empty>;
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;
69
- static createWith<T>(this: Class<T>, properties: Map<Tag, any>, model?: 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
+ */
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;
203
+
204
+ /**
205
+ * Create and return a query starting from this instance
206
+ *
207
+ * @return a query starting at this `CloudObject` instance
208
+ */
76
209
  query(): Query<this, Empty>;
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;
221
+ equals(object: any): boolean;
78
222
 
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
+ */
79
237
  follow<D extends CloudObject>(relation: Relation<this, D>): Query<D, Empty>;
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
+ */
80
248
  followSingle<D extends CloudObject>(relation: Relation<this, D>): QuerySingle<D>;
81
249
 
82
250
  // Properties getters
83
- get<T>(property: Property<T>): T | null;
84
- 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
+ *
265
+ * @param context [context]{@link Context} to which the Observable is attached
266
+ * @param property property or property's tag to observe
267
+ * @return Observable of property values
268
+ */
269
+ observe<T>(context: Context, property: Property<T> | Tag): Observable<T>;
85
270
 
86
271
  // Properties and Relations
272
+ /**
273
+ * Name property for all `CloudObjects`
274
+ */
87
275
  static nameProp: Property<string>;
88
- static instanceRel: Relation<CloudObject, CloudObject>;
276
+
277
+ /**
278
+ * Relation between a `CloudObject`and its model
279
+ * instance --modelRel-> model
280
+ */
89
281
  static modelRel: Relation<CloudObject, CloudObject>;
90
- static containsRel: Relation<CloudObject, CloudObject>;
282
+
283
+ /**
284
+ * Inverse relation of {@link modelRel} between a model and its instances
285
+ * Equivalent to `modelRel.getInverse()`
286
+ */
287
+ static instanceRel: Relation<CloudObject, CloudObject>;
288
+ /**
289
+ * Model `CloudObjects` can inherit relations and properties
290
+ * from another `CloudObject` model to mimic their behaviour.
291
+ *
292
+ * Relation from a model to the CloudObject model it extends.
293
+ * A --extendRel-> B
294
+ * A inherits B's properties and relations.
295
+ */
91
296
  static extendRel: Relation<CloudObject, CloudObject>;
297
+ /**
298
+ * Inverse relation of {@link extendRel}
299
+ */
92
300
  static extendedByRel: Relation<CloudObject, CloudObject>;
301
+ /**
302
+ * Relation between a container (a `CloudObject`) that has children (other `CloudObject`s)
303
+ *
304
+ * For example, from a folder to the contained elements or from a function to the elements needed for that function to run.
305
+ */
306
+ static containsRel: Relation<CloudObject, CloudObject>;
307
+ /**
308
+ * Relation between a model and the properties it defines.
309
+ */
93
310
  static propertyRel: Relation<CloudObject, PropertyModel>;
94
311
  }
95
312
 
313
+ /**
314
+ * A property of a model defines an attribute. A property has a `tag`.
315
+ * Each instance of a model can have value for these defined properties.
316
+ */
96
317
  export interface Property<T> extends HasTag {}
97
318
 
319
+ /**
320
+ * Relations are directed from A -> B and can be followed in either direction.
321
+ */
98
322
  export enum Direction {
323
+ /**
324
+ * For relation A -> B, go to A, the origin
325
+ */
99
326
  ORIGIN = '<',
327
+ /**
328
+ * For relation A -> B, go to B, the destination
329
+ */
100
330
  DESTINATION = '>'
101
331
  }
102
332
 
333
+ /**
334
+ * Relations can be defined between from a `CloudObject` to another, for example between two data types.
335
+ * Relations are directed and have two types: the origin type, the destination type.
336
+ *
337
+ * Defining a relation between two data types means that instances of these data types can be related with that relation.
338
+ */
103
339
  export class Relation<O extends CloudObject, D extends CloudObject> implements HasTag {
340
+ /**
341
+ * Create a relation between two CloudObject classes
342
+ * @param tag tag of the relation to create
343
+ * @param direction whether the relation points to the origin or destination
344
+ * @param origin origin class of the relation
345
+ * @param destination destination class of the relation
346
+ */
104
347
  constructor(tag: Tag, direction?: Direction, origin?: Class<O>, destination?: Class<D>);
348
+
349
+ /**
350
+ * @return tag of the relation
351
+ */
105
352
  getTag(): string;
353
+
354
+ /**
355
+ * @return direction of the relation, whether it points to origin or destination
356
+ */
106
357
  getDirection(): Direction;
358
+
359
+ /**
360
+ * @return class type for the destination of the relation
361
+ */
107
362
  type(): Class<D>;
363
+
364
+ /**
365
+ * @return class type for the origin of the relation
366
+ */
108
367
  originType(): Class<O>;
368
+
369
+ /**
370
+ * @return inverse relation where newOrigin = oldDestination, newDestination = oldOrigin
371
+ */
109
372
  getInverse(): Relation<D, O>;
110
373
  }
111
374
 
375
+ /**
376
+ * Register the class constructor as the class associated to the specified tag.
377
+ *
378
+ * This creates the link between a class and an DataType in the database.
379
+ * Once this link is created, all the instances of the DataType (model)
380
+ * are instantiated as JS objects using the specified class (see [CloudObject.get]{@link CloudObject#get})
381
+ *
382
+ * @param tag tag of the DataType
383
+ * @param object `CloudObject` constructor
384
+ */
112
385
  export function register(tag: Tag, object: Class<CloudObject>): void;
386
+
387
+ /**
388
+ * Create a constant property object which has the specified tag and type to be used in coded bricks.
389
+ *
390
+ * @param tag the property tag
391
+ * @param type type the property holds values of
392
+ * @return newly defined property
393
+ */
113
394
  export function defineProperty<T>(tag: Tag, type?: Class<T>): Property<T>;
395
+
396
+ /**
397
+ * Create a constant relation object between two specified DataTypes.
398
+ *
399
+ * That constant is used especially to create queries see [Query.follow(relation)]{@link Query#follow}
400
+ *
401
+ * @param tag tag of the relation
402
+ * @param origin origin DataType of the relation
403
+ * @param destination destination DataType of the relation. Default is `CloudObject`
404
+ * @param direction direction of the relation, pointing towards origin or destination. Default is `DESTINATION`
405
+ * @return newly defined relation
406
+ */
114
407
  export function defineRelation<O extends CloudObject, D extends CloudObject>(tag: Tag, origin?: Class<O>, destination?: Class<D>, direction?: Direction): Relation<O, D>;
408
+ /**
409
+ * Create a constant relation object between two generic `CloudObjects`
410
+ *
411
+ * That constant is used especially to create queries see [Query.follow(relation)]{@link Query#follow}
412
+ *
413
+ * @param tag tag of the relation
414
+ * @param direction direction of the relation, pointing towards origin or destination. Default is `DESTINATION`
415
+ * @return newly defined relation
416
+ */
115
417
  export function defineRelation(tag: Tag, direction?: Direction): Relation<CloudObject, CloudObject>;
418
+
419
+ /**
420
+ * Returns a constant object corresponding to the specified relation going to the opposite direction
421
+ *
422
+ * @param relation relation to inverse
423
+ * @return inverse relation
424
+ */
116
425
  export function defineInverseRelation<O extends CloudObject, D extends CloudObject>(relation: Relation<O, D>): Relation<D, O>;