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.
@@ -1,2 +1,2 @@
1
- import { i as createAsyncStorageAdapter } from "./asyncStorageAdapter-BZSj1ZO5.js";
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(args) {
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 args.entries) {
331
- if (args.isProtected(entry)) continue;
332
- unprotectedBytes += args.getSizeBytes(entry);
330
+ for (const entry of entries) {
331
+ if (isProtected(entry)) continue;
332
+ unprotectedBytes += getSizeBytes(entry);
333
333
  }
334
- if (unprotectedBytes <= args.maxBytes) {
335
- for (const entry of args.entries) keptKeys.add(args.getKey(entry));
334
+ if (unprotectedBytes <= maxBytes) {
335
+ for (const entry of entries) keptKeys.add(getKey(entry));
336
336
  return keptKeys;
337
337
  }
338
- const sortedEntries = [...args.entries].sort((a, b) => {
339
- const aProtected = args.isProtected(a);
340
- const bProtected = args.isProtected(b);
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 = args.isPinned(a);
344
- const bPinned = args.isPinned(b);
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 args.getLastAccessAt(b) - args.getLastAccessAt(a);
347
+ return getLastAccessAt(b) - getLastAccessAt(a);
348
348
  });
349
349
  let keptUnprotectedBytes = 0;
350
350
  for (const entry of sortedEntries) {
351
- const key = args.getKey(entry);
352
- if (args.isProtected(entry)) {
351
+ const key = getKey(entry);
352
+ if (isProtected(entry)) {
353
353
  keptKeys.add(key);
354
354
  continue;
355
355
  }
356
- const sizeBytes = args.getSizeBytes(entry);
357
- if (args.isPinned(entry)) {
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 <= args.maxBytes) {
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(args) {
394
- return defaultMaxBytes[getDefaultMaxBytesProfile(args.adapter)][args.kind];
393
+ function getDefaultMaxBytesForAdapter(adapter, kind) {
394
+ return defaultMaxBytes[getDefaultMaxBytesProfile(adapter)][kind];
395
395
  }
396
- function getDefaultMaxBytesForScope(args) {
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(args) {
456
+ function mergeManagedAsyncStorageCustomMetadata(currentCustomMetadata, nextCustomMetadata, protectedKeysSnapshotSet, scope, key) {
460
457
  const merged = {
461
- ...args.currentCustomMetadata ?? {},
462
- ...args.nextCustomMetadata ?? {}
458
+ ...currentCustomMetadata ?? {},
459
+ ...nextCustomMetadata ?? {}
463
460
  };
464
461
  const mergedCustomMetadata = Object.keys(merged).length > 0 ? merged : void 0;
465
- if (args.protectedKeysSnapshotSet !== null) return setOfflineProtectionMetadata(mergedCustomMetadata, args.protectedKeysSnapshotSet?.has(serializeProtectedRef({
466
- ...args.scope,
467
- key: args.key
468
- })) === true || isOfflineProtectedMetadata(args.nextCustomMetadata) || isOfflineProtectedMetadata(args.currentCustomMetadata));
469
- return setOfflineProtectionMetadata(mergedCustomMetadata, isOfflineProtectedMetadata(args.nextCustomMetadata) || isOfflineProtectedMetadata(args.currentCustomMetadata));
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(args) {
509
- return getSerializedStringSize(args.serializedValue) + getSerializedStringSize(JSON.stringify(serializeInternalManagedMetadataRecord({
510
- lastAccessAt: args.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: args.version,
513
- ...args.customMetadata ? { customMetadata: args.customMetadata } : {}
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
- adapter: "async",
566
- scopeKind: "collection.item"
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-BO_uDxe4.js";
2
- import { n as indexedDbPersistentStorage } from "./indexedDbPersistentStorage-DlUjN1qY.js";
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-DlUjN1qY.js";
1
+ import { n as indexedDbPersistentStorage, t as createIndexedDbPersistentStorage } from "./indexedDbPersistentStorage-DtWquUOj.js";
2
2
  export { createIndexedDbPersistentStorage, indexedDbPersistentStorage };
@@ -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-BZSj1ZO5.js";
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;