@t3-oss/env-nextjs
Advanced tools
Comparing version 0.4.1-canary.40f9204 to 0.4.1
@@ -5,2 +5,3 @@ import * as zod from 'zod'; | ||
type ErrorMessage<T extends string> = T; | ||
type Impossible<T extends Record<string, any>> = Partial<Record<keyof T, never>>; | ||
interface BaseOptions { | ||
@@ -12,20 +13,2 @@ isServer?: boolean; | ||
} | ||
interface ClientOptions<TPrefix extends string, TClient extends Record<string, ZodType>> { | ||
clientPrefix: TPrefix; | ||
client: { | ||
[TKey in keyof TClient]: TKey extends `${TPrefix}${string}` ? TClient[TKey] : ErrorMessage<`${TKey extends string ? TKey : never} is not prefixed with ${TPrefix}.`>; | ||
}; | ||
} | ||
interface WithoutClientOptions { | ||
clientPrefix?: never; | ||
client?: never; | ||
} | ||
interface ServerOptions<TPrefix extends string, TServer extends Record<string, ZodType>> { | ||
server: { | ||
[TKey in keyof TServer]: TPrefix extends "" ? TServer[TKey] : TKey extends `${TPrefix}${string}` ? ErrorMessage<`${TKey extends `${TPrefix}${string}` ? TKey : never} should not prefixed with ${TPrefix}.`> : TServer[TKey]; | ||
}; | ||
} | ||
interface WithoutServerOptions { | ||
server?: never; | ||
} | ||
interface StrictOptions<TPrefix extends string, TServer extends Record<string, ZodType>, TClient extends Record<string, ZodType>> extends BaseOptions { | ||
@@ -39,3 +22,14 @@ runtimeEnvStrict: Record<{ | ||
} | ||
type ServerClientOptions<TPrefix extends string, TServer extends Record<string, ZodType>, TClient extends Record<string, ZodType>> = (ClientOptions<TPrefix, TClient> & ServerOptions<TPrefix, TServer>) | (WithoutClientOptions & ServerOptions<TPrefix, TServer>) | (ClientOptions<TPrefix, TClient> & WithoutServerOptions); | ||
interface ClientOptions<TPrefix extends string, TClient extends Record<string, ZodType>> { | ||
clientPrefix: TPrefix; | ||
client: Partial<{ | ||
[TKey in keyof TClient]: TKey extends `${TPrefix}${string}` ? TClient[TKey] : ErrorMessage<`${TKey extends string ? TKey : never} is not prefixed with ${TPrefix}.`>; | ||
}>; | ||
} | ||
interface ServerOptions<TPrefix extends string, TServer extends Record<string, ZodType>> { | ||
server: Partial<{ | ||
[TKey in keyof TServer]: TPrefix extends "" ? TServer[TKey] : TKey extends `${TPrefix}${string}` ? ErrorMessage<`${TKey extends `${TPrefix}${string}` ? TKey : never} should not prefixed with ${TPrefix}.`> : TServer[TKey]; | ||
}>; | ||
} | ||
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>>); | ||
@@ -45,3 +39,3 @@ declare const CLIENT_PREFIX: "NEXT_PUBLIC_"; | ||
interface Options<TServer extends Record<string, ZodType>, TClient extends Record<`${ClientPrefix}${string}`, ZodType>> extends Omit<StrictOptions<ClientPrefix, TServer, TClient> & ServerClientOptions<ClientPrefix, TServer, TClient>, "runtimeEnvStrict" | "runtimeEnv" | "clientPrefix"> { | ||
runtimeEnv?: StrictOptions<ClientPrefix, TServer, TClient>["runtimeEnvStrict"]; | ||
runtimeEnv: StrictOptions<ClientPrefix, TServer, TClient>["runtimeEnvStrict"]; | ||
} | ||
@@ -48,0 +42,0 @@ declare function createEnv<TServer extends Record<string, ZodType> = NonNullable<unknown>, TClient extends Record<`${ClientPrefix}${string}`, ZodType> = NonNullable<unknown>>({ runtimeEnv, ...opts }: Options<TServer, TClient>): (zod.objectUtil.addQuestionMarks<{ [k_1 in keyof TServer]: TServer[k_1]["_output"]; }> extends infer T_3 extends object ? { [k in keyof T_3]: zod.objectUtil.addQuestionMarks<{ [k_1 in keyof TServer]: TServer[k_1]["_output"]; }>[k]; } : never) & (zod.objectUtil.addQuestionMarks<{ [k_2 in keyof TClient]: TClient[k_2]["_output"]; }> extends infer T_4 extends object ? { [k_1 in keyof T_4]: zod.objectUtil.addQuestionMarks<{ [k_2 in keyof TClient]: TClient[k_2]["_output"]; }>[k_1]; } : never) extends infer T ? { [P in keyof T]: ((zod.objectUtil.addQuestionMarks<{ [k_1 in keyof TServer]: TServer[k_1]["_output"]; }> extends infer T_1 extends object ? { [k in keyof T_1]: zod.objectUtil.addQuestionMarks<{ [k_1 in keyof TServer]: TServer[k_1]["_output"]; }>[k]; } : never) & (zod.objectUtil.addQuestionMarks<{ [k_2 in keyof TClient]: TClient[k_2]["_output"]; }> extends infer T_2 extends object ? { [k_1 in keyof T_2]: zod.objectUtil.addQuestionMarks<{ [k_2 in keyof TClient]: TClient[k_2]["_output"]; }>[k_1]; } : never))[P]; } : never; |
@@ -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 T(e){let r=_nullishCoalesce(_nullishCoalesce(e.runtimeEnvStrict, () => (e.runtimeEnv)), () => (process.env));if(e.skipValidation)return r;let i=typeof e.client=="object"?e.client:{},o=typeof e.server=="object"?e.server:{},l=_zod.z.object(i),a=_zod.z.object(o),c=_nullishCoalesce(e.isServer, () => (typeof window>"u")),f=a.merge(l),s=c?f.safeParse(r):l.safeParse(r),d=_nullishCoalesce(e.onValidationError, () => ((t=>{throw console.error("\u274C Invalid environment variables:",t.flatten().fieldErrors),new Error("Invalid environment variables")}))),p=_nullishCoalesce(e.onInvalidAccess, () => ((t=>{throw new Error("\u274C Attempted to access a server-side environment variable on the client")})));return s.success===!1?d(s.error):new Proxy(s.data,{get(t,n){if(typeof n=="string")return!c&&e.clientPrefix&&!n.startsWith(e.clientPrefix)?p(n):t[n]}})}var C="NEXT_PUBLIC_";function P({runtimeEnv:e,...r}){let i=typeof r.client=="object"?r.client:{},o=typeof r.server=="object"?r.server:{};return T({...r,client:i,server:o,clientPrefix:C,runtimeEnv:_nullishCoalesce(e, () => (process.env))})}exports.createEnv = P; | ||
"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 a(e){let r=_nullishCoalesce(_nullishCoalesce(e.runtimeEnvStrict, () => (e.runtimeEnv)), () => (process.env));if(e.skipValidation)return r;let i=typeof e.client=="object"?e.client:{},o=typeof e.server=="object"?e.server:{},c=_zod.z.object(i),f=_zod.z.object(o),l=_nullishCoalesce(e.isServer, () => (typeof window>"u")),p=f.merge(c),s=l?p.safeParse(r):c.safeParse(r),d=_nullishCoalesce(e.onValidationError, () => ((t=>{throw console.error("\u274C Invalid environment variables:",t.flatten().fieldErrors),new Error("Invalid environment variables")}))),T=_nullishCoalesce(e.onInvalidAccess, () => ((t=>{throw new Error("\u274C Attempted to access a server-side environment variable on the client")})));return s.success===!1?d(s.error):new Proxy(s.data,{get(t,n){if(typeof n=="string")return!l&&e.clientPrefix&&!n.startsWith(e.clientPrefix)?T(n):t[n]}})}var C="NEXT_PUBLIC_";function P({runtimeEnv:e,...r}){let i=typeof r.client=="object"?r.client:{},o=typeof r.server=="object"?r.server:{};return a({...r,client:i,server:o,clientPrefix:C,runtimeEnvStrict:e})}exports.createEnv = P; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@t3-oss/env-nextjs", | ||
"version": "0.4.1-canary.40f9204", | ||
"version": "0.4.1", | ||
"keywords": [ | ||
@@ -35,3 +35,3 @@ "create-t3-app", | ||
"dependencies": { | ||
"@t3-oss/env-core": "0.4.0" | ||
"@t3-oss/env-core": "0.4.1" | ||
}, | ||
@@ -38,0 +38,0 @@ "peerDependencies": { |
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
2
26512
52
+ Added@t3-oss/env-core@0.4.1(transitive)
- Removed@t3-oss/env-core@0.4.0(transitive)
Updated@t3-oss/env-core@0.4.1