@lionweb/core 0.8.0-beta.5 → 0.8.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/CHANGELOG.md +31 -5
  2. package/dist/deserializer.d.ts +10 -2
  3. package/dist/deserializer.d.ts.map +1 -1
  4. package/dist/deserializer.js +8 -7
  5. package/dist/deserializer.js.map +1 -1
  6. package/dist/dynamic-facade.d.ts +3 -3
  7. package/dist/dynamic-facade.d.ts.map +1 -1
  8. package/dist/dynamic-facade.js +4 -3
  9. package/dist/dynamic-facade.js.map +1 -1
  10. package/dist/extraction.d.ts +2 -2
  11. package/dist/extraction.d.ts.map +1 -1
  12. package/dist/extraction.js.map +1 -1
  13. package/dist/index.d.ts +0 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +0 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/m1/reference-utils.d.ts +3 -3
  18. package/dist/m1/reference-utils.d.ts.map +1 -1
  19. package/dist/m1/reference-utils.js.map +1 -1
  20. package/dist/m3/builtins-common.d.ts +70 -0
  21. package/dist/m3/builtins-common.d.ts.map +1 -0
  22. package/dist/m3/builtins-common.js +88 -0
  23. package/dist/m3/builtins-common.js.map +1 -0
  24. package/dist/m3/builtins-function.d.ts +9 -0
  25. package/dist/m3/builtins-function.d.ts.map +1 -0
  26. package/dist/m3/builtins-function.js +19 -0
  27. package/dist/m3/builtins-function.js.map +1 -0
  28. package/dist/m3/deserializer.d.ts +25 -0
  29. package/dist/m3/deserializer.d.ts.map +1 -1
  30. package/dist/m3/deserializer.js +18 -11
  31. package/dist/m3/deserializer.js.map +1 -1
  32. package/dist/m3/index.d.ts +7 -3
  33. package/dist/m3/index.d.ts.map +1 -1
  34. package/dist/m3/index.js +6 -3
  35. package/dist/m3/index.js.map +1 -1
  36. package/dist/m3/lioncore-common.d.ts +37 -0
  37. package/dist/m3/lioncore-common.d.ts.map +1 -0
  38. package/dist/m3/lioncore-common.js +10 -0
  39. package/dist/m3/lioncore-common.js.map +1 -0
  40. package/dist/m3/reading-writing.d.ts +41 -0
  41. package/dist/m3/reading-writing.d.ts.map +1 -0
  42. package/dist/m3/reading-writing.js +84 -0
  43. package/dist/m3/reading-writing.js.map +1 -0
  44. package/dist/m3/serializer.d.ts +17 -0
  45. package/dist/m3/serializer.d.ts.map +1 -1
  46. package/dist/m3/serializer.js +11 -2
  47. package/dist/m3/serializer.js.map +1 -1
  48. package/dist/m3/symbol-table.d.ts +3 -3
  49. package/dist/m3/types.d.ts +11 -15
  50. package/dist/m3/types.d.ts.map +1 -1
  51. package/dist/m3/types.js +2 -6
  52. package/dist/m3/types.js.map +1 -1
  53. package/dist/m3/version.d.ts +19 -0
  54. package/dist/m3/version.d.ts.map +1 -0
  55. package/dist/m3/version.js +19 -0
  56. package/dist/m3/version.js.map +1 -0
  57. package/dist/m3/versions/v2023_1/builtins-legacy.d.ts +44 -0
  58. package/dist/m3/versions/v2023_1/builtins-legacy.d.ts.map +1 -0
  59. package/dist/m3/{builtins.js → versions/v2023_1/builtins-legacy.js} +24 -79
  60. package/dist/m3/versions/v2023_1/builtins-legacy.js.map +1 -0
  61. package/dist/m3/versions/v2023_1/builtins.d.ts +34 -0
  62. package/dist/m3/versions/v2023_1/builtins.d.ts.map +1 -0
  63. package/dist/m3/versions/v2023_1/builtins.js +75 -0
  64. package/dist/m3/versions/v2023_1/builtins.js.map +1 -0
  65. package/dist/m3/versions/v2023_1/lioncore.d.ts +34 -0
  66. package/dist/m3/versions/v2023_1/lioncore.d.ts.map +1 -0
  67. package/dist/m3/versions/v2023_1/lioncore.js +86 -0
  68. package/dist/m3/versions/v2023_1/lioncore.js.map +1 -0
  69. package/dist/m3/versions/v2023_1/version.d.ts +6 -0
  70. package/dist/m3/versions/v2023_1/version.d.ts.map +1 -0
  71. package/dist/m3/versions/v2023_1/version.js +8 -0
  72. package/dist/m3/versions/v2023_1/version.js.map +1 -0
  73. package/dist/m3/versions.d.ts +23 -0
  74. package/dist/m3/versions.d.ts.map +1 -0
  75. package/dist/m3/versions.js +24 -0
  76. package/dist/m3/versions.js.map +1 -0
  77. package/dist/reading.d.ts +10 -6
  78. package/dist/reading.d.ts.map +1 -1
  79. package/dist/serializer.d.ts +17 -6
  80. package/dist/serializer.d.ts.map +1 -1
  81. package/dist/serializer.js +4 -5
  82. package/dist/serializer.js.map +1 -1
  83. package/dist/writing.d.ts +3 -1
  84. package/dist/writing.d.ts.map +1 -1
  85. package/dist/writing.js.map +1 -1
  86. package/package.json +3 -3
  87. package/src/deserializer.ts +18 -14
  88. package/src/dynamic-facade.ts +4 -4
  89. package/src/extraction.ts +3 -3
  90. package/src/index.ts +0 -1
  91. package/src/m1/reference-utils.ts +6 -6
  92. package/src/m3/README.md +1 -1
  93. package/src/m3/builtins-common.ts +143 -0
  94. package/src/m3/builtins-function.ts +22 -0
  95. package/src/m3/deserializer.ts +43 -14
  96. package/src/m3/index.ts +7 -3
  97. package/src/m3/lioncore-common.ts +42 -0
  98. package/src/m3/reading-writing.ts +160 -0
  99. package/src/m3/serializer.ts +25 -2
  100. package/src/m3/symbol-table.ts +3 -3
  101. package/src/m3/types.ts +12 -18
  102. package/src/m3/version.ts +23 -0
  103. package/src/m3/versions/v2023_1/builtins-legacy.ts +126 -0
  104. package/src/m3/versions/v2023_1/builtins.ts +102 -0
  105. package/src/m3/{lioncore.ts → versions/v2023_1/lioncore.ts} +53 -76
  106. package/src/m3/versions/v2023_1/version.ts +9 -0
  107. package/src/m3/versions.ts +32 -0
  108. package/src/reading.ts +10 -6
  109. package/src/serializer.ts +26 -14
  110. package/src/writing.ts +3 -1
  111. package/dist/m3/builtins.d.ts +0 -82
  112. package/dist/m3/builtins.d.ts.map +0 -1
  113. package/dist/m3/builtins.js.map +0 -1
  114. package/dist/m3/facade.d.ts +0 -17
  115. package/dist/m3/facade.d.ts.map +0 -1
  116. package/dist/m3/facade.js +0 -58
  117. package/dist/m3/facade.js.map +0 -1
  118. package/dist/m3/lioncore.d.ts +0 -41
  119. package/dist/m3/lioncore.d.ts.map +0 -1
  120. package/dist/m3/lioncore.js +0 -90
  121. package/dist/m3/lioncore.js.map +0 -1
  122. package/dist/version.d.ts +0 -5
  123. package/dist/version.d.ts.map +0 -1
  124. package/dist/version.js +0 -5
  125. package/dist/version.js.map +0 -1
  126. package/src/m3/builtins.ts +0 -198
  127. package/src/m3/facade.ts +0 -130
  128. package/src/version.ts +0 -5
package/src/m3/index.ts CHANGED
@@ -1,12 +1,16 @@
1
- export * from "./builtins.js"
1
+ export { newPropertyValueDeserializerRegistry, newPropertyValueSerializerRegistry, propertyValueDeserializerFrom, propertyValueSerializerFrom } from "./builtins-common.js"
2
+ export type * from "./builtins-common.js"
3
+ export { isBuiltinNodeConcept } from "./builtins-function.js"
2
4
  export * from "./constraints.js"
3
5
  export * from "./deserializer.js"
4
- export * from "./facade.js"
5
6
  export * from "./factory.js"
6
7
  export * from "./feature-resolvers.js"
7
8
  export * from "./functions.js"
8
- export * from "./lioncore.js"
9
+ export { lioncoreKey } from "./lioncore-common.js"
10
+ export * from "./reading-writing.js"
9
11
  export * from "./reference-checker.js"
10
12
  export * from "./serializer.js"
11
13
  export * from "./symbol-table.js"
12
14
  export * from "./types.js"
15
+ export { LionWebVersion } from "./version.js"
16
+ export * from "./versions.js"
@@ -0,0 +1,42 @@
1
+ import { Concept, Interface, Language, Property } from "./types.js"
2
+ import { StringsMapper } from "@lionweb/ts-utils"
3
+
4
+ /**
5
+ * The key for the LionCore language.
6
+ */
7
+ export const lioncoreKey = "LionCore-M3"
8
+
9
+ /**
10
+ * A key generator for the LionCore language.
11
+ * *Note*: don’t export!
12
+ */
13
+ export const generatedLionCoreKeyFrom: StringsMapper = (...names) =>
14
+ names.length === 1 ? lioncoreKey : names.slice(1).join("-")
15
+
16
+
17
+ /**
18
+ * Type def. for objects that façade (a version of) the LionCore language.
19
+ */
20
+ export type LionCoreFacade = {
21
+ language: Language
22
+ metaConcepts: {
23
+ annotation: Concept
24
+ classifier: Concept
25
+ concept: Concept
26
+ interface: Concept
27
+ containment: Concept
28
+ enumeration: Concept
29
+ enumerationLiteral: Concept
30
+ ikeyed: Interface
31
+ language: Concept
32
+ primitiveType: Concept
33
+ property: Concept
34
+ reference: Concept
35
+ }
36
+ metaFeatures: {
37
+ concept_abstract: Property
38
+ ikeyed_key: Property
39
+ language_version: Property
40
+ }
41
+ }
42
+
@@ -0,0 +1,160 @@
1
+ import { metaTypedBasedClassifierDeducerFor, qualifiedNameOf } from "./functions.js"
2
+ import { LionWebVersion } from "./version.js"
3
+ import { LionWebVersions } from "./versions.js"
4
+ import { Reader } from "../reading.js"
5
+ import {
6
+ Annotation,
7
+ Classifier,
8
+ Concept,
9
+ Containment,
10
+ Enumeration,
11
+ EnumerationLiteral,
12
+ Interface,
13
+ Language,
14
+ M3Concept,
15
+ PrimitiveType,
16
+ Property,
17
+ Reference
18
+ } from "./types.js"
19
+ import { updateSettingsNameBased, Writer } from "../writing.js"
20
+
21
+
22
+ /**
23
+ * @return an instance of {@link Reader} to read instances of the LionCore M3 (so M2s),
24
+ * according to the specified {@link LionWebVersion LionWeb `version`}.
25
+ */
26
+ export const lioncoreReaderFor = (version: LionWebVersion): Reader<M3Concept> => ({
27
+ classifierOf: metaTypedBasedClassifierDeducerFor(version.lioncoreFacade.language),
28
+ getFeatureValue: (node, feature) =>
29
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
+ (node as any)[feature.name], // (mirrors name-based update of settings)
31
+ enumerationLiteralFrom: (value, _) => value as EnumerationLiteral | null
32
+ })
33
+
34
+ /**
35
+ * An instance of {@link Reader} to read instances of the LionCore M3 (so M2s),
36
+ * according to the 2023.1 version of LionWeb.
37
+ *
38
+ * @deprecated Use {@link lioncoreReaderFor} instead.
39
+ */
40
+ export const lioncoreReader: Reader<M3Concept> = lioncoreReaderFor(LionWebVersions.v2023_1)
41
+
42
+ /**
43
+ * Alias for {@link lioncoreReader}, kept for backward compatibility, and to be removed later.
44
+ *
45
+ * @deprecated Use {@link lioncoreReaderFor} instead (skipping `lioncoreReader`).
46
+ */
47
+ export const lioncoreExtractionFacade = lioncoreReader
48
+
49
+
50
+ /**
51
+ * An instance of {@link Writer} for instances of the LionCore M3 (so M2s),
52
+ * according to the specified {@link LionWebVersion LionWeb `version`}.
53
+ */
54
+ export const lioncoreWriterFor = (version: LionWebVersion): Writer<M3Concept> => {
55
+ const { lioncoreFacade, builtinsFacade } = version
56
+ const { ikeyed_key } = lioncoreFacade.metaFeatures
57
+ const { inamed_name } = builtinsFacade.features
58
+ const { metaConcepts, metaFeatures } = lioncoreFacade
59
+ return {
60
+ nodeFor: (parent, classifier, id, propertySettings) => {
61
+ switch (classifier.key) {
62
+ case metaConcepts.annotation.key:
63
+ return new Annotation(
64
+ parent as Language,
65
+ propertySettings[inamed_name.key] as string,
66
+ propertySettings[ikeyed_key.key] as string,
67
+ id
68
+ )
69
+ case metaConcepts.concept.key:
70
+ return new Concept(
71
+ parent as Language,
72
+ propertySettings[inamed_name.key] as string,
73
+ propertySettings[ikeyed_key.key] as string,
74
+ id,
75
+ propertySettings[metaFeatures.concept_abstract.key] as boolean
76
+ )
77
+ case metaConcepts.interface.key:
78
+ return new Interface(
79
+ parent as Language,
80
+ propertySettings[inamed_name.key] as string,
81
+ propertySettings[ikeyed_key.key] as string,
82
+ id
83
+ )
84
+ case metaConcepts.containment.key:
85
+ return new Containment(
86
+ parent as Classifier,
87
+ propertySettings[inamed_name.key] as string,
88
+ propertySettings[ikeyed_key.key] as string,
89
+ id
90
+ )
91
+ case metaConcepts.enumeration.key:
92
+ return new Enumeration(
93
+ parent as Language,
94
+ propertySettings[inamed_name.key] as string,
95
+ propertySettings[ikeyed_key.key] as string,
96
+ id
97
+ )
98
+ case metaConcepts.enumerationLiteral.key:
99
+ return new EnumerationLiteral(
100
+ parent as Enumeration,
101
+ propertySettings[inamed_name.key] as string,
102
+ propertySettings[ikeyed_key.key] as string,
103
+ id
104
+ )
105
+ case metaConcepts.language.key:
106
+ return new Language(
107
+ propertySettings[inamed_name.key] as string,
108
+ propertySettings[metaFeatures.language_version.key] as string,
109
+ id,
110
+ propertySettings[metaFeatures.ikeyed_key.key] as string
111
+ )
112
+ case metaConcepts.primitiveType.key:
113
+ return new PrimitiveType(
114
+ parent as Language,
115
+ propertySettings[inamed_name.key] as string,
116
+ propertySettings[ikeyed_key.key] as string,
117
+ id
118
+ )
119
+ case metaConcepts.property.key:
120
+ return new Property(
121
+ parent as Classifier,
122
+ propertySettings[inamed_name.key] as string,
123
+ propertySettings[ikeyed_key.key] as string,
124
+ id
125
+ )
126
+ case metaConcepts.reference.key:
127
+ return new Reference(
128
+ parent as Classifier,
129
+ propertySettings[inamed_name.key] as string,
130
+ propertySettings[ikeyed_key.key] as string,
131
+ id
132
+ )
133
+ default:
134
+ throw new Error(
135
+ `don't know a node of concept ${qualifiedNameOf(classifier)} with key ${classifier.key} that's not in LionCore M3`
136
+ )
137
+ }
138
+ },
139
+ setFeatureValue: (node, feature, value) => {
140
+ updateSettingsNameBased(node as unknown as Record<string, unknown>, feature, value)
141
+ },
142
+ encodingOf: literal => literal
143
+ }
144
+ }
145
+
146
+ /**
147
+ * An instance of {@link Writer} for instances of the LionCore M3 (so M2s),
148
+ * according to the 2023.1 LionWeb version.
149
+ *
150
+ * @deprecated Use {@link lioncoreWriterFor} instead.
151
+ */
152
+ export const lioncoreWriter: Writer<M3Concept> = lioncoreWriterFor(LionWebVersions.v2023_1)
153
+
154
+ /**
155
+ * Alias for {@link lioncoreWriter}, kept for backward compatibility, and to be deprecated and removed later.
156
+ *
157
+ * @deprecated Use {@link lioncoreWriterFor} instead (skipping `lioncoreWrite` altogether).
158
+ */
159
+ export const lioncoreInstantationFacade = lioncoreWriter
160
+
@@ -1,13 +1,36 @@
1
1
  import { LionWebJsonChunk } from "@lionweb/json"
2
2
  import { serializerWith } from "../serializer.js"
3
- import { lioncoreReader } from "./facade.js"
3
+ import { lioncoreReaderFor } from "./reading-writing.js"
4
4
  import { Language } from "./types.js"
5
+ import { LionWebVersion } from "./version.js"
6
+ import { LionWebVersions } from "./versions.js"
5
7
 
6
8
 
9
+ /**
10
+ * Type def. for objects that contain all necessary data to deserialize one or more languages from a {@link LionWebJsonChunk serialization chunk}.
11
+ */
12
+ export type LanguageSerializationData = {
13
+ /**
14
+ * The version of the LionWeb serialization format to serialize in.
15
+ * Default = {@link LionWebVersions.v2023_1}.
16
+ */
17
+ lionWebVersion?: LionWebVersion
18
+ languages: Language[]
19
+ }
20
+
21
+ /**
22
+ * @return the {@link LionWebJsonChunk serialization chunk} serializing the given languages (M2s, as instances of the LionCore M3),
23
+ * according to the configured {@link LionWebVersion} (which itself defaults to {@link LionWebVersions.v2023_1}).
24
+ */
25
+ export const serializeLanguagesFor = (data: LanguageSerializationData) => {
26
+ const lionwebVersion = data.lionWebVersion ?? LionWebVersions.v2023_1
27
+ return serializerWith({ reader: lioncoreReaderFor(lionwebVersion) })(data.languages)
28
+ }
29
+
7
30
  /**
8
31
  * Serializes languages (i.e., instances of the LionCore metametamodel, using {@link M3Concept these type definitions})
9
32
  * into the LionWeb serialization JSON format.
10
33
  */
11
34
  export const serializeLanguages = (...languages: Language[]): LionWebJsonChunk =>
12
- serializerWith({ reader: lioncoreReader })(languages)
35
+ serializerWith({ reader: lioncoreReaderFor(LionWebVersions.v2023_1) })(languages)
13
36
 
@@ -18,15 +18,15 @@ interface SymbolTable {
18
18
 
19
19
  /**
20
20
  * Looks up the {@link LanguageEntity}, as pointed to by the given {@link LionWebJsonMetaPointer},
21
- * or {@code undefined} if it couldn't be found.
21
+ * or `undefined` if it couldn't be found.
22
22
  */
23
23
  entityMatching(entityMetaPointer: LionWebJsonMetaPointer): LanguageEntity | undefined
24
24
 
25
25
  /**
26
26
  * Looks up the {@link Feature}, as pointed to by the {@link LionWebJsonMetaPointer} given second,
27
27
  * as a feature of the {@link Classifier}, as pointed to by the {@link LionWebJsonMetaPointer} given first,
28
- * or {@code undefined} it it couldn't be found.
29
- * *Note* that the {@code language} and {@code version} values of both {@link LionWebJsonMetaPointer}-typed arguments should coincide,
28
+ * or `undefined` it it couldn't be found.
29
+ * *Note* that the `language` and `version` values of both {@link LionWebJsonMetaPointer}-typed arguments should coincide,
30
30
  * although this is typically not checked!
31
31
  */
32
32
  featureMatching(entityMetaPointer: LionWebJsonMetaPointer, featureMetaPointer: LionWebJsonMetaPointer): Feature | undefined
package/src/m3/types.ts CHANGED
@@ -5,15 +5,9 @@
5
5
 
6
6
  import { LionWebId, LionWebJsonMetaPointer, LionWebKey } from "@lionweb/json"
7
7
  import { ResolveInfoDeducer } from "../reading.js"
8
- import { MultiRef, SingleRef, referenceToSet } from "../references.js"
8
+ import { MultiRef, referenceToSet, SingleRef } from "../references.js"
9
9
  import { Node } from "../types.js"
10
-
11
-
12
- /**
13
- * The key of the LionCore language containing the built-ins.
14
- * (It's defined here because of instantiation order.)
15
- */
16
- const lioncoreBuiltinsKey = "LionCore-builtins"
10
+ import { lioncoreBuiltinsKey } from "./builtins-common.js"
17
11
 
18
12
 
19
13
  // Types appear roughly in the order of top-to-down+left-to-right in the diagram at:
@@ -72,7 +66,7 @@ abstract class M3Node implements IKeyed, IMetaTyped {
72
66
  this.key = key
73
67
  return this
74
68
  }
75
- annotations: Node[] = [] // (containment)
69
+ readonly annotations: Node[] = [] // (containment)
76
70
  }
77
71
 
78
72
  abstract class Feature extends M3Node {
@@ -136,7 +130,7 @@ abstract class LanguageEntity extends M3Node {
136
130
  }
137
131
 
138
132
  abstract class Classifier extends LanguageEntity {
139
- features: Feature[] = [] // (containment)
133
+ readonly features: Feature[] = [] // (containment)
140
134
  havingFeatures(...features: Feature[]) {
141
135
  this.features.push(...features.filter((feature) => this.features.indexOf(feature) < 0))
142
136
  return this
@@ -158,7 +152,7 @@ class Concept extends Classifier {
158
152
  abstract: boolean
159
153
  partition: boolean
160
154
  extends?: SingleRef<Concept> // (reference)
161
- implements: MultiRef<Interface> = [] // (reference)
155
+ readonly implements: MultiRef<Interface> = [] // (reference)
162
156
  constructor(language: Language, name: string, key: LionWebKey, id: LionWebId, abstract: boolean, extends_?: SingleRef<Concept>) {
163
157
  super(language, name, key, id)
164
158
  this.abstract = abstract
@@ -181,7 +175,7 @@ class Annotation extends Classifier {
181
175
  return "Annotation"
182
176
  }
183
177
  extends?: SingleRef<Annotation> // (reference)
184
- implements: MultiRef<Interface> = [] // (reference)
178
+ readonly implements: MultiRef<Interface> = [] // (reference)
185
179
  annotates: SingleRef<Classifier> = referenceToSet() // (reference)
186
180
  constructor(language: Language, name: string, key: LionWebKey, id: LionWebId, extends_?: SingleRef<Annotation>) {
187
181
  super(language, name, key, id)
@@ -202,7 +196,7 @@ class Interface extends Classifier {
202
196
  metaType(): string {
203
197
  return "Interface"
204
198
  }
205
- extends: MultiRef<Interface> = [] // (reference)
199
+ readonly extends: MultiRef<Interface> = [] // (reference)
206
200
  extending(...interfaces: Interface[]): Interface {
207
201
  // TODO check actual types of interfaces, or use type shapes/interfaces
208
202
  this.extends.push(...interfaces)
@@ -227,7 +221,7 @@ class Enumeration extends DataType {
227
221
  metaType(): string {
228
222
  return "Enumeration"
229
223
  }
230
- literals: EnumerationLiteral[] = [] // (containment)
224
+ readonly literals: EnumerationLiteral[] = [] // (containment)
231
225
  havingLiterals(...literals: EnumerationLiteral[]) {
232
226
  this.literals.push(...literals.filter((literal) => this.literals.indexOf(literal) < 0))
233
227
  return this
@@ -251,8 +245,8 @@ class Language extends M3Node {
251
245
  return "Language"
252
246
  }
253
247
  version: string
254
- entities: LanguageEntity[] = [] // (containment)
255
- dependsOn: MultiRef<Language> = [] // special (!) reference
248
+ readonly entities: LanguageEntity[] = [] // (containment)
249
+ readonly dependsOn: MultiRef<Language> = [] // special (!) reference
256
250
  // (!) special because deserializer needs to be aware of where to get the instance from
257
251
  constructor(name: string, version: string, id: LionWebId, key: LionWebKey) {
258
252
  super(id, name, key)
@@ -304,6 +298,7 @@ export {
304
298
  EnumerationLiteral,
305
299
  Feature,
306
300
  Interface,
301
+ M3Node,
307
302
  Language,
308
303
  LanguageEntity,
309
304
  Link,
@@ -319,7 +314,6 @@ export type {
319
314
  IKeyed,
320
315
  IMetaTyped,
321
316
  INamed,
322
- M3Concept,
323
- M3Node
317
+ M3Concept
324
318
  }
325
319
 
@@ -0,0 +1,23 @@
1
+ import { LionCoreFacade } from "./lioncore-common.js"
2
+ import { LionCoreBuiltinsFacade } from "./builtins-common.js"
3
+
4
+ /**
5
+ * Representation of a LionWeb version.
6
+ */
7
+ export class LionWebVersion {
8
+ constructor(
9
+ /**
10
+ * The value of the root-level `serializationFormatVersion` field for {@link LionWebJsonChunk serialization chunks} *emitted* by this version.
11
+ */
12
+ public readonly serializationFormatVersion: string,
13
+ public readonly lioncoreFacade: LionCoreFacade,
14
+ public readonly builtinsFacade: LionCoreBuiltinsFacade
15
+ ) {
16
+ }
17
+ }
18
+
19
+ /*
20
+ * This class must be in a separate file to avoid circular initializations:
21
+ * versions.ts[LionWebVersions] -> version-<version>.ts -> version.ts
22
+ */
23
+
@@ -0,0 +1,126 @@
1
+ import { asMinimalJsonString } from "@lionweb/ts-utils"
2
+ import { shouldBeIdentical } from "../../builtins-common.js"
3
+ import { DataType, Property } from "../../types.js"
4
+ import { PropertyValueDeserializer } from "../../../deserializer.js"
5
+ import { isUnresolvedReference } from "../../../references.js"
6
+ import { PropertyValueSerializer } from "../../../serializer.js"
7
+ import { v2023_1 } from "./version.js"
8
+
9
+
10
+ abstract class DataTypeRegistry<T> {
11
+ private map = new Map<DataType, T>()
12
+
13
+ private _sealed = false
14
+
15
+ sealed() {
16
+ this._sealed = true
17
+ return this
18
+ }
19
+
20
+ public register(dataType: DataType, t: T) {
21
+ if (this._sealed) {
22
+ throw new Error(`can't register a data type with a register that has been sealed`)
23
+ }
24
+ this.map.set(dataType, t)
25
+ }
26
+
27
+ protected byType(targetDataType: DataType): T | undefined {
28
+ for (const [dataType, t] of this.map.entries()) {
29
+ if (shouldBeIdentical(targetDataType, dataType)) {
30
+ return t
31
+ }
32
+ }
33
+ return undefined
34
+ }
35
+ }
36
+
37
+
38
+ const { booleanDataType, integerDataType, jsonDataType, stringDataType } = v2023_1.builtinsFacade.primitiveTypes
39
+
40
+
41
+ /**
42
+ * An implementation of {@link PropertyValueDeserializer} that knows how to deserialize serialized values of all the built-in primitive types.
43
+ *
44
+ * @deprecated
45
+ */
46
+ export class BuiltinPropertyValueDeserializer
47
+ extends DataTypeRegistry<(value: string) => unknown>
48
+ implements PropertyValueDeserializer {
49
+ constructor() {
50
+ super()
51
+ this.register(stringDataType, (value) => value)
52
+ this.register(booleanDataType, (value) => JSON.parse(value))
53
+ this.register(integerDataType, (value) => Number(value))
54
+ this.register(jsonDataType, (value) => JSON.parse(value as string))
55
+ }
56
+
57
+ deserializeValue(value: string | undefined, property: Property): unknown | undefined {
58
+ if (value === undefined) {
59
+ if (property.optional) {
60
+ return undefined
61
+ }
62
+ throw new Error(`can't deserialize undefined as the value of required property "${property.name}" (on classifier "${property.classifier.name}" in language "${property.classifier.language.name}")`)
63
+ }
64
+ const { type } = property
65
+ if (isUnresolvedReference(type)) {
66
+ throw new Error(`can't deserialize property "${property.name}" (on classifier "${property.classifier.name}" in language "${property.classifier.language.name}") with unspecified type`)
67
+ }
68
+ const specificDeserializer = this.byType(type)
69
+ if (specificDeserializer != undefined) {
70
+ return specificDeserializer(value)
71
+ } else {
72
+ throw new Error(`can't deserialize value of property "${property.name}" (on classifier "${property.classifier.name}" in language "${property.classifier.language.name}") of type "${type!.name}": ${value}`)
73
+ }
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Misspelled alias of {@link BuiltinPropertyValueDeserializer}, kept for backward compatibility, and to be deprecated and removed later.
79
+ *
80
+ * @deprecated
81
+ */
82
+ export class DefaultPrimitiveTypeDeserializer extends BuiltinPropertyValueDeserializer {
83
+ }
84
+
85
+ /**
86
+ * An implementation of {@link PropertyValueSerializer} that knows how to serialize values of all the built-in primitive types.
87
+ *
88
+ * @deprecated
89
+ */
90
+ export class BuiltinPropertyValueSerializer extends DataTypeRegistry<(value: unknown) => string> implements PropertyValueSerializer {
91
+ constructor() {
92
+ super()
93
+ this.register(stringDataType, (value) => value as string)
94
+ this.register(booleanDataType, (value) => `${value as boolean}`)
95
+ this.register(integerDataType, (value) => `${value as number}`)
96
+ this.register(jsonDataType, (value) => asMinimalJsonString(value))
97
+ }
98
+
99
+ serializeValue(value: unknown | undefined, property: Property): string | null {
100
+ if (value === undefined) {
101
+ if (property.optional) {
102
+ return null
103
+ }
104
+ throw new Error(`can't serialize undefined as the value of required property "${property.name}" (on classifier "${property.classifier.name}" in language "${property.classifier.language.name}")`)
105
+ }
106
+ const { type } = property
107
+ if (isUnresolvedReference(type)) {
108
+ throw new Error(`can't serialize property "${property.name}" (on classifier "${property.classifier.name}" in language "${property.classifier.language.name}") with unspecified type`)
109
+ }
110
+ const specificSerializer = this.byType(type)
111
+ if (specificSerializer != undefined) {
112
+ return specificSerializer(value)
113
+ } else {
114
+ throw new Error(`can't serialize value of property "${property.name}" (on classifier "${property.classifier.name}" in language "${property.classifier.language.name}") of type "${type!.name}": ${value}`)
115
+ }
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Misspelled alias of {@link BuiltinPropertyValueSerializer}, kept for backward compatibility, and to be deprecated and removed later.
121
+ *
122
+ * @deprecated
123
+ */
124
+ export class DefaultPrimitiveTypeSerializer extends BuiltinPropertyValueSerializer {
125
+ }
126
+
@@ -0,0 +1,102 @@
1
+ import { asMinimalJsonString } from "@lionweb/ts-utils"
2
+ import {
3
+ LionCoreBuiltinsFacade,
4
+ lioncoreBuiltinsIdAndKeyGenerator,
5
+ newPropertyValueDeserializerRegistry,
6
+ newPropertyValueSerializerRegistry,
7
+ propertyValueDeserializerFrom,
8
+ propertyValueSerializerFrom
9
+ } from "../../builtins-common.js"
10
+ import { isBuiltinNodeConcept } from "../../builtins-function.js"
11
+ import { LanguageFactory } from "../../factory.js"
12
+
13
+
14
+ const factory = new LanguageFactory(
15
+ "LionCore_builtins",
16
+ "2023.1",
17
+ lioncoreBuiltinsIdAndKeyGenerator,
18
+ lioncoreBuiltinsIdAndKeyGenerator
19
+ )
20
+ /*
21
+ * ID == key: `LionCore-builtins-${qualified name _without_ "LionCore-builtins", dash-separated}`
22
+ */
23
+
24
+
25
+ const stringDataType = factory.primitiveType("String")
26
+ const booleanDataType = factory.primitiveType("Boolean")
27
+ const integerDataType = factory.primitiveType("Integer")
28
+ const jsonDataType = factory.primitiveType("JSON")
29
+
30
+ const node = factory.concept("Node", true)
31
+
32
+ const inamed = factory.interface("INamed")
33
+
34
+ const inamed_name = factory.property(inamed, "name").ofType(stringDataType)
35
+
36
+
37
+ export const lioncoreBuiltinsFacade: LionCoreBuiltinsFacade = {
38
+ language: factory.language,
39
+ propertyValueDeserializer: propertyValueDeserializerFrom(
40
+ newPropertyValueDeserializerRegistry()
41
+ .set(stringDataType, (value) => value)
42
+ .set(booleanDataType, (value) => JSON.parse(value))
43
+ .set(integerDataType, (value) => Number(value))
44
+ .set(jsonDataType, (value) => JSON.parse(value as string))
45
+ ),
46
+ propertyValueSerializer: propertyValueSerializerFrom(
47
+ newPropertyValueSerializerRegistry()
48
+ .set(stringDataType, (value) => value as string)
49
+ .set(booleanDataType, (value) => `${value as boolean}`)
50
+ .set(integerDataType, (value) => `${value as number}`)
51
+ .set(jsonDataType, (value) => asMinimalJsonString(value))
52
+ ),
53
+ classifiers: { node, inamed },
54
+ features: { inamed_name },
55
+ primitiveTypes: {
56
+ stringDataType,
57
+ booleanDataType,
58
+ integerDataType,
59
+ jsonDataType,
60
+ /**
61
+ * Misspelled alias of {@link stringDataType}, kept for backward compatibility, and to be deprecated and removed later.
62
+ */
63
+ stringDatatype: stringDataType,
64
+ /**
65
+ * Misspelled alias of {@link booleanDataType}, kept for backward compatibility, and to be deprecated and removed later.
66
+ */
67
+ booleanDatatype: booleanDataType,
68
+ /**
69
+ * Misspelled alias of {@link integerDataType}, kept for backward compatibility, and to be deprecated and removed later.
70
+ */
71
+ integerDatatype: integerDataType,
72
+ /**
73
+ * Misspelled alias of {@link jsonDataType}, kept for backward compatibility, and to be deprecated and removed later.
74
+ */
75
+ jsonDatatype: jsonDataType
76
+ }
77
+ }
78
+
79
+
80
+ /**
81
+ * Definition of a LionCore language that serves as a standard library of built-in primitive types.
82
+ *
83
+ * @deprecated Use `<LionWebVersion>.builtinsFacade.isBuiltinNodeConcept` instead.
84
+ */
85
+ export const lioncoreBuiltins = factory.language
86
+ /**
87
+ * @deprecated Use `<LionWebVersion>.builtinsFacade.primitiveTypes` instead.
88
+ */
89
+ export const builtinPrimitives = lioncoreBuiltinsFacade.primitiveTypes
90
+ /**
91
+ * @deprecated Use `<LionWebVersion>.builtinsFacade.classifiers` instead.
92
+ */
93
+ export const builtinClassifiers = lioncoreBuiltinsFacade.classifiers
94
+ /**
95
+ * @deprecated Use `<LionWebVersion>.builtinsFacade.features` instead.
96
+ */
97
+ export const builtinFeatures = lioncoreBuiltinsFacade.features
98
+ /**
99
+ * @deprecated Use {@link isBuiltinNodeConcept} instead.
100
+ */
101
+ export const isBuiltinConcept = isBuiltinNodeConcept
102
+