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