@roc-db/test-utils 0.2.0-pre.24 → 0.2.0-pre.26

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
@@ -306,7 +306,7 @@ var readEntity = readOperation("readEntity", z17.string(), z17.union([PostSchema
306
306
  import { Query as Query11, readOperation as readOperation2 } from "roc-db";
307
307
  var readPost = readOperation2("readPost", PostRefSchema, PostSchema, (txn) => {
308
308
  const ref = txn.payload;
309
- return Query11(() => txn.readEntity(ref));
309
+ return Query11(() => txn.readEntity(ref, true));
310
310
  });
311
311
 
312
312
  // src/operations/updateBlockParagraph.ts
@@ -339,11 +339,25 @@ var updatePost = writeOperation11(UpdatePostMutationSchema, PostSchema, (txn) =>
339
339
  }));
340
340
  });
341
341
 
342
- // src/operations/updatePostTitle.ts
342
+ // src/operations/updatePostDescription.ts
343
343
  import { Query as Query14, writeOperation as writeOperation12 } from "roc-db";
344
- var updatePostTitle = writeOperation12(UpdatePostTitleMutationSchema, PostSchema, (txn) => {
344
+
345
+ // src/schemas/UpdatePostDescriptionMutationSchema.ts
346
+ import { mutationSchemaGenerator as mutationSchemaGenerator14 } from "roc-db";
347
+ import { z as z19 } from "zod";
348
+ var UpdatePostDescriptionMutationSchema = mutationSchemaGenerator14("updatePostDescription", z19.object({ ref: PostRefSchema, description: z19.string() }));
349
+
350
+ // src/operations/updatePostDescription.ts
351
+ var updatePostDescription = writeOperation12(UpdatePostDescriptionMutationSchema, PostSchema, (txn) => {
352
+ const { ref, description } = txn.payload;
353
+ return Query14(() => txn.patchEntity(ref, { data: { description } }));
354
+ }, { debounce: 10, changeSetOnly: true });
355
+
356
+ // src/operations/updatePostTitle.ts
357
+ import { Query as Query15, writeOperation as writeOperation13 } from "roc-db";
358
+ var updatePostTitle = writeOperation13(UpdatePostTitleMutationSchema, PostSchema, (txn) => {
345
359
  const { ref, title } = txn.payload;
346
- return Query14(() => txn.patchEntity(ref, { data: { title } }));
360
+ return Query15(() => txn.patchEntity(ref, { data: { title } }));
347
361
  }, { debounce: 10 });
348
362
 
349
363
  // src/operations/index.ts
@@ -361,6 +375,7 @@ var operations = [
361
375
  readPost,
362
376
  updateBlockParagraph,
363
377
  updatePost,
378
+ updatePostDescription,
364
379
  updatePostTitle
365
380
  ];
366
381
  // src/testAdapterImplementation.ts
@@ -435,6 +450,9 @@ var testAdapterImplementation = (adapterConstructor, engineArgsAdapter1 = {}, en
435
450
  expect(readPostRes.data.tags).toStrictEqual(["Foo", "Bar"]);
436
451
  expect(readPostRes).toMatchZodSchema(PostSchema);
437
452
  });
453
+ test("read not found (readEntity function)", async () => {
454
+ expect(() => adapter1.readPost("Post/999")).toThrow(NotFoundError2);
455
+ });
438
456
  test("update (updateEntity function)", async () => {
439
457
  const [post2] = await adapter1.updatePost({
440
458
  ref: postRef,
@@ -446,18 +464,26 @@ var testAdapterImplementation = (adapterConstructor, engineArgsAdapter1 = {}, en
446
464
  expect(post2).toMatchZodSchema(PostSchema);
447
465
  });
448
466
  test("updateTitle (patchEntity function + debounce)", async () => {
449
- const updatePostTitleRes1 = await adapter1.updatePostTitle({
467
+ const [update1, mutation1] = await adapter1.updatePostTitle({
450
468
  ref: postRef,
451
469
  title: "Title 3"
452
470
  });
453
- expect(updatePostTitleRes1[0]).toMatchZodSchema(PostSchema);
454
- const updatePostTitleRes2 = await adapter1.updatePostTitle({
471
+ expect(update1).toMatchZodSchema(PostSchema);
472
+ expect(mutation1).toMatchZodSchema(UpdatePostTitleMutationSchema);
473
+ const [update2, mutation2] = await adapter1.updatePostTitle({
455
474
  ref: postRef,
456
475
  title: "Title 4"
457
476
  });
458
- expect(updatePostTitleRes2[0]).toMatchZodSchema(PostSchema);
459
- expect(updatePostTitleRes2[1].ref).toBe(updatePostTitleRes1[1].ref);
460
- expect(updatePostTitleRes2[1].timestamp >= updatePostTitleRes1[1].timestamp).toBeTrue();
477
+ expect(update2).toMatchZodSchema(PostSchema);
478
+ expect(mutation2).toMatchZodSchema(UpdatePostTitleMutationSchema);
479
+ expect(mutation1.ref).toBe(mutation2.ref);
480
+ expect(mutation2.timestamp >= mutation1.timestamp).toBeTrue();
481
+ });
482
+ test("updatePostDescription without changeSetAdapter fails with BadRequestError", async () => {
483
+ expect(() => adapter1.updatePostDescription({
484
+ ref: postRef,
485
+ description: "Description 1"
486
+ })).toThrow(BadRequestError);
461
487
  });
462
488
  test("delete (deleteEntity function)", async () => {
463
489
  const [count, mutation] = await adapter1.deletePost(postRef);
@@ -172,6 +172,24 @@ export declare const operations: readonly [import("roc-db").WriteOperation<"appl
172
172
  authorRef?: `User/${string}` | undefined;
173
173
  }, {
174
174
  [x: string]: any;
175
+ }>, import("roc-db").WriteOperation<"updatePostDescription", {
176
+ ref: `Mutation/${string}`;
177
+ timestamp: string;
178
+ changeSetRef: null;
179
+ payload: {
180
+ ref: `Post/${string}`;
181
+ description: string;
182
+ };
183
+ log: [never, string, null][];
184
+ debounceCount: number;
185
+ identityRef: string;
186
+ name: "updatePostDescription";
187
+ sessionRef?: string | undefined;
188
+ }, {
189
+ ref: `Post/${string}`;
190
+ description: string;
191
+ }, {
192
+ [x: string]: any;
175
193
  }>, import("roc-db").WriteOperation<"updatePostTitle", {
176
194
  ref: `Mutation/${string}`;
177
195
  timestamp: string;
@@ -0,0 +1,19 @@
1
+ export declare const updatePostDescription: import("roc-db").WriteOperation<"updatePostDescription", {
2
+ ref: `Mutation/${string}`;
3
+ timestamp: string;
4
+ changeSetRef: null;
5
+ payload: {
6
+ ref: `Post/${string}`;
7
+ description: string;
8
+ };
9
+ log: [never, string, null][];
10
+ debounceCount: number;
11
+ identityRef: string;
12
+ name: "updatePostDescription";
13
+ sessionRef?: string | undefined;
14
+ }, {
15
+ ref: `Post/${string}`;
16
+ description: string;
17
+ }, {
18
+ [x: string]: any;
19
+ }>;
@@ -0,0 +1,51 @@
1
+ import { z } from "zod";
2
+ export declare const UpdatePostDescriptionMutationSchema: z.ZodObject<z.objectUtil.extendShape<{
3
+ ref: z.ZodType<`Mutation/${string}`, z.ZodTypeDef, `Mutation/${string}`>;
4
+ timestamp: z.ZodString;
5
+ changeSetRef: z.ZodNullable<z.ZodType<never, z.ZodTypeDef, never>>;
6
+ payload: z.ZodAny;
7
+ log: z.ZodArray<z.ZodTuple<[z.ZodType<never, z.ZodTypeDef, never>, z.ZodString, z.ZodNullable<z.ZodType<never, z.ZodTypeDef, never>>], null>, "many">;
8
+ debounceCount: z.ZodNumber;
9
+ identityRef: z.ZodString;
10
+ sessionRef: z.ZodOptional<z.ZodString>;
11
+ }, {
12
+ name: z.ZodLiteral<"updatePostDescription">;
13
+ changeSetRef: z.ZodType<never, z.ZodTypeDef, never> | z.ZodNullable<z.ZodType<never, z.ZodTypeDef, never>>;
14
+ payload: z.ZodObject<{
15
+ ref: z.ZodType<`Post/${string}`, z.ZodTypeDef, `Post/${string}`>;
16
+ description: z.ZodString;
17
+ }, "strip", z.ZodTypeAny, {
18
+ ref: `Post/${string}`;
19
+ description: string;
20
+ }, {
21
+ ref: `Post/${string}`;
22
+ description: string;
23
+ }>;
24
+ log: z.ZodType<[never, string, null][], z.ZodTypeDef, [never, string, null][]>;
25
+ }>, "strict", z.ZodTypeAny, {
26
+ ref: `Mutation/${string}`;
27
+ timestamp: string;
28
+ changeSetRef: null;
29
+ payload: {
30
+ ref: `Post/${string}`;
31
+ description: string;
32
+ };
33
+ log: [never, string, null][];
34
+ debounceCount: number;
35
+ identityRef: string;
36
+ name: "updatePostDescription";
37
+ sessionRef?: string | undefined;
38
+ }, {
39
+ ref: `Mutation/${string}`;
40
+ timestamp: string;
41
+ changeSetRef: null;
42
+ payload: {
43
+ ref: `Post/${string}`;
44
+ description: string;
45
+ };
46
+ log: [never, string, null][];
47
+ debounceCount: number;
48
+ identityRef: string;
49
+ name: "updatePostDescription";
50
+ sessionRef?: string | undefined;
51
+ }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roc-db/test-utils",
3
- "version": "0.2.0-pre.24",
3
+ "version": "0.2.0-pre.26",
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.24",
20
+ "roc-db": "0.2.0-pre.26",
21
21
  "zod": "3.24.2"
22
22
  },
23
23
  "keywords": [],