Skip to content

Commit f3651ca

Browse files
committed
fix: typos and other CodeRabbit suggestions
Signed-off-by: tunnckoCore <5038030+tunnckoCore@users.noreply.github.com>
1 parent 9e81688 commit f3651ca

File tree

8 files changed

+44
-44
lines changed

8 files changed

+44
-44
lines changed

.rules/zagora.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ import {
8585
isZagoraError,
8686
} from 'zagora/errors';
8787

88-
import * ZagoraTypes from 'zagora/types';
89-
import * zagoraUtils from 'zagora/utils';
88+
import * as ZagoraTypes from 'zagora/types';
89+
import * as zagoraUtils from 'zagora/utils';
9090
```
9191

9292
## Creating procedures
@@ -113,8 +113,8 @@ const result = agent({ name: 'Alice' });
113113
- oRPC/tRPC - `.handler(({ input, context }) => {})` - always a single object
114114
- zagora with primitive input (string, object, array) - `.handler(({ context }, input) => {})`
115115
- zagora with tuple schemas (spreaded args) - `.handler(({ context }, name, age) => {})`
116-
- zagora with errprs map - `.errors({ NOT_FOUND: z.object({ id: z.string() })}).handler(({ context, errors }, name, age) => {})`
117-
- zagora without options object - `zagora({ disableOptions: true }).input(z.string()).handle((input) => input)`
116+
- zagora with errors map - `.errors({ NOT_FOUND: z.object({ id: z.string() })}).handler(({ context, errors }, name, age) => {})`
117+
- zagora without options object - `zagora({ disableOptions: true }).input(z.string()).handler((input) => input)`
118118

119119
## Input and Output Validation
120120

@@ -151,7 +151,7 @@ const safeApi = zagora()
151151
.handler(({ env }) => {
152152
// env: { DATABASE_URL: string, JWT_SECRET: string, PORT: number }
153153
return a + b + env.PORT;
154-
});
154+
})
155155
// NOTE: you may need to cast with `as any` beause process.env differs from the schema!
156156
.callable({ env: process.env });
157157

@@ -237,7 +237,7 @@ For simpler procedures and API look, enable auto-callable mode to skip `.callabl
237237
const simpleProcedure = zagora({ autoCallable: true, disableOptions: true })
238238
.input(z.tuple([z.string(), z.number().default(10)]))
239239
.output(z.string())
240-
.handler((str, num) => input.toUpperCase());
240+
.handler((str, num) => str.toUpperCase());
241241

242242
const result = simpleProcedure('hello'); // Direct call
243243
```
@@ -267,28 +267,28 @@ const asyncAgent = zagora()
267267

268268
Agents built with Zagora are composable, testable, and maintain type safety throughout the application lifecycle.
269269

270+
---
271+
270272
## Rules and Special Notes for Zagora usage
271273

272274
The following rules outlines critical points, edge cases, and things to be careful about when using Zagora. These are derived from specially noted sections, examples, and warnings in the documentation.
273275

274-
## Error Handling
276+
### Error Handling Cautions
275277

276-
### Uppercase Error Keys
278+
#### Uppercase Error Keys
277279
- **Caution**: All keys in the error map must be uppercased (e.g., `NOT_FOUND`, not `not_found`). TypeScript will report a type error if not.
278280
- **Why**: These keys represent error "kinds" and are used in `result.error.kind`.
279281

280-
### Error Helper Validation
282+
#### Error Helper Validation
281283
- **Caution**: If you pass invalid or missing keys to error helpers (e.g., `errors.NOT_FOUND({ invalidKey: 'value' })`), you get a `VALIDATION_ERROR` with a `key` property indicating which error validation failed.
282284
- **Example**: `throw errors.RATE_LIMIT({ retryAfter: 'invalid' })``VALIDATION_ERROR` because `retryAfter` expects a number.
283285
- **Tip**: Use `.strict()` on error schemas to throw on unknown keys: `z.object({...}).strict()`.
284286

285-
### Error Type Guards
287+
#### Error Type Guards
286288
- **Caution**: Use `isValidationError`, `isInternalError`, `isDefinedError`, `isZagoraError` to narrow error types safely.
287289
- **Note**: Even syntax errors in handlers return `ZagoraResult` with error, never crashing the process.
288290

289-
## Context Management
290-
291-
### Context Merging
291+
### Context Merging and Management
292292
- **Caution**: Initial context (from `.context()`) is deep-merged with runtime context (from `.callable({ context })`).
293293
- **Example**: `.context({ userId: 'default' })` + `.callable({ context: { foo: 'bar' } })` → merged `{ userId: 'default', foo: 'bar' }`.
294294
- **Tip**: Useful for dependency injection; override at execution site (e.g., in server handlers).

AGENTS.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ import {
8585
isZagoraError,
8686
} from 'zagora/errors';
8787

88-
import * ZagoraTypes from 'zagora/types';
89-
import * zagoraUtils from 'zagora/utils';
88+
import * as ZagoraTypes from 'zagora/types';
89+
import * as zagoraUtils from 'zagora/utils';
9090
```
9191

9292
## Creating procedures
@@ -113,8 +113,8 @@ const result = agent({ name: 'Alice' });
113113
- oRPC/tRPC - `.handler(({ input, context }) => {})` - always a single object
114114
- zagora with primitive input (string, object, array) - `.handler(({ context }, input) => {})`
115115
- zagora with tuple schemas (spreaded args) - `.handler(({ context }, name, age) => {})`
116-
- zagora with errprs map - `.errors({ NOT_FOUND: z.object({ id: z.string() })}).handler(({ context, errors }, name, age) => {})`
117-
- zagora without options object - `zagora({ disableOptions: true }).input(z.string()).handle((input) => input)`
116+
- zagora with errors map - `.errors({ NOT_FOUND: z.object({ id: z.string() })}).handler(({ context, errors }, name, age) => {})`
117+
- zagora without options object - `zagora({ disableOptions: true }).input(z.string()).handler((input) => input)`
118118

119119
## Input and Output Validation
120120

@@ -151,7 +151,7 @@ const safeApi = zagora()
151151
.handler(({ env }) => {
152152
// env: { DATABASE_URL: string, JWT_SECRET: string, PORT: number }
153153
return a + b + env.PORT;
154-
});
154+
})
155155
// NOTE: you may need to cast with `as any` beause process.env differs from the schema!
156156
.callable({ env: process.env });
157157

@@ -237,7 +237,7 @@ For simpler procedures and API look, enable auto-callable mode to skip `.callabl
237237
const simpleProcedure = zagora({ autoCallable: true, disableOptions: true })
238238
.input(z.tuple([z.string(), z.number().default(10)]))
239239
.output(z.string())
240-
.handler((str, num) => input.toUpperCase());
240+
.handler((str, num) => str.toUpperCase());
241241

242242
const result = simpleProcedure('hello'); // Direct call
243243
```
@@ -267,28 +267,28 @@ const asyncAgent = zagora()
267267

268268
Agents built with Zagora are composable, testable, and maintain type safety throughout the application lifecycle.
269269

270+
---
271+
270272
## Rules and Special Notes for Zagora usage
271273

272274
The following rules outlines critical points, edge cases, and things to be careful about when using Zagora. These are derived from specially noted sections, examples, and warnings in the documentation.
273275

274-
## Error Handling
276+
### Error Handling Cautions
275277

276-
### Uppercase Error Keys
278+
#### Uppercase Error Keys
277279
- **Caution**: All keys in the error map must be uppercased (e.g., `NOT_FOUND`, not `not_found`). TypeScript will report a type error if not.
278280
- **Why**: These keys represent error "kinds" and are used in `result.error.kind`.
279281

280-
### Error Helper Validation
282+
#### Error Helper Validation
281283
- **Caution**: If you pass invalid or missing keys to error helpers (e.g., `errors.NOT_FOUND({ invalidKey: 'value' })`), you get a `VALIDATION_ERROR` with a `key` property indicating which error validation failed.
282284
- **Example**: `throw errors.RATE_LIMIT({ retryAfter: 'invalid' })``VALIDATION_ERROR` because `retryAfter` expects a number.
283285
- **Tip**: Use `.strict()` on error schemas to throw on unknown keys: `z.object({...}).strict()`.
284286

285-
### Error Type Guards
287+
#### Error Type Guards
286288
- **Caution**: Use `isValidationError`, `isInternalError`, `isDefinedError`, `isZagoraError` to narrow error types safely.
287289
- **Note**: Even syntax errors in handlers return `ZagoraResult` with error, never crashing the process.
288290

289-
## Context Management
290-
291-
### Context Merging
291+
### Context Merging and Management
292292
- **Caution**: Initial context (from `.context()`) is deep-merged with runtime context (from `.callable({ context })`).
293293
- **Example**: `.context({ userId: 'default' })` + `.callable({ context: { foo: 'bar' } })` → merged `{ userId: 'default', foo: 'bar' }`.
294294
- **Tip**: Useful for dependency injection; override at execution site (e.g., in server handlers).

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ They are built around the network, Zagora is built around functions with excelle
171171

172172
- Zagora is focused on producing "just functions", not networks, routers, or groups.
173173
- oRPC and tRPC does not "support" creating synchornous functions, they always are async
174-
+ in contrast, Zagora does not use `async/await `anywhere in the codebase, but `instanceof Promise` checks
174+
+ in contrast, Zagora does not use `async/await` anywhere in the codebase, but `instanceof Promise` checks
175175
+ the return type of Zagora procedures is dynamically inferred based on many factors
176176
- return type is NOT a union like `ZagoraResult | Promise<ZagoraResult>` which gives amazing DX
177177
- oRPC/tRPC cannot create procedures that look like regular functions, they always accept a single object
@@ -296,13 +296,12 @@ if (res.ok) {
296296
}
297297
```
298298

299-
[Back to top](#table-of-contents)
300-
301-
### Error Type Guards
302299
Isn't it amazing? You will never see `Error` or `try/catch` blocks again, and everything is typed top to bottom, well-known and intuitive.
303300

304301
But wait, there's more: **Type Guards**!
305302

303+
[Back to top](#table-of-contents)
304+
306305
### Error Type Guards
307306

308307
Since you may want to differentiate between the error kinds, there are couple of helper type guards that you can use to narrow down the error.
@@ -424,7 +423,7 @@ hello('ok');
424423

425424
hello('missing-required-keys');
426425
// result.error => { kind: 'VALIDATION_ERROR', key: 'RATE_LIMIT', issues: Schema.Issue[] }
427-
// result.error.issues - will contain the issue that `userId` and `messatge` are required
426+
// result.error.issues - will contain the issue that `userId` and `message` are required
428427

429428
hello('invalid-keys');
430429
// result.error => { kind: 'VALIDATION_ERROR', key: 'RATE_LIMIT', issues: Schema.Issue[] }

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
"scripts": {
4545
"prebuild": "bun run check:types",
4646
"build": "bunx tsdown",
47-
"check": "bun run check:format && bun run check:types && bun run check:repo",
47+
"check": "bun run check:copy-rules && bun run check:format && bun run check:types && bun run check:repo",
48+
"check:copy-rules": "cp AGENTS.md .rules/zagora.md",
4849
"check:format": "bunx @biomejs/biome check --fix --unsafe",
4950
"check:types": "bunx tsgo-dev -p ./tsconfig.json",
5051
"check:repo": "bunx sherif -r root-package-dependencies -r root-package-private-field",

src/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export function createValidationError<ErrorKindNames = never>(
6767
const issuesMsg = issues
6868
// strip "input" cuz it can be confusing when we are schema validating output and errors too
6969
.map((issue) => {
70-
const key = issue.path?.join(".");
70+
const key = issue.path?.join(".") || "(root)";
7171
const message = issue.message.replace("Invalid input: ", "");
7272
return `${key} => ${message}`;
7373
})

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ export class Zagora<
407407

408408
const { isAsync, handlerFailed, ...rest } = st;
409409

410-
// if handler failed, then we need to validate the error if errorShema,
410+
// if handler failed, then we need to validate the error if errorSchema,
411411
// otherwise we can passthrough the Result object whatever it is.
412412
return handlerFailed
413413
? validateError<TKindNames>(errorsMap as any, st.error, isAsync)

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ export function deepMerge(target: any, source: any): any {
263263
if (target == null || typeof target !== "object") return source;
264264
const result = Array.isArray(target) ? [...target] : { ...target };
265265
for (const key in source) {
266-
if (key in source) {
266+
if (Object.hasOwn(source, key)) {
267267
if (typeof source[key] === "object" && source[key] !== null) {
268268
result[key] = deepMerge(target[key], source[key]);
269269
} else {

test/main.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ test("multiple procedures (calculator) from single instance (autoCallable:true)"
474474
}
475475
});
476476

477-
test("handle optional/default valaues in object schemas", async () => {
477+
test("handle optional/default values in object schemas", async () => {
478478
const SpeedSchema = z.enum(["slow", "normal", "fast"]);
479479
const NumberSchema = z
480480
.string()
@@ -754,14 +754,14 @@ test("cache adapter passed through `.callable` method", async () => {
754754
expect((res2 as any).data).toStrictEqual(11);
755755
}
756756

757-
fixture();
758-
fixture(true);
759-
fixture(true, true);
760-
fixture(false, true);
761-
fixture(false, true, true);
762-
fixture(true, false);
763-
fixture(true, true, false);
764-
fixture(false, false, true);
757+
await fixture();
758+
await fixture(true);
759+
await fixture(true, true);
760+
await fixture(false, true);
761+
await fixture(false, true, true);
762+
await fixture(true, false);
763+
await fixture(true, true, false);
764+
await fixture(false, false, true);
765765
});
766766

767767
test("failing env validation schema through `.env` method", () => {

0 commit comments

Comments
 (0)