@kubb/plugin-oas 0.0.0-canary-20240509211223

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 (75) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +44 -0
  3. package/dist/OperationGenerator-DvnXUUp4.d.ts +56 -0
  4. package/dist/OperationGenerator-X6CTMfhG.d.cts +56 -0
  5. package/dist/Schema-BWPWyiQO.d.cts +39 -0
  6. package/dist/Schema-DFZBfjF2.d.ts +39 -0
  7. package/dist/SchemaGenerator-hK5SHxTI.d.ts +316 -0
  8. package/dist/SchemaGenerator-z_7YrAAB.d.cts +316 -0
  9. package/dist/chunk-2MJ2CQMI.js +61 -0
  10. package/dist/chunk-2MJ2CQMI.js.map +1 -0
  11. package/dist/chunk-3RCQ2LNT.js +81 -0
  12. package/dist/chunk-3RCQ2LNT.js.map +1 -0
  13. package/dist/chunk-55NUFNT6.cjs +68 -0
  14. package/dist/chunk-55NUFNT6.cjs.map +1 -0
  15. package/dist/chunk-ECXSQTMV.cjs +81 -0
  16. package/dist/chunk-ECXSQTMV.cjs.map +1 -0
  17. package/dist/chunk-EPTOYYAP.js +3312 -0
  18. package/dist/chunk-EPTOYYAP.js.map +1 -0
  19. package/dist/chunk-H52M2RUX.cjs +3312 -0
  20. package/dist/chunk-H52M2RUX.cjs.map +1 -0
  21. package/dist/chunk-LQ6IAWRX.js +68 -0
  22. package/dist/chunk-LQ6IAWRX.js.map +1 -0
  23. package/dist/chunk-VNFSHGSN.cjs +61 -0
  24. package/dist/chunk-VNFSHGSN.cjs.map +1 -0
  25. package/dist/components.cjs +18 -0
  26. package/dist/components.cjs.map +1 -0
  27. package/dist/components.d.cts +41 -0
  28. package/dist/components.d.ts +41 -0
  29. package/dist/components.js +18 -0
  30. package/dist/components.js.map +1 -0
  31. package/dist/hooks.cjs +152 -0
  32. package/dist/hooks.cjs.map +1 -0
  33. package/dist/hooks.d.cts +76 -0
  34. package/dist/hooks.d.ts +76 -0
  35. package/dist/hooks.js +152 -0
  36. package/dist/hooks.js.map +1 -0
  37. package/dist/index.cjs +985 -0
  38. package/dist/index.cjs.map +1 -0
  39. package/dist/index.d.cts +17 -0
  40. package/dist/index.d.ts +17 -0
  41. package/dist/index.js +985 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/types-n5zV4Q3s.d.cts +146 -0
  44. package/dist/types-n5zV4Q3s.d.ts +146 -0
  45. package/dist/utils.cjs +126 -0
  46. package/dist/utils.cjs.map +1 -0
  47. package/dist/utils.d.cts +80 -0
  48. package/dist/utils.d.ts +80 -0
  49. package/dist/utils.js +126 -0
  50. package/dist/utils.js.map +1 -0
  51. package/package.json +107 -0
  52. package/src/OperationGenerator.ts +328 -0
  53. package/src/SchemaGenerator.ts +827 -0
  54. package/src/SchemaMapper.ts +145 -0
  55. package/src/components/Oas.tsx +31 -0
  56. package/src/components/Operation.tsx +21 -0
  57. package/src/components/Schema.tsx +156 -0
  58. package/src/components/index.ts +3 -0
  59. package/src/hooks/index.ts +5 -0
  60. package/src/hooks/useOas.ts +15 -0
  61. package/src/hooks/useOperation.ts +18 -0
  62. package/src/hooks/useOperationManager.ts +142 -0
  63. package/src/hooks/useOperations.ts +40 -0
  64. package/src/hooks/useSchema.ts +23 -0
  65. package/src/index.ts +30 -0
  66. package/src/plugin.ts +133 -0
  67. package/src/types.ts +147 -0
  68. package/src/utils/getComments.ts +15 -0
  69. package/src/utils/getGroupedByTagFiles.ts +81 -0
  70. package/src/utils/getParams.ts +57 -0
  71. package/src/utils/getSchemaFactory.ts +33 -0
  72. package/src/utils/getSchemas.ts +45 -0
  73. package/src/utils/index.ts +8 -0
  74. package/src/utils/parseFromConfig.ts +36 -0
  75. package/src/utils/refSorter.ts +13 -0
@@ -0,0 +1,61 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunk55NUFNT6cjs = require('./chunk-55NUFNT6.cjs');
4
+
5
+ // src/SchemaMapper.ts
6
+ _chunk55NUFNT6cjs.init_cjs_shims.call(void 0, );
7
+ var schemaKeywords = {
8
+ any: "any",
9
+ strict: "strict",
10
+ unknown: "unknown",
11
+ number: "number",
12
+ integer: "integer",
13
+ string: "string",
14
+ boolean: "boolean",
15
+ undefined: "undefined",
16
+ nullable: "nullable",
17
+ null: "null",
18
+ nullish: "nullish",
19
+ array: "array",
20
+ tuple: "tuple",
21
+ enum: "enum",
22
+ union: "union",
23
+ datetime: "datetime",
24
+ date: "date",
25
+ email: "email",
26
+ uuid: "uuid",
27
+ url: "url",
28
+ /* intersection */
29
+ default: "default",
30
+ const: "const",
31
+ and: "and",
32
+ describe: "describe",
33
+ min: "min",
34
+ max: "max",
35
+ optional: "optional",
36
+ readOnly: "readOnly",
37
+ // custom ones
38
+ object: "object",
39
+ ref: "ref",
40
+ matches: "matches",
41
+ firstName: "firstName",
42
+ lastName: "lastName",
43
+ password: "password",
44
+ phone: "phone",
45
+ blob: "blob",
46
+ deprecated: "deprecated",
47
+ example: "example",
48
+ schema: "schema",
49
+ catchall: "catchall",
50
+ time: "time",
51
+ name: "name"
52
+ };
53
+ function isKeyword(meta, keyword) {
54
+ return meta.keyword === keyword;
55
+ }
56
+
57
+
58
+
59
+
60
+ exports.schemaKeywords = schemaKeywords; exports.isKeyword = isKeyword;
61
+ //# sourceMappingURL=chunk-VNFSHGSN.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/SchemaMapper.ts"],"names":[],"mappings":";;;;;AAAA;AA+EO,IAAM,iBAAiB;AAAA,EAC5B,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,WAAW;AAAA,EACX,UAAU;AAAA,EACV,MAAM;AAAA,EACN,SAAS;AAAA,EACT,OAAO;AAAA,EACP,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AAAA,EACP,UAAU;AAAA,EACV,MAAM;AAAA,EACN,OAAO;AAAA,EACP,MAAM;AAAA,EACN,KAAK;AAAA;AAAA,EAEL,SAAS;AAAA,EACT,OAAO;AAAA,EACP,KAAK;AAAA,EACL,UAAU;AAAA,EACV,KAAK;AAAA,EACL,KAAK;AAAA,EACL,UAAU;AAAA,EACV,UAAU;AAAA;AAAA,EAGV,QAAQ;AAAA,EACR,KAAK;AAAA,EACL,SAAS;AAAA,EACT,WAAW;AAAA,EACX,UAAU;AAAA,EACV,UAAU;AAAA,EACV,OAAO;AAAA,EACP,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,MAAM;AAAA,EACN,MAAM;AACR;AAiBO,SAAS,UAAiE,MAAS,SAAwD;AAChJ,SAAO,KAAK,YAAY;AAC1B","sourcesContent":["import type { KubbFile } from '@kubb/core'\n\nexport type SchemaKeywordMapper = {\n object: {\n keyword: 'object'\n args: {\n properties: { [x: string]: Schema[] }\n additionalProperties: Schema[]\n strict?: boolean\n }\n }\n strict: { keyword: 'strict' }\n url: { keyword: 'url' }\n readOnly: { keyword: 'readOnly' }\n uuid: { keyword: 'uuid' }\n email: { keyword: 'email' }\n firstName: { keyword: 'firstName' }\n lastName: { keyword: 'lastName' }\n phone: { keyword: 'phone' }\n password: { keyword: 'password' }\n date: { keyword: 'date'; args: { type?: 'date' | 'string' } }\n time: { keyword: 'time'; args: { type?: 'date' | 'string' } }\n datetime: { keyword: 'datetime'; args: { offset?: boolean; local?: boolean } }\n tuple: { keyword: 'tuple'; args: Schema[] }\n array: {\n keyword: 'array'\n args: { items: Schema[]; min?: number; max?: number }\n }\n enum: {\n keyword: 'enum'\n args: {\n name: string\n typeName: string\n asConst: boolean\n items: Array<{\n name: string | number\n format: 'string' | 'number'\n value?: string | number\n }>\n }\n }\n and: { keyword: 'and'; args: Schema[] }\n const: {\n keyword: 'const'\n args: {\n name: string | number\n format: 'string' | 'number'\n value?: string | number\n }\n }\n union: { keyword: 'union'; args: Schema[] }\n ref: {\n keyword: 'ref'\n args: { name: string; path: KubbFile.OptionalPath; isTypeOnly?: boolean }\n }\n matches: { keyword: 'matches'; args?: string }\n boolean: { keyword: 'boolean' }\n default: { keyword: 'default'; args: string | number | boolean }\n string: { keyword: 'string' }\n integer: { keyword: 'integer' }\n number: { keyword: 'number' }\n max: { keyword: 'max'; args: number }\n min: { keyword: 'min'; args: number }\n describe: { keyword: 'describe'; args: string }\n example: { keyword: 'example'; args: string }\n deprecated: { keyword: 'deprecated' }\n optional: { keyword: 'optional' }\n undefined: { keyword: 'undefined' }\n nullish: { keyword: 'nullish' }\n nullable: { keyword: 'nullable' }\n null: { keyword: 'null' }\n any: { keyword: 'any' }\n unknown: { keyword: 'unknown' }\n blob: { keyword: 'blob' }\n schema: { keyword: 'schema'; args: { type: 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object'; format?: string } }\n name: { keyword: 'name'; args: string }\n catchall: { keyword: 'catchall' }\n}\n\nexport const schemaKeywords = {\n any: 'any',\n strict: 'strict',\n unknown: 'unknown',\n number: 'number',\n integer: 'integer',\n string: 'string',\n boolean: 'boolean',\n undefined: 'undefined',\n nullable: 'nullable',\n null: 'null',\n nullish: 'nullish',\n array: 'array',\n tuple: 'tuple',\n enum: 'enum',\n union: 'union',\n datetime: 'datetime',\n date: 'date',\n email: 'email',\n uuid: 'uuid',\n url: 'url',\n /* intersection */\n default: 'default',\n const: 'const',\n and: 'and',\n describe: 'describe',\n min: 'min',\n max: 'max',\n optional: 'optional',\n readOnly: 'readOnly',\n\n // custom ones\n object: 'object',\n ref: 'ref',\n matches: 'matches',\n firstName: 'firstName',\n lastName: 'lastName',\n password: 'password',\n phone: 'phone',\n blob: 'blob',\n deprecated: 'deprecated',\n example: 'example',\n schema: 'schema',\n catchall: 'catchall',\n time: 'time',\n name: 'name',\n} satisfies {\n [K in keyof SchemaKeywordMapper]: SchemaKeywordMapper[K]['keyword']\n}\n\nexport type SchemaKeyword = keyof SchemaKeywordMapper\n\nexport type SchemaMapper<T = string | null | undefined> = {\n [K in keyof SchemaKeywordMapper]: (() => T | undefined) | undefined\n}\n\nexport type SchemaKeywordBase<T> = {\n keyword: SchemaKeyword\n args: T\n}\n\nexport type Schema = { keyword: string } | SchemaKeywordMapper[keyof SchemaKeywordMapper]\n\nexport function isKeyword<T extends Schema, K extends keyof SchemaKeywordMapper>(meta: T, keyword: K): meta is Extract<T, SchemaKeywordMapper[K]> {\n return meta.keyword === keyword\n}\n"]}
@@ -0,0 +1,18 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+ var _chunkH52M2RUXcjs = require('./chunk-H52M2RUX.cjs');
6
+ require('./chunk-VNFSHGSN.cjs');
7
+
8
+
9
+ var _chunk55NUFNT6cjs = require('./chunk-55NUFNT6.cjs');
10
+
11
+ // src/components/index.ts
12
+ _chunk55NUFNT6cjs.init_cjs_shims.call(void 0, );
13
+
14
+
15
+
16
+
17
+ exports.Oas = _chunkH52M2RUXcjs.Oas; exports.Operation = _chunkH52M2RUXcjs.Operation; exports.Schema = _chunkH52M2RUXcjs.Schema;
18
+ //# sourceMappingURL=components.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA","sourcesContent":["export { Oas } from './Oas.tsx'\nexport { Operation } from './Operation.tsx'\nexport { Schema } from './Schema.tsx'\n"]}
@@ -0,0 +1,41 @@
1
+ import { S as Schema } from './Schema-BWPWyiQO.cjs';
2
+ import * as react from 'react';
3
+ import { Operation as Operation$1, Oas as Oas$1 } from '@kubb/oas';
4
+ import { KubbNode } from '@kubb/react';
5
+ import { a as OperationGenerator } from './OperationGenerator-X6CTMfhG.cjs';
6
+ import './SchemaGenerator-z_7YrAAB.cjs';
7
+ import '@kubb/core';
8
+ import './types-n5zV4Q3s.cjs';
9
+ import '@kubb/oas/parser';
10
+
11
+ type Props$1 = {
12
+ operation: Operation$1;
13
+ children?: KubbNode;
14
+ };
15
+ type OperationContextProps = {
16
+ operation?: Operation$1;
17
+ };
18
+ declare function Operation({ operation, children }: Props$1): KubbNode;
19
+ declare namespace Operation {
20
+ var Context: react.Context<OperationContextProps>;
21
+ }
22
+
23
+ type Props = {
24
+ oas: Oas$1;
25
+ operations?: Operation$1[];
26
+ generator?: OperationGenerator;
27
+ children?: KubbNode;
28
+ };
29
+ type OasContextProps = {
30
+ oas?: Oas$1;
31
+ operations?: Operation$1[];
32
+ generator?: OperationGenerator;
33
+ };
34
+ declare function Oas({ oas, children, operations, generator }: Props): KubbNode;
35
+ declare namespace Oas {
36
+ var Context: react.Context<OasContextProps>;
37
+ var Operation: typeof Operation;
38
+ var Schema: typeof Schema;
39
+ }
40
+
41
+ export { Oas, Operation, Schema };
@@ -0,0 +1,41 @@
1
+ import { S as Schema } from './Schema-DFZBfjF2.js';
2
+ import * as react from 'react';
3
+ import { Operation as Operation$1, Oas as Oas$1 } from '@kubb/oas';
4
+ import { KubbNode } from '@kubb/react';
5
+ import { a as OperationGenerator } from './OperationGenerator-DvnXUUp4.js';
6
+ import './SchemaGenerator-hK5SHxTI.js';
7
+ import '@kubb/core';
8
+ import './types-n5zV4Q3s.js';
9
+ import '@kubb/oas/parser';
10
+
11
+ type Props$1 = {
12
+ operation: Operation$1;
13
+ children?: KubbNode;
14
+ };
15
+ type OperationContextProps = {
16
+ operation?: Operation$1;
17
+ };
18
+ declare function Operation({ operation, children }: Props$1): KubbNode;
19
+ declare namespace Operation {
20
+ var Context: react.Context<OperationContextProps>;
21
+ }
22
+
23
+ type Props = {
24
+ oas: Oas$1;
25
+ operations?: Operation$1[];
26
+ generator?: OperationGenerator;
27
+ children?: KubbNode;
28
+ };
29
+ type OasContextProps = {
30
+ oas?: Oas$1;
31
+ operations?: Operation$1[];
32
+ generator?: OperationGenerator;
33
+ };
34
+ declare function Oas({ oas, children, operations, generator }: Props): KubbNode;
35
+ declare namespace Oas {
36
+ var Context: react.Context<OasContextProps>;
37
+ var Operation: typeof Operation;
38
+ var Schema: typeof Schema;
39
+ }
40
+
41
+ export { Oas, Operation, Schema };
@@ -0,0 +1,18 @@
1
+ import {
2
+ Oas,
3
+ Operation,
4
+ Schema
5
+ } from "./chunk-EPTOYYAP.js";
6
+ import "./chunk-2MJ2CQMI.js";
7
+ import {
8
+ init_esm_shims
9
+ } from "./chunk-LQ6IAWRX.js";
10
+
11
+ // src/components/index.ts
12
+ init_esm_shims();
13
+ export {
14
+ Oas,
15
+ Operation,
16
+ Schema
17
+ };
18
+ //# sourceMappingURL=components.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/index.ts"],"sourcesContent":["export { Oas } from './Oas.tsx'\nexport { Operation } from './Operation.tsx'\nexport { Schema } from './Schema.tsx'\n"],"mappings":";;;;;;;;;;;AAAA;","names":[]}
package/dist/hooks.cjs ADDED
@@ -0,0 +1,152 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+
5
+ var _chunkH52M2RUXcjs = require('./chunk-H52M2RUX.cjs');
6
+ require('./chunk-VNFSHGSN.cjs');
7
+
8
+
9
+ var _chunk55NUFNT6cjs = require('./chunk-55NUFNT6.cjs');
10
+
11
+ // src/hooks/index.ts
12
+ _chunk55NUFNT6cjs.init_cjs_shims.call(void 0, );
13
+
14
+ // src/hooks/useOas.ts
15
+ _chunk55NUFNT6cjs.init_cjs_shims.call(void 0, );
16
+ var _react = require('@kubb/react');
17
+ function useOas() {
18
+ const { oas } = _react.useContext.call(void 0, _chunkH52M2RUXcjs.Oas.Context);
19
+ if (!oas) {
20
+ throw new Error("Oas is not defined");
21
+ }
22
+ return oas;
23
+ }
24
+
25
+ // src/hooks/useOperation.ts
26
+ _chunk55NUFNT6cjs.init_cjs_shims.call(void 0, );
27
+
28
+ function useOperation() {
29
+ const { operation } = _react.useContext.call(void 0, _chunkH52M2RUXcjs.Operation.Context);
30
+ if (!operation) {
31
+ throw new Error("Operation is not defined");
32
+ }
33
+ return operation;
34
+ }
35
+
36
+ // src/hooks/useOperationManager.ts
37
+ _chunk55NUFNT6cjs.init_cjs_shims.call(void 0, );
38
+
39
+ function useOperationManager() {
40
+ const { plugin, pluginManager } = _react.useApp.call(void 0, );
41
+ const { generator } = _react.useContext.call(void 0, _chunkH52M2RUXcjs.Oas.Context);
42
+ if (!generator) {
43
+ throw new Error(`'generator' is not defined`);
44
+ }
45
+ const getName = (operation, { pluginKey = plugin.key, type }) => {
46
+ return pluginManager.resolveName({
47
+ name: operation.getOperationId(),
48
+ pluginKey,
49
+ type
50
+ });
51
+ };
52
+ const getFile = (operation, { pluginKey = plugin.key, extName = ".ts" } = {}) => {
53
+ const tag = _optionalChain([operation, 'access', _ => _.getTags, 'call', _2 => _2(), 'access', _3 => _3.at, 'call', _4 => _4(0), 'optionalAccess', _5 => _5.name]);
54
+ const name = getName(operation, { type: "file", pluginKey });
55
+ const file = pluginManager.getFile({
56
+ name,
57
+ extName,
58
+ pluginKey,
59
+ options: { type: "file", pluginKey, tag }
60
+ });
61
+ return {
62
+ ...file,
63
+ meta: {
64
+ ...file.meta,
65
+ name,
66
+ pluginKey,
67
+ tag
68
+ }
69
+ };
70
+ };
71
+ const groupSchemasByByName = (operation, { pluginKey = plugin.key, type }) => {
72
+ const schemas = generator.getSchemas(operation);
73
+ const errors = (schemas.errors || []).reduce(
74
+ (prev, acc) => {
75
+ if (!acc.statusCode) {
76
+ return prev;
77
+ }
78
+ prev[acc.statusCode] = pluginManager.resolveName({
79
+ name: acc.name,
80
+ pluginKey: plugin.key,
81
+ type
82
+ });
83
+ return prev;
84
+ },
85
+ {}
86
+ );
87
+ return {
88
+ request: _optionalChain([schemas, 'access', _6 => _6.request, 'optionalAccess', _7 => _7.name]) ? pluginManager.resolveName({
89
+ name: schemas.request.name,
90
+ pluginKey,
91
+ type
92
+ }) : void 0,
93
+ parameters: {
94
+ path: _optionalChain([schemas, 'access', _8 => _8.pathParams, 'optionalAccess', _9 => _9.name]) ? pluginManager.resolveName({
95
+ name: schemas.pathParams.name,
96
+ pluginKey,
97
+ type
98
+ }) : void 0,
99
+ query: _optionalChain([schemas, 'access', _10 => _10.queryParams, 'optionalAccess', _11 => _11.name]) ? pluginManager.resolveName({
100
+ name: schemas.queryParams.name,
101
+ pluginKey,
102
+ type
103
+ }) : void 0,
104
+ header: _optionalChain([schemas, 'access', _12 => _12.headerParams, 'optionalAccess', _13 => _13.name]) ? pluginManager.resolveName({
105
+ name: schemas.headerParams.name,
106
+ pluginKey,
107
+ type
108
+ }) : void 0
109
+ },
110
+ responses: {
111
+ [schemas.response.statusCode || "default"]: pluginManager.resolveName({
112
+ name: schemas.response.name,
113
+ pluginKey,
114
+ type
115
+ }),
116
+ ...errors
117
+ }
118
+ };
119
+ };
120
+ return {
121
+ getName,
122
+ getFile,
123
+ getSchemas: (operation, forStatusCode) => generator.getSchemas(operation, forStatusCode),
124
+ groupSchemasByByName
125
+ };
126
+ }
127
+
128
+ // src/hooks/useOperations.ts
129
+ _chunk55NUFNT6cjs.init_cjs_shims.call(void 0, );
130
+
131
+ function useOperations({ method, path } = {}) {
132
+ const { operations } = _react.useContext.call(void 0, _chunkH52M2RUXcjs.Oas.Context);
133
+ if (!operations) {
134
+ throw new Error("Operations is not defined");
135
+ }
136
+ let items = operations;
137
+ if (path) {
138
+ items = items.filter((item) => item.path === path);
139
+ }
140
+ if (method) {
141
+ items = items.filter((item) => item.method === method);
142
+ }
143
+ return items;
144
+ }
145
+
146
+
147
+
148
+
149
+
150
+
151
+ exports.useOas = useOas; exports.useOperation = useOperation; exports.useOperationManager = useOperationManager; exports.useOperations = useOperations; exports.useSchema = _chunkH52M2RUXcjs.useSchema;
152
+ //# sourceMappingURL=hooks.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/index.ts","../src/hooks/useOas.ts","../src/hooks/useOperation.ts","../src/hooks/useOperationManager.ts","../src/hooks/useOperations.ts"],"names":["useContext"],"mappings":";;;;;;;;;;;AAAA;;;ACAA;AAAA,SAAS,kBAAkB;AAMpB,SAAS,SAAkB;AAChC,QAAM,EAAE,IAAI,IAAI,WAAW,IAAI,OAAO;AAEtC,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,oBAAoB;AAAA,EACtC;AAEA,SAAO;AACT;;;ACdA;AAAA,SAAS,cAAAA,mBAAkB;AASpB,SAAS,eAA8B;AAC5C,QAAM,EAAE,UAAU,IAAIA,YAAW,UAAU,OAAO;AAElD,MAAI,CAAC,WAAW;AACd,UAAM,IAAI,MAAM,0BAA0B;AAAA,EAC5C;AAEA,SAAO;AACT;;;ACjBA;AAAA,SAAS,QAAQ,cAAAA,mBAAkB;AAkC5B,SAAS,sBAAiD;AAC/D,QAAM,EAAE,QAAQ,cAAc,IAAI,OAAO;AACzC,QAAM,EAAE,UAAU,IAAIA,YAAW,IAAI,OAAO;AAE5C,MAAI,CAAC,WAAW;AACd,UAAM,IAAI,MAAM,4BAA4B;AAAA,EAC9C;AAEA,QAAM,UAAgD,CAAC,WAAW,EAAE,YAAY,OAAO,KAAK,KAAK,MAAM;AACrG,WAAO,cAAc,YAAY;AAAA,MAC/B,MAAM,UAAU,eAAe;AAAA,MAC/B;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AAEA,QAAM,UAAgD,CAAC,WAAW,EAAE,YAAY,OAAO,KAAK,UAAU,MAAM,IAAI,CAAC,MAAM;AAErH,UAAM,MAAM,UAAU,QAAQ,EAAE,GAAG,CAAC,GAAG;AACvC,UAAM,OAAO,QAAQ,WAAW,EAAE,MAAM,QAAQ,UAAU,CAAC;AAE3D,UAAM,OAAO,cAAc,QAAQ;AAAA,MACjC;AAAA,MACA;AAAA,MACA;AAAA,MACA,SAAS,EAAE,MAAM,QAAQ,WAAW,IAAI;AAAA,IAC1C,CAAC;AAED,WAAO;AAAA,MACL,GAAG;AAAA,MACH,MAAM;AAAA,QACJ,GAAG,KAAK;AAAA,QACR;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,uBAA0E,CAAC,WAAW,EAAE,YAAY,OAAO,KAAK,KAAK,MAAM;AAC/H,UAAM,UAAU,UAAU,WAAW,SAAS;AAE9C,UAAM,UAAU,QAAQ,UAAU,CAAC,GAAG;AAAA,MACpC,CAAC,MAAM,QAAQ;AACb,YAAI,CAAC,IAAI,YAAY;AACnB,iBAAO;AAAA,QACT;AAEA,aAAK,IAAI,UAAU,IAAI,cAAc,YAAY;AAAA,UAC/C,MAAM,IAAI;AAAA,UACV,WAAW,OAAO;AAAA,UAClB;AAAA,QACF,CAAC;AAED,eAAO;AAAA,MACT;AAAA,MACA,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,MACL,SAAS,QAAQ,SAAS,OACtB,cAAc,YAAY;AAAA,QACxB,MAAM,QAAQ,QAAQ;AAAA,QACtB;AAAA,QACA;AAAA,MACF,CAAC,IACD;AAAA,MACJ,YAAY;AAAA,QACV,MAAM,QAAQ,YAAY,OACtB,cAAc,YAAY;AAAA,UACxB,MAAM,QAAQ,WAAW;AAAA,UACzB;AAAA,UACA;AAAA,QACF,CAAC,IACD;AAAA,QACJ,OAAO,QAAQ,aAAa,OACxB,cAAc,YAAY;AAAA,UACxB,MAAM,QAAQ,YAAY;AAAA,UAC1B;AAAA,UACA;AAAA,QACF,CAAC,IACD;AAAA,QACJ,QAAQ,QAAQ,cAAc,OAC1B,cAAc,YAAY;AAAA,UACxB,MAAM,QAAQ,aAAa;AAAA,UAC3B;AAAA,UACA;AAAA,QACF,CAAC,IACD;AAAA,MACN;AAAA,MACA,WAAW;AAAA,QACT,CAAC,QAAQ,SAAS,cAAc,SAAS,GAAG,cAAc,YAAY;AAAA,UACpE,MAAM,QAAQ,SAAS;AAAA,UACvB;AAAA,UACA;AAAA,QACF,CAAC;AAAA,QACD,GAAG;AAAA,MACL;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,YAAY,CAAC,WAAW,kBAAkB,UAAU,WAAW,WAAW,aAAa;AAAA,IACvF;AAAA,EACF;AACF;;;AC7IA;AAAA,SAAS,cAAAA,mBAAkB;AAsBpB,SAAS,cAAc,EAAE,QAAQ,KAAK,IAAwB,CAAC,GAAgB;AACpF,QAAM,EAAE,WAAW,IAAIA,YAAW,IAAI,OAAO;AAE7C,MAAI,CAAC,YAAY;AACf,UAAM,IAAI,MAAM,2BAA2B;AAAA,EAC7C;AACA,MAAI,QAAQ;AAEZ,MAAI,MAAM;AACR,YAAQ,MAAM,OAAO,CAAC,SAAS,KAAK,SAAS,IAAI;AAAA,EACnD;AAEA,MAAI,QAAQ;AACV,YAAQ,MAAM,OAAO,CAAC,SAAS,KAAK,WAAW,MAAM;AAAA,EACvD;AAEA,SAAO;AACT","sourcesContent":["export { useOas } from './useOas.ts'\nexport { useOperation } from './useOperation.ts'\nexport { useOperationManager } from './useOperationManager.ts'\nexport { useOperations } from './useOperations.ts'\nexport { useSchema } from './useSchema.ts'\n","import { useContext } from '@kubb/react'\n\nimport { Oas } from '../components/Oas.tsx'\n\nimport type { Oas as OasType } from '@kubb/oas'\n\nexport function useOas(): OasType {\n const { oas } = useContext(Oas.Context)\n\n if (!oas) {\n throw new Error('Oas is not defined')\n }\n\n return oas\n}\n","import { useContext } from '@kubb/react'\n\nimport { Operation } from '../components/Operation.tsx'\n\nimport type { Operation as OperationType } from '@kubb/oas'\n\n/**\n * `useOperation` will return the current `Operation`\n */\nexport function useOperation(): OperationType {\n const { operation } = useContext(Operation.Context)\n\n if (!operation) {\n throw new Error('Operation is not defined')\n }\n\n return operation\n}\n","import { useApp, useContext } from '@kubb/react'\n\nimport { Oas } from '../components/Oas.tsx'\n\nimport type { KubbFile, Plugin, ResolveNameParams } from '@kubb/core'\nimport type { Operation, Operation as OperationType } from '@kubb/oas'\nimport type { OperationSchemas } from '../types.ts'\n\ntype FileMeta = KubbFile.FileMetaBase & {\n pluginKey: Plugin['key']\n name: string\n tag?: string\n}\n\ntype SchemaNames = {\n request: string | undefined\n parameters: {\n path: string | undefined\n query: string | undefined\n header: string | undefined\n }\n responses: Record<number, string>\n}\n\ntype UseOperationManagerResult = {\n getName: (operation: OperationType, params: { pluginKey?: Plugin['key']; type: ResolveNameParams['type'] }) => string\n getFile: (operation: OperationType, params?: { pluginKey?: Plugin['key']; extName?: KubbFile.Extname }) => KubbFile.File<FileMeta>\n groupSchemasByByName: (operation: OperationType, params: { pluginKey?: Plugin['key']; type: ResolveNameParams['type'] }) => SchemaNames\n getSchemas: (operation: Operation, forStatusCode?: string | number) => OperationSchemas\n}\n\n/**\n * `useOperationManager` will return some helper functions that can be used to get the operation file, get the operation name.\n */\nexport function useOperationManager(): UseOperationManagerResult {\n const { plugin, pluginManager } = useApp()\n const { generator } = useContext(Oas.Context)\n\n if (!generator) {\n throw new Error(`'generator' is not defined`)\n }\n\n const getName: UseOperationManagerResult['getName'] = (operation, { pluginKey = plugin.key, type }) => {\n return pluginManager.resolveName({\n name: operation.getOperationId(),\n pluginKey,\n type,\n })\n }\n\n const getFile: UseOperationManagerResult['getFile'] = (operation, { pluginKey = plugin.key, extName = '.ts' } = {}) => {\n // needed for the `output.group`\n const tag = operation.getTags().at(0)?.name\n const name = getName(operation, { type: 'file', pluginKey })\n\n const file = pluginManager.getFile({\n name,\n extName,\n pluginKey,\n options: { type: 'file', pluginKey, tag },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name,\n pluginKey,\n tag,\n },\n }\n }\n\n const groupSchemasByByName: UseOperationManagerResult['groupSchemasByByName'] = (operation, { pluginKey = plugin.key, type }) => {\n const schemas = generator.getSchemas(operation)\n\n const errors = (schemas.errors || []).reduce(\n (prev, acc) => {\n if (!acc.statusCode) {\n return prev\n }\n\n prev[acc.statusCode] = pluginManager.resolveName({\n name: acc.name,\n pluginKey: plugin.key,\n type,\n })\n\n return prev\n },\n {} as Record<number, string>,\n )\n\n return {\n request: schemas.request?.name\n ? pluginManager.resolveName({\n name: schemas.request.name,\n pluginKey,\n type,\n })\n : undefined,\n parameters: {\n path: schemas.pathParams?.name\n ? pluginManager.resolveName({\n name: schemas.pathParams.name,\n pluginKey,\n type,\n })\n : undefined,\n query: schemas.queryParams?.name\n ? pluginManager.resolveName({\n name: schemas.queryParams.name,\n pluginKey,\n type,\n })\n : undefined,\n header: schemas.headerParams?.name\n ? pluginManager.resolveName({\n name: schemas.headerParams.name,\n pluginKey,\n type,\n })\n : undefined,\n },\n responses: {\n [schemas.response.statusCode || 'default']: pluginManager.resolveName({\n name: schemas.response.name,\n pluginKey,\n type,\n }),\n ...errors,\n },\n }\n }\n\n return {\n getName,\n getFile,\n getSchemas: (operation, forStatusCode) => generator.getSchemas(operation, forStatusCode),\n groupSchemasByByName,\n }\n}\n","import { useContext } from '@kubb/react'\n\nimport { Oas } from '../components/Oas.tsx'\n\nimport type { HttpMethod, Operation } from '@kubb/oas'\n\ntype UseOperationsProps = {\n /**\n * Filter based on path\n * Weight: 2\n */\n path?: string\n /**\n * Filter based on method\n * Weight: 1\n */\n method?: HttpMethod\n}\n\n/**\n * `useOperations` will return all the Operations\n */\nexport function useOperations({ method, path }: UseOperationsProps = {}): Operation[] {\n const { operations } = useContext(Oas.Context)\n\n if (!operations) {\n throw new Error('Operations is not defined')\n }\n let items = operations\n\n if (path) {\n items = items.filter((item) => item.path === path)\n }\n\n if (method) {\n items = items.filter((item) => item.method === method)\n }\n\n return items\n}\n"]}
@@ -0,0 +1,76 @@
1
+ import { Oas, Operation, HttpMethod } from '@kubb/oas';
2
+ import { Plugin, ResolveNameParams, KubbFile } from '@kubb/core';
3
+ import { e as OperationSchemas } from './types-n5zV4Q3s.cjs';
4
+ import { a as SchemaContextProps } from './Schema-BWPWyiQO.cjs';
5
+ import { c as SchemaGenerator } from './SchemaGenerator-z_7YrAAB.cjs';
6
+ import '@kubb/oas/parser';
7
+ import 'react';
8
+ import '@kubb/react';
9
+
10
+ declare function useOas(): Oas;
11
+
12
+ /**
13
+ * `useOperation` will return the current `Operation`
14
+ */
15
+ declare function useOperation(): Operation;
16
+
17
+ type FileMeta = KubbFile.FileMetaBase & {
18
+ pluginKey: Plugin['key'];
19
+ name: string;
20
+ tag?: string;
21
+ };
22
+ type SchemaNames = {
23
+ request: string | undefined;
24
+ parameters: {
25
+ path: string | undefined;
26
+ query: string | undefined;
27
+ header: string | undefined;
28
+ };
29
+ responses: Record<number, string>;
30
+ };
31
+ type UseOperationManagerResult = {
32
+ getName: (operation: Operation, params: {
33
+ pluginKey?: Plugin['key'];
34
+ type: ResolveNameParams['type'];
35
+ }) => string;
36
+ getFile: (operation: Operation, params?: {
37
+ pluginKey?: Plugin['key'];
38
+ extName?: KubbFile.Extname;
39
+ }) => KubbFile.File<FileMeta>;
40
+ groupSchemasByByName: (operation: Operation, params: {
41
+ pluginKey?: Plugin['key'];
42
+ type: ResolveNameParams['type'];
43
+ }) => SchemaNames;
44
+ getSchemas: (operation: Operation, forStatusCode?: string | number) => OperationSchemas;
45
+ };
46
+ /**
47
+ * `useOperationManager` will return some helper functions that can be used to get the operation file, get the operation name.
48
+ */
49
+ declare function useOperationManager(): UseOperationManagerResult;
50
+
51
+ type UseOperationsProps = {
52
+ /**
53
+ * Filter based on path
54
+ * Weight: 2
55
+ */
56
+ path?: string;
57
+ /**
58
+ * Filter based on method
59
+ * Weight: 1
60
+ */
61
+ method?: HttpMethod;
62
+ };
63
+ /**
64
+ * `useOperations` will return all the Operations
65
+ */
66
+ declare function useOperations({ method, path }?: UseOperationsProps): Operation[];
67
+
68
+ type UseSchemaResult = Omit<SchemaContextProps, 'generator'> & {
69
+ generator: SchemaGenerator;
70
+ };
71
+ /**
72
+ * `useSchema` will return the current `schema properties`
73
+ */
74
+ declare function useSchema(): UseSchemaResult;
75
+
76
+ export { useOas, useOperation, useOperationManager, useOperations, useSchema };
@@ -0,0 +1,76 @@
1
+ import { Oas, Operation, HttpMethod } from '@kubb/oas';
2
+ import { Plugin, ResolveNameParams, KubbFile } from '@kubb/core';
3
+ import { e as OperationSchemas } from './types-n5zV4Q3s.js';
4
+ import { a as SchemaContextProps } from './Schema-DFZBfjF2.js';
5
+ import { c as SchemaGenerator } from './SchemaGenerator-hK5SHxTI.js';
6
+ import '@kubb/oas/parser';
7
+ import 'react';
8
+ import '@kubb/react';
9
+
10
+ declare function useOas(): Oas;
11
+
12
+ /**
13
+ * `useOperation` will return the current `Operation`
14
+ */
15
+ declare function useOperation(): Operation;
16
+
17
+ type FileMeta = KubbFile.FileMetaBase & {
18
+ pluginKey: Plugin['key'];
19
+ name: string;
20
+ tag?: string;
21
+ };
22
+ type SchemaNames = {
23
+ request: string | undefined;
24
+ parameters: {
25
+ path: string | undefined;
26
+ query: string | undefined;
27
+ header: string | undefined;
28
+ };
29
+ responses: Record<number, string>;
30
+ };
31
+ type UseOperationManagerResult = {
32
+ getName: (operation: Operation, params: {
33
+ pluginKey?: Plugin['key'];
34
+ type: ResolveNameParams['type'];
35
+ }) => string;
36
+ getFile: (operation: Operation, params?: {
37
+ pluginKey?: Plugin['key'];
38
+ extName?: KubbFile.Extname;
39
+ }) => KubbFile.File<FileMeta>;
40
+ groupSchemasByByName: (operation: Operation, params: {
41
+ pluginKey?: Plugin['key'];
42
+ type: ResolveNameParams['type'];
43
+ }) => SchemaNames;
44
+ getSchemas: (operation: Operation, forStatusCode?: string | number) => OperationSchemas;
45
+ };
46
+ /**
47
+ * `useOperationManager` will return some helper functions that can be used to get the operation file, get the operation name.
48
+ */
49
+ declare function useOperationManager(): UseOperationManagerResult;
50
+
51
+ type UseOperationsProps = {
52
+ /**
53
+ * Filter based on path
54
+ * Weight: 2
55
+ */
56
+ path?: string;
57
+ /**
58
+ * Filter based on method
59
+ * Weight: 1
60
+ */
61
+ method?: HttpMethod;
62
+ };
63
+ /**
64
+ * `useOperations` will return all the Operations
65
+ */
66
+ declare function useOperations({ method, path }?: UseOperationsProps): Operation[];
67
+
68
+ type UseSchemaResult = Omit<SchemaContextProps, 'generator'> & {
69
+ generator: SchemaGenerator;
70
+ };
71
+ /**
72
+ * `useSchema` will return the current `schema properties`
73
+ */
74
+ declare function useSchema(): UseSchemaResult;
75
+
76
+ export { useOas, useOperation, useOperationManager, useOperations, useSchema };
package/dist/hooks.js ADDED
@@ -0,0 +1,152 @@
1
+ import {
2
+ Oas,
3
+ Operation,
4
+ useSchema
5
+ } from "./chunk-EPTOYYAP.js";
6
+ import "./chunk-2MJ2CQMI.js";
7
+ import {
8
+ init_esm_shims
9
+ } from "./chunk-LQ6IAWRX.js";
10
+
11
+ // src/hooks/index.ts
12
+ init_esm_shims();
13
+
14
+ // src/hooks/useOas.ts
15
+ init_esm_shims();
16
+ import { useContext } from "@kubb/react";
17
+ function useOas() {
18
+ const { oas } = useContext(Oas.Context);
19
+ if (!oas) {
20
+ throw new Error("Oas is not defined");
21
+ }
22
+ return oas;
23
+ }
24
+
25
+ // src/hooks/useOperation.ts
26
+ init_esm_shims();
27
+ import { useContext as useContext2 } from "@kubb/react";
28
+ function useOperation() {
29
+ const { operation } = useContext2(Operation.Context);
30
+ if (!operation) {
31
+ throw new Error("Operation is not defined");
32
+ }
33
+ return operation;
34
+ }
35
+
36
+ // src/hooks/useOperationManager.ts
37
+ init_esm_shims();
38
+ import { useApp, useContext as useContext3 } from "@kubb/react";
39
+ function useOperationManager() {
40
+ const { plugin, pluginManager } = useApp();
41
+ const { generator } = useContext3(Oas.Context);
42
+ if (!generator) {
43
+ throw new Error(`'generator' is not defined`);
44
+ }
45
+ const getName = (operation, { pluginKey = plugin.key, type }) => {
46
+ return pluginManager.resolveName({
47
+ name: operation.getOperationId(),
48
+ pluginKey,
49
+ type
50
+ });
51
+ };
52
+ const getFile = (operation, { pluginKey = plugin.key, extName = ".ts" } = {}) => {
53
+ const tag = operation.getTags().at(0)?.name;
54
+ const name = getName(operation, { type: "file", pluginKey });
55
+ const file = pluginManager.getFile({
56
+ name,
57
+ extName,
58
+ pluginKey,
59
+ options: { type: "file", pluginKey, tag }
60
+ });
61
+ return {
62
+ ...file,
63
+ meta: {
64
+ ...file.meta,
65
+ name,
66
+ pluginKey,
67
+ tag
68
+ }
69
+ };
70
+ };
71
+ const groupSchemasByByName = (operation, { pluginKey = plugin.key, type }) => {
72
+ const schemas = generator.getSchemas(operation);
73
+ const errors = (schemas.errors || []).reduce(
74
+ (prev, acc) => {
75
+ if (!acc.statusCode) {
76
+ return prev;
77
+ }
78
+ prev[acc.statusCode] = pluginManager.resolveName({
79
+ name: acc.name,
80
+ pluginKey: plugin.key,
81
+ type
82
+ });
83
+ return prev;
84
+ },
85
+ {}
86
+ );
87
+ return {
88
+ request: schemas.request?.name ? pluginManager.resolveName({
89
+ name: schemas.request.name,
90
+ pluginKey,
91
+ type
92
+ }) : void 0,
93
+ parameters: {
94
+ path: schemas.pathParams?.name ? pluginManager.resolveName({
95
+ name: schemas.pathParams.name,
96
+ pluginKey,
97
+ type
98
+ }) : void 0,
99
+ query: schemas.queryParams?.name ? pluginManager.resolveName({
100
+ name: schemas.queryParams.name,
101
+ pluginKey,
102
+ type
103
+ }) : void 0,
104
+ header: schemas.headerParams?.name ? pluginManager.resolveName({
105
+ name: schemas.headerParams.name,
106
+ pluginKey,
107
+ type
108
+ }) : void 0
109
+ },
110
+ responses: {
111
+ [schemas.response.statusCode || "default"]: pluginManager.resolveName({
112
+ name: schemas.response.name,
113
+ pluginKey,
114
+ type
115
+ }),
116
+ ...errors
117
+ }
118
+ };
119
+ };
120
+ return {
121
+ getName,
122
+ getFile,
123
+ getSchemas: (operation, forStatusCode) => generator.getSchemas(operation, forStatusCode),
124
+ groupSchemasByByName
125
+ };
126
+ }
127
+
128
+ // src/hooks/useOperations.ts
129
+ init_esm_shims();
130
+ import { useContext as useContext4 } from "@kubb/react";
131
+ function useOperations({ method, path } = {}) {
132
+ const { operations } = useContext4(Oas.Context);
133
+ if (!operations) {
134
+ throw new Error("Operations is not defined");
135
+ }
136
+ let items = operations;
137
+ if (path) {
138
+ items = items.filter((item) => item.path === path);
139
+ }
140
+ if (method) {
141
+ items = items.filter((item) => item.method === method);
142
+ }
143
+ return items;
144
+ }
145
+ export {
146
+ useOas,
147
+ useOperation,
148
+ useOperationManager,
149
+ useOperations,
150
+ useSchema
151
+ };
152
+ //# sourceMappingURL=hooks.js.map