@amityco/ts-sdk 7.32.1-9a9aa5a.0 → 7.32.1-a88e5f5.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":"dropFromCache.d.ts","sourceRoot":"","sources":["../../../src/cache/api/dropFromCache.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,4CAAyC,OAqBlE,CAAC"}
1
+ {"version":3,"file":"dropFromCache.d.ts","sourceRoot":"","sources":["../../../src/cache/api/dropFromCache.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,4CAAyC,OAsBlE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"pushToCache.d.ts","sourceRoot":"","sources":["../../../src/cache/api/pushToCache.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,WAAW,8BAEhB,OAAO,YACJ,MAAM,YAAY,KAC1B,OAmBF,CAAC"}
1
+ {"version":3,"file":"pushToCache.d.ts","sourceRoot":"","sources":["../../../src/cache/api/pushToCache.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,WAAW,8BAEhB,OAAO,YACJ,MAAM,YAAY,KAC1B,OAkBF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"queryCache.d.ts","sourceRoot":"","sources":["../../../src/cache/api/queryCache.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,UAAU,+EAWtB,CAAC"}
1
+ {"version":3,"file":"queryCache.d.ts","sourceRoot":"","sources":["../../../src/cache/api/queryCache.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,UAAU,+EActB,CAAC"}
package/dist/index.cjs.js CHANGED
@@ -1187,116 +1187,6 @@ const wipeCache = async (storageKey = 'amitySdk') => {
1187
1187
  return true;
1188
1188
  };
1189
1189
 
1190
- // Indexes never enter persisted cache data. Replacing data (restore/wipe/enable) starts a new index.
1191
- const indexes = new WeakMap();
1192
- const prefixesFor = (key) => {
1193
- if (typeof key[0] !== 'string')
1194
- return [];
1195
- const prefixes = [JSON.stringify([key[0]])];
1196
- if (typeof key[1] === 'string')
1197
- prefixes.push(JSON.stringify([key[0], key[1]]));
1198
- return prefixes;
1199
- };
1200
- const removePropertyValue = (property, indexed) => {
1201
- const previous = property.previousValues.get(indexed.encodedKey);
1202
- if (previous === undefined)
1203
- return;
1204
- const matches = property.values.get(previous);
1205
- matches.delete(indexed);
1206
- if (!matches.size)
1207
- property.values.delete(previous);
1208
- property.previousValues.delete(indexed.encodedKey);
1209
- };
1210
- const addPropertyValue = (data, property, indexed) => {
1211
- var _a;
1212
- if (!partialMatch(property.prefix, indexed.key))
1213
- return;
1214
- const value = (_a = data[indexed.encodedKey].data) === null || _a === void 0 ? void 0 : _a[property.property];
1215
- if (typeof value !== 'string')
1216
- return;
1217
- let matches = property.values.get(value);
1218
- if (!matches) {
1219
- matches = new Set();
1220
- property.values.set(value, matches);
1221
- }
1222
- matches.add(indexed);
1223
- property.previousValues.set(indexed.encodedKey, value);
1224
- };
1225
- const addKey = (index, encodedKey) => {
1226
- const indexed = { encodedKey, key: decodeKey(encodedKey), order: index.nextOrder };
1227
- index.nextOrder += 1; // eslint-disable-line no-param-reassign
1228
- index.keys.set(encodedKey, indexed);
1229
- prefixesFor(indexed.key).forEach(prefix => {
1230
- let keys = index.prefixes.get(prefix);
1231
- if (!keys) {
1232
- keys = new Map();
1233
- index.prefixes.set(prefix, keys);
1234
- }
1235
- keys.set(encodedKey, indexed);
1236
- });
1237
- return indexed;
1238
- };
1239
- const getIndex = (data) => {
1240
- let index = indexes.get(data);
1241
- if (!index) {
1242
- index = { keys: new Map(), prefixes: new Map(), properties: new Map(), nextOrder: 0 };
1243
- Object.keys(data).forEach(encodedKey => addKey(index, encodedKey));
1244
- indexes.set(data, index);
1245
- }
1246
- return index;
1247
- };
1248
- const candidatesFor = (index, key) => {
1249
- var _a, _b;
1250
- const prefixes = prefixesFor(key);
1251
- if (!prefixes.length)
1252
- return index.keys.values();
1253
- return (_b = (_a = index.prefixes.get(prefixes[prefixes.length - 1])) === null || _a === void 0 ? void 0 : _a.values()) !== null && _b !== void 0 ? _b : [];
1254
- };
1255
- /** @hidden */
1256
- const getMatchingCacheKeys = (data, key) => Array.from(candidatesFor(getIndex(data), key)).filter(indexed => partialMatch(key, indexed.key));
1257
- /** Update only an index that has already been used; writes alone need no index build. @hidden */
1258
- const updateCacheIndex = (data, encodedKey) => {
1259
- var _a;
1260
- const index = indexes.get(data);
1261
- if (!index)
1262
- return;
1263
- const indexed = (_a = index.keys.get(encodedKey)) !== null && _a !== void 0 ? _a : addKey(index, encodedKey);
1264
- index.properties.forEach(property => {
1265
- removePropertyValue(property, indexed);
1266
- addPropertyValue(data, property, indexed);
1267
- });
1268
- };
1269
- /** @hidden */
1270
- const removeFromCacheIndex = (data, encodedKey) => {
1271
- const index = indexes.get(data);
1272
- const indexed = index === null || index === void 0 ? void 0 : index.keys.get(encodedKey);
1273
- if (!index || !indexed)
1274
- return;
1275
- index.properties.forEach(property => removePropertyValue(property, indexed));
1276
- prefixesFor(indexed.key).forEach(prefix => {
1277
- const keys = index.prefixes.get(prefix);
1278
- keys.delete(encodedKey);
1279
- if (!keys.size)
1280
- index.prefixes.delete(prefix);
1281
- });
1282
- index.keys.delete(encodedKey);
1283
- };
1284
- /** Index a string model property within one domain/operation, retaining cache insertion order. @hidden */
1285
- const getCacheEntriesByProperty = (data, prefix, property, value) => {
1286
- var _a;
1287
- const index = getIndex(data);
1288
- const identity = JSON.stringify([prefix, property]);
1289
- let propertyIndex = index.properties.get(identity);
1290
- if (!propertyIndex) {
1291
- propertyIndex = { prefix, property, values: new Map(), previousValues: new Map() };
1292
- index.properties.set(identity, propertyIndex);
1293
- Array.from(candidatesFor(index, prefix)).forEach(indexed => addPropertyValue(data, propertyIndex, indexed));
1294
- }
1295
- return Array.from((_a = propertyIndex.values.get(value)) !== null && _a !== void 0 ? _a : [])
1296
- .sort((a, b) => a.order - b.order)
1297
- .map(({ encodedKey }) => data[encodedKey]);
1298
- };
1299
-
1300
1190
  /**
1301
1191
  * ```js
1302
1192
  * import { queryCache } from '@amityco/ts-sdk'
@@ -1317,7 +1207,12 @@ const queryCache = (key) => {
1317
1207
  if (!cache)
1318
1208
  return;
1319
1209
  log('cache/api/queryCache', { key });
1320
- return getMatchingCacheKeys(cache.data, key).map(({ encodedKey }) => cache.data[encodedKey]);
1210
+ return Object.keys(cache.data)
1211
+ .filter(stringKey => {
1212
+ const decodedKey = decodeKey(stringKey);
1213
+ return partialMatch(key, decodedKey);
1214
+ })
1215
+ .map(stringKey => cache.data[stringKey]);
1321
1216
  };
1322
1217
 
1323
1218
  /**
@@ -1373,7 +1268,6 @@ const pushToCache = (key, data, options = { cachedAt: Date.now() }) => {
1373
1268
  }
1374
1269
  const encodedKey = encodeKey(key);
1375
1270
  cache.data[encodedKey] = Object.assign({ key, data }, options);
1376
- updateCacheIndex(cache.data, encodedKey);
1377
1271
  return true;
1378
1272
  };
1379
1273
 
@@ -1458,14 +1352,15 @@ const dropFromCache = (key, exact = false) => {
1458
1352
  return false;
1459
1353
  log('cache/api/dropFromCache', { key, exact });
1460
1354
  if (!exact) {
1461
- return getMatchingCacheKeys(cache.data, key)
1462
- .map(({ key: filteredKey }) => dropFromCache(filteredKey, true))
1355
+ return Object.keys(cache.data)
1356
+ .map(stringKey => decodeKey(stringKey))
1357
+ .filter(candidate => partialMatch(key, candidate))
1358
+ .map(filteredKey => dropFromCache(filteredKey, true))
1463
1359
  .every(returned => returned);
1464
1360
  }
1465
1361
  const encodedKey = encodeKey(key);
1466
1362
  if (encodedKey in cache.data) {
1467
1363
  delete cache.data[encodedKey];
1468
- removeFromCacheIndex(cache.data, encodedKey);
1469
1364
  return true;
1470
1365
  }
1471
1366
  return false;
@@ -3854,20 +3749,13 @@ const getUserMarker = async () => {
3854
3749
  return { data: latestUserMarker, cachedAt };
3855
3750
  };
3856
3751
 
3857
- /** Internal model lookup; deliberately excluded from the public Cache API. @hidden */
3858
- const queryCacheByProperty = (prefix, property, value) => {
3859
- const { cache } = getActiveClient();
3860
- if (!cache)
3861
- return;
3862
- return getCacheEntriesByProperty(cache.data, prefix, property, value);
3863
- };
3864
-
3865
3752
  const getMessageFromMainDB = (messageId) => {
3866
- var _a, _b, _c;
3753
+ var _a, _b;
3867
3754
  const message = (_a = pullFromCache(['message', 'get', messageId])) === null || _a === void 0 ? void 0 : _a.data;
3868
3755
  if (message)
3869
3756
  return message;
3870
- return (_c = (_b = queryCacheByProperty(['message', 'get'], 'messageId', messageId)) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.data;
3757
+ const messages = queryCache(['message', 'get']);
3758
+ return (_b = messages === null || messages === void 0 ? void 0 : messages.find(({ data }) => data.messageId === messageId)) === null || _b === void 0 ? void 0 : _b.data;
3871
3759
  };
3872
3760
 
3873
3761
  /** @hidden */
@@ -4009,8 +3897,7 @@ function convertFromRaw$2(_a) {
4009
3897
 
4010
3898
  const mergePayloadWithLocal = (payload) => {
4011
3899
  var _a, _b, _c;
4012
- // Cache keys may be local referenceIds even after a server messageId is assigned.
4013
- const localMessage = (_b = (_a = queryCacheByProperty(['message', 'get'], 'messageId', payload.messageId)) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.data;
3900
+ const localMessage = (_b = (_a = queryCache(['message', 'get'])) === null || _a === void 0 ? void 0 : _a.find(({ data }) => data.messageId === payload.messageId)) === null || _b === void 0 ? void 0 : _b.data;
4014
3901
  if (localMessage) {
4015
3902
  return Object.assign(Object.assign(Object.assign({}, localMessage), payload), {
4016
3903
  // NOTE: referenceId is missing in the some payload event. If we have local message data with referenceId, use it instead.
@@ -5577,9 +5464,9 @@ const channelLinkedObject = (channel) => {
5577
5464
  var _a;
5578
5465
  let previewMembers = [];
5579
5466
  if (['conversation', 'community'].includes(channel.type)) {
5580
- const channelUsers = queryCacheByProperty(['channelUsers', 'get'], 'channelId', channel.channelId);
5467
+ const channelUsers = queryCache(['channelUsers', 'get']);
5581
5468
  if (channelUsers && (channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.length) > 0) {
5582
- previewMembers = ((_a = channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(({ data }) => data.membership !== 'none')) !== null && _a !== void 0 ? _a : [])
5469
+ previewMembers = ((_a = channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(({ data }) => data.channelId === channel.channelId && data.membership !== 'none')) !== null && _a !== void 0 ? _a : [])
5583
5470
  // sort in ascending order by userInternalId
5584
5471
  .sort((a, b) => a.data.userInternalId.localeCompare(b.data.userInternalId))
5585
5472
  // Select only first 4 members
package/dist/index.esm.js CHANGED
@@ -1171,116 +1171,6 @@ const wipeCache = async (storageKey = 'amitySdk') => {
1171
1171
  return true;
1172
1172
  };
1173
1173
 
1174
- // Indexes never enter persisted cache data. Replacing data (restore/wipe/enable) starts a new index.
1175
- const indexes = new WeakMap();
1176
- const prefixesFor = (key) => {
1177
- if (typeof key[0] !== 'string')
1178
- return [];
1179
- const prefixes = [JSON.stringify([key[0]])];
1180
- if (typeof key[1] === 'string')
1181
- prefixes.push(JSON.stringify([key[0], key[1]]));
1182
- return prefixes;
1183
- };
1184
- const removePropertyValue = (property, indexed) => {
1185
- const previous = property.previousValues.get(indexed.encodedKey);
1186
- if (previous === undefined)
1187
- return;
1188
- const matches = property.values.get(previous);
1189
- matches.delete(indexed);
1190
- if (!matches.size)
1191
- property.values.delete(previous);
1192
- property.previousValues.delete(indexed.encodedKey);
1193
- };
1194
- const addPropertyValue = (data, property, indexed) => {
1195
- var _a;
1196
- if (!partialMatch(property.prefix, indexed.key))
1197
- return;
1198
- const value = (_a = data[indexed.encodedKey].data) === null || _a === void 0 ? void 0 : _a[property.property];
1199
- if (typeof value !== 'string')
1200
- return;
1201
- let matches = property.values.get(value);
1202
- if (!matches) {
1203
- matches = new Set();
1204
- property.values.set(value, matches);
1205
- }
1206
- matches.add(indexed);
1207
- property.previousValues.set(indexed.encodedKey, value);
1208
- };
1209
- const addKey = (index, encodedKey) => {
1210
- const indexed = { encodedKey, key: decodeKey(encodedKey), order: index.nextOrder };
1211
- index.nextOrder += 1; // eslint-disable-line no-param-reassign
1212
- index.keys.set(encodedKey, indexed);
1213
- prefixesFor(indexed.key).forEach(prefix => {
1214
- let keys = index.prefixes.get(prefix);
1215
- if (!keys) {
1216
- keys = new Map();
1217
- index.prefixes.set(prefix, keys);
1218
- }
1219
- keys.set(encodedKey, indexed);
1220
- });
1221
- return indexed;
1222
- };
1223
- const getIndex = (data) => {
1224
- let index = indexes.get(data);
1225
- if (!index) {
1226
- index = { keys: new Map(), prefixes: new Map(), properties: new Map(), nextOrder: 0 };
1227
- Object.keys(data).forEach(encodedKey => addKey(index, encodedKey));
1228
- indexes.set(data, index);
1229
- }
1230
- return index;
1231
- };
1232
- const candidatesFor = (index, key) => {
1233
- var _a, _b;
1234
- const prefixes = prefixesFor(key);
1235
- if (!prefixes.length)
1236
- return index.keys.values();
1237
- return (_b = (_a = index.prefixes.get(prefixes[prefixes.length - 1])) === null || _a === void 0 ? void 0 : _a.values()) !== null && _b !== void 0 ? _b : [];
1238
- };
1239
- /** @hidden */
1240
- const getMatchingCacheKeys = (data, key) => Array.from(candidatesFor(getIndex(data), key)).filter(indexed => partialMatch(key, indexed.key));
1241
- /** Update only an index that has already been used; writes alone need no index build. @hidden */
1242
- const updateCacheIndex = (data, encodedKey) => {
1243
- var _a;
1244
- const index = indexes.get(data);
1245
- if (!index)
1246
- return;
1247
- const indexed = (_a = index.keys.get(encodedKey)) !== null && _a !== void 0 ? _a : addKey(index, encodedKey);
1248
- index.properties.forEach(property => {
1249
- removePropertyValue(property, indexed);
1250
- addPropertyValue(data, property, indexed);
1251
- });
1252
- };
1253
- /** @hidden */
1254
- const removeFromCacheIndex = (data, encodedKey) => {
1255
- const index = indexes.get(data);
1256
- const indexed = index === null || index === void 0 ? void 0 : index.keys.get(encodedKey);
1257
- if (!index || !indexed)
1258
- return;
1259
- index.properties.forEach(property => removePropertyValue(property, indexed));
1260
- prefixesFor(indexed.key).forEach(prefix => {
1261
- const keys = index.prefixes.get(prefix);
1262
- keys.delete(encodedKey);
1263
- if (!keys.size)
1264
- index.prefixes.delete(prefix);
1265
- });
1266
- index.keys.delete(encodedKey);
1267
- };
1268
- /** Index a string model property within one domain/operation, retaining cache insertion order. @hidden */
1269
- const getCacheEntriesByProperty = (data, prefix, property, value) => {
1270
- var _a;
1271
- const index = getIndex(data);
1272
- const identity = JSON.stringify([prefix, property]);
1273
- let propertyIndex = index.properties.get(identity);
1274
- if (!propertyIndex) {
1275
- propertyIndex = { prefix, property, values: new Map(), previousValues: new Map() };
1276
- index.properties.set(identity, propertyIndex);
1277
- Array.from(candidatesFor(index, prefix)).forEach(indexed => addPropertyValue(data, propertyIndex, indexed));
1278
- }
1279
- return Array.from((_a = propertyIndex.values.get(value)) !== null && _a !== void 0 ? _a : [])
1280
- .sort((a, b) => a.order - b.order)
1281
- .map(({ encodedKey }) => data[encodedKey]);
1282
- };
1283
-
1284
1174
  /**
1285
1175
  * ```js
1286
1176
  * import { queryCache } from '@amityco/ts-sdk'
@@ -1301,7 +1191,12 @@ const queryCache = (key) => {
1301
1191
  if (!cache)
1302
1192
  return;
1303
1193
  log('cache/api/queryCache', { key });
1304
- return getMatchingCacheKeys(cache.data, key).map(({ encodedKey }) => cache.data[encodedKey]);
1194
+ return Object.keys(cache.data)
1195
+ .filter(stringKey => {
1196
+ const decodedKey = decodeKey(stringKey);
1197
+ return partialMatch(key, decodedKey);
1198
+ })
1199
+ .map(stringKey => cache.data[stringKey]);
1305
1200
  };
1306
1201
 
1307
1202
  /**
@@ -1357,7 +1252,6 @@ const pushToCache = (key, data, options = { cachedAt: Date.now() }) => {
1357
1252
  }
1358
1253
  const encodedKey = encodeKey(key);
1359
1254
  cache.data[encodedKey] = Object.assign({ key, data }, options);
1360
- updateCacheIndex(cache.data, encodedKey);
1361
1255
  return true;
1362
1256
  };
1363
1257
 
@@ -1442,14 +1336,15 @@ const dropFromCache = (key, exact = false) => {
1442
1336
  return false;
1443
1337
  log('cache/api/dropFromCache', { key, exact });
1444
1338
  if (!exact) {
1445
- return getMatchingCacheKeys(cache.data, key)
1446
- .map(({ key: filteredKey }) => dropFromCache(filteredKey, true))
1339
+ return Object.keys(cache.data)
1340
+ .map(stringKey => decodeKey(stringKey))
1341
+ .filter(candidate => partialMatch(key, candidate))
1342
+ .map(filteredKey => dropFromCache(filteredKey, true))
1447
1343
  .every(returned => returned);
1448
1344
  }
1449
1345
  const encodedKey = encodeKey(key);
1450
1346
  if (encodedKey in cache.data) {
1451
1347
  delete cache.data[encodedKey];
1452
- removeFromCacheIndex(cache.data, encodedKey);
1453
1348
  return true;
1454
1349
  }
1455
1350
  return false;
@@ -3854,20 +3749,13 @@ const getUserMarker = async () => {
3854
3749
  return { data: latestUserMarker, cachedAt };
3855
3750
  };
3856
3751
 
3857
- /** Internal model lookup; deliberately excluded from the public Cache API. @hidden */
3858
- const queryCacheByProperty = (prefix, property, value) => {
3859
- const { cache } = getActiveClient();
3860
- if (!cache)
3861
- return;
3862
- return getCacheEntriesByProperty(cache.data, prefix, property, value);
3863
- };
3864
-
3865
3752
  const getMessageFromMainDB = (messageId) => {
3866
- var _a, _b, _c;
3753
+ var _a, _b;
3867
3754
  const message = (_a = pullFromCache(['message', 'get', messageId])) === null || _a === void 0 ? void 0 : _a.data;
3868
3755
  if (message)
3869
3756
  return message;
3870
- return (_c = (_b = queryCacheByProperty(['message', 'get'], 'messageId', messageId)) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.data;
3757
+ const messages = queryCache(['message', 'get']);
3758
+ return (_b = messages === null || messages === void 0 ? void 0 : messages.find(({ data }) => data.messageId === messageId)) === null || _b === void 0 ? void 0 : _b.data;
3871
3759
  };
3872
3760
 
3873
3761
  /** @hidden */
@@ -4009,8 +3897,7 @@ function convertFromRaw$2(_a) {
4009
3897
 
4010
3898
  const mergePayloadWithLocal = (payload) => {
4011
3899
  var _a, _b, _c;
4012
- // Cache keys may be local referenceIds even after a server messageId is assigned.
4013
- const localMessage = (_b = (_a = queryCacheByProperty(['message', 'get'], 'messageId', payload.messageId)) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.data;
3900
+ const localMessage = (_b = (_a = queryCache(['message', 'get'])) === null || _a === void 0 ? void 0 : _a.find(({ data }) => data.messageId === payload.messageId)) === null || _b === void 0 ? void 0 : _b.data;
4014
3901
  if (localMessage) {
4015
3902
  return Object.assign(Object.assign(Object.assign({}, localMessage), payload), {
4016
3903
  // NOTE: referenceId is missing in the some payload event. If we have local message data with referenceId, use it instead.
@@ -5577,9 +5464,9 @@ const channelLinkedObject = (channel) => {
5577
5464
  var _a;
5578
5465
  let previewMembers = [];
5579
5466
  if (['conversation', 'community'].includes(channel.type)) {
5580
- const channelUsers = queryCacheByProperty(['channelUsers', 'get'], 'channelId', channel.channelId);
5467
+ const channelUsers = queryCache(['channelUsers', 'get']);
5581
5468
  if (channelUsers && (channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.length) > 0) {
5582
- previewMembers = ((_a = channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(({ data }) => data.membership !== 'none')) !== null && _a !== void 0 ? _a : [])
5469
+ previewMembers = ((_a = channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(({ data }) => data.channelId === channel.channelId && data.membership !== 'none')) !== null && _a !== void 0 ? _a : [])
5583
5470
  // sort in ascending order by userInternalId
5584
5471
  .sort((a, b) => a.data.userInternalId.localeCompare(b.data.userInternalId))
5585
5472
  // Select only first 4 members