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