Skip to content

feat: Migrate reference system from ZodRef to transform-based architecture#587

Merged
kingston merged 38 commits into
mainfrom
kingston/eng-749-convert-ref-system-to-use-new-ref-plan
Jul 3, 2025
Merged

feat: Migrate reference system from ZodRef to transform-based architecture#587
kingston merged 38 commits into
mainfrom
kingston/eng-749-convert-ref-system-to-use-new-ref-plan

Conversation

@kingston

@kingston kingston commented Jul 3, 2025

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Introduced a new schema reference system using transform-based architecture with marker classes and schema transformations.
    • Added a React hook for schema context integration and a context-based API for defining references and entities.
    • Added comprehensive integration and unit tests for complex reference scenarios, including custom name resolvers and parent-child relationships.
  • Refactor

    • Migrated all schema and plugin definitions to use context-aware schema creators instead of static schemas.
    • Replaced legacy reference handling (ZodRef) with a streamlined transform-based approach.
    • Updated all reference deletion behaviors to use SET_UNDEFINED instead of SET_NULL, with improved array handling.
  • Bug Fixes

    • Improved error handling for unresolved references and invalid reference deletion actions.
  • Documentation

    • Expanded and formalized code style, UI, and testing guidelines.
    • Consolidated and clarified developer command and testing documentation.
  • Chores

    • Updated dependencies and ESLint configuration to enforce unused import rules.
    • Cleaned up and consolidated internal code and test structure.

kingston added 30 commits June 24, 2025 10:37
@changeset-bot

changeset-bot Bot commented Jul 3, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1abe446

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 17 packages
Name Type
@baseplate-dev/project-builder-lib Patch
@baseplate-dev/project-builder-web Patch
@baseplate-dev/project-builder-cli Patch
@baseplate-dev/project-builder-common Patch
@baseplate-dev/project-builder-server Patch
@baseplate-dev/project-builder-test Patch
@baseplate-dev/plugin-auth Patch
@baseplate-dev/plugin-storage Patch
@baseplate-dev/code-morph Patch
@baseplate-dev/core-generators Patch
@baseplate-dev/create-project Patch
@baseplate-dev/fastify-generators Patch
@baseplate-dev/react-generators Patch
@baseplate-dev/sync Patch
@baseplate-dev/tools Patch
@baseplate-dev/ui-components Patch
@baseplate-dev/utils Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Jul 3, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
baseplate-project-builder-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 3, 2025 3:25pm

@coderabbitai

coderabbitai Bot commented Jul 3, 2025

Copy link
Copy Markdown

Caution

Review failed

Failed to post review comments.

Walkthrough

This change migrates the project's reference and schema handling from a legacy ZodRef-based approach to a new transform-based architecture using context-aware schema creator functions and marker classes. It replaces direct Zod schema manipulation with context-driven APIs for references and entities, introduces new deserialization and parsing methods, updates deletion behaviors, and refactors affected tests, plugins, and UI components to use the new system.

Changes

File(s) / Group Change Summary
packages/project-builder-lib/src/references/definition-ref-builder.ts
.../markers.ts
.../strip-ref-markers.ts
.../extend-parser-context-with-refs.ts
.../extract-definition-refs.ts
.../extract-definition-refs.unit.test.ts
Replaced ZodRef-based reference builder and marker system with new DefinitionRefBuilder, marker classes, symbol-based annotations, and recursive extraction utilities. Added context-driven reference and entity registration methods.
packages/project-builder-lib/src/references/deserialize-schema.ts
.../parse-schema-with-references.ts
.../fix-ref-deletions.ts
.../serialize-schema.ts
Replaced direct Zod schema deserialization/serialization and parsing with new transform-based functions using schema creators and context options. Centralized reference resolution logic.
packages/project-builder-lib/src/references/types.ts
.../fix-ref-deletions.unit.test.ts
.../deserialize-schema.unit.test.ts
.../serialize-schema.unit.test.ts
Renamed SET_NULL to SET_UNDEFINED in reference deletion actions. Updated all related logic and tests to use undefined instead of null for unset references, with stricter array handling.
packages/project-builder-lib/src/plugins/schema/common.ts
.../parser.ts
.../zod-with-plugins.ts
.../index.ts
Removed Zod plugin wrapper classes and related exports, eliminating legacy plugin-based schema extension in favor of new context-driven system.
packages/project-builder-lib/src/plugins/spec/config-spec.ts Refactored plugin config spec to register and retrieve schema creators instead of static Zod schemas.
packages/project-builder-lib/src/references/index.ts Updated exports to reflect new reference builder and extraction utilities, removed legacy ref-builder export.
packages/project-builder-lib/src/schema/creator/schema-creator.ts
.../types.ts
Added createDefinitionSchemaParserContext and extended parser context with reference/entity builder methods. Improved documentation and typing for schema creator context.
packages/project-builder-lib/src/schema/models/, .../features/, .../apps/, .../plugins/, .../project-definition.ts Refactored all schema definitions to use context-based APIs (ctx.withEnt, ctx.withRef, ctx.withRefBuilder) instead of direct helper functions. Added explicit id fields and updated reference handling throughout.
packages/project-builder-lib/src/definition/feature/feature-utils.ts
.../project-definition-container.*
.../parser/parser.ts
.../migrations/
Updated feature and project definition utilities to use new schema creator and plugin store patterns. Added migration for null-to-undefined parent refs.
packages/project-builder-lib/src/web/hooks/
packages/project-builder-web/src/hooks/
Introduced useDefinitionSchema React hook for context-aware schema retrieval. Removed usePluginEnhancedSchema and updated all UI hooks and components to use the new hook and context.
packages/project-builder-web/src/routes/ Refactored all forms and components to use the new schema context and reference handling, updated form validation logic, and replaced null with undefined for optional references.
plugins/plugin-auth/, plugins/plugin-storage/ Refactored plugin schemas and registration to use schema creator functions and context-based reference/entity APIs. Updated type exports accordingly.
.changeset/, .cursor/rules/, CLAUDE.md, package.json, packages/tools/ Updated documentation, code style, and testing guidelines. Added/removed scripts and dependencies for linting and code quality.
Removed Files: ref-builder.unit.test.ts, legacy plugin schema files Deleted obsolete tests and code for the ZodRef-based reference system and plugin wrappers.

Sequence Diagram(s)

sequenceDiagram
actor User
participant UI_Component
participant useDefinitionSchema
participant SchemaCreator
participant DefinitionSchemaParserContext
participant ReferenceMarkers

User->>UI_Component: Interacts with form/component
UI_Component->>useDefinitionSchema: Requests schema (creatorFn)
useDefinitionSchema->>DefinitionSchemaParserContext: Retrieves context
useDefinitionSchema->>SchemaCreator: Calls creatorFn(context)
SchemaCreator->>ReferenceMarkers: Uses ctx.withRef/withEnt/withRefBuilder to define schema
SchemaCreator-->>useDefinitionSchema: Returns Zod schema with markers
useDefinitionSchema-->>UI_Component: Returns ready-to-use schema
UI_Component->>Form: Passes schema for validation/parsing
Form->>ReferenceMarkers: Handles reference/entity markers during parse
Loading
sequenceDiagram
participant Deserializer
participant deserializeSchemaWithTransformedReferences
participant SchemaCreator
participant extractDefinitionRefs
participant resolveReferencesToIds

Deserializer->>deserializeSchemaWithTransformedReferences: Provide schemaCreator, input, options
deserializeSchemaWithTransformedReferences->>SchemaCreator: Call with context to get schema
deserializeSchemaWithTransformedReferences->>extractDefinitionRefs: Extract references/entities from input
extractDefinitionRefs-->>deserializeSchemaWithTransformedReferences: Return payload (data, refs, entities)
deserializeSchemaWithTransformedReferences->>resolveReferencesToIds: Resolve names to IDs in data
resolveReferencesToIds-->>deserializeSchemaWithTransformedReferences: Return fully resolved data
deserializeSchemaWithTransformedReferences-->>Deserializer: Return parsed, reference-resolved output
Loading

Possibly related PRs

  • halfdomelabs/baseplate#553: Migrates project definition schema handling to a creator pattern, closely related to this PR's schema creator/context refactor.
  • halfdomelabs/baseplate#578: Refactors schema handling to use schema creators and context-based APIs, directly connected to the transform-based reference handling and deserialization changes in this PR.
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedeslint-plugin-unused-imports@​4.1.41001008983100

View full report

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR migrates the project’s reference-handling system from a Zod‐based wrapper approach (ZodRef) to a new transform‐based architecture powered by definitionSchema and context builders (withRef, withEnt, withRefBuilder). Key changes include:

  • Replacing all zEnt/zRef/zRefBuilder usages with ctx.withEnt/ctx.withRef/ctx.withRefBuilder inside definitionSchema creators.
  • Introducing a unified useDefinitionSchema hook in place of usePluginEnhancedSchema and updating all React components to consume context‐aware schemas.
  • Refactoring core reference serialization, deserialization, and deletion logic to use transformed references, updating unit/integration tests accordingly.

Reviewed Changes

Copilot reviewed 96 out of 97 changed files in this pull request and generated no comments.

File Description
packages/project-builder-lib/src/references/deserialize-schema.ts Updated to use transform‐based parsing (parseSchemaWithTransformedReferences) but missing imports for Zod types in the signature.
plugins/plugin-auth/src/roles/schema.ts Refined createAuthRolesSchema, but an extra closing bracket was introduced in the .superRefine chain.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (2)

packages/project-builder-lib/src/references/deserialize-schema.ts:37

  • The return type references z.ZodType and TypeOf but neither z nor TypeOf are imported in this file. Add import { z, TypeOf } from 'zod' or switch to def.InferOutput<T> to ensure the type annotation compiles correctly.
  ReturnType<T> extends z.ZodType ? TypeOf<ReturnType<T>> : unknown

plugins/plugin-auth/src/roles/schema.ts:66

  • In the createAuthRolesSchema definition, the extra ] before the closing parenthesis causes a syntax error. The chain should end with ).superRefine(...))—remove the stray ] so the parentheses properly match the array(...).superRefine(...) call.
    ]),

@kingston kingston merged commit b6bc11f into main Jul 3, 2025
11 checks passed
@kingston kingston deleted the kingston/eng-749-convert-ref-system-to-use-new-ref-plan branch July 3, 2025 15:49
@github-actions github-actions Bot mentioned this pull request Jul 3, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Nov 28, 2025
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.

2 participants