@gaganref/confect-test 10.3.1-fork.92 → 10.3.1-fork.93

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 (36) hide show
  1. package/dist/TestConfect.d.ts +26 -0
  2. package/dist/TestConfect.d.ts.map +1 -1
  3. package/dist/TestConfect.js +9 -1
  4. package/dist/TestConfect.js.map +1 -1
  5. package/dist/internal/ConvexTest.d.ts +26 -1
  6. package/dist/internal/ConvexTest.d.ts.map +1 -1
  7. package/dist/internal/ConvexTest.js +55 -27
  8. package/dist/internal/ConvexTest.js.map +1 -1
  9. package/dist/internal/Execution.d.ts +138 -1
  10. package/dist/internal/Execution.d.ts.map +1 -1
  11. package/dist/internal/Execution.js +595 -182
  12. package/dist/internal/Execution.js.map +1 -1
  13. package/dist/internal/KernelRefusal.d.ts +134 -0
  14. package/dist/internal/KernelRefusal.d.ts.map +1 -1
  15. package/dist/internal/KernelRefusal.js +134 -1
  16. package/dist/internal/KernelRefusal.js.map +1 -1
  17. package/dist/internal/Redaction.d.ts +142 -0
  18. package/dist/internal/Redaction.d.ts.map +1 -0
  19. package/dist/internal/Redaction.js +448 -0
  20. package/dist/internal/Redaction.js.map +1 -0
  21. package/dist/internal/Snapshot.d.ts +298 -0
  22. package/dist/internal/Snapshot.d.ts.map +1 -0
  23. package/dist/internal/Snapshot.js +532 -0
  24. package/dist/internal/Snapshot.js.map +1 -0
  25. package/dist/internal/Subscriptions.d.ts +13 -0
  26. package/dist/internal/Subscriptions.d.ts.map +1 -1
  27. package/dist/internal/Subscriptions.js +27 -3
  28. package/dist/internal/Subscriptions.js.map +1 -1
  29. package/package.json +3 -3
  30. package/src/TestConfect.ts +63 -4
  31. package/src/internal/ConvexTest.ts +135 -38
  32. package/src/internal/Execution.ts +886 -287
  33. package/src/internal/KernelRefusal.ts +160 -0
  34. package/src/internal/Redaction.ts +730 -0
  35. package/src/internal/Snapshot.ts +945 -0
  36. package/src/internal/Subscriptions.ts +34 -4
@@ -0,0 +1,298 @@
1
+ import { type JSONValue } from "convex/values";
2
+ import * as Result from "effect/Result";
3
+ import * as Schema from "effect/Schema";
4
+ import type * as Kernel from "./Kernel.js";
5
+ import * as KernelRefusal from "./KernelRefusal.js";
6
+ import { type DocumentId, type FunctionPath } from "./KernelValues.js";
7
+ /**
8
+ * The counters the kernel allocates identities from: the next document ID, the
9
+ * latest creation time handed out, the next held attempt's ID, and the identity
10
+ * epoch, which every subscriber's `authenticate` advances. A restored world
11
+ * continues each where its source stopped, so the same calls mint the same
12
+ * identities and the same identity versions.
13
+ */
14
+ export interface Identity {
15
+ readonly nextDocumentId: number;
16
+ readonly lastCreationTime: number;
17
+ readonly nextAttemptId: number;
18
+ readonly identityEpoch: number;
19
+ }
20
+ /**
21
+ * What the kernel keeps beside a job's row, with the job's test world named
22
+ * rather than held. `null` is a job scheduled with no invocation bound.
23
+ */
24
+ export interface JobTarget {
25
+ readonly functionPath: FunctionPath;
26
+ readonly standing: boolean;
27
+ readonly world: string | null;
28
+ }
29
+ /**
30
+ * The kernel state a snapshot carries: committed rows of every component with
31
+ * the version that wrote each, the write log, the latest commit timestamp,
32
+ * every job's target, the clock's floor and the identity counters.
33
+ */
34
+ export interface Image {
35
+ readonly components: ReadonlyArray<string>;
36
+ readonly state: Kernel.State;
37
+ /**
38
+ * The latest deadline the clock was advanced to. `-Infinity` before any.
39
+ */
40
+ readonly floor: number;
41
+ readonly identity: Identity;
42
+ /**
43
+ * The target of every job whose row is committed, by job ID.
44
+ */
45
+ readonly jobs: ReadonlyMap<DocumentId, JobTarget>;
46
+ }
47
+ /**
48
+ * Whether a piece of kernel state is in a snapshot. `exported` names the
49
+ * snapshot field that carries it. `excluded` says why a restore starts without
50
+ * it.
51
+ */
52
+ export type Participation = {
53
+ readonly exported: string;
54
+ } | {
55
+ readonly excluded: string;
56
+ };
57
+ /**
58
+ * The snapshot's contract with the kernel's state. Every field of the committed
59
+ * state, of a job's target and of a `World` is listed here as exported or
60
+ * excluded with its reason. The first two are checked by type: a field added to
61
+ * `Kernel.State` or `Scheduling.Target` without an entry fails to compile. A
62
+ * `World`'s fields are private, which no type can enumerate, so
63
+ * `Snapshot.test.ts` compares a fresh world's own fields with `world` below,
64
+ * and a field added without an entry fails that test.
65
+ *
66
+ * That test sees only the own fields a fresh world has. It cannot see state
67
+ * created lazily after construction, held under a symbol or a `#private` name,
68
+ * or kept in a closure or another object, as subscribers are. So every live
69
+ * registry, state that exists only while something runs or a client is
70
+ * attached, is also listed in `live`. `World.liveCounts` reports each one,
71
+ * typed against `live`, and a restore refuses while any of them is non-empty,
72
+ * so a piece of live state the snapshot does not carry fails loudly rather than
73
+ * surviving a restore silently. A new live registry adds itself there.
74
+ *
75
+ * Owed by later rows, which add their state here when they land on `main`: cron
76
+ * state (#133), stored file bytes, storage ID mappings, `nextFile` and
77
+ * upload-token counters (#138), and component init markers. A restore never
78
+ * redeclares a cron and never draws a fresh random value: it installs the
79
+ * declared state as the snapshot holds it, so a row whose state comes from a
80
+ * declaration or a random draw exports what was declared or drawn.
81
+ */
82
+ export declare const contract: {
83
+ readonly state: {
84
+ tables: {
85
+ exported: string;
86
+ };
87
+ version: {
88
+ exported: string;
89
+ };
90
+ commitTs: {
91
+ exported: string;
92
+ };
93
+ log: {
94
+ exported: string;
95
+ };
96
+ };
97
+ readonly target: {
98
+ functionPath: {
99
+ exported: string;
100
+ };
101
+ standing: {
102
+ exported: string;
103
+ };
104
+ world: {
105
+ exported: string;
106
+ };
107
+ };
108
+ readonly world: {
109
+ components: {
110
+ excluded: string;
111
+ };
112
+ state: {
113
+ exported: string;
114
+ };
115
+ opened: {
116
+ excluded: string;
117
+ };
118
+ nextDocId: {
119
+ exported: string;
120
+ };
121
+ lastCreationTime: {
122
+ exported: string;
123
+ };
124
+ nextQueryId: {
125
+ excluded: string;
126
+ };
127
+ queries: {
128
+ excluded: string;
129
+ };
130
+ holding: {
131
+ excluded: string;
132
+ };
133
+ nextAttemptId: {
134
+ exported: string;
135
+ };
136
+ floor: {
137
+ exported: string;
138
+ };
139
+ targets: {
140
+ exported: string;
141
+ };
142
+ live: {
143
+ excluded: string;
144
+ };
145
+ identityEpoch: {
146
+ exported: string;
147
+ };
148
+ runtime: {
149
+ excluded: string;
150
+ };
151
+ redaction: {
152
+ excluded: string;
153
+ };
154
+ secrets: {
155
+ excluded: string;
156
+ };
157
+ };
158
+ /**
159
+ * Live registries: what blocks a snapshot while it is non-empty, and why.
160
+ */
161
+ readonly live: {
162
+ running: {
163
+ blocks: "export and restore";
164
+ reason: string;
165
+ };
166
+ walks: {
167
+ blocks: "export and restore";
168
+ reason: string;
169
+ };
170
+ functions: {
171
+ blocks: "export and restore";
172
+ reason: string;
173
+ };
174
+ held: {
175
+ blocks: "export and restore";
176
+ reason: string;
177
+ };
178
+ subscribers: {
179
+ blocks: "restore";
180
+ reason: string;
181
+ };
182
+ };
183
+ /**
184
+ * State outside the kernel's world, live per client or per process.
185
+ */
186
+ readonly outside: {
187
+ subscriptions: {
188
+ excluded: string;
189
+ };
190
+ requestIds: {
191
+ excluded: string;
192
+ };
193
+ };
194
+ };
195
+ declare const Body: Schema.Struct<{
196
+ readonly components: Schema.$Array<Schema.String>;
197
+ readonly version: Schema.Int;
198
+ readonly commitTs: Schema.String;
199
+ readonly floor: Schema.NullOr<Schema.Finite>;
200
+ readonly identity: Schema.Struct<{
201
+ readonly nextDocumentId: Schema.Int;
202
+ readonly lastCreationTime: Schema.Finite;
203
+ readonly nextAttemptId: Schema.Int;
204
+ readonly identityEpoch: Schema.Int;
205
+ }>;
206
+ readonly tables: Schema.$Array<Schema.Struct<{
207
+ readonly componentPath: Schema.String;
208
+ readonly table: Schema.String;
209
+ readonly rows: Schema.$Array<Schema.Struct<{
210
+ readonly version: Schema.Int;
211
+ readonly doc: Schema.Unknown;
212
+ }>>;
213
+ }>>;
214
+ readonly jobs: Schema.$Array<Schema.Struct<{
215
+ readonly id: Schema.String;
216
+ readonly target: Schema.Struct<{
217
+ readonly componentPath: Schema.String;
218
+ readonly udfPath: Schema.String;
219
+ }>;
220
+ readonly standing: Schema.Boolean;
221
+ readonly world: Schema.NullOr<Schema.String>;
222
+ }>>;
223
+ readonly log: Schema.$Array<Schema.Struct<{
224
+ readonly version: Schema.Int;
225
+ readonly commitTs: Schema.String;
226
+ readonly changes: Schema.$Array<Schema.Struct<{
227
+ readonly componentPath: Schema.String;
228
+ readonly id: Schema.String;
229
+ readonly before: Schema.Unknown;
230
+ readonly after: Schema.Unknown;
231
+ }>>;
232
+ }>>;
233
+ }>;
234
+ type Body = typeof Body.Type;
235
+ /**
236
+ * What an export writes for one document, before it reaches the bytes: the
237
+ * kernel marks secrets here. `table` is the document's table.
238
+ */
239
+ export type Redact = (componentPath: string, table: string, json: JSONValue) => JSONValue;
240
+ /**
241
+ * What a restore reads back for one document before decoding it: the kernel
242
+ * puts marked secrets back here.
243
+ */
244
+ export type Unredact = (json: JSONValue) => Result.Result<JSONValue, KernelRefusal.SnapshotSecretMissing>;
245
+ /**
246
+ * Encode `image` as snapshot bytes: a header line naming the format and the
247
+ * SHA-256 digest of the body, then the body as JSON. Components, tables, rows
248
+ * and jobs are sorted, and every document keeps its own field order, so the
249
+ * same state always encodes to the same bytes.
250
+ */
251
+ export declare const encode: (image: Image, redact?: Redact) => Uint8Array;
252
+ /**
253
+ * Check the decoded body before any map is built from it, so its order cannot
254
+ * change the result: components, tables, rows and jobs each appear once, and
255
+ * every document carries the system fields the kernel writes.
256
+ */
257
+ export declare const checkBody: (body: Body) => Result.Result<void, KernelRefusal.SnapshotMalformed | KernelRefusal.SnapshotRowInconsistent | KernelRefusal.SnapshotJobInconsistent>;
258
+ /**
259
+ * Why a decoded snapshot is not state the kernel could have reached.
260
+ */
261
+ export type Inconsistency = KernelRefusal.SnapshotAllocatorBehind | KernelRefusal.SnapshotRowInconsistent | KernelRefusal.SnapshotTimestampInconsistent | KernelRefusal.SnapshotJobInconsistent;
262
+ /**
263
+ * Rows match the write log: replaying every commit from the empty world, each
264
+ * change replacing the value the log last published, gives exactly the
265
+ * snapshot's rows, each at the version that last wrote it, in a registered
266
+ * component and under its ID's table.
267
+ */
268
+ export declare const checkRows: (image: Image) => Result.Result<void, KernelRefusal.SnapshotRowInconsistent>;
269
+ /**
270
+ * Identity counters run ahead of every identity the state holds: the next
271
+ * document ID past every ID's counter, the latest creation time at or past
272
+ * every document's, a positive next attempt ID and a non-negative epoch.
273
+ */
274
+ export declare const checkAllocators: (image: Image) => Result.Result<void, KernelRefusal.SnapshotAllocatorBehind>;
275
+ /**
276
+ * Commit timestamps strictly increase through the write log, and the latest
277
+ * commit timestamp is the log's last, or zero before any commit.
278
+ */
279
+ export declare const checkTimestamps: (image: Image) => Result.Result<void, KernelRefusal.SnapshotTimestampInconsistent>;
280
+ /**
281
+ * Every job names a committed job row and a registered component, every job row
282
+ * has its job, and no job is left running: a snapshot is never taken while a
283
+ * job runs.
284
+ */
285
+ export declare const checkJobs: (image: Image, table: string) => Result.Result<void, KernelRefusal.SnapshotJobInconsistent>;
286
+ /**
287
+ * Check a decoded image against every rule the kernel's own exports keep,
288
+ * before any of it is installed.
289
+ */
290
+ export declare const check: (image: Image, jobTable: string) => Result.Result<void, Inconsistency>;
291
+ /**
292
+ * Read snapshot bytes back into the state they encode. Bytes whose body no
293
+ * longer hashes to their header's digest refuse with `SnapshotDigestMismatch`
294
+ * before any of the body is read.
295
+ */
296
+ export declare const decode: (bytes: Uint8Array, unredact?: Unredact) => Result.Result<Image, KernelRefusal.SnapshotMalformed | KernelRefusal.SnapshotDigestMismatch | KernelRefusal.SnapshotSecretMissing | KernelRefusal.SnapshotRowInconsistent | KernelRefusal.SnapshotJobInconsistent>;
297
+ export {};
298
+ //# sourceMappingURL=Snapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Snapshot.d.ts","sourceRoot":"","sources":["../../src/internal/Snapshot.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,SAAS,EAEf,MAAM,eAAe,CAAC;AACvB,OA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