@blimu/codegen 0.1.0 → 0.2.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 +0 -1
- package/dist/generator/typescript/templates/.prettierrc.hbs +8 -0
- package/dist/generator/typescript/templates/README.md.hbs +10 -7
- package/dist/generator/typescript/templates/client.ts.hbs +108 -332
- package/dist/generator/typescript/templates/index.ts.hbs +4 -2
- package/dist/generator/typescript/templates/package.json.hbs +18 -9
- package/dist/generator/typescript/templates/schema.ts.hbs +51 -27
- package/dist/generator/typescript/templates/schema.zod.ts.hbs +22 -6
- package/dist/generator/typescript/templates/service.ts.hbs +8 -34
- package/dist/generator/typescript/templates/tsconfig.json.hbs +1 -2
- package/dist/generator/typescript/templates/utils.ts.hbs +4 -136
- package/dist/index.d.mts +37 -25
- package/dist/index.d.ts +37 -25
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -4
- package/dist/index.mjs.map +1 -1
- package/dist/main.js +4 -4
- package/dist/main.js.map +1 -1
- package/package.json +8 -6
|
@@ -1,51 +1,75 @@
|
|
|
1
1
|
// Generated types from OpenAPI components.schemas
|
|
2
2
|
|
|
3
|
+
{{! Generate import statements for predefined types actually used in this schema file }}
|
|
4
|
+
{{#if (getSchemaPredefinedTypes)}}
|
|
5
|
+
{{#each (groupByPackage (getSchemaPredefinedTypes))}}
|
|
6
|
+
import type { {{joinTypes this.types}} } from '{{this.package}}';
|
|
7
|
+
{{/each}}
|
|
8
|
+
{{/if}}
|
|
9
|
+
|
|
3
10
|
export type Enum<T> = T[keyof T];
|
|
4
11
|
|
|
5
|
-
{{
|
|
6
|
-
{{
|
|
7
|
-
{{
|
|
8
|
-
{{
|
|
12
|
+
{{! Enums: const objects + union types }}
|
|
13
|
+
{{#if (gt (len IR.modelDefs) 0)}}
|
|
14
|
+
{{#each IR.modelDefs}}
|
|
15
|
+
{{#if (eq this.schema.kind "enum")}}
|
|
9
16
|
export const {{this.name}} = {
|
|
10
|
-
{{
|
|
17
|
+
{{#each this.schema.enumValues as |v|}}
|
|
11
18
|
"{{v}}": {{#if (or (eq v "true") (eq v "false"))}}{{v}}{{else if (reMatch "^-?[0-9]+(\\.[0-9]+)?$" v)}}{{v}}{{else}}"{{v}}"{{/if}},
|
|
12
|
-
{{
|
|
19
|
+
{{/each}}
|
|
13
20
|
} as const;
|
|
14
21
|
|
|
15
22
|
export type {{this.name}} = Enum<typeof {{this.name}}>;
|
|
16
23
|
|
|
17
|
-
{{
|
|
18
|
-
{{
|
|
24
|
+
{{/if}}
|
|
25
|
+
{{/each}}
|
|
19
26
|
|
|
20
|
-
{{
|
|
21
|
-
{{
|
|
22
|
-
|
|
27
|
+
{{! Simple types: generate as regular type exports (not in namespace) }}
|
|
28
|
+
{{! Skip predefined types - they are imported instead }}
|
|
29
|
+
{{#each IR.modelDefs}}
|
|
30
|
+
{{#if (or (eq this.schema.kind "string") (eq this.schema.kind "number") (eq this.schema.kind "integer") (eq this.schema.kind "boolean") (eq this.schema.kind "null"))}}
|
|
31
|
+
{{#unless (isPredefinedType this.name)}}
|
|
32
|
+
{{#if this.annotations.description}}
|
|
23
33
|
/**
|
|
24
34
|
* {{decodeHtml (replace this.annotations.description "*/" "*\\/")}}
|
|
25
35
|
*/
|
|
26
|
-
{{
|
|
27
|
-
{{
|
|
36
|
+
{{/if}}
|
|
37
|
+
export type {{this.name}} = {{tsTypeStripNs this.schema}};
|
|
38
|
+
{{/unless}}
|
|
39
|
+
{{/if}}
|
|
40
|
+
{{/each}}
|
|
41
|
+
|
|
42
|
+
{{! Objects and other named models: render interfaces/types from structured IR }}
|
|
43
|
+
{{#each IR.modelDefs}}
|
|
44
|
+
{{#unless (or (eq this.schema.kind "string") (eq this.schema.kind "number") (eq this.schema.kind "integer") (eq this.schema.kind "boolean") (eq this.schema.kind "null"))}}
|
|
45
|
+
{{#if this.annotations.description}}
|
|
46
|
+
/**
|
|
47
|
+
* {{decodeHtml (replace this.annotations.description "*/" "*\\/")}}
|
|
48
|
+
*/
|
|
49
|
+
{{/if}}
|
|
50
|
+
{{#if (eq this.schema.kind "object")}}
|
|
28
51
|
export interface {{this.name}} {
|
|
29
|
-
{{
|
|
30
|
-
{{
|
|
52
|
+
{{#each this.schema.properties}}
|
|
53
|
+
{{#if this.annotations.description}}
|
|
31
54
|
/** {{decodeHtml (replace this.annotations.description "*/" "*\\/")}} */
|
|
32
|
-
{{
|
|
55
|
+
{{/if}}
|
|
33
56
|
{{quotePropName this.name}}{{#unless this.required}}?{{/unless}}: {{tsTypeStripNs this.type}};
|
|
34
|
-
{{
|
|
57
|
+
{{/each}}
|
|
35
58
|
}
|
|
36
59
|
|
|
37
|
-
{{
|
|
60
|
+
{{else if (eq this.schema.kind "ref")}}
|
|
38
61
|
export type {{this.name}} = {{tsTypeStripNs this.schema}};
|
|
39
62
|
|
|
40
|
-
{{
|
|
63
|
+
{{else if (or (eq this.schema.kind "oneOf") (eq this.schema.kind "anyOf") (eq this.schema.kind "allOf"))}}
|
|
41
64
|
export type {{this.name}} = {{tsTypeStripNs this.schema}};
|
|
42
65
|
|
|
43
|
-
{{
|
|
66
|
+
{{else if (eq this.schema.kind "array")}}
|
|
44
67
|
export type {{this.name}} = {{tsTypeStripNs this.schema}};
|
|
45
68
|
|
|
46
|
-
{{
|
|
47
|
-
{{
|
|
48
|
-
{{
|
|
69
|
+
{{/if}}
|
|
70
|
+
{{/unless}}
|
|
71
|
+
{{/each}}
|
|
72
|
+
{{/if}}
|
|
49
73
|
|
|
50
74
|
{{#if IR.services}}
|
|
51
75
|
|
|
@@ -62,12 +86,12 @@ export type Enum<T> = T[keyof T];
|
|
|
62
86
|
{{~/if~}}
|
|
63
87
|
*/
|
|
64
88
|
export interface {{pascal ../tag}}{{pascal (methodName this)}}Query {
|
|
65
|
-
{{
|
|
66
|
-
{{
|
|
89
|
+
{{#each this.queryParams}}
|
|
90
|
+
{{#if this.description}}
|
|
67
91
|
/** {{decodeHtml (replace this.description "*/" "*\\/")}} */
|
|
68
|
-
{{
|
|
92
|
+
{{/if}}
|
|
69
93
|
{{quotePropName this.name}}{{#unless this.required}}?{{/unless}}: {{tsTypeStripNs this.schema}};
|
|
70
|
-
{{
|
|
94
|
+
{{/each}}
|
|
71
95
|
}
|
|
72
96
|
|
|
73
97
|
{{/if}}
|
|
@@ -1,11 +1,26 @@
|
|
|
1
|
-
// Generated
|
|
1
|
+
// Generated zod schemas from OpenAPI components.schemas
|
|
2
2
|
// Use these schemas for runtime validation in forms, API requests, etc.
|
|
3
3
|
|
|
4
|
-
import { z } from
|
|
5
|
-
import * as Schema from
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import * as Schema from './schema';
|
|
6
6
|
|
|
7
|
+
{{! Simple types: generate as regular Zod schema exports (not in namespace) }}
|
|
8
|
+
{{#each IR.modelDefs}}
|
|
9
|
+
{{#if (or (eq this.schema.kind "string") (eq this.schema.kind "number") (eq this.schema.kind "integer") (eq this.schema.kind "boolean") (eq this.schema.kind "null"))}}
|
|
10
|
+
/**
|
|
11
|
+
* Schema for {{this.name}}
|
|
12
|
+
{{#if this.annotations.description}}
|
|
13
|
+
* {{decodeHtml (replace this.annotations.description "*/" "*\\/")}}
|
|
14
|
+
{{/if}}
|
|
15
|
+
*/
|
|
16
|
+
export const {{this.name}}Schema = {{zodSchema this.schema}};
|
|
17
|
+
{{/if}}
|
|
18
|
+
{{/each}}
|
|
19
|
+
|
|
20
|
+
{{! Objects and other named models: render Zod schemas from structured IR }}
|
|
7
21
|
{{#if (gt (len IR.modelDefs) 0)}}
|
|
8
22
|
{{~#each IR.modelDefs}}
|
|
23
|
+
{{~#unless (or (eq this.schema.kind "string") (eq this.schema.kind "number") (eq this.schema.kind "integer") (eq this.schema.kind "boolean") (eq this.schema.kind "null"))}}
|
|
9
24
|
{{~#if (eq this.schema.kind "enum")~}}
|
|
10
25
|
/**
|
|
11
26
|
* Zod schema for {{this.name}}
|
|
@@ -74,7 +89,7 @@ export const {{this.name}}Schema = z.union([
|
|
|
74
89
|
* {{decodeHtml (replace this.annotations.description "*/" "*\\/")}}
|
|
75
90
|
{{~/if~}}
|
|
76
91
|
*/
|
|
77
|
-
export const {{this.name}}Schema = {{#each this.schema.allOf}}{{#if @first}}{{zodSchema this}}{{else}}.
|
|
92
|
+
export const {{this.name}}Schema = {{#each this.schema.allOf}}{{#if @first}}{{zodSchema this}}{{else}}.extend({{zodSchema this}}.shape){{/if}}{{/each}};
|
|
78
93
|
|
|
79
94
|
{{~else if (eq this.schema.kind "array")~}}
|
|
80
95
|
/**
|
|
@@ -95,18 +110,19 @@ export const {{this.name}}Schema = z.array({{#if this.schema.items}}{{zodSchema
|
|
|
95
110
|
export const {{this.name}}Schema = {{zodSchema this.schema}};
|
|
96
111
|
|
|
97
112
|
{{~/if~}}
|
|
113
|
+
{{~/unless~}}
|
|
98
114
|
{{~/each~}}
|
|
99
115
|
{{~/if~}}
|
|
100
116
|
|
|
101
117
|
{{#if IR.services}}
|
|
102
118
|
|
|
103
|
-
// Operation query parameter
|
|
119
|
+
// Operation query parameter schemas
|
|
104
120
|
|
|
105
121
|
{{#each IR.services}}
|
|
106
122
|
{{#each this.operations}}
|
|
107
123
|
{{#if (gt (len this.queryParams) 0)}}
|
|
108
124
|
/**
|
|
109
|
-
*
|
|
125
|
+
* Schema for query params of {{../tag}}.{{pascal (methodName this)}}
|
|
110
126
|
{{~#if this.description~}}
|
|
111
127
|
* {{decodeHtml (replace this.description "*/" "*\\/")}}
|
|
112
128
|
{{~/if~}}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { CoreClient } from "../client";
|
|
2
2
|
import * as Schema from "../schema";
|
|
3
|
+
{{! Generate import statements for predefined types used in this specific service }}
|
|
4
|
+
{{#if (getServicePredefinedTypes Service)}}
|
|
5
|
+
{{#each (groupByPackage (getServicePredefinedTypes Service))}}
|
|
6
|
+
import type { {{joinTypes this.types}} } from '{{this.package}}';
|
|
7
|
+
{{/each}}
|
|
8
|
+
{{/if}}
|
|
3
9
|
|
|
4
10
|
export class {{serviceName Service.tag}} {
|
|
5
11
|
constructor(private core: CoreClient) {}
|
|
@@ -32,23 +38,7 @@ export class {{serviceName Service.tag}} {
|
|
|
32
38
|
query,
|
|
33
39
|
{{/if}}
|
|
34
40
|
{{#if requestBody}}
|
|
35
|
-
|
|
36
|
-
headers: {
|
|
37
|
-
...(init?.headers || {}),
|
|
38
|
-
"content-type": "application/json",
|
|
39
|
-
},
|
|
40
|
-
body: JSON.stringify(body),
|
|
41
|
-
{{else if (eq requestBody.contentType "multipart/form-data")}}
|
|
42
|
-
body: (body as any),
|
|
43
|
-
{{else if (eq requestBody.contentType "application/x-www-form-urlencoded")}}
|
|
44
|
-
headers: {
|
|
45
|
-
...(init?.headers || {}),
|
|
46
|
-
"content-type": "application/x-www-form-urlencoded",
|
|
47
|
-
},
|
|
48
|
-
body: (body as any),
|
|
49
|
-
{{else}}
|
|
50
|
-
body: (body as any),
|
|
51
|
-
{{/if}}
|
|
41
|
+
body: body as any,
|
|
52
42
|
{{/if}}
|
|
53
43
|
contentType: "{{response.contentType}}",
|
|
54
44
|
streamingFormat: "{{response.streamingFormat}}",
|
|
@@ -68,23 +58,7 @@ export class {{serviceName Service.tag}} {
|
|
|
68
58
|
query,
|
|
69
59
|
{{/if}}
|
|
70
60
|
{{#if requestBody}}
|
|
71
|
-
|
|
72
|
-
headers: {
|
|
73
|
-
...(init?.headers || {}),
|
|
74
|
-
"content-type": "application/json",
|
|
75
|
-
},
|
|
76
|
-
body: JSON.stringify(body),
|
|
77
|
-
{{else if (eq requestBody.contentType "multipart/form-data")}}
|
|
78
|
-
body: (body as any),
|
|
79
|
-
{{else if (eq requestBody.contentType "application/x-www-form-urlencoded")}}
|
|
80
|
-
headers: {
|
|
81
|
-
...(init?.headers || {}),
|
|
82
|
-
"content-type": "application/x-www-form-urlencoded",
|
|
83
|
-
},
|
|
84
|
-
body: (body as any),
|
|
85
|
-
{{else}}
|
|
86
|
-
body: (body as any),
|
|
87
|
-
{{/if}}
|
|
61
|
+
body: body as any,
|
|
88
62
|
{{/if}}
|
|
89
63
|
...(init || {}),
|
|
90
64
|
});
|
|
@@ -7,14 +7,13 @@
|
|
|
7
7
|
"isolatedModules": true,
|
|
8
8
|
"declaration": true,
|
|
9
9
|
"removeComments": true,
|
|
10
|
-
"emitDecoratorMetadata": true,
|
|
11
|
-
"experimentalDecorators": true,
|
|
12
10
|
"allowSyntheticDefaultImports": true,
|
|
13
11
|
"target": "ES2023",
|
|
14
12
|
"sourceMap": true,
|
|
15
13
|
"outDir": "./dist",
|
|
16
14
|
"baseUrl": "./src",
|
|
17
15
|
"incremental": true,
|
|
16
|
+
"tsBuildInfoFile": "./dist/tsconfig.tsbuildinfo",
|
|
18
17
|
"skipLibCheck": true,
|
|
19
18
|
"strictNullChecks": true,
|
|
20
19
|
"forceConsistentCasingInFileNames": true,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { parseSSEStream, parseNDJSONStream } from "@blimu/fetch";
|
|
2
|
+
|
|
1
3
|
export type PaginableQuery = { limit?: number; offset?: number } & Record<string, unknown>;
|
|
2
4
|
|
|
3
5
|
export async function* paginate<T>(
|
|
@@ -30,139 +32,5 @@ export async function listAll<T>(
|
|
|
30
32
|
return out;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
* Extracts data fields from text/event-stream format
|
|
36
|
-
*/
|
|
37
|
-
export async function* parseSSEStream(
|
|
38
|
-
response: Response
|
|
39
|
-
): AsyncGenerator<string, void, unknown> {
|
|
40
|
-
if (!response.body) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const reader = response.body.getReader();
|
|
45
|
-
const decoder = new TextDecoder();
|
|
46
|
-
let buffer = "";
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
while (true) {
|
|
50
|
-
const { done, value } = await reader.read();
|
|
51
|
-
if (done) break;
|
|
52
|
-
|
|
53
|
-
buffer += decoder.decode(value, { stream: true });
|
|
54
|
-
const lines = buffer.split("\n");
|
|
55
|
-
buffer = lines.pop() || ""; // Keep incomplete line in buffer
|
|
56
|
-
|
|
57
|
-
let currentEvent: { type?: string; data?: string; id?: string } = {};
|
|
58
|
-
|
|
59
|
-
for (const line of lines) {
|
|
60
|
-
if (line.trim() === "") {
|
|
61
|
-
// Empty line indicates end of event
|
|
62
|
-
if (currentEvent.data !== undefined) {
|
|
63
|
-
yield currentEvent.data;
|
|
64
|
-
}
|
|
65
|
-
currentEvent = {};
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const colonIndex = line.indexOf(":");
|
|
70
|
-
if (colonIndex === -1) continue;
|
|
71
|
-
|
|
72
|
-
const field = line.substring(0, colonIndex).trim();
|
|
73
|
-
const value = line.substring(colonIndex + 1).trim();
|
|
74
|
-
|
|
75
|
-
if (field === "data") {
|
|
76
|
-
currentEvent.data = currentEvent.data
|
|
77
|
-
? currentEvent.data + "\n" + value
|
|
78
|
-
: value;
|
|
79
|
-
} else if (field === "event") {
|
|
80
|
-
currentEvent.type = value;
|
|
81
|
-
} else if (field === "id") {
|
|
82
|
-
currentEvent.id = value;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Handle any remaining event in buffer
|
|
88
|
-
if (buffer.trim()) {
|
|
89
|
-
const lines = buffer.split("\n");
|
|
90
|
-
let currentEvent: { data?: string } = {};
|
|
91
|
-
for (const line of lines) {
|
|
92
|
-
if (line.trim() === "" && currentEvent.data !== undefined) {
|
|
93
|
-
yield currentEvent.data;
|
|
94
|
-
currentEvent = {};
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
const colonIndex = line.indexOf(":");
|
|
98
|
-
if (colonIndex !== -1) {
|
|
99
|
-
const field = line.substring(0, colonIndex).trim();
|
|
100
|
-
const value = line.substring(colonIndex + 1).trim();
|
|
101
|
-
if (field === "data") {
|
|
102
|
-
currentEvent.data = currentEvent.data
|
|
103
|
-
? currentEvent.data + "\n" + value
|
|
104
|
-
: value;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
if (currentEvent.data !== undefined) {
|
|
109
|
-
yield currentEvent.data;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
} finally {
|
|
113
|
-
reader.releaseLock();
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Parse NDJSON (Newline-Delimited JSON) stream
|
|
119
|
-
* Yields each JSON object as it arrives
|
|
120
|
-
*/
|
|
121
|
-
export async function* parseNDJSONStream<T = any>(
|
|
122
|
-
response: Response
|
|
123
|
-
): AsyncGenerator<T, void, unknown> {
|
|
124
|
-
if (!response.body) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const reader = response.body.getReader();
|
|
129
|
-
const decoder = new TextDecoder();
|
|
130
|
-
let buffer = "";
|
|
131
|
-
|
|
132
|
-
try {
|
|
133
|
-
while (true) {
|
|
134
|
-
const { done, value } = await reader.read();
|
|
135
|
-
if (done) break;
|
|
136
|
-
|
|
137
|
-
buffer += decoder.decode(value, { stream: true });
|
|
138
|
-
const lines = buffer.split("\n");
|
|
139
|
-
buffer = lines.pop() || ""; // Keep incomplete line in buffer
|
|
140
|
-
|
|
141
|
-
for (const line of lines) {
|
|
142
|
-
const trimmed = line.trim();
|
|
143
|
-
if (trimmed === "") continue;
|
|
144
|
-
|
|
145
|
-
try {
|
|
146
|
-
const parsed = JSON.parse(trimmed) as T;
|
|
147
|
-
yield parsed;
|
|
148
|
-
} catch (error) {
|
|
149
|
-
// Skip invalid JSON lines
|
|
150
|
-
console.warn("Skipping invalid JSON line:", trimmed);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Handle any remaining line in buffer
|
|
156
|
-
if (buffer.trim()) {
|
|
157
|
-
try {
|
|
158
|
-
const parsed = JSON.parse(buffer.trim()) as T;
|
|
159
|
-
yield parsed;
|
|
160
|
-
} catch (error) {
|
|
161
|
-
// Skip invalid JSON
|
|
162
|
-
console.warn("Skipping invalid JSON in buffer:", buffer.trim());
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
} finally {
|
|
166
|
-
reader.releaseLock();
|
|
167
|
-
}
|
|
168
|
-
}
|
|
35
|
+
// Re-export streaming parsers from @blimu/fetch
|
|
36
|
+
export { parseSSEStream, parseNDJSONStream };
|
package/dist/index.d.mts
CHANGED
|
@@ -2,12 +2,12 @@ import { z } from 'zod';
|
|
|
2
2
|
import { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
|
|
3
3
|
|
|
4
4
|
type OperationIdParser = (operationId: string, method: string, path: string) => string | Promise<string>;
|
|
5
|
-
declare const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
outputFileName: z.ZodOptional<z.ZodString>;
|
|
5
|
+
declare const PredefinedTypeSchema: z.ZodObject<{
|
|
6
|
+
type: z.ZodString;
|
|
7
|
+
package: z.ZodString;
|
|
8
|
+
importPath: z.ZodOptional<z.ZodString>;
|
|
10
9
|
}, z.core.$strip>;
|
|
10
|
+
type PredefinedType = z.infer<typeof PredefinedTypeSchema>;
|
|
11
11
|
declare const TYPESCRIPT_TEMPLATE_NAMES: readonly ["client.ts.hbs", "index.ts.hbs", "package.json.hbs", "README.md.hbs", "schema.ts.hbs", "schema.zod.ts.hbs", "service.ts.hbs", "tsconfig.json.hbs", "utils.ts.hbs"];
|
|
12
12
|
type TypeScriptTemplateName = (typeof TYPESCRIPT_TEMPLATE_NAMES)[number];
|
|
13
13
|
declare const TypeScriptClientSchema: z.ZodObject<{
|
|
@@ -20,16 +20,18 @@ declare const TypeScriptClientSchema: z.ZodObject<{
|
|
|
20
20
|
postCommand: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
21
21
|
defaultBaseURL: z.ZodOptional<z.ZodString>;
|
|
22
22
|
exclude: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
23
|
-
typeAugmentation: z.ZodOptional<z.ZodObject<{
|
|
24
|
-
moduleName: z.ZodOptional<z.ZodString>;
|
|
25
|
-
namespace: z.ZodOptional<z.ZodString>;
|
|
26
|
-
typeNames: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
27
|
-
outputFileName: z.ZodOptional<z.ZodString>;
|
|
28
|
-
}, z.core.$strip>>;
|
|
29
23
|
type: z.ZodLiteral<"typescript">;
|
|
30
24
|
packageName: z.ZodString;
|
|
31
25
|
moduleName: z.ZodOptional<z.ZodString>;
|
|
32
26
|
includeQueryKeys: z.ZodOptional<z.ZodBoolean>;
|
|
27
|
+
predefinedTypes: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
28
|
+
type: z.ZodString;
|
|
29
|
+
package: z.ZodString;
|
|
30
|
+
importPath: z.ZodOptional<z.ZodString>;
|
|
31
|
+
}, z.core.$strip>>>;
|
|
32
|
+
dependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
33
|
+
devDependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
34
|
+
formatCode: z.ZodOptional<z.ZodBoolean>;
|
|
33
35
|
templates: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
34
36
|
}, z.core.$strip>;
|
|
35
37
|
declare const ClientSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
@@ -42,16 +44,18 @@ declare const ClientSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
42
44
|
postCommand: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
43
45
|
defaultBaseURL: z.ZodOptional<z.ZodString>;
|
|
44
46
|
exclude: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
45
|
-
typeAugmentation: z.ZodOptional<z.ZodObject<{
|
|
46
|
-
moduleName: z.ZodOptional<z.ZodString>;
|
|
47
|
-
namespace: z.ZodOptional<z.ZodString>;
|
|
48
|
-
typeNames: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
49
|
-
outputFileName: z.ZodOptional<z.ZodString>;
|
|
50
|
-
}, z.core.$strip>>;
|
|
51
47
|
type: z.ZodLiteral<"typescript">;
|
|
52
48
|
packageName: z.ZodString;
|
|
53
49
|
moduleName: z.ZodOptional<z.ZodString>;
|
|
54
50
|
includeQueryKeys: z.ZodOptional<z.ZodBoolean>;
|
|
51
|
+
predefinedTypes: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
52
|
+
type: z.ZodString;
|
|
53
|
+
package: z.ZodString;
|
|
54
|
+
importPath: z.ZodOptional<z.ZodString>;
|
|
55
|
+
}, z.core.$strip>>>;
|
|
56
|
+
dependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
57
|
+
devDependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
58
|
+
formatCode: z.ZodOptional<z.ZodBoolean>;
|
|
55
59
|
templates: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
56
60
|
}, z.core.$strip>], "type">;
|
|
57
61
|
declare const ConfigSchema: z.ZodObject<{
|
|
@@ -67,23 +71,24 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
67
71
|
postCommand: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
68
72
|
defaultBaseURL: z.ZodOptional<z.ZodString>;
|
|
69
73
|
exclude: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
70
|
-
typeAugmentation: z.ZodOptional<z.ZodObject<{
|
|
71
|
-
moduleName: z.ZodOptional<z.ZodString>;
|
|
72
|
-
namespace: z.ZodOptional<z.ZodString>;
|
|
73
|
-
typeNames: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
74
|
-
outputFileName: z.ZodOptional<z.ZodString>;
|
|
75
|
-
}, z.core.$strip>>;
|
|
76
74
|
type: z.ZodLiteral<"typescript">;
|
|
77
75
|
packageName: z.ZodString;
|
|
78
76
|
moduleName: z.ZodOptional<z.ZodString>;
|
|
79
77
|
includeQueryKeys: z.ZodOptional<z.ZodBoolean>;
|
|
78
|
+
predefinedTypes: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
79
|
+
type: z.ZodString;
|
|
80
|
+
package: z.ZodString;
|
|
81
|
+
importPath: z.ZodOptional<z.ZodString>;
|
|
82
|
+
}, z.core.$strip>>>;
|
|
83
|
+
dependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
84
|
+
devDependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
85
|
+
formatCode: z.ZodOptional<z.ZodBoolean>;
|
|
80
86
|
templates: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
81
87
|
}, z.core.$strip>], "type">>;
|
|
82
88
|
}, z.core.$strip>;
|
|
83
89
|
type Config = z.infer<typeof ConfigSchema>;
|
|
84
90
|
type Client = z.infer<typeof ClientSchema>;
|
|
85
91
|
type TypeScriptClient = z.infer<typeof TypeScriptClientSchema>;
|
|
86
|
-
type TypeAugmentationOptions = z.infer<typeof TypeAugmentationOptionsSchema>;
|
|
87
92
|
|
|
88
93
|
declare class ConfigService {
|
|
89
94
|
private readonly logger;
|
|
@@ -143,6 +148,7 @@ interface IR {
|
|
|
143
148
|
models: IRModel[];
|
|
144
149
|
securitySchemes: IRSecurityScheme[];
|
|
145
150
|
modelDefs: IRModelDef[];
|
|
151
|
+
openApiDocument?: any;
|
|
146
152
|
}
|
|
147
153
|
interface IRParam {
|
|
148
154
|
name: string;
|
|
@@ -245,6 +251,10 @@ declare class IrBuilderService {
|
|
|
245
251
|
private firstAllowedTag;
|
|
246
252
|
private collectSecuritySchemes;
|
|
247
253
|
private collectParams;
|
|
254
|
+
private findMatchingComponentSchema;
|
|
255
|
+
private compareSchemas;
|
|
256
|
+
private extractModelNameFromSchema;
|
|
257
|
+
private generateTypeName;
|
|
248
258
|
private extractRequestBodyWithTypes;
|
|
249
259
|
private extractRequestBody;
|
|
250
260
|
private extractResponseWithTypes;
|
|
@@ -289,6 +299,7 @@ declare class TypeScriptGeneratorService implements Generator<TypeScriptClient>
|
|
|
289
299
|
private generatePackageJson;
|
|
290
300
|
private generateTsConfig;
|
|
291
301
|
private generateReadme;
|
|
302
|
+
private generatePrettierConfig;
|
|
292
303
|
}
|
|
293
304
|
|
|
294
305
|
declare class GeneratorModule {
|
|
@@ -302,8 +313,9 @@ declare class OpenApiModule {
|
|
|
302
313
|
|
|
303
314
|
interface GenerateOptions {
|
|
304
315
|
client?: string;
|
|
316
|
+
baseDir?: string;
|
|
305
317
|
}
|
|
306
318
|
declare function generate(configOrPath: Config | string, options?: GenerateOptions): Promise<void>;
|
|
307
319
|
declare function loadConfig(configPath: string): Promise<Config>;
|
|
308
320
|
|
|
309
|
-
export { type Client, ClientSchema, type Config, ConfigModule, ConfigSchema, ConfigService, type GenerateOptions, type Generator, GeneratorModule, GeneratorService, type IR, type IRAnnotations, type IRDiscriminator, type IRField, type IRModel, type IRModelDef, type IROperation, type IRParam, type IRRequestBody, type IRResponse, type IRSchema, IRSchemaKind, type IRSecurityScheme, type IRService, OpenApiModule, OpenApiService, type OperationIdParser,
|
|
321
|
+
export { type Client, ClientSchema, type Config, ConfigModule, ConfigSchema, ConfigService, type GenerateOptions, type Generator, GeneratorModule, GeneratorService, type IR, type IRAnnotations, type IRDiscriminator, type IRField, type IRModel, type IRModelDef, type IROperation, type IRParam, type IRRequestBody, type IRResponse, type IRSchema, IRSchemaKind, type IRSecurityScheme, type IRService, OpenApiModule, OpenApiService, type OperationIdParser, type PredefinedType, PredefinedTypeSchema, TYPESCRIPT_TEMPLATE_NAMES, type TypeScriptClient, TypeScriptClientSchema, type TypeScriptTemplateName, defineConfig, generate, loadConfig, loadMjsConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,12 +2,12 @@ import { z } from 'zod';
|
|
|
2
2
|
import { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
|
|
3
3
|
|
|
4
4
|
type OperationIdParser = (operationId: string, method: string, path: string) => string | Promise<string>;
|
|
5
|
-
declare const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
outputFileName: z.ZodOptional<z.ZodString>;
|
|
5
|
+
declare const PredefinedTypeSchema: z.ZodObject<{
|
|
6
|
+
type: z.ZodString;
|
|
7
|
+
package: z.ZodString;
|
|
8
|
+
importPath: z.ZodOptional<z.ZodString>;
|
|
10
9
|
}, z.core.$strip>;
|
|
10
|
+
type PredefinedType = z.infer<typeof PredefinedTypeSchema>;
|
|
11
11
|
declare const TYPESCRIPT_TEMPLATE_NAMES: readonly ["client.ts.hbs", "index.ts.hbs", "package.json.hbs", "README.md.hbs", "schema.ts.hbs", "schema.zod.ts.hbs", "service.ts.hbs", "tsconfig.json.hbs", "utils.ts.hbs"];
|
|
12
12
|
type TypeScriptTemplateName = (typeof TYPESCRIPT_TEMPLATE_NAMES)[number];
|
|
13
13
|
declare const TypeScriptClientSchema: z.ZodObject<{
|
|
@@ -20,16 +20,18 @@ declare const TypeScriptClientSchema: z.ZodObject<{
|
|
|
20
20
|
postCommand: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
21
21
|
defaultBaseURL: z.ZodOptional<z.ZodString>;
|
|
22
22
|
exclude: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
23
|
-
typeAugmentation: z.ZodOptional<z.ZodObject<{
|
|
24
|
-
moduleName: z.ZodOptional<z.ZodString>;
|
|
25
|
-
namespace: z.ZodOptional<z.ZodString>;
|
|
26
|
-
typeNames: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
27
|
-
outputFileName: z.ZodOptional<z.ZodString>;
|
|
28
|
-
}, z.core.$strip>>;
|
|
29
23
|
type: z.ZodLiteral<"typescript">;
|
|
30
24
|
packageName: z.ZodString;
|
|
31
25
|
moduleName: z.ZodOptional<z.ZodString>;
|
|
32
26
|
includeQueryKeys: z.ZodOptional<z.ZodBoolean>;
|
|
27
|
+
predefinedTypes: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
28
|
+
type: z.ZodString;
|
|
29
|
+
package: z.ZodString;
|
|
30
|
+
importPath: z.ZodOptional<z.ZodString>;
|
|
31
|
+
}, z.core.$strip>>>;
|
|
32
|
+
dependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
33
|
+
devDependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
34
|
+
formatCode: z.ZodOptional<z.ZodBoolean>;
|
|
33
35
|
templates: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
34
36
|
}, z.core.$strip>;
|
|
35
37
|
declare const ClientSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
@@ -42,16 +44,18 @@ declare const ClientSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
42
44
|
postCommand: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
43
45
|
defaultBaseURL: z.ZodOptional<z.ZodString>;
|
|
44
46
|
exclude: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
45
|
-
typeAugmentation: z.ZodOptional<z.ZodObject<{
|
|
46
|
-
moduleName: z.ZodOptional<z.ZodString>;
|
|
47
|
-
namespace: z.ZodOptional<z.ZodString>;
|
|
48
|
-
typeNames: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
49
|
-
outputFileName: z.ZodOptional<z.ZodString>;
|
|
50
|
-
}, z.core.$strip>>;
|
|
51
47
|
type: z.ZodLiteral<"typescript">;
|
|
52
48
|
packageName: z.ZodString;
|
|
53
49
|
moduleName: z.ZodOptional<z.ZodString>;
|
|
54
50
|
includeQueryKeys: z.ZodOptional<z.ZodBoolean>;
|
|
51
|
+
predefinedTypes: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
52
|
+
type: z.ZodString;
|
|
53
|
+
package: z.ZodString;
|
|
54
|
+
importPath: z.ZodOptional<z.ZodString>;
|
|
55
|
+
}, z.core.$strip>>>;
|
|
56
|
+
dependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
57
|
+
devDependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
58
|
+
formatCode: z.ZodOptional<z.ZodBoolean>;
|
|
55
59
|
templates: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
56
60
|
}, z.core.$strip>], "type">;
|
|
57
61
|
declare const ConfigSchema: z.ZodObject<{
|
|
@@ -67,23 +71,24 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
67
71
|
postCommand: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
68
72
|
defaultBaseURL: z.ZodOptional<z.ZodString>;
|
|
69
73
|
exclude: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
70
|
-
typeAugmentation: z.ZodOptional<z.ZodObject<{
|
|
71
|
-
moduleName: z.ZodOptional<z.ZodString>;
|
|
72
|
-
namespace: z.ZodOptional<z.ZodString>;
|
|
73
|
-
typeNames: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
74
|
-
outputFileName: z.ZodOptional<z.ZodString>;
|
|
75
|
-
}, z.core.$strip>>;
|
|
76
74
|
type: z.ZodLiteral<"typescript">;
|
|
77
75
|
packageName: z.ZodString;
|
|
78
76
|
moduleName: z.ZodOptional<z.ZodString>;
|
|
79
77
|
includeQueryKeys: z.ZodOptional<z.ZodBoolean>;
|
|
78
|
+
predefinedTypes: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
79
|
+
type: z.ZodString;
|
|
80
|
+
package: z.ZodString;
|
|
81
|
+
importPath: z.ZodOptional<z.ZodString>;
|
|
82
|
+
}, z.core.$strip>>>;
|
|
83
|
+
dependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
84
|
+
devDependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
85
|
+
formatCode: z.ZodOptional<z.ZodBoolean>;
|
|
80
86
|
templates: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
81
87
|
}, z.core.$strip>], "type">>;
|
|
82
88
|
}, z.core.$strip>;
|
|
83
89
|
type Config = z.infer<typeof ConfigSchema>;
|
|
84
90
|
type Client = z.infer<typeof ClientSchema>;
|
|
85
91
|
type TypeScriptClient = z.infer<typeof TypeScriptClientSchema>;
|
|
86
|
-
type TypeAugmentationOptions = z.infer<typeof TypeAugmentationOptionsSchema>;
|
|
87
92
|
|
|
88
93
|
declare class ConfigService {
|
|
89
94
|
private readonly logger;
|
|
@@ -143,6 +148,7 @@ interface IR {
|
|
|
143
148
|
models: IRModel[];
|
|
144
149
|
securitySchemes: IRSecurityScheme[];
|
|
145
150
|
modelDefs: IRModelDef[];
|
|
151
|
+
openApiDocument?: any;
|
|
146
152
|
}
|
|
147
153
|
interface IRParam {
|
|
148
154
|
name: string;
|
|
@@ -245,6 +251,10 @@ declare class IrBuilderService {
|
|
|
245
251
|
private firstAllowedTag;
|
|
246
252
|
private collectSecuritySchemes;
|
|
247
253
|
private collectParams;
|
|
254
|
+
private findMatchingComponentSchema;
|
|
255
|
+
private compareSchemas;
|
|
256
|
+
private extractModelNameFromSchema;
|
|
257
|
+
private generateTypeName;
|
|
248
258
|
private extractRequestBodyWithTypes;
|
|
249
259
|
private extractRequestBody;
|
|
250
260
|
private extractResponseWithTypes;
|
|
@@ -289,6 +299,7 @@ declare class TypeScriptGeneratorService implements Generator<TypeScriptClient>
|
|
|
289
299
|
private generatePackageJson;
|
|
290
300
|
private generateTsConfig;
|
|
291
301
|
private generateReadme;
|
|
302
|
+
private generatePrettierConfig;
|
|
292
303
|
}
|
|
293
304
|
|
|
294
305
|
declare class GeneratorModule {
|
|
@@ -302,8 +313,9 @@ declare class OpenApiModule {
|
|
|
302
313
|
|
|
303
314
|
interface GenerateOptions {
|
|
304
315
|
client?: string;
|
|
316
|
+
baseDir?: string;
|
|
305
317
|
}
|
|
306
318
|
declare function generate(configOrPath: Config | string, options?: GenerateOptions): Promise<void>;
|
|
307
319
|
declare function loadConfig(configPath: string): Promise<Config>;
|
|
308
320
|
|
|
309
|
-
export { type Client, ClientSchema, type Config, ConfigModule, ConfigSchema, ConfigService, type GenerateOptions, type Generator, GeneratorModule, GeneratorService, type IR, type IRAnnotations, type IRDiscriminator, type IRField, type IRModel, type IRModelDef, type IROperation, type IRParam, type IRRequestBody, type IRResponse, type IRSchema, IRSchemaKind, type IRSecurityScheme, type IRService, OpenApiModule, OpenApiService, type OperationIdParser,
|
|
321
|
+
export { type Client, ClientSchema, type Config, ConfigModule, ConfigSchema, ConfigService, type GenerateOptions, type Generator, GeneratorModule, GeneratorService, type IR, type IRAnnotations, type IRDiscriminator, type IRField, type IRModel, type IRModelDef, type IROperation, type IRParam, type IRRequestBody, type IRResponse, type IRSchema, IRSchemaKind, type IRSecurityScheme, type IRService, OpenApiModule, OpenApiService, type OperationIdParser, type PredefinedType, PredefinedTypeSchema, TYPESCRIPT_TEMPLATE_NAMES, type TypeScriptClient, TypeScriptClientSchema, type TypeScriptTemplateName, defineConfig, generate, loadConfig, loadMjsConfig };
|