@grom.js/effect-tg 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +162 -5
- package/dist/BotApi.d.ts +10 -12
- package/dist/BotApi.d.ts.map +1 -1
- package/dist/BotApi.js +2 -2
- package/dist/BotApi.js.map +1 -1
- package/dist/BotApiError.d.ts +46 -71
- package/dist/BotApiError.d.ts.map +1 -1
- package/dist/BotApiError.js +59 -41
- package/dist/BotApiError.js.map +1 -1
- package/dist/BotApiTransport.d.ts +10 -17
- package/dist/BotApiTransport.d.ts.map +1 -1
- package/dist/BotApiTransport.js +2 -7
- package/dist/BotApiTransport.js.map +1 -1
- package/dist/BotApiUrl.d.ts +6 -8
- package/dist/BotApiUrl.d.ts.map +1 -1
- package/dist/BotApiUrl.js.map +1 -1
- package/dist/Content.d.ts.map +1 -1
- package/dist/Dialog.d.ts +96 -41
- package/dist/Dialog.d.ts.map +1 -1
- package/dist/Dialog.js +60 -25
- package/dist/Dialog.js.map +1 -1
- package/dist/File.d.ts +1 -2
- package/dist/File.d.ts.map +1 -1
- package/dist/File.js +1 -1
- package/dist/File.js.map +1 -1
- package/dist/Markup.d.ts.map +1 -1
- package/dist/Runner.d.ts +1 -1
- package/dist/Runner.d.ts.map +1 -1
- package/dist/Send.d.ts +57 -130
- package/dist/Send.d.ts.map +1 -1
- package/dist/Send.js +65 -128
- package/dist/Send.js.map +1 -1
- package/dist/Text.d.ts.map +1 -1
- package/dist/internal/botApi.d.ts +3 -1
- package/dist/internal/botApi.d.ts.map +1 -1
- package/dist/internal/botApi.gen.d.ts +6501 -0
- package/dist/internal/botApi.gen.d.ts.map +1 -0
- package/dist/internal/botApi.gen.js +2 -0
- package/dist/internal/botApi.gen.js.map +1 -0
- package/dist/internal/botApi.js +2 -6
- package/dist/internal/botApi.js.map +1 -1
- package/dist/internal/botApiError.d.ts +5 -2
- package/dist/internal/botApiError.d.ts.map +1 -1
- package/dist/internal/botApiError.js +8 -18
- package/dist/internal/botApiError.js.map +1 -1
- package/dist/internal/botApiTransport.d.ts +5 -2
- package/dist/internal/botApiTransport.d.ts.map +1 -1
- package/dist/internal/botApiTransport.js +14 -10
- package/dist/internal/botApiTransport.js.map +1 -1
- package/dist/internal/dialog.d.ts +27 -10
- package/dist/internal/dialog.d.ts.map +1 -1
- package/dist/internal/dialog.js +88 -14
- package/dist/internal/dialog.js.map +1 -1
- package/dist/internal/file.d.ts +1 -1
- package/dist/internal/file.d.ts.map +1 -1
- package/dist/internal/file.js +1 -1
- package/dist/internal/file.js.map +1 -1
- package/dist/internal/runner.d.ts +4 -5
- package/dist/internal/runner.d.ts.map +1 -1
- package/dist/internal/runner.js +14 -19
- package/dist/internal/runner.js.map +1 -1
- package/dist/internal/send.d.ts +4 -4
- package/dist/internal/send.d.ts.map +1 -1
- package/dist/internal/send.js +62 -51
- package/dist/internal/send.js.map +1 -1
- package/package.json +12 -10
- package/src/BotApi.ts +38 -31
- package/src/BotApiError.ts +109 -63
- package/src/BotApiTransport.ts +18 -20
- package/src/BotApiUrl.ts +6 -8
- package/src/Content.ts +14 -14
- package/src/Dialog.ts +164 -42
- package/src/File.ts +3 -4
- package/src/Markup.ts +5 -5
- package/src/Send.ts +114 -202
- package/src/Text.ts +5 -5
- package/src/internal/botApi.gen.ts +6783 -0
- package/src/internal/botApi.ts +7 -11
- package/src/internal/botApiError.ts +15 -20
- package/src/internal/botApiTransport.ts +25 -17
- package/src/internal/dialog.ts +109 -26
- package/src/internal/file.ts +1 -1
- package/src/internal/runner.ts +34 -38
- package/src/internal/send.ts +161 -132
- package/dist/internal/botApiMethods.gen.d.ts +0 -2026
- package/dist/internal/botApiMethods.gen.d.ts.map +0 -1
- package/dist/internal/botApiMethods.gen.js +0 -2
- package/dist/internal/botApiMethods.gen.js.map +0 -1
- package/dist/internal/botApiShape.gen.d.ts +0 -398
- package/dist/internal/botApiShape.gen.d.ts.map +0 -1
- package/dist/internal/botApiShape.gen.js +0 -2
- package/dist/internal/botApiShape.gen.js.map +0 -1
- package/dist/internal/botApiTypes.gen.d.ts +0 -3903
- package/dist/internal/botApiTypes.gen.d.ts.map +0 -1
- package/dist/internal/botApiTypes.gen.js +0 -2
- package/dist/internal/botApiTypes.gen.js.map +0 -1
- package/src/internal/botApiMethods.gen.ts +0 -2027
- package/src/internal/botApiShape.gen.ts +0 -398
- package/src/internal/botApiTypes.gen.ts +0 -4178
package/README.md
CHANGED
|
@@ -1,9 +1,166 @@
|
|
|
1
|
-
|
|
1
|
+
# effect-tg
|
|
2
|
+
|
|
3
|
+
[](https://effect.website/)
|
|
4
|
+
[](https://www.npmjs.com/package/@grom.js/effect-tg)
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
> Work in progress.
|
|
6
|
+
Effectful library for crafting Telegram bots.
|
|
5
7
|
|
|
6
8
|
## Features
|
|
7
9
|
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
+
- Modular design to build with [Effect](https://effect.website).
|
|
11
|
+
- Complete type definitions for [Bot API](https://core.telegram.org/bots/api) methods and types.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
# Install the library
|
|
17
|
+
npm install @grom.js/effect-tg
|
|
18
|
+
|
|
19
|
+
# Install Effect dependencies
|
|
20
|
+
npm install effect @effect/platform
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Working with Bot API
|
|
24
|
+
|
|
25
|
+
### Calling methods
|
|
26
|
+
|
|
27
|
+
`BotApi` service provides access to Telegram's Bot API.
|
|
28
|
+
Each method on `BotApi` corresponds to the Bot API method with typed parameters and results.
|
|
29
|
+
Methods return an `Effect` that succeeds with the method result or fails with `BotApiError` (see ["Error handling"](#error-handling)).
|
|
30
|
+
|
|
31
|
+
**Example:** Calling Bot API methods using `BotApi`.
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { BotApi } from '@grom.js/effect-tg'
|
|
35
|
+
import { Effect } from 'effect'
|
|
36
|
+
|
|
37
|
+
const program = Effect.gen(function* () {
|
|
38
|
+
const api = yield* BotApi.BotApi
|
|
39
|
+
const me = yield* api.getMe()
|
|
40
|
+
yield* api.sendMessage({
|
|
41
|
+
chat_id: 123456789,
|
|
42
|
+
text: `Hello from ${me.username}!`,
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Alternatively, you can use `BotApi.callMethod` function to call any method by name.
|
|
48
|
+
|
|
49
|
+
**Example:** Calling Bot API methods using `BotApi.callMethod`.
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { BotApi } from '@grom.js/effect-tg'
|
|
53
|
+
import { Effect } from 'effect'
|
|
54
|
+
|
|
55
|
+
const program = Effect.gen(function* () {
|
|
56
|
+
const me = yield* BotApi.callMethod('getMe')
|
|
57
|
+
yield* BotApi.callMethod('sendMessage', {
|
|
58
|
+
chat_id: 123456789,
|
|
59
|
+
text: `Hello from ${me.username}!`,
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Configuration
|
|
65
|
+
|
|
66
|
+
`BotApi` has a layered architecture:
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
┌• BotApi — typed interface that delegates calls to `BotApiTransport`.
|
|
70
|
+
└─┬• BotApiTransport — serializes parameters, sends HTTP requests, parses responses.
|
|
71
|
+
├──• BotApiUrl — constructs endpoint URLs to methods and files.
|
|
72
|
+
└──• HttpClient — performs HTTP requests.
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
This design enables:
|
|
76
|
+
|
|
77
|
+
- **Extensibility**: Extend `BotApiTransport` to implement logging, retrying, etc.
|
|
78
|
+
- **Testability**: Mock implementation of `BotApiTransport` or `HttpClient` to test your bot.
|
|
79
|
+
- **Portability:** Provide different `BotApiUrl` to run a bot on test environment or with local Bot API server.
|
|
80
|
+
|
|
81
|
+
**Example:** Constructing `BotApi` layer.
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import { FetchHttpClient } from '@effect/platform'
|
|
85
|
+
import { BotApi, BotApiTransport, BotApiUrl } from '@grom.js/effect-tg'
|
|
86
|
+
import { Effect, Layer } from 'effect'
|
|
87
|
+
|
|
88
|
+
const BotApiLive = BotApi.layer.pipe(
|
|
89
|
+
Layer.provide(BotApiTransport.layer),
|
|
90
|
+
Layer.provide(
|
|
91
|
+
Layer.succeed(
|
|
92
|
+
BotApiUrl.BotApiUrl,
|
|
93
|
+
BotApiUrl.makeProd('YOUR_BOT_TOKEN')
|
|
94
|
+
)
|
|
95
|
+
),
|
|
96
|
+
Layer.provide(FetchHttpClient.layer),
|
|
97
|
+
)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Error handling
|
|
101
|
+
|
|
102
|
+
Failed `BotApi` method calls result in `BotApiError`, which is a union of tagged errors with additional information:
|
|
103
|
+
|
|
104
|
+
- `TransportError` — HTTP or network failure. `cause` property contains the original error from `HttpClient`.
|
|
105
|
+
- `RateLimited` — bot has exceeded flood limit. `retryAfter` property contains the duration to wait before retry.
|
|
106
|
+
- `GroupUpgraded` — group has been migrated to supergroup. `supergroup` property contains an object with the new ID.
|
|
107
|
+
- `MethodFailed` — response was unsuccessful, but the exact reason could not be determined. `possibleReason` property contains common failure reasons as string literals, determined by error code and description, which are subject to change.
|
|
108
|
+
- `InternalServerError` — Bot API server failed with 5xx error code.
|
|
109
|
+
|
|
110
|
+
All errors except `TransportError` also have `response` property that contains the original response from Bot API.
|
|
111
|
+
|
|
112
|
+
**Example:** Handling Bot API failures.
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
import { BotApi } from '@grom.js/effect-tg'
|
|
116
|
+
import { Duration, Effect, Match } from 'effect'
|
|
117
|
+
|
|
118
|
+
const program = BotApi.callMethod('doSomething').pipe(
|
|
119
|
+
Effect.matchEffect({
|
|
120
|
+
onSuccess: result => Effect.logInfo('Got result:', result),
|
|
121
|
+
onFailure: e => Match.value(e).pipe(
|
|
122
|
+
Match.tagsExhaustive({
|
|
123
|
+
TransportError: ({ message }) =>
|
|
124
|
+
Effect.logError(`Probably network issue: ${message}`),
|
|
125
|
+
RateLimited: ({ retryAfter }) =>
|
|
126
|
+
Effect.logError(`Try again in ${Duration.format(retryAfter)}`),
|
|
127
|
+
GroupUpgraded: ({ supergroup }) =>
|
|
128
|
+
Effect.logError(`Group now has a new ID: ${supergroup.id}`),
|
|
129
|
+
MethodFailed: ({ possibleReason, response }) =>
|
|
130
|
+
Match.value(possibleReason).pipe(
|
|
131
|
+
Match.when('BotBlockedByUser', () =>
|
|
132
|
+
Effect.logError('I was blocked...')),
|
|
133
|
+
Match.orElse(() =>
|
|
134
|
+
Effect.logError(`Unsuccessful response: ${response.description}`)),
|
|
135
|
+
),
|
|
136
|
+
InternalServerError: () =>
|
|
137
|
+
Effect.logError('Not much we can do about it.'),
|
|
138
|
+
}),
|
|
139
|
+
),
|
|
140
|
+
}),
|
|
141
|
+
)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Types
|
|
145
|
+
|
|
146
|
+
`BotApi` module exports type definitions for all Bot API types, method parameters and results.
|
|
147
|
+
|
|
148
|
+
**Example:** Creating custom types from Bot API types.
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
import { BotApi, BotApiError } from '@grom.js/effect-tg'
|
|
152
|
+
import { Effect } from 'effect'
|
|
153
|
+
|
|
154
|
+
// Union of all possible updates
|
|
155
|
+
type UpdateType = Exclude<keyof BotApi.Types.Update, 'update_id'>
|
|
156
|
+
|
|
157
|
+
// Function to get gifts of multiple chats
|
|
158
|
+
type GiftsCollector = (
|
|
159
|
+
chatIds: Array<BotApi.MethodParams['getChatGifts']['chat_id']>,
|
|
160
|
+
params: Omit<BotApi.MethodParams['getChatGifts'], 'chat_id'>,
|
|
161
|
+
) => Effect.Effect<
|
|
162
|
+
Array<BotApi.MethodResults['getChatGifts']>,
|
|
163
|
+
BotApiError.BotApiError,
|
|
164
|
+
BotApi.BotApi
|
|
165
|
+
>
|
|
166
|
+
```
|
package/dist/BotApi.d.ts
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import type * as BotApiError from './BotApiError.ts';
|
|
2
|
-
import type { MethodParams, MethodResults } from './internal/
|
|
3
|
-
import type { BotApiShape } from './internal/botApiShape.gen.ts';
|
|
4
|
-
import type * as Types from './internal/botApiTypes.gen.ts';
|
|
2
|
+
import type { MethodParams, MethodResults, BotApi as Service, Types } from './internal/botApi.gen.ts';
|
|
5
3
|
import * as Context from 'effect/Context';
|
|
6
4
|
import * as Effect from 'effect/Effect';
|
|
7
5
|
import * as Layer from 'effect/Layer';
|
|
8
6
|
import * as BotApiTransport from './BotApiTransport.ts';
|
|
9
|
-
export type { MethodParams, MethodResults, Types };
|
|
10
|
-
declare const BotApi_base: Context.TagClass<BotApi, "@grom.js/effect-tg/BotApi",
|
|
7
|
+
export type { MethodParams, MethodResults, Service, Types };
|
|
8
|
+
declare const BotApi_base: Context.TagClass<BotApi, "@grom.js/effect-tg/BotApi", Service>;
|
|
11
9
|
export declare class BotApi extends BotApi_base {
|
|
12
10
|
}
|
|
13
|
-
export
|
|
14
|
-
|
|
11
|
+
export interface BotApiMethod<TMethod extends keyof MethodParams> {
|
|
12
|
+
(...args: MethodArgs<TMethod>): Effect.Effect<MethodResults[TMethod], BotApiError.BotApiError, never>;
|
|
15
13
|
}
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
export declare const callMethod: <TMethod extends keyof MethodParams>(method: TMethod, ...args: MethodArgs<TMethod>) => Effect.Effect<MethodResults[TMethod], BotApiError.BotApiError, BotApi>;
|
|
15
|
+
export declare const make: (args: {
|
|
16
|
+
transport: BotApiTransport.Service;
|
|
17
|
+
}) => Service;
|
|
20
18
|
export declare const layer: Layer.Layer<BotApi, never, BotApiTransport.BotApiTransport>;
|
|
21
|
-
|
|
19
|
+
type MethodArgs<TMethod extends keyof MethodParams> = void extends MethodParams[TMethod] ? [params?: MethodParams[TMethod]] : [params: MethodParams[TMethod]];
|
|
22
20
|
//# sourceMappingURL=BotApi.d.ts.map
|
package/dist/BotApi.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BotApi.d.ts","sourceRoot":"","sources":["../src/BotApi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,WAAW,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"BotApi.d.ts","sourceRoot":"","sources":["../src/BotApi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,WAAW,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,MAAM,IAAI,OAAO,EACjB,KAAK,EACN,MAAM,0BAA0B,CAAA;AACjC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAA;AAGvD,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA;;AAE3D,qBAAa,MAAO,SAAQ,WAGzB;CAAG;AAEN,MAAM,WAAW,YAAY,CAAC,OAAO,SAAS,MAAM,YAAY;IAC9D,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,CAC3C,aAAa,CAAC,OAAO,CAAC,EACtB,WAAW,CAAC,WAAW,EACvB,KAAK,CACN,CAAA;CACF;AAED,eAAO,MAAM,UAAU,EAAE,CAAC,OAAO,SAAS,MAAM,YAAY,EAC1D,MAAM,EAAE,OAAO,EACf,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,KACzB,MAAM,CAAC,MAAM,CAChB,aAAa,CAAC,OAAO,CAAC,EACtB,WAAW,CAAC,WAAW,EACvB,MAAM,CAMA,CAAA;AAER,eAAO,MAAM,IAAI,EAAE,CAAC,IAAI,EAAE;IACxB,SAAS,EAAE,eAAe,CAAC,OAAO,CAAA;CACnC,KAAK,OAAuB,CAAA;AAE7B,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,KAAK,CAC7B,MAAM,EACN,KAAK,EACL,eAAe,CAAC,eAAe,CAOhC,CAAA;AAED,KAAK,UAAU,CAAC,OAAO,SAAS,MAAM,YAAY,IAChD,IAAI,SAAS,YAAY,CAAC,OAAO,CAAC,GAC9B,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,GAChC,CAAC,MAAM,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,CAAA"}
|
package/dist/BotApi.js
CHANGED
|
@@ -5,7 +5,7 @@ import * as BotApiTransport from "./BotApiTransport.js";
|
|
|
5
5
|
import * as internal from "./internal/botApi.js";
|
|
6
6
|
export class BotApi extends Context.Tag('@grom.js/effect-tg/BotApi')() {
|
|
7
7
|
}
|
|
8
|
+
export const callMethod = (method, params = undefined) => BotApi.pipe(Effect.flatMap(api => api[method](params)));
|
|
8
9
|
export const make = internal.make;
|
|
9
|
-
export const layer = Layer.effect(BotApi, Effect.andThen(BotApiTransport.BotApiTransport, internal.make));
|
|
10
|
-
export const callMethod = (method, params = undefined) => BotApi.pipe(Effect.flatMap((api) => api[method](params)));
|
|
10
|
+
export const layer = Layer.effect(BotApi, Effect.andThen(BotApiTransport.BotApiTransport, transport => internal.make({ transport })));
|
|
11
11
|
//# sourceMappingURL=BotApi.js.map
|
package/dist/BotApi.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BotApi.js","sourceRoot":"","sources":["../src/BotApi.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BotApi.js","sourceRoot":"","sources":["../src/BotApi.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAA;AAIhD,MAAM,OAAO,MAAO,SAAQ,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,EAGjE;CAAG;AAUN,MAAM,CAAC,MAAM,UAAU,GAOnB,CACF,MAAc,EACd,SAAkB,SAAS,EAC3B,EAAE,CAAC,MAAM,CAAC,IAAI,CACd,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAE,GAAW,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAC7C,CAAA;AAER,MAAM,CAAC,MAAM,IAAI,GAED,QAAQ,CAAC,IAAI,CAAA;AAE7B,MAAM,CAAC,MAAM,KAAK,GAId,KAAK,CAAC,MAAM,CACd,MAAM,EACN,MAAM,CAAC,OAAO,CACZ,eAAe,CAAC,eAAe,EAC/B,SAAS,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,CAAC,CAC1C,CACF,CAAA"}
|
package/dist/BotApiError.d.ts
CHANGED
|
@@ -1,91 +1,66 @@
|
|
|
1
|
-
import type * as
|
|
2
|
-
import type * as
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type * as HttpBody from '@effect/platform/HttpBody';
|
|
2
|
+
import type * as HttpClientError from '@effect/platform/HttpClientError';
|
|
3
|
+
import type * as BotApiTransport from './BotApiTransport.ts';
|
|
4
|
+
import * as Duration from 'effect/Duration';
|
|
5
|
+
import * as Dialog from './Dialog.ts';
|
|
6
|
+
export declare const TypeId = "@grom.js/effect-tg/BotApiError";
|
|
7
|
+
export type TypeId = typeof TypeId;
|
|
8
|
+
export declare const isBotApiError: (u: unknown) => u is BotApiError;
|
|
9
|
+
export type BotApiError = TransportError | MethodFailed | GroupUpgraded | RateLimited | InternalServerError;
|
|
10
|
+
declare const TransportError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
11
|
+
readonly _tag: "TransportError";
|
|
5
12
|
} & Readonly<A>;
|
|
6
13
|
/**
|
|
7
|
-
* Error
|
|
14
|
+
* Error caused by the transport when accessing Bot API.
|
|
8
15
|
*/
|
|
9
|
-
export declare class
|
|
10
|
-
|
|
11
|
-
description: string;
|
|
12
|
-
parameters?: BotApi.Types.ResponseParameters;
|
|
16
|
+
export declare class TransportError extends TransportError_base<{
|
|
17
|
+
cause: HttpClientError.HttpClientError | HttpBody.HttpBodyError;
|
|
13
18
|
}> {
|
|
19
|
+
readonly [TypeId]: TypeId;
|
|
14
20
|
get message(): string;
|
|
15
21
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*
|
|
19
|
-
* **Warning!** Error types are detected based on the error code and message
|
|
20
|
-
* returned from the Bot API, which are not guaranteed to be the same in
|
|
21
|
-
* the future. If they change, this function may not determine error type
|
|
22
|
-
* correctly.
|
|
23
|
-
*
|
|
24
|
-
* @see {@link https://github.com/tdlib/telegram-bot-api telegram-bot-api source code}
|
|
25
|
-
*/
|
|
26
|
-
export declare const narrow: (error: BotApiError) => KnownError | BotApiError;
|
|
27
|
-
export type KnownError = TooManyRequests | BotBlockedByUser | MessageNotModified | ReplyMarkupTooLong | QueryIdInvalid | MediaGroupedInvalid;
|
|
28
|
-
declare const TooManyRequests_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
29
|
-
readonly _tag: "@grom.js/effect-tg/BotApiError/TooManyRequests";
|
|
22
|
+
declare const MethodFailed_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
23
|
+
readonly _tag: "MethodFailed";
|
|
30
24
|
} & Readonly<A>;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
export declare class TooManyRequests extends TooManyRequests_base<{
|
|
35
|
-
cause: BotApiError;
|
|
36
|
-
retryAfter: Duration.Duration;
|
|
37
|
-
}> {
|
|
38
|
-
}
|
|
39
|
-
declare const BotBlockedByUser_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
40
|
-
readonly _tag: "@grom.js/effect-tg/BotApiError/BotBlockedByUser";
|
|
41
|
-
} & Readonly<A>;
|
|
42
|
-
/**
|
|
43
|
-
* Bot was blocked by the user.
|
|
44
|
-
*/
|
|
45
|
-
export declare class BotBlockedByUser extends BotBlockedByUser_base<{
|
|
46
|
-
cause: BotApiError;
|
|
47
|
-
}> {
|
|
48
|
-
}
|
|
49
|
-
declare const MessageNotModified_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
50
|
-
readonly _tag: "@grom.js/effect-tg/BotApiError/MessageNotModified";
|
|
51
|
-
} & Readonly<A>;
|
|
52
|
-
/**
|
|
53
|
-
* Message was not modified as its content and reply markup
|
|
54
|
-
* are exactly the same as the current one.
|
|
55
|
-
*/
|
|
56
|
-
export declare class MessageNotModified extends MessageNotModified_base<{
|
|
57
|
-
cause: BotApiError;
|
|
25
|
+
export declare class MethodFailed extends MethodFailed_base<{
|
|
26
|
+
response: FailureResponse;
|
|
27
|
+
possibleReason: MethodFailureReason;
|
|
58
28
|
}> {
|
|
29
|
+
readonly [TypeId]: TypeId;
|
|
30
|
+
get message(): string;
|
|
59
31
|
}
|
|
60
|
-
declare const
|
|
61
|
-
readonly _tag: "
|
|
32
|
+
declare const GroupUpgraded_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
33
|
+
readonly _tag: "GroupUpgraded";
|
|
62
34
|
} & Readonly<A>;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
export declare class ReplyMarkupTooLong extends ReplyMarkupTooLong_base<{
|
|
67
|
-
cause: BotApiError;
|
|
35
|
+
export declare class GroupUpgraded extends GroupUpgraded_base<{
|
|
36
|
+
response: FailureResponse;
|
|
37
|
+
supergroup: Dialog.Supergroup;
|
|
68
38
|
}> {
|
|
39
|
+
readonly [TypeId]: TypeId;
|
|
40
|
+
get message(): string;
|
|
69
41
|
}
|
|
70
|
-
declare const
|
|
71
|
-
readonly _tag: "
|
|
42
|
+
declare const RateLimited_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
43
|
+
readonly _tag: "RateLimited";
|
|
72
44
|
} & Readonly<A>;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
export declare class QueryIdInvalid extends QueryIdInvalid_base<{
|
|
77
|
-
cause: BotApiError;
|
|
45
|
+
export declare class RateLimited extends RateLimited_base<{
|
|
46
|
+
response: FailureResponse;
|
|
47
|
+
retryAfter: Duration.Duration;
|
|
78
48
|
}> {
|
|
49
|
+
readonly [TypeId]: TypeId;
|
|
50
|
+
get message(): string;
|
|
79
51
|
}
|
|
80
|
-
declare const
|
|
81
|
-
readonly _tag: "
|
|
52
|
+
declare const InternalServerError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
53
|
+
readonly _tag: "InternalServerError";
|
|
82
54
|
} & Readonly<A>;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
*/
|
|
86
|
-
export declare class MediaGroupedInvalid extends MediaGroupedInvalid_base<{
|
|
87
|
-
cause: BotApiError;
|
|
55
|
+
export declare class InternalServerError extends InternalServerError_base<{
|
|
56
|
+
response: FailureResponse;
|
|
88
57
|
}> {
|
|
58
|
+
readonly [TypeId]: TypeId;
|
|
89
59
|
}
|
|
60
|
+
export declare const fromResponse: (response: FailureResponse) => BotApiError;
|
|
61
|
+
export type MethodFailureReason = 'Unknown' | 'BotBlockedByUser' | 'MessageNotModified' | 'ReplyMarkupTooLong' | 'QueryIdInvalid' | 'MediaGroupedInvalid';
|
|
62
|
+
type FailureResponse = Extract<BotApiTransport.BotApiResponse, {
|
|
63
|
+
ok: false;
|
|
64
|
+
}>;
|
|
90
65
|
export {};
|
|
91
66
|
//# sourceMappingURL=BotApiError.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BotApiError.d.ts","sourceRoot":"","sources":["../src/BotApiError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,QAAQ,MAAM,
|
|
1
|
+
{"version":3,"file":"BotApiError.d.ts","sourceRoot":"","sources":["../src/BotApiError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,QAAQ,MAAM,2BAA2B,CAAA;AAC1D,OAAO,KAAK,KAAK,eAAe,MAAM,kCAAkC,CAAA;AACxE,OAAO,KAAK,KAAK,eAAe,MAAM,sBAAsB,CAAA;AAE5D,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAI3C,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAGrC,eAAO,MAAM,MAAM,mCAAmC,CAAA;AAEtD,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAA;AAElC,eAAO,MAAM,aAAa,GAAI,GAAG,OAAO,KAAG,CAAC,IAAI,WAA+C,CAAA;AAE/F,MAAM,MAAM,WA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AAK,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC,cAAc,EAAE;IAAE,EAAE,EAAE,KAAK,CAAA;CAAE,CAAC,CAAA"}
|
package/dist/BotApiError.js
CHANGED
|
@@ -1,53 +1,71 @@
|
|
|
1
1
|
import * as Data from 'effect/Data';
|
|
2
|
+
import * as Duration from 'effect/Duration';
|
|
3
|
+
import * as Match from 'effect/Match';
|
|
4
|
+
import * as Option from 'effect/Option';
|
|
5
|
+
import * as Predicate from 'effect/Predicate';
|
|
6
|
+
import * as Dialog from "./Dialog.js";
|
|
2
7
|
import * as internal from "./internal/botApiError.js";
|
|
8
|
+
export const TypeId = '@grom.js/effect-tg/BotApiError';
|
|
9
|
+
export const isBotApiError = (u) => Predicate.hasProperty(u, TypeId);
|
|
3
10
|
/**
|
|
4
|
-
* Error
|
|
11
|
+
* Error caused by the transport when accessing Bot API.
|
|
5
12
|
*/
|
|
6
|
-
export class
|
|
13
|
+
export class TransportError extends Data.TaggedError('TransportError') {
|
|
14
|
+
[TypeId] = TypeId;
|
|
7
15
|
get message() {
|
|
8
|
-
return
|
|
16
|
+
return Match.value(this.cause).pipe(Match.tagsExhaustive({
|
|
17
|
+
RequestError: e => e.message,
|
|
18
|
+
ResponseError: e => e.message,
|
|
19
|
+
HttpBodyError: e => Match.value(e.reason).pipe(Match.tagsExhaustive({
|
|
20
|
+
SchemaError: e => e.error.message,
|
|
21
|
+
JsonError: e => `JsonError: ${e.error}`,
|
|
22
|
+
})),
|
|
23
|
+
}));
|
|
9
24
|
}
|
|
10
25
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
* the future. If they change, this function may not determine error type
|
|
17
|
-
* correctly.
|
|
18
|
-
*
|
|
19
|
-
* @see {@link https://github.com/tdlib/telegram-bot-api telegram-bot-api source code}
|
|
20
|
-
*/
|
|
21
|
-
export const narrow = internal.narrow;
|
|
22
|
-
/**
|
|
23
|
-
* Flood limit exceeded. Need to wait `retryAfter` before retrying.
|
|
24
|
-
*/
|
|
25
|
-
export class TooManyRequests extends Data.TaggedError('@grom.js/effect-tg/BotApiError/TooManyRequests') {
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Bot was blocked by the user.
|
|
29
|
-
*/
|
|
30
|
-
export class BotBlockedByUser extends Data.TaggedError('@grom.js/effect-tg/BotApiError/BotBlockedByUser') {
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Message was not modified as its content and reply markup
|
|
34
|
-
* are exactly the same as the current one.
|
|
35
|
-
*/
|
|
36
|
-
export class MessageNotModified extends Data.TaggedError('@grom.js/effect-tg/BotApiError/MessageNotModified') {
|
|
26
|
+
export class MethodFailed extends Data.TaggedError('MethodFailed') {
|
|
27
|
+
[TypeId] = TypeId;
|
|
28
|
+
get message() {
|
|
29
|
+
return `(${this.response.error_code}) ${this.response.description}`;
|
|
30
|
+
}
|
|
37
31
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
export class GroupUpgraded extends Data.TaggedError('GroupUpgraded') {
|
|
33
|
+
[TypeId] = TypeId;
|
|
34
|
+
get message() {
|
|
35
|
+
return `Group has been upgraded to a supergroup with ID ${this.supergroup.id}.`;
|
|
36
|
+
}
|
|
42
37
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
export class RateLimited extends Data.TaggedError('RateLimited') {
|
|
39
|
+
[TypeId] = TypeId;
|
|
40
|
+
get message() {
|
|
41
|
+
return `Flood limit exceeded. Should wait for ${Duration.format(this.retryAfter)} before retrying.`;
|
|
42
|
+
}
|
|
47
43
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
*/
|
|
51
|
-
export class MediaGroupedInvalid extends Data.TaggedError('@grom.js/effect-tg/BotApiError/MediaGroupedInvalid') {
|
|
44
|
+
export class InternalServerError extends Data.TaggedError('InternalServerError') {
|
|
45
|
+
[TypeId] = TypeId;
|
|
52
46
|
}
|
|
47
|
+
export const fromResponse = (response) => {
|
|
48
|
+
if (response.error_code === 429 && response.parameters?.retry_after != null) {
|
|
49
|
+
return new RateLimited({
|
|
50
|
+
response,
|
|
51
|
+
retryAfter: Duration.seconds(response.parameters.retry_after),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
if (response.error_code === 400 && response.parameters?.migrate_to_chat_id != null) {
|
|
55
|
+
return new GroupUpgraded({
|
|
56
|
+
response,
|
|
57
|
+
supergroup: Dialog.supergroup(Option.getOrThrow(Dialog.decodePeerId('supergroup', response.parameters.migrate_to_chat_id))),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if (response.error_code >= 500) {
|
|
61
|
+
return new InternalServerError({ response });
|
|
62
|
+
}
|
|
63
|
+
return new MethodFailed({
|
|
64
|
+
response,
|
|
65
|
+
possibleReason: internal.guessReason({
|
|
66
|
+
code: response.error_code,
|
|
67
|
+
description: response.description,
|
|
68
|
+
}),
|
|
69
|
+
});
|
|
70
|
+
};
|
|
53
71
|
//# sourceMappingURL=BotApiError.js.map
|
package/dist/BotApiError.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BotApiError.js","sourceRoot":"","sources":["../src/BotApiError.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BotApiError.js","sourceRoot":"","sources":["../src/BotApiError.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,IAAI,MAAM,aAAa,CAAA;AACnC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,QAAQ,MAAM,2BAA2B,CAAA;AAErD,MAAM,CAAC,MAAM,MAAM,GAAG,gCAAgC,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,QAAQ,CAAC,WAAW,CAAC;YACnC,IAAI,EAAE,QAAQ,CAAC,UAAU;YACzB,WAAW,EAAE,QAAQ,CAAC,WAAW;SAClC,CAAC;KACH,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import type * as
|
|
1
|
+
import type * as BotApi from './BotApi.ts';
|
|
2
|
+
import type * as BotApiError from './BotApiError.ts';
|
|
2
3
|
import * as HttpClient from '@effect/platform/HttpClient';
|
|
3
4
|
import * as Context from 'effect/Context';
|
|
4
5
|
import * as Effect from 'effect/Effect';
|
|
5
6
|
import * as Layer from 'effect/Layer';
|
|
6
7
|
import * as BotApiUrl from './BotApiUrl.ts';
|
|
7
|
-
declare const BotApiTransport_base: Context.TagClass<BotApiTransport, "@grom.js/effect-tg/BotApiTransport",
|
|
8
|
+
declare const BotApiTransport_base: Context.TagClass<BotApiTransport, "@grom.js/effect-tg/BotApiTransport", Service>;
|
|
8
9
|
export declare class BotApiTransport extends BotApiTransport_base {
|
|
9
10
|
}
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
sendRequest: (method: string, params: unknown) => Effect.Effect<BotApiResponse, BotApiTransportError>;
|
|
13
|
-
}
|
|
11
|
+
export interface Service {
|
|
12
|
+
sendRequest: (method: string, params: unknown) => Effect.Effect<BotApiResponse, BotApiError.TransportError>;
|
|
14
13
|
}
|
|
15
14
|
/**
|
|
16
15
|
* @see https://core.telegram.org/bots/api#making-requests
|
|
@@ -23,18 +22,12 @@ export type BotApiResponse = {
|
|
|
23
22
|
ok: false;
|
|
24
23
|
error_code: number;
|
|
25
24
|
description: string;
|
|
26
|
-
parameters?: Types.ResponseParameters;
|
|
25
|
+
parameters?: BotApi.Types.ResponseParameters;
|
|
27
26
|
};
|
|
28
|
-
declare const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
* Error caused by the transport when accessing Bot API.
|
|
33
|
-
*/
|
|
34
|
-
export declare class BotApiTransportError extends BotApiTransportError_base<{
|
|
35
|
-
cause: unknown;
|
|
36
|
-
}> {
|
|
37
|
-
}
|
|
27
|
+
export declare const make: (options: {
|
|
28
|
+
httpClient: HttpClient.HttpClient;
|
|
29
|
+
botApiUrl: BotApiUrl.Service;
|
|
30
|
+
}) => Service;
|
|
38
31
|
export declare const layer: Layer.Layer<BotApiTransport, never, HttpClient.HttpClient | BotApiUrl.BotApiUrl>;
|
|
39
32
|
export {};
|
|
40
33
|
//# sourceMappingURL=BotApiTransport.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BotApiTransport.d.ts","sourceRoot":"","sources":["../src/BotApiTransport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,KAAK,MAAM
|
|
1
|
+
{"version":3,"file":"BotApiTransport.d.ts","sourceRoot":"","sources":["../src/BotApiTransport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,MAAM,aAAa,CAAA;AAC1C,OAAO,KAAK,KAAK,WAAW,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAAK,UAAU,MAAM,6BAA6B,CAAA;AACzD,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;;AAG3C,qBAAa,eAAgB,SAAQ,oBAGlC;CAAG;AAEN,MAAM,WAAW,OAAO;IACtB,WAAW,EAAE,CACX,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,OAAO,KACZ,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,WAAW,CAAC,cAAc,CAAC,CAAA;CAC/D;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB;IACA,EAAE,EAAE,IAAI,CAAA;IACR,MAAM,EAAE,OAAO,CAAA;IACf,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,GAAG;IACF,EAAE,EAAE,KAAK,CAAA;IACT,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAA;CAC7C,CAAA;AAEH,eAAO,MAAM,IAAI,EAAE,CAAC,OAAO,EAAE;IAC3B,UAAU,EAAE,UAAU,CAAC,UAAU,CAAA;IACjC,SAAS,EAAE,SAAS,CAAC,OAAO,CAAA;CAC7B,KAAK,OAAuB,CAAA;AAE7B,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,KAAK,CAC7B,eAAe,EACf,KAAK,EACL,UAAU,CAAC,UAAU,GAAG,SAAS,CAAC,SAAS,CAQ5C,CAAA"}
|
package/dist/BotApiTransport.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import * as HttpClient from '@effect/platform/HttpClient';
|
|
2
2
|
import * as Context from 'effect/Context';
|
|
3
|
-
import * as Data from 'effect/Data';
|
|
4
3
|
import * as Effect from 'effect/Effect';
|
|
5
4
|
import * as Layer from 'effect/Layer';
|
|
6
5
|
import * as BotApiUrl from "./BotApiUrl.js";
|
|
7
6
|
import * as internal from "./internal/botApiTransport.js";
|
|
8
7
|
export class BotApiTransport extends Context.Tag('@grom.js/effect-tg/BotApiTransport')() {
|
|
9
8
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*/
|
|
13
|
-
export class BotApiTransportError extends Data.TaggedError('@grom.js/effect-tg/BotApiTransport/BotApiTransportError') {
|
|
14
|
-
}
|
|
15
|
-
export const layer = Layer.effect(BotApiTransport, Effect.all([HttpClient.HttpClient, BotApiUrl.BotApiUrl]).pipe(Effect.andThen(reqs => internal.make(...reqs))));
|
|
9
|
+
export const make = internal.make;
|
|
10
|
+
export const layer = Layer.effect(BotApiTransport, Effect.all([HttpClient.HttpClient, BotApiUrl.BotApiUrl]).pipe(Effect.andThen(([httpClient, botApiUrl]) => (internal.make({ httpClient, botApiUrl })))));
|
|
16
11
|
//# sourceMappingURL=BotApiTransport.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BotApiTransport.js","sourceRoot":"","sources":["../src/BotApiTransport.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BotApiTransport.js","sourceRoot":"","sources":["../src/BotApiTransport.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,UAAU,MAAM,6BAA6B,CAAA;AACzD,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,QAAQ,MAAM,+BAA+B,CAAA;AAEzD,MAAM,OAAO,eAAgB,SAAQ,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,EAGnF;CAAG;AAwBN,MAAM,CAAC,MAAM,IAAI,GAGD,QAAQ,CAAC,IAAI,CAAA;AAE7B,MAAM,CAAC,MAAM,KAAK,GAId,KAAK,CAAC,MAAM,CACd,eAAe,EACf,MAAM,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,UAAU,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAC3D,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,CAC1C,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC,CAAC,CAC1C,CACF,CACF,CAAA"}
|
package/dist/BotApiUrl.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import * as Context from 'effect/Context';
|
|
2
|
-
declare const BotApiUrl_base: Context.TagClass<BotApiUrl, "@grom.js/effect-tg/BotApiUrl",
|
|
2
|
+
declare const BotApiUrl_base: Context.TagClass<BotApiUrl, "@grom.js/effect-tg/BotApiUrl", Service>;
|
|
3
3
|
export declare class BotApiUrl extends BotApiUrl_base {
|
|
4
4
|
}
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
toFile: (filePath: string) => URL;
|
|
9
|
-
}
|
|
5
|
+
export interface Service {
|
|
6
|
+
toMethod: (method: string) => URL;
|
|
7
|
+
toFile: (filePath: string) => URL;
|
|
10
8
|
}
|
|
11
|
-
export declare const makeProd: (token: string) =>
|
|
12
|
-
export declare const makeTest: (token: string) =>
|
|
9
|
+
export declare const makeProd: (token: string) => Service;
|
|
10
|
+
export declare const makeTest: (token: string) => Service;
|
|
13
11
|
export {};
|
|
14
12
|
//# sourceMappingURL=BotApiUrl.d.ts.map
|
package/dist/BotApiUrl.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BotApiUrl.d.ts","sourceRoot":"","sources":["../src/BotApiUrl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;;AAEzC,qBAAa,SAAU,SAAQ,cAG5B;CAAG;AAEN,MAAM,
|
|
1
|
+
{"version":3,"file":"BotApiUrl.d.ts","sourceRoot":"","sources":["../src/BotApiUrl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;;AAEzC,qBAAa,SAAU,SAAQ,cAG5B;CAAG;AAEN,MAAM,WAAW,OAAO;IACtB,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,GAAG,CAAA;IACjC,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,GAAG,CAAA;CAClC;AAED,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,KAAG,OAKxC,CAAA;AAED,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,KAAG,OAMxC,CAAA"}
|