@drakkar.software/starfish-client 3.0.0-alpha.5 → 3.0.0-alpha.50

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 (47) hide show
  1. package/README.md +59 -0
  2. package/dist/append-log.d.ts +228 -0
  3. package/dist/append-log.js +267 -0
  4. package/dist/background-sync.js +29 -0
  5. package/dist/bindings/legend.d.ts +23 -0
  6. package/dist/bindings/legend.js +32 -0
  7. package/dist/bindings/legend.js.map +2 -2
  8. package/dist/bindings/suspense.js +49 -0
  9. package/dist/bindings/zustand.d.ts +167 -2
  10. package/dist/bindings/zustand.js +941 -82
  11. package/dist/bindings/zustand.js.map +4 -4
  12. package/dist/blob-seal.d.ts +123 -0
  13. package/dist/client.d.ts +270 -5
  14. package/dist/client.js +391 -0
  15. package/dist/config.d.ts +9 -0
  16. package/dist/config.js +18 -0
  17. package/dist/debounced-sync.js +120 -0
  18. package/dist/dedup.js +35 -0
  19. package/dist/events.d.ts +150 -0
  20. package/dist/events.js +116 -0
  21. package/dist/events.js.map +7 -0
  22. package/dist/export.js +115 -0
  23. package/dist/fetch.d.ts +40 -0
  24. package/dist/fetch.js +51 -14
  25. package/dist/fetch.js.map +2 -2
  26. package/dist/history.js +61 -0
  27. package/dist/index.d.ts +16 -7
  28. package/dist/index.js +1029 -94
  29. package/dist/index.js.map +4 -4
  30. package/dist/kv-cache.d.ts +63 -0
  31. package/dist/logger.d.ts +3 -0
  32. package/dist/logger.js +80 -0
  33. package/dist/migrate.js +38 -0
  34. package/dist/mobile-lifecycle.d.ts +28 -1
  35. package/dist/mobile-lifecycle.js +94 -0
  36. package/dist/multi-store.js +92 -0
  37. package/dist/mutate.d.ts +39 -0
  38. package/dist/polling.js +52 -0
  39. package/dist/resolvers.js +223 -0
  40. package/dist/service-worker.js +55 -0
  41. package/dist/storage/indexeddb.js +59 -0
  42. package/dist/sync.d.ts +83 -0
  43. package/dist/sync.js +181 -0
  44. package/dist/types.d.ts +106 -11
  45. package/dist/types.js +18 -0
  46. package/dist/validate.js +28 -0
  47. package/package.json +12 -3
@@ -0,0 +1,61 @@
1
+ export class SnapshotHistory {
2
+ snapshots = [];
3
+ maxSnapshots;
4
+ storageKey;
5
+ constructor(options) {
6
+ this.maxSnapshots = options?.maxSnapshots ?? 20;
7
+ this.storageKey = options?.storageKey;
8
+ if (this.storageKey) {
9
+ try {
10
+ const raw = localStorage.getItem(this.storageKey);
11
+ if (raw) {
12
+ const parsed = JSON.parse(raw);
13
+ if (Array.isArray(parsed))
14
+ this.snapshots = parsed;
15
+ }
16
+ }
17
+ catch { /* corrupted or unavailable — start fresh */ }
18
+ }
19
+ }
20
+ /** Take a labeled snapshot of the given data. */
21
+ take(label, data) {
22
+ this.snapshots.push({
23
+ timestamp: Date.now(),
24
+ label,
25
+ data: JSON.stringify(data),
26
+ });
27
+ if (this.snapshots.length > this.maxSnapshots) {
28
+ this.snapshots = this.snapshots.slice(-this.maxSnapshots);
29
+ }
30
+ this.persist();
31
+ }
32
+ /** Restore data from a snapshot at the given index. Returns undefined if index is invalid or data is corrupt. */
33
+ restore(index) {
34
+ const snapshot = this.snapshots[index];
35
+ if (!snapshot)
36
+ return undefined;
37
+ try {
38
+ return JSON.parse(snapshot.data);
39
+ }
40
+ catch {
41
+ return undefined;
42
+ }
43
+ }
44
+ /** List available snapshots (metadata only, no data payload). */
45
+ list() {
46
+ return this.snapshots.map(({ timestamp, label }) => ({ timestamp, label }));
47
+ }
48
+ /** Clear all snapshots. */
49
+ clear() {
50
+ this.snapshots = [];
51
+ this.persist();
52
+ }
53
+ persist() {
54
+ if (!this.storageKey)
55
+ return;
56
+ try {
57
+ localStorage.setItem(this.storageKey, JSON.stringify(this.snapshots));
58
+ }
59
+ catch { /* quota exceeded — skip silently */ }
60
+ }
61
+ }
package/dist/index.d.ts CHANGED
@@ -4,21 +4,26 @@ export { stableStringify, computeHash } from "@drakkar.software/starfish-protoco
4
4
  export { buildRevocationList, revocationListCanonicalSigningInput } from "@drakkar.software/starfish-protocol";
5
5
  export type { RevocationList, RevocationEntry, RevokedSubject, BuildRevocationListOpts, } from "@drakkar.software/starfish-protocol";
6
6
  export type { PullResult, PushSuccess, PullKeyringProjection } from "@drakkar.software/starfish-protocol";
7
- export { StarfishClient } from "./client.js";
8
- export type { BlobPullResult, BlobPushResult, AppendPullOptions, PullOptions } from "./client.js";
7
+ export { StarfishClient, pullWasFromCache, stripPushPrefix } from "./client.js";
8
+ export type { BlobPullResult, BlobPushResult, AppendPullOptions, PullOptions, BatchPullOptions, BatchPullResult, BatchPullEntry, } from "./client.js";
9
+ export { sealAndPushBlob, pullAndOpenBlob } from "./blob-seal.js";
10
+ export type { ByteSealer, SealAndPushBlobOptions, PullAndOpenBlobOptions, } from "./blob-seal.js";
11
+ export { PARQUET_MIME_TYPE, PARQUET_MIME_TYPES } from "@drakkar.software/starfish-protocol";
9
12
  export { SyncManager, AbortError } from "./sync.js";
10
13
  export type { SyncManagerOptions, SyncSigner } from "./sync.js";
14
+ export { AppendLogCursor, AppendAuthorError, checkpointOf } from "./append-log.js";
15
+ export type { AppendLogCursorOptions, AppendElement, AuthorVerifier, ElementErrorPolicy } from "./append-log.js";
11
16
  export { ENCRYPTED_KEY } from "@drakkar.software/starfish-protocol";
12
17
  export type { Encryptor } from "@drakkar.software/starfish-protocol";
13
- export { ConflictError, StarfishHttpError, } from "./types.js";
14
- export type { StarfishClientOptions, StarfishCapProvider, ConflictResolver, ClientPlugin, } from "./types.js";
18
+ export { ConflictError, StarfishHttpError, AppendHttpError, } from "./types.js";
19
+ export type { StarfishClientOptions, StarfishCapProvider, PullCache, ConflictResolver, ClientPlugin, } from "./types.js";
15
20
  export { consoleSyncLogger, noopSyncLogger, createMetricsCollector } from "./logger.js";
16
21
  export type { SyncLogger, SyncMetrics, MetricsCollector } from "./logger.js";
17
22
  export { createMigrator } from "./migrate.js";
18
23
  export type { MigrationFn, MigrationConfig } from "./migrate.js";
19
24
  export { ValidationError, createSchemaValidator } from "./validate.js";
20
25
  export type { Validator, ValidationResult } from "./validate.js";
21
- export { classifyError } from "./fetch.js";
26
+ export { classifyError, parseRetryAfterMs } from "./fetch.js";
22
27
  export type { ErrorCategory } from "./fetch.js";
23
28
  export { createUnionMerge, createSoftDeleteResolver, timestampWinner, pruneTombstones, withConflictMeta, } from "./resolvers.js";
24
29
  export type { ConflictMeta, ConflictResolverWithMeta } from "./resolvers.js";
@@ -27,10 +32,14 @@ export type { Snapshot, SnapshotHistoryOptions } from "./history.js";
27
32
  export { startPolling, startAdaptivePolling } from "./polling.js";
28
33
  export type { PollableState, AdaptivePollingOptions, AdaptivePollingControls } from "./polling.js";
29
34
  export { createDedupFetch } from "./dedup.js";
35
+ export { mutateDoc } from "./mutate.js";
36
+ export type { DocState, DocMutator, MutateDocOptions } from "./mutate.js";
30
37
  export { fetchServerConfig } from "./config.js";
31
38
  export type { EncryptionMode, CollectionClientInfo, ConfigResponse } from "./config.js";
32
39
  export { createIndexedDBStorage } from "./storage/indexeddb.js";
33
40
  export type { IndexedDBStorageOptions, AsyncStateStorage } from "./storage/indexeddb.js";
41
+ export { createKvPullCache } from "./kv-cache.js";
42
+ export type { KvStore, KvPullCacheOptions } from "./kv-cache.js";
34
43
  export { exportData, importData, exportToBlob } from "./export.js";
35
44
  export type { ExportOptions } from "./export.js";
36
45
  export { isBackgroundSyncSupported, registerBackgroundSync } from "./background-sync.js";
@@ -40,8 +49,8 @@ export type { ServiceWorkerOptions } from "./service-worker.js";
40
49
  export { createSuspenseResource } from "./bindings/suspense.js";
41
50
  export { createDebouncedSync, createDebouncedPush } from "./debounced-sync.js";
42
51
  export type { DebouncedSyncOptions, DebouncedSync, DebouncedPushOptions, DebouncedPush } from "./debounced-sync.js";
43
- export { createMobileLifecycle } from "./mobile-lifecycle.js";
44
- export type { AppStateModule, NetInfoModule, MobileLifecycleDeps, MobileLifecycleOptions } from "./mobile-lifecycle.js";
52
+ export { createMobileLifecycle, createAppendLogMobileLifecycle } from "./mobile-lifecycle.js";
53
+ export type { AppStateModule, NetInfoModule, MobileLifecycleDeps, MobileLifecycleOptions, AppendLogLifecycleOptions } from "./mobile-lifecycle.js";
45
54
  export { createMultiStoreSync } from "./multi-store.js";
46
55
  export type { StoreSlice, BackupDocument, MultiStoreMigrationFn, MultiStoreSyncOptions, MultiStoreSync, } from "./multi-store.js";
47
56
  export type { AppendOnlyClientInfo } from "./config.js";