@baukit/data-contracts 0.7.2 → 0.7.4

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.
@@ -0,0 +1,1214 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { type JsonValue, type KeyValueStore, StorageError } from './contracts.js';
4
+ import {
5
+ type DraftCodec,
6
+ type DraftDecodeResult,
7
+ type DurableDraft,
8
+ type DurableDraftSnapshot,
9
+ DraftPersistenceError,
10
+ createDurableDraft,
11
+ } from './durable-draft.js';
12
+ import { InMemoryKeyValueStore } from './memory.js';
13
+
14
+ interface Deferred {
15
+ readonly promise: Promise<void>;
16
+ resolve(): void;
17
+ }
18
+
19
+ function deferred(): Deferred {
20
+ let resolve!: () => void;
21
+ const promise = new Promise<void>((onResolve) => {
22
+ resolve = onResolve;
23
+ });
24
+ return { promise, resolve };
25
+ }
26
+
27
+ type Operation = 'get' | 'set' | 'delete';
28
+
29
+ /** An in-memory store whose operations can be held open or made to fail. */
30
+ class ControlledStore implements KeyValueStore {
31
+ readonly inner = new InMemoryKeyValueStore();
32
+ readonly calls: { readonly operation: Operation; readonly key: string }[] = [];
33
+ readonly #gates = new Map<Operation, Deferred[]>();
34
+ readonly #failures = new Map<Operation, Error[]>();
35
+
36
+ hold(operation: Operation): Deferred {
37
+ const gate = deferred();
38
+ const gates = this.#gates.get(operation) ?? [];
39
+ gates.push(gate);
40
+ this.#gates.set(operation, gates);
41
+ return gate;
42
+ }
43
+
44
+ failNext(operation: Operation, error: Error): void {
45
+ const failures = this.#failures.get(operation) ?? [];
46
+ failures.push(error);
47
+ this.#failures.set(operation, failures);
48
+ }
49
+
50
+ async get(key: string): Promise<JsonValue | undefined> {
51
+ await this.#enter('get', key);
52
+ return this.inner.get(key);
53
+ }
54
+
55
+ async set(key: string, value: JsonValue): Promise<void> {
56
+ await this.#enter('set', key);
57
+ await this.inner.set(key, value);
58
+ }
59
+
60
+ async delete(key: string): Promise<void> {
61
+ await this.#enter('delete', key);
62
+ await this.inner.delete(key);
63
+ }
64
+
65
+ clear(): Promise<void> {
66
+ return this.inner.clear();
67
+ }
68
+
69
+ clearPrefix(prefix: string): Promise<void> {
70
+ return this.inner.clearPrefix(prefix);
71
+ }
72
+
73
+ async #enter(operation: Operation, key: string): Promise<void> {
74
+ this.calls.push({ operation, key });
75
+ const gate = this.#gates.get(operation)?.shift();
76
+ if (gate !== undefined) {
77
+ await gate.promise;
78
+ }
79
+ const failure = this.#failures.get(operation)?.shift();
80
+ if (failure !== undefined) {
81
+ throw failure;
82
+ }
83
+ }
84
+ }
85
+
86
+ interface Scope {
87
+ readonly account: string;
88
+ readonly document: string;
89
+ }
90
+
91
+ interface FormValue {
92
+ readonly title: string;
93
+ readonly tags: readonly string[];
94
+ }
95
+
96
+ const EMPTY: FormValue = { title: '', tags: [] };
97
+ const accountA: Scope = { account: 'account-a', document: 'note-1' };
98
+ const accountB: Scope = { account: 'account-b', document: 'note-1' };
99
+ const otherDocument: Scope = { account: 'account-a', document: 'note-2' };
100
+
101
+ function isRecord(value: JsonValue): value is Record<string, JsonValue> {
102
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
103
+ }
104
+
105
+ function isStringArray(value: JsonValue | undefined): value is string[] {
106
+ return Array.isArray(value) && value.every((item) => typeof item === 'string');
107
+ }
108
+
109
+ function decodeFormValue(value: JsonValue): DraftDecodeResult<FormValue> {
110
+ if (!isRecord(value) || typeof value['title'] !== 'string' || !isStringArray(value['tags'])) {
111
+ return { kind: 'corrupt' };
112
+ }
113
+ return { kind: 'decoded', value: { title: value['title'], tags: value['tags'] } };
114
+ }
115
+
116
+ /** Version 1 stored a single `tag`; version 2 stores `tags`. */
117
+ const codecV2: DraftCodec<FormValue> = {
118
+ version: 2,
119
+ encode: (value) => ({ title: value.title, tags: [...value.tags] }),
120
+ decode(value, version) {
121
+ if (version === 2) {
122
+ return decodeFormValue(value);
123
+ }
124
+ if (!isRecord(value) || typeof value['title'] !== 'string') {
125
+ return { kind: 'corrupt' };
126
+ }
127
+ const tag = value['tag'];
128
+ return {
129
+ kind: 'decoded',
130
+ value: { title: value['title'], tags: typeof tag === 'string' ? [tag] : [] },
131
+ };
132
+ },
133
+ };
134
+
135
+ const codecV1: DraftCodec<FormValue> = {
136
+ version: 1,
137
+ encode: (value) => ({ title: value.title, tags: [...value.tags] }),
138
+ decode: (value) => decodeFormValue(value),
139
+ };
140
+
141
+ function draftKey(scope: Scope): string {
142
+ return `draft:${encodeURIComponent(scope.account)}:${encodeURIComponent(scope.document)}`;
143
+ }
144
+
145
+ function createDraft(
146
+ store: KeyValueStore,
147
+ codec: DraftCodec<FormValue> = codecV2,
148
+ ): DurableDraft<Scope, FormValue> {
149
+ return createDurableDraft({ store, key: draftKey, codec });
150
+ }
151
+
152
+ type OpenSnapshot = Extract<DurableDraftSnapshot<Scope, FormValue>, { readonly open: true }>;
153
+
154
+ function openSnapshot(draft: DurableDraft<Scope, FormValue>): OpenSnapshot {
155
+ const snapshot = draft.getSnapshot();
156
+ if (!snapshot.open) {
157
+ throw new Error('Draft is closed.');
158
+ }
159
+ return snapshot;
160
+ }
161
+
162
+ async function settle(): Promise<void> {
163
+ for (let turn = 0; turn < 10; turn += 1) {
164
+ await Promise.resolve();
165
+ }
166
+ }
167
+
168
+ describe('durable draft', () => {
169
+ describe('opening', () => {
170
+ it('starts closed', () => {
171
+ const draft = createDraft(new ControlledStore());
172
+ expect(draft.getSnapshot()).toEqual({ open: false });
173
+ });
174
+
175
+ it('reports an empty draft with the initial value when nothing is stored', async () => {
176
+ const draft = createDraft(new ControlledStore());
177
+
178
+ await draft.open(accountA, EMPTY);
179
+
180
+ expect(openSnapshot(draft)).toMatchObject({
181
+ scope: accountA,
182
+ value: EMPTY,
183
+ recovery: 'none',
184
+ persistence: 'idle',
185
+ dirty: false,
186
+ error: null,
187
+ submission: 'none',
188
+ });
189
+ });
190
+
191
+ it('restores a stored draft of the current version', async () => {
192
+ const store = new ControlledStore();
193
+ await store.inner.set(draftKey(accountA), { version: 2, value: { title: 'Kept', tags: [] } });
194
+ const draft = createDraft(store);
195
+
196
+ const opened = draft.open(accountA, EMPTY);
197
+ expect(openSnapshot(draft).persistence).toBe('loading');
198
+ await opened;
199
+
200
+ expect(openSnapshot(draft)).toMatchObject({
201
+ value: { title: 'Kept', tags: [] },
202
+ recovery: 'restored',
203
+ persistence: 'idle',
204
+ dirty: false,
205
+ });
206
+ });
207
+
208
+ it('reads the existing version 1 envelope written as { version, value }', async () => {
209
+ const store = new ControlledStore();
210
+ await store.inner.set(draftKey(accountA), {
211
+ version: 1,
212
+ value: { title: 'Legacy', tags: ['a'] },
213
+ });
214
+ const draft = createDraft(store, codecV1);
215
+
216
+ await draft.open(accountA, EMPTY);
217
+
218
+ expect(openSnapshot(draft)).toMatchObject({
219
+ value: { title: 'Legacy', tags: ['a'] },
220
+ recovery: 'restored',
221
+ dirty: false,
222
+ });
223
+ });
224
+
225
+ it('keeps an edit made while the stored draft was loading', async () => {
226
+ const store = new ControlledStore();
227
+ await store.inner.set(draftKey(accountA), { version: 2, value: { title: 'Old', tags: [] } });
228
+ const gate = store.hold('get');
229
+ const draft = createDraft(store);
230
+
231
+ const opened = draft.open(accountA, EMPTY);
232
+ draft.update({ title: 'Typed', tags: [] });
233
+ gate.resolve();
234
+ await opened;
235
+
236
+ expect(openSnapshot(draft)).toMatchObject({
237
+ value: { title: 'Typed', tags: [] },
238
+ recovery: 'none',
239
+ dirty: true,
240
+ });
241
+ });
242
+ });
243
+
244
+ describe('corrupt drafts', () => {
245
+ const corruptEnvelopes: readonly (readonly [string, JsonValue])[] = [
246
+ ['a bare string', 'not a draft'],
247
+ ['an array', [1, 2]],
248
+ ['a missing value', { version: 2 }],
249
+ ['a non-integer version', { version: 1.5, value: {} }],
250
+ ['a zero version', { version: 0, value: {} }],
251
+ ['a string version', { version: '2', value: {} }],
252
+ ['a value the codec rejects', { version: 2, value: { title: 7 } }],
253
+ ];
254
+
255
+ it.each(corruptEnvelopes)(
256
+ 'reports %s as corrupt without touching storage',
257
+ async (_, stored) => {
258
+ const store = new ControlledStore();
259
+ await store.inner.set(draftKey(accountA), stored);
260
+ const draft = createDraft(store);
261
+
262
+ await draft.open(accountA, EMPTY);
263
+
264
+ expect(openSnapshot(draft)).toMatchObject({
265
+ value: EMPTY,
266
+ recovery: 'corrupt',
267
+ persistence: 'idle',
268
+ error: null,
269
+ });
270
+ expect(store.calls.map((call) => call.operation)).toEqual(['get']);
271
+ await expect(store.inner.get(draftKey(accountA))).resolves.toEqual(stored);
272
+ },
273
+ );
274
+
275
+ it('reports a throwing decoder as corrupt', async () => {
276
+ const store = new ControlledStore();
277
+ await store.inner.set(draftKey(accountA), { version: 2, value: {} });
278
+ const draft = createDurableDraft<Scope, FormValue>({
279
+ store,
280
+ key: draftKey,
281
+ codec: {
282
+ version: 2,
283
+ encode: (value) => codecV2.encode(value),
284
+ decode: () => {
285
+ throw new Error('secret decoder text');
286
+ },
287
+ },
288
+ });
289
+
290
+ await draft.open(accountA, EMPTY);
291
+
292
+ expect(openSnapshot(draft)).toMatchObject({ recovery: 'corrupt', error: null });
293
+ });
294
+
295
+ it('blocks saves until the product discards the corrupt draft', async () => {
296
+ const store = new ControlledStore();
297
+ await store.inner.set(draftKey(accountA), 'garbage');
298
+ const draft = createDraft(store);
299
+ await draft.open(accountA, EMPTY);
300
+
301
+ draft.update({ title: 'New', tags: [] });
302
+ await expect(draft.save()).resolves.toBe('blocked');
303
+ await expect(store.inner.get(draftKey(accountA))).resolves.toBe('garbage');
304
+
305
+ await expect(draft.clear({ reason: 'discarded' })).resolves.toBe('cleared');
306
+ expect(openSnapshot(draft)).toMatchObject({ recovery: 'none', value: EMPTY, dirty: false });
307
+
308
+ draft.update({ title: 'New', tags: [] });
309
+ await expect(draft.save()).resolves.toBe('saved');
310
+ await expect(store.inner.get(draftKey(accountA))).resolves.toEqual({
311
+ version: 2,
312
+ value: { title: 'New', tags: [] },
313
+ });
314
+ });
315
+ });
316
+
317
+ describe('codec versions', () => {
318
+ it('upgrades an older version and marks it dirty for the next save', async () => {
319
+ const store = new ControlledStore();
320
+ await store.inner.set(draftKey(accountA), { version: 1, value: { title: 'Old', tag: 'x' } });
321
+ const draft = createDraft(store);
322
+
323
+ await draft.open(accountA, EMPTY);
324
+
325
+ expect(openSnapshot(draft)).toMatchObject({
326
+ value: { title: 'Old', tags: ['x'] },
327
+ recovery: 'restored',
328
+ dirty: true,
329
+ });
330
+ expect(store.calls.map((call) => call.operation)).toEqual(['get']);
331
+
332
+ await expect(draft.save()).resolves.toBe('saved');
333
+ await expect(store.inner.get(draftKey(accountA))).resolves.toEqual({
334
+ version: 2,
335
+ value: { title: 'Old', tags: ['x'] },
336
+ });
337
+ expect(openSnapshot(draft).dirty).toBe(false);
338
+ });
339
+
340
+ it('reports a newer version as unsupported without decoding, writing, or deleting', async () => {
341
+ const store = new ControlledStore();
342
+ const stored = { version: 3, value: { title: 'Future' } };
343
+ await store.inner.set(draftKey(accountA), stored);
344
+ let decodeCalls = 0;
345
+ const draft = createDurableDraft<Scope, FormValue>({
346
+ store,
347
+ key: draftKey,
348
+ codec: {
349
+ ...codecV2,
350
+ decode: (value, version) => {
351
+ decodeCalls += 1;
352
+ return codecV2.decode(value, version);
353
+ },
354
+ },
355
+ });
356
+
357
+ await draft.open(accountA, EMPTY);
358
+ draft.update({ title: 'Mine', tags: [] });
359
+ await expect(draft.save()).resolves.toBe('blocked');
360
+
361
+ expect(decodeCalls).toBe(0);
362
+ expect(openSnapshot(draft)).toMatchObject({
363
+ recovery: 'unsupported-version',
364
+ value: { title: 'Mine', tags: [] },
365
+ dirty: true,
366
+ });
367
+ expect(store.calls.map((call) => call.operation)).toEqual(['get']);
368
+ await expect(store.inner.get(draftKey(accountA))).resolves.toEqual(stored);
369
+ });
370
+
371
+ it('lets the codec refuse an older version it no longer reads', async () => {
372
+ const store = new ControlledStore();
373
+ await store.inner.set(draftKey(accountA), { version: 1, value: {} });
374
+ const draft = createDurableDraft<Scope, FormValue>({
375
+ store,
376
+ key: draftKey,
377
+ codec: {
378
+ ...codecV2,
379
+ decode: (value, version) =>
380
+ version === 2 ? codecV2.decode(value, version) : { kind: 'unsupported-version' },
381
+ },
382
+ });
383
+
384
+ await draft.open(accountA, EMPTY);
385
+
386
+ expect(openSnapshot(draft).recovery).toBe('unsupported-version');
387
+ });
388
+ });
389
+
390
+ describe('saving', () => {
391
+ it('moves from dirty to saving to clean', async () => {
392
+ const store = new ControlledStore();
393
+ const draft = createDraft(store);
394
+ await draft.open(accountA, EMPTY);
395
+
396
+ draft.update({ title: 'A', tags: [] });
397
+ expect(openSnapshot(draft)).toMatchObject({ dirty: true, persistence: 'idle' });
398
+ const gate = store.hold('set');
399
+ const saved = draft.save();
400
+ await settle();
401
+ expect(openSnapshot(draft).persistence).toBe('saving');
402
+ gate.resolve();
403
+
404
+ await expect(saved).resolves.toBe('saved');
405
+ expect(openSnapshot(draft)).toMatchObject({ dirty: false, persistence: 'idle' });
406
+ });
407
+
408
+ it('keeps an edit made during a save dirty', async () => {
409
+ const store = new ControlledStore();
410
+ const draft = createDraft(store);
411
+ await draft.open(accountA, EMPTY);
412
+
413
+ draft.update({ title: 'A', tags: [] });
414
+ const gate = store.hold('set');
415
+ const saved = draft.save();
416
+ await settle();
417
+ draft.update({ title: 'AB', tags: [] });
418
+ gate.resolve();
419
+ await saved;
420
+
421
+ expect(openSnapshot(draft)).toMatchObject({ value: { title: 'AB', tags: [] }, dirty: true });
422
+ await expect(store.inner.get(draftKey(accountA))).resolves.toEqual({
423
+ version: 2,
424
+ value: { title: 'A', tags: [] },
425
+ });
426
+ });
427
+
428
+ it('writes only the newest value when saves queue up', async () => {
429
+ const store = new ControlledStore();
430
+ const draft = createDraft(store);
431
+ await draft.open(accountA, EMPTY);
432
+
433
+ draft.update({ title: 'A', tags: [] });
434
+ const gate = store.hold('set');
435
+ const first = draft.save();
436
+ await settle();
437
+ draft.update({ title: 'AB', tags: [] });
438
+ const second = draft.save();
439
+ draft.update({ title: 'ABC', tags: [] });
440
+ const third = draft.save();
441
+ gate.resolve();
442
+
443
+ await expect(Promise.all([first, second, third])).resolves.toEqual([
444
+ 'saved',
445
+ 'saved',
446
+ 'clean',
447
+ ]);
448
+ expect(store.calls.filter((call) => call.operation === 'set')).toHaveLength(2);
449
+ await expect(store.inner.get(draftKey(accountA))).resolves.toEqual({
450
+ version: 2,
451
+ value: { title: 'ABC', tags: [] },
452
+ });
453
+ });
454
+
455
+ it('resolves clean when nothing changed', async () => {
456
+ const store = new ControlledStore();
457
+ const draft = createDraft(store);
458
+ await draft.open(accountA, EMPTY);
459
+
460
+ await expect(draft.save()).resolves.toBe('clean');
461
+ expect(store.calls.map((call) => call.operation)).toEqual(['get']);
462
+ });
463
+ });
464
+
465
+ describe('persistence failure', () => {
466
+ it('reports a failed write with a safe typed error and keeps the value dirty', async () => {
467
+ const store = new ControlledStore();
468
+ const draft = createDraft(store);
469
+ await draft.open(accountA, EMPTY);
470
+ const cause = new Error('disk full: secret-title');
471
+ store.failNext('set', cause);
472
+
473
+ draft.update({ title: 'secret-title', tags: [] });
474
+ const error = await draft.save().catch((failure: unknown) => failure);
475
+
476
+ expect(error).toBeInstanceOf(DraftPersistenceError);
477
+ expect(error).toMatchObject({
478
+ code: 'draft_persistence_failed',
479
+ operation: 'write',
480
+ cause,
481
+ });
482
+ expect((error as Error).message).not.toContain('secret-title');
483
+ expect((error as Error).message).not.toContain('account-a');
484
+ expect(openSnapshot(draft)).toMatchObject({
485
+ persistence: 'failed',
486
+ dirty: true,
487
+ error,
488
+ value: { title: 'secret-title', tags: [] },
489
+ });
490
+
491
+ await expect(draft.save()).resolves.toBe('saved');
492
+ expect(openSnapshot(draft)).toMatchObject({ persistence: 'idle', dirty: false, error: null });
493
+ });
494
+
495
+ it('normalizes quota failures in the cause', async () => {
496
+ const store = new ControlledStore();
497
+ const draft = createDraft(store);
498
+ await draft.open(accountA, EMPTY);
499
+ store.failNext('set', Object.assign(new Error('quota'), { name: 'QuotaExceededError' }));
500
+
501
+ draft.update({ title: 'A', tags: [] });
502
+ const error = await draft.save().catch((failure: unknown) => failure);
503
+
504
+ expect((error as DraftPersistenceError).cause).toBeInstanceOf(StorageError);
505
+ expect((error as DraftPersistenceError).cause).toMatchObject({
506
+ code: 'storage_quota_exceeded',
507
+ });
508
+ });
509
+
510
+ it('reports a failed read as unavailable and still accepts edits', async () => {
511
+ const store = new ControlledStore();
512
+ store.failNext('get', new Error('blocked storage'));
513
+ const draft = createDraft(store);
514
+
515
+ await draft.open(accountA, EMPTY);
516
+
517
+ expect(openSnapshot(draft)).toMatchObject({
518
+ recovery: 'unavailable',
519
+ persistence: 'failed',
520
+ value: EMPTY,
521
+ });
522
+ expect(openSnapshot(draft).error).toMatchObject({ operation: 'read' });
523
+
524
+ draft.update({ title: 'A', tags: [] });
525
+ await expect(draft.save()).resolves.toBe('saved');
526
+ expect(openSnapshot(draft)).toMatchObject({ persistence: 'idle', error: null });
527
+ });
528
+
529
+ it('reports an encoder failure as a failed write', async () => {
530
+ const store = new ControlledStore();
531
+ const draft = createDurableDraft<Scope, FormValue>({
532
+ store,
533
+ key: draftKey,
534
+ codec: {
535
+ ...codecV2,
536
+ encode: () => {
537
+ throw new Error('cannot encode');
538
+ },
539
+ },
540
+ });
541
+ await draft.open(accountA, EMPTY);
542
+
543
+ draft.update({ title: 'A', tags: [] });
544
+
545
+ await expect(draft.save()).rejects.toMatchObject({ operation: 'write' });
546
+ expect(store.calls.map((call) => call.operation)).toEqual(['get']);
547
+ });
548
+ });
549
+
550
+ describe('clearing', () => {
551
+ it('clears after a confirmed submission and keeps the value visible', async () => {
552
+ const store = new ControlledStore();
553
+ const draft = createDraft(store);
554
+ await draft.open(accountA, EMPTY);
555
+ draft.update({ title: 'Sent', tags: [] });
556
+ await draft.save();
557
+
558
+ const { localRevision } = openSnapshot(draft);
559
+ await expect(draft.clear({ reason: 'submitted', localRevision })).resolves.toBe('cleared');
560
+
561
+ expect(openSnapshot(draft)).toMatchObject({
562
+ value: { title: 'Sent', tags: [] },
563
+ dirty: false,
564
+ persistence: 'idle',
565
+ submission: 'confirmed',
566
+ });
567
+ await expect(store.inner.get(draftKey(accountA))).resolves.toBeUndefined();
568
+ });
569
+
570
+ it('keeps newer edits instead of clearing after a submission of an older value', async () => {
571
+ const store = new ControlledStore();
572
+ const draft = createDraft(store);
573
+ await draft.open(accountA, EMPTY);
574
+ draft.update({ title: 'Sent', tags: [] });
575
+ const { localRevision } = openSnapshot(draft);
576
+ draft.update({ title: 'Sent and more', tags: [] });
577
+ await draft.save();
578
+
579
+ await expect(draft.clear({ reason: 'submitted', localRevision })).resolves.toBe(
580
+ 'newer-edits-kept',
581
+ );
582
+
583
+ expect(store.calls.some((call) => call.operation === 'delete')).toBe(false);
584
+ await expect(store.inner.get(draftKey(accountA))).resolves.toEqual({
585
+ version: 2,
586
+ value: { title: 'Sent and more', tags: [] },
587
+ });
588
+ });
589
+
590
+ it('keeps an edit made while the delete runs dirty', async () => {
591
+ const store = new ControlledStore();
592
+ const draft = createDraft(store);
593
+ await draft.open(accountA, EMPTY);
594
+ draft.update({ title: 'Sent', tags: [] });
595
+ await draft.save();
596
+ const gate = store.hold('delete');
597
+
598
+ const cleared = draft.clear({
599
+ reason: 'submitted',
600
+ localRevision: openSnapshot(draft).localRevision,
601
+ });
602
+ await settle();
603
+ expect(openSnapshot(draft).persistence).toBe('clearing');
604
+ draft.update({ title: 'Follow-up', tags: [] });
605
+ gate.resolve();
606
+
607
+ await expect(cleared).resolves.toBe('cleared');
608
+ expect(openSnapshot(draft)).toMatchObject({
609
+ value: { title: 'Follow-up', tags: [] },
610
+ dirty: true,
611
+ });
612
+ });
613
+
614
+ it('keeps a failed delete visible after a confirmed submission', async () => {
615
+ const store = new ControlledStore();
616
+ const draft = createDraft(store);
617
+ await draft.open(accountA, EMPTY);
618
+ draft.update({ title: 'Sent', tags: [] });
619
+ await draft.save();
620
+ store.failNext('delete', new Error('locked'));
621
+
622
+ const localRevision = openSnapshot(draft).localRevision;
623
+ const error = await draft
624
+ .clear({ reason: 'submitted', localRevision })
625
+ .catch((failure: unknown) => failure);
626
+
627
+ expect(error).toBeInstanceOf(DraftPersistenceError);
628
+ expect(error).toMatchObject({ operation: 'delete' });
629
+ expect(openSnapshot(draft)).toMatchObject({
630
+ persistence: 'failed',
631
+ submission: 'confirmed',
632
+ error,
633
+ value: { title: 'Sent', tags: [] },
634
+ });
635
+ await expect(store.inner.get(draftKey(accountA))).resolves.toBeDefined();
636
+
637
+ await expect(draft.clear({ reason: 'submitted', localRevision })).resolves.toBe('cleared');
638
+ expect(openSnapshot(draft)).toMatchObject({ persistence: 'idle', error: null });
639
+ });
640
+
641
+ it('discards local edits and returns to the initial value', async () => {
642
+ const store = new ControlledStore();
643
+ const draft = createDraft(store);
644
+ await draft.open(accountA, EMPTY);
645
+ draft.update({ title: 'Unwanted', tags: [] });
646
+ await draft.save();
647
+
648
+ await expect(draft.clear({ reason: 'discarded' })).resolves.toBe('cleared');
649
+
650
+ expect(openSnapshot(draft)).toMatchObject({ value: EMPTY, dirty: false, recovery: 'none' });
651
+ await expect(store.inner.get(draftKey(accountA))).resolves.toBeUndefined();
652
+ });
653
+
654
+ it('keeps the local value when discarding fails', async () => {
655
+ const store = new ControlledStore();
656
+ const draft = createDraft(store);
657
+ await draft.open(accountA, EMPTY);
658
+ draft.update({ title: 'Unwanted', tags: [] });
659
+ store.failNext('delete', new Error('locked'));
660
+
661
+ await expect(draft.clear({ reason: 'discarded' })).rejects.toBeInstanceOf(
662
+ DraftPersistenceError,
663
+ );
664
+ expect(openSnapshot(draft)).toMatchObject({
665
+ value: { title: 'Unwanted', tags: [] },
666
+ persistence: 'failed',
667
+ submission: 'none',
668
+ });
669
+ });
670
+
671
+ it('waits for an in-flight write before deleting', async () => {
672
+ const store = new ControlledStore();
673
+ const draft = createDraft(store);
674
+ await draft.open(accountA, EMPTY);
675
+ draft.update({ title: 'A', tags: [] });
676
+ const gate = store.hold('set');
677
+
678
+ const saved = draft.save();
679
+ const cleared = draft.clear({ reason: 'discarded' });
680
+ await settle();
681
+ gate.resolve();
682
+ await Promise.all([saved, cleared]);
683
+
684
+ expect(store.calls.map((call) => call.operation)).toEqual(['get', 'set', 'delete']);
685
+ await expect(store.inner.get(draftKey(accountA))).resolves.toBeUndefined();
686
+ });
687
+ });
688
+
689
+ describe('account and document switching', () => {
690
+ it('ignores a late read from the previous account', async () => {
691
+ const store = new ControlledStore();
692
+ await store.inner.set(draftKey(accountA), { version: 2, value: { title: 'A', tags: [] } });
693
+ await store.inner.set(draftKey(accountB), { version: 2, value: { title: 'B', tags: [] } });
694
+ const gate = store.hold('get');
695
+ const draft = createDraft(store);
696
+
697
+ const openA = draft.open(accountA, EMPTY);
698
+ const openB = draft.open(accountB, EMPTY);
699
+ gate.resolve();
700
+ await Promise.all([openA, openB]);
701
+
702
+ expect(openSnapshot(draft)).toMatchObject({
703
+ scope: accountB,
704
+ value: { title: 'B', tags: [] },
705
+ recovery: 'restored',
706
+ });
707
+ });
708
+
709
+ it('does not publish a late write from the previous document', async () => {
710
+ const store = new ControlledStore();
711
+ const draft = createDraft(store);
712
+ await draft.open(accountA, EMPTY);
713
+ draft.update({ title: 'A', tags: [] });
714
+ const gate = store.hold('set');
715
+ const saved = draft.save();
716
+ await settle();
717
+
718
+ const opened = draft.open(otherDocument, EMPTY);
719
+ gate.resolve();
720
+ await expect(saved).resolves.toBe('saved');
721
+ await opened;
722
+
723
+ expect(openSnapshot(draft)).toMatchObject({
724
+ scope: otherDocument,
725
+ value: EMPTY,
726
+ dirty: false,
727
+ persistence: 'idle',
728
+ });
729
+ await expect(store.inner.get(draftKey(accountA))).resolves.toEqual({
730
+ version: 2,
731
+ value: { title: 'A', tags: [] },
732
+ });
733
+ });
734
+
735
+ it('does not publish a late write failure from the previous account', async () => {
736
+ const store = new ControlledStore();
737
+ const draft = createDraft(store);
738
+ await draft.open(accountA, EMPTY);
739
+ draft.update({ title: 'A', tags: [] });
740
+ store.failNext('set', new Error('offline'));
741
+ const gate = store.hold('set');
742
+ const saved = draft.save();
743
+ await settle();
744
+
745
+ const opened = draft.open(accountB, EMPTY);
746
+ gate.resolve();
747
+ await expect(saved).rejects.toBeInstanceOf(DraftPersistenceError);
748
+ await opened;
749
+
750
+ expect(openSnapshot(draft)).toMatchObject({
751
+ scope: accountB,
752
+ persistence: 'idle',
753
+ error: null,
754
+ });
755
+ });
756
+
757
+ it('skips queued work of the previous scope that had not started', async () => {
758
+ const store = new ControlledStore();
759
+ const draft = createDraft(store);
760
+ const gate = store.hold('get');
761
+ const openA = draft.open(accountA, EMPTY);
762
+ await settle();
763
+ draft.update({ title: 'A', tags: [] });
764
+ const saved = draft.save();
765
+ const cleared = draft.clear({ reason: 'discarded' });
766
+
767
+ const openB = draft.open(accountB, EMPTY);
768
+ gate.resolve();
769
+ await Promise.all([openA, openB]);
770
+
771
+ await expect(saved).resolves.toBe('stale');
772
+ await expect(cleared).resolves.toBe('stale');
773
+ expect(store.calls.map((call) => call.operation)).toEqual(['get', 'get']);
774
+ });
775
+
776
+ it('sees the settled write of the first A session when switching A to B to A', async () => {
777
+ const store = new ControlledStore();
778
+ const draft = createDraft(store);
779
+ await draft.open(accountA, EMPTY);
780
+ draft.update({ title: 'first-a', tags: [] });
781
+ const writeGate = store.hold('set');
782
+ const saved = draft.save();
783
+ await settle();
784
+
785
+ const openB = draft.open(accountB, EMPTY);
786
+ const openA = draft.open(accountA, EMPTY);
787
+ writeGate.resolve();
788
+ await Promise.all([saved, openB, openA]);
789
+
790
+ expect(openSnapshot(draft)).toMatchObject({
791
+ scope: accountA,
792
+ value: { title: 'first-a', tags: [] },
793
+ recovery: 'restored',
794
+ });
795
+ });
796
+
797
+ it('does not let a late delete from the first A session clear the second', async () => {
798
+ const store = new ControlledStore();
799
+ const draft = createDraft(store);
800
+ await draft.open(accountA, EMPTY);
801
+ draft.update({ title: 'first-a', tags: [] });
802
+ await draft.save();
803
+ const deleteGate = store.hold('delete');
804
+ const cleared = draft.clear({ reason: 'discarded' });
805
+ await settle();
806
+
807
+ const openB = draft.open(accountB, EMPTY);
808
+ const openA = draft.open(accountA, { title: 'initial-a', tags: [] });
809
+ deleteGate.resolve();
810
+ await expect(cleared).resolves.toBe('cleared');
811
+ await Promise.all([openB, openA]);
812
+
813
+ expect(openSnapshot(draft)).toMatchObject({
814
+ scope: accountA,
815
+ value: { title: 'initial-a', tags: [] },
816
+ recovery: 'none',
817
+ persistence: 'idle',
818
+ });
819
+ });
820
+
821
+ it('never writes one account value under another account key', async () => {
822
+ const store = new ControlledStore();
823
+ const draft = createDraft(store);
824
+ await draft.open(accountA, EMPTY);
825
+ draft.update({ title: 'A only', tags: [] });
826
+ await draft.open(accountB, EMPTY);
827
+
828
+ await expect(draft.save()).resolves.toBe('clean');
829
+ await expect(store.inner.get(draftKey(accountB))).resolves.toBeUndefined();
830
+ });
831
+ });
832
+
833
+ describe('moving', () => {
834
+ const newNote: Scope = { account: 'account-a', document: 'new' };
835
+ const createdNote: Scope = { account: 'account-a', document: 'note-9' };
836
+
837
+ function operations(store: ControlledStore): string[] {
838
+ return store.calls.map((call) => `${call.operation} ${call.key}`);
839
+ }
840
+
841
+ it('writes a dirty value under the new key and deletes the old one', async () => {
842
+ const store = new ControlledStore();
843
+ const draft = createDraft(store);
844
+ await draft.open(newNote, EMPTY);
845
+ draft.update({ title: 'Draft', tags: [] });
846
+ const { localRevision } = openSnapshot(draft);
847
+
848
+ await expect(draft.move(createdNote)).resolves.toBe('moved');
849
+
850
+ expect(openSnapshot(draft)).toMatchObject({
851
+ scope: createdNote,
852
+ value: { title: 'Draft', tags: [] },
853
+ localRevision,
854
+ dirty: false,
855
+ persistence: 'idle',
856
+ });
857
+ expect(operations(store)).toEqual([
858
+ `get ${draftKey(newNote)}`,
859
+ `set ${draftKey(createdNote)}`,
860
+ `delete ${draftKey(newNote)}`,
861
+ ]);
862
+ await expect(store.inner.get(draftKey(createdNote))).resolves.toEqual({
863
+ version: 2,
864
+ value: { title: 'Draft', tags: [] },
865
+ });
866
+ });
867
+
868
+ it('carries a restored draft that has no local edits', async () => {
869
+ const store = new ControlledStore();
870
+ await store.inner.set(draftKey(newNote), { version: 2, value: { title: 'Kept', tags: [] } });
871
+ const draft = createDraft(store);
872
+ await draft.open(newNote, EMPTY);
873
+
874
+ await expect(draft.move(createdNote)).resolves.toBe('moved');
875
+
876
+ expect(openSnapshot(draft)).toMatchObject({ recovery: 'restored', dirty: false });
877
+ await expect(store.inner.get(draftKey(newNote))).resolves.toBeUndefined();
878
+ await expect(store.inner.get(draftKey(createdNote))).resolves.toEqual({
879
+ version: 2,
880
+ value: { title: 'Kept', tags: [] },
881
+ });
882
+ });
883
+
884
+ it('writes nothing new after a submitted clear', async () => {
885
+ const store = new ControlledStore();
886
+ const draft = createDraft(store);
887
+ await draft.open(newNote, EMPTY);
888
+ draft.update({ title: 'Sent', tags: [] });
889
+ await draft.save();
890
+ await draft.clear({ reason: 'submitted', localRevision: openSnapshot(draft).localRevision });
891
+
892
+ await expect(draft.move(createdNote)).resolves.toBe('moved');
893
+
894
+ expect(openSnapshot(draft)).toMatchObject({
895
+ scope: createdNote,
896
+ value: { title: 'Sent', tags: [] },
897
+ dirty: false,
898
+ submission: 'confirmed',
899
+ });
900
+ expect(operations(store).slice(3)).toEqual([`delete ${draftKey(newNote)}`]);
901
+ await expect(store.inner.get(draftKey(createdNote))).resolves.toBeUndefined();
902
+ });
903
+
904
+ it('keeps an edit made during the move dirty and saves it under the new key', async () => {
905
+ const store = new ControlledStore();
906
+ const draft = createDraft(store);
907
+ await draft.open(newNote, EMPTY);
908
+ draft.update({ title: 'First', tags: [] });
909
+ const gate = store.hold('set');
910
+
911
+ const moved = draft.move(createdNote);
912
+ await settle();
913
+ expect(openSnapshot(draft).persistence).toBe('saving');
914
+ draft.update({ title: 'Second', tags: [] });
915
+ gate.resolve();
916
+ await expect(moved).resolves.toBe('moved');
917
+
918
+ expect(openSnapshot(draft)).toMatchObject({ scope: createdNote, dirty: true });
919
+ await expect(draft.save()).resolves.toBe('saved');
920
+ await expect(store.inner.get(draftKey(createdNote))).resolves.toEqual({
921
+ version: 2,
922
+ value: { title: 'Second', tags: [] },
923
+ });
924
+ await expect(store.inner.get(draftKey(newNote))).resolves.toBeUndefined();
925
+ });
926
+
927
+ it('sends a save queued behind the move to the new key', async () => {
928
+ const store = new ControlledStore();
929
+ const draft = createDraft(store);
930
+ await draft.open(newNote, EMPTY);
931
+ draft.update({ title: 'First', tags: [] });
932
+
933
+ const gate = store.hold('delete');
934
+ const moved = draft.move(createdNote);
935
+ await settle();
936
+ draft.update({ title: 'Second', tags: [] });
937
+ const saved = draft.save();
938
+ gate.resolve();
939
+
940
+ await expect(moved).resolves.toBe('moved');
941
+ await expect(saved).resolves.toBe('saved');
942
+ expect(operations(store).slice(1)).toEqual([
943
+ `set ${draftKey(createdNote)}`,
944
+ `delete ${draftKey(newNote)}`,
945
+ `set ${draftKey(createdNote)}`,
946
+ ]);
947
+ await expect(store.inner.get(draftKey(createdNote))).resolves.toEqual({
948
+ version: 2,
949
+ value: { title: 'Second', tags: [] },
950
+ });
951
+ });
952
+
953
+ it('stays on the old scope when the write fails and can retry', async () => {
954
+ const store = new ControlledStore();
955
+ const draft = createDraft(store);
956
+ await draft.open(newNote, EMPTY);
957
+ draft.update({ title: 'Draft', tags: [] });
958
+ await draft.save();
959
+ store.failNext('set', new Error('offline'));
960
+
961
+ const error = await draft.move(createdNote).catch((failure: unknown) => failure);
962
+
963
+ expect(error).toBeInstanceOf(DraftPersistenceError);
964
+ expect(error).toMatchObject({ operation: 'write' });
965
+ expect(openSnapshot(draft)).toMatchObject({ scope: newNote, persistence: 'failed', error });
966
+ await expect(store.inner.get(draftKey(newNote))).resolves.toBeDefined();
967
+
968
+ await expect(draft.move(createdNote)).resolves.toBe('moved');
969
+ expect(openSnapshot(draft)).toMatchObject({
970
+ scope: createdNote,
971
+ persistence: 'idle',
972
+ error: null,
973
+ });
974
+ });
975
+
976
+ it('stays on the old scope when the delete fails and can retry', async () => {
977
+ const store = new ControlledStore();
978
+ const draft = createDraft(store);
979
+ await draft.open(newNote, EMPTY);
980
+ draft.update({ title: 'Draft', tags: [] });
981
+ store.failNext('delete', new Error('locked'));
982
+
983
+ await expect(draft.move(createdNote)).rejects.toMatchObject({ operation: 'delete' });
984
+ expect(openSnapshot(draft)).toMatchObject({ scope: newNote, persistence: 'failed' });
985
+
986
+ await expect(draft.move(createdNote)).resolves.toBe('moved');
987
+ await expect(store.inner.get(draftKey(newNote))).resolves.toBeUndefined();
988
+ await expect(store.inner.get(draftKey(createdNote))).resolves.toBeDefined();
989
+ });
990
+
991
+ it('blocks a corrupt draft without touching storage', async () => {
992
+ const store = new ControlledStore();
993
+ await store.inner.set(draftKey(newNote), 'not an envelope');
994
+ const draft = createDraft(store);
995
+ await draft.open(newNote, EMPTY);
996
+
997
+ await expect(draft.move(createdNote)).resolves.toBe('blocked');
998
+
999
+ expect(openSnapshot(draft).scope).toEqual(newNote);
1000
+ expect(operations(store)).toEqual([`get ${draftKey(newNote)}`]);
1001
+ });
1002
+
1003
+ it('only changes the scope when both scopes share a key', async () => {
1004
+ const store = new ControlledStore();
1005
+ const draft = createDraft(store);
1006
+ await draft.open(newNote, EMPTY);
1007
+ draft.update({ title: 'Draft', tags: [] });
1008
+ const sameKey: Scope = { ...newNote };
1009
+
1010
+ await expect(draft.move(sameKey)).resolves.toBe('moved');
1011
+
1012
+ expect(openSnapshot(draft).scope).toBe(sameKey);
1013
+ expect(openSnapshot(draft).dirty).toBe(true);
1014
+ expect(operations(store)).toEqual([`get ${draftKey(newNote)}`]);
1015
+ });
1016
+
1017
+ it('resolves stale after the scope changed and rejects when the key encoder throws', async () => {
1018
+ const store = new ControlledStore();
1019
+ const draft = createDurableDraft<Scope, FormValue>({
1020
+ store,
1021
+ key: (scope) => {
1022
+ if (scope.document === '') {
1023
+ throw new Error('empty document');
1024
+ }
1025
+ return draftKey(scope);
1026
+ },
1027
+ codec: codecV2,
1028
+ });
1029
+ await draft.open(newNote, EMPTY);
1030
+
1031
+ await expect(draft.move({ account: 'account-a', document: '' })).rejects.toThrow(
1032
+ 'empty document',
1033
+ );
1034
+ expect(openSnapshot(draft).scope).toEqual(newNote);
1035
+
1036
+ const moved = draft.move(createdNote);
1037
+ const reopened = draft.open(accountB, EMPTY);
1038
+ await expect(moved).resolves.toBe('stale');
1039
+ await reopened;
1040
+ await draft.close();
1041
+ await expect(draft.move(createdNote)).resolves.toBe('stale');
1042
+ expect(store.calls.map((call) => call.operation)).toEqual(['get', 'get']);
1043
+ });
1044
+ });
1045
+
1046
+ describe('scope fencing', () => {
1047
+ it('resolves stale without writing or deleting while the scope is inactive', async () => {
1048
+ const store = new ControlledStore();
1049
+ let active = true;
1050
+ const draft = createDurableDraft<Scope, FormValue>({
1051
+ store,
1052
+ key: draftKey,
1053
+ codec: codecV2,
1054
+ isScopeActive: () => active,
1055
+ });
1056
+ await draft.open(accountA, EMPTY);
1057
+ draft.update({ title: 'A', tags: [] });
1058
+ active = false;
1059
+
1060
+ await expect(draft.save()).resolves.toBe('stale');
1061
+ await expect(draft.clear({ reason: 'discarded' })).resolves.toBe('stale');
1062
+ await expect(draft.move(otherDocument)).resolves.toBe('stale');
1063
+
1064
+ expect(store.calls.map((call) => call.operation)).toEqual(['get']);
1065
+ expect(openSnapshot(draft)).toMatchObject({
1066
+ scope: accountA,
1067
+ value: { title: 'A', tags: [] },
1068
+ dirty: true,
1069
+ });
1070
+
1071
+ active = true;
1072
+ await expect(draft.save()).resolves.toBe('saved');
1073
+ });
1074
+
1075
+ it('refuses a move into a scope that is not active', async () => {
1076
+ const store = new ControlledStore();
1077
+ const draft = createDurableDraft<Scope, FormValue>({
1078
+ store,
1079
+ key: draftKey,
1080
+ codec: codecV2,
1081
+ isScopeActive: (scope) => scope.document !== otherDocument.document,
1082
+ });
1083
+ await draft.open(accountA, EMPTY);
1084
+ draft.update({ title: 'A', tags: [] });
1085
+
1086
+ await expect(draft.move(otherDocument)).resolves.toBe('stale');
1087
+ expect(store.calls.map((call) => call.operation)).toEqual(['get']);
1088
+ });
1089
+
1090
+ it('checks the scope when queued work starts, not when it was requested', async () => {
1091
+ const store = new ControlledStore();
1092
+ let active = true;
1093
+ const draft = createDurableDraft<Scope, FormValue>({
1094
+ store,
1095
+ key: draftKey,
1096
+ codec: codecV2,
1097
+ isScopeActive: () => active,
1098
+ });
1099
+ const gate = store.hold('get');
1100
+ const opened = draft.open(accountA, EMPTY);
1101
+ await settle();
1102
+ draft.update({ title: 'A', tags: [] });
1103
+ const saved = draft.save();
1104
+ active = false;
1105
+ gate.resolve();
1106
+ await opened;
1107
+
1108
+ await expect(saved).resolves.toBe('stale');
1109
+ expect(store.calls.map((call) => call.operation)).toEqual(['get']);
1110
+ });
1111
+ });
1112
+
1113
+ describe('closing', () => {
1114
+ it('closes without flushing and ignores later calls', async () => {
1115
+ const store = new ControlledStore();
1116
+ const draft = createDraft(store);
1117
+ await draft.open(accountA, EMPTY);
1118
+ draft.update({ title: 'unsaved', tags: [] });
1119
+
1120
+ await draft.close();
1121
+ draft.update({ title: 'ignored', tags: [] });
1122
+
1123
+ expect(draft.getSnapshot()).toEqual({ open: false });
1124
+ await expect(draft.save()).resolves.toBe('stale');
1125
+ await expect(draft.clear({ reason: 'discarded' })).resolves.toBe('stale');
1126
+ expect(store.calls.map((call) => call.operation)).toEqual(['get']);
1127
+ });
1128
+
1129
+ it('waits for the in-flight write before resolving', async () => {
1130
+ const store = new ControlledStore();
1131
+ const draft = createDraft(store);
1132
+ await draft.open(accountA, EMPTY);
1133
+ draft.update({ title: 'A', tags: [] });
1134
+ const gate = store.hold('set');
1135
+ void draft.save();
1136
+ await settle();
1137
+
1138
+ let closed = false;
1139
+ const closing = draft.close().then(() => {
1140
+ closed = true;
1141
+ });
1142
+ await settle();
1143
+ expect(closed).toBe(false);
1144
+ gate.resolve();
1145
+ await closing;
1146
+
1147
+ expect(closed).toBe(true);
1148
+ expect(draft.getSnapshot()).toEqual({ open: false });
1149
+ });
1150
+ });
1151
+
1152
+ it('notifies subscribers and keeps the snapshot stable between changes', async () => {
1153
+ const draft = createDraft(new ControlledStore());
1154
+ let notifications = 0;
1155
+ const unsubscribe = draft.subscribe(() => {
1156
+ notifications += 1;
1157
+ });
1158
+
1159
+ await draft.open(accountA, EMPTY);
1160
+ const snapshot = draft.getSnapshot();
1161
+ const before = notifications;
1162
+ expect(draft.getSnapshot()).toBe(snapshot);
1163
+
1164
+ draft.update({ title: 'A', tags: [] });
1165
+ expect(notifications).toBe(before + 1);
1166
+
1167
+ unsubscribe();
1168
+ draft.update({ title: 'AB', tags: [] });
1169
+ expect(notifications).toBe(before + 1);
1170
+ });
1171
+ });
1172
+
1173
+ describe('durable draft configuration', () => {
1174
+ it('rejects a codec version that is not a positive integer', () => {
1175
+ for (const version of [0, -1, 1.5, Number.NaN]) {
1176
+ expect(() =>
1177
+ createDurableDraft<Scope, FormValue>({
1178
+ store: new ControlledStore(),
1179
+ key: draftKey,
1180
+ codec: { ...codecV2, version },
1181
+ }),
1182
+ ).toThrow(RangeError);
1183
+ }
1184
+ });
1185
+
1186
+ it('rejects open and keeps the current scope when the key encoder throws', async () => {
1187
+ const draft = createDurableDraft<Scope, FormValue>({
1188
+ store: new ControlledStore(),
1189
+ key: (scope) => {
1190
+ if (scope.account === '') {
1191
+ throw new Error('empty account');
1192
+ }
1193
+ return draftKey(scope);
1194
+ },
1195
+ codec: codecV2,
1196
+ });
1197
+ await draft.open(accountA, EMPTY);
1198
+
1199
+ await expect(draft.open({ account: '', document: 'x' }, EMPTY)).rejects.toThrow(
1200
+ 'empty account',
1201
+ );
1202
+ expect(openSnapshot(draft).scope).toEqual(accountA);
1203
+ });
1204
+ });
1205
+
1206
+ it('exports the draft helper from its own entry point only', async () => {
1207
+ const [root, entry] = await Promise.all([
1208
+ import('@baukit/data-contracts'),
1209
+ import('@baukit/data-contracts/durable-draft'),
1210
+ ]);
1211
+ expect(entry.createDurableDraft).toBeTypeOf('function');
1212
+ expect(entry.DraftPersistenceError).toBeTypeOf('function');
1213
+ expect(Object.keys(root)).not.toContain('createDurableDraft');
1214
+ });