@@ -22,6 +22,17 @@ import type { IPermissionStorage, SecurityPluginConfig } from './types';
2222/** Default table name for storing permission metadata */
2323const DEFAULT_TABLE = 'objectql_permissions' ;
2424
25+ /**
26+ * Interface for permission storage row structure
27+ */
28+ interface PermissionRow {
29+ _id ?: string | number ;
30+ id ?: string | number ;
31+ object_name : string ;
32+ config : string ;
33+ updated_at ?: string ;
34+ }
35+
2536/**
2637 * Resolver function that locates a Driver instance by datasource name.
2738 * Typically wired from the ObjectQL application layer.
@@ -118,7 +129,7 @@ export class DatabasePermissionStorage implements IPermissionStorage {
118129 filters : [ [ 'object_name' , '=' , objectName ] ] ,
119130 top : 1 ,
120131 } ) ;
121- const row = Array . isArray ( rows ) ? rows [ 0 ] : undefined ;
132+ const row = Array . isArray ( rows ) ? rows [ 0 ] as unknown as PermissionRow | undefined : undefined ;
122133 if ( ! row ) return undefined ;
123134 return JSON . parse ( row . config ) as PermissionConfig ;
124135 } catch {
@@ -131,7 +142,7 @@ export class DatabasePermissionStorage implements IPermissionStorage {
131142 const result = new Map < string , PermissionConfig > ( ) ;
132143 try {
133144 const rows = await driver . find ( this . tableName , { } ) ;
134- const items = Array . isArray ( rows ) ? rows : [ ] ;
145+ const items = Array . isArray ( rows ) ? rows as unknown as PermissionRow [ ] : [ ] ;
135146 for ( const row of items ) {
136147 try {
137148 const config = JSON . parse ( row . config ) as PermissionConfig ;
@@ -152,10 +163,11 @@ export class DatabasePermissionStorage implements IPermissionStorage {
152163 try {
153164 const rows = await driver . find ( this . tableName , { } ) ;
154165 // Create a shallow copy to avoid issues when deleting during iteration
155- const items = Array . isArray ( rows ) ? [ ... rows ] : [ ] ;
166+ const items = Array . isArray ( rows ) ? rows as unknown as PermissionRow [ ] : [ ] ;
156167 for ( const row of items ) {
157- if ( row . _id || row . id || row . object_name ) {
158- await driver . delete ( this . tableName , row . _id ?? row . id ?? row . object_name , { } ) ;
168+ const id = row . _id ?? row . id ?? row . object_name ;
169+ if ( id !== undefined ) {
170+ await driver . delete ( this . tableName , id , { } ) ;
159171 }
160172 }
161173 } catch {
@@ -185,13 +197,15 @@ export class DatabasePermissionStorage implements IPermissionStorage {
185197 filters : [ [ 'object_name' , '=' , config . object ] ] ,
186198 top : 1 ,
187199 } ) ;
188- const row = Array . isArray ( rows ) ? rows [ 0 ] : undefined ;
200+ const row = Array . isArray ( rows ) ? rows [ 0 ] as unknown as PermissionRow | undefined : undefined ;
189201 if ( row ) {
190202 const id = row . _id ?? row . id ?? row . object_name ;
191- await driver . update ( this . tableName , id , {
203+ if ( id !== undefined ) {
204+ await driver . update ( this . tableName , id , {
192205 config : JSON . stringify ( config ) ,
193206 updated_at : new Date ( ) . toISOString ( ) ,
194207 } , { } ) ;
208+ }
195209 }
196210 } else {
197211 await driver . create ( this . tableName , {
@@ -212,10 +226,12 @@ export class DatabasePermissionStorage implements IPermissionStorage {
212226 filters : [ [ 'object_name' , '=' , objectName ] ] ,
213227 top : 1 ,
214228 } ) ;
215- const row = Array . isArray ( rows ) ? rows [ 0 ] : undefined ;
229+ const row = Array . isArray ( rows ) ? rows [ 0 ] as unknown as PermissionRow | undefined : undefined ;
216230 if ( row ) {
217231 const id = row . _id ?? row . id ?? row . object_name ;
218- await driver . delete ( this . tableName , id , { } ) ;
232+ if ( id !== undefined ) {
233+ await driver . delete ( this . tableName , id , { } ) ;
234+ }
219235 }
220236 } catch {
221237 // Row may not exist
0 commit comments