@kubb/ast 5.0.0-beta.65 → 5.0.0-beta.66
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/{defineMacro-CEZHaCXE.cjs → defineMacro-BxfaP1iL.cjs} +3 -4
- package/dist/{defineMacro-CEZHaCXE.cjs.map → defineMacro-BxfaP1iL.cjs.map} +1 -1
- package/dist/{defineMacro-B76LsJwO.js → defineMacro-D2vgAdoH.js} +2 -3
- package/dist/{defineMacro-B76LsJwO.js.map → defineMacro-D2vgAdoH.js.map} +1 -1
- package/dist/index.cjs +114 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +51 -32
- package/dist/index.js +57 -6
- package/dist/index.js.map +1 -1
- package/dist/macros.cjs +5 -6
- package/dist/macros.cjs.map +1 -1
- package/dist/macros.js +2 -3
- package/dist/macros.js.map +1 -1
- package/dist/{schema-YNbOtTCM.js → refs-CXp6uOHL.js} +502 -2
- package/dist/refs-CXp6uOHL.js.map +1 -0
- package/dist/{schema-BkvrrOAr.cjs → refs-DDIY_Tpn.cjs} +597 -7
- package/dist/refs-DDIY_Tpn.cjs.map +1 -0
- package/dist/{types-B6thixAv.d.ts → types-DpeAMnq5.d.ts} +5 -5
- package/dist/types.d.ts +3 -3
- package/dist/{utils-BJi0y-xg.js → utils-C2kwfetT.js} +2 -3
- package/dist/{utils-BJi0y-xg.js.map → utils-C2kwfetT.js.map} +1 -1
- package/dist/{utils-CEepwqmb.cjs → utils-DYhjlv0E.cjs} +13 -14
- package/dist/{utils-CEepwqmb.cjs.map → utils-DYhjlv0E.cjs.map} +1 -1
- package/dist/utils.cjs +3 -4
- package/dist/utils.js +2 -3
- package/package.json +1 -5
- package/dist/factory-B_qPwA1b.d.ts +0 -27
- package/dist/factory.cjs +0 -89
- package/dist/factory.cjs.map +0 -1
- package/dist/factory.d.ts +0 -3
- package/dist/factory.js +0 -58
- package/dist/factory.js.map +0 -1
- package/dist/refs-Dx6U5LoE.js +0 -505
- package/dist/refs-Dx6U5LoE.js.map +0 -1
- package/dist/refs-u5SDdyV7.cjs +0 -599
- package/dist/refs-u5SDdyV7.cjs.map +0 -1
- package/dist/schema-BkvrrOAr.cjs.map +0 -1
- package/dist/schema-YNbOtTCM.js.map +0 -1
|
@@ -1,6 +1,154 @@
|
|
|
1
1
|
import "./rolldown-runtime-CNktS9qV.js";
|
|
2
2
|
import { hash } from "node:crypto";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
//#region src/constants.ts
|
|
5
|
+
const visitorDepths = {
|
|
6
|
+
shallow: "shallow",
|
|
7
|
+
deep: "deep"
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Schema type discriminators used by all AST schema nodes.
|
|
11
|
+
*
|
|
12
|
+
* Each value is a stable discriminator across the AST (for example `schema.type === schemaTypes.object`).
|
|
13
|
+
*/
|
|
14
|
+
const schemaTypes = {
|
|
15
|
+
/**
|
|
16
|
+
* Text value.
|
|
17
|
+
*/
|
|
18
|
+
string: "string",
|
|
19
|
+
/**
|
|
20
|
+
* Floating-point number (`float`, `double`).
|
|
21
|
+
*/
|
|
22
|
+
number: "number",
|
|
23
|
+
/**
|
|
24
|
+
* Whole number (`int32`). Use `bigint` for `int64`.
|
|
25
|
+
*/
|
|
26
|
+
integer: "integer",
|
|
27
|
+
/**
|
|
28
|
+
* 64-bit integer (`int64`). Only used when `integerType` is set to `'bigint'`.
|
|
29
|
+
*/
|
|
30
|
+
bigint: "bigint",
|
|
31
|
+
/**
|
|
32
|
+
* Boolean value.
|
|
33
|
+
*/
|
|
34
|
+
boolean: "boolean",
|
|
35
|
+
/**
|
|
36
|
+
* Explicit null value.
|
|
37
|
+
*/
|
|
38
|
+
null: "null",
|
|
39
|
+
/**
|
|
40
|
+
* Any value (no type restriction).
|
|
41
|
+
*/
|
|
42
|
+
any: "any",
|
|
43
|
+
/**
|
|
44
|
+
* Unknown value (must be narrowed before usage).
|
|
45
|
+
*/
|
|
46
|
+
unknown: "unknown",
|
|
47
|
+
/**
|
|
48
|
+
* No return value (`void`).
|
|
49
|
+
*/
|
|
50
|
+
void: "void",
|
|
51
|
+
/**
|
|
52
|
+
* Object with named properties.
|
|
53
|
+
*/
|
|
54
|
+
object: "object",
|
|
55
|
+
/**
|
|
56
|
+
* Sequential list of items.
|
|
57
|
+
*/
|
|
58
|
+
array: "array",
|
|
59
|
+
/**
|
|
60
|
+
* Fixed-length list with position-specific items.
|
|
61
|
+
*/
|
|
62
|
+
tuple: "tuple",
|
|
63
|
+
/**
|
|
64
|
+
* "One of" multiple schema members.
|
|
65
|
+
*/
|
|
66
|
+
union: "union",
|
|
67
|
+
/**
|
|
68
|
+
* "All of" multiple schema members.
|
|
69
|
+
*/
|
|
70
|
+
intersection: "intersection",
|
|
71
|
+
/**
|
|
72
|
+
* Enum schema.
|
|
73
|
+
*/
|
|
74
|
+
enum: "enum",
|
|
75
|
+
/**
|
|
76
|
+
* Reference to another schema.
|
|
77
|
+
*/
|
|
78
|
+
ref: "ref",
|
|
79
|
+
/**
|
|
80
|
+
* Calendar date (for example `2026-03-24`).
|
|
81
|
+
*/
|
|
82
|
+
date: "date",
|
|
83
|
+
/**
|
|
84
|
+
* Date-time value (for example `2026-03-24T09:00:00Z`).
|
|
85
|
+
*/
|
|
86
|
+
datetime: "datetime",
|
|
87
|
+
/**
|
|
88
|
+
* Time-only value (for example `09:00:00`).
|
|
89
|
+
*/
|
|
90
|
+
time: "time",
|
|
91
|
+
/**
|
|
92
|
+
* UUID value.
|
|
93
|
+
*/
|
|
94
|
+
uuid: "uuid",
|
|
95
|
+
/**
|
|
96
|
+
* Email address value.
|
|
97
|
+
*/
|
|
98
|
+
email: "email",
|
|
99
|
+
/**
|
|
100
|
+
* URL value.
|
|
101
|
+
*/
|
|
102
|
+
url: "url",
|
|
103
|
+
/**
|
|
104
|
+
* IPv4 address value.
|
|
105
|
+
*/
|
|
106
|
+
ipv4: "ipv4",
|
|
107
|
+
/**
|
|
108
|
+
* IPv6 address value.
|
|
109
|
+
*/
|
|
110
|
+
ipv6: "ipv6",
|
|
111
|
+
/**
|
|
112
|
+
* Binary/blob value.
|
|
113
|
+
*/
|
|
114
|
+
blob: "blob",
|
|
115
|
+
/**
|
|
116
|
+
* Impossible value (`never`).
|
|
117
|
+
*/
|
|
118
|
+
never: "never"
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* One indentation level, derived from {@link INDENT_SIZE}.
|
|
122
|
+
*/
|
|
123
|
+
const INDENT = Array.from({ length: 2 }, () => " ").join("");
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/guards.ts
|
|
126
|
+
/**
|
|
127
|
+
* Narrows a `SchemaNode` to the variant that matches `type`.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* const schema = createSchema({ type: 'string' })
|
|
132
|
+
* const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | null
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
function narrowSchema(node, type) {
|
|
136
|
+
return node?.type === type ? node : null;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Narrows an `OperationNode` to an `HttpOperationNode` so `method` and `path` are present.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* if (isHttpOperationNode(node)) {
|
|
144
|
+
* console.log(node.method, node.path)
|
|
145
|
+
* }
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
function isHttpOperationNode(node) {
|
|
149
|
+
return node.protocol === "http" || node.method !== void 0 && node.path !== void 0;
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
4
152
|
//#region src/defineNode.ts
|
|
5
153
|
/**
|
|
6
154
|
* Visitor callback names, one per traversable node kind, in traversal order.
|
|
@@ -905,6 +1053,358 @@ function createSchema(props) {
|
|
|
905
1053
|
return schemaDef.create(props);
|
|
906
1054
|
}
|
|
907
1055
|
//#endregion
|
|
908
|
-
|
|
1056
|
+
//#region src/registry.ts
|
|
1057
|
+
/**
|
|
1058
|
+
* Every node definition. Adding a node means adding its `defineNode` to one
|
|
1059
|
+
* `nodes/*.ts` file and listing it here. The visitor tables in `visitor.ts` derive from it.
|
|
1060
|
+
*/
|
|
1061
|
+
const nodeDefs = [
|
|
1062
|
+
inputDef,
|
|
1063
|
+
outputDef,
|
|
1064
|
+
operationDef,
|
|
1065
|
+
requestBodyDef,
|
|
1066
|
+
contentDef,
|
|
1067
|
+
responseDef,
|
|
1068
|
+
schemaDef,
|
|
1069
|
+
propertyDef,
|
|
1070
|
+
parameterDef,
|
|
1071
|
+
functionParameterDef,
|
|
1072
|
+
functionParametersDef,
|
|
1073
|
+
typeLiteralDef,
|
|
1074
|
+
indexedAccessTypeDef,
|
|
1075
|
+
objectBindingPatternDef,
|
|
1076
|
+
constDef,
|
|
1077
|
+
typeDef,
|
|
1078
|
+
functionDef,
|
|
1079
|
+
arrowFunctionDef,
|
|
1080
|
+
textDef,
|
|
1081
|
+
breakDef,
|
|
1082
|
+
jsxDef,
|
|
1083
|
+
importDef,
|
|
1084
|
+
exportDef,
|
|
1085
|
+
sourceDef,
|
|
1086
|
+
fileDef
|
|
1087
|
+
];
|
|
1088
|
+
//#endregion
|
|
1089
|
+
//#region src/visitor.ts
|
|
1090
|
+
/**
|
|
1091
|
+
* Child node fields per node kind, in traversal order (Babel's `VISITOR_KEYS`).
|
|
1092
|
+
* Derived from each definition's `children`.
|
|
1093
|
+
*/
|
|
1094
|
+
const VISITOR_KEYS = Object.fromEntries(nodeDefs.flatMap((def) => def.children ? [[def.kind, def.children]] : []));
|
|
1095
|
+
/**
|
|
1096
|
+
* Maps a node kind to the matching visitor callback name. Derived from each
|
|
1097
|
+
* definition's `visitorKey`.
|
|
1098
|
+
*/
|
|
1099
|
+
const VISITOR_KEY_BY_KIND = Object.fromEntries(nodeDefs.flatMap((def) => def.visitorKey ? [[def.kind, def.visitorKey]] : []));
|
|
1100
|
+
/**
|
|
1101
|
+
* Creates a small async concurrency limiter.
|
|
1102
|
+
*
|
|
1103
|
+
* At most `concurrency` tasks are in flight at once. Extra tasks are queued.
|
|
1104
|
+
*
|
|
1105
|
+
* @example
|
|
1106
|
+
* ```ts
|
|
1107
|
+
* const limit = createLimit(2)
|
|
1108
|
+
* for (const task of [taskA, taskB, taskC]) {
|
|
1109
|
+
* await limit(() => task())
|
|
1110
|
+
* }
|
|
1111
|
+
* // only 2 tasks run at the same time
|
|
1112
|
+
* ```
|
|
1113
|
+
*/
|
|
1114
|
+
function createLimit(concurrency) {
|
|
1115
|
+
let active = 0;
|
|
1116
|
+
const queue = [];
|
|
1117
|
+
function next() {
|
|
1118
|
+
if (active < concurrency && queue.length > 0) {
|
|
1119
|
+
active++;
|
|
1120
|
+
queue.shift()();
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
return function limit(fn) {
|
|
1124
|
+
return new Promise((resolve, reject) => {
|
|
1125
|
+
queue.push(() => {
|
|
1126
|
+
Promise.resolve(fn()).then(resolve, reject).finally(() => {
|
|
1127
|
+
active--;
|
|
1128
|
+
next();
|
|
1129
|
+
});
|
|
1130
|
+
});
|
|
1131
|
+
next();
|
|
1132
|
+
});
|
|
1133
|
+
};
|
|
1134
|
+
}
|
|
1135
|
+
const visitorKeysByKind = VISITOR_KEYS;
|
|
1136
|
+
/**
|
|
1137
|
+
* Returns `true` when `value` is an AST node (an object carrying a `kind`).
|
|
1138
|
+
*/
|
|
1139
|
+
function isNode(value) {
|
|
1140
|
+
return typeof value === "object" && value !== null && "kind" in value;
|
|
1141
|
+
}
|
|
1142
|
+
/**
|
|
1143
|
+
* Returns the immediate traversable children of `node` based on {@link VISITOR_KEYS}.
|
|
1144
|
+
*
|
|
1145
|
+
* `Schema` children are only included when `recurse` is `true`. Shallow mode skips them.
|
|
1146
|
+
*
|
|
1147
|
+
* @example
|
|
1148
|
+
* ```ts
|
|
1149
|
+
* const children = getChildren(operationNode, true)
|
|
1150
|
+
* // returns parameters, the request body, and responses
|
|
1151
|
+
* ```
|
|
1152
|
+
*/
|
|
1153
|
+
function* getChildren(node, recurse) {
|
|
1154
|
+
if (node.kind === "Schema" && !recurse) return;
|
|
1155
|
+
const keys = visitorKeysByKind[node.kind];
|
|
1156
|
+
if (!keys) return;
|
|
1157
|
+
const record = node;
|
|
1158
|
+
for (const key of keys) {
|
|
1159
|
+
const value = record[key];
|
|
1160
|
+
if (Array.isArray(value)) {
|
|
1161
|
+
for (const item of value) if (isNode(item)) yield item;
|
|
1162
|
+
} else if (isNode(value)) yield value;
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
/**
|
|
1166
|
+
* Runs the visitor callback that matches `node.kind` with the traversal
|
|
1167
|
+
* context. The result is a replacement node, a collected value, or `undefined`
|
|
1168
|
+
* when no callback is registered for the kind.
|
|
1169
|
+
*
|
|
1170
|
+
* Shared by `walk`, `transform`, and `collectLazy` so node-kind dispatch lives
|
|
1171
|
+
* in one place. `TResult` is the caller's expected return: the same node type
|
|
1172
|
+
* for `transform`, the collected value type for `collectLazy`, ignored for `walk`.
|
|
1173
|
+
*/
|
|
1174
|
+
function applyVisitor(node, visitor, parent) {
|
|
1175
|
+
const key = VISITOR_KEY_BY_KIND[node.kind];
|
|
1176
|
+
if (!key) return void 0;
|
|
1177
|
+
const fn = visitor[key];
|
|
1178
|
+
return fn?.(node, { parent });
|
|
1179
|
+
}
|
|
1180
|
+
/**
|
|
1181
|
+
* Async depth-first traversal for side effects. Visitor return values are
|
|
1182
|
+
* ignored. Use `transform` when you want to rewrite nodes.
|
|
1183
|
+
*
|
|
1184
|
+
* Sibling nodes at each depth run concurrently up to `options.concurrency`
|
|
1185
|
+
* (defaults to `WALK_CONCURRENCY`). Higher values overlap I/O-bound visitor
|
|
1186
|
+
* work. Lower values reduce memory pressure.
|
|
1187
|
+
*
|
|
1188
|
+
* @example Log every operation
|
|
1189
|
+
* ```ts
|
|
1190
|
+
* await walk(root, {
|
|
1191
|
+
* operation(node) {
|
|
1192
|
+
* console.log(node.operationId)
|
|
1193
|
+
* },
|
|
1194
|
+
* })
|
|
1195
|
+
* ```
|
|
1196
|
+
*
|
|
1197
|
+
* @example Only visit the root node
|
|
1198
|
+
* ```ts
|
|
1199
|
+
* await walk(root, { depth: 'shallow', input: () => {} })
|
|
1200
|
+
* ```
|
|
1201
|
+
*/
|
|
1202
|
+
async function walk(node, options) {
|
|
1203
|
+
return _walk(node, options, (options.depth ?? visitorDepths.deep) === visitorDepths.deep, createLimit(options.concurrency ?? 30), void 0);
|
|
1204
|
+
}
|
|
1205
|
+
async function _walk(node, visitor, recurse, limit, parent) {
|
|
1206
|
+
await limit(() => applyVisitor(node, visitor, parent));
|
|
1207
|
+
const children = Array.from(getChildren(node, recurse));
|
|
1208
|
+
if (children.length === 0) return;
|
|
1209
|
+
await Promise.all(children.map((child) => _walk(child, visitor, recurse, limit, node)));
|
|
1210
|
+
}
|
|
1211
|
+
function transform(node, options) {
|
|
1212
|
+
const { depth, parent, ...visitor } = options;
|
|
1213
|
+
const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep;
|
|
1214
|
+
return transformChildren(applyVisitor(node, visitor, parent) ?? node, options, recurse);
|
|
1215
|
+
}
|
|
1216
|
+
/**
|
|
1217
|
+
* Immutably rebuilds a node's children using {@link VISITOR_KEYS}, transforming
|
|
1218
|
+
* each child node and leaving non-node values (e.g. `additionalProperties: true`) intact.
|
|
1219
|
+
* `Schema` children are skipped in shallow mode.
|
|
1220
|
+
*/
|
|
1221
|
+
function transformChildren(node, options, recurse) {
|
|
1222
|
+
if (node.kind === "Schema" && !recurse) return node;
|
|
1223
|
+
const keys = visitorKeysByKind[node.kind];
|
|
1224
|
+
if (!keys) return node;
|
|
1225
|
+
const record = node;
|
|
1226
|
+
const childOptions = {
|
|
1227
|
+
...options,
|
|
1228
|
+
parent: node
|
|
1229
|
+
};
|
|
1230
|
+
let updates;
|
|
1231
|
+
for (const key of keys) {
|
|
1232
|
+
if (!(key in record)) continue;
|
|
1233
|
+
const value = record[key];
|
|
1234
|
+
if (Array.isArray(value)) {
|
|
1235
|
+
let changed = false;
|
|
1236
|
+
const mapped = value.map((item) => {
|
|
1237
|
+
if (!isNode(item)) return item;
|
|
1238
|
+
const next = transform(item, childOptions);
|
|
1239
|
+
if (next !== item) changed = true;
|
|
1240
|
+
return next;
|
|
1241
|
+
});
|
|
1242
|
+
if (changed) (updates ??= {})[key] = mapped;
|
|
1243
|
+
} else if (isNode(value)) {
|
|
1244
|
+
const next = transform(value, childOptions);
|
|
1245
|
+
if (next !== value) (updates ??= {})[key] = next;
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
return updates ? {
|
|
1249
|
+
...node,
|
|
1250
|
+
...updates
|
|
1251
|
+
} : node;
|
|
1252
|
+
}
|
|
1253
|
+
/**
|
|
1254
|
+
* Lazy depth-first collection pass. Yields every non-null value returned by
|
|
1255
|
+
* the visitor callbacks. Use `collect` for the eager array form.
|
|
1256
|
+
*
|
|
1257
|
+
* @example Collect every operationId
|
|
1258
|
+
* ```ts
|
|
1259
|
+
* const ids: string[] = []
|
|
1260
|
+
* for (const id of collectLazy<string>(root, {
|
|
1261
|
+
* operation(node) {
|
|
1262
|
+
* return node.operationId
|
|
1263
|
+
* },
|
|
1264
|
+
* })) {
|
|
1265
|
+
* ids.push(id)
|
|
1266
|
+
* }
|
|
1267
|
+
* ```
|
|
1268
|
+
*/
|
|
1269
|
+
function* collectLazy(node, options) {
|
|
1270
|
+
const { depth, parent, ...visitor } = options;
|
|
1271
|
+
const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep;
|
|
1272
|
+
const v = applyVisitor(node, visitor, parent);
|
|
1273
|
+
if (v != null) yield v;
|
|
1274
|
+
for (const child of getChildren(node, recurse)) yield* collectLazy(child, {
|
|
1275
|
+
...options,
|
|
1276
|
+
parent: node
|
|
1277
|
+
});
|
|
1278
|
+
}
|
|
1279
|
+
/**
|
|
1280
|
+
* Eager depth-first collection pass. Gathers every non-null value the visitor
|
|
1281
|
+
* callbacks return into an array.
|
|
1282
|
+
*
|
|
1283
|
+
* @example Collect every operationId
|
|
1284
|
+
* ```ts
|
|
1285
|
+
* const ids = collect<string>(root, {
|
|
1286
|
+
* operation(node) {
|
|
1287
|
+
* return node.operationId
|
|
1288
|
+
* },
|
|
1289
|
+
* })
|
|
1290
|
+
* ```
|
|
1291
|
+
*/
|
|
1292
|
+
function collect(node, options) {
|
|
1293
|
+
return Array.from(collectLazy(node, options));
|
|
1294
|
+
}
|
|
1295
|
+
//#endregion
|
|
1296
|
+
//#region src/utils/refs.ts
|
|
1297
|
+
const plainStringTypes = new Set([
|
|
1298
|
+
"string",
|
|
1299
|
+
"uuid",
|
|
1300
|
+
"email",
|
|
1301
|
+
"url",
|
|
1302
|
+
"datetime"
|
|
1303
|
+
]);
|
|
1304
|
+
/**
|
|
1305
|
+
* Returns the last path segment of a reference string.
|
|
1306
|
+
*
|
|
1307
|
+
* @example
|
|
1308
|
+
* `extractRefName('#/components/schemas/Pet') // 'Pet'`
|
|
1309
|
+
*/
|
|
1310
|
+
function extractRefName(ref) {
|
|
1311
|
+
return ref.split("/").at(-1) ?? ref;
|
|
1312
|
+
}
|
|
1313
|
+
/**
|
|
1314
|
+
* Resolves the schema name of a ref node. Uses the last segment of `ref` when set, otherwise falls
|
|
1315
|
+
* back to `name` then nested `schema.name`.
|
|
1316
|
+
*
|
|
1317
|
+
* Returns `null` for non-ref nodes or when no name resolves.
|
|
1318
|
+
*
|
|
1319
|
+
* @example
|
|
1320
|
+
* `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'`
|
|
1321
|
+
*/
|
|
1322
|
+
function resolveRefName(node) {
|
|
1323
|
+
if (!node || node.type !== "ref") return null;
|
|
1324
|
+
if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null;
|
|
1325
|
+
return node.name ?? node.schema?.name ?? null;
|
|
1326
|
+
}
|
|
1327
|
+
/**
|
|
1328
|
+
* Builds a PascalCase child schema name by joining a parent name and property name.
|
|
1329
|
+
* Returns `null` when there is no parent to nest under.
|
|
1330
|
+
*
|
|
1331
|
+
* @example Nested under a parent
|
|
1332
|
+
* `childName('Order', 'shipping_address') // 'OrderShippingAddress'`
|
|
1333
|
+
*
|
|
1334
|
+
* @example No parent
|
|
1335
|
+
* `childName(undefined, 'params') // null`
|
|
1336
|
+
*/
|
|
1337
|
+
function childName(parentName, propName) {
|
|
1338
|
+
return parentName ? pascalCase([parentName, propName].join(" ")) : null;
|
|
1339
|
+
}
|
|
1340
|
+
/**
|
|
1341
|
+
* Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any
|
|
1342
|
+
* empty parts.
|
|
1343
|
+
*
|
|
1344
|
+
* @example
|
|
1345
|
+
* `enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'`
|
|
1346
|
+
*/
|
|
1347
|
+
function enumPropName(parentName, propName, enumSuffix) {
|
|
1348
|
+
return pascalCase([
|
|
1349
|
+
parentName,
|
|
1350
|
+
propName,
|
|
1351
|
+
enumSuffix
|
|
1352
|
+
].filter(Boolean).join(" "));
|
|
1353
|
+
}
|
|
1354
|
+
/**
|
|
1355
|
+
* Merges a ref node with its resolved schema, giving usage-site fields precedence.
|
|
1356
|
+
*
|
|
1357
|
+
* Every field set on the ref node except `kind`, `type`, `name`, `ref`, and `schema` overrides the
|
|
1358
|
+
* same field in the resolved `node.schema` (for example `description`, `nullable`, `readOnly`,
|
|
1359
|
+
* `deprecated`). Fields left `undefined` on the ref do not shadow the resolved schema. Non-ref
|
|
1360
|
+
* nodes and refs without a resolved `schema` are returned unchanged.
|
|
1361
|
+
*
|
|
1362
|
+
* @example
|
|
1363
|
+
* ```ts
|
|
1364
|
+
* const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })
|
|
1365
|
+
* const merged = syncSchemaRef(ref) // merges with resolved Pet schema
|
|
1366
|
+
* ```
|
|
1367
|
+
*/
|
|
1368
|
+
function syncSchemaRef(node) {
|
|
1369
|
+
const ref = narrowSchema(node, "ref");
|
|
1370
|
+
if (!ref) return node;
|
|
1371
|
+
if (!ref.schema) return node;
|
|
1372
|
+
const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref;
|
|
1373
|
+
const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== void 0));
|
|
1374
|
+
return createSchema({
|
|
1375
|
+
...ref.schema,
|
|
1376
|
+
...definedOverrides
|
|
1377
|
+
});
|
|
1378
|
+
}
|
|
1379
|
+
/**
|
|
1380
|
+
* Type guard that returns `true` when a schema emits as a plain `string` type.
|
|
1381
|
+
*
|
|
1382
|
+
* Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`
|
|
1383
|
+
* types, returns `true` only when `representation` is `'string'` rather than `'date'`.
|
|
1384
|
+
*/
|
|
1385
|
+
function isStringType(node) {
|
|
1386
|
+
if (plainStringTypes.has(node.type)) return true;
|
|
1387
|
+
const temporal = narrowSchema(node, "date") ?? narrowSchema(node, "time");
|
|
1388
|
+
if (temporal) return temporal.representation !== "date";
|
|
1389
|
+
return false;
|
|
1390
|
+
}
|
|
1391
|
+
/**
|
|
1392
|
+
* Derives a {@link ParamGroupType} for a query or header group from the resolver.
|
|
1393
|
+
*
|
|
1394
|
+
* Returns `null` when there is no resolver, no params, or the group name equals the
|
|
1395
|
+
* individual param name (so there is no real group to emit).
|
|
1396
|
+
*/
|
|
1397
|
+
function resolveGroupType({ node, params, group, resolver }) {
|
|
1398
|
+
if (!resolver || !params.length) return null;
|
|
1399
|
+
const firstParam = params[0];
|
|
1400
|
+
const groupName = (group === "query" ? resolver.resolveQueryParamsName : resolver.resolveHeaderParamsName).call(resolver, node, firstParam);
|
|
1401
|
+
if (groupName === resolver.resolveParamName(node, firstParam)) return null;
|
|
1402
|
+
return {
|
|
1403
|
+
type: groupName,
|
|
1404
|
+
optional: params.every((p) => !p.required)
|
|
1405
|
+
};
|
|
1406
|
+
}
|
|
1407
|
+
//#endregion
|
|
1408
|
+
export { breakDef as $, createFunctionParameter as A, createExport as B, outputDef as C, requestBodyDef as D, createRequestBody as E, functionParameterDef as F, fileDef as G, createImport as H, functionParametersDef as I, extractStringsFromNodes as J, importDef as K, indexedAccessTypeDef as L, createIndexedAccessType as M, createObjectBindingPattern as N, createInput as O, createTypeLiteral as P, arrowFunctionDef as Q, objectBindingPatternDef as R, createOutput as S, operationDef as T, createSource as U, createFile as V, exportDef as W, contentDef as X, camelCase as Y, createContent as Z, createProperty as _, schemaTypes as _t, resolveGroupType as a, createJsx as at, parameterDef as b, collect as c, functionDef as ct, walk as d, typeDef as dt, constDef as et, nodeDefs as f, defineNode as ft, responseDef as g, INDENT as gt, createResponse as h, narrowSchema as ht, isStringType as i, createFunction as it, createFunctionParameters as j, inputDef as k, collectLazy as l, jsxDef as lt, schemaDef as m, isHttpOperationNode as mt, enumPropName as n, createBreak as nt, resolveRefName as o, createText as ot, createSchema as p, visitorKeys as pt, sourceDef as q, extractRefName as r, createConst as rt, syncSchemaRef as s, createType as st, childName as t, createArrowFunction as tt, transform as u, textDef as ut, propertyDef as v, createOperation as w, optionality as x, createParameter as y, typeLiteralDef as z };
|
|
909
1409
|
|
|
910
|
-
//# sourceMappingURL=
|
|
1410
|
+
//# sourceMappingURL=refs-CXp6uOHL.js.map
|