@kubb/ast 5.15.4 → 5.16.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/dist/index.cjs +16 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -6
- package/dist/index.d.ts +25 -6
- package/dist/index.js +16 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -788,7 +788,10 @@ type CreateSchemaOutput<T extends CreateSchemaInput> = SchemaNodeByType[T['type'
|
|
|
788
788
|
*/
|
|
789
789
|
declare function createSchema<T extends CreateSchemaInput>(props: T): CreateSchemaOutput<T>;
|
|
790
790
|
declare function createSchema(props: CreateSchemaInput): SchemaNode;
|
|
791
|
-
|
|
791
|
+
/**
|
|
792
|
+
* Where a parameter is sent. `querystring` carries the whole query string as one value, serialized per `contentType`.
|
|
793
|
+
*/
|
|
794
|
+
type ParameterLocation = 'path' | 'query' | 'header' | 'cookie' | 'querystring';
|
|
792
795
|
/**
|
|
793
796
|
* Parameter serialization style, controlling how a parameter value is rendered into the request.
|
|
794
797
|
*/
|
|
@@ -814,7 +817,7 @@ type ParameterNode = BaseNode & {
|
|
|
814
817
|
*/
|
|
815
818
|
name: string;
|
|
816
819
|
/**
|
|
817
|
-
* Parameter location (`path`, `query`, `header`, or `
|
|
820
|
+
* Parameter location (`path`, `query`, `header`, `cookie`, or `querystring`).
|
|
818
821
|
*/
|
|
819
822
|
in: ParameterLocation;
|
|
820
823
|
/**
|
|
@@ -908,9 +911,24 @@ type ContentNode = BaseNode & {
|
|
|
908
911
|
*/
|
|
909
912
|
contentType: string;
|
|
910
913
|
/**
|
|
911
|
-
* Body schema for this content type.
|
|
914
|
+
* Body schema for this content type. For a stream it is the same node as `stream.schema`.
|
|
912
915
|
*/
|
|
913
916
|
schema?: SchemaNode;
|
|
917
|
+
/**
|
|
918
|
+
* Set when the content is a stream of items (an event stream, JSON Lines, a channel of messages) instead of one body.
|
|
919
|
+
*/
|
|
920
|
+
stream?: {
|
|
921
|
+
/**
|
|
922
|
+
* Schema of one item, such as one event of `text/event-stream` or one line of JSON Lines.
|
|
923
|
+
*/
|
|
924
|
+
schema?: SchemaNode;
|
|
925
|
+
/**
|
|
926
|
+
* What `schema` describes for an event stream.
|
|
927
|
+
* - `'event'` the parsed event with its `event`, `data`, `id` and `retry` fields
|
|
928
|
+
* - `'data'` only the `data` payload, which the client wraps in its own event type
|
|
929
|
+
*/
|
|
930
|
+
shape?: 'event' | 'data';
|
|
931
|
+
};
|
|
914
932
|
/**
|
|
915
933
|
* Property keys to exclude from the generated type via `Omit<Type, Keys>`.
|
|
916
934
|
* Set when a referenced schema has `readOnly`/`writeOnly` fields that should be omitted.
|
|
@@ -1045,9 +1063,10 @@ type ResponseInput = Pick<ResponseNode, 'statusCode'> & Partial<Omit<ResponseNod
|
|
|
1045
1063
|
declare function createResponse(props: ResponseInput): ResponseNode;
|
|
1046
1064
|
/**
|
|
1047
1065
|
* HTTP method an operation responds to. `QUERY` is the safe, idempotent method with a request body
|
|
1048
|
-
* from RFC 10008, declared with the `query` field of an OpenAPI 3.2 path item.
|
|
1066
|
+
* from RFC 10008, declared with the `query` field of an OpenAPI 3.2 path item. Any other name is a
|
|
1067
|
+
* method the source declares outside this fixed set, in the capitalization it is sent with.
|
|
1049
1068
|
*/
|
|
1050
|
-
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE' | 'QUERY';
|
|
1069
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE' | 'QUERY' | (string & {});
|
|
1051
1070
|
/**
|
|
1052
1071
|
* Fields shared by every operation, regardless of transport.
|
|
1053
1072
|
*/
|
|
@@ -2129,7 +2148,7 @@ export declare function compareEnforce(a?: Enforce, b?: Enforce): number;
|
|
|
2129
2148
|
*/
|
|
2130
2149
|
type Macro = Visitor & {
|
|
2131
2150
|
/**
|
|
2132
|
-
* Macro identifier used to tell macros apart, for example `'
|
|
2151
|
+
* Macro identifier used to tell macros apart, for example `'dedupe-union'`.
|
|
2133
2152
|
*/
|
|
2134
2153
|
name: string;
|
|
2135
2154
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -788,7 +788,10 @@ type CreateSchemaOutput<T extends CreateSchemaInput> = SchemaNodeByType[T['type'
|
|
|
788
788
|
*/
|
|
789
789
|
declare function createSchema<T extends CreateSchemaInput>(props: T): CreateSchemaOutput<T>;
|
|
790
790
|
declare function createSchema(props: CreateSchemaInput): SchemaNode;
|
|
791
|
-
|
|
791
|
+
/**
|
|
792
|
+
* Where a parameter is sent. `querystring` carries the whole query string as one value, serialized per `contentType`.
|
|
793
|
+
*/
|
|
794
|
+
type ParameterLocation = 'path' | 'query' | 'header' | 'cookie' | 'querystring';
|
|
792
795
|
/**
|
|
793
796
|
* Parameter serialization style, controlling how a parameter value is rendered into the request.
|
|
794
797
|
*/
|
|
@@ -814,7 +817,7 @@ type ParameterNode = BaseNode & {
|
|
|
814
817
|
*/
|
|
815
818
|
name: string;
|
|
816
819
|
/**
|
|
817
|
-
* Parameter location (`path`, `query`, `header`, or `
|
|
820
|
+
* Parameter location (`path`, `query`, `header`, `cookie`, or `querystring`).
|
|
818
821
|
*/
|
|
819
822
|
in: ParameterLocation;
|
|
820
823
|
/**
|
|
@@ -908,9 +911,24 @@ type ContentNode = BaseNode & {
|
|
|
908
911
|
*/
|
|
909
912
|
contentType: string;
|
|
910
913
|
/**
|
|
911
|
-
* Body schema for this content type.
|
|
914
|
+
* Body schema for this content type. For a stream it is the same node as `stream.schema`.
|
|
912
915
|
*/
|
|
913
916
|
schema?: SchemaNode;
|
|
917
|
+
/**
|
|
918
|
+
* Set when the content is a stream of items (an event stream, JSON Lines, a channel of messages) instead of one body.
|
|
919
|
+
*/
|
|
920
|
+
stream?: {
|
|
921
|
+
/**
|
|
922
|
+
* Schema of one item, such as one event of `text/event-stream` or one line of JSON Lines.
|
|
923
|
+
*/
|
|
924
|
+
schema?: SchemaNode;
|
|
925
|
+
/**
|
|
926
|
+
* What `schema` describes for an event stream.
|
|
927
|
+
* - `'event'` the parsed event with its `event`, `data`, `id` and `retry` fields
|
|
928
|
+
* - `'data'` only the `data` payload, which the client wraps in its own event type
|
|
929
|
+
*/
|
|
930
|
+
shape?: 'event' | 'data';
|
|
931
|
+
};
|
|
914
932
|
/**
|
|
915
933
|
* Property keys to exclude from the generated type via `Omit<Type, Keys>`.
|
|
916
934
|
* Set when a referenced schema has `readOnly`/`writeOnly` fields that should be omitted.
|
|
@@ -1045,9 +1063,10 @@ type ResponseInput = Pick<ResponseNode, 'statusCode'> & Partial<Omit<ResponseNod
|
|
|
1045
1063
|
declare function createResponse(props: ResponseInput): ResponseNode;
|
|
1046
1064
|
/**
|
|
1047
1065
|
* HTTP method an operation responds to. `QUERY` is the safe, idempotent method with a request body
|
|
1048
|
-
* from RFC 10008, declared with the `query` field of an OpenAPI 3.2 path item.
|
|
1066
|
+
* from RFC 10008, declared with the `query` field of an OpenAPI 3.2 path item. Any other name is a
|
|
1067
|
+
* method the source declares outside this fixed set, in the capitalization it is sent with.
|
|
1049
1068
|
*/
|
|
1050
|
-
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE' | 'QUERY';
|
|
1069
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE' | 'QUERY' | (string & {});
|
|
1051
1070
|
/**
|
|
1052
1071
|
* Fields shared by every operation, regardless of transport.
|
|
1053
1072
|
*/
|
|
@@ -2129,7 +2148,7 @@ export declare function compareEnforce(a?: Enforce, b?: Enforce): number;
|
|
|
2129
2148
|
*/
|
|
2130
2149
|
type Macro = Visitor & {
|
|
2131
2150
|
/**
|
|
2132
|
-
* Macro identifier used to tell macros apart, for example `'
|
|
2151
|
+
* Macro identifier used to tell macros apart, for example `'dedupe-union'`.
|
|
2133
2152
|
*/
|
|
2134
2153
|
name: string;
|
|
2135
2154
|
/**
|
package/dist/index.js
CHANGED
|
@@ -187,7 +187,7 @@ const VISITOR_KEYS = {
|
|
|
187
187
|
"responses"
|
|
188
188
|
],
|
|
189
189
|
RequestBody: ["content"],
|
|
190
|
-
Content: ["schema"],
|
|
190
|
+
Content: ["schema", "stream"],
|
|
191
191
|
Response: ["content"],
|
|
192
192
|
Schema: [
|
|
193
193
|
"properties",
|
|
@@ -251,24 +251,27 @@ function getChildren(node, recurse) {
|
|
|
251
251
|
});
|
|
252
252
|
return children;
|
|
253
253
|
}
|
|
254
|
+
/** Calls `visit` for each direct child node and stops at the first call that returns `true`. */
|
|
254
255
|
function visitChildNodes(node, visit) {
|
|
255
256
|
const keys = VISITOR_KEYS[node.kind];
|
|
256
257
|
if (!keys) return false;
|
|
257
258
|
const record = node;
|
|
259
|
+
const seen = /* @__PURE__ */ new Set();
|
|
260
|
+
const visitOnce = (child) => !seen.has(child) && (seen.add(child), visit(child));
|
|
258
261
|
for (const key of keys) {
|
|
259
262
|
const value = record[key];
|
|
260
263
|
if (Array.isArray(value)) {
|
|
261
|
-
for (const item of value) if (isNode(item) &&
|
|
264
|
+
for (const item of value) if (isNode(item) && visitOnce(item)) return true;
|
|
262
265
|
continue;
|
|
263
266
|
}
|
|
264
267
|
if (isNode(value)) {
|
|
265
|
-
if (
|
|
268
|
+
if (visitOnce(value)) return true;
|
|
266
269
|
continue;
|
|
267
270
|
}
|
|
268
271
|
if (isNodeRecord(value)) for (const name in value) {
|
|
269
272
|
if (!Object.hasOwn(value, name)) continue;
|
|
270
273
|
const item = value[name];
|
|
271
|
-
if (isNode(item) &&
|
|
274
|
+
if (isNode(item) && visitOnce(item)) return true;
|
|
272
275
|
}
|
|
273
276
|
}
|
|
274
277
|
return false;
|
|
@@ -366,13 +369,19 @@ function transformChildren(node, visitor, recurse) {
|
|
|
366
369
|
if (!keys) return node;
|
|
367
370
|
const record = node;
|
|
368
371
|
let updates;
|
|
372
|
+
const done = /* @__PURE__ */ new Map();
|
|
373
|
+
const transformOnce = (child) => {
|
|
374
|
+
const next = done.get(child) ?? transformNode(child, visitor, recurse, node);
|
|
375
|
+
done.set(child, next);
|
|
376
|
+
return next;
|
|
377
|
+
};
|
|
369
378
|
for (const key of keys) {
|
|
370
379
|
if (!(key in record)) continue;
|
|
371
380
|
const value = record[key];
|
|
372
381
|
if (Array.isArray(value)) {
|
|
373
382
|
let mapped;
|
|
374
383
|
for (const [i, item] of value.entries()) {
|
|
375
|
-
const next = isNode(item) ?
|
|
384
|
+
const next = isNode(item) ? transformOnce(item) : item;
|
|
376
385
|
if (mapped) {
|
|
377
386
|
mapped.push(next);
|
|
378
387
|
continue;
|
|
@@ -383,14 +392,14 @@ function transformChildren(node, visitor, recurse) {
|
|
|
383
392
|
continue;
|
|
384
393
|
}
|
|
385
394
|
if (isNode(value)) {
|
|
386
|
-
const next =
|
|
395
|
+
const next = transformOnce(value);
|
|
387
396
|
if (next !== value) (updates ??= {})[key] = next;
|
|
388
397
|
continue;
|
|
389
398
|
}
|
|
390
399
|
if (isNodeRecord(value)) {
|
|
391
400
|
let mapped;
|
|
392
401
|
for (const [name, item] of Object.entries(value)) {
|
|
393
|
-
const next = isNode(item) ?
|
|
402
|
+
const next = isNode(item) ? transformOnce(item) : item;
|
|
394
403
|
if (next !== item) (mapped ??= { ...value })[name] = next;
|
|
395
404
|
}
|
|
396
405
|
if (mapped) (updates ??= {})[key] = mapped;
|