@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.
- package/import/olympe.dm/datamodel/.Primordial.newInst.json +1 -1
- package/import/olympe.dm/datamodel/05_permission_schema.updateInst.json +1 -1
- package/import/olympe.sc/datamodel/01_language.newInst.json +1 -1
- package/index.js +988 -940
- package/package.json +3 -2
- package/types/composition.d.ts +122 -0
- package/types/data-connector.d.ts +356 -0
- package/types/{base.d.ts → data.d.ts} +168 -158
- package/types/index.d.ts +9 -3
- package/types/legacy.d.ts +2 -1
- package/types/models.d.ts +203 -0
- package/types/{utils.d.ts → other.d.ts} +158 -285
- package/types/query.d.ts +726 -0
- package/types/runtime.d.ts +49 -35
- package/types/service.d.ts +183 -0
- package/types/transaction-advanced.d.ts +34 -0
- package/types/transaction.d.ts +266 -0
- package/types/cloud.d.ts +0 -1726
package/types/runtime.d.ts
CHANGED
|
@@ -1,24 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { CloudObject, InstanceOrTag } from "./data";
|
|
2
|
+
import { Context } from "./other";
|
|
3
|
+
import { Property } from "./composition";
|
|
4
4
|
// @ts-ignore
|
|
5
|
-
import {Observable} from
|
|
6
|
-
import {CloudObject, Context, Property, InstanceOrTag} from "./base";
|
|
7
|
-
import {ErrorFlow} from "./utils";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Label of global properties used by convention through bricks and applications.
|
|
11
|
-
* Example of use:
|
|
12
|
-
*
|
|
13
|
-
* const transaction = context.get(TRANSACTION).
|
|
14
|
-
*
|
|
15
|
-
* The brick "Begin Transaction" push a transaction inside the context so it can be reused by other bricks before the "End Transaction" brick.
|
|
16
|
-
*/
|
|
17
|
-
export enum GlobalProperties {
|
|
18
|
-
EDITION = '__editionMode',
|
|
19
|
-
PRODUCTION = '__production',
|
|
20
|
-
TRANSACTION = '__transaction'
|
|
21
|
-
}
|
|
5
|
+
import { Observable } from "rxjs";
|
|
22
6
|
|
|
23
7
|
export class BrickContext extends Context {
|
|
24
8
|
/**
|
|
@@ -162,16 +146,6 @@ export class BrickContext extends Context {
|
|
|
162
146
|
onContext(id: string, callback: (context: BrickContext) => void): () => void;
|
|
163
147
|
}
|
|
164
148
|
|
|
165
|
-
/**
|
|
166
|
-
* Static function that must be called for every brick used in an application.
|
|
167
|
-
* It registers the brick code in the registry with the specified tag and return the Entry for that brick.
|
|
168
|
-
*
|
|
169
|
-
* @param tag the brick unique id
|
|
170
|
-
* @param brick the brick class
|
|
171
|
-
* @param args Extra arguments
|
|
172
|
-
*/
|
|
173
|
-
export function registerBrick(tag: string, brick: new () => Brick, ...args: any): void;
|
|
174
|
-
|
|
175
149
|
export abstract class Brick extends CloudObject {
|
|
176
150
|
|
|
177
151
|
/**
|
|
@@ -233,13 +207,13 @@ export abstract class Brick extends CloudObject {
|
|
|
233
207
|
protected destroy($: BrickContext): void;
|
|
234
208
|
|
|
235
209
|
/**
|
|
236
|
-
* @deprecated use {@
|
|
210
|
+
* @deprecated use {@link Brick.init} instead
|
|
237
211
|
* @param $ the brick context
|
|
238
212
|
*/
|
|
239
213
|
protected onInit($: BrickContext): void;
|
|
240
214
|
|
|
241
215
|
/**
|
|
242
|
-
* @deprecated use {@
|
|
216
|
+
* @deprecated use {@link Brick.update} instead
|
|
243
217
|
* @param $ the brick context
|
|
244
218
|
* @param inputs array of input values
|
|
245
219
|
* @param outputs array of output setter functions.
|
|
@@ -247,14 +221,14 @@ export abstract class Brick extends CloudObject {
|
|
|
247
221
|
protected onUpdate($: BrickContext, inputs: Array<any>, outputs: Array<(value: any) => void>): void;
|
|
248
222
|
|
|
249
223
|
/**
|
|
250
|
-
* @deprecated use {@
|
|
224
|
+
* @deprecated use {@link Brick.destroy} instead
|
|
251
225
|
* @param $ the brick context
|
|
252
226
|
*/
|
|
253
227
|
protected onDestroy($: BrickContext): void;
|
|
254
228
|
}
|
|
255
229
|
|
|
256
230
|
/**
|
|
257
|
-
* @deprecated use {@
|
|
231
|
+
* @deprecated use {@link Brick} instead
|
|
258
232
|
*/
|
|
259
233
|
export abstract class ActionBrick extends Brick { }
|
|
260
234
|
|
|
@@ -294,9 +268,49 @@ export abstract class VisualBrick extends Brick {
|
|
|
294
268
|
/**
|
|
295
269
|
* Called when the DOM Element associated to that brick has been added to the document and is ready to be drawn.
|
|
296
270
|
*
|
|
297
|
-
* @deprecated override {@
|
|
271
|
+
* @deprecated override {@link VisualBrick.render} and {@link VisualBrick.updateParent} instead.
|
|
298
272
|
* @param $ the brick context
|
|
299
273
|
* @param domElement the associated DOM Element
|
|
300
274
|
*/
|
|
301
275
|
protected draw($: BrickContext, domElement: Element);
|
|
302
276
|
}
|
|
277
|
+
|
|
278
|
+
// -- Configuration --
|
|
279
|
+
export class Config {
|
|
280
|
+
/**
|
|
281
|
+
* Return the value of the specified parameter.
|
|
282
|
+
* Parameters can get their values from the oConfig.json file or be overridden from the URL / command that opened the application.
|
|
283
|
+
*
|
|
284
|
+
* @param id the parameter id
|
|
285
|
+
*/
|
|
286
|
+
static getParameter(id: string): unknown | undefined;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Error type used to propagate errors through flows between bricks.
|
|
292
|
+
*/
|
|
293
|
+
export class ErrorFlow extends Error {
|
|
294
|
+
/**
|
|
295
|
+
* Create a new Error object to be sent in an error flow
|
|
296
|
+
*
|
|
297
|
+
* @param message the error message
|
|
298
|
+
* @param code the code associated to the error
|
|
299
|
+
*/
|
|
300
|
+
static create(message: string, code: number): ErrorFlow;
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Return the message of this error
|
|
304
|
+
*/
|
|
305
|
+
getMessage(): string;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Return the code associated to this error
|
|
309
|
+
*/
|
|
310
|
+
getCode(): number;
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Return the stack with the hierarchy of bricks that run the one having thrown the error.
|
|
314
|
+
*/
|
|
315
|
+
getStack(): string;
|
|
316
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { Context } from "./other";
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
import { Observable } from "rxjs";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Types of requests that can be received in a Service.
|
|
7
|
+
* This is used to know what method call on the request to answer the requester.
|
|
8
|
+
*/
|
|
9
|
+
export enum ServiceRequestType {
|
|
10
|
+
PUBLISH,
|
|
11
|
+
SEND,
|
|
12
|
+
GET,
|
|
13
|
+
SUBSCRIBE
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A request consumed by a service.
|
|
18
|
+
*/
|
|
19
|
+
export class ServiceRequest {
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Get the requesting client's user tag.
|
|
23
|
+
*
|
|
24
|
+
* @return the user tag
|
|
25
|
+
*/
|
|
26
|
+
userTag(): Promise<string>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Return the type of this Service Request
|
|
30
|
+
*
|
|
31
|
+
* @return the type of this request.
|
|
32
|
+
*/
|
|
33
|
+
requestType(): ServiceRequestType;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Get the request body.
|
|
37
|
+
*
|
|
38
|
+
* @return the request body
|
|
39
|
+
*/
|
|
40
|
+
body(): Object;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Acknowledge the request. Used for SEND requests
|
|
44
|
+
*
|
|
45
|
+
* @return a Promise that completes once the ack is sent
|
|
46
|
+
*/
|
|
47
|
+
ack(): Promise<void>;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Send a reply to the request with a content payload. Used for GET requests
|
|
51
|
+
*
|
|
52
|
+
* @param payload the payload of the reply
|
|
53
|
+
* @return a Promise that completes once the reply is sent
|
|
54
|
+
*/
|
|
55
|
+
reply(payload: Object): Promise<void>;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Send the topic where the requester should listen to get notifications. Used for OBSERVE requests.
|
|
59
|
+
* The string returned by the Promise is the id of that subscription. It can be used in parallel with
|
|
60
|
+
* the {@link Service.setUnsubscriptionHandler} method of the service to execute instructions when a subscription is removed.
|
|
61
|
+
*
|
|
62
|
+
* @param topic the topic where the client should
|
|
63
|
+
* @return a Promise that completes once the consumer has started to the listen to notifications. The
|
|
64
|
+
*/
|
|
65
|
+
notifyOn(topic: string): Promise<string>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Reply to the request with and error.
|
|
69
|
+
*
|
|
70
|
+
* @param error the error to send
|
|
71
|
+
* @return a Promise that completes once the error is sent
|
|
72
|
+
*/
|
|
73
|
+
fail(error: Error): Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
interface ServiceConfig {
|
|
77
|
+
/**
|
|
78
|
+
* After how much time (in ms) the message must be considered as timeout by the service.
|
|
79
|
+
*/
|
|
80
|
+
timeout?: number
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
interface SubscriptionServiceConfig extends ServiceConfig {
|
|
84
|
+
/**
|
|
85
|
+
* A callback to be called in case the subscription to the service is re-sent to the service (eg: after a reconnection).
|
|
86
|
+
*/
|
|
87
|
+
onRetry?: () => void;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* A service that processes requests coming from other VMs connected to the data cloud.
|
|
92
|
+
*/
|
|
93
|
+
export class Service {
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Create a new instance of the service with the specified id.
|
|
97
|
+
* It uses the context to make the lifecycle of the service related to the context one.
|
|
98
|
+
*
|
|
99
|
+
* @param serviceId the service id
|
|
100
|
+
* @param context the context of that service.
|
|
101
|
+
*/
|
|
102
|
+
constructor(serviceId: string, context: Context);
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Start and listen to incoming requests.
|
|
106
|
+
*/
|
|
107
|
+
listen(): Observable<ServiceRequest>;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Set a function to be executed each time a subscription to that service is closed.
|
|
111
|
+
* The function receives the subscription id that has been closed.
|
|
112
|
+
* The subscription id is the one that has been set and returned by the {@link ServiceRequest.notifyOn} method.
|
|
113
|
+
*
|
|
114
|
+
* @param handler the handler function to be executed when a subscription is closed.
|
|
115
|
+
* @return this Service instance.
|
|
116
|
+
*/
|
|
117
|
+
setUnsubscriptionHandler(handler: (subId: string) => void): this
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Stop the service.
|
|
121
|
+
*/
|
|
122
|
+
stop(): void
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Publish a message on the specified service without waiting for any acknowledge
|
|
126
|
+
*
|
|
127
|
+
* @param service the service id
|
|
128
|
+
* @param payload
|
|
129
|
+
*/
|
|
130
|
+
static publish(service: string, payload: Object): Promise<void>;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Returns a Publisher to publish a list of messages to the same service handler, to ensure the messages published
|
|
134
|
+
* are processed by the same processor instead of being balanced between the potential multiple instances of the service.
|
|
135
|
+
*
|
|
136
|
+
* @param service the service id
|
|
137
|
+
*/
|
|
138
|
+
static getPublisher(service: string): Publisher;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Send a request to a {@link Service} and wait for an ack.
|
|
142
|
+
*
|
|
143
|
+
* @param service the service id
|
|
144
|
+
* @param payload the message payload, optional
|
|
145
|
+
* @param config optional parameters for the message
|
|
146
|
+
* @return a Promise that completes when the call has been executed
|
|
147
|
+
*/
|
|
148
|
+
static send(service: string, payload?: Object, config?: ServiceConfig): Promise<void>;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Send a request to a {@link Service} and wait for a reply with a payload..
|
|
152
|
+
*
|
|
153
|
+
* @param service the service id
|
|
154
|
+
* @param payload the message payload
|
|
155
|
+
* @param config optional parameters for the message
|
|
156
|
+
* @return a Promise wrapping the resulting value
|
|
157
|
+
*/
|
|
158
|
+
static get(service: string, payload: Object, config?: ServiceConfig): Promise<Object>;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Send a request to a {@link Service} and subscribe to notifications published from that service.
|
|
162
|
+
*
|
|
163
|
+
* @param service the service id
|
|
164
|
+
* @param context the context used to link its lifecycle to this subscription
|
|
165
|
+
* @param payload the message payload, optional
|
|
166
|
+
* @param config optional parameters for the message
|
|
167
|
+
* @return an Observable emitting notifications
|
|
168
|
+
*/
|
|
169
|
+
static observe(service: string, context: Context, payload?: Object, config?: SubscriptionServiceConfig): {observable: Observable<Object>, publisher: Publisher};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* A publisher is used to send messages to a subscription handler.
|
|
174
|
+
*/
|
|
175
|
+
export interface Publisher {
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Publish a message to the subscription handler.
|
|
179
|
+
*
|
|
180
|
+
* @param payload the message payload
|
|
181
|
+
*/
|
|
182
|
+
publish(payload: Object): Promise<void>;
|
|
183
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { CloudObject } from "./data";
|
|
2
|
+
import { Property } from "./composition";
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import { Observable } from "rxjs";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* BurstTransactions are designed to continuously apply high rates of updates on properties (FIFO ordering).
|
|
8
|
+
* The only operation supported by BurstTransactions is to update properties of an instance.
|
|
9
|
+
*
|
|
10
|
+
* Unlike classical Transactions, a burst transaction preserves the order of update operations and
|
|
11
|
+
* is designed to handle many updates per second for smooth shared animations.
|
|
12
|
+
*
|
|
13
|
+
* Example of use:
|
|
14
|
+
* A marker representing a red dot on the screen which coordinate properties are controlled by motion sensors of an IoT device
|
|
15
|
+
* should use BurstTransaction instead of a bunch of continuous classical Transaction to have fluid movements on the screen.
|
|
16
|
+
*/
|
|
17
|
+
export class BurstTransaction {
|
|
18
|
+
constructor();
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Push all property values from specified Observable to update specified object
|
|
22
|
+
*
|
|
23
|
+
* @param object the object to update
|
|
24
|
+
* @param values observable mapping properties to new values
|
|
25
|
+
*/
|
|
26
|
+
push<T>(object: CloudObject, values: Observable<Map<Property<T>, T>>): void;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Commit and close the burst transaction
|
|
30
|
+
*
|
|
31
|
+
* @return A `Promise` completing with commit success/failure
|
|
32
|
+
*/
|
|
33
|
+
complete(): Promise<void>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { BrickContext } from "./runtime";
|
|
2
|
+
import { CloudObject, InstanceOrTag } from "./data";
|
|
3
|
+
import { Property, Relation } from "./composition";
|
|
4
|
+
import { Source } from "./data-connector";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
// ---------------------------
|
|
8
|
+
// -- Database transactions --
|
|
9
|
+
// ---------------------------
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Transactions are the unique way to apply a list of operations to the datacloud.
|
|
13
|
+
* A transaction can be merged into another transaction so that both are executed as a single set of operations.
|
|
14
|
+
*
|
|
15
|
+
* All the operations for a transaction are executed atomically. Either all operations succeed, or none is applied.
|
|
16
|
+
*
|
|
17
|
+
*
|
|
18
|
+
* There are 5 types of basic operations :
|
|
19
|
+
* - Create instance: create a node in the database with specified properties.
|
|
20
|
+
* - Update instance property: update an existing node in the database.
|
|
21
|
+
* - Delete instance: delete a node from the database. Delete only works if all the relations are removed too. Cascade delete can be activated.
|
|
22
|
+
* - Create relation: create a relation of a specific type between 2 existing node.
|
|
23
|
+
* - Delete relation: remove the specified relation between 2 specified nodes.
|
|
24
|
+
*
|
|
25
|
+
* In most cases, we apply the Transactions operations using the "execute()" method. The transaction size is limited but in real-time.
|
|
26
|
+
* It notifies observers of the data in real-time.
|
|
27
|
+
*
|
|
28
|
+
* Larger transactions with big set of operations (batch updates) must be executed using "executeAsLarge()" method. However, no notification will be generated.
|
|
29
|
+
*
|
|
30
|
+
* Callbacks can be registered on transaction using "afterExecution()" method. They are executed once the transaction is applied.
|
|
31
|
+
*
|
|
32
|
+
* Example of transaction:
|
|
33
|
+
*
|
|
34
|
+
* ```javascript
|
|
35
|
+
* const tx = new Transaction(true);
|
|
36
|
+
* const myNewInstanceTag = tx.create(<myModelTag>);
|
|
37
|
+
* tx.update(myNewInstanceTag, <myPropertyTag>, <myPropertyValue>)
|
|
38
|
+
* .execute()
|
|
39
|
+
* .then(() => {
|
|
40
|
+
* // success tx case
|
|
41
|
+
* })
|
|
42
|
+
* .catch((err) => {
|
|
43
|
+
* // error during tx case
|
|
44
|
+
* })
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* Concurrency transactions do not guarantee their execution order.
|
|
48
|
+
*/
|
|
49
|
+
export class Transaction {
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Create a new transaction object.
|
|
53
|
+
*
|
|
54
|
+
* @param persist if set to `true`, will persist to the data source the objects {@link Transaction.create} created in that transaction. (Default = `true`)
|
|
55
|
+
*/
|
|
56
|
+
constructor(persist?: boolean);
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Get the transaction id attached to this transaction
|
|
60
|
+
* @return this transaction id
|
|
61
|
+
*/
|
|
62
|
+
getId(): string;
|
|
63
|
+
|
|
64
|
+
// Operations
|
|
65
|
+
/**
|
|
66
|
+
* Create a new instance.
|
|
67
|
+
*
|
|
68
|
+
* A custom map can specify property values for the instance.
|
|
69
|
+
*
|
|
70
|
+
* A source can be the orchestrator ({@link {PredefinedDataSource.SERVER}}), local ({@link {PredefinedDataSource.SELF}}) or
|
|
71
|
+
* an external data source (tag of DBConnector). The source is where
|
|
72
|
+
* the object is persisted and its true value outside local scopes.
|
|
73
|
+
*
|
|
74
|
+
* @param model tag of the model of the instance to be created
|
|
75
|
+
* @param properties custom map from tag to their value for properties of the instance to be created
|
|
76
|
+
* @param source optional source of the instance
|
|
77
|
+
* @param tag optional tag of the instance to be created and must be unique
|
|
78
|
+
* @return the tag of the instance to be created
|
|
79
|
+
*/
|
|
80
|
+
create(model: InstanceOrTag, properties?: Map<InstanceOrTag, any>, source?: Source, tag?: string): string;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Update the property of an instance
|
|
84
|
+
*
|
|
85
|
+
* @param instance tag of the instance to be updated
|
|
86
|
+
* @param property the property to be updated
|
|
87
|
+
* @param value the value of the property to be updated to
|
|
88
|
+
* @return this transaction
|
|
89
|
+
*/
|
|
90
|
+
update<T>(instance: InstanceOrTag, property?: Property<T>, value?: T): this;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Update multiple properties of a single instance
|
|
94
|
+
*
|
|
95
|
+
* @param instance tag of the instance to be updated
|
|
96
|
+
* @param properties map of properties to update
|
|
97
|
+
* @return this transaction
|
|
98
|
+
*/
|
|
99
|
+
multiUpdate(instance: InstanceOrTag, properties: Map<InstanceOrTag, any>): this;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Delete an instance
|
|
103
|
+
*
|
|
104
|
+
* @param instance tag of the instance to be deleted
|
|
105
|
+
* @return this transaction
|
|
106
|
+
*/
|
|
107
|
+
delete(instance: InstanceOrTag): this;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Create relation between two instances
|
|
111
|
+
*
|
|
112
|
+
* @param relation tag of the relation to be created
|
|
113
|
+
* @param from tag of the ORIGIN instance of the relation
|
|
114
|
+
* @param to tag ofo the DESTINATION instance of the relation
|
|
115
|
+
* @return this transaction with the create relation operation registered
|
|
116
|
+
*/
|
|
117
|
+
createRelation(relation: InstanceOrTag, from: InstanceOrTag, to: InstanceOrTag): this;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Delete a relation between two specified instances.
|
|
121
|
+
*
|
|
122
|
+
* The relation is only deleted for the relation parameter direction.
|
|
123
|
+
*
|
|
124
|
+
* @param relation tag of the relation to be deleted
|
|
125
|
+
* @param from origin instance tag
|
|
126
|
+
* @param to destination instance tag
|
|
127
|
+
* @return this transaction
|
|
128
|
+
*/
|
|
129
|
+
deleteRelation(relation: InstanceOrTag, from: InstanceOrTag, to: InstanceOrTag): this;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Delete any number of the relation starting from specified node.
|
|
133
|
+
*
|
|
134
|
+
* The specified node might be the origin or (exclusive) the destination of the relation.
|
|
135
|
+
*
|
|
136
|
+
* For the relations :
|
|
137
|
+
* ```
|
|
138
|
+
* - a - [rel1] -> b,
|
|
139
|
+
* - c - [inverseRel(rel1)] -> a,
|
|
140
|
+
* - a - [rel1] -> d,
|
|
141
|
+
* - a - [rel2] -> d
|
|
142
|
+
* ```
|
|
143
|
+
* `tx.deleteAllRelation(rel1, a)` will remove the first and third relations
|
|
144
|
+
*
|
|
145
|
+
* @param relation deleted relation, indicates relation tag *and* direction
|
|
146
|
+
* @param origin starting node
|
|
147
|
+
*/
|
|
148
|
+
deleteAllRelations(relation: Relation<any, any>, origin: InstanceOrTag): this;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Set the specified instance to be persisted or not in this transaction.
|
|
152
|
+
* Default value of persist is true.
|
|
153
|
+
*
|
|
154
|
+
* @param instance the instance to be persisted
|
|
155
|
+
* @param persist determine if the specified instance should be persisted or not (true by default).
|
|
156
|
+
* @return this transaction
|
|
157
|
+
*/
|
|
158
|
+
persist(instance: InstanceOrTag, persist?: boolean): this;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Change the persistence mode for a single instance in this transaction
|
|
162
|
+
*
|
|
163
|
+
* @deprecated use {@link Transaction.persist} instead
|
|
164
|
+
* @param instance the instance to be persisted
|
|
165
|
+
* @param persist the persisting mode
|
|
166
|
+
* @return this transaction
|
|
167
|
+
*/
|
|
168
|
+
persistInstance(instance: InstanceOrTag, persist?: boolean): this;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Change the source of all instances created in this transaction
|
|
172
|
+
*
|
|
173
|
+
* `source` can be specified as :
|
|
174
|
+
* 1. a predefined source type {@link {PredefinedDataSource}}
|
|
175
|
+
* 2. an external data source (Tag of a `DBConnector`)
|
|
176
|
+
*
|
|
177
|
+
* The source of a data object is where the object is persisted.
|
|
178
|
+
*
|
|
179
|
+
* By default, the `source` is the default source configured in the project.
|
|
180
|
+
*
|
|
181
|
+
* @param source the new source for instances
|
|
182
|
+
* @return this transaction
|
|
183
|
+
*/
|
|
184
|
+
setSource(source: Source): this;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Retrieve the tag of the model of the instance tag
|
|
188
|
+
* from the created instances in this transaction
|
|
189
|
+
* or from the local database.
|
|
190
|
+
*
|
|
191
|
+
* @param tag the instance to find the model of
|
|
192
|
+
* @return the tag of the model of the given instance
|
|
193
|
+
*/
|
|
194
|
+
model(tag: InstanceOrTag): string | null;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Add all operations of another transaction into this transaction
|
|
198
|
+
*
|
|
199
|
+
* @param otherTransaction the other transaction to add operations from
|
|
200
|
+
* @return this transaction
|
|
201
|
+
*/
|
|
202
|
+
merge(otherTransaction: Transaction): this;
|
|
203
|
+
|
|
204
|
+
// Execution methods
|
|
205
|
+
/**
|
|
206
|
+
* Set a callback to be executed after all the operations
|
|
207
|
+
* in the transaction were executed successfully
|
|
208
|
+
*
|
|
209
|
+
* @param callback the callback to be executed
|
|
210
|
+
* @return this transaction
|
|
211
|
+
*/
|
|
212
|
+
afterExecution(callback: (success: boolean, message?: string) => void): this;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Execute atomically the transaction at the data sources. Return the transaction result if succeeds.
|
|
216
|
+
*
|
|
217
|
+
* @return promise resolving with the corresponding TransactionResult if the transaction succeeds,
|
|
218
|
+
* rejecting if the transaction fails
|
|
219
|
+
*/
|
|
220
|
+
execute(): Promise<TransactionResult>;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Execute atomically a transaction at the data source and returns the transaction result if succeeds.
|
|
224
|
+
* The `large` mode sends the transaction over HTTP, this has the following incidence:
|
|
225
|
+
* - Quicker processing of transaction
|
|
226
|
+
* - Allows transactions with no limit of size
|
|
227
|
+
* - Cannot be used when logged as Guest
|
|
228
|
+
*
|
|
229
|
+
* @return promise resolving with the corresponding TransactionResult if the transaction succeeds,
|
|
230
|
+
* rejecting if the transaction fails.
|
|
231
|
+
*/
|
|
232
|
+
executeAsLarge(): Promise<TransactionResult>;
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Start a transaction using an existing transaction in the provided context
|
|
236
|
+
* or a new one if there is none.
|
|
237
|
+
*
|
|
238
|
+
* @param $ context in which the transaction executes
|
|
239
|
+
* @return transaction
|
|
240
|
+
*/
|
|
241
|
+
static from($: BrickContext): Transaction;
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Execute a given transaction if there is no open transaction in the context.
|
|
245
|
+
*
|
|
246
|
+
* @param $ context
|
|
247
|
+
* @param transaction transaction to process
|
|
248
|
+
* @return boolean indicating if the argument transaction has been processed
|
|
249
|
+
*/
|
|
250
|
+
static process($: BrickContext, transaction: Transaction): Promise<boolean>;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* A transaction result is the object received after a transaction has been executed successfully.
|
|
256
|
+
* It provides information about what has been done.
|
|
257
|
+
*/
|
|
258
|
+
export class TransactionResult {
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Return the ordered list of CloudObjects created in this transaction.
|
|
262
|
+
*
|
|
263
|
+
* @return the list of CloudObjects instances
|
|
264
|
+
*/
|
|
265
|
+
getCreatedObjects(): CloudObject[];
|
|
266
|
+
}
|