fix: complete @objectstack/objectql mock and fix bridge driver naming#392
fix: complete @objectstack/objectql mock and fix bridge driver naming#392
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…stack/objectql mock and fix bridge driver naming Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes ObjectQL bridge + test mock behavior so CLI sync and related tests can resolve datasources and exercise the same hook/middleware paths as upstream @objectstack/objectql.
Changes:
- Always set
driver.nameto the datasource config key in theObjectQLbridge sodatasource('default')resolves correctly. - Expand the
@objectstack/objectqltest mock to include missing engine APIs (init(),datasource(),getDriverByName(),on()) and CRUD hook execution for mutations. - Add
count()to mock repositories with a driver-backed implementation + fallback.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/foundation/core/src/app.ts | Forces datasource driver naming to match config keys to make datasource(name) lookups work. |
| packages/foundation/core/test/mocks/@objectstack/objectql.ts | Completes the upstream-like mock API and adds hook/middleware behavior around CRUD operations. |
| // Fetch previous data for hooks that need it | ||
| let previousData: any; | ||
| if (driver?.findOne) { | ||
| try { previousData = await driver.findOne(name, { _id: id }); } catch (_e) { /* ignore */ } |
There was a problem hiding this comment.
driver.findOne is being called with { _id: id } as the id argument. All in-repo drivers use the signature findOne(objectName, id, query?, options?), so this call will look up a record with id "[object Object]" and previousData will always be undefined, breaking hooks that rely on it (e.g., multitenancy/validator). Call driver.findOne(name, id, undefined, options) (or driver.findOne(name, id) if options aren’t needed) to fetch the prior record.
| try { previousData = await driver.findOne(name, { _id: id }); } catch (_e) { /* ignore */ } | |
| try { previousData = await driver.findOne(name, id, undefined, options); } catch (_e) { /* ignore */ } |
| let previousData: any; | ||
| if (driver?.findOne) { | ||
| try { previousData = await driver.findOne(name, { _id: id }); } catch (_e) { /* ignore */ } | ||
| } |
There was a problem hiding this comment.
Same issue as update(): driver.findOne(name, { _id: id }) passes an object into the id parameter, so drivers won’t return the existing record and previousData will be missing in before/afterDelete hooks. Use driver.findOne(name, id, undefined, options) (or driver.findOne(name, id)) instead.
All CLI sync command tests fail with
app.datasource is not a function. Additional test failures in project-tracker and enterprise-erp were masked by turbo cache.Two root causes:
Bridge driver naming (
packages/foundation/core/src/app.ts)The constructor conditionally set
driver.name = configKeyonly when!driver.name. SinceSqlDriverdeclaresreadonly name = 'SqlDriver'(truthy), drivers were registered under their class name instead of the config key, sodatasource('default')never resolved.Incomplete mock (
packages/foundation/core/test/__mocks__/@objectstack/objectql.ts)The mock
ObjectQLclass was missing methods and behaviors present in the upstream engine:datasource(),getDriverByName(),on()(alias forregisterHook),count()on context objectsinit()behavior: upstream callsdriver.connect()+driver.init(objects)— mock was a no-opcreate/update/deleteoperations bypassed the hook system entirely (onlyfindtriggered hooks)ctx.data,ctx.user,ctx.previousDataas top-level propertiesResult: 66/66 turbo tasks pass (was 63/65 with 4 visible CLI failures + hidden failures behind cache).
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
fastdl.mongodb.org/home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/objectql/objectql/node_modules/.bin/../vitest/vitest.mjs run sh k/_t�� node esbuild.js --production(dns block)fonts.googleapis.com/opt/hostedtoolcache/node/24.13.0/x64/bin/node /opt/hostedtoolcache/node/24.13.0/x64/bin/node /home/REDACTED/work/objectql/objectql/node_modules/.pnpm/next@16.1.6_react-dom@19.2.4_react@19.2.4__react@19.2.4/node_modules/next/dist/compiled/jest-worker/processChild.js(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.