@t3-oss/env-core
Advanced tools
Comparing version 0.5.1 to 0.6.0
@@ -1,2 +0,2 @@ | ||
import { ZodError, ZodType, z, ZodObject } from 'zod'; | ||
import { ZodType, ZodError, z, ZodObject } from 'zod'; | ||
@@ -8,4 +8,5 @@ type ErrorMessage<T extends string> = T; | ||
type Impossible<T extends Record<string, any>> = Partial<Record<keyof T, never>>; | ||
interface BaseOptions { | ||
interface BaseOptions<TShared extends Record<string, ZodType>> { | ||
isServer?: boolean; | ||
shared?: TShared; | ||
onValidationError?: (error: ZodError) => never; | ||
@@ -15,7 +16,7 @@ onInvalidAccess?: (variable: string) => never; | ||
} | ||
interface LooseOptions extends BaseOptions { | ||
interface LooseOptions<TShared extends Record<string, ZodType>> extends BaseOptions<TShared> { | ||
runtimeEnvStrict?: never; | ||
runtimeEnv: Record<string, string | boolean | number | undefined>; | ||
} | ||
interface StrictOptions<TPrefix extends string, TServer extends Record<string, ZodType>, TClient extends Record<string, ZodType>> extends BaseOptions { | ||
interface StrictOptions<TPrefix extends string, TServer extends Record<string, ZodType>, TClient extends Record<string, ZodType>, TShared extends Record<string, ZodType>> extends BaseOptions<TShared> { | ||
runtimeEnvStrict: Record<{ | ||
@@ -25,3 +26,5 @@ [TKey in keyof TClient]: TKey extends `${TPrefix}${string}` ? TKey : never; | ||
[TKey in keyof TServer]: TKey extends `${TPrefix}${string}` ? never : TKey; | ||
}[keyof TServer], string | boolean | number | undefined>; | ||
}[keyof TServer] | { | ||
[TKey in keyof TShared]: TKey extends string ? TKey : never; | ||
}[keyof TShared], string | boolean | number | undefined>; | ||
runtimeEnv?: never; | ||
@@ -41,5 +44,5 @@ } | ||
type ServerClientOptions<TPrefix extends string, TServer extends Record<string, ZodType>, TClient extends Record<string, ZodType>> = (ClientOptions<TPrefix, TClient> & ServerOptions<TPrefix, TServer>) | (ServerOptions<TPrefix, TServer> & Impossible<ClientOptions<never, never>>) | (ClientOptions<TPrefix, TClient> & Impossible<ServerOptions<never, never>>); | ||
type EnvOptions<TPrefix extends string, TServer extends Record<string, ZodType>, TClient extends Record<string, ZodType>> = (LooseOptions & ServerClientOptions<TPrefix, TServer, TClient>) | (StrictOptions<TPrefix, TServer, TClient> & ServerClientOptions<TPrefix, TServer, TClient>); | ||
declare function createEnv<TPrefix extends string = "", TServer extends Record<string, ZodType> = NonNullable<unknown>, TClient extends Record<string, ZodType> = NonNullable<unknown>>(opts: EnvOptions<TPrefix, TServer, TClient>): Simplify<z.infer<ZodObject<TServer>> & z.infer<ZodObject<TClient>>>; | ||
type EnvOptions<TPrefix extends string, TServer extends Record<string, ZodType>, TClient extends Record<string, ZodType>, TShared extends Record<string, ZodType>> = (LooseOptions<TShared> & ServerClientOptions<TPrefix, TServer, TClient>) | (StrictOptions<TPrefix, TServer, TClient, TShared> & ServerClientOptions<TPrefix, TServer, TClient>); | ||
declare function createEnv<TPrefix extends string = "", TServer extends Record<string, ZodType> = NonNullable<unknown>, TClient extends Record<string, ZodType> = NonNullable<unknown>, TShared extends Record<string, ZodType> = NonNullable<unknown>>(opts: EnvOptions<TPrefix, TServer, TClient, TShared>): Simplify<z.infer<ZodObject<TServer>> & z.infer<ZodObject<TClient>> & z.infer<ZodObject<TShared>>>; | ||
export { BaseOptions, ClientOptions, EnvOptions, ErrorMessage, LooseOptions, ServerClientOptions, ServerOptions, Simplify, StrictOptions, createEnv }; |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var _zod = require('zod');function g(e){let t=_nullishCoalesce(_nullishCoalesce(e.runtimeEnvStrict, () => (e.runtimeEnv)), () => (process.env));if(!!e.skipValidation)return t;let d=typeof e.client=="object"?e.client:{},v=typeof e.server=="object"?e.server:{},o=_zod.z.object(d),l=_zod.z.object(v),s=_nullishCoalesce(e.isServer, () => (typeof window>"u")),a=l.merge(o),i=s?a.safeParse(t):o.safeParse(t),c=_nullishCoalesce(e.onValidationError, () => ((r=>{throw console.error("\u274C Invalid environment variables:",r.flatten().fieldErrors),new Error("Invalid environment variables")}))),f=_nullishCoalesce(e.onInvalidAccess, () => ((r=>{throw new Error("\u274C Attempted to access a server-side environment variable on the client")})));return i.success===!1?c(i.error):new Proxy(i.data,{get(r,n){if(typeof n=="string")return!s&&e.clientPrefix&&!n.startsWith(e.clientPrefix)?f(n):r[n]}})}exports.createEnv = g; | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var _zod = require('zod');function h(e){let t=_nullishCoalesce(_nullishCoalesce(e.runtimeEnvStrict, () => (e.runtimeEnv)), () => (process.env));if(!!e.skipValidation)return t;let a=typeof e.client=="object"?e.client:{},l=typeof e.server=="object"?e.server:{},c=typeof e.shared=="object"?e.shared:{},d=_zod.z.object(a),v=_zod.z.object(l),i=_zod.z.object(c),T=_nullishCoalesce(e.isServer, () => (typeof window>"u")),f=d.merge(i),x=v.merge(i).merge(d),s=T?x.safeParse(t):f.safeParse(t),y=_nullishCoalesce(e.onValidationError, () => ((n=>{throw console.error("\u274C Invalid environment variables:",n.flatten().fieldErrors),new Error("Invalid environment variables")}))),p=_nullishCoalesce(e.onInvalidAccess, () => ((n=>{throw new Error("\u274C Attempted to access a server-side environment variable on the client")})));return s.success===!1?y(s.error):new Proxy(s.data,{get(n,r){if(typeof r=="string")return!T&&e.clientPrefix&&!r.startsWith(e.clientPrefix)&&i.shape[r]===void 0?p(r):n[r]}})}exports.createEnv = h; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@t3-oss/env-core", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"keywords": [ | ||
@@ -5,0 +5,0 @@ "create-t3-app", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24792
54