@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,319 @@
1
+ import { ContentTypeReader } from '../types/content-type-reader';
2
+ export declare class LoadStrapiReader implements ContentTypeReader {
3
+ private strapiRoot;
4
+ private loadStrapiPromise;
5
+ constructor(strapiRoot: string);
6
+ readContentTypes(): Promise<Record<`api::${string}` | `plugin::${string}` | `admin::${string}` | `builtins::${string}`, {
7
+ name: string;
8
+ contentType: {
9
+ attributes?: Record<string, {
10
+ __t4s_required?: boolean;
11
+ pluginOptions?: any;
12
+ required?: boolean;
13
+ type?: "text" | "string";
14
+ } | {
15
+ __t4s_required?: boolean;
16
+ pluginOptions?: any;
17
+ required?: boolean;
18
+ type?: "email";
19
+ } | {
20
+ __t4s_required?: boolean;
21
+ pluginOptions?: any;
22
+ required?: boolean;
23
+ type?: "uid";
24
+ targetField?: string;
25
+ } | {
26
+ __t4s_required?: boolean;
27
+ pluginOptions?: any;
28
+ required?: boolean;
29
+ type?: "richtext";
30
+ } | {
31
+ __t4s_required?: boolean;
32
+ pluginOptions?: any;
33
+ required?: boolean;
34
+ type?: "json";
35
+ } | {
36
+ __t4s_required?: boolean;
37
+ pluginOptions?: any;
38
+ required?: boolean;
39
+ type?: "password";
40
+ } | {
41
+ __t4s_required?: boolean;
42
+ pluginOptions?: any;
43
+ required?: boolean;
44
+ type?: "integer";
45
+ } | {
46
+ __t4s_required?: boolean;
47
+ pluginOptions?: any;
48
+ required?: boolean;
49
+ type?: "float";
50
+ } | {
51
+ __t4s_required?: boolean;
52
+ pluginOptions?: any;
53
+ required?: boolean;
54
+ type?: "biginteger";
55
+ } | {
56
+ __t4s_required?: boolean;
57
+ pluginOptions?: any;
58
+ required?: boolean;
59
+ type?: "decimal";
60
+ } | {
61
+ __t4s_required?: boolean;
62
+ pluginOptions?: any;
63
+ required?: boolean;
64
+ type?: "enumeration";
65
+ enum?: string[];
66
+ } | {
67
+ __t4s_required?: boolean;
68
+ pluginOptions?: any;
69
+ required?: boolean;
70
+ type?: "date";
71
+ } | {
72
+ __t4s_required?: boolean;
73
+ pluginOptions?: any;
74
+ required?: boolean;
75
+ type?: "datetime";
76
+ } | {
77
+ __t4s_required?: boolean;
78
+ pluginOptions?: any;
79
+ required?: boolean;
80
+ type?: "time";
81
+ } | {
82
+ __t4s_required?: boolean;
83
+ pluginOptions?: any;
84
+ required?: boolean;
85
+ type?: "media";
86
+ multiple?: boolean;
87
+ allowedTypes?: ("images" | "videos" | "audios" | "files")[];
88
+ } | {
89
+ __t4s_required?: boolean;
90
+ pluginOptions?: any;
91
+ required?: boolean;
92
+ type?: "boolean";
93
+ } | {
94
+ __t4s_required?: boolean;
95
+ pluginOptions?: any;
96
+ required?: boolean;
97
+ type?: "relation";
98
+ target?: string;
99
+ relation?: "oneToOne";
100
+ } | {
101
+ __t4s_required?: boolean;
102
+ pluginOptions?: any;
103
+ required?: boolean;
104
+ type?: "relation";
105
+ target?: string;
106
+ relation?: "oneToOne";
107
+ inversedBy?: string;
108
+ } | {
109
+ __t4s_required?: boolean;
110
+ pluginOptions?: any;
111
+ required?: boolean;
112
+ type?: "relation";
113
+ target?: string;
114
+ mappedBy?: string;
115
+ relation?: "oneToMany";
116
+ } | {
117
+ __t4s_required?: boolean;
118
+ pluginOptions?: any;
119
+ required?: boolean;
120
+ type?: "relation";
121
+ target?: string;
122
+ relation?: "manyToOne";
123
+ inversedBy?: string;
124
+ } | {
125
+ __t4s_required?: boolean;
126
+ pluginOptions?: any;
127
+ required?: boolean;
128
+ type?: "relation";
129
+ target?: string;
130
+ relation?: "manyToMany";
131
+ inversedBy?: string;
132
+ mappedBy?: string;
133
+ } | {
134
+ __t4s_required?: boolean;
135
+ pluginOptions?: any;
136
+ required?: boolean;
137
+ type?: "relation";
138
+ target?: string;
139
+ relation?: "oneToMany";
140
+ } | {
141
+ type?: "relation";
142
+ relation?: "morphToMany";
143
+ } | {
144
+ __t4s_required?: boolean;
145
+ pluginOptions?: any;
146
+ required?: boolean;
147
+ type?: "component";
148
+ repeatable?: boolean;
149
+ component?: string;
150
+ } | {
151
+ __t4s_required?: boolean;
152
+ pluginOptions?: any;
153
+ required?: boolean;
154
+ type?: "dynamiczone";
155
+ components?: string[];
156
+ }>;
157
+ collectionName?: string;
158
+ options?: {
159
+ draftAndPublish?: boolean;
160
+ };
161
+ pluginOptions?: Record<string, any>;
162
+ uid?: string;
163
+ };
164
+ } & ({
165
+ namespace: "api" | "plugin";
166
+ collection: string;
167
+ } | {
168
+ namespace: "admin";
169
+ collection?: null;
170
+ })>>;
171
+ readComponents(): Promise<Record<string, {
172
+ collectionName?: string;
173
+ attributes?: Record<string, {
174
+ __t4s_required?: boolean;
175
+ pluginOptions?: any;
176
+ required?: boolean;
177
+ type?: "text" | "string";
178
+ } | {
179
+ __t4s_required?: boolean;
180
+ pluginOptions?: any;
181
+ required?: boolean;
182
+ type?: "email";
183
+ } | {
184
+ __t4s_required?: boolean;
185
+ pluginOptions?: any;
186
+ required?: boolean;
187
+ type?: "uid";
188
+ targetField?: string;
189
+ } | {
190
+ __t4s_required?: boolean;
191
+ pluginOptions?: any;
192
+ required?: boolean;
193
+ type?: "richtext";
194
+ } | {
195
+ __t4s_required?: boolean;
196
+ pluginOptions?: any;
197
+ required?: boolean;
198
+ type?: "json";
199
+ } | {
200
+ __t4s_required?: boolean;
201
+ pluginOptions?: any;
202
+ required?: boolean;
203
+ type?: "password";
204
+ } | {
205
+ __t4s_required?: boolean;
206
+ pluginOptions?: any;
207
+ required?: boolean;
208
+ type?: "integer";
209
+ } | {
210
+ __t4s_required?: boolean;
211
+ pluginOptions?: any;
212
+ required?: boolean;
213
+ type?: "float";
214
+ } | {
215
+ __t4s_required?: boolean;
216
+ pluginOptions?: any;
217
+ required?: boolean;
218
+ type?: "biginteger";
219
+ } | {
220
+ __t4s_required?: boolean;
221
+ pluginOptions?: any;
222
+ required?: boolean;
223
+ type?: "decimal";
224
+ } | {
225
+ __t4s_required?: boolean;
226
+ pluginOptions?: any;
227
+ required?: boolean;
228
+ type?: "enumeration";
229
+ enum?: string[];
230
+ } | {
231
+ __t4s_required?: boolean;
232
+ pluginOptions?: any;
233
+ required?: boolean;
234
+ type?: "date";
235
+ } | {
236
+ __t4s_required?: boolean;
237
+ pluginOptions?: any;
238
+ required?: boolean;
239
+ type?: "datetime";
240
+ } | {
241
+ __t4s_required?: boolean;
242
+ pluginOptions?: any;
243
+ required?: boolean;
244
+ type?: "time";
245
+ } | {
246
+ __t4s_required?: boolean;
247
+ pluginOptions?: any;
248
+ required?: boolean;
249
+ type?: "media";
250
+ multiple?: boolean;
251
+ allowedTypes?: ("images" | "videos" | "audios" | "files")[];
252
+ } | {
253
+ __t4s_required?: boolean;
254
+ pluginOptions?: any;
255
+ required?: boolean;
256
+ type?: "boolean";
257
+ } | {
258
+ __t4s_required?: boolean;
259
+ pluginOptions?: any;
260
+ required?: boolean;
261
+ type?: "relation";
262
+ target?: string;
263
+ relation?: "oneToOne";
264
+ } | {
265
+ __t4s_required?: boolean;
266
+ pluginOptions?: any;
267
+ required?: boolean;
268
+ type?: "relation";
269
+ target?: string;
270
+ relation?: "oneToOne";
271
+ inversedBy?: string;
272
+ } | {
273
+ __t4s_required?: boolean;
274
+ pluginOptions?: any;
275
+ required?: boolean;
276
+ type?: "relation";
277
+ target?: string;
278
+ mappedBy?: string;
279
+ relation?: "oneToMany";
280
+ } | {
281
+ __t4s_required?: boolean;
282
+ pluginOptions?: any;
283
+ required?: boolean;
284
+ type?: "relation";
285
+ target?: string;
286
+ relation?: "manyToOne";
287
+ inversedBy?: string;
288
+ } | {
289
+ __t4s_required?: boolean;
290
+ pluginOptions?: any;
291
+ required?: boolean;
292
+ type?: "relation";
293
+ target?: string;
294
+ relation?: "manyToMany";
295
+ inversedBy?: string;
296
+ mappedBy?: string;
297
+ } | {
298
+ __t4s_required?: boolean;
299
+ pluginOptions?: any;
300
+ required?: boolean;
301
+ type?: "relation";
302
+ target?: string;
303
+ relation?: "oneToMany";
304
+ } | {
305
+ type?: "relation";
306
+ relation?: "morphToMany";
307
+ } | {
308
+ __t4s_required?: boolean;
309
+ pluginOptions?: any;
310
+ required?: boolean;
311
+ type?: "component";
312
+ repeatable?: boolean;
313
+ component?: string;
314
+ }>;
315
+ options?: {};
316
+ uid?: string;
317
+ }>>;
318
+ private loadStrapi;
319
+ }
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ // This reader works by loading Strapi and accessing the content types directly on the instance
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.LoadStrapiReader = void 0;
14
+ const child_process_1 = require("child_process");
15
+ const promises_1 = require("fs/promises");
16
+ const posix_1 = require("path/posix");
17
+ const zod_1 = require("zod");
18
+ const component_1 = require("../types/component");
19
+ const content_type_1 = require("../types/content-type");
20
+ const schema = zod_1.z.tuple([
21
+ zod_1.z.record(content_type_1.strapiContentType),
22
+ zod_1.z.record(component_1.strapiComponent),
23
+ ]);
24
+ class LoadStrapiReader {
25
+ constructor(strapiRoot) {
26
+ this.strapiRoot = strapiRoot;
27
+ this.loadStrapiPromise = this.loadStrapi();
28
+ }
29
+ readContentTypes() {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ const data = (yield this.loadStrapiPromise)[0];
32
+ const newData = {};
33
+ Object.entries(data).forEach(([strapiName, schema]) => {
34
+ const [namespace, collectionAndBase] = strapiName.split('::');
35
+ if (namespace === 'admin') {
36
+ newData[strapiName] = {
37
+ namespace: namespace,
38
+ name: collectionAndBase,
39
+ contentType: schema,
40
+ };
41
+ return;
42
+ }
43
+ const [collection, base] = collectionAndBase.split('.');
44
+ newData[strapiName] = {
45
+ namespace: namespace,
46
+ collection,
47
+ name: base,
48
+ contentType: schema,
49
+ };
50
+ });
51
+ return newData;
52
+ });
53
+ }
54
+ readComponents() {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ const data = (yield this.loadStrapiPromise)[1];
57
+ return data;
58
+ });
59
+ }
60
+ loadStrapi() {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ const localRemoteFile = (0, posix_1.join)(__dirname, 'remote.js');
63
+ const remoteRemoteFile = (0, posix_1.join)(process.cwd(), this.strapiRoot, '.t4s.remote.js');
64
+ // Plant the remote execution file in the strapi project
65
+ yield (0, promises_1.cp)(localRemoteFile, remoteRemoteFile);
66
+ const output = yield new Promise((resolve, reject) => {
67
+ const remote = (0, child_process_1.spawn)('node', [remoteRemoteFile], {
68
+ cwd: this.strapiRoot,
69
+ });
70
+ const data = [];
71
+ remote.stdout.on('data', (chunk) => {
72
+ data.push(chunk);
73
+ });
74
+ remote.stderr.on('data', (chunk) => {
75
+ console.error(chunk.toString());
76
+ });
77
+ remote.on('close', () => {
78
+ resolve(data.map((b) => b === null || b === void 0 ? void 0 : b.toString()).join(''));
79
+ });
80
+ remote.on('error', (err) => {
81
+ reject(err);
82
+ });
83
+ });
84
+ let jsonParsed;
85
+ try {
86
+ jsonParsed = JSON.parse(output);
87
+ }
88
+ catch (err) {
89
+ console.error(err, output.slice(0, 100));
90
+ throw new Error('Failed to parse output from remote strapi');
91
+ }
92
+ let parsed;
93
+ try {
94
+ parsed = schema.parse(jsonParsed);
95
+ }
96
+ catch (err) {
97
+ console.error(err);
98
+ throw new Error('Failed to parse output from remote strapi, something may be malformed');
99
+ }
100
+ // Remove the remote execution file after we're done
101
+ yield (0, promises_1.rm)(remoteRemoteFile);
102
+ return parsed;
103
+ });
104
+ }
105
+ }
106
+ exports.LoadStrapiReader = LoadStrapiReader;