@deessejs/collections 0.0.5 → 0.0.7
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/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/fields/field.d.ts +1 -1
- package/dist/fields/types.d.ts +2 -2
- package/dist/utils/union-intersection.d.ts +1 -0
- package/dist/utils/union-intersection.js +1 -0
- package/package.json +1 -1
|
@@ -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
|
},
|
package/dist/fields/field.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
2
|
import { Field, FieldConfig, FieldTypeConfig, FieldTypeFinal } from "./types";
|
|
3
3
|
export declare const fieldType: <TParams extends z.ZodType>(config: FieldTypeConfig<TParams>) => (params: z.infer<TParams>) => FieldTypeFinal<TParams>;
|
|
4
|
-
export declare const field: <TType extends
|
|
4
|
+
export declare const field: <TType extends FieldTypeFinal>(config: FieldConfig<TType>) => Field<TType>;
|
package/dist/fields/types.d.ts
CHANGED
|
@@ -26,11 +26,11 @@ export type FieldPermissions = {
|
|
|
26
26
|
update: (ctx: any) => Promise<boolean>;
|
|
27
27
|
delete: (ctx: any) => Promise<boolean>;
|
|
28
28
|
};
|
|
29
|
-
export type FieldConfig<TType extends
|
|
29
|
+
export type FieldConfig<TType extends FieldTypeFinal> = {
|
|
30
30
|
type: TType;
|
|
31
31
|
permissions?: Partial<FieldPermissions>;
|
|
32
32
|
};
|
|
33
|
-
export type Field<TType extends
|
|
33
|
+
export type Field<TType extends FieldTypeFinal = FieldTypeFinal> = {
|
|
34
34
|
type: TType;
|
|
35
35
|
permissions: FieldPermissions;
|
|
36
36
|
};
|
|
@@ -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";
|