@oak-digital/types-4-strapi-2 0.5.5 → 1.0.0-beta.2

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 (86) hide show
  1. package/.eslintrc.json +2 -1
  2. package/CHANGELOG.md +7 -0
  3. package/README.md +17 -5
  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/load-strapi/remote.d.ts +1 -0
  41. package/lib/readers/load-strapi/remote.js +29 -0
  42. package/lib/readers/types/attributes.d.ts +1639 -0
  43. package/lib/readers/types/attributes.js +144 -0
  44. package/lib/readers/types/component.d.ts +723 -0
  45. package/lib/readers/types/component.js +11 -0
  46. package/lib/readers/types/content-type-reader.d.ts +16 -0
  47. package/lib/readers/types/content-type-reader.js +2 -0
  48. package/lib/readers/types/content-type.d.ts +766 -0
  49. package/lib/readers/types/content-type.js +16 -0
  50. package/lib/utils/casing/index.js +2 -2
  51. package/lib/utils/index.js +5 -39
  52. package/lib/writers/basic-writer.d.ts +24 -0
  53. package/lib/writers/basic-writer.js +75 -0
  54. package/lib/writers/types/writer.d.ts +4 -0
  55. package/lib/writers/types/writer.js +2 -0
  56. package/package.json +4 -2
  57. package/tests/strapi-project/.editorconfig +16 -0
  58. package/tests/strapi-project/.env.example +6 -0
  59. package/tests/strapi-project/README.md +57 -0
  60. package/tests/strapi-project/config/admin.ts +13 -0
  61. package/tests/strapi-project/config/api.ts +7 -0
  62. package/tests/strapi-project/config/database.ts +93 -0
  63. package/tests/strapi-project/config/middlewares.ts +12 -0
  64. package/tests/strapi-project/config/server.ts +10 -0
  65. package/tests/strapi-project/database/migrations/.gitkeep +0 -0
  66. package/tests/strapi-project/favicon.png +0 -0
  67. package/tests/strapi-project/package-lock.json +16125 -0
  68. package/tests/strapi-project/package.json +30 -0
  69. package/tests/strapi-project/public/robots.txt +3 -0
  70. package/tests/strapi-project/public/uploads/.gitkeep +0 -0
  71. package/tests/strapi-project/src/admin/app.example.tsx +35 -0
  72. package/tests/strapi-project/src/admin/webpack.config.example.js +9 -0
  73. package/tests/strapi-project/src/api/.gitkeep +0 -0
  74. package/tests/strapi-project/src/api/collection-1/content-types/collection-1/schema.json +18 -0
  75. package/tests/strapi-project/src/api/collection-1/content-types/generated-type/schema.json +18 -0
  76. package/tests/strapi-project/src/api/collection-1/controllers/collection-1.ts +7 -0
  77. package/tests/strapi-project/src/api/collection-1/controllers/generated-type.ts +7 -0
  78. package/tests/strapi-project/src/api/collection-1/routes/collection-1.ts +7 -0
  79. package/tests/strapi-project/src/api/collection-1/routes/generated-type.ts +7 -0
  80. package/tests/strapi-project/src/api/collection-1/services/collection-1.ts +7 -0
  81. package/tests/strapi-project/src/api/collection-1/services/generated-type.ts +7 -0
  82. package/tests/strapi-project/src/api/standalone-controller/controllers/standalone-controller.ts +13 -0
  83. package/tests/strapi-project/src/components/my-category/all-types.json +88 -0
  84. package/tests/strapi-project/src/components/other-category/sub-component.json +12 -0
  85. package/tests/strapi-project/src/extensions/.gitkeep +0 -0
  86. package/tests/strapi-project/src/index.ts +18 -0
@@ -1,41 +1,391 @@
1
+ import { caseType } from '../utils/casing/';
2
+ import { SupportedPluginNamesType } from '../plugins/types';
1
3
  import { File } from '../file/File';
4
+ import { ContentTypeReader } from '../readers/types/content-type-reader';
5
+ import { InterfaceWriter } from '../writers/types/writer';
6
+ declare type InterfaceManagerOptions = {
7
+ /**
8
+ * @default 'I'
9
+ * @type {string}
10
+ * @description The prefix to use for all interfaces
11
+ */
12
+ prefix?: string;
13
+ /**
14
+ * @default true
15
+ * @type {boolean}
16
+ * @description Whether to use the category prefix for component interfaces
17
+ */
18
+ useCategoryPrefix?: boolean;
19
+ /**
20
+ * @default ''
21
+ * @type {string}
22
+ * @description The prefix to use for component interfaces
23
+ */
24
+ componentPrefix?: string;
25
+ /**
26
+ * @default false
27
+ * @type {boolean}
28
+ * @description Whether to use only the component prefix for component interfaces
29
+ */
30
+ componentPrefixOverridesPrefix?: boolean;
31
+ /**
32
+ * @default ''
33
+ * @type {string}
34
+ * @description The prefix to use for builtin interfaces
35
+ */
36
+ /**
37
+ * @default false
38
+ * @type {boolean}
39
+ * @description Whether to use only the builtin prefix for builtin interfaces
40
+ */
41
+ /**
42
+ * @default null
43
+ * @type {string}
44
+ * @description The path to the prettier config file
45
+ */
46
+ fileCaseType?: caseType;
47
+ /**
48
+ * @default 'kebab'
49
+ * @type {caseType}
50
+ * @description The case type to use for folder names
51
+ */
52
+ folderCaseType?: caseType;
53
+ /**
54
+ * @default []
55
+ * @type {SupportedPluginNamesType[]}
56
+ * @description The plugins to use
57
+ */
58
+ enabledPlugins?: SupportedPluginNamesType[];
59
+ };
2
60
  export default class InterfaceManager {
3
61
  private Files;
4
- private OutRoot;
5
- private StrapiSrcRoot;
6
62
  private Options;
7
- private PrettierOptions;
8
63
  private PluginManager;
9
64
  private dependenciesInjected;
10
- static BaseOptions: {
11
- prefix: string;
12
- useCategoryPrefix: boolean;
13
- componentPrefix: string;
14
- componentPrefixOverridesPrefix: boolean;
15
- builtinsPrefix: string;
16
- builtinsPrefixOverridesPrefix: boolean;
17
- deleteOld: boolean;
18
- prettierFile: any;
19
- fileCaseType: "camel" | "capital" | "dot" | "snake" | "pascal" | "constant" | "kebab";
20
- folderCaseType: "camel" | "capital" | "dot" | "snake" | "pascal" | "constant" | "kebab";
21
- enabledPlugins: ("url-alias" | "i18n")[];
22
- };
23
- constructor(outRoot: string, strapiSrcRoot: string, options?: Partial<typeof InterfaceManager['BaseOptions']>);
65
+ private contentTypeReader;
66
+ private interfaceWriter;
67
+ constructor(reader: ContentTypeReader, writer: InterfaceWriter, { prefix, useCategoryPrefix, componentPrefix, componentPrefixOverridesPrefix, fileCaseType, folderCaseType, enabledPlugins, }?: Partial<InterfaceManagerOptions>);
24
68
  registerBuiltinPlugins(): void;
25
69
  registerPlugin(): void;
26
70
  validateOptions(): void;
27
- loadPrettierConfig(): Promise<void>;
28
71
  readSchemas(): Promise<{
29
- apiSchemas: any[];
30
- componentSchemas: any[];
72
+ apiSchemas: Record<`api::${string}` | `plugin::${string}` | `admin::${string}` | `builtins::${string}`, {
73
+ name: string;
74
+ contentType: {
75
+ attributes?: Record<string, {
76
+ __t4s_required?: boolean;
77
+ pluginOptions?: any;
78
+ required?: boolean;
79
+ type?: "text" | "string";
80
+ } | {
81
+ __t4s_required?: boolean;
82
+ pluginOptions?: any;
83
+ required?: boolean;
84
+ type?: "email";
85
+ } | {
86
+ __t4s_required?: boolean;
87
+ pluginOptions?: any;
88
+ required?: boolean;
89
+ type?: "uid";
90
+ targetField?: string;
91
+ } | {
92
+ __t4s_required?: boolean;
93
+ pluginOptions?: any;
94
+ required?: boolean;
95
+ type?: "richtext";
96
+ } | {
97
+ __t4s_required?: boolean;
98
+ pluginOptions?: any;
99
+ required?: boolean;
100
+ type?: "json";
101
+ } | {
102
+ __t4s_required?: boolean;
103
+ pluginOptions?: any;
104
+ required?: boolean;
105
+ type?: "password";
106
+ } | {
107
+ __t4s_required?: boolean;
108
+ pluginOptions?: any;
109
+ required?: boolean;
110
+ type?: "integer";
111
+ } | {
112
+ __t4s_required?: boolean;
113
+ pluginOptions?: any;
114
+ required?: boolean;
115
+ type?: "float";
116
+ } | {
117
+ __t4s_required?: boolean;
118
+ pluginOptions?: any;
119
+ required?: boolean;
120
+ type?: "biginteger";
121
+ } | {
122
+ __t4s_required?: boolean;
123
+ pluginOptions?: any;
124
+ required?: boolean;
125
+ type?: "decimal";
126
+ } | {
127
+ __t4s_required?: boolean;
128
+ pluginOptions?: any;
129
+ required?: boolean;
130
+ type?: "enumeration";
131
+ enum?: string[];
132
+ } | {
133
+ __t4s_required?: boolean;
134
+ pluginOptions?: any;
135
+ required?: boolean;
136
+ type?: "date";
137
+ } | {
138
+ __t4s_required?: boolean;
139
+ pluginOptions?: any;
140
+ required?: boolean;
141
+ type?: "datetime";
142
+ } | {
143
+ __t4s_required?: boolean;
144
+ pluginOptions?: any;
145
+ required?: boolean;
146
+ type?: "time";
147
+ } | {
148
+ __t4s_required?: boolean;
149
+ pluginOptions?: any;
150
+ required?: boolean;
151
+ type?: "media";
152
+ multiple?: boolean;
153
+ allowedTypes?: ("images" | "videos" | "audios" | "files")[];
154
+ } | {
155
+ __t4s_required?: boolean;
156
+ pluginOptions?: any;
157
+ required?: boolean;
158
+ type?: "boolean";
159
+ } | {
160
+ __t4s_required?: boolean;
161
+ pluginOptions?: any;
162
+ required?: boolean;
163
+ type?: "relation";
164
+ target?: string;
165
+ relation?: "oneToOne";
166
+ } | {
167
+ __t4s_required?: boolean;
168
+ pluginOptions?: any;
169
+ required?: boolean;
170
+ type?: "relation";
171
+ target?: string;
172
+ relation?: "oneToOne";
173
+ inversedBy?: string;
174
+ } | {
175
+ __t4s_required?: boolean;
176
+ pluginOptions?: any;
177
+ required?: boolean;
178
+ type?: "relation";
179
+ target?: string;
180
+ mappedBy?: string;
181
+ relation?: "oneToMany";
182
+ } | {
183
+ __t4s_required?: boolean;
184
+ pluginOptions?: any;
185
+ required?: boolean;
186
+ type?: "relation";
187
+ target?: string;
188
+ relation?: "manyToOne";
189
+ inversedBy?: string;
190
+ } | {
191
+ __t4s_required?: boolean;
192
+ pluginOptions?: any;
193
+ required?: boolean;
194
+ type?: "relation";
195
+ target?: string;
196
+ relation?: "manyToMany";
197
+ inversedBy?: string;
198
+ mappedBy?: string;
199
+ } | {
200
+ __t4s_required?: boolean;
201
+ pluginOptions?: any;
202
+ required?: boolean;
203
+ type?: "relation";
204
+ target?: string;
205
+ relation?: "oneToMany";
206
+ } | {
207
+ type?: "relation";
208
+ relation?: "morphToMany";
209
+ } | {
210
+ __t4s_required?: boolean;
211
+ pluginOptions?: any;
212
+ required?: boolean;
213
+ type?: "component";
214
+ repeatable?: boolean;
215
+ component?: string;
216
+ } | {
217
+ __t4s_required?: boolean;
218
+ pluginOptions?: any;
219
+ required?: boolean;
220
+ type?: "dynamiczone";
221
+ components?: string[];
222
+ }>;
223
+ collectionName?: string;
224
+ options?: {
225
+ draftAndPublish?: boolean;
226
+ };
227
+ pluginOptions?: Record<string, any>;
228
+ uid?: string;
229
+ };
230
+ } & ({
231
+ namespace: "api" | "plugin";
232
+ collection: string;
233
+ } | {
234
+ namespace: "admin";
235
+ collection?: null;
236
+ })>;
237
+ componentSchemas: Record<`${string}.${string}`, {
238
+ collectionName?: string;
239
+ attributes?: Record<string, {
240
+ __t4s_required?: boolean;
241
+ pluginOptions?: any;
242
+ required?: boolean;
243
+ type?: "text" | "string";
244
+ } | {
245
+ __t4s_required?: boolean;
246
+ pluginOptions?: any;
247
+ required?: boolean;
248
+ type?: "email";
249
+ } | {
250
+ __t4s_required?: boolean;
251
+ pluginOptions?: any;
252
+ required?: boolean;
253
+ type?: "uid";
254
+ targetField?: string;
255
+ } | {
256
+ __t4s_required?: boolean;
257
+ pluginOptions?: any;
258
+ required?: boolean;
259
+ type?: "richtext";
260
+ } | {
261
+ __t4s_required?: boolean;
262
+ pluginOptions?: any;
263
+ required?: boolean;
264
+ type?: "json";
265
+ } | {
266
+ __t4s_required?: boolean;
267
+ pluginOptions?: any;
268
+ required?: boolean;
269
+ type?: "password";
270
+ } | {
271
+ __t4s_required?: boolean;
272
+ pluginOptions?: any;
273
+ required?: boolean;
274
+ type?: "integer";
275
+ } | {
276
+ __t4s_required?: boolean;
277
+ pluginOptions?: any;
278
+ required?: boolean;
279
+ type?: "float";
280
+ } | {
281
+ __t4s_required?: boolean;
282
+ pluginOptions?: any;
283
+ required?: boolean;
284
+ type?: "biginteger";
285
+ } | {
286
+ __t4s_required?: boolean;
287
+ pluginOptions?: any;
288
+ required?: boolean;
289
+ type?: "decimal";
290
+ } | {
291
+ __t4s_required?: boolean;
292
+ pluginOptions?: any;
293
+ required?: boolean;
294
+ type?: "enumeration";
295
+ enum?: string[];
296
+ } | {
297
+ __t4s_required?: boolean;
298
+ pluginOptions?: any;
299
+ required?: boolean;
300
+ type?: "date";
301
+ } | {
302
+ __t4s_required?: boolean;
303
+ pluginOptions?: any;
304
+ required?: boolean;
305
+ type?: "datetime";
306
+ } | {
307
+ __t4s_required?: boolean;
308
+ pluginOptions?: any;
309
+ required?: boolean;
310
+ type?: "time";
311
+ } | {
312
+ __t4s_required?: boolean;
313
+ pluginOptions?: any;
314
+ required?: boolean;
315
+ type?: "media";
316
+ multiple?: boolean;
317
+ allowedTypes?: ("images" | "videos" | "audios" | "files")[];
318
+ } | {
319
+ __t4s_required?: boolean;
320
+ pluginOptions?: any;
321
+ required?: boolean;
322
+ type?: "boolean";
323
+ } | {
324
+ __t4s_required?: boolean;
325
+ pluginOptions?: any;
326
+ required?: boolean;
327
+ type?: "relation";
328
+ target?: string;
329
+ relation?: "oneToOne";
330
+ } | {
331
+ __t4s_required?: boolean;
332
+ pluginOptions?: any;
333
+ required?: boolean;
334
+ type?: "relation";
335
+ target?: string;
336
+ relation?: "oneToOne";
337
+ inversedBy?: string;
338
+ } | {
339
+ __t4s_required?: boolean;
340
+ pluginOptions?: any;
341
+ required?: boolean;
342
+ type?: "relation";
343
+ target?: string;
344
+ mappedBy?: string;
345
+ relation?: "oneToMany";
346
+ } | {
347
+ __t4s_required?: boolean;
348
+ pluginOptions?: any;
349
+ required?: boolean;
350
+ type?: "relation";
351
+ target?: string;
352
+ relation?: "manyToOne";
353
+ inversedBy?: string;
354
+ } | {
355
+ __t4s_required?: boolean;
356
+ pluginOptions?: any;
357
+ required?: boolean;
358
+ type?: "relation";
359
+ target?: string;
360
+ relation?: "manyToMany";
361
+ inversedBy?: string;
362
+ mappedBy?: string;
363
+ } | {
364
+ __t4s_required?: boolean;
365
+ pluginOptions?: any;
366
+ required?: boolean;
367
+ type?: "relation";
368
+ target?: string;
369
+ relation?: "oneToMany";
370
+ } | {
371
+ type?: "relation";
372
+ relation?: "morphToMany";
373
+ } | {
374
+ __t4s_required?: boolean;
375
+ pluginOptions?: any;
376
+ required?: boolean;
377
+ type?: "component";
378
+ repeatable?: boolean;
379
+ component?: string;
380
+ }>;
381
+ options?: {};
382
+ uid?: string;
383
+ }>;
31
384
  }>;
32
385
  addType(name: string, file: File, force?: boolean): boolean;
33
386
  createInterfaces(): Promise<void>;
34
387
  createBuiltinInterfaces(): void;
35
388
  injectDependencies(): void;
36
- deleteOldFolders(): Promise<void>;
37
- makeFolders(): Promise<void>;
38
- writeInterfaces(): Promise<void>;
39
- writeIndexFile(): Promise<void>;
40
389
  run(): Promise<void>;
41
390
  }
391
+ export {};