@lionweb/utilities 0.8.0-beta.5 → 0.8.0-beta.7
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 +1 -0
- package/dist/hashing.d.ts +1 -1
- package/dist/hashing.js +1 -1
- package/dist/m3/infer-languages.d.ts.map +1 -1
- package/dist/m3/infer-languages.js +3 -2
- package/dist/m3/infer-languages.js.map +1 -1
- package/dist/m3/ts-generation/common.d.ts.map +1 -1
- package/dist/m3/ts-generation/common.js +10 -7
- package/dist/m3/ts-generation/common.js.map +1 -1
- package/dist/m3/ts-generation/ts-types-generator.js +2 -2
- package/dist/m3/ts-generation/ts-types-generator.js.map +1 -1
- package/dist/serialization/annotation-remover.d.ts +2 -2
- package/dist/serialization/annotation-remover.js +2 -2
- package/dist/serialization/chunk.d.ts +14 -5
- package/dist/serialization/chunk.d.ts.map +1 -1
- package/dist/serialization/chunk.js +21 -11
- package/dist/serialization/chunk.js.map +1 -1
- package/package.json +6 -6
- package/src/hashing.ts +1 -1
- package/src/m3/infer-languages.ts +5 -2
- package/src/m3/ts-generation/common.ts +11 -8
- package/src/m3/ts-generation/ts-types-generator.ts +2 -2
- package/src/serialization/annotation-remover.ts +2 -2
- package/src/serialization/chunk.ts +32 -11
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
* Propagate `reference` field of `LionWebJsonReferenceTarget` type now being `null`able.
|
|
6
6
|
* Harden `asText` textualizer function against unset and unresolved references.
|
|
7
|
+
* Extend the `looksLikeSerializedLanguages`, `tryRead[All]AsLanguages`, and `combinationOf` functions with an optional `LionWebVersion` argument — see the TSDoc of these functions for the precise semantics.
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
## 0.7.2
|
package/dist/hashing.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare const hasher: (config?: StringHasherConfig) => StringHasher;
|
|
|
32
32
|
export declare const checkUniqueData: (hasher: StringHasher) => StringHasher;
|
|
33
33
|
/**
|
|
34
34
|
* Augments the given {@link StringHasher hasher} by checking
|
|
35
|
-
* whether it's been given defined (
|
|
35
|
+
* whether it's been given defined (`!== undefined`) data,
|
|
36
36
|
* throwing an error when not.
|
|
37
37
|
*/
|
|
38
38
|
export declare const checkDefinedData: (hasher: StringHasher) => StringHasher;
|
package/dist/hashing.js
CHANGED
|
@@ -43,7 +43,7 @@ export const checkUniqueData = (hasher) => {
|
|
|
43
43
|
};
|
|
44
44
|
/**
|
|
45
45
|
* Augments the given {@link StringHasher hasher} by checking
|
|
46
|
-
* whether it's been given defined (
|
|
46
|
+
* whether it's been given defined (`!== undefined`) data,
|
|
47
47
|
* throwing an error when not.
|
|
48
48
|
*/
|
|
49
49
|
export const checkDefinedData = (hasher) => (data) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"infer-languages.d.ts","sourceRoot":"","sources":["../../src/m3/infer-languages.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"infer-languages.d.ts","sourceRoot":"","sources":["../../src/m3/infer-languages.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,QAAQ,EAMX,MAAM,eAAe,CAAA;AACtB,OAAO,EAAa,gBAAgB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAUvE,eAAO,MAAM,oCAAoC,GAAI,OAAO,gBAAgB,KAAG,QAAQ,EA4GtF,CAAA;AAUD,eAAO,MAAM,wBAAwB,GAAI,KAAK,UAAU,WASvD,CAAA"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Concept, Containment, Language, lionWebVersionFrom, LionWebVersions, Property, Reference } from "@lionweb/core";
|
|
2
2
|
import { asArray, chain, concatenator, lastOf } from "@lionweb/ts-utils";
|
|
3
3
|
import { hasher } from "../hashing.js";
|
|
4
4
|
const possibleKeySeparators = ["-", "_"];
|
|
5
5
|
const id = chain(concatenator("-"), hasher());
|
|
6
6
|
const key = lastOf;
|
|
7
|
-
const { stringDataType, booleanDataType, integerDataType } = builtinPrimitives;
|
|
8
7
|
export const inferLanguagesFromSerializationChunk = (chunk) => {
|
|
8
|
+
const lionWebVersion = lionWebVersionFrom(chunk.serializationFormatVersion) ?? LionWebVersions.v2023_1;
|
|
9
|
+
const { stringDataType, booleanDataType, integerDataType } = lionWebVersion.builtinsFacade.primitiveTypes;
|
|
9
10
|
const languages = new Map();
|
|
10
11
|
const concepts = new Map();
|
|
11
12
|
const links = new Array();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"infer-languages.js","sourceRoot":"","sources":["../../src/m3/infer-languages.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,
|
|
1
|
+
{"version":3,"file":"infer-languages.js","sourceRoot":"","sources":["../../src/m3/infer-languages.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,OAAO,EACP,WAAW,EACX,QAAQ,EAER,kBAAkB,EAClB,eAAe,EACf,QAAQ,EACR,SAAS,EACZ,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAEtC,MAAM,qBAAqB,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;AAExC,MAAM,EAAE,GAAG,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAA;AAGlB,MAAM,CAAC,MAAM,oCAAoC,GAAG,CAAC,KAAuB,EAAc,EAAE;IACxF,MAAM,cAAc,GAAG,kBAAkB,CAAC,KAAK,CAAC,0BAA0B,CAAC,IAAI,eAAe,CAAC,OAAO,CAAA;IACtG,MAAM,EAAE,cAAc,EAAE,eAAe,EAAE,eAAe,EAAE,GAAG,cAAc,CAAC,cAAc,CAAC,cAAc,CAAA;IA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K,KAAK,MAAM,IAAI,KAAK,KAAK,OAAO,CAAA;AAE1E,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/m3/ts-generation/common.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/m3/ts-generation/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,QAAQ,EAIR,cAAc,EAGd,SAAS,EACZ,MAAM,eAAe,CAAA;AAKtB,eAAO,MAAM,SAAS,GAAI,UAAU,SAAS,CAAC,QAAQ,CAAC,KAAG,MAezD,CAAA;AAED,eAAO,MAAM,QAAQ,GAAI,QAAQ,cAAc,KAAG,OAGS,CAAA;AAG3D,eAAO,MAAM,kBAAkB,GAAI,QAAQ,cAAc,KAAG,OAW3D,CAAA"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { Annotation,
|
|
1
|
+
import { Annotation, Concept, Enumeration, Interface, isRef, LionWebVersions, PrimitiveType } from "@lionweb/core";
|
|
2
|
+
const { builtinsFacade } = LionWebVersions.v2023_1;
|
|
2
3
|
export const tsTypeFor = (datatype) => {
|
|
3
4
|
if (datatype instanceof PrimitiveType) {
|
|
4
|
-
switch (datatype) {
|
|
5
|
-
case
|
|
6
|
-
case
|
|
7
|
-
case
|
|
8
|
-
case
|
|
5
|
+
switch (datatype.key) {
|
|
6
|
+
case builtinsFacade.primitiveTypes.booleanDataType.key: return `boolean`;
|
|
7
|
+
case builtinsFacade.primitiveTypes.stringDataType.key: return `string`;
|
|
8
|
+
case builtinsFacade.primitiveTypes.integerDataType.key: return `number`;
|
|
9
|
+
case builtinsFacade.primitiveTypes.jsonDataType.key: return `unknown`;
|
|
9
10
|
default:
|
|
10
11
|
return `string`;
|
|
11
12
|
}
|
|
@@ -15,7 +16,9 @@ export const tsTypeFor = (datatype) => {
|
|
|
15
16
|
}
|
|
16
17
|
return `unknown /* [ERROR] can't compute a TS type for this datatype: ${datatype} */`;
|
|
17
18
|
};
|
|
18
|
-
export const isINamed = (entity) => entity
|
|
19
|
+
export const isINamed = (entity) => entity instanceof Interface
|
|
20
|
+
&& entity.language.key === builtinsFacade.classifiers.inamed.language.key
|
|
21
|
+
&& entity.key === builtinsFacade.classifiers.inamed.key;
|
|
19
22
|
export const usesINamedDirectly = (entity) => {
|
|
20
23
|
if (entity instanceof Annotation) {
|
|
21
24
|
return entity.implements.filter(isRef).some(isINamed);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/m3/ts-generation/common.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,UAAU,EACV,
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/m3/ts-generation/common.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,UAAU,EACV,OAAO,EAEP,WAAW,EACX,SAAS,EACT,KAAK,EAEL,eAAe,EACf,aAAa,EAEhB,MAAM,eAAe,CAAA;AAGtB,MAAM,EAAE,cAAc,EAAE,GAAG,eAAe,CAAC,OAAO,CAAA;AAElD,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,QAA6B,EAAU,EAAE;IAC/D,IAAI,QAAQ,YAAY,aAAa,EAAE,CAAC;QACpC,QAAQ,QAAQ,CAAC,GAAG,EAAE,CAAC;YACnB,KAAK,cAAc,CAAC,cAAc,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,OAAO,SAAS,CAAA;YACxE,KAAK,cAAc,CAAC,cAAc,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,OAAO,QAAQ,CAAA;YACtE,KAAK,cAAc,CAAC,cAAc,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,OAAO,QAAQ,CAAA;YACvE,KAAK,cAAc,CAAC,cAAc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{ allFeaturesOf, Annotation, Classifier, Concept, conceptsOf, Enumeration, inheritsDirectlyFrom, Interface, isConcrete, isRef, isUnresolvedReference, Link, LionWebVersions, nameOf, nameSorted, PrimitiveType, Property } from "@lionweb/core";
|
|
2
2
|
import { indent } from "@lionweb/textgen-utils";
|
|
3
3
|
import { groupBy, mapValues, uniquesAmong } from "@lionweb/ts-utils";
|
|
4
4
|
import { asString, when } from "littoral-templates";
|
|
@@ -126,7 +126,7 @@ export const tsTypeDefsForLanguage = (language, ...generationOptions) => {
|
|
|
126
126
|
const generatedDependencies = uniquesAmong(language.entities
|
|
127
127
|
.filter((entity) => entity instanceof Classifier)
|
|
128
128
|
.flatMap((entity) => dependenciesOfClassifier(entity)))
|
|
129
|
-
.filter((classifier) => classifier.language !== language && classifier.language !==
|
|
129
|
+
.filter((classifier) => classifier.language !== language && classifier.language.key !== LionWebVersions.v2023_1.builtinsFacade.language.key);
|
|
130
130
|
const importsPerPackage = groupBy(generatedDependencies, ({ language }) => language.name);
|
|
131
131
|
const concreteClassifiers = language.entities.filter(isConcrete);
|
|
132
132
|
return asString([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ts-types-generator.js","sourceRoot":"","sources":["../../../src/m3/ts-generation/ts-types-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,aAAa,EACb,UAAU,EACV,UAAU,EACV,OAAO,EACP,UAAU,EAGV,WAAW,EAEX,oBAAoB,EACpB,SAAS,EACT,UAAU,EACV,KAAK,EACL,qBAAqB,EAGrB,IAAI,EACJ,
|
|
1
|
+
{"version":3,"file":"ts-types-generator.js","sourceRoot":"","sources":["../../../src/m3/ts-generation/ts-types-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,aAAa,EACb,UAAU,EACV,UAAU,EACV,OAAO,EACP,UAAU,EAGV,WAAW,EAEX,oBAAoB,EACpB,SAAS,EACT,UAAU,EACV,KAAK,EACL,qBAAqB,EAGrB,IAAI,EACJ,eAAe,EACf,MAAM,E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,MAAM,GAAG,CAAC,CAAC,CAAC;YACjC,EAAE;YACF,6DAA6D,QAAQ,CAAC,IAAI,MAAM;YAChF,uBAAuB,UAAU,CAAC,mBAAmB,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG;YACjF,EAAE;SACL,CAAC;KACL,CACJ,CAAA;AAEL,CAAC,CAAA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { LionWebJsonChunk, LionWebJsonNode } from "@lionweb/json";
|
|
2
2
|
/**
|
|
3
3
|
* Removes all annotations from the given {@link LionWebJsonChunk}, i.e.:
|
|
4
|
-
* * all annotations on nodes in the form of the
|
|
5
|
-
* * all nodes that can be identified as instances of an {@link Annotation} by being referred to from
|
|
4
|
+
* * all annotations on nodes in the form of the `annotations` property,
|
|
5
|
+
* * all nodes that can be identified as instances of an {@link Annotation} by being referred to from `annotations`.
|
|
6
6
|
* It also removes all descendants of all annotations (insofar present in the given chunk).
|
|
7
7
|
* @param serializationChunk - The {@link LionWebJsonChunk}
|
|
8
8
|
*/
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { byIdMap } from "@lionweb/ts-utils";
|
|
2
2
|
/**
|
|
3
3
|
* Removes all annotations from the given {@link LionWebJsonChunk}, i.e.:
|
|
4
|
-
* * all annotations on nodes in the form of the
|
|
5
|
-
* * all nodes that can be identified as instances of an {@link Annotation} by being referred to from
|
|
4
|
+
* * all annotations on nodes in the form of the `annotations` property,
|
|
5
|
+
* * all nodes that can be identified as instances of an {@link Annotation} by being referred to from `annotations`.
|
|
6
6
|
* It also removes all descendants of all annotations (insofar present in the given chunk).
|
|
7
7
|
* @param serializationChunk - The {@link LionWebJsonChunk}
|
|
8
8
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Language } from "@lionweb/core";
|
|
1
|
+
import { Language, LionWebVersion } from "@lionweb/core";
|
|
2
2
|
import { LionWebJsonChunk } from "@lionweb/json";
|
|
3
3
|
/**
|
|
4
4
|
* Reads the file at the given path as a {@link LionWebJsonChunk serialization chunk}.
|
|
@@ -8,21 +8,30 @@ import { LionWebJsonChunk } from "@lionweb/json";
|
|
|
8
8
|
export declare const readSerializationChunk: (path: string) => Promise<LionWebJsonChunk>;
|
|
9
9
|
/**
|
|
10
10
|
* @return whether the given JSON looks like the serialization of languages.
|
|
11
|
+
* @param lionWebVersion The LionWeb version that the given JSON should adhere to.
|
|
12
|
+
* If not given, then the chunk should adhere to any of the {@link LionWebVersions specified LionWeb versions}.
|
|
11
13
|
*/
|
|
12
|
-
export declare const looksLikeSerializedLanguages: (json: unknown) => boolean;
|
|
14
|
+
export declare const looksLikeSerializedLanguages: (json: unknown, lionWebVersion?: LionWebVersion) => boolean;
|
|
13
15
|
/**
|
|
14
16
|
* Tries to read the given path as a JSON file containing the serialization of languages,
|
|
15
17
|
* and attempts to deserialize the serialization chunk when it is.
|
|
16
18
|
* If any of that fails, return an empty list.
|
|
19
|
+
* @param lionWebVersion The LionWeb version that the given JSON should adhere to.
|
|
20
|
+
* If not given, then the chunk should adhere to any of the {@link LionWebVersions specified LionWeb versions}.
|
|
17
21
|
*/
|
|
18
|
-
export declare const tryReadAsLanguages: (path: string) => Promise<Language[]>;
|
|
22
|
+
export declare const tryReadAsLanguages: (path: string, lionWebVersion?: LionWebVersion) => Promise<Language[]>;
|
|
19
23
|
/**
|
|
20
24
|
* @return the combination of the given {@link LionWebJsonChunk serialization chunks} into one.
|
|
25
|
+
* @param lionWebVersion The {@link LionWebVersion} to emit the combined serialization chunk with.
|
|
26
|
+
* If none is given, the version of the *first* serialization chunk is used.
|
|
27
|
+
* If no chunks are given, the {@link LionWebVersions.v2023_1} is used.
|
|
21
28
|
*/
|
|
22
|
-
export declare const combinationOf: (serializationChunks: LionWebJsonChunk[]) => LionWebJsonChunk;
|
|
29
|
+
export declare const combinationOf: (serializationChunks: LionWebJsonChunk[], lionWebVersion?: LionWebVersion) => LionWebJsonChunk;
|
|
23
30
|
/**
|
|
24
31
|
* Tries to read all the given paths as JSON serialization chunks that are serializations of languages,
|
|
25
32
|
* and attempts to combine those chunks into one chunk, and deserializes that.
|
|
33
|
+
* @param lionWebVersion The LionWeb version that the given JSON should adhere to.
|
|
34
|
+
* If not given, then the chunk should adhere to any of the {@link LionWebVersions specified LionWeb versions}.
|
|
26
35
|
*/
|
|
27
|
-
export declare const tryReadAllAsLanguages: (paths: string[]) => Promise<Language[]>;
|
|
36
|
+
export declare const tryReadAllAsLanguages: (paths: string[], lionWebVersion?: LionWebVersion) => Promise<Language[]>;
|
|
28
37
|
//# sourceMappingURL=chunk.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk.d.ts","sourceRoot":"","sources":["../../src/serialization/chunk.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"chunk.d.ts","sourceRoot":"","sources":["../../src/serialization/chunk.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,QAAQ,EAER,cAAc,EAEjB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,gBAAgB,EAA2B,MAAM,eAAe,CAAA;AAIzE;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GAAU,MAAM,MAAM,8BAOxD,CAAA;AAOD;;;;GAIG;AACH,eAAO,MAAM,4BAA4B,GAAI,MAAM,OAAO,EAAE,iBAAiB,cAAc,KAAG,OAQI,CAAA;AAGlG;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAAU,MAAM,MAAM,EAAE,iBAAiB,cAAc,KAAG,OAAO,CAAC,QAAQ,EAAE,CAa1G,CAAA;AAiBD;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GAAI,qBAAqB,gBAAgB,EAAE,EAAE,iBAAiB,cAAc,KAAG,gBAOnG,CAAA;AAGN;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GAAU,OAAO,MAAM,EAAE,EAAE,iBAAiB,cAAc,KAAG,OAAO,CAAC,QAAQ,EAAE,CAkBhH,CAAA"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { deserializeLanguages, lioncoreKey } from "@lionweb/core";
|
|
2
|
-
import { currentSerializationFormatVersion } from "@lionweb/json";
|
|
1
|
+
import { allLionWebVersions, deserializeLanguages, lioncoreKey, LionWebVersions } from "@lionweb/core";
|
|
3
2
|
import { readFileAsJson } from "../utils/json.js";
|
|
4
3
|
/**
|
|
5
4
|
* Reads the file at the given path as a {@link LionWebJsonChunk serialization chunk}.
|
|
@@ -19,9 +18,12 @@ export const readSerializationChunk = async (path) => {
|
|
|
19
18
|
const isRecord = (json) => typeof json === "object" && !Array.isArray(json);
|
|
20
19
|
/**
|
|
21
20
|
* @return whether the given JSON looks like the serialization of languages.
|
|
21
|
+
* @param lionWebVersion The LionWeb version that the given JSON should adhere to.
|
|
22
|
+
* If not given, then the chunk should adhere to any of the {@link LionWebVersions specified LionWeb versions}.
|
|
22
23
|
*/
|
|
23
|
-
export const looksLikeSerializedLanguages = (json) => isRecord(json)
|
|
24
|
-
&&
|
|
24
|
+
export const looksLikeSerializedLanguages = (json, lionWebVersion) => isRecord(json)
|
|
25
|
+
&& ((lionWebVersion === undefined ? allLionWebVersions : [lionWebVersion])
|
|
26
|
+
.some((version) => json["serializationFormatVersion"] === version.serializationFormatVersion))
|
|
25
27
|
&& "languages" in json
|
|
26
28
|
&& Array.isArray(json["languages"])
|
|
27
29
|
&& json["languages"].some((language) => isRecord(language) && language["key"] === lioncoreKey);
|
|
@@ -29,10 +31,12 @@ export const looksLikeSerializedLanguages = (json) => isRecord(json)
|
|
|
29
31
|
* Tries to read the given path as a JSON file containing the serialization of languages,
|
|
30
32
|
* and attempts to deserialize the serialization chunk when it is.
|
|
31
33
|
* If any of that fails, return an empty list.
|
|
34
|
+
* @param lionWebVersion The LionWeb version that the given JSON should adhere to.
|
|
35
|
+
* If not given, then the chunk should adhere to any of the {@link LionWebVersions specified LionWeb versions}.
|
|
32
36
|
*/
|
|
33
|
-
export const tryReadAsLanguages = async (path) => {
|
|
37
|
+
export const tryReadAsLanguages = async (path, lionWebVersion) => {
|
|
34
38
|
const serializationChunk = await readSerializationChunk(path);
|
|
35
|
-
if (!looksLikeSerializedLanguages(serializationChunk)) {
|
|
39
|
+
if (!looksLikeSerializedLanguages(serializationChunk, lionWebVersion)) {
|
|
36
40
|
console.error(`${path} is not a valid JSON serialization chunk of LionCore languages`);
|
|
37
41
|
return [];
|
|
38
42
|
}
|
|
@@ -52,20 +56,26 @@ const flatMapDistinct = (tss, equalFunc) => tss.reduce((acc, ts) => [
|
|
|
52
56
|
const areEqual = (left, right) => left.key === right.key && left.version === right.version;
|
|
53
57
|
/**
|
|
54
58
|
* @return the combination of the given {@link LionWebJsonChunk serialization chunks} into one.
|
|
59
|
+
* @param lionWebVersion The {@link LionWebVersion} to emit the combined serialization chunk with.
|
|
60
|
+
* If none is given, the version of the *first* serialization chunk is used.
|
|
61
|
+
* If no chunks are given, the {@link LionWebVersions.v2023_1} is used.
|
|
55
62
|
*/
|
|
56
|
-
export const combinationOf = (serializationChunks) => ({
|
|
57
|
-
serializationFormatVersion:
|
|
63
|
+
export const combinationOf = (serializationChunks, lionWebVersion) => ({
|
|
64
|
+
serializationFormatVersion: lionWebVersion?.serializationFormatVersion
|
|
65
|
+
?? (serializationChunks.length > 0 ? serializationChunks[0] : LionWebVersions.v2023_1).serializationFormatVersion,
|
|
58
66
|
languages: flatMapDistinct(serializationChunks.map(({ languages }) => languages), areEqual),
|
|
59
67
|
nodes: serializationChunks.flatMap(({ nodes }) => nodes)
|
|
60
68
|
});
|
|
61
69
|
/**
|
|
62
70
|
* Tries to read all the given paths as JSON serialization chunks that are serializations of languages,
|
|
63
71
|
* and attempts to combine those chunks into one chunk, and deserializes that.
|
|
72
|
+
* @param lionWebVersion The LionWeb version that the given JSON should adhere to.
|
|
73
|
+
* If not given, then the chunk should adhere to any of the {@link LionWebVersions specified LionWeb versions}.
|
|
64
74
|
*/
|
|
65
|
-
export const tryReadAllAsLanguages = async (paths) => {
|
|
75
|
+
export const tryReadAllAsLanguages = async (paths, lionWebVersion) => {
|
|
66
76
|
const serializationChunks = (await Promise.all(paths.map(readSerializationChunk)))
|
|
67
77
|
.filter((serializationChunk, index) => {
|
|
68
|
-
const ok = looksLikeSerializedLanguages(serializationChunk);
|
|
78
|
+
const ok = looksLikeSerializedLanguages(serializationChunk, lionWebVersion);
|
|
69
79
|
if (!ok) {
|
|
70
80
|
const path = paths[index];
|
|
71
81
|
console.error(`${path} is not a valid JSON serialization chunk of LionCore languages`);
|
|
@@ -73,7 +83,7 @@ export const tryReadAllAsLanguages = async (paths) => {
|
|
|
73
83
|
return ok;
|
|
74
84
|
});
|
|
75
85
|
try {
|
|
76
|
-
return deserializeLanguages(combinationOf(serializationChunks));
|
|
86
|
+
return deserializeLanguages(combinationOf(serializationChunks, lionWebVersion));
|
|
77
87
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
78
88
|
}
|
|
79
89
|
catch (e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk.js","sourceRoot":"","sources":["../../src/serialization/chunk.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"chunk.js","sourceRoot":"","sources":["../../src/serialization/chunk.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,kBAAkB,EAClB,oBAAoB,EAEpB,WAAW,EAEX,eAAe,EAClB,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAGjD;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,EAAE,IAAY,EAAE,EAAE;IACzD,IAAI,CAAC;QACD,OAAO,cAAc,CAAC,IAAI,CAAqB,CAAA;IACnD,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,2BAA2B,CAAC,CAAA;QACjD,MAAM,CAAC,CAAA;IACX,CAAC;A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KAAK,EAAE,KAAe,EAAE,cAA+B,EAAuB,EAAE;IACjH,MAAM,mBAAmB,GACrB,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC,CAAC;SACrD,MAAM,CAAC,CAAC,kBAAkB,EAAE,KAAK,EAAE,EAAE;QAClC,MAAM,EAAE,GAAG,4BAA4B,CAAC,kBAAkB,EAAE,cAAc,CAAC,CAAA;QAC3E,IAAI,CAAC,EAAE,EAAE,CAAC;YACN,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAA;YACzB,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,gEAAgE,CAAC,CAAA;QAC1F,CAAC;QACD,OAAO,EAAE,CAAA;IACb,CAAC,CAAC,CAAA;IACN,IAAI,CAAC;QACD,OAAO,oBAAoB,CAAC,aAAa,CAAC,mBAAmB,EAAE,cAAc,CAAC,CAAC,CAAA;QACvF,8DAA8D;IAC1D,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QACd,OAAO,CAAC,KAAK,CAAC,iFAAiF,CAAC,CAAC,OAAO,EAAE,CAAC,CAAA;QAC3G,OAAO,EAAE,CAAA;IACb,CAAC;AACL,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lionweb/utilities",
|
|
3
|
-
"version": "0.8.0-beta.
|
|
3
|
+
"version": "0.8.0-beta.7",
|
|
4
4
|
"description": "LionWeb utilities",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
"url": "https://github.com/LionWeb-io/lionweb-typescript/issues"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@lionweb/core": "0.8.0-beta.
|
|
19
|
-
"@lionweb/json": "0.8.0-beta.
|
|
20
|
-
"@lionweb/textgen-utils": "0.8.0-beta.
|
|
21
|
-
"@lionweb/ts-utils": "0.8.0-beta.
|
|
18
|
+
"@lionweb/core": "0.8.0-beta.7",
|
|
19
|
+
"@lionweb/json": "0.8.0-beta.7",
|
|
20
|
+
"@lionweb/textgen-utils": "0.8.0-beta.7",
|
|
21
|
+
"@lionweb/ts-utils": "0.8.0-beta.7",
|
|
22
22
|
"littoral-templates": "0.5.1",
|
|
23
|
-
"nanoid": "5.1.
|
|
23
|
+
"nanoid": "5.1.6"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"clean": "npx rimraf dist node_modules -g lionweb-utilities-*.tgz",
|
package/src/hashing.ts
CHANGED
|
@@ -71,7 +71,7 @@ export const checkUniqueData = (hasher: StringHasher): StringHasher => {
|
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
73
|
* Augments the given {@link StringHasher hasher} by checking
|
|
74
|
-
* whether it's been given defined (
|
|
74
|
+
* whether it's been given defined (`!== undefined`) data,
|
|
75
75
|
* throwing an error when not.
|
|
76
76
|
*/
|
|
77
77
|
export const checkDefinedData = (hasher: StringHasher): StringHasher =>
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
builtinPrimitives,
|
|
3
2
|
Concept,
|
|
4
3
|
Containment,
|
|
5
4
|
Language,
|
|
6
5
|
Link,
|
|
6
|
+
lionWebVersionFrom,
|
|
7
|
+
LionWebVersions,
|
|
7
8
|
Property,
|
|
8
9
|
Reference
|
|
9
10
|
} from "@lionweb/core"
|
|
@@ -16,9 +17,11 @@ const possibleKeySeparators = ["-", "_"]
|
|
|
16
17
|
const id = chain(concatenator("-"), hasher())
|
|
17
18
|
const key = lastOf
|
|
18
19
|
|
|
19
|
-
const { stringDataType, booleanDataType, integerDataType } = builtinPrimitives
|
|
20
20
|
|
|
21
21
|
export const inferLanguagesFromSerializationChunk = (chunk: LionWebJsonChunk): Language[] => {
|
|
22
|
+
const lionWebVersion = lionWebVersionFrom(chunk.serializationFormatVersion) ?? LionWebVersions.v2023_1
|
|
23
|
+
const { stringDataType, booleanDataType, integerDataType } = lionWebVersion.builtinsFacade.primitiveTypes
|
|
24
|
+
|
|
22
25
|
const languages = new Map<string, Language>()
|
|
23
26
|
const concepts = new Map<string, Concept>()
|
|
24
27
|
const links = new Array<{ link: Link; conceptId: LionWebId }>()
|
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Annotation,
|
|
3
|
-
builtinClassifiers,
|
|
4
|
-
builtinPrimitives,
|
|
5
3
|
Concept,
|
|
6
4
|
Datatype,
|
|
7
5
|
Enumeration,
|
|
8
6
|
Interface,
|
|
9
7
|
isRef,
|
|
10
8
|
LanguageEntity,
|
|
9
|
+
LionWebVersions,
|
|
11
10
|
PrimitiveType,
|
|
12
11
|
SingleRef
|
|
13
12
|
} from "@lionweb/core"
|
|
14
13
|
|
|
15
14
|
|
|
15
|
+
const { builtinsFacade } = LionWebVersions.v2023_1
|
|
16
|
+
|
|
16
17
|
export const tsTypeFor = (datatype: SingleRef<Datatype>): string => {
|
|
17
18
|
if (datatype instanceof PrimitiveType) {
|
|
18
|
-
switch (datatype) {
|
|
19
|
-
case
|
|
20
|
-
case
|
|
21
|
-
case
|
|
22
|
-
case
|
|
19
|
+
switch (datatype.key) {
|
|
20
|
+
case builtinsFacade.primitiveTypes.booleanDataType.key: return `boolean`
|
|
21
|
+
case builtinsFacade.primitiveTypes.stringDataType.key: return `string`
|
|
22
|
+
case builtinsFacade.primitiveTypes.integerDataType.key: return `number`
|
|
23
|
+
case builtinsFacade.primitiveTypes.jsonDataType.key: return `unknown`
|
|
23
24
|
default:
|
|
24
25
|
return `string`
|
|
25
26
|
}
|
|
@@ -31,7 +32,9 @@ export const tsTypeFor = (datatype: SingleRef<Datatype>): string => {
|
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
export const isINamed = (entity: LanguageEntity): boolean =>
|
|
34
|
-
|
|
35
|
+
entity instanceof Interface
|
|
36
|
+
&& entity.language.key === builtinsFacade.classifiers.inamed.language.key
|
|
37
|
+
&& entity.key === builtinsFacade.classifiers.inamed.key
|
|
35
38
|
|
|
36
39
|
|
|
37
40
|
export const usesINamedDirectly = (entity: LanguageEntity): boolean => {
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
Language,
|
|
17
17
|
LanguageEntity,
|
|
18
18
|
Link,
|
|
19
|
-
|
|
19
|
+
LionWebVersions,
|
|
20
20
|
nameOf,
|
|
21
21
|
nameSorted,
|
|
22
22
|
PrimitiveType,
|
|
@@ -188,7 +188,7 @@ export const tsTypeDefsForLanguage = (language: Language, ...generationOptions:
|
|
|
188
188
|
.filter((entity) => entity instanceof Classifier)
|
|
189
189
|
.flatMap((entity) => dependenciesOfClassifier(entity as Classifier))
|
|
190
190
|
)
|
|
191
|
-
.filter((classifier) => classifier.language !== language && classifier.language !==
|
|
191
|
+
.filter((classifier) => classifier.language !== language && classifier.language.key !== LionWebVersions.v2023_1.builtinsFacade.language.key)
|
|
192
192
|
const importsPerPackage = groupBy(
|
|
193
193
|
generatedDependencies,
|
|
194
194
|
({language}) => language.name
|
|
@@ -7,8 +7,8 @@ import { byIdMap } from "@lionweb/ts-utils"
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Removes all annotations from the given {@link LionWebJsonChunk}, i.e.:
|
|
10
|
-
* * all annotations on nodes in the form of the
|
|
11
|
-
* * all nodes that can be identified as instances of an {@link Annotation} by being referred to from
|
|
10
|
+
* * all annotations on nodes in the form of the `annotations` property,
|
|
11
|
+
* * all nodes that can be identified as instances of an {@link Annotation} by being referred to from `annotations`.
|
|
12
12
|
* It also removes all descendants of all annotations (insofar present in the given chunk).
|
|
13
13
|
* @param serializationChunk - The {@link LionWebJsonChunk}
|
|
14
14
|
*/
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
allLionWebVersions,
|
|
3
|
+
deserializeLanguages,
|
|
4
|
+
Language,
|
|
5
|
+
lioncoreKey,
|
|
6
|
+
LionWebVersion,
|
|
7
|
+
LionWebVersions
|
|
8
|
+
} from "@lionweb/core"
|
|
9
|
+
import { LionWebJsonChunk, LionWebJsonUsedLanguage } from "@lionweb/json"
|
|
3
10
|
import { readFileAsJson } from "../utils/json.js"
|
|
4
11
|
|
|
5
12
|
|
|
@@ -24,10 +31,15 @@ const isRecord = (json: unknown): json is Record<string, unknown> =>
|
|
|
24
31
|
|
|
25
32
|
/**
|
|
26
33
|
* @return whether the given JSON looks like the serialization of languages.
|
|
34
|
+
* @param lionWebVersion The LionWeb version that the given JSON should adhere to.
|
|
35
|
+
* If not given, then the chunk should adhere to any of the {@link LionWebVersions specified LionWeb versions}.
|
|
27
36
|
*/
|
|
28
|
-
export const looksLikeSerializedLanguages = (json: unknown): boolean =>
|
|
37
|
+
export const looksLikeSerializedLanguages = (json: unknown, lionWebVersion?: LionWebVersion): boolean =>
|
|
29
38
|
isRecord(json)
|
|
30
|
-
&&
|
|
39
|
+
&& (
|
|
40
|
+
(lionWebVersion === undefined ? allLionWebVersions : [lionWebVersion])
|
|
41
|
+
.some((version) => json["serializationFormatVersion"] === version.serializationFormatVersion)
|
|
42
|
+
)
|
|
31
43
|
&& "languages" in json
|
|
32
44
|
&& Array.isArray(json["languages"])
|
|
33
45
|
&& json["languages"].some((language) => isRecord(language) && language["key"] === lioncoreKey)
|
|
@@ -37,10 +49,12 @@ export const looksLikeSerializedLanguages = (json: unknown): boolean =>
|
|
|
37
49
|
* Tries to read the given path as a JSON file containing the serialization of languages,
|
|
38
50
|
* and attempts to deserialize the serialization chunk when it is.
|
|
39
51
|
* If any of that fails, return an empty list.
|
|
52
|
+
* @param lionWebVersion The LionWeb version that the given JSON should adhere to.
|
|
53
|
+
* If not given, then the chunk should adhere to any of the {@link LionWebVersions specified LionWeb versions}.
|
|
40
54
|
*/
|
|
41
|
-
export const tryReadAsLanguages = async (path: string): Promise<Language[]> => {
|
|
55
|
+
export const tryReadAsLanguages = async (path: string, lionWebVersion?: LionWebVersion): Promise<Language[]> => {
|
|
42
56
|
const serializationChunk = await readSerializationChunk(path)
|
|
43
|
-
if (!looksLikeSerializedLanguages(serializationChunk)) {
|
|
57
|
+
if (!looksLikeSerializedLanguages(serializationChunk, lionWebVersion)) {
|
|
44
58
|
console.error(`${path} is not a valid JSON serialization chunk of LionCore languages`)
|
|
45
59
|
return []
|
|
46
60
|
}
|
|
@@ -70,10 +84,15 @@ const areEqual = (left: LionWebJsonUsedLanguage, right: LionWebJsonUsedLanguage)
|
|
|
70
84
|
|
|
71
85
|
/**
|
|
72
86
|
* @return the combination of the given {@link LionWebJsonChunk serialization chunks} into one.
|
|
87
|
+
* @param lionWebVersion The {@link LionWebVersion} to emit the combined serialization chunk with.
|
|
88
|
+
* If none is given, the version of the *first* serialization chunk is used.
|
|
89
|
+
* If no chunks are given, the {@link LionWebVersions.v2023_1} is used.
|
|
73
90
|
*/
|
|
74
|
-
export const combinationOf = (serializationChunks: LionWebJsonChunk[]): LionWebJsonChunk =>
|
|
91
|
+
export const combinationOf = (serializationChunks: LionWebJsonChunk[], lionWebVersion?: LionWebVersion): LionWebJsonChunk =>
|
|
75
92
|
({
|
|
76
|
-
serializationFormatVersion:
|
|
93
|
+
serializationFormatVersion:
|
|
94
|
+
lionWebVersion?.serializationFormatVersion
|
|
95
|
+
?? (serializationChunks.length > 0 ? serializationChunks[0] : LionWebVersions.v2023_1).serializationFormatVersion,
|
|
77
96
|
languages: flatMapDistinct(serializationChunks.map(({languages}) => languages), areEqual),
|
|
78
97
|
nodes: serializationChunks.flatMap(({nodes}) => nodes)
|
|
79
98
|
})
|
|
@@ -82,12 +101,14 @@ export const combinationOf = (serializationChunks: LionWebJsonChunk[]): LionWebJ
|
|
|
82
101
|
/**
|
|
83
102
|
* Tries to read all the given paths as JSON serialization chunks that are serializations of languages,
|
|
84
103
|
* and attempts to combine those chunks into one chunk, and deserializes that.
|
|
104
|
+
* @param lionWebVersion The LionWeb version that the given JSON should adhere to.
|
|
105
|
+
* If not given, then the chunk should adhere to any of the {@link LionWebVersions specified LionWeb versions}.
|
|
85
106
|
*/
|
|
86
|
-
export const tryReadAllAsLanguages = async (paths: string[]): Promise<Language[]> => {
|
|
107
|
+
export const tryReadAllAsLanguages = async (paths: string[], lionWebVersion?: LionWebVersion): Promise<Language[]> => {
|
|
87
108
|
const serializationChunks =
|
|
88
109
|
(await Promise.all(paths.map(readSerializationChunk)))
|
|
89
110
|
.filter((serializationChunk, index) => {
|
|
90
|
-
const ok = looksLikeSerializedLanguages(serializationChunk)
|
|
111
|
+
const ok = looksLikeSerializedLanguages(serializationChunk, lionWebVersion)
|
|
91
112
|
if (!ok) {
|
|
92
113
|
const path = paths[index]
|
|
93
114
|
console.error(`${path} is not a valid JSON serialization chunk of LionCore languages`)
|
|
@@ -95,7 +116,7 @@ export const tryReadAllAsLanguages = async (paths: string[]): Promise<Language[]
|
|
|
95
116
|
return ok
|
|
96
117
|
})
|
|
97
118
|
try {
|
|
98
|
-
return deserializeLanguages(combinationOf(serializationChunks))
|
|
119
|
+
return deserializeLanguages(combinationOf(serializationChunks, lionWebVersion))
|
|
99
120
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
100
121
|
} catch (e: any) {
|
|
101
122
|
console.error(`couldn't deserialize combined JSON serialization chunk of LionCore languages: ${e.message}`)
|