@sdk-it/typescript 0.39.0 → 0.40.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.
Files changed (64) hide show
  1. package/dist/index.js +155 -53
  2. package/dist/index.js.map +3 -3
  3. package/dist/lib/client.d.ts.map +1 -1
  4. package/dist/lib/emitters/zod.d.ts.map +1 -1
  5. package/dist/lib/generate.d.ts +3 -1
  6. package/dist/lib/generate.d.ts.map +1 -1
  7. package/dist/lib/generator.d.ts.map +1 -1
  8. package/dist/lib/options.d.ts +1 -0
  9. package/dist/lib/options.d.ts.map +1 -1
  10. package/dist/lib/sdk.d.ts +1 -1
  11. package/dist/lib/sdk.d.ts.map +1 -1
  12. package/dist/lib/server-urls.d.ts +3 -0
  13. package/dist/lib/server-urls.d.ts.map +1 -0
  14. package/dist/lib/status-map.d.ts.map +1 -1
  15. package/dist/lib/typescript-snippet.d.ts.map +1 -1
  16. package/package.json +4 -4
  17. package/dist/connect.d.ts +0 -1
  18. package/dist/connect.d.ts.map +0 -1
  19. package/dist/global.d.js +0 -1
  20. package/dist/global.d.js.map +0 -7
  21. package/dist/lib/connect.d.ts +0 -162
  22. package/dist/lib/connect.d.ts.map +0 -1
  23. package/dist/lib/readme-generator.d.ts +0 -8
  24. package/dist/lib/readme-generator.d.ts.map +0 -1
  25. package/dist/lib/statusMap.d.ts +0 -2
  26. package/dist/lib/statusMap.d.ts.map +0 -1
  27. package/dist/lib/utils.d.ts +0 -17
  28. package/dist/lib/utils.d.ts.map +0 -1
  29. package/dist/lib/watcher.d.ts +0 -2
  30. package/dist/lib/watcher.d.ts.map +0 -1
  31. package/dist/src/index.js +0 -5
  32. package/dist/src/index.js.map +0 -7
  33. package/dist/src/lib/agent/ai-sdk.js +0 -60
  34. package/dist/src/lib/agent/ai-sdk.js.map +0 -7
  35. package/dist/src/lib/agent/openai-agents.js +0 -42
  36. package/dist/src/lib/agent/openai-agents.js.map +0 -7
  37. package/dist/src/lib/client.js +0 -152
  38. package/dist/src/lib/client.js.map +0 -7
  39. package/dist/src/lib/emitters/interface.js +0 -169
  40. package/dist/src/lib/emitters/interface.js.map +0 -7
  41. package/dist/src/lib/emitters/snippet.js +0 -191
  42. package/dist/src/lib/emitters/snippet.js.map +0 -7
  43. package/dist/src/lib/emitters/zod.js +0 -271
  44. package/dist/src/lib/emitters/zod.js.map +0 -7
  45. package/dist/src/lib/generate.js +0 -382
  46. package/dist/src/lib/generate.js.map +0 -7
  47. package/dist/src/lib/generator.js +0 -268
  48. package/dist/src/lib/generator.js.map +0 -7
  49. package/dist/src/lib/import-utilities.js +0 -56
  50. package/dist/src/lib/import-utilities.js.map +0 -7
  51. package/dist/src/lib/options.js +0 -3
  52. package/dist/src/lib/options.js.map +0 -7
  53. package/dist/src/lib/readme/prop.emitter.js +0 -283
  54. package/dist/src/lib/readme/prop.emitter.js.map +0 -7
  55. package/dist/src/lib/readme/readme.js +0 -105
  56. package/dist/src/lib/readme/readme.js.map +0 -7
  57. package/dist/src/lib/sdk.js +0 -236
  58. package/dist/src/lib/sdk.js.map +0 -7
  59. package/dist/src/lib/status-map.js +0 -28
  60. package/dist/src/lib/status-map.js.map +0 -7
  61. package/dist/src/lib/style.js +0 -1
  62. package/dist/src/lib/style.js.map +0 -7
  63. package/dist/src/lib/typescript-snippet.js +0 -738
  64. package/dist/src/lib/typescript-snippet.js.map +0 -7
@@ -1,268 +0,0 @@
1
- import { merge, template } from "lodash-es";
2
- import { join } from "node:path";
3
- import { camelcase, spinalcase } from "stringcase";
4
- import { followRef, isEmpty, isRef, resolveRef } from "@sdk-it/core";
5
- import {
6
- forEachOperation
7
- } from "@sdk-it/spec";
8
- import { ZodEmitter } from "./emitters/zod.ts";
9
- import { toEndpoint } from "./sdk.ts";
10
- import endpointsTxt from "./styles/github/endpoints.txt";
11
- function coearceRequestInput(spec, operation, type) {
12
- let objectSchema = resolveRef(
13
- spec,
14
- operation.requestBody.content[type].schema
15
- );
16
- const xProperties = objectSchema["x-properties"] ?? {};
17
- const xRequired = objectSchema["x-required"] ?? [];
18
- if (type === "application/empty") {
19
- objectSchema = {
20
- type: "object",
21
- additionalProperties: isEmpty(xProperties)
22
- };
23
- } else {
24
- if (objectSchema.type !== "object") {
25
- objectSchema = {
26
- type: "object",
27
- required: [operation.requestBody.required ? "$body" : ""],
28
- properties: {
29
- $body: objectSchema
30
- }
31
- };
32
- }
33
- }
34
- return {
35
- objectSchema,
36
- xProperties,
37
- xRequired
38
- };
39
- }
40
- function generateCode(config) {
41
- const commonZod = /* @__PURE__ */ new Map();
42
- const commonZodImports = [];
43
- const zodDeserialzer = new ZodEmitter(config.spec, (model, schema) => {
44
- commonZod.set(model, schema);
45
- commonZodImports.push({
46
- defaultImport: void 0,
47
- isTypeOnly: true,
48
- moduleSpecifier: `./${config.makeImport(model)}`,
49
- namedImports: [{ isTypeOnly: true, name: model }],
50
- namespaceImport: void 0
51
- });
52
- });
53
- const groups = {};
54
- const endpoints = {};
55
- forEachOperation(config.spec, (entry, operation) => {
56
- console.log(`Processing ${entry.method} ${entry.path}`);
57
- groups[entry.tag] ??= [];
58
- endpoints[entry.tag] ??= [];
59
- const schemas = {};
60
- const shortContenTypeMap = {
61
- "application/json": "json",
62
- "application/*+json": "json",
63
- // type specific of json like application/vnd.api+json (from the generation pov it shouldn't matter)
64
- "text/json": "json",
65
- // non standard - later standardized to application/json
66
- "application/x-www-form-urlencoded": "urlencoded",
67
- "multipart/form-data": "formdata",
68
- "application/xml": "xml",
69
- "text/plain": "text"
70
- };
71
- for (const type in operation.requestBody.content) {
72
- schemas[shortContenTypeMap[type]] = zodDeserialzer.handle(
73
- operationSchema(config.spec, operation, type),
74
- true
75
- );
76
- }
77
- const details = buildInput(config.spec, operation);
78
- const endpoint = toEndpoint(
79
- entry.tag,
80
- config.spec,
81
- operation,
82
- {
83
- method: entry.method,
84
- path: entry.path,
85
- operationId: operation.operationId,
86
- schemas,
87
- outgoingContentType: details.outgoingContentType,
88
- inputs: details.inputs
89
- },
90
- config
91
- );
92
- endpoints[entry.tag].push(endpoint);
93
- groups[entry.tag].push({
94
- method: entry.method,
95
- path: entry.path,
96
- operationId: operation.operationId,
97
- schemas,
98
- outgoingContentType: details.outgoingContentType,
99
- inputs: details.inputs
100
- });
101
- });
102
- const allSchemas = Object.keys(endpoints).map((it) => ({
103
- import: `import ${camelcase(it)} from './${config.makeImport(spinalcase(it))}';`,
104
- use: ` ...${camelcase(it)}`
105
- }));
106
- return {
107
- groups,
108
- commonZod,
109
- endpoints: {
110
- [join("api", "endpoints.ts")]: `
111
-
112
-
113
- import type z from 'zod';
114
- import type { ParseError } from '${config.makeImport("../http/parser")}';
115
- import type { ProblematicResponse, SuccessfulResponse } from '${config.makeImport(
116
- "../http/response"
117
- )}';
118
-
119
- import schemas from '${config.makeImport("./schemas")}';
120
- import type { Unionize } from '${config.makeImport("../http/dispatcher")}';
121
- ${template(endpointsTxt)({ outputType: config.style?.outputType })}`,
122
- [`${join("api", "schemas.ts")}`]: `${allSchemas.map((it) => it.import).join("\n")}
123
- import { KIND } from "${config.makeImport("../http/index")}";
124
- export default {
125
- ${allSchemas.map((it) => it.use).join(",\n")}
126
- };
127
-
128
- `.trim(),
129
- ...Object.fromEntries(
130
- Object.entries(endpoints).map(([name, endpoint]) => {
131
- return [
132
- [
133
- join("api", `${spinalcase(name)}.ts`),
134
- `${[
135
- `import z from 'zod';`,
136
- `import * as http from '${config.makeImport("../http/response")}';`,
137
- `import * as outputs from '${config.makeImport("../outputs/index")}';`,
138
- `import { toRequest, json, urlencoded, empty, formdata, type HeadersInit } from '${config.makeImport("../http/request")}';`,
139
- `import { chunked, buffered } from "${config.makeImport("../http/parse-response")}";`,
140
- `import * as ${camelcase(name)} from '../inputs/${config.makeImport(spinalcase(name))}';`,
141
- `import { createBaseUrlInterceptor, createHeadersInterceptor, type Interceptor } from '${config.makeImport("../http/interceptors")}';`,
142
- `import { Dispatcher, fetchType, type InstanceType } from '${config.makeImport("../http/dispatcher")}';`,
143
- `import { Pagination, OffsetPagination, CursorPagination } from "${config.makeImport("../pagination/index")}";`
144
- ].join(
145
- "\n"
146
- )}
147
- export default {
148
- ${endpoint.flatMap((it) => it.schemas).join(",\n")}
149
- }`
150
- ]
151
- ];
152
- }).flat()
153
- )
154
- }
155
- };
156
- }
157
- function toProps(spec, schemaOrRef, aggregator = []) {
158
- if (isRef(schemaOrRef)) {
159
- const schema = followRef(spec, schemaOrRef.$ref);
160
- return toProps(spec, schema, aggregator);
161
- } else if (schemaOrRef.type === "object") {
162
- for (const [name] of Object.entries(schemaOrRef.properties ?? {})) {
163
- aggregator.push(name);
164
- }
165
- return void 0;
166
- } else if ((schemaOrRef.type === "array" || schemaOrRef.type?.includes("array")) && schemaOrRef.items) {
167
- toProps(spec, schemaOrRef.items, aggregator);
168
- return void 0;
169
- } else if (schemaOrRef.allOf) {
170
- for (const it of schemaOrRef.allOf) {
171
- toProps(spec, it, aggregator);
172
- }
173
- return void 0;
174
- } else if (schemaOrRef.oneOf) {
175
- for (const it of schemaOrRef.oneOf) {
176
- toProps(spec, it, aggregator);
177
- }
178
- return void 0;
179
- } else if (schemaOrRef.anyOf) {
180
- for (const it of schemaOrRef.anyOf) {
181
- toProps(spec, it, aggregator);
182
- }
183
- return void 0;
184
- }
185
- console.warn("Unknown schema in body", schemaOrRef);
186
- return void 0;
187
- }
188
- function bodyInputs(spec, ctSchema) {
189
- const props = [];
190
- toProps(spec, ctSchema, props);
191
- return props.toSorted((a, b) => a.localeCompare(b)).reduce(
192
- (acc, prop) => ({
193
- ...acc,
194
- [prop]: {
195
- in: "body",
196
- schema: ""
197
- }
198
- }),
199
- {}
200
- );
201
- }
202
- const contentTypeSerializerMap = {
203
- "application/json": "json",
204
- "application/x-www-form-urlencoded": "urlencoded",
205
- "multipart/form-data": "formdata",
206
- "application/xml": "xml",
207
- "text/plain": "text",
208
- "application/empty": "empty"
209
- };
210
- const serializerContentTypeMap = Object.fromEntries(
211
- Object.entries(contentTypeSerializerMap).map(([k, v]) => [v, k])
212
- );
213
- function buildInput(spec, operation) {
214
- const inputs = {};
215
- let outgoingContentType = "empty";
216
- for (const [ct, value] of Object.entries(contentTypeSerializerMap)) {
217
- if (operation.requestBody.content[ct]) {
218
- outgoingContentType = value;
219
- const { objectSchema, xProperties } = coearceRequestInput(
220
- spec,
221
- operation,
222
- ct
223
- );
224
- for (const [name, prop] of Object.entries(xProperties)) {
225
- inputs[name] = {
226
- in: prop["x-in"],
227
- schema: ""
228
- };
229
- }
230
- Object.assign(inputs, bodyInputs(spec, objectSchema));
231
- break;
232
- }
233
- }
234
- return {
235
- inputs,
236
- outgoingContentType,
237
- ct: serializerContentTypeMap[outgoingContentType]
238
- };
239
- }
240
- function operationSchema(ir, operation, type) {
241
- const { objectSchema, xProperties, xRequired } = coearceRequestInput(
242
- ir,
243
- operation,
244
- type
245
- );
246
- const additionalProperties = {};
247
- for (const [name, prop] of Object.entries(xProperties)) {
248
- additionalProperties[name] = {
249
- name,
250
- required: xRequired?.includes(name),
251
- schema: prop,
252
- in: prop["x-in"]
253
- };
254
- }
255
- return merge({}, objectSchema, {
256
- required: Object.values(additionalProperties).filter((p) => p.required).map((p) => p.name),
257
- properties: Object.entries(additionalProperties).reduce(
258
- (acc, [, p]) => ({ ...acc, [p.name]: p.schema }),
259
- {}
260
- )
261
- });
262
- }
263
- export {
264
- buildInput,
265
- generateCode,
266
- operationSchema
267
- };
268
- //# sourceMappingURL=generator.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/lib/generator.ts"],
4
- "sourcesContent": ["import { merge, template } from 'lodash-es';\nimport { join } from 'node:path';\nimport type {\n OpenAPIObject,\n ParameterObject,\n ReferenceObject,\n SchemaObject,\n} from 'openapi3-ts/oas31';\nimport { camelcase, spinalcase } from 'stringcase';\n\nimport { followRef, isEmpty, isRef, resolveRef } from '@sdk-it/core';\nimport {\n type IR,\n type TunedOperationObject,\n forEachOperation,\n} from '@sdk-it/spec';\n\nimport { ZodEmitter } from './emitters/zod.ts';\nimport { type OperationInput, type Spec, toEndpoint } from './sdk.ts';\nimport type { Style } from './style.ts';\nimport endpointsTxt from './styles/github/endpoints.txt';\n\nfunction coearceRequestInput(\n spec: IR,\n operation: TunedOperationObject,\n type: string,\n) {\n let objectSchema = resolveRef(\n spec,\n operation.requestBody.content[type].schema,\n );\n const xProperties: Record<string, SchemaObject> =\n objectSchema['x-properties'] ?? {};\n const xRequired: string[] = objectSchema['x-required'] ?? [];\n\n if (type === 'application/empty') {\n // if empty body and not params then we need to set it to object with additional properties\n // to avoid unknown input ts errors.\n objectSchema = {\n type: 'object',\n additionalProperties: isEmpty(xProperties),\n };\n } else {\n if (objectSchema.type !== 'object') {\n objectSchema = {\n type: 'object',\n required: [operation.requestBody.required ? '$body' : ''],\n properties: {\n $body: objectSchema,\n },\n };\n }\n }\n return {\n objectSchema,\n xProperties,\n xRequired,\n };\n}\nexport interface NamedImport {\n name: string;\n alias?: string;\n isTypeOnly: boolean;\n}\nexport interface Import {\n isTypeOnly: boolean;\n moduleSpecifier: string;\n defaultImport: string | undefined;\n namedImports: NamedImport[];\n namespaceImport: string | undefined;\n}\n\nexport function generateCode(config: {\n /**\n * No support for jsdoc in vscode\n * @issue https://github.com/microsoft/TypeScript/issues/38106\n */\n spec: IR;\n style: Style;\n makeImport: (module: string) => string;\n}) {\n const commonZod = new Map<string, string>();\n const commonZodImports: Import[] = [];\n const zodDeserialzer = new ZodEmitter(config.spec, (model, schema) => {\n commonZod.set(model, schema);\n commonZodImports.push({\n defaultImport: undefined,\n isTypeOnly: true,\n moduleSpecifier: `./${config.makeImport(model)}`,\n namedImports: [{ isTypeOnly: true, name: model }],\n namespaceImport: undefined,\n });\n });\n\n const groups: Spec['operations'] = {};\n const endpoints: Record<string, ReturnType<typeof toEndpoint>[]> = {};\n\n forEachOperation(config.spec, (entry, operation) => {\n console.log(`Processing ${entry.method} ${entry.path}`);\n groups[entry.tag] ??= [];\n endpoints[entry.tag] ??= [];\n const schemas: Record<string, string> = {};\n const shortContenTypeMap: Record<string, string> = {\n 'application/json': 'json',\n 'application/*+json': 'json', // type specific of json like application/vnd.api+json (from the generation pov it shouldn't matter)\n 'text/json': 'json', // non standard - later standardized to application/json\n 'application/x-www-form-urlencoded': 'urlencoded',\n 'multipart/form-data': 'formdata',\n 'application/xml': 'xml',\n 'text/plain': 'text',\n };\n\n for (const type in operation.requestBody.content) {\n schemas[shortContenTypeMap[type]] = zodDeserialzer.handle(\n operationSchema(config.spec, operation, type),\n true,\n );\n }\n const details = buildInput(config.spec, operation);\n const endpoint = toEndpoint(\n entry.tag,\n config.spec,\n operation,\n {\n method: entry.method,\n path: entry.path,\n operationId: operation.operationId,\n schemas,\n outgoingContentType: details.outgoingContentType,\n inputs: details.inputs,\n },\n config,\n );\n\n endpoints[entry.tag].push(endpoint);\n\n groups[entry.tag].push({\n method: entry.method,\n path: entry.path,\n operationId: operation.operationId,\n schemas,\n outgoingContentType: details.outgoingContentType,\n inputs: details.inputs,\n });\n });\n const allSchemas = Object.keys(endpoints).map((it) => ({\n import: `import ${camelcase(it)} from './${config.makeImport(spinalcase(it))}';`,\n use: ` ...${camelcase(it)}`,\n }));\n\n return {\n groups,\n commonZod,\n endpoints: {\n [join('api', 'endpoints.ts')]: `\n\n\nimport type z from 'zod';\nimport type { ParseError } from '${config.makeImport('../http/parser')}';\nimport type { ProblematicResponse, SuccessfulResponse } from '${config.makeImport(\n '../http/response',\n )}';\n\nimport schemas from '${config.makeImport('./schemas')}';\nimport type { Unionize } from '${config.makeImport('../http/dispatcher')}';\n ${template(endpointsTxt)({ outputType: config.style?.outputType })}`,\n [`${join('api', 'schemas.ts')}`]:\n `${allSchemas.map((it) => it.import).join('\\n')}\nimport { KIND } from \"${config.makeImport('../http/index')}\";\nexport default {\\n${allSchemas.map((it) => it.use).join(',\\n')}\\n};\n\n`.trim(),\n ...Object.fromEntries(\n Object.entries(endpoints)\n .map(([name, endpoint]) => {\n return [\n [\n join('api', `${spinalcase(name)}.ts`),\n `${[\n `import z from 'zod';`,\n `import * as http from '${config.makeImport('../http/response')}';`,\n `import * as outputs from '${config.makeImport('../outputs/index')}';`,\n `import { toRequest, json, urlencoded, empty, formdata, type HeadersInit } from '${config.makeImport('../http/request')}';`,\n `import { chunked, buffered } from \"${config.makeImport('../http/parse-response')}\";`,\n `import * as ${camelcase(name)} from '../inputs/${config.makeImport(spinalcase(name))}';`,\n `import { createBaseUrlInterceptor, createHeadersInterceptor, type Interceptor } from '${config.makeImport('../http/interceptors')}';`,\n `import { Dispatcher, fetchType, type InstanceType } from '${config.makeImport('../http/dispatcher')}';`,\n `import { Pagination, OffsetPagination, CursorPagination } from \"${config.makeImport('../pagination/index')}\";`,\n ].join(\n '\\n',\n )}\\nexport default {\\n${endpoint.flatMap((it) => it.schemas).join(',\\n')}\\n}`,\n ],\n ];\n })\n .flat(),\n ),\n },\n };\n}\n\nfunction toProps(\n spec: OpenAPIObject,\n schemaOrRef: SchemaObject | ReferenceObject,\n aggregator: string[] = [],\n) {\n if (isRef(schemaOrRef)) {\n const schema = followRef(spec, schemaOrRef.$ref);\n return toProps(spec, schema, aggregator);\n } else if (schemaOrRef.type === 'object') {\n for (const [name] of Object.entries(schemaOrRef.properties ?? {})) {\n aggregator.push(name);\n }\n return void 0;\n } else if (\n (schemaOrRef.type === 'array' || schemaOrRef.type?.includes('array')) &&\n schemaOrRef.items\n ) {\n toProps(spec, schemaOrRef.items, aggregator);\n return void 0;\n } else if (schemaOrRef.allOf) {\n for (const it of schemaOrRef.allOf) {\n toProps(spec, it, aggregator);\n }\n return void 0;\n } else if (schemaOrRef.oneOf) {\n for (const it of schemaOrRef.oneOf) {\n toProps(spec, it, aggregator);\n }\n return void 0;\n } else if (schemaOrRef.anyOf) {\n for (const it of schemaOrRef.anyOf) {\n toProps(spec, it, aggregator);\n }\n return void 0;\n }\n console.warn('Unknown schema in body', schemaOrRef);\n return void 0;\n}\n\nfunction bodyInputs(spec: IR, ctSchema: SchemaObject | ReferenceObject) {\n const props: string[] = [];\n toProps(spec, ctSchema, props);\n\n return (\n props\n // TODO: should we preproccess the sort at spec level instead of generator's?\n .toSorted((a, b) => a.localeCompare(b))\n .reduce<Record<string, OperationInput>>(\n (acc, prop) => ({\n ...acc,\n [prop]: {\n in: 'body',\n schema: '',\n },\n }),\n {},\n )\n );\n}\n\nconst contentTypeSerializerMap = {\n 'application/json': 'json',\n 'application/x-www-form-urlencoded': 'urlencoded',\n 'multipart/form-data': 'formdata',\n 'application/xml': 'xml',\n 'text/plain': 'text',\n 'application/empty': 'empty',\n} as const;\nconst serializerContentTypeMap = Object.fromEntries(\n Object.entries(contentTypeSerializerMap).map(([k, v]) => [v, k]),\n) as Record<\n (typeof contentTypeSerializerMap)[keyof typeof contentTypeSerializerMap],\n string\n>;\n\nexport function buildInput(spec: IR, operation: TunedOperationObject) {\n const inputs: Record<string, OperationInput> = {};\n\n let outgoingContentType: (typeof contentTypeSerializerMap)[keyof typeof contentTypeSerializerMap] =\n 'empty';\n\n for (const [ct, value] of Object.entries(contentTypeSerializerMap)) {\n if (operation.requestBody.content[ct]) {\n outgoingContentType = value;\n const { objectSchema, xProperties } = coearceRequestInput(\n spec,\n operation,\n ct,\n );\n for (const [name, prop] of Object.entries(xProperties)) {\n inputs[name] = {\n in: prop['x-in'],\n schema: '',\n };\n }\n\n Object.assign(inputs, bodyInputs(spec, objectSchema));\n break;\n }\n }\n return {\n inputs,\n outgoingContentType,\n ct: serializerContentTypeMap[outgoingContentType],\n };\n}\n\nexport function operationSchema(\n ir: IR,\n operation: TunedOperationObject,\n type: string,\n) {\n const { objectSchema, xProperties, xRequired } = coearceRequestInput(\n ir,\n operation,\n type,\n );\n const additionalProperties: Record<string, ParameterObject> = {};\n for (const [name, prop] of Object.entries(xProperties)) {\n additionalProperties[name] = {\n name: name,\n required: xRequired?.includes(name),\n schema: prop,\n in: prop['x-in'],\n };\n }\n\n return merge({}, objectSchema, {\n required: Object.values(additionalProperties)\n .filter((p) => p.required)\n .map((p) => p.name),\n properties: Object.entries(additionalProperties).reduce(\n (acc, [, p]) => ({ ...acc, [p.name]: p.schema }),\n {},\n ),\n });\n}\n"],
5
- "mappings": "AAAA,SAAS,OAAO,gBAAgB;AAChC,SAAS,YAAY;AAOrB,SAAS,WAAW,kBAAkB;AAEtC,SAAS,WAAW,SAAS,OAAO,kBAAkB;AACtD;AAAA,EAGE;AAAA,OACK;AAEP,SAAS,kBAAkB;AAC3B,SAAyC,kBAAkB;AAE3D,OAAO,kBAAkB;AAEzB,SAAS,oBACP,MACA,WACA,MACA;AACA,MAAI,eAAe;AAAA,IACjB;AAAA,IACA,UAAU,YAAY,QAAQ,IAAI,EAAE;AAAA,EACtC;AACA,QAAM,cACJ,aAAa,cAAc,KAAK,CAAC;AACnC,QAAM,YAAsB,aAAa,YAAY,KAAK,CAAC;AAE3D,MAAI,SAAS,qBAAqB;AAGhC,mBAAe;AAAA,MACb,MAAM;AAAA,MACN,sBAAsB,QAAQ,WAAW;AAAA,IAC3C;AAAA,EACF,OAAO;AACL,QAAI,aAAa,SAAS,UAAU;AAClC,qBAAe;AAAA,QACb,MAAM;AAAA,QACN,UAAU,CAAC,UAAU,YAAY,WAAW,UAAU,EAAE;AAAA,QACxD,YAAY;AAAA,UACV,OAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAcO,SAAS,aAAa,QAQ1B;AACD,QAAM,YAAY,oBAAI,IAAoB;AAC1C,QAAM,mBAA6B,CAAC;AACpC,QAAM,iBAAiB,IAAI,WAAW,OAAO,MAAM,CAAC,OAAO,WAAW;AACpE,cAAU,IAAI,OAAO,MAAM;AAC3B,qBAAiB,KAAK;AAAA,MACpB,eAAe;AAAA,MACf,YAAY;AAAA,MACZ,iBAAiB,KAAK,OAAO,WAAW,KAAK,CAAC;AAAA,MAC9C,cAAc,CAAC,EAAE,YAAY,MAAM,MAAM,MAAM,CAAC;AAAA,MAChD,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d,IACA,WACA,MACA;AACA,QAAM,EAAE,cAAc,aAAa,UAAU,IAAI;AAAA,IAC/C;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,QAAM,uBAAwD,CAAC;AAC/D,aAAW,CAAC,MAAM,IAAI,KAAK,OAAO,QAAQ,WAAW,GAAG;AACtD,yBAAqB,IAAI,IAAI;AAAA,MAC3B;AAAA,MACA,UAAU,WAAW,SAAS,IAAI;AAAA,MAClC,QAAQ;AAAA,MACR,IAAI,KAAK,MAAM;AAAA,IACjB;AAAA,EACF;AAEA,SAAO,MAAM,CAAC,GAAG,cAAc;AAAA,IAC7B,UAAU,OAAO,OAAO,oBAAoB,EACzC,OAAO,CAAC,MAAM,EAAE,QAAQ,EACxB,IAAI,CAAC,MAAM,EAAE,IAAI;AAAA,IACpB,YAAY,OAAO,QAAQ,oBAAoB,EAAE;AAAA,MAC/C,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,CAAC,EAAE,IAAI,GAAG,EAAE,OAAO;AAAA,MAC9C,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AACH;",
6
- "names": []
7
- }
@@ -1,56 +0,0 @@
1
- import { removeDuplicates } from "@sdk-it/core";
2
- function mergeImports(...imports) {
3
- const merged = {};
4
- for (const it of imports) {
5
- merged[it.moduleSpecifier] = merged[it.moduleSpecifier] ?? {
6
- moduleSpecifier: it.moduleSpecifier,
7
- defaultImport: it.defaultImport,
8
- namespaceImport: it.namespaceImport,
9
- namedImports: []
10
- };
11
- for (const named of it.namedImports) {
12
- if (!merged[it.moduleSpecifier].namedImports.some(
13
- (x) => x.name === named.name
14
- )) {
15
- merged[it.moduleSpecifier].namedImports.push(named);
16
- }
17
- }
18
- }
19
- return Object.values(merged);
20
- }
21
- function importsToString(...imports) {
22
- return imports.map((it) => {
23
- if (it.defaultImport) {
24
- return `import ${it.defaultImport} from '${it.moduleSpecifier}'`;
25
- }
26
- if (it.namespaceImport) {
27
- return `import * as ${it.namespaceImport} from '${it.moduleSpecifier}'`;
28
- }
29
- if (it.namedImports) {
30
- return `import {${removeDuplicates(it.namedImports, (it2) => it2.name).map((n) => `${n.isTypeOnly ? "type" : ""} ${n.name}`).join(", ")}} from '${it.moduleSpecifier}'`;
31
- }
32
- throw new Error(`Invalid import ${JSON.stringify(it)}`);
33
- });
34
- }
35
- function useImports(content, ...imports) {
36
- const output = [];
37
- for (const it of mergeImports(...imports)) {
38
- const singleImport = it.defaultImport ?? it.namespaceImport;
39
- if (singleImport && content.includes(singleImport)) {
40
- output.push(importsToString(it).join("\n"));
41
- } else if (it.namedImports.length) {
42
- for (const namedImport of it.namedImports) {
43
- if (content.includes(namedImport.name)) {
44
- output.push(importsToString(it).join("\n"));
45
- }
46
- }
47
- }
48
- }
49
- return output;
50
- }
51
- export {
52
- importsToString,
53
- mergeImports,
54
- useImports
55
- };
56
- //# sourceMappingURL=import-utilities.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/lib/import-utilities.ts"],
4
- "sourcesContent": ["import { removeDuplicates } from '@sdk-it/core';\n\nexport function mergeImports(...imports: Import[]) {\n const merged: Record<string, Import> = {};\n\n for (const it of imports) {\n merged[it.moduleSpecifier] = merged[it.moduleSpecifier] ?? {\n moduleSpecifier: it.moduleSpecifier,\n defaultImport: it.defaultImport,\n namespaceImport: it.namespaceImport,\n namedImports: [],\n };\n for (const named of it.namedImports) {\n if (\n !merged[it.moduleSpecifier].namedImports.some(\n (x) => x.name === named.name,\n )\n ) {\n merged[it.moduleSpecifier].namedImports.push(named);\n }\n }\n }\n\n return Object.values(merged);\n}\n\nexport interface Import {\n isTypeOnly?: boolean;\n moduleSpecifier: string;\n defaultImport?: string | undefined;\n namedImports: NamedImport[];\n namespaceImport?: string | undefined;\n}\nexport interface NamedImport {\n name: string;\n alias?: string;\n isTypeOnly?: boolean;\n}\n\nexport function importsToString(...imports: Import[]) {\n return imports.map((it) => {\n if (it.defaultImport) {\n return `import ${it.defaultImport} from '${it.moduleSpecifier}'`;\n }\n if (it.namespaceImport) {\n return `import * as ${it.namespaceImport} from '${it.moduleSpecifier}'`;\n }\n if (it.namedImports) {\n return `import {${removeDuplicates(it.namedImports, (it) => it.name)\n .map((n) => `${n.isTypeOnly ? 'type' : ''} ${n.name}`)\n .join(', ')}} from '${it.moduleSpecifier}'`;\n }\n throw new Error(`Invalid import ${JSON.stringify(it)}`);\n });\n}\n\nexport function useImports(content: string, ...imports: Import[]) {\n const output: string[] = [];\n for (const it of mergeImports(...imports)) {\n const singleImport = it.defaultImport ?? it.namespaceImport;\n if (singleImport && content.includes(singleImport)) {\n output.push(importsToString(it).join('\\n'));\n } else if (it.namedImports.length) {\n for (const namedImport of it.namedImports) {\n if (content.includes(namedImport.name)) {\n output.push(importsToString(it).join('\\n'));\n }\n }\n }\n }\n return output;\n}\n\nexport type MakeImportFn = (moduleSpecifier: string) => string;\n"],
5
- "mappings": "AAAA,SAAS,wBAAwB;AAE1B,SAAS,gBAAgB,SAAmB;AACjD,QAAM,SAAiC,CAAC;AAExC,aAAW,MAAM,SAAS;AACxB,WAAO,GAAG,eAAe,IAAI,OAAO,GAAG,eAAe,KAAK;AAAA,MACzD,iBAAiB,GAAG;AAAA,MACpB,eAAe,GAAG;AAAA,MAClB,iBAAiB,GAAG;AAAA,MACpB,cAAc,CAAC;AAAA,IACjB;AACA,eAAW,SAAS,GAAG,cAAc;AACnC,UACE,CAAC,OAAO,GAAG,eAAe,EAAE,aAAa;AAAA,QACvC,CAAC,MAAM,EAAE,SAAS,MAAM;AAAA,MAC1B,GACA;AACA,eAAO,GAAG,eAAe,EAAE,aAAa,KAAK,KAAK;AAAA,MACpD;AAAA,IACF;AAAA,EACF;AAEA,SAAO,OAAO,OAAO,MAAM;AAC7B;AAeO,SAAS,mBAAmB,SAAmB;AACpD,SAAO,QAAQ,IAAI,CAAC,OAAO;AACzB,QAAI,GAAG,eAAe;AACpB,aAAO,UAAU,GAAG,aAAa,UAAU,GAAG,eAAe;AAAA,IAC/D;AACA,QAAI,GAAG,iBAAiB;AACtB,aAAO,eAAe,GAAG,eAAe,UAAU,GAAG,eAAe;AAAA,IACtE;AACA,QAAI,GAAG,cAAc;AACnB,aAAO,WAAW,iBAAiB,GAAG,cAAc,CAACA,QAAOA,IAAG,IAAI,EAChE,IAAI,CAAC,MAAM,GAAG,EAAE,aAAa,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,EACpD,KAAK,IAAI,CAAC,WAAW,GAAG,eAAe;AAAA,IAC5C;AACA,UAAM,IAAI,MAAM,kBAAkB,KAAK,UAAU,EAAE,CAAC,EAAE;AAAA,EACxD,CAAC;AACH;AAEO,SAAS,WAAW,YAAoB,SAAmB;AAChE,QAAM,SAAmB,CAAC;AAC1B,aAAW,MAAM,aAAa,GAAG,OAAO,GAAG;AACzC,UAAM,eAAe,GAAG,iBAAiB,GAAG;AAC5C,QAAI,gBAAgB,QAAQ,SAAS,YAAY,GAAG;AAClD,aAAO,KAAK,gBAAgB,EAAE,EAAE,KAAK,IAAI,CAAC;AAAA,IAC5C,WAAW,GAAG,aAAa,QAAQ;AACjC,iBAAW,eAAe,GAAG,cAAc;AACzC,YAAI,QAAQ,SAAS,YAAY,IAAI,GAAG;AACtC,iBAAO,KAAK,gBAAgB,EAAE,EAAE,KAAK,IAAI,CAAC;AAAA,QAC5C;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;",
6
- "names": ["it"]
7
- }
@@ -1,3 +0,0 @@
1
- import { npmRunPathEnv } from "npm-run-path";
2
- import {} from "@sdk-it/core/file-system.js";
3
- //# sourceMappingURL=options.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/lib/options.ts"],
4
- "sourcesContent": ["import { npmRunPathEnv } from 'npm-run-path';\n\nimport { type ReadFolderFn, type Writer } from '@sdk-it/core/file-system.js';\nimport type { PaginationConfig } from '@sdk-it/spec';\n\nimport type { Style } from './style.ts';\n\nexport interface TypeScriptGeneratorOptions {\n agentTools?: 'ai-sdk' | 'openai-agents';\n readme?: boolean | string;\n style?: Style;\n output: string;\n useTsExtension?: boolean;\n name?: string;\n pagination?: PaginationConfig | false;\n writer?: Writer;\n readFolder?: ReadFolderFn;\n /**\n * full: generate a full project including package.json and tsconfig.json. useful for monorepo/workspaces\n * minimal: generate only the client sdk\n */\n mode?: 'full' | 'minimal';\n formatCode?: (options: {\n output: string;\n env: ReturnType<typeof npmRunPathEnv>;\n }) => void | Promise<void>;\n /**\n * Whether to remove files that were previously generated but no longer needed\n * @default true\n */\n cleanup?: boolean;\n}\n"],
5
- "mappings": "AAAA,SAAS,qBAAqB;AAE9B,eAA+C;",
6
- "names": []
7
- }
@@ -1,283 +0,0 @@
1
- import { followRef, isRef } from "@sdk-it/core";
2
- import { coerceTypes } from "@sdk-it/spec";
3
- class PropEmitter {
4
- #spec;
5
- constructor(spec) {
6
- this.#spec = spec;
7
- }
8
- /**
9
- * Handle objects (properties)
10
- */
11
- #object(schema) {
12
- const lines = [];
13
- const properties = schema.properties || {};
14
- if (Object.keys(properties).length > 0) {
15
- lines.push(`**Properties:**`);
16
- for (const [propName, propSchema] of Object.entries(properties)) {
17
- const isRequired = (schema.required ?? []).includes(propName);
18
- lines.push(...this.#property(propName, propSchema, isRequired));
19
- }
20
- }
21
- if (schema.additionalProperties) {
22
- lines.push(`**Additional Properties:**`);
23
- if (typeof schema.additionalProperties === "boolean") {
24
- lines.push(`- Allowed: ${schema.additionalProperties}`);
25
- } else {
26
- lines.push(
27
- ...this.handle(schema.additionalProperties).map((l) => ` ${l}`)
28
- );
29
- }
30
- }
31
- return lines;
32
- }
33
- /**
34
- * Format a property with its type and description
35
- */
36
- #property(name, schema, required) {
37
- const docs = this.handle(schema);
38
- const rawType = docs[0].replace("**Type:** ", "").replace(" (nullable)", "|null");
39
- const defaultVal = !isRef(schema) && schema.default !== void 0 ? ` default: ${JSON.stringify(schema.default)}` : "";
40
- const reqMark = required ? " required" : "";
41
- const summary = `- \`${name}\` ${rawType}${reqMark}${defaultVal}:`;
42
- const detailLines = docs.slice(1).filter((it) => !it.startsWith("**Default:**")).map((it) => ` ${it}`);
43
- return [summary, ...detailLines];
44
- }
45
- /**
46
- * Handle array schemas
47
- */
48
- #array(schema) {
49
- const lines = [];
50
- lines.push(`**Array items:**`);
51
- if (schema.items) {
52
- const itemDocs = this.handle(schema.items);
53
- lines.push(...itemDocs.map((line) => ` ${line}`));
54
- } else {
55
- lines.push(` **Type:** \`unknown\``);
56
- }
57
- if (schema.minItems !== void 0)
58
- lines.push(`- Minimum items: ${schema.minItems}`);
59
- if (schema.maxItems !== void 0)
60
- lines.push(`- Maximum items: ${schema.maxItems}`);
61
- if (schema.uniqueItems) lines.push(`- Items must be unique.`);
62
- return lines;
63
- }
64
- #ref($ref) {
65
- const schemaName = $ref.split("/").pop() || "object";
66
- const resolved = followRef(this.#spec, $ref);
67
- const lines = [
68
- `**Type:** [\`${schemaName}\`](#${schemaName.toLowerCase()})`
69
- ];
70
- if (resolved.description) {
71
- lines.push(resolved.description);
72
- }
73
- return lines;
74
- }
75
- #allOf(schemas) {
76
- const lines = ["**All of (Intersection):**"];
77
- schemas.forEach((subSchema, index) => {
78
- lines.push(`- **Constraint ${index + 1}:**`);
79
- const subLines = this.handle(subSchema);
80
- lines.push(...subLines.map((l) => ` ${l}`));
81
- });
82
- return lines;
83
- }
84
- #anyOf(schemas) {
85
- const lines = ["**Any of (Union):**"];
86
- schemas.forEach((subSchema, index) => {
87
- lines.push(`- **Option ${index + 1}:**`);
88
- const subLines = this.handle(subSchema);
89
- lines.push(...subLines.map((l) => ` ${l}`));
90
- });
91
- return lines;
92
- }
93
- #oneOf(schemas) {
94
- const lines = ["**One of (Exclusive Union):**"];
95
- schemas.forEach((subSchema, index) => {
96
- lines.push(`- **Option ${index + 1}:**`);
97
- const subLines = this.handle(subSchema);
98
- lines.push(...subLines.map((l) => ` ${l}`));
99
- });
100
- return lines;
101
- }
102
- #enum(schema) {
103
- const lines = [`**Type:** \`${schema.type || "unknown"}\` (enum)`];
104
- if (schema.description) lines.push(schema.description);
105
- lines.push("**Allowed values:**");
106
- lines.push(
107
- ...(schema.enum || []).map((val) => `- \`${JSON.stringify(val)}\``)
108
- );
109
- if (schema.default !== void 0) {
110
- lines.push(`**Default:** \`${JSON.stringify(schema.default)}\``);
111
- }
112
- return lines;
113
- }
114
- #normal(type, schema, nullable) {
115
- const lines = [];
116
- const nullableSuffix = nullable ? " (nullable)" : "";
117
- const description = schema.description ? [schema.description] : [];
118
- switch (type) {
119
- case "string":
120
- lines.push(
121
- `**Type:** \`string\`${schema.format ? ` (format: ${schema.format})` : ""}${nullableSuffix}`
122
- );
123
- lines.push(...description);
124
- if (schema.minLength !== void 0)
125
- lines.push(`- Minimum length: ${schema.minLength}`);
126
- if (schema.maxLength !== void 0)
127
- lines.push(`- Maximum length: ${schema.maxLength}`);
128
- if (schema.pattern !== void 0)
129
- lines.push(`- Pattern: \`${schema.pattern}\``);
130
- break;
131
- case "number":
132
- case "integer":
133
- lines.push(
134
- `**Type:** \`${type}\`${schema.format ? ` (format: ${schema.format})` : ""}${nullableSuffix}`
135
- );
136
- lines.push(...description);
137
- if (schema.minimum !== void 0) {
138
- const exclusiveMin = typeof schema.exclusiveMinimum === "number";
139
- lines.push(
140
- `- Minimum: ${schema.minimum}${exclusiveMin ? " (exclusive)" : ""}`
141
- );
142
- if (exclusiveMin) {
143
- lines.push(
144
- `- Must be strictly greater than: ${schema.exclusiveMinimum}`
145
- );
146
- }
147
- } else if (typeof schema.exclusiveMinimum === "number") {
148
- lines.push(
149
- `- Must be strictly greater than: ${schema.exclusiveMinimum}`
150
- );
151
- }
152
- if (schema.maximum !== void 0) {
153
- const exclusiveMax = typeof schema.exclusiveMaximum === "number";
154
- lines.push(
155
- `- Maximum: ${schema.maximum}${exclusiveMax ? " (exclusive)" : ""}`
156
- );
157
- if (exclusiveMax) {
158
- lines.push(
159
- `- Must be strictly less than: ${schema.exclusiveMaximum}`
160
- );
161
- }
162
- } else if (typeof schema.exclusiveMaximum === "number") {
163
- lines.push(
164
- `- Must be strictly less than: ${schema.exclusiveMaximum}`
165
- );
166
- }
167
- if (schema.multipleOf !== void 0)
168
- lines.push(`- Must be a multiple of: ${schema.multipleOf}`);
169
- break;
170
- case "boolean":
171
- lines.push(`**Type:** \`boolean\`${nullableSuffix}`);
172
- lines.push(...description);
173
- break;
174
- case "object":
175
- lines.push(`**Type:** \`object\`${nullableSuffix}`);
176
- lines.push(...description);
177
- lines.push(...this.#object(schema));
178
- break;
179
- case "array":
180
- lines.push(`**Type:** \`array\`${nullableSuffix}`);
181
- lines.push(...description);
182
- lines.push(...this.#array(schema));
183
- break;
184
- case "null":
185
- lines.push(`**Type:** \`null\``);
186
- lines.push(...description);
187
- break;
188
- default:
189
- lines.push(`**Type:** \`${type}\`${nullableSuffix}`);
190
- lines.push(...description);
191
- }
192
- if (schema.default !== void 0) {
193
- lines.push(`**Default:** \`${JSON.stringify(schema.default)}\``);
194
- }
195
- return lines.filter((l) => l);
196
- }
197
- /**
198
- * Handle schemas by resolving references and delegating to appropriate handler
199
- */
200
- handle(schemaOrRef) {
201
- if (isRef(schemaOrRef)) {
202
- return this.#ref(schemaOrRef.$ref);
203
- }
204
- const schema = schemaOrRef;
205
- if (schema.allOf && Array.isArray(schema.allOf)) {
206
- return this.#allOf(schema.allOf);
207
- }
208
- if (schema.anyOf && Array.isArray(schema.anyOf)) {
209
- return this.#anyOf(schema.anyOf);
210
- }
211
- if (schema.oneOf && Array.isArray(schema.oneOf)) {
212
- return this.#oneOf(schema.oneOf);
213
- }
214
- if (schema.enum && Array.isArray(schema.enum)) {
215
- return this.#enum(schema);
216
- }
217
- let types = coerceTypes(schema);
218
- let nullable = false;
219
- if (types.includes("null")) {
220
- nullable = true;
221
- types = types.filter((t) => t !== "null");
222
- }
223
- if (types.length === 0) {
224
- if (schema.properties || schema.additionalProperties) {
225
- types = ["object"];
226
- } else if (schema.items) {
227
- types = ["array"];
228
- }
229
- }
230
- if (types.length === 0) {
231
- const lines2 = ["**Type:** `unknown`"];
232
- if (schema.description) lines2.push(schema.description);
233
- if (schema.default !== void 0)
234
- lines2.push(`**Default:** \`${JSON.stringify(schema.default)}\``);
235
- return lines2;
236
- }
237
- if (types.length === 1) {
238
- return this.#normal(types[0], schema, nullable);
239
- }
240
- const typeString = types.join(" | ");
241
- const nullableSuffix = nullable ? " (nullable)" : "";
242
- const lines = [`**Type:** \`${typeString}\`${nullableSuffix}`];
243
- if (schema.description) lines.push(schema.description);
244
- if (schema.default !== void 0)
245
- lines.push(`**Default:** \`${JSON.stringify(schema.default)}\``);
246
- return lines;
247
- }
248
- /**
249
- * Process a request body and return markdown documentation
250
- */
251
- requestBody(requestBody) {
252
- const lines = [];
253
- lines.push(`#### Input`);
254
- lines.push(requestBody.description || "");
255
- const contentEntries = Object.entries(requestBody.content);
256
- const multipleContentTypes = contentEntries.length > 1;
257
- if (multipleContentTypes) {
258
- for (const [contentType, mediaType] of contentEntries) {
259
- lines.push(`<details>`);
260
- lines.push(`<summary>Content Type: \`${contentType}\`</summary>`);
261
- lines.push("");
262
- if (mediaType.schema) {
263
- const schemaDocs = this.handle(mediaType.schema);
264
- lines.push(...schemaDocs.map((l) => l));
265
- }
266
- lines.push("");
267
- lines.push(`</details>`);
268
- }
269
- } else {
270
- const [contentType, mediaType] = contentEntries[0];
271
- lines.push(`Content Type: \`${contentType}\``);
272
- if (mediaType.schema) {
273
- const schemaDocs = this.handle(mediaType.schema);
274
- lines.push(...schemaDocs);
275
- }
276
- }
277
- return lines;
278
- }
279
- }
280
- export {
281
- PropEmitter
282
- };
283
- //# sourceMappingURL=prop.emitter.js.map