@oak-digital/types-4-strapi-2 0.5.5 → 1.0.0-beta.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.
- package/.eslintrc.json +2 -1
- package/CHANGELOG.md +7 -0
- package/README.md +17 -5
- package/lib/attributes/Attributes.d.ts +4 -3
- package/lib/attributes/Attributes.js +102 -78
- package/lib/content-types/reader.js +49 -145
- package/lib/extra-types/ExtraType.d.ts +2 -2
- package/lib/extra-types/ExtraType.js +19 -38
- package/lib/extra-types/createExtraTypes.d.ts +1 -1
- package/lib/extra-types/createExtraTypes.js +11 -12
- package/lib/file/File.d.ts +1 -1
- package/lib/file/File.js +44 -43
- package/lib/index.js +57 -19
- package/lib/interface/BuiltinComponentInterface.js +9 -27
- package/lib/interface/BuiltinInterface.d.ts +0 -1
- package/lib/interface/BuiltinInterface.js +5 -26
- package/lib/interface/ComponentInterface.d.ts +2 -1
- package/lib/interface/ComponentInterface.js +30 -48
- package/lib/interface/Interface.d.ts +6 -2
- package/lib/interface/Interface.js +69 -70
- package/lib/interface/builtinInterfaces.d.ts +1941 -2
- package/lib/interface/builtinInterfaces.js +56 -46
- package/lib/plugins/PluginManager.d.ts +8 -2
- package/lib/plugins/PluginManager.js +28 -35
- package/lib/plugins/draft-and-publish/index.d.ts +1 -1
- package/lib/plugins/draft-and-publish/index.js +17 -21
- package/lib/plugins/i18n/index.d.ts +1 -1
- package/lib/plugins/i18n/index.js +17 -22
- package/lib/plugins/index.js +4 -4
- package/lib/plugins/types.d.ts +1 -1
- package/lib/plugins/types.js +1 -4
- package/lib/plugins/url-alias/index.js +12 -15
- package/lib/plugins/url-alias/type.js +21 -32
- package/lib/program/InterfaceManager.d.ts +374 -24
- package/lib/program/InterfaceManager.js +128 -376
- package/lib/readers/by-file.d.ts +321 -0
- package/lib/readers/by-file.js +116 -0
- package/lib/readers/load-strapi/index.d.ts +319 -0
- package/lib/readers/load-strapi/index.js +106 -0
- package/lib/readers/types/attributes.d.ts +1639 -0
- package/lib/readers/types/attributes.js +144 -0
- package/lib/readers/types/component.d.ts +723 -0
- package/lib/readers/types/component.js +11 -0
- package/lib/readers/types/content-type-reader.d.ts +16 -0
- package/lib/readers/types/content-type-reader.js +2 -0
- package/lib/readers/types/content-type.d.ts +766 -0
- package/lib/readers/types/content-type.js +16 -0
- package/lib/utils/casing/index.js +2 -2
- package/lib/utils/index.js +5 -39
- package/lib/writers/basic-writer.d.ts +24 -0
- package/lib/writers/basic-writer.js +75 -0
- package/lib/writers/types/writer.d.ts +4 -0
- package/lib/writers/types/writer.js +2 -0
- package/package.json +4 -2
- package/tests/strapi-project/.editorconfig +16 -0
- package/tests/strapi-project/.env.example +6 -0
- package/tests/strapi-project/README.md +57 -0
- package/tests/strapi-project/config/admin.ts +13 -0
- package/tests/strapi-project/config/api.ts +7 -0
- package/tests/strapi-project/config/database.ts +93 -0
- package/tests/strapi-project/config/middlewares.ts +12 -0
- package/tests/strapi-project/config/server.ts +10 -0
- package/tests/strapi-project/database/migrations/.gitkeep +0 -0
- package/tests/strapi-project/favicon.png +0 -0
- package/tests/strapi-project/package-lock.json +16125 -0
- package/tests/strapi-project/package.json +30 -0
- package/tests/strapi-project/public/robots.txt +3 -0
- package/tests/strapi-project/public/uploads/.gitkeep +0 -0
- package/tests/strapi-project/src/admin/app.example.tsx +35 -0
- package/tests/strapi-project/src/admin/webpack.config.example.js +9 -0
- package/tests/strapi-project/src/api/.gitkeep +0 -0
- package/tests/strapi-project/src/api/collection-1/content-types/collection-1/schema.json +18 -0
- package/tests/strapi-project/src/api/collection-1/content-types/generated-type/schema.json +18 -0
- package/tests/strapi-project/src/api/collection-1/controllers/collection-1.ts +7 -0
- package/tests/strapi-project/src/api/collection-1/controllers/generated-type.ts +7 -0
- package/tests/strapi-project/src/api/collection-1/routes/collection-1.ts +7 -0
- package/tests/strapi-project/src/api/collection-1/routes/generated-type.ts +7 -0
- package/tests/strapi-project/src/api/collection-1/services/collection-1.ts +7 -0
- package/tests/strapi-project/src/api/collection-1/services/generated-type.ts +7 -0
- package/tests/strapi-project/src/api/standalone-controller/controllers/standalone-controller.ts +13 -0
- package/tests/strapi-project/src/components/my-category/all-types.json +88 -0
- package/tests/strapi-project/src/components/other-category/sub-component.json +12 -0
- package/tests/strapi-project/src/extensions/.gitkeep +0 -0
- package/tests/strapi-project/src/index.ts +18 -0
|
@@ -1,104 +1,103 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
4
|
};
|
|
20
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
6
|
+
const posix_1 = require("path/posix");
|
|
7
|
+
const Attributes_1 = __importDefault(require("../attributes/Attributes"));
|
|
8
|
+
const change_case_1 = require("change-case");
|
|
9
|
+
const constants_1 = require("../constants");
|
|
10
|
+
const File_1 = require("../file/File");
|
|
11
|
+
class Interface extends File_1.File {
|
|
12
|
+
constructor(baseName, namespace, attributes, relativeDirectoryPath, collectionName = null, fileCaseType = 'pascal', prefix = '') {
|
|
13
|
+
super(baseName, (0, posix_1.join)(namespace, relativeDirectoryPath), fileCaseType);
|
|
14
|
+
this.NamePrefix = '';
|
|
15
|
+
this.CollectionName = collectionName;
|
|
16
|
+
this.Namespace = namespace;
|
|
17
|
+
this.updateStrapiName();
|
|
18
|
+
this.NamePrefix = prefix;
|
|
19
|
+
this.Attributes = attributes;
|
|
35
20
|
if (!attributes) {
|
|
36
|
-
console.warn(
|
|
21
|
+
console.warn(`Warning: attributes for ${this.getStrapiName()} is empty!`);
|
|
37
22
|
}
|
|
38
|
-
return _this;
|
|
39
23
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
24
|
+
updateStrapiName() {
|
|
25
|
+
const collectionString = this.CollectionName
|
|
26
|
+
? `${this.CollectionName}.`
|
|
27
|
+
: '';
|
|
28
|
+
this.StrapiName = `${this.Namespace}::${collectionString}${this.BaseName}`;
|
|
29
|
+
}
|
|
30
|
+
getStrapiName() {
|
|
45
31
|
return this.StrapiName;
|
|
46
|
-
}
|
|
47
|
-
|
|
32
|
+
}
|
|
33
|
+
getDependencies() {
|
|
48
34
|
return this.getAttributes().getDependencies();
|
|
49
|
-
}
|
|
50
|
-
|
|
35
|
+
}
|
|
36
|
+
getFullName() {
|
|
37
|
+
let name;
|
|
38
|
+
if (this.Namespace === 'admin') {
|
|
39
|
+
name = `Admin${this.BaseName}`;
|
|
40
|
+
}
|
|
41
|
+
else if (this.CollectionName === null) {
|
|
42
|
+
name = this.BaseName;
|
|
43
|
+
}
|
|
44
|
+
else if (this.CollectionName === this.BaseName) {
|
|
45
|
+
name = this.BaseName;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
name = this.StrapiName.split('::').pop();
|
|
49
|
+
}
|
|
51
50
|
// TODO: use correct casing from options
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
const pascalName = (0, change_case_1.pascalCase)(name);
|
|
52
|
+
const fullName = `${this.NamePrefix}${pascalName}`;
|
|
53
|
+
return fullName;
|
|
54
|
+
}
|
|
55
|
+
hasPopulatableAttributes() {
|
|
56
56
|
return this.getAttributes().hasPopulatableAttributes();
|
|
57
|
-
}
|
|
58
|
-
|
|
57
|
+
}
|
|
58
|
+
getAttributes() {
|
|
59
59
|
return new Attributes_1.default(this.Attributes, this.RelationNames);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
}
|
|
61
|
+
attributesToString() {
|
|
62
|
+
const attrs = this.getAttributes();
|
|
63
63
|
return attrs.toString();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
}
|
|
65
|
+
getInerfaceString() {
|
|
66
|
+
const isPopulatable = this.hasPopulatableAttributes();
|
|
67
67
|
/* const populateString = isPopulatable ? `<${POPULATE_GENERIC_NAME} extends string | never = never>` : ''; */
|
|
68
|
-
|
|
68
|
+
const strArr = [`export interface ${this.getFullName()}`];
|
|
69
69
|
if (isPopulatable) {
|
|
70
|
-
strArr.push(
|
|
70
|
+
strArr.push(`<${constants_1.POPULATE_GENERIC_NAME} extends string | never = never>`);
|
|
71
71
|
}
|
|
72
72
|
strArr.push(' {\n');
|
|
73
73
|
strArr.push(this.getInterfaceFieldsString());
|
|
74
74
|
strArr.push('}');
|
|
75
|
-
|
|
75
|
+
const str = strArr.join('');
|
|
76
76
|
return str;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
}
|
|
78
|
+
getInterfaceFieldsString() {
|
|
79
|
+
const populatable = this.hasPopulatableAttributes();
|
|
80
|
+
const strArr = [];
|
|
81
81
|
strArr.push('id: number;\n');
|
|
82
|
-
strArr.push(
|
|
82
|
+
strArr.push(`attributes: `);
|
|
83
83
|
if (populatable) {
|
|
84
|
-
strArr.push(
|
|
84
|
+
strArr.push(`RequiredBy<`);
|
|
85
85
|
}
|
|
86
|
-
strArr.push(
|
|
86
|
+
strArr.push(`${this.attributesToString()}`);
|
|
87
87
|
if (populatable) {
|
|
88
88
|
// The comma for required by
|
|
89
89
|
strArr.push(', ');
|
|
90
90
|
// second generic for required by
|
|
91
|
-
strArr.push(
|
|
91
|
+
strArr.push(`${this.RelationNames['builtins::ExtractFlat'].name}<${constants_1.POPULATE_GENERIC_NAME}>`);
|
|
92
92
|
// close the required by
|
|
93
93
|
strArr.push('>');
|
|
94
94
|
}
|
|
95
|
-
strArr.push(
|
|
95
|
+
strArr.push(`\n`);
|
|
96
96
|
return strArr.join('');
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
}
|
|
98
|
+
toString() {
|
|
99
|
+
const strings = [this.getTsImports(), this.getInerfaceString()];
|
|
100
100
|
return strings.join('\n');
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
}(File_1.File));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
104
103
|
exports.default = Interface;
|