@roc-db/test-utils 0.2.0-pre.35 → 0.2.0-pre.37
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 +58 -14
- package/dist/types/operations/deleteBlocks.d.ts +13 -0
- package/dist/types/operations/index.d.ts +4 -4
- package/dist/types/schemas/{DeleteBlockMutationSchema.d.ts → DeleteBlocksMutationSchema.d.ts} +7 -7
- package/package.json +2 -2
- package/dist/types/operations/deleteBlock.d.ts +0 -13
package/dist/index.js
CHANGED
|
@@ -254,26 +254,33 @@ var createPost = writeOperation7(CreatePostMutationSchema, PostSchema, (txn) =>
|
|
|
254
254
|
}));
|
|
255
255
|
});
|
|
256
256
|
|
|
257
|
-
// src/operations/
|
|
257
|
+
// src/operations/deleteBlocks.ts
|
|
258
258
|
import { Query as Query8, QueryChain as QueryChain4, writeOperation as writeOperation8 } from "roc-db";
|
|
259
259
|
|
|
260
|
-
// src/schemas/
|
|
260
|
+
// src/schemas/DeleteBlocksMutationSchema.ts
|
|
261
261
|
import { mutationSchemaGenerator as mutationSchemaGenerator11 } from "roc-db";
|
|
262
262
|
import { z as z16 } from "zod";
|
|
263
|
-
var
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
263
|
+
var DeleteBlocksMutationSchema = mutationSchemaGenerator11("deleteBlocks", z16.array(z16.union([
|
|
264
|
+
BlockParagraphRefSchema,
|
|
265
|
+
BlockImageRefSchema,
|
|
266
|
+
BlockRowRefSchema
|
|
267
|
+
])));
|
|
268
|
+
|
|
269
|
+
// src/operations/deleteBlocks.ts
|
|
270
|
+
var DeleteBlockQuery = (txn, blockRef) => {
|
|
271
|
+
return QueryChain4(Query8(() => txn.readEntity(blockRef)), Query8((block) => {
|
|
272
|
+
return txn.readEntity(block.parents.parent, true);
|
|
273
|
+
}), Query8((post) => {
|
|
269
274
|
return txn.patchEntity(post.ref, {
|
|
270
|
-
|
|
271
|
-
|
|
275
|
+
children: {
|
|
276
|
+
blocks: post.children.blocks.filter((ref) => ref !== blockRef)
|
|
272
277
|
}
|
|
273
278
|
});
|
|
274
|
-
}), Query8(() => txn.deleteEntity(blockRef))
|
|
275
|
-
|
|
276
|
-
|
|
279
|
+
}), Query8(() => txn.deleteEntity(blockRef)));
|
|
280
|
+
};
|
|
281
|
+
var deleteBlocks = writeOperation8(DeleteBlocksMutationSchema, PostSchema, (txn) => {
|
|
282
|
+
const refs = txn.payload;
|
|
283
|
+
return QueryChain4(...refs.map((ref) => DeleteBlockQuery(txn, ref)));
|
|
277
284
|
}, { changeSetOnly: true });
|
|
278
285
|
|
|
279
286
|
// src/operations/deletePost.ts
|
|
@@ -446,7 +453,7 @@ var operations = [
|
|
|
446
453
|
createBlockRow,
|
|
447
454
|
createDraft,
|
|
448
455
|
createPost,
|
|
449
|
-
|
|
456
|
+
deleteBlocks,
|
|
450
457
|
deletePost,
|
|
451
458
|
moveBlocks,
|
|
452
459
|
readEntity,
|
|
@@ -680,6 +687,43 @@ var testAdapterImplementation = async (adapterConstructor, generateArgs) => {
|
|
|
680
687
|
expect2(res.length).toBeGreaterThan(0);
|
|
681
688
|
expect2(res.every((m) => m.changeSetRef === draftRef)).toBeTrue();
|
|
682
689
|
});
|
|
690
|
+
test("invalid changeSetRef throws error", async () => {
|
|
691
|
+
const changeSetAdapter2 = adapter1.changeSet("Draft/123");
|
|
692
|
+
expect2(() => changeSetAdapter2.createPost({ title: "Title 1" })).toThrow(BadRequestError);
|
|
693
|
+
});
|
|
694
|
+
test("deleteBlocks (patch running 2 times removing on array element every time)", async () => {
|
|
695
|
+
const [post2, createPostMutation] = await adapter1.createPost({
|
|
696
|
+
title: "Title 1",
|
|
697
|
+
slug: "title-1",
|
|
698
|
+
tags: ["Foo", "Bar"]
|
|
699
|
+
});
|
|
700
|
+
const [draft2, createDraftMutation] = await adapter1.createDraft({
|
|
701
|
+
postRef: post2.ref
|
|
702
|
+
});
|
|
703
|
+
const changeSetAdapter2 = adapter1.changeSet(draft2.ref);
|
|
704
|
+
const [{ block: blockParagraph12 }, createBlockParagraph1Mutation] = await changeSetAdapter2.createBlockParagraph({
|
|
705
|
+
parentRef: post2.ref
|
|
706
|
+
});
|
|
707
|
+
const [{ block: blockParagraph22 }, createBlockParagraph2Mutation] = await changeSetAdapter2.createBlockParagraph({
|
|
708
|
+
parentRef: post2.ref
|
|
709
|
+
});
|
|
710
|
+
const readPost2 = await changeSetAdapter2.readEntity(post2.ref);
|
|
711
|
+
expect2(readPost2.children.blocks).toEqual([
|
|
712
|
+
blockParagraph12.ref,
|
|
713
|
+
blockParagraph22.ref
|
|
714
|
+
]);
|
|
715
|
+
const [, deleteMutation] = await changeSetAdapter2.deleteBlocks([
|
|
716
|
+
blockParagraph12.ref,
|
|
717
|
+
blockParagraph22.ref
|
|
718
|
+
]);
|
|
719
|
+
expect2(deleteMutation.log[0][2].children.blocks).toEqual([
|
|
720
|
+
blockParagraph12.ref,
|
|
721
|
+
blockParagraph22.ref
|
|
722
|
+
]);
|
|
723
|
+
expect2(deleteMutation.log[0][2].updated.mutationRef).toBe(createBlockParagraph2Mutation.ref);
|
|
724
|
+
const readPost22 = await changeSetAdapter2.readEntity(post2.ref);
|
|
725
|
+
expect2(readPost22.updated.mutationRef).toEqual(deleteMutation.ref);
|
|
726
|
+
});
|
|
683
727
|
test("applyDraft", async () => {
|
|
684
728
|
const { draftRef: draftRef2 } = await prepareChangeSetTest(adapter1);
|
|
685
729
|
const [version, mutation] = await adapter1.applyDraft({
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const deleteBlocks: import("roc-db").WriteOperation<"deleteBlocks", {
|
|
2
|
+
ref: `Mutation/${string}`;
|
|
3
|
+
timestamp: string;
|
|
4
|
+
changeSetRef: null;
|
|
5
|
+
payload: (`BlockImage/${string}` | `BlockParagraph/${string}` | `BlockRow/${string}`)[];
|
|
6
|
+
log: any[];
|
|
7
|
+
debounceCount: number;
|
|
8
|
+
identityRef: string;
|
|
9
|
+
name: "deleteBlocks";
|
|
10
|
+
sessionRef?: string | undefined;
|
|
11
|
+
}, (`BlockImage/${string}` | `BlockParagraph/${string}` | `BlockRow/${string}`)[], {
|
|
12
|
+
[x: string]: any;
|
|
13
|
+
}>;
|
|
@@ -112,17 +112,17 @@ export declare const operations: readonly [import("roc-db").WriteOperation<"appl
|
|
|
112
112
|
slug?: string | undefined;
|
|
113
113
|
}, {
|
|
114
114
|
[x: string]: any;
|
|
115
|
-
}>, import("roc-db").WriteOperation<"
|
|
115
|
+
}>, import("roc-db").WriteOperation<"deleteBlocks", {
|
|
116
116
|
ref: `Mutation/${string}`;
|
|
117
117
|
timestamp: string;
|
|
118
118
|
changeSetRef: null;
|
|
119
|
-
payload: `BlockImage/${string}` | `BlockParagraph/${string}
|
|
119
|
+
payload: (`BlockImage/${string}` | `BlockParagraph/${string}` | `BlockRow/${string}`)[];
|
|
120
120
|
log: any[];
|
|
121
121
|
debounceCount: number;
|
|
122
122
|
identityRef: string;
|
|
123
|
-
name: "
|
|
123
|
+
name: "deleteBlocks";
|
|
124
124
|
sessionRef?: string | undefined;
|
|
125
|
-
}, `BlockImage/${string}` | `BlockParagraph/${string}
|
|
125
|
+
}, (`BlockImage/${string}` | `BlockParagraph/${string}` | `BlockRow/${string}`)[], {
|
|
126
126
|
[x: string]: any;
|
|
127
127
|
}>, import("roc-db").WriteOperation<"deletePost", {
|
|
128
128
|
ref: `Mutation/${string}`;
|
package/dist/types/schemas/{DeleteBlockMutationSchema.d.ts → DeleteBlocksMutationSchema.d.ts}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const DeleteBlocksMutationSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
3
3
|
ref: z.ZodType<`Mutation/${string}`, z.ZodTypeDef, `Mutation/${string}`>;
|
|
4
4
|
timestamp: z.ZodString;
|
|
5
5
|
changeSetRef: z.ZodNullable<z.ZodType<never, z.ZodTypeDef, never>>;
|
|
@@ -9,28 +9,28 @@ export declare const DeleteBlockMutationSchema: z.ZodObject<z.objectUtil.extendS
|
|
|
9
9
|
identityRef: z.ZodString;
|
|
10
10
|
sessionRef: z.ZodOptional<z.ZodString>;
|
|
11
11
|
}, {
|
|
12
|
-
name: z.ZodLiteral<"
|
|
12
|
+
name: z.ZodLiteral<"deleteBlocks">;
|
|
13
13
|
changeSetRef: z.ZodType<never, z.ZodTypeDef, never> | z.ZodNullable<z.ZodType<never, z.ZodTypeDef, never>>;
|
|
14
|
-
payload: z.ZodUnion<[z.ZodType<`BlockParagraph/${string}`, z.ZodTypeDef, `BlockParagraph/${string}`>, z.ZodType<`BlockImage/${string}`, z.ZodTypeDef, `BlockImage/${string}`>]>;
|
|
14
|
+
payload: z.ZodArray<z.ZodUnion<[z.ZodType<`BlockParagraph/${string}`, z.ZodTypeDef, `BlockParagraph/${string}`>, z.ZodType<`BlockImage/${string}`, z.ZodTypeDef, `BlockImage/${string}`>, z.ZodType<`BlockRow/${string}`, z.ZodTypeDef, `BlockRow/${string}`>]>, "many">;
|
|
15
15
|
log: z.ZodType<any[], z.ZodTypeDef, any[]>;
|
|
16
16
|
}>, "strict", z.ZodTypeAny, {
|
|
17
17
|
ref: `Mutation/${string}`;
|
|
18
18
|
timestamp: string;
|
|
19
19
|
changeSetRef: null;
|
|
20
|
-
payload: `BlockImage/${string}` | `BlockParagraph/${string}
|
|
20
|
+
payload: (`BlockImage/${string}` | `BlockParagraph/${string}` | `BlockRow/${string}`)[];
|
|
21
21
|
log: any[];
|
|
22
22
|
debounceCount: number;
|
|
23
23
|
identityRef: string;
|
|
24
|
-
name: "
|
|
24
|
+
name: "deleteBlocks";
|
|
25
25
|
sessionRef?: string | undefined;
|
|
26
26
|
}, {
|
|
27
27
|
ref: `Mutation/${string}`;
|
|
28
28
|
timestamp: string;
|
|
29
29
|
changeSetRef: null;
|
|
30
|
-
payload: `BlockImage/${string}` | `BlockParagraph/${string}
|
|
30
|
+
payload: (`BlockImage/${string}` | `BlockParagraph/${string}` | `BlockRow/${string}`)[];
|
|
31
31
|
log: any[];
|
|
32
32
|
debounceCount: number;
|
|
33
33
|
identityRef: string;
|
|
34
|
-
name: "
|
|
34
|
+
name: "deleteBlocks";
|
|
35
35
|
sessionRef?: string | undefined;
|
|
36
36
|
}>;
|
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.37",
|
|
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.
|
|
20
|
+
"roc-db": "0.2.0-pre.37",
|
|
21
21
|
"zod": "3.24.2"
|
|
22
22
|
},
|
|
23
23
|
"keywords": [],
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare const deleteBlock: import("roc-db").WriteOperation<"deleteBlock", {
|
|
2
|
-
ref: `Mutation/${string}`;
|
|
3
|
-
timestamp: string;
|
|
4
|
-
changeSetRef: null;
|
|
5
|
-
payload: `BlockImage/${string}` | `BlockParagraph/${string}`;
|
|
6
|
-
log: any[];
|
|
7
|
-
debounceCount: number;
|
|
8
|
-
identityRef: string;
|
|
9
|
-
name: "deleteBlock";
|
|
10
|
-
sessionRef?: string | undefined;
|
|
11
|
-
}, `BlockImage/${string}` | `BlockParagraph/${string}`, {
|
|
12
|
-
[x: string]: any;
|
|
13
|
-
}>;
|