@grom.js/bot-api-spec 0.4.1 → 0.6.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 +85 -9
- package/dist/format.d.ts +149 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +2 -0
- package/dist/format.js.map +1 -0
- package/dist/index.d.ts +3 -601
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -21777
- package/dist/index.js.map +1 -0
- package/dist/methods.gen.d.ts +177 -0
- package/dist/methods.gen.d.ts.map +1 -0
- package/dist/methods.gen.js +12382 -0
- package/dist/methods.gen.js.map +1 -0
- package/dist/types.gen.d.ts +295 -0
- package/dist/types.gen.d.ts.map +1 -0
- package/dist/types.gen.js +19806 -0
- package/dist/types.gen.js.map +1 -0
- package/package.json +30 -21
- package/src/format.ts +188 -0
- package/src/index.ts +2 -0
- package/src/methods.gen.ts +12546 -0
- package/src/types.gen.ts +20089 -0
package/README.md
CHANGED
|
@@ -1,21 +1,93 @@
|
|
|
1
|
+
[][bot-api]
|
|
2
|
+
[](https://www.npmjs.com/package/@grom.js/tgx)
|
|
3
|
+
[](https://jsr.io/@grom/tgx)
|
|
4
|
+
|
|
1
5
|
[Telegram Bot API](https://core.telegram.org/bots/api) specification as a collection of JavaScript objects in a [custom format](#format).
|
|
2
6
|
|
|
3
7
|
## Motivation
|
|
4
8
|
|
|
5
9
|
Automatically generate tools, libraries, MCP servers, custom documentations, etc.
|
|
6
10
|
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
# Using npm
|
|
15
|
+
npm install @grom.js/bot-api-spec
|
|
16
|
+
|
|
17
|
+
# Using JSR
|
|
18
|
+
deno add jsr:@grom/bot-api-spec
|
|
19
|
+
```
|
|
20
|
+
|
|
7
21
|
## Usage
|
|
8
22
|
|
|
23
|
+
Root module exports two objects:
|
|
24
|
+
|
|
25
|
+
1. `types` — definition of all Bot API types
|
|
26
|
+
2. `methods` — definition of all Bot API methods
|
|
27
|
+
|
|
9
28
|
```ts
|
|
10
|
-
import { types, methods } from '@grom.js/bot-api-spec'
|
|
29
|
+
import { types, methods } from '@grom.js/bot-api-spec' // '@grom/bot-api-spec' for JSR
|
|
30
|
+
|
|
31
|
+
console.log(types)
|
|
32
|
+
// {
|
|
33
|
+
// Update: {
|
|
34
|
+
// name: 'Update',
|
|
35
|
+
// description: { markdown: '...' },
|
|
36
|
+
// fields: [
|
|
37
|
+
// {
|
|
38
|
+
// name: 'update_id',
|
|
39
|
+
// type: { type: 'int32' },
|
|
40
|
+
// description: { markdown: '...' },
|
|
41
|
+
// required: true,
|
|
42
|
+
// },
|
|
43
|
+
// ...
|
|
44
|
+
// ],
|
|
45
|
+
// },
|
|
46
|
+
// ...
|
|
47
|
+
// }
|
|
11
48
|
|
|
12
|
-
console.log(
|
|
13
|
-
|
|
49
|
+
console.log(methods)
|
|
50
|
+
// {
|
|
51
|
+
// getUpdates: {
|
|
52
|
+
// name: 'getUpdates',
|
|
53
|
+
// description: { markdown: '...' },
|
|
54
|
+
// parameters: [
|
|
55
|
+
// {
|
|
56
|
+
// name: 'offset',
|
|
57
|
+
// type: { type: 'int32' },
|
|
58
|
+
// description: { markdown: '...' },
|
|
59
|
+
// required: false,
|
|
60
|
+
// },
|
|
61
|
+
// ...
|
|
62
|
+
// ],
|
|
63
|
+
// returnType: {
|
|
64
|
+
// type: 'array',
|
|
65
|
+
// of: {
|
|
66
|
+
// type: 'api-type',
|
|
67
|
+
// name: 'Update',
|
|
68
|
+
// },
|
|
69
|
+
// },
|
|
70
|
+
// },
|
|
71
|
+
// ...
|
|
72
|
+
// }
|
|
14
73
|
```
|
|
15
74
|
|
|
16
75
|
## Format
|
|
17
76
|
|
|
18
|
-
|
|
77
|
+
Refer to the [./src/format.ts](./src/format.ts) module for reference.
|
|
78
|
+
|
|
79
|
+
You can also import types in your code:
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import type { ValueType } from '@grom.js/bot-api-spec/format' // '@grom/bot-api-spec/format' for JSR
|
|
83
|
+
|
|
84
|
+
function generateCode(valueType: ValueType): string {
|
|
85
|
+
if (valueType.type === 'str') {
|
|
86
|
+
return 'string'
|
|
87
|
+
}
|
|
88
|
+
// ...
|
|
89
|
+
}
|
|
90
|
+
```
|
|
19
91
|
|
|
20
92
|
### Value Types
|
|
21
93
|
|
|
@@ -36,9 +108,13 @@ Below are the rules how we map type of a field/parameter to the `ValueType`:
|
|
|
36
108
|
|
|
37
109
|
### Descriptions
|
|
38
110
|
|
|
39
|
-
|
|
111
|
+
All definitions of types, methods, fields, and parameters include their descriptions.
|
|
112
|
+
|
|
113
|
+
Descriptions are copied verbatim from the official [Bot API documentation][bot-api], with the following modifications:
|
|
114
|
+
|
|
115
|
+
- Description HTML is parsed and converted to Markdown.
|
|
116
|
+
- The "_Optional._" prefix is omitted from field descriptions. Instead, the `required` property is set to `false` for such fields.
|
|
117
|
+
- "JSON-serialized..." portions are omitted from field/parameter descriptions.
|
|
118
|
+
- "...may have more than 32 significant bits...but it has at most 52 significant bits..." portions are omitted from _Integer_ field/parameter descriptions. Instead, the `type` is set to `int53` for such fields/parameters (as per [TDLib](https://core.telegram.org/tdlib/docs/td__api_8h.html#a6f57ab89c6371535f0fb7fec2d770126)).
|
|
40
119
|
|
|
41
|
-
-
|
|
42
|
-
- "_Optional._" prefix in field descriptions is omitted; instead, the `required` property is set to `false` for such fields.
|
|
43
|
-
- "JSON-serialized..." in field/parameter descriptions is omitted; instead, the `jsonSerialized` property is set to `true` for such fields/parameters.
|
|
44
|
-
- "...may have more than 32 significant bits...but it has at most 52 significant bits..." in _Integer_ field/parameter descriptions is omitted; instead, `type` is set to `int53` for such fields/parameters (as per [TDLib](https://core.telegram.org/tdlib/docs/td__api_8h.html#a6f57ab89c6371535f0fb7fec2d770126)).
|
|
120
|
+
[bot-api]: https://core.telegram.org/bots/api
|
package/dist/format.d.ts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import type { types } from './types.gen.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Type defined in the API. It can either be an {@link ApiTypeObject object}
|
|
4
|
+
* or a {@link ApiTypeOneOf union}.
|
|
5
|
+
*/
|
|
6
|
+
export type ApiType = ApiTypeObject | ApiTypeOneOf;
|
|
7
|
+
export interface ApiTypeObject {
|
|
8
|
+
/**
|
|
9
|
+
* Name of the type.
|
|
10
|
+
*/
|
|
11
|
+
name: string;
|
|
12
|
+
/**
|
|
13
|
+
* Description of the type.
|
|
14
|
+
*/
|
|
15
|
+
description: Description;
|
|
16
|
+
/**
|
|
17
|
+
* Fields of the object representing this type.
|
|
18
|
+
*/
|
|
19
|
+
fields: Array<FieldOrParam>;
|
|
20
|
+
oneOf?: never;
|
|
21
|
+
}
|
|
22
|
+
export interface ApiTypeOneOf {
|
|
23
|
+
/**
|
|
24
|
+
* Name of the type.
|
|
25
|
+
*/
|
|
26
|
+
name: string;
|
|
27
|
+
/**
|
|
28
|
+
* Description of the type.
|
|
29
|
+
*/
|
|
30
|
+
description: Description;
|
|
31
|
+
/**
|
|
32
|
+
* Array of possible types this type can be.
|
|
33
|
+
*/
|
|
34
|
+
oneOf: Array<ValueTypeApiType>;
|
|
35
|
+
fields?: never;
|
|
36
|
+
}
|
|
37
|
+
export interface ApiMethod {
|
|
38
|
+
/**
|
|
39
|
+
* Name of the method.
|
|
40
|
+
*/
|
|
41
|
+
name: string;
|
|
42
|
+
/**
|
|
43
|
+
* Description of the method.
|
|
44
|
+
*/
|
|
45
|
+
description: Description;
|
|
46
|
+
/**
|
|
47
|
+
* Parameters this method takes.
|
|
48
|
+
*/
|
|
49
|
+
parameters: Array<FieldOrParam>;
|
|
50
|
+
/**
|
|
51
|
+
* Type of the value this method returns.
|
|
52
|
+
*/
|
|
53
|
+
returnType: ValueType;
|
|
54
|
+
}
|
|
55
|
+
export interface FieldOrParam {
|
|
56
|
+
/**
|
|
57
|
+
* Name of the field/parameter.
|
|
58
|
+
*/
|
|
59
|
+
name: string;
|
|
60
|
+
/**
|
|
61
|
+
* Type of the value this field/parameter can be assigned.
|
|
62
|
+
*/
|
|
63
|
+
type: ValueType;
|
|
64
|
+
/**
|
|
65
|
+
* Whether this is a required field/parameter.
|
|
66
|
+
*/
|
|
67
|
+
required: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Description of the field/parameter.
|
|
70
|
+
*/
|
|
71
|
+
description: Description;
|
|
72
|
+
/**
|
|
73
|
+
* Whether this field/parameter should be JSON-serialized.
|
|
74
|
+
*/
|
|
75
|
+
jsonSerialized: boolean;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Description of a type/method/field/parameter.
|
|
79
|
+
*/
|
|
80
|
+
export interface Description {
|
|
81
|
+
markdown: string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Type of a value.
|
|
85
|
+
*/
|
|
86
|
+
export type ValueType = ValueTypeString | ValueTypeBoolean | ValueTypeInteger32 | ValueTypeInteger53 | ValueTypeFloat | ValueTypeInputFile | ValueTypeApiType | ValueTypeArray | ValueTypeUnion;
|
|
87
|
+
/**
|
|
88
|
+
* `String` value type.
|
|
89
|
+
*/
|
|
90
|
+
export interface ValueTypeString {
|
|
91
|
+
type: 'str';
|
|
92
|
+
literal?: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* `Boolean` value type.
|
|
96
|
+
*/
|
|
97
|
+
export interface ValueTypeBoolean {
|
|
98
|
+
type: 'bool';
|
|
99
|
+
literal?: boolean;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* `Integer` value type, which fits in a 32-bit integer.
|
|
103
|
+
*/
|
|
104
|
+
export interface ValueTypeInteger32 {
|
|
105
|
+
type: 'int32';
|
|
106
|
+
literal?: number;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* `Integer` value type, which may have more than 32 significant bits, but has
|
|
110
|
+
* at most 52 significant bits, so a 64-bit integer or double-precision float
|
|
111
|
+
* type are safe for storing values of this type.
|
|
112
|
+
*/
|
|
113
|
+
export interface ValueTypeInteger53 {
|
|
114
|
+
type: 'int53';
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* `Float` value type.
|
|
118
|
+
*/
|
|
119
|
+
export interface ValueTypeFloat {
|
|
120
|
+
type: 'float';
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* [`InputFile`](https://core.telegram.org/bots/api#inputfile) value type.
|
|
124
|
+
*/
|
|
125
|
+
export interface ValueTypeInputFile {
|
|
126
|
+
type: 'input-file';
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Any {@link ApiType} value type.
|
|
130
|
+
*/
|
|
131
|
+
export interface ValueTypeApiType {
|
|
132
|
+
type: 'api-type';
|
|
133
|
+
name: keyof typeof types;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Array of any value type.
|
|
137
|
+
*/
|
|
138
|
+
export interface ValueTypeArray {
|
|
139
|
+
type: 'array';
|
|
140
|
+
of: ValueType;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Union of any value types.
|
|
144
|
+
*/
|
|
145
|
+
export interface ValueTypeUnion {
|
|
146
|
+
type: 'union';
|
|
147
|
+
types: Array<ValueType>;
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAE3C;;;GAGG;AACH,MAAM,MAAM,OAAO,GACb,aAAa,GACb,YAAY,CAAA;AAElB,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,WAAW,EAAE,WAAW,CAAA;IAExB;;OAEG;IACH,MAAM,EAAE,KAAK,CAAC,YAAY,CAAC,CAAA;IAE3B,KAA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AO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,OAAO,CAAA;CACd;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,OAAO,CAAA;CACd;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,YAAY,CAAA;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,UAAU,CAAA;IAChB,IAAI,EAAE,MAAM,OAAO,KAAK,CAAA;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,OAAO,CAAA;IACb,EAAE,EAAE,SAAS,CAAA;CACd;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,OAAO,CAAA;IACb,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC,CAAA;CACxB"}
|
package/dist/format.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":""}
|