@olympeio/runtime-node 9.0.5 → 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-node",
3
- "version": "9.0.5",
3
+ "version": "9.1.2",
4
4
  "description": "Olympe Node Runtime Environment",
5
5
  "types": "types/index.d.ts",
6
6
  "dependencies": {
package/types/base.d.ts CHANGED
@@ -1,6 +1,6 @@
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
@@ -13,7 +13,7 @@ declare type Class<T> = { new(): T };
13
13
  */
14
14
  export type Tag = string | HasTag | Class<CloudObject>;
15
15
 
16
- export type List<T> = Array<T> | QueryResult<T>;
16
+ export type List<T> = Array<T> | (T extends CloudObject | CloudObject[] ? QueryResult<T> : never);
17
17
 
18
18
  /**
19
19
  * Generates a unique olympe tag used to identify `CloudObjects`
@@ -141,7 +141,7 @@ export abstract class CloudObject implements HasTag {
141
141
  * @param model data type to get instances of
142
142
  * @return A query starting from the instances of the specified model.
143
143
  */
144
- static instancesOf<T extends CloudObject>(model: Tag): Query<T, Empty>;
144
+ static instancesOf<T extends CloudObject>(model: Class<T> | Tag): Query<T, never>;
145
145
 
146
146
  /**
147
147
  * Get the CloudObject whose tag is specified.
@@ -206,7 +206,7 @@ export abstract class CloudObject implements HasTag {
206
206
  *
207
207
  * @return a query starting at this `CloudObject` instance
208
208
  */
209
- query(): Query<this, Empty>;
209
+ query(): Query<this, never>;
210
210
 
211
211
  /**
212
212
  * Return the persistence state of this instance.
@@ -234,7 +234,7 @@ export abstract class CloudObject implements HasTag {
234
234
  * @param relation the relation to follow from the starting instance (`this`)
235
235
  * @return query starting from `this` and following the relation `relation` as first step of the query
236
236
  */
237
- follow<D extends CloudObject>(relation: Relation<this, D>): Query<D, Empty>;
237
+ follow<D extends CloudObject>(relation: Relation<this, D>): Query<D, never>;
238
238
 
239
239
  /**
240
240
  * Start a `querySingle` from this instance that follows 0..1 relations
@@ -261,12 +261,32 @@ export abstract class CloudObject implements HasTag {
261
261
  *
262
262
  * The observable gets the new value each time the property gets updated in the datacloud.
263
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.
264
265
  *
265
266
  * @param context [context]{@link Context} to which the Observable is attached
266
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.
267
269
  * @return Observable of property values
268
270
  */
269
- observe<T>(context: Context, property: Property<T> | Tag): Observable<T>;
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;
270
290
 
271
291
  // Properties and Relations
272
292
  /**
@@ -330,13 +350,14 @@ export enum Direction {
330
350
  DESTINATION = '>'
331
351
  }
332
352
 
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
- */
339
- export class Relation<O extends CloudObject, D extends CloudObject> implements HasTag {
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
+
340
361
  /**
341
362
  * Create a relation between two CloudObject classes
342
363
  * @param tag tag of the relation to create
@@ -344,7 +365,21 @@ export class Relation<O extends CloudObject, D extends CloudObject> implements H
344
365
  * @param origin origin class of the relation
345
366
  * @param destination destination class of the relation
346
367
  */
347
- constructor(tag: Tag, direction?: Direction, origin?: Class<O>, destination?: Class<D>);
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 {
348
383
 
349
384
  /**
350
385
  * @return tag of the relation
package/types/cloud.d.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  // @ts-ignore
8
8
  import Observable from 'rxjs';
9
9
  import {Context, CloudObject, Relation, Property, Tag, Class} from "./base";
10
- import {BrickContext} from './runtime';
10
+ import {Brick, BrickContext} from './runtime';
11
11
  import {Color} from "./utils";
12
12
 
13
13
  // --------------------------
@@ -178,7 +178,7 @@ export class User extends CloudObject {
178
178
  static loginProp: Property<string>;
179
179
  static saltProp: Property<string>;
180
180
  static verifierProp: Property<string>;
181
- static SAMLNameIdProp: Property<string>;
181
+ static SAMLnameIdProp: Property<string>;
182
182
  }
183
183
 
184
184
  /**
@@ -234,6 +234,69 @@ export class EnumValue extends CloudObject {
234
234
  static rankProp: Property<number>;
235
235
  }
236
236
 
237
+ // -------------------------
238
+ // -- Workflow data types --
239
+ // -------------------------
240
+
241
+ /**
242
+ * A `Workflow` is a sequence of {@link WorkflowState} in which instances of a model goes through.
243
+ * {@link WorkflowState} are linked by {@link WorkflowTransition} that can have an optional _process function_.
244
+ * The `Workflow` also historize the {@link WorkflowState} of the instance and optionally serialize the object itself in a {@link WorkflowObjectState}.
245
+ */
246
+ export class Workflow extends CloudObject {
247
+ /** Is the instance serialization enabled or not */
248
+ static serializationEnabledProp: Property<boolean>;
249
+ /** The model to which the `Workflow` is associated */
250
+ static dataTypeRel: Relation<Workflow, CloudObject>;
251
+ /** The {@link WorkflowState} that are in the `Workflow` */
252
+ static statesRel: Relation<Workflow, WorkflowState>;
253
+ /** The initial {@link WorkflowState} of the `Workflow` */
254
+ static initialStateRel: Relation<Workflow, WorkflowState>;
255
+ }
256
+
257
+ /**
258
+ * A `WorkflowState` defines a state in a {@link Workflow}.
259
+ */
260
+ export class WorkflowState extends CloudObject { /* empty */ }
261
+
262
+ /**
263
+ * A `WorkflowTransition` defines a transition between 2 {@link WorkflowState}.
264
+ * It has a direction (`fromStateRel` to `toStateRel`) and can have an optional _process function_.
265
+ * The _process function_ (`processRefProp`) is automatically triggered when the transition occurs.
266
+ */
267
+ export class WorkflowTransition extends CloudObject {
268
+ /**
269
+ * The `WorkflowTransition` optional _process function_.
270
+ * It has this signature: (ControlFlow, CloudObject, User, Map) -> (ControlFlow, ErrorFlow)
271
+ */
272
+ static processRefProp: Property<Brick>;
273
+ /** The {@link WorkflowState} from which this transition starts */
274
+ static fromStateRel: Relation<WorkflowTransition, WorkflowState>;
275
+ /** The {@link WorkflowState} to which this transition ends */
276
+ static toStateRel: Relation<WorkflowTransition, WorkflowState>;
277
+ }
278
+
279
+ /**
280
+ * A `WorkflowObjectState` represents the state of an instance at a certain point in time.
281
+ * It is automatically created when initializing a {@link Workflow} on an instance or when triggering a {@link WorkflowTransition}.
282
+ */
283
+ export class WorkflowObjectState extends CloudObject {
284
+ /** The name of the {@link Workflow} associated */
285
+ static workflowProp: Property<string>;
286
+ /** The name of the {@link WorkflowState} */
287
+ static stateProp: Property<string>;
288
+ /** The name (login) of the {@link User} */
289
+ static assigneeProp: Property<string>;
290
+ /** The point in time of this object state */
291
+ static dateTimeProp: Property<Date>;
292
+ /** If the {@link Workflow} has serialization enabled, the object's property are saved here in JSON */
293
+ static serializedObjectProp: Property<string>;
294
+ /** The related instance this object state represents */
295
+ static objectRel: Relation<WorkflowObjectState, CloudObject>;
296
+ /** The related instance this object state represents. This relation only reference the current state */
297
+ static currentObjectRel: Relation<WorkflowObjectState, CloudObject>;
298
+ }
299
+
237
300
  // ---------------------------
238
301
  // -- Database transactions --
239
302
  // ---------------------------
@@ -503,7 +566,6 @@ export class BurstTransaction {
503
566
  // ----------------------
504
567
  // -- Database queries --
505
568
  // ----------------------
506
- type Empty = [];
507
569
 
508
570
  /**
509
571
  * A QueryResult is a list of key-value pairs that has been generated as a result of a `Query`.
@@ -521,7 +583,7 @@ type Empty = [];
521
583
  *
522
584
  * A QueryResult can be easily manipulated and transformed to a standard Array.
523
585
  */
524
- export class QueryResult<T> {
586
+ export class QueryResult<T extends CloudObject | CloudObject[]> {
525
587
  /**
526
588
  *@return empty `QueryResult`
527
589
  */
@@ -578,7 +640,6 @@ export class QueryResult<T> {
578
640
  *
579
641
  * @param key the value to search for
580
642
  * @return true if the value `key` is found
581
- * @TODO why T, it's CloudObjects
582
643
  */
583
644
  has(key: T | string): boolean;
584
645
 
@@ -591,7 +652,6 @@ export class QueryResult<T> {
591
652
  *
592
653
  * @param key the value to find the index of
593
654
  * @return index of the argument value or -1 if the value is not found
594
- * TODO why T, it's CloudObjects
595
655
  */
596
656
  indexOf(key: T | string): number;
597
657
 
@@ -676,7 +736,7 @@ export class QueryResult<T> {
676
736
  * @param predicate filter {@link Predicate}
677
737
  * @return array of matching values
678
738
  */
679
- filter(predicate: (entry: T) => boolean): T[];
739
+ filter(predicate: (entry: T, index: number) => boolean): T[];
680
740
 
681
741
  /**
682
742
  * Returns the first value matching the predicate, `null` otherwise.
@@ -687,14 +747,14 @@ export class QueryResult<T> {
687
747
  * @param predicate
688
748
  * @return the first value evaluating to true or `null`
689
749
  */
690
- find(predicate: (entry: T) => boolean): T | null;
750
+ find(predicate: (entry: T, index: number) => boolean): T | null;
691
751
 
692
752
  /**
693
753
  * Execute the specified callback function for each value of this `QueryResult`
694
754
  *
695
755
  * @param callback
696
756
  */
697
- forEach(callback: (entry: T) => void): void;
757
+ forEach(callback: (entry: T, index: number) => void): void;
698
758
 
699
759
  /**
700
760
  * Execute the specified callback function for each value of this `QueryResult`.
@@ -703,7 +763,7 @@ export class QueryResult<T> {
703
763
  * @param callback
704
764
  * @return new array of transformed values
705
765
  */
706
- map<S>(callback: (entry: T) => S): S[];
766
+ map<S>(callback: (entry: T, index: number) => S): S[];
707
767
 
708
768
  /**
709
769
  * Return a sorted copy of this QueryResult.
@@ -726,7 +786,7 @@ export class QueryResult<T> {
726
786
  * @param initial initial value of the accumulator
727
787
  * @return accumulated result applying the `reducer` function iteratively
728
788
  */
729
- reduce<S>(reducer: (accumulator: S, entry: T) => S, initial: S): S;
789
+ reduce<S>(reducer: (accumulator: S, entry: T, index: number) => S, initial: S): S;
730
790
 
731
791
  /**
732
792
  * Return a new QueryResult that contains the concatenation of two or more QueryResults.
@@ -803,7 +863,7 @@ export class QueryResult<T> {
803
863
  * - 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.
804
864
  * - 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.
805
865
  */
806
- export class Query<T extends CloudObject, R extends any[]> {
866
+ export class Query<T extends CloudObject, R> {
807
867
 
808
868
  /**
809
869
  * Create a query starting from the `CloudObject` specified tag
@@ -812,7 +872,7 @@ export class Query<T extends CloudObject, R extends any[]> {
812
872
  * @param source optional source of the data to answer the query
813
873
  * @return an empty Query whose starting point is defined by a single `CloudObject`
814
874
  */
815
- static from<T extends CloudObject>(tag: Tag, source?: string): Query<T, Empty>;
875
+ static from<T extends Tag>(tag: T, source?: string): Query<T extends CloudObject ? T : CloudObject, never>;
816
876
 
817
877
  /**
818
878
  * Create a query starting from the instances of the specified model
@@ -823,7 +883,7 @@ export class Query<T extends CloudObject, R extends any[]> {
823
883
  * an external data source ('<DBConnectorTag>')
824
884
  * @return a new query object starting from model instances
825
885
  */
826
- static instancesOf<T extends CloudObject>(model: Tag, source?: string): Query<T, Empty>;
886
+ static instancesOf<T extends Tag>(model: Class<T> | Tag, source?: string): Query<T extends CloudObject ? T : CloudObject, never>;
827
887
 
828
888
  /**
829
889
  * Instruct the query to follow a specified relation. This does not add any key-value pair to the result.
@@ -866,7 +926,7 @@ export class Query<T extends CloudObject, R extends any[]> {
866
926
  *
867
927
  * @return a new query object with the current level flagged to be returned.
868
928
  */
869
- andReturn(): Query<T, [...R, T]>;
929
+ andReturn(): Query<T, R extends never ? T : R extends CloudObject[] ? [...R, T] : [R, T]>;
870
930
 
871
931
  /**
872
932
  * Define a filter operation on the current working set of nodes.
@@ -942,7 +1002,7 @@ export class Query<T extends CloudObject, R extends any[]> {
942
1002
  * one has to provide a context that won't be destroyed before the query has a result.
943
1003
  * @return promise resolving to query result or failing otherwise.
944
1004
  */
945
- execute(context: Context): Promise<QueryResult<R>>;
1005
+ execute(context: Context): Promise<QueryResult<R extends never ? T : R extends CloudObject | CloudObject[] ? R : never>>;
946
1006
 
947
1007
  /**
948
1008
  * Get an observable to the current value of the QueryResult for this Query instance.
@@ -954,7 +1014,7 @@ export class Query<T extends CloudObject, R extends any[]> {
954
1014
  * @param context [context]{@link Context} to which the Observable is attached
955
1015
  * @return Observable of QueryResult values
956
1016
  */
957
- observe(context: Context): Observable<QueryResult<R>>;
1017
+ observe(context: Context): Observable<QueryResult<R extends never ? T : R extends CloudObject | CloudObject[] ? R : never>>;
958
1018
 
959
1019
  /**
960
1020
  * Execute synchronously the query on the local datacloud cache.
@@ -962,7 +1022,7 @@ export class Query<T extends CloudObject, R extends any[]> {
962
1022
  *
963
1023
  * @return query result of the execution on the local cache
964
1024
  */
965
- executeFromCache(): QueryResult<R>;
1025
+ executeFromCache(): QueryResult<R extends never ? T : R extends CloudObject | CloudObject[] ? R : never>;
966
1026
  }
967
1027
 
968
1028
  /**
package/types/utils.d.ts CHANGED
@@ -65,11 +65,6 @@ export class ServiceRequest {
65
65
  */
66
66
  userTag(): Promise<string>;
67
67
 
68
- /**
69
- * @return the type of the request
70
- */
71
- getType(): RequestType;
72
-
73
68
  /**
74
69
  * Get the request body.
75
70
  *
@@ -170,16 +165,6 @@ export class Service {
170
165
  static observe(service: string, context: Context, payload?: Object): Observable<Object>;
171
166
  }
172
167
 
173
- /**
174
- * Possible types of request coming for services.
175
- */
176
- export enum RequestType {
177
- SEND,
178
- GET,
179
- PUBLISH,
180
- SUBSCRIBE
181
- }
182
-
183
168
  // -- Authentication --
184
169
  /**
185
170
  * A static class that gathers all the required methods to handle the authentication and sessions with Olympe.