@deessejs/collections 0.0.18 → 0.0.19
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.
|
@@ -20,4 +20,10 @@ export type Collection<Slug extends string = string, Fields extends Record<strin
|
|
|
20
20
|
};
|
|
21
21
|
fields: Fields;
|
|
22
22
|
hooks?: CollectionHooks;
|
|
23
|
+
permissions?: {
|
|
24
|
+
create?: (ctx: any) => Promise<boolean>;
|
|
25
|
+
read?: (ctx: any) => Promise<boolean>;
|
|
26
|
+
update?: (ctx: any) => Promise<boolean>;
|
|
27
|
+
delete?: (ctx: any) => Promise<boolean>;
|
|
28
|
+
};
|
|
23
29
|
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Field, FieldChain, FieldTypeFinal } from "./types";
|
|
2
|
+
export declare const unique: <TType extends FieldTypeFinal>(field: Field<TType>) => Field<TType>;
|
|
3
|
+
export declare const required: <TType extends FieldTypeFinal>(field: Field<TType>) => Field<TType>;
|
|
4
|
+
export declare const optional: <TType extends FieldTypeFinal>(field: Field<TType>) => Field<TType>;
|
|
5
|
+
export declare const attachChain: <TType extends FieldTypeFinal>(f: Field<TType>) => FieldChain<TType>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.attachChain = exports.optional = exports.required = exports.unique = void 0;
|
|
4
|
+
const unique = (field) => {
|
|
5
|
+
return {
|
|
6
|
+
...field,
|
|
7
|
+
type: {
|
|
8
|
+
...field.type,
|
|
9
|
+
dsl: {
|
|
10
|
+
...field.type.dsl,
|
|
11
|
+
isUnique: true,
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
exports.unique = unique;
|
|
17
|
+
const required = (field) => ({
|
|
18
|
+
...field,
|
|
19
|
+
type: {
|
|
20
|
+
...field.type,
|
|
21
|
+
dsl: {
|
|
22
|
+
...field.type.dsl,
|
|
23
|
+
canBeNull: false,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
exports.required = required;
|
|
28
|
+
const optional = (field) => ({
|
|
29
|
+
...field,
|
|
30
|
+
type: {
|
|
31
|
+
...field.type,
|
|
32
|
+
dsl: {
|
|
33
|
+
...field.type.dsl,
|
|
34
|
+
canBeNull: true,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
exports.optional = optional;
|
|
39
|
+
const attachChain = (f) => {
|
|
40
|
+
return {
|
|
41
|
+
...f,
|
|
42
|
+
unique() {
|
|
43
|
+
return (0, exports.attachChain)((0, exports.unique)(f));
|
|
44
|
+
},
|
|
45
|
+
required() {
|
|
46
|
+
return (0, exports.attachChain)((0, exports.required)(f));
|
|
47
|
+
},
|
|
48
|
+
optional() {
|
|
49
|
+
return (0, exports.attachChain)((0, exports.optional)(f));
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
exports.attachChain = attachChain;
|
package/dist/fields/field.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
|
-
import {
|
|
2
|
+
import { 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 unique: <TType extends FieldTypeFinal>(field: Field<TType>) => Field<TType>;
|
|
5
|
-
export declare const required: <TType extends FieldTypeFinal>(field: Field<TType>) => Field<TType>;
|
|
6
|
-
export declare const optional: <TType extends FieldTypeFinal>(field: Field<TType>) => Field<TType>;
|
|
7
4
|
export declare const field: <TType extends FieldTypeFinal>(config: FieldConfig<TType>) => FieldChain<TType>;
|
package/dist/fields/field.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.field = exports.
|
|
3
|
+
exports.field = exports.fieldType = void 0;
|
|
4
|
+
const constraints_1 = require("./constraints");
|
|
4
5
|
const fieldType = (config) => (params) => {
|
|
5
6
|
const validated = config.schema ? config.schema.parse(params) : params;
|
|
6
7
|
return {
|
|
@@ -22,55 +23,6 @@ const defaultPermissions = {
|
|
|
22
23
|
update: async () => true,
|
|
23
24
|
delete: async () => true,
|
|
24
25
|
};
|
|
25
|
-
const unique = (field) => {
|
|
26
|
-
return {
|
|
27
|
-
...field,
|
|
28
|
-
type: {
|
|
29
|
-
...field.type,
|
|
30
|
-
dsl: {
|
|
31
|
-
...field.type.dsl,
|
|
32
|
-
isUnique: true,
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
exports.unique = unique;
|
|
38
|
-
const required = (field) => ({
|
|
39
|
-
...field,
|
|
40
|
-
type: {
|
|
41
|
-
...field.type,
|
|
42
|
-
dsl: {
|
|
43
|
-
...field.type.dsl,
|
|
44
|
-
canBeNull: false,
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
exports.required = required;
|
|
49
|
-
const optional = (field) => ({
|
|
50
|
-
...field,
|
|
51
|
-
type: {
|
|
52
|
-
...field.type,
|
|
53
|
-
dsl: {
|
|
54
|
-
...field.type.dsl,
|
|
55
|
-
canBeNull: true,
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
exports.optional = optional;
|
|
60
|
-
const attachChain = (f) => {
|
|
61
|
-
return {
|
|
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));
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
26
|
const field = (config) => {
|
|
75
27
|
const base = {
|
|
76
28
|
type: config.type,
|
|
@@ -79,6 +31,6 @@ const field = (config) => {
|
|
|
79
31
|
...config.permissions,
|
|
80
32
|
},
|
|
81
33
|
};
|
|
82
|
-
return attachChain(base);
|
|
34
|
+
return (0, constraints_1.attachChain)(base);
|
|
83
35
|
};
|
|
84
36
|
exports.field = field;
|