@vite-hub/env 0.1.0 → 0.3.1
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/README.md +178 -33
- package/dist/{access-B3qzBHye.js → access-B8lSDip4.js} +1 -1
- package/dist/{bridge-CdNdTN1V.d.ts → bridge-Cs9YfQWk.d.ts} +111 -38
- package/dist/{bridge-error-CFuU5zIz.js → bridge-error-BhJ77age.js} +14 -13
- package/dist/bridge.d.ts +2 -2
- package/dist/bridge.js +168 -6
- package/dist/cli-BPp7rdcA.d.ts +159 -0
- package/dist/{cli-CMQPQbii.js → cli-DLpY0QAo.js} +212 -30
- package/dist/cli.d.ts +2 -2
- package/dist/cli.js +1 -1
- package/dist/database.d.ts +29 -3
- package/dist/database.js +106 -15
- package/dist/declarations-C5XR3aKw.d.ts +58 -0
- package/dist/error-diagnostics-B8RFjQ1V.js +56 -0
- package/dist/index.d.ts +145 -10
- package/dist/index.js +240 -7
- package/dist/internal/agent.d.ts +1 -1
- package/dist/internal/agent.js +2 -2
- package/dist/internal/connections.d.ts +1 -1
- package/dist/internal/connections.js +2 -2
- package/dist/internal/server.d.ts +3 -0
- package/dist/internal/server.js +2 -0
- package/dist/object-_dlsZ4lP.js +276 -0
- package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
- package/dist/operations-X1w--wds.js +30 -0
- package/dist/operations.d.ts +37 -0
- package/dist/operations.js +833 -0
- package/dist/runtime/public-env.d.ts +5 -0
- package/dist/runtime/public-env.js +8 -0
- package/dist/runtime/server-env.d.ts +22 -0
- package/dist/runtime/server-env.js +35 -0
- package/dist/schema-DMZ1_yhY.js +360 -0
- package/dist/seal.d.ts +8 -5
- package/dist/seal.js +9 -6
- package/dist/{secret.js → secret-DJd-fy5T.js} +1 -1
- package/dist/server-ChNL_Xc3.js +1279 -0
- package/dist/server-Dd8bjIKd.d.ts +145 -0
- package/dist/server.d.ts +3 -25
- package/dist/server.js +2 -2
- package/dist/virtual-module.d.ts +6 -6
- package/dist/vite.d.ts +59 -14
- package/dist/vite.js +304 -115
- package/package.json +27 -38
- package/dist/auth.d.ts +0 -32
- package/dist/auth.js +0 -44
- package/dist/cli-DEwcUIe0.d.ts +0 -81
- package/dist/declarations-CiRdb1qP.d.ts +0 -32
- package/dist/declarations-DAVgctKD.js +0 -236
- package/dist/error-diagnostics-CrxjYNYr.js +0 -43
- package/dist/http.d.ts +0 -2
- package/dist/http.js +0 -122
- package/dist/presets.d.ts +0 -20
- package/dist/presets.js +0 -44
- package/dist/provider.d.ts +0 -5
- package/dist/provider.js +0 -8
- package/dist/schema.d.ts +0 -15
- package/dist/schema.js +0 -55
- package/dist/secret-C2191nAa.d.ts +0 -11
- package/dist/secret.d.ts +0 -2
- package/dist/server-DufVswRJ.js +0 -670
- package/dist/values-D_r6V774.js +0 -148
package/dist/values-D_r6V774.js
DELETED
|
@@ -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 };
|