@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.
Files changed (116) hide show
  1. package/.eslintrc.json +2 -1
  2. package/CHANGELOG.md +7 -0
  3. package/README.md +21 -8
  4. package/lib/attributes/Attributes.d.ts +4 -3
  5. package/lib/attributes/Attributes.js +102 -78
  6. package/lib/content-types/reader.js +49 -145
  7. package/lib/extra-types/ExtraType.d.ts +2 -2
  8. package/lib/extra-types/ExtraType.js +19 -38
  9. package/lib/extra-types/createExtraTypes.d.ts +1 -1
  10. package/lib/extra-types/createExtraTypes.js +11 -12
  11. package/lib/file/File.d.ts +1 -1
  12. package/lib/file/File.js +44 -43
  13. package/lib/index.js +57 -19
  14. package/lib/interface/BuiltinComponentInterface.js +9 -27
  15. package/lib/interface/BuiltinInterface.d.ts +0 -1
  16. package/lib/interface/BuiltinInterface.js +5 -26
  17. package/lib/interface/ComponentInterface.d.ts +2 -1
  18. package/lib/interface/ComponentInterface.js +30 -48
  19. package/lib/interface/Interface.d.ts +6 -2
  20. package/lib/interface/Interface.js +69 -70
  21. package/lib/interface/builtinInterfaces.d.ts +1941 -2
  22. package/lib/interface/builtinInterfaces.js +56 -46
  23. package/lib/plugins/PluginManager.d.ts +8 -2
  24. package/lib/plugins/PluginManager.js +28 -35
  25. package/lib/plugins/draft-and-publish/index.d.ts +1 -1
  26. package/lib/plugins/draft-and-publish/index.js +17 -21
  27. package/lib/plugins/i18n/index.d.ts +1 -1
  28. package/lib/plugins/i18n/index.js +17 -22
  29. package/lib/plugins/index.js +4 -4
  30. package/lib/plugins/types.d.ts +1 -1
  31. package/lib/plugins/types.js +1 -4
  32. package/lib/plugins/url-alias/index.js +12 -15
  33. package/lib/plugins/url-alias/type.js +21 -32
  34. package/lib/program/InterfaceManager.d.ts +374 -24
  35. package/lib/program/InterfaceManager.js +128 -376
  36. package/lib/readers/by-file.d.ts +321 -0
  37. package/lib/readers/by-file.js +116 -0
  38. package/lib/readers/load-strapi/index.d.ts +319 -0
  39. package/lib/readers/load-strapi/index.js +106 -0
  40. package/lib/readers/types/attributes.d.ts +1639 -0
  41. package/lib/readers/types/attributes.js +144 -0
  42. package/lib/readers/types/component.d.ts +723 -0
  43. package/lib/readers/types/component.js +11 -0
  44. package/lib/readers/types/content-type-reader.d.ts +16 -0
  45. package/lib/readers/types/content-type-reader.js +2 -0
  46. package/lib/readers/types/content-type.d.ts +766 -0
  47. package/lib/readers/types/content-type.js +16 -0
  48. package/lib/utils/casing/index.js +2 -2
  49. package/lib/utils/index.js +5 -39
  50. package/lib/writers/basic-writer.d.ts +24 -0
  51. package/lib/writers/basic-writer.js +75 -0
  52. package/lib/writers/types/writer.d.ts +4 -0
  53. package/lib/writers/types/writer.js +2 -0
  54. package/package.json +12 -9
  55. package/tests/strapi-project/.editorconfig +16 -0
  56. package/tests/strapi-project/.env.example +6 -0
  57. package/tests/strapi-project/README.md +57 -0
  58. package/tests/strapi-project/config/admin.ts +13 -0
  59. package/tests/strapi-project/config/api.ts +7 -0
  60. package/tests/strapi-project/config/database.ts +93 -0
  61. package/tests/strapi-project/config/middlewares.ts +12 -0
  62. package/tests/strapi-project/config/server.ts +10 -0
  63. package/tests/strapi-project/favicon.png +0 -0
  64. package/tests/strapi-project/package-lock.json +16125 -0
  65. package/tests/strapi-project/package.json +30 -0
  66. package/tests/strapi-project/public/robots.txt +3 -0
  67. package/tests/strapi-project/public/uploads/.gitkeep +0 -0
  68. package/tests/strapi-project/src/admin/app.example.tsx +35 -0
  69. package/tests/strapi-project/src/admin/webpack.config.example.js +9 -0
  70. package/tests/strapi-project/src/api/.gitkeep +0 -0
  71. package/tests/strapi-project/src/api/collection-1/content-types/collection-1/schema.json +18 -0
  72. package/tests/strapi-project/src/api/collection-1/content-types/generated-type/schema.json +18 -0
  73. package/tests/strapi-project/src/api/collection-1/controllers/collection-1.ts +7 -0
  74. package/tests/strapi-project/src/api/collection-1/controllers/generated-type.ts +7 -0
  75. package/tests/strapi-project/src/api/collection-1/routes/collection-1.ts +7 -0
  76. package/tests/strapi-project/src/api/collection-1/routes/generated-type.ts +7 -0
  77. package/tests/strapi-project/src/api/collection-1/services/collection-1.ts +7 -0
  78. package/tests/strapi-project/src/api/collection-1/services/generated-type.ts +7 -0
  79. package/tests/strapi-project/src/api/standalone-controller/controllers/standalone-controller.ts +13 -0
  80. package/tests/strapi-project/src/components/my-category/all-types.json +88 -0
  81. package/tests/strapi-project/src/components/other-category/sub-component.json +12 -0
  82. package/tests/strapi-project/src/extensions/.gitkeep +0 -0
  83. package/tests/strapi-project/src/index.ts +18 -0
  84. package/lib/.prettierrc.json +0 -7
  85. package/lib/case/index.d.ts +0 -4
  86. package/lib/case/index.js +0 -47
  87. package/lib/interface/Attributes.d.ts +0 -11
  88. package/lib/interface/Attributes.js +0 -167
  89. package/lib/interface/InterfaceManager.d.ts +0 -39
  90. package/lib/interface/InterfaceManager.js +0 -396
  91. package/lib/interface/interfaceCreator.js +0 -7
  92. package/lib/interface/interfaceWriter.d.ts +0 -2
  93. package/lib/interface/interfaceWriter.js +0 -46
  94. package/lib/interface/schemaReader.d.ts +0 -14
  95. package/lib/interface/schemaReader.js +0 -177
  96. package/lib/src/index.d.ts +0 -1
  97. package/lib/src/index.js +0 -25
  98. package/lib/src/interface/Attributes.d.ts +0 -11
  99. package/lib/src/interface/Attributes.js +0 -148
  100. package/lib/src/interface/BuiltinComponentInterface.d.ts +0 -5
  101. package/lib/src/interface/BuiltinComponentInterface.js +0 -36
  102. package/lib/src/interface/BuiltinInterface.d.ts +0 -5
  103. package/lib/src/interface/BuiltinInterface.js +0 -33
  104. package/lib/src/interface/ComponentInterface.d.ts +0 -8
  105. package/lib/src/interface/ComponentInterface.js +0 -58
  106. package/lib/src/interface/Interface.d.ts +0 -31
  107. package/lib/src/interface/Interface.js +0 -112
  108. package/lib/src/interface/InterfaceManager.d.ts +0 -25
  109. package/lib/src/interface/InterfaceManager.js +0 -288
  110. package/lib/src/interface/builtinInterfaces.d.ts +0 -4
  111. package/lib/src/interface/builtinInterfaces.js +0 -81
  112. package/lib/src/interface/schemaReader.d.ts +0 -14
  113. package/lib/src/interface/schemaReader.js +0 -172
  114. package/lib/src/utils/index.d.ts +0 -3
  115. package/lib/src/utils/index.js +0 -67
  116. /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
- var File_1 = require("../file/File");
20
- var ExtraType = /** @class */ (function (_super) {
21
- __extends(ExtraType, _super);
22
- function ExtraType(typeString, baseName, relativeDirectoryPath, fileCaseType) {
23
- if (fileCaseType === void 0) { fileCaseType = 'pascal'; }
24
- var _this = _super.call(this, baseName, relativeDirectoryPath, fileCaseType) || this;
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
- ExtraType.prototype.getDependencies = function () {
11
+ getDependencies() {
30
12
  return [];
31
- };
32
- ExtraType.prototype.getStrapiName = function () {
13
+ }
14
+ getStrapiName() {
33
15
  return this.StrapiName;
34
- };
35
- ExtraType.prototype.getFullName = function () {
16
+ }
17
+ getFullName() {
36
18
  return this.BaseName;
37
- };
38
- ExtraType.prototype.updateStrapiName = function () {
39
- this.StrapiName = "builtins::".concat(this.BaseName);
40
- };
41
- ExtraType.prototype.toString = function () {
19
+ }
20
+ updateStrapiName() {
21
+ this.StrapiName = `builtins::${this.BaseName}`;
22
+ }
23
+ toString() {
42
24
  // TODO: make this more dynamic
43
- return "export ".concat(this.typeString);
44
- };
45
- return ExtraType;
46
- }(File_1.File));
25
+ return `export ${this.typeString}`;
26
+ }
27
+ }
47
28
  exports.ExtraType = ExtraType;
@@ -1,2 +1,2 @@
1
- import { ExtraType } from "./ExtraType";
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
- var ExtraType_1 = require("./ExtraType");
4
+ const ExtraType_1 = require("./ExtraType");
5
5
  /* const requiredByString = `type RequiredBy<T, K extends string> = Required<Pick<T, K>> & Omit<T, K>;`; */
6
- var requiredByString = "type RequiredBy<T, K extends string> = Required<Pick<T, Extract<K, keyof T>>> & Omit<T, Extract<K, keyof T>>;";
7
- var extractNestedString = 'type ExtractNested<T, K extends string> = T extends `${K}.${infer U}` ? U : never;';
8
- var extractFlatString = 'type ExtractFlat<T extends string> = T extends `${infer U}.${string}` ? U : T;';
9
- var extraTypeData = {
10
- 'RequiredBy': requiredByString,
11
- 'ExtractNested': extractNestedString,
12
- 'ExtractFlat': extractFlatString,
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
- var createExtraTypes = function () {
15
- return Object.entries(extraTypeData).map(function (_a) {
16
- var name = _a[0], typeString = _a[1];
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
  };
@@ -1,4 +1,4 @@
1
- import { caseType } from "../utils/casing";
1
+ import { caseType } from '../utils/casing';
2
2
  export declare type RelationNames = Record<string, {
3
3
  name: string;
4
4
  file: File;
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
- var utils_1 = require("../utils");
5
- var posix_1 = require("path/posix");
6
- var casing_1 = require("../utils/casing");
7
- var File = /** @class */ (function () {
8
- function File(baseName, relativeDirectoryPath, fileCaseType) {
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
- File.prototype.setRelations = function (relations) {
19
- var _this = this;
17
+ setRelations(relations) {
20
18
  this.Relations = relations;
21
19
  this.RelationNames = {};
22
20
  this.RelationNamesCounter = {};
23
- this.Relations.forEach(function (file) {
24
- var name = file.getFullName();
21
+ this.Relations.forEach((file) => {
22
+ let name = file.getFullName();
25
23
  // FIXME: clean up this mess...
26
- if (file.getStrapiName() !== _this.getStrapiName()) {
24
+ if (file.getStrapiName() !== this.getStrapiName()) {
27
25
  // Avoid duplicate names
28
- if (name in _this.RelationNamesCounter) {
29
- name += ++_this.RelationNamesCounter[name];
26
+ if (name in this.RelationNamesCounter) {
27
+ name += ++this.RelationNamesCounter[name];
30
28
  }
31
29
  else {
32
- _this.RelationNamesCounter[name] = 0;
30
+ this.RelationNamesCounter[name] = 0;
33
31
  }
34
32
  }
35
- _this.RelationNames[file.getStrapiName()] = { name: name, file: file };
33
+ this.RelationNames[file.getStrapiName()] = { name, file };
36
34
  });
37
- };
35
+ }
38
36
  // For typescript import from index file
39
- File.prototype.getRelativeRootPath = function () {
40
- var path = (0, posix_1.join)(this.RelativeDirectoryPath, this.getFileBaseName());
37
+ getRelativeRootPath() {
38
+ const path = (0, posix_1.join)(this.RelativeDirectoryPath, this.getFileBaseName());
41
39
  return (0, utils_1.prefixDotSlash)(path);
42
- };
43
- File.prototype.getBaseName = function () {
40
+ }
41
+ getBaseName() {
44
42
  return this.BaseName;
45
- };
46
- File.prototype.getRelativeRootPathFile = function () {
47
- return "".concat(this.getRelativeRootPath(), ".ts");
48
- };
49
- File.prototype.getRelativeRootDir = function () {
50
- var path = (0, posix_1.dirname)(this.getRelativeRootPathFile());
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
- File.prototype.getFileBaseName = function () {
50
+ }
51
+ getFileBaseName() {
54
52
  return (0, casing_1.changeCase)(this.getBaseName(), this.FileCase);
55
- };
56
- File.prototype.getTsImports = function () {
57
- var _this = this;
58
- return Object.keys(this.RelationNames).map(function (strapiName) {
59
- if (strapiName === _this.getStrapiName()) {
53
+ }
54
+ getTsImports() {
55
+ return Object.keys(this.RelationNames)
56
+ .map((strapiName) => {
57
+ if (strapiName === this.getStrapiName()) {
60
58
  return '';
61
59
  }
62
- var relationName = _this.RelationNames[strapiName].name;
63
- var inter = _this.RelationNames[strapiName].file;
64
- var importPath = (0, utils_1.prefixDotSlash)((0, posix_1.relative)(_this.getRelativeRootDir(), inter.getRelativeRootPath()));
65
- var fullName = inter.getFullName();
66
- var importNameString = fullName === relationName ? fullName : "".concat(fullName, " as ").concat(relationName);
67
- return "import { ".concat(importNameString, " } from '").concat(importPath, "';");
68
- }).filter(function (s) { return s; }).join('\n');
69
- };
70
- return File;
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
- var commander_1 = require("commander");
7
- var InterfaceManager_1 = __importDefault(require("./program/InterfaceManager"));
8
- commander_1.program
9
- .name('t4s');
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 src directory for strapi', './src')
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
- var options = commander_1.program.opts();
22
- var input = options.in, out = options.out, componentPrefix = options.componentPrefix, prefix = options.prefix, prettierFile = options.prettier, deleteOld = options.deleteOld, fileCaseType = options.fileCase, folderCaseType = options.folderCase, plugins = options.plugins;
23
- var manager = new InterfaceManager_1.default(out, input, {
24
- componentPrefix: componentPrefix,
25
- prefix: prefix,
26
- prettierFile: prettierFile,
27
- deleteOld: deleteOld,
28
- fileCaseType: fileCaseType,
29
- folderCaseType: folderCaseType,
30
- enabledPlugins: plugins,
31
- });
32
- manager.run().catch(function (err) {
33
- console.error(err);
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
- var ComponentInterface_1 = __importDefault(require("./ComponentInterface"));
22
- var BuiltinComponentInterface = /** @class */ (function (_super) {
23
- __extends(BuiltinComponentInterface, _super);
24
- function BuiltinComponentInterface(baseName, attributes, relativeDirectoryPath, fileCase, prefix) {
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
- }) || this;
12
+ });
30
13
  }
31
- BuiltinComponentInterface.prototype.updateStrapiName = function () {
32
- this.StrapiName = "builtins::".concat(this.BaseName);
33
- };
34
- return BuiltinComponentInterface;
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
- var Interface_1 = __importDefault(require("./Interface"));
22
- var BuiltinInterface = /** @class */ (function (_super) {
23
- __extends(BuiltinInterface, _super);
24
- function BuiltinInterface(baseName, attributes, relativeDirectoryPath, fileCase, prefix) {
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
- BuiltinInterface.prototype.updateStrapiName = function () {
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
- var constants_1 = require("../constants");
22
- var Interface_1 = __importDefault(require("./Interface"));
23
- var ComponentInterface = /** @class */ (function (_super) {
24
- __extends(ComponentInterface, _super);
25
- function ComponentInterface(baseName, attributes, relativeDirectoryPath, category, fileCase, prefix, options) {
26
- if (prefix === void 0) { prefix = ''; }
27
- if (options === void 0) { options = {}; }
28
- var _this = _super.call(this, baseName, attributes, relativeDirectoryPath, fileCase, prefix) || this;
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
- _this.Category = category;
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
- _this.updateStrapiName();
39
- Object.assign(_this.Options, options);
40
- return _this;
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
- ComponentInterface.prototype.getInerfaceString = function () {
47
- var isPopulatable = this.hasPopulatableAttributes();
29
+ getInerfaceString() {
30
+ const isPopulatable = this.hasPopulatableAttributes();
48
31
  /* const populateString = isPopulatable ? `<${POPULATE_GENERIC_NAME} extends string | never = never>` : ''; */
49
- var strArr = [];
32
+ const strArr = [];
50
33
  if (isPopulatable) {
51
- strArr.push("export type ".concat(this.getFullName()));
34
+ strArr.push(`export type ${this.getFullName()}`);
52
35
  }
53
36
  else {
54
- strArr.push("export interface ".concat(this.getFullName()));
37
+ strArr.push(`export interface ${this.getFullName()}`);
55
38
  }
56
39
  if (isPopulatable) {
57
- strArr.push("<".concat(constants_1.POPULATE_GENERIC_NAME, " extends string | never = never>"));
58
- strArr.push(" = ".concat(this.RelationNames['builtins::RequiredBy'].name, "<"));
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
- var str = strArr.join('');
57
+ const str = strArr.join('');
75
58
  return str;
76
- };
77
- ComponentInterface.prototype.getInterfaceFieldsString = function () {
78
- var attrs = this.getAttributes();
79
- var str = '';
80
- var _a = this.Options, hasId = _a.hasId, hasComponent = _a.hasComponent;
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 += " __component: \"".concat(this.getStrapiName(), "\";\n");
68
+ str += ` __component: "${this.getStrapiName()}";\n`;
86
69
  }
87
70
  return str + attrs.toFieldsString();
88
- };
89
- return ComponentInterface;
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: any;
7
- constructor(baseName: string, attributes: any, relativeDirectoryPath: string, fileCaseType?: caseType, prefix?: string);
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[];