@lionweb/utilities 0.10.0-alpha.2 → 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
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,7 +1,14 @@
|
|
|
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;AACzG,OAAO,EAAE,kBAAkB,EAAE,kCAAkC,EAAE,gCAAgC,EAAE,MAAM,eAAe,CAAA;AAGxH,MAAM,mBAAmB,GAAG,UAAU,CAA0B,kBAAkB,CAAC,CAAC,CAAC,EAAC,GAAG,EAAC,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,EAAC,OAAO,EAAC,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,qBAAqB,CAAC,CAAC,CAAA;AACpJ,MAAM,WAAW,GAAG,UAAU,CAAkB,cAAc,CAAC,CAAC,EAAC,EAAE,EAAC,EAAE,EAAE,CAAC,EAAE,EAAE,qBAAqB,CAAC,CAAC,CAAA;AACpG,MAAM,mBAAmB,GAAG,kBAAkB,CAAiC,CAAC,CAAC,EAAC,QAAQ,EAAC,EAAE,EAAE,CAAC,QAAQ,EAAE,CAAC,EAAC,OAAO,EAAC,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,EAAC,GAAG,EAAC,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,qBAAqB,CAAC,CAAA;AACzK,MAAM,gBAAgB,GA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,EAAE,eAAe,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,QAAQ;SACzD,CAAC,CAAC;QACX,UAAU,EAAE,gBAAgB,CAAC,IAAI,CAAC,UAAU,CAAC;aACpC,GAAG,CAAC,CAAC,EAAC,SAAS,EAAE,OAAO,EAAC,EAAE,EAAE,CAAC,CAAC;YAC5B,SAAS,EAAE,kBAAkB,CAAC,SAAS,CAAC;YACxC,OAAO,EAAE,eAAe;gBACpB,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,gCAAgC,CAAC;gBAC9D,CAAC,CAAC,OAAO;SAChB,CAAC,CAAC;QACX,WAAW,EAAE,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW;QACzE,MAAM,EAAE,IAAI,CAAC,MAAM;KACtB,CAAC,CAAC;CACV,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
|
},
|
|
@@ -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
|
})
|