strapi-typed-client 1.6.1 → 2.0.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 -2
- package/dist/cli/commands/check.d.ts +2 -3
- package/dist/cli/commands/check.d.ts.map +1 -1
- package/dist/cli/commands/check.js +3 -3
- package/dist/cli/commands/check.js.map +1 -1
- package/dist/cli/commands/generate.d.ts +2 -3
- package/dist/cli/commands/generate.d.ts.map +1 -1
- package/dist/cli/commands/generate.js +3 -3
- package/dist/cli/commands/generate.js.map +1 -1
- package/dist/cli/commands/watch.d.ts +2 -3
- package/dist/cli/commands/watch.d.ts.map +1 -1
- package/dist/cli/commands/watch.js +15 -9
- package/dist/cli/commands/watch.js.map +1 -1
- package/dist/cli/utils/file-writer.d.ts +8 -7
- package/dist/cli/utils/file-writer.d.ts.map +1 -1
- package/dist/cli/utils/file-writer.js +17 -61
- package/dist/cli/utils/file-writer.js.map +1 -1
- package/dist/core/endpoint-converter.d.ts +5 -1
- package/dist/core/endpoint-converter.d.ts.map +1 -1
- package/dist/core/endpoint-converter.js +114 -8
- package/dist/core/endpoint-converter.js.map +1 -1
- package/dist/generator/auth-api-generator.d.ts +11 -3
- package/dist/generator/auth-api-generator.d.ts.map +1 -1
- package/dist/generator/auth-api-generator.js +213 -220
- package/dist/generator/auth-api-generator.js.map +1 -1
- package/dist/generator/client-generator.d.ts +8 -0
- package/dist/generator/client-generator.d.ts.map +1 -1
- package/dist/generator/client-generator.js +160 -54
- package/dist/generator/client-generator.js.map +1 -1
- package/dist/generator/custom-api-generator.d.ts +1 -1
- package/dist/generator/custom-api-generator.d.ts.map +1 -1
- package/dist/generator/custom-api-generator.js +29 -5
- package/dist/generator/custom-api-generator.js.map +1 -1
- package/dist/generator/index-generator.d.ts.map +1 -1
- package/dist/generator/index-generator.js +0 -1
- package/dist/generator/index-generator.js.map +1 -1
- package/dist/generator/index.d.ts +8 -0
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +50 -0
- package/dist/generator/index.js.map +1 -1
- package/dist/generator/plugin-api-generator.d.ts +2 -0
- package/dist/generator/plugin-api-generator.d.ts.map +1 -1
- package/dist/generator/plugin-api-generator.js +23 -1
- package/dist/generator/plugin-api-generator.js.map +1 -1
- package/dist/generator/plugin-registry.d.ts +5 -0
- package/dist/generator/plugin-registry.d.ts.map +1 -1
- package/dist/generator/plugin-registry.js +2 -1
- package/dist/generator/plugin-registry.js.map +1 -1
- package/dist/generator/types-generator.d.ts +13 -3
- package/dist/generator/types-generator.d.ts.map +1 -1
- package/dist/generator/types-generator.js +91 -101
- package/dist/generator/types-generator.js.map +1 -1
- package/dist/next/index.d.ts +8 -1
- package/dist/next/index.d.ts.map +1 -1
- package/dist/next/index.js +42 -45
- package/dist/next/index.js.map +1 -1
- package/dist/schema-types.d.ts +1 -1
- package/dist/schema-types.d.ts.map +1 -1
- package/dist/shared/client-header.d.ts +19 -0
- package/dist/shared/client-header.d.ts.map +1 -0
- package/dist/shared/client-header.js +58 -0
- package/dist/shared/client-header.js.map +1 -0
- package/package.json +9 -14
- package/dist/index.d.ts +0 -102
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -79
- package/dist/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ Generate into your source tree and commit the result:
|
|
|
31
31
|
npx strapi-types generate --url http://localhost:1337 --output ./src/strapi
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
Committed types survive reinstalls and show up as reviewable diffs.
|
|
34
|
+
Committed types survive reinstalls and show up as reviewable diffs.
|
|
35
35
|
|
|
36
36
|
### 4. Use
|
|
37
37
|
|
|
@@ -69,7 +69,7 @@ articles[0].category.name // fully typed
|
|
|
69
69
|
## Requirements
|
|
70
70
|
|
|
71
71
|
- **Strapi v5**
|
|
72
|
-
- **Node.js >=
|
|
72
|
+
- **Node.js >= 22**
|
|
73
73
|
|
|
74
74
|
## Documentation
|
|
75
75
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Check command - verifies that local types are in sync with remote schema
|
|
3
3
|
* Returns exit code 0 if in sync, 1 if out of sync
|
|
4
4
|
*/
|
|
5
|
+
import type { Command } from 'commander';
|
|
5
6
|
export interface CheckOptions {
|
|
6
7
|
url?: string;
|
|
7
8
|
token?: string;
|
|
@@ -21,7 +22,5 @@ export declare function check(options: CheckOptions): Promise<CheckResult>;
|
|
|
21
22
|
/**
|
|
22
23
|
* CLI handler for check command
|
|
23
24
|
*/
|
|
24
|
-
export declare function createCheckCommand(program:
|
|
25
|
-
command: (...args: any[]) => any;
|
|
26
|
-
}): void;
|
|
25
|
+
export declare function createCheckCommand(program: Command): void;
|
|
27
26
|
//# sourceMappingURL=check.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/check.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/check.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AASxC,MAAM,WAAW,YAAY;IACzB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,MAAM,WAAW,WAAW;IACxB,MAAM,EAAE,OAAO,CAAA;IACf,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,KAAK,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;GAEG;AACH,wBAAsB,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CA6EvE;AASD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA2CzD"}
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
* Returns exit code 0 if in sync, 1 if out of sync
|
|
4
4
|
*/
|
|
5
5
|
import { createApiClient } from '../utils/api-client.js';
|
|
6
|
-
import { readLocalSchemaHash, readLocalGeneratorVersion,
|
|
6
|
+
import { readLocalSchemaHash, readLocalGeneratorVersion, requireOutputDir, } from '../utils/file-writer.js';
|
|
7
7
|
import { getGeneratorVersion } from '../../shared/version.js';
|
|
8
8
|
/**
|
|
9
9
|
* Check if local types are in sync with remote schema
|
|
10
10
|
*/
|
|
11
11
|
export async function check(options) {
|
|
12
|
-
const outputDir = options.output || getDefaultOutputDir();
|
|
13
12
|
try {
|
|
13
|
+
const outputDir = requireOutputDir(options.output);
|
|
14
14
|
// Read local hash
|
|
15
15
|
const localHash = readLocalSchemaHash(outputDir);
|
|
16
16
|
if (!localHash) {
|
|
@@ -80,7 +80,7 @@ export function createCheckCommand(program) {
|
|
|
80
80
|
.description('Check if local types are in sync with remote Strapi schema')
|
|
81
81
|
.option('-u, --url <url>', 'Strapi API URL (default: STRAPI_URL env or http://localhost:1337)')
|
|
82
82
|
.option('-t, --token <token>', 'Strapi API token (default: STRAPI_TOKEN env)')
|
|
83
|
-
.option('-o, --output <path>', 'Output directory to check (
|
|
83
|
+
.option('-o, --output <path>', 'Output directory to check (required) — where you generated, e.g. ./src/strapi')
|
|
84
84
|
.option('-s, --silent', 'Suppress output messages')
|
|
85
85
|
.action(async (opts) => {
|
|
86
86
|
const result = await check({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../../src/cli/commands/check.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../../src/cli/commands/check.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EACH,mBAAmB,EACnB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M,KAAK,CAAC;YACvB,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,MAAM,EAAE,IAAI,CAAC,MAAM;SACtB,CAAC,CAAA;QAEF,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;YAC5C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACnB,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YACjB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;gBACf,OAAO,CAAC,GAAG,CACP,gDAAgD,CACnD,CAAA;YACL,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACnB,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACnB,CAAC,CAAC,CAAA;AACV,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generate command - generates TypeScript types from Strapi schema
|
|
3
3
|
*/
|
|
4
|
+
import type { Command } from 'commander';
|
|
4
5
|
export interface GenerateOptions {
|
|
5
6
|
url?: string;
|
|
6
7
|
token?: string;
|
|
@@ -36,7 +37,5 @@ export declare function generate(options: GenerateOptions): Promise<GenerateResu
|
|
|
36
37
|
/**
|
|
37
38
|
* CLI handler for generate command
|
|
38
39
|
*/
|
|
39
|
-
export declare function createGenerateCommand(program:
|
|
40
|
-
command: (...args: any[]) => any;
|
|
41
|
-
}): void;
|
|
40
|
+
export declare function createGenerateCommand(program: Command): void;
|
|
42
41
|
//# sourceMappingURL=generate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/generate.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/generate.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAWxC,MAAM,WAAW,eAAe;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,MAAM,CAAC,EAAE,IAAI,GAAG,IAAI,CAAA;CACvB;AA+BD,MAAM,WAAW,cAAc;IAC3B,OAAO,EAAE,OAAO,CAAA;IAChB,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,OAAO,CAAA;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE;IAC3C,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,OAAO,CAAA;CACzB,GAAG,OAAO,CAOV;AAED;;GAEG;AACH,wBAAsB,QAAQ,CAC1B,OAAO,EAAE,eAAe,GACzB,OAAO,CAAC,cAAc,CAAC,CAgLzB;AAWD;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAsD5D"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import * as fs from 'fs';
|
|
5
5
|
import * as path from 'path';
|
|
6
6
|
import { createApiClient } from '../utils/api-client.js';
|
|
7
|
-
import { readLocalSchemaHash, readLocalGeneratorVersion,
|
|
7
|
+
import { readLocalSchemaHash, readLocalGeneratorVersion, requireOutputDir, } from '../utils/file-writer.js';
|
|
8
8
|
import { Generator } from '../../generator/index.js';
|
|
9
9
|
import { transformSchema } from '../../core/schema-transformer.js';
|
|
10
10
|
import { getGeneratorVersion } from '../../shared/version.js';
|
|
@@ -50,10 +50,10 @@ export function isGeneratedOutputFresh(params) {
|
|
|
50
50
|
* Generate types from Strapi API
|
|
51
51
|
*/
|
|
52
52
|
export async function generate(options) {
|
|
53
|
-
const outputDir = options.output || getDefaultOutputDir();
|
|
54
53
|
const format = options.format ?? 'js';
|
|
55
54
|
const filesWritten = [];
|
|
56
55
|
try {
|
|
56
|
+
const outputDir = requireOutputDir(options.output);
|
|
57
57
|
assertOutputDirForFormat(outputDir, format);
|
|
58
58
|
// Create API client
|
|
59
59
|
const client = createApiClient({
|
|
@@ -183,7 +183,7 @@ export function createGenerateCommand(program) {
|
|
|
183
183
|
.description('Generate TypeScript types from Strapi schema')
|
|
184
184
|
.option('-u, --url <url>', 'Strapi API URL (default: STRAPI_URL env or http://localhost:1337)')
|
|
185
185
|
.option('-t, --token <token>', 'Strapi API token (default: STRAPI_TOKEN env)')
|
|
186
|
-
.option('-o, --output <path>', 'Output directory (
|
|
186
|
+
.option('-o, --output <path>', 'Output directory (required) — your source tree, e.g. ./src/strapi')
|
|
187
187
|
.option('-s, --silent', 'Suppress output messages')
|
|
188
188
|
.option('-f, --force', 'Force regeneration even if schema unchanged')
|
|
189
189
|
.option('--format <js|ts>', 'Output format: js (compiled .js + .d.ts, default) or ts (raw .ts for monorepo/source-tree output)', 'js')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/cli/commands/generate.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/cli/commands/generate.ts"],"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,CACP,gBAAgB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CACnD,CAAA;YACL,CAAC;QACL,CAAC;IACL,CAAC,CAAC,CAAA;AACV,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Watch command - connects to SSE stream and regenerates types on schema changes
|
|
3
3
|
*/
|
|
4
|
+
import type { Command } from 'commander';
|
|
4
5
|
export interface WatchOptions {
|
|
5
6
|
url?: string;
|
|
6
7
|
token?: string;
|
|
@@ -14,7 +15,5 @@ export declare function watch(options: WatchOptions): Promise<void>;
|
|
|
14
15
|
/**
|
|
15
16
|
* CLI handler for watch command
|
|
16
17
|
*/
|
|
17
|
-
export declare function createWatchCommand(program:
|
|
18
|
-
command: (...args: any[]) => any;
|
|
19
|
-
}): void;
|
|
18
|
+
export declare function createWatchCommand(program: Command): void;
|
|
20
19
|
//# sourceMappingURL=watch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/watch.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/watch.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAKxC,MAAM,WAAW,YAAY;IACzB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,OAAO,CAAA;CACnB;AAED;;GAEG;AACH,wBAAsB,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAkGhE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAgCzD"}
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
* Watch command - connects to SSE stream and regenerates types on schema changes
|
|
3
3
|
*/
|
|
4
4
|
import { createApiClient } from '../utils/api-client.js';
|
|
5
|
-
import { readLocalSchemaHash,
|
|
5
|
+
import { readLocalSchemaHash, requireOutputDir } from '../utils/file-writer.js';
|
|
6
6
|
import { SseConnection } from '../../shared/sse-client.js';
|
|
7
7
|
import { generate } from './generate.js';
|
|
8
8
|
/**
|
|
9
9
|
* Watch for schema changes via SSE
|
|
10
10
|
*/
|
|
11
11
|
export async function watch(options) {
|
|
12
|
-
const outputDir = options.output
|
|
12
|
+
const outputDir = requireOutputDir(options.output);
|
|
13
13
|
const client = createApiClient({
|
|
14
14
|
url: options.url,
|
|
15
15
|
token: options.token,
|
|
@@ -97,15 +97,21 @@ export function createWatchCommand(program) {
|
|
|
97
97
|
.description('Watch for schema changes and regenerate types automatically')
|
|
98
98
|
.option('-u, --url <url>', 'Strapi API URL (default: STRAPI_URL env or http://localhost:1337)')
|
|
99
99
|
.option('-t, --token <token>', 'Strapi API token (default: STRAPI_TOKEN env)')
|
|
100
|
-
.option('-o, --output <path>', 'Output directory (
|
|
100
|
+
.option('-o, --output <path>', 'Output directory (required) — your source tree, e.g. ./src/strapi')
|
|
101
101
|
.option('-s, --silent', 'Suppress regeneration messages')
|
|
102
102
|
.action(async (opts) => {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
try {
|
|
104
|
+
await watch({
|
|
105
|
+
url: opts.url,
|
|
106
|
+
token: opts.token,
|
|
107
|
+
output: opts.output,
|
|
108
|
+
silent: opts.silent,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
console.error(err.message);
|
|
113
|
+
process.exit(1);
|
|
114
|
+
}
|
|
109
115
|
});
|
|
110
116
|
}
|
|
111
117
|
//# sourceMappingURL=watch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watch.js","sourceRoot":"","sources":["../../../src/cli/commands/watch.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"watch.js","sourceRoot":"","sources":["../../../src/cli/commands/watch.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAExD,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AASxC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,OAAqB;IAC7C,MAAM,SAAS,GAAG,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IAElD,MAAM,MAAM,GAAG,eAAe,CAAC;QAC3B,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,KAAK,EAAE,OAAO,CAAC,KAAK;KACvB,CAAC,CAAA;IAEF,+BAA+B;IAC/B,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;IACvC,IAAI,CAAC,WAAW,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CACT,+BAA+B,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,uBAAuB,EAAE,CACpG,CAAA;QACD,OAAO,CAAC,KAAK,CACT,gFAAgF,CACnF,CAAA;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACnB,CAAC;IAED,uCAAuC;IACvC,MAAM,WAAW,GAAG,mBAAmB,CAAC,SAAS,CAAC,CAAA;IAClD,IAAI,CAAC,WAAW,EAAE,CAAC;QACf,OAAO,CAAC,GAAG,CAAC,sDAAsD,CAAC,CAAA;QACnE,MAAM,QAAQ,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,MAAM,CACH,iBAAiB,EACjB,mEAAmE,CACtE;SACA,MAAM,CACH,qBAAqB,EACrB,8CAA8C,CACjD;SACA,MAAM,CACH,qBAAqB,EACrB,mEAAmE,CACtE;SACA,MAAM,CAAC,cAAc,EAAE,gCAAgC,CAAC;SACxD,MAAM,CAAC,KAAK,EAAE,IAAkB,EAAE,EAAE;QACjC,IAAI,CAAC;YACD,MAAM,KAAK,CAAC;gBACR,GAAG,EAAE,IAAI,CAAC,GAAG;gBACb,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,MAAM,EAAE,IAAI,CAAC,MAAM;aACtB,CAAC,CAAA;QACN,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAE,GAAa,CAAC,OAAO,CAAC,CAAA;YACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACnB,CAAC;IACL,CAAC,CAAC,CAAA;AACV,CAAC"}
|
|
@@ -30,15 +30,16 @@ export declare function writeFiles(files: Array<{
|
|
|
30
30
|
content: string;
|
|
31
31
|
}>): WriteResult[];
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
33
|
+
* Require an explicit output directory. The generated client is meant to be
|
|
34
|
+
* written into your source tree and committed — there is no implicit
|
|
35
|
+
* node_modules default (a reinstall would wipe it). Throws an actionable error
|
|
36
|
+
* when no output was given, so both the CLI and programmatic callers fail loudly
|
|
37
|
+
* instead of silently writing somewhere unexpected.
|
|
35
38
|
*/
|
|
36
|
-
export declare function
|
|
39
|
+
export declare function requireOutputDir(output: string | undefined): string;
|
|
37
40
|
/**
|
|
38
|
-
* Read schema hash from the generated client.
|
|
39
|
-
*
|
|
40
|
-
* client at generation time as the first export — reading the file head is
|
|
41
|
-
* enough and avoids parsing the full client.
|
|
41
|
+
* Read schema hash from the generated client. SCHEMA_HASH is baked into the
|
|
42
|
+
* client at generation time as the first export.
|
|
42
43
|
*/
|
|
43
44
|
export declare function readLocalSchemaHash(outputDir: string): string | null;
|
|
44
45
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-writer.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/file-writer.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,MAAM,WAAW,WAAW;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,CAAC,EAAE,KAAK,CAAA;CAChB;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAI/C;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,WAAW,CASxE;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAMxD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;GAEG;AACH,wBAAgB,UAAU,CACtB,KAAK,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,GAChD,WAAW,EAAE,CAgBf;AAED
|
|
1
|
+
{"version":3,"file":"file-writer.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/file-writer.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,MAAM,WAAW,WAAW;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,CAAC,EAAE,KAAK,CAAA;CAChB;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAI/C;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,WAAW,CASxE;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAMxD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;GAEG;AACH,wBAAgB,UAAU,CACtB,KAAK,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,GAChD,WAAW,EAAE,CAgBf;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAUnE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAEpE;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAE1E"}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* File writer utilities for CLI output
|
|
3
3
|
*/
|
|
4
4
|
import * as fs from 'fs';
|
|
5
|
-
import { createRequire } from 'module';
|
|
6
5
|
import * as path from 'path';
|
|
6
|
+
import { readClientHeaderConst } from '../../shared/client-header.js';
|
|
7
7
|
/**
|
|
8
8
|
* Ensure directory exists
|
|
9
9
|
*/
|
|
@@ -58,54 +58,27 @@ export function writeFiles(files) {
|
|
|
58
58
|
return results;
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
61
|
+
* Require an explicit output directory. The generated client is meant to be
|
|
62
|
+
* written into your source tree and committed — there is no implicit
|
|
63
|
+
* node_modules default (a reinstall would wipe it). Throws an actionable error
|
|
64
|
+
* when no output was given, so both the CLI and programmatic callers fail loudly
|
|
65
|
+
* instead of silently writing somewhere unexpected.
|
|
63
66
|
*/
|
|
64
|
-
export function
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
catch {
|
|
71
|
-
return './dist';
|
|
67
|
+
export function requireOutputDir(output) {
|
|
68
|
+
if (!output || !output.trim()) {
|
|
69
|
+
throw new Error('No output directory specified.\n' +
|
|
70
|
+
'Pass --output pointing at your source tree, e.g.:\n' +
|
|
71
|
+
' strapi-types generate --output ./src/strapi --format ts\n' +
|
|
72
|
+
'Generated code is meant to be committed to your repo, not written into node_modules.');
|
|
72
73
|
}
|
|
74
|
+
return output.trim();
|
|
73
75
|
}
|
|
74
|
-
const HEADER_HEAD_BYTES = 512;
|
|
75
76
|
/**
|
|
76
|
-
* Read
|
|
77
|
-
*
|
|
78
|
-
*/
|
|
79
|
-
function readFileHead(filePath, bytes) {
|
|
80
|
-
let fd;
|
|
81
|
-
try {
|
|
82
|
-
fd = fs.openSync(filePath, 'r');
|
|
83
|
-
const buf = Buffer.alloc(bytes);
|
|
84
|
-
const read = fs.readSync(fd, buf, 0, bytes, 0);
|
|
85
|
-
return buf.slice(0, read).toString('utf-8');
|
|
86
|
-
}
|
|
87
|
-
catch {
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
finally {
|
|
91
|
-
if (fd !== undefined) {
|
|
92
|
-
try {
|
|
93
|
-
fs.closeSync(fd);
|
|
94
|
-
}
|
|
95
|
-
catch {
|
|
96
|
-
/* ignore */
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Read schema hash from the generated client. Tries client.ts (raw, .ts mode)
|
|
103
|
-
* first, then client.js (compiled, .js mode). SCHEMA_HASH is baked into the
|
|
104
|
-
* client at generation time as the first export — reading the file head is
|
|
105
|
-
* enough and avoids parsing the full client.
|
|
77
|
+
* Read schema hash from the generated client. SCHEMA_HASH is baked into the
|
|
78
|
+
* client at generation time as the first export.
|
|
106
79
|
*/
|
|
107
80
|
export function readLocalSchemaHash(outputDir) {
|
|
108
|
-
return
|
|
81
|
+
return readClientHeaderConst(outputDir, 'SCHEMA_HASH');
|
|
109
82
|
}
|
|
110
83
|
/**
|
|
111
84
|
* Read the GENERATOR_VERSION baked into the generated client at generation
|
|
@@ -114,23 +87,6 @@ export function readLocalSchemaHash(outputDir) {
|
|
|
114
87
|
* clients generated before version stamping was introduced).
|
|
115
88
|
*/
|
|
116
89
|
export function readLocalGeneratorVersion(outputDir) {
|
|
117
|
-
return
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Read a `export const <NAME> = '<value>'` baked into the generated client
|
|
121
|
-
* header. Both SCHEMA_HASH and GENERATOR_VERSION live in the first bytes of
|
|
122
|
-
* client.ts/client.js, so reading the head is enough.
|
|
123
|
-
*/
|
|
124
|
-
function readLocalHeaderConst(outputDir, name) {
|
|
125
|
-
const re = new RegExp(`${name}\\s*=\\s*['"]([^'"]*)['"]`);
|
|
126
|
-
for (const file of ['client.ts', 'client.js']) {
|
|
127
|
-
const head = readFileHead(path.join(outputDir, file), HEADER_HEAD_BYTES);
|
|
128
|
-
if (!head)
|
|
129
|
-
continue;
|
|
130
|
-
const match = head.match(re);
|
|
131
|
-
if (match)
|
|
132
|
-
return match[1];
|
|
133
|
-
}
|
|
134
|
-
return null;
|
|
90
|
+
return readClientHeaderConst(outputDir, 'GENERATOR_VERSION');
|
|
135
91
|
}
|
|
136
92
|
//# sourceMappingURL=file-writer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-writer.js","sourceRoot":"","sources":["../../../src/cli/utils/file-writer.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,
|
|
1
|
+
{"version":3,"file":"file-writer.js","sourceRoot":"","sources":["../../../src/cli/utils/file-writer.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,EAAE,qBAAqB,EAAE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EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;QACjD,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAEpB,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YAClB,OAAO,CAAC,KAAK,CACT,mBAAmB,IAAI,CAAC,IAAI,GAAG,EAC/B,MAAM,CAAC,KAAK,EAAE,OAAO,CACxB,CAAA;QACL,CAAC;IACL,CAAC;IAED,OAAO,OAAO,CAAA;AAClB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAA0B;IACvD,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CACX,kCAAkC;YAC9B,qDAAqD;YACrD,6DAA6D;YAC7D,sFAAsF,CAC7F,CAAA;IACL,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,EAAE,CAAA;AACxB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,SAAiB;IACjD,OAAO,qBAAqB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAA;AAC1D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CAAC,SAAiB;IACvD,OAAO,qBAAqB,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAA;AAChE,CAAC"}
|
|
@@ -21,6 +21,10 @@ export declare function convertEndpointsToRoutes(endpoints: ParsedEndpoint[]): P
|
|
|
21
21
|
*
|
|
22
22
|
* Extracts inline type definitions from endpoint types (body/response)
|
|
23
23
|
* and creates handler-to-type mappings.
|
|
24
|
+
*
|
|
25
|
+
* `knownTypeNames` is the set of type names the generated client defines
|
|
26
|
+
* (content-type + component cleanNames, MediaFile, extra controller types) so
|
|
27
|
+
* the sanitizer can tell a resolvable reference from a dangling one.
|
|
24
28
|
*/
|
|
25
|
-
export declare function convertEndpointsToCustomTypes(endpoints: ParsedEndpoint[], extraTypes?: ExtraControllerType[]): ParsedCustomTypes;
|
|
29
|
+
export declare function convertEndpointsToCustomTypes(endpoints: ParsedEndpoint[], extraTypes?: ExtraControllerType[], knownTypeNames?: Set<string>): ParsedCustomTypes;
|
|
26
30
|
//# sourceMappingURL=endpoint-converter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoint-converter.d.ts","sourceRoot":"","sources":["../../src/core/endpoint-converter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACR,cAAc,EACd,mBAAmB,EACtB,MAAM,6BAA6B,CAAA;AACpC,OAAO,KAAK,EAAe,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACzE,OAAO,KAAK,EACR,iBAAiB,EAEpB,MAAM,2BAA2B,CAAA;AAMlC;;GAEG;AACH,wBAAgB,wBAAwB,CACpC,SAAS,EAAE,cAAc,EAAE,GAC5B,YAAY,CAyBd;
|
|
1
|
+
{"version":3,"file":"endpoint-converter.d.ts","sourceRoot":"","sources":["../../src/core/endpoint-converter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACR,cAAc,EACd,mBAAmB,EACtB,MAAM,6BAA6B,CAAA;AACpC,OAAO,KAAK,EAAe,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACzE,OAAO,KAAK,EACR,iBAAiB,EAEpB,MAAM,2BAA2B,CAAA;AAMlC;;GAEG;AACH,wBAAgB,wBAAwB,CACpC,SAAS,EAAE,cAAc,EAAE,GAC5B,YAAY,CAyBd;AAoFD;;;;;;;;;GASG;AACH,wBAAgB,6BAA6B,CACzC,SAAS,EAAE,cAAc,EAAE,EAC3B,UAAU,CAAC,EAAE,mBAAmB,EAAE,EAClC,cAAc,GAAE,GAAG,CAAC,MAAM,CAAa,GACxC,iBAAiB,CA4InB"}
|
|
@@ -35,13 +35,90 @@ export function convertEndpointsToRoutes(endpoints) {
|
|
|
35
35
|
}
|
|
36
36
|
return { byController, all };
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* TS built-in / global type names that are always valid in a type expression
|
|
40
|
+
* and must never be treated as unresolved. Primitives (string, number, …) are
|
|
41
|
+
* lowercase so they aren't matched by the capitalised-identifier scan.
|
|
42
|
+
*/
|
|
43
|
+
const TS_BUILTIN_TYPES = new Set([
|
|
44
|
+
'Array',
|
|
45
|
+
'ReadonlyArray',
|
|
46
|
+
'Record',
|
|
47
|
+
'Partial',
|
|
48
|
+
'Required',
|
|
49
|
+
'Readonly',
|
|
50
|
+
'Pick',
|
|
51
|
+
'Omit',
|
|
52
|
+
'Exclude',
|
|
53
|
+
'Extract',
|
|
54
|
+
'NonNullable',
|
|
55
|
+
'Parameters',
|
|
56
|
+
'ReturnType',
|
|
57
|
+
'InstanceType',
|
|
58
|
+
'Awaited',
|
|
59
|
+
'Promise',
|
|
60
|
+
'Map',
|
|
61
|
+
'Set',
|
|
62
|
+
'WeakMap',
|
|
63
|
+
'WeakSet',
|
|
64
|
+
'Date',
|
|
65
|
+
'RegExp',
|
|
66
|
+
'Error',
|
|
67
|
+
'Object',
|
|
68
|
+
'String',
|
|
69
|
+
'Number',
|
|
70
|
+
'Boolean',
|
|
71
|
+
'Function',
|
|
72
|
+
'Symbol',
|
|
73
|
+
'BigInt',
|
|
74
|
+
'Uint8Array',
|
|
75
|
+
'ArrayBuffer',
|
|
76
|
+
'Blob',
|
|
77
|
+
'File',
|
|
78
|
+
'FormData',
|
|
79
|
+
]);
|
|
80
|
+
/**
|
|
81
|
+
* Custom-endpoint type strings are scraped verbatim from controller source, so
|
|
82
|
+
* they can reference named types that only exist in the controller's module
|
|
83
|
+
* (imported, never shipped) — emitting those would produce `Cannot find name`
|
|
84
|
+
* errors. Replace any capitalised identifier that isn't a TS built-in or a
|
|
85
|
+
* known generated/local type with `unknown` so the client always compiles.
|
|
86
|
+
* Full cross-module resolution is deferred to the ts-morph Endpoints parser.
|
|
87
|
+
*
|
|
88
|
+
* Heuristic and deliberately conservative: string literals are masked so names
|
|
89
|
+
* inside them are left alone, and identifiers in object-key position (followed
|
|
90
|
+
* by `:`) are treated as keys, not type references. Collects the names it
|
|
91
|
+
* dropped into `unresolved`.
|
|
92
|
+
*/
|
|
93
|
+
function sanitizeTypeRefs(typeStr, known, unresolved) {
|
|
94
|
+
// Mask string literals ('...' / "...") so identifiers inside them survive.
|
|
95
|
+
const literals = [];
|
|
96
|
+
const masked = typeStr.replace(/'[^']*'|"[^"]*"/g, m => {
|
|
97
|
+
literals.push(m);
|
|
98
|
+
return `${literals.length - 1}`;
|
|
99
|
+
});
|
|
100
|
+
const scanned = masked.replace(/\b[A-Z][A-Za-z0-9_]*\b/g, (name, offset, full) => {
|
|
101
|
+
// Skip object keys / labels: identifier immediately followed by `:`.
|
|
102
|
+
if (/^\s*:/.test(full.slice(offset + name.length)))
|
|
103
|
+
return name;
|
|
104
|
+
if (TS_BUILTIN_TYPES.has(name) || known.has(name))
|
|
105
|
+
return name;
|
|
106
|
+
unresolved.add(name);
|
|
107
|
+
return 'unknown';
|
|
108
|
+
});
|
|
109
|
+
return scanned.replace(/(\d+)/g, (_, i) => literals[Number(i)]);
|
|
110
|
+
}
|
|
38
111
|
/**
|
|
39
112
|
* Convert ParsedEndpoint[] to ParsedCustomTypes format
|
|
40
113
|
*
|
|
41
114
|
* Extracts inline type definitions from endpoint types (body/response)
|
|
42
115
|
* and creates handler-to-type mappings.
|
|
116
|
+
*
|
|
117
|
+
* `knownTypeNames` is the set of type names the generated client defines
|
|
118
|
+
* (content-type + component cleanNames, MediaFile, extra controller types) so
|
|
119
|
+
* the sanitizer can tell a resolvable reference from a dangling one.
|
|
43
120
|
*/
|
|
44
|
-
export function convertEndpointsToCustomTypes(endpoints, extraTypes) {
|
|
121
|
+
export function convertEndpointsToCustomTypes(endpoints, extraTypes, knownTypeNames = new Set()) {
|
|
45
122
|
const types = new Map();
|
|
46
123
|
const typeDefinitions = [];
|
|
47
124
|
const namespaceImports = [];
|
|
@@ -78,15 +155,36 @@ export function convertEndpointsToCustomTypes(endpoints, extraTypes) {
|
|
|
78
155
|
const namespaceName = toPascalCasePreserve(controller) + 'API';
|
|
79
156
|
const namespaceLines = [];
|
|
80
157
|
namespaceLines.push(`export namespace ${namespaceName} {`);
|
|
81
|
-
// Add extra (standalone) types first
|
|
82
158
|
const controllerExtraTypes = extraByController.get(controller);
|
|
159
|
+
const controllerEndpoints = byController.get(controller);
|
|
160
|
+
// Names this namespace itself defines — added to the known set so a
|
|
161
|
+
// reference to a sibling type in the same namespace isn't mistaken for
|
|
162
|
+
// an unresolved one by the sanitizer.
|
|
163
|
+
const ownNames = new Set();
|
|
164
|
+
if (controllerExtraTypes) {
|
|
165
|
+
for (const extra of controllerExtraTypes)
|
|
166
|
+
ownNames.add(extra.typeName);
|
|
167
|
+
}
|
|
168
|
+
if (controllerEndpoints) {
|
|
169
|
+
for (const endpoint of controllerEndpoints) {
|
|
170
|
+
if (!endpoint.types)
|
|
171
|
+
continue;
|
|
172
|
+
const ap = toPascalCasePreserve(endpoint.action);
|
|
173
|
+
if (endpoint.types.body)
|
|
174
|
+
ownNames.add(`${ap}Request`);
|
|
175
|
+
if (endpoint.types.response)
|
|
176
|
+
ownNames.add(`${ap}Response`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const nsKnown = new Set([...knownTypeNames, ...ownNames]);
|
|
180
|
+
const unresolved = new Set();
|
|
181
|
+
// Add extra (standalone) types first
|
|
83
182
|
if (controllerExtraTypes) {
|
|
84
183
|
for (const extra of controllerExtraTypes) {
|
|
85
|
-
namespaceLines.push(` export type ${extra.typeName} = ${extra.typeDefinition}`);
|
|
184
|
+
namespaceLines.push(` export type ${extra.typeName} = ${sanitizeTypeRefs(extra.typeDefinition, nsKnown, unresolved)}`);
|
|
86
185
|
}
|
|
87
186
|
}
|
|
88
187
|
// Add endpoint-derived types
|
|
89
|
-
const controllerEndpoints = byController.get(controller);
|
|
90
188
|
if (controllerEndpoints) {
|
|
91
189
|
for (const endpoint of controllerEndpoints) {
|
|
92
190
|
if (!endpoint.types)
|
|
@@ -95,7 +193,7 @@ export function convertEndpointsToCustomTypes(endpoints, extraTypes) {
|
|
|
95
193
|
// Generate Request type from body
|
|
96
194
|
if (endpoint.types.body) {
|
|
97
195
|
const typeName = `${actionPascal}Request`;
|
|
98
|
-
namespaceLines.push(` export type ${typeName} = ${endpoint.types.body}`);
|
|
196
|
+
namespaceLines.push(` export type ${typeName} = ${sanitizeTypeRefs(endpoint.types.body, nsKnown, unresolved)}`);
|
|
99
197
|
// Map handler to input type
|
|
100
198
|
const existing = types.get(endpoint.handler) || {
|
|
101
199
|
handler: endpoint.handler,
|
|
@@ -108,7 +206,7 @@ export function convertEndpointsToCustomTypes(endpoints, extraTypes) {
|
|
|
108
206
|
const typeName = `${actionPascal}Response`;
|
|
109
207
|
// Unwrap { data: ... } wrapper — StrapiClient already does response.data
|
|
110
208
|
const unwrappedResponse = unwrapDataWrapper(endpoint.types.response);
|
|
111
|
-
namespaceLines.push(` export type ${typeName} = ${unwrappedResponse}`);
|
|
209
|
+
namespaceLines.push(` export type ${typeName} = ${sanitizeTypeRefs(unwrappedResponse, nsKnown, unresolved)}`);
|
|
112
210
|
// Map handler to output type
|
|
113
211
|
const existing = types.get(endpoint.handler) || {
|
|
114
212
|
handler: endpoint.handler,
|
|
@@ -118,9 +216,17 @@ export function convertEndpointsToCustomTypes(endpoints, extraTypes) {
|
|
|
118
216
|
}
|
|
119
217
|
}
|
|
120
218
|
}
|
|
219
|
+
// If any referenced name couldn't be resolved we degraded it to
|
|
220
|
+
// `unknown` — leave a discoverable note in the committed output. Full
|
|
221
|
+
// cross-module resolution is deferred to the ts-morph Endpoints parser.
|
|
222
|
+
if (unresolved.size > 0) {
|
|
223
|
+
namespaceLines.splice(1, 0, ` // NOTE: ${[...unresolved].sort().join(', ')} could not be resolved from the schema and fall back to \`unknown\` (custom-endpoint types referencing controller-local types).`);
|
|
224
|
+
}
|
|
121
225
|
namespaceLines.push('}');
|
|
122
|
-
// Only add namespace if it has content
|
|
123
|
-
|
|
226
|
+
// Only add namespace if it has real content (open + close, plus an
|
|
227
|
+
// optional NOTE, is empty).
|
|
228
|
+
const minLines = unresolved.size > 0 ? 3 : 2;
|
|
229
|
+
if (namespaceLines.length > minLines) {
|
|
124
230
|
typeDefinitions.push(namespaceLines.join('\n'));
|
|
125
231
|
namespaceImports.push(namespaceName);
|
|
126
232
|
}
|