@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
@@ -0,0 +1,321 @@
1
+ import { ContentTypeReader } from './types/content-type-reader';
2
+ export declare class ByFileContentTypeReader implements ContentTypeReader {
3
+ private readonly strapiSrcRoot;
4
+ constructor(strapiRoot: string);
5
+ readComponents(): Promise<Record<`${string}.${string}`, {
6
+ collectionName?: string;
7
+ attributes?: Record<string, {
8
+ __t4s_required?: boolean;
9
+ pluginOptions?: any;
10
+ required?: boolean;
11
+ type?: "text" | "string";
12
+ } | {
13
+ __t4s_required?: boolean;
14
+ pluginOptions?: any;
15
+ required?: boolean;
16
+ type?: "email";
17
+ } | {
18
+ __t4s_required?: boolean;
19
+ pluginOptions?: any;
20
+ required?: boolean;
21
+ type?: "uid";
22
+ targetField?: string;
23
+ } | {
24
+ __t4s_required?: boolean;
25
+ pluginOptions?: any;
26
+ required?: boolean;
27
+ type?: "richtext";
28
+ } | {
29
+ __t4s_required?: boolean;
30
+ pluginOptions?: any;
31
+ required?: boolean;
32
+ type?: "json";
33
+ } | {
34
+ __t4s_required?: boolean;
35
+ pluginOptions?: any;
36
+ required?: boolean;
37
+ type?: "password";
38
+ } | {
39
+ __t4s_required?: boolean;
40
+ pluginOptions?: any;
41
+ required?: boolean;
42
+ type?: "integer";
43
+ } | {
44
+ __t4s_required?: boolean;
45
+ pluginOptions?: any;
46
+ required?: boolean;
47
+ type?: "float";
48
+ } | {
49
+ __t4s_required?: boolean;
50
+ pluginOptions?: any;
51
+ required?: boolean;
52
+ type?: "biginteger";
53
+ } | {
54
+ __t4s_required?: boolean;
55
+ pluginOptions?: any;
56
+ required?: boolean;
57
+ type?: "decimal";
58
+ } | {
59
+ __t4s_required?: boolean;
60
+ pluginOptions?: any;
61
+ required?: boolean;
62
+ type?: "enumeration";
63
+ enum?: string[];
64
+ } | {
65
+ __t4s_required?: boolean;
66
+ pluginOptions?: any;
67
+ required?: boolean;
68
+ type?: "date";
69
+ } | {
70
+ __t4s_required?: boolean;
71
+ pluginOptions?: any;
72
+ required?: boolean;
73
+ type?: "datetime";
74
+ } | {
75
+ __t4s_required?: boolean;
76
+ pluginOptions?: any;
77
+ required?: boolean;
78
+ type?: "time";
79
+ } | {
80
+ __t4s_required?: boolean;
81
+ pluginOptions?: any;
82
+ required?: boolean;
83
+ type?: "media";
84
+ multiple?: boolean;
85
+ allowedTypes?: ("images" | "videos" | "audios" | "files")[];
86
+ } | {
87
+ __t4s_required?: boolean;
88
+ pluginOptions?: any;
89
+ required?: boolean;
90
+ type?: "boolean";
91
+ } | {
92
+ __t4s_required?: boolean;
93
+ pluginOptions?: any;
94
+ required?: boolean;
95
+ type?: "relation";
96
+ target?: string;
97
+ relation?: "oneToOne";
98
+ } | {
99
+ __t4s_required?: boolean;
100
+ pluginOptions?: any;
101
+ required?: boolean;
102
+ type?: "relation";
103
+ target?: string;
104
+ relation?: "oneToOne";
105
+ inversedBy?: string;
106
+ } | {
107
+ __t4s_required?: boolean;
108
+ pluginOptions?: any;
109
+ required?: boolean;
110
+ type?: "relation";
111
+ target?: string;
112
+ mappedBy?: string;
113
+ relation?: "oneToMany";
114
+ } | {
115
+ __t4s_required?: boolean;
116
+ pluginOptions?: any;
117
+ required?: boolean;
118
+ type?: "relation";
119
+ target?: string;
120
+ relation?: "manyToOne";
121
+ inversedBy?: string;
122
+ } | {
123
+ __t4s_required?: boolean;
124
+ pluginOptions?: any;
125
+ required?: boolean;
126
+ type?: "relation";
127
+ target?: string;
128
+ relation?: "manyToMany";
129
+ inversedBy?: string;
130
+ mappedBy?: string;
131
+ } | {
132
+ __t4s_required?: boolean;
133
+ pluginOptions?: any;
134
+ required?: boolean;
135
+ type?: "relation";
136
+ target?: string;
137
+ relation?: "oneToMany";
138
+ } | {
139
+ type?: "relation";
140
+ relation?: "morphToMany";
141
+ } | {
142
+ __t4s_required?: boolean;
143
+ pluginOptions?: any;
144
+ required?: boolean;
145
+ type?: "component";
146
+ repeatable?: boolean;
147
+ component?: string;
148
+ }>;
149
+ options?: {};
150
+ uid?: string;
151
+ }>>;
152
+ readContentTypes(): Promise<Record<`api::${string}` | `plugin::${string}` | `admin::${string}` | `builtins::${string}`, {
153
+ name: string;
154
+ contentType: {
155
+ attributes?: Record<string, {
156
+ __t4s_required?: boolean;
157
+ pluginOptions?: any;
158
+ required?: boolean;
159
+ type?: "text" | "string";
160
+ } | {
161
+ __t4s_required?: boolean;
162
+ pluginOptions?: any;
163
+ required?: boolean;
164
+ type?: "email";
165
+ } | {
166
+ __t4s_required?: boolean;
167
+ pluginOptions?: any;
168
+ required?: boolean;
169
+ type?: "uid";
170
+ targetField?: string;
171
+ } | {
172
+ __t4s_required?: boolean;
173
+ pluginOptions?: any;
174
+ required?: boolean;
175
+ type?: "richtext";
176
+ } | {
177
+ __t4s_required?: boolean;
178
+ pluginOptions?: any;
179
+ required?: boolean;
180
+ type?: "json";
181
+ } | {
182
+ __t4s_required?: boolean;
183
+ pluginOptions?: any;
184
+ required?: boolean;
185
+ type?: "password";
186
+ } | {
187
+ __t4s_required?: boolean;
188
+ pluginOptions?: any;
189
+ required?: boolean;
190
+ type?: "integer";
191
+ } | {
192
+ __t4s_required?: boolean;
193
+ pluginOptions?: any;
194
+ required?: boolean;
195
+ type?: "float";
196
+ } | {
197
+ __t4s_required?: boolean;
198
+ pluginOptions?: any;
199
+ required?: boolean;
200
+ type?: "biginteger";
201
+ } | {
202
+ __t4s_required?: boolean;
203
+ pluginOptions?: any;
204
+ required?: boolean;
205
+ type?: "decimal";
206
+ } | {
207
+ __t4s_required?: boolean;
208
+ pluginOptions?: any;
209
+ required?: boolean;
210
+ type?: "enumeration";
211
+ enum?: string[];
212
+ } | {
213
+ __t4s_required?: boolean;
214
+ pluginOptions?: any;
215
+ required?: boolean;
216
+ type?: "date";
217
+ } | {
218
+ __t4s_required?: boolean;
219
+ pluginOptions?: any;
220
+ required?: boolean;
221
+ type?: "datetime";
222
+ } | {
223
+ __t4s_required?: boolean;
224
+ pluginOptions?: any;
225
+ required?: boolean;
226
+ type?: "time";
227
+ } | {
228
+ __t4s_required?: boolean;
229
+ pluginOptions?: any;
230
+ required?: boolean;
231
+ type?: "media";
232
+ multiple?: boolean;
233
+ allowedTypes?: ("images" | "videos" | "audios" | "files")[];
234
+ } | {
235
+ __t4s_required?: boolean;
236
+ pluginOptions?: any;
237
+ required?: boolean;
238
+ type?: "boolean";
239
+ } | {
240
+ __t4s_required?: boolean;
241
+ pluginOptions?: any;
242
+ required?: boolean;
243
+ type?: "relation";
244
+ target?: string;
245
+ relation?: "oneToOne";
246
+ } | {
247
+ __t4s_required?: boolean;
248
+ pluginOptions?: any;
249
+ required?: boolean;
250
+ type?: "relation";
251
+ target?: string;
252
+ relation?: "oneToOne";
253
+ inversedBy?: string;
254
+ } | {
255
+ __t4s_required?: boolean;
256
+ pluginOptions?: any;
257
+ required?: boolean;
258
+ type?: "relation";
259
+ target?: string;
260
+ mappedBy?: string;
261
+ relation?: "oneToMany";
262
+ } | {
263
+ __t4s_required?: boolean;
264
+ pluginOptions?: any;
265
+ required?: boolean;
266
+ type?: "relation";
267
+ target?: string;
268
+ relation?: "manyToOne";
269
+ inversedBy?: string;
270
+ } | {
271
+ __t4s_required?: boolean;
272
+ pluginOptions?: any;
273
+ required?: boolean;
274
+ type?: "relation";
275
+ target?: string;
276
+ relation?: "manyToMany";
277
+ inversedBy?: string;
278
+ mappedBy?: string;
279
+ } | {
280
+ __t4s_required?: boolean;
281
+ pluginOptions?: any;
282
+ required?: boolean;
283
+ type?: "relation";
284
+ target?: string;
285
+ relation?: "oneToMany";
286
+ } | {
287
+ type?: "relation";
288
+ relation?: "morphToMany";
289
+ } | {
290
+ __t4s_required?: boolean;
291
+ pluginOptions?: any;
292
+ required?: boolean;
293
+ type?: "component";
294
+ repeatable?: boolean;
295
+ component?: string;
296
+ } | {
297
+ __t4s_required?: boolean;
298
+ pluginOptions?: any;
299
+ required?: boolean;
300
+ type?: "dynamiczone";
301
+ components?: string[];
302
+ }>;
303
+ collectionName?: string;
304
+ options?: {
305
+ draftAndPublish?: boolean;
306
+ };
307
+ pluginOptions?: Record<string, any>;
308
+ uid?: string;
309
+ };
310
+ } & ({
311
+ namespace: "api" | "plugin";
312
+ collection: string;
313
+ } | {
314
+ namespace: "admin";
315
+ collection?: null;
316
+ })>>;
317
+ private readComponentSchema;
318
+ private readContentTypeSchema;
319
+ private getApiFolders;
320
+ private getComponentCategoryFolders;
321
+ }
@@ -0,0 +1,116 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ByFileContentTypeReader = void 0;
13
+ const posix_1 = require("path/posix");
14
+ const utils_1 = require("../utils");
15
+ const fs_1 = require("fs");
16
+ const promises_1 = require("fs/promises");
17
+ const component_1 = require("./types/component");
18
+ const content_type_1 = require("./types/content-type");
19
+ class ByFileContentTypeReader {
20
+ constructor(strapiRoot) {
21
+ this.strapiSrcRoot = (0, posix_1.join)(strapiRoot, 'src');
22
+ }
23
+ readComponents() {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const categories = yield this.getComponentCategoryFolders();
26
+ const schemas = {};
27
+ const nestedSchemasPromises = categories.map((category) => __awaiter(this, void 0, void 0, function* () {
28
+ const schemaFilesPath = (0, posix_1.join)(this.strapiSrcRoot, 'components', category);
29
+ const schemaFiles = yield (0, utils_1.readDirFiltered)(schemaFilesPath);
30
+ const schemaNamesWithAttributesPromises = schemaFiles.map((file) => __awaiter(this, void 0, void 0, function* () {
31
+ const schemaPath = (0, posix_1.join)(schemaFilesPath, file);
32
+ const schema = yield this.readComponentSchema(schemaPath);
33
+ const name = file.split('.')[0];
34
+ schemas[`${category}.${name}`] = schema;
35
+ }));
36
+ yield Promise.all(schemaNamesWithAttributesPromises);
37
+ }));
38
+ yield Promise.all(nestedSchemasPromises);
39
+ return schemas;
40
+ });
41
+ }
42
+ readContentTypes() {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ const apiFolders = yield this.getApiFolders();
45
+ const schemas = {};
46
+ const schemasWithAttributesPromises = apiFolders.map((apiFolder) => __awaiter(this, void 0, void 0, function* () {
47
+ const contentTypesFolder = (0, posix_1.join)(this.strapiSrcRoot, 'api', apiFolder, 'content-types');
48
+ if (!(0, fs_1.existsSync)(contentTypesFolder)) {
49
+ return;
50
+ }
51
+ const contentTypesFolders = yield (0, utils_1.readDirFiltered)(contentTypesFolder);
52
+ const contentTypePromises = contentTypesFolders.map((contentTypeFolder) => __awaiter(this, void 0, void 0, function* () {
53
+ const schemaPath = (0, posix_1.join)(this.strapiSrcRoot, 'api', apiFolder, 'content-types', contentTypeFolder, 'schema.json');
54
+ const schema = yield this.readContentTypeSchema(schemaPath);
55
+ const name = contentTypeFolder;
56
+ schemas[`api::${apiFolder}.${name}`] = {
57
+ collection: apiFolder,
58
+ name,
59
+ namespace: 'api',
60
+ contentType: schema,
61
+ };
62
+ }));
63
+ yield Promise.all(contentTypePromises);
64
+ }));
65
+ Promise.all(schemasWithAttributesPromises);
66
+ return schemas;
67
+ });
68
+ }
69
+ readComponentSchema(schemaPath) {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ const schemaData = yield (0, promises_1.readFile)(schemaPath);
72
+ try {
73
+ const object = JSON.parse(schemaData.toString());
74
+ const schema = component_1.strapiComponent.parse(object);
75
+ return schema;
76
+ }
77
+ catch (e) {
78
+ console.error(e);
79
+ throw new Error(`Failed to parse schema: ${schemaPath}`);
80
+ }
81
+ });
82
+ }
83
+ readContentTypeSchema(schemaPath) {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ const schemaData = yield (0, promises_1.readFile)(schemaPath);
86
+ try {
87
+ const object = JSON.parse(schemaData.toString());
88
+ const schema = content_type_1.strapiContentType.parse(object);
89
+ return schema;
90
+ }
91
+ catch (e) {
92
+ console.error(e);
93
+ throw new Error(`Failed to parse schema: ${schemaPath}`);
94
+ }
95
+ });
96
+ }
97
+ getApiFolders() {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ const path = (0, posix_1.join)(this.strapiSrcRoot, 'api');
100
+ const folders = yield (0, utils_1.readDirFiltered)(path);
101
+ return folders;
102
+ });
103
+ }
104
+ getComponentCategoryFolders() {
105
+ return __awaiter(this, void 0, void 0, function* () {
106
+ const path = (0, posix_1.join)(this.strapiSrcRoot, 'components');
107
+ // If there exists no components, just fallback to an empty array.
108
+ if (!(0, fs_1.existsSync)(path)) {
109
+ return [];
110
+ }
111
+ const folders = yield (0, utils_1.readDirFiltered)(path);
112
+ return folders;
113
+ });
114
+ }
115
+ }
116
+ exports.ByFileContentTypeReader = ByFileContentTypeReader;