Skip to content

Add namespacePrefix option to share one component across aggregates - #286

Closed
reeceyang wants to merge 1 commit into
mainfrom
reece/namespace-prefix
Closed

reeceyang wants to merge 1 commit into
mainfrom
reece/namespace-prefix

Conversation

@reeceyang

@reeceyang reeceyang commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Adds a namespacePrefix option to TableAggregate and DirectAggregate so multiple aggregates can share one component instance, instead of needing an app.use per aggregate. The client stores namespace ns as [prefix, ns] in the existing btree table, and paginateNamespaces range-scans the existing by_namespace index for a prefix, so upgrading needs no schema change or index backfill.

Stack

🤖 Generated with Claude Code

@reeceyang
reeceyang marked this pull request as draft November 10, 2026 01:15

@cubic-dev-ai cubic-dev-ai Bot 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.

1 issue found across 6 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/client/index.ts">

<violation number="1" location="src/client/index.ts:135">
P2: This encoding collides with valid unprefixed array namespaces: an unprefixed aggregate using `namespace: ["byAlbum", "x"]` shares the same tree as the prefixed aggregate `namespacePrefix: "byAlbum"` using `namespace: "x"`. Use a storage encoding that cannot overlap supported unprefixed namespaces, or explicitly reject this collision before enabling prefixes.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/client/index.ts
}
return ns === undefined
? [this.namespacePrefix]
: [this.namespacePrefix, ns];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: This encoding collides with valid unprefixed array namespaces: an unprefixed aggregate using namespace: ["byAlbum", "x"] shares the same tree as the prefixed aggregate namespacePrefix: "byAlbum" using namespace: "x". Use a storage encoding that cannot overlap supported unprefixed namespaces, or explicitly reject this collision before enabling prefixes.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/client/index.ts, line 135:

<comment>This encoding collides with valid unprefixed array namespaces: an unprefixed aggregate using `namespace: ["byAlbum", "x"]` shares the same tree as the prefixed aggregate `namespacePrefix: "byAlbum"` using `namespace: "x"`. Use a storage encoding that cannot overlap supported unprefixed namespaces, or explicitly reject this collision before enabling prefixes.</comment>

<file context>
@@ -110,13 +110,55 @@ export class Aggregate<
+    }
+    return ns === undefined
+      ? [this.namespacePrefix]
+      : [this.namespacePrefix, ns];
+  }
+
</file context>

@reeceyang
reeceyang marked this pull request as ready for review November 10, 2026 21:30

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 6 files

Re-trigger cubic

@reeceyang

Copy link
Copy Markdown
Contributor Author

@ianmacartney thoughts on this approach? this makes it so you can set the "name" of the aggregate when defining the client for the aggregate, and you don't need to pass it in to each aggregate call.

@ianmacartney ianmacartney left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like it! Assuming this can be used all the places users currently use separate aggregates, I think this is a good direction. I'd be interested in what a migration path looks like (could just be a readme explaining how to set up the dual-write setup / backfill process)

@reeceyang

Copy link
Copy Markdown
Contributor Author

From Claude: closing in favor of the named-aggregates approach in #292 and #278.

@reeceyang reeceyang closed this Nov 17, 2026
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