@strapi/typescript-utils 4.4.0-beta.4 → 4.4.0-rc.1
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.
|
@@ -438,6 +438,61 @@ describe('Attributes', () => {
|
|
|
438
438
|
});
|
|
439
439
|
});
|
|
440
440
|
|
|
441
|
+
describe('Custom field', () => {
|
|
442
|
+
test('No custom field', () => {
|
|
443
|
+
const attribute = {};
|
|
444
|
+
const modifiers = getAttributeModifiers(attribute);
|
|
445
|
+
|
|
446
|
+
expect(modifiers).toHaveLength(0);
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
test('Basic custom field', () => {
|
|
450
|
+
const attribute = {
|
|
451
|
+
type: 'string',
|
|
452
|
+
customField: 'plugin::color-picker.color',
|
|
453
|
+
};
|
|
454
|
+
const modifiers = getAttributeModifiers(attribute);
|
|
455
|
+
|
|
456
|
+
expect(modifiers).toHaveLength(1);
|
|
457
|
+
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
458
|
+
expect(modifiers[0].typeName.escapedText).toBe('CustomField');
|
|
459
|
+
expect(modifiers[0].typeArguments).toHaveLength(1);
|
|
460
|
+
expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.StringLiteral);
|
|
461
|
+
expect(modifiers[0].typeArguments[0].text).toBe('plugin::color-picker.color');
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
test('Advanced custom field', () => {
|
|
465
|
+
const attribute = {
|
|
466
|
+
type: 'string',
|
|
467
|
+
customField: 'plugin::color-picker.color',
|
|
468
|
+
options: {
|
|
469
|
+
format: 'hex',
|
|
470
|
+
},
|
|
471
|
+
};
|
|
472
|
+
const modifiers = getAttributeModifiers(attribute);
|
|
473
|
+
|
|
474
|
+
expect(modifiers).toHaveLength(1);
|
|
475
|
+
expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference);
|
|
476
|
+
expect(modifiers[0].typeName.escapedText).toBe('CustomField');
|
|
477
|
+
expect(modifiers[0].typeArguments).toHaveLength(2);
|
|
478
|
+
expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.StringLiteral);
|
|
479
|
+
expect(modifiers[0].typeArguments[0].text).toBe('plugin::color-picker.color');
|
|
480
|
+
expect(modifiers[0].typeArguments[1].kind).toBe(ts.SyntaxKind.TypeLiteral);
|
|
481
|
+
expect(modifiers[0].typeArguments[1].members).toHaveLength(1);
|
|
482
|
+
expect(modifiers[0].typeArguments[1].members[0].kind).toBe(
|
|
483
|
+
ts.SyntaxKind.PropertyDeclaration
|
|
484
|
+
);
|
|
485
|
+
expect(modifiers[0].typeArguments[1].members[0].name.escapedText).toBe('format');
|
|
486
|
+
expect(modifiers[0].typeArguments[1].members[0].kind).toBe(
|
|
487
|
+
ts.SyntaxKind.PropertyDeclaration
|
|
488
|
+
);
|
|
489
|
+
expect(modifiers[0].typeArguments[1].members[0].type.kind).toBe(
|
|
490
|
+
ts.SyntaxKind.StringLiteral
|
|
491
|
+
);
|
|
492
|
+
expect(modifiers[0].typeArguments[1].members[0].type.text).toBe('hex');
|
|
493
|
+
});
|
|
494
|
+
});
|
|
495
|
+
|
|
441
496
|
describe('Plugin Options', () => {
|
|
442
497
|
test('No plugin options', () => {
|
|
443
498
|
const attribute = {};
|
|
@@ -70,6 +70,22 @@ const getAttributeModifiers = (attribute) => {
|
|
|
70
70
|
);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
// Custom field
|
|
74
|
+
if (attribute.customField) {
|
|
75
|
+
addImport('CustomField');
|
|
76
|
+
|
|
77
|
+
const customFieldUid = factory.createStringLiteral(attribute.customField);
|
|
78
|
+
const typeArguments = [customFieldUid];
|
|
79
|
+
|
|
80
|
+
if (attribute.options) {
|
|
81
|
+
typeArguments.push(toTypeLiteral(attribute.options));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
modifiers.push(
|
|
85
|
+
factory.createTypeReferenceNode(factory.createIdentifier('CustomField'), typeArguments)
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
73
89
|
// Plugin Options
|
|
74
90
|
if (!_.isEmpty(attribute.pluginOptions)) {
|
|
75
91
|
addImport('SetPluginOptions');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/typescript-utils",
|
|
3
|
-
"version": "4.4.0-
|
|
3
|
+
"version": "4.4.0-rc.1",
|
|
4
4
|
"description": "Typescript support for Strapi",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"node": ">=14.19.1 <=18.x.x",
|
|
36
36
|
"npm": ">=6.0.0"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "00c788873a5b25b63ccdeaad6b0781d26c26d90d"
|
|
39
39
|
}
|