tsdf 17.0.0-alpha.10 → 17.0.0-alpha.11
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/async-storage.js +1 -1
- package/dist/{asyncStorageAdapter-BZSj1ZO5.js → asyncStorageAdapter-CSzvgl3s.js} +41 -78
- package/dist/{asyncStorageAdapters-DbyKyARM.js → asyncStorageAdapters-W8bChTBu.js} +2 -2
- package/dist/indexed-db-storage.js +1 -1
- package/dist/{indexedDbPersistentStorage-DlUjN1qY.js → indexedDbPersistentStorage-DtWquUOj.js} +2 -7
- package/dist/main.js +563 -1032
- package/dist/opfs-storage.js +1 -1
- package/dist/{opfsPersistentStorage-BO_uDxe4.js → opfsPersistentStorage-3c1zSDZi.js} +1 -1
- package/docs/browser-tabs-sync.md +2 -2
- package/docs/store-manager.md +1 -1
- package/package.json +1 -1
package/dist/async-storage.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as createAsyncStorageAdapter } from "./asyncStorageAdapter-
|
|
1
|
+
import { i as createAsyncStorageAdapter } from "./asyncStorageAdapter-CSzvgl3s.js";
|
|
2
2
|
export { createAsyncStorageAdapter };
|
|
@@ -324,42 +324,42 @@ function serializeJsonForStorage(value) {
|
|
|
324
324
|
sizeBytes: getSerializedStringSize(rawValue)
|
|
325
325
|
};
|
|
326
326
|
}
|
|
327
|
-
function keepEntriesWithinByteBudget(
|
|
327
|
+
function keepEntriesWithinByteBudget(entries, getKey, getLastAccessAt, getSizeBytes, isPinned, isProtected, maxBytes) {
|
|
328
328
|
const keptKeys = /* @__PURE__ */ new Set();
|
|
329
329
|
let unprotectedBytes = 0;
|
|
330
|
-
for (const entry of
|
|
331
|
-
if (
|
|
332
|
-
unprotectedBytes +=
|
|
330
|
+
for (const entry of entries) {
|
|
331
|
+
if (isProtected(entry)) continue;
|
|
332
|
+
unprotectedBytes += getSizeBytes(entry);
|
|
333
333
|
}
|
|
334
|
-
if (unprotectedBytes <=
|
|
335
|
-
for (const entry of
|
|
334
|
+
if (unprotectedBytes <= maxBytes) {
|
|
335
|
+
for (const entry of entries) keptKeys.add(getKey(entry));
|
|
336
336
|
return keptKeys;
|
|
337
337
|
}
|
|
338
|
-
const sortedEntries = [...
|
|
339
|
-
const aProtected =
|
|
340
|
-
const bProtected =
|
|
338
|
+
const sortedEntries = [...entries].sort((a, b) => {
|
|
339
|
+
const aProtected = isProtected(a);
|
|
340
|
+
const bProtected = isProtected(b);
|
|
341
341
|
if (aProtected && !bProtected) return -1;
|
|
342
342
|
if (!aProtected && bProtected) return 1;
|
|
343
|
-
const aPinned =
|
|
344
|
-
const bPinned =
|
|
343
|
+
const aPinned = isPinned(a);
|
|
344
|
+
const bPinned = isPinned(b);
|
|
345
345
|
if (aPinned && !bPinned) return -1;
|
|
346
346
|
if (!aPinned && bPinned) return 1;
|
|
347
|
-
return
|
|
347
|
+
return getLastAccessAt(b) - getLastAccessAt(a);
|
|
348
348
|
});
|
|
349
349
|
let keptUnprotectedBytes = 0;
|
|
350
350
|
for (const entry of sortedEntries) {
|
|
351
|
-
const key =
|
|
352
|
-
if (
|
|
351
|
+
const key = getKey(entry);
|
|
352
|
+
if (isProtected(entry)) {
|
|
353
353
|
keptKeys.add(key);
|
|
354
354
|
continue;
|
|
355
355
|
}
|
|
356
|
-
const sizeBytes =
|
|
357
|
-
if (
|
|
356
|
+
const sizeBytes = getSizeBytes(entry);
|
|
357
|
+
if (isPinned(entry)) {
|
|
358
358
|
keptKeys.add(key);
|
|
359
359
|
keptUnprotectedBytes += sizeBytes;
|
|
360
360
|
continue;
|
|
361
361
|
}
|
|
362
|
-
if (keptUnprotectedBytes + sizeBytes <=
|
|
362
|
+
if (keptUnprotectedBytes + sizeBytes <= maxBytes) {
|
|
363
363
|
keptKeys.add(key);
|
|
364
364
|
keptUnprotectedBytes += sizeBytes;
|
|
365
365
|
}
|
|
@@ -390,14 +390,11 @@ function getDefaultMaxBytesKindForScope(scopeKind) {
|
|
|
390
390
|
case "listQuery.query": return "listQuery";
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
|
-
function getDefaultMaxBytesForAdapter(
|
|
394
|
-
return defaultMaxBytes[getDefaultMaxBytesProfile(
|
|
393
|
+
function getDefaultMaxBytesForAdapter(adapter, kind) {
|
|
394
|
+
return defaultMaxBytes[getDefaultMaxBytesProfile(adapter)][kind];
|
|
395
395
|
}
|
|
396
|
-
function getDefaultMaxBytesForScope(
|
|
397
|
-
return getDefaultMaxBytesForAdapter(
|
|
398
|
-
adapter: args.adapter,
|
|
399
|
-
kind: getDefaultMaxBytesKindForScope(args.scopeKind)
|
|
400
|
-
});
|
|
396
|
+
function getDefaultMaxBytesForScope(adapter, scopeKind) {
|
|
397
|
+
return getDefaultMaxBytesForAdapter(adapter, getDefaultMaxBytesKindForScope(scopeKind));
|
|
401
398
|
}
|
|
402
399
|
//#endregion
|
|
403
400
|
//#region src/persistentStorage/types.ts
|
|
@@ -456,17 +453,17 @@ function setOfflineProtectionMetadata(customMetadata, offlineProtected) {
|
|
|
456
453
|
const { o: _ignored, ...withoutOfflineMarker } = customMetadata ?? {};
|
|
457
454
|
return Object.keys(withoutOfflineMarker).length > 0 ? withoutOfflineMarker : void 0;
|
|
458
455
|
}
|
|
459
|
-
function mergeManagedAsyncStorageCustomMetadata(
|
|
456
|
+
function mergeManagedAsyncStorageCustomMetadata(currentCustomMetadata, nextCustomMetadata, protectedKeysSnapshotSet, scope, key) {
|
|
460
457
|
const merged = {
|
|
461
|
-
...
|
|
462
|
-
...
|
|
458
|
+
...currentCustomMetadata ?? {},
|
|
459
|
+
...nextCustomMetadata ?? {}
|
|
463
460
|
};
|
|
464
461
|
const mergedCustomMetadata = Object.keys(merged).length > 0 ? merged : void 0;
|
|
465
|
-
if (
|
|
466
|
-
...
|
|
467
|
-
key
|
|
468
|
-
})) === true || isOfflineProtectedMetadata(
|
|
469
|
-
return setOfflineProtectionMetadata(mergedCustomMetadata, isOfflineProtectedMetadata(
|
|
462
|
+
if (protectedKeysSnapshotSet !== null) return setOfflineProtectionMetadata(mergedCustomMetadata, protectedKeysSnapshotSet?.has(serializeProtectedRef({
|
|
463
|
+
...scope,
|
|
464
|
+
key
|
|
465
|
+
})) === true || isOfflineProtectedMetadata(nextCustomMetadata) || isOfflineProtectedMetadata(currentCustomMetadata));
|
|
466
|
+
return setOfflineProtectionMetadata(mergedCustomMetadata, isOfflineProtectedMetadata(nextCustomMetadata) || isOfflineProtectedMetadata(currentCustomMetadata));
|
|
470
467
|
}
|
|
471
468
|
const ASYNC_METADATA_LAST_ACCESS_AT_KEY = "a";
|
|
472
469
|
const ASYNC_METADATA_VERSION_KEY = "v";
|
|
@@ -505,12 +502,12 @@ function serializeInternalManagedMetadataRecord(metadata) {
|
|
|
505
502
|
...customMetadata
|
|
506
503
|
};
|
|
507
504
|
}
|
|
508
|
-
function estimateManagedAsyncStorageEntrySizeBytes(
|
|
509
|
-
return getSerializedStringSize(
|
|
510
|
-
lastAccessAt
|
|
505
|
+
function estimateManagedAsyncStorageEntrySizeBytes(serializedValue, lastAccessAt, version, customMetadata) {
|
|
506
|
+
return getSerializedStringSize(serializedValue) + getSerializedStringSize(JSON.stringify(serializeInternalManagedMetadataRecord({
|
|
507
|
+
lastAccessAt,
|
|
511
508
|
sizeBytes: void 0,
|
|
512
|
-
version
|
|
513
|
-
...
|
|
509
|
+
version,
|
|
510
|
+
...customMetadata ? { customMetadata } : {}
|
|
514
511
|
})));
|
|
515
512
|
}
|
|
516
513
|
function parseIndexEntries(value) {
|
|
@@ -561,18 +558,9 @@ function serializeIndexState(state) {
|
|
|
561
558
|
}
|
|
562
559
|
function getDefaultStaticPolicyForScope(scope) {
|
|
563
560
|
switch (scope.kind) {
|
|
564
|
-
case "collection.item": return { maxBytes: getDefaultMaxBytesForScope(
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
}) };
|
|
568
|
-
case "listQuery.item": return { maxBytes: getDefaultMaxBytesForScope({
|
|
569
|
-
adapter: "async",
|
|
570
|
-
scopeKind: "listQuery.item"
|
|
571
|
-
}) };
|
|
572
|
-
case "listQuery.query": return { maxBytes: getDefaultMaxBytesForScope({
|
|
573
|
-
adapter: "async",
|
|
574
|
-
scopeKind: "listQuery.query"
|
|
575
|
-
}) };
|
|
561
|
+
case "collection.item": return { maxBytes: getDefaultMaxBytesForScope("async", "collection.item") };
|
|
562
|
+
case "listQuery.item": return { maxBytes: getDefaultMaxBytesForScope("async", "listQuery.item") };
|
|
563
|
+
case "listQuery.query": return { maxBytes: getDefaultMaxBytesForScope("async", "listQuery.query") };
|
|
576
564
|
default: return null;
|
|
577
565
|
}
|
|
578
566
|
}
|
|
@@ -1228,13 +1216,7 @@ var ManagedAsyncStorageAdapter = class {
|
|
|
1228
1216
|
const touchedKeys = [...new Set(touches.map((touch) => touch.key))];
|
|
1229
1217
|
const managedCapabilities = getManagedDriverCapabilities(this.#driver);
|
|
1230
1218
|
if (managedCapabilities?.applyManagedCommit !== void 0) {
|
|
1231
|
-
await managedCapabilities.applyManagedCommit(scope, args, { mergeOfflineProtectionMetadata: (key, nextCustomMetadata, currentCustomMetadata) => mergeManagedAsyncStorageCustomMetadata(
|
|
1232
|
-
currentCustomMetadata,
|
|
1233
|
-
key,
|
|
1234
|
-
nextCustomMetadata,
|
|
1235
|
-
protectedKeysSnapshotSet: getSessionProtectedKeysSnapshot(scope.sessionKey),
|
|
1236
|
-
scope
|
|
1237
|
-
}) });
|
|
1219
|
+
await managedCapabilities.applyManagedCommit(scope, args, { mergeOfflineProtectionMetadata: (key, nextCustomMetadata, currentCustomMetadata) => mergeManagedAsyncStorageCustomMetadata(currentCustomMetadata, nextCustomMetadata, getSessionProtectedKeysSnapshot(scope.sessionKey), scope, key) });
|
|
1238
1220
|
this.#advanceNamespaceReadCacheGeneration(scope);
|
|
1239
1221
|
this.#invalidateCachedNamespaceIndexState(scope);
|
|
1240
1222
|
for (const key of removes) this.#invalidateCachedPayloadValue(scope, key);
|
|
@@ -1261,21 +1243,10 @@ var ManagedAsyncStorageAdapter = class {
|
|
|
1261
1243
|
const protectedKeysSnapshotSet = getSessionProtectedKeysSnapshot(scope.sessionKey);
|
|
1262
1244
|
for (const upsert of upserts) {
|
|
1263
1245
|
const existingMetadata = indexEntries.get(upsert.key);
|
|
1264
|
-
const customMetadata = mergeManagedAsyncStorageCustomMetadata(
|
|
1265
|
-
currentCustomMetadata: existingMetadata?.customMetadata,
|
|
1266
|
-
key: upsert.key,
|
|
1267
|
-
nextCustomMetadata: upsert.metadata,
|
|
1268
|
-
protectedKeysSnapshotSet,
|
|
1269
|
-
scope
|
|
1270
|
-
});
|
|
1246
|
+
const customMetadata = mergeManagedAsyncStorageCustomMetadata(existingMetadata?.customMetadata, upsert.metadata, protectedKeysSnapshotSet, scope, upsert.key);
|
|
1271
1247
|
const nextLastAccessAt = touchesByKey.get(upsert.key) ?? existingMetadata?.lastAccessAt ?? now;
|
|
1272
1248
|
const serializedValue = upsert.serializedValue !== void 0 ? { rawValue: upsert.serializedValue } : serializeJsonForStorage(upsert.value);
|
|
1273
|
-
const nextSizeBytes = scope.kind !== "document" ? estimateManagedAsyncStorageEntrySizeBytes(
|
|
1274
|
-
customMetadata,
|
|
1275
|
-
lastAccessAt: nextLastAccessAt,
|
|
1276
|
-
serializedValue: serializedValue.rawValue,
|
|
1277
|
-
version: upsert.version
|
|
1278
|
-
}) : void 0;
|
|
1249
|
+
const nextSizeBytes = scope.kind !== "document" ? estimateManagedAsyncStorageEntrySizeBytes(serializedValue.rawValue, nextLastAccessAt, upsert.version, customMetadata) : void 0;
|
|
1279
1250
|
const nextMetadata = {
|
|
1280
1251
|
lastAccessAt: nextLastAccessAt,
|
|
1281
1252
|
version: upsert.version,
|
|
@@ -1786,15 +1757,7 @@ var ManagedAsyncStorageAdapter = class {
|
|
|
1786
1757
|
for (const payloadKey of payloadKeys) if (!indexState.entries.has(payloadKey)) payloadRecordKeysToRemove.add(getPayloadRecordKey(payloadKey));
|
|
1787
1758
|
if (effectiveStaticPolicy?.maxBytes !== void 0) {
|
|
1788
1759
|
const pinnedKeys = new Set(effectiveStaticPolicy.pinnedKeys ?? []);
|
|
1789
|
-
const keptKeys = keepEntriesWithinByteBudget(
|
|
1790
|
-
entries: candidateEntries,
|
|
1791
|
-
getKey: (entry) => entry.itemKey,
|
|
1792
|
-
getLastAccessAt: (entry) => entry.lastAccessAt,
|
|
1793
|
-
getSizeBytes: (entry) => entry.sizeBytes,
|
|
1794
|
-
isPinned: (entry) => pinnedKeys.has(entry.itemKey),
|
|
1795
|
-
isProtected: (entry) => entry.protected,
|
|
1796
|
-
maxBytes: effectiveStaticPolicy.maxBytes
|
|
1797
|
-
});
|
|
1760
|
+
const keptKeys = keepEntriesWithinByteBudget(candidateEntries, (entry) => entry.itemKey, (entry) => entry.lastAccessAt, (entry) => entry.sizeBytes, (entry) => pinnedKeys.has(entry.itemKey), (entry) => entry.protected, effectiveStaticPolicy.maxBytes);
|
|
1798
1761
|
for (const { itemKey } of candidateEntries) {
|
|
1799
1762
|
if (keptKeys.has(itemKey)) continue;
|
|
1800
1763
|
payloadRecordKeysToRemove.add(getPayloadRecordKey(itemKey));
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as opfsPersistentStorage } from "./opfsPersistentStorage-
|
|
2
|
-
import { n as indexedDbPersistentStorage } from "./indexedDbPersistentStorage-
|
|
1
|
+
import { t as opfsPersistentStorage } from "./opfsPersistentStorage-3c1zSDZi.js";
|
|
2
|
+
import { n as indexedDbPersistentStorage } from "./indexedDbPersistentStorage-DtWquUOj.js";
|
|
3
3
|
export { indexedDbPersistentStorage, opfsPersistentStorage };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as indexedDbPersistentStorage, t as createIndexedDbPersistentStorage } from "./indexedDbPersistentStorage-
|
|
1
|
+
import { n as indexedDbPersistentStorage, t as createIndexedDbPersistentStorage } from "./indexedDbPersistentStorage-DtWquUOj.js";
|
|
2
2
|
export { createIndexedDbPersistentStorage, indexedDbPersistentStorage };
|
package/dist/{indexedDbPersistentStorage-DlUjN1qY.js → indexedDbPersistentStorage-DtWquUOj.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as parseAsyncStorageRecordKey, F as encodePersistedAsyncNamespaceKind, H as serializeProtectedRef, I as getNamespaceId, L as getPayloadRecordKey, P as compareMetadata, R as getPersistedNamespaceId, V as parsePersistedAsyncNamespaceKind, a as estimateManagedAsyncStorageEntrySizeBytes, i as createAsyncStorageAdapter, v as serializeJsonForStorage, z as normalizeStaticPolicy } from "./asyncStorageAdapter-
|
|
1
|
+
import { B as parseAsyncStorageRecordKey, F as encodePersistedAsyncNamespaceKind, H as serializeProtectedRef, I as getNamespaceId, L as getPayloadRecordKey, P as compareMetadata, R as getPersistedNamespaceId, V as parsePersistedAsyncNamespaceKind, a as estimateManagedAsyncStorageEntrySizeBytes, i as createAsyncStorageAdapter, v as serializeJsonForStorage, z as normalizeStaticPolicy } from "./asyncStorageAdapter-CSzvgl3s.js";
|
|
2
2
|
import { __LEGIT_CAST__ } from "@ls-stack/utils/saferTyping";
|
|
3
3
|
import { isObject } from "@ls-stack/utils/typeGuards";
|
|
4
4
|
//#region src/persistentStorage/indexedDbAsyncStorageAdapter.ts
|
|
@@ -180,12 +180,7 @@ function compactEntryValue(scope, value) {
|
|
|
180
180
|
return { d: value };
|
|
181
181
|
}
|
|
182
182
|
function estimateIndexedDbManagedEntrySizeBytes(args) {
|
|
183
|
-
return estimateManagedAsyncStorageEntrySizeBytes(
|
|
184
|
-
customMetadata: args.customMetadata,
|
|
185
|
-
lastAccessAt: args.lastAccessAt,
|
|
186
|
-
serializedValue: args.serializedValue ?? serializeJsonForStorage(args.value).rawValue,
|
|
187
|
-
version: args.version
|
|
188
|
-
});
|
|
183
|
+
return estimateManagedAsyncStorageEntrySizeBytes(args.serializedValue ?? serializeJsonForStorage(args.value).rawValue, args.lastAccessAt, args.version, args.customMetadata);
|
|
189
184
|
}
|
|
190
185
|
function expandEntryValue(scope, record) {
|
|
191
186
|
return record.d;
|