@vite-hub/env 0.5.1 → 0.6.0

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.
@@ -742,7 +742,7 @@ async function callOperation(target, name, input) {
742
742
  const url = new URL(operationRpcPath.slice(1), base);
743
743
  origin = url.origin;
744
744
  const env = target.roots?.length ? {} : target.env;
745
- try {
745
+ if (!target.authorization) try {
746
746
  readConsoleSigningKey(env);
747
747
  } catch (error) {
748
748
  return {
@@ -754,15 +754,18 @@ async function callOperation(target, name, input) {
754
754
  };
755
755
  }
756
756
  const outcome = await callOperationRpc(name, input ?? {}, async (body) => {
757
- const headers = await signedOperationHeaders(env, url, body);
757
+ const signal = target.signal ?? AbortSignal.timeout(target.timeout ?? 3e4);
758
+ const headers = target.authorization ? operationHeaders() : await signedOperationHeaders(env, url, body);
759
+ if (target.authorization) headers.set("authorization", target.authorization);
758
760
  if (target.confirmed !== void 0) headers.set(operationConfirmationHeader, target.confirmed ? "confirmed" : "required");
759
761
  if (target.roots?.length) headers.set(operationExpectedRootsHeader, target.roots.map(projectRootHash).join(","));
762
+ signal.throwIfAborted();
760
763
  const response = await (target.fetch ?? fetch)(url.href, {
761
764
  body,
762
765
  headers,
763
766
  method: "POST",
764
767
  redirect: "manual",
765
- signal: AbortSignal.timeout(target.timeout ?? 3e4)
768
+ signal
766
769
  });
767
770
  const text = await response.text();
768
771
  let json;
@@ -799,7 +802,7 @@ async function callOperation(target, name, input) {
799
802
  } : void 0);
800
803
  if (failure) {
801
804
  if (target.roots?.length && failure.status === 401) failure.fix = `Pass --url ${base.href.slice(0, -1)} to send credentials. A command sends none to the dev server that it finds. ${failure.fix ?? "Set VITEHUB_CONSOLE_PRIVATE_KEY_<NAME> to a private key that `vitehub secret console-key` printed, and its public key in VITEHUB_CONSOLE_KEY_<NAME> on the app."}`;
802
- if ((failure.status === 401 || failure.status === 403) && !hasCredentials(env) && !failure.fix) failure.fix = target.roots?.length ? `Pass --url <origin> to send deployment credentials. ${operationCredentialHint}` : operationCredentialHint;
805
+ if ((failure.status === 401 || failure.status === 403) && !target.authorization && !hasCredentials(env) && !failure.fix) failure.fix = target.roots?.length ? `Pass --url <origin> to send deployment credentials. ${operationCredentialHint}` : operationCredentialHint;
803
806
  return {
804
807
  ok: false,
805
808
  ...failure
package/dist/cli.js CHANGED
@@ -1 +1 @@
1
- export { t as createEnvCliContributor, n as secretCliFeatures } from "./cli-CAlHK5nn.js";
1
+ export { t as createEnvCliContributor, n as secretCliFeatures } from "./cli-BXzUIcnA.js";
@@ -1,687 +1,6 @@
1
1
  import { a as isRecordOrFunction, n as standardJsonSchema, t as internalErrorDiagnostics } from "./error-diagnostics-5BceFRdD.js";
2
2
  import * as v from "valibot";
3
- // ../../node_modules/.pnpm/@valibot+to-json-schema@1.8.0_valibot@1.5.0_typescript@6.0.3_/node_modules/@valibot/to-json-schema/dist/index.mjs
4
- /**
5
- * Adds an error message to the errors array.
6
- *
7
- * @param errors The array of error messages.
8
- * @param message The error message to add.
9
- *
10
- * @returns The new errors.
11
- */
12
- function addError(errors, message) {
13
- if (errors) {
14
- errors.push(message);
15
- return errors;
16
- }
17
- return [message];
18
- }
19
- const ESCAPE_REGEX = /[.*+?^${}()|[\]\\]/g;
20
- /**
21
- * Escapes special regex characters in a string.
22
- *
23
- * @param string The string to escape.
24
- *
25
- * @returns The escaped string.
26
- */
27
- function escapeRegExp(string) {
28
- return string.replace(ESCAPE_REGEX, "\\$&");
29
- }
30
- /**
31
- * Throws an error or logs a warning based on the configuration.
32
- *
33
- * @param message The message to throw or log.
34
- * @param config The conversion configuration.
35
- */
36
- function handleError(message, config) {
37
- switch (config?.errorMode) {
38
- case "ignore": break;
39
- case "warn":
40
- console.warn(message);
41
- break;
42
- default: throw new Error(message);
43
- }
44
- }
45
- /**
46
- * Whether a value is JSON compatible for a const keyword.
47
- *
48
- * @param value The value to check.
49
- *
50
- * @returns Whether the value is JSON compatible.
51
- */
52
- function isJsonConstValue(value) {
53
- return typeof value === "boolean" || typeof value === "number" && Number.isFinite(value) || typeof value === "string";
54
- }
55
- /**
56
- * Whether values are JSON compatible for an enum keyword.
57
- *
58
- * @param values The values to check.
59
- *
60
- * @returns Whether the values are JSON compatible.
61
- */
62
- function isJsonEnumValues(values) {
63
- return values.every(isJsonConstValue);
64
- }
65
- /**
66
- * Schema reference map with collision-free reference ID allocation.
67
- */
68
- var ReferenceMap = class extends Map {
69
- /**
70
- * Creates an empty schema reference map.
71
- */
72
- constructor() {
73
- super();
74
- this.count = 0;
75
- this.usedIds = /* @__PURE__ */ new Set();
76
- }
77
- /**
78
- * Adds a schema reference and reserves its ID.
79
- *
80
- * @param schema The Valibot schema.
81
- * @param referenceId The reference ID.
82
- *
83
- * @returns The reference map.
84
- */
85
- set(schema, referenceId) {
86
- this.usedIds.add(referenceId);
87
- return super.set(schema, referenceId);
88
- }
89
- /**
90
- * Creates a reference ID that is not yet used.
91
- *
92
- * @param definitions The JSON Schema definitions.
93
- *
94
- * @returns The unused reference ID.
95
- */
96
- createId(definitions) {
97
- while (this.usedIds.has(`${this.count}`) || `${this.count}` in definitions) this.count++;
98
- return `${this.count++}`;
99
- }
100
- };
101
- /**
102
- * Returns the stricter lower bound.
103
- *
104
- * @param current The current lower bound.
105
- * @param value The new lower bound.
106
- *
107
- * @returns The stricter lower bound.
108
- */
109
- function getLowerBound(current, value) {
110
- if (typeof current !== "number" || !Number.isFinite(current) || value > current) return value;
111
- return current;
112
- }
113
- /**
114
- * Returns the stricter upper bound.
115
- *
116
- * @param current The current upper bound.
117
- * @param value The new upper bound.
118
- *
119
- * @returns The stricter upper bound.
120
- */
121
- function getUpperBound(current, value) {
122
- if (typeof current !== "number" || !Number.isFinite(current) || value < current) return value;
123
- return current;
124
- }
125
- /**
126
- * Returns the combined not restriction.
127
- *
128
- * @param current The current not restriction.
129
- * @param value The new not restriction.
130
- *
131
- * @returns The combined not restriction.
132
- */
133
- /* @__NO_SIDE_EFFECTS__ */
134
- function getNotRestriction(current, value) {
135
- return current !== void 0 ? { anyOf: [current, value] } : value;
136
- }
137
- /**
138
- * Intersects allowed values with an existing enum restriction.
139
- *
140
- * @param jsonSchema The JSON Schema object.
141
- * @param values The allowed values.
142
- */
143
- function intersectEnum(jsonSchema, values) {
144
- let enumValues = jsonSchema.enum ?? values;
145
- if (jsonSchema.enum) {
146
- const valueSet = new Set(values);
147
- enumValues = enumValues.filter((value) => valueSet.has(value));
148
- }
149
- if (enumValues.length) jsonSchema.enum = [...new Set(enumValues)];
150
- else {
151
- delete jsonSchema.enum;
152
- jsonSchema.not = /* @__PURE__ */ getNotRestriction(jsonSchema.not, {});
153
- }
154
- }
155
- /**
156
- * Converts any supported Valibot action to the JSON Schema format.
157
- *
158
- * @param jsonSchema The JSON Schema object.
159
- * @param valibotAction The Valibot action object.
160
- * @param config The conversion configuration.
161
- *
162
- * @returns The converted JSON Schema.
163
- */
164
- function convertAction(jsonSchema, valibotAction, config) {
165
- if (config?.ignoreActions?.includes(valibotAction.type)) return jsonSchema;
166
- let errors;
167
- switch (valibotAction.type) {
168
- case "base64":
169
- jsonSchema.contentEncoding = "base64";
170
- break;
171
- case "bic":
172
- case "cuid2":
173
- case "decimal":
174
- case "digits":
175
- case "domain":
176
- case "emoji":
177
- case "hash":
178
- case "hexadecimal":
179
- case "hex_color":
180
- case "isrc":
181
- case "iso_time_second":
182
- case "iso_week":
183
- case "ksuid":
184
- case "mac":
185
- case "mac48":
186
- case "mac64":
187
- case "nanoid":
188
- case "octal":
189
- case "slug":
190
- case "ulid":
191
- if (jsonSchema.pattern) errors = addError(errors, `The "${valibotAction.type}" action is not supported in combination with another regex action.`);
192
- else jsonSchema.pattern = valibotAction.requirement.source;
193
- break;
194
- case "description":
195
- jsonSchema.description = valibotAction.description;
196
- break;
197
- case "email":
198
- case "rfc_email":
199
- jsonSchema.format = "email";
200
- break;
201
- case "ends_with":
202
- if (jsonSchema.pattern) errors = addError(errors, `The "${valibotAction.type}" action is not supported in combination with another regex action.`);
203
- else jsonSchema.pattern = `${escapeRegExp(valibotAction.requirement)}$`;
204
- break;
205
- case "empty":
206
- if (jsonSchema.type === "array") jsonSchema.maxItems = 0;
207
- else {
208
- if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`);
209
- jsonSchema.maxLength = 0;
210
- }
211
- break;
212
- case "entries":
213
- if (!Number.isInteger(valibotAction.requirement) || valibotAction.requirement < 0) {
214
- errors = addError(errors, "The requirement of the \"entries\" action must be a non-negative integer.");
215
- break;
216
- }
217
- jsonSchema.minProperties = getLowerBound(jsonSchema.minProperties, valibotAction.requirement);
218
- jsonSchema.maxProperties = getUpperBound(jsonSchema.maxProperties, valibotAction.requirement);
219
- break;
220
- case "examples":
221
- if (Array.isArray(jsonSchema.examples)) jsonSchema.examples = [...jsonSchema.examples, ...valibotAction.examples];
222
- else jsonSchema.examples = valibotAction.examples;
223
- break;
224
- case "gt_value":
225
- if (jsonSchema.type !== "number" && jsonSchema.type !== "integer") {
226
- errors = addError(errors, `The "gt_value" action is not supported on type "${jsonSchema.type}".`);
227
- break;
228
- }
229
- if (!Number.isFinite(valibotAction.requirement)) {
230
- errors = addError(errors, "The requirement of the \"gt_value\" action is not JSON compatible.");
231
- break;
232
- }
233
- if (config?.target === "openapi-3.0") {
234
- errors = addError(errors, "The \"gt_value\" action is not supported for OpenAPI 3.0.");
235
- break;
236
- }
237
- jsonSchema.exclusiveMinimum = getLowerBound(jsonSchema.exclusiveMinimum, valibotAction.requirement);
238
- break;
239
- case "includes":
240
- if (jsonSchema.pattern) errors = addError(errors, `The "${valibotAction.type}" action is not supported in combination with another regex action.`);
241
- else jsonSchema.pattern = escapeRegExp(valibotAction.requirement);
242
- break;
243
- case "integer":
244
- jsonSchema.type = "integer";
245
- break;
246
- case "ipv4":
247
- jsonSchema.format = "ipv4";
248
- break;
249
- case "ipv6":
250
- jsonSchema.format = "ipv6";
251
- break;
252
- case "iso_date":
253
- jsonSchema.format = "date";
254
- break;
255
- case "iso_date_time":
256
- case "iso_timestamp":
257
- jsonSchema.format = "date-time";
258
- break;
259
- case "iso_time":
260
- jsonSchema.format = "time";
261
- break;
262
- case "jws_compact":
263
- if (jsonSchema.pattern) errors = addError(errors, `The "${valibotAction.type}" action is not supported in combination with another regex action.`);
264
- else jsonSchema.pattern = valibotAction.requirement.source;
265
- break;
266
- case "length":
267
- if (!Number.isInteger(valibotAction.requirement) || valibotAction.requirement < 0) {
268
- errors = addError(errors, "The requirement of the \"length\" action must be a non-negative integer.");
269
- break;
270
- }
271
- if (jsonSchema.type === "array") {
272
- jsonSchema.minItems = getLowerBound(jsonSchema.minItems, valibotAction.requirement);
273
- jsonSchema.maxItems = getUpperBound(jsonSchema.maxItems, valibotAction.requirement);
274
- } else {
275
- if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`);
276
- jsonSchema.minLength = getLowerBound(jsonSchema.minLength, valibotAction.requirement);
277
- jsonSchema.maxLength = getUpperBound(jsonSchema.maxLength, valibotAction.requirement);
278
- }
279
- break;
280
- case "lt_value":
281
- if (jsonSchema.type !== "number" && jsonSchema.type !== "integer") {
282
- errors = addError(errors, `The "lt_value" action is not supported on type "${jsonSchema.type}".`);
283
- break;
284
- }
285
- if (!Number.isFinite(valibotAction.requirement)) {
286
- errors = addError(errors, "The requirement of the \"lt_value\" action is not JSON compatible.");
287
- break;
288
- }
289
- if (config?.target === "openapi-3.0") {
290
- errors = addError(errors, "The \"lt_value\" action is not supported for OpenAPI 3.0.");
291
- break;
292
- }
293
- jsonSchema.exclusiveMaximum = getUpperBound(jsonSchema.exclusiveMaximum, valibotAction.requirement);
294
- break;
295
- case "max_entries":
296
- if (!Number.isInteger(valibotAction.requirement) || valibotAction.requirement < 0) {
297
- errors = addError(errors, "The requirement of the \"max_entries\" action must be a non-negative integer.");
298
- break;
299
- }
300
- jsonSchema.maxProperties = getUpperBound(jsonSchema.maxProperties, valibotAction.requirement);
301
- break;
302
- case "max_length":
303
- if (!Number.isInteger(valibotAction.requirement) || valibotAction.requirement < 0) {
304
- errors = addError(errors, "The requirement of the \"max_length\" action must be a non-negative integer.");
305
- break;
306
- }
307
- if (jsonSchema.type === "array") jsonSchema.maxItems = getUpperBound(jsonSchema.maxItems, valibotAction.requirement);
308
- else {
309
- if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`);
310
- jsonSchema.maxLength = getUpperBound(jsonSchema.maxLength, valibotAction.requirement);
311
- }
312
- break;
313
- case "max_value":
314
- if (jsonSchema.type !== "number" && jsonSchema.type !== "integer") {
315
- errors = addError(errors, `The "max_value" action is not supported on type "${jsonSchema.type}".`);
316
- break;
317
- }
318
- if (!Number.isFinite(valibotAction.requirement)) {
319
- errors = addError(errors, "The requirement of the \"max_value\" action is not JSON compatible.");
320
- break;
321
- }
322
- jsonSchema.maximum = getUpperBound(jsonSchema.maximum, valibotAction.requirement);
323
- break;
324
- case "metadata":
325
- if (typeof valibotAction.metadata.title === "string") jsonSchema.title = valibotAction.metadata.title;
326
- if (typeof valibotAction.metadata.description === "string") jsonSchema.description = valibotAction.metadata.description;
327
- if (Array.isArray(valibotAction.metadata.examples)) if (Array.isArray(jsonSchema.examples)) jsonSchema.examples = [...jsonSchema.examples, ...valibotAction.metadata.examples];
328
- else jsonSchema.examples = valibotAction.metadata.examples;
329
- for (const key of Object.keys(valibotAction.metadata)) if (key !== "title" && key !== "description" && key !== "examples" && key !== "__proto__") jsonSchema[key] = valibotAction.metadata[key];
330
- break;
331
- case "min_entries":
332
- if (!Number.isInteger(valibotAction.requirement) || valibotAction.requirement < 0) {
333
- errors = addError(errors, "The requirement of the \"min_entries\" action must be a non-negative integer.");
334
- break;
335
- }
336
- jsonSchema.minProperties = getLowerBound(jsonSchema.minProperties, valibotAction.requirement);
337
- break;
338
- case "min_length":
339
- if (!Number.isInteger(valibotAction.requirement) || valibotAction.requirement < 0) {
340
- errors = addError(errors, "The requirement of the \"min_length\" action must be a non-negative integer.");
341
- break;
342
- }
343
- if (jsonSchema.type === "array") jsonSchema.minItems = getLowerBound(jsonSchema.minItems, valibotAction.requirement);
344
- else {
345
- if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`);
346
- jsonSchema.minLength = getLowerBound(jsonSchema.minLength, valibotAction.requirement);
347
- }
348
- break;
349
- case "min_value":
350
- if (jsonSchema.type !== "number" && jsonSchema.type !== "integer") {
351
- errors = addError(errors, `The "min_value" action is not supported on type "${jsonSchema.type}".`);
352
- break;
353
- }
354
- if (!Number.isFinite(valibotAction.requirement)) {
355
- errors = addError(errors, "The requirement of the \"min_value\" action is not JSON compatible.");
356
- break;
357
- }
358
- jsonSchema.minimum = getLowerBound(jsonSchema.minimum, valibotAction.requirement);
359
- break;
360
- case "multiple_of":
361
- jsonSchema.multipleOf = valibotAction.requirement;
362
- break;
363
- case "non_empty":
364
- if (jsonSchema.type === "array") jsonSchema.minItems = getLowerBound(jsonSchema.minItems, 1);
365
- else {
366
- if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`);
367
- jsonSchema.minLength = getLowerBound(jsonSchema.minLength, 1);
368
- }
369
- break;
370
- case "not_value":
371
- if (!isJsonConstValue(valibotAction.requirement)) {
372
- errors = addError(errors, "The requirement of the \"not_value\" action is not JSON compatible.");
373
- break;
374
- }
375
- jsonSchema.not = /* @__PURE__ */ getNotRestriction(jsonSchema.not, config?.target === "openapi-3.0" ? { enum: [valibotAction.requirement] } : { const: valibotAction.requirement });
376
- break;
377
- case "not_values":
378
- if (!isJsonEnumValues(valibotAction.requirement)) {
379
- errors = addError(errors, "A requirement of the \"not_values\" action is not JSON compatible.");
380
- break;
381
- }
382
- if (valibotAction.requirement.length) jsonSchema.not = /* @__PURE__ */ getNotRestriction(jsonSchema.not, { enum: [...new Set(valibotAction.requirement)] });
383
- break;
384
- case "regex":
385
- if (valibotAction.requirement.flags) errors = addError(errors, "RegExp flags are not supported by JSON Schema.");
386
- if (jsonSchema.pattern) errors = addError(errors, `The "${valibotAction.type}" action is not supported in combination with another regex action.`);
387
- else jsonSchema.pattern = valibotAction.requirement.source;
388
- break;
389
- case "safe_integer":
390
- jsonSchema.type = "integer";
391
- jsonSchema.minimum = getLowerBound(jsonSchema.minimum, Number.MIN_SAFE_INTEGER);
392
- jsonSchema.maximum = getUpperBound(jsonSchema.maximum, Number.MAX_SAFE_INTEGER);
393
- break;
394
- case "starts_with":
395
- if (jsonSchema.pattern) errors = addError(errors, `The "${valibotAction.type}" action is not supported in combination with another regex action.`);
396
- else jsonSchema.pattern = `^${escapeRegExp(valibotAction.requirement)}`;
397
- break;
398
- case "title":
399
- jsonSchema.title = valibotAction.title;
400
- break;
401
- case "url":
402
- jsonSchema.format = "uri";
403
- break;
404
- case "uuid":
405
- jsonSchema.format = "uuid";
406
- break;
407
- case "value":
408
- if (!isJsonConstValue(valibotAction.requirement)) {
409
- errors = addError(errors, "The requirement of the \"value\" action is not JSON compatible.");
410
- break;
411
- }
412
- if (config?.target === "openapi-3.0") intersectEnum(jsonSchema, [valibotAction.requirement]);
413
- else if ("const" in jsonSchema && jsonSchema.const !== valibotAction.requirement) errors = addError(errors, `The "${valibotAction.type}" action is not supported in combination with a different "const" restriction.`);
414
- else jsonSchema.const = valibotAction.requirement;
415
- break;
416
- case "values":
417
- if (!isJsonEnumValues(valibotAction.requirement)) {
418
- errors = addError(errors, "A requirement of the \"values\" action is not JSON compatible.");
419
- break;
420
- }
421
- intersectEnum(jsonSchema, valibotAction.requirement);
422
- break;
423
- default: errors = addError(errors, `The "${valibotAction.type}" action cannot be converted to JSON Schema.`);
424
- }
425
- if (config?.overrideAction) {
426
- const actionOverride = config.overrideAction({
427
- valibotAction,
428
- jsonSchema,
429
- errors
430
- });
431
- if (actionOverride) return { ...actionOverride };
432
- }
433
- if (errors) for (const message of errors) handleError(message, config);
434
- return jsonSchema;
435
- }
436
- /**
437
- * Flattens a Valibot pipe by recursively expanding nested pipes.
438
- *
439
- * @param pipe The pipeline to flatten.
440
- *
441
- * @returns A flat pipeline.
442
- */
443
- function flattenPipe(pipe) {
444
- return pipe.flatMap((item) => "pipe" in item ? flattenPipe(item.pipe) : item);
445
- }
446
- /**
447
- * Returns the JSON Pointer reference for a definition key.
448
- *
449
- * @param referenceId The unescaped definition key.
450
- *
451
- * @returns The encoded JSON Pointer fragment.
452
- */
453
- function getDefinitionRef(referenceId) {
454
- return `#/$defs/${referenceId.replaceAll("~", "~0").replaceAll("/", "~1")}`;
455
- }
456
- /**
457
- * Converts any supported Valibot schema to the JSON Schema format.
458
- *
459
- * @param jsonSchema The JSON Schema object.
460
- * @param valibotSchema The Valibot schema object.
461
- * @param config The conversion configuration.
462
- * @param context The conversion context.
463
- * @param skipRef Whether to skip using a reference.
464
- *
465
- * @returns The converted JSON Schema.
466
- */
467
- function convertSchema(jsonSchema, valibotSchema, config, context, skipRef = false) {
468
- if (!skipRef) {
469
- const referenceId = context.referenceMap.get(valibotSchema);
470
- if (referenceId) {
471
- jsonSchema.$ref = getDefinitionRef(referenceId);
472
- if (config?.overrideRef) {
473
- const refOverride = config.overrideRef({
474
- ...context,
475
- referenceId,
476
- valibotSchema,
477
- jsonSchema
478
- });
479
- if (refOverride) jsonSchema.$ref = refOverride;
480
- }
481
- return jsonSchema;
482
- }
483
- }
484
- if ("pipe" in valibotSchema) {
485
- const flatPipe = flattenPipe(valibotSchema.pipe);
486
- let startIndex = 0;
487
- let stopIndex = flatPipe.length - 1;
488
- if (config?.typeMode === "input") {
489
- const inputStopIndex = flatPipe.slice(1).findIndex((item) => item.kind === "schema" || item.kind === "transformation" && (item.type === "find_item" || item.type === "parse_json" || item.type === "raw_transform" || item.type === "reduce_items" || item.type === "stringify_json" || item.type === "to_bigint" || item.type === "to_boolean" || item.type === "to_date" || item.type === "to_number" || item.type === "to_string" || item.type === "transform"));
490
- if (inputStopIndex !== -1) stopIndex = inputStopIndex;
491
- } else if (config?.typeMode === "output") {
492
- const outputStartIndex = flatPipe.findLastIndex((item) => item.kind === "schema");
493
- if (outputStartIndex !== -1) startIndex = outputStartIndex;
494
- }
495
- for (let index = startIndex; index <= stopIndex; index++) {
496
- const valibotPipeItem = flatPipe[index];
497
- if (valibotPipeItem.kind === "schema") {
498
- if (index > startIndex) handleError("Set the \"typeMode\" config to \"input\" or \"output\" to convert pipelines with multiple schemas.", config);
499
- jsonSchema = convertSchema(jsonSchema, valibotPipeItem, config, context, true);
500
- } else jsonSchema = convertAction(jsonSchema, valibotPipeItem, config);
501
- }
502
- return jsonSchema;
503
- }
504
- let errors;
505
- switch (valibotSchema.type) {
506
- case "boolean":
507
- jsonSchema.type = "boolean";
508
- break;
509
- case "null":
510
- if (config?.target === "openapi-3.0") jsonSchema.enum = [null];
511
- else jsonSchema.type = "null";
512
- break;
513
- case "number":
514
- jsonSchema.type = "number";
515
- break;
516
- case "string":
517
- jsonSchema.type = "string";
518
- break;
519
- case "array":
520
- jsonSchema.type = "array";
521
- jsonSchema.items = convertSchema({}, valibotSchema.item, config, context);
522
- break;
523
- case "tuple":
524
- case "tuple_with_rest":
525
- case "loose_tuple":
526
- case "strict_tuple":
527
- jsonSchema.type = "array";
528
- if (config?.target === "openapi-3.0") {
529
- jsonSchema.items = { anyOf: [] };
530
- jsonSchema.minItems = valibotSchema.items.length;
531
- for (const item of valibotSchema.items) jsonSchema.items.anyOf.push(convertSchema({}, item, config, context));
532
- if (valibotSchema.type === "tuple_with_rest") jsonSchema.items.anyOf.push(convertSchema({}, valibotSchema.rest, config, context));
533
- else if (valibotSchema.type === "strict_tuple" || valibotSchema.type === "tuple") jsonSchema.maxItems = valibotSchema.items.length;
534
- } else if (config?.target === "draft-2020-12") {
535
- jsonSchema.prefixItems = [];
536
- jsonSchema.minItems = valibotSchema.items.length;
537
- for (const item of valibotSchema.items) jsonSchema.prefixItems.push(convertSchema({}, item, config, context));
538
- if (valibotSchema.type === "tuple_with_rest") jsonSchema.items = convertSchema({}, valibotSchema.rest, config, context);
539
- else if (valibotSchema.type === "strict_tuple") jsonSchema.items = false;
540
- } else {
541
- jsonSchema.items = [];
542
- jsonSchema.minItems = valibotSchema.items.length;
543
- for (const item of valibotSchema.items) jsonSchema.items.push(convertSchema({}, item, config, context));
544
- if (valibotSchema.type === "tuple_with_rest") jsonSchema.additionalItems = convertSchema({}, valibotSchema.rest, config, context);
545
- else if (valibotSchema.type === "strict_tuple") jsonSchema.additionalItems = false;
546
- }
547
- break;
548
- case "object":
549
- case "object_with_rest":
550
- case "loose_object":
551
- case "strict_object":
552
- jsonSchema.type = "object";
553
- jsonSchema.properties = {};
554
- jsonSchema.required = [];
555
- for (const key in valibotSchema.entries) {
556
- const entry = valibotSchema.entries[key];
557
- jsonSchema.properties[key] = convertSchema({}, entry, config, context);
558
- if (entry.type !== "exact_optional" && entry.type !== "nullish" && entry.type !== "optional") jsonSchema.required.push(key);
559
- }
560
- if (valibotSchema.type === "object_with_rest") jsonSchema.additionalProperties = convertSchema({}, valibotSchema.rest, config, context);
561
- else if (valibotSchema.type === "strict_object") jsonSchema.additionalProperties = false;
562
- break;
563
- case "record":
564
- if (config?.target === "openapi-3.0" && "pipe" in valibotSchema.key) errors = addError(errors, "The \"record\" schema with a schema for the key that contains a \"pipe\" cannot be converted to JSON Schema.");
565
- if (valibotSchema.key.type !== "string") errors = addError(errors, `The "record" schema with the "${valibotSchema.key.type}" schema for the key cannot be converted to JSON Schema.`);
566
- jsonSchema.type = "object";
567
- if (config?.target !== "openapi-3.0") jsonSchema.propertyNames = convertSchema({}, valibotSchema.key, config, context);
568
- jsonSchema.additionalProperties = convertSchema({}, valibotSchema.value, config, context);
569
- break;
570
- case "any":
571
- case "unknown": break;
572
- case "never":
573
- jsonSchema.not = {};
574
- break;
575
- case "nullable":
576
- case "nullish":
577
- if (config?.target === "openapi-3.0") {
578
- const innerSchema = convertSchema({}, valibotSchema.wrapped, config, context);
579
- Object.assign(jsonSchema, innerSchema);
580
- jsonSchema.nullable = true;
581
- } else jsonSchema.anyOf = [convertSchema({}, valibotSchema.wrapped, config, context), { type: "null" }];
582
- if (valibotSchema.default !== void 0) jsonSchema.default = typeof valibotSchema.default === "function" ? valibotSchema.default() : valibotSchema.default;
583
- break;
584
- case "exact_optional":
585
- case "optional":
586
- case "undefinedable":
587
- jsonSchema = convertSchema(jsonSchema, valibotSchema.wrapped, config, context);
588
- if (valibotSchema.default !== void 0) jsonSchema.default = typeof valibotSchema.default === "function" ? valibotSchema.default() : valibotSchema.default;
589
- break;
590
- case "literal":
591
- if (!isJsonConstValue(valibotSchema.literal)) {
592
- errors = addError(errors, "The value of the \"literal\" schema is not JSON compatible.");
593
- break;
594
- }
595
- if (config?.target === "openapi-3.0") jsonSchema.enum = [valibotSchema.literal];
596
- else jsonSchema.const = valibotSchema.literal;
597
- break;
598
- case "enum":
599
- case "picklist": {
600
- const options = valibotSchema.options;
601
- if (!options.every((option) => typeof option === "string" || typeof option === "number" && Number.isFinite(option))) {
602
- errors = addError(errors, `An option of the "${valibotSchema.type}" schema is not JSON compatible.`);
603
- break;
604
- }
605
- jsonSchema.enum = options;
606
- if (options.every((option) => typeof option === "string")) jsonSchema.type = "string";
607
- else if (options.every((option) => typeof option === "number")) jsonSchema.type = "number";
608
- else if (config?.target !== "openapi-3.0") jsonSchema.type = ["string", "number"];
609
- break;
610
- }
611
- case "union":
612
- jsonSchema.anyOf = valibotSchema.options.map((option) => convertSchema({}, option, config, context));
613
- break;
614
- case "variant":
615
- jsonSchema.oneOf = valibotSchema.options.map((option) => convertSchema({}, option, config, context));
616
- break;
617
- case "intersect":
618
- jsonSchema.allOf = valibotSchema.options.map((option) => convertSchema({}, option, config, context));
619
- break;
620
- case "lazy": {
621
- let wrappedValibotSchema = context.getterMap.get(valibotSchema.getter);
622
- if (!wrappedValibotSchema) {
623
- wrappedValibotSchema = valibotSchema.getter(void 0);
624
- context.getterMap.set(valibotSchema.getter, wrappedValibotSchema);
625
- }
626
- let referenceId = context.referenceMap.get(wrappedValibotSchema);
627
- if (!referenceId) {
628
- referenceId = context.referenceMap.createId(context.definitions);
629
- context.referenceMap.set(wrappedValibotSchema, referenceId);
630
- context.definitions[referenceId] = convertSchema({}, wrappedValibotSchema, config, context, true);
631
- }
632
- jsonSchema.$ref = getDefinitionRef(referenceId);
633
- if (config?.overrideRef) {
634
- const refOverride = config.overrideRef({
635
- ...context,
636
- referenceId,
637
- valibotSchema: wrappedValibotSchema,
638
- jsonSchema
639
- });
640
- if (refOverride) jsonSchema.$ref = refOverride;
641
- }
642
- break;
643
- }
644
- default: errors = addError(errors, `The "${valibotSchema.type}" schema cannot be converted to JSON Schema.`);
645
- }
646
- if (config?.overrideSchema) {
647
- const schemaOverride = config.overrideSchema({
648
- ...context,
649
- referenceId: context.referenceMap.get(valibotSchema),
650
- valibotSchema,
651
- jsonSchema,
652
- errors
653
- });
654
- if (schemaOverride) return { ...schemaOverride };
655
- }
656
- if (errors) for (const message of errors) handleError(message, config);
657
- return jsonSchema;
658
- }
659
- /**
660
- * Converts a Valibot schema to the JSON Schema format.
661
- *
662
- * @param schema The Valibot schema object.
663
- * @param config The JSON Schema configuration.
664
- *
665
- * @returns The converted JSON Schema.
666
- */
667
- function toJsonSchema(schema, config) {
668
- const context = {
669
- definitions: {},
670
- referenceMap: new ReferenceMap(),
671
- getterMap: /* @__PURE__ */ new Map()
672
- };
673
- const definitions = config?.definitions ?? void 0;
674
- if (definitions) {
675
- for (const key in definitions) context.referenceMap.set(definitions[key], key);
676
- for (const key in definitions) context.definitions[key] = convertSchema({}, definitions[key], config, context, true);
677
- }
678
- const jsonSchema = convertSchema({}, schema, config, context);
679
- const target = config?.target ?? "draft-07";
680
- if (target === "draft-2020-12") jsonSchema.$schema = "https://json-schema.org/draft/2020-12/schema";
681
- else if (target === "draft-07") jsonSchema.$schema = "http://json-schema.org/draft-07/schema#";
682
- if (context.referenceMap.size) jsonSchema.$defs = context.definitions;
683
- return jsonSchema;
684
- }
3
+ import { toJsonSchema } from "@valibot/to-json-schema";
685
4
  // ../internal/src/valibot.ts
686
5
  const valibotTargets = /* @__PURE__ */ new Set([
687
6
  "draft-07",
package/dist/vite.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { A as schemaContainsEnum, E as envValueTypeName, F as envSourceFailed, I as invalidEnvDeclaration, L as isAbortError, M as isEnvSchemaValue, N as parseSchema, O as parseEnvValue, R as missingRequiredEnv, S as readViteHubSecret, f as invariant, g as runtimeRegistryEntries, h as isRuntimeProviderEntry, j as stringValueSchema, m as isRuntimeLiteralEntry, p as isRuntimeEnvEntry, r as describeServerEnv } from "./server-pTqnkM7n.js";
2
- import { a as VITEHUB_ENV_SERVER, c as createViteHubEnvImportAliases, d as viteHubEnvAmbientTypesPath, f as viteHubEnvDescriptionModulePath, g as viteHubEnvServerModuleTypesPath, h as viteHubEnvServerModulePath, i as VITEHUB_ENV_PUBLIC_ID, l as isServerEnvironment, m as viteHubEnvPublicModuleTypesPath, o as VITEHUB_ENV_SERVER_ID, p as viteHubEnvPublicModulePath, r as loadAllEnv, s as createNoExternalAddition, t as createEnvCliContributor, u as resolveViteHubProjectRoot } from "./cli-CAlHK5nn.js";
2
+ import { a as VITEHUB_ENV_SERVER, c as createViteHubEnvImportAliases, d as viteHubEnvAmbientTypesPath, f as viteHubEnvDescriptionModulePath, g as viteHubEnvServerModuleTypesPath, h as viteHubEnvServerModulePath, i as VITEHUB_ENV_PUBLIC_ID, l as isServerEnvironment, m as viteHubEnvPublicModuleTypesPath, o as VITEHUB_ENV_SERVER_ID, p as viteHubEnvPublicModulePath, r as loadAllEnv, s as createNoExternalAddition, t as createEnvCliContributor, u as resolveViteHubProjectRoot } from "./cli-BXzUIcnA.js";
3
3
  import { i as schemaModuleReference, n as env, r as runtimeValueSchema, t as descriptorVariable } from "./declarations-meg4Rmgd.js";
4
4
  import { t as envErrorDiagnostics } from "./error-diagnostics-BFzFaXcH.js";
5
5
  import { Diagnostic } from "nostics";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vite-hub/env",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "description": "Safe build and runtime environment variables for ViteHub.",
5
5
  "keywords": [
6
6
  "env",
@@ -97,7 +97,8 @@
97
97
  },
98
98
  "dependencies": {
99
99
  "@env-spec/parser": "0.6.3",
100
- "@vite-hub/runtime": "0.5.1",
100
+ "@valibot/to-json-schema": "^1.8.0",
101
+ "@vite-hub/runtime": "0.6.0",
101
102
  "magic-string": "^1.4.5",
102
103
  "nostics": "1.4.0",
103
104
  "valibot": "^1.5.0"
@@ -119,7 +120,7 @@
119
120
  "peerDependencies": {
120
121
  "vite": ">=8.0.0",
121
122
  "drizzle-orm": "1.0.0-rc.5 || 1.0.0-rc.6 || ^1.0.0",
122
- "@vite-hub/agent": "0.5.1",
123
+ "@vite-hub/agent": "0.6.0",
123
124
  "nitro": "3.0.261102-rc || ^3.0.261103-rc"
124
125
  },
125
126
  "peerDependenciesMeta": {