@mtkruto/node 0.60.0 → 0.61.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.
Files changed (111) hide show
  1. package/esm/2_tl.d.ts +4 -6
  2. package/esm/2_tl.d.ts.map +1 -1
  3. package/esm/2_tl.js +4 -6
  4. package/esm/client/0_storage_operations.d.ts.map +1 -1
  5. package/esm/client/0_storage_operations.js +9 -9
  6. package/esm/client/1_client_encrypted.d.ts.map +1 -1
  7. package/esm/client/1_client_encrypted.js +173 -126
  8. package/esm/client/1_client_plain.d.ts.map +1 -1
  9. package/esm/client/1_client_plain.js +12 -8
  10. package/esm/tl/0_api.d.ts +1 -2
  11. package/esm/tl/0_api.d.ts.map +1 -1
  12. package/esm/tl/0_api.js +7345 -6639
  13. package/esm/tl/0_tl_raw_reader.d.ts +2 -0
  14. package/esm/tl/0_tl_raw_reader.d.ts.map +1 -1
  15. package/esm/tl/0_tl_raw_reader.js +10 -0
  16. package/esm/tl/1_utilities.d.ts +10 -1
  17. package/esm/tl/1_utilities.d.ts.map +1 -1
  18. package/esm/tl/1_utilities.js +25 -1
  19. package/esm/tl/{5_message.d.ts → 2_message.d.ts} +5 -8
  20. package/esm/tl/2_message.d.ts.map +1 -0
  21. package/esm/tl/{5_message.js → 2_message.js} +16 -33
  22. package/esm/tl/{3_tl_reader.d.ts → 2_tl_reader.d.ts} +4 -3
  23. package/esm/tl/2_tl_reader.d.ts.map +1 -0
  24. package/esm/tl/2_tl_reader.js +146 -0
  25. package/esm/tl/2_tl_reader_test.d.ts.map +1 -0
  26. package/{script/tl/4_tl_writer.d.ts → esm/tl/2_tl_writer.d.ts} +4 -3
  27. package/esm/tl/2_tl_writer.d.ts.map +1 -0
  28. package/esm/tl/2_tl_writer.js +209 -0
  29. package/esm/tl/2_tl_writer_test.d.ts.map +1 -0
  30. package/{script/tl/3_utilities.d.ts → esm/tl/2_utilities.d.ts} +1 -1
  31. package/esm/tl/{3_utilities.d.ts.map → 2_utilities.d.ts.map} +1 -1
  32. package/esm/types/2_chosen_inline_result.d.ts.map +1 -1
  33. package/esm/types/2_chosen_inline_result.js +2 -2
  34. package/esm/types/5_callback_query.d.ts.map +1 -1
  35. package/esm/types/5_callback_query.js +3 -3
  36. package/esm/utilities/0_misc.d.ts +0 -1
  37. package/esm/utilities/0_misc.d.ts.map +1 -1
  38. package/esm/utilities/0_misc.js +0 -1
  39. package/package.json +1 -1
  40. package/script/2_tl.d.ts +4 -6
  41. package/script/2_tl.d.ts.map +1 -1
  42. package/script/2_tl.js +4 -6
  43. package/script/client/0_storage_operations.d.ts.map +1 -1
  44. package/script/client/0_storage_operations.js +8 -8
  45. package/script/client/1_client_encrypted.d.ts.map +1 -1
  46. package/script/client/1_client_encrypted.js +171 -124
  47. package/script/client/1_client_plain.d.ts.map +1 -1
  48. package/script/client/1_client_plain.js +11 -7
  49. package/script/tl/0_api.d.ts +1 -2
  50. package/script/tl/0_api.d.ts.map +1 -1
  51. package/script/tl/0_api.js +7346 -6640
  52. package/script/tl/0_tl_raw_reader.d.ts +2 -0
  53. package/script/tl/0_tl_raw_reader.d.ts.map +1 -1
  54. package/script/tl/0_tl_raw_reader.js +10 -0
  55. package/script/tl/1_utilities.d.ts +10 -1
  56. package/script/tl/1_utilities.d.ts.map +1 -1
  57. package/script/tl/1_utilities.js +29 -1
  58. package/script/tl/{5_message.d.ts → 2_message.d.ts} +5 -8
  59. package/script/tl/2_message.d.ts.map +1 -0
  60. package/script/tl/{5_message.js → 2_message.js} +17 -34
  61. package/script/tl/{3_tl_reader.d.ts → 2_tl_reader.d.ts} +4 -3
  62. package/script/tl/2_tl_reader.d.ts.map +1 -0
  63. package/script/tl/2_tl_reader.js +150 -0
  64. package/script/tl/2_tl_reader_test.d.ts.map +1 -0
  65. package/{esm/tl/4_tl_writer.d.ts → script/tl/2_tl_writer.d.ts} +4 -3
  66. package/script/tl/2_tl_writer.d.ts.map +1 -0
  67. package/script/tl/2_tl_writer.js +213 -0
  68. package/script/tl/2_tl_writer_test.d.ts.map +1 -0
  69. package/{esm/tl/3_utilities.d.ts → script/tl/2_utilities.d.ts} +1 -1
  70. package/script/tl/{3_utilities.d.ts.map → 2_utilities.d.ts.map} +1 -1
  71. package/script/types/2_chosen_inline_result.d.ts.map +1 -1
  72. package/script/types/2_chosen_inline_result.js +1 -1
  73. package/script/types/5_callback_query.d.ts.map +1 -1
  74. package/script/types/5_callback_query.js +2 -2
  75. package/script/utilities/0_misc.d.ts +0 -1
  76. package/script/utilities/0_misc.d.ts.map +1 -1
  77. package/script/utilities/0_misc.js +1 -2
  78. package/esm/tl/2_deserialize.d.ts +0 -23
  79. package/esm/tl/2_deserialize.d.ts.map +0 -1
  80. package/esm/tl/2_deserialize.js +0 -98
  81. package/esm/tl/2_serialize.d.ts +0 -22
  82. package/esm/tl/2_serialize.d.ts.map +0 -1
  83. package/esm/tl/2_serialize.js +0 -163
  84. package/esm/tl/2_serialize_test.d.ts.map +0 -1
  85. package/esm/tl/3_deserialize_test.d.ts.map +0 -1
  86. package/esm/tl/3_tl_reader.d.ts.map +0 -1
  87. package/esm/tl/3_tl_reader.js +0 -49
  88. package/esm/tl/4_rpc_result.d.ts +0 -27
  89. package/esm/tl/4_rpc_result.d.ts.map +0 -1
  90. package/esm/tl/4_rpc_result.js +0 -33
  91. package/esm/tl/4_tl_writer.d.ts.map +0 -1
  92. package/esm/tl/4_tl_writer.js +0 -45
  93. package/esm/tl/5_message.d.ts.map +0 -1
  94. package/script/tl/2_deserialize.d.ts +0 -23
  95. package/script/tl/2_deserialize.d.ts.map +0 -1
  96. package/script/tl/2_deserialize.js +0 -101
  97. package/script/tl/2_serialize.d.ts +0 -22
  98. package/script/tl/2_serialize.d.ts.map +0 -1
  99. package/script/tl/2_serialize.js +0 -166
  100. package/script/tl/2_serialize_test.d.ts.map +0 -1
  101. package/script/tl/3_deserialize_test.d.ts.map +0 -1
  102. package/script/tl/3_tl_reader.d.ts.map +0 -1
  103. package/script/tl/3_tl_reader.js +0 -53
  104. package/script/tl/4_rpc_result.d.ts +0 -27
  105. package/script/tl/4_rpc_result.d.ts.map +0 -1
  106. package/script/tl/4_rpc_result.js +0 -37
  107. package/script/tl/4_tl_writer.d.ts.map +0 -1
  108. package/script/tl/4_tl_writer.js +0 -49
  109. package/script/tl/5_message.d.ts.map +0 -1
  110. /package/esm/tl/{3_utilities.js → 2_utilities.js} +0 -0
  111. /package/script/tl/{3_utilities.js → 2_utilities.js} +0 -0
@@ -24,8 +24,10 @@ export declare class TLRawReader {
24
24
  constructor(_buffer: Uint8Array);
25
25
  get buffer(): Uint8Array;
26
26
  read(count: number): Uint8Array;
27
+ unread(count: number): void;
27
28
  readInt24(signed?: boolean): number;
28
29
  readInt32(signed?: boolean): number;
30
+ unreadInt32(): void;
29
31
  readInt64(signed?: boolean): bigint;
30
32
  readDouble(): number;
31
33
  readInt128(signed?: boolean): bigint;
@@ -1 +1 @@
1
- {"version":3,"file":"0_tl_raw_reader.d.ts","sourceRoot":"","sources":["../../src/tl/0_tl_raw_reader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,qBAAa,OAAQ,SAAQ,KAAK;CAEjC;AAED,qBAAa,WAAW;IACV,SAAS,CAAC,OAAO,EAAE,UAAU;gBAAnB,OAAO,EAAE,UAAU;IAGzC,IAAI,MAAM,IAAI,UAAU,CAEvB;IAED,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU;IAS/B,SAAS,CAAC,MAAM,UAAO,GAAG,MAAM;IAKhC,SAAS,CAAC,MAAM,UAAO,GAAG,MAAM;IAKhC,SAAS,CAAC,MAAM,UAAO,GAAG,MAAM;IAKhC,UAAU,IAAI,MAAM;IAKpB,UAAU,CAAC,MAAM,UAAO,GAAG,MAAM;IAKjC,UAAU,CAAC,MAAM,UAAO,GAAG,MAAM;IAKjC,SAAS,IAAI,UAAU;IAiBvB,UAAU,IAAI,MAAM;CAGrB"}
1
+ {"version":3,"file":"0_tl_raw_reader.d.ts","sourceRoot":"","sources":["../../src/tl/0_tl_raw_reader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,qBAAa,OAAQ,SAAQ,KAAK;CAEjC;AAED,qBAAa,WAAW;IACV,SAAS,CAAC,OAAO,EAAE,UAAU;gBAAnB,OAAO,EAAE,UAAU;IAGzC,IAAI,MAAM,IAAI,UAAU,CAEvB;IAED,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU;IAS/B,MAAM,CAAC,KAAK,EAAE,MAAM;IAQpB,SAAS,CAAC,MAAM,UAAO,GAAG,MAAM;IAKhC,SAAS,CAAC,MAAM,UAAO,GAAG,MAAM;IAKhC,WAAW;IAIX,SAAS,CAAC,MAAM,UAAO,GAAG,MAAM;IAKhC,UAAU,IAAI,MAAM;IAKpB,UAAU,CAAC,MAAM,UAAO,GAAG,MAAM;IAKjC,UAAU,CAAC,MAAM,UAAO,GAAG,MAAM;IAKjC,SAAS,IAAI,UAAU;IAiBvB,UAAU,IAAI,MAAM;CAGrB"}
@@ -44,6 +44,13 @@ class TLRawReader {
44
44
  this._buffer = this._buffer.subarray(count);
45
45
  return buffer;
46
46
  }
47
+ unread(count) {
48
+ const newOffest = this._buffer.byteOffset - count;
49
+ if (newOffest < 0) {
50
+ throw new TLError("No data has been read");
51
+ }
52
+ this._buffer = new Uint8Array(this._buffer.buffer, newOffest);
53
+ }
47
54
  readInt24(signed = true) {
48
55
  const buffer = this.read(24 / 8);
49
56
  return Number((0, _1_utilities_js_1.bigIntFromBuffer)(buffer, true, signed));
@@ -52,6 +59,9 @@ class TLRawReader {
52
59
  const buffer = this.read(32 / 8);
53
60
  return Number((0, _1_utilities_js_1.bigIntFromBuffer)(buffer, true, signed));
54
61
  }
62
+ unreadInt32() {
63
+ this.unread(32 / 8);
64
+ }
55
65
  readInt64(signed = true) {
56
66
  const buffer = this.read(64 / 8);
57
67
  return (0, _1_utilities_js_1.bigIntFromBuffer)(buffer, true, signed);
@@ -7,7 +7,7 @@
7
7
  * This program is free software: you can redistribute it and/or modify
8
8
  * it under the terms of the GNU Lesser General Public License as published by
9
9
  * the Free Software Foundation, either version 3 of the License, or
10
- * (at your option) any later version.
10
+ * (at your option) any later version.,,
11
11
  *
12
12
  * This program is distributed in the hope that it will be useful,
13
13
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -31,4 +31,13 @@ export declare function isOneOf<S extends keyof (Types & Functions)>(typeNames:
31
31
  export declare function isOfEnum<S extends keyof Enums>(enumName: S, value: unknown): value is Enums[S];
32
32
  export declare function as<S extends keyof Types>(typeName: S, value: unknown): Types[S];
33
33
  export declare function isGenericFunction(value: unknown): boolean;
34
+ export declare function mustGetReturnType(name: string): string;
35
+ export declare function repr(value: unknown): string | null;
36
+ export declare function getVectorItemType(type: string): string | null;
37
+ export declare const X = "X";
38
+ export declare const VECTOR = 481674261;
39
+ export declare const BOOL_TRUE = 2574415285;
40
+ export declare const BOOL_FALSE = 3162085175;
41
+ export declare const GZIP_PACKED = 812830625;
42
+ export declare const RPC_RESULT = 4082920705;
34
43
  //# sourceMappingURL=1_utilities.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"1_utilities.d.ts","sourceRoot":"","sources":["../../src/tl/1_utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAoB,KAAK,EAAE,MAAM,YAAY,CAAC;AAEhF,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEtD;AACD,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/D;AACD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAY3F;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,GAAG,GAAG,MAAM,IAAI,OAAO,CAE1D;AACD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,GAAG,QAI5C;AAED,wBAAgB,EAAE,CAAC,CAAC,SAAS,MAAM,CAAC,KAAK,GAAG,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,CAAC,SAAS,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK,CAMjL;AACD,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,CAAC,KAAK,GAAG,SAAS,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,CAAC,SAAS,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK,CAExM;AACD,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,KAAK,EAAE,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,CAE9F;AACD,wBAAgB,EAAE,CAAC,CAAC,SAAS,MAAM,KAAK,EAAE,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAM/E;AAWD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEzD"}
1
+ {"version":3,"file":"1_utilities.d.ts","sourceRoot":"","sources":["../../src/tl/1_utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAoB,KAAK,EAAE,MAAM,YAAY,CAAC;AAEhF,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEtD;AACD,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/D;AACD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAY3F;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,GAAG,GAAG,MAAM,IAAI,OAAO,CAE1D;AACD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,GAAG,QAI5C;AAED,wBAAgB,EAAE,CAAC,CAAC,SAAS,MAAM,CAAC,KAAK,GAAG,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,CAAC,SAAS,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK,CAMjL;AACD,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,CAAC,KAAK,GAAG,SAAS,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,CAAC,SAAS,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK,CAExM;AACD,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,KAAK,EAAE,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,CAE9F;AACD,wBAAgB,EAAE,CAAC,CAAC,SAAS,MAAM,KAAK,EAAE,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAM/E;AAWD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEzD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMtD;AAED,wBAAgB,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAElD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAK7D;AAID,eAAO,MAAM,CAAC,MAAM,CAAC;AACrB,eAAO,MAAM,MAAM,YAAa,CAAC;AACjC,eAAO,MAAM,SAAS,aAAa,CAAC;AACpC,eAAO,MAAM,UAAU,aAAa,CAAC;AACrC,eAAO,MAAM,WAAW,YAAa,CAAC;AACtC,eAAO,MAAM,UAAU,aAAa,CAAC"}
@@ -8,7 +8,7 @@
8
8
  * This program is free software: you can redistribute it and/or modify
9
9
  * it under the terms of the GNU Lesser General Public License as published by
10
10
  * the Free Software Foundation, either version 3 of the License, or
11
- * (at your option) any later version.
11
+ * (at your option) any later version.,,
12
12
  *
13
13
  * This program is distributed in the hope that it will be useful,
14
14
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -20,6 +20,7 @@
20
20
  */
21
21
  // deno-lint-ignore-file no-explicit-any
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.RPC_RESULT = exports.GZIP_PACKED = exports.BOOL_FALSE = exports.BOOL_TRUE = exports.VECTOR = exports.X = void 0;
23
24
  exports.isOptionalParam = isOptionalParam;
24
25
  exports.getOptionalParamInnerType = getOptionalParamInnerType;
25
26
  exports.analyzeOptionalParam = analyzeOptionalParam;
@@ -30,6 +31,9 @@ exports.isOneOf = isOneOf;
30
31
  exports.isOfEnum = isOfEnum;
31
32
  exports.as = as;
32
33
  exports.isGenericFunction = isGenericFunction;
34
+ exports.mustGetReturnType = mustGetReturnType;
35
+ exports.repr = repr;
36
+ exports.getVectorItemType = getVectorItemType;
33
37
  const _0_deps_js_1 = require("../0_deps.js");
34
38
  const _0_api_js_1 = require("./0_api.js");
35
39
  function isOptionalParam(ntype) {
@@ -90,3 +94,27 @@ const GENERIC_FUNCTIONS = [
90
94
  function isGenericFunction(value) {
91
95
  return isOneOf(GENERIC_FUNCTIONS, value);
92
96
  }
97
+ function mustGetReturnType(name) {
98
+ const type = (0, _0_api_js_1.getType)(name);
99
+ if (!type || type.length < 3 || !type[2]) {
100
+ (0, _0_deps_js_1.unreachable)();
101
+ }
102
+ return type[2];
103
+ }
104
+ function repr(value) {
105
+ return value == null ? null : (typeof value === "object" && "_" in value) ? value._ : value.constructor.name;
106
+ }
107
+ function getVectorItemType(type) {
108
+ if (!type.startsWith(VECTOR_PREFIX) || !type.endsWith(VECTOR_SUFFIX)) {
109
+ return null;
110
+ }
111
+ return type.slice(VECTOR_PREFIX.length).slice(0, -1 * VECTOR_SUFFIX.length);
112
+ }
113
+ const VECTOR_PREFIX = "Vector<";
114
+ const VECTOR_SUFFIX = ">";
115
+ exports.X = "X";
116
+ exports.VECTOR = 0x1CB5C415;
117
+ exports.BOOL_TRUE = 0x997275b5;
118
+ exports.BOOL_FALSE = 0xbc799737;
119
+ exports.GZIP_PACKED = 0x3072CFA1;
120
+ exports.RPC_RESULT = 0xF35C6D01;
@@ -17,23 +17,20 @@
17
17
  * You should have received a copy of the GNU Lesser General Public License
18
18
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
19
  */
20
- import { AnyObject } from "./0_api.js";
21
- import { TLReader } from "./3_tl_reader.js";
22
- import { rpc_result } from "./4_rpc_result.js";
23
- export declare const compressible: unique symbol;
20
+ import { TLRawReader } from "./0_tl_raw_reader.js";
24
21
  export interface message {
25
22
  _: "message";
26
23
  msg_id: bigint;
27
24
  seqno: number;
28
- body: AnyObject | msg_container | rpc_result;
25
+ body: Uint8Array | msg_container;
29
26
  }
30
27
  export declare function serializeMessage(message: message): Promise<Uint8Array>;
31
- export declare function deserializeMessage(reader: TLReader): Promise<message>;
28
+ export declare function deserializeMessage(reader: TLRawReader): Promise<message>;
32
29
  export interface msg_container {
33
30
  _: "msg_container";
34
31
  messages: message[];
35
32
  }
36
- export declare const MSG_CONTAINER_ID = 1945237724;
33
+ export declare const MSG_CONTAINER_CONSTRUCTOR = 1945237724;
37
34
  export declare function serializeMsgContainer(msgContainer: msg_container): Promise<Uint8Array>;
38
35
  export declare function deserializeMsgContainer(buffer: Uint8Array): Promise<msg_container>;
39
- //# sourceMappingURL=5_message.d.ts.map
36
+ //# sourceMappingURL=2_message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"2_message.d.ts","sourceRoot":"","sources":["../../src/tl/2_message.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAKnD,MAAM,WAAW,OAAO;IACtB,CAAC,EAAE,SAAS,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,UAAU,GAAG,aAAa,CAAC;CAClC;AAED,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAa5E;AAED,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAgB9E;AAID,MAAM,WAAW,aAAa;IAC5B,CAAC,EAAE,eAAe,CAAC;IACnB,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB;AAED,eAAO,MAAM,yBAAyB,aAAa,CAAC;AAEpD,wBAAsB,qBAAqB,CAAC,YAAY,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC,CAQ5F;AAED,wBAAsB,uBAAuB,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC,CAQxF"}
@@ -19,34 +19,22 @@
19
19
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20
20
  */
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.MSG_CONTAINER_ID = exports.compressible = void 0;
22
+ exports.MSG_CONTAINER_CONSTRUCTOR = void 0;
23
23
  exports.serializeMessage = serializeMessage;
24
24
  exports.deserializeMessage = deserializeMessage;
25
25
  exports.serializeMsgContainer = serializeMsgContainer;
26
26
  exports.deserializeMsgContainer = deserializeMsgContainer;
27
- const _1_utilities_js_1 = require("../1_utilities.js");
28
- const _1_utilities_js_2 = require("./1_utilities.js");
29
- const _3_tl_reader_js_1 = require("./3_tl_reader.js");
30
- const _4_rpc_result_js_1 = require("./4_rpc_result.js");
31
- const _4_tl_writer_js_1 = require("./4_tl_writer.js");
32
- const COMPRESSION_THREHSOLD = 1024;
33
- exports.compressible = Symbol.for("compressible");
27
+ const _0_tl_raw_reader_js_1 = require("./0_tl_raw_reader.js");
28
+ const _0_tl_raw_writer_js_1 = require("./0_tl_raw_writer.js");
34
29
  async function serializeMessage(message) {
35
- if (message.body._ == "rpc_result") {
36
- throw new Error("Not applicable");
37
- }
38
30
  let body;
39
- if (message.body._ == "msg_container") {
40
- body = await serializeMsgContainer(message.body);
31
+ if (message.body instanceof Uint8Array) {
32
+ body = message.body;
41
33
  }
42
34
  else {
43
- body = new _4_tl_writer_js_1.TLWriter().writeObject(message.body).buffer;
44
- }
45
- if (exports.compressible in message && body.length >= COMPRESSION_THREHSOLD) {
46
- const packed_data = await (0, _1_utilities_js_1.gzip)(body);
47
- body = new _4_tl_writer_js_1.TLWriter().writeObject({ _: "gzip_packed", packed_data }).buffer;
35
+ body = await serializeMsgContainer(message.body);
48
36
  }
49
- const writer = new _4_tl_writer_js_1.TLWriter()
37
+ const writer = new _0_tl_raw_writer_js_1.TLRawWriter()
50
38
  .writeInt64(message.msg_id)
51
39
  .writeInt32(message.seqno)
52
40
  .writeInt32(body.length)
@@ -57,29 +45,24 @@ async function deserializeMessage(reader) {
57
45
  const id_ = reader.readInt64();
58
46
  const seqno = reader.readInt32();
59
47
  const length = reader.readInt32();
60
- reader = new _3_tl_reader_js_1.TLReader(reader.read(length));
61
- const cid = reader.readInt32(false);
48
+ reader = new _0_tl_raw_reader_js_1.TLRawReader(reader.read(length));
49
+ const reader2 = new _0_tl_raw_reader_js_1.TLRawReader(reader.buffer);
50
+ const id = reader2.readInt32(false);
62
51
  let body;
63
52
  {
64
- if (cid == _4_rpc_result_js_1.RPC_RESULT_ID) {
65
- body = await (0, _4_rpc_result_js_1.deserializeRpcResult)(reader.buffer);
66
- }
67
- else if (cid == exports.MSG_CONTAINER_ID) {
68
- body = await deserializeMsgContainer(reader.buffer);
53
+ if (id == exports.MSG_CONTAINER_CONSTRUCTOR) {
54
+ body = await deserializeMsgContainer(reader2.buffer);
69
55
  }
70
56
  else {
71
- body = reader.readObject(cid);
57
+ body = reader.buffer;
72
58
  }
73
59
  }
74
- if ((0, _1_utilities_js_2.is)("gzip_packed", body)) {
75
- body = new _3_tl_reader_js_1.TLReader(await (0, _1_utilities_js_1.gunzip)(body.packed_data)).readObject();
76
- }
77
60
  return { _: "message", msg_id: id_, seqno, body };
78
61
  }
79
- exports.MSG_CONTAINER_ID = 0x73F1F8DC;
62
+ exports.MSG_CONTAINER_CONSTRUCTOR = 0x73F1F8DC;
80
63
  async function serializeMsgContainer(msgContainer) {
81
- const writer = new _4_tl_writer_js_1.TLWriter();
82
- writer.writeInt32(exports.MSG_CONTAINER_ID, false);
64
+ const writer = new _0_tl_raw_writer_js_1.TLRawWriter();
65
+ writer.writeInt32(exports.MSG_CONTAINER_CONSTRUCTOR, false);
83
66
  writer.writeInt32(msgContainer.messages.length);
84
67
  for (const message of msgContainer.messages) {
85
68
  writer.write(await serializeMessage(message));
@@ -87,7 +70,7 @@ async function serializeMsgContainer(msgContainer) {
87
70
  return writer.buffer;
88
71
  }
89
72
  async function deserializeMsgContainer(buffer) {
90
- const reader = new _3_tl_reader_js_1.TLReader(buffer);
73
+ const reader = new _0_tl_raw_reader_js_1.TLRawReader(buffer);
91
74
  const length = reader.readInt32();
92
75
  const messages = new Array();
93
76
  for (let i = 0; i < length; i++) {
@@ -19,8 +19,9 @@
19
19
  */
20
20
  import { TLRawReader } from "./0_tl_raw_reader.js";
21
21
  import { AnyObject } from "./0_api.js";
22
- export type ReadObject = boolean | AnyObject | Array<ReadObject>;
22
+ export type ReadObject = boolean | number | bigint | string | Uint8Array | AnyObject | Array<ReadObject>;
23
23
  export declare class TLReader extends TLRawReader {
24
- readObject(id?: number): ReadObject;
24
+ #private;
25
+ deserialize(type: string): Promise<ReadObject>;
25
26
  }
26
- //# sourceMappingURL=3_tl_reader.d.ts.map
27
+ //# sourceMappingURL=2_tl_reader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"2_tl_reader.d.ts","sourceRoot":"","sources":["../../src/tl/2_tl_reader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAW,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAoD,MAAM,YAAY,CAAC;AAKzF,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,SAAS,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;AAEzG,qBAAa,QAAS,SAAQ,WAAW;;IACjC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;CAqHrD"}
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ /**
3
+ * MTKruto - Cross-runtime JavaScript library for building Telegram clients
4
+ * Copyright (C) 2023-2025 Roj <https://roj.im/>
5
+ *
6
+ * This file is part of MTKruto.
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU Lesser General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public License
19
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
20
+ */
21
+ // deno-lint-ignore-file no-explicit-any
22
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
23
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
24
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
25
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
26
+ };
27
+ var _TLReader_instances, _TLReader_deserializeEnum, _TLReader_deserializeType, _TLReader_deserializeVector, _TLReader_deserializePrimitive;
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.TLReader = void 0;
30
+ const _0_tl_raw_reader_js_1 = require("./0_tl_raw_reader.js");
31
+ const _0_api_js_1 = require("./0_api.js");
32
+ const _0_deps_js_1 = require("../0_deps.js");
33
+ const _1_utilities_js_1 = require("../1_utilities.js");
34
+ const _1_utilities_js_2 = require("./1_utilities.js");
35
+ class TLReader extends _0_tl_raw_reader_js_1.TLRawReader {
36
+ constructor() {
37
+ super(...arguments);
38
+ _TLReader_instances.add(this);
39
+ }
40
+ async deserialize(type) {
41
+ if ((0, _1_utilities_js_2.isOptionalParam)(type)) {
42
+ type = (0, _1_utilities_js_2.getOptionalParamInnerType)(type);
43
+ }
44
+ const primitive = __classPrivateFieldGet(this, _TLReader_instances, "m", _TLReader_deserializePrimitive).call(this, type);
45
+ if (primitive !== undefined) {
46
+ return primitive;
47
+ }
48
+ const id = this.readInt32(false);
49
+ if (id == _1_utilities_js_2.GZIP_PACKED) {
50
+ const buffer = await (0, _1_utilities_js_1.gunzip)(this.readBytes());
51
+ return await new TLReader(buffer).deserialize(type);
52
+ }
53
+ if (type == _1_utilities_js_2.X) {
54
+ const typeName = (0, _0_api_js_1.getTypeName)(id);
55
+ if (!typeName) {
56
+ throw new _0_tl_raw_reader_js_1.TLError(`Unknown constructor: ${id.toString(16)}`);
57
+ }
58
+ this.unreadInt32();
59
+ return await this.deserialize(typeName);
60
+ }
61
+ if (id == _1_utilities_js_2.VECTOR) {
62
+ return await __classPrivateFieldGet(this, _TLReader_instances, "m", _TLReader_deserializeVector).call(this, type);
63
+ }
64
+ const enum_ = (0, _0_api_js_1.getEnum)(type);
65
+ if (enum_) {
66
+ return await __classPrivateFieldGet(this, _TLReader_instances, "m", _TLReader_deserializeEnum).call(this, enum_, id);
67
+ }
68
+ const type_ = (0, _0_api_js_1.getType)(type);
69
+ if (type_) {
70
+ return await __classPrivateFieldGet(this, _TLReader_instances, "m", _TLReader_deserializeType).call(this, type, type_, id);
71
+ }
72
+ (0, _0_deps_js_1.unreachable)(`unknown type: ${type} id ${id}`);
73
+ }
74
+ }
75
+ exports.TLReader = TLReader;
76
+ _TLReader_instances = new WeakSet(), _TLReader_deserializeEnum = async function _TLReader_deserializeEnum(enum_, id) {
77
+ const validTypes = enum_.map((v) => [v, (0, _0_api_js_1.getType)(v)]);
78
+ const type = validTypes.find((v) => v[1] && v[1][0] == id);
79
+ if (!type || !type[1]) {
80
+ throw new _0_tl_raw_reader_js_1.TLError(`Constructor not in enum: ${id.toString(16)}`);
81
+ }
82
+ return await __classPrivateFieldGet(this, _TLReader_instances, "m", _TLReader_deserializeType).call(this, type[0], type[1], id);
83
+ }, _TLReader_deserializeType = async function _TLReader_deserializeType(type, desc, id) {
84
+ if (desc[0] != id) {
85
+ throw new _0_tl_raw_reader_js_1.TLError(`Expected constructor ${desc[0].toString(16)} but got ${id}`);
86
+ }
87
+ const type_ = { _: type };
88
+ const flagFields = {};
89
+ for (const [name, type] of desc[1]) {
90
+ if ((0, _1_utilities_js_2.isOptionalParam)(type)) {
91
+ const { flagField, bitIndex } = (0, _1_utilities_js_2.analyzeOptionalParam)(type);
92
+ const bits = flagFields[flagField];
93
+ if ((bits & (1 << bitIndex)) == 0) {
94
+ continue;
95
+ }
96
+ }
97
+ if (type == "#") {
98
+ flagFields[name] = this.readInt32();
99
+ continue;
100
+ }
101
+ const value = await this.deserialize(type);
102
+ if (typeof value !== "boolean" || value) {
103
+ type_[name] = value;
104
+ }
105
+ }
106
+ return type_;
107
+ }, _TLReader_deserializeVector = async function _TLReader_deserializeVector(type) {
108
+ const itemType = (0, _1_utilities_js_2.getVectorItemType)(type);
109
+ if (!itemType) {
110
+ throw new _0_tl_raw_reader_js_1.TLError(`Expected Vector but received ${type}`);
111
+ }
112
+ const size = this.readInt32();
113
+ const array = new Array();
114
+ for (let i = 0; i < size; ++i) {
115
+ array.push(await this.deserialize(itemType));
116
+ }
117
+ return array;
118
+ }, _TLReader_deserializePrimitive = function _TLReader_deserializePrimitive(type) {
119
+ switch (type) {
120
+ case "bytes":
121
+ return this.readBytes();
122
+ case "int128":
123
+ return this.readInt128();
124
+ case "int256":
125
+ return this.readInt256();
126
+ case "double":
127
+ return this.readDouble();
128
+ case "long":
129
+ return this.readInt64();
130
+ case "true":
131
+ return true;
132
+ case "int":
133
+ return this.readInt32();
134
+ case "Bool": {
135
+ const id = this.readInt32(false);
136
+ if (id == _1_utilities_js_2.BOOL_TRUE) {
137
+ return true;
138
+ }
139
+ else if (id == _1_utilities_js_2.BOOL_FALSE) {
140
+ return false;
141
+ }
142
+ else {
143
+ (0, _0_deps_js_1.unreachable)(`expected boolTrue or boolFalse but got ${id}`);
144
+ }
145
+ break;
146
+ }
147
+ case "string":
148
+ return this.readString();
149
+ }
150
+ };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"2_tl_reader_test.d.ts","sourceRoot":"","sources":["../../src/tl/2_tl_reader_test.ts"],"names":[],"mappings":""}
@@ -17,9 +17,10 @@
17
17
  * You should have received a copy of the GNU Lesser General Public License
18
18
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
19
  */
20
+ import { AnyObject } from "./0_api.js";
20
21
  import { TLRawWriter } from "./0_tl_raw_writer.js";
21
- import { ReadObject } from "./3_tl_reader.js";
22
22
  export declare class TLWriter extends TLRawWriter {
23
- writeObject(object: ReadObject): typeof this;
23
+ #private;
24
+ serialize(value: AnyObject): typeof this;
24
25
  }
25
- //# sourceMappingURL=4_tl_writer.d.ts.map
26
+ //# sourceMappingURL=2_tl_writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"2_tl_writer.d.ts","sourceRoot":"","sources":["../../src/tl/2_tl_writer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,EAAE,SAAS,EAAoB,MAAM,YAAY,CAAC;AAEzD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD,qBAAa,QAAS,SAAQ,WAAW;;IACvC,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,IAAI;CAwLzC"}
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+ /**
3
+ * MTKruto - Cross-runtime JavaScript library for building Telegram clients
4
+ * Copyright (C) 2023-2025 Roj <https://roj.im/>
5
+ *
6
+ * This file is part of MTKruto.
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU Lesser General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public License
19
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
20
+ */
21
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
22
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
23
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
24
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
25
+ };
26
+ var _TLWriter_instances, _TLWriter_serialize, _TLWriter_serializeVector, _TLWriter_serializePrimitive, _TLWriter_isTypeValid;
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.TLWriter = void 0;
29
+ // deno-lint-ignore-file no-explicit-any
30
+ const _0_api_js_1 = require("./0_api.js");
31
+ const _0_tl_raw_reader_js_1 = require("./0_tl_raw_reader.js");
32
+ const _0_tl_raw_writer_js_1 = require("./0_tl_raw_writer.js");
33
+ const _1_utilities_js_1 = require("./1_utilities.js");
34
+ class TLWriter extends _0_tl_raw_writer_js_1.TLRawWriter {
35
+ constructor() {
36
+ super(...arguments);
37
+ _TLWriter_instances.add(this);
38
+ }
39
+ serialize(value) {
40
+ (0, _1_utilities_js_1.assertIsValidType)(value);
41
+ __classPrivateFieldGet(this, _TLWriter_instances, "m", _TLWriter_serialize).call(this, value._, value, "");
42
+ return this;
43
+ }
44
+ }
45
+ exports.TLWriter = TLWriter;
46
+ _TLWriter_instances = new WeakSet(), _TLWriter_serialize = function _TLWriter_serialize(type, value, debugInfo) {
47
+ if (__classPrivateFieldGet(this, _TLWriter_instances, "m", _TLWriter_serializePrimitive).call(this, type, value, debugInfo)) {
48
+ return;
49
+ }
50
+ if (__classPrivateFieldGet(this, _TLWriter_instances, "m", _TLWriter_serializeVector).call(this, type, value, debugInfo)) {
51
+ return;
52
+ }
53
+ (0, _1_utilities_js_1.assertIsValidType)(value);
54
+ const maybeParameters = (0, _0_api_js_1.getType)(value._);
55
+ if (!maybeParameters) {
56
+ throw new _0_tl_raw_reader_js_1.TLError(`Unknown type: ${value._}`);
57
+ }
58
+ if (type != "!X" && !__classPrivateFieldGet(this, _TLWriter_instances, "m", _TLWriter_isTypeValid).call(this, type, value)) {
59
+ throw new _0_tl_raw_reader_js_1.TLError(`Expected ${type} but got ${value._}`);
60
+ }
61
+ const type__ = value;
62
+ const [id, parameters_] = maybeParameters;
63
+ this.writeInt32(id, false);
64
+ for (const [i, [name, type]] of parameters_.entries()) {
65
+ if ((0, _1_utilities_js_1.isOptionalParam)(type) && type__[name] === undefined) {
66
+ continue;
67
+ }
68
+ const debugInfo = ` [0x${id.toString(16).toUpperCase()}::${i}]`;
69
+ if (type == "#") {
70
+ let flags = 0;
71
+ const flagField_ = name;
72
+ for (const [name, type] of parameters_) {
73
+ if ((0, _1_utilities_js_1.isOptionalParam)(type)) {
74
+ const { flagField, bitIndex } = (0, _1_utilities_js_1.analyzeOptionalParam)(type);
75
+ if (flagField == flagField_) {
76
+ if (type__[name] !== undefined) {
77
+ flags |= 1 << bitIndex;
78
+ }
79
+ }
80
+ }
81
+ }
82
+ this.writeInt32(flags);
83
+ continue;
84
+ }
85
+ if (type__[name] === undefined && !(0, _1_utilities_js_1.isOptionalParam)(type)) {
86
+ throw new Error(`Missing required parameter: ${name}`);
87
+ }
88
+ __classPrivateFieldGet(this, _TLWriter_instances, "m", _TLWriter_serialize).call(this, type, type__[name], debugInfo);
89
+ }
90
+ return;
91
+ }, _TLWriter_serializeVector = function _TLWriter_serializeVector(type, value, debugInfo) {
92
+ if ((0, _1_utilities_js_1.isOptionalParam)(type)) {
93
+ type = (0, _1_utilities_js_1.getOptionalParamInnerType)(type);
94
+ }
95
+ const itemType = (0, _1_utilities_js_1.getVectorItemType)(type);
96
+ if (!itemType) {
97
+ return false;
98
+ }
99
+ if (!Array.isArray(value)) {
100
+ throw new TypeError(`Expected array but received ${(0, _1_utilities_js_1.repr)(value)}${debugInfo}`);
101
+ }
102
+ this.writeInt32(_1_utilities_js_1.VECTOR, false);
103
+ this.writeInt32(value.length);
104
+ for (const item of value) {
105
+ __classPrivateFieldGet(this, _TLWriter_instances, "m", _TLWriter_serialize).call(this, itemType, item, debugInfo);
106
+ }
107
+ return true;
108
+ }, _TLWriter_serializePrimitive = function _TLWriter_serializePrimitive(type, value, debugInfo) {
109
+ if ((0, _1_utilities_js_1.isOptionalParam)(type)) {
110
+ type = (0, _1_utilities_js_1.getOptionalParamInnerType)(type);
111
+ }
112
+ const valueRepr = (0, _1_utilities_js_1.repr)(value);
113
+ switch (type) {
114
+ case "bytes":
115
+ if ((value instanceof Uint8Array)) {
116
+ this.writeBytes(value);
117
+ }
118
+ else {
119
+ throw new _0_tl_raw_reader_js_1.TLError(`Expected Uint8Array but received ${valueRepr}${debugInfo}`);
120
+ }
121
+ return true;
122
+ case "int128":
123
+ if (typeof value === "bigint") {
124
+ this.writeInt128(value);
125
+ }
126
+ else {
127
+ throw new _0_tl_raw_reader_js_1.TLError(`Expected bigint but received ${valueRepr}${debugInfo}`);
128
+ }
129
+ return true;
130
+ case "int256":
131
+ if (typeof value === "bigint") {
132
+ this.writeInt256(value);
133
+ }
134
+ else {
135
+ throw new _0_tl_raw_reader_js_1.TLError(`Expected bigint but received ${valueRepr}${debugInfo}`);
136
+ }
137
+ return true;
138
+ case "long":
139
+ if (typeof value === "bigint") {
140
+ this.writeInt64(value);
141
+ }
142
+ else {
143
+ throw new _0_tl_raw_reader_js_1.TLError(`Expected bigint but received ${valueRepr}${debugInfo}`);
144
+ }
145
+ return true;
146
+ case "Bool":
147
+ if (typeof value === "boolean") {
148
+ if (value) {
149
+ this.writeInt32(_1_utilities_js_1.BOOL_TRUE);
150
+ }
151
+ else {
152
+ this.writeInt32(_1_utilities_js_1.BOOL_FALSE);
153
+ }
154
+ }
155
+ else {
156
+ throw new _0_tl_raw_reader_js_1.TLError(`Expected boolean but received ${valueRepr}${debugInfo}`);
157
+ }
158
+ return true;
159
+ case "int":
160
+ //
161
+ if (value == null) {
162
+ value = 0;
163
+ }
164
+ //
165
+ if (typeof value === "number") {
166
+ this.writeInt32(value);
167
+ }
168
+ else {
169
+ throw new _0_tl_raw_reader_js_1.TLError(`Expected number but received ${valueRepr}${debugInfo}`);
170
+ }
171
+ return true;
172
+ case "double":
173
+ //
174
+ if (value == null) {
175
+ value = 0;
176
+ }
177
+ //
178
+ if (typeof value === "number") {
179
+ this.writeDouble(value);
180
+ }
181
+ else {
182
+ throw new _0_tl_raw_reader_js_1.TLError(`Expected number but received ${valueRepr}${debugInfo}`);
183
+ }
184
+ return true;
185
+ case "string":
186
+ if (typeof value === "string") {
187
+ this.writeString(value);
188
+ }
189
+ else if (value instanceof Uint8Array) {
190
+ this.writeBytes(value);
191
+ }
192
+ else {
193
+ this.writeString("");
194
+ }
195
+ // else {
196
+ // throw new TypeError(`Expected string or Uint8Array but received ${valueRepr}`);
197
+ // }
198
+ return true;
199
+ case "true":
200
+ if (value !== true) {
201
+ throw new _0_tl_raw_reader_js_1.TLError(`Expected true but received ${valueRepr}${debugInfo}`);
202
+ }
203
+ return true;
204
+ default:
205
+ return false;
206
+ }
207
+ }, _TLWriter_isTypeValid = function _TLWriter_isTypeValid(type, value) {
208
+ if (type == value._) {
209
+ return true;
210
+ }
211
+ const enum_ = (0, _0_api_js_1.getEnum)(type);
212
+ return enum_?.includes(value._) || false;
213
+ };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"2_tl_writer_test.d.ts","sourceRoot":"","sources":["../../src/tl/2_tl_writer_test.ts"],"names":[],"mappings":""}