@amityco/ts-sdk 7.32.0 → 7.32.1-23b143a2.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/dist/cache/api/dropFromCache.d.ts.map +1 -1
- package/dist/cache/api/pushToCache.d.ts.map +1 -1
- package/dist/cache/api/queryCache.d.ts.map +1 -1
- package/dist/cache/api/queryCacheByProperty.d.ts +3 -0
- package/dist/cache/api/queryCacheByProperty.d.ts.map +1 -0
- package/dist/cache/api/tests/queryCache.test.d.ts +2 -0
- package/dist/cache/api/tests/queryCache.test.d.ts.map +1 -0
- package/dist/cache/utils/cacheIndex.d.ts +15 -0
- package/dist/cache/utils/cacheIndex.d.ts.map +1 -0
- package/dist/index.cjs.js +130 -17
- package/dist/index.esm.js +130 -17
- package/dist/index.umd.js +2 -2
- package/dist/messageRepository/utils/getMessageFromMainDB.d.ts.map +1 -1
- package/dist/messageRepository/utils/prepareMessagePayload.d.ts.map +1 -1
- package/dist/utils/linkedObject/channelLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/tests/channelCachePerformance.test.d.ts +2 -0
- package/dist/utils/linkedObject/tests/channelCachePerformance.test.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dropFromCache.d.ts","sourceRoot":"","sources":["../../../src/cache/api/dropFromCache.ts"],"names":[],"mappings":"
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pushToCache.d.ts","sourceRoot":"","sources":["../../../src/cache/api/pushToCache.ts"],"names":[],"mappings":"
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryCache.d.ts","sourceRoot":"","sources":["../../../src/cache/api/queryCache.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,UAAU,+
|
|
1
|
+
{"version":3,"file":"queryCache.d.ts","sourceRoot":"","sources":["../../../src/cache/api/queryCache.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,UAAU,+EAWtB,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** Internal model lookup; deliberately excluded from the public Cache API. @hidden */
|
|
2
|
+
export declare const queryCacheByProperty: <T>(prefix: [string, string], property: keyof T & string, value: string) => Amity.CacheEntry<T>[] | undefined;
|
|
3
|
+
//# sourceMappingURL=queryCacheByProperty.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryCacheByProperty.d.ts","sourceRoot":"","sources":["../../../src/cache/api/queryCacheByProperty.ts"],"names":[],"mappings":"AAGA,sFAAsF;AACtF,eAAO,MAAM,oBAAoB,cACvB,CAAC,MAAM,EAAE,MAAM,CAAC,qCAEjB,MAAM,sCAKd,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryCache.test.d.ts","sourceRoot":"","sources":["../../../../src/cache/api/tests/queryCache.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare type IndexedKey = {
|
|
2
|
+
encodedKey: string;
|
|
3
|
+
key: Amity.CacheKey;
|
|
4
|
+
order: number;
|
|
5
|
+
};
|
|
6
|
+
/** @hidden */
|
|
7
|
+
export declare const getMatchingCacheKeys: (data: Amity.Cache['data'], key: Amity.CacheKey) => IndexedKey[];
|
|
8
|
+
/** Update only an index that has already been used; writes alone need no index build. @hidden */
|
|
9
|
+
export declare const updateCacheIndex: (data: Amity.Cache['data'], encodedKey: string) => void;
|
|
10
|
+
/** @hidden */
|
|
11
|
+
export declare const removeFromCacheIndex: (data: Amity.Cache['data'], encodedKey: string) => void;
|
|
12
|
+
/** Index a string model property within one domain/operation, retaining cache insertion order. @hidden */
|
|
13
|
+
export declare const getCacheEntriesByProperty: <T>(data: Amity.Cache['data'], prefix: [string, string], property: string, value: string) => Amity.CacheEntry<T>[];
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=cacheIndex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cacheIndex.d.ts","sourceRoot":"","sources":["../../../src/cache/utils/cacheIndex.ts"],"names":[],"mappings":"AAEA,aAAK,UAAU,GAAG;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,KAAK,CAAC,QAAQ,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAsFF,cAAc;AACd,eAAO,MAAM,oBAAoB,SAAU,WAAW,CAAC,MAAM,CAAC,sCACoC,CAAC;AAEnG,iGAAiG;AACjG,eAAO,MAAM,gBAAgB,SAAU,WAAW,CAAC,MAAM,CAAC,cAAc,MAAM,SAQ7E,CAAC;AAEF,cAAc;AACd,eAAO,MAAM,oBAAoB,SAAU,WAAW,CAAC,MAAM,CAAC,cAAc,MAAM,SAWjF,CAAC;AAEF,0GAA0G;AAC1G,eAAO,MAAM,yBAAyB,YAC9B,WAAW,CAAC,MAAM,CAAC,UACjB,CAAC,MAAM,EAAE,MAAM,CAAC,YACd,MAAM,SACT,MAAM,0BAed,CAAC"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -1184,6 +1184,116 @@ const wipeCache = async (storageKey = 'amitySdk') => {
|
|
|
1184
1184
|
return true;
|
|
1185
1185
|
};
|
|
1186
1186
|
|
|
1187
|
+
// Indexes never enter persisted cache data. Replacing data (restore/wipe/enable) starts a new index.
|
|
1188
|
+
const indexes = new WeakMap();
|
|
1189
|
+
const prefixesFor = (key) => {
|
|
1190
|
+
if (typeof key[0] !== 'string')
|
|
1191
|
+
return [];
|
|
1192
|
+
const prefixes = [JSON.stringify([key[0]])];
|
|
1193
|
+
if (typeof key[1] === 'string')
|
|
1194
|
+
prefixes.push(JSON.stringify([key[0], key[1]]));
|
|
1195
|
+
return prefixes;
|
|
1196
|
+
};
|
|
1197
|
+
const removePropertyValue = (property, indexed) => {
|
|
1198
|
+
const previous = property.previousValues.get(indexed.encodedKey);
|
|
1199
|
+
if (previous === undefined)
|
|
1200
|
+
return;
|
|
1201
|
+
const matches = property.values.get(previous);
|
|
1202
|
+
matches.delete(indexed);
|
|
1203
|
+
if (!matches.size)
|
|
1204
|
+
property.values.delete(previous);
|
|
1205
|
+
property.previousValues.delete(indexed.encodedKey);
|
|
1206
|
+
};
|
|
1207
|
+
const addPropertyValue = (data, property, indexed) => {
|
|
1208
|
+
var _a;
|
|
1209
|
+
if (!partialMatch(property.prefix, indexed.key))
|
|
1210
|
+
return;
|
|
1211
|
+
const value = (_a = data[indexed.encodedKey].data) === null || _a === void 0 ? void 0 : _a[property.property];
|
|
1212
|
+
if (typeof value !== 'string')
|
|
1213
|
+
return;
|
|
1214
|
+
let matches = property.values.get(value);
|
|
1215
|
+
if (!matches) {
|
|
1216
|
+
matches = new Set();
|
|
1217
|
+
property.values.set(value, matches);
|
|
1218
|
+
}
|
|
1219
|
+
matches.add(indexed);
|
|
1220
|
+
property.previousValues.set(indexed.encodedKey, value);
|
|
1221
|
+
};
|
|
1222
|
+
const addKey = (index, encodedKey) => {
|
|
1223
|
+
const indexed = { encodedKey, key: decodeKey(encodedKey), order: index.nextOrder };
|
|
1224
|
+
index.nextOrder += 1; // eslint-disable-line no-param-reassign
|
|
1225
|
+
index.keys.set(encodedKey, indexed);
|
|
1226
|
+
prefixesFor(indexed.key).forEach(prefix => {
|
|
1227
|
+
let keys = index.prefixes.get(prefix);
|
|
1228
|
+
if (!keys) {
|
|
1229
|
+
keys = new Map();
|
|
1230
|
+
index.prefixes.set(prefix, keys);
|
|
1231
|
+
}
|
|
1232
|
+
keys.set(encodedKey, indexed);
|
|
1233
|
+
});
|
|
1234
|
+
return indexed;
|
|
1235
|
+
};
|
|
1236
|
+
const getIndex = (data) => {
|
|
1237
|
+
let index = indexes.get(data);
|
|
1238
|
+
if (!index) {
|
|
1239
|
+
index = { keys: new Map(), prefixes: new Map(), properties: new Map(), nextOrder: 0 };
|
|
1240
|
+
Object.keys(data).forEach(encodedKey => addKey(index, encodedKey));
|
|
1241
|
+
indexes.set(data, index);
|
|
1242
|
+
}
|
|
1243
|
+
return index;
|
|
1244
|
+
};
|
|
1245
|
+
const candidatesFor = (index, key) => {
|
|
1246
|
+
var _a, _b;
|
|
1247
|
+
const prefixes = prefixesFor(key);
|
|
1248
|
+
if (!prefixes.length)
|
|
1249
|
+
return index.keys.values();
|
|
1250
|
+
return (_b = (_a = index.prefixes.get(prefixes[prefixes.length - 1])) === null || _a === void 0 ? void 0 : _a.values()) !== null && _b !== void 0 ? _b : [];
|
|
1251
|
+
};
|
|
1252
|
+
/** @hidden */
|
|
1253
|
+
const getMatchingCacheKeys = (data, key) => Array.from(candidatesFor(getIndex(data), key)).filter(indexed => partialMatch(key, indexed.key));
|
|
1254
|
+
/** Update only an index that has already been used; writes alone need no index build. @hidden */
|
|
1255
|
+
const updateCacheIndex = (data, encodedKey) => {
|
|
1256
|
+
var _a;
|
|
1257
|
+
const index = indexes.get(data);
|
|
1258
|
+
if (!index)
|
|
1259
|
+
return;
|
|
1260
|
+
const indexed = (_a = index.keys.get(encodedKey)) !== null && _a !== void 0 ? _a : addKey(index, encodedKey);
|
|
1261
|
+
index.properties.forEach(property => {
|
|
1262
|
+
removePropertyValue(property, indexed);
|
|
1263
|
+
addPropertyValue(data, property, indexed);
|
|
1264
|
+
});
|
|
1265
|
+
};
|
|
1266
|
+
/** @hidden */
|
|
1267
|
+
const removeFromCacheIndex = (data, encodedKey) => {
|
|
1268
|
+
const index = indexes.get(data);
|
|
1269
|
+
const indexed = index === null || index === void 0 ? void 0 : index.keys.get(encodedKey);
|
|
1270
|
+
if (!index || !indexed)
|
|
1271
|
+
return;
|
|
1272
|
+
index.properties.forEach(property => removePropertyValue(property, indexed));
|
|
1273
|
+
prefixesFor(indexed.key).forEach(prefix => {
|
|
1274
|
+
const keys = index.prefixes.get(prefix);
|
|
1275
|
+
keys.delete(encodedKey);
|
|
1276
|
+
if (!keys.size)
|
|
1277
|
+
index.prefixes.delete(prefix);
|
|
1278
|
+
});
|
|
1279
|
+
index.keys.delete(encodedKey);
|
|
1280
|
+
};
|
|
1281
|
+
/** Index a string model property within one domain/operation, retaining cache insertion order. @hidden */
|
|
1282
|
+
const getCacheEntriesByProperty = (data, prefix, property, value) => {
|
|
1283
|
+
var _a;
|
|
1284
|
+
const index = getIndex(data);
|
|
1285
|
+
const identity = JSON.stringify([prefix, property]);
|
|
1286
|
+
let propertyIndex = index.properties.get(identity);
|
|
1287
|
+
if (!propertyIndex) {
|
|
1288
|
+
propertyIndex = { prefix, property, values: new Map(), previousValues: new Map() };
|
|
1289
|
+
index.properties.set(identity, propertyIndex);
|
|
1290
|
+
Array.from(candidatesFor(index, prefix)).forEach(indexed => addPropertyValue(data, propertyIndex, indexed));
|
|
1291
|
+
}
|
|
1292
|
+
return Array.from((_a = propertyIndex.values.get(value)) !== null && _a !== void 0 ? _a : [])
|
|
1293
|
+
.sort((a, b) => a.order - b.order)
|
|
1294
|
+
.map(({ encodedKey }) => data[encodedKey]);
|
|
1295
|
+
};
|
|
1296
|
+
|
|
1187
1297
|
/**
|
|
1188
1298
|
* ```js
|
|
1189
1299
|
* import { queryCache } from '@amityco/ts-sdk'
|
|
@@ -1204,12 +1314,7 @@ const queryCache = (key) => {
|
|
|
1204
1314
|
if (!cache)
|
|
1205
1315
|
return;
|
|
1206
1316
|
log('cache/api/queryCache', { key });
|
|
1207
|
-
return
|
|
1208
|
-
.filter(stringKey => {
|
|
1209
|
-
const decodedKey = decodeKey(stringKey);
|
|
1210
|
-
return partialMatch(key, decodedKey);
|
|
1211
|
-
})
|
|
1212
|
-
.map(stringKey => cache.data[stringKey]);
|
|
1317
|
+
return getMatchingCacheKeys(cache.data, key).map(({ encodedKey }) => cache.data[encodedKey]);
|
|
1213
1318
|
};
|
|
1214
1319
|
|
|
1215
1320
|
/**
|
|
@@ -1265,6 +1370,7 @@ const pushToCache = (key, data, options = { cachedAt: Date.now() }) => {
|
|
|
1265
1370
|
}
|
|
1266
1371
|
const encodedKey = encodeKey(key);
|
|
1267
1372
|
cache.data[encodedKey] = Object.assign({ key, data }, options);
|
|
1373
|
+
updateCacheIndex(cache.data, encodedKey);
|
|
1268
1374
|
return true;
|
|
1269
1375
|
};
|
|
1270
1376
|
|
|
@@ -1349,15 +1455,14 @@ const dropFromCache = (key, exact = false) => {
|
|
|
1349
1455
|
return false;
|
|
1350
1456
|
log('cache/api/dropFromCache', { key, exact });
|
|
1351
1457
|
if (!exact) {
|
|
1352
|
-
return
|
|
1353
|
-
.map(
|
|
1354
|
-
.filter(candidate => partialMatch(key, candidate))
|
|
1355
|
-
.map(filteredKey => dropFromCache(filteredKey, true))
|
|
1458
|
+
return getMatchingCacheKeys(cache.data, key)
|
|
1459
|
+
.map(({ key: filteredKey }) => dropFromCache(filteredKey, true))
|
|
1356
1460
|
.every(returned => returned);
|
|
1357
1461
|
}
|
|
1358
1462
|
const encodedKey = encodeKey(key);
|
|
1359
1463
|
if (encodedKey in cache.data) {
|
|
1360
1464
|
delete cache.data[encodedKey];
|
|
1465
|
+
removeFromCacheIndex(cache.data, encodedKey);
|
|
1361
1466
|
return true;
|
|
1362
1467
|
}
|
|
1363
1468
|
return false;
|
|
@@ -3746,13 +3851,20 @@ const getUserMarker = async () => {
|
|
|
3746
3851
|
return { data: latestUserMarker, cachedAt };
|
|
3747
3852
|
};
|
|
3748
3853
|
|
|
3854
|
+
/** Internal model lookup; deliberately excluded from the public Cache API. @hidden */
|
|
3855
|
+
const queryCacheByProperty = (prefix, property, value) => {
|
|
3856
|
+
const { cache } = getActiveClient();
|
|
3857
|
+
if (!cache)
|
|
3858
|
+
return;
|
|
3859
|
+
return getCacheEntriesByProperty(cache.data, prefix, property, value);
|
|
3860
|
+
};
|
|
3861
|
+
|
|
3749
3862
|
const getMessageFromMainDB = (messageId) => {
|
|
3750
|
-
var _a, _b;
|
|
3863
|
+
var _a, _b, _c;
|
|
3751
3864
|
const message = (_a = pullFromCache(['message', 'get', messageId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
3752
3865
|
if (message)
|
|
3753
3866
|
return message;
|
|
3754
|
-
|
|
3755
|
-
return (_b = messages === null || messages === void 0 ? void 0 : messages.find(({ data }) => data.messageId === messageId)) === null || _b === void 0 ? void 0 : _b.data;
|
|
3867
|
+
return (_c = (_b = queryCacheByProperty(['message', 'get'], 'messageId', messageId)) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.data;
|
|
3756
3868
|
};
|
|
3757
3869
|
|
|
3758
3870
|
/** @hidden */
|
|
@@ -3894,7 +4006,8 @@ function convertFromRaw$2(_a) {
|
|
|
3894
4006
|
|
|
3895
4007
|
const mergePayloadWithLocal = (payload) => {
|
|
3896
4008
|
var _a, _b, _c;
|
|
3897
|
-
|
|
4009
|
+
// Cache keys may be local referenceIds even after a server messageId is assigned.
|
|
4010
|
+
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;
|
|
3898
4011
|
if (localMessage) {
|
|
3899
4012
|
return Object.assign(Object.assign(Object.assign({}, localMessage), payload), {
|
|
3900
4013
|
// NOTE: referenceId is missing in the some payload event. If we have local message data with referenceId, use it instead.
|
|
@@ -5461,9 +5574,9 @@ const channelLinkedObject = (channel) => {
|
|
|
5461
5574
|
var _a;
|
|
5462
5575
|
let previewMembers = [];
|
|
5463
5576
|
if (['conversation', 'community'].includes(channel.type)) {
|
|
5464
|
-
const channelUsers =
|
|
5577
|
+
const channelUsers = queryCacheByProperty(['channelUsers', 'get'], 'channelId', channel.channelId);
|
|
5465
5578
|
if (channelUsers && (channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.length) > 0) {
|
|
5466
|
-
previewMembers = ((_a = channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(({ data }) => data.
|
|
5579
|
+
previewMembers = ((_a = channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(({ data }) => data.membership !== 'none')) !== null && _a !== void 0 ? _a : [])
|
|
5467
5580
|
// sort in ascending order by userInternalId
|
|
5468
5581
|
.sort((a, b) => a.data.userInternalId.localeCompare(b.data.userInternalId))
|
|
5469
5582
|
// Select only first 4 members
|
|
@@ -14026,7 +14139,7 @@ const getWatchSessionStorage = () => {
|
|
|
14026
14139
|
return storageInstance;
|
|
14027
14140
|
};
|
|
14028
14141
|
|
|
14029
|
-
const privateKey = "
|
|
14142
|
+
const privateKey = "MIIEpQIBAAKCAQEAwAEc/oZgYIvKSUG/C3mONYLR4ZPgAjMEX4bJ+xqqakUDRtqlNO+eZs2blQ1Ko0DBkqPExyQezvjibH5W2UZBV5RaBTlTcNVKTToMBEGesAfaEcM3qUyQHxdbFYZv6P4sb14dcwxTQ8usmaV8ooiR1Fcaso5ZWYcZ8Hb46FbQ7OoVumsBtPWwfZ4f003o5VCl6AIM6lcLv9UDLlFVYhE+PeXpRHtfWlGqxMvqC9oinlwhL6nWv6VjQXW4nhcib72dPBzfHT7k/PMKto2SxALYdb68ENiAGuJLWi3AUHSyYCJK2w7wIlWfJUAI0v26ub10IpExr6D5QuW2577jjP93iwIDAQABAoIBAFWfqXhwIIatkFY+9Z1+ZcbDQimgsmMIsUiQaX6Lk7e0cxOj6czDlxYtVtaPiNtow2pLkjNkjkCqiP7tEHnwdK9DvylZOTa2R15NJpK3WLcTqVIGhsn/FL5owfv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F/H/59LcSx2Bh28fp3/efiVIOpVd4Y=";
|
|
14030
14143
|
/*
|
|
14031
14144
|
* The crypto algorithm used for importing key and signing string
|
|
14032
14145
|
*/
|
package/dist/index.esm.js
CHANGED
|
@@ -1168,6 +1168,116 @@ const wipeCache = async (storageKey = 'amitySdk') => {
|
|
|
1168
1168
|
return true;
|
|
1169
1169
|
};
|
|
1170
1170
|
|
|
1171
|
+
// Indexes never enter persisted cache data. Replacing data (restore/wipe/enable) starts a new index.
|
|
1172
|
+
const indexes = new WeakMap();
|
|
1173
|
+
const prefixesFor = (key) => {
|
|
1174
|
+
if (typeof key[0] !== 'string')
|
|
1175
|
+
return [];
|
|
1176
|
+
const prefixes = [JSON.stringify([key[0]])];
|
|
1177
|
+
if (typeof key[1] === 'string')
|
|
1178
|
+
prefixes.push(JSON.stringify([key[0], key[1]]));
|
|
1179
|
+
return prefixes;
|
|
1180
|
+
};
|
|
1181
|
+
const removePropertyValue = (property, indexed) => {
|
|
1182
|
+
const previous = property.previousValues.get(indexed.encodedKey);
|
|
1183
|
+
if (previous === undefined)
|
|
1184
|
+
return;
|
|
1185
|
+
const matches = property.values.get(previous);
|
|
1186
|
+
matches.delete(indexed);
|
|
1187
|
+
if (!matches.size)
|
|
1188
|
+
property.values.delete(previous);
|
|
1189
|
+
property.previousValues.delete(indexed.encodedKey);
|
|
1190
|
+
};
|
|
1191
|
+
const addPropertyValue = (data, property, indexed) => {
|
|
1192
|
+
var _a;
|
|
1193
|
+
if (!partialMatch(property.prefix, indexed.key))
|
|
1194
|
+
return;
|
|
1195
|
+
const value = (_a = data[indexed.encodedKey].data) === null || _a === void 0 ? void 0 : _a[property.property];
|
|
1196
|
+
if (typeof value !== 'string')
|
|
1197
|
+
return;
|
|
1198
|
+
let matches = property.values.get(value);
|
|
1199
|
+
if (!matches) {
|
|
1200
|
+
matches = new Set();
|
|
1201
|
+
property.values.set(value, matches);
|
|
1202
|
+
}
|
|
1203
|
+
matches.add(indexed);
|
|
1204
|
+
property.previousValues.set(indexed.encodedKey, value);
|
|
1205
|
+
};
|
|
1206
|
+
const addKey = (index, encodedKey) => {
|
|
1207
|
+
const indexed = { encodedKey, key: decodeKey(encodedKey), order: index.nextOrder };
|
|
1208
|
+
index.nextOrder += 1; // eslint-disable-line no-param-reassign
|
|
1209
|
+
index.keys.set(encodedKey, indexed);
|
|
1210
|
+
prefixesFor(indexed.key).forEach(prefix => {
|
|
1211
|
+
let keys = index.prefixes.get(prefix);
|
|
1212
|
+
if (!keys) {
|
|
1213
|
+
keys = new Map();
|
|
1214
|
+
index.prefixes.set(prefix, keys);
|
|
1215
|
+
}
|
|
1216
|
+
keys.set(encodedKey, indexed);
|
|
1217
|
+
});
|
|
1218
|
+
return indexed;
|
|
1219
|
+
};
|
|
1220
|
+
const getIndex = (data) => {
|
|
1221
|
+
let index = indexes.get(data);
|
|
1222
|
+
if (!index) {
|
|
1223
|
+
index = { keys: new Map(), prefixes: new Map(), properties: new Map(), nextOrder: 0 };
|
|
1224
|
+
Object.keys(data).forEach(encodedKey => addKey(index, encodedKey));
|
|
1225
|
+
indexes.set(data, index);
|
|
1226
|
+
}
|
|
1227
|
+
return index;
|
|
1228
|
+
};
|
|
1229
|
+
const candidatesFor = (index, key) => {
|
|
1230
|
+
var _a, _b;
|
|
1231
|
+
const prefixes = prefixesFor(key);
|
|
1232
|
+
if (!prefixes.length)
|
|
1233
|
+
return index.keys.values();
|
|
1234
|
+
return (_b = (_a = index.prefixes.get(prefixes[prefixes.length - 1])) === null || _a === void 0 ? void 0 : _a.values()) !== null && _b !== void 0 ? _b : [];
|
|
1235
|
+
};
|
|
1236
|
+
/** @hidden */
|
|
1237
|
+
const getMatchingCacheKeys = (data, key) => Array.from(candidatesFor(getIndex(data), key)).filter(indexed => partialMatch(key, indexed.key));
|
|
1238
|
+
/** Update only an index that has already been used; writes alone need no index build. @hidden */
|
|
1239
|
+
const updateCacheIndex = (data, encodedKey) => {
|
|
1240
|
+
var _a;
|
|
1241
|
+
const index = indexes.get(data);
|
|
1242
|
+
if (!index)
|
|
1243
|
+
return;
|
|
1244
|
+
const indexed = (_a = index.keys.get(encodedKey)) !== null && _a !== void 0 ? _a : addKey(index, encodedKey);
|
|
1245
|
+
index.properties.forEach(property => {
|
|
1246
|
+
removePropertyValue(property, indexed);
|
|
1247
|
+
addPropertyValue(data, property, indexed);
|
|
1248
|
+
});
|
|
1249
|
+
};
|
|
1250
|
+
/** @hidden */
|
|
1251
|
+
const removeFromCacheIndex = (data, encodedKey) => {
|
|
1252
|
+
const index = indexes.get(data);
|
|
1253
|
+
const indexed = index === null || index === void 0 ? void 0 : index.keys.get(encodedKey);
|
|
1254
|
+
if (!index || !indexed)
|
|
1255
|
+
return;
|
|
1256
|
+
index.properties.forEach(property => removePropertyValue(property, indexed));
|
|
1257
|
+
prefixesFor(indexed.key).forEach(prefix => {
|
|
1258
|
+
const keys = index.prefixes.get(prefix);
|
|
1259
|
+
keys.delete(encodedKey);
|
|
1260
|
+
if (!keys.size)
|
|
1261
|
+
index.prefixes.delete(prefix);
|
|
1262
|
+
});
|
|
1263
|
+
index.keys.delete(encodedKey);
|
|
1264
|
+
};
|
|
1265
|
+
/** Index a string model property within one domain/operation, retaining cache insertion order. @hidden */
|
|
1266
|
+
const getCacheEntriesByProperty = (data, prefix, property, value) => {
|
|
1267
|
+
var _a;
|
|
1268
|
+
const index = getIndex(data);
|
|
1269
|
+
const identity = JSON.stringify([prefix, property]);
|
|
1270
|
+
let propertyIndex = index.properties.get(identity);
|
|
1271
|
+
if (!propertyIndex) {
|
|
1272
|
+
propertyIndex = { prefix, property, values: new Map(), previousValues: new Map() };
|
|
1273
|
+
index.properties.set(identity, propertyIndex);
|
|
1274
|
+
Array.from(candidatesFor(index, prefix)).forEach(indexed => addPropertyValue(data, propertyIndex, indexed));
|
|
1275
|
+
}
|
|
1276
|
+
return Array.from((_a = propertyIndex.values.get(value)) !== null && _a !== void 0 ? _a : [])
|
|
1277
|
+
.sort((a, b) => a.order - b.order)
|
|
1278
|
+
.map(({ encodedKey }) => data[encodedKey]);
|
|
1279
|
+
};
|
|
1280
|
+
|
|
1171
1281
|
/**
|
|
1172
1282
|
* ```js
|
|
1173
1283
|
* import { queryCache } from '@amityco/ts-sdk'
|
|
@@ -1188,12 +1298,7 @@ const queryCache = (key) => {
|
|
|
1188
1298
|
if (!cache)
|
|
1189
1299
|
return;
|
|
1190
1300
|
log('cache/api/queryCache', { key });
|
|
1191
|
-
return
|
|
1192
|
-
.filter(stringKey => {
|
|
1193
|
-
const decodedKey = decodeKey(stringKey);
|
|
1194
|
-
return partialMatch(key, decodedKey);
|
|
1195
|
-
})
|
|
1196
|
-
.map(stringKey => cache.data[stringKey]);
|
|
1301
|
+
return getMatchingCacheKeys(cache.data, key).map(({ encodedKey }) => cache.data[encodedKey]);
|
|
1197
1302
|
};
|
|
1198
1303
|
|
|
1199
1304
|
/**
|
|
@@ -1249,6 +1354,7 @@ const pushToCache = (key, data, options = { cachedAt: Date.now() }) => {
|
|
|
1249
1354
|
}
|
|
1250
1355
|
const encodedKey = encodeKey(key);
|
|
1251
1356
|
cache.data[encodedKey] = Object.assign({ key, data }, options);
|
|
1357
|
+
updateCacheIndex(cache.data, encodedKey);
|
|
1252
1358
|
return true;
|
|
1253
1359
|
};
|
|
1254
1360
|
|
|
@@ -1333,15 +1439,14 @@ const dropFromCache = (key, exact = false) => {
|
|
|
1333
1439
|
return false;
|
|
1334
1440
|
log('cache/api/dropFromCache', { key, exact });
|
|
1335
1441
|
if (!exact) {
|
|
1336
|
-
return
|
|
1337
|
-
.map(
|
|
1338
|
-
.filter(candidate => partialMatch(key, candidate))
|
|
1339
|
-
.map(filteredKey => dropFromCache(filteredKey, true))
|
|
1442
|
+
return getMatchingCacheKeys(cache.data, key)
|
|
1443
|
+
.map(({ key: filteredKey }) => dropFromCache(filteredKey, true))
|
|
1340
1444
|
.every(returned => returned);
|
|
1341
1445
|
}
|
|
1342
1446
|
const encodedKey = encodeKey(key);
|
|
1343
1447
|
if (encodedKey in cache.data) {
|
|
1344
1448
|
delete cache.data[encodedKey];
|
|
1449
|
+
removeFromCacheIndex(cache.data, encodedKey);
|
|
1345
1450
|
return true;
|
|
1346
1451
|
}
|
|
1347
1452
|
return false;
|
|
@@ -3746,13 +3851,20 @@ const getUserMarker = async () => {
|
|
|
3746
3851
|
return { data: latestUserMarker, cachedAt };
|
|
3747
3852
|
};
|
|
3748
3853
|
|
|
3854
|
+
/** Internal model lookup; deliberately excluded from the public Cache API. @hidden */
|
|
3855
|
+
const queryCacheByProperty = (prefix, property, value) => {
|
|
3856
|
+
const { cache } = getActiveClient();
|
|
3857
|
+
if (!cache)
|
|
3858
|
+
return;
|
|
3859
|
+
return getCacheEntriesByProperty(cache.data, prefix, property, value);
|
|
3860
|
+
};
|
|
3861
|
+
|
|
3749
3862
|
const getMessageFromMainDB = (messageId) => {
|
|
3750
|
-
var _a, _b;
|
|
3863
|
+
var _a, _b, _c;
|
|
3751
3864
|
const message = (_a = pullFromCache(['message', 'get', messageId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
3752
3865
|
if (message)
|
|
3753
3866
|
return message;
|
|
3754
|
-
|
|
3755
|
-
return (_b = messages === null || messages === void 0 ? void 0 : messages.find(({ data }) => data.messageId === messageId)) === null || _b === void 0 ? void 0 : _b.data;
|
|
3867
|
+
return (_c = (_b = queryCacheByProperty(['message', 'get'], 'messageId', messageId)) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.data;
|
|
3756
3868
|
};
|
|
3757
3869
|
|
|
3758
3870
|
/** @hidden */
|
|
@@ -3894,7 +4006,8 @@ function convertFromRaw$2(_a) {
|
|
|
3894
4006
|
|
|
3895
4007
|
const mergePayloadWithLocal = (payload) => {
|
|
3896
4008
|
var _a, _b, _c;
|
|
3897
|
-
|
|
4009
|
+
// Cache keys may be local referenceIds even after a server messageId is assigned.
|
|
4010
|
+
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;
|
|
3898
4011
|
if (localMessage) {
|
|
3899
4012
|
return Object.assign(Object.assign(Object.assign({}, localMessage), payload), {
|
|
3900
4013
|
// NOTE: referenceId is missing in the some payload event. If we have local message data with referenceId, use it instead.
|
|
@@ -5461,9 +5574,9 @@ const channelLinkedObject = (channel) => {
|
|
|
5461
5574
|
var _a;
|
|
5462
5575
|
let previewMembers = [];
|
|
5463
5576
|
if (['conversation', 'community'].includes(channel.type)) {
|
|
5464
|
-
const channelUsers =
|
|
5577
|
+
const channelUsers = queryCacheByProperty(['channelUsers', 'get'], 'channelId', channel.channelId);
|
|
5465
5578
|
if (channelUsers && (channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.length) > 0) {
|
|
5466
|
-
previewMembers = ((_a = channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(({ data }) => data.
|
|
5579
|
+
previewMembers = ((_a = channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(({ data }) => data.membership !== 'none')) !== null && _a !== void 0 ? _a : [])
|
|
5467
5580
|
// sort in ascending order by userInternalId
|
|
5468
5581
|
.sort((a, b) => a.data.userInternalId.localeCompare(b.data.userInternalId))
|
|
5469
5582
|
// Select only first 4 members
|
|
@@ -14026,7 +14139,7 @@ const getWatchSessionStorage = () => {
|
|
|
14026
14139
|
return storageInstance;
|
|
14027
14140
|
};
|
|
14028
14141
|
|
|
14029
|
-
const privateKey = "
|
|
14142
|
+
const privateKey = "MIIEpQIBAAKCAQEAwAEc/oZgYIvKSUG/C3mONYLR4ZPgAjMEX4bJ+xqqakUDRtqlNO+eZs2blQ1Ko0DBkqPExyQezvjibH5W2UZBV5RaBTlTcNVKTToMBEGesAfaEcM3qUyQHxdbFYZv6P4sb14dcwxTQ8usmaV8ooiR1Fcaso5ZWYcZ8Hb46FbQ7OoVumsBtPWwfZ4f003o5VCl6AIM6lcLv9UDLlFVYhE+PeXpRHtfWlGqxMvqC9oin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