@opendaw/lib-box 0.0.19 → 0.0.20
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/README.md +6 -0
- package/dist/address.d.ts +7 -1
- package/dist/address.d.ts.map +1 -1
- package/dist/address.js +12 -0
- package/dist/editing.d.ts.map +1 -1
- package/dist/editing.js +31 -39
- package/dist/graph-edges.d.ts +0 -1
- package/dist/graph-edges.d.ts.map +1 -1
- package/dist/graph-edges.js +2 -4
- package/dist/graph.d.ts +1 -1
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +1 -4
- package/dist/pointer-hub.js +4 -4
- package/dist/pointer.d.ts +9 -1
- package/dist/pointer.d.ts.map +1 -1
- package/dist/pointer.js +34 -3
- package/package.json +4 -4
package/README.md
CHANGED
@@ -4,6 +4,12 @@ _This package is part of the openDAW SDK_
|
|
4
4
|
|
5
5
|
Graph-based object modeling system with serialization, transactions, and pointer management for TypeScript projects.
|
6
6
|
|
7
|
+
## Wishlist
|
8
|
+
|
9
|
+
* Introduce readonly fields (cannot only be written in the constructing phase)
|
10
|
+
* Introduce meta-fields (compile time only)
|
11
|
+
* Add array with all TypeMap keys
|
12
|
+
|
7
13
|
## Core Architecture
|
8
14
|
|
9
15
|
* **box.ts** - Core Box class for graph nodes with field management
|
package/dist/address.d.ts
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
import { Comparable, Comparator, DataInput, DataOutput, Func, int, Nullable, SortedSet, UUID } from "@opendaw/lib-std";
|
2
2
|
import { FieldKey, FieldKeys } from "./field";
|
3
|
-
export type AddressLayout = [UUID.Format, FieldKeys];
|
4
3
|
export type AddressJSON = {
|
5
4
|
uuid: Array<int>;
|
6
5
|
fields: Array<int>;
|
7
6
|
};
|
7
|
+
export type AddressLayout = [UUID.Format, FieldKeys];
|
8
8
|
export declare class Address implements Comparable<Address> {
|
9
9
|
#private;
|
10
10
|
static newSet<T>(keyExtractor: Func<T, Address>): SortedSet<Address, T>;
|
@@ -25,6 +25,7 @@ export declare class Address implements Comparable<Address> {
|
|
25
25
|
append(key: FieldKey): Address;
|
26
26
|
startsWith(other: Address): boolean;
|
27
27
|
write(output: DataOutput): void;
|
28
|
+
moveTo(target: UUID.Format): Address;
|
28
29
|
decompose(): AddressLayout;
|
29
30
|
toJSON(): {
|
30
31
|
uuid: number[];
|
@@ -44,4 +45,9 @@ export declare namespace Addressable {
|
|
44
45
|
const startsWith: <A extends Addressable>(address: Address, sorted: ReadonlyArray<A>) => Array<A>;
|
45
46
|
const endsWith: <A extends Addressable>(address: Address, sorted: ReadonlyArray<A>) => Array<A>;
|
46
47
|
}
|
48
|
+
export declare class AddressIdEncoder {
|
49
|
+
#private;
|
50
|
+
constructor();
|
51
|
+
getOrCreate(address: Address): string;
|
52
|
+
}
|
47
53
|
//# sourceMappingURL=address.d.ts.map
|
package/dist/address.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,UAAU,EACV,UAAU,EACV,SAAS,EACT,UAAU,EACV,IAAI,EACJ,GAAG,EACH,QAAQ,EACR,SAAS,EACT,IAAI,EACP,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAC,MAAM,SAAS,CAAA;AAE3C,MAAM,MAAM,
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,UAAU,EACV,UAAU,EACV,SAAS,EACT,UAAU,EACV,IAAI,EACJ,GAAG,EACH,QAAQ,EACR,SAAS,EACT,IAAI,EACP,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAC,MAAM,SAAS,CAAA;AAE3C,MAAM,MAAM,WAAW,GAAG;IAAE,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAAC,MAAM,EAAE,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
}
|
97
|
+
moveTo(target) { return new Address(target, this.#fieldKeys); }
|
97
98
|
decompose() { return [this.#uuid, this.#fieldKeys]; }
|
98
99
|
toJSON() { return { uuid: Array.from(this.#uuid.values()), fields: Array.from(this.#fieldKeys.values()) }; }
|
99
100
|
toArrayBuffer() {
|
@@ -131,3 +132,14 @@ export var Addressable;
|
|
131
132
|
.filter((addressable) => address.startsWith(addressable.address));
|
132
133
|
};
|
133
134
|
})(Addressable || (Addressable = {}));
|
135
|
+
export class AddressIdEncoder {
|
136
|
+
#ids;
|
137
|
+
#idCount;
|
138
|
+
constructor() {
|
139
|
+
this.#ids = Address.newSet(({ address }) => address);
|
140
|
+
this.#idCount = 0;
|
141
|
+
}
|
142
|
+
getOrCreate(address) {
|
143
|
+
return `id${this.#ids.getOrCreate(address, () => ({ address, id: `${++this.#idCount}` })).id}`;
|
144
|
+
}
|
145
|
+
}
|
package/dist/editing.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"editing.d.ts","sourceRoot":"","sources":["../src/editing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,SAAS,CAAA;AAChC,OAAO,EAAsB,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,kBAAkB,CAAA;
|
1
|
+
{"version":3,"file":"editing.d.ts","sourceRoot":"","sources":["../src/editing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,SAAS,CAAA;AAChC,OAAO,EAAsB,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,kBAAkB,CAAA;AAqB/E,MAAM,WAAW,mBAAmB;IAChC,OAAO,IAAI,IAAI,CAAA;IACf,MAAM,IAAI,IAAI,CAAA;CACjB;AAED,qBAAa,OAAO;;gBASJ,KAAK,EAAE,QAAQ;IAI3B,IAAI,KAAK,IAAI,QAAQ,CAAqB;IAE1C,OAAO,IAAI,OAAO;IAElB,KAAK,IAAI,IAAI;IAOb,IAAI,IAAI,OAAO;IASf,IAAI,IAAI,OAAO;IAaf,SAAS,IAAI,OAAO;IAEpB,MAAM,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,GAAE,OAAc,GAAG,MAAM,CAAC,CAAC,CAAC;IAW1E,iBAAiB,IAAI,mBAAmB;IAkCxC,IAAI,IAAI,IAAI;IAOZ,YAAY,IAAI,IAAI;CAKvB"}
|
package/dist/editing.js
CHANGED
@@ -1,35 +1,33 @@
|
|
1
1
|
import { Arrays, assert, Option } from "@opendaw/lib-std";
|
2
|
-
class
|
3
|
-
updates;
|
4
|
-
constructor(updates) {
|
5
|
-
|
2
|
+
class Modification {
|
3
|
+
#updates;
|
4
|
+
constructor(updates) { this.#updates = updates; }
|
5
|
+
inverse(graph) {
|
6
|
+
graph.beginTransaction();
|
7
|
+
this.#updates.toReversed().forEach(update => update.inverse(graph));
|
8
|
+
graph.endTransaction();
|
6
9
|
}
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
}
|
12
|
-
redo(graph) {
|
13
|
-
for (const update of this.updates) {
|
14
|
-
update.forward(graph);
|
15
|
-
}
|
10
|
+
forward(graph) {
|
11
|
+
graph.beginTransaction();
|
12
|
+
this.#updates.forEach(update => update.forward(graph));
|
13
|
+
graph.endTransaction();
|
16
14
|
}
|
17
15
|
}
|
18
16
|
export class Editing {
|
19
17
|
#graph;
|
20
18
|
#pending = [];
|
21
|
-
#
|
19
|
+
#marked = [];
|
22
20
|
#modifying = false;
|
23
21
|
#historyIndex = 0;
|
24
22
|
constructor(graph) {
|
25
23
|
this.#graph = graph;
|
26
24
|
}
|
27
25
|
get graph() { return this.#graph; }
|
28
|
-
isEmpty() { return this.#
|
26
|
+
isEmpty() { return this.#marked.length === 0 && this.#pending.length === 0; }
|
29
27
|
clear() {
|
30
28
|
assert(!this.#modifying, "Already modifying");
|
31
29
|
Arrays.clear(this.#pending);
|
32
|
-
Arrays.clear(this.#
|
30
|
+
Arrays.clear(this.#marked);
|
33
31
|
this.#historyIndex = 0;
|
34
32
|
}
|
35
33
|
undo() {
|
@@ -39,24 +37,20 @@ export class Editing {
|
|
39
37
|
if (this.#historyIndex === 0) {
|
40
38
|
return false;
|
41
39
|
}
|
42
|
-
this.#
|
43
|
-
|
44
|
-
editingStep.undo(this.#graph);
|
45
|
-
this.#graph.endTransaction();
|
40
|
+
const modifications = this.#marked[--this.#historyIndex];
|
41
|
+
modifications.toReversed().forEach(step => step.inverse(this.#graph));
|
46
42
|
this.#graph.edges().validateRequirements();
|
47
43
|
return true;
|
48
44
|
}
|
49
45
|
redo() {
|
50
|
-
if (this.#historyIndex === this.#
|
46
|
+
if (this.#historyIndex === this.#marked.length) {
|
51
47
|
return false;
|
52
48
|
}
|
53
49
|
if (this.#pending.length > 0) {
|
54
50
|
console.warn("redo while having pending updates?");
|
55
51
|
return false;
|
56
52
|
}
|
57
|
-
this.#
|
58
|
-
this.#history[this.#historyIndex++].redo(this.#graph);
|
59
|
-
this.#graph.endTransaction();
|
53
|
+
this.#marked[this.#historyIndex++].forEach(step => step.forward(this.#graph));
|
60
54
|
this.#graph.edges().validateRequirements();
|
61
55
|
return true;
|
62
56
|
}
|
@@ -65,7 +59,7 @@ export class Editing {
|
|
65
59
|
canModify() { return !this.#graph.inTransaction(); }
|
66
60
|
modify(modifier, mark = true) {
|
67
61
|
if (this.#modifying) {
|
68
|
-
// we just keep adding new updates
|
62
|
+
// we just keep adding new pending updates
|
69
63
|
return Option.wrap(modifier());
|
70
64
|
}
|
71
65
|
if (mark && this.#pending.length > 0) {
|
@@ -80,17 +74,13 @@ export class Editing {
|
|
80
74
|
beginModification() {
|
81
75
|
this.#graph.beginTransaction();
|
82
76
|
this.#modifying = true;
|
83
|
-
const subscription = this.#graph.subscribeToAllUpdates({
|
84
|
-
onUpdate: (update) => this.#pending.push(update)
|
85
|
-
});
|
86
77
|
const complete = () => {
|
87
|
-
this.#graph.endTransaction();
|
88
|
-
subscription.terminate();
|
89
78
|
this.#modifying = false;
|
79
|
+
this.#graph.endTransaction();
|
90
80
|
this.#graph.edges().validateRequirements();
|
91
81
|
};
|
92
82
|
return {
|
93
|
-
approve:
|
83
|
+
approve: complete,
|
94
84
|
revert: () => {
|
95
85
|
this.clearPending();
|
96
86
|
complete();
|
@@ -100,12 +90,14 @@ export class Editing {
|
|
100
90
|
#modify(modifier) {
|
101
91
|
assert(!this.#modifying, "Already modifying");
|
102
92
|
this.#modifying = true;
|
103
|
-
const
|
104
|
-
|
105
|
-
});
|
93
|
+
const updates = [];
|
94
|
+
const subscription = this.#graph.subscribeToAllUpdates({ onUpdate: (update) => { updates.push(update); } });
|
106
95
|
this.#graph.beginTransaction();
|
107
96
|
const result = modifier();
|
108
97
|
this.#graph.endTransaction();
|
98
|
+
if (updates.length > 0) {
|
99
|
+
this.#pending.push(new Modification(updates));
|
100
|
+
}
|
109
101
|
subscription.terminate();
|
110
102
|
this.#modifying = false;
|
111
103
|
this.#graph.edges().validateRequirements();
|
@@ -115,17 +107,17 @@ export class Editing {
|
|
115
107
|
if (this.#pending.length === 0) {
|
116
108
|
return;
|
117
109
|
}
|
118
|
-
if (this.#
|
119
|
-
this.#
|
110
|
+
if (this.#marked.length - this.#historyIndex > 0) {
|
111
|
+
this.#marked.splice(this.#historyIndex);
|
120
112
|
}
|
121
|
-
this.#
|
122
|
-
this.#historyIndex = this.#
|
113
|
+
this.#marked.push(this.#pending.splice(0));
|
114
|
+
this.#historyIndex = this.#marked.length;
|
123
115
|
}
|
124
116
|
clearPending() {
|
125
117
|
if (this.#pending.length === 0) {
|
126
118
|
return;
|
127
119
|
}
|
128
|
-
this.#pending.reverse().forEach(
|
120
|
+
this.#pending.reverse().forEach(modification => modification.inverse(this.#graph));
|
129
121
|
this.#pending.length = 0;
|
130
122
|
}
|
131
123
|
}
|
package/dist/graph-edges.d.ts
CHANGED
@@ -12,6 +12,5 @@ export declare class GraphEdges {
|
|
12
12
|
outgoingEdgesOf(box: Box): ReadonlyArray<[PointerField, Address]>;
|
13
13
|
incomingEdgesOf(vertex: Box | Vertex): ReadonlyArray<PointerField>;
|
14
14
|
validateRequirements(): void;
|
15
|
-
verifyPointers(): void;
|
16
15
|
}
|
17
16
|
//# sourceMappingURL=graph-edges.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"graph-edges.d.ts","sourceRoot":"","sources":["../src/graph-edges.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAA;AACjC,OAAO,EAAC,YAAY,EAAC,MAAM,WAAW,CAAA;AACtC,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAA;AAC/B,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAA;AAEzB,qBAAa,UAAU;;;IAanB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI;IAchD,iBAAiB,CAAC,GAAG,KAAK,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,IAAI;IAoBrD,OAAO,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI;IAQpD,UAAU,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI;IAOtC,eAAe,CAAC,GAAG,EAAE,GAAG,GAAG,aAAa,CAAC,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAIjE,eAAe,CAAC,MAAM,EAAE,GAAG,GAAG,MAAM,GAAG,aAAa,CAAC,YAAY,CAAC;IASlE,oBAAoB,IAAI,IAAI;
|
1
|
+
{"version":3,"file":"graph-edges.d.ts","sourceRoot":"","sources":["../src/graph-edges.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAA;AACjC,OAAO,EAAC,YAAY,EAAC,MAAM,WAAW,CAAA;AACtC,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAA;AAC/B,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAA;AAEzB,qBAAa,UAAU;;;IAanB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI;IAchD,iBAAiB,CAAC,GAAG,KAAK,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,IAAI;IAoBrD,OAAO,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI;IAQpD,UAAU,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI;IAOtC,eAAe,CAAC,GAAG,EAAE,GAAG,GAAG,aAAa,CAAC,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAIjE,eAAe,CAAC,MAAM,EAAE,GAAG,GAAG,MAAM,GAAG,aAAa,CAAC,YAAY,CAAC;IASlE,oBAAoB,IAAI,IAAI;CAgC/B"}
|
package/dist/graph-edges.js
CHANGED
@@ -72,6 +72,7 @@ export class GraphEdges {
|
|
72
72
|
}
|
73
73
|
validateRequirements() {
|
74
74
|
this.#requiresTarget.forEach(pointer => {
|
75
|
+
assert(pointer.isAttached(), `Pointer ${pointer.address.toString()} is not attached`);
|
75
76
|
if (pointer.isEmpty()) {
|
76
77
|
if (pointer.mandatory) {
|
77
78
|
return panic(`Pointer ${pointer.toString()} requires an edge.`);
|
@@ -82,6 +83,7 @@ export class GraphEdges {
|
|
82
83
|
}
|
83
84
|
});
|
84
85
|
this.#requiresPointer.forEach(target => {
|
86
|
+
assert(target.isAttached(), `Target ${target.address.toString()} is not attached`);
|
85
87
|
if (target.pointerHub.isEmpty()) {
|
86
88
|
if (target.pointerRules.mandatory) {
|
87
89
|
return panic(`Target ${target.toString()} requires an edge.`);
|
@@ -92,10 +94,6 @@ export class GraphEdges {
|
|
92
94
|
}
|
93
95
|
});
|
94
96
|
}
|
95
|
-
verifyPointers() {
|
96
|
-
this.#requiresTarget.forEach(pointer => assert(pointer.isAttached(), `${pointer.address.toString()} is not attached`));
|
97
|
-
this.#requiresPointer.forEach(vertex => assert(vertex.isAttached(), `${vertex.address.toString()} is not attached`));
|
98
|
-
}
|
99
97
|
#collectSameBox(set, id, map) {
|
100
98
|
const range = Address.boxRange(set, id, map);
|
101
99
|
return isDefined(range) ? set.values().slice(range[0], range[1]) : Arrays.empty();
|
package/dist/graph.d.ts
CHANGED
@@ -26,7 +26,7 @@ export declare class BoxGraph<BoxMap = any> {
|
|
26
26
|
endTransaction(): void;
|
27
27
|
inTransaction(): boolean;
|
28
28
|
constructingBox(): boolean;
|
29
|
-
createBox(name: keyof BoxMap, uuid: UUID.Format, constructor: Procedure<Box>):
|
29
|
+
createBox(name: keyof BoxMap, uuid: UUID.Format, constructor: Procedure<Box>): Box;
|
30
30
|
stageBox<B extends Box>(box: B, constructor?: Procedure<B>): B;
|
31
31
|
subscribeTransaction(listener: TransactionListener): Subscription;
|
32
32
|
subscribeToAllUpdates(listener: UpdateListener): Subscription;
|
package/dist/graph.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../src/graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAKH,IAAI,EACJ,GAAG,EAGH,MAAM,EAEN,SAAS,EAET,YAAY,EACZ,IAAI,EACP,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAA;AACjC,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAA;AAC/B,OAAO,EAAC,YAAY,EAAC,MAAM,WAAW,CAAA;AACtC,OAAO,EAAC,cAAc,EAAE,eAAe,EAAC,MAAM,aAAa,CAAA;AAE3D,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAA;AACzB,OAAO,EAAuE,MAAM,EAAC,MAAM,WAAW,CAAA;AACtG,OAAO,EAAc,WAAW,EAAC,MAAM,eAAe,CAAA;AACtD,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAA;AAExC,MAAM,MAAM,UAAU,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,MAAM,MAAM,EAClB,K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 -49,7 +49,7 @@ export class BoxGraph {
|
|
49
49
|
inTransaction() { return this.#inTransaction; }
|
50
50
|
constructingBox() { return this.#constructingBox; }
|
51
51
|
createBox(name, uuid, constructor) {
|
52
|
-
this.#boxFactory.unwrap("No box-factory installed")(name, this, uuid, constructor);
|
52
|
+
return this.#boxFactory.unwrap("No box-factory installed")(name, this, uuid, constructor);
|
53
53
|
}
|
54
54
|
stageBox(box, constructor) {
|
55
55
|
this.#assertTransaction();
|
@@ -171,10 +171,7 @@ export class BoxGraph {
|
|
171
171
|
return { boxes: boxes, pointers: Array.from(pointers).reverse() };
|
172
172
|
}
|
173
173
|
verifyPointers() {
|
174
|
-
console.debug("validate requirements");
|
175
174
|
this.#edges.validateRequirements();
|
176
|
-
this.#edges.verifyPointers();
|
177
|
-
console.debug("verify pointers");
|
178
175
|
let count = 0 | 0;
|
179
176
|
const verify = (vertex) => {
|
180
177
|
for (const field of vertex.fields()) {
|
package/dist/pointer-hub.js
CHANGED
@@ -6,8 +6,8 @@ export class PointerHub {
|
|
6
6
|
return Option.wrap(`PointerField cannot point to itself: ${pointer}`);
|
7
7
|
}
|
8
8
|
if (!target.pointerRules.accepts.some((type) => type === pointer.pointerType)) {
|
9
|
-
|
10
|
-
return Option.wrap(`${pointer.
|
9
|
+
const accepting = target.pointerRules.accepts.join(", ");
|
10
|
+
return Option.wrap(`${String(pointer.pointerType)} does not satisfy any of the allowed types (${accepting}).`);
|
11
11
|
}
|
12
12
|
return Option.None;
|
13
13
|
}
|
@@ -59,8 +59,8 @@ export class PointerHub {
|
|
59
59
|
return panic(issue.unwrap());
|
60
60
|
}
|
61
61
|
if (this.#inTransaction.isEmpty()) {
|
62
|
-
this.#vertex.graph.subscribeEndTransaction(this.#onEndTransaction);
|
63
62
|
this.#inTransaction = Option.wrap([{ type: "add", pointerField }]);
|
63
|
+
this.#vertex.graph.subscribeEndTransaction(this.#onEndTransaction);
|
64
64
|
}
|
65
65
|
else {
|
66
66
|
this.#inTransaction.unwrap().push({ type: "add", pointerField });
|
@@ -69,8 +69,8 @@ export class PointerHub {
|
|
69
69
|
}
|
70
70
|
onRemoved(pointerField) {
|
71
71
|
if (this.#inTransaction.isEmpty()) {
|
72
|
-
this.#vertex.graph.subscribeEndTransaction(this.#onEndTransaction);
|
73
72
|
this.#inTransaction = Option.wrap([{ type: "remove", pointerField }]);
|
73
|
+
this.#vertex.graph.subscribeEndTransaction(this.#onEndTransaction);
|
74
74
|
}
|
75
75
|
else {
|
76
76
|
this.#inTransaction.unwrap().push({ type: "remove", pointerField });
|
package/dist/pointer.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { DataInput, DataOutput, Nullish, Observer, Option, Subscription } from "@opendaw/lib-std";
|
1
|
+
import { DataInput, DataOutput, Nullish, Observer, Option, Provider, Subscription } from "@opendaw/lib-std";
|
2
2
|
import { Vertex, VertexVisitor } from "./vertex";
|
3
3
|
import { Address } from "./address";
|
4
4
|
import { PointerHub } from "./pointer-hub";
|
@@ -6,9 +6,17 @@ import { Field, FieldConstruct } from "./field";
|
|
6
6
|
declare const _Unreferenceable: unique symbol;
|
7
7
|
export type UnreferenceableType = typeof _Unreferenceable;
|
8
8
|
export type PointerTypes = number | string | UnreferenceableType;
|
9
|
+
export interface SpecialEncoder {
|
10
|
+
map(pointer: PointerField): Option<Address>;
|
11
|
+
}
|
12
|
+
export interface SpecialDecoder {
|
13
|
+
map(pointer: PointerField, newAddress: Option<Address>): Option<Address>;
|
14
|
+
}
|
9
15
|
export declare class PointerField<P extends PointerTypes = PointerTypes> extends Field<UnreferenceableType, never> {
|
10
16
|
#private;
|
11
17
|
static create<P extends PointerTypes>(construct: FieldConstruct<UnreferenceableType>, pointerType: P, mandatory: boolean): PointerField<P>;
|
18
|
+
static encodeWith<R>(encoder: SpecialEncoder, exec: Provider<R>): R;
|
19
|
+
static decodeWith<R>(decoder: SpecialDecoder, exec: Provider<R>): R;
|
12
20
|
private constructor();
|
13
21
|
get pointerHub(): PointerHub;
|
14
22
|
get pointerType(): P;
|
package/dist/pointer.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"pointer.d.ts","sourceRoot":"","sources":["../src/pointer.ts"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"pointer.d.ts","sourceRoot":"","sources":["../src/pointer.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,SAAS,EACT,UAAU,EACV,OAAO,EACP,QAAQ,EACR,MAAM,EAEN,QAAQ,EAER,YAAY,EAEf,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,UAAU,CAAA;AAC9C,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAA;AACjC,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAA;AACxC,OAAO,EAAC,KAAK,EAAE,cAAc,EAAC,MAAM,SAAS,CAAA;AAG7C,QAAA,MAAM,gBAAgB,eAA4B,CAAA;AAElD,MAAM,MAAM,mBAAmB,GAAG,OAAO,gBAAgB,CAAA;AAEzD,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,mBAAmB,CAAA;AAEhE,MAAM,WAAW,cAAc;IAAE,GAAG,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;CAAC;AAE7E,MAAM,WAAW,cAAc;IAAE,GAAG,CAAC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;CAAC;AAE1G,qBAAa,YAAY,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY,CAAE,SAAQ,KAAK,CAAC,mBAAmB,EAAE,KAAK,CAAC;;IACtG,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,YAAY,EAAE,SAAS,EAAE,cAAc,CAAC,mBAAmB,CAAC,EAC9C,WAAW,EAAE,CAAC,EACd,SAAS,EAAE,OAAO,GAAG,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|
package/dist/pointer.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Option, panic, safeExecute } from "@opendaw/lib-std";
|
1
|
+
import { assert, Option, panic, safeExecute, tryCatch } from "@opendaw/lib-std";
|
2
2
|
import { Address } from "./address";
|
3
3
|
import { PointerHub } from "./pointer-hub";
|
4
4
|
import { Field } from "./field";
|
@@ -8,6 +8,28 @@ export class PointerField extends Field {
|
|
8
8
|
static create(construct, pointerType, mandatory) {
|
9
9
|
return new PointerField(construct, pointerType, mandatory);
|
10
10
|
}
|
11
|
+
static encodeWith(encoder, exec) {
|
12
|
+
assert(this.#encoder.isEmpty(), "SerializationEncoder already in use");
|
13
|
+
this.#encoder = Option.wrap(encoder);
|
14
|
+
const result = tryCatch(exec);
|
15
|
+
this.#encoder = Option.None;
|
16
|
+
if (result.status === "failure") {
|
17
|
+
throw result.error;
|
18
|
+
}
|
19
|
+
return result.value;
|
20
|
+
}
|
21
|
+
static decodeWith(decoder, exec) {
|
22
|
+
assert(this.#decoder.isEmpty(), "SerializationDecoder already in use");
|
23
|
+
this.#decoder = Option.wrap(decoder);
|
24
|
+
const result = tryCatch(exec);
|
25
|
+
this.#decoder = Option.None;
|
26
|
+
if (result.status === "failure") {
|
27
|
+
throw result.error;
|
28
|
+
}
|
29
|
+
return result.value;
|
30
|
+
}
|
31
|
+
static #encoder = Option.None;
|
32
|
+
static #decoder = Option.None;
|
11
33
|
#pointerType;
|
12
34
|
#mandatory;
|
13
35
|
#targetVertex = Option.None;
|
@@ -65,10 +87,19 @@ export class PointerField extends Field {
|
|
65
87
|
nonEmpty() { return this.targetAddress.nonEmpty(); }
|
66
88
|
resolvedTo(newTarget) { this.#targetVertex = newTarget; }
|
67
89
|
read(input) {
|
68
|
-
|
90
|
+
const address = input.readBoolean()
|
91
|
+
? Option.wrap(Address.read(input))
|
92
|
+
: Option.None;
|
93
|
+
this.targetAddress = PointerField.#decoder.match({
|
94
|
+
none: () => address,
|
95
|
+
some: decoder => decoder.map(this, address)
|
96
|
+
});
|
69
97
|
}
|
70
98
|
write(output) {
|
71
|
-
|
99
|
+
PointerField.#encoder.match({
|
100
|
+
none: () => this.#targetAddress,
|
101
|
+
some: encoder => encoder.map(this)
|
102
|
+
}).match({
|
72
103
|
none: () => output.writeBoolean(false),
|
73
104
|
some: address => {
|
74
105
|
output.writeBoolean(true);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@opendaw/lib-box",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.20",
|
4
4
|
"main": "./dist/index.js",
|
5
5
|
"types": "./dist/index.d.ts",
|
6
6
|
"license": "LGPL-3.0-or-later",
|
@@ -22,12 +22,12 @@
|
|
22
22
|
"test": "vitest run"
|
23
23
|
},
|
24
24
|
"dependencies": {
|
25
|
-
"@opendaw/lib-runtime": "^0.0.
|
26
|
-
"@opendaw/lib-std": "^0.0.
|
25
|
+
"@opendaw/lib-runtime": "^0.0.20",
|
26
|
+
"@opendaw/lib-std": "^0.0.20"
|
27
27
|
},
|
28
28
|
"devDependencies": {
|
29
29
|
"@opendaw/eslint-config": "^0.0.18",
|
30
30
|
"@opendaw/typescript-config": "^0.0.19"
|
31
31
|
},
|
32
|
-
"gitHead": "
|
32
|
+
"gitHead": "de891be4fc9e418776b3a6c433748e287abab912"
|
33
33
|
}
|