Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add urloptions and *Status types #146

Merged
merged 1 commit into from
Feb 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ declare module 'resourcerer' {
silent?: boolean;
};

declare class Model<T extends Record<string, any> = {[key: string]: any}> {
constructor(attrs?: T, options?: Record<string, any> & SetOptions): Model;
declare class Model<
T extends Record<string, any> = {[key: string]: any},
O extends Record<string, any> & SetOptions = {[key: string]: any}
> {
constructor(attrs?: T, options?: O): Model<T, O>;

// TODO: need to reference idAttribute here
id: T extends {id: string} ? string : string | undefined;
Expand Down Expand Up @@ -61,9 +64,13 @@ declare module 'resourcerer' {

toJSON(): T;

url(urlOptions?: Record<string, any>): string;
url(urlOptions?: this["urlOptions"]): string;

urlRoot(urlOptions?: this["urlOptions"]): string;

urlRoot(urlOptions?: Record<string, any>): string;
collection?: Collection;

readonly urlOptions: Omit<O, keyof SetOptions>;

static cacheFields: Array<string | ((attrs: T) => Record<string, any>)>;

Expand All @@ -85,7 +92,7 @@ declare module 'resourcerer' {
constructor(
models?: ModelArg<T> | ModelArg<T>[],
options?: O
): Collection<T>;
): Collection<T, O>;

length: number;

Expand Down Expand Up @@ -135,7 +142,9 @@ declare module 'resourcerer' {

fetch(options?: {parse?: boolean} & SyncOptions & CSetOptions): Promise<[Collection<T>, Response]>;

url(urlOptions?: O): string;
url(urlOptions?: this["urlOptions"]): string;

readonly urlOptions: Omit<O, keyof CSetOptions>;

static cacheFields: Array<string | ((attrs: T) => Record<string, any>)>;

Expand Down Expand Up @@ -173,6 +182,7 @@ declare module 'resourcerer' {
[key: `${string}LoadingState`]: LoadingTypes;
[key: `${string}Collection`]: Collection;
[key: `${string}Model`]: Model;
[key: `${string}Status`]: number;
}

declare function haveAllLoaded(loadingStates: LoadingTypes | LoadingTypes[]): boolean;
Expand Down
Loading