@amityco/ts-sdk-react-native 7.25.1-144f8feb.0 → 7.25.1-4faf708f.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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cache/utils/index.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa,QAAQ,CAAC;AACnC,eAAO,MAAM,eAAe,UAAU,CAAC;AACvC,eAAO,MAAM,mBAAmB,SAAS,CAAC;AAC1C,eAAO,MAAM,oBAAoB,eAAe,CAAC;AAEjD,eAAO,MAAM,sBAAsB,QAAa,CAAC;AACjD,eAAO,MAAM,cAAc,QAAa,CAAC;AACzC,eAAO,MAAM,wBAAwB,QAAa,CAAC;AAkBnD;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,2BAA0B,MACmC,CAAC;AAEpF;;;;;;;;;GASG;AACH,eAAO,MAAM,SAAS,QAAS,MAAM,mBAAoC,CAAC;AAE1E;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,cAAe,GAAG,aAAa,GAAG,KAAG,OAa7D,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,4BAA6B,GAAG,2BACU,CAAC;AAEhE;;;;;;;;;GASG;AACH,eAAO,MAAM,4BAA4B,cAAe,MAAM,WAAW,KAAG,OACS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cache/utils/index.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa,QAAQ,CAAC;AACnC,eAAO,MAAM,eAAe,UAAU,CAAC;AACvC,eAAO,MAAM,mBAAmB,SAAS,CAAC;AAC1C,eAAO,MAAM,oBAAoB,eAAe,CAAC;AAEjD,eAAO,MAAM,sBAAsB,QAAa,CAAC;AACjD,eAAO,MAAM,cAAc,QAAa,CAAC;AACzC,eAAO,MAAM,wBAAwB,QAAa,CAAC;AAkBnD;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,2BAA0B,MAQ7C,CAAC;AAEJ;;;;;;;;;GASG;AACH,eAAO,MAAM,SAAS,QAAS,MAAM,mBAAoC,CAAC;AAE1E;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,cAAe,GAAG,aAAa,GAAG,KAAG,OAa7D,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,4BAA6B,GAAG,2BACU,CAAC;AAEhE;;;;;;;;;GASG;AACH,eAAO,MAAM,4BAA4B,cAAe,MAAM,WAAW,KAAG,OACS,CAAC"}
package/dist/index.cjs.js CHANGED
@@ -397,7 +397,13 @@ const normalize = (source) => Object.keys(source)
397
397
  * @category Cache
398
398
  * @hidden
399
399
  */
400
- const encodeKey = (key) => JSON.stringify(key, (_, val) => (typeof val === 'object' ? normalize(val) : val));
400
+ const encodeKey = (key) => JSON.stringify(key, (_, val) =>
401
+ // `typeof null` is `'object'`, so a nullish segment would reach normalize()
402
+ // and throw on Object.keys(null) — taking down whichever cache read built
403
+ // the key. Amity.Serializable does not admit null in the first place, so a
404
+ // null here is a payload that broke its own contract: encode it as null and
405
+ // let the miss be a miss.
406
+ val !== null && typeof val === 'object' ? normalize(val) : val);
401
407
  /**
402
408
  * Decodes a string back into a {@link Amity.CacheKey}
403
409
 
@@ -16628,6 +16634,39 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
16628
16634
  return !((_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName));
16629
16635
  };
16630
16636
 
16637
+ /**
16638
+ * Resolves the id of the parent post that a child-post payload belongs to.
16639
+ *
16640
+ * `parentId` and `parentPostId` name the same post, but a payload does not
16641
+ * always carry both — and the delete/create child handlers decide *whether* a
16642
+ * post is a child from `parentId` while reading the cache with `parentPostId`.
16643
+ * When only the former is set that read builds `['post', 'get', undefined]`,
16644
+ * which cannot match anything and, when the value is null, breaks key encoding
16645
+ * outright. Reading whichever id is present keeps the decision and the lookup
16646
+ * on the same post.
16647
+ *
16648
+ * @param post the child post payload
16649
+ * @returns the parent post id, or undefined when the payload carries neither
16650
+ *
16651
+ * @category Post Events
16652
+ * @hidden
16653
+ */
16654
+ const resolveParentPostId = (post) => {
16655
+ if (post.parentPostId)
16656
+ return post.parentPostId;
16657
+ if (post.parentId) {
16658
+ // Diagnostic: we do not know yet whether the server actually emits this
16659
+ // shape. If this warning is never seen in practice the fallback can go.
16660
+ console.warn('[AmitySDK] post payload carries `parentId` without `parentPostId` — falling back to `parentId`', {
16661
+ postId: post.postId,
16662
+ parentId: post.parentId,
16663
+ parentPostId: post.parentPostId,
16664
+ });
16665
+ return post.parentId;
16666
+ }
16667
+ return undefined;
16668
+ };
16669
+
16631
16670
  const processDeleteChildPost = (payload) => {
16632
16671
  var _a;
16633
16672
  const post = payload.posts[0];
@@ -16639,7 +16678,10 @@ const processDeleteChildPost = (payload) => {
16639
16678
  }
16640
16679
  else {
16641
16680
  // child post in a parent post
16642
- const parentPost = (_a = pullFromCache(['post', 'get', post.parentPostId])) === null || _a === void 0 ? void 0 : _a.data;
16681
+ const parentPostId = resolveParentPostId(post);
16682
+ if (!parentPostId)
16683
+ return;
16684
+ const parentPost = (_a = pullFromCache(['post', 'get', parentPostId])) === null || _a === void 0 ? void 0 : _a.data;
16643
16685
  if (!parentPost)
16644
16686
  return;
16645
16687
  pushToCache(['post', 'get', parentPost.postId], Object.assign(Object.assign({}, parentPost), { children: parentPost.children.filter(childId => childId !== post.postId) }));
@@ -16650,7 +16692,10 @@ const processCreateChildPost = (payload) => {
16650
16692
  const post = payload.posts[0];
16651
16693
  if (!post.parentId)
16652
16694
  return;
16653
- const parentPost = (_a = pullFromCache(['post', 'get', post.parentPostId])) === null || _a === void 0 ? void 0 : _a.data;
16695
+ const parentPostId = resolveParentPostId(post);
16696
+ if (!parentPostId)
16697
+ return;
16698
+ const parentPost = (_a = pullFromCache(['post', 'get', parentPostId])) === null || _a === void 0 ? void 0 : _a.data;
16654
16699
  if (!parentPost)
16655
16700
  return;
16656
16701
  pushToCache(['post', 'get', parentPost.postId], Object.assign(Object.assign({}, parentPost), { children: [...new Set([post.postId, ...parentPost.children])] }));
package/dist/index.esm.js CHANGED
@@ -362,7 +362,13 @@ const normalize = (source) => Object.keys(source)
362
362
  * @category Cache
363
363
  * @hidden
364
364
  */
365
- const encodeKey = (key) => JSON.stringify(key, (_, val) => (typeof val === 'object' ? normalize(val) : val));
365
+ const encodeKey = (key) => JSON.stringify(key, (_, val) =>
366
+ // `typeof null` is `'object'`, so a nullish segment would reach normalize()
367
+ // and throw on Object.keys(null) — taking down whichever cache read built
368
+ // the key. Amity.Serializable does not admit null in the first place, so a
369
+ // null here is a payload that broke its own contract: encode it as null and
370
+ // let the miss be a miss.
371
+ val !== null && typeof val === 'object' ? normalize(val) : val);
366
372
  /**
367
373
  * Decodes a string back into a {@link Amity.CacheKey}
368
374
 
@@ -16609,6 +16615,39 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
16609
16615
  return !((_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName));
16610
16616
  };
16611
16617
 
16618
+ /**
16619
+ * Resolves the id of the parent post that a child-post payload belongs to.
16620
+ *
16621
+ * `parentId` and `parentPostId` name the same post, but a payload does not
16622
+ * always carry both — and the delete/create child handlers decide *whether* a
16623
+ * post is a child from `parentId` while reading the cache with `parentPostId`.
16624
+ * When only the former is set that read builds `['post', 'get', undefined]`,
16625
+ * which cannot match anything and, when the value is null, breaks key encoding
16626
+ * outright. Reading whichever id is present keeps the decision and the lookup
16627
+ * on the same post.
16628
+ *
16629
+ * @param post the child post payload
16630
+ * @returns the parent post id, or undefined when the payload carries neither
16631
+ *
16632
+ * @category Post Events
16633
+ * @hidden
16634
+ */
16635
+ const resolveParentPostId = (post) => {
16636
+ if (post.parentPostId)
16637
+ return post.parentPostId;
16638
+ if (post.parentId) {
16639
+ // Diagnostic: we do not know yet whether the server actually emits this
16640
+ // shape. If this warning is never seen in practice the fallback can go.
16641
+ console.warn('[AmitySDK] post payload carries `parentId` without `parentPostId` — falling back to `parentId`', {
16642
+ postId: post.postId,
16643
+ parentId: post.parentId,
16644
+ parentPostId: post.parentPostId,
16645
+ });
16646
+ return post.parentId;
16647
+ }
16648
+ return undefined;
16649
+ };
16650
+
16612
16651
  const processDeleteChildPost = (payload) => {
16613
16652
  var _a;
16614
16653
  const post = payload.posts[0];
@@ -16620,7 +16659,10 @@ const processDeleteChildPost = (payload) => {
16620
16659
  }
16621
16660
  else {
16622
16661
  // child post in a parent post
16623
- const parentPost = (_a = pullFromCache(['post', 'get', post.parentPostId])) === null || _a === void 0 ? void 0 : _a.data;
16662
+ const parentPostId = resolveParentPostId(post);
16663
+ if (!parentPostId)
16664
+ return;
16665
+ const parentPost = (_a = pullFromCache(['post', 'get', parentPostId])) === null || _a === void 0 ? void 0 : _a.data;
16624
16666
  if (!parentPost)
16625
16667
  return;
16626
16668
  pushToCache(['post', 'get', parentPost.postId], Object.assign(Object.assign({}, parentPost), { children: parentPost.children.filter(childId => childId !== post.postId) }));
@@ -16631,7 +16673,10 @@ const processCreateChildPost = (payload) => {
16631
16673
  const post = payload.posts[0];
16632
16674
  if (!post.parentId)
16633
16675
  return;
16634
- const parentPost = (_a = pullFromCache(['post', 'get', post.parentPostId])) === null || _a === void 0 ? void 0 : _a.data;
16676
+ const parentPostId = resolveParentPostId(post);
16677
+ if (!parentPostId)
16678
+ return;
16679
+ const parentPost = (_a = pullFromCache(['post', 'get', parentPostId])) === null || _a === void 0 ? void 0 : _a.data;
16635
16680
  if (!parentPost)
16636
16681
  return;
16637
16682
  pushToCache(['post', 'get', parentPost.postId], Object.assign(Object.assign({}, parentPost), { children: [...new Set([post.postId, ...parentPost.children])] }));