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

Add support for custom objects that will correctly type to DataType - #192

Merged
jhaynie merged 1 commit into
mainfrom
datatype-custom
Oct 4, 2025
Merged

jhaynie merged 1 commit into
mainfrom
datatype-custom

Conversation

@jhaynie

@jhaynie jhaynie commented Oct 4, 2025 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Improved DataType handling to accept any valid custom JSON-like objects, including nested and mixed structures.
  • Tests
    • Added comprehensive tests covering acceptance of various JSON shapes and binary/stream inputs, plus edge cases for robustness.
  • Chores
    • Bumped version to 0.0.150.
    • Updated changelog with details of the fix.

@coderabbitai

coderabbitai Bot commented Oct 4, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds version 0.0.150, updates JsonPrimitive typing to accept arbitrary valid custom objects as JSON, and introduces a comprehensive test suite validating DataType and JSON object acceptance. No changes to runtime control flow.

Changes

Cohort / File(s) Summary
Versioning & Changelog
CHANGELOG.md, package.json
Added changelog entry for 0.0.150; bumped package version from 0.0.149 to 0.0.150.
Types Update
src/types.ts
Expanded JsonPrimitive to include { [key: string]: JsonPrimitive }, enabling arbitrary object-like JSON support.
Tests: DataType & JSON Objects
test/types/datatype.test.ts
Added tests for isDataType and JSON object validation across primitives, buffers/streams, nested objects/arrays, and edge cases.

Sequence Diagram(s)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

A rabbit taps its debug drum,
“New types hop in—make JSON hum!”
Buffers, streams, and objects too,
Nested burrows passing through.
Version bumps with gentle cheer—
0.0.150’s here! 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title clearly indicates that the primary goal is to support custom objects in DataType typing, which directly matches the updates to the JsonPrimitive definition and the added tests for object support. It succinctly captures the main change without unnecessary detail or ambiguity.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ 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 datatype-custom

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/types.ts (1)

196-203: Consider consolidating redundant type definitions.

Adding { [key: string]: JsonPrimitive } to JsonPrimitive creates logical redundancy with JsonObject (line 218), which already permits string keys via JsonKey. While this addition may improve TypeScript's type inference for plain object literals, it introduces maintenance overhead and potential confusion.

Consider these alternatives:

  • Simplify by relying solely on JsonObject if type inference proves sufficient after testing
  • Document why both forms are needed if TypeScript inference genuinely requires the explicit index signature
  • Ensure future changes keep both definitions synchronized

Alternative approach (if TypeScript inference works without the extra union member):

 export type JsonPrimitive =
 	| string
 	| number
 	| boolean
 	| null
 	| JsonArray
-	| JsonObject
-	| { [key: string]: JsonPrimitive };
+	| JsonObject;

If the explicit index signature is necessary for type inference, add a comment explaining why:

 export type JsonPrimitive =
 	| string
 	| number
 	| boolean
 	| null
 	| JsonArray
 	| JsonObject
+	// Explicit index signature improves TypeScript inference for plain object literals
 	| { [key: string]: JsonPrimitive };
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6c6e9ad and ed8848d.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • CHANGELOG.md (1 hunks)
  • package.json (1 hunks)
  • src/types.ts (1 hunks)
  • test/types/datatype.test.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
{src,test}/**/!(*.d).ts

📄 CodeRabbit inference engine (AGENT.md)

{src,test}/**/!(*.d).ts: Use strict TypeScript and prefer unknown over any
Use ESM import/export syntax; avoid CommonJS require/module.exports
Use relative imports for internal modules
Keep imports organized (sorted, no unused imports)
Use tabs with a visual width of 2 spaces
Limit lines to a maximum of 80 characters
Use single quotes for strings
Use proper Error types; do not throw strings
Prefer template literals over string concatenation

Files:

  • src/types.ts
  • test/types/datatype.test.ts
test/**

📄 CodeRabbit inference engine (AGENT.md)

Tests must mirror the source structure under the test/ directory

Files:

  • test/types/datatype.test.ts
🧬 Code graph analysis (1)
test/types/datatype.test.ts (1)
src/types.ts (3)
  • isDataType (167-191)
  • DataType (144-152)
  • isJsonObject (233-256)
🔇 Additional comments (3)
package.json (1)

3-3: LGTM: Version bump is consistent.

The version bump to 0.0.150 aligns with the CHANGELOG entry documenting the JsonPrimitive type fix.

test/types/datatype.test.ts (1)

1-206: Excellent test coverage!

The test suite is comprehensive and well-structured, covering:

  • All DataType variants (Buffer, Uint8Array, ArrayBuffer, Blob, ReadableStream, strings)
  • Custom object shapes including nested structures, mixed primitives, and arrays
  • Edge cases like empty objects/arrays and deeply nested structures
  • Data objects with contentType property
  • Proper rejection of null/undefined

The tests effectively validate the expanded JsonPrimitive type and ensure DataType accepts arbitrary valid JSON objects.

CHANGELOG.md (1)

3-7: LGTM: Changelog entry is accurate.

The changelog clearly documents the patch change for version 0.0.150, accurately describing the fix to support arbitrary valid custom objects as Json in DataType.

@jhaynie
jhaynie merged commit 53d9ebc into main Oct 4, 2025
3 checks passed
@jhaynie
jhaynie deleted the datatype-custom branch October 4, 2025 13:50
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.

1 participant