teamplay 0.5.0-alpha.2 → 0.5.0-alpha.21

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 (44) hide show
  1. package/dist/index.d.ts +22 -8
  2. package/dist/index.js +1 -4
  3. package/dist/orm/Aggregation.d.ts +6 -4
  4. package/dist/orm/Aggregation.js +39 -11
  5. package/dist/orm/Compat/SignalCompat.js +141 -409
  6. package/dist/orm/Compat/queryReadiness.d.ts +13 -5
  7. package/dist/orm/Compat/silentContext.js +4 -22
  8. package/dist/orm/Compat/startStopCompat.js +33 -0
  9. package/dist/orm/Doc.js +48 -3
  10. package/dist/orm/Query.d.ts +1 -0
  11. package/dist/orm/Query.js +67 -22
  12. package/dist/orm/Signal.d.ts +3 -3
  13. package/dist/orm/SignalBase.d.ts +27 -2
  14. package/dist/orm/SignalBase.js +296 -5
  15. package/dist/orm/addModel.d.ts +9 -2
  16. package/dist/orm/getSignal.js +0 -2
  17. package/dist/orm/index.d.ts +2 -2
  18. package/dist/orm/privateData.d.ts +7 -22
  19. package/dist/orm/signalMetadata.d.ts +1 -1
  20. package/dist/orm/signalMetadata.js +29 -3
  21. package/dist/orm/signalReads.d.ts +1 -1
  22. package/dist/orm/signalReads.js +7 -7
  23. package/dist/orm/signalSymbols.js +1 -1
  24. package/dist/orm/sub.d.ts +9 -1
  25. package/dist/orm/subscriptionGcDelay.js +2 -6
  26. package/dist/orm/types/baseMethods.d.ts +2 -1
  27. package/dist/orm/types/jsonSchema.d.ts +3 -3
  28. package/dist/orm/types/modelManifest.d.ts +12 -1
  29. package/dist/orm/types/query.d.ts +7 -1
  30. package/dist/orm/types/signal.d.ts +44 -15
  31. package/dist/react/convertToObserver.js +1 -4
  32. package/dist/react/promiseBatcher.js +1 -1
  33. package/dist/react/renderAttemptDestroyer.d.ts +0 -8
  34. package/dist/react/renderAttemptDestroyer.js +2 -28
  35. package/dist/react/trapRender.js +3 -3
  36. package/dist/react/useSub.d.ts +104 -5
  37. package/dist/react/useSub.js +191 -32
  38. package/dist/react/useSuspendMemo.js +1 -5
  39. package/dist/server.d.ts +1 -1
  40. package/package.json +16 -10
  41. package/dist/orm/Compat/hooksCompat.d.ts +0 -33
  42. package/dist/orm/Compat/hooksCompat.js +0 -360
  43. package/dist/react/compatComponentRegistry.d.ts +0 -4
  44. package/dist/react/compatComponentRegistry.js +0 -19
@@ -5,7 +5,7 @@ import { getRoot, ROOT, ROOT_ID, getRootSignal, GLOBAL_ROOT_ID, unregisterRootFi
5
5
  import { isPrivateMutationForbidden } from "../connection.js";
6
6
  import { docSubscriptions } from '../Doc.js';
7
7
  import { IS_QUERY, getQuerySignal, querySubscriptions } from '../Query.js';
8
- import { IS_AGGREGATION, aggregationSubscriptions, getAggregationSignal } from '../Aggregation.js';
8
+ import { AGGREGATIONS, IS_AGGREGATION, aggregationSubscriptions, getAggregationSignal } from '../Aggregation.js';
9
9
  import { getIdFieldsForSegments, isIdFieldPath, isPublicDocPath, normalizeIdFields, isPlainObject } from "../idFields.js";
10
10
  import { incrementPublic as _incrementPublic, arrayPushPublic as _arrayPushPublic, arrayUnshiftPublic as _arrayUnshiftPublic, arrayInsertPublic as _arrayInsertPublic, arrayPopPublic as _arrayPopPublic, arrayShiftPublic as _arrayShiftPublic, arrayRemovePublic as _arrayRemovePublic, arrayMovePublic as _arrayMovePublic, setPublicDocReplace as _setPublicDocReplace, stringInsertPublic as _stringInsertPublic, stringRemovePublic as _stringRemovePublic } from '../dataTree.js';
11
11
  import { on as onCustomEvent, removeListener as removeCustomEventListener } from './eventsCompat.js';
@@ -21,29 +21,15 @@ import disposeRootContext from "../disposeRootContext.js";
21
21
  import { arrayInsertPrivateData, arrayMovePrivateData, arrayPopPrivateData, arrayPushPrivateData, arrayRemovePrivateData, arrayShiftPrivateData, arrayUnshiftPrivateData, delPrivateData, setReplacePrivateData, stringInsertPrivateData, stringRemovePrivateData } from '../privateData.js';
22
22
  class SignalCompat extends Signal {
23
23
  static ID_FIELDS = ['_id', 'id'];
24
- static [GETTERS] = [...DEFAULT_GETTERS, 'at', 'scope', 'getCopy', 'getDeepCopy'];
25
- get root() {
26
- return this.scope();
27
- }
28
- path(subpath) {
29
- if (arguments.length > 1)
30
- throw Error('Signal.path() expects a single argument');
31
- if (arguments.length === 0)
32
- return super.path();
33
- const segments = parseAtSubpath(subpath, arguments.length, 'Signal.path()');
34
- if (segments.length === 0)
35
- return super.path();
36
- return [...this[SEGMENTS], ...segments].join('.');
37
- }
38
- at(subpath) {
39
- const segments = arguments.length > 1
40
- ? parseAtSegments(arguments, 'Signal.at()')
41
- : parseAtSubpath(subpath, arguments.length, 'Signal.at()');
42
- if (segments.length === 0)
43
- return this;
44
- return resolveRelativePathTarget(this, segments);
24
+ static [GETTERS] = DEFAULT_GETTERS;
25
+ path() {
26
+ if (arguments.length > 0)
27
+ throw Error('Signal.path() does not accept any arguments');
28
+ return super.path();
45
29
  }
46
30
  getId() {
31
+ if (isAggregationValuePath(this[SEGMENTS]))
32
+ return super.getId();
47
33
  const $target = resolveRefSignal(this);
48
34
  if ($target !== this)
49
35
  return $target.getId();
@@ -55,19 +41,15 @@ class SignalCompat extends Signal {
55
41
  return $target.getCollection();
56
42
  return super.getCollection();
57
43
  }
58
- getCopy(subpath) {
59
- if (arguments.length > 1)
60
- throw Error('Signal.getCopy() expects a single argument');
61
- const segments = parseAtSubpath(subpath, arguments.length, 'Signal.getCopy()');
62
- const value = getSignalValueAt(this, segments);
63
- return shallowCopy(value);
44
+ getCopy() {
45
+ if (arguments.length > 0)
46
+ throw Error('Signal.getCopy() does not accept any arguments');
47
+ return shallowCopy(this.get());
64
48
  }
65
- getDeepCopy(subpath) {
66
- if (arguments.length > 1)
67
- throw Error('Signal.getDeepCopy() expects a single argument');
68
- const segments = parseAtSubpath(subpath, arguments.length, 'Signal.getDeepCopy()');
69
- const value = getSignalValueAt(this, segments);
70
- return deepCopy(value);
49
+ getDeepCopy() {
50
+ if (arguments.length > 0)
51
+ throw Error('Signal.getDeepCopy() does not accept any arguments');
52
+ return deepCopy(this.get());
71
53
  }
72
54
  query(collection, params, options) {
73
55
  if (arguments.length < 1 || arguments.length > 3)
@@ -136,60 +118,37 @@ class SignalCompat extends Signal {
136
118
  return createSilentSignalWrapper(this, enabled);
137
119
  }
138
120
  get() {
139
- if (arguments.length > 1) {
140
- const segments = parseAtSegments(arguments, 'Signal.get()');
141
- const $target = resolveRelativePathTarget(this, segments);
142
- return Signal.prototype.get.call($target);
143
- }
144
- if (arguments.length === 1) {
145
- if (arguments[0] == null) {
146
- return Signal.prototype.get.apply(this, []);
147
- }
148
- const segments = parseAtSubpath(arguments[0], 1, 'Signal.get()');
149
- const $target = resolveRelativePathTarget(this, segments);
150
- return Signal.prototype.get.call($target);
151
- }
121
+ if (arguments.length > 0)
122
+ throw Error('Signal.get() does not accept any arguments');
152
123
  return Signal.prototype.get.apply(this, arguments);
153
124
  }
154
125
  peek() {
155
- if (arguments.length > 1) {
156
- const segments = parseAtSegments(arguments, 'Signal.peek()');
157
- const $target = resolveRelativePathTarget(this, segments);
158
- return Signal.prototype.peek.call($target);
159
- }
160
- if (arguments.length === 1) {
161
- if (arguments[0] == null) {
162
- const $target = resolveRefSignal(this);
163
- if ($target !== this)
164
- return Signal.prototype.peek.apply($target, []);
165
- return Signal.prototype.peek.apply(this, []);
166
- }
167
- const segments = parseAtSubpath(arguments[0], 1, 'Signal.peek()');
168
- const $target = resolveRelativePathTarget(this, segments);
169
- return Signal.prototype.peek.call($target);
170
- }
126
+ if (arguments.length > 0)
127
+ throw Error('Signal.peek() does not accept any arguments');
171
128
  const $target = resolveRefSignal(this);
172
129
  if ($target !== this)
173
130
  return Signal.prototype.peek.apply($target, arguments);
174
131
  return Signal.prototype.peek.apply(this, arguments);
175
132
  }
176
- async set(path, value) {
133
+ async set(value) {
177
134
  const forwarded = forwardRef(this, 'set', arguments);
178
135
  if (forwarded)
179
136
  return forwarded;
180
- if (arguments.length > 2)
181
- throw Error('Signal.set() expects one or two arguments');
182
- let segments = [];
183
- if (arguments.length === 2) {
184
- segments = parseAtSubpath(path, 1, 'Signal.set()');
185
- }
186
- else if (arguments.length === 1) {
187
- value = path;
188
- }
189
- const $target = resolveRelativePathTarget(this, segments);
137
+ if (arguments.length > 1)
138
+ throw Error('Signal.set() expects a single argument');
190
139
  if (value === undefined)
191
- return Signal.prototype.set.call($target, value);
192
- return setReplaceOnSignal($target, value);
140
+ return Signal.prototype.set.call(this, value);
141
+ return setReplaceOnSignal(this, value);
142
+ }
143
+ async setReplace(value) {
144
+ const forwarded = forwardRef(this, 'setReplace', arguments);
145
+ if (forwarded)
146
+ return forwarded;
147
+ if (arguments.length > 1)
148
+ throw Error('Signal.setReplace() expects a single argument');
149
+ if (value === undefined)
150
+ return Signal.prototype.set.call(this, value);
151
+ return setReplaceOnSignal(this, value);
193
152
  }
194
153
  async add(collectionOrValue, value) {
195
154
  const isRoot = this[SEGMENTS].length === 0;
@@ -207,102 +166,56 @@ class SignalCompat extends Signal {
207
166
  throw Error('Signal.add() expects a single argument');
208
167
  return Signal.prototype.add.call(this, collectionOrValue);
209
168
  }
210
- async setNull(path, value) {
169
+ async setNull(value) {
211
170
  const forwarded = forwardRef(this, 'setNull', arguments);
212
171
  if (forwarded)
213
172
  return forwarded;
214
- if (arguments.length > 2)
215
- throw Error('Signal.setNull() expects one or two arguments');
216
- let segments = [];
217
- if (arguments.length === 2) {
218
- segments = parseAtSubpath(path, 1, 'Signal.setNull()');
219
- }
220
- else if (arguments.length === 1) {
221
- value = path;
222
- }
223
- const $target = resolveRelativePathTarget(this, segments);
224
- if ($target.get() != null)
173
+ if (arguments.length > 1)
174
+ throw Error('Signal.setNull() expects a single argument');
175
+ if (this.get() != null)
225
176
  return;
226
- return setReplaceOnSignal($target, value);
177
+ return setReplaceOnSignal(this, value);
227
178
  }
228
- async create(path, value) {
179
+ async create(value) {
229
180
  const forwarded = forwardRef(this, 'create', arguments);
230
181
  if (forwarded)
231
182
  return forwarded;
232
- if (arguments.length > 2)
233
- throw Error('Signal.create() expects zero to two arguments');
234
- let segments = [];
235
- if (arguments.length === 2) {
236
- segments = parseAtSubpath(path, 1, 'Signal.create()');
237
- }
238
- else if (arguments.length === 1) {
239
- if (typeof path === 'string' || typeof path === 'number') {
240
- segments = parseAtSubpath(path, 1, 'Signal.create()');
241
- value = {};
242
- }
243
- else {
244
- value = path;
245
- }
246
- }
247
- else {
183
+ if (arguments.length > 1)
184
+ throw Error('Signal.create() expects zero or one argument');
185
+ if (arguments.length === 0) {
248
186
  value = {};
249
187
  }
250
- const $target = resolveRelativePathTarget(this, segments);
251
- ensureCreateTarget($target, 'Signal.create()');
252
- if ($target.get() != null) {
253
- throw Error(`Signal.create() may only be used on a non-existing document path. Path: ${$target.path()}`);
188
+ ensureCreateTarget(this, 'Signal.create()');
189
+ if (this.get() != null) {
190
+ throw Error(`Signal.create() may only be used on a non-existing document path. Path: ${this.path()}`);
254
191
  }
255
- return setReplaceOnSignal($target, value);
192
+ return setReplaceOnSignal(this, value);
256
193
  }
257
- async setDiffDeep(path, value) {
194
+ async setDiffDeep(value) {
258
195
  const forwarded = forwardRef(this, 'setDiffDeep', arguments);
259
196
  if (forwarded)
260
197
  return forwarded;
261
- if (arguments.length > 2)
262
- throw Error('Signal.setDiffDeep() expects one or two arguments');
263
- let segments = [];
264
- if (arguments.length === 2) {
265
- segments = parseAtSubpath(path, 1, 'Signal.setDiffDeep()');
266
- }
267
- else if (arguments.length === 1) {
268
- value = path;
269
- }
270
- const $target = resolveRelativePathTarget(this, segments);
271
- return runInBatch(() => setDiffDeepOnSignal($target, value));
198
+ if (arguments.length > 1)
199
+ throw Error('Signal.setDiffDeep() expects a single argument');
200
+ return runInBatch(() => setDiffDeepOnSignal(this, value));
272
201
  }
273
- async setDiff(path, value) {
202
+ async setDiff(value) {
274
203
  const forwarded = forwardRef(this, 'setDiff', arguments);
275
204
  if (forwarded)
276
205
  return forwarded;
277
- if (arguments.length > 2)
278
- throw Error('Signal.setDiff() expects one or two arguments');
279
- let segments = [];
280
- if (arguments.length === 2) {
281
- segments = parseAtSubpath(path, 1, 'Signal.setDiff()');
282
- }
283
- else if (arguments.length === 1) {
284
- value = path;
285
- }
286
- const $target = resolveRelativePathTarget(this, segments);
287
- const before = $target.peek();
206
+ if (arguments.length > 1)
207
+ throw Error('Signal.setDiff() expects a single argument');
208
+ const before = this.peek();
288
209
  if (racerEqualCompat(before, value))
289
210
  return;
290
- return setReplaceOnSignal($target, value);
211
+ return setReplaceOnSignal(this, value);
291
212
  }
292
- async setEach(path, object) {
213
+ async setEach(object) {
293
214
  const forwarded = forwardRef(this, 'setEach', arguments);
294
215
  if (forwarded)
295
216
  return forwarded;
296
- if (arguments.length > 2)
297
- throw Error('Signal.setEach() expects one or two arguments');
298
- let segments = [];
299
- if (arguments.length === 2) {
300
- segments = parseAtSubpath(path, 1, 'Signal.setEach()');
301
- }
302
- else if (arguments.length === 1) {
303
- object = path;
304
- }
305
- const $target = resolveRelativePathTarget(this, segments);
217
+ if (arguments.length > 1)
218
+ throw Error('Signal.setEach() expects a single argument');
306
219
  if (!object)
307
220
  return;
308
221
  if (typeof object !== 'object') {
@@ -311,126 +224,83 @@ class SignalCompat extends Signal {
311
224
  return runInBatch(async () => {
312
225
  const promises = [];
313
226
  for (const key of Object.keys(object)) {
314
- promises.push(SignalCompat.prototype.set.call($target[key], object[key]));
227
+ promises.push(SignalCompat.prototype.set.call(this[key], object[key]));
315
228
  }
316
229
  await Promise.all(promises);
317
230
  });
318
231
  }
319
- async del(path) {
232
+ async del() {
320
233
  const forwarded = forwardRef(this, 'del', arguments);
321
234
  if (forwarded)
322
235
  return forwarded;
323
- if (arguments.length > 1)
324
- throw Error('Signal.del() expects a single argument');
325
- const segments = parseAtSubpath(path, arguments.length, 'Signal.del()');
326
- const $target = resolveRelativePathTarget(this, segments);
236
+ if (arguments.length > 0)
237
+ throw Error('Signal.del() does not accept any arguments');
327
238
  try {
328
- return await Signal.prototype.del.call($target);
239
+ return await Signal.prototype.del.call(this);
329
240
  }
330
241
  catch (error) {
331
- if (isMissingPublicDocDeleteError($target, error))
242
+ if (isMissingPublicDocDeleteError(this, error))
332
243
  return;
333
244
  throw error;
334
245
  }
335
246
  }
336
- async increment(path, byNumber) {
247
+ async increment(byNumber) {
337
248
  const forwarded = forwardRef(this, 'increment', arguments);
338
249
  if (forwarded)
339
250
  return forwarded;
340
- if (arguments.length > 2)
341
- throw Error('Signal.increment() expects one or two arguments');
342
- let segments = [];
343
- if (arguments.length === 2) {
344
- segments = parseAtSubpath(path, 1, 'Signal.increment()');
345
- }
346
- else if (arguments.length === 1) {
347
- if (typeof path === 'number') {
348
- byNumber = path;
349
- }
350
- else {
351
- segments = parseAtSubpath(path, 1, 'Signal.increment()');
352
- }
251
+ if (arguments.length > 1)
252
+ throw Error('Signal.increment() expects zero or one argument');
253
+ if (byNumber != null && (typeof byNumber !== 'number' || !Number.isFinite(byNumber))) {
254
+ throw Error('Signal.increment() expects a numeric argument');
353
255
  }
354
- const $target = resolveRelativePathTarget(this, segments);
355
- return incrementOnSignal($target, byNumber);
256
+ return incrementOnSignal(this, byNumber);
356
257
  }
357
- async push(path, value) {
258
+ async push(value) {
358
259
  const forwarded = forwardRef(this, 'push', arguments);
359
260
  if (forwarded)
360
261
  return forwarded;
361
- if (arguments.length > 2)
362
- throw Error('Signal.push() expects one or two arguments');
363
- let segments = [];
364
- if (arguments.length === 2) {
365
- segments = parseAtSubpath(path, 1, 'Signal.push()');
366
- }
367
- else {
368
- value = path;
369
- }
370
- const $target = resolveRelativePathTarget(this, segments);
371
- return arrayPushOnSignal($target, value);
262
+ if (arguments.length > 1)
263
+ throw Error('Signal.push() expects a single argument');
264
+ return arrayPushOnSignal(this, value);
372
265
  }
373
- async unshift(path, value) {
266
+ async unshift(value) {
374
267
  const forwarded = forwardRef(this, 'unshift', arguments);
375
268
  if (forwarded)
376
269
  return forwarded;
377
- if (arguments.length > 2)
378
- throw Error('Signal.unshift() expects one or two arguments');
379
- let segments = [];
380
- if (arguments.length === 2) {
381
- segments = parseAtSubpath(path, 1, 'Signal.unshift()');
382
- }
383
- else {
384
- value = path;
385
- }
386
- const $target = resolveRelativePathTarget(this, segments);
387
- return arrayUnshiftOnSignal($target, value);
270
+ if (arguments.length > 1)
271
+ throw Error('Signal.unshift() expects a single argument');
272
+ return arrayUnshiftOnSignal(this, value);
388
273
  }
389
- async insert(path, index, values) {
274
+ async insert(index, values) {
390
275
  const forwarded = forwardRef(this, 'insert', arguments);
391
276
  if (forwarded)
392
277
  return forwarded;
393
278
  if (arguments.length < 2)
394
279
  throw Error('Not enough arguments for insert');
395
- if (arguments.length > 3)
396
- throw Error('Signal.insert() expects two or three arguments');
397
- let segments = [];
398
- if (arguments.length === 2) {
399
- index = arguments[0];
400
- values = arguments[1];
401
- }
402
- else {
403
- segments = parseAtSubpath(path, 1, 'Signal.insert()');
404
- index = arguments[1];
405
- values = arguments[2];
406
- }
280
+ if (arguments.length > 2)
281
+ throw Error('Signal.insert() expects two arguments');
407
282
  if (typeof index !== 'number' || !Number.isFinite(index)) {
408
283
  throw Error('Signal.insert() expects a numeric index');
409
284
  }
410
- const $target = resolveRelativePathTarget(this, segments);
411
- return arrayInsertOnSignal($target, index, values);
285
+ return arrayInsertOnSignal(this, index, values);
412
286
  }
413
- async pop(path) {
287
+ async pop() {
414
288
  const forwarded = forwardRef(this, 'pop', arguments);
415
289
  if (forwarded)
416
290
  return forwarded;
417
- if (arguments.length > 1)
418
- throw Error('Signal.pop() expects a single argument');
419
- const segments = parseAtSubpath(path, arguments.length, 'Signal.pop()');
420
- const $target = resolveRelativePathTarget(this, segments);
421
- return arrayPopOnSignal($target);
291
+ if (arguments.length > 0)
292
+ throw Error('Signal.pop() does not accept any arguments');
293
+ return arrayPopOnSignal(this);
422
294
  }
423
- async shift(path) {
295
+ async shift() {
424
296
  const forwarded = forwardRef(this, 'shift', arguments);
425
297
  if (forwarded)
426
298
  return forwarded;
427
- if (arguments.length > 1)
428
- throw Error('Signal.shift() expects a single argument');
429
- const segments = parseAtSubpath(path, arguments.length, 'Signal.shift()');
430
- const $target = resolveRelativePathTarget(this, segments);
431
- return arrayShiftOnSignal($target);
299
+ if (arguments.length > 0)
300
+ throw Error('Signal.shift() does not accept any arguments');
301
+ return arrayShiftOnSignal(this);
432
302
  }
433
- async remove(path, index, howMany) {
303
+ async remove(index, howMany) {
434
304
  const forwarded = forwardRef(this, 'remove', arguments);
435
305
  if (forwarded)
436
306
  return forwarded;
@@ -444,129 +314,53 @@ class SignalCompat extends Signal {
444
314
  const $target = resolveSignal($root, segments);
445
315
  return arrayRemoveOnSignal($target, +index, howMany);
446
316
  }
447
- if (arguments.length < 1)
448
- throw Error('Not enough arguments for remove');
449
- if (arguments.length > 3)
450
- throw Error('Signal.remove() expects one to three arguments');
451
- let segments = [];
452
- if (arguments.length === 1) {
453
- if (typeof path === 'number') {
454
- index = path;
455
- }
456
- else {
457
- segments = parseAtSubpath(path, 1, 'Signal.remove()');
458
- }
459
- }
460
- else if (arguments.length === 2) {
461
- if (typeof path === 'number') {
462
- index = path;
463
- howMany = arguments[1];
464
- }
465
- else {
466
- segments = parseAtSubpath(path, 1, 'Signal.remove()');
467
- index = arguments[1];
468
- }
469
- }
470
- else {
471
- segments = parseAtSubpath(path, 1, 'Signal.remove()');
472
- index = arguments[1];
473
- howMany = arguments[2];
474
- }
475
- if (index == null && segments.length && typeof segments[segments.length - 1] === 'number') {
476
- index = segments.pop();
477
- }
317
+ if (arguments.length > 2)
318
+ throw Error('Signal.remove() expects zero to two arguments');
478
319
  if (typeof index !== 'number' || !Number.isFinite(index)) {
479
320
  throw Error('Signal.remove() expects a numeric index');
480
321
  }
481
- const $target = resolveRelativePathTarget(this, segments);
482
- return arrayRemoveOnSignal($target, index, howMany);
322
+ return arrayRemoveOnSignal(this, index, howMany);
483
323
  }
484
- async move(path, from, to, howMany) {
324
+ async move(from, to, howMany) {
485
325
  const forwarded = forwardRef(this, 'move', arguments);
486
326
  if (forwarded)
487
327
  return forwarded;
488
328
  if (arguments.length < 2)
489
329
  throw Error('Not enough arguments for move');
490
- if (arguments.length > 4)
491
- throw Error('Signal.move() expects two to four arguments');
492
- let segments = [];
493
- if (arguments.length === 2) {
494
- from = arguments[0];
495
- to = arguments[1];
496
- }
497
- else if (arguments.length === 3) {
498
- if (typeof path === 'number') {
499
- from = arguments[0];
500
- to = arguments[1];
501
- howMany = arguments[2];
502
- }
503
- else {
504
- segments = parseAtSubpath(path, 1, 'Signal.move()');
505
- from = arguments[1];
506
- to = arguments[2];
507
- }
508
- }
509
- else {
510
- segments = parseAtSubpath(path, 1, 'Signal.move()');
511
- from = arguments[1];
512
- to = arguments[2];
513
- howMany = arguments[3];
514
- }
330
+ if (arguments.length > 3)
331
+ throw Error('Signal.move() expects two or three arguments');
515
332
  if (typeof from !== 'number' || !Number.isFinite(from) || typeof to !== 'number' || !Number.isFinite(to)) {
516
333
  throw Error('Signal.move() expects numeric from/to');
517
334
  }
518
- const $target = resolveRelativePathTarget(this, segments);
519
- return arrayMoveOnSignal($target, from, to, howMany);
335
+ return arrayMoveOnSignal(this, from, to, howMany);
520
336
  }
521
- async stringInsert(path, index, text) {
337
+ async stringInsert(index, text) {
522
338
  const forwarded = forwardRef(this, 'stringInsert', arguments);
523
339
  if (forwarded)
524
340
  return forwarded;
525
341
  if (arguments.length < 2)
526
342
  throw Error('Not enough arguments for stringInsert');
527
- if (arguments.length > 3)
528
- throw Error('Signal.stringInsert() expects two or three arguments');
529
- let segments = [];
530
- if (arguments.length === 2) {
531
- index = arguments[0];
532
- text = arguments[1];
533
- }
534
- else {
535
- segments = parseAtSubpath(path, 1, 'Signal.stringInsert()');
536
- index = arguments[1];
537
- text = arguments[2];
538
- }
343
+ if (arguments.length > 2)
344
+ throw Error('Signal.stringInsert() expects two arguments');
539
345
  if (typeof index !== 'number' || !Number.isFinite(index)) {
540
346
  throw Error('Signal.stringInsert() expects a numeric index');
541
347
  }
542
- const $target = resolveRelativePathTarget(this, segments);
543
- return stringInsertOnSignal($target, index, text);
348
+ return stringInsertOnSignal(this, index, text);
544
349
  }
545
- async stringRemove(path, index, howMany) {
350
+ async stringRemove(index, howMany) {
546
351
  const forwarded = forwardRef(this, 'stringRemove', arguments);
547
352
  if (forwarded)
548
353
  return forwarded;
549
354
  if (arguments.length < 2)
550
355
  throw Error('Not enough arguments for stringRemove');
551
- if (arguments.length > 3)
552
- throw Error('Signal.stringRemove() expects two or three arguments');
553
- let segments = [];
554
- if (arguments.length === 2) {
555
- index = arguments[0];
556
- howMany = arguments[1];
557
- }
558
- else {
559
- segments = parseAtSubpath(path, 1, 'Signal.stringRemove()');
560
- index = arguments[1];
561
- howMany = arguments[2];
562
- }
356
+ if (arguments.length > 2)
357
+ throw Error('Signal.stringRemove() expects two arguments');
563
358
  if (typeof index !== 'number' || !Number.isFinite(index)) {
564
359
  throw Error('Signal.stringRemove() expects a numeric index');
565
360
  }
566
361
  if (howMany == null)
567
362
  howMany = 1;
568
- const $target = resolveRelativePathTarget(this, segments);
569
- return stringRemoveOnSignal($target, index, howMany);
363
+ return stringRemoveOnSignal(this, index, howMany);
570
364
  }
571
365
  async assign(value) {
572
366
  const forwarded = forwardRef(this, 'assign', arguments);
@@ -626,63 +420,50 @@ class SignalCompat extends Signal {
626
420
  return removeCustomEventListener(eventName, handler);
627
421
  }
628
422
  ref(path, target, options) {
629
- if (arguments.length > 3)
630
- throw Error('Signal.ref() expects one to three arguments');
631
- let $from = this;
423
+ if (arguments.length < 1 || arguments.length > 2)
424
+ throw Error('Signal.ref() expects one or two arguments');
632
425
  let $to;
633
426
  if (arguments.length === 1) {
634
427
  $to = resolveRefTarget(this, path, 'Signal.ref()');
635
428
  }
636
- else if (arguments.length === 2) {
637
- if (isSignalLike(target) || typeof target === 'string') {
638
- const segments = parseAtSubpath(path, 1, 'Signal.ref()');
639
- $from = resolveSignal(this, segments);
640
- $to = resolveRefTarget(this, target, 'Signal.ref()');
641
- }
642
- else {
643
- $to = resolveRefTarget(this, path, 'Signal.ref()');
644
- options = target;
645
- }
646
- }
647
429
  else {
648
- const segments = parseAtSubpath(path, 1, 'Signal.ref()');
649
- $from = resolveSignal(this, segments);
650
- $to = resolveRefTarget(this, target, 'Signal.ref()');
430
+ $to = resolveRefTarget(this, path, 'Signal.ref()');
431
+ options = target;
651
432
  }
652
433
  if (!$to)
653
434
  throw Error('Signal.ref() expects a target path or signal');
654
- if ($from === $to)
655
- return $from;
656
- ensurePrivateRefSource($from, 'Signal.ref()');
657
- const store = getRefStore($from);
658
- const fromPath = $from.path();
435
+ if (this === $to)
436
+ return this;
437
+ ensurePrivateRefSource(this, 'Signal.ref()');
438
+ const store = getRefStore(this);
439
+ const fromPath = this.path();
659
440
  const existing = store.get(fromPath);
660
441
  if (existing)
661
442
  existing.stop();
662
443
  const mirrorOnly = !!($to?.[IS_QUERY] || $to?.[IS_AGGREGATION]);
663
- const { stop, onChange } = createRefLink($from, $to, { mirrorOnly, options });
444
+ const { stop, onChange } = createRefLink(this, $to, { mirrorOnly, options });
664
445
  store.set(fromPath, { stop });
665
- const fromRootId = (getRoot($from) || $from)?.[ROOT_ID];
446
+ const fromRootId = (getRoot(this) || this)?.[ROOT_ID];
666
447
  const toRootId = (getRoot($to) || $to)?.[ROOT_ID];
667
448
  if (!mirrorOnly) {
668
- $from[REF_TARGET] = $to;
669
- setRefLink(fromRootId, fromPath, $to.path(), $from[SEGMENTS], $to[SEGMENTS], {
449
+ this[REF_TARGET] = $to;
450
+ setRefLink(fromRootId, fromPath, $to.path(), this[SEGMENTS], $to[SEGMENTS], {
670
451
  mirrorOnly: false,
671
452
  fromRootId,
672
453
  toRootId
673
454
  });
674
455
  }
675
456
  else {
676
- setRefLink(fromRootId, fromPath, $to.path(), $from[SEGMENTS], $to[SEGMENTS], {
457
+ setRefLink(fromRootId, fromPath, $to.path(), this[SEGMENTS], $to[SEGMENTS], {
677
458
  mirrorOnly: true,
678
459
  onChange,
679
460
  fromRootId,
680
461
  toRootId
681
462
  });
682
- if ($from[REF_TARGET])
683
- delete $from[REF_TARGET];
463
+ if (this[REF_TARGET])
464
+ delete this[REF_TARGET];
684
465
  }
685
- return $from;
466
+ return this;
686
467
  }
687
468
  refExtra(path) {
688
469
  if (arguments.length !== 1)
@@ -707,40 +488,24 @@ class SignalCompat extends Signal {
707
488
  const $target = resolveSignal($root, segments);
708
489
  return SignalCompat.prototype.ref.call($target, this.ids);
709
490
  }
710
- removeRef(path) {
711
- if (arguments.length > 1)
712
- throw Error('Signal.removeRef() expects a single argument');
713
- let $from = this;
714
- if (arguments.length === 1) {
715
- const segments = parseAtSubpath(path, 1, 'Signal.removeRef()');
716
- $from = resolveSignal(this, segments);
717
- }
718
- const store = getRefStore($from);
719
- const fromPath = $from.path();
491
+ removeRef() {
492
+ if (arguments.length > 0)
493
+ throw Error('Signal.removeRef() does not accept any arguments');
494
+ const store = getRefStore(this);
495
+ const fromPath = this.path();
720
496
  const existing = store.get(fromPath);
721
497
  if (existing) {
722
498
  existing.stop();
723
499
  store.delete(fromPath);
724
500
  }
725
- const fromRootId = (getRoot($from) || $from)?.[ROOT_ID];
501
+ const fromRootId = (getRoot(this) || this)?.[ROOT_ID];
726
502
  removeRefLink(fromRootId, fromPath);
727
- const $target = resolveRefSignal($from);
728
- if ($target !== $from) {
729
- setDiffDeepBypassRef($from, deepCopy($target.get()));
503
+ const $target = resolveRefSignal(this);
504
+ if ($target !== this) {
505
+ setDiffDeepBypassRef(this, deepCopy($target.get()));
730
506
  }
731
- if ($from[REF_TARGET])
732
- delete $from[REF_TARGET];
733
- }
734
- scope(path) {
735
- const $root = getRoot(this) || this;
736
- if (arguments.length === 0)
737
- return $root;
738
- const segments = arguments.length > 1
739
- ? parseAtSegments(arguments, 'Signal.scope()')
740
- : parseAtSubpath(path, arguments.length, 'Signal.scope()');
741
- if (segments.length === 0)
742
- return $root;
743
- return resolveRelativePathTarget($root, segments);
507
+ if (this[REF_TARGET])
508
+ delete this[REF_TARGET];
744
509
  }
745
510
  }
746
511
  const SILENT_WRAPPER = Symbol('compat silent wrapper');
@@ -849,6 +614,11 @@ function readRefValue($signal) {
849
614
  throw err;
850
615
  }
851
616
  }
617
+ function isAggregationValuePath(segments) {
618
+ return Array.isArray(segments) &&
619
+ segments.length >= 3 &&
620
+ segments[0] === AGGREGATIONS;
621
+ }
852
622
  function resolveRefSignal($signal) {
853
623
  const directTarget = resolveRefSignalSafe($signal);
854
624
  if (directTarget && directTarget !== $signal)
@@ -935,22 +705,6 @@ function parseAtSubpath(subpath, argsLength, methodName) {
935
705
  return [subpath];
936
706
  throw Error(`${methodName} expects a string or integer argument`);
937
707
  }
938
- function parseAtSegments(args, methodName) {
939
- const segments = [];
940
- for (const arg of Array.from(args)) {
941
- if (typeof arg === 'string') {
942
- const parts = arg.split('.').filter(Boolean);
943
- segments.push(...parts);
944
- continue;
945
- }
946
- if (typeof arg === 'number' && Number.isFinite(arg) && Number.isInteger(arg)) {
947
- segments.push(arg);
948
- continue;
949
- }
950
- throw Error(`${methodName} expects string or integer path segments`);
951
- }
952
- return segments;
953
- }
954
708
  function resolveSignal($signal, segments) {
955
709
  let $cursor = $signal;
956
710
  for (const segment of segments) {
@@ -958,24 +712,6 @@ function resolveSignal($signal, segments) {
958
712
  }
959
713
  return $cursor;
960
714
  }
961
- function resolveSignalWithRefs($signal, relativeSegments) {
962
- const baseSegments = Array.isArray($signal?.[SEGMENTS]) ? $signal[SEGMENTS] : [];
963
- const absoluteSegments = baseSegments.concat(relativeSegments);
964
- const resolvedSegments = resolveRefSegmentsSafe(absoluteSegments, (getRoot($signal) || $signal)?.[ROOT_ID]);
965
- if (!resolvedSegments)
966
- return resolveSignal($signal, relativeSegments);
967
- // Signals created through root functions can carry a raw root in [ROOT].
968
- // For path-based ref writes we need proxy traversal semantics.
969
- const $root = getRoot($signal) || $signal;
970
- const $traversalRoot = getRoot($root) || $root;
971
- return resolveSignal($traversalRoot, resolvedSegments);
972
- }
973
- function resolveRelativePathTarget($signal, relativeSegments) {
974
- if (!Array.isArray(relativeSegments) || relativeSegments.length === 0) {
975
- return resolveSignal($signal, []);
976
- }
977
- return resolveSignalWithRefs($signal, relativeSegments);
978
- }
979
715
  function isMissingPublicDocDeleteError($signal, error) {
980
716
  const segments = $signal?.[SEGMENTS];
981
717
  if (!Array.isArray(segments) || segments.length < 2)
@@ -1175,10 +911,6 @@ function deepEqualCompat(left, right) {
1175
911
  function racerEqualCompat(left, right) {
1176
912
  return left === right || (Number.isNaN(left) && Number.isNaN(right));
1177
913
  }
1178
- function getSignalValueAt($signal, segments) {
1179
- const $target = resolveRelativePathTarget($signal, segments);
1180
- return $target.get();
1181
- }
1182
914
  async function setReplaceOnSignal($signal, value) {
1183
915
  const segments = $signal[SEGMENTS];
1184
916
  if (segments.length === 0)