@@ -2,17 +2,17 @@ import StorageRegistry from "../registry"
22import { StorageBackendFeatureSupport } from "./backend-features" ;
33import { isRelationshipReference } from "./relationships" ;
44
5- export type CreateSingleOptions = DBNameOptions
6- export type CreateSingleResult = { object ? : any }
5+ export type CreateSingleOptions = DBNameOptions & { incObject ? : boolean }
6+ export type CreateSingleResult < PK , T > = { pk : PK , object ? : T }
77export type FindSingleOptions = DBNameOptions & IgnoreCaseOptions & ReverseOptions & { fields ?: string [ ] }
88export type FindManyOptions = FindSingleOptions & PaginationOptions & SortingOptions
99export type CountOptions = DBNameOptions & IgnoreCaseOptions
10- export type UpdateManyOptions = DBNameOptions
11- export type UpdateManyResult = any
1210export type UpdateSingleOptions = DBNameOptions
13- export type UpdateSingleResult = any
11+ export type UpdateSingleResult = { count ? : number }
12+ export type UpdateManyOptions = DBNameOptions
13+ export type UpdateManyResult = UpdateSingleResult
1414export type DeleteSingleOptions = DBNameOptions
15- export type DeleteSingleResult = any
15+ export type DeleteSingleResult = { count ? : number }
1616export type DeleteManyOptions = DBNameOptions & { limit ? : number }
1717export type DeleteManyResult = any
1818export type OperationBatch = Array < CreateObjectBatchOperation | UpdateObjectsBatchOperation | DeleteObjectsBatchOperation >
@@ -78,7 +78,11 @@ export abstract class StorageBackend {
7878 async cleanup ( ) : Promise < any > { }
7979 async migrate ( { database} : { database ?} = { } ) : Promise < any > { }
8080
81- abstract async createObject ( collection : string , object , options ? : CreateSingleOptions )
81+ abstract async createObject < PK = string , T = any > (
82+ collection : string ,
83+ object : T ,
84+ options ? : CreateSingleOptions ,
85+ ) : Promise < CreateSingleResult < PK , T > >
8286
8387 abstract findObjects < T > ( collection : string , query , options ? : FindManyOptions ) : Promise < Array < T > >
8488 async findObject < T > ( collection : string , query , options ? : FindSingleOptions ) : Promise < T | null > {
@@ -124,7 +128,12 @@ export abstract class StorageBackend {
124128 async deleteObject ( collection : string , object , options ? : DeleteSingleOptions ) : Promise < DeleteSingleResult > {
125129 const definition = this . registry . collections [ collection ]
126130 if ( typeof definition . pkIndex === 'string' ) {
127- await this . deleteObjects ( collection , { [ definition . pkIndex ] : object [ definition . pkIndex ] } , { ...( options || { } ) , limit : 1 } )
131+ return this . deleteObjects ( collection , {
132+ [ definition . pkIndex ] : object [ definition . pkIndex ] ,
133+ } , {
134+ ...( options || { } ) ,
135+ limit : 1 ,
136+ } )
128137 } else {
129138 throw new Error ( 'Updating single objects with compound pks is not supported yet' )
130139 }
@@ -177,4 +186,4 @@ export function _validateOperationRegistration(identifier, backend : StorageBack
177186 }
178187
179188 return true
180- }
189+ }
0 commit comments