Skip to content

Commit 0b8c248

Browse files
committed
refactor, prepare for release
1 parent 45d9f7c commit 0b8c248

16 files changed

Lines changed: 335 additions & 191 deletions

bun.lock

Lines changed: 157 additions & 92 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eslint.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ import antfu from '@antfu/eslint-config'
22

33
export default antfu({
44
formatters: true,
5+
stylistic: {
6+
indent: 2,
7+
quotes: 'single',
8+
semi: false,
9+
},
10+
markdown: false, // Disable linting of code blocks in Markdown.
511
}, {
612
rules: {
713
'antfu/top-level-function': 'off',

package.json

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,46 @@
22
"name": "@grom.js/effectg",
33
"type": "module",
44
"version": "0.1.0",
5-
"private": false,
5+
"packageManager": "bun@1.3.1",
6+
"license": "MIT",
7+
"repository": {
8+
"type": "git",
9+
"url": "https://github.com/grom-dev/effectg.git"
10+
},
11+
"exports": {
12+
".": {
13+
"types": "./dist/index.d.ts",
14+
"import": "./dist/index.js"
15+
}
16+
},
17+
"files": ["dist/"],
18+
"engines": {
19+
"node": "22.x"
20+
},
621
"scripts": {
7-
"gen": "bun run scripts/gen-bot-api.ts",
8-
"typecheck": "tsc",
22+
"gen:bot-api": "bun run scripts/gen-bot-api.ts",
23+
"typecheck": "tsc --build --noEmit",
24+
"build": "tsc --build",
25+
"deps": "taze --write --interactive --include-locked minor",
926
"lint": "eslint .",
10-
"lint:fix": "eslint . --fix"
27+
"lint:fix": "eslint . --fix",
28+
"release": "bumpp"
1129
},
1230
"dependencies": {
13-
"@effect/platform": "^0.91.1",
14-
"@effect/platform-bun": "^0.80.0",
15-
"effect": "^3.17.14"
31+
"@effect/platform": "0.93.0",
32+
"@effect/platform-bun": "0.83.0",
33+
"effect": "3.19.2"
1634
},
1735
"devDependencies": {
18-
"@antfu/eslint-config": "^5.4.1",
19-
"@grom.js/bot-api-spec": "^0.4.1",
20-
"@types/bun": "latest",
21-
"eslint": "^9.36.0",
22-
"eslint-plugin-format": "^1.0.1",
23-
"ts-morph": "^27.0.0",
24-
"typescript": "^5.9.3"
36+
"@antfu/eslint-config": "6.2.0",
37+
"@grom.js/bot-api-spec": "0.4.1",
38+
"@types/bun": "1.3.1",
39+
"@types/node": "^22.19.0",
40+
"bumpp": "10.3.1",
41+
"eslint": "9.39.1",
42+
"eslint-plugin-format": "1.0.2",
43+
"taze": "19.9.0",
44+
"ts-morph": "27.0.2",
45+
"typescript": "5.9.3"
2546
}
2647
}

scripts/gen-bot-api.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ async function main() {
77
const proj = new Project()
88
genTypes(proj.createSourceFile('./src/internal/botApiTypes.gen.ts', {}, { overwrite: true }))
99
genMethods(proj.createSourceFile('./src/internal/botApiMethods.gen.ts', {}, { overwrite: true }))
10-
genBotApiShape(proj.createSourceFile('./src/internal/botApiShape.gen.ts', {}, { overwrite: true }))
10+
genShape(proj.createSourceFile('./src/internal/botApiShape.gen.ts', {}, { overwrite: true }))
1111
await proj.save()
1212
}
1313

@@ -49,12 +49,12 @@ function genMethods(f: SourceFile): void {
4949
inputFile: 'InputFile',
5050
}
5151
f.addImportDeclaration({
52-
moduleSpecifier: './botApiTypes.gen.ts',
52+
moduleSpecifier: './botApiTypes.gen.js',
5353
isTypeOnly: true,
5454
namespaceImport: 'Types',
5555
})
5656
f.addImportDeclaration({
57-
moduleSpecifier: './inputFile.ts',
57+
moduleSpecifier: './inputFile.js',
5858
isTypeOnly: true,
5959
namedImports: ['InputFile'],
6060
})
@@ -93,12 +93,12 @@ function genMethods(f: SourceFile): void {
9393
}
9494
}
9595

96-
function genBotApiShape(f: SourceFile): void {
96+
function genShape(f: SourceFile): void {
9797
f.addImportDeclarations([
9898
{
9999
isTypeOnly: true,
100100
namedImports: ['BotApiMethod'],
101-
moduleSpecifier: './botApiMethod',
101+
moduleSpecifier: './botApiMethod.js',
102102
},
103103
])
104104
f.addInterface({

src/BotApi.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import type { BotApiShape } from './internal/botApiShape.gen'
1+
import type { BotApiShape } from './internal/botApiShape.gen.js'
22
import * as Context from 'effect/Context'
3-
import * as Layer from 'effect/Layer'
4-
import * as internal from './internal/botApi'
3+
import * as internal from './internal/botApi.js'
4+
5+
export type { MethodParams, MethodResults } from './internal/botApiMethods.gen.js'
6+
export type * as Types from './internal/botApiTypes.gen.js'
57

68
export class BotApi extends Context.Tag('@grom.js/effectg/BotApi')<
79
BotApi,
810
BotApiShape
911
>() {}
1012

1113
export const make = internal.make
12-
export const layer = Layer.effect(BotApi, make)

src/BotApiError.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type * as Types from './internal/botApiTypes.gen'
1+
import type * as Types from './internal/botApiTypes.gen.js'
22
import * as Data from 'effect/Data'
33

44
/**

src/BotApiTransport.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import type * as Effect from 'effect/Effect'
2-
import type { BotApiTransportError } from './BotApiTransportError'
3-
import type * as Types from './internal/botApiTypes.gen'
4-
import { Layer } from 'effect'
2+
import type { BotApiTransportError } from './BotApiTransportError.js'
3+
import type * as Types from './internal/botApiTypes.gen.js'
54
import * as Context from 'effect/Context'
6-
import * as internal from './internal/botApiTransport'
5+
import * as internal from './internal/botApiTransport.js'
76

87
export class BotApiTransport extends Context.Tag('@grom.js/effectg/BotApiTransport')<
98
BotApiTransport,
@@ -33,16 +32,14 @@ export type BotApiResponse
3332

3433
export const makeWith = internal.makeWith
3534

36-
export const layerProd = (token: string) => Layer.effect(
37-
BotApiTransport,
35+
export const makeProd = (token: string) => (
3836
makeWith({
3937
makeUrl: method => new URL(`https://api.telegram.org/bot${token}/${method}`),
40-
}),
38+
})
4139
)
4240

43-
export const layerTest = (token: string) => Layer.effect(
44-
BotApiTransport,
41+
export const makeTest = (token: string) => (
4542
makeWith({
4643
makeUrl: method => new URL(`https://api.telegram.org/bot${token}/test/${method}`),
47-
}),
44+
})
4845
)

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export * as BotApi from './BotApi'
2-
export * as BotApiError from './BotApiError'
3-
export * as BotApiTransport from './BotApiTransport'
4-
export * as BotApiTransportError from './BotApiTransportError'
1+
export * as BotApi from './BotApi.js'
2+
export * as BotApiError from './BotApiError.js'
3+
export * as BotApiTransport from './BotApiTransport.js'
4+
export * as BotApiTransportError from './BotApiTransportError.js'

src/internal/botApi.ts

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
1-
import type { BotApiShape } from './botApiShape.gen'
1+
import type { BotApiTransport } from '../BotApiTransport.js'
2+
import type { BotApiShape } from './botApiShape.gen.js'
23
import * as Effect from 'effect/Effect'
3-
import { BotApiError } from '../BotApiError'
4-
import { BotApiTransport } from '../BotApiTransport'
4+
import { BotApiError } from '../BotApiError.js'
55

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
2934
})
30-
return botApi as BotApiShape
31-
})
35+
)

src/internal/botApiMethod.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Effect } from 'effect/Effect'
2-
import type { BotApiError } from '../BotApiError'
3-
import type { BotApiTransportError } from '../BotApiTransportError'
4-
import type { MethodParams, MethodResults } from './botApiMethods.gen'
2+
import type { BotApiError } from '../BotApiError.js'
3+
import type { BotApiTransportError } from '../BotApiTransportError.js'
4+
import type { MethodParams, MethodResults } from './botApiMethods.gen.js'
55

66
export interface BotApiMethod<M extends keyof MethodParams> {
77
(params: MethodParams[M]): Effect<

0 commit comments

Comments
 (0)