@kubb/agent 5.0.0-beta.2 → 5.0.0-beta.20
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/.output/nitro.json +1 -1
- package/.output/server/chunks/nitro/nitro.mjs +1480 -1561
- package/.output/server/chunks/nitro/nitro.mjs.map +1 -1
- package/.output/server/chunks/routes/api/health.get.mjs +1 -1
- package/.output/server/index.mjs +1 -1
- package/.output/server/node_modules/ajv/dist/2019.d.ts +1 -1
- package/.output/server/node_modules/ajv/dist/2019.js.map +1 -1
- package/.output/server/node_modules/ajv/dist/2020.d.ts +1 -1
- package/.output/server/node_modules/ajv/dist/2020.js.map +1 -1
- package/.output/server/node_modules/ajv/dist/ajv.d.ts +1 -1
- package/.output/server/node_modules/ajv/dist/ajv.js.map +1 -1
- package/.output/server/node_modules/ajv/dist/compile/index.d.ts +2 -1
- package/.output/server/node_modules/ajv/dist/compile/index.js +10 -3
- package/.output/server/node_modules/ajv/dist/compile/index.js.map +1 -1
- package/.output/server/node_modules/ajv/dist/compile/jtd/parse.js +1 -1
- package/.output/server/node_modules/ajv/dist/compile/jtd/parse.js.map +1 -1
- package/.output/server/node_modules/ajv/dist/compile/jtd/serialize.js +1 -1
- package/.output/server/node_modules/ajv/dist/compile/jtd/serialize.js.map +1 -1
- package/.output/server/node_modules/ajv/dist/compile/names.d.ts +1 -0
- package/.output/server/node_modules/ajv/dist/compile/names.js +1 -0
- package/.output/server/node_modules/ajv/dist/compile/names.js.map +1 -1
- package/.output/server/node_modules/ajv/dist/compile/validate/index.d.ts +1 -1
- package/.output/server/node_modules/ajv/dist/compile/validate/index.js +18 -4
- package/.output/server/node_modules/ajv/dist/compile/validate/index.js.map +1 -1
- package/.output/server/node_modules/ajv/dist/core.d.ts +4 -0
- package/.output/server/node_modules/ajv/dist/core.js +15 -1
- package/.output/server/node_modules/ajv/dist/core.js.map +1 -1
- package/.output/server/node_modules/ajv/dist/draft4.d.ts +19 -0
- package/.output/server/node_modules/ajv/dist/draft4.js +57 -0
- package/.output/server/node_modules/ajv/dist/draft4.js.map +1 -0
- package/.output/server/node_modules/ajv/dist/refs/json-schema-draft-04.json +138 -0
- package/.output/server/node_modules/ajv/dist/types/index.d.ts +3 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js +2 -1
- package/.output/server/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js.map +1 -1
- package/.output/server/node_modules/ajv/dist/vocabularies/applicator/allOf.js +1 -1
- package/.output/server/node_modules/ajv/dist/vocabularies/applicator/allOf.js.map +1 -1
- package/.output/server/node_modules/ajv/dist/vocabularies/applicator/properties.js +2 -1
- package/.output/server/node_modules/ajv/dist/vocabularies/applicator/properties.js.map +1 -1
- package/.output/server/node_modules/ajv/dist/vocabularies/code.d.ts +1 -1
- package/.output/server/node_modules/ajv/dist/vocabularies/code.js +10 -3
- package/.output/server/node_modules/ajv/dist/vocabularies/code.js.map +1 -1
- package/.output/server/node_modules/ajv/dist/vocabularies/core/ref.js +12 -2
- package/.output/server/node_modules/ajv/dist/vocabularies/core/ref.js.map +1 -1
- package/.output/server/node_modules/ajv/dist/vocabularies/discriminator/index.js +56 -21
- package/.output/server/node_modules/ajv/dist/vocabularies/discriminator/index.js.map +1 -1
- package/.output/server/node_modules/ajv/dist/vocabularies/draft4.d.ts +3 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/draft4.js +29 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/draft4.js.map +1 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/metadata.js +10 -2
- package/.output/server/node_modules/ajv/dist/vocabularies/metadata.js.map +1 -1
- package/.output/server/node_modules/ajv/dist/vocabularies/oasContext.d.ts +3 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/oasContext.js +26 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/oasContext.js.map +1 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedProperties.js +22 -3
- package/.output/server/node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedProperties.js.map +1 -1
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/draft04/limitNumber.d.ts +12 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/draft04/limitNumber.js +43 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/draft04/limitNumber.js.map +1 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/draft04/limitNumberExclusive.d.ts +3 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/draft04/limitNumberExclusive.js +19 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/draft04/limitNumberExclusive.js.map +1 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/index.js +4 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/index.js.map +1 -1
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/readOnly.d.ts +3 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/readOnly.js +20 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/readOnly.js.map +1 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/required.js +8 -1
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/required.js.map +1 -1
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/writeOnly.d.ts +3 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/writeOnly.js +20 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/writeOnly.js.map +1 -0
- package/.output/server/node_modules/ajv/lib/2019.ts +1 -0
- package/.output/server/node_modules/ajv/lib/2020.ts +1 -0
- package/.output/server/node_modules/ajv/lib/ajv.ts +1 -0
- package/.output/server/node_modules/ajv/lib/compile/index.ts +16 -3
- package/.output/server/node_modules/ajv/lib/compile/jtd/parse.ts +3 -1
- package/.output/server/node_modules/ajv/lib/compile/jtd/serialize.ts +3 -1
- package/.output/server/node_modules/ajv/lib/compile/names.ts +1 -0
- package/.output/server/node_modules/ajv/lib/compile/validate/index.ts +21 -4
- package/.output/server/node_modules/ajv/lib/core.ts +20 -1
- package/.output/server/node_modules/ajv/lib/draft4.ts +79 -0
- package/.output/server/node_modules/ajv/lib/refs/json-schema-draft-04.json +138 -0
- package/.output/server/node_modules/ajv/lib/types/index.ts +4 -0
- package/.output/server/node_modules/ajv/lib/vocabularies/applicator/additionalProperties.ts +2 -1
- package/.output/server/node_modules/ajv/lib/vocabularies/applicator/allOf.ts +1 -1
- package/.output/server/node_modules/ajv/lib/vocabularies/applicator/properties.ts +4 -1
- package/.output/server/node_modules/ajv/lib/vocabularies/code.ts +10 -3
- package/.output/server/node_modules/ajv/lib/vocabularies/core/ref.ts +21 -5
- package/.output/server/node_modules/ajv/lib/vocabularies/discriminator/index.ts +69 -19
- package/.output/server/node_modules/ajv/lib/vocabularies/draft4.ts +32 -0
- package/.output/server/node_modules/ajv/lib/vocabularies/metadata.ts +10 -2
- package/.output/server/node_modules/ajv/lib/vocabularies/oasContext.ts +27 -0
- package/.output/server/node_modules/ajv/lib/vocabularies/unevaluated/unevaluatedProperties.ts +29 -7
- package/.output/server/node_modules/ajv/lib/vocabularies/validation/draft04/limitNumber.ts +75 -0
- package/.output/server/node_modules/ajv/lib/vocabularies/validation/draft04/limitNumberExclusive.ts +26 -0
- package/.output/server/node_modules/ajv/lib/vocabularies/validation/index.ts +4 -0
- package/.output/server/node_modules/ajv/lib/vocabularies/validation/readOnly.ts +23 -0
- package/.output/server/node_modules/ajv/lib/vocabularies/validation/required.ts +7 -1
- package/.output/server/node_modules/ajv/lib/vocabularies/validation/writeOnly.ts +22 -0
- package/.output/server/node_modules/ajv/package.json +9 -6
- package/.output/server/node_modules/fflate/esm/index.mjs +87 -56
- package/.output/server/node_modules/fflate/package.json +12 -11
- package/.output/server/node_modules/jiti/LICENSE +21 -0
- package/.output/server/node_modules/jiti/README.md +258 -0
- package/.output/server/node_modules/jiti/dist/babel.cjs +257 -0
- package/.output/server/node_modules/jiti/dist/jiti.cjs +1 -0
- package/.output/server/node_modules/jiti/lib/jiti-cli.mjs +34 -0
- package/.output/server/node_modules/jiti/lib/jiti-hooks.mjs +124 -0
- package/.output/server/node_modules/jiti/lib/jiti-native.mjs +121 -0
- package/.output/server/node_modules/jiti/lib/jiti-register.d.mts +1 -0
- package/.output/server/node_modules/jiti/lib/jiti-register.mjs +4 -0
- package/.output/server/node_modules/jiti/lib/jiti-static.mjs +23 -0
- package/.output/server/node_modules/jiti/lib/jiti.cjs +30 -0
- package/.output/server/node_modules/jiti/lib/jiti.d.cts +8 -0
- package/.output/server/node_modules/jiti/lib/jiti.d.mts +8 -0
- package/.output/server/node_modules/jiti/lib/jiti.mjs +29 -0
- package/.output/server/node_modules/jiti/lib/types.d.ts +420 -0
- package/.output/server/node_modules/jiti/package.json +146 -0
- package/.output/server/node_modules/remeda/dist/hasProp.js +2 -0
- package/.output/server/node_modules/remeda/dist/index.js +1 -1
- package/.output/server/node_modules/remeda/package.json +12 -12
- package/.output/server/node_modules/ws/lib/sender.js +6 -1
- package/.output/server/node_modules/ws/package.json +1 -1
- package/.output/server/package.json +5 -8
- package/README.md +62 -27
- package/package.json +15 -14
- package/.output/server/node_modules/@rolldown/binding-linux-x64-gnu/package.json +0 -40
- package/.output/server/node_modules/@rolldown/binding-linux-x64-gnu/rolldown-binding.linux-x64-gnu.node +0 -0
- package/.output/server/node_modules/@rolldown/pluginutils/dist/filter/composable-filters.js +0 -256
- package/.output/server/node_modules/@rolldown/pluginutils/dist/filter/filter-vite-plugins.js +0 -75
- package/.output/server/node_modules/@rolldown/pluginutils/dist/filter/index.js +0 -3
- package/.output/server/node_modules/@rolldown/pluginutils/dist/filter/simple-filters.js +0 -70
- package/.output/server/node_modules/@rolldown/pluginutils/dist/index.js +0 -1
- package/.output/server/node_modules/@rolldown/pluginutils/dist/utils.js +0 -17
- package/.output/server/node_modules/@rolldown/pluginutils/package.json +0 -37
- package/.output/server/node_modules/rolldown/dist/index.mjs +0 -50
- package/.output/server/node_modules/rolldown/dist/parse-ast-index.mjs +0 -60
- package/.output/server/node_modules/rolldown/dist/shared/binding-BeU_1iEk.mjs +0 -582
- package/.output/server/node_modules/rolldown/dist/shared/bindingify-input-options-DbbBhzky.mjs +0 -2211
- package/.output/server/node_modules/rolldown/dist/shared/define-config-DJOr6Iwt.mjs +0 -6
- package/.output/server/node_modules/rolldown/dist/shared/error-DL-e8-oE.mjs +0 -85
- package/.output/server/node_modules/rolldown/dist/shared/logs-D80CXhvg.mjs +0 -180
- package/.output/server/node_modules/rolldown/dist/shared/misc-DJYbNKZX.mjs +0 -21
- package/.output/server/node_modules/rolldown/dist/shared/normalize-string-or-regex-CbQQ69gT.mjs +0 -66
- package/.output/server/node_modules/rolldown/dist/shared/parse-B_ZnWxLZ.mjs +0 -74
- package/.output/server/node_modules/rolldown/dist/shared/prompt-U5ajztzG.mjs +0 -847
- package/.output/server/node_modules/rolldown/dist/shared/rolldown-D3JZ9rMt.mjs +0 -40
- package/.output/server/node_modules/rolldown/dist/shared/rolldown-build-DSxL8qiP.mjs +0 -3325
- package/.output/server/node_modules/rolldown/dist/shared/watch-Bd8v9ewv.mjs +0 -374
- package/.output/server/node_modules/rolldown/package.json +0 -153
- package/.output/server/node_modules/unrun/dist/index.mjs +0 -2
- package/.output/server/node_modules/unrun/dist/src-GU5PtktT.mjs +0 -887
- package/.output/server/node_modules/unrun/package.json +0 -125
|
@@ -18,7 +18,7 @@ import { deflateSync } from 'fflate';
|
|
|
18
18
|
import { x } from 'tinyexec';
|
|
19
19
|
import { access, rm, readFile as readFile$1, readdir as readdir$1, mkdir, writeFile as writeFile$1 } from 'node:fs/promises';
|
|
20
20
|
import { styleText } from 'node:util';
|
|
21
|
-
import {
|
|
21
|
+
import { createJiti } from 'jiti';
|
|
22
22
|
import { mergeDeep } from 'remeda';
|
|
23
23
|
import WebSocket from 'ws';
|
|
24
24
|
|
|
@@ -90,26 +90,26 @@ function destr(value, options = {}) {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
const HASH_RE
|
|
94
|
-
const AMPERSAND_RE
|
|
95
|
-
const SLASH_RE
|
|
96
|
-
const EQUAL_RE
|
|
97
|
-
const PLUS_RE
|
|
98
|
-
const ENC_CARET_RE
|
|
99
|
-
const ENC_BACKTICK_RE
|
|
100
|
-
const ENC_PIPE_RE
|
|
101
|
-
const ENC_SPACE_RE
|
|
93
|
+
const HASH_RE = /#/g;
|
|
94
|
+
const AMPERSAND_RE = /&/g;
|
|
95
|
+
const SLASH_RE = /\//g;
|
|
96
|
+
const EQUAL_RE = /=/g;
|
|
97
|
+
const PLUS_RE = /\+/g;
|
|
98
|
+
const ENC_CARET_RE = /%5e/gi;
|
|
99
|
+
const ENC_BACKTICK_RE = /%60/gi;
|
|
100
|
+
const ENC_PIPE_RE = /%7c/gi;
|
|
101
|
+
const ENC_SPACE_RE = /%20/gi;
|
|
102
102
|
const ENC_SLASH_RE = /%2f/gi;
|
|
103
|
-
function encode
|
|
104
|
-
return encodeURI("" + text).replace(ENC_PIPE_RE
|
|
103
|
+
function encode(text) {
|
|
104
|
+
return encodeURI("" + text).replace(ENC_PIPE_RE, "|");
|
|
105
105
|
}
|
|
106
|
-
function encodeQueryValue
|
|
107
|
-
return encode
|
|
106
|
+
function encodeQueryValue(input) {
|
|
107
|
+
return encode(typeof input === "string" ? input : JSON.stringify(input)).replace(PLUS_RE, "%2B").replace(ENC_SPACE_RE, "+").replace(HASH_RE, "%23").replace(AMPERSAND_RE, "%26").replace(ENC_BACKTICK_RE, "`").replace(ENC_CARET_RE, "^").replace(SLASH_RE, "%2F");
|
|
108
108
|
}
|
|
109
|
-
function encodeQueryKey
|
|
110
|
-
return encodeQueryValue
|
|
109
|
+
function encodeQueryKey(text) {
|
|
110
|
+
return encodeQueryValue(text).replace(EQUAL_RE, "%3D");
|
|
111
111
|
}
|
|
112
|
-
function decode
|
|
112
|
+
function decode(text = "") {
|
|
113
113
|
try {
|
|
114
114
|
return decodeURIComponent("" + text);
|
|
115
115
|
} catch {
|
|
@@ -117,16 +117,16 @@ function decode$1(text = "") {
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
function decodePath(text) {
|
|
120
|
-
return decode
|
|
120
|
+
return decode(text.replace(ENC_SLASH_RE, "%252F"));
|
|
121
121
|
}
|
|
122
|
-
function decodeQueryKey
|
|
123
|
-
return decode
|
|
122
|
+
function decodeQueryKey(text) {
|
|
123
|
+
return decode(text.replace(PLUS_RE, " "));
|
|
124
124
|
}
|
|
125
|
-
function decodeQueryValue
|
|
126
|
-
return decode
|
|
125
|
+
function decodeQueryValue(text) {
|
|
126
|
+
return decode(text.replace(PLUS_RE, " "));
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
function parseQuery
|
|
129
|
+
function parseQuery(parametersString = "") {
|
|
130
130
|
const object = /* @__PURE__ */ Object.create(null);
|
|
131
131
|
if (parametersString[0] === "?") {
|
|
132
132
|
parametersString = parametersString.slice(1);
|
|
@@ -136,11 +136,11 @@ function parseQuery$1(parametersString = "") {
|
|
|
136
136
|
if (s.length < 2) {
|
|
137
137
|
continue;
|
|
138
138
|
}
|
|
139
|
-
const key = decodeQueryKey
|
|
139
|
+
const key = decodeQueryKey(s[1]);
|
|
140
140
|
if (key === "__proto__" || key === "constructor") {
|
|
141
141
|
continue;
|
|
142
142
|
}
|
|
143
|
-
const value = decodeQueryValue
|
|
143
|
+
const value = decodeQueryValue(s[2] || "");
|
|
144
144
|
if (object[key] === void 0) {
|
|
145
145
|
object[key] = value;
|
|
146
146
|
} else if (Array.isArray(object[key])) {
|
|
@@ -151,48 +151,48 @@ function parseQuery$1(parametersString = "") {
|
|
|
151
151
|
}
|
|
152
152
|
return object;
|
|
153
153
|
}
|
|
154
|
-
function encodeQueryItem
|
|
154
|
+
function encodeQueryItem(key, value) {
|
|
155
155
|
if (typeof value === "number" || typeof value === "boolean") {
|
|
156
156
|
value = String(value);
|
|
157
157
|
}
|
|
158
158
|
if (!value) {
|
|
159
|
-
return encodeQueryKey
|
|
159
|
+
return encodeQueryKey(key);
|
|
160
160
|
}
|
|
161
161
|
if (Array.isArray(value)) {
|
|
162
162
|
return value.map(
|
|
163
|
-
(_value) => `${encodeQueryKey
|
|
163
|
+
(_value) => `${encodeQueryKey(key)}=${encodeQueryValue(_value)}`
|
|
164
164
|
).join("&");
|
|
165
165
|
}
|
|
166
|
-
return `${encodeQueryKey
|
|
166
|
+
return `${encodeQueryKey(key)}=${encodeQueryValue(value)}`;
|
|
167
167
|
}
|
|
168
|
-
function stringifyQuery
|
|
169
|
-
return Object.keys(query).filter((k) => query[k] !== void 0).map((k) => encodeQueryItem
|
|
168
|
+
function stringifyQuery(query) {
|
|
169
|
+
return Object.keys(query).filter((k) => query[k] !== void 0).map((k) => encodeQueryItem(k, query[k])).filter(Boolean).join("&");
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
const PROTOCOL_STRICT_REGEX
|
|
173
|
-
const PROTOCOL_REGEX
|
|
174
|
-
const PROTOCOL_RELATIVE_REGEX
|
|
175
|
-
const JOIN_LEADING_SLASH_RE
|
|
176
|
-
function hasProtocol
|
|
172
|
+
const PROTOCOL_STRICT_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{1,2})/;
|
|
173
|
+
const PROTOCOL_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{2})?/;
|
|
174
|
+
const PROTOCOL_RELATIVE_REGEX = /^([/\\]\s*){2,}[^/\\]/;
|
|
175
|
+
const JOIN_LEADING_SLASH_RE = /^\.?\//;
|
|
176
|
+
function hasProtocol(inputString, opts = {}) {
|
|
177
177
|
if (typeof opts === "boolean") {
|
|
178
178
|
opts = { acceptRelative: opts };
|
|
179
179
|
}
|
|
180
180
|
if (opts.strict) {
|
|
181
|
-
return PROTOCOL_STRICT_REGEX
|
|
181
|
+
return PROTOCOL_STRICT_REGEX.test(inputString);
|
|
182
182
|
}
|
|
183
|
-
return PROTOCOL_REGEX
|
|
183
|
+
return PROTOCOL_REGEX.test(inputString) || (opts.acceptRelative ? PROTOCOL_RELATIVE_REGEX.test(inputString) : false);
|
|
184
184
|
}
|
|
185
|
-
function hasTrailingSlash
|
|
185
|
+
function hasTrailingSlash(input = "", respectQueryAndFragment) {
|
|
186
186
|
{
|
|
187
187
|
return input.endsWith("/");
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
|
-
function withoutTrailingSlash
|
|
190
|
+
function withoutTrailingSlash(input = "", respectQueryAndFragment) {
|
|
191
191
|
{
|
|
192
|
-
return (hasTrailingSlash
|
|
192
|
+
return (hasTrailingSlash(input) ? input.slice(0, -1) : input) || "/";
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
|
-
function withTrailingSlash
|
|
195
|
+
function withTrailingSlash(input = "", respectQueryAndFragment) {
|
|
196
196
|
{
|
|
197
197
|
return input.endsWith("/") ? input : input + "/";
|
|
198
198
|
}
|
|
@@ -204,36 +204,54 @@ function withLeadingSlash(input = "") {
|
|
|
204
204
|
return hasLeadingSlash(input) ? input : "/" + input;
|
|
205
205
|
}
|
|
206
206
|
function withBase(input, base) {
|
|
207
|
-
if (isEmptyURL
|
|
207
|
+
if (isEmptyURL(base) || hasProtocol(input)) {
|
|
208
208
|
return input;
|
|
209
209
|
}
|
|
210
|
-
const _base = withoutTrailingSlash
|
|
210
|
+
const _base = withoutTrailingSlash(base);
|
|
211
211
|
if (input.startsWith(_base)) {
|
|
212
212
|
const nextChar = input[_base.length];
|
|
213
213
|
if (!nextChar || nextChar === "/" || nextChar === "?") {
|
|
214
214
|
return input;
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
|
-
return joinURL
|
|
217
|
+
return joinURL(_base, input);
|
|
218
|
+
}
|
|
219
|
+
function withoutBase(input, base) {
|
|
220
|
+
if (isEmptyURL(base)) {
|
|
221
|
+
return input;
|
|
222
|
+
}
|
|
223
|
+
const _base = withoutTrailingSlash(base);
|
|
224
|
+
if (!input.startsWith(_base)) {
|
|
225
|
+
return input;
|
|
226
|
+
}
|
|
227
|
+
const nextChar = input[_base.length];
|
|
228
|
+
if (nextChar && nextChar !== "/" && nextChar !== "?") {
|
|
229
|
+
return input;
|
|
230
|
+
}
|
|
231
|
+
const trimmed = input.slice(_base.length).replace(/^\/+/, "");
|
|
232
|
+
return "/" + trimmed;
|
|
218
233
|
}
|
|
219
|
-
function withQuery
|
|
220
|
-
const parsed = parseURL
|
|
221
|
-
const mergedQuery = { ...parseQuery
|
|
222
|
-
parsed.search = stringifyQuery
|
|
223
|
-
return stringifyParsedURL
|
|
234
|
+
function withQuery(input, query) {
|
|
235
|
+
const parsed = parseURL(input);
|
|
236
|
+
const mergedQuery = { ...parseQuery(parsed.search), ...query };
|
|
237
|
+
parsed.search = stringifyQuery(mergedQuery);
|
|
238
|
+
return stringifyParsedURL(parsed);
|
|
239
|
+
}
|
|
240
|
+
function getQuery(input) {
|
|
241
|
+
return parseQuery(parseURL(input).search);
|
|
224
242
|
}
|
|
225
|
-
function isEmptyURL
|
|
243
|
+
function isEmptyURL(url) {
|
|
226
244
|
return !url || url === "/";
|
|
227
245
|
}
|
|
228
|
-
function isNonEmptyURL
|
|
246
|
+
function isNonEmptyURL(url) {
|
|
229
247
|
return url && url !== "/";
|
|
230
248
|
}
|
|
231
|
-
function joinURL
|
|
249
|
+
function joinURL(base, ...input) {
|
|
232
250
|
let url = base || "";
|
|
233
|
-
for (const segment of input.filter((url2) => isNonEmptyURL
|
|
251
|
+
for (const segment of input.filter((url2) => isNonEmptyURL(url2))) {
|
|
234
252
|
if (url) {
|
|
235
|
-
const _segment = segment.replace(JOIN_LEADING_SLASH_RE
|
|
236
|
-
url = withTrailingSlash
|
|
253
|
+
const _segment = segment.replace(JOIN_LEADING_SLASH_RE, "");
|
|
254
|
+
url = withTrailingSlash(url) + _segment;
|
|
237
255
|
} else {
|
|
238
256
|
url = segment;
|
|
239
257
|
}
|
|
@@ -241,8 +259,8 @@ function joinURL$1(base, ...input) {
|
|
|
241
259
|
return url;
|
|
242
260
|
}
|
|
243
261
|
|
|
244
|
-
const protocolRelative
|
|
245
|
-
function parseURL
|
|
262
|
+
const protocolRelative = Symbol.for("ufo:protocolRelative");
|
|
263
|
+
function parseURL(input = "", defaultProto) {
|
|
246
264
|
const _specialProtoMatch = input.match(
|
|
247
265
|
/^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i
|
|
248
266
|
);
|
|
@@ -258,15 +276,15 @@ function parseURL$1(input = "", defaultProto) {
|
|
|
258
276
|
hash: ""
|
|
259
277
|
};
|
|
260
278
|
}
|
|
261
|
-
if (!hasProtocol
|
|
262
|
-
return parsePath
|
|
279
|
+
if (!hasProtocol(input, { acceptRelative: true })) {
|
|
280
|
+
return parsePath(input);
|
|
263
281
|
}
|
|
264
282
|
const [, protocol = "", auth, hostAndPath = ""] = input.replace(/\\/g, "/").match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/) || [];
|
|
265
283
|
let [, host = "", path = ""] = hostAndPath.match(/([^#/?]*)(.*)?/) || [];
|
|
266
284
|
if (protocol === "file:") {
|
|
267
285
|
path = path.replace(/\/(?=[A-Za-z]:)/, "");
|
|
268
286
|
}
|
|
269
|
-
const { pathname, search, hash } = parsePath
|
|
287
|
+
const { pathname, search, hash } = parsePath(path);
|
|
270
288
|
return {
|
|
271
289
|
protocol: protocol.toLowerCase(),
|
|
272
290
|
auth: auth ? auth.slice(0, Math.max(0, auth.length - 1)) : "",
|
|
@@ -274,10 +292,10 @@ function parseURL$1(input = "", defaultProto) {
|
|
|
274
292
|
pathname,
|
|
275
293
|
search,
|
|
276
294
|
hash,
|
|
277
|
-
[protocolRelative
|
|
295
|
+
[protocolRelative]: !protocol
|
|
278
296
|
};
|
|
279
297
|
}
|
|
280
|
-
function parsePath
|
|
298
|
+
function parsePath(input = "") {
|
|
281
299
|
const [pathname = "", search = "", hash = ""] = (input.match(/([^#?]*)(\?[^#]*)?(#.*)?/) || []).splice(1);
|
|
282
300
|
return {
|
|
283
301
|
pathname,
|
|
@@ -285,13 +303,13 @@ function parsePath$1(input = "") {
|
|
|
285
303
|
hash
|
|
286
304
|
};
|
|
287
305
|
}
|
|
288
|
-
function stringifyParsedURL
|
|
306
|
+
function stringifyParsedURL(parsed) {
|
|
289
307
|
const pathname = parsed.pathname || "";
|
|
290
308
|
const search = parsed.search ? (parsed.search.startsWith("?") ? "" : "?") + parsed.search : "";
|
|
291
309
|
const hash = parsed.hash || "";
|
|
292
310
|
const auth = parsed.auth ? parsed.auth + "@" : "";
|
|
293
311
|
const host = parsed.host || "";
|
|
294
|
-
const proto = parsed.protocol || parsed[protocolRelative
|
|
312
|
+
const proto = parsed.protocol || parsed[protocolRelative] ? (parsed.protocol || "") + "//" : "";
|
|
295
313
|
return proto + auth + host + pathname + search + hash;
|
|
296
314
|
}
|
|
297
315
|
|
|
@@ -1591,7 +1609,7 @@ function createResolver(stack) {
|
|
|
1591
1609
|
res = {
|
|
1592
1610
|
...res,
|
|
1593
1611
|
..._res,
|
|
1594
|
-
route: joinURL
|
|
1612
|
+
route: joinURL(res.route || "/", _res.route || "/")
|
|
1595
1613
|
};
|
|
1596
1614
|
}
|
|
1597
1615
|
return res;
|
|
@@ -1609,7 +1627,7 @@ function normalizeLayer(input) {
|
|
|
1609
1627
|
handler = toEventHandler(handler, void 0, input.route);
|
|
1610
1628
|
}
|
|
1611
1629
|
return {
|
|
1612
|
-
route: withoutTrailingSlash
|
|
1630
|
+
route: withoutTrailingSlash(input.route),
|
|
1613
1631
|
match: input.match,
|
|
1614
1632
|
handler
|
|
1615
1633
|
};
|
|
@@ -1676,7 +1694,7 @@ function websocketOptions(evResolver, appOptions) {
|
|
|
1676
1694
|
...appOptions.websocket,
|
|
1677
1695
|
async resolve(info) {
|
|
1678
1696
|
const url = info.request?.url || info.url || "/";
|
|
1679
|
-
const { pathname } = typeof url === "string" ? parseURL
|
|
1697
|
+
const { pathname } = typeof url === "string" ? parseURL(url) : url;
|
|
1680
1698
|
const resolved = await evResolver(pathname);
|
|
1681
1699
|
return resolved?.handler?.__websocket__ || {};
|
|
1682
1700
|
}
|
|
@@ -2268,7 +2286,7 @@ function createFetch(globalOptions = {}) {
|
|
|
2268
2286
|
context.request = withBase(context.request, context.options.baseURL);
|
|
2269
2287
|
}
|
|
2270
2288
|
if (context.options.query) {
|
|
2271
|
-
context.request = withQuery
|
|
2289
|
+
context.request = withQuery(context.request, context.options.query);
|
|
2272
2290
|
delete context.options.query;
|
|
2273
2291
|
}
|
|
2274
2292
|
if ("query" in context.options) {
|
|
@@ -2413,269 +2431,69 @@ const Headers$1 = globalThis.Headers || s$1;
|
|
|
2413
2431
|
const AbortController = globalThis.AbortController || i;
|
|
2414
2432
|
createFetch({ fetch, Headers: Headers$1, AbortController });
|
|
2415
2433
|
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
const ENC_CARET_RE = /%5e/gi;
|
|
2422
|
-
const ENC_BACKTICK_RE = /%60/gi;
|
|
2423
|
-
const ENC_PIPE_RE = /%7c/gi;
|
|
2424
|
-
const ENC_SPACE_RE = /%20/gi;
|
|
2425
|
-
function encode(text) {
|
|
2426
|
-
return encodeURI("" + text).replace(ENC_PIPE_RE, "|");
|
|
2427
|
-
}
|
|
2428
|
-
function encodeQueryValue(input) {
|
|
2429
|
-
return encode(typeof input === "string" ? input : JSON.stringify(input)).replace(PLUS_RE, "%2B").replace(ENC_SPACE_RE, "+").replace(HASH_RE, "%23").replace(AMPERSAND_RE, "%26").replace(ENC_BACKTICK_RE, "`").replace(ENC_CARET_RE, "^").replace(SLASH_RE, "%2F");
|
|
2430
|
-
}
|
|
2431
|
-
function encodeQueryKey(text) {
|
|
2432
|
-
return encodeQueryValue(text).replace(EQUAL_RE, "%3D");
|
|
2434
|
+
function wrapToPromise(value) {
|
|
2435
|
+
if (!value || typeof value.then !== "function") {
|
|
2436
|
+
return Promise.resolve(value);
|
|
2437
|
+
}
|
|
2438
|
+
return value;
|
|
2433
2439
|
}
|
|
2434
|
-
function
|
|
2440
|
+
function asyncCall(function_, ...arguments_) {
|
|
2435
2441
|
try {
|
|
2436
|
-
return
|
|
2437
|
-
} catch {
|
|
2438
|
-
return
|
|
2442
|
+
return wrapToPromise(function_(...arguments_));
|
|
2443
|
+
} catch (error) {
|
|
2444
|
+
return Promise.reject(error);
|
|
2439
2445
|
}
|
|
2440
2446
|
}
|
|
2441
|
-
function
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
function decodeQueryValue(text) {
|
|
2445
|
-
return decode(text.replace(PLUS_RE, " "));
|
|
2447
|
+
function isPrimitive(value) {
|
|
2448
|
+
const type = typeof value;
|
|
2449
|
+
return value === null || type !== "object" && type !== "function";
|
|
2446
2450
|
}
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
if (parametersString[0] === "?") {
|
|
2451
|
-
parametersString = parametersString.slice(1);
|
|
2452
|
-
}
|
|
2453
|
-
for (const parameter of parametersString.split("&")) {
|
|
2454
|
-
const s = parameter.match(/([^=]+)=?(.*)/) || [];
|
|
2455
|
-
if (s.length < 2) {
|
|
2456
|
-
continue;
|
|
2457
|
-
}
|
|
2458
|
-
const key = decodeQueryKey(s[1]);
|
|
2459
|
-
if (key === "__proto__" || key === "constructor") {
|
|
2460
|
-
continue;
|
|
2461
|
-
}
|
|
2462
|
-
const value = decodeQueryValue(s[2] || "");
|
|
2463
|
-
if (object[key] === void 0) {
|
|
2464
|
-
object[key] = value;
|
|
2465
|
-
} else if (Array.isArray(object[key])) {
|
|
2466
|
-
object[key].push(value);
|
|
2467
|
-
} else {
|
|
2468
|
-
object[key] = [object[key], value];
|
|
2469
|
-
}
|
|
2470
|
-
}
|
|
2471
|
-
return object;
|
|
2451
|
+
function isPureObject(value) {
|
|
2452
|
+
const proto = Object.getPrototypeOf(value);
|
|
2453
|
+
return !proto || proto.isPrototypeOf(Object);
|
|
2472
2454
|
}
|
|
2473
|
-
function
|
|
2474
|
-
if (
|
|
2475
|
-
|
|
2476
|
-
}
|
|
2477
|
-
if (!value) {
|
|
2478
|
-
return encodeQueryKey(key);
|
|
2479
|
-
}
|
|
2480
|
-
if (Array.isArray(value)) {
|
|
2481
|
-
return value.map(
|
|
2482
|
-
(_value) => `${encodeQueryKey(key)}=${encodeQueryValue(_value)}`
|
|
2483
|
-
).join("&");
|
|
2455
|
+
function stringify(value) {
|
|
2456
|
+
if (isPrimitive(value)) {
|
|
2457
|
+
return String(value);
|
|
2484
2458
|
}
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
function stringifyQuery(query) {
|
|
2488
|
-
return Object.keys(query).filter((k) => query[k] !== void 0).map((k) => encodeQueryItem(k, query[k])).filter(Boolean).join("&");
|
|
2489
|
-
}
|
|
2490
|
-
|
|
2491
|
-
const PROTOCOL_STRICT_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{1,2})/;
|
|
2492
|
-
const PROTOCOL_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{2})?/;
|
|
2493
|
-
const PROTOCOL_RELATIVE_REGEX = /^([/\\]\s*){2,}[^/\\]/;
|
|
2494
|
-
const JOIN_LEADING_SLASH_RE = /^\.?\//;
|
|
2495
|
-
function hasProtocol(inputString, opts = {}) {
|
|
2496
|
-
if (typeof opts === "boolean") {
|
|
2497
|
-
opts = { acceptRelative: opts };
|
|
2459
|
+
if (isPureObject(value) || Array.isArray(value)) {
|
|
2460
|
+
return JSON.stringify(value);
|
|
2498
2461
|
}
|
|
2499
|
-
if (
|
|
2500
|
-
return
|
|
2462
|
+
if (typeof value.toJSON === "function") {
|
|
2463
|
+
return stringify(value.toJSON());
|
|
2501
2464
|
}
|
|
2502
|
-
|
|
2465
|
+
throw new Error("[unstorage] Cannot stringify value!");
|
|
2503
2466
|
}
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2467
|
+
const BASE64_PREFIX = "base64:";
|
|
2468
|
+
function serializeRaw(value) {
|
|
2469
|
+
if (typeof value === "string") {
|
|
2470
|
+
return value;
|
|
2507
2471
|
}
|
|
2472
|
+
return BASE64_PREFIX + base64Encode(value);
|
|
2508
2473
|
}
|
|
2509
|
-
function
|
|
2510
|
-
{
|
|
2511
|
-
return
|
|
2474
|
+
function deserializeRaw(value) {
|
|
2475
|
+
if (typeof value !== "string") {
|
|
2476
|
+
return value;
|
|
2512
2477
|
}
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
{
|
|
2516
|
-
return input.endsWith("/") ? input : input + "/";
|
|
2478
|
+
if (!value.startsWith(BASE64_PREFIX)) {
|
|
2479
|
+
return value;
|
|
2517
2480
|
}
|
|
2481
|
+
return base64Decode(value.slice(BASE64_PREFIX.length));
|
|
2518
2482
|
}
|
|
2519
|
-
function
|
|
2520
|
-
if (
|
|
2521
|
-
return input;
|
|
2522
|
-
}
|
|
2523
|
-
const _base = withoutTrailingSlash(base);
|
|
2524
|
-
if (!input.startsWith(_base)) {
|
|
2525
|
-
return input;
|
|
2526
|
-
}
|
|
2527
|
-
const nextChar = input[_base.length];
|
|
2528
|
-
if (nextChar && nextChar !== "/" && nextChar !== "?") {
|
|
2529
|
-
return input;
|
|
2483
|
+
function base64Decode(input) {
|
|
2484
|
+
if (globalThis.Buffer) {
|
|
2485
|
+
return Buffer.from(input, "base64");
|
|
2530
2486
|
}
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
const parsed = parseURL(input);
|
|
2536
|
-
const mergedQuery = { ...parseQuery(parsed.search), ...query };
|
|
2537
|
-
parsed.search = stringifyQuery(mergedQuery);
|
|
2538
|
-
return stringifyParsedURL(parsed);
|
|
2539
|
-
}
|
|
2540
|
-
function getQuery(input) {
|
|
2541
|
-
return parseQuery(parseURL(input).search);
|
|
2542
|
-
}
|
|
2543
|
-
function isEmptyURL(url) {
|
|
2544
|
-
return !url || url === "/";
|
|
2545
|
-
}
|
|
2546
|
-
function isNonEmptyURL(url) {
|
|
2547
|
-
return url && url !== "/";
|
|
2487
|
+
return Uint8Array.from(
|
|
2488
|
+
globalThis.atob(input),
|
|
2489
|
+
(c) => c.codePointAt(0)
|
|
2490
|
+
);
|
|
2548
2491
|
}
|
|
2549
|
-
function
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
if (url) {
|
|
2553
|
-
const _segment = segment.replace(JOIN_LEADING_SLASH_RE, "");
|
|
2554
|
-
url = withTrailingSlash(url) + _segment;
|
|
2555
|
-
} else {
|
|
2556
|
-
url = segment;
|
|
2557
|
-
}
|
|
2492
|
+
function base64Encode(input) {
|
|
2493
|
+
if (globalThis.Buffer) {
|
|
2494
|
+
return Buffer.from(input).toString("base64");
|
|
2558
2495
|
}
|
|
2559
|
-
return
|
|
2560
|
-
}
|
|
2561
|
-
|
|
2562
|
-
const protocolRelative = Symbol.for("ufo:protocolRelative");
|
|
2563
|
-
function parseURL(input = "", defaultProto) {
|
|
2564
|
-
const _specialProtoMatch = input.match(
|
|
2565
|
-
/^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i
|
|
2566
|
-
);
|
|
2567
|
-
if (_specialProtoMatch) {
|
|
2568
|
-
const [, _proto, _pathname = ""] = _specialProtoMatch;
|
|
2569
|
-
return {
|
|
2570
|
-
protocol: _proto.toLowerCase(),
|
|
2571
|
-
pathname: _pathname,
|
|
2572
|
-
href: _proto + _pathname,
|
|
2573
|
-
auth: "",
|
|
2574
|
-
host: "",
|
|
2575
|
-
search: "",
|
|
2576
|
-
hash: ""
|
|
2577
|
-
};
|
|
2578
|
-
}
|
|
2579
|
-
if (!hasProtocol(input, { acceptRelative: true })) {
|
|
2580
|
-
return defaultProto ? parseURL(defaultProto + input) : parsePath(input);
|
|
2581
|
-
}
|
|
2582
|
-
const [, protocol = "", auth, hostAndPath = ""] = input.replace(/\\/g, "/").match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/) || [];
|
|
2583
|
-
let [, host = "", path = ""] = hostAndPath.match(/([^#/?]*)(.*)?/) || [];
|
|
2584
|
-
if (protocol === "file:") {
|
|
2585
|
-
path = path.replace(/\/(?=[A-Za-z]:)/, "");
|
|
2586
|
-
}
|
|
2587
|
-
const { pathname, search, hash } = parsePath(path);
|
|
2588
|
-
return {
|
|
2589
|
-
protocol: protocol.toLowerCase(),
|
|
2590
|
-
auth: auth ? auth.slice(0, Math.max(0, auth.length - 1)) : "",
|
|
2591
|
-
host,
|
|
2592
|
-
pathname,
|
|
2593
|
-
search,
|
|
2594
|
-
hash,
|
|
2595
|
-
[protocolRelative]: !protocol
|
|
2596
|
-
};
|
|
2597
|
-
}
|
|
2598
|
-
function parsePath(input = "") {
|
|
2599
|
-
const [pathname = "", search = "", hash = ""] = (input.match(/([^#?]*)(\?[^#]*)?(#.*)?/) || []).splice(1);
|
|
2600
|
-
return {
|
|
2601
|
-
pathname,
|
|
2602
|
-
search,
|
|
2603
|
-
hash
|
|
2604
|
-
};
|
|
2605
|
-
}
|
|
2606
|
-
function stringifyParsedURL(parsed) {
|
|
2607
|
-
const pathname = parsed.pathname || "";
|
|
2608
|
-
const search = parsed.search ? (parsed.search.startsWith("?") ? "" : "?") + parsed.search : "";
|
|
2609
|
-
const hash = parsed.hash || "";
|
|
2610
|
-
const auth = parsed.auth ? parsed.auth + "@" : "";
|
|
2611
|
-
const host = parsed.host || "";
|
|
2612
|
-
const proto = parsed.protocol || parsed[protocolRelative] ? (parsed.protocol || "") + "//" : "";
|
|
2613
|
-
return proto + auth + host + pathname + search + hash;
|
|
2614
|
-
}
|
|
2615
|
-
|
|
2616
|
-
function wrapToPromise(value) {
|
|
2617
|
-
if (!value || typeof value.then !== "function") {
|
|
2618
|
-
return Promise.resolve(value);
|
|
2619
|
-
}
|
|
2620
|
-
return value;
|
|
2621
|
-
}
|
|
2622
|
-
function asyncCall(function_, ...arguments_) {
|
|
2623
|
-
try {
|
|
2624
|
-
return wrapToPromise(function_(...arguments_));
|
|
2625
|
-
} catch (error) {
|
|
2626
|
-
return Promise.reject(error);
|
|
2627
|
-
}
|
|
2628
|
-
}
|
|
2629
|
-
function isPrimitive(value) {
|
|
2630
|
-
const type = typeof value;
|
|
2631
|
-
return value === null || type !== "object" && type !== "function";
|
|
2632
|
-
}
|
|
2633
|
-
function isPureObject(value) {
|
|
2634
|
-
const proto = Object.getPrototypeOf(value);
|
|
2635
|
-
return !proto || proto.isPrototypeOf(Object);
|
|
2636
|
-
}
|
|
2637
|
-
function stringify(value) {
|
|
2638
|
-
if (isPrimitive(value)) {
|
|
2639
|
-
return String(value);
|
|
2640
|
-
}
|
|
2641
|
-
if (isPureObject(value) || Array.isArray(value)) {
|
|
2642
|
-
return JSON.stringify(value);
|
|
2643
|
-
}
|
|
2644
|
-
if (typeof value.toJSON === "function") {
|
|
2645
|
-
return stringify(value.toJSON());
|
|
2646
|
-
}
|
|
2647
|
-
throw new Error("[unstorage] Cannot stringify value!");
|
|
2648
|
-
}
|
|
2649
|
-
const BASE64_PREFIX = "base64:";
|
|
2650
|
-
function serializeRaw(value) {
|
|
2651
|
-
if (typeof value === "string") {
|
|
2652
|
-
return value;
|
|
2653
|
-
}
|
|
2654
|
-
return BASE64_PREFIX + base64Encode(value);
|
|
2655
|
-
}
|
|
2656
|
-
function deserializeRaw(value) {
|
|
2657
|
-
if (typeof value !== "string") {
|
|
2658
|
-
return value;
|
|
2659
|
-
}
|
|
2660
|
-
if (!value.startsWith(BASE64_PREFIX)) {
|
|
2661
|
-
return value;
|
|
2662
|
-
}
|
|
2663
|
-
return base64Decode(value.slice(BASE64_PREFIX.length));
|
|
2664
|
-
}
|
|
2665
|
-
function base64Decode(input) {
|
|
2666
|
-
if (globalThis.Buffer) {
|
|
2667
|
-
return Buffer.from(input, "base64");
|
|
2668
|
-
}
|
|
2669
|
-
return Uint8Array.from(
|
|
2670
|
-
globalThis.atob(input),
|
|
2671
|
-
(c) => c.codePointAt(0)
|
|
2672
|
-
);
|
|
2673
|
-
}
|
|
2674
|
-
function base64Encode(input) {
|
|
2675
|
-
if (globalThis.Buffer) {
|
|
2676
|
-
return Buffer.from(input).toString("base64");
|
|
2677
|
-
}
|
|
2678
|
-
return globalThis.btoa(String.fromCodePoint(...input));
|
|
2496
|
+
return globalThis.btoa(String.fromCodePoint(...input));
|
|
2679
2497
|
}
|
|
2680
2498
|
|
|
2681
2499
|
const storageKeyProperties = [
|
|
@@ -4608,12 +4426,17 @@ function sendToBetterStack(level, tag, message, ctx) {
|
|
|
4608
4426
|
const fullMessage = message !== void 0 ? `[${tag}] ${message}` : tag;
|
|
4609
4427
|
const context = toBetterStackContext(ctx);
|
|
4610
4428
|
if (level === "error") {
|
|
4611
|
-
client.error(fullMessage, context).then(() => client.flush())
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
}
|
|
4615
|
-
|
|
4429
|
+
client.error(fullMessage, context).then(() => client.flush()).catch(() => {
|
|
4430
|
+
});
|
|
4431
|
+
return;
|
|
4432
|
+
}
|
|
4433
|
+
if (level === "warn") {
|
|
4434
|
+
client.warn(fullMessage, context).then(() => client.flush()).catch(() => {
|
|
4435
|
+
});
|
|
4436
|
+
return;
|
|
4616
4437
|
}
|
|
4438
|
+
client.info(fullMessage, context).then(() => client.flush()).catch(() => {
|
|
4439
|
+
});
|
|
4617
4440
|
} catch (_e) {
|
|
4618
4441
|
}
|
|
4619
4442
|
}
|
|
@@ -4887,15 +4710,17 @@ async function disconnect({ sessionId, token, studioUrl }) {
|
|
|
4887
4710
|
}
|
|
4888
4711
|
}
|
|
4889
4712
|
|
|
4890
|
-
var __defProp$2 = Object.defineProperty;
|
|
4891
|
-
var __name = (target, value) => __defProp$2(target, "name", {
|
|
4892
|
-
value,
|
|
4893
|
-
configurable: true
|
|
4894
|
-
});
|
|
4895
|
-
|
|
4896
4713
|
const visitorDepths = {
|
|
4897
4714
|
deep: "deep"
|
|
4898
4715
|
};
|
|
4716
|
+
function memoize$1(store, factory) {
|
|
4717
|
+
return (key) => {
|
|
4718
|
+
if (store.has(key)) return store.get(key);
|
|
4719
|
+
const value = factory(key);
|
|
4720
|
+
store.set(key, value);
|
|
4721
|
+
return value;
|
|
4722
|
+
};
|
|
4723
|
+
}
|
|
4899
4724
|
function trimExtName(text) {
|
|
4900
4725
|
const dotIndex = text.lastIndexOf(".");
|
|
4901
4726
|
if (dotIndex > 0 && !text.includes("/", dotIndex)) return text.slice(0, dotIndex);
|
|
@@ -4910,235 +4735,136 @@ function extractRefName(ref) {
|
|
|
4910
4735
|
var _a;
|
|
4911
4736
|
return (_a = ref.split("/").at(-1)) != null ? _a : ref;
|
|
4912
4737
|
}
|
|
4913
|
-
function
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
queue.shift()();
|
|
4920
|
-
}
|
|
4738
|
+
function* getChildren(node, recurse) {
|
|
4739
|
+
var _a;
|
|
4740
|
+
if (node.kind === "Input") {
|
|
4741
|
+
yield* node.schemas;
|
|
4742
|
+
yield* node.operations;
|
|
4743
|
+
return;
|
|
4921
4744
|
}
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
next();
|
|
4928
|
-
});
|
|
4929
|
-
});
|
|
4930
|
-
next();
|
|
4931
|
-
});
|
|
4932
|
-
};
|
|
4933
|
-
}
|
|
4934
|
-
function getChildren(node, recurse) {
|
|
4935
|
-
var _a, _b, _c;
|
|
4936
|
-
switch (node.kind) {
|
|
4937
|
-
case "Input":
|
|
4938
|
-
return [...node.schemas, ...node.operations];
|
|
4939
|
-
case "Output":
|
|
4940
|
-
return [];
|
|
4941
|
-
case "Operation":
|
|
4942
|
-
return [
|
|
4943
|
-
...node.parameters,
|
|
4944
|
-
...(_c = (_b = (_a = node.requestBody) == null ? void 0 : _a.content) == null ? void 0 : _b.flatMap((c) => c.schema ? [c.schema] : [])) != null ? _c : [],
|
|
4945
|
-
...node.responses
|
|
4946
|
-
];
|
|
4947
|
-
case "Schema": {
|
|
4948
|
-
const children = [];
|
|
4949
|
-
if (!recurse) return [];
|
|
4950
|
-
if ("properties" in node && node.properties.length > 0) children.push(...node.properties);
|
|
4951
|
-
if ("items" in node && node.items) children.push(...node.items);
|
|
4952
|
-
if ("members" in node && node.members) children.push(...node.members);
|
|
4953
|
-
if ("additionalProperties" in node && node.additionalProperties && node.additionalProperties !== true) children.push(node.additionalProperties);
|
|
4954
|
-
return children;
|
|
4745
|
+
if (node.kind === "Output") return;
|
|
4746
|
+
if (node.kind === "Operation") {
|
|
4747
|
+
yield* node.parameters;
|
|
4748
|
+
if ((_a = node.requestBody) == null ? void 0 : _a.content) {
|
|
4749
|
+
for (const c of node.requestBody.content) if (c.schema) yield c.schema;
|
|
4955
4750
|
}
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
case "Parameter":
|
|
4959
|
-
return [node.schema];
|
|
4960
|
-
case "Response":
|
|
4961
|
-
return node.schema ? [node.schema] : [];
|
|
4962
|
-
case "FunctionParameter":
|
|
4963
|
-
case "ParameterGroup":
|
|
4964
|
-
case "FunctionParameters":
|
|
4965
|
-
case "Type":
|
|
4966
|
-
return [];
|
|
4967
|
-
default:
|
|
4968
|
-
return [];
|
|
4751
|
+
yield* node.responses;
|
|
4752
|
+
return;
|
|
4969
4753
|
}
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
case "Operation":
|
|
4990
|
-
await limit(() => {
|
|
4991
|
-
var _a;
|
|
4992
|
-
return (_a = visitor.operation) == null ? void 0 : _a.call(visitor, node, { parent });
|
|
4993
|
-
});
|
|
4994
|
-
break;
|
|
4995
|
-
case "Schema":
|
|
4996
|
-
await limit(() => {
|
|
4997
|
-
var _a;
|
|
4998
|
-
return (_a = visitor.schema) == null ? void 0 : _a.call(visitor, node, { parent });
|
|
4999
|
-
});
|
|
5000
|
-
break;
|
|
5001
|
-
case "Property":
|
|
5002
|
-
await limit(() => {
|
|
5003
|
-
var _a;
|
|
5004
|
-
return (_a = visitor.property) == null ? void 0 : _a.call(visitor, node, { parent });
|
|
5005
|
-
});
|
|
5006
|
-
break;
|
|
5007
|
-
case "Parameter":
|
|
5008
|
-
await limit(() => {
|
|
5009
|
-
var _a;
|
|
5010
|
-
return (_a = visitor.parameter) == null ? void 0 : _a.call(visitor, node, { parent });
|
|
5011
|
-
});
|
|
5012
|
-
break;
|
|
5013
|
-
case "Response":
|
|
5014
|
-
await limit(() => {
|
|
5015
|
-
var _a;
|
|
5016
|
-
return (_a = visitor.response) == null ? void 0 : _a.call(visitor, node, { parent });
|
|
5017
|
-
});
|
|
5018
|
-
break;
|
|
4754
|
+
if (node.kind === "Schema") {
|
|
4755
|
+
if (!recurse) return;
|
|
4756
|
+
if ("properties" in node && node.properties.length > 0) yield* node.properties;
|
|
4757
|
+
if ("items" in node && node.items) yield* node.items;
|
|
4758
|
+
if ("members" in node && node.members) yield* node.members;
|
|
4759
|
+
if ("additionalProperties" in node && node.additionalProperties && node.additionalProperties !== true) yield node.additionalProperties;
|
|
4760
|
+
return;
|
|
4761
|
+
}
|
|
4762
|
+
if (node.kind === "Property") {
|
|
4763
|
+
yield node.schema;
|
|
4764
|
+
return;
|
|
4765
|
+
}
|
|
4766
|
+
if (node.kind === "Parameter") {
|
|
4767
|
+
yield node.schema;
|
|
4768
|
+
return;
|
|
4769
|
+
}
|
|
4770
|
+
if (node.kind === "Response") {
|
|
4771
|
+
if (node.schema) yield node.schema;
|
|
4772
|
+
return;
|
|
5019
4773
|
}
|
|
5020
|
-
const children = getChildren(node, recurse);
|
|
5021
|
-
for (const child of children) await _walk(child, visitor, recurse, limit, node);
|
|
5022
4774
|
}
|
|
5023
4775
|
function transform(node, options) {
|
|
5024
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
4776
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
5025
4777
|
const { depth, parent, ...visitor } = options;
|
|
5026
4778
|
const recurse = (depth != null ? depth : visitorDepths.deep) === visitorDepths.deep;
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
}
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
|
|
5048
|
-
|
|
5049
|
-
|
|
5050
|
-
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
parent: op
|
|
5059
|
-
})),
|
|
5060
|
-
requestBody: op.requestBody ? {
|
|
5061
|
-
...op.requestBody,
|
|
5062
|
-
content: (_d = op.requestBody.content) == null ? void 0 : _d.map((c) => ({
|
|
5063
|
-
...c,
|
|
5064
|
-
schema: c.schema ? transform(c.schema, {
|
|
5065
|
-
...options,
|
|
5066
|
-
parent: op
|
|
5067
|
-
}) : void 0
|
|
5068
|
-
}))
|
|
5069
|
-
} : void 0,
|
|
5070
|
-
responses: op.responses.map((r) => transform(r, {
|
|
5071
|
-
...options,
|
|
5072
|
-
parent: op
|
|
4779
|
+
if (node.kind === "Input") {
|
|
4780
|
+
const input = (_b = (_a = visitor.input) == null ? void 0 : _a.call(visitor, node, { parent })) != null ? _b : node;
|
|
4781
|
+
return {
|
|
4782
|
+
...input,
|
|
4783
|
+
schemas: input.schemas.map((s) => transform(s, {
|
|
4784
|
+
...options,
|
|
4785
|
+
parent: input
|
|
4786
|
+
})),
|
|
4787
|
+
operations: input.operations.map((op) => transform(op, {
|
|
4788
|
+
...options,
|
|
4789
|
+
parent: input
|
|
4790
|
+
}))
|
|
4791
|
+
};
|
|
4792
|
+
}
|
|
4793
|
+
if (node.kind === "Output") return (_d = (_c = visitor.output) == null ? void 0 : _c.call(visitor, node, { parent })) != null ? _d : node;
|
|
4794
|
+
if (node.kind === "Operation") {
|
|
4795
|
+
const op = (_f = (_e = visitor.operation) == null ? void 0 : _e.call(visitor, node, { parent })) != null ? _f : node;
|
|
4796
|
+
return {
|
|
4797
|
+
...op,
|
|
4798
|
+
parameters: op.parameters.map((p) => transform(p, {
|
|
4799
|
+
...options,
|
|
4800
|
+
parent: op
|
|
4801
|
+
})),
|
|
4802
|
+
requestBody: op.requestBody ? {
|
|
4803
|
+
...op.requestBody,
|
|
4804
|
+
content: (_g = op.requestBody.content) == null ? void 0 : _g.map((c) => ({
|
|
4805
|
+
...c,
|
|
4806
|
+
schema: c.schema ? transform(c.schema, {
|
|
4807
|
+
...options,
|
|
4808
|
+
parent: op
|
|
4809
|
+
}) : void 0
|
|
5073
4810
|
}))
|
|
5074
|
-
}
|
|
5075
|
-
|
|
5076
|
-
case "Schema": {
|
|
5077
|
-
let schema = node;
|
|
5078
|
-
const replaced = (_e = visitor.schema) == null ? void 0 : _e.call(visitor, schema, { parent });
|
|
5079
|
-
if (replaced) schema = replaced;
|
|
5080
|
-
const childOptions = {
|
|
4811
|
+
} : void 0,
|
|
4812
|
+
responses: op.responses.map((r) => transform(r, {
|
|
5081
4813
|
...options,
|
|
5082
|
-
parent:
|
|
5083
|
-
}
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
|
|
5090
|
-
|
|
5091
|
-
}
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
|
|
5108
|
-
|
|
5109
|
-
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
|
|
5119
|
-
if (replaced) response = replaced;
|
|
5120
|
-
return {
|
|
5121
|
-
...response,
|
|
5122
|
-
schema: transform(response.schema, {
|
|
5123
|
-
...options,
|
|
5124
|
-
parent: response
|
|
5125
|
-
})
|
|
5126
|
-
};
|
|
5127
|
-
}
|
|
5128
|
-
case "FunctionParameter":
|
|
5129
|
-
case "ParameterGroup":
|
|
5130
|
-
case "FunctionParameters":
|
|
5131
|
-
case "Type":
|
|
5132
|
-
return node;
|
|
5133
|
-
default:
|
|
5134
|
-
return node;
|
|
4814
|
+
parent: op
|
|
4815
|
+
}))
|
|
4816
|
+
};
|
|
4817
|
+
}
|
|
4818
|
+
if (node.kind === "Schema") {
|
|
4819
|
+
const schema = (_i = (_h = visitor.schema) == null ? void 0 : _h.call(visitor, node, { parent })) != null ? _i : node;
|
|
4820
|
+
const childOptions = {
|
|
4821
|
+
...options,
|
|
4822
|
+
parent: schema
|
|
4823
|
+
};
|
|
4824
|
+
return {
|
|
4825
|
+
...schema,
|
|
4826
|
+
..."properties" in schema && recurse ? { properties: schema.properties.map((p) => transform(p, childOptions)) } : {},
|
|
4827
|
+
..."items" in schema && recurse ? { items: (_j = schema.items) == null ? void 0 : _j.map((i) => transform(i, childOptions)) } : {},
|
|
4828
|
+
..."members" in schema && recurse ? { members: (_k = schema.members) == null ? void 0 : _k.map((m) => transform(m, childOptions)) } : {},
|
|
4829
|
+
..."additionalProperties" in schema && recurse && schema.additionalProperties && schema.additionalProperties !== true ? { additionalProperties: transform(schema.additionalProperties, childOptions) } : {}
|
|
4830
|
+
};
|
|
4831
|
+
}
|
|
4832
|
+
if (node.kind === "Property") {
|
|
4833
|
+
const prop = (_m = (_l = visitor.property) == null ? void 0 : _l.call(visitor, node, { parent })) != null ? _m : node;
|
|
4834
|
+
return createProperty({
|
|
4835
|
+
...prop,
|
|
4836
|
+
schema: transform(prop.schema, {
|
|
4837
|
+
...options,
|
|
4838
|
+
parent: prop
|
|
4839
|
+
})
|
|
4840
|
+
});
|
|
4841
|
+
}
|
|
4842
|
+
if (node.kind === "Parameter") {
|
|
4843
|
+
const param = (_o = (_n = visitor.parameter) == null ? void 0 : _n.call(visitor, node, { parent })) != null ? _o : node;
|
|
4844
|
+
return createParameter({
|
|
4845
|
+
...param,
|
|
4846
|
+
schema: transform(param.schema, {
|
|
4847
|
+
...options,
|
|
4848
|
+
parent: param
|
|
4849
|
+
})
|
|
4850
|
+
});
|
|
5135
4851
|
}
|
|
4852
|
+
if (node.kind === "Response") {
|
|
4853
|
+
const response = (_q = (_p = visitor.response) == null ? void 0 : _p.call(visitor, node, { parent })) != null ? _q : node;
|
|
4854
|
+
return {
|
|
4855
|
+
...response,
|
|
4856
|
+
schema: transform(response.schema, {
|
|
4857
|
+
...options,
|
|
4858
|
+
parent: response
|
|
4859
|
+
})
|
|
4860
|
+
};
|
|
4861
|
+
}
|
|
4862
|
+
return node;
|
|
5136
4863
|
}
|
|
5137
|
-
function
|
|
4864
|
+
function* collectLazy(node, options) {
|
|
5138
4865
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
5139
4866
|
const { depth, parent, ...visitor } = options;
|
|
5140
4867
|
const recurse = (depth != null ? depth : visitorDepths.deep) === visitorDepths.deep;
|
|
5141
|
-
const results = [];
|
|
5142
4868
|
let v;
|
|
5143
4869
|
switch (node.kind) {
|
|
5144
4870
|
case "Input":
|
|
@@ -5163,12 +4889,14 @@ function collect(node, options) {
|
|
|
5163
4889
|
v = (_g = visitor.response) == null ? void 0 : _g.call(visitor, node, { parent });
|
|
5164
4890
|
break;
|
|
5165
4891
|
}
|
|
5166
|
-
if (v !== void 0)
|
|
5167
|
-
for (const child of getChildren(node, recurse))
|
|
4892
|
+
if (v !== void 0) yield v;
|
|
4893
|
+
for (const child of getChildren(node, recurse)) yield* collectLazy(child, {
|
|
5168
4894
|
...options,
|
|
5169
4895
|
parent: node
|
|
5170
|
-
})
|
|
5171
|
-
|
|
4896
|
+
});
|
|
4897
|
+
}
|
|
4898
|
+
function collect(node, options) {
|
|
4899
|
+
return Array.from(collectLazy(node, options));
|
|
5172
4900
|
}
|
|
5173
4901
|
function sourceKey(source) {
|
|
5174
4902
|
var _a, _b, _c;
|
|
@@ -5199,11 +4927,11 @@ function combineSources(sources) {
|
|
|
5199
4927
|
}
|
|
5200
4928
|
return [...seen.values()];
|
|
5201
4929
|
}
|
|
5202
|
-
function combineExports(exports
|
|
4930
|
+
function combineExports(exports) {
|
|
5203
4931
|
const result = [];
|
|
5204
4932
|
const namedByPath = /* @__PURE__ */ new Map();
|
|
5205
4933
|
const seen = /* @__PURE__ */ new Set();
|
|
5206
|
-
const keyed = exports
|
|
4934
|
+
const keyed = exports.map((node) => ({
|
|
5207
4935
|
node,
|
|
5208
4936
|
key: sortKey(node)
|
|
5209
4937
|
}));
|
|
@@ -5236,9 +4964,17 @@ function combineExports(exports$1) {
|
|
|
5236
4964
|
}
|
|
5237
4965
|
return result;
|
|
5238
4966
|
}
|
|
5239
|
-
function combineImports(imports, exports
|
|
5240
|
-
const exportedNames = new Set(exports
|
|
4967
|
+
function combineImports(imports, exports, source) {
|
|
4968
|
+
const exportedNames = new Set(exports.flatMap((e) => Array.isArray(e.name) ? e.name : e.name ? [e.name] : []));
|
|
5241
4969
|
const isUsed = (importName) => !source || source.includes(importName) || exportedNames.has(importName);
|
|
4970
|
+
const importNameMemo = /* @__PURE__ */ new Map();
|
|
4971
|
+
const canonicalizeName = (n) => {
|
|
4972
|
+
var _a;
|
|
4973
|
+
if (typeof n === "string") return n;
|
|
4974
|
+
const key = `${n.propertyName}:${(_a = n.name) != null ? _a : ""}`;
|
|
4975
|
+
if (!importNameMemo.has(key)) importNameMemo.set(key, n);
|
|
4976
|
+
return importNameMemo.get(key);
|
|
4977
|
+
};
|
|
5242
4978
|
const result = [];
|
|
5243
4979
|
const namedByPath = /* @__PURE__ */ new Map();
|
|
5244
4980
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -5252,7 +4988,7 @@ function combineImports(imports, exports$1, source) {
|
|
|
5252
4988
|
const { path: path2, isTypeOnly } = curr;
|
|
5253
4989
|
let { name } = curr;
|
|
5254
4990
|
if (Array.isArray(name)) {
|
|
5255
|
-
name = [...new Set(name)].filter((item) => {
|
|
4991
|
+
name = [...new Set(name.map(canonicalizeName))].filter((item) => {
|
|
5256
4992
|
var _a;
|
|
5257
4993
|
return typeof item === "string" ? isUsed(item) : isUsed((_a = item.name) != null ? _a : item.propertyName);
|
|
5258
4994
|
});
|
|
@@ -5305,17 +5041,23 @@ function resolveRefName(node) {
|
|
|
5305
5041
|
if (node.ref) return (_d = (_c = (_a = extractRefName(node.ref)) != null ? _a : node.name) != null ? _c : (_b = node.schema) == null ? void 0 : _b.name) != null ? _d : void 0;
|
|
5306
5042
|
return (_g = (_f = node.name) != null ? _f : (_e = node.schema) == null ? void 0 : _e.name) != null ? _g : void 0;
|
|
5307
5043
|
}
|
|
5308
|
-
|
|
5309
|
-
|
|
5044
|
+
const collectSchemaRefs = memoize$1(/* @__PURE__ */ new WeakMap(), (node) => {
|
|
5045
|
+
const refs = /* @__PURE__ */ new Set();
|
|
5310
5046
|
collect(node, { schema(child) {
|
|
5311
5047
|
if (child.type === "ref") {
|
|
5312
5048
|
const name = resolveRefName(child);
|
|
5313
|
-
if (name)
|
|
5049
|
+
if (name) refs.add(name);
|
|
5314
5050
|
}
|
|
5315
5051
|
} });
|
|
5052
|
+
return refs;
|
|
5053
|
+
});
|
|
5054
|
+
function collectReferencedSchemaNames(node, out = /* @__PURE__ */ new Set()) {
|
|
5055
|
+
if (!node) return out;
|
|
5056
|
+
for (const name of collectSchemaRefs(node)) out.add(name);
|
|
5316
5057
|
return out;
|
|
5317
5058
|
}
|
|
5318
|
-
|
|
5059
|
+
const collectUsedSchemaNamesMemo = memoize$1(/* @__PURE__ */ new WeakMap(), (ops) => memoize$1(/* @__PURE__ */ new WeakMap(), (schemas) => computeUsedSchemaNames(ops, schemas)));
|
|
5060
|
+
function computeUsedSchemaNames(operations, schemas) {
|
|
5319
5061
|
const schemaMap = /* @__PURE__ */ new Map();
|
|
5320
5062
|
for (const schema of schemas) if (schema.name) schemaMap.set(schema.name, schema);
|
|
5321
5063
|
const result = /* @__PURE__ */ new Set();
|
|
@@ -5327,12 +5069,15 @@ function collectUsedSchemaNames(operations, schemas) {
|
|
|
5327
5069
|
if (namedSchema) visitSchema(namedSchema);
|
|
5328
5070
|
}
|
|
5329
5071
|
}
|
|
5330
|
-
for (const op of operations) for (const schema of
|
|
5072
|
+
for (const op of operations) for (const schema of collectLazy(op, {
|
|
5331
5073
|
depth: "shallow",
|
|
5332
5074
|
schema: (node) => node
|
|
5333
5075
|
})) visitSchema(schema);
|
|
5334
5076
|
return result;
|
|
5335
5077
|
}
|
|
5078
|
+
function collectUsedSchemaNames(operations, schemas) {
|
|
5079
|
+
return collectUsedSchemaNamesMemo(operations)(schemas);
|
|
5080
|
+
}
|
|
5336
5081
|
function syncOptionality(schema, required) {
|
|
5337
5082
|
var _a;
|
|
5338
5083
|
const nullable = (_a = schema.nullable) != null ? _a : false;
|
|
@@ -5342,6 +5087,14 @@ function syncOptionality(schema, required) {
|
|
|
5342
5087
|
nullish: !required && nullable ? true : void 0
|
|
5343
5088
|
};
|
|
5344
5089
|
}
|
|
5090
|
+
function createStreamInput(schemas, operations, meta) {
|
|
5091
|
+
return {
|
|
5092
|
+
kind: "Input",
|
|
5093
|
+
schemas,
|
|
5094
|
+
operations,
|
|
5095
|
+
meta
|
|
5096
|
+
};
|
|
5097
|
+
}
|
|
5345
5098
|
function createProperty(props) {
|
|
5346
5099
|
var _a;
|
|
5347
5100
|
const required = (_a = props.required) != null ? _a : false;
|
|
@@ -5395,9 +5148,9 @@ var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !==
|
|
|
5395
5148
|
var __accessCheck$1 = (obj, member, msg) => member.has(obj) || __typeError$1("Cannot " + msg);
|
|
5396
5149
|
var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
5397
5150
|
var __privateAdd$1 = (obj, member, value) => member.has(obj) ? __typeError$1("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
5398
|
-
var __privateSet
|
|
5151
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
|
|
5399
5152
|
var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
|
|
5400
|
-
var _cache, _filesCache, _FileManager_instances, store_fn,
|
|
5153
|
+
var _options, _URLPath_instances, transformParam_fn, eachParam_fn, _a$1, _cache, _filesCache, _FileManager_instances, store_fn, _b, _studio, _middlewareListeners, _eventGeneratorPlugins, _resolvers, _defaultResolvers, _hookListeners, _KubbDriver_instances, normalizePlugin_fn, registerAdapter_fn, registerMiddleware_fn, registerPlugin_fn, trackHookListener_fn, _getDefaultResolver, _c;
|
|
5401
5154
|
function toCamelOrPascal(text, pascal) {
|
|
5402
5155
|
return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
|
|
5403
5156
|
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
@@ -5423,53 +5176,314 @@ function pascalCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
|
5423
5176
|
}) : camelCase(part));
|
|
5424
5177
|
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
|
|
5425
5178
|
}
|
|
5426
|
-
|
|
5427
|
-
|
|
5428
|
-
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
if (
|
|
5432
|
-
|
|
5433
|
-
|
|
5434
|
-
|
|
5435
|
-
|
|
5179
|
+
function* chunks(arr, size) {
|
|
5180
|
+
for (let i = 0; i < arr.length; i += size) yield arr.slice(i, i + size);
|
|
5181
|
+
}
|
|
5182
|
+
async function forBatches(source, process2, options) {
|
|
5183
|
+
const { concurrency, flush } = options;
|
|
5184
|
+
if (Array.isArray(source)) {
|
|
5185
|
+
for (const batch2 of chunks(source, concurrency)) {
|
|
5186
|
+
await process2(batch2);
|
|
5187
|
+
if (flush) await flush();
|
|
5188
|
+
}
|
|
5189
|
+
return;
|
|
5190
|
+
}
|
|
5191
|
+
const batch = [];
|
|
5192
|
+
for await (const item of source) {
|
|
5193
|
+
batch.push(item);
|
|
5194
|
+
if (batch.length >= concurrency) {
|
|
5195
|
+
await process2(batch.splice(0));
|
|
5196
|
+
if (flush) await flush();
|
|
5197
|
+
}
|
|
5198
|
+
}
|
|
5199
|
+
if (batch.length > 0) {
|
|
5200
|
+
await process2(batch.splice(0));
|
|
5201
|
+
if (flush) await flush();
|
|
5202
|
+
}
|
|
5203
|
+
}
|
|
5204
|
+
async function withDrain(work, flush) {
|
|
5205
|
+
await work(flush);
|
|
5206
|
+
await flush();
|
|
5207
|
+
}
|
|
5208
|
+
function isPromise(result) {
|
|
5209
|
+
return result !== null && result !== void 0 && typeof result["then"] === "function";
|
|
5210
|
+
}
|
|
5211
|
+
function memoize(store, factory) {
|
|
5212
|
+
return (key) => {
|
|
5213
|
+
if (store.has(key)) return store.get(key);
|
|
5214
|
+
const value = factory(key);
|
|
5215
|
+
store.set(key, value);
|
|
5216
|
+
return value;
|
|
5217
|
+
};
|
|
5218
|
+
}
|
|
5219
|
+
function arrayToAsyncIterable(arr) {
|
|
5220
|
+
return { [Symbol.asyncIterator]() {
|
|
5221
|
+
return (async function* () {
|
|
5222
|
+
yield* arr;
|
|
5223
|
+
})();
|
|
5224
|
+
} };
|
|
5225
|
+
}
|
|
5226
|
+
const reservedWords = /* @__PURE__ */ new Set([
|
|
5227
|
+
"abstract",
|
|
5228
|
+
"arguments",
|
|
5229
|
+
"boolean",
|
|
5230
|
+
"break",
|
|
5231
|
+
"byte",
|
|
5232
|
+
"case",
|
|
5233
|
+
"catch",
|
|
5234
|
+
"char",
|
|
5235
|
+
"class",
|
|
5236
|
+
"const",
|
|
5237
|
+
"continue",
|
|
5238
|
+
"debugger",
|
|
5239
|
+
"default",
|
|
5240
|
+
"delete",
|
|
5241
|
+
"do",
|
|
5242
|
+
"double",
|
|
5243
|
+
"else",
|
|
5244
|
+
"enum",
|
|
5245
|
+
"eval",
|
|
5246
|
+
"export",
|
|
5247
|
+
"extends",
|
|
5248
|
+
"false",
|
|
5249
|
+
"final",
|
|
5250
|
+
"finally",
|
|
5251
|
+
"float",
|
|
5252
|
+
"for",
|
|
5253
|
+
"function",
|
|
5254
|
+
"goto",
|
|
5255
|
+
"if",
|
|
5256
|
+
"implements",
|
|
5257
|
+
"import",
|
|
5258
|
+
"in",
|
|
5259
|
+
"instanceof",
|
|
5260
|
+
"int",
|
|
5261
|
+
"interface",
|
|
5262
|
+
"let",
|
|
5263
|
+
"long",
|
|
5264
|
+
"native",
|
|
5265
|
+
"new",
|
|
5266
|
+
"null",
|
|
5267
|
+
"package",
|
|
5268
|
+
"private",
|
|
5269
|
+
"protected",
|
|
5270
|
+
"public",
|
|
5271
|
+
"return",
|
|
5272
|
+
"short",
|
|
5273
|
+
"static",
|
|
5274
|
+
"super",
|
|
5275
|
+
"switch",
|
|
5276
|
+
"synchronized",
|
|
5277
|
+
"this",
|
|
5278
|
+
"throw",
|
|
5279
|
+
"throws",
|
|
5280
|
+
"transient",
|
|
5281
|
+
"true",
|
|
5282
|
+
"try",
|
|
5283
|
+
"typeof",
|
|
5284
|
+
"var",
|
|
5285
|
+
"void",
|
|
5286
|
+
"volatile",
|
|
5287
|
+
"while",
|
|
5288
|
+
"with",
|
|
5289
|
+
"yield",
|
|
5290
|
+
"Array",
|
|
5291
|
+
"Date",
|
|
5292
|
+
"hasOwnProperty",
|
|
5293
|
+
"Infinity",
|
|
5294
|
+
"isFinite",
|
|
5295
|
+
"isNaN",
|
|
5296
|
+
"isPrototypeOf",
|
|
5297
|
+
"length",
|
|
5298
|
+
"Math",
|
|
5299
|
+
"name",
|
|
5300
|
+
"NaN",
|
|
5301
|
+
"Number",
|
|
5302
|
+
"Object",
|
|
5303
|
+
"prototype",
|
|
5304
|
+
"String",
|
|
5305
|
+
"toString",
|
|
5306
|
+
"undefined",
|
|
5307
|
+
"valueOf"
|
|
5308
|
+
]);
|
|
5309
|
+
function isValidVarName(name) {
|
|
5310
|
+
if (!name || reservedWords.has(name)) return false;
|
|
5311
|
+
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
5312
|
+
}
|
|
5313
|
+
var URLPath = (_a$1 = class {
|
|
5314
|
+
constructor(path2, options = {}) {
|
|
5315
|
+
__privateAdd$1(this, _URLPath_instances);
|
|
5316
|
+
/**
|
|
5317
|
+
* The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`.
|
|
5318
|
+
*/
|
|
5319
|
+
__publicField$1(this, "path");
|
|
5320
|
+
__privateAdd$1(this, _options);
|
|
5321
|
+
this.path = path2;
|
|
5322
|
+
__privateSet(this, _options, options);
|
|
5323
|
+
}
|
|
5324
|
+
/** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`.
|
|
5325
|
+
*
|
|
5326
|
+
* @example
|
|
5327
|
+
* ```ts
|
|
5328
|
+
* new URLPath('/pet/{petId}').URL // '/pet/:petId'
|
|
5329
|
+
* ```
|
|
5330
|
+
*/
|
|
5331
|
+
get URL() {
|
|
5332
|
+
return this.toURLPath();
|
|
5333
|
+
}
|
|
5334
|
+
/** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`).
|
|
5335
|
+
*
|
|
5336
|
+
* @example
|
|
5337
|
+
* ```ts
|
|
5338
|
+
* new URLPath('https://petstore.swagger.io/v2/pet').isURL // true
|
|
5339
|
+
* new URLPath('/pet/{petId}').isURL // false
|
|
5340
|
+
* ```
|
|
5341
|
+
*/
|
|
5342
|
+
get isURL() {
|
|
5343
|
+
try {
|
|
5344
|
+
return !!new URL(this.path).href;
|
|
5345
|
+
} catch {
|
|
5346
|
+
return false;
|
|
5347
|
+
}
|
|
5348
|
+
}
|
|
5349
|
+
/**
|
|
5350
|
+
* Converts the OpenAPI path to a TypeScript template literal string.
|
|
5351
|
+
*
|
|
5352
|
+
* @example
|
|
5353
|
+
* new URLPath('/pet/{petId}').template // '`/pet/${petId}`'
|
|
5354
|
+
* new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
|
|
5355
|
+
*/
|
|
5356
|
+
get template() {
|
|
5357
|
+
return this.toTemplateString();
|
|
5358
|
+
}
|
|
5359
|
+
/** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set.
|
|
5360
|
+
*
|
|
5361
|
+
* @example
|
|
5362
|
+
* ```ts
|
|
5363
|
+
* new URLPath('/pet/{petId}').object
|
|
5364
|
+
* // { url: '/pet/:petId', params: { petId: 'petId' } }
|
|
5365
|
+
* ```
|
|
5366
|
+
*/
|
|
5367
|
+
get object() {
|
|
5368
|
+
return this.toObject();
|
|
5369
|
+
}
|
|
5370
|
+
/** Returns a map of path parameter names, or `undefined` when the path has no parameters.
|
|
5371
|
+
*
|
|
5372
|
+
* @example
|
|
5373
|
+
* ```ts
|
|
5374
|
+
* new URLPath('/pet/{petId}').params // { petId: 'petId' }
|
|
5375
|
+
* new URLPath('/pet').params // undefined
|
|
5376
|
+
* ```
|
|
5377
|
+
*/
|
|
5378
|
+
get params() {
|
|
5379
|
+
return this.getParams();
|
|
5380
|
+
}
|
|
5381
|
+
toObject({ type = "path", replacer, stringify } = {}) {
|
|
5382
|
+
const object = {
|
|
5383
|
+
url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
|
|
5384
|
+
params: this.getParams()
|
|
5385
|
+
};
|
|
5386
|
+
if (stringify) {
|
|
5387
|
+
if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
5388
|
+
if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
|
|
5389
|
+
return `{ url: '${object.url}' }`;
|
|
5390
|
+
}
|
|
5391
|
+
return object;
|
|
5392
|
+
}
|
|
5393
|
+
/**
|
|
5394
|
+
* Converts the OpenAPI path to a TypeScript template literal string.
|
|
5395
|
+
* An optional `replacer` can transform each extracted parameter name before interpolation.
|
|
5396
|
+
*
|
|
5397
|
+
* @example
|
|
5398
|
+
* new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
|
|
5399
|
+
*/
|
|
5400
|
+
toTemplateString({ prefix = "", replacer } = {}) {
|
|
5401
|
+
return `\`${prefix}${this.path.split(/\{([^}]+)\}/).map((part, i) => {
|
|
5402
|
+
if (i % 2 === 0) return part;
|
|
5403
|
+
const param = __privateMethod$1(this, _URLPath_instances, transformParam_fn).call(this, part);
|
|
5404
|
+
return `\${${replacer ? replacer(param) : param}}`;
|
|
5405
|
+
}).join("")}\``;
|
|
5406
|
+
}
|
|
5407
|
+
/**
|
|
5408
|
+
* Extracts all `{param}` segments from the path and returns them as a key-value map.
|
|
5409
|
+
* An optional `replacer` transforms each parameter name in both key and value positions.
|
|
5410
|
+
* Returns `undefined` when no path parameters are found.
|
|
5411
|
+
*
|
|
5412
|
+
* @example
|
|
5413
|
+
* ```ts
|
|
5414
|
+
* new URLPath('/pet/{petId}/tag/{tagId}').getParams()
|
|
5415
|
+
* // { petId: 'petId', tagId: 'tagId' }
|
|
5416
|
+
* ```
|
|
5417
|
+
*/
|
|
5418
|
+
getParams(replacer) {
|
|
5419
|
+
const params = {};
|
|
5420
|
+
__privateMethod$1(this, _URLPath_instances, eachParam_fn).call(this, (_raw, param) => {
|
|
5421
|
+
const key = replacer ? replacer(param) : param;
|
|
5422
|
+
params[key] = key;
|
|
5423
|
+
});
|
|
5424
|
+
return Object.keys(params).length > 0 ? params : void 0;
|
|
5425
|
+
}
|
|
5426
|
+
/** Converts the OpenAPI path to Express-style colon syntax.
|
|
5427
|
+
*
|
|
5428
|
+
* @example
|
|
5429
|
+
* ```ts
|
|
5430
|
+
* new URLPath('/pet/{petId}').toURLPath() // '/pet/:petId'
|
|
5431
|
+
* ```
|
|
5432
|
+
*/
|
|
5433
|
+
toURLPath() {
|
|
5434
|
+
return this.path.replace(/\{([^}]+)\}/g, ":$1");
|
|
5435
|
+
}
|
|
5436
|
+
}, _options = new WeakMap(), _URLPath_instances = new WeakSet(), transformParam_fn = function(raw) {
|
|
5437
|
+
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
5438
|
+
return __privateGet$1(this, _options).casing === "camelcase" ? camelCase(param) : param;
|
|
5439
|
+
}, /**
|
|
5440
|
+
* Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name.
|
|
5441
|
+
*/
|
|
5442
|
+
eachParam_fn = function(fn) {
|
|
5443
|
+
for (const match of this.path.matchAll(/\{([^}]+)\}/g)) {
|
|
5444
|
+
const raw = match[1];
|
|
5445
|
+
fn(raw, __privateMethod$1(this, _URLPath_instances, transformParam_fn).call(this, raw));
|
|
5446
|
+
}
|
|
5447
|
+
}, _a$1);
|
|
5448
|
+
const DEFAULT_STUDIO_URL = "https://kubb.studio";
|
|
5449
|
+
const DEFAULT_BANNER = "simple";
|
|
5450
|
+
const DEFAULT_EXTENSION = { ".ts": ".ts" };
|
|
5451
|
+
function getMode(fileOrFolder) {
|
|
5452
|
+
if (!fileOrFolder) return "split";
|
|
5453
|
+
return extname(fileOrFolder) ? "single" : "split";
|
|
5454
|
+
}
|
|
5455
|
+
const stringPatternCache = /* @__PURE__ */ new Map();
|
|
5456
|
+
function testPattern(value, pattern) {
|
|
5457
|
+
if (typeof pattern === "string") {
|
|
5458
|
+
let regex = stringPatternCache.get(pattern);
|
|
5459
|
+
if (!regex) {
|
|
5460
|
+
regex = new RegExp(pattern);
|
|
5461
|
+
stringPatternCache.set(pattern, regex);
|
|
5436
5462
|
}
|
|
5437
5463
|
return regex.test(value);
|
|
5438
5464
|
}
|
|
5439
5465
|
return value.match(pattern) !== null;
|
|
5440
5466
|
}
|
|
5441
5467
|
function matchesOperationPattern(node, type, pattern) {
|
|
5442
|
-
var _a2, _b2,
|
|
5443
|
-
|
|
5444
|
-
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
|
|
5448
|
-
|
|
5449
|
-
return testPattern(node.path, pattern);
|
|
5450
|
-
case "method":
|
|
5451
|
-
return testPattern(node.method.toLowerCase(), pattern);
|
|
5452
|
-
case "contentType":
|
|
5453
|
-
return (_c = (_b2 = (_a2 = node.requestBody) == null ? void 0 : _a2.content) == null ? void 0 : _b2.some((c) => testPattern(c.contentType, pattern))) != null ? _c : false;
|
|
5454
|
-
default:
|
|
5455
|
-
return false;
|
|
5456
|
-
}
|
|
5468
|
+
var _a2, _b2, _c2;
|
|
5469
|
+
if (type === "tag") return node.tags.some((tag) => testPattern(tag, pattern));
|
|
5470
|
+
if (type === "operationId") return testPattern(node.operationId, pattern);
|
|
5471
|
+
if (type === "path") return testPattern(node.path, pattern);
|
|
5472
|
+
if (type === "method") return testPattern(node.method.toLowerCase(), pattern);
|
|
5473
|
+
if (type === "contentType") return (_c2 = (_b2 = (_a2 = node.requestBody) == null ? void 0 : _a2.content) == null ? void 0 : _b2.some((c) => testPattern(c.contentType, pattern))) != null ? _c2 : false;
|
|
5474
|
+
return false;
|
|
5457
5475
|
}
|
|
5458
5476
|
function matchesSchemaPattern(node, type, pattern) {
|
|
5459
|
-
|
|
5460
|
-
|
|
5461
|
-
return node.name ? testPattern(node.name, pattern) : false;
|
|
5462
|
-
default:
|
|
5463
|
-
return null;
|
|
5464
|
-
}
|
|
5477
|
+
if (type === "schemaName") return node.name ? testPattern(node.name, pattern) : false;
|
|
5478
|
+
return null;
|
|
5465
5479
|
}
|
|
5466
5480
|
function defaultResolver(name, type) {
|
|
5467
|
-
|
|
5468
|
-
if (type === "
|
|
5469
|
-
|
|
5470
|
-
return resolvedName;
|
|
5481
|
+
if (type === "file" || type === "function") return camelCase(name, { isFile: type === "file" });
|
|
5482
|
+
if (type === "type") return pascalCase(name);
|
|
5483
|
+
return camelCase(name);
|
|
5471
5484
|
}
|
|
5472
|
-
|
|
5485
|
+
const resolveOptionsCache = /* @__PURE__ */ new WeakMap();
|
|
5486
|
+
function computeOptions(node, options, exclude, include, override) {
|
|
5473
5487
|
var _a2, _b2;
|
|
5474
5488
|
if (isOperationNode(node)) {
|
|
5475
5489
|
if (exclude.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) return null;
|
|
@@ -5494,28 +5508,43 @@ function defaultResolveOptions(node, { options, exclude = [], include, override
|
|
|
5494
5508
|
}
|
|
5495
5509
|
return options;
|
|
5496
5510
|
}
|
|
5511
|
+
function defaultResolveOptions(node, { options, exclude = [], include, override = [] }) {
|
|
5512
|
+
const optionsKey = options;
|
|
5513
|
+
let byOptions = resolveOptionsCache.get(optionsKey);
|
|
5514
|
+
if (!byOptions) {
|
|
5515
|
+
byOptions = /* @__PURE__ */ new WeakMap();
|
|
5516
|
+
resolveOptionsCache.set(optionsKey, byOptions);
|
|
5517
|
+
}
|
|
5518
|
+
const cached = byOptions.get(node);
|
|
5519
|
+
if (cached !== void 0) return cached.value;
|
|
5520
|
+
const result = computeOptions(node, options, exclude, include, override);
|
|
5521
|
+
byOptions.set(node, { value: result });
|
|
5522
|
+
return result;
|
|
5523
|
+
}
|
|
5497
5524
|
function defaultResolvePath({ baseName, pathMode, tag, path: groupPath }, { root, output, group }) {
|
|
5498
|
-
|
|
5499
|
-
|
|
5500
|
-
|
|
5501
|
-
|
|
5502
|
-
|
|
5503
|
-
|
|
5504
|
-
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5508
|
-
|
|
5509
|
-
|
|
5525
|
+
if ((pathMode != null ? pathMode : getMode(path$1.resolve(root, output.path))) === "single") return path$1.resolve(root, output.path);
|
|
5526
|
+
const result = (() => {
|
|
5527
|
+
var _a2;
|
|
5528
|
+
if (group && (groupPath || tag)) {
|
|
5529
|
+
const groupValue = group.type === "path" ? groupPath : tag;
|
|
5530
|
+
const defaultName = group.type === "tag" ? ({ group: g }) => `${camelCase(g)}Controller` : ({ group: g }) => {
|
|
5531
|
+
const segment = g.split("/").filter((s) => s !== "" && s !== "." && s !== "..")[0];
|
|
5532
|
+
return segment ? camelCase(segment) : "";
|
|
5533
|
+
};
|
|
5534
|
+
const resolveName = (_a2 = group.name) != null ? _a2 : defaultName;
|
|
5535
|
+
return path$1.resolve(root, output.path, resolveName({ group: groupValue }), baseName);
|
|
5536
|
+
}
|
|
5537
|
+
return path$1.resolve(root, output.path, baseName);
|
|
5538
|
+
})();
|
|
5510
5539
|
const outputDir = path$1.resolve(root, output.path);
|
|
5511
5540
|
const outputDirWithSep = outputDir.endsWith(path$1.sep) ? outputDir : `${outputDir}${path$1.sep}`;
|
|
5512
5541
|
if (result !== outputDir && !result.startsWith(outputDirWithSep)) throw new Error(`[Kubb] Resolved path "${result}" is outside the output directory "${outputDir}". This may indicate a path traversal attempt in the OpenAPI specification or a misconfigured group.name function.`);
|
|
5513
5542
|
return result;
|
|
5514
5543
|
}
|
|
5515
|
-
function defaultResolveFile({ name, extname: extname2, tag, path: groupPath }, context
|
|
5516
|
-
const pathMode =
|
|
5517
|
-
const baseName = `${pathMode === "single" ? "" :
|
|
5518
|
-
const filePath =
|
|
5544
|
+
function defaultResolveFile({ name, extname: extname2, tag, path: groupPath }, context) {
|
|
5545
|
+
const pathMode = getMode(path$1.resolve(context.root, context.output.path));
|
|
5546
|
+
const baseName = `${pathMode === "single" ? "" : this.default(name, "file")}${extname2}`;
|
|
5547
|
+
const filePath = this.resolvePath({
|
|
5519
5548
|
baseName,
|
|
5520
5549
|
pathMode,
|
|
5521
5550
|
tag,
|
|
@@ -5524,7 +5553,7 @@ function defaultResolveFile({ name, extname: extname2, tag, path: groupPath }, c
|
|
|
5524
5553
|
return createFile({
|
|
5525
5554
|
path: filePath,
|
|
5526
5555
|
baseName: path$1.basename(filePath),
|
|
5527
|
-
meta: { pluginName:
|
|
5556
|
+
meta: { pluginName: this.pluginName },
|
|
5528
5557
|
sources: [],
|
|
5529
5558
|
imports: [],
|
|
5530
5559
|
exports: []
|
|
@@ -5532,12 +5561,16 @@ function defaultResolveFile({ name, extname: extname2, tag, path: groupPath }, c
|
|
|
5532
5561
|
}
|
|
5533
5562
|
function buildDefaultBanner({ title, description, version, config }) {
|
|
5534
5563
|
try {
|
|
5535
|
-
|
|
5536
|
-
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
|
|
5564
|
+
const source = (() => {
|
|
5565
|
+
if (Array.isArray(config.input)) {
|
|
5566
|
+
const first = config.input[0];
|
|
5567
|
+
if (first && "path" in first) return path$1.basename(first.path);
|
|
5568
|
+
return "";
|
|
5569
|
+
}
|
|
5570
|
+
if (config.input && "path" in config.input) return path$1.basename(config.input.path);
|
|
5571
|
+
if (config.input && "data" in config.input) return "text content";
|
|
5572
|
+
return "";
|
|
5573
|
+
})();
|
|
5541
5574
|
let banner = "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n";
|
|
5542
5575
|
if (config.output.defaultBanner === "simple") {
|
|
5543
5576
|
banner += "*/\n";
|
|
@@ -5560,32 +5593,31 @@ function buildDefaultBanner({ title, description, version, config }) {
|
|
|
5560
5593
|
return "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n*/";
|
|
5561
5594
|
}
|
|
5562
5595
|
}
|
|
5563
|
-
function defaultResolveBanner(
|
|
5564
|
-
|
|
5565
|
-
if (typeof (output == null ? void 0 : output.banner) === "function") return output.banner(node);
|
|
5596
|
+
function defaultResolveBanner(meta, { output, config }) {
|
|
5597
|
+
if (typeof (output == null ? void 0 : output.banner) === "function") return output.banner(meta);
|
|
5566
5598
|
if (typeof (output == null ? void 0 : output.banner) === "string") return output.banner;
|
|
5567
5599
|
if (config.output.defaultBanner === false) return;
|
|
5568
5600
|
return buildDefaultBanner({
|
|
5569
|
-
title:
|
|
5570
|
-
version:
|
|
5601
|
+
title: meta == null ? void 0 : meta.title,
|
|
5602
|
+
version: meta == null ? void 0 : meta.version,
|
|
5571
5603
|
config
|
|
5572
5604
|
});
|
|
5573
5605
|
}
|
|
5574
|
-
function defaultResolveFooter(
|
|
5575
|
-
if (typeof (output == null ? void 0 : output.footer) === "function") return
|
|
5606
|
+
function defaultResolveFooter(meta, { output }) {
|
|
5607
|
+
if (typeof (output == null ? void 0 : output.footer) === "function") return output.footer(meta);
|
|
5576
5608
|
if (typeof (output == null ? void 0 : output.footer) === "string") return output.footer;
|
|
5577
5609
|
}
|
|
5578
5610
|
function defineResolver(build) {
|
|
5579
|
-
|
|
5580
|
-
|
|
5611
|
+
let resolver;
|
|
5612
|
+
resolver = {
|
|
5581
5613
|
default: defaultResolver,
|
|
5582
5614
|
resolveOptions: defaultResolveOptions,
|
|
5583
5615
|
resolvePath: defaultResolvePath,
|
|
5584
|
-
resolveFile: (params, context) => defaultResolveFile(params, context
|
|
5616
|
+
resolveFile: (params, context) => defaultResolveFile.call(resolver, params, context),
|
|
5585
5617
|
resolveBanner: defaultResolveBanner,
|
|
5586
5618
|
resolveFooter: defaultResolveFooter,
|
|
5587
|
-
...build(
|
|
5588
|
-
}
|
|
5619
|
+
...build()
|
|
5620
|
+
};
|
|
5589
5621
|
return resolver;
|
|
5590
5622
|
}
|
|
5591
5623
|
function encodeAst(input) {
|
|
@@ -5630,7 +5662,7 @@ function mergeFilesByPath(files) {
|
|
|
5630
5662
|
}
|
|
5631
5663
|
return merged;
|
|
5632
5664
|
}
|
|
5633
|
-
var FileManager = (
|
|
5665
|
+
var FileManager = (_b = class {
|
|
5634
5666
|
constructor() {
|
|
5635
5667
|
__privateAdd$1(this, _FileManager_instances);
|
|
5636
5668
|
__privateAdd$1(this, _cache, /* @__PURE__ */ new Map());
|
|
@@ -5658,18 +5690,28 @@ var FileManager = (_a$1 = class {
|
|
|
5658
5690
|
}
|
|
5659
5691
|
deleteByPath(path2) {
|
|
5660
5692
|
__privateGet$1(this, _cache).delete(path2);
|
|
5661
|
-
__privateSet
|
|
5693
|
+
__privateSet(this, _filesCache, null);
|
|
5662
5694
|
}
|
|
5663
5695
|
clear() {
|
|
5664
5696
|
__privateGet$1(this, _cache).clear();
|
|
5665
|
-
__privateSet
|
|
5697
|
+
__privateSet(this, _filesCache, null);
|
|
5666
5698
|
}
|
|
5667
5699
|
/**
|
|
5668
|
-
*
|
|
5700
|
+
* Releases all stored files. Called by the core after `kubb:build:end` to
|
|
5701
|
+
* free the per-plugin FileNode caches for the rest of the process lifetime.
|
|
5702
|
+
*/
|
|
5703
|
+
dispose() {
|
|
5704
|
+
this.clear();
|
|
5705
|
+
}
|
|
5706
|
+
[Symbol.dispose]() {
|
|
5707
|
+
this.dispose();
|
|
5708
|
+
}
|
|
5709
|
+
/**
|
|
5710
|
+
* All stored files, sorted by path length (shorter paths first).
|
|
5669
5711
|
*/
|
|
5670
5712
|
get files() {
|
|
5671
5713
|
if (__privateGet$1(this, _filesCache)) return __privateGet$1(this, _filesCache);
|
|
5672
|
-
__privateSet
|
|
5714
|
+
__privateSet(this, _filesCache, [...__privateGet$1(this, _cache).values()].sort((a, b) => {
|
|
5673
5715
|
const lenDiff = a.path.length - b.path.length;
|
|
5674
5716
|
if (lenDiff !== 0) return lenDiff;
|
|
5675
5717
|
const aIsIndex = a.path.endsWith("/index.ts") || a.path === "index.ts";
|
|
@@ -5688,36 +5730,38 @@ var FileManager = (_a$1 = class {
|
|
|
5688
5730
|
__privateGet$1(this, _cache).set(resolvedFile.path, resolvedFile);
|
|
5689
5731
|
resolvedFiles.push(resolvedFile);
|
|
5690
5732
|
}
|
|
5691
|
-
__privateSet
|
|
5733
|
+
__privateSet(this, _filesCache, null);
|
|
5692
5734
|
return resolvedFiles;
|
|
5693
|
-
},
|
|
5694
|
-
async function applyHookResult(result, driver, rendererFactory) {
|
|
5695
|
-
if (!result) return;
|
|
5696
|
-
if (Array.isArray(result)) {
|
|
5697
|
-
driver.fileManager.upsert(...result);
|
|
5698
|
-
return;
|
|
5699
|
-
}
|
|
5700
|
-
if (!rendererFactory) return;
|
|
5701
|
-
const renderer = rendererFactory();
|
|
5702
|
-
await renderer.render(result);
|
|
5703
|
-
driver.fileManager.upsert(...renderer.files);
|
|
5704
|
-
renderer.unmount();
|
|
5705
|
-
}
|
|
5735
|
+
}, _b);
|
|
5706
5736
|
function enforceOrder(enforce) {
|
|
5707
5737
|
return enforce === "pre" ? -1 : enforce === "post" ? 1 : 0;
|
|
5708
5738
|
}
|
|
5709
|
-
var
|
|
5739
|
+
var KubbDriver = (_c = class {
|
|
5710
5740
|
constructor(config, options) {
|
|
5711
|
-
__privateAdd$1(this,
|
|
5741
|
+
__privateAdd$1(this, _KubbDriver_instances);
|
|
5712
5742
|
__publicField$1(this, "config");
|
|
5713
5743
|
__publicField$1(this, "options");
|
|
5714
5744
|
/**
|
|
5715
|
-
* The
|
|
5716
|
-
*
|
|
5745
|
+
* The streaming `InputStreamNode` produced by the adapter.
|
|
5746
|
+
* Always set after adapter setup — parse-only adapters are wrapped automatically.
|
|
5717
5747
|
*/
|
|
5718
5748
|
__publicField$1(this, "inputNode");
|
|
5719
5749
|
__publicField$1(this, "adapter");
|
|
5720
|
-
|
|
5750
|
+
/**
|
|
5751
|
+
* Studio session state, kept together so `dispose()` can reset it atomically.
|
|
5752
|
+
*
|
|
5753
|
+
* - `source` holds the raw adapter source so `adapter.parse()` can be called lazily.
|
|
5754
|
+
* Intentionally outlives the build; cleared by `dispose()`.
|
|
5755
|
+
* - `isOpen` prevents opening the studio more than once per build.
|
|
5756
|
+
* - `inputNode` caches the parse promise so `adapter.parse()` is called at most once
|
|
5757
|
+
* per studio session, even when `openInStudio()` is called multiple times.
|
|
5758
|
+
*/
|
|
5759
|
+
__privateAdd$1(this, _studio, {
|
|
5760
|
+
source: void 0,
|
|
5761
|
+
isOpen: false,
|
|
5762
|
+
inputNode: void 0
|
|
5763
|
+
});
|
|
5764
|
+
__privateAdd$1(this, _middlewareListeners, []);
|
|
5721
5765
|
/**
|
|
5722
5766
|
* Central file store for all generated files.
|
|
5723
5767
|
* Plugins should use `this.addFile()` / `this.upsertFile()` (via their context) to
|
|
@@ -5729,97 +5773,50 @@ var PluginDriver = (_b$1 = class {
|
|
|
5729
5773
|
* Tracks which plugins have generators registered via `addGenerator()` (event-based path).
|
|
5730
5774
|
* Used by the build loop to decide whether to emit generator events for a given plugin.
|
|
5731
5775
|
*/
|
|
5732
|
-
__privateAdd$1(this,
|
|
5776
|
+
__privateAdd$1(this, _eventGeneratorPlugins, /* @__PURE__ */ new Set());
|
|
5733
5777
|
__privateAdd$1(this, _resolvers, /* @__PURE__ */ new Map());
|
|
5734
5778
|
__privateAdd$1(this, _defaultResolvers, /* @__PURE__ */ new Map());
|
|
5735
5779
|
__privateAdd$1(this, _hookListeners, /* @__PURE__ */ new Map());
|
|
5780
|
+
__privateAdd$1(this, _getDefaultResolver, memoize(__privateGet$1(this, _defaultResolvers), (pluginName) => defineResolver(() => ({
|
|
5781
|
+
name: "default",
|
|
5782
|
+
pluginName
|
|
5783
|
+
}))));
|
|
5736
5784
|
this.config = config;
|
|
5737
5785
|
this.options = options;
|
|
5738
|
-
|
|
5739
|
-
if (typeof plugin.apply === "function") return plugin.apply(config);
|
|
5740
|
-
return true;
|
|
5741
|
-
}).sort((a, b) => {
|
|
5742
|
-
var _a2, _b2;
|
|
5743
|
-
if ((_a2 = b.dependencies) == null ? void 0 : _a2.includes(a.name)) return -1;
|
|
5744
|
-
if ((_b2 = a.dependencies) == null ? void 0 : _b2.includes(b.name)) return 1;
|
|
5745
|
-
return enforceOrder(a.enforce) - enforceOrder(b.enforce);
|
|
5746
|
-
}).forEach((plugin) => {
|
|
5747
|
-
this.plugins.set(plugin.name, plugin);
|
|
5748
|
-
});
|
|
5786
|
+
this.adapter = config.adapter;
|
|
5749
5787
|
}
|
|
5750
5788
|
/**
|
|
5751
5789
|
* Returns `'single'` when `fileOrFolder` has a file extension, `'split'` otherwise.
|
|
5752
5790
|
*
|
|
5753
5791
|
* @example
|
|
5754
5792
|
* ```ts
|
|
5755
|
-
*
|
|
5756
|
-
*
|
|
5793
|
+
* KubbDriver.getMode('src/gen/types.ts') // 'single'
|
|
5794
|
+
* KubbDriver.getMode('src/gen/types') // 'split'
|
|
5757
5795
|
* ```
|
|
5758
5796
|
*/
|
|
5759
5797
|
static getMode(fileOrFolder) {
|
|
5760
|
-
|
|
5761
|
-
|
|
5798
|
+
return getMode(fileOrFolder);
|
|
5799
|
+
}
|
|
5800
|
+
async setup() {
|
|
5801
|
+
const normalized = this.config.plugins.map((rawPlugin) => __privateMethod$1(this, _KubbDriver_instances, normalizePlugin_fn).call(this, rawPlugin));
|
|
5802
|
+
normalized.sort((a, b) => {
|
|
5803
|
+
var _a2, _b2;
|
|
5804
|
+
if ((_a2 = b.dependencies) == null ? void 0 : _a2.includes(a.name)) return -1;
|
|
5805
|
+
if ((_b2 = a.dependencies) == null ? void 0 : _b2.includes(b.name)) return 1;
|
|
5806
|
+
return enforceOrder(a.enforce) - enforceOrder(b.enforce);
|
|
5807
|
+
});
|
|
5808
|
+
for (const plugin of normalized) {
|
|
5809
|
+
if (plugin.apply) plugin.apply(this.config);
|
|
5810
|
+
__privateMethod$1(this, _KubbDriver_instances, registerPlugin_fn).call(this, plugin);
|
|
5811
|
+
this.plugins.set(plugin.name, plugin);
|
|
5812
|
+
}
|
|
5813
|
+
if (this.config.middleware) for (const middleware of this.config.middleware) for (const event of Object.keys(middleware.hooks)) __privateMethod$1(this, _KubbDriver_instances, registerMiddleware_fn).call(this, event, middleware.hooks);
|
|
5814
|
+
if (this.config.adapter) await __privateMethod$1(this, _KubbDriver_instances, registerAdapter_fn).call(this, this.config.adapter);
|
|
5762
5815
|
}
|
|
5763
5816
|
get hooks() {
|
|
5764
5817
|
return this.options.hooks;
|
|
5765
5818
|
}
|
|
5766
5819
|
/**
|
|
5767
|
-
* Registers a hook-style plugin's lifecycle handlers on the shared `AsyncEventEmitter`.
|
|
5768
|
-
*
|
|
5769
|
-
* For `kubb:plugin:setup`, the registered listener wraps the globally emitted context with a
|
|
5770
|
-
* plugin-specific one so that `addGenerator`, `setResolver`, `setTransformer`, and
|
|
5771
|
-
* `setRenderer` all target the correct `normalizedPlugin` entry in the plugins map.
|
|
5772
|
-
*
|
|
5773
|
-
* All other hooks are iterated and registered directly as pass-through listeners.
|
|
5774
|
-
* Any event key present in the global `KubbHooks` interface can be subscribed to.
|
|
5775
|
-
*
|
|
5776
|
-
* External tooling can subscribe to any of these events via `hooks.on(...)` to observe
|
|
5777
|
-
* the plugin lifecycle without modifying plugin behavior.
|
|
5778
|
-
*
|
|
5779
|
-
* @internal
|
|
5780
|
-
*/
|
|
5781
|
-
registerPluginHooks(hookPlugin, normalizedPlugin) {
|
|
5782
|
-
const { hooks } = hookPlugin;
|
|
5783
|
-
if (hooks["kubb:plugin:setup"]) {
|
|
5784
|
-
const setupHandler = (globalCtx) => {
|
|
5785
|
-
var _a2;
|
|
5786
|
-
const pluginCtx = {
|
|
5787
|
-
...globalCtx,
|
|
5788
|
-
options: (_a2 = hookPlugin.options) != null ? _a2 : {},
|
|
5789
|
-
addGenerator: (gen) => {
|
|
5790
|
-
this.registerGenerator(normalizedPlugin.name, gen);
|
|
5791
|
-
},
|
|
5792
|
-
setResolver: (resolver) => {
|
|
5793
|
-
this.setPluginResolver(normalizedPlugin.name, resolver);
|
|
5794
|
-
},
|
|
5795
|
-
setTransformer: (visitor) => {
|
|
5796
|
-
normalizedPlugin.transformer = visitor;
|
|
5797
|
-
},
|
|
5798
|
-
setRenderer: (renderer) => {
|
|
5799
|
-
normalizedPlugin.renderer = renderer;
|
|
5800
|
-
},
|
|
5801
|
-
setOptions: (opts) => {
|
|
5802
|
-
normalizedPlugin.options = {
|
|
5803
|
-
...normalizedPlugin.options,
|
|
5804
|
-
...opts
|
|
5805
|
-
};
|
|
5806
|
-
},
|
|
5807
|
-
injectFile: (userFileNode) => {
|
|
5808
|
-
this.fileManager.add(createFile(userFileNode));
|
|
5809
|
-
}
|
|
5810
|
-
};
|
|
5811
|
-
return hooks["kubb:plugin:setup"](pluginCtx);
|
|
5812
|
-
};
|
|
5813
|
-
this.hooks.on("kubb:plugin:setup", setupHandler);
|
|
5814
|
-
__privateMethod$1(this, _PluginDriver_instances, trackHookListener_fn).call(this, "kubb:plugin:setup", setupHandler);
|
|
5815
|
-
}
|
|
5816
|
-
for (const [event, handler] of Object.entries(hooks)) {
|
|
5817
|
-
if (event === "kubb:plugin:setup" || !handler) continue;
|
|
5818
|
-
this.hooks.on(event, handler);
|
|
5819
|
-
__privateMethod$1(this, _PluginDriver_instances, trackHookListener_fn).call(this, event, handler);
|
|
5820
|
-
}
|
|
5821
|
-
}
|
|
5822
|
-
/**
|
|
5823
5820
|
* Emits the `kubb:plugin:setup` event so that all registered hook-style plugin listeners
|
|
5824
5821
|
* can configure generators, resolvers, transformers and renderers before `buildStart` runs.
|
|
5825
5822
|
*
|
|
@@ -5863,28 +5860,40 @@ var PluginDriver = (_b$1 = class {
|
|
|
5863
5860
|
if (gen.schema) {
|
|
5864
5861
|
const schemaHandler = async (node, ctx) => {
|
|
5865
5862
|
if (ctx.plugin.name !== pluginName) return;
|
|
5866
|
-
await applyHookResult(
|
|
5863
|
+
await applyHookResult({
|
|
5864
|
+
result: await gen.schema(node, ctx),
|
|
5865
|
+
driver: this,
|
|
5866
|
+
rendererFactory: resolveRenderer()
|
|
5867
|
+
});
|
|
5867
5868
|
};
|
|
5868
5869
|
this.hooks.on("kubb:generate:schema", schemaHandler);
|
|
5869
|
-
__privateMethod$1(this,
|
|
5870
|
+
__privateMethod$1(this, _KubbDriver_instances, trackHookListener_fn).call(this, "kubb:generate:schema", schemaHandler);
|
|
5870
5871
|
}
|
|
5871
5872
|
if (gen.operation) {
|
|
5872
5873
|
const operationHandler = async (node, ctx) => {
|
|
5873
5874
|
if (ctx.plugin.name !== pluginName) return;
|
|
5874
|
-
await applyHookResult(
|
|
5875
|
+
await applyHookResult({
|
|
5876
|
+
result: await gen.operation(node, ctx),
|
|
5877
|
+
driver: this,
|
|
5878
|
+
rendererFactory: resolveRenderer()
|
|
5879
|
+
});
|
|
5875
5880
|
};
|
|
5876
5881
|
this.hooks.on("kubb:generate:operation", operationHandler);
|
|
5877
|
-
__privateMethod$1(this,
|
|
5882
|
+
__privateMethod$1(this, _KubbDriver_instances, trackHookListener_fn).call(this, "kubb:generate:operation", operationHandler);
|
|
5878
5883
|
}
|
|
5879
5884
|
if (gen.operations) {
|
|
5880
5885
|
const operationsHandler = async (nodes, ctx) => {
|
|
5881
5886
|
if (ctx.plugin.name !== pluginName) return;
|
|
5882
|
-
await applyHookResult(
|
|
5887
|
+
await applyHookResult({
|
|
5888
|
+
result: await gen.operations(nodes, ctx),
|
|
5889
|
+
driver: this,
|
|
5890
|
+
rendererFactory: resolveRenderer()
|
|
5891
|
+
});
|
|
5883
5892
|
};
|
|
5884
5893
|
this.hooks.on("kubb:generate:operations", operationsHandler);
|
|
5885
|
-
__privateMethod$1(this,
|
|
5894
|
+
__privateMethod$1(this, _KubbDriver_instances, trackHookListener_fn).call(this, "kubb:generate:operations", operationsHandler);
|
|
5886
5895
|
}
|
|
5887
|
-
__privateGet$1(this,
|
|
5896
|
+
__privateGet$1(this, _eventGeneratorPlugins).add(pluginName);
|
|
5888
5897
|
}
|
|
5889
5898
|
/**
|
|
5890
5899
|
* Returns `true` when at least one generator was registered for the given plugin
|
|
@@ -5893,8 +5902,8 @@ var PluginDriver = (_b$1 = class {
|
|
|
5893
5902
|
* Used by the build loop to decide whether to walk the AST and emit generator events
|
|
5894
5903
|
* for a plugin that has no static `plugin.generators`.
|
|
5895
5904
|
*/
|
|
5896
|
-
|
|
5897
|
-
return __privateGet$1(this,
|
|
5905
|
+
hasEventGenerators(pluginName) {
|
|
5906
|
+
return __privateGet$1(this, _eventGeneratorPlugins).has(pluginName);
|
|
5898
5907
|
}
|
|
5899
5908
|
/**
|
|
5900
5909
|
* Unregisters all plugin lifecycle listeners from the shared event emitter.
|
|
@@ -5905,7 +5914,20 @@ var PluginDriver = (_b$1 = class {
|
|
|
5905
5914
|
dispose() {
|
|
5906
5915
|
for (const [event, handlers] of __privateGet$1(this, _hookListeners)) for (const handler of handlers) this.hooks.off(event, handler);
|
|
5907
5916
|
__privateGet$1(this, _hookListeners).clear();
|
|
5908
|
-
__privateGet$1(this,
|
|
5917
|
+
__privateGet$1(this, _eventGeneratorPlugins).clear();
|
|
5918
|
+
__privateGet$1(this, _resolvers).clear();
|
|
5919
|
+
__privateGet$1(this, _defaultResolvers).clear();
|
|
5920
|
+
this.fileManager.dispose();
|
|
5921
|
+
this.inputNode = void 0;
|
|
5922
|
+
__privateSet(this, _studio, {
|
|
5923
|
+
source: void 0,
|
|
5924
|
+
isOpen: false,
|
|
5925
|
+
inputNode: void 0
|
|
5926
|
+
});
|
|
5927
|
+
for (const [event, handler] of __privateGet$1(this, _middlewareListeners)) this.hooks.off(event, handler);
|
|
5928
|
+
}
|
|
5929
|
+
[Symbol.dispose]() {
|
|
5930
|
+
this.dispose();
|
|
5909
5931
|
}
|
|
5910
5932
|
/**
|
|
5911
5933
|
* Merges `partial` with the plugin's default resolver and stores the result.
|
|
@@ -5914,7 +5936,7 @@ var PluginDriver = (_b$1 = class {
|
|
|
5914
5936
|
*/
|
|
5915
5937
|
setPluginResolver(pluginName, partial) {
|
|
5916
5938
|
const merged = {
|
|
5917
|
-
...
|
|
5939
|
+
...__privateGet$1(this, _getDefaultResolver).call(this, pluginName),
|
|
5918
5940
|
...partial
|
|
5919
5941
|
};
|
|
5920
5942
|
__privateGet$1(this, _resolvers).set(pluginName, merged);
|
|
@@ -5922,8 +5944,8 @@ var PluginDriver = (_b$1 = class {
|
|
|
5922
5944
|
if (plugin) plugin.resolver = merged;
|
|
5923
5945
|
}
|
|
5924
5946
|
getResolver(pluginName) {
|
|
5925
|
-
var _a2, _b2,
|
|
5926
|
-
return (
|
|
5947
|
+
var _a2, _b2, _c2;
|
|
5948
|
+
return (_c2 = (_b2 = __privateGet$1(this, _resolvers).get(pluginName)) != null ? _b2 : (_a2 = this.plugins.get(pluginName)) == null ? void 0 : _a2.resolver) != null ? _c2 : __privateGet$1(this, _getDefaultResolver).call(this, pluginName);
|
|
5927
5949
|
}
|
|
5928
5950
|
getContext(plugin) {
|
|
5929
5951
|
const driver = this;
|
|
@@ -5933,7 +5955,7 @@ var PluginDriver = (_b$1 = class {
|
|
|
5933
5955
|
return resolve(driver.config.root, driver.config.output.path);
|
|
5934
5956
|
},
|
|
5935
5957
|
getMode(output) {
|
|
5936
|
-
return
|
|
5958
|
+
return _c.getMode(resolve(driver.config.root, driver.config.output.path, output.path));
|
|
5937
5959
|
},
|
|
5938
5960
|
hooks: driver.hooks,
|
|
5939
5961
|
plugin,
|
|
@@ -5947,8 +5969,12 @@ var PluginDriver = (_b$1 = class {
|
|
|
5947
5969
|
upsertFile: async (...files) => {
|
|
5948
5970
|
driver.fileManager.upsert(...files);
|
|
5949
5971
|
},
|
|
5950
|
-
get
|
|
5951
|
-
|
|
5972
|
+
get meta() {
|
|
5973
|
+
var _a2, _b2;
|
|
5974
|
+
return (_b2 = (_a2 = driver.inputNode) == null ? void 0 : _a2.meta) != null ? _b2 : {
|
|
5975
|
+
circularNames: [],
|
|
5976
|
+
enumNames: []
|
|
5977
|
+
};
|
|
5952
5978
|
},
|
|
5953
5979
|
get adapter() {
|
|
5954
5980
|
return driver.adapter;
|
|
@@ -5968,14 +5994,15 @@ var PluginDriver = (_b$1 = class {
|
|
|
5968
5994
|
info(message) {
|
|
5969
5995
|
driver.hooks.emit("kubb:info", { message });
|
|
5970
5996
|
},
|
|
5971
|
-
openInStudio(options) {
|
|
5972
|
-
var _a2, _b2;
|
|
5973
|
-
if (!driver.config.devtools || __privateGet$1(driver,
|
|
5997
|
+
async openInStudio(options) {
|
|
5998
|
+
var _a2, _b2, _c2, _d;
|
|
5999
|
+
if (!driver.config.devtools || __privateGet$1(driver, _studio).isOpen) return;
|
|
5974
6000
|
if (typeof driver.config.devtools !== "object") throw new Error("Devtools must be an object");
|
|
5975
|
-
if (!driver.
|
|
5976
|
-
|
|
5977
|
-
const studioUrl = (_b2 = (_a2 = driver.config.devtools) == null ? void 0 : _a2.studioUrl) != null ? _b2 : "https://
|
|
5978
|
-
|
|
6001
|
+
if (!driver.adapter || !__privateGet$1(driver, _studio).source) throw new Error("adapter is not defined, make sure you have set the parser in kubb.config.ts");
|
|
6002
|
+
__privateGet$1(driver, _studio).isOpen = true;
|
|
6003
|
+
const studioUrl = (_b2 = (_a2 = driver.config.devtools) == null ? void 0 : _a2.studioUrl) != null ? _b2 : "https://kubb.studio";
|
|
6004
|
+
(_d = (_c2 = __privateGet$1(driver, _studio)).inputNode) != null ? _d : _c2.inputNode = Promise.resolve(driver.adapter.parse(__privateGet$1(driver, _studio).source));
|
|
6005
|
+
return openInStudio(await __privateGet$1(driver, _studio).inputNode, studioUrl, options);
|
|
5979
6006
|
}
|
|
5980
6007
|
};
|
|
5981
6008
|
}
|
|
@@ -5987,23 +6014,107 @@ var PluginDriver = (_b$1 = class {
|
|
|
5987
6014
|
if (!plugin) throw new Error(`[kubb] Plugin "${pluginName}" is required but not found. Make sure it is included in your Kubb config.`);
|
|
5988
6015
|
return plugin;
|
|
5989
6016
|
}
|
|
5990
|
-
},
|
|
6017
|
+
}, _studio = new WeakMap(), _middlewareListeners = new WeakMap(), _eventGeneratorPlugins = new WeakMap(), _resolvers = new WeakMap(), _defaultResolvers = new WeakMap(), _hookListeners = new WeakMap(), _KubbDriver_instances = new WeakSet(), /**
|
|
5991
6018
|
* Creates an `NormalizedPlugin` from a hook-style plugin and registers
|
|
5992
6019
|
* its lifecycle handlers on the `AsyncEventEmitter`.
|
|
5993
6020
|
*/
|
|
5994
|
-
normalizePlugin_fn = function(
|
|
5995
|
-
|
|
5996
|
-
|
|
5997
|
-
|
|
5998
|
-
|
|
5999
|
-
|
|
6021
|
+
normalizePlugin_fn = function(plugin) {
|
|
6022
|
+
var _a2;
|
|
6023
|
+
const normalized = {
|
|
6024
|
+
name: plugin.name,
|
|
6025
|
+
dependencies: plugin.dependencies,
|
|
6026
|
+
enforce: plugin.enforce,
|
|
6027
|
+
hooks: plugin.hooks,
|
|
6028
|
+
options: (_a2 = plugin.options) != null ? _a2 : {
|
|
6000
6029
|
output: { path: "." },
|
|
6001
6030
|
exclude: [],
|
|
6002
6031
|
override: []
|
|
6003
6032
|
}
|
|
6004
6033
|
};
|
|
6005
|
-
|
|
6006
|
-
return
|
|
6034
|
+
if ("apply" in plugin && typeof plugin.apply === "function") normalized.apply = plugin.apply;
|
|
6035
|
+
return normalized;
|
|
6036
|
+
}, registerAdapter_fn = async function(adapter) {
|
|
6037
|
+
const source = inputToAdapterSource(this.config);
|
|
6038
|
+
__privateGet$1(this, _studio).source = source;
|
|
6039
|
+
if (adapter.stream) {
|
|
6040
|
+
this.inputNode = await adapter.stream(source);
|
|
6041
|
+
await this.hooks.emit("kubb:debug", {
|
|
6042
|
+
date: /* @__PURE__ */ new Date(),
|
|
6043
|
+
logs: [`\u2713 Adapter '${adapter.name}' producing input stream`]
|
|
6044
|
+
});
|
|
6045
|
+
} else {
|
|
6046
|
+
const inputNode = await adapter.parse(source);
|
|
6047
|
+
this.inputNode = createStreamInput(arrayToAsyncIterable(inputNode.schemas), arrayToAsyncIterable(inputNode.operations), inputNode.meta);
|
|
6048
|
+
await this.hooks.emit("kubb:debug", {
|
|
6049
|
+
date: /* @__PURE__ */ new Date(),
|
|
6050
|
+
logs: [
|
|
6051
|
+
`\u2713 Adapter '${adapter.name}' resolved InputNode (wrapped as stream)`,
|
|
6052
|
+
` \u2022 Schemas: ${inputNode.schemas.length}`,
|
|
6053
|
+
` \u2022 Operations: ${inputNode.operations.length}`
|
|
6054
|
+
]
|
|
6055
|
+
});
|
|
6056
|
+
}
|
|
6057
|
+
}, registerMiddleware_fn = function(event, middlewareHooks) {
|
|
6058
|
+
const handler = middlewareHooks[event];
|
|
6059
|
+
if (!handler) return;
|
|
6060
|
+
this.hooks.on(event, handler);
|
|
6061
|
+
__privateGet$1(this, _middlewareListeners).push([event, handler]);
|
|
6062
|
+
}, /**
|
|
6063
|
+
* Registers a hook-style plugin's lifecycle handlers on the shared `AsyncEventEmitter`.
|
|
6064
|
+
*
|
|
6065
|
+
* For `kubb:plugin:setup`, the registered listener wraps the globally emitted context with a
|
|
6066
|
+
* plugin-specific one so that `addGenerator`, `setResolver`, `setTransformer`, and
|
|
6067
|
+
* `setRenderer` all target the correct `normalizedPlugin` entry in the plugins map.
|
|
6068
|
+
*
|
|
6069
|
+
* All other hooks are iterated and registered directly as pass-through listeners.
|
|
6070
|
+
* Any event key present in the global `KubbHooks` interface can be subscribed to.
|
|
6071
|
+
*
|
|
6072
|
+
* External tooling can subscribe to any of these events via `hooks.on(...)` to observe
|
|
6073
|
+
* the plugin lifecycle without modifying plugin behavior.
|
|
6074
|
+
*
|
|
6075
|
+
* @internal
|
|
6076
|
+
*/
|
|
6077
|
+
registerPlugin_fn = function(plugin) {
|
|
6078
|
+
const { hooks } = plugin;
|
|
6079
|
+
if (!hooks) return;
|
|
6080
|
+
if (hooks["kubb:plugin:setup"]) {
|
|
6081
|
+
const setupHandler = (globalCtx) => {
|
|
6082
|
+
var _a2;
|
|
6083
|
+
const pluginCtx = {
|
|
6084
|
+
...globalCtx,
|
|
6085
|
+
options: (_a2 = plugin.options) != null ? _a2 : {},
|
|
6086
|
+
addGenerator: (gen) => {
|
|
6087
|
+
this.registerGenerator(plugin.name, gen);
|
|
6088
|
+
},
|
|
6089
|
+
setResolver: (resolver) => {
|
|
6090
|
+
this.setPluginResolver(plugin.name, resolver);
|
|
6091
|
+
},
|
|
6092
|
+
setTransformer: (visitor) => {
|
|
6093
|
+
plugin.transformer = visitor;
|
|
6094
|
+
},
|
|
6095
|
+
setRenderer: (renderer) => {
|
|
6096
|
+
plugin.renderer = renderer;
|
|
6097
|
+
},
|
|
6098
|
+
setOptions: (opts) => {
|
|
6099
|
+
plugin.options = {
|
|
6100
|
+
...plugin.options,
|
|
6101
|
+
...opts
|
|
6102
|
+
};
|
|
6103
|
+
},
|
|
6104
|
+
injectFile: (userFileNode) => {
|
|
6105
|
+
this.fileManager.add(createFile(userFileNode));
|
|
6106
|
+
}
|
|
6107
|
+
};
|
|
6108
|
+
return hooks["kubb:plugin:setup"](pluginCtx);
|
|
6109
|
+
};
|
|
6110
|
+
this.hooks.on("kubb:plugin:setup", setupHandler);
|
|
6111
|
+
__privateMethod$1(this, _KubbDriver_instances, trackHookListener_fn).call(this, "kubb:plugin:setup", setupHandler);
|
|
6112
|
+
}
|
|
6113
|
+
for (const [event, handler] of Object.entries(hooks)) {
|
|
6114
|
+
if (event === "kubb:plugin:setup" || !handler) continue;
|
|
6115
|
+
this.hooks.on(event, handler);
|
|
6116
|
+
__privateMethod$1(this, _KubbDriver_instances, trackHookListener_fn).call(this, event, handler);
|
|
6117
|
+
}
|
|
6007
6118
|
}, trackHookListener_fn = function(event, handler) {
|
|
6008
6119
|
let handlers = __privateGet$1(this, _hookListeners).get(event);
|
|
6009
6120
|
if (!handlers) {
|
|
@@ -6011,16 +6122,47 @@ normalizePlugin_fn = function(hookPlugin) {
|
|
|
6011
6122
|
__privateGet$1(this, _hookListeners).set(event, handlers);
|
|
6012
6123
|
}
|
|
6013
6124
|
handlers.add(handler);
|
|
6014
|
-
},
|
|
6015
|
-
|
|
6016
|
-
if (
|
|
6017
|
-
|
|
6018
|
-
|
|
6019
|
-
|
|
6020
|
-
}
|
|
6021
|
-
|
|
6022
|
-
|
|
6023
|
-
|
|
6125
|
+
}, _getDefaultResolver = new WeakMap(), _c);
|
|
6126
|
+
function applyHookResult({ result, driver, rendererFactory }) {
|
|
6127
|
+
if (!result) return;
|
|
6128
|
+
if (Array.isArray(result)) {
|
|
6129
|
+
driver.fileManager.upsert(...result);
|
|
6130
|
+
return;
|
|
6131
|
+
}
|
|
6132
|
+
if (!rendererFactory) return;
|
|
6133
|
+
const renderer = rendererFactory();
|
|
6134
|
+
if (renderer.stream) {
|
|
6135
|
+
for (const file of renderer.stream(result)) driver.fileManager.upsert(file);
|
|
6136
|
+
renderer.unmount();
|
|
6137
|
+
return;
|
|
6138
|
+
}
|
|
6139
|
+
return applyAsyncRender({
|
|
6140
|
+
renderer,
|
|
6141
|
+
result,
|
|
6142
|
+
driver
|
|
6143
|
+
});
|
|
6144
|
+
}
|
|
6145
|
+
async function applyAsyncRender({ renderer, result, driver }) {
|
|
6146
|
+
await renderer.render(result);
|
|
6147
|
+
driver.fileManager.upsert(...renderer.files);
|
|
6148
|
+
renderer.unmount();
|
|
6149
|
+
}
|
|
6150
|
+
function inputToAdapterSource(config) {
|
|
6151
|
+
const input = config.input;
|
|
6152
|
+
if (!input) throw new Error("[kubb] input is required when using an adapter. Provide input.path or input.data in your config.");
|
|
6153
|
+
if ("data" in input) return {
|
|
6154
|
+
type: "data",
|
|
6155
|
+
data: input.data
|
|
6156
|
+
};
|
|
6157
|
+
if (new URLPath(input.path).isURL) return {
|
|
6158
|
+
type: "path",
|
|
6159
|
+
path: input.path
|
|
6160
|
+
};
|
|
6161
|
+
return {
|
|
6162
|
+
type: "path",
|
|
6163
|
+
path: resolve(config.root, input.path)
|
|
6164
|
+
};
|
|
6165
|
+
}
|
|
6024
6166
|
|
|
6025
6167
|
var __defProp = Object.defineProperty;
|
|
6026
6168
|
var __typeError = (msg) => {
|
|
@@ -6031,17 +6173,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6031
6173
|
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
6032
6174
|
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6033
6175
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
6034
|
-
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
|
|
6035
6176
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
6036
|
-
var
|
|
6037
|
-
set _(value) {
|
|
6038
|
-
__privateSet(obj, member, value);
|
|
6039
|
-
},
|
|
6040
|
-
get _() {
|
|
6041
|
-
return __privateGet(obj, member, getter);
|
|
6042
|
-
}
|
|
6043
|
-
});
|
|
6044
|
-
var _emitter, _a, _options, _URLPath_instances, transformParam_fn, eachParam_fn, _b, _c, _head, _tail, _size, _d, _limit, _e;
|
|
6177
|
+
var _emitter, _AsyncEventEmitter_instances, emitAll_fn, _a;
|
|
6045
6178
|
var BuildError = class extends Error {
|
|
6046
6179
|
constructor(message, options) {
|
|
6047
6180
|
super(message, { cause: options.cause });
|
|
@@ -6059,6 +6192,7 @@ var AsyncEventEmitter = (_a = class {
|
|
|
6059
6192
|
* @default 10
|
|
6060
6193
|
*/
|
|
6061
6194
|
constructor(maxListener = 10) {
|
|
6195
|
+
__privateAdd(this, _AsyncEventEmitter_instances);
|
|
6062
6196
|
__privateAdd(this, _emitter, new EventEmitter());
|
|
6063
6197
|
__privateGet(this, _emitter).setMaxListeners(maxListener);
|
|
6064
6198
|
}
|
|
@@ -6071,20 +6205,10 @@ var AsyncEventEmitter = (_a = class {
|
|
|
6071
6205
|
* await emitter.emit('build', 'petstore')
|
|
6072
6206
|
* ```
|
|
6073
6207
|
*/
|
|
6074
|
-
|
|
6208
|
+
emit(eventName, ...eventArgs) {
|
|
6075
6209
|
const listeners = __privateGet(this, _emitter).listeners(eventName);
|
|
6076
6210
|
if (listeners.length === 0) return;
|
|
6077
|
-
|
|
6078
|
-
await listener(...eventArgs);
|
|
6079
|
-
} catch (err) {
|
|
6080
|
-
let serializedArgs;
|
|
6081
|
-
try {
|
|
6082
|
-
serializedArgs = JSON.stringify(eventArgs);
|
|
6083
|
-
} catch {
|
|
6084
|
-
serializedArgs = String(eventArgs);
|
|
6085
|
-
}
|
|
6086
|
-
throw new Error(`Error in async listener for "${eventName}" with eventArgs ${serializedArgs}`, { cause: toError(err) });
|
|
6087
|
-
}
|
|
6211
|
+
return __privateMethod(this, _AsyncEventEmitter_instances, emitAll_fn).call(this, eventName, listeners, eventArgs);
|
|
6088
6212
|
}
|
|
6089
6213
|
/**
|
|
6090
6214
|
* Registers a persistent listener for `eventName`.
|
|
@@ -6146,7 +6270,19 @@ var AsyncEventEmitter = (_a = class {
|
|
|
6146
6270
|
removeAll() {
|
|
6147
6271
|
__privateGet(this, _emitter).removeAllListeners();
|
|
6148
6272
|
}
|
|
6149
|
-
}, _emitter = new WeakMap(),
|
|
6273
|
+
}, _emitter = new WeakMap(), _AsyncEventEmitter_instances = new WeakSet(), emitAll_fn = async function(eventName, listeners, eventArgs) {
|
|
6274
|
+
for (const listener of listeners) try {
|
|
6275
|
+
await listener(...eventArgs);
|
|
6276
|
+
} catch (err) {
|
|
6277
|
+
let serializedArgs;
|
|
6278
|
+
try {
|
|
6279
|
+
serializedArgs = JSON.stringify(eventArgs);
|
|
6280
|
+
} catch {
|
|
6281
|
+
serializedArgs = String(eventArgs);
|
|
6282
|
+
}
|
|
6283
|
+
throw new Error(`Error in async listener for "${eventName}" with eventArgs ${serializedArgs}`, { cause: toError(err) });
|
|
6284
|
+
}
|
|
6285
|
+
}, _a);
|
|
6150
6286
|
function getElapsedMs(hrStart) {
|
|
6151
6287
|
const [seconds, nanoseconds] = process.hrtime(hrStart);
|
|
6152
6288
|
const ms = seconds * 1e3 + nanoseconds / 1e6;
|
|
@@ -6197,414 +6333,75 @@ async function clean(path) {
|
|
|
6197
6333
|
force: true
|
|
6198
6334
|
});
|
|
6199
6335
|
}
|
|
6200
|
-
|
|
6201
|
-
|
|
6202
|
-
|
|
6203
|
-
"boolean",
|
|
6204
|
-
"break",
|
|
6205
|
-
"byte",
|
|
6206
|
-
"case",
|
|
6207
|
-
"catch",
|
|
6208
|
-
"char",
|
|
6209
|
-
"class",
|
|
6210
|
-
"const",
|
|
6211
|
-
"continue",
|
|
6212
|
-
"debugger",
|
|
6213
|
-
"default",
|
|
6214
|
-
"delete",
|
|
6215
|
-
"do",
|
|
6216
|
-
"double",
|
|
6217
|
-
"else",
|
|
6218
|
-
"enum",
|
|
6219
|
-
"eval",
|
|
6220
|
-
"export",
|
|
6221
|
-
"extends",
|
|
6222
|
-
"false",
|
|
6223
|
-
"final",
|
|
6224
|
-
"finally",
|
|
6225
|
-
"float",
|
|
6226
|
-
"for",
|
|
6227
|
-
"function",
|
|
6228
|
-
"goto",
|
|
6229
|
-
"if",
|
|
6230
|
-
"implements",
|
|
6231
|
-
"import",
|
|
6232
|
-
"in",
|
|
6233
|
-
"instanceof",
|
|
6234
|
-
"int",
|
|
6235
|
-
"interface",
|
|
6236
|
-
"let",
|
|
6237
|
-
"long",
|
|
6238
|
-
"native",
|
|
6239
|
-
"new",
|
|
6240
|
-
"null",
|
|
6241
|
-
"package",
|
|
6242
|
-
"private",
|
|
6243
|
-
"protected",
|
|
6244
|
-
"public",
|
|
6245
|
-
"return",
|
|
6246
|
-
"short",
|
|
6247
|
-
"static",
|
|
6248
|
-
"super",
|
|
6249
|
-
"switch",
|
|
6250
|
-
"synchronized",
|
|
6251
|
-
"this",
|
|
6252
|
-
"throw",
|
|
6253
|
-
"throws",
|
|
6254
|
-
"transient",
|
|
6255
|
-
"true",
|
|
6256
|
-
"try",
|
|
6257
|
-
"typeof",
|
|
6258
|
-
"var",
|
|
6259
|
-
"void",
|
|
6260
|
-
"volatile",
|
|
6261
|
-
"while",
|
|
6262
|
-
"with",
|
|
6263
|
-
"yield",
|
|
6264
|
-
"Array",
|
|
6265
|
-
"Date",
|
|
6266
|
-
"hasOwnProperty",
|
|
6267
|
-
"Infinity",
|
|
6268
|
-
"isFinite",
|
|
6269
|
-
"isNaN",
|
|
6270
|
-
"isPrototypeOf",
|
|
6271
|
-
"length",
|
|
6272
|
-
"Math",
|
|
6273
|
-
"name",
|
|
6274
|
-
"NaN",
|
|
6275
|
-
"Number",
|
|
6276
|
-
"Object",
|
|
6277
|
-
"prototype",
|
|
6278
|
-
"String",
|
|
6279
|
-
"toString",
|
|
6280
|
-
"undefined",
|
|
6281
|
-
"valueOf"
|
|
6282
|
-
]);
|
|
6283
|
-
function isValidVarName(name) {
|
|
6284
|
-
if (!name || reservedWords.has(name)) return false;
|
|
6285
|
-
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
6286
|
-
}
|
|
6287
|
-
var URLPath = (_b = class {
|
|
6288
|
-
constructor(path, options = {}) {
|
|
6289
|
-
__privateAdd(this, _URLPath_instances);
|
|
6290
|
-
/**
|
|
6291
|
-
* The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`.
|
|
6292
|
-
*/
|
|
6293
|
-
__publicField(this, "path");
|
|
6294
|
-
__privateAdd(this, _options);
|
|
6295
|
-
this.path = path;
|
|
6296
|
-
__privateSet(this, _options, options);
|
|
6297
|
-
}
|
|
6298
|
-
/** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`.
|
|
6299
|
-
*
|
|
6300
|
-
* @example
|
|
6301
|
-
* ```ts
|
|
6302
|
-
* new URLPath('/pet/{petId}').URL // '/pet/:petId'
|
|
6303
|
-
* ```
|
|
6304
|
-
*/
|
|
6305
|
-
get URL() {
|
|
6306
|
-
return this.toURLPath();
|
|
6307
|
-
}
|
|
6308
|
-
/** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`).
|
|
6309
|
-
*
|
|
6310
|
-
* @example
|
|
6311
|
-
* ```ts
|
|
6312
|
-
* new URLPath('https://petstore.swagger.io/v2/pet').isURL // true
|
|
6313
|
-
* new URLPath('/pet/{petId}').isURL // false
|
|
6314
|
-
* ```
|
|
6315
|
-
*/
|
|
6316
|
-
get isURL() {
|
|
6317
|
-
try {
|
|
6318
|
-
return !!new URL(this.path).href;
|
|
6319
|
-
} catch {
|
|
6320
|
-
return false;
|
|
6321
|
-
}
|
|
6322
|
-
}
|
|
6323
|
-
/**
|
|
6324
|
-
* Converts the OpenAPI path to a TypeScript template literal string.
|
|
6325
|
-
*
|
|
6326
|
-
* @example
|
|
6327
|
-
* new URLPath('/pet/{petId}').template // '`/pet/${petId}`'
|
|
6328
|
-
* new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
|
|
6329
|
-
*/
|
|
6330
|
-
get template() {
|
|
6331
|
-
return this.toTemplateString();
|
|
6332
|
-
}
|
|
6333
|
-
/** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set.
|
|
6334
|
-
*
|
|
6335
|
-
* @example
|
|
6336
|
-
* ```ts
|
|
6337
|
-
* new URLPath('/pet/{petId}').object
|
|
6338
|
-
* // { url: '/pet/:petId', params: { petId: 'petId' } }
|
|
6339
|
-
* ```
|
|
6340
|
-
*/
|
|
6341
|
-
get object() {
|
|
6342
|
-
return this.toObject();
|
|
6343
|
-
}
|
|
6344
|
-
/** Returns a map of path parameter names, or `undefined` when the path has no parameters.
|
|
6345
|
-
*
|
|
6346
|
-
* @example
|
|
6347
|
-
* ```ts
|
|
6348
|
-
* new URLPath('/pet/{petId}').params // { petId: 'petId' }
|
|
6349
|
-
* new URLPath('/pet').params // undefined
|
|
6350
|
-
* ```
|
|
6351
|
-
*/
|
|
6352
|
-
get params() {
|
|
6353
|
-
return this.getParams();
|
|
6354
|
-
}
|
|
6355
|
-
toObject({ type = "path", replacer, stringify } = {}) {
|
|
6356
|
-
const object = {
|
|
6357
|
-
url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
|
|
6358
|
-
params: this.getParams()
|
|
6359
|
-
};
|
|
6360
|
-
if (stringify) {
|
|
6361
|
-
if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
6362
|
-
if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
|
|
6363
|
-
return `{ url: '${object.url}' }`;
|
|
6364
|
-
}
|
|
6365
|
-
return object;
|
|
6366
|
-
}
|
|
6367
|
-
/**
|
|
6368
|
-
* Converts the OpenAPI path to a TypeScript template literal string.
|
|
6369
|
-
* An optional `replacer` can transform each extracted parameter name before interpolation.
|
|
6370
|
-
*
|
|
6371
|
-
* @example
|
|
6372
|
-
* new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
|
|
6373
|
-
*/
|
|
6374
|
-
toTemplateString({ prefix = "", replacer } = {}) {
|
|
6375
|
-
return `\`${prefix}${this.path.split(/\{([^}]+)\}/).map((part, i) => {
|
|
6376
|
-
if (i % 2 === 0) return part;
|
|
6377
|
-
const param = __privateMethod(this, _URLPath_instances, transformParam_fn).call(this, part);
|
|
6378
|
-
return `\${${replacer ? replacer(param) : param}}`;
|
|
6379
|
-
}).join("")}\``;
|
|
6380
|
-
}
|
|
6381
|
-
/**
|
|
6382
|
-
* Extracts all `{param}` segments from the path and returns them as a key-value map.
|
|
6383
|
-
* An optional `replacer` transforms each parameter name in both key and value positions.
|
|
6384
|
-
* Returns `undefined` when no path parameters are found.
|
|
6385
|
-
*
|
|
6386
|
-
* @example
|
|
6387
|
-
* ```ts
|
|
6388
|
-
* new URLPath('/pet/{petId}/tag/{tagId}').getParams()
|
|
6389
|
-
* // { petId: 'petId', tagId: 'tagId' }
|
|
6390
|
-
* ```
|
|
6391
|
-
*/
|
|
6392
|
-
getParams(replacer) {
|
|
6393
|
-
const params = {};
|
|
6394
|
-
__privateMethod(this, _URLPath_instances, eachParam_fn).call(this, (_raw, param) => {
|
|
6395
|
-
const key = replacer ? replacer(param) : param;
|
|
6396
|
-
params[key] = key;
|
|
6397
|
-
});
|
|
6398
|
-
return Object.keys(params).length > 0 ? params : void 0;
|
|
6399
|
-
}
|
|
6400
|
-
/** Converts the OpenAPI path to Express-style colon syntax.
|
|
6401
|
-
*
|
|
6402
|
-
* @example
|
|
6403
|
-
* ```ts
|
|
6404
|
-
* new URLPath('/pet/{petId}').toURLPath() // '/pet/:petId'
|
|
6405
|
-
* ```
|
|
6406
|
-
*/
|
|
6407
|
-
toURLPath() {
|
|
6408
|
-
return this.path.replace(/\{([^}]+)\}/g, ":$1");
|
|
6409
|
-
}
|
|
6410
|
-
}, _options = new WeakMap(), _URLPath_instances = new WeakSet(), transformParam_fn = function(raw) {
|
|
6411
|
-
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
6412
|
-
return __privateGet(this, _options).casing === "camelcase" ? camelCase(param) : param;
|
|
6413
|
-
}, /**
|
|
6414
|
-
* Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name.
|
|
6415
|
-
*/
|
|
6416
|
-
eachParam_fn = function(fn) {
|
|
6417
|
-
for (const match of this.path.matchAll(/\{([^}]+)\}/g)) {
|
|
6418
|
-
const raw = match[1];
|
|
6419
|
-
fn(raw, __privateMethod(this, _URLPath_instances, transformParam_fn).call(this, raw));
|
|
6420
|
-
}
|
|
6421
|
-
}, _b);
|
|
6422
|
-
var Node$1 = (_c = class {
|
|
6423
|
-
constructor(value) {
|
|
6424
|
-
__publicField(this, "value");
|
|
6425
|
-
__publicField(this, "next");
|
|
6426
|
-
this.value = value;
|
|
6427
|
-
}
|
|
6428
|
-
}, __name(_c, "Node"), _c);
|
|
6429
|
-
var Queue = (_d = class {
|
|
6430
|
-
constructor() {
|
|
6431
|
-
__privateAdd(this, _head);
|
|
6432
|
-
__privateAdd(this, _tail);
|
|
6433
|
-
__privateAdd(this, _size);
|
|
6434
|
-
this.clear();
|
|
6435
|
-
}
|
|
6436
|
-
enqueue(value) {
|
|
6437
|
-
const node = new Node$1(value);
|
|
6438
|
-
if (__privateGet(this, _head)) {
|
|
6439
|
-
__privateGet(this, _tail).next = node;
|
|
6440
|
-
__privateSet(this, _tail, node);
|
|
6441
|
-
} else {
|
|
6442
|
-
__privateSet(this, _head, node);
|
|
6443
|
-
__privateSet(this, _tail, node);
|
|
6444
|
-
}
|
|
6445
|
-
__privateWrapper(this, _size)._++;
|
|
6446
|
-
}
|
|
6447
|
-
dequeue() {
|
|
6448
|
-
const current = __privateGet(this, _head);
|
|
6449
|
-
if (!current) return;
|
|
6450
|
-
__privateSet(this, _head, __privateGet(this, _head).next);
|
|
6451
|
-
__privateWrapper(this, _size)._--;
|
|
6452
|
-
if (!__privateGet(this, _head)) __privateSet(this, _tail, void 0);
|
|
6453
|
-
return current.value;
|
|
6454
|
-
}
|
|
6455
|
-
peek() {
|
|
6456
|
-
if (!__privateGet(this, _head)) return;
|
|
6457
|
-
return __privateGet(this, _head).value;
|
|
6458
|
-
}
|
|
6459
|
-
clear() {
|
|
6460
|
-
__privateSet(this, _head, void 0);
|
|
6461
|
-
__privateSet(this, _tail, void 0);
|
|
6462
|
-
__privateSet(this, _size, 0);
|
|
6463
|
-
}
|
|
6464
|
-
get size() {
|
|
6465
|
-
return __privateGet(this, _size);
|
|
6466
|
-
}
|
|
6467
|
-
*[Symbol.iterator]() {
|
|
6468
|
-
let current = __privateGet(this, _head);
|
|
6469
|
-
while (current) {
|
|
6470
|
-
yield current.value;
|
|
6471
|
-
current = current.next;
|
|
6472
|
-
}
|
|
6473
|
-
}
|
|
6474
|
-
*drain() {
|
|
6475
|
-
while (__privateGet(this, _head)) yield this.dequeue();
|
|
6476
|
-
}
|
|
6477
|
-
}, _head = new WeakMap(), _tail = new WeakMap(), _size = new WeakMap(), _d);
|
|
6478
|
-
function pLimit(concurrency) {
|
|
6479
|
-
let rejectOnClear = false;
|
|
6480
|
-
if (typeof concurrency === "object") ({ concurrency, rejectOnClear = false } = concurrency);
|
|
6481
|
-
validateConcurrency(concurrency);
|
|
6482
|
-
if (typeof rejectOnClear !== "boolean") throw new TypeError("Expected `rejectOnClear` to be a boolean");
|
|
6483
|
-
const queue = new Queue();
|
|
6484
|
-
let activeCount = 0;
|
|
6485
|
-
const resumeNext = () => {
|
|
6486
|
-
if (activeCount < concurrency && queue.size > 0) {
|
|
6487
|
-
activeCount++;
|
|
6488
|
-
queue.dequeue().run();
|
|
6489
|
-
}
|
|
6490
|
-
};
|
|
6491
|
-
const next = () => {
|
|
6492
|
-
activeCount--;
|
|
6493
|
-
resumeNext();
|
|
6494
|
-
};
|
|
6495
|
-
const run = async (function_, resolve2, arguments_) => {
|
|
6496
|
-
const result = (async () => function_(...arguments_))();
|
|
6497
|
-
resolve2(result);
|
|
6498
|
-
try {
|
|
6499
|
-
await result;
|
|
6500
|
-
} catch {
|
|
6501
|
-
}
|
|
6502
|
-
next();
|
|
6503
|
-
};
|
|
6504
|
-
const enqueue = (function_, resolve2, reject, arguments_) => {
|
|
6505
|
-
const queueItem = { reject };
|
|
6506
|
-
new Promise((internalResolve) => {
|
|
6507
|
-
queueItem.run = internalResolve;
|
|
6508
|
-
queue.enqueue(queueItem);
|
|
6509
|
-
}).then(run.bind(void 0, function_, resolve2, arguments_));
|
|
6510
|
-
if (activeCount < concurrency) resumeNext();
|
|
6511
|
-
};
|
|
6512
|
-
const generator = (function_, ...arguments_) => new Promise((resolve2, reject) => {
|
|
6513
|
-
enqueue(function_, resolve2, reject, arguments_);
|
|
6514
|
-
});
|
|
6515
|
-
Object.defineProperties(generator, {
|
|
6516
|
-
activeCount: { get: () => activeCount },
|
|
6517
|
-
pendingCount: { get: () => queue.size },
|
|
6518
|
-
clearQueue: { value() {
|
|
6519
|
-
if (!rejectOnClear) {
|
|
6520
|
-
queue.clear();
|
|
6521
|
-
return;
|
|
6522
|
-
}
|
|
6523
|
-
const abortError = AbortSignal.abort().reason;
|
|
6524
|
-
while (queue.size > 0) queue.dequeue().reject(abortError);
|
|
6525
|
-
} },
|
|
6526
|
-
concurrency: {
|
|
6527
|
-
get: () => concurrency,
|
|
6528
|
-
set(newConcurrency) {
|
|
6529
|
-
validateConcurrency(newConcurrency);
|
|
6530
|
-
concurrency = newConcurrency;
|
|
6531
|
-
queueMicrotask(() => {
|
|
6532
|
-
while (activeCount < concurrency && queue.size > 0) resumeNext();
|
|
6533
|
-
});
|
|
6534
|
-
}
|
|
6535
|
-
},
|
|
6536
|
-
map: { async value(iterable, function_) {
|
|
6537
|
-
const promises = Array.from(iterable, (value, index) => this(function_, value, index));
|
|
6538
|
-
return Promise.all(promises);
|
|
6539
|
-
} }
|
|
6540
|
-
});
|
|
6541
|
-
return generator;
|
|
6542
|
-
}
|
|
6543
|
-
function validateConcurrency(concurrency) {
|
|
6544
|
-
if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
6336
|
+
var version$1 = "5.0.0-beta.20";
|
|
6337
|
+
function createStorage(build2) {
|
|
6338
|
+
return (options) => build2(options != null ? options : {});
|
|
6545
6339
|
}
|
|
6546
6340
|
function joinSources(file) {
|
|
6547
|
-
|
|
6341
|
+
const sources = file.sources;
|
|
6342
|
+
if (sources.length === 0) return "";
|
|
6343
|
+
const parts = [];
|
|
6344
|
+
for (const source of sources) {
|
|
6345
|
+
const s = extractStringsFromNodes(source.nodes);
|
|
6346
|
+
if (s) parts.push(s);
|
|
6347
|
+
}
|
|
6348
|
+
return parts.join("\n\n");
|
|
6548
6349
|
}
|
|
6549
|
-
var FileProcessor =
|
|
6350
|
+
var FileProcessor = class {
|
|
6550
6351
|
constructor() {
|
|
6551
|
-
|
|
6352
|
+
__publicField(this, "events", new AsyncEventEmitter());
|
|
6552
6353
|
}
|
|
6553
|
-
|
|
6354
|
+
parse(file, { parsers, extension } = {}) {
|
|
6554
6355
|
const parseExtName = (extension == null ? void 0 : extension[file.extname]) || void 0;
|
|
6555
6356
|
if (!parsers || !file.extname) return joinSources(file);
|
|
6556
6357
|
const parser = parsers.get(file.extname);
|
|
6557
6358
|
if (!parser) return joinSources(file);
|
|
6558
6359
|
return parser.parse(file, { extname: parseExtName });
|
|
6559
6360
|
}
|
|
6560
|
-
|
|
6561
|
-
await (onStart == null ? void 0 : onStart(files));
|
|
6361
|
+
*stream(files, options = {}) {
|
|
6562
6362
|
const total = files.length;
|
|
6363
|
+
if (total === 0) return;
|
|
6563
6364
|
let processed = 0;
|
|
6564
|
-
const
|
|
6565
|
-
const source =
|
|
6566
|
-
|
|
6567
|
-
|
|
6568
|
-
});
|
|
6569
|
-
const currentProcessed = ++processed;
|
|
6570
|
-
const percentage = currentProcessed / total * 100;
|
|
6571
|
-
await (onUpdate == null ? void 0 : onUpdate({
|
|
6365
|
+
for (const file of files) {
|
|
6366
|
+
const source = this.parse(file, options);
|
|
6367
|
+
processed++;
|
|
6368
|
+
yield {
|
|
6572
6369
|
file,
|
|
6573
6370
|
source,
|
|
6574
|
-
processed
|
|
6575
|
-
|
|
6576
|
-
total
|
|
6577
|
-
}
|
|
6578
|
-
}
|
|
6579
|
-
if (mode === "sequential") for (const file of files) await processOne(file);
|
|
6580
|
-
else await Promise.all(files.map((file) => __privateGet(this, _limit).call(this, () => processOne(file))));
|
|
6581
|
-
await (onEnd == null ? void 0 : onEnd(files));
|
|
6582
|
-
return files;
|
|
6371
|
+
processed,
|
|
6372
|
+
total,
|
|
6373
|
+
percentage: processed / total * 100
|
|
6374
|
+
};
|
|
6375
|
+
}
|
|
6583
6376
|
}
|
|
6584
|
-
|
|
6585
|
-
|
|
6586
|
-
|
|
6587
|
-
|
|
6588
|
-
|
|
6589
|
-
|
|
6590
|
-
|
|
6377
|
+
async run(files, options = {}) {
|
|
6378
|
+
await this.events.emit("start", files);
|
|
6379
|
+
for (const { file, source, processed, total, percentage } of this.stream(files, options)) await this.events.emit("update", {
|
|
6380
|
+
file,
|
|
6381
|
+
source,
|
|
6382
|
+
processed,
|
|
6383
|
+
percentage,
|
|
6384
|
+
total
|
|
6385
|
+
});
|
|
6386
|
+
await this.events.emit("end", files);
|
|
6387
|
+
return files;
|
|
6388
|
+
}
|
|
6389
|
+
};
|
|
6591
6390
|
const fsStorage = createStorage(() => ({
|
|
6592
6391
|
name: "fs",
|
|
6593
6392
|
async hasItem(key) {
|
|
6594
6393
|
try {
|
|
6595
6394
|
await access(resolve(key));
|
|
6596
6395
|
return true;
|
|
6597
|
-
} catch (
|
|
6598
|
-
|
|
6599
|
-
throw new Error(`Failed to access storage item "${key}"`, { cause: error });
|
|
6396
|
+
} catch (_error) {
|
|
6397
|
+
return false;
|
|
6600
6398
|
}
|
|
6601
6399
|
},
|
|
6602
6400
|
async getItem(key) {
|
|
6603
6401
|
try {
|
|
6604
6402
|
return await readFile$1(resolve(key), "utf8");
|
|
6605
|
-
} catch (
|
|
6606
|
-
|
|
6607
|
-
throw new Error(`Failed to read storage item "${key}"`, { cause: error });
|
|
6403
|
+
} catch (_error) {
|
|
6404
|
+
return null;
|
|
6608
6405
|
}
|
|
6609
6406
|
},
|
|
6610
6407
|
async setItem(key, value) {
|
|
@@ -6614,23 +6411,22 @@ const fsStorage = createStorage(() => ({
|
|
|
6614
6411
|
await rm(resolve(key), { force: true });
|
|
6615
6412
|
},
|
|
6616
6413
|
async getKeys(base) {
|
|
6617
|
-
const keys = [];
|
|
6618
6414
|
const resolvedBase = resolve(base != null ? base : process.cwd());
|
|
6619
|
-
async function
|
|
6415
|
+
async function* walk(dir, prefix) {
|
|
6620
6416
|
let entries;
|
|
6621
6417
|
try {
|
|
6622
6418
|
entries = await readdir$1(dir, { withFileTypes: true });
|
|
6623
|
-
} catch (
|
|
6624
|
-
|
|
6625
|
-
throw new Error(`Failed to list storage keys under "${resolvedBase}"`, { cause: error });
|
|
6419
|
+
} catch (_error) {
|
|
6420
|
+
return;
|
|
6626
6421
|
}
|
|
6627
6422
|
for (const entry of entries) {
|
|
6628
6423
|
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
6629
|
-
if (entry.isDirectory())
|
|
6630
|
-
else
|
|
6424
|
+
if (entry.isDirectory()) yield* walk(join(dir, entry.name), rel);
|
|
6425
|
+
else yield rel;
|
|
6631
6426
|
}
|
|
6632
6427
|
}
|
|
6633
|
-
|
|
6428
|
+
const keys = [];
|
|
6429
|
+
for await (const key of walk(resolvedBase, "")) keys.push(key);
|
|
6634
6430
|
return keys;
|
|
6635
6431
|
},
|
|
6636
6432
|
async clear(base) {
|
|
@@ -6638,37 +6434,131 @@ const fsStorage = createStorage(() => ({
|
|
|
6638
6434
|
await clean(resolve(base));
|
|
6639
6435
|
}
|
|
6640
6436
|
}));
|
|
6641
|
-
|
|
6642
|
-
function
|
|
6437
|
+
function _usingCtx() {
|
|
6438
|
+
var r = "function" == typeof SuppressedError ? SuppressedError : function(r2, e2) {
|
|
6439
|
+
var n2 = Error();
|
|
6440
|
+
return n2.name = "SuppressedError", n2.error = r2, n2.suppressed = e2, n2;
|
|
6441
|
+
};
|
|
6442
|
+
var e = {};
|
|
6443
|
+
var n = [];
|
|
6444
|
+
function using(r2, e2) {
|
|
6445
|
+
if (null != e2) {
|
|
6446
|
+
if (Object(e2) !== e2) throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
|
|
6447
|
+
if (r2) var o = e2[Symbol.asyncDispose || Symbol["for"]("Symbol.asyncDispose")];
|
|
6448
|
+
if (void 0 === o && (o = e2[Symbol.dispose || Symbol["for"]("Symbol.dispose")], r2)) var t = o;
|
|
6449
|
+
if ("function" != typeof o) throw new TypeError("Object is not disposable.");
|
|
6450
|
+
t && (o = function o2() {
|
|
6451
|
+
try {
|
|
6452
|
+
t.call(e2);
|
|
6453
|
+
} catch (r3) {
|
|
6454
|
+
return Promise.reject(r3);
|
|
6455
|
+
}
|
|
6456
|
+
}), n.push({
|
|
6457
|
+
v: e2,
|
|
6458
|
+
d: o,
|
|
6459
|
+
a: r2
|
|
6460
|
+
});
|
|
6461
|
+
} else r2 && n.push({
|
|
6462
|
+
d: e2,
|
|
6463
|
+
a: r2
|
|
6464
|
+
});
|
|
6465
|
+
return e2;
|
|
6466
|
+
}
|
|
6643
6467
|
return {
|
|
6644
|
-
|
|
6645
|
-
|
|
6646
|
-
|
|
6647
|
-
|
|
6648
|
-
|
|
6468
|
+
e,
|
|
6469
|
+
u: using.bind(null, false),
|
|
6470
|
+
a: using.bind(null, true),
|
|
6471
|
+
d: function d() {
|
|
6472
|
+
var o;
|
|
6473
|
+
var t = this.e;
|
|
6474
|
+
var s = 0;
|
|
6475
|
+
function next() {
|
|
6476
|
+
for (; o = n.pop(); ) try {
|
|
6477
|
+
if (!o.a && 1 === s) return s = 0, n.push(o), Promise.resolve().then(next);
|
|
6478
|
+
if (o.d) {
|
|
6479
|
+
var r2 = o.d.call(o.v);
|
|
6480
|
+
if (o.a) return s |= 2, Promise.resolve(r2).then(next, err);
|
|
6481
|
+
} else s |= 1;
|
|
6482
|
+
} catch (r3) {
|
|
6483
|
+
return err(r3);
|
|
6484
|
+
}
|
|
6485
|
+
if (1 === s) return t !== e ? Promise.reject(t) : Promise.resolve();
|
|
6486
|
+
if (t !== e) throw t;
|
|
6487
|
+
}
|
|
6488
|
+
function err(n2) {
|
|
6489
|
+
return t = t !== e ? new r(n2, t) : n2, next();
|
|
6490
|
+
}
|
|
6491
|
+
return next();
|
|
6492
|
+
}
|
|
6649
6493
|
};
|
|
6650
6494
|
}
|
|
6651
|
-
function
|
|
6652
|
-
|
|
6495
|
+
function createSourcesView(storage) {
|
|
6496
|
+
const paths = /* @__PURE__ */ new Set();
|
|
6497
|
+
return createStorage(() => ({
|
|
6498
|
+
name: `${storage.name}:sources`,
|
|
6499
|
+
async hasItem(key) {
|
|
6500
|
+
return paths.has(key) && await storage.hasItem(key);
|
|
6501
|
+
},
|
|
6502
|
+
async getItem(key) {
|
|
6503
|
+
return paths.has(key) ? storage.getItem(key) : null;
|
|
6504
|
+
},
|
|
6505
|
+
async setItem(key, value) {
|
|
6506
|
+
paths.add(key);
|
|
6507
|
+
await storage.setItem(key, value);
|
|
6508
|
+
},
|
|
6509
|
+
async removeItem(key) {
|
|
6510
|
+
paths.delete(key);
|
|
6511
|
+
await storage.removeItem(key);
|
|
6512
|
+
},
|
|
6513
|
+
async getKeys(base) {
|
|
6514
|
+
if (!base) return [...paths];
|
|
6515
|
+
const result = [];
|
|
6516
|
+
for (const key of paths) if (key.startsWith(base)) result.push(key);
|
|
6517
|
+
return result;
|
|
6518
|
+
},
|
|
6519
|
+
async clear() {
|
|
6520
|
+
paths.clear();
|
|
6521
|
+
await storage.clear();
|
|
6522
|
+
}
|
|
6523
|
+
}))();
|
|
6653
6524
|
}
|
|
6654
6525
|
async function setup(userConfig, options = {}) {
|
|
6655
|
-
var _a2,
|
|
6526
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
6656
6527
|
const hooks = (_a2 = options.hooks) != null ? _a2 : new AsyncEventEmitter();
|
|
6657
|
-
const
|
|
6528
|
+
const config = {
|
|
6529
|
+
...userConfig,
|
|
6530
|
+
root: userConfig.root || process.cwd(),
|
|
6531
|
+
parsers: (_b = userConfig.parsers) != null ? _b : [],
|
|
6532
|
+
output: {
|
|
6533
|
+
format: false,
|
|
6534
|
+
lint: false,
|
|
6535
|
+
extension: DEFAULT_EXTENSION,
|
|
6536
|
+
defaultBanner: DEFAULT_BANNER,
|
|
6537
|
+
...userConfig.output
|
|
6538
|
+
},
|
|
6539
|
+
storage: (_c = userConfig.storage) != null ? _c : fsStorage(),
|
|
6540
|
+
devtools: userConfig.devtools ? {
|
|
6541
|
+
studioUrl: DEFAULT_STUDIO_URL,
|
|
6542
|
+
...typeof userConfig.devtools === "boolean" ? {} : userConfig.devtools
|
|
6543
|
+
} : void 0,
|
|
6544
|
+
plugins: (_d = userConfig.plugins) != null ? _d : []
|
|
6545
|
+
};
|
|
6546
|
+
const driver = new KubbDriver(config, { hooks });
|
|
6547
|
+
const storage = createSourcesView(config.storage);
|
|
6658
6548
|
const diagnosticInfo = getDiagnosticInfo();
|
|
6659
|
-
if (Array.isArray(userConfig.input)) await hooks.emit("kubb:warn", { message: "This feature is still under development \u2014 use with caution" });
|
|
6660
6549
|
await hooks.emit("kubb:debug", {
|
|
6661
6550
|
date: /* @__PURE__ */ new Date(),
|
|
6662
6551
|
logs: [
|
|
6663
6552
|
"Configuration:",
|
|
6664
6553
|
` \u2022 Name: ${userConfig.name || "unnamed"}`,
|
|
6665
6554
|
` \u2022 Root: ${userConfig.root || process.cwd()}`,
|
|
6666
|
-
` \u2022 Output: ${((
|
|
6667
|
-
` \u2022 Plugins: ${((
|
|
6555
|
+
` \u2022 Output: ${((_e = userConfig.output) == null ? void 0 : _e.path) || "not specified"}`,
|
|
6556
|
+
` \u2022 Plugins: ${((_f = userConfig.plugins) == null ? void 0 : _f.length) || 0}`,
|
|
6668
6557
|
"Output Settings:",
|
|
6669
|
-
` \u2022 Storage: ${
|
|
6670
|
-
` \u2022 Formatter: ${((
|
|
6671
|
-
` \u2022 Linter: ${((
|
|
6558
|
+
` \u2022 Storage: ${config.storage.name}`,
|
|
6559
|
+
` \u2022 Formatter: ${((_g = userConfig.output) == null ? void 0 : _g.format) || "none"}`,
|
|
6560
|
+
` \u2022 Linter: ${((_h = userConfig.output) == null ? void 0 : _h.lint) || "none"}`,
|
|
6561
|
+
`Running adapter: ${((_i = config.adapter) == null ? void 0 : _i.name) || "none"}`,
|
|
6672
6562
|
"Environment:",
|
|
6673
6563
|
Object.entries(diagnosticInfo).map(([key, value]) => ` \u2022 ${key}: ${value}`).join("\n")
|
|
6674
6564
|
]
|
|
@@ -6687,181 +6577,303 @@ async function setup(userConfig, options = {}) {
|
|
|
6687
6577
|
throw new Error(`Cannot read file/URL defined in \`input.path\` or set with \`kubb generate PATH\` in the CLI of your Kubb config ${userConfig.input.path}`, { cause: error });
|
|
6688
6578
|
}
|
|
6689
6579
|
}
|
|
6690
|
-
if (!userConfig.adapter) throw new Error("Adapter should be defined");
|
|
6691
|
-
const config = {
|
|
6692
|
-
...userConfig,
|
|
6693
|
-
root: userConfig.root || process.cwd(),
|
|
6694
|
-
parsers: (_g = userConfig.parsers) != null ? _g : [],
|
|
6695
|
-
adapter: userConfig.adapter,
|
|
6696
|
-
output: {
|
|
6697
|
-
format: false,
|
|
6698
|
-
lint: false,
|
|
6699
|
-
write: true,
|
|
6700
|
-
extension: DEFAULT_EXTENSION,
|
|
6701
|
-
defaultBanner: DEFAULT_BANNER,
|
|
6702
|
-
...userConfig.output
|
|
6703
|
-
},
|
|
6704
|
-
devtools: userConfig.devtools ? {
|
|
6705
|
-
studioUrl: DEFAULT_STUDIO_URL,
|
|
6706
|
-
...typeof userConfig.devtools === "boolean" ? {} : userConfig.devtools
|
|
6707
|
-
} : void 0,
|
|
6708
|
-
plugins: userConfig.plugins
|
|
6709
|
-
};
|
|
6710
|
-
const storage = config.output.write === false ? null : (_h = config.storage) != null ? _h : fsStorage();
|
|
6711
6580
|
if (config.output.clean) {
|
|
6712
6581
|
await hooks.emit("kubb:debug", {
|
|
6713
6582
|
date: /* @__PURE__ */ new Date(),
|
|
6714
6583
|
logs: ["Cleaning output directories", ` \u2022 Output: ${config.output.path}`]
|
|
6715
6584
|
});
|
|
6716
|
-
await
|
|
6585
|
+
await config.storage.clear(resolve(config.root, config.output.path));
|
|
6717
6586
|
}
|
|
6718
|
-
|
|
6719
|
-
function registerMiddlewareHook(event, middlewareHooks) {
|
|
6720
|
-
const handler = middlewareHooks[event];
|
|
6721
|
-
if (handler) hooks.on(event, handler);
|
|
6722
|
-
}
|
|
6723
|
-
for (const middleware of (_i = config.middleware) != null ? _i : []) for (const event of Object.keys(middleware.hooks)) registerMiddlewareHook(event, middleware.hooks);
|
|
6724
|
-
const adapter = config.adapter;
|
|
6725
|
-
if (!adapter) throw new Error("No adapter configured. Please provide an adapter in your kubb.config.ts.");
|
|
6726
|
-
const source = inputToAdapterSource(config);
|
|
6727
|
-
await hooks.emit("kubb:debug", {
|
|
6728
|
-
date: /* @__PURE__ */ new Date(),
|
|
6729
|
-
logs: [`Running adapter: ${adapter.name}`]
|
|
6730
|
-
});
|
|
6731
|
-
driver.adapter = adapter;
|
|
6732
|
-
driver.inputNode = await adapter.parse(source);
|
|
6733
|
-
await hooks.emit("kubb:debug", {
|
|
6734
|
-
date: /* @__PURE__ */ new Date(),
|
|
6735
|
-
logs: [
|
|
6736
|
-
`\u2713 Adapter '${adapter.name}' resolved InputNode`,
|
|
6737
|
-
` \u2022 Schemas: ${driver.inputNode.schemas.length}`,
|
|
6738
|
-
` \u2022 Operations: ${driver.inputNode.operations.length}`
|
|
6739
|
-
]
|
|
6740
|
-
});
|
|
6587
|
+
await driver.setup();
|
|
6741
6588
|
return {
|
|
6742
6589
|
config,
|
|
6743
6590
|
hooks,
|
|
6744
6591
|
driver,
|
|
6745
|
-
|
|
6746
|
-
|
|
6592
|
+
storage,
|
|
6593
|
+
dispose,
|
|
6594
|
+
[Symbol.dispose]: dispose
|
|
6747
6595
|
};
|
|
6596
|
+
function dispose() {
|
|
6597
|
+
driver.dispose();
|
|
6598
|
+
}
|
|
6748
6599
|
}
|
|
6749
|
-
async function
|
|
6750
|
-
var _a2
|
|
6751
|
-
|
|
6752
|
-
|
|
6753
|
-
|
|
6754
|
-
|
|
6755
|
-
|
|
6756
|
-
|
|
6757
|
-
|
|
6758
|
-
|
|
6759
|
-
|
|
6760
|
-
|
|
6761
|
-
|
|
6762
|
-
|
|
6763
|
-
|
|
6764
|
-
|
|
6765
|
-
|
|
6766
|
-
|
|
6767
|
-
|
|
6768
|
-
"method",
|
|
6769
|
-
"contentType"
|
|
6770
|
-
]);
|
|
6771
|
-
const hasOperationBasedIncludes = (_b2 = include == null ? void 0 : include.some(({ type }) => operationFilterTypes.has(type))) != null ? _b2 : false;
|
|
6772
|
-
const hasSchemaNameIncludes = (_c2 = include == null ? void 0 : include.some(({ type }) => type === "schemaName")) != null ? _c2 : false;
|
|
6773
|
-
let allowedSchemaNames;
|
|
6774
|
-
if (hasOperationBasedIncludes && !hasSchemaNameIncludes) allowedSchemaNames = collectUsedSchemaNames(inputNode.operations.filter((op) => resolver.resolveOptions(op, {
|
|
6775
|
-
options: plugin.options,
|
|
6776
|
-
exclude,
|
|
6777
|
-
include,
|
|
6778
|
-
override
|
|
6779
|
-
}) !== null), inputNode.schemas);
|
|
6780
|
-
await walk(inputNode, {
|
|
6781
|
-
depth: "shallow",
|
|
6782
|
-
async schema(node) {
|
|
6783
|
-
const transformedNode = plugin.transformer ? transform(node, plugin.transformer) : node;
|
|
6784
|
-
if (allowedSchemaNames !== void 0 && transformedNode.name && !allowedSchemaNames.has(transformedNode.name)) return;
|
|
6785
|
-
const options = resolver.resolveOptions(transformedNode, {
|
|
6786
|
-
options: plugin.options,
|
|
6787
|
-
exclude,
|
|
6788
|
-
include,
|
|
6789
|
-
override
|
|
6600
|
+
async function safeBuild(setupResult) {
|
|
6601
|
+
var _a2;
|
|
6602
|
+
try {
|
|
6603
|
+
var _usingCtx$1 = _usingCtx();
|
|
6604
|
+
_usingCtx$1.u(setupResult);
|
|
6605
|
+
const { driver, hooks, storage } = setupResult;
|
|
6606
|
+
const failedPlugins = /* @__PURE__ */ new Set();
|
|
6607
|
+
const pluginTimings = /* @__PURE__ */ new Map();
|
|
6608
|
+
const config = driver.config;
|
|
6609
|
+
const writtenPaths = /* @__PURE__ */ new Set();
|
|
6610
|
+
const parsersMap = /* @__PURE__ */ new Map();
|
|
6611
|
+
const fileProcessor = new FileProcessor();
|
|
6612
|
+
for (const parser of config.parsers) if (parser.extNames) for (const extname of parser.extNames) parsersMap.set(extname, parser);
|
|
6613
|
+
async function flushPendingFiles() {
|
|
6614
|
+
const files = driver.fileManager.files.filter((f) => !writtenPaths.has(f.path));
|
|
6615
|
+
if (files.length === 0) return;
|
|
6616
|
+
await hooks.emit("kubb:debug", {
|
|
6617
|
+
date: /* @__PURE__ */ new Date(),
|
|
6618
|
+
logs: [`Writing ${files.length} files...`]
|
|
6790
6619
|
});
|
|
6791
|
-
|
|
6792
|
-
const
|
|
6793
|
-
|
|
6794
|
-
|
|
6795
|
-
};
|
|
6796
|
-
|
|
6797
|
-
|
|
6798
|
-
|
|
6620
|
+
await hooks.emit("kubb:files:processing:start", { files });
|
|
6621
|
+
const stream = fileProcessor.stream(files, {
|
|
6622
|
+
parsers: parsersMap,
|
|
6623
|
+
extension: config.output.extension
|
|
6624
|
+
});
|
|
6625
|
+
const queue = [];
|
|
6626
|
+
for (const { file, source, processed, total, percentage } of stream) {
|
|
6627
|
+
writtenPaths.add(file.path);
|
|
6628
|
+
queue.push((async () => {
|
|
6629
|
+
await hooks.emit("kubb:file:processing:update", {
|
|
6630
|
+
file,
|
|
6631
|
+
source,
|
|
6632
|
+
processed,
|
|
6633
|
+
total,
|
|
6634
|
+
percentage,
|
|
6635
|
+
config
|
|
6636
|
+
});
|
|
6637
|
+
if (source) await storage.setItem(file.path, source);
|
|
6638
|
+
})());
|
|
6639
|
+
if (queue.length >= 50) await Promise.all(queue.splice(0));
|
|
6799
6640
|
}
|
|
6800
|
-
await
|
|
6801
|
-
|
|
6802
|
-
|
|
6803
|
-
|
|
6804
|
-
|
|
6805
|
-
options: plugin.options,
|
|
6806
|
-
exclude,
|
|
6807
|
-
include,
|
|
6808
|
-
override
|
|
6641
|
+
await Promise.all(queue);
|
|
6642
|
+
await hooks.emit("kubb:files:processing:end", { files });
|
|
6643
|
+
await hooks.emit("kubb:debug", {
|
|
6644
|
+
date: /* @__PURE__ */ new Date(),
|
|
6645
|
+
logs: [`\u2713 File write process completed for ${files.length} files`]
|
|
6809
6646
|
});
|
|
6810
|
-
|
|
6811
|
-
|
|
6812
|
-
|
|
6813
|
-
|
|
6814
|
-
|
|
6647
|
+
}
|
|
6648
|
+
async function dispatchOperationsToGenerators(generators, collectedOperations, ctx, rendererFor) {
|
|
6649
|
+
for (const gen of generators) {
|
|
6650
|
+
if (!gen.operations) continue;
|
|
6651
|
+
await applyHookResult({
|
|
6652
|
+
result: await gen.operations(collectedOperations, ctx),
|
|
6653
|
+
driver,
|
|
6654
|
+
rendererFactory: rendererFor(gen)
|
|
6655
|
+
});
|
|
6656
|
+
}
|
|
6657
|
+
await driver.hooks.emit("kubb:generate:operations", collectedOperations, ctx);
|
|
6658
|
+
}
|
|
6659
|
+
async function runPlugins(entries) {
|
|
6660
|
+
var _a3, _b;
|
|
6661
|
+
const { schemas, operations } = driver.inputNode;
|
|
6662
|
+
const operationFilterTypes = /* @__PURE__ */ new Set([
|
|
6663
|
+
"tag",
|
|
6664
|
+
"operationId",
|
|
6665
|
+
"path",
|
|
6666
|
+
"method",
|
|
6667
|
+
"contentType"
|
|
6668
|
+
]);
|
|
6669
|
+
const states = entries.map(({ plugin, context, hrStart }) => {
|
|
6670
|
+
var _a4;
|
|
6671
|
+
const { exclude, include, override } = plugin.options;
|
|
6672
|
+
const hasExclude = Array.isArray(exclude) && exclude.length > 0;
|
|
6673
|
+
const hasInclude = Array.isArray(include) && include.length > 0;
|
|
6674
|
+
const hasOverride = Array.isArray(override) && override.length > 0;
|
|
6675
|
+
return {
|
|
6676
|
+
plugin,
|
|
6677
|
+
generatorContext: {
|
|
6678
|
+
...context,
|
|
6679
|
+
resolver: driver.getResolver(plugin.name)
|
|
6680
|
+
},
|
|
6681
|
+
generators: (_a4 = plugin.generators) != null ? _a4 : [],
|
|
6682
|
+
hrStart,
|
|
6683
|
+
failed: false,
|
|
6684
|
+
error: void 0,
|
|
6685
|
+
optionsAreStatic: !hasExclude && !hasInclude && !hasOverride,
|
|
6686
|
+
allowedSchemaNames: void 0
|
|
6815
6687
|
};
|
|
6816
|
-
|
|
6817
|
-
|
|
6818
|
-
|
|
6688
|
+
});
|
|
6689
|
+
const pruningStates = states.filter(({ plugin }) => {
|
|
6690
|
+
var _a4, _b2;
|
|
6691
|
+
const { include } = plugin.options;
|
|
6692
|
+
return ((_a4 = include == null ? void 0 : include.some(({ type }) => operationFilterTypes.has(type))) != null ? _a4 : false) && !((_b2 = include == null ? void 0 : include.some(({ type }) => type === "schemaName")) != null ? _b2 : false);
|
|
6693
|
+
});
|
|
6694
|
+
if (pruningStates.length > 0) {
|
|
6695
|
+
const allSchemas = [];
|
|
6696
|
+
for await (const schema of schemas) allSchemas.push(schema);
|
|
6697
|
+
const includedOpsByState = new Map(pruningStates.map((s) => [s, []]));
|
|
6698
|
+
for await (const operation of operations) for (const state of pruningStates) {
|
|
6699
|
+
const { exclude, include, override } = state.plugin.options;
|
|
6700
|
+
if (state.generatorContext.resolver.resolveOptions(operation, {
|
|
6701
|
+
options: state.plugin.options,
|
|
6702
|
+
exclude,
|
|
6703
|
+
include,
|
|
6704
|
+
override
|
|
6705
|
+
}) !== null) (_a3 = includedOpsByState.get(state)) == null ? void 0 : _a3.push(operation);
|
|
6706
|
+
}
|
|
6707
|
+
for (const state of pruningStates) state.allowedSchemaNames = collectUsedSchemaNames((_b = includedOpsByState.get(state)) != null ? _b : [], allSchemas);
|
|
6708
|
+
}
|
|
6709
|
+
function resolveRendererFor(gen, state) {
|
|
6710
|
+
var _a4, _b2;
|
|
6711
|
+
return gen.renderer === null ? void 0 : (_b2 = (_a4 = gen.renderer) != null ? _a4 : state.plugin.renderer) != null ? _b2 : state.generatorContext.config.renderer;
|
|
6712
|
+
}
|
|
6713
|
+
async function dispatchSchema(state, node) {
|
|
6714
|
+
if (state.failed) return;
|
|
6715
|
+
try {
|
|
6716
|
+
const { plugin, generatorContext, generators } = state;
|
|
6717
|
+
const transformedNode = plugin.transformer ? transform(node, plugin.transformer) : node;
|
|
6718
|
+
if (state.allowedSchemaNames !== void 0 && transformedNode.name && !state.allowedSchemaNames.has(transformedNode.name)) return;
|
|
6719
|
+
const { exclude, include, override } = plugin.options;
|
|
6720
|
+
const options = state.optionsAreStatic ? plugin.options : generatorContext.resolver.resolveOptions(transformedNode, {
|
|
6721
|
+
options: plugin.options,
|
|
6722
|
+
exclude,
|
|
6723
|
+
include,
|
|
6724
|
+
override
|
|
6725
|
+
});
|
|
6726
|
+
if (options === null) return;
|
|
6727
|
+
const ctx = {
|
|
6728
|
+
...generatorContext,
|
|
6729
|
+
options
|
|
6730
|
+
};
|
|
6731
|
+
for (const gen of generators) {
|
|
6732
|
+
if (!gen.schema) continue;
|
|
6733
|
+
const raw = gen.schema(transformedNode, ctx);
|
|
6734
|
+
const applied = applyHookResult({
|
|
6735
|
+
result: isPromise(raw) ? await raw : raw,
|
|
6736
|
+
driver,
|
|
6737
|
+
rendererFactory: resolveRendererFor(gen, state)
|
|
6738
|
+
});
|
|
6739
|
+
if (isPromise(applied)) await applied;
|
|
6740
|
+
}
|
|
6741
|
+
await driver.hooks.emit("kubb:generate:schema", transformedNode, ctx);
|
|
6742
|
+
} catch (caughtError) {
|
|
6743
|
+
state.failed = true;
|
|
6744
|
+
state.error = caughtError;
|
|
6819
6745
|
}
|
|
6820
|
-
await driver.hooks.emit("kubb:generate:operation", transformedNode, ctx);
|
|
6821
6746
|
}
|
|
6822
|
-
|
|
6823
|
-
|
|
6824
|
-
|
|
6825
|
-
|
|
6826
|
-
|
|
6827
|
-
|
|
6828
|
-
|
|
6829
|
-
|
|
6830
|
-
|
|
6831
|
-
|
|
6832
|
-
|
|
6833
|
-
|
|
6834
|
-
|
|
6835
|
-
|
|
6836
|
-
|
|
6837
|
-
|
|
6838
|
-
|
|
6839
|
-
|
|
6840
|
-
|
|
6841
|
-
|
|
6842
|
-
|
|
6843
|
-
|
|
6844
|
-
|
|
6845
|
-
|
|
6846
|
-
|
|
6847
|
-
|
|
6848
|
-
|
|
6849
|
-
|
|
6850
|
-
|
|
6851
|
-
|
|
6852
|
-
|
|
6853
|
-
|
|
6854
|
-
|
|
6855
|
-
|
|
6856
|
-
|
|
6857
|
-
|
|
6858
|
-
|
|
6859
|
-
|
|
6860
|
-
|
|
6861
|
-
|
|
6862
|
-
|
|
6747
|
+
async function dispatchOperation(state, node) {
|
|
6748
|
+
if (state.failed) return;
|
|
6749
|
+
try {
|
|
6750
|
+
const { plugin, generatorContext, generators } = state;
|
|
6751
|
+
const transformedNode = plugin.transformer ? transform(node, plugin.transformer) : node;
|
|
6752
|
+
const { exclude, include, override } = plugin.options;
|
|
6753
|
+
const options = state.optionsAreStatic ? plugin.options : generatorContext.resolver.resolveOptions(transformedNode, {
|
|
6754
|
+
options: plugin.options,
|
|
6755
|
+
exclude,
|
|
6756
|
+
include,
|
|
6757
|
+
override
|
|
6758
|
+
});
|
|
6759
|
+
if (options === null) return;
|
|
6760
|
+
const ctx = {
|
|
6761
|
+
...generatorContext,
|
|
6762
|
+
options
|
|
6763
|
+
};
|
|
6764
|
+
for (const gen of generators) {
|
|
6765
|
+
if (!gen.operation) continue;
|
|
6766
|
+
const raw = gen.operation(transformedNode, ctx);
|
|
6767
|
+
const applied = applyHookResult({
|
|
6768
|
+
result: isPromise(raw) ? await raw : raw,
|
|
6769
|
+
driver,
|
|
6770
|
+
rendererFactory: resolveRendererFor(gen, state)
|
|
6771
|
+
});
|
|
6772
|
+
if (isPromise(applied)) await applied;
|
|
6773
|
+
}
|
|
6774
|
+
await driver.hooks.emit("kubb:generate:operation", transformedNode, ctx);
|
|
6775
|
+
} catch (caughtError) {
|
|
6776
|
+
state.failed = true;
|
|
6777
|
+
state.error = caughtError;
|
|
6778
|
+
}
|
|
6779
|
+
}
|
|
6780
|
+
await forBatches(schemas, (nodes) => Promise.all(nodes.flatMap((n) => states.map((state) => dispatchSchema(state, n)))), {
|
|
6781
|
+
concurrency: 8,
|
|
6782
|
+
flush: flushPendingFiles
|
|
6783
|
+
});
|
|
6784
|
+
const collectedOperations = [];
|
|
6785
|
+
await forBatches(operations, (nodes) => {
|
|
6786
|
+
collectedOperations.push(...nodes);
|
|
6787
|
+
return Promise.all(nodes.flatMap((n) => states.map((state) => dispatchOperation(state, n))));
|
|
6788
|
+
}, {
|
|
6789
|
+
concurrency: 8,
|
|
6790
|
+
flush: flushPendingFiles
|
|
6791
|
+
});
|
|
6792
|
+
for (const state of states) {
|
|
6793
|
+
if (!state.failed) try {
|
|
6794
|
+
const { plugin, generatorContext, generators } = state;
|
|
6795
|
+
await dispatchOperationsToGenerators(generators, collectedOperations, {
|
|
6796
|
+
...generatorContext,
|
|
6797
|
+
options: plugin.options
|
|
6798
|
+
}, (gen) => resolveRendererFor(gen, state));
|
|
6799
|
+
} catch (caughtError) {
|
|
6800
|
+
state.failed = true;
|
|
6801
|
+
state.error = caughtError;
|
|
6802
|
+
}
|
|
6803
|
+
const duration = getElapsedMs(state.hrStart);
|
|
6804
|
+
pluginTimings.set(state.plugin.name, duration);
|
|
6805
|
+
await driver.hooks.emit("kubb:plugin:end", {
|
|
6806
|
+
plugin: state.plugin,
|
|
6807
|
+
duration,
|
|
6808
|
+
success: !state.failed,
|
|
6809
|
+
...state.failed && state.error ? { error: state.error } : {},
|
|
6810
|
+
config: driver.config,
|
|
6811
|
+
get files() {
|
|
6812
|
+
return driver.fileManager.files;
|
|
6813
|
+
},
|
|
6814
|
+
upsertFile: (...files) => driver.fileManager.upsert(...files)
|
|
6815
|
+
});
|
|
6816
|
+
if (state.failed && state.error) failedPlugins.add({
|
|
6817
|
+
plugin: state.plugin,
|
|
6818
|
+
error: state.error
|
|
6819
|
+
});
|
|
6820
|
+
await driver.hooks.emit("kubb:debug", {
|
|
6821
|
+
date: /* @__PURE__ */ new Date(),
|
|
6822
|
+
logs: [state.failed ? "\u2717 Plugin start failed" : `\u2713 Plugin started successfully (${formatMs(duration)})`]
|
|
6863
6823
|
});
|
|
6864
|
-
|
|
6824
|
+
}
|
|
6825
|
+
}
|
|
6826
|
+
try {
|
|
6827
|
+
await driver.emitSetupHooks();
|
|
6828
|
+
if (driver.adapter && driver.inputNode) await hooks.emit("kubb:build:start", {
|
|
6829
|
+
config,
|
|
6830
|
+
adapter: driver.adapter,
|
|
6831
|
+
meta: driver.inputNode.meta,
|
|
6832
|
+
getPlugin: driver.getPlugin.bind(driver),
|
|
6833
|
+
get files() {
|
|
6834
|
+
return driver.fileManager.files;
|
|
6835
|
+
},
|
|
6836
|
+
upsertFile: (...files2) => driver.fileManager.upsert(...files2)
|
|
6837
|
+
});
|
|
6838
|
+
const generatorPlugins = [];
|
|
6839
|
+
for (const plugin of driver.plugins.values()) {
|
|
6840
|
+
const context = driver.getContext(plugin);
|
|
6841
|
+
const hrStart = process.hrtime();
|
|
6842
|
+
try {
|
|
6843
|
+
await hooks.emit("kubb:plugin:start", { plugin });
|
|
6844
|
+
await hooks.emit("kubb:debug", {
|
|
6845
|
+
date: /* @__PURE__ */ new Date(),
|
|
6846
|
+
logs: ["Starting plugin...", ` \u2022 Plugin Name: ${plugin.name}`]
|
|
6847
|
+
});
|
|
6848
|
+
} catch (caughtError) {
|
|
6849
|
+
const error = caughtError;
|
|
6850
|
+
const duration2 = getElapsedMs(hrStart);
|
|
6851
|
+
pluginTimings.set(plugin.name, duration2);
|
|
6852
|
+
await hooks.emit("kubb:plugin:end", {
|
|
6853
|
+
plugin,
|
|
6854
|
+
duration: duration2,
|
|
6855
|
+
success: false,
|
|
6856
|
+
error,
|
|
6857
|
+
config,
|
|
6858
|
+
get files() {
|
|
6859
|
+
return driver.fileManager.files;
|
|
6860
|
+
},
|
|
6861
|
+
upsertFile: (...files2) => driver.fileManager.upsert(...files2)
|
|
6862
|
+
});
|
|
6863
|
+
failedPlugins.add({
|
|
6864
|
+
plugin,
|
|
6865
|
+
error
|
|
6866
|
+
});
|
|
6867
|
+
continue;
|
|
6868
|
+
}
|
|
6869
|
+
if (((_a2 = plugin.generators) == null ? void 0 : _a2.length) || driver.hasEventGenerators(plugin.name)) {
|
|
6870
|
+
generatorPlugins.push({
|
|
6871
|
+
plugin,
|
|
6872
|
+
context,
|
|
6873
|
+
hrStart
|
|
6874
|
+
});
|
|
6875
|
+
continue;
|
|
6876
|
+
}
|
|
6865
6877
|
const duration = getElapsedMs(hrStart);
|
|
6866
6878
|
pluginTimings.set(plugin.name, duration);
|
|
6867
6879
|
await hooks.emit("kubb:plugin:end", {
|
|
@@ -6878,107 +6890,61 @@ async function safeBuild(setupResult) {
|
|
|
6878
6890
|
date: /* @__PURE__ */ new Date(),
|
|
6879
6891
|
logs: [`\u2713 Plugin started successfully (${formatMs(duration)})`]
|
|
6880
6892
|
});
|
|
6881
|
-
}
|
|
6882
|
-
|
|
6883
|
-
|
|
6893
|
+
}
|
|
6894
|
+
if (generatorPlugins.length > 0) if (driver.inputNode) await withDrain(() => runPlugins(generatorPlugins), flushPendingFiles);
|
|
6895
|
+
else for (const { plugin, hrStart } of generatorPlugins) {
|
|
6884
6896
|
const duration = getElapsedMs(hrStart);
|
|
6897
|
+
pluginTimings.set(plugin.name, duration);
|
|
6885
6898
|
await hooks.emit("kubb:plugin:end", {
|
|
6886
6899
|
plugin,
|
|
6887
6900
|
duration,
|
|
6888
|
-
success:
|
|
6889
|
-
error,
|
|
6901
|
+
success: true,
|
|
6890
6902
|
config,
|
|
6891
6903
|
get files() {
|
|
6892
6904
|
return driver.fileManager.files;
|
|
6893
6905
|
},
|
|
6894
6906
|
upsertFile: (...files2) => driver.fileManager.upsert(...files2)
|
|
6895
6907
|
});
|
|
6896
|
-
await hooks.emit("kubb:debug", {
|
|
6897
|
-
date: errorTimestamp,
|
|
6898
|
-
logs: [
|
|
6899
|
-
"\u2717 Plugin start failed",
|
|
6900
|
-
` \u2022 Plugin Name: ${plugin.name}`,
|
|
6901
|
-
` \u2022 Error: ${error.constructor.name} - ${error.message}`,
|
|
6902
|
-
" \u2022 Stack Trace:",
|
|
6903
|
-
error.stack || "No stack trace available"
|
|
6904
|
-
]
|
|
6905
|
-
});
|
|
6906
|
-
failedPlugins.add({
|
|
6907
|
-
plugin,
|
|
6908
|
-
error
|
|
6909
|
-
});
|
|
6910
6908
|
}
|
|
6909
|
+
await hooks.emit("kubb:plugins:end", {
|
|
6910
|
+
config,
|
|
6911
|
+
get files() {
|
|
6912
|
+
return driver.fileManager.files;
|
|
6913
|
+
},
|
|
6914
|
+
upsertFile: (...files2) => driver.fileManager.upsert(...files2)
|
|
6915
|
+
});
|
|
6916
|
+
await flushPendingFiles();
|
|
6917
|
+
const files = driver.fileManager.files;
|
|
6918
|
+
await hooks.emit("kubb:build:end", {
|
|
6919
|
+
files,
|
|
6920
|
+
config,
|
|
6921
|
+
outputDir: resolve(config.root, config.output.path)
|
|
6922
|
+
});
|
|
6923
|
+
return {
|
|
6924
|
+
failedPlugins,
|
|
6925
|
+
files,
|
|
6926
|
+
driver,
|
|
6927
|
+
pluginTimings,
|
|
6928
|
+
storage
|
|
6929
|
+
};
|
|
6930
|
+
} catch (error) {
|
|
6931
|
+
return {
|
|
6932
|
+
failedPlugins,
|
|
6933
|
+
files: [],
|
|
6934
|
+
driver,
|
|
6935
|
+
pluginTimings,
|
|
6936
|
+
error,
|
|
6937
|
+
storage
|
|
6938
|
+
};
|
|
6911
6939
|
}
|
|
6912
|
-
|
|
6913
|
-
|
|
6914
|
-
get files() {
|
|
6915
|
-
return driver.fileManager.files;
|
|
6916
|
-
},
|
|
6917
|
-
upsertFile: (...files2) => driver.fileManager.upsert(...files2)
|
|
6918
|
-
});
|
|
6919
|
-
const files = driver.fileManager.files;
|
|
6920
|
-
const parsersMap = /* @__PURE__ */ new Map();
|
|
6921
|
-
for (const parser of config.parsers) if (parser.extNames) for (const extname of parser.extNames) parsersMap.set(extname, parser);
|
|
6922
|
-
const fileProcessor = new FileProcessor();
|
|
6923
|
-
await hooks.emit("kubb:debug", {
|
|
6924
|
-
date: /* @__PURE__ */ new Date(),
|
|
6925
|
-
logs: [`Writing ${files.length} files...`]
|
|
6926
|
-
});
|
|
6927
|
-
await fileProcessor.run(files, {
|
|
6928
|
-
parsers: parsersMap,
|
|
6929
|
-
extension: config.output.extension,
|
|
6930
|
-
onStart: async (processingFiles) => {
|
|
6931
|
-
await hooks.emit("kubb:files:processing:start", { files: processingFiles });
|
|
6932
|
-
},
|
|
6933
|
-
onUpdate: async ({ file, source, processed, total, percentage }) => {
|
|
6934
|
-
await hooks.emit("kubb:file:processing:update", {
|
|
6935
|
-
file,
|
|
6936
|
-
source,
|
|
6937
|
-
processed,
|
|
6938
|
-
total,
|
|
6939
|
-
percentage,
|
|
6940
|
-
config
|
|
6941
|
-
});
|
|
6942
|
-
if (source) {
|
|
6943
|
-
await (storage == null ? void 0 : storage.setItem(file.path, source));
|
|
6944
|
-
sources.set(file.path, source);
|
|
6945
|
-
}
|
|
6946
|
-
},
|
|
6947
|
-
onEnd: async (processedFiles) => {
|
|
6948
|
-
await hooks.emit("kubb:files:processing:end", { files: processedFiles });
|
|
6949
|
-
await hooks.emit("kubb:debug", {
|
|
6950
|
-
date: /* @__PURE__ */ new Date(),
|
|
6951
|
-
logs: [`\u2713 File write process completed for ${processedFiles.length} files`]
|
|
6952
|
-
});
|
|
6953
|
-
}
|
|
6954
|
-
});
|
|
6955
|
-
await hooks.emit("kubb:build:end", {
|
|
6956
|
-
files,
|
|
6957
|
-
config,
|
|
6958
|
-
outputDir: resolve(config.root, config.output.path)
|
|
6959
|
-
});
|
|
6960
|
-
return {
|
|
6961
|
-
failedPlugins,
|
|
6962
|
-
files,
|
|
6963
|
-
driver,
|
|
6964
|
-
pluginTimings,
|
|
6965
|
-
sources
|
|
6966
|
-
};
|
|
6967
|
-
} catch (error) {
|
|
6968
|
-
return {
|
|
6969
|
-
failedPlugins,
|
|
6970
|
-
files: [],
|
|
6971
|
-
driver,
|
|
6972
|
-
pluginTimings,
|
|
6973
|
-
error,
|
|
6974
|
-
sources
|
|
6975
|
-
};
|
|
6940
|
+
} catch (_) {
|
|
6941
|
+
_usingCtx$1.e = _;
|
|
6976
6942
|
} finally {
|
|
6977
|
-
|
|
6943
|
+
_usingCtx$1.d();
|
|
6978
6944
|
}
|
|
6979
6945
|
}
|
|
6980
6946
|
async function build(setupResult) {
|
|
6981
|
-
const { files, driver, failedPlugins, pluginTimings, error,
|
|
6947
|
+
const { files, driver, failedPlugins, pluginTimings, error, storage } = await safeBuild(setupResult);
|
|
6982
6948
|
if (error) throw error;
|
|
6983
6949
|
if (failedPlugins.size > 0) {
|
|
6984
6950
|
const errors = [...failedPlugins].map(({ error: error2 }) => error2);
|
|
@@ -6990,27 +6956,21 @@ async function build(setupResult) {
|
|
|
6990
6956
|
driver,
|
|
6991
6957
|
pluginTimings,
|
|
6992
6958
|
error: void 0,
|
|
6993
|
-
|
|
6959
|
+
storage
|
|
6994
6960
|
};
|
|
6995
6961
|
}
|
|
6996
|
-
function
|
|
6997
|
-
if (Array.isArray(config.input)) return {
|
|
6998
|
-
type: "paths",
|
|
6999
|
-
paths: config.input.map((i) => new URLPath(i.path).isURL ? i.path : resolve(config.root, i.path))
|
|
7000
|
-
};
|
|
7001
|
-
if ("data" in config.input) return {
|
|
7002
|
-
type: "data",
|
|
7003
|
-
data: config.input.data
|
|
7004
|
-
};
|
|
7005
|
-
if (new URLPath(config.input.path).isURL) return {
|
|
7006
|
-
type: "path",
|
|
7007
|
-
path: config.input.path
|
|
7008
|
-
};
|
|
6962
|
+
function getDiagnosticInfo() {
|
|
7009
6963
|
return {
|
|
7010
|
-
|
|
7011
|
-
|
|
6964
|
+
nodeVersion: version$2,
|
|
6965
|
+
KubbVersion: version$1,
|
|
6966
|
+
platform: process.platform,
|
|
6967
|
+
arch: process.arch,
|
|
6968
|
+
cwd: process.cwd()
|
|
7012
6969
|
};
|
|
7013
6970
|
}
|
|
6971
|
+
function isInputPath(config) {
|
|
6972
|
+
return typeof (config == null ? void 0 : config.input) === "object" && config.input !== null && "path" in config.input;
|
|
6973
|
+
}
|
|
7014
6974
|
function createKubb(userConfig, options = {}) {
|
|
7015
6975
|
var _a2;
|
|
7016
6976
|
const hooks = (_a2 = options.hooks) != null ? _a2 : new AsyncEventEmitter();
|
|
@@ -7019,15 +6979,17 @@ function createKubb(userConfig, options = {}) {
|
|
|
7019
6979
|
get hooks() {
|
|
7020
6980
|
return hooks;
|
|
7021
6981
|
},
|
|
7022
|
-
get
|
|
7023
|
-
|
|
7024
|
-
return
|
|
6982
|
+
get storage() {
|
|
6983
|
+
if (!setupResult) throw new Error("[kubb] setup() must be called before accessing storage");
|
|
6984
|
+
return setupResult.storage;
|
|
7025
6985
|
},
|
|
7026
6986
|
get driver() {
|
|
7027
|
-
|
|
6987
|
+
if (!setupResult) throw new Error("[kubb] setup() must be called before accessing driver");
|
|
6988
|
+
return setupResult.driver;
|
|
7028
6989
|
},
|
|
7029
6990
|
get config() {
|
|
7030
|
-
|
|
6991
|
+
if (!setupResult) throw new Error("[kubb] setup() must be called before accessing config");
|
|
6992
|
+
return setupResult.config;
|
|
7031
6993
|
},
|
|
7032
6994
|
async setup() {
|
|
7033
6995
|
setupResult = await setup(userConfig, { hooks });
|
|
@@ -7074,7 +7036,7 @@ const memoryStorage = createStorage(() => {
|
|
|
7074
7036
|
};
|
|
7075
7037
|
});
|
|
7076
7038
|
|
|
7077
|
-
var version = "5.0.0-beta.
|
|
7039
|
+
var version = "5.0.0-beta.20";
|
|
7078
7040
|
|
|
7079
7041
|
function isCommandMessage(msg) {
|
|
7080
7042
|
return msg.type === "command";
|
|
@@ -7085,9 +7047,6 @@ function isPongMessage(msg) {
|
|
|
7085
7047
|
function isDisconnectMessage(msg) {
|
|
7086
7048
|
return msg.type === "disconnect";
|
|
7087
7049
|
}
|
|
7088
|
-
function isPublishCommandMessage(msg) {
|
|
7089
|
-
return msg.type === "command" && msg.command === "publish";
|
|
7090
|
-
}
|
|
7091
7050
|
|
|
7092
7051
|
function getStorage() {
|
|
7093
7052
|
return useStorage("kubb");
|
|
@@ -7131,7 +7090,7 @@ async function generate({ config, hooks }) {
|
|
|
7131
7090
|
const kubb = createKubb(config, { hooks });
|
|
7132
7091
|
await kubb.setup();
|
|
7133
7092
|
await hooks.emit("kubb:info", { message: config.name ? `Build generation ${config.name}` : "Build generation" });
|
|
7134
|
-
const {
|
|
7093
|
+
const { failedPlugins, error } = await kubb.safeBuild();
|
|
7135
7094
|
await hooks.emit("kubb:info", { message: "Load summary" });
|
|
7136
7095
|
const hasFailures = failedPlugins.size > 0 || error;
|
|
7137
7096
|
if (hasFailures) {
|
|
@@ -7142,11 +7101,11 @@ async function generate({ config, hooks }) {
|
|
|
7142
7101
|
allErrors.forEach((err) => {
|
|
7143
7102
|
hooks.emit("kubb:error", { error: err });
|
|
7144
7103
|
});
|
|
7145
|
-
await hooks.emit("kubb:generation:end", { config,
|
|
7104
|
+
await hooks.emit("kubb:generation:end", { config, storage: kubb.storage });
|
|
7146
7105
|
throw new Error("Generation failed");
|
|
7147
7106
|
}
|
|
7148
7107
|
await hooks.emit("kubb:success", { message: "Generation successfully" });
|
|
7149
|
-
await hooks.emit("kubb:generation:end", { config,
|
|
7108
|
+
await hooks.emit("kubb:generation:end", { config, storage: kubb.storage });
|
|
7150
7109
|
if (config.output.format) {
|
|
7151
7110
|
await hooks.emit("kubb:format:start");
|
|
7152
7111
|
let formatter = config.output.format;
|
|
@@ -7221,20 +7180,15 @@ async function generate({ config, hooks }) {
|
|
|
7221
7180
|
}
|
|
7222
7181
|
}
|
|
7223
7182
|
|
|
7224
|
-
const
|
|
7225
|
-
|
|
7226
|
-
|
|
7227
|
-
|
|
7228
|
-
|
|
7229
|
-
|
|
7230
|
-
|
|
7231
|
-
};
|
|
7183
|
+
const jiti = createJiti(globalThis._importMeta_.url, {
|
|
7184
|
+
jsx: {
|
|
7185
|
+
runtime: "automatic",
|
|
7186
|
+
importSource: "@kubb/renderer-jsx"
|
|
7187
|
+
},
|
|
7188
|
+
moduleCache: false
|
|
7189
|
+
});
|
|
7232
7190
|
const tsLoader = async (configFile) => {
|
|
7233
|
-
|
|
7234
|
-
path: configFile,
|
|
7235
|
-
inputOptions: unrunInputOptions
|
|
7236
|
-
});
|
|
7237
|
-
return module;
|
|
7191
|
+
return jiti.import(configFile, { default: true });
|
|
7238
7192
|
};
|
|
7239
7193
|
async function getCosmiConfig(configPath) {
|
|
7240
7194
|
var _a;
|
|
@@ -7295,6 +7249,21 @@ async function resolvePlugins(plugins) {
|
|
|
7295
7249
|
})
|
|
7296
7250
|
);
|
|
7297
7251
|
}
|
|
7252
|
+
async function resolveMiddlewares(middlewares) {
|
|
7253
|
+
return Promise.all(
|
|
7254
|
+
middlewares.map(async ({ name, options }) => {
|
|
7255
|
+
const factory = await loadPluginFactory(name);
|
|
7256
|
+
return factory(options != null ? options : {});
|
|
7257
|
+
})
|
|
7258
|
+
);
|
|
7259
|
+
}
|
|
7260
|
+
async function checkPeerDependencies() {
|
|
7261
|
+
try {
|
|
7262
|
+
await import('@kubb/renderer-jsx');
|
|
7263
|
+
} catch {
|
|
7264
|
+
logger.warn("Missing peer dependency @kubb/renderer-jsx. Install it alongside kubb plugins.");
|
|
7265
|
+
}
|
|
7266
|
+
}
|
|
7298
7267
|
|
|
7299
7268
|
async function mergePlugins(diskPlugins, studioPlugins) {
|
|
7300
7269
|
if (!diskPlugins && !studioPlugins) return void 0;
|
|
@@ -7323,44 +7292,6 @@ async function mergePlugins(diskPlugins, studioPlugins) {
|
|
|
7323
7292
|
return [...mergedDisk, ...studioOnly];
|
|
7324
7293
|
}
|
|
7325
7294
|
|
|
7326
|
-
async function publish({ command, outputPath, root, hooks }) {
|
|
7327
|
-
var _a, _b, _c, _d;
|
|
7328
|
-
const resolvedOutputPath = path$1.isAbsolute(outputPath) ? outputPath : path$1.resolve(root, outputPath);
|
|
7329
|
-
const [cmd, ...args] = tokenize(command);
|
|
7330
|
-
if (!cmd) {
|
|
7331
|
-
throw new Error(`[plugin-publish] Invalid publish command: "${command}"`);
|
|
7332
|
-
}
|
|
7333
|
-
const commandWithArgs = args.length ? `${cmd} ${args.join(" ")}` : cmd;
|
|
7334
|
-
await hooks.emit("kubb:info", { message: `[publish] Running "${commandWithArgs}" in "${resolvedOutputPath}"` });
|
|
7335
|
-
const startTime = Date.now();
|
|
7336
|
-
let exitCode = null;
|
|
7337
|
-
try {
|
|
7338
|
-
const proc = x(cmd, args, {
|
|
7339
|
-
nodeOptions: { cwd: resolvedOutputPath }
|
|
7340
|
-
});
|
|
7341
|
-
for await (const line of proc) {
|
|
7342
|
-
if (line.trim()) {
|
|
7343
|
-
await hooks.emit("kubb:info", { message: line.trim() });
|
|
7344
|
-
}
|
|
7345
|
-
}
|
|
7346
|
-
const result = await proc;
|
|
7347
|
-
exitCode = (_a = result.exitCode) != null ? _a : null;
|
|
7348
|
-
} catch (err) {
|
|
7349
|
-
const message = (_d = (_c = (_b = err == null ? void 0 : err.stderr) == null ? void 0 : _b.trim()) != null ? _c : err == null ? void 0 : err.message) != null ? _d : String(err);
|
|
7350
|
-
const error = new Error(`[publish] Failed to run "${commandWithArgs}": ${message}`);
|
|
7351
|
-
error.cause = err;
|
|
7352
|
-
await hooks.emit("kubb:error", { error });
|
|
7353
|
-
throw error;
|
|
7354
|
-
}
|
|
7355
|
-
if (exitCode !== 0) {
|
|
7356
|
-
const error = new Error(`[publish] "${commandWithArgs}" exited with code ${exitCode}`);
|
|
7357
|
-
await hooks.emit("kubb:error", { error });
|
|
7358
|
-
throw error;
|
|
7359
|
-
}
|
|
7360
|
-
const duration = Date.now() - startTime;
|
|
7361
|
-
await hooks.emit("kubb:success", { message: `[publish] Published successfully in ${duration}ms` });
|
|
7362
|
-
}
|
|
7363
|
-
|
|
7364
7295
|
function setupHookListener(hooks, root) {
|
|
7365
7296
|
hooks.on("kubb:hook:start", async (ctx) => {
|
|
7366
7297
|
const { id, command, args } = ctx;
|
|
@@ -7396,7 +7327,7 @@ function setupHookListener(hooks, root) {
|
|
|
7396
7327
|
}
|
|
7397
7328
|
|
|
7398
7329
|
const agentDefaults = {
|
|
7399
|
-
studioUrl: "https://
|
|
7330
|
+
studioUrl: "https://kubb.studio",
|
|
7400
7331
|
configPath: "kubb.config.ts",
|
|
7401
7332
|
retryIntervalMs: 3e4,
|
|
7402
7333
|
heartbeatIntervalMs: 3e4,
|
|
@@ -7431,24 +7362,24 @@ function sendAgentMessage(ws, message) {
|
|
|
7431
7362
|
throw new Error("Failed to send message to Kubb Studio", { cause: error });
|
|
7432
7363
|
}
|
|
7433
7364
|
}
|
|
7434
|
-
function setupEventsStream(ws, hooks
|
|
7365
|
+
function setupEventsStream(ws, hooks) {
|
|
7435
7366
|
function sendDataMessage(payload) {
|
|
7436
7367
|
sendAgentMessage(ws, {
|
|
7437
7368
|
type: "data",
|
|
7438
|
-
payload
|
|
7369
|
+
payload
|
|
7439
7370
|
});
|
|
7440
7371
|
}
|
|
7441
7372
|
hooks.on("kubb:plugin:start", (ctx) => {
|
|
7442
7373
|
sendDataMessage({
|
|
7443
7374
|
type: "kubb:plugin:start",
|
|
7444
|
-
data: [ctx.plugin],
|
|
7375
|
+
data: [{ plugin: ctx.plugin }],
|
|
7445
7376
|
timestamp: Date.now()
|
|
7446
7377
|
});
|
|
7447
7378
|
});
|
|
7448
7379
|
hooks.on("kubb:plugin:end", (ctx) => {
|
|
7449
7380
|
sendDataMessage({
|
|
7450
7381
|
type: "kubb:plugin:end",
|
|
7451
|
-
data: [ctx.plugin,
|
|
7382
|
+
data: [{ plugin: ctx.plugin, duration: ctx.duration, success: ctx.success }],
|
|
7452
7383
|
timestamp: Date.now()
|
|
7453
7384
|
});
|
|
7454
7385
|
});
|
|
@@ -7483,21 +7414,21 @@ function setupEventsStream(ws, hooks, getSource) {
|
|
|
7483
7414
|
hooks.on("kubb:info", ({ message, info }) => {
|
|
7484
7415
|
sendDataMessage({
|
|
7485
7416
|
type: "kubb:info",
|
|
7486
|
-
data: [message, info],
|
|
7417
|
+
data: [{ message, info }],
|
|
7487
7418
|
timestamp: Date.now()
|
|
7488
7419
|
});
|
|
7489
7420
|
});
|
|
7490
7421
|
hooks.on("kubb:success", ({ message, info }) => {
|
|
7491
7422
|
sendDataMessage({
|
|
7492
7423
|
type: "kubb:success",
|
|
7493
|
-
data: [message, info],
|
|
7424
|
+
data: [{ message, info }],
|
|
7494
7425
|
timestamp: Date.now()
|
|
7495
7426
|
});
|
|
7496
7427
|
});
|
|
7497
7428
|
hooks.on("kubb:warn", ({ message, info }) => {
|
|
7498
7429
|
sendDataMessage({
|
|
7499
7430
|
type: "kubb:warn",
|
|
7500
|
-
data: [message, info],
|
|
7431
|
+
data: [{ message, info }],
|
|
7501
7432
|
timestamp: Date.now()
|
|
7502
7433
|
});
|
|
7503
7434
|
});
|
|
@@ -7513,14 +7444,17 @@ function setupEventsStream(ws, hooks, getSource) {
|
|
|
7513
7444
|
timestamp: Date.now()
|
|
7514
7445
|
});
|
|
7515
7446
|
});
|
|
7516
|
-
hooks.on("kubb:generation:end", ({ config,
|
|
7447
|
+
hooks.on("kubb:generation:end", async ({ config, storage }) => {
|
|
7517
7448
|
const sourcesRecord = {};
|
|
7518
|
-
|
|
7519
|
-
|
|
7520
|
-
|
|
7449
|
+
for (const key of await storage.getKeys()) {
|
|
7450
|
+
const value = await storage.getItem(key);
|
|
7451
|
+
if (value !== null) {
|
|
7452
|
+
sourcesRecord[key] = value;
|
|
7453
|
+
}
|
|
7454
|
+
}
|
|
7521
7455
|
sendDataMessage({
|
|
7522
7456
|
type: "kubb:generation:end",
|
|
7523
|
-
data: [config,
|
|
7457
|
+
data: [{ config, storage: sourcesRecord }],
|
|
7524
7458
|
timestamp: Date.now()
|
|
7525
7459
|
});
|
|
7526
7460
|
});
|
|
@@ -7547,7 +7481,6 @@ async function connectToStudio(options) {
|
|
|
7547
7481
|
resolvedConfigPath,
|
|
7548
7482
|
allowAll,
|
|
7549
7483
|
allowWrite,
|
|
7550
|
-
allowPublish,
|
|
7551
7484
|
root,
|
|
7552
7485
|
retryInterval,
|
|
7553
7486
|
heartbeatInterval = 3e4,
|
|
@@ -7555,7 +7488,6 @@ async function connectToStudio(options) {
|
|
|
7555
7488
|
nitro
|
|
7556
7489
|
} = options;
|
|
7557
7490
|
const hooks = new AsyncEventEmitter();
|
|
7558
|
-
let currentSource;
|
|
7559
7491
|
async function reconnect() {
|
|
7560
7492
|
logger.info(`Retrying connection in ${formatMs$1(retryInterval)} to Kubb Studio ...`);
|
|
7561
7493
|
setTimeout(() => connectToStudio({ ...options, initialSession: void 0 }), retryInterval);
|
|
@@ -7570,7 +7502,6 @@ async function connectToStudio(options) {
|
|
|
7570
7502
|
const maskedSessionId = maskString(sessionId);
|
|
7571
7503
|
const effectiveAllowAll = isSandbox ? false : allowAll;
|
|
7572
7504
|
const effectiveWrite = isSandbox ? false : allowWrite;
|
|
7573
|
-
const effectivePublish = isSandbox ? false : allowPublish;
|
|
7574
7505
|
let serverDisconnected = false;
|
|
7575
7506
|
let heartbeatTimer;
|
|
7576
7507
|
async function cleanup(reason = "cleanup") {
|
|
@@ -7582,6 +7513,7 @@ async function connectToStudio(options) {
|
|
|
7582
7513
|
ws.removeEventListener("open", onOpen);
|
|
7583
7514
|
ws.removeEventListener("close", onClose);
|
|
7584
7515
|
ws.removeEventListener("error", onError);
|
|
7516
|
+
ws.removeEventListener("message", onMessage);
|
|
7585
7517
|
} catch (_error) {
|
|
7586
7518
|
}
|
|
7587
7519
|
}
|
|
@@ -7614,9 +7546,9 @@ async function connectToStudio(options) {
|
|
|
7614
7546
|
});
|
|
7615
7547
|
});
|
|
7616
7548
|
heartbeatTimer = setInterval(() => sendAgentMessage(ws, { type: "ping" }), heartbeatInterval);
|
|
7617
|
-
setupEventsStream(ws, hooks
|
|
7618
|
-
|
|
7619
|
-
var _a2, _b, _c, _d
|
|
7549
|
+
setupEventsStream(ws, hooks);
|
|
7550
|
+
const onMessage = async (message) => {
|
|
7551
|
+
var _a2, _b, _c, _d;
|
|
7620
7552
|
try {
|
|
7621
7553
|
const data = JSON.parse(message.data);
|
|
7622
7554
|
logger.info(`[${maskedSessionId}] Received "${data.type}" from Studio`);
|
|
@@ -7638,11 +7570,11 @@ async function connectToStudio(options) {
|
|
|
7638
7570
|
}
|
|
7639
7571
|
if (isCommandMessage(data)) {
|
|
7640
7572
|
if (data.command === "generate") {
|
|
7641
|
-
currentSource = "generate";
|
|
7642
7573
|
const config = await loadConfig(resolvedConfigPath);
|
|
7643
7574
|
const storedConfig = data.payload ? null : await getLatestStudioConfigFromStorage({ sessionId }).catch(() => null);
|
|
7644
7575
|
const patch = (_b = (_a2 = data.payload) != null ? _a2 : storedConfig) != null ? _b : void 0;
|
|
7645
7576
|
const plugins = await mergePlugins(config.plugins, patch == null ? void 0 : patch.plugins);
|
|
7577
|
+
const middleware = (patch == null ? void 0 : patch.middleware) ? await resolveMiddlewares(patch.middleware) : config.middleware;
|
|
7646
7578
|
const inputOverride = isSandbox ? { data: (_c = patch == null ? void 0 : patch.input) != null ? _c : "" } : void 0;
|
|
7647
7579
|
if (allowWrite && isSandbox) {
|
|
7648
7580
|
logger.warn(`[${maskedSessionId}] Agent is running in a sandbox environment, write will be disabled`);
|
|
@@ -7658,6 +7590,9 @@ async function connectToStudio(options) {
|
|
|
7658
7590
|
logger.warn(`[${maskedSessionId}] Failed to save studio config: ${err == null ? void 0 : err.message}`);
|
|
7659
7591
|
});
|
|
7660
7592
|
}
|
|
7593
|
+
const generationHooks = new AsyncEventEmitter();
|
|
7594
|
+
setupHookListener(generationHooks, root);
|
|
7595
|
+
setupEventsStream(ws, generationHooks);
|
|
7661
7596
|
await generate({
|
|
7662
7597
|
config: {
|
|
7663
7598
|
...config,
|
|
@@ -7667,12 +7602,15 @@ async function connectToStudio(options) {
|
|
|
7667
7602
|
output: {
|
|
7668
7603
|
...config.output
|
|
7669
7604
|
},
|
|
7670
|
-
plugins
|
|
7605
|
+
plugins,
|
|
7606
|
+
middleware,
|
|
7607
|
+
// Studio may send an opaque adapter options blob; forward it unchanged to createKubb.
|
|
7608
|
+
// The adapter factory is responsible for validating and merging its own options.
|
|
7609
|
+
...(patch == null ? void 0 : patch.adapter) != null && { adapter: patch.adapter }
|
|
7671
7610
|
},
|
|
7672
|
-
hooks
|
|
7611
|
+
hooks: generationHooks
|
|
7673
7612
|
});
|
|
7674
7613
|
logger.success(`[${maskedSessionId}] Completed "${data.type}" from Studio`);
|
|
7675
|
-
currentSource = void 0;
|
|
7676
7614
|
return;
|
|
7677
7615
|
}
|
|
7678
7616
|
if (data.command === "connect") {
|
|
@@ -7684,8 +7622,7 @@ async function connectToStudio(options) {
|
|
|
7684
7622
|
configPath,
|
|
7685
7623
|
permissions: {
|
|
7686
7624
|
allowAll: effectiveAllowAll,
|
|
7687
|
-
allowWrite: effectiveWrite
|
|
7688
|
-
allowPublish: effectivePublish
|
|
7625
|
+
allowWrite: effectiveWrite
|
|
7689
7626
|
},
|
|
7690
7627
|
config: {
|
|
7691
7628
|
plugins: config.plugins.map((plugin) => ({
|
|
@@ -7698,30 +7635,13 @@ async function connectToStudio(options) {
|
|
|
7698
7635
|
logger.success(`[${maskedSessionId}] Completed "${data.type}" from Studio`);
|
|
7699
7636
|
return;
|
|
7700
7637
|
}
|
|
7701
|
-
if (isPublishCommandMessage(data)) {
|
|
7702
|
-
if (!effectivePublish) {
|
|
7703
|
-
logger.warn(`[${maskedSessionId}] Publish command rejected \u2014 KUBB_AGENT_ALLOW_PUBLISH is not enabled`);
|
|
7704
|
-
return;
|
|
7705
|
-
}
|
|
7706
|
-
currentSource = "publish";
|
|
7707
|
-
const config = await loadConfig(resolvedConfigPath);
|
|
7708
|
-
const resolvedCommand = (_e = (_d = data.payload.command) != null ? _d : process.env.KUBB_AGENT_PUBLISH_COMMAND) != null ? _e : "npm publish";
|
|
7709
|
-
await publish({
|
|
7710
|
-
command: resolvedCommand,
|
|
7711
|
-
outputPath: config.output.path,
|
|
7712
|
-
root,
|
|
7713
|
-
hooks
|
|
7714
|
-
});
|
|
7715
|
-
logger.success(`[${maskedSessionId}] Completed "${data.command}" from Studio`);
|
|
7716
|
-
currentSource = void 0;
|
|
7717
|
-
return;
|
|
7718
|
-
}
|
|
7719
7638
|
}
|
|
7720
7639
|
logger.warn(`[${maskedSessionId}] Unknown message type from Kubb Studio: ${message.data}`);
|
|
7721
7640
|
} catch (error) {
|
|
7722
|
-
logger.error(`[${maskedSessionId}] [unhandledRejection] ${(
|
|
7641
|
+
logger.error(`[${maskedSessionId}] [unhandledRejection] ${(_d = error == null ? void 0 : error.message) != null ? _d : error}`);
|
|
7723
7642
|
}
|
|
7724
|
-
}
|
|
7643
|
+
};
|
|
7644
|
+
ws.addEventListener("message", onMessage);
|
|
7725
7645
|
} catch (error) {
|
|
7726
7646
|
throw new Error(`[unhandledRejection] ${(_a = error == null ? void 0 : error.message) != null ? _a : error}`, {
|
|
7727
7647
|
cause: error
|
|
@@ -7751,7 +7671,6 @@ function resolveStudioRuntimeConfig(env = process$1.env, cwd = process$1.cwd())
|
|
|
7751
7671
|
root,
|
|
7752
7672
|
allowAll,
|
|
7753
7673
|
allowWrite: allowAll || parseBooleanEnv(env.KUBB_AGENT_ALLOW_WRITE),
|
|
7754
|
-
allowPublish: allowAll || parseBooleanEnv(env.KUBB_AGENT_ALLOW_PUBLISH),
|
|
7755
7674
|
poolSize: parsePositiveIntegerEnv(env.KUBB_AGENT_POOL_SIZE, agentDefaults.poolSize),
|
|
7756
7675
|
hasSecret: Boolean(env.KUBB_AGENT_SECRET)
|
|
7757
7676
|
};
|
|
@@ -7761,7 +7680,7 @@ function getErrorMessage(error) {
|
|
|
7761
7680
|
return error instanceof Error ? error.message : String(error);
|
|
7762
7681
|
}
|
|
7763
7682
|
const _zcw7I4pYH8OiCfaDcjy_x7I6IH1tLDQR3W_yRZgP6E = defineNitroPlugin(async (nitro) => {
|
|
7764
|
-
const { studioUrl, token, configPath, resolvedConfigPath, retryInterval, heartbeatInterval, root, allowAll, allowWrite,
|
|
7683
|
+
const { studioUrl, token, configPath, resolvedConfigPath, retryInterval, heartbeatInterval, root, allowAll, allowWrite, poolSize, hasSecret } = resolveStudioRuntimeConfig(process$1.env);
|
|
7765
7684
|
if (!token) {
|
|
7766
7685
|
logger.warn("KUBB_AGENT_TOKEN not set", "cannot authenticate with studio");
|
|
7767
7686
|
return null;
|
|
@@ -7771,6 +7690,7 @@ const _zcw7I4pYH8OiCfaDcjy_x7I6IH1tLDQR3W_yRZgP6E = defineNitroPlugin(async (nit
|
|
|
7771
7690
|
}
|
|
7772
7691
|
const maskedToken = maskString(token);
|
|
7773
7692
|
try {
|
|
7693
|
+
await checkPeerDependencies();
|
|
7774
7694
|
await registerAgent({ token, studioUrl, poolSize });
|
|
7775
7695
|
const baseOptions = {
|
|
7776
7696
|
token,
|
|
@@ -7779,7 +7699,6 @@ const _zcw7I4pYH8OiCfaDcjy_x7I6IH1tLDQR3W_yRZgP6E = defineNitroPlugin(async (nit
|
|
|
7779
7699
|
resolvedConfigPath,
|
|
7780
7700
|
allowAll,
|
|
7781
7701
|
allowWrite,
|
|
7782
|
-
allowPublish,
|
|
7783
7702
|
root,
|
|
7784
7703
|
retryInterval,
|
|
7785
7704
|
heartbeatInterval,
|