Skip to content

Commit

Permalink
Defined new types for GetResponse and ListResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Beal committed Jan 15, 2023
1 parent 9d41856 commit 26c75f6
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export interface DataRepo<T extends DataObject> {
* Looks up an object by its key fields. This method will always use the index
* @param template Subset of fields in the object necessary for a complete lookup
*/
getObject(template: Partial<T>): Promise<T | null>;
getObject(template: Partial<T>): Promise<GetResponse<T>>;
putObject(obj: T): Promise<WriteResults<T>>;
putObjects(objects: T[]): Promise<WriteResults<T>[]>;
listObjects(template: Partial<T>): Promise<T[]>;
listObjects(template: Partial<T>): Promise<ListResponse<T>>;
}

export type Scalar = IndexableScalar | boolean | null | undefined;
Expand Down Expand Up @@ -72,6 +72,28 @@ export enum WriteResult {
ERROR = 'error',
}

export type GetResponse<T extends DataObject> = {
data: T | undefined;
result: ReadResult;
error?: string;
errorCode?: number;
}

export type ListResponse<T extends DataObject> = {
data: T[];
result: ReadResult;
hasMore: boolean;
next: Keys<T>;
error?: string;
errorCode?: number;
}

export enum ReadResult {
FOUND = 'found',
NOT_FOUND = 'not_found',
ERROR = 'error'
}

export type KeyConfig<T extends DataObject> = {
keyName: keyof T | string;
keyType?: KeyType;
Expand Down

0 comments on commit 26c75f6

Please sign in to comment.