@lionweb/delta-protocol-client 0.7.2 → 0.8.0-beta.1
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/CHANGELOG.md +5 -0
- package/dist/client.d.ts +2 -16
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +13 -52
- package/dist/client.js.map +1 -1
- package/package.json +7 -7
- package/src/client.ts +12 -74
package/CHANGELOG.md
CHANGED
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DeltaReceiver,
|
|
1
|
+
import { DeltaReceiver, Forest, ILanguageBase, INodeBase } from "@lionweb/class-core";
|
|
2
2
|
import { LionWebId, LionWebJsonChunk } from "@lionweb/json";
|
|
3
3
|
import { Command, Event, QueryMessage, SemanticLogger, SubscribeToPartitionChangesParameters } from "@lionweb/delta-protocol-common";
|
|
4
4
|
import { LowLevelClientInstantiator } from "./low-level-client.js";
|
|
@@ -19,12 +19,7 @@ export type LionWebClientParameters = {
|
|
|
19
19
|
*/
|
|
20
20
|
export declare class LionWebClient {
|
|
21
21
|
readonly clientId: LionWebId;
|
|
22
|
-
|
|
23
|
-
readonly idMapping: IdMapping;
|
|
24
|
-
readonly createNode: NodeBaseFactory;
|
|
25
|
-
readonly deserialize: Deserializer<INodeBase[]>;
|
|
26
|
-
readonly deserializeWithIdMapping: Deserializer<RootsWithIdMapping>;
|
|
27
|
-
private readonly effectiveReceiveDelta;
|
|
22
|
+
forest: Forest;
|
|
28
23
|
private readonly lowLevelClient;
|
|
29
24
|
private _participationId?;
|
|
30
25
|
get participationId(): string | undefined;
|
|
@@ -32,15 +27,7 @@ export declare class LionWebClient {
|
|
|
32
27
|
private lastReceivedSequenceNumber;
|
|
33
28
|
private constructor();
|
|
34
29
|
private readonly queryResolveById;
|
|
35
|
-
private static readonly nodesByIdFrom;
|
|
36
30
|
static create({ clientId, url, languageBases, instantiateDeltaReceiverForwardingTo, serializationChunk, semanticLogger, lowLevelClientInstantiator }: LionWebClientParameters): Promise<LionWebClient>;
|
|
37
|
-
/**
|
|
38
|
-
* Sets the model held by the client to the given model, discarding the previous one.
|
|
39
|
-
* **Note**:
|
|
40
|
-
* - The model is assumed to be injected with `this.effectiveReceiveDelta` — e.g. using this.createNode(...) or this.deserialize(...)`!
|
|
41
|
-
* - No commands will be sent because of this action.
|
|
42
|
-
*/
|
|
43
|
-
setModel(newModel: INodeBase[]): void;
|
|
44
31
|
disconnect(): Promise<void>;
|
|
45
32
|
/**
|
|
46
33
|
* Makes the query in the sense that the given query request is sent (as a client message),
|
|
@@ -56,7 +43,6 @@ export declare class LionWebClient {
|
|
|
56
43
|
reconnect(queryId: LionWebId, participationId: LionWebId, lastReceivedSequenceNumber: number): Promise<void>;
|
|
57
44
|
getAvailableIds(queryId: LionWebId, count: number): Promise<LionWebId[]>;
|
|
58
45
|
listPartitions(queryId: LionWebId): Promise<LionWebJsonChunk>;
|
|
59
|
-
private static checkWhetherPartition;
|
|
60
46
|
private checkSignedOn;
|
|
61
47
|
addPartition(partition: INodeBase): void;
|
|
62
48
|
deletePartition(partition: INodeBase): void;
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAiBA,OAAO,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,SAAS,EAAkB,MAAM,qBAAqB,CAAA;AACrG,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAE3D,OAAO,EAOH,OAAO,EAGP,KAAK,EAQL,YAAY,EAGZ,cAAc,EAMd,qCAAqC,EAIxC,MAAM,gCAAgC,CAAA;AACvC,OAAO,EAAkB,0BAA0B,EAAE,MAAM,uBAAuB,CAAA;AAMlF;;GAEG;AACH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IASzF,MAAM,CAAC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAelE,OAAO,CAAC,OAAO,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAU1C,SAAS,CAAC,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,SAAS,EAAE,0BAA0B,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAY5G,eAAe,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAUxE,cAAc,CAAC,OAAO,EAAE,SAAS,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAYnE,OAAO,CAAC,aAAa;IAMrB,YAAY,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI;IAKxC,eAAe,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI;CAK9C"}
|
package/dist/client.js
CHANGED
|
@@ -14,9 +14,7 @@
|
|
|
14
14
|
//
|
|
15
15
|
// SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
|
|
16
16
|
// SPDX-License-Identifier: Apache-2.0
|
|
17
|
-
import {
|
|
18
|
-
import { Concept } from "@lionweb/core";
|
|
19
|
-
import { byIdMap } from "@lionweb/ts-utils";
|
|
17
|
+
import { Forest, serializeDelta } from "@lionweb/class-core";
|
|
20
18
|
import { ansi, ClientAppliedEvent, ClientDidNotApplyEventFromOwnCommand, ClientHadProblem, ClientReceivedMessage, ClientSentMessage, DeltaOccurredOnClient, deltaToCommandTranslator, eventToDeltaTranslator, isEvent, isQueryResponse, semanticLoggerFunctionFrom } from "@lionweb/delta-protocol-common";
|
|
21
19
|
import { priorityQueueAcceptor } from "./priority-queue.js";
|
|
22
20
|
const { clientWarning } = ansi;
|
|
@@ -28,14 +26,9 @@ export class LionWebClient {
|
|
|
28
26
|
return this._participationId;
|
|
29
27
|
}
|
|
30
28
|
// TODO could also get this from the priority queue (which would need to be adapted for that)
|
|
31
|
-
constructor(clientId,
|
|
29
|
+
constructor(clientId, forest, lowLevelClient) {
|
|
32
30
|
this.clientId = clientId;
|
|
33
|
-
this.
|
|
34
|
-
this.idMapping = idMapping;
|
|
35
|
-
this.createNode = createNode;
|
|
36
|
-
this.deserialize = deserialize;
|
|
37
|
-
this.deserializeWithIdMapping = deserializeWithIdMapping;
|
|
38
|
-
this.effectiveReceiveDelta = effectiveReceiveDelta;
|
|
31
|
+
this.forest = forest;
|
|
39
32
|
this.lowLevelClient = lowLevelClient;
|
|
40
33
|
this.signedOff = false;
|
|
41
34
|
this.lastReceivedSequenceNumber = -1;
|
|
@@ -78,11 +71,11 @@ export class LionWebClient {
|
|
|
78
71
|
}
|
|
79
72
|
};
|
|
80
73
|
const effectiveReceiveDelta = instantiateDeltaReceiverForwardingTo === undefined ? commandSender : instantiateDeltaReceiverForwardingTo(commandSender);
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const eventAsDelta = eventToDeltaTranslator(languageBases,
|
|
74
|
+
const forest = new Forest({ languageBases, receiveDelta: effectiveReceiveDelta });
|
|
75
|
+
if (serializationChunk !== undefined) {
|
|
76
|
+
forest.deserializeInto(serializationChunk);
|
|
77
|
+
}
|
|
78
|
+
const eventAsDelta = eventToDeltaTranslator(languageBases, forest.deserializeWithIdMapping);
|
|
86
79
|
loading = false;
|
|
87
80
|
const processEvent = (event) => {
|
|
88
81
|
lionWebClient.lastReceivedSequenceNumber = event.sequenceNumber;
|
|
@@ -90,10 +83,10 @@ export class LionWebClient {
|
|
|
90
83
|
// Note: we can't remove members from issuedCommandIds because there may be multiple events originating fom a single command.
|
|
91
84
|
if (commandOriginatingFromSelf === undefined) {
|
|
92
85
|
try {
|
|
93
|
-
const delta = eventAsDelta(event, idMapping);
|
|
86
|
+
const delta = eventAsDelta(event, forest.idMapping);
|
|
94
87
|
if (delta !== undefined) {
|
|
95
88
|
try {
|
|
96
|
-
applyDelta(delta);
|
|
89
|
+
forest.applyDelta(delta);
|
|
97
90
|
log(new ClientAppliedEvent(clientId, event));
|
|
98
91
|
}
|
|
99
92
|
catch (e) {
|
|
@@ -129,19 +122,9 @@ export class LionWebClient {
|
|
|
129
122
|
}
|
|
130
123
|
};
|
|
131
124
|
const lowLevelClient = await lowLevelClientInstantiator({ url, clientId, receiveMessageOnClient /* no logging parameter */ });
|
|
132
|
-
const lionWebClient = new LionWebClient(clientId,
|
|
125
|
+
const lionWebClient = new LionWebClient(clientId, forest, lowLevelClient); // Note: we need this `lionWebClient` constant non-inlined for write-access to lastReceivedSequenceNumber and queryResolveById.
|
|
133
126
|
return lionWebClient;
|
|
134
127
|
}
|
|
135
|
-
/**
|
|
136
|
-
* Sets the model held by the client to the given model, discarding the previous one.
|
|
137
|
-
* **Note**:
|
|
138
|
-
* - The model is assumed to be injected with `this.effectiveReceiveDelta` — e.g. using this.createNode(...) or this.deserialize(...)`!
|
|
139
|
-
* - No commands will be sent because of this action.
|
|
140
|
-
*/
|
|
141
|
-
setModel(newModel) {
|
|
142
|
-
this.model = newModel;
|
|
143
|
-
this.idMapping.reinitializeWith(LionWebClient.nodesByIdFrom(newModel));
|
|
144
|
-
}
|
|
145
128
|
async disconnect() {
|
|
146
129
|
// TODO abort responses to all queries that the repository hasn't responded to?
|
|
147
130
|
await this.lowLevelClient.disconnect();
|
|
@@ -223,15 +206,6 @@ export class LionWebClient {
|
|
|
223
206
|
return response.partitions;
|
|
224
207
|
}
|
|
225
208
|
// commands, in order of the specification (§ 6.5):
|
|
226
|
-
static checkWhetherPartition(node) {
|
|
227
|
-
const { classifier } = node;
|
|
228
|
-
if (!(classifier instanceof Concept)) {
|
|
229
|
-
throw new Error(`node with classifier ${classifier.name} from language ${classifier.language.name} is not an instance of a Concept`);
|
|
230
|
-
}
|
|
231
|
-
if (!classifier.partition) {
|
|
232
|
-
throw new Error(`classifier ${classifier.name} from language ${classifier.language.name} is not a partition`);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
209
|
checkSignedOn() {
|
|
236
210
|
if (this._participationId === undefined) {
|
|
237
211
|
throw new Error(`client ${this.clientId} can't send a command without being signed on`);
|
|
@@ -239,24 +213,11 @@ export class LionWebClient {
|
|
|
239
213
|
}
|
|
240
214
|
addPartition(partition) {
|
|
241
215
|
this.checkSignedOn();
|
|
242
|
-
|
|
243
|
-
if (this.model.indexOf(partition) === -1) {
|
|
244
|
-
this.model.push(partition);
|
|
245
|
-
this.idMapping.updateWith(partition);
|
|
246
|
-
this.effectiveReceiveDelta(new PartitionAddedDelta(partition));
|
|
247
|
-
} // else: ignore; already done
|
|
216
|
+
this.forest.addPartition(partition);
|
|
248
217
|
}
|
|
249
218
|
deletePartition(partition) {
|
|
250
219
|
this.checkSignedOn();
|
|
251
|
-
|
|
252
|
-
if (index > -1) {
|
|
253
|
-
this.model.splice(index, 1);
|
|
254
|
-
this.effectiveReceiveDelta(new PartitionDeletedDelta(partition));
|
|
255
|
-
}
|
|
256
|
-
else {
|
|
257
|
-
throw new Error(`node with id "${partition.id}" is not a partition in the current model`);
|
|
258
|
-
}
|
|
220
|
+
this.forest.deletePartition(partition);
|
|
259
221
|
}
|
|
260
222
|
}
|
|
261
|
-
LionWebClient.nodesByIdFrom = (model) => byIdMap(model.flatMap(allNodesFrom));
|
|
262
223
|
//# sourceMappingURL=client.js.map
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,EAAE;AACF,iEAAiE;AACjE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,EAAE;AACF,sEAAsE;AACtE,sCAAsC;AAEtC,OAAO,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"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;YAClC,WAAW,EAAE,uBAAuB;YACpC,OAAO;YACP,gBAAgB,EAAE,EAAE;SACE,CAA2B,CAAA;QACrD,OAAO,QAAQ,CAAC,UAAU,CAAA;IAC9B,CAAC;IAGD,mDAAmD;IAE3C,aAAa;QACjB,IAAI,IAAI,CAAC,gBAAgB,KAAK,SAAS,EAAE,CAAC;YACtC,MAAM,IAAI,KAAK,CAAC,UAAU,IAAI,CAAC,QAAQ,+CAA+C,CAAC,CAAA;QAC3F,CAAC;IACL,CAAC;IAED,YAAY,CAAC,SAAoB;QAC7B,IAAI,CAAC,aAAa,EAAE,CAAA;QACpB,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,CAAA;IACvC,CAAC;IAED,eAAe,CAAC,SAAoB;QAChC,IAAI,CAAC,aAAa,EAAE,CAAA;QACpB,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,CAAA;IAC1C,CAAC;CAEJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lionweb/delta-protocol-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0-beta.1",
|
|
4
4
|
"description": "Part of the implementation of a delta protocol client not tied to a specific message transport protocol",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"release": "npm publish"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@lionweb/class-core": "0.
|
|
31
|
-
"@lionweb/core": "0.
|
|
32
|
-
"@lionweb/delta-protocol-common": "0.
|
|
33
|
-
"@lionweb/delta-protocol-client": "0.
|
|
34
|
-
"@lionweb/json": "0.
|
|
35
|
-
"@lionweb/ts-utils": "0.
|
|
30
|
+
"@lionweb/class-core": "0.8.0-beta.1",
|
|
31
|
+
"@lionweb/core": "0.8.0-beta.1",
|
|
32
|
+
"@lionweb/delta-protocol-common": "0.8.0-beta.1",
|
|
33
|
+
"@lionweb/delta-protocol-client": "0.8.0-beta.1",
|
|
34
|
+
"@lionweb/json": "0.8.0-beta.1",
|
|
35
|
+
"@lionweb/ts-utils": "0.8.0-beta.1"
|
|
36
36
|
}
|
|
37
37
|
}
|
package/src/client.ts
CHANGED
|
@@ -15,25 +15,8 @@
|
|
|
15
15
|
// SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
|
|
16
16
|
// SPDX-License-Identifier: Apache-2.0
|
|
17
17
|
|
|
18
|
-
import {
|
|
19
|
-
allNodesFrom,
|
|
20
|
-
applyDelta,
|
|
21
|
-
combinedFactoryFor,
|
|
22
|
-
DeltaReceiver,
|
|
23
|
-
Deserializer,
|
|
24
|
-
IdMapping,
|
|
25
|
-
ILanguageBase,
|
|
26
|
-
INodeBase,
|
|
27
|
-
nodeBaseDeserializerWithIdMapping,
|
|
28
|
-
NodeBaseFactory,
|
|
29
|
-
PartitionAddedDelta,
|
|
30
|
-
PartitionDeletedDelta,
|
|
31
|
-
RootsWithIdMapping,
|
|
32
|
-
serializeDelta
|
|
33
|
-
} from "@lionweb/class-core"
|
|
34
|
-
import { Concept } from "@lionweb/core"
|
|
18
|
+
import { DeltaReceiver, Forest, ILanguageBase, INodeBase, serializeDelta } from "@lionweb/class-core"
|
|
35
19
|
import { LionWebId, LionWebJsonChunk } from "@lionweb/json"
|
|
36
|
-
import { byIdMap } from "@lionweb/ts-utils"
|
|
37
20
|
|
|
38
21
|
import {
|
|
39
22
|
ansi,
|
|
@@ -105,20 +88,12 @@ export class LionWebClient {
|
|
|
105
88
|
|
|
106
89
|
private constructor(
|
|
107
90
|
public readonly clientId: LionWebId,
|
|
108
|
-
public
|
|
109
|
-
public readonly idMapping: IdMapping,
|
|
110
|
-
public readonly createNode: NodeBaseFactory,
|
|
111
|
-
public readonly deserialize: Deserializer<INodeBase[]>,
|
|
112
|
-
public readonly deserializeWithIdMapping: Deserializer<RootsWithIdMapping>,
|
|
113
|
-
private readonly effectiveReceiveDelta: DeltaReceiver,
|
|
91
|
+
public forest: Forest,
|
|
114
92
|
private readonly lowLevelClient: LowLevelClient<Command | QueryMessage>
|
|
115
93
|
) {}
|
|
116
94
|
|
|
117
95
|
private readonly queryResolveById: { [queryId: string]: (value: QueryMessage) => void } = {}
|
|
118
96
|
|
|
119
|
-
private static readonly nodesByIdFrom = (model: INodeBase[]) =>
|
|
120
|
-
byIdMap(model.flatMap(allNodesFrom))
|
|
121
|
-
|
|
122
97
|
static async create({clientId, url, languageBases, instantiateDeltaReceiverForwardingTo, serializationChunk, semanticLogger, lowLevelClientInstantiator}: LionWebClientParameters): Promise<LionWebClient> {
|
|
123
98
|
const log = semanticLoggerFunctionFrom(semanticLogger)
|
|
124
99
|
|
|
@@ -146,11 +121,11 @@ export class LionWebClient {
|
|
|
146
121
|
}
|
|
147
122
|
}
|
|
148
123
|
const effectiveReceiveDelta = instantiateDeltaReceiverForwardingTo === undefined ? commandSender : instantiateDeltaReceiverForwardingTo(commandSender)
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const eventAsDelta = eventToDeltaTranslator(languageBases,
|
|
124
|
+
const forest = new Forest({ languageBases, receiveDelta: effectiveReceiveDelta })
|
|
125
|
+
if (serializationChunk !== undefined) {
|
|
126
|
+
forest.deserializeInto(serializationChunk)
|
|
127
|
+
}
|
|
128
|
+
const eventAsDelta = eventToDeltaTranslator(languageBases, forest.deserializeWithIdMapping)
|
|
154
129
|
loading = false
|
|
155
130
|
|
|
156
131
|
const processEvent = (event: Event) => {
|
|
@@ -159,10 +134,10 @@ export class LionWebClient {
|
|
|
159
134
|
// Note: we can't remove members from issuedCommandIds because there may be multiple events originating fom a single command.
|
|
160
135
|
if (commandOriginatingFromSelf === undefined) {
|
|
161
136
|
try {
|
|
162
|
-
const delta = eventAsDelta(event, idMapping)
|
|
137
|
+
const delta = eventAsDelta(event, forest.idMapping)
|
|
163
138
|
if (delta !== undefined) {
|
|
164
139
|
try {
|
|
165
|
-
applyDelta(delta)
|
|
140
|
+
forest.applyDelta(delta)
|
|
166
141
|
log(new ClientAppliedEvent(clientId, event))
|
|
167
142
|
} catch (e) {
|
|
168
143
|
log(new ClientHadProblem(clientId, `couldn't apply delta of type ${delta.constructor.name} because of: ${(e as Error).message}`))
|
|
@@ -202,28 +177,12 @@ export class LionWebClient {
|
|
|
202
177
|
|
|
203
178
|
const lionWebClient = new LionWebClient(
|
|
204
179
|
clientId,
|
|
205
|
-
|
|
206
|
-
idMapping,
|
|
207
|
-
combinedFactoryFor(languageBases, effectiveReceiveDelta),
|
|
208
|
-
(serializationChunk) => deserializerWithIdMapping(serializationChunk).roots,
|
|
209
|
-
deserializerWithIdMapping,
|
|
210
|
-
effectiveReceiveDelta,
|
|
180
|
+
forest,
|
|
211
181
|
lowLevelClient
|
|
212
182
|
) // Note: we need this `lionWebClient` constant non-inlined for write-access to lastReceivedSequenceNumber and queryResolveById.
|
|
213
183
|
return lionWebClient
|
|
214
184
|
}
|
|
215
185
|
|
|
216
|
-
/**
|
|
217
|
-
* Sets the model held by the client to the given model, discarding the previous one.
|
|
218
|
-
* **Note**:
|
|
219
|
-
* - The model is assumed to be injected with `this.effectiveReceiveDelta` — e.g. using this.createNode(...) or this.deserialize(...)`!
|
|
220
|
-
* - No commands will be sent because of this action.
|
|
221
|
-
*/
|
|
222
|
-
setModel(newModel: INodeBase[]) {
|
|
223
|
-
this.model = newModel
|
|
224
|
-
this.idMapping.reinitializeWith(LionWebClient.nodesByIdFrom(newModel))
|
|
225
|
-
}
|
|
226
|
-
|
|
227
186
|
async disconnect(): Promise<void> {
|
|
228
187
|
// TODO abort responses to all queries that the repository hasn't responded to?
|
|
229
188
|
await this.lowLevelClient.disconnect()
|
|
@@ -331,16 +290,6 @@ export class LionWebClient {
|
|
|
331
290
|
|
|
332
291
|
// commands, in order of the specification (§ 6.5):
|
|
333
292
|
|
|
334
|
-
private static checkWhetherPartition(node: INodeBase): void {
|
|
335
|
-
const {classifier} = node
|
|
336
|
-
if (!(classifier instanceof Concept)) {
|
|
337
|
-
throw new Error(`node with classifier ${classifier.name} from language ${classifier.language.name} is not an instance of a Concept`)
|
|
338
|
-
}
|
|
339
|
-
if (!classifier.partition) {
|
|
340
|
-
throw new Error(`classifier ${classifier.name} from language ${classifier.language.name} is not a partition`)
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
293
|
private checkSignedOn(): void {
|
|
345
294
|
if (this._participationId === undefined) {
|
|
346
295
|
throw new Error(`client ${this.clientId} can't send a command without being signed on`)
|
|
@@ -349,23 +298,12 @@ export class LionWebClient {
|
|
|
349
298
|
|
|
350
299
|
addPartition(partition: INodeBase): void {
|
|
351
300
|
this.checkSignedOn()
|
|
352
|
-
|
|
353
|
-
if (this.model.indexOf(partition) === -1) {
|
|
354
|
-
this.model.push(partition)
|
|
355
|
-
this.idMapping.updateWith(partition)
|
|
356
|
-
this.effectiveReceiveDelta(new PartitionAddedDelta(partition))
|
|
357
|
-
} // else: ignore; already done
|
|
301
|
+
this.forest.addPartition(partition)
|
|
358
302
|
}
|
|
359
303
|
|
|
360
304
|
deletePartition(partition: INodeBase): void {
|
|
361
305
|
this.checkSignedOn()
|
|
362
|
-
|
|
363
|
-
if (index > -1) {
|
|
364
|
-
this.model.splice(index, 1)
|
|
365
|
-
this.effectiveReceiveDelta(new PartitionDeletedDelta(partition))
|
|
366
|
-
} else {
|
|
367
|
-
throw new Error(`node with id "${partition.id}" is not a partition in the current model`)
|
|
368
|
-
}
|
|
306
|
+
this.forest.deletePartition(partition)
|
|
369
307
|
}
|
|
370
308
|
|
|
371
309
|
}
|