teamplay 0.4.0-alpha.54 → 0.4.0-alpha.56

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/orm/Query.js CHANGED
@@ -230,7 +230,7 @@ export class QuerySubscriptions {
230
230
 
231
231
  subscribe ($query) {
232
232
  const collectionName = $query[COLLECTION_NAME]
233
- const params = JSON.parse(JSON.stringify($query[PARAMS]))
233
+ const params = cloneQueryParams($query[PARAMS])
234
234
  const hash = $query[HASH]
235
235
  this.cancelDestroy(hash)
236
236
  let count = this.subCount.get(hash) || 0
@@ -395,6 +395,7 @@ function maybeMaterializeQueryDocsToCollection (collectionName, shareDocs) {
395
395
  }
396
396
 
397
397
  export function hashQuery (collectionName, params) {
398
+ params = normalizeQueryParamsForHash(params)
398
399
  // TODO: probably makes sense to use fast-stable-json-stringify for this because of the params
399
400
  return JSON.stringify({ query: [collectionName, params] })
400
401
  }
@@ -409,7 +410,7 @@ export function parseQueryHash (hash) {
409
410
  }
410
411
 
411
412
  export function getQuerySignal (collectionName, params, options) {
412
- params = JSON.parse(JSON.stringify(params))
413
+ params = cloneQueryParams(params)
413
414
  const hash = hashQuery(collectionName, params)
414
415
 
415
416
  const $query = getSignal(undefined, [collectionName], {
@@ -433,6 +434,31 @@ const ERRORS = {
433
434
 
434
435
  function ignoreDestroyError () {}
435
436
 
437
+ function cloneQueryParams (params) {
438
+ if (!isCompatEnv()) return JSON.parse(JSON.stringify(params))
439
+ return cloneQueryParamsCompat(params)
440
+ }
441
+
442
+ function normalizeQueryParamsForHash (params) {
443
+ if (!isCompatEnv()) return params
444
+ return cloneQueryParamsCompat(params)
445
+ }
446
+
447
+ // Racer compat: keep query keys with undefined values by normalizing them to null
448
+ // instead of dropping them via JSON serialization.
449
+ function cloneQueryParamsCompat (value) {
450
+ if (value === undefined) return null
451
+ if (value == null || typeof value !== 'object') return value
452
+ if (Array.isArray(value)) return value.map(item => cloneQueryParamsCompat(item))
453
+ const object = {}
454
+ for (const key in value) {
455
+ if (Object.prototype.hasOwnProperty.call(value, key)) {
456
+ object[key] = cloneQueryParamsCompat(value[key])
457
+ }
458
+ }
459
+ return object
460
+ }
461
+
436
462
  function createPendingDestroyEntry () {
437
463
  let resolvePending
438
464
  let rejectPending
package/orm/dataTree.js CHANGED
@@ -155,7 +155,16 @@ export async function setPublicDoc (segments, value, deleteValue = false) {
155
155
  const idFields = getIdFieldsForSegments([collection, docId])
156
156
  if (segments.length >= 3 && idFields.includes(segments[segments.length - 1])) return
157
157
  const doc = getConnection().get(collection, docId)
158
- const docState = resolvePublicDocState({ collection, docId, doc, idFields, hydrateCompatDocData: true })
158
+ let docState = resolvePublicDocState({ collection, docId, doc, idFields, hydrateCompatDocData: true })
159
+ if (!docState.exists && segments.length > 2) {
160
+ docState = await resolvePublicDocStateWithCompatFetchFallback({
161
+ collection,
162
+ docId,
163
+ doc,
164
+ idFields,
165
+ hydrateCompatDocData: true
166
+ })
167
+ }
159
168
  if (!docState.exists && deleteValue) throw Error(ERRORS.deleteNonExistentDoc(segments))
160
169
  // make sure that the value is not observable to not trigger extra reads. And clone it
161
170
  value = raw(value)
@@ -235,7 +244,16 @@ export async function setPublicDocReplace (segments, value) {
235
244
  const idFields = getIdFieldsForSegments([collection, docId])
236
245
  if (segments.length >= 3 && idFields.includes(segments[segments.length - 1])) return
237
246
  const doc = getConnection().get(collection, docId)
238
- const docState = resolvePublicDocState({ collection, docId, doc, idFields, hydrateCompatDocData: true })
247
+ let docState = resolvePublicDocState({ collection, docId, doc, idFields, hydrateCompatDocData: true })
248
+ if (!docState.exists && segments.length > 2) {
249
+ docState = await resolvePublicDocStateWithCompatFetchFallback({
250
+ collection,
251
+ docId,
252
+ doc,
253
+ idFields,
254
+ hydrateCompatDocData: true
255
+ })
256
+ }
239
257
  // make sure that the value is not observable to not trigger extra reads. And clone it
240
258
  value = raw(value)
241
259
  if (value != null) {
@@ -344,6 +362,24 @@ function resolvePublicDocState ({
344
362
  return { exists: true, snapshot: localSnapshot, source: 'local' }
345
363
  }
346
364
 
365
+ async function resolvePublicDocStateWithCompatFetchFallback ({
366
+ collection,
367
+ docId,
368
+ doc,
369
+ idFields,
370
+ hydrateCompatDocData = false
371
+ }) {
372
+ let docState = resolvePublicDocState({ collection, docId, doc, idFields, hydrateCompatDocData })
373
+ if (docState.exists || !isCompatEnv()) return docState
374
+
375
+ await new Promise((resolve, reject) => {
376
+ doc.fetch(err => err ? reject(err) : resolve())
377
+ })
378
+
379
+ docState = resolvePublicDocState({ collection, docId, doc, idFields, hydrateCompatDocData })
380
+ return docState
381
+ }
382
+
347
383
  function ensureLocalDocSyncedWithShareDoc ({
348
384
  collection,
349
385
  docId,
@@ -463,7 +499,13 @@ export async function incrementPublic (segments, byNumber) {
463
499
  if (!(collection && docId)) throw Error(ERRORS.publicDoc(segments))
464
500
  const doc = getConnection().get(collection, docId)
465
501
  const idFields = getIdFieldsForSegments([collection, docId])
466
- const docState = resolvePublicDocState({ collection, docId, doc, idFields, hydrateCompatDocData: true })
502
+ const docState = await resolvePublicDocStateWithCompatFetchFallback({
503
+ collection,
504
+ docId,
505
+ doc,
506
+ idFields,
507
+ hydrateCompatDocData: true
508
+ })
467
509
  if (!docState.exists) throw Error(ERRORS.nonExistingDoc(segments))
468
510
  const relativePath = segments.slice(2)
469
511
  const op = [{ p: relativePath, na: byNumber }]
@@ -490,7 +532,13 @@ export async function arrayInsertPublic (segments, index, values) {
490
532
  if (!(collection && docId)) throw Error(ERRORS.publicDoc(segments))
491
533
  const doc = getConnection().get(collection, docId)
492
534
  const idFields = getIdFieldsForSegments([collection, docId])
493
- const docState = resolvePublicDocState({ collection, docId, doc, idFields, hydrateCompatDocData: true })
535
+ const docState = await resolvePublicDocStateWithCompatFetchFallback({
536
+ collection,
537
+ docId,
538
+ doc,
539
+ idFields,
540
+ hydrateCompatDocData: true
541
+ })
494
542
  if (!docState.exists) throw Error(ERRORS.nonExistingDoc(segments))
495
543
  let current = getRaw(segments)
496
544
  if (current == null) {
@@ -539,7 +587,13 @@ export async function arrayRemovePublic (segments, index, howMany = 1) {
539
587
  if (!(collection && docId)) throw Error(ERRORS.publicDoc(segments))
540
588
  const doc = getConnection().get(collection, docId)
541
589
  const idFields = getIdFieldsForSegments([collection, docId])
542
- const docState = resolvePublicDocState({ collection, docId, doc, idFields, hydrateCompatDocData: true })
590
+ const docState = await resolvePublicDocStateWithCompatFetchFallback({
591
+ collection,
592
+ docId,
593
+ doc,
594
+ idFields,
595
+ hydrateCompatDocData: true
596
+ })
543
597
  if (!docState.exists) throw Error(ERRORS.nonExistingDoc(segments))
544
598
  const arr = getRaw(segments) || []
545
599
  const removed = arr.slice(index, index + howMany)
@@ -557,7 +611,13 @@ export async function arrayMovePublic (segments, from, to, howMany = 1) {
557
611
  if (!(collection && docId)) throw Error(ERRORS.publicDoc(segments))
558
612
  const doc = getConnection().get(collection, docId)
559
613
  const idFields = getIdFieldsForSegments([collection, docId])
560
- const docState = resolvePublicDocState({ collection, docId, doc, idFields, hydrateCompatDocData: true })
614
+ const docState = await resolvePublicDocStateWithCompatFetchFallback({
615
+ collection,
616
+ docId,
617
+ doc,
618
+ idFields,
619
+ hydrateCompatDocData: true
620
+ })
561
621
  if (!docState.exists) throw Error(ERRORS.nonExistingDoc(segments))
562
622
  const arr = getRaw(segments) || []
563
623
  const len = arr.length
@@ -623,7 +683,13 @@ export async function stringInsertPublic (segments, index, text) {
623
683
  if (!(collection && docId)) throw Error(ERRORS.publicDoc(segments))
624
684
  const doc = getConnection().get(collection, docId)
625
685
  const idFields = getIdFieldsForSegments([collection, docId])
626
- const docState = resolvePublicDocState({ collection, docId, doc, idFields, hydrateCompatDocData: true })
686
+ const docState = await resolvePublicDocStateWithCompatFetchFallback({
687
+ collection,
688
+ docId,
689
+ doc,
690
+ idFields,
691
+ hydrateCompatDocData: true
692
+ })
627
693
  if (!docState.exists) throw Error(ERRORS.nonExistingDoc(segments))
628
694
  const relativePath = segments.slice(2)
629
695
  const previous = getRaw(segments)
@@ -646,7 +712,13 @@ export async function stringRemovePublic (segments, index, howMany) {
646
712
  if (!(collection && docId)) throw Error(ERRORS.publicDoc(segments))
647
713
  const doc = getConnection().get(collection, docId)
648
714
  const idFields = getIdFieldsForSegments([collection, docId])
649
- const docState = resolvePublicDocState({ collection, docId, doc, idFields, hydrateCompatDocData: true })
715
+ const docState = await resolvePublicDocStateWithCompatFetchFallback({
716
+ collection,
717
+ docId,
718
+ doc,
719
+ idFields,
720
+ hydrateCompatDocData: true
721
+ })
650
722
  if (!docState.exists) throw Error(ERRORS.nonExistingDoc(segments))
651
723
  const relativePath = segments.slice(2)
652
724
  const previous = getRaw(segments)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teamplay",
3
- "version": "0.4.0-alpha.54",
3
+ "version": "0.4.0-alpha.56",
4
4
  "description": "Full-stack signals ORM with multiplayer",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -83,5 +83,5 @@
83
83
  ]
84
84
  },
85
85
  "license": "MIT",
86
- "gitHead": "4e0872cc4f98406c9561835f8032590c677492e5"
86
+ "gitHead": "50b36e96bbd184b0608a654759c2e8f7340f7559"
87
87
  }