@lionweb/class-core 0.8.0-beta.0 → 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 +2 -0
- package/dist/base-types.d.ts +10 -1
- package/dist/base-types.d.ts.map +1 -1
- package/dist/deserializer.d.ts +3 -7
- package/dist/deserializer.d.ts.map +1 -1
- package/dist/deserializer.js.map +1 -1
- package/dist/forest.d.ts +67 -0
- package/dist/forest.d.ts.map +1 -0
- package/dist/forest.js +109 -0
- package/dist/forest.js.map +1 -0
- package/dist/id-mapping.d.ts +2 -1
- package/dist/id-mapping.d.ts.map +1 -1
- package/dist/id-mapping.js +2 -1
- package/dist/id-mapping.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/linking.d.ts +2 -2
- package/package.json +4 -4
- package/src/base-types.ts +12 -1
- package/src/deserializer.ts +5 -9
- package/src/forest.ts +173 -0
- package/src/id-mapping.ts +2 -1
- package/src/index.ts +1 -0
- package/src/linking.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
*Note* that this is a **breaking change**, but these parameters weren’t used outside of tests anyway.
|
|
12
12
|
* Simplify `Deserializer` type, by removing the `dependentNodes` parameter: (only) pass an appropriate instance of `IdMapping` instead.
|
|
13
13
|
*Note* that this is a **breaking change**, but either parameter is optional and carries the same information, so this should avoid confusion and misuse.
|
|
14
|
+
* Add a `Forest` class that encapsulates a “forest” of partitions, together with their ID mapping, a factory, a deserializer – also deserializing into the forest –, and methods to apply deltas.
|
|
15
|
+
* Add a `ObservableForest` class that is Mobx-observable.
|
|
14
16
|
|
|
15
17
|
|
|
16
18
|
## 0.7.2
|
package/dist/base-types.d.ts
CHANGED
|
@@ -155,7 +155,7 @@ export declare abstract class NodeBase implements INodeBase {
|
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
157
157
|
* A type for functions that acts as factories, creating an instance of {@link INodeBase}
|
|
158
|
-
* matching the given {@link Classifier classifier} and the given ID (of type {@link
|
|
158
|
+
* matching the given {@link Classifier classifier} and the given ID (of type {@link LionWebId}).
|
|
159
159
|
*/
|
|
160
160
|
export type NodeBaseFactory = (classifier: Classifier, id: LionWebId) => INodeBase;
|
|
161
161
|
/**
|
|
@@ -169,4 +169,13 @@ export interface ILanguageBase {
|
|
|
169
169
|
factory(receiveDelta?: DeltaReceiver): NodeBaseFactory;
|
|
170
170
|
enumLiteralFrom<T>(enumerationLiteral: EnumerationLiteral): T;
|
|
171
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* The configuration required to be able to instantiate a {@link NodeBaseFactory factory} for a set of languages.
|
|
174
|
+
*/
|
|
175
|
+
export type FactoryConfiguration = {
|
|
176
|
+
/** The {@link ILanguageBase}s for (at least) all the languages used, minus LionCore M3 and built-ins. */
|
|
177
|
+
languageBases: ILanguageBase[];
|
|
178
|
+
/** An optional {@link DeltaReceiver} that will be injected in all {@link INodeBase nodes} created. */
|
|
179
|
+
receiveDelta?: DeltaReceiver;
|
|
180
|
+
};
|
|
172
181
|
//# sourceMappingURL=base-types.d.ts.map
|
package/dist/base-types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-types.d.ts","sourceRoot":"","sources":["../src/base-types.ts"],"names":[],"mappings":"AAiBA,OAAO,EAEH,UAAU,EAGV,WAAW,EACX,kBAAkB,EAClB,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,SAAS,EACZ,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAIzC,OAAO,EACH,uBAAuB,EACvB,uBAAuB,EACvB,aAAa,EACb,mBAAmB,EAGnB,oBAAoB,EACpB,qBAAqB,EAGxB,MAAM,YAAY,CAAA;AAGnB;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,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,CAAC,OAAO,CAAC;IActE,IAAI,WAAW,IAAI,OAAO,EAAE,CAG3B;IAED,IAAI,QAAQ,IAAI,SAAS,EAAE,CAgB1B;IAED,IAAI,gBAAgB,IAAI,SAAS,EAAE,CAelC;IAED,QAAQ,CAAC,uBAAuB,EAAE,uBAAuB,CAAqC;IAC9F,IAAI,WAAW,IAAI,SAAS,EAAE,CAE7B;IAED,aAAa,CAAC,UAAU,EAAE,SAAS;IAInC,uBAAuB,CAAC,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM;IAI5D,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAIjD,wBAAwB,CAAC,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM;IAI7D,gBAAgB,CAAC,UAAU,EAAE,SAAS;CAIzC;AAGD;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,EAAE,EAAE,SAAS,KAAK,SAAS,CAAC;AAEnF;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC1B,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,CAAC,YAAY,CAAC,EAAE,aAAa,GAAG,eAAe,CAAC;IACvD,eAAe,CAAC,CAAC,EAAE,kBAAkB,EAAE,kBAAkB,GAAG,CAAC,CAAC;CACjE;AAGD;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IAC/B,yGAAyG;IACzG,aAAa,EAAE,aAAa,EAAE,CAAC;IAC/B,sGAAsG;IACtG,YAAY,CAAC,EAAE,aAAa,CAAA;CAC/B,CAAC"}
|
package/dist/deserializer.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PropertyValueDeserializer, SimplisticHandler } from "@lionweb/core";
|
|
2
2
|
import { LionWebJsonChunk } from "@lionweb/json";
|
|
3
|
-
import { DeltaReceiver, IdMapping, ILanguageBase, INodeBase } from "./index.js";
|
|
3
|
+
import { DeltaReceiver, IdMapping, ILanguageBase, INodeBase, FactoryConfiguration } from "./index.js";
|
|
4
4
|
/**
|
|
5
5
|
* A type for deserializer functions that are parametrized in their return type.
|
|
6
6
|
*/
|
|
@@ -22,10 +22,6 @@ export type RootsWithIdMapping = {
|
|
|
22
22
|
* (and partially optional).
|
|
23
23
|
*/
|
|
24
24
|
export type DeserializerConfiguration = {
|
|
25
|
-
/** The {@link ILanguageBase}s for (at least) all the languages used in the {@link LionWebJsonChunk} to deserialize, minus LionCore M3 and built-ins. */
|
|
26
|
-
languageBases: ILanguageBase[];
|
|
27
|
-
/** An optional {@link DeltaReceiver} that will be injected in all {@link INodeBase nodes} created. */
|
|
28
|
-
receiveDelta?: DeltaReceiver;
|
|
29
25
|
/** Default: {@link builtinPropertyValueDeserializer}. */
|
|
30
26
|
propertyValueDeserializer?: PropertyValueDeserializer;
|
|
31
27
|
/** Default: {@link defaultSimplisticHandler}. */
|
|
@@ -41,7 +37,7 @@ declare function nodeBaseDeserializerWithIdMapping(languageBases: ILanguageBase[
|
|
|
41
37
|
/**
|
|
42
38
|
* @param configuration a {@link DeserializerConfiguration configuration object} for the deserializer.
|
|
43
39
|
*/
|
|
44
|
-
declare function nodeBaseDeserializerWithIdMapping(configuration: DeserializerConfiguration): Deserializer<RootsWithIdMapping>;
|
|
40
|
+
declare function nodeBaseDeserializerWithIdMapping(configuration: FactoryConfiguration & DeserializerConfiguration): Deserializer<RootsWithIdMapping>;
|
|
45
41
|
/**
|
|
46
42
|
* @return a {@link Deserializer} function for the languages (given as {@link ILanguageBase}s) that returns the roots (of type {@link INodeBase}) of the deserialized model.
|
|
47
43
|
* Deprecated:
|
|
@@ -52,6 +48,6 @@ declare function nodeBaseDeserializer(languageBases: ILanguageBase[], receiveDel
|
|
|
52
48
|
/**
|
|
53
49
|
* @param configuration a {@link DeserializerConfiguration configuration object} for the deserializer.
|
|
54
50
|
*/
|
|
55
|
-
declare function nodeBaseDeserializer(configuration: DeserializerConfiguration): Deserializer<INodeBase[]>;
|
|
51
|
+
declare function nodeBaseDeserializer(configuration: FactoryConfiguration & DeserializerConfiguration): Deserializer<INodeBase[]>;
|
|
56
52
|
export { nodeBaseDeserializerWithIdMapping, nodeBaseDeserializer };
|
|
57
53
|
//# sourceMappingURL=deserializer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deserializer.d.ts","sourceRoot":"","sources":["../src/deserializer.ts"],"names":[],"mappings":"AAiBA,OAAO,EASH,yBAAyB,EAEzB,iBAAiB,EAEpB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAa,gBAAgB,EAAmB,MAAM,eAAe,CAAA;AAG5E,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"deserializer.d.ts","sourceRoot":"","sources":["../src/deserializer.ts"],"names":[],"mappings":"AAiBA,OAAO,EASH,yBAAyB,EAEzB,iBAAiB,EAEpB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAa,gBAAgB,EAAmB,MAAM,eAAe,CAAA;AAG5E,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAKrG;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI;AAC1B,uEAAuE;AACvE,kBAAkB,EAAE,gBAAgB;AACpC,0GAA0G;AAC1G,SAAS,CAAC,EAAE,SAAS,KACpB,CAAC,CAAC;AAGP;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAAE,KAAK,EAAE,SAAS,EAAE,CAAC;IAAC,SAAS,EAAE,SAAS,CAAA;CAAE,CAAC;AAG9E;;;GAGG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACpC,yDAAyD;IACzD,yBAAyB,CAAC,EAAE,yBAAyB,CAAC;IACtD,iDAAiD;IACjD,eAAe,CAAC,EAAE,iBAAiB,CAAA;CACtC,CAAC;AAGF;;;;;GAKG;AACH,iBAAS,iCAAiC,CAAC,aAAa,EAAE,aAAa,EAAE,EAAE,YAAY,CAAC,EAAE,aAAa,GAAG,YAAY,CAAC,kBAAkB,CAAC,CAAC;AAC3I;;GAEG;AACH,iBAAS,iCAAiC,CAAC,aAAa,EAAE,oBAAoB,GAAG,yBAAyB,GAAG,YAAY,CAAC,kBAAkB,CAAC,CAAC;AA4I9I;;;;;GAKG;AACH,iBAAS,oBAAoB,CAAC,aAAa,EAAE,aAAa,EAAE,EAAE,YAAY,CAAC,EAAE,aAAa,GAAG,YAAY,CAAC,SAAS,EAAE,CAAC,CAAC;AACvH;;GAEG;AACH,iBAAS,oBAAoB,CAAC,aAAa,EAAE,oBAAoB,GAAG,yBAAyB,GAAG,YAAY,CAAC,SAAS,EAAE,CAAC,CAAC;AAY1H,OAAO,EAAE,iCAAiC,EAAE,oBAAoB,EAAE,CAAC"}
|
package/dist/deserializer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deserializer.js","sourceRoot":"","sources":["../src/deserializer.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,EACH,gCAAgC,EAChC,UAAU,EACV,WAAW,EACX,wBAAwB,EACxB,WAAW,EACX,oBAAoB,EACpB,aAAa,EACb,QAAQ,EAER,SAAS,EAET,UAAU,EACb,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEzD,OAAO,EAAiB,SAAS,
|
|
1
|
+
{"version":3,"file":"deserializer.js","sourceRoot":"","sources":["../src/deserializer.ts"],"names":[],"mappings":"AAAA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OAAO,CAAC,4BAA4B,CAAC;QACvC,CAAC,CAAC,iCAAiC,CAAC,4BAA4B,EAAE,YAAY,CAAC,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC,KAAK;QACpH,CAAC,CAAC,iCAAiC,CAAC,4BAA4B,CAAC,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC,KAAK,CAAA;AAClH,CAAC;AAGD,OAAO,EAAE,iCAAiC,EAAE,oBAAoB,EAAE,CAAC"}
|
package/dist/forest.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { LionWebJsonChunk } from "@lionweb/json";
|
|
2
|
+
import { FactoryConfiguration, INodeBase, NodeBaseFactory } from "./base-types.js";
|
|
3
|
+
import { IDelta } from "./deltas/index.js";
|
|
4
|
+
import { Deserializer, DeserializerConfiguration, RootsWithIdMapping } from "./deserializer.js";
|
|
5
|
+
import { IdMapping } from "./id-mapping.js";
|
|
6
|
+
/**
|
|
7
|
+
* An instance of this class encompasses a complete model (=“forest”), to conveniently encapsulate that.
|
|
8
|
+
* (Essentially, it’s a sort of in-memory repository.)
|
|
9
|
+
*/
|
|
10
|
+
export declare class Forest {
|
|
11
|
+
private readonly languageBases;
|
|
12
|
+
private readonly receiveDelta?;
|
|
13
|
+
/**
|
|
14
|
+
* The partitions contained in `this` forest.
|
|
15
|
+
*/
|
|
16
|
+
readonly partitions: INodeBase[];
|
|
17
|
+
/**
|
|
18
|
+
* The {@link IdMapping ID mapping} mapping to all nodes in any of the partitions in `this` forest from the IDs of those nodes **plus** *unattached* nodes.
|
|
19
|
+
* A node is attached if it’s a partition – i.e., its classifier is marked as a partition –, or if it’s – directly, or indirectly – contained by a partition.
|
|
20
|
+
* This may happen as a result of deleting nodes, or of unattached nodes being deserialized into `this` forest through the `deserializeInto` or `applyDelta[s]` methods.
|
|
21
|
+
*/
|
|
22
|
+
readonly idMapping: IdMapping;
|
|
23
|
+
/**
|
|
24
|
+
* A {@link NodeBaseFactory factory} for nodes with classifiers from the {@link ILanguageBase language bases} passed during instantiation of `this` forest.
|
|
25
|
+
* This factory method installs the {@link DeltaReceiver} that may be passed during instantiation of `this` forest.
|
|
26
|
+
*/
|
|
27
|
+
readonly createNode: NodeBaseFactory;
|
|
28
|
+
/**
|
|
29
|
+
* A {@link Deserializer deserializer} that returns roots/partitions together with an ID mapping for all nodes in those.
|
|
30
|
+
* *Note*: this is primarily for internal use — specifically: to create an event-to-delta translator with.
|
|
31
|
+
* (That translator uses type from `delta-protocol-common` so we don’t want to have it here.)
|
|
32
|
+
* Using this method does *not* change `this` forest’s state.
|
|
33
|
+
*/
|
|
34
|
+
readonly deserializeWithIdMapping: Deserializer<RootsWithIdMapping>;
|
|
35
|
+
constructor(configuration: FactoryConfiguration & DeserializerConfiguration);
|
|
36
|
+
private emitDelta;
|
|
37
|
+
/**
|
|
38
|
+
* Adds the given `partition` to the partitions of `this` forest – provided it’s not already part of it –,
|
|
39
|
+
* and emits the corresponding {@link PartitionAddedDelta}.
|
|
40
|
+
*/
|
|
41
|
+
addPartition: (partition: INodeBase) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Deletes the indicated `partition` from the partitions of `this` forest – provided it’s part of it –,
|
|
44
|
+
* and emits the corresponding {@link PartitionDeletedDelta}.
|
|
45
|
+
*/
|
|
46
|
+
deletePartition: (partition: INodeBase) => void;
|
|
47
|
+
/**
|
|
48
|
+
* Deserializes the given `serializationChunk` and adds any partitions in it to the partitions of `this` forest,
|
|
49
|
+
* It also updates the ID mapping, including with mappings for deserialized unattached nodes.
|
|
50
|
+
*/
|
|
51
|
+
deserializeInto: (serializationChunk: LionWebJsonChunk) => INodeBase[];
|
|
52
|
+
/**
|
|
53
|
+
* Applies the given `delta`, taking care of updating the state of the internal ID mapping.
|
|
54
|
+
*/
|
|
55
|
+
applyDelta: (delta: IDelta) => void;
|
|
56
|
+
/**
|
|
57
|
+
* Applies the given `deltas`, taking care of updating the state of the internal ID mapping.
|
|
58
|
+
*/
|
|
59
|
+
applyDeltas: (deltas: IDelta[]) => void;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* “Mobx-ified” version of the {@link Forest} class.
|
|
63
|
+
*/
|
|
64
|
+
export declare class ObservableForest extends Forest {
|
|
65
|
+
constructor(configuration: FactoryConfiguration & DeserializerConfiguration);
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=forest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forest.d.ts","sourceRoot":"","sources":["../src/forest.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAGhD,OAAO,EAAE,oBAAoB,EAAiB,SAAS,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjG,OAAO,EAGH,MAAM,EAIT,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EACH,YAAY,EACZ,yBAAyB,EAEzB,kBAAkB,EACrB,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAG3C;;;GAGG;AACH,qBAAa,MAAM;IAEf,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiB;IAE/C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAe;IAE7C;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,SAAS,EAAE,CAAA;IAEhC;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAA;IAE7B;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,eAAe,CAAA;IAEpC;;;;;OAKG;IACH,QAAQ,CAAC,wBAAwB,EAAE,YAAY,CAAC,kBAAkB,CAAC,CAAA;gBAGvD,aAAa,EAAE,oBAAoB,GAAG,yBAAyB;IAU3E,OAAO,CAAC,SAAS,CAIhB;IAED;;;OAGG;IACH,YAAY,GAAI,WAAW,SAAS,UASnC;IAED;;;OAGG;IACH,eAAe,GAAI,WAAW,SAAS,UAQtC;IAED;;;OAGG;IACH,eAAe,GAAI,oBAAoB,gBAAgB,KAAG,SAAS,EAAE,CAKpE;IAED;;OAEG;IACH,UAAU,GAAI,OAAO,MAAM,UAG1B;IAED;;OAEG;IACH,WAAW,GAAI,QAAQ,MAAM,EAAE,UAE9B;CAEJ;AAGD;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,MAAM;gBAE5B,aAAa,EAAE,oBAAoB,GAAG,yBAAyB;CAc9E"}
|
package/dist/forest.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Copyright 2025 TRUMPF Laser SE and other contributors
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License")
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
|
|
16
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
import { isPartition } from "@lionweb/core";
|
|
18
|
+
import { action, makeObservable, observable } from "mobx";
|
|
19
|
+
import { applyDeltaWithLookup, PartitionAddedDelta, PartitionDeletedDelta, updateIdMappingWithDelta } from "./deltas/index.js";
|
|
20
|
+
import { nodeBaseDeserializerWithIdMapping } from "./deserializer.js";
|
|
21
|
+
import { combinedFactoryFor } from "./factory.js";
|
|
22
|
+
import { IdMapping } from "./id-mapping.js";
|
|
23
|
+
/**
|
|
24
|
+
* An instance of this class encompasses a complete model (=“forest”), to conveniently encapsulate that.
|
|
25
|
+
* (Essentially, it’s a sort of in-memory repository.)
|
|
26
|
+
*/
|
|
27
|
+
export class Forest {
|
|
28
|
+
constructor(configuration) {
|
|
29
|
+
this.emitDelta = (thunk) => {
|
|
30
|
+
if (this.receiveDelta) {
|
|
31
|
+
this.receiveDelta(thunk());
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Adds the given `partition` to the partitions of `this` forest – provided it’s not already part of it –,
|
|
36
|
+
* and emits the corresponding {@link PartitionAddedDelta}.
|
|
37
|
+
*/
|
|
38
|
+
this.addPartition = (partition) => {
|
|
39
|
+
if (!isPartition(partition.classifier)) {
|
|
40
|
+
throw new Error(`node with ID ${partition.id} is a ${partition.classifier.name} which is not a <<partition>> concept`);
|
|
41
|
+
}
|
|
42
|
+
if (this.partitions.indexOf(partition) === -1) {
|
|
43
|
+
this.partitions.push(partition);
|
|
44
|
+
this.idMapping.updateWith(partition);
|
|
45
|
+
this.emitDelta(() => new PartitionAddedDelta(partition));
|
|
46
|
+
} // else: ignore; already done
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Deletes the indicated `partition` from the partitions of `this` forest – provided it’s part of it –,
|
|
50
|
+
* and emits the corresponding {@link PartitionDeletedDelta}.
|
|
51
|
+
*/
|
|
52
|
+
this.deletePartition = (partition) => {
|
|
53
|
+
const index = this.partitions.indexOf(partition);
|
|
54
|
+
if (index > -1) {
|
|
55
|
+
this.partitions.splice(index, 1);
|
|
56
|
+
this.emitDelta(() => new PartitionDeletedDelta(partition));
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
throw new Error(`node with id "${partition.id}" is not an added partition`);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Deserializes the given `serializationChunk` and adds any partitions in it to the partitions of `this` forest,
|
|
64
|
+
* It also updates the ID mapping, including with mappings for deserialized unattached nodes.
|
|
65
|
+
*/
|
|
66
|
+
this.deserializeInto = (serializationChunk) => {
|
|
67
|
+
const { roots: newRoots, idMapping: newIdMapping } = this.deserializeWithIdMapping(serializationChunk, this.idMapping);
|
|
68
|
+
this.partitions.push(...newRoots.filter((newRoot) => isPartition(newRoot.classifier)));
|
|
69
|
+
this.idMapping.mergeIn(newIdMapping); // also merge in new unattached, non-partition roots
|
|
70
|
+
return newRoots;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Applies the given `delta`, taking care of updating the state of the internal ID mapping.
|
|
74
|
+
*/
|
|
75
|
+
this.applyDelta = (delta) => {
|
|
76
|
+
applyDeltaWithLookup(this.idMapping, delta, () => this.partitions);
|
|
77
|
+
updateIdMappingWithDelta(this.idMapping, delta);
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Applies the given `deltas`, taking care of updating the state of the internal ID mapping.
|
|
81
|
+
*/
|
|
82
|
+
this.applyDeltas = (deltas) => {
|
|
83
|
+
deltas.forEach((delta) => this.applyDelta(delta));
|
|
84
|
+
};
|
|
85
|
+
this.languageBases = configuration.languageBases;
|
|
86
|
+
this.receiveDelta = configuration.receiveDelta;
|
|
87
|
+
this.partitions = [];
|
|
88
|
+
this.idMapping = new IdMapping({});
|
|
89
|
+
this.createNode = combinedFactoryFor(this.languageBases, this.receiveDelta);
|
|
90
|
+
this.deserializeWithIdMapping = nodeBaseDeserializerWithIdMapping(configuration);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* “Mobx-ified” version of the {@link Forest} class.
|
|
95
|
+
*/
|
|
96
|
+
export class ObservableForest extends Forest {
|
|
97
|
+
constructor(configuration) {
|
|
98
|
+
super(configuration);
|
|
99
|
+
makeObservable(this, {
|
|
100
|
+
partitions: observable,
|
|
101
|
+
addPartition: action,
|
|
102
|
+
deserializeInto: action,
|
|
103
|
+
applyDelta: action,
|
|
104
|
+
applyDeltas: action
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// (but also see: https://mobx.js.org/subclassing.html)
|
|
109
|
+
//# sourceMappingURL=forest.js.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42
42
|
*/
|
|
43
43
|
reinitializeWith: (nodesById: NodesById) => void;
|
|
44
44
|
/**
|
|
45
|
-
* Merges the given `that` {@link IdMapping} **in**to `this
|
|
45
|
+
* Merges the given `that` {@link IdMapping} **in**to `this`,
|
|
46
|
+
* overwriting any previous mappings in `this`.
|
|
46
47
|
*/
|
|
47
48
|
mergeIn: (that: IdMapping) => void;
|
|
48
49
|
}
|
package/dist/id-mapping.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"id-mapping.d.ts","sourceRoot":"","sources":["../src/id-mapping.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,SAAS,EAAc,MAAM,eAAe,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAEzC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAGhD;;GAEG;AACH,KAAK,SAAS,GAAG;IAAE,CAAC,EAAE,EAAE,SAAS,GAAG,SAAS,CAAA;CAAE,CAAA;AAG/C;;;;GAIG;AACH,qBAAa,SAAS;IAElB,OAAO,CAAC,SAAS,CAAY;gBACjB,SAAS,EAAE,SAAS;IAKhC;;;OAGG;IACH,MAAM,GAAI,IAAI,SAAS,KAAG,SAAS,CAKlC;IAED;;;OAGG;IACH,SAAS,GAAI,IAAI,SAAS,KAAG,CAAC,SAAS,GAAG,SAAS,CAAC,CAC7B;IAEvB;;;OAGG;IACH,SAAS,GAAI,gBAAgB,cAAc,KAAG,SAAS,CAAC,SAAS,CAAC,CAGT;IAEzD;;OAEG;IACH,UAAU,GAAI,MAAM,SAAS,UAK5B;IAED;;;;OAIG;IACH,gBAAgB,GAAI,WAAW,SAAS,UAEvC;IAED
|
|
1
|
+
{"version":3,"file":"id-mapping.d.ts","sourceRoot":"","sources":["../src/id-mapping.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,SAAS,EAAc,MAAM,eAAe,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAEzC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAGhD;;GAEG;AACH,KAAK,SAAS,GAAG;IAAE,CAAC,EAAE,EAAE,SAAS,GAAG,SAAS,CAAA;CAAE,CAAA;AAG/C;;;;GAIG;AACH,qBAAa,SAAS;IAElB,OAAO,CAAC,SAAS,CAAY;gBACjB,SAAS,EAAE,SAAS;IAKhC;;;OAGG;IACH,MAAM,GAAI,IAAI,SAAS,KAAG,SAAS,CAKlC;IAED;;;OAGG;IACH,SAAS,GAAI,IAAI,SAAS,KAAG,CAAC,SAAS,GAAG,SAAS,CAAC,CAC7B;IAEvB;;;OAGG;IACH,SAAS,GAAI,gBAAgB,cAAc,KAAG,SAAS,CAAC,SAAS,CAAC,CAGT;IAEzD;;OAEG;IACH,UAAU,GAAI,MAAM,SAAS,UAK5B;IAED;;;;OAIG;IACH,gBAAgB,GAAI,WAAW,SAAS,UAEvC;IAED;;;OAGG;IACH,OAAO,GAAI,MAAM,SAAS,UAIzB;CAEJ"}
|
package/dist/id-mapping.js
CHANGED
|
@@ -63,7 +63,8 @@ export class IdMapping {
|
|
|
63
63
|
this.nodesById = nodesById;
|
|
64
64
|
};
|
|
65
65
|
/**
|
|
66
|
-
* Merges the given `that` {@link IdMapping} **in**to `this
|
|
66
|
+
* Merges the given `that` {@link IdMapping} **in**to `this`,
|
|
67
|
+
* overwriting any previous mappings in `this`.
|
|
67
68
|
*/
|
|
68
69
|
this.mergeIn = (that) => {
|
|
69
70
|
for (const id in that.nodesById) {
|
package/dist/id-mapping.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"id-mapping.js","sourceRoot":"","sources":["../src/id-mapping.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,EAAE;AACF,iEAAiE;AACjE,mEAAm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C,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;YAChD,iGAAiG;QACrG,CAAC,CAAA;QAED;;;;WAIG;QACH,qBAAgB,GAAG,CAAC,SAAoB,EAAE,EAAE;YACxC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC/B,CAAC,CAAA;QAED;;;WAGG;QACH,YAAO,GAAG,CAAC,IAAe,EAAE,EAAE;YAC1B,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;gBAC9B,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;YAC5C,CAAC;QACL,CAAC,CAAA;QA1DG,IAAI,CAAC,SAAS,GAAG,EAAC,GAAG,SAAS,EAAC,CAAC;IACpC,CAAC;CA2DJ"}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from "./deserializer.js";
|
|
|
5
5
|
export { deepDuplicateWith } from "./duplicator.js";
|
|
6
6
|
export * from "./id-mapping.js";
|
|
7
7
|
export { combinedFactoryFor } from "./factory.js";
|
|
8
|
+
export { Forest, ObservableForest } from "./forest.js";
|
|
8
9
|
export * from "./LionCore_builtins.g.js";
|
|
9
10
|
export type { IdOrUnresolved } from "./references.js";
|
|
10
11
|
export { idFrom } from "./references.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiBA,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiBA,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEvD,cAAc,0BAA0B,CAAC;AACzC,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,2BAA2B,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,cAAc,2BAA2B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,7 @@ export * from "./deserializer.js";
|
|
|
21
21
|
export { deepDuplicateWith } from "./duplicator.js";
|
|
22
22
|
export * from "./id-mapping.js";
|
|
23
23
|
export { combinedFactoryFor } from "./factory.js";
|
|
24
|
+
export { Forest, ObservableForest } from "./forest.js";
|
|
24
25
|
// skip linking.js: see comment there
|
|
25
26
|
export * from "./LionCore_builtins.g.js";
|
|
26
27
|
export { idFrom } from "./references.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.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,iCA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,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,cAAc,2BAA2B,CAAC"}
|
package/dist/linking.d.ts
CHANGED
|
@@ -11,11 +11,11 @@ import { INodeBase } from "./index.js";
|
|
|
11
11
|
* 2. `feature` — the {@link Link link} feature to install on, or `null` to indicate that it's an annotation.
|
|
12
12
|
* 3. `nodesIds` — are the IDs of the nodes to install.
|
|
13
13
|
* 4. *optional* `originalReferenceTargets` — are the original reference targets of a {@link Reference reference} feature.
|
|
14
|
-
* This element is only present when the feature is a {@link Reference reference}
|
|
14
|
+
* This element is only present when the feature is a {@link Reference reference}.
|
|
15
15
|
* The `nodesIds` and `originalReferenceTargets` match up per index.
|
|
16
16
|
*
|
|
17
17
|
* Note: **DON'T** export this types from the package,
|
|
18
|
-
* as these are only used to align the deserializer and deep-
|
|
18
|
+
* as these are only used to align the deserializer and deep-duplicator.
|
|
19
19
|
*/
|
|
20
20
|
export type NodesToInstall = [container: INodeBase, feature: Link | null, nodesIds: LionWebId[], originalReferenceTargets?: INodeBase[]];
|
|
21
21
|
//# sourceMappingURL=linking.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lionweb/class-core",
|
|
3
|
-
"version": "0.8.0-beta.
|
|
3
|
+
"version": "0.8.0-beta.1",
|
|
4
4
|
"description": "Generic, language-aspecific base types for generated TypeScript APIs",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"release": "npm publish"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@lionweb/core": "0.8.0-beta.
|
|
31
|
-
"@lionweb/json": "0.8.0-beta.
|
|
32
|
-
"@lionweb/ts-utils": "0.8.0-beta.
|
|
30
|
+
"@lionweb/core": "0.8.0-beta.1",
|
|
31
|
+
"@lionweb/json": "0.8.0-beta.1",
|
|
32
|
+
"@lionweb/ts-utils": "0.8.0-beta.1",
|
|
33
33
|
"littoral-templates": "0.5.1",
|
|
34
34
|
"mobx": "6.13.7"
|
|
35
35
|
}
|
package/src/base-types.ts
CHANGED
|
@@ -335,7 +335,7 @@ export abstract class NodeBase implements INodeBase {
|
|
|
335
335
|
|
|
336
336
|
/**
|
|
337
337
|
* A type for functions that acts as factories, creating an instance of {@link INodeBase}
|
|
338
|
-
* matching the given {@link Classifier classifier} and the given ID (of type {@link
|
|
338
|
+
* matching the given {@link Classifier classifier} and the given ID (of type {@link LionWebId}).
|
|
339
339
|
*/
|
|
340
340
|
export type NodeBaseFactory = (classifier: Classifier, id: LionWebId) => INodeBase;
|
|
341
341
|
|
|
@@ -351,3 +351,14 @@ export interface ILanguageBase {
|
|
|
351
351
|
enumLiteralFrom<T>(enumerationLiteral: EnumerationLiteral): T;
|
|
352
352
|
}
|
|
353
353
|
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* The configuration required to be able to instantiate a {@link NodeBaseFactory factory} for a set of languages.
|
|
357
|
+
*/
|
|
358
|
+
export type FactoryConfiguration = {
|
|
359
|
+
/** The {@link ILanguageBase}s for (at least) all the languages used, minus LionCore M3 and built-ins. */
|
|
360
|
+
languageBases: ILanguageBase[],
|
|
361
|
+
/** An optional {@link DeltaReceiver} that will be injected in all {@link INodeBase nodes} created. */
|
|
362
|
+
receiveDelta?: DeltaReceiver
|
|
363
|
+
};
|
|
364
|
+
|
package/src/deserializer.ts
CHANGED
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
import { LionWebId, LionWebJsonChunk, LionWebJsonNode } from "@lionweb/json"
|
|
33
33
|
import { byIdMap, keepDefineds } from "@lionweb/ts-utils"
|
|
34
34
|
|
|
35
|
-
import { DeltaReceiver, IdMapping, ILanguageBase, INodeBase } from "./index.js"
|
|
35
|
+
import { DeltaReceiver, IdMapping, ILanguageBase, INodeBase, FactoryConfiguration } from "./index.js"
|
|
36
36
|
import { combinedLanguageBaseLookupFor } from "./factory.js"
|
|
37
37
|
import { NodesToInstall } from "./linking.js"
|
|
38
38
|
|
|
@@ -60,10 +60,6 @@ export type RootsWithIdMapping = { roots: INodeBase[], idMapping: IdMapping };
|
|
|
60
60
|
* (and partially optional).
|
|
61
61
|
*/
|
|
62
62
|
export type DeserializerConfiguration = {
|
|
63
|
-
/** The {@link ILanguageBase}s for (at least) all the languages used in the {@link LionWebJsonChunk} to deserialize, minus LionCore M3 and built-ins. */
|
|
64
|
-
languageBases: ILanguageBase[],
|
|
65
|
-
/** An optional {@link DeltaReceiver} that will be injected in all {@link INodeBase nodes} created. */
|
|
66
|
-
receiveDelta?: DeltaReceiver,
|
|
67
63
|
/** Default: {@link builtinPropertyValueDeserializer}. */
|
|
68
64
|
propertyValueDeserializer?: PropertyValueDeserializer,
|
|
69
65
|
/** Default: {@link defaultSimplisticHandler}. */
|
|
@@ -81,8 +77,8 @@ function nodeBaseDeserializerWithIdMapping(languageBases: ILanguageBase[], recei
|
|
|
81
77
|
/**
|
|
82
78
|
* @param configuration a {@link DeserializerConfiguration configuration object} for the deserializer.
|
|
83
79
|
*/
|
|
84
|
-
function nodeBaseDeserializerWithIdMapping(configuration: DeserializerConfiguration): Deserializer<RootsWithIdMapping>;
|
|
85
|
-
function nodeBaseDeserializerWithIdMapping(languageBasesOrConfiguration: ILanguageBase[] | DeserializerConfiguration, mayBeReceiveDelta?: DeltaReceiver): Deserializer<RootsWithIdMapping> {
|
|
80
|
+
function nodeBaseDeserializerWithIdMapping(configuration: FactoryConfiguration & DeserializerConfiguration): Deserializer<RootsWithIdMapping>;
|
|
81
|
+
function nodeBaseDeserializerWithIdMapping(languageBasesOrConfiguration: ILanguageBase[] | (FactoryConfiguration & DeserializerConfiguration), mayBeReceiveDelta?: DeltaReceiver): Deserializer<RootsWithIdMapping> {
|
|
86
82
|
const [languageBases, receiveDelta, propertyValueDeserializer, problemsHandler] = Array.isArray(languageBasesOrConfiguration)
|
|
87
83
|
? [languageBasesOrConfiguration, mayBeReceiveDelta, builtinPropertyValueDeserializer, defaultSimplisticHandler]
|
|
88
84
|
: [languageBasesOrConfiguration.languageBases, languageBasesOrConfiguration.receiveDelta, languageBasesOrConfiguration.propertyValueDeserializer ?? builtinPropertyValueDeserializer, languageBasesOrConfiguration.problemsHandler ?? defaultSimplisticHandler];
|
|
@@ -231,8 +227,8 @@ function nodeBaseDeserializer(languageBases: ILanguageBase[], receiveDelta?: Del
|
|
|
231
227
|
/**
|
|
232
228
|
* @param configuration a {@link DeserializerConfiguration configuration object} for the deserializer.
|
|
233
229
|
*/
|
|
234
|
-
function nodeBaseDeserializer(configuration: DeserializerConfiguration): Deserializer<INodeBase[]>;
|
|
235
|
-
function nodeBaseDeserializer(languageBasesOrConfiguration: ILanguageBase[] | DeserializerConfiguration, receiveDelta?: DeltaReceiver): Deserializer<INodeBase[]> {
|
|
230
|
+
function nodeBaseDeserializer(configuration: FactoryConfiguration & DeserializerConfiguration): Deserializer<INodeBase[]>;
|
|
231
|
+
function nodeBaseDeserializer(languageBasesOrConfiguration: ILanguageBase[] | (FactoryConfiguration & DeserializerConfiguration), receiveDelta?: DeltaReceiver): Deserializer<INodeBase[]> {
|
|
236
232
|
return (
|
|
237
233
|
serializationChunk,
|
|
238
234
|
idMapping
|
package/src/forest.ts
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// Copyright 2025 TRUMPF Laser SE and other contributors
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License")
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
|
|
16
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
|
|
18
|
+
import { isPartition } from "@lionweb/core"
|
|
19
|
+
import { LionWebJsonChunk } from "@lionweb/json"
|
|
20
|
+
import { action, makeObservable, observable } from "mobx"
|
|
21
|
+
|
|
22
|
+
import { FactoryConfiguration, ILanguageBase, INodeBase, NodeBaseFactory } from "./base-types.js"
|
|
23
|
+
import {
|
|
24
|
+
applyDeltaWithLookup,
|
|
25
|
+
DeltaReceiver,
|
|
26
|
+
IDelta,
|
|
27
|
+
PartitionAddedDelta,
|
|
28
|
+
PartitionDeletedDelta,
|
|
29
|
+
updateIdMappingWithDelta
|
|
30
|
+
} from "./deltas/index.js"
|
|
31
|
+
import {
|
|
32
|
+
Deserializer,
|
|
33
|
+
DeserializerConfiguration,
|
|
34
|
+
nodeBaseDeserializerWithIdMapping,
|
|
35
|
+
RootsWithIdMapping
|
|
36
|
+
} from "./deserializer.js"
|
|
37
|
+
import { combinedFactoryFor } from "./factory.js"
|
|
38
|
+
import { IdMapping } from "./id-mapping.js"
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* An instance of this class encompasses a complete model (=“forest”), to conveniently encapsulate that.
|
|
43
|
+
* (Essentially, it’s a sort of in-memory repository.)
|
|
44
|
+
*/
|
|
45
|
+
export class Forest {
|
|
46
|
+
|
|
47
|
+
private readonly languageBases: ILanguageBase[]
|
|
48
|
+
|
|
49
|
+
private readonly receiveDelta?: DeltaReceiver
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The partitions contained in `this` forest.
|
|
53
|
+
*/
|
|
54
|
+
readonly partitions: INodeBase[]
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The {@link IdMapping ID mapping} mapping to all nodes in any of the partitions in `this` forest from the IDs of those nodes **plus** *unattached* nodes.
|
|
58
|
+
* A node is attached if it’s a partition – i.e., its classifier is marked as a partition –, or if it’s – directly, or indirectly – contained by a partition.
|
|
59
|
+
* This may happen as a result of deleting nodes, or of unattached nodes being deserialized into `this` forest through the `deserializeInto` or `applyDelta[s]` methods.
|
|
60
|
+
*/
|
|
61
|
+
readonly idMapping: IdMapping // We need to expose this to be able to instantiate an EventToDeltaTranslator!
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* A {@link NodeBaseFactory factory} for nodes with classifiers from the {@link ILanguageBase language bases} passed during instantiation of `this` forest.
|
|
65
|
+
* This factory method installs the {@link DeltaReceiver} that may be passed during instantiation of `this` forest.
|
|
66
|
+
*/
|
|
67
|
+
readonly createNode: NodeBaseFactory
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* A {@link Deserializer deserializer} that returns roots/partitions together with an ID mapping for all nodes in those.
|
|
71
|
+
* *Note*: this is primarily for internal use — specifically: to create an event-to-delta translator with.
|
|
72
|
+
* (That translator uses type from `delta-protocol-common` so we don’t want to have it here.)
|
|
73
|
+
* Using this method does *not* change `this` forest’s state.
|
|
74
|
+
*/
|
|
75
|
+
readonly deserializeWithIdMapping: Deserializer<RootsWithIdMapping>
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
constructor(configuration: FactoryConfiguration & DeserializerConfiguration) {
|
|
79
|
+
this.languageBases = configuration.languageBases
|
|
80
|
+
this.receiveDelta = configuration.receiveDelta
|
|
81
|
+
this.partitions = []
|
|
82
|
+
this.idMapping = new IdMapping({})
|
|
83
|
+
this.createNode = combinedFactoryFor(this.languageBases, this.receiveDelta)
|
|
84
|
+
this.deserializeWithIdMapping = nodeBaseDeserializerWithIdMapping(configuration)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
private emitDelta = (thunk: () => IDelta) => {
|
|
89
|
+
if (this.receiveDelta) {
|
|
90
|
+
this.receiveDelta(thunk())
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Adds the given `partition` to the partitions of `this` forest – provided it’s not already part of it –,
|
|
96
|
+
* and emits the corresponding {@link PartitionAddedDelta}.
|
|
97
|
+
*/
|
|
98
|
+
addPartition = (partition: INodeBase) => {
|
|
99
|
+
if (!isPartition(partition.classifier)) {
|
|
100
|
+
throw new Error(`node with ID ${partition.id} is a ${partition.classifier.name} which is not a <<partition>> concept`)
|
|
101
|
+
}
|
|
102
|
+
if (this.partitions.indexOf(partition) === -1) {
|
|
103
|
+
this.partitions.push(partition)
|
|
104
|
+
this.idMapping.updateWith(partition)
|
|
105
|
+
this.emitDelta(() => new PartitionAddedDelta(partition))
|
|
106
|
+
} // else: ignore; already done
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Deletes the indicated `partition` from the partitions of `this` forest – provided it’s part of it –,
|
|
111
|
+
* and emits the corresponding {@link PartitionDeletedDelta}.
|
|
112
|
+
*/
|
|
113
|
+
deletePartition = (partition: INodeBase) => {
|
|
114
|
+
const index = this.partitions.indexOf(partition)
|
|
115
|
+
if (index > -1) {
|
|
116
|
+
this.partitions.splice(index, 1)
|
|
117
|
+
this.emitDelta(() => new PartitionDeletedDelta(partition))
|
|
118
|
+
} else {
|
|
119
|
+
throw new Error(`node with id "${partition.id}" is not an added partition`)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Deserializes the given `serializationChunk` and adds any partitions in it to the partitions of `this` forest,
|
|
125
|
+
* It also updates the ID mapping, including with mappings for deserialized unattached nodes.
|
|
126
|
+
*/
|
|
127
|
+
deserializeInto = (serializationChunk: LionWebJsonChunk): INodeBase[] => {
|
|
128
|
+
const { roots: newRoots, idMapping: newIdMapping } = this.deserializeWithIdMapping(serializationChunk, this.idMapping)
|
|
129
|
+
this.partitions.push(...newRoots.filter((newRoot) => isPartition(newRoot.classifier)))
|
|
130
|
+
this.idMapping.mergeIn(newIdMapping) // also merge in new unattached, non-partition roots
|
|
131
|
+
return newRoots
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Applies the given `delta`, taking care of updating the state of the internal ID mapping.
|
|
136
|
+
*/
|
|
137
|
+
applyDelta = (delta: IDelta) => {
|
|
138
|
+
applyDeltaWithLookup(this.idMapping, delta, () => this.partitions)
|
|
139
|
+
updateIdMappingWithDelta(this.idMapping, delta)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Applies the given `deltas`, taking care of updating the state of the internal ID mapping.
|
|
144
|
+
*/
|
|
145
|
+
applyDeltas = (deltas: IDelta[]) => {
|
|
146
|
+
deltas.forEach((delta) => this.applyDelta(delta))
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* “Mobx-ified” version of the {@link Forest} class.
|
|
154
|
+
*/
|
|
155
|
+
export class ObservableForest extends Forest {
|
|
156
|
+
|
|
157
|
+
constructor(configuration: FactoryConfiguration & DeserializerConfiguration) {
|
|
158
|
+
super(configuration)
|
|
159
|
+
makeObservable(
|
|
160
|
+
this,
|
|
161
|
+
{
|
|
162
|
+
partitions: observable,
|
|
163
|
+
addPartition: action,
|
|
164
|
+
deserializeInto: action,
|
|
165
|
+
applyDelta: action,
|
|
166
|
+
applyDeltas: action
|
|
167
|
+
}
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
}
|
|
172
|
+
// (but also see: https://mobx.js.org/subclassing.html)
|
|
173
|
+
|
package/src/id-mapping.ts
CHANGED
|
@@ -88,7 +88,8 @@ export class IdMapping {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
|
-
* Merges the given `that` {@link IdMapping} **in**to `this
|
|
91
|
+
* Merges the given `that` {@link IdMapping} **in**to `this`,
|
|
92
|
+
* overwriting any previous mappings in `this`.
|
|
92
93
|
*/
|
|
93
94
|
mergeIn = (that: IdMapping) => {
|
|
94
95
|
for (const id in that.nodesById) {
|
package/src/index.ts
CHANGED
|
@@ -22,6 +22,7 @@ export * from "./deserializer.js";
|
|
|
22
22
|
export { deepDuplicateWith } from "./duplicator.js";
|
|
23
23
|
export * from "./id-mapping.js";
|
|
24
24
|
export { combinedFactoryFor } from "./factory.js";
|
|
25
|
+
export { Forest, ObservableForest } from "./forest.js";
|
|
25
26
|
// skip linking.js: see comment there
|
|
26
27
|
export * from "./LionCore_builtins.g.js";
|
|
27
28
|
export type { IdOrUnresolved } from "./references.js";
|
package/src/linking.ts
CHANGED
|
@@ -30,11 +30,11 @@ import { INodeBase } from "./index.js"
|
|
|
30
30
|
* 2. `feature` — the {@link Link link} feature to install on, or `null` to indicate that it's an annotation.
|
|
31
31
|
* 3. `nodesIds` — are the IDs of the nodes to install.
|
|
32
32
|
* 4. *optional* `originalReferenceTargets` — are the original reference targets of a {@link Reference reference} feature.
|
|
33
|
-
* This element is only present when the feature is a {@link Reference reference}
|
|
33
|
+
* This element is only present when the feature is a {@link Reference reference}.
|
|
34
34
|
* The `nodesIds` and `originalReferenceTargets` match up per index.
|
|
35
35
|
*
|
|
36
36
|
* Note: **DON'T** export this types from the package,
|
|
37
|
-
* as these are only used to align the deserializer and deep-
|
|
37
|
+
* as these are only used to align the deserializer and deep-duplicator.
|
|
38
38
|
*/
|
|
39
39
|
export type NodesToInstall = [ container: INodeBase, feature: Link | null, nodesIds: LionWebId[], originalReferenceTargets?: INodeBase[] ];
|
|
40
40
|
|