@lionweb/class-core 0.8.0-beta.6 → 0.8.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +7 -0
  3. package/dist/base-types.d.ts +4 -4
  4. package/dist/base-types.d.ts.map +1 -1
  5. package/dist/deltas/appliers.d.ts.map +1 -1
  6. package/dist/deltas/appliers.js +10 -12
  7. package/dist/deltas/appliers.js.map +1 -1
  8. package/dist/deltas/index.d.ts +0 -1
  9. package/dist/deltas/index.d.ts.map +1 -1
  10. package/dist/deltas/index.js +0 -1
  11. package/dist/deltas/index.js.map +1 -1
  12. package/dist/deltas/inverters.d.ts +1 -1
  13. package/dist/deltas/inverters.d.ts.map +1 -1
  14. package/dist/deltas/inverters.js +31 -34
  15. package/dist/deltas/inverters.js.map +1 -1
  16. package/dist/deltas/serialization/base.d.ts.map +1 -1
  17. package/dist/deltas/serialization/base.js +2 -2
  18. package/dist/deltas/serialization/base.js.map +1 -1
  19. package/dist/deltas/serialization/deserializer.g.d.ts.map +1 -1
  20. package/dist/deltas/serialization/deserializer.g.js +59 -63
  21. package/dist/deltas/serialization/deserializer.g.js.map +1 -1
  22. package/dist/deltas/serialization/serializer.g.d.ts.map +1 -1
  23. package/dist/deltas/serialization/serializer.g.js +5 -11
  24. package/dist/deltas/serialization/serializer.g.js.map +1 -1
  25. package/dist/deltas/serialization/types.g.d.ts +5 -9
  26. package/dist/deltas/serialization/types.g.d.ts.map +1 -1
  27. package/dist/deltas/types.g.d.ts +8 -12
  28. package/dist/deltas/types.g.d.ts.map +1 -1
  29. package/dist/deltas/types.g.js +7 -12
  30. package/dist/deltas/types.g.js.map +1 -1
  31. package/dist/deserializer.d.ts +1 -1
  32. package/dist/deserializer.d.ts.map +1 -1
  33. package/dist/deserializer.js +3 -3
  34. package/dist/deserializer.js.map +1 -1
  35. package/dist/id-mapping.d.ts +16 -10
  36. package/dist/id-mapping.d.ts.map +1 -1
  37. package/dist/id-mapping.js +21 -6
  38. package/dist/id-mapping.js.map +1 -1
  39. package/dist/references.d.ts +3 -4
  40. package/dist/references.d.ts.map +1 -1
  41. package/dist/references.js +1 -1
  42. package/dist/references.js.map +1 -1
  43. package/dist/serializer.d.ts +2 -2
  44. package/dist/serializer.d.ts.map +1 -1
  45. package/dist/serializer.js +13 -9
  46. package/dist/serializer.js.map +1 -1
  47. package/dist/textualizer.d.ts +2 -1
  48. package/dist/textualizer.d.ts.map +1 -1
  49. package/dist/textualizer.js +13 -1
  50. package/dist/textualizer.js.map +1 -1
  51. package/dist/value-managers/references.d.ts +8 -8
  52. package/dist/value-managers/references.d.ts.map +1 -1
  53. package/dist/value-managers/references.js +3 -5
  54. package/dist/value-managers/references.js.map +1 -1
  55. package/package.json +5 -5
  56. package/src/base-types.ts +4 -4
  57. package/src/deltas/appliers.ts +16 -19
  58. package/src/deltas/index.ts +0 -1
  59. package/src/deltas/inverters.ts +31 -35
  60. package/src/deltas/serialization/base.ts +2 -2
  61. package/src/deltas/serialization/deserializer.g.ts +58 -63
  62. package/src/deltas/serialization/serializer.g.ts +4 -13
  63. package/src/deltas/serialization/types.g.ts +4 -10
  64. package/src/deltas/types.g.ts +5 -11
  65. package/src/deserializer.ts +4 -4
  66. package/src/id-mapping.ts +29 -14
  67. package/src/references.ts +3 -5
  68. package/src/serializer.ts +17 -11
  69. package/src/textualizer.ts +20 -2
  70. package/src/value-managers/references.ts +11 -13
  71. package/dist/deltas/compositor.d.ts +0 -51
  72. package/dist/deltas/compositor.d.ts.map +0 -1
  73. package/dist/deltas/compositor.js +0 -95
  74. package/dist/deltas/compositor.js.map +0 -1
  75. package/src/deltas/compositor.ts +0 -107
@@ -47,7 +47,6 @@ export type SerializedDelta =
47
47
  | ReferenceAddedSerializedDelta
48
48
  | ReferenceDeletedSerializedDelta
49
49
  | ReferenceChangedSerializedDelta
50
- | CompositeSerializedDelta
51
50
  | NoOpSerializedDelta
52
51
  ;
53
52
 
@@ -249,7 +248,7 @@ export type ReferenceAddedSerializedDelta = {
249
248
  parent: LionWebId
250
249
  reference: LionWebJsonMetaPointer
251
250
  index: number
252
- newTarget: IdOrNull
251
+ newReference: IdOrNull
253
252
  }
254
253
 
255
254
  export type ReferenceDeletedSerializedDelta = {
@@ -257,7 +256,7 @@ export type ReferenceDeletedSerializedDelta = {
257
256
  parent: LionWebId
258
257
  reference: LionWebJsonMetaPointer
259
258
  index: number
260
- deletedTarget: IdOrNull
259
+ deletedReference: IdOrNull
261
260
  }
262
261
 
263
262
  export type ReferenceChangedSerializedDelta = {
@@ -265,13 +264,8 @@ export type ReferenceChangedSerializedDelta = {
265
264
  parent: LionWebId
266
265
  reference: LionWebJsonMetaPointer
267
266
  index: number
268
- newTarget: IdOrNull
269
- oldTarget: IdOrNull
270
- }
271
-
272
- export type CompositeSerializedDelta = {
273
- kind: "Composite"
274
- parts: SerializedDelta[]
267
+ newReference: IdOrNull
268
+ oldReference: IdOrNull
275
269
  }
276
270
 
277
271
  export type NoOpSerializedDelta = {
@@ -20,6 +20,7 @@
20
20
 
21
21
  import {
22
22
  Containment,
23
+ Node,
23
24
  Property,
24
25
  Reference,
25
26
  SingleRef
@@ -254,7 +255,7 @@ export class ReferenceAddedDelta implements IDelta {
254
255
  public readonly parent: INodeBase,
255
256
  public readonly reference: Reference,
256
257
  public readonly index: number,
257
- public readonly newTarget: SingleRef<INodeBase>
258
+ public readonly newReference: SingleRef<Node>
258
259
  ) {
259
260
  }
260
261
  }
@@ -264,7 +265,7 @@ export class ReferenceDeletedDelta implements IDelta {
264
265
  public readonly parent: INodeBase,
265
266
  public readonly reference: Reference,
266
267
  public readonly index: number,
267
- public readonly deletedTarget: SingleRef<INodeBase>
268
+ public readonly deletedReference: SingleRef<Node>
268
269
  ) {
269
270
  }
270
271
  }
@@ -274,15 +275,8 @@ export class ReferenceChangedDelta implements IDelta {
274
275
  public readonly parent: INodeBase,
275
276
  public readonly reference: Reference,
276
277
  public readonly index: number,
277
- public readonly newTarget: SingleRef<INodeBase>,
278
- public readonly oldTarget: SingleRef<INodeBase>
279
- ) {
280
- }
281
- }
282
-
283
- export class CompositeDelta implements IDelta {
284
- constructor(
285
- public readonly parts: IDelta[]
278
+ public readonly newReference: SingleRef<Node>,
279
+ public readonly oldReference: SingleRef<Node>
286
280
  ) {
287
281
  }
288
282
  }
@@ -19,8 +19,8 @@ import {
19
19
  Classifier,
20
20
  consoleProblemReporter,
21
21
  Containment,
22
- defaultLionWebVersion,
23
22
  Enumeration,
23
+ LionWebVersions,
24
24
  MemoisingSymbolTable,
25
25
  PrimitiveType,
26
26
  ProblemReporter,
@@ -61,7 +61,7 @@ export type RootsWithIdMapping = { roots: INodeBase[], idMapping: IdMapping };
61
61
  */
62
62
  export type DeserializerConfiguration = {
63
63
  // FIXME parametrize (optionally) in LionWebVersion
64
- /** Default: {@code lioncoreBuiltinsFacade.propertyValueDeserializer}. */
64
+ /** Default: `lioncoreBuiltinsFacade.propertyValueDeserializer`. */
65
65
  propertyValueDeserializer?: PropertyValueDeserializer,
66
66
  /** Default: {@link consoleProblemReporter}. */
67
67
  problemReporter?: ProblemReporter
@@ -83,8 +83,8 @@ function nodeBaseDeserializerWithIdMapping(languageBases: ILanguageBase[], recei
83
83
  function nodeBaseDeserializerWithIdMapping(configuration: FactoryConfiguration & DeserializerConfiguration): Deserializer<RootsWithIdMapping>;
84
84
  function nodeBaseDeserializerWithIdMapping(languageBasesOrConfiguration: ILanguageBase[] | (FactoryConfiguration & DeserializerConfiguration), mayBeReceiveDelta?: DeltaReceiver): Deserializer<RootsWithIdMapping> {
85
85
  const [languageBases, receiveDelta, propertyValueDeserializer, problemReporter] = Array.isArray(languageBasesOrConfiguration)
86
- ? [languageBasesOrConfiguration, mayBeReceiveDelta, defaultLionWebVersion.builtinsFacade.propertyValueDeserializer, consoleProblemReporter]
87
- : [languageBasesOrConfiguration.languageBases, languageBasesOrConfiguration.receiveDelta, languageBasesOrConfiguration.propertyValueDeserializer ?? defaultLionWebVersion.builtinsFacade.propertyValueDeserializer, languageBasesOrConfiguration.problemReporter ?? languageBasesOrConfiguration.problemsHandler ?? consoleProblemReporter];
86
+ ? [languageBasesOrConfiguration, mayBeReceiveDelta, LionWebVersions.v2023_1.builtinsFacade.propertyValueDeserializer, consoleProblemReporter]
87
+ : [languageBasesOrConfiguration.languageBases, languageBasesOrConfiguration.receiveDelta, languageBasesOrConfiguration.propertyValueDeserializer ?? LionWebVersions.v2023_1.builtinsFacade.propertyValueDeserializer, languageBasesOrConfiguration.problemReporter ?? languageBasesOrConfiguration.problemsHandler ?? consoleProblemReporter];
88
88
 
89
89
  const symbolTable = new MemoisingSymbolTable(languageBases.map(({language}) => language));
90
90
  const languageBaseFor = combinedLanguageBaseLookupFor(languageBases);
package/src/id-mapping.ts CHANGED
@@ -15,17 +15,17 @@
15
15
  // SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
16
16
  // SPDX-License-Identifier: Apache-2.0
17
17
 
18
- import { referenceToSet, SingleRef } from "@lionweb/core"
18
+ import { Node, referenceToSet, SingleRef } from "@lionweb/core"
19
19
  import { LionWebId } from "@lionweb/json"
20
20
 
21
- import { INodeBase } from "./base-types.js"
21
+ import { INodeBase, NodeBase } from "./base-types.js"
22
22
  import { IdOrNull } from "./references.js"
23
23
 
24
24
 
25
25
  /**
26
- * Type def. for a (hash-)map {@link LionWebId ID} &rarr; {@link INodeBase}.
26
+ * Type def. for a (hash-)map {@link LionWebId ID} &rarr; {@link Node}.
27
27
  */
28
- type NodesById = { [id: LionWebId]: INodeBase }
28
+ type NodesById = { [id: LionWebId]: Node }
29
29
 
30
30
 
31
31
  /**
@@ -39,13 +39,13 @@ export class IdMapping {
39
39
  constructor(nodesById: NodesById) {
40
40
  this.nodesById = {...nodesById};
41
41
  }
42
- // TODO consider using an instance of Map<Id, INodeBase> instead
42
+ // TODO consider using an instance of Map<Id, Node> instead
43
43
 
44
44
  /**
45
- * @return the {@link INodeBase node} with the given {@link LionWebId `id`}, or
45
+ * @return the {@link Node node} with the given {@link LionWebId `id`}, or
46
46
  * @throws an Error if no node with the given ID was registered.
47
47
  */
48
- fromId = (id: LionWebId): INodeBase => {
48
+ fromId = (id: LionWebId): Node => {
49
49
  if (!(id in this.nodesById)) {
50
50
  throw new Error(`node with id=${id} not in ID mapping`);
51
51
  }
@@ -53,17 +53,30 @@ export class IdMapping {
53
53
  }
54
54
 
55
55
  /**
56
- * @return the {@link INodeBase node} with the given {@link LionWebId `id`},
56
+ * @return the {@link INodeBase node} with the given {@link LionWebId `id`}, or
57
+ * @throws an Error if no node with the given ID was registered, or
58
+ * if the node is not a {@link INodeBase}.
59
+ */
60
+ nodeBaseFromId = (id: LionWebId): INodeBase => {
61
+ const node = this.fromId(id);
62
+ if (node instanceof NodeBase) {
63
+ return node;
64
+ }
65
+ throw new Error(`node with id=${id} is not a[n I]NodeBase`)
66
+ }
67
+
68
+ /**
69
+ * @return the {@link Node node} with the given {@link LionWebId `id`},
57
70
  * or `undefined` if no node with the given ID was registered.
58
71
  */
59
- tryFromId = (id: LionWebId): (INodeBase | undefined) =>
72
+ tryFromId = (id: LionWebId): (Node | undefined) =>
60
73
  this.nodesById[id];
61
74
 
62
75
  /**
63
- * @return the {@link INodeBase node} referenced from the given {@link LionWebId ID},
76
+ * @return the {@link Node node} referenced from the given {@link LionWebId ID},
64
77
  * or `unresolved` if `unresolved` was passed in or no node with the given ID was registered.
65
78
  */
66
- fromRefId = (idOrNull: IdOrNull): SingleRef<INodeBase> =>
79
+ fromRefId = (idOrNull: IdOrNull): SingleRef<Node> =>
67
80
  idOrNull === null
68
81
  ? referenceToSet()
69
82
  : (this.nodesById[idOrNull] ?? referenceToSet());
@@ -71,10 +84,12 @@ export class IdMapping {
71
84
  /**
72
85
  * Updates this {@link IdMapping} with the given `node` *and all its descendants* (recursively).
73
86
  */
74
- updateWith = (node: INodeBase) => {
87
+ updateWith = (node: Node) => {
75
88
  this.nodesById[node.id] = node;
76
- node.children // recurse into all children
77
- .forEach((child) => this.updateWith(child));
89
+ if (node instanceof NodeBase) {
90
+ node.children // recurse into all children
91
+ .forEach((child) => this.updateWith(child));
92
+ }
78
93
  // TODO figure out when it's really necessary to call this, as it's potentially *very* expensive
79
94
  }
80
95
 
package/src/references.ts CHANGED
@@ -15,11 +15,9 @@
15
15
  // SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
16
16
  // SPDX-License-Identifier: Apache-2.0
17
17
 
18
- import { isUnresolvedReference, SingleRef } from "@lionweb/core"
18
+ import { isUnresolvedReference, Node, SingleRef } from "@lionweb/core"
19
19
  import { LionWebId } from "@lionweb/json"
20
20
 
21
- import { INodeBase } from "./base-types.js"
22
-
23
21
 
24
22
  /**
25
23
  * A type that expresses a value is either an {@link LionWebId} or a value to indicate that resolution to a node previously failed.
@@ -28,8 +26,8 @@ export type IdOrNull = LionWebId | null
28
26
 
29
27
 
30
28
  /**
31
- * @return the ID of a given reference to a {@link INodeBase}, or `null` if that reference was previously unresolved.
29
+ * @return the ID of a given reference to a {@link Node}, or `null` if that reference was previously unresolved.
32
30
  */
33
- export const idFrom = (ref: SingleRef<INodeBase>): IdOrNull =>
31
+ export const idFrom = (ref: SingleRef<Node>): IdOrNull =>
34
32
  isUnresolvedReference(ref) ? null : ref.id
35
33
 
package/src/serializer.ts CHANGED
@@ -16,12 +16,14 @@
16
16
  // SPDX-License-Identifier: Apache-2.0
17
17
 
18
18
  import {
19
+ allLionWebVersions,
19
20
  allSuperTypesOf,
20
21
  Containment,
21
- defaultLionWebVersion,
22
22
  Enumeration,
23
23
  Feature,
24
24
  isUnresolvedReference,
25
+ LionWebVersions,
26
+ Node,
25
27
  PrimitiveType,
26
28
  Property,
27
29
  PropertyValueSerializer,
@@ -31,7 +33,7 @@ import {
31
33
  serializerWith
32
34
  } from "@lionweb/core"
33
35
 
34
- import { INodeBase, LionCore_builtinsBase } from "./index.js"
36
+ import { INodeBase, LionCore_builtinsBase, NodeBase } from "./index.js"
35
37
 
36
38
 
37
39
  /**
@@ -55,7 +57,7 @@ export const getFeatureValue = (node: INodeBase, feature: Feature) => {
55
57
  * A {@link ResolveInfoDeducer} that works on {@link INodeBase}s.
56
58
  * *Note*: the {@link Reference} passed is not taken into account (yet).
57
59
  */
58
- const nodeBaseResolveInfoDeducer: ResolveInfoDeducer<INodeBase> = (node, _reference) => {
60
+ const nodeBaseResolveInfoDeducer: ResolveInfoDeducer<Node> = (node, _reference) => {
59
61
  // TODO put innards in separate function
60
62
  if ("name" in node) {
61
63
  // evaluating `node.name` might cause an error through FeatureValueManager.throwOnReadOfUnset:
@@ -66,12 +68,16 @@ const nodeBaseResolveInfoDeducer: ResolveInfoDeducer<INodeBase> = (node, _refere
66
68
  return undefined;
67
69
  }
68
70
  }
69
- const allSupertypes = allSuperTypesOf(node.classifier);
70
- if (allSupertypes.indexOf(defaultLionWebVersion.builtinsFacade.classifiers.inamed) > -1) {
71
- return node.getPropertyValueManager(defaultLionWebVersion.builtinsFacade.features.inamed_name).getDirectly() as (string | undefined);
72
- }
73
- if (allSupertypes.indexOf(LionCore_builtinsBase.INSTANCE.INamed) > -1) {
74
- return node.getPropertyValueManager(LionCore_builtinsBase.INSTANCE.INamed_name).getDirectly() as (string | undefined);
71
+ if (node instanceof NodeBase) {
72
+ const allSupertypes = allSuperTypesOf(node.classifier);
73
+ allLionWebVersions.forEach((lionWebVersion) => {
74
+ if (allSupertypes.indexOf(lionWebVersion.builtinsFacade.classifiers.inamed) > -1) {
75
+ return node.getPropertyValueManager(lionWebVersion.builtinsFacade.features.inamed_name).getDirectly() as (string | undefined);
76
+ }
77
+ })
78
+ if (allSupertypes.indexOf(LionCore_builtinsBase.INSTANCE.INamed) > -1) {
79
+ return node.getPropertyValueManager(LionCore_builtinsBase.INSTANCE.INamed_name).getDirectly() as (string | undefined);
80
+ }
75
81
  }
76
82
  return undefined;
77
83
  };
@@ -80,7 +86,7 @@ const nodeBaseResolveInfoDeducer: ResolveInfoDeducer<INodeBase> = (node, _refere
80
86
  * A {@link Reader} that works on/for {@link INodeBase}s specifically.
81
87
  * **Note** that this function is for internal use only!
82
88
  */
83
- export const nodeBaseReader: Reader<INodeBase> = {
89
+ export const nodeBaseReader: Reader<INodeBase, Node> = {
84
90
  classifierOf: (node) => node.classifier,
85
91
  getFeatureValue,
86
92
  enumerationLiteralFrom: (encoding, enumeration) => {
@@ -109,7 +115,7 @@ type PropertyValueSerializerConfiguration = Partial<{
109
115
  * Unrecoverable issues are passed to the optional `reportIssue` argument, and
110
116
  */
111
117
  export const propertyValueSerializerWith = (configuration?: PropertyValueSerializerConfiguration) => {
112
- const primitiveValueSerializer = configuration?.primitiveValueSerializer ?? defaultLionWebVersion.builtinsFacade.propertyValueSerializer
118
+ const primitiveValueSerializer = configuration?.primitiveValueSerializer ?? LionWebVersions.v2023_1.builtinsFacade.propertyValueSerializer
113
119
  const reportIssue = configuration?.reportIssue ?? ((message) => { throw new Error(message) })
114
120
  return {
115
121
  serializeValue: (value: unknown, property: Property) => {
@@ -21,6 +21,7 @@ import {
21
21
  Feature,
22
22
  isUnresolvedReference,
23
23
  Link,
24
+ Node,
24
25
  Property,
25
26
  Reference,
26
27
  UnresolvedReference
@@ -53,12 +54,29 @@ const asINodeBases = (value: INodeBaseOrNotThere | INodeBaseOrNotThere[]): INode
53
54
  return []
54
55
  }
55
56
 
57
+ type NodeOrNotThere = Node | UnresolvedReference | undefined
58
+
59
+ const asNodes = (value: NodeOrNotThere | NodeOrNotThere[]): Node[] => {
60
+ const isNode = (value: NodeOrNotThere): value is Node =>
61
+ !(value === undefined || isUnresolvedReference(value))
62
+
63
+ if (Array.isArray(value)) {
64
+ return value
65
+ .filter((subValue) => isNode(subValue))
66
+ .map((subValue) => subValue as Node)
67
+ }
68
+ if (isNode(value)) {
69
+ return [value]
70
+ }
71
+ return []
72
+ }
73
+
56
74
 
57
75
  /**
58
76
  * @return a function that renders the roots of a given forest of {@link INodeBase nodes} in a textual tree-representation.
59
77
  * @param identificationFor a function that renders an identification for the given {@link INodeBase node} — typically its name or its ID.
60
78
  */
61
- export const asTreeTextWith = (identificationFor: (node: INodeBase) => string): ((nodes: INodeBase[]) => string) => {
79
+ export const asTreeTextWith = (identificationFor: (node: Node) => string): ((nodes: INodeBase[]) => string) => {
62
80
 
63
81
  const asText = (node: INodeBase): Template => {
64
82
  const featureValueAsText = (feature: Feature) => {
@@ -87,7 +105,7 @@ export const asTreeTextWith = (identificationFor: (node: INodeBase) => string):
87
105
  }
88
106
  if (feature instanceof Reference) {
89
107
  const valueManager= node.getReferenceValueManager(feature)
90
- const references = asINodeBases(valueManager.getDirectly())
108
+ const references = asNodes(valueManager.getDirectly())
91
109
  return [
92
110
  `${feature.name} -> ${references.length === 0 ? nothing : references.map(identificationFor).join(", ")}`
93
111
  ]
@@ -15,18 +15,18 @@
15
15
  // SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
16
16
  // SPDX-License-Identifier: Apache-2.0
17
17
 
18
- import { MultiRef, Reference, SingleRef } from "@lionweb/core"
18
+ import { MultiRef, Node, Reference, SingleRef } from "@lionweb/core"
19
19
  import { action, observable } from "mobx"
20
20
 
21
21
  import { INodeBase } from "../base-types.js"
22
- import { CompositeDelta, ReferenceAddedDelta, ReferenceChangedDelta, ReferenceDeletedDelta } from "../deltas/index.js"
22
+ import { ReferenceAddedDelta, ReferenceChangedDelta, ReferenceDeletedDelta } from "../deltas/index.js"
23
23
  import { checkIndex, FeatureValueManager } from "./base.js"
24
24
 
25
25
 
26
26
  /**
27
27
  * An instance manages the value of a particular reference feature on a particular instance of a classifier.
28
28
  */
29
- export abstract class ReferenceValueManager<T extends INodeBase> extends FeatureValueManager<Reference> {
29
+ export abstract class ReferenceValueManager<T extends Node> extends FeatureValueManager<Reference> {
30
30
 
31
31
  get reference(): Reference {
32
32
  return this.feature;
@@ -44,7 +44,7 @@ export abstract class ReferenceValueManager<T extends INodeBase> extends Feature
44
44
  }
45
45
 
46
46
 
47
- export abstract class SingleReferenceValueManager<T extends INodeBase> extends ReferenceValueManager<T> {
47
+ export abstract class SingleReferenceValueManager<T extends Node> extends ReferenceValueManager<T> {
48
48
 
49
49
  protected constructor(reference: Reference, container: INodeBase) {
50
50
  super(reference, container);
@@ -72,7 +72,7 @@ export abstract class SingleReferenceValueManager<T extends INodeBase> extends R
72
72
  }
73
73
 
74
74
 
75
- export class OptionalSingleReferenceValueManager<T extends INodeBase> extends SingleReferenceValueManager<T> {
75
+ export class OptionalSingleReferenceValueManager<T extends Node> extends SingleReferenceValueManager<T> {
76
76
 
77
77
  constructor(reference: Reference, container: INodeBase) {
78
78
  super(reference, container);
@@ -109,7 +109,7 @@ export class OptionalSingleReferenceValueManager<T extends INodeBase> extends Si
109
109
  }
110
110
 
111
111
 
112
- export class RequiredSingleReferenceValueManager<T extends INodeBase> extends SingleReferenceValueManager<T> {
112
+ export class RequiredSingleReferenceValueManager<T extends Node> extends SingleReferenceValueManager<T> {
113
113
 
114
114
  constructor(reference: Reference, container: INodeBase) {
115
115
  super(reference, container);
@@ -145,7 +145,7 @@ export class RequiredSingleReferenceValueManager<T extends INodeBase> extends Si
145
145
  }
146
146
 
147
147
 
148
- export abstract class MultiReferenceValueManager<T extends INodeBase> extends ReferenceValueManager<T> {
148
+ export abstract class MultiReferenceValueManager<T extends Node> extends ReferenceValueManager<T> {
149
149
 
150
150
  protected constructor(reference: Reference, container: INodeBase) {
151
151
  super(reference, container);
@@ -214,10 +214,8 @@ export abstract class MultiReferenceValueManager<T extends INodeBase> extends Re
214
214
  @action move(oldIndex: number, newIndex: number) {
215
215
  const target = this.moveDirectly(oldIndex, newIndex);
216
216
  if (target !== undefined) {
217
- this.emitDelta(() => new CompositeDelta([
218
- new ReferenceDeletedDelta(this.container, this.reference, oldIndex, target),
219
- new ReferenceAddedDelta(this.container, this.reference, newIndex < oldIndex ? newIndex : newIndex - 1, target)
220
- ]));
217
+ this.emitDelta(() => new ReferenceDeletedDelta(this.container, this.reference, oldIndex, target));
218
+ this.emitDelta(() => new ReferenceAddedDelta(this.container, this.reference, newIndex < oldIndex ? newIndex : newIndex - 1, target));
221
219
  }
222
220
  }
223
221
 
@@ -233,7 +231,7 @@ export abstract class MultiReferenceValueManager<T extends INodeBase> extends Re
233
231
  }
234
232
 
235
233
 
236
- export class OptionalMultiReferenceValueManager<T extends INodeBase> extends MultiReferenceValueManager<T> {
234
+ export class OptionalMultiReferenceValueManager<T extends Node> extends MultiReferenceValueManager<T> {
237
235
 
238
236
  constructor(reference: Reference, container: INodeBase) {
239
237
  super(reference, container);
@@ -250,7 +248,7 @@ export class OptionalMultiReferenceValueManager<T extends INodeBase> extends Mul
250
248
  }
251
249
 
252
250
 
253
- export class RequiredMultiReferenceValueManager<T extends INodeBase> extends MultiReferenceValueManager<T> {
251
+ export class RequiredMultiReferenceValueManager<T extends Node> extends MultiReferenceValueManager<T> {
254
252
 
255
253
  constructor(reference: Reference, container: INodeBase) {
256
254
  super(reference, container);
@@ -1,51 +0,0 @@
1
- import { DeltaReceiver } from "../index.js";
2
- /**
3
- * A *delta compositor* is used to *aggregate* deltas as {@link CompositeDelta composite deltas}.
4
- *
5
- * Usage:
6
- * ```typescript
7
- * const compositor = new Compositor(downstreamReceiveDelta);
8
- * compositor.openComposite();
9
- * // ...
10
- * compositor.upstreamReceiveDelta(<delta>);
11
- * // ...
12
- * compositor.closeComposite();
13
- * ```
14
- */
15
- export declare class DeltaCompositor {
16
- private readonly downstreamReceiveDelta;
17
- private readonly maximumNestingDepth;
18
- /**
19
- * The {@link DeltaReceiver} implementation that either forwards to the given downstream delta handle
20
- * or gathers deltas into composite deltas to forward to the downstream delta receiver later.
21
- */
22
- readonly upstreamReceiveDelta: DeltaReceiver;
23
- /**
24
- * An array of arrays of {@link IDelta deltas}, comprising a “stack”.
25
- *
26
- * Invariants:
27
- * - (I1) composite has been opened &hArr; `this.deltasInComposite !== undefined` / `Array.isArray(this.deltasInComposite)`
28
- * - (I2) this.deltasStack is either undefined or an array containing at least one array
29
- */
30
- private deltasStack;
31
- /**
32
- * @param downstreamReceiveDelta the {@link DeltaReceiver} that deltas get passed to.
33
- * @param maximumNestingDepth the maximum depth that composites can be nested.
34
- * A maximum depth of e.g. 1 means that at most 1 composite can be open at any time.
35
- */
36
- constructor(downstreamReceiveDelta: DeltaReceiver, maximumNestingDepth?: number);
37
- /**
38
- * Opens a composite, meaning that all deltas passed to the {@link upstreamReceiveDelta} are gathered into a composite delta
39
- * that gets forwarded to the downstream delta receiver as soon as the composite is closed.
40
- *
41
- * Composites can be nested, to the maximum depth configured through this class’ constructor,
42
- * beyond which an error gets thrown.
43
- */
44
- openComposite: () => void;
45
- /**
46
- * Closes the current composite, producing the deltas gathered for this composite into a composite delta.
47
- * Composites can be nested, and deltas only get forwarded to the downstream delta receiver after the top-level composite has been closed.
48
- */
49
- closeComposite: () => void;
50
- }
51
- //# sourceMappingURL=compositor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compositor.d.ts","sourceRoot":"","sources":["../../src/deltas/compositor.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAkB,aAAa,EAAU,MAAM,aAAa,CAAA;AAGnE;;;;;;;;;;;;GAYG;AACH,qBAAa,eAAe;IAsBZ,OAAO,CAAC,QAAQ,CAAC,sBAAsB;IAAiB,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IApBxG;;;OAGG;IACH,QAAQ,CAAC,oBAAoB,EAAE,aAAa,CAAC;IAE7C;;;;;;OAMG;IACH,OAAO,CAAC,WAAW,CAAqC;IAExD;;;;OAIG;gBAC0B,sBAAsB,EAAE,aAAa,EAAmB,mBAAmB,GAAE,MAAiB;IAe3H;;;;;;OAMG;IACH,aAAa,QAAO,IAAI,CAQvB;IAED;;;OAGG;IACH,cAAc,QAAO,IAAI,CAYxB;CAEJ"}
@@ -1,95 +0,0 @@
1
- // Copyright 2025 TRUMPF Laser SE and other contributors
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License")
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
- //
15
- // SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
16
- // SPDX-License-Identifier: Apache-2.0
17
- import { CompositeDelta } from "../index.js";
18
- /**
19
- * A *delta compositor* is used to *aggregate* deltas as {@link CompositeDelta composite deltas}.
20
- *
21
- * Usage:
22
- * ```typescript
23
- * const compositor = new Compositor(downstreamReceiveDelta);
24
- * compositor.openComposite();
25
- * // ...
26
- * compositor.upstreamReceiveDelta(<delta>);
27
- * // ...
28
- * compositor.closeComposite();
29
- * ```
30
- */
31
- export class DeltaCompositor {
32
- /**
33
- * @param downstreamReceiveDelta the {@link DeltaReceiver} that deltas get passed to.
34
- * @param maximumNestingDepth the maximum depth that composites can be nested.
35
- * A maximum depth of e.g. 1 means that at most 1 composite can be open at any time.
36
- */
37
- constructor(downstreamReceiveDelta, maximumNestingDepth = Infinity) {
38
- this.downstreamReceiveDelta = downstreamReceiveDelta;
39
- this.maximumNestingDepth = maximumNestingDepth;
40
- /**
41
- * An array of arrays of {@link IDelta deltas}, comprising a “stack”.
42
- *
43
- * Invariants:
44
- * - (I1) composite has been opened &hArr; `this.deltasInComposite !== undefined` / `Array.isArray(this.deltasInComposite)`
45
- * - (I2) this.deltasStack is either undefined or an array containing at least one array
46
- */
47
- this.deltasStack = undefined;
48
- /**
49
- * Opens a composite, meaning that all deltas passed to the {@link upstreamReceiveDelta} are gathered into a composite delta
50
- * that gets forwarded to the downstream delta receiver as soon as the composite is closed.
51
- *
52
- * Composites can be nested, to the maximum depth configured through this class’ constructor,
53
- * beyond which an error gets thrown.
54
- */
55
- this.openComposite = () => {
56
- if (this.deltasStack === undefined) {
57
- this.deltasStack = []; // ==> (I1) + 1st half of (I2)
58
- }
59
- if (this.deltasStack.length >= this.maximumNestingDepth) {
60
- throw new Error(`attempt occurred to start a nested composition exceeding the maximum nesting depth`);
61
- }
62
- this.deltasStack.push([]); // ==> 2nd half of (I2)
63
- };
64
- /**
65
- * Closes the current composite, producing the deltas gathered for this composite into a composite delta.
66
- * Composites can be nested, and deltas only get forwarded to the downstream delta receiver after the top-level composite has been closed.
67
- */
68
- this.closeComposite = () => {
69
- if (this.deltasStack === undefined) {
70
- throw new Error(`attempt occurred to finish a composite without one being started`);
71
- }
72
- const parts = this.deltasStack.pop(); // is an array because of (I2)
73
- if (this.deltasStack.length === 0) { // last array popped from stack
74
- this.deltasStack = undefined; // maintain (I2)
75
- }
76
- if (parts.length > 0) {
77
- this.upstreamReceiveDelta(new CompositeDelta(parts));
78
- }
79
- };
80
- if (maximumNestingDepth !== Infinity && (!Number.isInteger(maximumNestingDepth) || maximumNestingDepth < 0)) {
81
- throw new Error(`maximum nesting depth must be a non-negative integer`);
82
- }
83
- this.upstreamReceiveDelta = (delta) => {
84
- if (this.deltasStack === undefined) {
85
- // pass on immediately:
86
- this.downstreamReceiveDelta(delta);
87
- }
88
- else {
89
- // store for later:
90
- this.deltasStack[this.deltasStack.length - 1].push(delta); // (I2)
91
- }
92
- };
93
- }
94
- }
95
- //# sourceMappingURL=compositor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compositor.js","sourceRoot":"","sources":["../../src/deltas/compositor.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,EAAE;AACF,iEAAiE;AACjE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,EAAE;AACF,sEAAsE;AACtE,sCAAsC;AAEtC,OAAO,EAAE,cAAc,EAAyB,MAAM,aAAa,CAAA;AAGnE;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,eAAe;IAiBxB;;;;OAIG;IACH,YAA6B,sBAAqC,EAAmB,sBAA8B,QAAQ;QAA9F,2BAAsB,GAAtB,sBAAsB,CAAe;QAAmB,wBAAmB,GAAnB,mBAAmB,CAAmB;QAd3H;;;;;;WAMG;QACK,gBAAW,GAA2B,SAAS,CAAC;QAsBxD;;;;;;WAMG;QACH,kBAAa,GAAG,GAAS,EAAE;YACvB,IAAI,IAAI,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;gBACjC,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC,CAAE,8BAA8B;YAC1D,CAAC;YACD,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,IAAI,IAAI,CAAC,mBAAmB,EAAE,CAAC;gBACtD,MAAM,IAAI,KAAK,CAAC,oFAAoF,CAAC,CAAA;YACzG,CAAC;YACD,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAE,uBAAuB;QACvD,CAAC,CAAA;QAED;;;WAGG;QACH,mBAAc,GAAG,GAAS,EAAE;YACxB,IAAI,IAAI,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;gBACjC,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC;YACxF,CAAC;YAED,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,EAAG,CAAC,CAAE,8BAA8B;YACtE,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC,CAAI,+BAA+B;gBACnE,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC,CAAG,gBAAgB;YACpD,CAAC;YACD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACnB,IAAI,CAAC,oBAAoB,CAAC,IAAI,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;YACzD,CAAC;QACL,CAAC,CAAA;QA/CG,IAAI,mBAAmB,KAAK,QAAQ,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,mBAAmB,CAAC,IAAI,mBAAmB,GAAG,CAAC,CAAC,EAAE,CAAC;YAC1G,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;QAC5E,CAAC;QACD,IAAI,CAAC,oBAAoB,GAAG,CAAC,KAAK,EAAE,EAAE;YAClC,IAAI,IAAI,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;gBACjC,uBAAuB;gBACvB,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC;YACvC,CAAC;iBAAM,CAAC;gBACJ,mBAAmB;gBACnB,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAE,OAAO;YACvE,CAAC;QACL,CAAC,CAAC;IACN,CAAC;CAqCJ"}