@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,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
- var Attributes_1 = __importDefault(require("../attributes/Attributes"));
22
- var change_case_1 = require("change-case");
23
- var constants_1 = require("../constants");
24
- var File_1 = require("../file/File");
25
- var Interface = /** @class */ (function (_super) {
26
- __extends(Interface, _super);
27
- function Interface(baseName, attributes, relativeDirectoryPath, fileCaseType, prefix) {
28
- if (fileCaseType === void 0) { fileCaseType = 'pascal'; }
29
- if (prefix === void 0) { prefix = ''; }
30
- var _this = _super.call(this, baseName, relativeDirectoryPath, fileCaseType) || this;
31
- _this.NamePrefix = '';
32
- _this.updateStrapiName();
33
- _this.NamePrefix = prefix;
34
- _this.Attributes = attributes;
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("Warning: attributes for ".concat(_this.getStrapiName(), " is empty!"));
21
+ console.warn(`Warning: attributes for ${this.getStrapiName()} is empty!`);
37
22
  }
38
- return _this;
39
23
  }
40
- Interface.prototype.updateStrapiName = function () {
41
- // TODO: add support for api name
42
- this.StrapiName = "api::".concat(this.BaseName, ".").concat(this.BaseName);
43
- };
44
- Interface.prototype.getStrapiName = function () {
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
- Interface.prototype.getDependencies = function () {
32
+ }
33
+ getDependencies() {
48
34
  return this.getAttributes().getDependencies();
49
- };
50
- Interface.prototype.getFullName = function () {
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
- var pascalName = (0, change_case_1.pascalCase)(this.BaseName);
53
- return "".concat(this.NamePrefix).concat(pascalName);
54
- };
55
- Interface.prototype.hasPopulatableAttributes = function () {
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
- Interface.prototype.getAttributes = function () {
57
+ }
58
+ getAttributes() {
59
59
  return new Attributes_1.default(this.Attributes, this.RelationNames);
60
- };
61
- Interface.prototype.attributesToString = function () {
62
- var attrs = this.getAttributes();
60
+ }
61
+ attributesToString() {
62
+ const attrs = this.getAttributes();
63
63
  return attrs.toString();
64
- };
65
- Interface.prototype.getInerfaceString = function () {
66
- var isPopulatable = this.hasPopulatableAttributes();
64
+ }
65
+ getInerfaceString() {
66
+ const isPopulatable = this.hasPopulatableAttributes();
67
67
  /* const populateString = isPopulatable ? `<${POPULATE_GENERIC_NAME} extends string | never = never>` : ''; */
68
- var strArr = ["export interface ".concat(this.getFullName())];
68
+ const strArr = [`export interface ${this.getFullName()}`];
69
69
  if (isPopulatable) {
70
- strArr.push("<".concat(constants_1.POPULATE_GENERIC_NAME, " extends string | never = never>"));
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
- var str = strArr.join('');
75
+ const str = strArr.join('');
76
76
  return str;
77
- };
78
- Interface.prototype.getInterfaceFieldsString = function () {
79
- var populatable = this.hasPopulatableAttributes();
80
- var strArr = [];
77
+ }
78
+ getInterfaceFieldsString() {
79
+ const populatable = this.hasPopulatableAttributes();
80
+ const strArr = [];
81
81
  strArr.push('id: number;\n');
82
- strArr.push("attributes: ");
82
+ strArr.push(`attributes: `);
83
83
  if (populatable) {
84
- strArr.push("RequiredBy<");
84
+ strArr.push(`RequiredBy<`);
85
85
  }
86
- strArr.push("".concat(this.attributesToString()));
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("".concat(this.RelationNames['builtins::ExtractFlat'].name, "<").concat(constants_1.POPULATE_GENERIC_NAME, ">"));
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("\n");
95
+ strArr.push(`\n`);
96
96
  return strArr.join('');
97
- };
98
- Interface.prototype.toString = function () {
99
- var strings = [this.getTsImports(), this.getInerfaceString()];
97
+ }
98
+ toString() {
99
+ const strings = [this.getTsImports(), this.getInerfaceString()];
100
100
  return strings.join('\n');
101
- };
102
- return Interface;
103
- }(File_1.File));
101
+ }
102
+ }
104
103
  exports.default = Interface;