@lionweb/class-core 0.7.0-beta.12 → 0.7.0-beta.13

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 (57) hide show
  1. package/CHANGELOG.md +4 -1
  2. package/README.md +6 -6
  3. package/dist/LionCore_builtins.g.d.ts +2 -2
  4. package/dist/LionCore_builtins.g.d.ts.map +1 -1
  5. package/dist/LionCore_builtins.g.js +1 -1
  6. package/dist/LionCore_builtins.g.js.map +1 -1
  7. package/dist/base-types.d.ts +7 -7
  8. package/dist/base-types.d.ts.map +1 -1
  9. package/dist/base-types.js +3 -3
  10. package/dist/base-types.js.map +1 -1
  11. package/dist/convenience.d.ts +7 -7
  12. package/dist/convenience.d.ts.map +1 -1
  13. package/dist/convenience.js +7 -7
  14. package/dist/convenience.js.map +1 -1
  15. package/dist/deltas/appliers.d.ts +2 -2
  16. package/dist/deltas/appliers.d.ts.map +1 -1
  17. package/dist/deltas/appliers.js +5 -2
  18. package/dist/deltas/appliers.js.map +1 -1
  19. package/dist/deltas/compositor.d.ts +51 -0
  20. package/dist/deltas/compositor.d.ts.map +1 -0
  21. package/dist/deltas/compositor.js +95 -0
  22. package/dist/deltas/compositor.js.map +1 -0
  23. package/dist/deltas/index.d.ts +2 -1
  24. package/dist/deltas/index.d.ts.map +1 -1
  25. package/dist/deltas/index.js +2 -1
  26. package/dist/deltas/index.js.map +1 -1
  27. package/dist/deltas/receivers.d.ts +39 -0
  28. package/dist/deltas/receivers.d.ts.map +1 -0
  29. package/dist/deltas/receivers.js +59 -0
  30. package/dist/deltas/receivers.js.map +1 -0
  31. package/dist/deserializer.d.ts +5 -5
  32. package/dist/deserializer.d.ts.map +1 -1
  33. package/dist/deserializer.js +8 -8
  34. package/dist/deserializer.js.map +1 -1
  35. package/dist/factory.d.ts +2 -2
  36. package/dist/factory.d.ts.map +1 -1
  37. package/dist/factory.js +2 -2
  38. package/dist/factory.js.map +1 -1
  39. package/dist/value-managers/base.d.ts +2 -2
  40. package/dist/value-managers/base.js +4 -4
  41. package/dist/value-managers/base.js.map +1 -1
  42. package/package.json +4 -4
  43. package/src/LionCore_builtins.g.ts +2 -2
  44. package/src/base-types.ts +6 -6
  45. package/src/convenience.ts +10 -10
  46. package/src/deltas/appliers.ts +5 -2
  47. package/src/deltas/compositor.ts +107 -0
  48. package/src/deltas/index.ts +3 -1
  49. package/src/deltas/receivers.ts +91 -0
  50. package/src/deserializer.ts +9 -9
  51. package/src/factory.ts +3 -3
  52. package/src/value-managers/base.ts +4 -4
  53. package/dist/deltas/handlers.d.ts +0 -17
  54. package/dist/deltas/handlers.d.ts.map +0 -1
  55. package/dist/deltas/handlers.js +0 -43
  56. package/dist/deltas/handlers.js.map +0 -1
  57. package/src/deltas/handlers.ts +0 -64
@@ -17,7 +17,9 @@
17
17
 
18
18
  export * from "./appliers.js";
19
19
  export * from "./base.js";
20
- export * from "./handlers.js";
20
+ export * from "./compositor.js";
21
21
  export * from "./inverters.js";
22
+ export * from "./receivers.js";
22
23
  export * from "./types.g.js";
23
24
  export * from "./serialization/index.js";
25
+
@@ -0,0 +1,91 @@
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
+
18
+ import { IDelta } from "./base.js"
19
+ import { serializeDelta } from "./serialization/index.js"
20
+
21
+ /**
22
+ * A type for functions that receive deltas.
23
+ */
24
+ export type DeltaReceiver = (delta: IDelta) => void;
25
+
26
+ /**
27
+ * Legacy alias for {@link DeltaReceiver}.
28
+ */
29
+ export type DeltaHandler = (delta: IDelta) => void;
30
+
31
+ /**
32
+ * @return a tuple consisting of a {@link DeltaReceiver} implementation (as 1st member) that pushes any received delta unto the tuple's 2nd member: an array of {@link IDelta deltas}.
33
+ * @param printSerializations determines whether the deltas are serialized as JSON and printed to the JavaScript console.
34
+ */
35
+ export const collectingDeltaReceiver = (printSerializations = false): [DeltaReceiver, IDelta[]] => {
36
+ const deltas: IDelta[] = [];
37
+ const receiveDelta: DeltaReceiver = (delta) => {
38
+ deltas.push(delta);
39
+ if (printSerializations) {
40
+ console.log(JSON.stringify(serializeDelta(delta), null, 4));
41
+ }
42
+ };
43
+ return [receiveDelta, deltas];
44
+ };
45
+
46
+ /**
47
+ * Legacy alias for {@link collectingDeltaReceiver}.
48
+ */
49
+ export const collectingDeltaHandler = collectingDeltaReceiver;
50
+
51
+ /**
52
+ * An interface for {@link DeltaReceiver delta receivers} that can be switched on and off — “latchingDeltaReceiverFrom”.
53
+ */
54
+ export interface LatchingDeltaReceiver extends DeltaReceiver {
55
+ latch(emitDeltas: boolean): void;
56
+ }
57
+
58
+ /**
59
+ * Legacy alias for {@link LatchingDeltaReceiver}.
60
+ */
61
+ export interface LatchingDeltaHandler extends LatchingDeltaReceiver {};
62
+
63
+ /**
64
+ * @return a latching version of the given {@link DeltaReceiver delta receiver}.
65
+ */
66
+ export const latchingDeltaReceiverFrom = (receiveDelta: DeltaReceiver): LatchingDeltaReceiver => {
67
+ let emitDeltas = false;
68
+ return Object.assign(
69
+ (delta: IDelta) => {
70
+ if (emitDeltas) {
71
+ receiveDelta(delta);
72
+ }
73
+ },
74
+ {
75
+ latch(emitDeltas_: boolean) {
76
+ emitDeltas = emitDeltas_;
77
+ },
78
+ },
79
+ );
80
+ };
81
+
82
+
83
+ /**
84
+ * @return a {@link DeltaReceiver delta receiver} implementation that forwards received deltas to the given {@link DeltaReceiver delta receivers}.
85
+ * This is necessary e.g. for combining using the delta protocol with an undo mechanism.
86
+ */
87
+ export const deltaReceiverForwardingTo = (...deltaReceivers: DeltaReceiver[]): DeltaReceiver =>
88
+ (delta) => {
89
+ deltaReceivers.forEach((receiveDelta) => receiveDelta(delta));
90
+ };
91
+
@@ -33,7 +33,7 @@ import {
33
33
  import { LionWebId, LionWebJsonChunk, LionWebJsonNode } from "@lionweb/json"
34
34
  import { byIdMap, keepDefineds } from "@lionweb/ts-utils"
35
35
 
36
- import { DeltaHandler, IdMapping, ILanguageBase, INodeBase } from "./index.js"
36
+ import { DeltaReceiver, IdMapping, ILanguageBase, INodeBase } from "./index.js"
37
37
  import { NodesToInstall } from "./linking.js"
38
38
 
39
39
 
@@ -57,9 +57,9 @@ const languageBaseLookupFor = (languageBases: ILanguageBase[]) =>
57
57
  return languageBase;
58
58
  };
59
59
 
60
- const factoryLookupFor = (languageBases: ILanguageBase[], handleDelta?: DeltaHandler) => {
60
+ const factoryLookupFor = (languageBases: ILanguageBase[], receiveDelta?: DeltaReceiver) => {
61
61
  const lookup = languageBaseLookupFor(languageBases);
62
- return (language: Language) => lookup(language).factory(handleDelta);
62
+ return (language: Language) => lookup(language).factory(receiveDelta);
63
63
  }
64
64
 
65
65
 
@@ -73,13 +73,13 @@ export type RootsWithIdMapping = { roots: INodeBase[], idMapping: IdMapping };
73
73
  /**
74
74
  * @return a {@link Deserializer} function for the given languages (given as {@link ILanguageBase}s) that returns a {@link RootsWithIdMapping}.
75
75
  * @param languageBases the {@link ILanguageBase}s for (at least) all the languages used in the {@link LionWebJsonChunk} to deserialize, minus LionCore M3 and built-ins.
76
- * @param handleDelta an optional {@link DeltaHandler} that will be injected in all {@link INodeBase nodes} created.
76
+ * @param receiveDelta an optional {@link DeltaReceiver} that will be injected in all {@link INodeBase nodes} created.
77
77
  */
78
- export const nodeBaseDeserializerWithIdMapping = (languageBases: ILanguageBase[], handleDelta?: DeltaHandler): Deserializer<RootsWithIdMapping> => {
78
+ export const nodeBaseDeserializerWithIdMapping = (languageBases: ILanguageBase[], receiveDelta?: DeltaReceiver): Deserializer<RootsWithIdMapping> => {
79
79
 
80
80
  const symbolTable = new MemoisingSymbolTable(languageBases.map(({language}) => language));
81
81
  const languageBaseFor = languageBaseLookupFor(languageBases);
82
- const factoryFor = factoryLookupFor(languageBases, handleDelta);
82
+ const factoryFor = factoryLookupFor(languageBases, receiveDelta);
83
83
 
84
84
  return (
85
85
  serializationChunk: LionWebJsonChunk,
@@ -219,10 +219,10 @@ export const nodeBaseDeserializerWithIdMapping = (languageBases: ILanguageBase[]
219
219
  /**
220
220
  * @return a {@link Deserializer} function for the languages (given as {@link ILanguageBase}s) that returns the roots (of type {@link INodeBase}) of the deserialized model.
221
221
  * @param languageBases the {@link ILanguageBase}s for (at least) all the languages used in the {@link LionWebJsonChunk} to deserialize, minus LionCore M3 and built-ins.
222
- * @param handleDelta an optional {@link DeltaHandler} that will be injected in all {@link INodeBase nodes} created.
222
+ * @param receiveDelta an optional {@link DeltaReceiver} that will be injected in all {@link INodeBase nodes} created.
223
223
  */
224
- export const nodeBaseDeserializer = (languageBases: ILanguageBase[], handleDelta?: DeltaHandler): Deserializer<INodeBase[]> => {
225
- const deserializerWithIdMapping = nodeBaseDeserializerWithIdMapping(languageBases, handleDelta);
224
+ export const nodeBaseDeserializer = (languageBases: ILanguageBase[], receiveDelta?: DeltaReceiver): Deserializer<INodeBase[]> => {
225
+ const deserializerWithIdMapping = nodeBaseDeserializerWithIdMapping(languageBases, receiveDelta);
226
226
  return (
227
227
  serializationChunk: LionWebJsonChunk,
228
228
  dependentNodes: INodeBase[] = [],
package/src/factory.ts CHANGED
@@ -17,18 +17,18 @@
17
17
 
18
18
  import { lazyMapGet } from "@lionweb/ts-utils"
19
19
  import { ILanguageBase, NodeBaseFactory } from "./base-types.js"
20
- import { DeltaHandler } from "./deltas/index.js"
20
+ import { DeltaReceiver } from "./deltas/index.js"
21
21
 
22
22
  /**
23
23
  * @return a {@link NodeBaseFactory factory function} that works for all given {@link ILanguageBase language bases}.
24
24
  */
25
- export const combinedFactoryFor = (languageBases: ILanguageBase[], handleDelta?: DeltaHandler): NodeBaseFactory => {
25
+ export const combinedFactoryFor = (languageBases: ILanguageBase[], receiveDelta?: DeltaReceiver): NodeBaseFactory => {
26
26
  // create lookup map:
27
27
  const languageKey2version2factory: { [key: string]: { [version: string]: NodeBaseFactory } } = {}
28
28
  languageBases.forEach((languageBase) => {
29
29
  const {key, version} = languageBase.language
30
30
  const version2factory = lazyMapGet(languageKey2version2factory, key, () => ({}))
31
- lazyMapGet(version2factory, version, () => languageBase.factory(handleDelta))
31
+ lazyMapGet(version2factory, version, () => languageBase.factory(receiveDelta))
32
32
  // (Note: don't destructure factory from languageBase, as that will unbind it as "this"!)
33
33
  })
34
34
 
@@ -29,12 +29,12 @@ export abstract class ValueManager {
29
29
  }
30
30
 
31
31
  /**
32
- * Emits a delta if a {@link DeltaHandler} is registered with the container.
33
- * @param deltaThunk a thunk that generates the delta, and is only called when a delta handler is registered with the container.
32
+ * Emits a delta if a {@link DeltaReceiver} is registered with the container.
33
+ * @param deltaThunk a thunk that generates the delta, and is only called when a delta receiver is registered with the container.
34
34
  */
35
35
  emitDelta(deltaThunk: () => IDelta) {
36
- if (this.container.handleDelta) {
37
- this.container.handleDelta(deltaThunk());
36
+ if (this.container.receiveDelta) {
37
+ this.container.receiveDelta(deltaThunk());
38
38
  }
39
39
  }
40
40
 
@@ -1,17 +0,0 @@
1
- import { IDelta } from "./base.js";
2
- /**
3
- * A type for functions that handle deltas.
4
- */
5
- export type DeltaHandler = (delta: IDelta) => void;
6
- export declare const collectingDeltaHandler: (printSerializations?: boolean) => [DeltaHandler, IDelta[]];
7
- /**
8
- * An interface for {@link DeltaHandler delta handlers} that can be switched on and off — “latching”.
9
- */
10
- export interface LatchingDeltaHandler extends DeltaHandler {
11
- latch(emitDeltas: boolean): void;
12
- }
13
- /**
14
- * @return a latching version of the given {@link DeltaHandler delta handler}.
15
- */
16
- export declare const latching: (handleDelta: DeltaHandler) => LatchingDeltaHandler;
17
- //# sourceMappingURL=handlers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/deltas/handlers.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAIlC;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;AAEnD,eAAO,MAAM,sBAAsB,GAAI,6BAA2B,KAAG,CAAC,YAAY,EAAE,MAAM,EAAE,CAS3F,CAAC;AAGF;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,YAAY;IACtD,KAAK,CAAC,UAAU,EAAE,OAAO,GAAG,IAAI,CAAC;CACpC;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,GAAI,aAAa,YAAY,KAAG,oBAcpD,CAAC"}
@@ -1,43 +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 { serializeDelta } from "./serialization/index.js";
18
- export const collectingDeltaHandler = (printSerializations = false) => {
19
- const deltas = [];
20
- const handleDelta = (delta) => {
21
- deltas.push(delta);
22
- if (printSerializations) {
23
- console.log(JSON.stringify(serializeDelta(delta), null, 4));
24
- }
25
- };
26
- return [handleDelta, deltas];
27
- };
28
- /**
29
- * @return a latching version of the given {@link DeltaHandler delta handler}.
30
- */
31
- export const latching = (handleDelta) => {
32
- let emitDeltas = false;
33
- return Object.assign((delta) => {
34
- if (emitDeltas) {
35
- handleDelta(delta);
36
- }
37
- }, {
38
- latch(emitDeltas_) {
39
- emitDeltas = emitDeltas_;
40
- },
41
- });
42
- };
43
- //# sourceMappingURL=handlers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/deltas/handlers.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;AAGtC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAQzD,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,mBAAmB,GAAG,KAAK,EAA4B,EAAE;IAC5F,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,WAAW,GAAiB,CAAC,KAAK,EAAE,EAAE;QACxC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnB,IAAI,mBAAmB,EAAE,CAAC;YACtB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QAChE,CAAC;IACL,CAAC,CAAC;IACF,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;AACjC,CAAC,CAAC;AAUF;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,WAAyB,EAAwB,EAAE;IACxE,IAAI,UAAU,GAAG,KAAK,CAAC;IACvB,OAAO,MAAM,CAAC,MAAM,CAChB,CAAC,KAAa,EAAE,EAAE;QACd,IAAI,UAAU,EAAE,CAAC;YACb,WAAW,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;IACL,CAAC,EACD;QACI,KAAK,CAAC,WAAoB;YACtB,UAAU,GAAG,WAAW,CAAC;QAC7B,CAAC;KACJ,CACJ,CAAC;AACN,CAAC,CAAC"}
@@ -1,64 +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
-
18
- import { IDelta } from "./base.js"
19
- import { serializeDelta } from "./serialization/index.js"
20
-
21
-
22
- /**
23
- * A type for functions that handle deltas.
24
- */
25
- export type DeltaHandler = (delta: IDelta) => void;
26
-
27
- export const collectingDeltaHandler = (printSerializations = false): [DeltaHandler, IDelta[]] => {
28
- const deltas: IDelta[] = [];
29
- const handleDelta: DeltaHandler = (delta) => {
30
- deltas.push(delta);
31
- if (printSerializations) {
32
- console.log(JSON.stringify(serializeDelta(delta), null, 4));
33
- }
34
- };
35
- return [handleDelta, deltas];
36
- };
37
-
38
-
39
- /**
40
- * An interface for {@link DeltaHandler delta handlers} that can be switched on and off — “latching”.
41
- */
42
- export interface LatchingDeltaHandler extends DeltaHandler {
43
- latch(emitDeltas: boolean): void;
44
- }
45
-
46
- /**
47
- * @return a latching version of the given {@link DeltaHandler delta handler}.
48
- */
49
- export const latching = (handleDelta: DeltaHandler): LatchingDeltaHandler => {
50
- let emitDeltas = false;
51
- return Object.assign(
52
- (delta: IDelta) => {
53
- if (emitDeltas) {
54
- handleDelta(delta);
55
- }
56
- },
57
- {
58
- latch(emitDeltas_: boolean) {
59
- emitDeltas = emitDeltas_;
60
- },
61
- },
62
- );
63
- };
64
-