@deessejs/collections 0.0.16 → 0.0.18
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/fields/field.d.ts +2 -4
- package/dist/fields/field.js +37 -52
- package/dist/fields/types.d.ts +5 -0
- package/package.json +1 -1
package/dist/fields/field.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
|
-
import { Field, FieldConfig, FieldTypeConfig, FieldTypeFinal } from "./types";
|
|
2
|
+
import { Field, FieldChain, FieldConfig, FieldTypeConfig, FieldTypeFinal } from "./types";
|
|
3
3
|
export declare const fieldType: <TOutput, TParams extends z.ZodType>(config: FieldTypeConfig<TParams>) => (params: z.infer<TParams>) => FieldTypeFinal<TParams, TOutput>;
|
|
4
|
-
export declare const field: <TType extends FieldTypeFinal>(config: FieldConfig<TType>) => Field<TType>;
|
|
5
4
|
export declare const unique: <TType extends FieldTypeFinal>(field: Field<TType>) => Field<TType>;
|
|
6
5
|
export declare const required: <TType extends FieldTypeFinal>(field: Field<TType>) => Field<TType>;
|
|
7
6
|
export declare const optional: <TType extends FieldTypeFinal>(field: Field<TType>) => Field<TType>;
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const notNullable: <TType extends FieldTypeFinal>(field: Field<TType>) => Field<TType>;
|
|
7
|
+
export declare const field: <TType extends FieldTypeFinal>(config: FieldConfig<TType>) => FieldChain<TType>;
|
package/dist/fields/field.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.field = exports.optional = exports.required = exports.unique = exports.fieldType = void 0;
|
|
4
4
|
const fieldType = (config) => (params) => {
|
|
5
5
|
const validated = config.schema ? config.schema.parse(params) : params;
|
|
6
6
|
return {
|
|
@@ -22,16 +22,6 @@ const defaultPermissions = {
|
|
|
22
22
|
update: async () => true,
|
|
23
23
|
delete: async () => true,
|
|
24
24
|
};
|
|
25
|
-
const field = (config) => {
|
|
26
|
-
return {
|
|
27
|
-
type: config.type,
|
|
28
|
-
permissions: {
|
|
29
|
-
...defaultPermissions,
|
|
30
|
-
...config.permissions,
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
exports.field = field;
|
|
35
25
|
const unique = (field) => {
|
|
36
26
|
return {
|
|
37
27
|
...field,
|
|
@@ -45,55 +35,50 @@ const unique = (field) => {
|
|
|
45
35
|
};
|
|
46
36
|
};
|
|
47
37
|
exports.unique = unique;
|
|
48
|
-
const required = (field) => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
type
|
|
52
|
-
|
|
53
|
-
dsl
|
|
54
|
-
|
|
55
|
-
canBeNull: false,
|
|
56
|
-
},
|
|
38
|
+
const required = (field) => ({
|
|
39
|
+
...field,
|
|
40
|
+
type: {
|
|
41
|
+
...field.type,
|
|
42
|
+
dsl: {
|
|
43
|
+
...field.type.dsl,
|
|
44
|
+
canBeNull: false,
|
|
57
45
|
},
|
|
58
|
-
}
|
|
59
|
-
};
|
|
46
|
+
},
|
|
47
|
+
});
|
|
60
48
|
exports.required = required;
|
|
61
|
-
const optional = (field) => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
type
|
|
65
|
-
|
|
66
|
-
dsl
|
|
67
|
-
|
|
68
|
-
canBeNull: true,
|
|
69
|
-
},
|
|
49
|
+
const optional = (field) => ({
|
|
50
|
+
...field,
|
|
51
|
+
type: {
|
|
52
|
+
...field.type,
|
|
53
|
+
dsl: {
|
|
54
|
+
...field.type.dsl,
|
|
55
|
+
canBeNull: true,
|
|
70
56
|
},
|
|
71
|
-
}
|
|
72
|
-
};
|
|
57
|
+
},
|
|
58
|
+
});
|
|
73
59
|
exports.optional = optional;
|
|
74
|
-
const
|
|
60
|
+
const attachChain = (f) => {
|
|
75
61
|
return {
|
|
76
|
-
...
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
62
|
+
...f,
|
|
63
|
+
unique() {
|
|
64
|
+
return attachChain((0, exports.unique)(f));
|
|
65
|
+
},
|
|
66
|
+
required() {
|
|
67
|
+
return attachChain((0, exports.required)(f));
|
|
68
|
+
},
|
|
69
|
+
optional() {
|
|
70
|
+
return attachChain((0, exports.optional)(f));
|
|
83
71
|
},
|
|
84
72
|
};
|
|
85
73
|
};
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
...
|
|
92
|
-
dsl: {
|
|
93
|
-
...field.type.dsl,
|
|
94
|
-
canBeNull: false,
|
|
95
|
-
},
|
|
74
|
+
const field = (config) => {
|
|
75
|
+
const base = {
|
|
76
|
+
type: config.type,
|
|
77
|
+
permissions: {
|
|
78
|
+
...defaultPermissions,
|
|
79
|
+
...config.permissions,
|
|
96
80
|
},
|
|
97
81
|
};
|
|
82
|
+
return attachChain(base);
|
|
98
83
|
};
|
|
99
|
-
exports.
|
|
84
|
+
exports.field = field;
|
package/dist/fields/types.d.ts
CHANGED
|
@@ -39,3 +39,8 @@ export type Field<TType extends FieldTypeFinal = FieldTypeFinal> = {
|
|
|
39
39
|
export type InferSchema<F extends Record<string, Field>> = {
|
|
40
40
|
[K in keyof F]: F[K] extends Field<infer FT> ? FT extends FieldTypeFinal<any, infer TVal> ? TVal : never : never;
|
|
41
41
|
};
|
|
42
|
+
export type FieldChain<TType extends FieldTypeFinal> = Field<TType> & {
|
|
43
|
+
unique(): FieldChain<TType>;
|
|
44
|
+
required(): FieldChain<TType>;
|
|
45
|
+
optional(): FieldChain<TType>;
|
|
46
|
+
};
|