@lionweb/class-core 0.6.13-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.
Files changed (143) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +157 -0
  3. package/dist/base-types.d.ts +167 -0
  4. package/dist/base-types.d.ts.map +1 -0
  5. package/dist/base-types.js +147 -0
  6. package/dist/base-types.js.map +1 -0
  7. package/dist/convenience.d.ts +49 -0
  8. package/dist/convenience.d.ts.map +1 -0
  9. package/dist/convenience.js +75 -0
  10. package/dist/convenience.js.map +1 -0
  11. package/dist/deltas/appliers.d.ts +42 -0
  12. package/dist/deltas/appliers.d.ts.map +1 -0
  13. package/dist/deltas/appliers.js +274 -0
  14. package/dist/deltas/appliers.js.map +1 -0
  15. package/dist/deltas/base.d.ts +6 -0
  16. package/dist/deltas/base.d.ts.map +1 -0
  17. package/dist/deltas/base.js +18 -0
  18. package/dist/deltas/base.js.map +1 -0
  19. package/dist/deltas/handlers.d.ts +17 -0
  20. package/dist/deltas/handlers.d.ts.map +1 -0
  21. package/dist/deltas/handlers.js +43 -0
  22. package/dist/deltas/handlers.js.map +1 -0
  23. package/dist/deltas/index.d.ts +7 -0
  24. package/dist/deltas/index.d.ts.map +1 -0
  25. package/dist/deltas/index.js +23 -0
  26. package/dist/deltas/index.js.map +1 -0
  27. package/dist/deltas/inverters.d.ts +7 -0
  28. package/dist/deltas/inverters.d.ts.map +1 -0
  29. package/dist/deltas/inverters.js +82 -0
  30. package/dist/deltas/inverters.js.map +1 -0
  31. package/dist/deltas/serialization/base.d.ts +7 -0
  32. package/dist/deltas/serialization/base.d.ts.map +1 -0
  33. package/dist/deltas/serialization/base.js +18 -0
  34. package/dist/deltas/serialization/base.js.map +1 -0
  35. package/dist/deltas/serialization/deserializer.g.d.ts +5 -0
  36. package/dist/deltas/serialization/deserializer.g.d.ts.map +1 -0
  37. package/dist/deltas/serialization/deserializer.g.js +164 -0
  38. package/dist/deltas/serialization/deserializer.g.js.map +1 -0
  39. package/dist/deltas/serialization/index.d.ts +5 -0
  40. package/dist/deltas/serialization/index.d.ts.map +1 -0
  41. package/dist/deltas/serialization/index.js +21 -0
  42. package/dist/deltas/serialization/index.js.map +1 -0
  43. package/dist/deltas/serialization/serializer-helpers.d.ts +12 -0
  44. package/dist/deltas/serialization/serializer-helpers.d.ts.map +1 -0
  45. package/dist/deltas/serialization/serializer-helpers.js +28 -0
  46. package/dist/deltas/serialization/serializer-helpers.js.map +1 -0
  47. package/dist/deltas/serialization/serializer.g.d.ts +4 -0
  48. package/dist/deltas/serialization/serializer.g.d.ts.map +1 -0
  49. package/dist/deltas/serialization/serializer.g.js +208 -0
  50. package/dist/deltas/serialization/serializer.g.js.map +1 -0
  51. package/dist/deltas/serialization/types.g.d.ts +147 -0
  52. package/dist/deltas/serialization/types.g.d.ts.map +1 -0
  53. package/dist/deltas/serialization/types.g.js +18 -0
  54. package/dist/deltas/serialization/types.g.js.map +1 -0
  55. package/dist/deltas/types.g.d.ts +149 -0
  56. package/dist/deltas/types.g.d.ts.map +1 -0
  57. package/dist/deltas/types.g.js +180 -0
  58. package/dist/deltas/types.g.js.map +1 -0
  59. package/dist/deserializer.d.ts +27 -0
  60. package/dist/deserializer.d.ts.map +1 -0
  61. package/dist/deserializer.js +168 -0
  62. package/dist/deserializer.js.map +1 -0
  63. package/dist/duplicator.d.ts +19 -0
  64. package/dist/duplicator.d.ts.map +1 -0
  65. package/dist/duplicator.js +87 -0
  66. package/dist/duplicator.js.map +1 -0
  67. package/dist/id-mapping.d.ts +19 -0
  68. package/dist/id-mapping.d.ts.map +1 -0
  69. package/dist/id-mapping.js +44 -0
  70. package/dist/id-mapping.js.map +1 -0
  71. package/dist/index.d.ts +11 -0
  72. package/dist/index.d.ts.map +1 -0
  73. package/dist/index.js +28 -0
  74. package/dist/index.js.map +1 -0
  75. package/dist/linking.d.ts +20 -0
  76. package/dist/linking.d.ts.map +1 -0
  77. package/dist/linking.js +18 -0
  78. package/dist/linking.js.map +1 -0
  79. package/dist/lionCore_builtins.g.d.ts +35 -0
  80. package/dist/lionCore_builtins.g.d.ts.map +1 -0
  81. package/dist/lionCore_builtins.g.js +96 -0
  82. package/dist/lionCore_builtins.g.js.map +1 -0
  83. package/dist/serializer.d.ts +17 -0
  84. package/dist/serializer.d.ts.map +1 -0
  85. package/dist/serializer.js +70 -0
  86. package/dist/serializer.js.map +1 -0
  87. package/dist/textualizer.d.ts +7 -0
  88. package/dist/textualizer.d.ts.map +1 -0
  89. package/dist/textualizer.js +82 -0
  90. package/dist/textualizer.js.map +1 -0
  91. package/dist/value-managers/annotations.d.ts +33 -0
  92. package/dist/value-managers/annotations.d.ts.map +1 -0
  93. package/dist/value-managers/annotations.js +192 -0
  94. package/dist/value-managers/annotations.js.map +1 -0
  95. package/dist/value-managers/base.d.ts +53 -0
  96. package/dist/value-managers/base.d.ts.map +1 -0
  97. package/dist/value-managers/base.js +102 -0
  98. package/dist/value-managers/base.js.map +1 -0
  99. package/dist/value-managers/containments.d.ts +58 -0
  100. package/dist/value-managers/containments.d.ts.map +1 -0
  101. package/dist/value-managers/containments.js +408 -0
  102. package/dist/value-managers/containments.js.map +1 -0
  103. package/dist/value-managers/index.d.ts +6 -0
  104. package/dist/value-managers/index.d.ts.map +1 -0
  105. package/dist/value-managers/index.js +22 -0
  106. package/dist/value-managers/index.js.map +1 -0
  107. package/dist/value-managers/properties.d.ts +24 -0
  108. package/dist/value-managers/properties.d.ts.map +1 -0
  109. package/dist/value-managers/properties.js +191 -0
  110. package/dist/value-managers/properties.js.map +1 -0
  111. package/dist/value-managers/references.d.ts +58 -0
  112. package/dist/value-managers/references.d.ts.map +1 -0
  113. package/dist/value-managers/references.js +346 -0
  114. package/dist/value-managers/references.js.map +1 -0
  115. package/package.json +35 -0
  116. package/src/base-types.ts +353 -0
  117. package/src/convenience.ts +101 -0
  118. package/src/deltas/appliers.ts +317 -0
  119. package/src/deltas/base.ts +23 -0
  120. package/src/deltas/handlers.ts +64 -0
  121. package/src/deltas/index.ts +23 -0
  122. package/src/deltas/inverters.ts +111 -0
  123. package/src/deltas/serialization/base.ts +26 -0
  124. package/src/deltas/serialization/deserializer.g.ts +193 -0
  125. package/src/deltas/serialization/index.ts +22 -0
  126. package/src/deltas/serialization/serializer-helpers.ts +36 -0
  127. package/src/deltas/serialization/serializer.g.ts +272 -0
  128. package/src/deltas/serialization/types.g.ts +209 -0
  129. package/src/deltas/types.g.ts +231 -0
  130. package/src/deserializer.ts +234 -0
  131. package/src/duplicator.ts +111 -0
  132. package/src/id-mapping.ts +58 -0
  133. package/src/index.ts +29 -0
  134. package/src/linking.ts +39 -0
  135. package/src/lionCore_builtins.g.ts +141 -0
  136. package/src/serializer.ts +86 -0
  137. package/src/textualizer.ts +104 -0
  138. package/src/value-managers/annotations.ts +139 -0
  139. package/src/value-managers/base.ts +123 -0
  140. package/src/value-managers/containments.ts +323 -0
  141. package/src/value-managers/index.ts +22 -0
  142. package/src/value-managers/properties.ts +127 -0
  143. package/src/value-managers/references.ts +268 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 TRUMPF Laser SE and other contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,157 @@
1
+ # README
2
+
3
+ This NPM package holds the generic, language-**a**specific base layer for generated TypeScript APIs.
4
+ This base layer includes reflectivity, support for the **delta protocol** and observability through [the MobX framework](https://mobx.js.org/README.html).
5
+ In addition, it contains functions that provide (de-)serialization and some convenience.
6
+
7
+
8
+ ## Installation
9
+
10
+ Run the following command to add this package to an NPM-based project:
11
+
12
+ ```shell
13
+ npm add @lionweb/class-core
14
+ ```
15
+
16
+ This adds this package as a dependency to your NPM-based project.
17
+
18
+ *Note* that this package is typically a direct dependency of API packages, and possibly re-exported from those to avoid having to add it as a separate dependency.
19
+
20
+
21
+ ## Direct usage
22
+
23
+ The following top-level members of this package are suitable and intended to be used directly.
24
+
25
+ * `allNodesFrom` — Computes all descendant nodes from the given node, including that node itself.
26
+
27
+ * `deepClonerFor` — Given `ILanguageBase`s and an optional `DeltaHandler`, it returns a function that clones the given nodes, *without* altering the IDs.
28
+
29
+ * `deepCopierFor` — Given `ILanguageBase`s and an optional `DeltaHandler`, it returns a function that clones the given nodes, generating new IDs for all the duplicated nodes.
30
+
31
+ * `incomingReferences` — Finds all references coming into the given target node or any of the given target nodes, within the given search scope.
32
+
33
+ * `nodeBaseDeserializerWithIdMapping` — Returns a `Deserializer` function for the given languages (given as `ILanguageBase`s) that, given a serialization chunk, returns an object with the `roots` of the model (as `INodeBase`s) and an instance `idMapping` of the `IdMapping` class (see below).
34
+
35
+ * `nodeBaseDeserializer` — Returns a `Deserializer` function for the given languages (given as `ILanguageBase`s) that, given a serialization chunk, returns the roots of the model (as `INodeBase`s).
36
+
37
+ * `serializeNodeBases` — Returns a serialization of the given nodes (of type `INodeBase`) as a `SerializationChunk`.
38
+
39
+ * A version of the LionCore builtins language, compatible with the `class-core` base types:
40
+ * `LionCore_builtinsBase` reflective class – implements `ILanguageBase`,
41
+ * the abstract `Node` class (corresponding to the `Node` interface, unfortunately of the same name),
42
+ * the `INamed` interface,
43
+ * and the `String`, `Boolean`, `Integer`, and `JSON` (*) primitive types.
44
+ *) To be deprecated in version 2024.1 of LionWeb.
45
+
46
+ The `IdMapping` class should not be used directly but is exposed (as a type) because an instance of it is returned by the `nodeBaseDeserializerWithIdMapping` function.
47
+
48
+ ### Specifically for deltas and changes
49
+
50
+ The list above does not contain the top-level members of this package specifically pertain to the implementation of the delta protocol:
51
+
52
+ * All deltas implement the `IDelta` interface.
53
+
54
+ * The `DeltaHandler` type represents functions that handles a delta.
55
+ Such a function has to be passed to invocations `<concrete classifier>.create(<id>, <handleDelta>)` and various other places, in order to “hook up” to the delta protocol.
56
+ Such a place is recognizable from the presence of an argument `handleDelta?: DeltaHandler`.
57
+
58
+ * Deltas can be applied to a model state using the `applyDelta[s]` and `applyDelta[s]applyDeltaWithLookup` functions.
59
+ The functions with plural `Deltas` in their names apply the given array of `IDelta`s in that order.
60
+ The functions with the `WithLookup` postfix in their names take an additional `IdMapping` instance, and apply the given delta(s) to the nodes managed by that ID mapping.
61
+
62
+ * The `invertDelta` function *inverts* a given `IDelta` instance, in the sense that it undoes that delta after it has been applied.
63
+
64
+ * The `deltaDeserializer` function deserializes previously-serialized deltas (of type `SerializedDelta`)
65
+
66
+ * The `serializeDelta` function serializes a given `IDelta` as a `SerializedDelta`.
67
+
68
+
69
+ ## Architecture
70
+
71
+ ### Base types
72
+
73
+ The starting point of this package is the `INodeBase` interface, which is a specialization (extension) of the `Node` interface from `@lionweb/core`.
74
+ The abstract class `NodeBase` is its implementation which is used exclusively to extend from by classes corresponding to LionWeb classifiers.
75
+ Everywhere else, you'll see `INodeBase` being referenced.
76
+ A node object represented as an `INodeBase` has (at least) the following characteristics:
77
+
78
+ 1. It knows whether and how it's contained by a parent.
79
+ 2. It knows what its classifier is.
80
+ 3. It manages the values of its features through *value managers* (see below) that are wired up for observability (according to the MobX framework) and emission of deltas according to the delta protocol.
81
+
82
+ An implementation of the `ILanguageBase` interface captures three base aspects of a language:
83
+
84
+ 1. Its language definition of type `Language` as a static member `INSTANCE`.
85
+ 2. A `factory` method that – given an optional `DeltaHandler` produces a `NodeBaseFactory`, which (in turn) is a function that, given a `Classifier` instance, produces the appropriate `INodeBase` instance with the provided `id`, `classifier`, and `handleDelta` arguments.
86
+ 3. A `enumLiteralFrom` method that produces a runtime representation of a given `EnumerationLiteral`.
87
+
88
+ ### Value managers
89
+
90
+ A value manager is an object that manages either the value on a node object of a specific feature of a classifier (a feature value manager), or the annotations on a node object (an annotations value manager).
91
+ Every feature value manager is a subclass of `FeatureValueManager`.
92
+ A concrete implementation exists for every (combination of) feature meta kind (property, containment, reference) and cardinality, as determined by the `optional` flag of a feature, and the `multiple` flag of a *link* – i.e.: containment or reference – feature.
93
+ (A flag is a boolean field.)
94
+
95
+ The following table explains the notation we use from here on for cardinalities:
96
+
97
+ | *notation* | optional | multiple (link only) |
98
+ |------------|----------|----------------------|
99
+ | 1 | false | false |
100
+ | 0..1 | true | false |
101
+ | 1..* | false | true |
102
+ | 0..* | true | true |
103
+
104
+ (This notation for cardinality is aligned with MPS.)
105
+
106
+ All value managers provide the following members:
107
+
108
+ * A `property`, `containment`, or `reference` getter that returns the `Feature` (of the corresponding subtype) this instance manages the values for.
109
+ * An `isSet` method that returns whether the feature managed has a value set.
110
+
111
+ Beyond this, all value managers expose various (and varying) methods to access the managed values, and to manipulate them.
112
+ These methods come in two varieties:
113
+
114
+ * *With* a `Directly` postfix:
115
+ These only update the underlying managed and observable value(s), including updating ***parentage*** – i.e.: the way that node members of the value are contained by their parent node – for children and annotation, and MobX gets notified about the change.
116
+ **Note** that the current implementation doesn't follow the rule that these `Directly` methods also update parentage everywhere yet.
117
+ * *Without* that postfix:
118
+ These methods first check against the cardinality of the feature, throwing an appropriate `Error` if the managed value or its intended state change doesn't match the cardinality.
119
+ If they don't throw an error, they proceed to call the corresponding method with `Directly` postfix, and also emit the appropriate delta.
120
+
121
+ There are two value manager classes for properties, for cardinalities `1` and `0..1`.
122
+ Both expose 2x2 methods: `get[Directly]`, and `set[Directly]`.
123
+ These do the obvious things.
124
+
125
+ All link – i.e.: containment and reference – value managers expose the following methods:
126
+
127
+ * `get[Directly]` — Returns the managed value whose type is directly dependent on the details of the feature.
128
+ * `set[Directly]` — Sets the managed value of a single-valued link feature.
129
+ * `add[Directly]` — Adds the given value to the managed value.
130
+ For a single-valued link, an `Error` is thrown when a value was already present.
131
+ The `addDirectly` method is specifically used by the deserializer and deep-cloner/-copier.
132
+
133
+ All multi-valued link value managers also expose the following methods:
134
+
135
+ * `insertAtIndex[Directly]` — Inserts the given node at the specified index, shifting all already-present nodes “to the right” – i.e.: incrementing their indices.
136
+ (It throws if the specified index is invalid.)
137
+ * `removeDirectly[Directly]` — Removes the given node from the nodes in the managed value.
138
+ If the given node is not present, nothing happens.
139
+ If the given node is present more than once, only the first one gets removed.
140
+ * `move[Directly]` — Moves the node at the given old index to the new index, shifting any remaining nodes accordingly.
141
+
142
+ There's only one class for annotation: `AnnotationsValueManager`.
143
+ It exposes the following API:
144
+
145
+ * `get` — Returns the annotations.
146
+ (There's no `getDirectly` here.)
147
+ * `add[Directly]` — Appends the given annotation to the end of the array of annotations.
148
+ * `insertAtIndex[Directly]` — Inserts the given annotation at the specified index, shifting all already-present annotations “to the right” – i.e.: incrementing their indices.
149
+ (It throws if the specified index is invalid.)
150
+ * `move[Directly]` — Moves the annotation at the given “old” index to the “new” index.
151
+ (It throws if either of the specified indices are invalid.)
152
+ * `replaceAtIndex[Directly]` - Replaces the annotation at the specified index with the given annotation.
153
+ (It throws if the specified index is invalid.)
154
+ * `remove[Directly]` — Removes the given annotation from the managed annotations.
155
+ If the given annotation is not present, nothing happens.
156
+ If the given annotation is present more than once, only the first one gets removed.
157
+
@@ -0,0 +1,167 @@
1
+ import { Classifier, Containment, EnumerationLiteral, Feature, Id, Language, Node, Property, Reference } from "@lionweb/core";
2
+ import { AnnotationsValueManager, ContainmentValueManager, DeltaHandler, FeatureValueManager, PropertyValueManager, ReferenceValueManager } from "./index.js";
3
+ /**
4
+ * Encodes how a {@link INodeBase} is contained by a parent.
5
+ * If the {@code containingFeature} is {@code null}, the {@link INodeBase} is an annotation
6
+ * and effectively contained by the {@link INodeBase.annotations} property.
7
+ */
8
+ export type Parentage = [parent: INodeBase, containingFeature: Containment | null];
9
+ /**
10
+ * The base interface for node objects that know about how they're contained,
11
+ * know what their {@link Classifier meta-type} is,
12
+ * and manage the values of their features through {@link ValueManager value managers}
13
+ * that are wired up for observability (according to the MobX library) and emission of deltas.
14
+ */
15
+ export interface INodeBase extends Node {
16
+ classifier: Classifier;
17
+ /**
18
+ * The parent of this node object,
19
+ * or {@code undefined} if it's either a root (in which case it {@code this.classifier} should be a {@link Concept} which is a partition)
20
+ * or (currently/temporarily) an orphan.
21
+ */
22
+ parent: INodeBase | undefined;
23
+ /**
24
+ * The {@link Containment containment feature} through which this node is contained by its parent,
25
+ * or `null` if it's an annotation,
26
+ * or `undefined` exactly when `parent` is also `undefined`.
27
+ */
28
+ containment: Containment | null | undefined;
29
+ /**
30
+ * Attach this node to the given `parent` {@link INodeBase}, through the given `containment` {@link Containment}.
31
+ *Note* that this is **for internal use only**!
32
+ */
33
+ attachTo(parent: INodeBase, containment: Containment | null): void;
34
+ /**
35
+ * Detach this node from its stated parent(age).
36
+ * *Note* that this is **for internal use only**!
37
+ */
38
+ detach(): void;
39
+ /**
40
+ * @return the value manager for the given {@link Property property} feature.
41
+ * @throws if this node('s {@link Classifier classifier}) doesn't have that property.
42
+ */
43
+ getPropertyValueManager(property: Property): PropertyValueManager<unknown>;
44
+ /**
45
+ * @return the value manager for the given {@link Containment containment} feature.
46
+ * @throws if this node('s {@link Classifier classifier}) doesn't have that containment.
47
+ */
48
+ getContainmentValueManager(containment: Containment): ContainmentValueManager<INodeBase>;
49
+ /**
50
+ * @return the value manager for the given {@link Reference reference} feature.
51
+ * @throws if this node('s {@link Classifier classifier}) doesn't have that reference.
52
+ */
53
+ getReferenceValueManager(reference: Reference): ReferenceValueManager<INodeBase>;
54
+ /**
55
+ * @return the value manager for the given {@link Feature feature}.
56
+ * @throws if this node('s {@link Classifier classifier}) doesn't have that feature.
57
+ */
58
+ getFeatureValueManager(feature: Feature): FeatureValueManager<Feature>;
59
+ /**
60
+ * @return the value manager for the annotations.
61
+ */
62
+ annotationsValueManager: AnnotationsValueManager;
63
+ /**
64
+ * The annotations annotating this node.
65
+ */
66
+ annotations: INodeBase[];
67
+ /**
68
+ * Adds the given annotation (as an instance of {@link INodeBase}) to the annotations of this node.
69
+ */
70
+ addAnnotation(annotation: INodeBase): void;
71
+ /**
72
+ * Inserts the given annotation (as an instance of {@link INodeBase}) among the annotations of this node,
73
+ * displacing all existing annotations with index &geq; the given one “to the right”.
74
+ */
75
+ insertAnnotationAtIndex(annotation: INodeBase, index: number): void;
76
+ /**
77
+ * Moves the annotation at the given `oldIndex` to the `newIndex` position.
78
+ */
79
+ moveAnnotation(oldIndex: number, newIndex: number): void;
80
+ /**
81
+ * Replaces the existing annotation at the given index, with the given annotation (as an instance of {@link INodeBase}).
82
+ */
83
+ replaceAnnotationAtIndex(annotation: INodeBase, index: number): void;
84
+ /**
85
+ * Removes the given annotation (as an instance of {@link INodeBase}) from the annotations of this node.
86
+ * (In the case of duplicates, only the first occurrence is removed.)
87
+ */
88
+ removeAnnotation(annotation: INodeBase): void;
89
+ /**
90
+ * @return the {@link Feature features} of the {@link Classifier} that is this node's meta-type,
91
+ * that are set.
92
+ * A feature has a set value if it's not `undefined` for single-valued features,
93
+ * or an empty array `[]` for multi-valued features.
94
+ *
95
+ * Note* that this is (in principle) **for internal use only**!
96
+ */
97
+ get setFeatures(): Feature[];
98
+ /**
99
+ * @return all children – not all descendants! – of this node, including directly-contained annotations.
100
+ *Note* that this is (in principle) **for internal use only**!
101
+ */
102
+ get children(): INodeBase[];
103
+ /**
104
+ * An optionally-installed {@link DeltaHandler}.
105
+ */
106
+ handleDelta?: DeltaHandler;
107
+ /**
108
+ * A message to indicate this node's meta-type (including originating language) and its ID.
109
+ */
110
+ locationMessage: string;
111
+ }
112
+ /**
113
+ * The base type for any node that's managed by a, potentially delta-emitting, API.
114
+ *
115
+ * It receives a {@link DeltaHandler} to pass {@link IDelta deltas} to
116
+ * that occur due to changes to values of its features,
117
+ * as well as moving among parents and deletion.
118
+ *
119
+ * It keeps explicit track of how it's contained by its parent (when it has one),
120
+ * to make moving children among parents easier.
121
+ */
122
+ export declare abstract class NodeBase implements INodeBase {
123
+ readonly classifier: Classifier;
124
+ readonly id: Id;
125
+ readonly handleDelta?: DeltaHandler | undefined;
126
+ private _parentage?;
127
+ get parent(): INodeBase | undefined;
128
+ get containment(): Containment | null | undefined;
129
+ attachTo(parent: INodeBase, containingFeature: Containment | null): void;
130
+ detach(): void;
131
+ protected constructor(classifier: Classifier, id: Id, handleDelta?: DeltaHandler | undefined, parentage?: Parentage);
132
+ get locationMessage(): string;
133
+ getPropertyValueManager(property: Property): PropertyValueManager<unknown>;
134
+ getContainmentValueManager(containment: Containment): ContainmentValueManager<INodeBase>;
135
+ getReferenceValueManager(reference: Reference): ReferenceValueManager<INodeBase>;
136
+ getFeatureValueManager(feature: Feature): FeatureValueManager<Feature>;
137
+ get setFeatures(): Feature[];
138
+ get children(): INodeBase[];
139
+ readonly annotationsValueManager: AnnotationsValueManager;
140
+ get annotations(): INodeBase[];
141
+ addAnnotation(annotation: INodeBase): void;
142
+ insertAnnotationAtIndex(annotation: INodeBase, index: number): void;
143
+ moveAnnotation(oldIndex: number, newIndex: number): void;
144
+ replaceAnnotationAtIndex(annotation: INodeBase, index: number): void;
145
+ removeAnnotation(annotation: INodeBase): void;
146
+ }
147
+ /**
148
+ * A type for functions that acts as factories, creating an instance of {@link INodeBase}
149
+ * matching the given {@link Classifier classifier} and the given ID (of type {@link Id}).
150
+ */
151
+ export type NodeBaseFactory = (classifier: Classifier, id: Id) => INodeBase;
152
+ /**
153
+ * A type that captures three base aspects of a language:
154
+ * its {@link Language definition},
155
+ * a method to produce {@link NodeBaseFactory factories},
156
+ * and a method to produce a runtime representation of a given {@link EnumerationLiteral}.
157
+ */
158
+ export interface ILanguageBase {
159
+ language: Language;
160
+ factory(handleDelta?: DeltaHandler): NodeBaseFactory;
161
+ enumLiteralFrom<T>(enumerationLiteral: EnumerationLiteral): T;
162
+ }
163
+ /**
164
+ * Removes the given child node from its parent, and returns its containment index.
165
+ */
166
+ export declare const removeFromParent: (parent: INodeBase | undefined, child: INodeBase) => number;
167
+ //# sourceMappingURL=base-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-types.d.ts","sourceRoot":"","sources":["../src/base-types.ts"],"names":[],"mappings":"AAiBA,OAAO,EAEH,UAAU,EAGV,WAAW,EACX,kBAAkB,EAClB,OAAO,EACP,EAAE,EACF,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,SAAS,EACZ,MAAM,eAAe,CAAC;AAGvB,OAA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