|
1 | | -import type { BotApiShape } from './botApiShape.gen' |
| 1 | +import type { BotApiTransport } from '../BotApiTransport.js' |
| 2 | +import type { BotApiShape } from './botApiShape.gen.js' |
2 | 3 | import * as Effect from 'effect/Effect' |
3 | | -import { BotApiError } from '../BotApiError' |
4 | | -import { BotApiTransport } from '../BotApiTransport' |
| 4 | +import { BotApiError } from '../BotApiError.js' |
5 | 5 |
|
6 | | -export const make = Effect.gen(function* () { |
7 | | - const transport = yield* BotApiTransport |
8 | | - const botApi = new Proxy({}, { |
9 | | - get: (_target, prop) => { |
10 | | - if (typeof prop !== 'string') { |
11 | | - return |
12 | | - } |
13 | | - const method = prop |
14 | | - return (params: void | Record<string, unknown> = {}) => |
15 | | - Effect.gen(function* () { |
16 | | - const response = yield* transport.sendRequest(method, params) |
17 | | - if (response.ok) { |
18 | | - return response.result |
19 | | - } |
20 | | - yield* Effect.fail( |
21 | | - new BotApiError({ |
22 | | - code: response.error_code, |
23 | | - description: response.description, |
24 | | - parameters: response.parameters, |
25 | | - }), |
26 | | - ) |
27 | | - }) |
28 | | - }, |
| 6 | +export const make = (options: { |
| 7 | + transport: typeof BotApiTransport.Service |
| 8 | +}) => ( |
| 9 | + Effect.gen(function* () { |
| 10 | + const botApi = new Proxy({}, { |
| 11 | + get: (_target, prop) => { |
| 12 | + if (typeof prop !== 'string') { |
| 13 | + return |
| 14 | + } |
| 15 | + const method = prop |
| 16 | + return (params: void | Record<string, unknown> = {}) => ( |
| 17 | + Effect.gen(function* () { |
| 18 | + const response = yield* options.transport.sendRequest(method, params) |
| 19 | + if (response.ok) { |
| 20 | + return response.result |
| 21 | + } |
| 22 | + yield* Effect.fail( |
| 23 | + new BotApiError({ |
| 24 | + code: response.error_code, |
| 25 | + description: response.description, |
| 26 | + parameters: response.parameters, |
| 27 | + }), |
| 28 | + ) |
| 29 | + }) |
| 30 | + ) |
| 31 | + }, |
| 32 | + }) |
| 33 | + return botApi as BotApiShape |
29 | 34 | }) |
30 | | - return botApi as BotApiShape |
31 | | -}) |
| 35 | +) |
0 commit comments