@arkenv/nextjs 0.1.1 → 0.1.2
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/client.cjs +1 -1
- package/dist/client.js +1 -1
- package/dist/config.cjs +12 -11
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.cts +16 -1
- package/dist/config.d.cts.map +1 -1
- package/dist/config.d.ts +16 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +12 -11
- package/dist/config.js.map +1 -1
- package/dist/create-env-CRDyrJOZ.js +2 -0
- package/dist/create-env-CRDyrJOZ.js.map +1 -0
- package/dist/create-env-o205_sj3.cjs +2 -0
- package/dist/{create-env-B6DmIK3X.js.map → create-env-o205_sj3.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/react-server.cjs +1 -1
- package/dist/react-server.js +1 -1
- package/dist/server.cjs +1 -1
- package/dist/server.js +1 -1
- package/dist/shared.cjs +1 -1
- package/dist/shared.js +1 -1
- package/package.json +6 -3
- package/dist/create-env-B6DmIK3X.js +0 -2
- package/dist/create-env-C_h541CQ.cjs +0 -2
- package/dist/create-env-C_h541CQ.cjs.map +0 -1
package/dist/client.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./create-env-
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./create-env-o205_sj3.cjs`);require(`./config.cjs`);let t=require(`arkenv`);function n(t,n){if(t&&typeof t==`object`&&(`runtimeEnv`in t||`client`in t||`shared`in t)){if(`server`in t)throw Error(`client entry point only accepts 'client' and 'shared' schemas.`);return e.t(t,!1)}return e.t(t,n,{isServer:!1,strictLayout:`client`})}const r=n;exports.createEnv=n,exports.default=r,Object.defineProperty(exports,`type`,{enumerable:!0,get:function(){return t.type}});
|
|
2
2
|
//# sourceMappingURL=client.cjs.map
|
package/dist/client.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"./create-env-
|
|
1
|
+
import{t as e}from"./create-env-CRDyrJOZ.js";import{type as t}from"arkenv";function n(t,n){if(t&&typeof t==`object`&&(`runtimeEnv`in t||`client`in t||`shared`in t)){if(`server`in t)throw Error(`client entry point only accepts 'client' and 'shared' schemas.`);return e(t,!1)}return e(t,n,{isServer:!1,strictLayout:`client`})}const r=n;export{n as createEnv,r as default,t as type};
|
|
2
2
|
//# sourceMappingURL=client.js.map
|
package/dist/config.cjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`node:fs`);c=s(c,1);let l=require(`node:path`);l=s(l,1);let u=require(`@arkenv/build`),
|
|
2
|
-
|
|
3
|
-
`)}
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`node:fs`);c=s(c,1);let l=require(`node:path`);l=s(l,1);let u=require(`node:url`),d=require(`@arkenv/build`),f=require(`jiti`),p=!1;function m(e){return e===`simple`?(process.env.NODE_ENV===`development`&&!p&&(p=!0,console.warn(`⚠️ [arkenv] The 'simple' layout option is deprecated and will be removed in the next major version. Use 'flat' instead.`)),`simple`):e===`flat`?`simple`:e}function h(e,t){let n=e?.schemaPath?l.default.resolve(e.schemaPath):(0,d.findSchemaPath)(),r=!1;if(n)if(c.default.existsSync(n))r=!0;else{let e=l.default.extname(n);if(e){let t=n.slice(0,-e.length);c.default.existsSync(t)&&(r=!0)}}if(!n||!r)throw Error(`[ArkEnv] Could not find schema file at ${e?.schemaPath||`src/env.ts or env.ts`}. Please specify 'schemaPath' in setupArkEnv options.`);let{layout:i,baseDir:a}=(0,d.resolveLayout)(n,m(e?.layout)),o=i===`strict`&&a?a:l.default.dirname(n),s=l.default.join(o,`generated`,`env.gen.ts`),p=e?.outputPath?l.default.resolve(e.outputPath):s,h=e?.codegen??!0;if(h)try{_(n,p,i)}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`[ArkEnv] Failed to generate env.gen.ts: ${t}`)}if(e?.validate??!0)try{globalThis.__arkenv_force_server__=!0;let e=i===`strict`&&a?l.default.join(a,`server.ts`):n,r=typeof __filename<`u`?__filename:require(`url`).pathToFileURL(__filename).href?(0,u.fileURLToPath)(require(`url`).pathToFileURL(__filename).href):``,o=l.default.dirname(r),s=c.default.existsSync(l.default.join(o,`shared.ts`))?l.default.join(o,`shared.ts`):l.default.join(o,`shared.js`);(0,f.createJiti)(e,{moduleCache:!1,fsCache:!1,tsconfigPaths:!0,alias:{"server-only":s,"./script":s,"./script.tsx":s,...t?._jitiAliases}})(e)}catch(e){console.error(`
|
|
2
|
+
❌ [ArkEnv] Environment validation failed:`),console.error(e instanceof Error?e.message:String(e)),console.error(``),process.exit(1)}finally{delete globalThis.__arkenv_force_server__}(process.env.NODE_ENV===`development`||process.env.NEXT_PHASE===`phase-development-server`)&&h&&(0,d.watchSchema)(i===`strict`&&a?[l.default.join(a,`internal`,`shared.ts`),l.default.join(a,`client.ts`),l.default.join(a,`server.ts`)].filter(c.default.existsSync):[n],()=>{_(n,p,i)})}function g(e,t){return h(t),e}function _(e,t,n){let{layout:r,baseDir:i}=(0,d.resolveLayout)(e,m(n)),a=``;if(r===`strict`){let e=l.default.join(i,`client.ts`),t=l.default.join(i,`internal`,`shared.ts`),n=c.default.existsSync(e)?c.default.readFileSync(e,`utf-8`):``,r=c.default.existsSync(t)?c.default.readFileSync(t,`utf-8`):``;a=T((0,d.extractClientKeys)(n),(0,d.extractSharedKeys)(r))}else{let{clientKeys:t,sharedKeys:n,isLegacy:r}=y(c.default.readFileSync(e,`utf-8`));a=r?C(t,n):w(t,n)}let o=l.default.dirname(t);c.default.existsSync(o)||c.default.mkdirSync(o,{recursive:!0});let s=!0;c.default.existsSync(t)&&c.default.readFileSync(t,`utf-8`)===a&&(s=!1),s&&c.default.writeFileSync(t,a,`utf-8`)}function v(e){let t=/\b(?:arkenv|createEnv)\s*\(/g;for(;t.exec(e)!==null;){let n=1,r=t.lastIndex,i=null,a=null,o=0,s=0,c=[],l=``;for(;r<e.length&&n>0;){let t=e[r],u=e[r+1];if(a===`single`){(t===`
|
|
3
|
+
`||t===`\r`)&&(a=null),l+=t,r++;continue}if(a===`multi`){if(t===`*`&&u===`/`){a=null,l+=`*/`,r+=2;continue}l+=t,r++;continue}if(i){t===i&&e[r-1]!==`\\`&&(i=null),l+=t,r++;continue}if(t===`/`&&u===`/`){a=`single`,l+=`//`,r+=2;continue}if(t===`/`&&u===`*`){a=`multi`,l+=`/*`,r+=2;continue}if(t===`'`||t===`"`||t==="`"){i=t,l+=t,r++;continue}if(t===`(`?n++:t===`)`?n--:t===`{`?o++:t===`}`?o--:t===`[`?s++:t===`]`&&s--,n===0){c.push(l);break}t===`,`&&n===1&&o===0&&s===0?(c.push(l),l=``):l+=t,r++}if(n===0&&c.length>0)return{schemaArg:c[0].trim(),optionsArg:c[1]?c[1].trim():null}}return null}function y(e){let t=[],n=[],r=v(e);if(!r)return{clientKeys:t,sharedKeys:n,isLegacy:!1};let i=(0,d.parseBlockKeys)(r.schemaArg.replace(/^\{/,``).replace(/\}$/,``).trim()),a=i.includes(`client`)||i.includes(`server`)||i.includes(`shared`);if(a){let e=(0,d.extractBlock)(r.schemaArg,`client`);e&&t.push(...(0,d.parseBlockKeys)(e));let i=(0,d.extractBlock)(r.schemaArg,`shared`);i&&n.push(...(0,d.parseBlockKeys)(i))}else{let e=[];if(r.optionsArg){let t=r.optionsArg.match(/exposeToClient\s*:\s*\[([\s\S]*?)\]/)||r.optionsArg.match(/expose\s*:\s*\[([\s\S]*?)\]/)||r.optionsArg.match(/shared\s*:\s*\[([\s\S]*?)\]/);if(t){let n=t[1].matchAll(/['"`](.*?)['"`]/g);for(let t of n)e.push(t[1])}}for(let r of i)e.includes(r)||r===`NODE_ENV`?n.push(r):r.startsWith(`NEXT_PUBLIC_`)&&t.push(r)}return{clientKeys:t,sharedKeys:n,isLegacy:a}}function b(e,t){return Array.from(new Set([...e,...t])).map(e=>`\t\t\t${e}: typeof window !== "undefined" ? (globalThis as any).__arkenv_env__?.${e} ?? process.env.${e} : process.env.${e},`).join(`
|
|
4
|
+
`)}const x=`/* eslint-disable */
|
|
4
5
|
// biome-ignore format: auto-generated
|
|
5
6
|
// Generated by ArkEnv. DO NOT EDIT DIRECTLY.
|
|
6
|
-
`,
|
|
7
|
+
`,S=`
|
|
7
8
|
export default createEnv;
|
|
8
|
-
`;function
|
|
9
|
+
`;function C(e,t){return`${x}
|
|
9
10
|
import { createEnv as coreCreateEnv } from "@arkenv/nextjs";
|
|
10
11
|
|
|
11
12
|
export { type } from "@arkenv/nextjs";
|
|
@@ -24,11 +25,11 @@ export function createEnv<
|
|
|
24
25
|
return coreCreateEnv({
|
|
25
26
|
...options,
|
|
26
27
|
runtimeEnv: {
|
|
27
|
-
${
|
|
28
|
+
${b(e,t)}
|
|
28
29
|
},
|
|
29
30
|
} as any) as any;
|
|
30
31
|
}
|
|
31
|
-
${
|
|
32
|
+
${S}`}function w(e,t){return`${x}
|
|
32
33
|
import { createEnv as coreCreateEnv } from "@arkenv/nextjs";
|
|
33
34
|
import type { type as at, distill } from "arktype";
|
|
34
35
|
|
|
@@ -56,12 +57,12 @@ export function createEnv<
|
|
|
56
57
|
const env = coreCreateEnv(schema as any, {
|
|
57
58
|
...options,
|
|
58
59
|
runtimeEnv: {
|
|
59
|
-
${
|
|
60
|
+
${b(e,t)}
|
|
60
61
|
},
|
|
61
62
|
} as any);
|
|
62
63
|
return env as unknown as Readonly<distill.Out<at.infer<TSchema>>>;
|
|
63
64
|
}
|
|
64
|
-
${
|
|
65
|
+
${S}`}function T(e,t){return`${x}
|
|
65
66
|
import { createEnv as coreCreateEnv } from "@arkenv/nextjs/client";
|
|
66
67
|
|
|
67
68
|
export { type } from "@arkenv/nextjs/client";
|
|
@@ -80,9 +81,9 @@ export function createEnv<
|
|
|
80
81
|
return coreCreateEnv<TSchema, TExtends>(schema as any, {
|
|
81
82
|
...options,
|
|
82
83
|
runtimeEnv: {
|
|
83
|
-
${
|
|
84
|
+
${b(e,t)}
|
|
84
85
|
},
|
|
85
86
|
} as any);
|
|
86
87
|
}
|
|
87
|
-
${
|
|
88
|
+
${S}`}exports.extractClientKeys=d.extractClientKeys,exports.extractKeys=y,exports.extractSharedKeys=d.extractSharedKeys,exports.runCodegen=_,exports.setupArkEnv=h,exports.t=s,exports.withArkEnv=g;
|
|
88
89
|
//# sourceMappingURL=config.cjs.map
|
package/dist/config.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.cjs","names":["path","fs"],"sources":["../src/config.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport {\n\textractBlock,\n\textractClientKeys,\n\textractSharedKeys,\n\tfindSchemaPath,\n\tparseBlockKeys,\n\tresolveLayout,\n\twatchSchema,\n} from \"@arkenv/build\";\n\nexport { extractClientKeys, extractSharedKeys };\n\nlet hasWarnedSimpleLayout = false;\n\nfunction normalizeLayout(\n\tlayout: ArkEnvConfigOptions[\"layout\"],\n): \"simple\" | \"strict\" | undefined {\n\tif (layout === \"simple\") {\n\t\tif (process.env.NODE_ENV === \"development\" && !hasWarnedSimpleLayout) {\n\t\t\thasWarnedSimpleLayout = true;\n\t\t\tconsole.warn(\n\t\t\t\t\"⚠️ [arkenv] The 'simple' layout option is deprecated and will be removed in the next major version. Use 'flat' instead.\",\n\t\t\t);\n\t\t}\n\t\treturn \"simple\";\n\t}\n\tif (layout === \"flat\") {\n\t\treturn \"simple\";\n\t}\n\treturn layout;\n}\n\n/**\n * Configuration options for the ArkEnv Next.js integration.\n *\n * @example\n * ```ts\n * const configOptions: ArkEnvConfigOptions = {\n * schemaPath: \"./src/env.ts\",\n * outputPath: \"./src/generated/env.gen.ts\"\n * };\n * ```\n */\nexport type ArkEnvConfigOptions = {\n\t/**\n\t * Specify the path to the schema definition file.\n\t *\n\t * Defaults to searching for `\"src/env.ts\"` or `\"env.ts\"` in the project root.\n\t *\n\t * @default \"src/env.ts\"\n\t * @example\n\t * ```ts\n\t * export default withArkEnv(nextConfig, {\n\t * schemaPath: \"./src/env.ts\"\n\t * });\n\t * ```\n\t */\n\tschemaPath?: string;\n\n\t/**\n\t * Specify the path where the generated file (`env.gen.ts`) should be written.\n\t *\n\t * Defaults to `\"generated/env.gen.ts\"` in the same directory as the schema file.\n\t *\n\t * @default \"[schemaDirectory]/generated/env.gen.ts\"\n\t * @example\n\t * ```ts\n\t * export default withArkEnv(nextConfig, {\n\t * outputPath: \"./src/generated/env.gen.ts\"\n\t * });\n\t * ```\n\t */\n\toutputPath?: string;\n\n\t/**\n\t * Specify the configuration layout.\n\t *\n\t * - `\"flat\"` (default): A single `env.ts` schema file.\n\t * - `\"strict\"`: A 3-file split schema layout (`env/internal/shared.ts`, `env/client.ts`, `env/server.ts`).\n\t *\n\t * @default \"flat\"\n\t */\n\tlayout?:\n\t\t| \"flat\"\n\t\t| \"strict\"\n\t\t/** @deprecated Use `\"flat\"` instead. `\"simple\"` will be removed in the next major version. */\n\t\t| \"simple\";\n};\n\n/**\n * Run ArkEnv codegen and setup without wrapping nextConfig.\n *\n * @param options Optional configuration paths for schema and output files\n * @throws An error if the schema file cannot be found or if code generation fails\n */\nexport function setupArkEnv(options?: ArkEnvConfigOptions): void {\n\t// 1. Locate the env.ts schema file or strict schema directory\n\tconst schemaPath = options?.schemaPath\n\t\t? path.resolve(options.schemaPath)\n\t\t: findSchemaPath();\n\n\t// Auto-detect layout if not specified\n\tlet exists = false;\n\tif (schemaPath) {\n\t\tif (fs.existsSync(schemaPath)) {\n\t\t\texists = true;\n\t\t} else {\n\t\t\tconst ext = path.extname(schemaPath);\n\t\t\tif (ext) {\n\t\t\t\tconst baseWithoutExt = schemaPath.slice(0, -ext.length);\n\t\t\t\tif (fs.existsSync(baseWithoutExt)) {\n\t\t\t\t\texists = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (!schemaPath || !exists) {\n\t\tthrow new Error(\n\t\t\t`[ArkEnv] Could not find schema file at ${\n\t\t\t\toptions?.schemaPath || \"src/env.ts or env.ts\"\n\t\t\t}. Please specify 'schemaPath' in setupArkEnv options.`,\n\t\t);\n\t}\n\n\tconst normalizedLayout = normalizeLayout(options?.layout);\n\n\tconst { layout: resolvedLayout, baseDir } = resolveLayout(\n\t\tschemaPath,\n\t\tnormalizedLayout,\n\t);\n\n\t// 2. Determine outputPath (defaults to generated/env.gen.ts in the same directory as schemaPath/baseDir)\n\tconst defaultOutputDir =\n\t\tresolvedLayout === \"strict\" && baseDir ? baseDir : path.dirname(schemaPath);\n\tconst defaultOutputPath = path.join(\n\t\tdefaultOutputDir,\n\t\t\"generated\",\n\t\t\"env.gen.ts\",\n\t);\n\tconst outputPath = options?.outputPath\n\t\t? path.resolve(options.outputPath)\n\t\t: defaultOutputPath;\n\n\t// 3. Run initial code generation\n\ttry {\n\t\trunCodegen(schemaPath, outputPath, resolvedLayout);\n\t} catch (error: unknown) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tthrow new Error(`[ArkEnv] Failed to generate env.gen.ts: ${message}`);\n\t}\n\n\t// 4. Initialize development file watcher if in dev mode\n\tconst isDev =\n\t\tprocess.env.NODE_ENV === \"development\" ||\n\t\tprocess.env.NEXT_PHASE === \"phase-development-server\";\n\tif (isDev) {\n\t\tconst watchPaths =\n\t\t\tresolvedLayout === \"strict\" && baseDir\n\t\t\t\t? [\n\t\t\t\t\t\tpath.join(baseDir, \"internal\", \"shared.ts\"),\n\t\t\t\t\t\tpath.join(baseDir, \"client.ts\"),\n\t\t\t\t\t\tpath.join(baseDir, \"server.ts\"),\n\t\t\t\t\t].filter(fs.existsSync)\n\t\t\t\t: [schemaPath];\n\t\twatchSchema(watchPaths, () => {\n\t\t\trunCodegen(schemaPath, outputPath, resolvedLayout);\n\t\t});\n\t}\n}\n\n/**\n * Wrap a Next.js configuration object to automatically generate the `runtimeEnv` block in `env.gen.ts`.\n *\n * @param nextConfig The Next.js configuration object or function\n * @param options Optional configuration paths for schema and output files\n * @returns The Next.js configuration object unchanged\n * @throws An error if the schema file cannot be found or if code generation fails\n */\nexport function withArkEnv<T>(nextConfig: T, options?: ArkEnvConfigOptions): T {\n\tsetupArkEnv(options);\n\treturn nextConfig;\n}\n\n/**\n * Run code generation to read the schema file and generate the env.gen.ts factory.\n *\n * @param schemaPath The absolute path to the schema file or directory\n * @param outputPath The absolute path to the generated output file\n * @param layoutOption The explicit layout to use; auto-detected from the filesystem when omitted\n * @throws An error if strict layout files are missing when `layoutOption` is `\"strict\"`\n */\nexport function runCodegen(\n\tschemaPath: string,\n\toutputPath: string,\n\tlayoutOption?: ArkEnvConfigOptions[\"layout\"],\n) {\n\tconst normalizedLayout = normalizeLayout(layoutOption);\n\n\tconst { layout: resolvedLayout, baseDir } = resolveLayout(\n\t\tschemaPath,\n\t\tnormalizedLayout,\n\t);\n\n\tlet generatedCode = \"\";\n\tif (resolvedLayout === \"strict\") {\n\t\tconst clientPath = path.join(baseDir, \"client.ts\");\n\t\tconst sharedPath = path.join(baseDir, \"internal\", \"shared.ts\");\n\n\t\tconst clientContent = fs.existsSync(clientPath)\n\t\t\t? fs.readFileSync(clientPath, \"utf-8\")\n\t\t\t: \"\";\n\t\tconst sharedContent = fs.existsSync(sharedPath)\n\t\t\t? fs.readFileSync(sharedPath, \"utf-8\")\n\t\t\t: \"\";\n\n\t\tconst clientKeys = extractClientKeys(clientContent);\n\t\tconst sharedKeys = extractSharedKeys(sharedContent);\n\n\t\tgeneratedCode = generateClientFactoryCode(clientKeys, sharedKeys);\n\t} else {\n\t\tconst fileContent = fs.readFileSync(schemaPath, \"utf-8\");\n\t\tconst { clientKeys, sharedKeys, isLegacy } = extractKeys(fileContent);\n\t\tif (isLegacy) {\n\t\t\tgeneratedCode = generateFactoryCode(clientKeys, sharedKeys);\n\t\t} else {\n\t\t\tgeneratedCode = generateFlatFactoryCode(clientKeys, sharedKeys);\n\t\t}\n\t}\n\n\t// Ensure parent directory exists\n\tconst outputDir = path.dirname(outputPath);\n\tif (!fs.existsSync(outputDir)) {\n\t\tfs.mkdirSync(outputDir, { recursive: true });\n\t}\n\n\t// Write if changed to avoid unnecessary filesystem/watcher triggers\n\tlet shouldWrite = true;\n\tif (fs.existsSync(outputPath)) {\n\t\tconst existingContent = fs.readFileSync(outputPath, \"utf-8\");\n\t\tif (existingContent === generatedCode) {\n\t\t\tshouldWrite = false;\n\t\t}\n\t}\n\n\tif (shouldWrite) {\n\t\tfs.writeFileSync(outputPath, generatedCode, \"utf-8\");\n\t}\n}\n\nfunction extractCallArguments(\n\tcontent: string,\n): { schemaArg: string; optionsArg: string | null } | null {\n\tconst regex = /\\b(?:arkenv|createEnv)\\s*\\(/g;\n\twhile (regex.exec(content) !== null) {\n\t\tlet parenCount = 1;\n\t\tlet index = regex.lastIndex;\n\t\tlet inString: string | null = null;\n\t\tlet inComment: \"single\" | \"multi\" | null = null;\n\t\tlet braceCount = 0;\n\t\tlet bracketCount = 0;\n\n\t\tconst args: string[] = [];\n\t\tlet currentArg = \"\";\n\n\t\twhile (index < content.length && parenCount > 0) {\n\t\t\tconst char = content[index];\n\t\t\tconst nextChar = content[index + 1];\n\n\t\t\tif (inComment === \"single\") {\n\t\t\t\tif (char === \"\\n\" || char === \"\\r\") inComment = null;\n\t\t\t\tcurrentArg += char;\n\t\t\t\tindex++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (inComment === \"multi\") {\n\t\t\t\tif (char === \"*\" && nextChar === \"/\") {\n\t\t\t\t\tinComment = null;\n\t\t\t\t\tcurrentArg += \"*/\";\n\t\t\t\t\tindex += 2;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tcurrentArg += char;\n\t\t\t\tindex++;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (inString) {\n\t\t\t\tif (char === inString && content[index - 1] !== \"\\\\\") {\n\t\t\t\t\tinString = null;\n\t\t\t\t}\n\t\t\t\tcurrentArg += char;\n\t\t\t\tindex++;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (char === \"/\" && nextChar === \"/\") {\n\t\t\t\tinComment = \"single\";\n\t\t\t\tcurrentArg += \"//\";\n\t\t\t\tindex += 2;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (char === \"/\" && nextChar === \"*\") {\n\t\t\t\tinComment = \"multi\";\n\t\t\t\tcurrentArg += \"/*\";\n\t\t\t\tindex += 2;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (char === \"'\" || char === '\"' || char === \"`\") {\n\t\t\t\tinString = char;\n\t\t\t\tcurrentArg += char;\n\t\t\t\tindex++;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (char === \"(\") {\n\t\t\t\tparenCount++;\n\t\t\t} else if (char === \")\") {\n\t\t\t\tparenCount--;\n\t\t\t} else if (char === \"{\") {\n\t\t\t\tbraceCount++;\n\t\t\t} else if (char === \"}\") {\n\t\t\t\tbraceCount--;\n\t\t\t} else if (char === \"[\") {\n\t\t\t\tbracketCount++;\n\t\t\t} else if (char === \"]\") {\n\t\t\t\tbracketCount--;\n\t\t\t}\n\n\t\t\tif (parenCount === 0) {\n\t\t\t\targs.push(currentArg);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tchar === \",\" &&\n\t\t\t\tparenCount === 1 &&\n\t\t\t\tbraceCount === 0 &&\n\t\t\t\tbracketCount === 0\n\t\t\t) {\n\t\t\t\targs.push(currentArg);\n\t\t\t\tcurrentArg = \"\";\n\t\t\t} else {\n\t\t\t\tcurrentArg += char;\n\t\t\t}\n\t\t\tindex++;\n\t\t}\n\n\t\tif (parenCount === 0 && args.length > 0) {\n\t\t\treturn {\n\t\t\t\tschemaArg: args[0].trim(),\n\t\t\t\toptionsArg: args[1] ? args[1].trim() : null,\n\t\t\t};\n\t\t}\n\t}\n\treturn null;\n}\n\n/**\n * Statically extract client and shared keys from the schema content.\n *\n * @param content The schema file string content\n * @returns An object containing the extracted client and shared keys\n */\nexport function extractKeys(content: string): {\n\tclientKeys: string[];\n\tsharedKeys: string[];\n\tisLegacy?: boolean;\n} {\n\tconst clientKeys: string[] = [];\n\tconst sharedKeys: string[] = [];\n\n\tconst args = extractCallArguments(content);\n\tif (!args) {\n\t\treturn { clientKeys, sharedKeys, isLegacy: false };\n\t}\n\n\t// Strip outer braces if present\n\tconst trimmedSchema = args.schemaArg\n\t\t.replace(/^\\{/, \"\")\n\t\t.replace(/\\}$/, \"\")\n\t\t.trim();\n\tconst topKeys = parseBlockKeys(trimmedSchema);\n\tconst isLegacy =\n\t\ttopKeys.includes(\"client\") ||\n\t\ttopKeys.includes(\"server\") ||\n\t\ttopKeys.includes(\"shared\");\n\n\tif (isLegacy) {\n\t\tconst clientBlock = extractBlock(args.schemaArg, \"client\");\n\t\tif (clientBlock) {\n\t\t\tclientKeys.push(...parseBlockKeys(clientBlock));\n\t\t}\n\t\tconst sharedBlock = extractBlock(args.schemaArg, \"shared\");\n\t\tif (sharedBlock) {\n\t\t\tsharedKeys.push(...parseBlockKeys(sharedBlock));\n\t\t}\n\t} else {\n\t\t// New flat layout\n\t\tconst optionExposedKeys: string[] = [];\n\t\tif (args.optionsArg) {\n\t\t\tconst exposeMatch =\n\t\t\t\targs.optionsArg.match(/exposeToClient\\s*:\\s*\\[([\\s\\S]*?)\\]/) ||\n\t\t\t\targs.optionsArg.match(/expose\\s*:\\s*\\[([\\s\\S]*?)\\]/) ||\n\t\t\t\targs.optionsArg.match(/shared\\s*:\\s*\\[([\\s\\S]*?)\\]/);\n\t\t\tif (exposeMatch) {\n\t\t\t\tconst matches = exposeMatch[1].matchAll(/['\"`](.*?)['\"`]/g);\n\t\t\t\tfor (const match of matches) {\n\t\t\t\t\toptionExposedKeys.push(match[1]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const key of topKeys) {\n\t\t\t// NODE_ENV is implicitly shared as Next.js automatically inlines and replaces references to process.env.NODE_ENV in browser bundles.\n\t\t\t// See: https://nextjs.org/docs/app/guides/environment-variables\n\t\t\tif (optionExposedKeys.includes(key) || key === \"NODE_ENV\") {\n\t\t\t\tsharedKeys.push(key);\n\t\t\t} else if (key.startsWith(\"NEXT_PUBLIC_\")) {\n\t\t\t\tclientKeys.push(key);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn { clientKeys, sharedKeys, isLegacy };\n}\n\n/**\n * Generate the triple-tab indented runtime environment variables mapping.\n */\nfunction generateRuntimeEnvLines(\n\tclientKeys: string[],\n\tsharedKeys: string[],\n): string {\n\tconst allKeys = Array.from(new Set([...clientKeys, ...sharedKeys]));\n\treturn allKeys\n\t\t.map(\n\t\t\t(key) =>\n\t\t\t\t`\\t\\t\\t${key}: typeof window !== \"undefined\" ? (globalThis as any).__arkenv_env__?.${key} ?? process.env.${key} : process.env.${key},`,\n\t\t)\n\t\t.join(\"\\n\");\n}\n\nconst GENERATED_HEADER = `/* eslint-disable */\n// biome-ignore format: auto-generated\n// Generated by ArkEnv. DO NOT EDIT DIRECTLY.\n`;\n\nconst GENERATED_FOOTER = `\nexport default createEnv;\n`;\n\n/**\n * Generate the TypeScript factory code for the tailored createEnv helper.\n *\n * @param clientKeys The client environment variable keys\n * @param sharedKeys The shared environment variable keys\n * @returns The generated TypeScript source code string\n */\nfunction generateFactoryCode(\n\tclientKeys: string[],\n\tsharedKeys: string[],\n): string {\n\tconst runtimeEnvLines = generateRuntimeEnvLines(clientKeys, sharedKeys);\n\n\treturn `${GENERATED_HEADER}\nimport { createEnv as coreCreateEnv } from \"@arkenv/nextjs\";\n\nexport { type } from \"@arkenv/nextjs\";\n\nexport function createEnv<\n\tconst TServer extends Record<string, any> = {},\n\tconst TClient extends Record<string, any> = {},\n\tconst TShared extends Record<string, any> = {},\n>(options: {\n\tserver?: TServer;\n\tclient?: TClient & {\n\t\t[K in keyof TClient]: K extends \\`NEXT_PUBLIC_\\${string}\\` ? unknown : never;\n\t};\n\tshared?: TShared;\n}) {\n\treturn coreCreateEnv({\n\t\t...options,\n\t\truntimeEnv: {\n${runtimeEnvLines}\n\t\t},\n\t} as any) as any;\n}\n${GENERATED_FOOTER}`;\n}\n\n/**\n * Generate the TypeScript factory code for the Flat Layout createEnv helper.\n *\n * @remarks\n * **Architecture tripwire:** Do not statically compile the schema here or\n * reference internal-only types (the `$` scope or `MergeExtends`).\n *\n * - **Generic wrapper:** The factory must stay generic because the concrete\n * schema is owned by the user-land `env.ts`.\n * - **Type strategy:** It intentionally returns the full schema type to ensure\n * flawless Server Component autocomplete.\n * - **Security boundary:** Client-side protection is deliberately deferred to\n * the runtime Proxy in `@arkenv/nextjs`, which throws on unauthorized access.\n *\n * 📖 See ADR-0010: Flat layout codegen and type inference strategy\n * (`docs/adr/0010-flat-layout-codegen-type-strategy.md`).\n */\nfunction generateFlatFactoryCode(\n\tclientKeys: string[],\n\tsharedKeys: string[],\n): string {\n\tconst runtimeEnvLines = generateRuntimeEnvLines(clientKeys, sharedKeys);\n\n\treturn `${GENERATED_HEADER}\nimport { createEnv as coreCreateEnv } from \"@arkenv/nextjs\";\nimport type { type as at, distill } from \"arktype\";\n\nexport { type } from \"@arkenv/nextjs\";\n\nexport function createEnv<\n\tconst TSchema extends Record<string, unknown> & { runtimeEnv?: never } = {},\n\tconst TExpose extends keyof TSchema = never,\n\tconst TExtends extends readonly unknown[] = [],\n>(\n\tschema: TSchema,\n\toptions?: {\n\t\t/**\n\t\t * Custom environment variables to expose to the client bundle.\n\t\t * By default, variables prefixed with \\`NEXT_PUBLIC_\\` and \\`NODE_ENV\\` are exposed automatically.\n\t\t * Use this option to expose custom variables that do not have the \\`NEXT_PUBLIC_\\` prefix.\n\t\t */\n\t\texposeToClient?: readonly TExpose[];\n\t\textends?: [...TExtends];\n\t},\n): Readonly<distill.Out<at.infer<TSchema>>> {\n\t// Types expose the full schema for a great DX on the server; the runtime\n\t// Proxy from \\`@arkenv/nextjs\\` enforces the security boundary by throwing\n\t// when a server-only variable is accessed on the client.\n\tconst env = coreCreateEnv(schema as any, {\n\t\t...options,\n\t\truntimeEnv: {\n${runtimeEnvLines}\n\t\t},\n\t} as any);\n\treturn env as unknown as Readonly<distill.Out<at.infer<TSchema>>>;\n}\n${GENERATED_FOOTER}`;\n}\n\n/**\n * Generate the TypeScript factory code for the strict-layout `createEnv` helper.\n *\n * Unlike `generateFactoryCode`, this variant imports from `@arkenv/nextjs/client`\n * and exposes a positional-schema signature suited for split-file projects.\n *\n * @param clientKeys The env var keys extracted from `client.ts`\n * @param sharedKeys The env var keys extracted from `internal/shared.ts`\n * @returns The generated TypeScript source code string\n */\nfunction generateClientFactoryCode(\n\tclientKeys: string[],\n\tsharedKeys: string[],\n): string {\n\tconst runtimeEnvLines = generateRuntimeEnvLines(clientKeys, sharedKeys);\n\n\treturn `${GENERATED_HEADER}\nimport { createEnv as coreCreateEnv } from \"@arkenv/nextjs/client\";\n\nexport { type } from \"@arkenv/nextjs/client\";\n\nexport function createEnv<\n\tconst TSchema extends Record<string, any> = {},\n\tconst TExtends extends readonly unknown[] = [],\n>(\n\tschema: TSchema & {\n\t\t[K in keyof TSchema]: K extends \\`NEXT_PUBLIC_\\${string}\\` ? unknown : never;\n\t},\n\toptions?: {\n\t\textends?: [...TExtends];\n\t},\n) {\n\treturn coreCreateEnv<TSchema, TExtends>(schema as any, {\n\t\t...options,\n\t\truntimeEnv: {\n${runtimeEnvLines}\n\t\t},\n\t} as any);\n}\n${GENERATED_FOOTER}`;\n}\n"],"mappings":"soBAcI,EAAwB,GAE5B,SAAS,EACR,EACkC,CAalC,OAZI,IAAW,UACV,QAAQ,IAAI,WAAa,eAAiB,CAAC,IAC9C,EAAwB,GACxB,QAAQ,KACP,0HACA,EAEK,UAEJ,IAAW,OACP,SAED,EAkER,SAAgB,EAAY,EAAqC,CAEhE,IAAM,EAAa,GAAS,WACzBA,EAAAA,QAAK,QAAQ,EAAQ,WAAW,EAAA,EAAA,EAAA,iBAChB,CAGf,EAAS,GACb,GAAI,EACH,GAAIC,EAAAA,QAAG,WAAW,EAAW,CAC5B,EAAS,OACH,CACN,IAAM,EAAMD,EAAAA,QAAK,QAAQ,EAAW,CACpC,GAAI,EAAK,CACR,IAAM,EAAiB,EAAW,MAAM,EAAG,CAAC,EAAI,OAAO,CACnDC,EAAAA,QAAG,WAAW,EAAe,GAChC,EAAS,KAMb,GAAI,CAAC,GAAc,CAAC,EACnB,MAAU,MACT,0CACC,GAAS,YAAc,uBACvB,uDACD,CAKF,GAAM,CAAE,OAAQ,EAAgB,YAAA,EAAA,EAAA,eAC/B,EAHwB,EAAgB,GAAS,OAIjC,CAChB,CAGK,EACL,IAAmB,UAAY,EAAU,EAAUD,EAAAA,QAAK,QAAQ,EAAW,CACtE,EAAoBA,EAAAA,QAAK,KAC9B,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C,IAAK,IAAM,KAAO,EAGb,EAAkB,SAAS,EAAI,EAAI,IAAQ,WAC9C,EAAW,KAAK,EAAI,CACV,EAAI,WAAW,eAAe,EACxC,EAAW,KAAK,EAAI,CAKvB,MAAO,CAAE,aAAY,aAAY,WAAU,CAM5C,SAAS,EACR,EACA,EACS,CAET,OADgB,MAAM,KAAK,IAAI,IAAI,CAAC,GAAG,EAAY,GAAG,EAAW,CAAC,CACpD,CACZ,IACC,GACA,SAAS,EAAI,wEAAwE,EAAI,kBAAkB,EAAI,iBAAiB,EAAI,GACrI,CACA,KAAK;EAAK,CAGb,MAAM,EAAmB;;;EAKnB,EAAmB;;EAWzB,SAAS,EACR,EACA,EACS,CAGT,MAAO,GAAG,EAAiB;;;;;;;;;;;;;;;;;;;EAFH,EAAwB,EAAY,EAqB5C,CAAC;;;;EAIhB,IAoBF,SAAS,EACR,EACA,EACS,CAGT,MAAO,GAAG,EAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAFH,EAAwB,EAAY,EA8B5C,CAAC;;;;;EAKhB,IAaF,SAAS,EACR,EACA,EACS,CAGT,MAAO,GAAG,EAAiB;;;;;;;;;;;;;;;;;;;EAFH,EAAwB,EAAY,EAqB5C,CAAC;;;;EAIhB"}
|
|
1
|
+
{"version":3,"file":"config.cjs","names":["path","fs"],"sources":["../src/config.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport {\n\textractBlock,\n\textractClientKeys,\n\textractSharedKeys,\n\tfindSchemaPath,\n\tparseBlockKeys,\n\tresolveLayout,\n\twatchSchema,\n} from \"@arkenv/build\";\nimport { createJiti } from \"jiti\";\n\nexport { extractClientKeys, extractSharedKeys };\n\nlet hasWarnedSimpleLayout = false;\n\nfunction normalizeLayout(\n\tlayout: ArkEnvConfigOptions[\"layout\"],\n): \"simple\" | \"strict\" | undefined {\n\tif (layout === \"simple\") {\n\t\tif (process.env.NODE_ENV === \"development\" && !hasWarnedSimpleLayout) {\n\t\t\thasWarnedSimpleLayout = true;\n\t\t\tconsole.warn(\n\t\t\t\t\"⚠️ [arkenv] The 'simple' layout option is deprecated and will be removed in the next major version. Use 'flat' instead.\",\n\t\t\t);\n\t\t}\n\t\treturn \"simple\";\n\t}\n\tif (layout === \"flat\") {\n\t\treturn \"simple\";\n\t}\n\treturn layout;\n}\n\n/**\n * Configuration options for the ArkEnv Next.js integration.\n *\n * @example\n * ```ts\n * const configOptions: ArkEnvConfigOptions = {\n * schemaPath: \"./src/env.ts\",\n * outputPath: \"./src/generated/env.gen.ts\"\n * };\n * ```\n */\nexport type ArkEnvConfigOptions = {\n\t/**\n\t * Specify the path to the schema definition file.\n\t *\n\t * Defaults to searching for `\"src/env.ts\"` or `\"env.ts\"` in the project root.\n\t *\n\t * @default \"src/env.ts\"\n\t * @example\n\t * ```ts\n\t * export default withArkEnv(nextConfig, {\n\t * schemaPath: \"./src/env.ts\"\n\t * });\n\t * ```\n\t */\n\tschemaPath?: string;\n\n\t/**\n\t * Specify the path where the generated file (`env.gen.ts`) should be written.\n\t *\n\t * Defaults to `\"generated/env.gen.ts\"` in the same directory as the schema file.\n\t *\n\t * @default \"[schemaDirectory]/generated/env.gen.ts\"\n\t * @example\n\t * ```ts\n\t * export default withArkEnv(nextConfig, {\n\t * outputPath: \"./src/generated/env.gen.ts\"\n\t * });\n\t * ```\n\t */\n\toutputPath?: string;\n\n\t/**\n\t * Specify the configuration layout.\n\t *\n\t * - `\"flat\"` (default): A single `env.ts` schema file.\n\t * - `\"strict\"`: A 3-file split schema layout (`env/internal/shared.ts`, `env/client.ts`, `env/server.ts`).\n\t *\n\t * @default \"flat\"\n\t */\n\tlayout?:\n\t\t| \"flat\"\n\t\t| \"strict\"\n\t\t/** @deprecated Use `\"flat\"` instead. `\"simple\"` will be removed in the next major version. */\n\t\t| \"simple\";\n\n\t/**\n\t * Enable or disable build-time environment variable validation during build/dev startup.\n\t *\n\t * @default true\n\t */\n\tvalidate?: boolean;\n\n\t/**\n\t * Enable or disable automatic code generation of the `env.gen.ts` file.\n\t *\n\t * @default true\n\t */\n\tcodegen?: boolean;\n};\n\n/**\n * Run ArkEnv codegen and setup without wrapping nextConfig.\n *\n * @param options Optional configuration paths for schema and output files\n * @param internalOptions Optional configuration for internal testing hooks\n * @throws An error if the schema file cannot be found or if code generation fails\n */\nexport function setupArkEnv(\n\toptions?: ArkEnvConfigOptions,\n\tinternalOptions?: { _jitiAliases?: Record<string, string> },\n): void {\n\t// 1. Locate the env.ts schema file or strict schema directory\n\tconst schemaPath = options?.schemaPath\n\t\t? path.resolve(options.schemaPath)\n\t\t: findSchemaPath();\n\n\t// Auto-detect layout if not specified\n\tlet exists = false;\n\tif (schemaPath) {\n\t\tif (fs.existsSync(schemaPath)) {\n\t\t\texists = true;\n\t\t} else {\n\t\t\tconst ext = path.extname(schemaPath);\n\t\t\tif (ext) {\n\t\t\t\tconst baseWithoutExt = schemaPath.slice(0, -ext.length);\n\t\t\t\tif (fs.existsSync(baseWithoutExt)) {\n\t\t\t\t\texists = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (!schemaPath || !exists) {\n\t\tthrow new Error(\n\t\t\t`[ArkEnv] Could not find schema file at ${\n\t\t\t\toptions?.schemaPath || \"src/env.ts or env.ts\"\n\t\t\t}. Please specify 'schemaPath' in setupArkEnv options.`,\n\t\t);\n\t}\n\n\tconst normalizedLayout = normalizeLayout(options?.layout);\n\n\tconst { layout: resolvedLayout, baseDir } = resolveLayout(\n\t\tschemaPath,\n\t\tnormalizedLayout,\n\t);\n\n\t// 2. Determine outputPath (defaults to generated/env.gen.ts in the same directory as schemaPath/baseDir)\n\tconst defaultOutputDir =\n\t\tresolvedLayout === \"strict\" && baseDir ? baseDir : path.dirname(schemaPath);\n\tconst defaultOutputPath = path.join(\n\t\tdefaultOutputDir,\n\t\t\"generated\",\n\t\t\"env.gen.ts\",\n\t);\n\tconst outputPath = options?.outputPath\n\t\t? path.resolve(options.outputPath)\n\t\t: defaultOutputPath;\n\n\t// 3. Run initial code generation if enabled\n\tconst codegen = options?.codegen ?? true;\n\tif (codegen) {\n\t\ttry {\n\t\t\trunCodegen(schemaPath, outputPath, resolvedLayout);\n\t\t} catch (error: unknown) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tthrow new Error(`[ArkEnv] Failed to generate env.gen.ts: ${message}`);\n\t\t}\n\t}\n\n\t// 4. Validate schema against environment variables\n\tconst runValidation = options?.validate ?? true;\n\tif (runValidation) {\n\t\ttry {\n\t\t\t(globalThis as any).__arkenv_force_server__ = true;\n\t\t\tconst fileToEvaluate =\n\t\t\t\tresolvedLayout === \"strict\" && baseDir\n\t\t\t\t\t? path.join(baseDir, \"server.ts\")\n\t\t\t\t\t: schemaPath;\n\n\t\t\tconst filenameForJiti =\n\t\t\t\ttypeof __filename !== \"undefined\"\n\t\t\t\t\t? __filename\n\t\t\t\t\t: typeof import.meta !== \"undefined\" && import.meta.url\n\t\t\t\t\t\t? fileURLToPath(import.meta.url)\n\t\t\t\t\t\t: \"\";\n\t\t\tconst dir = path.dirname(filenameForJiti);\n\t\t\tconst sharedPath = fs.existsSync(path.join(dir, \"shared.ts\"))\n\t\t\t\t? path.join(dir, \"shared.ts\")\n\t\t\t\t: path.join(dir, \"shared.js\");\n\n\t\t\tconst aliases: Record<string, string> = {\n\t\t\t\t\"server-only\": sharedPath,\n\t\t\t\t\"./script\": sharedPath,\n\t\t\t\t\"./script.tsx\": sharedPath,\n\t\t\t\t...internalOptions?._jitiAliases,\n\t\t\t};\n\n\t\t\tconst jiti = createJiti(fileToEvaluate, {\n\t\t\t\tmoduleCache: false,\n\t\t\t\tfsCache: false,\n\t\t\t\ttsconfigPaths: true,\n\t\t\t\talias: aliases,\n\t\t\t});\n\t\t\tjiti(fileToEvaluate);\n\t\t} catch (error: unknown) {\n\t\t\tconsole.error(\"\\n❌ [ArkEnv] Environment validation failed:\");\n\t\t\tconsole.error(error instanceof Error ? error.message : String(error));\n\t\t\tconsole.error(\"\");\n\t\t\tprocess.exit(1);\n\t\t} finally {\n\t\t\tdelete (globalThis as any).__arkenv_force_server__;\n\t\t}\n\t}\n\n\t// 5. Initialize development file watcher if in dev mode and codegen is enabled\n\tconst isDev =\n\t\tprocess.env.NODE_ENV === \"development\" ||\n\t\tprocess.env.NEXT_PHASE === \"phase-development-server\";\n\tif (isDev && codegen) {\n\t\tconst watchPaths =\n\t\t\tresolvedLayout === \"strict\" && baseDir\n\t\t\t\t? [\n\t\t\t\t\t\tpath.join(baseDir, \"internal\", \"shared.ts\"),\n\t\t\t\t\t\tpath.join(baseDir, \"client.ts\"),\n\t\t\t\t\t\tpath.join(baseDir, \"server.ts\"),\n\t\t\t\t\t].filter(fs.existsSync)\n\t\t\t\t: [schemaPath];\n\t\twatchSchema(watchPaths, () => {\n\t\t\trunCodegen(schemaPath, outputPath, resolvedLayout);\n\t\t});\n\t}\n}\n\n/**\n * Wrap a Next.js configuration object to automatically generate the `runtimeEnv` block in `env.gen.ts`.\n *\n * @param nextConfig The Next.js configuration object or function\n * @param options Optional configuration paths for schema and output files\n * @returns The Next.js configuration object unchanged\n * @throws An error if the schema file cannot be found or if code generation fails\n */\nexport function withArkEnv<T>(nextConfig: T, options?: ArkEnvConfigOptions): T {\n\tsetupArkEnv(options);\n\treturn nextConfig;\n}\n\n/**\n * Run code generation to read the schema file and generate the env.gen.ts factory.\n *\n * @param schemaPath The absolute path to the schema file or directory\n * @param outputPath The absolute path to the generated output file\n * @param layoutOption The explicit layout to use; auto-detected from the filesystem when omitted\n * @throws An error if strict layout files are missing when `layoutOption` is `\"strict\"`\n */\nexport function runCodegen(\n\tschemaPath: string,\n\toutputPath: string,\n\tlayoutOption?: ArkEnvConfigOptions[\"layout\"],\n) {\n\tconst normalizedLayout = normalizeLayout(layoutOption);\n\n\tconst { layout: resolvedLayout, baseDir } = resolveLayout(\n\t\tschemaPath,\n\t\tnormalizedLayout,\n\t);\n\n\tlet generatedCode = \"\";\n\tif (resolvedLayout === \"strict\") {\n\t\tconst clientPath = path.join(baseDir, \"client.ts\");\n\t\tconst sharedPath = path.join(baseDir, \"internal\", \"shared.ts\");\n\n\t\tconst clientContent = fs.existsSync(clientPath)\n\t\t\t? fs.readFileSync(clientPath, \"utf-8\")\n\t\t\t: \"\";\n\t\tconst sharedContent = fs.existsSync(sharedPath)\n\t\t\t? fs.readFileSync(sharedPath, \"utf-8\")\n\t\t\t: \"\";\n\n\t\tconst clientKeys = extractClientKeys(clientContent);\n\t\tconst sharedKeys = extractSharedKeys(sharedContent);\n\n\t\tgeneratedCode = generateClientFactoryCode(clientKeys, sharedKeys);\n\t} else {\n\t\tconst fileContent = fs.readFileSync(schemaPath, \"utf-8\");\n\t\tconst { clientKeys, sharedKeys, isLegacy } = extractKeys(fileContent);\n\t\tif (isLegacy) {\n\t\t\tgeneratedCode = generateFactoryCode(clientKeys, sharedKeys);\n\t\t} else {\n\t\t\tgeneratedCode = generateFlatFactoryCode(clientKeys, sharedKeys);\n\t\t}\n\t}\n\n\t// Ensure parent directory exists\n\tconst outputDir = path.dirname(outputPath);\n\tif (!fs.existsSync(outputDir)) {\n\t\tfs.mkdirSync(outputDir, { recursive: true });\n\t}\n\n\t// Write if changed to avoid unnecessary filesystem/watcher triggers\n\tlet shouldWrite = true;\n\tif (fs.existsSync(outputPath)) {\n\t\tconst existingContent = fs.readFileSync(outputPath, \"utf-8\");\n\t\tif (existingContent === generatedCode) {\n\t\t\tshouldWrite = false;\n\t\t}\n\t}\n\n\tif (shouldWrite) {\n\t\tfs.writeFileSync(outputPath, generatedCode, \"utf-8\");\n\t}\n}\n\nfunction extractCallArguments(\n\tcontent: string,\n): { schemaArg: string; optionsArg: string | null } | null {\n\tconst regex = /\\b(?:arkenv|createEnv)\\s*\\(/g;\n\twhile (regex.exec(content) !== null) {\n\t\tlet parenCount = 1;\n\t\tlet index = regex.lastIndex;\n\t\tlet inString: string | null = null;\n\t\tlet inComment: \"single\" | \"multi\" | null = null;\n\t\tlet braceCount = 0;\n\t\tlet bracketCount = 0;\n\n\t\tconst args: string[] = [];\n\t\tlet currentArg = \"\";\n\n\t\twhile (index < content.length && parenCount > 0) {\n\t\t\tconst char = content[index];\n\t\t\tconst nextChar = content[index + 1];\n\n\t\t\tif (inComment === \"single\") {\n\t\t\t\tif (char === \"\\n\" || char === \"\\r\") inComment = null;\n\t\t\t\tcurrentArg += char;\n\t\t\t\tindex++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (inComment === \"multi\") {\n\t\t\t\tif (char === \"*\" && nextChar === \"/\") {\n\t\t\t\t\tinComment = null;\n\t\t\t\t\tcurrentArg += \"*/\";\n\t\t\t\t\tindex += 2;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tcurrentArg += char;\n\t\t\t\tindex++;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (inString) {\n\t\t\t\tif (char === inString && content[index - 1] !== \"\\\\\") {\n\t\t\t\t\tinString = null;\n\t\t\t\t}\n\t\t\t\tcurrentArg += char;\n\t\t\t\tindex++;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (char === \"/\" && nextChar === \"/\") {\n\t\t\t\tinComment = \"single\";\n\t\t\t\tcurrentArg += \"//\";\n\t\t\t\tindex += 2;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (char === \"/\" && nextChar === \"*\") {\n\t\t\t\tinComment = \"multi\";\n\t\t\t\tcurrentArg += \"/*\";\n\t\t\t\tindex += 2;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (char === \"'\" || char === '\"' || char === \"`\") {\n\t\t\t\tinString = char;\n\t\t\t\tcurrentArg += char;\n\t\t\t\tindex++;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (char === \"(\") {\n\t\t\t\tparenCount++;\n\t\t\t} else if (char === \")\") {\n\t\t\t\tparenCount--;\n\t\t\t} else if (char === \"{\") {\n\t\t\t\tbraceCount++;\n\t\t\t} else if (char === \"}\") {\n\t\t\t\tbraceCount--;\n\t\t\t} else if (char === \"[\") {\n\t\t\t\tbracketCount++;\n\t\t\t} else if (char === \"]\") {\n\t\t\t\tbracketCount--;\n\t\t\t}\n\n\t\t\tif (parenCount === 0) {\n\t\t\t\targs.push(currentArg);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tchar === \",\" &&\n\t\t\t\tparenCount === 1 &&\n\t\t\t\tbraceCount === 0 &&\n\t\t\t\tbracketCount === 0\n\t\t\t) {\n\t\t\t\targs.push(currentArg);\n\t\t\t\tcurrentArg = \"\";\n\t\t\t} else {\n\t\t\t\tcurrentArg += char;\n\t\t\t}\n\t\t\tindex++;\n\t\t}\n\n\t\tif (parenCount === 0 && args.length > 0) {\n\t\t\treturn {\n\t\t\t\tschemaArg: args[0].trim(),\n\t\t\t\toptionsArg: args[1] ? args[1].trim() : null,\n\t\t\t};\n\t\t}\n\t}\n\treturn null;\n}\n\n/**\n * Statically extract client and shared keys from the schema content.\n *\n * @param content The schema file string content\n * @returns An object containing the extracted client and shared keys\n */\nexport function extractKeys(content: string): {\n\tclientKeys: string[];\n\tsharedKeys: string[];\n\tisLegacy?: boolean;\n} {\n\tconst clientKeys: string[] = [];\n\tconst sharedKeys: string[] = [];\n\n\tconst args = extractCallArguments(content);\n\tif (!args) {\n\t\treturn { clientKeys, sharedKeys, isLegacy: false };\n\t}\n\n\t// Strip outer braces if present\n\tconst trimmedSchema = args.schemaArg\n\t\t.replace(/^\\{/, \"\")\n\t\t.replace(/\\}$/, \"\")\n\t\t.trim();\n\tconst topKeys = parseBlockKeys(trimmedSchema);\n\tconst isLegacy =\n\t\ttopKeys.includes(\"client\") ||\n\t\ttopKeys.includes(\"server\") ||\n\t\ttopKeys.includes(\"shared\");\n\n\tif (isLegacy) {\n\t\tconst clientBlock = extractBlock(args.schemaArg, \"client\");\n\t\tif (clientBlock) {\n\t\t\tclientKeys.push(...parseBlockKeys(clientBlock));\n\t\t}\n\t\tconst sharedBlock = extractBlock(args.schemaArg, \"shared\");\n\t\tif (sharedBlock) {\n\t\t\tsharedKeys.push(...parseBlockKeys(sharedBlock));\n\t\t}\n\t} else {\n\t\t// New flat layout\n\t\tconst optionExposedKeys: string[] = [];\n\t\tif (args.optionsArg) {\n\t\t\tconst exposeMatch =\n\t\t\t\targs.optionsArg.match(/exposeToClient\\s*:\\s*\\[([\\s\\S]*?)\\]/) ||\n\t\t\t\targs.optionsArg.match(/expose\\s*:\\s*\\[([\\s\\S]*?)\\]/) ||\n\t\t\t\targs.optionsArg.match(/shared\\s*:\\s*\\[([\\s\\S]*?)\\]/);\n\t\t\tif (exposeMatch) {\n\t\t\t\tconst matches = exposeMatch[1].matchAll(/['\"`](.*?)['\"`]/g);\n\t\t\t\tfor (const match of matches) {\n\t\t\t\t\toptionExposedKeys.push(match[1]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const key of topKeys) {\n\t\t\t// NODE_ENV is implicitly shared as Next.js automatically inlines and replaces references to process.env.NODE_ENV in browser bundles.\n\t\t\t// See: https://nextjs.org/docs/app/guides/environment-variables\n\t\t\tif (optionExposedKeys.includes(key) || key === \"NODE_ENV\") {\n\t\t\t\tsharedKeys.push(key);\n\t\t\t} else if (key.startsWith(\"NEXT_PUBLIC_\")) {\n\t\t\t\tclientKeys.push(key);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn { clientKeys, sharedKeys, isLegacy };\n}\n\n/**\n * Generate the triple-tab indented runtime environment variables mapping.\n */\nfunction generateRuntimeEnvLines(\n\tclientKeys: string[],\n\tsharedKeys: string[],\n): string {\n\tconst allKeys = Array.from(new Set([...clientKeys, ...sharedKeys]));\n\treturn allKeys\n\t\t.map(\n\t\t\t(key) =>\n\t\t\t\t`\\t\\t\\t${key}: typeof window !== \"undefined\" ? (globalThis as any).__arkenv_env__?.${key} ?? process.env.${key} : process.env.${key},`,\n\t\t)\n\t\t.join(\"\\n\");\n}\n\nconst GENERATED_HEADER = `/* eslint-disable */\n// biome-ignore format: auto-generated\n// Generated by ArkEnv. DO NOT EDIT DIRECTLY.\n`;\n\nconst GENERATED_FOOTER = `\nexport default createEnv;\n`;\n\n/**\n * Generate the TypeScript factory code for the tailored createEnv helper.\n *\n * @param clientKeys The client environment variable keys\n * @param sharedKeys The shared environment variable keys\n * @returns The generated TypeScript source code string\n */\nfunction generateFactoryCode(\n\tclientKeys: string[],\n\tsharedKeys: string[],\n): string {\n\tconst runtimeEnvLines = generateRuntimeEnvLines(clientKeys, sharedKeys);\n\n\treturn `${GENERATED_HEADER}\nimport { createEnv as coreCreateEnv } from \"@arkenv/nextjs\";\n\nexport { type } from \"@arkenv/nextjs\";\n\nexport function createEnv<\n\tconst TServer extends Record<string, any> = {},\n\tconst TClient extends Record<string, any> = {},\n\tconst TShared extends Record<string, any> = {},\n>(options: {\n\tserver?: TServer;\n\tclient?: TClient & {\n\t\t[K in keyof TClient]: K extends \\`NEXT_PUBLIC_\\${string}\\` ? unknown : never;\n\t};\n\tshared?: TShared;\n}) {\n\treturn coreCreateEnv({\n\t\t...options,\n\t\truntimeEnv: {\n${runtimeEnvLines}\n\t\t},\n\t} as any) as any;\n}\n${GENERATED_FOOTER}`;\n}\n\n/**\n * Generate the TypeScript factory code for the Flat Layout createEnv helper.\n *\n * @remarks\n * **Architecture tripwire:** Do not statically compile the schema here or\n * reference internal-only types (the `$` scope or `MergeExtends`).\n *\n * - **Generic wrapper:** The factory must stay generic because the concrete\n * schema is owned by the user-land `env.ts`.\n * - **Type strategy:** It intentionally returns the full schema type to ensure\n * flawless Server Component autocomplete.\n * - **Security boundary:** Client-side protection is deliberately deferred to\n * the runtime Proxy in `@arkenv/nextjs`, which throws on unauthorized access.\n *\n * 📖 See ADR-0010: Flat layout codegen and type inference strategy\n * (`docs/adr/0010-flat-layout-codegen-type-strategy.md`).\n */\nfunction generateFlatFactoryCode(\n\tclientKeys: string[],\n\tsharedKeys: string[],\n): string {\n\tconst runtimeEnvLines = generateRuntimeEnvLines(clientKeys, sharedKeys);\n\n\treturn `${GENERATED_HEADER}\nimport { createEnv as coreCreateEnv } from \"@arkenv/nextjs\";\nimport type { type as at, distill } from \"arktype\";\n\nexport { type } from \"@arkenv/nextjs\";\n\nexport function createEnv<\n\tconst TSchema extends Record<string, unknown> & { runtimeEnv?: never } = {},\n\tconst TExpose extends keyof TSchema = never,\n\tconst TExtends extends readonly unknown[] = [],\n>(\n\tschema: TSchema,\n\toptions?: {\n\t\t/**\n\t\t * Custom environment variables to expose to the client bundle.\n\t\t * By default, variables prefixed with \\`NEXT_PUBLIC_\\` and \\`NODE_ENV\\` are exposed automatically.\n\t\t * Use this option to expose custom variables that do not have the \\`NEXT_PUBLIC_\\` prefix.\n\t\t */\n\t\texposeToClient?: readonly TExpose[];\n\t\textends?: [...TExtends];\n\t},\n): Readonly<distill.Out<at.infer<TSchema>>> {\n\t// Types expose the full schema for a great DX on the server; the runtime\n\t// Proxy from \\`@arkenv/nextjs\\` enforces the security boundary by throwing\n\t// when a server-only variable is accessed on the client.\n\tconst env = coreCreateEnv(schema as any, {\n\t\t...options,\n\t\truntimeEnv: {\n${runtimeEnvLines}\n\t\t},\n\t} as any);\n\treturn env as unknown as Readonly<distill.Out<at.infer<TSchema>>>;\n}\n${GENERATED_FOOTER}`;\n}\n\n/**\n * Generate the TypeScript factory code for the strict-layout `createEnv` helper.\n *\n * Unlike `generateFactoryCode`, this variant imports from `@arkenv/nextjs/client`\n * and exposes a positional-schema signature suited for split-file projects.\n *\n * @param clientKeys The env var keys extracted from `client.ts`\n * @param sharedKeys The env var keys extracted from `internal/shared.ts`\n * @returns The generated TypeScript source code string\n */\nfunction generateClientFactoryCode(\n\tclientKeys: string[],\n\tsharedKeys: string[],\n): string {\n\tconst runtimeEnvLines = generateRuntimeEnvLines(clientKeys, sharedKeys);\n\n\treturn `${GENERATED_HEADER}\nimport { createEnv as coreCreateEnv } from \"@arkenv/nextjs/client\";\n\nexport { type } from \"@arkenv/nextjs/client\";\n\nexport function createEnv<\n\tconst TSchema extends Record<string, any> = {},\n\tconst TExtends extends readonly unknown[] = [],\n>(\n\tschema: TSchema & {\n\t\t[K in keyof TSchema]: K extends \\`NEXT_PUBLIC_\\${string}\\` ? unknown : never;\n\t},\n\toptions?: {\n\t\textends?: [...TExtends];\n\t},\n) {\n\treturn coreCreateEnv<TSchema, TExtends>(schema as any, {\n\t\t...options,\n\t\truntimeEnv: {\n${runtimeEnvLines}\n\t\t},\n\t} as any);\n}\n${GENERATED_FOOTER}`;\n}\n"],"mappings":"8qBAgBI,EAAwB,GAE5B,SAAS,EACR,EACkC,CAalC,OAZI,IAAW,UACV,QAAQ,IAAI,WAAa,eAAiB,CAAC,IAC9C,EAAwB,GACxB,QAAQ,KACP,0HACA,EAEK,UAEJ,IAAW,OACP,SAED,EAiFR,SAAgB,EACf,EACA,EACO,CAEP,IAAM,EAAa,GAAS,WACzBA,EAAAA,QAAK,QAAQ,EAAQ,WAAW,EAAA,EAAA,EAAA,iBAChB,CAGf,EAAS,GACb,GAAI,EACH,GAAIC,EAAAA,QAAG,WAAW,EAAW,CAC5B,EAAS,OACH,CACN,IAAM,EAAMD,EAAAA,QAAK,QAAQ,EAAW,CACpC,GAAI,EAAK,CACR,IAAM,EAAiB,EAAW,MAAM,EAAG,CAAC,EAAI,OAAO,CACnDC,EAAAA,QAAG,WAAW,EAAe,GAChC,EAAS,KAMb,GAAI,CAAC,GAAc,CAAC,EACnB,MAAU,MACT,0CACC,GAAS,YAAc,uBACvB,uDACD,CAKF,GAAM,CAAE,OAAQ,EAAgB,YAAA,EAAA,EAAA,eAC/B,EAHwB,EAAgB,GAAS,OAIjC,CAChB,CAGK,EACL,IAAmB,UAAY,EAAU,EAAUD,EAAAA,QAAK,QAAQ,EAAW,CACtE,EAAoBA,EAAAA,QAAK,KAC9B,EACA,YACA,aACA,CACK,EAAa,GAAS,WACzBA,EAAAA,QAAK,QAAQ,EAAQ,WAAW,CAChC,EAGG,EAAU,GAAS,SAAW,GACpC,GAAI,E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,EAqB5C,CAAC;;;;EAIhB,IAoBF,SAAS,EACR,EACA,EACS,CAGT,MAAO,GAAG,EAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAFH,EAAwB,EAAY,EA8B5C,CAAC;;;;;EAKhB,IAaF,SAAS,EACR,EACA,EACS,CAGT,MAAO,GAAG,EAAiB;;;;;;;;;;;;;;;;;;;EAFH,EAAwB,EAAY,EAqB5C,CAAC;;;;EAIhB"}
|
package/dist/config.d.cts
CHANGED
|
@@ -50,14 +50,29 @@ type ArkEnvConfigOptions = {
|
|
|
50
50
|
* @default "flat"
|
|
51
51
|
*/
|
|
52
52
|
layout?: "flat" | "strict" /** @deprecated Use `"flat"` instead. `"simple"` will be removed in the next major version. */ | "simple";
|
|
53
|
+
/**
|
|
54
|
+
* Enable or disable build-time environment variable validation during build/dev startup.
|
|
55
|
+
*
|
|
56
|
+
* @default true
|
|
57
|
+
*/
|
|
58
|
+
validate?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Enable or disable automatic code generation of the `env.gen.ts` file.
|
|
61
|
+
*
|
|
62
|
+
* @default true
|
|
63
|
+
*/
|
|
64
|
+
codegen?: boolean;
|
|
53
65
|
};
|
|
54
66
|
/**
|
|
55
67
|
* Run ArkEnv codegen and setup without wrapping nextConfig.
|
|
56
68
|
*
|
|
57
69
|
* @param options Optional configuration paths for schema and output files
|
|
70
|
+
* @param internalOptions Optional configuration for internal testing hooks
|
|
58
71
|
* @throws An error if the schema file cannot be found or if code generation fails
|
|
59
72
|
*/
|
|
60
|
-
declare function setupArkEnv(options?: ArkEnvConfigOptions
|
|
73
|
+
declare function setupArkEnv(options?: ArkEnvConfigOptions, internalOptions?: {
|
|
74
|
+
_jitiAliases?: Record<string, string>;
|
|
75
|
+
}): void;
|
|
61
76
|
/**
|
|
62
77
|
* Wrap a Next.js configuration object to automatically generate the `runtimeEnv` block in `env.gen.ts`.
|
|
63
78
|
*
|
package/dist/config.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.cts","names":[],"sources":["../src/config.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"config.d.cts","names":[],"sources":["../src/config.ts"],"mappings":";;;;AA+CA;;;;;;;;;;KAAY,mBAAA;EAmEI;;;;;;;;;;;AAuIhB;;EA5LC,UAAA;EA4LyC;;;;;;;;;;;;;EA7KzC,UAAA;EA0LyB;;;;;;;;EAhLzB,MAAA,qBA4Ve;;;;;;EAjVf,QAAA;EAoVQ;;;;;EA7UR,OAAA;AAAA;;;;;;;;iBAUe,WAAA,CACf,OAAA,GAAU,mBAAA,EACV,eAAA;EAAoB,YAAA,GAAe,MAAA;AAAA;;;;;;;;;iBAqIpB,UAAA,GAAA,CAAc,UAAA,EAAY,CAAA,EAAG,OAAA,GAAU,mBAAA,GAAsB,CAAA;;;;;;;;;iBAa7D,UAAA,CACf,UAAA,UACA,UAAA,UACA,YAAA,GAAe,mBAAA;;;;;;;iBAyKA,WAAA,CAAY,OAAA;EAC3B,UAAA;EACA,UAAA;EACA,QAAA;AAAA"}
|
package/dist/config.d.ts
CHANGED
|
@@ -50,14 +50,29 @@ type ArkEnvConfigOptions = {
|
|
|
50
50
|
* @default "flat"
|
|
51
51
|
*/
|
|
52
52
|
layout?: "flat" | "strict" /** @deprecated Use `"flat"` instead. `"simple"` will be removed in the next major version. */ | "simple";
|
|
53
|
+
/**
|
|
54
|
+
* Enable or disable build-time environment variable validation during build/dev startup.
|
|
55
|
+
*
|
|
56
|
+
* @default true
|
|
57
|
+
*/
|
|
58
|
+
validate?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Enable or disable automatic code generation of the `env.gen.ts` file.
|
|
61
|
+
*
|
|
62
|
+
* @default true
|
|
63
|
+
*/
|
|
64
|
+
codegen?: boolean;
|
|
53
65
|
};
|
|
54
66
|
/**
|
|
55
67
|
* Run ArkEnv codegen and setup without wrapping nextConfig.
|
|
56
68
|
*
|
|
57
69
|
* @param options Optional configuration paths for schema and output files
|
|
70
|
+
* @param internalOptions Optional configuration for internal testing hooks
|
|
58
71
|
* @throws An error if the schema file cannot be found or if code generation fails
|
|
59
72
|
*/
|
|
60
|
-
declare function setupArkEnv(options?: ArkEnvConfigOptions
|
|
73
|
+
declare function setupArkEnv(options?: ArkEnvConfigOptions, internalOptions?: {
|
|
74
|
+
_jitiAliases?: Record<string, string>;
|
|
75
|
+
}): void;
|
|
61
76
|
/**
|
|
62
77
|
* Wrap a Next.js configuration object to automatically generate the `runtimeEnv` block in `env.gen.ts`.
|
|
63
78
|
*
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","names":[],"sources":["../src/config.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"config.d.ts","names":[],"sources":["../src/config.ts"],"mappings":";;;;AA+CA;;;;;;;;;;KAAY,mBAAA;EAmEI;;;;;;;;;;;AAuIhB;;EA5LC,UAAA;EA4LyC;;;;;;;;;;;;;EA7KzC,UAAA;EA0LyB;;;;;;;;EAhLzB,MAAA,qBA4Ve;;;;;;EAjVf,QAAA;EAoVQ;;;;;EA7UR,OAAA;AAAA;;;;;;;;iBAUe,WAAA,CACf,OAAA,GAAU,mBAAA,EACV,eAAA;EAAoB,YAAA,GAAe,MAAA;AAAA;;;;;;;;;iBAqIpB,UAAA,GAAA,CAAc,UAAA,EAAY,CAAA,EAAG,OAAA,GAAU,mBAAA,GAAsB,CAAA;;;;;;;;;iBAa7D,UAAA,CACf,UAAA,UACA,UAAA,UACA,YAAA,GAAe,mBAAA;;;;;;;iBAyKA,WAAA,CAAY,OAAA;EAC3B,UAAA;EACA,UAAA;EACA,QAAA;AAAA"}
|
package/dist/config.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import e from"node:fs";import t from"node:path";import{extractBlock as
|
|
2
|
-
|
|
3
|
-
`)}
|
|
1
|
+
import e from"node:fs";import t from"node:path";import{fileURLToPath as n}from"node:url";import{extractBlock as r,extractClientKeys as i,extractSharedKeys as a,findSchemaPath as o,parseBlockKeys as s,resolveLayout as c,watchSchema as l}from"@arkenv/build";import{createJiti as u}from"jiti";let d=!1;function f(e){return e===`simple`?(process.env.NODE_ENV===`development`&&!d&&(d=!0,console.warn(`⚠️ [arkenv] The 'simple' layout option is deprecated and will be removed in the next major version. Use 'flat' instead.`)),`simple`):e===`flat`?`simple`:e}function p(r,i){let a=r?.schemaPath?t.resolve(r.schemaPath):o(),s=!1;if(a)if(e.existsSync(a))s=!0;else{let n=t.extname(a);if(n){let t=a.slice(0,-n.length);e.existsSync(t)&&(s=!0)}}if(!a||!s)throw Error(`[ArkEnv] Could not find schema file at ${r?.schemaPath||`src/env.ts or env.ts`}. Please specify 'schemaPath' in setupArkEnv options.`);let{layout:d,baseDir:p}=c(a,f(r?.layout)),m=d===`strict`&&p?p:t.dirname(a),g=t.join(m,`generated`,`env.gen.ts`),_=r?.outputPath?t.resolve(r.outputPath):g,v=r?.codegen??!0;if(v)try{h(a,_,d)}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`[ArkEnv] Failed to generate env.gen.ts: ${t}`)}if(r?.validate??!0)try{globalThis.__arkenv_force_server__=!0;let r=d===`strict`&&p?t.join(p,`server.ts`):a,o=typeof __filename<`u`?__filename:import.meta.url?n(import.meta.url):``,s=t.dirname(o),c=e.existsSync(t.join(s,`shared.ts`))?t.join(s,`shared.ts`):t.join(s,`shared.js`);u(r,{moduleCache:!1,fsCache:!1,tsconfigPaths:!0,alias:{"server-only":c,"./script":c,"./script.tsx":c,...i?._jitiAliases}})(r)}catch(e){console.error(`
|
|
2
|
+
❌ [ArkEnv] Environment validation failed:`),console.error(e instanceof Error?e.message:String(e)),console.error(``),process.exit(1)}finally{delete globalThis.__arkenv_force_server__}(process.env.NODE_ENV===`development`||process.env.NEXT_PHASE===`phase-development-server`)&&v&&l(d===`strict`&&p?[t.join(p,`internal`,`shared.ts`),t.join(p,`client.ts`),t.join(p,`server.ts`)].filter(e.existsSync):[a],()=>{h(a,_,d)})}function m(e,t){return p(t),e}function h(n,r,o){let{layout:s,baseDir:l}=c(n,f(o)),u=``;if(s===`strict`){let n=t.join(l,`client.ts`),r=t.join(l,`internal`,`shared.ts`),o=e.existsSync(n)?e.readFileSync(n,`utf-8`):``,s=e.existsSync(r)?e.readFileSync(r,`utf-8`):``;u=C(i(o),a(s))}else{let{clientKeys:t,sharedKeys:r,isLegacy:i}=_(e.readFileSync(n,`utf-8`));u=i?x(t,r):S(t,r)}let d=t.dirname(r);e.existsSync(d)||e.mkdirSync(d,{recursive:!0});let p=!0;e.existsSync(r)&&e.readFileSync(r,`utf-8`)===u&&(p=!1),p&&e.writeFileSync(r,u,`utf-8`)}function g(e){let t=/\b(?:arkenv|createEnv)\s*\(/g;for(;t.exec(e)!==null;){let n=1,r=t.lastIndex,i=null,a=null,o=0,s=0,c=[],l=``;for(;r<e.length&&n>0;){let t=e[r],u=e[r+1];if(a===`single`){(t===`
|
|
3
|
+
`||t===`\r`)&&(a=null),l+=t,r++;continue}if(a===`multi`){if(t===`*`&&u===`/`){a=null,l+=`*/`,r+=2;continue}l+=t,r++;continue}if(i){t===i&&e[r-1]!==`\\`&&(i=null),l+=t,r++;continue}if(t===`/`&&u===`/`){a=`single`,l+=`//`,r+=2;continue}if(t===`/`&&u===`*`){a=`multi`,l+=`/*`,r+=2;continue}if(t===`'`||t===`"`||t==="`"){i=t,l+=t,r++;continue}if(t===`(`?n++:t===`)`?n--:t===`{`?o++:t===`}`?o--:t===`[`?s++:t===`]`&&s--,n===0){c.push(l);break}t===`,`&&n===1&&o===0&&s===0?(c.push(l),l=``):l+=t,r++}if(n===0&&c.length>0)return{schemaArg:c[0].trim(),optionsArg:c[1]?c[1].trim():null}}return null}function _(e){let t=[],n=[],i=g(e);if(!i)return{clientKeys:t,sharedKeys:n,isLegacy:!1};let a=s(i.schemaArg.replace(/^\{/,``).replace(/\}$/,``).trim()),o=a.includes(`client`)||a.includes(`server`)||a.includes(`shared`);if(o){let e=r(i.schemaArg,`client`);e&&t.push(...s(e));let a=r(i.schemaArg,`shared`);a&&n.push(...s(a))}else{let e=[];if(i.optionsArg){let t=i.optionsArg.match(/exposeToClient\s*:\s*\[([\s\S]*?)\]/)||i.optionsArg.match(/expose\s*:\s*\[([\s\S]*?)\]/)||i.optionsArg.match(/shared\s*:\s*\[([\s\S]*?)\]/);if(t){let n=t[1].matchAll(/['"`](.*?)['"`]/g);for(let t of n)e.push(t[1])}}for(let r of a)e.includes(r)||r===`NODE_ENV`?n.push(r):r.startsWith(`NEXT_PUBLIC_`)&&t.push(r)}return{clientKeys:t,sharedKeys:n,isLegacy:o}}function v(e,t){return Array.from(new Set([...e,...t])).map(e=>`\t\t\t${e}: typeof window !== "undefined" ? (globalThis as any).__arkenv_env__?.${e} ?? process.env.${e} : process.env.${e},`).join(`
|
|
4
|
+
`)}const y=`/* eslint-disable */
|
|
4
5
|
// biome-ignore format: auto-generated
|
|
5
6
|
// Generated by ArkEnv. DO NOT EDIT DIRECTLY.
|
|
6
|
-
`,
|
|
7
|
+
`,b=`
|
|
7
8
|
export default createEnv;
|
|
8
|
-
`;function
|
|
9
|
+
`;function x(e,t){return`${y}
|
|
9
10
|
import { createEnv as coreCreateEnv } from "@arkenv/nextjs";
|
|
10
11
|
|
|
11
12
|
export { type } from "@arkenv/nextjs";
|
|
@@ -24,11 +25,11 @@ export function createEnv<
|
|
|
24
25
|
return coreCreateEnv({
|
|
25
26
|
...options,
|
|
26
27
|
runtimeEnv: {
|
|
27
|
-
${
|
|
28
|
+
${v(e,t)}
|
|
28
29
|
},
|
|
29
30
|
} as any) as any;
|
|
30
31
|
}
|
|
31
|
-
${
|
|
32
|
+
${b}`}function S(e,t){return`${y}
|
|
32
33
|
import { createEnv as coreCreateEnv } from "@arkenv/nextjs";
|
|
33
34
|
import type { type as at, distill } from "arktype";
|
|
34
35
|
|
|
@@ -56,12 +57,12 @@ export function createEnv<
|
|
|
56
57
|
const env = coreCreateEnv(schema as any, {
|
|
57
58
|
...options,
|
|
58
59
|
runtimeEnv: {
|
|
59
|
-
${
|
|
60
|
+
${v(e,t)}
|
|
60
61
|
},
|
|
61
62
|
} as any);
|
|
62
63
|
return env as unknown as Readonly<distill.Out<at.infer<TSchema>>>;
|
|
63
64
|
}
|
|
64
|
-
${
|
|
65
|
+
${b}`}function C(e,t){return`${y}
|
|
65
66
|
import { createEnv as coreCreateEnv } from "@arkenv/nextjs/client";
|
|
66
67
|
|
|
67
68
|
export { type } from "@arkenv/nextjs/client";
|
|
@@ -80,9 +81,9 @@ export function createEnv<
|
|
|
80
81
|
return coreCreateEnv<TSchema, TExtends>(schema as any, {
|
|
81
82
|
...options,
|
|
82
83
|
runtimeEnv: {
|
|
83
|
-
${
|
|
84
|
+
${v(e,t)}
|
|
84
85
|
},
|
|
85
86
|
} as any);
|
|
86
87
|
}
|
|
87
|
-
${
|
|
88
|
+
${b}`}export{i as extractClientKeys,_ as extractKeys,a as extractSharedKeys,h as runCodegen,p as setupArkEnv,m as withArkEnv};
|
|
88
89
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","names":[],"sources":["../src/config.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport {\n\textractBlock,\n\textractClientKeys,\n\textractSharedKeys,\n\tfindSchemaPath,\n\tparseBlockKeys,\n\tresolveLayout,\n\twatchSchema,\n} from \"@arkenv/build\";\n\nexport { extractClientKeys, extractSharedKeys };\n\nlet hasWarnedSimpleLayout = false;\n\nfunction normalizeLayout(\n\tlayout: ArkEnvConfigOptions[\"layout\"],\n): \"simple\" | \"strict\" | undefined {\n\tif (layout === \"simple\") {\n\t\tif (process.env.NODE_ENV === \"development\" && !hasWarnedSimpleLayout) {\n\t\t\thasWarnedSimpleLayout = true;\n\t\t\tconsole.warn(\n\t\t\t\t\"⚠️ [arkenv] The 'simple' layout option is deprecated and will be removed in the next major version. Use 'flat' instead.\",\n\t\t\t);\n\t\t}\n\t\treturn \"simple\";\n\t}\n\tif (layout === \"flat\") {\n\t\treturn \"simple\";\n\t}\n\treturn layout;\n}\n\n/**\n * Configuration options for the ArkEnv Next.js integration.\n *\n * @example\n * ```ts\n * const configOptions: ArkEnvConfigOptions = {\n * schemaPath: \"./src/env.ts\",\n * outputPath: \"./src/generated/env.gen.ts\"\n * };\n * ```\n */\nexport type ArkEnvConfigOptions = {\n\t/**\n\t * Specify the path to the schema definition file.\n\t *\n\t * Defaults to searching for `\"src/env.ts\"` or `\"env.ts\"` in the project root.\n\t *\n\t * @default \"src/env.ts\"\n\t * @example\n\t * ```ts\n\t * export default withArkEnv(nextConfig, {\n\t * schemaPath: \"./src/env.ts\"\n\t * });\n\t * ```\n\t */\n\tschemaPath?: string;\n\n\t/**\n\t * Specify the path where the generated file (`env.gen.ts`) should be written.\n\t *\n\t * Defaults to `\"generated/env.gen.ts\"` in the same directory as the schema file.\n\t *\n\t * @default \"[schemaDirectory]/generated/env.gen.ts\"\n\t * @example\n\t * ```ts\n\t * export default withArkEnv(nextConfig, {\n\t * outputPath: \"./src/generated/env.gen.ts\"\n\t * });\n\t * ```\n\t */\n\toutputPath?: string;\n\n\t/**\n\t * Specify the configuration layout.\n\t *\n\t * - `\"flat\"` (default): A single `env.ts` schema file.\n\t * - `\"strict\"`: A 3-file split schema layout (`env/internal/shared.ts`, `env/client.ts`, `env/server.ts`).\n\t *\n\t * @default \"flat\"\n\t */\n\tlayout?:\n\t\t| \"flat\"\n\t\t| \"strict\"\n\t\t/** @deprecated Use `\"flat\"` instead. `\"simple\"` will be removed in the next major version. */\n\t\t| \"simple\";\n};\n\n/**\n * Run ArkEnv codegen and setup without wrapping nextConfig.\n *\n * @param options Optional configuration paths for schema and output files\n * @throws An error if the schema file cannot be found or if code generation fails\n */\nexport function setupArkEnv(options?: ArkEnvConfigOptions): void {\n\t// 1. Locate the env.ts schema file or strict schema directory\n\tconst schemaPath = options?.schemaPath\n\t\t? path.resolve(options.schemaPath)\n\t\t: findSchemaPath();\n\n\t// Auto-detect layout if not specified\n\tlet exists = false;\n\tif (schemaPath) {\n\t\tif (fs.existsSync(schemaPath)) {\n\t\t\texists = true;\n\t\t} else {\n\t\t\tconst ext = path.extname(schemaPath);\n\t\t\tif (ext) {\n\t\t\t\tconst baseWithoutExt = schemaPath.slice(0, -ext.length);\n\t\t\t\tif (fs.existsSync(baseWithoutExt)) {\n\t\t\t\t\texists = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (!schemaPath || !exists) {\n\t\tthrow new Error(\n\t\t\t`[ArkEnv] Could not find schema file at ${\n\t\t\t\toptions?.schemaPath || \"src/env.ts or env.ts\"\n\t\t\t}. Please specify 'schemaPath' in setupArkEnv options.`,\n\t\t);\n\t}\n\n\tconst normalizedLayout = normalizeLayout(options?.layout);\n\n\tconst { layout: resolvedLayout, baseDir } = resolveLayout(\n\t\tschemaPath,\n\t\tnormalizedLayout,\n\t);\n\n\t// 2. Determine outputPath (defaults to generated/env.gen.ts in the same directory as schemaPath/baseDir)\n\tconst defaultOutputDir =\n\t\tresolvedLayout === \"strict\" && baseDir ? baseDir : path.dirname(schemaPath);\n\tconst defaultOutputPath = path.join(\n\t\tdefaultOutputDir,\n\t\t\"generated\",\n\t\t\"env.gen.ts\",\n\t);\n\tconst outputPath = options?.outputPath\n\t\t? path.resolve(options.outputPath)\n\t\t: defaultOutputPath;\n\n\t// 3. Run initial code generation\n\ttry {\n\t\trunCodegen(schemaPath, outputPath, resolvedLayout);\n\t} catch (error: unknown) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tthrow new Error(`[ArkEnv] Failed to generate env.gen.ts: ${message}`);\n\t}\n\n\t// 4. Initialize development file watcher if in dev mode\n\tconst isDev =\n\t\tprocess.env.NODE_ENV === \"development\" ||\n\t\tprocess.env.NEXT_PHASE === \"phase-development-server\";\n\tif (isDev) {\n\t\tconst watchPaths =\n\t\t\tresolvedLayout === \"strict\" && baseDir\n\t\t\t\t? [\n\t\t\t\t\t\tpath.join(baseDir, \"internal\", \"shared.ts\"),\n\t\t\t\t\t\tpath.join(baseDir, \"client.ts\"),\n\t\t\t\t\t\tpath.join(baseDir, \"server.ts\"),\n\t\t\t\t\t].filter(fs.existsSync)\n\t\t\t\t: [schemaPath];\n\t\twatchSchema(watchPaths, () => {\n\t\t\trunCodegen(schemaPath, outputPath, resolvedLayout);\n\t\t});\n\t}\n}\n\n/**\n * Wrap a Next.js configuration object to automatically generate the `runtimeEnv` block in `env.gen.ts`.\n *\n * @param nextConfig The Next.js configuration object or function\n * @param options Optional configuration paths for schema and output files\n * @returns The Next.js configuration object unchanged\n * @throws An error if the schema file cannot be found or if code generation fails\n */\nexport function withArkEnv<T>(nextConfig: T, options?: ArkEnvConfigOptions): T {\n\tsetupArkEnv(options);\n\treturn nextConfig;\n}\n\n/**\n * Run code generation to read the schema file and generate the env.gen.ts factory.\n *\n * @param schemaPath The absolute path to the schema file or directory\n * @param outputPath The absolute path to the generated output file\n * @param layoutOption The explicit layout to use; auto-detected from the filesystem when omitted\n * @throws An error if strict layout files are missing when `layoutOption` is `\"strict\"`\n */\nexport function runCodegen(\n\tschemaPath: string,\n\toutputPath: string,\n\tlayoutOption?: ArkEnvConfigOptions[\"layout\"],\n) {\n\tconst normalizedLayout = normalizeLayout(layoutOption);\n\n\tconst { layout: resolvedLayout, baseDir } = resolveLayout(\n\t\tschemaPath,\n\t\tnormalizedLayout,\n\t);\n\n\tlet generatedCode = \"\";\n\tif (resolvedLayout === \"strict\") {\n\t\tconst clientPath = path.join(baseDir, \"client.ts\");\n\t\tconst sharedPath = path.join(baseDir, \"internal\", \"shared.ts\");\n\n\t\tconst clientContent = fs.existsSync(clientPath)\n\t\t\t? fs.readFileSync(clientPath, \"utf-8\")\n\t\t\t: \"\";\n\t\tconst sharedContent = fs.existsSync(sharedPath)\n\t\t\t? fs.readFileSync(sharedPath, \"utf-8\")\n\t\t\t: \"\";\n\n\t\tconst clientKeys = extractClientKeys(clientContent);\n\t\tconst sharedKeys = extractSharedKeys(sharedContent);\n\n\t\tgeneratedCode = generateClientFactoryCode(clientKeys, sharedKeys);\n\t} else {\n\t\tconst fileContent = fs.readFileSync(schemaPath, \"utf-8\");\n\t\tconst { clientKeys, sharedKeys, isLegacy } = extractKeys(fileContent);\n\t\tif (isLegacy) {\n\t\t\tgeneratedCode = generateFactoryCode(clientKeys, sharedKeys);\n\t\t} else {\n\t\t\tgeneratedCode = generateFlatFactoryCode(clientKeys, sharedKeys);\n\t\t}\n\t}\n\n\t// Ensure parent directory exists\n\tconst outputDir = path.dirname(outputPath);\n\tif (!fs.existsSync(outputDir)) {\n\t\tfs.mkdirSync(outputDir, { recursive: true });\n\t}\n\n\t// Write if changed to avoid unnecessary filesystem/watcher triggers\n\tlet shouldWrite = true;\n\tif (fs.existsSync(outputPath)) {\n\t\tconst existingContent = fs.readFileSync(outputPath, \"utf-8\");\n\t\tif (existingContent === generatedCode) {\n\t\t\tshouldWrite = false;\n\t\t}\n\t}\n\n\tif (shouldWrite) {\n\t\tfs.writeFileSync(outputPath, generatedCode, \"utf-8\");\n\t}\n}\n\nfunction extractCallArguments(\n\tcontent: string,\n): { schemaArg: string; optionsArg: string | null } | null {\n\tconst regex = /\\b(?:arkenv|createEnv)\\s*\\(/g;\n\twhile (regex.exec(content) !== null) {\n\t\tlet parenCount = 1;\n\t\tlet index = regex.lastIndex;\n\t\tlet inString: string | null = null;\n\t\tlet inComment: \"single\" | \"multi\" | null = null;\n\t\tlet braceCount = 0;\n\t\tlet bracketCount = 0;\n\n\t\tconst args: string[] = [];\n\t\tlet currentArg = \"\";\n\n\t\twhile (index < content.length && parenCount > 0) {\n\t\t\tconst char = content[index];\n\t\t\tconst nextChar = content[index + 1];\n\n\t\t\tif (inComment === \"single\") {\n\t\t\t\tif (char === \"\\n\" || char === \"\\r\") inComment = null;\n\t\t\t\tcurrentArg += char;\n\t\t\t\tindex++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (inComment === \"multi\") {\n\t\t\t\tif (char === \"*\" && nextChar === \"/\") {\n\t\t\t\t\tinComment = null;\n\t\t\t\t\tcurrentArg += \"*/\";\n\t\t\t\t\tindex += 2;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tcurrentArg += char;\n\t\t\t\tindex++;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (inString) {\n\t\t\t\tif (char === inString && content[index - 1] !== \"\\\\\") {\n\t\t\t\t\tinString = null;\n\t\t\t\t}\n\t\t\t\tcurrentArg += char;\n\t\t\t\tindex++;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (char === \"/\" && nextChar === \"/\") {\n\t\t\t\tinComment = \"single\";\n\t\t\t\tcurrentArg += \"//\";\n\t\t\t\tindex += 2;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (char === \"/\" && nextChar === \"*\") {\n\t\t\t\tinComment = \"multi\";\n\t\t\t\tcurrentArg += \"/*\";\n\t\t\t\tindex += 2;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (char === \"'\" || char === '\"' || char === \"`\") {\n\t\t\t\tinString = char;\n\t\t\t\tcurrentArg += char;\n\t\t\t\tindex++;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (char === \"(\") {\n\t\t\t\tparenCount++;\n\t\t\t} else if (char === \")\") {\n\t\t\t\tparenCount--;\n\t\t\t} else if (char === \"{\") {\n\t\t\t\tbraceCount++;\n\t\t\t} else if (char === \"}\") {\n\t\t\t\tbraceCount--;\n\t\t\t} else if (char === \"[\") {\n\t\t\t\tbracketCount++;\n\t\t\t} else if (char === \"]\") {\n\t\t\t\tbracketCount--;\n\t\t\t}\n\n\t\t\tif (parenCount === 0) {\n\t\t\t\targs.push(currentArg);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tchar === \",\" &&\n\t\t\t\tparenCount === 1 &&\n\t\t\t\tbraceCount === 0 &&\n\t\t\t\tbracketCount === 0\n\t\t\t) {\n\t\t\t\targs.push(currentArg);\n\t\t\t\tcurrentArg = \"\";\n\t\t\t} else {\n\t\t\t\tcurrentArg += char;\n\t\t\t}\n\t\t\tindex++;\n\t\t}\n\n\t\tif (parenCount === 0 && args.length > 0) {\n\t\t\treturn {\n\t\t\t\tschemaArg: args[0].trim(),\n\t\t\t\toptionsArg: args[1] ? args[1].trim() : null,\n\t\t\t};\n\t\t}\n\t}\n\treturn null;\n}\n\n/**\n * Statically extract client and shared keys from the schema content.\n *\n * @param content The schema file string content\n * @returns An object containing the extracted client and shared keys\n */\nexport function extractKeys(content: string): {\n\tclientKeys: string[];\n\tsharedKeys: string[];\n\tisLegacy?: boolean;\n} {\n\tconst clientKeys: string[] = [];\n\tconst sharedKeys: string[] = [];\n\n\tconst args = extractCallArguments(content);\n\tif (!args) {\n\t\treturn { clientKeys, sharedKeys, isLegacy: false };\n\t}\n\n\t// Strip outer braces if present\n\tconst trimmedSchema = args.schemaArg\n\t\t.replace(/^\\{/, \"\")\n\t\t.replace(/\\}$/, \"\")\n\t\t.trim();\n\tconst topKeys = parseBlockKeys(trimmedSchema);\n\tconst isLegacy =\n\t\ttopKeys.includes(\"client\") ||\n\t\ttopKeys.includes(\"server\") ||\n\t\ttopKeys.includes(\"shared\");\n\n\tif (isLegacy) {\n\t\tconst clientBlock = extractBlock(args.schemaArg, \"client\");\n\t\tif (clientBlock) {\n\t\t\tclientKeys.push(...parseBlockKeys(clientBlock));\n\t\t}\n\t\tconst sharedBlock = extractBlock(args.schemaArg, \"shared\");\n\t\tif (sharedBlock) {\n\t\t\tsharedKeys.push(...parseBlockKeys(sharedBlock));\n\t\t}\n\t} else {\n\t\t// New flat layout\n\t\tconst optionExposedKeys: string[] = [];\n\t\tif (args.optionsArg) {\n\t\t\tconst exposeMatch =\n\t\t\t\targs.optionsArg.match(/exposeToClient\\s*:\\s*\\[([\\s\\S]*?)\\]/) ||\n\t\t\t\targs.optionsArg.match(/expose\\s*:\\s*\\[([\\s\\S]*?)\\]/) ||\n\t\t\t\targs.optionsArg.match(/shared\\s*:\\s*\\[([\\s\\S]*?)\\]/);\n\t\t\tif (exposeMatch) {\n\t\t\t\tconst matches = exposeMatch[1].matchAll(/['\"`](.*?)['\"`]/g);\n\t\t\t\tfor (const match of matches) {\n\t\t\t\t\toptionExposedKeys.push(match[1]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const key of topKeys) {\n\t\t\t// NODE_ENV is implicitly shared as Next.js automatically inlines and replaces references to process.env.NODE_ENV in browser bundles.\n\t\t\t// See: https://nextjs.org/docs/app/guides/environment-variables\n\t\t\tif (optionExposedKeys.includes(key) || key === \"NODE_ENV\") {\n\t\t\t\tsharedKeys.push(key);\n\t\t\t} else if (key.startsWith(\"NEXT_PUBLIC_\")) {\n\t\t\t\tclientKeys.push(key);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn { clientKeys, sharedKeys, isLegacy };\n}\n\n/**\n * Generate the triple-tab indented runtime environment variables mapping.\n */\nfunction generateRuntimeEnvLines(\n\tclientKeys: string[],\n\tsharedKeys: string[],\n): string {\n\tconst allKeys = Array.from(new Set([...clientKeys, ...sharedKeys]));\n\treturn allKeys\n\t\t.map(\n\t\t\t(key) =>\n\t\t\t\t`\\t\\t\\t${key}: typeof window !== \"undefined\" ? (globalThis as any).__arkenv_env__?.${key} ?? process.env.${key} : process.env.${key},`,\n\t\t)\n\t\t.join(\"\\n\");\n}\n\nconst GENERATED_HEADER = `/* eslint-disable */\n// biome-ignore format: auto-generated\n// Generated by ArkEnv. DO NOT EDIT DIRECTLY.\n`;\n\nconst GENERATED_FOOTER = `\nexport default createEnv;\n`;\n\n/**\n * Generate the TypeScript factory code for the tailored createEnv helper.\n *\n * @param clientKeys The client environment variable keys\n * @param sharedKeys The shared environment variable keys\n * @returns The generated TypeScript source code string\n */\nfunction generateFactoryCode(\n\tclientKeys: string[],\n\tsharedKeys: string[],\n): string {\n\tconst runtimeEnvLines = generateRuntimeEnvLines(clientKeys, sharedKeys);\n\n\treturn `${GENERATED_HEADER}\nimport { createEnv as coreCreateEnv } from \"@arkenv/nextjs\";\n\nexport { type } from \"@arkenv/nextjs\";\n\nexport function createEnv<\n\tconst TServer extends Record<string, any> = {},\n\tconst TClient extends Record<string, any> = {},\n\tconst TShared extends Record<string, any> = {},\n>(options: {\n\tserver?: TServer;\n\tclient?: TClient & {\n\t\t[K in keyof TClient]: K extends \\`NEXT_PUBLIC_\\${string}\\` ? unknown : never;\n\t};\n\tshared?: TShared;\n}) {\n\treturn coreCreateEnv({\n\t\t...options,\n\t\truntimeEnv: {\n${runtimeEnvLines}\n\t\t},\n\t} as any) as any;\n}\n${GENERATED_FOOTER}`;\n}\n\n/**\n * Generate the TypeScript factory code for the Flat Layout createEnv helper.\n *\n * @remarks\n * **Architecture tripwire:** Do not statically compile the schema here or\n * reference internal-only types (the `$` scope or `MergeExtends`).\n *\n * - **Generic wrapper:** The factory must stay generic because the concrete\n * schema is owned by the user-land `env.ts`.\n * - **Type strategy:** It intentionally returns the full schema type to ensure\n * flawless Server Component autocomplete.\n * - **Security boundary:** Client-side protection is deliberately deferred to\n * the runtime Proxy in `@arkenv/nextjs`, which throws on unauthorized access.\n *\n * 📖 See ADR-0010: Flat layout codegen and type inference strategy\n * (`docs/adr/0010-flat-layout-codegen-type-strategy.md`).\n */\nfunction generateFlatFactoryCode(\n\tclientKeys: string[],\n\tsharedKeys: string[],\n): string {\n\tconst runtimeEnvLines = generateRuntimeEnvLines(clientKeys, sharedKeys);\n\n\treturn `${GENERATED_HEADER}\nimport { createEnv as coreCreateEnv } from \"@arkenv/nextjs\";\nimport type { type as at, distill } from \"arktype\";\n\nexport { type } from \"@arkenv/nextjs\";\n\nexport function createEnv<\n\tconst TSchema extends Record<string, unknown> & { runtimeEnv?: never } = {},\n\tconst TExpose extends keyof TSchema = never,\n\tconst TExtends extends readonly unknown[] = [],\n>(\n\tschema: TSchema,\n\toptions?: {\n\t\t/**\n\t\t * Custom environment variables to expose to the client bundle.\n\t\t * By default, variables prefixed with \\`NEXT_PUBLIC_\\` and \\`NODE_ENV\\` are exposed automatically.\n\t\t * Use this option to expose custom variables that do not have the \\`NEXT_PUBLIC_\\` prefix.\n\t\t */\n\t\texposeToClient?: readonly TExpose[];\n\t\textends?: [...TExtends];\n\t},\n): Readonly<distill.Out<at.infer<TSchema>>> {\n\t// Types expose the full schema for a great DX on the server; the runtime\n\t// Proxy from \\`@arkenv/nextjs\\` enforces the security boundary by throwing\n\t// when a server-only variable is accessed on the client.\n\tconst env = coreCreateEnv(schema as any, {\n\t\t...options,\n\t\truntimeEnv: {\n${runtimeEnvLines}\n\t\t},\n\t} as any);\n\treturn env as unknown as Readonly<distill.Out<at.infer<TSchema>>>;\n}\n${GENERATED_FOOTER}`;\n}\n\n/**\n * Generate the TypeScript factory code for the strict-layout `createEnv` helper.\n *\n * Unlike `generateFactoryCode`, this variant imports from `@arkenv/nextjs/client`\n * and exposes a positional-schema signature suited for split-file projects.\n *\n * @param clientKeys The env var keys extracted from `client.ts`\n * @param sharedKeys The env var keys extracted from `internal/shared.ts`\n * @returns The generated TypeScript source code string\n */\nfunction generateClientFactoryCode(\n\tclientKeys: string[],\n\tsharedKeys: string[],\n): string {\n\tconst runtimeEnvLines = generateRuntimeEnvLines(clientKeys, sharedKeys);\n\n\treturn `${GENERATED_HEADER}\nimport { createEnv as coreCreateEnv } from \"@arkenv/nextjs/client\";\n\nexport { type } from \"@arkenv/nextjs/client\";\n\nexport function createEnv<\n\tconst TSchema extends Record<string, any> = {},\n\tconst TExtends extends readonly unknown[] = [],\n>(\n\tschema: TSchema & {\n\t\t[K in keyof TSchema]: K extends \\`NEXT_PUBLIC_\\${string}\\` ? unknown : never;\n\t},\n\toptions?: {\n\t\textends?: [...TExtends];\n\t},\n) {\n\treturn coreCreateEnv<TSchema, TExtends>(schema as any, {\n\t\t...options,\n\t\truntimeEnv: {\n${runtimeEnvLines}\n\t\t},\n\t} as any);\n}\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AAY,EAqB5C,CAAC;;;;EAIhB"}
|
|
1
|
+
{"version":3,"file":"config.js","names":[],"sources":["../src/config.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport {\n\textractBlock,\n\textractClientKeys,\n\textractSharedKeys,\n\tfindSchemaPath,\n\tparseBlockKeys,\n\tresolveLayout,\n\twatchSchema,\n} from \"@arkenv/build\";\nimport { createJiti } from \"jiti\";\n\nexport { extractClientKeys, extractSharedKeys };\n\nlet hasWarnedSimpleLayout = false;\n\nfunction normalizeLayout(\n\tlayout: ArkEnvConfigOptions[\"layout\"],\n): \"simple\" | \"strict\" | undefined {\n\tif (layout === \"simple\") {\n\t\tif (process.env.NODE_ENV === \"development\" && !hasWarnedSimpleLayout) {\n\t\t\thasWarnedSimpleLayout = true;\n\t\t\tconsole.warn(\n\t\t\t\t\"⚠️ [arkenv] The 'simple' layout option is deprecated and will be removed in the next major version. Use 'flat' instead.\",\n\t\t\t);\n\t\t}\n\t\treturn \"simple\";\n\t}\n\tif (layout === \"flat\") {\n\t\treturn \"simple\";\n\t}\n\treturn layout;\n}\n\n/**\n * Configuration options for the ArkEnv Next.js integration.\n *\n * @example\n * ```ts\n * const configOptions: ArkEnvConfigOptions = {\n * schemaPath: \"./src/env.ts\",\n * outputPath: \"./src/generated/env.gen.ts\"\n * };\n * ```\n */\nexport type ArkEnvConfigOptions = {\n\t/**\n\t * Specify the path to the schema definition file.\n\t *\n\t * Defaults to searching for `\"src/env.ts\"` or `\"env.ts\"` in the project root.\n\t *\n\t * @default \"src/env.ts\"\n\t * @example\n\t * ```ts\n\t * export default withArkEnv(nextConfig, {\n\t * schemaPath: \"./src/env.ts\"\n\t * });\n\t * ```\n\t */\n\tschemaPath?: string;\n\n\t/**\n\t * Specify the path where the generated file (`env.gen.ts`) should be written.\n\t *\n\t * Defaults to `\"generated/env.gen.ts\"` in the same directory as the schema file.\n\t *\n\t * @default \"[schemaDirectory]/generated/env.gen.ts\"\n\t * @example\n\t * ```ts\n\t * export default withArkEnv(nextConfig, {\n\t * outputPath: \"./src/generated/env.gen.ts\"\n\t * });\n\t * ```\n\t */\n\toutputPath?: string;\n\n\t/**\n\t * Specify the configuration layout.\n\t *\n\t * - `\"flat\"` (default): A single `env.ts` schema file.\n\t * - `\"strict\"`: A 3-file split schema layout (`env/internal/shared.ts`, `env/client.ts`, `env/server.ts`).\n\t *\n\t * @default \"flat\"\n\t */\n\tlayout?:\n\t\t| \"flat\"\n\t\t| \"strict\"\n\t\t/** @deprecated Use `\"flat\"` instead. `\"simple\"` will be removed in the next major version. */\n\t\t| \"simple\";\n\n\t/**\n\t * Enable or disable build-time environment variable validation during build/dev startup.\n\t *\n\t * @default true\n\t */\n\tvalidate?: boolean;\n\n\t/**\n\t * Enable or disable automatic code generation of the `env.gen.ts` file.\n\t *\n\t * @default true\n\t */\n\tcodegen?: boolean;\n};\n\n/**\n * Run ArkEnv codegen and setup without wrapping nextConfig.\n *\n * @param options Optional configuration paths for schema and output files\n * @param internalOptions Optional configuration for internal testing hooks\n * @throws An error if the schema file cannot be found or if code generation fails\n */\nexport function setupArkEnv(\n\toptions?: ArkEnvConfigOptions,\n\tinternalOptions?: { _jitiAliases?: Record<string, string> },\n): void {\n\t// 1. Locate the env.ts schema file or strict schema directory\n\tconst schemaPath = options?.schemaPath\n\t\t? path.resolve(options.schemaPath)\n\t\t: findSchemaPath();\n\n\t// Auto-detect layout if not specified\n\tlet exists = false;\n\tif (schemaPath) {\n\t\tif (fs.existsSync(schemaPath)) {\n\t\t\texists = true;\n\t\t} else {\n\t\t\tconst ext = path.extname(schemaPath);\n\t\t\tif (ext) {\n\t\t\t\tconst baseWithoutExt = schemaPath.slice(0, -ext.length);\n\t\t\t\tif (fs.existsSync(baseWithoutExt)) {\n\t\t\t\t\texists = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (!schemaPath || !exists) {\n\t\tthrow new Error(\n\t\t\t`[ArkEnv] Could not find schema file at ${\n\t\t\t\toptions?.schemaPath || \"src/env.ts or env.ts\"\n\t\t\t}. Please specify 'schemaPath' in setupArkEnv options.`,\n\t\t);\n\t}\n\n\tconst normalizedLayout = normalizeLayout(options?.layout);\n\n\tconst { layout: resolvedLayout, baseDir } = resolveLayout(\n\t\tschemaPath,\n\t\tnormalizedLayout,\n\t);\n\n\t// 2. Determine outputPath (defaults to generated/env.gen.ts in the same directory as schemaPath/baseDir)\n\tconst defaultOutputDir =\n\t\tresolvedLayout === \"strict\" && baseDir ? baseDir : path.dirname(schemaPath);\n\tconst defaultOutputPath = path.join(\n\t\tdefaultOutputDir,\n\t\t\"generated\",\n\t\t\"env.gen.ts\",\n\t);\n\tconst outputPath = options?.outputPath\n\t\t? path.resolve(options.outputPath)\n\t\t: defaultOutputPath;\n\n\t// 3. Run initial code generation if enabled\n\tconst codegen = options?.codegen ?? true;\n\tif (codegen) {\n\t\ttry {\n\t\t\trunCodegen(schemaPath, outputPath, resolvedLayout);\n\t\t} catch (error: unknown) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tthrow new Error(`[ArkEnv] Failed to generate env.gen.ts: ${message}`);\n\t\t}\n\t}\n\n\t// 4. Validate schema against environment variables\n\tconst runValidation = options?.validate ?? true;\n\tif (runValidation) {\n\t\ttry {\n\t\t\t(globalThis as any).__arkenv_force_server__ = true;\n\t\t\tconst fileToEvaluate =\n\t\t\t\tresolvedLayout === \"strict\" && baseDir\n\t\t\t\t\t? path.join(baseDir, \"server.ts\")\n\t\t\t\t\t: schemaPath;\n\n\t\t\tconst filenameForJiti =\n\t\t\t\ttypeof __filename !== \"undefined\"\n\t\t\t\t\t? __filename\n\t\t\t\t\t: typeof import.meta !== \"undefined\" && import.meta.url\n\t\t\t\t\t\t? fileURLToPath(import.meta.url)\n\t\t\t\t\t\t: \"\";\n\t\t\tconst dir = path.dirname(filenameForJiti);\n\t\t\tconst sharedPath = fs.existsSync(path.join(dir, \"shared.ts\"))\n\t\t\t\t? path.join(dir, \"shared.ts\")\n\t\t\t\t: path.join(dir, \"shared.js\");\n\n\t\t\tconst aliases: Record<string, string> = {\n\t\t\t\t\"server-only\": sharedPath,\n\t\t\t\t\"./script\": sharedPath,\n\t\t\t\t\"./script.tsx\": sharedPath,\n\t\t\t\t...internalOptions?._jitiAliases,\n\t\t\t};\n\n\t\t\tconst jiti = createJiti(fileToEvaluate, {\n\t\t\t\tmoduleCache: false,\n\t\t\t\tfsCache: false,\n\t\t\t\ttsconfigPaths: true,\n\t\t\t\talias: aliases,\n\t\t\t});\n\t\t\tjiti(fileToEvaluate);\n\t\t} catch (error: unknown) {\n\t\t\tconsole.error(\"\\n❌ [ArkEnv] Environment validation failed:\");\n\t\t\tconsole.error(error instanceof Error ? error.message : String(error));\n\t\t\tconsole.error(\"\");\n\t\t\tprocess.exit(1);\n\t\t} finally {\n\t\t\tdelete (globalThis as any).__arkenv_force_server__;\n\t\t}\n\t}\n\n\t// 5. Initialize development file watcher if in dev mode and codegen is enabled\n\tconst isDev =\n\t\tprocess.env.NODE_ENV === \"development\" ||\n\t\tprocess.env.NEXT_PHASE === \"phase-development-server\";\n\tif (isDev && codegen) {\n\t\tconst watchPaths =\n\t\t\tresolvedLayout === \"strict\" && baseDir\n\t\t\t\t? [\n\t\t\t\t\t\tpath.join(baseDir, \"internal\", \"shared.ts\"),\n\t\t\t\t\t\tpath.join(baseDir, \"client.ts\"),\n\t\t\t\t\t\tpath.join(baseDir, \"server.ts\"),\n\t\t\t\t\t].filter(fs.existsSync)\n\t\t\t\t: [schemaPath];\n\t\twatchSchema(watchPaths, () => {\n\t\t\trunCodegen(schemaPath, outputPath, resolvedLayout);\n\t\t});\n\t}\n}\n\n/**\n * Wrap a Next.js configuration object to automatically generate the `runtimeEnv` block in `env.gen.ts`.\n *\n * @param nextConfig The Next.js configuration object or function\n * @param options Optional configuration paths for schema and output files\n * @returns The Next.js configuration object unchanged\n * @throws An error if the schema file cannot be found or if code generation fails\n */\nexport function withArkEnv<T>(nextConfig: T, options?: ArkEnvConfigOptions): T {\n\tsetupArkEnv(options);\n\treturn nextConfig;\n}\n\n/**\n * Run code generation to read the schema file and generate the env.gen.ts factory.\n *\n * @param schemaPath The absolute path to the schema file or directory\n * @param outputPath The absolute path to the generated output file\n * @param layoutOption The explicit layout to use; auto-detected from the filesystem when omitted\n * @throws An error if strict layout files are missing when `layoutOption` is `\"strict\"`\n */\nexport function runCodegen(\n\tschemaPath: string,\n\toutputPath: string,\n\tlayoutOption?: ArkEnvConfigOptions[\"layout\"],\n) {\n\tconst normalizedLayout = normalizeLayout(layoutOption);\n\n\tconst { layout: resolvedLayout, baseDir } = resolveLayout(\n\t\tschemaPath,\n\t\tnormalizedLayout,\n\t);\n\n\tlet generatedCode = \"\";\n\tif (resolvedLayout === \"strict\") {\n\t\tconst clientPath = path.join(baseDir, \"client.ts\");\n\t\tconst sharedPath = path.join(baseDir, \"internal\", \"shared.ts\");\n\n\t\tconst clientContent = fs.existsSync(clientPath)\n\t\t\t? fs.readFileSync(clientPath, \"utf-8\")\n\t\t\t: \"\";\n\t\tconst sharedContent = fs.existsSync(sharedPath)\n\t\t\t? fs.readFileSync(sharedPath, \"utf-8\")\n\t\t\t: \"\";\n\n\t\tconst clientKeys = extractClientKeys(clientContent);\n\t\tconst sharedKeys = extractSharedKeys(sharedContent);\n\n\t\tgeneratedCode = generateClientFactoryCode(clientKeys, sharedKeys);\n\t} else {\n\t\tconst fileContent = fs.readFileSync(schemaPath, \"utf-8\");\n\t\tconst { clientKeys, sharedKeys, isLegacy } = extractKeys(fileContent);\n\t\tif (isLegacy) {\n\t\t\tgeneratedCode = generateFactoryCode(clientKeys, sharedKeys);\n\t\t} else {\n\t\t\tgeneratedCode = generateFlatFactoryCode(clientKeys, sharedKeys);\n\t\t}\n\t}\n\n\t// Ensure parent directory exists\n\tconst outputDir = path.dirname(outputPath);\n\tif (!fs.existsSync(outputDir)) {\n\t\tfs.mkdirSync(outputDir, { recursive: true });\n\t}\n\n\t// Write if changed to avoid unnecessary filesystem/watcher triggers\n\tlet shouldWrite = true;\n\tif (fs.existsSync(outputPath)) {\n\t\tconst existingContent = fs.readFileSync(outputPath, \"utf-8\");\n\t\tif (existingContent === generatedCode) {\n\t\t\tshouldWrite = false;\n\t\t}\n\t}\n\n\tif (shouldWrite) {\n\t\tfs.writeFileSync(outputPath, generatedCode, \"utf-8\");\n\t}\n}\n\nfunction extractCallArguments(\n\tcontent: string,\n): { schemaArg: string; optionsArg: string | null } | null {\n\tconst regex = /\\b(?:arkenv|createEnv)\\s*\\(/g;\n\twhile (regex.exec(content) !== null) {\n\t\tlet parenCount = 1;\n\t\tlet index = regex.lastIndex;\n\t\tlet inString: string | null = null;\n\t\tlet inComment: \"single\" | \"multi\" | null = null;\n\t\tlet braceCount = 0;\n\t\tlet bracketCount = 0;\n\n\t\tconst args: string[] = [];\n\t\tlet currentArg = \"\";\n\n\t\twhile (index < content.length && parenCount > 0) {\n\t\t\tconst char = content[index];\n\t\t\tconst nextChar = content[index + 1];\n\n\t\t\tif (inComment === \"single\") {\n\t\t\t\tif (char === \"\\n\" || char === \"\\r\") inComment = null;\n\t\t\t\tcurrentArg += char;\n\t\t\t\tindex++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (inComment === \"multi\") {\n\t\t\t\tif (char === \"*\" && nextChar === \"/\") {\n\t\t\t\t\tinComment = null;\n\t\t\t\t\tcurrentArg += \"*/\";\n\t\t\t\t\tindex += 2;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tcurrentArg += char;\n\t\t\t\tindex++;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (inString) {\n\t\t\t\tif (char === inString && content[index - 1] !== \"\\\\\") {\n\t\t\t\t\tinString = null;\n\t\t\t\t}\n\t\t\t\tcurrentArg += char;\n\t\t\t\tindex++;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (char === \"/\" && nextChar === \"/\") {\n\t\t\t\tinComment = \"single\";\n\t\t\t\tcurrentArg += \"//\";\n\t\t\t\tindex += 2;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (char === \"/\" && nextChar === \"*\") {\n\t\t\t\tinComment = \"multi\";\n\t\t\t\tcurrentArg += \"/*\";\n\t\t\t\tindex += 2;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (char === \"'\" || char === '\"' || char === \"`\") {\n\t\t\t\tinString = char;\n\t\t\t\tcurrentArg += char;\n\t\t\t\tindex++;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (char === \"(\") {\n\t\t\t\tparenCount++;\n\t\t\t} else if (char === \")\") {\n\t\t\t\tparenCount--;\n\t\t\t} else if (char === \"{\") {\n\t\t\t\tbraceCount++;\n\t\t\t} else if (char === \"}\") {\n\t\t\t\tbraceCount--;\n\t\t\t} else if (char === \"[\") {\n\t\t\t\tbracketCount++;\n\t\t\t} else if (char === \"]\") {\n\t\t\t\tbracketCount--;\n\t\t\t}\n\n\t\t\tif (parenCount === 0) {\n\t\t\t\targs.push(currentArg);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tchar === \",\" &&\n\t\t\t\tparenCount === 1 &&\n\t\t\t\tbraceCount === 0 &&\n\t\t\t\tbracketCount === 0\n\t\t\t) {\n\t\t\t\targs.push(currentArg);\n\t\t\t\tcurrentArg = \"\";\n\t\t\t} else {\n\t\t\t\tcurrentArg += char;\n\t\t\t}\n\t\t\tindex++;\n\t\t}\n\n\t\tif (parenCount === 0 && args.length > 0) {\n\t\t\treturn {\n\t\t\t\tschemaArg: args[0].trim(),\n\t\t\t\toptionsArg: args[1] ? args[1].trim() : null,\n\t\t\t};\n\t\t}\n\t}\n\treturn null;\n}\n\n/**\n * Statically extract client and shared keys from the schema content.\n *\n * @param content The schema file string content\n * @returns An object containing the extracted client and shared keys\n */\nexport function extractKeys(content: string): {\n\tclientKeys: string[];\n\tsharedKeys: string[];\n\tisLegacy?: boolean;\n} {\n\tconst clientKeys: string[] = [];\n\tconst sharedKeys: string[] = [];\n\n\tconst args = extractCallArguments(content);\n\tif (!args) {\n\t\treturn { clientKeys, sharedKeys, isLegacy: false };\n\t}\n\n\t// Strip outer braces if present\n\tconst trimmedSchema = args.schemaArg\n\t\t.replace(/^\\{/, \"\")\n\t\t.replace(/\\}$/, \"\")\n\t\t.trim();\n\tconst topKeys = parseBlockKeys(trimmedSchema);\n\tconst isLegacy =\n\t\ttopKeys.includes(\"client\") ||\n\t\ttopKeys.includes(\"server\") ||\n\t\ttopKeys.includes(\"shared\");\n\n\tif (isLegacy) {\n\t\tconst clientBlock = extractBlock(args.schemaArg, \"client\");\n\t\tif (clientBlock) {\n\t\t\tclientKeys.push(...parseBlockKeys(clientBlock));\n\t\t}\n\t\tconst sharedBlock = extractBlock(args.schemaArg, \"shared\");\n\t\tif (sharedBlock) {\n\t\t\tsharedKeys.push(...parseBlockKeys(sharedBlock));\n\t\t}\n\t} else {\n\t\t// New flat layout\n\t\tconst optionExposedKeys: string[] = [];\n\t\tif (args.optionsArg) {\n\t\t\tconst exposeMatch =\n\t\t\t\targs.optionsArg.match(/exposeToClient\\s*:\\s*\\[([\\s\\S]*?)\\]/) ||\n\t\t\t\targs.optionsArg.match(/expose\\s*:\\s*\\[([\\s\\S]*?)\\]/) ||\n\t\t\t\targs.optionsArg.match(/shared\\s*:\\s*\\[([\\s\\S]*?)\\]/);\n\t\t\tif (exposeMatch) {\n\t\t\t\tconst matches = exposeMatch[1].matchAll(/['\"`](.*?)['\"`]/g);\n\t\t\t\tfor (const match of matches) {\n\t\t\t\t\toptionExposedKeys.push(match[1]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const key of topKeys) {\n\t\t\t// NODE_ENV is implicitly shared as Next.js automatically inlines and replaces references to process.env.NODE_ENV in browser bundles.\n\t\t\t// See: https://nextjs.org/docs/app/guides/environment-variables\n\t\t\tif (optionExposedKeys.includes(key) || key === \"NODE_ENV\") {\n\t\t\t\tsharedKeys.push(key);\n\t\t\t} else if (key.startsWith(\"NEXT_PUBLIC_\")) {\n\t\t\t\tclientKeys.push(key);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn { clientKeys, sharedKeys, isLegacy };\n}\n\n/**\n * Generate the triple-tab indented runtime environment variables mapping.\n */\nfunction generateRuntimeEnvLines(\n\tclientKeys: string[],\n\tsharedKeys: string[],\n): string {\n\tconst allKeys = Array.from(new Set([...clientKeys, ...sharedKeys]));\n\treturn allKeys\n\t\t.map(\n\t\t\t(key) =>\n\t\t\t\t`\\t\\t\\t${key}: typeof window !== \"undefined\" ? (globalThis as any).__arkenv_env__?.${key} ?? process.env.${key} : process.env.${key},`,\n\t\t)\n\t\t.join(\"\\n\");\n}\n\nconst GENERATED_HEADER = `/* eslint-disable */\n// biome-ignore format: auto-generated\n// Generated by ArkEnv. DO NOT EDIT DIRECTLY.\n`;\n\nconst GENERATED_FOOTER = `\nexport default createEnv;\n`;\n\n/**\n * Generate the TypeScript factory code for the tailored createEnv helper.\n *\n * @param clientKeys The client environment variable keys\n * @param sharedKeys The shared environment variable keys\n * @returns The generated TypeScript source code string\n */\nfunction generateFactoryCode(\n\tclientKeys: string[],\n\tsharedKeys: string[],\n): string {\n\tconst runtimeEnvLines = generateRuntimeEnvLines(clientKeys, sharedKeys);\n\n\treturn `${GENERATED_HEADER}\nimport { createEnv as coreCreateEnv } from \"@arkenv/nextjs\";\n\nexport { type } from \"@arkenv/nextjs\";\n\nexport function createEnv<\n\tconst TServer extends Record<string, any> = {},\n\tconst TClient extends Record<string, any> = {},\n\tconst TShared extends Record<string, any> = {},\n>(options: {\n\tserver?: TServer;\n\tclient?: TClient & {\n\t\t[K in keyof TClient]: K extends \\`NEXT_PUBLIC_\\${string}\\` ? unknown : never;\n\t};\n\tshared?: TShared;\n}) {\n\treturn coreCreateEnv({\n\t\t...options,\n\t\truntimeEnv: {\n${runtimeEnvLines}\n\t\t},\n\t} as any) as any;\n}\n${GENERATED_FOOTER}`;\n}\n\n/**\n * Generate the TypeScript factory code for the Flat Layout createEnv helper.\n *\n * @remarks\n * **Architecture tripwire:** Do not statically compile the schema here or\n * reference internal-only types (the `$` scope or `MergeExtends`).\n *\n * - **Generic wrapper:** The factory must stay generic because the concrete\n * schema is owned by the user-land `env.ts`.\n * - **Type strategy:** It intentionally returns the full schema type to ensure\n * flawless Server Component autocomplete.\n * - **Security boundary:** Client-side protection is deliberately deferred to\n * the runtime Proxy in `@arkenv/nextjs`, which throws on unauthorized access.\n *\n * 📖 See ADR-0010: Flat layout codegen and type inference strategy\n * (`docs/adr/0010-flat-layout-codegen-type-strategy.md`).\n */\nfunction generateFlatFactoryCode(\n\tclientKeys: string[],\n\tsharedKeys: string[],\n): string {\n\tconst runtimeEnvLines = generateRuntimeEnvLines(clientKeys, sharedKeys);\n\n\treturn `${GENERATED_HEADER}\nimport { createEnv as coreCreateEnv } from \"@arkenv/nextjs\";\nimport type { type as at, distill } from \"arktype\";\n\nexport { type } from \"@arkenv/nextjs\";\n\nexport function createEnv<\n\tconst TSchema extends Record<string, unknown> & { runtimeEnv?: never } = {},\n\tconst TExpose extends keyof TSchema = never,\n\tconst TExtends extends readonly unknown[] = [],\n>(\n\tschema: TSchema,\n\toptions?: {\n\t\t/**\n\t\t * Custom environment variables to expose to the client bundle.\n\t\t * By default, variables prefixed with \\`NEXT_PUBLIC_\\` and \\`NODE_ENV\\` are exposed automatically.\n\t\t * Use this option to expose custom variables that do not have the \\`NEXT_PUBLIC_\\` prefix.\n\t\t */\n\t\texposeToClient?: readonly TExpose[];\n\t\textends?: [...TExtends];\n\t},\n): Readonly<distill.Out<at.infer<TSchema>>> {\n\t// Types expose the full schema for a great DX on the server; the runtime\n\t// Proxy from \\`@arkenv/nextjs\\` enforces the security boundary by throwing\n\t// when a server-only variable is accessed on the client.\n\tconst env = coreCreateEnv(schema as any, {\n\t\t...options,\n\t\truntimeEnv: {\n${runtimeEnvLines}\n\t\t},\n\t} as any);\n\treturn env as unknown as Readonly<distill.Out<at.infer<TSchema>>>;\n}\n${GENERATED_FOOTER}`;\n}\n\n/**\n * Generate the TypeScript factory code for the strict-layout `createEnv` helper.\n *\n * Unlike `generateFactoryCode`, this variant imports from `@arkenv/nextjs/client`\n * and exposes a positional-schema signature suited for split-file projects.\n *\n * @param clientKeys The env var keys extracted from `client.ts`\n * @param sharedKeys The env var keys extracted from `internal/shared.ts`\n * @returns The generated TypeScript source code string\n */\nfunction generateClientFactoryCode(\n\tclientKeys: string[],\n\tsharedKeys: string[],\n): string {\n\tconst runtimeEnvLines = generateRuntimeEnvLines(clientKeys, sharedKeys);\n\n\treturn `${GENERATED_HEADER}\nimport { createEnv as coreCreateEnv } from \"@arkenv/nextjs/client\";\n\nexport { type } from \"@arkenv/nextjs/client\";\n\nexport function createEnv<\n\tconst TSchema extends Record<string, any> = {},\n\tconst TExtends extends readonly unknown[] = [],\n>(\n\tschema: TSchema & {\n\t\t[K in keyof TSchema]: K extends \\`NEXT_PUBLIC_\\${string}\\` ? unknown : never;\n\t},\n\toptions?: {\n\t\textends?: [...TExtends];\n\t},\n) {\n\treturn coreCreateEnv<TSchema, TExtends>(schema as any, {\n\t\t...options,\n\t\truntimeEnv: {\n${runtimeEnvLines}\n\t\t},\n\t} as any);\n}\n${GENERATED_FOOTER}`;\n}\n"],"mappings":"kSAgBA,IAAI,EAAwB,GAE5B,SAAS,EACR,EACkC,CAalC,OAZI,IAAW,UACV,QAAQ,IAAI,WAAa,eAAiB,CAAC,IAC9C,EAAwB,GACxB,QAAQ,KACP,0HACA,EAEK,UAEJ,IAAW,OACP,SAED,EAiFR,SAAgB,EACf,EACA,EACO,CAEP,IAAM,EAAa,GAAS,WACzB,EAAK,QAAQ,EAAQ,WAAW,CAChC,GAAgB,CAGf,EAAS,GACb,GAAI,EACH,GAAI,EAAG,WAAW,EAAW,CAC5B,EAAS,OACH,CACN,IAAM,EAAM,EAAK,QAAQ,EAAW,CACpC,GAAI,EAAK,CACR,IAAM,EAAiB,EAAW,MAAM,EAA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;;;;;EAFH,EAAwB,EAAY,EAqB5C,CAAC;;;;EAIhB,IAoBF,SAAS,EACR,EACA,EACS,CAGT,MAAO,GAAG,EAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAFH,EAAwB,EAAY,EA8B5C,CAAC;;;;;EAKhB,IAaF,SAAS,EACR,EACA,EACS,CAGT,MAAO,GAAG,EAAiB;;;;;;;;;;;;;;;;;;;EAFH,EAAwB,EAAY,EAqB5C,CAAC;;;;EAIhB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{createEnv as e}from"arkenv";const t=Symbol.for(`arkenv.extended_env`),n=Symbol.for(`arkenv.keys`),r=Symbol.for(`arkenv.server_only_keys`);let i=!1;function a(e){if(!e||typeof e!=`object`&&typeof e!=`function`)return[];if(e.json&&typeof e.json==`object`&&e.json.domain===`object`){let t=[];if(Array.isArray(e.json.required))for(let n of e.json.required)n&&typeof n==`object`&&`key`in n&&t.push(n.key);if(Array.isArray(e.json.optional))for(let n of e.json.optional)n&&typeof n==`object`&&`key`in n&&t.push(n.key);return t}return`shape`in e&&e.shape&&typeof e.shape==`object`?Object.keys(e.shape):`entries`in e&&e.entries&&typeof e.entries==`object`?Object.keys(e.entries):Object.keys(e)}function o(o,s,c){let l={},u={},d={},f=[],p={},m=!1;if(typeof s==`boolean`)process.env.NODE_ENV===`development`&&!i&&(i=!0,console.warn(`⚠️ [arkenv] Deprecated: The nested layout structure (specifying 'server', 'client', or 'shared' keys in createEnv) is deprecated and will be removed in the next major version. Please migrate to the flat layout. See guide: https://arkenv.js.org/docs/nextjs/faq#how-do-i-define-client-side-variables`)),l=o.server||{},u=o.client||{},d=o.shared||{},f=o.extends||[],p=o.runtimeEnv||{},m=globalThis.__arkenv_force_server__===!0||!!s;else{let e=o||{},t=s||{};if(f=t.extends||[],p=t.runtimeEnv||{},m=globalThis.__arkenv_force_server__===!0||!!c?.isServer,c?.isShared)d=e;else if(c?.strictLayout===`client`)u=e;else if(c?.strictLayout===`server`)l=e;else{let n=t.exposeToClient||t.expose||t.shared||[];for(let t of Object.keys(e))n.includes(t)||t===`NODE_ENV`?d[t]=e[t]:t.startsWith(`NEXT_PUBLIC_`)?u[t]=e[t]:l[t]=e[t]}}let h={},g=new Set,_=new Set;for(let e of Object.keys(l))g.add(e),!(e in u)&&!(e in d)&&_.add(e);for(let e of Object.keys(u))g.add(e);for(let e of Object.keys(d))g.add(e);let v={};if(f&&Array.isArray(f)){for(let i of f)if(i&&(typeof i==`object`||typeof i==`function`)){let o=i[t];if(o){h={...h,...o};let e=i[n];if(e instanceof Set)for(let t of e)g.add(t);let t=i[r];if(t instanceof Set)for(let e of t)_.add(e)}else{for(let e of Object.keys(h))h[e]!==void 0&&(v[e]=h[e]);for(let e of Object.keys(p))p[e]!==void 0&&(v[e]=p[e]);if(m)for(let e of Object.keys(l))v[e]===void 0&&process.env[e]!==void 0&&(v[e]=process.env[e]);let t=e(i,{env:v});h={...h,...t};let n=a(i);for(let e of n)g.add(e),m&&!e.startsWith(`NEXT_PUBLIC_`)&&!c?.isShared&&_.add(e)}}}for(let e of Object.keys(u))_.delete(e);for(let e of Object.keys(d))_.delete(e);for(let e of Object.keys(u))if(!e.startsWith(`NEXT_PUBLIC_`))throw Error(`Client-side environment variables must be prefixed with 'NEXT_PUBLIC_'. Found invalid key: ${e}`);let y=[...Object.keys(u),...Object.keys(d)];for(let e of y)if(!(e in p))throw Error(`Missing key in runtimeEnv: ${e}. All client and shared environment variables must be explicitly destructured in runtimeEnv.`);for(let e of Object.keys(p))if(!g.has(e))throw Error(`Environment variable '${e}' is passed to runtimeEnv but is not defined in the schema.`);for(let e of Object.keys(h))h[e]!==void 0&&(v[e]=h[e]);let b=typeof globalThis<`u`?globalThis.__arkenv_env__:void 0;for(let e of Object.keys(p))p[e]!==void 0&&(v[e]=p[e]),b&&b[e]!==void 0&&(e.startsWith(`NEXT_PUBLIC_`)||e in u||e in d)&&(v[e]=b[e]);if(m)for(let e of Object.keys(l))v[e]===void 0&&process.env[e]!==void 0&&(v[e]=process.env[e]);let x=e(m?{...l,...u,...d}:{...u,...d},{env:v}),S={...h,...x};return new Proxy(S,{get(e,i,a){if(i===t)return e;if(i===n)return g;if(i===r)return _;if(typeof i==`symbol`)return Reflect.get(e,i,a);if(typeof i==`string`){if(_.has(i)&&!m)throw Error(`ArkEnv Error: Attempted to access server environment variable '${i}' on the client.`);if(!g.has(i)&&!(i in Object.prototype)&&!(i===`__esModule`||i===`$$typeof`||i===`toJSON`||i===`inspect`))throw Error(`Environment variable '${i}' is not defined in the schema.`)}return Reflect.get(e,i,a)}})}export{o as t};
|
|
2
|
+
//# sourceMappingURL=create-env-CRDyrJOZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-env-CRDyrJOZ.js","names":["coreCreateEnv"],"sources":["../src/create-env.ts"],"sourcesContent":["import type { Dict, SchemaShape } from \"@repo/types\";\nimport { createEnv as coreCreateEnv } from \"arkenv\";\n\nexport const EXTENDED_ENV = Symbol.for(\"arkenv.extended_env\");\nexport const ENV_KEYS = Symbol.for(\"arkenv.keys\");\nexport const SERVER_ONLY_KEYS = Symbol.for(\"arkenv.server_only_keys\");\n\nlet hasWarnedLegacy = false;\n\nfunction getSchemaKeys(schema: any): string[] {\n\tif (!schema || (typeof schema !== \"object\" && typeof schema !== \"function\")) {\n\t\treturn [];\n\t}\n\n\t// ArkType Type\n\tif (\n\t\tschema.json &&\n\t\ttypeof schema.json === \"object\" &&\n\t\tschema.json.domain === \"object\"\n\t) {\n\t\tconst keys: string[] = [];\n\t\tif (Array.isArray(schema.json.required)) {\n\t\t\tfor (const r of schema.json.required) {\n\t\t\t\tif (r && typeof r === \"object\" && \"key\" in r) {\n\t\t\t\t\tkeys.push(r.key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (Array.isArray(schema.json.optional)) {\n\t\t\tfor (const o of schema.json.optional) {\n\t\t\t\tif (o && typeof o === \"object\" && \"key\" in o) {\n\t\t\t\t\tkeys.push(o.key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn keys;\n\t}\n\n\t// Zod schema\n\tif (\"shape\" in schema && schema.shape && typeof schema.shape === \"object\") {\n\t\treturn Object.keys(schema.shape);\n\t}\n\n\t// Valibot schema\n\tif (\n\t\t\"entries\" in schema &&\n\t\tschema.entries &&\n\t\ttypeof schema.entries === \"object\"\n\t) {\n\t\treturn Object.keys(schema.entries);\n\t}\n\n\t// Plain object schema\n\treturn Object.keys(schema);\n}\n\n/**\n * Validate and wrap environment variables in a security proxy.\n *\n * @internal\n */\nexport function createEnvInternal(\n\tschemaOrOptions: any,\n\toptionsOrIsServer: any,\n\tcontext?: {\n\t\tisServer: boolean;\n\t\tisShared?: boolean;\n\t\tstrictLayout?: \"client\" | \"server\";\n\t},\n): unknown {\n\tlet server: SchemaShape = {};\n\tlet client: SchemaShape = {};\n\tlet shared: SchemaShape = {};\n\tlet extendsList: unknown[] = [];\n\tlet runtimeEnv: Dict<string> = {};\n\tlet isServer = false;\n\n\tif (typeof optionsOrIsServer === \"boolean\") {\n\t\tif (process.env.NODE_ENV === \"development\" && !hasWarnedLegacy) {\n\t\t\thasWarnedLegacy = true;\n\t\t\tconsole.warn(\n\t\t\t\t\"⚠️ [arkenv] Deprecated: The nested layout structure (specifying 'server', 'client', or 'shared' keys in createEnv) is deprecated and will be removed in the next major version. Please migrate to the flat layout. See guide: https://arkenv.js.org/docs/nextjs/faq#how-do-i-define-client-side-variables\",\n\t\t\t);\n\t\t}\n\t\t// Old nested schema behavior (backward compatible)\n\t\tserver = schemaOrOptions.server || {};\n\t\tclient = schemaOrOptions.client || {};\n\t\tshared = schemaOrOptions.shared || {};\n\t\textendsList = schemaOrOptions.extends || [];\n\t\truntimeEnv = schemaOrOptions.runtimeEnv || {};\n\t\tisServer =\n\t\t\t(globalThis as any).__arkenv_force_server__ === true ||\n\t\t\t!!optionsOrIsServer;\n\t} else {\n\t\t// New flat schema behavior\n\t\tconst flatSchema = schemaOrOptions || {};\n\t\tconst options = optionsOrIsServer || {};\n\t\textendsList = options.extends || [];\n\t\truntimeEnv = options.runtimeEnv || {};\n\t\tisServer =\n\t\t\t(globalThis as any).__arkenv_force_server__ === true ||\n\t\t\t!!context?.isServer;\n\n\t\tif (context?.isShared) {\n\t\t\tshared = flatSchema;\n\t\t} else if (context?.strictLayout === \"client\") {\n\t\t\tclient = flatSchema;\n\t\t} else if (context?.strictLayout === \"server\") {\n\t\t\tserver = flatSchema;\n\t\t} else {\n\t\t\tconst exposedKeys =\n\t\t\t\toptions.exposeToClient || options.expose || options.shared || [];\n\t\t\tfor (const key of Object.keys(flatSchema)) {\n\t\t\t\t// NODE_ENV is implicitly shared as Next.js automatically inlines and replaces references to process.env.NODE_ENV in browser bundles.\n\t\t\t\t// See: https://nextjs.org/docs/app/guides/environment-variables\n\t\t\t\tif (exposedKeys.includes(key) || key === \"NODE_ENV\") {\n\t\t\t\t\tshared[key] = flatSchema[key];\n\t\t\t\t} else if (key.startsWith(\"NEXT_PUBLIC_\")) {\n\t\t\t\t\tclient[key] = flatSchema[key];\n\t\t\t\t} else {\n\t\t\t\t\tserver[key] = flatSchema[key];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tlet extendedEnvValues: Dict<string> = {};\n\tconst allKeys = new Set<string>();\n\tconst serverOnlyKeys = new Set<string>();\n\n\t// Add local keys\n\tfor (const key of Object.keys(server)) {\n\t\tallKeys.add(key);\n\t\tif (!(key in client) && !(key in shared)) {\n\t\t\tserverOnlyKeys.add(key);\n\t\t}\n\t}\n\tfor (const key of Object.keys(client)) {\n\t\tallKeys.add(key);\n\t}\n\tfor (const key of Object.keys(shared)) {\n\t\tallKeys.add(key);\n\t}\n\n\t// Prepare combined environment for core validation\n\tconst combinedEnv: Dict<string> = {};\n\n\t// Process extended environments\n\tif (extendsList && Array.isArray(extendsList)) {\n\t\tfor (const ext of extendsList) {\n\t\t\tif (ext && (typeof ext === \"object\" || typeof ext === \"function\")) {\n\t\t\t\tconst raw = (ext as any)[EXTENDED_ENV];\n\t\t\t\tif (raw) {\n\t\t\t\t\textendedEnvValues = { ...extendedEnvValues, ...raw };\n\n\t\t\t\t\tconst extKeys = (ext as any)[ENV_KEYS];\n\t\t\t\t\tif (extKeys instanceof Set) {\n\t\t\t\t\t\tfor (const key of extKeys) allKeys.add(key);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst extServerOnly = (ext as any)[SERVER_ONLY_KEYS];\n\t\t\t\t\tif (extServerOnly instanceof Set) {\n\t\t\t\t\t\tfor (const key of extServerOnly) serverOnlyKeys.add(key);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Prepare what we have so far for validating the extended schema\n\t\t\t\t\tfor (const key of Object.keys(extendedEnvValues)) {\n\t\t\t\t\t\tif (extendedEnvValues[key] !== undefined) {\n\t\t\t\t\t\t\tcombinedEnv[key] = extendedEnvValues[key];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tfor (const key of Object.keys(runtimeEnv)) {\n\t\t\t\t\t\tif (runtimeEnv[key] !== undefined) {\n\t\t\t\t\t\t\tcombinedEnv[key] = runtimeEnv[key];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (isServer) {\n\t\t\t\t\t\tfor (const key of Object.keys(server)) {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tcombinedEnv[key] === undefined &&\n\t\t\t\t\t\t\t\tprocess.env[key] !== undefined\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcombinedEnv[key] = process.env[key];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst validated = coreCreateEnv(ext as any, { env: combinedEnv });\n\t\t\t\t\textendedEnvValues = { ...extendedEnvValues, ...validated };\n\n\t\t\t\t\tconst extKeys = getSchemaKeys(ext);\n\t\t\t\t\tfor (const key of extKeys) {\n\t\t\t\t\t\tallKeys.add(key);\n\t\t\t\t\t\t// Only classify as server-only if we are on the server, it's not a public key,\n\t\t\t\t\t\t// and we aren't explicitly inside the shared entry point.\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tisServer &&\n\t\t\t\t\t\t\t!key.startsWith(\"NEXT_PUBLIC_\") &&\n\t\t\t\t\t\t\t!context?.isShared\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tserverOnlyKeys.add(key);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Remove keys from serverOnlyKeys if they are defined as client or shared locally\n\tfor (const key of Object.keys(client)) {\n\t\tserverOnlyKeys.delete(key);\n\t}\n\tfor (const key of Object.keys(shared)) {\n\t\tserverOnlyKeys.delete(key);\n\t}\n\n\t// Validate options\n\t// For client keys, check prefix\n\tfor (const key of Object.keys(client)) {\n\t\tif (!key.startsWith(\"NEXT_PUBLIC_\")) {\n\t\t\tthrow new Error(\n\t\t\t\t`Client-side environment variables must be prefixed with 'NEXT_PUBLIC_'. Found invalid key: ${key}`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// Check runtimeEnv has all local client and shared keys\n\tconst requiredKeys = [...Object.keys(client), ...Object.keys(shared)];\n\tfor (const key of requiredKeys) {\n\t\tif (!(key in runtimeEnv)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Missing key in runtimeEnv: ${key}. All client and shared environment variables must be explicitly destructured in runtimeEnv.`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// Check runtimeEnv does not have any keys not defined in the schema (allKeys)\n\tfor (const key of Object.keys(runtimeEnv)) {\n\t\tif (!allKeys.has(key)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Environment variable '${key}' is passed to runtimeEnv but is not defined in the schema.`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// Build final combinedEnv\n\tfor (const key of Object.keys(extendedEnvValues)) {\n\t\tif (extendedEnvValues[key] !== undefined) {\n\t\t\tcombinedEnv[key] = extendedEnvValues[key];\n\t\t}\n\t}\n\n\tconst globalEnv =\n\t\ttypeof globalThis !== \"undefined\"\n\t\t\t? (globalThis as any).__arkenv_env__\n\t\t\t: undefined;\n\n\tfor (const key of Object.keys(runtimeEnv)) {\n\t\tif (runtimeEnv[key] !== undefined) {\n\t\t\tcombinedEnv[key] = runtimeEnv[key];\n\t\t}\n\t\tif (globalEnv && globalEnv[key] !== undefined) {\n\t\t\tif (key.startsWith(\"NEXT_PUBLIC_\") || key in client || key in shared) {\n\t\t\t\tcombinedEnv[key] = globalEnv[key];\n\t\t\t}\n\t\t}\n\t}\n\n\tif (isServer) {\n\t\t// Fallback server keys to process.env if omitted or undefined\n\t\tfor (const key of Object.keys(server)) {\n\t\t\tif (combinedEnv[key] === undefined && process.env[key] !== undefined) {\n\t\t\t\tcombinedEnv[key] = process.env[key];\n\t\t\t}\n\t\t}\n\t}\n\n\t// Select schema based on environment\n\tconst schema = isServer\n\t\t? { ...server, ...client, ...shared }\n\t\t: { ...client, ...shared };\n\n\t// Run core validation\n\tconst validated = coreCreateEnv(schema as any, { env: combinedEnv });\n\n\tconst mergedValidated = { ...extendedEnvValues, ...validated };\n\n\t// Return a Proxy wrapper\n\treturn new Proxy(mergedValidated, {\n\t\tget(target, prop, receiver) {\n\t\t\tif (prop === EXTENDED_ENV) {\n\t\t\t\treturn target;\n\t\t\t}\n\t\t\tif (prop === ENV_KEYS) {\n\t\t\t\treturn allKeys;\n\t\t\t}\n\t\t\tif (prop === SERVER_ONLY_KEYS) {\n\t\t\t\treturn serverOnlyKeys;\n\t\t\t}\n\n\t\t\t// Always allow symbol properties (Symbol.iterator, Symbol.toStringTag, etc.)\n\t\t\tif (typeof prop === \"symbol\") {\n\t\t\t\treturn Reflect.get(target, prop, receiver);\n\t\t\t}\n\n\t\t\tif (typeof prop === \"string\") {\n\t\t\t\tif (serverOnlyKeys.has(prop) && !isServer) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`ArkEnv Error: Attempted to access server environment variable '${prop}' on the client.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Allow schema keys and standard Object prototype properties\n\t\t\t\tif (!allKeys.has(prop) && !(prop in Object.prototype)) {\n\t\t\t\t\t// Fallback for bundler/framework-specific properties that bypass the prototype\n\t\t\t\t\tconst isCommonKey =\n\t\t\t\t\t\tprop === \"__esModule\" ||\n\t\t\t\t\t\tprop === \"$$typeof\" ||\n\t\t\t\t\t\tprop === \"toJSON\" ||\n\t\t\t\t\t\tprop === \"inspect\";\n\n\t\t\t\t\tif (!isCommonKey) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Environment variable '${prop}' is not defined in the schema.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn Reflect.get(target, prop, receiver);\n\t\t},\n\t});\n}\n"],"mappings":"mCAGA,MAAa,EAAe,OAAO,IAAI,sBAAsB,CAChD,EAAW,OAAO,IAAI,cAAc,CACpC,EAAmB,OAAO,IAAI,0BAA0B,CAErE,IAAI,EAAkB,GAEtB,SAAS,EAAc,EAAuB,CAC7C,GAAI,CAAC,GAAW,OAAO,GAAW,UAAY,OAAO,GAAW,WAC/D,MAAO,EAAE,CAIV,GACC,EAAO,MACP,OAAO,EAAO,MAAS,UACvB,EAAO,KAAK,SAAW,SACtB,CACD,IAAM,EAAiB,EAAE,CACzB,GAAI,MAAM,QAAQ,EAAO,KAAK,SAAS,KACjC,IAAM,KAAK,EAAO,KAAK,SACvB,GAAK,OAAO,GAAM,UAAY,QAAS,GAC1C,EAAK,KAAK,EAAE,IAAI,CAInB,GAAI,MAAM,QAAQ,EAAO,KAAK,SAAS,KACjC,IAAM,KAAK,EAAO,KAAK,SACvB,GAAK,OAAO,GAAM,UAAY,QAAS,GAC1C,EAAK,KAAK,EAAE,IAAI,CAInB,OAAO,EAkBR,MAdI,UAAW,GAAU,EAAO,OAAS,OAAO,EAAO,OAAU,SACzD,OAAO,KAAK,EAAO,MAAM,CAK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IAAS,EACZ,OAAO,EAER,GAAI,IAAS,EACZ,OAAO,EAER,GAAI,IAAS,EACZ,OAAO,EAIR,GAAI,OAAO,GAAS,SACnB,OAAO,QAAQ,IAAI,EAAQ,EAAM,EAAS,CAG3C,GAAI,OAAO,GAAS,SAAU,CAC7B,GAAI,EAAe,IAAI,EAAK,EAAI,CAAC,EAChC,MAAU,MACT,kEAAkE,EAAK,kBACvE,CAIF,GAAI,CAAC,EAAQ,IAAI,EAAK,EAAI,EAAE,KAAQ,OAAO,YAQtC,EALH,IAAS,cACT,IAAS,YACT,IAAS,UACT,IAAS,WAGT,MAAU,MACT,yBAAyB,EAAK,iCAC9B,CAIJ,OAAO,QAAQ,IAAI,EAAQ,EAAM,EAAS,EAE3C,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
require(`./config.cjs`);let e=require(`arkenv`);const t=Symbol.for(`arkenv.extended_env`),n=Symbol.for(`arkenv.keys`),r=Symbol.for(`arkenv.server_only_keys`);let i=!1;function a(e){if(!e||typeof e!=`object`&&typeof e!=`function`)return[];if(e.json&&typeof e.json==`object`&&e.json.domain===`object`){let t=[];if(Array.isArray(e.json.required))for(let n of e.json.required)n&&typeof n==`object`&&`key`in n&&t.push(n.key);if(Array.isArray(e.json.optional))for(let n of e.json.optional)n&&typeof n==`object`&&`key`in n&&t.push(n.key);return t}return`shape`in e&&e.shape&&typeof e.shape==`object`?Object.keys(e.shape):`entries`in e&&e.entries&&typeof e.entries==`object`?Object.keys(e.entries):Object.keys(e)}function o(o,s,c){let l={},u={},d={},f=[],p={},m=!1;if(typeof s==`boolean`)process.env.NODE_ENV===`development`&&!i&&(i=!0,console.warn(`⚠️ [arkenv] Deprecated: The nested layout structure (specifying 'server', 'client', or 'shared' keys in createEnv) is deprecated and will be removed in the next major version. Please migrate to the flat layout. See guide: https://arkenv.js.org/docs/nextjs/faq#how-do-i-define-client-side-variables`)),l=o.server||{},u=o.client||{},d=o.shared||{},f=o.extends||[],p=o.runtimeEnv||{},m=globalThis.__arkenv_force_server__===!0||!!s;else{let e=o||{},t=s||{};if(f=t.extends||[],p=t.runtimeEnv||{},m=globalThis.__arkenv_force_server__===!0||!!c?.isServer,c?.isShared)d=e;else if(c?.strictLayout===`client`)u=e;else if(c?.strictLayout===`server`)l=e;else{let n=t.exposeToClient||t.expose||t.shared||[];for(let t of Object.keys(e))n.includes(t)||t===`NODE_ENV`?d[t]=e[t]:t.startsWith(`NEXT_PUBLIC_`)?u[t]=e[t]:l[t]=e[t]}}let h={},g=new Set,_=new Set;for(let e of Object.keys(l))g.add(e),!(e in u)&&!(e in d)&&_.add(e);for(let e of Object.keys(u))g.add(e);for(let e of Object.keys(d))g.add(e);let v={};if(f&&Array.isArray(f)){for(let i of f)if(i&&(typeof i==`object`||typeof i==`function`)){let o=i[t];if(o){h={...h,...o};let e=i[n];if(e instanceof Set)for(let t of e)g.add(t);let t=i[r];if(t instanceof Set)for(let e of t)_.add(e)}else{for(let e of Object.keys(h))h[e]!==void 0&&(v[e]=h[e]);for(let e of Object.keys(p))p[e]!==void 0&&(v[e]=p[e]);if(m)for(let e of Object.keys(l))v[e]===void 0&&process.env[e]!==void 0&&(v[e]=process.env[e]);let t=(0,e.createEnv)(i,{env:v});h={...h,...t};let n=a(i);for(let e of n)g.add(e),m&&!e.startsWith(`NEXT_PUBLIC_`)&&!c?.isShared&&_.add(e)}}}for(let e of Object.keys(u))_.delete(e);for(let e of Object.keys(d))_.delete(e);for(let e of Object.keys(u))if(!e.startsWith(`NEXT_PUBLIC_`))throw Error(`Client-side environment variables must be prefixed with 'NEXT_PUBLIC_'. Found invalid key: ${e}`);let y=[...Object.keys(u),...Object.keys(d)];for(let e of y)if(!(e in p))throw Error(`Missing key in runtimeEnv: ${e}. All client and shared environment variables must be explicitly destructured in runtimeEnv.`);for(let e of Object.keys(p))if(!g.has(e))throw Error(`Environment variable '${e}' is passed to runtimeEnv but is not defined in the schema.`);for(let e of Object.keys(h))h[e]!==void 0&&(v[e]=h[e]);let b=typeof globalThis<`u`?globalThis.__arkenv_env__:void 0;for(let e of Object.keys(p))p[e]!==void 0&&(v[e]=p[e]),b&&b[e]!==void 0&&(e.startsWith(`NEXT_PUBLIC_`)||e in u||e in d)&&(v[e]=b[e]);if(m)for(let e of Object.keys(l))v[e]===void 0&&process.env[e]!==void 0&&(v[e]=process.env[e]);let x=(0,e.createEnv)(m?{...l,...u,...d}:{...u,...d},{env:v}),S={...h,...x};return new Proxy(S,{get(e,i,a){if(i===t)return e;if(i===n)return g;if(i===r)return _;if(typeof i==`symbol`)return Reflect.get(e,i,a);if(typeof i==`string`){if(_.has(i)&&!m)throw Error(`ArkEnv Error: Attempted to access server environment variable '${i}' on the client.`);if(!g.has(i)&&!(i in Object.prototype)&&!(i===`__esModule`||i===`$$typeof`||i===`toJSON`||i===`inspect`))throw Error(`Environment variable '${i}' is not defined in the schema.`)}return Reflect.get(e,i,a)}})}Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return o}});
|
|
2
|
+
//# sourceMappingURL=create-env-o205_sj3.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-env-B6DmIK3X.js","names":["coreCreateEnv"],"sources":["../src/create-env.ts"],"sourcesContent":["import type { Dict, SchemaShape } from \"@repo/types\";\nimport { createEnv as coreCreateEnv } from \"arkenv\";\n\nexport const EXTENDED_ENV = Symbol.for(\"arkenv.extended_env\");\nexport const ENV_KEYS = Symbol.for(\"arkenv.keys\");\nexport const SERVER_ONLY_KEYS = Symbol.for(\"arkenv.server_only_keys\");\n\nlet hasWarnedLegacy = false;\n\nfunction getSchemaKeys(schema: any): string[] {\n\tif (!schema || (typeof schema !== \"object\" && typeof schema !== \"function\")) {\n\t\treturn [];\n\t}\n\n\t// ArkType Type\n\tif (\n\t\tschema.json &&\n\t\ttypeof schema.json === \"object\" &&\n\t\tschema.json.domain === \"object\"\n\t) {\n\t\tconst keys: string[] = [];\n\t\tif (Array.isArray(schema.json.required)) {\n\t\t\tfor (const r of schema.json.required) {\n\t\t\t\tif (r && typeof r === \"object\" && \"key\" in r) {\n\t\t\t\t\tkeys.push(r.key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (Array.isArray(schema.json.optional)) {\n\t\t\tfor (const o of schema.json.optional) {\n\t\t\t\tif (o && typeof o === \"object\" && \"key\" in o) {\n\t\t\t\t\tkeys.push(o.key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn keys;\n\t}\n\n\t// Zod schema\n\tif (\"shape\" in schema && schema.shape && typeof schema.shape === \"object\") {\n\t\treturn Object.keys(schema.shape);\n\t}\n\n\t// Valibot schema\n\tif (\n\t\t\"entries\" in schema &&\n\t\tschema.entries &&\n\t\ttypeof schema.entries === \"object\"\n\t) {\n\t\treturn Object.keys(schema.entries);\n\t}\n\n\t// Plain object schema\n\treturn Object.keys(schema);\n}\n\n/**\n * Validate and wrap environment variables in a security proxy.\n *\n * @internal\n */\nexport function createEnvInternal(\n\tschemaOrOptions: any,\n\toptionsOrIsServer: any,\n\tcontext?: {\n\t\tisServer: boolean;\n\t\tisShared?: boolean;\n\t\tstrictLayout?: \"client\" | \"server\";\n\t},\n): unknown {\n\tlet server: SchemaShape = {};\n\tlet client: SchemaShape = {};\n\tlet shared: SchemaShape = {};\n\tlet extendsList: unknown[] = [];\n\tlet runtimeEnv: Dict<string> = {};\n\tlet isServer = false;\n\n\tif (typeof optionsOrIsServer === \"boolean\") {\n\t\tif (process.env.NODE_ENV === \"development\" && !hasWarnedLegacy) {\n\t\t\thasWarnedLegacy = true;\n\t\t\tconsole.warn(\n\t\t\t\t\"⚠️ [arkenv] Deprecated: The nested layout structure (specifying 'server', 'client', or 'shared' keys in createEnv) is deprecated and will be removed in the next major version. Please migrate to the flat layout. See guide: https://arkenv.js.org/docs/nextjs/faq#how-do-i-define-client-side-variables\",\n\t\t\t);\n\t\t}\n\t\t// Old nested schema behavior (backward compatible)\n\t\tserver = schemaOrOptions.server || {};\n\t\tclient = schemaOrOptions.client || {};\n\t\tshared = schemaOrOptions.shared || {};\n\t\textendsList = schemaOrOptions.extends || [];\n\t\truntimeEnv = schemaOrOptions.runtimeEnv || {};\n\t\tisServer = optionsOrIsServer;\n\t} else {\n\t\t// New flat schema behavior\n\t\tconst flatSchema = schemaOrOptions || {};\n\t\tconst options = optionsOrIsServer || {};\n\t\textendsList = options.extends || [];\n\t\truntimeEnv = options.runtimeEnv || {};\n\t\tisServer = !!context?.isServer;\n\n\t\tif (context?.isShared) {\n\t\t\tshared = flatSchema;\n\t\t} else if (context?.strictLayout === \"client\") {\n\t\t\tclient = flatSchema;\n\t\t} else if (context?.strictLayout === \"server\") {\n\t\t\tserver = flatSchema;\n\t\t} else {\n\t\t\tconst exposedKeys =\n\t\t\t\toptions.exposeToClient || options.expose || options.shared || [];\n\t\t\tfor (const key of Object.keys(flatSchema)) {\n\t\t\t\t// NODE_ENV is implicitly shared as Next.js automatically inlines and replaces references to process.env.NODE_ENV in browser bundles.\n\t\t\t\t// See: https://nextjs.org/docs/app/guides/environment-variables\n\t\t\t\tif (exposedKeys.includes(key) || key === \"NODE_ENV\") {\n\t\t\t\t\tshared[key] = flatSchema[key];\n\t\t\t\t} else if (key.startsWith(\"NEXT_PUBLIC_\")) {\n\t\t\t\t\tclient[key] = flatSchema[key];\n\t\t\t\t} else {\n\t\t\t\t\tserver[key] = flatSchema[key];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tlet extendedEnvValues: Dict<string> = {};\n\tconst allKeys = new Set<string>();\n\tconst serverOnlyKeys = new Set<string>();\n\n\t// Add local keys\n\tfor (const key of Object.keys(server)) {\n\t\tallKeys.add(key);\n\t\tif (!(key in client) && !(key in shared)) {\n\t\t\tserverOnlyKeys.add(key);\n\t\t}\n\t}\n\tfor (const key of Object.keys(client)) {\n\t\tallKeys.add(key);\n\t}\n\tfor (const key of Object.keys(shared)) {\n\t\tallKeys.add(key);\n\t}\n\n\t// Prepare combined environment for core validation\n\tconst combinedEnv: Dict<string> = {};\n\n\t// Process extended environments\n\tif (extendsList && Array.isArray(extendsList)) {\n\t\tfor (const ext of extendsList) {\n\t\t\tif (ext && (typeof ext === \"object\" || typeof ext === \"function\")) {\n\t\t\t\tconst raw = (ext as any)[EXTENDED_ENV];\n\t\t\t\tif (raw) {\n\t\t\t\t\textendedEnvValues = { ...extendedEnvValues, ...raw };\n\n\t\t\t\t\tconst extKeys = (ext as any)[ENV_KEYS];\n\t\t\t\t\tif (extKeys instanceof Set) {\n\t\t\t\t\t\tfor (const key of extKeys) allKeys.add(key);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst extServerOnly = (ext as any)[SERVER_ONLY_KEYS];\n\t\t\t\t\tif (extServerOnly instanceof Set) {\n\t\t\t\t\t\tfor (const key of extServerOnly) serverOnlyKeys.add(key);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Prepare what we have so far for validating the extended schema\n\t\t\t\t\tfor (const key of Object.keys(extendedEnvValues)) {\n\t\t\t\t\t\tif (extendedEnvValues[key] !== undefined) {\n\t\t\t\t\t\t\tcombinedEnv[key] = extendedEnvValues[key];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tfor (const key of Object.keys(runtimeEnv)) {\n\t\t\t\t\t\tif (runtimeEnv[key] !== undefined) {\n\t\t\t\t\t\t\tcombinedEnv[key] = runtimeEnv[key];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (isServer) {\n\t\t\t\t\t\tfor (const key of Object.keys(server)) {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tcombinedEnv[key] === undefined &&\n\t\t\t\t\t\t\t\tprocess.env[key] !== undefined\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcombinedEnv[key] = process.env[key];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst validated = coreCreateEnv(ext as any, { env: combinedEnv });\n\t\t\t\t\textendedEnvValues = { ...extendedEnvValues, ...validated };\n\n\t\t\t\t\tconst extKeys = getSchemaKeys(ext);\n\t\t\t\t\tfor (const key of extKeys) {\n\t\t\t\t\t\tallKeys.add(key);\n\t\t\t\t\t\t// Only classify as server-only if we are on the server, it's not a public key,\n\t\t\t\t\t\t// and we aren't explicitly inside the shared entry point.\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tisServer &&\n\t\t\t\t\t\t\t!key.startsWith(\"NEXT_PUBLIC_\") &&\n\t\t\t\t\t\t\t!context?.isShared\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tserverOnlyKeys.add(key);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Remove keys from serverOnlyKeys if they are defined as client or shared locally\n\tfor (const key of Object.keys(client)) {\n\t\tserverOnlyKeys.delete(key);\n\t}\n\tfor (const key of Object.keys(shared)) {\n\t\tserverOnlyKeys.delete(key);\n\t}\n\n\t// Validate options\n\t// For client keys, check prefix\n\tfor (const key of Object.keys(client)) {\n\t\tif (!key.startsWith(\"NEXT_PUBLIC_\")) {\n\t\t\tthrow new Error(\n\t\t\t\t`Client-side environment variables must be prefixed with 'NEXT_PUBLIC_'. Found invalid key: ${key}`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// Check runtimeEnv has all local client and shared keys\n\tconst requiredKeys = [...Object.keys(client), ...Object.keys(shared)];\n\tfor (const key of requiredKeys) {\n\t\tif (!(key in runtimeEnv)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Missing key in runtimeEnv: ${key}. All client and shared environment variables must be explicitly destructured in runtimeEnv.`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// Check runtimeEnv does not have any keys not defined in the schema (allKeys)\n\tfor (const key of Object.keys(runtimeEnv)) {\n\t\tif (!allKeys.has(key)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Environment variable '${key}' is passed to runtimeEnv but is not defined in the schema.`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// Build final combinedEnv\n\tfor (const key of Object.keys(extendedEnvValues)) {\n\t\tif (extendedEnvValues[key] !== undefined) {\n\t\t\tcombinedEnv[key] = extendedEnvValues[key];\n\t\t}\n\t}\n\n\tconst globalEnv =\n\t\ttypeof globalThis !== \"undefined\"\n\t\t\t? (globalThis as any).__arkenv_env__\n\t\t\t: undefined;\n\n\tfor (const key of Object.keys(runtimeEnv)) {\n\t\tif (runtimeEnv[key] !== undefined) {\n\t\t\tcombinedEnv[key] = runtimeEnv[key];\n\t\t}\n\t\tif (globalEnv && globalEnv[key] !== undefined) {\n\t\t\tif (key.startsWith(\"NEXT_PUBLIC_\") || key in client || key in shared) {\n\t\t\t\tcombinedEnv[key] = globalEnv[key];\n\t\t\t}\n\t\t}\n\t}\n\n\tif (isServer) {\n\t\t// Fallback server keys to process.env if omitted or undefined\n\t\tfor (const key of Object.keys(server)) {\n\t\t\tif (combinedEnv[key] === undefined && process.env[key] !== undefined) {\n\t\t\t\tcombinedEnv[key] = process.env[key];\n\t\t\t}\n\t\t}\n\t}\n\n\t// Select schema based on environment\n\tconst schema = isServer\n\t\t? { ...server, ...client, ...shared }\n\t\t: { ...client, ...shared };\n\n\t// Run core validation\n\tconst validated = coreCreateEnv(schema as any, { env: combinedEnv });\n\n\tconst mergedValidated = { ...extendedEnvValues, ...validated };\n\n\t// Return a Proxy wrapper\n\treturn new Proxy(mergedValidated, {\n\t\tget(target, prop, receiver) {\n\t\t\tif (prop === EXTENDED_ENV) {\n\t\t\t\treturn target;\n\t\t\t}\n\t\t\tif (prop === ENV_KEYS) {\n\t\t\t\treturn allKeys;\n\t\t\t}\n\t\t\tif (prop === SERVER_ONLY_KEYS) {\n\t\t\t\treturn serverOnlyKeys;\n\t\t\t}\n\n\t\t\t// Always allow symbol properties (Symbol.iterator, Symbol.toStringTag, etc.)\n\t\t\tif (typeof prop === \"symbol\") {\n\t\t\t\treturn Reflect.get(target, prop, receiver);\n\t\t\t}\n\n\t\t\tif (typeof prop === \"string\") {\n\t\t\t\tif (serverOnlyKeys.has(prop) && !isServer) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`ArkEnv Error: Attempted to access server environment variable '${prop}' on the client.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Allow schema keys and standard Object prototype properties\n\t\t\t\tif (!allKeys.has(prop) && !(prop in Object.prototype)) {\n\t\t\t\t\t// Fallback for bundler/framework-specific properties that bypass the prototype\n\t\t\t\t\tconst isCommonKey =\n\t\t\t\t\t\tprop === \"__esModule\" ||\n\t\t\t\t\t\tprop === \"$$typeof\" ||\n\t\t\t\t\t\tprop === \"toJSON\" ||\n\t\t\t\t\t\tprop === \"inspect\";\n\n\t\t\t\t\tif (!isCommonKey) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Environment variable '${prop}' is not defined in the schema.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn Reflect.get(target, prop, receiver);\n\t\t},\n\t});\n}\n"],"mappings":"mCAGA,MAAa,EAAe,OAAO,IAAI,sBAAsB,CAChD,EAAW,OAAO,IAAI,cAAc,CACpC,EAAmB,OAAO,IAAI,0BAA0B,CAErE,IAAI,EAAkB,GAEtB,SAAS,EAAc,EAAuB,CAC7C,GAAI,CAAC,GAAW,OAAO,GAAW,UAAY,OAAO,GAAW,WAC/D,MAAO,EAAE,CAIV,GACC,EAAO,MACP,OAAO,EAAO,MAAS,UACvB,EAAO,KAAK,SAAW,SACtB,CACD,IAAM,EAAiB,EAAE,CACzB,GAAI,MAAM,QAAQ,EAAO,KAAK,SAAS,KACjC,IAAM,KAAK,EAAO,KAAK,SACvB,GAAK,OAAO,GAAM,UAAY,QAAS,GAC1C,EAAK,KAAK,EAAE,IAAI,CAInB,GAAI,MAAM,QAAQ,EAAO,KAAK,SAAS,KACjC,IAAM,KAAK,EAAO,KAAK,SACvB,GAAK,OAAO,GAAM,UAAY,QAAS,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AAW,CAG9D,OAAO,IAAI,MAAM,EAAiB,CACjC,IAAI,EAAQ,EAAM,EAAU,CAC3B,GAAI,IAAS,EACZ,OAAO,EAER,GAAI,IAAS,EACZ,OAAO,EAER,GAAI,IAAS,EACZ,OAAO,EAIR,GAAI,OAAO,GAAS,SACnB,OAAO,QAAQ,IAAI,EAAQ,EAAM,EAAS,CAG3C,GAAI,OAAO,GAAS,SAAU,CAC7B,GAAI,EAAe,IAAI,EAAK,EAAI,CAAC,EAChC,MAAU,MACT,kEAAkE,EAAK,kBACvE,CAIF,GAAI,CAAC,EAAQ,IAAI,EAAK,EAAI,EAAE,KAAQ,OAAO,YAQtC,EALH,IAAS,cACT,IAAS,YACT,IAAS,UACT,IAAS,WAGT,MAAU,MACT,yBAAyB,EAAK,iCAC9B,CAIJ,OAAO,QAAQ,IAAI,EAAQ,EAAM,EAAS,EAE3C,CAAC"}
|
|
1
|
+
{"version":3,"file":"create-env-o205_sj3.cjs","names":[],"sources":["../src/create-env.ts"],"sourcesContent":["import type { Dict, SchemaShape } from \"@repo/types\";\nimport { createEnv as coreCreateEnv } from \"arkenv\";\n\nexport const EXTENDED_ENV = Symbol.for(\"arkenv.extended_env\");\nexport const ENV_KEYS = Symbol.for(\"arkenv.keys\");\nexport const SERVER_ONLY_KEYS = Symbol.for(\"arkenv.server_only_keys\");\n\nlet hasWarnedLegacy = false;\n\nfunction getSchemaKeys(schema: any): string[] {\n\tif (!schema || (typeof schema !== \"object\" && typeof schema !== \"function\")) {\n\t\treturn [];\n\t}\n\n\t// ArkType Type\n\tif (\n\t\tschema.json &&\n\t\ttypeof schema.json === \"object\" &&\n\t\tschema.json.domain === \"object\"\n\t) {\n\t\tconst keys: string[] = [];\n\t\tif (Array.isArray(schema.json.required)) {\n\t\t\tfor (const r of schema.json.required) {\n\t\t\t\tif (r && typeof r === \"object\" && \"key\" in r) {\n\t\t\t\t\tkeys.push(r.key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (Array.isArray(schema.json.optional)) {\n\t\t\tfor (const o of schema.json.optional) {\n\t\t\t\tif (o && typeof o === \"object\" && \"key\" in o) {\n\t\t\t\t\tkeys.push(o.key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn keys;\n\t}\n\n\t// Zod schema\n\tif (\"shape\" in schema && schema.shape && typeof schema.shape === \"object\") {\n\t\treturn Object.keys(schema.shape);\n\t}\n\n\t// Valibot schema\n\tif (\n\t\t\"entries\" in schema &&\n\t\tschema.entries &&\n\t\ttypeof schema.entries === \"object\"\n\t) {\n\t\treturn Object.keys(schema.entries);\n\t}\n\n\t// Plain object schema\n\treturn Object.keys(schema);\n}\n\n/**\n * Validate and wrap environment variables in a security proxy.\n *\n * @internal\n */\nexport function createEnvInternal(\n\tschemaOrOptions: any,\n\toptionsOrIsServer: any,\n\tcontext?: {\n\t\tisServer: boolean;\n\t\tisShared?: boolean;\n\t\tstrictLayout?: \"client\" | \"server\";\n\t},\n): unknown {\n\tlet server: SchemaShape = {};\n\tlet client: SchemaShape = {};\n\tlet shared: SchemaShape = {};\n\tlet extendsList: unknown[] = [];\n\tlet runtimeEnv: Dict<string> = {};\n\tlet isServer = false;\n\n\tif (typeof optionsOrIsServer === \"boolean\") {\n\t\tif (process.env.NODE_ENV === \"development\" && !hasWarnedLegacy) {\n\t\t\thasWarnedLegacy = true;\n\t\t\tconsole.warn(\n\t\t\t\t\"⚠️ [arkenv] Deprecated: The nested layout structure (specifying 'server', 'client', or 'shared' keys in createEnv) is deprecated and will be removed in the next major version. Please migrate to the flat layout. See guide: https://arkenv.js.org/docs/nextjs/faq#how-do-i-define-client-side-variables\",\n\t\t\t);\n\t\t}\n\t\t// Old nested schema behavior (backward compatible)\n\t\tserver = schemaOrOptions.server || {};\n\t\tclient = schemaOrOptions.client || {};\n\t\tshared = schemaOrOptions.shared || {};\n\t\textendsList = schemaOrOptions.extends || [];\n\t\truntimeEnv = schemaOrOptions.runtimeEnv || {};\n\t\tisServer =\n\t\t\t(globalThis as any).__arkenv_force_server__ === true ||\n\t\t\t!!optionsOrIsServer;\n\t} else {\n\t\t// New flat schema behavior\n\t\tconst flatSchema = schemaOrOptions || {};\n\t\tconst options = optionsOrIsServer || {};\n\t\textendsList = options.extends || [];\n\t\truntimeEnv = options.runtimeEnv || {};\n\t\tisServer =\n\t\t\t(globalThis as any).__arkenv_force_server__ === true ||\n\t\t\t!!context?.isServer;\n\n\t\tif (context?.isShared) {\n\t\t\tshared = flatSchema;\n\t\t} else if (context?.strictLayout === \"client\") {\n\t\t\tclient = flatSchema;\n\t\t} else if (context?.strictLayout === \"server\") {\n\t\t\tserver = flatSchema;\n\t\t} else {\n\t\t\tconst exposedKeys =\n\t\t\t\toptions.exposeToClient || options.expose || options.shared || [];\n\t\t\tfor (const key of Object.keys(flatSchema)) {\n\t\t\t\t// NODE_ENV is implicitly shared as Next.js automatically inlines and replaces references to process.env.NODE_ENV in browser bundles.\n\t\t\t\t// See: https://nextjs.org/docs/app/guides/environment-variables\n\t\t\t\tif (exposedKeys.includes(key) || key === \"NODE_ENV\") {\n\t\t\t\t\tshared[key] = flatSchema[key];\n\t\t\t\t} else if (key.startsWith(\"NEXT_PUBLIC_\")) {\n\t\t\t\t\tclient[key] = flatSchema[key];\n\t\t\t\t} else {\n\t\t\t\t\tserver[key] = flatSchema[key];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tlet extendedEnvValues: Dict<string> = {};\n\tconst allKeys = new Set<string>();\n\tconst serverOnlyKeys = new Set<string>();\n\n\t// Add local keys\n\tfor (const key of Object.keys(server)) {\n\t\tallKeys.add(key);\n\t\tif (!(key in client) && !(key in shared)) {\n\t\t\tserverOnlyKeys.add(key);\n\t\t}\n\t}\n\tfor (const key of Object.keys(client)) {\n\t\tallKeys.add(key);\n\t}\n\tfor (const key of Object.keys(shared)) {\n\t\tallKeys.add(key);\n\t}\n\n\t// Prepare combined environment for core validation\n\tconst combinedEnv: Dict<string> = {};\n\n\t// Process extended environments\n\tif (extendsList && Array.isArray(extendsList)) {\n\t\tfor (const ext of extendsList) {\n\t\t\tif (ext && (typeof ext === \"object\" || typeof ext === \"function\")) {\n\t\t\t\tconst raw = (ext as any)[EXTENDED_ENV];\n\t\t\t\tif (raw) {\n\t\t\t\t\textendedEnvValues = { ...extendedEnvValues, ...raw };\n\n\t\t\t\t\tconst extKeys = (ext as any)[ENV_KEYS];\n\t\t\t\t\tif (extKeys instanceof Set) {\n\t\t\t\t\t\tfor (const key of extKeys) allKeys.add(key);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst extServerOnly = (ext as any)[SERVER_ONLY_KEYS];\n\t\t\t\t\tif (extServerOnly instanceof Set) {\n\t\t\t\t\t\tfor (const key of extServerOnly) serverOnlyKeys.add(key);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Prepare what we have so far for validating the extended schema\n\t\t\t\t\tfor (const key of Object.keys(extendedEnvValues)) {\n\t\t\t\t\t\tif (extendedEnvValues[key] !== undefined) {\n\t\t\t\t\t\t\tcombinedEnv[key] = extendedEnvValues[key];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tfor (const key of Object.keys(runtimeEnv)) {\n\t\t\t\t\t\tif (runtimeEnv[key] !== undefined) {\n\t\t\t\t\t\t\tcombinedEnv[key] = runtimeEnv[key];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (isServer) {\n\t\t\t\t\t\tfor (const key of Object.keys(server)) {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tcombinedEnv[key] === undefined &&\n\t\t\t\t\t\t\t\tprocess.env[key] !== undefined\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcombinedEnv[key] = process.env[key];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst validated = coreCreateEnv(ext as any, { env: combinedEnv });\n\t\t\t\t\textendedEnvValues = { ...extendedEnvValues, ...validated };\n\n\t\t\t\t\tconst extKeys = getSchemaKeys(ext);\n\t\t\t\t\tfor (const key of extKeys) {\n\t\t\t\t\t\tallKeys.add(key);\n\t\t\t\t\t\t// Only classify as server-only if we are on the server, it's not a public key,\n\t\t\t\t\t\t// and we aren't explicitly inside the shared entry point.\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tisServer &&\n\t\t\t\t\t\t\t!key.startsWith(\"NEXT_PUBLIC_\") &&\n\t\t\t\t\t\t\t!context?.isShared\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tserverOnlyKeys.add(key);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Remove keys from serverOnlyKeys if they are defined as client or shared locally\n\tfor (const key of Object.keys(client)) {\n\t\tserverOnlyKeys.delete(key);\n\t}\n\tfor (const key of Object.keys(shared)) {\n\t\tserverOnlyKeys.delete(key);\n\t}\n\n\t// Validate options\n\t// For client keys, check prefix\n\tfor (const key of Object.keys(client)) {\n\t\tif (!key.startsWith(\"NEXT_PUBLIC_\")) {\n\t\t\tthrow new Error(\n\t\t\t\t`Client-side environment variables must be prefixed with 'NEXT_PUBLIC_'. Found invalid key: ${key}`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// Check runtimeEnv has all local client and shared keys\n\tconst requiredKeys = [...Object.keys(client), ...Object.keys(shared)];\n\tfor (const key of requiredKeys) {\n\t\tif (!(key in runtimeEnv)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Missing key in runtimeEnv: ${key}. All client and shared environment variables must be explicitly destructured in runtimeEnv.`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// Check runtimeEnv does not have any keys not defined in the schema (allKeys)\n\tfor (const key of Object.keys(runtimeEnv)) {\n\t\tif (!allKeys.has(key)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Environment variable '${key}' is passed to runtimeEnv but is not defined in the schema.`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// Build final combinedEnv\n\tfor (const key of Object.keys(extendedEnvValues)) {\n\t\tif (extendedEnvValues[key] !== undefined) {\n\t\t\tcombinedEnv[key] = extendedEnvValues[key];\n\t\t}\n\t}\n\n\tconst globalEnv =\n\t\ttypeof globalThis !== \"undefined\"\n\t\t\t? (globalThis as any).__arkenv_env__\n\t\t\t: undefined;\n\n\tfor (const key of Object.keys(runtimeEnv)) {\n\t\tif (runtimeEnv[key] !== undefined) {\n\t\t\tcombinedEnv[key] = runtimeEnv[key];\n\t\t}\n\t\tif (globalEnv && globalEnv[key] !== undefined) {\n\t\t\tif (key.startsWith(\"NEXT_PUBLIC_\") || key in client || key in shared) {\n\t\t\t\tcombinedEnv[key] = globalEnv[key];\n\t\t\t}\n\t\t}\n\t}\n\n\tif (isServer) {\n\t\t// Fallback server keys to process.env if omitted or undefined\n\t\tfor (const key of Object.keys(server)) {\n\t\t\tif (combinedEnv[key] === undefined && process.env[key] !== undefined) {\n\t\t\t\tcombinedEnv[key] = process.env[key];\n\t\t\t}\n\t\t}\n\t}\n\n\t// Select schema based on environment\n\tconst schema = isServer\n\t\t? { ...server, ...client, ...shared }\n\t\t: { ...client, ...shared };\n\n\t// Run core validation\n\tconst validated = coreCreateEnv(schema as any, { env: combinedEnv });\n\n\tconst mergedValidated = { ...extendedEnvValues, ...validated };\n\n\t// Return a Proxy wrapper\n\treturn new Proxy(mergedValidated, {\n\t\tget(target, prop, receiver) {\n\t\t\tif (prop === EXTENDED_ENV) {\n\t\t\t\treturn target;\n\t\t\t}\n\t\t\tif (prop === ENV_KEYS) {\n\t\t\t\treturn allKeys;\n\t\t\t}\n\t\t\tif (prop === SERVER_ONLY_KEYS) {\n\t\t\t\treturn serverOnlyKeys;\n\t\t\t}\n\n\t\t\t// Always allow symbol properties (Symbol.iterator, Symbol.toStringTag, etc.)\n\t\t\tif (typeof prop === \"symbol\") {\n\t\t\t\treturn Reflect.get(target, prop, receiver);\n\t\t\t}\n\n\t\t\tif (typeof prop === \"string\") {\n\t\t\t\tif (serverOnlyKeys.has(prop) && !isServer) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`ArkEnv Error: Attempted to access server environment variable '${prop}' on the client.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Allow schema keys and standard Object prototype properties\n\t\t\t\tif (!allKeys.has(prop) && !(prop in Object.prototype)) {\n\t\t\t\t\t// Fallback for bundler/framework-specific properties that bypass the prototype\n\t\t\t\t\tconst isCommonKey =\n\t\t\t\t\t\tprop === \"__esModule\" ||\n\t\t\t\t\t\tprop === \"$$typeof\" ||\n\t\t\t\t\t\tprop === \"toJSON\" ||\n\t\t\t\t\t\tprop === \"inspect\";\n\n\t\t\t\t\tif (!isCommonKey) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Environment variable '${prop}' is not defined in the schema.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn Reflect.get(target, prop, receiver);\n\t\t},\n\t});\n}\n"],"mappings":"gDAGA,MAAa,EAAe,OAAO,IAAI,sBAAsB,CAChD,EAAW,OAAO,IAAI,cAAc,CACpC,EAAmB,OAAO,IAAI,0BAA0B,CAErE,IAAI,EAAkB,GAEtB,SAAS,EAAc,EAAuB,CAC7C,GAAI,CAAC,GAAW,OAAO,GAAW,UAAY,OAAO,GAAW,WAC/D,MAAO,EAAE,CAIV,GACC,EAAO,MACP,OAAO,EAAO,MAAS,UACvB,EAAO,KAAK,SAAW,SACtB,CACD,IAAM,EAAiB,EAAE,CACzB,GAAI,MAAM,QAAQ,EAAO,KAAK,SAAS,KACjC,IAAM,KAAK,EAAO,KAAK,SACvB,GAAK,OAAO,GAAM,UAAY,QAAS,GAC1C,EAAK,KAAK,EAAE,IAAI,CAInB,GAAI,MAAM,QAAQ,EAAO,KAAK,SAAS,KACjC,IAAM,KAAK,EAAO,KAAK,SACvB,GAAK,OAAO,GAAM,UAAY,QAAS,GAC1C,EAAK,KAAK,EAAE,IAAI,CAIn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E9D,EAAkB,CAAE,GAAG,EAAmB,GAAG,EAAW,CAG9D,OAAO,IAAI,MAAM,EAAiB,CACjC,IAAI,EAAQ,EAAM,EAAU,CAC3B,GAAI,IAAS,EACZ,OAAO,EAER,GAAI,IAAS,EACZ,OAAO,EAER,GAAI,IAAS,EACZ,OAAO,EAIR,GAAI,OAAO,GAAS,SACnB,OAAO,QAAQ,IAAI,EAAQ,EAAM,EAAS,CAG3C,GAAI,OAAO,GAAS,SAAU,CAC7B,GAAI,EAAe,IAAI,EAAK,EAAI,CAAC,EAChC,MAAU,MACT,kEAAkE,EAAK,kBACvE,CAIF,GAAI,CAAC,EAAQ,IAAI,EAAK,EAAI,EAAE,KAAQ,OAAO,YAQtC,EALH,IAAS,cACT,IAAS,YACT,IAAS,UACT,IAAS,WAGT,MAAU,MACT,yBAAyB,EAAK,iCAC9B,CAIJ,OAAO,QAAQ,IAAI,EAAQ,EAAM,EAAS,EAE3C,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./create-env-
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./create-env-o205_sj3.cjs`),t=require(`./script-BJ1JRyJi.cjs`);require(`./config.cjs`);let n=require(`arkenv`);function r(t,n){return t&&typeof t==`object`&&(`runtimeEnv`in t||`server`in t||`client`in t||`shared`in t)?e.t(t,!1):e.t(t,n,{isServer:!1})}const i=r;exports.ArkEnvScript=t.t,exports.createEnv=r,exports.default=i,Object.defineProperty(exports,`type`,{enumerable:!0,get:function(){return n.type}});
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"./create-env-
|
|
1
|
+
import{t as e}from"./create-env-CRDyrJOZ.js";import{t}from"./script-DB7wIIvT.js";import{type as n}from"arkenv";function r(t,n){return t&&typeof t==`object`&&(`runtimeEnv`in t||`server`in t||`client`in t||`shared`in t)?e(t,!1):e(t,n,{isServer:!1})}const i=r;export{t as ArkEnvScript,r as createEnv,i as default,n as type};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/react-server.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./create-env-
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./create-env-o205_sj3.cjs`),t=require(`./script-BJ1JRyJi.cjs`);require(`./config.cjs`);let n=require(`arkenv`);function r(t,n){return t&&typeof t==`object`&&(`runtimeEnv`in t||`server`in t||`client`in t||`shared`in t)?e.t(t,!0):e.t(t,n,{isServer:!0})}const i=r;exports.ArkEnvScript=t.t,exports.createEnv=r,exports.default=i,Object.defineProperty(exports,`type`,{enumerable:!0,get:function(){return n.type}});
|
|
2
2
|
//# sourceMappingURL=react-server.cjs.map
|
package/dist/react-server.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"./create-env-
|
|
1
|
+
import{t as e}from"./create-env-CRDyrJOZ.js";import{t}from"./script-DB7wIIvT.js";import{type as n}from"arkenv";function r(t,n){return t&&typeof t==`object`&&(`runtimeEnv`in t||`server`in t||`client`in t||`shared`in t)?e(t,!0):e(t,n,{isServer:!0})}const i=r;export{t as ArkEnvScript,r as createEnv,i as default,n as type};
|
|
2
2
|
//# sourceMappingURL=react-server.js.map
|
package/dist/server.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./create-env-
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./create-env-o205_sj3.cjs`);require(`./config.cjs`);let t=require(`arkenv`);require(`server-only`);function n(t,n){if(t&&typeof t==`object`&&(`runtimeEnv`in t||`server`in t||`shared`in t)){if(`client`in t)throw Error(`server entry point only accepts 'server' and 'shared' schemas.`);return e.t(t,!0)}return e.t(t,n,{isServer:!0,strictLayout:`server`})}const r=n;exports.createEnv=n,exports.default=r,Object.defineProperty(exports,`type`,{enumerable:!0,get:function(){return t.type}});
|
|
2
2
|
//# sourceMappingURL=server.cjs.map
|
package/dist/server.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"./create-env-
|
|
1
|
+
import{t as e}from"./create-env-CRDyrJOZ.js";import{type as t}from"arkenv";import"server-only";function n(t,n){if(t&&typeof t==`object`&&(`runtimeEnv`in t||`server`in t||`shared`in t)){if(`client`in t)throw Error(`server entry point only accepts 'server' and 'shared' schemas.`);return e(t,!0)}return e(t,n,{isServer:!0,strictLayout:`server`})}const r=n;export{n as createEnv,r as default,t as type};
|
|
2
2
|
//# sourceMappingURL=server.js.map
|
package/dist/shared.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./create-env-
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./create-env-o205_sj3.cjs`);require(`./config.cjs`);let t=require(`arkenv`);function n(t,n){return e.t(t,n,{isServer:typeof window>`u`,isShared:!0})}const r=n;exports.createEnv=n,exports.default=r,Object.defineProperty(exports,`type`,{enumerable:!0,get:function(){return t.type}});
|
|
2
2
|
//# sourceMappingURL=shared.cjs.map
|
package/dist/shared.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"./create-env-
|
|
1
|
+
import{t as e}from"./create-env-CRDyrJOZ.js";import{type as t}from"arkenv";function n(t,n){return e(t,n,{isServer:typeof window>`u`,isShared:!0})}const r=n;export{n as createEnv,r as default,t as type};
|
|
2
2
|
//# sourceMappingURL=shared.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkenv/nextjs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"author": "Yam Borodetsky <yam@yam.codes>",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"module": "./dist/index.js",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"chokidar": "^4.0.3",
|
|
13
|
+
"jiti": "2.7.0",
|
|
13
14
|
"server-only": "^0.0.1",
|
|
14
15
|
"@arkenv/build": "0.0.1",
|
|
15
16
|
"arkenv": "0.12.2"
|
|
@@ -133,15 +134,17 @@
|
|
|
133
134
|
{
|
|
134
135
|
"name": "@arkenv/nextjs/config",
|
|
135
136
|
"path": "dist/config.js",
|
|
136
|
-
"limit": "
|
|
137
|
+
"limit": "4 kB",
|
|
137
138
|
"import": "*",
|
|
138
139
|
"ignore": [
|
|
139
140
|
"next",
|
|
140
141
|
"arktype",
|
|
141
142
|
"arkenv",
|
|
142
143
|
"chokidar",
|
|
144
|
+
"jiti",
|
|
143
145
|
"node:fs",
|
|
144
|
-
"node:path"
|
|
146
|
+
"node:path",
|
|
147
|
+
"node:url"
|
|
145
148
|
]
|
|
146
149
|
}
|
|
147
150
|
],
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{createEnv as e}from"arkenv";const t=Symbol.for(`arkenv.extended_env`),n=Symbol.for(`arkenv.keys`),r=Symbol.for(`arkenv.server_only_keys`);let i=!1;function a(e){if(!e||typeof e!=`object`&&typeof e!=`function`)return[];if(e.json&&typeof e.json==`object`&&e.json.domain===`object`){let t=[];if(Array.isArray(e.json.required))for(let n of e.json.required)n&&typeof n==`object`&&`key`in n&&t.push(n.key);if(Array.isArray(e.json.optional))for(let n of e.json.optional)n&&typeof n==`object`&&`key`in n&&t.push(n.key);return t}return`shape`in e&&e.shape&&typeof e.shape==`object`?Object.keys(e.shape):`entries`in e&&e.entries&&typeof e.entries==`object`?Object.keys(e.entries):Object.keys(e)}function o(o,s,c){let l={},u={},d={},f=[],p={},m=!1;if(typeof s==`boolean`)process.env.NODE_ENV===`development`&&!i&&(i=!0,console.warn(`⚠️ [arkenv] Deprecated: The nested layout structure (specifying 'server', 'client', or 'shared' keys in createEnv) is deprecated and will be removed in the next major version. Please migrate to the flat layout. See guide: https://arkenv.js.org/docs/nextjs/faq#how-do-i-define-client-side-variables`)),l=o.server||{},u=o.client||{},d=o.shared||{},f=o.extends||[],p=o.runtimeEnv||{},m=s;else{let e=o||{},t=s||{};if(f=t.extends||[],p=t.runtimeEnv||{},m=!!c?.isServer,c?.isShared)d=e;else if(c?.strictLayout===`client`)u=e;else if(c?.strictLayout===`server`)l=e;else{let n=t.exposeToClient||t.expose||t.shared||[];for(let t of Object.keys(e))n.includes(t)||t===`NODE_ENV`?d[t]=e[t]:t.startsWith(`NEXT_PUBLIC_`)?u[t]=e[t]:l[t]=e[t]}}let h={},g=new Set,_=new Set;for(let e of Object.keys(l))g.add(e),!(e in u)&&!(e in d)&&_.add(e);for(let e of Object.keys(u))g.add(e);for(let e of Object.keys(d))g.add(e);let v={};if(f&&Array.isArray(f)){for(let i of f)if(i&&(typeof i==`object`||typeof i==`function`)){let o=i[t];if(o){h={...h,...o};let e=i[n];if(e instanceof Set)for(let t of e)g.add(t);let t=i[r];if(t instanceof Set)for(let e of t)_.add(e)}else{for(let e of Object.keys(h))h[e]!==void 0&&(v[e]=h[e]);for(let e of Object.keys(p))p[e]!==void 0&&(v[e]=p[e]);if(m)for(let e of Object.keys(l))v[e]===void 0&&process.env[e]!==void 0&&(v[e]=process.env[e]);let t=e(i,{env:v});h={...h,...t};let n=a(i);for(let e of n)g.add(e),m&&!e.startsWith(`NEXT_PUBLIC_`)&&!c?.isShared&&_.add(e)}}}for(let e of Object.keys(u))_.delete(e);for(let e of Object.keys(d))_.delete(e);for(let e of Object.keys(u))if(!e.startsWith(`NEXT_PUBLIC_`))throw Error(`Client-side environment variables must be prefixed with 'NEXT_PUBLIC_'. Found invalid key: ${e}`);let y=[...Object.keys(u),...Object.keys(d)];for(let e of y)if(!(e in p))throw Error(`Missing key in runtimeEnv: ${e}. All client and shared environment variables must be explicitly destructured in runtimeEnv.`);for(let e of Object.keys(p))if(!g.has(e))throw Error(`Environment variable '${e}' is passed to runtimeEnv but is not defined in the schema.`);for(let e of Object.keys(h))h[e]!==void 0&&(v[e]=h[e]);let b=typeof globalThis<`u`?globalThis.__arkenv_env__:void 0;for(let e of Object.keys(p))p[e]!==void 0&&(v[e]=p[e]),b&&b[e]!==void 0&&(e.startsWith(`NEXT_PUBLIC_`)||e in u||e in d)&&(v[e]=b[e]);if(m)for(let e of Object.keys(l))v[e]===void 0&&process.env[e]!==void 0&&(v[e]=process.env[e]);let x=e(m?{...l,...u,...d}:{...u,...d},{env:v}),S={...h,...x};return new Proxy(S,{get(e,i,a){if(i===t)return e;if(i===n)return g;if(i===r)return _;if(typeof i==`symbol`)return Reflect.get(e,i,a);if(typeof i==`string`){if(_.has(i)&&!m)throw Error(`ArkEnv Error: Attempted to access server environment variable '${i}' on the client.`);if(!g.has(i)&&!(i in Object.prototype)&&!(i===`__esModule`||i===`$$typeof`||i===`toJSON`||i===`inspect`))throw Error(`Environment variable '${i}' is not defined in the schema.`)}return Reflect.get(e,i,a)}})}export{o as t};
|
|
2
|
-
//# sourceMappingURL=create-env-B6DmIK3X.js.map
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
require(`./config.cjs`);let e=require(`arkenv`);const t=Symbol.for(`arkenv.extended_env`),n=Symbol.for(`arkenv.keys`),r=Symbol.for(`arkenv.server_only_keys`);let i=!1;function a(e){if(!e||typeof e!=`object`&&typeof e!=`function`)return[];if(e.json&&typeof e.json==`object`&&e.json.domain===`object`){let t=[];if(Array.isArray(e.json.required))for(let n of e.json.required)n&&typeof n==`object`&&`key`in n&&t.push(n.key);if(Array.isArray(e.json.optional))for(let n of e.json.optional)n&&typeof n==`object`&&`key`in n&&t.push(n.key);return t}return`shape`in e&&e.shape&&typeof e.shape==`object`?Object.keys(e.shape):`entries`in e&&e.entries&&typeof e.entries==`object`?Object.keys(e.entries):Object.keys(e)}function o(o,s,c){let l={},u={},d={},f=[],p={},m=!1;if(typeof s==`boolean`)process.env.NODE_ENV===`development`&&!i&&(i=!0,console.warn(`⚠️ [arkenv] Deprecated: The nested layout structure (specifying 'server', 'client', or 'shared' keys in createEnv) is deprecated and will be removed in the next major version. Please migrate to the flat layout. See guide: https://arkenv.js.org/docs/nextjs/faq#how-do-i-define-client-side-variables`)),l=o.server||{},u=o.client||{},d=o.shared||{},f=o.extends||[],p=o.runtimeEnv||{},m=s;else{let e=o||{},t=s||{};if(f=t.extends||[],p=t.runtimeEnv||{},m=!!c?.isServer,c?.isShared)d=e;else if(c?.strictLayout===`client`)u=e;else if(c?.strictLayout===`server`)l=e;else{let n=t.exposeToClient||t.expose||t.shared||[];for(let t of Object.keys(e))n.includes(t)||t===`NODE_ENV`?d[t]=e[t]:t.startsWith(`NEXT_PUBLIC_`)?u[t]=e[t]:l[t]=e[t]}}let h={},g=new Set,_=new Set;for(let e of Object.keys(l))g.add(e),!(e in u)&&!(e in d)&&_.add(e);for(let e of Object.keys(u))g.add(e);for(let e of Object.keys(d))g.add(e);let v={};if(f&&Array.isArray(f)){for(let i of f)if(i&&(typeof i==`object`||typeof i==`function`)){let o=i[t];if(o){h={...h,...o};let e=i[n];if(e instanceof Set)for(let t of e)g.add(t);let t=i[r];if(t instanceof Set)for(let e of t)_.add(e)}else{for(let e of Object.keys(h))h[e]!==void 0&&(v[e]=h[e]);for(let e of Object.keys(p))p[e]!==void 0&&(v[e]=p[e]);if(m)for(let e of Object.keys(l))v[e]===void 0&&process.env[e]!==void 0&&(v[e]=process.env[e]);let t=(0,e.createEnv)(i,{env:v});h={...h,...t};let n=a(i);for(let e of n)g.add(e),m&&!e.startsWith(`NEXT_PUBLIC_`)&&!c?.isShared&&_.add(e)}}}for(let e of Object.keys(u))_.delete(e);for(let e of Object.keys(d))_.delete(e);for(let e of Object.keys(u))if(!e.startsWith(`NEXT_PUBLIC_`))throw Error(`Client-side environment variables must be prefixed with 'NEXT_PUBLIC_'. Found invalid key: ${e}`);let y=[...Object.keys(u),...Object.keys(d)];for(let e of y)if(!(e in p))throw Error(`Missing key in runtimeEnv: ${e}. All client and shared environment variables must be explicitly destructured in runtimeEnv.`);for(let e of Object.keys(p))if(!g.has(e))throw Error(`Environment variable '${e}' is passed to runtimeEnv but is not defined in the schema.`);for(let e of Object.keys(h))h[e]!==void 0&&(v[e]=h[e]);let b=typeof globalThis<`u`?globalThis.__arkenv_env__:void 0;for(let e of Object.keys(p))p[e]!==void 0&&(v[e]=p[e]),b&&b[e]!==void 0&&(e.startsWith(`NEXT_PUBLIC_`)||e in u||e in d)&&(v[e]=b[e]);if(m)for(let e of Object.keys(l))v[e]===void 0&&process.env[e]!==void 0&&(v[e]=process.env[e]);let x=(0,e.createEnv)(m?{...l,...u,...d}:{...u,...d},{env:v}),S={...h,...x};return new Proxy(S,{get(e,i,a){if(i===t)return e;if(i===n)return g;if(i===r)return _;if(typeof i==`symbol`)return Reflect.get(e,i,a);if(typeof i==`string`){if(_.has(i)&&!m)throw Error(`ArkEnv Error: Attempted to access server environment variable '${i}' on the client.`);if(!g.has(i)&&!(i in Object.prototype)&&!(i===`__esModule`||i===`$$typeof`||i===`toJSON`||i===`inspect`))throw Error(`Environment variable '${i}' is not defined in the schema.`)}return Reflect.get(e,i,a)}})}Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return o}});
|
|
2
|
-
//# sourceMappingURL=create-env-C_h541CQ.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-env-C_h541CQ.cjs","names":[],"sources":["../src/create-env.ts"],"sourcesContent":["import type { Dict, SchemaShape } from \"@repo/types\";\nimport { createEnv as coreCreateEnv } from \"arkenv\";\n\nexport const EXTENDED_ENV = Symbol.for(\"arkenv.extended_env\");\nexport const ENV_KEYS = Symbol.for(\"arkenv.keys\");\nexport const SERVER_ONLY_KEYS = Symbol.for(\"arkenv.server_only_keys\");\n\nlet hasWarnedLegacy = false;\n\nfunction getSchemaKeys(schema: any): string[] {\n\tif (!schema || (typeof schema !== \"object\" && typeof schema !== \"function\")) {\n\t\treturn [];\n\t}\n\n\t// ArkType Type\n\tif (\n\t\tschema.json &&\n\t\ttypeof schema.json === \"object\" &&\n\t\tschema.json.domain === \"object\"\n\t) {\n\t\tconst keys: string[] = [];\n\t\tif (Array.isArray(schema.json.required)) {\n\t\t\tfor (const r of schema.json.required) {\n\t\t\t\tif (r && typeof r === \"object\" && \"key\" in r) {\n\t\t\t\t\tkeys.push(r.key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (Array.isArray(schema.json.optional)) {\n\t\t\tfor (const o of schema.json.optional) {\n\t\t\t\tif (o && typeof o === \"object\" && \"key\" in o) {\n\t\t\t\t\tkeys.push(o.key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn keys;\n\t}\n\n\t// Zod schema\n\tif (\"shape\" in schema && schema.shape && typeof schema.shape === \"object\") {\n\t\treturn Object.keys(schema.shape);\n\t}\n\n\t// Valibot schema\n\tif (\n\t\t\"entries\" in schema &&\n\t\tschema.entries &&\n\t\ttypeof schema.entries === \"object\"\n\t) {\n\t\treturn Object.keys(schema.entries);\n\t}\n\n\t// Plain object schema\n\treturn Object.keys(schema);\n}\n\n/**\n * Validate and wrap environment variables in a security proxy.\n *\n * @internal\n */\nexport function createEnvInternal(\n\tschemaOrOptions: any,\n\toptionsOrIsServer: any,\n\tcontext?: {\n\t\tisServer: boolean;\n\t\tisShared?: boolean;\n\t\tstrictLayout?: \"client\" | \"server\";\n\t},\n): unknown {\n\tlet server: SchemaShape = {};\n\tlet client: SchemaShape = {};\n\tlet shared: SchemaShape = {};\n\tlet extendsList: unknown[] = [];\n\tlet runtimeEnv: Dict<string> = {};\n\tlet isServer = false;\n\n\tif (typeof optionsOrIsServer === \"boolean\") {\n\t\tif (process.env.NODE_ENV === \"development\" && !hasWarnedLegacy) {\n\t\t\thasWarnedLegacy = true;\n\t\t\tconsole.warn(\n\t\t\t\t\"⚠️ [arkenv] Deprecated: The nested layout structure (specifying 'server', 'client', or 'shared' keys in createEnv) is deprecated and will be removed in the next major version. Please migrate to the flat layout. See guide: https://arkenv.js.org/docs/nextjs/faq#how-do-i-define-client-side-variables\",\n\t\t\t);\n\t\t}\n\t\t// Old nested schema behavior (backward compatible)\n\t\tserver = schemaOrOptions.server || {};\n\t\tclient = schemaOrOptions.client || {};\n\t\tshared = schemaOrOptions.shared || {};\n\t\textendsList = schemaOrOptions.extends || [];\n\t\truntimeEnv = schemaOrOptions.runtimeEnv || {};\n\t\tisServer = optionsOrIsServer;\n\t} else {\n\t\t// New flat schema behavior\n\t\tconst flatSchema = schemaOrOptions || {};\n\t\tconst options = optionsOrIsServer || {};\n\t\textendsList = options.extends || [];\n\t\truntimeEnv = options.runtimeEnv || {};\n\t\tisServer = !!context?.isServer;\n\n\t\tif (context?.isShared) {\n\t\t\tshared = flatSchema;\n\t\t} else if (context?.strictLayout === \"client\") {\n\t\t\tclient = flatSchema;\n\t\t} else if (context?.strictLayout === \"server\") {\n\t\t\tserver = flatSchema;\n\t\t} else {\n\t\t\tconst exposedKeys =\n\t\t\t\toptions.exposeToClient || options.expose || options.shared || [];\n\t\t\tfor (const key of Object.keys(flatSchema)) {\n\t\t\t\t// NODE_ENV is implicitly shared as Next.js automatically inlines and replaces references to process.env.NODE_ENV in browser bundles.\n\t\t\t\t// See: https://nextjs.org/docs/app/guides/environment-variables\n\t\t\t\tif (exposedKeys.includes(key) || key === \"NODE_ENV\") {\n\t\t\t\t\tshared[key] = flatSchema[key];\n\t\t\t\t} else if (key.startsWith(\"NEXT_PUBLIC_\")) {\n\t\t\t\t\tclient[key] = flatSchema[key];\n\t\t\t\t} else {\n\t\t\t\t\tserver[key] = flatSchema[key];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tlet extendedEnvValues: Dict<string> = {};\n\tconst allKeys = new Set<string>();\n\tconst serverOnlyKeys = new Set<string>();\n\n\t// Add local keys\n\tfor (const key of Object.keys(server)) {\n\t\tallKeys.add(key);\n\t\tif (!(key in client) && !(key in shared)) {\n\t\t\tserverOnlyKeys.add(key);\n\t\t}\n\t}\n\tfor (const key of Object.keys(client)) {\n\t\tallKeys.add(key);\n\t}\n\tfor (const key of Object.keys(shared)) {\n\t\tallKeys.add(key);\n\t}\n\n\t// Prepare combined environment for core validation\n\tconst combinedEnv: Dict<string> = {};\n\n\t// Process extended environments\n\tif (extendsList && Array.isArray(extendsList)) {\n\t\tfor (const ext of extendsList) {\n\t\t\tif (ext && (typeof ext === \"object\" || typeof ext === \"function\")) {\n\t\t\t\tconst raw = (ext as any)[EXTENDED_ENV];\n\t\t\t\tif (raw) {\n\t\t\t\t\textendedEnvValues = { ...extendedEnvValues, ...raw };\n\n\t\t\t\t\tconst extKeys = (ext as any)[ENV_KEYS];\n\t\t\t\t\tif (extKeys instanceof Set) {\n\t\t\t\t\t\tfor (const key of extKeys) allKeys.add(key);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst extServerOnly = (ext as any)[SERVER_ONLY_KEYS];\n\t\t\t\t\tif (extServerOnly instanceof Set) {\n\t\t\t\t\t\tfor (const key of extServerOnly) serverOnlyKeys.add(key);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Prepare what we have so far for validating the extended schema\n\t\t\t\t\tfor (const key of Object.keys(extendedEnvValues)) {\n\t\t\t\t\t\tif (extendedEnvValues[key] !== undefined) {\n\t\t\t\t\t\t\tcombinedEnv[key] = extendedEnvValues[key];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tfor (const key of Object.keys(runtimeEnv)) {\n\t\t\t\t\t\tif (runtimeEnv[key] !== undefined) {\n\t\t\t\t\t\t\tcombinedEnv[key] = runtimeEnv[key];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (isServer) {\n\t\t\t\t\t\tfor (const key of Object.keys(server)) {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tcombinedEnv[key] === undefined &&\n\t\t\t\t\t\t\t\tprocess.env[key] !== undefined\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcombinedEnv[key] = process.env[key];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst validated = coreCreateEnv(ext as any, { env: combinedEnv });\n\t\t\t\t\textendedEnvValues = { ...extendedEnvValues, ...validated };\n\n\t\t\t\t\tconst extKeys = getSchemaKeys(ext);\n\t\t\t\t\tfor (const key of extKeys) {\n\t\t\t\t\t\tallKeys.add(key);\n\t\t\t\t\t\t// Only classify as server-only if we are on the server, it's not a public key,\n\t\t\t\t\t\t// and we aren't explicitly inside the shared entry point.\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tisServer &&\n\t\t\t\t\t\t\t!key.startsWith(\"NEXT_PUBLIC_\") &&\n\t\t\t\t\t\t\t!context?.isShared\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tserverOnlyKeys.add(key);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Remove keys from serverOnlyKeys if they are defined as client or shared locally\n\tfor (const key of Object.keys(client)) {\n\t\tserverOnlyKeys.delete(key);\n\t}\n\tfor (const key of Object.keys(shared)) {\n\t\tserverOnlyKeys.delete(key);\n\t}\n\n\t// Validate options\n\t// For client keys, check prefix\n\tfor (const key of Object.keys(client)) {\n\t\tif (!key.startsWith(\"NEXT_PUBLIC_\")) {\n\t\t\tthrow new Error(\n\t\t\t\t`Client-side environment variables must be prefixed with 'NEXT_PUBLIC_'. Found invalid key: ${key}`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// Check runtimeEnv has all local client and shared keys\n\tconst requiredKeys = [...Object.keys(client), ...Object.keys(shared)];\n\tfor (const key of requiredKeys) {\n\t\tif (!(key in runtimeEnv)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Missing key in runtimeEnv: ${key}. All client and shared environment variables must be explicitly destructured in runtimeEnv.`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// Check runtimeEnv does not have any keys not defined in the schema (allKeys)\n\tfor (const key of Object.keys(runtimeEnv)) {\n\t\tif (!allKeys.has(key)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Environment variable '${key}' is passed to runtimeEnv but is not defined in the schema.`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// Build final combinedEnv\n\tfor (const key of Object.keys(extendedEnvValues)) {\n\t\tif (extendedEnvValues[key] !== undefined) {\n\t\t\tcombinedEnv[key] = extendedEnvValues[key];\n\t\t}\n\t}\n\n\tconst globalEnv =\n\t\ttypeof globalThis !== \"undefined\"\n\t\t\t? (globalThis as any).__arkenv_env__\n\t\t\t: undefined;\n\n\tfor (const key of Object.keys(runtimeEnv)) {\n\t\tif (runtimeEnv[key] !== undefined) {\n\t\t\tcombinedEnv[key] = runtimeEnv[key];\n\t\t}\n\t\tif (globalEnv && globalEnv[key] !== undefined) {\n\t\t\tif (key.startsWith(\"NEXT_PUBLIC_\") || key in client || key in shared) {\n\t\t\t\tcombinedEnv[key] = globalEnv[key];\n\t\t\t}\n\t\t}\n\t}\n\n\tif (isServer) {\n\t\t// Fallback server keys to process.env if omitted or undefined\n\t\tfor (const key of Object.keys(server)) {\n\t\t\tif (combinedEnv[key] === undefined && process.env[key] !== undefined) {\n\t\t\t\tcombinedEnv[key] = process.env[key];\n\t\t\t}\n\t\t}\n\t}\n\n\t// Select schema based on environment\n\tconst schema = isServer\n\t\t? { ...server, ...client, ...shared }\n\t\t: { ...client, ...shared };\n\n\t// Run core validation\n\tconst validated = coreCreateEnv(schema as any, { env: combinedEnv });\n\n\tconst mergedValidated = { ...extendedEnvValues, ...validated };\n\n\t// Return a Proxy wrapper\n\treturn new Proxy(mergedValidated, {\n\t\tget(target, prop, receiver) {\n\t\t\tif (prop === EXTENDED_ENV) {\n\t\t\t\treturn target;\n\t\t\t}\n\t\t\tif (prop === ENV_KEYS) {\n\t\t\t\treturn allKeys;\n\t\t\t}\n\t\t\tif (prop === SERVER_ONLY_KEYS) {\n\t\t\t\treturn serverOnlyKeys;\n\t\t\t}\n\n\t\t\t// Always allow symbol properties (Symbol.iterator, Symbol.toStringTag, etc.)\n\t\t\tif (typeof prop === \"symbol\") {\n\t\t\t\treturn Reflect.get(target, prop, receiver);\n\t\t\t}\n\n\t\t\tif (typeof prop === \"string\") {\n\t\t\t\tif (serverOnlyKeys.has(prop) && !isServer) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`ArkEnv Error: Attempted to access server environment variable '${prop}' on the client.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Allow schema keys and standard Object prototype properties\n\t\t\t\tif (!allKeys.has(prop) && !(prop in Object.prototype)) {\n\t\t\t\t\t// Fallback for bundler/framework-specific properties that bypass the prototype\n\t\t\t\t\tconst isCommonKey =\n\t\t\t\t\t\tprop === \"__esModule\" ||\n\t\t\t\t\t\tprop === \"$$typeof\" ||\n\t\t\t\t\t\tprop === \"toJSON\" ||\n\t\t\t\t\t\tprop === \"inspect\";\n\n\t\t\t\t\tif (!isCommonKey) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Environment variable '${prop}' is not defined in the schema.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn Reflect.get(target, prop, receiver);\n\t\t},\n\t});\n}\n"],"mappings":"gDAGA,MAAa,EAAe,OAAO,IAAI,sBAAsB,CAChD,EAAW,OAAO,IAAI,cAAc,CACpC,EAAmB,OAAO,IAAI,0BAA0B,CAErE,IAAI,EAAkB,GAEt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