@lionweb/class-core 0.7.0-beta.16 → 0.7.0-beta.17
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 +4 -1
- package/dist/deserializer.d.ts +1 -1
- package/dist/deserializer.d.ts.map +1 -1
- package/dist/deserializer.js +1 -1
- package/dist/deserializer.js.map +1 -1
- package/dist/feature-resolvers.d.ts +15 -1
- package/dist/feature-resolvers.d.ts.map +1 -1
- package/dist/feature-resolvers.js +31 -6
- package/dist/feature-resolvers.js.map +1 -1
- package/dist/id-mapping.d.ts +8 -2
- package/dist/id-mapping.d.ts.map +1 -1
- package/dist/id-mapping.js +7 -0
- package/dist/id-mapping.js.map +1 -1
- package/package.json +4 -4
- package/src/deserializer.ts +10 -10
- package/src/feature-resolvers.ts +51 -9
- package/src/id-mapping.ts +14 -2
package/CHANGELOG.md
CHANGED
|
@@ -20,7 +20,10 @@
|
|
|
20
20
|
* Implement inverters for all deltas.
|
|
21
21
|
* Fix single-containment and -reference value managers.
|
|
22
22
|
* (Fix a small cosmetic thing in `asTreeTextWith`: unset properties’ values now get shown as “`<not set>`” instead of as “`$<not set>`” — note the removed `$`.)
|
|
23
|
-
* Expose feature resolution with proper checking to avoid undebuggable `
|
|
23
|
+
* Expose feature resolution with proper checking to avoid undebuggable `undefined` dereferencing at runtime in `deltaDeserializer` and `eventToDeltaTranslator` functions.
|
|
24
|
+
* Dependent nodes can now be passed to a deserializer as an `IdMapping` instance as well.
|
|
25
|
+
* Add a getter `raw` to the `IdMapping` class that returns a snapshot of the internal hashmap ID → node.
|
|
26
|
+
* The `NodesById` type is now exported as well, to that end.
|
|
24
27
|
|
|
25
28
|
|
|
26
29
|
## 0.6.13
|
package/dist/deserializer.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { DeltaReceiver, IdMapping, ILanguageBase, INodeBase } from "./index.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* A type for deserializer functions that are parametrized in their return type.
|
|
6
6
|
*/
|
|
7
|
-
export type Deserializer<T> = (serializationChunk: LionWebJsonChunk, dependentNodes?: INodeBase[], propertyValueDeserializer?: PropertyValueDeserializer, problemHandler?: SimplisticHandler) => T;
|
|
7
|
+
export type Deserializer<T> = (serializationChunk: LionWebJsonChunk, dependentNodes?: (INodeBase[] | IdMapping), propertyValueDeserializer?: PropertyValueDeserializer, problemHandler?: SimplisticHandler) => T;
|
|
8
8
|
/**
|
|
9
9
|
* A quasi-tuple of the roots (of type {@link INodeBase}) of a model,
|
|
10
10
|
* and its {@link IdMapping} instance.
|
|
@@ -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;AAK/E;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAC1B,kBAAkB,EAAE,gBAAgB,EACpC,cAAc,CAAC,EAAE,SAAS,EAAE,
|
|
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;AAK/E;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAC1B,kBAAkB,EAAE,gBAAgB,EACpC,cAAc,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,SAAS,CAAC,EAC1C,yBAAyB,CAAC,EAAE,yBAAyB,EACrD,cAAc,CAAC,EAAE,iBAAiB,KACjC,CAAC,CAAC;AAGP;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAAE,KAAK,EAAE,SAAS,EAAE,CAAC;IAAC,SAAS,EAAE,SAAS,CAAA;CAAE,CAAC;AAG9E;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,GAAI,eAAe,aAAa,EAAE,EAAE,eAAe,aAAa,KAAG,YAAY,CAAC,kBAAkB,CAyI/I,CAAC;AAGF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAAI,eAAe,aAAa,EAAE,EAAE,eAAe,aAAa,KAAG,YAAY,CAAC,SAAS,EAAE,CAS3H,CAAA"}
|
package/dist/deserializer.js
CHANGED
|
@@ -93,7 +93,7 @@ export const nodeBaseDeserializerWithIdMapping = (languageBases, receiveDelta) =
|
|
|
93
93
|
const nodesById = byIdMap(keepDefineds(serializationChunk
|
|
94
94
|
.nodes
|
|
95
95
|
.map(createNode)));
|
|
96
|
-
const dependentNodesById = byIdMap(dependentNodes);
|
|
96
|
+
const dependentNodesById = dependentNodes instanceof IdMapping ? dependentNodes.raw : byIdMap(dependentNodes);
|
|
97
97
|
const lookupNodeById = (id) => nodesById[id] ?? dependentNodesById[id];
|
|
98
98
|
nodesToInstall.forEach(([node, feature, ids]) => {
|
|
99
99
|
if (feature instanceof Containment) {
|
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,EA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BAAM,CAAC;wBACJ,YAAY,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;wBACxC,aAAa,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;oBAC1C,CAAC;gBACL,CAAC,CAAC,CAAC;gBACH,OAAO;YACX,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO;YACH,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC;iBAC1B,MAAM,CAAC,CAAC,EAAC,MAAM,EAAC,EAAE,EAAE,CAAC,MAAM,KAAK,SAAS,CAAC;YAC/C,SAAS,EAAE,IAAI,SAAS,CAAC,EAAE,GAAG,SAAS,EAAE,GAAG,kBAAkB,EAAE,CAAC;SACpE,CAAC;IAEN,CAAC,CAAC;AACN,CAAC,CAAC;AAGF;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,aAA8B,EAAE,YAA4B,EAA6B,EAAE;IAC5H,MAAM,yBAAyB,GAAG,iCAAiC,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;IACjG,OAAO,CACH,kBAAkB,EAClB,cAAc,GAAG,EAAE,EACnB,yBAAyB,GAAG,IAAI,gCAAgC,EAAE,EAClE,eAAe,GAAG,wBAAwB,EAC/B,EAAE,CACb,yBAAyB,CAAC,kBAAkB,EAAE,cAAc,EAAE,yBAAyB,EAAE,eAAe,CAAC,CAAC,KAAK,CAAA;AACvH,CAAC,CAAA"}
|
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
import { Containment, Feature, Language, Property, Reference } from "@lionweb/core";
|
|
2
2
|
import { LionWebJsonMetaPointer } from "@lionweb/json";
|
|
3
3
|
import { INodeBase } from "./base-types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Type def. for functions that resolve a {@link Feature feature} of the indicated sub-type
|
|
6
|
+
* from a feature's and a classifier's meta-pointers,
|
|
7
|
+
* throwing an {@link Error error} when the feature couldn't be resolved,
|
|
8
|
+
* or it isn't of the expected sub-type.
|
|
9
|
+
*/
|
|
4
10
|
export type FeatureResolver<FT extends Feature> = (metaPointer: LionWebJsonMetaPointer, container: INodeBase) => FT;
|
|
5
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Type def. for an object containing {@link FeatureResolver resolvers} for
|
|
13
|
+
* {@link Property properties}, {@link Containmnent containments}, and {@link Reference references}.
|
|
14
|
+
*/
|
|
15
|
+
export type FeatureResolvers = {
|
|
6
16
|
resolvedPropertyFrom: FeatureResolver<Property>;
|
|
7
17
|
resolvedContainmentFrom: FeatureResolver<Containment>;
|
|
8
18
|
resolvedReferenceFrom: FeatureResolver<Reference>;
|
|
9
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* @return an {@link FeatureResolvers object} for the given {@link Language languages}.
|
|
22
|
+
*/
|
|
23
|
+
export declare const featureResolversFor: (languages: Language[]) => FeatureResolvers;
|
|
10
24
|
//# sourceMappingURL=feature-resolvers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature-resolvers.d.ts","sourceRoot":"","sources":["../src/feature-resolvers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"feature-resolvers.d.ts","sourceRoot":"","sources":["../src/feature-resolvers.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAwB,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACzG,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAG3C;;;;;GAKG;AACH,MAAM,MAAM,eAAe,CAAC,EAAE,SAAS,OAAO,IAAI,CAAC,WAAW,EAAE,sBAAsB,EAAE,SAAS,EAAE,SAAS,KAAK,EAAE,CAAA;AAEnH;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC3B,oBAAoB,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAA;IAC/C,uBAAuB,EAAE,eAAe,CAAC,WAAW,CAAC,CAAA;IACrD,qBAAqB,EAAE,eAAe,CAAC,SAAS,CAAC,CAAA;CACpD,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAAI,WAAW,QAAQ,EAAE,KAAG,gBA0B3D,CAAA"}
|
|
@@ -1,17 +1,42 @@
|
|
|
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
|
|
1
17
|
import { Containment, MemoisingSymbolTable, Property, Reference } from "@lionweb/core";
|
|
18
|
+
/**
|
|
19
|
+
* @return an {@link FeatureResolvers object} for the given {@link Language languages}.
|
|
20
|
+
*/
|
|
2
21
|
export const featureResolversFor = (languages) => {
|
|
3
22
|
const symbolTable = new MemoisingSymbolTable(languages);
|
|
4
23
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
-
const featureResolverFor = (
|
|
6
|
-
const
|
|
7
|
-
const
|
|
24
|
+
const featureResolverFor = (featureClassConstructor) => (featureMetaPointer, container) => {
|
|
25
|
+
const classifierMetaPointer = container.classifier.metaPointer();
|
|
26
|
+
const featureLocationMessage = () => `feature with meta-pointer ${JSON.stringify(featureMetaPointer)} on instance with ID="${container.id}" with meta-pointer ${JSON.stringify(classifierMetaPointer)}`;
|
|
27
|
+
const feature = symbolTable.featureMatching(classifierMetaPointer, featureMetaPointer);
|
|
8
28
|
if (feature === undefined) {
|
|
9
29
|
throw new Error(`couldn't resolve ${featureLocationMessage()}`); // fail early <== unrecoverable
|
|
10
30
|
}
|
|
11
|
-
if (
|
|
12
|
-
throw new Error(`${featureLocationMessage()} is not a ${
|
|
31
|
+
if (feature.constructor !== featureClassConstructor) { // feature's type must match desired type *exactly*
|
|
32
|
+
throw new Error(`${featureLocationMessage()} is not a ${featureClassConstructor.name} but a ${feature.constructor.name}`); // fail early <== unrecoverable
|
|
13
33
|
}
|
|
14
|
-
|
|
34
|
+
/*
|
|
35
|
+
* We could make this function memoising as well, to avoid having to perform these checks every resolution.
|
|
36
|
+
* That memoisation would involve a 6-deep lookup, in the feature's meta-pointer + container's classifier meta-pointer.
|
|
37
|
+
* The checks seem cheap enough to not be problematic performance-wise, though.
|
|
38
|
+
*/
|
|
39
|
+
return feature; // valid <== feature.constructor === featureClassConstructor
|
|
15
40
|
};
|
|
16
41
|
return {
|
|
17
42
|
resolvedPropertyFrom: featureResolverFor(Property),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature-resolvers.js","sourceRoot":"","sources":["../src/feature-resolvers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAqB,oBAAoB,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"feature-resolvers.js","sourceRoot":"","sources":["../src/feature-resolvers.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,EAAE,WAAW,EAAq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AAC;KACvD,CAAA;AACL,CAAC,CAAA"}
|
package/dist/id-mapping.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { IdOrUnresolved, SingleRef } from "@lionweb/core";
|
|
2
2
|
import { LionWebId } from "@lionweb/json";
|
|
3
3
|
import { INodeBase } from "./index.js";
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Type def. for a (hash-)map {@link LionWebId ID} → {@link INodeBase}.
|
|
6
|
+
*/
|
|
7
|
+
export type NodesById = {
|
|
5
8
|
[id: LionWebId]: INodeBase;
|
|
6
9
|
};
|
|
7
10
|
/**
|
|
@@ -37,6 +40,9 @@ export declare class IdMapping {
|
|
|
37
40
|
* and should only be used by components which are in complete control of the nodes being passed to this method.
|
|
38
41
|
*/
|
|
39
42
|
reinitializeWith: (nodesById: NodesById) => void;
|
|
43
|
+
/**
|
|
44
|
+
* A raw snapshot of this ID mapping, as a {@link NodesById} object (that is a defensive copy).
|
|
45
|
+
*/
|
|
46
|
+
get raw(): NodesById;
|
|
40
47
|
}
|
|
41
|
-
export {};
|
|
42
48
|
//# sourceMappingURL=id-mapping.d.ts.map
|
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,cAAc,EAAE,SAAS,EAAc,MAAM,eAAe,CAAA;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAEzC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"id-mapping.d.ts","sourceRoot":"","sources":["../src/id-mapping.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAc,MAAM,eAAe,CAAA;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAEzC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAGtC;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IAAE,CAAC,EAAE,EAAE,SAAS,GAAG,SAAS,CAAA;CAAE,CAAA;AAGtD;;;;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,GAAG,MAAM,SAAS,UAK3B;IAED;;;;OAIG;IACH,gBAAgB,GAAI,WAAW,SAAS,UAEvC;IAED;;OAEG;IACH,IAAI,GAAG,IAAI,SAAS,CAEnB;CAEJ"}
|
package/dist/id-mapping.js
CHANGED
|
@@ -52,6 +52,7 @@ export class IdMapping {
|
|
|
52
52
|
this.nodesById[node.id] = node;
|
|
53
53
|
node.children // recurse into all children
|
|
54
54
|
.forEach((child) => this.updateWith(child));
|
|
55
|
+
// TODO figure out when it's really necessary to call this, as it's potentially *very* expensive
|
|
55
56
|
};
|
|
56
57
|
/**
|
|
57
58
|
* Re-initializes this {@link IdMapping ID mapping} with the given nodes-by-ID.
|
|
@@ -63,5 +64,11 @@ export class IdMapping {
|
|
|
63
64
|
};
|
|
64
65
|
this.nodesById = { ...nodesById };
|
|
65
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* A raw snapshot of this ID mapping, as a {@link NodesById} object (that is a defensive copy).
|
|
69
|
+
*/
|
|
70
|
+
get raw() {
|
|
71
|
+
return { ...this.nodesById };
|
|
72
|
+
}
|
|
66
73
|
}
|
|
67
74
|
//# sourceMappingURL=id-mapping.js.map
|
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,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,EAA6B,UAAU,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"id-mapping.js","sourceRoot":"","sources":["../src/id-mapping.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,EAA6B,UAAU,EAAE,MAAM,eAAe,CAAA;AAYrE;;;;GAIG;AACH,MAAM,OAAO,SAAS;IAGlB,YAAY,SAAoB;QAGhC,iEAAiE;QAEjE;;;WAGG;QACH,WAAM,GAAG,CAAC,EAAa,EAAa,EAAE;YAClC,IAAI,CAAC,CAAC,EAAE,IAAI,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC1B,MAAM,IAAI,KAAK,CAAC,gBAAgB,EAAE,oBAAoB,CAAC,CAAC;YAC5D,CAAC;YACD,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;QAC9B,CAAC,CAAA;QAED;;;WAGG;QACH,cAAS,GAAG,CAAC,EAAa,EAA2B,EAAE,CACnD,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;QAEvB;;;WAGG;QACH,cAAS,GAAG,CAAC,cAA8B,EAAwB,EAAE,CACjE,cAAc,KAAK,UAAU;YACzB,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,UAAU,CAAC,CAAC;QAEzD;;WAEG;QACH,eAAU,GAAE,CAAC,IAAe,EAAE,EAAE;YAC5B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;YAC/B,IAAI,CAAC,QAAQ,CAAG,4BAA4B;iBACvC,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;QAhDG,IAAI,CAAC,SAAS,GAAG,EAAC,GAAG,SAAS,EAAC,CAAC;IACpC,CAAC;IAiDD;;OAEG;IACH,IAAI,GAAG;QACH,OAAO,EAAC,GAAG,IAAI,CAAC,SAAS,EAAC,CAAC;IAC/B,CAAC;CAEJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lionweb/class-core",
|
|
3
|
-
"version": "0.7.0-beta.
|
|
3
|
+
"version": "0.7.0-beta.17",
|
|
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.7.0-beta.
|
|
31
|
-
"@lionweb/json": "0.7.0-beta.
|
|
32
|
-
"@lionweb/ts-utils": "0.7.0-beta.
|
|
30
|
+
"@lionweb/core": "0.7.0-beta.17",
|
|
31
|
+
"@lionweb/json": "0.7.0-beta.17",
|
|
32
|
+
"@lionweb/ts-utils": "0.7.0-beta.17",
|
|
33
33
|
"littoral-templates": "0.5.0",
|
|
34
34
|
"mobx": "6.13.7"
|
|
35
35
|
}
|
package/src/deserializer.ts
CHANGED
|
@@ -42,7 +42,7 @@ import { NodesToInstall } from "./linking.js"
|
|
|
42
42
|
*/
|
|
43
43
|
export type Deserializer<T> = (
|
|
44
44
|
serializationChunk: LionWebJsonChunk,
|
|
45
|
-
dependentNodes?: INodeBase[],
|
|
45
|
+
dependentNodes?: (INodeBase[] | IdMapping),
|
|
46
46
|
propertyValueDeserializer?: PropertyValueDeserializer,
|
|
47
47
|
problemHandler?: SimplisticHandler
|
|
48
48
|
) => T;
|
|
@@ -66,10 +66,10 @@ export const nodeBaseDeserializerWithIdMapping = (languageBases: ILanguageBase[]
|
|
|
66
66
|
const languageBaseFor = combinedLanguageBaseLookupFor(languageBases);
|
|
67
67
|
|
|
68
68
|
return (
|
|
69
|
-
serializationChunk
|
|
70
|
-
dependentNodes
|
|
71
|
-
propertyValueDeserializer
|
|
72
|
-
problemsHandler
|
|
69
|
+
serializationChunk,
|
|
70
|
+
dependentNodes = [],
|
|
71
|
+
propertyValueDeserializer = new BuiltinPropertyValueDeserializer(),
|
|
72
|
+
problemsHandler = defaultSimplisticHandler
|
|
73
73
|
): RootsWithIdMapping => {
|
|
74
74
|
|
|
75
75
|
const nodesToInstall: NodesToInstall[] = [];
|
|
@@ -143,7 +143,7 @@ export const nodeBaseDeserializerWithIdMapping = (languageBases: ILanguageBase[]
|
|
|
143
143
|
)
|
|
144
144
|
);
|
|
145
145
|
|
|
146
|
-
const dependentNodesById = byIdMap(dependentNodes)
|
|
146
|
+
const dependentNodesById = dependentNodes instanceof IdMapping ? dependentNodes.raw : byIdMap(dependentNodes);
|
|
147
147
|
|
|
148
148
|
const lookupNodeById = (id: LionWebId) =>
|
|
149
149
|
nodesById[id] ?? dependentNodesById[id];
|
|
@@ -208,10 +208,10 @@ export const nodeBaseDeserializerWithIdMapping = (languageBases: ILanguageBase[]
|
|
|
208
208
|
export const nodeBaseDeserializer = (languageBases: ILanguageBase[], receiveDelta?: DeltaReceiver): Deserializer<INodeBase[]> => {
|
|
209
209
|
const deserializerWithIdMapping = nodeBaseDeserializerWithIdMapping(languageBases, receiveDelta);
|
|
210
210
|
return (
|
|
211
|
-
serializationChunk
|
|
212
|
-
dependentNodes
|
|
213
|
-
propertyValueDeserializer
|
|
214
|
-
problemsHandler
|
|
211
|
+
serializationChunk,
|
|
212
|
+
dependentNodes = [],
|
|
213
|
+
propertyValueDeserializer = new BuiltinPropertyValueDeserializer(),
|
|
214
|
+
problemsHandler = defaultSimplisticHandler
|
|
215
215
|
): INodeBase[] =>
|
|
216
216
|
deserializerWithIdMapping(serializationChunk, dependentNodes, propertyValueDeserializer, problemsHandler).roots
|
|
217
217
|
}
|
package/src/feature-resolvers.ts
CHANGED
|
@@ -1,24 +1,66 @@
|
|
|
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
|
+
|
|
1
18
|
import { Containment, Feature, Language, MemoisingSymbolTable, Property, Reference } from "@lionweb/core"
|
|
2
19
|
import { LionWebJsonMetaPointer } from "@lionweb/json"
|
|
3
20
|
import { INodeBase } from "./base-types.js"
|
|
4
21
|
|
|
5
22
|
|
|
6
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Type def. for functions that resolve a {@link Feature feature} of the indicated sub-type
|
|
25
|
+
* from a feature's and a classifier's meta-pointers,
|
|
26
|
+
* throwing an {@link Error error} when the feature couldn't be resolved,
|
|
27
|
+
* or it isn't of the expected sub-type.
|
|
28
|
+
*/
|
|
29
|
+
export type FeatureResolver<FT extends Feature> = (metaPointer: LionWebJsonMetaPointer, container: INodeBase) => FT
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Type def. for an object containing {@link FeatureResolver resolvers} for
|
|
33
|
+
* {@link Property properties}, {@link Containmnent containments}, and {@link Reference references}.
|
|
34
|
+
*/
|
|
35
|
+
export type FeatureResolvers = {
|
|
36
|
+
resolvedPropertyFrom: FeatureResolver<Property>
|
|
37
|
+
resolvedContainmentFrom: FeatureResolver<Containment>
|
|
38
|
+
resolvedReferenceFrom: FeatureResolver<Reference>
|
|
39
|
+
}
|
|
7
40
|
|
|
8
|
-
|
|
41
|
+
/**
|
|
42
|
+
* @return an {@link FeatureResolvers object} for the given {@link Language languages}.
|
|
43
|
+
*/
|
|
44
|
+
export const featureResolversFor = (languages: Language[]): FeatureResolvers => {
|
|
9
45
|
const symbolTable = new MemoisingSymbolTable(languages)
|
|
10
46
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
-
const featureResolverFor = <FT extends Feature>(
|
|
12
|
-
(
|
|
13
|
-
const
|
|
14
|
-
const
|
|
47
|
+
const featureResolverFor = <FT extends Feature>(featureClassConstructor: new (...args: any[]) => FT): FeatureResolver<FT> =>
|
|
48
|
+
(featureMetaPointer, container) => {
|
|
49
|
+
const classifierMetaPointer = container.classifier.metaPointer()
|
|
50
|
+
const featureLocationMessage = () => `feature with meta-pointer ${JSON.stringify(featureMetaPointer)} on instance with ID="${container.id}" with meta-pointer ${JSON.stringify(classifierMetaPointer)}`
|
|
51
|
+
const feature = symbolTable.featureMatching(classifierMetaPointer, featureMetaPointer)
|
|
15
52
|
if (feature === undefined) {
|
|
16
53
|
throw new Error(`couldn't resolve ${featureLocationMessage()}`) // fail early <== unrecoverable
|
|
17
54
|
}
|
|
18
|
-
if (
|
|
19
|
-
throw new Error(`${featureLocationMessage()} is not a ${
|
|
55
|
+
if (feature.constructor !== featureClassConstructor) { // feature's type must match desired type *exactly*
|
|
56
|
+
throw new Error(`${featureLocationMessage()} is not a ${featureClassConstructor.name} but a ${feature.constructor.name}`) // fail early <== unrecoverable
|
|
20
57
|
}
|
|
21
|
-
|
|
58
|
+
/*
|
|
59
|
+
* We could make this function memoising as well, to avoid having to perform these checks every resolution.
|
|
60
|
+
* That memoisation would involve a 6-deep lookup, in the feature's meta-pointer + container's classifier meta-pointer.
|
|
61
|
+
* The checks seem cheap enough to not be problematic performance-wise, though.
|
|
62
|
+
*/
|
|
63
|
+
return feature as FT // valid <== feature.constructor === featureClassConstructor
|
|
22
64
|
}
|
|
23
65
|
return {
|
|
24
66
|
resolvedPropertyFrom: featureResolverFor(Property),
|
package/src/id-mapping.ts
CHANGED
|
@@ -20,7 +20,11 @@ import { LionWebId } from "@lionweb/json"
|
|
|
20
20
|
|
|
21
21
|
import { INodeBase } from "./index.js"
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Type def. for a (hash-)map {@link LionWebId ID} → {@link INodeBase}.
|
|
26
|
+
*/
|
|
27
|
+
export type NodesById = { [id: LionWebId]: INodeBase }
|
|
24
28
|
|
|
25
29
|
|
|
26
30
|
/**
|
|
@@ -70,6 +74,7 @@ export class IdMapping {
|
|
|
70
74
|
this.nodesById[node.id] = node;
|
|
71
75
|
node.children // recurse into all children
|
|
72
76
|
.forEach((child) => this.updateWith(child));
|
|
77
|
+
// TODO figure out when it's really necessary to call this, as it's potentially *very* expensive
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
/**
|
|
@@ -78,7 +83,14 @@ export class IdMapping {
|
|
|
78
83
|
* and should only be used by components which are in complete control of the nodes being passed to this method.
|
|
79
84
|
*/
|
|
80
85
|
reinitializeWith = (nodesById: NodesById) => {
|
|
81
|
-
this.nodesById = nodesById
|
|
86
|
+
this.nodesById = nodesById;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* A raw snapshot of this ID mapping, as a {@link NodesById} object (that is a defensive copy).
|
|
91
|
+
*/
|
|
92
|
+
get raw(): NodesById {
|
|
93
|
+
return {...this.nodesById};
|
|
82
94
|
}
|
|
83
95
|
|
|
84
96
|
}
|