@noy-db/hub 0.2.0-pre.8 → 0.2.0-pre.9

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.
Files changed (70) hide show
  1. package/dist/attestation/index.d.cts +1 -1
  2. package/dist/attestation/index.d.ts +1 -1
  3. package/dist/blobs/index.d.cts +2 -2
  4. package/dist/blobs/index.d.ts +2 -2
  5. package/dist/bundle/index.cjs +160 -0
  6. package/dist/bundle/index.cjs.map +1 -1
  7. package/dist/bundle/index.d.cts +3 -3
  8. package/dist/bundle/index.d.ts +3 -3
  9. package/dist/bundle/index.js +1 -1
  10. package/dist/{chunk-6774ZOQ7.js → chunk-6CME4UEK.js} +154 -1
  11. package/dist/chunk-6CME4UEK.js.map +1 -0
  12. package/dist/consent/index.d.cts +2 -2
  13. package/dist/consent/index.d.ts +2 -2
  14. package/dist/derivations/index.d.cts +3 -3
  15. package/dist/derivations/index.d.ts +3 -3
  16. package/dist/{dev-unlock-p3ysikWP.d.ts → dev-unlock-B4kDxep_.d.ts} +1 -1
  17. package/dist/{dev-unlock-M4VAWNq_.d.cts → dev-unlock-BIoEFbwm.d.cts} +1 -1
  18. package/dist/guards/index.d.cts +3 -3
  19. package/dist/guards/index.d.ts +3 -3
  20. package/dist/{hash-BPsYPcv_.d.cts → hash-DdpVypUp.d.cts} +1 -1
  21. package/dist/{hash-C1GtiOhR.d.ts → hash-HJqD14vS.d.ts} +1 -1
  22. package/dist/history/index.d.cts +3 -3
  23. package/dist/history/index.d.ts +3 -3
  24. package/dist/i18n/index.d.cts +2 -2
  25. package/dist/i18n/index.d.ts +2 -2
  26. package/dist/index.cjs +153 -0
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +9 -9
  29. package/dist/index.d.ts +9 -9
  30. package/dist/index.js +1 -1
  31. package/dist/materialized-views/index.d.cts +3 -3
  32. package/dist/materialized-views/index.d.ts +3 -3
  33. package/dist/{noydb-LZBH3XDK.js → noydb-G725ZSZG.js} +2 -2
  34. package/dist/overlay-views/index.d.cts +3 -3
  35. package/dist/overlay-views/index.d.ts +3 -3
  36. package/dist/periods/index.d.cts +2 -2
  37. package/dist/periods/index.d.ts +2 -2
  38. package/dist/session/index.d.cts +3 -3
  39. package/dist/session/index.d.ts +3 -3
  40. package/dist/shadow/index.d.cts +2 -2
  41. package/dist/shadow/index.d.ts +2 -2
  42. package/dist/snapshots/index.cjs +37 -3
  43. package/dist/snapshots/index.cjs.map +1 -1
  44. package/dist/snapshots/index.d.cts +12 -5
  45. package/dist/snapshots/index.d.ts +12 -5
  46. package/dist/snapshots/index.js +37 -3
  47. package/dist/snapshots/index.js.map +1 -1
  48. package/dist/store/index.d.cts +2 -2
  49. package/dist/store/index.d.ts +2 -2
  50. package/dist/sync/index.d.cts +1 -1
  51. package/dist/sync/index.d.ts +1 -1
  52. package/dist/team/index.d.cts +2 -2
  53. package/dist/team/index.d.ts +2 -2
  54. package/dist/tx/index.d.cts +2 -2
  55. package/dist/tx/index.d.ts +2 -2
  56. package/dist/{types-DGU60JDt.d.ts → types-Df28QFKb.d.ts} +43 -1
  57. package/dist/{types-DjunxzJa.d.cts → types-DyXYr8rE.d.cts} +43 -1
  58. package/dist/{ulid-BFJkYRRW.d.ts → ulid-CJ8RzRrm.d.ts} +1 -1
  59. package/dist/{ulid-DPeuPgi3.d.cts → ulid-Drr7ykr6.d.cts} +1 -1
  60. package/dist/{with-derivation-DfOpKjFw.d.ts → with-derivation-DFnFByiQ.d.ts} +1 -1
  61. package/dist/{with-derivation-Df0kMlED.d.cts → with-derivation-DU3Sjazm.d.cts} +1 -1
  62. package/dist/{with-guard-C6W5RVrH.d.cts → with-guard-ByyxmEe7.d.cts} +1 -1
  63. package/dist/{with-guard-0KksDtSR.d.ts → with-guard-qube6BMI.d.ts} +1 -1
  64. package/dist/{with-materialized-view-BiasFcYx.d.ts → with-materialized-view-BLkQxoQN.d.ts} +1 -1
  65. package/dist/{with-materialized-view-BmDKyHrm.d.cts → with-materialized-view-BmEToIR1.d.cts} +1 -1
  66. package/dist/{with-overlayed-view-CA66vhHz.d.cts → with-overlayed-view-BMsQQbWm.d.cts} +1 -1
  67. package/dist/{with-overlayed-view-CQViuko_.d.ts → with-overlayed-view-CRsSEwHR.d.ts} +1 -1
  68. package/package.json +3 -3
  69. package/dist/chunk-6774ZOQ7.js.map +0 -1
  70. /package/dist/{noydb-LZBH3XDK.js.map → noydb-G725ZSZG.js.map} +0 -0
@@ -1,4 +1,4 @@
1
- import { b1 as NoydbStore } from '../types-DjunxzJa.cjs';
1
+ import { b3 as NoydbStore } from '../types-DyXYr8rE.cjs';
2
2
  import { AttestationFieldSchema, QrPayload, RevocationList } from '@noy-db/attestation';
3
3
  export { AttestationFieldSchema, QrPayload, RevocationList, VerifyInput, VerifyResult, decodeQr, isRevoked, signRevocationList, verifyAttestation, verifyRevocationList } from '@noy-db/attestation';
4
4
  export { o as AttestationError } from '../index-4fBVt8j9.cjs';
@@ -1,4 +1,4 @@
1
- import { b1 as NoydbStore } from '../types-DGU60JDt.js';
1
+ import { b3 as NoydbStore } from '../types-Df28QFKb.js';
2
2
  import { AttestationFieldSchema, QrPayload, RevocationList } from '@noy-db/attestation';
3
3
  export { AttestationFieldSchema, QrPayload, RevocationList, VerifyInput, VerifyResult, decodeQr, isRevoked, signRevocationList, verifyAttestation, verifyRevocationList } from '@noy-db/attestation';
4
4
  export { o as AttestationError } from '../index-D8I_pyJD.js';
@@ -1,5 +1,5 @@
1
- import { B as BlobStrategy } from '../types-DjunxzJa.cjs';
2
- export { z as BLOB_CHUNKS_COLLECTION, A as BLOB_COLLECTION, C as BLOB_EVICTION_AUDIT_COLLECTION, E as BLOB_INDEX_COLLECTION, F as BLOB_SLOTS_PREFIX, G as BLOB_VERSIONS_PREFIX, H as BlobEvictionEntry, J as BlobFieldPolicy, K as BlobFieldsConfig, M as BlobObject, N as BlobPutOptions, Q as BlobResponseOptions, T as BlobSet, U as BlobStrategyOpenArgs, V as CompactRunOptions, W as CompactionContext, X as CompactionResult, Y as DEFAULT_CHUNK_SIZE, Z as EXPORT_AUDIT_COLLECTION, _ as ExportBlobsAbortedError, $ as ExportBlobsAuditEntry, a0 as ExportBlobsHandle, a1 as ExportBlobsOptions, a2 as ExportedBlob, a3 as SlotInfo, a4 as SlotRecord, a5 as VersionRecord, a6 as createExportBlobsHandle, a7 as runCompaction } from '../types-DjunxzJa.cjs';
1
+ import { B as BlobStrategy } from '../types-DyXYr8rE.cjs';
2
+ export { z as BLOB_CHUNKS_COLLECTION, A as BLOB_COLLECTION, C as BLOB_EVICTION_AUDIT_COLLECTION, E as BLOB_INDEX_COLLECTION, F as BLOB_SLOTS_PREFIX, G as BLOB_VERSIONS_PREFIX, H as BlobEvictionEntry, J as BlobFieldPolicy, K as BlobFieldsConfig, M as BlobObject, N as BlobPutOptions, Q as BlobResponseOptions, T as BlobSet, U as BlobStrategyOpenArgs, V as CompactRunOptions, W as CompactionContext, X as CompactionResult, Y as DEFAULT_CHUNK_SIZE, Z as EXPORT_AUDIT_COLLECTION, _ as ExportBlobsAbortedError, $ as ExportBlobsAuditEntry, a0 as ExportBlobsHandle, a1 as ExportBlobsOptions, a2 as ExportedBlob, a3 as SlotInfo, a4 as SlotRecord, a5 as VersionRecord, a6 as createExportBlobsHandle, a7 as runCompaction } from '../types-DyXYr8rE.cjs';
3
3
  export { d as detectMagic, a as detectMimeType, i as isPreCompressed } from '../mime-magic-CBBSOkjm.cjs';
4
4
  import '../lazy-builder-wY4pMCEe.cjs';
5
5
  import '../predicate-BSAGEyu5.cjs';
@@ -1,5 +1,5 @@
1
- import { B as BlobStrategy } from '../types-DGU60JDt.js';
2
- export { z as BLOB_CHUNKS_COLLECTION, A as BLOB_COLLECTION, C as BLOB_EVICTION_AUDIT_COLLECTION, E as BLOB_INDEX_COLLECTION, F as BLOB_SLOTS_PREFIX, G as BLOB_VERSIONS_PREFIX, H as BlobEvictionEntry, J as BlobFieldPolicy, K as BlobFieldsConfig, M as BlobObject, N as BlobPutOptions, Q as BlobResponseOptions, T as BlobSet, U as BlobStrategyOpenArgs, V as CompactRunOptions, W as CompactionContext, X as CompactionResult, Y as DEFAULT_CHUNK_SIZE, Z as EXPORT_AUDIT_COLLECTION, _ as ExportBlobsAbortedError, $ as ExportBlobsAuditEntry, a0 as ExportBlobsHandle, a1 as ExportBlobsOptions, a2 as ExportedBlob, a3 as SlotInfo, a4 as SlotRecord, a5 as VersionRecord, a6 as createExportBlobsHandle, a7 as runCompaction } from '../types-DGU60JDt.js';
1
+ import { B as BlobStrategy } from '../types-Df28QFKb.js';
2
+ export { z as BLOB_CHUNKS_COLLECTION, A as BLOB_COLLECTION, C as BLOB_EVICTION_AUDIT_COLLECTION, E as BLOB_INDEX_COLLECTION, F as BLOB_SLOTS_PREFIX, G as BLOB_VERSIONS_PREFIX, H as BlobEvictionEntry, J as BlobFieldPolicy, K as BlobFieldsConfig, M as BlobObject, N as BlobPutOptions, Q as BlobResponseOptions, T as BlobSet, U as BlobStrategyOpenArgs, V as CompactRunOptions, W as CompactionContext, X as CompactionResult, Y as DEFAULT_CHUNK_SIZE, Z as EXPORT_AUDIT_COLLECTION, _ as ExportBlobsAbortedError, $ as ExportBlobsAuditEntry, a0 as ExportBlobsHandle, a1 as ExportBlobsOptions, a2 as ExportedBlob, a3 as SlotInfo, a4 as SlotRecord, a5 as VersionRecord, a6 as createExportBlobsHandle, a7 as runCompaction } from '../types-Df28QFKb.js';
3
3
  export { d as detectMagic, a as detectMimeType, i as isPreCompressed } from '../mime-magic-CBBSOkjm.js';
4
4
  import '../lazy-builder-7tIpFyWN.js';
5
5
  import '../predicate-BSAGEyu5.js';
@@ -15176,6 +15176,125 @@ var init_strategy10 = __esm({
15176
15176
  },
15177
15177
  async restoreSnapshot() {
15178
15178
  throw NOT_ENABLED5;
15179
+ },
15180
+ async autoSnapshot() {
15181
+ throw NOT_ENABLED5;
15182
+ }
15183
+ };
15184
+ }
15185
+ });
15186
+
15187
+ // src/snapshots/scheduler.ts
15188
+ var SnapshotScheduler;
15189
+ var init_scheduler = __esm({
15190
+ "src/snapshots/scheduler.ts"() {
15191
+ "use strict";
15192
+ SnapshotScheduler = class {
15193
+ policy;
15194
+ callbacks;
15195
+ debounceTimer = null;
15196
+ intervalTimer = null;
15197
+ lastFireTime = 0;
15198
+ firing = false;
15199
+ started = false;
15200
+ boundVisibility = null;
15201
+ boundUnload = null;
15202
+ constructor(policy, callbacks) {
15203
+ this.policy = policy;
15204
+ this.callbacks = callbacks;
15205
+ if (this.shouldRegisterUnload()) {
15206
+ this.boundVisibility = this.handleVisibility.bind(this);
15207
+ this.boundUnload = this.handleUnload.bind(this);
15208
+ }
15209
+ }
15210
+ start() {
15211
+ if (this.started) return;
15212
+ this.started = true;
15213
+ if (this.policy.mode === "interval") {
15214
+ const ms = this.policy.intervalMs ?? 3e5;
15215
+ this.intervalTimer = setInterval(() => {
15216
+ void this.execFire();
15217
+ }, ms);
15218
+ }
15219
+ if (this.boundVisibility && this.boundUnload) {
15220
+ if (typeof document !== "undefined") {
15221
+ document.addEventListener("visibilitychange", this.boundVisibility);
15222
+ }
15223
+ if (typeof globalThis.addEventListener === "function") {
15224
+ globalThis.addEventListener("pagehide", this.boundUnload);
15225
+ }
15226
+ if (typeof process !== "undefined" && typeof process.on === "function") {
15227
+ process.on("beforeExit", this.boundUnload);
15228
+ }
15229
+ }
15230
+ }
15231
+ stop() {
15232
+ if (!this.started) return;
15233
+ this.started = false;
15234
+ if (this.debounceTimer) {
15235
+ clearTimeout(this.debounceTimer);
15236
+ this.debounceTimer = null;
15237
+ }
15238
+ if (this.intervalTimer) {
15239
+ clearInterval(this.intervalTimer);
15240
+ this.intervalTimer = null;
15241
+ }
15242
+ if (this.boundVisibility && this.boundUnload) {
15243
+ if (typeof document !== "undefined") {
15244
+ document.removeEventListener("visibilitychange", this.boundVisibility);
15245
+ }
15246
+ if (typeof globalThis.removeEventListener === "function") {
15247
+ globalThis.removeEventListener("pagehide", this.boundUnload);
15248
+ }
15249
+ if (typeof process !== "undefined" && typeof process.removeListener === "function") {
15250
+ process.removeListener("beforeExit", this.boundUnload);
15251
+ }
15252
+ }
15253
+ }
15254
+ notifyChange() {
15255
+ if (!this.started) return;
15256
+ if (this.policy.mode === "debounce") this.resetDebounce();
15257
+ }
15258
+ resetDebounce() {
15259
+ if (this.debounceTimer) clearTimeout(this.debounceTimer);
15260
+ const ms = this.policy.debounceMs ?? 3e4;
15261
+ this.debounceTimer = setTimeout(() => {
15262
+ this.debounceTimer = null;
15263
+ void this.execFire();
15264
+ }, ms);
15265
+ }
15266
+ async execFire() {
15267
+ if (this.firing) return;
15268
+ const minInterval = this.policy.minIntervalMs ?? 0;
15269
+ if (minInterval > 0 && Date.now() - this.lastFireTime < minInterval) {
15270
+ if (this.policy.mode === "debounce") this.resetDebounce();
15271
+ return;
15272
+ }
15273
+ if (this.callbacks.pendingCount() === 0) return;
15274
+ this.firing = true;
15275
+ try {
15276
+ await this.callbacks.fire();
15277
+ this.lastFireTime = Date.now();
15278
+ } catch {
15279
+ } finally {
15280
+ this.firing = false;
15281
+ }
15282
+ }
15283
+ handleVisibility() {
15284
+ if (typeof document !== "undefined" && document.visibilityState === "hidden") {
15285
+ this.flush();
15286
+ }
15287
+ }
15288
+ handleUnload() {
15289
+ this.flush();
15290
+ }
15291
+ flush() {
15292
+ if (this.callbacks.pendingCount() === 0) return;
15293
+ void this.callbacks.fire().catch(() => {
15294
+ });
15295
+ }
15296
+ shouldRegisterUnload() {
15297
+ return this.policy.onUnload ?? this.policy.mode !== "manual";
15179
15298
  }
15180
15299
  };
15181
15300
  }
@@ -15656,6 +15775,7 @@ var init_noydb = __esm({
15656
15775
  init_unlock_state();
15657
15776
  init_sync_strategy();
15658
15777
  init_strategy10();
15778
+ init_scheduler();
15659
15779
  init_transaction();
15660
15780
  init_strategy11();
15661
15781
  init_sync_policy();
@@ -15717,6 +15837,8 @@ var init_noydb = __esm({
15717
15837
  sessionStrategy;
15718
15838
  syncStrategy;
15719
15839
  snapshotStrategy;
15840
+ snapshotScheduler = null;
15841
+ dirtySnapshotVaults = /* @__PURE__ */ new Set();
15720
15842
  /**
15721
15843
  * Currently-running multi-record transaction, set by
15722
15844
  * `runTransaction` at the start of Phase 2 (commit) and cleared in
@@ -15742,6 +15864,7 @@ var init_noydb = __esm({
15742
15864
  this.sessionStrategy = options.sessionStrategy ?? NO_SESSION;
15743
15865
  this.syncStrategy = options.syncStrategy ?? NO_SYNC;
15744
15866
  this.snapshotStrategy = options.snapshotStrategy ?? NO_SNAPSHOTS;
15867
+ this.initSnapshotCadence();
15745
15868
  this.publicEnvelopeSchema = resolveSchema(options.publicEnvelope);
15746
15869
  if (options.sessionPolicy) {
15747
15870
  this.sessionStrategy.validateSessionPolicy(options.sessionPolicy);
@@ -16698,6 +16821,8 @@ var init_noydb = __esm({
16698
16821
  }
16699
16822
  close() {
16700
16823
  this.closed = true;
16824
+ this.snapshotScheduler?.stop();
16825
+ this.snapshotScheduler = null;
16701
16826
  if (this.sessionTimer) {
16702
16827
  clearTimeout(this.sessionTimer);
16703
16828
  this.sessionTimer = null;
@@ -17743,6 +17868,41 @@ var init_noydb = __esm({
17743
17868
  }
17744
17869
  return this.snapshotStrategy.snapshot(v, this.options.user, opts);
17745
17870
  }
17871
+ /**
17872
+ * Wire the automatic-snapshot cadence when a non-manual `snapshotPolicy` is
17873
+ * configured. Subscribes to `onAfterWrite` to mark the written vault dirty and
17874
+ * nudge the scheduler; the scheduler fires `autoSnapshot()` per dirty vault.
17875
+ * No-op for `mode:'manual'` or no policy.
17876
+ */
17877
+ initSnapshotCadence() {
17878
+ const policy = this.snapshotStrategy.policy;
17879
+ if (!policy || !policy.mode || policy.mode === "manual") return;
17880
+ const scheduler = new SnapshotScheduler(policy, {
17881
+ fire: async () => {
17882
+ const names = [...this.dirtySnapshotVaults];
17883
+ this.dirtySnapshotVaults.clear();
17884
+ for (const name of names) {
17885
+ const v = this.vaultCache.get(name);
17886
+ if (!v) continue;
17887
+ try {
17888
+ await this.snapshotStrategy.autoSnapshot(v, this.options.user);
17889
+ } catch (err) {
17890
+ this.dirtySnapshotVaults.add(name);
17891
+ console.warn(
17892
+ `[noy-db] auto-snapshot failed for vault "${name}": ` + (err instanceof Error ? err.message : String(err))
17893
+ );
17894
+ }
17895
+ }
17896
+ },
17897
+ pendingCount: () => this.dirtySnapshotVaults.size
17898
+ });
17899
+ this.onAfterWrite((event) => {
17900
+ this.dirtySnapshotVaults.add(event.vault);
17901
+ scheduler.notifyChange();
17902
+ });
17903
+ scheduler.start();
17904
+ this.snapshotScheduler = scheduler;
17905
+ }
17746
17906
  /**
17747
17907
  * List all snapshots for the given vault, newest first.
17748
17908
  * Reads only the sidecar index — does not download snapshot bytes.