-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing webhooks type annotation
- Loading branch information
Showing
7 changed files
with
141 additions
and
94 deletions.
There are no files selected for viewing
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,84 +1,135 @@ | ||
import { ApiError, Collection, Hardware, Model, ModelVersion, Page, Prediction, Status, Training, Visibility, WebhookEventType } from "replicate"; | ||
import { | ||
Account, | ||
ApiError, | ||
Collection, | ||
Deployment, | ||
Hardware, | ||
Model, | ||
ModelVersion, | ||
Page, | ||
Prediction, | ||
Status, | ||
Training, | ||
Visibility, | ||
WebhookEventType, | ||
} from "replicate"; | ||
|
||
export type Equals<X, Y> = | ||
(<T>() => T extends X ? 1 : 2) extends | ||
(<T>() => T extends Y ? 1 : 2) ? true : false; | ||
export type Equals<X, Y> = (<T>() => T extends X ? 1 : 2) extends < | ||
T, | ||
>() => T extends Y ? 1 : 2 | ||
? true | ||
: false; | ||
|
||
|
||
type AssertFalse<A extends false> = A | ||
type AssertFalse<A extends false> = A; | ||
|
||
// @ts-expect-error | ||
export type TestAssertion = AssertFalse<Equals<any, any>> | ||
|
||
export type TestApiError = AssertFalse<Equals<ApiError, any>> | ||
export type TestCollection = AssertFalse<Equals<Collection, any>> | ||
export type TestHardware = AssertFalse<Equals<Hardware, any>> | ||
export type TestModel = AssertFalse<Equals<Model, any>> | ||
export type TestModelVersion = AssertFalse<Equals<ModelVersion, any>> | ||
export type TestPage = AssertFalse<Equals<Page<unknown>, any>> | ||
export type TestPrediction = AssertFalse<Equals<Prediction, any>> | ||
export type TestStatus = AssertFalse<Equals<Status, any>> | ||
export type TestTraining = AssertFalse<Equals<Training, any>> | ||
export type TestVisibility = AssertFalse<Equals<Visibility, any>> | ||
export type TestWebhookEventType = AssertFalse<Equals<WebhookEventType, any>> | ||
export type TestAssertion = AssertFalse<Equals<any, any>>; | ||
|
||
export type TestAccount = AssertFalse<Equals<Account, any>>; | ||
export type TestApiError = AssertFalse<Equals<ApiError, any>>; | ||
export type TestCollection = AssertFalse<Equals<Collection, any>>; | ||
export type TestDeployment = AssertFalse<Equals<Deployment, any>>; | ||
export type TestHardware = AssertFalse<Equals<Hardware, any>>; | ||
export type TestModel = AssertFalse<Equals<Model, any>>; | ||
export type TestModelVersion = AssertFalse<Equals<ModelVersion, any>>; | ||
export type TestPage = AssertFalse<Equals<Page<unknown>, any>>; | ||
export type TestPrediction = AssertFalse<Equals<Prediction, any>>; | ||
export type TestStatus = AssertFalse<Equals<Status, any>>; | ||
export type TestTraining = AssertFalse<Equals<Training, any>>; | ||
export type TestVisibility = AssertFalse<Equals<Visibility, any>>; | ||
export type TestWebhookEventType = AssertFalse<Equals<WebhookEventType, any>>; | ||
|
||
// NOTE: We export the constants to avoid unused varaible issues. | ||
|
||
export const collection: Collection = { name: "", slug: "", description: "", models: [] }; | ||
export const account: Account = { | ||
type: "user", | ||
name: "", | ||
username: "", | ||
github_url: "", | ||
}; | ||
export const collection: Collection = { | ||
name: "", | ||
slug: "", | ||
description: "", | ||
models: [], | ||
}; | ||
export const deployment: Deployment = { | ||
owner: "", | ||
name: "", | ||
current_release: { | ||
number: 1, | ||
model: "", | ||
version: "", | ||
created_at: "", | ||
created_by: { | ||
type: "user", | ||
username: "", | ||
name: "", | ||
github_url: "", | ||
}, | ||
configuration: { | ||
hardware: "gpu-a100", | ||
min_instances: 0, | ||
max_instances: 5, | ||
}, | ||
}, | ||
}; | ||
export const status: Status = "starting"; | ||
export const visibility: Visibility = "public"; | ||
export const webhookType: WebhookEventType = "start"; | ||
export const err: ApiError = Object.assign(new Error(), {request: new Request("file://"), response: new Response()}); | ||
export const err: ApiError = Object.assign(new Error(), { | ||
request: new Request("file://"), | ||
response: new Response(), | ||
}); | ||
export const hardware: Hardware = { sku: "", name: "" }; | ||
export const model: Model = { | ||
url: "", | ||
owner: "", | ||
name: "", | ||
description: "", | ||
visibility: "public", | ||
github_url: "", | ||
paper_url: "", | ||
license_url: "", | ||
run_count: 10, | ||
cover_image_url: "", | ||
default_example: undefined, | ||
latest_version: undefined, | ||
url: "", | ||
owner: "", | ||
name: "", | ||
description: "", | ||
visibility: "public", | ||
github_url: "", | ||
paper_url: "", | ||
license_url: "", | ||
run_count: 10, | ||
cover_image_url: "", | ||
default_example: undefined, | ||
latest_version: undefined, | ||
}; | ||
export const version: ModelVersion = { | ||
id: "", | ||
created_at: "", | ||
cog_version: "", | ||
openapi_schema: "", | ||
id: "", | ||
created_at: "", | ||
cog_version: "", | ||
openapi_schema: "", | ||
}; | ||
export const prediction: Prediction = { | ||
id: "", | ||
status: "starting", | ||
model: "", | ||
version: "", | ||
input: {}, | ||
output: {}, | ||
source: "api", | ||
error: undefined, | ||
logs: "", | ||
metrics: { | ||
predict_time: 100, | ||
}, | ||
webhook: "", | ||
webhook_events_filter: [], | ||
created_at: "", | ||
started_at: "", | ||
completed_at: "", | ||
urls: { | ||
get: "", | ||
cancel: "", | ||
stream: "", | ||
}, | ||
id: "", | ||
status: "starting", | ||
model: "", | ||
version: "", | ||
input: {}, | ||
output: {}, | ||
source: "api", | ||
error: undefined, | ||
logs: "", | ||
metrics: { | ||
predict_time: 100, | ||
}, | ||
webhook: "", | ||
webhook_events_filter: [], | ||
created_at: "", | ||
started_at: "", | ||
completed_at: "", | ||
urls: { | ||
get: "", | ||
cancel: "", | ||
stream: "", | ||
}, | ||
}; | ||
export const training: Training = prediction; | ||
|
||
export const page: Page<ModelVersion> = { | ||
previous: "", | ||
next: "", | ||
results: [version], | ||
previous: "", | ||
next: "", | ||
results: [version], | ||
}; |
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,4 +1,4 @@ | ||
/** | ||
/** | ||
* @template T | ||
* @typedef {import("./types").Page<T>} Page | ||
*/ | ||
|