@opendatalabs/personal-server-ts-core 1.6.0 → 1.8.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.
Files changed (106) hide show
  1. package/dist/api/index.d.ts +53 -2
  2. package/dist/api/index.d.ts.map +1 -1
  3. package/dist/api/index.js +300 -25
  4. package/dist/api/index.js.map +1 -1
  5. package/dist/contracts/data.d.ts +30 -1
  6. package/dist/contracts/data.d.ts.map +1 -1
  7. package/dist/contracts/data.js +126 -33
  8. package/dist/contracts/data.js.map +1 -1
  9. package/dist/errors/catalog.d.ts +40 -0
  10. package/dist/errors/catalog.d.ts.map +1 -1
  11. package/dist/errors/catalog.js +53 -0
  12. package/dist/errors/catalog.js.map +1 -1
  13. package/dist/lineage/attestation.d.ts +42 -0
  14. package/dist/lineage/attestation.d.ts.map +1 -0
  15. package/dist/lineage/attestation.js +25 -0
  16. package/dist/lineage/attestation.js.map +1 -0
  17. package/dist/lineage/gateway.d.ts +105 -0
  18. package/dist/lineage/gateway.d.ts.map +1 -0
  19. package/dist/lineage/gateway.js +242 -0
  20. package/dist/lineage/gateway.js.map +1 -0
  21. package/dist/lineage/index.d.ts +5 -0
  22. package/dist/lineage/index.d.ts.map +1 -0
  23. package/dist/lineage/index.js +5 -0
  24. package/dist/lineage/index.js.map +1 -0
  25. package/dist/lineage/lineage.d.ts +141 -0
  26. package/dist/lineage/lineage.d.ts.map +1 -0
  27. package/dist/lineage/lineage.js +255 -0
  28. package/dist/lineage/lineage.js.map +1 -0
  29. package/dist/logging/access-log.d.ts +7 -1
  30. package/dist/logging/access-log.d.ts.map +1 -1
  31. package/dist/mcp/read-client.d.ts.map +1 -1
  32. package/dist/mcp/read-client.js +25 -1
  33. package/dist/mcp/read-client.js.map +1 -1
  34. package/dist/mcp/session.d.ts.map +1 -1
  35. package/dist/mcp/session.js +10 -1
  36. package/dist/mcp/session.js.map +1 -1
  37. package/dist/ports/index.d.ts +125 -0
  38. package/dist/ports/index.d.ts.map +1 -1
  39. package/dist/ports/index.js.map +1 -1
  40. package/dist/signing/request-signer.d.ts +2 -0
  41. package/dist/signing/request-signer.d.ts.map +1 -1
  42. package/dist/signing/request-signer.js +1 -0
  43. package/dist/signing/request-signer.js.map +1 -1
  44. package/dist/signing/signer.d.ts +8 -0
  45. package/dist/signing/signer.d.ts.map +1 -1
  46. package/dist/signing/signer.js +9 -0
  47. package/dist/signing/signer.js.map +1 -1
  48. package/dist/storage/adapters/index.d.ts +1 -1
  49. package/dist/storage/adapters/index.d.ts.map +1 -1
  50. package/dist/storage/adapters/index.js +1 -1
  51. package/dist/storage/adapters/index.js.map +1 -1
  52. package/dist/storage/adapters/vana.d.ts +2 -0
  53. package/dist/storage/adapters/vana.d.ts.map +1 -1
  54. package/dist/storage/adapters/vana.js +5 -1
  55. package/dist/storage/adapters/vana.js.map +1 -1
  56. package/dist/storage/index/types.d.ts +1 -0
  57. package/dist/storage/index/types.d.ts.map +1 -1
  58. package/dist/sync/data-point-feed.d.ts +35 -0
  59. package/dist/sync/data-point-feed.d.ts.map +1 -0
  60. package/dist/sync/data-point-feed.js +122 -0
  61. package/dist/sync/data-point-feed.js.map +1 -0
  62. package/dist/sync/data-point-id.d.ts +7 -0
  63. package/dist/sync/data-point-id.d.ts.map +1 -0
  64. package/dist/sync/data-point-id.js +16 -0
  65. package/dist/sync/data-point-id.js.map +1 -0
  66. package/dist/sync/delete-data-port.d.ts +50 -0
  67. package/dist/sync/delete-data-port.d.ts.map +1 -0
  68. package/dist/sync/delete-data-port.js +244 -0
  69. package/dist/sync/delete-data-port.js.map +1 -0
  70. package/dist/sync/engine/sync-manager.d.ts +14 -4
  71. package/dist/sync/engine/sync-manager.d.ts.map +1 -1
  72. package/dist/sync/engine/sync-manager.js +53 -8
  73. package/dist/sync/engine/sync-manager.js.map +1 -1
  74. package/dist/sync/index.d.ts +7 -0
  75. package/dist/sync/index.d.ts.map +1 -1
  76. package/dist/sync/index.js +7 -0
  77. package/dist/sync/index.js.map +1 -1
  78. package/dist/sync/pending-blob-deletions.d.ts +29 -0
  79. package/dist/sync/pending-blob-deletions.d.ts.map +1 -0
  80. package/dist/sync/pending-blob-deletions.js +116 -0
  81. package/dist/sync/pending-blob-deletions.js.map +1 -0
  82. package/dist/sync/scope-deletions.d.ts +155 -0
  83. package/dist/sync/scope-deletions.d.ts.map +1 -0
  84. package/dist/sync/scope-deletions.js +225 -0
  85. package/dist/sync/scope-deletions.js.map +1 -0
  86. package/dist/sync/tombstone.d.ts +27 -0
  87. package/dist/sync/tombstone.d.ts.map +1 -0
  88. package/dist/sync/tombstone.js +28 -0
  89. package/dist/sync/tombstone.js.map +1 -0
  90. package/dist/sync/workers/delete.d.ts +152 -31
  91. package/dist/sync/workers/delete.d.ts.map +1 -1
  92. package/dist/sync/workers/delete.js +461 -27
  93. package/dist/sync/workers/delete.js.map +1 -1
  94. package/dist/sync/workers/download.d.ts +38 -1
  95. package/dist/sync/workers/download.d.ts.map +1 -1
  96. package/dist/sync/workers/download.js +106 -2
  97. package/dist/sync/workers/download.js.map +1 -1
  98. package/dist/sync/workers/upload.d.ts +41 -7
  99. package/dist/sync/workers/upload.d.ts.map +1 -1
  100. package/dist/sync/workers/upload.js +147 -21
  101. package/dist/sync/workers/upload.js.map +1 -1
  102. package/dist/write/attribution.d.ts +6 -4
  103. package/dist/write/attribution.d.ts.map +1 -1
  104. package/dist/write/attribution.js +51 -3
  105. package/dist/write/attribution.js.map +1 -1
  106. package/package.json +5 -1
@@ -1,42 +1,163 @@
1
- import type { StorageAdapter } from "../../storage/adapters/interface.js";
2
- import type { GatewayClient } from "@opendatalabs/vana-sdk/browser";
3
- import type { ServerSigner } from "../../signing/signer.js";
4
1
  import type { Logger } from "../../logger/index.js";
5
- import type { DataStoragePort } from "../../ports/index.js";
6
- export interface DeleteWorkerDeps {
2
+ import type { DataPointFeedPort, DataStoragePort, DeleteDataPort, PendingBlobDeletion, PendingBlobDeletionStore } from "../../ports/index.js";
3
+ import { type ScopeDeletionTracker } from "../scope-deletions.js";
4
+ /**
5
+ * Exact blob deletes sent per pass. vana-storage allows 30 DELETE requests
6
+ * per owner per 60 seconds. A DELETE request's own pass and the next sync
7
+ * cycle's retry pass can land inside one window, so each pass sends at most
8
+ * half the budget; whatever does not fit is queued and drained on later
9
+ * cycles, and a 429 simply re-queues its key.
10
+ */
11
+ export declare const BLOB_DELETE_BATCH_SIZE = 15;
12
+ export interface DeleteScopeDeps {
7
13
  storage: DataStoragePort;
8
- storageAdapter: StorageAdapter;
9
- gateway: GatewayClient;
10
- signer: ServerSigner;
11
- serverOwner: string;
14
+ /** Data owner; absent only on an unconfigured host (no key material). */
15
+ serverOwner?: string;
16
+ /**
17
+ * Remote deletion (gateway tombstone + storage blobs). Absent when the host
18
+ * runs without sync (no owner key material): deletion is then local-only
19
+ * and reported as such, never silently "durable".
20
+ */
21
+ deleteData?: DeleteDataPort | null;
22
+ /** Exact-key retry markers for blob deletes that did not finish. */
23
+ pendingBlobDeletions?: PendingBlobDeletionStore;
24
+ /**
25
+ * Read-side deletion memory. A landed tombstone is recorded here so this
26
+ * replica's reads answer 410 immediately, before any sync cycle.
27
+ */
28
+ scopeDeletions?: ScopeDeletionTracker;
29
+ /**
30
+ * Deletion-aware registry lookup, re-read right after the tombstone attempt
31
+ * (a registration racing a "not-registered" answer) and by the retry to
32
+ * expand a marker whose tombstone version was not known.
33
+ */
34
+ dataPointFeed?: DataPointFeedPort;
12
35
  logger: Logger;
36
+ now?: () => Date;
37
+ }
38
+ export type DeleteStepStatus = "ok" | "skipped" | "failed" | "deferred";
39
+ export interface DeleteScopeStep {
40
+ status: DeleteStepStatus;
41
+ /** Why the step was skipped (e.g. "not-registered", "sync-disabled"). */
42
+ reason?: string;
43
+ /** Error message when status is "failed". */
44
+ error?: string;
13
45
  }
14
- export interface DeleteScopeRemoteResult {
46
+ export interface DeleteScopeResult {
15
47
  scope: string;
16
- /** Synced versions de-registered at the gateway. */
17
- filesDeregistered: number;
18
- /** Ciphertext blobs hard-deleted from storage. */
19
- blobsDeleted: number;
20
- errors: Array<{
21
- fileId: string | null;
22
- message: string;
23
- }>;
48
+ /** DPv2 identity: keccak256(abi.encode(owner, scope)); null without an owner. */
49
+ dataPointId: string | null;
50
+ /**
51
+ * True once the gateway holds the tombstone (or never held the point at
52
+ * all): sync can no longer resurrect the scope on any replica. False when
53
+ * only the local copy was removed.
54
+ */
55
+ durable: boolean;
56
+ steps: {
57
+ gateway: DeleteScopeStep & {
58
+ /** Tombstone version at the gateway; null when it did not report one. */
59
+ version?: string | null;
60
+ deletedAt?: string | null;
61
+ };
62
+ /**
63
+ * Storage step. "ok": every blob key the tombstone covers is gone.
64
+ * "deferred": some keys are queued for later passes (rate-limit batch,
65
+ * or a tombstone version the gateway did not report). "failed": at
66
+ * least one delete errored; the failed keys are queued too.
67
+ */
68
+ storage: DeleteScopeStep & {
69
+ blobsDeleted?: number;
70
+ blobsMissing?: number;
71
+ blobsPending?: number;
72
+ };
73
+ local: DeleteScopeStep & {
74
+ deletedCount?: number;
75
+ };
76
+ };
77
+ /**
78
+ * True when the tombstone landed but blob deletion did not finish: exact
79
+ * retry markers were recorded and later sync cycles finish them.
80
+ */
81
+ pendingBlobDeletion: boolean;
82
+ }
83
+ export interface BlobDeletionPlan {
84
+ /**
85
+ * Exact keys of covered local entries that lie outside the registry range:
86
+ * an upload that landed under a key the registry never saw (crashed before
87
+ * registering, or rebased later) is still deleted data. Bounded by the
88
+ * local index size.
89
+ */
90
+ keys: string[];
91
+ /**
92
+ * Every registry version up to and including the tombstone's, as inclusive
93
+ * bounds. Versions are a dense, strictly increasing integer sequence per
94
+ * scope and an absent key answers 404, so the range is exact and complete
95
+ * across replicas without listing storage. Kept as bounds, never
96
+ * materialised: a large tombstone version costs nothing until its keys are
97
+ * actually sent, a batch at a time. Null without a tombstone version.
98
+ */
99
+ range: {
100
+ from: string;
101
+ to: string;
102
+ } | null;
24
103
  }
25
104
  /**
26
- * Propagate a scope deletion to the authoritative remote stores.
105
+ * The storage keys a tombstone covers for `scope`. A re-add registered after
106
+ * the tombstone lives under a higher version key, so it is never in this set
107
+ * and survives by construction. With no tombstone version (never registered,
108
+ * or the gateway did not report one) only the local entries' keys can be
109
+ * enumerated.
110
+ */
111
+ export declare function planBlobDeletions(storage: Pick<DataStoragePort, "listVersions">, scope: string, tombstoneVersionValue: string | null): BlobDeletionPlan;
112
+ /**
113
+ * Durable scope deletion, in the only order that cannot resurrect data:
114
+ *
115
+ * 1. gateway tombstone (owner-signed AddData at current + 1; the fact)
116
+ * 2. storage blobs (exact keys of every version the tombstone covers)
117
+ * 3. local copy (index rows + files + sidecars)
27
118
  *
28
- * NOT SUPPORTED on the DPv2 (DataPoint) gateway: there is no data-point
29
- * de-registration / deletion endpoint, and the DataPointRecord listing carries
30
- * no soft-delete (`deletedAt`) flag. Under the legacy file model this worker
31
- * de-registered each file then hard-deleted its blob; that path is gone with
32
- * `gateway.getFile` / `gateway.deleteFile` / `signFileDeletion`.
119
+ * The local delete never runs before the gateway has acknowledged: until the
120
+ * registry says "deleted", the next sync cycle would re-pull the point from
121
+ * the still-live row. Step 2 deletes exact per-version keys, never the scope
122
+ * prefix, so a re-add another replica lands at any time keeps its ciphertext
123
+ * (it is registered above the tombstone version and stored under that key).
124
+ * Keys that could not be deleted in this pass are queued as exact retry
125
+ * markers; step 3 does not wait for them because the tombstone already makes
126
+ * the deletion stick.
33
127
  *
34
- * Deleting the ciphertext blob alone would be unsafe: the data point would
35
- * stay listed, so any server syncing it would 404 on download and wedge its
36
- * sync cursor. So this is a no-op that logs the limitation. Local deletion
37
- * (index rows + on-disk blobs) still happens via the storage port's
38
- * `deleteScope`, independent of this worker — only the *remote* copy is left
39
- * in place until DPv2 grows a deletion API.
128
+ * Not serialised here: the sync manager runs this under the same lock as its
129
+ * upload/download cycles so a delete cannot interleave with an upload of the
130
+ * same scope on this replica (see engine/sync-manager.ts). Uploads racing on
131
+ * another replica are handled by the upload worker's deletion guard and the
132
+ * download worker's reconcile.
133
+ */
134
+ export declare function deleteScope(deps: DeleteScopeDeps, scope: string): Promise<DeleteScopeResult>;
135
+ export interface RetryPendingBlobDeletionsResult {
136
+ /** Exact keys finished this pass (deleted, or already absent). */
137
+ completed: PendingBlobDeletion[];
138
+ /** Unexpanded markers dropped because the scope is live again. */
139
+ superseded: string[];
140
+ failed: Array<{
141
+ scope: string;
142
+ version: string | null;
143
+ error: string;
144
+ }>;
145
+ /** Markers still queued after this pass (a range counts once). */
146
+ remaining: number;
147
+ }
148
+ /**
149
+ * Finish blob deletions whose tombstone landed but whose storage deletes did
150
+ * not: one batch of exact keys per sync cycle, taken from exact-key markers
151
+ * first and then from the head of range markers (which advance in place),
152
+ * each key retried until storage acknowledges (2xx or 404). Unexpanded
153
+ * markers (the gateway did not report a tombstone version at delete time)
154
+ * are expanded from the registry first; if the registry shows the scope live
155
+ * again the old tombstone's version is unknowable, so the marker is dropped
156
+ * and the pre-tombstone ciphertext stays (owner-decryptable only) until the
157
+ * next delete of that scope.
40
158
  */
41
- export declare function deleteScopeRemote(deps: DeleteWorkerDeps, scope: string): Promise<DeleteScopeRemoteResult>;
159
+ export declare function retryPendingBlobDeletions(deps: Pick<DeleteScopeDeps, "deleteData" | "pendingBlobDeletions" | "dataPointFeed" | "serverOwner" | "logger"> & {
160
+ /** Local index, for expanding unexpanded markers into exact keys. */
161
+ storage?: Pick<DataStoragePort, "listVersions">;
162
+ }): Promise<RetryPendingBlobDeletionsResult>;
42
163
  //# sourceMappingURL=delete.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../src/sync/workers/delete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,u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