@kubb/ast 5.0.0-alpha.24 → 5.0.0-alpha.25
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 +55 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +12 -2
- package/dist/index.js +55 -7
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/{visitor-DsdLcLjR.d.ts → visitor-C2XD9px4.d.ts} +114 -12
- package/package.json +1 -1
- package/src/constants.ts +8 -0
- package/src/factory.ts +41 -5
- package/src/index.ts +1 -1
- package/src/nodes/index.ts +3 -0
- package/src/nodes/schema.ts +114 -6
- package/src/types.ts +3 -0
- package/src/utils.ts +23 -0
- package/src/visitor.ts +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { A as syncOptionality, C as createParameter,
|
|
2
|
+
import { A as syncOptionality, C as createParameter, D as createRoot, Dt as isScalarPrimitive, E as createResponse, Et as httpMethods, N as ParserOptions, O as createSchema, Ot as mediaTypes, R as OperationNode, S as createOperation, T as createProperty, W as ParameterNode, _ as createPrinterFactory, b as createFunctionParameter, bt as ParameterGroupNode, ct as SchemaNodeByType, d as transform, f as walk, g as PrinterFactoryOptions, k as createTypeNode, kt as schemaTypes, l as collect, m as extractRefName, st as SchemaNode, u as composeTransformers, v as definePrinter, vt as FunctionParameterNode, w as createParameterGroup, wt as ScalarPrimitive, x as createFunctionParameters, yt as FunctionParametersNode } from "./visitor-C2XD9px4.js";
|
|
3
3
|
|
|
4
4
|
//#region src/guards.d.ts
|
|
5
5
|
/**
|
|
@@ -107,6 +107,16 @@ declare function simplifyUnion(members: Array<SchemaNode>): Array<SchemaNode>;
|
|
|
107
107
|
declare function setEnumName(propNode: SchemaNode, parentName: string | null | undefined, propName: string, enumSuffix: string): SchemaNode;
|
|
108
108
|
//#endregion
|
|
109
109
|
//#region src/utils.d.ts
|
|
110
|
+
/**
|
|
111
|
+
* Returns a merged schema view for a ref node, combining the resolved `node.schema`
|
|
112
|
+
* (base from the referenced definition) with any usage-site sibling fields set directly
|
|
113
|
+
* on the ref node (description, readOnly, nullable, deprecated, etc.).
|
|
114
|
+
*
|
|
115
|
+
* Usage-site fields take precedence over the resolved schema's own fields when both are defined.
|
|
116
|
+
*
|
|
117
|
+
* For non-ref nodes the node itself is returned unchanged.
|
|
118
|
+
*/
|
|
119
|
+
declare function syncSchemaRef(node: SchemaNode): SchemaNode;
|
|
110
120
|
/**
|
|
111
121
|
* Returns `true` when a schema is emitted as a plain `string` type.
|
|
112
122
|
*
|
|
@@ -296,5 +306,5 @@ type CreateOperationParamsOptions = {
|
|
|
296
306
|
*/
|
|
297
307
|
declare function createOperationParams(node: OperationNode, options: CreateOperationParamsOptions): FunctionParametersNode;
|
|
298
308
|
//#endregion
|
|
299
|
-
export { type OperationParamsResolver, type ParserOptions, type PrinterFactoryOptions, type ScalarPrimitive, caseParams, childName, collect, collectImports, composeTransformers, createDiscriminantNode, createFunctionParameter, createFunctionParameters, createOperation, createOperationParams, createParameter, createParameterGroup, createPrinterFactory, createProperty, createResponse, createRoot, createSchema, createTypeNode, definePrinter, enumPropName, extractRefName, findDiscriminator, httpMethods, isOperationNode, isScalarPrimitive, isSchemaNode, isStringType, mediaTypes, mergeAdjacentObjects, narrowSchema, schemaTypes, setDiscriminatorEnum, setEnumName, simplifyUnion, syncOptionality, transform, walk };
|
|
309
|
+
export { type OperationParamsResolver, type ParserOptions, type PrinterFactoryOptions, type ScalarPrimitive, caseParams, childName, collect, collectImports, composeTransformers, createDiscriminantNode, createFunctionParameter, createFunctionParameters, createOperation, createOperationParams, createParameter, createParameterGroup, createPrinterFactory, createProperty, createResponse, createRoot, createSchema, createTypeNode, definePrinter, enumPropName, extractRefName, findDiscriminator, httpMethods, isOperationNode, isScalarPrimitive, isSchemaNode, isStringType, mediaTypes, mergeAdjacentObjects, narrowSchema, schemaTypes, setDiscriminatorEnum, setEnumName, simplifyUnion, syncOptionality, syncSchemaRef, transform, walk };
|
|
300
310
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -38,6 +38,8 @@ const schemaTypes = {
|
|
|
38
38
|
uuid: "uuid",
|
|
39
39
|
email: "email",
|
|
40
40
|
url: "url",
|
|
41
|
+
ipv4: "ipv4",
|
|
42
|
+
ipv6: "ipv6",
|
|
41
43
|
blob: "blob",
|
|
42
44
|
never: "never"
|
|
43
45
|
};
|
|
@@ -159,13 +161,41 @@ function createOperation(props) {
|
|
|
159
161
|
kind: "Operation"
|
|
160
162
|
};
|
|
161
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Maps schema `type` to its underlying `primitive`.
|
|
166
|
+
* Primitive types map to themselves; special string formats map to `'string'`.
|
|
167
|
+
* Complex types (`ref`, `enum`, `union`, `intersection`, `tuple`, `blob`) are left unset.
|
|
168
|
+
*/
|
|
169
|
+
const TYPE_TO_PRIMITIVE = {
|
|
170
|
+
string: "string",
|
|
171
|
+
number: "number",
|
|
172
|
+
integer: "integer",
|
|
173
|
+
bigint: "bigint",
|
|
174
|
+
boolean: "boolean",
|
|
175
|
+
null: "null",
|
|
176
|
+
any: "any",
|
|
177
|
+
unknown: "unknown",
|
|
178
|
+
void: "void",
|
|
179
|
+
never: "never",
|
|
180
|
+
object: "object",
|
|
181
|
+
array: "array",
|
|
182
|
+
date: "date",
|
|
183
|
+
uuid: "string",
|
|
184
|
+
email: "string",
|
|
185
|
+
url: "string",
|
|
186
|
+
datetime: "string",
|
|
187
|
+
time: "string"
|
|
188
|
+
};
|
|
162
189
|
function createSchema(props) {
|
|
190
|
+
const inferredPrimitive = TYPE_TO_PRIMITIVE[props.type];
|
|
163
191
|
if (props["type"] === "object") return {
|
|
164
192
|
properties: [],
|
|
193
|
+
primitive: "object",
|
|
165
194
|
...props,
|
|
166
195
|
kind: "Schema"
|
|
167
196
|
};
|
|
168
197
|
return {
|
|
198
|
+
primitive: inferredPrimitive,
|
|
169
199
|
...props,
|
|
170
200
|
kind: "Schema"
|
|
171
201
|
};
|
|
@@ -592,11 +622,9 @@ function isValidVarName(name) {
|
|
|
592
622
|
* @example
|
|
593
623
|
* ```ts
|
|
594
624
|
* const limit = createLimit(2)
|
|
595
|
-
*
|
|
596
|
-
* limit(() =>
|
|
597
|
-
*
|
|
598
|
-
* limit(() => taskC()),
|
|
599
|
-
* ])
|
|
625
|
+
* for (const task of [taskA, taskB, taskC]) {
|
|
626
|
+
* await limit(() => task())
|
|
627
|
+
* }
|
|
600
628
|
* // only 2 tasks run at the same time
|
|
601
629
|
* ```
|
|
602
630
|
*/
|
|
@@ -708,7 +736,7 @@ async function _walk(node, visitor, recurse, limit, parent) {
|
|
|
708
736
|
case "FunctionParameters": break;
|
|
709
737
|
}
|
|
710
738
|
const children = getChildren(node, recurse);
|
|
711
|
-
|
|
739
|
+
for (const child of children) await _walk(child, visitor, recurse, limit, node);
|
|
712
740
|
}
|
|
713
741
|
function transform(node, options) {
|
|
714
742
|
const { depth, parent, ...visitor } = options;
|
|
@@ -1047,6 +1075,26 @@ const plainStringTypes = new Set([
|
|
|
1047
1075
|
"datetime"
|
|
1048
1076
|
]);
|
|
1049
1077
|
/**
|
|
1078
|
+
* Returns a merged schema view for a ref node, combining the resolved `node.schema`
|
|
1079
|
+
* (base from the referenced definition) with any usage-site sibling fields set directly
|
|
1080
|
+
* on the ref node (description, readOnly, nullable, deprecated, etc.).
|
|
1081
|
+
*
|
|
1082
|
+
* Usage-site fields take precedence over the resolved schema's own fields when both are defined.
|
|
1083
|
+
*
|
|
1084
|
+
* For non-ref nodes the node itself is returned unchanged.
|
|
1085
|
+
*/
|
|
1086
|
+
function syncSchemaRef(node) {
|
|
1087
|
+
const ref = narrowSchema(node, "ref");
|
|
1088
|
+
if (!ref) return node;
|
|
1089
|
+
if (!ref.schema) return node;
|
|
1090
|
+
const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref;
|
|
1091
|
+
const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== void 0));
|
|
1092
|
+
return createSchema({
|
|
1093
|
+
...ref.schema,
|
|
1094
|
+
...definedOverrides
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
1097
|
+
/**
|
|
1050
1098
|
* Returns `true` when a schema is emitted as a plain `string` type.
|
|
1051
1099
|
*
|
|
1052
1100
|
* - `string`, `uuid`, `email`, `url`, `datetime` are always plain strings.
|
|
@@ -1339,6 +1387,6 @@ function toStructType({ node, params, resolver }) {
|
|
|
1339
1387
|
});
|
|
1340
1388
|
}
|
|
1341
1389
|
//#endregion
|
|
1342
|
-
export { caseParams, childName, collect, collectImports, composeTransformers, createDiscriminantNode, createFunctionParameter, createFunctionParameters, createOperation, createOperationParams, createParameter, createParameterGroup, createPrinterFactory, createProperty, createResponse, createRoot, createSchema, createTypeNode, definePrinter, enumPropName, extractRefName, findDiscriminator, httpMethods, isOperationNode, isScalarPrimitive, isSchemaNode, isStringType, mediaTypes, mergeAdjacentObjects, narrowSchema, schemaTypes, setDiscriminatorEnum, setEnumName, simplifyUnion, syncOptionality, transform, walk };
|
|
1390
|
+
export { caseParams, childName, collect, collectImports, composeTransformers, createDiscriminantNode, createFunctionParameter, createFunctionParameters, createOperation, createOperationParams, createParameter, createParameterGroup, createPrinterFactory, createProperty, createResponse, createRoot, createSchema, createTypeNode, definePrinter, enumPropName, extractRefName, findDiscriminator, httpMethods, isOperationNode, isScalarPrimitive, isSchemaNode, isStringType, mediaTypes, mergeAdjacentObjects, narrowSchema, schemaTypes, setDiscriminatorEnum, setEnumName, simplifyUnion, syncOptionality, syncSchemaRef, transform, walk };
|
|
1343
1391
|
|
|
1344
1392
|
//# sourceMappingURL=index.js.map
|