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

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.
Files changed (2) hide show
  1. package/dist/index.js +26 -11
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -129,7 +129,7 @@ var entities = [
129
129
  PostSchema
130
130
  ];
131
131
  // src/operations/applyDraft.ts
132
- import { Query, writeOperation } from "roc-db";
132
+ import { Query, QueryChain, writeOperation } from "roc-db";
133
133
 
134
134
  // src/schemas/ApplyDraftMutationSchema.ts
135
135
  import { mutationSchemaGenerator as mutationSchemaGenerator5 } from "roc-db";
@@ -139,7 +139,14 @@ var ApplyDraftMutationSchema = mutationSchemaGenerator5("applyDraft", z10.object
139
139
  // src/operations/applyDraft.ts
140
140
  var applyDraft = writeOperation(ApplyDraftMutationSchema, undefined, (txn) => {
141
141
  const { ref } = txn.payload;
142
- return Query(() => txn.applyChangeSet(ref));
142
+ const versionRef = txn.createRef("PostVersion");
143
+ return QueryChain(Query(() => txn.applyChangeSet(ref)), Query(() => txn.patchEntity(ref, {
144
+ data: { appliedAt: txn.mutation.timestamp }
145
+ })), Query((draft) => txn.childRefsOf(draft.parents.post, true)), Query((childRefs, draft) => txn.batchReadEntities([draft.parents.post, ...childRefs])), Query((childEntities) => txn.createEntity(versionRef, {
146
+ data: {
147
+ snapshot: childEntities
148
+ }
149
+ })));
143
150
  });
144
151
 
145
152
  // src/operations/createBlockImage.ts
@@ -158,7 +165,7 @@ var createBlockImage = writeOperation2(CreateBlockImageMutationSchema, BlockImag
158
165
  }, { changeSetOnly: true });
159
166
 
160
167
  // src/operations/createBlockParagraph.ts
161
- import { Query as Query3, QueryChain, writeOperation as writeOperation3 } from "roc-db";
168
+ import { Query as Query3, QueryChain as QueryChain2, writeOperation as writeOperation3 } from "roc-db";
162
169
 
163
170
  // src/schemas/CreateBlockParagraphMutationSchema.ts
164
171
  import { mutationSchemaGenerator as mutationSchemaGenerator7 } from "roc-db";
@@ -175,13 +182,13 @@ var CreateBlockParagraphMutationSchema = mutationSchemaGenerator7("createBlockPa
175
182
  var createBlockParagrah = writeOperation3(CreateBlockParagraphMutationSchema, BlockParagraphSchema, (txn) => {
176
183
  const ref = txn.createRef("BlockParagraph");
177
184
  const { parentRef } = txn.payload;
178
- return QueryChain(Query3(() => txn.readEntity(parentRef, true)), Query3((parent) => txn.patchEntity(parentRef, {
185
+ return QueryChain2(Query3(() => txn.readEntity(parentRef, true)), Query3((parent) => txn.patchEntity(parentRef, {
179
186
  children: { blocks: [...parent.children.blocks, ref] }
180
187
  })), Query3(() => txn.createEntity(ref, { parents: { parent: parentRef } })), Query3((block, updatedParent) => ({ block, updatedParent })));
181
188
  }, { changeSetOnly: true });
182
189
 
183
190
  // src/operations/createBlockRow.ts
184
- import { Query as Query4, QueryChain as QueryChain2, writeOperation as writeOperation4 } from "roc-db";
191
+ import { Query as Query4, QueryChain as QueryChain3, writeOperation as writeOperation4 } from "roc-db";
185
192
 
186
193
  // src/schemas/CreateBlockRowMutationSchema.ts
187
194
  import { mutationSchemaGenerator as mutationSchemaGenerator8 } from "roc-db";
@@ -192,7 +199,7 @@ var CreateBlockRowMutationSchema = mutationSchemaGenerator8("createBlockRow", z1
192
199
  var createBlockRow = writeOperation4(CreateBlockRowMutationSchema, BlockParagraphSchema, (txn) => {
193
200
  const ref = txn.createRef("BlockRow");
194
201
  const { parentRef } = txn.payload;
195
- return QueryChain2(Query4(() => txn.readEntity(parentRef)), Query4((parent) => {
202
+ return QueryChain3(Query4(() => txn.readEntity(parentRef)), Query4((parent) => {
196
203
  return txn.patchEntity(parentRef, {
197
204
  children: { blocks: [...parent.children.blocks, ref] }
198
205
  });
@@ -248,7 +255,7 @@ var createPost = writeOperation7(CreatePostMutationSchema, PostSchema, (txn) =>
248
255
  });
249
256
 
250
257
  // src/operations/deleteBlock.ts
251
- import { Query as Query8, QueryChain as QueryChain3, writeOperation as writeOperation8 } from "roc-db";
258
+ import { Query as Query8, QueryChain as QueryChain4, writeOperation as writeOperation8 } from "roc-db";
252
259
 
253
260
  // src/schemas/DeleteBlockMutationSchema.ts
254
261
  import { mutationSchemaGenerator as mutationSchemaGenerator11 } from "roc-db";
@@ -258,7 +265,7 @@ var DeleteBlockMutationSchema = mutationSchemaGenerator11("deleteBlock", z16.uni
258
265
  // src/operations/deleteBlock.ts
259
266
  var deleteBlock = writeOperation8(DeleteBlockMutationSchema, PostSchema, (txn) => {
260
267
  const blockRef = txn.payload;
261
- return QueryChain3(Query8(() => txn.readEntity(blockRef, true)), Query8((block) => txn.readEntity(block.parents.post, true)), Query8((post) => {
268
+ return QueryChain4(Query8(() => txn.readEntity(blockRef, true)), Query8((block) => txn.readEntity(block.parents.post, true)), Query8((post) => {
262
269
  return txn.patchEntity(post.ref, {
263
270
  data: {
264
271
  blockRefs: post.data.blockRefs.filter((ref) => ref !== blockRef)
@@ -283,11 +290,11 @@ var deletePost = writeOperation9(DeletePostMutationSchema, undefined, (txn) => {
283
290
  });
284
291
 
285
292
  // src/operations/readEntity.ts
286
- import { NotFoundError, Query as Query10, QueryChain as QueryChain4, readOperation } from "roc-db";
293
+ import { NotFoundError, Query as Query10, QueryChain as QueryChain5, readOperation } from "roc-db";
287
294
  import { z as z17 } from "zod";
288
295
  var readEntity = readOperation("readEntity", z17.string(), z17.union([PostSchema, BlockImageSchema, BlockParagraphSchema]), (txn) => {
289
296
  const ref = txn.payload;
290
- return QueryChain4(Query10(() => txn.readEntity(ref)), Query10((entity) => {
297
+ return QueryChain5(Query10(() => txn.readEntity(ref)), Query10((entity) => {
291
298
  if (!entity) {
292
299
  throw new NotFoundError(ref);
293
300
  }
@@ -513,13 +520,21 @@ var testAdapterImplementation = (adapterConstructor, engineArgsAdapter1 = {}, en
513
520
  expect(res.length).toBeGreaterThan(0);
514
521
  expect(res.every((m) => m.changeSetRef === draftRef)).toBeTrue();
515
522
  });
516
- test("pageMutations2", async () => {
523
+ test("pageMutations run again", async () => {
517
524
  const res = await changeSetAdapter.pageMutations({
518
525
  changeSetRef: draftRef
519
526
  });
520
527
  expect(res.length).toBeGreaterThan(0);
521
528
  expect(res.every((m) => m.changeSetRef === draftRef)).toBeTrue();
522
529
  });
530
+ describe("create and apply draft", () => {
531
+ test("applyDraft", async () => {
532
+ const { draftRef: draftRef2 } = await prepareChangeSetTest(adapter1);
533
+ const [version, mutation] = await adapter1.applyDraft({
534
+ ref: draftRef2
535
+ });
536
+ });
537
+ });
523
538
  });
524
539
  };
525
540
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roc-db/test-utils",
3
- "version": "0.2.0-pre.20",
3
+ "version": "0.2.0-pre.21",
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",
20
+ "roc-db": "0.2.0-pre.21",
21
21
  "zod": "3.24.2"
22
22
  },
23
23
  "keywords": [],