@terreno/api 0.30.0 → 56.0.0-beta.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.
- package/dist/api.d.ts +10 -0
- package/dist/api.js +110 -361
- package/dist/auth.d.ts +26 -0
- package/dist/auth.js +100 -1
- package/dist/betterAuth.d.ts +5 -0
- package/dist/betterAuthSetup.js +23 -4
- package/dist/docLoader.js +12 -9
- package/dist/errors.d.ts +13 -0
- package/dist/errors.js +29 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +29 -1
- package/dist/middleware.d.ts +7 -0
- package/dist/middleware.js +16 -1
- package/dist/openApiCompat.d.ts +10 -1
- package/dist/openApiCompat.js +115 -47
- package/dist/permissions.d.ts +27 -0
- package/dist/permissions.js +42 -1
- package/dist/plugins.d.ts +13 -0
- package/dist/plugins.js +35 -1
- package/dist/realtime/changeStreamWatcher.d.ts +100 -3
- package/dist/realtime/changeStreamWatcher.js +542 -137
- package/dist/realtime/realtimeApp.d.ts +2 -0
- package/dist/realtime/realtimeApp.js +73 -21
- package/dist/realtime/sessionRevalidation.d.ts +90 -0
- package/dist/realtime/sessionRevalidation.js +438 -0
- package/dist/realtime/socketAuth.d.ts +97 -0
- package/dist/realtime/socketAuth.js +272 -0
- package/dist/realtime/socketUser.d.ts +54 -0
- package/dist/realtime/socketUser.js +75 -5
- package/dist/realtime/types.d.ts +40 -0
- package/dist/secretProviders.d.ts +23 -0
- package/dist/secretProviders.js +9 -3
- package/dist/sync/executors.d.ts +198 -0
- package/dist/sync/executors.js +670 -0
- package/dist/sync/loadHarness.js +807 -0
- package/dist/sync/models.d.ts +216 -0
- package/dist/sync/models.js +644 -0
- package/dist/sync/mutationHandler.d.ts +97 -0
- package/dist/sync/mutationHandler.js +886 -0
- package/dist/sync/registry.d.ts +73 -0
- package/dist/sync/registry.js +223 -0
- package/dist/sync/routes.d.ts +62 -0
- package/dist/sync/routes.js +936 -0
- package/dist/sync/scripts/compactTombstones.d.ts +47 -0
- package/dist/sync/scripts/compactTombstones.js +270 -0
- package/dist/sync/serialize.d.ts +20 -0
- package/dist/{tests/bunSetup.js → sync/serialize.js} +35 -68
- package/dist/sync/socketHandlers.d.ts +54 -0
- package/dist/sync/socketHandlers.js +470 -0
- package/dist/sync/streams.d.ts +85 -0
- package/dist/sync/streams.js +221 -0
- package/dist/sync/syncApp.d.ts +29 -0
- package/dist/sync/syncApp.js +44 -0
- package/dist/sync/syncBatch.d.ts +71 -0
- package/dist/sync/syncBatch.js +252 -0
- package/dist/sync/syncSeqPlugin.d.ts +8 -0
- package/dist/sync/syncSeqPlugin.js +903 -0
- package/dist/sync/types.d.ts +254 -0
- package/dist/sync/types.js +9 -0
- package/dist/terrenoApp.js +90 -27
- package/dist/vendor/wesleytodd-openapi/index.d.ts +1 -1
- package/dist/vendor/wesleytodd-openapi/lib/ui.d.ts +2 -1
- package/package.json +7 -6
- package/src/__tests__/openApiCompat.test.ts +20 -0
- package/src/actions.openApi.test.ts +7 -10
- package/src/api.test.ts +12 -0
- package/src/api.ts +87 -295
- package/src/auth.test.ts +128 -176
- package/src/auth.ts +109 -0
- package/src/betterAuth.ts +6 -0
- package/src/betterAuthSetup.test.ts +34 -0
- package/src/betterAuthSetup.ts +20 -1
- package/src/docLoader.ts +3 -1
- package/src/errors.ts +33 -0
- package/src/expressServer.test.ts +7 -1
- package/src/index.ts +42 -0
- package/src/middleware.test.ts +40 -1
- package/src/middleware.ts +15 -0
- package/src/openApiCompat.ts +99 -45
- package/src/permissions.test.ts +75 -1
- package/src/permissions.ts +49 -0
- package/src/plugins.test.ts +54 -0
- package/src/plugins.ts +43 -0
- package/src/realtime/changeStreamWatcher.ts +552 -114
- package/src/realtime/realtime.test.ts +157 -0
- package/src/realtime/realtimeApp.ts +75 -11
- package/src/realtime/sessionRevalidation.test.ts +423 -0
- package/src/realtime/sessionRevalidation.ts +273 -0
- package/src/realtime/socketAuth.test.ts +355 -0
- package/src/realtime/socketAuth.ts +228 -0
- package/src/realtime/socketUser.ts +69 -0
- package/src/realtime/types.ts +40 -0
- package/src/secretProviders.test.ts +7 -1
- package/src/secretProviders.ts +15 -3
- package/src/sync/ensureSyncIndexes.test.ts +144 -0
- package/src/sync/executors.test.ts +882 -0
- package/src/sync/executors.ts +703 -0
- package/src/sync/integration.test.ts +1160 -0
- package/src/sync/loadHarness.ts +618 -0
- package/src/sync/models.ts +640 -0
- package/src/sync/mutationHandler.test.ts +1252 -0
- package/src/sync/mutationHandler.ts +850 -0
- package/src/sync/registry.ts +232 -0
- package/src/sync/routes.ts +812 -0
- package/src/sync/scripts/compactTombstones.test.ts +249 -0
- package/src/sync/scripts/compactTombstones.ts +145 -0
- package/src/sync/serialize.ts +48 -0
- package/src/sync/sessionRevalidationIntegration.test.ts +281 -0
- package/src/sync/socketHandlers.ts +320 -0
- package/src/sync/streams.ts +188 -0
- package/src/sync/sync.test.ts +582 -0
- package/src/sync/syncApp.ts +44 -0
- package/src/sync/syncBatch.ts +219 -0
- package/src/sync/syncFrontier.test.ts +494 -0
- package/src/sync/syncPhaseC.test.ts +718 -0
- package/src/sync/syncRoutes.test.ts +865 -0
- package/src/sync/syncSeqPlugin.ts +738 -0
- package/src/sync/syncSocket.test.ts +1440 -0
- package/src/sync/types.ts +270 -0
- package/src/terrenoApp.ts +37 -17
- package/src/tests/bunSetup.ts +8 -0
- package/tsconfig.json +4 -4
- package/tsconfig.typedoc.json +7 -1
- package/dist/__tests__/openApiCompat.test.js +0 -317
- package/dist/__tests__/versionCheckPlugin.test.d.ts +0 -1
- package/dist/__tests__/versionCheckPlugin.test.js +0 -597
- package/dist/actions.openApi.test.d.ts +0 -1
- package/dist/actions.openApi.test.js +0 -255
- package/dist/actions.test.d.ts +0 -1
- package/dist/actions.test.js +0 -1089
- package/dist/api.arrayOperations.test.d.ts +0 -1
- package/dist/api.arrayOperations.test.js +0 -878
- package/dist/api.asyncHandler.test.d.ts +0 -1
- package/dist/api.asyncHandler.test.js +0 -236
- package/dist/api.coverage.test.d.ts +0 -1
- package/dist/api.coverage.test.js +0 -194
- package/dist/api.errorPaths.test.d.ts +0 -1
- package/dist/api.errorPaths.test.js +0 -801
- package/dist/api.errors.test.d.ts +0 -1
- package/dist/api.errors.test.js +0 -185
- package/dist/api.hooks.test.d.ts +0 -1
- package/dist/api.hooks.test.js +0 -950
- package/dist/api.query.test.d.ts +0 -1
- package/dist/api.query.test.js +0 -948
- package/dist/api.test.d.ts +0 -1
- package/dist/api.test.js +0 -2820
- package/dist/auth.compile.test.d.ts +0 -1
- package/dist/auth.compile.test.js +0 -201
- package/dist/auth.coverage.test.d.ts +0 -1
- package/dist/auth.coverage.test.js +0 -202
- package/dist/auth.test.d.ts +0 -1
- package/dist/auth.test.js +0 -2286
- package/dist/betterAuth.test.d.ts +0 -1
- package/dist/betterAuth.test.js +0 -181
- package/dist/betterAuthApp.test.d.ts +0 -1
- package/dist/betterAuthApp.test.js +0 -242
- package/dist/betterAuthSetup.test.d.ts +0 -1
- package/dist/betterAuthSetup.test.js +0 -762
- package/dist/config.test.d.ts +0 -1
- package/dist/config.test.js +0 -353
- package/dist/configuration.test.d.ts +0 -1
- package/dist/configuration.test.js +0 -980
- package/dist/configurationPlugin.test.d.ts +0 -1
- package/dist/configurationPlugin.test.js +0 -827
- package/dist/consentApp.test.d.ts +0 -1
- package/dist/consentApp.test.js +0 -1415
- package/dist/docLoader.test.d.ts +0 -1
- package/dist/docLoader.test.js +0 -137
- package/dist/envConfigurationPlugin.test.d.ts +0 -1
- package/dist/envConfigurationPlugin.test.js +0 -369
- package/dist/errors.test.d.ts +0 -1
- package/dist/errors.test.js +0 -607
- package/dist/expressServer.test.d.ts +0 -1
- package/dist/expressServer.test.js +0 -1249
- package/dist/githubAuth.test.d.ts +0 -1
- package/dist/githubAuth.test.js +0 -1142
- package/dist/httpClient.test.d.ts +0 -1
- package/dist/httpClient.test.js +0 -1471
- package/dist/logger.test.d.ts +0 -1
- package/dist/logger.test.js +0 -685
- package/dist/middleware.test.d.ts +0 -1
- package/dist/middleware.test.js +0 -241
- package/dist/notifiers/googleChatNotifier.test.d.ts +0 -1
- package/dist/notifiers/googleChatNotifier.test.js +0 -298
- package/dist/notifiers/slackNotifier.test.d.ts +0 -1
- package/dist/notifiers/slackNotifier.test.js +0 -297
- package/dist/notifiers/zoomNotifier.test.d.ts +0 -1
- package/dist/notifiers/zoomNotifier.test.js +0 -373
- package/dist/openApi.test.d.ts +0 -1
- package/dist/openApi.test.js +0 -620
- package/dist/openApiBuilder.test.d.ts +0 -1
- package/dist/openApiBuilder.test.js +0 -601
- package/dist/openApiEtag.test.d.ts +0 -1
- package/dist/openApiEtag.test.js +0 -86
- package/dist/openApiValidator.test.d.ts +0 -1
- package/dist/openApiValidator.test.js +0 -761
- package/dist/permissions.middleware.test.d.ts +0 -1
- package/dist/permissions.middleware.test.js +0 -308
- package/dist/permissions.test.d.ts +0 -1
- package/dist/permissions.test.js +0 -439
- package/dist/plugins.test.d.ts +0 -1
- package/dist/plugins.test.js +0 -890
- package/dist/populate.test.d.ts +0 -1
- package/dist/populate.test.js +0 -373
- package/dist/realtime/realtime.test.d.ts +0 -10
- package/dist/realtime/realtime.test.js +0 -3982
- package/dist/requestContext.test.d.ts +0 -1
- package/dist/requestContext.test.js +0 -412
- package/dist/scriptRunner.test.d.ts +0 -1
- package/dist/scriptRunner.test.js +0 -386
- package/dist/secretProviders.test.d.ts +0 -1
- package/dist/secretProviders.test.js +0 -726
- package/dist/syncConsents.test.d.ts +0 -1
- package/dist/syncConsents.test.js +0 -522
- package/dist/terrenoApp.test.d.ts +0 -1
- package/dist/terrenoApp.test.js +0 -489
- package/dist/tests/bunSetup.d.ts +0 -1
- package/dist/tests/fixtures/compileAuthEntry.d.ts +0 -1
- package/dist/tests/fixtures/compileAuthEntry.js +0 -37
- package/dist/tests/testEnv.d.ts +0 -0
- package/dist/tests/testEnv.js +0 -6
- package/dist/transformers.test.d.ts +0 -1
- package/dist/transformers.test.js +0 -423
- package/dist/utils.test.d.ts +0 -1
- package/dist/utils.test.js +0 -242
- /package/dist/{__tests__/openApiCompat.test.d.ts → sync/loadHarness.d.ts} +0 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import mongoose, { type ClientSession, type Model } from "mongoose";
|
|
2
|
+
/**
|
|
3
|
+
* Mongoose models backing the SyncDB protocol: the per-stream monotonic counter
|
|
4
|
+
* and the per-user encryption key material.
|
|
5
|
+
*/
|
|
6
|
+
/** An uncommitted seq claim recorded on the counter's in-flight registry (C1). */
|
|
7
|
+
export interface SyncPendingClaim {
|
|
8
|
+
/** The claimed seq (or, for a batch, one entry per claimed seq). */
|
|
9
|
+
seq: number;
|
|
10
|
+
/** When the claim was registered; a claim older than the lease is reclaimable. */
|
|
11
|
+
claimedAt: Date;
|
|
12
|
+
}
|
|
13
|
+
export interface SyncCounterDocument {
|
|
14
|
+
_id: mongoose.Types.ObjectId;
|
|
15
|
+
stream: string;
|
|
16
|
+
seq: number;
|
|
17
|
+
/**
|
|
18
|
+
* C1: seqs claimed but not yet confirmed committed. The stable frontier is
|
|
19
|
+
* `min(pending.seq) - 1`, or `seq` (the head) when empty, so a cursor never
|
|
20
|
+
* advances past a seq whose owning write has not yet landed.
|
|
21
|
+
*/
|
|
22
|
+
pending: SyncPendingClaim[];
|
|
23
|
+
/**
|
|
24
|
+
* C7 retention watermark: the highest seq on this stream whose row (tombstone or
|
|
25
|
+
* scope-move marker) has been hard-deleted by `compactTombstones`. A client whose
|
|
26
|
+
* cursor is below this may have missed a compacted deletion and must re-bootstrap;
|
|
27
|
+
* a client at or above it has already seen everything that was reaped. 0 until the
|
|
28
|
+
* first compaction pass touches the stream.
|
|
29
|
+
*/
|
|
30
|
+
compactedThroughSeq: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* C1: a `pending` claim older than this is treated as abandoned (the writer
|
|
34
|
+
* crashed between claiming and confirming) and excluded from the frontier — a
|
|
35
|
+
* crashed writer must never freeze the frontier forever. Default 60s.
|
|
36
|
+
*/
|
|
37
|
+
export declare const PENDING_CLAIM_LEASE_MS: number;
|
|
38
|
+
export declare const SyncCounter: Model<SyncCounterDocument>;
|
|
39
|
+
/**
|
|
40
|
+
* Result of a seq claim: the last seq claimed (range [lastSeq - count + 1, lastSeq])
|
|
41
|
+
* and whether the claim registered a pending entry that a later `confirmSyncSeqs`
|
|
42
|
+
* must clear. A session-backed claim skips the pending registry entirely (the write
|
|
43
|
+
* and the `$inc` commit atomically), so `registered` is false and no confirm is due.
|
|
44
|
+
*/
|
|
45
|
+
export interface SyncSeqClaim {
|
|
46
|
+
/** The last (highest) seq claimed; the range is [lastSeq - count + 1, lastSeq]. */
|
|
47
|
+
lastSeq: number;
|
|
48
|
+
/** Every seq claimed, in ascending order (the range materialized). */
|
|
49
|
+
seqs: number[];
|
|
50
|
+
/** True when a pending registry entry was recorded and `confirmSyncSeqs` must clear it. */
|
|
51
|
+
registered: boolean;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* C1: atomically claim `count` sequence numbers for a stream AND register them on
|
|
55
|
+
* the in-flight registry so the stable frontier can exclude them until committed.
|
|
56
|
+
*
|
|
57
|
+
* Two modes:
|
|
58
|
+
* - **No caller session (the hot path):** one `findOneAndUpdate` does `$inc: {seq}`
|
|
59
|
+
* plus `$push` of a `pending` entry per claimed seq. The write commits separately,
|
|
60
|
+
* so `confirmSyncSeqs` must `$pull` the entries once it lands. Until then the
|
|
61
|
+
* frontier holds below the lowest pending seq.
|
|
62
|
+
* - **Caller session present:** the `$inc` and the document write commit atomically
|
|
63
|
+
* in the caller's transaction, so there is no window where a claimed seq is
|
|
64
|
+
* uncommitted — the pending registry is skipped (`registered: false`, nothing to
|
|
65
|
+
* confirm). Frontier logic treats a session-backed claim as already committed.
|
|
66
|
+
*
|
|
67
|
+
* Retries once on the upsert race (two concurrent first claims for a new stream).
|
|
68
|
+
*/
|
|
69
|
+
export declare const claimSyncSeqs: ({ stream, count, session, }: {
|
|
70
|
+
stream: string;
|
|
71
|
+
count?: number;
|
|
72
|
+
session?: ClientSession | null;
|
|
73
|
+
}) => Promise<SyncSeqClaim>;
|
|
74
|
+
/** Outcome of clearing pending claims from a stream's in-flight registry. */
|
|
75
|
+
export interface SyncSeqConfirmResult {
|
|
76
|
+
/**
|
|
77
|
+
* True when at least one pending entry was actually removed. False means the claim
|
|
78
|
+
* was already gone — for a `registered` claim that is the reaped-lease signature
|
|
79
|
+
* (Task 9.17): the writer stalled past {@link PENDING_CLAIM_LEASE_MS},
|
|
80
|
+
* `computeStableFrontier` reclaimed its seq, and the frontier has already advanced
|
|
81
|
+
* past a seq whose write only just landed. Callers must re-stamp the document (see
|
|
82
|
+
* `restampReapedSeq`) or log loudly rather than silently stranding it.
|
|
83
|
+
*/
|
|
84
|
+
cleared: boolean;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* C1: confirm that the writes owning `seqs` on `stream` have committed, clearing
|
|
88
|
+
* their pending registry entries so the stable frontier can advance past them.
|
|
89
|
+
* A no-op when `seqs` is empty (a session-backed claim registered nothing). Runs
|
|
90
|
+
* after the document write commits (`post("save")` / query-write post hook); a
|
|
91
|
+
* `$pull` failure is logged by the caller and left to age out via the lease.
|
|
92
|
+
*
|
|
93
|
+
* Returns whether anything was actually cleared so callers can detect a reaped
|
|
94
|
+
* lease — see {@link SyncSeqConfirmResult}.
|
|
95
|
+
*/
|
|
96
|
+
export declare const confirmSyncSeqs: ({ stream, seqs, session, }: {
|
|
97
|
+
stream: string;
|
|
98
|
+
seqs: number[];
|
|
99
|
+
session?: ClientSession | null;
|
|
100
|
+
}) => Promise<SyncSeqConfirmResult>;
|
|
101
|
+
/**
|
|
102
|
+
* Cancel claimed-but-never-used seqs (Task 9.13): the owning write failed, so the seqs
|
|
103
|
+
* will never be stamped on any document and holding the frontier below them for the
|
|
104
|
+
* full lease would stall every catch-up cursor on the stream for no reason. Unlike
|
|
105
|
+
* `confirmSyncSeqs` this is only safe when the write is known NOT to have committed
|
|
106
|
+
* (e.g. a Mongoose `VersionError`, where the conditional update matched no document).
|
|
107
|
+
*/
|
|
108
|
+
export declare const releaseSyncSeqs: ({ stream, seqs, session, }: {
|
|
109
|
+
stream: string;
|
|
110
|
+
seqs: number[];
|
|
111
|
+
session?: ClientSession | null;
|
|
112
|
+
}) => Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* C1: the stable frontier for a stream — the highest seq below which no claim is
|
|
115
|
+
* uncommitted. A cursor (snapshot or delta) may advance to seq N only when N is at
|
|
116
|
+
* or below this value, so no committed document is ever permanently skipped.
|
|
117
|
+
*
|
|
118
|
+
* frontier = `min(live pending.seq) - 1`, or the head `seq` when no live pending
|
|
119
|
+
* entries remain. A pending entry older than {@link PENDING_CLAIM_LEASE_MS} is
|
|
120
|
+
* considered abandoned (crashed writer): it is excluded from the min AND `$pull`ed
|
|
121
|
+
* opportunistically so a crash cannot freeze the frontier forever.
|
|
122
|
+
*/
|
|
123
|
+
export declare const computeStableFrontier: ({ stream }: {
|
|
124
|
+
stream: string;
|
|
125
|
+
}) => Promise<number>;
|
|
126
|
+
/**
|
|
127
|
+
* C7: raise a stream's retention watermark to `seq` (never lowers it — `$max`), called by
|
|
128
|
+
* `compactTombstones` after it hard-deletes rows. Served to clients as the snapshot's
|
|
129
|
+
* `oldestRetainedSeq`, which is the only signal that a stale cursor must re-bootstrap.
|
|
130
|
+
* Does not create the counter: a stream with compacted rows always already has one.
|
|
131
|
+
*/
|
|
132
|
+
export declare const recordCompactedThroughSeq: ({ stream, seq, }: {
|
|
133
|
+
stream: string;
|
|
134
|
+
seq: number;
|
|
135
|
+
}) => Promise<void>;
|
|
136
|
+
/**
|
|
137
|
+
* C7: the stream's retention watermark — the highest seq whose tombstone/marker has been
|
|
138
|
+
* compacted away. 0 when nothing has been compacted (no retention gap to enforce).
|
|
139
|
+
*/
|
|
140
|
+
export declare const getCompactedThroughSeq: ({ stream }: {
|
|
141
|
+
stream: string;
|
|
142
|
+
}) => Promise<number>;
|
|
143
|
+
export interface SyncScopeMoveDocument {
|
|
144
|
+
_id: mongoose.Types.ObjectId;
|
|
145
|
+
collectionTag: string;
|
|
146
|
+
entityId: string;
|
|
147
|
+
fromStream: string;
|
|
148
|
+
toStream: string;
|
|
149
|
+
seq: number;
|
|
150
|
+
created: Date;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* C4: durable marker written in the same op-scope as a scope move, replacing the
|
|
154
|
+
* racy `_syncPrevStream` post-image read. The old stream tombstones the document
|
|
155
|
+
* from this marker (change-stream fan-out + snapshot catch-up), so a racing second
|
|
156
|
+
* write that overwrites `_syncPrevStream` can no longer erase the tombstone.
|
|
157
|
+
*
|
|
158
|
+
* Retention: reaped only by `compactTombstones`, which honors the owning model's
|
|
159
|
+
* `retentionDays` and records a `compactedThroughSeq` watermark as it deletes.
|
|
160
|
+
*/
|
|
161
|
+
export declare const SyncScopeMove: Model<SyncScopeMoveDocument>;
|
|
162
|
+
/** Lifecycle status of a sync mutation ledger row. */
|
|
163
|
+
export type SyncMutationStatus = "pending" | "applied" | "conflicted" | "failed";
|
|
164
|
+
export interface SyncMutationDocument {
|
|
165
|
+
_id: mongoose.Types.ObjectId;
|
|
166
|
+
mutationId: string;
|
|
167
|
+
userId: string;
|
|
168
|
+
status: SyncMutationStatus;
|
|
169
|
+
nackCode?: string;
|
|
170
|
+
resultId?: string;
|
|
171
|
+
resultSeq?: number;
|
|
172
|
+
error?: string;
|
|
173
|
+
created: Date;
|
|
174
|
+
claimedAt: Date;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* C5 (FIX 6): a `pending` row older than this may be taken over by a fresh
|
|
178
|
+
* delivery — the original claimant is assumed to have crashed between the
|
|
179
|
+
* claim and finalizing the ledger row.
|
|
180
|
+
*/
|
|
181
|
+
export declare const SYNC_MUTATION_LEASE_MS: number;
|
|
182
|
+
/**
|
|
183
|
+
* Idempotency ledger for the sync mutation channel. A row is inserted with status
|
|
184
|
+
* `pending` before a mutation is applied (the atomic claim on the unique mutationId);
|
|
185
|
+
* the outcome is recorded on the same row so duplicate deliveries — socket retries or
|
|
186
|
+
* the HTTP fallback racing a socket send — read back the recorded outcome instead of
|
|
187
|
+
* re-applying.
|
|
188
|
+
*
|
|
189
|
+
* Task 9.21: a row NEVER stores document data. A conflict records only
|
|
190
|
+
* `{resultId, resultSeq}`; a duplicate delivery re-serializes the live document from
|
|
191
|
+
* `resultId` through the collection's sync `responseHandler`, so PHI is not retained in
|
|
192
|
+
* `syncmutations` for the 30-day TTL and the client also sees current (not stale) state.
|
|
193
|
+
*/
|
|
194
|
+
export declare const SyncMutation: Model<SyncMutationDocument>;
|
|
195
|
+
export interface SyncKeyDocument {
|
|
196
|
+
_id: mongoose.Types.ObjectId;
|
|
197
|
+
userId: string;
|
|
198
|
+
keyMaterial: string;
|
|
199
|
+
created: Date;
|
|
200
|
+
}
|
|
201
|
+
export declare const SyncKey: Model<SyncKeyDocument>;
|
|
202
|
+
/**
|
|
203
|
+
* Build the indexes for every sync bookkeeping model, throwing on the first failure so
|
|
204
|
+
* server startup fails loudly. Kicked off by `SyncApp.register` and awaited through
|
|
205
|
+
* `ensureSyncIndexes()`; idempotent, so calling it repeatedly is safe.
|
|
206
|
+
*/
|
|
207
|
+
export declare const ensureSyncModelIndexes: () => Promise<void>;
|
|
208
|
+
/**
|
|
209
|
+
* Return the user's key material, generating it on first call. Race-safe: concurrent
|
|
210
|
+
* first calls converge on the single persisted value via `$setOnInsert` upsert — a
|
|
211
|
+
* caller must never receive bytes that were not persisted, or its encrypted store
|
|
212
|
+
* would be undecryptable by any other session.
|
|
213
|
+
*/
|
|
214
|
+
export declare const getOrCreateSyncKeyMaterial: ({ userId }: {
|
|
215
|
+
userId: string;
|
|
216
|
+
}) => Promise<string>;
|