@strapi/typescript-utils 0.0.0-next.f45143c5e2a8a9d85691d0abf79a3f42024a0c71 → 0.0.0-next.f7babb775ed9a7e18d8351cb7f74c63e016323c4

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/.eslintignore CHANGED
@@ -1,2 +1,3 @@
1
1
  node_modules/
2
2
  .eslintrc.js
3
+ index.d.ts
package/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ // FIXME: to remove when migrating this package to ts
2
+ declare module '@strapi/typescript-utils' {
3
+ const utils: any;
4
+ export = utils;
5
+ }
package/jest.config.js CHANGED
@@ -2,4 +2,5 @@
2
2
 
3
3
  module.exports = {
4
4
  preset: '../../../jest-preset.unit.js',
5
+ displayName: 'Typescript utils',
5
6
  };
@@ -1,22 +1,22 @@
1
1
  'use strict';
2
2
 
3
- jest.mock('../../../generators/schemas/imports', () => ({ addImport: jest.fn() }));
3
+ jest.mock('../../../generators/common/imports', () => ({ addImport: jest.fn() }));
4
4
 
5
5
  const consoleWarnMock = jest.spyOn(console, 'warn').mockImplementation();
6
6
 
7
7
  const ts = require('typescript');
8
8
 
9
- const attributeToPropertySignature = require('../../../generators/schemas/attributes');
9
+ const attributeToPropertySignature = require('../../../generators/common/models/attributes');
10
10
  const {
11
11
  getAttributeType,
12
12
  getAttributeModifiers,
13
- } = require('../../../generators/schemas/attributes');
14
- const { addImport } = require('../../../generators/schemas/imports');
13
+ } = require('../../../generators/common/models/attributes');
14
+ const { addImport } = require('../../../generators/common/imports');
15
15
 
16
16
  // TODO: emit definition (to a string) & also check snapshots based on that. It would allow checking both the structure & the output.
17
17
  describe('Attributes', () => {
18
18
  afterEach(() => {
19
- jest.resetAllMocks();
19
+ jest.clearAllMocks();
20
20
  });
21
21
 
22
22
  describe('Attribute to Property Signature', () => {
@@ -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('StringAttribute');
51
+ expect(prop.type.types[0].typeName.escapedText).toBe('Attribute.String');
52
52
  expect(prop.type.types[0].typeArguments).toBeUndefined();
53
53
  });
54
54
 
@@ -60,7 +60,7 @@ 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('ComponentAttribute');
63
+ expect(prop.type.types[0].typeName.escapedText).toBe('Attribute.Component');
64
64
  expect(prop.type.types[0].typeArguments).toHaveLength(1);
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');
@@ -82,14 +82,14 @@ describe('Attributes', () => {
82
82
  const [attributeType, requiredOptionType] = prop.type.types;
83
83
 
84
84
  expect(attributeType.kind).toBe(ts.SyntaxKind.TypeReference);
85
- expect(attributeType.typeName.escapedText).toBe('EnumerationAttribute');
85
+ expect(attributeType.typeName.escapedText).toBe('Attribute.Enumeration');
86
86
  expect(attributeType.typeArguments).toHaveLength(1);
87
87
  expect(attributeType.typeArguments[0].kind).toBe(ts.SyntaxKind.TupleType);
88
88
  expect(attributeType.typeArguments[0].elements[0].text).toBe('a');
89
89
  expect(attributeType.typeArguments[0].elements[1].text).toBe('b');
90
90
 
91
91
  expect(requiredOptionType.kind).toBe(ts.SyntaxKind.TypeReference);
92
- expect(requiredOptionType.typeName.escapedText).toBe('DefaultTo');
92
+ expect(requiredOptionType.typeName.escapedText).toBe('Attribute.DefaultTo');
93
93
  expect(requiredOptionType.typeArguments).toHaveLength(1);
94
94
  expect(requiredOptionType.typeArguments[0].kind).toBe(ts.SyntaxKind.StringLiteral);
95
95
  expect(requiredOptionType.typeArguments[0].text).toBe('b');
@@ -108,22 +108,22 @@ describe('Attributes', () => {
108
108
  });
109
109
 
110
110
  test.each([
111
- ['string', 'StringAttribute'],
112
- ['text', 'TextAttribute'],
113
- ['richtext', 'RichTextAttribute'],
114
- ['password', 'PasswordAttribute'],
115
- ['email', 'EmailAttribute'],
116
- ['date', 'DateAttribute'],
117
- ['time', 'TimeAttribute'],
118
- ['datetime', 'DateTimeAttribute'],
119
- ['timestamp', 'TimestampAttribute'],
120
- ['integer', 'IntegerAttribute'],
121
- ['biginteger', 'BigIntegerAttribute'],
122
- ['float', 'FloatAttribute'],
123
- ['decimal', 'DecimalAttribute'],
124
- ['boolean', 'BooleanAttribute'],
125
- ['json', 'JSONAttribute'],
126
- ['media', 'MediaAttribute'],
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'],
127
127
  ])('Basic %p attribute should map to a %p type', (type, expectedType) => {
128
128
  const typeNode = getAttributeType('foo', { type });
129
129
 
@@ -134,7 +134,7 @@ describe('Attributes', () => {
134
134
  expect(typeNode.typeArguments).toBeUndefined();
135
135
 
136
136
  expect(consoleWarnMock).not.toHaveBeenCalled();
137
- expect(addImport).toHaveBeenCalledWith(expectedType);
137
+ expect(addImport).toHaveBeenCalledWith('Attribute');
138
138
  });
139
139
 
140
140
  describe('Complex types (with generic type parameters)', () => {
@@ -145,7 +145,7 @@ describe('Attributes', () => {
145
145
  expect(typeNode.typeName.escapedText).toBe(typeName);
146
146
 
147
147
  expect(consoleWarnMock).not.toHaveBeenCalled();
148
- expect(addImport).toHaveBeenCalledWith(typeName);
148
+ expect(addImport).toHaveBeenCalledWith('Attribute');
149
149
  };
150
150
 
151
151
  describe('Enumeration', () => {
@@ -153,7 +153,7 @@ describe('Attributes', () => {
153
153
  const attribute = { type: 'enumeration', enum: ['a', 'b', 'c'] };
154
154
  const typeNode = getAttributeType('foo', attribute);
155
155
 
156
- defaultAssertions(typeNode, 'EnumerationAttribute');
156
+ defaultAssertions(typeNode, 'Attribute.Enumeration');
157
157
 
158
158
  expect(typeNode.typeArguments).toHaveLength(1);
159
159
  expect(typeNode.typeArguments[0].kind).toBe(ts.SyntaxKind.TupleType);
@@ -174,7 +174,7 @@ describe('Attributes', () => {
174
174
  const attribute = { type: 'uid' };
175
175
  const typeNode = getAttributeType('foo', attribute);
176
176
 
177
- defaultAssertions(typeNode, 'UIDAttribute');
177
+ defaultAssertions(typeNode, 'Attribute.UID');
178
178
 
179
179
  expect(typeNode.typeArguments).toBeUndefined();
180
180
  });
@@ -183,7 +183,7 @@ describe('Attributes', () => {
183
183
  const attribute = { type: 'uid', targetField: 'bar' };
184
184
  const typeNode = getAttributeType('foo', attribute, 'api::bar.bar');
185
185
 
186
- defaultAssertions(typeNode, 'UIDAttribute');
186
+ defaultAssertions(typeNode, 'Attribute.UID');
187
187
 
188
188
  expect(typeNode.typeArguments).not.toBeUndefined();
189
189
  expect(typeNode.typeArguments).toHaveLength(2);
@@ -199,7 +199,7 @@ describe('Attributes', () => {
199
199
  const attribute = { type: 'uid', options: { separator: '_' } };
200
200
  const typeNode = getAttributeType('foo', attribute);
201
201
 
202
- defaultAssertions(typeNode, 'UIDAttribute');
202
+ defaultAssertions(typeNode, 'Attribute.UID');
203
203
 
204
204
  expect(typeNode.typeArguments).toHaveLength(3);
205
205
 
@@ -224,7 +224,7 @@ describe('Attributes', () => {
224
224
  const attribute = { type: 'uid', options: { separator: '_' }, targetField: 'bar' };
225
225
  const typeNode = getAttributeType('foo', attribute, 'api::bar.bar');
226
226
 
227
- defaultAssertions(typeNode, 'UIDAttribute');
227
+ defaultAssertions(typeNode, 'Attribute.UID');
228
228
 
229
229
  expect(typeNode.typeArguments).toHaveLength(3);
230
230
 
@@ -254,7 +254,7 @@ describe('Attributes', () => {
254
254
  const attribute = { type: 'relation', relation: 'oneToOne', target: 'api::bar.bar' };
255
255
  const typeNode = getAttributeType('foo', attribute, 'api::foo.foo');
256
256
 
257
- defaultAssertions(typeNode, 'RelationAttribute');
257
+ defaultAssertions(typeNode, 'Attribute.Relation');
258
258
 
259
259
  expect(typeNode.typeArguments).toHaveLength(3);
260
260
 
@@ -272,7 +272,7 @@ describe('Attributes', () => {
272
272
  const attribute = { type: 'relation', relation: 'morphMany' };
273
273
  const typeNode = getAttributeType('foo', attribute, 'api::foo.foo');
274
274
 
275
- defaultAssertions(typeNode, 'RelationAttribute');
275
+ defaultAssertions(typeNode, 'Attribute.Relation');
276
276
 
277
277
  expect(typeNode.typeArguments).toHaveLength(2);
278
278
 
@@ -289,7 +289,7 @@ describe('Attributes', () => {
289
289
  const attribute = { type: 'component', component: 'default.comp', repeatable: true };
290
290
  const typeNode = getAttributeType('foo', attribute);
291
291
 
292
- defaultAssertions(typeNode, 'ComponentAttribute');
292
+ defaultAssertions(typeNode, 'Attribute.Component');
293
293
 
294
294
  expect(typeNode.typeArguments).toHaveLength(2);
295
295
 
@@ -303,7 +303,7 @@ describe('Attributes', () => {
303
303
  const attribute = { type: 'component', component: 'default.comp' };
304
304
  const typeNode = getAttributeType('foo', attribute);
305
305
 
306
- defaultAssertions(typeNode, 'ComponentAttribute');
306
+ defaultAssertions(typeNode, 'Attribute.Component');
307
307
 
308
308
  expect(typeNode.typeArguments).toHaveLength(1);
309
309
 
@@ -317,7 +317,7 @@ describe('Attributes', () => {
317
317
  const attribute = { type: 'dynamiczone', components: ['default.comp1', 'default.comp2'] };
318
318
  const typeNode = getAttributeType('foo', attribute);
319
319
 
320
- defaultAssertions(typeNode, 'DynamicZoneAttribute');
320
+ defaultAssertions(typeNode, 'Attribute.DynamicZone');
321
321
 
322
322
  expect(typeNode.typeArguments).toHaveLength(1);
323
323
 
@@ -359,7 +359,7 @@ describe('Attributes', () => {
359
359
 
360
360
  expect(modifiers).toHaveLength(1);
361
361
  expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
362
- expect(modifiers[0].typeName.escapedText).toBe('RequiredAttribute');
362
+ expect(modifiers[0].typeName.escapedText).toBe('Attribute.Required');
363
363
  });
364
364
  });
365
365
 
@@ -384,7 +384,7 @@ describe('Attributes', () => {
384
384
 
385
385
  expect(modifiers).toHaveLength(1);
386
386
  expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
387
- expect(modifiers[0].typeName.escapedText).toBe('PrivateAttribute');
387
+ expect(modifiers[0].typeName.escapedText).toBe('Attribute.Private');
388
388
  });
389
389
  });
390
390
 
@@ -409,7 +409,7 @@ describe('Attributes', () => {
409
409
 
410
410
  expect(modifiers).toHaveLength(1);
411
411
  expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
412
- expect(modifiers[0].typeName.escapedText).toBe('UniqueAttribute');
412
+ expect(modifiers[0].typeName.escapedText).toBe('Attribute.Unique');
413
413
  });
414
414
  });
415
415
 
@@ -434,7 +434,7 @@ describe('Attributes', () => {
434
434
 
435
435
  expect(modifiers).toHaveLength(1);
436
436
  expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
437
- expect(modifiers[0].typeName.escapedText).toBe('ConfigurableAttribute');
437
+ expect(modifiers[0].typeName.escapedText).toBe('Attribute.Configurable');
438
438
  });
439
439
  });
440
440
 
@@ -455,7 +455,7 @@ describe('Attributes', () => {
455
455
 
456
456
  expect(modifiers).toHaveLength(1);
457
457
  expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
458
- expect(modifiers[0].typeName.escapedText).toBe('CustomField');
458
+ expect(modifiers[0].typeName.escapedText).toBe('Attribute.CustomField');
459
459
  expect(modifiers[0].typeArguments).toHaveLength(1);
460
460
  expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.StringLiteral);
461
461
  expect(modifiers[0].typeArguments[0].text).toBe('plugin::color-picker.color');
@@ -473,7 +473,7 @@ describe('Attributes', () => {
473
473
 
474
474
  expect(modifiers).toHaveLength(1);
475
475
  expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
476
- expect(modifiers[0].typeName.escapedText).toBe('CustomField');
476
+ expect(modifiers[0].typeName.escapedText).toBe('Attribute.CustomField');
477
477
  expect(modifiers[0].typeArguments).toHaveLength(2);
478
478
  expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.StringLiteral);
479
479
  expect(modifiers[0].typeArguments[0].text).toBe('plugin::color-picker.color');
@@ -507,7 +507,7 @@ describe('Attributes', () => {
507
507
 
508
508
  expect(modifiers).toHaveLength(1);
509
509
  expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
510
- expect(modifiers[0].typeName.escapedText).toBe('SetPluginOptions');
510
+ expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetPluginOptions');
511
511
  expect(modifiers[0].typeArguments).toHaveLength(1);
512
512
  expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.TypeLiteral);
513
513
  expect(modifiers[0].typeArguments[0].members).toHaveLength(1);
@@ -546,7 +546,7 @@ describe('Attributes', () => {
546
546
  expect(modifiers).toHaveLength(1);
547
547
 
548
548
  expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
549
- expect(modifiers[0].typeName.escapedText).toBe('SetMinMax');
549
+ expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMax');
550
550
 
551
551
  expect(modifiers[0].typeArguments).toHaveLength(1);
552
552
  expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.TypeLiteral);
@@ -570,7 +570,7 @@ describe('Attributes', () => {
570
570
  expect(modifiers).toHaveLength(1);
571
571
 
572
572
  expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
573
- expect(modifiers[0].typeName.escapedText).toBe('SetMinMax');
573
+ expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMax');
574
574
 
575
575
  expect(modifiers[0].typeArguments).toHaveLength(1);
576
576
  expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.TypeLiteral);
@@ -594,7 +594,7 @@ describe('Attributes', () => {
594
594
  expect(modifiers).toHaveLength(1);
595
595
 
596
596
  expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
597
- expect(modifiers[0].typeName.escapedText).toBe('SetMinMax');
597
+ expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMax');
598
598
 
599
599
  expect(modifiers[0].typeArguments).toHaveLength(1);
600
600
  expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.TypeLiteral);
@@ -636,7 +636,7 @@ describe('Attributes', () => {
636
636
  expect(modifiers).toHaveLength(1);
637
637
 
638
638
  expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
639
- expect(modifiers[0].typeName.escapedText).toBe('SetMinMaxLength');
639
+ expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMaxLength');
640
640
 
641
641
  expect(modifiers[0].typeArguments).toHaveLength(1);
642
642
  expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.TypeLiteral);
@@ -660,7 +660,7 @@ describe('Attributes', () => {
660
660
  expect(modifiers).toHaveLength(1);
661
661
 
662
662
  expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
663
- expect(modifiers[0].typeName.escapedText).toBe('SetMinMaxLength');
663
+ expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMaxLength');
664
664
 
665
665
  expect(modifiers[0].typeArguments).toHaveLength(1);
666
666
  expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.TypeLiteral);
@@ -684,7 +684,7 @@ describe('Attributes', () => {
684
684
  expect(modifiers).toHaveLength(1);
685
685
 
686
686
  expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
687
- expect(modifiers[0].typeName.escapedText).toBe('SetMinMaxLength');
687
+ expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMaxLength');
688
688
 
689
689
  expect(modifiers[0].typeArguments).toHaveLength(1);
690
690
  expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.TypeLiteral);
@@ -726,7 +726,7 @@ describe('Attributes', () => {
726
726
  expect(modifiers).toHaveLength(1);
727
727
 
728
728
  expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
729
- expect(modifiers[0].typeName.escapedText).toBe('DefaultTo');
729
+ expect(modifiers[0].typeName.escapedText).toBe('Attribute.DefaultTo');
730
730
 
731
731
  expect(modifiers[0].typeArguments).toHaveLength(1);
732
732
  expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.TrueKeyword);
@@ -739,7 +739,7 @@ describe('Attributes', () => {
739
739
  expect(modifiers).toHaveLength(1);
740
740
 
741
741
  expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
742
- expect(modifiers[0].typeName.escapedText).toBe('DefaultTo');
742
+ expect(modifiers[0].typeName.escapedText).toBe('Attribute.DefaultTo');
743
743
 
744
744
  expect(modifiers[0].typeArguments).toHaveLength(1);
745
745
  expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.TypeLiteral);
@@ -6,7 +6,7 @@ const {
6
6
  addImport,
7
7
  generateImportDefinition,
8
8
  getImports,
9
- } = require('../../../generators/schemas/imports');
9
+ } = require('../../../generators/common/imports');
10
10
 
11
11
  describe('Imports', () => {
12
12
  test('When first loaded, the list of imports should be empty', () => {
@@ -27,28 +27,30 @@ describe('Imports', () => {
27
27
  });
28
28
 
29
29
  test('Generate an import type definition containing the registered import', () => {
30
- const def = generateImportDefinition();
30
+ const defs = generateImportDefinition();
31
31
 
32
- expect(def.kind).toBe(ts.SyntaxKind.ImportDeclaration);
32
+ defs.forEach((def) => {
33
+ expect(def.kind).toBe(ts.SyntaxKind.ImportDeclaration);
33
34
 
34
- // Module specifier
35
- expect(def.moduleSpecifier.kind).toBe(ts.SyntaxKind.StringLiteral);
36
- expect(def.moduleSpecifier.text).toBe('@strapi/strapi');
35
+ // Module specifier
36
+ expect(def.moduleSpecifier.kind).toBe(ts.SyntaxKind.StringLiteral);
37
+ expect(def.moduleSpecifier.text).toBe('@strapi/strapi');
37
38
 
38
- // Import clause (should be named imports)
39
- expect(def.importClause.kind).toBe(ts.SyntaxKind.ImportClause);
39
+ // Import clause (should be named imports)
40
+ expect(def.importClause.kind).toBe(ts.SyntaxKind.ImportClause);
40
41
 
41
- const { elements } = def.importClause.namedBindings;
42
+ const { elements } = def.importClause.namedBindings;
42
43
 
43
- expect(elements).toHaveLength(2);
44
+ expect(elements).toHaveLength(2);
44
45
 
45
- // Import clauses
46
- getImports().forEach((namedImport, index) => {
47
- const element = elements[index];
46
+ // Import clauses
47
+ getImports().forEach((namedImport, index) => {
48
+ const element = elements[index];
48
49
 
49
- expect(element.kind).toBe(ts.SyntaxKind.ImportSpecifier);
50
- expect(element.name.kind).toBe(ts.SyntaxKind.Identifier);
51
- expect(element.name.escapedText).toBe(namedImport);
50
+ expect(element.kind).toBe(ts.SyntaxKind.ImportSpecifier);
51
+ expect(element.name.kind).toBe(ts.SyntaxKind.Identifier);
52
+ expect(element.name.escapedText).toBe(namedImport);
53
+ });
52
54
  });
53
55
  });
54
56
  });
@@ -4,71 +4,18 @@ const ts = require('typescript');
4
4
  const { factory } = require('typescript');
5
5
 
6
6
  const {
7
- getAllStrapiSchemas,
8
7
  getDefinitionAttributesCount,
9
8
  getSchemaExtendsTypeName,
10
9
  getSchemaInterfaceName,
11
10
  getSchemaModelType,
12
11
  getTypeNode,
13
12
  toTypeLiteral,
14
- } = require('../../../generators/schemas/utils');
13
+ } = require('../../../generators/common/models/utils');
15
14
 
16
15
  describe('Utils', () => {
17
- describe('Get All Strapi Schemas', () => {
18
- test('Get both components and content types', () => {
19
- const strapi = {
20
- contentTypes: {
21
- ctA: {},
22
- ctB: {},
23
- },
24
- components: {
25
- comp1: {},
26
- comp2: {},
27
- comp3: {},
28
- },
29
- };
30
-
31
- const schemas = getAllStrapiSchemas(strapi);
32
-
33
- expect(schemas).toMatchObject({ ctA: {}, ctB: {}, comp1: {}, comp2: {}, comp3: {} });
34
- });
35
-
36
- test('Get only components if there is no content type', () => {
37
- const strapi = {
38
- contentTypes: {},
39
-
40
- components: {
41
- comp1: {},
42
- comp2: {},
43
- comp3: {},
44
- },
45
- };
46
-
47
- const schemas = getAllStrapiSchemas(strapi);
48
-
49
- expect(schemas).toMatchObject({ comp1: {}, comp2: {}, comp3: {} });
50
- });
51
-
52
- test('Get only content types if there is no component', () => {
53
- const strapi = {
54
- contentTypes: {
55
- ctA: {},
56
- ctB: {},
57
- },
58
-
59
- components: {},
60
- };
61
-
62
- const schemas = getAllStrapiSchemas(strapi);
63
-
64
- expect(schemas).toMatchObject({ ctA: {}, ctB: {} });
65
- });
66
- });
67
-
68
16
  describe('Get Definition Attributes Count', () => {
69
17
  const createMainNode = (members = []) => {
70
18
  return factory.createInterfaceDeclaration(
71
- undefined,
72
19
  undefined,
73
20
  factory.createIdentifier('Foo'),
74
21
  undefined,
@@ -79,7 +26,6 @@ describe('Utils', () => {
79
26
 
80
27
  const createPropertyDeclaration = (name, type) => {
81
28
  return factory.createPropertyDeclaration(
82
- undefined,
83
29
  undefined,
84
30
  factory.createIdentifier(name),
85
31
  undefined,
@@ -174,10 +120,10 @@ describe('Utils', () => {
174
120
 
175
121
  describe('Get Schema Extends Type Name', () => {
176
122
  test.each([
177
- [{ modelType: 'component', kind: null }, 'ComponentSchema'],
178
- [{ modelType: 'contentType', kind: 'singleType' }, 'SingleTypeSchema'],
179
- [{ modelType: 'contentType', kind: 'collectionType' }, 'CollectionTypeSchema'],
180
- [{ modelType: 'invalidType', kind: 'foo' }, 'Schema'],
123
+ [{ modelType: 'component', kind: null }, 'Schema.Component'],
124
+ [{ modelType: 'contentType', kind: 'singleType' }, 'Schema.SingleType'],
125
+ [{ modelType: 'contentType', kind: 'collectionType' }, 'Schema.CollectionType'],
126
+ [{ modelType: 'invalidType', kind: 'foo' }, null],
181
127
  ])("Expect %p to generate %p as the base type for a schema's interface", (schema, expected) => {
182
128
  expect(getSchemaExtendsTypeName(schema)).toBe(expected);
183
129
  });
@@ -22,12 +22,13 @@ module.exports = {
22
22
  factory.createImportSpecifier(false, undefined, factory.createIdentifier(key))
23
23
  );
24
24
 
25
- return factory.createImportDeclaration(
26
- undefined,
27
- undefined,
28
- factory.createImportClause(false, undefined, factory.createNamedImports(formattedImports)),
29
- factory.createStringLiteral('@strapi/strapi'),
30
- undefined
31
- );
25
+ return [
26
+ factory.createImportDeclaration(
27
+ undefined,
28
+ factory.createImportClause(true, undefined, factory.createNamedImports(formattedImports)),
29
+ factory.createStringLiteral('@strapi/strapi'),
30
+ undefined
31
+ ),
32
+ ];
32
33
  },
33
34
  };
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ const models = require('./models');
4
+ const imports = require('./imports');
5
+
6
+ module.exports = {
7
+ models,
8
+ imports,
9
+ };