Skip to content

Commit 70a9ae6

Browse files
committed
test(runtime,organizations): module-scope refusing matcher; alias spec/contracts to source
Claude-Session: https://claude.ai/code/session_01LFqdRsuM5nkqoJdHd5ztVk Co-authored-by: Claude <noreply@anthropic.com>
1 parent 090a6a0 commit 70a9ae6

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

‎packages/plugins/organizations/vitest.config.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ export default defineConfig({
112112
find: /^@objectstack\/spec\/data$/,
113113
replacement: path.resolve(__dirname, '../../spec/src/data/index.ts'),
114114
},
115+
{
116+
find: /^@objectstack\/spec\/contracts$/,
117+
replacement: path.resolve(__dirname, '../../spec/src/contracts/index.ts'),
118+
},
115119
],
116120
},
117121
test: {

‎packages/runtime/src/app-plugin.seed-landed.test.ts‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,29 @@ import type { PluginContext } from '@objectstack/core';
2323
* organization's creation.
2424
*/
2525

26+
/**
27+
* `where` as the seed loader spells it here: field equality only. A combinator
28+
* or a value operator is REFUSED rather than answered, so a shape this double
29+
* does not implement can never read as a match or a miss.
30+
*/
31+
function rowMatches(row: any, where: Record<string, unknown> = {}): boolean {
32+
return Object.entries(where).every(([k, v]) => {
33+
if (k.startsWith('$')) throw new Error(`engine double: unsupported combinator ${k}`);
34+
if (v !== null && typeof v === 'object') {
35+
throw new Error(`engine double: unsupported value operator on ${k}: ${JSON.stringify(v)}`);
36+
}
37+
return (row[k] ?? null) === (v ?? null);
38+
});
39+
}
40+
2641
/** A faithful in-memory engine: `where` filters, ids minted on insert. */
2742
function createEngine() {
2843
const store: Record<string, any[]> = {};
2944
let next = 0;
30-
const matches = (row: any, where: Record<string, unknown> = {}) =>
31-
Object.entries(where).every(([k, v]) => {
32-
if (k.startsWith('$')) throw new Error(`engine double: unsupported operator ${k}`);
33-
return (row[k] ?? null) === (v ?? null);
34-
});
3545
const engine: any = {
3646
store,
3747
async find(object: string, query?: any) {
38-
let rows = (store[object] ?? []).filter((r) => matches(r, query?.where));
48+
let rows = (store[object] ?? []).filter((r) => rowMatches(r, query?.where));
3949
if (typeof query?.limit === 'number') rows = rows.slice(0, query.limit);
4050
return rows.map((r) => ({ ...r }));
4151
},

0 commit comments

Comments
 (0)