@lionweb/core 0.7.0-beta.9 → 0.7.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 +11 -0
- package/dist/deserializer.d.ts +2 -3
- package/dist/deserializer.d.ts.map +1 -1
- package/dist/deserializer.js +9 -12
- package/dist/deserializer.js.map +1 -1
- package/dist/extraction.d.ts.map +1 -1
- package/dist/functions.d.ts.map +1 -1
- package/dist/handler.d.ts +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/m1/reference-utils.d.ts +1 -1
- package/dist/m1/reference-utils.d.ts.map +1 -1
- package/dist/m3/builtins.d.ts +16 -0
- package/dist/m3/builtins.d.ts.map +1 -1
- package/dist/m3/builtins.js +24 -1
- package/dist/m3/builtins.js.map +1 -1
- package/dist/m3/constraints.d.ts.map +1 -1
- package/dist/m3/deserializer.d.ts.map +1 -1
- package/dist/m3/deserializer.js +2 -2
- package/dist/m3/deserializer.js.map +1 -1
- package/dist/m3/feature-resolvers.d.ts +23 -0
- package/dist/m3/feature-resolvers.d.ts.map +1 -0
- package/dist/m3/feature-resolvers.js +48 -0
- package/dist/m3/feature-resolvers.js.map +1 -0
- package/dist/m3/functions.d.ts.map +1 -1
- package/dist/m3/index.d.ts +2 -0
- package/dist/m3/index.d.ts.map +1 -1
- package/dist/m3/index.js +2 -0
- package/dist/m3/index.js.map +1 -1
- package/dist/m3/reference-checker.d.ts.map +1 -1
- package/dist/m3/serializer.d.ts.map +1 -1
- package/dist/{symbol-table.d.ts → m3/symbol-table.d.ts} +14 -14
- package/dist/m3/symbol-table.d.ts.map +1 -0
- package/dist/m3/symbol-table.js +43 -0
- package/dist/m3/symbol-table.js.map +1 -0
- package/dist/m3/types.d.ts.map +1 -1
- package/dist/references.d.ts +7 -2
- package/dist/references.d.ts.map +1 -1
- package/dist/references.js +5 -1
- package/dist/references.js.map +1 -1
- package/dist/serializer.d.ts +1 -1
- package/dist/serializer.d.ts.map +1 -1
- package/dist/serializer.js +22 -12
- package/dist/serializer.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/writing.js +1 -1
- package/package.json +31 -31
- package/src/deserializer.ts +228 -0
- package/src/dynamic-facade.ts +63 -0
- package/src/extraction.ts +31 -0
- package/src/functions.ts +28 -0
- package/src/handler.ts +57 -0
- package/src/index.ts +13 -0
- package/src/m1/reference-utils.ts +106 -0
- package/src/m3/README.md +16 -0
- package/src/m3/builtins.ts +196 -0
- package/src/m3/constraints.ts +109 -0
- package/src/m3/deserializer.ts +38 -0
- package/src/m3/facade.ts +130 -0
- package/src/m3/factory.ts +98 -0
- package/src/m3/feature-resolvers.ts +72 -0
- package/src/m3/functions.ts +379 -0
- package/src/m3/index.ts +12 -0
- package/src/m3/lioncore.ts +139 -0
- package/src/m3/reference-checker.ts +38 -0
- package/src/m3/serializer.ts +13 -0
- package/src/m3/symbol-table.ts +125 -0
- package/src/m3/types.ts +325 -0
- package/src/reading.ts +55 -0
- package/src/references.ts +39 -0
- package/src/serializer.ts +244 -0
- package/src/types.ts +11 -0
- package/src/version.ts +5 -0
- package/src/writing.ts +79 -0
- package/dist/symbol-table.d.ts.map +0 -1
- package/dist/symbol-table.js +0 -59
- package/dist/symbol-table.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"symbol-table.d.ts","sourceRoot":"","sources":["../../src/m3/symbol-table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAGlE,OAAO,EAAc,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAG1E;;;;GAIG;AACH,UAAU,WAAW;IAEjB;;OAEG;IACH,gBAAgB,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAA;IAExE;;;OAGG;IACH,cAAc,CAAC,iBAAiB,EAAE,sBAAsB,GAAG,cAAc,GAAG,SAAS,CAAA;IAErF;;;;;;OAMG;IACH,eAAe,CAAC,iBAAiB,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,sBAAsB,GAAG,OAAO,GAAG,SAAS,CAAA;CAE9H;AAUD;;;;GAIG;AACH,cAAM,oBAAqB,YAAW,WAAW;IAE7C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;gBAE1B,SAAS,EAAE,QAAQ,EAAE;IAIjC,OAAO,CAAC,QAAQ,CAAC,4BAA4B,CAAqE;IAElH,gBAAgB,GAAI,aAAa,UAAU,EAAE,SAAS,MAAM,KAAG,QAAQ,GAAG,SAAS,CAQ9E;IAGL,OAAO,CAAC,QAAQ,CAAC,wCAAwC,CAAkH;IAE3K,OAAO,CAAC,kBAAkB,CAmBrB;IAEL,cAAc,GAAI,mBAAmB,sBAAsB,KAAG,cAAc,GAAG,SAAS,CAClC;IAEtD;;;OAGG;IACH,2BAA2B,GAAI,mBAAmB,sBAAsB,KAAG,OAAO,EAAE,CACnB;IAEjE,eAAe,GAAI,uBAAuB,sBAAsB,EAAE,oBAAoB,sBAAsB,KAAG,OAAO,GAAG,SAAS,CAUjI;CAEJ;AAGD,YAAY,EACR,WAAW,EACd,CAAA;AAED,OAAO,EACH,oBAAoB,EACvB,CAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { lazyMapGet } from "@lionweb/ts-utils";
|
|
2
|
+
import { allFeaturesOf } from "./functions.js";
|
|
3
|
+
import { Classifier } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* A {@link SymbolTable} implementation that *memoises* the items it has looked up.
|
|
6
|
+
* This helps with performance, because otherwise lookup might be linear in the (max.) number of languages,
|
|
7
|
+
* entities in a language, features in classifiers — taking inheritance into account.
|
|
8
|
+
*/
|
|
9
|
+
class MemoisingSymbolTable {
|
|
10
|
+
constructor(languages) {
|
|
11
|
+
this.languageKey2version2language = {};
|
|
12
|
+
this.languageMatching = (languageKey, version) => lazyMapGet(lazyMapGet(this.languageKey2version2language, languageKey, () => ({})), version, () => this.languages.find((language) => language.key === languageKey
|
|
13
|
+
&& language.version === version));
|
|
14
|
+
this.languageKey2version2entityKey2entityInfo = {};
|
|
15
|
+
this.entityInfoMatching = (entityMetaPointer) => lazyMapGet(lazyMapGet(lazyMapGet(this.languageKey2version2entityKey2entityInfo, entityMetaPointer.language, () => ({})), entityMetaPointer.version, () => ({})), entityMetaPointer.key, () => {
|
|
16
|
+
const entity = this.languageMatching(entityMetaPointer.language, entityMetaPointer.version)
|
|
17
|
+
?.entities
|
|
18
|
+
.find((entity) => entity.key === entityMetaPointer.key);
|
|
19
|
+
return entity === undefined
|
|
20
|
+
? undefined
|
|
21
|
+
: {
|
|
22
|
+
entity,
|
|
23
|
+
allFeatures: entity instanceof Classifier ? allFeaturesOf(entity) : [], featureKey2feature: {}
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
this.entityMatching = (entityMetaPointer) => this.entityInfoMatching(entityMetaPointer)?.entity;
|
|
27
|
+
/**
|
|
28
|
+
* Looks up the {@link LanguageEntity}, as pointed to by the given {@link LionWebJsonMetaPointer},
|
|
29
|
+
* and @returns all its {@link Feature features} or an empty array if it couldn't be found.
|
|
30
|
+
*/
|
|
31
|
+
this.allFeaturesOfEntityMatching = (entityMetaPointer) => this.entityInfoMatching(entityMetaPointer)?.allFeatures ?? [];
|
|
32
|
+
this.featureMatching = (classifierMetaPointer, featureMetaPointer) => {
|
|
33
|
+
const entityInfo = this.entityInfoMatching(classifierMetaPointer);
|
|
34
|
+
if (entityInfo === undefined || !(entityInfo.entity instanceof Classifier)) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
return lazyMapGet(entityInfo.featureKey2feature, featureMetaPointer.key, () => entityInfo.allFeatures.find((feature) => feature.key === featureMetaPointer.key));
|
|
38
|
+
};
|
|
39
|
+
this.languages = languages;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export { MemoisingSymbolTable };
|
|
43
|
+
//# sourceMappingURL=symbol-table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"symbol-table.js","sourceRoot":"","sources":["../../src/m3/symbol-table.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAqC,MAAM,YAAY,CAAA;AAwC1E;;;;GAIG;AACH,MAAM,oBAAoB;IAItB,YAAY,SAAqB;QAIhB,iCAA4B,GAAmE,EAAE,CAAA;QAElH,qBAAgB,GAAG,CAAC,WAAuB,EAAE,OAAe,EAAwB,EAAE,CAClF,UAAU,CACN,UAAU,CAAC,IAAI,CAAC,4BAA4B,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EACtE,OAAO,EACP,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAChC,QAAQ,CAAC,GAAG,KAAK,WAAW;eAC5B,QAAQ,CAAC,OAAO,KAAK,OAAO,CAClC,CACJ,CAAA;QAGY,6CAAwC,GAAgH,EAAE,CAAA;QAEnK,uBAAkB,GAAG,CAAC,iBAAyC,EAA0B,EAAE,CAC/F,UAAU,CACN,UAAU,CACN,UAAU,CAAC,IAAI,CAAC,wCAAwC,EAAE,iBAAiB,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EACjG,iBAAiB,CAAC,OAAO,EACzB,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CACb,EACD,iBAAiB,CAAC,GAAG,EACrB,GAAG,EAAE;YACD,MAAM,MAAM,GAAG,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,QAAQ,EAAE,iBAAiB,CA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BAAoB,EACvB,CAAA"}
|
package/dist/m3/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/m3/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAc,MAAM,kBAAkB,CAAA;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAGlC;;;GAGG;AACH,QAAA,MAAM,mBAAmB,sBAAsB,CAAA;AAO/C,UAAU,MAAM;IACZ,IAAI,EAAE,MAAM,CAAA;CACf;AAED,QAAA,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/m3/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAc,MAAM,kBAAkB,CAAA;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAGlC;;;GAGG;AACH,QAAA,MAAM,mBAAmB,sBAAsB,CAAA;AAO/C,UAAU,MAAM;IACZ,IAAI,EAAE,MAAM,CAAA;CACf;AAED,QAAA,MAAM,QAAQ,GAAI,MAAM,MAAM,KAAG,IAAI,IAAI,MACU,CAAA;AAEnD,QAAA,MAAM,iBAAiB,EAAE,kBAAkB,CAAC,IAAI,CACU,CAAA;AAG1D,UAAU,MAAO,SAAQ,MAAM;IAC3B,GAAG,EAAE,SAAS,CAAA;CACjB;AAGD;;;;GAIG;AACH,UAAU,UAAU;IAChB,QAAQ,IAAI,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Gf,OAAO,EACH,UAAU,EACV,UAAU,EACV,OAAO,EACP,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,kBAAkB,EAClB,OAAO,EACP,SAAS,EACT,QAAQ,EACR,cAAc,EACd,IAAI,EACJ,aAAa,EACb,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,mBAAmB,EACnB,iBAAiB,EACpB,CAAA;AAED,YAAY,EACR,MAAM,EACN,UAAU,EACV,MAAM,EACN,SAAS,EACT,MAAM,EACT,CAAA"}
|
package/dist/references.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { LionWebId } from "@lionweb/json";
|
|
2
|
+
import { Node } from "./types.js";
|
|
2
3
|
/**
|
|
3
4
|
* The `unresolved` symbol indicates a reference value which hasn't been resolved yet.
|
|
4
5
|
* It differs from an unset (`undefined`) value.
|
|
@@ -9,9 +10,9 @@ export declare const unresolved: null;
|
|
|
9
10
|
*/
|
|
10
11
|
export type SingleRef<T> = typeof unresolved | T;
|
|
11
12
|
/**
|
|
12
|
-
*
|
|
13
|
+
* @return whether a given (at most) single-valued reference actually refers to something.
|
|
13
14
|
*/
|
|
14
|
-
export declare const isRef: <T>(ref?: SingleRef<T>
|
|
15
|
+
export declare const isRef: <T>(ref?: SingleRef<T>) => ref is T;
|
|
15
16
|
/**
|
|
16
17
|
* A type alias for a multi-valued reference, to make it look consistent with {@link SingleRef}.
|
|
17
18
|
*/
|
|
@@ -20,4 +21,8 @@ export type MultiRef<T> = T[];
|
|
|
20
21
|
* A type that expresses a value is either an {@link LionWebId} or a value to indicate that resolution to a node previously failed.
|
|
21
22
|
*/
|
|
22
23
|
export type IdOrUnresolved = LionWebId | typeof unresolved;
|
|
24
|
+
/**
|
|
25
|
+
* @return the serialization of the given {@link SingleRef single reference target}, as a {@link LionWebId LionWeb ID}.
|
|
26
|
+
*/
|
|
27
|
+
export declare const serializedRef: <NT extends Node>(ref: SingleRef<NT>) => LionWebId | typeof unresolved;
|
|
23
28
|
//# sourceMappingURL=references.d.ts.map
|
package/dist/references.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"references.d.ts","sourceRoot":"","sources":["../src/references.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"references.d.ts","sourceRoot":"","sources":["../src/references.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAGjC;;;GAGG;AACH,eAAO,MAAM,UAAU,MAAO,CAAA;AAE9B;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,OAAO,UAAU,GAAG,CAAC,CAAA;AAEhD;;GAEG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,EAAE,MAAM,SAAS,CAAC,CAAC,CAAC,KAAG,GAAG,IAAI,CACV,CAAA;AAE3C;;GAEG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,EAAE,CAAA;AAG7B;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,OAAO,UAAU,CAAC;AAG3D;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,EAAE,SAAS,IAAI,EAAE,KAAK,SAAS,CAAC,EAAE,CAAC,KAAG,SAAS,GAAG,OAAO,UAC3C,CAAA"}
|
package/dist/references.js
CHANGED
|
@@ -4,7 +4,11 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export const unresolved = null;
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* @return whether a given (at most) single-valued reference actually refers to something.
|
|
8
8
|
*/
|
|
9
9
|
export const isRef = (ref) => ref !== undefined && ref !== unresolved;
|
|
10
|
+
/**
|
|
11
|
+
* @return the serialization of the given {@link SingleRef single reference target}, as a {@link LionWebId LionWeb ID}.
|
|
12
|
+
*/
|
|
13
|
+
export const serializedRef = (ref) => ref === unresolved ? unresolved : ref.id;
|
|
10
14
|
//# sourceMappingURL=references.js.map
|
package/dist/references.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"references.js","sourceRoot":"","sources":["../src/references.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"references.js","sourceRoot":"","sources":["../src/references.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAA;AAO9B;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAI,GAAkB,EAAY,EAAE,CACrD,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,UAAU,CAAA;AAc3C;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAkB,GAAkB,EAAiC,EAAE,CAChG,GAAG,KAAK,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAA"}
|
package/dist/serializer.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export declare const metaPointerFor: (feature: Feature) => LionWebJsonMetaPointe
|
|
|
43
43
|
export declare const nodeSerializer: <NT extends Node>(reader: Reader<NT>, serializationOptions?: SerializationOptions) => (nodes: NT[]) => LionWebJsonChunk;
|
|
44
44
|
/**
|
|
45
45
|
* @return a {@link LionWebJsonChunk} of the given model (i.e., an array of {@link Node nodes} - the first argument) to the LionWeb serialization JSON format.
|
|
46
|
-
*
|
|
46
|
+
* *Note:* this function will be deprecated and removed later — use {@link nodeSerializer} instead.
|
|
47
47
|
*/
|
|
48
48
|
export declare const serializeNodes: <NT extends Node>(nodes: NT[], reader: Reader<NT>, propertyValueSerializerOrOptions?: PropertyValueSerializer | SerializationOptions) => LionWebJsonChunk;
|
|
49
49
|
//# sourceMappingURL=serializer.d.ts.map
|
package/dist/serializer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializer.d.ts","sourceRoot":"","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AAI,EAC1C,OAAO,EAAE,EAAE,EACX,QAAQ,MAAM,CAAC,EAAE,CAAC,EAClB,mCAAmC,uBAAuB,GAAG,oBAAoB,KAClF,gBAQS,CAAA"}
|
package/dist/serializer.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { currentSerializationFormatVersion } from "@lionweb/json";
|
|
2
|
-
import { asArray } from "@lionweb/ts-utils";
|
|
2
|
+
import { asArray, keepDefineds, lazyMapGet, uniquesAmong } from "@lionweb/ts-utils";
|
|
3
3
|
import { asIds } from "./functions.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { builtinPropertyValueSerializer } from "./m3/builtins.js";
|
|
5
|
+
import { inheritsDirectlyFrom } from "./m3/functions.js";
|
|
6
6
|
import { Containment, Enumeration, PrimitiveType, Property, Reference, simpleNameDeducer } from "./m3/types.js";
|
|
7
7
|
const isPropertyValueSerializer = (value) => typeof value === "object" && value !== null && "serializeValue" in value && typeof value.serializeValue === "function";
|
|
8
8
|
/**
|
|
@@ -20,17 +20,29 @@ export const metaPointerFor = (feature) => {
|
|
|
20
20
|
* @return a function that serializes the {@link Node nodes} passed to it.
|
|
21
21
|
*/
|
|
22
22
|
export const nodeSerializer = (reader, serializationOptions) => {
|
|
23
|
-
const propertyValueSerializer = serializationOptions?.propertyValueSerializer ?? serializationOptions?.primitiveTypeSerializer ??
|
|
23
|
+
const propertyValueSerializer = serializationOptions?.propertyValueSerializer ?? serializationOptions?.primitiveTypeSerializer ?? builtinPropertyValueSerializer;
|
|
24
24
|
const serializeEmptyFeatures = serializationOptions?.serializeEmptyFeatures ?? true;
|
|
25
|
+
const languageKey2version2classifierKey2allFeatures = {};
|
|
26
|
+
const memoisedAllFeaturesOf = (classifier) => lazyMapGet(lazyMapGet(lazyMapGet(languageKey2version2classifierKey2allFeatures, classifier.language.key, () => ({})), classifier.language.version, () => ({})), classifier.key, () => uniquesAmong(// make unique in case a feature was inherited from multiple super-classifiers
|
|
27
|
+
[...classifier.features, ...(inheritsDirectlyFrom(classifier).flatMap(memoisedAllFeaturesOf))]
|
|
28
|
+
/*
|
|
29
|
+
* [NOTE]
|
|
30
|
+
* The allFeaturesOf function uses flatMapNonCyclingFollowing which avoids that features of a super-classifier are added multiple times.
|
|
31
|
+
* Unfortunately, to make use of the memoising, we can't use flatMapNonCyclingFollowing in the same way here.
|
|
32
|
+
* So, we have to remove duplicates ourselves.
|
|
33
|
+
*/
|
|
34
|
+
));
|
|
25
35
|
return (nodes) => {
|
|
26
36
|
const serializedNodes = []; // keep nodes as much as possible "in order"
|
|
27
37
|
const ids = {}; // maintain a map to keep track of IDs of nodes that have been serialized
|
|
28
38
|
const languagesUsed = [];
|
|
39
|
+
const usedLanguageKey2Version2Boolean = {};
|
|
29
40
|
const registerLanguageUsed = (language) => {
|
|
30
|
-
|
|
41
|
+
const version2Boolean = lazyMapGet(usedLanguageKey2Version2Boolean, language.key, () => ({}));
|
|
42
|
+
if (!version2Boolean[language.version]) {
|
|
43
|
+
version2Boolean[language.version] = true;
|
|
31
44
|
languagesUsed.push(language);
|
|
32
45
|
}
|
|
33
|
-
// TODO could make this more efficient by using a hash table
|
|
34
46
|
};
|
|
35
47
|
const visit = (node, parent) => {
|
|
36
48
|
if (node.id in ids) {
|
|
@@ -50,7 +62,7 @@ export const nodeSerializer = (reader, serializationOptions) => {
|
|
|
50
62
|
};
|
|
51
63
|
serializedNodes.push(serializedNode);
|
|
52
64
|
ids[node.id] = true;
|
|
53
|
-
|
|
65
|
+
memoisedAllFeaturesOf(classifier).forEach((feature) => {
|
|
54
66
|
const value = reader.getFeatureValue(node, feature);
|
|
55
67
|
const featureLanguage = feature.classifier.language;
|
|
56
68
|
registerLanguageUsed(featureLanguage);
|
|
@@ -83,8 +95,7 @@ export const nodeSerializer = (reader, serializationOptions) => {
|
|
|
83
95
|
}
|
|
84
96
|
serializedNode.containments.push({
|
|
85
97
|
containment: featureMetaPointer,
|
|
86
|
-
children: asIds(children)
|
|
87
|
-
.filter(childId => childId !== null)
|
|
98
|
+
children: keepDefineds(asIds(children))
|
|
88
99
|
.map(childId => childId)
|
|
89
100
|
});
|
|
90
101
|
children.forEach(childOrNull => {
|
|
@@ -102,8 +113,7 @@ export const nodeSerializer = (reader, serializationOptions) => {
|
|
|
102
113
|
}
|
|
103
114
|
serializedNode.references.push({
|
|
104
115
|
reference: featureMetaPointer,
|
|
105
|
-
targets: targets
|
|
106
|
-
.filter(tOrNull => tOrNull !== null) // (skip "non-connected" targets)
|
|
116
|
+
targets: keepDefineds(targets) // (skip "non-connected" targets)
|
|
107
117
|
.map(t => t)
|
|
108
118
|
.map(t => ({
|
|
109
119
|
resolveInfo: (reader.resolveInfoFor ? reader.resolveInfoFor(t) : simpleNameDeducer(t)) ?? null,
|
|
@@ -128,7 +138,7 @@ export const nodeSerializer = (reader, serializationOptions) => {
|
|
|
128
138
|
};
|
|
129
139
|
/**
|
|
130
140
|
* @return a {@link LionWebJsonChunk} of the given model (i.e., an array of {@link Node nodes} - the first argument) to the LionWeb serialization JSON format.
|
|
131
|
-
*
|
|
141
|
+
* *Note:* this function will be deprecated and removed later — use {@link nodeSerializer} instead.
|
|
132
142
|
*/
|
|
133
143
|
export const serializeNodes = (nodes, reader, propertyValueSerializerOrOptions) => nodeSerializer(reader, isPropertyValueSerializer(propertyValueSerializerOrOptions)
|
|
134
144
|
? {
|
package/dist/serializer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializer.js","sourceRoot":"","sources":["../src/serializer.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,iCAAiC,EAKpC,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"serializer.js","sourceRoot":"","sources":["../src/serializer.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,iCAAiC,EAKpC,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,UA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B,EAAE,gCAAgC;KAC5D;IACD,CAAC,CAAC,gCAAgC,CACzC,CAAC,KAAK,CAAC,CAAA"}
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/dist/writing.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Link } from "./m3/types.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* @return a {@link SettingsUpdater} that uses the given “meta key” – which is a property/key on the {@link Feature} type –
|
|
4
4
|
* to look up what key to look a feature’s value up on a settings object.
|
|
5
|
-
*
|
|
5
|
+
* *Note:* for internal use only — use with some care!
|
|
6
6
|
*/
|
|
7
7
|
const settingsUpdater = (metaKey) => (settings, feature, value) => {
|
|
8
8
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/package.json
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
2
|
+
"name": "@lionweb/core",
|
|
3
|
+
"version": "0.7.1",
|
|
4
|
+
"description": "LionWeb core for {Java|Type}Script",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"typings": "dist/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/LionWeb-io/lionweb-typescript.git"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/LionWeb-io/lionweb-typescript/issues"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"clean": "npx rimraf dist node_modules -g lionweb-core-*.tgz",
|
|
19
|
+
"build": "tsc",
|
|
20
|
+
"lint": "eslint src",
|
|
21
|
+
"prep:pre-release": "npm run clean && npm install && npm run build",
|
|
22
|
+
"prerelease-alpha": "npm run prep:pre-release",
|
|
23
|
+
"release-alpha": "npm publish --tag alpha",
|
|
24
|
+
"prerelease-beta": "npm run prep:pre-release",
|
|
25
|
+
"release-beta": "npm publish --tag beta",
|
|
26
|
+
"prerelease": "npm run prep:pre-release",
|
|
27
|
+
"release": "npm publish"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@lionweb/json": "0.7.1",
|
|
31
|
+
"@lionweb/ts-utils": "0.7.1"
|
|
32
|
+
}
|
|
33
33
|
}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import {
|
|
2
|
+
currentSerializationFormatVersion,
|
|
3
|
+
LionWebId,
|
|
4
|
+
LionWebJsonChunk,
|
|
5
|
+
LionWebJsonNode,
|
|
6
|
+
LionWebKey
|
|
7
|
+
} from "@lionweb/json"
|
|
8
|
+
import { byIdMap, groupBy, keepDefineds } from "@lionweb/ts-utils"
|
|
9
|
+
import { Writer } from "./writing.js"
|
|
10
|
+
import { defaultSimplisticHandler, SimplisticHandler } from "./handler.js"
|
|
11
|
+
import {
|
|
12
|
+
builtinPropertyValueDeserializer,
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
14
|
+
BuiltinPropertyValueDeserializer
|
|
15
|
+
} from "./m3/builtins.js"
|
|
16
|
+
import { MemoisingSymbolTable } from "./m3/symbol-table.js"
|
|
17
|
+
import { Classifier, Containment, Enumeration, Language, PrimitiveType, Property, Reference } from "./m3/types.js"
|
|
18
|
+
import { unresolved } from "./references.js"
|
|
19
|
+
import { Node } from "./types.js"
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Interface for objects that expose a method to deserialize a property's value.
|
|
23
|
+
*/
|
|
24
|
+
export interface PropertyValueDeserializer {
|
|
25
|
+
deserializeValue(value: string | undefined, property: Property): unknown | undefined
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Misspelled alias of {@link PropertyValueDeserializer}, kept for backward compatibility, and to be deprecated and removed later.
|
|
30
|
+
*/
|
|
31
|
+
export interface PrimitiveTypeDeserializer extends PropertyValueDeserializer {}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @return a deserialization of a {@link LionWebJsonChunk}
|
|
35
|
+
*
|
|
36
|
+
* @param serializationChunk - a {@link SerializedModel model} from its LionWeb serialization JSON format
|
|
37
|
+
* @param writer - a {@link Writer} that is used to instantiate nodes and set values on them
|
|
38
|
+
* @param languages - a {@link Language language} that the serialized model is expected to conform to
|
|
39
|
+
* @param dependentNodes - a collection of nodes from dependent models against which all references in the serialized model are supposed to resolve against
|
|
40
|
+
* @param propertyValueDeserializer - a deserializer for values of properties (by default a {@link BuiltinPropertyValueDeserializer})
|
|
41
|
+
* @param problemHandler - a handler for reporting problems (by default a {@link defaultSimplisticHandler})
|
|
42
|
+
*/
|
|
43
|
+
export const deserializeSerializationChunk = <NT extends Node>(
|
|
44
|
+
serializationChunk: LionWebJsonChunk,
|
|
45
|
+
writer: Writer<NT>,
|
|
46
|
+
languages: Language[],
|
|
47
|
+
// TODO facades <--> languages, so it's weird that it looks split up like this
|
|
48
|
+
dependentNodes: Node[],
|
|
49
|
+
// TODO (#13) see if you can turn this into [nodes: Node[], writer: Writer<Node>][] after all
|
|
50
|
+
propertyValueDeserializer: PropertyValueDeserializer = builtinPropertyValueDeserializer,
|
|
51
|
+
problemHandler: SimplisticHandler = defaultSimplisticHandler
|
|
52
|
+
): NT[] => {
|
|
53
|
+
if (serializationChunk.serializationFormatVersion !== currentSerializationFormatVersion) {
|
|
54
|
+
problemHandler.reportProblem(
|
|
55
|
+
`can't deserialize from serialization format other than version "${currentSerializationFormatVersion}" - assuming that version`
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const symbolTable = new MemoisingSymbolTable(languages)
|
|
60
|
+
|
|
61
|
+
const { nodes: serializedNodes } = serializationChunk
|
|
62
|
+
|
|
63
|
+
const serializedNodeById = byIdMap(serializedNodes)
|
|
64
|
+
|
|
65
|
+
const deserializedNodeById: { [id: LionWebId]: NT } = {}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Instantiates a {@link Node} from the given {@link LionWebJsonNode},
|
|
69
|
+
* and stores it under its ID so references to it can be resolved.
|
|
70
|
+
* For every serialized node, only one instance will ever be constructed (through memoisation).
|
|
71
|
+
*/
|
|
72
|
+
const instantiateMemoised = (serNode: LionWebJsonNode, parent?: NT): NT | null => {
|
|
73
|
+
if (serNode.id in deserializedNodeById) {
|
|
74
|
+
return deserializedNodeById[serNode.id]
|
|
75
|
+
}
|
|
76
|
+
const node = instantiate(serNode, parent)
|
|
77
|
+
if (node !== null) {
|
|
78
|
+
deserializedNodeById[node.id] = node
|
|
79
|
+
}
|
|
80
|
+
return node
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
type ReferenceToInstall = [node: NT, feature: Reference, refId: LionWebId]
|
|
84
|
+
const referencesToInstall: ReferenceToInstall[] = []
|
|
85
|
+
|
|
86
|
+
const tryInstantiate = (
|
|
87
|
+
parent: NT | undefined,
|
|
88
|
+
classifier: Classifier,
|
|
89
|
+
id: LionWebId,
|
|
90
|
+
propertySettings: { [propertyKey: LionWebKey]: unknown }
|
|
91
|
+
): NT | null => {
|
|
92
|
+
try {
|
|
93
|
+
return writer.nodeFor(parent, classifier, id, propertySettings)
|
|
94
|
+
} catch (e: unknown) {
|
|
95
|
+
problemHandler.reportProblem(
|
|
96
|
+
`error occurred during instantiation of a node for classifier ${classifier.name} with meta-pointer (${classifier.language.key}, ${classifier.language.version}, ${classifier.key}); reason:`
|
|
97
|
+
)
|
|
98
|
+
problemHandler.reportProblem((e as Error).toString())
|
|
99
|
+
return null
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Instantiates a {@link Node} from its {@link LionWebJsonNode serialization}.
|
|
105
|
+
*/
|
|
106
|
+
const instantiate = (
|
|
107
|
+
{ id, classifier: classifierMetaPointer, properties, containments, references, annotations }: LionWebJsonNode,
|
|
108
|
+
parent?: NT
|
|
109
|
+
): NT | null => {
|
|
110
|
+
const classifier = symbolTable.entityMatching(classifierMetaPointer)
|
|
111
|
+
|
|
112
|
+
if (classifier === undefined || !(classifier instanceof Classifier)) {
|
|
113
|
+
problemHandler.reportProblem(
|
|
114
|
+
`can't deserialize node with id=${id}: can't find the classifier with key ${classifierMetaPointer.key} in language (${classifierMetaPointer.language}, ${classifierMetaPointer.version})`
|
|
115
|
+
)
|
|
116
|
+
return null
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const allFeatures = symbolTable.allFeaturesOfEntityMatching(classifierMetaPointer)
|
|
120
|
+
|
|
121
|
+
const propertySettings: { [propertyKey: LionWebKey]: unknown } = {}
|
|
122
|
+
|
|
123
|
+
const serializedPropertiesPerKey = properties === undefined ? {} : groupBy(properties, sp => sp.property.key) // (this assumes no duplicate keys among properties!)
|
|
124
|
+
if (properties !== undefined) {
|
|
125
|
+
allFeatures
|
|
126
|
+
.filter(feature => feature instanceof Property)
|
|
127
|
+
.map(feature => feature as Property)
|
|
128
|
+
.forEach(property => {
|
|
129
|
+
if (property.key in serializedPropertiesPerKey) {
|
|
130
|
+
const value = serializedPropertiesPerKey[property.key][0].value
|
|
131
|
+
if (property.type instanceof PrimitiveType) {
|
|
132
|
+
propertySettings[property.key] =
|
|
133
|
+
value === null ? undefined : propertyValueDeserializer.deserializeValue(value, property as Property)
|
|
134
|
+
return
|
|
135
|
+
}
|
|
136
|
+
if (property.type instanceof Enumeration) {
|
|
137
|
+
const literal = property.type.literals.find(literal => literal.key === value)
|
|
138
|
+
if (literal !== undefined) {
|
|
139
|
+
propertySettings[property.key] = writer.encodingOf(literal)
|
|
140
|
+
}
|
|
141
|
+
return
|
|
142
|
+
}
|
|
143
|
+
// (property is not handled, because neither a primitive type nor of enumeration type)
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const node = tryInstantiate(parent, classifier, id, propertySettings)
|
|
149
|
+
if (node === null) {
|
|
150
|
+
return null
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const serializedContainmentsPerKey = containments === undefined ? {} : groupBy(containments, sp => sp.containment.key) // (this assumes no duplicate keys among containments!)
|
|
154
|
+
const serializedReferencesPerKey = references === undefined ? {} : groupBy(references, sp => sp.reference.key) // (this assumes no duplicate keys among references!)
|
|
155
|
+
|
|
156
|
+
allFeatures.forEach(feature => {
|
|
157
|
+
if (feature instanceof Property && properties !== undefined && feature.key in serializedPropertiesPerKey) {
|
|
158
|
+
writer.setFeatureValue(node, feature, propertySettings[feature.key])
|
|
159
|
+
} else if (feature instanceof Containment && containments !== undefined && feature.key in serializedContainmentsPerKey) {
|
|
160
|
+
const childIds = serializedContainmentsPerKey[feature.key].flatMap(serChildren => serChildren.children) as LionWebId[]
|
|
161
|
+
if (feature.multiple) {
|
|
162
|
+
childIds.forEach(childId => {
|
|
163
|
+
if (childId in serializedNodeById) {
|
|
164
|
+
writer.setFeatureValue(node, feature, instantiateMemoised(serializedNodeById[childId], node))
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
} else {
|
|
168
|
+
if (childIds.length > 0) {
|
|
169
|
+
// just set the 1st one:
|
|
170
|
+
const firstChildId = childIds[0]
|
|
171
|
+
if (firstChildId in serializedNodeById) {
|
|
172
|
+
writer.setFeatureValue(node, feature, instantiateMemoised(serializedNodeById[firstChildId], node))
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
} else if (feature instanceof Reference && references !== undefined && feature.key in serializedReferencesPerKey) {
|
|
177
|
+
const serRefs = (serializedReferencesPerKey[feature.key] ?? []).flatMap(serReferences =>
|
|
178
|
+
serReferences.targets.map(t => t.reference)
|
|
179
|
+
)
|
|
180
|
+
referencesToInstall.push(
|
|
181
|
+
...(serRefs.filter(serRef => typeof serRef === "string") as LionWebId[]).map(
|
|
182
|
+
refId => [node, feature, refId] as ReferenceToInstall
|
|
183
|
+
)
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
node.annotations = keepDefineds(
|
|
189
|
+
annotations
|
|
190
|
+
.filter(annotationId => annotationId in serializedNodeById)
|
|
191
|
+
.map(annotationId => instantiateMemoised(serializedNodeById[annotationId]))
|
|
192
|
+
)
|
|
193
|
+
.map(annotation => annotation!)
|
|
194
|
+
|
|
195
|
+
return node
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const rootLikeNodes = keepDefineds(
|
|
199
|
+
serializedNodes
|
|
200
|
+
.filter(({ parent }) => parent === null || !(parent in serializedNodeById))
|
|
201
|
+
.map(serializedNode => instantiateMemoised(serializedNode))
|
|
202
|
+
)
|
|
203
|
+
.map(node => node!)
|
|
204
|
+
|
|
205
|
+
const dependentNodesById = byIdMap(dependentNodes)
|
|
206
|
+
|
|
207
|
+
referencesToInstall.forEach(([node, reference, refId]) => {
|
|
208
|
+
const target = deserializedNodeById[refId] ?? dependentNodesById[refId]
|
|
209
|
+
const value = (() => {
|
|
210
|
+
if (target === undefined) {
|
|
211
|
+
const metaTypeMessage = "concept" in node ? ` and (meta-)type ${node.concept}` : ""
|
|
212
|
+
problemHandler.reportProblem(
|
|
213
|
+
`couldn't resolve the target with id=${refId} of a "${reference.name}" reference on the node with id=${node.id}${metaTypeMessage}`
|
|
214
|
+
)
|
|
215
|
+
return unresolved
|
|
216
|
+
}
|
|
217
|
+
return target
|
|
218
|
+
})()
|
|
219
|
+
writer.setFeatureValue(node, reference, value)
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
return rootLikeNodes
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Alias for {@link deserializeSerializationChunk}.
|
|
227
|
+
*/
|
|
228
|
+
export const deserializeChunk = deserializeSerializationChunk
|