@strapi/typescript-utils 0.0.0-next.f7babb775ed9a7e18d8351cb7f74c63e016323c4 → 0.0.0-next.f93d6eabe52aa7681655cfa08eedbc3708dbb90d
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/LICENSE +18 -3
- package/lib/__tests__/generators/schemas/attributes.test.js +280 -135
- package/lib/__tests__/generators/schemas/utils.test.js +31 -31
- package/lib/compile.js +2 -6
- package/lib/compilers/basic.js +12 -4
- package/lib/compilers/index.js +0 -2
- package/lib/generators/common/imports.js +3 -3
- package/lib/generators/common/models/attributes.js +35 -10
- package/lib/generators/common/models/mappers.js +35 -22
- package/lib/generators/common/models/schema.js +7 -5
- package/lib/generators/common/models/utils.js +7 -7
- package/lib/generators/components/index.js +21 -5
- package/lib/generators/content-types/index.js +21 -5
- package/lib/generators/index.js +1 -1
- package/lib/generators/utils.js +10 -5
- package/lib/index.js +0 -3
- package/lib/utils/index.js +2 -0
- package/lib/utils/resolve-outdir-sync.js +18 -0
- package/package.json +15 -8
- package/tsconfigs/admin.json +18 -19
- package/tsconfigs/server.json +18 -16
- package/lib/admin/create-tsconfig-file.js +0 -37
- package/lib/admin/index.js +0 -5
- package/lib/compilers/watch.js +0 -37
|
@@ -48,7 +48,7 @@ describe('Attributes', () => {
|
|
|
48
48
|
|
|
49
49
|
expect(prop.type.types).toHaveLength(1);
|
|
50
50
|
expect(prop.type.types[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
51
|
-
expect(prop.type.types[0].typeName.escapedText).toBe('Attribute.String');
|
|
51
|
+
expect(prop.type.types[0].typeName.escapedText).toBe('Schema.Attribute.String');
|
|
52
52
|
expect(prop.type.types[0].typeArguments).toBeUndefined();
|
|
53
53
|
});
|
|
54
54
|
|
|
@@ -60,10 +60,11 @@ describe('Attributes', () => {
|
|
|
60
60
|
|
|
61
61
|
expect(prop.type.types).toHaveLength(1);
|
|
62
62
|
expect(prop.type.types[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
63
|
-
expect(prop.type.types[0].typeName.escapedText).toBe('Attribute.Component');
|
|
64
|
-
expect(prop.type.types[0].typeArguments).toHaveLength(
|
|
63
|
+
expect(prop.type.types[0].typeName.escapedText).toBe('Schema.Attribute.Component');
|
|
64
|
+
expect(prop.type.types[0].typeArguments).toHaveLength(2);
|
|
65
65
|
expect(prop.type.types[0].typeArguments[0].kind).toBe(ts.SyntaxKind.StringLiteral);
|
|
66
66
|
expect(prop.type.types[0].typeArguments[0].text).toBe('default.comp');
|
|
67
|
+
expect(prop.type.types[0].typeArguments[1].kind).toBe(ts.SyntaxKind.FalseKeyword);
|
|
67
68
|
});
|
|
68
69
|
|
|
69
70
|
test('Attribute with type argument and options', () => {
|
|
@@ -82,14 +83,14 @@ describe('Attributes', () => {
|
|
|
82
83
|
const [attributeType, requiredOptionType] = prop.type.types;
|
|
83
84
|
|
|
84
85
|
expect(attributeType.kind).toBe(ts.SyntaxKind.TypeReference);
|
|
85
|
-
expect(attributeType.typeName.escapedText).toBe('Attribute.Enumeration');
|
|
86
|
+
expect(attributeType.typeName.escapedText).toBe('Schema.Attribute.Enumeration');
|
|
86
87
|
expect(attributeType.typeArguments).toHaveLength(1);
|
|
87
88
|
expect(attributeType.typeArguments[0].kind).toBe(ts.SyntaxKind.TupleType);
|
|
88
89
|
expect(attributeType.typeArguments[0].elements[0].text).toBe('a');
|
|
89
90
|
expect(attributeType.typeArguments[0].elements[1].text).toBe('b');
|
|
90
91
|
|
|
91
92
|
expect(requiredOptionType.kind).toBe(ts.SyntaxKind.TypeReference);
|
|
92
|
-
expect(requiredOptionType.typeName.escapedText).toBe('Attribute.DefaultTo');
|
|
93
|
+
expect(requiredOptionType.typeName.escapedText).toBe('Schema.Attribute.DefaultTo');
|
|
93
94
|
expect(requiredOptionType.typeArguments).toHaveLength(1);
|
|
94
95
|
expect(requiredOptionType.typeArguments[0].kind).toBe(ts.SyntaxKind.StringLiteral);
|
|
95
96
|
expect(requiredOptionType.typeArguments[0].text).toBe('b');
|
|
@@ -108,22 +109,22 @@ describe('Attributes', () => {
|
|
|
108
109
|
});
|
|
109
110
|
|
|
110
111
|
test.each([
|
|
111
|
-
['string', 'Attribute.String'],
|
|
112
|
-
['text', 'Attribute.Text'],
|
|
113
|
-
['richtext', 'Attribute.RichText'],
|
|
114
|
-
['password', 'Attribute.Password'],
|
|
115
|
-
['email', 'Attribute.Email'],
|
|
116
|
-
['date', 'Attribute.Date'],
|
|
117
|
-
['time', 'Attribute.Time'],
|
|
118
|
-
['datetime', 'Attribute.DateTime'],
|
|
119
|
-
['timestamp', 'Attribute.Timestamp'],
|
|
120
|
-
['integer', 'Attribute.Integer'],
|
|
121
|
-
['biginteger', 'Attribute.BigInteger'],
|
|
122
|
-
['float', 'Attribute.Float'],
|
|
123
|
-
['decimal', 'Attribute.Decimal'],
|
|
124
|
-
['boolean', 'Attribute.Boolean'],
|
|
125
|
-
['json', 'Attribute.JSON'],
|
|
126
|
-
['media', 'Attribute.Media'],
|
|
112
|
+
['string', 'Schema.Attribute.String'],
|
|
113
|
+
['text', 'Schema.Attribute.Text'],
|
|
114
|
+
['richtext', 'Schema.Attribute.RichText'],
|
|
115
|
+
['password', 'Schema.Attribute.Password'],
|
|
116
|
+
['email', 'Schema.Attribute.Email'],
|
|
117
|
+
['date', 'Schema.Attribute.Date'],
|
|
118
|
+
['time', 'Schema.Attribute.Time'],
|
|
119
|
+
['datetime', 'Schema.Attribute.DateTime'],
|
|
120
|
+
['timestamp', 'Schema.Attribute.Timestamp'],
|
|
121
|
+
['integer', 'Schema.Attribute.Integer'],
|
|
122
|
+
['biginteger', 'Schema.Attribute.BigInteger'],
|
|
123
|
+
['float', 'Schema.Attribute.Float'],
|
|
124
|
+
['decimal', 'Schema.Attribute.Decimal'],
|
|
125
|
+
['boolean', 'Schema.Attribute.Boolean'],
|
|
126
|
+
['json', 'Schema.Attribute.JSON'],
|
|
127
|
+
['media', 'Schema.Attribute.Media'],
|
|
127
128
|
])('Basic %p attribute should map to a %p type', (type, expectedType) => {
|
|
128
129
|
const typeNode = getAttributeType('foo', { type });
|
|
129
130
|
|
|
@@ -134,7 +135,7 @@ describe('Attributes', () => {
|
|
|
134
135
|
expect(typeNode.typeArguments).toBeUndefined();
|
|
135
136
|
|
|
136
137
|
expect(consoleWarnMock).not.toHaveBeenCalled();
|
|
137
|
-
expect(addImport).toHaveBeenCalledWith('
|
|
138
|
+
expect(addImport).toHaveBeenCalledWith('Schema');
|
|
138
139
|
});
|
|
139
140
|
|
|
140
141
|
describe('Complex types (with generic type parameters)', () => {
|
|
@@ -145,15 +146,81 @@ describe('Attributes', () => {
|
|
|
145
146
|
expect(typeNode.typeName.escapedText).toBe(typeName);
|
|
146
147
|
|
|
147
148
|
expect(consoleWarnMock).not.toHaveBeenCalled();
|
|
148
|
-
expect(addImport).toHaveBeenCalledWith('
|
|
149
|
+
expect(addImport).toHaveBeenCalledWith('Schema');
|
|
149
150
|
};
|
|
150
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
|
+
|
|
151
218
|
describe('Enumeration', () => {
|
|
152
219
|
test('Enumeration with an enum property', () => {
|
|
153
220
|
const attribute = { type: 'enumeration', enum: ['a', 'b', 'c'] };
|
|
154
221
|
const typeNode = getAttributeType('foo', attribute);
|
|
155
222
|
|
|
156
|
-
defaultAssertions(typeNode, 'Attribute.Enumeration');
|
|
223
|
+
defaultAssertions(typeNode, 'Schema.Attribute.Enumeration');
|
|
157
224
|
|
|
158
225
|
expect(typeNode.typeArguments).toHaveLength(1);
|
|
159
226
|
expect(typeNode.typeArguments[0].kind).toBe(ts.SyntaxKind.TupleType);
|
|
@@ -174,7 +241,7 @@ describe('Attributes', () => {
|
|
|
174
241
|
const attribute = { type: 'uid' };
|
|
175
242
|
const typeNode = getAttributeType('foo', attribute);
|
|
176
243
|
|
|
177
|
-
defaultAssertions(typeNode, 'Attribute.UID');
|
|
244
|
+
defaultAssertions(typeNode, 'Schema.Attribute.UID');
|
|
178
245
|
|
|
179
246
|
expect(typeNode.typeArguments).toBeUndefined();
|
|
180
247
|
});
|
|
@@ -183,30 +250,26 @@ describe('Attributes', () => {
|
|
|
183
250
|
const attribute = { type: 'uid', targetField: 'bar' };
|
|
184
251
|
const typeNode = getAttributeType('foo', attribute, 'api::bar.bar');
|
|
185
252
|
|
|
186
|
-
defaultAssertions(typeNode, 'Attribute.UID');
|
|
253
|
+
defaultAssertions(typeNode, 'Schema.Attribute.UID');
|
|
187
254
|
|
|
188
255
|
expect(typeNode.typeArguments).not.toBeUndefined();
|
|
189
|
-
expect(typeNode.typeArguments).toHaveLength(
|
|
256
|
+
expect(typeNode.typeArguments).toHaveLength(1);
|
|
190
257
|
|
|
191
258
|
expect(typeNode.typeArguments[0].kind).toBe(ts.SyntaxKind.StringLiteral);
|
|
192
|
-
expect(typeNode.typeArguments[0].text).toBe('
|
|
193
|
-
|
|
194
|
-
expect(typeNode.typeArguments[1].kind).toBe(ts.SyntaxKind.StringLiteral);
|
|
195
|
-
expect(typeNode.typeArguments[1].text).toBe('bar');
|
|
259
|
+
expect(typeNode.typeArguments[0].text).toBe('bar');
|
|
196
260
|
});
|
|
197
261
|
|
|
198
262
|
test('UID with partial options and no target field', () => {
|
|
199
263
|
const attribute = { type: 'uid', options: { separator: '_' } };
|
|
200
|
-
const typeNode = getAttributeType('foo', attribute);
|
|
264
|
+
const typeNode = getAttributeType('foo', attribute, 'api::foo.foo');
|
|
201
265
|
|
|
202
|
-
defaultAssertions(typeNode, 'Attribute.UID');
|
|
266
|
+
defaultAssertions(typeNode, 'Schema.Attribute.UID');
|
|
203
267
|
|
|
204
|
-
expect(typeNode.typeArguments).toHaveLength(
|
|
268
|
+
expect(typeNode.typeArguments).toHaveLength(2);
|
|
205
269
|
|
|
206
270
|
expect(typeNode.typeArguments[0].kind).toBe(ts.SyntaxKind.UndefinedKeyword);
|
|
207
|
-
expect(typeNode.typeArguments[1].kind).toBe(ts.SyntaxKind.UndefinedKeyword);
|
|
208
271
|
|
|
209
|
-
const optionsLiteralNode = typeNode.typeArguments[
|
|
272
|
+
const optionsLiteralNode = typeNode.typeArguments[1];
|
|
210
273
|
|
|
211
274
|
expect(optionsLiteralNode.kind).toBe(ts.SyntaxKind.TypeLiteral);
|
|
212
275
|
expect(optionsLiteralNode.members).toHaveLength(1);
|
|
@@ -224,17 +287,14 @@ describe('Attributes', () => {
|
|
|
224
287
|
const attribute = { type: 'uid', options: { separator: '_' }, targetField: 'bar' };
|
|
225
288
|
const typeNode = getAttributeType('foo', attribute, 'api::bar.bar');
|
|
226
289
|
|
|
227
|
-
defaultAssertions(typeNode, 'Attribute.UID');
|
|
290
|
+
defaultAssertions(typeNode, 'Schema.Attribute.UID');
|
|
228
291
|
|
|
229
|
-
expect(typeNode.typeArguments).toHaveLength(
|
|
292
|
+
expect(typeNode.typeArguments).toHaveLength(2);
|
|
230
293
|
|
|
231
294
|
expect(typeNode.typeArguments[0].kind).toBe(ts.SyntaxKind.StringLiteral);
|
|
232
|
-
expect(typeNode.typeArguments[0].text).toBe('
|
|
295
|
+
expect(typeNode.typeArguments[0].text).toBe('bar');
|
|
233
296
|
|
|
234
|
-
|
|
235
|
-
expect(typeNode.typeArguments[1].text).toBe('bar');
|
|
236
|
-
|
|
237
|
-
const optionsLiteralNode = typeNode.typeArguments[2];
|
|
297
|
+
const optionsLiteralNode = typeNode.typeArguments[1];
|
|
238
298
|
|
|
239
299
|
expect(optionsLiteralNode.kind).toBe(ts.SyntaxKind.TypeLiteral);
|
|
240
300
|
expect(optionsLiteralNode.members).toHaveLength(1);
|
|
@@ -254,33 +314,27 @@ describe('Attributes', () => {
|
|
|
254
314
|
const attribute = { type: 'relation', relation: 'oneToOne', target: 'api::bar.bar' };
|
|
255
315
|
const typeNode = getAttributeType('foo', attribute, 'api::foo.foo');
|
|
256
316
|
|
|
257
|
-
defaultAssertions(typeNode, 'Attribute.Relation');
|
|
317
|
+
defaultAssertions(typeNode, 'Schema.Attribute.Relation');
|
|
258
318
|
|
|
259
|
-
expect(typeNode.typeArguments).toHaveLength(
|
|
319
|
+
expect(typeNode.typeArguments).toHaveLength(2);
|
|
260
320
|
|
|
261
321
|
expect(typeNode.typeArguments[0].kind).toBe(ts.SyntaxKind.StringLiteral);
|
|
262
|
-
expect(typeNode.typeArguments[0].text).toBe('
|
|
322
|
+
expect(typeNode.typeArguments[0].text).toBe('oneToOne');
|
|
263
323
|
|
|
264
324
|
expect(typeNode.typeArguments[1].kind).toBe(ts.SyntaxKind.StringLiteral);
|
|
265
|
-
expect(typeNode.typeArguments[1].text).toBe('
|
|
266
|
-
|
|
267
|
-
expect(typeNode.typeArguments[2].kind).toBe(ts.SyntaxKind.StringLiteral);
|
|
268
|
-
expect(typeNode.typeArguments[2].text).toBe('api::bar.bar');
|
|
325
|
+
expect(typeNode.typeArguments[1].text).toBe('api::bar.bar');
|
|
269
326
|
});
|
|
270
327
|
|
|
271
328
|
test('Polymorphic relation', () => {
|
|
272
329
|
const attribute = { type: 'relation', relation: 'morphMany' };
|
|
273
330
|
const typeNode = getAttributeType('foo', attribute, 'api::foo.foo');
|
|
274
331
|
|
|
275
|
-
defaultAssertions(typeNode, 'Attribute.Relation');
|
|
332
|
+
defaultAssertions(typeNode, 'Schema.Attribute.Relation');
|
|
276
333
|
|
|
277
|
-
expect(typeNode.typeArguments).toHaveLength(
|
|
334
|
+
expect(typeNode.typeArguments).toHaveLength(1);
|
|
278
335
|
|
|
279
336
|
expect(typeNode.typeArguments[0].kind).toBe(ts.SyntaxKind.StringLiteral);
|
|
280
|
-
expect(typeNode.typeArguments[0].text).toBe('
|
|
281
|
-
|
|
282
|
-
expect(typeNode.typeArguments[1].kind).toBe(ts.SyntaxKind.StringLiteral);
|
|
283
|
-
expect(typeNode.typeArguments[1].text).toBe('morphMany');
|
|
337
|
+
expect(typeNode.typeArguments[0].text).toBe('morphMany');
|
|
284
338
|
});
|
|
285
339
|
});
|
|
286
340
|
|
|
@@ -289,7 +343,7 @@ describe('Attributes', () => {
|
|
|
289
343
|
const attribute = { type: 'component', component: 'default.comp', repeatable: true };
|
|
290
344
|
const typeNode = getAttributeType('foo', attribute);
|
|
291
345
|
|
|
292
|
-
defaultAssertions(typeNode, 'Attribute.Component');
|
|
346
|
+
defaultAssertions(typeNode, 'Schema.Attribute.Component');
|
|
293
347
|
|
|
294
348
|
expect(typeNode.typeArguments).toHaveLength(2);
|
|
295
349
|
|
|
@@ -303,12 +357,14 @@ describe('Attributes', () => {
|
|
|
303
357
|
const attribute = { type: 'component', component: 'default.comp' };
|
|
304
358
|
const typeNode = getAttributeType('foo', attribute);
|
|
305
359
|
|
|
306
|
-
defaultAssertions(typeNode, 'Attribute.Component');
|
|
360
|
+
defaultAssertions(typeNode, 'Schema.Attribute.Component');
|
|
307
361
|
|
|
308
|
-
expect(typeNode.typeArguments).toHaveLength(
|
|
362
|
+
expect(typeNode.typeArguments).toHaveLength(2);
|
|
309
363
|
|
|
310
364
|
expect(typeNode.typeArguments[0].kind).toBe(ts.SyntaxKind.StringLiteral);
|
|
311
365
|
expect(typeNode.typeArguments[0].text).toBe('default.comp');
|
|
366
|
+
|
|
367
|
+
expect(typeNode.typeArguments[1].kind).toBe(ts.SyntaxKind.FalseKeyword);
|
|
312
368
|
});
|
|
313
369
|
});
|
|
314
370
|
|
|
@@ -317,7 +373,7 @@ describe('Attributes', () => {
|
|
|
317
373
|
const attribute = { type: 'dynamiczone', components: ['default.comp1', 'default.comp2'] };
|
|
318
374
|
const typeNode = getAttributeType('foo', attribute);
|
|
319
375
|
|
|
320
|
-
defaultAssertions(typeNode, 'Attribute.DynamicZone');
|
|
376
|
+
defaultAssertions(typeNode, 'Schema.Attribute.DynamicZone');
|
|
321
377
|
|
|
322
378
|
expect(typeNode.typeArguments).toHaveLength(1);
|
|
323
379
|
|
|
@@ -359,7 +415,7 @@ describe('Attributes', () => {
|
|
|
359
415
|
|
|
360
416
|
expect(modifiers).toHaveLength(1);
|
|
361
417
|
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
362
|
-
expect(modifiers[0].typeName.escapedText).toBe('Attribute.Required');
|
|
418
|
+
expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.Required');
|
|
363
419
|
});
|
|
364
420
|
});
|
|
365
421
|
|
|
@@ -384,7 +440,7 @@ describe('Attributes', () => {
|
|
|
384
440
|
|
|
385
441
|
expect(modifiers).toHaveLength(1);
|
|
386
442
|
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
387
|
-
expect(modifiers[0].typeName.escapedText).toBe('Attribute.Private');
|
|
443
|
+
expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.Private');
|
|
388
444
|
});
|
|
389
445
|
});
|
|
390
446
|
|
|
@@ -409,7 +465,7 @@ describe('Attributes', () => {
|
|
|
409
465
|
|
|
410
466
|
expect(modifiers).toHaveLength(1);
|
|
411
467
|
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
412
|
-
expect(modifiers[0].typeName.escapedText).toBe('Attribute.Unique');
|
|
468
|
+
expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.Unique');
|
|
413
469
|
});
|
|
414
470
|
});
|
|
415
471
|
|
|
@@ -434,7 +490,7 @@ describe('Attributes', () => {
|
|
|
434
490
|
|
|
435
491
|
expect(modifiers).toHaveLength(1);
|
|
436
492
|
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
437
|
-
expect(modifiers[0].typeName.escapedText).toBe('Attribute.Configurable');
|
|
493
|
+
expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.Configurable');
|
|
438
494
|
});
|
|
439
495
|
});
|
|
440
496
|
|
|
@@ -455,7 +511,7 @@ describe('Attributes', () => {
|
|
|
455
511
|
|
|
456
512
|
expect(modifiers).toHaveLength(1);
|
|
457
513
|
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
458
|
-
expect(modifiers[0].typeName.escapedText).toBe('Attribute.CustomField');
|
|
514
|
+
expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.CustomField');
|
|
459
515
|
expect(modifiers[0].typeArguments).toHaveLength(1);
|
|
460
516
|
expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.StringLiteral);
|
|
461
517
|
expect(modifiers[0].typeArguments[0].text).toBe('plugin::color-picker.color');
|
|
@@ -473,7 +529,7 @@ describe('Attributes', () => {
|
|
|
473
529
|
|
|
474
530
|
expect(modifiers).toHaveLength(1);
|
|
475
531
|
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
476
|
-
expect(modifiers[0].typeName.escapedText).toBe('Attribute.CustomField');
|
|
532
|
+
expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.CustomField');
|
|
477
533
|
expect(modifiers[0].typeArguments).toHaveLength(2);
|
|
478
534
|
expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.StringLiteral);
|
|
479
535
|
expect(modifiers[0].typeArguments[0].text).toBe('plugin::color-picker.color');
|
|
@@ -507,7 +563,7 @@ describe('Attributes', () => {
|
|
|
507
563
|
|
|
508
564
|
expect(modifiers).toHaveLength(1);
|
|
509
565
|
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
510
|
-
expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetPluginOptions');
|
|
566
|
+
expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.SetPluginOptions');
|
|
511
567
|
expect(modifiers[0].typeArguments).toHaveLength(1);
|
|
512
568
|
expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.TypeLiteral);
|
|
513
569
|
expect(modifiers[0].typeArguments[0].members).toHaveLength(1);
|
|
@@ -546,21 +602,29 @@ describe('Attributes', () => {
|
|
|
546
602
|
expect(modifiers).toHaveLength(1);
|
|
547
603
|
|
|
548
604
|
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
549
|
-
expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMax');
|
|
605
|
+
expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.SetMinMax');
|
|
550
606
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
607
|
+
const [setMinMax] = modifiers;
|
|
608
|
+
const { typeArguments } = setMinMax;
|
|
609
|
+
|
|
610
|
+
expect(typeArguments).toBeDefined();
|
|
611
|
+
expect(typeArguments).toHaveLength(2);
|
|
612
|
+
|
|
613
|
+
const [definition, typeofMinMax] = typeArguments;
|
|
554
614
|
|
|
555
615
|
// Min
|
|
556
|
-
expect(
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
);
|
|
563
|
-
expect(
|
|
616
|
+
expect(definition.kind).toBe(ts.SyntaxKind.TypeLiteral);
|
|
617
|
+
expect(definition.members).toHaveLength(1);
|
|
618
|
+
|
|
619
|
+
const [min] = definition.members;
|
|
620
|
+
|
|
621
|
+
expect(min.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
|
|
622
|
+
expect(min.name.escapedText).toBe('min');
|
|
623
|
+
expect(min.type.kind).toBe(ts.SyntaxKind.NumericLiteral);
|
|
624
|
+
expect(min.type.text).toBe('2');
|
|
625
|
+
|
|
626
|
+
// Check for number keyword on the second typeArgument
|
|
627
|
+
expect(typeofMinMax.kind).toBe(ts.SyntaxKind.NumberKeyword);
|
|
564
628
|
});
|
|
565
629
|
|
|
566
630
|
test('No Min, Max: 3', () => {
|
|
@@ -570,21 +634,29 @@ describe('Attributes', () => {
|
|
|
570
634
|
expect(modifiers).toHaveLength(1);
|
|
571
635
|
|
|
572
636
|
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
573
|
-
expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMax');
|
|
637
|
+
expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.SetMinMax');
|
|
574
638
|
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
expect(modifiers[0].typeArguments[0].members).toHaveLength(1);
|
|
639
|
+
const [setMinMax] = modifiers;
|
|
640
|
+
const { typeArguments } = setMinMax;
|
|
578
641
|
|
|
579
|
-
|
|
580
|
-
expect(
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
);
|
|
587
|
-
|
|
642
|
+
expect(typeArguments).toBeDefined();
|
|
643
|
+
expect(typeArguments).toHaveLength(2);
|
|
644
|
+
|
|
645
|
+
const [definition, typeofMinMax] = typeArguments;
|
|
646
|
+
|
|
647
|
+
// Max
|
|
648
|
+
expect(definition.kind).toBe(ts.SyntaxKind.TypeLiteral);
|
|
649
|
+
expect(definition.members).toHaveLength(1);
|
|
650
|
+
|
|
651
|
+
const [max] = definition.members;
|
|
652
|
+
|
|
653
|
+
expect(max.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
|
|
654
|
+
expect(max.name.escapedText).toBe('max');
|
|
655
|
+
expect(max.type.kind).toBe(ts.SyntaxKind.NumericLiteral);
|
|
656
|
+
expect(max.type.text).toBe('3');
|
|
657
|
+
|
|
658
|
+
// Check for number keyword on the second typeArgument
|
|
659
|
+
expect(typeofMinMax.kind).toBe(ts.SyntaxKind.NumberKeyword);
|
|
588
660
|
});
|
|
589
661
|
|
|
590
662
|
test('Min: 4, Max: 12', () => {
|
|
@@ -594,30 +666,98 @@ describe('Attributes', () => {
|
|
|
594
666
|
expect(modifiers).toHaveLength(1);
|
|
595
667
|
|
|
596
668
|
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
597
|
-
expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMax');
|
|
669
|
+
expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.SetMinMax');
|
|
598
670
|
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
expect(modifiers[0].typeArguments[0].members).toHaveLength(2);
|
|
671
|
+
const [setMinMax] = modifiers;
|
|
672
|
+
const { typeArguments } = setMinMax;
|
|
602
673
|
|
|
603
|
-
|
|
604
|
-
expect(
|
|
605
|
-
ts.SyntaxKind.PropertyDeclaration
|
|
606
|
-
);
|
|
607
|
-
expect(modifiers[0].typeArguments[0].members[0].name.escapedText).toBe('min');
|
|
608
|
-
expect(modifiers[0].typeArguments[0].members[0].type.kind).toBe(
|
|
609
|
-
ts.SyntaxKind.NumericLiteral
|
|
610
|
-
);
|
|
611
|
-
expect(modifiers[0].typeArguments[0].members[0].type.text).toBe('4');
|
|
674
|
+
expect(typeArguments).toBeDefined();
|
|
675
|
+
expect(typeArguments).toHaveLength(2);
|
|
612
676
|
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
expect(
|
|
617
|
-
expect(
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
677
|
+
const [definition, typeofMinMax] = typeArguments;
|
|
678
|
+
|
|
679
|
+
// Min/Max
|
|
680
|
+
expect(definition.kind).toBe(ts.SyntaxKind.TypeLiteral);
|
|
681
|
+
expect(definition.members).toHaveLength(2);
|
|
682
|
+
|
|
683
|
+
const [max, min] = definition.members;
|
|
684
|
+
|
|
685
|
+
expect(max.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
|
|
686
|
+
expect(max.name.escapedText).toBe('max');
|
|
687
|
+
expect(max.type.kind).toBe(ts.SyntaxKind.NumericLiteral);
|
|
688
|
+
expect(max.type.text).toBe('12');
|
|
689
|
+
|
|
690
|
+
expect(min.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
|
|
691
|
+
expect(min.name.escapedText).toBe('min');
|
|
692
|
+
expect(min.type.kind).toBe(ts.SyntaxKind.NumericLiteral);
|
|
693
|
+
expect(min.type.text).toBe('4');
|
|
694
|
+
|
|
695
|
+
// Check for number keyword on the second typeArgument
|
|
696
|
+
expect(typeofMinMax.kind).toBe(ts.SyntaxKind.NumberKeyword);
|
|
697
|
+
});
|
|
698
|
+
|
|
699
|
+
test('Min: "1"', () => {
|
|
700
|
+
const attribute = { min: '1' };
|
|
701
|
+
const modifiers = getAttributeModifiers(attribute);
|
|
702
|
+
|
|
703
|
+
expect(modifiers).toHaveLength(1);
|
|
704
|
+
|
|
705
|
+
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
706
|
+
expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.SetMinMax');
|
|
707
|
+
|
|
708
|
+
const [setMinMax] = modifiers;
|
|
709
|
+
const { typeArguments } = setMinMax;
|
|
710
|
+
|
|
711
|
+
expect(typeArguments).toBeDefined();
|
|
712
|
+
expect(typeArguments).toHaveLength(2);
|
|
713
|
+
|
|
714
|
+
const [definition, typeofMinMax] = typeArguments;
|
|
715
|
+
|
|
716
|
+
// Min/Max
|
|
717
|
+
expect(definition.kind).toBe(ts.SyntaxKind.TypeLiteral);
|
|
718
|
+
expect(definition.members).toHaveLength(1);
|
|
719
|
+
|
|
720
|
+
const [min] = definition.members;
|
|
721
|
+
|
|
722
|
+
expect(min.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
|
|
723
|
+
expect(min.name.escapedText).toBe('min');
|
|
724
|
+
expect(min.type.kind).toBe(ts.SyntaxKind.StringLiteral);
|
|
725
|
+
expect(min.type.text).toBe('1');
|
|
726
|
+
|
|
727
|
+
// Check for string keyword on the second typeArgument
|
|
728
|
+
expect(typeofMinMax.kind).toBe(ts.SyntaxKind.StringKeyword);
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
test('Min: 0', () => {
|
|
732
|
+
const attribute = { min: 0 };
|
|
733
|
+
const modifiers = getAttributeModifiers(attribute);
|
|
734
|
+
|
|
735
|
+
expect(modifiers).toHaveLength(1);
|
|
736
|
+
|
|
737
|
+
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
738
|
+
expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.SetMinMax');
|
|
739
|
+
|
|
740
|
+
const [setMinMax] = modifiers;
|
|
741
|
+
const { typeArguments } = setMinMax;
|
|
742
|
+
|
|
743
|
+
expect(typeArguments).toBeDefined();
|
|
744
|
+
expect(typeArguments).toHaveLength(2);
|
|
745
|
+
|
|
746
|
+
const [definition, typeofMinMax] = typeArguments;
|
|
747
|
+
|
|
748
|
+
// Min/Max
|
|
749
|
+
expect(definition.kind).toBe(ts.SyntaxKind.TypeLiteral);
|
|
750
|
+
expect(definition.members).toHaveLength(1);
|
|
751
|
+
|
|
752
|
+
const [min] = definition.members;
|
|
753
|
+
|
|
754
|
+
expect(min.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
|
|
755
|
+
expect(min.name.escapedText).toBe('min');
|
|
756
|
+
expect(min.type.kind).toBe(ts.SyntaxKind.NumericLiteral);
|
|
757
|
+
expect(min.type.text).toBe('0');
|
|
758
|
+
|
|
759
|
+
// Check for string keyword on the second typeArgument
|
|
760
|
+
expect(typeofMinMax.kind).toBe(ts.SyntaxKind.NumberKeyword);
|
|
621
761
|
});
|
|
622
762
|
});
|
|
623
763
|
|
|
@@ -636,7 +776,7 @@ describe('Attributes', () => {
|
|
|
636
776
|
expect(modifiers).toHaveLength(1);
|
|
637
777
|
|
|
638
778
|
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
639
|
-
expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMaxLength');
|
|
779
|
+
expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.SetMinMaxLength');
|
|
640
780
|
|
|
641
781
|
expect(modifiers[0].typeArguments).toHaveLength(1);
|
|
642
782
|
expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.TypeLiteral);
|
|
@@ -660,7 +800,7 @@ describe('Attributes', () => {
|
|
|
660
800
|
expect(modifiers).toHaveLength(1);
|
|
661
801
|
|
|
662
802
|
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
663
|
-
expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMaxLength');
|
|
803
|
+
expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.SetMinMaxLength');
|
|
664
804
|
|
|
665
805
|
expect(modifiers[0].typeArguments).toHaveLength(1);
|
|
666
806
|
expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.TypeLiteral);
|
|
@@ -684,30 +824,25 @@ describe('Attributes', () => {
|
|
|
684
824
|
expect(modifiers).toHaveLength(1);
|
|
685
825
|
|
|
686
826
|
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
687
|
-
expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMaxLength');
|
|
827
|
+
expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.SetMinMaxLength');
|
|
688
828
|
|
|
689
829
|
expect(modifiers[0].typeArguments).toHaveLength(1);
|
|
690
830
|
expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.TypeLiteral);
|
|
691
831
|
expect(modifiers[0].typeArguments[0].members).toHaveLength(2);
|
|
692
832
|
|
|
693
|
-
|
|
694
|
-
expect(modifiers[0].typeArguments[0].members[0].kind).toBe(
|
|
695
|
-
ts.SyntaxKind.PropertyDeclaration
|
|
696
|
-
);
|
|
697
|
-
expect(modifiers[0].typeArguments[0].members[0].name.escapedText).toBe('minLength');
|
|
698
|
-
expect(modifiers[0].typeArguments[0].members[0].type.kind).toBe(
|
|
699
|
-
ts.SyntaxKind.NumericLiteral
|
|
700
|
-
);
|
|
701
|
-
expect(modifiers[0].typeArguments[0].members[0].type.text).toBe('4');
|
|
833
|
+
const [maxLength, minLength] = modifiers[0].typeArguments[0].members;
|
|
702
834
|
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
);
|
|
706
|
-
expect(
|
|
707
|
-
expect(
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
expect(
|
|
835
|
+
// Max
|
|
836
|
+
expect(maxLength.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
|
|
837
|
+
expect(maxLength.name.escapedText).toBe('maxLength');
|
|
838
|
+
expect(maxLength.type.kind).toBe(ts.SyntaxKind.NumericLiteral);
|
|
839
|
+
expect(maxLength.type.text).toBe('12');
|
|
840
|
+
|
|
841
|
+
// Min
|
|
842
|
+
expect(minLength.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
|
|
843
|
+
expect(minLength.name.escapedText).toBe('minLength');
|
|
844
|
+
expect(minLength.type.kind).toBe(ts.SyntaxKind.NumericLiteral);
|
|
845
|
+
expect(minLength.type.text).toBe('4');
|
|
711
846
|
});
|
|
712
847
|
});
|
|
713
848
|
|
|
@@ -726,7 +861,7 @@ describe('Attributes', () => {
|
|
|
726
861
|
expect(modifiers).toHaveLength(1);
|
|
727
862
|
|
|
728
863
|
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
729
|
-
expect(modifiers[0].typeName.escapedText).toBe('Attribute.DefaultTo');
|
|
864
|
+
expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.DefaultTo');
|
|
730
865
|
|
|
731
866
|
expect(modifiers[0].typeArguments).toHaveLength(1);
|
|
732
867
|
expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.TrueKeyword);
|
|
@@ -739,7 +874,7 @@ describe('Attributes', () => {
|
|
|
739
874
|
expect(modifiers).toHaveLength(1);
|
|
740
875
|
|
|
741
876
|
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
742
|
-
expect(modifiers[0].typeName.escapedText).toBe('Attribute.DefaultTo');
|
|
877
|
+
expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.DefaultTo');
|
|
743
878
|
|
|
744
879
|
expect(modifiers[0].typeArguments).toHaveLength(1);
|
|
745
880
|
expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.TypeLiteral);
|
|
@@ -752,6 +887,16 @@ describe('Attributes', () => {
|
|
|
752
887
|
ts.SyntaxKind.TrueKeyword
|
|
753
888
|
);
|
|
754
889
|
});
|
|
890
|
+
|
|
891
|
+
test('Default: <function>', () => {
|
|
892
|
+
const anyFunction = jest.fn();
|
|
893
|
+
const attribute = { default: anyFunction };
|
|
894
|
+
|
|
895
|
+
const modifiers = getAttributeModifiers(attribute);
|
|
896
|
+
|
|
897
|
+
// The default modifier shouldn't be processed when encountering a function
|
|
898
|
+
expect(modifiers).toHaveLength(0);
|
|
899
|
+
});
|
|
755
900
|
});
|
|
756
901
|
});
|
|
757
902
|
});
|