@oak-digital/types-4-strapi-2 1.0.7 → 1.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/lib/readers/types/attributes.d.ts +2470 -0
- package/lib/readers/types/attributes.js +159 -0
- package/lib/readers/types/component.d.ts +855 -0
- package/lib/readers/types/component.js +11 -0
- package/lib/readers/types/content-type-reader.d.ts +16 -0
- package/lib/readers/types/content-type-reader.js +2 -0
- package/lib/readers/types/content-type.d.ts +899 -0
- package/lib/readers/types/content-type.js +16 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/writers/types/writer.d.ts +4 -0
- package/lib/writers/types/writer.js +2 -0
- package/package.json +9 -2
- package/.editorconfig +0 -9
- package/.eslintrc.json +0 -49
- package/.github/workflows/publish.yml +0 -48
- package/.prettierrc.json +0 -8
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.contentTypeAttribute = exports.isKnownAttribute = exports.attribute = exports.anyAttribute = exports.knownAttribute = exports.dynamiczoneAttribute = exports.componentAttribute = exports.relationAttribute = exports.morphOneAttribute = exports.morphToManyAttribute = exports.hasManyAttribute = exports.manyToManyAttribute = exports.manyToOneAttribute = exports.belongsToManyAttribute = exports.oneToOneAttribute = exports.hasOneAttribute = exports.baseRelationAttribute = exports.booleanAttribute = exports.mediaAttribute = exports.dateAttribute = exports.timeAttribute = exports.dateTimeAttribute = exports.dateOnlyAttribute = exports.enumAttribute = exports.numberAttribute = exports.decimalAttribute = exports.bigIntAttribute = exports.floatAttribute = exports.integerAttribute = exports.passwordAttribute = exports.jsonAttribute = exports.blocksAttribute = exports.richTextAttribute = exports.uidAttribute = exports.emailAttribute = exports.textAttribute = exports.baseAttribute = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const constants_1 = require("../../constants");
|
|
6
|
+
exports.baseAttribute = zod_1.z.object({
|
|
7
|
+
pluginOptions: zod_1.z.any().optional(),
|
|
8
|
+
required: zod_1.z.boolean().optional(),
|
|
9
|
+
[constants_1.CERTAINLY_REQUIRED_KEY]: zod_1.z.boolean().optional(),
|
|
10
|
+
});
|
|
11
|
+
exports.textAttribute = exports.baseAttribute.extend({
|
|
12
|
+
type: zod_1.z.enum(['text', 'string']),
|
|
13
|
+
});
|
|
14
|
+
exports.emailAttribute = exports.baseAttribute.extend({
|
|
15
|
+
type: zod_1.z.literal('email'),
|
|
16
|
+
});
|
|
17
|
+
exports.uidAttribute = exports.baseAttribute.extend({
|
|
18
|
+
type: zod_1.z.literal('uid'),
|
|
19
|
+
targetField: zod_1.z.string().optional(),
|
|
20
|
+
});
|
|
21
|
+
exports.richTextAttribute = exports.baseAttribute.extend({
|
|
22
|
+
type: zod_1.z.literal('richtext'),
|
|
23
|
+
});
|
|
24
|
+
exports.blocksAttribute = exports.baseAttribute.extend({
|
|
25
|
+
type: zod_1.z.literal('blocks'),
|
|
26
|
+
// TODO: fill out the rest of the fields
|
|
27
|
+
});
|
|
28
|
+
exports.jsonAttribute = exports.baseAttribute.extend({
|
|
29
|
+
type: zod_1.z.literal('json'),
|
|
30
|
+
});
|
|
31
|
+
exports.passwordAttribute = exports.baseAttribute.extend({
|
|
32
|
+
type: zod_1.z.literal('password'),
|
|
33
|
+
});
|
|
34
|
+
exports.integerAttribute = exports.baseAttribute.extend({
|
|
35
|
+
type: zod_1.z.literal('integer'),
|
|
36
|
+
});
|
|
37
|
+
exports.floatAttribute = exports.baseAttribute.extend({
|
|
38
|
+
type: zod_1.z.literal('float'),
|
|
39
|
+
});
|
|
40
|
+
exports.bigIntAttribute = exports.baseAttribute.extend({
|
|
41
|
+
type: zod_1.z.literal('biginteger'),
|
|
42
|
+
});
|
|
43
|
+
exports.decimalAttribute = exports.baseAttribute.extend({
|
|
44
|
+
type: zod_1.z.literal('decimal'),
|
|
45
|
+
});
|
|
46
|
+
exports.numberAttribute = zod_1.z.discriminatedUnion('type', [
|
|
47
|
+
exports.integerAttribute,
|
|
48
|
+
exports.floatAttribute,
|
|
49
|
+
exports.bigIntAttribute,
|
|
50
|
+
exports.decimalAttribute,
|
|
51
|
+
]);
|
|
52
|
+
exports.enumAttribute = exports.baseAttribute.extend({
|
|
53
|
+
type: zod_1.z.literal('enumeration'),
|
|
54
|
+
enum: zod_1.z.array(zod_1.z.string()),
|
|
55
|
+
});
|
|
56
|
+
exports.dateOnlyAttribute = exports.baseAttribute.extend({
|
|
57
|
+
type: zod_1.z.literal('date'),
|
|
58
|
+
});
|
|
59
|
+
exports.dateTimeAttribute = exports.baseAttribute.extend({
|
|
60
|
+
type: zod_1.z.literal('datetime'),
|
|
61
|
+
});
|
|
62
|
+
exports.timeAttribute = exports.baseAttribute.extend({
|
|
63
|
+
type: zod_1.z.literal('time'),
|
|
64
|
+
});
|
|
65
|
+
exports.dateAttribute = zod_1.z.discriminatedUnion('type', [
|
|
66
|
+
exports.dateOnlyAttribute,
|
|
67
|
+
exports.dateTimeAttribute,
|
|
68
|
+
exports.timeAttribute,
|
|
69
|
+
]);
|
|
70
|
+
exports.mediaAttribute = exports.baseAttribute.extend({
|
|
71
|
+
type: zod_1.z.literal('media'),
|
|
72
|
+
multiple: zod_1.z.boolean().optional(),
|
|
73
|
+
allowedTypes: zod_1.z
|
|
74
|
+
.array(zod_1.z.enum(['images', 'videos', 'audios', 'files']))
|
|
75
|
+
.optional()
|
|
76
|
+
.default(['images', 'videos', 'audios', 'files']),
|
|
77
|
+
});
|
|
78
|
+
exports.booleanAttribute = exports.baseAttribute.extend({
|
|
79
|
+
type: zod_1.z.literal('boolean'),
|
|
80
|
+
});
|
|
81
|
+
exports.baseRelationAttribute = exports.baseAttribute.extend({
|
|
82
|
+
type: zod_1.z.literal('relation'),
|
|
83
|
+
target: zod_1.z.string(),
|
|
84
|
+
});
|
|
85
|
+
exports.hasOneAttribute = exports.baseRelationAttribute.extend({
|
|
86
|
+
relation: zod_1.z.literal('oneToOne'),
|
|
87
|
+
});
|
|
88
|
+
exports.oneToOneAttribute = exports.baseRelationAttribute.extend({
|
|
89
|
+
relation: zod_1.z.literal('oneToOne'),
|
|
90
|
+
inversedBy: zod_1.z.string(),
|
|
91
|
+
});
|
|
92
|
+
exports.belongsToManyAttribute = exports.baseRelationAttribute.extend({
|
|
93
|
+
mappedBy: zod_1.z.string(),
|
|
94
|
+
relation: zod_1.z.literal('oneToMany'),
|
|
95
|
+
});
|
|
96
|
+
exports.manyToOneAttribute = exports.baseRelationAttribute.extend({
|
|
97
|
+
relation: zod_1.z.literal('manyToOne'),
|
|
98
|
+
inversedBy: zod_1.z.string(),
|
|
99
|
+
});
|
|
100
|
+
exports.manyToManyAttribute = exports.baseRelationAttribute.extend({
|
|
101
|
+
relation: zod_1.z.literal('manyToMany'),
|
|
102
|
+
inversedBy: zod_1.z.string().optional(),
|
|
103
|
+
mappedBy: zod_1.z.string().optional(),
|
|
104
|
+
});
|
|
105
|
+
exports.hasManyAttribute = exports.baseRelationAttribute.extend({
|
|
106
|
+
relation: zod_1.z.literal('oneToMany'),
|
|
107
|
+
});
|
|
108
|
+
exports.morphToManyAttribute = exports.baseAttribute.extend({
|
|
109
|
+
type: zod_1.z.literal('relation'),
|
|
110
|
+
relation: zod_1.z.literal('morphToMany'),
|
|
111
|
+
});
|
|
112
|
+
exports.morphOneAttribute = exports.baseAttribute.extend({
|
|
113
|
+
type: zod_1.z.literal('relation'),
|
|
114
|
+
relation: zod_1.z.literal('morphToOne'),
|
|
115
|
+
});
|
|
116
|
+
exports.relationAttribute = zod_1.z.union([
|
|
117
|
+
exports.hasOneAttribute,
|
|
118
|
+
exports.oneToOneAttribute,
|
|
119
|
+
exports.belongsToManyAttribute,
|
|
120
|
+
exports.manyToOneAttribute,
|
|
121
|
+
exports.manyToManyAttribute,
|
|
122
|
+
exports.hasManyAttribute,
|
|
123
|
+
exports.morphToManyAttribute,
|
|
124
|
+
exports.morphOneAttribute,
|
|
125
|
+
]);
|
|
126
|
+
exports.componentAttribute = exports.baseAttribute.extend({
|
|
127
|
+
type: zod_1.z.literal('component'),
|
|
128
|
+
repeatable: zod_1.z.boolean().optional(),
|
|
129
|
+
component: zod_1.z.string(),
|
|
130
|
+
});
|
|
131
|
+
exports.dynamiczoneAttribute = exports.baseAttribute.extend({
|
|
132
|
+
type: zod_1.z.literal('dynamiczone'),
|
|
133
|
+
components: zod_1.z.array(zod_1.z.string()),
|
|
134
|
+
});
|
|
135
|
+
exports.knownAttribute = zod_1.z.union([
|
|
136
|
+
exports.textAttribute,
|
|
137
|
+
exports.emailAttribute,
|
|
138
|
+
exports.uidAttribute,
|
|
139
|
+
exports.richTextAttribute,
|
|
140
|
+
exports.blocksAttribute,
|
|
141
|
+
exports.jsonAttribute,
|
|
142
|
+
exports.passwordAttribute,
|
|
143
|
+
...exports.numberAttribute.options,
|
|
144
|
+
exports.enumAttribute,
|
|
145
|
+
...exports.dateAttribute.options,
|
|
146
|
+
exports.mediaAttribute,
|
|
147
|
+
exports.booleanAttribute,
|
|
148
|
+
...exports.relationAttribute.options,
|
|
149
|
+
exports.componentAttribute,
|
|
150
|
+
]);
|
|
151
|
+
exports.anyAttribute = exports.baseAttribute.extend({
|
|
152
|
+
type: zod_1.z.custom(val => !exports.knownAttribute.options.some(schema => schema.shape.type.safeParse(val).success)).transform(() => 'any'),
|
|
153
|
+
}).passthrough();
|
|
154
|
+
exports.attribute = zod_1.z.union([...exports.knownAttribute.options, exports.anyAttribute]);
|
|
155
|
+
const isKnownAttribute = (attributeObject) => {
|
|
156
|
+
return exports.attribute.safeParse(attributeObject).success;
|
|
157
|
+
};
|
|
158
|
+
exports.isKnownAttribute = isKnownAttribute;
|
|
159
|
+
exports.contentTypeAttribute = zod_1.z.union([exports.dynamiczoneAttribute, exports.attribute]);
|