Fix CLI/client parsing, dependency, and runtime safety issues#4
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
📝 WalkthroughWalkthroughMoves TypeScript to devDependencies, adds storage abstraction and runtime config validation in the client, enables token-aware realtime and query validation, enhances CLI route generation and SQL parsing, tightens dev cleanup and logging, and updates templates and dependencies (fast-deep-equal, .env patterns). Changes
Sequence Diagram(s)sequenceDiagram
actor Dev
participant CreateClient as createClient(config)
participant Config as BetterBaseConfigSchema
participant Storage as StorageAdapter
participant Auth as AuthClient
participant Realtime as RealtimeClient
Dev->>CreateClient: call with config
CreateClient->>Config: parse & validate config
Config-->>CreateClient: parsed config
CreateClient->>Storage: init storage (config.storage or getStorage)
Storage-->>CreateClient: storage instance
CreateClient->>Auth: new AuthClient(..., storage)
Auth-->>CreateClient: auth instance
CreateClient->>Realtime: new RealtimeClient(url, token from auth)
Realtime-->>CreateClient: realtime instance
Note over Auth,Realtime: Auth updates propagate -> Realtime.setToken(token)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
betterbase/packages/cli/src/commands/generate.ts (1)
88-146:⚠️ Potential issue | 🟠 MajorBoolean query filters will misparse
"false"astrue.
FILTER_COERCEusesz.coerce.boolean()(viaschemaTypeToZod), which coerces values using JavaScript's truthy/falsy semantics—any non-empty string becomestrue. As a result,?active=false(and_inarrays containing"false") will be coerced totrue, producing incorrect filtering.🔧 Suggested fixes
Option 1 (Zod v4+, recommended): Use
z.stringbool()- if (type === 'boolean') return 'z.coerce.boolean()'; + if (type === 'boolean') return 'z.stringbool()';Option 2: Explicit string→boolean preprocess
- if (type === 'boolean') return 'z.coerce.boolean()'; + if (type === 'boolean') + return 'z.preprocess((v) => (v === "true" ? true : v === "false" ? false : v), z.boolean())';Option 3: Enum with transform
- if (type === 'boolean') return 'z.coerce.boolean()'; + if (type === 'boolean') return 'z.enum(["true", "false"]).transform(v => v === "true")';🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@betterbase/packages/cli/src/commands/generate.ts` around lines 88 - 146, FILTER_COERCE currently uses z.coerce.boolean() which treats any non-empty string as true, causing "?active=false" to misparse; update the boolean coercion used when building FILTER_COERCE (where schemaTypeToZod produces z schemas) to explicitly parse string booleans (e.g., use a preprocess that returns true only for 'true' and false only for 'false' and passes through actual booleans) so both single-value parsing (the parsed = schema.safeParse(value) branch) and array parsing (parsedInValues items validated in the _in branch) correctly interpret "true"/"false"; change the boolean branch in schemaTypeToZod (and thus FILTER_COERCE) to use that explicit string→boolean parser so eq(...) and inArray(...) get correct boolean values.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@betterbase/packages/cli/src/commands/generate.ts`:
- Around line 88-146: FILTER_COERCE currently uses z.coerce.boolean() which
treats any non-empty string as true, causing "?active=false" to misparse; update
the boolean coercion used when building FILTER_COERCE (where schemaTypeToZod
produces z schemas) to explicitly parse string booleans (e.g., use a preprocess
that returns true only for 'true' and false only for 'false' and passes through
actual booleans) so both single-value parsing (the parsed =
schema.safeParse(value) branch) and array parsing (parsedInValues items
validated in the _in branch) correctly interpret "true"/"false"; change the
boolean branch in schemaTypeToZod (and thus FILTER_COERCE) to use that explicit
string→boolean parser so eq(...) and inArray(...) get correct boolean values.
Summary
This PR verifies and addresses the reported findings across CLI, client package, and base template scaffolding.
CLI updates
typescriptfrom runtime deps todevDependenciesinpackages/cli/package.json.auth.tscreatedUserguard.generate.tsensureZodValidatorInstalledto walk ancestor directories for hoisted installs and package declarations (dependencies/devDependencies/peerDependencies).child.FILTERABLE_COLUMNSand typed coercion map for safe filter handling._infilter parsing support in generated routes using JSON +inArray.migrate.ts--line comment and/* */block comment handling.index.tscontext-generator.tsscanner.ts??to||so empty names fall back to declaration identifier.init.tsparseNonNegativeIntnow treats empty/whitespace as missing and returns fallback.POST /api/usersroute template.src/lib/env.ts.Client updates
packages/client/package.jsonweroperking/Betterbase.typecheckandtypecheck:testare both--noEmit.lintscript to Biome and added@biomejs/biomedevDependency.errors.tsBetterBaseErrornow setsnamefromthis.constructor.name.auth.tssignUpandsignIn.client.tsstoragesupport to config handling.from()now accepts optionalQueryBuilderOptions.query-builder.tsexecuted) for mutation/execute lifecycle.select,eq,in,limit,offset,order).in()now serializes arrays withJSON.stringify.singularKeyoverride option path viaQueryBuilderOptions.realtime.tsconstructor+setToken) and tokenized WS URL.connect()no longer throws whenWebSocketis unavailable; enters disabled mode with warning.build.tstest/client.test.tstsconfig.test.jsondeclarationMap.tsconfig.jsondeclarationMapto avoid conflict when test config disables declarations.Base template updates
templates/base/.gitignore.env.*and!.env.example.templates/base/README.mdsrc/lib/realtime.tsto project structure tree.templates/base/src/index.tstemplates/base/src/lib/realtime.tsdeepEqualwithfast-deep-equal.templates/base/package.jsonfast-deep-equaldependency.Monorepo config
jsxfromtsconfig.base.jsonto keep base config React-agnostic.Validation
git diff --checkpasses.bun run typecheck:test(client package) currently fails in this environment due missing Bun type definitions (TS2688: Cannot find type definition file for 'bun').Codex Task
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Chores