| 66 | } |
| 67 | |
| 68 | runTask<T, TResult extends Json<T> | void>( |
| 69 | key: IntegrationTaskKey, |
| 70 | callback: (client: ReplicateClient, task: IOTask, io: IO) => Promise<TResult>, |
| 71 | options?: RunTaskOptions, |
| 72 | errorCallback?: RunTaskErrorCallback |
| 73 | ): Promise<TResult> { |
| 74 | if (!this._io) throw new Error("No IO"); |
| 75 | if (!this._connectionKey) throw new Error("No connection key"); |
| 76 | |
| 77 | return this._io.runTask( |
| 78 | key, |
| 79 | (task, io) => { |
| 80 | if (!this._client) throw new Error("No client"); |
| 81 | return callback(this._client, task, io); |
| 82 | }, |
| 83 | { |
| 84 | icon: "replicate", |
| 85 | retry: retry.standardBackoff, |
| 86 | ...(options ?? {}), |
| 87 | connectionKey: this._connectionKey, |
| 88 | }, |
| 89 | errorCallback ?? onError |
| 90 | ); |
| 91 | } |
| 92 | |
| 93 | get collections() { |
| 94 | return new Collections(this.runTask.bind(this)); |