@another-trial/airgram 5.1.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/Airgram.d.ts +12 -0
- package/Airgram.js +66 -0
- package/Airgram.js.map +1 -0
- package/README.md +3 -0
- package/__tests__/json.d.ts +1 -0
- package/__tests__/json.js +29 -0
- package/__tests__/json.js.map +1 -0
- package/components/Auth.d.ts +35 -0
- package/components/Auth.js +391 -0
- package/components/Auth.js.map +1 -0
- package/components/BaseJsonClient.d.ts +14 -0
- package/components/BaseJsonClient.js +10 -0
- package/components/BaseJsonClient.js.map +1 -0
- package/components/FakeJsonClient.d.ts +35 -0
- package/components/FakeJsonClient.js +252 -0
- package/components/FakeJsonClient.js.map +1 -0
- package/components/Provider.d.ts +12 -0
- package/components/Provider.js +117 -0
- package/components/Provider.js.map +1 -0
- package/components/TdJsonClient.d.ts +40 -0
- package/components/TdJsonClient.js +310 -0
- package/components/TdJsonClient.js.map +1 -0
- package/components/index.d.ts +3 -0
- package/components/index.js +16 -0
- package/components/index.js.map +1 -0
- package/index.d.ts +5 -0
- package/index.js +24 -0
- package/index.js.map +1 -0
- package/package.json +28 -0
- package/types.d.ts +14 -0
- package/types.js +3 -0
- package/types.js.map +1 -0
- package/utils/index.d.ts +2 -0
- package/utils/index.js +15 -0
- package/utils/index.js.map +1 -0
- package/utils/json.d.ts +5 -0
- package/utils/json.js +77 -0
- package/utils/json.js.map +1 -0
- package/utils/prompt.d.ts +5 -0
- package/utils/prompt.js +58 -0
- package/utils/prompt.js.map +1 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/camelcase,@typescript-eslint/no-explicit-any */
|
|
3
|
+
var __extends = (this && this.__extends) || (function () {
|
|
4
|
+
var extendStatics = function (d, b) {
|
|
5
|
+
extendStatics = Object.setPrototypeOf ||
|
|
6
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
7
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
8
|
+
return extendStatics(d, b);
|
|
9
|
+
};
|
|
10
|
+
return function (d, b) {
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
17
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
19
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
20
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
21
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
22
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
26
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
27
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
28
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
29
|
+
function step(op) {
|
|
30
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
31
|
+
while (_) try {
|
|
32
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
33
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
34
|
+
switch (op[0]) {
|
|
35
|
+
case 0: case 1: t = op; break;
|
|
36
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
37
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
38
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
39
|
+
default:
|
|
40
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
41
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
42
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
43
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
44
|
+
if (t[2]) _.ops.pop();
|
|
45
|
+
_.trys.pop(); continue;
|
|
46
|
+
}
|
|
47
|
+
op = body.call(thisArg, _);
|
|
48
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
49
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
exports.FakeJsonClient = void 0;
|
|
54
|
+
var fs_1 = require("fs");
|
|
55
|
+
var utils_1 = require("../utils");
|
|
56
|
+
var BaseJsonClient_1 = require("./BaseJsonClient");
|
|
57
|
+
var FakeJsonClient = /** @class */ (function (_super) {
|
|
58
|
+
__extends(FakeJsonClient, _super);
|
|
59
|
+
function FakeJsonClient(filename) {
|
|
60
|
+
var _this = _super.call(this) || this;
|
|
61
|
+
_this.destroyed = false;
|
|
62
|
+
_this.pending = new Map();
|
|
63
|
+
_this.sleepPromise = null;
|
|
64
|
+
_this.stack = new Map();
|
|
65
|
+
_this.updateHandlers = new Map();
|
|
66
|
+
_this.wakeup = null;
|
|
67
|
+
_this.deserialize = utils_1.createDeserializer();
|
|
68
|
+
_this.handleError = function (error) {
|
|
69
|
+
throw error;
|
|
70
|
+
};
|
|
71
|
+
_this.log = JSON.parse(fs_1.readFileSync(filename, { encoding: 'utf-8' }));
|
|
72
|
+
_this.logSize = _this.log.length;
|
|
73
|
+
return _this;
|
|
74
|
+
}
|
|
75
|
+
FakeJsonClient.prototype.addUpdateHandler = function (clientId, fn) {
|
|
76
|
+
this.updateHandlers.set(clientId, fn);
|
|
77
|
+
console.time('getUpdates()');
|
|
78
|
+
this.loop();
|
|
79
|
+
};
|
|
80
|
+
FakeJsonClient.prototype.catch = function (handler) {
|
|
81
|
+
this.handleError = handler;
|
|
82
|
+
};
|
|
83
|
+
FakeJsonClient.prototype.create = function () {
|
|
84
|
+
return 1;
|
|
85
|
+
};
|
|
86
|
+
FakeJsonClient.prototype.destroy = function () {
|
|
87
|
+
this.pending.clear();
|
|
88
|
+
this.sleepPromise = null;
|
|
89
|
+
this.wakeup = null;
|
|
90
|
+
this.destroyed = true;
|
|
91
|
+
};
|
|
92
|
+
FakeJsonClient.prototype.execute = function (query) {
|
|
93
|
+
return this.parseResponse(JSON.stringify({ _: 'ok', query: query }));
|
|
94
|
+
};
|
|
95
|
+
FakeJsonClient.prototype.pause = function () {
|
|
96
|
+
var _this = this;
|
|
97
|
+
if (!this.wakeup) {
|
|
98
|
+
this.sleepPromise = new Promise(function (resolve) {
|
|
99
|
+
_this.wakeup = resolve;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
FakeJsonClient.prototype.removeUpdateHandler = function (clientId) {
|
|
104
|
+
this.updateHandlers.delete(clientId);
|
|
105
|
+
this.pending.delete(clientId);
|
|
106
|
+
this.stack.delete(clientId);
|
|
107
|
+
};
|
|
108
|
+
FakeJsonClient.prototype.resume = function () {
|
|
109
|
+
if (this.wakeup && !this.destroyed) {
|
|
110
|
+
this.wakeup();
|
|
111
|
+
this.sleepPromise = null;
|
|
112
|
+
this.wakeup = null;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
FakeJsonClient.prototype.send = function (clientId, id, request, resolve) {
|
|
116
|
+
if (!this.destroyed) {
|
|
117
|
+
console.info('[FakeJsonClient] send()', {
|
|
118
|
+
clientId: clientId,
|
|
119
|
+
id: id,
|
|
120
|
+
request: request,
|
|
121
|
+
resolve: resolve
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
FakeJsonClient.prototype.addToStack = function (response) {
|
|
126
|
+
if (response) {
|
|
127
|
+
var clientId = Number(response['@client_id']);
|
|
128
|
+
var clientStack = this.getClientStack(clientId);
|
|
129
|
+
clientStack.push(response);
|
|
130
|
+
if (clientStack.length === 1) {
|
|
131
|
+
this.handleResponse(clientId).catch(this.handleError);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
FakeJsonClient.prototype.getClientHandlers = function (clientId) {
|
|
136
|
+
var clientHandlers = this.pending.get(clientId);
|
|
137
|
+
if (!clientHandlers) {
|
|
138
|
+
clientHandlers = new Map();
|
|
139
|
+
this.pending.set(clientId, clientHandlers);
|
|
140
|
+
}
|
|
141
|
+
return clientHandlers;
|
|
142
|
+
};
|
|
143
|
+
FakeJsonClient.prototype.getClientStack = function (clientId) {
|
|
144
|
+
var clientStack = this.stack.get(clientId);
|
|
145
|
+
if (!clientStack) {
|
|
146
|
+
clientStack = [];
|
|
147
|
+
this.stack.set(clientId, clientStack);
|
|
148
|
+
}
|
|
149
|
+
return clientStack;
|
|
150
|
+
};
|
|
151
|
+
FakeJsonClient.prototype.handleResponse = function (clientId) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
153
|
+
var clientStack, response, requestId, clientHandlers, resolve;
|
|
154
|
+
var _this = this;
|
|
155
|
+
return __generator(this, function (_a) {
|
|
156
|
+
switch (_a.label) {
|
|
157
|
+
case 0:
|
|
158
|
+
clientStack = this.getClientStack(clientId);
|
|
159
|
+
response = clientStack.shift();
|
|
160
|
+
if (!response) {
|
|
161
|
+
return [2 /*return*/, Promise.resolve()];
|
|
162
|
+
}
|
|
163
|
+
requestId = response['@extra'];
|
|
164
|
+
delete response['@client_id'];
|
|
165
|
+
delete response['@extra'];
|
|
166
|
+
if (!requestId) return [3 /*break*/, 1];
|
|
167
|
+
clientHandlers = this.getClientHandlers(clientId);
|
|
168
|
+
resolve = clientHandlers.get(requestId);
|
|
169
|
+
clientHandlers.delete(requestId);
|
|
170
|
+
if (resolve) {
|
|
171
|
+
resolve(response);
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
// this.handleError(new Error(`[TdProxy] request handler for the client ${clientId} not found. Missed update: ${JSON.stringify(response)}`))
|
|
175
|
+
}
|
|
176
|
+
return [3 /*break*/, 3];
|
|
177
|
+
case 1: return [4 /*yield*/, this.handleUpdate(clientId, response)];
|
|
178
|
+
case 2:
|
|
179
|
+
_a.sent();
|
|
180
|
+
_a.label = 3;
|
|
181
|
+
case 3:
|
|
182
|
+
setImmediate(function () { return _this.handleResponse(clientId); });
|
|
183
|
+
return [2 /*return*/];
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
FakeJsonClient.prototype.handleUpdate = function (clientId, response) {
|
|
189
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
190
|
+
var handler;
|
|
191
|
+
return __generator(this, function (_a) {
|
|
192
|
+
handler = this.updateHandlers.get(clientId);
|
|
193
|
+
if (handler) {
|
|
194
|
+
return [2 /*return*/, handler(response)];
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
this.handleError(new Error("[TdProxy] updates handler for the client " + clientId + " not found. Missed update: " + JSON.stringify(response)));
|
|
198
|
+
}
|
|
199
|
+
return [2 /*return*/];
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
FakeJsonClient.prototype.loop = function () {
|
|
204
|
+
var _this = this;
|
|
205
|
+
if (this.destroyed) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (this.sleepPromise) {
|
|
209
|
+
this.sleepPromise.then(function () {
|
|
210
|
+
_this.receive();
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
this.receive();
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
FakeJsonClient.prototype.onReceive = function (response) {
|
|
218
|
+
var _this = this;
|
|
219
|
+
if (response) {
|
|
220
|
+
this.addToStack(response);
|
|
221
|
+
}
|
|
222
|
+
setImmediate(function () { return _this.loop(); });
|
|
223
|
+
};
|
|
224
|
+
FakeJsonClient.prototype.parseResponse = function (data) {
|
|
225
|
+
try {
|
|
226
|
+
if (data === null) {
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
return JSON.parse(data, this.deserialize);
|
|
230
|
+
}
|
|
231
|
+
catch (e) {
|
|
232
|
+
this.handleError(new Error('[TdProxy] received invalid JSON'));
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
FakeJsonClient.prototype.receive = function () {
|
|
237
|
+
if (this.destroyed) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
var response = this.log.shift();
|
|
241
|
+
if (!response) {
|
|
242
|
+
console.log("Total updates: " + this.logSize);
|
|
243
|
+
console.timeEnd('getUpdates()');
|
|
244
|
+
return this.destroy();
|
|
245
|
+
}
|
|
246
|
+
var tdObject = this.parseResponse(response);
|
|
247
|
+
this.onReceive(tdObject);
|
|
248
|
+
};
|
|
249
|
+
return FakeJsonClient;
|
|
250
|
+
}(BaseJsonClient_1.BaseJsonClient));
|
|
251
|
+
exports.FakeJsonClient = FakeJsonClient;
|
|
252
|
+
//# sourceMappingURL=FakeJsonClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FakeJsonClient.js","sourceRoot":"","sources":["../../src/components/FakeJsonClient.ts"],"names":[],"mappings":";AAAA,oFAAoF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGpF,yBAAiC;AAEjC,kCAA6C;AAC7C,mD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AI,QAAQ,EAAE;YACZ,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;SAC1B;QACD,YAAY,CAAC,cAAM,OAAA,KAAI,CAAC,IAAI,EAAE,EAAX,CAAW,CAAC,CAAA;IACjC,CAAC;IAEO,sCAAa,GAArB,UAAuB,IAAmB;QACxC,IAAI;YACF,IAAI,IAAI,KAAK,IAAI,EAAE;gBACjB,OAAO,IAAI,CAAA;aACZ;YACD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;SAC1C;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC,CAAA;YAC9D,OAAO,IAAI,CAAA;SACZ;IACH,CAAC;IAEO,gCAAO,GAAf;QACE,IAAI,IAAI,CAAC,SAAS,EAAE;YAClB,OAAM;SACP;QAED,IAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAA;QACjC,IAAI,CAAC,QAAQ,EAAE;YACb,OAAO,CAAC,GAAG,CAAC,oBAAkB,IAAI,CAAC,OAAS,CAAC,CAAA;YAC7C,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;YAC/B,OAAO,IAAI,CAAC,OAAO,EAAE,CAAA;SACtB;QAED,IAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;QAC7C,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAA;IAC1B,CAAC;IACH,qBAAC;AAAD,CAAC,AApND,CAAoC,+BAAc,GAoNjD;AApNY,wCAAc"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ApiRequest, Provider as BaseTdProvider, TdObject } from '@airgram/core';
|
|
2
|
+
import { TdProviderConfig } from '../types';
|
|
3
|
+
import { BaseJsonClient } from './BaseJsonClient';
|
|
4
|
+
export declare class Provider extends BaseTdProvider {
|
|
5
|
+
private readonly clientId;
|
|
6
|
+
private readonly tdJsonClient;
|
|
7
|
+
private waitForDestroy;
|
|
8
|
+
constructor(tdJsonClient: BaseJsonClient, { handleUpdate }: TdProviderConfig);
|
|
9
|
+
destroy(): Promise<void>;
|
|
10
|
+
execute(request: ApiRequest): TdObject;
|
|
11
|
+
send(request: ApiRequest): Promise<TdObject>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
extendStatics(d, b);
|
|
11
|
+
function __() { this.constructor = d; }
|
|
12
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
var __assign = (this && this.__assign) || function () {
|
|
16
|
+
__assign = Object.assign || function(t) {
|
|
17
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
18
|
+
s = arguments[i];
|
|
19
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
20
|
+
t[p] = s[p];
|
|
21
|
+
}
|
|
22
|
+
return t;
|
|
23
|
+
};
|
|
24
|
+
return __assign.apply(this, arguments);
|
|
25
|
+
};
|
|
26
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
27
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
28
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
29
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
30
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
31
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
32
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
36
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
37
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
38
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
39
|
+
function step(op) {
|
|
40
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
41
|
+
while (_) try {
|
|
42
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
43
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
44
|
+
switch (op[0]) {
|
|
45
|
+
case 0: case 1: t = op; break;
|
|
46
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
47
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
48
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
49
|
+
default:
|
|
50
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
51
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
52
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
53
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
54
|
+
if (t[2]) _.ops.pop();
|
|
55
|
+
_.trys.pop(); continue;
|
|
56
|
+
}
|
|
57
|
+
op = body.call(thisArg, _);
|
|
58
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
59
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
63
|
+
exports.Provider = void 0;
|
|
64
|
+
var core_1 = require("@airgram/core");
|
|
65
|
+
var queryId = 0;
|
|
66
|
+
var Provider = /** @class */ (function (_super) {
|
|
67
|
+
__extends(Provider, _super);
|
|
68
|
+
function Provider(tdJsonClient, _a) {
|
|
69
|
+
var handleUpdate = _a.handleUpdate;
|
|
70
|
+
var _this = _super.call(this) || this;
|
|
71
|
+
_this.waitForDestroy = null;
|
|
72
|
+
_this.tdJsonClient = tdJsonClient;
|
|
73
|
+
_this.clientId = _this.tdJsonClient.create();
|
|
74
|
+
_this.tdJsonClient.addUpdateHandler(_this.clientId, function (update) {
|
|
75
|
+
if (_this.waitForDestroy && update._ === 'updateAuthorizationState' &&
|
|
76
|
+
update.authorizationState._ === 'authorizationStateClosed') {
|
|
77
|
+
_this.tdJsonClient.removeUpdateHandler(_this.clientId);
|
|
78
|
+
return _this.waitForDestroy();
|
|
79
|
+
}
|
|
80
|
+
return handleUpdate(update);
|
|
81
|
+
});
|
|
82
|
+
return _this;
|
|
83
|
+
}
|
|
84
|
+
Provider.prototype.destroy = function () {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
86
|
+
var _this = this;
|
|
87
|
+
return __generator(this, function (_a) {
|
|
88
|
+
return [2 /*return*/, new Promise(function (resolve) {
|
|
89
|
+
if (_this.waitForDestroy) {
|
|
90
|
+
return _this.waitForDestroy;
|
|
91
|
+
}
|
|
92
|
+
_this.waitForDestroy = resolve;
|
|
93
|
+
_this.send({ method: 'close', params: {} });
|
|
94
|
+
})];
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
Provider.prototype.execute = function (request) {
|
|
99
|
+
var id = "q" + ++queryId;
|
|
100
|
+
var method = request.method, params = request.params;
|
|
101
|
+
var data = this.tdJsonClient.execute(__assign(__assign({}, params), { '@extra': id, _: method }));
|
|
102
|
+
if (data === null) {
|
|
103
|
+
throw new Error("[TdProvider] empty response. Request: " + JSON.stringify(request));
|
|
104
|
+
}
|
|
105
|
+
return data;
|
|
106
|
+
};
|
|
107
|
+
Provider.prototype.send = function (request) {
|
|
108
|
+
var id = "q" + this.clientId + ":" + ++queryId;
|
|
109
|
+
var method = request.method, params = request.params;
|
|
110
|
+
var _a = core_1.createDeferred(), promise = _a.promise, resolve = _a.resolve;
|
|
111
|
+
this.tdJsonClient.send(this.clientId, id, __assign(__assign({}, params), { '@extra': id, _: method }), resolve);
|
|
112
|
+
return promise;
|
|
113
|
+
};
|
|
114
|
+
return Provider;
|
|
115
|
+
}(core_1.Provider));
|
|
116
|
+
exports.Provider = Provider;
|
|
117
|
+
//# sourceMappingURL=Provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Provider.js","sourceRoot":"","sources":["../../src/components/Provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sCAMsB;AAItB,IAAI,OAAO,GAAG,CAAC,CAAA;AAEf;IAA8B,4BAAc;IAO1C,kBAAoB,YAA4B,EAAE,EAAkC;YAAhC,YAAY,kBAAA;QAAhE,YACE,iBAAO,SAWR;QAdO,oBAAc,GAAkC,IAAI,CAAA;QAI1D,KAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,KAAI,CAAC,QAAQ,GAAG,KAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAA;QAC1C,KAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,KAAI,CAAC,QAAQ,EAAE,UAAC,MAAgB;YACjE,IAAI,KAAI,CAAC,cAAc,IAAI,MAAM,CAAC,CA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AY;QAC5B,IAAA,KAAuB,qBAAc,EAAY,EAA/C,OAAO,aAAA,EAAE,OAAO,aAA+B,CAAA;QACvD,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,wBACnC,MAAM,KACT,QAAQ,EAAE,EAAE,EACZ,CAAC,EAAE,MAAM,KACR,OAAO,CAAC,CAAA;QACX,OAAO,OAAO,CAAA;IAChB,CAAC;IACH,eAAC;AAAD,CAAC,AAxDD,CAA8B,eAAc,GAwD3C;AAxDY,4BAAQ"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { TdObject } from '@airgram/core';
|
|
2
|
+
import { NativeTdObject, TdJsonConfig, UpdateHandlerFn } from '../types';
|
|
3
|
+
import { BaseJsonClient } from './BaseJsonClient';
|
|
4
|
+
export declare class TdJsonClient extends BaseJsonClient {
|
|
5
|
+
readonly command?: string;
|
|
6
|
+
private readonly client;
|
|
7
|
+
private readonly deserialize;
|
|
8
|
+
private destroyed;
|
|
9
|
+
private handleError;
|
|
10
|
+
private log;
|
|
11
|
+
private readonly pending;
|
|
12
|
+
private readonly serialize;
|
|
13
|
+
private sleepPromise;
|
|
14
|
+
private stack;
|
|
15
|
+
private readonly timeout;
|
|
16
|
+
private readonly updateHandlers;
|
|
17
|
+
private wakeup;
|
|
18
|
+
private writeLog;
|
|
19
|
+
constructor({ command, models, timeout }: TdJsonConfig);
|
|
20
|
+
addUpdateHandler(clientId: number, fn: UpdateHandlerFn): void;
|
|
21
|
+
catch(handler: (error: Error) => void): void;
|
|
22
|
+
create(): number;
|
|
23
|
+
destroy(): void;
|
|
24
|
+
execute(query: TdObject): NativeTdObject;
|
|
25
|
+
flushLog(filename?: string): string[];
|
|
26
|
+
pause(): void;
|
|
27
|
+
removeUpdateHandler(clientId: number): void;
|
|
28
|
+
resume(): void;
|
|
29
|
+
send(clientId: number, id: string, request: TdObject, resolve: UpdateHandlerFn): void;
|
|
30
|
+
startLog(): void;
|
|
31
|
+
private addToStack;
|
|
32
|
+
private getClientHandlers;
|
|
33
|
+
private getClientStack;
|
|
34
|
+
private handleResponse;
|
|
35
|
+
private handleUpdate;
|
|
36
|
+
private loop;
|
|
37
|
+
private onReceive;
|
|
38
|
+
private parseResponse;
|
|
39
|
+
private receive;
|
|
40
|
+
}
|