@lionweb/utilities 0.1.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/LICENSE +201 -0
- package/dist/id-generation.d.ts +26 -0
- package/dist/id-generation.d.ts.map +1 -0
- package/dist/id-generation.js +30 -0
- package/dist/id-generation.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/json.d.ts +3 -0
- package/dist/json.d.ts.map +1 -0
- package/dist/json.js +5 -0
- package/dist/json.js.map +1 -0
- package/dist/m3/diagrams/Mermaid-generator.d.ts +7 -0
- package/dist/m3/diagrams/Mermaid-generator.d.ts.map +1 -0
- package/dist/m3/diagrams/Mermaid-generator.js +93 -0
- package/dist/m3/diagrams/Mermaid-generator.js.map +1 -0
- package/dist/m3/diagrams/PlantUML-generator.d.ts +7 -0
- package/dist/m3/diagrams/PlantUML-generator.d.ts.map +1 -0
- package/dist/m3/diagrams/PlantUML-generator.js +122 -0
- package/dist/m3/diagrams/PlantUML-generator.js.map +1 -0
- package/dist/m3/ecore/importer.d.ts +7 -0
- package/dist/m3/ecore/importer.d.ts.map +1 -0
- package/dist/m3/ecore/importer.js +101 -0
- package/dist/m3/ecore/importer.js.map +1 -0
- package/dist/m3/ecore/types.d.ts +60 -0
- package/dist/m3/ecore/types.d.ts.map +1 -0
- package/dist/m3/ecore/types.js +2 -0
- package/dist/m3/ecore/types.js.map +1 -0
- package/dist/m3/schema-generator.d.ts +7 -0
- package/dist/m3/schema-generator.d.ts.map +1 -0
- package/dist/m3/schema-generator.js +155 -0
- package/dist/m3/schema-generator.js.map +1 -0
- package/dist/serialization-utils.d.ts +12 -0
- package/dist/serialization-utils.d.ts.map +1 -0
- package/dist/serialization-utils.js +41 -0
- package/dist/serialization-utils.js.map +1 -0
- package/package.json +30 -0
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.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IdGenerator } from "@lionweb/core";
|
|
2
|
+
/**
|
|
3
|
+
* ID generator based on the {@link https://zelark.github.io/nano-id-cc/ `nanoid` NPM package}.
|
|
4
|
+
*/
|
|
5
|
+
export declare const nanoIdGen: () => IdGenerator;
|
|
6
|
+
declare const defaultHashAlgorithm = "SHA256";
|
|
7
|
+
/**
|
|
8
|
+
* Type definition for objects that configure a
|
|
9
|
+
* {@link hashingIdGen hashing ID generator}.
|
|
10
|
+
*/
|
|
11
|
+
export type HashingIdGenConfig = {
|
|
12
|
+
algorithm?: typeof defaultHashAlgorithm | string;
|
|
13
|
+
salt?: string;
|
|
14
|
+
encoding?: "base64url" | "base64";
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Creates a {@link IdGenerator hashing ID generator},
|
|
18
|
+
* optionally using a {@link HashingIdGenConfig configuration object}.
|
|
19
|
+
* The default is:
|
|
20
|
+
* - uses the *SHA256* hashing algorithm
|
|
21
|
+
* - without salt prefix string
|
|
22
|
+
* Note that the created ID generator must be given data in the form of a string (`!== undefined`).
|
|
23
|
+
*/
|
|
24
|
+
export declare const hashingIdGen: (config?: HashingIdGenConfig) => IdGenerator;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=id-generation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id-generation.d.ts","sourceRoot":"","sources":["../src/id-generation.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAA;AAGzC;;GAEG;AACH,eAAO,MAAM,SAAS,QAAO,WACX,CAAA;AAGlB,QAAA,MAAM,oBAAoB,WAAW,CAAA;AAErC;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC7B,SAAS,CAAC,EAAE,OAAO,oBAAoB,GAAG,MAAM,CAAA;IAChD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAA;CACpC,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,YAAa,kBAAkB,KAAG,WAc1D,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { nanoid } from "nanoid";
|
|
2
|
+
import { createHash } from "crypto";
|
|
3
|
+
/**
|
|
4
|
+
* ID generator based on the {@link https://zelark.github.io/nano-id-cc/ `nanoid` NPM package}.
|
|
5
|
+
*/
|
|
6
|
+
export const nanoIdGen = () => () => nanoid();
|
|
7
|
+
const defaultHashAlgorithm = "SHA256";
|
|
8
|
+
/**
|
|
9
|
+
* Creates a {@link IdGenerator hashing ID generator},
|
|
10
|
+
* optionally using a {@link HashingIdGenConfig configuration object}.
|
|
11
|
+
* The default is:
|
|
12
|
+
* - uses the *SHA256* hashing algorithm
|
|
13
|
+
* - without salt prefix string
|
|
14
|
+
* Note that the created ID generator must be given data in the form of a string (`!== undefined`).
|
|
15
|
+
*/
|
|
16
|
+
export const hashingIdGen = (config) => {
|
|
17
|
+
const algorithm = config?.algorithm ?? defaultHashAlgorithm;
|
|
18
|
+
const salt = config?.salt ?? "";
|
|
19
|
+
const encoding = config?.encoding ?? "base64url";
|
|
20
|
+
return (data) => {
|
|
21
|
+
if (data === undefined) {
|
|
22
|
+
throw new Error(`expected data for hashing`);
|
|
23
|
+
}
|
|
24
|
+
return createHash(algorithm)
|
|
25
|
+
.update(salt + data)
|
|
26
|
+
.digest(encoding)
|
|
27
|
+
.toString();
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=id-generation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id-generation.js","sourceRoot":"","sources":["../src/id-generation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,QAAQ,CAAA;AAC7B,OAAO,EAAC,UAAU,EAAC,MAAM,QAAQ,CAAA;AAKjC;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,GAAgB,EAAE,CACvC,GAAG,EAAE,CAAC,MAAM,EAAE,CAAA;AAGlB,MAAM,oBAAoB,GAAG,QAAQ,CAAA;AAYrC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAA2B,EAAe,EAAE;IACrE,MAAM,SAAS,GAAG,MAAM,EAAE,SAAS,IAAI,oBAAoB,CAAA;IAC3D,MAAM,IAAI,GAAG,MAAM,EAAE,IAAI,IAAI,EAAE,CAAA;IAC/B,MAAM,QAAQ,GAAG,MAAM,EAAE,QAAQ,IAAI,WAAW,CAAA;IAEhD,OAAO,CAAC,IAAI,EAAE,EAAE;QACZ,IAAI,IAAI,KAAK,SAAS,EAAE;YACpB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAA;SAC/C;QACD,OAAO,UAAU,CAAC,SAAS,CAAC;aACvB,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC;aACnB,MAAM,CAAC,QAAQ,CAAC;aAChB,QAAQ,EAAE,CAAA;IACnB,CAAC,CAAA;AACL,CAAC,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./m3/diagrams/Mermaid-generator.js";
|
|
2
|
+
export * from "./m3/diagrams/PlantUML-generator.js";
|
|
3
|
+
export * from "./m3/ecore/importer.js";
|
|
4
|
+
export * from "./m3/ecore/types.js";
|
|
5
|
+
export * from "./m3/schema-generator.js";
|
|
6
|
+
export * from "./id-generation.js";
|
|
7
|
+
export * from "./json.js";
|
|
8
|
+
export * from "./serialization-utils.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAA;AAClD,cAAc,qCAAqC,CAAA;AACnD,cAAc,wBAAwB,CAAA;AACtC,cAAc,qBAAqB,CAAA;AACnC,cAAc,0BAA0B,CAAA;AACxC,cAAc,oBAAoB,CAAA;AAClC,cAAc,WAAW,CAAA;AACzB,cAAc,0BAA0B,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./m3/diagrams/Mermaid-generator.js";
|
|
2
|
+
export * from "./m3/diagrams/PlantUML-generator.js";
|
|
3
|
+
export * from "./m3/ecore/importer.js";
|
|
4
|
+
export * from "./m3/ecore/types.js";
|
|
5
|
+
export * from "./m3/schema-generator.js";
|
|
6
|
+
export * from "./id-generation.js";
|
|
7
|
+
export * from "./json.js";
|
|
8
|
+
export * from "./serialization-utils.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAA;AAClD,cAAc,qCAAqC,CAAA;AACnD,cAAc,wBAAwB,CAAA;AACtC,cAAc,qBAAqB,CAAA;AACnC,cAAc,0BAA0B,CAAA;AACxC,cAAc,oBAAoB,CAAA;AAClC,cAAc,WAAW,CAAA;AACzB,cAAc,0BAA0B,CAAA"}
|
package/dist/json.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,eAAe,SAAU,MAAM,QAAQ,OAAO,SACd,CAAA;AAG7C,eAAO,MAAM,cAAc,SAAU,MAAM,KAAG,OACD,CAAA"}
|
package/dist/json.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from "fs";
|
|
2
|
+
const asPrettyString = (json) => JSON.stringify(json, null, 2);
|
|
3
|
+
export const writeJsonAsFile = (path, json) => writeFileSync(path, asPrettyString(json));
|
|
4
|
+
export const readFileAsJson = (path) => JSON.parse(readFileSync(path).toString());
|
|
5
|
+
//# sourceMappingURL=json.js.map
|
package/dist/json.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,aAAa,EAAC,MAAM,IAAI,CAAA;AAG9C,MAAM,cAAc,GAAG,CAAC,IAAa,EAAU,EAAE,CAC7C,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;AAGjC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAY,EAAE,IAAa,EAAE,EAAE,CAC3D,aAAa,CAAC,IAAI,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC,CAAA;AAG7C,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAAY,EAAW,EAAE,CACpD,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Language } from "@lionweb/core";
|
|
2
|
+
/**
|
|
3
|
+
* Generates a string with a Mermaid class diagram
|
|
4
|
+
* representing the given {@link Language LionCore instance}.
|
|
5
|
+
*/
|
|
6
|
+
export declare const generateMermaidForLanguage: ({ entities }: Language) => string;
|
|
7
|
+
//# sourceMappingURL=Mermaid-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Mermaid-generator.d.ts","sourceRoot":"","sources":["../../../src/m3/diagrams/Mermaid-generator.ts"],"names":[],"mappings":"AACA,OAAO,EAQH,QAAQ,EAQX,MAAM,eAAe,CAAA;AAuBtB;;;GAGG;AACH,eAAO,MAAM,0BAA0B,iBAAgB,QAAQ,WAWzD,CAAA"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { asString, indentWith } from "littoral-templates";
|
|
2
|
+
import { Concept, ConceptInterface, Containment, entitiesSortedByName, Enumeration, isRef, Link, nonRelationalFeatures, PrimitiveType, relationsOf, type, unresolved } from "@lionweb/core";
|
|
3
|
+
// define some layouting basics/building algebra:
|
|
4
|
+
const indented = indentWith(` `)(1);
|
|
5
|
+
const block = (header, elements) => elements.length === 0
|
|
6
|
+
? header
|
|
7
|
+
: [
|
|
8
|
+
`${header} {`,
|
|
9
|
+
indented(elements),
|
|
10
|
+
`}`
|
|
11
|
+
];
|
|
12
|
+
const withNewLine = (content) => [
|
|
13
|
+
content,
|
|
14
|
+
``
|
|
15
|
+
];
|
|
16
|
+
/**
|
|
17
|
+
* Generates a string with a Mermaid class diagram
|
|
18
|
+
* representing the given {@link Language LionCore instance}.
|
|
19
|
+
*/
|
|
20
|
+
export const generateMermaidForLanguage = ({ entities }) => asString([
|
|
21
|
+
"```mermaid",
|
|
22
|
+
`classDiagram
|
|
23
|
+
|
|
24
|
+
`,
|
|
25
|
+
indented(entitiesSortedByName(entities).map(generateForElement)),
|
|
26
|
+
``,
|
|
27
|
+
indented(entitiesSortedByName(entities).map(generateForRelationsOf)),
|
|
28
|
+
``,
|
|
29
|
+
"```"
|
|
30
|
+
]);
|
|
31
|
+
const generateForEnumeration = ({ name, literals }) => withNewLine(block(`class ${name}`, [
|
|
32
|
+
`<<enumeration>>`,
|
|
33
|
+
literals.map(({ name }) => name)
|
|
34
|
+
]));
|
|
35
|
+
const generateForConcept = ({ name, features, abstract: abstract_, extends: extends_ /*, implements: implements_*/, partition }) => [
|
|
36
|
+
block(`class ${partition ? `<<partition>> ` : ``}${name}`, nonRelationalFeatures(features).map(generateForNonRelationalFeature)),
|
|
37
|
+
abstract_ ? `<<Abstract>> ${name}` : [],
|
|
38
|
+
isRef(extends_) ? `${extends_.name} <|-- ${name}` : [],
|
|
39
|
+
``
|
|
40
|
+
];
|
|
41
|
+
const generateForConceptInterface = ({ name, features, extends: extends_ }) => [
|
|
42
|
+
block(`class ${name}`, nonRelationalFeatures(features).map(generateForNonRelationalFeature)),
|
|
43
|
+
`<<Interface>> ${name}`,
|
|
44
|
+
extends_.map(({ name: extendsName }) => `${extendsName} <|-- ${name}`),
|
|
45
|
+
``
|
|
46
|
+
];
|
|
47
|
+
const generateForNonRelationalFeature = (feature) => {
|
|
48
|
+
const { name, optional } = feature;
|
|
49
|
+
const multiple = feature instanceof Link && feature.multiple;
|
|
50
|
+
const type_ = type(feature);
|
|
51
|
+
const typeText = `${multiple ? `List~` : ``}${type_ === unresolved ? `???` : type_.name}${multiple ? `~` : ``}${optional ? `?` : ``}`;
|
|
52
|
+
return `+${typeText} ${name}`;
|
|
53
|
+
};
|
|
54
|
+
const generateForPrimitiveType = ({ name }) => `%% primitive type: "${name}"
|
|
55
|
+
|
|
56
|
+
`;
|
|
57
|
+
// Note: No construct for PrimitiveType exists in PlantUML.
|
|
58
|
+
const generateForElement = (element) => {
|
|
59
|
+
if (element instanceof Concept) {
|
|
60
|
+
return generateForConcept(element);
|
|
61
|
+
}
|
|
62
|
+
if (element instanceof ConceptInterface) {
|
|
63
|
+
return generateForConceptInterface(element);
|
|
64
|
+
}
|
|
65
|
+
if (element instanceof Enumeration) {
|
|
66
|
+
return generateForEnumeration(element);
|
|
67
|
+
}
|
|
68
|
+
if (element instanceof PrimitiveType) {
|
|
69
|
+
return generateForPrimitiveType(element);
|
|
70
|
+
}
|
|
71
|
+
return `// unhandled metamodel element: ${element.name}`;
|
|
72
|
+
};
|
|
73
|
+
const generateForRelationsOf = (element) => {
|
|
74
|
+
const relations = relationsOf(element);
|
|
75
|
+
return relations.length === 0
|
|
76
|
+
? ``
|
|
77
|
+
: relations
|
|
78
|
+
.map((relation) => generateForRelation(element, relation));
|
|
79
|
+
};
|
|
80
|
+
const generateForRelation = ({ name: leftName }, relation) => {
|
|
81
|
+
const { name: relationName, optional, multiple, type } = relation;
|
|
82
|
+
const rightName = isRef(type) ? type.name : (type === unresolved ? `<unresolved>` : `<null>`);
|
|
83
|
+
const isContainment = relation instanceof Containment;
|
|
84
|
+
const leftMultiplicity = isContainment ? `1` : `*`;
|
|
85
|
+
const rightMultiplicity = (() => {
|
|
86
|
+
if (multiple) {
|
|
87
|
+
return "*";
|
|
88
|
+
}
|
|
89
|
+
return optional ? "0..1" : "1";
|
|
90
|
+
})();
|
|
91
|
+
return `${leftName} "${leftMultiplicity}" ${isContainment ? `o` : ``}-- "${rightMultiplicity}" ${rightName}: ${relationName}`;
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=Mermaid-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Mermaid-generator.js","sourceRoot":"","sources":["../../../src/m3/diagrams/Mermaid-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,UAAU,EAAe,MAAM,oBAAoB,CAAA;AACrE,OAAO,EACH,OAAO,EACP,gBAAgB,EAChB,WAAW,EACX,oBAAoB,EACpB,WAAW,EAEX,KAAK,EAGL,IAAI,EACJ,qBAAqB,EACrB,aAAa,EACb,WAAW,EACX,IAAI,EACJ,UAAU,EACb,MAAM,eAAe,CAAA;AAGtB,iDAAiD;AAEjD,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;AAEpC,MAAM,KAAK,GAAG,CAAC,MAAc,EAAE,QAAsB,EAAgB,EAAE,CACnE,QAAQ,CAAC,MAAM,KAAK,CAAC;IACjB,CAAC,CAAC,MAAM;IACR,CAAC,CAAC;QACE,GAAG,MAAM,IAAI;QACb,QAAQ,CAAC,QAAQ,CAAC;QAClB,GAAG;KACN,CAAA;AAET,MAAM,WAAW,GAAG,CAAC,OAAqB,EAA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CAAA;SACb;QACD,OAAO,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAA;IAClC,CAAC,CAAC,EAAE,CAAA;IACJ,OAAO,GAAG,QAAQ,KAAK,gBAAgB,KAAK,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,OAAO,iBAAiB,KAAK,SAAS,KAAK,YAAY,EAAE,CAAA;AACjI,CAAC,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Language } from "@lionweb/core";
|
|
2
|
+
/**
|
|
3
|
+
* Generates a string with a PlantUML class diagram
|
|
4
|
+
* representing the given {@link Language LionCore instance}.
|
|
5
|
+
*/
|
|
6
|
+
export declare const generatePlantUmlForLanguage: ({ name, entities }: Language) => string;
|
|
7
|
+
//# sourceMappingURL=PlantUML-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlantUML-generator.d.ts","sourceRoot":"","sources":["../../../src/m3/diagrams/PlantUML-generator.ts"],"names":[],"mappings":"AACA,OAAO,EAQH,QAAQ,EAQX,MAAM,eAAe,CAAA;AAMtB;;;GAGG;AACH,eAAO,MAAM,2BAA2B,uBAAsB,QAAQ,WAmBpE,CAAA"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { asString, indentWith } from "littoral-templates";
|
|
2
|
+
import { Concept, ConceptInterface, Containment, entitiesSortedByName, Enumeration, isRef, Link, nonRelationalFeatures, PrimitiveType, relationsOf, type, unresolved } from "@lionweb/core";
|
|
3
|
+
const indented = indentWith(` `)(1);
|
|
4
|
+
/**
|
|
5
|
+
* Generates a string with a PlantUML class diagram
|
|
6
|
+
* representing the given {@link Language LionCore instance}.
|
|
7
|
+
*/
|
|
8
|
+
export const generatePlantUmlForLanguage = ({ name, entities }) => asString([
|
|
9
|
+
`@startuml
|
|
10
|
+
hide empty members
|
|
11
|
+
|
|
12
|
+
' qualified name: "${name}"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
`,
|
|
16
|
+
entitiesSortedByName(entities).map(generateForElement),
|
|
17
|
+
`
|
|
18
|
+
|
|
19
|
+
' relations:
|
|
20
|
+
|
|
21
|
+
`,
|
|
22
|
+
entitiesSortedByName(entities).map(generateForRelationsOf),
|
|
23
|
+
`
|
|
24
|
+
@enduml
|
|
25
|
+
`
|
|
26
|
+
]);
|
|
27
|
+
const generateForEnumeration = ({ name, literals }) => [
|
|
28
|
+
`enum ${name} {`,
|
|
29
|
+
indented(literals.map(({ name }) => name)),
|
|
30
|
+
`}
|
|
31
|
+
|
|
32
|
+
`
|
|
33
|
+
];
|
|
34
|
+
const generateForConcept = ({ name, features, abstract: abstract_, extends: extends_, implements: implements_, partition }) => {
|
|
35
|
+
const nonRelationalFeatures_ = nonRelationalFeatures(features);
|
|
36
|
+
const fragments = [];
|
|
37
|
+
if (abstract_) {
|
|
38
|
+
fragments.push(`abstract`);
|
|
39
|
+
}
|
|
40
|
+
fragments.push(`class`, name);
|
|
41
|
+
if (partition) {
|
|
42
|
+
fragments.push(`<<partition>>`);
|
|
43
|
+
}
|
|
44
|
+
if (isRef(extends_)) {
|
|
45
|
+
fragments.push(`extends`, extends_.name);
|
|
46
|
+
}
|
|
47
|
+
if (implements_.length > 0) {
|
|
48
|
+
fragments.push(`implements`, implements_.map((conceptInterface) => conceptInterface.name).sort().join(", "));
|
|
49
|
+
}
|
|
50
|
+
return nonRelationalFeatures_.length === 0
|
|
51
|
+
? [
|
|
52
|
+
`${fragments.join(" ")}`,
|
|
53
|
+
``
|
|
54
|
+
]
|
|
55
|
+
: [
|
|
56
|
+
`${fragments.join(" ")} {`,
|
|
57
|
+
indented(nonRelationalFeatures_.map(generateForNonRelationalFeature)),
|
|
58
|
+
`}`,
|
|
59
|
+
``
|
|
60
|
+
];
|
|
61
|
+
};
|
|
62
|
+
const generateForConceptInterface = ({ name, extends: extends_, features }) => {
|
|
63
|
+
const nonRelationalFeatures_ = nonRelationalFeatures(features);
|
|
64
|
+
const fragments = [`interface`, name];
|
|
65
|
+
if (extends_.length > 0) {
|
|
66
|
+
fragments.push(`extends`, extends_.map((superInterface) => superInterface.name).join(", "));
|
|
67
|
+
}
|
|
68
|
+
return nonRelationalFeatures_.length === 0
|
|
69
|
+
? `${fragments.join(" ")}`
|
|
70
|
+
: [
|
|
71
|
+
`${fragments.join(" ")} {`,
|
|
72
|
+
indented(nonRelationalFeatures_.map(generateForNonRelationalFeature)),
|
|
73
|
+
`}`,
|
|
74
|
+
``
|
|
75
|
+
];
|
|
76
|
+
};
|
|
77
|
+
const generateForNonRelationalFeature = (feature) => {
|
|
78
|
+
const { name, optional } = feature;
|
|
79
|
+
const multiple = feature instanceof Link && feature.multiple;
|
|
80
|
+
const type_ = type(feature);
|
|
81
|
+
return `${name}: ${multiple ? `List<` : ``}${type_ === unresolved ? `???` : type_.name}${multiple ? `>` : ``}${(optional && !multiple) ? ` <<optional>>` : ``}`;
|
|
82
|
+
};
|
|
83
|
+
const generateForPrimitiveType = ({ name }) => `' primitive type: "${name}"
|
|
84
|
+
|
|
85
|
+
`;
|
|
86
|
+
// Note: No construct for PrimitiveType exists in PlantUML.
|
|
87
|
+
const generateForElement = (element) => {
|
|
88
|
+
if (element instanceof Enumeration) {
|
|
89
|
+
return generateForEnumeration(element);
|
|
90
|
+
}
|
|
91
|
+
if (element instanceof Concept) {
|
|
92
|
+
return generateForConcept(element);
|
|
93
|
+
}
|
|
94
|
+
if (element instanceof ConceptInterface) {
|
|
95
|
+
return generateForConceptInterface(element);
|
|
96
|
+
}
|
|
97
|
+
if (element instanceof PrimitiveType) {
|
|
98
|
+
return generateForPrimitiveType(element);
|
|
99
|
+
}
|
|
100
|
+
return `' unhandled metamodel element: ${element.name}
|
|
101
|
+
`;
|
|
102
|
+
};
|
|
103
|
+
const generateForRelationsOf = (element) => {
|
|
104
|
+
const relations = relationsOf(element);
|
|
105
|
+
return relations.length === 0
|
|
106
|
+
? ``
|
|
107
|
+
: relations
|
|
108
|
+
.map((relation) => generateForRelation(element, relation));
|
|
109
|
+
};
|
|
110
|
+
const generateForRelation = ({ name: leftName }, relation) => {
|
|
111
|
+
const { name: relationName, type, optional, multiple } = relation;
|
|
112
|
+
const rightName = isRef(type) ? type.name : (type === unresolved ? `<unresolved>` : `<null>`);
|
|
113
|
+
const isContainment = relation instanceof Containment;
|
|
114
|
+
const leftMultiplicity = isContainment ? `1` : `*`;
|
|
115
|
+
const rightMultiplicity = multiple ? "*" : (optional ? "0..1" : "1");
|
|
116
|
+
return `${leftName} "${leftMultiplicity}" ${isContainment ? `o` : ``}-- "${rightMultiplicity}" ${rightName}: ${relationName}`;
|
|
117
|
+
};
|
|
118
|
+
/*
|
|
119
|
+
Notes:
|
|
120
|
+
1. No construct for PrimitiveType in PlantUML.
|
|
121
|
+
*/
|
|
122
|
+
//# sourceMappingURL=PlantUML-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlantUML-generator.js","sourceRoot":"","sources":["../../../src/m3/diagrams/PlantUML-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,UAAU,EAAC,MAAM,oBAAoB,CAAA;AACvD,OAAO,EACH,OAAO,EACP,gBAAgB,EAChB,WAAW,EACX,oBAAoB,EACpB,WAAW,EAEX,KAAK,EAGL,IAAI,EACJ,qBAAqB,EACrB,aAAa,EACb,WAAW,EACX,IAAI,EACJ,UAAU,EACb,MAAM,eAAe,CAAA;AAGtB,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;AAGpC;;;GAGG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,EAAC,IAAI,EAAE,QAAQ,EAAW,EAAE,EAAE,CACtE,QAAQ,CAAC;IACb;;;qBAGqB,IAAI;;;CAGxB;IACG,oBAAoB,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,kBAAkB,CAAC;IAC1D;;;;CAIC;IACG,oBAAoB,CA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ACtE,CAAC,CAAA;AAGD,MAAM,mBAAmB,GAAG,CAAC,EAAC,IAAI,EAAE,QAAQ,EAAiB,EAAE,QAAc,EAAE,EAAE;IAC7E,MAAM,EAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAC,GAAG,QAAQ,CAAA;IAC/D,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAA;IAC7F,MAAM,aAAa,GAAG,QAAQ,YAAY,WAAW,CAAA;IACrD,MAAM,gBAAgB,GAAG,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAA;IAClD,MAAM,iBAAiB,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;IACpE,OAAO,GAAG,QAAQ,KAAK,gBAAgB,KAAK,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,OAAO,iBAAiB,KAAK,SAAS,KAAK,YAAY,EAAE,CAAA;AACjI,CAAC,CAAA;AAGD;;;GAGG"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Language } from "@lionweb/core";
|
|
2
|
+
import { EcoreXml } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Converts a parsed Ecore XML metamodel (file) to a {@link Language LionCore instance}.
|
|
5
|
+
*/
|
|
6
|
+
export declare const asLionCoreLanguage: (ecoreXml: EcoreXml, version: string) => Language;
|
|
7
|
+
//# sourceMappingURL=importer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importer.d.ts","sourceRoot":"","sources":["../../../src/m3/ecore/importer.ts"],"names":[],"mappings":"AAAA,OAAO,EAaH,QAAQ,EAOX,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAsB,QAAQ,EAA4B,MAAM,YAAY,CAAA;AAuBnF;;GAEG;AACH,eAAO,MAAM,kBAAkB,aAAc,QAAQ,WAAW,MAAM,KAAG,QAwHxE,CAAA"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { asArray, builtinPrimitives, checkDefinedData, checkUniqueData, checkUniqueId, checkValidId, duplicatesAmong, keyOf, LanguageFactory, namedsOf, qualifiedNameOf, wrapIdGen } from "@lionweb/core";
|
|
2
|
+
import { hashingIdGen } from "../../id-generation.js";
|
|
3
|
+
const localRefPrefix = "#//";
|
|
4
|
+
/**
|
|
5
|
+
* "Dereferences" a type descriptor string by removing the optional <pre>"#//"</pre> prefix.
|
|
6
|
+
*/
|
|
7
|
+
const deref = (typeDescriptor) => typeDescriptor.startsWith(localRefPrefix)
|
|
8
|
+
? typeDescriptor.substring(localRefPrefix.length)
|
|
9
|
+
: typeDescriptor;
|
|
10
|
+
const { booleanDatatype, integerDatatype, stringDatatype } = builtinPrimitives;
|
|
11
|
+
const typeDesc2primitiveType = {
|
|
12
|
+
"ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString": stringDatatype,
|
|
13
|
+
"ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String": stringDatatype,
|
|
14
|
+
"ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//Boolean": booleanDatatype,
|
|
15
|
+
"ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//Int": integerDatatype
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Converts a parsed Ecore XML metamodel (file) to a {@link Language LionCore instance}.
|
|
19
|
+
*/
|
|
20
|
+
export const asLionCoreLanguage = (ecoreXml, version) => {
|
|
21
|
+
const ePackage = ecoreXml["ecore:EPackage"];
|
|
22
|
+
// TODO (#10) an Ecore XML can contain multiple EPackage-s
|
|
23
|
+
const factory = new LanguageFactory(ePackage["$"]["name"], version, wrapIdGen(hashingIdGen(), checkDefinedData, checkUniqueData, checkValidId, checkUniqueId));
|
|
24
|
+
// phase 1: convert EClassifiers but without their EStructuralFeatures (in the case of EClasses)
|
|
25
|
+
const convertEClassifier = (eClassifier) => {
|
|
26
|
+
const xsiType = eClassifier["$"]["xsi:type"];
|
|
27
|
+
if (xsiType === "ecore:EClass") {
|
|
28
|
+
return factory.concept(eClassifier["$"]["name"], false);
|
|
29
|
+
}
|
|
30
|
+
if (xsiType === "ecore:EEnum") {
|
|
31
|
+
return factory.enumeration(eClassifier["$"]["name"]);
|
|
32
|
+
}
|
|
33
|
+
throw new Error(`don't know how to convert an EClassifier with descriptor "${xsiType}"`);
|
|
34
|
+
};
|
|
35
|
+
// TODO (#10) ConceptInterface?
|
|
36
|
+
const convertedEClassifiers = ePackage["eClassifiers"]
|
|
37
|
+
.map((eClassifier) => [eClassifier, convertEClassifier(eClassifier)]);
|
|
38
|
+
const eClassifierConversionFor = (eClassifierName) => convertedEClassifiers
|
|
39
|
+
.find(([source, _]) => source["$"]["name"] === eClassifierName)[1];
|
|
40
|
+
// phase 2: also convert features of EClasses
|
|
41
|
+
const convertEStructuralFeature = (container, feature) => {
|
|
42
|
+
const metaType = feature["$"]["xsi:type"];
|
|
43
|
+
const name = feature["$"]["name"];
|
|
44
|
+
switch (metaType) {
|
|
45
|
+
case "ecore:EAttribute": {
|
|
46
|
+
const typeDesc = feature["$"]["eType"];
|
|
47
|
+
const property = factory.property(container, name)
|
|
48
|
+
.ofType(typeDesc in typeDesc2primitiveType
|
|
49
|
+
? typeDesc2primitiveType[typeDesc]
|
|
50
|
+
: eClassifierConversionFor(deref(typeDesc)));
|
|
51
|
+
if (feature["$"]["lowerBound"] === "0") {
|
|
52
|
+
property.isOptional();
|
|
53
|
+
}
|
|
54
|
+
return property;
|
|
55
|
+
}
|
|
56
|
+
case "ecore:EReference": {
|
|
57
|
+
const link = (feature["$"]["containment"]
|
|
58
|
+
? factory.containment(container, name)
|
|
59
|
+
: factory.reference(container, name))
|
|
60
|
+
.ofType(eClassifierConversionFor(deref(feature["$"]["eType"])));
|
|
61
|
+
if (feature["$"]["lowerBound"] === "0") {
|
|
62
|
+
link.isOptional();
|
|
63
|
+
}
|
|
64
|
+
if (feature["$"]["upperBound"] === "-1") {
|
|
65
|
+
link.isMultiple();
|
|
66
|
+
}
|
|
67
|
+
return link;
|
|
68
|
+
}
|
|
69
|
+
default:
|
|
70
|
+
throw new Error(`feature of meta type ${metaType} not handled`);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
convertedEClassifiers.forEach(([source, target]) => {
|
|
74
|
+
const xsiType = source["$"]["xsi:type"];
|
|
75
|
+
if (xsiType === "ecore:EClass") {
|
|
76
|
+
const classifier = target;
|
|
77
|
+
classifier
|
|
78
|
+
.havingFeatures(...asArray(source.eStructuralFeatures)
|
|
79
|
+
.map((feature) => convertEStructuralFeature(classifier, feature)));
|
|
80
|
+
if (source["$"]["eSuperTypes"] !== undefined) {
|
|
81
|
+
target.extends = eClassifierConversionFor(deref(source["$"]["eSuperTypes"]));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (xsiType === "ecore:EEnum") {
|
|
85
|
+
const classifier = target;
|
|
86
|
+
classifier
|
|
87
|
+
.havingLiterals(...asArray(source.eLiterals)
|
|
88
|
+
.map((literal) => factory.enumerationLiteral(classifier, literal["$"]["name"])));
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
// phase 3: put all converted things into the metamodel
|
|
92
|
+
factory.language
|
|
93
|
+
.havingEntities(...convertedEClassifiers.map(([_, mmElement]) => mmElement));
|
|
94
|
+
// phase 4: dedup keys (crudely, using the qualified name) where necessary
|
|
95
|
+
Object.entries(duplicatesAmong(namedsOf(factory.language), keyOf))
|
|
96
|
+
.forEach(([_, mmElements]) => {
|
|
97
|
+
mmElements.forEach((mmElement) => mmElement.havingKey(qualifiedNameOf(mmElement, "_")));
|
|
98
|
+
});
|
|
99
|
+
return factory.language;
|
|
100
|
+
};
|
|
101
|
+
//# sourceMappingURL=importer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importer.js","sourceRoot":"","sources":["../../../src/m3/ecore/importer.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,OAAO,EACP,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,YAAY,EAGZ,eAAe,EAGf,KAAK,EAGL,eAAe,EACf,QAAQ,EAER,eAAe,EACf,SAAS,EACZ,MAAM,eAAe,CAAA;AACtB,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAA;AAInD,MAAM,cAAc,GAAG,KAAK,CAAA;AAC5B;;GAEG;AACH,MAAM,KAAK,GAAG,CAAC,cAAsB,EAAU,EAAE,CAC7C,cAAc,CAAC,UAAU,CAAC,cAAc,CAAC;IACrC,CAAC,CAAC,cAAc,CAAC,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC;IACjD,CAAC,CAAC,cAAc,CAAA;AAGxB,MAAM,EAAC,eAAe,EAAE,eAAe,EAAE,cAAc,EAAC,GAAG,iBAAiB,CAAA;AAE5E,MAAM,sBAAsB,GAAkC;IAC1D,iEAAiE,EAAE,cAAc;IACjF,kEAAkE,EAAE,cAAc;IAClF,mEAAmE,EAAE,eAAe;IACpF,+DAA+D,EAAE,eAAe;CACnF,CAAA;AAGD;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,QAAkB,EAAE,OAAe,EAAY,EAAE;IAEhF,MAAM,QAAQ,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CAAA;IAC3C,2DAA2D;IAC3D,MAAM,OAAO,GAAG,IAAI,eAAe,CAC/B,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,EACrB,OAAO,EACP,SAAS,CACL,YAAY,EAAE,EACd,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,aAAa,CAChB,CACJ,CAAA;IAG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EAAE,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,eAAe,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC,CAAA;IAC3F,CAAC,CAAC,CAAA;IAEN,OAAO,OAAO,CAAC,QAAQ,CAAA;AAC3B,CAAC,CAAA"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { AnyNumberOf } from "@lionweb/core";
|
|
2
|
+
/**
|
|
3
|
+
* Type definitions that correspond to an Ecore XML metamodel (file),
|
|
4
|
+
* parsed using the <tt>xml2js</tt> XML parser library
|
|
5
|
+
* (or with a parser exactly compatible with that.)
|
|
6
|
+
*
|
|
7
|
+
* For completeness' sake, the required code could look as follows:
|
|
8
|
+
* ```ts
|
|
9
|
+
* import {parseString} from "xml2js"
|
|
10
|
+
*
|
|
11
|
+
* parseString(data, (err, ecoreXml) => {
|
|
12
|
+
* const language = asLionCoreLanguage(ecoreXml as EcoreXml, "1")
|
|
13
|
+
* })
|
|
14
|
+
* ```
|
|
15
|
+
* (It's assumed that {@link EcoreXml} is already imported.)
|
|
16
|
+
*/
|
|
17
|
+
export type ENamed = {
|
|
18
|
+
"$": {
|
|
19
|
+
"name": string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export type EcoreXml = {
|
|
23
|
+
"ecore:EPackage": EcorePackage;
|
|
24
|
+
};
|
|
25
|
+
export type EcorePackage = ENamed & {
|
|
26
|
+
"eClassifiers": EClassifier[];
|
|
27
|
+
};
|
|
28
|
+
export type EClassifier = EClass | EEnum;
|
|
29
|
+
export type EClass = ENamed & {
|
|
30
|
+
"$": {
|
|
31
|
+
"xsi:type": "ecore:EClass";
|
|
32
|
+
"eSuperTypes"?: string;
|
|
33
|
+
};
|
|
34
|
+
"eStructuralFeatures"?: AnyNumberOf<EStructuralFeature>;
|
|
35
|
+
};
|
|
36
|
+
export type EStructuralFeature = EAttribute | EReference;
|
|
37
|
+
export type EAttribute = ENamed & {
|
|
38
|
+
"$": {
|
|
39
|
+
"xsi:type": "ecore:EAttribute";
|
|
40
|
+
"lowerBound": string;
|
|
41
|
+
"eType": string;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export type EReference = ENamed & {
|
|
45
|
+
"$": {
|
|
46
|
+
"xsi:type": "ecore:EReference";
|
|
47
|
+
"lowerBound"?: string;
|
|
48
|
+
"upperBound": string;
|
|
49
|
+
"eType": string;
|
|
50
|
+
"containment"?: boolean;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
export type EEnum = ENamed & {
|
|
54
|
+
"$": {
|
|
55
|
+
"xsi:type": "ecore:EEnum";
|
|
56
|
+
};
|
|
57
|
+
"eLiterals"?: AnyNumberOf<EEnumLiteral>;
|
|
58
|
+
};
|
|
59
|
+
export type EEnumLiteral = ENamed;
|
|
60
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/m3/ecore/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAA;AAGzC;;;;;;;;;;;;;;GAcG;AAEH,MAAM,MAAM,MAAM,GAAG;IACjB,GAAG,EAAE;QACD,MAAM,EAAE,MAAM,CAAA;KACjB,CAAA;CACJ,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG;IACnB,gBAAgB,EAAE,YAAY,CAAA;CACjC,CAAA;AAED,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG;IAChC,cAAc,EAAE,WAAW,EAAE,CAAA;CAChC,CAAA;AAED,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,KAAK,CAAA;AAExC,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG;IAC1B,GAAG,EAAE;QACD,UAAU,EAAE,cAAc,CAAA;QAC1B,aAAa,CAAC,EAAE,MAAM,CAAA;KACzB,CAAA;IACD,qBAAqB,CAAC,EAAE,WAAW,CAAC,kBAAkB,CAAC,CAAA;CAC1D,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG,UAAU,GAAG,UAAU,CAAA;AAExD,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG;IAC9B,GAAG,EAAE;QACD,UAAU,EAAE,kBAAkB,CAAA;QAC9B,YAAY,EAAE,MAAM,CAAA;QACpB,OAAO,EAAE,MAAM,CAAA;KAClB,CAAA;CACJ,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG;IAC9B,GAAG,EAAE;QACD,UAAU,EAAE,kBAAkB,CAAA;QAC9B,YAAY,CAAC,EAAE,MAAM,CAAA;QACrB,YAAY,EAAE,MAAM,CAAA;QACpB,OAAO,EAAE,MAAM,CAAA;QACf,aAAa,CAAC,EAAE,OAAO,CAAA;KAC1B,CAAA;CACJ,CAAA;AAED,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG;IACzB,GAAG,EAAE;QACD,UAAU,EAAE,aAAa,CAAA;KAC5B,CAAA;IACD,WAAW,CAAC,EAAE,WAAW,CAAC,YAAY,CAAC,CAAA;CAC1C,CAAA;AAED,MAAM,MAAM,YAAY,GAAG,MAAM,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/m3/ecore/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Language } from "@lionweb/core";
|
|
2
|
+
/**
|
|
3
|
+
* Generates a JSON Schema for the LionWeb-compliant serialization JSON format
|
|
4
|
+
* specific to the (metamodel in/of the) given language.
|
|
5
|
+
*/
|
|
6
|
+
export declare const schemaFor: (language: Language) => unknown;
|
|
7
|
+
//# sourceMappingURL=schema-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-generator.d.ts","sourceRoot":"","sources":["../../src/m3/schema-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAYH,QAAQ,EAGX,MAAM,eAAe,CAAA;AAyFtB;;;GAGG;AACH,eAAO,MAAM,SAAS,aAAc,QAAQ,KAAG,OAgF9C,CAAA"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { allFeaturesOf, Enumeration, isConcrete, isContainment, isEnumeration, isProperty, isRef, isReference, PrimitiveType } from "@lionweb/core";
|
|
2
|
+
// TODO import types for JSON Schema for added type-safety?
|
|
3
|
+
const ref = (id) => ({ $ref: `#/$defs/${id}` });
|
|
4
|
+
const isString = () => ({ type: "string" });
|
|
5
|
+
const asJSONSchemaType = (dataType) => {
|
|
6
|
+
if (dataType instanceof Enumeration) {
|
|
7
|
+
return ref(dataType.key);
|
|
8
|
+
}
|
|
9
|
+
if (dataType instanceof PrimitiveType) {
|
|
10
|
+
// (TODO use equality on the level of PrimitiveType instances (but builtins is not a singleton))
|
|
11
|
+
switch (dataType.name) {
|
|
12
|
+
case "String":
|
|
13
|
+
case "Boolean":
|
|
14
|
+
case "Integer":
|
|
15
|
+
case "JSON": return isString();
|
|
16
|
+
default:
|
|
17
|
+
throw new Error(`can't deal with PrimitiveType "${dataType.name}"`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
throw new Error(`can't handle Datatype instance: ${dataType}`);
|
|
21
|
+
};
|
|
22
|
+
const schemaForFeatures = (features, mapFeature, specifyRequireds) => {
|
|
23
|
+
const requireds = features.filter(({ optional }) => !optional);
|
|
24
|
+
return {
|
|
25
|
+
type: "array",
|
|
26
|
+
items: {
|
|
27
|
+
// FIXME what here?
|
|
28
|
+
},
|
|
29
|
+
properties: Object.fromEntries(features
|
|
30
|
+
.map((feature) => [
|
|
31
|
+
feature.key,
|
|
32
|
+
mapFeature(feature)
|
|
33
|
+
])),
|
|
34
|
+
required: specifyRequireds && requireds.length > 0
|
|
35
|
+
? requireds.map(({ key }) => key)
|
|
36
|
+
: undefined,
|
|
37
|
+
additionalProperties: false
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
const schemaForProperty = (property) => isRef(property.type)
|
|
41
|
+
? asJSONSchemaType(property.type)
|
|
42
|
+
: {}; // "any"
|
|
43
|
+
const schemaForConcept = (concept) => {
|
|
44
|
+
const allFeatures = allFeaturesOf(concept);
|
|
45
|
+
return {
|
|
46
|
+
type: "object",
|
|
47
|
+
properties: {
|
|
48
|
+
id: ref("Id"),
|
|
49
|
+
concept: {
|
|
50
|
+
const: {
|
|
51
|
+
metamodel: "LionCore_M3",
|
|
52
|
+
version: "1",
|
|
53
|
+
key: concept.key
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
properties: schemaForFeatures(allFeatures.filter(isProperty), schemaForProperty, true),
|
|
57
|
+
children: schemaForFeatures(allFeatures.filter(isContainment), (_) => ref("Ids"), true),
|
|
58
|
+
references: schemaForFeatures(allFeatures.filter(isReference), (_) => ref("Ids"), false),
|
|
59
|
+
parent: ref("ParentId")
|
|
60
|
+
},
|
|
61
|
+
required: [
|
|
62
|
+
"id",
|
|
63
|
+
"concept",
|
|
64
|
+
"properties",
|
|
65
|
+
"children",
|
|
66
|
+
"references"
|
|
67
|
+
],
|
|
68
|
+
additionalProperties: false
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
const schemaForEnumeration = ({ literals }) => ({
|
|
72
|
+
enum: literals.map(({ name }) => name)
|
|
73
|
+
});
|
|
74
|
+
/**
|
|
75
|
+
* Generates a JSON Schema for the LionWeb-compliant serialization JSON format
|
|
76
|
+
* specific to the (metamodel in/of the) given language.
|
|
77
|
+
*/
|
|
78
|
+
export const schemaFor = (language) => {
|
|
79
|
+
const concreteConcepts = language.entities.filter(isConcrete);
|
|
80
|
+
const enumerations = language.entities.filter(isEnumeration);
|
|
81
|
+
return {
|
|
82
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
83
|
+
$id: `${language.name}-serialization`,
|
|
84
|
+
title: `Serialization format specific to ${language.name}`,
|
|
85
|
+
...ref("SerializedModel"),
|
|
86
|
+
$defs: {
|
|
87
|
+
// TODO (#34) put the static definitions in a separate, referred-to JSON Schema
|
|
88
|
+
"SerializedModel": {
|
|
89
|
+
type: "object",
|
|
90
|
+
properties: {
|
|
91
|
+
serializationFormatVersion: {
|
|
92
|
+
const: "1"
|
|
93
|
+
},
|
|
94
|
+
languages: {
|
|
95
|
+
const: []
|
|
96
|
+
},
|
|
97
|
+
nodes: {
|
|
98
|
+
type: "array",
|
|
99
|
+
items: ref("SerializedNode")
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
required: [
|
|
103
|
+
"serializationFormatVersion",
|
|
104
|
+
"languages",
|
|
105
|
+
"nodes"
|
|
106
|
+
],
|
|
107
|
+
additionalProperties: false
|
|
108
|
+
},
|
|
109
|
+
"Id": {
|
|
110
|
+
type: "string",
|
|
111
|
+
minLength: 1
|
|
112
|
+
},
|
|
113
|
+
"Ids": {
|
|
114
|
+
type: "array",
|
|
115
|
+
items: ref("Id"),
|
|
116
|
+
minItems: 1 // because empties are not allowed
|
|
117
|
+
},
|
|
118
|
+
"MetaPointer": {
|
|
119
|
+
type: "object",
|
|
120
|
+
properties: {
|
|
121
|
+
"language": isString(),
|
|
122
|
+
"version": isString(),
|
|
123
|
+
"key": isString()
|
|
124
|
+
},
|
|
125
|
+
required: [
|
|
126
|
+
"language",
|
|
127
|
+
"version",
|
|
128
|
+
"key"
|
|
129
|
+
],
|
|
130
|
+
additionalProperties: false
|
|
131
|
+
},
|
|
132
|
+
"ParentId": {
|
|
133
|
+
oneOf: [
|
|
134
|
+
ref("Id"),
|
|
135
|
+
{ type: null }
|
|
136
|
+
]
|
|
137
|
+
},
|
|
138
|
+
...Object.fromEntries(concreteConcepts
|
|
139
|
+
.map((element) => [
|
|
140
|
+
element.name,
|
|
141
|
+
schemaForConcept(element)
|
|
142
|
+
])),
|
|
143
|
+
"SerializedNode": {
|
|
144
|
+
oneOf: concreteConcepts
|
|
145
|
+
.map(({ name }) => ref(name))
|
|
146
|
+
},
|
|
147
|
+
...Object.fromEntries(enumerations
|
|
148
|
+
.map((enumeration) => [
|
|
149
|
+
enumeration.key,
|
|
150
|
+
schemaForEnumeration(enumeration)
|
|
151
|
+
]))
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
//# sourceMappingURL=schema-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-generator.js","sourceRoot":"","sources":["../../src/m3/schema-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,aAAa,EAGb,WAAW,EAEX,UAAU,EACV,aAAa,EACb,aAAa,EACb,UAAU,EACV,KAAK,EACL,WAAW,EAEX,aAAa,EAEhB,MAAM,eAAe,CAAA;AACtB,4DAA4D;AAG5D,MAAM,GAAG,GAAG,CAAC,EAAU,EAAoB,EAAE,CACzC,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAA;AAE/B,MAAM,QAAQ,GAAG,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;AAE3C,MAAM,gBAAgB,GAAG,CAAC,QAAkB,EAAW,EAAE;IACrD,IAAI,QAAQ,YAAY,WAAW,EAAE;QACjC,OAAO,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;KAC3B;IACD,IAAI,QAAQ,YAAY,aAAa,EAAE;QACnC,iGAAiG;QACjG,QAAQ,QAAQ,CAAC,IAAI,EAAE;YACnB,KAAK,QAAQ,CAAC;YACd,KAAK,SAAS,CAAC;YACf,KAAK,SAAS,CAAC;YACf,KAAK,MAAM,CAAC,CAAC,OAAO,QAAQ,EAAE,CAAA;YAC9B;gBACI,MAAM,IAAI,KAAK,CAAC,kCAAkC,QAAQ,CAAC,IAAI,GAAG,CAAC,CAAA;SAC1E;KACJ;IACD,MAAM,IAAI,KAAK,CAAC,mCAAmC,QAAQ,EAAE,CAAC,CAAA;AAClE,CAAC,CAAA;AAGD,MAAM,iBAAiB,GAAG,CAAoB,QAAa,EAAE,UAAmC,EAAE,gBAAyB,EAAE,EAAE;IAC3H,M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CAAC,GAAG;gBACf,oBAAoB,CAAC,WAAW,CAAC;aACpC,CAAC,CACT;SACJ;KACJ,CAAA;AACL,CAAC,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SerializationChunk } from "@lionweb/core";
|
|
2
|
+
/**
|
|
3
|
+
* @return A shortened version of a {@link SerializedModel JSON serialization}, which should make it easier to inspect.
|
|
4
|
+
* Note that the shortened version doesn't contain all information, and could (in theory) be malformed.
|
|
5
|
+
*/
|
|
6
|
+
export declare const shortenedSerialization: ({ nodes }: SerializationChunk) => any[];
|
|
7
|
+
/**
|
|
8
|
+
* @return A sorted version of a {@link SerializedModel JSON serialization}, which should make it easier to inspect.
|
|
9
|
+
* Note that the sorted version destroy the order of links, which might effectively alter semantics.
|
|
10
|
+
*/
|
|
11
|
+
export declare const sortedSerialization: ({ serializationFormatVersion, languages, nodes }: SerializationChunk) => SerializationChunk;
|
|
12
|
+
//# sourceMappingURL=serialization-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization-utils.d.ts","sourceRoot":"","sources":["../src/serialization-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAkB,MAAM,eAAe,CAAA;AAGjE;;;GAGG;AACH,eAAO,MAAM,sBAAsB,cAAa,kBAAkB,UAY3D,CAAA;AAGP;;;GAGG;AACH,eAAO,MAAM,mBAAmB,qDAAoD,kBAAkB,KAAG,kBAqBnG,CAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { sortByStringKey } from "@lionweb/core";
|
|
2
|
+
/**
|
|
3
|
+
* @return A shortened version of a {@link SerializedModel JSON serialization}, which should make it easier to inspect.
|
|
4
|
+
* Note that the shortened version doesn't contain all information, and could (in theory) be malformed.
|
|
5
|
+
*/
|
|
6
|
+
export const shortenedSerialization = ({ nodes }) => nodes.map((node) => ({
|
|
7
|
+
id: node.id,
|
|
8
|
+
concept: node.concept.key,
|
|
9
|
+
parent: node.parent ?? undefined,
|
|
10
|
+
...Object.fromEntries([
|
|
11
|
+
...node.properties.map((serProp) => [serProp.property.key, serProp.value]),
|
|
12
|
+
...node.children.map((serContainment) => [serContainment.containment.key, serContainment.children]),
|
|
13
|
+
...node.references.map((serReference) => [serReference.reference.key, serReference.targets.map(({ reference }) => reference)])
|
|
14
|
+
])
|
|
15
|
+
}));
|
|
16
|
+
/**
|
|
17
|
+
* @return A sorted version of a {@link SerializedModel JSON serialization}, which should make it easier to inspect.
|
|
18
|
+
* Note that the sorted version destroy the order of links, which might effectively alter semantics.
|
|
19
|
+
*/
|
|
20
|
+
export const sortedSerialization = ({ serializationFormatVersion, languages, nodes }) => ({
|
|
21
|
+
serializationFormatVersion,
|
|
22
|
+
languages,
|
|
23
|
+
nodes: sortByStringKey(nodes, ({ id }) => id)
|
|
24
|
+
.map((node) => ({
|
|
25
|
+
id: node.id,
|
|
26
|
+
concept: node.concept,
|
|
27
|
+
parent: node.parent,
|
|
28
|
+
properties: sortByStringKey(node.properties, ({ property }) => property.key),
|
|
29
|
+
children: sortByStringKey(node.children, ({ containment }) => containment.key)
|
|
30
|
+
.map(({ containment, children }) => ({
|
|
31
|
+
containment,
|
|
32
|
+
children: children.sort()
|
|
33
|
+
})),
|
|
34
|
+
references: sortByStringKey(node.references, ({ reference }) => reference.key)
|
|
35
|
+
.map(({ reference, targets }) => ({
|
|
36
|
+
reference,
|
|
37
|
+
targets: sortByStringKey(targets, ({ reference }) => reference)
|
|
38
|
+
}))
|
|
39
|
+
}))
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=serialization-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization-utils.js","sourceRoot":"","sources":["../src/serialization-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,eAAe,EAAC,MAAM,eAAe,CAAA;AAGjE;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,EAAC,KAAK,EAAqB,EAA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AAE,eAAe,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,EAAC,QAAQ,EAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC;QAC1E,QAAQ,EAAE,eAAe,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAC,WAAW,EAAC,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC;aACnE,GAAG,CAAC,CAAC,EAAC,WAAW,EAAE,QAAQ,EAAC,EAAE,EAAE,CAAC,CAAC;YAC/B,WAAW;YACX,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE;SAC5B,CAAC,CAAC;QACX,UAAU,EAAE,eAAe,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,EAAC,SAAS,EAAC,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC;aACnE,GAAG,CAAC,CAAC,EAAC,SAAS,EAAE,OAAO,EAAC,EAAE,EAAE,CAAC,CAAC;YAC5B,SAAS;YACT,OAAO,EAAE,eAAe,CAAC,OAAO,EAAE,CAAC,EAAC,SAAS,EAAC,EAAE,EAAE,CAAC,SAAS,CAAC;SAChE,CAAC,CAAC;KACd,CAAC,CAAC;CACV,CAAC,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lionweb/utilities",
|
|
3
|
+
"version": "0.1.0-beta.0",
|
|
4
|
+
"description": "LionWeb utilities",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"typings": "dist/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/LionWeb-org/lioncore-typescript.git"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/LionWeb-org/lioncore-typescript/issues"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@lionweb/core": "0.5.0-beta.0",
|
|
19
|
+
"littoral-templates": "^0.2.2",
|
|
20
|
+
"nanoid": "^4.0.2"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/node": "^20.6.0",
|
|
24
|
+
"typescript": "^5.2.2"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsc",
|
|
28
|
+
"clean": "rm -rf dist/ && rm -rf node_modules/"
|
|
29
|
+
}
|
|
30
|
+
}
|