@jutsustack/api-codegen 0.0.0-stage → 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.
Files changed (240) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +764 -2
  3. package/bin/jutsu-api.js +14 -0
  4. package/dist/cache/manifest.d.ts +35 -0
  5. package/dist/cache/manifest.d.ts.map +1 -0
  6. package/dist/cache/manifest.js +37 -0
  7. package/dist/cache/manifest.js.map +1 -0
  8. package/dist/cjs/cache/manifest.d.ts +34 -0
  9. package/dist/cjs/cache/manifest.js +45 -0
  10. package/dist/cjs/cli.d.ts +8 -0
  11. package/dist/cjs/cli.js +245 -0
  12. package/dist/cjs/codegen/emit-api.d.ts +6 -0
  13. package/dist/cjs/codegen/emit-api.js +108 -0
  14. package/dist/cjs/codegen/emit-bindings.d.ts +8 -0
  15. package/dist/cjs/codegen/emit-bindings.js +115 -0
  16. package/dist/cjs/codegen/emit-types.d.ts +10 -0
  17. package/dist/cjs/codegen/emit-types.js +232 -0
  18. package/dist/cjs/codegen/emit.d.ts +28 -0
  19. package/dist/cjs/codegen/emit.js +180 -0
  20. package/dist/cjs/codegen/files.d.ts +14 -0
  21. package/dist/cjs/codegen/files.js +66 -0
  22. package/dist/cjs/codegen/plan.d.ts +32 -0
  23. package/dist/cjs/codegen/plan.js +84 -0
  24. package/dist/cjs/codegen/print.d.ts +10 -0
  25. package/dist/cjs/codegen/print.js +65 -0
  26. package/dist/cjs/codegen/templates/bindings.d.ts +13 -0
  27. package/dist/cjs/codegen/templates/bindings.js +707 -0
  28. package/dist/cjs/codegen/templates/runtime.d.ts +2 -0
  29. package/dist/cjs/codegen/templates/runtime.js +1401 -0
  30. package/dist/cjs/codegen/templates/transports.d.ts +1 -0
  31. package/dist/cjs/codegen/templates/transports.js +272 -0
  32. package/dist/cjs/codegen/tsType.d.ts +15 -0
  33. package/dist/cjs/codegen/tsType.js +114 -0
  34. package/dist/cjs/collect/collect.d.ts +16 -0
  35. package/dist/cjs/collect/collect.js +472 -0
  36. package/dist/cjs/collect/naming.d.ts +25 -0
  37. package/dist/cjs/collect/naming.js +149 -0
  38. package/dist/cjs/collect/path.d.ts +10 -0
  39. package/dist/cjs/collect/path.js +67 -0
  40. package/dist/cjs/config/init.d.ts +37 -0
  41. package/dist/cjs/config/init.js +143 -0
  42. package/dist/cjs/config/load.d.ts +11 -0
  43. package/dist/cjs/config/load.js +121 -0
  44. package/dist/cjs/config/types.d.ts +88 -0
  45. package/dist/cjs/config/types.js +2 -0
  46. package/dist/cjs/config/validate.d.ts +8 -0
  47. package/dist/cjs/config/validate.js +200 -0
  48. package/dist/cjs/generate.d.ts +55 -0
  49. package/dist/cjs/generate.js +263 -0
  50. package/dist/cjs/index.d.ts +23 -0
  51. package/dist/cjs/index.js +48 -0
  52. package/dist/cjs/model/collection.d.ts +83 -0
  53. package/dist/cjs/model/collection.js +16 -0
  54. package/dist/cjs/model/infer.d.ts +7 -0
  55. package/dist/cjs/model/infer.js +95 -0
  56. package/dist/cjs/model/merge.d.ts +3 -0
  57. package/dist/cjs/model/merge.js +131 -0
  58. package/dist/cjs/model/reserved.d.ts +2 -0
  59. package/dist/cjs/model/reserved.js +128 -0
  60. package/dist/cjs/model/schema.d.ts +54 -0
  61. package/dist/cjs/model/schema.js +2 -0
  62. package/dist/cjs/package.json +1 -0
  63. package/dist/cjs/parsers/openapi-schema.d.ts +30 -0
  64. package/dist/cjs/parsers/openapi-schema.js +241 -0
  65. package/dist/cjs/parsers/openapi.d.ts +8 -0
  66. package/dist/cjs/parsers/openapi.js +435 -0
  67. package/dist/cjs/parsers/postman.d.ts +20 -0
  68. package/dist/cjs/parsers/postman.js +493 -0
  69. package/dist/cjs/parsers/types.d.ts +52 -0
  70. package/dist/cjs/parsers/types.js +2 -0
  71. package/dist/cjs/sources/load.d.ts +25 -0
  72. package/dist/cjs/sources/load.js +296 -0
  73. package/dist/cjs/sources/parse.d.ts +4 -0
  74. package/dist/cjs/sources/parse.js +50 -0
  75. package/dist/cjs/util/errors.d.ts +9 -0
  76. package/dist/cjs/util/errors.js +23 -0
  77. package/dist/cjs/util/fs.d.ts +7 -0
  78. package/dist/cjs/util/fs.js +44 -0
  79. package/dist/cjs/util/hash.d.ts +3 -0
  80. package/dist/cjs/util/hash.js +26 -0
  81. package/dist/cjs/util/json.d.ts +10 -0
  82. package/dist/cjs/util/json.js +31 -0
  83. package/dist/cjs/util/log.d.ts +22 -0
  84. package/dist/cjs/util/log.js +45 -0
  85. package/dist/cjs/version.d.ts +2 -0
  86. package/dist/cjs/version.js +6 -0
  87. package/dist/cli.d.ts +9 -0
  88. package/dist/cli.d.ts.map +1 -0
  89. package/dist/cli.js +238 -0
  90. package/dist/cli.js.map +1 -0
  91. package/dist/codegen/emit-api.d.ts +7 -0
  92. package/dist/codegen/emit-api.d.ts.map +1 -0
  93. package/dist/codegen/emit-api.js +105 -0
  94. package/dist/codegen/emit-api.js.map +1 -0
  95. package/dist/codegen/emit-bindings.d.ts +9 -0
  96. package/dist/codegen/emit-bindings.d.ts.map +1 -0
  97. package/dist/codegen/emit-bindings.js +112 -0
  98. package/dist/codegen/emit-bindings.js.map +1 -0
  99. package/dist/codegen/emit-types.d.ts +11 -0
  100. package/dist/codegen/emit-types.d.ts.map +1 -0
  101. package/dist/codegen/emit-types.js +230 -0
  102. package/dist/codegen/emit-types.js.map +1 -0
  103. package/dist/codegen/emit.d.ts +29 -0
  104. package/dist/codegen/emit.d.ts.map +1 -0
  105. package/dist/codegen/emit.js +177 -0
  106. package/dist/codegen/emit.js.map +1 -0
  107. package/dist/codegen/files.d.ts +15 -0
  108. package/dist/codegen/files.d.ts.map +1 -0
  109. package/dist/codegen/files.js +57 -0
  110. package/dist/codegen/files.js.map +1 -0
  111. package/dist/codegen/plan.d.ts +33 -0
  112. package/dist/codegen/plan.d.ts.map +1 -0
  113. package/dist/codegen/plan.js +79 -0
  114. package/dist/codegen/plan.js.map +1 -0
  115. package/dist/codegen/print.d.ts +11 -0
  116. package/dist/codegen/print.d.ts.map +1 -0
  117. package/dist/codegen/print.js +59 -0
  118. package/dist/codegen/print.js.map +1 -0
  119. package/dist/codegen/templates/bindings.d.ts +14 -0
  120. package/dist/codegen/templates/bindings.d.ts.map +1 -0
  121. package/dist/codegen/templates/bindings.js +705 -0
  122. package/dist/codegen/templates/bindings.js.map +1 -0
  123. package/dist/codegen/templates/runtime.d.ts +3 -0
  124. package/dist/codegen/templates/runtime.d.ts.map +1 -0
  125. package/dist/codegen/templates/runtime.js +1398 -0
  126. package/dist/codegen/templates/runtime.js.map +1 -0
  127. package/dist/codegen/templates/transports.d.ts +2 -0
  128. package/dist/codegen/templates/transports.d.ts.map +1 -0
  129. package/dist/codegen/templates/transports.js +270 -0
  130. package/dist/codegen/templates/transports.js.map +1 -0
  131. package/dist/codegen/tsType.d.ts +16 -0
  132. package/dist/codegen/tsType.d.ts.map +1 -0
  133. package/dist/codegen/tsType.js +111 -0
  134. package/dist/codegen/tsType.js.map +1 -0
  135. package/dist/collect/collect.d.ts +17 -0
  136. package/dist/collect/collect.d.ts.map +1 -0
  137. package/dist/collect/collect.js +469 -0
  138. package/dist/collect/collect.js.map +1 -0
  139. package/dist/collect/naming.d.ts +26 -0
  140. package/dist/collect/naming.d.ts.map +1 -0
  141. package/dist/collect/naming.js +137 -0
  142. package/dist/collect/naming.js.map +1 -0
  143. package/dist/collect/path.d.ts +11 -0
  144. package/dist/collect/path.d.ts.map +1 -0
  145. package/dist/collect/path.js +62 -0
  146. package/dist/collect/path.js.map +1 -0
  147. package/dist/config/init.d.ts +38 -0
  148. package/dist/config/init.d.ts.map +1 -0
  149. package/dist/config/init.js +134 -0
  150. package/dist/config/init.js.map +1 -0
  151. package/dist/config/load.d.ts +12 -0
  152. package/dist/config/load.d.ts.map +1 -0
  153. package/dist/config/load.js +112 -0
  154. package/dist/config/load.js.map +1 -0
  155. package/dist/config/types.d.ts +89 -0
  156. package/dist/config/types.d.ts.map +1 -0
  157. package/dist/config/types.js +2 -0
  158. package/dist/config/types.js.map +1 -0
  159. package/dist/config/validate.d.ts +9 -0
  160. package/dist/config/validate.d.ts.map +1 -0
  161. package/dist/config/validate.js +196 -0
  162. package/dist/config/validate.js.map +1 -0
  163. package/dist/generate.d.ts +56 -0
  164. package/dist/generate.d.ts.map +1 -0
  165. package/dist/generate.js +255 -0
  166. package/dist/generate.js.map +1 -0
  167. package/dist/index.d.ts +24 -0
  168. package/dist/index.d.ts.map +1 -0
  169. package/dist/index.js +15 -0
  170. package/dist/index.js.map +1 -0
  171. package/dist/model/collection.d.ts +84 -0
  172. package/dist/model/collection.d.ts.map +1 -0
  173. package/dist/model/collection.js +13 -0
  174. package/dist/model/collection.js.map +1 -0
  175. package/dist/model/infer.d.ts +8 -0
  176. package/dist/model/infer.d.ts.map +1 -0
  177. package/dist/model/infer.js +91 -0
  178. package/dist/model/infer.js.map +1 -0
  179. package/dist/model/merge.d.ts +4 -0
  180. package/dist/model/merge.d.ts.map +1 -0
  181. package/dist/model/merge.js +129 -0
  182. package/dist/model/merge.js.map +1 -0
  183. package/dist/model/reserved.d.ts +3 -0
  184. package/dist/model/reserved.d.ts.map +1 -0
  185. package/dist/model/reserved.js +126 -0
  186. package/dist/model/reserved.js.map +1 -0
  187. package/dist/model/schema.d.ts +55 -0
  188. package/dist/model/schema.d.ts.map +1 -0
  189. package/dist/model/schema.js +2 -0
  190. package/dist/model/schema.js.map +1 -0
  191. package/dist/parsers/openapi-schema.d.ts +31 -0
  192. package/dist/parsers/openapi-schema.d.ts.map +1 -0
  193. package/dist/parsers/openapi-schema.js +238 -0
  194. package/dist/parsers/openapi-schema.js.map +1 -0
  195. package/dist/parsers/openapi.d.ts +9 -0
  196. package/dist/parsers/openapi.d.ts.map +1 -0
  197. package/dist/parsers/openapi.js +432 -0
  198. package/dist/parsers/openapi.js.map +1 -0
  199. package/dist/parsers/postman.d.ts +21 -0
  200. package/dist/parsers/postman.d.ts.map +1 -0
  201. package/dist/parsers/postman.js +488 -0
  202. package/dist/parsers/postman.js.map +1 -0
  203. package/dist/parsers/types.d.ts +53 -0
  204. package/dist/parsers/types.d.ts.map +1 -0
  205. package/dist/parsers/types.js +2 -0
  206. package/dist/parsers/types.js.map +1 -0
  207. package/dist/sources/load.d.ts +26 -0
  208. package/dist/sources/load.d.ts.map +1 -0
  209. package/dist/sources/load.js +291 -0
  210. package/dist/sources/load.js.map +1 -0
  211. package/dist/sources/parse.d.ts +5 -0
  212. package/dist/sources/parse.d.ts.map +1 -0
  213. package/dist/sources/parse.js +48 -0
  214. package/dist/sources/parse.js.map +1 -0
  215. package/dist/util/errors.d.ts +10 -0
  216. package/dist/util/errors.d.ts.map +1 -0
  217. package/dist/util/errors.js +18 -0
  218. package/dist/util/errors.js.map +1 -0
  219. package/dist/util/fs.d.ts +8 -0
  220. package/dist/util/fs.d.ts.map +1 -0
  221. package/dist/util/fs.js +36 -0
  222. package/dist/util/fs.js.map +1 -0
  223. package/dist/util/hash.d.ts +4 -0
  224. package/dist/util/hash.d.ts.map +1 -0
  225. package/dist/util/hash.js +23 -0
  226. package/dist/util/hash.js.map +1 -0
  227. package/dist/util/json.d.ts +11 -0
  228. package/dist/util/json.d.ts.map +1 -0
  229. package/dist/util/json.js +24 -0
  230. package/dist/util/json.js.map +1 -0
  231. package/dist/util/log.d.ts +23 -0
  232. package/dist/util/log.d.ts.map +1 -0
  233. package/dist/util/log.js +42 -0
  234. package/dist/util/log.js.map +1 -0
  235. package/dist/version.d.ts +3 -0
  236. package/dist/version.d.ts.map +1 -0
  237. package/dist/version.js +4 -0
  238. package/dist/version.js.map +1 -0
  239. package/package.json +117 -4
  240. package/schema/config.schema.json +182 -0
@@ -0,0 +1 @@
1
+ export declare const TRANSPORTS: string;
@@ -0,0 +1,272 @@
1
+ "use strict";
2
+ // HTTP-library adapters, appended to the generated runtime.ts. Typed structurally, so the
3
+ // generated code imports no HTTP library. Same String.raw rules as runtime.ts.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.TRANSPORTS = void 0;
6
+ exports.TRANSPORTS = String.raw `// ─── HTTP library: pass it as createClient({ http }) ─────────────────────────
7
+
8
+ /** fetch, an axios instance, Angular's HttpClient or a react-native-fetch client. */
9
+ export type HttpLibrary = typeof fetch | AxiosLike | AngularHttpClientLike | ReactNativeFetchLike;
10
+
11
+ /** The transport for an HTTP library, recognised by its shape; undefined means globalThis.fetch. */
12
+ export function toTransport(http?: HttpLibrary): Transport {
13
+ if (http === undefined) return fetchTransport();
14
+ const lib = http as unknown as { request?: unknown; interceptors?: unknown; jsonp?: unknown };
15
+ if (typeof lib.request === 'function') {
16
+ if (lib.interceptors !== null && typeof lib.interceptors === 'object') return axiosTransport(http as AxiosLike);
17
+ if (typeof lib.jsonp === 'function') return angularHttpTransport(http as AngularHttpClientLike);
18
+ return reactNativeFetchTransport(http as ReactNativeFetchLike);
19
+ }
20
+ if (typeof http === 'function') return fetchTransport({ fetch: http as typeof fetch });
21
+ throw new TypeError(
22
+ 'createClient: "http" must be fetch, an axios instance, Angular HttpClient or a react-native-fetch client; ' +
23
+ 'for anything else pass your own function as "transport"'
24
+ );
25
+ }
26
+
27
+ // ─── fetch (browser, Node 18+, Deno, Bun, edge, React Native) ───────────────
28
+
29
+ export interface FetchTransportConfig {
30
+ /** default globalThis.fetch */
31
+ fetch?: typeof fetch;
32
+ /** fetch() options for every call (credentials, cache, …) */
33
+ init?: FetchInit;
34
+ }
35
+
36
+ export function fetchTransport(config: FetchTransportConfig = {}): Transport {
37
+ return async (request) => {
38
+ const doFetch = config.fetch ?? globalThis.fetch;
39
+ if (typeof doFetch !== 'function') {
40
+ throw new TypeError('fetchTransport: no fetch() available; pass one with fetchTransport({ fetch })');
41
+ }
42
+ const headers = { ...request.headers };
43
+ const body = encodeBody(request.body, request.contentType, headers);
44
+ const init: RequestInit & { next?: FetchInit['next'] } = {
45
+ ...config.init,
46
+ ...request.init,
47
+ ...(request.adapterOptions as RequestInit | undefined),
48
+ method: request.method,
49
+ headers,
50
+ signal: request.signal,
51
+ };
52
+ if (body !== undefined) init.body = body as Exclude<RequestInit['body'], undefined>;
53
+ const response = await doFetch(request.url, init);
54
+ const responseHeaders = headerRecord(response.headers);
55
+ let data: unknown;
56
+ try {
57
+ // a forced responseType applies to success bodies only
58
+ data = await readBody(response, request, response.ok ? request.responseType : undefined);
59
+ } catch (error) {
60
+ if (request.signal.aborted) throw error;
61
+ if (response.ok) {
62
+ throw new ApiError('PARSE', {
63
+ method: request.method,
64
+ url: request.url,
65
+ status: response.status,
66
+ headers: responseHeaders,
67
+ endpoint: request.endpoint,
68
+ originalError: error,
69
+ });
70
+ }
71
+ }
72
+ return { status: response.status, headers: responseHeaders, data, url: response.url || request.url };
73
+ };
74
+ }
75
+
76
+ async function readBody(response: Response, request: TransportRequest, responseType: ResponseKind | undefined): Promise<unknown> {
77
+ const status = response.status;
78
+ if (request.method === 'HEAD' || status === 204 || status === 205 || status === 304) return undefined;
79
+ const type = (response.headers.get('content-type') || '').toLowerCase();
80
+ const kind = responseType ?? kindOf(type);
81
+ if (kind === 'blob') return response.blob();
82
+ if (kind === 'arraybuffer') return response.arrayBuffer();
83
+ const text = await response.text();
84
+ if (kind === 'json') return text ? JSON.parse(text) : undefined;
85
+ // untyped bodies that look like JSON are parsed when possible
86
+ if (type !== '' || responseType !== undefined || !/^\s*[[{]/.test(text)) return text;
87
+ try {
88
+ return JSON.parse(text);
89
+ } catch {
90
+ return text;
91
+ }
92
+ }
93
+
94
+ function kindOf(contentType: string): ResponseKind {
95
+ if (contentType.indexOf('json') !== -1) return 'json';
96
+ const textual =
97
+ contentType === '' ||
98
+ contentType.indexOf('text/') === 0 ||
99
+ contentType.indexOf('xml') !== -1 ||
100
+ contentType.indexOf('urlencoded') !== -1;
101
+ return textual ? 'text' : 'blob';
102
+ }
103
+
104
+ // ─── axios ──────────────────────────────────────────────────────────────────
105
+
106
+ /** The part of an axios instance the transport uses (axios.create() or axios itself). */
107
+ export interface AxiosLike {
108
+ request(config: {
109
+ method: string;
110
+ url: string;
111
+ headers: Record<string, string>;
112
+ data?: unknown;
113
+ signal?: AbortSignal;
114
+ responseType?: 'json' | 'text' | 'blob' | 'arraybuffer';
115
+ validateStatus?: (status: number) => boolean;
116
+ }): Promise<{ status: number; headers: unknown; data: unknown; request?: unknown }>;
117
+ }
118
+
119
+ /** Sends through your axios instance; its interceptors and settings keep working. */
120
+ export function axiosTransport(instance: AxiosLike): Transport {
121
+ return async (request) => {
122
+ const headers = { ...request.headers };
123
+ const data = encodeBody(request.body, request.contentType, headers);
124
+ const response = await instance.request({
125
+ ...(request.adapterOptions as object | undefined),
126
+ method: request.method,
127
+ url: request.url,
128
+ headers,
129
+ ...(data !== undefined ? { data } : {}),
130
+ signal: request.signal,
131
+ ...(request.responseType ? { responseType: request.responseType } : {}),
132
+ // every status resolves; the client decides what is an error
133
+ validateStatus: () => true,
134
+ });
135
+ return { status: response.status, headers: headerRecord(response.headers), data: response.data };
136
+ };
137
+ }
138
+
139
+ // ─── @jutsustack/react-native-fetch (SSL pinning, token refresh) ────────────
140
+
141
+ /** The part of a react-native-fetch client the transport uses. */
142
+ export interface ReactNativeFetchLike {
143
+ request(
144
+ method: TransportRequest['method'],
145
+ url: string,
146
+ options?: {
147
+ body?: unknown;
148
+ headers?: Record<string, string | undefined>;
149
+ contentType?: 'json' | 'urlencoded' | 'text' | 'multipart' | 'binary';
150
+ responseType?: 'json' | 'text' | 'arraybuffer';
151
+ timeoutMs?: number;
152
+ signal?: AbortSignal;
153
+ skipAuth?: boolean;
154
+ idempotencyKey?: string;
155
+ retries?: number;
156
+ }
157
+ ): Promise<{ status: number; headers: Record<string, string>; data: unknown }>;
158
+ }
159
+
160
+ /** Sends through a createJutsuClient() client; its own retries are off. */
161
+ export function reactNativeFetchTransport(client: ReactNativeFetchLike): Transport {
162
+ return async (request) => {
163
+ const responseType = request.responseType === 'blob' ? undefined : request.responseType;
164
+ try {
165
+ const response = await client.request(request.method, request.url, {
166
+ ...(request.adapterOptions as object | undefined),
167
+ headers: request.headers,
168
+ signal: request.signal,
169
+ timeoutMs: request.timeoutMs,
170
+ skipAuth: request.skipAuth,
171
+ retries: 0,
172
+ ...(request.body !== undefined ? { body: request.body } : {}),
173
+ ...(request.contentType ? { contentType: request.contentType } : {}),
174
+ ...(responseType ? { responseType } : {}),
175
+ ...(request.idempotencyKey ? { idempotencyKey: request.idempotencyKey } : {}),
176
+ });
177
+ return { status: response.status, headers: response.headers ?? {}, data: response.data };
178
+ } catch (error) {
179
+ // react-native-fetch rejects on HTTP errors: hand back the response
180
+ const e = error as { kind?: unknown; status?: unknown; data?: unknown; headers?: unknown } | null;
181
+ if (e && e.kind === 'HTTP' && typeof e.status === 'number') {
182
+ return { status: e.status, headers: headerRecord(e.headers), data: e.data };
183
+ }
184
+ if (e && e.kind === 'PARSE') {
185
+ throw new ApiError('PARSE', { method: request.method, url: request.url, endpoint: request.endpoint, originalError: error });
186
+ }
187
+ throw error;
188
+ }
189
+ };
190
+ }
191
+
192
+ // ─── Angular HttpClient (interceptors, XSRF, testing tools) ─────────────────
193
+
194
+ interface Unsubscribable {
195
+ unsubscribe(): void;
196
+ }
197
+
198
+ interface HttpHeadersLike {
199
+ keys(): string[];
200
+ get(name: string): string | null;
201
+ }
202
+
203
+ /** The part of Angular's HttpClient the transport uses. */
204
+ export interface AngularHttpClientLike {
205
+ request(
206
+ method: string,
207
+ url: string,
208
+ options: {
209
+ body?: unknown;
210
+ headers?: Record<string, string>;
211
+ observe: 'response';
212
+ responseType: 'json' | 'text' | 'blob' | 'arraybuffer';
213
+ [option: string]: unknown;
214
+ }
215
+ ): {
216
+ subscribe(observer: {
217
+ next?: (response: { status: number; headers: HttpHeadersLike; body: unknown; url?: string | null }) => void;
218
+ error?: (error: unknown) => void;
219
+ }): Unsubscribable;
220
+ };
221
+ }
222
+
223
+ /** Sends through Angular's HttpClient; create it inside an injection context. */
224
+ export function angularHttpTransport(http: AngularHttpClientLike): Transport {
225
+ return (request) =>
226
+ new Promise<TransportResponse>((resolve, reject) => {
227
+ const headers = { ...request.headers };
228
+ const body = encodeBody(request.body, request.contentType, headers);
229
+ let settled = false;
230
+ const subscription = http
231
+ .request(request.method, request.url, {
232
+ ...request.adapterOptions,
233
+ ...(body !== undefined ? { body } : {}),
234
+ headers,
235
+ observe: 'response',
236
+ responseType: request.responseType ?? 'json',
237
+ })
238
+ .subscribe({
239
+ next: (response) => {
240
+ settled = true;
241
+ request.signal.removeEventListener('abort', onAbort);
242
+ resolve({ status: response.status, headers: angularHeaders(response.headers), data: response.body, url: response.url ?? request.url });
243
+ },
244
+ error: (error: unknown) => {
245
+ settled = true;
246
+ request.signal.removeEventListener('abort', onAbort);
247
+ // HttpErrorResponse: status 0 means no response arrived
248
+ const e = error as { status?: unknown; error?: unknown; headers?: HttpHeadersLike } | null;
249
+ if (e && typeof e.status === 'number' && e.status > 0) {
250
+ resolve({ status: e.status, headers: e.headers ? angularHeaders(e.headers) : {}, data: e.error });
251
+ } else {
252
+ reject(error);
253
+ }
254
+ },
255
+ });
256
+ function onAbort() {
257
+ if (!settled) subscription.unsubscribe();
258
+ }
259
+ if (request.signal.aborted) onAbort();
260
+ else request.signal.addEventListener('abort', onAbort, { once: true });
261
+ });
262
+ }
263
+
264
+ function angularHeaders(headers: HttpHeadersLike): Record<string, string> {
265
+ const out: Record<string, string> = {};
266
+ for (const key of headers.keys()) {
267
+ const value = headers.get(key);
268
+ if (value !== null) out[key.toLowerCase()] = value;
269
+ }
270
+ return out;
271
+ }
272
+ `;
@@ -0,0 +1,15 @@
1
+ import type { Schema } from '../model/schema.js';
2
+ export interface TypeContext {
3
+ /** type used for binary payloads */
4
+ fileType: string;
5
+ /** add `| undefined` to optional properties (query objects under exactOptionalPropertyTypes) */
6
+ optionalUndefined?: boolean;
7
+ /** collects the runtime type names the printed types refer to (for imports) */
8
+ used?: Set<string>;
9
+ }
10
+ /** TypeScript type expression for a schema, pretty-printed at `indent`. */
11
+ export declare function tsType(schema: Schema, ctx: TypeContext, indent?: string, depth?: number): string;
12
+ /** True when the schema prints as an object literal, so it can be an `interface`. */
13
+ export declare function isInterfaceable(schema: Schema): schema is Extract<Schema, {
14
+ type: 'object';
15
+ }>;
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tsType = tsType;
4
+ exports.isInterfaceable = isInterfaceable;
5
+ const print_js_1 = require("./print.js");
6
+ const MAX_DEPTH = 40;
7
+ /** TypeScript type expression for a schema, pretty-printed at `indent`. */
8
+ function tsType(schema, ctx, indent = '', depth = 0) {
9
+ const base = baseType(schema, ctx, indent, depth);
10
+ if (schema.nullable && schema.type !== 'null' && schema.type !== 'unknown') {
11
+ return needsParens(schema) ? `(${base}) | null` : `${base} | null`;
12
+ }
13
+ return base;
14
+ }
15
+ function needsParens(schema) {
16
+ return (schema.type === 'union' || schema.type === 'intersection' || hasEnum(schema));
17
+ }
18
+ function hasEnum(schema) {
19
+ return ((schema.type === 'string' ||
20
+ schema.type === 'number' ||
21
+ schema.type === 'integer' ||
22
+ schema.type === 'boolean') &&
23
+ (schema.enum?.length ?? 0) > 1);
24
+ }
25
+ function baseType(schema, ctx, indent, depth) {
26
+ if (depth > MAX_DEPTH)
27
+ return 'unknown';
28
+ switch (schema.type) {
29
+ case 'string':
30
+ return schema.enum?.length
31
+ ? schema.enum.map(print_js_1.tsString).join(' | ')
32
+ : 'string';
33
+ case 'number':
34
+ case 'integer':
35
+ return schema.enum?.length
36
+ ? schema.enum
37
+ .map((n) => (Number.isFinite(n) ? String(n) : 'number'))
38
+ .join(' | ')
39
+ : 'number';
40
+ case 'boolean':
41
+ return schema.enum?.length === 1 ? String(schema.enum[0]) : 'boolean';
42
+ case 'null':
43
+ return 'null';
44
+ case 'unknown':
45
+ return 'unknown';
46
+ case 'file':
47
+ ctx.used?.add(ctx.fileType);
48
+ return ctx.fileType;
49
+ case 'ref':
50
+ return schema.name;
51
+ case 'array': {
52
+ const item = tsType(schema.items, ctx, indent, depth + 1);
53
+ return /^[\w.]+$/.test(item) ? `${item}[]` : `Array<${item}>`;
54
+ }
55
+ case 'union': {
56
+ const parts = [
57
+ ...new Set(schema.anyOf.map((s) => wrap(tsType(s, ctx, indent, depth + 1), s))),
58
+ ];
59
+ return parts.length ? parts.join(' | ') : 'never';
60
+ }
61
+ case 'intersection': {
62
+ const parts = schema.allOf.map((s) => wrap(tsType(s, ctx, indent, depth + 1), s));
63
+ return parts.length ? parts.join(' & ') : 'unknown';
64
+ }
65
+ case 'object':
66
+ return objectType(schema, ctx, indent, depth);
67
+ }
68
+ }
69
+ function wrap(text, schema) {
70
+ return schema.nullable ||
71
+ schema.type === 'union' ||
72
+ schema.type === 'intersection'
73
+ ? `(${text})`
74
+ : text;
75
+ }
76
+ function objectType(schema, ctx, indent, depth) {
77
+ const entries = Object.entries(schema.properties);
78
+ const extra = schema.additionalProperties;
79
+ if (!entries.length) {
80
+ if (extra === false)
81
+ return 'Record<string, never>';
82
+ if (extra && typeof extra === 'object')
83
+ return `Record<string, ${tsType(extra, ctx, indent, depth + 1)}>`;
84
+ return 'Record<string, unknown>';
85
+ }
86
+ const inner = indent + ' ';
87
+ const required = new Set(schema.required);
88
+ let out = '{\n';
89
+ const propertyTypes = [];
90
+ for (const [key, value] of entries) {
91
+ const optional = !required.has(key);
92
+ out += (0, print_js_1.jsDoc)([value.description, value.deprecated ? '@deprecated' : undefined], inner);
93
+ let type = tsType(value, ctx, inner, depth + 1);
94
+ propertyTypes.push(type);
95
+ if (optional && ctx.optionalUndefined)
96
+ type += ' | undefined';
97
+ out += `${inner}${(0, print_js_1.propKey)(key)}${optional ? '?' : ''}: ${type};\n`;
98
+ }
99
+ if (extra && typeof extra === 'object') {
100
+ // an index signature must also admit the declared properties' types
101
+ const index = [
102
+ ...new Set([tsType(extra, ctx, inner, depth + 1), ...propertyTypes]),
103
+ ];
104
+ out += `${inner}[key: string]: ${index.join(' | ')} | undefined;\n`;
105
+ }
106
+ return out + `${indent}}`;
107
+ }
108
+ /** True when the schema prints as an object literal, so it can be an `interface`. */
109
+ function isInterfaceable(schema) {
110
+ return (schema.type === 'object' &&
111
+ !schema.nullable &&
112
+ Object.keys(schema.properties).length > 0 &&
113
+ typeof schema.additionalProperties !== 'object');
114
+ }
@@ -0,0 +1,16 @@
1
+ import type { ApiCollection, HttpMethod } from '../model/collection.js';
2
+ import type { ParsedSource } from '../parsers/types.js';
3
+ export type GroupBy = 'folder' | 'tag' | 'path' | 'none';
4
+ export interface CollectOptions {
5
+ project: string;
6
+ methods?: readonly HttpMethod[];
7
+ groupBy?: GroupBy;
8
+ include?: readonly string[];
9
+ exclude?: readonly string[];
10
+ /** source content hashes, recorded in the collection for traceability */
11
+ hashes?: Record<string, string>;
12
+ }
13
+ /** Merges parsed sources into one {@link ApiCollection} with stable, unique names. */
14
+ export declare function buildCollection(sources: ParsedSource[], options: CollectOptions): ApiCollection;
15
+ /** `/users/**`, `GET /users/*`, `**\/internal/**` → RegExp over `METHOD /path` or `/path`. */
16
+ export declare function globToRegExp(glob: string): RegExp;