@kubb/ast 5.0.0-beta.8 → 5.0.0-beta.80
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/LICENSE +17 -10
- package/README.md +53 -27
- package/dist/defineMacro-CqX4m8Dq.js +98 -0
- package/dist/defineMacro-CqX4m8Dq.js.map +1 -0
- package/dist/defineMacro-DmGR7vfu.cjs +114 -0
- package/dist/defineMacro-DmGR7vfu.cjs.map +1 -0
- package/dist/defineMacro-DzsACbFo.d.ts +466 -0
- package/dist/index-Cu2zmNxv.d.ts +2188 -0
- package/dist/index.cjs +194 -2239
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +88 -3405
- package/dist/index.js +150 -2160
- package/dist/index.js.map +1 -1
- package/dist/macros.cjs +130 -0
- package/dist/macros.cjs.map +1 -0
- package/dist/macros.d.ts +61 -0
- package/dist/macros.js +128 -0
- package/dist/macros.js.map +1 -0
- package/dist/refs-Bg3rmujP.cjs +135 -0
- package/dist/refs-Bg3rmujP.cjs.map +1 -0
- package/dist/refs-BjBHwunY.js +101 -0
- package/dist/refs-BjBHwunY.js.map +1 -0
- package/dist/rolldown-runtime-CNktS9qV.js +17 -0
- package/dist/types-CWF7DV0f.d.ts +259 -0
- package/dist/types.cjs +0 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.js +1 -0
- package/dist/utils.cjs +613 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.ts +353 -0
- package/dist/utils.js +589 -0
- package/dist/utils.js.map +1 -0
- package/dist/visitor-Dk0DNLfC.js +1203 -0
- package/dist/visitor-Dk0DNLfC.js.map +1 -0
- package/dist/visitor-h6dEM3vR.cjs +1567 -0
- package/dist/visitor-h6dEM3vR.cjs.map +1 -0
- package/package.json +17 -5
- package/dist/chunk--u3MIqq1.js +0 -8
- package/src/constants.ts +0 -228
- package/src/factory.ts +0 -742
- package/src/guards.ts +0 -110
- package/src/index.ts +0 -46
- package/src/infer.ts +0 -130
- package/src/mocks.ts +0 -176
- package/src/nodes/base.ts +0 -56
- package/src/nodes/code.ts +0 -304
- package/src/nodes/file.ts +0 -230
- package/src/nodes/function.ts +0 -223
- package/src/nodes/http.ts +0 -119
- package/src/nodes/index.ts +0 -86
- package/src/nodes/operation.ts +0 -111
- package/src/nodes/output.ts +0 -26
- package/src/nodes/parameter.ts +0 -41
- package/src/nodes/property.ts +0 -34
- package/src/nodes/response.ts +0 -43
- package/src/nodes/root.ts +0 -64
- package/src/nodes/schema.ts +0 -656
- package/src/printer.ts +0 -250
- package/src/refs.ts +0 -67
- package/src/resolvers.ts +0 -45
- package/src/transformers.ts +0 -159
- package/src/types.ts +0 -70
- package/src/utils.ts +0 -915
- package/src/visitor.ts +0 -592
package/dist/macros.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import "./rolldown-runtime-CNktS9qV.js";
|
|
2
|
+
import { Q as narrowSchema, o as createSchema, u as createProperty } from "./visitor-Dk0DNLfC.js";
|
|
3
|
+
import { r as defineMacro } from "./defineMacro-CqX4m8Dq.js";
|
|
4
|
+
import { n as enumPropName } from "./refs-BjBHwunY.js";
|
|
5
|
+
//#region src/macros/macroDiscriminatorEnum.ts
|
|
6
|
+
/**
|
|
7
|
+
* Builds a macro that replaces a discriminator property's schema with a string enum of the given
|
|
8
|
+
* values. Object schemas that lack the property are returned unchanged.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const macro = macroDiscriminatorEnum({ propertyName: 'type', values: ['dog', 'cat'] })
|
|
13
|
+
* const next = applyMacros(objectSchema, [macro], { depth: 'shallow' })
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
function macroDiscriminatorEnum({ propertyName, values, enumName }) {
|
|
17
|
+
return defineMacro({
|
|
18
|
+
name: "discriminator-enum",
|
|
19
|
+
schema(node) {
|
|
20
|
+
const objectNode = narrowSchema(node, "object");
|
|
21
|
+
if (!objectNode?.properties?.length) return void 0;
|
|
22
|
+
if (!objectNode.properties.some((prop) => prop.name === propertyName)) return void 0;
|
|
23
|
+
return createSchema({
|
|
24
|
+
...objectNode,
|
|
25
|
+
properties: objectNode.properties.map((prop) => {
|
|
26
|
+
if (prop.name !== propertyName) return prop;
|
|
27
|
+
return createProperty({
|
|
28
|
+
...prop,
|
|
29
|
+
schema: createSchema({
|
|
30
|
+
type: "enum",
|
|
31
|
+
primitive: "string",
|
|
32
|
+
enumValues: values,
|
|
33
|
+
name: enumName,
|
|
34
|
+
readOnly: prop.schema.readOnly,
|
|
35
|
+
writeOnly: prop.schema.writeOnly
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/macros/macroEnumName.ts
|
|
45
|
+
/**
|
|
46
|
+
* Builds a macro that names an inline enum schema from its parent and property name. Boolean enums
|
|
47
|
+
* are left anonymous. Non-enum nodes are returned unchanged.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* const macro = macroEnumName({ parentName: 'Pet', propName: 'status', enumSuffix: 'enum' })
|
|
52
|
+
* const named = applyMacros(propSchema, [macro], { depth: 'shallow' })
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
function macroEnumName({ parentName, propName, enumSuffix }) {
|
|
56
|
+
return defineMacro({
|
|
57
|
+
name: "enum-name",
|
|
58
|
+
schema(node) {
|
|
59
|
+
const enumNode = narrowSchema(node, "enum");
|
|
60
|
+
if (enumNode?.primitive === "boolean") return {
|
|
61
|
+
...node,
|
|
62
|
+
name: null
|
|
63
|
+
};
|
|
64
|
+
if (enumNode) return {
|
|
65
|
+
...node,
|
|
66
|
+
name: enumPropName(parentName, propName, enumSuffix)
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/macros/macroSimplifyUnion.ts
|
|
73
|
+
/**
|
|
74
|
+
* Scalar primitive schema types used for union simplification and type narrowing.
|
|
75
|
+
*/
|
|
76
|
+
const SCALAR_PRIMITIVE_TYPES = /* @__PURE__ */ new Set([
|
|
77
|
+
"string",
|
|
78
|
+
"number",
|
|
79
|
+
"integer",
|
|
80
|
+
"bigint",
|
|
81
|
+
"boolean"
|
|
82
|
+
]);
|
|
83
|
+
function isScalarPrimitive(type) {
|
|
84
|
+
return SCALAR_PRIMITIVE_TYPES.has(type);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Filters union members, dropping enum members that a broader scalar primitive already covers.
|
|
88
|
+
*/
|
|
89
|
+
function simplifyUnionMembers(members) {
|
|
90
|
+
const scalarPrimitives = new Set(members.filter((member) => isScalarPrimitive(member.type)).map((m) => m.type));
|
|
91
|
+
if (!scalarPrimitives.size) return members;
|
|
92
|
+
return members.filter((member) => {
|
|
93
|
+
const enumNode = narrowSchema(member, "enum");
|
|
94
|
+
if (!enumNode) return true;
|
|
95
|
+
const primitive = enumNode.primitive;
|
|
96
|
+
if (!primitive) return true;
|
|
97
|
+
if ((enumNode.namedEnumValues?.length ?? enumNode.enumValues?.length ?? 0) <= 1) return true;
|
|
98
|
+
if (scalarPrimitives.has(primitive)) return false;
|
|
99
|
+
if ((primitive === "integer" || primitive === "number") && (scalarPrimitives.has("integer") || scalarPrimitives.has("number"))) return false;
|
|
100
|
+
return true;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Removes union members a broader scalar primitive already covers, such as a multi-value string enum
|
|
105
|
+
* sitting next to a plain `string`. Single-value enums are kept.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* const next = applyMacros(unionSchema, [macroSimplifyUnion], { depth: 'shallow' })
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
const macroSimplifyUnion = defineMacro({
|
|
113
|
+
name: "simplify-union",
|
|
114
|
+
schema(node) {
|
|
115
|
+
const unionNode = narrowSchema(node, "union");
|
|
116
|
+
if (!unionNode?.members?.length) return void 0;
|
|
117
|
+
const simplified = simplifyUnionMembers(unionNode.members);
|
|
118
|
+
if (simplified.length === unionNode.members.length) return void 0;
|
|
119
|
+
return {
|
|
120
|
+
...unionNode,
|
|
121
|
+
members: simplified
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
//#endregion
|
|
126
|
+
export { macroDiscriminatorEnum, macroEnumName, macroSimplifyUnion };
|
|
127
|
+
|
|
128
|
+
//# sourceMappingURL=macros.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"macros.js","names":[],"sources":["../src/macros/macroDiscriminatorEnum.ts","../src/macros/macroEnumName.ts","../src/macros/macroSimplifyUnion.ts"],"sourcesContent":["import { defineMacro } from '../defineMacro.ts'\nimport { narrowSchema } from '../guards.ts'\nimport { createProperty } from '../nodes/property.ts'\nimport { createSchema } from '../nodes/schema.ts'\n\ntype Props = {\n propertyName: string\n values: Array<string>\n enumName?: string\n}\n\n/**\n * Builds a macro that replaces a discriminator property's schema with a string enum of the given\n * values. Object schemas that lack the property are returned unchanged.\n *\n * @example\n * ```ts\n * const macro = macroDiscriminatorEnum({ propertyName: 'type', values: ['dog', 'cat'] })\n * const next = applyMacros(objectSchema, [macro], { depth: 'shallow' })\n * ```\n */\nexport function macroDiscriminatorEnum({ propertyName, values, enumName }: Props) {\n return defineMacro({\n name: 'discriminator-enum',\n schema(node) {\n const objectNode = narrowSchema(node, 'object')\n if (!objectNode?.properties?.length) return undefined\n if (!objectNode.properties.some((prop) => prop.name === propertyName)) return undefined\n\n return createSchema({\n ...objectNode,\n properties: objectNode.properties.map((prop) => {\n if (prop.name !== propertyName) return prop\n\n return createProperty({\n ...prop,\n schema: createSchema({\n type: 'enum',\n primitive: 'string',\n enumValues: values,\n name: enumName,\n readOnly: prop.schema.readOnly,\n writeOnly: prop.schema.writeOnly,\n }),\n })\n }),\n })\n },\n })\n}\n","import { defineMacro } from '../defineMacro.ts'\nimport { narrowSchema } from '../guards.ts'\nimport { enumPropName } from '../utils/refs.ts'\n\ntype Props = {\n parentName: string | null | undefined\n propName: string\n enumSuffix: string\n}\n\n/**\n * Builds a macro that names an inline enum schema from its parent and property name. Boolean enums\n * are left anonymous. Non-enum nodes are returned unchanged.\n *\n * @example\n * ```ts\n * const macro = macroEnumName({ parentName: 'Pet', propName: 'status', enumSuffix: 'enum' })\n * const named = applyMacros(propSchema, [macro], { depth: 'shallow' })\n * ```\n */\nexport function macroEnumName({ parentName, propName, enumSuffix }: Props) {\n return defineMacro({\n name: 'enum-name',\n schema(node) {\n const enumNode = narrowSchema(node, 'enum')\n\n if (enumNode?.primitive === 'boolean') return { ...node, name: null }\n if (enumNode) return { ...node, name: enumPropName(parentName, propName, enumSuffix) }\n\n return undefined\n },\n })\n}\n","import { defineMacro } from '../defineMacro.ts'\nimport { narrowSchema } from '../guards.ts'\nimport type { SchemaNode } from '../nodes/schema.ts'\n\ntype ScalarPrimitive = 'string' | 'number' | 'integer' | 'bigint' | 'boolean'\n\n/**\n * Scalar primitive schema types used for union simplification and type narrowing.\n */\nconst SCALAR_PRIMITIVE_TYPES = new Set<ScalarPrimitive>(['string', 'number', 'integer', 'bigint', 'boolean'])\n\nfunction isScalarPrimitive(type: string): type is ScalarPrimitive {\n return SCALAR_PRIMITIVE_TYPES.has(type as ScalarPrimitive)\n}\n\n/**\n * Filters union members, dropping enum members that a broader scalar primitive already covers.\n */\nfunction simplifyUnionMembers(members: Array<SchemaNode>): Array<SchemaNode> {\n const scalarPrimitives = new Set(members.filter((member) => isScalarPrimitive(member.type)).map((m) => m.type))\n if (!scalarPrimitives.size) return members\n\n return members.filter((member) => {\n const enumNode = narrowSchema(member, 'enum')\n if (!enumNode) return true\n\n const primitive = enumNode.primitive\n if (!primitive) return true\n\n const enumValueCount = enumNode.namedEnumValues?.length ?? enumNode.enumValues?.length ?? 0\n if (enumValueCount <= 1) return true\n\n if (scalarPrimitives.has(primitive)) return false\n if ((primitive === 'integer' || primitive === 'number') && (scalarPrimitives.has('integer') || scalarPrimitives.has('number'))) return false\n\n return true\n })\n}\n\n/**\n * Removes union members a broader scalar primitive already covers, such as a multi-value string enum\n * sitting next to a plain `string`. Single-value enums are kept.\n *\n * @example\n * ```ts\n * const next = applyMacros(unionSchema, [macroSimplifyUnion], { depth: 'shallow' })\n * ```\n */\nexport const macroSimplifyUnion = defineMacro({\n name: 'simplify-union',\n schema(node) {\n const unionNode = narrowSchema(node, 'union')\n if (!unionNode?.members?.length) return undefined\n\n const simplified = simplifyUnionMembers(unionNode.members)\n if (simplified.length === unionNode.members.length) return undefined\n\n return { ...unionNode, members: simplified }\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;AAqBA,SAAgB,uBAAuB,EAAE,cAAc,QAAQ,YAAmB;CAChF,OAAO,YAAY;EACjB,MAAM;EACN,OAAO,MAAM;GACX,MAAM,aAAa,aAAa,MAAM,QAAQ;GAC9C,IAAI,CAAC,YAAY,YAAY,QAAQ,OAAO,KAAA;GAC5C,IAAI,CAAC,WAAW,WAAW,MAAM,SAAS,KAAK,SAAS,YAAY,GAAG,OAAO,KAAA;GAE9E,OAAO,aAAa;IAClB,GAAG;IACH,YAAY,WAAW,WAAW,KAAK,SAAS;KAC9C,IAAI,KAAK,SAAS,cAAc,OAAO;KAEvC,OAAO,eAAe;MACpB,GAAG;MACH,QAAQ,aAAa;OACnB,MAAM;OACN,WAAW;OACX,YAAY;OACZ,MAAM;OACN,UAAU,KAAK,OAAO;OACtB,WAAW,KAAK,OAAO;MACzB,CAAC;KACH,CAAC;IACH,CAAC;GACH,CAAC;EACH;CACF,CAAC;AACH;;;;;;;;;;;;;AC7BA,SAAgB,cAAc,EAAE,YAAY,UAAU,cAAqB;CACzE,OAAO,YAAY;EACjB,MAAM;EACN,OAAO,MAAM;GACX,MAAM,WAAW,aAAa,MAAM,MAAM;GAE1C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,0 +1,135 @@
|
|
|
1
|
+
const require_visitor = require("./visitor-h6dEM3vR.cjs");
|
|
2
|
+
//#region src/utils/refs.ts
|
|
3
|
+
const plainStringTypes = /* @__PURE__ */ new Set([
|
|
4
|
+
"string",
|
|
5
|
+
"uuid",
|
|
6
|
+
"email",
|
|
7
|
+
"url",
|
|
8
|
+
"datetime"
|
|
9
|
+
]);
|
|
10
|
+
/**
|
|
11
|
+
* Returns the last path segment of a reference string.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* `extractRefName('#/components/schemas/Pet') // 'Pet'`
|
|
15
|
+
*/
|
|
16
|
+
function extractRefName(ref) {
|
|
17
|
+
return ref.split("/").at(-1) ?? ref;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Resolves the schema name of a ref node. Uses the last segment of `ref` when set, otherwise falls
|
|
21
|
+
* back to `name` then nested `schema.name`.
|
|
22
|
+
*
|
|
23
|
+
* Returns `null` for non-ref nodes or when no name resolves.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'`
|
|
27
|
+
*/
|
|
28
|
+
function resolveRefName(node) {
|
|
29
|
+
if (!node || node.type !== "ref") return null;
|
|
30
|
+
if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null;
|
|
31
|
+
return node.name ?? node.schema?.name ?? null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Builds a PascalCase child schema name by joining a parent name and property name.
|
|
35
|
+
* Returns `null` when there is no parent to nest under.
|
|
36
|
+
*
|
|
37
|
+
* @example Nested under a parent
|
|
38
|
+
* `childName('Order', 'shipping_address') // 'OrderShippingAddress'`
|
|
39
|
+
*
|
|
40
|
+
* @example No parent
|
|
41
|
+
* `childName(undefined, 'params') // null`
|
|
42
|
+
*/
|
|
43
|
+
function childName(parentName, propName) {
|
|
44
|
+
return parentName ? require_visitor.pascalCase([parentName, propName].join(" ")) : null;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any
|
|
48
|
+
* empty parts.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* `enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'`
|
|
52
|
+
*/
|
|
53
|
+
function enumPropName(parentName, propName, enumSuffix) {
|
|
54
|
+
return require_visitor.pascalCase([
|
|
55
|
+
parentName,
|
|
56
|
+
propName,
|
|
57
|
+
enumSuffix
|
|
58
|
+
].filter(Boolean).join(" "));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Merges a ref node with its resolved schema, giving usage-site fields precedence.
|
|
62
|
+
*
|
|
63
|
+
* Every field set on the ref node except `kind`, `type`, `name`, `ref`, and `schema` overrides the
|
|
64
|
+
* same field in the resolved `node.schema` (for example `description`, `nullable`, `readOnly`,
|
|
65
|
+
* `deprecated`). Fields left `undefined` on the ref do not shadow the resolved schema. Non-ref
|
|
66
|
+
* nodes and refs without a resolved `schema` are returned unchanged.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })
|
|
71
|
+
* const merged = syncSchemaRef(ref) // merges with resolved Pet schema
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
function syncSchemaRef(node) {
|
|
75
|
+
const ref = require_visitor.narrowSchema(node, "ref");
|
|
76
|
+
if (!ref) return node;
|
|
77
|
+
if (!ref.schema) return node;
|
|
78
|
+
const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref;
|
|
79
|
+
const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== void 0));
|
|
80
|
+
return require_visitor.createSchema({
|
|
81
|
+
...ref.schema,
|
|
82
|
+
...definedOverrides
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Type guard that returns `true` when a schema emits as a plain `string` type.
|
|
87
|
+
*
|
|
88
|
+
* Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`
|
|
89
|
+
* types, returns `true` only when `representation` is `'string'` rather than `'date'`.
|
|
90
|
+
*/
|
|
91
|
+
function isStringType(node) {
|
|
92
|
+
if (plainStringTypes.has(node.type)) return true;
|
|
93
|
+
const temporal = require_visitor.narrowSchema(node, "date") ?? require_visitor.narrowSchema(node, "time");
|
|
94
|
+
if (temporal) return temporal.representation !== "date";
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
Object.defineProperty(exports, "childName", {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function() {
|
|
101
|
+
return childName;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
Object.defineProperty(exports, "enumPropName", {
|
|
105
|
+
enumerable: true,
|
|
106
|
+
get: function() {
|
|
107
|
+
return enumPropName;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
Object.defineProperty(exports, "extractRefName", {
|
|
111
|
+
enumerable: true,
|
|
112
|
+
get: function() {
|
|
113
|
+
return extractRefName;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
Object.defineProperty(exports, "isStringType", {
|
|
117
|
+
enumerable: true,
|
|
118
|
+
get: function() {
|
|
119
|
+
return isStringType;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
Object.defineProperty(exports, "resolveRefName", {
|
|
123
|
+
enumerable: true,
|
|
124
|
+
get: function() {
|
|
125
|
+
return resolveRefName;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
Object.defineProperty(exports, "syncSchemaRef", {
|
|
129
|
+
enumerable: true,
|
|
130
|
+
get: function() {
|
|
131
|
+
return syncSchemaRef;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
//# sourceMappingURL=refs-Bg3rmujP.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refs-Bg3rmujP.cjs","names":["pascalCase","narrowSchema","createSchema"],"sources":["../src/utils/refs.ts"],"sourcesContent":["import { pascalCase } from '@internals/utils'\nimport { narrowSchema } from '../guards.ts'\nimport type { SchemaNode } from '../nodes/index.ts'\nimport { createSchema, type SchemaType } from '../nodes/schema.ts'\n\nconst plainStringTypes = new Set<SchemaType>(['string', 'uuid', 'email', 'url', 'datetime'] as const)\n\n/**\n * Returns the last path segment of a reference string.\n *\n * @example\n * `extractRefName('#/components/schemas/Pet') // 'Pet'`\n */\nexport function extractRefName(ref: string): string {\n return ref.split('/').at(-1) ?? ref\n}\n\n/**\n * Resolves the schema name of a ref node. Uses the last segment of `ref` when set, otherwise falls\n * back to `name` then nested `schema.name`.\n *\n * Returns `null` for non-ref nodes or when no name resolves.\n *\n * @example\n * `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'`\n */\nexport function resolveRefName(node: SchemaNode | undefined): string | null {\n if (!node || node.type !== 'ref') return null\n if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null\n\n return node.name ?? node.schema?.name ?? null\n}\n\n/**\n * Builds a PascalCase child schema name by joining a parent name and property name.\n * Returns `null` when there is no parent to nest under.\n *\n * @example Nested under a parent\n * `childName('Order', 'shipping_address') // 'OrderShippingAddress'`\n *\n * @example No parent\n * `childName(undefined, 'params') // null`\n */\nexport function childName(parentName: string | null | undefined, propName: string): string | null {\n return parentName ? pascalCase([parentName, propName].join(' ')) : null\n}\n\n/**\n * Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any\n * empty parts.\n *\n * @example\n * `enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'`\n */\nexport function enumPropName(parentName: string | null | undefined, propName: string, enumSuffix: string): string {\n return pascalCase([parentName, propName, enumSuffix].filter(Boolean).join(' '))\n}\n\n/**\n * Merges a ref node with its resolved schema, giving usage-site fields precedence.\n *\n * Every field set on the ref node except `kind`, `type`, `name`, `ref`, and `schema` overrides the\n * same field in the resolved `node.schema` (for example `description`, `nullable`, `readOnly`,\n * `deprecated`). Fields left `undefined` on the ref do not shadow the resolved schema. Non-ref\n * nodes and refs without a resolved `schema` are returned unchanged.\n *\n * @example\n * ```ts\n * const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })\n * const merged = syncSchemaRef(ref) // merges with resolved Pet schema\n * ```\n */\nexport function syncSchemaRef(node: SchemaNode): SchemaNode {\n const ref = narrowSchema(node, 'ref')\n\n if (!ref) return node\n if (!ref.schema) return node\n\n const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref\n\n // Filter out undefined override values so they don't shadow the resolved schema's fields.\n const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== undefined))\n\n return createSchema({ ...ref.schema, ...definedOverrides })\n}\n\n/**\n * Type guard that returns `true` when a schema emits as a plain `string` type.\n *\n * Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`\n * types, returns `true` only when `representation` is `'string'` rather than `'date'`.\n */\nexport function isStringType(node: SchemaNode): boolean {\n if (plainStringTypes.has(node.type)) {\n return true\n }\n\n const temporal = narrowSchema(node, 'date') ?? narrowSchema(node, 'time')\n if (temporal) {\n return temporal.representation !== 'date'\n }\n\n return false\n}\n"],"mappings":";;AAKA,MAAM,mCAAmB,IAAI,IAAgB;CAAC;CAAU;CAAQ;CAAS;CAAO;AAAU,CAAU;;;;;;;AAQpG,SAAgB,eAAe,KAAqB;CAClD,OAAO,IAAI,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK;AAClC;;;;;;;;;;AAWA,SAAgB,eAAe,MAA6C;CAC1E,IAAI,CAAC,QAAQ,KAAK,SAAS,OAAO,OAAO;CACzC,IAAI,KAAK,KAAK,OAAO,eAAe,KAAK,GAAG,KAAK,KAAK,QAAQ,KAAK,QAAQ,QAAQ;CAEnF,OAAO,KAAK,QAAQ,KAAK,QAAQ,QAAQ;AAC3C;;;;;;;;;;;AAYA,SAAgB,UAAU,YAAuC,UAAiC;CAChG,OAAO,aAAaA,gBAAAA,WAAW,CAAC,YAAY,QAAQ,CAAC,CAAC,KAAK,GAAG,CAAC,IAAI;AACrE;;;;;;;;AASA,SAAgB,aAAa,YAAuC,UAAkB,YAA4B;CAChH,OAAOA,gBAAAA,WAAW;EAAC;EAAY;EAAU;CAAU,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC;AAChF;;;;;;;;;;;;;;;AAgBA,SAAgB,cAAc,MAA8B;CAC1D,MAAM,MAAMC,gBAAAA,aAAa,MAAM,KAAK;CAEpC,IAAI,CAAC,KAAK,OAAO;CACjB,IAAI,CAAC,IAAI,QAAQ,OAAO;CAExB,MAAM,EAAE,MAAM,OAAO,MAAM,OAAO,MAAM,OAAO,KAAK,MAAM,QAAQ,SAAS,GAAG,cAAc;CAG5F,MAAM,mBAAmB,OAAO,YAAY,OAAO,QAAQ,SAAS,CAAC,CAAC,QAAQ,GAAG,OAAO,MAAM,KAAA,CAAS,CAAC;CAExG,OAAOC,gBAAAA,aAAa;EAAE,GAAG,IAAI;EAAQ,GAAG;CAAiB,CAAC;AAC5D;;;;;;;AAQA,SAAgB,aAAa,MAA2B;CACtD,IAAI,iBAAiB,IAAI,KAAK,IAAI,GAChC,OAAO;CAGT,MAAM,WAAWD,gBAAAA,aAAa,MAAM,MAAM,KAAKA,gBAAAA,aAAa,MAAM,MAAM;CACxE,IAAI,UACF,OAAO,SAAS,mBAAmB;CAGrC,OAAO;AACT"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import "./rolldown-runtime-CNktS9qV.js";
|
|
2
|
+
import { M as pascalCase, Q as narrowSchema, o as createSchema } from "./visitor-Dk0DNLfC.js";
|
|
3
|
+
//#region src/utils/refs.ts
|
|
4
|
+
const plainStringTypes = /* @__PURE__ */ new Set([
|
|
5
|
+
"string",
|
|
6
|
+
"uuid",
|
|
7
|
+
"email",
|
|
8
|
+
"url",
|
|
9
|
+
"datetime"
|
|
10
|
+
]);
|
|
11
|
+
/**
|
|
12
|
+
* Returns the last path segment of a reference string.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* `extractRefName('#/components/schemas/Pet') // 'Pet'`
|
|
16
|
+
*/
|
|
17
|
+
function extractRefName(ref) {
|
|
18
|
+
return ref.split("/").at(-1) ?? ref;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Resolves the schema name of a ref node. Uses the last segment of `ref` when set, otherwise falls
|
|
22
|
+
* back to `name` then nested `schema.name`.
|
|
23
|
+
*
|
|
24
|
+
* Returns `null` for non-ref nodes or when no name resolves.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'`
|
|
28
|
+
*/
|
|
29
|
+
function resolveRefName(node) {
|
|
30
|
+
if (!node || node.type !== "ref") return null;
|
|
31
|
+
if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null;
|
|
32
|
+
return node.name ?? node.schema?.name ?? null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Builds a PascalCase child schema name by joining a parent name and property name.
|
|
36
|
+
* Returns `null` when there is no parent to nest under.
|
|
37
|
+
*
|
|
38
|
+
* @example Nested under a parent
|
|
39
|
+
* `childName('Order', 'shipping_address') // 'OrderShippingAddress'`
|
|
40
|
+
*
|
|
41
|
+
* @example No parent
|
|
42
|
+
* `childName(undefined, 'params') // null`
|
|
43
|
+
*/
|
|
44
|
+
function childName(parentName, propName) {
|
|
45
|
+
return parentName ? pascalCase([parentName, propName].join(" ")) : null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any
|
|
49
|
+
* empty parts.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* `enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'`
|
|
53
|
+
*/
|
|
54
|
+
function enumPropName(parentName, propName, enumSuffix) {
|
|
55
|
+
return pascalCase([
|
|
56
|
+
parentName,
|
|
57
|
+
propName,
|
|
58
|
+
enumSuffix
|
|
59
|
+
].filter(Boolean).join(" "));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Merges a ref node with its resolved schema, giving usage-site fields precedence.
|
|
63
|
+
*
|
|
64
|
+
* Every field set on the ref node except `kind`, `type`, `name`, `ref`, and `schema` overrides the
|
|
65
|
+
* same field in the resolved `node.schema` (for example `description`, `nullable`, `readOnly`,
|
|
66
|
+
* `deprecated`). Fields left `undefined` on the ref do not shadow the resolved schema. Non-ref
|
|
67
|
+
* nodes and refs without a resolved `schema` are returned unchanged.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })
|
|
72
|
+
* const merged = syncSchemaRef(ref) // merges with resolved Pet schema
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
function syncSchemaRef(node) {
|
|
76
|
+
const ref = narrowSchema(node, "ref");
|
|
77
|
+
if (!ref) return node;
|
|
78
|
+
if (!ref.schema) return node;
|
|
79
|
+
const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref;
|
|
80
|
+
const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== void 0));
|
|
81
|
+
return createSchema({
|
|
82
|
+
...ref.schema,
|
|
83
|
+
...definedOverrides
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Type guard that returns `true` when a schema emits as a plain `string` type.
|
|
88
|
+
*
|
|
89
|
+
* Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`
|
|
90
|
+
* types, returns `true` only when `representation` is `'string'` rather than `'date'`.
|
|
91
|
+
*/
|
|
92
|
+
function isStringType(node) {
|
|
93
|
+
if (plainStringTypes.has(node.type)) return true;
|
|
94
|
+
const temporal = narrowSchema(node, "date") ?? narrowSchema(node, "time");
|
|
95
|
+
if (temporal) return temporal.representation !== "date";
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
//#endregion
|
|
99
|
+
export { resolveRefName as a, isStringType as i, enumPropName as n, syncSchemaRef as o, extractRefName as r, childName as t };
|
|
100
|
+
|
|
101
|
+
//# sourceMappingURL=refs-BjBHwunY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refs-BjBHwunY.js","names":[],"sources":["../src/utils/refs.ts"],"sourcesContent":["import { pascalCase } from '@internals/utils'\nimport { narrowSchema } from '../guards.ts'\nimport type { SchemaNode } from '../nodes/index.ts'\nimport { createSchema, type SchemaType } from '../nodes/schema.ts'\n\nconst plainStringTypes = new Set<SchemaType>(['string', 'uuid', 'email', 'url', 'datetime'] as const)\n\n/**\n * Returns the last path segment of a reference string.\n *\n * @example\n * `extractRefName('#/components/schemas/Pet') // 'Pet'`\n */\nexport function extractRefName(ref: string): string {\n return ref.split('/').at(-1) ?? ref\n}\n\n/**\n * Resolves the schema name of a ref node. Uses the last segment of `ref` when set, otherwise falls\n * back to `name` then nested `schema.name`.\n *\n * Returns `null` for non-ref nodes or when no name resolves.\n *\n * @example\n * `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'`\n */\nexport function resolveRefName(node: SchemaNode | undefined): string | null {\n if (!node || node.type !== 'ref') return null\n if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null\n\n return node.name ?? node.schema?.name ?? null\n}\n\n/**\n * Builds a PascalCase child schema name by joining a parent name and property name.\n * Returns `null` when there is no parent to nest under.\n *\n * @example Nested under a parent\n * `childName('Order', 'shipping_address') // 'OrderShippingAddress'`\n *\n * @example No parent\n * `childName(undefined, 'params') // null`\n */\nexport function childName(parentName: string | null | undefined, propName: string): string | null {\n return parentName ? pascalCase([parentName, propName].join(' ')) : null\n}\n\n/**\n * Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any\n * empty parts.\n *\n * @example\n * `enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'`\n */\nexport function enumPropName(parentName: string | null | undefined, propName: string, enumSuffix: string): string {\n return pascalCase([parentName, propName, enumSuffix].filter(Boolean).join(' '))\n}\n\n/**\n * Merges a ref node with its resolved schema, giving usage-site fields precedence.\n *\n * Every field set on the ref node except `kind`, `type`, `name`, `ref`, and `schema` overrides the\n * same field in the resolved `node.schema` (for example `description`, `nullable`, `readOnly`,\n * `deprecated`). Fields left `undefined` on the ref do not shadow the resolved schema. Non-ref\n * nodes and refs without a resolved `schema` are returned unchanged.\n *\n * @example\n * ```ts\n * const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })\n * const merged = syncSchemaRef(ref) // merges with resolved Pet schema\n * ```\n */\nexport function syncSchemaRef(node: SchemaNode): SchemaNode {\n const ref = narrowSchema(node, 'ref')\n\n if (!ref) return node\n if (!ref.schema) return node\n\n const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref\n\n // Filter out undefined override values so they don't shadow the resolved schema's fields.\n const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== undefined))\n\n return createSchema({ ...ref.schema, ...definedOverrides })\n}\n\n/**\n * Type guard that returns `true` when a schema emits as a plain `string` type.\n *\n * Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`\n * types, returns `true` only when `representation` is `'string'` rather than `'date'`.\n */\nexport function isStringType(node: SchemaNode): boolean {\n if (plainStringTypes.has(node.type)) {\n return true\n }\n\n const temporal = narrowSchema(node, 'date') ?? narrowSchema(node, 'time')\n if (temporal) {\n return temporal.representation !== 'date'\n }\n\n return false\n}\n"],"mappings":";;;AAKA,MAAM,mCAAmB,IA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ACxE,IAAI,UACF,OAAO,SAAS,mBAAmB;CAGrC,OAAO;AACT"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", {
|
|
4
|
+
value,
|
|
5
|
+
configurable: true
|
|
6
|
+
});
|
|
7
|
+
var __exportAll = (all, no_symbols) => {
|
|
8
|
+
let target = {};
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
13
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
14
|
+
return target;
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
export { __name as n, __exportAll as t };
|