@geekmidas/envkit 0.3.0 → 0.5.0
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/{EnvironmentBuilder-DHfDXJUm.d.mts → EnvironmentBuilder-jF-b7WQg.d.mts} +1 -1
- package/dist/{EnvironmentBuilder-DHfDXJUm.d.mts.map → EnvironmentBuilder-jF-b7WQg.d.mts.map} +1 -1
- package/dist/EnvironmentBuilder.d.mts +1 -1
- package/dist/{EnvironmentParser-c06agx31.mjs → EnvironmentParser-CBLsPUyQ.mjs} +7 -2
- package/dist/EnvironmentParser-CBLsPUyQ.mjs.map +1 -0
- package/dist/{EnvironmentParser-CY8TosTN.d.mts → EnvironmentParser-CkLfmn4Y.d.mts} +1 -1
- package/dist/{EnvironmentParser-CY8TosTN.d.mts.map → EnvironmentParser-CkLfmn4Y.d.mts.map} +1 -1
- package/dist/{EnvironmentParser-Bt246UeP.cjs → EnvironmentParser-DlWHnhDY.cjs} +7 -2
- package/dist/EnvironmentParser-DlWHnhDY.cjs.map +1 -0
- package/dist/EnvironmentParser-DtOL86NU.d.cts.map +1 -1
- package/dist/EnvironmentParser.cjs +2 -1
- package/dist/EnvironmentParser.d.mts +1 -1
- package/dist/EnvironmentParser.mjs +2 -1
- package/dist/SnifferEnvironmentParser.cjs +2 -1
- package/dist/SnifferEnvironmentParser.cjs.map +1 -1
- package/dist/SnifferEnvironmentParser.d.mts +1 -1
- package/dist/SnifferEnvironmentParser.mjs +2 -1
- package/dist/SnifferEnvironmentParser.mjs.map +1 -1
- package/dist/{SstEnvironmentBuilder-CjURMGjW.d.mts → SstEnvironmentBuilder-BZngSQKQ.d.mts} +2 -2
- package/dist/{SstEnvironmentBuilder-CjURMGjW.d.mts.map → SstEnvironmentBuilder-BZngSQKQ.d.mts.map} +1 -1
- package/dist/{SstEnvironmentBuilder-BEBFSUYr.mjs → SstEnvironmentBuilder-DVB7cJq4.mjs} +1 -1
- package/dist/{SstEnvironmentBuilder-BEBFSUYr.mjs.map → SstEnvironmentBuilder-DVB7cJq4.mjs.map} +1 -1
- package/dist/{SstEnvironmentBuilder-wFnN2M5O.cjs → SstEnvironmentBuilder-jsnqgtcW.cjs} +1 -1
- package/dist/{SstEnvironmentBuilder-wFnN2M5O.cjs.map → SstEnvironmentBuilder-jsnqgtcW.cjs.map} +1 -1
- package/dist/SstEnvironmentBuilder.cjs +1 -1
- package/dist/SstEnvironmentBuilder.d.mts +2 -2
- package/dist/SstEnvironmentBuilder.mjs +1 -1
- package/dist/formatter-Cox0NGxT.d.mts +51 -0
- package/dist/formatter-Cox0NGxT.d.mts.map +1 -0
- package/dist/formatter-D85aIkpd.d.cts +51 -0
- package/dist/formatter-D85aIkpd.d.cts.map +1 -0
- package/dist/formatter-fz8V7x6i.mjs +113 -0
- package/dist/formatter-fz8V7x6i.mjs.map +1 -0
- package/dist/formatter-w8Tsccw4.cjs +125 -0
- package/dist/formatter-w8Tsccw4.cjs.map +1 -0
- package/dist/formatter.cjs +4 -0
- package/dist/formatter.d.cts +2 -0
- package/dist/formatter.d.mts +2 -0
- package/dist/formatter.mjs +3 -0
- package/dist/index.cjs +5 -2
- package/dist/index.d.cts +2 -1
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +3 -2
- package/dist/sst.cjs +1 -1
- package/dist/sst.d.mts +2 -2
- package/dist/sst.mjs +1 -1
- package/package.json +1 -1
- package/src/EnvironmentParser.ts +7 -2
- package/src/__tests__/formatter.spec.ts +250 -0
- package/src/formatter.ts +147 -0
- package/src/index.ts +5 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/dist/EnvironmentParser-Bt246UeP.cjs.map +0 -1
- package/dist/EnvironmentParser-c06agx31.mjs.map +0 -1
|
@@ -128,4 +128,4 @@ declare class EnvironmentBuilder<TRecord extends Record<string, InputValue> = Re
|
|
|
128
128
|
}
|
|
129
129
|
//#endregion
|
|
130
130
|
export { EnvRecord, EnvValue, EnvironmentBuilder, EnvironmentBuilderOptions, EnvironmentResolver, InputValue, Resolvers, TypedInputValue, TypedResolvers, environmentCase };
|
|
131
|
-
//# sourceMappingURL=EnvironmentBuilder-
|
|
131
|
+
//# sourceMappingURL=EnvironmentBuilder-jF-b7WQg.d.mts.map
|
package/dist/{EnvironmentBuilder-DHfDXJUm.d.mts.map → EnvironmentBuilder-jF-b7WQg.d.mts.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnvironmentBuilder-
|
|
1
|
+
{"version":3,"file":"EnvironmentBuilder-jF-b7WQg.d.mts","names":[],"sources":["../src/EnvironmentBuilder.ts"],"sourcesContent":[],"mappings":";;AAaA;AAYA;AAQA;AAUA;;;;AAA+E;AAK/E;;AAAuC,iBAnCvB,eAAA,CAmCuB,IAAA,EAAA,MAAA,CAAA,EAAA,MAAA;;AAAT;AAK9B;AAWA;AAKY,UA5CK,SAAA,CA4CU;EAQtB,CAAA,GAAA,EAAA,MAAA,CAAA,EAnDW,QAmDA;;;;AAAoD;AAAA;AAKvD,KAjDD,QAAA,GAiDC,MAAA,GAAA,MAAA,GAAA,OAAA,GAjDsC,SAiDtC;;;;AAAuC;AAAA;;;;AAMvC,KA7CD,mBA6CC,CAAA,IAAA,GAAA,CAAA,GAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EA7CmD,CA6CnD,EAAA,GA7CyD,SA6CzD;;;;AACL,KAzCI,SAAA,GAAY,MAyChB,CAAA,MAAA,EAzC+B,mBAyC/B,CAAA,GAAA,CAAA,CAAA;AAAO;AAAA;;AAMiB,UA1Cf,yBAAA,CA0Ce;EAAU;;;;EAGV,gBAAkB,CAAA,EAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EAAA,OAAA,EAAA,GAAA,IAAA;;;;;AAGnC,KArCH,UAAA,GAqCG,MAAA,GAAA;EAMH,IAAA,EAAA,MAAA;EAAc,CAAA,GAAA,EAAA,MAAA,CAAA,EAAA,OAAA;CAAA;;;;AAEX,KAxCH,eAwCG,CAAA,cAAA,MAAA,GAAA,MAAA,CAAA,GAAA;EAAO,IAAE,EAvCjB,KAuCiB;EAAK,CAAA,GAA3B,EAAA,MAAA,CAAA,EAAA,OAAA;CAAY;AADyC;AA2BvD;;KA1DK,WA2D2B,CAAA,CAAA,CAAA,GA3DV,CA2DU,SAAA;EAAU,IAAzB,EAAA,KAAA,WAAA,MAAA;CAAM,GA3D4C,CA2D5C,GAAsC,KAAA;;;;KAtDxD,QAuD2B,CAAA,CAAA,CAAA,GAvDb,CAuDa,SAAA;EAAc,IAOpC,EAAA,MAAA;CAAO,GA9D+B,IA+DnC,CA/DwC,CA+DxC,EAAA,MAAA,CAAA,GAAA,KAAA;;;AAoBM;KA9Ed,8BAA8B,eAAe,6BACrC,UAAU,YAAY,QAAQ,YACnC;;;;KAKH,6BACY,eAAe,mDAGnB,UAAU,QAAQ;QAAmB;IAC9C,SAAS,QAAQ,oBAEb;;;;;KAMI,+BAA+B,eAAe,2BAC/C,cAAc,WAAW,oBAClC,aAAa,SAAS;;;;;;;;;;;;;;;;;;;;;;;cA0BX,mCACI,eAAe,cAAc,eAAe,gCACzC,YAAY,eAAe;;;;sBAOrC,oBACG,sBACF;;;;;;;;;;;WAmBD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { EnvRecord, EnvValue, EnvironmentBuilder, EnvironmentBuilderOptions, EnvironmentResolver, InputValue, Resolvers, TypedInputValue, TypedResolvers, environmentCase } from "./EnvironmentBuilder-
|
|
1
|
+
import { EnvRecord, EnvValue, EnvironmentBuilder, EnvironmentBuilderOptions, EnvironmentResolver, InputValue, Resolvers, TypedInputValue, TypedResolvers, environmentCase } from "./EnvironmentBuilder-jF-b7WQg.mjs";
|
|
2
2
|
export { EnvRecord, EnvValue, EnvironmentBuilder, EnvironmentBuilderOptions, EnvironmentResolver, InputValue, Resolvers, TypedInputValue, TypedResolvers, environmentCase };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { formatParseError, isDevelopment } from "./formatter-fz8V7x6i.mjs";
|
|
1
2
|
import get from "lodash.get";
|
|
2
3
|
import set from "lodash.set";
|
|
3
4
|
import { z } from "zod/v4";
|
|
@@ -44,7 +45,11 @@ var ConfigParser = class {
|
|
|
44
45
|
return result;
|
|
45
46
|
};
|
|
46
47
|
const parsedConfig = parseDeep(this.config);
|
|
47
|
-
if (errors.length > 0)
|
|
48
|
+
if (errors.length > 0) {
|
|
49
|
+
const zodError = new z.ZodError(errors);
|
|
50
|
+
if (isDevelopment()) console.error(formatParseError(zodError));
|
|
51
|
+
throw zodError;
|
|
52
|
+
}
|
|
48
53
|
return parsedConfig;
|
|
49
54
|
}
|
|
50
55
|
/**
|
|
@@ -206,4 +211,4 @@ var EnvironmentParser = class {
|
|
|
206
211
|
|
|
207
212
|
//#endregion
|
|
208
213
|
export { ConfigParser, EnvironmentParser };
|
|
209
|
-
//# sourceMappingURL=EnvironmentParser-
|
|
214
|
+
//# sourceMappingURL=EnvironmentParser-CBLsPUyQ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnvironmentParser-CBLsPUyQ.mjs","names":["config: TResponse","envVars: Set<string>","errors: z.core.$ZodIssue[]","config: T","path: string[]","result: EmptyObject","schema: z.ZodType","name: string","issue: z.core.$ZodIssue","builder: (get: EnvFetcher) => TReturn"],"sources":["../src/EnvironmentParser.ts"],"sourcesContent":["import get from 'lodash.get';\nimport set from 'lodash.set';\nimport { z } from 'zod/v4';\nimport { formatParseError, isDevelopment } from './formatter.js';\n\n/**\n * Parses and validates configuration objects against Zod schemas.\n * Handles nested configurations and aggregates validation errors.\n *\n * @template TResponse - The shape of the configuration object\n */\nexport class ConfigParser<TResponse extends EmptyObject> {\n\t/**\n\t * Creates a new ConfigParser instance.\n\t *\n\t * @param config - The configuration object to parse\n\t * @param envVars - Set of environment variable names that were accessed\n\t */\n\tconstructor(\n\t\tprivate readonly config: TResponse,\n\t\tprivate readonly envVars: Set<string> = new Set(),\n\t) {}\n\t/**\n\t * Parses the config object and validates it against the Zod schemas\n\t * @returns The parsed config object\n\t */\n\tparse(): InferConfig<TResponse> {\n\t\tconst errors: z.core.$ZodIssue[] = [];\n\n\t\tconst parseDeep = <T>(config: T, path: string[] = []) => {\n\t\t\tconst result: EmptyObject = {};\n\n\t\t\tif (config && typeof config !== 'object') {\n\t\t\t\treturn config;\n\t\t\t}\n\n\t\t\tfor (const key in config) {\n\t\t\t\tconst schema = config[key];\n\t\t\t\tconst currentPath = [...path, key];\n\n\t\t\t\tif (schema instanceof z.ZodType) {\n\t\t\t\t\tconst parsed = schema.safeParse(undefined);\n\t\t\t\t\tif (parsed.success) {\n\t\t\t\t\t\tset(result, key, parsed.data);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If the schema is invalid, assign the error\n\t\t\t\t\t\terrors.push(\n\t\t\t\t\t\t\t...parsed.error.issues.map((issue) => ({\n\t\t\t\t\t\t\t\t...issue,\n\t\t\t\t\t\t\t\tpath: [...currentPath, ...(issue.path as string[])],\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else if (schema) {\n\t\t\t\t\tset(result, key, parseDeep(schema as EmptyObject, currentPath));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn result;\n\t\t};\n\n\t\tconst parsedConfig = parseDeep(\n\t\t\tthis.config,\n\t\t) as unknown as InferConfig<TResponse>;\n\n\t\tif (errors.length > 0) {\n\t\t\tconst zodError = new z.ZodError(errors);\n\t\t\t// In development, log a formatted error message before throwing\n\t\t\tif (isDevelopment()) {\n\t\t\t\tconsole.error(formatParseError(zodError));\n\t\t\t}\n\t\t\tthrow zodError;\n\t\t}\n\n\t\treturn parsedConfig;\n\t}\n\n\t/**\n\t * Returns an array of environment variable names that were accessed during config creation.\n\t * This is useful for deployment and configuration management to know which env vars are required.\n\t *\n\t * @returns Array of environment variable names, sorted alphabetically\n\t *\n\t * @example\n\t * ```typescript\n\t * const config = envParser.create((get) => ({\n\t * dbUrl: get('DATABASE_URL').string(),\n\t * port: get('PORT').number()\n\t * }));\n\t *\n\t * config.getEnvironmentVariables(); // ['DATABASE_URL', 'PORT']\n\t * ```\n\t */\n\tgetEnvironmentVariables(): string[] {\n\t\treturn Array.from(this.envVars).sort();\n\t}\n}\n\n/**\n * Parses environment variables with type-safe validation using Zod schemas.\n * Provides a fluent API for defining environment variable schemas with automatic\n * error context enrichment.\n *\n * @template T - The type of the configuration object (typically process.env)\n *\n * @example\n * ```typescript\n * const config = new EnvironmentParser(process.env)\n * .create((get) => ({\n * port: get('PORT').string().transform(Number).default(3000),\n * database: {\n * url: get('DATABASE_URL').string().url()\n * }\n * }))\n * .parse();\n * ```\n */\nexport class EnvironmentParser<T extends EmptyObject> {\n\t/**\n\t * Set to track which environment variable names have been accessed\n\t */\n\tprivate readonly accessedVars: Set<string> = new Set();\n\n\t/**\n\t * Creates a new EnvironmentParser instance.\n\t *\n\t * @param config - The configuration object to parse (typically process.env)\n\t */\n\tconstructor(private readonly config: T) {}\n\n\t/**\n\t * Wraps a Zod schema to intercept parse/safeParse calls and enrich error messages\n\t * with environment variable context.\n\t *\n\t * @param schema - The Zod schema to wrap\n\t * @param name - The environment variable name for error context\n\t * @returns A wrapped Zod schema with enhanced error reporting\n\t */\n\tprivate wrapSchema = (schema: z.ZodType, name: string): z.ZodType => {\n\t\t// Create a proxy that intercepts all method calls on the schema\n\t\treturn new Proxy(schema, {\n\t\t\tget: (target, prop) => {\n\t\t\t\tif (prop === 'parse') {\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tconst value = get(this.config, name);\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\treturn target.parse(value);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tif (error instanceof z.ZodError) {\n\t\t\t\t\t\t\t\t// Modify the error to include the environment variable name\n\t\t\t\t\t\t\t\tconst modifiedIssues = error.issues.map((issue) => ({\n\t\t\t\t\t\t\t\t\t...issue,\n\t\t\t\t\t\t\t\t\tmessage: `Environment variable \"${name}\": ${issue.message}`,\n\t\t\t\t\t\t\t\t\tpath: [name, ...issue.path],\n\t\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t\t\tthrow new z.ZodError(modifiedIssues);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tif (prop === 'safeParse') {\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tconst value = get(this.config, name);\n\t\t\t\t\t\tconst result = target.safeParse(value);\n\n\t\t\t\t\t\tif (!result.success) {\n\t\t\t\t\t\t\t// Modify the error to include the environment variable name\n\t\t\t\t\t\t\tconst modifiedIssues = result.error.issues.map(\n\t\t\t\t\t\t\t\t(issue: z.core.$ZodIssue) => ({\n\t\t\t\t\t\t\t\t\t...issue,\n\t\t\t\t\t\t\t\t\tmessage: `Environment variable \"${name}\": ${issue.message}`,\n\t\t\t\t\t\t\t\t\tpath: [name, ...issue.path],\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tsuccess: false as const,\n\t\t\t\t\t\t\t\terror: new z.ZodError(modifiedIssues),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\t// For any method that returns a new schema (like transform, optional, etc.),\n\t\t\t\t// wrap the result as well\n\t\t\t\tconst originalProp = target[prop as keyof typeof target];\n\t\t\t\tif (typeof originalProp === 'function') {\n\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\tconst result = originalProp.apply(target, args);\n\t\t\t\t\t\t// If the result is a ZodType, wrap it too\n\t\t\t\t\t\tif (result && typeof result === 'object' && 'parse' in result) {\n\t\t\t\t\t\t\treturn this.wrapSchema(result, name);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn originalProp;\n\t\t\t},\n\t\t});\n\t};\n\n\t/**\n\t * Creates a proxied version of the Zod object that wraps all schema creators\n\t * to provide enhanced error messages with environment variable context.\n\t *\n\t * @param name - The environment variable name\n\t * @returns A proxied Zod object with wrapped schema creators\n\t */\n\tprivate getZodGetter = (name: string) => {\n\t\t// Track that this environment variable was accessed\n\t\tthis.accessedVars.add(name);\n\n\t\t// Return an object that has all Zod schemas but with our wrapper\n\t\treturn new Proxy(\n\t\t\t{ ...z },\n\t\t\t{\n\t\t\t\tget: (target, prop) => {\n\t\t\t\t\t// deno-lint-ignore ban-ts-comment\n\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\tconst value = target[prop];\n\n\t\t\t\t\tif (typeof value === 'function') {\n\t\t\t\t\t\t// Return a wrapper around each Zod schema creator\n\t\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\t\tconst schema = value(...args);\n\t\t\t\t\t\t\treturn this.wrapSchema(schema, name);\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\t// Handle objects like z.coerce\n\t\t\t\t\tif (value && typeof value === 'object') {\n\t\t\t\t\t\treturn new Proxy(value, {\n\t\t\t\t\t\t\tget: (nestedTarget, nestedProp) => {\n\t\t\t\t\t\t\t\tconst nestedValue =\n\t\t\t\t\t\t\t\t\tnestedTarget[nestedProp as keyof typeof nestedTarget];\n\t\t\t\t\t\t\t\tif (typeof nestedValue === 'function') {\n\t\t\t\t\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\t\t\t\t\tconst schema = nestedValue(...args);\n\t\t\t\t\t\t\t\t\t\treturn this.wrapSchema(schema, name);\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn nestedValue;\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\treturn value;\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t};\n\n\t/**\n\t * Creates a new ConfigParser object that can be used to parse the config object\n\t *\n\t * @param builder - A function that takes a getter function and returns a config object\n\t * @returns A ConfigParser object that can be used to parse the config object\n\t */\n\tcreate<TReturn extends EmptyObject>(\n\t\tbuilder: (get: EnvFetcher) => TReturn,\n\t): ConfigParser<TReturn> {\n\t\tconst config = builder(this.getZodGetter);\n\t\treturn new ConfigParser(config, this.accessedVars);\n\t}\n\n\t/**\n\t * Returns an array of environment variable names that were accessed via the getter.\n\t * This is useful for build-time analysis to determine which env vars a service needs.\n\t *\n\t * @returns Array of environment variable names, sorted alphabetically\n\t *\n\t * @example\n\t * ```typescript\n\t * const sniffer = new EnvironmentParser({});\n\t * service.register(sniffer);\n\t * const envVars = sniffer.getEnvironmentVariables(); // ['DATABASE_URL', 'PORT']\n\t * ```\n\t */\n\tgetEnvironmentVariables(): string[] {\n\t\treturn Array.from(this.accessedVars).sort();\n\t}\n}\n\n/**\n * Infers the TypeScript type of a configuration object based on its Zod schemas.\n * Recursively processes nested objects and extracts types from Zod schemas.\n *\n * @template T - The configuration object type\n */\nexport type InferConfig<T extends EmptyObject> = {\n\t[K in keyof T]: T[K] extends z.ZodSchema\n\t\t? z.infer<T[K]>\n\t\t: T[K] extends Record<string, unknown>\n\t\t\t? InferConfig<T[K]>\n\t\t\t: T[K];\n};\n\n/**\n * Function type for fetching environment variables with Zod validation.\n * Returns a Zod object scoped to a specific environment variable.\n *\n * @template TPath - The environment variable path type\n * @param name - The environment variable name\n * @returns A Zod object for defining the schema\n */\nexport type EnvFetcher<TPath extends string = string> = (\n\tname: TPath,\n) => typeof z;\n\n/**\n * Function type for building environment configuration objects.\n * Takes an EnvFetcher and returns a configuration object with Zod schemas.\n *\n * @template TResponse - The response configuration object type\n * @param get - The environment variable fetcher function\n * @returns The configuration object with Zod schemas\n */\nexport type EnvironmentBuilder<TResponse extends EmptyObject> = (\n\tget: EnvFetcher,\n) => TResponse;\n\n/**\n * Type alias for a generic object with unknown values.\n * Used as a constraint for configu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GAGtB,MAAM,QAAQ,OAAO;AAErB,cAAW,UAAU,WAEpB,QAAO,CAAC,GAAG,SAAgB;IAC1B,MAAM,SAAS,MAAM,GAAG,KAAK;AAC7B,WAAO,KAAK,WAAW,QAAQ,KAAK;GACpC;AAIF,OAAI,gBAAgB,UAAU,SAC7B,QAAO,IAAI,MAAM,OAAO,EACvB,KAAK,CAAC,cAAc,eAAe;IAClC,MAAM,cACL,aAAa;AACd,eAAW,gBAAgB,WAC1B,QAAO,CAAC,GAAG,SAAgB;KAC1B,MAAM,SAAS,YAAY,GAAG,KAAK;AACnC,YAAO,KAAK,WAAW,QAAQ,KAAK;IACpC;AAEF,WAAO;GACP,EACD;AAGF,UAAO;EACP,EACD;CAEF;;;;;;;CAQD,OACCE,SACwB;EACxB,MAAM,SAAS,QAAQ,KAAK,aAAa;AACzC,SAAO,IAAI,aAAa,QAAQ,KAAK;CACrC;;;;;;;;;;;;;;CAeD,0BAAoC;AACnC,SAAO,MAAM,KAAK,KAAK,aAAa,CAAC,MAAM;CAC3C;AACD"}
|
|
@@ -144,4 +144,4 @@ type EmptyObject = Record<string | number | symbol, unknown>;
|
|
|
144
144
|
//# sourceMappingURL=EnvironmentParser.d.ts.map
|
|
145
145
|
//#endregion
|
|
146
146
|
export { ConfigParser, EmptyObject, EnvFetcher, EnvironmentBuilder, EnvironmentParser, InferConfig };
|
|
147
|
-
//# sourceMappingURL=EnvironmentParser-
|
|
147
|
+
//# sourceMappingURL=EnvironmentParser-CkLfmn4Y.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnvironmentParser-
|
|
1
|
+
{"version":3,"file":"EnvironmentParser-CkLfmn4Y.d.mts","names":[],"sources":["../src/EnvironmentParser.ts"],"sourcesContent":[],"mappings":";;;;;;AAWA;;;;AAS4B,cATf,YASe,CAAA,kBATgB,WAShB,CAAA,CAAA;EAAG,iBAMT,MAAA;EAAS,iBAArB,OAAA;EAAW;AA2FrB;;;;;EAiJmC,WAClB,CAAA,MAAA,EApPU,SAoPV,EAAA,OAAA,CAAA,EAnPW,GAmPX,CAAA,MAAA,CAAA;EAAU;;;AACX;EA6BJ,KAAA,CAAA,CAAA,EA3QF,WA2Qa,CA3QD,SA2QC,CAAA;EAAA;;;;;;;;;;;;;;;;EAKjB,uBAAC,CAAA,CAAA,EAAA,MAAA,EAAA;AAAC;AAWR;;;;AAEa;AAUb;;;;;AAEc;AAMd;;;;;;;;cApNa,4BAA4B;;;;;;;;;;;sBAWH;;;;;;;;;;;;;;;;;;;;;;;;yBAsId,4BACP,eAAe,UAC5B,aAAa;;;;;;;;;;;;;;;;;;;;;;KA6BL,sBAAsB,6BACrB,IAAI,EAAE,WAAW,CAAA,CAAE,YAC5B,CAAA,CAAE,MAAM,EAAE,MACV,EAAE,WAAW,0BACZ,YAAY,EAAE,MACd,EAAE;;;;;;;;;KAWK,mDACL,iBACK;;;;;;;;;KAUA,qCAAqC,qBAC3C,eACD;;;;;KAMO,WAAA,GAAc"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const require_formatter = require('./formatter-w8Tsccw4.cjs');
|
|
2
3
|
const lodash_get = require_chunk.__toESM(require("lodash.get"));
|
|
3
4
|
const lodash_set = require_chunk.__toESM(require("lodash.set"));
|
|
4
5
|
const zod_v4 = require_chunk.__toESM(require("zod/v4"));
|
|
@@ -45,7 +46,11 @@ var ConfigParser = class {
|
|
|
45
46
|
return result;
|
|
46
47
|
};
|
|
47
48
|
const parsedConfig = parseDeep(this.config);
|
|
48
|
-
if (errors.length > 0)
|
|
49
|
+
if (errors.length > 0) {
|
|
50
|
+
const zodError = new zod_v4.z.ZodError(errors);
|
|
51
|
+
if (require_formatter.isDevelopment()) console.error(require_formatter.formatParseError(zodError));
|
|
52
|
+
throw zodError;
|
|
53
|
+
}
|
|
49
54
|
return parsedConfig;
|
|
50
55
|
}
|
|
51
56
|
/**
|
|
@@ -218,4 +223,4 @@ Object.defineProperty(exports, 'EnvironmentParser', {
|
|
|
218
223
|
return EnvironmentParser;
|
|
219
224
|
}
|
|
220
225
|
});
|
|
221
|
-
//# sourceMappingURL=EnvironmentParser-
|
|
226
|
+
//# sourceMappingURL=EnvironmentParser-DlWHnhDY.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnvironmentParser-DlWHnhDY.cjs","names":["config: TResponse","envVars: Set<string>","errors: z.core.$ZodIssue[]","config: T","path: string[]","result: EmptyObject","z","schema: z.ZodType","name: string","issue: z.core.$ZodIssue","builder: (get: EnvFetcher) => TReturn"],"sources":["../src/EnvironmentParser.ts"],"sourcesContent":["import get from 'lodash.get';\nimport set from 'lodash.set';\nimport { z } from 'zod/v4';\nimport { formatParseError, isDevelopment } from './formatter.js';\n\n/**\n * Parses and validates configuration objects against Zod schemas.\n * Handles nested configurations and aggregates validation errors.\n *\n * @template TResponse - The shape of the configuration object\n */\nexport class ConfigParser<TResponse extends EmptyObject> {\n\t/**\n\t * Creates a new ConfigParser instance.\n\t *\n\t * @param config - The configuration object to parse\n\t * @param envVars - Set of environment variable names that were accessed\n\t */\n\tconstructor(\n\t\tprivate readonly config: TResponse,\n\t\tprivate readonly envVars: Set<string> = new Set(),\n\t) {}\n\t/**\n\t * Parses the config object and validates it against the Zod schemas\n\t * @returns The parsed config object\n\t */\n\tparse(): InferConfig<TResponse> {\n\t\tconst errors: z.core.$ZodIssue[] = [];\n\n\t\tconst parseDeep = <T>(config: T, path: string[] = []) => {\n\t\t\tconst result: EmptyObject = {};\n\n\t\t\tif (config && typeof config !== 'object') {\n\t\t\t\treturn config;\n\t\t\t}\n\n\t\t\tfor (const key in config) {\n\t\t\t\tconst schema = config[key];\n\t\t\t\tconst currentPath = [...path, key];\n\n\t\t\t\tif (schema instanceof z.ZodType) {\n\t\t\t\t\tconst parsed = schema.safeParse(undefined);\n\t\t\t\t\tif (parsed.success) {\n\t\t\t\t\t\tset(result, key, parsed.data);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If the schema is invalid, assign the error\n\t\t\t\t\t\terrors.push(\n\t\t\t\t\t\t\t...parsed.error.issues.map((issue) => ({\n\t\t\t\t\t\t\t\t...issue,\n\t\t\t\t\t\t\t\tpath: [...currentPath, ...(issue.path as string[])],\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else if (schema) {\n\t\t\t\t\tset(result, key, parseDeep(schema as EmptyObject, currentPath));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn result;\n\t\t};\n\n\t\tconst parsedConfig = parseDeep(\n\t\t\tthis.config,\n\t\t) as unknown as InferConfig<TResponse>;\n\n\t\tif (errors.length > 0) {\n\t\t\tconst zodError = new z.ZodError(errors);\n\t\t\t// In development, log a formatted error message before throwing\n\t\t\tif (isDevelopment()) {\n\t\t\t\tconsole.error(formatParseError(zodError));\n\t\t\t}\n\t\t\tthrow zodError;\n\t\t}\n\n\t\treturn parsedConfig;\n\t}\n\n\t/**\n\t * Returns an array of environment variable names that were accessed during config creation.\n\t * This is useful for deployment and configuration management to know which env vars are required.\n\t *\n\t * @returns Array of environment variable names, sorted alphabetically\n\t *\n\t * @example\n\t * ```typescript\n\t * const config = envParser.create((get) => ({\n\t * dbUrl: get('DATABASE_URL').string(),\n\t * port: get('PORT').number()\n\t * }));\n\t *\n\t * config.getEnvironmentVariables(); // ['DATABASE_URL', 'PORT']\n\t * ```\n\t */\n\tgetEnvironmentVariables(): string[] {\n\t\treturn Array.from(this.envVars).sort();\n\t}\n}\n\n/**\n * Parses environment variables with type-safe validation using Zod schemas.\n * Provides a fluent API for defining environment variable schemas with automatic\n * error context enrichment.\n *\n * @template T - The type of the configuration object (typically process.env)\n *\n * @example\n * ```typescript\n * const config = new EnvironmentParser(process.env)\n * .create((get) => ({\n * port: get('PORT').string().transform(Number).default(3000),\n * database: {\n * url: get('DATABASE_URL').string().url()\n * }\n * }))\n * .parse();\n * ```\n */\nexport class EnvironmentParser<T extends EmptyObject> {\n\t/**\n\t * Set to track which environment variable names have been accessed\n\t */\n\tprivate readonly accessedVars: Set<string> = new Set();\n\n\t/**\n\t * Creates a new EnvironmentParser instance.\n\t *\n\t * @param config - The configuration object to parse (typically process.env)\n\t */\n\tconstructor(private readonly config: T) {}\n\n\t/**\n\t * Wraps a Zod schema to intercept parse/safeParse calls and enrich error messages\n\t * with environment variable context.\n\t *\n\t * @param schema - The Zod schema to wrap\n\t * @param name - The environment variable name for error context\n\t * @returns A wrapped Zod schema with enhanced error reporting\n\t */\n\tprivate wrapSchema = (schema: z.ZodType, name: string): z.ZodType => {\n\t\t// Create a proxy that intercepts all method calls on the schema\n\t\treturn new Proxy(schema, {\n\t\t\tget: (target, prop) => {\n\t\t\t\tif (prop === 'parse') {\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tconst value = get(this.config, name);\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\treturn target.parse(value);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tif (error instanceof z.ZodError) {\n\t\t\t\t\t\t\t\t// Modify the error to include the environment variable name\n\t\t\t\t\t\t\t\tconst modifiedIssues = error.issues.map((issue) => ({\n\t\t\t\t\t\t\t\t\t...issue,\n\t\t\t\t\t\t\t\t\tmessage: `Environment variable \"${name}\": ${issue.message}`,\n\t\t\t\t\t\t\t\t\tpath: [name, ...issue.path],\n\t\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t\t\tthrow new z.ZodError(modifiedIssues);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tif (prop === 'safeParse') {\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tconst value = get(this.config, name);\n\t\t\t\t\t\tconst result = target.safeParse(value);\n\n\t\t\t\t\t\tif (!result.success) {\n\t\t\t\t\t\t\t// Modify the error to include the environment variable name\n\t\t\t\t\t\t\tconst modifiedIssues = result.error.issues.map(\n\t\t\t\t\t\t\t\t(issue: z.core.$ZodIssue) => ({\n\t\t\t\t\t\t\t\t\t...issue,\n\t\t\t\t\t\t\t\t\tmessage: `Environment variable \"${name}\": ${issue.message}`,\n\t\t\t\t\t\t\t\t\tpath: [name, ...issue.path],\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tsuccess: false as const,\n\t\t\t\t\t\t\t\terror: new z.ZodError(modifiedIssues),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\t// For any method that returns a new schema (like transform, optional, etc.),\n\t\t\t\t// wrap the result as well\n\t\t\t\tconst originalProp = target[prop as keyof typeof target];\n\t\t\t\tif (typeof originalProp === 'function') {\n\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\tconst result = originalProp.apply(target, args);\n\t\t\t\t\t\t// If the result is a ZodType, wrap it too\n\t\t\t\t\t\tif (result && typeof result === 'object' && 'parse' in result) {\n\t\t\t\t\t\t\treturn this.wrapSchema(result, name);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn originalProp;\n\t\t\t},\n\t\t});\n\t};\n\n\t/**\n\t * Creates a proxied version of the Zod object that wraps all schema creators\n\t * to provide enhanced error messages with environment variable context.\n\t *\n\t * @param name - The environment variable name\n\t * @returns A proxied Zod object with wrapped schema creators\n\t */\n\tprivate getZodGetter = (name: string) => {\n\t\t// Track that this environment variable was accessed\n\t\tthis.accessedVars.add(name);\n\n\t\t// Return an object that has all Zod schemas but with our wrapper\n\t\treturn new Proxy(\n\t\t\t{ ...z },\n\t\t\t{\n\t\t\t\tget: (target, prop) => {\n\t\t\t\t\t// deno-lint-ignore ban-ts-comment\n\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\tconst value = target[prop];\n\n\t\t\t\t\tif (typeof value === 'function') {\n\t\t\t\t\t\t// Return a wrapper around each Zod schema creator\n\t\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\t\tconst schema = value(...args);\n\t\t\t\t\t\t\treturn this.wrapSchema(schema, name);\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\t// Handle objects like z.coerce\n\t\t\t\t\tif (value && typeof value === 'object') {\n\t\t\t\t\t\treturn new Proxy(value, {\n\t\t\t\t\t\t\tget: (nestedTarget, nestedProp) => {\n\t\t\t\t\t\t\t\tconst nestedValue =\n\t\t\t\t\t\t\t\t\tnestedTarget[nestedProp as keyof typeof nestedTarget];\n\t\t\t\t\t\t\t\tif (typeof nestedValue === 'function') {\n\t\t\t\t\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\t\t\t\t\tconst schema = nestedValue(...args);\n\t\t\t\t\t\t\t\t\t\treturn this.wrapSchema(schema, name);\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn nestedValue;\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\treturn value;\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t};\n\n\t/**\n\t * Creates a new ConfigParser object that can be used to parse the config object\n\t *\n\t * @param builder - A function that takes a getter function and returns a config object\n\t * @returns A ConfigParser object that can be used to parse the config object\n\t */\n\tcreate<TReturn extends EmptyObject>(\n\t\tbuilder: (get: EnvFetcher) => TReturn,\n\t): ConfigParser<TReturn> {\n\t\tconst config = builder(this.getZodGetter);\n\t\treturn new ConfigParser(config, this.accessedVars);\n\t}\n\n\t/**\n\t * Returns an array of environment variable names that were accessed via the getter.\n\t * This is useful for build-time analysis to determine which env vars a service needs.\n\t *\n\t * @returns Array of environment variable names, sorted alphabetically\n\t *\n\t * @example\n\t * ```typescript\n\t * const sniffer = new EnvironmentParser({});\n\t * service.register(sniffer);\n\t * const envVars = sniffer.getEnvironmentVariables(); // ['DATABASE_URL', 'PORT']\n\t * ```\n\t */\n\tgetEnvironmentVariables(): string[] {\n\t\treturn Array.from(this.accessedVars).sort();\n\t}\n}\n\n/**\n * Infers the TypeScript type of a configuration object based on its Zod schemas.\n * Recursively processes nested objects and extracts types from Zod schemas.\n *\n * @template T - The configuration object type\n */\nexport type InferConfig<T extends EmptyObject> = {\n\t[K in keyof T]: T[K] extends z.ZodSchema\n\t\t? z.infer<T[K]>\n\t\t: T[K] extends Record<string, unknown>\n\t\t\t? InferConfig<T[K]>\n\t\t\t: T[K];\n};\n\n/**\n * Function type for fetching environment variables with Zod validation.\n * Returns a Zod object scoped to a specific environment variable.\n *\n * @template TPath - The environment variable path type\n * @param name - The environment variable name\n * @returns A Zod object for defining the schema\n */\nexport type EnvFetcher<TPath extends string = string> = (\n\tname: TPath,\n) => typeof z;\n\n/**\n * Function type for building environment configuration objects.\n * Takes an EnvFetcher and returns a configuration object with Zod schemas.\n *\n * @template TResponse - The response configuration object type\n * @param get - The environment variable fetcher function\n * @returns The configuration object with Zod schemas\n */\nexport type EnvironmentBuilder<TResponse extends EmptyObject> = (\n\tget: EnvFetcher,\n) => TResponse;\n\n/**\n * Type alias for a generic object with unknown values.\n * Used as a constraint for configuration objects.\n */\nexport type EmptyObject = Record<string | number | symbol, unknown>;\n"],"mappings":";;;;;;;;;;;;;AAWA,IAAa,eAAb,MAAyD;;;;;;;CAOxD,YACkBA,QACAC,0BAAuB,IAAI,OAC3C;EAFgB;EACA;CACd;;;;;CAKJ,QAAgC;EAC/B,MAAMC,SAA6B,CAAE;EAErC,MAAM,YAAY,CAAIC,QAAWC,OAAiB,CAAE,MAAK;GACxD,MAAMC,SAAsB,CAAE;AAE9B,OAAI,iBAAiB,WAAW,SAC/B,QAAO;AAGR,QAAK,MAAM,OAAO,QAAQ;IACzB,MAAM,SAAS,OAAO;IACtB,MAAM,cAAc,CAAC,GAAG,MAAM,GAAI;AAElC,Q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P,EACD;AAGF,UAAO;EACP,EACD;CAEF;;;;;;;CAQD,OACCI,SACwB;EACxB,MAAM,SAAS,QAAQ,KAAK,aAAa;AACzC,SAAO,IAAI,aAAa,QAAQ,KAAK;CACrC;;;;;;;;;;;;;;CAeD,0BAAoC;AACnC,SAAO,MAAM,KAAK,KAAK,aAAa,CAAC,MAAM;CAC3C;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnvironmentParser-DtOL86NU.d.cts","names":[],"sources":["../src/EnvironmentParser.ts"],"sourcesContent":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"EnvironmentParser-DtOL86NU.d.cts","names":[],"sources":["../src/EnvironmentParser.ts"],"sourcesContent":[],"mappings":";;;;;;AAWA;;;;AAS4B,cATf,YASe,CAAA,kBATgB,WAShB,CAAA,CAAA;EAAG,iBAMT,MAAA;EAAS,iBAArB,OAAA;EAAW;AA2FrB;;;;;EAiJmC,WAClB,CAAA,MAAA,EApPU,SAoPV,EAAA,OAAA,CAAA,EAnPW,GAmPX,CAAA,MAAA,CAAA;EAAU;;;AACX;EA6BJ,KAAA,CAAA,CAAA,EA3QF,WA2Qa,CA3QD,SA2QC,CAAA;EAAA;;;;;;;;;;;;;;;;EAKjB,uBAAC,CAAA,CAAA,EAAA,MAAA,EAAA;AAAC;AAWR;;;;AAEa;AAUb;;;;;AAEc;AAMd;;;;;;;;cApNa,4BAA4B;;;;;;;;;;;sBAWH;;;;;;;;;;;;;;;;;;;;;;;;yBAsId,4BACP,eAAe,UAC5B,aAAa;;;;;;;;;;;;;;;;;;;;;;KA6BL,sBAAsB,6BACrB,IAAI,EAAE,WAAW,CAAA,CAAE,YAC5B,CAAA,CAAE,MAAM,EAAE,MACV,EAAE,WAAW,0BACZ,YAAY,EAAE,MACd,EAAE;;;;;;;;;KAWK,mDACL,iBACK;;;;;;;;;KAUA,qCAAqC,qBAC3C,eACD;;;;;KAMO,WAAA,GAAc"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
require('./formatter-w8Tsccw4.cjs');
|
|
2
|
+
const require_EnvironmentParser = require('./EnvironmentParser-DlWHnhDY.cjs');
|
|
2
3
|
|
|
3
4
|
exports.ConfigParser = require_EnvironmentParser.ConfigParser;
|
|
4
5
|
exports.EnvironmentParser = require_EnvironmentParser.EnvironmentParser;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ConfigParser, EmptyObject, EnvFetcher, EnvironmentBuilder, EnvironmentParser, InferConfig } from "./EnvironmentParser-
|
|
1
|
+
import { ConfigParser, EmptyObject, EnvFetcher, EnvironmentBuilder, EnvironmentParser, InferConfig } from "./EnvironmentParser-CkLfmn4Y.mjs";
|
|
2
2
|
export { ConfigParser, EmptyObject, EnvFetcher, EnvironmentBuilder, EnvironmentParser, InferConfig };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
|
|
2
|
+
require('./formatter-w8Tsccw4.cjs');
|
|
3
|
+
const require_EnvironmentParser = require('./EnvironmentParser-DlWHnhDY.cjs');
|
|
3
4
|
const zod_v4 = require_chunk.__toESM(require("zod/v4"));
|
|
4
5
|
|
|
5
6
|
//#region src/SnifferEnvironmentParser.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SnifferEnvironmentParser.cjs","names":["schema: z.ZodType","name: string","z","result: Record<string, unknown>","builder: (get: EnvFetcher) => TReturn","ConfigParser","config: T","result: EmptyObject"],"sources":["../src/SnifferEnvironmentParser.ts"],"sourcesContent":["import { z } from 'zod/v4';\nimport {\n\tConfigParser,\n\ttype EmptyObject,\n\ttype EnvFetcher,\n} from './EnvironmentParser';\n\n/**\n * A specialized EnvironmentParser for build-time analysis that tracks\n * which environment variables are accessed without requiring actual values.\n *\n * Unlike the regular EnvironmentParser, the sniffer:\n * - Always returns mock values from .parse() and .safeParse()\n * - Never throws validation errors\n * - Tracks all accessed environment variable names\n *\n * This allows service registration to succeed during build-time analysis\n * even when environment variables are not set.\n *\n * @example\n * ```typescript\n * const sniffer = new SnifferEnvironmentParser();\n * await service.register(sniffer); // Always succeeds\n * const envVars = sniffer.getEnvironmentVariables(); // ['DATABASE_URL', 'API_KEY']\n * ```\n */\nexport class SnifferEnvironmentParser<_T extends EmptyObject = EmptyObject> {\n\tprivate readonly accessedVars: Set<string> = new Set();\n\n\t/**\n\t * Wraps a Zod schema to always return mock values.\n\t * This ensures .parse() and .safeParse() never fail.\n\t */\n\tprivate wrapSchema = (schema: z.ZodType, name: string): z.ZodType => {\n\t\treturn new Proxy(schema, {\n\t\t\tget: (target, prop) => {\n\t\t\t\tif (prop === 'parse') {\n\t\t\t\t\treturn () => this.getMockValue(target);\n\t\t\t\t}\n\n\t\t\t\tif (prop === 'safeParse') {\n\t\t\t\t\treturn () => ({\n\t\t\t\t\t\tsuccess: true as const,\n\t\t\t\t\t\tdata: this.getMockValue(target),\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tconst originalProp = target[prop as keyof typeof target];\n\t\t\t\tif (typeof originalProp === 'function') {\n\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\tconst result = originalProp.apply(target, args);\n\t\t\t\t\t\tif (result && typeof result === 'object' && 'parse' in result) {\n\t\t\t\t\t\t\treturn this.wrapSchema(result, name);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn originalProp;\n\t\t\t},\n\t\t});\n\t};\n\n\t/**\n\t * Returns a mock value based on the Zod schema type.\n\t */\n\tprivate getMockValue(schema: z.ZodType): unknown {\n\t\t// Return type-appropriate mock values\n\t\tif (schema instanceof z.ZodString) return '';\n\t\tif (schema instanceof z.ZodNumber) return 0;\n\t\tif (schema instanceof z.ZodBoolean) return false;\n\t\tif (schema instanceof z.ZodArray) return [];\n\t\tif (schema instanceof z.ZodOptional) return undefined;\n\t\tif (schema instanceof z.ZodNullable) return null;\n\n\t\t// For object schemas, build mock object from shape\n\t\tif (schema instanceof z.ZodObject && schema.shape) {\n\t\t\tconst result: Record<string, unknown> = {};\n\t\t\tfor (const [key, value] of Object.entries(schema.shape)) {\n\t\t\t\tif (value instanceof z.ZodType) {\n\t\t\t\t\tresult[key] = this.getMockValue(value);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\treturn '';\n\t}\n\n\t/**\n\t * Creates a proxied Zod getter that tracks environment variable access.\n\t */\n\tprivate getZodGetter = (name: string) => {\n\t\tthis.accessedVars.add(name);\n\n\t\treturn new Proxy(\n\t\t\t{ ...z },\n\t\t\t{\n\t\t\t\tget: (target, prop) => {\n\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\tconst value = target[prop];\n\n\t\t\t\t\tif (typeof value === 'function') {\n\t\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\t\tconst schema = value(...args);\n\t\t\t\t\t\t\treturn this.wrapSchema(schema, name);\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tif (value && typeof value === 'object') {\n\t\t\t\t\t\treturn new Proxy(value, {\n\t\t\t\t\t\t\tget: (nestedTarget, nestedProp) => {\n\t\t\t\t\t\t\t\tconst nestedValue =\n\t\t\t\t\t\t\t\t\tnestedTarget[nestedProp as keyof typeof nestedTarget];\n\t\t\t\t\t\t\t\tif (typeof nestedValue === 'function') {\n\t\t\t\t\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\t\t\t\t\tconst schema = nestedValue(...args);\n\t\t\t\t\t\t\t\t\t\treturn this.wrapSchema(schema, name);\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn nestedValue;\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\treturn value;\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t};\n\n\t/**\n\t * Creates a ConfigParser that will return mock values when parsed.\n\t */\n\tcreate<TReturn extends EmptyObject>(\n\t\tbuilder: (get: EnvFetcher) => TReturn,\n\t): ConfigParser<TReturn> {\n\t\tconst config = builder(this.getZodGetter);\n\t\treturn new SnifferConfigParser(config, this.accessedVars);\n\t}\n\n\t/**\n\t * Returns all environment variable names that were accessed.\n\t */\n\tgetEnvironmentVariables(): string[] {\n\t\treturn Array.from(this.accessedVars).sort();\n\t}\n}\n\n/**\n * A ConfigParser that always succeeds with mock values.\n */\nclass SnifferConfigParser<\n\tTResponse extends EmptyObject,\n> extends ConfigParser<TResponse> {\n\toverride parse(): any {\n\t\treturn this.parseWithMocks(this.getConfig());\n\t}\n\n\tprivate getConfig(): TResponse {\n\t\t// Access the private config via any cast\n\t\treturn (this as any).config;\n\t}\n\n\tprivate parseWithMocks<T>(config: T): any {\n\t\tconst result: EmptyObject = {};\n\n\t\tif (config && typeof config !== 'object') {\n\t\t\treturn config;\n\t\t}\n\n\t\tfor (const key in config) {\n\t\t\tconst schema = config[key];\n\n\t\t\tif (schema instanceof z.ZodType) {\n\t\t\t\t// Use safeParse which will return mock values from our wrapped schema\n\t\t\t\tconst parsed = schema.safeParse(undefined);\n\t\t\t\tresult[key] = parsed.success\n\t\t\t\t\t? parsed.data\n\t\t\t\t\t: this.getDefaultForSchema(schema);\n\t\t\t} else if (schema && typeof schema === 'object') {\n\t\t\t\tresult[key] = this.parseWithMocks(schema as EmptyObject);\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n\n\tprivate getDefaultForSchema(schema: z.ZodType): unknown {\n\t\tif (schema instanceof z.ZodString) return '';\n\t\tif (schema instanceof z.ZodNumber) return 0;\n\t\tif (schema instanceof z.ZodBoolean) return false;\n\t\tif (schema instanceof z.ZodArray) return [];\n\t\tif (schema instanceof z.ZodOptional) return undefined;\n\t\tif (schema instanceof z.ZodNullable) return null;\n\n\t\tif (schema instanceof z.ZodObject && schema.shape) {\n\t\t\tconst result: Record<string, unknown> = {};\n\t\t\tfor (const [key, value] of Object.entries(schema.shape)) {\n\t\t\t\tif (value instanceof z.ZodType) {\n\t\t\t\t\tresult[key] = this.getDefaultForSchema(value);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\treturn '';\n\t}\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"SnifferEnvironmentParser.cjs","names":["schema: z.ZodType","name: string","z","result: Record<string, unknown>","builder: (get: EnvFetcher) => TReturn","ConfigParser","config: T","result: EmptyObject"],"sources":["../src/SnifferEnvironmentParser.ts"],"sourcesContent":["import { z } from 'zod/v4';\nimport {\n\tConfigParser,\n\ttype EmptyObject,\n\ttype EnvFetcher,\n} from './EnvironmentParser';\n\n/**\n * A specialized EnvironmentParser for build-time analysis that tracks\n * which environment variables are accessed without requiring actual values.\n *\n * Unlike the regular EnvironmentParser, the sniffer:\n * - Always returns mock values from .parse() and .safeParse()\n * - Never throws validation errors\n * - Tracks all accessed environment variable names\n *\n * This allows service registration to succeed during build-time analysis\n * even when environment variables are not set.\n *\n * @example\n * ```typescript\n * const sniffer = new SnifferEnvironmentParser();\n * await service.register(sniffer); // Always succeeds\n * const envVars = sniffer.getEnvironmentVariables(); // ['DATABASE_URL', 'API_KEY']\n * ```\n */\nexport class SnifferEnvironmentParser<_T extends EmptyObject = EmptyObject> {\n\tprivate readonly accessedVars: Set<string> = new Set();\n\n\t/**\n\t * Wraps a Zod schema to always return mock values.\n\t * This ensures .parse() and .safeParse() never fail.\n\t */\n\tprivate wrapSchema = (schema: z.ZodType, name: string): z.ZodType => {\n\t\treturn new Proxy(schema, {\n\t\t\tget: (target, prop) => {\n\t\t\t\tif (prop === 'parse') {\n\t\t\t\t\treturn () => this.getMockValue(target);\n\t\t\t\t}\n\n\t\t\t\tif (prop === 'safeParse') {\n\t\t\t\t\treturn () => ({\n\t\t\t\t\t\tsuccess: true as const,\n\t\t\t\t\t\tdata: this.getMockValue(target),\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tconst originalProp = target[prop as keyof typeof target];\n\t\t\t\tif (typeof originalProp === 'function') {\n\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\tconst result = originalProp.apply(target, args);\n\t\t\t\t\t\tif (result && typeof result === 'object' && 'parse' in result) {\n\t\t\t\t\t\t\treturn this.wrapSchema(result, name);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn originalProp;\n\t\t\t},\n\t\t});\n\t};\n\n\t/**\n\t * Returns a mock value based on the Zod schema type.\n\t */\n\tprivate getMockValue(schema: z.ZodType): unknown {\n\t\t// Return type-appropriate mock values\n\t\tif (schema instanceof z.ZodString) return '';\n\t\tif (schema instanceof z.ZodNumber) return 0;\n\t\tif (schema instanceof z.ZodBoolean) return false;\n\t\tif (schema instanceof z.ZodArray) return [];\n\t\tif (schema instanceof z.ZodOptional) return undefined;\n\t\tif (schema instanceof z.ZodNullable) return null;\n\n\t\t// For object schemas, build mock object from shape\n\t\tif (schema instanceof z.ZodObject && schema.shape) {\n\t\t\tconst result: Record<string, unknown> = {};\n\t\t\tfor (const [key, value] of Object.entries(schema.shape)) {\n\t\t\t\tif (value instanceof z.ZodType) {\n\t\t\t\t\tresult[key] = this.getMockValue(value);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\treturn '';\n\t}\n\n\t/**\n\t * Creates a proxied Zod getter that tracks environment variable access.\n\t */\n\tprivate getZodGetter = (name: string) => {\n\t\tthis.accessedVars.add(name);\n\n\t\treturn new Proxy(\n\t\t\t{ ...z },\n\t\t\t{\n\t\t\t\tget: (target, prop) => {\n\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\tconst value = target[prop];\n\n\t\t\t\t\tif (typeof value === 'function') {\n\t\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\t\tconst schema = value(...args);\n\t\t\t\t\t\t\treturn this.wrapSchema(schema, name);\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tif (value && typeof value === 'object') {\n\t\t\t\t\t\treturn new Proxy(value, {\n\t\t\t\t\t\t\tget: (nestedTarget, nestedProp) => {\n\t\t\t\t\t\t\t\tconst nestedValue =\n\t\t\t\t\t\t\t\t\tnestedTarget[nestedProp as keyof typeof nestedTarget];\n\t\t\t\t\t\t\t\tif (typeof nestedValue === 'function') {\n\t\t\t\t\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\t\t\t\t\tconst schema = nestedValue(...args);\n\t\t\t\t\t\t\t\t\t\treturn this.wrapSchema(schema, name);\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn nestedValue;\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\treturn value;\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t};\n\n\t/**\n\t * Creates a ConfigParser that will return mock values when parsed.\n\t */\n\tcreate<TReturn extends EmptyObject>(\n\t\tbuilder: (get: EnvFetcher) => TReturn,\n\t): ConfigParser<TReturn> {\n\t\tconst config = builder(this.getZodGetter);\n\t\treturn new SnifferConfigParser(config, this.accessedVars);\n\t}\n\n\t/**\n\t * Returns all environment variable names that were accessed.\n\t */\n\tgetEnvironmentVariables(): string[] {\n\t\treturn Array.from(this.accessedVars).sort();\n\t}\n}\n\n/**\n * A ConfigParser that always succeeds with mock values.\n */\nclass SnifferConfigParser<\n\tTResponse extends EmptyObject,\n> extends ConfigParser<TResponse> {\n\toverride parse(): any {\n\t\treturn this.parseWithMocks(this.getConfig());\n\t}\n\n\tprivate getConfig(): TResponse {\n\t\t// Access the private config via any cast\n\t\treturn (this as any).config;\n\t}\n\n\tprivate parseWithMocks<T>(config: T): any {\n\t\tconst result: EmptyObject = {};\n\n\t\tif (config && typeof config !== 'object') {\n\t\t\treturn config;\n\t\t}\n\n\t\tfor (const key in config) {\n\t\t\tconst schema = config[key];\n\n\t\t\tif (schema instanceof z.ZodType) {\n\t\t\t\t// Use safeParse which will return mock values from our wrapped schema\n\t\t\t\tconst parsed = schema.safeParse(undefined);\n\t\t\t\tresult[key] = parsed.success\n\t\t\t\t\t? parsed.data\n\t\t\t\t\t: this.getDefaultForSchema(schema);\n\t\t\t} else if (schema && typeof schema === 'object') {\n\t\t\t\tresult[key] = this.parseWithMocks(schema as EmptyObject);\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n\n\tprivate getDefaultForSchema(schema: z.ZodType): unknown {\n\t\tif (schema instanceof z.ZodString) return '';\n\t\tif (schema instanceof z.ZodNumber) return 0;\n\t\tif (schema instanceof z.ZodBoolean) return false;\n\t\tif (schema instanceof z.ZodArray) return [];\n\t\tif (schema instanceof z.ZodOptional) return undefined;\n\t\tif (schema instanceof z.ZodNullable) return null;\n\n\t\tif (schema instanceof z.ZodObject && schema.shape) {\n\t\t\tconst result: Record<string, unknown> = {};\n\t\t\tfor (const [key, value] of Object.entries(schema.shape)) {\n\t\t\t\tif (value instanceof z.ZodType) {\n\t\t\t\t\tresult[key] = this.getDefaultForSchema(value);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\treturn '';\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAa,2BAAb,MAA4E;CAC3E,AAAiB,+BAA4B,IAAI;;;;;CAMjD,AAAQ,aAAa,CAACA,QAAmBC,SAA4B;AACpE,SAAO,IAAI,MAAM,QAAQ,EACxB,KAAK,CAAC,QAAQ,SAAS;AACtB,OAAI,SAAS,QACZ,QAAO,MAAM,KAAK,aAAa,OAAO;AAGvC,OAAI,SAAS,YACZ,QAAO,OAAO;IACb,SAAS;IACT,MAAM,KAAK,aAAa,OAAO;GAC/B;GAGF,MAAM,eAAe,OAAO;AAC5B,cAAW,iBAAiB,WAC3B,QAAO,CAAC,GAAG,SAAgB;IAC1B,MAAM,SAAS,aAAa,MAAM,QAAQ,KAAK;AAC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1 @@
|
|
|
1
|
-
{"version":3,"file":"SnifferEnvironmentParser.mjs","names":["schema: z.ZodType","name: string","result: Record<string, unknown>","builder: (get: EnvFetcher) => TReturn","config: T","result: EmptyObject"],"sources":["../src/SnifferEnvironmentParser.ts"],"sourcesContent":["import { z } from 'zod/v4';\nimport {\n\tConfigParser,\n\ttype EmptyObject,\n\ttype EnvFetcher,\n} from './EnvironmentParser';\n\n/**\n * A specialized EnvironmentParser for build-time analysis that tracks\n * which environment variables are accessed without requiring actual values.\n *\n * Unlike the regular EnvironmentParser, the sniffer:\n * - Always returns mock values from .parse() and .safeParse()\n * - Never throws validation errors\n * - Tracks all accessed environment variable names\n *\n * This allows service registration to succeed during build-time analysis\n * even when environment variables are not set.\n *\n * @example\n * ```typescript\n * const sniffer = new SnifferEnvironmentParser();\n * await service.register(sniffer); // Always succeeds\n * const envVars = sniffer.getEnvironmentVariables(); // ['DATABASE_URL', 'API_KEY']\n * ```\n */\nexport class SnifferEnvironmentParser<_T extends EmptyObject = EmptyObject> {\n\tprivate readonly accessedVars: Set<string> = new Set();\n\n\t/**\n\t * Wraps a Zod schema to always return mock values.\n\t * This ensures .parse() and .safeParse() never fail.\n\t */\n\tprivate wrapSchema = (schema: z.ZodType, name: string): z.ZodType => {\n\t\treturn new Proxy(schema, {\n\t\t\tget: (target, prop) => {\n\t\t\t\tif (prop === 'parse') {\n\t\t\t\t\treturn () => this.getMockValue(target);\n\t\t\t\t}\n\n\t\t\t\tif (prop === 'safeParse') {\n\t\t\t\t\treturn () => ({\n\t\t\t\t\t\tsuccess: true as const,\n\t\t\t\t\t\tdata: this.getMockValue(target),\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tconst originalProp = target[prop as keyof typeof target];\n\t\t\t\tif (typeof originalProp === 'function') {\n\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\tconst result = originalProp.apply(target, args);\n\t\t\t\t\t\tif (result && typeof result === 'object' && 'parse' in result) {\n\t\t\t\t\t\t\treturn this.wrapSchema(result, name);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn originalProp;\n\t\t\t},\n\t\t});\n\t};\n\n\t/**\n\t * Returns a mock value based on the Zod schema type.\n\t */\n\tprivate getMockValue(schema: z.ZodType): unknown {\n\t\t// Return type-appropriate mock values\n\t\tif (schema instanceof z.ZodString) return '';\n\t\tif (schema instanceof z.ZodNumber) return 0;\n\t\tif (schema instanceof z.ZodBoolean) return false;\n\t\tif (schema instanceof z.ZodArray) return [];\n\t\tif (schema instanceof z.ZodOptional) return undefined;\n\t\tif (schema instanceof z.ZodNullable) return null;\n\n\t\t// For object schemas, build mock object from shape\n\t\tif (schema instanceof z.ZodObject && schema.shape) {\n\t\t\tconst result: Record<string, unknown> = {};\n\t\t\tfor (const [key, value] of Object.entries(schema.shape)) {\n\t\t\t\tif (value instanceof z.ZodType) {\n\t\t\t\t\tresult[key] = this.getMockValue(value);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\treturn '';\n\t}\n\n\t/**\n\t * Creates a proxied Zod getter that tracks environment variable access.\n\t */\n\tprivate getZodGetter = (name: string) => {\n\t\tthis.accessedVars.add(name);\n\n\t\treturn new Proxy(\n\t\t\t{ ...z },\n\t\t\t{\n\t\t\t\tget: (target, prop) => {\n\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\tconst value = target[prop];\n\n\t\t\t\t\tif (typeof value === 'function') {\n\t\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\t\tconst schema = value(...args);\n\t\t\t\t\t\t\treturn this.wrapSchema(schema, name);\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tif (value && typeof value === 'object') {\n\t\t\t\t\t\treturn new Proxy(value, {\n\t\t\t\t\t\t\tget: (nestedTarget, nestedProp) => {\n\t\t\t\t\t\t\t\tconst nestedValue =\n\t\t\t\t\t\t\t\t\tnestedTarget[nestedProp as keyof typeof nestedTarget];\n\t\t\t\t\t\t\t\tif (typeof nestedValue === 'function') {\n\t\t\t\t\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\t\t\t\t\tconst schema = nestedValue(...args);\n\t\t\t\t\t\t\t\t\t\treturn this.wrapSchema(schema, name);\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn nestedValue;\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\treturn value;\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t};\n\n\t/**\n\t * Creates a ConfigParser that will return mock values when parsed.\n\t */\n\tcreate<TReturn extends EmptyObject>(\n\t\tbuilder: (get: EnvFetcher) => TReturn,\n\t): ConfigParser<TReturn> {\n\t\tconst config = builder(this.getZodGetter);\n\t\treturn new SnifferConfigParser(config, this.accessedVars);\n\t}\n\n\t/**\n\t * Returns all environment variable names that were accessed.\n\t */\n\tgetEnvironmentVariables(): string[] {\n\t\treturn Array.from(this.accessedVars).sort();\n\t}\n}\n\n/**\n * A ConfigParser that always succeeds with mock values.\n */\nclass SnifferConfigParser<\n\tTResponse extends EmptyObject,\n> extends ConfigParser<TResponse> {\n\toverride parse(): any {\n\t\treturn this.parseWithMocks(this.getConfig());\n\t}\n\n\tprivate getConfig(): TResponse {\n\t\t// Access the private config via any cast\n\t\treturn (this as any).config;\n\t}\n\n\tprivate parseWithMocks<T>(config: T): any {\n\t\tconst result: EmptyObject = {};\n\n\t\tif (config && typeof config !== 'object') {\n\t\t\treturn config;\n\t\t}\n\n\t\tfor (const key in config) {\n\t\t\tconst schema = config[key];\n\n\t\t\tif (schema instanceof z.ZodType) {\n\t\t\t\t// Use safeParse which will return mock values from our wrapped schema\n\t\t\t\tconst parsed = schema.safeParse(undefined);\n\t\t\t\tresult[key] = parsed.success\n\t\t\t\t\t? parsed.data\n\t\t\t\t\t: this.getDefaultForSchema(schema);\n\t\t\t} else if (schema && typeof schema === 'object') {\n\t\t\t\tresult[key] = this.parseWithMocks(schema as EmptyObject);\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n\n\tprivate getDefaultForSchema(schema: z.ZodType): unknown {\n\t\tif (schema instanceof z.ZodString) return '';\n\t\tif (schema instanceof z.ZodNumber) return 0;\n\t\tif (schema instanceof z.ZodBoolean) return false;\n\t\tif (schema instanceof z.ZodArray) return [];\n\t\tif (schema instanceof z.ZodOptional) return undefined;\n\t\tif (schema instanceof z.ZodNullable) return null;\n\n\t\tif (schema instanceof z.ZodObject && schema.shape) {\n\t\t\tconst result: Record<string, unknown> = {};\n\t\t\tfor (const [key, value] of Object.entries(schema.shape)) {\n\t\t\t\tif (value instanceof z.ZodType) {\n\t\t\t\t\tresult[key] = this.getDefaultForSchema(value);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\treturn '';\n\t}\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"SnifferEnvironmentParser.mjs","names":["schema: z.ZodType","name: string","result: Record<string, unknown>","builder: (get: EnvFetcher) => TReturn","config: T","result: EmptyObject"],"sources":["../src/SnifferEnvironmentParser.ts"],"sourcesContent":["import { z } from 'zod/v4';\nimport {\n\tConfigParser,\n\ttype EmptyObject,\n\ttype EnvFetcher,\n} from './EnvironmentParser';\n\n/**\n * A specialized EnvironmentParser for build-time analysis that tracks\n * which environment variables are accessed without requiring actual values.\n *\n * Unlike the regular EnvironmentParser, the sniffer:\n * - Always returns mock values from .parse() and .safeParse()\n * - Never throws validation errors\n * - Tracks all accessed environment variable names\n *\n * This allows service registration to succeed during build-time analysis\n * even when environment variables are not set.\n *\n * @example\n * ```typescript\n * const sniffer = new SnifferEnvironmentParser();\n * await service.register(sniffer); // Always succeeds\n * const envVars = sniffer.getEnvironmentVariables(); // ['DATABASE_URL', 'API_KEY']\n * ```\n */\nexport class SnifferEnvironmentParser<_T extends EmptyObject = EmptyObject> {\n\tprivate readonly accessedVars: Set<string> = new Set();\n\n\t/**\n\t * Wraps a Zod schema to always return mock values.\n\t * This ensures .parse() and .safeParse() never fail.\n\t */\n\tprivate wrapSchema = (schema: z.ZodType, name: string): z.ZodType => {\n\t\treturn new Proxy(schema, {\n\t\t\tget: (target, prop) => {\n\t\t\t\tif (prop === 'parse') {\n\t\t\t\t\treturn () => this.getMockValue(target);\n\t\t\t\t}\n\n\t\t\t\tif (prop === 'safeParse') {\n\t\t\t\t\treturn () => ({\n\t\t\t\t\t\tsuccess: true as const,\n\t\t\t\t\t\tdata: this.getMockValue(target),\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tconst originalProp = target[prop as keyof typeof target];\n\t\t\t\tif (typeof originalProp === 'function') {\n\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\tconst result = originalProp.apply(target, args);\n\t\t\t\t\t\tif (result && typeof result === 'object' && 'parse' in result) {\n\t\t\t\t\t\t\treturn this.wrapSchema(result, name);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn originalProp;\n\t\t\t},\n\t\t});\n\t};\n\n\t/**\n\t * Returns a mock value based on the Zod schema type.\n\t */\n\tprivate getMockValue(schema: z.ZodType): unknown {\n\t\t// Return type-appropriate mock values\n\t\tif (schema instanceof z.ZodString) return '';\n\t\tif (schema instanceof z.ZodNumber) return 0;\n\t\tif (schema instanceof z.ZodBoolean) return false;\n\t\tif (schema instanceof z.ZodArray) return [];\n\t\tif (schema instanceof z.ZodOptional) return undefined;\n\t\tif (schema instanceof z.ZodNullable) return null;\n\n\t\t// For object schemas, build mock object from shape\n\t\tif (schema instanceof z.ZodObject && schema.shape) {\n\t\t\tconst result: Record<string, unknown> = {};\n\t\t\tfor (const [key, value] of Object.entries(schema.shape)) {\n\t\t\t\tif (value instanceof z.ZodType) {\n\t\t\t\t\tresult[key] = this.getMockValue(value);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\treturn '';\n\t}\n\n\t/**\n\t * Creates a proxied Zod getter that tracks environment variable access.\n\t */\n\tprivate getZodGetter = (name: string) => {\n\t\tthis.accessedVars.add(name);\n\n\t\treturn new Proxy(\n\t\t\t{ ...z },\n\t\t\t{\n\t\t\t\tget: (target, prop) => {\n\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\tconst value = target[prop];\n\n\t\t\t\t\tif (typeof value === 'function') {\n\t\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\t\tconst schema = value(...args);\n\t\t\t\t\t\t\treturn this.wrapSchema(schema, name);\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tif (value && typeof value === 'object') {\n\t\t\t\t\t\treturn new Proxy(value, {\n\t\t\t\t\t\t\tget: (nestedTarget, nestedProp) => {\n\t\t\t\t\t\t\t\tconst nestedValue =\n\t\t\t\t\t\t\t\t\tnestedTarget[nestedProp as keyof typeof nestedTarget];\n\t\t\t\t\t\t\t\tif (typeof nestedValue === 'function') {\n\t\t\t\t\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\t\t\t\t\tconst schema = nestedValue(...args);\n\t\t\t\t\t\t\t\t\t\treturn this.wrapSchema(schema, name);\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn nestedValue;\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\treturn value;\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t};\n\n\t/**\n\t * Creates a ConfigParser that will return mock values when parsed.\n\t */\n\tcreate<TReturn extends EmptyObject>(\n\t\tbuilder: (get: EnvFetcher) => TReturn,\n\t): ConfigParser<TReturn> {\n\t\tconst config = builder(this.getZodGetter);\n\t\treturn new SnifferConfigParser(config, this.accessedVars);\n\t}\n\n\t/**\n\t * Returns all environment variable names that were accessed.\n\t */\n\tgetEnvironmentVariables(): string[] {\n\t\treturn Array.from(this.accessedVars).sort();\n\t}\n}\n\n/**\n * A ConfigParser that always succeeds with mock values.\n */\nclass SnifferConfigParser<\n\tTResponse extends EmptyObject,\n> extends ConfigParser<TResponse> {\n\toverride parse(): any {\n\t\treturn this.parseWithMocks(this.getConfig());\n\t}\n\n\tprivate getConfig(): TResponse {\n\t\t// Access the private config via any cast\n\t\treturn (this as any).config;\n\t}\n\n\tprivate parseWithMocks<T>(config: T): any {\n\t\tconst result: EmptyObject = {};\n\n\t\tif (config && typeof config !== 'object') {\n\t\t\treturn config;\n\t\t}\n\n\t\tfor (const key in config) {\n\t\t\tconst schema = config[key];\n\n\t\t\tif (schema instanceof z.ZodType) {\n\t\t\t\t// Use safeParse which will return mock values from our wrapped schema\n\t\t\t\tconst parsed = schema.safeParse(undefined);\n\t\t\t\tresult[key] = parsed.success\n\t\t\t\t\t? parsed.data\n\t\t\t\t\t: this.getDefaultForSchema(schema);\n\t\t\t} else if (schema && typeof schema === 'object') {\n\t\t\t\tresult[key] = this.parseWithMocks(schema as EmptyObject);\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n\n\tprivate getDefaultForSchema(schema: z.ZodType): unknown {\n\t\tif (schema instanceof z.ZodString) return '';\n\t\tif (schema instanceof z.ZodNumber) return 0;\n\t\tif (schema instanceof z.ZodBoolean) return false;\n\t\tif (schema instanceof z.ZodArray) return [];\n\t\tif (schema instanceof z.ZodOptional) return undefined;\n\t\tif (schema instanceof z.ZodNullable) return null;\n\n\t\tif (schema instanceof z.ZodObject && schema.shape) {\n\t\t\tconst result: Record<string, unknown> = {};\n\t\t\tfor (const [key, value] of Object.entries(schema.shape)) {\n\t\t\t\tif (value instanceof z.ZodType) {\n\t\t\t\t\tresult[key] = this.getDefaultForSchema(value);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\treturn '';\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAa,2BAAb,MAA4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O;AAC3C,MAAI,kBAAkB,EAAE,SAAU,QAAO,CAAE;AAC3C,MAAI,kBAAkB,EAAE,YAAa;AACrC,MAAI,kBAAkB,EAAE,YAAa,QAAO;AAE5C,MAAI,kBAAkB,EAAE,aAAa,OAAO,OAAO;GAClD,MAAME,SAAkC,CAAE;AAC1C,QAAK,MAAM,CAAC,KAAK,MAAM,IAAI,OAAO,QAAQ,OAAO,MAAM,CACtD,KAAI,iBAAiB,EAAE,QACtB,QAAO,OAAO,KAAK,oBAAoB,MAAM;AAG/C,UAAO;EACP;AAED,SAAO;CACP;AACD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EnvRecord, EnvironmentBuilderOptions, EnvironmentResolver, InputValue, Resolvers } from "./EnvironmentBuilder-
|
|
1
|
+
import { EnvRecord, EnvironmentBuilderOptions, EnvironmentResolver, InputValue, Resolvers } from "./EnvironmentBuilder-jF-b7WQg.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/SstEnvironmentBuilder.d.ts
|
|
4
4
|
|
|
@@ -174,4 +174,4 @@ declare class SstEnvironmentBuilder<TRecord extends Record<string, SstResource |
|
|
|
174
174
|
}
|
|
175
175
|
//#endregion
|
|
176
176
|
export { ApiGatewayV2, Bucket, Function, Postgres, ResourceProcessor, ResourceType, Secret, SnsTopic, SstEnvironmentBuilder, SstResource, Vpc, sstResolvers };
|
|
177
|
-
//# sourceMappingURL=SstEnvironmentBuilder-
|
|
177
|
+
//# sourceMappingURL=SstEnvironmentBuilder-BZngSQKQ.d.mts.map
|
package/dist/{SstEnvironmentBuilder-CjURMGjW.d.mts.map → SstEnvironmentBuilder-BZngSQKQ.d.mts.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SstEnvironmentBuilder-
|
|
1
|
+
{"version":3,"file":"SstEnvironmentBuilder-BZngSQKQ.d.mts","names":[],"sources":["../src/SstEnvironmentBuilder.ts"],"sourcesContent":[],"mappings":";;;;;;AAaA;AAsBA;AAAw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;;;;;;;;;;;cAiCd,sCACI,eAAe,cAAc;;;;;;;;;sBAepC,+BACc,gBAAgB,oBAC5B;;;;;;WAmBF"}
|
package/dist/{SstEnvironmentBuilder-BEBFSUYr.mjs.map → SstEnvironmentBuilder-DVB7cJq4.mjs.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SstEnvironmentBuilder-
|
|
1
|
+
{"version":3,"file":"SstEnvironmentBuilder-DVB7cJq4.mjs","names":["name: string","value: SecretValue","key: string","value: PostgresValue","value: BucketValue","value: SnsTopicValue","sstResolvers: Resolvers","record: TRecord","additionalResolvers?: CustomResolvers<TRecord>","options?: EnvironmentBuilderOptions","mergedResolvers: Resolvers"],"sources":["../src/SstEnvironmentBuilder.ts"],"sourcesContent":["import {\n\tEnvironmentBuilder,\n\ttype EnvironmentBuilderOptions,\n\ttype EnvironmentResolver,\n\ttype EnvRecord,\n\ttype InputValue,\n\ttype Resolvers,\n} from './EnvironmentBuilder';\n\n/**\n * Enumeration of supported SST (Serverless Stack Toolkit) resource types.\n * Used to identify and process different AWS and SST resources.\n */\nexport enum ResourceType {\n\t// Legacy format (dot notation)\n\tApiGatewayV2 = 'sst.aws.ApiGatewayV2',\n\tPostgres = 'sst.aws.Postgres',\n\tFunction = 'sst.aws.Function',\n\tBucket = 'sst.aws.Bucket',\n\tVpc = 'sst.aws.Vpc',\n\tSecret = 'sst.sst.Secret',\n\n\t// Modern format (colon notation)\n\tSSTSecret = 'sst:sst:Secret',\n\tSSTFunction = 'sst:sst:Function',\n\tSSTApiGatewayV2 = 'sst:aws:ApiGatewayV2',\n\tSSTPostgres = 'sst:aws:Postgres',\n\tSSTBucket = 'sst:aws:Bucket',\n\tSnsTopic = 'sst:aws:SnsTopic',\n}\n\n/**\n * AWS API Gateway V2 resource type.\n * Represents an HTTP/WebSocket API.\n */\nexport type ApiGatewayV2 = {\n\ttype: ResourceType.ApiGatewayV2 | ResourceType.SSTApiGatewayV2;\n\turl: string;\n};\n\n/**\n * PostgreSQL database resource type.\n * Contains all connection details needed to connect to the database.\n */\nexport type Postgres = {\n\ttype: ResourceType.Postgres | ResourceType.SSTPostgres;\n\tdatabase: string;\n\thost: string;\n\tpassword: string;\n\tport: number;\n\tusername: string;\n};\n\n/**\n * AWS Lambda Function resource type.\n */\nexport type Function = {\n\ttype: ResourceType.Function | ResourceType.SSTFunction;\n\tname: string;\n};\n\n/**\n * AWS S3 Bucket resource type.\n */\nexport type Bucket = {\n\ttype: ResourceType.Bucket | ResourceType.SSTBucket;\n\tname: string;\n};\n\n/**\n * AWS VPC (Virtual Private Cloud) resource type.\n */\nexport type Vpc = {\n\ttype: ResourceType.Vpc;\n\tbastion: string;\n};\n\n/**\n * Secret resource type for storing sensitive values.\n */\nexport type Secret = {\n\ttype: ResourceType.Secret | ResourceType.SSTSecret;\n\tvalue: string;\n};\n\n/**\n * AWS SNS Topic resource type.\n */\nexport type SnsTopic = {\n\ttype: ResourceType.SnsTopic;\n\tarn: string;\n};\n\n/**\n * Union type of all supported SST resource types.\n */\nexport type SstResource =\n\t| ApiGatewayV2\n\t| Postgres\n\t| Function\n\t| Bucket\n\t| Vpc\n\t| Secret\n\t| SnsTopic;\n\n// Value types without the `type` key (for resolver parameters)\ntype SecretValue = Omit<Secret, 'type'>;\ntype PostgresValue = Omit<Postgres, 'type'>;\ntype BucketValue = Omit<Bucket, 'type'>;\ntype SnsTopicValue = Omit<SnsTopic, 'type'>;\n\n/**\n * Function type for processing a specific resource type into environment variables.\n *\n * @template K - The specific resource type (without `type` key)\n * @param name - The resource name\n * @param value - The resource value (without `type` key)\n * @returns Object mapping environment variable names to values\n */\nexport type ResourceProcessor<K> = (name: string, value: K) => EnvRecord;\n\n// SST Resource Resolvers (receive values without `type` key)\n\nconst secretResolver = (name: string, value: SecretValue) => ({\n\t[name]: value.value,\n});\n\nconst postgresResolver = (key: string, value: PostgresValue) => ({\n\t[`${key}Name`]: value.database,\n\t[`${key}Host`]: value.host,\n\t[`${key}Password`]: value.password,\n\t[`${key}Port`]: value.port,\n\t[`${key}Username`]: value.username,\n});\n\nconst bucketResolver = (name: string, value: BucketValue) => ({\n\t[`${name}Name`]: value.name,\n});\n\nconst topicResolver = (name: string, value: SnsTopicValue) => ({\n\t[`${name}Arn`]: value.arn,\n});\n\nconst noopResolver = () => ({});\n\n/**\n * Pre-configured resolvers for all SST resource types.\n */\nexport const sstResolvers: Resolvers = {\n\t// Legacy format\n\t[ResourceType.ApiGatewayV2]: noopResolver,\n\t[ResourceType.Function]: noopResolver,\n\t[ResourceType.Vpc]: noopResolver,\n\t[ResourceType.Secret]: secretResolver,\n\t[ResourceType.Postgres]: postgresResolver,\n\t[ResourceType.Bucket]: bucketResolver,\n\n\t// Modern format\n\t[ResourceType.SSTSecret]: secretResolver,\n\t[ResourceType.SSTBucket]: bucketResolver,\n\t[ResourceType.SSTFunction]: noopResolver,\n\t[ResourceType.SSTPostgres]: postgresResolver,\n\t[ResourceType.SSTApiGatewayV2]: noopResolver,\n\t[ResourceType.SnsTopic]: topicResolver,\n};\n\n/**\n * All known SST resource type strings.\n */\ntype SstResourceTypeString = `${ResourceType}`;\n\n/**\n * Extracts the `type` string value from an input value.\n */\ntype ExtractType<T> = T extends { type: infer U extends string } ? U : never;\n\n/**\n * Removes the `type` key from an object type.\n */\ntype OmitType<T> = T extends { type: string } ? Omit<T, 'type'> : never;\n\n/**\n * Extracts all unique `type` values from a record (excluding plain strings).\n */\ntype AllTypeValues<TRecord extends Record<string, InputValue>> = {\n\t[K in keyof TRecord]: ExtractType<TRecord[K]>;\n}[keyof TRecord];\n\n/**\n * Extracts only the custom (non-SST) type values from a record.\n */\ntype CustomTypeValues<TRecord extends Record<string, InputValue>> = Exclude<\n\tAllTypeValues<TRecord>,\n\tSstResourceTypeString\n>;\n\n/**\n * For a given type value, finds the corresponding value type (without `type` key).\n */\ntype ValueForType<\n\tTRecord extends Record<string, InputValue>,\n\tTType extends string,\n> = {\n\t[K in keyof TRecord]: TRecord[K] extends { type: TType }\n\t\t? OmitType<TRecord[K]>\n\t\t: never;\n}[keyof TRecord];\n\n/**\n * Generates typed resolvers for custom (non-SST) types in the input record.\n */\ntype CustomResolvers<TRecord extends Record<string, InputValue>> =\n\tCustomTypeValues<TRecord> extends never\n\t\t? Resolvers | undefined\n\t\t: {\n\t\t\t\t[TType in CustomTypeValues<TRecord>]: EnvironmentResolver<\n\t\t\t\t\tValueForType<TRecord, TType>\n\t\t\t\t>;\n\t\t\t};\n\n/**\n * SST-specific environment builder with built-in resolvers for all known\n * SST resource types.\n *\n * Wraps the generic EnvironmentBuilder with pre-configured SST resolvers.\n *\n * @template TRecord - The input record type for type inference\n *\n * @example\n * ```typescript\n * const env = new SstEnvironmentBuilder({\n * database: { type: 'sst:aws:Postgres', host: '...', ... },\n * apiKey: { type: 'sst:sst:Secret', value: 'secret' },\n * appName: 'my-app',\n * }).build();\n *\n * // With custom resolvers (typed based on input)\n * const env = new SstEnvironmentBuilder(\n * {\n * database: postgresResource,\n * custom: { type: 'my-custom' as const, data: 'foo' },\n * },\n * {\n * // TypeScript requires 'my-custom' resolver with typed value\n * 'my-custom': (key, value) => ({ [`${key}Data`]: value.data }),\n * }\n * ).build();\n * ```\n */\nexport class SstEnvironmentBuilder<\n\tTRecord extends Record<string, SstResource | InputValue | string>,\n> {\n\tprivate readonly builder: EnvironmentBuilder<\n\t\tRecord<string, InputValue>,\n\t\tResolvers\n\t>;\n\n\t/**\n\t * Create a new SST environment builder.\n\t *\n\t * @param record - Object containing SST resources, custom resources, and/or string values\n\t * @param additionalResolvers - Optional custom resolvers (typed based on custom types in record)\n\t * @param options - Optional configuration options\n\t */\n\tconstructor(\n\t\trecord: TRecord,\n\t\tadditionalResolvers?: CustomResolvers<TRecord>,\n\t\toptions?: EnvironmentBuilderOptions,\n\t) {\n\t\t// Merge resolvers with custom ones taking precedence\n\t\tconst mergedResolvers: Resolvers = additionalResolvers\n\t\t\t? { ...sstResolvers, ...additionalResolvers }\n\t\t\t: sstResolvers;\n\n\t\tthis.builder = new EnvironmentBuilder(\n\t\t\trecord as Record<string, InputValue>,\n\t\t\tmergedResolvers,\n\t\t\toptions,\n\t\t);\n\t}\n\n\t/**\n\t * Build environment variables from the input record.\n\t *\n\t * @returns A record of environment variables\n\t */\n\tbuild(): EnvRecord {\n\t\treturn this.builder.build();\n\t}\n}\n\nexport type {\n\tEnvironmentBuilderOptions,\n\tEnvRecord,\n\tEnvValue,\n} from './EnvironmentBuilder';\n// Re-export useful types\nexport { environmentCase } from './EnvironmentBuilder';\n"],"mappings":";;;;;;;AAaA,IAAY,wDAAL;AAEN;AACA;AACA;AACA;AACA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;;AACA;AA8FD,MAAM,iBAAiB,CAACA,MAAcC,WAAwB,GAC5D,OAAO,MAAM,MACd;AAED,MAAM,mBAAmB,CAACC,KAAaC,WAA0B;GAC9D,EAAE,IAAI,QAAQ,MAAM;GACpB,EAAE,IAAI,QAAQ,MAAM;GACpB,EAAE,IAAI,YAAY,MAAM;GACxB,EAAE,IAAI,QAAQ,MAAM;GACpB,EAAE,IAAI,YAAY,MAAM;AAC1B;AAED,MAAM,iBAAiB,CAACH,MAAcI,WAAwB,IAC3D,EAAE,KAAK,QAAQ,MAAM,KACvB;AAED,MAAM,gBAAgB,CAACJ,MAAcK,WAA0B,IAC5D,EAAE,KAAK,OAAO,MAAM,IACtB;AAED,MAAM,eAAe,OAAO,CAAE;;;;AAK9B,MAAaC,eAA0B;EAErC,aAAa,eAAe;EAC5B,aAAa,WAAW;EACxB,aAAa,MAAM;EACnB,aAAa,SAAS;EACtB,aAAa,WAAW;EACxB,aAAa,SAAS;EAGtB,aAAa,YAAY;EACzB,aAAa,YAAY;EACzB,aAAa,cAAc;EAC3B,aAAa,cAAc;EAC3B,aAAa,kBAAkB;EAC/B,aAAa,WAAW;AACzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqFD,IAAa,wBAAb,MAEE;CACD,AAAiB;;;;;;;;CAYjB,YACCC,QACAC,qBACAC,SACC;EAED,MAAMC,kBAA6B,sBAChC;GAAE,GAAG;GAAc,GAAG;EAAqB,IAC3C;AAEH,OAAK,UAAU,IAAI,mBAClB,QACA,iBACA;CAED;;;;;;CAOD,QAAmB;AAClB,SAAO,KAAK,QAAQ,OAAO;CAC3B;AACD"}
|
package/dist/{SstEnvironmentBuilder-wFnN2M5O.cjs.map → SstEnvironmentBuilder-jsnqgtcW.cjs.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SstEnvironmentBuilder-
|
|
1
|
+
{"version":3,"file":"SstEnvironmentBuilder-jsnqgtcW.cjs","names":["name: string","value: SecretValue","key: string","value: PostgresValue","value: BucketValue","value: SnsTopicValue","sstResolvers: Resolvers","record: TRecord","additionalResolvers?: CustomResolvers<TRecord>","options?: EnvironmentBuilderOptions","mergedResolvers: Resolvers","EnvironmentBuilder"],"sources":["../src/SstEnvironmentBuilder.ts"],"sourcesContent":["import {\n\tEnvironmentBuilder,\n\ttype EnvironmentBuilderOptions,\n\ttype EnvironmentResolver,\n\ttype EnvRecord,\n\ttype InputValue,\n\ttype Resolvers,\n} from './EnvironmentBuilder';\n\n/**\n * Enumeration of supported SST (Serverless Stack Toolkit) resource types.\n * Used to identify and process different AWS and SST resources.\n */\nexport enum ResourceType {\n\t// Legacy format (dot notation)\n\tApiGatewayV2 = 'sst.aws.ApiGatewayV2',\n\tPostgres = 'sst.aws.Postgres',\n\tFunction = 'sst.aws.Function',\n\tBucket = 'sst.aws.Bucket',\n\tVpc = 'sst.aws.Vpc',\n\tSecret = 'sst.sst.Secret',\n\n\t// Modern format (colon notation)\n\tSSTSecret = 'sst:sst:Secret',\n\tSSTFunction = 'sst:sst:Function',\n\tSSTApiGatewayV2 = 'sst:aws:ApiGatewayV2',\n\tSSTPostgres = 'sst:aws:Postgres',\n\tSSTBucket = 'sst:aws:Bucket',\n\tSnsTopic = 'sst:aws:SnsTopic',\n}\n\n/**\n * AWS API Gateway V2 resource type.\n * Represents an HTTP/WebSocket API.\n */\nexport type ApiGatewayV2 = {\n\ttype: ResourceType.ApiGatewayV2 | ResourceType.SSTApiGatewayV2;\n\turl: string;\n};\n\n/**\n * PostgreSQL database resource type.\n * Contains all connection details needed to connect to the database.\n */\nexport type Postgres = {\n\ttype: ResourceType.Postgres | ResourceType.SSTPostgres;\n\tdatabase: string;\n\thost: string;\n\tpassword: string;\n\tport: number;\n\tusername: string;\n};\n\n/**\n * AWS Lambda Function resource type.\n */\nexport type Function = {\n\ttype: ResourceType.Function | ResourceType.SSTFunction;\n\tname: string;\n};\n\n/**\n * AWS S3 Bucket resource type.\n */\nexport type Bucket = {\n\ttype: ResourceType.Bucket | ResourceType.SSTBucket;\n\tname: string;\n};\n\n/**\n * AWS VPC (Virtual Private Cloud) resource type.\n */\nexport type Vpc = {\n\ttype: ResourceType.Vpc;\n\tbastion: string;\n};\n\n/**\n * Secret resource type for storing sensitive values.\n */\nexport type Secret = {\n\ttype: ResourceType.Secret | ResourceType.SSTSecret;\n\tvalue: string;\n};\n\n/**\n * AWS SNS Topic resource type.\n */\nexport type SnsTopic = {\n\ttype: ResourceType.SnsTopic;\n\tarn: string;\n};\n\n/**\n * Union type of all supported SST resource types.\n */\nexport type SstResource =\n\t| ApiGatewayV2\n\t| Postgres\n\t| Function\n\t| Bucket\n\t| Vpc\n\t| Secret\n\t| SnsTopic;\n\n// Value types without the `type` key (for resolver parameters)\ntype SecretValue = Omit<Secret, 'type'>;\ntype PostgresValue = Omit<Postgres, 'type'>;\ntype BucketValue = Omit<Bucket, 'type'>;\ntype SnsTopicValue = Omit<SnsTopic, 'type'>;\n\n/**\n * Function type for processing a specific resource type into environment variables.\n *\n * @template K - The specific resource type (without `type` key)\n * @param name - The resource name\n * @param value - The resource value (without `type` key)\n * @returns Object mapping environment variable names to values\n */\nexport type ResourceProcessor<K> = (name: string, value: K) => EnvRecord;\n\n// SST Resource Resolvers (receive values without `type` key)\n\nconst secretResolver = (name: string, value: SecretValue) => ({\n\t[name]: value.value,\n});\n\nconst postgresResolver = (key: string, value: PostgresValue) => ({\n\t[`${key}Name`]: value.database,\n\t[`${key}Host`]: value.host,\n\t[`${key}Password`]: value.password,\n\t[`${key}Port`]: value.port,\n\t[`${key}Username`]: value.username,\n});\n\nconst bucketResolver = (name: string, value: BucketValue) => ({\n\t[`${name}Name`]: value.name,\n});\n\nconst topicResolver = (name: string, value: SnsTopicValue) => ({\n\t[`${name}Arn`]: value.arn,\n});\n\nconst noopResolver = () => ({});\n\n/**\n * Pre-configured resolvers for all SST resource types.\n */\nexport const sstResolvers: Resolvers = {\n\t// Legacy format\n\t[ResourceType.ApiGatewayV2]: noopResolver,\n\t[ResourceType.Function]: noopResolver,\n\t[ResourceType.Vpc]: noopResolver,\n\t[ResourceType.Secret]: secretResolver,\n\t[ResourceType.Postgres]: postgresResolver,\n\t[ResourceType.Bucket]: bucketResolver,\n\n\t// Modern format\n\t[ResourceType.SSTSecret]: secretResolver,\n\t[ResourceType.SSTBucket]: bucketResolver,\n\t[ResourceType.SSTFunction]: noopResolver,\n\t[ResourceType.SSTPostgres]: postgresResolver,\n\t[ResourceType.SSTApiGatewayV2]: noopResolver,\n\t[ResourceType.SnsTopic]: topicResolver,\n};\n\n/**\n * All known SST resource type strings.\n */\ntype SstResourceTypeString = `${ResourceType}`;\n\n/**\n * Extracts the `type` string value from an input value.\n */\ntype ExtractType<T> = T extends { type: infer U extends string } ? U : never;\n\n/**\n * Removes the `type` key from an object type.\n */\ntype OmitType<T> = T extends { type: string } ? Omit<T, 'type'> : never;\n\n/**\n * Extracts all unique `type` values from a record (excluding plain strings).\n */\ntype AllTypeValues<TRecord extends Record<string, InputValue>> = {\n\t[K in keyof TRecord]: ExtractType<TRecord[K]>;\n}[keyof TRecord];\n\n/**\n * Extracts only the custom (non-SST) type values from a record.\n */\ntype CustomTypeValues<TRecord extends Record<string, InputValue>> = Exclude<\n\tAllTypeValues<TRecord>,\n\tSstResourceTypeString\n>;\n\n/**\n * For a given type value, finds the corresponding value type (without `type` key).\n */\ntype ValueForType<\n\tTRecord extends Record<string, InputValue>,\n\tTType extends string,\n> = {\n\t[K in keyof TRecord]: TRecord[K] extends { type: TType }\n\t\t? OmitType<TRecord[K]>\n\t\t: never;\n}[keyof TRecord];\n\n/**\n * Generates typed resolvers for custom (non-SST) types in the input record.\n */\ntype CustomResolvers<TRecord extends Record<string, InputValue>> =\n\tCustomTypeValues<TRecord> extends never\n\t\t? Resolvers | undefined\n\t\t: {\n\t\t\t\t[TType in CustomTypeValues<TRecord>]: EnvironmentResolver<\n\t\t\t\t\tValueForType<TRecord, TType>\n\t\t\t\t>;\n\t\t\t};\n\n/**\n * SST-specific environment builder with built-in resolvers for all known\n * SST resource types.\n *\n * Wraps the generic EnvironmentBuilder with pre-configured SST resolvers.\n *\n * @template TRecord - The input record type for type inference\n *\n * @example\n * ```typescript\n * const env = new SstEnvironmentBuilder({\n * database: { type: 'sst:aws:Postgres', host: '...', ... },\n * apiKey: { type: 'sst:sst:Secret', value: 'secret' },\n * appName: 'my-app',\n * }).build();\n *\n * // With custom resolvers (typed based on input)\n * const env = new SstEnvironmentBuilder(\n * {\n * database: postgresResource,\n * custom: { type: 'my-custom' as const, data: 'foo' },\n * },\n * {\n * // TypeScript requires 'my-custom' resolver with typed value\n * 'my-custom': (key, value) => ({ [`${key}Data`]: value.data }),\n * }\n * ).build();\n * ```\n */\nexport class SstEnvironmentBuilder<\n\tTRecord extends Record<string, SstResource | InputValue | string>,\n> {\n\tprivate readonly builder: EnvironmentBuilder<\n\t\tRecord<string, InputValue>,\n\t\tResolvers\n\t>;\n\n\t/**\n\t * Create a new SST environment builder.\n\t *\n\t * @param record - Object containing SST resources, custom resources, and/or string values\n\t * @param additionalResolvers - Optional custom resolvers (typed based on custom types in record)\n\t * @param options - Optional configuration options\n\t */\n\tconstructor(\n\t\trecord: TRecord,\n\t\tadditionalResolvers?: CustomResolvers<TRecord>,\n\t\toptions?: EnvironmentBuilderOptions,\n\t) {\n\t\t// Merge resolvers with custom ones taking precedence\n\t\tconst mergedResolvers: Resolvers = additionalResolvers\n\t\t\t? { ...sstResolvers, ...additionalResolvers }\n\t\t\t: sstResolvers;\n\n\t\tthis.builder = new EnvironmentBuilder(\n\t\t\trecord as Record<string, InputValue>,\n\t\t\tmergedResolvers,\n\t\t\toptions,\n\t\t);\n\t}\n\n\t/**\n\t * Build environment variables from the input record.\n\t *\n\t * @returns A record of environment variables\n\t */\n\tbuild(): EnvRecord {\n\t\treturn this.builder.build();\n\t}\n}\n\nexport type {\n\tEnvironmentBuilderOptions,\n\tEnvRecord,\n\tEnvValue,\n} from './EnvironmentBuilder';\n// Re-export useful types\nexport { environmentCase } from './EnvironmentBuilder';\n"],"mappings":";;;;;;;AAaA,IAAY,wDAAL;AAEN;AACA;AACA;AACA;AACA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;;AACA;AA8FD,MAAM,iBAAiB,CAACA,MAAcC,WAAwB,GAC5D,OAAO,MAAM,MACd;AAED,MAAM,mBAAmB,CAACC,KAAaC,WAA0B;GAC9D,EAAE,IAAI,QAAQ,MAAM;GACpB,EAAE,IAAI,QAAQ,MAAM;GACpB,EAAE,IAAI,YAAY,MAAM;GACxB,EAAE,IAAI,QAAQ,MAAM;GACpB,EAAE,IAAI,YAAY,MAAM;AAC1B;AAED,MAAM,iBAAiB,CAACH,MAAcI,WAAwB,IAC3D,EAAE,KAAK,QAAQ,MAAM,KACvB;AAED,MAAM,gBAAgB,CAACJ,MAAcK,WAA0B,IAC5D,EAAE,KAAK,OAAO,MAAM,IACtB;AAED,MAAM,eAAe,OAAO,CAAE;;;;AAK9B,MAAaC,eAA0B;EAErC,aAAa,eAAe;EAC5B,aAAa,WAAW;EACxB,aAAa,MAAM;EACnB,aAAa,SAAS;EACtB,aAAa,WAAW;EACxB,aAAa,SAAS;EAGtB,aAAa,YAAY;EACzB,aAAa,YAAY;EACzB,aAAa,cAAc;EAC3B,aAAa,cAAc;EAC3B,aAAa,kBAAkB;EAC/B,aAAa,WAAW;AACzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqFD,IAAa,wBAAb,MAEE;CACD,AAAiB;;;;;;;;CAYjB,YACCC,QACAC,qBACAC,SACC;EAED,MAAMC,kBAA6B,sBAChC;GAAE,GAAG;GAAc,GAAG;EAAqB,IAC3C;AAEH,OAAK,UAAU,IAAIC,8CAClB,QACA,iBACA;CAED;;;;;;CAOD,QAAmB;AAClB,SAAO,KAAK,QAAQ,OAAO;CAC3B;AACD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_EnvironmentBuilder = require('./EnvironmentBuilder-Djr1VsWM.cjs');
|
|
2
|
-
const require_SstEnvironmentBuilder = require('./SstEnvironmentBuilder-
|
|
2
|
+
const require_SstEnvironmentBuilder = require('./SstEnvironmentBuilder-jsnqgtcW.cjs');
|
|
3
3
|
|
|
4
4
|
exports.ResourceType = require_SstEnvironmentBuilder.ResourceType;
|
|
5
5
|
exports.SstEnvironmentBuilder = require_SstEnvironmentBuilder.SstEnvironmentBuilder;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { EnvRecord, EnvValue, EnvironmentBuilderOptions, environmentCase } from "./EnvironmentBuilder-
|
|
2
|
-
import { ApiGatewayV2, Bucket, Function, Postgres, ResourceProcessor, ResourceType, Secret, SnsTopic, SstEnvironmentBuilder, SstResource, Vpc, sstResolvers } from "./SstEnvironmentBuilder-
|
|
1
|
+
import { EnvRecord, EnvValue, EnvironmentBuilderOptions, environmentCase } from "./EnvironmentBuilder-jF-b7WQg.mjs";
|
|
2
|
+
import { ApiGatewayV2, Bucket, Function, Postgres, ResourceProcessor, ResourceType, Secret, SnsTopic, SstEnvironmentBuilder, SstResource, Vpc, sstResolvers } from "./SstEnvironmentBuilder-BZngSQKQ.mjs";
|
|
3
3
|
export { ApiGatewayV2, Bucket, EnvRecord, EnvValue, EnvironmentBuilderOptions, Function, Postgres, ResourceProcessor, ResourceType, Secret, SnsTopic, SstEnvironmentBuilder, SstResource, Vpc, environmentCase, sstResolvers };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { environmentCase } from "./EnvironmentBuilder-BSuHZm0y.mjs";
|
|
2
|
-
import { ResourceType, SstEnvironmentBuilder, sstResolvers } from "./SstEnvironmentBuilder-
|
|
2
|
+
import { ResourceType, SstEnvironmentBuilder, sstResolvers } from "./SstEnvironmentBuilder-DVB7cJq4.mjs";
|
|
3
3
|
|
|
4
4
|
export { ResourceType, SstEnvironmentBuilder, environmentCase, sstResolvers };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
|
|
3
|
+
//#region src/formatter.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Options for formatting parse errors.
|
|
7
|
+
*/
|
|
8
|
+
interface FormatOptions {
|
|
9
|
+
/** Whether to use colors in output. Defaults to auto-detect TTY. */
|
|
10
|
+
colors?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Formats a ZodError into a user-friendly string for development.
|
|
14
|
+
*
|
|
15
|
+
* @param error - The ZodError to format
|
|
16
|
+
* @param options - Formatting options
|
|
17
|
+
* @returns Formatted error message
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* try {
|
|
22
|
+
* config.parse();
|
|
23
|
+
* } catch (error) {
|
|
24
|
+
* if (error instanceof ZodError) {
|
|
25
|
+
* console.error(formatParseError(error));
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* Output:
|
|
31
|
+
* ```
|
|
32
|
+
* Environment Configuration Failed
|
|
33
|
+
*
|
|
34
|
+
* Missing Variables:
|
|
35
|
+
* DATABASE_URL - Required
|
|
36
|
+
* JWT_SECRET - Required
|
|
37
|
+
*
|
|
38
|
+
* Invalid Values:
|
|
39
|
+
* NODE_ENV = "invalid"
|
|
40
|
+
* Expected: "development" | "staging" | "production"
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
declare function formatParseError(error: z.ZodError, options?: FormatOptions): string;
|
|
44
|
+
/**
|
|
45
|
+
* Checks if the current environment is development.
|
|
46
|
+
*/
|
|
47
|
+
declare function isDevelopment(): boolean;
|
|
48
|
+
//# sourceMappingURL=formatter.d.ts.map
|
|
49
|
+
//#endregion
|
|
50
|
+
export { FormatOptions, formatParseError, isDevelopment };
|
|
51
|
+
//# sourceMappingURL=formatter-Cox0NGxT.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter-Cox0NGxT.d.mts","names":[],"sources":["../src/formatter.ts"],"sourcesContent":[],"mappings":";;;;;;AAKA;AAgDgB,UAhDC,aAAA,CAgDe;EAAA;EAAA,MACtB,CAAA,EAAA,OAAA;;AACkB;AAwF5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA1FgB,gBAAA,QACR,CAAA,CAAE,oBACA;;;;iBAwFM,aAAA,CAAA"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
|
|
3
|
+
//#region src/formatter.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Options for formatting parse errors.
|
|
7
|
+
*/
|
|
8
|
+
interface FormatOptions {
|
|
9
|
+
/** Whether to use colors in output. Defaults to auto-detect TTY. */
|
|
10
|
+
colors?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Formats a ZodError into a user-friendly string for development.
|
|
14
|
+
*
|
|
15
|
+
* @param error - The ZodError to format
|
|
16
|
+
* @param options - Formatting options
|
|
17
|
+
* @returns Formatted error message
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* try {
|
|
22
|
+
* config.parse();
|
|
23
|
+
* } catch (error) {
|
|
24
|
+
* if (error instanceof ZodError) {
|
|
25
|
+
* console.error(formatParseError(error));
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* Output:
|
|
31
|
+
* ```
|
|
32
|
+
* Environment Configuration Failed
|
|
33
|
+
*
|
|
34
|
+
* Missing Variables:
|
|
35
|
+
* DATABASE_URL - Required
|
|
36
|
+
* JWT_SECRET - Required
|
|
37
|
+
*
|
|
38
|
+
* Invalid Values:
|
|
39
|
+
* NODE_ENV = "invalid"
|
|
40
|
+
* Expected: "development" | "staging" | "production"
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
declare function formatParseError(error: z.ZodError, options?: FormatOptions): string;
|
|
44
|
+
/**
|
|
45
|
+
* Checks if the current environment is development.
|
|
46
|
+
*/
|
|
47
|
+
declare function isDevelopment(): boolean;
|
|
48
|
+
//# sourceMappingURL=formatter.d.ts.map
|
|
49
|
+
//#endregion
|
|
50
|
+
export { FormatOptions, formatParseError, isDevelopment };
|
|
51
|
+
//# sourceMappingURL=formatter-D85aIkpd.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter-D85aIkpd.d.cts","names":[],"sources":["../src/formatter.ts"],"sourcesContent":[],"mappings":";;;;;;AAKA;AAgDgB,UAhDC,aAAA,CAgDe;EAAA;EAAA,MACtB,CAAA,EAAA,OAAA;;AACkB;AAwF5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA1FgB,gBAAA,QACR,CAAA,CAAE,oBACA;;;;iBAwFM,aAAA,CAAA"}
|