@roc-db/test-utils 0.2.0-pre.36 → 0.2.0-pre.38

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 CHANGED
@@ -254,26 +254,33 @@ var createPost = writeOperation7(CreatePostMutationSchema, PostSchema, (txn) =>
254
254
  }));
255
255
  });
256
256
 
257
- // src/operations/deleteBlock.ts
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/DeleteBlockMutationSchema.ts
260
+ // src/schemas/DeleteBlocksMutationSchema.ts
261
261
  import { mutationSchemaGenerator as mutationSchemaGenerator11 } from "roc-db";
262
262
  import { z as z16 } from "zod";
263
- var DeleteBlockMutationSchema = mutationSchemaGenerator11("deleteBlock", z16.union([BlockParagraphRefSchema, BlockImageRefSchema]));
264
-
265
- // src/operations/deleteBlock.ts
266
- var deleteBlock = writeOperation8(DeleteBlockMutationSchema, PostSchema, (txn) => {
267
- const blockRef = txn.payload;
268
- return QueryChain4(Query8(() => txn.readEntity(blockRef, true)), Query8((block) => txn.readEntity(block.parents.post, true)), Query8((post) => {
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
- data: {
271
- blockRefs: post.data.blockRefs.filter((ref) => ref !== blockRef)
275
+ children: {
276
+ blocks: post.children.blocks.filter((ref) => ref !== blockRef)
272
277
  }
273
278
  });
274
- }), Query8(() => txn.deleteEntity(blockRef)), Query8((_, updatedPost) => {
275
- return updatedPost;
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
- deleteBlock,
456
+ deleteBlocks,
450
457
  deletePost,
451
458
  moveBlocks,
452
459
  readEntity,
@@ -459,7 +466,8 @@ var operations = [
459
466
  ];
460
467
  // src/testAdapterImplementation.ts
461
468
  import { beforeAll, describe, expect as expect2, test } from "bun:test";
462
- import { BadRequestError, NotFoundError as NotFoundError2 } from "roc-db";
469
+ import { BadRequestError, NotFoundError as NotFoundError2, Snowflake } from "roc-db";
470
+ var snowflake = new Snowflake(10, 10);
463
471
  var prepareChangeSetTest = async (adapter, adapter2) => {
464
472
  const [post, createPostMutation] = await adapter.createPost({
465
473
  title: "Title 1",
@@ -511,6 +519,7 @@ var testAdapterImplementation = async (adapterConstructor, generateArgs) => {
511
519
  operations,
512
520
  entities,
513
521
  session: { identityRef: "User/42" },
522
+ snowflake,
514
523
  ...await generateArgs()
515
524
  });
516
525
  };
@@ -684,6 +693,39 @@ var testAdapterImplementation = async (adapterConstructor, generateArgs) => {
684
693
  const changeSetAdapter2 = adapter1.changeSet("Draft/123");
685
694
  expect2(() => changeSetAdapter2.createPost({ title: "Title 1" })).toThrow(BadRequestError);
686
695
  });
696
+ test("deleteBlocks (patch running 2 times removing on array element every time)", async () => {
697
+ const [post2, createPostMutation] = await adapter1.createPost({
698
+ title: "Title 1",
699
+ slug: "title-1",
700
+ tags: ["Foo", "Bar"]
701
+ });
702
+ const [draft2, createDraftMutation] = await adapter1.createDraft({
703
+ postRef: post2.ref
704
+ });
705
+ const changeSetAdapter2 = adapter1.changeSet(draft2.ref);
706
+ const [{ block: blockParagraph12 }, createBlockParagraph1Mutation] = await changeSetAdapter2.createBlockParagraph({
707
+ parentRef: post2.ref
708
+ });
709
+ const [{ block: blockParagraph22 }, createBlockParagraph2Mutation] = await changeSetAdapter2.createBlockParagraph({
710
+ parentRef: post2.ref
711
+ });
712
+ const readPost2 = await changeSetAdapter2.readEntity(post2.ref);
713
+ expect2(readPost2.children.blocks).toEqual([
714
+ blockParagraph12.ref,
715
+ blockParagraph22.ref
716
+ ]);
717
+ const [, deleteMutation] = await changeSetAdapter2.deleteBlocks([
718
+ blockParagraph12.ref,
719
+ blockParagraph22.ref
720
+ ]);
721
+ expect2(deleteMutation.log[0][2].children.blocks).toEqual([
722
+ blockParagraph12.ref,
723
+ blockParagraph22.ref
724
+ ]);
725
+ expect2(deleteMutation.log[0][2].updated.mutationRef).toBe(createBlockParagraph2Mutation.ref);
726
+ const readPost22 = await changeSetAdapter2.readEntity(post2.ref);
727
+ expect2(readPost22.updated.mutationRef).toEqual(deleteMutation.ref);
728
+ });
687
729
  test("applyDraft", async () => {
688
730
  const { draftRef: draftRef2 } = await prepareChangeSetTest(adapter1);
689
731
  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<"deleteBlock", {
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: "deleteBlock";
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}`;
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- export declare const DeleteBlockMutationSchema: z.ZodObject<z.objectUtil.extendShape<{
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<"deleteBlock">;
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: "deleteBlock";
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: "deleteBlock";
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.36",
3
+ "version": "0.2.0-pre.38",
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.36",
20
+ "roc-db": "0.2.0-pre.38",
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
- }>;