Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

chore(orm): export JSON types#476

Merged
ymc9 merged 1 commit intodevfrom
chore/export-json-types
Dec 12, 2025
Merged

chore(orm): export JSON types#476
ymc9 merged 1 commit intodevfrom
chore/export-json-types

Conversation

@ymc9
Copy link
Copy Markdown
Member

@ymc9 ymc9 commented Dec 12, 2025

Summary by CodeRabbit

  • Refactor

    • Consolidated null-value type definitions and JSON type exports into a centralized module for improved consistency and maintainability.
  • Breaking Changes

    • Removed null-value type exports from the client entry point; these are now available from the main package export.
    • JSON type imports may require updated import paths in consuming code.

✏️ Tip: You can customize this high-level summary in your review settings.

Copilot AI review requested due to automatic review settings December 12, 2025 06:45
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 12, 2025

Walkthrough

Consolidate null sentinel class definitions and JSON type definitions from distributed modules (client/null-values.ts, utils/type-utils.ts) into centralized common-types.ts, and update import paths across the codebase accordingly.

Changes

Cohort / File(s) Summary
Centralized type definitions
packages/orm/src/common-types.ts
Added null sentinel classes (DbNullClass, JsonNullClass, AnyNullClass) with private branding fields, corresponding singleton instances (DbNull, JsonNull, AnyNull), and JSON type definitions (JsonValue, JsonObject, JsonArray, JsonNullValues).
Updated import paths
packages/orm/src/client/crud-types.ts, packages/orm/src/client/crud/dialects/base-dialect.ts, packages/orm/src/client/crud/dialects/postgresql.ts, packages/orm/src/client/crud/dialects/sqlite.ts, packages/orm/src/client/crud/validator/index.ts
Changed import source for null value classes from ./null-values or ../../null-values to ../../../common-types or ../../../../common-types.
Public API changes
packages/orm/src/client/index.ts
Removed re-exports of AnyNull, DbNull, and JsonNull from ./null-values.
Type cleanup
packages/orm/src/utils/type-utils.ts
Removed public exports of JsonValue, JsonObject, JsonArray, and JsonNullValues. Updated imports from ../client/null-values to ../common-types.
Module removal
packages/orm/src/client/null-values.ts
Removed all exported class definitions (DbNullClass, JsonNullClass, AnyNullClass), singleton constants (DbNull, JsonNull, AnyNull), and their type aliases.
Root export updates
packages/orm/src/index.ts
Added re-export of entire ./common-types module. Removed re-exports of JsonArray, JsonObject, JsonValue from ./utils/type-utils.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Verify import path correctness: Ensure all import statements in updated files reference the correct paths in common-types.ts
  • Type definition equivalence: Confirm that moved null sentinel classes and JSON types in common-types.ts are semantically identical to their original definitions
  • Breaking API changes: Review removal of null value re-exports from client/index.ts for downstream impact on public API consumers
  • Circular dependency check: Verify no circular dependencies introduced between common-types.ts and other modules

Possibly related PRs

  • feat(orm): implement json filters #472: Updates JsonFilter usage in packages/orm/src/client/crud-types.ts that directly interacts with the centralized JsonValue and JsonNullValues types being introduced in this PR.

Poem

🐰 Hops with glee through scattered debris,
Gathering nulls from branches of tree,
One common home where types now roam,
Our branded sentinels perfectly agree!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the PR: consolidating and exporting JSON-related types from a centralized location (common-types module).
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/export-json-types

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Dec 12, 2025

Claude finished @ymc9's task —— View job


Code Review Analysis ✅

I'll review this PR that exports JSON types. Let me analyze the changes systematically.

Todo List

  • Read and analyze the deleted file (null-values.ts)
  • Read and analyze the new common-types.ts file
  • Review import/export changes across affected files
  • Check for potential breaking changes
  • Provide comprehensive review feedback

Review Summary

This PR is a clean refactoring that consolidates JSON-related types into a centralized location. The changes improve code organization and make JSON types more accessible across the ORM package.

Changes Overview

🔄 File Movement & Consolidation

  • Deleted: packages/orm/src/client/null-values.ts
  • Created: packages/orm/src/common-types.ts
  • Impact: Moved JSON null handling classes and types from client-specific to common location

🔧 Type Definitions Moved

The following types and classes were moved from null-values.ts to common-types.ts:

JSON Value Types:

  • JsonValue - Union of JSON value types
  • JsonObject - JSON object type
  • JsonArray - JSON array type

Null Handling Classes:

  • DbNullClass & DbNull - Database null representation
  • JsonNullClass & JsonNull - JSON null representation
  • AnyNullClass & AnyNull - Any null representation
  • JsonNullValues - Union type for all null values

🔗 Import Updates

All affected files properly updated their imports:

// Before
import { DbNullClass, JsonNullClass } from '../null-values';

// After  
import { DbNullClass, JsonNullClass } from '../../../common-types';

Positive Aspects

  1. Better Organization: Moving JSON types to a common location improves discoverability
  2. Consistent Exports: All types are properly exported from packages/orm/src/index.ts
  3. Clean Refactoring: No logic changes, just reorganization
  4. Proper Import Updates: All imports correctly updated with relative paths
  5. Type Safety: Maintains existing type safety and contracts

Issues Found

1. Missing Type Exports in index.ts

The main index.ts file exports everything from common-types, but it should use export type * for pure types:

Current (packages/orm/src/index.ts):

export * from './common-types';  // Line 2

Suggested:

export type * from './common-types';

The classes (DbNull, JsonNull, AnyNull) should remain as value exports, but the pure types (JsonValue, JsonObject, etc.) should be type-only exports.

2. Potential Bundle Size Impact

By making JSON types more accessible via the main index, this could increase bundle size for consumers who don't need JSON functionality. However, this is likely minimal impact and worth the improved DX.

🎯 Recommendations

High Priority

  1. Fix Export Types: Use export type * pattern for pure types in index.ts to avoid unnecessary runtime imports

Optional Improvements

  1. Add JSDoc Comments: Consider adding documentation to the exported types in common-types.ts
  2. Validation: Run the build/tests to ensure no breaking changes for consumers

🔍 Breaking Change Analysis

✅ No Breaking Changes Expected:

  • All types maintain the same names and signatures
  • Import paths change but types remain exported from main index
  • Existing user code should continue working without modification

🧪 Testing Recommendation

The refactoring looks solid, but I recommend:

  1. Running the full test suite to verify no regressions
  2. Checking that TypeScript compilation works correctly
  3. Verifying that generated type definitions include the new exports

Overall Assessment

This is a well-executed refactoring that improves code organization without introducing breaking changes. The main issue is a minor export optimization that should be addressed before merging.

Recommendation: Approve with minor fix

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 consolidates JSON-related types and null value types by moving them from their scattered locations (packages/orm/src/utils/type-utils.ts and packages/orm/src/client/null-values.ts) into a new central file packages/orm/src/common-types.ts. The types are now exported from the main package entry point, making them more accessible to external consumers.

Key changes:

  • Created packages/orm/src/common-types.ts containing JSON types (JsonValue, JsonObject, JsonArray, JsonNullValues) and null value classes (DbNullClass, JsonNullClass, AnyNullClass)
  • Updated all internal imports across dialect files, validators, and type utilities to reference the new location
  • Removed the old packages/orm/src/client/null-values.ts file and related type definitions from type-utils.ts

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/orm/src/common-types.ts New file centralizing JSON types and null value types with their class implementations
packages/orm/src/index.ts Added export for common-types module, removed redundant type-specific exports
packages/orm/src/client/index.ts Removed null value exports (now exported from main index)
packages/orm/src/client/null-values.ts Deleted file, moved to common-types.ts
packages/orm/src/utils/type-utils.ts Removed JSON type definitions, now imported from common-types
packages/orm/src/client/crud-types.ts Updated imports to reference common-types module
packages/orm/src/client/crud/validator/index.ts Updated imports to reference common-types module
packages/orm/src/client/crud/dialects/base-dialect.ts Updated imports to reference common-types module
packages/orm/src/client/crud/dialects/postgresql.ts Updated imports to reference common-types module
packages/orm/src/client/crud/dialects/sqlite.ts Updated imports to reference common-types module

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/orm/src/common-types.ts
Comment thread packages/orm/src/common-types.ts
Comment thread packages/orm/src/common-types.ts
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
packages/orm/src/common-types.ts (1)

6-25: Prefer a less-blunt branding approach than // @ts-ignore (if lint rules allow).

If your lint setup supports it, consider swapping // @ts-ignore for a targeted disable (eslint) or a declare private readonly brand field to keep the nominal typing without suppressing type-checking broadly.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 96629ed and fc76247.

📒 Files selected for processing (10)
  • packages/orm/src/client/crud-types.ts (1 hunks)
  • packages/orm/src/client/crud/dialects/base-dialect.ts (1 hunks)
  • packages/orm/src/client/crud/dialects/postgresql.ts (1 hunks)
  • packages/orm/src/client/crud/dialects/sqlite.ts (1 hunks)
  • packages/orm/src/client/crud/validator/index.ts (1 hunks)
  • packages/orm/src/client/index.ts (0 hunks)
  • packages/orm/src/client/null-values.ts (0 hunks)
  • packages/orm/src/common-types.ts (1 hunks)
  • packages/orm/src/index.ts (1 hunks)
  • packages/orm/src/utils/type-utils.ts (1 hunks)
💤 Files with no reviewable changes (2)
  • packages/orm/src/client/index.ts
  • packages/orm/src/client/null-values.ts
🧰 Additional context used
🧠 Learnings (5)
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to packages/zenstackhq/orm/**/*.{ts,tsx} : Implement plugin hooks at ORM, Kysely, and entity mutation levels for query interception and customization

Applied to files:

  • packages/orm/src/index.ts
  • packages/orm/src/client/crud/dialects/base-dialect.ts
  • packages/orm/src/client/crud/dialects/sqlite.ts
  • packages/orm/src/client/crud/dialects/postgresql.ts
  • packages/orm/src/client/crud/validator/index.ts
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to packages/zenstackhq/orm/**/*.{ts,tsx} : Use Kysely as the query builder interface for low-level database queries, avoiding raw SQL when possible

Applied to files:

  • packages/orm/src/index.ts
  • packages/orm/src/client/crud/dialects/base-dialect.ts
  • packages/orm/src/client/crud/dialects/sqlite.ts
  • packages/orm/src/client/crud-types.ts
  • packages/orm/src/client/crud/dialects/postgresql.ts
  • packages/orm/src/client/crud/validator/index.ts
  • packages/orm/src/utils/type-utils.ts
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to packages/zenstackhq/orm/**/*.test.{ts,tsx} : ORM package tests should include comprehensive client API tests and policy tests

Applied to files:

  • packages/orm/src/index.ts
  • packages/orm/src/client/crud/validator/index.ts
📚 Learning: 2025-10-21T16:09:31.218Z
Learnt from: ymc9
Repo: zenstackhq/zenstack-v3 PR: 319
File: packages/runtime/src/client/executor/zenstack-query-executor.ts:63-72
Timestamp: 2025-10-21T16:09:31.218Z
Learning: In ZenStack, TypeDefs can be inherited by models. When a TypeDef contains fields with `map` attributes, those mapped field names need to be processed by the QueryNameMapper since they become part of the inheriting model's schema. Therefore, when checking if a schema has mapped names (e.g., in `schemaHasMappedNames`), both `schema.models` and `schema.typeDefs` must be inspected for `@map` and `map` attributes.

Applied to files:

  • packages/orm/src/client/crud/dialects/sqlite.ts
  • packages/orm/src/client/crud/dialects/postgresql.ts
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to **/*.zmodel : ZModel schema files should define database structure and policies that compile to TypeScript via `zenstack generate`

Applied to files:

  • packages/orm/src/client/crud/dialects/postgresql.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Agent
  • GitHub Check: build-test (20.x, postgresql)
  • GitHub Check: build-test (20.x, sqlite)
🔇 Additional comments (6)
packages/orm/src/client/crud/dialects/sqlite.ts (1)

13-13: Import move to common-types looks safe.

packages/orm/src/client/crud/dialects/base-dialect.ts (1)

5-5: Import move to common-types looks safe.

packages/orm/src/client/crud/validator/index.ts (1)

6-6: Import move to common-types looks safe.

packages/orm/src/client/crud/dialects/postgresql.ts (1)

14-14: Import move to common-types looks safe.

packages/orm/src/client/crud-types.ts (1)

2-2: Type-only import from common-types is appropriate here.

packages/orm/src/utils/type-utils.ts (1)

2-2: Importing Json types from common-types is a good consolidation.*

Comment thread packages/orm/src/common-types.ts
Comment thread packages/orm/src/index.ts
@ymc9 ymc9 merged commit 618a96e into dev Dec 12, 2025
14 checks passed
@ymc9 ymc9 deleted the chore/export-json-types branch December 12, 2025 06:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants