@roc-db/test-utils 0.2.0-pre.60 → 0.2.0-pre.62
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 +27 -0
- package/dist/types/operations/crudBySlug.d.ts +11 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -610,6 +610,19 @@ var updatePostTitle = writeOperation19("updatePostTitle", z41.object({ ref: Post
|
|
|
610
610
|
return Query28(() => txn.patchEntity(ref, { data: { title } }));
|
|
611
611
|
}, { debounce: 10, outputSchema: PostSchema });
|
|
612
612
|
|
|
613
|
+
// src/operations/crudBySlug.ts
|
|
614
|
+
import { Query as Query29, QueryChain as QueryChain10, writeOperation as writeOperation20 } from "roc-db";
|
|
615
|
+
import { z as z42 } from "zod";
|
|
616
|
+
var crudBySlug = writeOperation20("crudBySlug", z42.object({ slug: z42.string(), newSlug: z42.string() }), (txn) => {
|
|
617
|
+
const { slug, newSlug } = txn.payload;
|
|
618
|
+
return QueryChain10(Query29(() => txn.readEntityByUniqueField("Post", "slug", slug)), Query29((post) => txn.patchEntity(post.ref, { data: { slug: newSlug } })), Query29(() => txn.readEntityByUniqueField("Post", "slug", newSlug)), Query29((post) => txn.deleteEntity(post.ref)), Query29(() => {
|
|
619
|
+
return [
|
|
620
|
+
txn.readEntityByUniqueField("Post", "slug", slug, false),
|
|
621
|
+
txn.readEntityByUniqueField("Post", "slug", newSlug, false)
|
|
622
|
+
];
|
|
623
|
+
}));
|
|
624
|
+
});
|
|
625
|
+
|
|
613
626
|
// src/operations/index.ts
|
|
614
627
|
var operations = [
|
|
615
628
|
applyDraft,
|
|
@@ -620,6 +633,7 @@ var operations = [
|
|
|
620
633
|
createDraft,
|
|
621
634
|
createPost,
|
|
622
635
|
createUser,
|
|
636
|
+
crudBySlug,
|
|
623
637
|
deleteBlocks,
|
|
624
638
|
deleteDraft,
|
|
625
639
|
deletePost,
|
|
@@ -769,6 +783,19 @@ var testAdapterImplementation = async (adapterConstructor, generateArgs) => {
|
|
|
769
783
|
const readPostRes2 = await adapter1.readPostBySlug(slug2);
|
|
770
784
|
expect2(readPostRes2.data.slug).toStrictEqual(slug2);
|
|
771
785
|
});
|
|
786
|
+
test("update and delete post by slug", async () => {
|
|
787
|
+
const slug1 = faker.lorem.slug(5);
|
|
788
|
+
const slug2 = faker.lorem.slug(5);
|
|
789
|
+
const [post2] = await adapter1.createPost({
|
|
790
|
+
title: "Title 1",
|
|
791
|
+
slug: slug1
|
|
792
|
+
});
|
|
793
|
+
const [res] = await adapter1.crudBySlug({
|
|
794
|
+
slug: slug1,
|
|
795
|
+
newSlug: slug2
|
|
796
|
+
});
|
|
797
|
+
expect2(res).toStrictEqual([null, null]);
|
|
798
|
+
});
|
|
772
799
|
test("update index entries", async () => {
|
|
773
800
|
const [post2] = await adapter1.createPost({
|
|
774
801
|
title: "Title 1",
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const crudBySlug: import("roc-db").WriteOperation<"crudBySlug", z.ZodObject<{
|
|
3
|
+
slug: z.ZodString;
|
|
4
|
+
newSlug: z.ZodString;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
slug: string;
|
|
7
|
+
newSlug: string;
|
|
8
|
+
}, {
|
|
9
|
+
slug: string;
|
|
10
|
+
newSlug: string;
|
|
11
|
+
}>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@roc-db/test-utils",
|
|
3
|
-
"version": "0.2.0-pre.
|
|
3
|
+
"version": "0.2.0-pre.62",
|
|
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
|
+
"roc-db": "0.2.0-pre.62",
|
|
21
21
|
"zod": "3.24.2"
|
|
22
22
|
},
|
|
23
23
|
"keywords": [],
|