@mrlegendbot/baileys 1.2.4 → 1.2.6

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 (214) hide show
  1. package/WAProto/GenerateStatics.sh +3 -0
  2. package/WAProto/fix-imports.js +85 -0
  3. package/WAProto/index.d.ts +14017 -0
  4. package/WAProto/index.js +97691 -2
  5. package/lib/Defaults/index.d.ts +75 -0
  6. package/lib/Defaults/index.js +92 -89
  7. package/lib/Menu/index.d.ts +42 -0
  8. package/lib/Menu/index.js +283 -0
  9. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  10. package/lib/Signal/Group/ciphertext-message.js +10 -9
  11. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  12. package/lib/Signal/Group/group-session-builder.js +22 -21
  13. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  14. package/lib/Signal/Group/group_cipher.js +69 -75
  15. package/lib/Signal/Group/index.d.ts +12 -0
  16. package/lib/Signal/Group/index.js +1 -0
  17. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  18. package/lib/Signal/Group/keyhelper.js +10 -9
  19. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  20. package/lib/Signal/Group/sender-chain-key.js +22 -21
  21. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  22. package/lib/Signal/Group/sender-key-distribution-message.js +60 -51
  23. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  24. package/lib/Signal/Group/sender-key-message.js +62 -56
  25. package/lib/Signal/Group/sender-key-name.d.ts +18 -0
  26. package/lib/Signal/Group/sender-key-name.js +40 -38
  27. package/lib/Signal/Group/sender-key-record.d.ts +31 -0
  28. package/lib/Signal/Group/sender-key-record.js +34 -33
  29. package/lib/Signal/Group/sender-key-state.d.ts +39 -0
  30. package/lib/Signal/Group/sender-key-state.js +76 -72
  31. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  32. package/lib/Signal/Group/sender-message-key.js +23 -22
  33. package/lib/Signal/libsignal.d.ts +5 -0
  34. package/lib/Signal/libsignal.js +405 -506
  35. package/lib/Signal/lid-mapping.d.ts +23 -0
  36. package/lib/Signal/lid-mapping.js +258 -276
  37. package/lib/Socket/Client/index.d.ts +3 -0
  38. package/lib/Socket/Client/index.js +1 -0
  39. package/lib/Socket/Client/types.d.ts +16 -0
  40. package/lib/Socket/Client/types.js +7 -6
  41. package/lib/Socket/Client/websocket.d.ts +13 -0
  42. package/lib/Socket/Client/websocket.js +49 -48
  43. package/lib/Socket/business.d.ts +217 -0
  44. package/lib/Socket/business.js +369 -349
  45. package/lib/Socket/chats.d.ts +125 -0
  46. package/lib/Socket/chats.js +1148 -1172
  47. package/lib/Socket/communities.d.ts +273 -0
  48. package/lib/Socket/communities.js +413 -473
  49. package/lib/Socket/groups.d.ts +161 -0
  50. package/lib/Socket/groups.js +331 -387
  51. package/lib/Socket/index.d.ts +267 -0
  52. package/lib/Socket/index.js +19 -6
  53. package/lib/Socket/messages-recv.d.ts +203 -0
  54. package/lib/Socket/messages-recv.js +1719 -1782
  55. package/lib/Socket/messages-send.d.ts +199 -0
  56. package/lib/Socket/messages-send.js +2451 -1504
  57. package/lib/Socket/mex.d.ts +3 -0
  58. package/lib/Socket/mex.js +35 -40
  59. package/lib/Socket/newsletter.d.ts +170 -0
  60. package/lib/Socket/newsletter.js +191 -239
  61. package/lib/Socket/socket.d.ts +59 -0
  62. package/lib/Socket/socket.js +923 -992
  63. package/lib/Types/Auth.d.ts +117 -0
  64. package/lib/Types/Auth.js +1 -0
  65. package/lib/Types/Bussines.d.ts +25 -0
  66. package/lib/Types/Bussines.js +1 -0
  67. package/lib/Types/Call.d.ts +15 -0
  68. package/lib/Types/Call.js +1 -0
  69. package/lib/Types/Chat.d.ts +124 -0
  70. package/lib/Types/Chat.js +8 -1
  71. package/lib/Types/Contact.d.ts +26 -0
  72. package/lib/Types/Contact.js +1 -0
  73. package/lib/Types/Events.d.ts +256 -0
  74. package/lib/Types/Events.js +2 -1
  75. package/lib/Types/GroupMetadata.d.ts +71 -0
  76. package/lib/Types/GroupMetadata.js +1 -0
  77. package/lib/Types/Label.d.ts +47 -0
  78. package/lib/Types/Label.js +22 -20
  79. package/lib/Types/LabelAssociation.d.ts +30 -0
  80. package/lib/Types/LabelAssociation.js +4 -2
  81. package/lib/Types/Message.d.ts +320 -0
  82. package/lib/Types/Message.js +5 -3
  83. package/lib/Types/Mex.d.ts +141 -0
  84. package/lib/Types/Mex.js +31 -26
  85. package/lib/Types/Product.d.ts +79 -0
  86. package/lib/Types/Product.js +1 -0
  87. package/lib/Types/Signal.d.ts +87 -0
  88. package/lib/Types/Signal.js +2 -1
  89. package/lib/Types/Socket.d.ts +136 -0
  90. package/lib/Types/Socket.js +3 -2
  91. package/lib/Types/State.d.ts +97 -0
  92. package/lib/Types/State.js +52 -4
  93. package/lib/Types/USync.d.ts +26 -0
  94. package/lib/Types/USync.js +1 -0
  95. package/lib/Types/index.d.ts +66 -0
  96. package/lib/Types/index.js +11 -10
  97. package/lib/Utils/auth-utils.d.ts +24 -0
  98. package/lib/Utils/auth-utils.js +277 -240
  99. package/lib/Utils/browser-utils.d.ts +4 -0
  100. package/lib/Utils/browser-utils.js +23 -20
  101. package/lib/Utils/business.d.ts +23 -0
  102. package/lib/Utils/business.js +204 -200
  103. package/lib/Utils/chat-utils.d.ts +100 -0
  104. package/lib/Utils/chat-utils.js +810 -836
  105. package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
  106. package/lib/Utils/companion-reg-client-utils.js +25 -23
  107. package/lib/Utils/crypto.d.ts +37 -0
  108. package/lib/Utils/crypto.js +86 -70
  109. package/lib/Utils/decode-wa-message.d.ts +66 -0
  110. package/lib/Utils/decode-wa-message.js +284 -277
  111. package/lib/Utils/event-buffer.d.ts +36 -0
  112. package/lib/Utils/event-buffer.js +595 -592
  113. package/lib/Utils/generics.d.ts +92 -0
  114. package/lib/Utils/generics.js +335 -312
  115. package/lib/Utils/history.d.ts +24 -0
  116. package/lib/Utils/history.js +115 -123
  117. package/lib/Utils/identity-change-handler.d.ts +44 -0
  118. package/lib/Utils/identity-change-handler.js +50 -0
  119. package/lib/Utils/index.d.ts +22 -0
  120. package/lib/Utils/index.js +2 -1
  121. package/lib/Utils/link-preview.d.ts +21 -0
  122. package/lib/Utils/link-preview.js +73 -74
  123. package/lib/Utils/logger.d.ts +12 -0
  124. package/lib/Utils/logger.js +2 -3
  125. package/lib/Utils/lt-hash.d.ts +8 -0
  126. package/lib/Utils/lt-hash.js +6 -0
  127. package/lib/Utils/make-mutex.d.ts +9 -0
  128. package/lib/Utils/make-mutex.js +27 -27
  129. package/lib/Utils/message-retry-manager.d.ts +115 -0
  130. package/lib/Utils/message-retry-manager.js +254 -213
  131. package/lib/Utils/messages-media.d.ts +133 -0
  132. package/lib/Utils/messages-media.js +715 -741
  133. package/lib/Utils/messages.d.ts +91 -0
  134. package/lib/Utils/messages.js +827 -791
  135. package/lib/Utils/noise-handler.d.ts +20 -0
  136. package/lib/Utils/noise-handler.js +187 -215
  137. package/lib/Utils/offline-node-processor.d.ts +17 -0
  138. package/lib/Utils/offline-node-processor.js +40 -0
  139. package/lib/Utils/pre-key-manager.d.ts +28 -0
  140. package/lib/Utils/pre-key-manager.js +98 -69
  141. package/lib/Utils/process-message.d.ts +60 -0
  142. package/lib/Utils/process-message.js +586 -617
  143. package/lib/Utils/reporting-utils.d.ts +11 -0
  144. package/lib/Utils/reporting-utils.js +234 -553
  145. package/lib/Utils/signal.d.ts +47 -0
  146. package/lib/Utils/signal.js +170 -217
  147. package/lib/Utils/stanza-ack.d.ts +11 -0
  148. package/lib/Utils/stanza-ack.js +35 -27
  149. package/lib/Utils/sync-action-utils.d.ts +19 -0
  150. package/lib/Utils/sync-action-utils.js +41 -37
  151. package/lib/Utils/tc-token-utils.d.ts +37 -0
  152. package/lib/Utils/tc-token-utils.js +141 -120
  153. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  154. package/lib/Utils/use-multi-file-auth-state.js +105 -87
  155. package/lib/Utils/validate-connection.d.ts +11 -0
  156. package/lib/Utils/validate-connection.js +188 -190
  157. package/lib/WABinary/constants.d.ts +28 -0
  158. package/lib/WABinary/constants.js +1294 -28
  159. package/lib/WABinary/decode.d.ts +7 -0
  160. package/lib/WABinary/decode.js +249 -245
  161. package/lib/WABinary/encode.d.ts +3 -0
  162. package/lib/WABinary/encode.js +206 -201
  163. package/lib/WABinary/generic-utils.d.ts +15 -0
  164. package/lib/WABinary/generic-utils.js +89 -86
  165. package/lib/WABinary/index.d.ts +6 -0
  166. package/lib/WABinary/index.js +1 -0
  167. package/lib/WABinary/jid-utils.d.ts +48 -0
  168. package/lib/WABinary/jid-utils.js +77 -68
  169. package/lib/WABinary/types.d.ts +19 -0
  170. package/lib/WABinary/types.js +1 -0
  171. package/lib/WAM/BinaryInfo.d.ts +9 -0
  172. package/lib/WAM/BinaryInfo.js +8 -7
  173. package/lib/WAM/constants.d.ts +40 -0
  174. package/lib/WAM/constants.js +22853 -19892
  175. package/lib/WAM/encode.d.ts +3 -0
  176. package/lib/WAM/encode.js +132 -121
  177. package/lib/WAM/index.d.ts +4 -0
  178. package/lib/WAM/index.js +1 -0
  179. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  180. package/lib/WAUSync/Protocols/USyncContactProtocol.js +43 -46
  181. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  182. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +48 -47
  183. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  184. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +23 -22
  185. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  186. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +33 -30
  187. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
  188. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +20 -19
  189. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  190. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +44 -53
  191. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  192. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -24
  193. package/lib/WAUSync/Protocols/index.d.ts +6 -0
  194. package/lib/WAUSync/Protocols/index.js +1 -0
  195. package/lib/WAUSync/USyncQuery.d.ts +30 -0
  196. package/lib/WAUSync/USyncQuery.js +88 -79
  197. package/lib/WAUSync/USyncUser.d.ts +17 -0
  198. package/lib/WAUSync/USyncUser.js +29 -28
  199. package/lib/WAUSync/index.d.ts +4 -0
  200. package/lib/WAUSync/index.js +1 -0
  201. package/lib/index.d.ts +12 -0
  202. package/lib/index.js +2 -2
  203. package/package.json +86 -22
  204. package/README.upstream.md +0 -1312
  205. package/WAProto/WAProto.json +0 -1
  206. package/WAProto/WAProto.proto +0 -6275
  207. package/WAProto/compiler.js +0 -550
  208. package/lib/Store/index.js +0 -8
  209. package/lib/Store/keyed-db.js +0 -108
  210. package/lib/Store/make-cache-manager-store.js +0 -70
  211. package/lib/Store/make-in-memory-store.js +0 -417
  212. package/lib/Store/make-ordered-dictionary.js +0 -69
  213. package/lib/Store/object-repository.js +0 -27
  214. package/lib/Utils/use-sqlite-auth-state.js +0 -162
@@ -1,550 +0,0 @@
1
- import { readFileSync, writeFileSync } from 'fs';
2
- import { fileURLToPath } from 'url';
3
- import Long from 'long';
4
- const MAXV = 0x1fffffffffffff;
5
- const isLongIn = v => v && typeof v === 'object' && 'low' in v && 'high' in v;
6
- const longToBig = v => (v.unsigned ? BigInt(v.high >>> 0) : BigInt(v.high | 0)) * 4294967296n + BigInt(v.low >>> 0);
7
- const toBig = v => typeof v === 'bigint' ? v : isLongIn(v) ? longToBig(v) : BigInt(Math.trunc(Number(v)));
8
- class Writer {
9
- constructor() {
10
- this.buf = new Uint8Array(128);
11
- this.len = 0;
12
- }
13
- _e(n) {
14
- if (this.len + n > this.buf.length) {
15
- let c = this.buf.length * 2;
16
- while (c < this.len + n) c *= 2;
17
- const nb = new Uint8Array(c);
18
- nb.set(this.buf.subarray(0, this.len));
19
- this.buf = nb;
20
- }
21
- }
22
- byte(b) {
23
- this._e(1);
24
- this.buf[this.len++] = b;
25
- }
26
- raw(u) {
27
- this._e(u.length);
28
- this.buf.set(u, this.len);
29
- this.len += u.length;
30
- }
31
- varintNum(n) {
32
- this._e(10);
33
- while (n > 0x7f) {
34
- this.buf[this.len++] = n & 0x7f | 0x80;
35
- n = Math.floor(n / 128);
36
- }
37
- this.buf[this.len++] = n;
38
- }
39
- varintBig(v) {
40
- this._e(10);
41
- let n = BigInt.asUintN(64, v);
42
- while (n > 0x7fn) {
43
- this.buf[this.len++] = Number(n & 0x7fn | 0x80n);
44
- n >>= 7n;
45
- }
46
- this.buf[this.len++] = Number(n);
47
- }
48
- tag(field, wire) {
49
- this.varintNum(field * 8 + wire);
50
- }
51
- vint(v) {
52
- if (typeof v === 'number' && v >= 0 && v <= MAXV && Number.isInteger(v)) this.varintNum(v);else this.varintBig(toBig(v));
53
- }
54
- fixed32(v) {
55
- this._e(4);
56
- const n = Number(BigInt.asUintN(32, toBig(v))) >>> 0;
57
- this.buf[this.len++] = n & 255;
58
- this.buf[this.len++] = n >>> 8 & 255;
59
- this.buf[this.len++] = n >>> 16 & 255;
60
- this.buf[this.len++] = n >>> 24 & 255;
61
- }
62
- fixed64(v) {
63
- this._e(8);
64
- const b = Buffer.alloc(8);
65
- b.writeBigUInt64LE(BigInt.asUintN(64, toBig(v)));
66
- this.raw(b);
67
- }
68
- float(v) {
69
- this._e(4);
70
- const b = Buffer.alloc(4);
71
- b.writeFloatLE(v);
72
- this.raw(b);
73
- }
74
- double(v) {
75
- this._e(8);
76
- const b = Buffer.alloc(8);
77
- b.writeDoubleLE(v);
78
- this.raw(b);
79
- }
80
- finish() {
81
- return this.buf.subarray(0, this.len);
82
- }
83
- }
84
- const zigzag = v => BigInt.asUintN(64, toBig(v) << 1n ^ toBig(v) >> 63n);
85
- const toBuf = v => Buffer.isBuffer(v) ? v : typeof v === 'string' ? Buffer.from(v, 'base64') : v?.type === 'Buffer' ? Buffer.from(v.data) : v instanceof Uint8Array ? Buffer.from(v) : Buffer.from(v);
86
- const wireOf = f => f.k === 'varint' ? 0 : f.k === 'i64' ? 1 : f.k === 'i32' ? 5 : 2;
87
- class Reader {
88
- constructor(buf) {
89
- this.buf = buf;
90
- this.p = 0;
91
- this.len = buf.length;
92
- }
93
- varint() {
94
- const buf = this.buf;
95
- const start = this.p;
96
- let r = 0,
97
- mult = 1,
98
- b,
99
- n = 0;
100
- do {
101
- b = buf[this.p++];
102
- r += (b & 0x7f) * mult;
103
- mult *= 128;
104
- n++;
105
- } while (b & 0x80);
106
- if (n > 7) {
107
- this.p = start;
108
- return this.varintBig();
109
- }
110
- return r;
111
- }
112
- varintBig() {
113
- const buf = this.buf;
114
- let r = 0n,
115
- s = 0n,
116
- b;
117
- do {
118
- b = buf[this.p++];
119
- r |= BigInt(b & 0x7f) << s;
120
- s += 7n;
121
- } while (b & 0x80);
122
- return r;
123
- }
124
- skipVarint() {
125
- const buf = this.buf;
126
- while (buf[this.p++] & 0x80) {}
127
- }
128
- u32() {
129
- const buf = this.buf,
130
- p = this.p;
131
- this.p += 4;
132
- return (buf[p] | buf[p + 1] << 8 | buf[p + 2] << 16 | buf[p + 3] << 24) >>> 0;
133
- }
134
- }
135
- const numOrBig = b => b <= 9007199254740991n && b >= -9007199254740991n ? Number(b) : b;
136
- const B64JSON = function () {
137
- return this.toString('base64');
138
- };
139
- function makeCodec(TABLE, opts = {}) {
140
- const Long = opts.Long;
141
- const tagBytes = opts.bytesJSON ? b => (Object.defineProperty(b, 'toJSON', {
142
- value: B64JSON,
143
- enumerable: false,
144
- configurable: true
145
- }), b) : b => b;
146
- const toLong = big => Long ? Long.fromString(BigInt.asIntN(64, big).toString()) : numOrBig(BigInt.asIntN(64, big));
147
- function writeScalar(w, f, v) {
148
- switch (f.k) {
149
- case 'varint':
150
- if (f.s === 'bool') w.byte(v ? 1 : 0);else if (f.s === 'zigzag' || f.s === 'zigzaglong') w.varintBig(zigzag(v));else w.vint(v);
151
- break;
152
- case 'i64':
153
- f.s === 'double' ? w.double(v) : w.fixed64(v);
154
- break;
155
- case 'i32':
156
- f.s === 'float' ? w.float(v) : w.fixed32(v);
157
- break;
158
- case 'string':
159
- {
160
- const b = Buffer.from(String(v), 'utf8');
161
- w.varintNum(b.length);
162
- w.raw(b);
163
- break;
164
- }
165
- case 'bytes':
166
- {
167
- const b = toBuf(v);
168
- w.varintNum(b.length);
169
- w.raw(b);
170
- break;
171
- }
172
- case 'msg':
173
- {
174
- const s = new Writer();
175
- encodeInto(s, TABLE[f.msg], v);
176
- const b = s.finish();
177
- w.varintNum(b.length);
178
- w.raw(b);
179
- break;
180
- }
181
- }
182
- }
183
- function encodeInto(w, T, obj) {
184
- if (!T) throw new Error('unknown message in table');
185
- const order = T.order;
186
- for (let i = 0; i < order.length; i++) {
187
- const f = order[i];
188
- let v = obj[f.name];
189
- if (v == null) continue;
190
- if (f.k === 'varint' && f.s === 'enum') {
191
- const re = x => {
192
- if (typeof x !== 'string') return x;
193
- const n = f.enumMap && x in f.enumMap ? f.enumMap[x] : Number(x);
194
- return Number.isFinite(n) ? n : undefined;
195
- };
196
- if (f.rep) {
197
- v = (Array.isArray(v) ? v : [v]).map(re).filter(x => x !== undefined);
198
- if (!v.length) continue;
199
- } else {
200
- v = re(v);
201
- if (v === undefined) continue;
202
- }
203
- }
204
- if (f.rep) {
205
- if (!Array.isArray(v)) v = [v];
206
- if (f.packed && (f.k === 'varint' || f.k === 'i64' || f.k === 'i32')) {
207
- const s = new Writer();
208
- for (let j = 0; j < v.length; j++) writeScalar(s, f, v[j]);
209
- const b = s.finish();
210
- w.tag(f.id, 2);
211
- w.varintNum(b.length);
212
- w.raw(b);
213
- } else {
214
- const wt = wireOf(f);
215
- for (let j = 0; j < v.length; j++) {
216
- w.tag(f.id, wt);
217
- writeScalar(w, f, v[j]);
218
- }
219
- }
220
- } else {
221
- w.tag(f.id, wireOf(f));
222
- writeScalar(w, f, v);
223
- }
224
- }
225
- }
226
- function encode(msgName, obj) {
227
- const w = new Writer();
228
- encodeInto(w, TABLE[msgName], obj);
229
- return w.finish();
230
- }
231
- function readScalar(r, f) {
232
- switch (f.k) {
233
- case 'varint':
234
- {
235
- if (f.s === 'bool') return !!r.varint();
236
- if (f.s === 'zigzag') {
237
- const u = r.varintBig();
238
- return numOrBig(u >> 1n ^ -(u & 1n));
239
- }
240
- if (f.s === 'zigzaglong') {
241
- const u = r.varintBig();
242
- return toLong(u >> 1n ^ -(u & 1n));
243
- }
244
- if (f.s === 'enum') {
245
- const v = r.varint();
246
- return typeof v === 'bigint' ? Number(BigInt.asIntN(32, v)) : v | 0;
247
- }
248
- if (f.s === 'long') {
249
- const v = r.varint();
250
- return toLong(typeof v === 'bigint' ? v : BigInt(v));
251
- }
252
- const v = r.varint();
253
- return typeof v === 'bigint' ? numOrBig(BigInt.asIntN(64, v)) : v;
254
- }
255
- case 'i64':
256
- {
257
- const b = Buffer.from(r.buf.buffer, r.buf.byteOffset + r.p, 8);
258
- r.p += 8;
259
- return f.s === 'double' ? b.readDoubleLE(0) : toLong(b.readBigUInt64LE(0));
260
- }
261
- case 'i32':
262
- {
263
- if (f.s === 'float') {
264
- const b = Buffer.from(r.buf.buffer, r.buf.byteOffset + r.p, 4);
265
- r.p += 4;
266
- return b.readFloatLE(0);
267
- }
268
- return r.u32();
269
- }
270
- case 'string':
271
- {
272
- const len = r.varint();
273
- const s = Buffer.from(r.buf.buffer, r.buf.byteOffset + r.p, len).toString('utf8');
274
- r.p += len;
275
- return s;
276
- }
277
- case 'bytes':
278
- {
279
- const len = r.varint();
280
- const b = tagBytes(Buffer.from(r.buf.subarray(r.p, r.p + len)));
281
- r.p += len;
282
- return b;
283
- }
284
- case 'msg':
285
- {
286
- const len = r.varint();
287
- const sub = r.buf.subarray(r.p, r.p + len);
288
- r.p += len;
289
- return decode(f.msg, sub);
290
- }
291
- }
292
- }
293
- function decode(msgName, buf) {
294
- const T = TABLE[msgName];
295
- if (!T) throw new Error('unknown message: ' + msgName);
296
- const byId = T.byId;
297
- const obj = {};
298
- const r = new Reader(buf);
299
- while (r.p < r.len) {
300
- const tag = r.varint();
301
- const id = tag >>> 3;
302
- const wire = tag & 7;
303
- const f = byId[id];
304
- if (!f) {
305
- skip(r, wire);
306
- continue;
307
- }
308
- if (f.rep && wire === 2 && (f.k === 'varint' || f.k === 'i64' || f.k === 'i32')) {
309
- const len = r.varint();
310
- const end = r.p + len;
311
- const arr = obj[f.name] || (obj[f.name] = []);
312
- while (r.p < end) arr.push(readScalar(r, f));
313
- } else {
314
- const val = readScalar(r, f);
315
- if (f.rep) (obj[f.name] || (obj[f.name] = [])).push(val);else obj[f.name] = val;
316
- }
317
- }
318
- return obj;
319
- }
320
- function skip(r, wire) {
321
- if (wire === 0) r.skipVarint();else if (wire === 2) {
322
- const len = r.varint();
323
- r.p += len;
324
- } else if (wire === 1) r.p += 8;else if (wire === 5) r.p += 4;
325
- }
326
- return {
327
- encode,
328
- decode
329
- };
330
- }
331
- const KIND = [{
332
- k: 'varint',
333
- s: 'int'
334
- }, {
335
- k: 'varint',
336
- s: 'zigzag'
337
- }, {
338
- k: 'varint',
339
- s: 'bool'
340
- }, {
341
- k: 'i64',
342
- s: 'long'
343
- }, {
344
- k: 'i64',
345
- s: 'double'
346
- }, {
347
- k: 'i32',
348
- s: 'int'
349
- }, {
350
- k: 'i32',
351
- s: 'float'
352
- }, {
353
- k: 'string'
354
- }, {
355
- k: 'bytes'
356
- }, {
357
- k: 'varint',
358
- s: 'enum'
359
- }, {
360
- k: 'varint',
361
- s: 'long'
362
- }, {
363
- k: 'varint',
364
- s: 'zigzaglong'
365
- }];
366
- function makeProto(tablePath) {
367
- const {
368
- m,
369
- t,
370
- e
371
- } = JSON.parse(readFileSync(tablePath, 'utf8'));
372
- const TABLE = {};
373
- for (const [full, fields] of Object.entries(t)) {
374
- const order = fields.map(([name, id, tc, flags = 0, enumName]) => {
375
- const base = tc >= 100 ? {
376
- k: 'msg',
377
- msg: m[tc - 100]
378
- } : KIND[tc];
379
- const f = {
380
- name,
381
- id,
382
- ...base,
383
- rep: !!(flags & 1),
384
- packed: !!(flags & 2)
385
- };
386
- if (tc === 9 && enumName && e[enumName]) f.enumMap = e[enumName];
387
- return f;
388
- });
389
- const byId = {};
390
- for (const f of order) byId[f.id] = f;
391
- TABLE[full] = {
392
- order,
393
- byId
394
- };
395
- }
396
- const codec = makeCodec(TABLE, {
397
- Long,
398
- bytesJSON: true
399
- });
400
- const proto = {};
401
- const nodeFor = path => {
402
- let c = proto;
403
- for (const p of path) c = c[p] || (c[p] = {});
404
- return c;
405
- };
406
- for (const full of Object.keys(t)) {
407
- const node = nodeFor(full.replace(/^proto\./, '').split('.'));
408
- node.encode = o => ({
409
- finish: () => codec.encode(full, o || {})
410
- });
411
- node.decode = b => codec.decode(full, b);
412
- node.create = o => o || {};
413
- node.fromObject = o => o || {};
414
- node.toObject = o => o || {};
415
- node.verify = () => null;
416
- node.name = full.split('.').pop();
417
- }
418
- for (const [full, values] of Object.entries(e)) {
419
- const node = nodeFor(full.replace(/^proto\./, '').split('.'));
420
- for (const [k, v] of Object.entries(values)) {
421
- node[k] = v;
422
- node[v] = k;
423
- }
424
- }
425
- return {
426
- proto,
427
- codec
428
- };
429
- }
430
- const MODS = {
431
- types: {},
432
- fields: {
433
- 'proto.SyncActionValue.AgentAction': {
434
- deviceID: {
435
- type: 'int32',
436
- id: 2
437
- }
438
- },
439
- 'proto.SyncActionValue.ChatAssignmentAction': {
440
- deviceAgentID: {
441
- type: 'string',
442
- id: 1
443
- }
444
- },
445
- 'proto.SyncActionValue.StatusPrivacyAction': {
446
- shareToFB: {
447
- type: 'bool',
448
- id: 3
449
- },
450
- shareToIG: {
451
- type: 'bool',
452
- id: 4
453
- }
454
- }
455
- }
456
- };
457
- export async function generateTable(protoPath, outPath) {
458
- const pb = await import('protobufjs');
459
- const protobuf = pb.default || pb;
460
- const root = await protobuf.load(protoPath);
461
- for (const [parent, types] of Object.entries(MODS.types || {})) {
462
- const P = root.lookupType(parent);
463
- for (const [name, def] of Object.entries(types)) {
464
- if (P.get(name)) continue;
465
- P.add(protobuf.Type.fromJSON(name, def));
466
- }
467
- }
468
- for (const [typeName, fields] of Object.entries(MODS.fields || {})) {
469
- const T = root.lookupType(typeName);
470
- for (const [fname, f] of Object.entries(fields)) {
471
- if (T.get(fname)) continue;
472
- if (T.fieldsArray.find(x => x.id === f.id)) continue;
473
- T.add(new protobuf.Field(fname, f.id, f.type, f.rule));
474
- }
475
- }
476
- root.resolveAll();
477
- const SCALAR = {
478
- int32: 0,
479
- uint32: 0,
480
- sint32: 1,
481
- bool: 2,
482
- fixed64: 3,
483
- sfixed64: 3,
484
- double: 4,
485
- fixed32: 5,
486
- sfixed32: 5,
487
- float: 6,
488
- string: 7,
489
- bytes: 8,
490
- int64: 10,
491
- uint64: 10,
492
- sint64: 11
493
- };
494
- const msgNames = [];
495
- const idx = n => {
496
- let i = msgNames.indexOf(n);
497
- return i < 0 ? msgNames.push(n) - 1 : i;
498
- };
499
- const t = {},
500
- enums = {};
501
- (function build(ns) {
502
- for (const o of Object.values(ns.nested || {})) {
503
- if (o.values) enums[o.fullName.replace(/^\./, '')] = o.values;
504
- if (o.fieldsArray) {
505
- const full = o.fullName.replace(/^\./, '');
506
- const fs2 = [];
507
- for (const f of o.fieldsArray) {
508
- if (f.map) continue;
509
- const rt = f.resolvedType;
510
- let tc, enumName;
511
- if (rt && rt.fieldsArray !== undefined && rt.values === undefined) tc = 100 + idx(rt.fullName.replace(/^\./, ''));else if (rt && rt.values) {
512
- tc = 9;
513
- enumName = rt.fullName.replace(/^\./, '');
514
- } else tc = SCALAR[f.type];
515
- const numeric = tc < 100 && tc !== 7 && tc !== 8;
516
- const flags = (f.repeated ? 1 : 0) | (f.repeated && numeric && f.packed !== false ? 2 : 0);
517
- if (tc === 9) fs2.push([f.name, f.id, 9, flags, enumName]);else if (flags) fs2.push([f.name, f.id, tc, flags]);else fs2.push([f.name, f.id, tc]);
518
- }
519
- fs2.sort((a, b) => a[1] - b[1]);
520
- t[full] = fs2;
521
- }
522
- if (o.nested) build(o);
523
- }
524
- })(root);
525
- writeFileSync(outPath, JSON.stringify({
526
- m: msgNames,
527
- t,
528
- e: enums
529
- }));
530
- return {
531
- types: Object.keys(t).length,
532
- enums: Object.keys(enums).length
533
- };
534
- }
535
- if (process.argv[1] && (process.argv[1] === fileURLToPath(import.meta.url) || process.argv.includes('--generate'))) {
536
- const protoPath = fileURLToPath(new URL('./WAProto.proto', import.meta.url));
537
- const outPath = fileURLToPath(new URL('./WAProto.json', import.meta.url));
538
- generateTable(protoPath, outPath).catch(err => {
539
- console.error(err);
540
- process.exit(1);
541
- });
542
- }
543
- const tablePath = fileURLToPath(new URL('./WAProto.json', import.meta.url));
544
- const built = makeProto(tablePath);
545
- export const proto = built.proto;
546
- export const codec = built.codec;
547
- export default {
548
- proto,
549
- codec
550
- };
@@ -1,8 +0,0 @@
1
- export * from './make-cache-manager-store.js';
2
- export * from './make-ordered-dictionary.js';
3
- export * from './object-repository.js';
4
- export * from './make-in-memory-store.js';
5
- export { default as makeInMemoryStore } from './make-in-memory-store.js';
6
- export { default as MakeCacheManagerStore } from './make-cache-manager-store.js';
7
- export { default as MakeOrderedDictionary } from './make-ordered-dictionary.js';
8
- export { default as ObjectRepository } from './object-repository.js';
@@ -1,108 +0,0 @@
1
- export default class KeyedDB {
2
- constructor(compareFn, idGetter) {
3
- if (typeof compareFn !== "function" || typeof idGetter !== "function") {
4
- throw new Error("KeyedDB requires compare and idGetter functions");
5
- }
6
- this._compare = compareFn;
7
- this._idGetter = idGetter;
8
- this._array = [];
9
- this._dict = {};
10
- }
11
- get length() {
12
- return this._array.length;
13
- }
14
- get(id) {
15
- return this._dict[id];
16
- }
17
- insert(entry, mode = "insert") {
18
- const id = this._idGetter(entry);
19
- const existing = this._dict[id];
20
- if (existing && mode === "insert") {
21
- return false;
22
- }
23
- this._dict[id] = entry;
24
- let inserted = false;
25
- for (let i = 0; i < this._array.length; i++) {
26
- const cmp = this._compare(entry, this._array[i]);
27
- if (cmp < 0) {
28
- this._array.splice(i, 0, entry);
29
- inserted = true;
30
- break;
31
- }
32
- }
33
- if (!inserted) this._array.push(entry);
34
- return true;
35
- }
36
- insertIfAbsent(...entries) {
37
- const added = [];
38
- for (const entry of entries) {
39
- if (!this._dict[this._idGetter(entry)]) {
40
- this.insert(entry);
41
- added.push(entry);
42
- }
43
- }
44
- return added;
45
- }
46
- upsert(...entries) {
47
- const added = [];
48
- for (const entry of entries) {
49
- const id = this._idGetter(entry);
50
- if (this._dict[id]) {
51
- const idx = this._array.findIndex(e => this._idGetter(e) === id);
52
- if (idx >= 0) this._array[idx] = entry;
53
- this._dict[id] = entry;
54
- } else {
55
- this.insert(entry);
56
- added.push(entry);
57
- }
58
- }
59
- return added;
60
- }
61
- update(id, updater) {
62
- const item = this._dict[id];
63
- if (!item) return false;
64
- updater(item);
65
- const idx = this._array.findIndex(e => this._idGetter(e) === id);
66
- if (idx >= 0) this._array[idx] = item;
67
- return true;
68
- }
69
- updateAssign(id, update) {
70
- const item = this._dict[id];
71
- if (!item) return false;
72
- Object.assign(item, update);
73
- const idx = this._array.findIndex(e => this._idGetter(e) === id);
74
- if (idx >= 0) this._array[idx] = item;
75
- return true;
76
- }
77
- deleteById(id) {
78
- if (!this._dict[id]) return false;
79
- delete this._dict[id];
80
- const idx = this._array.findIndex(e => this._idGetter(e) === id);
81
- if (idx >= 0) this._array.splice(idx, 1);
82
- return true;
83
- }
84
- clear() {
85
- this._array = [];
86
- this._dict = {};
87
- }
88
- all() {
89
- return [...this._array];
90
- }
91
- filter(predicate) {
92
- this._array = this._array.filter(predicate);
93
- this._dict = {};
94
- for (const entry of this._array) {
95
- this._dict[this._idGetter(entry)] = entry;
96
- }
97
- }
98
- count() {
99
- return this._array.length;
100
- }
101
- toJSON() {
102
- return this._array;
103
- }
104
- fromJSON(array) {
105
- this.clear();
106
- for (const entry of array) this.insert(entry);
107
- }
108
- }