feat: sync ghbot-Nodeloc v1.2.0 capabilities into upstream
Merges all 33 commits from lza6/ghbot-Nodeloc (v1.0.0 through v1.2.0) while keeping both sides' features in every conflicted file: - EventRouter dispatch extracted from runReview.ts (7.1), with the runtime environment block preserved on the review-start comment - Unified command ack messages (6.3) combined with the collapsed runtime environment block and bot signature on /recheck replies - Status banner and collapsible unposted findings in review bodies (6.1) - Centralized runtime directories behind GHBOT_RUNTIME_DIR (D-13); webhook knowledge cache now lives under tempRootDirectory() - Production hardening for merge races, timeouts, webhook ops; atomic temp-file rename for R2 cache restores kept from upstream - Webhook parity retained: triage events gated by WEBHOOK_TRIAGE_ENABLED, read-only command guidance, repository knowledge injection, runtime environment block on webhook chat replies - Sanitization/secret redaction centralization, error-aware retry, duplicate merge prevention, in-process webhook retries, /metrics - Infra: eslint/prettier gates with CI verify workflow, docs archives typecheck, eslint, prettier format:check, and 164 tests all pass.
This commit is contained in:
commit
9e47ab339e
180 files changed
+15130
-1209
No files matched your search
@@ -0,0 +1,63 @@
|
||||
---
|
||||
title: Use Primitive Schemas Correctly
|
||||
impact: CRITICAL
|
||||
impactDescription: Incorrect primitive selection causes validation to pass on wrong types; using z.any() or z.unknown() loses all type safety
|
||||
tags: schema, primitives, types, basics
|
||||
---
|
||||
|
||||
## Use Primitive Schemas Correctly
|
||||
|
||||
Zod provides specific schemas for each primitive type. Using the wrong schema (e.g., `z.string()` when you need `z.number()`) or falling back to `z.any()` defeats the purpose of validation entirely, allowing corrupt data through.
|
||||
|
||||
**Incorrect (wrong primitive or any):**
|
||||
|
||||
```typescript
|
||||
import { z } from "zod";
|
||||
|
||||
// Using any loses all type safety
|
||||
const userSchema = z.object({
|
||||
id: z.any(), // Accepts anything - no validation
|
||||
age: z.string(), // Wrong type - age should be number
|
||||
active: z.any() // Should be boolean
|
||||
});
|
||||
|
||||
// This passes validation but data is wrong
|
||||
userSchema.parse({ id: null, age: "twenty", active: "yes" });
|
||||
// Result: { id: null, age: "twenty", active: "yes" }
|
||||
```
|
||||
|
||||
**Correct (specific primitives):**
|
||||
|
||||
```typescript
|
||||
import { z } from "zod";
|
||||
|
||||
const userSchema = z.object({
|
||||
id: z.string().uuid(), // Specific format validation
|
||||
age: z.number().int().positive(), // Correct type with constraints
|
||||
active: z.boolean() // Exact boolean type
|
||||
});
|
||||
|
||||
// Now invalid data is rejected
|
||||
userSchema.parse({ id: null, age: "twenty", active: "yes" });
|
||||
// Throws ZodError with specific field errors
|
||||
```
|
||||
|
||||
**Available primitive schemas:**
|
||||
|
||||
- `z.string()` - strings with optional regex, min, max, email, url, uuid
|
||||
- `z.number()` - numbers with optional int, positive, negative, min, max
|
||||
- `z.bigint()` - BigInt values
|
||||
- `z.boolean()` - true/false only
|
||||
- `z.date()` - Date objects
|
||||
- `z.symbol()` - Symbol type
|
||||
- `z.undefined()` - undefined only
|
||||
- `z.null()` - null only
|
||||
- `z.void()` - undefined (for function returns)
|
||||
- `z.never()` - no valid value
|
||||
|
||||
**When NOT to use this pattern:**
|
||||
|
||||
- When you genuinely need to accept any value (rare - consider `z.unknown()` instead)
|
||||
- When migrating legacy code incrementally (use `z.any()` temporarily, then fix)
|
||||
|
||||
Reference: [Zod Primitives](https://zod.dev/api#primitives)
|
||||
Reference in new issue
Block a user