@vite-hub/env 0.1.0 → 0.3.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.
Files changed (61) hide show
  1. package/README.md +178 -33
  2. package/dist/{access-B3qzBHye.js → access-B8lSDip4.js} +1 -1
  3. package/dist/{bridge-CdNdTN1V.d.ts → bridge-Cs9YfQWk.d.ts} +111 -38
  4. package/dist/{bridge-error-CFuU5zIz.js → bridge-error-BhJ77age.js} +14 -13
  5. package/dist/bridge.d.ts +2 -2
  6. package/dist/bridge.js +168 -6
  7. package/dist/cli-BPp7rdcA.d.ts +159 -0
  8. package/dist/{cli-CMQPQbii.js → cli-DLpY0QAo.js} +212 -30
  9. package/dist/cli.d.ts +2 -2
  10. package/dist/cli.js +1 -1
  11. package/dist/database.d.ts +29 -3
  12. package/dist/database.js +106 -15
  13. package/dist/declarations-C5XR3aKw.d.ts +58 -0
  14. package/dist/error-diagnostics-B8RFjQ1V.js +56 -0
  15. package/dist/index.d.ts +145 -10
  16. package/dist/index.js +240 -7
  17. package/dist/internal/agent.d.ts +1 -1
  18. package/dist/internal/agent.js +2 -2
  19. package/dist/internal/connections.d.ts +1 -1
  20. package/dist/internal/connections.js +2 -2
  21. package/dist/internal/server.d.ts +3 -0
  22. package/dist/internal/server.js +2 -0
  23. package/dist/object-_dlsZ4lP.js +276 -0
  24. package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
  25. package/dist/operations-X1w--wds.js +30 -0
  26. package/dist/operations.d.ts +37 -0
  27. package/dist/operations.js +833 -0
  28. package/dist/runtime/public-env.d.ts +5 -0
  29. package/dist/runtime/public-env.js +8 -0
  30. package/dist/runtime/server-env.d.ts +22 -0
  31. package/dist/runtime/server-env.js +35 -0
  32. package/dist/schema-DMZ1_yhY.js +360 -0
  33. package/dist/seal.d.ts +8 -5
  34. package/dist/seal.js +9 -6
  35. package/dist/{secret.js → secret-DJd-fy5T.js} +1 -1
  36. package/dist/server-ChNL_Xc3.js +1279 -0
  37. package/dist/server-Dd8bjIKd.d.ts +145 -0
  38. package/dist/server.d.ts +3 -25
  39. package/dist/server.js +2 -2
  40. package/dist/virtual-module.d.ts +6 -6
  41. package/dist/vite.d.ts +59 -14
  42. package/dist/vite.js +304 -115
  43. package/package.json +27 -38
  44. package/dist/auth.d.ts +0 -32
  45. package/dist/auth.js +0 -44
  46. package/dist/cli-DEwcUIe0.d.ts +0 -81
  47. package/dist/declarations-CiRdb1qP.d.ts +0 -32
  48. package/dist/declarations-DAVgctKD.js +0 -236
  49. package/dist/error-diagnostics-CrxjYNYr.js +0 -43
  50. package/dist/http.d.ts +0 -2
  51. package/dist/http.js +0 -122
  52. package/dist/presets.d.ts +0 -20
  53. package/dist/presets.js +0 -44
  54. package/dist/provider.d.ts +0 -5
  55. package/dist/provider.js +0 -8
  56. package/dist/schema.d.ts +0 -15
  57. package/dist/schema.js +0 -55
  58. package/dist/secret-C2191nAa.d.ts +0 -11
  59. package/dist/secret.d.ts +0 -2
  60. package/dist/server-DufVswRJ.js +0 -670
  61. package/dist/values-D_r6V774.js +0 -148
@@ -1,148 +0,0 @@
1
- import { hasRuntimeType } from "@vite-hub/runtime/internal/runtime-type";
2
- //#region src/internal/runtime-type.ts
3
- function isRuntimeRecord(value) {
4
- return value !== null && hasRuntimeType(value, "object") && !Array.isArray(value);
5
- }
6
- //#endregion
7
- //#region src/core/json-value.ts
8
- /** JSON values accepted at the environment boundary, without prototype or internal keys. */
9
- function isEnvSchemaValue(value, depth = 0) {
10
- if (depth > 64) return false;
11
- if (value === null || typeof value === "string" || typeof value === "boolean") return true;
12
- if (typeof value === "number") return Number.isFinite(value);
13
- if (Array.isArray(value)) return value.every((item) => isEnvSchemaValue(item, depth + 1));
14
- if (typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype) return false;
15
- return Object.entries(value).every(([key, item]) => ![
16
- "__proto__",
17
- "prototype",
18
- "constructor",
19
- "__envSchemaUnset"
20
- ].includes(key) && isEnvSchemaValue(item, depth + 1));
21
- }
22
- //#endregion
23
- //#region src/core/values.ts
24
- const stringValueSchema = Object.freeze({ kind: "string" });
25
- /** Parse one host, provider, or default value with a serializable Server Env value schema. */
26
- function parseEnvValue(schema, input) {
27
- switch (schema.kind) {
28
- case "array":
29
- case "object": {
30
- let value = input;
31
- if (typeof value === "string") try {
32
- value = JSON.parse(value);
33
- } catch {
34
- return {
35
- success: false,
36
- message: "Expected valid JSON."
37
- };
38
- }
39
- return isEnvSchemaValue(value) && matchesJsonType(schema, value) ? {
40
- data: typeof input === "string" ? value : structuredClone(value),
41
- success: true
42
- } : {
43
- success: false,
44
- message: "JSON value does not match the declared type."
45
- };
46
- }
47
- case "string": return hasRuntimeType(input, "string") && (schema.minLength === void 0 || input.length >= schema.minLength) && (schema.maxLength === void 0 || input.length <= schema.maxLength) ? {
48
- data: input,
49
- success: true
50
- } : {
51
- message: schema.minLength === void 0 && schema.maxLength === void 0 ? "Expected a string." : "Expected a string within the declared length constraints.",
52
- success: false
53
- };
54
- case "boolean": return parseBoolean(input);
55
- case "number": return parseNumber(input, schema);
56
- case "url": return parseUrl(input);
57
- case "enum": return hasRuntimeType(input, "string") && schema.values.includes(input) ? {
58
- data: input,
59
- success: true
60
- } : {
61
- message: `Expected one of ${schema.values.map((value) => JSON.stringify(value)).join(", ")}.`,
62
- success: false
63
- };
64
- }
65
- }
66
- /** Return the TypeScript type that a value schema produces. */
67
- function envValueTypeName(schema) {
68
- switch (schema.kind) {
69
- case "array": return `Array<${schema.items ? envValueTypeName(schema.items) : "unknown"}>`;
70
- case "object": {
71
- if (!schema.properties) return "Record<string, unknown>";
72
- const properties = Object.entries(schema.properties);
73
- return properties.length ? `{ ${properties.map(([key, property]) => `${JSON.stringify(key)}: ${envValueTypeName(property)}`).join("; ")} }` : "Record<string, never>";
74
- }
75
- case "enum": return schema.values.map((value) => JSON.stringify(value)).join(" | ");
76
- case "url": return "string";
77
- default: return schema.kind;
78
- }
79
- }
80
- function parseBoolean(input) {
81
- if (hasRuntimeType(input, "boolean")) return {
82
- data: input,
83
- success: true
84
- };
85
- const normalized = hasRuntimeType(input, "string") ? input.trim().toLowerCase() : void 0;
86
- if (normalized === "true" || normalized === "1") return {
87
- data: true,
88
- success: true
89
- };
90
- if (normalized === "false" || normalized === "0") return {
91
- data: false,
92
- success: true
93
- };
94
- return {
95
- message: "Expected a boolean: true, false, 1, or 0.",
96
- success: false
97
- };
98
- }
99
- function parseNumber(input, schema) {
100
- if (schema.decimal && hasRuntimeType(input, "string") && !/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i.test(input.trim())) return {
101
- message: "Expected a finite decimal number.",
102
- success: false
103
- };
104
- const value = hasRuntimeType(input, "string") && input.trim() ? Number(input) : input;
105
- if (!hasRuntimeType(value, "number") || !Number.isFinite(value)) return {
106
- message: "Expected a finite number.",
107
- success: false
108
- };
109
- if (schema.isInt && !Number.isSafeInteger(value) || schema.min !== void 0 && value < schema.min || schema.max !== void 0 && value > schema.max) return {
110
- message: "Expected a number within the declared constraints.",
111
- success: false
112
- };
113
- return {
114
- data: value,
115
- success: true
116
- };
117
- }
118
- function parseUrl(input) {
119
- if (hasRuntimeType(input, "string")) try {
120
- if (new URL(input).protocol) return {
121
- data: input,
122
- success: true
123
- };
124
- } catch {}
125
- return {
126
- message: "Expected an absolute URL.",
127
- success: false
128
- };
129
- }
130
- function matchesJsonType(schema, value) {
131
- switch (schema.kind) {
132
- case "array": return Array.isArray(value) && (!schema.items || value.every((item) => schema.items && matchesJsonType(schema.items, item)));
133
- case "object": return value !== null && typeof value === "object" && !Array.isArray(value) && (!schema.properties || Object.keys(value).length === Object.keys(schema.properties).length && Object.entries(schema.properties).every(([key, property]) => Object.hasOwn(value, key) && matchesJsonType(property, Reflect.get(value, key))));
134
- case "boolean": return typeof value === "boolean";
135
- case "number": return typeof value === "number" && parseEnvValue(schema, value).success;
136
- default: return typeof value === "string" && parseEnvValue(schema, value).success;
137
- }
138
- }
139
- function schemaContainsEnum(schema) {
140
- switch (schema.kind) {
141
- case "enum": return true;
142
- case "array": return !!schema.items && schemaContainsEnum(schema.items);
143
- case "object": return Object.values(schema.properties ?? {}).some(schemaContainsEnum);
144
- default: return false;
145
- }
146
- }
147
- //#endregion
148
- export { isEnvSchemaValue as a, stringValueSchema as i, parseEnvValue as n, hasRuntimeType as o, schemaContainsEnum as r, isRuntimeRecord as s, envValueTypeName as t };