@lionweb/core 0.6.10 → 0.6.11-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,133 @@
1
+ # Changelog
2
+
3
+ ## 0.6.11 - not officially released yet
4
+
5
+ * Separate CHANGELOG from README.
6
+ * Move the reference util functions (`referenceValues`, `incomingReferences`, `referencesToOutOfScopeNodes`) and type (class `ReferenceValue`) from the `utilities` package to `core`.
7
+ Aliases (as re-exports) are left in its place to avoid code breaking.
8
+ The move is necessary because not all clients of `@lionweb/utilities` can install the Node.js-specific dependencies of the dependencies that package (such as `crypto`).
9
+
10
+
11
+ ## 0.6.10
12
+
13
+ * Make `DefaultPrimitiveTypeDeserializer` and `DefaultPrimitiveTypeSerializer` be able to deal with duplicate definitions of datatypes.
14
+ * Expose a function `shouldBeIdentical` that determines whether two datatypes should be structurally equal based on equality of: meta type, key, and language's key.
15
+ * Make serializer more resilient against unresolved (i.e., `null`-valued) children.
16
+ * Fix that `resolveInfo` of a serialized reference must be `null`, not `undefined`.
17
+
18
+
19
+ ## 0.6.9
20
+
21
+ * Improve deserialization:
22
+ * Produce more meaningful messages for problems
23
+ * Configure how problems are reported through an instance of a `SimplisticHandler`, calling a new function `deserializeLanguagesWithHandler`.
24
+ The default value for the handler is `defaultSimplisticHandler` which just reports the problem to the JavaScript console (using `console.log`).
25
+ The `AccumulatingSimplisticHandler` class accumulates the problems reported, which can be accessed through its `allProblems` method.
26
+ The `AggregatingSimplisticHandler` class aggregates the problems reported (with count), which can be output using its `reportAllProblemsOnConsole` method, and accessed through its `allProblems` method.
27
+ * Pass dependent languages also _as languages_ from languages deserializer to regular deserializer, not just as referable data (which is only useful for the built-ins)
28
+ * Fix a bug in the serializer that caused an "unhelpful" exception on an unset or unresolved — i.e., "not-connected", represented by a `null` value — reference target .
29
+ Now, such reference targets are simply skipped.
30
+
31
+
32
+ ## 0.6.8
33
+
34
+ * With respect to deserialization:
35
+ * Relax deserialization to just skip serialized nodes for which the corresponding M2 data can't be found.
36
+ * Fix a bug w.r.t. enumeration literals — deserializing changed the keys of enumeration literals in the language's definition.
37
+ * Deserialization doesn't throw on unresolvable references, but warns on the console and returns `null` (which means “unresolved”).
38
+ * Export `byIdMap` function, which computes a map id → thing from an array of things with an `id`, from the package.
39
+ * Make `SerializedProperty.value` `null`-able, to align with the specification.
40
+
41
+
42
+ ## 0.6.7
43
+
44
+ * Fix cycle in imports that some bundlers were having trouble with.
45
+
46
+
47
+ ## 0.6.6
48
+
49
+ * The serializer now also serializes annotations.
50
+ * Add support for custom primitive types.
51
+ Specifically:
52
+ * A new interface type `PrimitiveTypeSerializer`.
53
+ * A default implementation `DefaultPrimitiveTypeSerializer` of that that's aware of the LionCore built-in primitive types.
54
+ * `serializeNodes` has an additional argument of type `PrimitiveTypeSerializer` with as default value an instance of `DefaultPrimitiveTypeSerializer`.
55
+
56
+
57
+ ## 0.6.5
58
+
59
+ * Add support for custom primitive types.
60
+ Specifically:
61
+ * A new interface type `PrimitiveTypeDeserializer`.
62
+ * A default implementation `DefaultPrimitiveTypeDeserializer` of that that's aware of the LionCore built-in primitive types.
63
+ * `deserializeSerializationChunk` has an additional argument of type `PrimitiveTypeDeserializer` with as default value an instance of `DefaultPrimitiveTypeDeserializer`.
64
+ * Expose function `inheritsFrom`.
65
+
66
+
67
+ ## 0.6.4
68
+
69
+ * Add functions `mapValues` and `instantiableClassifiers`.
70
+ * Add a method `SymbolTable.languageMatching` to look up a language.
71
+
72
+
73
+ ## 0.6.3
74
+
75
+ * The deserializer now deserializes all nodes in the serialization chunk, not just the root nodes (identified as having `parent` set to `null`).
76
+ (This fixes [issue #145](https://github.com/LionWeb-io/lionweb-typescript/issues/145).)
77
+ * Also: `deserializeChunk` is renamed to `deserializeSerializationChunk` for naming consistency, although `deserializeChunk` is retained as an alias.
78
+ * Add a method `metaType` to M3 types, to deduce classifiers' names from.
79
+ (That fixes [issue #143](https://github.com/LionWeb-io/lionweb-typescript/issues/143).)
80
+
81
+
82
+ ## 0.6.2
83
+
84
+ * Add a method `Classifier.metaPointer`.
85
+
86
+
87
+ ## 0.6.1
88
+
89
+ * Introduce a `isBuiltinNodeConcept` function that checks whether a classifier happens to be the `Node` concept built into LionCore.
90
+ * Add a reference `annotates` to `Annotation`.
91
+
92
+
93
+ ## 0.6.0
94
+
95
+ * Introduce a type `SymbolTable` to encapsulate lookup of languages' entities and their features.
96
+ * Provide a naive and a memoising implementation of the `SymbolTable` abstraction, and use the latter in the deserializer to make that (a bit) more performant.
97
+
98
+
99
+ ## 0.5.0
100
+
101
+ This is the first version corresponding to a release of LionWeb (version: 2023.1) as a whole.
102
+
103
+ * Remove JSON Schema generation functionality – this wasn't up-to-date at all.
104
+ * Implement persistence of annotations on `Node`s, including (de-)serialization.
105
+ * Added an optional field `resolveInfoFor` to the `ExtractionFacade` type, to compute the field `resolveInfo` field of a serialized reference target.
106
+ The default used is to check whether a node instance implements `INamed` and takes the value of the `name` field.
107
+ * _Breaking change:_ `serializeLanguage` and `deserializeLanguage` are now "multi-lingual" in the sense that a serialization chunk can contain multiple `Language`s.
108
+ As a result, these functions have been renamed to (the plural) `serializeLanguages` (with varargs), and `deserializeLanguages` (returning `Language[]`).
109
+ * (Bugfix:) Deserialize `Annotation`s.
110
+ * _Breaking change:_ Rework ID and key generation in the LionCore `LanguageFactory`.
111
+ As part of that:
112
+ * Add `String[s]Mapper` types, a `StringsMapper` instance `last`, and functions `concatenator` and `chain` to produce instances of them.
113
+ * Remove `M3Node.keyed` and the "awkward" key generation in the `InstantiationFacade` for the LionCore language.
114
+ * Remove types `IdGenerator`, and `KeyGenerator` and everything related to that.
115
+ * Expose keys (instead of qualified names) for LionCore M3 and the LionCore built-ins.
116
+ * Add a type `DynamicINamed` and an M3-function `conceptsOf`, primarily for generation purposes.
117
+ * Move `asText` and ID checking to `@lionweb/utilities`.
118
+ * Expose a helper function `nameSorted`.
119
+ * Rename `ConceptInterface` → `Interface`.
120
+ * Change names: `ReadModelAPI` → `ExtractionFacade`, `WriteModelAPI` → `InstantiationFacade`.
121
+ * Change name of `concept` fields to `classifier`, and their types (where applicable) to `Classifier`.
122
+ * Fix `license` field in `package.json` to `"Apache-2.0"`.
123
+ * Replace all occurrences of "LIon" (with uppercase 'I') with "Lion" (with lowercase 'i').
124
+ * Split the `ModelAPI` interface into a read- and write-part: `ReadModelAPI` vs. `WriteModelAPI`.
125
+ * Make fixes w.r.t. multi-language models.
126
+ * Migrate from Deno to Node.js.
127
+ * Implement import of enums in Ecore importer.
128
+
129
+
130
+ ## Prior to 0.5.0
131
+
132
+ No changelog has been kept for previous versions, regardless of whether these were published or not.
133
+
package/README.md CHANGED
@@ -30,123 +30,6 @@ The following is a list of links to potential starting points:
30
30
  * [Serialization](src/serialization.ts).
31
31
 
32
32
 
33
- ## Changelog
34
-
35
- ### 0.6.10 - not officially released yet
36
-
37
- * Make `DefaultPrimitiveTypeDeserializer` and `DefaultPrimitiveTypeSerializer` be able to deal with duplicate definitions of datatypes.
38
- * Expose a function `shouldBeIdentical` that determines whether two datatypes should be structurally equal based on equality of: meta type, key, and language's key.
39
- * Make serializer more resilient against unresolved (i.e., `null`-valued) children.
40
- * Fix that `resolveInfo` of a serialized reference must be `null`, not `undefined`.
41
-
42
-
43
- ### 0.6.9
44
-
45
- * Improve deserialization:
46
- * Produce more meaningful messages for problems
47
- * Configure how problems are reported through an instance of a `SimplisticHandler`, calling a new function `deserializeLanguagesWithHandler`.
48
- The default value for the handler is `defaultSimplisticHandler` which just reports the problem to the JavaScript console (using `console.log`).
49
- The `AccumulatingSimplisticHandler` class accumulates the problems reported, which can be accessed through its `allProblems` method.
50
- The `AggregatingSimplisticHandler` class aggregates the problems reported (with count), which can be output using its `reportAllProblemsOnConsole` method, and accessed through its `allProblems` method.
51
- * Pass dependent languages also _as languages_ from languages deserializer to regular deserializer, not just as referable data (which is only useful for the built-ins)
52
- * Fix a bug in the serializer that caused an "unhelpful" exception on an unset or unresolved — i.e., "not-connected", represented by a `null` value — reference target .
53
- Now, such reference targets are simply skipped.
54
-
55
-
56
- ### 0.6.8
57
-
58
- * With respect to deserialization:
59
- * Relax deserialization to just skip serialized nodes for which the corresponding M2 data can't be found.
60
- * Fix a bug w.r.t. enumeration literals — deserializing changed the keys of enumeration literals in the language's definition.
61
- * Deserialization doesn't throw on unresolvable references, but warns on the console and returns `null` (which means “unresolved”).
62
- * Export `byIdMap` function, which computes a map id → thing from an array of things with an `id`, from the package.
63
- * Make `SerializedProperty.value` `null`-able, to align with the specification.
64
-
65
-
66
- ### 0.6.7
67
-
68
- * Fix cycle in imports that some bundlers were having trouble with.
69
-
70
-
71
- ### 0.6.6
72
-
73
- * The serializer now also serializes annotations.
74
- * Add support for custom primitive types.
75
- Specifically:
76
- * A new interface type `PrimitiveTypeSerializer`.
77
- * A default implementation `DefaultPrimitiveTypeSerializer` of that that's aware of the LionCore built-in primitive types.
78
- * `serializeNodes` has an additional argument of type `PrimitiveTypeSerializer` with as default value an instance of `DefaultPrimitiveTypeSerializer`.
79
-
80
-
81
- ### 0.6.5
82
-
83
- * Add support for custom primitive types.
84
- Specifically:
85
- * A new interface type `PrimitiveTypeDeserializer`.
86
- * A default implementation `DefaultPrimitiveTypeDeserializer` of that that's aware of the LionCore built-in primitive types.
87
- * `deserializeSerializationChunk` has an additional argument of type `PrimitiveTypeDeserializer` with as default value an instance of `DefaultPrimitiveTypeDeserializer`.
88
- * Expose function `inheritsFrom`.
89
-
90
- ### 0.6.4
91
-
92
- * Add functions `mapValues` and `instantiableClassifiers`.
93
- * Add a method `SymbolTable.languageMatching` to look up a language.
94
-
95
- ### 0.6.3
96
-
97
- * The deserializer now deserializes all nodes in the serialization chunk, not just the root nodes (identified as having `parent` set to `null`).
98
- (This fixes [issue #145](https://github.com/LionWeb-io/lionweb-typescript/issues/145).)
99
- * Also: `deserializeChunk` is renamed to `deserializeSerializationChunk` for naming consistency, although `deserializeChunk` is retained as an alias.
100
- * Add a method `metaType` to M3 types, to deduce classifiers' names from.
101
- (That fixes [issue #143](https://github.com/LionWeb-io/lionweb-typescript/issues/143).)
102
-
103
- ### 0.6.2
104
-
105
- * Add a method `Classifier.metaPointer`.
106
-
107
- ### 0.6.1
108
-
109
- * Introduce a `isBuiltinNodeConcept` function that checks whether a classifier happens to be the `Node` concept built into LionCore.
110
- * Add a reference `annotates` to `Annotation`.
111
-
112
- ### 0.6.0
113
-
114
- * Introduce a type `SymbolTable` to encapsulate lookup of languages' entities and their features.
115
- * Provide a naive and a memoising implementation of the `SymbolTable` abstraction, and use the latter in the deserializer to make that (a bit) more performant.
116
-
117
- ### 0.5.0
118
-
119
- This is the first version corresponding to a release of LionWeb (version: 2023.1) as a whole.
120
-
121
- * Remove JSON Schema generation functionality – this wasn't up-to-date at all.
122
- * Implement persistence of annotations on `Node`s, including (de-)serialization.
123
- * Added an optional field `resolveInfoFor` to the `ExtractionFacade` type, to compute the field `resolveInfo` field of a serialized reference target.
124
- The default used is to check whether a node instance implements `INamed` and takes the value of the `name` field.
125
- * _Breaking change:_ `serializeLanguage` and `deserializeLanguage` are now "multi-lingual" in the sense that a serialization chunk can contain multiple `Language`s.
126
- As a result, these functions have been renamed to (the plural) `serializeLanguages` (with varargs), and `deserializeLanguages` (returning `Language[]`).
127
- * (Bugfix:) Deserialize `Annotation`s.
128
- * _Breaking change:_ Rework ID and key generation in the LionCore `LanguageFactory`.
129
- As part of that:
130
- * Add `String[s]Mapper` types, a `StringsMapper` instance `last`, and functions `concatenator` and `chain` to produce instances of them.
131
- * Remove `M3Node.keyed` and the "awkward" key generation in the `InstantiationFacade` for the LionCore language.
132
- * Remove types `IdGenerator`, and `KeyGenerator` and everything related to that.
133
- * Expose keys (instead of qualified names) for LionCore M3 and the LionCore built-ins.
134
- * Add a type `DynamicINamed` and an M3-function `conceptsOf`, primarily for generation purposes.
135
- * Move `asText` and ID checking to `@lionweb/utilities`.
136
- * Expose a helper function `nameSorted`.
137
- * Rename `ConceptInterface` → `Interface`.
138
- * Change names: `ReadModelAPI` → `ExtractionFacade`, `WriteModelAPI` → `InstantiationFacade`.
139
- * Change name of `concept` fields to `classifier`, and their types (where applicable) to `Classifier`.
140
- * Fix `license` field in `package.json` to `"Apache-2.0"`.
141
- * Replace all occurrences of "LIon" (with uppercase 'I') with "Lion" (with lowercase 'i').
142
- * Split the `ModelAPI` interface into a read- and write-part: `ReadModelAPI` vs. `WriteModelAPI`.
143
- * Make fixes w.r.t. multi-language models.
144
- * Migrate from Deno to Node.js.
145
- * Implement import of enums in Ecore importer.
146
-
147
- No changelog has been kept for previous versions, regardless of whether these were published or not.
148
-
149
-
150
33
  ## Development
151
34
 
152
35
  Build it from source as follows:
package/dist/index.d.ts CHANGED
@@ -11,4 +11,5 @@ export * from "./types.js";
11
11
  export * from "./utils/index.js";
12
12
  export * from "./version.js";
13
13
  export * from "./m3/index.js";
14
+ export * from "./m1/reference-utils.js";
14
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA;AAChC,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA;AAChC,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,yBAAyB,CAAA"}
package/dist/index.js CHANGED
@@ -11,4 +11,5 @@ export * from "./types.js";
11
11
  export * from "./utils/index.js";
12
12
  export * from "./version.js";
13
13
  export * from "./m3/index.js";
14
+ export * from "./m1/reference-utils.js";
14
15
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA;AAChC,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA;AAChC,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,yBAAyB,CAAA"}
@@ -0,0 +1,56 @@
1
+ import { Reference } from "../m3/index.js";
2
+ import { ExtractionFacade } from "../facade.js";
3
+ import { Node } from "../types.js";
4
+ /**
5
+ * Represents information about a source and target node related through a {@link Reference}.
6
+ * An index of `null` means that the reference is (at most) single-valued.
7
+ */
8
+ export declare class ReferenceValue<NT extends Node> {
9
+ readonly sourceNode: NT;
10
+ readonly targetNode: NT;
11
+ readonly reference: Reference;
12
+ readonly index: number | null;
13
+ constructor(sourceNode: NT, targetNode: NT, reference: Reference, index: number | null);
14
+ }
15
+ /**
16
+ * Finds all references within the given scope, as {@link ReferenceValue reference values}.
17
+ * To search within all nodes under a collection of root nodes,
18
+ * use _child extraction_ to compute all nodes in the forest hanging off of those root nodes as scope.
19
+ * Note that any reference is found uniquely,
20
+ * i.e. the returned {@link ReferenceValue reference values} are pairwise distinct,
21
+ * even if the scope passed contains duplicate nodes.
22
+ *
23
+ * @param scope - the {@link Node nodes} that are searched for references
24
+ * @param extractionFacade - an {@link ExtractionFacade} to reflect on nodes.
25
+ * _Note_ that it's assumed that its {@link getFeatureValue} function doesn't throw.
26
+ */
27
+ export declare const referenceValues: <NT extends Node>(scope: NT[], extractionFacade: ExtractionFacade<NT>) => ReferenceValue<NT>[];
28
+ /**
29
+ * Finds all references coming into the given target node or any of the given target nodes,
30
+ * within the given scope, as {@link ReferenceValue reference values}.
31
+ * To search within all nodes under a collection of root nodes,
32
+ * use _child extraction_ to compute all nodes in the forest hanging off of those root nodes as scope.
33
+ * Note that any reference is found uniquely,
34
+ * i.e. the returned {@link ReferenceValue reference values} are pairwise distinct,
35
+ * even if the given target nodes or scope contain duplicate nodes.
36
+ *
37
+ * @param targetNodeOrNodes - one or more target {@link Node nodes} for which the incoming references are searched
38
+ * @param scope - the {@link Node nodes} that are searched for references
39
+ * @param extractionFacade - an {@link ExtractionFacade} to reflect on nodes.
40
+ * _Note_ that it's assumed that its {@link getFeatureValue} function doesn't throw.
41
+ */
42
+ export declare const incomingReferences: <NT extends Node>(targetNodeOrNodes: NT | NT[], scope: NT[], extractionFacade: ExtractionFacade<NT>) => ReferenceValue<NT>[];
43
+ /**
44
+ * Finds all references to nodes that are not in the given scope, as {@link ReferenceValue reference values}.
45
+ * To search within all nodes under a collection of root nodes,
46
+ * use _child extraction_ to compute all nodes in the forest hanging off of those root nodes as scope.
47
+ * Note that any reference is found uniquely,
48
+ * i.e. the returned {@link ReferenceValue reference values} are pairwise distinct,
49
+ * even if the given scope contains duplicate nodes.
50
+ *
51
+ * @param scope - the {@link Node nodes} that form the scope of “reachable” nodes
52
+ * @param extractionFacade - an {@link ExtractionFacade} to reflect on nodes.
53
+ * _Note_ that it's assumed that its {@link getFeatureValue} function doesn't throw.
54
+ */
55
+ export declare const referencesToOutOfScopeNodes: <NT extends Node>(scope: NT[], extractionFacade: ExtractionFacade<NT>) => ReferenceValue<NT>[];
56
+ //# sourceMappingURL=reference-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reference-utils.d.ts","sourceRoot":"","sources":["../../src/m1/reference-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,SAAS,EAAC,MAAM,gBAAgB,CAAA;AACvD,OAAO,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAC,IAAI,EAAC,MAAM,aAAa,CAAA;AAGhC;;;GAGG;AACH,qBAAa,cAAc,CAAC,EAAE,SAAS,IAAI;aAEnB,UAAU,EAAE,EAAE;aACd,UAAU,EAAE,EAAE;aACd,SAAS,EAAE,SAAS;aACpB,KAAK,EAAE,MAAM,GAAG,IAAI;gBAHpB,UAAU,EAAE,EAAE,EACd,UAAU,EAAE,EAAE,EACd,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,MAAM,GAAG,IAAI;CAE3C;AAGD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,gGA4B3B,CAAA;AAGD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,kBAAkB,8HAQ9B,CAAA;AAGD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,2BAA2B,gGAK4C,CAAA"}
@@ -0,0 +1,78 @@
1
+ import { allFeaturesOf, Reference } from "../m3/index.js";
2
+ /**
3
+ * Represents information about a source and target node related through a {@link Reference}.
4
+ * An index of `null` means that the reference is (at most) single-valued.
5
+ */
6
+ export class ReferenceValue {
7
+ constructor(sourceNode, targetNode, reference, index) {
8
+ this.sourceNode = sourceNode;
9
+ this.targetNode = targetNode;
10
+ this.reference = reference;
11
+ this.index = index;
12
+ }
13
+ }
14
+ /**
15
+ * Finds all references within the given scope, as {@link ReferenceValue reference values}.
16
+ * To search within all nodes under a collection of root nodes,
17
+ * use _child extraction_ to compute all nodes in the forest hanging off of those root nodes as scope.
18
+ * Note that any reference is found uniquely,
19
+ * i.e. the returned {@link ReferenceValue reference values} are pairwise distinct,
20
+ * even if the scope passed contains duplicate nodes.
21
+ *
22
+ * @param scope - the {@link Node nodes} that are searched for references
23
+ * @param extractionFacade - an {@link ExtractionFacade} to reflect on nodes.
24
+ * _Note_ that it's assumed that its {@link getFeatureValue} function doesn't throw.
25
+ */
26
+ export const referenceValues = (scope, extractionFacade) => {
27
+ const visit = (sourceNode, reference) => {
28
+ if (reference.multiple) {
29
+ const targetNodes = extractionFacade.getFeatureValue(sourceNode, reference) ?? [];
30
+ return targetNodes
31
+ .map((targetNode, index) => new ReferenceValue(sourceNode, targetNode, reference, index));
32
+ }
33
+ const targetNode = extractionFacade.getFeatureValue(sourceNode, reference);
34
+ if (targetNode !== undefined) {
35
+ return [new ReferenceValue(sourceNode, targetNode, reference, null)];
36
+ }
37
+ return [];
38
+ };
39
+ return [...new Set(scope)] // ~ .distinct()
40
+ .flatMap((sourceNode) => allFeaturesOf(extractionFacade.classifierOf(sourceNode))
41
+ .filter((feature) => feature instanceof Reference)
42
+ .map((feature) => feature)
43
+ .flatMap((reference) => visit(sourceNode, reference)));
44
+ };
45
+ /**
46
+ * Finds all references coming into the given target node or any of the given target nodes,
47
+ * within the given scope, as {@link ReferenceValue reference values}.
48
+ * To search within all nodes under a collection of root nodes,
49
+ * use _child extraction_ to compute all nodes in the forest hanging off of those root nodes as scope.
50
+ * Note that any reference is found uniquely,
51
+ * i.e. the returned {@link ReferenceValue reference values} are pairwise distinct,
52
+ * even if the given target nodes or scope contain duplicate nodes.
53
+ *
54
+ * @param targetNodeOrNodes - one or more target {@link Node nodes} for which the incoming references are searched
55
+ * @param scope - the {@link Node nodes} that are searched for references
56
+ * @param extractionFacade - an {@link ExtractionFacade} to reflect on nodes.
57
+ * _Note_ that it's assumed that its {@link getFeatureValue} function doesn't throw.
58
+ */
59
+ export const incomingReferences = (targetNodeOrNodes, scope, extractionFacade) => {
60
+ const targetNodes = Array.isArray(targetNodeOrNodes) ? targetNodeOrNodes : [targetNodeOrNodes];
61
+ return referenceValues(scope, extractionFacade)
62
+ .filter((referenceValue) => targetNodes.indexOf(referenceValue.targetNode) > -1);
63
+ };
64
+ /**
65
+ * Finds all references to nodes that are not in the given scope, as {@link ReferenceValue reference values}.
66
+ * To search within all nodes under a collection of root nodes,
67
+ * use _child extraction_ to compute all nodes in the forest hanging off of those root nodes as scope.
68
+ * Note that any reference is found uniquely,
69
+ * i.e. the returned {@link ReferenceValue reference values} are pairwise distinct,
70
+ * even if the given scope contains duplicate nodes.
71
+ *
72
+ * @param scope - the {@link Node nodes} that form the scope of “reachable” nodes
73
+ * @param extractionFacade - an {@link ExtractionFacade} to reflect on nodes.
74
+ * _Note_ that it's assumed that its {@link getFeatureValue} function doesn't throw.
75
+ */
76
+ export const referencesToOutOfScopeNodes = (scope, extractionFacade) => referenceValues(scope, extractionFacade)
77
+ .filter((referenceValue) => scope.indexOf(referenceValue.targetNode) === -1);
78
+ //# sourceMappingURL=reference-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reference-utils.js","sourceRoot":"","sources":["../../src/m1/reference-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,SAAS,EAAC,MAAM,gBAAgB,CAAA;AAKvD;;;GAGG;AACH,MAAM,OAAO,cAAc;IACvB,YACoB,UAAc,EACd,UAAc,EACd,SAAoB,EACpB,KAAoB;QAHpB,eAAU,GAAV,UAAU,CAAI;QACd,eAAU,GAAV,UAAU,CAAI;QACd,cAAS,GAAT,SAAS,CAAW;QACpB,UAAK,GAAL,KAAK,CAAe;IACrC,CAAC;CACP;AAGD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC3B,KAAW,EACX,gBAAsC,EAClB,EAAE;IACtB,MAAM,KAAK,GAAG,CAAC,UAAc,EAAE,SAAoB,EAAwB,EAAE;QACzE,IAAI,SAAS,CAAC,QAAQ,EAAE,CAAC;YACrB,MAAM,WAAW,GAAG,gBAAgB,CAAC,eAAe,CAAC,UAAU,EAAE,SAAS,CAAS,IAAI,EAAE,CAAA;YACzF,OAAO,WAAW;iBACb,GAAG,CAAC,CAAC,UAAU,EAAE,KAAK,EAAE,EAAE,CACvB,IAAI,cAAc,CAAK,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,CAAC,CACnE,CAAA;QACT,CAAC;QAED,MAAM,UAAU,GAAG,gBAAgB,CAAC,eAAe,CAAC,UAAU,EAAE,SAAS,CAAqB,CAAA;QAC9F,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC3B,OAAO,CAAC,IAAI,cAAc,CAAK,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC,CAAA;QAC5E,CAAC;QAED,OAAO,EAAE,CAAA;IACb,CAAC,CAAA;IAED,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAE,gBAAgB;SACvC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE,CACpB,aAAa,CAAC,gBAAgB,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;SACnD,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,YAAY,SAAS,CAAC;SACjD,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAoB,CAAC;SACtC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,CAC5D,CAAA;AACT,CAAC,CAAA;AAGD;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAC9B,iBAA4B,EAC5B,KAAW,EACX,gBAAsC,EAClB,EAAE;IACtB,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAA;IAC9F,OAAO,eAAe,CAAC,KAAK,EAAE,gBAAgB,CAAC;SAC1C,MAAM,CAAC,CAAC,cAAc,EAAE,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;AACxF,CAAC,CAAA;AAGD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CACvC,KAAW,EACX,gBAAsC,EAClB,EAAE,CACtB,eAAe,CAAC,KAAK,EAAE,gBAAgB,CAAC;KACnC,MAAM,CAAC,CAAC,cAAc,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lionweb/core",
3
- "version": "0.6.10",
3
+ "version": "0.6.11-beta.0",
4
4
  "description": "LionWeb core for {Java|Type}Script",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",