@lionweb/core 0.8.0-beta.5 → 0.8.0-beta.6
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 +27 -5
- package/dist/deserializer.d.ts +10 -2
- package/dist/deserializer.d.ts.map +1 -1
- package/dist/deserializer.js +8 -7
- package/dist/deserializer.js.map +1 -1
- package/dist/dynamic-facade.d.ts +1 -1
- package/dist/dynamic-facade.d.ts.map +1 -1
- package/dist/dynamic-facade.js +3 -3
- package/dist/dynamic-facade.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/m3/builtins-common.d.ts +70 -0
- package/dist/m3/builtins-common.d.ts.map +1 -0
- package/dist/m3/builtins-common.js +88 -0
- package/dist/m3/builtins-common.js.map +1 -0
- package/dist/m3/builtins-function.d.ts +9 -0
- package/dist/m3/builtins-function.d.ts.map +1 -0
- package/dist/m3/builtins-function.js +19 -0
- package/dist/m3/builtins-function.js.map +1 -0
- package/dist/m3/deserializer.d.ts +25 -0
- package/dist/m3/deserializer.d.ts.map +1 -1
- package/dist/m3/deserializer.js +18 -11
- package/dist/m3/deserializer.js.map +1 -1
- package/dist/m3/index.d.ts +7 -3
- package/dist/m3/index.d.ts.map +1 -1
- package/dist/m3/index.js +6 -3
- package/dist/m3/index.js.map +1 -1
- package/dist/m3/lioncore-common.d.ts +37 -0
- package/dist/m3/lioncore-common.d.ts.map +1 -0
- package/dist/m3/lioncore-common.js +10 -0
- package/dist/m3/lioncore-common.js.map +1 -0
- package/dist/m3/reading-writing.d.ts +41 -0
- package/dist/m3/reading-writing.d.ts.map +1 -0
- package/dist/m3/reading-writing.js +84 -0
- package/dist/m3/reading-writing.js.map +1 -0
- package/dist/m3/serializer.d.ts +17 -0
- package/dist/m3/serializer.d.ts.map +1 -1
- package/dist/m3/serializer.js +11 -2
- package/dist/m3/serializer.js.map +1 -1
- package/dist/m3/types.d.ts +9 -13
- package/dist/m3/types.d.ts.map +1 -1
- package/dist/m3/types.js +1 -5
- package/dist/m3/types.js.map +1 -1
- package/dist/m3/version.d.ts +19 -0
- package/dist/m3/version.d.ts.map +1 -0
- package/dist/m3/version.js +19 -0
- package/dist/m3/version.js.map +1 -0
- package/dist/m3/versions/v2023_1/builtins-legacy.d.ts +44 -0
- package/dist/m3/versions/v2023_1/builtins-legacy.d.ts.map +1 -0
- package/dist/m3/{builtins.js → versions/v2023_1/builtins-legacy.js} +24 -79
- package/dist/m3/versions/v2023_1/builtins-legacy.js.map +1 -0
- package/dist/m3/versions/v2023_1/builtins.d.ts +34 -0
- package/dist/m3/versions/v2023_1/builtins.d.ts.map +1 -0
- package/dist/m3/versions/v2023_1/builtins.js +75 -0
- package/dist/m3/versions/v2023_1/builtins.js.map +1 -0
- package/dist/m3/versions/v2023_1/lioncore.d.ts +34 -0
- package/dist/m3/versions/v2023_1/lioncore.d.ts.map +1 -0
- package/dist/m3/versions/v2023_1/lioncore.js +86 -0
- package/dist/m3/versions/v2023_1/lioncore.js.map +1 -0
- package/dist/m3/versions/v2023_1/version.d.ts +6 -0
- package/dist/m3/versions/v2023_1/version.d.ts.map +1 -0
- package/dist/m3/versions/v2023_1/version.js +8 -0
- package/dist/m3/versions/v2023_1/version.js.map +1 -0
- package/dist/m3/versions.d.ts +27 -0
- package/dist/m3/versions.d.ts.map +1 -0
- package/dist/m3/versions.js +28 -0
- package/dist/m3/versions.js.map +1 -0
- package/dist/reading.d.ts +2 -0
- package/dist/reading.d.ts.map +1 -1
- package/dist/serializer.d.ts +12 -1
- package/dist/serializer.d.ts.map +1 -1
- package/dist/serializer.js +4 -4
- package/dist/serializer.js.map +1 -1
- package/dist/writing.d.ts +2 -0
- package/dist/writing.d.ts.map +1 -1
- package/dist/writing.js.map +1 -1
- package/package.json +3 -3
- package/src/deserializer.ts +18 -14
- package/src/dynamic-facade.ts +3 -4
- package/src/index.ts +0 -1
- package/src/m3/README.md +1 -1
- package/src/m3/builtins-common.ts +143 -0
- package/src/m3/builtins-function.ts +22 -0
- package/src/m3/deserializer.ts +43 -14
- package/src/m3/index.ts +7 -3
- package/src/m3/lioncore-common.ts +42 -0
- package/src/m3/reading-writing.ts +160 -0
- package/src/m3/serializer.ts +25 -2
- package/src/m3/types.ts +10 -16
- package/src/m3/version.ts +23 -0
- package/src/m3/versions/v2023_1/builtins-legacy.ts +126 -0
- package/src/m3/versions/v2023_1/builtins.ts +102 -0
- package/src/m3/{lioncore.ts → versions/v2023_1/lioncore.ts} +53 -76
- package/src/m3/versions/v2023_1/version.ts +9 -0
- package/src/m3/versions.ts +37 -0
- package/src/reading.ts +2 -0
- package/src/serializer.ts +18 -5
- package/src/writing.ts +2 -0
- package/dist/m3/builtins.d.ts +0 -82
- package/dist/m3/builtins.d.ts.map +0 -1
- package/dist/m3/builtins.js.map +0 -1
- package/dist/m3/facade.d.ts +0 -17
- package/dist/m3/facade.d.ts.map +0 -1
- package/dist/m3/facade.js +0 -58
- package/dist/m3/facade.js.map +0 -1
- package/dist/m3/lioncore.d.ts +0 -41
- package/dist/m3/lioncore.d.ts.map +0 -1
- package/dist/m3/lioncore.js +0 -90
- package/dist/m3/lioncore.js.map +0 -1
- package/dist/version.d.ts +0 -5
- package/dist/version.d.ts.map +0 -1
- package/dist/version.js +0 -5
- package/dist/version.js.map +0 -1
- package/src/m3/builtins.ts +0 -198
- package/src/m3/facade.ts +0 -130
- package/src/version.ts +0 -5
package/src/m3/serializer.ts
CHANGED
|
@@ -1,13 +1,36 @@
|
|
|
1
1
|
import { LionWebJsonChunk } from "@lionweb/json"
|
|
2
2
|
import { serializerWith } from "../serializer.js"
|
|
3
|
-
import {
|
|
3
|
+
import { lioncoreReaderFor } from "./reading-writing.js"
|
|
4
4
|
import { Language } from "./types.js"
|
|
5
|
+
import { LionWebVersion } from "./version.js"
|
|
6
|
+
import { defaultLionWebVersion, 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 defaultLionWebVersion}.
|
|
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 defaultLionWebVersion}).
|
|
24
|
+
*/
|
|
25
|
+
export const serializeLanguagesFor = (data: LanguageSerializationData) => {
|
|
26
|
+
const lionwebVersion = data.lionWebVersion ?? defaultLionWebVersion
|
|
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:
|
|
35
|
+
serializerWith({ reader: lioncoreReaderFor(LionWebVersions.v2023_1) })(languages)
|
|
13
36
|
|
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,
|
|
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)
|
|
@@ -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
|
+
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { lioncoreBuiltinsFacade } from "./builtins.js"
|
|
2
|
+
import { LanguageFactory } from "../../factory.js"
|
|
3
|
+
import { generatedLionCoreKeyFrom, LionCoreFacade } from "../../lioncore-common.js"
|
|
4
4
|
|
|
5
|
-
const lioncoreKey = "LionCore-M3"
|
|
6
5
|
|
|
7
6
|
const factory = new LanguageFactory(
|
|
8
7
|
"LionCore_M3",
|
|
9
|
-
|
|
10
|
-
(...names) => "-id-" + (names
|
|
11
|
-
|
|
8
|
+
"2023.1",
|
|
9
|
+
(...names) => "-id-" + generatedLionCoreKeyFrom(...names),
|
|
10
|
+
generatedLionCoreKeyFrom
|
|
12
11
|
)
|
|
13
12
|
/*
|
|
14
13
|
* ID: `-id-${key}`
|
|
@@ -17,28 +16,25 @@ const factory = new LanguageFactory(
|
|
|
17
16
|
|
|
18
17
|
/**
|
|
19
18
|
* Definition of LionCore in terms of itself.
|
|
19
|
+
*
|
|
20
|
+
* @deprecated Use {@code lioncoreFacade.language} instead.
|
|
20
21
|
*/
|
|
21
22
|
export const lioncore = factory.language.havingKey("LionCore-M3")
|
|
22
23
|
|
|
23
|
-
const { inamed } =
|
|
24
|
-
const { booleanDataType, stringDataType } =
|
|
24
|
+
const { inamed } = lioncoreBuiltinsFacade.classifiers
|
|
25
|
+
const { booleanDataType, stringDataType } = lioncoreBuiltinsFacade.primitiveTypes
|
|
25
26
|
|
|
26
27
|
const ikeyed = factory.interface("IKeyed").extending(inamed)
|
|
27
|
-
|
|
28
28
|
const ikeyed_key = factory.property(ikeyed, "key").ofType(stringDataType)
|
|
29
29
|
|
|
30
30
|
const feature = factory.concept("Feature", true).implementing(ikeyed)
|
|
31
|
-
|
|
32
|
-
const feature_optional = factory.property(feature, "optional").ofType(booleanDataType)
|
|
31
|
+
factory.property(feature, "optional").ofType(booleanDataType)
|
|
33
32
|
|
|
34
33
|
const property = factory.concept("Property", false, feature)
|
|
35
|
-
|
|
36
34
|
const property_type = factory.reference(property, "type")
|
|
37
35
|
|
|
38
36
|
const link = factory.concept("Link", true, feature)
|
|
39
|
-
|
|
40
|
-
const link_multiple = factory.property(link, "multiple").ofType(booleanDataType)
|
|
41
|
-
|
|
37
|
+
factory.property(link, "multiple").ofType(booleanDataType)
|
|
42
38
|
const link_type = factory.reference(link, "type")
|
|
43
39
|
|
|
44
40
|
const containment = factory.concept("Containment", false, link)
|
|
@@ -48,92 +44,73 @@ const reference = factory.concept("Reference", false, link)
|
|
|
48
44
|
const languageEntity = factory.concept("LanguageEntity", true).implementing(ikeyed)
|
|
49
45
|
|
|
50
46
|
const classifier = factory.concept("Classifier", true, languageEntity)
|
|
51
|
-
|
|
52
|
-
const classifier_features = factory.containment(classifier, "features").isOptional().isMultiple().ofType(feature)
|
|
53
|
-
|
|
47
|
+
factory.containment(classifier, "features").isOptional().isMultiple().ofType(feature)
|
|
54
48
|
link_type.ofType(classifier)
|
|
55
49
|
|
|
56
50
|
const annotation = factory.concept("Annotation", false, classifier)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const annotation_extends = factory.reference(annotation, "extends").isOptional().ofType(annotation)
|
|
61
|
-
|
|
51
|
+
factory.reference(annotation, "annotates").isOptional().ofType(classifier)
|
|
52
|
+
factory.reference(annotation, "extends").isOptional().ofType(annotation)
|
|
62
53
|
const annotation_implements = factory.reference(annotation, "implements").isMultiple().isOptional()
|
|
63
54
|
|
|
64
55
|
const concept = factory.concept("Concept", false, classifier)
|
|
65
|
-
|
|
66
56
|
const concept_abstract = factory.property(concept, "abstract").ofType(booleanDataType)
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const concept_extends = factory.reference(concept, "extends").isOptional().ofType(concept)
|
|
71
|
-
|
|
57
|
+
factory.property(concept, "partition").ofType(booleanDataType)
|
|
58
|
+
factory.reference(concept, "extends").isOptional().ofType(concept)
|
|
72
59
|
const concept_implements = factory.reference(concept, "implements").isOptional().isMultiple()
|
|
73
60
|
|
|
74
61
|
const interface_ = factory.concept("Interface", false, classifier)
|
|
75
|
-
|
|
76
|
-
const interface_extends = factory.reference(interface_, "extends").isOptional().isMultiple().ofType(interface_)
|
|
62
|
+
factory.reference(interface_, "extends").isOptional().isMultiple().ofType(interface_)
|
|
77
63
|
|
|
78
64
|
annotation_implements.ofType(interface_)
|
|
79
65
|
concept_implements.ofType(interface_)
|
|
80
66
|
|
|
81
67
|
const dataType = factory.concept("DataType", true, languageEntity)
|
|
82
|
-
|
|
83
68
|
property_type.ofType(dataType)
|
|
84
69
|
|
|
85
70
|
const primitiveType = factory.concept("PrimitiveType", false, dataType)
|
|
86
71
|
|
|
87
72
|
const enumeration = factory.concept("Enumeration", false, dataType)
|
|
88
|
-
|
|
89
73
|
const enumeration_literals = factory.containment(enumeration, "literals").isMultiple().isOptional()
|
|
90
|
-
|
|
91
74
|
const enumerationLiteral = factory.concept("EnumerationLiteral", false).implementing(ikeyed)
|
|
92
|
-
|
|
93
75
|
enumeration_literals.ofType(enumerationLiteral)
|
|
94
76
|
|
|
95
77
|
const language = factory.concept("Language", false).implementing(ikeyed).isPartition()
|
|
96
|
-
|
|
97
78
|
const language_version = factory.property(language, "version").ofType(stringDataType)
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
79
|
+
factory.containment(language, "entities").isOptional().isMultiple().ofType(languageEntity)
|
|
80
|
+
factory.reference(language, "dependsOn").isOptional().isMultiple().ofType(language)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
export const lioncoreFacade: LionCoreFacade = {
|
|
84
|
+
language: factory.language,
|
|
85
|
+
metaConcepts: {
|
|
86
|
+
annotation,
|
|
87
|
+
classifier,
|
|
88
|
+
concept,
|
|
89
|
+
interface: interface_,
|
|
90
|
+
containment,
|
|
91
|
+
enumeration,
|
|
92
|
+
enumerationLiteral,
|
|
93
|
+
ikeyed,
|
|
94
|
+
language,
|
|
95
|
+
primitiveType,
|
|
96
|
+
property,
|
|
97
|
+
reference
|
|
98
|
+
},
|
|
99
|
+
metaFeatures: {
|
|
100
|
+
concept_abstract,
|
|
101
|
+
ikeyed_key,
|
|
102
|
+
language_version
|
|
103
|
+
}
|
|
116
104
|
}
|
|
117
105
|
|
|
118
|
-
export const metaFeatures = {
|
|
119
|
-
annotation_annotates,
|
|
120
|
-
annotation_extends,
|
|
121
|
-
annotation_implements,
|
|
122
|
-
classifier_features,
|
|
123
|
-
concept_abstract,
|
|
124
|
-
concept_partition,
|
|
125
|
-
concept_extends,
|
|
126
|
-
concept_implements,
|
|
127
|
-
interface_extends,
|
|
128
|
-
enumeration_literals,
|
|
129
|
-
feature_optional,
|
|
130
|
-
ikeyed_key,
|
|
131
|
-
language_dependsOn,
|
|
132
|
-
language_entities,
|
|
133
|
-
language_version,
|
|
134
|
-
link_multiple,
|
|
135
|
-
link_type,
|
|
136
|
-
property_type
|
|
137
|
-
}
|
|
138
106
|
|
|
139
|
-
|
|
107
|
+
/**
|
|
108
|
+
* @deprecated Use {@code <LionWeb version>.lioncoreFacade.metaConcepts} instead.
|
|
109
|
+
*/
|
|
110
|
+
export const metaConcepts = lioncoreFacade.metaConcepts
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @deprecated Use {@code <LionWeb version>.lioncoreFacade.metaFeatures} instead.
|
|
114
|
+
*/
|
|
115
|
+
export const metaFeatures = lioncoreFacade.metaFeatures
|
|
116
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { lioncoreBuiltinsFacade } from "./builtins.js"
|
|
2
|
+
import { lioncoreFacade } from "./lioncore.js"
|
|
3
|
+
import { LionWebVersion } from "../../version.js"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A representation of the 2023.1 LionWeb version.
|
|
7
|
+
*/
|
|
8
|
+
export const v2023_1 = new LionWebVersion("2023.1", lioncoreFacade, lioncoreBuiltinsFacade)
|
|
9
|
+
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { v2023_1 } from "./versions/v2023_1/version.js"
|
|
2
|
+
import { LionWebVersion } from "./version.js"
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The *current* release(d) version.
|
|
7
|
+
*
|
|
8
|
+
* @deprecated Use {@code defaultLionWebVersion.serializationFormatVersion} instead.
|
|
9
|
+
*/
|
|
10
|
+
export const currentReleaseVersion = "2023.1"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* An enumeration (as const object) of all LionWeb versions currently supported by the WIP specification.
|
|
15
|
+
*/
|
|
16
|
+
export const LionWebVersions = {
|
|
17
|
+
// LionWeb standard version 2023.1 — defined at https://lionweb.io/specification/2023.1
|
|
18
|
+
v2023_1
|
|
19
|
+
} as const
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* All LionWeb versions.
|
|
23
|
+
*/
|
|
24
|
+
export const allLionWebVersions = Object.values(LionWebVersions)
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The current default LionWeb version.
|
|
28
|
+
*/
|
|
29
|
+
export const defaultLionWebVersion = LionWebVersions.v2023_1
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @return the {@link LionWebVersion} matching the given `serializationFormatVersion` string,
|
|
33
|
+
* or {@link undefined} if there’s none.
|
|
34
|
+
*/
|
|
35
|
+
export const lionWebVersionFrom = (serializationFormatVersion: string): LionWebVersion | undefined =>
|
|
36
|
+
allLionWebVersions.find((version) => version.serializationFormatVersion === serializationFormatVersion)
|
|
37
|
+
|
package/src/reading.ts
CHANGED
|
@@ -51,6 +51,8 @@ export interface Reader<NT extends Node> {
|
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
53
|
* Alias for {@link Reader}, kept for backward compatibility, and to be deprecated and removed later.
|
|
54
|
+
*
|
|
55
|
+
* @deprecated Use {@link Reader} instead.
|
|
54
56
|
*/
|
|
55
57
|
export interface ExtractionFacade<NT extends Node> extends Reader<NT> {}
|
|
56
58
|
|