@oak-digital/types-4-strapi-2 0.5.4 → 0.5.5
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/README.md +4 -3
- package/lib/program/InterfaceManager.js +2 -2
- package/package.json +9 -8
- package/lib/.prettierrc.json +0 -7
- package/lib/case/index.d.ts +0 -4
- package/lib/case/index.js +0 -47
- package/lib/interface/Attributes.d.ts +0 -11
- package/lib/interface/Attributes.js +0 -167
- package/lib/interface/InterfaceManager.d.ts +0 -39
- package/lib/interface/InterfaceManager.js +0 -396
- package/lib/interface/interfaceCreator.d.ts +0 -0
- package/lib/interface/interfaceCreator.js +0 -7
- package/lib/interface/interfaceWriter.d.ts +0 -2
- package/lib/interface/interfaceWriter.js +0 -46
- package/lib/interface/schemaReader.d.ts +0 -14
- package/lib/interface/schemaReader.js +0 -177
- package/lib/src/index.d.ts +0 -1
- package/lib/src/index.js +0 -25
- package/lib/src/interface/Attributes.d.ts +0 -11
- package/lib/src/interface/Attributes.js +0 -148
- package/lib/src/interface/BuiltinComponentInterface.d.ts +0 -5
- package/lib/src/interface/BuiltinComponentInterface.js +0 -36
- package/lib/src/interface/BuiltinInterface.d.ts +0 -5
- package/lib/src/interface/BuiltinInterface.js +0 -33
- package/lib/src/interface/ComponentInterface.d.ts +0 -8
- package/lib/src/interface/ComponentInterface.js +0 -58
- package/lib/src/interface/Interface.d.ts +0 -31
- package/lib/src/interface/Interface.js +0 -112
- package/lib/src/interface/InterfaceManager.d.ts +0 -25
- package/lib/src/interface/InterfaceManager.js +0 -288
- package/lib/src/interface/builtinInterfaces.d.ts +0 -4
- package/lib/src/interface/builtinInterfaces.js +0 -81
- package/lib/src/interface/schemaReader.d.ts +0 -14
- package/lib/src/interface/schemaReader.js +0 -172
- package/lib/src/utils/index.d.ts +0 -3
- package/lib/src/utils/index.js +0 -67
package/README.md
CHANGED
|
@@ -154,12 +154,13 @@ export default (plugin: any) => {
|
|
|
154
154
|
To build this project, use the following command
|
|
155
155
|
|
|
156
156
|
```bash
|
|
157
|
-
|
|
157
|
+
pnpm run build
|
|
158
158
|
```
|
|
159
159
|
|
|
160
160
|
## Publishing
|
|
161
161
|
|
|
162
162
|
```bash
|
|
163
|
-
|
|
164
|
-
|
|
163
|
+
pnpm version # major | minor | patch
|
|
164
|
+
pnpm run build
|
|
165
|
+
pnpm publish
|
|
165
166
|
```
|
|
@@ -67,7 +67,7 @@ var ComponentInterface_1 = __importDefault(require("../interface/ComponentInterf
|
|
|
67
67
|
var Interface_1 = __importDefault(require("../interface/Interface"));
|
|
68
68
|
var reader_1 = require("../content-types/reader");
|
|
69
69
|
var prettier_1 = __importDefault(require("prettier"));
|
|
70
|
-
var
|
|
70
|
+
var change_case_1 = require("change-case");
|
|
71
71
|
var casing_1 = require("../utils/casing/");
|
|
72
72
|
var events_1 = require("../events");
|
|
73
73
|
var plugins_1 = require("../plugins");
|
|
@@ -203,7 +203,7 @@ var InterfaceManager = /** @class */ (function () {
|
|
|
203
203
|
var componentName = name;
|
|
204
204
|
var strapiName = "".concat(categoryName, ".").concat(name);
|
|
205
205
|
var componentPrefix = "".concat(_this.Options.componentPrefix).concat(_this.Options.useCategoryPrefix
|
|
206
|
-
? (0,
|
|
206
|
+
? (0, change_case_1.pascalCase)(categoryName)
|
|
207
207
|
: '');
|
|
208
208
|
var prefix = _this.Options.componentPrefixOverridesPrefix
|
|
209
209
|
? componentPrefix
|
package/package.json
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oak-digital/types-4-strapi-2",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5",
|
|
4
4
|
"description": "Typescript interface generator for Strapi 4 models",
|
|
5
5
|
"bin": {
|
|
6
6
|
"t4s": "./bin/index.js"
|
|
7
7
|
},
|
|
8
|
-
"scripts": {
|
|
9
|
-
"build": "tsc -p .",
|
|
10
|
-
"testtypes": "node ./bin/index.js",
|
|
11
|
-
"lint": "eslint src/",
|
|
12
|
-
"t4s": "node ./bin/index.js"
|
|
13
|
-
},
|
|
14
8
|
"repository": {
|
|
15
9
|
"type": "git",
|
|
16
10
|
"url": "git+https://github.com/Oak-Digital/types-4-strapi-2.git"
|
|
@@ -33,11 +27,18 @@
|
|
|
33
27
|
"@typescript-eslint/eslint-plugin": "^5.33.1",
|
|
34
28
|
"@typescript-eslint/parser": "^5.33.1",
|
|
35
29
|
"eslint": "^8.22.0",
|
|
30
|
+
"rimraf": "^4.4.1",
|
|
36
31
|
"typescript": "^4.7.4"
|
|
37
32
|
},
|
|
38
33
|
"dependencies": {
|
|
39
34
|
"change-case": "^4.1.2",
|
|
40
35
|
"commander": "^9.4.0",
|
|
41
36
|
"prettier": "^2.7.1"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "rimraf lib && tsc -p .",
|
|
40
|
+
"testtypes": "node ./bin/index.js",
|
|
41
|
+
"lint": "eslint src/",
|
|
42
|
+
"t4s": "node ./bin/index.js"
|
|
42
43
|
}
|
|
43
|
-
}
|
|
44
|
+
}
|
package/lib/.prettierrc.json
DELETED
package/lib/case/index.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export declare const caseTypesArray: readonly ["camel", "capital", "dot", "snake", "pascal", "constant", "kebab"];
|
|
2
|
-
export declare type caseType = typeof caseTypesArray[number];
|
|
3
|
-
export declare function checkCaseType(caseName: caseType): caseName is caseType;
|
|
4
|
-
export declare function changeCase(text: string, caseName: caseType): string;
|
package/lib/case/index.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.changeCase = exports.checkCaseType = exports.caseTypesArray = void 0;
|
|
4
|
-
var change_case_1 = require("change-case");
|
|
5
|
-
exports.caseTypesArray = [
|
|
6
|
-
'camel',
|
|
7
|
-
'capital',
|
|
8
|
-
'dot',
|
|
9
|
-
'snake',
|
|
10
|
-
'pascal',
|
|
11
|
-
'constant',
|
|
12
|
-
'kebab',
|
|
13
|
-
];
|
|
14
|
-
function checkCaseType(caseName) {
|
|
15
|
-
return exports.caseTypesArray.includes(caseName);
|
|
16
|
-
}
|
|
17
|
-
exports.checkCaseType = checkCaseType;
|
|
18
|
-
function changeCase(text, caseName) {
|
|
19
|
-
var name = text;
|
|
20
|
-
switch (caseName) {
|
|
21
|
-
case 'dot':
|
|
22
|
-
name = (0, change_case_1.dotCase)(name);
|
|
23
|
-
break;
|
|
24
|
-
case 'camel':
|
|
25
|
-
name = (0, change_case_1.camelCase)(name);
|
|
26
|
-
break;
|
|
27
|
-
case 'snake':
|
|
28
|
-
name = (0, change_case_1.snakeCase)(name);
|
|
29
|
-
break;
|
|
30
|
-
case 'capital':
|
|
31
|
-
name = (0, change_case_1.capitalCase)(name);
|
|
32
|
-
break;
|
|
33
|
-
case 'constant':
|
|
34
|
-
name = (0, change_case_1.constantCase)(name);
|
|
35
|
-
break;
|
|
36
|
-
case 'kebab':
|
|
37
|
-
// paramcase is the same as kebab
|
|
38
|
-
name = (0, change_case_1.paramCase)(name);
|
|
39
|
-
break;
|
|
40
|
-
case 'pascal':
|
|
41
|
-
default:
|
|
42
|
-
name = (0, change_case_1.pascalCase)(name);
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
return name;
|
|
46
|
-
}
|
|
47
|
-
exports.changeCase = changeCase;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { RelationNames } from './Interface';
|
|
2
|
-
export default class Attributes {
|
|
3
|
-
Attrs: Record<string, Record<string, any>>;
|
|
4
|
-
private RelationNames;
|
|
5
|
-
constructor(attr: Record<string, Record<string, any>>, relationNames: RelationNames);
|
|
6
|
-
isAttributeOptional(attr: any): boolean;
|
|
7
|
-
getDependencies(): any[];
|
|
8
|
-
attributeToString(attrName: string, attr: any): string;
|
|
9
|
-
toFieldsString(): string;
|
|
10
|
-
toString(): string;
|
|
11
|
-
}
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var Attributes = /** @class */ (function () {
|
|
4
|
-
function Attributes(attr, relationNames) {
|
|
5
|
-
this.RelationNames = {};
|
|
6
|
-
this.Attrs = attr;
|
|
7
|
-
this.RelationNames = relationNames;
|
|
8
|
-
}
|
|
9
|
-
Attributes.prototype.isAttributeOptional = function (attr) {
|
|
10
|
-
// If it is a component / relation / dynamiczone it is always optional due to population
|
|
11
|
-
switch (attr.type) {
|
|
12
|
-
case 'nested':
|
|
13
|
-
return attr.nullable === true;
|
|
14
|
-
case 'component':
|
|
15
|
-
case 'dynamiczone':
|
|
16
|
-
case 'relation':
|
|
17
|
-
return true;
|
|
18
|
-
default:
|
|
19
|
-
break;
|
|
20
|
-
}
|
|
21
|
-
return false;
|
|
22
|
-
};
|
|
23
|
-
Attributes.prototype.getDependencies = function () {
|
|
24
|
-
var dependencies = [];
|
|
25
|
-
for (var attrName in this.Attrs) {
|
|
26
|
-
var attr = this.Attrs[attrName];
|
|
27
|
-
var dependencyNames = [];
|
|
28
|
-
switch (attr.type) {
|
|
29
|
-
case 'nested':
|
|
30
|
-
var attrs = new Attributes(attr.fields, this.RelationNames);
|
|
31
|
-
dependencyNames.push.apply(dependencyNames, attrs.getDependencies());
|
|
32
|
-
break;
|
|
33
|
-
case 'relation':
|
|
34
|
-
dependencyNames.push(attr.target);
|
|
35
|
-
break;
|
|
36
|
-
case 'component':
|
|
37
|
-
dependencyNames.push(attr.component);
|
|
38
|
-
break;
|
|
39
|
-
case 'media':
|
|
40
|
-
dependencyNames.push('builtins::Media');
|
|
41
|
-
break;
|
|
42
|
-
case 'dynamiczone':
|
|
43
|
-
dependencyNames.push.apply(dependencyNames, attr.components);
|
|
44
|
-
break;
|
|
45
|
-
default:
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
// // If the current dependency is the interface itself, do not report it as a dependency
|
|
49
|
-
// if (dependencyName === strapiName) {
|
|
50
|
-
// continue;
|
|
51
|
-
// }
|
|
52
|
-
dependencyNames.forEach(function (dependencyName) {
|
|
53
|
-
if (!dependencies.includes(dependencyName)) {
|
|
54
|
-
dependencies.push(dependencyName);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
return dependencies;
|
|
59
|
-
};
|
|
60
|
-
Attributes.prototype.attributeToString = function (attrName, attr) {
|
|
61
|
-
var _this = this;
|
|
62
|
-
var _a, _b, _c, _d;
|
|
63
|
-
var optionalString = this.isAttributeOptional(attr) ? '?' : '';
|
|
64
|
-
var orNull = ' | null';
|
|
65
|
-
var requiredString = attr.required !== true ? orNull : '';
|
|
66
|
-
var str = " ".concat(attrName).concat(optionalString, ": ");
|
|
67
|
-
var isArray = false;
|
|
68
|
-
switch (attr.type) {
|
|
69
|
-
// types-4-strapi-2 specific, used for builtin types
|
|
70
|
-
case 'nested':
|
|
71
|
-
// Be careful with recursion
|
|
72
|
-
// console.log(attr);
|
|
73
|
-
var nullableString = ((_a = attr === null || attr === void 0 ? void 0 : attr.nullable) !== null && _a !== void 0 ? _a : false) ? ' | null' : '';
|
|
74
|
-
var newAttrs = new Attributes(attr.fields, this.RelationNames);
|
|
75
|
-
str += newAttrs.toString() + nullableString;
|
|
76
|
-
break;
|
|
77
|
-
case 'relation':
|
|
78
|
-
var apiName = attr.target;
|
|
79
|
-
// console.log(this.RelationNames, apiName)
|
|
80
|
-
var dependencyName = (_c = (_b = this.RelationNames[apiName]) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : 'any';
|
|
81
|
-
var relationMultipleString = attr.relation.endsWith('ToMany') ? '[]' : orNull;
|
|
82
|
-
str += "{ data: ".concat(dependencyName).concat(relationMultipleString, "; }");
|
|
83
|
-
break;
|
|
84
|
-
case 'component':
|
|
85
|
-
var componentName = attr.component;
|
|
86
|
-
var relationNameObj = this.RelationNames[componentName];
|
|
87
|
-
var dependencyComponentName = relationNameObj.name;
|
|
88
|
-
isArray = (_d = attr.repeatable) !== null && _d !== void 0 ? _d : false;
|
|
89
|
-
str += dependencyComponentName;
|
|
90
|
-
break;
|
|
91
|
-
case 'media':
|
|
92
|
-
var mediaMultipleString = attr.multiple ? '[]' : requiredString;
|
|
93
|
-
str += "{ data: ".concat(this.RelationNames['builtins::Media'].name).concat(mediaMultipleString, "; }");
|
|
94
|
-
break;
|
|
95
|
-
case 'password':
|
|
96
|
-
return null;
|
|
97
|
-
case 'enumeration':
|
|
98
|
-
var hasDefault = 'default' in attr;
|
|
99
|
-
var enums = attr.enum.map(function (en) { return "\"".concat(en, "\""); });
|
|
100
|
-
enums.push('null');
|
|
101
|
-
var typeString = enums.join(' | ');
|
|
102
|
-
str += typeString;
|
|
103
|
-
break;
|
|
104
|
-
case 'dynamiczone':
|
|
105
|
-
// console.log(attr.components);
|
|
106
|
-
var relations = attr.components
|
|
107
|
-
.map(function (componentName) { return _this.RelationNames[componentName].name; });
|
|
108
|
-
// console.log(relations);
|
|
109
|
-
var relationsString = relations.join(' | ');
|
|
110
|
-
// console.log(relationsString);
|
|
111
|
-
str += "Array<".concat(relationsString, ">");
|
|
112
|
-
break;
|
|
113
|
-
case 'string':
|
|
114
|
-
case 'text':
|
|
115
|
-
case 'richtext':
|
|
116
|
-
case 'email':
|
|
117
|
-
case 'uid':
|
|
118
|
-
str += 'string';
|
|
119
|
-
str += requiredString;
|
|
120
|
-
break;
|
|
121
|
-
case 'integer':
|
|
122
|
-
case 'biginteger':
|
|
123
|
-
case 'decimal':
|
|
124
|
-
case 'float':
|
|
125
|
-
str += 'number';
|
|
126
|
-
str += requiredString;
|
|
127
|
-
break;
|
|
128
|
-
case 'date':
|
|
129
|
-
case 'datetime':
|
|
130
|
-
case 'time':
|
|
131
|
-
str += 'string';
|
|
132
|
-
str += requiredString;
|
|
133
|
-
break;
|
|
134
|
-
case 'boolean':
|
|
135
|
-
str += attr.type;
|
|
136
|
-
str += requiredString;
|
|
137
|
-
break;
|
|
138
|
-
case 'json':
|
|
139
|
-
default:
|
|
140
|
-
str += 'any';
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
var isArrayString = isArray ? '[]' : '';
|
|
144
|
-
str += "".concat(isArrayString, ";");
|
|
145
|
-
return str;
|
|
146
|
-
};
|
|
147
|
-
Attributes.prototype.toFieldsString = function () {
|
|
148
|
-
var strings = [];
|
|
149
|
-
for (var attrName in this.Attrs) {
|
|
150
|
-
var attr = this.Attrs[attrName];
|
|
151
|
-
var attrString = this.attributeToString(attrName, attr);
|
|
152
|
-
if (attrString === null) {
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
strings.push(attrString);
|
|
156
|
-
}
|
|
157
|
-
return strings.map(function (s) { return "".concat(s, "\n"); }).join('');
|
|
158
|
-
};
|
|
159
|
-
Attributes.prototype.toString = function () {
|
|
160
|
-
var strings = ['{'];
|
|
161
|
-
strings.push(this.toFieldsString());
|
|
162
|
-
strings.push('}');
|
|
163
|
-
return strings.join('\n');
|
|
164
|
-
};
|
|
165
|
-
return Attributes;
|
|
166
|
-
}());
|
|
167
|
-
exports.default = Attributes;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import EventEmitter from 'events';
|
|
3
|
-
export default class InterfaceManager {
|
|
4
|
-
private Interfaces;
|
|
5
|
-
private OutRoot;
|
|
6
|
-
private StrapiSrcRoot;
|
|
7
|
-
private Options;
|
|
8
|
-
private PrettierOptions;
|
|
9
|
-
eventEmitter: EventEmitter;
|
|
10
|
-
static BaseOptions: {
|
|
11
|
-
prefix: string;
|
|
12
|
-
useCategoryPrefix: boolean;
|
|
13
|
-
componentPrefix: string;
|
|
14
|
-
componentPrefixOverridesPrefix: boolean;
|
|
15
|
-
builtinsPrefix: string;
|
|
16
|
-
builtinsPrefixOverridesPrefix: boolean;
|
|
17
|
-
deleteOld: boolean;
|
|
18
|
-
prettierFile: any;
|
|
19
|
-
fileCaseType: "pascal" | "camel" | "capital" | "dot" | "snake" | "constant" | "kebab";
|
|
20
|
-
folderCaseType: "pascal" | "camel" | "capital" | "dot" | "snake" | "constant" | "kebab";
|
|
21
|
-
enabledPlugins: "url-alias"[];
|
|
22
|
-
};
|
|
23
|
-
constructor(outRoot: string, strapiSrcRoot: string, options?: Partial<typeof InterfaceManager['BaseOptions']>);
|
|
24
|
-
registerPlugins(): void;
|
|
25
|
-
validateOptions(): void;
|
|
26
|
-
loadPrettierConfig(): Promise<void>;
|
|
27
|
-
readSchemas(): Promise<{
|
|
28
|
-
apiSchemas: any[];
|
|
29
|
-
componentSchemas: any[];
|
|
30
|
-
}>;
|
|
31
|
-
createInterfaces(): Promise<void>;
|
|
32
|
-
createBuiltinInterfaces(): void;
|
|
33
|
-
injectDependencies(): void;
|
|
34
|
-
deleteOldFolders(): Promise<void>;
|
|
35
|
-
makeFolders(): Promise<void>;
|
|
36
|
-
writeInterfaces(): Promise<void>;
|
|
37
|
-
writeIndexFile(): Promise<void>;
|
|
38
|
-
run(): Promise<void>;
|
|
39
|
-
}
|