@effect-ak/tg-bot-client 0.2.0 → 0.2.1

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.
Files changed (45) hide show
  1. package/dist/cjs/bot/factory/_service.js +49 -10
  2. package/dist/cjs/bot/factory/client-config.js +49 -10
  3. package/dist/cjs/bot/factory/make-bot.js +45 -6
  4. package/dist/cjs/bot/message-handler/_service.js +42 -3
  5. package/dist/cjs/bot/run.js +3 -3
  6. package/dist/cjs/bot/update-poller/_service.js +49 -10
  7. package/dist/cjs/bot/update-poller/fetch-updates.js +44 -5
  8. package/dist/cjs/bot/update-poller/poll-and-handle.js +46 -7
  9. package/dist/cjs/client/_client.js +49 -10
  10. package/dist/cjs/client/config.js +45 -6
  11. package/dist/cjs/client/errors.js +42 -3
  12. package/dist/cjs/client/execute-request/_service.js +48 -9
  13. package/dist/cjs/client/execute-request/execute.js +52 -13
  14. package/dist/cjs/client/execute-request/payload.js +2 -2
  15. package/dist/cjs/client/file/_service.js +51 -12
  16. package/dist/cjs/client/file/get-file.js +45 -6
  17. package/dist/cjs/const.js +5 -5
  18. package/dist/cjs/index.js +24 -55
  19. package/dist/dts/bot/factory/make-bot.d.ts +2 -2
  20. package/dist/esm/bot/factory/_service.js +46 -9
  21. package/dist/esm/bot/factory/client-config.js +46 -9
  22. package/dist/esm/bot/factory/make-bot.js +42 -5
  23. package/dist/esm/bot/message-handler/_service.js +39 -2
  24. package/dist/esm/bot/message-handler/types.js +2 -1
  25. package/dist/esm/bot/message-handler/utils.js +5 -1
  26. package/dist/esm/bot/run.js +8 -4
  27. package/dist/esm/bot/update-poller/_service.js +46 -9
  28. package/dist/esm/bot/update-poller/errors.js +2 -1
  29. package/dist/esm/bot/update-poller/fetch-updates.js +41 -4
  30. package/dist/esm/bot/update-poller/poll-and-handle.js +43 -6
  31. package/dist/esm/bot/update-poller/settings.js +5 -1
  32. package/dist/esm/client/_client.js +46 -9
  33. package/dist/esm/client/config.js +43 -5
  34. package/dist/esm/client/errors.js +39 -2
  35. package/dist/esm/client/execute-request/_service.js +45 -8
  36. package/dist/esm/client/execute-request/execute.js +49 -12
  37. package/dist/esm/client/execute-request/payload.js +7 -3
  38. package/dist/esm/client/file/_service.js +48 -11
  39. package/dist/esm/client/file/get-file.js +42 -5
  40. package/dist/esm/client/guards.js +9 -3
  41. package/dist/esm/const.js +9 -5
  42. package/dist/esm/index.js +21 -5
  43. package/dist/esm/specification/api.js +2 -1
  44. package/dist/esm/specification/types.js +2 -1
  45. package/package.json +1 -2
@@ -1,9 +1,46 @@
1
- import * as Micro from "effect/Micro";
2
- import { BotUpdatePollerService, BotUpdatesPollerServiceDefault } from "../../bot/update-poller/_service.js";
3
- export const makeBot = (messageHandler) => Micro.gen(function* () {
4
- const { runBot } = yield* Micro.service(BotUpdatePollerService);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.makeBot = void 0;
37
+ const Micro = __importStar(require("effect/Micro"));
38
+ const _service_js_1 = require("../../bot/update-poller/_service.js");
39
+ const makeBot = (messageHandler) => Micro.gen(function* () {
40
+ const { runBot } = yield* Micro.service(_service_js_1.BotUpdatePollerService);
5
41
  return yield* runBot(messageHandler);
6
- }).pipe(Micro.provideServiceEffect(BotUpdatePollerService, BotUpdatesPollerServiceDefault), Micro.tapError(error => {
42
+ }).pipe(Micro.provideServiceEffect(_service_js_1.BotUpdatePollerService, _service_js_1.BotUpdatesPollerServiceDefault), Micro.tapError(error => {
7
43
  console.error(error);
8
44
  return Micro.void;
9
45
  }));
46
+ exports.makeBot = makeBot;
@@ -1,4 +1,41 @@
1
- import * as Context from "effect/Context";
2
- export class BotMessageHandler extends Context.Tag("BotMessageHandler")() {
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.BotMessageHandler = void 0;
37
+ const Context = __importStar(require("effect/Context"));
38
+ class BotMessageHandler extends Context.Tag("BotMessageHandler")() {
3
39
  }
40
+ exports.BotMessageHandler = BotMessageHandler;
4
41
  ;
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,7 @@
1
- export const extractUpdate = (input) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractUpdate = void 0;
4
+ const extractUpdate = (input) => {
2
5
  for (const [field, value] of Object.entries(input)) {
3
6
  if (field == "update_id") {
4
7
  continue;
@@ -10,3 +13,4 @@ export const extractUpdate = (input) => {
10
13
  }
11
14
  return undefined;
12
15
  };
16
+ exports.extractUpdate = extractUpdate;
@@ -1,6 +1,10 @@
1
- import { Micro } from "effect";
2
- import { BotFactoryServiceDefault } from "./factory/_service.js";
3
- export const runTgChatBot = (input) => BotFactoryServiceDefault
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runTgChatBot = void 0;
4
+ const effect_1 = require("effect");
5
+ const _service_js_1 = require("./factory/_service.js");
6
+ const runTgChatBot = (input) => _service_js_1.BotFactoryServiceDefault
4
7
  .runBot(input)
5
- .pipe(Micro.runPromise)
8
+ .pipe(effect_1.Micro.runPromise)
6
9
  .finally(() => "Telegram chat bot has been shutdown");
10
+ exports.runTgChatBot = runTgChatBot;
@@ -1,20 +1,57 @@
1
- import * as Micro from "effect/Micro";
2
- import * as Context from "effect/Context";
3
- import { ClientExecuteRequestService, ClientExecuteRequestServiceDefault } from "../../client/execute-request/_service.js";
4
- import { pollAndHandle } from "./poll-and-handle.js";
5
- export class BotUpdatePollerService extends Context.Tag("BotUpdatePollerService")() {
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.BotUpdatesPollerServiceDefault = exports.BotUpdatePollerService = void 0;
37
+ const Micro = __importStar(require("effect/Micro"));
38
+ const Context = __importStar(require("effect/Context"));
39
+ const _service_js_1 = require("../../client/execute-request/_service.js");
40
+ const poll_and_handle_js_1 = require("./poll-and-handle.js");
41
+ class BotUpdatePollerService extends Context.Tag("BotUpdatePollerService")() {
6
42
  }
43
+ exports.BotUpdatePollerService = BotUpdatePollerService;
7
44
  ;
8
- export const BotUpdatesPollerServiceDefault = Micro.gen(function* () {
45
+ exports.BotUpdatesPollerServiceDefault = Micro.gen(function* () {
9
46
  const state = {
10
47
  isActive: false,
11
48
  };
12
- const client = yield* Micro.service(ClientExecuteRequestService);
49
+ const client = yield* Micro.service(_service_js_1.ClientExecuteRequestService);
13
50
  const runBot = (messageHandler) => Micro.gen(function* () {
14
51
  if (state.isActive) {
15
52
  return yield* Micro.fail("AlreadyRunning");
16
53
  }
17
- const fiber = yield* pollAndHandle({
54
+ const fiber = yield* (0, poll_and_handle_js_1.pollAndHandle)({
18
55
  settings: messageHandler,
19
56
  execute: client.execute
20
57
  }).pipe(Micro.forkDaemon);
@@ -28,4 +65,4 @@ export const BotUpdatesPollerServiceDefault = Micro.gen(function* () {
28
65
  return {
29
66
  runBot
30
67
  };
31
- }).pipe(Micro.provideServiceEffect(ClientExecuteRequestService, ClientExecuteRequestServiceDefault));
68
+ }).pipe(Micro.provideServiceEffect(_service_js_1.ClientExecuteRequestService, _service_js_1.ClientExecuteRequestServiceDefault));
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +1,42 @@
1
- import * as Micro from "effect/Micro";
2
- import { extractUpdate } from "../../bot/message-handler/utils.js";
3
- export const fetchUpdates = ({ state, settings, execute, handlers }) => Micro.gen(function* () {
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.fetchUpdates = void 0;
37
+ const Micro = __importStar(require("effect/Micro"));
38
+ const utils_js_1 = require("../../bot/message-handler/utils.js");
39
+ const fetchUpdates = ({ state, settings, execute, handlers }) => Micro.gen(function* () {
4
40
  const updateId = state.lastUpdateId;
5
41
  console.info("getting updates", state);
6
42
  const updates = yield* execute("get_updates", {
@@ -10,7 +46,7 @@ export const fetchUpdates = ({ state, settings, execute, handlers }) => Micro.ge
10
46
  let lastSuccessId = undefined;
11
47
  let hasError = false;
12
48
  for (const updateObject of updates) {
13
- const update = extractUpdate(updateObject);
49
+ const update = (0, utils_js_1.extractUpdate)(updateObject);
14
50
  if (!update) {
15
51
  console.warn("Unknown update", update);
16
52
  hasError = true;
@@ -47,3 +83,4 @@ export const fetchUpdates = ({ state, settings, execute, handlers }) => Micro.ge
47
83
  }
48
84
  return { updates, lastSuccessId, hasError };
49
85
  });
86
+ exports.fetchUpdates = fetchUpdates;
@@ -1,13 +1,49 @@
1
- import * as Micro from "effect/Micro";
2
- import { makeSettingsFrom } from "./settings.js";
3
- import { fetchUpdates } from "./fetch-updates.js";
4
- export const pollAndHandle = (input) => {
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.pollAndHandle = void 0;
37
+ const Micro = __importStar(require("effect/Micro"));
38
+ const settings_js_1 = require("./settings.js");
39
+ const fetch_updates_js_1 = require("./fetch-updates.js");
40
+ const pollAndHandle = (input) => {
5
41
  const state = {
6
42
  lastUpdateId: undefined,
7
43
  emptyResponses: 0
8
44
  };
9
- const settings = makeSettingsFrom(input.settings);
10
- return Micro.delay(1000)(fetchUpdates({
45
+ const settings = (0, settings_js_1.makeSettingsFrom)(input.settings);
46
+ return Micro.delay(1000)((0, fetch_updates_js_1.fetchUpdates)({
11
47
  state, settings,
12
48
  execute: input.execute,
13
49
  handlers: input.settings,
@@ -35,3 +71,4 @@ export const pollAndHandle = (input) => {
35
71
  }
36
72
  }));
37
73
  };
74
+ exports.pollAndHandle = pollAndHandle;
@@ -1,4 +1,7 @@
1
- export const makeSettingsFrom = (input) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeSettingsFrom = void 0;
4
+ const makeSettingsFrom = (input) => {
2
5
  let limit = input.batch_size ?? 10;
3
6
  let timeout = input.timeout ?? 10;
4
7
  if (limit < 10 || limit > 100) {
@@ -13,3 +16,4 @@ export const makeSettingsFrom = (input) => {
13
16
  limit, timeout
14
17
  };
15
18
  };
19
+ exports.makeSettingsFrom = makeSettingsFrom;
@@ -1,16 +1,53 @@
1
- import * as Micro from "effect/Micro";
2
- import { makeTgBotClientConfig, TgBotClientConfig } from "./config.js";
3
- import { ClientExecuteRequestService, ClientExecuteRequestServiceDefault } from "./execute-request/_service.js";
4
- import { ClientFileService, ClientFileServiceDefault } from "./file/_service.js";
5
- export const makeTgBotClient = (input) => {
6
- const config = makeTgBotClientConfig(input);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.makeTgBotClient = void 0;
37
+ const Micro = __importStar(require("effect/Micro"));
38
+ const config_js_1 = require("./config.js");
39
+ const _service_js_1 = require("./execute-request/_service.js");
40
+ const _service_js_2 = require("./file/_service.js");
41
+ const makeTgBotClient = (input) => {
42
+ const config = (0, config_js_1.makeTgBotClientConfig)(input);
7
43
  const client = Micro.gen(function* () {
8
- const execute = yield* Micro.service(ClientExecuteRequestService);
9
- const file = yield* Micro.service(ClientFileService);
44
+ const execute = yield* Micro.service(_service_js_1.ClientExecuteRequestService);
45
+ const file = yield* Micro.service(_service_js_2.ClientFileService);
10
46
  return {
11
47
  execute: (method, input) => execute.execute(method, input).pipe(Micro.runPromise),
12
48
  getFile: (input) => file.getFile(input).pipe(Micro.runPromise)
13
49
  };
14
- }).pipe(Micro.provideServiceEffect(ClientExecuteRequestService, ClientExecuteRequestServiceDefault), Micro.provideServiceEffect(ClientFileService, ClientFileServiceDefault), Micro.provideService(TgBotClientConfig, config), Micro.runSync);
50
+ }).pipe(Micro.provideServiceEffect(_service_js_1.ClientExecuteRequestService, _service_js_1.ClientExecuteRequestServiceDefault), Micro.provideServiceEffect(_service_js_2.ClientFileService, _service_js_2.ClientFileServiceDefault), Micro.provideService(config_js_1.TgBotClientConfig, config), Micro.runSync);
15
51
  return client;
16
52
  };
53
+ exports.makeTgBotClient = makeTgBotClient;
@@ -1,8 +1,46 @@
1
- import * as Context from "effect/Context";
2
- import { defaultBaseUrl } from "../const.js";
3
- export const makeTgBotClientConfig = (input) => TgBotClientConfig.of({
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.TgBotClientConfig = exports.makeTgBotClientConfig = void 0;
37
+ const Context = __importStar(require("effect/Context"));
38
+ const const_js_1 = require("../const.js");
39
+ const makeTgBotClientConfig = (input) => TgBotClientConfig.of({
4
40
  ...input,
5
- ["base-url"]: input["base-url"] ?? defaultBaseUrl
41
+ ["base-url"]: input["base-url"] ?? const_js_1.defaultBaseUrl
6
42
  });
7
- export class TgBotClientConfig extends Context.Tag("TgBotClientConfig")() {
43
+ exports.makeTgBotClientConfig = makeTgBotClientConfig;
44
+ class TgBotClientConfig extends Context.Tag("TgBotClientConfig")() {
8
45
  }
46
+ exports.TgBotClientConfig = TgBotClientConfig;
@@ -1,5 +1,41 @@
1
- import * as Data from "effect/Data";
2
- export class TgBotClientError extends Data.TaggedError("TgBotClientError") {
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.TgBotClientError = void 0;
37
+ const Data = __importStar(require("effect/Data"));
38
+ class TgBotClientError extends Data.TaggedError("TgBotClientError") {
3
39
  static missingSuccess = new TgBotClientError({
4
40
  reason: {
5
41
  type: "ClientInternalError",
@@ -7,3 +43,4 @@ export class TgBotClientError extends Data.TaggedError("TgBotClientError") {
7
43
  },
8
44
  });
9
45
  }
46
+ exports.TgBotClientError = TgBotClientError;
@@ -1,12 +1,49 @@
1
- import * as Micro from "effect/Micro";
2
- import * as Context from "effect/Context";
3
- import { TgBotClientConfig } from "../config.js";
4
- import { execute } from "./execute.js";
5
- export class ClientExecuteRequestService extends Context.Tag("ClientExecuteRequestService")() {
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ClientExecuteRequestServiceDefault = exports.ClientExecuteRequestService = void 0;
37
+ const Micro = __importStar(require("effect/Micro"));
38
+ const Context = __importStar(require("effect/Context"));
39
+ const config_js_1 = require("../config.js");
40
+ const execute_js_1 = require("./execute.js");
41
+ class ClientExecuteRequestService extends Context.Tag("ClientExecuteRequestService")() {
6
42
  }
7
- export const ClientExecuteRequestServiceDefault = Micro.gen(function* () {
8
- const config = yield* Micro.service(TgBotClientConfig);
43
+ exports.ClientExecuteRequestService = ClientExecuteRequestService;
44
+ exports.ClientExecuteRequestServiceDefault = Micro.gen(function* () {
45
+ const config = yield* Micro.service(config_js_1.TgBotClientConfig);
9
46
  return {
10
- execute: (method, input) => execute(config, method, input)
47
+ execute: (method, input) => (0, execute_js_1.execute)(config, method, input)
11
48
  };
12
49
  });
@@ -1,31 +1,67 @@
1
- import * as Micro from "effect/Micro";
2
- import * as String from "effect/String";
3
- import { TgBotClientError } from "../errors.js";
4
- import { makePayload } from "./payload.js";
5
- import { isTgBotApiResponse } from "../guards.js";
6
- export const execute = (config, method, input) => Micro.gen(function* () {
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.execute = void 0;
37
+ const Micro = __importStar(require("effect/Micro"));
38
+ const String = __importStar(require("effect/String"));
39
+ const errors_js_1 = require("../errors.js");
40
+ const payload_js_1 = require("./payload.js");
41
+ const guards_js_1 = require("../guards.js");
42
+ const execute = (config, method, input) => Micro.gen(function* () {
7
43
  const httpResponse = yield* Micro.tryPromise({
8
44
  try: () => fetch(`${config["base-url"]}/bot${config["bot-token"]}/${String.snakeToCamel(method)}`, {
9
- body: makePayload(input) ?? null,
45
+ body: (0, payload_js_1.makePayload)(input) ?? null,
10
46
  method: "POST",
11
47
  }),
12
- catch: cause => new TgBotClientError({
48
+ catch: cause => new errors_js_1.TgBotClientError({
13
49
  reason: { type: "ClientInternalError", cause }
14
50
  })
15
51
  });
16
52
  const response = yield* Micro.tryPromise({
17
53
  try: () => httpResponse.json(),
18
- catch: () => new TgBotClientError({
54
+ catch: () => new errors_js_1.TgBotClientError({
19
55
  reason: { type: "UnexpectedResponse", response: httpResponse }
20
56
  })
21
57
  });
22
- if (!isTgBotApiResponse(response)) {
23
- return yield* Micro.fail(new TgBotClientError({
58
+ if (!(0, guards_js_1.isTgBotApiResponse)(response)) {
59
+ return yield* Micro.fail(new errors_js_1.TgBotClientError({
24
60
  reason: { type: "UnexpectedResponse", response }
25
61
  }));
26
62
  }
27
63
  if (!httpResponse.ok) {
28
- return yield* Micro.fail(new TgBotClientError({
64
+ return yield* Micro.fail(new errors_js_1.TgBotClientError({
29
65
  reason: {
30
66
  type: "NotOkResponse",
31
67
  ...(response.error_code ? { errorCode: response.error_code } : undefined),
@@ -35,3 +71,4 @@ export const execute = (config, method, input) => Micro.gen(function* () {
35
71
  }
36
72
  return response.result;
37
73
  });
74
+ exports.execute = execute;