Skip to content

Commit

Permalink
refactor: document object and service response data type
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm committed Nov 27, 2022
1 parent cc52765 commit 5346efa
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
18 changes: 15 additions & 3 deletions packages/core/fetch/src/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import {createLogger, alwatrRegisteredList} from '@alwatr/logger';

import type {FetchOptions, CacheDuplicate, CacheStrategy} from './type';

export {FetchOptions, CacheDuplicate, CacheStrategy};
import type {
FetchOptions,
CacheDuplicate,
CacheStrategy,
AlwatrDocumentObject,
AlwatrServiceResponse,
} from './type';

export {
FetchOptions,
CacheDuplicate,
CacheStrategy,
AlwatrDocumentObject,
AlwatrServiceResponse,
};

const logger = createLogger('alwatr/fetch');

Expand Down
31 changes: 30 additions & 1 deletion packages/core/fetch/src/type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

export type CacheStrategy = 'network_only' | 'network_first' | 'cache_only' | 'cache_first' | 'stale_while_revalidate';
export type CacheDuplicate = 'never' | 'always' | 'until_load' | 'auto';

Expand Down Expand Up @@ -87,3 +86,33 @@ export interface FetchOptions extends RequestInit {
*/
token?: string;
}

export type AlwatrDocumentObject = {
[key: string]: unknown;
id: string;
_meta?: {
rev: number;
created: number;
updated: number;
};
};

export type AlwatrServiceResponseFailed = {
ok: false;
errorCode: string;
_meta?: Record<string, unknown>;
};

export type AlwatrServiceResponseSuccess<
TData extends Record<string, unknown>,
TMeta extends Record<string, unknown> = never
> = {
ok: true;
_meta?: TMeta;
data: TData;
};

export type AlwatrServiceResponse<
TData extends Record<string, unknown>,
TMeta extends Record<string, unknown> = never
> = AlwatrServiceResponseSuccess<TData, TMeta> | AlwatrServiceResponseFailed;

0 comments on commit 5346efa

Please sign in to comment.