strapi-typed-client 2.2.0 → 2.3.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/README.md +2 -0
- package/dist/cjs/plugin/server/src/controllers/schema.js +3 -3
- package/dist/cjs/plugin/server/src/services/endpoint-parser.js +138 -0
- package/dist/cjs/plugin/server/src/services/endpoints.js +368 -501
- package/dist/cjs/plugin/server/src/services/schema.js +31 -13
- package/dist/cjs/shared/constants.js +9 -6
- package/dist/cli/commands/check.d.ts.map +1 -1
- package/dist/cli/commands/check.js +17 -0
- package/dist/cli/commands/check.js.map +1 -1
- package/dist/cli/commands/generate.d.ts +7 -0
- package/dist/cli/commands/generate.d.ts.map +1 -1
- package/dist/cli/commands/generate.js +48 -17
- package/dist/cli/commands/generate.js.map +1 -1
- package/dist/cli/commands/init.d.ts +2 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +41 -8
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/watch.d.ts +2 -0
- package/dist/cli/commands/watch.d.ts.map +1 -1
- package/dist/cli/commands/watch.js +24 -12
- package/dist/cli/commands/watch.js.map +1 -1
- package/dist/core/endpoint-converter.d.ts +16 -0
- package/dist/core/endpoint-converter.d.ts.map +1 -1
- package/dist/core/endpoint-converter.js +30 -32
- package/dist/core/endpoint-converter.js.map +1 -1
- package/dist/core/generator/filters-generator.d.ts.map +1 -1
- package/dist/core/generator/filters-generator.js +39 -4
- package/dist/core/generator/filters-generator.js.map +1 -1
- package/dist/core/schema-transformer.d.ts.map +1 -1
- package/dist/core/schema-transformer.js +27 -6
- package/dist/core/schema-transformer.js.map +1 -1
- package/dist/generator/auth-api-generator.d.ts +2 -0
- package/dist/generator/auth-api-generator.d.ts.map +1 -1
- package/dist/generator/auth-api-generator.js +35 -45
- package/dist/generator/auth-api-generator.js.map +1 -1
- package/dist/generator/client-generator.d.ts +2 -1
- package/dist/generator/client-generator.d.ts.map +1 -1
- package/dist/generator/client-generator.js +4 -1
- package/dist/generator/client-generator.js.map +1 -1
- package/dist/generator/custom-api-generator.d.ts.map +1 -1
- package/dist/generator/custom-api-generator.js +24 -25
- package/dist/generator/custom-api-generator.js.map +1 -1
- package/dist/generator/index.d.ts +17 -3
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +71 -14
- package/dist/generator/index.js.map +1 -1
- package/dist/generator/input-fields.d.ts +33 -0
- package/dist/generator/input-fields.d.ts.map +1 -0
- package/dist/generator/input-fields.js +78 -0
- package/dist/generator/input-fields.js.map +1 -0
- package/dist/generator/method-signature.d.ts +61 -0
- package/dist/generator/method-signature.d.ts.map +1 -0
- package/dist/generator/method-signature.js +56 -0
- package/dist/generator/method-signature.js.map +1 -0
- package/dist/generator/plugin-api-generator.d.ts.map +1 -1
- package/dist/generator/plugin-api-generator.js +15 -15
- package/dist/generator/plugin-api-generator.js.map +1 -1
- package/dist/generator/types-generator.d.ts +1 -10
- package/dist/generator/types-generator.d.ts.map +1 -1
- package/dist/generator/types-generator.js +123 -88
- package/dist/generator/types-generator.js.map +1 -1
- package/dist/generator/validation-generator.d.ts +26 -0
- package/dist/generator/validation-generator.d.ts.map +1 -0
- package/dist/generator/validation-generator.js +230 -0
- package/dist/generator/validation-generator.js.map +1 -0
- package/dist/generator/zod-resolution.d.ts +2 -0
- package/dist/generator/zod-resolution.d.ts.map +1 -0
- package/dist/generator/zod-resolution.js +22 -0
- package/dist/generator/zod-resolution.js.map +1 -0
- package/dist/next/index.d.ts +3 -0
- package/dist/next/index.d.ts.map +1 -1
- package/dist/next/index.js +19 -7
- package/dist/next/index.js.map +1 -1
- package/dist/plugin/admin/src/pages/HomePage.js +3 -0
- package/dist/plugin/admin/src/pages/HomePage.js.map +1 -1
- package/dist/plugin/server/src/controllers/schema.d.ts +2 -2
- package/dist/plugin/server/src/controllers/schema.d.ts.map +1 -1
- package/dist/plugin/server/src/controllers/schema.js +3 -3
- package/dist/plugin/server/src/controllers/schema.js.map +1 -1
- package/dist/plugin/server/src/index.d.ts +8 -8
- package/dist/plugin/server/src/services/endpoint-parser.d.ts +9 -0
- package/dist/plugin/server/src/services/endpoint-parser.d.ts.map +1 -0
- package/dist/plugin/server/src/services/endpoint-parser.js +136 -0
- package/dist/plugin/server/src/services/endpoint-parser.js.map +1 -0
- package/dist/plugin/server/src/services/endpoints.d.ts +6 -6
- package/dist/plugin/server/src/services/endpoints.d.ts.map +1 -1
- package/dist/plugin/server/src/services/endpoints.js +368 -501
- package/dist/plugin/server/src/services/endpoints.js.map +1 -1
- package/dist/plugin/server/src/services/schema.d.ts +2 -2
- package/dist/plugin/server/src/services/schema.d.ts.map +1 -1
- package/dist/plugin/server/src/services/schema.js +32 -14
- package/dist/plugin/server/src/services/schema.js.map +1 -1
- package/dist/schema-types.d.ts +4 -0
- package/dist/schema-types.d.ts.map +1 -1
- package/dist/shared/client-header.d.ts +11 -0
- package/dist/shared/client-header.d.ts.map +1 -1
- package/dist/shared/client-header.js +20 -0
- package/dist/shared/client-header.js.map +1 -1
- package/dist/shared/constants.d.ts +8 -5
- package/dist/shared/constants.d.ts.map +1 -1
- package/dist/shared/constants.js +8 -5
- package/dist/shared/constants.js.map +1 -1
- package/dist/shared/custom-types.d.ts +1 -0
- package/dist/shared/custom-types.d.ts.map +1 -1
- package/dist/shared/index.d.ts +1 -1
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +1 -1
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/strapi-schema-types.d.ts +3 -0
- package/dist/shared/strapi-schema-types.d.ts.map +1 -1
- package/dist/transformer/index.d.ts +1 -1
- package/dist/transformer/index.d.ts.map +1 -1
- package/dist/transformer/index.js +11 -6
- package/dist/transformer/index.js.map +1 -1
- package/package.json +10 -3
package/dist/generator/index.js
CHANGED
|
@@ -5,6 +5,9 @@ import * as ts from 'typescript';
|
|
|
5
5
|
import { TypesGenerator } from './types-generator.js';
|
|
6
6
|
import { ClientGenerator } from './client-generator.js';
|
|
7
7
|
import { IndexGenerator } from './index-generator.js';
|
|
8
|
+
import { ValidationGenerator } from './validation-generator.js';
|
|
9
|
+
import { resolveZod } from './zod-resolution.js';
|
|
10
|
+
import { VALIDATION_FILE_MARKER, isGeneratedValidationFile, validationFileNames, } from '../shared/client-header.js';
|
|
8
11
|
function stripLocalJsExtensions(source) {
|
|
9
12
|
return source.replace(/(from\s+['"]|export\s+\*\s+from\s+['"])(\.[^'"]*)\.js(['"])/g, '$1$2$3');
|
|
10
13
|
}
|
|
@@ -19,10 +22,17 @@ export class Generator {
|
|
|
19
22
|
this.clientGenerator = new ClientGenerator();
|
|
20
23
|
this.indexGenerator = new IndexGenerator();
|
|
21
24
|
}
|
|
22
|
-
async generate(schema, endpoints, extraTypes, schemaHash = '', generatorVersion = '', format = 'js', typecheck = true, authMode = 'legacy') {
|
|
25
|
+
async generate(schema, { endpoints, extraTypes, schemaHash = '', generatorVersion = '', format = 'js', typecheck = true, authMode = 'legacy', validation = 'none', } = {}) {
|
|
26
|
+
// Fail before any work: a missing zod or a foreign validation file must
|
|
27
|
+
// not leave a half-written tree
|
|
28
|
+
this.assertValidationFilesAreOurs(validation);
|
|
29
|
+
const zodDir = validation === 'zod' ? resolveZod(this.outputDir) : undefined;
|
|
30
|
+
const moduleOptions = zodDir
|
|
31
|
+
? { paths: { zod: [zodDir] } }
|
|
32
|
+
: {};
|
|
23
33
|
// Generate all source contents
|
|
24
34
|
const typesContent = this.typesGenerator.generate(schema);
|
|
25
|
-
const clientContent = this.clientGenerator.generate(schema, endpoints, extraTypes, schemaHash, generatorVersion, authMode);
|
|
35
|
+
const clientContent = this.clientGenerator.generate(schema, endpoints, extraTypes, schemaHash, generatorVersion, authMode, validation);
|
|
26
36
|
const indexContent = this.indexGenerator.generate();
|
|
27
37
|
// Format all files with prettier
|
|
28
38
|
const files = {
|
|
@@ -30,6 +40,9 @@ export class Generator {
|
|
|
30
40
|
'client.ts': await this.formatContent(clientContent),
|
|
31
41
|
'index.ts': await this.formatContent(indexContent),
|
|
32
42
|
};
|
|
43
|
+
if (validation === 'zod') {
|
|
44
|
+
files['validation.ts'] = await this.formatContent(new ValidationGenerator().generate(schema));
|
|
45
|
+
}
|
|
33
46
|
if (format === 'ts') {
|
|
34
47
|
// Write raw TypeScript for consumers that compile sources
|
|
35
48
|
// themselves (monorepos). Strip `.js` extensions from local
|
|
@@ -42,15 +55,46 @@ export class Generator {
|
|
|
42
55
|
]));
|
|
43
56
|
// Type-check the exact bytes we're about to write, BEFORE touching
|
|
44
57
|
// the consumer's tree — a guard throw must leave it untouched.
|
|
45
|
-
this.verifyGeneratedTypes(strippedFiles, typecheck);
|
|
58
|
+
this.verifyGeneratedTypes(strippedFiles, typecheck, moduleOptions);
|
|
46
59
|
this.ensureOutputDir();
|
|
47
60
|
for (const [fileName, data] of Object.entries(strippedFiles)) {
|
|
48
61
|
fs.writeFileSync(path.join(this.outputDir, fileName), data, 'utf-8');
|
|
49
62
|
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
// Compile all files together so cross-file imports resolve correctly
|
|
66
|
+
await this.compileFiles(files, typecheck, moduleOptions);
|
|
67
|
+
}
|
|
68
|
+
this.removeStaleValidationFiles(format, validation);
|
|
69
|
+
}
|
|
70
|
+
assertValidationFilesAreOurs(validation) {
|
|
71
|
+
if (validation !== 'zod')
|
|
50
72
|
return;
|
|
73
|
+
// The other format's name matters too: `./validation` would resolve to either
|
|
74
|
+
for (const name of [
|
|
75
|
+
...validationFileNames('ts'),
|
|
76
|
+
...validationFileNames('js'),
|
|
77
|
+
]) {
|
|
78
|
+
const file = path.join(this.outputDir, name);
|
|
79
|
+
if (fs.existsSync(file) && !isGeneratedValidationFile(file)) {
|
|
80
|
+
throw new Error(`${file} was not generated by strapi-typed-client, so it will not be overwritten. Rename it or generate into another --output.`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Covers turning validation off and switching format while it is on
|
|
85
|
+
removeStaleValidationFiles(format, validation) {
|
|
86
|
+
const keep = new Set(validation === 'zod' ? validationFileNames(format) : []);
|
|
87
|
+
for (const name of [
|
|
88
|
+
...validationFileNames('ts'),
|
|
89
|
+
...validationFileNames('js'),
|
|
90
|
+
]) {
|
|
91
|
+
if (keep.has(name))
|
|
92
|
+
continue;
|
|
93
|
+
const file = path.join(this.outputDir, name);
|
|
94
|
+
if (fs.existsSync(file) && isGeneratedValidationFile(file)) {
|
|
95
|
+
fs.rmSync(file);
|
|
96
|
+
}
|
|
51
97
|
}
|
|
52
|
-
// Compile all files together so cross-file imports resolve correctly
|
|
53
|
-
await this.compileFiles(files, typecheck);
|
|
54
98
|
}
|
|
55
99
|
ensureOutputDir() {
|
|
56
100
|
if (!fs.existsSync(this.outputDir)) {
|
|
@@ -73,8 +117,9 @@ export class Generator {
|
|
|
73
117
|
return content;
|
|
74
118
|
}
|
|
75
119
|
}
|
|
76
|
-
async compileFiles(files, typecheck) {
|
|
120
|
+
async compileFiles(files, typecheck, moduleOptions) {
|
|
77
121
|
const compilerOptions = {
|
|
122
|
+
...moduleOptions,
|
|
78
123
|
target: ts.ScriptTarget.ES2022,
|
|
79
124
|
module: ts.ModuleKind.ES2022,
|
|
80
125
|
declaration: true,
|
|
@@ -107,15 +152,24 @@ export class Generator {
|
|
|
107
152
|
// type-check. Verify it the way a consumer's tsc would (on disk, where
|
|
108
153
|
// bundler resolution maps the `.js` import specifiers to the sibling
|
|
109
154
|
// `.ts`) and fail loudly rather than emit broken types into their tree.
|
|
110
|
-
this.verifyGeneratedTypes(files, typecheck);
|
|
155
|
+
this.verifyGeneratedTypes(files, typecheck, moduleOptions);
|
|
111
156
|
// Compile all files together
|
|
112
157
|
const program = ts.createProgram(fileNames, compilerOptions, host);
|
|
113
|
-
program.emit();
|
|
158
|
+
const emitted = program.emit();
|
|
159
|
+
// Declaration emit can fail on its own (e.g. TS7056) after the type check passed
|
|
160
|
+
if (emitted.diagnostics.length > 0) {
|
|
161
|
+
throw new Error(`Failed to emit the generated client:\n${ts.formatDiagnostics(emitted.diagnostics, host)}`);
|
|
162
|
+
}
|
|
114
163
|
// Write output files
|
|
115
164
|
this.ensureOutputDir();
|
|
116
165
|
for (const [fileName, data] of Object.entries(outputs)) {
|
|
117
166
|
const outputPath = path.join(this.outputDir, fileName);
|
|
118
|
-
|
|
167
|
+
// tsc drops the leading comment from declarations; the marker is what
|
|
168
|
+
// lets a later run recognise this file as ours
|
|
169
|
+
const content = fileName === 'validation.d.ts'
|
|
170
|
+
? `${VALIDATION_FILE_MARKER}\n${data}`
|
|
171
|
+
: data;
|
|
172
|
+
fs.writeFileSync(outputPath, content, 'utf-8');
|
|
119
173
|
}
|
|
120
174
|
}
|
|
121
175
|
/**
|
|
@@ -124,8 +178,8 @@ export class Generator {
|
|
|
124
178
|
* to a warning and writes anyway, so a strict-only false positive can't
|
|
125
179
|
* wedge an upgrade with no recourse.
|
|
126
180
|
*/
|
|
127
|
-
verifyGeneratedTypes(files, typecheck) {
|
|
128
|
-
const message = this.collectTypeErrors(files);
|
|
181
|
+
verifyGeneratedTypes(files, typecheck, moduleOptions) {
|
|
182
|
+
const message = this.collectTypeErrors(files, moduleOptions);
|
|
129
183
|
if (!message)
|
|
130
184
|
return;
|
|
131
185
|
if (typecheck)
|
|
@@ -137,10 +191,11 @@ export class Generator {
|
|
|
137
191
|
* a formatted error message, or null if clean. Run from a temp dir on disk
|
|
138
192
|
* so bundler resolution maps the `.js` import specifiers to the sibling
|
|
139
193
|
* `.ts` files — the in-memory emit program can't resolve those, so it can't
|
|
140
|
-
* double as the check. Strict +
|
|
141
|
-
* tsconfig
|
|
194
|
+
* double as the check. Strict + noUncheckedIndexedAccess is deliberately
|
|
195
|
+
* stricter than a typical consumer tsconfig — the strict presets ship the
|
|
196
|
+
* flag, and the emitted client must stay clean under them.
|
|
142
197
|
*/
|
|
143
|
-
collectTypeErrors(files) {
|
|
198
|
+
collectTypeErrors(files, moduleOptions) {
|
|
144
199
|
const checkDir = fs.mkdtempSync(path.join(os.tmpdir(), 'strapi-types-check-'));
|
|
145
200
|
try {
|
|
146
201
|
for (const [name, content] of Object.entries(files)) {
|
|
@@ -148,10 +203,12 @@ export class Generator {
|
|
|
148
203
|
}
|
|
149
204
|
const rootNames = Object.keys(files).map(n => path.join(checkDir, n));
|
|
150
205
|
const program = ts.createProgram(rootNames, {
|
|
206
|
+
...moduleOptions,
|
|
151
207
|
target: ts.ScriptTarget.ES2022,
|
|
152
208
|
module: ts.ModuleKind.ES2022,
|
|
153
209
|
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
154
210
|
strict: true,
|
|
211
|
+
noUncheckedIndexedAccess: true,
|
|
155
212
|
skipLibCheck: true,
|
|
156
213
|
noEmit: true,
|
|
157
214
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,KAAK,EAAE,MAAM,YAAY,CAAA;AAEhC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,KAAK,EAAE,MAAM,YAAY,CAAA;AAEhC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAA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AC,EAAE;gBACL,MAAM,GAAG,GAAG,EAAE,CAAC,4BAA4B,CACvC,CAAC,CAAC,WAAW,EACb,IAAI,CACP,CAAA;gBACD,MAAM,GAAG,GACL,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,KAAK,SAAS;oBAC3B,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAC7B,CAAC,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC,CAAC,KAAK,CAAC;yBACxC,IAAI,GAAG,CAChB,GAAG;oBACL,CAAC,CAAC,EAAE,CAAA;gBACZ,OAAO,KAAK,GAAG,KAAK,CAAC,CAAC,IAAI,KAAK,GAAG,EAAE,CAAA;YACxC,CAAC,CAAC;iBACD,IAAI,CAAC,IAAI,CAAC,CAAA;YACf,OAAO,CACH,0CAA0C,WAAW,CAAC,MAAM,cAAc;gBAC1E,wDAAwD;gBACxD,2EAA2E,OAAO,EAAE,CACvF,CAAA;QACL,CAAC;gBAAS,CAAC;YACP,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;QACzD,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Attribute, Component, ContentType, ParsedSchema } from '../schema-types.js';
|
|
2
|
+
export type InputMode = 'Create' | 'Update';
|
|
3
|
+
export type InputField = {
|
|
4
|
+
name: string;
|
|
5
|
+
optional: boolean;
|
|
6
|
+
} & ({
|
|
7
|
+
kind: 'id';
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'attribute';
|
|
10
|
+
attr: Attribute;
|
|
11
|
+
nullable: boolean;
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'media';
|
|
14
|
+
multiple: boolean;
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'relation';
|
|
17
|
+
} | {
|
|
18
|
+
kind: 'component';
|
|
19
|
+
componentType: string;
|
|
20
|
+
repeatable: boolean;
|
|
21
|
+
nullable: boolean;
|
|
22
|
+
} | {
|
|
23
|
+
kind: 'dynamiczone';
|
|
24
|
+
componentTypes: string[];
|
|
25
|
+
} | {
|
|
26
|
+
kind: 'locale';
|
|
27
|
+
} | {
|
|
28
|
+
kind: 'publishedAt';
|
|
29
|
+
});
|
|
30
|
+
export declare function inputFields(type: ContentType | Component, mode: InputMode, isContentType: boolean): InputField[];
|
|
31
|
+
/** UIDs of the components used inside any dynamic zone. */
|
|
32
|
+
export declare function dzComponentUids(schema: ParsedSchema): Set<string>;
|
|
33
|
+
//# sourceMappingURL=input-fields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-fields.d.ts","sourceRoot":"","sources":["../../src/generator/input-fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,SAAS,EACT,SAAS,EACT,WAAW,EACX,YAAY,EACf,MAAM,oBAAoB,CAAA;AAE3B,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAA;AAG3C,MAAM,MAAM,UAAU,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GAAG,CACzD;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,GACd;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GACzD;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,GACpB;IACI,IAAI,EAAE,WAAW,CAAA;IACjB,aAAa,EAAE,MAAM,CAAA;IACrB,UAAU,EAAE,OAAO,CAAA;IACnB,QAAQ,EAAE,OAAO,CAAA;CACpB,GACD;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,cAAc,EAAE,MAAM,EAAE,CAAA;CAAE,GACjD;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,CAC5B,CAAA;AAGD,wBAAgB,WAAW,CACvB,IAAI,EAAE,WAAW,GAAG,SAAS,EAC7B,IAAI,EAAE,SAAS,EACf,aAAa,EAAE,OAAO,GACvB,UAAU,EAAE,CAkEd;AAED,2DAA2D;AAC3D,wBAAgB,eAAe,CAAC,MAAM,EAAE,YAAY,GAAG,GAAG,CAAC,MAAM,CAAC,CAQjE"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Each rule mirrors what a live Strapi 5 accepts on create/update (see input-types docs)
|
|
2
|
+
export function inputFields(type, mode, isContentType) {
|
|
3
|
+
const update = mode === 'Update';
|
|
4
|
+
const fields = [];
|
|
5
|
+
if (!isContentType)
|
|
6
|
+
fields.push({ name: 'id', optional: true, kind: 'id' });
|
|
7
|
+
for (const attr of type.attributes) {
|
|
8
|
+
// Strapi applies a schema default before checking `required`
|
|
9
|
+
const hasDefault = attr.defaultValue !== undefined && attr.defaultValue !== null;
|
|
10
|
+
fields.push({
|
|
11
|
+
name: attr.name,
|
|
12
|
+
optional: update || !attr.required || hasDefault,
|
|
13
|
+
kind: 'attribute',
|
|
14
|
+
attr,
|
|
15
|
+
nullable: !attr.required,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
for (const media of type.media) {
|
|
19
|
+
fields.push({
|
|
20
|
+
name: media.name,
|
|
21
|
+
optional: true,
|
|
22
|
+
kind: 'media',
|
|
23
|
+
multiple: media.multiple,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
// Strapi-managed relations (the creator fields) are readable but never writable
|
|
27
|
+
for (const rel of type.relations) {
|
|
28
|
+
if (rel.readOnly)
|
|
29
|
+
continue;
|
|
30
|
+
fields.push({ name: rel.name, optional: true, kind: 'relation' });
|
|
31
|
+
}
|
|
32
|
+
// Strapi rejects null for repeatable components and dynamic zones, and
|
|
33
|
+
// enforces `required` on a single component (unlike relations/media).
|
|
34
|
+
for (const comp of type.components) {
|
|
35
|
+
const required = comp.required && !comp.repeatable;
|
|
36
|
+
fields.push({
|
|
37
|
+
name: comp.name,
|
|
38
|
+
optional: update || !required,
|
|
39
|
+
kind: 'component',
|
|
40
|
+
componentType: comp.componentType,
|
|
41
|
+
repeatable: comp.repeatable,
|
|
42
|
+
nullable: !comp.repeatable && !required,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
for (const dz of type.dynamicZones) {
|
|
46
|
+
fields.push({
|
|
47
|
+
name: dz.name,
|
|
48
|
+
optional: true,
|
|
49
|
+
kind: 'dynamiczone',
|
|
50
|
+
componentTypes: dz.componentTypes,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
// i18n content types already carry `locale` as an attribute
|
|
54
|
+
const taken = new Set(fields.map(f => f.name));
|
|
55
|
+
if (isContentType && !taken.has('locale')) {
|
|
56
|
+
fields.push({ name: 'locale', optional: true, kind: 'locale' });
|
|
57
|
+
}
|
|
58
|
+
if (isContentType && !taken.has('publishedAt')) {
|
|
59
|
+
fields.push({
|
|
60
|
+
name: 'publishedAt',
|
|
61
|
+
optional: true,
|
|
62
|
+
kind: 'publishedAt',
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return fields;
|
|
66
|
+
}
|
|
67
|
+
/** UIDs of the components used inside any dynamic zone. */
|
|
68
|
+
export function dzComponentUids(schema) {
|
|
69
|
+
const uids = new Set();
|
|
70
|
+
for (const owner of [...schema.contentTypes, ...schema.components]) {
|
|
71
|
+
for (const dz of owner.dynamicZones) {
|
|
72
|
+
for (const uid of dz.components)
|
|
73
|
+
uids.add(uid);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return uids;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=input-fields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-fields.js","sourceRoot":"","sources":["../../src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AAQ,EAAE,IAAI;YACd,IAAI,EAAE,aAAa;SACtB,CAAC,CAAA;IACN,CAAC;IAED,OAAO,MAAM,CAAA;AACjB,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,eAAe,CAAC,MAAoB;IAChD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAA;IAC9B,KAAK,MAAM,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,YAAY,EAAE,GAAG,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;QACjE,KAAK,MAAM,EAAE,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC;YAClC,KAAK,MAAM,GAAG,IAAI,EAAE,CAAC,UAAU;gBAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAClD,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth for the shape of a generated API method: its
|
|
3
|
+
* parameter list and its `this.request` call.
|
|
4
|
+
*
|
|
5
|
+
* Custom routes, auth and the plugin registry each assembled both by hand,
|
|
6
|
+
* three parallel implementations of one pattern — and `nextOptions` fell out
|
|
7
|
+
* of one of them entirely plus two hand-rolled auth special cases (#89).
|
|
8
|
+
* Anything that must hold for every generated request belongs here, so a new
|
|
9
|
+
* generator inherits it instead of re-deriving it.
|
|
10
|
+
*
|
|
11
|
+
* Emitted text is not whitespace-sensitive: the generator runs prettier over
|
|
12
|
+
* every file before writing it.
|
|
13
|
+
*/
|
|
14
|
+
/** Trailing parameter every request-issuing method carries. */
|
|
15
|
+
export declare const NEXT_OPTIONS_PARAM = "nextOptions?: NextOptions";
|
|
16
|
+
/** The matching argument name, third positional slot of `request`. */
|
|
17
|
+
export declare const NEXT_OPTIONS_ARG = "nextOptions";
|
|
18
|
+
export interface MethodParamsSpec {
|
|
19
|
+
/** Path parameters in declaration order; always typed `string`. */
|
|
20
|
+
pathParams?: readonly string[];
|
|
21
|
+
/** Request body, for POST/PUT/PATCH. */
|
|
22
|
+
data?: {
|
|
23
|
+
name?: string;
|
|
24
|
+
type: string;
|
|
25
|
+
optional?: boolean;
|
|
26
|
+
};
|
|
27
|
+
/** Query parameters. */
|
|
28
|
+
query?: {
|
|
29
|
+
name?: string;
|
|
30
|
+
type: string;
|
|
31
|
+
optional?: boolean;
|
|
32
|
+
};
|
|
33
|
+
/** Anything caller-specific that must precede `nextOptions`. */
|
|
34
|
+
extra?: readonly string[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Build a method's parameter list. `nextOptions` is appended unconditionally —
|
|
38
|
+
* that is the whole point of routing signatures through here.
|
|
39
|
+
*/
|
|
40
|
+
export declare function buildMethodParams(spec?: MethodParamsSpec): string;
|
|
41
|
+
export interface RequestCallSpec {
|
|
42
|
+
/** Type argument for `request<...>`. */
|
|
43
|
+
responseType: string;
|
|
44
|
+
/** URL expression; defaults to the local `url` binding. */
|
|
45
|
+
url?: string;
|
|
46
|
+
/**
|
|
47
|
+
* `RequestInit` literal. Defaults to `{}` — a GET still has to pass it so
|
|
48
|
+
* `nextOptions` lands in the third slot rather than being read as the init.
|
|
49
|
+
*/
|
|
50
|
+
init?: string;
|
|
51
|
+
/** Error-message prefix, when the caller emits one. */
|
|
52
|
+
errorPrefix?: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Build a `this.request(...)` call with `nextOptions` in its third positional
|
|
56
|
+
* slot. Passing it second — where `RequestInit` goes — type-checks against the
|
|
57
|
+
* generated client and silently drops every Next.js option, so the argument
|
|
58
|
+
* order is fixed here rather than at each call site.
|
|
59
|
+
*/
|
|
60
|
+
export declare function buildRequestCall(spec: RequestCallSpec): string;
|
|
61
|
+
//# sourceMappingURL=method-signature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"method-signature.d.ts","sourceRoot":"","sources":["../../src/generator/method-signature.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,+DAA+D;AAC/D,eAAO,MAAM,kBAAkB,8BAA8B,CAAA;AAE7D,sEAAsE;AACtE,eAAO,MAAM,gBAAgB,gBAAgB,CAAA;AAE7C,MAAM,WAAW,gBAAgB;IAC7B,mEAAmE;IACnE,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IAC9B,wCAAwC;IACxC,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;IAC1D,wBAAwB;IACxB,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;IAC3D,gEAAgE;IAChE,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAC5B;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,GAAE,gBAAqB,GAAG,MAAM,CAuBrE;AAED,MAAM,WAAW,eAAe;IAC5B,wCAAwC;IACxC,YAAY,EAAE,MAAM,CAAA;IACpB,2DAA2D;IAC3D,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,uDAAuD;IACvD,WAAW,CAAC,EAAE,MAAM,CAAA;CACvB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM,CAS9D"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth for the shape of a generated API method: its
|
|
3
|
+
* parameter list and its `this.request` call.
|
|
4
|
+
*
|
|
5
|
+
* Custom routes, auth and the plugin registry each assembled both by hand,
|
|
6
|
+
* three parallel implementations of one pattern — and `nextOptions` fell out
|
|
7
|
+
* of one of them entirely plus two hand-rolled auth special cases (#89).
|
|
8
|
+
* Anything that must hold for every generated request belongs here, so a new
|
|
9
|
+
* generator inherits it instead of re-deriving it.
|
|
10
|
+
*
|
|
11
|
+
* Emitted text is not whitespace-sensitive: the generator runs prettier over
|
|
12
|
+
* every file before writing it.
|
|
13
|
+
*/
|
|
14
|
+
/** Trailing parameter every request-issuing method carries. */
|
|
15
|
+
export const NEXT_OPTIONS_PARAM = 'nextOptions?: NextOptions';
|
|
16
|
+
/** The matching argument name, third positional slot of `request`. */
|
|
17
|
+
export const NEXT_OPTIONS_ARG = 'nextOptions';
|
|
18
|
+
/**
|
|
19
|
+
* Build a method's parameter list. `nextOptions` is appended unconditionally —
|
|
20
|
+
* that is the whole point of routing signatures through here.
|
|
21
|
+
*/
|
|
22
|
+
export function buildMethodParams(spec = {}) {
|
|
23
|
+
const params = [];
|
|
24
|
+
for (const param of spec.pathParams ?? []) {
|
|
25
|
+
params.push(`${param}: string`);
|
|
26
|
+
}
|
|
27
|
+
if (spec.data) {
|
|
28
|
+
const name = spec.data.name ?? 'data';
|
|
29
|
+
const optional = spec.data.optional ?? true;
|
|
30
|
+
params.push(`${name}${optional ? '?' : ''}: ${spec.data.type}`);
|
|
31
|
+
}
|
|
32
|
+
if (spec.query) {
|
|
33
|
+
const name = spec.query.name ?? 'params';
|
|
34
|
+
const optional = spec.query.optional ?? true;
|
|
35
|
+
params.push(`${name}${optional ? '?' : ''}: ${spec.query.type}`);
|
|
36
|
+
}
|
|
37
|
+
params.push(...(spec.extra ?? []));
|
|
38
|
+
params.push(NEXT_OPTIONS_PARAM);
|
|
39
|
+
return params.join(', ');
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Build a `this.request(...)` call with `nextOptions` in its third positional
|
|
43
|
+
* slot. Passing it second — where `RequestInit` goes — type-checks against the
|
|
44
|
+
* generated client and silently drops every Next.js option, so the argument
|
|
45
|
+
* order is fixed here rather than at each call site.
|
|
46
|
+
*/
|
|
47
|
+
export function buildRequestCall(spec) {
|
|
48
|
+
const args = [
|
|
49
|
+
spec.url ?? 'url',
|
|
50
|
+
spec.init ?? '{}',
|
|
51
|
+
NEXT_OPTIONS_ARG,
|
|
52
|
+
...(spec.errorPrefix ? [`'${spec.errorPrefix}'`] : []),
|
|
53
|
+
];
|
|
54
|
+
return `this.request<${spec.responseType}>(${args.join(', ')})`;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=method-signature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"method-signature.js","sourceRoot":"","sources":["../../src/generator/method-signature.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,+DAA+D;AAC/D,MAAM,CAAC,MAAM,kBAAkB,GAAG,2BAA2B,CAAA;AAE7D,sEAAsE;AACtE,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAAA;AAa7C;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAyB,EAAE;IACzD,MAAM,MAAM,GAAa,EAAE,CAAA;IAE3B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC;QACxC,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,UAAU,CAAC,CAAA;IACnC,CAAC;IAED,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;QACZ,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,MAAM,CAAA;QACrC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAA;QAC3C,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;IACnE,CAAC;IAED,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,QAAQ,CAAA;QACxC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,IAAI,IAAI,CAAA;QAC5C,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAA;IACpE,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAA;IAClC,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;IAE/B,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAC5B,CAAC;AAgBD;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAqB;IAClD,MAAM,IAAI,GAAG;QACT,IAAI,CAAC,GAAG,IAAI,KAAK;QACjB,IAAI,CAAC,IAAI,IAAI,IAAI;QACjB,gBAAgB;QAChB,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;KACzD,CAAA;IAED,OAAO,gBAAgB,IAAI,CAAC,YAAY,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAA;AACnE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-api-generator.d.ts","sourceRoot":"","sources":["../../src/generator/plugin-api-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,cAAc,EAEjB,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"plugin-api-generator.d.ts","sourceRoot":"","sources":["../../src/generator/plugin-api-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,cAAc,EAEjB,MAAM,sBAAsB,CAAA;AAG7B;;;;;;;;GAQG;AACH,qBAAa,kBAAkB;IAC3B;;;;;OAKG;IACH,wBAAwB,CACpB,SAAS,GAAE,cAAc,EAAoB,GAC9C,MAAM;IAMT,OAAO,CAAC,mBAAmB;IAe3B,OAAO,CAAC,cAAc;IA8BtB,sEAAsE;IACtE,OAAO,CAAC,aAAa;IASrB,OAAO,CAAC,eAAe;IAcvB,OAAO,CAAC,aAAa;IAkBrB,OAAO,CAAC,mBAAmB;IAkB3B,OAAO,CAAC,eAAe;CAO1B"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PLUGIN_REGISTRY, } from './plugin-registry.js';
|
|
2
|
+
import { buildMethodParams, buildRequestCall } from './method-signature.js';
|
|
2
3
|
/**
|
|
3
4
|
* Generates standalone API classes for Strapi plugins listed in
|
|
4
5
|
* `PLUGIN_REGISTRY`. Each contract becomes a `class XxxAPI extends BaseAPI`
|
|
@@ -42,7 +43,11 @@ ${methods}
|
|
|
42
43
|
const method = `${docComment}
|
|
43
44
|
async ${ep.methodName}(${params}): Promise<${ep.responseType}> {
|
|
44
45
|
${indentedUrl}
|
|
45
|
-
return
|
|
46
|
+
return ${buildRequestCall({
|
|
47
|
+
responseType: ep.responseType,
|
|
48
|
+
init: reqOptions,
|
|
49
|
+
errorPrefix,
|
|
50
|
+
})}
|
|
46
51
|
}`;
|
|
47
52
|
if (!ep.deprecatedAlias)
|
|
48
53
|
return method;
|
|
@@ -68,20 +73,15 @@ ${indentedUrl}
|
|
|
68
73
|
return names.join(', ');
|
|
69
74
|
}
|
|
70
75
|
buildParameters(ep) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
if (ep.queryType) {
|
|
81
|
-
parts.push(`params?: ${ep.queryType}`);
|
|
82
|
-
}
|
|
83
|
-
parts.push('nextOptions?: NextOptions');
|
|
84
|
-
return parts.join(', ');
|
|
76
|
+
// paramTypes carry their own types, so they go through `extra` rather
|
|
77
|
+
// than the string-typed pathParams slot.
|
|
78
|
+
return buildMethodParams({
|
|
79
|
+
extra: [
|
|
80
|
+
...Object.entries(ep.paramTypes ?? {}).map(([name, type]) => `${name}: ${type}`),
|
|
81
|
+
...(ep.bodyType ? [`body: ${ep.bodyType}`] : []),
|
|
82
|
+
...(ep.queryType ? [`params?: ${ep.queryType}`] : []),
|
|
83
|
+
],
|
|
84
|
+
});
|
|
85
85
|
}
|
|
86
86
|
buildUrlLines(ep) {
|
|
87
87
|
let path = ep.path;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-api-generator.js","sourceRoot":"","sources":["../../src/generator/plugin-api-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,eAAe,GAGlB,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"plugin-api-generator.js","sourceRoot":"","sources":["../../src/generator/plugin-api-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,eAAe,GAGlB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAE3E;;;;;;;;GAQG;AACH,MAAM,OAAO,kBAAkB;IAC3B;;;;;OAKG;IACH,wBAAwB,CACpB,YAA8B,eAAe;QAE7C,OAAO,SAAS;aACX,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;aACnD,IAAI,CAAC,MAAM,CAAC,CAAA;IACrB,CAAC;IAEO,mBAAmB,CAAC,QAAwB;QAChD,MAAM,OAAO,GAAG,QAAQ,CAAC,SAAS;aAC7B,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;aACxD,IAAI,CAAC,MAAM,CAAC,CAAA;QAEjB,OAAO,eAAe,QAAQ,CAAC,UAAU;QACzC,QAAQ,CAAC,SAAS;;;;;EA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AAA;QACL,CAAC;QAED,OAAO,CAAC,4CAA4C,IAAI,IAAI,CAAC,CAAA;IACjE,CAAC;IAEO,mBAAmB,CAAC,EAAkB;QAC1C,MAAM,IAAI,GAAa,EAAE,CAAA;QACzB,IAAI,EAAE,CAAC,MAAM,KAAK,KAAK,EAAE,CAAC;YACtB,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,MAAM,GAAG,CAAC,CAAA;QACvC,CAAC;QACD,IAAI,EAAE,CAAC,QAAQ,EAAE,CAAC;YACd,8DAA8D;YAC9D,kDAAkD;YAClD,IAAI,EAAE,CAAC,QAAQ,KAAK,UAAU,EAAE,CAAC;gBAC7B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;YACrB,CAAC;iBAAM,CAAC;gBACJ,IAAI,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAA;YAC3C,CAAC;QACL,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAA;QAClC,OAAO,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAA;IACnC,CAAC;IAEO,eAAe,CAAC,EAAkB;QACtC,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,MAAM,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAA;QAC3C,IAAI,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC;YAClB,OAAO,SAAS,KAAK,KAAK,CAAA;QAC9B,CAAC;QACD,OAAO,eAAe,EAAE,CAAC,WAAW,gBAAgB,KAAK,SAAS,CAAA;IACtE,CAAC;CACJ"}
|
|
@@ -11,18 +11,9 @@ export declare class TypesGenerator {
|
|
|
11
11
|
private addComponentInterface;
|
|
12
12
|
private addComponentDzAlias;
|
|
13
13
|
private addComponentDzInputAliases;
|
|
14
|
-
private collectDzComponentUids;
|
|
15
14
|
private addComponentInputInterfaces;
|
|
16
|
-
/**
|
|
17
|
-
* Shared property list for `*CreateInput` / `*UpdateInput`. In create mode a
|
|
18
|
-
* required *scalar* drops its `?` (and `| null`); update mode is fully
|
|
19
|
-
* partial (every key optional). Required-ness is enforced for scalars only —
|
|
20
|
-
* Strapi does not validate `required` on relations/media/components at the
|
|
21
|
-
* REST layer, so forcing those keys would reject payloads it accepts.
|
|
22
|
-
* Components / dynamic zones still split so their nested required scalars
|
|
23
|
-
* are enforced in the Create variant.
|
|
24
|
-
*/
|
|
25
15
|
private buildInputProperties;
|
|
16
|
+
private inputFieldType;
|
|
26
17
|
private addContentTypeInterface;
|
|
27
18
|
private addInputTypeInterfaces;
|
|
28
19
|
private addPopulateParams;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-generator.d.ts","sourceRoot":"","sources":["../../src/generator/types-generator.ts"],"names":[],"mappings":"AAMA,OAAO,EACH,YAAY,EAIf,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"types-generator.d.ts","sourceRoot":"","sources":["../../src/generator/types-generator.ts"],"names":[],"mappings":"AAMA,OAAO,EACH,YAAY,EAIf,MAAM,oBAAoB,CAAA;AAqB3B,qBAAa,cAAc;IACvB,OAAO,CAAC,WAAW,CAAiB;IACpC,OAAO,CAAC,MAAM,CAAC,CAAc;;IAM7B,QAAQ,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM;IAkHtC,OAAO,CAAC,iBAAiB;IAkQzB,OAAO,CAAC,mBAAmB;IAW3B,OAAO,CAAC,OAAO;IASf,OAAO,CAAC,gBAAgB;IAsBxB,OAAO,CAAC,qBAAqB;IAoB7B,OAAO,CAAC,mBAAmB;IAQ3B,OAAO,CAAC,0BAA0B;IAalC,OAAO,CAAC,2BAA2B;IAcnC,OAAO,CAAC,oBAAoB;IAkB5B,OAAO,CAAC,cAAc;IAmCtB,OAAO,CAAC,uBAAuB;IAiC/B,OAAO,CAAC,sBAAsB;IAc9B,OAAO,CAAC,iBAAiB;IAgCzB,OAAO,CAAC,0BAA0B;IA+DlC,OAAO,CAAC,sBAAsB;IAyB9B,OAAO,CAAC,mBAAmB;IA6B3B;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAuC/B;;OAEG;IACH,OAAO,CAAC,yBAAyB;IA2CjC;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAyE7B,OAAO,CAAC,uBAAuB;IAS/B;;OAEG;IACH,OAAO,CAAC,oBAAoB;CAqB/B"}
|