Skip to content

Commit 207f0b9

Browse files
committed
Add missing TypeScript definitions
1 parent 64ad79a commit 207f0b9

9 files changed

+44
-35
lines changed

index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class Replicate {
147147
* @param {string} [options.webhook] - An HTTPS URL for receiving a webhook when the prediction has new output
148148
* @param {WebhookEventType[]} [options.webhook_events_filter] - You can change which events trigger webhook requests by specifying webhook events (`start`|`output`|`logs`|`completed`)
149149
* @param {AbortSignal} [options.signal] - AbortSignal to cancel the prediction
150-
* @param {Function} [progress] - Callback function that receives the prediction object as it's updated. The function is called when the prediction is created, each time its updated while polling for completion, and when it's completed.
150+
* @param {(p: Prediction) => void} [progress] - Callback function that receives the prediction object as it's updated. The function is called when the prediction is created, each time its updated while polling for completion, and when it's completed.
151151
* @throws {Error} If the reference is invalid
152152
* @throws {Error} If the prediction failed
153153
* @returns {Promise<Prediction>} - Resolves with the output of running the model
@@ -421,6 +421,7 @@ module.exports.parseProgressFromLogs = parseProgressFromLogs;
421421

422422
/**
423423
* @typedef {import("./lib/error")} ApiError
424+
* @typedef {import("./lib/types").Account} Account
424425
* @typedef {import("./lib/types").Collection} Collection
425426
* @typedef {import("./lib/types").ModelVersion} ModelVersion
426427
* @typedef {import("./lib/types").Hardware} Hardware

lib/accounts.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
/** @typedef {import("./types").Account} Account */
2+
13
/**
24
* Get the current account
35
*
4-
* @returns {Promise<object>} Resolves with the current account
6+
* @returns {Promise<Account>} Resolves with the current account
57
*/
68
async function getCurrentAccount() {
79
const response = await this.request("/account", {

lib/deployments.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
/** @typedef {import("./types").Deployment} Deployment */
12
/** @typedef {import("./types").Prediction} Prediction */
3+
/** @typedef {import("./types").WebhookEventType} WebhookEventType */
24

35
const { transformFileInputs } = require("./util");
46

@@ -45,7 +47,7 @@ async function createPrediction(deployment_owner, deployment_name, options) {
4547
*
4648
* @param {string} deployment_owner - Required. The username of the user or organization who owns the deployment
4749
* @param {string} deployment_name - Required. The name of the deployment
48-
* @returns {Promise<object>} Resolves with the deployment data
50+
* @returns {Promise<Deployment>} Resolves with the deployment data
4951
*/
5052
async function getDeployment(deployment_owner, deployment_name) {
5153
const response = await this.request(

lib/predictions.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/**
22
* @template T
33
* @typedef {import("./types").Page<T>} Page
4+
*/
5+
6+
/**
47
* @typedef {import("./types").Prediction} Prediction
58
* @typedef {Object} BasePredictionOptions
69
* @property {unknown} input - Required. An object with the model inputs

lib/stream.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ServerSentEvent {
4141
*
4242
* @param {object} config
4343
* @param {string} config.url The URL to connect to.
44-
* @param {typeof fetch} [config.fetch] The URL to connect to.
44+
* @param {(url: URL | RequestInfo, init?: RequestInit | undefined) => Promise<Response>} [config.fetch] The URL to connect to.
4545
* @param {object} [config.options] The EventSource options.
4646
* @returns {ReadableStream<ServerSentEvent> & AsyncIterable<ServerSentEvent>}
4747
*/

lib/types.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
1-
/**
1+
/**
22
* @typedef {"starting" | "processing" | "succeeded" | "failed" | "canceled"} Status
33
* @typedef {"public" | "private"} Visibility
4-
* @typedef {"start" | "output" | "logs" | "completed"} WebhookEventType
4+
* @typedef {"start" | "output" | "logs" | "completed"} WebhookEventType
5+
*
6+
* @typedef {Object} Account
7+
* @property {"user" | "organization"} type
8+
* @property {string} username
9+
* @property {string} name
10+
* @property {string=} github_url
511
*
612
* @typedef {Object} Collection
713
* @property {string} name
814
* @property {string} slug
915
* @property {string} description
1016
* @property {Model[]=} models
1117
*
18+
* @typedef {Object} Deployment
19+
* @property {string} owner
20+
* @property {string} name
21+
* @property {object} current_release
22+
* @property {number} current_release.number
23+
* @property {string} current_release.model
24+
* @property {string} current_release.version
25+
* @property {string} current_release.created_at
26+
* @property {Account} current_release.created_by
27+
* @property {object} current_release.configuration
28+
* @property {string} current_release.configuration.hardware
29+
* @property {number} current_release.configuration.min_instances
30+
* @property {number} current_release.configuration.max_instances
31+
*
1232
* @typedef {Object} Hardware
1333
* @property {string} sku
1434
* @property {string} name

lib/util.js

+8-23
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,16 @@
11
const ApiError = require("./error");
22

3-
/**
4-
* @see {@link validateWebhook}
5-
* @overload
6-
* @param {object} requestData - The request data
7-
* @param {string} requestData.id - The webhook ID header from the incoming request.
8-
* @param {string} requestData.timestamp - The webhook timestamp header from the incoming request.
9-
* @param {string} requestData.body - The raw body of the incoming webhook request.
10-
* @param {string} requestData.secret - The webhook secret, obtained from `replicate.webhooks.defaul.secret` method.
11-
* @param {string} requestData.signature - The webhook signature header from the incoming request, comprising one or more space-delimited signatures.
12-
*/
13-
14-
/**
15-
* @see {@link validateWebhook}
16-
* @overload
17-
* @param {object} requestData - The request object
18-
* @param {object} requestData.headers - The request headers
19-
* @param {string} requestData.headers["webhook-id"] - The webhook ID header from the incoming request
20-
* @param {string} requestData.headers["webhook-timestamp"] - The webhook timestamp header from the incoming request
21-
* @param {string} requestData.headers["webhook-signature"] - The webhook signature header from the incoming request, comprising one or more space-delimited signatures
22-
* @param {string} requestData.body - The raw body of the incoming webhook request
23-
* @param {string} secret - The webhook secret, obtained from `replicate.webhooks.defaul.secret` method
24-
*/
25-
263
/**
274
* Validate a webhook signature
285
*
6+
* @typedef {Object} WebhookPayload
7+
* @property {string} id - The webhook ID header from the incoming request.
8+
* @property {string} timestamp - The webhook timestamp header from the incoming request.
9+
* @property {string} body - The raw body of the incoming webhook request.
10+
* @property {string} signature - The webhook signature header from the incoming request, comprising one or more space-delimited signatures.
11+
*
12+
* @param {Request | WebhookPayload} requestData
13+
* @param {string} secret - The webhook secret, obtained from `replicate.webhooks.defaul.secret` method.
2914
* @returns {Promise<boolean>} - True if the signature is valid
3015
* @throws {Error} - If the request is missing required headers, body, or secret
3116
*/

lib/webhooks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Get the default webhook signing secret
33
*
4-
* @returns {Promise<object>} Resolves with the signing secret for the default webhook
4+
* @returns {Promise<{key: string}>} Resolves with the signing secret for the default webhook
55
*/
66
async function getDefaultWebhookSecret() {
77
const response = await this.request("/webhooks/default/secret", {

package.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"yarn": ">=1.7.0"
2828
},
2929
"scripts": {
30-
"build": "npm run build:types",
30+
"build": "npm run build:types && tsc --noEmit dist/types/**/*.d.ts",
3131
"build:types": "tsc --target ES2022 --declaration --emitDeclarationOnly --allowJs --types node --outDir ./dist/types index.js",
3232
"check": "tsc",
3333
"format": "biome format . --write",
@@ -39,14 +39,10 @@
3939
"test:integration": "npm run build; for x in commonjs esm typescript; do npm --prefix integration/$x install --omit=dev && npm --prefix integration/$x test; done;",
4040
"test:all": "npm run check; npm run test; npm run test:integration"
4141
},
42-
"optionalDependencies": {
43-
"readable-stream": ">=4.0.0"
44-
},
4542
"devDependencies": {
4643
"@biomejs/biome": "^1.4.1",
4744
"@types/jest": "^29.5.3",
4845
"@typescript-eslint/eslint-plugin": "^5.56.0",
49-
"cross-fetch": "^3.1.5",
5046
"jest": "^29.6.2",
5147
"nock": "^14.0.0-beta.4",
5248
"publint": "^0.2.7",

0 commit comments

Comments
 (0)