@@ -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. */
2742function 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