teamplay 0.5.0-alpha.8 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/config.d.ts +2 -0
- package/dist/config.js +1 -0
- package/dist/connect/index.d.ts +1 -1
- package/dist/connect/index.js +6 -2
- package/dist/connect/offline/index.d.ts +1 -1
- package/dist/connect/offline/index.js +8 -4
- package/dist/connect/offline/react-native.d.ts +1 -1
- package/dist/connect/offline/web.d.ts +1 -1
- package/dist/connect/test.d.ts +1 -1
- package/dist/connect/test.js +5 -1
- package/dist/index.d.ts +9 -5
- package/dist/index.js +6 -5
- package/dist/orm/$.js +1 -1
- package/dist/orm/Aggregation.d.ts +5 -3
- package/dist/orm/Aggregation.js +39 -15
- package/dist/orm/Doc.js +0 -55
- package/dist/orm/Query.d.ts +1 -0
- package/dist/orm/Query.js +25 -82
- package/dist/orm/Root.d.ts +4 -0
- package/dist/orm/Root.js +16 -0
- package/dist/orm/Signal.d.ts +0 -2
- package/dist/orm/Signal.js +1 -4
- package/dist/orm/SignalBase.d.ts +21 -1
- package/dist/orm/SignalBase.js +259 -56
- package/dist/orm/batchScheduler.d.ts +7 -7
- package/dist/orm/connection.d.ts +0 -4
- package/dist/orm/connection.js +0 -12
- package/dist/orm/dataTree.d.ts +12 -12
- package/dist/orm/dataTree.js +55 -107
- package/dist/orm/disposeRootContext.js +0 -14
- package/dist/orm/events.d.ts +6 -0
- package/dist/orm/events.js +48 -0
- package/dist/orm/getSignal.d.ts +1 -1
- package/dist/orm/getSignal.js +4 -33
- package/dist/orm/idFields.d.ts +10 -1
- package/dist/orm/idFields.js +102 -14
- package/dist/orm/index.d.ts +2 -0
- package/dist/orm/index.js +1 -0
- package/dist/orm/initModels.js +1 -1
- package/dist/orm/privateData.d.ts +7 -22
- package/dist/orm/privateData.js +20 -1
- package/dist/orm/queryReadiness.d.ts +13 -0
- package/dist/orm/{Compat/queryReadiness.js → queryReadiness.js} +10 -10
- package/dist/orm/reaction.d.ts +11 -0
- package/dist/orm/reaction.js +47 -0
- package/dist/orm/rootContext.d.ts +0 -16
- package/dist/orm/rootContext.js +0 -28
- package/dist/orm/signalMetadata.js +3 -3
- package/dist/orm/signalReads.js +3 -9
- package/dist/orm/signalStorageMutations.d.ts +0 -2
- package/dist/orm/signalStorageMutations.js +0 -9
- package/dist/orm/signalSymbols.js +1 -1
- package/dist/orm/signalValueMutations.d.ts +1 -1
- package/dist/orm/signalValueMutations.js +0 -3
- package/dist/orm/sub.d.ts +12 -7
- package/dist/orm/sub.js +87 -30
- package/dist/orm/subscriptionGcDelay.js +2 -6
- package/dist/react/convertToObserver.js +1 -4
- package/dist/react/promiseBatcher.js +1 -1
- package/dist/react/renderAttemptDestroyer.d.ts +0 -8
- package/dist/react/renderAttemptDestroyer.js +2 -28
- package/dist/react/trapRender.js +3 -3
- package/dist/react/useSub.d.ts +86 -5
- package/dist/react/useSub.js +191 -32
- package/dist/react/useSuspendMemo.js +1 -5
- package/dist/server.d.ts +2 -3
- package/dist/server.js +5 -3
- package/package.json +16 -14
- package/dist/orm/Compat/SignalCompat.d.ts +0 -3
- package/dist/orm/Compat/SignalCompat.js +0 -1267
- package/dist/orm/Compat/eventsCompat.d.ts +0 -3
- package/dist/orm/Compat/eventsCompat.js +0 -73
- package/dist/orm/Compat/hooksCompat.d.ts +0 -33
- package/dist/orm/Compat/hooksCompat.js +0 -360
- package/dist/orm/Compat/modelEvents.d.ts +0 -6
- package/dist/orm/Compat/modelEvents.js +0 -228
- package/dist/orm/Compat/queryReadiness.d.ts +0 -5
- package/dist/orm/Compat/refFallback.d.ts +0 -13
- package/dist/orm/Compat/refFallback.js +0 -65
- package/dist/orm/Compat/refRegistry.d.ts +0 -6
- package/dist/orm/Compat/refRegistry.js +0 -54
- package/dist/orm/Compat/silentContext.d.ts +0 -5
- package/dist/orm/Compat/silentContext.js +0 -48
- package/dist/orm/Compat/startStopCompat.d.ts +0 -3
- package/dist/orm/Compat/startStopCompat.js +0 -217
- package/dist/orm/compatEnv.d.ts +0 -1
- package/dist/orm/compatEnv.js +0 -4
- package/dist/react/compatComponentRegistry.d.ts +0 -4
- package/dist/react/compatComponentRegistry.js +0 -19
- /package/dist/orm/{Reaction.d.ts → reactionSubscriptions.d.ts} +0 -0
- /package/dist/orm/{Reaction.js → reactionSubscriptions.js} +0 -0
package/dist/orm/SignalBase.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ARRAY_METHOD, DEFAULT_GETTERS, GET, GETTERS, SEGMENTS } from './signalS
|
|
|
2
2
|
export { SEGMENTS, ARRAY_METHOD, GET, GETTERS, DEFAULT_GETTERS };
|
|
3
3
|
export declare class Signal<TValue = unknown> extends Function {
|
|
4
4
|
/** Fields that are treated as document ids and mirror the document id segment. */
|
|
5
|
-
static ID_FIELDS:
|
|
5
|
+
static get ID_FIELDS(): import("./idFields.js").IdFields;
|
|
6
6
|
/** Method names that keep method binding priority over child signal dot access. */
|
|
7
7
|
static [GETTERS]: string[];
|
|
8
8
|
/** Association metadata registered for this model class. */
|
|
@@ -45,6 +45,8 @@ export declare class Signal<TValue = unknown> extends Function {
|
|
|
45
45
|
* @param fn Function to execute inside the batch.
|
|
46
46
|
*/
|
|
47
47
|
batch<TResult>(fn: () => TResult): TResult;
|
|
48
|
+
close(): Promise<void>;
|
|
49
|
+
close(callback: (err?: unknown) => void): void;
|
|
48
50
|
/**
|
|
49
51
|
* Internal read hook used by `.get()` and `.peek()`.
|
|
50
52
|
* @param method Storage read function to use for the current signal path.
|
|
@@ -54,6 +56,12 @@ export declare class Signal<TValue = unknown> extends Function {
|
|
|
54
56
|
get(): TValue;
|
|
55
57
|
/** Return document ids for a query or aggregation signal. */
|
|
56
58
|
getIds(): string[];
|
|
59
|
+
/** Return query extra data, aggregation data, or undefined for ordinary signals. */
|
|
60
|
+
getExtra(): unknown;
|
|
61
|
+
/** Return a shallow copy of the current value. */
|
|
62
|
+
getCopy(): TValue;
|
|
63
|
+
/** Return a deep copy of the current value. */
|
|
64
|
+
getDeepCopy(): TValue;
|
|
57
65
|
/** Read the current value without tracking it for reactive rendering. */
|
|
58
66
|
peek(): TValue;
|
|
59
67
|
/** Return the document id represented by this document signal. */
|
|
@@ -105,6 +113,18 @@ export declare class Signal<TValue = unknown> extends Function {
|
|
|
105
113
|
* @param value New value to store at this signal path.
|
|
106
114
|
*/
|
|
107
115
|
setReplace(value: TValue): Promise<void>;
|
|
116
|
+
/** Set the current value only when it is null or undefined. */
|
|
117
|
+
setNull(value: TValue): Promise<void>;
|
|
118
|
+
/** Replace the current value unless it is exactly equal to the new value. */
|
|
119
|
+
setDiff(value: TValue): Promise<void>;
|
|
120
|
+
/** Recursively diff objects and arrays at the current signal path. */
|
|
121
|
+
setDiffDeep(value: TValue): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Set multiple object fields with per-key replace semantics.
|
|
124
|
+
* Unlike assign(), null is stored as null and undefined follows setReplace() semantics.
|
|
125
|
+
* @param object Object containing fields to set.
|
|
126
|
+
*/
|
|
127
|
+
setEach(object: NonNullable<TValue> extends object ? Partial<NonNullable<TValue>> : never): Promise<void>;
|
|
108
128
|
/**
|
|
109
129
|
* Set multiple object fields at once. Fields set to `null` or `undefined` are deleted.
|
|
110
130
|
* @param value Object containing fields to set or delete.
|
package/dist/orm/SignalBase.js
CHANGED
|
@@ -12,18 +12,16 @@
|
|
|
12
12
|
* 3. If extremely late bindings are enabled, to prevent name collisions when accessing fields
|
|
13
13
|
* in the raw data tree which have the same name as signal's methods
|
|
14
14
|
*/
|
|
15
|
+
import { raw } from '@nx-js/observer-util';
|
|
16
|
+
import arrayDiff from 'arraydiff';
|
|
15
17
|
import uuid from '@teamplay/utils/uuid';
|
|
16
18
|
import { get as _get, setPublicDoc as _setPublicDoc, setPublicDocReplace as _setPublicDocReplace, del as _del, dataTreeRaw, getRaw, getLogicalRootSnapshot, incrementPublic as _incrementPublic, arrayPushPublic as _arrayPushPublic, arrayUnshiftPublic as _arrayUnshiftPublic, arrayInsertPublic as _arrayInsertPublic, arrayPopPublic as _arrayPopPublic, arrayShiftPublic as _arrayShiftPublic, arrayRemovePublic as _arrayRemovePublic, arrayMovePublic as _arrayMovePublic, stringInsertPublic as _stringInsertPublic, stringRemovePublic as _stringRemovePublic } from './dataTree.js';
|
|
17
19
|
import getSignal, { rawSignal } from "./getSignal.js";
|
|
18
20
|
import { docSubscriptions } from './Doc.js';
|
|
19
21
|
import { IS_QUERY, HASH, QUERIES } from './Query.js';
|
|
20
|
-
import { AGGREGATIONS, getAggregationCollectionName, getAggregationDocId } from './Aggregation.js';
|
|
21
|
-
import { ROOT_FUNCTION, ROOT_ID, getRoot } from "./Root.js";
|
|
22
|
-
import {
|
|
23
|
-
import { DEFAULT_ID_FIELDS, getIdFieldsForSegments, isIdFieldPath, isPublicDocPath, normalizeIdFields, prepareAddPayload, resolveAddDocId } from "./idFields.js";
|
|
24
|
-
import { isCompatEnv } from './compatEnv.js';
|
|
25
|
-
import { resolveRefSegmentsSafe, resolveRefSignalSafe } from './Compat/refFallback.js';
|
|
26
|
-
import { compatStartOnRoot, compatStopOnRoot, joinScopePath } from './Compat/startStopCompat.js';
|
|
22
|
+
import { AGGREGATIONS, IS_AGGREGATION, getAggregationCollectionName, getAggregationDocId } from './Aggregation.js';
|
|
23
|
+
import { ROOT_FUNCTION, ROOT_ID, closeRootSignal, getRoot } from "./Root.js";
|
|
24
|
+
import { getDefaultIdFields, getIdFieldsForSegments, isIdFieldPath, isPlainObject, isPublicDocPath, normalizeIdFields, prepareAddPayload, resolveAddDocId } from "./idFields.js";
|
|
27
25
|
import { runInBatch } from './batchScheduler.js';
|
|
28
26
|
import { isPublicCollection } from "./signalPathKind.js";
|
|
29
27
|
import { ARRAY_METHOD, DEFAULT_GETTERS, GET, GETTERS, SEGMENTS } from "./signalSymbols.js";
|
|
@@ -81,7 +79,6 @@ const SIGNAL_READ_CONTEXT = {
|
|
|
81
79
|
const SIGNAL_VALUE_MUTATION_CONTEXT = {
|
|
82
80
|
getOwningRootId: getSignalOwningRootId,
|
|
83
81
|
isPublicCollection,
|
|
84
|
-
isPrivateMutationForbidden,
|
|
85
82
|
setPublicDoc: _setPublicDoc,
|
|
86
83
|
setPrivateData,
|
|
87
84
|
deletePublicDoc(segments) {
|
|
@@ -91,7 +88,9 @@ const SIGNAL_VALUE_MUTATION_CONTEXT = {
|
|
|
91
88
|
};
|
|
92
89
|
export class Signal extends Function {
|
|
93
90
|
/** Fields that are treated as document ids and mirror the document id segment. */
|
|
94
|
-
static ID_FIELDS
|
|
91
|
+
static get ID_FIELDS() {
|
|
92
|
+
return getDefaultIdFields();
|
|
93
|
+
}
|
|
95
94
|
/** Method names that keep method binding priority over child signal dot access. */
|
|
96
95
|
static [GETTERS] = DEFAULT_GETTERS;
|
|
97
96
|
/** Association metadata registered for this model class. */
|
|
@@ -181,6 +180,14 @@ export class Signal extends Function {
|
|
|
181
180
|
throw Error('Signal.batch() expects a function argument');
|
|
182
181
|
return runInBatch(fn);
|
|
183
182
|
}
|
|
183
|
+
close(callback) {
|
|
184
|
+
if (arguments.length > 1)
|
|
185
|
+
throw Error('Signal.close() expects zero or one argument');
|
|
186
|
+
if (callback != null && typeof callback !== 'function') {
|
|
187
|
+
throw Error('Signal.close() expects callback to be a function');
|
|
188
|
+
}
|
|
189
|
+
return callback ? closeRootSignal(this, callback) : closeRootSignal(this);
|
|
190
|
+
}
|
|
184
191
|
/**
|
|
185
192
|
* Internal read hook used by `.get()` and `.peek()`.
|
|
186
193
|
* @param method Storage read function to use for the current signal path.
|
|
@@ -202,6 +209,28 @@ export class Signal extends Function {
|
|
|
202
209
|
throw Error('Signal.getIds() does not accept any arguments');
|
|
203
210
|
return getSignalIds(this, SIGNAL_READ_CONTEXT);
|
|
204
211
|
}
|
|
212
|
+
/** Return query extra data, aggregation data, or undefined for ordinary signals. */
|
|
213
|
+
getExtra() {
|
|
214
|
+
if (arguments.length > 0)
|
|
215
|
+
throw Error('Signal.getExtra() does not accept any arguments');
|
|
216
|
+
if (this[IS_AGGREGATION])
|
|
217
|
+
return this.get();
|
|
218
|
+
if (this[IS_QUERY])
|
|
219
|
+
return this.extra.get();
|
|
220
|
+
return undefined;
|
|
221
|
+
}
|
|
222
|
+
/** Return a shallow copy of the current value. */
|
|
223
|
+
getCopy() {
|
|
224
|
+
if (arguments.length > 0)
|
|
225
|
+
throw Error('Signal.getCopy() does not accept any arguments');
|
|
226
|
+
return shallowCopy(this.get());
|
|
227
|
+
}
|
|
228
|
+
/** Return a deep copy of the current value. */
|
|
229
|
+
getDeepCopy() {
|
|
230
|
+
if (arguments.length > 0)
|
|
231
|
+
throw Error('Signal.getDeepCopy() does not accept any arguments');
|
|
232
|
+
return deepCopy(this.get());
|
|
233
|
+
}
|
|
205
234
|
/** Read the current value without tracking it for reactive rendering. */
|
|
206
235
|
peek() {
|
|
207
236
|
if (arguments.length > 0)
|
|
@@ -284,14 +313,52 @@ export class Signal extends Function {
|
|
|
284
313
|
}
|
|
285
314
|
return;
|
|
286
315
|
}
|
|
287
|
-
if (isPrivateMutationForbidden()) {
|
|
288
|
-
throw Error(`
|
|
289
|
-
Can't modify private collections data when 'publicOnly' is enabled.
|
|
290
|
-
On the server you can only work with public collections.
|
|
291
|
-
`);
|
|
292
|
-
}
|
|
293
316
|
setReplacePrivateData(getSignalOwningRootId(this), segments, nextValue);
|
|
294
317
|
}
|
|
318
|
+
/** Set the current value only when it is null or undefined. */
|
|
319
|
+
async setNull(value) {
|
|
320
|
+
if (arguments.length > 1)
|
|
321
|
+
throw Error('Signal.setNull() expects a single argument');
|
|
322
|
+
if (this.get() != null)
|
|
323
|
+
return;
|
|
324
|
+
await this.setReplace(value);
|
|
325
|
+
}
|
|
326
|
+
/** Replace the current value unless it is exactly equal to the new value. */
|
|
327
|
+
async setDiff(value) {
|
|
328
|
+
if (arguments.length > 1)
|
|
329
|
+
throw Error('Signal.setDiff() expects a single argument');
|
|
330
|
+
const before = this.peek();
|
|
331
|
+
if (racerEqual(before, value))
|
|
332
|
+
return;
|
|
333
|
+
await this.setReplace(value);
|
|
334
|
+
}
|
|
335
|
+
/** Recursively diff objects and arrays at the current signal path. */
|
|
336
|
+
async setDiffDeep(value) {
|
|
337
|
+
if (arguments.length > 1)
|
|
338
|
+
throw Error('Signal.setDiffDeep() expects a single argument');
|
|
339
|
+
await runInBatch(() => setDiffDeepOnSignal(this, value));
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Set multiple object fields with per-key replace semantics.
|
|
343
|
+
* Unlike assign(), null is stored as null and undefined follows setReplace() semantics.
|
|
344
|
+
* @param object Object containing fields to set.
|
|
345
|
+
*/
|
|
346
|
+
async setEach(object) {
|
|
347
|
+
if (arguments.length > 1)
|
|
348
|
+
throw Error('Signal.setEach() expects a single argument');
|
|
349
|
+
if (!object)
|
|
350
|
+
return;
|
|
351
|
+
if (typeof object !== 'object') {
|
|
352
|
+
throw Error('Signal.setEach() expects an object argument, got: ' + typeof object);
|
|
353
|
+
}
|
|
354
|
+
await runInBatch(async () => {
|
|
355
|
+
const promises = [];
|
|
356
|
+
for (const key of Object.keys(object)) {
|
|
357
|
+
promises.push(this[key].setReplace(object[key]));
|
|
358
|
+
}
|
|
359
|
+
await Promise.all(promises);
|
|
360
|
+
});
|
|
361
|
+
}
|
|
295
362
|
/**
|
|
296
363
|
* Set multiple object fields at once. Fields set to `null` or `undefined` are deleted.
|
|
297
364
|
* @param value Object containing fields to set or delete.
|
|
@@ -510,8 +577,10 @@ export class Signal extends Function {
|
|
|
510
577
|
async add(value) {
|
|
511
578
|
if (arguments.length > 1)
|
|
512
579
|
throw Error('Signal.add() expects a single argument');
|
|
513
|
-
const
|
|
514
|
-
const
|
|
580
|
+
const collection = this[SEGMENTS][0];
|
|
581
|
+
const collectionIdFields = getIdFieldsForSegments([collection, '']);
|
|
582
|
+
const id = resolveAddDocId(value, collectionIdFields, uuid);
|
|
583
|
+
const idFields = getIdFieldsForSegments([collection, id]);
|
|
515
584
|
await this[id].set(prepareAddPayload(value, idFields, id));
|
|
516
585
|
return id;
|
|
517
586
|
}
|
|
@@ -522,6 +591,177 @@ export class Signal extends Function {
|
|
|
522
591
|
await deleteSignalValue(this, SIGNAL_VALUE_MUTATION_CONTEXT);
|
|
523
592
|
}
|
|
524
593
|
}
|
|
594
|
+
async function setDiffDeepOnSignal($target, value) {
|
|
595
|
+
if ($target[SEGMENTS].length === 0)
|
|
596
|
+
throw Error('Can\'t set the root signal data');
|
|
597
|
+
await diffDeepOnSignal($target, $target.peek(), value);
|
|
598
|
+
}
|
|
599
|
+
async function diffDeepOnSignal($signal, before, after) {
|
|
600
|
+
if (before === after)
|
|
601
|
+
return;
|
|
602
|
+
if (Array.isArray(before) && Array.isArray(after)) {
|
|
603
|
+
const diff = arrayDiff(before, after, deepEqual);
|
|
604
|
+
if (!diff.length)
|
|
605
|
+
return;
|
|
606
|
+
const index = getSingleArrayReplacementIndex(diff);
|
|
607
|
+
if (index != null) {
|
|
608
|
+
await diffDeepOnSignal(getChildSignal($signal, index), before[index], after[index]);
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
await applyArrayDiff($signal, diff);
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
if (isDiffableObject(before, after)) {
|
|
615
|
+
const preservePath = $signal[SEGMENTS];
|
|
616
|
+
for (const key of Object.keys(before)) {
|
|
617
|
+
if (Object.prototype.hasOwnProperty.call(after, key))
|
|
618
|
+
continue;
|
|
619
|
+
await deleteForDiffDeep(getChildSignal($signal, key), preservePath);
|
|
620
|
+
}
|
|
621
|
+
for (const key of Object.keys(after)) {
|
|
622
|
+
await diffDeepOnSignal(getChildSignal($signal, key), before[key], after[key]);
|
|
623
|
+
}
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
await $signal.setReplace(after);
|
|
627
|
+
}
|
|
628
|
+
function isDiffableObject(before, after) {
|
|
629
|
+
if (!isPlainObject(before) || !isPlainObject(after))
|
|
630
|
+
return false;
|
|
631
|
+
if (isReactLike(before) || isReactLike(after))
|
|
632
|
+
return false;
|
|
633
|
+
return true;
|
|
634
|
+
}
|
|
635
|
+
function isReactLike(value) {
|
|
636
|
+
return !!(value && typeof value === 'object' && typeof value.$$typeof === 'symbol');
|
|
637
|
+
}
|
|
638
|
+
function getSingleArrayReplacementIndex(diff) {
|
|
639
|
+
if (!Array.isArray(diff) || diff.length !== 2)
|
|
640
|
+
return null;
|
|
641
|
+
const first = diff[0];
|
|
642
|
+
const second = diff[1];
|
|
643
|
+
if (first instanceof arrayDiff.RemoveDiff &&
|
|
644
|
+
second instanceof arrayDiff.InsertDiff &&
|
|
645
|
+
first.index === second.index &&
|
|
646
|
+
first.howMany === 1 &&
|
|
647
|
+
second.values.length === 1) {
|
|
648
|
+
return first.index;
|
|
649
|
+
}
|
|
650
|
+
return null;
|
|
651
|
+
}
|
|
652
|
+
async function applyArrayDiff($signal, diff) {
|
|
653
|
+
for (const item of diff) {
|
|
654
|
+
if (item instanceof arrayDiff.InsertDiff) {
|
|
655
|
+
await $signal.insert(item.index, item.values);
|
|
656
|
+
continue;
|
|
657
|
+
}
|
|
658
|
+
if (item instanceof arrayDiff.RemoveDiff) {
|
|
659
|
+
await $signal.remove(item.index, item.howMany);
|
|
660
|
+
continue;
|
|
661
|
+
}
|
|
662
|
+
if (item instanceof arrayDiff.MoveDiff) {
|
|
663
|
+
await $signal.move(item.from, item.to, item.howMany);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
async function deleteForDiffDeep($signal, preservePath) {
|
|
668
|
+
const segments = $signal[SEGMENTS];
|
|
669
|
+
const idFields = getIdFieldsForSegments(segments);
|
|
670
|
+
if (isIdFieldPath(segments, idFields))
|
|
671
|
+
return;
|
|
672
|
+
if (isPublicCollection(segments[0])) {
|
|
673
|
+
await $signal.del();
|
|
674
|
+
return;
|
|
675
|
+
}
|
|
676
|
+
delPrivateData(getSignalOwningRootId($signal), segments, { preservePath });
|
|
677
|
+
}
|
|
678
|
+
function getChildSignal($parent, key) {
|
|
679
|
+
return getSignal(getRoot($parent) || $parent, [...$parent[SEGMENTS], key]);
|
|
680
|
+
}
|
|
681
|
+
function deepEqual(left, right) {
|
|
682
|
+
if (left === right)
|
|
683
|
+
return true;
|
|
684
|
+
if (left == null || right == null)
|
|
685
|
+
return false;
|
|
686
|
+
if (typeof left !== 'object' || typeof right !== 'object')
|
|
687
|
+
return false;
|
|
688
|
+
if (Array.isArray(left) !== Array.isArray(right))
|
|
689
|
+
return false;
|
|
690
|
+
if (Array.isArray(left)) {
|
|
691
|
+
if (left.length !== right.length)
|
|
692
|
+
return false;
|
|
693
|
+
for (let i = 0; i < left.length; i++) {
|
|
694
|
+
if (!deepEqual(left[i], right[i]))
|
|
695
|
+
return false;
|
|
696
|
+
}
|
|
697
|
+
return true;
|
|
698
|
+
}
|
|
699
|
+
if (!isPlainObject(left) || !isPlainObject(right))
|
|
700
|
+
return false;
|
|
701
|
+
const leftKeys = Object.keys(left);
|
|
702
|
+
const rightKeys = Object.keys(right);
|
|
703
|
+
if (leftKeys.length !== rightKeys.length)
|
|
704
|
+
return false;
|
|
705
|
+
for (const key of leftKeys) {
|
|
706
|
+
if (!Object.prototype.hasOwnProperty.call(right, key))
|
|
707
|
+
return false;
|
|
708
|
+
if (!deepEqual(left[key], right[key]))
|
|
709
|
+
return false;
|
|
710
|
+
}
|
|
711
|
+
return true;
|
|
712
|
+
}
|
|
713
|
+
function racerEqual(left, right) {
|
|
714
|
+
return left === right || (Number.isNaN(left) && Number.isNaN(right));
|
|
715
|
+
}
|
|
716
|
+
function shallowCopy(value) {
|
|
717
|
+
const rawValue = raw(value);
|
|
718
|
+
if (Array.isArray(rawValue))
|
|
719
|
+
return rawValue.slice();
|
|
720
|
+
if (rawValue && typeof rawValue === 'object')
|
|
721
|
+
return { ...rawValue };
|
|
722
|
+
return rawValue;
|
|
723
|
+
}
|
|
724
|
+
function deepCopy(value) {
|
|
725
|
+
const rawValue = raw(value);
|
|
726
|
+
if (!rawValue || typeof rawValue !== 'object')
|
|
727
|
+
return rawValue;
|
|
728
|
+
if (typeof globalThis.structuredClone === 'function') {
|
|
729
|
+
try {
|
|
730
|
+
return globalThis.structuredClone(rawValue);
|
|
731
|
+
}
|
|
732
|
+
catch { }
|
|
733
|
+
}
|
|
734
|
+
return racerDeepCopy(rawValue);
|
|
735
|
+
}
|
|
736
|
+
// Racer-style deep copy:
|
|
737
|
+
// - Preserves prototypes by instantiating via `new value.constructor()`
|
|
738
|
+
// - Copies own enumerable props recursively
|
|
739
|
+
// - Keeps functions as-is (no cloning)
|
|
740
|
+
// - Handles Date by creating a new Date
|
|
741
|
+
// Limitations: does not handle cyclic refs, Map/Set/RegExp/TypedArray, non-enumerables.
|
|
742
|
+
function racerDeepCopy(value) {
|
|
743
|
+
if (value instanceof Date)
|
|
744
|
+
return new Date(value);
|
|
745
|
+
if (typeof value === 'object') {
|
|
746
|
+
if (value === null)
|
|
747
|
+
return null;
|
|
748
|
+
if (Array.isArray(value)) {
|
|
749
|
+
const array = [];
|
|
750
|
+
for (let i = value.length; i--;) {
|
|
751
|
+
array[i] = racerDeepCopy(value[i]);
|
|
752
|
+
}
|
|
753
|
+
return array;
|
|
754
|
+
}
|
|
755
|
+
const object = new value.constructor();
|
|
756
|
+
for (const key in value) {
|
|
757
|
+
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
758
|
+
object[key] = racerDeepCopy(value[key]);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
return object;
|
|
762
|
+
}
|
|
763
|
+
return value;
|
|
764
|
+
}
|
|
525
765
|
// dot syntax returns a child signal only if no such method or property exists
|
|
526
766
|
export const regularBindings = {
|
|
527
767
|
apply(signal, thisArg, argumentsList) {
|
|
@@ -538,8 +778,7 @@ export const regularBindings = {
|
|
|
538
778
|
return Reflect.apply(extremelyLateBindings.get, this, arguments);
|
|
539
779
|
}
|
|
540
780
|
};
|
|
541
|
-
const QUERY_METHODS = ['map', 'reduce', 'find', 'get', 'getIds', 'getExtra'
|
|
542
|
-
const AGGREGATION_ALLOWED_METHODS = ['subscribe', 'unsubscribe', 'fetch', 'unfetch', 'ref', 'removeRef', 'refExtra', 'refIds'];
|
|
781
|
+
const QUERY_METHODS = ['map', 'reduce', 'find', 'get', 'getIds', 'getExtra'];
|
|
543
782
|
// dot syntax always returns a child signal even if such method or property exists.
|
|
544
783
|
// The method is only called when the signal is explicitly called as a function,
|
|
545
784
|
// in which case we get the original method from the raw (non-proxied) parent signal
|
|
@@ -584,7 +823,7 @@ export const extremelyLateBindings = {
|
|
|
584
823
|
});
|
|
585
824
|
}
|
|
586
825
|
}
|
|
587
|
-
else if (!DEFAULT_GETTERS.includes(key)
|
|
826
|
+
else if (!DEFAULT_GETTERS.includes(key)) {
|
|
588
827
|
throw Error(ERRORS.aggregationSetter(segments, key));
|
|
589
828
|
}
|
|
590
829
|
}
|
|
@@ -592,42 +831,6 @@ export const extremelyLateBindings = {
|
|
|
592
831
|
const rawParent = rawSignal($parent);
|
|
593
832
|
if (key in rawParent)
|
|
594
833
|
return Reflect.apply(rawParent[key], $parent, argumentsList);
|
|
595
|
-
if (isCompatEnv()) {
|
|
596
|
-
const $resolvedParent = resolveRefSignalSafe($parent);
|
|
597
|
-
if ($resolvedParent && $resolvedParent !== $parent) {
|
|
598
|
-
const rawResolvedParent = rawSignal($resolvedParent);
|
|
599
|
-
if (rawResolvedParent && key in rawResolvedParent) {
|
|
600
|
-
return Reflect.apply(rawResolvedParent[key], $resolvedParent, argumentsList);
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
else {
|
|
604
|
-
const resolvedSegments = resolveRefSegmentsSafe(segments, (getRoot(signal) || signal)?.[ROOT_ID]);
|
|
605
|
-
if (resolvedSegments) {
|
|
606
|
-
const $resolvedByPath = getSignal(getRoot(signal), resolvedSegments);
|
|
607
|
-
const rawResolvedByPath = rawSignal($resolvedByPath);
|
|
608
|
-
if (rawResolvedByPath && key in rawResolvedByPath) {
|
|
609
|
-
return Reflect.apply(rawResolvedByPath[key], $resolvedByPath, argumentsList);
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
if (key === 'start') {
|
|
614
|
-
const [relativePath, ...depsAndGetter] = argumentsList;
|
|
615
|
-
if (typeof relativePath !== 'string')
|
|
616
|
-
throw Error('Signal.start() expects targetPath to be a string');
|
|
617
|
-
const absolutePath = joinScopePath($parent.path(), relativePath);
|
|
618
|
-
return compatStartOnRoot(getRoot($parent) || $parent, absolutePath, ...depsAndGetter);
|
|
619
|
-
}
|
|
620
|
-
if (key === 'stop') {
|
|
621
|
-
if (argumentsList.length > 1)
|
|
622
|
-
throw Error('Signal.stop() expects zero or one argument');
|
|
623
|
-
const relativePath = argumentsList.length === 0 ? '' : argumentsList[0];
|
|
624
|
-
if (relativePath != null && typeof relativePath !== 'string') {
|
|
625
|
-
throw Error('Signal.stop() expects targetPath to be a string');
|
|
626
|
-
}
|
|
627
|
-
const absolutePath = joinScopePath($parent.path(), relativePath || '');
|
|
628
|
-
return compatStopOnRoot(getRoot($parent) || $parent, absolutePath);
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
834
|
throw Error(ERRORS.noSignalKey($parent, key));
|
|
632
835
|
},
|
|
633
836
|
get(signal, key, receiver) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export function beginBatch(): void
|
|
2
|
-
export function endBatch(): void
|
|
3
|
-
export function inBatch(): boolean
|
|
4
|
-
export function runInBatch(fn:
|
|
5
|
-
export function scheduleReaction(reactionFn:
|
|
6
|
-
export function flushReactions(): void
|
|
7
|
-
export function __resetBatchSchedulerForTests(): void
|
|
1
|
+
export function beginBatch (): void
|
|
2
|
+
export function endBatch (): void
|
|
3
|
+
export function inBatch (): boolean
|
|
4
|
+
export function runInBatch<TResult> (fn: () => TResult): TResult
|
|
5
|
+
export function scheduleReaction (reactionFn: () => unknown): void
|
|
6
|
+
export function flushReactions (): void
|
|
7
|
+
export function __resetBatchSchedulerForTests (): void
|
package/dist/orm/connection.d.ts
CHANGED
|
@@ -16,11 +16,7 @@ export interface TeamplayConnection {
|
|
|
16
16
|
[key: string]: unknown;
|
|
17
17
|
}
|
|
18
18
|
export declare let connection: TeamplayConnection | undefined;
|
|
19
|
-
export declare let publicOnly: boolean | undefined;
|
|
20
19
|
export declare function setConnection(_connection: TeamplayConnection | undefined): void;
|
|
21
20
|
export declare function getConnection(): TeamplayConnection;
|
|
22
21
|
export declare function setDefaultFetchOnly(_fetchOnly: boolean): void;
|
|
23
22
|
export declare function getDefaultFetchOnly(): boolean;
|
|
24
|
-
export declare function setFetchOnly(_fetchOnly: boolean): void;
|
|
25
|
-
export declare function setPublicOnly(_publicOnly: boolean): void;
|
|
26
|
-
export declare function isPrivateMutationForbidden(): boolean;
|
package/dist/orm/connection.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { isCompatEnv } from './compatEnv.js';
|
|
2
1
|
export let connection;
|
|
3
2
|
let defaultFetchOnly;
|
|
4
|
-
export let publicOnly;
|
|
5
3
|
export function setConnection(_connection) {
|
|
6
4
|
connection = _connection;
|
|
7
5
|
}
|
|
@@ -16,16 +14,6 @@ export function setDefaultFetchOnly(_fetchOnly) {
|
|
|
16
14
|
export function getDefaultFetchOnly() {
|
|
17
15
|
return !!defaultFetchOnly;
|
|
18
16
|
}
|
|
19
|
-
// Deprecated alias kept for internal transition.
|
|
20
|
-
export function setFetchOnly(_fetchOnly) {
|
|
21
|
-
setDefaultFetchOnly(_fetchOnly);
|
|
22
|
-
}
|
|
23
|
-
export function setPublicOnly(_publicOnly) {
|
|
24
|
-
publicOnly = _publicOnly;
|
|
25
|
-
}
|
|
26
|
-
export function isPrivateMutationForbidden() {
|
|
27
|
-
return !!publicOnly && !isCompatEnv();
|
|
28
|
-
}
|
|
29
17
|
const ERRORS = {
|
|
30
18
|
notSet: `
|
|
31
19
|
Connection is not set.
|
package/dist/orm/dataTree.d.ts
CHANGED
|
@@ -4,18 +4,18 @@ export function getLogicalRootSnapshot(rootId: any, tree?: {}): {
|
|
|
4
4
|
};
|
|
5
5
|
export function get(segments: any, tree?: {}): {};
|
|
6
6
|
export function getRaw(segments: any): {};
|
|
7
|
-
export function set(segments: any, value: any, tree
|
|
8
|
-
export function setReplace(segments: any, value: any, tree
|
|
9
|
-
export function del(segments: any, tree
|
|
7
|
+
export function set(segments: any, value: any, tree?: {}): void;
|
|
8
|
+
export function setReplace(segments: any, value: any, tree?: {}): void;
|
|
9
|
+
export function del(segments: any, tree?: {}): void;
|
|
10
10
|
export function setPublicDoc(segments: any, value: any, deleteValue?: boolean): Promise<any>;
|
|
11
11
|
export function setPublicDocReplace(segments: any, value: any): Promise<any>;
|
|
12
|
-
export function arrayPush(segments: any, value: any, tree
|
|
13
|
-
export function arrayUnshift(segments: any, value: any, tree
|
|
14
|
-
export function arrayInsert(segments: any, index: any, values: any, tree
|
|
15
|
-
export function arrayPop(segments: any, tree
|
|
16
|
-
export function arrayShift(segments: any, tree
|
|
17
|
-
export function arrayRemove(segments: any, index: any, howMany
|
|
18
|
-
export function arrayMove(segments: any, from: any, to: any, howMany
|
|
12
|
+
export function arrayPush(segments: any, value: any, tree?: {}): number;
|
|
13
|
+
export function arrayUnshift(segments: any, value: any, tree?: {}): number;
|
|
14
|
+
export function arrayInsert(segments: any, index: any, values: any, tree?: {}): number;
|
|
15
|
+
export function arrayPop(segments: any, tree?: {}): any;
|
|
16
|
+
export function arrayShift(segments: any, tree?: {}): any;
|
|
17
|
+
export function arrayRemove(segments: any, index: any, howMany?: number, tree?: {}): any[];
|
|
18
|
+
export function arrayMove(segments: any, from: any, to: any, howMany?: number, tree?: {}): any[];
|
|
19
19
|
export function incrementPublic(segments: any, byNumber: any): Promise<any>;
|
|
20
20
|
export function arrayPushPublic(segments: any, value: any): Promise<any>;
|
|
21
21
|
export function arrayUnshiftPublic(segments: any, value: any): Promise<any>;
|
|
@@ -24,8 +24,8 @@ export function arrayPopPublic(segments: any): Promise<any>;
|
|
|
24
24
|
export function arrayShiftPublic(segments: any): Promise<any>;
|
|
25
25
|
export function arrayRemovePublic(segments: any, index: any, howMany?: number): Promise<any>;
|
|
26
26
|
export function arrayMovePublic(segments: any, from: any, to: any, howMany?: number): Promise<any>;
|
|
27
|
-
export function stringInsertLocal(segments: any, index: any, text: any, tree
|
|
28
|
-
export function stringRemoveLocal(segments: any, index: any, howMany: any, tree
|
|
27
|
+
export function stringInsertLocal(segments: any, index: any, text: any, tree?: {}): any;
|
|
28
|
+
export function stringRemoveLocal(segments: any, index: any, howMany: any, tree?: {}): any;
|
|
29
29
|
export function stringInsertPublic(segments: any, index: any, text: any): Promise<any>;
|
|
30
30
|
export function stringRemovePublic(segments: any, index: any, howMany: any): Promise<any>;
|
|
31
31
|
export { isPrivateCollectionSegments } from "./rootScope.js";
|