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 CHANGED
@@ -1,5 +1,5 @@
1
- import { TPrefixFormat, TSharedFormat, TServerFormat, TClientFormat, TExtendsFormat, TSchema, FinalSchema, EnvOptions, DefineEnv } from './types.js';
1
+ import { PrefixFormat, SharedFormat, ServerFormat, ClientFormat, ExtendsFormat, Schema, FinalSchema, EnvOptions, DefineEnv } from './types.js';
2
2
 
3
- declare function defineEnv<TPrefix extends TPrefixFormat, TShared extends TSharedFormat = NonNullable<unknown>, TServer extends TServerFormat = NonNullable<unknown>, TClient extends TClientFormat = NonNullable<unknown>, const TExtends extends TExtendsFormat = [], TFinalSchema extends TSchema = FinalSchema<TShared, TServer, TClient, TExtends>>(options: EnvOptions<TPrefix, TShared, TServer, TClient, TExtends, TFinalSchema>): DefineEnv<TFinalSchema>;
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}},T=e=>Object.fromEntries(Object.entries(e).map(([t,a])=>[t,y(a)]));var F=e=>["__esModule","$$typeof"].includes(e),x=(e,t)=>({...e.shared&&e.shared,...e.server&&t&&e.server,...e.client&&e.client}),O=(e,t)=>({...e.extends?.reduce((u,s)=>({...u,...x(s,t)}),{}),...x(e,t)}),f=class extends Error{constructor(t){super(t),this.name="EnvError"}};function w(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=O(e,a),c=e.transform?.(d,a)??d,h=p(c)?y(c):T(c);if(o)return{...h,...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 v=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},I=n=>a||!v(n);return new Proxy("value"in l?l.value:{},{get(n,r){if(typeof r=="string"&&!F(r))return r==="_schema"?d:I(r)?Reflect.get(n,r):s(r)}})}export{w as defineEnv};
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" | "dev" | undefined, {}>;
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, {}>;
@@ -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>]>, 3 | 2, unknown>>;
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<TPrefixFormat, infer TShared, infer TServer, infer TClient> ? CombinedSchema<TShared, TServer, TClient> : T extends Readonly<ValidationOptions<TPrefixFormat, infer TShared, infer TServer, infer TClient>> ? CombinedSchema<TShared, TServer, TClient> : never;
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<TArr extends readonly unknown[] | unknown[], TAcc extends StandardSchemaDictionary<object, object> = StandardSchemaDictionary<object, object>> = TArr extends readonly [] | [] ? TAcc : TArr extends readonly [infer Head, ...infer Tail] | [infer Head, ...infer Tail] ? Tail extends readonly unknown[] | unknown[] ? Mutable<Reduce<Tail, CombinedSchema<TAcc, ExtractCombinedSchema<Head>>>> : never : never;
93
- type InferPresetOutput<T extends TExtendsFormat[number]> = StandardSchemaDictionary.InferOutput<ExtractCombinedSchema<T>>;
94
- type CombinedSchema<TShared extends TSharedFormat = TSharedFormat, TServer extends TServerFormat = TServerFormat, TClient extends TClientFormat = TClientFormat> = Merge<TShared, Merge<TServer, TClient>>;
95
- type TPrefixFormat = string | undefined;
96
- type TSharedFormat = StandardSchemaDictionary<object, object>;
97
- type TServerFormat = StandardSchemaDictionary<object, object>;
98
- type TClientFormat = StandardSchemaDictionary<object, object>;
99
- type TExtendsFormat = (TPreset | Readonly<TPreset>)[] | ReadonlyArray<TPreset>;
100
- type TPreset<TPrefix extends TPrefixFormat = TPrefixFormat, TShared extends TSharedFormat = TSharedFormat, TServer extends TServerFormat = TServerFormat, TClient extends TClientFormat = TClientFormat> = ValidationOptions<TPrefix, TShared, TServer, TClient> & {
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 TSchema = StandardSchemaV1<object, object>;
104
- interface BaseOptions<TExtends extends TExtendsFormat> {
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?: TExtends;
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<TExtends extends TExtendsFormat> extends BaseOptions<TExtends> {
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<TPrefix extends TPrefixFormat, TServer extends TServerFormat, TClient extends TClientFormat, TShared extends TSharedFormat, TExtends extends TExtendsFormat> extends BaseOptions<TExtends> {
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
- [TKey in keyof TClient]: TPrefix extends undefined ? never : TKey extends `${TPrefix}${string}` ? TKey : never;
149
- }[keyof TClient] | {
150
- [TKey in keyof TServer]: TPrefix extends undefined ? TKey : TKey extends `${TPrefix}${string}` ? never : TKey;
151
- }[keyof TServer] | {
152
- [TKey in keyof TShared]: TKey extends string ? TKey : never;
153
- }[keyof TShared], string | boolean | number | undefined>;
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<TShared extends TSharedFormat> {
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?: TShared;
163
+ shared?: Shared;
164
164
  }
165
- interface ClientOptions<TPrefix extends TPrefixFormat, TClient extends TClientFormat> {
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?: TPrefix;
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
- [TKey in keyof TClient]: TKey extends `${TPrefix}${string}` ? TClient[TKey] : ErrorMessage<`${TKey extends string ? TKey : never} is not prefixed with ${TPrefix}.`>;
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<TPrefix extends TPrefixFormat, TServer extends TServerFormat> {
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
- [TKey in keyof TServer]: TPrefix extends undefined ? TServer[TKey] : TPrefix extends "" ? TServer[TKey] : TKey extends `${TPrefix}${string}` ? ErrorMessage<`${TKey extends `${TPrefix}${string}` ? TKey : never} should not prefixed with ${TPrefix}.`> : TServer[TKey];
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<TPrefix extends TPrefixFormat = TPrefixFormat, TShared extends TSharedFormat = TSharedFormat, TServer extends TServerFormat = TServerFormat, TClient extends TClientFormat = TClientFormat> = ((ClientOptions<TPrefix, TClient> & ServerOptions<TPrefix, TServer>) | (ServerOptions<TPrefix, TServer> & Impossible<ClientOptions<never, never>>) | (ClientOptions<TPrefix, TClient> & Impossible<ServerOptions<never, never>>)) & SharedOptions<TShared>;
189
- interface TransformSchemaOptions<TShared extends TSharedFormat, TServer extends TServerFormat, TClient extends TClientFormat, TExtends extends TExtendsFormat, TFinalSchema extends TSchema> {
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<TShared, TServer, TClient, TExtends>>, isServer: boolean) => TFinalSchema;
194
+ transform?: (shape: Simplify<FullSchemaShape<Shared, Server, Client, Extends>>, isServer: boolean) => FinalSchema;
195
195
  }
196
- type EnvOptions<TPrefix extends TPrefixFormat = TPrefixFormat, TShared extends TSharedFormat = TSharedFormat, TServer extends TServerFormat = TServerFormat, TClient extends TClientFormat = TClientFormat, TExtends extends TExtendsFormat = TExtendsFormat, TFinalSchema extends TSchema = TSchema> = (LooseOptions<TExtends> | StrictOptions<TPrefix, TServer, TClient, TShared, TExtends>) & ValidationOptions<TPrefix, TShared, TServer, TClient> & TransformSchemaOptions<TShared, TServer, TClient, TExtends, TFinalSchema>;
197
- type FullSchemaShape<TShared extends TSharedFormat, TServer extends TServerFormat, TClient extends TClientFormat, TExtends extends TExtendsFormat> = CombinedSchema<Reduce<TExtends>, CombinedSchema<TShared, TServer, TClient>>;
198
- type FinalSchema<TShared extends TSharedFormat, TServer extends TServerFormat, TClient extends TClientFormat, TExtends extends TExtendsFormat> = StandardSchemaV1<object, UndefinedOptional<StandardSchemaDictionary.InferOutput<FullSchemaShape<TShared, TServer, TClient, TExtends>>>>;
199
- type DefineEnv<TFinalSchema extends TSchema = TSchema> = Simplify<Readonly<StandardSchemaV1.InferOutput<TFinalSchema> & {
200
- _schema: TFinalSchema;
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, ServerOptions, SharedOptions, Simplify, StrictOptions, TClientFormat, TExtendsFormat, TPrefixFormat, TPreset, TSchema, TServerFormat, TSharedFormat, TransformSchemaOptions, ValidationOptions };
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "envin",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Type-safe env validation with live previews",
5
5
  "keywords": [
6
6
  "turbostarter",