@oak-digital/types-4-strapi-2 0.3.6 → 0.5.0

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 CHANGED
@@ -32,10 +32,6 @@
32
32
  "no-return-await": ["error"],
33
33
  "no-var": ["error"],
34
34
  "no-cond-assign": ["error", "always"],
35
- "indent": [
36
- "error",
37
- 4
38
- ],
39
35
  "linebreak-style": [
40
36
  "error",
41
37
  "unix"
package/.prettierrc.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "parser": "typescript",
3
3
  "semi": true,
4
+ "indent": 4,
4
5
  "singleQuote": true,
5
6
  "bracketSameLine": false,
6
7
  "trailingComma": "es5"
package/README.md CHANGED
@@ -49,11 +49,12 @@ This can be done with the `--out` flag like in the following example.
49
49
  * Generate TypeScript interfaces for builtin types such as `Media` and `MediaFormat`
50
50
  * Select input and output directory
51
51
  * Prettier formatting and ability to use your own `.prettierrc`.
52
+ * Generate types for plugins such as [url-alias](https://github.com/strapi-community/strapi-plugin-url-alias)
53
+ * Population by generics
52
54
 
53
55
  ### Planned features
54
56
 
55
57
  * Support for localization
56
- * Support if you are using other plugins, such as `url-alias`, which should add extra fields for some interfaces.
57
58
 
58
59
  ## Flags
59
60
 
@@ -65,6 +66,45 @@ This can be done with the `--out` flag like in the following example.
65
66
  | --component-prefix <prefix> | A prefix for components | none |
66
67
  | -D, --delete-old | CAUTION: This option is equivalent to running `rm -rf` on the output directory first | `false` |
67
68
  | --prettier <file> | The prettier config file to use for formatting TypeScript interfaces | none |
69
+ | --plugins <plugins...> | The plugins to use | none |
70
+
71
+ ## Using plugins
72
+
73
+ It is possible to generate types for plugins, for example url-alias gives a new field on your content types, so that plugin will automatically add that field to your types.
74
+ You can see a list of builtin plugins below.
75
+ Some plugins might not be fully featured.
76
+
77
+ It will be possible in the future to add your own plugins in later versions.
78
+
79
+ ### List of supported plugins
80
+
81
+ * url-alias
82
+
83
+ ### example of using plugins
84
+
85
+ ```bash
86
+ $ t4s --plugins url-alias
87
+ ```
88
+
89
+ ## Population
90
+
91
+ If your content types contains relations, dynamic zones or media, the fields can be set to required in the same way as you would populate them in the strapi api.
92
+
93
+ Here is an example if you have a content type name page, with a relation to a related page that you want the title and date of.
94
+
95
+ ```typescript
96
+ type PageWithRelated = Page<'related_page.title' | 'related_page.date'>
97
+ ```
98
+
99
+ This will make the title and date field on the new type required, so that you do not need to make an extra if check.
100
+ NOTE: when doing this, you should also make sure that you are actually populating it the same way as in the api
101
+
102
+ Other example using an array
103
+
104
+ ```typescript
105
+ const populatedFields = ['related_page.title', 'related_page.date'] as const; // as const is important
106
+ type PageWithRelated = Page<typeof populatedFields[number]>;
107
+ ```
68
108
 
69
109
  ## Tips and tricks
70
110
 
@@ -0,0 +1,13 @@
1
+ import { RelationNames } from '../file/File';
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
+ isAttributePopulatable(attr: any): boolean;
7
+ hasPopulatableAttributes(): boolean;
8
+ getPopulatableAttributes(): Set<string>;
9
+ getDependencies(): string[];
10
+ attributeToString(attrName: string, attr: any): string;
11
+ toFieldsString(): string;
12
+ toString(): string;
13
+ }
@@ -0,0 +1,227 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var constants_1 = require("../constants");
4
+ var Attributes = /** @class */ (function () {
5
+ function Attributes(attr, relationNames) {
6
+ this.RelationNames = {};
7
+ this.Attrs = attr;
8
+ this.RelationNames = relationNames;
9
+ }
10
+ Attributes.prototype.isAttributePopulatable = function (attr) {
11
+ // If it is a component / relation / dynamiczone it is always optional due to population
12
+ switch (attr.type) {
13
+ case 'nested':
14
+ // we need to check equality since it could be undefined
15
+ return attr.nullable === true;
16
+ case 'media': // media is also always populatable
17
+ case 'component':
18
+ case 'dynamiczone':
19
+ case 'relation':
20
+ return true;
21
+ default:
22
+ break;
23
+ }
24
+ return false;
25
+ };
26
+ Attributes.prototype.hasPopulatableAttributes = function () {
27
+ for (var attrName in this.Attrs) {
28
+ var attr = this.Attrs[attrName];
29
+ if (this.isAttributePopulatable(attr)) {
30
+ return true;
31
+ }
32
+ }
33
+ return false;
34
+ };
35
+ Attributes.prototype.getPopulatableAttributes = function () {
36
+ var populatableAttributes = new Set();
37
+ for (var attrName in this.Attrs) {
38
+ var attr = this.Attrs[attrName];
39
+ if (this.isAttributePopulatable(attr)) {
40
+ populatableAttributes.add(attrName);
41
+ }
42
+ }
43
+ return populatableAttributes;
44
+ };
45
+ Attributes.prototype.getDependencies = function () {
46
+ var _a;
47
+ var dependencies = new Set();
48
+ for (var attrName in this.Attrs) {
49
+ var attr = this.Attrs[attrName];
50
+ switch (attr.type) {
51
+ case 'nested':
52
+ var attrs = new Attributes(attr.fields, this.RelationNames);
53
+ var deps = attrs.getDependencies();
54
+ deps.forEach(function (dep) { return dependencies.add(dep); });
55
+ break;
56
+ case 'relation':
57
+ dependencies.add(attr.target);
58
+ break;
59
+ case 'component':
60
+ dependencies.add(attr.component);
61
+ break;
62
+ case 'media':
63
+ dependencies.add('builtins::Media');
64
+ break;
65
+ case 'dynamiczone':
66
+ var componentDeps = (_a = attr.components) !== null && _a !== void 0 ? _a : [];
67
+ componentDeps.forEach(function (dep) { return dependencies.add(dep); });
68
+ break;
69
+ default:
70
+ continue;
71
+ }
72
+ // // If the current dependency is the interface itself, do not report it as a dependency
73
+ // if (dependencyName === strapiName) {
74
+ // continue;
75
+ // }
76
+ }
77
+ if (this.hasPopulatableAttributes()) {
78
+ dependencies.add('builtins::ExtractNested');
79
+ dependencies.add('builtins::ExtractFlat');
80
+ dependencies.add('builtins::RequiredBy');
81
+ }
82
+ return Array.from(dependencies);
83
+ };
84
+ Attributes.prototype.attributeToString = function (attrName, attr) {
85
+ var _this = this;
86
+ var _a, _b, _c;
87
+ var isPopulatable = this.isAttributePopulatable(attr);
88
+ var isOptional = isPopulatable;
89
+ var optionalString = isOptional ? '?' : '';
90
+ var orNull = ' | null';
91
+ // TODO: only add this in non paranoid mode
92
+ /* const requiredString = attr.required !== true ? orNull : ''; */
93
+ var requiredString = orNull;
94
+ var str = " ".concat(attrName).concat(optionalString, ": ");
95
+ var isArray = false;
96
+ switch (attr.type) {
97
+ // types-4-strapi-2 specific, used for builtin types
98
+ case 'nested':
99
+ // Be careful with recursion
100
+ // console.log(attr);
101
+ var nullableString = ((_a = attr === null || attr === void 0 ? void 0 : attr.nullable) !== null && _a !== void 0 ? _a : false) ? ' | null' : '';
102
+ var newAttrs = new Attributes(attr.fields, this.RelationNames);
103
+ str += newAttrs.toString() + nullableString;
104
+ break;
105
+ case 'relation':
106
+ var apiName = attr.target;
107
+ // console.log(this.RelationNames, apiName)
108
+ var dependencyName = (_c = (_b = this.RelationNames[apiName]) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : 'any';
109
+ var relationMultipleString = attr.relation.endsWith('ToMany')
110
+ ? '[]'
111
+ : orNull;
112
+ str += "{ data: ";
113
+ str += dependencyName;
114
+ // TODO: assert correctly
115
+ var relationInterface = this.RelationNames[apiName].file;
116
+ if (relationInterface.hasPopulatableAttributes()) {
117
+ str += '<';
118
+ str += "".concat(this.RelationNames['builtins::ExtractNested'].name, "<").concat(constants_1.POPULATE_GENERIC_NAME, ", '").concat(attrName, "'>");
119
+ str += '>';
120
+ }
121
+ str += relationMultipleString;
122
+ str += "; }";
123
+ break;
124
+ case 'component':
125
+ var componentName = attr.component;
126
+ var relationNameObj = this.RelationNames[componentName];
127
+ /* console.log(this.RelationNames); */
128
+ var dependencyComponentName = relationNameObj.name;
129
+ /* isArray = attr.repeatable ?? false; */
130
+ isArray = false; // we already handle this here.
131
+ str += dependencyComponentName;
132
+ if (attr.repeatable) {
133
+ str += '[]';
134
+ }
135
+ str += requiredString; // resolves #20. components can be null.
136
+ break;
137
+ case 'media':
138
+ var mediaMultipleString = attr.multiple
139
+ ? '[]'
140
+ : requiredString;
141
+ str += "{ data: ";
142
+ str += this.RelationNames['builtins::Media'].name;
143
+ str += mediaMultipleString;
144
+ str += "; }";
145
+ break;
146
+ case 'password':
147
+ return null;
148
+ case 'enumeration':
149
+ var hasDefault = 'default' in attr;
150
+ var enums = attr.enum.map(function (en) { return "\"".concat(en, "\""); });
151
+ enums.push('null');
152
+ var typeString = enums.join(' | ');
153
+ str += typeString;
154
+ break;
155
+ case 'dynamiczone':
156
+ // console.log(attr.components);
157
+ var relations = attr.components.map(function (componentName) {
158
+ var component = _this.RelationNames[componentName];
159
+ // in this context file should always be an interface
160
+ var file = component.file;
161
+ var populatable = file.hasPopulatableAttributes();
162
+ /* false; */
163
+ var populatableString = populatable
164
+ ? "".concat(_this.RelationNames[componentName].name, "<").concat(_this.RelationNames['builtins::ExtractNested'].name, "<").concat(constants_1.POPULATE_GENERIC_NAME, ", '").concat(attrName, "'>>")
165
+ : _this.RelationNames[componentName].name;
166
+ return populatableString;
167
+ });
168
+ // console.log(relations);
169
+ var relationsString = relations.join(' | ');
170
+ // console.log(relationsString);
171
+ str += "Array<".concat(relationsString, ">");
172
+ break;
173
+ case 'string':
174
+ case 'text':
175
+ case 'richtext':
176
+ case 'email':
177
+ case 'uid':
178
+ str += 'string';
179
+ str += requiredString;
180
+ break;
181
+ case 'integer':
182
+ case 'biginteger':
183
+ case 'decimal':
184
+ case 'float':
185
+ str += 'number';
186
+ str += requiredString;
187
+ break;
188
+ case 'date':
189
+ case 'datetime':
190
+ case 'time':
191
+ str += 'string';
192
+ str += requiredString;
193
+ break;
194
+ case 'boolean':
195
+ str += attr.type;
196
+ str += requiredString;
197
+ break;
198
+ case 'json':
199
+ default:
200
+ str += 'any';
201
+ break;
202
+ }
203
+ var isArrayString = isArray ? '[]' : '';
204
+ str += "".concat(isArrayString, ";");
205
+ return str;
206
+ };
207
+ Attributes.prototype.toFieldsString = function () {
208
+ var strings = [];
209
+ for (var attrName in this.Attrs) {
210
+ var attr = this.Attrs[attrName];
211
+ var attrString = this.attributeToString(attrName, attr);
212
+ if (attrString === null) {
213
+ continue;
214
+ }
215
+ strings.push(attrString);
216
+ }
217
+ return strings.map(function (s) { return "".concat(s, "\n"); }).join('');
218
+ };
219
+ Attributes.prototype.toString = function () {
220
+ var strings = ['{'];
221
+ strings.push(this.toFieldsString());
222
+ strings.push('}');
223
+ return strings.join('\n');
224
+ };
225
+ return Attributes;
226
+ }());
227
+ exports.default = Attributes;
@@ -0,0 +1 @@
1
+ export declare const POPULATE_GENERIC_NAME = "Populate";
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.POPULATE_GENERIC_NAME = void 0;
4
+ exports.POPULATE_GENERIC_NAME = 'Populate';
@@ -0,0 +1,14 @@
1
+ export declare function readSchema(schemaPath: string): Promise<any>;
2
+ export declare function getApiFolders(strapiSrcRoot: string): Promise<string[]>;
3
+ export declare function getComponentCategoryFolders(strapiSrcRoot: string): Promise<string[]>;
4
+ export declare function getComponentSchemas(strapiSrcRoot: string): Promise<{
5
+ category: string;
6
+ schemas: {
7
+ name: string;
8
+ attributes: any;
9
+ }[];
10
+ }[]>;
11
+ export declare function getApiSchemas(strapiSrcRoot: string): Promise<{
12
+ name: string;
13
+ attributes: any;
14
+ }[]>;
@@ -0,0 +1,177 @@
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
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.getApiSchemas = exports.getComponentSchemas = exports.getComponentCategoryFolders = exports.getApiFolders = exports.readSchema = void 0;
40
+ var node_fs_1 = require("node:fs");
41
+ var promises_1 = require("node:fs/promises");
42
+ var posix_1 = require("node:path/posix");
43
+ var utils_1 = require("../utils");
44
+ function readSchema(schemaPath) {
45
+ return __awaiter(this, void 0, void 0, function () {
46
+ var schemaData, e_1;
47
+ return __generator(this, function (_a) {
48
+ switch (_a.label) {
49
+ case 0:
50
+ _a.trys.push([0, 2, , 3]);
51
+ return [4 /*yield*/, (0, promises_1.readFile)(schemaPath)];
52
+ case 1:
53
+ schemaData = _a.sent();
54
+ return [2 /*return*/, JSON.parse(schemaData.toString()).attributes];
55
+ case 2:
56
+ e_1 = _a.sent();
57
+ return [2 /*return*/, null];
58
+ case 3: return [2 /*return*/];
59
+ }
60
+ });
61
+ });
62
+ }
63
+ exports.readSchema = readSchema;
64
+ function getApiFolders(strapiSrcRoot) {
65
+ return __awaiter(this, void 0, void 0, function () {
66
+ var path, folders;
67
+ return __generator(this, function (_a) {
68
+ switch (_a.label) {
69
+ case 0:
70
+ path = (0, posix_1.join)(strapiSrcRoot, 'api');
71
+ return [4 /*yield*/, (0, utils_1.readDirFiltered)(path)];
72
+ case 1:
73
+ folders = _a.sent();
74
+ return [2 /*return*/, folders];
75
+ }
76
+ });
77
+ });
78
+ }
79
+ exports.getApiFolders = getApiFolders;
80
+ function getComponentCategoryFolders(strapiSrcRoot) {
81
+ return __awaiter(this, void 0, void 0, function () {
82
+ var path, folders;
83
+ return __generator(this, function (_a) {
84
+ switch (_a.label) {
85
+ case 0:
86
+ path = (0, posix_1.join)(strapiSrcRoot, 'components');
87
+ // If there exists no components, just fallback to an empty array.
88
+ if (!(0, node_fs_1.existsSync)(path)) {
89
+ return [2 /*return*/, []];
90
+ }
91
+ return [4 /*yield*/, (0, utils_1.readDirFiltered)(path)];
92
+ case 1:
93
+ folders = _a.sent();
94
+ return [2 /*return*/, folders];
95
+ }
96
+ });
97
+ });
98
+ }
99
+ exports.getComponentCategoryFolders = getComponentCategoryFolders;
100
+ function getComponentSchemas(strapiSrcRoot) {
101
+ return __awaiter(this, void 0, void 0, function () {
102
+ var categories, nestedSchemasPromises, nestedSchemasArr;
103
+ var _this = this;
104
+ return __generator(this, function (_a) {
105
+ switch (_a.label) {
106
+ case 0: return [4 /*yield*/, getComponentCategoryFolders(strapiSrcRoot)];
107
+ case 1:
108
+ categories = _a.sent();
109
+ nestedSchemasPromises = categories.map(function (category) { return __awaiter(_this, void 0, void 0, function () {
110
+ var schemaFilesPath, schemaFiles, schemaNamesWithAttributesPromises, schemaNamesWithAttributes;
111
+ var _this = this;
112
+ return __generator(this, function (_a) {
113
+ switch (_a.label) {
114
+ case 0:
115
+ schemaFilesPath = (0, posix_1.join)(strapiSrcRoot, 'components', category);
116
+ return [4 /*yield*/, (0, utils_1.readDirFiltered)(schemaFilesPath)];
117
+ case 1:
118
+ schemaFiles = _a.sent();
119
+ schemaNamesWithAttributesPromises = schemaFiles.map(function (file) { return __awaiter(_this, void 0, void 0, function () {
120
+ var schemaPath, attributes, name;
121
+ return __generator(this, function (_a) {
122
+ switch (_a.label) {
123
+ case 0:
124
+ schemaPath = (0, posix_1.join)(schemaFilesPath, file);
125
+ return [4 /*yield*/, readSchema(schemaPath)];
126
+ case 1:
127
+ attributes = _a.sent();
128
+ name = file.split('.')[0];
129
+ return [2 /*return*/, { name: name, attributes: attributes }];
130
+ }
131
+ });
132
+ }); });
133
+ return [4 /*yield*/, Promise.all(schemaNamesWithAttributesPromises)];
134
+ case 2:
135
+ schemaNamesWithAttributes = _a.sent();
136
+ return [2 /*return*/, { category: category, schemas: schemaNamesWithAttributes }];
137
+ }
138
+ });
139
+ }); });
140
+ return [4 /*yield*/, Promise.all(nestedSchemasPromises)];
141
+ case 2:
142
+ nestedSchemasArr = _a.sent();
143
+ return [2 /*return*/, nestedSchemasArr];
144
+ }
145
+ });
146
+ });
147
+ }
148
+ exports.getComponentSchemas = getComponentSchemas;
149
+ function getApiSchemas(strapiSrcRoot) {
150
+ return __awaiter(this, void 0, void 0, function () {
151
+ var apiFolders, schemasWithAttributesPromises, schemasWithAttributes;
152
+ var _this = this;
153
+ return __generator(this, function (_a) {
154
+ switch (_a.label) {
155
+ case 0: return [4 /*yield*/, getApiFolders(strapiSrcRoot)];
156
+ case 1:
157
+ apiFolders = _a.sent();
158
+ schemasWithAttributesPromises = apiFolders.map(function (folder) { return __awaiter(_this, void 0, void 0, function () {
159
+ var schemaPath, attributes;
160
+ return __generator(this, function (_a) {
161
+ switch (_a.label) {
162
+ case 0:
163
+ schemaPath = (0, posix_1.join)(strapiSrcRoot, 'api', folder, 'content-types', folder, 'schema.json');
164
+ return [4 /*yield*/, readSchema(schemaPath)];
165
+ case 1:
166
+ attributes = _a.sent();
167
+ return [2 /*return*/, { name: folder, attributes: attributes }];
168
+ }
169
+ });
170
+ }); });
171
+ schemasWithAttributes = Promise.all(schemasWithAttributesPromises);
172
+ return [2 /*return*/, schemasWithAttributes];
173
+ }
174
+ });
175
+ });
176
+ }
177
+ exports.getApiSchemas = getApiSchemas;
@@ -0,0 +1,11 @@
1
+ import { File } from "../file/File";
2
+ import { caseType } from "../utils/casing";
3
+ export declare class ExtraType extends File {
4
+ protected typeString: string;
5
+ constructor(typeString: string, baseName: string, relativeDirectoryPath: string, fileCaseType?: caseType);
6
+ getDependencies(): any[];
7
+ getStrapiName(): string;
8
+ getFullName(): string;
9
+ protected updateStrapiName(): void;
10
+ toString(): string;
11
+ }
@@ -0,0 +1,47 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ 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;
28
+ }
29
+ ExtraType.prototype.getDependencies = function () {
30
+ return [];
31
+ };
32
+ ExtraType.prototype.getStrapiName = function () {
33
+ return this.StrapiName;
34
+ };
35
+ ExtraType.prototype.getFullName = function () {
36
+ return this.BaseName;
37
+ };
38
+ ExtraType.prototype.updateStrapiName = function () {
39
+ this.StrapiName = "builtins::".concat(this.BaseName);
40
+ };
41
+ ExtraType.prototype.toString = function () {
42
+ // TODO: make this more dynamic
43
+ return "export ".concat(this.typeString);
44
+ };
45
+ return ExtraType;
46
+ }(File_1.File));
47
+ exports.ExtraType = ExtraType;
@@ -0,0 +1,2 @@
1
+ import { ExtraType } from "./ExtraType";
2
+ export declare const createExtraTypes: () => ExtraType[];
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createExtraTypes = void 0;
4
+ var ExtraType_1 = require("./ExtraType");
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,
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');
18
+ return extraType;
19
+ });
20
+ };
21
+ exports.createExtraTypes = createExtraTypes;
@@ -0,0 +1,26 @@
1
+ import { caseType } from "../utils/casing";
2
+ export declare type RelationNames = Record<string, {
3
+ name: string;
4
+ file: File;
5
+ }>;
6
+ export declare abstract class File {
7
+ private Relations;
8
+ protected RelationNames: RelationNames;
9
+ private RelationNamesCounter;
10
+ protected BaseName: string;
11
+ protected StrapiName: string;
12
+ private RelativeDirectoryPath;
13
+ protected FileCase: caseType;
14
+ constructor(baseName: string, relativeDirectoryPath: string, fileCaseType?: caseType);
15
+ abstract getDependencies(): string[];
16
+ abstract getStrapiName(): string;
17
+ abstract getFullName(): string;
18
+ abstract toString(): string;
19
+ setRelations(relations: File[]): void;
20
+ getRelativeRootPath(): any;
21
+ getBaseName(): string;
22
+ getRelativeRootPathFile(): string;
23
+ getRelativeRootDir(): string;
24
+ getFileBaseName(): string;
25
+ protected getTsImports(): string;
26
+ }