@@ -2,19 +2,19 @@ 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
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 }
17- export type DeleteManyResult = any
17+ export type DeleteManyResult = DeleteSingleResult
1818
1919export type IgnoreCaseOptions = { ignoreCase ? : string [ ] }
2020export type ReverseOptions = { reverse ? : boolean }
@@ -71,7 +71,11 @@ export abstract class StorageBackend {
7171 async cleanup ( ) : Promise < any > { }
7272 async migrate ( { database} : { database ?} = { } ) : Promise < any > { }
7373
74- abstract async createObject ( collection : string , object , options ? : CreateSingleOptions )
74+ abstract async createObject < PK = string , T = any > (
75+ collection : string ,
76+ object : T ,
77+ options ? : CreateSingleOptions ,
78+ ) : Promise < CreateSingleResult < PK , T > >
7579
7680 abstract findObjects < T > ( collection : string , query , options ? : FindManyOptions ) : Promise < Array < T > >
7781 async findObject < T > ( collection : string , query , options ? : FindSingleOptions ) : Promise < T | null > {
@@ -117,7 +121,12 @@ export abstract class StorageBackend {
117121 async deleteObject ( collection : string , object , options ? : DeleteSingleOptions ) : Promise < DeleteSingleResult > {
118122 const definition = this . registry . collections [ collection ]
119123 if ( typeof definition . pkIndex === 'string' ) {
120- await this . deleteObjects ( collection , { [ definition . pkIndex ] : object [ definition . pkIndex ] } , { ...( options || { } ) , limit : 1 } )
124+ return this . deleteObjects ( collection , {
125+ [ definition . pkIndex ] : object [ definition . pkIndex ] ,
126+ } , {
127+ ...( options || { } ) ,
128+ limit : 1 ,
129+ } )
121130 } else {
122131 throw new Error ( 'Updating single objects with compound pks is not supported yet' )
123132 }
@@ -166,4 +175,4 @@ export function _validateOperationRegistration(identifier, backend : StorageBack
166175 }
167176
168177 return true
169- }
178+ }
0 commit comments