4242
4343import { describe , it , expect , beforeAll , afterAll , vi } from 'vitest' ;
4444import { PermissionSetSchema } from '@objectstack/spec/security' ;
45+ import type { EngineQueryOptions } from '@objectstack/spec/data' ;
4546import { ObjectQL } from '@objectstack/objectql' ;
4647import { SqlDriver } from '@objectstack/driver-sql' ;
4748import { SecurityPlugin } from '@objectstack/plugin-security' ;
@@ -69,7 +70,7 @@ const MEMBER_SET = PermissionSetSchema.parse({
6970 rowLevelSecurity : [ { name : 'region_scope' , object : SCOPED , operation : 'all' , using : "record.region != 'HIDDEN'" } ] ,
7071} ) ;
7172
72- const MEMBER_CTX = { userId : 'usr_member' , positions : [ ] , permissions : [ MEMBER_SET . name ] , posture : 'MEMBER' } ;
73+ const MEMBER_CTX = { userId : 'usr_member' , positions : [ ] as string [ ] , permissions : [ MEMBER_SET . name ] , posture : 'MEMBER' as const } ;
7374
7475/** A well-formed instant no row here carries: a token read before a write that moved it. */
7576const STALE = '2000-01-01T00:00:00.000Z' ;
@@ -81,6 +82,9 @@ const MASKED_ID = 'v1';
8182/** The positive control's row. */
8283const PLAIN_ID = 'p1' ;
8384
85+ /** A by-id read's options, typed to the engine's contract. */
86+ const byId = ( id : string , context : EngineQueryOptions [ 'context' ] ) : EngineQueryOptions => ( { where : { id } , context } ) ;
87+
8488const clone = < T > ( v : T ) : T => ( v === undefined ? v : JSON . parse ( JSON . stringify ( v ) ) ) ;
8589
8690interface Answer {
@@ -179,7 +183,7 @@ describe('[#23586] a 409 CONCURRENT_UPDATE reports only what the caller may read
179183
180184 /** The row as the system reads it now (`null` once deleted). */
181185 const systemRow = async ( object : string , id : string ) =>
182- ( await engine . findOne ( object , { where : { id } , context : SYS_CTX } as any ) ) as any ;
186+ ( await engine . findOne ( object , byId ( id , SYS_CTX ) ) ) as any ;
183187 /** The row's current version token, as the system reads it. */
184188 const versionOf = async ( object : string , id : string ) : Promise < string > => {
185189 const row = await systemRow ( object , id ) ;
@@ -316,7 +320,7 @@ describe('[#23586] a 409 CONCURRENT_UPDATE reports only what the caller may read
316320 const record : any = doorIndex === 0 ? conflictState ( stale . body ) . currentRecord : thrownRecord ;
317321 expect ( record ) . toMatchObject ( { id : MASKED_ID , title : 'visible' , region : 'NA' } ) ;
318322 expect ( record ) . not . toHaveProperty ( 'secret' ) ;
319- const callerRead : any = await engine . findOne ( SCOPED , { where : { id : MASKED_ID } , context : clone ( MEMBER_CTX ) } as any ) ;
323+ const callerRead : any = await engine . findOne ( SCOPED , byId ( MASKED_ID , clone ( MEMBER_CTX ) ) ) ;
320324 expect ( callerRead ) . not . toHaveProperty ( 'secret' ) ;
321325 expect ( record ) . toEqual ( callerRead ) ;
322326
0 commit comments