@roc-db/test-utils 0.2.0-pre.2 → 0.2.0-pre.20

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
@@ -128,95 +128,108 @@ var entities = [
128
128
  DraftSchema,
129
129
  PostSchema
130
130
  ];
131
- // src/operations/createBlockImage.ts
131
+ // src/operations/applyDraft.ts
132
132
  import { Query, writeOperation } from "roc-db";
133
133
 
134
- // src/schemas/CreateBlockImageMutationSchema.ts
134
+ // src/schemas/ApplyDraftMutationSchema.ts
135
135
  import { mutationSchemaGenerator as mutationSchemaGenerator5 } from "roc-db";
136
136
  import { z as z10 } from "zod";
137
- var CreateBlockImageMutationSchema = mutationSchemaGenerator5("createBlockImage", z10.object({ postRef: PostRefSchema }).strict(), undefined, true);
137
+ var ApplyDraftMutationSchema = mutationSchemaGenerator5("applyDraft", z10.object({ ref: DraftRefSchema }).strict());
138
+
139
+ // src/operations/applyDraft.ts
140
+ var applyDraft = writeOperation(ApplyDraftMutationSchema, undefined, (txn) => {
141
+ const { ref } = txn.payload;
142
+ return Query(() => txn.applyChangeSet(ref));
143
+ });
138
144
 
139
145
  // src/operations/createBlockImage.ts
140
- var createBlockImage = writeOperation(CreateBlockImageMutationSchema, BlockImageSchema, (txn) => {
146
+ import { Query as Query2, writeOperation as writeOperation2 } from "roc-db";
147
+
148
+ // src/schemas/CreateBlockImageMutationSchema.ts
149
+ import { mutationSchemaGenerator as mutationSchemaGenerator6 } from "roc-db";
150
+ import { z as z11 } from "zod";
151
+ var CreateBlockImageMutationSchema = mutationSchemaGenerator6("createBlockImage", z11.object({ postRef: PostRefSchema }).strict(), undefined, true);
152
+
153
+ // src/operations/createBlockImage.ts
154
+ var createBlockImage = writeOperation2(CreateBlockImageMutationSchema, BlockImageSchema, (txn) => {
141
155
  const ref = txn.createRef("BlockImage");
142
156
  const { postRef } = txn.payload;
143
- return Query(() => txn.createEntity(ref, { parents: { post: postRef } }));
157
+ return Query2(() => txn.createEntity(ref, { parents: { post: postRef } }));
144
158
  }, { changeSetOnly: true });
145
159
 
146
160
  // src/operations/createBlockParagraph.ts
147
- import { Query as Query2, QueryChain, writeOperation as writeOperation2 } from "roc-db";
161
+ import { Query as Query3, QueryChain, writeOperation as writeOperation3 } from "roc-db";
148
162
 
149
163
  // src/schemas/CreateBlockParagraphMutationSchema.ts
150
- import { mutationSchemaGenerator as mutationSchemaGenerator6 } from "roc-db";
151
- import { z as z11 } from "zod";
164
+ import { mutationSchemaGenerator as mutationSchemaGenerator7 } from "roc-db";
165
+ import { z as z12 } from "zod";
152
166
 
153
167
  // src/schemas/BlockRowRefSchema.ts
154
168
  import { refSchemaGenerator as refSchemaGenerator7 } from "roc-db";
155
169
  var BlockRowRefSchema = refSchemaGenerator7("BlockRow");
156
170
 
157
171
  // src/schemas/CreateBlockParagraphMutationSchema.ts
158
- var CreateBlockParagraphMutationSchema = mutationSchemaGenerator6("createBlockParagraph", z11.object({ parentRef: z11.union([PostRefSchema, BlockRowRefSchema]) }).strict(), undefined, true);
172
+ var CreateBlockParagraphMutationSchema = mutationSchemaGenerator7("createBlockParagraph", z12.object({ parentRef: z12.union([PostRefSchema, BlockRowRefSchema]) }).strict(), undefined, true);
159
173
 
160
174
  // src/operations/createBlockParagraph.ts
161
- var createBlockParagrah = writeOperation2(CreateBlockParagraphMutationSchema, BlockParagraphSchema, (txn) => {
175
+ var createBlockParagrah = writeOperation3(CreateBlockParagraphMutationSchema, BlockParagraphSchema, (txn) => {
162
176
  const ref = txn.createRef("BlockParagraph");
163
177
  const { parentRef } = txn.payload;
164
- return QueryChain(Query2(() => txn.readEntity(parentRef, true)), Query2((parent) => txn.patchEntity(parentRef, {
178
+ return QueryChain(Query3(() => txn.readEntity(parentRef, true)), Query3((parent) => txn.patchEntity(parentRef, {
165
179
  children: { blocks: [...parent.children.blocks, ref] }
166
- })), Query2(() => txn.createEntity(ref, { parents: { parent: parentRef } })), Query2((block, updatedParent) => ({ block, updatedParent })));
180
+ })), Query3(() => txn.createEntity(ref, { parents: { parent: parentRef } })), Query3((block, updatedParent) => ({ block, updatedParent })));
167
181
  }, { changeSetOnly: true });
168
182
 
169
183
  // src/operations/createBlockRow.ts
170
- import { Query as Query3, QueryChain as QueryChain2, writeOperation as writeOperation3 } from "roc-db";
184
+ import { Query as Query4, QueryChain as QueryChain2, writeOperation as writeOperation4 } from "roc-db";
171
185
 
172
186
  // src/schemas/CreateBlockRowMutationSchema.ts
173
- import { mutationSchemaGenerator as mutationSchemaGenerator7 } from "roc-db";
174
- import { z as z12 } from "zod";
175
- var CreateBlockRowMutationSchema = mutationSchemaGenerator7("createBlockRow", z12.object({ parentRef: z12.union([PostRefSchema, BlockRowRefSchema]) }).strict(), undefined, true);
187
+ import { mutationSchemaGenerator as mutationSchemaGenerator8 } from "roc-db";
188
+ import { z as z13 } from "zod";
189
+ var CreateBlockRowMutationSchema = mutationSchemaGenerator8("createBlockRow", z13.object({ parentRef: z13.union([PostRefSchema, BlockRowRefSchema]) }).strict(), undefined, true);
176
190
 
177
191
  // src/operations/createBlockRow.ts
178
- var createBlockRow = writeOperation3(CreateBlockRowMutationSchema, BlockParagraphSchema, (txn) => {
192
+ var createBlockRow = writeOperation4(CreateBlockRowMutationSchema, BlockParagraphSchema, (txn) => {
179
193
  const ref = txn.createRef("BlockRow");
180
194
  const { parentRef } = txn.payload;
181
- return QueryChain2(Query3(() => txn.readEntity(parentRef)), Query3((parent) => {
182
- console.log("asdfasfd", parent);
195
+ return QueryChain2(Query4(() => txn.readEntity(parentRef)), Query4((parent) => {
183
196
  return txn.patchEntity(parentRef, {
184
197
  children: { blocks: [...parent.children.blocks, ref] }
185
198
  });
186
- }), Query3(() => txn.createEntity(ref, {
199
+ }), Query4(() => txn.createEntity(ref, {
187
200
  children: { blocks: [] },
188
201
  parents: { parent: parentRef }
189
- })), Query3((block, updatedParent) => ({ block, updatedParent })));
202
+ })), Query4((block, updatedParent) => ({ block, updatedParent })));
190
203
  }, { changeSetOnly: true });
191
204
 
192
205
  // src/operations/createBlockTitle.ts
193
- import { Query as Query4, writeOperation as writeOperation4 } from "roc-db";
206
+ import { Query as Query5, writeOperation as writeOperation5 } from "roc-db";
194
207
 
195
208
  // src/schemas/CreateBlockTitleMutationSchema.ts
196
- import { mutationSchemaGenerator as mutationSchemaGenerator8 } from "roc-db";
197
- import { z as z13 } from "zod";
198
- var CreateBlockTitleMutationSchema = mutationSchemaGenerator8("createBlockTitle", z13.object({ parentRef: z13.union([PostRefSchema, BlockRowRefSchema]) }).strict(), undefined, true);
209
+ import { mutationSchemaGenerator as mutationSchemaGenerator9 } from "roc-db";
210
+ import { z as z14 } from "zod";
211
+ var CreateBlockTitleMutationSchema = mutationSchemaGenerator9("createBlockTitle", z14.object({ parentRef: z14.union([PostRefSchema, BlockRowRefSchema]) }).strict(), undefined, true);
199
212
 
200
213
  // src/operations/createBlockTitle.ts
201
- var createBlockTitle = writeOperation4(CreateBlockTitleMutationSchema, BlockTitleSchema, (txn) => {
214
+ var createBlockTitle = writeOperation5(CreateBlockTitleMutationSchema, BlockTitleSchema, (txn) => {
202
215
  const ref = txn.createRef("BlockTitle");
203
216
  const { postRef } = txn.payload;
204
- return Query4(() => txn.createEntity(ref, { parents: { post: postRef } }));
217
+ return Query5(() => txn.createEntity(ref, { parents: { post: postRef } }));
205
218
  }, { changeSetOnly: true });
206
219
 
207
220
  // src/operations/createDraft.ts
208
- import { Query as Query5, writeOperation as writeOperation5 } from "roc-db";
221
+ import { Query as Query6, writeOperation as writeOperation6 } from "roc-db";
209
222
 
210
223
  // src/schemas/CreateDraftMutationSchema.ts
211
- import { mutationSchemaGenerator as mutationSchemaGenerator9 } from "roc-db";
212
- import { z as z14 } from "zod";
213
- var CreateDraftMutationSchema = mutationSchemaGenerator9("createDraft", z14.object({ postRef: PostRefSchema }).strict());
224
+ import { mutationSchemaGenerator as mutationSchemaGenerator10 } from "roc-db";
225
+ import { z as z15 } from "zod";
226
+ var CreateDraftMutationSchema = mutationSchemaGenerator10("createDraft", z15.object({ postRef: PostRefSchema }).strict());
214
227
 
215
228
  // src/operations/createDraft.ts
216
- var createDraft = writeOperation5(CreateDraftMutationSchema, DraftSchema, (txn) => {
229
+ var createDraft = writeOperation6(CreateDraftMutationSchema, DraftSchema, (txn) => {
217
230
  const ref = txn.createRef("Draft");
218
231
  const { postRef } = txn.payload;
219
- return Query5(() => txn.createEntity(ref, {
232
+ return Query6(() => txn.createEntity(ref, {
220
233
  parents: {
221
234
  post: postRef
222
235
  }
@@ -224,57 +237,57 @@ var createDraft = writeOperation5(CreateDraftMutationSchema, DraftSchema, (txn)
224
237
  });
225
238
 
226
239
  // src/operations/createPost.ts
227
- import { Query as Query6, writeOperation as writeOperation6 } from "roc-db";
228
- var createPost = writeOperation6(CreatePostMutationSchema, PostSchema, (txn) => {
240
+ import { Query as Query7, writeOperation as writeOperation7 } from "roc-db";
241
+ var createPost = writeOperation7(CreatePostMutationSchema, PostSchema, (txn) => {
229
242
  const ref = txn.createRef("Post");
230
243
  const { title, slug, tags } = txn.payload;
231
- return Query6(() => txn.createEntity(ref, {
244
+ return Query7(() => txn.createEntity(ref, {
232
245
  data: { title, tags, slug },
233
246
  children: { blocks: [] }
234
247
  }));
235
248
  });
236
249
 
237
250
  // src/operations/deleteBlock.ts
238
- import { Query as Query7, QueryChain as QueryChain3, writeOperation as writeOperation7 } from "roc-db";
251
+ import { Query as Query8, QueryChain as QueryChain3, writeOperation as writeOperation8 } from "roc-db";
239
252
 
240
253
  // src/schemas/DeleteBlockMutationSchema.ts
241
- import { mutationSchemaGenerator as mutationSchemaGenerator10 } from "roc-db";
242
- import { z as z15 } from "zod";
243
- var DeleteBlockMutationSchema = mutationSchemaGenerator10("deleteBlock", z15.union([BlockParagraphRefSchema, BlockImageRefSchema]));
254
+ import { mutationSchemaGenerator as mutationSchemaGenerator11 } from "roc-db";
255
+ import { z as z16 } from "zod";
256
+ var DeleteBlockMutationSchema = mutationSchemaGenerator11("deleteBlock", z16.union([BlockParagraphRefSchema, BlockImageRefSchema]));
244
257
 
245
258
  // src/operations/deleteBlock.ts
246
- var deleteBlock = writeOperation7(DeleteBlockMutationSchema, PostSchema, (txn) => {
259
+ var deleteBlock = writeOperation8(DeleteBlockMutationSchema, PostSchema, (txn) => {
247
260
  const blockRef = txn.payload;
248
- return QueryChain3(Query7(() => txn.readEntity(blockRef, true)), Query7((block) => txn.readEntity(block.parents.post, true)), Query7((post) => {
261
+ return QueryChain3(Query8(() => txn.readEntity(blockRef, true)), Query8((block) => txn.readEntity(block.parents.post, true)), Query8((post) => {
249
262
  return txn.patchEntity(post.ref, {
250
263
  data: {
251
264
  blockRefs: post.data.blockRefs.filter((ref) => ref !== blockRef)
252
265
  }
253
266
  });
254
- }), Query7(() => txn.deleteEntity(blockRef)), Query7((_, updatedPost) => {
267
+ }), Query8(() => txn.deleteEntity(blockRef)), Query8((_, updatedPost) => {
255
268
  return updatedPost;
256
269
  }));
257
270
  }, { changeSetOnly: true });
258
271
 
259
272
  // src/operations/deletePost.ts
260
- import { Query as Query8, writeOperation as writeOperation8 } from "roc-db";
273
+ import { Query as Query9, writeOperation as writeOperation9 } from "roc-db";
261
274
 
262
275
  // src/schemas/DeletePostMutationSchema.ts
263
- import { mutationSchemaGenerator as mutationSchemaGenerator11 } from "roc-db";
264
- var DeletePostMutationSchema = mutationSchemaGenerator11("deletePost", PostRefSchema);
276
+ import { mutationSchemaGenerator as mutationSchemaGenerator12 } from "roc-db";
277
+ var DeletePostMutationSchema = mutationSchemaGenerator12("deletePost", PostRefSchema);
265
278
 
266
279
  // src/operations/deletePost.ts
267
- var deletePost = writeOperation8(DeletePostMutationSchema, undefined, (txn) => {
280
+ var deletePost = writeOperation9(DeletePostMutationSchema, undefined, (txn) => {
268
281
  const ref = txn.payload;
269
- return Query8(() => txn.deleteEntity(ref, true));
282
+ return Query9(() => txn.deleteEntity(ref, true));
270
283
  });
271
284
 
272
285
  // src/operations/readEntity.ts
273
- import { NotFoundError, Query as Query9, QueryChain as QueryChain4, readOperation } from "roc-db";
274
- import { z as z16 } from "zod";
275
- var readEntity = readOperation("readEntity", z16.string(), z16.union([PostSchema, BlockImageSchema, BlockParagraphSchema]), (txn) => {
286
+ import { NotFoundError, Query as Query10, QueryChain as QueryChain4, readOperation } from "roc-db";
287
+ import { z as z17 } from "zod";
288
+ var readEntity = readOperation("readEntity", z17.string(), z17.union([PostSchema, BlockImageSchema, BlockParagraphSchema]), (txn) => {
276
289
  const ref = txn.payload;
277
- return QueryChain4(Query9(() => txn.readEntity(ref)), Query9((entity) => {
290
+ return QueryChain4(Query10(() => txn.readEntity(ref)), Query10((entity) => {
278
291
  if (!entity) {
279
292
  throw new NotFoundError(ref);
280
293
  }
@@ -283,36 +296,36 @@ var readEntity = readOperation("readEntity", z16.string(), z16.union([PostSchema
283
296
  });
284
297
 
285
298
  // src/operations/readPost.ts
286
- import { Query as Query10, readOperation as readOperation2 } from "roc-db";
299
+ import { Query as Query11, readOperation as readOperation2 } from "roc-db";
287
300
  var readPost = readOperation2("readPost", PostRefSchema, PostSchema, (txn) => {
288
301
  const ref = txn.payload;
289
- return Query10(() => txn.readEntity(ref));
302
+ return Query11(() => txn.readEntity(ref));
290
303
  });
291
304
 
292
305
  // src/operations/updateBlockParagraph.ts
293
- import { Query as Query11, writeOperation as writeOperation9 } from "roc-db";
306
+ import { Query as Query12, writeOperation as writeOperation10 } from "roc-db";
294
307
 
295
308
  // src/schemas/UpdateBlockParagraphMutationSchema.ts
296
- import { mutationSchemaGenerator as mutationSchemaGenerator12 } from "roc-db";
297
- import { z as z17 } from "zod";
298
- var UpdateBlockParagraphMutationSchema = mutationSchemaGenerator12("updateBlockParagraph", z17.object({
309
+ import { mutationSchemaGenerator as mutationSchemaGenerator13 } from "roc-db";
310
+ import { z as z18 } from "zod";
311
+ var UpdateBlockParagraphMutationSchema = mutationSchemaGenerator13("updateBlockParagraph", z18.object({
299
312
  ref: BlockParagraphRefSchema,
300
- content: z17.string()
313
+ content: z18.string()
301
314
  }));
302
315
 
303
316
  // src/operations/updateBlockParagraph.ts
304
- var updateBlockParagraph = writeOperation9(UpdateBlockParagraphMutationSchema, BlockParagraphRefSchema, (txn) => {
317
+ var updateBlockParagraph = writeOperation10(UpdateBlockParagraphMutationSchema, BlockParagraphRefSchema, (txn) => {
305
318
  const { ref, content } = txn.payload;
306
- return Query11(() => txn.patchEntity(ref, {
319
+ return Query12(() => txn.patchEntity(ref, {
307
320
  data: { content }
308
321
  }));
309
322
  });
310
323
 
311
324
  // src/operations/updatePost.ts
312
- import { Query as Query12, writeOperation as writeOperation10 } from "roc-db";
313
- var updatePost = writeOperation10(UpdatePostMutationSchema, PostSchema, (txn) => {
325
+ import { Query as Query13, writeOperation as writeOperation11 } from "roc-db";
326
+ var updatePost = writeOperation11(UpdatePostMutationSchema, PostSchema, (txn) => {
314
327
  const { ref, authorRef, ...data } = txn.payload;
315
- return Query12(() => txn.updateEntity(ref, {
328
+ return Query13(() => txn.updateEntity(ref, {
316
329
  data,
317
330
  parents: { author: authorRef },
318
331
  children: { blocks: [] }
@@ -320,14 +333,15 @@ var updatePost = writeOperation10(UpdatePostMutationSchema, PostSchema, (txn) =>
320
333
  });
321
334
 
322
335
  // src/operations/updatePostTitle.ts
323
- import { Query as Query13, writeOperation as writeOperation11 } from "roc-db";
324
- var updatePostTitle = writeOperation11(UpdatePostTitleMutationSchema, PostSchema, (txn) => {
336
+ import { Query as Query14, writeOperation as writeOperation12 } from "roc-db";
337
+ var updatePostTitle = writeOperation12(UpdatePostTitleMutationSchema, PostSchema, (txn) => {
325
338
  const { ref, title } = txn.payload;
326
- return Query13(() => txn.patchEntity(ref, { data: { title } }));
339
+ return Query14(() => txn.patchEntity(ref, { data: { title } }));
327
340
  }, { debounce: 10 });
328
341
 
329
342
  // src/operations/index.ts
330
343
  var operations = [
344
+ applyDraft,
331
345
  createBlockImage,
332
346
  createBlockTitle,
333
347
  createBlockParagrah,
@@ -344,7 +358,7 @@ var operations = [
344
358
  ];
345
359
  // src/testAdapterImplementation.ts
346
360
  import { beforeAll, describe, expect, test } from "bun:test";
347
- import { NotFoundError as NotFoundError2 } from "roc-db";
361
+ import { BadRequestError, NotFoundError as NotFoundError2 } from "roc-db";
348
362
  var prepareChangeSetTest = async (adapter) => {
349
363
  const [post] = await adapter.createPost({
350
364
  title: "Title 1",
@@ -376,56 +390,135 @@ var prepareChangeSetTest = async (adapter) => {
376
390
  };
377
391
  var testAdapterImplementation = (adapterConstructor, engineArgsAdapter1 = {}, engineArgsAdapter2 = {}) => {
378
392
  return async () => {
379
- const adapter1 = adapterConstructor({ operations, entities, ...engineArgsAdapter1 });
380
- const adapter2 = adapterConstructor({ operations, entities, ...engineArgsAdapter2 });
393
+ const adapter1 = adapterConstructor({
394
+ operations,
395
+ entities,
396
+ session: { identityRef: "User/42" },
397
+ ...engineArgsAdapter1
398
+ });
399
+ const adapter2 = adapterConstructor({
400
+ operations,
401
+ entities,
402
+ session: { identityRef: "User/42" },
403
+ ...engineArgsAdapter2
404
+ });
405
+ describe("Post CRUD", async () => {
406
+ let postRef;
407
+ let post;
408
+ let createPostMutation;
409
+ beforeAll(async () => {
410
+ const createPostRes = await adapter1.createPost({
411
+ title: "Title 1",
412
+ slug: "title-1",
413
+ tags: ["Foo", "Bar"]
414
+ });
415
+ post = createPostRes[0];
416
+ postRef = createPostRes[0].ref;
417
+ createPostMutation = createPostRes[1];
418
+ });
419
+ test("create (createEntity function)", async () => {
420
+ expect(post).toMatchZodSchema(PostSchema);
421
+ expect(post.data.title).toBe("Title 1");
422
+ expect(post.data.tags).toStrictEqual(["Foo", "Bar"]);
423
+ });
424
+ test("read (readEntity function)", async () => {
425
+ const readPostRes = await adapter1.readPost(postRef);
426
+ expect(readPostRes.data.title).toStrictEqual("Title 1");
427
+ expect(readPostRes.data.tags).toStrictEqual(["Foo", "Bar"]);
428
+ expect(readPostRes).toMatchZodSchema(PostSchema);
429
+ });
430
+ test("update (updateEntity function)", async () => {
431
+ const [post2] = await adapter1.updatePost({
432
+ ref: postRef,
433
+ title: "Title 2",
434
+ tags: ["Foo"]
435
+ });
436
+ expect(post2.data.tags).toStrictEqual(["Foo"]);
437
+ expect(post2.data.title).toBe("Title 2");
438
+ expect(post2).toMatchZodSchema(PostSchema);
439
+ });
440
+ test("updateTitle (patchEntity function + debounce)", async () => {
441
+ const updatePostTitleRes1 = await adapter1.updatePostTitle({
442
+ ref: postRef,
443
+ title: "Title 3"
444
+ });
445
+ expect(updatePostTitleRes1[0]).toMatchZodSchema(PostSchema);
446
+ const updatePostTitleRes2 = await adapter1.updatePostTitle({
447
+ ref: postRef,
448
+ title: "Title 4"
449
+ });
450
+ expect(updatePostTitleRes2[0]).toMatchZodSchema(PostSchema);
451
+ expect(updatePostTitleRes2[1].ref).toBe(updatePostTitleRes1[1].ref);
452
+ expect(updatePostTitleRes2[1].timestamp >= updatePostTitleRes1[1].timestamp).toBeTrue();
453
+ });
454
+ test("delete (deleteEntity function)", async () => {
455
+ const [count, mutation] = await adapter1.deletePost(postRef);
456
+ expect(count).toBe(1);
457
+ expect(mutation.log).toStrictEqual([[postRef, "delete", null]]);
458
+ });
459
+ test("sync mutation", async () => {
460
+ const res = await adapter2.syncOptimisticMutation(createPostMutation);
461
+ expect(res[0]).toStrictEqual(post);
462
+ expect(res[1]).toStrictEqual(createPostMutation);
463
+ expect(() => adapter2.syncOptimisticMutation(createPostMutation)).toThrowError(BadRequestError);
464
+ });
465
+ });
381
466
  describe("changeSet", async () => {
382
- let postRef, draftRef, changeSetAdapter, block, post, blockRow, blockParagraph2;
467
+ let postRef, draftRef, changeSetAdapter, blockParagraph1, post, blockRow, blockParagraph2;
383
468
  beforeAll(async () => {
384
- const res = await prepareChangeSetTest(adapter1);
385
- postRef = res.postRef;
386
- draftRef = res.draftRef;
387
- changeSetAdapter = res.changeSetAdapter;
388
- block = res.blockParagraph1;
389
- blockRow = res.blockRow;
390
- blockParagraph2 = res.blockParagraph2;
391
- post = res.post;
469
+ ({
470
+ postRef,
471
+ draftRef,
472
+ changeSetAdapter,
473
+ blockParagraph1,
474
+ post,
475
+ blockRow,
476
+ blockParagraph2
477
+ } = await prepareChangeSetTest(adapter1));
392
478
  });
393
479
  test("create (createEntity function w/changeSetRef)", async () => {
394
- expect(block).toMatchZodSchema(BlockParagraphSchema);
480
+ expect(blockParagraph1).toMatchZodSchema(BlockParagraphSchema);
395
481
  expect(post).toMatchZodSchema(PostSchema);
396
482
  });
397
483
  test("read (readEntity function w/changeSetRef)", async () => {
398
- const read = await changeSetAdapter.readEntity(block.ref);
484
+ const read = await changeSetAdapter.readEntity(blockParagraph1.ref);
399
485
  expect(read).toMatchZodSchema(BlockParagraphSchema);
400
486
  });
487
+ test("update (patchEntity function w/changeSetRef)", async () => {
488
+ const [updatedBlock] = await changeSetAdapter.updateBlockParagraph({
489
+ ref: blockParagraph1.ref,
490
+ content: "Hello, world!"
491
+ });
492
+ expect(updatedBlock).toMatchZodSchema(BlockParagraphSchema);
493
+ });
401
494
  test("delete (with cascade delete)", async () => {
402
495
  const [count, mutation] = await changeSetAdapter.deletePost(postRef);
403
496
  expect(count).toBe(4);
404
497
  expect(mutation.log).toStrictEqual([
405
- [block.ref, "delete", draftRef],
406
- [blockRow.ref, "delete", draftRef],
498
+ [blockParagraph1.ref, "delete", draftRef],
407
499
  [blockParagraph2.ref, "delete", draftRef],
500
+ [blockRow.ref, "delete", draftRef],
408
501
  [postRef, "delete", draftRef]
409
502
  ]);
503
+ await expect(() => changeSetAdapter.readEntity(blockParagraph1.ref)).toThrow(NotFoundError2);
504
+ await expect(() => changeSetAdapter.updateBlockParagraph({
505
+ ref: blockParagraph1.ref,
506
+ content: "Foo"
507
+ })).toThrow(NotFoundError2);
410
508
  });
411
- test("update (patchEntity function w/changeSetRef)", async () => {
412
- const [updatedBlock] = await changeSetAdapter.updateBlockParagraph({
413
- ref: block.ref,
414
- content: "Hello, world!"
509
+ test("pageMutations", async () => {
510
+ const res = await changeSetAdapter.pageMutations({
511
+ changeSetRef: draftRef
415
512
  });
416
- expect(updatedBlock).toMatchZodSchema(BlockParagraphSchema);
513
+ expect(res.length).toBeGreaterThan(0);
514
+ expect(res.every((m) => m.changeSetRef === draftRef)).toBeTrue();
417
515
  });
418
- test.skip("delete (deleteEntity function w/changeSetRef)", async () => {
419
- const [updatedBlock, deleteMutation] = await changeSetAdapter.deleteBlock(block.ref);
420
- expect(deleteMutation.log).toStrictEqual([
421
- [postRef, "update", draftRef],
422
- [block.ref, "delete", draftRef]
423
- ]);
424
- expect(() => changeSetAdapter.readEntity(block.ref)).toThrow(NotFoundError2);
425
- expect(() => changeSetAdapter.updateBlockParagraph({
426
- ref: block.ref,
427
- content: "Foo"
428
- })).toThrow(NotFoundError2);
516
+ test("pageMutations2", async () => {
517
+ const res = await changeSetAdapter.pageMutations({
518
+ changeSetRef: draftRef
519
+ });
520
+ expect(res.length).toBeGreaterThan(0);
521
+ expect(res.every((m) => m.changeSetRef === draftRef)).toBeTrue();
429
522
  });
430
523
  });
431
524
  };
@@ -434,7 +527,10 @@ var testAdapterImplementation = (adapterConstructor, engineArgsAdapter1 = {}, en
434
527
  import { createInMemoryAdapter } from "@roc-db/in-memory";
435
528
  var inMemoryAdapter = createInMemoryAdapter({
436
529
  operations,
437
- entities
530
+ entities,
531
+ session: {
532
+ identityRef: "User/42"
533
+ }
438
534
  });
439
535
  export {
440
536
  testAdapterImplementation,
@@ -1,4 +1,4 @@
1
1
  export * from "./schemas";
2
- export * from "./operations";
2
+ export { operations } from "./operations";
3
3
  export { testAdapterImplementation } from "./testAdapterImplementation";
4
4
  export { inMemoryAdapter } from "./inMemoryAdapter";
@@ -0,0 +1,13 @@
1
+ export declare const applyDraft: import("roc-db").WriteOperation<"applyDraft", {
2
+ ref: `Mutation/${string}`;
3
+ timestamp: string;
4
+ changeSetRef: null;
5
+ payload: {
6
+ ref: `Draft/${string}`;
7
+ };
8
+ log: [never, string, null][];
9
+ debounceCount: number;
10
+ name: "applyDraft";
11
+ }, {
12
+ ref: `Draft/${string}`;
13
+ }, any>;
@@ -1,4 +1,16 @@
1
- export declare const operations: readonly [import("roc-db").WriteOperation<"createBlockImage", {
1
+ export declare const operations: readonly [import("roc-db").WriteOperation<"applyDraft", {
2
+ ref: `Mutation/${string}`;
3
+ timestamp: string;
4
+ changeSetRef: null;
5
+ payload: {
6
+ ref: `Draft/${string}`;
7
+ };
8
+ log: [never, string, null][];
9
+ debounceCount: number;
10
+ name: "applyDraft";
11
+ }, {
12
+ ref: `Draft/${string}`;
13
+ }, any>, import("roc-db").WriteOperation<"createBlockImage", {
2
14
  ref: `Mutation/${string}`;
3
15
  timestamp: string;
4
16
  changeSetRef: null;
@@ -0,0 +1,40 @@
1
+ import { z } from "zod";
2
+ export declare const ApplyDraftMutationSchema: 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
+ }, {
10
+ name: z.ZodLiteral<"applyDraft">;
11
+ changeSetRef: z.ZodType<never, z.ZodTypeDef, never> | z.ZodNullable<z.ZodType<never, z.ZodTypeDef, never>>;
12
+ payload: z.ZodObject<{
13
+ ref: z.ZodType<`Draft/${string}`, z.ZodTypeDef, `Draft/${string}`>;
14
+ }, "strict", z.ZodTypeAny, {
15
+ ref: `Draft/${string}`;
16
+ }, {
17
+ ref: `Draft/${string}`;
18
+ }>;
19
+ log: z.ZodType<[never, string, null][], z.ZodTypeDef, [never, string, null][]>;
20
+ }>, "strict", z.ZodTypeAny, {
21
+ ref: `Mutation/${string}`;
22
+ timestamp: string;
23
+ changeSetRef: null;
24
+ payload: {
25
+ ref: `Draft/${string}`;
26
+ };
27
+ log: [never, string, null][];
28
+ debounceCount: number;
29
+ name: "applyDraft";
30
+ }, {
31
+ ref: `Mutation/${string}`;
32
+ timestamp: string;
33
+ changeSetRef: null;
34
+ payload: {
35
+ ref: `Draft/${string}`;
36
+ };
37
+ log: [never, string, null][];
38
+ debounceCount: number;
39
+ name: "applyDraft";
40
+ }>;
@@ -30,3 +30,4 @@ export declare const BlockParagraphSchema: z.ZodObject<z.objectUtil.extendShape<
30
30
  }, {
31
31
  [x: string]: any;
32
32
  }>;
33
+ export type BlockParagraph = z.infer<typeof BlockParagraphSchema>;
@@ -0,0 +1,2 @@
1
+ import { z } from "zod";
2
+ export declare const BlockRefSchema: z.ZodUnion<[z.ZodType<`BlockParagraph/${string}`, z.ZodTypeDef, `BlockParagraph/${string}`>, z.ZodType<`BlockRow/${string}`, z.ZodTypeDef, `BlockRow/${string}`>]>;
@@ -0,0 +1,33 @@
1
+ import { z } from "zod";
2
+ export declare const BlockRowSchema: z.ZodObject<z.objectUtil.extendShape<{
3
+ ref: z.ZodType<never, z.ZodTypeDef, never>;
4
+ entity: z.ZodString;
5
+ created: z.ZodObject<{
6
+ mutationRef: z.ZodType<`Mutation/${string}`, z.ZodTypeDef, `Mutation/${string}`>;
7
+ timestamp: z.ZodString;
8
+ }, "strict", z.ZodTypeAny, {
9
+ mutationRef: `Mutation/${string}`;
10
+ timestamp: string;
11
+ }, {
12
+ mutationRef: `Mutation/${string}`;
13
+ timestamp: string;
14
+ }>;
15
+ updated: z.ZodObject<{
16
+ mutationRef: z.ZodType<`Mutation/${string}`, z.ZodTypeDef, `Mutation/${string}`>;
17
+ timestamp: z.ZodString;
18
+ }, "strict", z.ZodTypeAny, {
19
+ mutationRef: `Mutation/${string}`;
20
+ timestamp: string;
21
+ }, {
22
+ mutationRef: `Mutation/${string}`;
23
+ timestamp: string;
24
+ }>;
25
+ data: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
26
+ parents: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
27
+ ancestors: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
28
+ }, z.ZodRawShape>, "strict", z.ZodTypeAny, {
29
+ [x: string]: any;
30
+ }, {
31
+ [x: string]: any;
32
+ }>;
33
+ export type BlockRow = z.infer<typeof BlockRowSchema>;
@@ -30,3 +30,4 @@ export declare const PostSchema: z.ZodObject<z.objectUtil.extendShape<{
30
30
  }, {
31
31
  [x: string]: any;
32
32
  }>;
33
+ export type Post = z.infer<typeof PostSchema>;
package/package.json CHANGED
@@ -1,30 +1,23 @@
1
1
  {
2
2
  "name": "@roc-db/test-utils",
3
- "version": "0.2.0-pre.2",
3
+ "version": "0.2.0-pre.20",
4
4
  "type": "module",
5
5
  "exports": {
6
- ".": "./src/index.ts",
7
- "./setup": "./src/setup/index.ts"
6
+ ".": {
7
+ "import": "./dist/index.js",
8
+ "types": "./dist/types/index.d.ts"
9
+ },
10
+ "./setup": {
11
+ "import": "./dist/setup/index.js",
12
+ "types": "./dist/types/setup/index.d.ts"
13
+ }
8
14
  },
9
15
  "files": [
10
16
  "dist"
11
17
  ],
12
18
  "sideEffects": false,
13
- "scripts": {
14
- "build": "NODE_ENV=production bun run scripts/build.ts",
15
- "build:types": "rm -rf dist/types && bun run tsc --noCheck",
16
- "test": "echo"
17
- },
18
- "devDependencies": {
19
- "@faker-js/faker": "9.6.0",
20
- "@types/bun": "1.2.5",
21
- "@types/sanitize-html": "2.13.0",
22
- "bun": "1.2.5",
23
- "expect-type": "1.2.0",
24
- "roc-db": "0.2.0-pre.2"
25
- },
26
19
  "peerDependencies": {
27
- "roc-db": "0.2.0-pre.2",
20
+ "roc-db": "0.2.0-pre.20",
28
21
  "zod": "3.24.2"
29
22
  },
30
23
  "keywords": [],