Skip to content

Dev#159

Merged
robertjbass merged 6 commits intomainfrom
dev
Apr 1, 2026
Merged

Dev#159
robertjbass merged 6 commits intomainfrom
dev

Conversation

@robertjbass
Copy link
Copy Markdown
Owner

@robertjbass robertjbass commented Apr 1, 2026

Summary by CodeRabbit

  • New Features

    • Added a CLI option to override the SurrealDB query namespace (useful for running queries against non-default namespaces).
  • Bug Fixes

    • Query execution now defaults to the 'default' namespace instead of deriving it from instance names, improving reliability.
  • Documentation

    • Changelog updated for versions 0.47.11 and 0.47.12 reflecting the namespace behavior and CLI flag.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 1, 2026

Warning

Rate limit exceeded

@robertjbass has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 44 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 5 minutes and 44 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1f450ab1-6493-4790-9d04-d644830795ee

📥 Commits

Reviewing files that changed from the base of the PR and between 2ab472f and 4fbd7e5.

📒 Files selected for processing (5)
  • CHANGELOG.md
  • cli/commands/query.ts
  • engines/surrealdb/index.ts
  • package.json
  • types/index.ts
📝 Walkthrough

Walkthrough

Adds a CLI --namespace option for spindb query, passes an optional options.namespace through to SurrealDBEngine.executeQuery (which no longer solely derives namespace from the container name), computes/logs defaultUser once in SurrealDBEngine.start, and bumps package version to 0.47.12 with corresponding CHANGELOG entries.

Changes

Cohort / File(s) Summary
Release & Changelog
CHANGELOG.md, package.json
Bumped package version to 0.47.12 and added changelog entries documenting SurrealDB namespace/executeQuery fixes.
CLI: query command
cli/commands/query.ts
Added -n, --namespace <name> option and thread namespace?: string through action options into queryOpts passed to engine.executeQuery.
SurrealDB engine
engines/surrealdb/index.ts
executeQuery now honors options.namespace (falls back to previously derived namespace only if unset). start computes defaultUser once and adds debug logging around credential loading.
Docs / Notes
CLAUDE.md
Added planned improvements and proposals around normalizing executeQuery results and moving engine credential/config generation into spindb create.

Sequence Diagram(s)

sequenceDiagram
  participant CLI as CLI (spindb query)
  participant Engine as SurrealDBEngine
  participant DB as SurrealDB

  CLI->>Engine: call executeQuery(query, { database, namespace? })
  alt namespace provided
    Engine->>DB: run query in provided namespace
  else namespace not provided
    Engine->>DB: derive namespace from container/name and run query
  end
  DB-->>Engine: query results
  Engine-->>CLI: return results
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Dev #155: Modifies SurrealDB startup/credential handling touching SurrealDBEngine.start.
  • Dev #158: Refactors credential-loading logic in SurrealDBEngine.start, related to how default username/credentials are loaded.
  • fix: add query auth support for all engines #147: Related changes to credential loading and engine startup behavior affecting the same engine code paths.

Poem

🐰 I found a namespace, hopping light and spry,
A flag to guide queries across the sky.
Logs whisper usernames, tidy and neat,
Version bumped—new steps for each tiny feet. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Dev' is vague and does not convey any meaningful information about the changeset, which includes namespace override support, query options, version bumps, and documentation. Use a descriptive title that summarizes the main change, such as 'Add namespace override support for SurrealDB queries' or 'Support custom namespace in query command'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev

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.

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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@engines/surrealdb/index.ts`:
- Around line 1014-1017: The namespace is hardcoded to 'default' (const
namespace = 'default') causing mismatch with other methods that derive
namespaces via name.replace(/-/g, '_'); update the namespace determination to
use the same logic as other methods (e.g., derive namespace from the container
name with name.replace(/-/g, '_') or use an explicit options.namespace when
provided) so connect(), createDatabase(), listDatabases(), createUser(), and
executeQuery() all use the same computed namespace; locate the const namespace
declaration and replace the hardcoded value with the shared namespace-resolution
logic used elsewhere in this class (or fallback to options.namespace if
present).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 07839920-b3d3-4375-8ee4-d338193628ad

📥 Commits

Reviewing files that changed from the base of the PR and between ccbf04d and 31d22fe.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • engines/surrealdb/index.ts
  • package.json

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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cli/commands/query.ts`:
- Around line 247-258: The code is bypassing TypeScript safety by building
queryOpts as Record<string, unknown> and then casting to QueryOptions before
calling engine.executeQuery; add a namespace?: string field to the QueryOptions
interface in types/index.ts so it formally accepts namespace, then change the
local variable in cli/commands/query.ts to be typed as QueryOptions (populate
namespace when options.namespace is present) and remove the final as
QueryOptions cast so engine.executeQuery receives a properly typed object (this
will also remove the brittle double-cast used later in
engines/surrealdb/index.ts:1015).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4f7286b8-012f-4d31-a294-b733ab2ab1c6

📥 Commits

Reviewing files that changed from the base of the PR and between 31d22fe and 2ab472f.

📒 Files selected for processing (5)
  • CHANGELOG.md
  • CLAUDE.md
  • cli/commands/query.ts
  • engines/surrealdb/index.ts
  • package.json
✅ Files skipped from review due to trivial changes (2)
  • package.json
  • CLAUDE.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • engines/surrealdb/index.ts
  • CHANGELOG.md

Comment on lines +247 to +258
const queryOpts: Record<string, unknown> = {
database,
...remoteQueryOptions,
})
}
if (options.namespace) {
queryOpts.namespace = options.namespace
}
const result = await engine.executeQuery(
config,
query,
queryOpts as QueryOptions,
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Verify QueryOptions contract and cast-based namespace usage:"
rg -n -C2 "export type QueryOptions|namespace\?:|as QueryOptions|Record<string, unknown>|\\.namespace" \
  types/index.ts cli/commands/query.ts engines/surrealdb/index.ts

Repository: robertjbass/spindb

Length of output: 2882


Promote namespace into the typed query contract (avoid cast-based bypass).

Lines 247 and 257 currently bypass TypeScript safety (Record<string, unknown> + as QueryOptions). This hides a real contract gap: the command accepts namespace (line 93) and passes it to executeQuery, but QueryOptions does not declare it. The SurrealDB engine then casts back to access it (engines/surrealdb/index.ts:1015), creating brittle double-casting.

Suggested fix

In types/index.ts, add namespace to QueryOptions:

 export type QueryOptions = {
   database?: string
+  namespace?: string
   method?: 'GET' | 'POST' | 'PUT' | 'DELETE'
   body?: Record<string, unknown>
   host?: string
   password?: string
   username?: string
   ssl?: boolean
   scheme?: string
 }

Then in cli/commands/query.ts, use the proper type:

-const queryOpts: Record<string, unknown> = {
+const queryOpts: QueryOptions = {
   database,
   ...remoteQueryOptions,
 }
 if (options.namespace) {
   queryOpts.namespace = options.namespace
 }
 const result = await engine.executeQuery(
   config,
   query,
-  queryOpts as QueryOptions,
+  queryOpts,
 )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const queryOpts: Record<string, unknown> = {
database,
...remoteQueryOptions,
})
}
if (options.namespace) {
queryOpts.namespace = options.namespace
}
const result = await engine.executeQuery(
config,
query,
queryOpts as QueryOptions,
)
const queryOpts: QueryOptions = {
database,
...remoteQueryOptions,
}
if (options.namespace) {
queryOpts.namespace = options.namespace
}
const result = await engine.executeQuery(
config,
query,
queryOpts,
)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cli/commands/query.ts` around lines 247 - 258, The code is bypassing
TypeScript safety by building queryOpts as Record<string, unknown> and then
casting to QueryOptions before calling engine.executeQuery; add a namespace?:
string field to the QueryOptions interface in types/index.ts so it formally
accepts namespace, then change the local variable in cli/commands/query.ts to be
typed as QueryOptions (populate namespace when options.namespace is present) and
remove the final as QueryOptions cast so engine.executeQuery receives a properly
typed object (this will also remove the brittle double-cast used later in
engines/surrealdb/index.ts:1015).

@robertjbass robertjbass merged commit bf72b09 into main Apr 1, 2026
134 of 136 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.

1 participant