kubb 5.0.0-beta.80 → 5.0.0-beta.82
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/ast.cjs +374 -0
- package/dist/ast.d.ts +3 -0
- package/dist/ast.js +2 -0
- package/dist/config.cjs +3 -0
- package/dist/config.d.ts +3 -0
- package/dist/config.js +2 -0
- package/dist/defineConfig-BXme6pNF.cjs +117 -0
- package/dist/defineConfig-BXme6pNF.cjs.map +1 -0
- package/dist/defineConfig-Bz5OdPiM.d.ts +63 -0
- package/dist/defineConfig-D01AIFC1.js +112 -0
- package/dist/defineConfig-D01AIFC1.js.map +1 -0
- package/dist/index.cjs +8 -111
- package/dist/index.d.ts +3 -63
- package/dist/index.js +3 -112
- package/dist/jsx/jsx-dev-runtime.cjs +9 -0
- package/dist/jsx/jsx-dev-runtime.d.ts +1 -0
- package/dist/jsx/jsx-dev-runtime.js +2 -0
- package/dist/jsx/jsx-runtime.cjs +9 -0
- package/dist/jsx/jsx-runtime.d.ts +1 -0
- package/dist/jsx/jsx-runtime.js +2 -0
- package/dist/jsx.cjs +18 -0
- package/dist/jsx.d.ts +2 -0
- package/dist/jsx.js +3 -0
- package/dist/kit/testing.cjs +9 -0
- package/dist/kit/testing.d.ts +1 -0
- package/dist/kit/testing.js +2 -0
- package/dist/kit.cjs +9 -0
- package/dist/kit.d.ts +1 -0
- package/dist/kit.js +2 -0
- package/package.json +39 -12
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/ast.cjs
ADDED
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _kubb_ast = require("@kubb/ast");
|
|
3
|
+
Object.defineProperty(exports, "applyMacros", {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
get: function() {
|
|
6
|
+
return _kubb_ast.applyMacros;
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
Object.defineProperty(exports, "arrowFunctionDef", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return _kubb_ast.arrowFunctionDef;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(exports, "breakDef", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function() {
|
|
18
|
+
return _kubb_ast.breakDef;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(exports, "buildJSDoc", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function() {
|
|
24
|
+
return _kubb_ast.buildJSDoc;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
Object.defineProperty(exports, "buildList", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function() {
|
|
30
|
+
return _kubb_ast.buildList;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(exports, "buildObject", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: function() {
|
|
36
|
+
return _kubb_ast.buildObject;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(exports, "childName", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get: function() {
|
|
42
|
+
return _kubb_ast.childName;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(exports, "collect", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: function() {
|
|
48
|
+
return _kubb_ast.collect;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(exports, "collectUsedSchemaNames", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function() {
|
|
54
|
+
return _kubb_ast.collectUsedSchemaNames;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
Object.defineProperty(exports, "composeMacros", {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
get: function() {
|
|
60
|
+
return _kubb_ast.composeMacros;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
Object.defineProperty(exports, "constDef", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
get: function() {
|
|
66
|
+
return _kubb_ast.constDef;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
Object.defineProperty(exports, "containsCircularRef", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
get: function() {
|
|
72
|
+
return _kubb_ast.containsCircularRef;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
Object.defineProperty(exports, "contentDef", {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
get: function() {
|
|
78
|
+
return _kubb_ast.contentDef;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
Object.defineProperty(exports, "createPrinter", {
|
|
82
|
+
enumerable: true,
|
|
83
|
+
get: function() {
|
|
84
|
+
return _kubb_ast.createPrinter;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
Object.defineProperty(exports, "defineDialect", {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
get: function() {
|
|
90
|
+
return _kubb_ast.defineDialect;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
Object.defineProperty(exports, "defineMacro", {
|
|
94
|
+
enumerable: true,
|
|
95
|
+
get: function() {
|
|
96
|
+
return _kubb_ast.defineMacro;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
Object.defineProperty(exports, "defineNode", {
|
|
100
|
+
enumerable: true,
|
|
101
|
+
get: function() {
|
|
102
|
+
return _kubb_ast.defineNode;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
Object.defineProperty(exports, "enumPropName", {
|
|
106
|
+
enumerable: true,
|
|
107
|
+
get: function() {
|
|
108
|
+
return _kubb_ast.enumPropName;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
Object.defineProperty(exports, "exportDef", {
|
|
112
|
+
enumerable: true,
|
|
113
|
+
get: function() {
|
|
114
|
+
return _kubb_ast.exportDef;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
Object.defineProperty(exports, "extractRefName", {
|
|
118
|
+
enumerable: true,
|
|
119
|
+
get: function() {
|
|
120
|
+
return _kubb_ast.extractRefName;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
Object.defineProperty(exports, "extractStringsFromNodes", {
|
|
124
|
+
enumerable: true,
|
|
125
|
+
get: function() {
|
|
126
|
+
return _kubb_ast.extractStringsFromNodes;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
Object.defineProperty(exports, "fileDef", {
|
|
130
|
+
enumerable: true,
|
|
131
|
+
get: function() {
|
|
132
|
+
return _kubb_ast.fileDef;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
Object.defineProperty(exports, "findCircularSchemas", {
|
|
136
|
+
enumerable: true,
|
|
137
|
+
get: function() {
|
|
138
|
+
return _kubb_ast.findCircularSchemas;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
Object.defineProperty(exports, "functionDef", {
|
|
142
|
+
enumerable: true,
|
|
143
|
+
get: function() {
|
|
144
|
+
return _kubb_ast.functionDef;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
Object.defineProperty(exports, "getNestedAccessor", {
|
|
148
|
+
enumerable: true,
|
|
149
|
+
get: function() {
|
|
150
|
+
return _kubb_ast.getNestedAccessor;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
Object.defineProperty(exports, "importDef", {
|
|
154
|
+
enumerable: true,
|
|
155
|
+
get: function() {
|
|
156
|
+
return _kubb_ast.importDef;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
Object.defineProperty(exports, "inputDef", {
|
|
160
|
+
enumerable: true,
|
|
161
|
+
get: function() {
|
|
162
|
+
return _kubb_ast.inputDef;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
Object.defineProperty(exports, "isHttpOperationNode", {
|
|
166
|
+
enumerable: true,
|
|
167
|
+
get: function() {
|
|
168
|
+
return _kubb_ast.isHttpOperationNode;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
Object.defineProperty(exports, "isStringType", {
|
|
172
|
+
enumerable: true,
|
|
173
|
+
get: function() {
|
|
174
|
+
return _kubb_ast.isStringType;
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
Object.defineProperty(exports, "isValidVarName", {
|
|
178
|
+
enumerable: true,
|
|
179
|
+
get: function() {
|
|
180
|
+
return _kubb_ast.isValidVarName;
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
Object.defineProperty(exports, "jsStringEscape", {
|
|
184
|
+
enumerable: true,
|
|
185
|
+
get: function() {
|
|
186
|
+
return _kubb_ast.jsStringEscape;
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
Object.defineProperty(exports, "jsxDef", {
|
|
190
|
+
enumerable: true,
|
|
191
|
+
get: function() {
|
|
192
|
+
return _kubb_ast.jsxDef;
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
Object.defineProperty(exports, "lazyGetter", {
|
|
196
|
+
enumerable: true,
|
|
197
|
+
get: function() {
|
|
198
|
+
return _kubb_ast.lazyGetter;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
Object.defineProperty(exports, "macroDiscriminatorEnum", {
|
|
202
|
+
enumerable: true,
|
|
203
|
+
get: function() {
|
|
204
|
+
return _kubb_ast.macroDiscriminatorEnum;
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
Object.defineProperty(exports, "macroEnumName", {
|
|
208
|
+
enumerable: true,
|
|
209
|
+
get: function() {
|
|
210
|
+
return _kubb_ast.macroEnumName;
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
Object.defineProperty(exports, "macroSimplifyUnion", {
|
|
214
|
+
enumerable: true,
|
|
215
|
+
get: function() {
|
|
216
|
+
return _kubb_ast.macroSimplifyUnion;
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
Object.defineProperty(exports, "mapSchemaItems", {
|
|
220
|
+
enumerable: true,
|
|
221
|
+
get: function() {
|
|
222
|
+
return _kubb_ast.mapSchemaItems;
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
Object.defineProperty(exports, "mapSchemaMembers", {
|
|
226
|
+
enumerable: true,
|
|
227
|
+
get: function() {
|
|
228
|
+
return _kubb_ast.mapSchemaMembers;
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
Object.defineProperty(exports, "mapSchemaProperties", {
|
|
232
|
+
enumerable: true,
|
|
233
|
+
get: function() {
|
|
234
|
+
return _kubb_ast.mapSchemaProperties;
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
Object.defineProperty(exports, "mergeAdjacentObjectsLazy", {
|
|
238
|
+
enumerable: true,
|
|
239
|
+
get: function() {
|
|
240
|
+
return _kubb_ast.mergeAdjacentObjectsLazy;
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
Object.defineProperty(exports, "narrowSchema", {
|
|
244
|
+
enumerable: true,
|
|
245
|
+
get: function() {
|
|
246
|
+
return _kubb_ast.narrowSchema;
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
Object.defineProperty(exports, "nodeDefs", {
|
|
250
|
+
enumerable: true,
|
|
251
|
+
get: function() {
|
|
252
|
+
return _kubb_ast.nodeDefs;
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
Object.defineProperty(exports, "objectKey", {
|
|
256
|
+
enumerable: true,
|
|
257
|
+
get: function() {
|
|
258
|
+
return _kubb_ast.objectKey;
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
Object.defineProperty(exports, "operationDef", {
|
|
262
|
+
enumerable: true,
|
|
263
|
+
get: function() {
|
|
264
|
+
return _kubb_ast.operationDef;
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
Object.defineProperty(exports, "optionality", {
|
|
268
|
+
enumerable: true,
|
|
269
|
+
get: function() {
|
|
270
|
+
return _kubb_ast.optionality;
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
Object.defineProperty(exports, "outputDef", {
|
|
274
|
+
enumerable: true,
|
|
275
|
+
get: function() {
|
|
276
|
+
return _kubb_ast.outputDef;
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
Object.defineProperty(exports, "parameterDef", {
|
|
280
|
+
enumerable: true,
|
|
281
|
+
get: function() {
|
|
282
|
+
return _kubb_ast.parameterDef;
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
Object.defineProperty(exports, "propertyDef", {
|
|
286
|
+
enumerable: true,
|
|
287
|
+
get: function() {
|
|
288
|
+
return _kubb_ast.propertyDef;
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
Object.defineProperty(exports, "requestBodyDef", {
|
|
292
|
+
enumerable: true,
|
|
293
|
+
get: function() {
|
|
294
|
+
return _kubb_ast.requestBodyDef;
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
Object.defineProperty(exports, "responseDef", {
|
|
298
|
+
enumerable: true,
|
|
299
|
+
get: function() {
|
|
300
|
+
return _kubb_ast.responseDef;
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
Object.defineProperty(exports, "schemaDef", {
|
|
304
|
+
enumerable: true,
|
|
305
|
+
get: function() {
|
|
306
|
+
return _kubb_ast.schemaDef;
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
Object.defineProperty(exports, "schemaTypes", {
|
|
310
|
+
enumerable: true,
|
|
311
|
+
get: function() {
|
|
312
|
+
return _kubb_ast.schemaTypes;
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
Object.defineProperty(exports, "sourceDef", {
|
|
316
|
+
enumerable: true,
|
|
317
|
+
get: function() {
|
|
318
|
+
return _kubb_ast.sourceDef;
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
Object.defineProperty(exports, "stringify", {
|
|
322
|
+
enumerable: true,
|
|
323
|
+
get: function() {
|
|
324
|
+
return _kubb_ast.stringify;
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
Object.defineProperty(exports, "stringifyObject", {
|
|
328
|
+
enumerable: true,
|
|
329
|
+
get: function() {
|
|
330
|
+
return _kubb_ast.stringifyObject;
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
Object.defineProperty(exports, "syncSchemaRef", {
|
|
334
|
+
enumerable: true,
|
|
335
|
+
get: function() {
|
|
336
|
+
return _kubb_ast.syncSchemaRef;
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
Object.defineProperty(exports, "textDef", {
|
|
340
|
+
enumerable: true,
|
|
341
|
+
get: function() {
|
|
342
|
+
return _kubb_ast.textDef;
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
Object.defineProperty(exports, "toRegExpString", {
|
|
346
|
+
enumerable: true,
|
|
347
|
+
get: function() {
|
|
348
|
+
return _kubb_ast.toRegExpString;
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
Object.defineProperty(exports, "transform", {
|
|
352
|
+
enumerable: true,
|
|
353
|
+
get: function() {
|
|
354
|
+
return _kubb_ast.transform;
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
Object.defineProperty(exports, "trimQuotes", {
|
|
358
|
+
enumerable: true,
|
|
359
|
+
get: function() {
|
|
360
|
+
return _kubb_ast.trimQuotes;
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
Object.defineProperty(exports, "typeDef", {
|
|
364
|
+
enumerable: true,
|
|
365
|
+
get: function() {
|
|
366
|
+
return _kubb_ast.typeDef;
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
Object.defineProperty(exports, "walk", {
|
|
370
|
+
enumerable: true,
|
|
371
|
+
get: function() {
|
|
372
|
+
return _kubb_ast.walk;
|
|
373
|
+
}
|
|
374
|
+
});
|
package/dist/ast.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { applyMacros, arrowFunctionDef, breakDef, buildJSDoc, buildList, buildObject, childName, collect, collectUsedSchemaNames, composeMacros, constDef, containsCircularRef, contentDef, createPrinter, defineDialect, defineMacro, defineNode, enumPropName, exportDef, extractRefName, extractStringsFromNodes, fileDef, findCircularSchemas, functionDef, getNestedAccessor, importDef, inputDef, isHttpOperationNode, isStringType, isValidVarName, jsStringEscape, jsxDef, lazyGetter, macroDiscriminatorEnum, macroEnumName, macroSimplifyUnion, mapSchemaItems, mapSchemaMembers, mapSchemaProperties, mergeAdjacentObjectsLazy, narrowSchema, nodeDefs, objectKey, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, responseDef, schemaDef, schemaTypes, sourceDef, stringify, stringifyObject, syncSchemaRef, textDef, toRegExpString, transform, trimQuotes, typeDef, walk } from "@kubb/ast";
|
|
2
|
+
export type * from "@kubb/ast";
|
|
3
|
+
export { applyMacros, arrowFunctionDef, breakDef, buildJSDoc, buildList, buildObject, childName, collect, collectUsedSchemaNames, composeMacros, constDef, containsCircularRef, contentDef, createPrinter, defineDialect, defineMacro, defineNode, enumPropName, exportDef, extractRefName, extractStringsFromNodes, fileDef, findCircularSchemas, functionDef, getNestedAccessor, importDef, inputDef, isHttpOperationNode, isStringType, isValidVarName, jsStringEscape, jsxDef, lazyGetter, macroDiscriminatorEnum, macroEnumName, macroSimplifyUnion, mapSchemaItems, mapSchemaMembers, mapSchemaProperties, mergeAdjacentObjectsLazy, narrowSchema, nodeDefs, objectKey, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, responseDef, schemaDef, schemaTypes, sourceDef, stringify, stringifyObject, syncSchemaRef, textDef, toRegExpString, transform, trimQuotes, typeDef, walk };
|
package/dist/ast.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { applyMacros, arrowFunctionDef, breakDef, buildJSDoc, buildList, buildObject, childName, collect, collectUsedSchemaNames, composeMacros, constDef, containsCircularRef, contentDef, createPrinter, defineDialect, defineMacro, defineNode, enumPropName, exportDef, extractRefName, extractStringsFromNodes, fileDef, findCircularSchemas, functionDef, getNestedAccessor, importDef, inputDef, isHttpOperationNode, isStringType, isValidVarName, jsStringEscape, jsxDef, lazyGetter, macroDiscriminatorEnum, macroEnumName, macroSimplifyUnion, mapSchemaItems, mapSchemaMembers, mapSchemaProperties, mergeAdjacentObjectsLazy, narrowSchema, nodeDefs, objectKey, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, responseDef, schemaDef, schemaTypes, sourceDef, stringify, stringifyObject, syncSchemaRef, textDef, toRegExpString, transform, trimQuotes, typeDef, walk } from "@kubb/ast";
|
|
2
|
+
export { applyMacros, arrowFunctionDef, breakDef, buildJSDoc, buildList, buildObject, childName, collect, collectUsedSchemaNames, composeMacros, constDef, containsCircularRef, contentDef, createPrinter, defineDialect, defineMacro, defineNode, enumPropName, exportDef, extractRefName, extractStringsFromNodes, fileDef, findCircularSchemas, functionDef, getNestedAccessor, importDef, inputDef, isHttpOperationNode, isStringType, isValidVarName, jsStringEscape, jsxDef, lazyGetter, macroDiscriminatorEnum, macroEnumName, macroSimplifyUnion, mapSchemaItems, mapSchemaMembers, mapSchemaProperties, mergeAdjacentObjectsLazy, narrowSchema, nodeDefs, objectKey, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, responseDef, schemaDef, schemaTypes, sourceDef, stringify, stringifyObject, syncSchemaRef, textDef, toRegExpString, transform, trimQuotes, typeDef, walk };
|
package/dist/config.cjs
ADDED
package/dist/config.d.ts
ADDED
package/dist/config.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
//#endregion
|
|
2
|
+
let _kubb_core = require("@kubb/core");
|
|
3
|
+
let _kubb_adapter_oas = require("@kubb/adapter-oas");
|
|
4
|
+
let _kubb_plugin_barrel = require("@kubb/plugin-barrel");
|
|
5
|
+
let _kubb_parser_ts = require("@kubb/parser-ts");
|
|
6
|
+
let _kubb_parser_md = require("@kubb/parser-md");
|
|
7
|
+
//#region ../../internals/utils/src/promise.ts
|
|
8
|
+
/** Returns `true` when `result` is a thenable `Promise`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* isPromise(Promise.resolve(1)) // true
|
|
13
|
+
* isPromise(42) // false
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
function isPromise(result) {
|
|
17
|
+
return result !== null && result !== void 0 && typeof result["then"] === "function";
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/defineConfig.ts
|
|
21
|
+
/**
|
|
22
|
+
* Applies default `root`, adapter, parsers, plugins, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.
|
|
23
|
+
*
|
|
24
|
+
* - `root` defaults to `process.cwd()`
|
|
25
|
+
* - `adapter` defaults to `adapterOas()`
|
|
26
|
+
* - `parsers` defaults to `[parserTs, parserTsx, parserMd]`
|
|
27
|
+
* - `reporters` defaults to `[cliReporter, jsonReporter, fileReporter]`
|
|
28
|
+
* - `plugins` gets `pluginBarrel()` appended when none is already present
|
|
29
|
+
* - `output.barrel` defaults to `{ type: 'named' }` only when `pluginBarrel` is part of `plugins`.
|
|
30
|
+
* When the user provides a plugins list without `pluginBarrel`, `barrel` is left untouched.
|
|
31
|
+
* - `output.format` defaults to `false`
|
|
32
|
+
* - `output.lint` defaults to `false`
|
|
33
|
+
*/
|
|
34
|
+
function applyDefaults(config) {
|
|
35
|
+
const plugins = config.plugins?.some((p) => p.name === _kubb_plugin_barrel.pluginBarrelName) ? config.plugins ?? [] : [...config.plugins ?? [], (0, _kubb_plugin_barrel.pluginBarrel)()];
|
|
36
|
+
const hasBarrelPlugin = plugins.some((p) => p.name === _kubb_plugin_barrel.pluginBarrelName);
|
|
37
|
+
const output = { ...config.output };
|
|
38
|
+
if (hasBarrelPlugin && output.barrel === void 0) output.barrel = { type: "named" };
|
|
39
|
+
if (output.format === void 0) output.format = false;
|
|
40
|
+
if (output.lint === void 0) output.lint = false;
|
|
41
|
+
return {
|
|
42
|
+
...config,
|
|
43
|
+
root: config.root || process.cwd(),
|
|
44
|
+
adapter: config.adapter ?? (0, _kubb_adapter_oas.adapterOas)(),
|
|
45
|
+
parsers: config.parsers?.length ? config.parsers : [
|
|
46
|
+
_kubb_parser_ts.parserTs,
|
|
47
|
+
_kubb_parser_ts.parserTsx,
|
|
48
|
+
_kubb_parser_md.parserMd
|
|
49
|
+
],
|
|
50
|
+
reporters: config.reporters?.length ? config.reporters : [
|
|
51
|
+
_kubb_core.cliReporter,
|
|
52
|
+
_kubb_core.jsonReporter,
|
|
53
|
+
_kubb_core.fileReporter
|
|
54
|
+
],
|
|
55
|
+
plugins,
|
|
56
|
+
output
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function normalizeConfig(config) {
|
|
60
|
+
if (Array.isArray(config)) return config.map(applyDefaults);
|
|
61
|
+
return applyDefaults(config);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Defines a Kubb build configuration and fills in defaults for any omitted fields.
|
|
65
|
+
*
|
|
66
|
+
* Defaults applied when omitted:
|
|
67
|
+
* - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).
|
|
68
|
+
* - `parsers` → `[parserTs, parserTsx, parserMd]`.
|
|
69
|
+
* - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.
|
|
70
|
+
* - `plugins` → `pluginBarrel()` is appended when not already present.
|
|
71
|
+
* - `output.barrel` → `{ type: 'named' }` only when `pluginBarrel` is
|
|
72
|
+
* in the plugins list.
|
|
73
|
+
* - `output.format` and `output.lint` → `false`.
|
|
74
|
+
*
|
|
75
|
+
* Accepts a config object, an array of configs, a Promise resolving to one,
|
|
76
|
+
* or a function that receives the parsed CLI options and returns any of the
|
|
77
|
+
* above. The return type is preserved so async/array variants stay typed.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* import { defineConfig } from 'kubb'
|
|
82
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
83
|
+
*
|
|
84
|
+
* export default defineConfig({
|
|
85
|
+
* input: { path: './petStore.yaml' },
|
|
86
|
+
* output: { path: './src/gen' },
|
|
87
|
+
* plugins: [pluginTs()],
|
|
88
|
+
* })
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @example Function form with CLI options
|
|
92
|
+
* ```ts
|
|
93
|
+
* import { defineConfig } from 'kubb'
|
|
94
|
+
*
|
|
95
|
+
* export default defineConfig(({ input }) => ({
|
|
96
|
+
* input: { path: input ?? './petStore.yaml' },
|
|
97
|
+
* output: { path: './src/gen' },
|
|
98
|
+
* plugins: [],
|
|
99
|
+
* }))
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
function defineConfig(config) {
|
|
103
|
+
if (typeof config === "function") return (async (cli) => {
|
|
104
|
+
return normalizeConfig(await config(cli));
|
|
105
|
+
});
|
|
106
|
+
if (isPromise(config)) return config.then((resolved) => normalizeConfig(resolved));
|
|
107
|
+
return normalizeConfig(config);
|
|
108
|
+
}
|
|
109
|
+
//#endregion
|
|
110
|
+
Object.defineProperty(exports, "defineConfig", {
|
|
111
|
+
enumerable: true,
|
|
112
|
+
get: function() {
|
|
113
|
+
return defineConfig;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
//# sourceMappingURL=defineConfig-BXme6pNF.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineConfig-BXme6pNF.cjs","names":["pluginBarrelName","parserTs","parserTsx","parserMd","cliReporter","jsonReporter","fileReporter"],"sources":["../../../internals/utils/src/promise.ts","../src/defineConfig.ts"],"sourcesContent":["/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Wraps `factory` with a keyed cache backed by the provided store.\n *\n * Pass a `WeakMap` for object keys (results are GC-eligible when the key is\n * collected) or a `Map` for primitive keys. For multi-argument functions,\n * nest two `memoize` calls — the outer keyed by the first argument, the\n * inner (created once per outer miss) keyed by the second.\n *\n * Because the cache is owned by the caller, it can be shared, inspected, or\n * cleared independently of the memoized function.\n *\n * @example Single WeakMap key\n * ```ts\n * const cache = new WeakMap<SchemaNode, Set<string>>()\n * const getRefs = memoize(cache, (node) => collectRefs(node))\n * ```\n *\n * @example Single Map key (primitive)\n * ```ts\n * const cache = new Map<string, Resolver>()\n * const getResolver = memoize(cache, (name) => buildResolver(name))\n * ```\n *\n * @example Two-level (object + primitive)\n * ```ts\n * const outer = new WeakMap<Params[], Map<string, Params[]>>()\n * const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))\n * fn(params)('camelcase')\n * ```\n */\nexport function memoize<TKey, TValue>(store: Store<TKey, TValue>, factory: (key: TKey) => TValue): (key: TKey) => TValue {\n return (key: TKey): TValue => {\n if (store.has(key)) return store.get(key)!\n const value = factory(key)\n store.set(key, value)\n return value\n }\n}\n\n/**\n * Container that switches between an eager `Array<T>` and a lazy `AsyncIterable<T>`.\n *\n * `Array<T>` by default. With `Stream` set to `true` it becomes `AsyncIterable<T>`, so large\n * collections can be produced lazily without holding every item in memory. Pairs with\n * {@link arrayToAsyncIterable}, which lifts a plain array into the streaming form.\n *\n * @example\n * ```ts\n * type Eager = Streamable<number> // Array<number>\n * type Lazy = Streamable<number, true> // AsyncIterable<number>\n * ```\n */\nexport type Streamable<T, Stream extends boolean = false> = Stream extends true ? AsyncIterable<T> : Array<T>\n\n/**\n * Wraps a plain array in a reusable `AsyncIterable`.\n * Each `[Symbol.asyncIterator]()` call returns a fresh generator so the\n * iterable can be consumed multiple times (e.g. once per plugin pre-scan).\n *\n * @example\n * ```ts\n * const stream = arrayToAsyncIterable([1, 2, 3])\n * for await (const n of stream) console.log(n) // 1, 2, 3\n * ```\n */\nexport function arrayToAsyncIterable<T>(arr: ReadonlyArray<T>): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]() {\n return (async function* () {\n yield* arr\n })()\n },\n }\n}\n","import { isPromise, type PossiblePromise } from '@internals/utils'\nimport { adapterOas } from '@kubb/adapter-oas'\nimport { cliReporter, type CLIOptions, fileReporter, jsonReporter, type UserConfig } from '@kubb/core'\nimport { pluginBarrel, pluginBarrelName } from '@kubb/plugin-barrel'\nimport { parserTs, parserTsx } from '@kubb/parser-ts'\nimport { parserMd } from '@kubb/parser-md'\n\ntype AnyConfigResult = UserConfig<any> | Array<UserConfig<any>>\ntype ConfigInput = AnyConfigResult | Promise<AnyConfigResult> | ((cli: CLIOptions) => PossiblePromise<AnyConfigResult>)\ntype NormalizeConfig<TConfig> =\n TConfig extends Array<UserConfig<infer TInput>> ? Array<UserConfig<TInput>> : TConfig extends UserConfig<infer TInput> ? UserConfig<TInput> : never\ntype DefinedConfig<TConfig extends ConfigInput> = TConfig extends (cli: CLIOptions) => PossiblePromise<infer TResult>\n ? (cli: CLIOptions) => Promise<NormalizeConfig<TResult>>\n : TConfig extends Promise<infer TResult>\n ? Promise<NormalizeConfig<TResult>>\n : NormalizeConfig<TConfig>\n\n/**\n * Applies default `root`, adapter, parsers, plugins, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.\n *\n * - `root` defaults to `process.cwd()`\n * - `adapter` defaults to `adapterOas()`\n * - `parsers` defaults to `[parserTs, parserTsx, parserMd]`\n * - `reporters` defaults to `[cliReporter, jsonReporter, fileReporter]`\n * - `plugins` gets `pluginBarrel()` appended when none is already present\n * - `output.barrel` defaults to `{ type: 'named' }` only when `pluginBarrel` is part of `plugins`.\n * When the user provides a plugins list without `pluginBarrel`, `barrel` is left untouched.\n * - `output.format` defaults to `false`\n * - `output.lint` defaults to `false`\n */\nfunction applyDefaults<TInput>(config: UserConfig<TInput>): UserConfig<TInput> {\n const alreadyHasBarrel = config.plugins?.some((p) => p.name === pluginBarrelName)\n const plugins = alreadyHasBarrel ? (config.plugins ?? []) : [...(config.plugins ?? []), pluginBarrel()]\n const hasBarrelPlugin = plugins.some((p) => p.name === pluginBarrelName)\n\n const output = { ...config.output }\n if (hasBarrelPlugin && output.barrel === undefined) {\n output.barrel = { type: 'named' }\n }\n if (output.format === undefined) {\n output.format = false\n }\n if (output.lint === undefined) {\n output.lint = false\n }\n\n return {\n ...config,\n root: config.root || process.cwd(),\n adapter: config.adapter ?? adapterOas(),\n parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx, parserMd],\n reporters: config.reporters?.length ? config.reporters : [cliReporter, jsonReporter, fileReporter],\n plugins,\n output,\n }\n}\n\nfunction normalizeConfig<TInput>(config: UserConfig<TInput> | Array<UserConfig<TInput>>): UserConfig<TInput> | Array<UserConfig<TInput>> {\n if (Array.isArray(config)) {\n return config.map(applyDefaults)\n }\n\n return applyDefaults(config)\n}\n\n/**\n * Defines a Kubb build configuration and fills in defaults for any omitted fields.\n *\n * Defaults applied when omitted:\n * - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).\n * - `parsers` → `[parserTs, parserTsx, parserMd]`.\n * - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.\n * - `plugins` → `pluginBarrel()` is appended when not already present.\n * - `output.barrel` → `{ type: 'named' }` only when `pluginBarrel` is\n * in the plugins list.\n * - `output.format` and `output.lint` → `false`.\n *\n * Accepts a config object, an array of configs, a Promise resolving to one,\n * or a function that receives the parsed CLI options and returns any of the\n * above. The return type is preserved so async/array variants stay typed.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginTs } from '@kubb/plugin-ts'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [pluginTs()],\n * })\n * ```\n *\n * @example Function form with CLI options\n * ```ts\n * import { defineConfig } from 'kubb'\n *\n * export default defineConfig(({ input }) => ({\n * input: { path: input ?? './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [],\n * }))\n * ```\n */\nexport function defineConfig<TConfig extends ConfigInput>(config: TConfig): DefinedConfig<TConfig> {\n if (typeof config === 'function') {\n return (async (cli: CLIOptions) => {\n return normalizeConfig(await config(cli))\n }) as DefinedConfig<TConfig>\n }\n\n if (isPromise(config)) {\n return config.then((resolved) => normalizeConfig(resolved)) as DefinedConfig<TConfig>\n }\n\n return normalizeConfig(config) as DefinedConfig<TConfig>\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,SAAgB,UAAa,QAAkD;CAC7E,OAAO,WAAW,QAAQ,WAAW,KAAA,KAAa,OAAQ,OAAmC,YAAY;AAC3G;;;;;;;;;;;;;;;;ACSA,SAAS,cAAsB,QAAgD;CAE7E,MAAM,UADmB,OAAO,SAAS,MAAM,MAAM,EAAE,SAASA,oBAAAA,gBAAgB,IAC5C,OAAO,WAAW,CAAC,IAAK,CAAC,GAAI,OAAO,WAAW,CAAC,IAAA,GAAA,oBAAA,aAAA,CAAiB,CAAC;CACtG,MAAM,kBAAkB,QAAQ,MAAM,MAAM,EAAE,SAASA,oBAAAA,gBAAgB;CAEvE,MAAM,SAAS,EAAE,GAAG,OAAO,OAAO;CAClC,IAAI,mBAAmB,OAAO,WAAW,KAAA,GACvC,OAAO,SAAS,EAAE,MAAM,QAAQ;CAElC,IAAI,OAAO,WAAW,KAAA,GACpB,OAAO,SAAS;CAElB,IAAI,OAAO,SAAS,KAAA,GAClB,OAAO,OAAO;CAGhB,OAAO;EACL,GAAG;EACH,MAAM,OAAO,QAAQ,QAAQ,IAAI;EACjC,SAAS,OAAO,YAAA,GAAA,kBAAA,WAAA,CAAsB;EACtC,SAAS,OAAO,SAAS,SAAS,OAAO,UAAU;GAACC,gBAAAA;GAAUC,gBAAAA;GAAWC,gBAAAA;EAAQ;EACjF,WAAW,OAAO,WAAW,SAAS,OAAO,YAAY;GAACC,WAAAA;GAAaC,WAAAA;GAAcC,WAAAA;EAAY;EACjG;EACA;CACF;AACF;AAEA,SAAS,gBAAwB,QAAwG;CACvI,IAAI,MAAM,QAAQ,MAAM,GACtB,OAAO,OAAO,IAAI,aAAa;CAGjC,OAAO,cAAc,MAAM;AAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,aAA0C,QAAyC;CACjG,IAAI,OAAO,WAAW,YACpB,QAAQ,OAAO,QAAoB;EACjC,OAAO,gBAAgB,MAAM,OAAO,GAAG,CAAC;CAC1C;CAGF,IAAI,UAAU,MAAM,GAClB,OAAO,OAAO,MAAM,aAAa,gBAAgB,QAAQ,CAAC;CAG5D,OAAO,gBAAgB,MAAM;AAC/B"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
|
|
2
|
+
import { CLIOptions, UserConfig } from "@kubb/core";
|
|
3
|
+
|
|
4
|
+
//#region ../../internals/utils/src/promise.d.ts
|
|
5
|
+
/** A value that may already be resolved or still pending.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* function load(id: string): PossiblePromise<string> {
|
|
10
|
+
* return cache.get(id) ?? fetchRemote(id)
|
|
11
|
+
* }
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
type PossiblePromise<T> = Promise<T> | T;
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/defineConfig.d.ts
|
|
17
|
+
type AnyConfigResult = UserConfig<any> | Array<UserConfig<any>>;
|
|
18
|
+
type ConfigInput = AnyConfigResult | Promise<AnyConfigResult> | ((cli: CLIOptions) => PossiblePromise<AnyConfigResult>);
|
|
19
|
+
type NormalizeConfig<TConfig> = TConfig extends Array<UserConfig<infer TInput>> ? Array<UserConfig<TInput>> : TConfig extends UserConfig<infer TInput> ? UserConfig<TInput> : never;
|
|
20
|
+
type DefinedConfig<TConfig extends ConfigInput> = TConfig extends ((cli: CLIOptions) => PossiblePromise<infer TResult>) ? (cli: CLIOptions) => Promise<NormalizeConfig<TResult>> : TConfig extends Promise<infer TResult> ? Promise<NormalizeConfig<TResult>> : NormalizeConfig<TConfig>;
|
|
21
|
+
/**
|
|
22
|
+
* Defines a Kubb build configuration and fills in defaults for any omitted fields.
|
|
23
|
+
*
|
|
24
|
+
* Defaults applied when omitted:
|
|
25
|
+
* - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).
|
|
26
|
+
* - `parsers` → `[parserTs, parserTsx, parserMd]`.
|
|
27
|
+
* - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.
|
|
28
|
+
* - `plugins` → `pluginBarrel()` is appended when not already present.
|
|
29
|
+
* - `output.barrel` → `{ type: 'named' }` only when `pluginBarrel` is
|
|
30
|
+
* in the plugins list.
|
|
31
|
+
* - `output.format` and `output.lint` → `false`.
|
|
32
|
+
*
|
|
33
|
+
* Accepts a config object, an array of configs, a Promise resolving to one,
|
|
34
|
+
* or a function that receives the parsed CLI options and returns any of the
|
|
35
|
+
* above. The return type is preserved so async/array variants stay typed.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { defineConfig } from 'kubb'
|
|
40
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
41
|
+
*
|
|
42
|
+
* export default defineConfig({
|
|
43
|
+
* input: { path: './petStore.yaml' },
|
|
44
|
+
* output: { path: './src/gen' },
|
|
45
|
+
* plugins: [pluginTs()],
|
|
46
|
+
* })
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @example Function form with CLI options
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { defineConfig } from 'kubb'
|
|
52
|
+
*
|
|
53
|
+
* export default defineConfig(({ input }) => ({
|
|
54
|
+
* input: { path: input ?? './petStore.yaml' },
|
|
55
|
+
* output: { path: './src/gen' },
|
|
56
|
+
* plugins: [],
|
|
57
|
+
* }))
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
declare function defineConfig<TConfig extends ConfigInput>(config: TConfig): DefinedConfig<TConfig>;
|
|
61
|
+
//#endregion
|
|
62
|
+
export { defineConfig as t };
|
|
63
|
+
//# sourceMappingURL=defineConfig-Bz5OdPiM.d.ts.map
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import "./rolldown-runtime-C0LytTxp.js";
|
|
2
|
+
import { cliReporter, fileReporter, jsonReporter } from "@kubb/core";
|
|
3
|
+
import { adapterOas } from "@kubb/adapter-oas";
|
|
4
|
+
import { pluginBarrel, pluginBarrelName } from "@kubb/plugin-barrel";
|
|
5
|
+
import { parserTs, parserTsx } from "@kubb/parser-ts";
|
|
6
|
+
import { parserMd } from "@kubb/parser-md";
|
|
7
|
+
//#region ../../internals/utils/src/promise.ts
|
|
8
|
+
/** Returns `true` when `result` is a thenable `Promise`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* isPromise(Promise.resolve(1)) // true
|
|
13
|
+
* isPromise(42) // false
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
function isPromise(result) {
|
|
17
|
+
return result !== null && result !== void 0 && typeof result["then"] === "function";
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/defineConfig.ts
|
|
21
|
+
/**
|
|
22
|
+
* Applies default `root`, adapter, parsers, plugins, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.
|
|
23
|
+
*
|
|
24
|
+
* - `root` defaults to `process.cwd()`
|
|
25
|
+
* - `adapter` defaults to `adapterOas()`
|
|
26
|
+
* - `parsers` defaults to `[parserTs, parserTsx, parserMd]`
|
|
27
|
+
* - `reporters` defaults to `[cliReporter, jsonReporter, fileReporter]`
|
|
28
|
+
* - `plugins` gets `pluginBarrel()` appended when none is already present
|
|
29
|
+
* - `output.barrel` defaults to `{ type: 'named' }` only when `pluginBarrel` is part of `plugins`.
|
|
30
|
+
* When the user provides a plugins list without `pluginBarrel`, `barrel` is left untouched.
|
|
31
|
+
* - `output.format` defaults to `false`
|
|
32
|
+
* - `output.lint` defaults to `false`
|
|
33
|
+
*/
|
|
34
|
+
function applyDefaults(config) {
|
|
35
|
+
const plugins = config.plugins?.some((p) => p.name === pluginBarrelName) ? config.plugins ?? [] : [...config.plugins ?? [], pluginBarrel()];
|
|
36
|
+
const hasBarrelPlugin = plugins.some((p) => p.name === pluginBarrelName);
|
|
37
|
+
const output = { ...config.output };
|
|
38
|
+
if (hasBarrelPlugin && output.barrel === void 0) output.barrel = { type: "named" };
|
|
39
|
+
if (output.format === void 0) output.format = false;
|
|
40
|
+
if (output.lint === void 0) output.lint = false;
|
|
41
|
+
return {
|
|
42
|
+
...config,
|
|
43
|
+
root: config.root || process.cwd(),
|
|
44
|
+
adapter: config.adapter ?? adapterOas(),
|
|
45
|
+
parsers: config.parsers?.length ? config.parsers : [
|
|
46
|
+
parserTs,
|
|
47
|
+
parserTsx,
|
|
48
|
+
parserMd
|
|
49
|
+
],
|
|
50
|
+
reporters: config.reporters?.length ? config.reporters : [
|
|
51
|
+
cliReporter,
|
|
52
|
+
jsonReporter,
|
|
53
|
+
fileReporter
|
|
54
|
+
],
|
|
55
|
+
plugins,
|
|
56
|
+
output
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function normalizeConfig(config) {
|
|
60
|
+
if (Array.isArray(config)) return config.map(applyDefaults);
|
|
61
|
+
return applyDefaults(config);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Defines a Kubb build configuration and fills in defaults for any omitted fields.
|
|
65
|
+
*
|
|
66
|
+
* Defaults applied when omitted:
|
|
67
|
+
* - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).
|
|
68
|
+
* - `parsers` → `[parserTs, parserTsx, parserMd]`.
|
|
69
|
+
* - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.
|
|
70
|
+
* - `plugins` → `pluginBarrel()` is appended when not already present.
|
|
71
|
+
* - `output.barrel` → `{ type: 'named' }` only when `pluginBarrel` is
|
|
72
|
+
* in the plugins list.
|
|
73
|
+
* - `output.format` and `output.lint` → `false`.
|
|
74
|
+
*
|
|
75
|
+
* Accepts a config object, an array of configs, a Promise resolving to one,
|
|
76
|
+
* or a function that receives the parsed CLI options and returns any of the
|
|
77
|
+
* above. The return type is preserved so async/array variants stay typed.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* import { defineConfig } from 'kubb'
|
|
82
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
83
|
+
*
|
|
84
|
+
* export default defineConfig({
|
|
85
|
+
* input: { path: './petStore.yaml' },
|
|
86
|
+
* output: { path: './src/gen' },
|
|
87
|
+
* plugins: [pluginTs()],
|
|
88
|
+
* })
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @example Function form with CLI options
|
|
92
|
+
* ```ts
|
|
93
|
+
* import { defineConfig } from 'kubb'
|
|
94
|
+
*
|
|
95
|
+
* export default defineConfig(({ input }) => ({
|
|
96
|
+
* input: { path: input ?? './petStore.yaml' },
|
|
97
|
+
* output: { path: './src/gen' },
|
|
98
|
+
* plugins: [],
|
|
99
|
+
* }))
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
function defineConfig(config) {
|
|
103
|
+
if (typeof config === "function") return (async (cli) => {
|
|
104
|
+
return normalizeConfig(await config(cli));
|
|
105
|
+
});
|
|
106
|
+
if (isPromise(config)) return config.then((resolved) => normalizeConfig(resolved));
|
|
107
|
+
return normalizeConfig(config);
|
|
108
|
+
}
|
|
109
|
+
//#endregion
|
|
110
|
+
export { defineConfig as t };
|
|
111
|
+
|
|
112
|
+
//# sourceMappingURL=defineConfig-D01AIFC1.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineConfig-D01AIFC1.js","names":[],"sources":["../../../internals/utils/src/promise.ts","../src/defineConfig.ts"],"sourcesContent":["/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Wraps `factory` with a keyed cache backed by the provided store.\n *\n * Pass a `WeakMap` for object keys (results are GC-eligible when the key is\n * collected) or a `Map` for primitive keys. For multi-argument functions,\n * nest two `memoize` calls — the outer keyed by the first argument, the\n * inner (created once per outer miss) keyed by the second.\n *\n * Because the cache is owned by the caller, it can be shared, inspected, or\n * cleared independently of the memoized function.\n *\n * @example Single WeakMap key\n * ```ts\n * const cache = new WeakMap<SchemaNode, Set<string>>()\n * const getRefs = memoize(cache, (node) => collectRefs(node))\n * ```\n *\n * @example Single Map key (primitive)\n * ```ts\n * const cache = new Map<string, Resolver>()\n * const getResolver = memoize(cache, (name) => buildResolver(name))\n * ```\n *\n * @example Two-level (object + primitive)\n * ```ts\n * const outer = new WeakMap<Params[], Map<string, Params[]>>()\n * const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))\n * fn(params)('camelcase')\n * ```\n */\nexport function memoize<TKey, TValue>(store: Store<TKey, TValue>, factory: (key: TKey) => TValue): (key: TKey) => TValue {\n return (key: TKey): TValue => {\n if (store.has(key)) return store.get(key)!\n const value = factory(key)\n store.set(key, value)\n return value\n }\n}\n\n/**\n * Container that switches between an eager `Array<T>` and a lazy `AsyncIterable<T>`.\n *\n * `Array<T>` by default. With `Stream` set to `true` it becomes `AsyncIterable<T>`, so large\n * collections can be produced lazily without holding every item in memory. Pairs with\n * {@link arrayToAsyncIterable}, which lifts a plain array into the streaming form.\n *\n * @example\n * ```ts\n * type Eager = Streamable<number> // Array<number>\n * type Lazy = Streamable<number, true> // AsyncIterable<number>\n * ```\n */\nexport type Streamable<T, Stream extends boolean = false> = Stream extends true ? AsyncIterable<T> : Array<T>\n\n/**\n * Wraps a plain array in a reusable `AsyncIterable`.\n * Each `[Symbol.asyncIterator]()` call returns a fresh generator so the\n * iterable can be consumed multiple times (e.g. once per plugin pre-scan).\n *\n * @example\n * ```ts\n * const stream = arrayToAsyncIterable([1, 2, 3])\n * for await (const n of stream) console.log(n) // 1, 2, 3\n * ```\n */\nexport function arrayToAsyncIterable<T>(arr: ReadonlyArray<T>): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]() {\n return (async function* () {\n yield* arr\n })()\n },\n }\n}\n","import { isPromise, type PossiblePromise } from '@internals/utils'\nimport { adapterOas } from '@kubb/adapter-oas'\nimport { cliReporter, type CLIOptions, fileReporter, jsonReporter, type UserConfig } from '@kubb/core'\nimport { pluginBarrel, pluginBarrelName } from '@kubb/plugin-barrel'\nimport { parserTs, parserTsx } from '@kubb/parser-ts'\nimport { parserMd } from '@kubb/parser-md'\n\ntype AnyConfigResult = UserConfig<any> | Array<UserConfig<any>>\ntype ConfigInput = AnyConfigResult | Promise<AnyConfigResult> | ((cli: CLIOptions) => PossiblePromise<AnyConfigResult>)\ntype NormalizeConfig<TConfig> =\n TConfig extends Array<UserConfig<infer TInput>> ? Array<UserConfig<TInput>> : TConfig extends UserConfig<infer TInput> ? UserConfig<TInput> : never\ntype DefinedConfig<TConfig extends ConfigInput> = TConfig extends (cli: CLIOptions) => PossiblePromise<infer TResult>\n ? (cli: CLIOptions) => Promise<NormalizeConfig<TResult>>\n : TConfig extends Promise<infer TResult>\n ? Promise<NormalizeConfig<TResult>>\n : NormalizeConfig<TConfig>\n\n/**\n * Applies default `root`, adapter, parsers, plugins, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.\n *\n * - `root` defaults to `process.cwd()`\n * - `adapter` defaults to `adapterOas()`\n * - `parsers` defaults to `[parserTs, parserTsx, parserMd]`\n * - `reporters` defaults to `[cliReporter, jsonReporter, fileReporter]`\n * - `plugins` gets `pluginBarrel()` appended when none is already present\n * - `output.barrel` defaults to `{ type: 'named' }` only when `pluginBarrel` is part of `plugins`.\n * When the user provides a plugins list without `pluginBarrel`, `barrel` is left untouched.\n * - `output.format` defaults to `false`\n * - `output.lint` defaults to `false`\n */\nfunction applyDefaults<TInput>(config: UserConfig<TInput>): UserConfig<TInput> {\n const alreadyHasBarrel = config.plugins?.some((p) => p.name === pluginBarrelName)\n const plugins = alreadyHasBarrel ? (config.plugins ?? []) : [...(config.plugins ?? []), pluginBarrel()]\n const hasBarrelPlugin = plugins.some((p) => p.name === pluginBarrelName)\n\n const output = { ...config.output }\n if (hasBarrelPlugin && output.barrel === undefined) {\n output.barrel = { type: 'named' }\n }\n if (output.format === undefined) {\n output.format = false\n }\n if (output.lint === undefined) {\n output.lint = false\n }\n\n return {\n ...config,\n root: config.root || process.cwd(),\n adapter: config.adapter ?? adapterOas(),\n parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx, parserMd],\n reporters: config.reporters?.length ? config.reporters : [cliReporter, jsonReporter, fileReporter],\n plugins,\n output,\n }\n}\n\nfunction normalizeConfig<TInput>(config: UserConfig<TInput> | Array<UserConfig<TInput>>): UserConfig<TInput> | Array<UserConfig<TInput>> {\n if (Array.isArray(config)) {\n return config.map(applyDefaults)\n }\n\n return applyDefaults(config)\n}\n\n/**\n * Defines a Kubb build configuration and fills in defaults for any omitted fields.\n *\n * Defaults applied when omitted:\n * - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).\n * - `parsers` → `[parserTs, parserTsx, parserMd]`.\n * - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.\n * - `plugins` → `pluginBarrel()` is appended when not already present.\n * - `output.barrel` → `{ type: 'named' }` only when `pluginBarrel` is\n * in the plugins list.\n * - `output.format` and `output.lint` → `false`.\n *\n * Accepts a config object, an array of configs, a Promise resolving to one,\n * or a function that receives the parsed CLI options and returns any of the\n * above. The return type is preserved so async/array variants stay typed.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginTs } from '@kubb/plugin-ts'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [pluginTs()],\n * })\n * ```\n *\n * @example Function form with CLI options\n * ```ts\n * import { defineConfig } from 'kubb'\n *\n * export default defineConfig(({ input }) => ({\n * input: { path: input ?? './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [],\n * }))\n * ```\n */\nexport function defineConfig<TConfig extends ConfigInput>(config: TConfig): DefinedConfig<TConfig> {\n if (typeof config === 'function') {\n return (async (cli: CLIOptions) => {\n return normalizeConfig(await config(cli))\n }) as DefinedConfig<TConfig>\n }\n\n if (isPromise(config)) {\n return config.then((resolved) => normalizeConfig(resolved)) as DefinedConfig<TConfig>\n }\n\n return normalizeConfig(config) as DefinedConfig<TConfig>\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,SAAgB,UAAa,QAAkD;CAC7E,OAAO,WAAW,QAAQ,WAAW,KAAA,KAAa,OAAQ,OAAmC,YAAY;AAC3G;;;;;;;;;;;;;;;;ACSA,SAAS,cAAsB,QAAgD;CAE7E,MAAM,UADmB,OAAO,SAAS,MAAM,MAAM,EAAE,SAAS,gBAAgB,IAC5C,OAAO,WAAW,CAAC,IAAK,CAAC,GAAI,OAAO,WAAW,CAAC,GAAI,aAAa,CAAC;CACtG,MAAM,kBAAkB,QAAQ,MAAM,MAAM,EAAE,SAAS,gBAAgB;CAEvE,MAAM,SAAS,EAAE,GAAG,OAAO,OAAO;CAClC,IAAI,mBAAmB,OAAO,WAAW,KAAA,GACvC,OAAO,SAAS,EAAE,MAAM,QAAQ;CAElC,IAAI,OAAO,WAAW,KAAA,GACpB,OAAO,SAAS;CAElB,IAAI,OAAO,SAAS,KAAA,GAClB,OAAO,OAAO;CAGhB,OAAO;EACL,GAAG;EACH,MAAM,OAAO,QAAQ,QAAQ,IAAI;EACjC,SAAS,OAAO,WAAW,WAAW;EACtC,SAAS,OAAO,SAAS,SAAS,OAAO,UAAU;GAAC;GAAU;GAAW;EAAQ;EACjF,WAAW,OAAO,WAAW,SAAS,OAAO,YAAY;GAAC;GAAa;GAAc;EAAY;EACjG;EACA;CACF;AACF;AAEA,SAAS,gBAAwB,QAAwG;CACvI,IAAI,MAAM,QAAQ,MAAM,GACtB,OAAO,OAAO,IAAI,aAAa;CAGjC,OAAO,cAAc,MAAM;AAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,aAA0C,QAAyC;CACjG,IAAI,OAAO,WAAW,YACpB,QAAQ,OAAO,QAAoB;EACjC,OAAO,gBAAgB,MAAM,OAAO,GAAG,CAAC;CAC1C;CAGF,IAAI,UAAU,MAAM,GAClB,OAAO,OAAO,MAAM,aAAa,gBAAgB,QAAQ,CAAC;CAG5D,OAAO,gBAAgB,MAAM;AAC/B"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,113 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
3
|
-
let _kubb_adapter_oas = require("@kubb/adapter-oas");
|
|
2
|
+
const require_defineConfig = require("./defineConfig-BXme6pNF.cjs");
|
|
4
3
|
let _kubb_core = require("@kubb/core");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* ```ts
|
|
13
|
-
* isPromise(Promise.resolve(1)) // true
|
|
14
|
-
* isPromise(42) // false
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
function isPromise(result) {
|
|
18
|
-
return result !== null && result !== void 0 && typeof result["then"] === "function";
|
|
19
|
-
}
|
|
20
|
-
//#endregion
|
|
21
|
-
//#region src/defineConfig.ts
|
|
22
|
-
/**
|
|
23
|
-
* Applies default `root`, adapter, parsers, plugins, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.
|
|
24
|
-
*
|
|
25
|
-
* - `root` defaults to `process.cwd()`
|
|
26
|
-
* - `adapter` defaults to `adapterOas()`
|
|
27
|
-
* - `parsers` defaults to `[parserTs, parserTsx, parserMd]`
|
|
28
|
-
* - `reporters` defaults to `[cliReporter, jsonReporter, fileReporter]`
|
|
29
|
-
* - `plugins` gets `pluginBarrel()` appended when none is already present
|
|
30
|
-
* - `output.barrel` defaults to `{ type: 'named' }` only when `pluginBarrel` is part of `plugins`.
|
|
31
|
-
* When the user provides a plugins list without `pluginBarrel`, `barrel` is left untouched.
|
|
32
|
-
* - `output.format` defaults to `false`
|
|
33
|
-
* - `output.lint` defaults to `false`
|
|
34
|
-
*/
|
|
35
|
-
function applyDefaults(config) {
|
|
36
|
-
const plugins = config.plugins?.some((p) => p.name === _kubb_plugin_barrel.pluginBarrelName) ? config.plugins ?? [] : [...config.plugins ?? [], (0, _kubb_plugin_barrel.pluginBarrel)()];
|
|
37
|
-
const hasBarrelPlugin = plugins.some((p) => p.name === _kubb_plugin_barrel.pluginBarrelName);
|
|
38
|
-
const output = { ...config.output };
|
|
39
|
-
if (hasBarrelPlugin && output.barrel === void 0) output.barrel = { type: "named" };
|
|
40
|
-
if (output.format === void 0) output.format = false;
|
|
41
|
-
if (output.lint === void 0) output.lint = false;
|
|
42
|
-
return {
|
|
43
|
-
...config,
|
|
44
|
-
root: config.root || process.cwd(),
|
|
45
|
-
adapter: config.adapter ?? (0, _kubb_adapter_oas.adapterOas)(),
|
|
46
|
-
parsers: config.parsers?.length ? config.parsers : [
|
|
47
|
-
_kubb_parser_ts.parserTs,
|
|
48
|
-
_kubb_parser_ts.parserTsx,
|
|
49
|
-
_kubb_parser_md.parserMd
|
|
50
|
-
],
|
|
51
|
-
reporters: config.reporters?.length ? config.reporters : [
|
|
52
|
-
_kubb_core.cliReporter,
|
|
53
|
-
_kubb_core.jsonReporter,
|
|
54
|
-
_kubb_core.fileReporter
|
|
55
|
-
],
|
|
56
|
-
plugins,
|
|
57
|
-
output
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
function normalizeConfig(config) {
|
|
61
|
-
if (Array.isArray(config)) return config.map(applyDefaults);
|
|
62
|
-
return applyDefaults(config);
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Defines a Kubb build configuration and fills in defaults for any omitted fields.
|
|
66
|
-
*
|
|
67
|
-
* Defaults applied when omitted:
|
|
68
|
-
* - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).
|
|
69
|
-
* - `parsers` → `[parserTs, parserTsx, parserMd]`.
|
|
70
|
-
* - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.
|
|
71
|
-
* - `plugins` → `pluginBarrel()` is appended when not already present.
|
|
72
|
-
* - `output.barrel` → `{ type: 'named' }` only when `pluginBarrel` is
|
|
73
|
-
* in the plugins list.
|
|
74
|
-
* - `output.format` and `output.lint` → `false`.
|
|
75
|
-
*
|
|
76
|
-
* Accepts a config object, an array of configs, a Promise resolving to one,
|
|
77
|
-
* or a function that receives the parsed CLI options and returns any of the
|
|
78
|
-
* above. The return type is preserved so async/array variants stay typed.
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```ts
|
|
82
|
-
* import { defineConfig } from 'kubb'
|
|
83
|
-
* import { pluginTs } from '@kubb/plugin-ts'
|
|
84
|
-
*
|
|
85
|
-
* export default defineConfig({
|
|
86
|
-
* input: { path: './petStore.yaml' },
|
|
87
|
-
* output: { path: './src/gen' },
|
|
88
|
-
* plugins: [pluginTs()],
|
|
89
|
-
* })
|
|
90
|
-
* ```
|
|
91
|
-
*
|
|
92
|
-
* @example Function form with CLI options
|
|
93
|
-
* ```ts
|
|
94
|
-
* import { defineConfig } from 'kubb'
|
|
95
|
-
*
|
|
96
|
-
* export default defineConfig(({ input }) => ({
|
|
97
|
-
* input: { path: input ?? './petStore.yaml' },
|
|
98
|
-
* output: { path: './src/gen' },
|
|
99
|
-
* plugins: [],
|
|
100
|
-
* }))
|
|
101
|
-
* ```
|
|
102
|
-
*/
|
|
103
|
-
function defineConfig(config) {
|
|
104
|
-
if (typeof config === "function") return (async (cli) => {
|
|
105
|
-
return normalizeConfig(await config(cli));
|
|
106
|
-
});
|
|
107
|
-
if (isPromise(config)) return config.then((resolved) => normalizeConfig(resolved));
|
|
108
|
-
return normalizeConfig(config);
|
|
109
|
-
}
|
|
110
|
-
//#endregion
|
|
111
|
-
exports.defineConfig = defineConfig;
|
|
112
|
-
|
|
113
|
-
//# sourceMappingURL=index.cjs.map
|
|
4
|
+
Object.defineProperty(exports, "createKubb", {
|
|
5
|
+
enumerable: true,
|
|
6
|
+
get: function() {
|
|
7
|
+
return _kubb_core.createKubb;
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
exports.defineConfig = require_defineConfig.defineConfig;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,64 +1,4 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import {
|
|
1
|
+
import { t as defineConfig } from "./defineConfig-Bz5OdPiM.js";
|
|
2
|
+
import { BuildOutput, Config, CreateKubbOptions, Kubb, UserConfig, createKubb } from "@kubb/core";
|
|
3
3
|
import { BarrelType } from "@kubb/plugin-barrel";
|
|
4
|
-
|
|
5
|
-
//#region ../../internals/utils/src/promise.d.ts
|
|
6
|
-
/** A value that may already be resolved or still pending.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* function load(id: string): PossiblePromise<string> {
|
|
11
|
-
* return cache.get(id) ?? fetchRemote(id)
|
|
12
|
-
* }
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
type PossiblePromise<T> = Promise<T> | T;
|
|
16
|
-
//#endregion
|
|
17
|
-
//#region src/defineConfig.d.ts
|
|
18
|
-
type AnyConfigResult = UserConfig<any> | Array<UserConfig<any>>;
|
|
19
|
-
type ConfigInput = AnyConfigResult | Promise<AnyConfigResult> | ((cli: CLIOptions) => PossiblePromise<AnyConfigResult>);
|
|
20
|
-
type NormalizeConfig<TConfig> = TConfig extends Array<UserConfig<infer TInput>> ? Array<UserConfig<TInput>> : TConfig extends UserConfig<infer TInput> ? UserConfig<TInput> : never;
|
|
21
|
-
type DefinedConfig<TConfig extends ConfigInput> = TConfig extends ((cli: CLIOptions) => PossiblePromise<infer TResult>) ? (cli: CLIOptions) => Promise<NormalizeConfig<TResult>> : TConfig extends Promise<infer TResult> ? Promise<NormalizeConfig<TResult>> : NormalizeConfig<TConfig>;
|
|
22
|
-
/**
|
|
23
|
-
* Defines a Kubb build configuration and fills in defaults for any omitted fields.
|
|
24
|
-
*
|
|
25
|
-
* Defaults applied when omitted:
|
|
26
|
-
* - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).
|
|
27
|
-
* - `parsers` → `[parserTs, parserTsx, parserMd]`.
|
|
28
|
-
* - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.
|
|
29
|
-
* - `plugins` → `pluginBarrel()` is appended when not already present.
|
|
30
|
-
* - `output.barrel` → `{ type: 'named' }` only when `pluginBarrel` is
|
|
31
|
-
* in the plugins list.
|
|
32
|
-
* - `output.format` and `output.lint` → `false`.
|
|
33
|
-
*
|
|
34
|
-
* Accepts a config object, an array of configs, a Promise resolving to one,
|
|
35
|
-
* or a function that receives the parsed CLI options and returns any of the
|
|
36
|
-
* above. The return type is preserved so async/array variants stay typed.
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```ts
|
|
40
|
-
* import { defineConfig } from 'kubb'
|
|
41
|
-
* import { pluginTs } from '@kubb/plugin-ts'
|
|
42
|
-
*
|
|
43
|
-
* export default defineConfig({
|
|
44
|
-
* input: { path: './petStore.yaml' },
|
|
45
|
-
* output: { path: './src/gen' },
|
|
46
|
-
* plugins: [pluginTs()],
|
|
47
|
-
* })
|
|
48
|
-
* ```
|
|
49
|
-
*
|
|
50
|
-
* @example Function form with CLI options
|
|
51
|
-
* ```ts
|
|
52
|
-
* import { defineConfig } from 'kubb'
|
|
53
|
-
*
|
|
54
|
-
* export default defineConfig(({ input }) => ({
|
|
55
|
-
* input: { path: input ?? './petStore.yaml' },
|
|
56
|
-
* output: { path: './src/gen' },
|
|
57
|
-
* plugins: [],
|
|
58
|
-
* }))
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
declare function defineConfig<TConfig extends ConfigInput>(config: TConfig): DefinedConfig<TConfig>;
|
|
62
|
-
//#endregion
|
|
63
|
-
export { type BarrelType, defineConfig };
|
|
64
|
-
//# sourceMappingURL=index.d.ts.map
|
|
4
|
+
export { type BarrelType, type BuildOutput, type Config, type CreateKubbOptions, type Kubb, type UserConfig, createKubb, defineConfig };
|
package/dist/index.js
CHANGED
|
@@ -1,112 +1,3 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { pluginBarrel, pluginBarrelName } from "@kubb/plugin-barrel";
|
|
5
|
-
import { parserTs, parserTsx } from "@kubb/parser-ts";
|
|
6
|
-
import { parserMd } from "@kubb/parser-md";
|
|
7
|
-
//#region ../../internals/utils/src/promise.ts
|
|
8
|
-
/** Returns `true` when `result` is a thenable `Promise`.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* isPromise(Promise.resolve(1)) // true
|
|
13
|
-
* isPromise(42) // false
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
function isPromise(result) {
|
|
17
|
-
return result !== null && result !== void 0 && typeof result["then"] === "function";
|
|
18
|
-
}
|
|
19
|
-
//#endregion
|
|
20
|
-
//#region src/defineConfig.ts
|
|
21
|
-
/**
|
|
22
|
-
* Applies default `root`, adapter, parsers, plugins, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.
|
|
23
|
-
*
|
|
24
|
-
* - `root` defaults to `process.cwd()`
|
|
25
|
-
* - `adapter` defaults to `adapterOas()`
|
|
26
|
-
* - `parsers` defaults to `[parserTs, parserTsx, parserMd]`
|
|
27
|
-
* - `reporters` defaults to `[cliReporter, jsonReporter, fileReporter]`
|
|
28
|
-
* - `plugins` gets `pluginBarrel()` appended when none is already present
|
|
29
|
-
* - `output.barrel` defaults to `{ type: 'named' }` only when `pluginBarrel` is part of `plugins`.
|
|
30
|
-
* When the user provides a plugins list without `pluginBarrel`, `barrel` is left untouched.
|
|
31
|
-
* - `output.format` defaults to `false`
|
|
32
|
-
* - `output.lint` defaults to `false`
|
|
33
|
-
*/
|
|
34
|
-
function applyDefaults(config) {
|
|
35
|
-
const plugins = config.plugins?.some((p) => p.name === pluginBarrelName) ? config.plugins ?? [] : [...config.plugins ?? [], pluginBarrel()];
|
|
36
|
-
const hasBarrelPlugin = plugins.some((p) => p.name === pluginBarrelName);
|
|
37
|
-
const output = { ...config.output };
|
|
38
|
-
if (hasBarrelPlugin && output.barrel === void 0) output.barrel = { type: "named" };
|
|
39
|
-
if (output.format === void 0) output.format = false;
|
|
40
|
-
if (output.lint === void 0) output.lint = false;
|
|
41
|
-
return {
|
|
42
|
-
...config,
|
|
43
|
-
root: config.root || process.cwd(),
|
|
44
|
-
adapter: config.adapter ?? adapterOas(),
|
|
45
|
-
parsers: config.parsers?.length ? config.parsers : [
|
|
46
|
-
parserTs,
|
|
47
|
-
parserTsx,
|
|
48
|
-
parserMd
|
|
49
|
-
],
|
|
50
|
-
reporters: config.reporters?.length ? config.reporters : [
|
|
51
|
-
cliReporter,
|
|
52
|
-
jsonReporter,
|
|
53
|
-
fileReporter
|
|
54
|
-
],
|
|
55
|
-
plugins,
|
|
56
|
-
output
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
function normalizeConfig(config) {
|
|
60
|
-
if (Array.isArray(config)) return config.map(applyDefaults);
|
|
61
|
-
return applyDefaults(config);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Defines a Kubb build configuration and fills in defaults for any omitted fields.
|
|
65
|
-
*
|
|
66
|
-
* Defaults applied when omitted:
|
|
67
|
-
* - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).
|
|
68
|
-
* - `parsers` → `[parserTs, parserTsx, parserMd]`.
|
|
69
|
-
* - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.
|
|
70
|
-
* - `plugins` → `pluginBarrel()` is appended when not already present.
|
|
71
|
-
* - `output.barrel` → `{ type: 'named' }` only when `pluginBarrel` is
|
|
72
|
-
* in the plugins list.
|
|
73
|
-
* - `output.format` and `output.lint` → `false`.
|
|
74
|
-
*
|
|
75
|
-
* Accepts a config object, an array of configs, a Promise resolving to one,
|
|
76
|
-
* or a function that receives the parsed CLI options and returns any of the
|
|
77
|
-
* above. The return type is preserved so async/array variants stay typed.
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```ts
|
|
81
|
-
* import { defineConfig } from 'kubb'
|
|
82
|
-
* import { pluginTs } from '@kubb/plugin-ts'
|
|
83
|
-
*
|
|
84
|
-
* export default defineConfig({
|
|
85
|
-
* input: { path: './petStore.yaml' },
|
|
86
|
-
* output: { path: './src/gen' },
|
|
87
|
-
* plugins: [pluginTs()],
|
|
88
|
-
* })
|
|
89
|
-
* ```
|
|
90
|
-
*
|
|
91
|
-
* @example Function form with CLI options
|
|
92
|
-
* ```ts
|
|
93
|
-
* import { defineConfig } from 'kubb'
|
|
94
|
-
*
|
|
95
|
-
* export default defineConfig(({ input }) => ({
|
|
96
|
-
* input: { path: input ?? './petStore.yaml' },
|
|
97
|
-
* output: { path: './src/gen' },
|
|
98
|
-
* plugins: [],
|
|
99
|
-
* }))
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
function defineConfig(config) {
|
|
103
|
-
if (typeof config === "function") return (async (cli) => {
|
|
104
|
-
return normalizeConfig(await config(cli));
|
|
105
|
-
});
|
|
106
|
-
if (isPromise(config)) return config.then((resolved) => normalizeConfig(resolved));
|
|
107
|
-
return normalizeConfig(config);
|
|
108
|
-
}
|
|
109
|
-
//#endregion
|
|
110
|
-
export { defineConfig };
|
|
111
|
-
|
|
112
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import { t as defineConfig } from "./defineConfig-D01AIFC1.js";
|
|
2
|
+
import { createKubb } from "@kubb/core";
|
|
3
|
+
export { createKubb, defineConfig };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
var _kubb_renderer_jsx_jsx_dev_runtime = require("@kubb/renderer-jsx/jsx-dev-runtime");
|
|
2
|
+
Object.keys(_kubb_renderer_jsx_jsx_dev_runtime).forEach(function(k) {
|
|
3
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
get: function() {
|
|
6
|
+
return _kubb_renderer_jsx_jsx_dev_runtime[k];
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@kubb/renderer-jsx/jsx-dev-runtime";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
var _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
|
|
2
|
+
Object.keys(_kubb_renderer_jsx_jsx_runtime).forEach(function(k) {
|
|
3
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
get: function() {
|
|
6
|
+
return _kubb_renderer_jsx_jsx_runtime[k];
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@kubb/renderer-jsx/jsx-runtime";
|
package/dist/jsx.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var _kubb_renderer_jsx = require("@kubb/renderer-jsx");
|
|
2
|
+
Object.keys(_kubb_renderer_jsx).forEach(function(k) {
|
|
3
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
get: function() {
|
|
6
|
+
return _kubb_renderer_jsx[k];
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
});
|
|
10
|
+
var _kubb_renderer_jsx_types = require("@kubb/renderer-jsx/types");
|
|
11
|
+
Object.keys(_kubb_renderer_jsx_types).forEach(function(k) {
|
|
12
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function() {
|
|
15
|
+
return _kubb_renderer_jsx_types[k];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
package/dist/jsx.d.ts
ADDED
package/dist/jsx.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
var _kubb_kit_testing = require("@kubb/kit/testing");
|
|
2
|
+
Object.keys(_kubb_kit_testing).forEach(function(k) {
|
|
3
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
get: function() {
|
|
6
|
+
return _kubb_kit_testing[k];
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@kubb/kit/testing";
|
package/dist/kit.cjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
var _kubb_kit = require("@kubb/kit");
|
|
2
|
+
Object.keys(_kubb_kit).forEach(function(k) {
|
|
3
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
get: function() {
|
|
6
|
+
return _kubb_kit[k];
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
});
|
package/dist/kit.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@kubb/kit";
|
package/dist/kit.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kubb",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.82",
|
|
4
4
|
"description": "The meta framework for code generation. Point Kubb at a schema and it generates types, clients, hooks, validators, mocks, and more.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api-client",
|
|
@@ -42,6 +42,34 @@
|
|
|
42
42
|
"import": "./dist/index.js",
|
|
43
43
|
"require": "./dist/index.cjs"
|
|
44
44
|
},
|
|
45
|
+
"./ast": {
|
|
46
|
+
"import": "./dist/ast.js",
|
|
47
|
+
"require": "./dist/ast.cjs"
|
|
48
|
+
},
|
|
49
|
+
"./config": {
|
|
50
|
+
"import": "./dist/config.js",
|
|
51
|
+
"require": "./dist/config.cjs"
|
|
52
|
+
},
|
|
53
|
+
"./jsx": {
|
|
54
|
+
"import": "./dist/jsx.js",
|
|
55
|
+
"require": "./dist/jsx.cjs"
|
|
56
|
+
},
|
|
57
|
+
"./jsx/jsx-dev-runtime": {
|
|
58
|
+
"import": "./dist/jsx/jsx-dev-runtime.js",
|
|
59
|
+
"require": "./dist/jsx/jsx-dev-runtime.cjs"
|
|
60
|
+
},
|
|
61
|
+
"./jsx/jsx-runtime": {
|
|
62
|
+
"import": "./dist/jsx/jsx-runtime.js",
|
|
63
|
+
"require": "./dist/jsx/jsx-runtime.cjs"
|
|
64
|
+
},
|
|
65
|
+
"./kit": {
|
|
66
|
+
"import": "./dist/kit.js",
|
|
67
|
+
"require": "./dist/kit.cjs"
|
|
68
|
+
},
|
|
69
|
+
"./kit/testing": {
|
|
70
|
+
"import": "./dist/kit/testing.js",
|
|
71
|
+
"require": "./dist/kit/testing.cjs"
|
|
72
|
+
},
|
|
45
73
|
"./package.json": "./package.json"
|
|
46
74
|
},
|
|
47
75
|
"publishConfig": {
|
|
@@ -49,14 +77,16 @@
|
|
|
49
77
|
"registry": "https://registry.npmjs.org/"
|
|
50
78
|
},
|
|
51
79
|
"dependencies": {
|
|
52
|
-
"@kubb/adapter-oas": "5.0.0-beta.
|
|
53
|
-
"@kubb/cli": "5.0.0-beta.
|
|
54
|
-
"@kubb/core": "5.0.0-beta.
|
|
55
|
-
"@kubb/
|
|
56
|
-
"@kubb/
|
|
57
|
-
"@kubb/
|
|
58
|
-
"@kubb/
|
|
59
|
-
"@kubb/
|
|
80
|
+
"@kubb/adapter-oas": "5.0.0-beta.82",
|
|
81
|
+
"@kubb/cli": "5.0.0-beta.82",
|
|
82
|
+
"@kubb/core": "5.0.0-beta.82",
|
|
83
|
+
"@kubb/ast": "5.0.0-beta.82",
|
|
84
|
+
"@kubb/mcp": "5.0.0-beta.82",
|
|
85
|
+
"@kubb/kit": "5.0.0-beta.82",
|
|
86
|
+
"@kubb/parser-ts": "5.0.0-beta.82",
|
|
87
|
+
"@kubb/parser-md": "5.0.0-beta.82",
|
|
88
|
+
"@kubb/plugin-barrel": "5.0.0-beta.82",
|
|
89
|
+
"@kubb/renderer-jsx": "5.0.0-beta.82"
|
|
60
90
|
},
|
|
61
91
|
"devDependencies": {
|
|
62
92
|
"typescript": "^6.0.3",
|
|
@@ -71,9 +101,6 @@
|
|
|
71
101
|
"clean": "node -e \"require('node:fs').rmSync('./dist', {recursive:true,force:true})\"",
|
|
72
102
|
"lint": "oxlint .",
|
|
73
103
|
"lint:fix": "oxlint --fix .",
|
|
74
|
-
"release": "pnpm publish --no-git-check",
|
|
75
|
-
"release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
|
|
76
|
-
"release:stage": "pnpm stage publish --no-git-check",
|
|
77
104
|
"start": "tsdown --watch",
|
|
78
105
|
"test": "vitest --passWithNoTests",
|
|
79
106
|
"typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["pluginBarrelName","parserTs","parserTsx","parserMd","cliReporter","jsonReporter","fileReporter"],"sources":["../../../internals/utils/src/promise.ts","../src/defineConfig.ts"],"sourcesContent":["/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Wraps `factory` with a keyed cache backed by the provided store.\n *\n * Pass a `WeakMap` for object keys (results are GC-eligible when the key is\n * collected) or a `Map` for primitive keys. For multi-argument functions,\n * nest two `memoize` calls — the outer keyed by the first argument, the\n * inner (created once per outer miss) keyed by the second.\n *\n * Because the cache is owned by the caller, it can be shared, inspected, or\n * cleared independently of the memoized function.\n *\n * @example Single WeakMap key\n * ```ts\n * const cache = new WeakMap<SchemaNode, Set<string>>()\n * const getRefs = memoize(cache, (node) => collectRefs(node))\n * ```\n *\n * @example Single Map key (primitive)\n * ```ts\n * const cache = new Map<string, Resolver>()\n * const getResolver = memoize(cache, (name) => buildResolver(name))\n * ```\n *\n * @example Two-level (object + primitive)\n * ```ts\n * const outer = new WeakMap<Params[], Map<string, Params[]>>()\n * const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))\n * fn(params)('camelcase')\n * ```\n */\nexport function memoize<TKey, TValue>(store: Store<TKey, TValue>, factory: (key: TKey) => TValue): (key: TKey) => TValue {\n return (key: TKey): TValue => {\n if (store.has(key)) return store.get(key)!\n const value = factory(key)\n store.set(key, value)\n return value\n }\n}\n\n/**\n * Container that switches between an eager `Array<T>` and a lazy `AsyncIterable<T>`.\n *\n * `Array<T>` by default. With `Stream` set to `true` it becomes `AsyncIterable<T>`, so large\n * collections can be produced lazily without holding every item in memory. Pairs with\n * {@link arrayToAsyncIterable}, which lifts a plain array into the streaming form.\n *\n * @example\n * ```ts\n * type Eager = Streamable<number> // Array<number>\n * type Lazy = Streamable<number, true> // AsyncIterable<number>\n * ```\n */\nexport type Streamable<T, Stream extends boolean = false> = Stream extends true ? AsyncIterable<T> : Array<T>\n\n/**\n * Wraps a plain array in a reusable `AsyncIterable`.\n * Each `[Symbol.asyncIterator]()` call returns a fresh generator so the\n * iterable can be consumed multiple times (e.g. once per plugin pre-scan).\n *\n * @example\n * ```ts\n * const stream = arrayToAsyncIterable([1, 2, 3])\n * for await (const n of stream) console.log(n) // 1, 2, 3\n * ```\n */\nexport function arrayToAsyncIterable<T>(arr: ReadonlyArray<T>): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]() {\n return (async function* () {\n yield* arr\n })()\n },\n }\n}\n","import { isPromise, type PossiblePromise } from '@internals/utils'\nimport { adapterOas } from '@kubb/adapter-oas'\nimport { cliReporter, type CLIOptions, fileReporter, jsonReporter, type UserConfig } from '@kubb/core'\nimport { pluginBarrel, pluginBarrelName } from '@kubb/plugin-barrel'\nimport { parserTs, parserTsx } from '@kubb/parser-ts'\nimport { parserMd } from '@kubb/parser-md'\n\ntype AnyConfigResult = UserConfig<any> | Array<UserConfig<any>>\ntype ConfigInput = AnyConfigResult | Promise<AnyConfigResult> | ((cli: CLIOptions) => PossiblePromise<AnyConfigResult>)\ntype NormalizeConfig<TConfig> =\n TConfig extends Array<UserConfig<infer TInput>> ? Array<UserConfig<TInput>> : TConfig extends UserConfig<infer TInput> ? UserConfig<TInput> : never\ntype DefinedConfig<TConfig extends ConfigInput> = TConfig extends (cli: CLIOptions) => PossiblePromise<infer TResult>\n ? (cli: CLIOptions) => Promise<NormalizeConfig<TResult>>\n : TConfig extends Promise<infer TResult>\n ? Promise<NormalizeConfig<TResult>>\n : NormalizeConfig<TConfig>\n\n/**\n * Applies default `root`, adapter, parsers, plugins, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.\n *\n * - `root` defaults to `process.cwd()`\n * - `adapter` defaults to `adapterOas()`\n * - `parsers` defaults to `[parserTs, parserTsx, parserMd]`\n * - `reporters` defaults to `[cliReporter, jsonReporter, fileReporter]`\n * - `plugins` gets `pluginBarrel()` appended when none is already present\n * - `output.barrel` defaults to `{ type: 'named' }` only when `pluginBarrel` is part of `plugins`.\n * When the user provides a plugins list without `pluginBarrel`, `barrel` is left untouched.\n * - `output.format` defaults to `false`\n * - `output.lint` defaults to `false`\n */\nfunction applyDefaults<TInput>(config: UserConfig<TInput>): UserConfig<TInput> {\n const alreadyHasBarrel = config.plugins?.some((p) => p.name === pluginBarrelName)\n const plugins = alreadyHasBarrel ? (config.plugins ?? []) : [...(config.plugins ?? []), pluginBarrel()]\n const hasBarrelPlugin = plugins.some((p) => p.name === pluginBarrelName)\n\n const output = { ...config.output }\n if (hasBarrelPlugin && output.barrel === undefined) {\n output.barrel = { type: 'named' }\n }\n if (output.format === undefined) {\n output.format = false\n }\n if (output.lint === undefined) {\n output.lint = false\n }\n\n return {\n ...config,\n root: config.root || process.cwd(),\n adapter: config.adapter ?? adapterOas(),\n parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx, parserMd],\n reporters: config.reporters?.length ? config.reporters : [cliReporter, jsonReporter, fileReporter],\n plugins,\n output,\n }\n}\n\nfunction normalizeConfig<TInput>(config: UserConfig<TInput> | Array<UserConfig<TInput>>): UserConfig<TInput> | Array<UserConfig<TInput>> {\n if (Array.isArray(config)) {\n return config.map(applyDefaults)\n }\n\n return applyDefaults(config)\n}\n\n/**\n * Defines a Kubb build configuration and fills in defaults for any omitted fields.\n *\n * Defaults applied when omitted:\n * - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).\n * - `parsers` → `[parserTs, parserTsx, parserMd]`.\n * - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.\n * - `plugins` → `pluginBarrel()` is appended when not already present.\n * - `output.barrel` → `{ type: 'named' }` only when `pluginBarrel` is\n * in the plugins list.\n * - `output.format` and `output.lint` → `false`.\n *\n * Accepts a config object, an array of configs, a Promise resolving to one,\n * or a function that receives the parsed CLI options and returns any of the\n * above. The return type is preserved so async/array variants stay typed.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginTs } from '@kubb/plugin-ts'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [pluginTs()],\n * })\n * ```\n *\n * @example Function form with CLI options\n * ```ts\n * import { defineConfig } from 'kubb'\n *\n * export default defineConfig(({ input }) => ({\n * input: { path: input ?? './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [],\n * }))\n * ```\n */\nexport function defineConfig<TConfig extends ConfigInput>(config: TConfig): DefinedConfig<TConfig> {\n if (typeof config === 'function') {\n return (async (cli: CLIOptions) => {\n return normalizeConfig(await config(cli))\n }) as DefinedConfig<TConfig>\n }\n\n if (isPromise(config)) {\n return config.then((resolved) => normalizeConfig(resolved)) as DefinedConfig<TConfig>\n }\n\n return normalizeConfig(config) as DefinedConfig<TConfig>\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAmBA,SAAgB,UAAa,QAAkD;CAC7E,OAAO,WAAW,QAAQ,WAAW,KAAA,KAAa,OAAQ,OAAmC,YAAY;AAC3G;;;;;;;;;;;;;;;;ACSA,SAAS,cAAsB,QAAgD;CAE7E,MAAM,UADmB,OAAO,SAAS,MAAM,MAAM,EAAE,SAASA,oBAAAA,gBAAgB,IAC5C,OAAO,WAAW,CAAC,IAAK,CAAC,GAAI,OAAO,WAAW,CAAC,IAAA,GAAA,oBAAA,aAAA,CAAiB,CAAC;CACtG,MAAM,kBAAkB,QAAQ,MAAM,MAAM,EAAE,SAASA,oBAAAA,gBAAgB;CAEvE,MAAM,SAAS,EAAE,GAAG,OAAO,OAAO;CAClC,IAAI,mBAAmB,OAAO,WAAW,KAAA,GACvC,OAAO,SAAS,EAAE,MAAM,QAAQ;CAElC,IAAI,OAAO,WAAW,KAAA,GACpB,OAAO,SAAS;CAElB,IAAI,OAAO,SAAS,KAAA,GAClB,OAAO,OAAO;CAGhB,OAAO;EACL,GAAG;EACH,MAAM,OAAO,QAAQ,QAAQ,IAAI;EACjC,SAAS,OAAO,YAAA,GAAA,kBAAA,WAAA,CAAsB;EACtC,SAAS,OAAO,SAAS,SAAS,OAAO,UAAU;GAACC,gBAAAA;GAAUC,gBAAAA;GAAWC,gBAAAA;EAAQ;EACjF,WAAW,OAAO,WAAW,SAAS,OAAO,YAAY;GAACC,WAAAA;GAAaC,WAAAA;GAAcC,WAAAA;EAAY;EACjG;EACA;CACF;AACF;AAEA,SAAS,gBAAwB,QAAwG;CACvI,IAAI,MAAM,QAAQ,MAAM,GACtB,OAAO,OAAO,IAAI,aAAa;CAGjC,OAAO,cAAc,MAAM;AAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,aAA0C,QAAyC;CACjG,IAAI,OAAO,WAAW,YACpB,QAAQ,OAAO,QAAoB;EACjC,OAAO,gBAAgB,MAAM,OAAO,GAAG,CAAC;CAC1C;CAGF,IAAI,UAAU,MAAM,GAClB,OAAO,OAAO,MAAM,aAAa,gBAAgB,QAAQ,CAAC;CAG5D,OAAO,gBAAgB,MAAM;AAC/B"}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../internals/utils/src/promise.ts","../src/defineConfig.ts"],"sourcesContent":["/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Wraps `factory` with a keyed cache backed by the provided store.\n *\n * Pass a `WeakMap` for object keys (results are GC-eligible when the key is\n * collected) or a `Map` for primitive keys. For multi-argument functions,\n * nest two `memoize` calls — the outer keyed by the first argument, the\n * inner (created once per outer miss) keyed by the second.\n *\n * Because the cache is owned by the caller, it can be shared, inspected, or\n * cleared independently of the memoized function.\n *\n * @example Single WeakMap key\n * ```ts\n * const cache = new WeakMap<SchemaNode, Set<string>>()\n * const getRefs = memoize(cache, (node) => collectRefs(node))\n * ```\n *\n * @example Single Map key (primitive)\n * ```ts\n * const cache = new Map<string, Resolver>()\n * const getResolver = memoize(cache, (name) => buildResolver(name))\n * ```\n *\n * @example Two-level (object + primitive)\n * ```ts\n * const outer = new WeakMap<Params[], Map<string, Params[]>>()\n * const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))\n * fn(params)('camelcase')\n * ```\n */\nexport function memoize<TKey, TValue>(store: Store<TKey, TValue>, factory: (key: TKey) => TValue): (key: TKey) => TValue {\n return (key: TKey): TValue => {\n if (store.has(key)) return store.get(key)!\n const value = factory(key)\n store.set(key, value)\n return value\n }\n}\n\n/**\n * Container that switches between an eager `Array<T>` and a lazy `AsyncIterable<T>`.\n *\n * `Array<T>` by default. With `Stream` set to `true` it becomes `AsyncIterable<T>`, so large\n * collections can be produced lazily without holding every item in memory. Pairs with\n * {@link arrayToAsyncIterable}, which lifts a plain array into the streaming form.\n *\n * @example\n * ```ts\n * type Eager = Streamable<number> // Array<number>\n * type Lazy = Streamable<number, true> // AsyncIterable<number>\n * ```\n */\nexport type Streamable<T, Stream extends boolean = false> = Stream extends true ? AsyncIterable<T> : Array<T>\n\n/**\n * Wraps a plain array in a reusable `AsyncIterable`.\n * Each `[Symbol.asyncIterator]()` call returns a fresh generator so the\n * iterable can be consumed multiple times (e.g. once per plugin pre-scan).\n *\n * @example\n * ```ts\n * const stream = arrayToAsyncIterable([1, 2, 3])\n * for await (const n of stream) console.log(n) // 1, 2, 3\n * ```\n */\nexport function arrayToAsyncIterable<T>(arr: ReadonlyArray<T>): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]() {\n return (async function* () {\n yield* arr\n })()\n },\n }\n}\n","import { isPromise, type PossiblePromise } from '@internals/utils'\nimport { adapterOas } from '@kubb/adapter-oas'\nimport { cliReporter, type CLIOptions, fileReporter, jsonReporter, type UserConfig } from '@kubb/core'\nimport { pluginBarrel, pluginBarrelName } from '@kubb/plugin-barrel'\nimport { parserTs, parserTsx } from '@kubb/parser-ts'\nimport { parserMd } from '@kubb/parser-md'\n\ntype AnyConfigResult = UserConfig<any> | Array<UserConfig<any>>\ntype ConfigInput = AnyConfigResult | Promise<AnyConfigResult> | ((cli: CLIOptions) => PossiblePromise<AnyConfigResult>)\ntype NormalizeConfig<TConfig> =\n TConfig extends Array<UserConfig<infer TInput>> ? Array<UserConfig<TInput>> : TConfig extends UserConfig<infer TInput> ? UserConfig<TInput> : never\ntype DefinedConfig<TConfig extends ConfigInput> = TConfig extends (cli: CLIOptions) => PossiblePromise<infer TResult>\n ? (cli: CLIOptions) => Promise<NormalizeConfig<TResult>>\n : TConfig extends Promise<infer TResult>\n ? Promise<NormalizeConfig<TResult>>\n : NormalizeConfig<TConfig>\n\n/**\n * Applies default `root`, adapter, parsers, plugins, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.\n *\n * - `root` defaults to `process.cwd()`\n * - `adapter` defaults to `adapterOas()`\n * - `parsers` defaults to `[parserTs, parserTsx, parserMd]`\n * - `reporters` defaults to `[cliReporter, jsonReporter, fileReporter]`\n * - `plugins` gets `pluginBarrel()` appended when none is already present\n * - `output.barrel` defaults to `{ type: 'named' }` only when `pluginBarrel` is part of `plugins`.\n * When the user provides a plugins list without `pluginBarrel`, `barrel` is left untouched.\n * - `output.format` defaults to `false`\n * - `output.lint` defaults to `false`\n */\nfunction applyDefaults<TInput>(config: UserConfig<TInput>): UserConfig<TInput> {\n const alreadyHasBarrel = config.plugins?.some((p) => p.name === pluginBarrelName)\n const plugins = alreadyHasBarrel ? (config.plugins ?? []) : [...(config.plugins ?? []), pluginBarrel()]\n const hasBarrelPlugin = plugins.some((p) => p.name === pluginBarrelName)\n\n const output = { ...config.output }\n if (hasBarrelPlugin && output.barrel === undefined) {\n output.barrel = { type: 'named' }\n }\n if (output.format === undefined) {\n output.format = false\n }\n if (output.lint === undefined) {\n output.lint = false\n }\n\n return {\n ...config,\n root: config.root || process.cwd(),\n adapter: config.adapter ?? adapterOas(),\n parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx, parserMd],\n reporters: config.reporters?.length ? config.reporters : [cliReporter, jsonReporter, fileReporter],\n plugins,\n output,\n }\n}\n\nfunction normalizeConfig<TInput>(config: UserConfig<TInput> | Array<UserConfig<TInput>>): UserConfig<TInput> | Array<UserConfig<TInput>> {\n if (Array.isArray(config)) {\n return config.map(applyDefaults)\n }\n\n return applyDefaults(config)\n}\n\n/**\n * Defines a Kubb build configuration and fills in defaults for any omitted fields.\n *\n * Defaults applied when omitted:\n * - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).\n * - `parsers` → `[parserTs, parserTsx, parserMd]`.\n * - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.\n * - `plugins` → `pluginBarrel()` is appended when not already present.\n * - `output.barrel` → `{ type: 'named' }` only when `pluginBarrel` is\n * in the plugins list.\n * - `output.format` and `output.lint` → `false`.\n *\n * Accepts a config object, an array of configs, a Promise resolving to one,\n * or a function that receives the parsed CLI options and returns any of the\n * above. The return type is preserved so async/array variants stay typed.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginTs } from '@kubb/plugin-ts'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [pluginTs()],\n * })\n * ```\n *\n * @example Function form with CLI options\n * ```ts\n * import { defineConfig } from 'kubb'\n *\n * export default defineConfig(({ input }) => ({\n * input: { path: input ?? './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [],\n * }))\n * ```\n */\nexport function defineConfig<TConfig extends ConfigInput>(config: TConfig): DefinedConfig<TConfig> {\n if (typeof config === 'function') {\n return (async (cli: CLIOptions) => {\n return normalizeConfig(await config(cli))\n }) as DefinedConfig<TConfig>\n }\n\n if (isPromise(config)) {\n return config.then((resolved) => normalizeConfig(resolved)) as DefinedConfig<TConfig>\n }\n\n return normalizeConfig(config) as DefinedConfig<TConfig>\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,SAAgB,UAAa,QAAkD;CAC7E,OAAO,WAAW,QAAQ,WAAW,KAAA,KAAa,OAAQ,OAAmC,YAAY;AAC3G;;;;;;;;;;;;;;;;ACSA,SAAS,cAAsB,QAAgD;CAE7E,MAAM,UADmB,OAAO,SAAS,MAAM,MAAM,EAAE,SAAS,gBAAgB,IAC5C,OAAO,WAAW,CAAC,IAAK,CAAC,GAAI,OAAO,WAAW,CAAC,GAAI,aAAa,CAAC;CACtG,MAAM,kBAAkB,QAAQ,MAAM,MAAM,EAAE,SAAS,gBAAgB;CAEvE,MAAM,SAAS,EAAE,GAAG,OAAO,OAAO;CAClC,IAAI,mBAAmB,OAAO,WAAW,KAAA,GACvC,OAAO,SAAS,EAAE,MAAM,QAAQ;CAElC,IAAI,OAAO,WAAW,KAAA,GACpB,OAAO,SAAS;CAElB,IAAI,OAAO,SAAS,KAAA,GAClB,OAAO,OAAO;CAGhB,OAAO;EACL,GAAG;EACH,MAAM,OAAO,QAAQ,QAAQ,IAAI;EACjC,SAAS,OAAO,WAAW,WAAW;EACtC,SAAS,OAAO,SAAS,SAAS,OAAO,UAAU;GAAC;GAAU;GAAW;EAAQ;EACjF,WAAW,OAAO,WAAW,SAAS,OAAO,YAAY;GAAC;GAAa;GAAc;EAAY;EACjG;EACA;CACF;AACF;AAEA,SAAS,gBAAwB,QAAwG;CACvI,IAAI,MAAM,QAAQ,MAAM,GACtB,OAAO,OAAO,IAAI,aAAa;CAGjC,OAAO,cAAc,MAAM;AAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,aAA0C,QAAyC;CACjG,IAAI,OAAO,WAAW,YACpB,QAAQ,OAAO,QAAoB;EACjC,OAAO,gBAAgB,MAAM,OAAO,GAAG,CAAC;CAC1C;CAGF,IAAI,UAAU,MAAM,GAClB,OAAO,OAAO,MAAM,aAAa,gBAAgB,QAAQ,CAAC;CAG5D,OAAO,gBAAgB,MAAM;AAC/B"}
|