@opendaw/lib-box 0.0.6
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 +1 -0
- package/dist/address.d.ts +47 -0
- package/dist/address.d.ts.map +1 -0
- package/dist/address.js +133 -0
- package/dist/array.d.ts +19 -0
- package/dist/array.d.ts.map +1 -0
- package/dist/array.js +32 -0
- package/dist/box.d.ts +51 -0
- package/dist/box.d.ts.map +1 -0
- package/dist/box.js +122 -0
- package/dist/dispatchers.d.ts +16 -0
- package/dist/dispatchers.d.ts.map +1 -0
- package/dist/dispatchers.js +127 -0
- package/dist/editing.d.ts +21 -0
- package/dist/editing.d.ts.map +1 -0
- package/dist/editing.js +131 -0
- package/dist/field.d.ts +42 -0
- package/dist/field.d.ts.map +1 -0
- package/dist/field.js +80 -0
- package/dist/graph-edges.d.ts +16 -0
- package/dist/graph-edges.d.ts.map +1 -0
- package/dist/graph-edges.js +109 -0
- package/dist/graph.d.ts +55 -0
- package/dist/graph.d.ts.map +1 -0
- package/dist/graph.js +262 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/object.d.ts +17 -0
- package/dist/object.d.ts.map +1 -0
- package/dist/object.js +19 -0
- package/dist/pointer-hub.d.ts +26 -0
- package/dist/pointer-hub.d.ts.map +1 -0
- package/dist/pointer-hub.js +110 -0
- package/dist/pointer.d.ts +32 -0
- package/dist/pointer.d.ts.map +1 -0
- package/dist/pointer.js +82 -0
- package/dist/primitive.d.ts +110 -0
- package/dist/primitive.d.ts.map +1 -0
- package/dist/primitive.js +152 -0
- package/dist/serializer.d.ts +7 -0
- package/dist/serializer.d.ts.map +1 -0
- package/dist/serializer.js +29 -0
- package/dist/sync-source.d.ts +11 -0
- package/dist/sync-source.d.ts.map +1 -0
- package/dist/sync-source.js +72 -0
- package/dist/sync-target.d.ts +5 -0
- package/dist/sync-target.d.ts.map +1 -0
- package/dist/sync-target.js +40 -0
- package/dist/sync.d.ts +24 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +1 -0
- package/dist/updates.d.ts +70 -0
- package/dist/updates.d.ts.map +1 -0
- package/dist/updates.js +178 -0
- package/dist/vertex.d.ts +41 -0
- package/dist/vertex.d.ts.map +1 -0
- package/dist/vertex.js +1 -0
- package/package.json +33 -0
package/dist/updates.js
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
import { ValueSerialization } from "./primitive";
|
2
|
+
import { Address } from "./address";
|
3
|
+
import { Arrays, ByteArrayInput, Option, UUID } from "@opendaw/lib-std";
|
4
|
+
export var Updates;
|
5
|
+
(function (Updates) {
|
6
|
+
Updates.decode = (input) => {
|
7
|
+
const numBlocks = input.readInt();
|
8
|
+
return Arrays.create(() => {
|
9
|
+
const type = input.readString();
|
10
|
+
switch (type) {
|
11
|
+
case "new": {
|
12
|
+
const uuid = UUID.fromDataInput(input);
|
13
|
+
const name = input.readString();
|
14
|
+
const settings = new Int8Array(input.readInt());
|
15
|
+
input.readBytes(settings);
|
16
|
+
return new NewUpdate(uuid, name, settings.buffer);
|
17
|
+
}
|
18
|
+
case "pointer": {
|
19
|
+
const address = Address.read(input);
|
20
|
+
const oldAddress = input.readBoolean() ? Option.wrap(Address.read(input)) : Option.None;
|
21
|
+
const newAddress = input.readBoolean() ? Option.wrap(Address.read(input)) : Option.None;
|
22
|
+
return new PointerUpdate(address, oldAddress, newAddress);
|
23
|
+
}
|
24
|
+
case "primitive": {
|
25
|
+
const address = Address.read(input);
|
26
|
+
const type = input.readString();
|
27
|
+
const serializer = ValueSerialization[type];
|
28
|
+
const oldValue = serializer.decode(input);
|
29
|
+
const newValue = serializer.decode(input);
|
30
|
+
return new PrimitiveUpdate(address, serializer, oldValue, newValue);
|
31
|
+
}
|
32
|
+
case "delete": {
|
33
|
+
const uuid = UUID.fromDataInput(input);
|
34
|
+
const name = input.readString();
|
35
|
+
const settings = new Int8Array(input.readInt());
|
36
|
+
input.readBytes(settings);
|
37
|
+
return new DeleteUpdate(uuid, name, settings.buffer);
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}, numBlocks);
|
41
|
+
};
|
42
|
+
})(Updates || (Updates = {}));
|
43
|
+
export class NewUpdate {
|
44
|
+
type = "new";
|
45
|
+
#uuid;
|
46
|
+
#name;
|
47
|
+
#settings;
|
48
|
+
constructor(uuid, name, settings) {
|
49
|
+
this.#uuid = uuid;
|
50
|
+
this.#name = name;
|
51
|
+
this.#settings = settings;
|
52
|
+
}
|
53
|
+
get uuid() { return this.#uuid; }
|
54
|
+
get name() { return this.#name; }
|
55
|
+
get settings() { return this.#settings; }
|
56
|
+
forward(graph) {
|
57
|
+
graph.createBox(this.#name, this.#uuid, box => box.read(new ByteArrayInput(this.#settings)));
|
58
|
+
}
|
59
|
+
inverse(graph) {
|
60
|
+
graph.findBox(this.#uuid).unwrap(() => `Could not find ${this.#name}`).unstage();
|
61
|
+
}
|
62
|
+
write(output) {
|
63
|
+
output.writeString(this.type);
|
64
|
+
UUID.toDataOutput(output, this.#uuid);
|
65
|
+
output.writeString(this.#name);
|
66
|
+
output.writeInt(this.#settings.byteLength);
|
67
|
+
output.writeBytes(new Int8Array(this.#settings));
|
68
|
+
}
|
69
|
+
toString() {
|
70
|
+
return `{NewUpdate uuid: ${UUID.toString(this.#uuid)}, attachment: ${this.settings.byteLength}b`;
|
71
|
+
}
|
72
|
+
toDebugString(_graph) { return this.toString(); }
|
73
|
+
}
|
74
|
+
export class PrimitiveUpdate {
|
75
|
+
type = "primitive";
|
76
|
+
#address;
|
77
|
+
#serialization;
|
78
|
+
#oldValue;
|
79
|
+
#newValue;
|
80
|
+
constructor(address, serialization, oldValue, newValue) {
|
81
|
+
this.#address = address;
|
82
|
+
this.#serialization = serialization;
|
83
|
+
this.#oldValue = oldValue;
|
84
|
+
this.#newValue = newValue;
|
85
|
+
}
|
86
|
+
get address() { return this.#address; }
|
87
|
+
get oldValue() { return this.#oldValue; }
|
88
|
+
get newValue() { return this.#newValue; }
|
89
|
+
matches(field) { return field.address.equals(this.address); }
|
90
|
+
inverse(graph) { this.field(graph).setValue(this.#oldValue); }
|
91
|
+
forward(graph) { this.field(graph).setValue(this.#newValue); }
|
92
|
+
field(graph) {
|
93
|
+
return graph.findVertex(this.#address)
|
94
|
+
.unwrap(() => `Could not find PrimitiveField at ${this.#address}`);
|
95
|
+
}
|
96
|
+
write(output) {
|
97
|
+
output.writeString(this.type);
|
98
|
+
this.#address.write(output);
|
99
|
+
output.writeString(this.#serialization.type);
|
100
|
+
this.#serialization.encode(output, this.#oldValue);
|
101
|
+
this.#serialization.encode(output, this.#newValue);
|
102
|
+
}
|
103
|
+
toString() {
|
104
|
+
return `{PrimitiveUpdate oldValue: ${this.#oldValue}, newValue: ${this.#newValue}`;
|
105
|
+
}
|
106
|
+
}
|
107
|
+
export class PointerUpdate {
|
108
|
+
type = "pointer";
|
109
|
+
#address;
|
110
|
+
#oldValue;
|
111
|
+
#newValue;
|
112
|
+
constructor(address, oldValue, newValue) {
|
113
|
+
this.#address = address;
|
114
|
+
this.#oldValue = oldValue;
|
115
|
+
this.#newValue = newValue;
|
116
|
+
}
|
117
|
+
get address() { return this.#address; }
|
118
|
+
get oldValue() { return this.#oldValue; }
|
119
|
+
get newValue() { return this.#newValue; }
|
120
|
+
matches(field) { return field.address.equals(this.address); }
|
121
|
+
inverse(graph) { this.field(graph).targetAddress = this.#oldValue; }
|
122
|
+
forward(graph) { this.field(graph).targetAddress = this.#newValue; }
|
123
|
+
field(graph) {
|
124
|
+
return graph.findVertex(this.#address)
|
125
|
+
.unwrap(() => `Could not find PointerField at ${this.#address}`);
|
126
|
+
}
|
127
|
+
write(output) {
|
128
|
+
output.writeString(this.type);
|
129
|
+
this.#address.write(output);
|
130
|
+
this.#oldValue.match({
|
131
|
+
none: () => output.writeBoolean(false),
|
132
|
+
some: address => {
|
133
|
+
output.writeBoolean(true);
|
134
|
+
address.write(output);
|
135
|
+
}
|
136
|
+
});
|
137
|
+
this.#newValue.match({
|
138
|
+
none: () => output.writeBoolean(false),
|
139
|
+
some: address => {
|
140
|
+
output.writeBoolean(true);
|
141
|
+
address.write(output);
|
142
|
+
}
|
143
|
+
});
|
144
|
+
}
|
145
|
+
toString() {
|
146
|
+
return `{PointerUpdate oldValue: ${this.#oldValue.unwrapOrNull()}, newValue: ${this.#newValue.unwrapOrNull()}`;
|
147
|
+
}
|
148
|
+
}
|
149
|
+
export class DeleteUpdate {
|
150
|
+
type = "delete";
|
151
|
+
#uuid;
|
152
|
+
#name;
|
153
|
+
#settings;
|
154
|
+
constructor(uuid, name, settings) {
|
155
|
+
this.#uuid = uuid;
|
156
|
+
this.#name = name;
|
157
|
+
this.#settings = settings;
|
158
|
+
}
|
159
|
+
get uuid() { return this.#uuid; }
|
160
|
+
get name() { return this.#name; }
|
161
|
+
get settings() { return this.#settings; }
|
162
|
+
forward(graph) {
|
163
|
+
graph.findBox(this.#uuid).unwrap(() => `Could not find ${this.#name}`).unstage();
|
164
|
+
}
|
165
|
+
inverse(graph) {
|
166
|
+
graph.createBox(this.#name, this.#uuid, box => box.read(new ByteArrayInput(this.#settings)));
|
167
|
+
}
|
168
|
+
write(output) {
|
169
|
+
output.writeString(this.type);
|
170
|
+
UUID.toDataOutput(output, this.#uuid);
|
171
|
+
output.writeString(this.#name);
|
172
|
+
output.writeInt(this.#settings.byteLength);
|
173
|
+
output.writeBytes(new Int8Array(this.#settings));
|
174
|
+
}
|
175
|
+
toString() {
|
176
|
+
return `{DeleteUpdate uuid: ${UUID.toString(this.#uuid)}, attachment: ${this.settings.byteLength}b`;
|
177
|
+
}
|
178
|
+
}
|
package/dist/vertex.d.ts
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
import { DataInput, DataOutput, Nullish, Option } from "@opendaw/lib-std";
|
2
|
+
import { Addressable } from "./address";
|
3
|
+
import { Box } from "./box";
|
4
|
+
import { Field, Fields } from "./field";
|
5
|
+
import { PointerField, PointerTypes } from "./pointer";
|
6
|
+
import { PointerHub } from "./pointer-hub";
|
7
|
+
import { PrimitiveField } from "./primitive";
|
8
|
+
import { ArrayField } from "./array";
|
9
|
+
import { BoxGraph } from "./graph";
|
10
|
+
import { ObjectField } from "./object";
|
11
|
+
export interface PointerRules<P extends PointerTypes> {
|
12
|
+
readonly accepts: ReadonlyArray<P>;
|
13
|
+
readonly mandatory: boolean;
|
14
|
+
}
|
15
|
+
export declare const NoPointers: PointerRules<never>;
|
16
|
+
export interface VertexVisitor<RETURN = void> {
|
17
|
+
visitArrayField?(field: ArrayField): RETURN;
|
18
|
+
visitObjectField?<FIELDS extends Fields>(field: ObjectField<FIELDS>): RETURN;
|
19
|
+
visitPointerField?(field: PointerField): RETURN;
|
20
|
+
visitPrimitiveField?(field: PrimitiveField): RETURN;
|
21
|
+
visitField?(field: Field): RETURN;
|
22
|
+
}
|
23
|
+
export interface Visitable {
|
24
|
+
accept<VISITOR extends VertexVisitor<any>>(visitor: VISITOR): VISITOR extends VertexVisitor<infer R> ? Nullish<R> : void;
|
25
|
+
}
|
26
|
+
export interface Vertex<P extends PointerTypes = PointerTypes, F extends Fields = any> extends Addressable, Visitable {
|
27
|
+
get box(): Box;
|
28
|
+
get graph(): BoxGraph;
|
29
|
+
get parent(): Vertex;
|
30
|
+
get pointerHub(): PointerHub;
|
31
|
+
get pointerRules(): PointerRules<P>;
|
32
|
+
isBox(): this is Box;
|
33
|
+
isField(): this is Field;
|
34
|
+
isAttached(): boolean;
|
35
|
+
fields(): Iterable<Field>;
|
36
|
+
getField(key: keyof F): F[keyof F];
|
37
|
+
optField(key: keyof F): Option<F[keyof F]>;
|
38
|
+
read(input: DataInput): void;
|
39
|
+
write(output: DataOutput): void;
|
40
|
+
}
|
41
|
+
//# sourceMappingURL=vertex.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"vertex.d.ts","sourceRoot":"","sources":["../src/vertex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,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AO,SAAS,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAA;CAC3H;AAED,MAAM,WAAW,MAAM,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY,EAAE,CAAC,SAAS,MAAM,GAAG,GAAG,CAAE,SAAQ,WAAW,EAAE,SAAS;IACjH,IAAI,GAAG,IAAI,GAAG,CAAA;IACd,IAAI,KAAK,IAAI,QAAQ,CAAA;IACrB,IAAI,MAAM,IAAI,MAAM,CAAA;IACpB,IAAI,UAAU,IAAI,UAAU,CAAA;IAC5B,IAAI,YAAY,IAAI,YAAY,CAAC,CAAC,CAAC,CAAA;IAEnC,KAAK,IAAI,IAAI,IAAI,GAAG,CAAA;IACpB,OAAO,IAAI,IAAI,IAAI,KAAK,CAAA;IACxB,UAAU,IAAI,OAAO,CAAA;IACrB,MAAM,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAA;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;IAClC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IAC1C,IAAI,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAA;IAC5B,KAAK,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAA;CAClC"}
|
package/dist/vertex.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export const NoPointers = Object.freeze({ mandatory: false, accepts: [] });
|
package/package.json
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
{
|
2
|
+
"name": "@opendaw/lib-box",
|
3
|
+
"version": "0.0.6",
|
4
|
+
"main": "./dist/index.js",
|
5
|
+
"types": "./dist/index.d.ts",
|
6
|
+
"license": "LGPL-3.0-or-later",
|
7
|
+
"publishConfig": {
|
8
|
+
"access": "public"
|
9
|
+
},
|
10
|
+
"exports": {
|
11
|
+
".": {
|
12
|
+
"types": "./dist/index.d.ts",
|
13
|
+
"default": "./dist/index.js"
|
14
|
+
}
|
15
|
+
},
|
16
|
+
"files": [
|
17
|
+
"dist/**/*"
|
18
|
+
],
|
19
|
+
"scripts": {
|
20
|
+
"build": "tsc",
|
21
|
+
"lint": "eslint \"**/*.ts\"",
|
22
|
+
"test": "vitest run"
|
23
|
+
},
|
24
|
+
"dependencies": {
|
25
|
+
"@opendaw/lib-runtime": "^0.0.6",
|
26
|
+
"@opendaw/lib-std": "^0.0.6"
|
27
|
+
},
|
28
|
+
"devDependencies": {
|
29
|
+
"@opendaw/eslint-config": "^0.0.6",
|
30
|
+
"@opendaw/typescript-config": "^0.0.6"
|
31
|
+
},
|
32
|
+
"gitHead": "04e5363a9851c7e116a306c2e933c5f410980fbe"
|
33
|
+
}
|