@audiotool/nexus 0.0.9 → 0.0.11

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 (37) hide show
  1. package/dist/api.js +2 -2
  2. package/dist/{audiotool-api-o8DnCQiu.js → audiotool-api-D9u-oGp3.js} +191 -184
  3. package/dist/audiotool-client.d.ts +0 -12
  4. package/dist/document/backend/create-wasm-document-state.d.ts +11 -0
  5. package/dist/document/backend/document-service/connection/index.d.ts +37 -0
  6. package/dist/document/backend/document-service/connection/ping-notifier.d.ts +20 -0
  7. package/dist/document/backend/document-service/connection/transaction-receiver.d.ts +26 -0
  8. package/dist/document/backend/document-service/connection/transaction-receiver.test.d.ts +1 -0
  9. package/dist/document/backend/document-service/connection/transaction-sender.d.ts +17 -0
  10. package/dist/document/backend/document-service/connection/transaction-sender.test.d.ts +1 -0
  11. package/dist/document/backend/document-service/gateway.d.ts +19 -33
  12. package/dist/document/backend/gateway.d.ts +12 -1
  13. package/dist/document/backend/validator.d.ts +2 -0
  14. package/dist/document/document.d.ts +9 -1
  15. package/dist/document/event-manager.d.ts +5 -0
  16. package/dist/document/mock/mock-document-state.d.ts +1 -0
  17. package/dist/document.js +1 -1
  18. package/dist/exports/index.d.ts +2 -0
  19. package/dist/{get-schema-location-details-D2lXBgbu.js → get-schema-location-details-CI3Fi5PK.js} +1 -1
  20. package/dist/{observable-notifier-value-pw47I_2-.js → hash-map-CMrPM1s6.js} +87 -88
  21. package/dist/index.js +1081 -1015
  22. package/dist/lang-K-8hAzE4.js +40 -0
  23. package/dist/login-status.d.ts +1 -2
  24. package/dist/synced-document.d.ts +45 -4
  25. package/dist/utils/combine-notifiers.d.ts +1 -1
  26. package/dist/utils/grpc/retrying-client.d.ts +2 -0
  27. package/dist/utils/lang.d.ts +17 -8
  28. package/dist/utils.js +3 -3
  29. package/package.json +1 -1
  30. package/dist/document/backend/document-service/wrapper/buffered-sender.d.ts +0 -29
  31. package/dist/document/backend/document-service/wrapper/create-ping-loop.d.ts +0 -8
  32. package/dist/document/backend/document-service/wrapper/create-receive-next-transaction-fn.d.ts +0 -15
  33. package/dist/document/backend/document-service/wrapper/wrapper.d.ts +0 -41
  34. package/dist/document/init-collab-gateway.d.ts +0 -6
  35. package/dist/lang-BqPY1uAS.js +0 -22
  36. /package/dist/{document/backend/document-service/wrapper/buffered-sender.test.d.ts → audiotool-client.test.d.ts} +0 -0
  37. /package/dist/document/backend/document-service/{wrapper/wrapper.test.d.ts → connection/ping-notifier.test.d.ts} +0 -0
package/dist/index.js CHANGED
@@ -1,20 +1,20 @@
1
- var Zt = Object.defineProperty;
2
- var Qt = (i) => {
1
+ var Wt = Object.defineProperty;
2
+ var jt = (i) => {
3
3
  throw TypeError(i);
4
4
  };
5
- var _t = (i, e, t) => e in i ? Zt(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
6
- var r = (i, e, t) => _t(i, typeof e != "symbol" ? e + "" : e, t), Wt = (i, e, t) => e.has(i) || Qt("Cannot " + t);
7
- var s = (i, e, t) => (Wt(i, e, "read from private field"), t ? t.call(i) : e.get(i)), p = (i, e, t) => e.has(i) ? Qt("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(i) : e.set(i, t), h = (i, e, t, n) => (Wt(i, e, "write to private field"), n ? n.call(i, t) : e.set(i, t), t), g = (i, e, t) => (Wt(i, e, "access private method"), t);
8
- import { aS as entityMessageToTypeKey, aT as mustUnpackEntity, aU as packEntity, aV as getEntityTypeKeyFromProtoName, aW as unpackEntity, aX as Preset, aY as anyEntityToTypeKey, aZ as createRetryingPromiseClient, a_ as createAuthorizedKeepaliveTransport, aR as createAudiotoolAPI, a$ as extractUuid, n as neverThrowingFetch } from "./audiotool-api-o8DnCQiu.js";
9
- import { Message, proto3, Any, protoInt64, ScalarType, MethodKind } from "@bufbuild/protobuf";
5
+ var Gt = (i, e, t) => e in i ? Wt(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
6
+ var a = (i, e, t) => Gt(i, typeof e != "symbol" ? e + "" : e, t), At = (i, e, t) => e.has(i) || jt("Cannot " + t);
7
+ var s = (i, e, t) => (At(i, e, "read from private field"), t ? t.call(i) : e.get(i)), h = (i, e, t) => e.has(i) ? jt("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(i) : e.set(i, t), g = (i, e, t, n) => (At(i, e, "write to private field"), n ? n.call(i, t) : e.set(i, t), t), y = (i, e, t) => (At(i, e, "access private method"), t);
8
+ import { aS as entityMessageToTypeKey, aT as mustUnpackEntity, aU as packEntity, aV as getEntityTypeKeyFromProtoName, aW as unpackEntity, aX as Preset, aY as anyEntityToTypeKey, aZ as createRetryingPromiseClient, a_ as createAuthorizedKeepaliveTransport, aR as createAudiotoolAPI, a$ as extractUuid, n as neverThrowingFetch } from "./audiotool-api-D9u-oGp3.js";
9
+ import { Message, proto3, protoInt64, Any, ScalarType, MethodKind } from "@bufbuild/protobuf";
10
10
  import { P as Pointer, E as Empty, e as entityMessageTypes } from "./types-Cztu157p.js";
11
- import { t as throw_, a as assert, b as asyncInterval, s as sleep } from "./lang-BqPY1uAS.js";
12
- import { h as hashSymbol, H as HashMap, V as ValueNotifier, N as Notifier, A as AsyncLock } from "./observable-notifier-value-pw47I_2-.js";
11
+ import { t as throw_, a as assert, b as asyncInterval, s as sleep } from "./lang-K-8hAzE4.js";
12
+ import { V as ValueNotifier, N as Notifier, h as hashSymbol, H as HashMap, A as AsyncLock } from "./hash-map-CMrPM1s6.js";
13
+ import { ConnectError, Code } from "@connectrpc/connect";
13
14
  import { v5 } from "uuid";
14
- import { s as schemaLocationToSchemaPath, a as schemaPathToSchemaLocation, g as getSchemaLocationDetails, _ as _getSchemaLocatorDetails } from "./get-schema-location-details-D2lXBgbu.js";
15
+ import { s as schemaLocationToSchemaPath, a as schemaPathToSchemaLocation, g as getSchemaLocationDetails, _ as _getSchemaLocatorDetails } from "./get-schema-location-details-CI3Fi5PK.js";
15
16
  import toposort from "toposort";
16
- import { ConnectError, Code } from "@connectrpc/connect";
17
- const F = class F extends Message {
17
+ const L = class L extends Message {
18
18
  constructor(t) {
19
19
  super();
20
20
  /**
@@ -22,7 +22,7 @@ const F = class F extends Message {
22
22
  *
23
23
  * @generated from field: string project_name = 1;
24
24
  */
25
- r(this, "projectName", "");
25
+ a(this, "projectName", "");
26
26
  /**
27
27
  * The client_id is used to identify the client.
28
28
  *
@@ -30,23 +30,23 @@ const F = class F extends Message {
30
30
  *
31
31
  * @generated from field: string client_id = 2;
32
32
  */
33
- r(this, "clientId", "");
33
+ a(this, "clientId", "");
34
34
  proto3.util.initPartial(t, this);
35
35
  }
36
36
  static fromBinary(t, n) {
37
- return new F().fromBinary(t, n);
37
+ return new L().fromBinary(t, n);
38
38
  }
39
39
  static fromJson(t, n) {
40
- return new F().fromJson(t, n);
40
+ return new L().fromJson(t, n);
41
41
  }
42
42
  static fromJsonString(t, n) {
43
- return new F().fromJsonString(t, n);
43
+ return new L().fromJsonString(t, n);
44
44
  }
45
45
  static equals(t, n) {
46
- return proto3.util.equals(F, t, n);
46
+ return proto3.util.equals(L, t, n);
47
47
  }
48
48
  };
49
- r(F, "runtime", proto3), r(F, "typeName", "audiotool.document.v1.AttachMetadataRequest"), r(F, "fields", proto3.util.newFieldList(() => [
49
+ a(L, "runtime", proto3), a(L, "typeName", "audiotool.document.v1.AttachMetadataRequest"), a(L, "fields", proto3.util.newFieldList(() => [
50
50
  {
51
51
  no: 1,
52
52
  name: "project_name",
@@ -62,8 +62,8 @@ r(F, "runtime", proto3), r(F, "typeName", "audiotool.document.v1.AttachMetadataR
62
62
  /* ScalarType.STRING */
63
63
  }
64
64
  ]));
65
- let AttachMetadataRequest = F;
66
- const J = class J extends Message {
65
+ let AttachMetadataRequest = L;
66
+ const U = class U extends Message {
67
67
  constructor(t) {
68
68
  super();
69
69
  /**
@@ -71,36 +71,36 @@ const J = class J extends Message {
71
71
  *
72
72
  * @generated from field: string source_name = 1;
73
73
  */
74
- r(this, "sourceName", "");
74
+ a(this, "sourceName", "");
75
75
  /**
76
76
  * The client_id is used to identify the client. A user can have multiple clients as he could
77
77
  * have multiple devices or multiple tabs open.
78
78
  *
79
79
  * @generated from field: string client_id = 2;
80
80
  */
81
- r(this, "clientId", "");
81
+ a(this, "clientId", "");
82
82
  /**
83
83
  * The coordinates of the client can be blank.
84
84
  *
85
85
  * @generated from field: audiotool.document.v1.ClientCoordinates client_coordinates = 3;
86
86
  */
87
- r(this, "clientCoordinates");
87
+ a(this, "clientCoordinates");
88
88
  proto3.util.initPartial(t, this);
89
89
  }
90
90
  static fromBinary(t, n) {
91
- return new J().fromBinary(t, n);
91
+ return new U().fromBinary(t, n);
92
92
  }
93
93
  static fromJson(t, n) {
94
- return new J().fromJson(t, n);
94
+ return new U().fromJson(t, n);
95
95
  }
96
96
  static fromJsonString(t, n) {
97
- return new J().fromJsonString(t, n);
97
+ return new U().fromJsonString(t, n);
98
98
  }
99
99
  static equals(t, n) {
100
- return proto3.util.equals(J, t, n);
100
+ return proto3.util.equals(U, t, n);
101
101
  }
102
102
  };
103
- r(J, "runtime", proto3), r(J, "typeName", "audiotool.document.v1.AttachMetadataResponse"), r(J, "fields", proto3.util.newFieldList(() => [
103
+ a(U, "runtime", proto3), a(U, "typeName", "audiotool.document.v1.AttachMetadataResponse"), a(U, "fields", proto3.util.newFieldList(() => [
104
104
  {
105
105
  no: 1,
106
106
  name: "source_name",
@@ -117,8 +117,8 @@ r(J, "runtime", proto3), r(J, "typeName", "audiotool.document.v1.AttachMetadataR
117
117
  },
118
118
  { no: 3, name: "client_coordinates", kind: "message", T: ClientCoordinates }
119
119
  ]));
120
- let AttachMetadataResponse = J;
121
- const C = class C extends Message {
120
+ let AttachMetadataResponse = U;
121
+ const B = class B extends Message {
122
122
  constructor(t) {
123
123
  super();
124
124
  /**
@@ -126,7 +126,7 @@ const C = class C extends Message {
126
126
  *
127
127
  * @generated from field: string project_name = 1;
128
128
  */
129
- r(this, "projectName", "");
129
+ a(this, "projectName", "");
130
130
  /**
131
131
  * The client_id is used to identify the client.
132
132
  *
@@ -134,29 +134,29 @@ const C = class C extends Message {
134
134
  *
135
135
  * @generated from field: string client_id = 2;
136
136
  */
137
- r(this, "clientId", "");
137
+ a(this, "clientId", "");
138
138
  /**
139
139
  * The coordinates of the client can be blank.
140
140
  *
141
141
  * @generated from field: audiotool.document.v1.ClientCoordinates client_coordinates = 3;
142
142
  */
143
- r(this, "clientCoordinates");
143
+ a(this, "clientCoordinates");
144
144
  proto3.util.initPartial(t, this);
145
145
  }
146
146
  static fromBinary(t, n) {
147
- return new C().fromBinary(t, n);
147
+ return new B().fromBinary(t, n);
148
148
  }
149
149
  static fromJson(t, n) {
150
- return new C().fromJson(t, n);
150
+ return new B().fromJson(t, n);
151
151
  }
152
152
  static fromJsonString(t, n) {
153
- return new C().fromJsonString(t, n);
153
+ return new B().fromJsonString(t, n);
154
154
  }
155
155
  static equals(t, n) {
156
- return proto3.util.equals(C, t, n);
156
+ return proto3.util.equals(B, t, n);
157
157
  }
158
158
  };
159
- r(C, "runtime", proto3), r(C, "typeName", "audiotool.document.v1.PutMetadataRequest"), r(C, "fields", proto3.util.newFieldList(() => [
159
+ a(B, "runtime", proto3), a(B, "typeName", "audiotool.document.v1.PutMetadataRequest"), a(B, "fields", proto3.util.newFieldList(() => [
160
160
  {
161
161
  no: 1,
162
162
  name: "project_name",
@@ -173,27 +173,27 @@ r(C, "runtime", proto3), r(C, "typeName", "audiotool.document.v1.PutMetadataRequ
173
173
  },
174
174
  { no: 3, name: "client_coordinates", kind: "message", T: ClientCoordinates }
175
175
  ]));
176
- let PutMetadataRequest = C;
177
- const L = class L extends Message {
176
+ let PutMetadataRequest = B;
177
+ const C = class C extends Message {
178
178
  constructor(e) {
179
179
  super(), proto3.util.initPartial(e, this);
180
180
  }
181
181
  static fromBinary(e, t) {
182
- return new L().fromBinary(e, t);
182
+ return new C().fromBinary(e, t);
183
183
  }
184
184
  static fromJson(e, t) {
185
- return new L().fromJson(e, t);
185
+ return new C().fromJson(e, t);
186
186
  }
187
187
  static fromJsonString(e, t) {
188
- return new L().fromJsonString(e, t);
188
+ return new C().fromJsonString(e, t);
189
189
  }
190
190
  static equals(e, t) {
191
- return proto3.util.equals(L, e, t);
191
+ return proto3.util.equals(C, e, t);
192
192
  }
193
193
  };
194
- r(L, "runtime", proto3), r(L, "typeName", "audiotool.document.v1.PutMetadataResponse"), r(L, "fields", proto3.util.newFieldList(() => []));
195
- let PutMetadataResponse = L;
196
- const U = class U extends Message {
194
+ a(C, "runtime", proto3), a(C, "typeName", "audiotool.document.v1.PutMetadataResponse"), a(C, "fields", proto3.util.newFieldList(() => []));
195
+ let PutMetadataResponse = C;
196
+ const A = class A extends Message {
197
197
  constructor(t) {
198
198
  super();
199
199
  /**
@@ -201,13 +201,13 @@ const U = class U extends Message {
201
201
  *
202
202
  * @generated from field: double x = 1;
203
203
  */
204
- r(this, "x", 0);
204
+ a(this, "x", 0);
205
205
  /**
206
206
  * The y coordinate of the cursor.
207
207
  *
208
208
  * @generated from field: double y = 2;
209
209
  */
210
- r(this, "y", 0);
210
+ a(this, "y", 0);
211
211
  /**
212
212
  * The context is a client specific information like:
213
213
  * - timeline
@@ -223,47 +223,47 @@ const U = class U extends Message {
223
223
  *
224
224
  * @generated from field: string context = 3;
225
225
  */
226
- r(this, "context", "");
226
+ a(this, "context", "");
227
227
  /**
228
228
  * The height of the context - optional.
229
229
  *
230
230
  * @generated from field: double context_height = 4;
231
231
  */
232
- r(this, "contextHeight", 0);
232
+ a(this, "contextHeight", 0);
233
233
  /**
234
234
  * The width of the context - optional.
235
235
  *
236
236
  * @generated from field: double context_width = 5;
237
237
  */
238
- r(this, "contextWidth", 0);
238
+ a(this, "contextWidth", 0);
239
239
  /**
240
240
  * The x display value of the context - optional.
241
241
  *
242
242
  * @generated from field: double context_x = 6;
243
243
  */
244
- r(this, "contextX", 0);
244
+ a(this, "contextX", 0);
245
245
  /**
246
246
  * The y display value of the context - optional.
247
247
  *
248
248
  * @generated from field: double context_y = 7;
249
249
  */
250
- r(this, "contextY", 0);
250
+ a(this, "contextY", 0);
251
251
  proto3.util.initPartial(t, this);
252
252
  }
253
253
  static fromBinary(t, n) {
254
- return new U().fromBinary(t, n);
254
+ return new A().fromBinary(t, n);
255
255
  }
256
256
  static fromJson(t, n) {
257
- return new U().fromJson(t, n);
257
+ return new A().fromJson(t, n);
258
258
  }
259
259
  static fromJsonString(t, n) {
260
- return new U().fromJsonString(t, n);
260
+ return new A().fromJsonString(t, n);
261
261
  }
262
262
  static equals(t, n) {
263
- return proto3.util.equals(U, t, n);
263
+ return proto3.util.equals(A, t, n);
264
264
  }
265
265
  };
266
- r(U, "runtime", proto3), r(U, "typeName", "audiotool.document.v1.ClientCoordinates"), r(U, "fields", proto3.util.newFieldList(() => [
266
+ a(A, "runtime", proto3), a(A, "typeName", "audiotool.document.v1.ClientCoordinates"), a(A, "fields", proto3.util.newFieldList(() => [
267
267
  {
268
268
  no: 1,
269
269
  name: "x",
@@ -314,8 +314,8 @@ r(U, "runtime", proto3), r(U, "typeName", "audiotool.document.v1.ClientCoordinat
314
314
  /* ScalarType.DOUBLE */
315
315
  }
316
316
  ]));
317
- let ClientCoordinates = U;
318
- const B = class B extends Message {
317
+ let ClientCoordinates = A;
318
+ const D = class D extends Message {
319
319
  constructor(t) {
320
320
  super();
321
321
  /**
@@ -323,29 +323,29 @@ const B = class B extends Message {
323
323
  *
324
324
  * @generated from field: string project_name = 1;
325
325
  */
326
- r(this, "projectName", "");
326
+ a(this, "projectName", "");
327
327
  /**
328
328
  * The filter is used to filter the entities.
329
329
  *
330
330
  * @generated from field: string filter = 2;
331
331
  */
332
- r(this, "filter", "");
332
+ a(this, "filter", "");
333
333
  proto3.util.initPartial(t, this);
334
334
  }
335
335
  static fromBinary(t, n) {
336
- return new B().fromBinary(t, n);
336
+ return new D().fromBinary(t, n);
337
337
  }
338
338
  static fromJson(t, n) {
339
- return new B().fromJson(t, n);
339
+ return new D().fromJson(t, n);
340
340
  }
341
341
  static fromJsonString(t, n) {
342
- return new B().fromJsonString(t, n);
342
+ return new D().fromJsonString(t, n);
343
343
  }
344
344
  static equals(t, n) {
345
- return proto3.util.equals(B, t, n);
345
+ return proto3.util.equals(D, t, n);
346
346
  }
347
347
  };
348
- r(B, "runtime", proto3), r(B, "typeName", "audiotool.document.v1.GetEntitiesRequest"), r(B, "fields", proto3.util.newFieldList(() => [
348
+ a(D, "runtime", proto3), a(D, "typeName", "audiotool.document.v1.GetEntitiesRequest"), a(D, "fields", proto3.util.newFieldList(() => [
349
349
  {
350
350
  no: 1,
351
351
  name: "project_name",
@@ -361,8 +361,8 @@ r(B, "runtime", proto3), r(B, "typeName", "audiotool.document.v1.GetEntitiesRequ
361
361
  /* ScalarType.STRING */
362
362
  }
363
363
  ]));
364
- let GetEntitiesRequest = B;
365
- const A = class A extends Message {
364
+ let GetEntitiesRequest = D;
365
+ const q = class q extends Message {
366
366
  constructor(t) {
367
367
  super();
368
368
  /**
@@ -371,27 +371,27 @@ const A = class A extends Message {
371
371
  *
372
372
  * @generated from field: repeated google.protobuf.Any entities = 1;
373
373
  */
374
- r(this, "entities", []);
374
+ a(this, "entities", []);
375
375
  proto3.util.initPartial(t, this);
376
376
  }
377
377
  static fromBinary(t, n) {
378
- return new A().fromBinary(t, n);
378
+ return new q().fromBinary(t, n);
379
379
  }
380
380
  static fromJson(t, n) {
381
- return new A().fromJson(t, n);
381
+ return new q().fromJson(t, n);
382
382
  }
383
383
  static fromJsonString(t, n) {
384
- return new A().fromJsonString(t, n);
384
+ return new q().fromJsonString(t, n);
385
385
  }
386
386
  static equals(t, n) {
387
- return proto3.util.equals(A, t, n);
387
+ return proto3.util.equals(q, t, n);
388
388
  }
389
389
  };
390
- r(A, "runtime", proto3), r(A, "typeName", "audiotool.document.v1.GetEntitiesResponse"), r(A, "fields", proto3.util.newFieldList(() => [
390
+ a(q, "runtime", proto3), a(q, "typeName", "audiotool.document.v1.GetEntitiesResponse"), a(q, "fields", proto3.util.newFieldList(() => [
391
391
  { no: 1, name: "entities", kind: "message", T: Any, repeated: !0 }
392
392
  ]));
393
- let GetEntitiesResponse = A;
394
- const D = class D extends Message {
393
+ let GetEntitiesResponse = q;
394
+ const O = class O extends Message {
395
395
  constructor(t) {
396
396
  super();
397
397
  /**
@@ -399,7 +399,7 @@ const D = class D extends Message {
399
399
  *
400
400
  * @generated from field: string project_name = 1;
401
401
  */
402
- r(this, "projectName", "");
402
+ a(this, "projectName", "");
403
403
  /**
404
404
  * The commit_index which the client has last seen.
405
405
  *
@@ -416,23 +416,23 @@ const D = class D extends Message {
416
416
  *
417
417
  * @generated from field: uint32 commit_index = 2;
418
418
  */
419
- r(this, "commitIndex", 0);
419
+ a(this, "commitIndex", 0);
420
420
  proto3.util.initPartial(t, this);
421
421
  }
422
422
  static fromBinary(t, n) {
423
- return new D().fromBinary(t, n);
423
+ return new O().fromBinary(t, n);
424
424
  }
425
425
  static fromJson(t, n) {
426
- return new D().fromJson(t, n);
426
+ return new O().fromJson(t, n);
427
427
  }
428
428
  static fromJsonString(t, n) {
429
- return new D().fromJsonString(t, n);
429
+ return new O().fromJsonString(t, n);
430
430
  }
431
431
  static equals(t, n) {
432
- return proto3.util.equals(D, t, n);
432
+ return proto3.util.equals(O, t, n);
433
433
  }
434
434
  };
435
- r(D, "runtime", proto3), r(D, "typeName", "audiotool.document.v1.AttachRequest"), r(D, "fields", proto3.util.newFieldList(() => [
435
+ a(O, "runtime", proto3), a(O, "typeName", "audiotool.document.v1.AttachRequest"), a(O, "fields", proto3.util.newFieldList(() => [
436
436
  {
437
437
  no: 1,
438
438
  name: "project_name",
@@ -448,8 +448,8 @@ r(D, "runtime", proto3), r(D, "typeName", "audiotool.document.v1.AttachRequest")
448
448
  /* ScalarType.UINT32 */
449
449
  }
450
450
  ]));
451
- let AttachRequest = D;
452
- const O = class O extends Message {
451
+ let AttachRequest = O;
452
+ const R = class R extends Message {
453
453
  constructor(t) {
454
454
  super();
455
455
  /**
@@ -457,28 +457,28 @@ const O = class O extends Message {
457
457
  *
458
458
  * @generated from oneof audiotool.document.v1.AttachResponse.message
459
459
  */
460
- r(this, "message", { case: void 0 });
460
+ a(this, "message", { case: void 0 });
461
461
  proto3.util.initPartial(t, this);
462
462
  }
463
463
  static fromBinary(t, n) {
464
- return new O().fromBinary(t, n);
464
+ return new R().fromBinary(t, n);
465
465
  }
466
466
  static fromJson(t, n) {
467
- return new O().fromJson(t, n);
467
+ return new R().fromJson(t, n);
468
468
  }
469
469
  static fromJsonString(t, n) {
470
- return new O().fromJsonString(t, n);
470
+ return new R().fromJsonString(t, n);
471
471
  }
472
472
  static equals(t, n) {
473
- return proto3.util.equals(O, t, n);
473
+ return proto3.util.equals(R, t, n);
474
474
  }
475
475
  };
476
- r(O, "runtime", proto3), r(O, "typeName", "audiotool.document.v1.AttachResponse"), r(O, "fields", proto3.util.newFieldList(() => [
476
+ a(R, "runtime", proto3), a(R, "typeName", "audiotool.document.v1.AttachResponse"), a(R, "fields", proto3.util.newFieldList(() => [
477
477
  { no: 1, name: "transaction", kind: "message", T: Transaction, oneof: "message" },
478
478
  { no: 2, name: "noop", kind: "message", T: Noop, oneof: "message" }
479
479
  ]));
480
- let AttachResponse = O;
481
- const q = class q extends Message {
480
+ let AttachResponse = R;
481
+ const j = class j extends Message {
482
482
  constructor(t) {
483
483
  super();
484
484
  /**
@@ -486,23 +486,23 @@ const q = class q extends Message {
486
486
  *
487
487
  * @generated from field: uint32 server_commit_index = 1;
488
488
  */
489
- r(this, "serverCommitIndex", 0);
489
+ a(this, "serverCommitIndex", 0);
490
490
  proto3.util.initPartial(t, this);
491
491
  }
492
492
  static fromBinary(t, n) {
493
- return new q().fromBinary(t, n);
493
+ return new j().fromBinary(t, n);
494
494
  }
495
495
  static fromJson(t, n) {
496
- return new q().fromJson(t, n);
496
+ return new j().fromJson(t, n);
497
497
  }
498
498
  static fromJsonString(t, n) {
499
- return new q().fromJsonString(t, n);
499
+ return new j().fromJsonString(t, n);
500
500
  }
501
501
  static equals(t, n) {
502
- return proto3.util.equals(q, t, n);
502
+ return proto3.util.equals(j, t, n);
503
503
  }
504
504
  };
505
- r(q, "runtime", proto3), r(q, "typeName", "audiotool.document.v1.Noop"), r(q, "fields", proto3.util.newFieldList(() => [
505
+ a(j, "runtime", proto3), a(j, "typeName", "audiotool.document.v1.Noop"), a(j, "fields", proto3.util.newFieldList(() => [
506
506
  {
507
507
  no: 1,
508
508
  name: "server_commit_index",
@@ -511,8 +511,8 @@ r(q, "runtime", proto3), r(q, "typeName", "audiotool.document.v1.Noop"), r(q, "f
511
511
  /* ScalarType.UINT32 */
512
512
  }
513
513
  ]));
514
- let Noop = q;
515
- const j = class j extends Message {
514
+ let Noop = j;
515
+ const $ = class $ extends Message {
516
516
  constructor(t) {
517
517
  super();
518
518
  /**
@@ -521,28 +521,28 @@ const j = class j extends Message {
521
521
  *
522
522
  * @generated from oneof audiotool.document.v1.ModifyRequest.message
523
523
  */
524
- r(this, "message", { case: void 0 });
524
+ a(this, "message", { case: void 0 });
525
525
  proto3.util.initPartial(t, this);
526
526
  }
527
527
  static fromBinary(t, n) {
528
- return new j().fromBinary(t, n);
528
+ return new $().fromBinary(t, n);
529
529
  }
530
530
  static fromJson(t, n) {
531
- return new j().fromJson(t, n);
531
+ return new $().fromJson(t, n);
532
532
  }
533
533
  static fromJsonString(t, n) {
534
- return new j().fromJsonString(t, n);
534
+ return new $().fromJsonString(t, n);
535
535
  }
536
536
  static equals(t, n) {
537
- return proto3.util.equals(j, t, n);
537
+ return proto3.util.equals($, t, n);
538
538
  }
539
539
  };
540
- r(j, "runtime", proto3), r(j, "typeName", "audiotool.document.v1.ModifyRequest"), r(j, "fields", proto3.util.newFieldList(() => [
540
+ a($, "runtime", proto3), a($, "typeName", "audiotool.document.v1.ModifyRequest"), a($, "fields", proto3.util.newFieldList(() => [
541
541
  { no: 1, name: "project_name", kind: "scalar", T: 9, oneof: "message" },
542
542
  { no: 2, name: "transaction", kind: "message", T: Transaction, oneof: "message" }
543
543
  ]));
544
- let ModifyRequest = j;
545
- const R = class R extends Message {
544
+ let ModifyRequest = $;
545
+ const V = class V extends Message {
546
546
  constructor(t) {
547
547
  super();
548
548
  /**
@@ -551,23 +551,23 @@ const R = class R extends Message {
551
551
  *
552
552
  * @generated from field: string error = 1;
553
553
  */
554
- r(this, "error", "");
554
+ a(this, "error", "");
555
555
  proto3.util.initPartial(t, this);
556
556
  }
557
557
  static fromBinary(t, n) {
558
- return new R().fromBinary(t, n);
558
+ return new V().fromBinary(t, n);
559
559
  }
560
560
  static fromJson(t, n) {
561
- return new R().fromJson(t, n);
561
+ return new V().fromJson(t, n);
562
562
  }
563
563
  static fromJsonString(t, n) {
564
- return new R().fromJsonString(t, n);
564
+ return new V().fromJsonString(t, n);
565
565
  }
566
566
  static equals(t, n) {
567
- return proto3.util.equals(R, t, n);
567
+ return proto3.util.equals(V, t, n);
568
568
  }
569
569
  };
570
- r(R, "runtime", proto3), r(R, "typeName", "audiotool.document.v1.ModifyResponse"), r(R, "fields", proto3.util.newFieldList(() => [
570
+ a(V, "runtime", proto3), a(V, "typeName", "audiotool.document.v1.ModifyResponse"), a(V, "fields", proto3.util.newFieldList(() => [
571
571
  {
572
572
  no: 1,
573
573
  name: "error",
@@ -576,8 +576,8 @@ r(R, "runtime", proto3), r(R, "typeName", "audiotool.document.v1.ModifyResponse"
576
576
  /* ScalarType.STRING */
577
577
  }
578
578
  ]));
579
- let ModifyResponse = R;
580
- const $ = class $ extends Message {
579
+ let ModifyResponse = V;
580
+ const W = class W extends Message {
581
581
  constructor(t) {
582
582
  super();
583
583
  /**
@@ -585,29 +585,29 @@ const $ = class $ extends Message {
585
585
  *
586
586
  * @generated from field: string project_name = 1;
587
587
  */
588
- r(this, "projectName", "");
588
+ a(this, "projectName", "");
589
589
  /**
590
590
  * The transactions to apply to the document, in order.
591
591
  *
592
592
  * @generated from field: repeated audiotool.document.v1.Transaction transactions = 2;
593
593
  */
594
- r(this, "transactions", []);
594
+ a(this, "transactions", []);
595
595
  proto3.util.initPartial(t, this);
596
596
  }
597
597
  static fromBinary(t, n) {
598
- return new $().fromBinary(t, n);
598
+ return new W().fromBinary(t, n);
599
599
  }
600
600
  static fromJson(t, n) {
601
- return new $().fromJson(t, n);
601
+ return new W().fromJson(t, n);
602
602
  }
603
603
  static fromJsonString(t, n) {
604
- return new $().fromJsonString(t, n);
604
+ return new W().fromJsonString(t, n);
605
605
  }
606
606
  static equals(t, n) {
607
- return proto3.util.equals($, t, n);
607
+ return proto3.util.equals(W, t, n);
608
608
  }
609
609
  };
610
- r($, "runtime", proto3), r($, "typeName", "audiotool.document.v1.ApplyTransactionsRequest"), r($, "fields", proto3.util.newFieldList(() => [
610
+ a(W, "runtime", proto3), a(W, "typeName", "audiotool.document.v1.ApplyTransactionsRequest"), a(W, "fields", proto3.util.newFieldList(() => [
611
611
  {
612
612
  no: 1,
613
613
  name: "project_name",
@@ -617,8 +617,8 @@ r($, "runtime", proto3), r($, "typeName", "audiotool.document.v1.ApplyTransactio
617
617
  },
618
618
  { no: 2, name: "transactions", kind: "message", T: Transaction, repeated: !0 }
619
619
  ]));
620
- let ApplyTransactionsRequest = $;
621
- const V = class V extends Message {
620
+ let ApplyTransactionsRequest = W;
621
+ const G = class G extends Message {
622
622
  constructor(t) {
623
623
  super();
624
624
  /**
@@ -626,31 +626,31 @@ const V = class V extends Message {
626
626
  *
627
627
  * @generated from field: map<string, string> errors = 1;
628
628
  */
629
- r(this, "errors", {});
629
+ a(this, "errors", {});
630
630
  proto3.util.initPartial(t, this);
631
631
  }
632
632
  static fromBinary(t, n) {
633
- return new V().fromBinary(t, n);
633
+ return new G().fromBinary(t, n);
634
634
  }
635
635
  static fromJson(t, n) {
636
- return new V().fromJson(t, n);
636
+ return new G().fromJson(t, n);
637
637
  }
638
638
  static fromJsonString(t, n) {
639
- return new V().fromJsonString(t, n);
639
+ return new G().fromJsonString(t, n);
640
640
  }
641
641
  static equals(t, n) {
642
- return proto3.util.equals(V, t, n);
642
+ return proto3.util.equals(G, t, n);
643
643
  }
644
644
  };
645
- r(V, "runtime", proto3), r(V, "typeName", "audiotool.document.v1.ApplyTransactionsResponse"), r(V, "fields", proto3.util.newFieldList(() => [
645
+ a(G, "runtime", proto3), a(G, "typeName", "audiotool.document.v1.ApplyTransactionsResponse"), a(G, "fields", proto3.util.newFieldList(() => [
646
646
  { no: 1, name: "errors", kind: "map", K: 9, V: {
647
647
  kind: "scalar",
648
648
  T: 9
649
649
  /* ScalarType.STRING */
650
650
  } }
651
651
  ]));
652
- let ApplyTransactionsResponse = V;
653
- const W = class W extends Message {
652
+ let ApplyTransactionsResponse = G;
653
+ const z = class z extends Message {
654
654
  constructor(t) {
655
655
  super();
656
656
  /**
@@ -659,36 +659,36 @@ const W = class W extends Message {
659
659
  *
660
660
  * @generated from field: string id = 1;
661
661
  */
662
- r(this, "id", "");
662
+ a(this, "id", "");
663
663
  /**
664
664
  * An incremental number that is increased with each accepted transaction provided by the
665
665
  * document-service.
666
666
  *
667
667
  * @generated from field: uint32 commit_index = 2;
668
668
  */
669
- r(this, "commitIndex", 0);
669
+ a(this, "commitIndex", 0);
670
670
  /**
671
671
  * A list of modifications to the document. The order of the modifications is important.
672
672
  *
673
673
  * @generated from field: repeated audiotool.document.v1.Modification modifications = 3;
674
674
  */
675
- r(this, "modifications", []);
675
+ a(this, "modifications", []);
676
676
  proto3.util.initPartial(t, this);
677
677
  }
678
678
  static fromBinary(t, n) {
679
- return new W().fromBinary(t, n);
679
+ return new z().fromBinary(t, n);
680
680
  }
681
681
  static fromJson(t, n) {
682
- return new W().fromJson(t, n);
682
+ return new z().fromJson(t, n);
683
683
  }
684
684
  static fromJsonString(t, n) {
685
- return new W().fromJsonString(t, n);
685
+ return new z().fromJsonString(t, n);
686
686
  }
687
687
  static equals(t, n) {
688
- return proto3.util.equals(W, t, n);
688
+ return proto3.util.equals(z, t, n);
689
689
  }
690
690
  };
691
- r(W, "runtime", proto3), r(W, "typeName", "audiotool.document.v1.Transaction"), r(W, "fields", proto3.util.newFieldList(() => [
691
+ a(z, "runtime", proto3), a(z, "typeName", "audiotool.document.v1.Transaction"), a(z, "fields", proto3.util.newFieldList(() => [
692
692
  {
693
693
  no: 1,
694
694
  name: "id",
@@ -705,8 +705,8 @@ r(W, "runtime", proto3), r(W, "typeName", "audiotool.document.v1.Transaction"),
705
705
  },
706
706
  { no: 3, name: "modifications", kind: "message", T: Modification, repeated: !0 }
707
707
  ]));
708
- let Transaction = W;
709
- const G = class G extends Message {
708
+ let Transaction = z;
709
+ const K = class K extends Message {
710
710
  constructor(t) {
711
711
  super();
712
712
  /**
@@ -714,29 +714,29 @@ const G = class G extends Message {
714
714
  *
715
715
  * @generated from oneof audiotool.document.v1.Modification.modification
716
716
  */
717
- r(this, "modification", { case: void 0 });
717
+ a(this, "modification", { case: void 0 });
718
718
  proto3.util.initPartial(t, this);
719
719
  }
720
720
  static fromBinary(t, n) {
721
- return new G().fromBinary(t, n);
721
+ return new K().fromBinary(t, n);
722
722
  }
723
723
  static fromJson(t, n) {
724
- return new G().fromJson(t, n);
724
+ return new K().fromJson(t, n);
725
725
  }
726
726
  static fromJsonString(t, n) {
727
- return new G().fromJsonString(t, n);
727
+ return new K().fromJsonString(t, n);
728
728
  }
729
729
  static equals(t, n) {
730
- return proto3.util.equals(G, t, n);
730
+ return proto3.util.equals(K, t, n);
731
731
  }
732
732
  };
733
- r(G, "runtime", proto3), r(G, "typeName", "audiotool.document.v1.Modification"), r(G, "fields", proto3.util.newFieldList(() => [
733
+ a(K, "runtime", proto3), a(K, "typeName", "audiotool.document.v1.Modification"), a(K, "fields", proto3.util.newFieldList(() => [
734
734
  { no: 2, name: "create", kind: "message", T: Create, oneof: "modification" },
735
735
  { no: 3, name: "delete", kind: "message", T: Delete, oneof: "modification" },
736
736
  { no: 4, name: "update", kind: "message", T: Update, oneof: "modification" }
737
737
  ]));
738
- let Modification = G;
739
- const z = class z extends Message {
738
+ let Modification = K;
739
+ const H = class H extends Message {
740
740
  constructor(t) {
741
741
  super();
742
742
  /**
@@ -744,27 +744,27 @@ const z = class z extends Message {
744
744
  *
745
745
  * @generated from field: google.protobuf.Any entity = 1;
746
746
  */
747
- r(this, "entity");
747
+ a(this, "entity");
748
748
  proto3.util.initPartial(t, this);
749
749
  }
750
750
  static fromBinary(t, n) {
751
- return new z().fromBinary(t, n);
751
+ return new H().fromBinary(t, n);
752
752
  }
753
753
  static fromJson(t, n) {
754
- return new z().fromJson(t, n);
754
+ return new H().fromJson(t, n);
755
755
  }
756
756
  static fromJsonString(t, n) {
757
- return new z().fromJsonString(t, n);
757
+ return new H().fromJsonString(t, n);
758
758
  }
759
759
  static equals(t, n) {
760
- return proto3.util.equals(z, t, n);
760
+ return proto3.util.equals(H, t, n);
761
761
  }
762
762
  };
763
- r(z, "runtime", proto3), r(z, "typeName", "audiotool.document.v1.Create"), r(z, "fields", proto3.util.newFieldList(() => [
763
+ a(H, "runtime", proto3), a(H, "typeName", "audiotool.document.v1.Create"), a(H, "fields", proto3.util.newFieldList(() => [
764
764
  { no: 1, name: "entity", kind: "message", T: Any }
765
765
  ]));
766
- let Create = z;
767
- const K = class K extends Message {
766
+ let Create = H;
767
+ const Q = class Q extends Message {
768
768
  constructor(t) {
769
769
  super();
770
770
  /**
@@ -772,29 +772,29 @@ const K = class K extends Message {
772
772
  *
773
773
  * @generated from field: audiotool.document.v1.Pointer field = 1;
774
774
  */
775
- r(this, "field");
775
+ a(this, "field");
776
776
  /**
777
777
  * The poossible values for an update
778
778
  *
779
779
  * @generated from oneof audiotool.document.v1.Update.value
780
780
  */
781
- r(this, "value", { case: void 0 });
781
+ a(this, "value", { case: void 0 });
782
782
  proto3.util.initPartial(t, this);
783
783
  }
784
784
  static fromBinary(t, n) {
785
- return new K().fromBinary(t, n);
785
+ return new Q().fromBinary(t, n);
786
786
  }
787
787
  static fromJson(t, n) {
788
- return new K().fromJson(t, n);
788
+ return new Q().fromJson(t, n);
789
789
  }
790
790
  static fromJsonString(t, n) {
791
- return new K().fromJsonString(t, n);
791
+ return new Q().fromJsonString(t, n);
792
792
  }
793
793
  static equals(t, n) {
794
- return proto3.util.equals(K, t, n);
794
+ return proto3.util.equals(Q, t, n);
795
795
  }
796
796
  };
797
- r(K, "runtime", proto3), r(K, "typeName", "audiotool.document.v1.Update"), r(K, "fields", proto3.util.newFieldList(() => [
797
+ a(Q, "runtime", proto3), a(Q, "typeName", "audiotool.document.v1.Update"), a(Q, "fields", proto3.util.newFieldList(() => [
798
798
  { no: 1, name: "field", kind: "message", T: Pointer },
799
799
  { no: 2, name: "double", kind: "scalar", T: 1, oneof: "value" },
800
800
  { no: 3, name: "float", kind: "scalar", T: 2, oneof: "value" },
@@ -813,8 +813,8 @@ r(K, "runtime", proto3), r(K, "typeName", "audiotool.document.v1.Update"), r(K,
813
813
  { no: 16, name: "bytes", kind: "scalar", T: 12, oneof: "value" },
814
814
  { no: 17, name: "pointer", kind: "message", T: Pointer, oneof: "value" }
815
815
  ]));
816
- let Update = K;
817
- const H = class H extends Message {
816
+ let Update = Q;
817
+ const X = class X extends Message {
818
818
  constructor(t) {
819
819
  super();
820
820
  /**
@@ -822,23 +822,23 @@ const H = class H extends Message {
822
822
  *
823
823
  * @generated from field: string entity_id = 1;
824
824
  */
825
- r(this, "entityId", "");
825
+ a(this, "entityId", "");
826
826
  proto3.util.initPartial(t, this);
827
827
  }
828
828
  static fromBinary(t, n) {
829
- return new H().fromBinary(t, n);
829
+ return new X().fromBinary(t, n);
830
830
  }
831
831
  static fromJson(t, n) {
832
- return new H().fromJson(t, n);
832
+ return new X().fromJson(t, n);
833
833
  }
834
834
  static fromJsonString(t, n) {
835
- return new H().fromJsonString(t, n);
835
+ return new X().fromJsonString(t, n);
836
836
  }
837
837
  static equals(t, n) {
838
- return proto3.util.equals(H, t, n);
838
+ return proto3.util.equals(X, t, n);
839
839
  }
840
840
  };
841
- r(H, "runtime", proto3), r(H, "typeName", "audiotool.document.v1.Delete"), r(H, "fields", proto3.util.newFieldList(() => [
841
+ a(X, "runtime", proto3), a(X, "typeName", "audiotool.document.v1.Delete"), a(X, "fields", proto3.util.newFieldList(() => [
842
842
  {
843
843
  no: 1,
844
844
  name: "entity_id",
@@ -847,27 +847,27 @@ r(H, "runtime", proto3), r(H, "typeName", "audiotool.document.v1.Delete"), r(H,
847
847
  /* ScalarType.STRING */
848
848
  }
849
849
  ]));
850
- let Delete = H;
851
- const Q = class Q extends Message {
850
+ let Delete = X;
851
+ const Y = class Y extends Message {
852
852
  constructor(e) {
853
853
  super(), proto3.util.initPartial(e, this);
854
854
  }
855
855
  static fromBinary(e, t) {
856
- return new Q().fromBinary(e, t);
856
+ return new Y().fromBinary(e, t);
857
857
  }
858
858
  static fromJson(e, t) {
859
- return new Q().fromJson(e, t);
859
+ return new Y().fromJson(e, t);
860
860
  }
861
861
  static fromJsonString(e, t) {
862
- return new Q().fromJsonString(e, t);
862
+ return new Y().fromJsonString(e, t);
863
863
  }
864
864
  static equals(e, t) {
865
- return proto3.util.equals(Q, e, t);
865
+ return proto3.util.equals(Y, e, t);
866
866
  }
867
867
  };
868
- r(Q, "runtime", proto3), r(Q, "typeName", "audiotool.document.v1.GetWasmRequest"), r(Q, "fields", proto3.util.newFieldList(() => []));
869
- let GetWasmRequest = Q;
870
- const X = class X extends Message {
868
+ a(Y, "runtime", proto3), a(Y, "typeName", "audiotool.document.v1.GetWasmRequest"), a(Y, "fields", proto3.util.newFieldList(() => []));
869
+ let GetWasmRequest = Y;
870
+ const Z = class Z extends Message {
871
871
  constructor(t) {
872
872
  super();
873
873
  /**
@@ -875,23 +875,23 @@ const X = class X extends Message {
875
875
  *
876
876
  * @generated from field: bytes data = 1;
877
877
  */
878
- r(this, "data", new Uint8Array(0));
878
+ a(this, "data", new Uint8Array(0));
879
879
  proto3.util.initPartial(t, this);
880
880
  }
881
881
  static fromBinary(t, n) {
882
- return new X().fromBinary(t, n);
882
+ return new Z().fromBinary(t, n);
883
883
  }
884
884
  static fromJson(t, n) {
885
- return new X().fromJson(t, n);
885
+ return new Z().fromJson(t, n);
886
886
  }
887
887
  static fromJsonString(t, n) {
888
- return new X().fromJsonString(t, n);
888
+ return new Z().fromJsonString(t, n);
889
889
  }
890
890
  static equals(t, n) {
891
- return proto3.util.equals(X, t, n);
891
+ return proto3.util.equals(Z, t, n);
892
892
  }
893
893
  };
894
- r(X, "runtime", proto3), r(X, "typeName", "audiotool.document.v1.GetWasmResponse"), r(X, "fields", proto3.util.newFieldList(() => [
894
+ a(Z, "runtime", proto3), a(Z, "typeName", "audiotool.document.v1.GetWasmResponse"), a(Z, "fields", proto3.util.newFieldList(() => [
895
895
  {
896
896
  no: 1,
897
897
  name: "data",
@@ -900,27 +900,27 @@ r(X, "runtime", proto3), r(X, "typeName", "audiotool.document.v1.GetWasmResponse
900
900
  /* ScalarType.BYTES */
901
901
  }
902
902
  ]));
903
- let GetWasmResponse = X;
904
- const Y = class Y extends Message {
903
+ let GetWasmResponse = Z;
904
+ const _ = class _ extends Message {
905
905
  constructor(e) {
906
906
  super(), proto3.util.initPartial(e, this);
907
907
  }
908
908
  static fromBinary(e, t) {
909
- return new Y().fromBinary(e, t);
909
+ return new _().fromBinary(e, t);
910
910
  }
911
911
  static fromJson(e, t) {
912
- return new Y().fromJson(e, t);
912
+ return new _().fromJson(e, t);
913
913
  }
914
914
  static fromJsonString(e, t) {
915
- return new Y().fromJsonString(e, t);
915
+ return new _().fromJsonString(e, t);
916
916
  }
917
917
  static equals(e, t) {
918
- return proto3.util.equals(Y, e, t);
918
+ return proto3.util.equals(_, e, t);
919
919
  }
920
920
  };
921
- r(Y, "runtime", proto3), r(Y, "typeName", "audiotool.document.v1.GetWasmExecRequest"), r(Y, "fields", proto3.util.newFieldList(() => []));
922
- let GetWasmExecRequest = Y;
923
- const Z = class Z extends Message {
921
+ a(_, "runtime", proto3), a(_, "typeName", "audiotool.document.v1.GetWasmExecRequest"), a(_, "fields", proto3.util.newFieldList(() => []));
922
+ let GetWasmExecRequest = _;
923
+ const tt = class tt extends Message {
924
924
  constructor(t) {
925
925
  super();
926
926
  /**
@@ -928,23 +928,23 @@ const Z = class Z extends Message {
928
928
  *
929
929
  * @generated from field: string data = 1;
930
930
  */
931
- r(this, "data", "");
931
+ a(this, "data", "");
932
932
  proto3.util.initPartial(t, this);
933
933
  }
934
934
  static fromBinary(t, n) {
935
- return new Z().fromBinary(t, n);
935
+ return new tt().fromBinary(t, n);
936
936
  }
937
937
  static fromJson(t, n) {
938
- return new Z().fromJson(t, n);
938
+ return new tt().fromJson(t, n);
939
939
  }
940
940
  static fromJsonString(t, n) {
941
- return new Z().fromJsonString(t, n);
941
+ return new tt().fromJsonString(t, n);
942
942
  }
943
943
  static equals(t, n) {
944
- return proto3.util.equals(Z, t, n);
944
+ return proto3.util.equals(tt, t, n);
945
945
  }
946
946
  };
947
- r(Z, "runtime", proto3), r(Z, "typeName", "audiotool.document.v1.GetWasmExecResponse"), r(Z, "fields", proto3.util.newFieldList(() => [
947
+ a(tt, "runtime", proto3), a(tt, "typeName", "audiotool.document.v1.GetWasmExecResponse"), a(tt, "fields", proto3.util.newFieldList(() => [
948
948
  {
949
949
  no: 1,
950
950
  name: "data",
@@ -953,8 +953,8 @@ r(Z, "runtime", proto3), r(Z, "typeName", "audiotool.document.v1.GetWasmExecResp
953
953
  /* ScalarType.STRING */
954
954
  }
955
955
  ]));
956
- let GetWasmExecResponse = Z;
957
- const _ = class _ extends Message {
956
+ let GetWasmExecResponse = tt;
957
+ const et = class et extends Message {
958
958
  constructor(t) {
959
959
  super();
960
960
  /**
@@ -962,36 +962,36 @@ const _ = class _ extends Message {
962
962
  *
963
963
  * @generated from field: string project_name = 1;
964
964
  */
965
- r(this, "projectName", "");
965
+ a(this, "projectName", "");
966
966
  /**
967
967
  * The client id is used to identify the client.
968
968
  *
969
969
  * @generated from field: string client_id = 2;
970
970
  */
971
- r(this, "clientId", "");
971
+ a(this, "clientId", "");
972
972
  /**
973
973
  * The last ping duration in ms measured by the client.
974
974
  * if left empty, the server will not count the ping.
975
975
  *
976
976
  * @generated from field: uint32 last_ping_ms = 3;
977
977
  */
978
- r(this, "lastPingMs", 0);
978
+ a(this, "lastPingMs", 0);
979
979
  proto3.util.initPartial(t, this);
980
980
  }
981
981
  static fromBinary(t, n) {
982
- return new _().fromBinary(t, n);
982
+ return new et().fromBinary(t, n);
983
983
  }
984
984
  static fromJson(t, n) {
985
- return new _().fromJson(t, n);
985
+ return new et().fromJson(t, n);
986
986
  }
987
987
  static fromJsonString(t, n) {
988
- return new _().fromJsonString(t, n);
988
+ return new et().fromJsonString(t, n);
989
989
  }
990
990
  static equals(t, n) {
991
- return proto3.util.equals(_, t, n);
991
+ return proto3.util.equals(et, t, n);
992
992
  }
993
993
  };
994
- r(_, "runtime", proto3), r(_, "typeName", "audiotool.document.v1.PingRequest"), r(_, "fields", proto3.util.newFieldList(() => [
994
+ a(et, "runtime", proto3), a(et, "typeName", "audiotool.document.v1.PingRequest"), a(et, "fields", proto3.util.newFieldList(() => [
995
995
  {
996
996
  no: 1,
997
997
  name: "project_name",
@@ -1014,27 +1014,27 @@ r(_, "runtime", proto3), r(_, "typeName", "audiotool.document.v1.PingRequest"),
1014
1014
  /* ScalarType.UINT32 */
1015
1015
  }
1016
1016
  ]));
1017
- let PingRequest = _;
1018
- const tt = class tt extends Message {
1017
+ let PingRequest = et;
1018
+ const nt = class nt extends Message {
1019
1019
  constructor(e) {
1020
1020
  super(), proto3.util.initPartial(e, this);
1021
1021
  }
1022
1022
  static fromBinary(e, t) {
1023
- return new tt().fromBinary(e, t);
1023
+ return new nt().fromBinary(e, t);
1024
1024
  }
1025
1025
  static fromJson(e, t) {
1026
- return new tt().fromJson(e, t);
1026
+ return new nt().fromJson(e, t);
1027
1027
  }
1028
1028
  static fromJsonString(e, t) {
1029
- return new tt().fromJsonString(e, t);
1029
+ return new nt().fromJsonString(e, t);
1030
1030
  }
1031
1031
  static equals(e, t) {
1032
- return proto3.util.equals(tt, e, t);
1032
+ return proto3.util.equals(nt, e, t);
1033
1033
  }
1034
1034
  };
1035
- r(tt, "runtime", proto3), r(tt, "typeName", "audiotool.document.v1.PingResponse"), r(tt, "fields", proto3.util.newFieldList(() => []));
1036
- let PingResponse = tt;
1037
- const et = class et extends Message {
1035
+ a(nt, "runtime", proto3), a(nt, "typeName", "audiotool.document.v1.PingResponse"), a(nt, "fields", proto3.util.newFieldList(() => []));
1036
+ let PingResponse = nt;
1037
+ const it = class it extends Message {
1038
1038
  constructor(t) {
1039
1039
  super();
1040
1040
  /**
@@ -1042,23 +1042,23 @@ const et = class et extends Message {
1042
1042
  *
1043
1043
  * @generated from field: string project_name = 1;
1044
1044
  */
1045
- r(this, "projectName", "");
1045
+ a(this, "projectName", "");
1046
1046
  proto3.util.initPartial(t, this);
1047
1047
  }
1048
1048
  static fromBinary(t, n) {
1049
- return new et().fromBinary(t, n);
1049
+ return new it().fromBinary(t, n);
1050
1050
  }
1051
1051
  static fromJson(t, n) {
1052
- return new et().fromJson(t, n);
1052
+ return new it().fromJson(t, n);
1053
1053
  }
1054
1054
  static fromJsonString(t, n) {
1055
- return new et().fromJsonString(t, n);
1055
+ return new it().fromJsonString(t, n);
1056
1056
  }
1057
1057
  static equals(t, n) {
1058
- return proto3.util.equals(et, t, n);
1058
+ return proto3.util.equals(it, t, n);
1059
1059
  }
1060
1060
  };
1061
- r(et, "runtime", proto3), r(et, "typeName", "audiotool.document.v1.GetClientStatsRequest"), r(et, "fields", proto3.util.newFieldList(() => [
1061
+ a(it, "runtime", proto3), a(it, "typeName", "audiotool.document.v1.GetClientStatsRequest"), a(it, "fields", proto3.util.newFieldList(() => [
1062
1062
  {
1063
1063
  no: 1,
1064
1064
  name: "project_name",
@@ -1067,8 +1067,8 @@ r(et, "runtime", proto3), r(et, "typeName", "audiotool.document.v1.GetClientStat
1067
1067
  /* ScalarType.STRING */
1068
1068
  }
1069
1069
  ]));
1070
- let GetClientStatsRequest = et;
1071
- const nt = class nt extends Message {
1070
+ let GetClientStatsRequest = it;
1071
+ const ot = class ot extends Message {
1072
1072
  constructor(t) {
1073
1073
  super();
1074
1074
  /**
@@ -1076,27 +1076,27 @@ const nt = class nt extends Message {
1076
1076
  *
1077
1077
  * @generated from field: repeated audiotool.document.v1.ClientInfo client_info = 1;
1078
1078
  */
1079
- r(this, "clientInfo", []);
1079
+ a(this, "clientInfo", []);
1080
1080
  proto3.util.initPartial(t, this);
1081
1081
  }
1082
1082
  static fromBinary(t, n) {
1083
- return new nt().fromBinary(t, n);
1083
+ return new ot().fromBinary(t, n);
1084
1084
  }
1085
1085
  static fromJson(t, n) {
1086
- return new nt().fromJson(t, n);
1086
+ return new ot().fromJson(t, n);
1087
1087
  }
1088
1088
  static fromJsonString(t, n) {
1089
- return new nt().fromJsonString(t, n);
1089
+ return new ot().fromJsonString(t, n);
1090
1090
  }
1091
1091
  static equals(t, n) {
1092
- return proto3.util.equals(nt, t, n);
1092
+ return proto3.util.equals(ot, t, n);
1093
1093
  }
1094
1094
  };
1095
- r(nt, "runtime", proto3), r(nt, "typeName", "audiotool.document.v1.GetClientStatsResponse"), r(nt, "fields", proto3.util.newFieldList(() => [
1095
+ a(ot, "runtime", proto3), a(ot, "typeName", "audiotool.document.v1.GetClientStatsResponse"), a(ot, "fields", proto3.util.newFieldList(() => [
1096
1096
  { no: 1, name: "client_info", kind: "message", T: ClientInfo, repeated: !0 }
1097
1097
  ]));
1098
- let GetClientStatsResponse = nt;
1099
- const it = class it extends Message {
1098
+ let GetClientStatsResponse = ot;
1099
+ const rt = class rt extends Message {
1100
1100
  constructor(t) {
1101
1101
  super();
1102
1102
  /**
@@ -1104,42 +1104,42 @@ const it = class it extends Message {
1104
1104
  *
1105
1105
  * @generated from field: string id = 1;
1106
1106
  */
1107
- r(this, "id", "");
1107
+ a(this, "id", "");
1108
1108
  /**
1109
1109
  * the client's ping
1110
1110
  *
1111
1111
  * @generated from field: uint32 ping_ms = 2;
1112
1112
  */
1113
- r(this, "pingMs", 0);
1113
+ a(this, "pingMs", 0);
1114
1114
  /**
1115
1115
  * set if client is offline
1116
1116
  *
1117
1117
  * @generated from field: bool offline = 3;
1118
1118
  */
1119
- r(this, "offline", !1);
1119
+ a(this, "offline", !1);
1120
1120
  /**
1121
1121
  * The source name of the client. This can be a user name in the form of 'users/{id}' but is not
1122
1122
  * guaranteed to be a user.
1123
1123
  *
1124
1124
  * @generated from field: string source_name = 4;
1125
1125
  */
1126
- r(this, "sourceName", "");
1126
+ a(this, "sourceName", "");
1127
1127
  proto3.util.initPartial(t, this);
1128
1128
  }
1129
1129
  static fromBinary(t, n) {
1130
- return new it().fromBinary(t, n);
1130
+ return new rt().fromBinary(t, n);
1131
1131
  }
1132
1132
  static fromJson(t, n) {
1133
- return new it().fromJson(t, n);
1133
+ return new rt().fromJson(t, n);
1134
1134
  }
1135
1135
  static fromJsonString(t, n) {
1136
- return new it().fromJsonString(t, n);
1136
+ return new rt().fromJsonString(t, n);
1137
1137
  }
1138
1138
  static equals(t, n) {
1139
- return proto3.util.equals(it, t, n);
1139
+ return proto3.util.equals(rt, t, n);
1140
1140
  }
1141
1141
  };
1142
- r(it, "runtime", proto3), r(it, "typeName", "audiotool.document.v1.ClientInfo"), r(it, "fields", proto3.util.newFieldList(() => [
1142
+ a(rt, "runtime", proto3), a(rt, "typeName", "audiotool.document.v1.ClientInfo"), a(rt, "fields", proto3.util.newFieldList(() => [
1143
1143
  {
1144
1144
  no: 1,
1145
1145
  name: "id",
@@ -1169,27 +1169,27 @@ r(it, "runtime", proto3), r(it, "typeName", "audiotool.document.v1.ClientInfo"),
1169
1169
  /* ScalarType.STRING */
1170
1170
  }
1171
1171
  ]));
1172
- let ClientInfo = it;
1173
- const ot = class ot extends Message {
1172
+ let ClientInfo = rt;
1173
+ const at = class at extends Message {
1174
1174
  constructor(e) {
1175
1175
  super(), proto3.util.initPartial(e, this);
1176
1176
  }
1177
1177
  static fromBinary(e, t) {
1178
- return new ot().fromBinary(e, t);
1178
+ return new at().fromBinary(e, t);
1179
1179
  }
1180
1180
  static fromJson(e, t) {
1181
- return new ot().fromJson(e, t);
1181
+ return new at().fromJson(e, t);
1182
1182
  }
1183
1183
  static fromJsonString(e, t) {
1184
- return new ot().fromJsonString(e, t);
1184
+ return new at().fromJsonString(e, t);
1185
1185
  }
1186
1186
  static equals(e, t) {
1187
- return proto3.util.equals(ot, e, t);
1187
+ return proto3.util.equals(at, e, t);
1188
1188
  }
1189
1189
  };
1190
- r(ot, "runtime", proto3), r(ot, "typeName", "audiotool.document.v1.GetVersionRequest"), r(ot, "fields", proto3.util.newFieldList(() => []));
1191
- let GetVersionRequest = ot;
1192
- const rt = class rt extends Message {
1190
+ a(at, "runtime", proto3), a(at, "typeName", "audiotool.document.v1.GetVersionRequest"), a(at, "fields", proto3.util.newFieldList(() => []));
1191
+ let GetVersionRequest = at;
1192
+ const st = class st extends Message {
1193
1193
  constructor(t) {
1194
1194
  super();
1195
1195
  /**
@@ -1197,23 +1197,23 @@ const rt = class rt extends Message {
1197
1197
  *
1198
1198
  * @generated from field: string version = 1;
1199
1199
  */
1200
- r(this, "version", "");
1200
+ a(this, "version", "");
1201
1201
  proto3.util.initPartial(t, this);
1202
1202
  }
1203
1203
  static fromBinary(t, n) {
1204
- return new rt().fromBinary(t, n);
1204
+ return new st().fromBinary(t, n);
1205
1205
  }
1206
1206
  static fromJson(t, n) {
1207
- return new rt().fromJson(t, n);
1207
+ return new st().fromJson(t, n);
1208
1208
  }
1209
1209
  static fromJsonString(t, n) {
1210
- return new rt().fromJsonString(t, n);
1210
+ return new st().fromJsonString(t, n);
1211
1211
  }
1212
1212
  static equals(t, n) {
1213
- return proto3.util.equals(rt, t, n);
1213
+ return proto3.util.equals(st, t, n);
1214
1214
  }
1215
1215
  };
1216
- r(rt, "runtime", proto3), r(rt, "typeName", "audiotool.document.v1.GetVersionResponse"), r(rt, "fields", proto3.util.newFieldList(() => [
1216
+ a(st, "runtime", proto3), a(st, "typeName", "audiotool.document.v1.GetVersionResponse"), a(st, "fields", proto3.util.newFieldList(() => [
1217
1217
  {
1218
1218
  no: 1,
1219
1219
  name: "version",
@@ -1222,27 +1222,27 @@ r(rt, "runtime", proto3), r(rt, "typeName", "audiotool.document.v1.GetVersionRes
1222
1222
  /* ScalarType.STRING */
1223
1223
  }
1224
1224
  ]));
1225
- let GetVersionResponse = rt;
1226
- const at = class at extends Message {
1225
+ let GetVersionResponse = st;
1226
+ const ct = class ct extends Message {
1227
1227
  constructor(e) {
1228
1228
  super(), proto3.util.initPartial(e, this);
1229
1229
  }
1230
1230
  static fromBinary(e, t) {
1231
- return new at().fromBinary(e, t);
1231
+ return new ct().fromBinary(e, t);
1232
1232
  }
1233
1233
  static fromJson(e, t) {
1234
- return new at().fromJson(e, t);
1234
+ return new ct().fromJson(e, t);
1235
1235
  }
1236
1236
  static fromJsonString(e, t) {
1237
- return new at().fromJsonString(e, t);
1237
+ return new ct().fromJsonString(e, t);
1238
1238
  }
1239
1239
  static equals(e, t) {
1240
- return proto3.util.equals(at, e, t);
1240
+ return proto3.util.equals(ct, e, t);
1241
1241
  }
1242
1242
  };
1243
- r(at, "runtime", proto3), r(at, "typeName", "audiotool.document.v1.GetTimeRequest"), r(at, "fields", proto3.util.newFieldList(() => []));
1244
- let GetTimeRequest = at;
1245
- const st = class st extends Message {
1243
+ a(ct, "runtime", proto3), a(ct, "typeName", "audiotool.document.v1.GetTimeRequest"), a(ct, "fields", proto3.util.newFieldList(() => []));
1244
+ let GetTimeRequest = ct;
1245
+ const dt = class dt extends Message {
1246
1246
  constructor(t) {
1247
1247
  super();
1248
1248
  /**
@@ -1250,23 +1250,23 @@ const st = class st extends Message {
1250
1250
  *
1251
1251
  * @generated from field: int64 time = 1;
1252
1252
  */
1253
- r(this, "time", protoInt64.zero);
1253
+ a(this, "time", protoInt64.zero);
1254
1254
  proto3.util.initPartial(t, this);
1255
1255
  }
1256
1256
  static fromBinary(t, n) {
1257
- return new st().fromBinary(t, n);
1257
+ return new dt().fromBinary(t, n);
1258
1258
  }
1259
1259
  static fromJson(t, n) {
1260
- return new st().fromJson(t, n);
1260
+ return new dt().fromJson(t, n);
1261
1261
  }
1262
1262
  static fromJsonString(t, n) {
1263
- return new st().fromJsonString(t, n);
1263
+ return new dt().fromJsonString(t, n);
1264
1264
  }
1265
1265
  static equals(t, n) {
1266
- return proto3.util.equals(st, t, n);
1266
+ return proto3.util.equals(dt, t, n);
1267
1267
  }
1268
1268
  };
1269
- r(st, "runtime", proto3), r(st, "typeName", "audiotool.document.v1.GetTimeResponse"), r(st, "fields", proto3.util.newFieldList(() => [
1269
+ a(dt, "runtime", proto3), a(dt, "typeName", "audiotool.document.v1.GetTimeResponse"), a(dt, "fields", proto3.util.newFieldList(() => [
1270
1270
  {
1271
1271
  no: 1,
1272
1272
  name: "time",
@@ -1275,7 +1275,7 @@ r(st, "runtime", proto3), r(st, "typeName", "audiotool.document.v1.GetTimeRespon
1275
1275
  /* ScalarType.INT64 */
1276
1276
  }
1277
1277
  ]));
1278
- let GetTimeResponse = st;
1278
+ let GetTimeResponse = dt;
1279
1279
  const wasmUrl = "/document_validator.wasm", wasmJsUrl = "/wasm_exec.js", runningInNode = typeof process < "u";
1280
1280
  let wasmDocumentStateBuilderCache;
1281
1281
  const getWasmDocumentState = async () => {
@@ -1285,16 +1285,16 @@ const getWasmDocumentState = async () => {
1285
1285
  wasmDocumentStateBuilderCache = i;
1286
1286
  const t = executeWrapperJs(), n = loadWasm();
1287
1287
  await t;
1288
- const o = globalThis.Go ?? throw_("wasm wrapper initialization failed: Go not defined"), a = new o();
1288
+ const o = globalThis.Go ?? throw_("wasm wrapper initialization failed: Go not defined"), r = new o();
1289
1289
  try {
1290
1290
  await n;
1291
- const l = await WebAssembly.instantiate(
1291
+ const d = await WebAssembly.instantiate(
1292
1292
  await n,
1293
- a.importObject
1293
+ r.importObject
1294
1294
  );
1295
- a.run(l);
1296
- } catch (l) {
1297
- throw new Error("Failed to instantiate validator WASM", { cause: l });
1295
+ r.run(d);
1296
+ } catch (d) {
1297
+ throw new Error("Failed to instantiate validator WASM", { cause: d });
1298
1298
  }
1299
1299
  delete globalThis.Go;
1300
1300
  const c = (
@@ -1302,13 +1302,21 @@ const getWasmDocumentState = async () => {
1302
1302
  globalThis.createDocumentState ?? throw_("wasm initialization failed: createDocumentState not defined")
1303
1303
  );
1304
1304
  return delete globalThis.createDocumentState, e(() => {
1305
- const l = c();
1305
+ const d = c();
1306
+ let u = !1;
1306
1307
  return {
1307
- applyTransaction(u) {
1308
- const m = l.applyTransaction(u.toBinary());
1308
+ applyTransaction(f) {
1309
+ assert(
1310
+ !u,
1311
+ "tried applying a transaction after document state was terminated"
1312
+ );
1313
+ const m = d.applyTransaction(f.toBinary());
1309
1314
  return m instanceof Object && "error" in m ? m.error : new Transaction({
1310
- modifications: m.rollbacks.map((f) => Modification.fromBinary(f))
1315
+ modifications: m.rollbacks.map((p) => Modification.fromBinary(p))
1311
1316
  });
1317
+ },
1318
+ terminate() {
1319
+ u = !0, d.delete();
1312
1320
  }
1313
1321
  };
1314
1322
  }), (await i)();
@@ -1343,6 +1351,321 @@ const getWasmDocumentState = async () => {
1343
1351
  e.dirname(t.fileURLToPath(import.meta.url)),
1344
1352
  `.${wasmUrl}`
1345
1353
  ), WebAssembly.compile(new Uint8Array(i.readFileSync(n)));
1354
+ };
1355
+ var I, b;
1356
+ class NexusStateConsolidator {
1357
+ constructor(e) {
1358
+ /**
1359
+ * A copy of the document state, to validate that pending transactions can still be applied,
1360
+ * and drop them if not.
1361
+ */
1362
+ h(this, I);
1363
+ /**
1364
+ * Transactions not yet confirmed or rejected by the remote.
1365
+ *
1366
+ * This is list contains `[forward, backward]` transactions, where `forward` are always the last transactions
1367
+ * applied to {@link #state}, while backwards contains their respective reverse, so the state
1368
+ * before all transactions in {@link #pending} can be restored.
1369
+ */
1370
+ h(this, b, []);
1371
+ g(this, I, e);
1372
+ }
1373
+ /**
1374
+ * Consolidate the local and remote transaction history.
1375
+ *
1376
+ * @param newReceived Newly received transaction from the remote
1377
+ * @param newReceivedRejected Newly received transaction rejections from the remote. **must be a subset of previously created transactions**
1378
+ * @param newCreated Newly created transactions on the local document
1379
+ * @returns Transactions needed to sync local & remote, plus transactions created but not yet received
1380
+ */
1381
+ consolidate(e, t, n) {
1382
+ n.forEach((l) => {
1383
+ const d = s(this, I).applyTransaction(l);
1384
+ if (!(d instanceof Transaction))
1385
+ throw new Error(`Error applying reverse transaction: ${d}`);
1386
+ s(this, b).push([l, d]);
1387
+ });
1388
+ let o = e[0], r = s(this, b)[0];
1389
+ for (; o !== void 0 && r !== void 0 && o.id === r[0].id; )
1390
+ e.shift(), s(this, b).shift(), o = e[0], r = s(this, b)[0];
1391
+ if (e.length === 0) {
1392
+ if (t.size === 0)
1393
+ return [];
1394
+ const l = s(this, b).findIndex(
1395
+ ([m]) => t.has(m.id)
1396
+ );
1397
+ if (l === -1)
1398
+ throw new Error(
1399
+ "Invariant violation: expected to find rejected transaction in #pending, but didn't. This is a bug."
1400
+ );
1401
+ const d = s(this, b).splice(l), u = d.map(([, m]) => {
1402
+ if (!(s(this, I).applyTransaction(m) instanceof Transaction))
1403
+ throw new Error("error applying reversal of transaction");
1404
+ return m;
1405
+ }).reverse(), f = d.filter(([m]) => !t.has(m.id)).map(([m]) => {
1406
+ const p = s(this, I).applyTransaction(m);
1407
+ if (p instanceof Transaction)
1408
+ return [m, p];
1409
+ }).filter((m) => m !== void 0);
1410
+ return s(this, b).push(...f), [...u, ...f.map(([m]) => m)];
1411
+ }
1412
+ const c = s(this, b).map((l) => l[1].clone()).reverse();
1413
+ return c.forEach((l) => {
1414
+ const d = s(this, I).applyTransaction(l);
1415
+ if (!(d instanceof Transaction))
1416
+ throw new Error(`Error applying reverse transaction: ${d}`);
1417
+ }), e.forEach((l) => {
1418
+ const d = s(this, I).applyTransaction(l);
1419
+ if (!(d instanceof Transaction))
1420
+ throw new Error(`Error applying incoming transaction: ${d}`);
1421
+ }), g(this, b, s(this, b).filter(([l]) => {
1422
+ const d = t.has(l.id), u = e.some(
1423
+ (f) => f.id === l.id
1424
+ );
1425
+ return !d && !u;
1426
+ }).map(([l]) => {
1427
+ const d = s(this, I).applyTransaction(l);
1428
+ return d instanceof Transaction ? [l, d] : void 0;
1429
+ }).filter((l) => l !== void 0)), [
1430
+ ...c,
1431
+ ...e,
1432
+ ...s(this, b).map(([l]) => l)
1433
+ ];
1434
+ }
1435
+ }
1436
+ I = new WeakMap(), b = new WeakMap();
1437
+ const combinedValueNotifiersWithAnd = (...i) => {
1438
+ const e = new ValueNotifier(!0), t = () => e.setValue(i.every((n) => n.getValue()));
1439
+ return i.forEach((n) => n.subscribe(() => t())), t(), e;
1440
+ }, createPingNotifier = (i, e, t) => {
1441
+ const n = new Notifier(), o = new ValueNotifier(0), r = new ValueNotifier(!0);
1442
+ n.subscribe((l) => {
1443
+ r.setValue(l);
1444
+ });
1445
+ const c = asyncInterval(
1446
+ async (l) => {
1447
+ const d = Date.now(), u = await i.ping(
1448
+ {
1449
+ clientId: (t == null ? void 0 : t.clientId) ?? "undefined",
1450
+ projectName: e,
1451
+ // required by backend
1452
+ lastPingMs: Math.floor(o.getValue())
1453
+ },
1454
+ {
1455
+ onRetry: () => n.notify(!1),
1456
+ signal: l
1457
+ }
1458
+ );
1459
+ if (!l.aborted) {
1460
+ if (u instanceof Error)
1461
+ throw u;
1462
+ n.notify(!0), o.setValue(Date.now() - d);
1463
+ }
1464
+ },
1465
+ 1e3,
1466
+ { immediateTrigger: !0 }
1467
+ );
1468
+ return {
1469
+ pingCallResults: n,
1470
+ connectionOk: r,
1471
+ pingMs: o,
1472
+ terminate: () => {
1473
+ n.terminate(), c.terminate(), r.terminate(), o.terminate();
1474
+ }
1475
+ };
1476
+ }, createTransactionReceiver = (i, e, t) => {
1477
+ const n = new ValueNotifier(!0);
1478
+ let o = 0;
1479
+ const r = new AbortController();
1480
+ let c = new AbortController(), l = !1;
1481
+ const d = () => (c.abort(), c = new AbortController(), i.attach(
1482
+ { projectName: e, commitIndex: o },
1483
+ {
1484
+ signal: AbortSignal.any([
1485
+ c.signal,
1486
+ r.signal
1487
+ ])
1488
+ }
1489
+ )[Symbol.asyncIterator]());
1490
+ let u = d();
1491
+ const f = 1e3;
1492
+ return {
1493
+ nextTransactionIterator: async function* () {
1494
+ for (; ; )
1495
+ try {
1496
+ const { value: p, done: w } = await u.next();
1497
+ if (w ?? !1)
1498
+ throw new Error("document service attach stream closed");
1499
+ switch (n.setValue(!0), p.message.case) {
1500
+ case "noop": {
1501
+ if (!l) {
1502
+ l = !0, yield new Transaction({ id: crypto.randomUUID() });
1503
+ continue;
1504
+ }
1505
+ continue;
1506
+ }
1507
+ case "transaction": {
1508
+ o = p.message.value.commitIndex, l = !0, yield p.message.value;
1509
+ continue;
1510
+ }
1511
+ default:
1512
+ throw new Error(
1513
+ `received attach response with unknown message case: ${p.message.case}`
1514
+ );
1515
+ }
1516
+ } catch (p) {
1517
+ if (r.signal.aborted)
1518
+ return;
1519
+ if (!(p instanceof ConnectError))
1520
+ throw p;
1521
+ switch (p.code) {
1522
+ case Code.Canceled:
1523
+ // thrown if abort controller is aborted
1524
+ case Code.Aborted:
1525
+ case Code.Unavailable:
1526
+ case Code.Unknown: {
1527
+ if (n.setValue(!1), await sleep(
1528
+ f + Math.random() * f * 0.1,
1529
+ // pass in master abort controller for early termination
1530
+ r.signal
1531
+ ), r.signal.aborted)
1532
+ return;
1533
+ u = d();
1534
+ continue;
1535
+ }
1536
+ // else throw
1537
+ default:
1538
+ throw p.code === Code.OutOfRange ? new Error(
1539
+ "local document state too far in the past, must reload tab"
1540
+ ) : p;
1541
+ }
1542
+ }
1543
+ }(),
1544
+ terminate: () => r.abort(),
1545
+ reconnect: () => c.abort(),
1546
+ connectionOk: n
1547
+ };
1548
+ }, createTransactionSender = (i, e) => {
1549
+ const t = new ValueNotifier(!0), n = [], o = promiseBarrier();
1550
+ let r;
1551
+ return (async () => {
1552
+ for (; ; ) {
1553
+ const l = n.splice(0);
1554
+ if (l.length === 0) {
1555
+ if (r !== void 0) {
1556
+ r.resolve();
1557
+ return;
1558
+ }
1559
+ await o.wait;
1560
+ continue;
1561
+ }
1562
+ const d = await i.applyTransactions(
1563
+ {
1564
+ projectName: e,
1565
+ transactions: l.map(([u]) => u)
1566
+ },
1567
+ {
1568
+ callIsOk: t
1569
+ }
1570
+ // no signal passed: we want to send everything
1571
+ );
1572
+ if (d instanceof Error)
1573
+ throw new Error("error sending transaction", { cause: d });
1574
+ l.forEach(([u, f]) => {
1575
+ f(d.errors[u.id] ?? void 0);
1576
+ });
1577
+ }
1578
+ })(), {
1579
+ sendNextTransaction: async (l) => {
1580
+ if (r !== void 0)
1581
+ throw new Error("tried sending transaction after termination");
1582
+ const { promise: d, resolve: u } = Promise.withResolvers();
1583
+ return n.push([l, u]), o.signal(), d;
1584
+ },
1585
+ terminate: async () => {
1586
+ if (r !== void 0) {
1587
+ await r.promise;
1588
+ return;
1589
+ }
1590
+ r = Promise.withResolvers(), o.signal(), t.terminate(), await r.promise, n.length > 0 && console.error(
1591
+ "invariant violation: nextBatch not empty after termination; have:",
1592
+ n.length,
1593
+ "transactions left"
1594
+ );
1595
+ },
1596
+ connectionOk: t
1597
+ };
1598
+ }, promiseBarrier = () => {
1599
+ let { promise: i, resolve: e } = Promise.withResolvers();
1600
+ return {
1601
+ get wait() {
1602
+ return i;
1603
+ },
1604
+ signal: () => {
1605
+ e(), { promise: i, resolve: e } = Promise.withResolvers();
1606
+ }
1607
+ };
1608
+ }, createDocumentServiceConnection = (i, e, t) => {
1609
+ const n = createPingNotifier(i, e, {}), o = createTransactionReceiver(
1610
+ i,
1611
+ e
1612
+ ), r = createTransactionSender(
1613
+ i,
1614
+ e
1615
+ ), c = combinedValueNotifiersWithAnd(
1616
+ n.connectionOk,
1617
+ o.connectionOk,
1618
+ r.connectionOk
1619
+ );
1620
+ return n.pingCallResults.subscribe((l) => {
1621
+ l || o.reconnect();
1622
+ }), {
1623
+ receiveNextTransaction: o.nextTransactionIterator,
1624
+ sendNextTransaction: r.sendNextTransaction,
1625
+ pingMs: n.pingMs,
1626
+ connectionOk: c,
1627
+ terminate: async () => {
1628
+ n.terminate(), o.terminate(), await r.terminate(), c.terminate();
1629
+ }
1630
+ };
1631
+ }, createCollabGateway = (i, e, t, n) => {
1632
+ const o = new ValueNotifier(!1), r = createDocumentServiceConnection(
1633
+ i,
1634
+ t
1635
+ ), c = new NexusStateConsolidator(e), l = [], d = [], u = /* @__PURE__ */ new Set();
1636
+ (async () => {
1637
+ for await (const p of r.receiveNextTransaction)
1638
+ l.push(p);
1639
+ })(), r.connectionOk.subscribe((p) => {
1640
+ o.setValue(!p);
1641
+ });
1642
+ let m = !1;
1643
+ return {
1644
+ blocked: o,
1645
+ send: (p) => {
1646
+ if (m)
1647
+ throw new Error(
1648
+ "tried sending a transaction after gateway was terminated"
1649
+ );
1650
+ p = p.clone(), p.id = crypto.randomUUID(), d.push(p), r.sendNextTransaction(p).then((w) => {
1651
+ w !== void 0 && u.add(p.id);
1652
+ });
1653
+ },
1654
+ synchronize: () => {
1655
+ if (m)
1656
+ return [];
1657
+ l.length > 0;
1658
+ const p = c.consolidate(
1659
+ l,
1660
+ u,
1661
+ d
1662
+ );
1663
+ return l.length = 0, u.clear(), d.length = 0, p;
1664
+ },
1665
+ terminate: async () => {
1666
+ m = !0, await r.terminate(), l.length = 0, u.clear(), d.length = 0, o.terminate(), e.terminate();
1667
+ }
1668
+ };
1346
1669
  }, createWasmNexusValidator = async () => {
1347
1670
  const i = await getWasmDocumentState();
1348
1671
  return {
@@ -1352,16 +1675,19 @@ const getWasmDocumentState = async () => {
1352
1675
  );
1353
1676
  if (!(t instanceof Transaction))
1354
1677
  return t;
1678
+ },
1679
+ terminate: () => {
1680
+ i.terminate();
1355
1681
  }
1356
1682
  };
1357
1683
  };
1358
- var Pt;
1359
- const pt = class pt {
1684
+ var St;
1685
+ const ht = class ht {
1360
1686
  constructor(e = void 0, t = void 0, n = []) {
1361
- r(this, "entityId");
1362
- r(this, "fieldIndex");
1363
- r(this, "entityType");
1364
- p(this, Pt);
1687
+ a(this, "entityId");
1688
+ a(this, "fieldIndex");
1689
+ a(this, "entityType");
1690
+ h(this, St);
1365
1691
  if (this.entityId = e ?? "", this.fieldIndex = n, this.entityType = t, e !== void 0 && e !== "" && t === void 0)
1366
1692
  throw new Error("entity type is required if id is set");
1367
1693
  }
@@ -1377,14 +1703,14 @@ const pt = class pt {
1377
1703
  }
1378
1704
  /** @internal Returns a copy of this object with an appended field number. */
1379
1705
  withAppendedFieldNumber(e) {
1380
- return new pt(this.entityId, this.entityType, [
1706
+ return new ht(this.entityId, this.entityType, [
1381
1707
  ...this.fieldIndex,
1382
1708
  e
1383
1709
  ]);
1384
1710
  }
1385
1711
  /** @internal */
1386
1712
  withFieldIndex(e) {
1387
- return new pt(this.entityId, this.entityType, [...e]);
1713
+ return new ht(this.entityId, this.entityType, [...e]);
1388
1714
  }
1389
1715
  /** @internal */
1390
1716
  toPointerMessage() {
@@ -1394,7 +1720,7 @@ const pt = class pt {
1394
1720
  });
1395
1721
  }
1396
1722
  get [hashSymbol]() {
1397
- return s(this, Pt) === void 0 && h(this, Pt, hashNexusLocation(this.entityId, this.fieldIndex)), s(this, Pt);
1723
+ return s(this, St) === void 0 && g(this, St, hashNexusLocation(this.entityId, this.fieldIndex)), s(this, St);
1398
1724
  }
1399
1725
  /** Returns a human readable string representation */
1400
1726
  toString() {
@@ -1405,27 +1731,27 @@ const pt = class pt {
1405
1731
  }
1406
1732
  /** @internal clones the location, updating only the id */
1407
1733
  withId(e) {
1408
- return new pt(e, this.entityType, this.fieldIndex.slice());
1734
+ return new ht(e, this.entityType, this.fieldIndex.slice());
1409
1735
  }
1410
1736
  /** @internal */
1411
1737
  static fromPointerMessage(e, t) {
1412
1738
  if (t.entityId === void 0 || t.entityId === "")
1413
- return new pt();
1739
+ return new ht();
1414
1740
  const n = e(t.entityId);
1415
1741
  if (n === void 0)
1416
1742
  throw new Error(
1417
1743
  `entity type for ${t.entityId} is undefined for a set pointer: ${t.toJsonString()}`
1418
1744
  );
1419
- return new pt(t.entityId, n, t.fieldIndex.slice());
1745
+ return new ht(t.entityId, n, t.fieldIndex.slice());
1420
1746
  }
1421
1747
  /** @internal */
1422
1748
  static fromSchemaPath(e, t) {
1423
1749
  const { entityType: n, fieldIndex: o } = schemaPathToSchemaLocation(t);
1424
- return new pt(e, n, o);
1750
+ return new ht(e, n, o);
1425
1751
  }
1426
1752
  };
1427
- Pt = new WeakMap();
1428
- let NexusLocation = pt;
1753
+ St = new WeakMap();
1754
+ let NexusLocation = ht;
1429
1755
  const hashNexusLocation = (i, e) => v5(
1430
1756
  `${i}/${e.join(",")}`,
1431
1757
  "4f4aaf81-65f2-4239-b1df-e34a0729f6b8"
@@ -1471,49 +1797,49 @@ const hashNexusLocation = (i, e) => v5(
1471
1797
  class ArrayField {
1472
1798
  /** @internal */
1473
1799
  constructor(e, t) {
1474
- r(this, "location");
1800
+ a(this, "location");
1475
1801
  /** The array of fields contained in this array field. */
1476
- r(this, "array");
1802
+ a(this, "array");
1477
1803
  this.location = e, this.array = t;
1478
1804
  }
1479
1805
  }
1480
- var kt;
1806
+ var Et;
1481
1807
  class PrimitiveField {
1482
1808
  /** @internal */
1483
1809
  constructor(e, t, n, o) {
1484
1810
  /** The location of this field within the Nexus document. */
1485
- r(this, "location");
1811
+ a(this, "location");
1486
1812
  /** The value of the field; private with a getter to prevent accidenal overwrites. */
1487
- p(this, kt);
1813
+ h(this, Et);
1488
1814
  /** Whether the field is mutable. Updating immutable fields results in a transaction error.
1489
1815
  *
1490
1816
  * If the type fo the field is known at compile time, updating the field using the {@link TransactionBuilder}
1491
1817
  * or listing to updates of the field using the {@link NexusEventManager} will result in type errors.
1492
1818
  */
1493
- r(this, "mutable");
1819
+ a(this, "mutable");
1494
1820
  /** @internal The type of the field in the protobuf message. Used internally. */
1495
- r(this, "_protoType");
1496
- this.location = e, h(this, kt, t), this._protoType = n, this.mutable = o;
1821
+ a(this, "_protoType");
1822
+ this.location = e, g(this, Et, t), this._protoType = n, this.mutable = o;
1497
1823
  }
1498
1824
  /** Get the value of the field. To set, use transactions in the document. */
1499
1825
  get value() {
1500
- return s(this, kt);
1826
+ return s(this, Et);
1501
1827
  }
1502
1828
  /**
1503
1829
  * @internal
1504
1830
  *
1505
1831
  * Set the value of this field. Used by {@link NexusDocument}, don't use directly! */
1506
1832
  _setValue(e) {
1507
- h(this, kt, protoPrecision[this._protoType](e));
1833
+ g(this, Et, protoPrecision[this._protoType](e));
1508
1834
  }
1509
1835
  }
1510
- kt = new WeakMap();
1836
+ Et = new WeakMap();
1511
1837
  class NexusObject {
1512
1838
  /** @internal */
1513
1839
  constructor(e, t) {
1514
1840
  /** the fields in this object */
1515
- r(this, "fields");
1516
- r(this, "location");
1841
+ a(this, "fields");
1842
+ a(this, "location");
1517
1843
  this.location = t, this.fields = e;
1518
1844
  }
1519
1845
  /** @internal Returns the field with the given field number. Throws if it can't find it. */
@@ -1530,9 +1856,9 @@ class NexusEntity extends NexusObject {
1530
1856
  constructor(t, n) {
1531
1857
  super(n, t);
1532
1858
  /** The id of this entity. */
1533
- r(this, "id");
1859
+ a(this, "id");
1534
1860
  /** The entity type key of this entity. */
1535
- r(this, "entityType");
1861
+ a(this, "entityType");
1536
1862
  this.id = t.entityId, this.entityType = t.entityType;
1537
1863
  }
1538
1864
  /**
@@ -1544,49 +1870,49 @@ class NexusEntity extends NexusObject {
1544
1870
  if (t.length === 0)
1545
1871
  throw "tried resolving empty field path";
1546
1872
  const [n, ...o] = t;
1547
- let a = this._getField(n);
1873
+ let r = this._getField(n);
1548
1874
  for (const c of o) {
1549
- if (a instanceof NexusObject) {
1550
- a = a._getField(c);
1875
+ if (r instanceof NexusObject) {
1876
+ r = r._getField(c);
1551
1877
  continue;
1552
1878
  }
1553
- if (a instanceof ArrayField) {
1554
- a = a.array[c];
1879
+ if (r instanceof ArrayField) {
1880
+ r = r.array[c];
1555
1881
  continue;
1556
1882
  }
1557
- throw `tried resolving field number ${c} on non-object field ${a}`;
1883
+ throw `tried resolving field number ${c} on non-object field ${r}`;
1558
1884
  }
1559
- return a;
1885
+ return r;
1560
1886
  }
1561
1887
  }
1562
1888
  const createNexusFields = (i, e, t, n) => {
1563
1889
  const o = {};
1564
- return t.getType().fields.list().forEach((a) => {
1565
- if (a.name === "id" && a.no === 1)
1890
+ return t.getType().fields.list().forEach((r) => {
1891
+ if (r.name === "id" && r.no === 1)
1566
1892
  return;
1567
- const c = n.withAppendedFieldNumber(a.no), d = t[a.localName];
1568
- let l;
1569
- if (!a.repeated)
1570
- l = createField(
1893
+ const c = n.withAppendedFieldNumber(r.no), l = t[r.localName];
1894
+ let d;
1895
+ if (!r.repeated)
1896
+ d = createField(
1571
1897
  i,
1572
1898
  e,
1573
1899
  c,
1574
- d,
1575
- a
1900
+ l,
1901
+ r
1576
1902
  );
1577
1903
  else {
1578
- const u = d.map(
1579
- (m, f) => createField(
1904
+ const u = l.map(
1905
+ (f, m) => createField(
1580
1906
  i,
1581
1907
  e,
1582
- c.withAppendedFieldNumber(f),
1583
- m,
1584
- a
1908
+ c.withAppendedFieldNumber(m),
1909
+ f,
1910
+ r
1585
1911
  )
1586
1912
  );
1587
- l = new ArrayField(c, u);
1913
+ d = new ArrayField(c, u);
1588
1914
  }
1589
- o[a.localName] = l;
1915
+ o[r.localName] = d;
1590
1916
  }), o;
1591
1917
  }, createField = (i, e, t, n, o) => {
1592
1918
  switch (o.kind) {
@@ -1601,13 +1927,13 @@ const createNexusFields = (i, e, t, n) => {
1601
1927
  if (o.T === Empty)
1602
1928
  return new NexusObject({}, t);
1603
1929
  assert(n !== void 0, `undefined value for field ${t}`);
1604
- const a = createNexusFields(
1930
+ const r = createNexusFields(
1605
1931
  i,
1606
1932
  e,
1607
1933
  n,
1608
1934
  t
1609
1935
  );
1610
- return new NexusObject(a, t);
1936
+ return new NexusObject(r, t);
1611
1937
  }
1612
1938
  case "scalar":
1613
1939
  return new PrimitiveField(
@@ -1709,8 +2035,8 @@ const createNexusFields = (i, e, t, n) => {
1709
2035
  o._setValue(t);
1710
2036
  return;
1711
2037
  }
1712
- const a = o.value;
1713
- a.isEmpty() || n == null || n.onStopPointingTo(o.location, a), o._setValue(t);
2038
+ const r = o.value;
2039
+ r.isEmpty() || n == null || n.onStopPointingTo(o.location, r), o._setValue(t);
1714
2040
  const c = t;
1715
2041
  c.isEmpty() || n == null || n.onStartPointingTo(o.location, c);
1716
2042
  }, nexusDocumentState = (i) => {
@@ -1726,51 +2052,51 @@ const createNexusFields = (i, e, t, n) => {
1726
2052
  onUpdate: () => {
1727
2053
  },
1728
2054
  ...(i == null ? void 0 : i.callbacks) ?? {}
1729
- }, o = /* @__PURE__ */ new Map(), a = (u) => {
1730
- var m;
1731
- return ((m = e.get(u)) == null ? void 0 : m.entityType) ?? o.get(u);
2055
+ }, o = /* @__PURE__ */ new Map(), r = (u) => {
2056
+ var f;
2057
+ return ((f = e.get(u)) == null ? void 0 : f.entityType) ?? o.get(u);
1732
2058
  }, c = (u) => {
1733
- const m = createEntity(
1734
- a,
2059
+ const f = createEntity(
2060
+ r,
1735
2061
  mustUnpackEntity(
1736
2062
  u.entity ?? throw_("received empty create modification")
1737
2063
  )
1738
2064
  );
1739
- e.set(m.id, m), visitPointers$1(m, (f, y) => {
1740
- addSourceTarget(t, f, y), n.onStartPointingTo(f, y);
1741
- }), n.onCreate(m);
1742
- }, d = (u) => {
1743
- const m = u.entityId, f = e.get(m) ?? throw_("can't find deleted entity");
1744
- e.delete(m), visitPointers$1(f, (y, v) => {
1745
- removeSourceTarget(t, y, v), n.onStopPointingTo(y, v);
1746
- }), n.onDelete(f);
2065
+ e.set(f.id, f), visitPointers$1(f, (m, p) => {
2066
+ addSourceTarget(t, m, p), n.onStartPointingTo(m, p);
2067
+ }), n.onCreate(f);
1747
2068
  }, l = (u) => {
1748
- const m = u.field ?? throw_("received update without pointer"), f = NexusLocation.fromPointerMessage(a, m), y = e.get(f.entityId) ?? throw_("can't find updated entity"), v = extractPbUpdateValue(u.value, a);
1749
- applyUpdate(y, f, v, {
1750
- onStopPointingTo: (w, b) => {
1751
- removeSourceTarget(t, w, b) || throw_(), n.onStopPointingTo(w, b);
2069
+ const f = u.entityId, m = e.get(f) ?? throw_("can't find deleted entity");
2070
+ e.delete(f), visitPointers$1(m, (p, w) => {
2071
+ removeSourceTarget(t, p, w), n.onStopPointingTo(p, w);
2072
+ }), n.onDelete(m);
2073
+ }, d = (u) => {
2074
+ const f = u.field ?? throw_("received update without pointer"), m = NexusLocation.fromPointerMessage(r, f), p = e.get(m.entityId) ?? throw_("can't find updated entity"), w = extractPbUpdateValue(u.value, r);
2075
+ applyUpdate(p, m, w, {
2076
+ onStopPointingTo: (x, E) => {
2077
+ removeSourceTarget(t, x, E) || throw_(), n.onStopPointingTo(x, E);
1752
2078
  },
1753
- onStartPointingTo: (w, b) => {
1754
- addSourceTarget(t, w, b), n.onStartPointingTo(w, b);
2079
+ onStartPointingTo: (x, E) => {
2080
+ addSourceTarget(t, x, E), n.onStartPointingTo(x, E);
1755
2081
  }
1756
- }), n.onUpdate(f, v);
2082
+ }), n.onUpdate(m, w);
1757
2083
  };
1758
2084
  return {
1759
2085
  entities: e,
1760
2086
  references: t,
1761
2087
  applyModification(u) {
1762
- const m = u.modification;
1763
- switch (m.case) {
2088
+ const f = u.modification;
2089
+ switch (f.case) {
1764
2090
  case "create": {
1765
- c(m.value);
2091
+ c(f.value);
1766
2092
  break;
1767
2093
  }
1768
2094
  case "delete": {
1769
- d(m.value);
2095
+ l(f.value);
1770
2096
  break;
1771
2097
  }
1772
2098
  case "update": {
1773
- l(m.value);
2099
+ d(f.value);
1774
2100
  break;
1775
2101
  }
1776
2102
  }
@@ -1778,11 +2104,11 @@ const createNexusFields = (i, e, t, n) => {
1778
2104
  getStats() {
1779
2105
  return {
1780
2106
  entities: e.size,
1781
- references: t.values().reduce((u, m) => u + m.length, 0)
2107
+ references: t.values().reduce((u, f) => u + f.length, 0)
1782
2108
  };
1783
2109
  },
1784
- _addEntityTypeForId(u, m) {
1785
- o.set(u, m);
2110
+ _addEntityTypeForId(u, f) {
2111
+ o.set(u, f);
1786
2112
  }
1787
2113
  };
1788
2114
  }, TerminableBuilder = {
@@ -1793,17 +2119,17 @@ const createNexusFields = (i, e, t, n) => {
1793
2119
  }
1794
2120
  })
1795
2121
  };
1796
- var ct, ht, k, lt, dt, At;
1797
- const Et = class Et {
2122
+ var N, lt, k, F, J, Jt;
2123
+ const bt = class bt {
1798
2124
  constructor(e = nexusDocumentState()) {
1799
- p(this, ct, new HashMap());
1800
- p(this, ht, /* @__PURE__ */ new Map());
2125
+ h(this, N, new HashMap());
2126
+ h(this, lt, /* @__PURE__ */ new Map());
1801
2127
  /** contains either: entity id, *, or entity type */
1802
- p(this, k, /* @__PURE__ */ new Map());
1803
- p(this, lt, new HashMap());
1804
- p(this, dt, new HashMap());
1805
- p(this, At);
1806
- h(this, At, e), Et.debugWindowInstance ?? (Et.debugWindowInstance = this);
2128
+ h(this, k, /* @__PURE__ */ new Map());
2129
+ h(this, F, new HashMap());
2130
+ h(this, J, new HashMap());
2131
+ h(this, Jt);
2132
+ g(this, Jt, e), bt.debugWindowInstance ?? (bt.debugWindowInstance = this);
1807
2133
  }
1808
2134
  /**
1809
2135
  * Subscribe to the event that an entity of a specific type is created.
@@ -1812,24 +2138,24 @@ const Et = class Et {
1812
2138
  * during entity creation will still be called on removal of the entity.
1813
2139
  */
1814
2140
  onCreate(e, t) {
1815
- const n = (a) => {
2141
+ const n = (r) => {
1816
2142
  const c = t(
1817
- a
2143
+ r
1818
2144
  );
1819
- c !== void 0 && this.onRemove(a, c);
2145
+ c !== void 0 && this.onRemove(r, c);
1820
2146
  };
1821
- return getOrDefault(s(this, ht), e).add(n), TerminableBuilder.terminableFrom(
2147
+ return getOrDefault(s(this, lt), e).add(n), TerminableBuilder.terminableFrom(
1822
2148
  () => {
1823
- var a;
1824
- return (a = s(this, ht).get(e)) == null ? void 0 : a.delete(n);
2149
+ var r;
2150
+ return (r = s(this, lt).get(e)) == null ? void 0 : r.delete(n);
1825
2151
  }
1826
2152
  );
1827
2153
  }
1828
2154
  /** @internal */
1829
2155
  _dispatchCreate(e) {
1830
2156
  [
1831
- ...s(this, ht).get("*") ?? [],
1832
- ...s(this, ht).get(e.entityType) ?? []
2157
+ ...s(this, lt).get("*") ?? [],
2158
+ ...s(this, lt).get(e.entityType) ?? []
1833
2159
  ].forEach((t) => t(e));
1834
2160
  }
1835
2161
  /**
@@ -1839,17 +2165,17 @@ const Et = class Et {
1839
2165
  */
1840
2166
  onUpdate(e, t, n = !0) {
1841
2167
  const o = t;
1842
- return getOrDefault(s(this, ct), e.location).add(o), n && t(e.value), TerminableBuilder.terminableFrom(
2168
+ return getOrDefault(s(this, N), e.location).add(o), n && t(e.value), TerminableBuilder.terminableFrom(
1843
2169
  () => {
1844
2170
  var c;
1845
- return (c = s(this, ct).get(e.location)) == null ? void 0 : c.delete(o);
2171
+ return (c = s(this, N).get(e.location)) == null ? void 0 : c.delete(o);
1846
2172
  }
1847
2173
  );
1848
2174
  }
1849
2175
  /** @internal */
1850
2176
  _dispatchUpdate(e, t) {
1851
2177
  var n;
1852
- (n = s(this, ct).get(e)) == null || n.forEach((o) => o(t));
2178
+ (n = s(this, N).get(e)) == null || n.forEach((o) => o(t));
1853
2179
  }
1854
2180
  /**
1855
2181
  * Subscribe to an event where an entity is removed.
@@ -1870,8 +2196,8 @@ const Et = class Et {
1870
2196
  typeof e == "string" ? e : e.id
1871
2197
  ).add(n), TerminableBuilder.terminableFrom(
1872
2198
  () => {
1873
- var a;
1874
- return (a = s(this, k).get(typeof e == "string" ? e : e.id)) == null ? void 0 : a.delete(n);
2199
+ var r;
2200
+ return (r = s(this, k).get(typeof e == "string" ? e : e.id)) == null ? void 0 : r.delete(n);
1875
2201
  }
1876
2202
  );
1877
2203
  }
@@ -1881,7 +2207,7 @@ const Et = class Et {
1881
2207
  ...s(this, k).get("*") ?? [],
1882
2208
  ...s(this, k).get(e.id) ?? [],
1883
2209
  ...s(this, k).get(e.entityType) ?? []
1884
- ].forEach((t) => t(e)), s(this, k).delete(e.id), [...s(this, lt).keys()].filter((t) => t.entityId === e.id).forEach((t) => s(this, lt).delete(t)), [...s(this, dt).keys()].filter((t) => t.entityId === e.id).forEach((t) => s(this, dt).delete(t)), [...s(this, ct).keys()].filter((t) => t.entityId === e.id).forEach((t) => s(this, ct).delete(t));
2210
+ ].forEach((t) => t(e)), s(this, k).delete(e.id), [...s(this, F).keys()].filter((t) => t.entityId === e.id).forEach((t) => s(this, F).delete(t)), [...s(this, J).keys()].filter((t) => t.entityId === e.id).forEach((t) => s(this, J).delete(t)), [...s(this, N).keys()].filter((t) => t.entityId === e.id).forEach((t) => s(this, N).delete(t));
1885
2211
  }
1886
2212
  /** Subscribe to the event that some pointer in the document starts pointing to a given location.
1887
2213
  *
@@ -1902,18 +2228,18 @@ const Et = class Et {
1902
2228
  * @returns A terminable that when terminated will stop dispatching new onPointingTo events.
1903
2229
  */
1904
2230
  onPointingTo(e, t, n = !0) {
1905
- var a;
1906
- return getOrDefault(s(this, lt), e).add(t), n && ((a = s(this, At).references.get(e)) == null || a.forEach((c) => t(c))), TerminableBuilder.terminableFrom(
2231
+ var r;
2232
+ return getOrDefault(s(this, F), e).add(t), n && ((r = s(this, Jt).references.get(e)) == null || r.forEach((c) => t(c))), TerminableBuilder.terminableFrom(
1907
2233
  () => {
1908
2234
  var c;
1909
- return (c = s(this, lt).get(e)) == null ? void 0 : c.delete(t);
2235
+ return (c = s(this, F).get(e)) == null ? void 0 : c.delete(t);
1910
2236
  }
1911
2237
  );
1912
2238
  }
1913
2239
  /** @internal */
1914
2240
  _dispatchPointingTo(e, t) {
1915
2241
  var n;
1916
- (n = s(this, lt).get(e)) == null || n.forEach((o) => o(t));
2242
+ (n = s(this, F).get(e)) == null || n.forEach((o) => o(t));
1917
2243
  }
1918
2244
  /** Subscribe to the event that some pointer in the document stops pointing to a given location.
1919
2245
  *
@@ -1930,17 +2256,24 @@ const Et = class Et {
1930
2256
  * @returns A terminable that when terminated will stop dispatching new onStopPointingTo events.
1931
2257
  */
1932
2258
  onStopPointingTo(e, t) {
1933
- return getOrDefault(s(this, dt), e).add(t), TerminableBuilder.terminableFrom(
2259
+ return getOrDefault(s(this, J), e).add(t), TerminableBuilder.terminableFrom(
1934
2260
  () => {
1935
2261
  var o;
1936
- return (o = s(this, dt).get(e)) == null ? void 0 : o.delete(t);
2262
+ return (o = s(this, J).get(e)) == null ? void 0 : o.delete(t);
1937
2263
  }
1938
2264
  );
1939
2265
  }
1940
2266
  /** @internal */
1941
2267
  _dispatchStopPointingTo(e, t) {
1942
2268
  var n;
1943
- (n = s(this, dt).get(e)) == null || n.forEach((o) => o(t));
2269
+ (n = s(this, J).get(e)) == null || n.forEach((o) => o(t));
2270
+ }
2271
+ /**
2272
+ * @internal
2273
+ *
2274
+ * Removes all event listeners.*/
2275
+ _clear() {
2276
+ s(this, lt).clear(), s(this, N).clear(), s(this, k).clear(), s(this, F).clear(), s(this, J).clear();
1944
2277
  }
1945
2278
  /**
1946
2279
  * @internal
@@ -1948,68 +2281,78 @@ const Et = class Et {
1948
2281
  * on large documents. Don't call too often. */
1949
2282
  getStats() {
1950
2283
  return {
1951
- numCreateListeners: sizeOf(s(this, ht)),
1952
- numUpdateListeners: sizeOf(s(this, ct)),
2284
+ numCreateListeners: sizeOf(s(this, lt)),
2285
+ numUpdateListeners: sizeOf(s(this, N)),
1953
2286
  numRemoveListeners: sizeOf(s(this, k)),
1954
- numPointingToListeners: sizeOf(s(this, lt)),
1955
- numStopPointingToListeners: sizeOf(s(this, dt))
2287
+ numPointingToListeners: sizeOf(s(this, F)),
2288
+ numStopPointingToListeners: sizeOf(s(this, J))
1956
2289
  };
1957
2290
  }
1958
2291
  };
1959
- ct = new WeakMap(), ht = new WeakMap(), k = new WeakMap(), lt = new WeakMap(), dt = new WeakMap(), At = new WeakMap(), /**
2292
+ N = new WeakMap(), lt = new WeakMap(), k = new WeakMap(), F = new WeakMap(), J = new WeakMap(), Jt = new WeakMap(), /**
1960
2293
  * @internal
1961
2294
  * For debugging purposes, the first instance of the nexus event manager ever created. */
1962
- r(Et, "debugWindowInstance");
1963
- let NexusEventManager = Et;
1964
- const sizeOf = (i) => i.values().reduce((e, t) => e + t.size, 0), getOrDefault = (i, e) => i.get(e) ?? i.set(e, /* @__PURE__ */ new Set()).get(e) ?? throw_(), mockNexusGateway = () => ({
1965
- synchronize: () => [new Transaction()],
1966
- send: () => {
1967
- },
1968
- blocked: new ValueNotifier(!1)
1969
- }), mockNexusValidator = () => ({
2295
+ a(bt, "debugWindowInstance");
2296
+ let NexusEventManager = bt;
2297
+ const sizeOf = (i) => i.values().reduce((e, t) => e + t.size, 0), getOrDefault = (i, e) => i.get(e) ?? i.set(e, /* @__PURE__ */ new Set()).get(e) ?? throw_(), mockNexusGateway = () => {
2298
+ let i = !1, e = !1;
2299
+ return {
2300
+ synchronize: () => e ? "done" : (e = !0, [new Transaction()]),
2301
+ send: () => {
2302
+ if (i)
2303
+ throw new Error("Gateway terminated");
2304
+ },
2305
+ blocked: new ValueNotifier(!1),
2306
+ terminate: async () => {
2307
+ i = !0;
2308
+ }
2309
+ };
2310
+ }, mockNexusValidator = () => ({
1970
2311
  validate: () => {
2312
+ },
2313
+ terminate: () => {
1971
2314
  }
1972
2315
  });
1973
- var Mt, Tt, It, Nt, ft, Bt, Xt;
1974
- const zt = class zt {
2316
+ var Pt, vt, kt, Mt, pt, Ft, $t;
2317
+ const qt = class qt {
1975
2318
  constructor({
1976
2319
  getFields: e,
1977
2320
  getRefs: t,
1978
2321
  filterFields: n,
1979
2322
  documentLock: o
1980
2323
  }) {
1981
- p(this, ft);
1982
- p(this, Mt);
1983
- p(this, Tt);
1984
- p(this, It);
1985
- p(this, Nt);
1986
- h(this, Mt, e), h(this, Tt, t), h(this, It, n), h(this, Nt, o);
2324
+ h(this, pt);
2325
+ h(this, Pt);
2326
+ h(this, vt);
2327
+ h(this, kt);
2328
+ h(this, Mt);
2329
+ g(this, Pt, e), g(this, vt, t), g(this, kt, n), g(this, Mt, o);
1987
2330
  }
1988
2331
  /** Only keep fields that are marked with target type appearing in `targetTypes`. */
1989
2332
  ofTargetTypes(...e) {
1990
- return g(this, ft, Bt).call(this, (t) => getSchemaLocationDetails(t.location).targetTypes.some(
2333
+ return y(this, pt, Ft).call(this, (t) => getSchemaLocationDetails(t.location).targetTypes.some(
1991
2334
  (n) => e.includes(n)
1992
2335
  ));
1993
2336
  }
1994
2337
  /** Only keep fields that aren't pointed to by any other field in the nexus document. */
1995
2338
  notPointedTo() {
1996
- return g(this, ft, Bt).call(this, (e) => {
1997
- const t = s(this, Tt).call(this).get(e.location);
2339
+ return y(this, pt, Ft).call(this, (e) => {
2340
+ const t = s(this, vt).call(this).get(e.location);
1998
2341
  return t === void 0 || t.length === 0;
1999
2342
  });
2000
2343
  }
2001
2344
  pointedToBy(e) {
2002
- return g(this, ft, Bt).call(this, (t) => {
2003
- const n = s(this, Tt).call(this).get(t.location);
2345
+ return y(this, pt, Ft).call(this, (t) => {
2346
+ const n = s(this, vt).call(this).get(t.location);
2004
2347
  return n !== void 0 && n.some((o) => o.equals(e));
2005
2348
  });
2006
2349
  }
2007
2350
  primitiveFields() {
2008
- return g(this, ft, Bt).call(this, (e) => e instanceof PrimitiveField);
2351
+ return y(this, pt, Ft).call(this, (e) => e instanceof PrimitiveField);
2009
2352
  }
2010
2353
  /** Returns all primitive fields selected using this query */
2011
2354
  get() {
2012
- return s(this, Mt).call(this).filter((e) => s(this, It).call(this, e));
2355
+ return s(this, Pt).call(this).filter((e) => s(this, kt).call(this, e));
2013
2356
  }
2014
2357
  /** Returns the first primitive field of the result, or undefined if the query is empty.
2015
2358
  */
@@ -2020,32 +2363,32 @@ const zt = class zt {
2020
2363
  * part of a ComparableMap that maps entity ids to fields for that entity.
2021
2364
  */
2022
2365
  getByEntity() {
2023
- g(this, ft, Xt).call(this);
2366
+ y(this, pt, $t).call(this);
2024
2367
  const e = /* @__PURE__ */ new Map();
2025
2368
  return this.get().forEach((t) => {
2026
2369
  e.has(t.location.entityId) || e.set(t.location.entityId, []), (e.get(t.location.entityId) ?? throw_()).push(t);
2027
2370
  }), e;
2028
2371
  }
2029
2372
  };
2030
- Mt = new WeakMap(), Tt = new WeakMap(), It = new WeakMap(), Nt = new WeakMap(), ft = new WeakSet(), Bt = function(e) {
2031
- return new zt({
2032
- getFields: s(this, Mt),
2033
- getRefs: s(this, Tt),
2034
- filterFields: (t) => s(this, It).call(this, t) && e(t),
2035
- documentLock: s(this, Nt)
2373
+ Pt = new WeakMap(), vt = new WeakMap(), kt = new WeakMap(), Mt = new WeakMap(), pt = new WeakSet(), Ft = function(e) {
2374
+ return new qt({
2375
+ getFields: s(this, Pt),
2376
+ getRefs: s(this, vt),
2377
+ filterFields: (t) => s(this, kt).call(this, t) && e(t),
2378
+ documentLock: s(this, Mt)
2036
2379
  });
2037
- }, Xt = function() {
2380
+ }, $t = function() {
2038
2381
  var e;
2039
- if (!(((e = s(this, Nt)) == null ? void 0 : e.locked) ?? !0))
2382
+ if (!(((e = s(this, Mt)) == null ? void 0 : e.locked) ?? !0))
2040
2383
  throw new Error("Document is not locked");
2041
2384
  };
2042
- let FieldQuery = zt;
2043
- var x, ut, vt, T, E, gt;
2044
- const Kt = class Kt {
2385
+ let FieldQuery = qt;
2386
+ var T, ut, Tt, v, P, wt;
2387
+ const Ot = class Ot {
2045
2388
  /** Don't construct this class, it is constructed by NexusDocument. */
2046
2389
  constructor(e) {
2047
- p(this, T);
2048
- p(this, x);
2390
+ h(this, v);
2391
+ h(this, T);
2049
2392
  /** This function filters & transforms entities. When modifying a query,
2050
2393
  * (e.g. with `ofTypes`, we basically "append" another function
2051
2394
  * to this one that filters and casts the entities.
@@ -2053,14 +2396,14 @@ const Kt = class Kt {
2053
2396
  * When calling `run`, we get all entities and filter them using this function
2054
2397
  * before returning all existing entities.
2055
2398
  */
2056
- p(this, ut);
2057
- p(this, vt);
2058
- h(this, x, (e == null ? void 0 : e.documentState) ?? nexusDocumentState()), h(this, ut, (e == null ? void 0 : e.filterEntities) ?? ((t) => t)), h(this, vt, e == null ? void 0 : e.documentLock);
2399
+ h(this, ut);
2400
+ h(this, Tt);
2401
+ g(this, T, (e == null ? void 0 : e.documentState) ?? nexusDocumentState()), g(this, ut, (e == null ? void 0 : e.filterEntities) ?? ((t) => t)), g(this, Tt, e == null ? void 0 : e.documentLock);
2059
2402
  }
2060
2403
  /** Returns all entities selected by this query, in undefined order.
2061
2404
  */
2062
2405
  get() {
2063
- return g(this, T, gt).call(this), [...s(this, ut).call(this, s(this, x).entities).values()];
2406
+ return y(this, v, wt).call(this), [...s(this, ut).call(this, s(this, T).entities).values()];
2064
2407
  }
2065
2408
  /** Returns the first entity returned by `get()`, if any.
2066
2409
  *
@@ -2069,11 +2412,11 @@ const Kt = class Kt {
2069
2412
  * if it's known that the query will return at most one entity.
2070
2413
  */
2071
2414
  getOne() {
2072
- return g(this, T, gt).call(this), this.get()[0];
2415
+ return y(this, v, wt).call(this), this.get()[0];
2073
2416
  }
2074
2417
  /** Of all selected entities, return the one with id `id`, if it exists. */
2075
2418
  getEntity(e) {
2076
- return g(this, T, gt).call(this), s(this, ut).call(this, s(this, x).entities).get(e);
2419
+ return y(this, v, wt).call(this), s(this, ut).call(this, s(this, T).entities).get(e);
2077
2420
  }
2078
2421
  /**
2079
2422
  * Of all selected entities, return the one with id `id`. Throw if it doesn't
@@ -2087,7 +2430,7 @@ const Kt = class Kt {
2087
2430
  * of the provided types.
2088
2431
  */
2089
2432
  getEntityAs(e, ...t) {
2090
- g(this, T, gt).call(this), assert(t.length > 0, "must provide at least one type");
2433
+ y(this, v, wt).call(this), assert(t.length > 0, "must provide at least one type");
2091
2434
  const n = this.getEntity(e);
2092
2435
  if (n !== void 0 && t.includes(n.entityType))
2093
2436
  return n;
@@ -2097,7 +2440,7 @@ const Kt = class Kt {
2097
2440
  * provided types. Throw if it doesn't exist.
2098
2441
  */
2099
2442
  mustGetEntityAs(e, ...t) {
2100
- g(this, T, gt).call(this), assert(t.length > 0, "must provide at least one type");
2443
+ y(this, v, wt).call(this), assert(t.length > 0, "must provide at least one type");
2101
2444
  const n = this.mustGetEntity(e);
2102
2445
  return t.includes(n.entityType) ? n : throw_(
2103
2446
  `entity with uuid ${e} is not of any of the provided types ${t}`
@@ -2105,7 +2448,7 @@ const Kt = class Kt {
2105
2448
  }
2106
2449
  /** Only keep entities whose id appears in `ids`. */
2107
2450
  withIds(...e) {
2108
- return g(this, T, E).call(this, (t) => filterByUuids(t, e));
2451
+ return y(this, v, P).call(this, (t) => filterByUuids(t, e));
2109
2452
  }
2110
2453
  /** Return the `FieldQuery<NexusField>` that starts with all fields of all
2111
2454
  * currently selected entities.
@@ -2113,39 +2456,39 @@ const Kt = class Kt {
2113
2456
  fields() {
2114
2457
  return new FieldQuery({
2115
2458
  getFields: () => [
2116
- ...s(this, ut).call(this, s(this, x).entities).values()
2459
+ ...s(this, ut).call(this, s(this, T).entities).values()
2117
2460
  ].flatMap((e) => toFields(e)),
2118
- getRefs: () => s(this, x).references,
2461
+ getRefs: () => s(this, T).references,
2119
2462
  filterFields: () => !0,
2120
- documentLock: s(this, vt)
2463
+ documentLock: s(this, Tt)
2121
2464
  });
2122
2465
  }
2123
2466
  /** Only keep entities whose messages are marked with a target type appearing
2124
2467
  * in `targetTypes`. Target types of fields of entities are ignored.
2125
2468
  */
2126
2469
  ofTargetTypes(...e) {
2127
- return g(this, T, E).call(this, (t) => {
2470
+ return y(this, v, P).call(this, (t) => {
2128
2471
  const n = /* @__PURE__ */ new Map();
2129
- return t.forEach((o, a) => {
2472
+ return t.forEach((o, r) => {
2130
2473
  getSchemaLocationDetails(o.location).targetTypes.some(
2131
2474
  (c) => e.includes(c)
2132
- ) && n.set(a, o);
2475
+ ) && n.set(r, o);
2133
2476
  }), n;
2134
2477
  });
2135
2478
  }
2136
2479
  /** Check if a specific entity is contained in the current query. */
2137
2480
  has(e) {
2138
- g(this, T, gt).call(this);
2481
+ y(this, v, wt).call(this);
2139
2482
  const t = typeof e == "string" ? e : e.id;
2140
- return s(this, ut).call(this, s(this, x).entities).has(t);
2483
+ return s(this, ut).call(this, s(this, T).entities).has(t);
2141
2484
  }
2142
2485
  /** Only keep entities whose type string appears in `types`. */
2143
2486
  ofTypes(...e) {
2144
- return g(this, T, E).call(this, (t) => filterByType(t, e));
2487
+ return y(this, v, P).call(this, (t) => filterByType(t, e));
2145
2488
  }
2146
2489
  /** Omit entities whose type string appears in `types`. */
2147
2490
  notOfTypes(...e) {
2148
- return g(this, T, E).call(this, (t) => omitByType(t, e));
2491
+ return y(this, v, P).call(this, (t) => omitByType(t, e));
2149
2492
  }
2150
2493
  /** Only keep entities that have some fields that point to:
2151
2494
  * * `entityOfType`: some field of entities of a set of types
@@ -2161,21 +2504,21 @@ const Kt = class Kt {
2161
2504
  */
2162
2505
  get pointingTo() {
2163
2506
  return {
2164
- entityOfType: (...e) => g(this, T, E).call(this, (t) => filterByUuids(
2507
+ entityOfType: (...e) => y(this, v, P).call(this, (t) => filterByUuids(
2165
2508
  t,
2166
2509
  getUuidsPointingToTypes(
2167
- s(this, x).references,
2168
- s(this, x).entities,
2510
+ s(this, T).references,
2511
+ s(this, T).entities,
2169
2512
  ...e
2170
2513
  )
2171
2514
  )),
2172
- locations: (...e) => g(this, T, E).call(this, (t) => filterByUuids(
2515
+ locations: (...e) => y(this, v, P).call(this, (t) => filterByUuids(
2173
2516
  t,
2174
- getUuidsPointingToLocations(s(this, x).references, e)
2517
+ getUuidsPointingToLocations(s(this, T).references, e)
2175
2518
  )),
2176
- entities: (...e) => g(this, T, E).call(this, (t) => filterByUuids(
2519
+ entities: (...e) => y(this, v, P).call(this, (t) => filterByUuids(
2177
2520
  t,
2178
- getUuidsPointingToEntities(s(this, x).references, e)
2521
+ getUuidsPointingToEntities(s(this, T).references, e)
2179
2522
  ))
2180
2523
  };
2181
2524
  }
@@ -2193,41 +2536,41 @@ const Kt = class Kt {
2193
2536
  */
2194
2537
  get pointedToBy() {
2195
2538
  return {
2196
- entityOfType: (...e) => g(this, T, E).call(this, (t) => filterByUuids(
2539
+ entityOfType: (...e) => y(this, v, P).call(this, (t) => filterByUuids(
2197
2540
  t,
2198
2541
  getUuidsPointedToByTypes(
2199
- s(this, x).references,
2200
- s(this, x).entities,
2542
+ s(this, T).references,
2543
+ s(this, T).entities,
2201
2544
  ...e
2202
2545
  )
2203
2546
  )),
2204
- locations: (...e) => g(this, T, E).call(this, (t) => filterByUuids(
2547
+ locations: (...e) => y(this, v, P).call(this, (t) => filterByUuids(
2205
2548
  t,
2206
- getUuidsPointedToByLocations(s(this, x).references, e)
2549
+ getUuidsPointedToByLocations(s(this, T).references, e)
2207
2550
  )),
2208
- entities: (...e) => g(this, T, E).call(this, (t) => filterByUuids(
2551
+ entities: (...e) => y(this, v, P).call(this, (t) => filterByUuids(
2209
2552
  t,
2210
- getUuidsPointedToByEntities(s(this, x).references, e)
2553
+ getUuidsPointedToByEntities(s(this, T).references, e)
2211
2554
  ))
2212
2555
  };
2213
2556
  }
2214
2557
  };
2215
- x = new WeakMap(), ut = new WeakMap(), vt = new WeakMap(), T = new WeakSet(), /** Return a copy of this class, with a new function "appended" to the
2558
+ T = new WeakMap(), ut = new WeakMap(), Tt = new WeakMap(), v = new WeakSet(), /** Return a copy of this class, with a new function "appended" to the
2216
2559
  * filter pipeline. The filter can change the type of the entity, or
2217
2560
  * remove entities from the query.
2218
2561
  */
2219
- E = function(e) {
2220
- return new Kt({
2221
- documentState: s(this, x),
2562
+ P = function(e) {
2563
+ return new Ot({
2564
+ documentState: s(this, T),
2222
2565
  filterEntities: (t) => e(s(this, ut).call(this, t)),
2223
- documentLock: s(this, vt)
2566
+ documentLock: s(this, Tt)
2224
2567
  });
2225
- }, gt = function() {
2568
+ }, wt = function() {
2226
2569
  var e;
2227
- if (!(((e = s(this, vt)) == null ? void 0 : e.locked) ?? !0))
2570
+ if (!(((e = s(this, Tt)) == null ? void 0 : e.locked) ?? !0))
2228
2571
  throw new Error("EntityQuery method called without locking the document");
2229
2572
  };
2230
- let EntityQuery = Kt;
2573
+ let EntityQuery = Ot;
2231
2574
  const filterByType = (i, e) => {
2232
2575
  const t = /* @__PURE__ */ new Map();
2233
2576
  return [...i.values()].filter((n) => e.includes(n.entityType)).forEach((n) => t.set(n.id, n)), t;
@@ -2243,17 +2586,17 @@ const filterByType = (i, e) => {
2243
2586
  var n;
2244
2587
  return ((n = i.get(t)) == null ? void 0 : n.map((o) => o.entityId)) ?? [];
2245
2588
  }), getUuidsPointingToEntities = (i, e) => [...i.entries()].filter(([t, n]) => e.some((o) => t.entityId === o)).flatMap(([t, n]) => n.map((o) => o.entityId)), getUuidsPointedToByLocations = (i, e) => [...i.entries()].filter(
2246
- ([t, n]) => e.some((o) => n.some((a) => o.equals(a)))
2589
+ ([t, n]) => e.some((o) => n.some((r) => o.equals(r)))
2247
2590
  ).map(([t, n]) => t.entityId), getUuidsPointingToTypes = (i, e, ...t) => [...i.entries()].filter(([n, o]) => {
2248
- const a = e.get(n.entityId);
2249
- return a !== void 0 && t.includes(a.entityType);
2250
- }).flatMap(([n, o]) => o.map((a) => a.entityId)), getUuidsPointedToByTypes = (i, e, ...t) => [...i.entries()].filter(
2251
- ([n, o]) => o.some((a) => {
2252
- const c = e.get(a.entityId);
2591
+ const r = e.get(n.entityId);
2592
+ return r !== void 0 && t.includes(r.entityType);
2593
+ }).flatMap(([n, o]) => o.map((r) => r.entityId)), getUuidsPointedToByTypes = (i, e, ...t) => [...i.entries()].filter(
2594
+ ([n, o]) => o.some((r) => {
2595
+ const c = e.get(r.entityId);
2253
2596
  return c !== void 0 && t.includes(c.entityType);
2254
2597
  })
2255
2598
  ).map(([n, o]) => n.entityId), getUuidsPointedToByEntities = (i, e) => [...i.entries()].filter(
2256
- ([t, n]) => e.some((o) => n.some((a) => a.entityId === o))
2599
+ ([t, n]) => e.some((o) => n.some((r) => r.entityId === o))
2257
2600
  ).map(([t, n]) => t.entityId), toFields = (i) => {
2258
2601
  const e = (t) => {
2259
2602
  if (t instanceof PrimitiveField)
@@ -2356,15 +2699,15 @@ const filterByType = (i, e) => {
2356
2699
  );
2357
2700
  return;
2358
2701
  }
2359
- const a = t[n.localName], c = o[n.localName];
2702
+ const r = t[n.localName], c = o[n.localName];
2360
2703
  assert(
2361
- Array.isArray(a),
2704
+ Array.isArray(r),
2362
2705
  `tried overriding repeated field ${n.localName} of message ${e.getType().typeName} with non-array field`
2363
2706
  ), assert(
2364
- a.length === c.length,
2707
+ r.length === c.length,
2365
2708
  `tried overriding repeated field ${n.localName} with array of different length`
2366
- ), a.forEach((d, l) => {
2367
- c[l] = toFieldValue(i, n, c[l], d);
2709
+ ), r.forEach((l, d) => {
2710
+ c[d] = toFieldValue(i, n, c[d], l);
2368
2711
  });
2369
2712
  });
2370
2713
  }, toFieldValue = (i, e, t, n) => {
@@ -2406,8 +2749,8 @@ const filterByType = (i, e) => {
2406
2749
  return n.map((o) => t(o));
2407
2750
  if (typeof n == "object" && n != null) {
2408
2751
  const o = {};
2409
- return Object.entries(n).forEach(([a, c]) => {
2410
- o[a] = t(c);
2752
+ return Object.entries(n).forEach(([r, c]) => {
2753
+ o[r] = t(c);
2411
2754
  }), o;
2412
2755
  }
2413
2756
  return n;
@@ -2415,31 +2758,31 @@ const filterByType = (i, e) => {
2415
2758
  return t(i);
2416
2759
  }, buildModificationsForCloneLinkedEntities = (...i) => {
2417
2760
  const e = i.map(
2418
- (l) => l instanceof NexusEntity ? { entity: l } : l
2761
+ (d) => d instanceof NexusEntity ? { entity: d } : d
2419
2762
  ), t = /* @__PURE__ */ new Map();
2420
2763
  e.forEach(
2421
- (l) => t.set(l.entity.id, crypto.randomUUID())
2764
+ (d) => t.set(d.entity.id, crypto.randomUUID())
2422
2765
  );
2423
2766
  const n = /* @__PURE__ */ new Map();
2424
- e.forEach((l) => n.set(l.entity.id, l));
2425
- const o = /* @__PURE__ */ new Map(), a = [];
2426
- [...n.values()].forEach(({ entity: l, overwrites: u }) => {
2427
- const m = entityToConstructorType(l), f = createDefaultEntityMessage(l.entityType);
2428
- f.id = t.get(l.id) ?? throw_();
2429
- const y = mapConstructorLocations(m, (v) => {
2430
- const w = t.get(v.entityId);
2431
- return w !== void 0 ? (a.push([f.id, w]), new NexusLocation(w, v.entityType, [
2432
- ...v.fieldIndex
2433
- ])) : v;
2767
+ e.forEach((d) => n.set(d.entity.id, d));
2768
+ const o = /* @__PURE__ */ new Map(), r = [];
2769
+ [...n.values()].forEach(({ entity: d, overwrites: u }) => {
2770
+ const f = entityToConstructorType(d), m = createDefaultEntityMessage(d.entityType);
2771
+ m.id = t.get(d.id) ?? throw_();
2772
+ const p = mapConstructorLocations(f, (w) => {
2773
+ const x = t.get(w.entityId);
2774
+ return x !== void 0 ? (r.push([m.id, x]), new NexusLocation(x, w.entityType, [
2775
+ ...w.fieldIndex
2776
+ ])) : w;
2434
2777
  });
2435
- updateEntityMessageWithConstructor(f, y), u !== void 0 && updateEntityMessageWithConstructor(f, u), o.set(f.id, [l.entityType, f]);
2778
+ updateEntityMessageWithConstructor(m, p), u !== void 0 && updateEntityMessageWithConstructor(m, u), o.set(m.id, [d.entityType, m]);
2436
2779
  });
2437
- const c = toposort(a).reverse(), d = [...o.keys()].filter(
2438
- (l) => !c.includes(l)
2780
+ const c = toposort(r).reverse(), l = [...o.keys()].filter(
2781
+ (d) => !c.includes(d)
2439
2782
  );
2440
2783
  return {
2441
- modifications: [...c, ...d].map((l) => {
2442
- const [, u] = o.get(l) ?? throw_();
2784
+ modifications: [...c, ...l].map((d) => {
2785
+ const [, u] = o.get(d) ?? throw_();
2443
2786
  return buildCreateModification(u);
2444
2787
  }),
2445
2788
  uuidMap: t
@@ -2467,13 +2810,13 @@ const filterByType = (i, e) => {
2467
2810
  };
2468
2811
  }, buildModificationForRemove = (i) => buildDeleteModification(i), buildModificationForRemoveWithDependencies = (i, e) => {
2469
2812
  const t = /* @__PURE__ */ new Set(), n = [];
2470
- t.add(i), t.forEach((a) => {
2471
- e.pointingTo.entities(a).get().forEach((c) => {
2472
- n.push([c.id, a]), t.add(c.id);
2813
+ t.add(i), t.forEach((r) => {
2814
+ e.pointingTo.entities(r).get().forEach((c) => {
2815
+ n.push([c.id, r]), t.add(c.id);
2473
2816
  });
2474
2817
  });
2475
2818
  let o;
2476
- return n.length > 0 ? o = toposort(n) : o = [i], o.map((a) => buildModificationForRemove(a));
2819
+ return n.length > 0 ? o = toposort(n) : o = [i], o.map((r) => buildModificationForRemove(r));
2477
2820
  }, buildPresetUpdateModifications = (i, e) => buildModificationForObject(i, e), buildModificationForField = (i, e) => {
2478
2821
  if (i instanceof PrimitiveField)
2479
2822
  return buildUpdateForPrimitiveField(i, e);
@@ -2492,17 +2835,17 @@ const filterByType = (i, e) => {
2492
2835
  ), i.value.equalsPointer(e) ? [] : [buildModificationForFieldUpdate(i, e)]) : i.value === e ? [] : [buildModificationForFieldUpdate(i, e)]), updatePresetPointers = (i, e) => {
2493
2836
  const t = /* @__PURE__ */ new Map(), n = unpackEntity(i.target) ?? throw_();
2494
2837
  t.set(n.id, e), t.set("", "");
2495
- const o = i.relatives.map((a) => unpackEntity(a) ?? throw_());
2496
- return o.forEach((a) => {
2497
- if (t.has(a.id))
2838
+ const o = i.relatives.map((r) => unpackEntity(r) ?? throw_());
2839
+ return o.forEach((r) => {
2840
+ if (t.has(r.id))
2498
2841
  throw new Error("duplicate entity id");
2499
- t.set(a.id, crypto.randomUUID());
2500
- }), [n, ...o].forEach((a) => {
2501
- a ?? (a = throw_("can't happen")), a.id = t.get(a.id) ?? throw_(), visitPointers(a, (c) => {
2502
- t.has(c.entityId) || console.error("entity", a.constructor.name, "pointer", c), c.entityId = t.get(c.entityId) ?? throw_("preset contains pointer to unknown entity");
2842
+ t.set(r.id, crypto.randomUUID());
2843
+ }), [n, ...o].forEach((r) => {
2844
+ r ?? (r = throw_("can't happen")), r.id = t.get(r.id) ?? throw_(), visitPointers(r, (c) => {
2845
+ t.has(c.entityId) || console.error("entity", r.constructor.name, "pointer", c), c.entityId = t.get(c.entityId) ?? throw_("preset contains pointer to unknown entity");
2503
2846
  });
2504
2847
  }), new Preset({
2505
- relatives: o.map((a) => packEntity(a)),
2848
+ relatives: o.map((r) => packEntity(r)),
2506
2849
  target: packEntity(n)
2507
2850
  });
2508
2851
  }, visitPointers = (i, e) => {
@@ -2544,13 +2887,13 @@ const filterByType = (i, e) => {
2544
2887
  entitiesToRemovePointingToMain: PRESET_TARGET_RELATIVE_TYPES[e] ?? throw_("preset with unexpected main entity type")
2545
2888
  };
2546
2889
  }, toposortEntities = (i) => {
2547
- const e = new Map(i.map((a) => [a.id, a])), t = [];
2548
- i.forEach((a) => {
2549
- visitPointers(a, (c) => {
2550
- e.has(c.entityId) && t.push([a.id, c.entityId]);
2890
+ const e = new Map(i.map((r) => [r.id, r])), t = [];
2891
+ i.forEach((r) => {
2892
+ visitPointers(r, (c) => {
2893
+ e.has(c.entityId) && t.push([r.id, c.entityId]);
2551
2894
  });
2552
2895
  });
2553
- const n = toposort(t).reverse().map((a) => e.get(a) ?? throw_()), o = i.filter((a) => !n.includes(a));
2896
+ const n = toposort(t).reverse().map((r) => e.get(r) ?? throw_()), o = i.filter((r) => !n.includes(r));
2554
2897
  return [...n, ...o];
2555
2898
  }, PRESET_TARGET_RELATIVE_TYPES = {
2556
2899
  // synthesizers
@@ -2656,12 +2999,12 @@ const filterByType = (i, e) => {
2656
2999
  // select entities that point from/tom target entity
2657
3000
  ...o.pointingTo.entities(i.id).get(),
2658
3001
  ...o.pointedToBy.entities(i.id).get()
2659
- ].map((a) => [
3002
+ ].map((r) => [
2660
3003
  // select entities that point from/to any relatives entity
2661
- ...o.pointingTo.entities(a.id).get(),
2662
- ...o.pointedToBy.entities(a.id).get(),
2663
- a
2664
- ]).flat().map((a) => entityToPbMessage(a, !1));
3004
+ ...o.pointingTo.entities(r.id).get(),
3005
+ ...o.pointedToBy.entities(r.id).get(),
3006
+ r
3007
+ ]).flat().map((r) => entityToPbMessage(r, !1));
2665
3008
  }
2666
3009
  return updateUuids([t, ...n]), new Preset({
2667
3010
  relatives: n.map((o) => packEntity(o)),
@@ -2673,8 +3016,8 @@ const filterByType = (i, e) => {
2673
3016
  const t = (n) => (e.set(n, e.get(n) ?? crypto.randomUUID()), e.get(n) ?? throw_());
2674
3017
  i.forEach((n) => {
2675
3018
  const o = t(n.id);
2676
- n.id = o, visitPointers(n, (a) => {
2677
- a.entityId = t(a.entityId);
3019
+ n.id = o, visitPointers(n, (r) => {
3020
+ r.entityId = t(r.entityId);
2678
3021
  });
2679
3022
  });
2680
3023
  }, transactionBuilder = (i) => {
@@ -2683,22 +3026,22 @@ const filterByType = (i, e) => {
2683
3026
  create: (t, n) => {
2684
3027
  if (e)
2685
3028
  throw new CallAfterSendError("create");
2686
- const { modification: o, entityId: a } = buildModificationForNewEntity(t, n);
2687
- return i.applyModification(o, !0), i.query.mustGetEntity(a);
3029
+ const { modification: o, entityId: r } = buildModificationForNewEntity(t, n);
3030
+ return i.applyModification(o, !0), i.query.mustGetEntity(r);
2688
3031
  },
2689
3032
  clone: (t, n) => {
2690
3033
  if (e)
2691
3034
  throw new CallAfterSendError("clone");
2692
- const { modification: o, entityId: a } = buildModificationForEntityClone(t, n);
2693
- return i.applyModification(o, !0), i.query.mustGetEntity(a);
3035
+ const { modification: o, entityId: r } = buildModificationForEntityClone(t, n);
3036
+ return i.applyModification(o, !0), i.query.mustGetEntity(r);
2694
3037
  },
2695
3038
  cloneLinked: (...t) => {
2696
3039
  if (e)
2697
3040
  throw new CallAfterSendError("cloneLinked");
2698
3041
  const { modifications: n, uuidMap: o } = buildModificationsForCloneLinkedEntities(...t);
2699
- return n.forEach((a) => i.applyModification(a, !0)), t.map((a) => {
2700
- const c = a instanceof NexusEntity ? a.id : a.entity.id, d = o.get(c) ?? throw_();
2701
- return i.query.mustGetEntity(d);
3042
+ return n.forEach((r) => i.applyModification(r, !0)), t.map((r) => {
3043
+ const c = r instanceof NexusEntity ? r.id : r.entity.id, l = o.get(c) ?? throw_();
3044
+ return i.query.mustGetEntity(l);
2702
3045
  });
2703
3046
  },
2704
3047
  update: (t, n) => {
@@ -2725,7 +3068,7 @@ const filterByType = (i, e) => {
2725
3068
  if (e)
2726
3069
  throw new CallAfterSendError("removeWithDependencies");
2727
3070
  const n = t instanceof NexusEntity ? t.id : t;
2728
- buildModificationForRemoveWithDependencies(n, i.query).forEach((a) => i.applyModification(a, !0));
3071
+ buildModificationForRemoveWithDependencies(n, i.query).forEach((r) => i.applyModification(r, !0));
2729
3072
  },
2730
3073
  applyPresetTo: (t, n) => {
2731
3074
  if (e)
@@ -2770,10 +3113,10 @@ class CallAfterSendError extends Error {
2770
3113
  );
2771
3114
  }
2772
3115
  }
2773
- var mt, P, M, yt, xt, Dt, Ft, Ot, Gt;
3116
+ var mt, S, M, ft, yt, Lt, It, Ut, Nt, Bt, Ct, Dt;
2774
3117
  class NexusDocument {
2775
3118
  constructor(e) {
2776
- p(this, Ot);
3119
+ h(this, Ct);
2777
3120
  /** Public field to query the entities in the document.
2778
3121
  *
2779
3122
  * ## Careful
@@ -2807,41 +3150,50 @@ class NexusDocument {
2807
3150
  * })
2808
3151
  * ```
2809
3152
  */
2810
- r(this, "queryEntitiesWithoutLock");
3153
+ a(this, "queryEntitiesWithoutLock");
2811
3154
  /** Manages subscriptions to nexus events, such as entity update & creation */
2812
- r(this, "events");
3155
+ a(this, "events");
2813
3156
  /**
2814
3157
  * This is a notifier that notifies of all modifications applied on the nexus
2815
3158
  * document, locally created or incoming from the backend.
2816
3159
  *
2817
3160
  * If the transaction is incoming `local` is `false`.
2818
3161
  */
2819
- r(this, "onModification", new Notifier());
3162
+ a(this, "onModification", new Notifier());
2820
3163
  /** Keeps track of all entities currently in the document. */
2821
- p(this, mt);
3164
+ h(this, mt);
2822
3165
  /**
2823
3166
  * Lock that protects transactions. Only one transaction can be created at a time.
2824
3167
  */
2825
- p(this, P, new AsyncLock());
3168
+ h(this, S, new AsyncLock());
2826
3169
  /** The connection to the backend */
2827
- p(this, M);
3170
+ h(this, M);
2828
3171
  /** Validates any and all modifications */
2829
- p(this, yt);
3172
+ h(this, ft);
2830
3173
  /**
2831
3174
  * This flag is set to true if {@link takeTransactions} is called. Before that, no transactions
2832
3175
  * from the backend are processed, and no transactions are allowed to be created from the frontend.
2833
3176
  *
2834
3177
  * This is to make sure that all `onCreate` callbacks are attached before any entity is created.
2835
3178
  */
2836
- p(this, xt, !1);
3179
+ h(this, yt, !1);
3180
+ /**
3181
+ * This flag is set to true during {@link stop} to exit early if {@link stop} is called twice.
3182
+ */
3183
+ h(this, Lt, !1);
3184
+ /**
3185
+ * This flag is set to true after {@link stop} is called and causes all further calls to {@link createTransaction} and {@link modify} to throw an error.
3186
+ */
3187
+ h(this, It, !1);
2837
3188
  /**
2838
3189
  * The number of modifications applied to the document for incoming transactions before control
2839
3190
  * is yield to the scheduler.
2840
3191
  */
2841
- p(this, Dt);
3192
+ h(this, Ut);
2842
3193
  /** The delay between two gateway.synchronize() calls to sync with backend. */
2843
- p(this, Ft);
2844
- h(this, Ft, (e == null ? void 0 : e.synchronizeEveryMs) ?? 16), h(this, Dt, (e == null ? void 0 : e.incomingModificationsBatchSize) ?? 20), h(this, mt, nexusDocumentState({
3194
+ h(this, Nt);
3195
+ h(this, Bt);
3196
+ g(this, Nt, (e == null ? void 0 : e.synchronizeEveryMs) ?? 16), g(this, Ut, (e == null ? void 0 : e.incomingModificationsBatchSize) ?? 20), g(this, mt, nexusDocumentState({
2845
3197
  callbacks: {
2846
3198
  onStartPointingTo: (t, n) => {
2847
3199
  this.events._dispatchPointingTo(n, t);
@@ -2872,7 +3224,7 @@ class NexusDocument {
2872
3224
  * This is to make sure that all `onCreate` callbacks are attached before any entity is created.
2873
3225
  */
2874
3226
  get transactionsAllowed() {
2875
- return s(this, xt);
3227
+ return s(this, yt);
2876
3228
  }
2877
3229
  /**
2878
3230
  * Wait to acquire the document lock, then returns a {@link TransactionBuilder} that can be used to modify the nexus document
@@ -2887,27 +3239,27 @@ class NexusDocument {
2887
3239
  * @returns: {@link TransactionBuilder}
2888
3240
  */
2889
3241
  async createTransaction(e, t = !0) {
2890
- assert(s(this, xt), "Transactions not allowed yet"), assert(s(this, M) !== void 0, "Gateway not initialized"), assert(s(this, yt) !== void 0, "Validator not initialized");
2891
- const n = t ? await s(this, P).acquire() : void 0, o = [], a = new EntityQuery({
3242
+ assert(s(this, yt), "Transactions not allowed yet"), assert(s(this, M) !== void 0, "Gateway not initialized"), assert(s(this, ft) !== void 0, "Validator not initialized"), assert(!s(this, It), "Document stopped");
3243
+ const n = t ? await s(this, S).acquire() : void 0, o = [], r = new EntityQuery({
2892
3244
  documentState: s(this, mt),
2893
- documentLock: s(this, P)
3245
+ documentLock: s(this, S)
2894
3246
  }), c = (e == null ? void 0 : e.actionId) ?? Symbol();
2895
3247
  return transactionBuilder({
2896
- applyModification: (d, l) => {
2897
- const u = g(this, Ot, Gt).call(this, d, {
3248
+ applyModification: (l, d) => {
3249
+ const u = y(this, Ct, Dt).call(this, l, {
2898
3250
  local: !0,
2899
- throwIfInvalid: l,
3251
+ throwIfInvalid: d,
2900
3252
  actionId: c
2901
3253
  });
2902
3254
  if (u !== void 0)
2903
3255
  return u;
2904
- o.push(d);
3256
+ o.push(l);
2905
3257
  },
2906
3258
  finish: () => {
2907
- var d;
2908
- return o.length === 0 ? (n == null || n.release(), []) : ((d = s(this, M)) == null || d.send(new Transaction({ modifications: o })), n == null || n.release(), o);
3259
+ var l;
3260
+ return o.length === 0 ? (n == null || n.release(), []) : ((l = s(this, M)) == null || l.send(new Transaction({ modifications: o })), n == null || n.release(), o);
2909
3261
  },
2910
- query: a
3262
+ query: r
2911
3263
  });
2912
3264
  }
2913
3265
  /**
@@ -2940,397 +3292,116 @@ class NexusDocument {
2940
3292
  * It should be called exactly once when all `onCreate` callbacks are registered.
2941
3293
  */
2942
3294
  async takeTransactions(e) {
2943
- if (s(this, xt))
3295
+ if (s(this, yt))
2944
3296
  throw new Error("called `takeTransactions()` twice");
2945
- h(this, yt, (e == null ? void 0 : e.validator) ?? mockNexusValidator()), h(this, M, (e == null ? void 0 : e.gateway) ?? mockNexusGateway());
3297
+ g(this, ft, (e == null ? void 0 : e.validator) ?? mockNexusValidator()), g(this, M, (e == null ? void 0 : e.gateway) ?? mockNexusGateway());
2946
3298
  let t;
2947
- s(this, M).blocked.subscribe(async (l) => {
2948
- l ? t === void 0 && (t = await s(this, P).acquire()) : (t == null || t.release(), t = void 0);
3299
+ s(this, M).blocked.subscribe(async (u) => {
3300
+ u ? t === void 0 && (t = await s(this, S).acquire()) : (t == null || t.release(), t = void 0);
2949
3301
  });
2950
- const n = await s(this, P).acquire();
2951
- h(this, xt, !0);
3302
+ const n = await s(this, S).acquire();
3303
+ g(this, yt, !0);
2952
3304
  const {
2953
3305
  promise: o,
2954
- resolve: a
3306
+ resolve: r
2955
3307
  } = Promise.withResolvers(), c = asyncInterval(async () => {
2956
- const l = (s(this, M) ?? throw_()).synchronize();
2957
- if (l.length === 0)
3308
+ const u = (s(this, M) ?? throw_()).synchronize();
3309
+ if (u === "done")
3310
+ throw new Error(
3311
+ "Gateway returned 'done' before returning the initial transaction."
3312
+ );
3313
+ if (u.length === 0)
2958
3314
  return;
2959
- const u = l.flatMap((m) => m.modifications).length;
2960
- await this.applyIncomingTransactions(l, {
3315
+ const f = u.flatMap((m) => m.modifications).length;
3316
+ await this._applyIncomingTransactions(u, {
2961
3317
  _takeTransactionLock: !1
2962
- }), c.terminate(), a(u > 0);
2963
- }, s(this, Ft)), d = await o;
3318
+ }), c.terminate(), r(f > 0);
3319
+ }, s(this, Nt)), l = await o;
2964
3320
  if ((e == null ? void 0 : e.templateTransaction) !== void 0)
2965
- if (d)
3321
+ if (l)
2966
3322
  console.error(
2967
3323
  "Could not apply template transaction to document: Project state from backend is not empty."
2968
3324
  );
2969
3325
  else {
2970
- const l = await e.templateTransaction, u = await this.createTransaction(void 0, !1);
2971
- l.modifications.forEach((m) => u._addModification(m)), u.send();
3326
+ const u = await e.templateTransaction, f = await this.createTransaction(void 0, !1);
3327
+ u.modifications.forEach((m) => f._addModification(m)), f.send();
3328
+ }
3329
+ n.release();
3330
+ const d = asyncInterval(async (u) => {
3331
+ if (u.aborted)
3332
+ return;
3333
+ const f = await s(this, S).acquire(), m = (s(this, M) ?? throw_()).synchronize();
3334
+ if (m === "done") {
3335
+ d.terminate(), f.release();
3336
+ return;
2972
3337
  }
2973
- n.release(), asyncInterval(async () => {
2974
- const l = await s(this, P).acquire(), u = (s(this, M) ?? throw_()).synchronize();
2975
- await this.applyIncomingTransactions(u, { _takeTransactionLock: !1 }), l.release();
2976
- }, s(this, Ft));
3338
+ await this._applyIncomingTransactions(m, { _takeTransactionLock: !1 }), f.release();
3339
+ }, s(this, Nt));
3340
+ g(this, Bt, () => d.terminate());
2977
3341
  }
2978
3342
  /** Apply a transaction that doesn't originate from this document. Yields to the browser
2979
3343
  * scheduler every few modifications applied to make sure we don't block the main thread
2980
3344
  * for too long for big transactions. Throws if the transaction lock isn't taken.
2981
3345
  *
2982
3346
  */
2983
- async applyIncomingTransactions(e, t) {
2984
- assert(s(this, M) !== void 0, "Gateway not initialized"), assert(s(this, yt) !== void 0, "Validator not initialized");
2985
- const n = (t == null ? void 0 : t._takeTransactionLock) ?? !0 ? await s(this, P).acquire() : assert(
2986
- s(this, P).locked,
3347
+ async _applyIncomingTransactions(e, t) {
3348
+ assert(s(this, M) !== void 0, "Gateway not initialized"), assert(s(this, ft) !== void 0, "Validator not initialized"), assert(!s(this, It), "Document stopped");
3349
+ const n = (t == null ? void 0 : t._takeTransactionLock) ?? !0 ? await s(this, S).acquire() : assert(
3350
+ s(this, S).locked,
2987
3351
  "if takeTransactionLock is false, the lock must be held."
2988
3352
  );
2989
3353
  for (const o of e)
2990
- for (const [a, c] of o.modifications.entries())
2991
- g(this, Ot, Gt).call(this, c, {
3354
+ for (const [r, c] of o.modifications.entries())
3355
+ y(this, Ct, Dt).call(this, c, {
2992
3356
  local: !1,
2993
3357
  throwIfInvalid: !0
2994
- }), a % s(this, Dt) === 0 && await sleep(0);
3358
+ }), r % s(this, Ut) === 0 && await sleep(0);
2995
3359
  n == null || n.release();
2996
3360
  }
2997
3361
  /** For debugging purposes */
2998
3362
  getStats() {
2999
3363
  return s(this, mt).getStats();
3000
3364
  }
3365
+ /** Stop the document from syncing. This will have the following effect:
3366
+ * First, all pending `modify` and `createTransaction` calls will finish.
3367
+ * The modifications they create will be synced with the backend, and the document is locked down.
3368
+ *
3369
+ * After this, calling `modify` or `createTransaction` will throw an error. The only property that
3370
+ * can still be accessed is `queryEntities`. The document can be thrown away safely after this.
3371
+ */
3372
+ async terminate() {
3373
+ var e, t, n;
3374
+ if (!s(this, yt))
3375
+ throw new Error("Can't stop a document that hasn't started yet.");
3376
+ s(this, Lt) || (g(this, Lt, !0), await s(this, S).acquire(), (e = s(this, Bt)) == null || e.call(this), s(this, S).acquire = () => throw_(
3377
+ "invariant violated: cannot get transaction lock after document stopped"
3378
+ ), g(this, It, !0), await ((t = s(this, M)) == null ? void 0 : t.terminate()), (n = s(this, ft)) == null || n.terminate(), this.events._clear());
3379
+ }
3001
3380
  }
3002
- mt = new WeakMap(), P = new WeakMap(), M = new WeakMap(), yt = new WeakMap(), xt = new WeakMap(), Dt = new WeakMap(), Ft = new WeakMap(), Ot = new WeakSet(), /**
3381
+ mt = new WeakMap(), S = new WeakMap(), M = new WeakMap(), ft = new WeakMap(), yt = new WeakMap(), Lt = new WeakMap(), It = new WeakMap(), Ut = new WeakMap(), Nt = new WeakMap(), Bt = new WeakMap(), Ct = new WeakSet(), /**
3003
3382
  * Apply a modification to the document after validating it, and dispatch events to
3004
3383
  * {@link onModification} listeners. Throws if the modification is invalid, unless `throwIfInvalid` is false;
3005
3384
  * in that case, the function returns `string` on error and doesn't change the document state. If application
3006
3385
  * succeeds, always returns undefined.
3007
3386
  */
3008
- Gt = function(e, {
3387
+ Dt = function(e, {
3009
3388
  local: t = !0,
3010
3389
  throwIfInvalid: n = !0,
3011
3390
  actionId: o
3012
3391
  }) {
3013
- assert(s(this, yt) !== void 0, "Validator not initialized"), assert(
3014
- s(this, P).locked,
3392
+ assert(s(this, ft) !== void 0, "Validator not initialized"), assert(
3393
+ s(this, S).locked,
3015
3394
  "tried applying modification without lock"
3016
3395
  );
3017
- const a = s(this, yt).validate(e);
3018
- if (a !== void 0) {
3396
+ const r = s(this, ft).validate(e);
3397
+ if (r !== void 0) {
3019
3398
  if (n)
3020
- throw new Error(`modification failed validation: ${a}`);
3021
- return a;
3399
+ throw new Error(`modification failed validation: ${r}`);
3400
+ return r;
3022
3401
  }
3023
3402
  s(this, mt).applyModification(e), this.onModification.notify({ modification: e, local: t, actionId: o });
3024
3403
  };
3025
- var I, S;
3026
- class NexusStateConsolidator {
3027
- constructor(e) {
3028
- /**
3029
- * A copy of the document state, to validate that pending transactions can still be applied,
3030
- * and drop them if not.
3031
- */
3032
- p(this, I);
3033
- /**
3034
- * Transactions not yet confirmed or rejected by the remote.
3035
- *
3036
- * This is list contains `[forward, backward]` transactions, where `forward` are always the last transactions
3037
- * applied to {@link #state}, while backwards contains their respective reverse, so the state
3038
- * before all transactions in {@link #pending} can be restored.
3039
- */
3040
- p(this, S, []);
3041
- h(this, I, e);
3042
- }
3043
- /**
3044
- * Consolidate the local and remote transaction history.
3045
- *
3046
- * @param newReceived Newly received transaction from the remote
3047
- * @param newReceivedRejected Newly received transaction rejections from the remote. **must be a subset of previously created transactions**
3048
- * @param newCreated Newly created transactions on the local document
3049
- * @returns Transactions needed to sync local & remote, plus transactions created but not yet received
3050
- */
3051
- consolidate(e, t, n) {
3052
- n.forEach((d) => {
3053
- const l = s(this, I).applyTransaction(d);
3054
- if (!(l instanceof Transaction))
3055
- throw new Error(`Error applying reverse transaction: ${l}`);
3056
- s(this, S).push([d, l]);
3057
- });
3058
- let o = e[0], a = s(this, S)[0];
3059
- for (; o !== void 0 && a !== void 0 && o.id === a[0].id; )
3060
- e.shift(), s(this, S).shift(), o = e[0], a = s(this, S)[0];
3061
- if (e.length === 0) {
3062
- if (t.size === 0)
3063
- return [];
3064
- const d = s(this, S).findIndex(
3065
- ([f]) => t.has(f.id)
3066
- );
3067
- if (d === -1)
3068
- throw new Error(
3069
- "Invariant violation: expected to find rejected transaction in #pending, but didn't. This is a bug."
3070
- );
3071
- const l = s(this, S).splice(d), u = l.map(([, f]) => {
3072
- if (!(s(this, I).applyTransaction(f) instanceof Transaction))
3073
- throw new Error("error applying reversal of transaction");
3074
- return f;
3075
- }).reverse(), m = l.filter(([f]) => !t.has(f.id)).map(([f]) => {
3076
- const y = s(this, I).applyTransaction(f);
3077
- if (y instanceof Transaction)
3078
- return [f, y];
3079
- }).filter((f) => f !== void 0);
3080
- return s(this, S).push(...m), [...u, ...m.map(([f]) => f)];
3081
- }
3082
- const c = s(this, S).map((d) => d[1].clone()).reverse();
3083
- return c.forEach((d) => {
3084
- const l = s(this, I).applyTransaction(d);
3085
- if (!(l instanceof Transaction))
3086
- throw new Error(`Error applying reverse transaction: ${l}`);
3087
- }), e.forEach((d) => {
3088
- const l = s(this, I).applyTransaction(d);
3089
- if (!(l instanceof Transaction))
3090
- throw new Error(`Error applying incoming transaction: ${l}`);
3091
- }), h(this, S, s(this, S).filter(([d]) => {
3092
- const l = t.has(d.id), u = e.some(
3093
- (m) => m.id === d.id
3094
- );
3095
- return !l && !u;
3096
- }).map(([d]) => {
3097
- const l = s(this, I).applyTransaction(d);
3098
- return l instanceof Transaction ? [d, l] : void 0;
3099
- }).filter((d) => d !== void 0)), [
3100
- ...c,
3101
- ...e,
3102
- ...s(this, S).map(([d]) => d)
3103
- ];
3104
- }
3105
- }
3106
- I = new WeakMap(), S = new WeakMap();
3107
- var qt, jt, Rt, $t, Jt, Vt, bt, Ct, Lt;
3108
- const wt = class wt {
3109
- constructor({
3110
- documentService: e,
3111
- state: t,
3112
- logOutgoingTransactions: n,
3113
- logIncomingTransactions: o,
3114
- logConsolidatedTransactions: a,
3115
- logRejectedTransactions: c
3116
- }) {
3117
- p(this, qt);
3118
- p(this, jt);
3119
- p(this, Rt, !1);
3120
- // = false due to ts complaining
3121
- p(this, $t);
3122
- // the connection to the backend, to send & receive transactions
3123
- p(this, Jt);
3124
- r(this, "blocked");
3125
- p(this, Vt);
3126
- p(this, bt, []);
3127
- p(this, Ct, []);
3128
- p(this, Lt, /* @__PURE__ */ new Set());
3129
- h(this, Jt, e), h(this, Vt, new NexusStateConsolidator(t)), h(this, $t, a ?? !1), h(this, Rt, o ?? !1), h(this, jt, n ?? !1), h(this, qt, c ?? !1), (async () => {
3130
- for (; ; ) {
3131
- const l = await e.receiveNextTransaction();
3132
- s(this, bt).push(l), wt.stats.numReceivedCtr++, s(this, Rt) && console.debug("CollabGateway: received transaction", l);
3133
- }
3134
- })();
3135
- const d = new ValueNotifier(!1);
3136
- s(this, Jt).connectionOk.subscribe((l) => {
3137
- d.setValue(!l);
3138
- }), this.blocked = d;
3139
- }
3140
- /** Send a transaction to the document service. */
3141
- send(e) {
3142
- e.id = crypto.randomUUID(), s(this, Ct).push(e.clone()), wt.stats.numQueuedCtr++, s(this, jt) && console.debug("CollabGateway: sending local transaction", e), s(this, Jt).sendNextTransaction(e).then((t) => {
3143
- wt.stats.numConfirmedCtr++, t !== void 0 && (s(this, Lt).add(e.id), s(this, qt) && console.debug(
3144
- "CollabGateway: received rejected transaction",
3145
- e,
3146
- t
3147
- ), wt.stats.numRejectedCtr++);
3148
- });
3149
- }
3150
- /** Receive new transactions from the backend, already consolidated with the local change history.*/
3151
- synchronize() {
3152
- const e = s(this, bt).length > 0, t = s(this, Vt).consolidate(
3153
- s(this, bt),
3154
- s(this, Lt),
3155
- s(this, Ct)
3156
- );
3157
- return s(this, bt).length = 0, s(this, Lt).clear(), s(this, Ct).length = 0, s(this, $t) && e && console.debug("CollabGateway: consolidated transactions", t), t;
3158
- }
3159
- };
3160
- qt = new WeakMap(), jt = new WeakMap(), Rt = new WeakMap(), $t = new WeakMap(), Jt = new WeakMap(), Vt = new WeakMap(), bt = new WeakMap(), Ct = new WeakMap(), Lt = new WeakMap(), /**
3161
- * Some stats, useful for debugging.
3162
- */
3163
- r(wt, "stats", {
3164
- numReceivedCtr: 0,
3165
- numConfirmedCtr: 0,
3166
- numQueuedCtr: 0,
3167
- numRejectedCtr: 0
3168
- });
3169
- let CollabGateway = wt;
3170
- const combinedValueNotifiersWithAnd = (...i) => {
3171
- const e = new ValueNotifier(!0), t = () => e.setValue(i.every((n) => n.getValue()));
3172
- return i.forEach((n) => n.subscribe(() => t())), t(), e;
3173
- };
3174
- var Ut;
3175
- class BufferedSender {
3176
- constructor(e, t = 100) {
3177
- /** Contains data to be sent out during the next batched send. The second element resolves the promise
3178
- * created in `send` for that data.
3179
- */
3180
- p(this, Ut, []);
3181
- (async () => {
3182
- for (; ; ) {
3183
- const n = s(this, Ut).splice(0, s(this, Ut).length);
3184
- if (n.length === 0) {
3185
- await sleep(t);
3186
- continue;
3187
- }
3188
- const o = await e(n.map(([a]) => a));
3189
- n.forEach(([, a], c) => {
3190
- a(o[c]);
3191
- });
3192
- }
3193
- })();
3194
- }
3195
- async send(e) {
3196
- return new Promise((t) => {
3197
- s(this, Ut).push([e, t]);
3198
- });
3199
- }
3200
- }
3201
- Ut = new WeakMap();
3202
- const createPingNotifier = (i, e, t, n) => {
3203
- const o = new ValueNotifier(0);
3204
- return (async () => {
3205
- for (; ; ) {
3206
- const c = Date.now();
3207
- await i.ping(
3208
- {
3209
- clientId: "undefined",
3210
- projectName: e,
3211
- lastPingMs: Math.floor(o.getValue())
3212
- },
3213
- {
3214
- callIsOk: n
3215
- }
3216
- );
3217
- const d = Date.now() - c;
3218
- await sleep(Math.max(0, t - d)), o.setValue(d / 2);
3219
- }
3220
- })(), o;
3221
- }, createReceiveNextTransactionFn = (i, e, t, n, o) => {
3222
- let a = 0;
3223
- const c = () => i.attach({ projectName: e, commitIndex: a }, { signal: o() })[Symbol.asyncIterator]();
3224
- let d = c(), l = !1;
3225
- return async () => {
3226
- for (; ; )
3227
- try {
3228
- const { value: u, done: m } = await d.next();
3229
- if (m ?? !1)
3230
- throw new Error("document service attach stream closed");
3231
- switch (t.setValue(!0), u.message.case) {
3232
- case "noop": {
3233
- if (l)
3234
- continue;
3235
- return l = !0, new Transaction();
3236
- }
3237
- case "transaction": {
3238
- const f = u.message.value;
3239
- return a = f.commitIndex, l = !0, f;
3240
- }
3241
- default:
3242
- throw new Error(
3243
- `received attach response with unknown message case: ${u.message.case}`
3244
- );
3245
- }
3246
- } catch (u) {
3247
- if (!(u instanceof ConnectError))
3248
- throw u;
3249
- switch (u.code) {
3250
- case Code.Canceled:
3251
- // happens if abort controller throws
3252
- case Code.Aborted:
3253
- case Code.Unavailable:
3254
- case Code.Unknown: {
3255
- t.setValue(!1), console.debug("Connection lost:", u.message, " - retrying..."), await sleep(n + Math.random() * n * 0.1), d = c();
3256
- continue;
3257
- }
3258
- case Code.OutOfRange:
3259
- throw new Error(
3260
- "local document state too far in the past, must reload tab"
3261
- );
3262
- default:
3263
- throw u;
3264
- }
3265
- }
3266
- };
3267
- }, createDocumentServiceWrapper = ({
3268
- projectName: i,
3269
- pingIntervalMs: e,
3270
- backoffMs: t = 1e3,
3271
- documentService: n
3272
- }) => {
3273
- let o = new AbortController();
3274
- const a = new ValueNotifier(!0);
3275
- a.subscribe((w) => {
3276
- w ? o = new AbortController() : o.abort("ping called failed, connection assumed lost");
3277
- });
3278
- let c;
3279
- c = createPingNotifier(
3280
- n,
3281
- i,
3282
- e,
3283
- a
3284
- );
3285
- const d = new ValueNotifier(!0), l = createReceiveNextTransactionFn(
3286
- n,
3287
- i,
3288
- d,
3289
- t,
3290
- () => o.signal
3291
- ), u = new ValueNotifier(!0), m = new BufferedSender(
3292
- async (w) => {
3293
- const b = await n.applyTransactions(
3294
- {
3295
- projectName: i,
3296
- transactions: w
3297
- },
3298
- {
3299
- callIsOk: u
3300
- }
3301
- );
3302
- if (b instanceof Error)
3303
- throw new Error("error sending transaction", { cause: b });
3304
- return w.map(
3305
- (N) => b.errors[N.id] ?? void 0
3306
- );
3307
- }
3308
- ), f = async (w) => await m.send(w), y = combinedValueNotifiersWithAnd(
3309
- a,
3310
- d,
3311
- u
3312
- );
3313
- return {
3314
- ping: c,
3315
- connectionOk: y,
3316
- receiveNextTransaction: l,
3317
- sendNextTransaction: f
3318
- };
3319
- }, initCollabGateway = async (i, e) => {
3320
- const t = createDocumentServiceWrapper({
3321
- projectName: i,
3322
- documentService: e,
3323
- pingIntervalMs: 1e3
3324
- }), n = await getWasmDocumentState();
3325
- return new CollabGateway({
3326
- documentService: t,
3327
- state: n,
3328
- logOutgoingTransactions: !1,
3329
- logIncomingTransactions: !1,
3330
- logConsolidatedTransactions: !1,
3331
- logRejectedTransactions: !1
3332
- });
3333
- }, DocumentService = {
3404
+ const DocumentService = {
3334
3405
  typeName: "audiotool.document.v1.DocumentService",
3335
3406
  methods: {
3336
3407
  /**
@@ -3495,62 +3566,56 @@ const createPingNotifier = (i, e, t, n) => {
3495
3566
  kind: MethodKind.Unary
3496
3567
  }
3497
3568
  }
3569
+ }, createSyncedDocument = (i, e, t, n) => ({
3570
+ connected: e,
3571
+ createTransaction: () => i.createTransaction(),
3572
+ modify: (o) => i.modify(o),
3573
+ queryEntities: i.queryEntitiesWithoutLock,
3574
+ events: i.events,
3575
+ start: async () => i.takeTransactions({ validator: t, gateway: n }),
3576
+ stop: async () => i.terminate()
3577
+ }), createOfflineDocument = async (i) => {
3578
+ const e = (i == null ? void 0 : i.validated) ?? !0 ? await createWasmNexusValidator() : mockNexusValidator(), t = mockNexusGateway(), n = new NexusDocument(), o = new ValueNotifier(!0), r = createSyncedDocument(n, o, e, t);
3579
+ return await r.start(), r;
3498
3580
  }, createOnlineDocument = async (i, e, t) => {
3499
- var u;
3581
+ var f;
3500
3582
  let n = createWasmNexusValidator();
3501
3583
  const o = await i.projectService.openSession({
3502
3584
  projectName: e
3503
3585
  });
3504
3586
  if (o instanceof Error)
3505
3587
  throw new Error("Couldn't open session", { cause: o });
3506
- const a = createRetryingPromiseClient(
3588
+ const r = createRetryingPromiseClient(
3507
3589
  DocumentService,
3508
3590
  createAuthorizedKeepaliveTransport({
3509
- baseUrl: ((u = o.session) == null ? void 0 : u.documentServiceUrl) ?? throw_("backend returned no document service url"),
3591
+ baseUrl: ((f = o.session) == null ? void 0 : f.documentServiceUrl) ?? throw_("backend returned no document service url"),
3510
3592
  useBinaryFormat: !0,
3511
3593
  getToken: t
3512
3594
  })
3513
- );
3514
- await n;
3515
- const c = await initCollabGateway(
3516
- e ?? throw_(),
3517
- a
3518
- ), d = new NexusDocument(), l = new ValueNotifier(!1);
3519
- return c.blocked.subscribe((m) => l.setValue(!m)), createSyncedDocument(d, l, await n, c);
3520
- }, createOfflineDocument = async (i) => {
3521
- const e = i ? await createWasmNexusValidator() : mockNexusValidator(), t = mockNexusGateway(), n = new NexusDocument(), o = new ValueNotifier(!0);
3522
- return createSyncedDocument(n, o, e, t);
3523
- }, createSyncedDocument = (i, e, t, n) => ({
3524
- connected: e,
3525
- createTransaction: () => i.createTransaction(),
3526
- modify: (o) => i.modify(o),
3527
- queryEntities: i.queryEntitiesWithoutLock,
3528
- events: i.events,
3529
- start: async () => i.takeTransactions({ validator: t, gateway: n })
3530
- }), createAudiotoolClient = async ({
3595
+ ), c = await n, l = createCollabGateway(
3596
+ r,
3597
+ await getWasmDocumentState(),
3598
+ e
3599
+ ), d = new NexusDocument(), u = new ValueNotifier(!1);
3600
+ return l.blocked.subscribe((m) => u.setValue(!m)), createSyncedDocument(d, u, c, l);
3601
+ }, createAudiotoolClient = async ({
3531
3602
  authorization: i
3532
3603
  }) => {
3533
3604
  const e = async () => {
3534
3605
  if (typeof i == "string")
3535
3606
  return addBearerPrefix(i);
3536
- const o = await i.getToken();
3537
- if (o instanceof Error)
3607
+ const n = await i.getToken();
3608
+ if (n instanceof Error)
3538
3609
  throw new Error("Failed to get authentication token", {
3539
- cause: o
3610
+ cause: n
3540
3611
  });
3541
- return addBearerPrefix(o);
3612
+ return addBearerPrefix(n);
3542
3613
  }, t = await createAudiotoolAPI(e);
3543
- let n = !1;
3544
3614
  return {
3545
3615
  api: t,
3546
- createSyncedDocument: async (o) => {
3547
- if (n)
3548
- throw new Error("Can only create one synced document currently.");
3549
- if (n = !0, o.mode === "online") {
3550
- const a = extractProjectName(o.project), c = await createOnlineDocument(t, a, e);
3551
- return console.debug("Nexus connected."), c;
3552
- } else
3553
- return await createOfflineDocument(o.validated);
3616
+ createSyncedDocument: async ({ project: n }) => {
3617
+ const o = extractProjectName(n);
3618
+ return await createOnlineDocument(t, o, e);
3554
3619
  }
3555
3620
  };
3556
3621
  }, extractProjectName = (i) => {
@@ -3572,17 +3637,17 @@ const createPingNotifier = (i, e, t, n) => {
3572
3637
  codeVerifier: `oidc_${i}_oidc_code_verifier`,
3573
3638
  userName: `oidc_${i}_oidc_user_name`,
3574
3639
  state: `oidc_${i}_oidc_state`
3575
- }, o = () => redirectUserToLogin(n, i, t, e), a = new URLSearchParams(window.location.search), c = a.get("error"), d = a.get("error_description");
3640
+ }, o = () => redirectUserToLogin(n, i, t, e), r = new URLSearchParams(window.location.search), c = r.get("error"), l = r.get("error_description");
3576
3641
  if (c != null)
3577
3642
  return cleanupUrl(), cleanUpLocalStorage(n), {
3578
3643
  loggedIn: !1,
3579
- error: toError(c, d),
3644
+ error: toError(c, l),
3580
3645
  login: o
3581
3646
  };
3582
- const l = a.get("code");
3583
- if (l != null) {
3584
- const f = a.get("state"), y = localStorage.getItem(n.state);
3585
- if (f == null || y == null || f !== y)
3647
+ const d = r.get("code");
3648
+ if (d != null) {
3649
+ const m = r.get("state"), p = localStorage.getItem(n.state);
3650
+ if (m == null || p == null || m !== p)
3586
3651
  return {
3587
3652
  loggedIn: !1,
3588
3653
  error: toError(
@@ -3591,14 +3656,14 @@ const createPingNotifier = (i, e, t, n) => {
3591
3656
  ),
3592
3657
  login: o
3593
3658
  };
3594
- const v = localStorage.getItem(n.codeVerifier);
3595
- if (v == null)
3659
+ const w = localStorage.getItem(n.codeVerifier);
3660
+ if (w == null)
3596
3661
  return {
3597
3662
  loggedIn: !1,
3598
3663
  error: toError("Code verifier not found. Restart the auth flow."),
3599
3664
  login: o
3600
3665
  };
3601
- const w = await fetch(TOKEN_ENDPOINT, {
3666
+ const x = await fetch(TOKEN_ENDPOINT, {
3602
3667
  method: "POST",
3603
3668
  headers: {
3604
3669
  "Content-Type": "application/x-www-form-urlencoded"
@@ -3606,70 +3671,70 @@ const createPingNotifier = (i, e, t, n) => {
3606
3671
  body: new URLSearchParams({
3607
3672
  client_id: i,
3608
3673
  grant_type: "authorization_code",
3609
- code: l,
3674
+ code: d,
3610
3675
  redirect_uri: e,
3611
- code_verifier: v,
3676
+ code_verifier: w,
3612
3677
  token_endpoint_auth_method: "none"
3613
3678
  })
3614
3679
  }), {
3615
- access_token: b,
3616
- refresh_token: N,
3617
- expires_in: St,
3618
- error: Ht,
3619
- error_description: Yt
3620
- } = await w.json();
3621
- if (Ht)
3680
+ access_token: E,
3681
+ refresh_token: gt,
3682
+ expires_in: xt,
3683
+ error: Rt,
3684
+ error_description: Vt
3685
+ } = await x.json();
3686
+ if (Rt)
3622
3687
  return {
3623
3688
  loggedIn: !1,
3624
- error: toError(Ht, Yt),
3689
+ error: toError(Rt, Vt),
3625
3690
  login: o
3626
3691
  };
3627
- localStorage.setItem(n.accessToken, b), localStorage.setItem(n.refreshToken, N), localStorage.setItem(
3692
+ localStorage.setItem(n.accessToken, E), localStorage.setItem(n.refreshToken, gt), localStorage.setItem(
3628
3693
  n.expiresAt,
3629
- (Date.now() + St * 1e3).toString()
3694
+ (Date.now() + xt * 1e3).toString()
3630
3695
  ), cleanupUrl(), localStorage.removeItem(n.codeVerifier);
3631
3696
  }
3632
3697
  localStorage.removeItem(n.state);
3633
3698
  const u = await getOrFetchValidToken(n, i);
3634
- let m;
3699
+ let f;
3635
3700
  if (typeof u == "string") {
3636
- const f = async () => {
3637
- if (m == null) {
3638
- m = (async () => await getOrFetchValidToken(n, i) ?? new Error("User not logged in."))();
3639
- const v = await m;
3640
- return m = void 0, v;
3701
+ const m = async () => {
3702
+ if (f == null) {
3703
+ f = (async () => await getOrFetchValidToken(n, i) ?? new Error("User not logged in."))();
3704
+ const w = await f;
3705
+ return f = void 0, w;
3641
3706
  }
3642
- return await m;
3707
+ return await f;
3643
3708
  };
3644
- let y;
3709
+ let p;
3645
3710
  return {
3646
3711
  loggedIn: !0,
3647
- getToken: f,
3712
+ getToken: m,
3648
3713
  getUserName: async () => {
3649
- if (y !== void 0)
3650
- return await y;
3651
- const { promise: v, resolve: w } = Promise.withResolvers();
3652
- y = v;
3653
- const b = await f();
3654
- if (b instanceof Error)
3655
- return w(b), await y;
3656
- const N = await neverThrowingFetch(
3714
+ if (p !== void 0)
3715
+ return await p;
3716
+ const { promise: w, resolve: x } = Promise.withResolvers();
3717
+ p = w;
3718
+ const E = await m();
3719
+ if (E instanceof Error)
3720
+ return x(E), await p;
3721
+ const gt = await neverThrowingFetch(
3657
3722
  `${API_ENDPOINT}/audiotool.auth.v1.AuthService/GetWhoami`,
3658
3723
  {
3659
3724
  method: "POST",
3660
3725
  headers: {
3661
- Authorization: `Bearer ${b}`,
3726
+ Authorization: `Bearer ${E}`,
3662
3727
  "Content-Type": "application/json"
3663
3728
  },
3664
3729
  body: JSON.stringify({})
3665
3730
  }
3666
3731
  );
3667
- if (N instanceof Error)
3668
- return w(N), await y;
3669
- if (!N.ok)
3670
- return w(new Error(`Failed to get user info: ${N.statusText}`)), await y;
3671
- const { whoami: St } = await N.json();
3672
- return console.debug("whoami", St), w((St == null ? void 0 : St.userName) ?? "Unknown User"), await y;
3732
+ if (gt instanceof Error)
3733
+ return x(gt), await p;
3734
+ if (!gt.ok)
3735
+ return x(new Error(`Failed to get user info: ${gt.statusText}`)), await p;
3736
+ const { whoami: xt } = await gt.json();
3737
+ return console.debug("whoami", xt), x((xt == null ? void 0 : xt.userName) ?? "Unknown User"), await p;
3673
3738
  },
3674
3739
  logout() {
3675
3740
  cleanUpLocalStorage(n), cleanupUrl(), window.location.reload();
@@ -3693,18 +3758,18 @@ const createPingNotifier = (i, e, t, n) => {
3693
3758
  }, redirectUserToLogin = async (i, e, t, n) => {
3694
3759
  const o = generateCodeVerifier();
3695
3760
  localStorage.setItem(i.codeVerifier, o);
3696
- const a = await generateCodeChallenge(o), c = crypto.getRandomValues(new Uint8Array(16)).join("");
3761
+ const r = await generateCodeChallenge(o), c = crypto.getRandomValues(new Uint8Array(16)).join("");
3697
3762
  localStorage.setItem(i.state, c);
3698
- const d = new URL(AUTHORIZATION_ENDPOINT);
3699
- d.search = new URLSearchParams({
3763
+ const l = new URL(AUTHORIZATION_ENDPOINT);
3764
+ l.search = new URLSearchParams({
3700
3765
  response_type: "code",
3701
3766
  client_id: e,
3702
3767
  scope: t,
3703
3768
  code_challenge_method: "S256",
3704
- code_challenge: a,
3769
+ code_challenge: r,
3705
3770
  redirect_uri: n,
3706
3771
  state: c
3707
- }).toString(), window.location.href = d.toString();
3772
+ }).toString(), window.location.href = l.toString();
3708
3773
  }, toError = (i, e) => (e = e ? `: ${e}` : "", new Error(`${i}${e}`)), generateCodeVerifier = () => {
3709
3774
  const i = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
3710
3775
  return crypto.getRandomValues(new Uint8Array(64)).reduce(
@@ -3720,8 +3785,8 @@ const createPingNotifier = (i, e, t, n) => {
3720
3785
  return;
3721
3786
  let n = !0;
3722
3787
  {
3723
- const f = localStorage.getItem(i.expiresAt);
3724
- n = f == null ? !0 : Date.now() >= parseInt(f) - 6e4;
3788
+ const m = localStorage.getItem(i.expiresAt);
3789
+ n = m == null ? !0 : Date.now() >= parseInt(m) - 6e4;
3725
3790
  }
3726
3791
  if (!n)
3727
3792
  return t;
@@ -3730,7 +3795,7 @@ const createPingNotifier = (i, e, t, n) => {
3730
3795
  cleanUpLocalStorage(i);
3731
3796
  return;
3732
3797
  }
3733
- const a = await neverThrowingFetch(TOKEN_ENDPOINT, {
3798
+ const r = await neverThrowingFetch(TOKEN_ENDPOINT, {
3734
3799
  method: "POST",
3735
3800
  headers: {
3736
3801
  "Content-Type": "application/x-www-form-urlencoded"
@@ -3741,17 +3806,18 @@ const createPingNotifier = (i, e, t, n) => {
3741
3806
  refresh_token: o
3742
3807
  })
3743
3808
  });
3744
- if (a instanceof Error)
3745
- return new Error(`Error during refresh token request: ${a.name}`, {
3746
- cause: a.message
3809
+ if (r instanceof Error)
3810
+ return new Error(`Error during refresh token request: ${r.name}`, {
3811
+ cause: r.message
3747
3812
  });
3748
- const { error: c, error_description: d, access_token: l, refresh_token: u, expires_in: m } = await a.json();
3749
- return c ? toError(c, d) : (localStorage.setItem(i.accessToken, l), localStorage.setItem(i.refreshToken, u), localStorage.setItem(
3813
+ const { error: c, error_description: l, access_token: d, refresh_token: u, expires_in: f } = await r.json();
3814
+ return c ? toError(c, l) : (localStorage.setItem(i.accessToken, d), localStorage.setItem(i.refreshToken, u), localStorage.setItem(
3750
3815
  i.expiresAt,
3751
- (Date.now() + m * 1e3).toString()
3752
- ), l);
3816
+ (Date.now() + f * 1e3).toString()
3817
+ ), d);
3753
3818
  };
3754
3819
  export {
3755
3820
  createAudiotoolClient,
3821
+ createOfflineDocument,
3756
3822
  getLoginStatus
3757
3823
  };