@deessejs/collections 0.0.6 → 0.0.8
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/collections/define.d.ts +1 -1
- package/dist/collections/define.js +3 -1
- package/dist/collections/types.d.ts +13 -0
- package/dist/config/index.d.ts +2 -2
- package/dist/config/index.js +12 -1
- package/dist/config/types.d.ts +2 -0
- package/dist/database/types.d.ts +9 -0
- package/dist/database/types.js +2 -0
- package/dist/fields/core.d.ts +7 -1
- package/dist/fields/core.js +1 -1
- package/dist/utils/union-intersection.d.ts +1 -0
- package/dist/utils/union-intersection.js +1 -0
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Collection } from "./types";
|
|
2
|
-
export declare const collection: (config: Collection) =>
|
|
2
|
+
export declare const collection: (config: Collection) => Collection;
|
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import { Field } from "../fields";
|
|
2
|
+
export type CollectionHooks = {
|
|
3
|
+
beforeCreate?: (data: any) => Promise<any>;
|
|
4
|
+
afterCreate?: (data: any) => Promise<any>;
|
|
5
|
+
beforeUpdate?: (data: any) => Promise<any>;
|
|
6
|
+
afterUpdate?: (data: any) => Promise<any>;
|
|
7
|
+
beforeDelete?: (data: any) => Promise<any>;
|
|
8
|
+
afterDelete?: (data: any) => Promise<any>;
|
|
9
|
+
beforeOperation?: (data: any) => Promise<any>;
|
|
10
|
+
afterOperation?: (data: any) => Promise<any>;
|
|
11
|
+
afterError?: (error: Error) => Promise<any>;
|
|
12
|
+
afterSuccess?: (data: any) => Promise<any>;
|
|
13
|
+
};
|
|
2
14
|
export type Collection = {
|
|
3
15
|
slug: string;
|
|
4
16
|
name?: string;
|
|
@@ -9,4 +21,5 @@ export type Collection = {
|
|
|
9
21
|
fields: {
|
|
10
22
|
[key: string]: Field;
|
|
11
23
|
};
|
|
24
|
+
hooks?: CollectionHooks;
|
|
12
25
|
};
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Config } from "./types";
|
|
2
|
-
export declare const defineConfig: (config:
|
|
1
|
+
import { Config, DbFromConfig } from "./types";
|
|
2
|
+
export declare const defineConfig: <C extends Config>(config: C) => DbFromConfig<C>;
|
package/dist/config/index.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defineConfig = void 0;
|
|
4
|
-
const defineConfig = (config) => {
|
|
4
|
+
const defineConfig = (config) => {
|
|
5
|
+
const db = {};
|
|
6
|
+
for (const col of config.collections) {
|
|
7
|
+
db[col.slug] = {
|
|
8
|
+
create: (data) => ({ ...data, id: "generated" }),
|
|
9
|
+
read: (id) => ({ id }),
|
|
10
|
+
update: (id, data) => ({ id, ...data }),
|
|
11
|
+
delete: (id) => { },
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
return db;
|
|
15
|
+
};
|
|
5
16
|
exports.defineConfig = defineConfig;
|
package/dist/config/types.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Collection } from "../collections/types";
|
|
2
|
+
import { CollectionsCrud } from "../database/types";
|
|
2
3
|
export type Config = {
|
|
3
4
|
collections: Collection[];
|
|
4
5
|
};
|
|
6
|
+
export type DbFromConfig<C extends Config> = UnionToIntersection<CollectionsCrud<C["collections"][number]>>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Collection } from "../collections/types";
|
|
2
|
+
export type CollectionsCrud<C extends Collection> = {
|
|
3
|
+
[K in C["slug"]]: {
|
|
4
|
+
create: (data: C["fields"]) => Promise<any>;
|
|
5
|
+
read: (id: string) => Promise<any>;
|
|
6
|
+
update: (id: string, data: Partial<C["fields"]>) => Promise<any>;
|
|
7
|
+
delete: (id: string) => Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
};
|
package/dist/fields/core.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
|
-
export declare const number: (params:
|
|
2
|
+
export declare const number: (params: {
|
|
3
|
+
min: number;
|
|
4
|
+
max: number;
|
|
5
|
+
}) => import("./types").FieldTypeFinal<z.ZodObject<{
|
|
6
|
+
min: z.ZodNumber;
|
|
7
|
+
max: z.ZodNumber;
|
|
8
|
+
}, z.core.$strip>>;
|
package/dist/fields/core.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.number = void 0;
|
|
|
7
7
|
const zod_1 = __importDefault(require("zod"));
|
|
8
8
|
const field_1 = require("./field");
|
|
9
9
|
exports.number = (0, field_1.fieldType)({
|
|
10
|
-
schema: zod_1.default.number(),
|
|
10
|
+
schema: zod_1.default.object({ min: zod_1.default.number(), max: zod_1.default.number() }),
|
|
11
11
|
dsl: {
|
|
12
12
|
kind: "number",
|
|
13
13
|
},
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|