envin 1.1.2 → 1.1.3
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/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/presets/arktype.d.ts +1 -1
- package/dist/presets/zod.d.ts +1 -1
- package/dist/types.d.ts +37 -37
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PrefixFormat, SharedFormat, ServerFormat, ClientFormat, ExtendsFormat, Schema, FinalSchema, EnvOptions, DefineEnv } from './types.js';
|
|
2
2
|
|
|
3
|
-
declare function defineEnv<
|
|
3
|
+
declare function defineEnv<Prefix extends PrefixFormat, Shared extends SharedFormat = NonNullable<unknown>, Server extends ServerFormat = NonNullable<unknown>, Client extends ClientFormat = NonNullable<unknown>, const Extends extends ExtendsFormat = [], FinalSchemaType extends Schema = FinalSchema<Shared, Server, Client, Extends>>(options: EnvOptions<Prefix, Shared, Server, Client, Extends, FinalSchemaType>): DefineEnv<FinalSchemaType>;
|
|
4
4
|
|
|
5
5
|
export { defineEnv };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function S(e,t){if(e instanceof Promise)throw new Error(t)}function m(e,t){let a={},u=[];for(let s in e){let o=e[s]?.["~standard"].validate(t[s]);if(S(o,`Validation must be synchronous, but ${s} returned a Promise.`),o?.issues){u.push(...o.issues.map(d=>({...d,path:[s,...d.path??[]]})));continue}a[s]=o?.value}return u.length?{issues:u}:{value:a}}var p=e=>["function","object"].includes(typeof e)&&!!e&&"~standard"in e&&typeof e["~standard"]=="object"&&!!e["~standard"]&&"validate"in e["~standard"],y=e=>{if(!(typeof e!="object"||e===null)){if("default"in e&&!["object","function"].includes(typeof e.default))return e.default;if("_def"in e&&typeof e._def=="object"&&e._def!==null&&"defaultValue"in e._def)return typeof e._def.defaultValue=="function"?e._def.defaultValue?.():e._def.defaultValue}},
|
|
1
|
+
function S(e,t){if(e instanceof Promise)throw new Error(t)}function m(e,t){let a={},u=[];for(let s in e){let o=e[s]?.["~standard"].validate(t[s]);if(S(o,`Validation must be synchronous, but ${s} returned a Promise.`),o?.issues){u.push(...o.issues.map(d=>({...d,path:[s,...d.path??[]]})));continue}a[s]=o?.value}return u.length?{issues:u}:{value:a}}var p=e=>["function","object"].includes(typeof e)&&!!e&&"~standard"in e&&typeof e["~standard"]=="object"&&!!e["~standard"]&&"validate"in e["~standard"],y=e=>{if(!(typeof e!="object"||e===null)){if("default"in e&&!["object","function"].includes(typeof e.default))return e.default;if("_def"in e&&typeof e._def=="object"&&e._def!==null&&"defaultValue"in e._def)return typeof e._def.defaultValue=="function"?e._def.defaultValue?.():e._def.defaultValue}},x=e=>Object.fromEntries(Object.entries(e).map(([t,a])=>[t,y(a)]));var O=e=>["__esModule","$$typeof"].includes(e),h=(e,t)=>({...e.shared&&e.shared,...e.server&&t&&e.server,...e.client&&e.client}),k=(e,t)=>({...e.extends?.reduce((u,s)=>({...u,...h(s,t)}),{}),...h(e,t)}),f=class extends Error{constructor(t){super(t),this.name="EnvError"}};function P(e){let t=e.envStrict??e.env??process.env;for(let[n,r]of Object.entries(t))r===""&&delete t[n];let a=e.isServer??(typeof window>"u"||"Deno"in window),u=e.onError??(n=>{throw console.error("\u274C Invalid environment variables:",n),new f("Invalid environment variables")}),s=e.onInvalidAccess??(n=>{throw new f(`\u274C Attempted to access a server-side environment variable on the client: ${n}`)}),o=!!e.skip,d=k(e,a),c=e.transform?.(d,a)??d,v=p(c)?y(c):x(c);if(o)return{...v,...t,_schema:d};let l=p(c)?c["~standard"].validate(t):m(d,t);if(S(l,"Validation must be synchronous!"),l.issues)return u(l.issues);let I=n=>{let r=[e,...e.extends??[]].map(i=>({keys:Object.keys(i.client??{}),prefix:i.clientPrefix})).some(i=>i.keys.includes(n)&&(!i.prefix||n.startsWith(i.prefix)));return![...Object.keys(e.shared??{}),...e.extends?.flatMap(i=>Object.keys(i.shared??{}))??[]].includes(n)&&!r},F=n=>a||!I(n);return new Proxy("value"in l?l.value:{},{get(n,r){if(typeof r=="string"&&!O(r))return r==="_schema"?d:F(r)?Reflect.get(n,r):s(r)}})}export{P as defineEnv};
|
|
@@ -155,7 +155,7 @@ declare const netlify: {
|
|
|
155
155
|
readonly server: {
|
|
156
156
|
readonly NETLIFY: arktype_internal_methods_base_ts.BaseType<string | undefined, {}>;
|
|
157
157
|
readonly BUILD_ID: arktype_internal_methods_base_ts.BaseType<string | undefined, {}>;
|
|
158
|
-
readonly CONTEXT: arktype_internal_methods_base_ts.BaseType<"production" | "deploy-preview" | "branch-deploy" |
|
|
158
|
+
readonly CONTEXT: arktype_internal_methods_base_ts.BaseType<"dev" | "production" | "deploy-preview" | "branch-deploy" | undefined, {}>;
|
|
159
159
|
readonly REPOSITORY_URL: arktype_internal_methods_base_ts.BaseType<string | undefined, {}>;
|
|
160
160
|
readonly BRANCH: arktype_internal_methods_base_ts.BaseType<string | undefined, {}>;
|
|
161
161
|
readonly URL: arktype_internal_methods_base_ts.BaseType<string | undefined, {}>;
|
package/dist/presets/zod.d.ts
CHANGED
|
@@ -247,7 +247,7 @@ type ViteEnv = InferPresetOutput<typeof vite>;
|
|
|
247
247
|
declare const wxt: {
|
|
248
248
|
readonly id: "wxt";
|
|
249
249
|
readonly server: {
|
|
250
|
-
readonly MANIFEST_VERSION: z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodLiteral<2>, z.ZodLiteral<3>]>,
|
|
250
|
+
readonly MANIFEST_VERSION: z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodLiteral<2>, z.ZodLiteral<3>]>, 2 | 3, unknown>>;
|
|
251
251
|
readonly BROWSER: z.ZodOptional<z.ZodEnum<["chrome", "firefox", "safari", "edge", "opera"]>>;
|
|
252
252
|
readonly CHROME: z.ZodOptional<z.ZodBoolean>;
|
|
253
253
|
readonly FIREFOX: z.ZodOptional<z.ZodBoolean>;
|
package/dist/types.d.ts
CHANGED
|
@@ -87,25 +87,25 @@ type UndefinedOptional<T> = Partial<Pick<T, PossiblyUndefinedKeys<T>>> & Omit<T,
|
|
|
87
87
|
/** Converts a readonly type to a mutable type */
|
|
88
88
|
type Mutable<T> = T extends Readonly<infer U> ? U : T;
|
|
89
89
|
/** Extracts the combined schema from validation options */
|
|
90
|
-
type ExtractCombinedSchema<T> = T extends ValidationOptions<
|
|
90
|
+
type ExtractCombinedSchema<T> = T extends ValidationOptions<PrefixFormat, infer Shared, infer Server, infer Client> ? CombinedSchema<Shared, Server, Client> : T extends Readonly<ValidationOptions<PrefixFormat, infer Shared, infer Server, infer Client>> ? CombinedSchema<Shared, Server, Client> : never;
|
|
91
91
|
/** Reduces an array of schemas to a single schema */
|
|
92
|
-
type Reduce<
|
|
93
|
-
type InferPresetOutput<T extends
|
|
94
|
-
type CombinedSchema<
|
|
95
|
-
type
|
|
96
|
-
type
|
|
97
|
-
type
|
|
98
|
-
type
|
|
99
|
-
type
|
|
100
|
-
type
|
|
92
|
+
type Reduce<Arr extends readonly unknown[] | unknown[], Acc extends StandardSchemaDictionary<object, object> = StandardSchemaDictionary<object, object>> = Arr extends readonly [] | [] ? Acc : Arr extends readonly [infer Head, ...infer Tail] | [infer Head, ...infer Tail] ? Tail extends readonly unknown[] | unknown[] ? Mutable<Reduce<Tail, CombinedSchema<Acc, ExtractCombinedSchema<Head>>>> : never : never;
|
|
93
|
+
type InferPresetOutput<T extends ExtendsFormat[number]> = StandardSchemaDictionary.InferOutput<ExtractCombinedSchema<T>>;
|
|
94
|
+
type CombinedSchema<Shared extends SharedFormat = SharedFormat, Server extends ServerFormat = ServerFormat, Client extends ClientFormat = ClientFormat> = Merge<Shared, Merge<Server, Client>>;
|
|
95
|
+
type PrefixFormat = string | undefined;
|
|
96
|
+
type SharedFormat = StandardSchemaDictionary<object, object>;
|
|
97
|
+
type ServerFormat = StandardSchemaDictionary<object, object>;
|
|
98
|
+
type ClientFormat = StandardSchemaDictionary<object, object>;
|
|
99
|
+
type ExtendsFormat = (Preset | Readonly<Preset>)[] | ReadonlyArray<Preset>;
|
|
100
|
+
type Preset<Prefix extends PrefixFormat = PrefixFormat, Shared extends SharedFormat = SharedFormat, Server extends ServerFormat = ServerFormat, Client extends ClientFormat = ClientFormat> = ValidationOptions<Prefix, Shared, Server, Client> & {
|
|
101
101
|
id?: string;
|
|
102
102
|
};
|
|
103
|
-
type
|
|
104
|
-
interface BaseOptions<
|
|
103
|
+
type Schema = StandardSchemaV1<object, object>;
|
|
104
|
+
interface BaseOptions<Extends extends ExtendsFormat> {
|
|
105
105
|
/**
|
|
106
106
|
* Array of preset configurations to extend from.
|
|
107
107
|
*/
|
|
108
|
-
extends?:
|
|
108
|
+
extends?: Extends;
|
|
109
109
|
/**
|
|
110
110
|
* Whether to skip validation of environment variables.
|
|
111
111
|
* @default false
|
|
@@ -127,7 +127,7 @@ interface BaseOptions<TExtends extends TExtendsFormat> {
|
|
|
127
127
|
*/
|
|
128
128
|
onInvalidAccess?: (variable: string) => never;
|
|
129
129
|
}
|
|
130
|
-
interface LooseOptions<
|
|
130
|
+
interface LooseOptions<Extends extends ExtendsFormat> extends BaseOptions<Extends> {
|
|
131
131
|
/**
|
|
132
132
|
* Must be undefined when using loose options. Use `env` instead.
|
|
133
133
|
*/
|
|
@@ -139,65 +139,65 @@ interface LooseOptions<TExtends extends TExtendsFormat> extends BaseOptions<TExt
|
|
|
139
139
|
*/
|
|
140
140
|
env?: Record<string, string | boolean | number | undefined>;
|
|
141
141
|
}
|
|
142
|
-
interface StrictOptions<
|
|
142
|
+
interface StrictOptions<Prefix extends PrefixFormat, Server extends ServerFormat, Client extends ClientFormat, Shared extends SharedFormat, Extends extends ExtendsFormat> extends BaseOptions<Extends> {
|
|
143
143
|
/**
|
|
144
144
|
* Runtime Environment variables to use for validation - `process.env`, `import.meta.env` or similar.
|
|
145
145
|
* Enforces all environment variables to be set. Required in for example Next.js Edge and Client runtimes.
|
|
146
146
|
*/
|
|
147
147
|
envStrict?: Record<{
|
|
148
|
-
[
|
|
149
|
-
}[keyof
|
|
150
|
-
[
|
|
151
|
-
}[keyof
|
|
152
|
-
[
|
|
153
|
-
}[keyof
|
|
148
|
+
[Key in keyof Client]: Prefix extends undefined ? never : Key extends `${Prefix}${string}` ? Key : never;
|
|
149
|
+
}[keyof Client] | {
|
|
150
|
+
[Key in keyof Server]: Prefix extends undefined ? Key : Key extends `${Prefix}${string}` ? never : Key;
|
|
151
|
+
}[keyof Server] | {
|
|
152
|
+
[Key in keyof Shared]: Key extends string ? Key : never;
|
|
153
|
+
}[keyof Shared], string | boolean | number | undefined>;
|
|
154
154
|
/**
|
|
155
155
|
* Must be undefined when using strict options. Use `envStrict` instead.
|
|
156
156
|
*/
|
|
157
157
|
env?: never;
|
|
158
158
|
}
|
|
159
|
-
interface SharedOptions<
|
|
159
|
+
interface SharedOptions<Shared extends SharedFormat> {
|
|
160
160
|
/**
|
|
161
161
|
* Specify your shared environment variables schema here. These variables are available on both client and server.
|
|
162
162
|
*/
|
|
163
|
-
shared?:
|
|
163
|
+
shared?: Shared;
|
|
164
164
|
}
|
|
165
|
-
interface ClientOptions<
|
|
165
|
+
interface ClientOptions<Prefix extends PrefixFormat, Client extends ClientFormat> {
|
|
166
166
|
/**
|
|
167
167
|
* The prefix that client-side variables must have. This is enforced both at
|
|
168
168
|
* a type-level and at runtime.
|
|
169
169
|
*/
|
|
170
|
-
clientPrefix?:
|
|
170
|
+
clientPrefix?: Prefix;
|
|
171
171
|
/**
|
|
172
172
|
* Specify your client-side environment variables schema here. This way you can ensure the app isn't
|
|
173
173
|
* built with invalid env vars.
|
|
174
174
|
*/
|
|
175
175
|
client?: Partial<{
|
|
176
|
-
[
|
|
176
|
+
[Key in keyof Client]: Key extends `${Prefix}${string}` ? Client[Key] : ErrorMessage<`${Key extends string ? Key : never} is not prefixed with ${Prefix}.`>;
|
|
177
177
|
}>;
|
|
178
178
|
}
|
|
179
|
-
interface ServerOptions<
|
|
179
|
+
interface ServerOptions<Prefix extends PrefixFormat, Server extends ServerFormat> {
|
|
180
180
|
/**
|
|
181
181
|
* Specify your server-side environment variables schema here. This way you can ensure the app isn't
|
|
182
182
|
* built with invalid env vars.
|
|
183
183
|
*/
|
|
184
184
|
server: Partial<{
|
|
185
|
-
[
|
|
185
|
+
[Key in keyof Server]: Prefix extends undefined ? Server[Key] : Prefix extends "" ? Server[Key] : Key extends `${Prefix}${string}` ? ErrorMessage<`${Key extends `${Prefix}${string}` ? Key : never} should not prefixed with ${Prefix}.`> : Server[Key];
|
|
186
186
|
}>;
|
|
187
187
|
}
|
|
188
|
-
type ValidationOptions<
|
|
189
|
-
interface TransformSchemaOptions<
|
|
188
|
+
type ValidationOptions<Prefix extends PrefixFormat = PrefixFormat, Shared extends SharedFormat = SharedFormat, Server extends ServerFormat = ServerFormat, Client extends ClientFormat = ClientFormat> = ((ClientOptions<Prefix, Client> & ServerOptions<Prefix, Server>) | (ServerOptions<Prefix, Server> & Impossible<ClientOptions<never, never>>) | (ClientOptions<Prefix, Client> & Impossible<ServerOptions<never, never>>)) & SharedOptions<Shared>;
|
|
189
|
+
interface TransformSchemaOptions<Shared extends SharedFormat, Server extends ServerFormat, Client extends ClientFormat, Extends extends ExtendsFormat, FinalSchema extends Schema> {
|
|
190
190
|
/**
|
|
191
191
|
* A custom function to combine the schemas.
|
|
192
192
|
* Can be used to add further refinement or transformation.
|
|
193
193
|
*/
|
|
194
|
-
transform?: (shape: Simplify<FullSchemaShape<
|
|
194
|
+
transform?: (shape: Simplify<FullSchemaShape<Shared, Server, Client, Extends>>, isServer: boolean) => FinalSchema;
|
|
195
195
|
}
|
|
196
|
-
type EnvOptions<
|
|
197
|
-
type FullSchemaShape<
|
|
198
|
-
type FinalSchema<
|
|
199
|
-
type DefineEnv<
|
|
200
|
-
_schema:
|
|
196
|
+
type EnvOptions<Prefix extends PrefixFormat = PrefixFormat, Shared extends SharedFormat = SharedFormat, Server extends ServerFormat = ServerFormat, Client extends ClientFormat = ClientFormat, Extends extends ExtendsFormat = ExtendsFormat, FinalSchema extends Schema = Schema> = (LooseOptions<Extends> | StrictOptions<Prefix, Server, Client, Shared, Extends>) & ValidationOptions<Prefix, Shared, Server, Client> & TransformSchemaOptions<Shared, Server, Client, Extends, FinalSchema>;
|
|
197
|
+
type FullSchemaShape<Shared extends SharedFormat, Server extends ServerFormat, Client extends ClientFormat, Extends extends ExtendsFormat> = CombinedSchema<Reduce<Extends>, CombinedSchema<Shared, Server, Client>>;
|
|
198
|
+
type FinalSchema<Shared extends SharedFormat, Server extends ServerFormat, Client extends ClientFormat, Extends extends ExtendsFormat> = StandardSchemaV1<object, UndefinedOptional<StandardSchemaDictionary.InferOutput<FullSchemaShape<Shared, Server, Client, Extends>>>>;
|
|
199
|
+
type DefineEnv<FinalSchema extends Schema = Schema> = Simplify<Readonly<StandardSchemaV1.InferOutput<FinalSchema> & {
|
|
200
|
+
_schema: FinalSchema;
|
|
201
201
|
}>>;
|
|
202
202
|
|
|
203
|
-
export type { BaseOptions, ClientOptions, CombinedSchema, DefineEnv, EnvOptions, ErrorMessage, FinalSchema, FullSchemaShape, InferPresetOutput, LooseOptions,
|
|
203
|
+
export type { BaseOptions, ClientFormat, ClientOptions, CombinedSchema, DefineEnv, EnvOptions, ErrorMessage, ExtendsFormat, FinalSchema, FullSchemaShape, InferPresetOutput, LooseOptions, PrefixFormat, Preset, Schema, ServerFormat, ServerOptions, SharedFormat, SharedOptions, Simplify, StrictOptions, TransformSchemaOptions, ValidationOptions };
|