@kubb/plugin-oas 5.0.0-alpha.3 → 5.0.0-alpha.30

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.
Files changed (61) hide show
  1. package/dist/{SchemaMapper-SneuY1wg.d.ts → SchemaMapper-CLIXrzqv.d.ts} +3 -3
  2. package/dist/SchemaMapper-CeavHZlp.cjs.map +1 -1
  3. package/dist/SchemaMapper-CqMkO2T1.js.map +1 -1
  4. package/dist/{createGenerator-jtR_okrd.d.ts → createGenerator-DL3CAvaU.d.ts} +121 -70
  5. package/dist/{generators-vAAte6w6.cjs → generators-85sP4GIS.cjs} +7 -7
  6. package/dist/generators-85sP4GIS.cjs.map +1 -0
  7. package/dist/{generators-B8HiBWvT.js → generators-hPE06pZB.js} +7 -7
  8. package/dist/generators-hPE06pZB.js.map +1 -0
  9. package/dist/generators.cjs +1 -1
  10. package/dist/generators.d.ts +4 -3
  11. package/dist/generators.js +1 -1
  12. package/dist/{getFooter-Pw3tLCiV.js → getFooter-Dz4u5Mg4.js} +5 -2
  13. package/dist/getFooter-Dz4u5Mg4.js.map +1 -0
  14. package/dist/{getFooter-BBzsC616.cjs → getFooter-gshcRE1-.cjs} +5 -2
  15. package/dist/getFooter-gshcRE1-.cjs.map +1 -0
  16. package/dist/hooks.cjs +25 -21
  17. package/dist/hooks.cjs.map +1 -1
  18. package/dist/hooks.d.ts +10 -7
  19. package/dist/hooks.js +27 -23
  20. package/dist/hooks.js.map +1 -1
  21. package/dist/index.cjs +50 -45
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.ts +26 -52
  24. package/dist/index.js +49 -44
  25. package/dist/index.js.map +1 -1
  26. package/dist/mocks.d.ts +1 -1
  27. package/dist/{requestBody-BJJL0mpy.cjs → requestBody-94hwM4b-.cjs} +115 -304
  28. package/dist/requestBody-94hwM4b-.cjs.map +1 -0
  29. package/dist/{requestBody-CSL-jLGQ.js → requestBody-BO3N7fWH.js} +107 -290
  30. package/dist/requestBody-BO3N7fWH.js.map +1 -0
  31. package/dist/utils.cjs +61 -11
  32. package/dist/utils.cjs.map +1 -1
  33. package/dist/utils.d.ts +4 -4
  34. package/dist/utils.js +61 -11
  35. package/dist/utils.js.map +1 -1
  36. package/package.json +8 -12
  37. package/src/OperationGenerator.ts +72 -86
  38. package/src/SchemaGenerator.ts +61 -82
  39. package/src/SchemaMapper.ts +2 -2
  40. package/src/generators/createGenerator.ts +13 -16
  41. package/src/generators/createReactGenerator.ts +12 -15
  42. package/src/generators/index.ts +2 -2
  43. package/src/generators/jsonGenerator.ts +3 -3
  44. package/src/generators/types.ts +5 -43
  45. package/src/hooks/useOas.ts +5 -2
  46. package/src/hooks/useOperationManager.ts +22 -21
  47. package/src/hooks/useSchemaManager.ts +8 -8
  48. package/src/index.ts +2 -2
  49. package/src/plugin.ts +13 -9
  50. package/src/types.ts +15 -8
  51. package/src/utils/getBanner.ts +1 -1
  52. package/src/utils/getFooter.ts +1 -1
  53. package/src/utils/getImports.ts +3 -3
  54. package/src/utils/getParams.ts +2 -2
  55. package/src/utils.tsx +51 -151
  56. package/dist/generators-B8HiBWvT.js.map +0 -1
  57. package/dist/generators-vAAte6w6.cjs.map +0 -1
  58. package/dist/getFooter-BBzsC616.cjs.map +0 -1
  59. package/dist/getFooter-Pw3tLCiV.js.map +0 -1
  60. package/dist/requestBody-BJJL0mpy.cjs.map +0 -1
  61. package/dist/requestBody-CSL-jLGQ.js.map +0 -1
@@ -1,9 +1,9 @@
1
1
  import "./chunk--u3MIqq1.js";
2
- import { i as pascalCase } from "./getFooter-Pw3tLCiV.js";
2
+ import { i as pascalCase } from "./getFooter-Dz4u5Mg4.js";
3
3
  import { n as schemaKeywords, t as isKeyword } from "./SchemaMapper-CqMkO2T1.js";
4
4
  import { KUBB_INLINE_REF_PREFIX, isDiscriminator, isNullable, isOpenApiV3_1Document, isReference } from "@kubb/oas";
5
5
  import { isDeepEqual, isNumber, uniqueWith } from "remeda";
6
- import { App, createReactFabric } from "@kubb/react-fabric";
6
+ import { Fabric, createReactFabric } from "@kubb/react-fabric";
7
7
  import { jsx } from "@kubb/react-fabric/jsx-runtime";
8
8
  //#region ../../internals/utils/src/names.ts
9
9
  /**
@@ -57,133 +57,6 @@ function stringify(value) {
57
57
  return JSON.stringify(trimQuotes(value.toString()));
58
58
  }
59
59
  //#endregion
60
- //#region ../../node_modules/.pnpm/yocto-queue@1.2.2/node_modules/yocto-queue/index.js
61
- var Node = class {
62
- value;
63
- next;
64
- constructor(value) {
65
- this.value = value;
66
- }
67
- };
68
- var Queue = class {
69
- #head;
70
- #tail;
71
- #size;
72
- constructor() {
73
- this.clear();
74
- }
75
- enqueue(value) {
76
- const node = new Node(value);
77
- if (this.#head) {
78
- this.#tail.next = node;
79
- this.#tail = node;
80
- } else {
81
- this.#head = node;
82
- this.#tail = node;
83
- }
84
- this.#size++;
85
- }
86
- dequeue() {
87
- const current = this.#head;
88
- if (!current) return;
89
- this.#head = this.#head.next;
90
- this.#size--;
91
- if (!this.#head) this.#tail = void 0;
92
- return current.value;
93
- }
94
- peek() {
95
- if (!this.#head) return;
96
- return this.#head.value;
97
- }
98
- clear() {
99
- this.#head = void 0;
100
- this.#tail = void 0;
101
- this.#size = 0;
102
- }
103
- get size() {
104
- return this.#size;
105
- }
106
- *[Symbol.iterator]() {
107
- let current = this.#head;
108
- while (current) {
109
- yield current.value;
110
- current = current.next;
111
- }
112
- }
113
- *drain() {
114
- while (this.#head) yield this.dequeue();
115
- }
116
- };
117
- //#endregion
118
- //#region ../../node_modules/.pnpm/p-limit@7.3.0/node_modules/p-limit/index.js
119
- function pLimit(concurrency) {
120
- let rejectOnClear = false;
121
- if (typeof concurrency === "object") ({concurrency, rejectOnClear = false} = concurrency);
122
- validateConcurrency(concurrency);
123
- if (typeof rejectOnClear !== "boolean") throw new TypeError("Expected `rejectOnClear` to be a boolean");
124
- const queue = new Queue();
125
- let activeCount = 0;
126
- const resumeNext = () => {
127
- if (activeCount < concurrency && queue.size > 0) {
128
- activeCount++;
129
- queue.dequeue().run();
130
- }
131
- };
132
- const next = () => {
133
- activeCount--;
134
- resumeNext();
135
- };
136
- const run = async (function_, resolve, arguments_) => {
137
- const result = (async () => function_(...arguments_))();
138
- resolve(result);
139
- try {
140
- await result;
141
- } catch {}
142
- next();
143
- };
144
- const enqueue = (function_, resolve, reject, arguments_) => {
145
- const queueItem = { reject };
146
- new Promise((internalResolve) => {
147
- queueItem.run = internalResolve;
148
- queue.enqueue(queueItem);
149
- }).then(run.bind(void 0, function_, resolve, arguments_));
150
- if (activeCount < concurrency) resumeNext();
151
- };
152
- const generator = (function_, ...arguments_) => new Promise((resolve, reject) => {
153
- enqueue(function_, resolve, reject, arguments_);
154
- });
155
- Object.defineProperties(generator, {
156
- activeCount: { get: () => activeCount },
157
- pendingCount: { get: () => queue.size },
158
- clearQueue: { value() {
159
- if (!rejectOnClear) {
160
- queue.clear();
161
- return;
162
- }
163
- const abortError = AbortSignal.abort().reason;
164
- while (queue.size > 0) queue.dequeue().reject(abortError);
165
- } },
166
- concurrency: {
167
- get: () => concurrency,
168
- set(newConcurrency) {
169
- validateConcurrency(newConcurrency);
170
- concurrency = newConcurrency;
171
- queueMicrotask(() => {
172
- while (activeCount < concurrency && queue.size > 0) resumeNext();
173
- });
174
- }
175
- },
176
- map: { async value(iterable, function_) {
177
- const promises = Array.from(iterable, (value, index) => this(function_, value, index));
178
- return Promise.all(promises);
179
- } }
180
- });
181
- return generator;
182
- }
183
- function validateConcurrency(concurrency) {
184
- if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) throw new TypeError("Expected `concurrency` to be a number from 1 and up");
185
- }
186
- //#endregion
187
60
  //#region src/utils/getSchemaFactory.ts
188
61
  /**
189
62
  * Creates a factory function that generates a versioned OpenAPI schema result.
@@ -203,137 +76,83 @@ function getSchemaFactory(oas) {
203
76
  }
204
77
  //#endregion
205
78
  //#region src/utils.tsx
206
- function isBuildOperationsV1Options(options) {
207
- return (options.version ?? "1") === "1";
208
- }
209
- async function buildOperations(operationsOrNodes, options) {
210
- const { config, fabric, plugin } = options;
211
- if (!options.Component) return;
79
+ /**
80
+ * Renders a React component for a list of operations (V1 generators).
81
+ */
82
+ async function renderOperations(operations, options) {
83
+ const { config, fabric, plugin, Component, generator } = options;
84
+ if (!Component) return;
85
+ const { driver, oas, mode } = generator.context;
212
86
  const fabricChild = createReactFabric();
213
- if (isBuildOperationsV1Options(options)) {
214
- const { generator, Component } = options;
215
- const { pluginManager, oas, mode } = generator.context;
216
- await fabricChild.render(/* @__PURE__ */ jsx(App, {
217
- meta: {
218
- pluginManager,
219
- plugin,
220
- mode,
221
- oas
222
- },
223
- children: /* @__PURE__ */ jsx(Component, {
224
- config,
225
- operations: operationsOrNodes,
226
- generator,
227
- plugin
228
- })
229
- }));
230
- } else {
231
- const { Component, adapter } = options;
232
- await fabricChild.render(/* @__PURE__ */ jsx(App, {
233
- meta: { plugin },
234
- children: /* @__PURE__ */ jsx(Component, {
235
- config,
236
- adapter,
237
- nodes: operationsOrNodes,
238
- options: plugin.options
239
- })
240
- }));
241
- }
242
- await fabric.context.fileManager.upsert(...fabricChild.files);
87
+ await fabricChild.render(/* @__PURE__ */ jsx(Fabric, {
88
+ meta: {
89
+ driver,
90
+ plugin,
91
+ mode,
92
+ oas
93
+ },
94
+ children: /* @__PURE__ */ jsx(Component, {
95
+ config,
96
+ operations,
97
+ generator,
98
+ plugin
99
+ })
100
+ }));
101
+ fabric.context.fileManager.upsert(...fabricChild.files);
243
102
  fabricChild.unmount();
244
103
  }
245
- function isBuildOperationV1Options(options) {
246
- return (options.version ?? "1") === "1";
247
- }
248
- async function buildOperation(operationOrNode, options) {
249
- const { config, fabric, plugin } = options;
250
- if (!options.Component) return;
104
+ /**
105
+ * Renders a React component for a single operation (V1 generators).
106
+ */
107
+ async function renderOperation(operation, options) {
108
+ const { config, fabric, plugin, Component, generator } = options;
109
+ if (!Component) return;
110
+ const { driver, oas, mode } = generator.context;
251
111
  const fabricChild = createReactFabric();
252
- if (isBuildOperationV1Options(options)) {
253
- const { generator, Component } = options;
254
- const { pluginManager, oas, mode } = generator.context;
255
- await fabricChild.render(/* @__PURE__ */ jsx(App, {
256
- meta: {
257
- pluginManager,
258
- plugin,
259
- mode,
260
- oas
261
- },
262
- children: /* @__PURE__ */ jsx(Component, {
263
- config,
264
- operation: operationOrNode,
265
- plugin,
266
- generator
267
- })
268
- }));
269
- } else {
270
- const { Component, adapter, pluginManager, mode } = options;
271
- await fabricChild.render(/* @__PURE__ */ jsx(App, {
272
- meta: {
273
- plugin,
274
- pluginManager,
275
- mode
276
- },
277
- children: /* @__PURE__ */ jsx(Component, {
278
- config,
279
- adapter,
280
- node: operationOrNode,
281
- options: plugin.options
282
- })
283
- }));
284
- }
285
- await fabric.context.fileManager.upsert(...fabricChild.files);
112
+ await fabricChild.render(/* @__PURE__ */ jsx(Fabric, {
113
+ meta: {
114
+ driver,
115
+ plugin,
116
+ mode,
117
+ oas
118
+ },
119
+ children: /* @__PURE__ */ jsx(Component, {
120
+ config,
121
+ operation,
122
+ plugin,
123
+ generator
124
+ })
125
+ }));
126
+ fabric.context.fileManager.upsert(...fabricChild.files);
286
127
  fabricChild.unmount();
287
128
  }
288
- function isBuildSchemaV1Options(options) {
289
- return (options.version ?? "1") === "1";
290
- }
291
- async function buildSchema(schema, options) {
292
- const { config, fabric, plugin } = options;
293
- if (!options.Component) return;
129
+ /**
130
+ * Renders a React component for a single schema (V1 generators).
131
+ */
132
+ async function renderSchema(schema, options) {
133
+ const { config, fabric, plugin, Component, generator } = options;
134
+ if (!Component) return;
135
+ const { driver, oas, mode } = generator.context;
294
136
  const fabricChild = createReactFabric();
295
- if (isBuildSchemaV1Options(options)) {
296
- const { generator, Component } = options;
297
- const { pluginManager, oas, mode } = generator.context;
298
- await fabricChild.render(/* @__PURE__ */ jsx(App, {
299
- meta: {
300
- pluginManager,
301
- plugin,
302
- mode,
303
- oas
304
- },
305
- children: /* @__PURE__ */ jsx(Component, {
306
- config,
307
- schema,
308
- plugin,
309
- generator
310
- })
311
- }));
312
- } else {
313
- const { Component, adapter, pluginManager, mode } = options;
314
- await fabricChild.render(/* @__PURE__ */ jsx(App, {
315
- meta: {
316
- plugin,
317
- pluginManager,
318
- mode
319
- },
320
- children: /* @__PURE__ */ jsx(Component, {
321
- config,
322
- adapter,
323
- node: schema,
324
- options: plugin.options
325
- })
326
- }));
327
- }
328
- await fabric.context.fileManager.upsert(...fabricChild.files);
137
+ await fabricChild.render(/* @__PURE__ */ jsx(Fabric, {
138
+ meta: {
139
+ driver,
140
+ plugin,
141
+ mode,
142
+ oas
143
+ },
144
+ children: /* @__PURE__ */ jsx(Component, {
145
+ config,
146
+ schema,
147
+ plugin,
148
+ generator
149
+ })
150
+ }));
151
+ fabric.context.fileManager.upsert(...fabricChild.files);
329
152
  fabricChild.unmount();
330
153
  }
331
154
  //#endregion
332
155
  //#region src/SchemaGenerator.ts
333
- /** Max concurrent generator tasks (across generators). */
334
- const GENERATOR_CONCURRENCY = 3;
335
- /** Max concurrent schema parsing tasks (per generator). */
336
- const SCHEMA_CONCURRENCY = 30;
337
156
  var SchemaGenerator = class SchemaGenerator {
338
157
  #options;
339
158
  #context;
@@ -610,17 +429,17 @@ var SchemaGenerator = class SchemaGenerator {
610
429
  this.#ensureNameMapping();
611
430
  const originalName = $ref.replace(/.+\//, "");
612
431
  const resolvedName = this.#schemaNameMapping.get($ref) || originalName;
613
- const propertyName = this.context.pluginManager.resolveName({
432
+ const propertyName = this.context.driver.resolveName({
614
433
  name: resolvedName,
615
434
  pluginName: this.context.plugin.name,
616
435
  type: "function"
617
436
  });
618
- const fileName = this.context.pluginManager.resolveName({
437
+ const fileName = this.context.driver.resolveName({
619
438
  name: resolvedName,
620
439
  pluginName: this.context.plugin.name,
621
440
  type: "file"
622
441
  });
623
- const file = this.context.pluginManager.getFile({
442
+ const file = this.context.driver.getFile({
624
443
  name: fileName,
625
444
  pluginName: this.context.plugin.name,
626
445
  extname: ".ts"
@@ -932,7 +751,7 @@ var SchemaGenerator = class SchemaGenerator {
932
751
  options.enumSuffix
933
752
  ];
934
753
  const enumName = useCollisionDetection ? pascalCase(enumNameParts.join(" ")) : getUniqueName(pascalCase(enumNameParts.join(" ")), this.options.usedEnumNames || {});
935
- const typeName = this.context.pluginManager.resolveName({
754
+ const typeName = this.context.driver.resolveName({
936
755
  name: enumName,
937
756
  pluginName: this.context.plugin.name,
938
757
  type: "type"
@@ -1259,12 +1078,11 @@ var SchemaGenerator = class SchemaGenerator {
1259
1078
  }
1260
1079
  async #doBuild(schemas, generators) {
1261
1080
  const schemaEntries = Object.entries(schemas);
1262
- const generatorLimit = pLimit(GENERATOR_CONCURRENCY);
1263
- const schemaLimit = pLimit(SCHEMA_CONCURRENCY);
1264
- const writeTasks = generators.map((generator) => generatorLimit(async () => {
1265
- if (generator.version === "2") return [];
1081
+ const results = [];
1082
+ for (const generator of generators) {
1083
+ if (!("type" in generator)) continue;
1266
1084
  const v1Generator = generator;
1267
- const schemaTasks = schemaEntries.map(([name, schemaObject]) => schemaLimit(async () => {
1085
+ for (const [name, schemaObject] of schemaEntries) {
1268
1086
  const options = this.#getOptions(name);
1269
1087
  const tree = this.parse({
1270
1088
  schema: schemaObject,
@@ -1272,16 +1090,32 @@ var SchemaGenerator = class SchemaGenerator {
1272
1090
  parentName: null,
1273
1091
  rootName: name
1274
1092
  });
1275
- if (v1Generator.type === "react") {
1276
- await buildSchema({
1277
- name,
1278
- value: schemaObject,
1279
- tree
1280
- }, {
1281
- config: this.context.pluginManager.config,
1282
- fabric: this.context.fabric,
1283
- Component: v1Generator.Schema,
1093
+ if (v1Generator.type === "react") await renderSchema({
1094
+ name,
1095
+ value: schemaObject,
1096
+ tree
1097
+ }, {
1098
+ config: this.context.driver.config,
1099
+ fabric: this.context.fabric,
1100
+ Component: v1Generator.Schema,
1101
+ generator: this,
1102
+ plugin: {
1103
+ ...this.context.plugin,
1104
+ options: {
1105
+ ...this.options,
1106
+ ...options
1107
+ }
1108
+ }
1109
+ });
1110
+ else {
1111
+ const result = await v1Generator.schema?.({
1112
+ config: this.context.driver.config,
1284
1113
  generator: this,
1114
+ schema: {
1115
+ name,
1116
+ value: schemaObject,
1117
+ tree
1118
+ },
1285
1119
  plugin: {
1286
1120
  ...this.context.plugin,
1287
1121
  options: {
@@ -1290,28 +1124,11 @@ var SchemaGenerator = class SchemaGenerator {
1290
1124
  }
1291
1125
  }
1292
1126
  });
1293
- return [];
1127
+ results.push(...[result ?? []].flat());
1294
1128
  }
1295
- return await v1Generator.schema?.({
1296
- config: this.context.pluginManager.config,
1297
- generator: this,
1298
- schema: {
1299
- name,
1300
- value: schemaObject,
1301
- tree
1302
- },
1303
- plugin: {
1304
- ...this.context.plugin,
1305
- options: {
1306
- ...this.options,
1307
- ...options
1308
- }
1309
- }
1310
- }) ?? [];
1311
- }));
1312
- return (await Promise.all(schemaTasks)).flat();
1313
- }));
1314
- return (await Promise.all(writeTasks)).flat();
1129
+ }
1130
+ }
1131
+ return results;
1315
1132
  }
1316
1133
  };
1317
1134
  //#endregion
@@ -1342,6 +1159,6 @@ function withRequiredRequestBodySchema(operationSchema) {
1342
1159
  };
1343
1160
  }
1344
1161
  //#endregion
1345
- export { buildOperations as a, pLimit as c, buildOperation as i, withRequiredRequestBodySchema as n, buildSchema as o, SchemaGenerator as r, getSchemaFactory as s, isRequestBodyRequired as t };
1162
+ export { renderOperations as a, renderOperation as i, withRequiredRequestBodySchema as n, renderSchema as o, SchemaGenerator as r, getSchemaFactory as s, isRequestBodyRequired as t };
1346
1163
 
1347
- //# sourceMappingURL=requestBody-CSL-jLGQ.js.map
1164
+ //# sourceMappingURL=requestBody-BO3N7fWH.js.map