@strapi/typescript-utils 5.0.0-beta.7 → 5.0.0-beta.9
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.
|
@@ -149,6 +149,72 @@ describe('Attributes', () => {
|
|
|
149
149
|
expect(addImport).toHaveBeenCalledWith('Schema');
|
|
150
150
|
};
|
|
151
151
|
|
|
152
|
+
describe('Media', () => {
|
|
153
|
+
test('Media with multiple and with no allowedTypes', () => {
|
|
154
|
+
const attribute = { type: 'media', multiple: true };
|
|
155
|
+
const typeNode = getAttributeType('foo', attribute);
|
|
156
|
+
|
|
157
|
+
defaultAssertions(typeNode, 'Schema.Attribute.Media');
|
|
158
|
+
|
|
159
|
+
expect(typeNode.typeArguments).toHaveLength(2);
|
|
160
|
+
|
|
161
|
+
expect(typeNode.typeArguments[0].kind).toBe(ts.SyntaxKind.UndefinedKeyword);
|
|
162
|
+
|
|
163
|
+
expect(typeNode.typeArguments[1].kind).toBe(ts.SyntaxKind.TrueKeyword);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test('Media without multiple with allowedTypes', () => {
|
|
167
|
+
const attribute = { type: 'media', allowedTypes: ['images', 'videos'] };
|
|
168
|
+
const typeNode = getAttributeType('foo', attribute);
|
|
169
|
+
|
|
170
|
+
defaultAssertions(typeNode, 'Schema.Attribute.Media');
|
|
171
|
+
|
|
172
|
+
expect(typeNode.typeArguments).toHaveLength(1);
|
|
173
|
+
|
|
174
|
+
expect(typeNode.typeArguments[0].kind).toBe(ts.SyntaxKind.UnionType);
|
|
175
|
+
|
|
176
|
+
const unionTypes = typeNode.typeArguments[0].types;
|
|
177
|
+
|
|
178
|
+
attribute.allowedTypes.forEach((value, index) => {
|
|
179
|
+
const element = unionTypes[index];
|
|
180
|
+
|
|
181
|
+
expect(element.kind).toBe(ts.SyntaxKind.StringLiteral);
|
|
182
|
+
expect(element.text).toBe(value);
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test('Media with multiple and with allowedTypes', () => {
|
|
187
|
+
const attribute = { type: 'media', multiple: true, allowedTypes: ['images', 'videos'] };
|
|
188
|
+
const typeNode = getAttributeType('foo', attribute);
|
|
189
|
+
|
|
190
|
+
defaultAssertions(typeNode, 'Schema.Attribute.Media');
|
|
191
|
+
|
|
192
|
+
expect(typeNode.typeArguments).toHaveLength(2);
|
|
193
|
+
|
|
194
|
+
expect(typeNode.typeArguments[0].kind).toBe(ts.SyntaxKind.UnionType);
|
|
195
|
+
|
|
196
|
+
const unionTypes = typeNode.typeArguments[0].types;
|
|
197
|
+
|
|
198
|
+
attribute.allowedTypes.forEach((value, index) => {
|
|
199
|
+
const element = unionTypes[index];
|
|
200
|
+
|
|
201
|
+
expect(element.kind).toBe(ts.SyntaxKind.StringLiteral);
|
|
202
|
+
expect(element.text).toBe(value);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
expect(typeNode.typeArguments[1].kind).toBe(ts.SyntaxKind.TrueKeyword);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test('Media without multiple and with no allowedTypes', () => {
|
|
209
|
+
const attribute = { type: 'media' };
|
|
210
|
+
const typeNode = getAttributeType('foo', attribute);
|
|
211
|
+
|
|
212
|
+
defaultAssertions(typeNode, 'Schema.Attribute.Media');
|
|
213
|
+
|
|
214
|
+
expect(typeNode.typeArguments).toBeUndefined();
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
|
|
152
218
|
describe('Enumeration', () => {
|
|
153
219
|
test('Enumeration with an enum property', () => {
|
|
154
220
|
const attribute = { type: 'enumeration', enum: ['a', 'b', 'c'] };
|
|
@@ -87,8 +87,26 @@ module.exports = {
|
|
|
87
87
|
blocks() {
|
|
88
88
|
return [withAttributeNamespace('Blocks')];
|
|
89
89
|
},
|
|
90
|
-
media() {
|
|
91
|
-
|
|
90
|
+
media({ attribute }) {
|
|
91
|
+
const { allowedTypes, multiple } = attribute;
|
|
92
|
+
|
|
93
|
+
const params = [];
|
|
94
|
+
|
|
95
|
+
const typesParam = allowedTypes
|
|
96
|
+
? factory.createUnionTypeNode(
|
|
97
|
+
allowedTypes.map((allowedType) => factory.createStringLiteral(allowedType))
|
|
98
|
+
)
|
|
99
|
+
: factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword);
|
|
100
|
+
|
|
101
|
+
if (allowedTypes || multiple) {
|
|
102
|
+
params.push(typesParam);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (multiple) {
|
|
106
|
+
params.push(factory.createTrue());
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return [withAttributeNamespace('Media'), params];
|
|
92
110
|
},
|
|
93
111
|
relation({ attribute }) {
|
|
94
112
|
const { relation, target } = attribute;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/typescript-utils",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.9",
|
|
4
4
|
"description": "Typescript support for Strapi",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"node": ">=18.0.0 <=20.x.x",
|
|
50
50
|
"npm": ">=6.0.0"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "0a5a7b91474a18df8a8c6c81613cca1f9c598445"
|
|
53
53
|
}
|