-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Models): introduce Query Models and List Models
- Loading branch information
Showing
32 changed files
with
637 additions
and
75 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { ApiClientError } from "../core/index.js"; | ||
import assertStatus from "./assertStatus.js"; | ||
import { AxiosHeaders } from "axios"; | ||
import { Response } from "./Response.js"; | ||
|
||
const headerName = "x-pagination-totalcount"; | ||
const baseError = `Could not get header ${headerName}`; | ||
|
||
export const extractTotalCountHeader = (response: Response): number => { | ||
assertStatus(response, 200); | ||
|
||
if (!(response.headers instanceof AxiosHeaders)) { | ||
throw ApiClientError.fromResponse( | ||
`${baseError}: Expected headers to be of type AxiosHeaders`, | ||
response, | ||
); | ||
} | ||
|
||
const headerContent = response.headers.get(headerName); | ||
|
||
if (typeof headerContent !== "string") { | ||
throw ApiClientError.fromResponse( | ||
`${baseError}: value is not of type string (is ${typeof headerContent} instead)`, | ||
response, | ||
); | ||
} | ||
|
||
const asNumber = Number.parseInt(headerContent); | ||
|
||
if (isNaN(asNumber)) { | ||
throw ApiClientError.fromResponse( | ||
`${baseError}: value is not a valid number (${typeof asNumber})`, | ||
response, | ||
); | ||
} | ||
|
||
return asNumber; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
export { assertStatus, assertOneOfStatus } from "@mittwald/api-client-commons"; | ||
export { | ||
assertStatus, | ||
assertOneOfStatus, | ||
extractTotalCountHeader, | ||
} from "@mittwald/api-client-commons"; | ||
export { MittwaldAPIClient as MittwaldAPIV2Client } from "./v2/default.js"; | ||
export type { MittwaldAPIV2 } from "./generated/v2/types.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
import { | ||
AppInstallationListItemData, | ||
AppInstallationData, | ||
AppInstallationListQuery, | ||
AppInstallationListQueryData, | ||
} from "../types.js"; | ||
import { QueryResponseData } from "../../../base/index.js"; | ||
|
||
export interface AppInstallationBehaviors { | ||
find: (id: string) => Promise<AppInstallationData | undefined>; | ||
list: ( | ||
projectId: string, | ||
query?: AppInstallationListQuery, | ||
) => Promise<AppInstallationListItemData[]>; | ||
query?: AppInstallationListQueryData, | ||
) => Promise<QueryResponseData<AppInstallationListItemData>>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export class ListDataModel<TItem> { | ||
public readonly items: readonly TItem[]; | ||
public readonly totalCount: number; | ||
|
||
public constructor(items: TItem[], totalCount: number) { | ||
this.items = Object.freeze(items); | ||
this.totalCount = totalCount; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { hash } from "object-code"; | ||
|
||
export abstract class ListQueryModel<TQuery> { | ||
protected readonly query: TQuery; | ||
public readonly queryId: string; | ||
|
||
public constructor(query: TQuery) { | ||
this.query = query; | ||
this.queryId = hash(query).toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
import { DataModel } from "./DataModel.js"; | ||
|
||
export type DataType<T> = T extends DataModel<infer TData> ? TData : never; | ||
|
||
export type QueryResponseData<T> = { | ||
items: readonly T[]; | ||
totalCount: number; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.