@strapi/typescript-utils 0.0.0-next.fb3a0b82484ce466b1efb1b28f16fc8ef73aba4a → 0.0.0-next.fd9757603c653ca239c45d6e28ab536d2dae0b39
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 +193 -43
- package/lib/admin/create-tsconfig-file.js +2 -16
- package/lib/generators/common/models/attributes.js +30 -3
- package/lib/generators/common/models/mappers.js +20 -2
- package/package.json +8 -8
- package/tsconfigs/admin.json +9 -13
- package/tsconfigs/server.json +15 -15
package/LICENSE
CHANGED
|
@@ -2,7 +2,21 @@ Copyright (c) 2015-present Strapi Solutions SAS
|
|
|
2
2
|
|
|
3
3
|
Portions of the Strapi software are licensed as follows:
|
|
4
4
|
|
|
5
|
-
* All software that resides under an "ee/" directory (the “EE Software”), if that directory exists, is licensed under the license defined
|
|
5
|
+
* All software that resides under an "ee/" directory (the “EE Software”), if that directory exists, is licensed under the license defined below.
|
|
6
|
+
|
|
7
|
+
Enterprise License
|
|
8
|
+
|
|
9
|
+
If you or the company you represent has entered into a written agreement referencing the Enterprise Edition of the Strapi source code available at
|
|
10
|
+
https://github.com/strapi/strapi, then such agreement applies to your use of the Enterprise Edition of the Strapi Software. If you or the company you
|
|
11
|
+
represent is using the Enterprise Edition of the Strapi Software in connection with a subscription to our cloud offering, then the agreement you have
|
|
12
|
+
agreed to with respect to our cloud offering and the licenses included in such agreement apply to your use of the Enterprise Edition of the Strapi Software.
|
|
13
|
+
Otherwise, the Strapi Enterprise Software License Agreement (found here https://strapi.io/enterprise-terms) applies to your use of the Enterprise Edition of the Strapi Software.
|
|
14
|
+
|
|
15
|
+
BY ACCESSING OR USING THE ENTERPRISE EDITION OF THE STRAPI SOFTWARE, YOU ARE AGREEING TO BE BOUND BY THE RELEVANT REFERENCED AGREEMENT.
|
|
16
|
+
IF YOU ARE NOT AUTHORIZED TO ACCEPT THESE TERMS ON BEHALF OF THE COMPANY YOU REPRESENT OR IF YOU DO NOT AGREE TO ALL OF THE RELEVANT TERMS AND CONDITIONS REFERENCED AND YOU
|
|
17
|
+
HAVE NOT OTHERWISE EXECUTED A WRITTEN AGREEMENT WITH STRAPI, YOU ARE NOT AUTHORIZED TO ACCESS OR USE OR ALLOW ANY USER TO ACCESS OR USE ANY PART OF
|
|
18
|
+
THE ENTERPRISE EDITION OF THE STRAPI SOFTWARE. YOUR ACCESS RIGHTS ARE CONDITIONAL ON YOUR CONSENT TO THE RELEVANT REFERENCED TERMS TO THE EXCLUSION OF ALL OTHER TERMS;
|
|
19
|
+
IF THE RELEVANT REFERENCED TERMS ARE CONSIDERED AN OFFER BY YOU, ACCEPTANCE IS EXPRESSLY LIMITED TO THE RELEVANT REFERENCED TERMS.
|
|
6
20
|
|
|
7
21
|
* All software outside of the above-mentioned directories or restrictions above is available under the "MIT Expat" license as set forth below.
|
|
8
22
|
|
|
@@ -18,5 +32,6 @@ furnished to do so, subject to the following conditions:
|
|
|
18
32
|
The above copyright notice and this permission notice shall be included in all
|
|
19
33
|
copies or substantial portions of the Software.
|
|
20
34
|
|
|
21
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
-
|
|
35
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
36
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
37
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -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'] };
|
|
@@ -548,19 +614,27 @@ describe('Attributes', () => {
|
|
|
548
614
|
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
549
615
|
expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMax');
|
|
550
616
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
617
|
+
const [setMinMax] = modifiers;
|
|
618
|
+
const { typeArguments } = setMinMax;
|
|
619
|
+
|
|
620
|
+
expect(typeArguments).toBeDefined();
|
|
621
|
+
expect(typeArguments).toHaveLength(2);
|
|
622
|
+
|
|
623
|
+
const [definition, typeofMinMax] = typeArguments;
|
|
554
624
|
|
|
555
625
|
// Min
|
|
556
|
-
expect(
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
);
|
|
563
|
-
expect(
|
|
626
|
+
expect(definition.kind).toBe(ts.SyntaxKind.TypeLiteral);
|
|
627
|
+
expect(definition.members).toHaveLength(1);
|
|
628
|
+
|
|
629
|
+
const [min] = definition.members;
|
|
630
|
+
|
|
631
|
+
expect(min.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
|
|
632
|
+
expect(min.name.escapedText).toBe('min');
|
|
633
|
+
expect(min.type.kind).toBe(ts.SyntaxKind.NumericLiteral);
|
|
634
|
+
expect(min.type.text).toBe('2');
|
|
635
|
+
|
|
636
|
+
// Check for number keyword on the second typeArgument
|
|
637
|
+
expect(typeofMinMax.kind).toBe(ts.SyntaxKind.NumberKeyword);
|
|
564
638
|
});
|
|
565
639
|
|
|
566
640
|
test('No Min, Max: 3', () => {
|
|
@@ -572,19 +646,27 @@ describe('Attributes', () => {
|
|
|
572
646
|
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
573
647
|
expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMax');
|
|
574
648
|
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
expect(modifiers[0].typeArguments[0].members).toHaveLength(1);
|
|
649
|
+
const [setMinMax] = modifiers;
|
|
650
|
+
const { typeArguments } = setMinMax;
|
|
578
651
|
|
|
579
|
-
|
|
580
|
-
expect(
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
);
|
|
587
|
-
|
|
652
|
+
expect(typeArguments).toBeDefined();
|
|
653
|
+
expect(typeArguments).toHaveLength(2);
|
|
654
|
+
|
|
655
|
+
const [definition, typeofMinMax] = typeArguments;
|
|
656
|
+
|
|
657
|
+
// Max
|
|
658
|
+
expect(definition.kind).toBe(ts.SyntaxKind.TypeLiteral);
|
|
659
|
+
expect(definition.members).toHaveLength(1);
|
|
660
|
+
|
|
661
|
+
const [max] = definition.members;
|
|
662
|
+
|
|
663
|
+
expect(max.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
|
|
664
|
+
expect(max.name.escapedText).toBe('max');
|
|
665
|
+
expect(max.type.kind).toBe(ts.SyntaxKind.NumericLiteral);
|
|
666
|
+
expect(max.type.text).toBe('3');
|
|
667
|
+
|
|
668
|
+
// Check for number keyword on the second typeArgument
|
|
669
|
+
expect(typeofMinMax.kind).toBe(ts.SyntaxKind.NumberKeyword);
|
|
588
670
|
});
|
|
589
671
|
|
|
590
672
|
test('Min: 4, Max: 12', () => {
|
|
@@ -596,28 +678,96 @@ describe('Attributes', () => {
|
|
|
596
678
|
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
597
679
|
expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMax');
|
|
598
680
|
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
expect(modifiers[0].typeArguments[0].members).toHaveLength(2);
|
|
681
|
+
const [setMinMax] = modifiers;
|
|
682
|
+
const { typeArguments } = setMinMax;
|
|
602
683
|
|
|
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');
|
|
684
|
+
expect(typeArguments).toBeDefined();
|
|
685
|
+
expect(typeArguments).toHaveLength(2);
|
|
612
686
|
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
expect(
|
|
617
|
-
expect(
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
687
|
+
const [definition, typeofMinMax] = typeArguments;
|
|
688
|
+
|
|
689
|
+
// Min/Max
|
|
690
|
+
expect(definition.kind).toBe(ts.SyntaxKind.TypeLiteral);
|
|
691
|
+
expect(definition.members).toHaveLength(2);
|
|
692
|
+
|
|
693
|
+
const [min, max] = definition.members;
|
|
694
|
+
|
|
695
|
+
expect(min.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
|
|
696
|
+
expect(min.name.escapedText).toBe('min');
|
|
697
|
+
expect(min.type.kind).toBe(ts.SyntaxKind.NumericLiteral);
|
|
698
|
+
expect(min.type.text).toBe('4');
|
|
699
|
+
|
|
700
|
+
expect(max.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
|
|
701
|
+
expect(max.name.escapedText).toBe('max');
|
|
702
|
+
expect(max.type.kind).toBe(ts.SyntaxKind.NumericLiteral);
|
|
703
|
+
expect(max.type.text).toBe('12');
|
|
704
|
+
|
|
705
|
+
// Check for number keyword on the second typeArgument
|
|
706
|
+
expect(typeofMinMax.kind).toBe(ts.SyntaxKind.NumberKeyword);
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
test('Min: "1"', () => {
|
|
710
|
+
const attribute = { min: '1' };
|
|
711
|
+
const modifiers = getAttributeModifiers(attribute);
|
|
712
|
+
|
|
713
|
+
expect(modifiers).toHaveLength(1);
|
|
714
|
+
|
|
715
|
+
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
716
|
+
expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMax');
|
|
717
|
+
|
|
718
|
+
const [setMinMax] = modifiers;
|
|
719
|
+
const { typeArguments } = setMinMax;
|
|
720
|
+
|
|
721
|
+
expect(typeArguments).toBeDefined();
|
|
722
|
+
expect(typeArguments).toHaveLength(2);
|
|
723
|
+
|
|
724
|
+
const [definition, typeofMinMax] = typeArguments;
|
|
725
|
+
|
|
726
|
+
// Min/Max
|
|
727
|
+
expect(definition.kind).toBe(ts.SyntaxKind.TypeLiteral);
|
|
728
|
+
expect(definition.members).toHaveLength(1);
|
|
729
|
+
|
|
730
|
+
const [min] = definition.members;
|
|
731
|
+
|
|
732
|
+
expect(min.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
|
|
733
|
+
expect(min.name.escapedText).toBe('min');
|
|
734
|
+
expect(min.type.kind).toBe(ts.SyntaxKind.StringLiteral);
|
|
735
|
+
expect(min.type.text).toBe('1');
|
|
736
|
+
|
|
737
|
+
// Check for string keyword on the second typeArgument
|
|
738
|
+
expect(typeofMinMax.kind).toBe(ts.SyntaxKind.StringKeyword);
|
|
739
|
+
});
|
|
740
|
+
|
|
741
|
+
test('Min: 0', () => {
|
|
742
|
+
const attribute = { min: 0 };
|
|
743
|
+
const modifiers = getAttributeModifiers(attribute);
|
|
744
|
+
|
|
745
|
+
expect(modifiers).toHaveLength(1);
|
|
746
|
+
|
|
747
|
+
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
748
|
+
expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMax');
|
|
749
|
+
|
|
750
|
+
const [setMinMax] = modifiers;
|
|
751
|
+
const { typeArguments } = setMinMax;
|
|
752
|
+
|
|
753
|
+
expect(typeArguments).toBeDefined();
|
|
754
|
+
expect(typeArguments).toHaveLength(2);
|
|
755
|
+
|
|
756
|
+
const [definition, typeofMinMax] = typeArguments;
|
|
757
|
+
|
|
758
|
+
// Min/Max
|
|
759
|
+
expect(definition.kind).toBe(ts.SyntaxKind.TypeLiteral);
|
|
760
|
+
expect(definition.members).toHaveLength(1);
|
|
761
|
+
|
|
762
|
+
const [min] = definition.members;
|
|
763
|
+
|
|
764
|
+
expect(min.kind).toBe(ts.SyntaxKind.PropertyDeclaration);
|
|
765
|
+
expect(min.name.escapedText).toBe('min');
|
|
766
|
+
expect(min.type.kind).toBe(ts.SyntaxKind.NumericLiteral);
|
|
767
|
+
expect(min.type.text).toBe('0');
|
|
768
|
+
|
|
769
|
+
// Check for string keyword on the second typeArgument
|
|
770
|
+
expect(typeofMinMax.kind).toBe(ts.SyntaxKind.NumberKeyword);
|
|
621
771
|
});
|
|
622
772
|
});
|
|
623
773
|
|
|
@@ -2,25 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const fs = require('fs-extra');
|
|
5
|
+
const adminTsConfig = require('../../tsconfigs/admin.json');
|
|
5
6
|
|
|
6
7
|
module.exports = async (dest) => {
|
|
7
8
|
const tsConfig = {
|
|
8
|
-
|
|
9
|
-
lib: ['es2019', 'es2020.promise', 'es2020.bigint', 'es2020.string', 'DOM'],
|
|
10
|
-
noImplicitAny: false,
|
|
11
|
-
module: 'es2020',
|
|
12
|
-
target: 'es5',
|
|
13
|
-
jsx: 'react',
|
|
14
|
-
allowJs: true,
|
|
15
|
-
strict: true,
|
|
16
|
-
moduleResolution: 'node',
|
|
17
|
-
skipLibCheck: true,
|
|
18
|
-
esModuleInterop: true,
|
|
19
|
-
allowSyntheticDefaultImports: true,
|
|
20
|
-
resolveJsonModule: true,
|
|
21
|
-
noEmit: false,
|
|
22
|
-
incremental: true,
|
|
23
|
-
},
|
|
9
|
+
...adminTsConfig,
|
|
24
10
|
include: ['../../../src/admin/*', '../../../src/**/**/admin/src/*'],
|
|
25
11
|
exclude: ['node_modules', '**/*.test.js', '*.js'],
|
|
26
12
|
};
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const ts = require('typescript');
|
|
4
4
|
const _ = require('lodash/fp');
|
|
5
5
|
|
|
6
6
|
const { addImport } = require('../imports');
|
|
7
7
|
const { getTypeNode, toTypeLiteral, withAttributeNamespace, NAMESPACES } = require('./utils');
|
|
8
8
|
const mappers = require('./mappers');
|
|
9
9
|
|
|
10
|
+
const { factory } = ts;
|
|
11
|
+
|
|
10
12
|
/**
|
|
11
13
|
* Create the base type node for a given attribute
|
|
12
14
|
*
|
|
@@ -100,14 +102,39 @@ const getAttributeModifiers = (attribute) => {
|
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
// Min / Max
|
|
103
|
-
// TODO: Always provide a second type argument for min/max (ie: resolve the attribute scalar type with a `GetAttributeType<${mappers[attribute][0]}>` (useful for biginter (string values)))
|
|
104
105
|
if (!_.isNil(attribute.min) || !_.isNil(attribute.max)) {
|
|
105
106
|
const minMaxProperties = _.pick(['min', 'max'], attribute);
|
|
107
|
+
const { min, max } = minMaxProperties;
|
|
108
|
+
|
|
109
|
+
const typeofMin = typeof min;
|
|
110
|
+
const typeofMax = typeof max;
|
|
111
|
+
|
|
112
|
+
// Throws error if min/max exist but have different types to prevent unexpected behavior
|
|
113
|
+
if (min !== undefined && max !== undefined && typeofMin !== typeofMax) {
|
|
114
|
+
throw new Error('typeof min/max values mismatch');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
let typeKeyword;
|
|
118
|
+
|
|
119
|
+
// use 'string'
|
|
120
|
+
if (typeofMin === 'string' || typeofMax === 'string') {
|
|
121
|
+
typeKeyword = ts.SyntaxKind.StringKeyword;
|
|
122
|
+
}
|
|
123
|
+
// use 'number'
|
|
124
|
+
else if (typeofMin === 'number' || typeofMax === 'number') {
|
|
125
|
+
typeKeyword = ts.SyntaxKind.NumberKeyword;
|
|
126
|
+
}
|
|
127
|
+
// invalid type
|
|
128
|
+
else {
|
|
129
|
+
throw new Error(
|
|
130
|
+
`Invalid data type for min/max options. Must be string, number or undefined, but found { min: ${min} (${typeofMin}), max: ${max} (${typeofMax}) }`
|
|
131
|
+
);
|
|
132
|
+
}
|
|
106
133
|
|
|
107
134
|
modifiers.push(
|
|
108
135
|
factory.createTypeReferenceNode(
|
|
109
136
|
factory.createIdentifier(withAttributeNamespace('SetMinMax')),
|
|
110
|
-
[toTypeLiteral(minMaxProperties)]
|
|
137
|
+
[toTypeLiteral(minMaxProperties), factory.createKeywordTypeNode(typeKeyword)]
|
|
111
138
|
)
|
|
112
139
|
);
|
|
113
140
|
}
|
|
@@ -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,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/typescript-utils",
|
|
3
|
-
"version": "0.0.0-next.
|
|
3
|
+
"version": "0.0.0-next.fd9757603c653ca239c45d6e28ab536d2dae0b39",
|
|
4
4
|
"description": "Typescript support for Strapi",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"strapi",
|
|
7
|
+
"generators"
|
|
8
|
+
],
|
|
5
9
|
"repository": {
|
|
6
10
|
"type": "git",
|
|
7
11
|
"url": "git://github.com/strapi/strapi.git",
|
|
8
12
|
"directory": "packages/utils/typescript"
|
|
9
13
|
},
|
|
10
|
-
"keywords": [
|
|
11
|
-
"strapi",
|
|
12
|
-
"generators"
|
|
13
|
-
],
|
|
14
14
|
"license": "SEE LICENSE IN LICENSE",
|
|
15
15
|
"author": {
|
|
16
16
|
"name": "Strapi Solutions SAS",
|
|
@@ -36,15 +36,15 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"chalk": "4.1.2",
|
|
39
|
-
"cli-table3": "0.6.
|
|
39
|
+
"cli-table3": "0.6.5",
|
|
40
40
|
"fs-extra": "10.0.0",
|
|
41
41
|
"lodash": "4.17.21",
|
|
42
42
|
"prettier": "2.8.4",
|
|
43
43
|
"typescript": "5.2.2"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|
|
46
|
-
"node": ">=
|
|
46
|
+
"node": ">=18.0.0 <=20.x.x",
|
|
47
47
|
"npm": ">=6.0.0"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "fd9757603c653ca239c45d6e28ab536d2dae0b39"
|
|
50
50
|
}
|
package/tsconfigs/admin.json
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
-
|
|
4
3
|
"compilerOptions": {
|
|
5
4
|
"target": "ESNext",
|
|
6
5
|
"module": "ESNext",
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
"
|
|
6
|
+
"moduleResolution": "Bundler",
|
|
7
|
+
"useDefineForClassFields": true,
|
|
8
|
+
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
|
9
|
+
"allowJs": false,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
10
12
|
"allowSyntheticDefaultImports": true,
|
|
11
|
-
"resolveJsonModule": true,
|
|
12
|
-
"isolatedModules": true,
|
|
13
|
-
|
|
14
|
-
"noImplicitAny": false,
|
|
15
13
|
"strict": true,
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"skipLibCheck": true,
|
|
20
|
-
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"resolveJsonModule": true,
|
|
16
|
+
"noEmit": true,
|
|
21
17
|
"jsx": "react-jsx"
|
|
22
18
|
}
|
|
23
19
|
}
|
package/tsconfigs/server.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"module": "CommonJS",
|
|
6
|
+
"moduleResolution": "Node",
|
|
7
|
+
"lib": ["ES2020"],
|
|
8
|
+
"target": "ES2019",
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
"strict": false,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
"incremental": true,
|
|
15
|
+
"esModuleInterop": true,
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"noEmitOnError": true,
|
|
18
|
+
"noImplicitThis": true
|
|
19
|
+
}
|
|
20
20
|
}
|