@opendaw/studio-core 0.0.45 → 0.0.46

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.
@@ -1 +1 @@
1
- {"version":3,"file":"YService.d.ts","sourceRoot":"","sources":["../../src/ysync/YService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,MAAM,EAAmC,MAAM,kBAAkB,CAAA;AAQjF,OAAO,EAAC,OAAO,EAAE,UAAU,EAAC,MAAM,YAAY,CAAA;AAI9C,yBAAiB,QAAQ,CAAC;IAMf,MAAM,eAAe,GAAU,YAAY,MAAM,CAAC,OAAO,CAAC,EAC3B,KAAK,UAAU,EACf,UAAU,MAAM,KAAG,OAAO,CAAC,OAAO,CAiDvE,CAAA;CACJ"}
1
+ {"version":3,"file":"YService.d.ts","sourceRoot":"","sources":["../../src/ysync/YService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,MAAM,EAAyC,MAAM,kBAAkB,CAAA;AAQvF,OAAO,EAAC,OAAO,EAAE,UAAU,EAAC,MAAM,YAAY,CAAA;AAI9C,yBAAiB,QAAQ,CAAC;IAMf,MAAM,eAAe,GAAU,YAAY,MAAM,CAAC,OAAO,CAAC,EAC3B,KAAK,UAAU,EACf,UAAU,MAAM,KAAG,OAAO,CAAC,OAAO,CA6DvE,CAAA;CACJ"}
@@ -1,7 +1,7 @@
1
- import { Errors, Option, panic, RuntimeNotifier, TimeSpan } from "@opendaw/lib-std";
1
+ import { Errors, Option, panic, RuntimeNotifier, TimeSpan, UUID } from "@opendaw/lib-std";
2
2
  import { BoxGraph } from "@opendaw/lib-box";
3
3
  import { Promises } from "@opendaw/lib-runtime";
4
- import { BoxIO } from "@opendaw/studio-boxes";
4
+ import { BoxIO, UserInterfaceBox } from "@opendaw/studio-boxes";
5
5
  import { ProjectDecoder } from "@opendaw/studio-adapters";
6
6
  import { YSync } from "./YSync";
7
7
  import * as Y from "yjs";
@@ -33,13 +33,18 @@ export var YService;
33
33
  provider.on("sync", onSync);
34
34
  await Promises.timeout(promise, TimeSpan.seconds(10), "Timeout 'synced'");
35
35
  }
36
- const boxesMap = doc.getMap("boxes");
37
- if (boxesMap.size === 0) {
36
+ const boxes = doc.getMap("boxes");
37
+ const isRoomEmpty = boxes.size === 0;
38
+ if (isRoomEmpty) {
38
39
  const project = optProject.match({
39
40
  none: () => Project.new(env),
40
41
  some: project => project.copy()
41
42
  });
42
- const sync = await YSync.populate({ boxGraph: project.boxGraph, doc, conflict: () => project.invalid() });
43
+ const sync = await YSync.populateRoom({
44
+ boxGraph: project.boxGraph,
45
+ boxes,
46
+ conflict: () => project.invalid()
47
+ });
43
48
  project.own(sync);
44
49
  project.editing.disable();
45
50
  return project;
@@ -57,11 +62,17 @@ export var YService;
57
62
  }
58
63
  }
59
64
  const boxGraph = new BoxGraph(Option.wrap(BoxIO.create));
60
- const sync = await YSync.join({ boxGraph, doc, conflict: () => project.invalid() });
65
+ const sync = await YSync.joinRoom({ boxGraph, boxes, conflict: () => project.invalid() });
66
+ const mandatoryBoxes = ProjectDecoder.findMandatoryBoxes(boxGraph);
61
67
  const project = Project.skeleton(env, {
62
68
  boxGraph,
63
- mandatoryBoxes: ProjectDecoder.findMandatoryBoxes(boxGraph)
64
- });
69
+ mandatoryBoxes
70
+ }, false);
71
+ boxGraph.beginTransaction();
72
+ // TODO How takes care to remove the user interface boxes?
73
+ const userInterfaceBox = UserInterfaceBox.create(boxGraph, UUID.generate(), box => box.root.refer(mandatoryBoxes.rootBox.users));
74
+ boxGraph.endTransaction();
75
+ project.follow(userInterfaceBox);
65
76
  project.own(sync);
66
77
  project.editing.disable();
67
78
  return project;
@@ -3,15 +3,15 @@ import { BoxGraph } from "@opendaw/lib-box";
3
3
  import * as Y from "yjs";
4
4
  export type Construct<T> = {
5
5
  boxGraph: BoxGraph<T>;
6
- doc: Y.Doc;
6
+ boxes: Y.Map<unknown>;
7
7
  conflict?: Provider<boolean>;
8
8
  };
9
9
  export declare class YSync<T> implements Terminable {
10
10
  #private;
11
11
  static isEmpty(doc: Y.Doc): boolean;
12
- static populate<T>({ boxGraph, doc }: Construct<T>): Promise<YSync<T>>;
13
- static join<T>({ boxGraph, doc }: Construct<T>): Promise<YSync<T>>;
14
- constructor({ boxGraph, doc, conflict }: Construct<T>);
12
+ static populateRoom<T>({ boxGraph, boxes }: Construct<T>): Promise<YSync<T>>;
13
+ static joinRoom<T>({ boxGraph, boxes }: Construct<T>): Promise<YSync<T>>;
14
+ constructor({ boxGraph, boxes, conflict }: Construct<T>);
15
15
  terminate(): void;
16
16
  }
17
17
  //# sourceMappingURL=YSync.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"YSync.d.ts","sourceRoot":"","sources":["../../src/ysync/YSync.ts"],"names":[],"mappings":"AAAA,OAAO,EASH,QAAQ,EAER,UAAU,EAGb,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAa,QAAQ,EAA2D,MAAM,kBAAkB,CAAA;AAE/G,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAIxB,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IACvB,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACtB,GAAG,EAAE,CAAC,CAAC,GAAG,CAAA;IACV,QAAQ,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;CAC/B,CAAA;AAED,qBAAa,KAAK,CAAC,CAAC,CAAE,YAAW,UAAU;;IACvC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,GAAG,OAAO;WAItB,QAAQ,CAAC,CAAC,EAAE,EAAC,QAAQ,EAAE,GAAG,EAAC,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;WAa7D,IAAI,CAAC,CAAC,EAAE,EAAC,QAAQ,EAAE,GAAG,EAAC,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBA4B1D,EAAC,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAC,EAAE,SAAS,CAAC,CAAC,CAAC;IASnD,SAAS,IAAI,IAAI;CA0KpB"}
1
+ {"version":3,"file":"YSync.d.ts","sourceRoot":"","sources":["../../src/ysync/YSync.ts"],"names":[],"mappings":"AAAA,OAAO,EASH,QAAQ,EAER,UAAU,EAGb,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAa,QAAQ,EAA2D,MAAM,kBAAkB,CAAA;AAE/G,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAIxB,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IACvB,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACtB,KAAK,EAAE,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IACrB,QAAQ,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;CAC/B,CAAA;AAED,qBAAa,KAAK,CAAC,CAAC,CAAE,YAAW,UAAU;;IACvC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,GAAG,OAAO;WAItB,YAAY,CAAC,CAAC,EAAE,EAAC,QAAQ,EAAE,KAAK,EAAC,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;WAcnE,QAAQ,CAAC,CAAC,EAAE,EAAC,QAAQ,EAAE,KAAK,EAAC,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBA0BhE,EAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAC,EAAE,SAAS,CAAC,CAAC,CAAC;IAQrD,SAAS,IAAI,IAAI;CAgLpB"}
@@ -5,25 +5,25 @@ export class YSync {
5
5
  static isEmpty(doc) {
6
6
  return doc.getMap("boxes").size === 0;
7
7
  }
8
- static async populate({ boxGraph, doc }) {
8
+ static async populateRoom({ boxGraph, boxes }) {
9
9
  console.debug("populate");
10
- const boxesMap = doc.getMap("boxes");
11
- assert(boxesMap.size === 0, "BoxesMap must be empty");
12
- const sync = new YSync({ boxGraph, doc });
13
- doc.transact(() => boxGraph.boxes().forEach(box => {
10
+ assert(boxes.size === 0, "boxes must be empty");
11
+ const sync = new YSync({ boxGraph, boxes });
12
+ asDefined(boxes.doc, "Y.Map is not connect to Y.Doc")
13
+ .transact(() => boxGraph.boxes()
14
+ .forEach(box => {
14
15
  const key = UUID.toString(box.address.uuid);
15
16
  const map = YMapper.createBoxMap(box);
16
- boxesMap.set(key, map);
17
+ boxes.set(key, map);
17
18
  }), "[openDAW] populate");
18
19
  return sync;
19
20
  }
20
- static async join({ boxGraph, doc }) {
21
+ static async joinRoom({ boxGraph, boxes }) {
21
22
  console.debug("join");
22
23
  assert(boxGraph.boxes().length === 0, "BoxGraph must be empty");
23
- const sync = new YSync({ boxGraph, doc });
24
+ const sync = new YSync({ boxGraph, boxes });
24
25
  boxGraph.beginTransaction();
25
- const boxesMap = doc.getMap("boxes");
26
- boxesMap.forEach((value, key) => {
26
+ boxes.forEach((value, key) => {
27
27
  const boxMap = value;
28
28
  const uuid = UUID.parse(key);
29
29
  const name = boxMap.get("name");
@@ -36,16 +36,14 @@ export class YSync {
36
36
  }
37
37
  #terminator = new Terminator();
38
38
  #boxGraph;
39
- #doc;
40
39
  #conflict;
41
- #boxesMap;
40
+ #boxes;
42
41
  #updates;
43
42
  #ignoreUpdates = false;
44
- constructor({ boxGraph, doc, conflict }) {
43
+ constructor({ boxGraph, boxes, conflict }) {
45
44
  this.#boxGraph = boxGraph;
46
- this.#doc = doc;
47
45
  this.#conflict = Option.wrap(conflict);
48
- this.#boxesMap = doc.getMap("boxes");
46
+ this.#boxes = boxes;
49
47
  this.#updates = [];
50
48
  this.#terminator.ownAll(this.#setupYjs(), this.#setupOpenDAW());
51
49
  }
@@ -83,7 +81,8 @@ export class YSync {
83
81
  this.#ignoreUpdates = true;
84
82
  this.#boxGraph.endTransaction();
85
83
  this.#ignoreUpdates = false;
86
- this.#boxGraph.verifyPointers();
84
+ // TODO Only in DEV-MODE
85
+ // this.#boxGraph.verifyPointers()
87
86
  }
88
87
  catch (reason) {
89
88
  this.terminate();
@@ -94,11 +93,11 @@ export class YSync {
94
93
  this.#rollbackTransaction(events);
95
94
  }
96
95
  };
97
- this.#boxesMap.observeDeep(eventHandler);
98
- return { terminate: () => { this.#boxesMap.unobserveDeep(eventHandler); } };
96
+ this.#boxes.observeDeep(eventHandler);
97
+ return { terminate: () => { this.#boxes.unobserveDeep(eventHandler); } };
99
98
  }
100
99
  #createBox(key) {
101
- const map = this.#boxesMap.get(key);
100
+ const map = this.#boxes.get(key);
102
101
  const name = map.get("name");
103
102
  const fields = map.get("fields");
104
103
  const uuid = UUID.parse(key);
@@ -119,7 +118,7 @@ export class YSync {
119
118
  }
120
119
  const vertex = vertexOption.unwrap("Could not find field");
121
120
  const [uuidAsString, fieldsKey, ...fieldKeys] = path;
122
- const targetMap = YMapper.findMap(this.#boxesMap
121
+ const targetMap = YMapper.findMap(this.#boxes
123
122
  .get(String(uuidAsString))
124
123
  .get(String(fieldsKey)), fieldKeys);
125
124
  assert(vertex.isField(), "Vertex must be either Primitive or Pointer");
@@ -146,7 +145,8 @@ export class YSync {
146
145
  }
147
146
  #rollbackTransaction(events) {
148
147
  console.debug(`rollback ${events.length} events...`);
149
- this.#doc.transact(() => {
148
+ this.#getDoc()
149
+ .transact(() => {
150
150
  for (let i = events.length - 1; i >= 0; i--) {
151
151
  const event = events[i];
152
152
  const target = asInstanceOf(event.target, Y.Map);
@@ -180,7 +180,7 @@ export class YSync {
180
180
  this.#updates.length = 0;
181
181
  return;
182
182
  }
183
- this.#doc.transact(() => this.#updates.forEach(update => {
183
+ this.#getDoc().transact(() => this.#updates.forEach(update => {
184
184
  /**
185
185
  * TRANSFER CHANGES FROM OPENDAW TO YJS
186
186
  */
@@ -188,11 +188,11 @@ export class YSync {
188
188
  const uuid = update.uuid;
189
189
  const key = UUID.toString(uuid);
190
190
  const box = this.#boxGraph.findBox(uuid).unwrap();
191
- this.#boxesMap.set(key, YMapper.createBoxMap(box));
191
+ this.#boxes.set(key, YMapper.createBoxMap(box));
192
192
  }
193
193
  else if (update.type === "primitive") {
194
194
  const key = UUID.toString(update.address.uuid);
195
- const boxObject = asDefined(this.#boxesMap.get(key), "Could not find box");
195
+ const boxObject = asDefined(this.#boxes.get(key), "Could not find box");
196
196
  const { address: { fieldKeys }, newValue } = update;
197
197
  let field = boxObject.get("fields");
198
198
  for (let i = 0; i < fieldKeys.length - 1; i++) {
@@ -202,7 +202,7 @@ export class YSync {
202
202
  }
203
203
  else if (update.type === "pointer") {
204
204
  const key = UUID.toString(update.address.uuid);
205
- const boxObject = asDefined(this.#boxesMap.get(key), "Could not find box");
205
+ const boxObject = asDefined(this.#boxes.get(key), "Could not find box");
206
206
  const { address: { fieldKeys }, newAddress } = update;
207
207
  let field = boxObject.get("fields");
208
208
  for (let i = 0; i < fieldKeys.length - 1; i++) {
@@ -211,7 +211,7 @@ export class YSync {
211
211
  field.set(String(fieldKeys[fieldKeys.length - 1]), newAddress.mapOr(address => address.toString(), null));
212
212
  }
213
213
  else if (update.type === "delete") {
214
- this.#boxesMap.delete(UUID.toString(update.uuid));
214
+ this.#boxes.delete(UUID.toString(update.uuid));
215
215
  }
216
216
  }), "[openDAW] updates");
217
217
  this.#updates.length = 0;
@@ -220,4 +220,7 @@ export class YSync {
220
220
  onUpdate: (update) => this.#updates.push(update)
221
221
  }));
222
222
  }
223
+ #getDoc() {
224
+ return asDefined(this.#boxes.doc, "Y.Map is not connect to Y.Doc");
225
+ }
223
226
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opendaw/studio-core",
3
- "version": "0.0.45",
3
+ "version": "0.0.46",
4
4
  "license": "LGPL-3.0-or-later",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -26,16 +26,16 @@
26
26
  "test": "vitest run --config vitest.config.ts"
27
27
  },
28
28
  "dependencies": {
29
- "@opendaw/lib-box": "^0.0.36",
30
- "@opendaw/lib-dawproject": "^0.0.22",
31
- "@opendaw/lib-dom": "^0.0.36",
32
- "@opendaw/lib-dsp": "^0.0.36",
33
- "@opendaw/lib-fusion": "^0.0.36",
34
- "@opendaw/lib-runtime": "^0.0.36",
35
- "@opendaw/lib-std": "^0.0.36",
36
- "@opendaw/studio-adapters": "^0.0.37",
37
- "@opendaw/studio-boxes": "^0.0.36",
38
- "@opendaw/studio-enums": "^0.0.27",
29
+ "@opendaw/lib-box": "^0.0.37",
30
+ "@opendaw/lib-dawproject": "^0.0.23",
31
+ "@opendaw/lib-dom": "^0.0.37",
32
+ "@opendaw/lib-dsp": "^0.0.37",
33
+ "@opendaw/lib-fusion": "^0.0.37",
34
+ "@opendaw/lib-runtime": "^0.0.37",
35
+ "@opendaw/lib-std": "^0.0.37",
36
+ "@opendaw/studio-adapters": "^0.0.38",
37
+ "@opendaw/studio-boxes": "^0.0.37",
38
+ "@opendaw/studio-enums": "^0.0.28",
39
39
  "dropbox": "^10.34.0",
40
40
  "y-websocket": "^1.4.5",
41
41
  "yjs": "^13.6.27",
@@ -43,10 +43,10 @@
43
43
  },
44
44
  "devDependencies": {
45
45
  "@opendaw/eslint-config": "^0.0.20",
46
- "@opendaw/studio-core-processors": "^0.0.37",
47
- "@opendaw/studio-core-workers": "^0.0.32",
48
- "@opendaw/studio-forge-boxes": "^0.0.36",
46
+ "@opendaw/studio-core-processors": "^0.0.38",
47
+ "@opendaw/studio-core-workers": "^0.0.33",
48
+ "@opendaw/studio-forge-boxes": "^0.0.37",
49
49
  "@opendaw/typescript-config": "^0.0.20"
50
50
  },
51
- "gitHead": "a3c95d33522ce3b35c1a67af0fd6064488d35c97"
51
+ "gitHead": "cbe2d3409a066196db3434a48f61320f29c80d99"
52
52
  }