@grom.js/bot-api-spec 0.5.0 → 0.6.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.
package/README.md CHANGED
@@ -1,21 +1,90 @@
1
- [Telegram Bot API](https://core.telegram.org/bots/api) specification as a collection of JavaScript objects in a [custom format](#format).
1
+ [![bot-api](https://img.shields.io/badge/v9.3-000?style=flat&logo=telegram&logoColor=%2325A3E1&label=Bot%20API&labelColor=%23000&color=%2325A3E1)][bot-api]
2
+ [![npm](https://img.shields.io/npm/v/%40grom.js%2Fbot-api-spec?style=flat&logo=npm&logoColor=%23BB443E&logoSize=auto&label=%C2%A0&labelColor=%23fff&color=%23BB443E)](https://www.npmjs.com/package/@grom.js/tgx)
3
+ [![jsr](https://img.shields.io/jsr/v/%40grom/bot-api-spec?style=flat&logo=jsr&logoColor=%231B3646&logoSize=auto&label=%C2%A0&labelColor=%23F3E051&color=%231B3646)](https://jsr.io/@grom/tgx)
4
+
5
+ [Telegram Bot API][bot-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: `types` and `methods`, containing definitions of all Bot API types and methods respectively.
24
+
9
25
  ```ts
10
- import { types, methods } from '@grom.js/bot-api-spec'
26
+ import { types, methods } from '@grom.js/bot-api-spec' // '@grom/bot-api-spec' for JSR
27
+
28
+ console.log(types)
29
+ // {
30
+ // Update: {
31
+ // name: 'Update',
32
+ // description: { markdown: '...' },
33
+ // fields: [
34
+ // {
35
+ // name: 'update_id',
36
+ // type: { type: 'int32' },
37
+ // description: { markdown: '...' },
38
+ // required: true,
39
+ // },
40
+ // ...
41
+ // ],
42
+ // },
43
+ // ...
44
+ // }
11
45
 
12
- console.log(types) // { Update: <definition of Update>, ... }
13
- console.log(methods) // { getUpdates: <definition of getUpdates>, ... }
46
+ console.log(methods)
47
+ // {
48
+ // getUpdates: {
49
+ // name: 'getUpdates',
50
+ // description: { markdown: '...' },
51
+ // parameters: [
52
+ // {
53
+ // name: 'offset',
54
+ // type: { type: 'int32' },
55
+ // description: { markdown: '...' },
56
+ // required: false,
57
+ // },
58
+ // ...
59
+ // ],
60
+ // returnType: {
61
+ // type: 'array',
62
+ // of: {
63
+ // type: 'api-type',
64
+ // name: 'Update',
65
+ // },
66
+ // },
67
+ // },
68
+ // ...
69
+ // }
14
70
  ```
15
71
 
16
72
  ## Format
17
73
 
18
- See [./src/types.ts](./src/types.ts)
74
+ Refer to the [./src/format.ts](./src/format.ts) module for reference.
75
+
76
+ You can also import types in your code:
77
+
78
+ ```ts
79
+ import type { ValueType } from '@grom.js/bot-api-spec/format' // '@grom/bot-api-spec/format' for JSR
80
+
81
+ function generateCode(valueType: ValueType): string {
82
+ if (valueType.type === 'str') {
83
+ return 'string'
84
+ }
85
+ // ...
86
+ }
87
+ ```
19
88
 
20
89
  ### Value Types
21
90
 
@@ -36,9 +105,13 @@ Below are the rules how we map type of a field/parameter to the `ValueType`:
36
105
 
37
106
  ### Descriptions
38
107
 
39
- Objects also include descriptions of the API types, methods, fields, and parameters, with the following remarks:
108
+ All definitions of types, methods, fields, and parameters include their descriptions.
109
+
110
+ Descriptions are copied verbatim from the official [Bot API documentation][bot-api], with the following modifications:
111
+
112
+ - Description HTML is parsed and converted to Markdown.
113
+ - The "_Optional._" prefix is omitted from field descriptions. Instead, the `required` property is set to `false` for such fields.
114
+ - "JSON-serialized..." portions are omitted from field/parameter descriptions.
115
+ - "...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
116
 
41
- - Description is an object with a single `markdown` property, a string containing the description in Markdown format with formatting (**bold**, _italic_, etc.) and links preserved.
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)).
117
+ [bot-api]: https://core.telegram.org/bots/api
@@ -6,7 +6,9 @@
6
6
  import type { ApiMethod } from './format.ts';
7
7
  /**
8
8
  * Definition of all Bot API methods as an object.
9
- * Properties are created in the same order as they appear in the docs.
9
+ *
10
+ * Properties are defined in the same order as they appear in the
11
+ * {@link https://core.telegram.org/bots/api Telegram Bot API documentation}.
10
12
  */
11
13
  export declare const methods: {
12
14
  getUpdates: ApiMethod;
@@ -1 +1 @@
1
- {"version":3,"file":"methods.gen.d.ts","sourceRoot":"","sources":["../src/methods.gen.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAklY5C;;;GAGG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmKnB,CAAA"}
1
+ {"version":3,"file":"methods.gen.d.ts","sourceRoot":"","sources":["../src/methods.gen.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAklY5C;;;;;GAKG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmKnB,CAAA"}
@@ -12211,7 +12211,9 @@ const getGameHighScores = {
12211
12211
  };
12212
12212
  /**
12213
12213
  * Definition of all Bot API methods as an object.
12214
- * Properties are created in the same order as they appear in the docs.
12214
+ *
12215
+ * Properties are defined in the same order as they appear in the
12216
+ * {@link https://core.telegram.org/bots/api Telegram Bot API documentation}.
12215
12217
  */
12216
12218
  export const methods = {
12217
12219
  getUpdates,