Skip to content

Commit 1c75669

Browse files
committed
feat: introduce env vars validation through .env(schema, processEnv?) method
1 parent f90565c commit 1c75669

File tree

7 files changed

+431
-172
lines changed

7 files changed

+431
-172
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Zagora
22

3-
[![ci](https://github.com/tunnckoCore/zagora/actions/workflows/ci.yml/badge.svg)](https://github.com/tunnckoCore/zagora/actions/workflows/ci.yml) <!-- COV_BADGE:START -->![coverage](https://badgen.net/badge/coverage/96.13%25/99CC09)<!-- COV_BADGE:END -->
3+
[![ci](https://github.com/tunnckoCore/zagora/actions/workflows/ci.yml/badge.svg)](https://github.com/tunnckoCore/zagora/actions/workflows/ci.yml) <!-- COV_BADGE:START -->![coverage](https://badgen.net/badge/coverage/95.85%25/99CC09)<!-- COV_BADGE:END -->
44

55
Elevate your TypeScript workflow with Zagora: a sleek, bulletproof toolkit for forging type-safe, error-proof functions and libraries that never throw. Powered by StandardSchema-compliant validators like Zod, Valibot, and Arktype, it delivers rock-solid input/output validation and richly typed errors. No routers, no network baggage — just pure, exportable functions ready to supercharge your code. The ultimate streamlined alternative to oRPC and tRPC, stripping away the network layer for unmatched type-safety, simplicity and robustness.
66

@@ -15,7 +15,7 @@ Elevate your TypeScript workflow with Zagora: a sleek, bulletproof toolkit for f
1515
- 🔒 **Type-Safe:** Full type inference across inputs, outputs, errors, context, optionals, and defaults.
1616
-**Ergonomic:** Pure functions with auto-filled defaults, optional args, and detailed diagnostics.
1717
- 🏠 **Familiar:** Echoes remote-RPC patterns from oRPC and tRPC, but focused on libraries, not apps.
18-
- ⚖️ **Unopinionated:** Zero assumptions - no routers, middlewares, or network dependencies.
18+
- ⚖️ **Unopinionated:** Zero assumptions - no routers, middlewares, or network concepts.
1919
- 🎁 **No Unwrapping:** Direct access to results, unlike `neverthrow` - no extra steps required.
2020
- 🤖 **Agents Ready:** Rules for LLMs with subtle nuances and where to be careful. [Read/get here](./AGENTS.md)
2121

@@ -694,7 +694,7 @@ Creates a new Zagora instance.
694694
- `.context<T>(initial)` - Type the context with generic, and optionally set initial context
695695
- `.cache(adapter)` - Set cache adapter that should have `has`, `get`, `set`, methods
696696
- `.handler(fn)` - Set handler/procedure function
697-
- `.callable(runtimeContext?)` - Create callable procedure, context is deep merged with the initial context.
697+
- `.callable(opts?: { context?, cache? })` - Create callable procedure, context is deep merged with the initial context.
698698

699699
## Error Types
700700

src/errors.ts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export function isZagoraError<T>(val: any): val is ZagoraError<T> {
5858
}
5959

6060
export function createValidationError<ErrorKindNames = never>(
61-
mode: "input" | "output" | "error data",
61+
mode: "input" | "output" | "error data" | "env",
6262
issues: SchemaIssue[],
6363
key?: ErrorKindNames,
6464
) {
@@ -115,28 +115,15 @@ export type ErrorHelpers<
115115
}
116116
: never;
117117

118-
export type ErrorsMapPlain<TErrorsMap extends Record<string, AnySchema>> = {
119-
[K in keyof TErrorsMap]: Prettify<
120-
{ kind: K } & InferSchemaOutput<TErrorsMap[K]>
121-
>;
118+
export type InferSchemaMapPlain<
119+
T extends Record<string, AnySchema>,
120+
ResolveErr extends boolean,
121+
> = {
122+
[K in keyof T]: ResolveErr extends true
123+
? Prettify<{ kind: K } & InferSchemaOutput<T[K]>>
124+
: Prettify<InferSchemaOutput<T[K]>>;
122125
};
123126

124-
// export type ErrorsMapResolved<
125-
// TErrorsMap extends Record<string, AnySchema> | undefined,
126-
// > = TErrorsMap extends Record<string, AnySchema>
127-
// ? ErrorsMapPlain<TErrorsMap>
128-
// : undefined;
129-
130-
export type ErrorsMapResolved<
131-
TErrorsMap extends Record<string, AnySchema> | undefined,
132-
> = TErrorsMap extends Record<string, AnySchema>
133-
? {
134-
[K in keyof TErrorsMap]: Prettify<
135-
{ kind: K } & InferSchemaOutput<TErrorsMap[K]>
136-
>;
137-
}
138-
: undefined;
139-
140127
export type ResolveErrorKindNames<TErrorsMap> = TErrorsMap extends Record<
141128
string,
142129
AnySchema

0 commit comments

Comments
 (0)