Skip to content

fix: prevent jsonPath method from being serialized in schema output#125

Merged
rmorehig merged 2 commits intomainfrom
fix/issue-124-jsonpath-method-serialization
Mar 7, 2026
Merged

fix: prevent jsonPath method from being serialized in schema output#125
rmorehig merged 2 commits intomainfrom
fix/issue-124-jsonpath-method-serialization

Conversation

@jorgesancha
Copy link
Collaborator

Summary

Fixes #124

When running tinybird build, generated .datasource files contained the entire jsonPath method body instead of proper JSON path values:

timestamp DateTime `json:jsonPath(path) {
    return createValidator(tinybirdType, {
      ...modifiers,
      jsonPath: path,
    });
  }`,

Root Cause

In getColumnJsonPath() at src/schema/datasource.ts, when isTypeValidator(column) returns false (which can happen due to cross-module Symbol issues between the CLI's SDK and the user's installed SDK), the code fell through to check:

if (column.jsonPath !== undefined) {
  return column.jsonPath;
}

Since TypeValidator objects have a jsonPath method, this condition was truthy, causing the function itself to be returned. When interpolated in a template literal during schema generation, the function's .toString() was called, producing the function body in the output.

Fix

Changed the check to verify jsonPath is actually a string value:

if (typeof column.jsonPath === "string") {
  return column.jsonPath;
}

This ensures we only return jsonPath when it's a valid string path, not when it's a function reference.

Test Plan

  • Added test to verify getColumnJsonPath never returns a function
  • All existing datasource and generator tests pass

🤖 Generated with Claude Code

When isTypeValidator() returns false due to cross-module Symbol issues,
getColumnJsonPath() fell through to check `column.jsonPath !== undefined`.
Since validators have a jsonPath method, this returned the function itself,
which got stringified in the generated .datasource files.

Fix: check `typeof column.jsonPath === "string"` instead.

Bumps version to 0.0.59.

Fixes #124

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jorgesancha jorgesancha requested a review from rmorehig March 7, 2026 13:30
@jorgesancha
Copy link
Collaborator Author

I found out that this issue showed up because I had an older version installed globally (0.46) and the latest one installed locally (0.58), so an incompatibility between 0.58 and the tinybird client in 0.46 caused this.

Bash(tinybird --version 2>&1)
  ⎿  0.0.46

                                                                                                                                                           02:45 PM claude-opus-4-6
⏺ The global CLI (0.0.46) is older than the local SDK (0.0.58). The mismatch could be the issue. Let me update the global CLI and retry.

⏺ Bash(npm install -g @tinybirdco/sdk@latest && tinybird --version)
  ⎿  changed 12 packages in 961ms

     4 packages are looking for funding
       run `npm fund` for details
     0.0.46

                                                                                                                                                           02:45 PM claude-opus-4-6
⏺ Let me try using the local SDK version instead.

⏺ Bash(source .env.local && npx tinybird build 2>&1)
  ⎿  » Git branch:      feat/tinybird-integration
     » Tinybird branch: feat_tinybird_integration existing

     Building...
     ✓ top_pages.pipe changed

     ✓ Build completed in 840ms

                                                                                                                                                           02:45 PM claude-opus-4-6
⏺ Build succeeded with npx tinybird. The global CLI was outdated. Let me reinstall the global one properly.

⏺ Bash(npm uninstall -g @tinybirdco/sdk && npm install -g @tinybirdco/sdk@0.0.58 && tinybird --version)
  ⎿  removed 12 packages in 352ms

     added 12 packages in 892ms

     4 packages are looking for funding
       run `npm fund` for details
     0.0.46

∴ Thinking…

  The CLI version stays at 0.0.46 even with the 0.0.58 package. They must have different version numbers for the CLI binary vs the npm package. The issue is that the globally installed
  version's CLI binary is older. Using npx works because it uses the local node_modules version. Let's just recommend using npx tinybird going forward. Let me verify the build output to
  show the user the environment link.

                                                                                                                                                           02:46 PM claude-opus-4-6
⏺ The global CLI binary version differs from the npm package version. Use npx tinybird to ensure you're using the local version. The build succeeded - the top_pages.pipe was created

@rmorehig rmorehig merged commit a90885b into main Mar 7, 2026
2 checks passed
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.

When following the Installation prompt, the datasource creation leaded some TypeScript code into the data source

2 participants