@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.
@@ -1,10 +1,11 @@
1
+ import { Class, Context } from "./other";
2
+ import { Direction, HasTag, Property, Relation } from "./composition";
3
+ import { PropertyModel } from "./models";
4
+ import { Query, QuerySingle, QueryResult } from "./query";
5
+ import { Source } from "./data-connector";
6
+ import { Transaction } from "./transaction";
1
7
  // @ts-ignore
2
- import {Observable} from 'rxjs';
3
- import {PropertyModel, Query, QueryResult, QuerySingle, Source} from "./cloud";
4
-
5
- // **********************************
6
- // Primitives
7
- // **********************************
8
+ import { Observable } from "rxjs";
8
9
 
9
10
  /**
10
11
  * A InstanceOrTag can be either a `string`, a `HasTag` (CloudObject instance, Property, Relation, ...)
@@ -12,100 +13,183 @@ import {PropertyModel, Query, QueryResult, QuerySingle, Source} from "./cloud";
12
13
  */
13
14
  export type InstanceOrTag = string | HasTag | typeof CloudObject;
14
15
 
15
- export type List<T> = Array<T> | (T extends CloudObject | CloudObject[] ? QueryResult<T> : never);
16
-
17
- export type Class<T> = {new (): T};
18
-
19
16
  /**
20
- * Generates a unique olympe tag used to identify `CloudObjects`
21
- *
22
- * @return {string} tag
17
+ * File is the main class used to create business objects with a binary/string data content.
18
+ * It is a Data Type so can be extended and associated to a data source.
23
19
  */
24
- export function generateTag(): string;
20
+ export class File extends CloudObject {
25
21
 
26
- /**
27
- * Get the unique identifier of the specified InstanceOrTag as a string
28
- *
29
- * If the given tag is a `CloudObject` instance, the tag of that instance is returned.
30
- * If a class constructor is given, the tag of the corresponding `CloudObject` is returned.
31
- *
32
- * @param tag
33
- * @return string tag of given input
34
- */
35
- export function tagToString(tag: InstanceOrTag): string;
22
+ /**
23
+ * @deprecated because conflict with {@link CloudObject.nameProp}. Use {@link File.fileNameProp} instead.
24
+ */
25
+ static nameProp: Property<string>;
26
+ static fileNameProp: Property<string>;
27
+ static creationDateProp: Property<Date>;
28
+ static modificationDateProp: Property<Date>;
29
+ static mimeTypeProp: Property<string>;
30
+ static urlProp: Property<string>;
36
31
 
37
- /**
38
- * The HasTag interface defines objects that have a tag.
39
- * The tag of these objects must be returned by the overridden method: `getTag()`
40
- */
41
- export interface HasTag {
42
32
  /**
43
- * @return tag of this instance
33
+ * Set the binary content of a specified file
34
+ * @param transaction transaction in which to create the file
35
+ * @param file tag of the file
36
+ * @param name file name
37
+ * @param content byte content of the file
38
+ * @param mimeType optional mime type of the file
44
39
  */
45
- getTag(): string;
46
- }
40
+ static setContent(transaction: Transaction, file: InstanceOrTag, name: string, content: Uint8Array | ArrayBuffer, mimeType?: string): void;
41
+
42
+ /**
43
+ * Set the content of a `File` from a specified URL
44
+ * @param transaction transaction in which to create the file
45
+ * @param file tag of the file
46
+ * @param name filename
47
+ * @param url url to retrieve content from
48
+ * @param mimeType optional mime type of the file
49
+ */
50
+ static setURLContent(transaction: Transaction, file: InstanceOrTag, name: string, url: string, mimeType?: string): void;
51
+
52
+ /**
53
+ * @deprecated Please use {@link File.setContent}
54
+ * Create a `File` from its content
55
+ *
56
+ * @param transaction transaction in which to create the file
57
+ * @param name filename
58
+ * @param content byte content of the file
59
+ * @param mimeType optional mime type of the file
60
+ * @param source optional source where file will be stored ({@link {PredefinedDataSource}} or DBConnector tag)
61
+ * @param tag optional tag for the file
62
+ * @return tag string of the file
63
+ */
64
+ static createFromContent(transaction: Transaction, name: string, content: Uint8Array | ArrayBuffer, mimeType?: string, source?: Source, tag?: string): string;
65
+
66
+ /**
67
+ * @deprecated Please use {@link File.setURLContent}
68
+ * Create a `File` from a specified URL
69
+ * @param transaction transaction in which to create the file
70
+ * @param name filename
71
+ * @param url url to retrieve content from
72
+ * @param mimeType optional mime type of the file
73
+ * @param source optional source where file will be stored ({@link {PredefinedDataSource}} or DBConnector tag)
74
+ * @param tag optional tag for the file
75
+ * @return tag string of the file
76
+ */
77
+ static createFromURL(transaction: Transaction, name: string, url: string, mimeType?: string, source?: Source, tag?: string): string;
78
+
79
+ /**
80
+ * Gets the file content as an ArrayBuffer.
81
+ *
82
+ * @deprecated consider using the new `getContentAsBinary` method returning a Promise instead
83
+ * @param onSuccess (deprecated) callback to execute when byte content has been retrieved successfully
84
+ * @param onFailure (deprecated) callback to execute when content retrieval has failed
85
+ */
86
+ getContentAsBinary(onSuccess: (content: ArrayBuffer) => void, onFailure?: (errMsg: string) => void);
87
+
88
+ /**
89
+ * Gets the file content as an ArrayBuffer.
90
+ *
91
+ * @return promise resolving with the content as a byte array
92
+ */
93
+ getContentAsBinary(): Promise<ArrayBuffer>;
94
+
95
+ /**
96
+ * Get the content of this file and returns it as an UTF-8 string.
97
+ * **Note:** this method should be used only when the file is a text file.
98
+ *
99
+ * @deprecated consider using the new `getContentAsString` method returning a Promise instead
100
+ * @param onSuccess (deprecated) callback to execute when string content has been retrieved successfully
101
+ * @param onFailure (deprecated) callback to execute when content retrieval has failed
102
+ */
103
+ getContentAsString(onSuccess: (content: string) => void, onFailure?: (errMsg: string) => void);
47
104
 
48
- /**
49
- * Softcoded application context
50
- *
51
- * Contexts have parents and children, they represent the lifecycle of bricks.
52
- * They contain callbacks executed at specific time of the brick lifespan.
53
- *
54
- * Each time a brick is updated with new inputs, {@apilink Context.clear} is called,
55
- * executing all callbacks registered with {@apilink Context.onClear}.
56
- *
57
- * When a brick is destroyed, {@apilink Context.destroy} is called,
58
- * executing all callbacks registered with {@apilink Context.onClear} and {@apilink Context.onDestroy}
59
- */
60
- export abstract class Context {
61
105
  /**
62
- * Destroy the current context. It destroys all children context attached to this one and clear their values.
63
- * The context cannot be reused after calling this function.
106
+ * Get the content of this file and returns it as an UTF-8 string.
107
+ * **Note:** this method should be used only when the file is a text file.
108
+ *
109
+ * @return promise resolving with the content as a string
64
110
  */
65
- destroy(): void;
111
+ getContentAsString(): Promise<string>;
66
112
 
67
113
  /**
68
- * Clear the current context: detach and destroys all children context.
69
- * The context can be reused.
114
+ * Gets the URL that gives direct access to the file content:
115
+ * - For files that are external to Olympe, gives the normal URL
116
+ * - For the files stored by Olympe, provides a dataURL, with the content embedded in Base64
117
+ *
118
+ * @deprecated consider using the new `getContentUrl` method returning a Promise instead
119
+ * @param onSuccess (deprecated) callback to execute when content has been retrieved successfully
120
+ * @param onFailure (deprecated) callback to execute when content retrieval has failed
70
121
  */
71
- clear(): void;
122
+ getContentUrl(onSuccess: (content: string) => void, onFailure?: () => void);
72
123
 
73
124
  /**
74
- * Register a callback to execute when the context is destroyed. Return the callback id.
125
+ * Gets the URL that gives direct access to the file content:
126
+ * - For files that are external to Olympe, gives the normal URL
127
+ * - For the files stored by Olympe, provides a dataURL, with the content embedded in Base64
75
128
  *
76
- * @param callback the callback function
77
- * @return the callback id
129
+ * @return promise resolving with the content as a string
78
130
  */
79
- onDestroy(callback: () => void): string;
131
+ getContentUrl(): Promise<string>;
80
132
 
81
133
  /**
82
- * Remove a previously registered callback with {@apilink Context.onDestroy} method using its id.
134
+ * Save this file with specified name
83
135
  *
84
- * @param callbackId the id of the callback to unregister
136
+ * @param name filename
85
137
  */
86
- offDestroy(callbackId: string): boolean;
138
+ saveAs(name: string): void;
139
+ }
140
+
87
141
 
142
+ /**
143
+ * An Enum is an ordered list of string key-values mappings
144
+ */
145
+ export class Enum extends CloudObject {
88
146
  /**
89
- * Register a callback to execute every time the context is cleared.
90
- * This happens every time the brick is refreshed with new inputs and during the brick destruction.
91
- * Return the callback id.
147
+ * Create an empty `Enum?` without any value
148
+ *
149
+ * See {@link EnumValue.createValue} to create values for an Enum.
92
150
  *
93
- * @param callback the callback function
94
- * @return the callback id
151
+ * @param transaction transaction in which to create the Enum
152
+ * @param name optional name of the Enum
153
+ * @return string tag of the Enum object
154
+ */
155
+ create(transaction: Transaction, name?: string): string;
156
+
157
+ /**
158
+ * Get the values defined for this `Enum`
95
159
  */
96
- onClear(callback: () => void): string;
160
+ getValues(): QueryResult<EnumValue>;
161
+ }
97
162
 
163
+ /**
164
+ * An `EnumValue` is a single value part of an `Enum`.
165
+ * It has a `string` name, a rank (its position in the Enum list).
166
+ *
167
+ * The values for `EnumValue` are always stringified.
168
+ */
169
+ export class EnumValue extends CloudObject {
98
170
  /**
99
- * Remove a previously registered callback with {@apilink Context.onClear} method using its id.
171
+ * Add a `EnumValue` to a specified `Enum`
100
172
  *
101
- * @param id the id of the callback to unregister
173
+ * @param transaction transaction in which to add the EnumValue to the Enum
174
+ * @param enumModel `EnumModel` containing the specified `EnumValue`
175
+ * @param value value of the `EnumValue`
176
+ * @param name name of the `EnumValue`
177
+ * @param rank position of the `EnumValue` in the `Enum`
102
178
  */
103
- offClear(id: string): void;
179
+ static createValue(transaction: Transaction, enumModel: InstanceOrTag, value: string, name?: string, rank?: number): string;
104
180
 
105
181
  /**
106
- * Whether the context is destroyed or currently being destroyed.
182
+ * Name property for an EnumValue
183
+ */
184
+ static nameProp: Property<string>;
185
+ /**
186
+ * Value property for an EnumValue
107
187
  */
108
- isDestroyed(): boolean;
188
+ static valueProp: Property<string>;
189
+ /**
190
+ * Rank property for an EnumValue
191
+ */
192
+ static rankProp: Property<number>;
109
193
  }
110
194
 
111
195
  /**
@@ -113,7 +197,7 @@ export abstract class Context {
113
197
  * In essence, it represents a remote reference to an object in the data cloud.
114
198
  * It is identified by its unique ID, or tag. From a `CloudObject` you can access related `CloudObjects`.
115
199
  *
116
- * A `CloudObject` can be instantiated via the {@apilink InstanceOrTag} of its model, and it can be instantiated multiple times with different properties values.
200
+ * A `CloudObject` can be instantiated via the {@link InstanceOrTag} of its model, and it can be instantiated multiple times with different properties values.
117
201
  * *Data types* defined in DRAW are such `CloudObjects`, instances of Data types are also `CloudObjects`.
118
202
  *
119
203
  * **Example:**
@@ -135,7 +219,7 @@ export abstract class CloudObject implements HasTag {
135
219
  static getProperties(): Property<any>[];
136
220
 
137
221
  /**
138
- * Return all the relations whose origin OR destination is the {@apilink CloudObject} associated to this class.
222
+ * Return all the relations whose origin OR destination is the {@link CloudObject} associated to this class.
139
223
  *
140
224
  * @return All relations defined on the current data type. It can be the destination or the origin of the relations.
141
225
  */
@@ -153,7 +237,7 @@ export abstract class CloudObject implements HasTag {
153
237
  * Get the CloudObject whose tag is specified.
154
238
  *
155
239
  * This only works if the `CloudObject` is already present in the local datacloud cache.
156
- * (NB: you can use a {@apilink Query} to retrieve a distant {@apilink CloudObject})
240
+ * (NB: you can use a {@link Query} to retrieve a distant {@link CloudObject})
157
241
  *
158
242
  * @static
159
243
  * @param tag tag of the `CloudObject`
@@ -253,7 +337,7 @@ export abstract class CloudObject implements HasTag {
253
337
  /**
254
338
  * Start a query from this instance and follow the relation given as argument.
255
339
  * The query starts from this single instance, and follows a relation to an arbitrary
256
- * number of destination instances. See {@apilink Query.follow | Query.follow(relation)}
340
+ * number of destination instances. See {@link Query.follow | Query.follow(relation)}
257
341
  *
258
342
  * The following are equivalent:
259
343
  * ```javascript
@@ -279,7 +363,7 @@ export abstract class CloudObject implements HasTag {
279
363
 
280
364
  // Properties getters
281
365
  /**
282
- * Get the current value of the specified property for this {@apilink CloudObject} instance
366
+ * Get the current value of the specified property for this {@link CloudObject} instance
283
367
  *
284
368
  * @param property property or property's tag
285
369
  * @return property value
@@ -290,7 +374,7 @@ export abstract class CloudObject implements HasTag {
290
374
  * Get an observable to the current value of the specified property for this `CloudObject` instance.
291
375
  *
292
376
  * The observable gets the new value each time the property gets updated in the datacloud.
293
- * The observable gets completed automatically once the specified context is {@apilink Context.onClear | cleared}.
377
+ * The observable gets completed automatically once the specified context is {@link Context.onClear | cleared}.
294
378
  * 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.
295
379
  *
296
380
  * @param context context to which the Observable is attached
@@ -304,7 +388,7 @@ export abstract class CloudObject implements HasTag {
304
388
  * Get an observable to pair [property, value] for this `CloudObject` instance.
305
389
  *
306
390
  * The observable gets the new value each time any property gets updated in the datacloud.
307
- * The observable gets completed automatically once the specified context is {@apilink Context.onClear | cleared}.
391
+ * The observable gets completed automatically once the specified context is {@link Context.onClear | cleared}.
308
392
  *
309
393
  * @param context Context to which the Observable will be attached
310
394
  * @return Observable of property values
@@ -320,7 +404,7 @@ export abstract class CloudObject implements HasTag {
320
404
 
321
405
  /**
322
406
  * Create a Javascript object from this CloudObject current state, including its tag and property values.
323
- * It provides the same result as {@apilink CloudObject.toObject | toObject} called with nameAsKey = true and inheritedProperties = false.
407
+ * It provides the same result as {@link CloudObject.toObject | toObject} called with nameAsKey = true and inheritedProperties = false.
324
408
  */
325
409
  toJSON(): Object;
326
410
 
@@ -337,7 +421,7 @@ export abstract class CloudObject implements HasTag {
337
421
  static modelRel: Relation<CloudObject, CloudObject>;
338
422
 
339
423
  /**
340
- * Inverse relation of {@apilink modelRel} between a model and its instances
424
+ * Inverse relation of {@link modelRel} between a model and its instances
341
425
  * Equivalent to `modelRel.getInverse()`
342
426
  */
343
427
  static instancesRel: Relation<CloudObject, CloudObject>;
@@ -351,7 +435,7 @@ export abstract class CloudObject implements HasTag {
351
435
  */
352
436
  static extendRel: Relation<CloudObject, CloudObject>;
353
437
  /**
354
- * Inverse relation of {@apilink extendRel}
438
+ * Inverse relation of {@link extendRel}
355
439
  */
356
440
  static extendedByRel: Relation<CloudObject, CloudObject>;
357
441
  /**
@@ -366,89 +450,13 @@ export abstract class CloudObject implements HasTag {
366
450
  static propertyRel: Relation<CloudObject, PropertyModel>;
367
451
  }
368
452
 
369
- /**
370
- * A property of a model defines an attribute. A property has a `tag`.
371
- * Each instance of a model can have value for these defined properties.
372
- */
373
- export interface Property<T> extends HasTag {}
374
-
375
- /**
376
- * Relations are directed from A to B and can be followed in either direction.
377
- */
378
- export enum Direction {
379
- /**
380
- * For relation A to B, go to A, the origin
381
- */
382
- ORIGIN = '<',
383
- /**
384
- * For relation A to B, go to B, the destination
385
- */
386
- DESTINATION = '>'
387
- }
388
-
389
- interface RelationConstructor {
390
- /**
391
- * Create a relation between two CloudObject classes
392
- * @param tag tag of the relation to create
393
- * @param direction whether the relation points to the origin or destination
394
- */
395
- new(tag: InstanceOrTag, direction?: Direction): Relation<CloudObject, CloudObject>;
396
-
397
- /**
398
- * Create a relation between two CloudObject classes
399
- * @param tag tag of the relation to create
400
- * @param direction whether the relation points to the origin or destination
401
- * @param origin origin class of the relation
402
- * @param destination destination class of the relation
403
- */
404
- new<O extends CloudObject, D extends CloudObject>(tag: InstanceOrTag, direction?: Direction, origin?: Class<O>, destination?: Class<D>): Relation<O, D>;
405
- }
406
-
407
- /**
408
- * Global variable, constructor of class Relation.
409
- */
410
- export declare const Relation: RelationConstructor;
411
-
412
- /**
413
- * Relations can be defined between from a `CloudObject` to another, for example between two data types.
414
- * Relations are directed and have two types: the origin type, the destination type.
415
- *
416
- * Defining a relation between two data types means that instances of these data types can be related with that relation.
417
- */
418
- export interface Relation<O extends CloudObject, D extends CloudObject> extends HasTag {
419
-
420
- /**
421
- * @return tag of the relation
422
- */
423
- getTag(): string;
424
-
425
- /**
426
- * @return direction of the relation, whether it points to origin or destination
427
- */
428
- getDirection(): Direction;
429
-
430
- /**
431
- * @return class type for the destination of the relation
432
- */
433
- type(): Class<D>;
434
-
435
- /**
436
- * @return class type for the origin of the relation
437
- */
438
- originType(): Class<O>;
439
-
440
- /**
441
- * @return inverse relation where newOrigin = oldDestination, newDestination = oldOrigin
442
- */
443
- getInverse(): Relation<D, O>;
444
- }
445
453
 
446
454
  /**
447
455
  * Register the class constructor as the class associated to the specified tag.
448
456
  *
449
457
  * This creates the link between a class and an DataType in the database.
450
458
  * Once this link is created, all the instances of the DataType (model)
451
- * are instantiated as JS objects using the specified class (see {@apilink CloudObject.get})
459
+ * are instantiated as JS objects using the specified class (see {@link CloudObject.get})
452
460
  *
453
461
  * @param tag tag of the DataType
454
462
  * @param object `CloudObject` constructor
@@ -464,10 +472,11 @@ export function register(tag: InstanceOrTag, object: typeof CloudObject): void;
464
472
  */
465
473
  export function defineProperty<T>(tag: InstanceOrTag, type?: Class<T>): Property<T>;
466
474
 
475
+
467
476
  /**
468
477
  * Create a constant relation object between two specified DataTypes.
469
478
  *
470
- * That constant is used especially to create queries see {@apilink Query.follow | Query.follow(relation)}
479
+ * That constant is used especially to create queries see {@link Query.follow | Query.follow(relation)}
471
480
  *
472
481
  * @param tag tag of the relation
473
482
  * @param origin origin DataType of the relation
@@ -479,7 +488,7 @@ export function defineRelation<O extends CloudObject, D extends CloudObject>(tag
479
488
  /**
480
489
  * Create a constant relation object between two generic `CloudObjects`
481
490
  *
482
- * That constant is used especially to create queries see {@apilink Query.follow | Query.follow(relation)}
491
+ * That constant is used especially to create queries see {@link Query.follow | Query.follow(relation)}
483
492
  *
484
493
  * @param tag tag of the relation
485
494
  * @param direction direction of the relation, pointing towards origin or destination. Default is `DESTINATION`
@@ -487,6 +496,7 @@ export function defineRelation<O extends CloudObject, D extends CloudObject>(tag
487
496
  */
488
497
  export function defineRelation(tag: InstanceOrTag, direction?: Direction): Relation<CloudObject, CloudObject>;
489
498
 
499
+
490
500
  /**
491
501
  * Returns a constant object corresponding to the specified relation going to the opposite direction
492
502
  *
package/types/index.d.ts CHANGED
@@ -1,5 +1,11 @@
1
- export * from './base';
2
1
  export * from './runtime';
3
- export * from './cloud';
4
- export * from './utils';
2
+ export * from './query';
3
+ export * from './transaction';
4
+ export * from './data';
5
+ export * from './service';
6
+ export * from './composition';
7
+ export * from './transaction-advanced';
8
+ export * from './data-connector';
9
+ export * from './models';
10
+ export * from './other';
5
11
  export * from './legacy';
package/types/legacy.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  // @ts-ignore
2
2
  import {Observable} from 'rxjs';
3
- import {CloudObject, Direction, HasTag, Property, Relation, InstanceOrTag} from "./base";
3
+ import {CloudObject, InstanceOrTag} from "./data";
4
+ import {Direction, HasTag, Property, Relation} from "./composition";
4
5
  import {Brick, VisualBrick} from "./runtime";
5
6
  /**
6
7
  * The entry of a brick is a static object linked to the brick class itself that is used to make the link between the