@oak-digital/types-4-strapi-2 0.5.4 → 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 +21 -8
- 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 +12 -9
- 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/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
- 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.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/{lib/interface/interfaceCreator.d.ts → tests/strapi-project/database/migrations/.gitkeep} +0 -0
|
@@ -1,47 +1,28 @@
|
|
|
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
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.ExtraType = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
_this.typeString = typeString;
|
|
26
|
-
_this.updateStrapiName();
|
|
27
|
-
return _this;
|
|
4
|
+
const File_1 = require("../file/File");
|
|
5
|
+
class ExtraType extends File_1.File {
|
|
6
|
+
constructor(typeString, baseName, relativeDirectoryPath, fileCaseType = 'pascal') {
|
|
7
|
+
super(baseName, relativeDirectoryPath, fileCaseType);
|
|
8
|
+
this.typeString = typeString;
|
|
9
|
+
this.updateStrapiName();
|
|
28
10
|
}
|
|
29
|
-
|
|
11
|
+
getDependencies() {
|
|
30
12
|
return [];
|
|
31
|
-
}
|
|
32
|
-
|
|
13
|
+
}
|
|
14
|
+
getStrapiName() {
|
|
33
15
|
return this.StrapiName;
|
|
34
|
-
}
|
|
35
|
-
|
|
16
|
+
}
|
|
17
|
+
getFullName() {
|
|
36
18
|
return this.BaseName;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
this.StrapiName =
|
|
40
|
-
}
|
|
41
|
-
|
|
19
|
+
}
|
|
20
|
+
updateStrapiName() {
|
|
21
|
+
this.StrapiName = `builtins::${this.BaseName}`;
|
|
22
|
+
}
|
|
23
|
+
toString() {
|
|
42
24
|
// TODO: make this more dynamic
|
|
43
|
-
return
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
}(File_1.File));
|
|
25
|
+
return `export ${this.typeString}`;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
47
28
|
exports.ExtraType = ExtraType;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ExtraType } from
|
|
1
|
+
import { ExtraType } from './ExtraType';
|
|
2
2
|
export declare const createExtraTypes: () => ExtraType[];
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createExtraTypes = void 0;
|
|
4
|
-
|
|
4
|
+
const ExtraType_1 = require("./ExtraType");
|
|
5
5
|
/* const requiredByString = `type RequiredBy<T, K extends string> = Required<Pick<T, K>> & Omit<T, K>;`; */
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
const requiredByString = `type RequiredBy<T, K extends string> = Required<Pick<T, Extract<K, keyof T>>> & Omit<T, Extract<K, keyof T>>;`;
|
|
7
|
+
const extractNestedString = 'type ExtractNested<T, K extends string> = T extends `${K}.${infer U}` ? U : never;';
|
|
8
|
+
const extractFlatString = 'type ExtractFlat<T extends string> = T extends `${infer U}.${string}` ? U : T;';
|
|
9
|
+
const extraTypeData = {
|
|
10
|
+
RequiredBy: requiredByString,
|
|
11
|
+
ExtractNested: extractNestedString,
|
|
12
|
+
ExtractFlat: extractFlatString,
|
|
13
13
|
};
|
|
14
|
-
|
|
15
|
-
return Object.entries(extraTypeData).map(
|
|
16
|
-
|
|
17
|
-
var extraType = new ExtraType_1.ExtraType(typeString, name, 'builtins');
|
|
14
|
+
const createExtraTypes = () => {
|
|
15
|
+
return Object.entries(extraTypeData).map(([name, typeString]) => {
|
|
16
|
+
const extraType = new ExtraType_1.ExtraType(typeString, name, 'builtins');
|
|
18
17
|
return extraType;
|
|
19
18
|
});
|
|
20
19
|
};
|
package/lib/file/File.d.ts
CHANGED
package/lib/file/File.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.File = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (fileCaseType === void 0) { fileCaseType = 'pascal'; }
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const posix_1 = require("path/posix");
|
|
6
|
+
const casing_1 = require("../utils/casing");
|
|
7
|
+
class File {
|
|
8
|
+
constructor(baseName, relativeDirectoryPath, fileCaseType = 'pascal') {
|
|
10
9
|
this.Relations = []; // Components and relations
|
|
11
10
|
this.RelationNames = {};
|
|
12
11
|
this.RelationNamesCounter = {};
|
|
@@ -15,58 +14,60 @@ var File = /** @class */ (function () {
|
|
|
15
14
|
this.FileCase = fileCaseType;
|
|
16
15
|
this.RelativeDirectoryPath = relativeDirectoryPath;
|
|
17
16
|
}
|
|
18
|
-
|
|
19
|
-
var _this = this;
|
|
17
|
+
setRelations(relations) {
|
|
20
18
|
this.Relations = relations;
|
|
21
19
|
this.RelationNames = {};
|
|
22
20
|
this.RelationNamesCounter = {};
|
|
23
|
-
this.Relations.forEach(
|
|
24
|
-
|
|
21
|
+
this.Relations.forEach((file) => {
|
|
22
|
+
let name = file.getFullName();
|
|
25
23
|
// FIXME: clean up this mess...
|
|
26
|
-
if (file.getStrapiName() !==
|
|
24
|
+
if (file.getStrapiName() !== this.getStrapiName()) {
|
|
27
25
|
// Avoid duplicate names
|
|
28
|
-
if (name in
|
|
29
|
-
name += ++
|
|
26
|
+
if (name in this.RelationNamesCounter) {
|
|
27
|
+
name += ++this.RelationNamesCounter[name];
|
|
30
28
|
}
|
|
31
29
|
else {
|
|
32
|
-
|
|
30
|
+
this.RelationNamesCounter[name] = 0;
|
|
33
31
|
}
|
|
34
32
|
}
|
|
35
|
-
|
|
33
|
+
this.RelationNames[file.getStrapiName()] = { name, file };
|
|
36
34
|
});
|
|
37
|
-
}
|
|
35
|
+
}
|
|
38
36
|
// For typescript import from index file
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
getRelativeRootPath() {
|
|
38
|
+
const path = (0, posix_1.join)(this.RelativeDirectoryPath, this.getFileBaseName());
|
|
41
39
|
return (0, utils_1.prefixDotSlash)(path);
|
|
42
|
-
}
|
|
43
|
-
|
|
40
|
+
}
|
|
41
|
+
getBaseName() {
|
|
44
42
|
return this.BaseName;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
}
|
|
44
|
+
getRelativeRootPathFile() {
|
|
45
|
+
return `${this.getRelativeRootPath()}.ts`;
|
|
46
|
+
}
|
|
47
|
+
getRelativeRootDir() {
|
|
48
|
+
const path = (0, posix_1.dirname)(this.getRelativeRootPathFile());
|
|
51
49
|
return path;
|
|
52
|
-
}
|
|
53
|
-
|
|
50
|
+
}
|
|
51
|
+
getFileBaseName() {
|
|
54
52
|
return (0, casing_1.changeCase)(this.getBaseName(), this.FileCase);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (strapiName ===
|
|
53
|
+
}
|
|
54
|
+
getTsImports() {
|
|
55
|
+
return Object.keys(this.RelationNames)
|
|
56
|
+
.map((strapiName) => {
|
|
57
|
+
if (strapiName === this.getStrapiName()) {
|
|
60
58
|
return '';
|
|
61
59
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
60
|
+
const relationName = this.RelationNames[strapiName].name;
|
|
61
|
+
const inter = this.RelationNames[strapiName].file;
|
|
62
|
+
const importPath = (0, utils_1.prefixDotSlash)((0, posix_1.relative)(this.getRelativeRootDir(), inter.getRelativeRootPath()));
|
|
63
|
+
const fullName = inter.getFullName();
|
|
64
|
+
const importNameString = fullName === relationName
|
|
65
|
+
? fullName
|
|
66
|
+
: `${fullName} as ${relationName}`;
|
|
67
|
+
return `import { ${importNameString} } from '${importPath}';`;
|
|
68
|
+
})
|
|
69
|
+
.filter((s) => s)
|
|
70
|
+
.join('\n');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
72
73
|
exports.File = File;
|
package/lib/index.js
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
5
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
15
|
+
const commander_1 = require("commander");
|
|
16
|
+
const InterfaceManager_1 = __importDefault(require("./program/InterfaceManager"));
|
|
17
|
+
const by_file_1 = require("./readers/by-file");
|
|
18
|
+
const basic_writer_1 = require("./writers/basic-writer");
|
|
19
|
+
const prettier_1 = __importDefault(require("prettier"));
|
|
20
|
+
const load_strapi_1 = require("./readers/load-strapi");
|
|
21
|
+
commander_1.program.name('t4s');
|
|
10
22
|
commander_1.program
|
|
11
|
-
.option('-i, --in <dir>', 'The
|
|
23
|
+
.option('-i, --in <dir>', 'The root directory for strapi', './')
|
|
12
24
|
.option('-o, --out <dir>', 'The output directory to output the types to', './types')
|
|
25
|
+
.option('-r, --reader <reader>', 'The reader to use (possible: by-file, load-strapi. See docs for more info)', 'by-file')
|
|
13
26
|
.option('--prefix <prefix>', 'A prefix for all generated interfaces', 'I')
|
|
14
27
|
.option('--component-prefix <prefix>', 'A prefix for components', '')
|
|
15
28
|
.option('-D, --delete-old', 'CAUTION: This option is equivalent to running rm -rf on the output directory first')
|
|
@@ -18,17 +31,42 @@ commander_1.program
|
|
|
18
31
|
.option('--plugins <plugins...>', 'A list of enabled plugins in the target strapi project that modify content-types')
|
|
19
32
|
.option('--prettier <file>', 'The prettier config file to use for formatting typescript interfaces');
|
|
20
33
|
commander_1.program.parse();
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
const options = commander_1.program.opts();
|
|
35
|
+
const { in: input, out, componentPrefix, prefix, prettier: prettierFile, deleteOld, fileCase: fileCaseType, folderCase: folderCaseType, plugins, reader: readerName, } = options;
|
|
36
|
+
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
const defaultPrettierOptions = {
|
|
38
|
+
parser: 'typescript',
|
|
39
|
+
};
|
|
40
|
+
let prettierOptions = defaultPrettierOptions;
|
|
41
|
+
if (prettierFile) {
|
|
42
|
+
const resolved = yield prettier_1.default.resolveConfig(prettierFile, {
|
|
43
|
+
editorconfig: true,
|
|
44
|
+
});
|
|
45
|
+
prettierOptions = Object.assign(Object.assign({}, defaultPrettierOptions), resolved);
|
|
46
|
+
}
|
|
47
|
+
let reader;
|
|
48
|
+
switch (readerName) {
|
|
49
|
+
case 'by-file':
|
|
50
|
+
reader = new by_file_1.ByFileContentTypeReader(input);
|
|
51
|
+
break;
|
|
52
|
+
case 'load-strapi':
|
|
53
|
+
reader = new load_strapi_1.LoadStrapiReader(input);
|
|
54
|
+
break;
|
|
55
|
+
default:
|
|
56
|
+
throw new Error(`Unknown reader: ${readerName}`);
|
|
57
|
+
}
|
|
58
|
+
const writer = new basic_writer_1.BasicWriter(out, {
|
|
59
|
+
deleteOld,
|
|
60
|
+
prettierOptions,
|
|
61
|
+
});
|
|
62
|
+
const manager = new InterfaceManager_1.default(reader, writer, {
|
|
63
|
+
componentPrefix,
|
|
64
|
+
prefix,
|
|
65
|
+
fileCaseType,
|
|
66
|
+
folderCaseType,
|
|
67
|
+
enabledPlugins: plugins,
|
|
68
|
+
});
|
|
69
|
+
manager.run().catch((err) => {
|
|
70
|
+
console.error(err);
|
|
71
|
+
});
|
|
72
|
+
}))();
|
|
@@ -1,36 +1,18 @@
|
|
|
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
|
-
if (prefix === void 0) { prefix = ''; }
|
|
26
|
-
return _super.call(this, baseName, attributes, relativeDirectoryPath, 'builtins', fileCase, prefix, {
|
|
6
|
+
const ComponentInterface_1 = __importDefault(require("./ComponentInterface"));
|
|
7
|
+
class BuiltinComponentInterface extends ComponentInterface_1.default {
|
|
8
|
+
constructor(baseName, attributes, relativeDirectoryPath, fileCase, prefix = '') {
|
|
9
|
+
super(baseName, 'builtins', attributes, relativeDirectoryPath, '', fileCase, prefix, {
|
|
27
10
|
hasId: false,
|
|
28
11
|
hasComponent: false,
|
|
29
|
-
})
|
|
12
|
+
});
|
|
30
13
|
}
|
|
31
|
-
|
|
32
|
-
this.StrapiName =
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
}(ComponentInterface_1.default));
|
|
14
|
+
updateStrapiName() {
|
|
15
|
+
this.StrapiName = `builtins::${this.BaseName}`;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
36
18
|
exports.default = BuiltinComponentInterface;
|
|
@@ -2,5 +2,4 @@ import { caseType } from '../utils/casing';
|
|
|
2
2
|
import Interface from './Interface';
|
|
3
3
|
export default class BuiltinInterface extends Interface {
|
|
4
4
|
constructor(baseName: string, attributes: any, relativeDirectoryPath: string, fileCase: caseType, prefix?: string);
|
|
5
|
-
updateStrapiName(): void;
|
|
6
5
|
}
|
|
@@ -1,33 +1,12 @@
|
|
|
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
|
-
if (prefix === void 0) { prefix = ''; }
|
|
26
|
-
return _super.call(this, baseName, attributes, relativeDirectoryPath, fileCase, prefix) || this;
|
|
6
|
+
const Interface_1 = __importDefault(require("./Interface"));
|
|
7
|
+
class BuiltinInterface extends Interface_1.default {
|
|
8
|
+
constructor(baseName, attributes, relativeDirectoryPath, fileCase, prefix = '') {
|
|
9
|
+
super(baseName, 'builtins', attributes, relativeDirectoryPath, null, fileCase, prefix);
|
|
27
10
|
}
|
|
28
|
-
|
|
29
|
-
this.StrapiName = "builtins::".concat(this.BaseName);
|
|
30
|
-
};
|
|
31
|
-
return BuiltinInterface;
|
|
32
|
-
}(Interface_1.default));
|
|
11
|
+
}
|
|
33
12
|
exports.default = BuiltinInterface;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { Namespace } from '../readers/types/content-type-reader';
|
|
1
2
|
import { caseType } from '../utils/casing';
|
|
2
3
|
import Interface from './Interface';
|
|
3
4
|
export default class ComponentInterface extends Interface {
|
|
4
5
|
protected Category: string;
|
|
5
6
|
protected Options: Record<string, any>;
|
|
6
|
-
constructor(baseName: string, attributes: any, relativeDirectoryPath: string, category: string, fileCase: caseType, prefix?: string, options?: Record<string, any>);
|
|
7
|
+
constructor(baseName: string, namespace: Namespace, attributes: any, relativeDirectoryPath: string, category: string, fileCase: caseType, prefix?: string, options?: Record<string, any>);
|
|
7
8
|
updateStrapiName(): void;
|
|
8
9
|
getInerfaceString(): string;
|
|
9
10
|
getInterfaceFieldsString(): string;
|
|
@@ -1,61 +1,44 @@
|
|
|
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
|
-
_this.Options = {
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
const Interface_1 = __importDefault(require("./Interface"));
|
|
8
|
+
class ComponentInterface extends Interface_1.default {
|
|
9
|
+
constructor(baseName, namespace, attributes, relativeDirectoryPath, category, fileCase, prefix = '', options = {}) {
|
|
10
|
+
// TODO: Component interface doesn't really make sense to extend from Interface, but it works for now.
|
|
11
|
+
// we should transition to use composition instead of this type of inheritance
|
|
12
|
+
super(baseName, namespace, attributes, relativeDirectoryPath, category, fileCase, prefix);
|
|
13
|
+
this.Options = {
|
|
30
14
|
hasId: true,
|
|
31
15
|
hasComponent: true,
|
|
32
16
|
};
|
|
33
|
-
|
|
17
|
+
this.Category = category;
|
|
34
18
|
// this.Attributes.id = {
|
|
35
19
|
// type: "number", // Components have a id field with a number
|
|
36
20
|
// required: true,
|
|
37
21
|
// };
|
|
38
|
-
|
|
39
|
-
Object.assign(
|
|
40
|
-
|
|
22
|
+
this.updateStrapiName();
|
|
23
|
+
Object.assign(this.Options, options);
|
|
24
|
+
}
|
|
25
|
+
updateStrapiName() {
|
|
26
|
+
this.StrapiName = `${this.Category}.${this.getBaseName()}`;
|
|
41
27
|
}
|
|
42
|
-
ComponentInterface.prototype.updateStrapiName = function () {
|
|
43
|
-
this.StrapiName = "".concat(this.Category, ".").concat(this.getBaseName());
|
|
44
|
-
};
|
|
45
28
|
// TODO: make this more dynamic in parent
|
|
46
|
-
|
|
47
|
-
|
|
29
|
+
getInerfaceString() {
|
|
30
|
+
const isPopulatable = this.hasPopulatableAttributes();
|
|
48
31
|
/* const populateString = isPopulatable ? `<${POPULATE_GENERIC_NAME} extends string | never = never>` : ''; */
|
|
49
|
-
|
|
32
|
+
const strArr = [];
|
|
50
33
|
if (isPopulatable) {
|
|
51
|
-
strArr.push(
|
|
34
|
+
strArr.push(`export type ${this.getFullName()}`);
|
|
52
35
|
}
|
|
53
36
|
else {
|
|
54
|
-
strArr.push(
|
|
37
|
+
strArr.push(`export interface ${this.getFullName()}`);
|
|
55
38
|
}
|
|
56
39
|
if (isPopulatable) {
|
|
57
|
-
strArr.push(
|
|
58
|
-
strArr.push(
|
|
40
|
+
strArr.push(`<${constants_1.POPULATE_GENERIC_NAME} extends string | never = never>`);
|
|
41
|
+
strArr.push(` = ${this.RelationNames['builtins::RequiredBy'].name}<`);
|
|
59
42
|
}
|
|
60
43
|
strArr.push(' {\n');
|
|
61
44
|
strArr.push(this.getInterfaceFieldsString());
|
|
@@ -71,21 +54,20 @@ var ComponentInterface = /** @class */ (function (_super) {
|
|
|
71
54
|
// required by end
|
|
72
55
|
strArr.push('>');
|
|
73
56
|
}
|
|
74
|
-
|
|
57
|
+
const str = strArr.join('');
|
|
75
58
|
return str;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
59
|
+
}
|
|
60
|
+
getInterfaceFieldsString() {
|
|
61
|
+
const attrs = this.getAttributes();
|
|
62
|
+
let str = '';
|
|
63
|
+
const { hasId, hasComponent } = this.Options;
|
|
81
64
|
if (hasId) {
|
|
82
65
|
str += ' id: number;\n';
|
|
83
66
|
}
|
|
84
67
|
if (hasComponent) {
|
|
85
|
-
str +=
|
|
68
|
+
str += ` __component: "${this.getStrapiName()}";\n`;
|
|
86
69
|
}
|
|
87
70
|
return str + attrs.toFieldsString();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
}(Interface_1.default));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
91
73
|
exports.default = ComponentInterface;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { caseType } from '../utils/casing';
|
|
2
2
|
import Attributes from '../attributes/Attributes';
|
|
3
3
|
import { File } from '../file/File';
|
|
4
|
+
import { AttributeWithNested } from './builtinInterfaces';
|
|
5
|
+
import { Namespace } from '../readers/types/content-type-reader';
|
|
4
6
|
export default class Interface extends File {
|
|
5
7
|
private NamePrefix;
|
|
6
|
-
protected Attributes:
|
|
7
|
-
|
|
8
|
+
protected Attributes: Record<string, AttributeWithNested>;
|
|
9
|
+
protected CollectionName: string | null;
|
|
10
|
+
protected Namespace: Namespace;
|
|
11
|
+
constructor(baseName: string, namespace: Namespace, attributes: Record<string, AttributeWithNested>, relativeDirectoryPath: string, collectionName?: string | null, fileCaseType?: caseType, prefix?: string);
|
|
8
12
|
protected updateStrapiName(): void;
|
|
9
13
|
getStrapiName(): string;
|
|
10
14
|
getDependencies(): string[];
|