Skip to content

Conversation

@mathpirate
Copy link
Contributor

@mathpirate mathpirate commented Nov 22, 2025

Adds injected schemas for a variety of CT types, eg Cell.of, Cell.for (and the equivalents for other Cell-like types), cell (the constructor), and generateObject

Test plan still only partially implemented but basics seem like they are working

Type narrowing for literal values is hacky and needs improving in a future follow-up


Summary by cubic

Automatically injects JSON schemas into Cell constructors and factory methods, and adds literal type widening to produce simpler, more general schemas. Also fixes link resolution to drop schemas when a remaining path field is not defined.

  • New Features

    • Injects schemas for cell(), Cell.of(), OpaqueCell.of(), Stream.of(), ComparableCell.of(), ReadonlyCell.of(), WriteonlyCell.of().
    • Wraps Cell.for(...) with .asSchema(...) to attach schemas.
    • Supports wish() (schema as second arg) and generateObject() (schema in options).
    • Adds literal widening (number/string/boolean/bigint → base types), applies within arrays and nested objects, and merges identical schemas to reduce anyOf noise.
  • Bug Fixes

    • Cell.of() with no value now inserts undefined as the first arg so the schema stays in the second position.
    • Link resolution removes schema when following a path to a field not present in the schema (no parent schema leakage).

Written for commit 09ea8b4. Summary will update automatically on new commits.

@mathpirate mathpirate force-pushed the feat/more-schemas-injected branch from 8d5a436 to 88c43fd Compare November 22, 2025 08:17
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 101 files

seefeldb and others added 2 commits November 25, 2025 10:06
When Cell.of<T>() is called with a type argument but no value argument,
the schema was incorrectly being placed as the first argument. The schema
must always be the second argument, so now undefined is inserted as the
first argument when no value is provided.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
… schema

When resolving a link with a remaining path, if `getSchemaAtPath` returns
`undefined` (because the field doesn't exist in the schema), the resolved
link should have no schema property rather than keeping the parent schema.

Previously, the code spread `...nextLink` which would include the original
schema, then conditionally added the new schema only if truthy. This meant
an undefined schema from `getSchemaAtPath` would leave the original schema
in place.

The fix:
1. Destructures `schema` out of `nextLink` to prevent it from being spread
2. Uses `schema \!== undefined` instead of truthiness check to properly
   handle empty object schemas `{}`
3. Only adds `schema` back to the result if it's explicitly not undefined

Example: An array schema `{type: "array", items: {type: "number"}}` linked
through a path to `.length` should result in `schema: undefined` since
"length" is not defined in array schemas.
@seefeldb seefeldb merged commit c46851b into main Nov 25, 2025
9 checks passed
@seefeldb seefeldb deleted the feat/more-schemas-injected branch November 25, 2025 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants