teamplay 0.5.0-alpha.23 → 0.5.0-alpha.25
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/dist/orm/Compat/SignalCompat.js +0 -24
- package/dist/orm/dataTree.js +36 -30
- package/package.json +2 -2
|
@@ -159,21 +159,6 @@ class SignalCompat extends Signal {
|
|
|
159
159
|
return;
|
|
160
160
|
return setReplaceOnSignal(this, value);
|
|
161
161
|
}
|
|
162
|
-
async create(value) {
|
|
163
|
-
const forwarded = forwardRef(this, 'create', arguments);
|
|
164
|
-
if (forwarded)
|
|
165
|
-
return forwarded;
|
|
166
|
-
if (arguments.length > 1)
|
|
167
|
-
throw Error('Signal.create() expects zero or one argument');
|
|
168
|
-
if (arguments.length === 0) {
|
|
169
|
-
value = {};
|
|
170
|
-
}
|
|
171
|
-
ensureCreateTarget(this, 'Signal.create()');
|
|
172
|
-
if (this.get() != null) {
|
|
173
|
-
throw Error(`Signal.create() may only be used on a non-existing document path. Path: ${this.path()}`);
|
|
174
|
-
}
|
|
175
|
-
return setReplaceOnSignal(this, value);
|
|
176
|
-
}
|
|
177
162
|
async setDiffDeep(value) {
|
|
178
163
|
const forwarded = forwardRef(this, 'setDiffDeep', arguments);
|
|
179
164
|
if (forwarded)
|
|
@@ -956,15 +941,6 @@ function ensureValueTarget($signal) {
|
|
|
956
941
|
throw Error('Mutators can\'t be used on a query signal');
|
|
957
942
|
return segments;
|
|
958
943
|
}
|
|
959
|
-
function ensureCreateTarget($signal, methodName) {
|
|
960
|
-
const segments = $signal[SEGMENTS];
|
|
961
|
-
if ($signal[IS_QUERY])
|
|
962
|
-
throw Error(`${methodName} can't be used on a query signal`);
|
|
963
|
-
if (segments.length !== 2) {
|
|
964
|
-
throw Error(`${methodName} may only be used on a document path`);
|
|
965
|
-
}
|
|
966
|
-
return segments;
|
|
967
|
-
}
|
|
968
944
|
async function arrayPushOnSignal($signal, value) {
|
|
969
945
|
const segments = ensureArrayTarget($signal);
|
|
970
946
|
const idFields = getIdFieldsForSegments(segments);
|
package/dist/orm/dataTree.js
CHANGED
|
@@ -178,14 +178,14 @@ export async function setPublicDoc(segments, value, deleteValue = false) {
|
|
|
178
178
|
if (isIdFieldPath(segments, idFields))
|
|
179
179
|
return;
|
|
180
180
|
const doc = getConnection().get(collection, docId);
|
|
181
|
-
let docState = resolvePublicDocState({ collection, docId, doc, idFields,
|
|
181
|
+
let docState = resolvePublicDocState({ collection, docId, doc, idFields, hydrateDocDataFromLocal: true });
|
|
182
182
|
if (!docState.exists && segments.length > 2) {
|
|
183
|
-
docState = await
|
|
183
|
+
docState = await resolvePublicDocStateWithFetchFallback({
|
|
184
184
|
collection,
|
|
185
185
|
docId,
|
|
186
186
|
doc,
|
|
187
187
|
idFields,
|
|
188
|
-
|
|
188
|
+
hydrateDocDataFromLocal: true
|
|
189
189
|
});
|
|
190
190
|
}
|
|
191
191
|
if (!docState.exists && deleteValue)
|
|
@@ -286,14 +286,14 @@ export async function setPublicDocReplace(segments, value) {
|
|
|
286
286
|
if (isIdFieldPath(segments, idFields))
|
|
287
287
|
return;
|
|
288
288
|
const doc = getConnection().get(collection, docId);
|
|
289
|
-
let docState = resolvePublicDocState({ collection, docId, doc, idFields,
|
|
289
|
+
let docState = resolvePublicDocState({ collection, docId, doc, idFields, hydrateDocDataFromLocal: true });
|
|
290
290
|
if (!docState.exists && segments.length > 2) {
|
|
291
|
-
docState = await
|
|
291
|
+
docState = await resolvePublicDocStateWithFetchFallback({
|
|
292
292
|
collection,
|
|
293
293
|
docId,
|
|
294
294
|
doc,
|
|
295
295
|
idFields,
|
|
296
|
-
|
|
296
|
+
hydrateDocDataFromLocal: true
|
|
297
297
|
});
|
|
298
298
|
}
|
|
299
299
|
// make sure that the value is not observable to not trigger extra reads. And clone it
|
|
@@ -374,9 +374,10 @@ async function createPublicDocAndHydrateLocal({ doc, collection, docId, newDoc,
|
|
|
374
374
|
await new Promise((resolve, reject) => {
|
|
375
375
|
doc.create(newDoc, err => err ? reject(err) : resolve());
|
|
376
376
|
});
|
|
377
|
-
//
|
|
378
|
-
//
|
|
379
|
-
|
|
377
|
+
// Keep public creates immediately writable even when the ShareDB snapshot has
|
|
378
|
+
// not been loaded via subscribe/fetch yet. UI flows rely on optimistic add()
|
|
379
|
+
// followed by child writes without waiting for DB confirmation.
|
|
380
|
+
if (doc?.data == null) {
|
|
380
381
|
const localDoc = JSON.parse(JSON.stringify(newDoc || {}));
|
|
381
382
|
if (isPlainObject(localDoc))
|
|
382
383
|
injectIdFields(localDoc, idFields, docId);
|
|
@@ -387,7 +388,7 @@ async function createPublicDocAndHydrateLocal({ doc, collection, docId, newDoc,
|
|
|
387
388
|
}
|
|
388
389
|
ensureLocalDocSyncedWithShareDoc({ collection, docId, doc, idFields });
|
|
389
390
|
}
|
|
390
|
-
function resolvePublicDocState({ collection, docId, doc, idFields,
|
|
391
|
+
function resolvePublicDocState({ collection, docId, doc, idFields, hydrateDocDataFromLocal = false }) {
|
|
391
392
|
ensureLocalDocSyncedWithShareDoc({ collection, docId, doc, idFields });
|
|
392
393
|
if (isMissingShareDoc(doc)) {
|
|
393
394
|
return { exists: false, snapshot: undefined, source: 'none' };
|
|
@@ -400,24 +401,29 @@ function resolvePublicDocState({ collection, docId, doc, idFields, hydrateCompat
|
|
|
400
401
|
};
|
|
401
402
|
}
|
|
402
403
|
const localSnapshot = getRaw([collection, docId]);
|
|
403
|
-
if (
|
|
404
|
+
if (localSnapshot == null) {
|
|
404
405
|
return { exists: false, snapshot: undefined, source: 'none' };
|
|
405
406
|
}
|
|
406
|
-
//
|
|
407
|
-
//
|
|
408
|
-
if (
|
|
407
|
+
// Local raw data can be the source of truth between add() and later subpath
|
|
408
|
+
// mutations even if ShareDB doc.data is currently empty or was recreated.
|
|
409
|
+
if (hydrateDocDataFromLocal) {
|
|
409
410
|
doc.data = localSnapshot;
|
|
410
411
|
}
|
|
411
412
|
return { exists: true, snapshot: localSnapshot, source: 'local' };
|
|
412
413
|
}
|
|
413
|
-
async function
|
|
414
|
-
let docState = resolvePublicDocState({ collection, docId, doc, idFields,
|
|
415
|
-
if (docState.exists
|
|
414
|
+
async function resolvePublicDocStateWithFetchFallback({ collection, docId, doc, idFields, hydrateDocDataFromLocal = false }) {
|
|
415
|
+
let docState = resolvePublicDocState({ collection, docId, doc, idFields, hydrateDocDataFromLocal });
|
|
416
|
+
if (docState.exists)
|
|
417
|
+
return docState;
|
|
418
|
+
const shouldFetch = isCompatEnv() || (getRaw([collection, docId]) != null &&
|
|
419
|
+
isMissingShareDoc(doc) &&
|
|
420
|
+
doc.version == null);
|
|
421
|
+
if (!shouldFetch)
|
|
416
422
|
return docState;
|
|
417
423
|
await new Promise((resolve, reject) => {
|
|
418
424
|
doc.fetch(err => err ? reject(err) : resolve());
|
|
419
425
|
});
|
|
420
|
-
docState = resolvePublicDocState({ collection, docId, doc, idFields,
|
|
426
|
+
docState = resolvePublicDocState({ collection, docId, doc, idFields, hydrateDocDataFromLocal });
|
|
421
427
|
return docState;
|
|
422
428
|
}
|
|
423
429
|
function ensureLocalDocSyncedWithShareDoc({ collection, docId, doc, idFields }) {
|
|
@@ -572,12 +578,12 @@ export async function incrementPublic(segments, byNumber) {
|
|
|
572
578
|
throw Error(ERRORS.publicDoc(segments));
|
|
573
579
|
const doc = getConnection().get(collection, docId);
|
|
574
580
|
const idFields = getIdFieldsForSegments([collection, docId]);
|
|
575
|
-
const docState = await
|
|
581
|
+
const docState = await resolvePublicDocStateWithFetchFallback({
|
|
576
582
|
collection,
|
|
577
583
|
docId,
|
|
578
584
|
doc,
|
|
579
585
|
idFields,
|
|
580
|
-
|
|
586
|
+
hydrateDocDataFromLocal: true
|
|
581
587
|
});
|
|
582
588
|
if (!docState.exists)
|
|
583
589
|
throw Error(ERRORS.nonExistingDoc(segments));
|
|
@@ -615,12 +621,12 @@ export async function arrayInsertPublic(segments, index, values) {
|
|
|
615
621
|
throw Error(ERRORS.publicDoc(segments));
|
|
616
622
|
const doc = getConnection().get(collection, docId);
|
|
617
623
|
const idFields = getIdFieldsForSegments([collection, docId]);
|
|
618
|
-
const docState = await
|
|
624
|
+
const docState = await resolvePublicDocStateWithFetchFallback({
|
|
619
625
|
collection,
|
|
620
626
|
docId,
|
|
621
627
|
doc,
|
|
622
628
|
idFields,
|
|
623
|
-
|
|
629
|
+
hydrateDocDataFromLocal: true
|
|
624
630
|
});
|
|
625
631
|
if (!docState.exists)
|
|
626
632
|
throw Error(ERRORS.nonExistingDoc(segments));
|
|
@@ -674,12 +680,12 @@ export async function arrayRemovePublic(segments, index, howMany = 1) {
|
|
|
674
680
|
throw Error(ERRORS.publicDoc(segments));
|
|
675
681
|
const doc = getConnection().get(collection, docId);
|
|
676
682
|
const idFields = getIdFieldsForSegments([collection, docId]);
|
|
677
|
-
const docState = await
|
|
683
|
+
const docState = await resolvePublicDocStateWithFetchFallback({
|
|
678
684
|
collection,
|
|
679
685
|
docId,
|
|
680
686
|
doc,
|
|
681
687
|
idFields,
|
|
682
|
-
|
|
688
|
+
hydrateDocDataFromLocal: true
|
|
683
689
|
});
|
|
684
690
|
if (!docState.exists)
|
|
685
691
|
throw Error(ERRORS.nonExistingDoc(segments));
|
|
@@ -702,12 +708,12 @@ export async function arrayMovePublic(segments, from, to, howMany = 1) {
|
|
|
702
708
|
throw Error(ERRORS.publicDoc(segments));
|
|
703
709
|
const doc = getConnection().get(collection, docId);
|
|
704
710
|
const idFields = getIdFieldsForSegments([collection, docId]);
|
|
705
|
-
const docState = await
|
|
711
|
+
const docState = await resolvePublicDocStateWithFetchFallback({
|
|
706
712
|
collection,
|
|
707
713
|
docId,
|
|
708
714
|
doc,
|
|
709
715
|
idFields,
|
|
710
|
-
|
|
716
|
+
hydrateDocDataFromLocal: true
|
|
711
717
|
});
|
|
712
718
|
if (!docState.exists)
|
|
713
719
|
throw Error(ERRORS.nonExistingDoc(segments));
|
|
@@ -780,12 +786,12 @@ export async function stringInsertPublic(segments, index, text) {
|
|
|
780
786
|
throw Error(ERRORS.publicDoc(segments));
|
|
781
787
|
const doc = getConnection().get(collection, docId);
|
|
782
788
|
const idFields = getIdFieldsForSegments([collection, docId]);
|
|
783
|
-
const docState = await
|
|
789
|
+
const docState = await resolvePublicDocStateWithFetchFallback({
|
|
784
790
|
collection,
|
|
785
791
|
docId,
|
|
786
792
|
doc,
|
|
787
793
|
idFields,
|
|
788
|
-
|
|
794
|
+
hydrateDocDataFromLocal: true
|
|
789
795
|
});
|
|
790
796
|
if (!docState.exists)
|
|
791
797
|
throw Error(ERRORS.nonExistingDoc(segments));
|
|
@@ -814,12 +820,12 @@ export async function stringRemovePublic(segments, index, howMany) {
|
|
|
814
820
|
throw Error(ERRORS.publicDoc(segments));
|
|
815
821
|
const doc = getConnection().get(collection, docId);
|
|
816
822
|
const idFields = getIdFieldsForSegments([collection, docId]);
|
|
817
|
-
const docState = await
|
|
823
|
+
const docState = await resolvePublicDocStateWithFetchFallback({
|
|
818
824
|
collection,
|
|
819
825
|
docId,
|
|
820
826
|
doc,
|
|
821
827
|
idFields,
|
|
822
|
-
|
|
828
|
+
hydrateDocDataFromLocal: true
|
|
823
829
|
});
|
|
824
830
|
if (!docState.exists)
|
|
825
831
|
throw Error(ERRORS.nonExistingDoc(segments));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "teamplay",
|
|
3
|
-
"version": "0.5.0-alpha.
|
|
3
|
+
"version": "0.5.0-alpha.25",
|
|
4
4
|
"description": "Full-stack signals ORM with multiplayer",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -134,5 +134,5 @@
|
|
|
134
134
|
]
|
|
135
135
|
},
|
|
136
136
|
"license": "MIT",
|
|
137
|
-
"gitHead": "
|
|
137
|
+
"gitHead": "f1dcc0b025c80535acfe03a583e828c491f2a1e6"
|
|
138
138
|
}
|