@roc-db/test-utils 0.2.0-pre.98 → 0.2.0-pre.99
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/index.js +159 -102
- package/dist/types/entities/Draft.d.ts +1 -0
- package/dist/types/entities/index.d.ts +1 -0
- package/dist/types/operations/duplicateDraft.d.ts +10 -0
- package/dist/types/schemas/PostVersionRefSchema.d.ts +1 -0
- package/dist/types/setup/index.d.ts +11 -0
- package/package.json +7 -3
package/dist/index.js
CHANGED
|
@@ -66,12 +66,20 @@ import { z as z5 } from "zod";
|
|
|
66
66
|
// src/entities/Draft.ts
|
|
67
67
|
import { Entity } from "roc-db";
|
|
68
68
|
import { z as z4 } from "zod";
|
|
69
|
+
|
|
70
|
+
// src/schemas/PostVersionRefSchema.ts
|
|
71
|
+
import { refSchemaGenerator as refSchemaGenerator5 } from "roc-db";
|
|
72
|
+
var PostVersionRefSchema = refSchemaGenerator5("PostVersion");
|
|
73
|
+
|
|
74
|
+
// src/entities/Draft.ts
|
|
69
75
|
var Draft = new Entity("Draft", {
|
|
76
|
+
changeSet: true,
|
|
70
77
|
data: z4.object({
|
|
71
78
|
appliedAt: z4.string().optional()
|
|
72
79
|
}),
|
|
73
80
|
parents: z4.object({
|
|
74
|
-
post: PostRefSchema
|
|
81
|
+
post: PostRefSchema,
|
|
82
|
+
version: PostVersionRefSchema.optional()
|
|
75
83
|
})
|
|
76
84
|
});
|
|
77
85
|
|
|
@@ -91,8 +99,8 @@ import { entitySchemaGenerator as entitySchemaGenerator5 } from "roc-db";
|
|
|
91
99
|
import { z as z6 } from "zod";
|
|
92
100
|
|
|
93
101
|
// src/schemas/UserRefSchema.ts
|
|
94
|
-
import { refSchemaGenerator as
|
|
95
|
-
var UserRefSchema =
|
|
102
|
+
import { refSchemaGenerator as refSchemaGenerator6 } from "roc-db";
|
|
103
|
+
var UserRefSchema = refSchemaGenerator6("User");
|
|
96
104
|
|
|
97
105
|
// src/schemas/PostSchema.ts
|
|
98
106
|
var PostSchema = entitySchemaGenerator5("Post", {
|
|
@@ -167,8 +175,8 @@ var PostEntity = new Entity3("Post", {
|
|
|
167
175
|
import { z as z13 } from "zod";
|
|
168
176
|
|
|
169
177
|
// src/schemas/BlockRowRefSchema.ts
|
|
170
|
-
import { refSchemaGenerator as
|
|
171
|
-
var BlockRowRefSchema =
|
|
178
|
+
import { refSchemaGenerator as refSchemaGenerator7 } from "roc-db";
|
|
179
|
+
var BlockRowRefSchema = refSchemaGenerator7("BlockRow");
|
|
172
180
|
|
|
173
181
|
// src/schemas/BlockRefSchema.ts
|
|
174
182
|
var BlockRefSchema = z13.union([
|
|
@@ -215,6 +223,7 @@ var OrgSettingsEntity = new Entity6("OrgSettings", {
|
|
|
215
223
|
import { Entity as Entity7 } from "roc-db";
|
|
216
224
|
import { z as z17 } from "zod";
|
|
217
225
|
var PostVersion = new Entity7("PostVersion", {
|
|
226
|
+
version: true,
|
|
218
227
|
data: z17.object({
|
|
219
228
|
version: z17.number(),
|
|
220
229
|
snapshot: z17.array(z17.any())
|
|
@@ -433,29 +442,42 @@ var deletePost = writeOperation14("deletePost", PostRefSchema, (txn) => {
|
|
|
433
442
|
return Query14(() => txn.deleteEntity(ref, true));
|
|
434
443
|
});
|
|
435
444
|
|
|
436
|
-
// src/operations/
|
|
445
|
+
// src/operations/duplicateDraft.ts
|
|
437
446
|
import { Query as Query15, QueryChain as QueryChain6, writeOperation as writeOperation15 } from "roc-db";
|
|
438
447
|
import { z as z30 } from "zod";
|
|
439
|
-
var
|
|
440
|
-
|
|
441
|
-
|
|
448
|
+
var duplicateDraft = writeOperation15("duplicateDraft", z30.object({ sourceRef: DraftRefSchema, postRef: PostRefSchema }).strict(), (txn) => {
|
|
449
|
+
const newDraftRef = txn.createRef("Draft");
|
|
450
|
+
const { sourceRef, postRef } = txn.payload;
|
|
451
|
+
return QueryChain6(Query15(() => txn.createEntity(newDraftRef, { parents: { post: postRef } })), Query15(() => txn.duplicateChangeSetMutations(sourceRef, newDraftRef)), Query15((dup) => ({
|
|
452
|
+
draftRef: newDraftRef,
|
|
453
|
+
mutations: dup.mutations,
|
|
454
|
+
refMap: dup.refMap
|
|
455
|
+
})));
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
// src/operations/moveBlocks.ts
|
|
459
|
+
import { Query as Query16, QueryChain as QueryChain7, writeOperation as writeOperation16 } from "roc-db";
|
|
460
|
+
import { z as z31 } from "zod";
|
|
461
|
+
var PayloadSchema3 = z31.object({
|
|
462
|
+
refs: z31.array(z31.union([BlockParagraphRefSchema, BlockRowRefSchema])),
|
|
463
|
+
targetPosition: z31.number().min(0)
|
|
442
464
|
}).strict();
|
|
443
|
-
var moveBlocks =
|
|
465
|
+
var moveBlocks = writeOperation16("moveBlocks", PayloadSchema3, (txn) => {
|
|
444
466
|
const { refs } = txn.payload;
|
|
445
|
-
return
|
|
467
|
+
return QueryChain7(Query16(() => txn.batchReadEntities(refs)), Query16((items) => {
|
|
446
468
|
return "todo";
|
|
447
469
|
}));
|
|
448
470
|
});
|
|
449
471
|
|
|
450
472
|
// src/operations/pageBlocks.ts
|
|
451
|
-
import { Query as
|
|
452
|
-
import { z as
|
|
453
|
-
var pageBlocks = readOperation("pageBlocks",
|
|
454
|
-
size:
|
|
455
|
-
parentRef:
|
|
473
|
+
import { Query as Query17, readOperation } from "roc-db";
|
|
474
|
+
import { z as z32 } from "zod";
|
|
475
|
+
var pageBlocks = readOperation("pageBlocks", z32.object({
|
|
476
|
+
size: z32.number().default(100),
|
|
477
|
+
parentRef: z32.string().optional()
|
|
456
478
|
}), (txn) => {
|
|
457
479
|
const { size, parentRef } = txn.payload;
|
|
458
|
-
return
|
|
480
|
+
return Query17(() => txn.pageEntities({
|
|
459
481
|
entities: ["BlockImage", "BlockParagraph"],
|
|
460
482
|
size,
|
|
461
483
|
childrenOf: parentRef ? [parentRef] : []
|
|
@@ -463,50 +485,50 @@ var pageBlocks = readOperation("pageBlocks", z31.object({
|
|
|
463
485
|
});
|
|
464
486
|
|
|
465
487
|
// src/operations/pageEmptyEntitiesArray.ts
|
|
466
|
-
import { Query as
|
|
467
|
-
import { z as
|
|
468
|
-
var pageEmptyEntitiesArray = readOperation2("pageEmptyEntitiesArray",
|
|
488
|
+
import { Query as Query18, readOperation as readOperation2 } from "roc-db";
|
|
489
|
+
import { z as z33 } from "zod";
|
|
490
|
+
var pageEmptyEntitiesArray = readOperation2("pageEmptyEntitiesArray", z33.object({ size: z33.number().default(100) }), (txn) => {
|
|
469
491
|
const { size } = txn.payload;
|
|
470
|
-
return
|
|
492
|
+
return Query18(() => txn.pageEntities({ entities: [], size }));
|
|
471
493
|
});
|
|
472
494
|
|
|
473
495
|
// src/operations/pagePosts.ts
|
|
474
|
-
import { Query as
|
|
475
|
-
import { z as
|
|
476
|
-
var pagePosts = readOperation3("pagePosts",
|
|
496
|
+
import { Query as Query19, readOperation as readOperation3 } from "roc-db";
|
|
497
|
+
import { z as z34 } from "zod";
|
|
498
|
+
var pagePosts = readOperation3("pagePosts", z34.object({ size: z34.number().default(100) }).default({}), (txn) => {
|
|
477
499
|
const { size } = txn.payload;
|
|
478
|
-
return
|
|
500
|
+
return Query19(() => txn.pageEntities({ entities: ["Post"], size }));
|
|
479
501
|
});
|
|
480
502
|
|
|
481
503
|
// src/operations/pageSplat.ts
|
|
482
|
-
import { Query as
|
|
483
|
-
import { z as
|
|
484
|
-
var pageSplat = readOperation4("pageSplat",
|
|
504
|
+
import { Query as Query20, readOperation as readOperation4 } from "roc-db";
|
|
505
|
+
import { z as z35 } from "zod";
|
|
506
|
+
var pageSplat = readOperation4("pageSplat", z35.object({ size: z35.number().default(100) }), (txn) => {
|
|
485
507
|
const { size } = txn.payload;
|
|
486
|
-
return
|
|
508
|
+
return Query20(() => txn.pageEntities({ entities: "*", size }));
|
|
487
509
|
});
|
|
488
510
|
|
|
489
511
|
// src/operations/pagePostsByTag.ts
|
|
490
|
-
import { Query as
|
|
491
|
-
import { z as
|
|
492
|
-
var pagePostsByTag = readOperation5("pagePostsByTag",
|
|
512
|
+
import { Query as Query21, readOperation as readOperation5 } from "roc-db";
|
|
513
|
+
import { z as z36 } from "zod";
|
|
514
|
+
var pagePostsByTag = readOperation5("pagePostsByTag", z36.string(), (txn) => {
|
|
493
515
|
const tag = txn.payload;
|
|
494
|
-
return
|
|
516
|
+
return Query21(() => txn.pageEntitiesByIndex("Post", "tags", tag));
|
|
495
517
|
});
|
|
496
518
|
|
|
497
519
|
// src/operations/readEntity.ts
|
|
498
|
-
import { NotFoundError, Query as
|
|
499
|
-
import { z as
|
|
500
|
-
var readEntity = readOperation6("readEntity",
|
|
520
|
+
import { NotFoundError, Query as Query22, QueryChain as QueryChain8, readOperation as readOperation6 } from "roc-db";
|
|
521
|
+
import { z as z37 } from "zod";
|
|
522
|
+
var readEntity = readOperation6("readEntity", z37.string(), (txn) => {
|
|
501
523
|
const ref = txn.payload;
|
|
502
|
-
return
|
|
524
|
+
return QueryChain8(Query22(() => txn.readEntity(ref)), Query22((entity) => {
|
|
503
525
|
if (!entity) {
|
|
504
526
|
throw new NotFoundError(ref);
|
|
505
527
|
}
|
|
506
528
|
return entity;
|
|
507
529
|
}));
|
|
508
530
|
}, {
|
|
509
|
-
outputSchema:
|
|
531
|
+
outputSchema: z37.union([
|
|
510
532
|
PostSchema,
|
|
511
533
|
BlockImageSchema,
|
|
512
534
|
BlockParagraphSchema
|
|
@@ -514,11 +536,11 @@ var readEntity = readOperation6("readEntity", z36.string(), (txn) => {
|
|
|
514
536
|
});
|
|
515
537
|
|
|
516
538
|
// src/operations/readMutation.ts
|
|
517
|
-
import { NotFoundError as NotFoundError2, Query as
|
|
518
|
-
import { z as
|
|
519
|
-
var readMutation = readOperation7("readMutation",
|
|
539
|
+
import { NotFoundError as NotFoundError2, Query as Query23, QueryChain as QueryChain9, readOperation as readOperation7 } from "roc-db";
|
|
540
|
+
import { z as z38 } from "zod";
|
|
541
|
+
var readMutation = readOperation7("readMutation", z38.string(), (txn) => {
|
|
520
542
|
const ref = txn.payload;
|
|
521
|
-
return
|
|
543
|
+
return QueryChain9(Query23(() => txn.readMutation(ref)), Query23((entity) => {
|
|
522
544
|
if (!entity) {
|
|
523
545
|
throw new NotFoundError2(ref);
|
|
524
546
|
}
|
|
@@ -527,57 +549,57 @@ var readMutation = readOperation7("readMutation", z37.string(), (txn) => {
|
|
|
527
549
|
});
|
|
528
550
|
|
|
529
551
|
// src/operations/readOrgSettings.ts
|
|
530
|
-
import { Query as
|
|
531
|
-
import { z as
|
|
532
|
-
var readOrgSettings = readOperation8("readOrgSettings",
|
|
552
|
+
import { Query as Query24, readOperation as readOperation8 } from "roc-db";
|
|
553
|
+
import { z as z39 } from "zod";
|
|
554
|
+
var readOrgSettings = readOperation8("readOrgSettings", z39.object({}).optional(), (txn) => Query24(() => txn.readEntity("OrgSettings", true)));
|
|
533
555
|
|
|
534
556
|
// src/operations/readPost.ts
|
|
535
|
-
import { Query as
|
|
557
|
+
import { Query as Query25, readOperation as readOperation9 } from "roc-db";
|
|
536
558
|
var readPost = readOperation9("readPost", PostRefSchema, (txn) => {
|
|
537
559
|
const ref = txn.payload;
|
|
538
|
-
return
|
|
560
|
+
return Query25(() => txn.readEntity(ref, true));
|
|
539
561
|
}, { outputSchema: PostSchema });
|
|
540
562
|
|
|
541
563
|
// src/operations/readPostBySlug.ts
|
|
542
|
-
import { Query as
|
|
543
|
-
import { z as
|
|
544
|
-
var readPostBySlug = readOperation10("readPostBySlug",
|
|
564
|
+
import { Query as Query26, readOperation as readOperation10 } from "roc-db";
|
|
565
|
+
import { z as z40 } from "zod";
|
|
566
|
+
var readPostBySlug = readOperation10("readPostBySlug", z40.string(), (txn) => {
|
|
545
567
|
const slug = txn.payload;
|
|
546
|
-
return
|
|
568
|
+
return Query26(() => txn.readEntityByUniqueField("Post", "slug", slug));
|
|
547
569
|
}, { outputSchema: PostSchema });
|
|
548
570
|
|
|
549
571
|
// src/operations/testTransactionalEdits.ts
|
|
550
572
|
import { expect } from "bun:test";
|
|
551
|
-
import { Query as
|
|
552
|
-
import { z as
|
|
573
|
+
import { Query as Query27, QueryChain as QueryChain10, writeOperation as writeOperation17 } from "roc-db";
|
|
574
|
+
import { z as z41 } from "zod";
|
|
553
575
|
var TestCreatePatchDeleteInSameTransaction = (txn, title) => {
|
|
554
576
|
const postRef = txn.createRef("Post");
|
|
555
|
-
return
|
|
577
|
+
return QueryChain10(Query27(() => txn.createEntity(postRef, {
|
|
556
578
|
data: { title, tags: [] },
|
|
557
579
|
children: { blocks: [] }
|
|
558
|
-
})),
|
|
580
|
+
})), Query27(() => txn.patchEntity(postRef, { data: { foo: "bar" } })), Query27((post) => {
|
|
559
581
|
expect(post.data.title).toBe(title);
|
|
560
582
|
expect(post.data.foo).toBe("bar");
|
|
561
|
-
}),
|
|
583
|
+
}), Query27(() => txn.patchEntity(postRef, { data: { foo: null, bar: "foo" } })), Query27((post) => {
|
|
562
584
|
expect(post.data.title).toBe(title);
|
|
563
585
|
expect(post.data.foo).toBeUndefined();
|
|
564
586
|
expect(post.data.bar).toBe("foo");
|
|
565
587
|
expect(txn.log).toHaveLength(1);
|
|
566
588
|
expect(txn.log.get(postRef)[0]).toBe("create");
|
|
567
|
-
}),
|
|
589
|
+
}), Query27((post) => txn.deleteEntity(postRef)), Query27((res) => {
|
|
568
590
|
expect(res).toBe(1);
|
|
569
591
|
expect(txn.log).toHaveLength(0);
|
|
570
592
|
}));
|
|
571
593
|
};
|
|
572
594
|
var TestUpdateAndDeleteInSameTransaction = (txn, ref) => {
|
|
573
|
-
return
|
|
595
|
+
return QueryChain10(Query27(() => txn.patchEntity(ref, { data: { foo: "bar" } })), Query27((post) => {
|
|
574
596
|
expect(post.data.foo).toBe("bar");
|
|
575
|
-
}),
|
|
597
|
+
}), Query27(() => txn.patchEntity(ref, { data: { foo: null, bar: "foo" } })), Query27((post) => {
|
|
576
598
|
expect(post.data.foo).toBeUndefined();
|
|
577
599
|
expect(post.data.bar).toBe("foo");
|
|
578
600
|
expect(txn.log).toHaveLength(1);
|
|
579
601
|
expect(txn.log.get(ref)[0]).toBe("update");
|
|
580
|
-
}),
|
|
602
|
+
}), Query27((post) => txn.deleteEntity(ref)), Query27((res) => {
|
|
581
603
|
expect(res).toBe(1);
|
|
582
604
|
expect(txn.log).toHaveLength(1);
|
|
583
605
|
expect(txn.log.get(ref)[0]).toBe("delete");
|
|
@@ -585,14 +607,14 @@ var TestUpdateAndDeleteInSameTransaction = (txn, ref) => {
|
|
|
585
607
|
};
|
|
586
608
|
var TestCreateOnExistingRef = (txn) => {
|
|
587
609
|
const ref = txn.createRef("Post");
|
|
588
|
-
return
|
|
610
|
+
return QueryChain10(Query27(() => txn.createEntity(ref, { data: { foo: "bar" } })), Query27(() => txn.createEntity(ref, { data: { foo: "bar" } })));
|
|
589
611
|
};
|
|
590
|
-
var PayloadSchema4 =
|
|
591
|
-
name:
|
|
612
|
+
var PayloadSchema4 = z41.object({
|
|
613
|
+
name: z41.string().optional(),
|
|
592
614
|
post1ref: PostRefSchema.optional(),
|
|
593
615
|
post2ref: PostRefSchema.optional()
|
|
594
616
|
}).strict();
|
|
595
|
-
var testTransactionalEdits =
|
|
617
|
+
var testTransactionalEdits = writeOperation17("testTransactionalEdits", PayloadSchema4, (txn) => {
|
|
596
618
|
const { name, post1ref, post2ref } = txn.payload;
|
|
597
619
|
if (name)
|
|
598
620
|
return TestCreatePatchDeleteInSameTransaction(txn, name);
|
|
@@ -603,38 +625,38 @@ var testTransactionalEdits = writeOperation16("testTransactionalEdits", PayloadS
|
|
|
603
625
|
}, {});
|
|
604
626
|
|
|
605
627
|
// src/operations/updateBlockParagraph.ts
|
|
606
|
-
import { Query as
|
|
607
|
-
import { z as
|
|
608
|
-
var updateBlockParagraph =
|
|
628
|
+
import { Query as Query28, writeOperation as writeOperation18 } from "roc-db";
|
|
629
|
+
import { z as z42 } from "zod";
|
|
630
|
+
var updateBlockParagraph = writeOperation18("updateBlockParagraph", z42.object({
|
|
609
631
|
ref: BlockParagraphRefSchema,
|
|
610
|
-
content:
|
|
632
|
+
content: z42.string()
|
|
611
633
|
}), (txn) => {
|
|
612
634
|
const { ref, content } = txn.payload;
|
|
613
|
-
return
|
|
635
|
+
return Query28(() => txn.patchEntity(ref, {
|
|
614
636
|
data: { content }
|
|
615
637
|
}));
|
|
616
638
|
}, { outputSchema: BlockParagraphSchema });
|
|
617
639
|
|
|
618
640
|
// src/operations/updateOrgSettingsName.ts
|
|
619
|
-
import { Query as
|
|
620
|
-
import { z as
|
|
621
|
-
var updateOrgSettingsName =
|
|
641
|
+
import { Query as Query29, writeOperation as writeOperation19 } from "roc-db";
|
|
642
|
+
import { z as z43 } from "zod";
|
|
643
|
+
var updateOrgSettingsName = writeOperation19("updateOrgSettingsName", z43.object({ name: z43.string() }), (txn) => {
|
|
622
644
|
const { name } = txn.payload;
|
|
623
|
-
return
|
|
645
|
+
return Query29(() => txn.patchEntity("OrgSettings", { data: { name } }));
|
|
624
646
|
}, { debounce: 10 });
|
|
625
647
|
|
|
626
648
|
// src/operations/updatePost.ts
|
|
627
|
-
import { Query as
|
|
628
|
-
import { z as
|
|
629
|
-
var PayloadSchema5 =
|
|
649
|
+
import { Query as Query30, writeOperation as writeOperation20 } from "roc-db";
|
|
650
|
+
import { z as z44 } from "zod";
|
|
651
|
+
var PayloadSchema5 = z44.object({
|
|
630
652
|
ref: PostRefSchema,
|
|
631
|
-
title:
|
|
632
|
-
tags:
|
|
653
|
+
title: z44.string().optional(),
|
|
654
|
+
tags: z44.array(z44.string()).optional().default([]),
|
|
633
655
|
authorRef: UserRefSchema.optional()
|
|
634
656
|
});
|
|
635
|
-
var updatePost =
|
|
657
|
+
var updatePost = writeOperation20("updatePost", PayloadSchema5, (txn) => {
|
|
636
658
|
const { ref, authorRef, ...data } = txn.payload;
|
|
637
|
-
return
|
|
659
|
+
return Query30(() => txn.updateEntity(ref, {
|
|
638
660
|
data,
|
|
639
661
|
parents: { author: authorRef },
|
|
640
662
|
children: { blocks: [] }
|
|
@@ -642,43 +664,43 @@ var updatePost = writeOperation19("updatePost", PayloadSchema5, (txn) => {
|
|
|
642
664
|
}, { outputSchema: PostSchema });
|
|
643
665
|
|
|
644
666
|
// src/operations/updatePostDescription.ts
|
|
645
|
-
import { Query as
|
|
646
|
-
import { z as
|
|
647
|
-
var updatePostDescription =
|
|
667
|
+
import { Query as Query31, writeOperation as writeOperation21 } from "roc-db";
|
|
668
|
+
import { z as z45 } from "zod";
|
|
669
|
+
var updatePostDescription = writeOperation21("updatePostDescription", z45.object({ ref: PostRefSchema, description: z45.string() }), (txn) => {
|
|
648
670
|
const { ref, description } = txn.payload;
|
|
649
|
-
return
|
|
671
|
+
return Query31(() => txn.patchEntity(ref, { data: { description } }));
|
|
650
672
|
}, { debounce: 10, changeSetOnly: true, outputSchema: PostSchema });
|
|
651
673
|
|
|
652
674
|
// src/operations/updatePostSlug.ts
|
|
653
|
-
import { Query as
|
|
654
|
-
import { z as
|
|
655
|
-
var updatePostSlug =
|
|
675
|
+
import { Query as Query32, writeOperation as writeOperation22 } from "roc-db";
|
|
676
|
+
import { z as z46 } from "zod";
|
|
677
|
+
var updatePostSlug = writeOperation22("updatePostSlug", z46.object({ ref: PostRefSchema, slug: z46.string() }), (txn) => {
|
|
656
678
|
const { ref, slug } = txn.payload;
|
|
657
|
-
return
|
|
679
|
+
return Query32(() => txn.patchEntity(ref, { data: { slug } }));
|
|
658
680
|
}, { debounce: 10, outputSchema: PostSchema });
|
|
659
681
|
|
|
660
682
|
// src/operations/updatePostTags.ts
|
|
661
|
-
import { Query as
|
|
662
|
-
import { z as
|
|
663
|
-
var updatePostTags =
|
|
683
|
+
import { Query as Query33, writeOperation as writeOperation23 } from "roc-db";
|
|
684
|
+
import { z as z47 } from "zod";
|
|
685
|
+
var updatePostTags = writeOperation23("updatePostTags", z47.object({ ref: PostRefSchema, tags: z47.array(z47.string()) }), (txn) => {
|
|
664
686
|
const { ref, tags } = txn.payload;
|
|
665
|
-
return
|
|
687
|
+
return Query33(() => txn.patchEntity(ref, { data: { tags } }));
|
|
666
688
|
}, { debounce: 10, outputSchema: PostSchema });
|
|
667
689
|
|
|
668
690
|
// src/operations/updatePostTitle.ts
|
|
669
|
-
import { Query as
|
|
670
|
-
import { z as
|
|
671
|
-
var updatePostTitle =
|
|
691
|
+
import { Query as Query34, writeOperation as writeOperation24 } from "roc-db";
|
|
692
|
+
import { z as z48 } from "zod";
|
|
693
|
+
var updatePostTitle = writeOperation24("updatePostTitle", z48.object({ ref: PostRefSchema, title: z48.string() }), (txn) => {
|
|
672
694
|
const { ref, title } = txn.payload;
|
|
673
|
-
return
|
|
695
|
+
return Query34(() => txn.patchEntity(ref, { data: { title } }));
|
|
674
696
|
}, { debounce: 10, outputSchema: PostSchema });
|
|
675
697
|
|
|
676
698
|
// src/operations/crudBySlug.ts
|
|
677
|
-
import { Query as
|
|
678
|
-
import { z as
|
|
679
|
-
var crudBySlug =
|
|
699
|
+
import { Query as Query35, QueryChain as QueryChain11, writeOperation as writeOperation25 } from "roc-db";
|
|
700
|
+
import { z as z49 } from "zod";
|
|
701
|
+
var crudBySlug = writeOperation25("crudBySlug", z49.object({ slug: z49.string(), newSlug: z49.string() }), (txn) => {
|
|
680
702
|
const { slug, newSlug } = txn.payload;
|
|
681
|
-
return
|
|
703
|
+
return QueryChain11(Query35(() => txn.readEntityByUniqueField("Post", "slug", slug)), Query35((post) => txn.patchEntity(post.ref, { data: { slug: newSlug } })), Query35(() => txn.readEntityByUniqueField("Post", "slug", newSlug)), Query35((post) => txn.deleteEntity(post.ref)), Query35(() => {
|
|
682
704
|
return [
|
|
683
705
|
txn.readEntityByUniqueField("Post", "slug", slug, false),
|
|
684
706
|
txn.readEntityByUniqueField("Post", "slug", newSlug, false)
|
|
@@ -703,6 +725,7 @@ var operations = [
|
|
|
703
725
|
deleteDraft,
|
|
704
726
|
deleteOrgSettings,
|
|
705
727
|
deletePost,
|
|
728
|
+
duplicateDraft,
|
|
706
729
|
readPostBySlug,
|
|
707
730
|
moveBlocks,
|
|
708
731
|
pagePostsByTag,
|
|
@@ -732,7 +755,7 @@ import {
|
|
|
732
755
|
NotFoundError as NotFoundError3,
|
|
733
756
|
Snowflake
|
|
734
757
|
} from "roc-db";
|
|
735
|
-
import { z as
|
|
758
|
+
import { z as z50 } from "zod";
|
|
736
759
|
import { faker } from "@faker-js/faker";
|
|
737
760
|
var snowflake = new Snowflake(10, 10);
|
|
738
761
|
var prepareChangeSetTest = async (adapter, adapter2) => {
|
|
@@ -1056,7 +1079,7 @@ var testAdapterImplementation = async (adapterConstructor, generateArgs) => {
|
|
|
1056
1079
|
test("constructor rejects singleton + uniqueDataKeys", () => {
|
|
1057
1080
|
expect2(() => new Entity9("Bad", {
|
|
1058
1081
|
singleton: true,
|
|
1059
|
-
data:
|
|
1082
|
+
data: z50.object({ name: z50.string() }),
|
|
1060
1083
|
uniqueDataKeys: ["name"]
|
|
1061
1084
|
})).toThrow(/singleton/);
|
|
1062
1085
|
});
|
|
@@ -1196,6 +1219,40 @@ var testAdapterImplementation = async (adapterConstructor, generateArgs) => {
|
|
|
1196
1219
|
const changeSetAdapter2 = adapter1.changeSet("Draft/123");
|
|
1197
1220
|
expect2(() => changeSetAdapter2.createPost({ title: "Title 1" })).toThrow(BadRequestError);
|
|
1198
1221
|
});
|
|
1222
|
+
test("duplicateDraft (txn.duplicateChangeSetMutations) produces an independent copy with remapped refs", async () => {
|
|
1223
|
+
const [post2] = await adapter1.createPost({
|
|
1224
|
+
title: "Title 1",
|
|
1225
|
+
slug: faker.lorem.slug(5)
|
|
1226
|
+
});
|
|
1227
|
+
const [sourceDraft] = await adapter1.createDraft({
|
|
1228
|
+
postRef: post2.ref
|
|
1229
|
+
});
|
|
1230
|
+
const sourceCs = adapter1.changeSet(sourceDraft.ref);
|
|
1231
|
+
const [{ block: row }] = await sourceCs.createBlockRow({
|
|
1232
|
+
parentRef: post2.ref
|
|
1233
|
+
});
|
|
1234
|
+
const [{ block: para }] = await sourceCs.createBlockParagraph({
|
|
1235
|
+
parentRef: row.ref,
|
|
1236
|
+
content: "Hello"
|
|
1237
|
+
});
|
|
1238
|
+
const [{ draftRef: newDraftRef, mutations, refMap }] = await adapter1.duplicateDraft({
|
|
1239
|
+
sourceRef: sourceDraft.ref,
|
|
1240
|
+
postRef: post2.ref
|
|
1241
|
+
});
|
|
1242
|
+
expect2(mutations).toHaveLength(2);
|
|
1243
|
+
const newRow = refMap.get(row.ref);
|
|
1244
|
+
const newPara = refMap.get(para.ref);
|
|
1245
|
+
expect2(newRow).toBeDefined();
|
|
1246
|
+
expect2(newPara).toBeDefined();
|
|
1247
|
+
expect2(newRow).not.toBe(row.ref);
|
|
1248
|
+
expect2(newPara).not.toBe(para.ref);
|
|
1249
|
+
expect2([...refMap.values()]).not.toContain(row.ref);
|
|
1250
|
+
expect2([...refMap.values()]).not.toContain(para.ref);
|
|
1251
|
+
const targetCs = adapter1.changeSet(newDraftRef);
|
|
1252
|
+
expect2((await targetCs.readEntity(newRow)).ref).toBe(newRow);
|
|
1253
|
+
expect2((await targetCs.readEntity(newPara)).parents.parent).toBe(newRow);
|
|
1254
|
+
expect2((await sourceCs.readEntity(para.ref)).parents.parent).toBe(row.ref);
|
|
1255
|
+
});
|
|
1199
1256
|
test("deleteBlocks (patch running 2 times removing on array element every time)", async () => {
|
|
1200
1257
|
const [post2, createPostMutation] = await adapter1.createPost({
|
|
1201
1258
|
title: "Title 1",
|
|
@@ -4,4 +4,5 @@ export declare const Draft: Entity<"Draft", z.ZodObject<{
|
|
|
4
4
|
appliedAt: z.ZodOptional<z.ZodString>;
|
|
5
5
|
}, z.core.$strip>, z.ZodObject<{}, z.core.$strip>, z.ZodObject<{
|
|
6
6
|
post: z.ZodTemplateLiteral<`Post/${number}`>;
|
|
7
|
+
version: z.ZodOptional<z.ZodTemplateLiteral<`PostVersion/${number}`>>;
|
|
7
8
|
}, z.core.$strip>, z.ZodObject<{}, z.core.$strip>, false>;
|
|
@@ -2,6 +2,7 @@ export declare const entities: (import("roc-db").Entity<"Draft", import("zod").Z
|
|
|
2
2
|
appliedAt: import("zod").ZodOptional<import("zod").ZodString>;
|
|
3
3
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
4
4
|
post: import("zod").ZodTemplateLiteral<`Post/${number}`>;
|
|
5
|
+
version: import("zod").ZodOptional<import("zod").ZodTemplateLiteral<`PostVersion/${number}`>>;
|
|
5
6
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{}, import("zod/v4/core").$strip>, false> | import("roc-db").Entity<"BlockImage", import("zod").ZodObject<{
|
|
6
7
|
url: import("zod").ZodString;
|
|
7
8
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Canonical consumer usage of the `txn.duplicateChangeSetMutations` primitive:
|
|
4
|
+
* create the new draft and copy the source draft's pending mutations into it,
|
|
5
|
+
* all in one transaction.
|
|
6
|
+
*/
|
|
7
|
+
export declare const duplicateDraft: import("roc-db").WriteOperation<"duplicateDraft", z.ZodObject<{
|
|
8
|
+
sourceRef: z.ZodType<`Draft/${number}`, `Draft/${number}`, z.core.$ZodTypeInternals<`Draft/${number}`, `Draft/${number}`>>;
|
|
9
|
+
postRef: z.ZodTemplateLiteral<`Post/${number}`>;
|
|
10
|
+
}, z.core.$strict>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PostVersionRefSchema: import("zod").ZodTemplateLiteral<`PostVersion/${number}`>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ZodSchema } from "zod";
|
|
2
|
+
interface CustomMatchers {
|
|
3
|
+
toMatchZodSchema(schema: ZodSchema): any;
|
|
4
|
+
}
|
|
5
|
+
declare module "bun:test" {
|
|
6
|
+
interface Matchers<T> extends CustomMatchers {
|
|
7
|
+
}
|
|
8
|
+
interface AsymmetricMatchers extends CustomMatchers {
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@roc-db/test-utils",
|
|
3
|
-
"version": "0.2.0-pre.
|
|
3
|
+
"version": "0.2.0-pre.99",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
],
|
|
18
18
|
"sideEffects": false,
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"roc-db": "0.2.0-pre.98",
|
|
20
|
+
"roc-db": ">=0.2.0-pre.98 <1.0.0",
|
|
21
21
|
"zod": ">=4.0.0"
|
|
22
22
|
},
|
|
23
23
|
"keywords": [],
|
|
@@ -26,5 +26,9 @@
|
|
|
26
26
|
"type": "git",
|
|
27
27
|
"url": "git+https://github.com/eigilsagafos/roc-db.git"
|
|
28
28
|
},
|
|
29
|
-
"license": "MIT"
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public",
|
|
32
|
+
"registry": "https://registry.npmjs.org/"
|
|
33
|
+
}
|
|
30
34
|
}
|