@lionweb/core 0.5.0-beta.0
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 +10 -0
- package/LICENSE +201 -0
- package/dist/api.d.ts +72 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +47 -0
- package/dist/api.js.map +1 -0
- package/dist/deserializer.d.ts +14 -0
- package/dist/deserializer.d.ts.map +1 -0
- package/dist/deserializer.js +134 -0
- package/dist/deserializer.js.map +1 -0
- package/dist/dynamic-api.d.ts +19 -0
- package/dist/dynamic-api.d.ts.map +1 -0
- package/dist/dynamic-api.js +28 -0
- package/dist/dynamic-api.js.map +1 -0
- package/dist/functions.d.ts +10 -0
- package/dist/functions.d.ts.map +1 -0
- package/dist/functions.js +13 -0
- package/dist/functions.js.map +1 -0
- package/dist/id-generation.d.ts +54 -0
- package/dist/id-generation.d.ts.map +1 -0
- package/dist/id-generation.js +76 -0
- package/dist/id-generation.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/m3/api.d.ts +16 -0
- package/dist/m3/api.d.ts.map +1 -0
- package/dist/m3/api.js +55 -0
- package/dist/m3/api.js.map +1 -0
- package/dist/m3/builtins.d.ts +24 -0
- package/dist/m3/builtins.d.ts.map +1 -0
- package/dist/m3/builtins.js +67 -0
- package/dist/m3/builtins.js.map +1 -0
- package/dist/m3/constraints.d.ts +16 -0
- package/dist/m3/constraints.d.ts.map +1 -0
- package/dist/m3/constraints.js +40 -0
- package/dist/m3/constraints.js.map +1 -0
- package/dist/m3/deserializer.d.ts +8 -0
- package/dist/m3/deserializer.d.ts.map +1 -0
- package/dist/m3/deserializer.js +16 -0
- package/dist/m3/deserializer.js.map +1 -0
- package/dist/m3/factory.d.ts +26 -0
- package/dist/m3/factory.d.ts.map +1 -0
- package/dist/m3/factory.js +48 -0
- package/dist/m3/factory.js.map +1 -0
- package/dist/m3/functions.d.ts +110 -0
- package/dist/m3/functions.d.ts.map +1 -0
- package/dist/m3/functions.js +145 -0
- package/dist/m3/functions.js.map +1 -0
- package/dist/m3/index.d.ts +12 -0
- package/dist/m3/index.d.ts.map +1 -0
- package/dist/m3/index.js +12 -0
- package/dist/m3/index.js.map +1 -0
- package/dist/m3/key-generation.d.ts +15 -0
- package/dist/m3/key-generation.d.ts.map +1 -0
- package/dist/m3/key-generation.js +11 -0
- package/dist/m3/key-generation.js.map +1 -0
- package/dist/m3/lioncore.d.ts +39 -0
- package/dist/m3/lioncore.d.ts.map +1 -0
- package/dist/m3/lioncore.js +150 -0
- package/dist/m3/lioncore.js.map +1 -0
- package/dist/m3/reference-checker.d.ts +6 -0
- package/dist/m3/reference-checker.d.ts.map +1 -0
- package/dist/m3/reference-checker.js +29 -0
- package/dist/m3/reference-checker.js.map +1 -0
- package/dist/m3/serializer.d.ts +9 -0
- package/dist/m3/serializer.d.ts.map +1 -0
- package/dist/m3/serializer.js +9 -0
- package/dist/m3/serializer.js.map +1 -0
- package/dist/m3/textual-syntax.d.ts +4 -0
- package/dist/m3/textual-syntax.d.ts.map +1 -0
- package/dist/m3/textual-syntax.js +57 -0
- package/dist/m3/textual-syntax.js.map +1 -0
- package/dist/m3/types.d.ts +117 -0
- package/dist/m3/types.d.ts.map +1 -0
- package/dist/m3/types.js +196 -0
- package/dist/m3/types.js.map +1 -0
- package/dist/references.d.ts +18 -0
- package/dist/references.d.ts.map +1 -0
- package/dist/references.js +10 -0
- package/dist/references.js.map +1 -0
- package/dist/serialization.d.ts +51 -0
- package/dist/serialization.d.ts.map +1 -0
- package/dist/serialization.js +5 -0
- package/dist/serialization.js.map +1 -0
- package/dist/serializer.d.ts +8 -0
- package/dist/serializer.d.ts.map +1 -0
- package/dist/serializer.js +101 -0
- package/dist/serializer.js.map +1 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/array-helpers.d.ts +14 -0
- package/dist/utils/array-helpers.d.ts.map +1 -0
- package/dist/utils/array-helpers.js +15 -0
- package/dist/utils/array-helpers.js.map +1 -0
- package/dist/utils/cycles.d.ts +8 -0
- package/dist/utils/cycles.d.ts.map +1 -0
- package/dist/utils/cycles.js +26 -0
- package/dist/utils/cycles.js.map +1 -0
- package/dist/utils/grouping.d.ts +13 -0
- package/dist/utils/grouping.d.ts.map +1 -0
- package/dist/utils/grouping.js +26 -0
- package/dist/utils/grouping.js.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/recursion.d.ts +13 -0
- package/dist/utils/recursion.d.ts.map +1 -0
- package/dist/utils/recursion.js +21 -0
- package/dist/utils/recursion.js.map +1 -0
- package/dist/utils/sorting.d.ts +7 -0
- package/dist/utils/sorting.d.ts.map +1 -0
- package/dist/utils/sorting.js +7 -0
- package/dist/utils/sorting.js.map +1 -0
- package/package.json +23 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
* Replaced all occurrences of "LIon" (with uppercase 'I') with "Lion" (with lowercase 'i').
|
|
6
|
+
* Split the `ModelAPI` interface into a read- and write-part: `ReadModelAPI` vs. `WriteModelAPI`.
|
|
7
|
+
* Make fixes w.r.t. multi-language models.
|
|
8
|
+
* Migrate from Deno to Node.js.
|
|
9
|
+
* Implement import of Ecore enums.
|
|
10
|
+
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2022 LionWeb Team
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Node } from "./types.js";
|
|
2
|
+
import { Concept, Enumeration, EnumerationLiteral, Feature } from "./m3/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Type def. for functions that deduce the {@link Concept concept} of a given {@link Node node}.
|
|
5
|
+
*/
|
|
6
|
+
type ConceptDeducer<NT extends Node> = (node: NT) => Concept;
|
|
7
|
+
/**
|
|
8
|
+
* Two interfaces that defines APIs for in-memory models.
|
|
9
|
+
* Instances/implementations of this interface parametrize generic (de-)serialization.
|
|
10
|
+
* Implementations of ModelAPI {w|c}ould be:
|
|
11
|
+
* - specific to Lioncore (so to match m3/types.ts)
|
|
12
|
+
* - generic just to deserialize into Node & { settings: { [featureName: string]: unknown } } -- á la Federico
|
|
13
|
+
*/
|
|
14
|
+
interface ReadModelAPI<NT extends Node> {
|
|
15
|
+
/**
|
|
16
|
+
* @return The {@link Concept concept} of the given node
|
|
17
|
+
*/
|
|
18
|
+
conceptOf: ConceptDeducer<NT>;
|
|
19
|
+
/**
|
|
20
|
+
* @return The value of the given {@link Feature feature} on the given node.
|
|
21
|
+
*/
|
|
22
|
+
getFeatureValue: (node: NT, feature: Feature) => unknown;
|
|
23
|
+
/**
|
|
24
|
+
* @return The {@link EnumerationLiteral} corresponding to
|
|
25
|
+
* the given {@link Enumeration} and the runtime encoding of a literal of it,
|
|
26
|
+
*/
|
|
27
|
+
enumerationLiteralFrom: (encoding: unknown, enumeration: Enumeration) => EnumerationLiteral | null;
|
|
28
|
+
}
|
|
29
|
+
interface WriteModelAPI<NT extends Node> {
|
|
30
|
+
/**
|
|
31
|
+
* @return An instance of the given concept, also given its parent (or {@link undefined} for root nodes),
|
|
32
|
+
* its ID and the values of the node's properties ("settings").
|
|
33
|
+
* (The latter may be required as arguments for the constructor of a class, whose instances represent nodes.)
|
|
34
|
+
*/
|
|
35
|
+
nodeFor: (parent: NT | undefined, concept: Concept, id: string, propertySettings: {
|
|
36
|
+
[propertyKey: string]: unknown;
|
|
37
|
+
}) => NT;
|
|
38
|
+
/**
|
|
39
|
+
* Sets the *single* given value of the indicated {@link Feature} on the given node.
|
|
40
|
+
* This means adding it in case the feature is multi-valued, meaning it is a {@link Link} with {@code multiple = true}.
|
|
41
|
+
*/
|
|
42
|
+
setFeatureValue: (node: NT, feature: Feature, value: unknown) => void;
|
|
43
|
+
/**
|
|
44
|
+
* @return The runtime encoding of the given {@link EnumerationLiteral}.
|
|
45
|
+
*/
|
|
46
|
+
encodingOf: (literal: EnumerationLiteral) => unknown;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Type def. for functions that extract {@link Node nodes} from a given one.
|
|
50
|
+
*/
|
|
51
|
+
type NodesExtractor<NT extends Node> = (nodes: NT) => NT[];
|
|
52
|
+
/**
|
|
53
|
+
* @return A function that extracts the children from a given node.
|
|
54
|
+
*/
|
|
55
|
+
declare const childrenExtractorUsing: <NT extends Node>(api: ReadModelAPI<NT>) => NodesExtractor<NT>;
|
|
56
|
+
/**
|
|
57
|
+
* @return a function that extracts *all* nodes from a given start node - usually a root node.
|
|
58
|
+
*/
|
|
59
|
+
declare const nodesExtractorUsing: <NT extends Node>(api: ReadModelAPI<NT>) => NodesExtractor<NT>;
|
|
60
|
+
/**
|
|
61
|
+
* Updates the value of the given {@link Feature feature} on the given "settings" object
|
|
62
|
+
* (either a {@link Node node} or a sub object of it), using the feature's *name*.
|
|
63
|
+
*/
|
|
64
|
+
declare const updateSettingsNameBased: (settings: Record<string, unknown>, feature: Feature, value: unknown) => void;
|
|
65
|
+
/**
|
|
66
|
+
* Updates the value of the given {@link Feature feature} on the given "settings" object
|
|
67
|
+
* (either a {@link Node node} or a sub object of it), using the feature's *key*.
|
|
68
|
+
*/
|
|
69
|
+
declare const updateSettingsKeyBased: (settings: Record<string, unknown>, feature: Feature, value: unknown) => void;
|
|
70
|
+
export type { ConceptDeducer, NodesExtractor, ReadModelAPI, WriteModelAPI };
|
|
71
|
+
export { childrenExtractorUsing, nodesExtractorUsing, updateSettingsKeyBased, updateSettingsNameBased };
|
|
72
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,YAAY,CAAA;AAC/B,OAAO,EAAC,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,OAAO,EAAO,MAAM,eAAe,CAAA;AAKrF;;GAEG;AACH,KAAK,cAAc,CAAC,EAAE,SAAS,IAAI,IAAI,CAAC,IAAI,EAAE,EAAE,KAAK,OAAO,CAAA;AAG5D;;;;;;GAMG;AAGH,UAAU,YAAY,CAAC,EAAE,SAAS,IAAI;IAElC;;OAEG;IACH,SAAS,EAAE,cAAc,CAAC,EAAE,CAAC,CAAA;IAE7B;;OAEG;IACH,eAAe,EAAE,CAAC,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,KAAK,OAAO,CAAA;IAGxD;;;OAGG;IACH,sBAAsB,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,KAAK,kBAAkB,GAAG,IAAI,CAAA;CAErG;AAED,UAAU,aAAa,CAAC,EAAE,SAAS,IAAI;IAEnC;;;;OAIG;IACH,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,GAAG,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,gBAAgB,EAAE;QAAE,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,KAAK,EAAE,CAAA;IAE3H;;;OAGG;IACH,eAAe,EAAE,CAAC,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;IAGrE;;OAEG;IACH,UAAU,EAAE,CAAC,OAAO,EAAE,kBAAkB,KAAK,OAAO,CAAA;CAEvD;AAED;;GAEG;AACH,KAAK,cAAc,CAAC,EAAE,SAAS,IAAI,IAAI,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,CAAA;AAE1D;;GAEG;AACH,QAAA,MAAM,sBAAsB,gEAIyD,CAAA;AAGrF;;GAEG;AACH,QAAA,MAAM,mBAAmB,gEACyD,CAAA;AAGlF;;;GAGG;AACH,QAAA,MAAM,uBAAuB,aAAc,OAAO,MAAM,EAAE,OAAO,CAAC,WAAW,OAAO,SAAS,OAAO,KAAG,IAUtG,CAAA;AAED;;;GAGG;AACH,QAAA,MAAM,sBAAsB,aAAc,OAAO,MAAM,EAAE,OAAO,CAAC,WAAW,OAAO,SAAS,OAAO,KAAG,IAUrG,CAAA;AAED,YAAY,EACR,cAAc,EACd,cAAc,EACd,YAAY,EACZ,aAAa,EAChB,CAAA;AAED,OAAO,EACH,sBAAsB,EACtB,mBAAmB,EACnB,sBAAsB,EACtB,uBAAuB,EAC1B,CAAA"}
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Link } from "./m3/types.js";
|
|
2
|
+
import { flatMapNonCyclingFollowing, trivialFlatMapper } from "./utils/recursion.js";
|
|
3
|
+
import { allFeaturesOf, isContainment } from "./m3/functions.js";
|
|
4
|
+
/**
|
|
5
|
+
* @return A function that extracts the children from a given node.
|
|
6
|
+
*/
|
|
7
|
+
const childrenExtractorUsing = (api) => (node) => allFeaturesOf(api.conceptOf(node))
|
|
8
|
+
.filter(isContainment)
|
|
9
|
+
.flatMap((containment) => api.getFeatureValue(node, containment));
|
|
10
|
+
/**
|
|
11
|
+
* @return a function that extracts *all* nodes from a given start node - usually a root node.
|
|
12
|
+
*/
|
|
13
|
+
const nodesExtractorUsing = (api) => flatMapNonCyclingFollowing(trivialFlatMapper, childrenExtractorUsing(api));
|
|
14
|
+
/**
|
|
15
|
+
* Updates the value of the given {@link Feature feature} on the given "settings" object
|
|
16
|
+
* (either a {@link Node node} or a sub object of it), using the feature's *name*.
|
|
17
|
+
*/
|
|
18
|
+
const updateSettingsNameBased = (settings, feature, value) => {
|
|
19
|
+
const fName = feature.name;
|
|
20
|
+
if (feature instanceof Link && feature.multiple) {
|
|
21
|
+
if (!Array.isArray(settings[fName])) {
|
|
22
|
+
settings[fName] = [];
|
|
23
|
+
}
|
|
24
|
+
settings[fName].push(value);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
settings[fName] = value;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Updates the value of the given {@link Feature feature} on the given "settings" object
|
|
32
|
+
* (either a {@link Node node} or a sub object of it), using the feature's *key*.
|
|
33
|
+
*/
|
|
34
|
+
const updateSettingsKeyBased = (settings, feature, value) => {
|
|
35
|
+
const { key } = feature;
|
|
36
|
+
if (feature instanceof Link && feature.multiple) {
|
|
37
|
+
if (!Array.isArray(settings[key])) {
|
|
38
|
+
settings[key] = [];
|
|
39
|
+
}
|
|
40
|
+
settings[key].push(value);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
settings[key] = value;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
export { childrenExtractorUsing, nodesExtractorUsing, updateSettingsKeyBased, updateSettingsNameBased };
|
|
47
|
+
//# sourceMappingURL=api.js.map
|
package/dist/api.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AACA,OAAO,EAAoD,IAAI,EAAC,MAAM,eAAe,CAAA;AACrF,OAAO,EAAC,0BAA0B,EAAE,iBAAiB,EAAC,MAAM,sBAAsB,CAAA;AAClF,OAAO,EAAC,aAAa,EAAE,aAAa,EAAC,MAAM,mBAAmB,CAAA;AAmE9D;;GAEG;AACH,MAAM,sBAAsB,GAAG,C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,QAAQ,CAAC,GAAG,CAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;KAC3C;SAAM;QACH,QAAQ,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;KACxB;AACL,CAAC,CAAA;AASD,OAAO,EACH,sBAAsB,EACtB,mBAAmB,EACnB,sBAAsB,EACtB,uBAAuB,EAC1B,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Node } from "./types.js";
|
|
2
|
+
import { SerializationChunk } from "./serialization.js";
|
|
3
|
+
import { WriteModelAPI } from "./api.js";
|
|
4
|
+
import { Language } from "./m3/types.js";
|
|
5
|
+
/**
|
|
6
|
+
* @return a deserialization of a {@link SerializationChunk}
|
|
7
|
+
*
|
|
8
|
+
* @param serializationChunk - a {@link SerializedModel model} from its LionWeb serialization JSON format
|
|
9
|
+
* @param api - a {@link ModelAPI model API} that is used to instantiate nodes and set values on them
|
|
10
|
+
* @param languages - a {@link Language language} that the serialized model is expected to conform to
|
|
11
|
+
* @param dependentNodes - a collection of nodes from dependent models against which all references in the serialized model are supposed to resolve against
|
|
12
|
+
*/
|
|
13
|
+
export declare const deserializeChunk: <NT extends Node>(serializationChunk: SerializationChunk, api: WriteModelAPI<NT>, languages: Language[], dependentNodes: Node[]) => NT[];
|
|
14
|
+
//# sourceMappingURL=deserializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deserializer.d.ts","sourceRoot":"","sources":["../src/deserializer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAK,IAAI,EAAC,MAAM,YAAY,CAAA;AACnC,OAAO,EAAoC,kBAAkB,EAAiB,MAAM,oBAAoB,CAAA;AACxG,OAAO,EAAC,aAAa,EAAC,MAAM,UAAU,CAAA;AACtC,OAAO,EAAoC,QAAQ,EAAqC,MAAM,eAAe,CAAA;AAkB7G;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,wCACL,kBAAkB,qCAE3B,QAAQ,EAAE,kBAEL,IAAI,EAAE,SA4IzB,CAAA"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { currentSerializationFormatVersion } from "./serialization.js";
|
|
2
|
+
import { Concept, Containment, Enumeration, PrimitiveType, Property, Reference } from "./m3/types.js";
|
|
3
|
+
import { allFeaturesOf } from "./m3/functions.js";
|
|
4
|
+
import { deserializeBuiltin } from "./m3/builtins.js";
|
|
5
|
+
import { groupBy } from "./utils/grouping.js";
|
|
6
|
+
/**
|
|
7
|
+
* @return a map id -> thing with id.
|
|
8
|
+
*/
|
|
9
|
+
const byIdMap = (ts) => {
|
|
10
|
+
const map = {};
|
|
11
|
+
ts.forEach((t) => {
|
|
12
|
+
map[t.id] = t;
|
|
13
|
+
});
|
|
14
|
+
return map;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* @return a deserialization of a {@link SerializationChunk}
|
|
18
|
+
*
|
|
19
|
+
* @param serializationChunk - a {@link SerializedModel model} from its LionWeb serialization JSON format
|
|
20
|
+
* @param api - a {@link ModelAPI model API} that is used to instantiate nodes and set values on them
|
|
21
|
+
* @param languages - a {@link Language language} that the serialized model is expected to conform to
|
|
22
|
+
* @param dependentNodes - a collection of nodes from dependent models against which all references in the serialized model are supposed to resolve against
|
|
23
|
+
*/
|
|
24
|
+
export const deserializeChunk = (serializationChunk, api, languages,
|
|
25
|
+
// TODO APIs <--> languages, so it's weird that it looks split up like this
|
|
26
|
+
dependentNodes
|
|
27
|
+
// TODO (#13) see if you can turn this into [nodes: Node[], api: ModelAPI<Node>][] after all
|
|
28
|
+
) => {
|
|
29
|
+
if (serializationChunk.serializationFormatVersion !== currentSerializationFormatVersion) {
|
|
30
|
+
throw new Error(`can't deserialize from serialization format other than version 1`);
|
|
31
|
+
}
|
|
32
|
+
const allEntities = languages.flatMap(({ entities }) => entities);
|
|
33
|
+
const { nodes: serializedNodes } = serializationChunk;
|
|
34
|
+
const serializedRootNodes = serializedNodes.filter(({ parent }) => parent === null);
|
|
35
|
+
if (serializedRootNodes.length === 0) {
|
|
36
|
+
throw new Error(`could not deserialize: no root nodes found`);
|
|
37
|
+
}
|
|
38
|
+
const serializedNodeById = byIdMap(serializedNodes);
|
|
39
|
+
const deserializedNodeById = {};
|
|
40
|
+
/**
|
|
41
|
+
* Instantiates a {@link Node} from the given {@link SerializedNode},
|
|
42
|
+
* and stores it under its ID so references to it can be resolved.
|
|
43
|
+
* For every serialized node, only one instance will ever be constructed (through memoisation).
|
|
44
|
+
*/
|
|
45
|
+
const instantiateMemoised = (serNode, parent) => {
|
|
46
|
+
if (serNode.id in deserializedNodeById) {
|
|
47
|
+
return deserializedNodeById[serNode.id];
|
|
48
|
+
}
|
|
49
|
+
const node = instantiate(serNode, parent);
|
|
50
|
+
deserializedNodeById[node.id] = node;
|
|
51
|
+
return node;
|
|
52
|
+
};
|
|
53
|
+
const referencesToInstall = [];
|
|
54
|
+
/**
|
|
55
|
+
* Instantiates a {@link Node} from its {@link SerializedNode serialization}.
|
|
56
|
+
*/
|
|
57
|
+
const instantiate = ({ concept: conceptMetaPointer, id, properties, children, references }, parent) => {
|
|
58
|
+
const concept = allEntities
|
|
59
|
+
.find((element) => element instanceof Concept && element.key === conceptMetaPointer.key);
|
|
60
|
+
if (concept === undefined) {
|
|
61
|
+
throw new Error(`can't deserialize a node having concept with ID "${conceptMetaPointer.key}"`);
|
|
62
|
+
}
|
|
63
|
+
const allFeatures = allFeaturesOf(concept);
|
|
64
|
+
const propertySettings = {};
|
|
65
|
+
const serializedPropertiesPerKey = properties === undefined ? {} : groupBy(properties, (sp) => sp.property.key);
|
|
66
|
+
if (properties !== undefined) {
|
|
67
|
+
allFeatures
|
|
68
|
+
.filter((feature) => feature instanceof Property)
|
|
69
|
+
.map((feature) => feature)
|
|
70
|
+
.forEach((property) => {
|
|
71
|
+
if (property.key in serializedPropertiesPerKey) {
|
|
72
|
+
const value = serializedPropertiesPerKey[property.key][0].value;
|
|
73
|
+
if (property.type instanceof PrimitiveType) {
|
|
74
|
+
propertySettings[property.key] = deserializeBuiltin(value, property);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (property.type instanceof Enumeration) {
|
|
78
|
+
const literal = property.type.literals.find((literal) => literal.key = value);
|
|
79
|
+
if (literal !== undefined) {
|
|
80
|
+
propertySettings[property.key] = api.encodingOf(literal);
|
|
81
|
+
}
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
// (property is not handled, because neither a primitive type nor of enumeration type)
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
const node = api.nodeFor(parent, concept, id, propertySettings);
|
|
89
|
+
const serializedChildrenPerKey = children === undefined ? {} : groupBy(children, (sp) => sp.containment.key);
|
|
90
|
+
const serializedReferencesPerKey = references === undefined ? {} : groupBy(references, (sp) => sp.reference.key);
|
|
91
|
+
allFeatures
|
|
92
|
+
.forEach((feature) => {
|
|
93
|
+
if (feature instanceof Property && properties !== undefined && feature.key in serializedPropertiesPerKey) {
|
|
94
|
+
api.setFeatureValue(node, feature, propertySettings[feature.key]);
|
|
95
|
+
}
|
|
96
|
+
else if (feature instanceof Containment && children !== undefined && feature.key in serializedChildrenPerKey) {
|
|
97
|
+
const childIds = serializedChildrenPerKey[feature.key].flatMap((serChildren) => serChildren.children);
|
|
98
|
+
if (feature.multiple) {
|
|
99
|
+
childIds
|
|
100
|
+
.forEach((childId) => {
|
|
101
|
+
api.setFeatureValue(node, feature, instantiateMemoised(serializedNodeById[childId], node));
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
if (childIds.length > 0) {
|
|
106
|
+
api.setFeatureValue(node, feature, instantiateMemoised(serializedNodeById[childIds[0]], node));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else if (feature instanceof Reference && references !== undefined && feature.key in serializedReferencesPerKey) {
|
|
111
|
+
const serRefs = (serializedReferencesPerKey[feature.key] ?? []).flatMap((serReferences) => serReferences.targets.map((t) => t.reference));
|
|
112
|
+
referencesToInstall.push(...(serRefs
|
|
113
|
+
.filter((serRef) => typeof serRef === "string")
|
|
114
|
+
.map((refId) => [node, feature, refId])));
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
return node;
|
|
118
|
+
};
|
|
119
|
+
const rootNodes = serializedRootNodes.map((serializedRootNode) => instantiateMemoised(serializedRootNode));
|
|
120
|
+
const nodesOfDependentModelsById = byIdMap(dependentNodes);
|
|
121
|
+
referencesToInstall.forEach(([node, reference, refId]) => {
|
|
122
|
+
const lookUpById = () => {
|
|
123
|
+
const target = deserializedNodeById[refId] ?? nodesOfDependentModelsById[refId];
|
|
124
|
+
if (target === undefined) {
|
|
125
|
+
const metaTypeMessage = "concept" in node ? ` and (meta-)type ${node.concept}` : "";
|
|
126
|
+
throw new Error(`couldn't find the target with id "${refId}" of a "${reference.name}" reference on the node with id "${node.id}"${metaTypeMessage}`);
|
|
127
|
+
}
|
|
128
|
+
return target;
|
|
129
|
+
};
|
|
130
|
+
api.setFeatureValue(node, reference, lookUpById());
|
|
131
|
+
});
|
|
132
|
+
return rootNodes;
|
|
133
|
+
};
|
|
134
|
+
//# sourceMappingURL=deserializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deserializer.js","sourceRoot":"","sources":["../src/deserializer.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,iCAAiC,EAAqC,MAAM,oBAAoB,CAAA;AAExG,OAAO,EAAC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAY,aAAa,EAAE,QAAQ,EAAE,SAAS,EAAC,MAAM,eAAe,CAAA;AAC7G,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAC,kBAAkB,EAAC,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAC,OAAO,EAAC,MAAM,qBAAqB,CAAA;AAG3C;;GAEG;AACH,MAAM,OAAO,GAAG,CAAuB,EAAO,EAAmB,EAAE;IAC/D,MAAM,GAAG,G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"./m3/types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Type definition for "dynamic nodes" that are not backed by specific types (e.g. classes).
|
|
6
|
+
*/
|
|
7
|
+
export type DynamicNode = Node & {
|
|
8
|
+
concept: Concept;
|
|
9
|
+
settings: Record<string, unknown>;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* An implementation of {@link ReadModelAPI} for {@link DynamicNode dynamic nodes}.
|
|
13
|
+
*/
|
|
14
|
+
export declare const dynamicReadModelAPI: ReadModelAPI<DynamicNode>;
|
|
15
|
+
/**
|
|
16
|
+
* An implementation of {@link WriteModelAPI} for {@link DynamicNode dynamic nodes}.
|
|
17
|
+
*/
|
|
18
|
+
export declare const dynamicWriteModelAPI: WriteModelAPI<DynamicNode>;
|
|
19
|
+
//# sourceMappingURL=dynamic-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamic-api.d.ts","sourceRoot":"","sources":["../src/dynamic-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,YAAY,CAAA;AAC/B,OAAO,EAAC,YAAY,EAA0B,aAAa,EAAC,MAAM,UAAU,CAAA;AAC5E,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAA;AAGrC;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,IAAI,GAAG;IAC7B,OAAO,EAAE,OAAO,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACpC,CAAA;AAID;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,YAAY,CAAC,WAAW,CAQxD,CAAA;AAGF;;GAEG;AAEH,eAAO,MAAM,oBAAoB,EAAE,aAAa,CAAC,WAAW,CAU1D,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { updateSettingsKeyBased } from "./api.js";
|
|
2
|
+
// TODO could also have properties, containments, references - mimicking the serialization
|
|
3
|
+
/**
|
|
4
|
+
* An implementation of {@link ReadModelAPI} for {@link DynamicNode dynamic nodes}.
|
|
5
|
+
*/
|
|
6
|
+
export const dynamicReadModelAPI = ({
|
|
7
|
+
conceptOf: (node) => node.concept,
|
|
8
|
+
getFeatureValue: (node, feature) =>
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
+
node.settings[feature.key],
|
|
11
|
+
enumerationLiteralFrom: (value, enumeration) => enumeration.literals.find(({ key }) => key === value)
|
|
12
|
+
?? null // (undefined -> null)
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* An implementation of {@link WriteModelAPI} for {@link DynamicNode dynamic nodes}.
|
|
16
|
+
*/
|
|
17
|
+
export const dynamicWriteModelAPI = ({
|
|
18
|
+
nodeFor: (_parent, concept, id, _propertySettings) => ({
|
|
19
|
+
id,
|
|
20
|
+
concept,
|
|
21
|
+
settings: {}
|
|
22
|
+
}),
|
|
23
|
+
setFeatureValue: (node, feature, value) => {
|
|
24
|
+
updateSettingsKeyBased(node.settings, feature, value);
|
|
25
|
+
},
|
|
26
|
+
encodingOf: ({ key }) => key
|
|
27
|
+
});
|
|
28
|
+
//# sourceMappingURL=dynamic-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamic-api.js","sourceRoot":"","sources":["../src/dynamic-api.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,sBAAsB,EAAgB,MAAM,UAAU,CAAA;AAW5E,2FAA2F;AAG3F;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAA8B,CAAC;IAC3D,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO;IACjC,eAAe,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE;IACvC,8DAA8D;IACrD,IAAI,CAAC,QAAgB,CAAC,OAAO,CAAC,GAAG,CAAC;IACvC,sBAAsB,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE,CAC3C,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAC,GAAG,EAAC,EAAE,EAAE,CAAC,GAAG,KAAK,KAAK,CAAC;WAChD,IAAI,CAAI,sBAAsB;CACxC,CAAC,CAAA;AAGF;;GAEG;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAA+B,CAAC;IAC7D,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,iBAAiB,EAAE,EAAE,CAAC,CAAC;QACnD,EAAE;QACF,OAAO;QACP,QAAQ,EAAE,EAAE;KACC,CAAA;IACjB,eAAe,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;QACtC,sBAAsB,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC,CAAA;IACzD,CAAC;IACD,UAAU,EAAE,CAAC,EAAC,GAAG,EAAC,EAAE,EAAE,CAAC,GAAG;CAC7B,CAAC,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Id, Node } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* @return a list of itself and the ancestors of the given {@link Node node}, in anti-chronological order.
|
|
4
|
+
*/
|
|
5
|
+
export declare const containmentChain: (node: Node) => Node[];
|
|
6
|
+
/**
|
|
7
|
+
* Maps an array of {@link Node AST nodes} to their IDs.
|
|
8
|
+
*/
|
|
9
|
+
export declare const asIds: (nodes: Node[]) => Id[];
|
|
10
|
+
//# sourceMappingURL=functions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,EAAE,EAAE,IAAI,EAAC,MAAM,YAAY,CAAA;AAInC;;GAEG;AACH,eAAO,MAAM,gBAAgB,SAAU,IAAI,KAAG,IAAI,EAGjD,CAAA;AAGD;;GAEG;AACH,eAAO,MAAM,KAAK,UAAW,IAAI,EAAE,KAAG,EAAE,EACb,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { flatMapNonCyclingFollowing, trivialFlatMapper } from "./utils/recursion.js";
|
|
2
|
+
/**
|
|
3
|
+
* @return a list of itself and the ancestors of the given {@link Node node}, in anti-chronological order.
|
|
4
|
+
*/
|
|
5
|
+
export const containmentChain = (node) => {
|
|
6
|
+
const getParent = (t) => t.parent === undefined ? [] : [t.parent];
|
|
7
|
+
return flatMapNonCyclingFollowing(trivialFlatMapper, getParent)(node);
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Maps an array of {@link Node AST nodes} to their IDs.
|
|
11
|
+
*/
|
|
12
|
+
export const asIds = (nodes) => nodes.map(({ id }) => id);
|
|
13
|
+
//# sourceMappingURL=functions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,0BAA0B,EAAE,iBAAiB,EAAC,MAAM,sBAAsB,CAAA;AAGlF;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAU,EAAU,EAAE;IACnD,MAAM,SAAS,GAAG,CAAC,CAAO,EAAU,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;IAC/E,OAAO,0BAA0B,CAAC,iBAAiB,EAAE,SAAS,CAAC,CAAC,IAAI,CAAC,CAAA;AACzE,CAAC,CAAA;AAGD;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,KAAa,EAAQ,EAAE,CACzC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAC,EAAE,EAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAA"}
|