@lionweb/utilities 0.10.0-alpha.1 → 0.10.0-alpha.3
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 +3 -0
- package/dist/m3/textualizer.d.ts.map +1 -1
- package/dist/m3/textualizer.js +2 -2
- package/dist/m3/textualizer.js.map +1 -1
- package/dist/m3/ts-generation/common.js +1 -1
- package/dist/m3/ts-generation/common.js.map +1 -1
- package/dist/m3/ts-generation/ts-types-generator.d.ts.map +1 -1
- package/dist/m3/ts-generation/ts-types-generator.js +2 -4
- package/dist/m3/ts-generation/ts-types-generator.js.map +1 -1
- package/dist/serialization/sorting.d.ts +10 -3
- package/dist/serialization/sorting.d.ts.map +1 -1
- package/dist/serialization/sorting.js +30 -13
- package/dist/serialization/sorting.js.map +1 -1
- package/dist/serialization/textualizer.d.ts.map +1 -1
- package/dist/serialization/textualizer.js +17 -14
- package/dist/serialization/textualizer.js.map +1 -1
- package/package.json +5 -5
- package/src/m3/textualizer.ts +3 -3
- package/src/m3/ts-generation/common.ts +1 -1
- package/src/m3/ts-generation/ts-types-generator.ts +3 -6
- package/src/serialization/sorting.ts +41 -14
- package/src/serialization/textualizer.ts +27 -17
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
* Deprecate the `readFileAsJson` and `writeJsonAsFile` functions in favor of the `readFileAsJsonSync` and `writeJsonAsFileSync` functions from `@lionweb/node-utils`.
|
|
6
6
|
(This change has been propagated throughout the entire codebase.)
|
|
7
|
+
* W.r.t. the `sortedSerializationChunk` function:
|
|
8
|
+
* Give it an additional, optional flag argument `sortConnections` that determines whether containments, references, and annotations are sorted by ID.
|
|
9
|
+
* It now sorts used languages and features by full meta-pointer, not just its key (language’s key for used language, feature’s key for feature).
|
|
7
10
|
|
|
8
11
|
|
|
9
12
|
## 0.9.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textualizer.d.ts","sourceRoot":"","sources":["../../src/m3/textualizer.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"textualizer.d.ts","sourceRoot":"","sources":["../../src/m3/textualizer.ts"],"names":[],"mappings":"AAAA,OAAO,EAUH,QAAQ,EAUX,MAAM,eAAe,CAAA;AA2EtB,eAAO,MAAM,cAAc,GAAI,UAAU,QAAQ,WAA+B,CAAA;AAEhF,eAAO,MAAM,eAAe,GAAI,WAAW,QAAQ,EAAE,KAAG,MAAiF,CAAA"}
|
package/dist/m3/textualizer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Annotation, Concept, Containment, Enumeration, EnumerationLiteral, Interface, isRef,
|
|
1
|
+
import { Annotation, Concept, Containment, Enumeration, EnumerationLiteral, Interface, isRef, Language, Link, nameOf, nameSorted, PrimitiveType, Property, tryToRenderAsText } from "@lionweb/core";
|
|
2
2
|
import { asString, indentWith } from "littoral-templates";
|
|
3
3
|
const indented = indentWith(" ")(1);
|
|
4
|
-
const refAsText = (ref) => (ref
|
|
4
|
+
const refAsText = (ref) => tryToRenderAsText(ref) ?? `???`;
|
|
5
5
|
const recurse = (ts, header, func = asText) => (ts === undefined || ts.length === 0) ? [] : indented([header, indented(ts.map(func))]);
|
|
6
6
|
const featuresOf = (classifier) => recurse(nameSorted(classifier.features), `features (↓name):`);
|
|
7
7
|
const asText = (node) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textualizer.js","sourceRoot":"","sources":["../../src/m3/textualizer.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,UAAU,EAEV,OAAO,EACP,WAAW,EACX,WAAW,EACX,kBAAkB,EAElB,SAAS,EACT,KAAK,EACL,
|
|
1
|
+
{"version":3,"file":"textualizer.js","sourceRoot":"","sources":["../../src/m3/textualizer.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,UAAU,EAEV,OAAO,EACP,WAAW,EACX,WAAW,EACX,kBAAkB,EAElB,SA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AC,QAAQ,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;aAC1E,CAAC;YACF,EAAE;SACL,CAAA;IACL,CAAC;IAED,IAAI,IAAI,YAAY,aAAa,EAAE,CAAC;QAChC,OAAO,kBAAkB,IAAI,CAAC,IAAI,EAAE,CAAA;IACxC,CAAC;IAED,IAAI,IAAI,YAAY,QAAQ,EAAE,CAAC;QAC3B,OAAO,GAAG,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAA;IAC7E,CAAC;IAED,OAAO,aAAa,IAAI,CAAC,GAAG,QAAQ,IAAI,CAAC,EAAE,cAAc,IAAI,CAAC,WAAW,CAAC,IAAI,cAAc,CAAA;AAChG,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,QAAkB,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAA;AAEhF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,SAAqB,EAAU,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -14,7 +14,7 @@ export const tsTypeFor = (datatype) => {
|
|
|
14
14
|
if (datatype instanceof Enumeration) {
|
|
15
15
|
return datatype.name;
|
|
16
16
|
}
|
|
17
|
-
return `unknown /* [ERROR] can't compute a TS type for this datatype: ${datatype} */`;
|
|
17
|
+
return `unknown /* [ERROR] can't compute a TS type for this datatype: ${datatype.toString()} */`;
|
|
18
18
|
};
|
|
19
19
|
export const isINamed = (entity) => entity instanceof Interface
|
|
20
20
|
&& entity.language.key === builtinsFacade.classifiers.inamed.language.key
|
|
@@ -1 +1 @@
|
|
|
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,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,OAAO,SAAS,CAAA;YACrE;gBACI,OAAO,QAAQ,CAAA;QACvB,CAAC;IACL,CAAC;IACD,IAAI,QAAQ,YAAY,WAAW,EAAE,CAAC;QAClC,OAAO,QAAQ,CAAC,IAAI,CAAA;IACxB,CAAC;IACD,OAAO,iEAAiE,QAAQ,KAAK,CAAA;
|
|
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,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,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;QAC5B,OAAO,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IACzD,CAAC;IACD,IAAI,MAAM,YAAY,SAAS,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IACtD,CAAC;IACD,OAAO,KAAK,CAAA;AAChB,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ts-types-generator.d.ts","sourceRoot":"","sources":["../../../src/m3/ts-generation/ts-types-generator.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ts-types-generator.d.ts","sourceRoot":"","sources":["../../../src/m3/ts-generation/ts-types-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAcH,QAAQ,EASX,MAAM,eAAe,CAAA;AAsDtB,oBAAY,iBAAiB;IACzB,YAAY,IAAA;CACf;AAGD;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAAI,UAAU,QAAQ,EAAE,GAAG,mBAAmB,iBAAiB,EAAE,WAwIlG,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { allFeaturesOf, Annotation, Classifier, Concept, conceptsOf, Enumeration, inheritsDirectlyFrom, Interface, isConcrete, isRef,
|
|
1
|
+
import { allFeaturesOf, Annotation, Classifier, Concept, conceptsOf, Enumeration, inheritsDirectlyFrom, Interface, isConcrete, isRef, Link, LionWebVersions, nameOf, nameSorted, PrimitiveType, Property, tryToRenderAsText } 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";
|
|
@@ -20,7 +20,7 @@ const fieldForFeature = (feature) => {
|
|
|
20
20
|
const fieldForLink = ({ name, type, optional, multiple }) => ({
|
|
21
21
|
name,
|
|
22
22
|
optional: optional && !multiple,
|
|
23
|
-
type: `${
|
|
23
|
+
type: `${(tryToRenderAsText(type) ?? `unknown`)}${multiple ? `[]` : ``}`
|
|
24
24
|
});
|
|
25
25
|
const fieldForProperty = ({ name, type, optional }) => ({
|
|
26
26
|
name,
|
|
@@ -114,10 +114,8 @@ export const tsTypeDefsForLanguage = (language, ...generationOptions) => {
|
|
|
114
114
|
...inheritsDirectlyFrom(classifier),
|
|
115
115
|
...allFeaturesOf(classifier)
|
|
116
116
|
.filter((feature) => feature instanceof Link)
|
|
117
|
-
.map((feature) => feature)
|
|
118
117
|
.flatMap(({ type }) => type)
|
|
119
118
|
.filter((type) => type instanceof Classifier)
|
|
120
|
-
.map((classifier) => classifier)
|
|
121
119
|
];
|
|
122
120
|
const coreImports = [
|
|
123
121
|
...(language.entities.every(usesINamedDirectly) ? [] : [`DynamicNode`]),
|
|
@@ -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,
|
|
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,EAGL,IAAI,EACJ,eAAe,EACf,MAAM,EACN,UAAU,EACV,aAAa,EACb,QAAQ,EACR,iBAAiB,EACpB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAC/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@@
|
|
|
1
1
|
import { LionWebJsonChunk } from "@lionweb/json";
|
|
2
2
|
/**
|
|
3
|
-
* @return A sorted version of a {@link
|
|
4
|
-
*
|
|
3
|
+
* @return A sorted version of a {@link LionWebJsonChunk serialization chunk}, meaning:
|
|
4
|
+
*
|
|
5
|
+
* - All nodes sorted by ID.
|
|
6
|
+
* - For all nodes, their properties, containments, and references are sorted lexicographically by the tuple (language-key, feature-key, language-version) — essentially, by the meta-pointer.
|
|
7
|
+
* - If the `sortConnections` argument is `true`, then for every node, all containments, references, and contained annotations are sorted by ID.
|
|
8
|
+
* All key-value pairs in the objects in the JSON produced, appear according to the specification of the LionWeb serialization format, with missing key-value pairs put in with their default values.
|
|
9
|
+
*
|
|
10
|
+
* Sorted serialization chunks lean themselves well to being compared as text files.
|
|
11
|
+
* Setting `sortConnections` to `true` usually changes the meaning of the serialization chunk, but makes it easy to find out whether a list of items appearing in a containment, a reference, or the annotations of a node merely appear in a different order, or really differ.
|
|
5
12
|
*/
|
|
6
|
-
export declare const sortedSerializationChunk: ({ serializationFormatVersion, languages, nodes }: LionWebJsonChunk) => LionWebJsonChunk;
|
|
13
|
+
export declare const sortedSerializationChunk: ({ serializationFormatVersion, languages, nodes }: LionWebJsonChunk, sortConnections?: boolean) => LionWebJsonChunk;
|
|
7
14
|
//# sourceMappingURL=sorting.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sorting.d.ts","sourceRoot":"","sources":["../../src/serialization/sorting.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"sorting.d.ts","sourceRoot":"","sources":["../../src/serialization/sorting.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,gBAAgB,EAQnB,MAAM,eAAe,CAAA;AAatB;;;;;;;;;;GAUG;AACH,eAAO,MAAM,wBAAwB,GAAI,kDAAgD,gBAAgB,EAAE,kBAAkB,OAAO,KAAG,gBAyBjI,CAAA"}
|
|
@@ -1,28 +1,45 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { orderedMetaPointer, orderedSerializedLanguageReference,
|
|
1
|
+
import { mappedComparer, mappedLexiComparer, regularStringComparer, sorterWith } from "@lionweb/ts-utils";
|
|
2
|
+
import { orderedMetaPointer, orderedSerializedLanguageReference, orderedSerializedReferenceTarget } from "./ordering.js";
|
|
3
|
+
const sortedUsedLanguages = sorterWith(mappedLexiComparer([({ key }) => key, ({ version }) => version], regularStringComparer));
|
|
4
|
+
const sortedNodes = sorterWith(mappedComparer(({ id }) => id, regularStringComparer));
|
|
5
|
+
const metaPointerComparer = mappedLexiComparer([({ language }) => language, ({ version }) => version, ({ key }) => key], regularStringComparer);
|
|
6
|
+
const sortedProperties = sorterWith(mappedComparer(({ property }) => property, metaPointerComparer));
|
|
7
|
+
const sortedContainments = sorterWith(mappedComparer(({ containment }) => containment, metaPointerComparer));
|
|
8
|
+
const sortedReferences = sorterWith(mappedComparer(({ reference }) => reference, metaPointerComparer));
|
|
9
|
+
const sortedTargets = sorterWith(mappedComparer(({ reference, resolveInfo }) => (reference ?? resolveInfo), regularStringComparer));
|
|
3
10
|
/**
|
|
4
|
-
* @return A sorted version of a {@link
|
|
5
|
-
*
|
|
11
|
+
* @return A sorted version of a {@link LionWebJsonChunk serialization chunk}, meaning:
|
|
12
|
+
*
|
|
13
|
+
* - All nodes sorted by ID.
|
|
14
|
+
* - For all nodes, their properties, containments, and references are sorted lexicographically by the tuple (language-key, feature-key, language-version) — essentially, by the meta-pointer.
|
|
15
|
+
* - If the `sortConnections` argument is `true`, then for every node, all containments, references, and contained annotations are sorted by ID.
|
|
16
|
+
* All key-value pairs in the objects in the JSON produced, appear according to the specification of the LionWeb serialization format, with missing key-value pairs put in with their default values.
|
|
17
|
+
*
|
|
18
|
+
* Sorted serialization chunks lean themselves well to being compared as text files.
|
|
19
|
+
* Setting `sortConnections` to `true` usually changes the meaning of the serialization chunk, but makes it easy to find out whether a list of items appearing in a containment, a reference, or the annotations of a node merely appear in a different order, or really differ.
|
|
6
20
|
*/
|
|
7
|
-
export const sortedSerializationChunk = ({ serializationFormatVersion, languages, nodes }) => ({
|
|
21
|
+
export const sortedSerializationChunk = ({ serializationFormatVersion, languages, nodes }, sortConnections) => ({
|
|
8
22
|
serializationFormatVersion,
|
|
9
|
-
languages:
|
|
10
|
-
|
|
23
|
+
languages: sortedUsedLanguages(languages)
|
|
24
|
+
.map(orderedSerializedLanguageReference),
|
|
25
|
+
nodes: sortedNodes(nodes)
|
|
11
26
|
.map((node) => ({
|
|
12
27
|
id: node.id,
|
|
13
28
|
classifier: orderedMetaPointer(node.classifier),
|
|
14
|
-
properties:
|
|
15
|
-
containments:
|
|
29
|
+
properties: sortedProperties(node.properties),
|
|
30
|
+
containments: sortedContainments(node.containments)
|
|
16
31
|
.map(({ containment, children }) => ({
|
|
17
32
|
containment: orderedMetaPointer(containment),
|
|
18
|
-
children: children.sort()
|
|
33
|
+
children: sortConnections ? children.sort() : children
|
|
19
34
|
})),
|
|
20
|
-
references:
|
|
35
|
+
references: sortedReferences(node.references)
|
|
21
36
|
.map(({ reference, targets }) => ({
|
|
22
37
|
reference: orderedMetaPointer(reference),
|
|
23
|
-
targets:
|
|
38
|
+
targets: sortConnections
|
|
39
|
+
? sortedTargets(targets).map(orderedSerializedReferenceTarget)
|
|
40
|
+
: targets
|
|
24
41
|
})),
|
|
25
|
-
annotations: node.annotations.sort(),
|
|
42
|
+
annotations: sortConnections ? node.annotations.sort() : node.annotations,
|
|
26
43
|
parent: node.parent
|
|
27
44
|
}))
|
|
28
45
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sorting.js","sourceRoot":"","sources":["../../src/serialization/sorting.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sorting.js","sourceRoot":"","sources":["../../src/serialization/sorting.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AACz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CAAC,MAAM;KACtB,CAAC,CAAC;CACV,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textualizer.d.ts","sourceRoot":"","sources":["../../src/serialization/textualizer.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"textualizer.d.ts","sourceRoot":"","sources":["../../src/serialization/textualizer.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,QAAQ,EAGX,MAAM,eAAe,CAAA;AACtB,OAAO,EAEH,gBAAgB,EAOnB,MAAM,eAAe,CAAA;AActB,eAAO,MAAM,iBAAiB,GAAI,WAAW,gBAAgB,EAAE,YAAW,QAAQ,EAAO,WA+ExF,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Enumeration, isUnresolvedReference, MemoisingSymbolTable, Property } from "@lionweb/core";
|
|
1
|
+
import { Enumeration, isReferenceToSet, isUnresolvedReference, MemoisingSymbolTable, Property } from "@lionweb/core";
|
|
2
2
|
import { byIdMap } from "@lionweb/ts-utils";
|
|
3
3
|
import { asString, indentWith } from "littoral-templates";
|
|
4
4
|
const indent = indentWith(" ")(1);
|
|
@@ -11,23 +11,26 @@ export const genericAsTreeText = ({ nodes }, languages = []) => {
|
|
|
11
11
|
const nodesById = byIdMap(nodes);
|
|
12
12
|
const symbolTable = new MemoisingSymbolTable(languages);
|
|
13
13
|
const nameOrKey = (classifier, feature) => symbolTable.featureMatching(classifier, feature)?.name ?? `[${feature.key}]`;
|
|
14
|
+
const realPropertyAsText = ({ type }, value) => {
|
|
15
|
+
if (type instanceof Enumeration) {
|
|
16
|
+
return type.literals.find(literal => literal.key === value)?.name ?? value;
|
|
17
|
+
}
|
|
18
|
+
if (type === undefined || isReferenceToSet(type)) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
if (isUnresolvedReference(type)) {
|
|
22
|
+
return type.resolveInfo;
|
|
23
|
+
}
|
|
24
|
+
switch (type.name) {
|
|
25
|
+
case "String": return `'${value}'`;
|
|
26
|
+
default: return value;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
14
29
|
const propertyAsText = (classifier, { property: propertyMetaPointer, value }) => {
|
|
15
30
|
const property = symbolTable.featureMatching(classifier, propertyMetaPointer);
|
|
16
31
|
const identification = nameOrKey(classifier, propertyMetaPointer);
|
|
17
32
|
const displayValue = property instanceof Property
|
|
18
|
-
? property
|
|
19
|
-
? (property.type.literals.find(literal => literal.key === value)?.name ?? value)
|
|
20
|
-
: (() => {
|
|
21
|
-
if (property.type === undefined || isUnresolvedReference(property.type)) {
|
|
22
|
-
return `???`;
|
|
23
|
-
}
|
|
24
|
-
switch (property.type.name) {
|
|
25
|
-
case "String":
|
|
26
|
-
return `'${value}'`;
|
|
27
|
-
default:
|
|
28
|
-
return value;
|
|
29
|
-
}
|
|
30
|
-
})()
|
|
33
|
+
? realPropertyAsText(property, value) ?? `???`
|
|
31
34
|
: value;
|
|
32
35
|
return `${identification} = ${displayValue}`;
|
|
33
36
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textualizer.js","sourceRoot":"","sources":["../../src/serialization/textualizer.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"textualizer.js","sourceRoot":"","sources":["../../src/serialization/textualizer.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,gBAAgB,EAChB,qBAAqB,EAErB,oBAAoB,EACpB,QAAQ,EACX,MAAM,eAAe,CAAA;AAWtB,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAY,MAAM,oBAAoB,CAAA;AAEnE,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;AAEpC,MAAM,WAAW,GAAG,CAAC,QAAkB,EAAE,MAAc,EAAY,EAAE,CAAC,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAA;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,EAAE,qBAAqB,CAAC,CAAC;gBAC7D,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,qBAAqB,CAAC,CAAC;gBAClE,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,iBAAiB,EAAE,qBAAqB,CAAC,CAAC;gBACtE,WAAW,CAAC,GAAG,CAAC,gBAAgB,CAAC;aACpC,CAAC;YACF,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;SAC7B,CAAA;IACL,CAAC,CAAA;IAED,OAAO,QAAQ,CACX,KAAK;SACA,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,aAAa;SAClD,GAAG,CAAC,MAAM,CAAC,CACnB,CAAA;AAEL,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lionweb/utilities",
|
|
3
|
-
"version": "0.10.0-alpha.
|
|
3
|
+
"version": "0.10.0-alpha.3",
|
|
4
4
|
"description": "LionWeb utilities",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
"url": "https://github.com/LionWeb-io/lionweb-typescript/issues"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@lionweb/core": "0.10.0-alpha.
|
|
19
|
-
"@lionweb/json": "0.10.0-alpha.
|
|
20
|
-
"@lionweb/textgen-utils": "0.10.0-alpha.
|
|
21
|
-
"@lionweb/ts-utils": "0.10.0-alpha.
|
|
18
|
+
"@lionweb/core": "0.10.0-alpha.3",
|
|
19
|
+
"@lionweb/json": "0.10.0-alpha.3",
|
|
20
|
+
"@lionweb/textgen-utils": "0.10.0-alpha.3",
|
|
21
|
+
"@lionweb/ts-utils": "0.10.0-alpha.3",
|
|
22
22
|
"littoral-templates": "0.5.1",
|
|
23
23
|
"nanoid": "5.1.6"
|
|
24
24
|
},
|
package/src/m3/textualizer.ts
CHANGED
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
INamed,
|
|
9
9
|
Interface,
|
|
10
10
|
isRef,
|
|
11
|
-
isUnresolvedReference,
|
|
12
11
|
Language,
|
|
13
12
|
Link,
|
|
14
13
|
M3Node,
|
|
@@ -17,14 +16,15 @@ import {
|
|
|
17
16
|
Node,
|
|
18
17
|
PrimitiveType,
|
|
19
18
|
Property,
|
|
20
|
-
SingleRef
|
|
19
|
+
SingleRef,
|
|
20
|
+
tryToRenderAsText
|
|
21
21
|
} from "@lionweb/core"
|
|
22
22
|
import { asString, indentWith, Template } from "littoral-templates"
|
|
23
23
|
|
|
24
24
|
const indented = indentWith(" ")(1)
|
|
25
25
|
|
|
26
26
|
const refAsText = <NT extends INamed & Node>(ref: SingleRef<NT>): string =>
|
|
27
|
-
(ref
|
|
27
|
+
tryToRenderAsText(ref) ?? `???`
|
|
28
28
|
|
|
29
29
|
const recurse = <NT extends M3Node>(ts: NT[], header: string, func: (t: NT) => Template = asText): Template =>
|
|
30
30
|
(ts === undefined || ts.length === 0) ? [] : indented([header, indented(ts.map(func))])
|
|
@@ -28,7 +28,7 @@ export const tsTypeFor = (datatype: SingleRef<Datatype>): string => {
|
|
|
28
28
|
if (datatype instanceof Enumeration) {
|
|
29
29
|
return datatype.name
|
|
30
30
|
}
|
|
31
|
-
return `unknown /* [ERROR] can't compute a TS type for this datatype: ${datatype} */`
|
|
31
|
+
return `unknown /* [ERROR] can't compute a TS type for this datatype: ${datatype.toString()} */`
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export const isINamed = (entity: LanguageEntity): boolean =>
|
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
Interface,
|
|
13
13
|
isConcrete,
|
|
14
14
|
isRef,
|
|
15
|
-
isUnresolvedReference,
|
|
16
15
|
Language,
|
|
17
16
|
LanguageEntity,
|
|
18
17
|
Link,
|
|
@@ -20,7 +19,8 @@ import {
|
|
|
20
19
|
nameOf,
|
|
21
20
|
nameSorted,
|
|
22
21
|
PrimitiveType,
|
|
23
|
-
Property
|
|
22
|
+
Property,
|
|
23
|
+
tryToRenderAsText
|
|
24
24
|
} from "@lionweb/core"
|
|
25
25
|
import { indent } from "@lionweb/textgen-utils"
|
|
26
26
|
import { groupBy, mapValues, uniquesAmong } from "@lionweb/ts-utils"
|
|
@@ -43,12 +43,11 @@ const fieldForFeature = (feature: Feature) => {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
47
46
|
const fieldForLink = ({name, type, optional, multiple}: Link): Field =>
|
|
48
47
|
({
|
|
49
48
|
name,
|
|
50
49
|
optional: optional && !multiple,
|
|
51
|
-
type: `${
|
|
50
|
+
type: `${(tryToRenderAsText(type) ?? `unknown`)}${multiple ? `[]` : ``}`
|
|
52
51
|
})
|
|
53
52
|
|
|
54
53
|
|
|
@@ -172,10 +171,8 @@ export const tsTypeDefsForLanguage = (language: Language, ...generationOptions:
|
|
|
172
171
|
...inheritsDirectlyFrom(classifier),
|
|
173
172
|
...allFeaturesOf(classifier)
|
|
174
173
|
.filter((feature) => feature instanceof Link)
|
|
175
|
-
.map((feature) => feature as Link)
|
|
176
174
|
.flatMap(({type}) => type)
|
|
177
175
|
.filter((type) => type instanceof Classifier)
|
|
178
|
-
.map((classifier) => classifier as Classifier)
|
|
179
176
|
]
|
|
180
177
|
|
|
181
178
|
const coreImports = [
|
|
@@ -1,32 +1,59 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
LionWebJsonChunk,
|
|
3
|
+
LionWebJsonContainment,
|
|
4
|
+
LionWebJsonMetaPointer,
|
|
5
|
+
LionWebJsonNode,
|
|
6
|
+
LionWebJsonProperty,
|
|
7
|
+
LionWebJsonReference,
|
|
8
|
+
LionWebJsonReferenceTarget,
|
|
9
|
+
LionWebJsonUsedLanguage
|
|
10
|
+
} from "@lionweb/json"
|
|
11
|
+
import { mappedComparer, mappedLexiComparer, regularStringComparer, sorterWith } from "@lionweb/ts-utils"
|
|
12
|
+
import { orderedMetaPointer, orderedSerializedLanguageReference, orderedSerializedReferenceTarget } from "./ordering.js"
|
|
4
13
|
|
|
5
14
|
|
|
15
|
+
const sortedUsedLanguages = sorterWith<LionWebJsonUsedLanguage>(mappedLexiComparer([({key}) => key, ({version}) => version], regularStringComparer))
|
|
16
|
+
const sortedNodes = sorterWith<LionWebJsonNode>(mappedComparer(({id}) => id, regularStringComparer))
|
|
17
|
+
const metaPointerComparer = mappedLexiComparer<LionWebJsonMetaPointer, string>([({language}) => language, ({version}) => version, ({key}) => key], regularStringComparer)
|
|
18
|
+
const sortedProperties = sorterWith<LionWebJsonProperty>(mappedComparer(({property}) => property, metaPointerComparer))
|
|
19
|
+
const sortedContainments = sorterWith<LionWebJsonContainment>(mappedComparer(({containment}) => containment, metaPointerComparer))
|
|
20
|
+
const sortedReferences = sorterWith<LionWebJsonReference>(mappedComparer(({reference}) => reference, metaPointerComparer))
|
|
21
|
+
const sortedTargets = sorterWith<LionWebJsonReferenceTarget>(mappedComparer(({reference, resolveInfo}) => (reference ?? resolveInfo)!, regularStringComparer))
|
|
22
|
+
|
|
6
23
|
/**
|
|
7
|
-
* @return A sorted version of a {@link
|
|
8
|
-
*
|
|
24
|
+
* @return A sorted version of a {@link LionWebJsonChunk serialization chunk}, meaning:
|
|
25
|
+
*
|
|
26
|
+
* - All nodes sorted by ID.
|
|
27
|
+
* - For all nodes, their properties, containments, and references are sorted lexicographically by the tuple (language-key, feature-key, language-version) — essentially, by the meta-pointer.
|
|
28
|
+
* - If the `sortConnections` argument is `true`, then for every node, all containments, references, and contained annotations are sorted by ID.
|
|
29
|
+
* All key-value pairs in the objects in the JSON produced, appear according to the specification of the LionWeb serialization format, with missing key-value pairs put in with their default values.
|
|
30
|
+
*
|
|
31
|
+
* Sorted serialization chunks lean themselves well to being compared as text files.
|
|
32
|
+
* Setting `sortConnections` to `true` usually changes the meaning of the serialization chunk, but makes it easy to find out whether a list of items appearing in a containment, a reference, or the annotations of a node merely appear in a different order, or really differ.
|
|
9
33
|
*/
|
|
10
|
-
export const sortedSerializationChunk = ({serializationFormatVersion, languages, nodes}: LionWebJsonChunk): LionWebJsonChunk =>
|
|
34
|
+
export const sortedSerializationChunk = ({serializationFormatVersion, languages, nodes}: LionWebJsonChunk, sortConnections?: boolean): LionWebJsonChunk =>
|
|
11
35
|
({
|
|
12
36
|
serializationFormatVersion,
|
|
13
|
-
languages:
|
|
14
|
-
|
|
37
|
+
languages: sortedUsedLanguages(languages)
|
|
38
|
+
.map(orderedSerializedLanguageReference),
|
|
39
|
+
nodes: sortedNodes(nodes)
|
|
15
40
|
.map((node) => ({
|
|
16
41
|
id: node.id,
|
|
17
42
|
classifier: orderedMetaPointer(node.classifier),
|
|
18
|
-
properties:
|
|
19
|
-
containments:
|
|
43
|
+
properties: sortedProperties(node.properties),
|
|
44
|
+
containments: sortedContainments(node.containments)
|
|
20
45
|
.map(({containment, children}) => ({
|
|
21
46
|
containment: orderedMetaPointer(containment),
|
|
22
|
-
children: children.sort()
|
|
47
|
+
children: sortConnections ? children.sort() : children
|
|
23
48
|
})),
|
|
24
|
-
references:
|
|
49
|
+
references: sortedReferences(node.references)
|
|
25
50
|
.map(({reference, targets}) => ({
|
|
26
51
|
reference: orderedMetaPointer(reference),
|
|
27
|
-
targets:
|
|
52
|
+
targets: sortConnections
|
|
53
|
+
? sortedTargets(targets).map(orderedSerializedReferenceTarget)
|
|
54
|
+
: targets
|
|
28
55
|
})),
|
|
29
|
-
annotations: node.annotations.sort(),
|
|
56
|
+
annotations: sortConnections ? node.annotations.sort() : node.annotations,
|
|
30
57
|
parent: node.parent
|
|
31
58
|
}))
|
|
32
59
|
})
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Enumeration,
|
|
3
|
+
isReferenceToSet,
|
|
4
|
+
isUnresolvedReference,
|
|
5
|
+
Language,
|
|
6
|
+
MemoisingSymbolTable,
|
|
7
|
+
Property
|
|
8
|
+
} from "@lionweb/core"
|
|
2
9
|
import {
|
|
3
10
|
LionWebId,
|
|
4
11
|
LionWebJsonChunk,
|
|
@@ -30,25 +37,28 @@ export const genericAsTreeText = ({ nodes }: LionWebJsonChunk, languages: Langua
|
|
|
30
37
|
const nameOrKey = (classifier: LionWebJsonMetaPointer, feature: LionWebJsonMetaPointer): string =>
|
|
31
38
|
symbolTable.featureMatching(classifier, feature)?.name ?? `[${feature.key}]`
|
|
32
39
|
|
|
40
|
+
const realPropertyAsText = ({type}: Property, value: string | null): string | null | undefined => {
|
|
41
|
+
if (type instanceof Enumeration) {
|
|
42
|
+
return type.literals.find(literal => literal.key === value)?.name ?? value
|
|
43
|
+
}
|
|
44
|
+
if (type === undefined || isReferenceToSet(type)) {
|
|
45
|
+
return undefined
|
|
46
|
+
}
|
|
47
|
+
if (isUnresolvedReference(type)) {
|
|
48
|
+
return type.resolveInfo
|
|
49
|
+
}
|
|
50
|
+
switch (type.name) {
|
|
51
|
+
case "String": return `'${value}'`
|
|
52
|
+
default: return value
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
33
56
|
const propertyAsText = (classifier: LionWebJsonMetaPointer, { property: propertyMetaPointer, value }: LionWebJsonProperty) => {
|
|
34
57
|
const property = symbolTable.featureMatching(classifier, propertyMetaPointer)
|
|
35
58
|
const identification = nameOrKey(classifier, propertyMetaPointer)
|
|
36
|
-
const displayValue =
|
|
37
|
-
property
|
|
38
|
-
|
|
39
|
-
? (property.type.literals.find(literal => literal.key === value)?.name ?? value)
|
|
40
|
-
: (() => {
|
|
41
|
-
if (property.type === undefined || isUnresolvedReference(property.type)) {
|
|
42
|
-
return `???`
|
|
43
|
-
}
|
|
44
|
-
switch (property.type.name) {
|
|
45
|
-
case "String":
|
|
46
|
-
return `'${value}'`
|
|
47
|
-
default:
|
|
48
|
-
return value
|
|
49
|
-
}
|
|
50
|
-
})()
|
|
51
|
-
: value
|
|
59
|
+
const displayValue = property instanceof Property
|
|
60
|
+
? realPropertyAsText(property, value) ?? `???`
|
|
61
|
+
: value
|
|
52
62
|
return `${identification} = ${displayValue}`
|
|
53
63
|
}
|
|
54
64
|
|