@pixui-dev/pxw 0.1.20 → 0.1.21
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/bin/pxw.js +199 -199
- package/bin/wpbuild.js +10 -10
- package/config/default.conf +20 -20
- package/config/devops.js +372 -361
- package/config/h5es.js +10 -10
- package/config/index.html +183 -181
- package/config/pfbs.js +245 -245
- package/config/util.js +140 -140
- package/config/webpack.js +325 -309
- package/lib/assets/check.html +62 -62
- package/lib/assets/preact.js +4354 -4354
- package/lib/check/main.less +62 -62
- package/lib/check/main.tsx +41 -41
- package/lib/check/tool.js +3 -3
- package/lib/check/util.tsx +110 -110
- package/lib/grpc-web/dist/ChunkParser.js +117 -117
- package/lib/grpc-web/dist/Code.js +58 -58
- package/lib/grpc-web/dist/client.js +299 -299
- package/lib/grpc-web/dist/debug.js +16 -16
- package/lib/grpc-web/dist/detach.js +7 -7
- package/lib/grpc-web/dist/index.js +29 -29
- package/lib/grpc-web/dist/invoke.js +32 -32
- package/lib/grpc-web/dist/message.js +3 -3
- package/lib/grpc-web/dist/metadata.js +5 -5
- package/lib/grpc-web/dist/service.js +3 -3
- package/lib/grpc-web/dist/transports/Transport.js +15 -15
- package/lib/grpc-web/dist/transports/http/fetch.js +117 -117
- package/lib/grpc-web/dist/transports/http/http.js +15 -15
- package/lib/grpc-web/dist/transports/http/xhr.js +136 -136
- package/lib/grpc-web/dist/transports/http/xhrUtil.js +36 -36
- package/lib/grpc-web/dist/transports/websocket/websocket.js +95 -95
- package/lib/grpc-web/dist/typings/ChunkParser.d.ts +17 -17
- package/lib/grpc-web/dist/typings/Code.d.ts +20 -20
- package/lib/grpc-web/dist/typings/client.d.ts +25 -25
- package/lib/grpc-web/dist/typings/debug.d.ts +1 -1
- package/lib/grpc-web/dist/typings/detach.d.ts +1 -1
- package/lib/grpc-web/dist/typings/index.d.ts +45 -45
- package/lib/grpc-web/dist/typings/invoke.d.ts +20 -20
- package/lib/grpc-web/dist/typings/message.d.ts +8 -8
- package/lib/grpc-web/dist/typings/metadata.d.ts +2 -2
- package/lib/grpc-web/dist/typings/service.d.ts +16 -16
- package/lib/grpc-web/dist/typings/transports/Transport.d.ts +22 -22
- package/lib/grpc-web/dist/typings/transports/http/fetch.d.ts +6 -6
- package/lib/grpc-web/dist/typings/transports/http/http.d.ts +5 -5
- package/lib/grpc-web/dist/typings/transports/http/xhr.d.ts +27 -27
- package/lib/grpc-web/dist/typings/transports/http/xhrUtil.d.ts +3 -3
- package/lib/grpc-web/dist/typings/transports/websocket/websocket.d.ts +2 -2
- package/lib/grpc-web/dist/typings/unary.d.ts +23 -23
- package/lib/grpc-web/dist/typings/util.d.ts +2 -2
- package/lib/grpc-web/dist/unary.js +44 -44
- package/lib/grpc-web/dist/util.js +11 -11
- package/lib/grpcTransport/PixHttp2Transport.ts +107 -107
- package/lib/grpcTransport/PixLuaTransport.ts +82 -82
- package/lib/h5es-types/v1.9.2/h5es.d.ts +1698 -1698
- package/lib/h5es-types/v3.5.0/h5es.d.ts +1788 -1788
- package/lib/pi_component/tinyList/tinyList.js +483 -483
- package/lib/pi_component/tinyList/tinyList.tsx +517 -517
- package/lib/preact-router.js +395 -395
- package/lib/preact.js +4355 -4355
- package/lib/preact.tq.js +4385 -4385
- package/lib/react-window/src/FixedSizeGrid.js +172 -172
- package/lib/react-window/src/FixedSizeList.js +91 -91
- package/lib/react-window/src/VariableSizeGrid.js +329 -329
- package/lib/react-window/src/VariableSizeList.js +231 -231
- package/lib/react-window/src/__tests__/FixedSizeGrid.js +942 -942
- package/lib/react-window/src/__tests__/FixedSizeList.js +749 -749
- package/lib/react-window/src/__tests__/VariableSizeGrid.js +598 -598
- package/lib/react-window/src/__tests__/VariableSizeList.js +345 -345
- package/lib/react-window/src/__tests__/__snapshots__/FixedSizeGrid.js.snap +912 -912
- package/lib/react-window/src/__tests__/__snapshots__/FixedSizeList.js.snap +568 -568
- package/lib/react-window/src/__tests__/__snapshots__/VariableSizeGrid.js.snap +542 -542
- package/lib/react-window/src/__tests__/__snapshots__/VariableSizeList.js.snap +331 -331
- package/lib/react-window/src/__tests__/areEqual.js +28 -28
- package/lib/react-window/src/__tests__/shouldComponentUpdate.js +32 -32
- package/lib/react-window/src/areEqual.js +13 -13
- package/lib/react-window/src/createGridComponent.js +657 -657
- package/lib/react-window/src/createListComponent.js +574 -574
- package/lib/react-window/src/domHelpers.js +69 -69
- package/lib/react-window/src/index.js +9 -9
- package/lib/react-window/src/shallowDiffers.js +17 -17
- package/lib/react-window/src/shouldComponentUpdate.js +11 -11
- package/lib/react-window/src/test.js.flow +382 -382
- package/lib/react-window/src/timer.js +36 -36
- package/lib/types/dom.ts +17 -17
- package/lib/types/ext.d.ts +81 -81
- package/lib/types/preact/css.d.ts +7476 -7476
- package/lib/types/preact/index.d.ts +340 -340
- package/lib/types/preact/internal.d.ts +94 -94
- package/lib/types/preact/jsx.d.ts +309 -309
- package/lib/types/preact-router/index.d.ts +84 -84
- package/package.json +113 -113
- package/scripts/pack.js +40 -40
- package/scripts/postinstall.js +11 -11
- package/scripts/run-pxw.js +12 -12
- package/tsconfig.json +30 -30
|
@@ -1,299 +1,299 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
-
var metadata_1 = require('./metadata');
|
|
4
|
-
var ChunkParser_1 = require('./ChunkParser');
|
|
5
|
-
var Code_1 = require('./Code');
|
|
6
|
-
var debug_1 = require('./debug');
|
|
7
|
-
var Transport_1 = require('./transports/Transport');
|
|
8
|
-
var util_1 = require('./util');
|
|
9
|
-
function client(methodDescriptor, props) {
|
|
10
|
-
return new GrpcClient(methodDescriptor, props);
|
|
11
|
-
}
|
|
12
|
-
exports.client = client;
|
|
13
|
-
var GrpcClient = (function () {
|
|
14
|
-
function GrpcClient(methodDescriptor, props) {
|
|
15
|
-
this.started = false;
|
|
16
|
-
this.sentFirstMessage = false;
|
|
17
|
-
this.completed = false;
|
|
18
|
-
this.closed = false;
|
|
19
|
-
this.finishedSending = false;
|
|
20
|
-
this.onHeadersCallbacks = [];
|
|
21
|
-
this.onMessageCallbacks = [];
|
|
22
|
-
this.onEndCallbacks = [];
|
|
23
|
-
this.parser = new ChunkParser_1.ChunkParser();
|
|
24
|
-
this.methodDefinition = methodDescriptor;
|
|
25
|
-
this.props = props;
|
|
26
|
-
this.createTransport();
|
|
27
|
-
}
|
|
28
|
-
GrpcClient.prototype.createTransport = function () {
|
|
29
|
-
var url = this.props.host + '/' + this.methodDefinition.service.serviceName + '/' + this.methodDefinition.methodName;
|
|
30
|
-
var transportOptions = {
|
|
31
|
-
methodDefinition: this.methodDefinition,
|
|
32
|
-
debug: this.props.debug || false,
|
|
33
|
-
url: url,
|
|
34
|
-
onHeaders: this.onTransportHeaders.bind(this),
|
|
35
|
-
onChunk: this.onTransportChunk.bind(this),
|
|
36
|
-
onEnd: this.onTransportEnd.bind(this),
|
|
37
|
-
};
|
|
38
|
-
if (this.props.transport) {
|
|
39
|
-
this.transport = this.props.transport(transportOptions);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
this.transport = Transport_1.makeDefaultTransport(transportOptions);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
GrpcClient.prototype.onTransportHeaders = function (headers, status) {
|
|
46
|
-
this.props.debug && debug_1.debug('onHeaders', headers, status);
|
|
47
|
-
if (this.closed) {
|
|
48
|
-
this.props.debug && debug_1.debug('grpc.onHeaders received after request was closed - ignoring');
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
if (status === 0) {
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
this.responseHeaders = headers;
|
|
55
|
-
this.props.debug && debug_1.debug('onHeaders.responseHeaders', JSON.stringify(this.responseHeaders, null, 2));
|
|
56
|
-
var gRPCStatus = getStatusFromHeaders(headers);
|
|
57
|
-
this.props.debug && debug_1.debug('onHeaders.gRPCStatus', gRPCStatus);
|
|
58
|
-
var code = gRPCStatus && gRPCStatus >= 0 ? gRPCStatus : Code_1.httpStatusToCode(status);
|
|
59
|
-
this.props.debug && debug_1.debug('onHeaders.code', code);
|
|
60
|
-
var gRPCMessage = headers.get('grpc-message') || [];
|
|
61
|
-
this.props.debug && debug_1.debug('onHeaders.gRPCMessage', gRPCMessage);
|
|
62
|
-
this.rawOnHeaders(headers);
|
|
63
|
-
if (code !== Code_1.Code.OK) {
|
|
64
|
-
var statusMessage = this.decodeGRPCStatus(gRPCMessage[0]);
|
|
65
|
-
this.rawOnError(code, statusMessage, headers);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
GrpcClient.prototype.onTransportChunk = function (chunkBytes) {
|
|
70
|
-
var _this = this;
|
|
71
|
-
if (this.closed) {
|
|
72
|
-
this.props.debug && debug_1.debug('grpc.onChunk received after request was closed - ignoring');
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
if (window.noProto) {
|
|
76
|
-
_this.rawOnMessage(chunkBytes);
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
var data = [];
|
|
80
|
-
try {
|
|
81
|
-
data = this.parser.parse(chunkBytes);
|
|
82
|
-
}
|
|
83
|
-
catch (e) {
|
|
84
|
-
this.props.debug && debug_1.debug('onChunk.parsing error', e, e.message);
|
|
85
|
-
this.rawOnError(Code_1.Code.Internal, 'parsing error: ' + e.message);
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
data.forEach(function (d) {
|
|
89
|
-
if (d.chunkType === ChunkParser_1.ChunkType.MESSAGE) {
|
|
90
|
-
var deserialized = _this.methodDefinition.responseType.deserializeBinary(d.data);
|
|
91
|
-
_this.rawOnMessage(deserialized);
|
|
92
|
-
}
|
|
93
|
-
else if (d.chunkType === ChunkParser_1.ChunkType.TRAILERS) {
|
|
94
|
-
if (!_this.responseHeaders) {
|
|
95
|
-
_this.responseHeaders = new metadata_1.Metadata(d.trailers);
|
|
96
|
-
_this.rawOnHeaders(_this.responseHeaders);
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
_this.responseTrailers = new metadata_1.Metadata(d.trailers);
|
|
100
|
-
_this.props.debug && debug_1.debug('onChunk.trailers', _this.responseTrailers);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
GrpcClient.prototype.onTransportEnd = function () {
|
|
107
|
-
this.props.debug && debug_1.debug('grpc.onEnd');
|
|
108
|
-
if (this.closed) {
|
|
109
|
-
this.props.debug && debug_1.debug('grpc.onEnd received after request was closed - ignoring');
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
if (this.responseTrailers === undefined) {
|
|
113
|
-
if (this.responseHeaders === undefined) {
|
|
114
|
-
this.rawOnError(Code_1.Code.Unknown, 'Response closed without headers');
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
var grpcStatus_1 = getStatusFromHeaders(this.responseHeaders);
|
|
118
|
-
var grpcMessage_1 = this.responseHeaders.get('grpc-message');
|
|
119
|
-
this.props.debug && debug_1.debug('grpc.headers only response ', grpcStatus_1, grpcMessage_1);
|
|
120
|
-
if (grpcStatus_1 === null) {
|
|
121
|
-
this.rawOnEnd(Code_1.Code.Unknown, 'Response closed without grpc-status (Headers only)', this.responseHeaders);
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
var statusMessage_1 = this.decodeGRPCStatus(grpcMessage_1[0]);
|
|
125
|
-
this.rawOnEnd(grpcStatus_1, statusMessage_1, this.responseHeaders);
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
var grpcStatus = getStatusFromHeaders(this.responseTrailers);
|
|
129
|
-
if (grpcStatus === null) {
|
|
130
|
-
this.rawOnError(Code_1.Code.Internal, 'Response closed without grpc-status (Trailers provided)');
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
var grpcMessage = this.responseTrailers.get('grpc-message');
|
|
134
|
-
var statusMessage = this.decodeGRPCStatus(grpcMessage[0]);
|
|
135
|
-
this.rawOnEnd(grpcStatus, statusMessage, this.responseTrailers);
|
|
136
|
-
};
|
|
137
|
-
GrpcClient.prototype.decodeGRPCStatus = function (src) {
|
|
138
|
-
if (src) {
|
|
139
|
-
try {
|
|
140
|
-
return decodeURIComponent(src);
|
|
141
|
-
}
|
|
142
|
-
catch (err) {
|
|
143
|
-
return src;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
return '';
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
GrpcClient.prototype.rawOnEnd = function (code, message, trailers) {
|
|
151
|
-
var _this = this;
|
|
152
|
-
this.props.debug && debug_1.debug('rawOnEnd', code, message, trailers);
|
|
153
|
-
if (this.completed) return;
|
|
154
|
-
this.completed = true;
|
|
155
|
-
this.onEndCallbacks.forEach(function (callback) {
|
|
156
|
-
if (_this.closed) return;
|
|
157
|
-
try {
|
|
158
|
-
callback(code, message, trailers);
|
|
159
|
-
}
|
|
160
|
-
catch (e) {
|
|
161
|
-
setTimeout(function () {
|
|
162
|
-
throw e;
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
};
|
|
167
|
-
GrpcClient.prototype.rawOnHeaders = function (headers) {
|
|
168
|
-
this.props.debug && debug_1.debug('rawOnHeaders', headers);
|
|
169
|
-
if (this.completed) return;
|
|
170
|
-
this.onHeadersCallbacks.forEach(function (callback) {
|
|
171
|
-
try {
|
|
172
|
-
callback(headers);
|
|
173
|
-
}
|
|
174
|
-
catch (e) {
|
|
175
|
-
setTimeout(function () {
|
|
176
|
-
throw e;
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
};
|
|
181
|
-
GrpcClient.prototype.rawOnError = function (code, msg, trailers) {
|
|
182
|
-
var _this = this;
|
|
183
|
-
if (trailers === void 0) {
|
|
184
|
-
trailers = new metadata_1.Metadata();
|
|
185
|
-
}
|
|
186
|
-
this.props.debug && debug_1.debug('rawOnError', code, msg);
|
|
187
|
-
if (this.completed) return;
|
|
188
|
-
this.completed = true;
|
|
189
|
-
this.onEndCallbacks.forEach(function (callback) {
|
|
190
|
-
if (_this.closed) return;
|
|
191
|
-
try {
|
|
192
|
-
callback(code, msg, trailers);
|
|
193
|
-
}
|
|
194
|
-
catch (e) {
|
|
195
|
-
setTimeout(function () {
|
|
196
|
-
throw e;
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
};
|
|
201
|
-
GrpcClient.prototype.rawOnMessage = function (res) {
|
|
202
|
-
var _this = this;
|
|
203
|
-
//this.props.debug && debug_1.debug("rawOnMessage", res.toObject());
|
|
204
|
-
if (this.completed || this.closed) return;
|
|
205
|
-
this.onMessageCallbacks.forEach(function (callback) {
|
|
206
|
-
if (_this.closed) return;
|
|
207
|
-
try {
|
|
208
|
-
callback(res);
|
|
209
|
-
}
|
|
210
|
-
catch (e) {
|
|
211
|
-
setTimeout(function () {
|
|
212
|
-
throw e;
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
};
|
|
217
|
-
GrpcClient.prototype.onHeaders = function (callback) {
|
|
218
|
-
this.onHeadersCallbacks.push(callback);
|
|
219
|
-
};
|
|
220
|
-
GrpcClient.prototype.onMessage = function (callback) {
|
|
221
|
-
this.onMessageCallbacks.push(callback);
|
|
222
|
-
};
|
|
223
|
-
GrpcClient.prototype.onEnd = function (callback) {
|
|
224
|
-
this.onEndCallbacks.push(callback);
|
|
225
|
-
};
|
|
226
|
-
GrpcClient.prototype.start = function (metadata) {
|
|
227
|
-
if (this.started) {
|
|
228
|
-
throw new Error('Client already started - cannot .start()');
|
|
229
|
-
}
|
|
230
|
-
this.started = true;
|
|
231
|
-
var requestHeaders = new metadata_1.Metadata(metadata ? metadata : {});
|
|
232
|
-
requestHeaders.set('content-type', 'application/grpc-web+proto');
|
|
233
|
-
requestHeaders.set('x-grpc-web', '1');
|
|
234
|
-
this.transport.start(requestHeaders);
|
|
235
|
-
};
|
|
236
|
-
GrpcClient.prototype.send = function (msg) {
|
|
237
|
-
if (!this.started) {
|
|
238
|
-
throw new Error('Client not started - .start() must be called before .send()');
|
|
239
|
-
}
|
|
240
|
-
if (this.closed) {
|
|
241
|
-
throw new Error('Client already closed - cannot .send()');
|
|
242
|
-
}
|
|
243
|
-
if (this.finishedSending) {
|
|
244
|
-
throw new Error('Client already finished sending - cannot .send()');
|
|
245
|
-
}
|
|
246
|
-
if (!this.methodDefinition.requestStream && this.sentFirstMessage) {
|
|
247
|
-
throw new Error('Message already sent for non-client-streaming method - cannot .send()');
|
|
248
|
-
}
|
|
249
|
-
this.sentFirstMessage = true;
|
|
250
|
-
if (window.noProto) {
|
|
251
|
-
this.transport.sendMessage(msg);
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
var msgBytes = util_1.frameRequest(msg);
|
|
255
|
-
this.transport.sendMessage(msgBytes);
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
GrpcClient.prototype.finishSend = function () {
|
|
259
|
-
if (!this.started) {
|
|
260
|
-
throw new Error('Client not started - .finishSend() must be called before .close()');
|
|
261
|
-
}
|
|
262
|
-
if (this.closed) {
|
|
263
|
-
throw new Error('Client already closed - cannot .send()');
|
|
264
|
-
}
|
|
265
|
-
if (this.finishedSending) {
|
|
266
|
-
throw new Error('Client already finished sending - cannot .finishSend()');
|
|
267
|
-
}
|
|
268
|
-
this.finishedSending = true;
|
|
269
|
-
this.transport.finishSend();
|
|
270
|
-
};
|
|
271
|
-
GrpcClient.prototype.close = function () {
|
|
272
|
-
if (!this.started) {
|
|
273
|
-
throw new Error('Client not started - .start() must be called before .close()');
|
|
274
|
-
}
|
|
275
|
-
if (!this.closed) {
|
|
276
|
-
this.closed = true;
|
|
277
|
-
this.props.debug && debug_1.debug('request.abort aborting request');
|
|
278
|
-
this.transport.cancel();
|
|
279
|
-
}
|
|
280
|
-
else {
|
|
281
|
-
throw new Error('Client already closed - cannot .close()');
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
|
-
return GrpcClient;
|
|
285
|
-
})();
|
|
286
|
-
function getStatusFromHeaders(headers) {
|
|
287
|
-
var fromHeaders = headers.get('grpc-status') || [];
|
|
288
|
-
if (fromHeaders.length > 0) {
|
|
289
|
-
try {
|
|
290
|
-
var asString = fromHeaders[0];
|
|
291
|
-
return parseInt(asString, 10);
|
|
292
|
-
}
|
|
293
|
-
catch (e) {
|
|
294
|
-
return null;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
return null;
|
|
298
|
-
}
|
|
299
|
-
//# sourceMappingURL=client.js.map
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
var metadata_1 = require('./metadata');
|
|
4
|
+
var ChunkParser_1 = require('./ChunkParser');
|
|
5
|
+
var Code_1 = require('./Code');
|
|
6
|
+
var debug_1 = require('./debug');
|
|
7
|
+
var Transport_1 = require('./transports/Transport');
|
|
8
|
+
var util_1 = require('./util');
|
|
9
|
+
function client(methodDescriptor, props) {
|
|
10
|
+
return new GrpcClient(methodDescriptor, props);
|
|
11
|
+
}
|
|
12
|
+
exports.client = client;
|
|
13
|
+
var GrpcClient = (function () {
|
|
14
|
+
function GrpcClient(methodDescriptor, props) {
|
|
15
|
+
this.started = false;
|
|
16
|
+
this.sentFirstMessage = false;
|
|
17
|
+
this.completed = false;
|
|
18
|
+
this.closed = false;
|
|
19
|
+
this.finishedSending = false;
|
|
20
|
+
this.onHeadersCallbacks = [];
|
|
21
|
+
this.onMessageCallbacks = [];
|
|
22
|
+
this.onEndCallbacks = [];
|
|
23
|
+
this.parser = new ChunkParser_1.ChunkParser();
|
|
24
|
+
this.methodDefinition = methodDescriptor;
|
|
25
|
+
this.props = props;
|
|
26
|
+
this.createTransport();
|
|
27
|
+
}
|
|
28
|
+
GrpcClient.prototype.createTransport = function () {
|
|
29
|
+
var url = this.props.host + '/' + this.methodDefinition.service.serviceName + '/' + this.methodDefinition.methodName;
|
|
30
|
+
var transportOptions = {
|
|
31
|
+
methodDefinition: this.methodDefinition,
|
|
32
|
+
debug: this.props.debug || false,
|
|
33
|
+
url: url,
|
|
34
|
+
onHeaders: this.onTransportHeaders.bind(this),
|
|
35
|
+
onChunk: this.onTransportChunk.bind(this),
|
|
36
|
+
onEnd: this.onTransportEnd.bind(this),
|
|
37
|
+
};
|
|
38
|
+
if (this.props.transport) {
|
|
39
|
+
this.transport = this.props.transport(transportOptions);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
this.transport = Transport_1.makeDefaultTransport(transportOptions);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
GrpcClient.prototype.onTransportHeaders = function (headers, status) {
|
|
46
|
+
this.props.debug && debug_1.debug('onHeaders', headers, status);
|
|
47
|
+
if (this.closed) {
|
|
48
|
+
this.props.debug && debug_1.debug('grpc.onHeaders received after request was closed - ignoring');
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (status === 0) {
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
this.responseHeaders = headers;
|
|
55
|
+
this.props.debug && debug_1.debug('onHeaders.responseHeaders', JSON.stringify(this.responseHeaders, null, 2));
|
|
56
|
+
var gRPCStatus = getStatusFromHeaders(headers);
|
|
57
|
+
this.props.debug && debug_1.debug('onHeaders.gRPCStatus', gRPCStatus);
|
|
58
|
+
var code = gRPCStatus && gRPCStatus >= 0 ? gRPCStatus : Code_1.httpStatusToCode(status);
|
|
59
|
+
this.props.debug && debug_1.debug('onHeaders.code', code);
|
|
60
|
+
var gRPCMessage = headers.get('grpc-message') || [];
|
|
61
|
+
this.props.debug && debug_1.debug('onHeaders.gRPCMessage', gRPCMessage);
|
|
62
|
+
this.rawOnHeaders(headers);
|
|
63
|
+
if (code !== Code_1.Code.OK) {
|
|
64
|
+
var statusMessage = this.decodeGRPCStatus(gRPCMessage[0]);
|
|
65
|
+
this.rawOnError(code, statusMessage, headers);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
GrpcClient.prototype.onTransportChunk = function (chunkBytes) {
|
|
70
|
+
var _this = this;
|
|
71
|
+
if (this.closed) {
|
|
72
|
+
this.props.debug && debug_1.debug('grpc.onChunk received after request was closed - ignoring');
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (window.noProto) {
|
|
76
|
+
_this.rawOnMessage(chunkBytes);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
var data = [];
|
|
80
|
+
try {
|
|
81
|
+
data = this.parser.parse(chunkBytes);
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
this.props.debug && debug_1.debug('onChunk.parsing error', e, e.message);
|
|
85
|
+
this.rawOnError(Code_1.Code.Internal, 'parsing error: ' + e.message);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
data.forEach(function (d) {
|
|
89
|
+
if (d.chunkType === ChunkParser_1.ChunkType.MESSAGE) {
|
|
90
|
+
var deserialized = _this.methodDefinition.responseType.deserializeBinary(d.data);
|
|
91
|
+
_this.rawOnMessage(deserialized);
|
|
92
|
+
}
|
|
93
|
+
else if (d.chunkType === ChunkParser_1.ChunkType.TRAILERS) {
|
|
94
|
+
if (!_this.responseHeaders) {
|
|
95
|
+
_this.responseHeaders = new metadata_1.Metadata(d.trailers);
|
|
96
|
+
_this.rawOnHeaders(_this.responseHeaders);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
_this.responseTrailers = new metadata_1.Metadata(d.trailers);
|
|
100
|
+
_this.props.debug && debug_1.debug('onChunk.trailers', _this.responseTrailers);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
GrpcClient.prototype.onTransportEnd = function () {
|
|
107
|
+
this.props.debug && debug_1.debug('grpc.onEnd');
|
|
108
|
+
if (this.closed) {
|
|
109
|
+
this.props.debug && debug_1.debug('grpc.onEnd received after request was closed - ignoring');
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (this.responseTrailers === undefined) {
|
|
113
|
+
if (this.responseHeaders === undefined) {
|
|
114
|
+
this.rawOnError(Code_1.Code.Unknown, 'Response closed without headers');
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
var grpcStatus_1 = getStatusFromHeaders(this.responseHeaders);
|
|
118
|
+
var grpcMessage_1 = this.responseHeaders.get('grpc-message');
|
|
119
|
+
this.props.debug && debug_1.debug('grpc.headers only response ', grpcStatus_1, grpcMessage_1);
|
|
120
|
+
if (grpcStatus_1 === null) {
|
|
121
|
+
this.rawOnEnd(Code_1.Code.Unknown, 'Response closed without grpc-status (Headers only)', this.responseHeaders);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
var statusMessage_1 = this.decodeGRPCStatus(grpcMessage_1[0]);
|
|
125
|
+
this.rawOnEnd(grpcStatus_1, statusMessage_1, this.responseHeaders);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
var grpcStatus = getStatusFromHeaders(this.responseTrailers);
|
|
129
|
+
if (grpcStatus === null) {
|
|
130
|
+
this.rawOnError(Code_1.Code.Internal, 'Response closed without grpc-status (Trailers provided)');
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
var grpcMessage = this.responseTrailers.get('grpc-message');
|
|
134
|
+
var statusMessage = this.decodeGRPCStatus(grpcMessage[0]);
|
|
135
|
+
this.rawOnEnd(grpcStatus, statusMessage, this.responseTrailers);
|
|
136
|
+
};
|
|
137
|
+
GrpcClient.prototype.decodeGRPCStatus = function (src) {
|
|
138
|
+
if (src) {
|
|
139
|
+
try {
|
|
140
|
+
return decodeURIComponent(src);
|
|
141
|
+
}
|
|
142
|
+
catch (err) {
|
|
143
|
+
return src;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
return '';
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
GrpcClient.prototype.rawOnEnd = function (code, message, trailers) {
|
|
151
|
+
var _this = this;
|
|
152
|
+
this.props.debug && debug_1.debug('rawOnEnd', code, message, trailers);
|
|
153
|
+
if (this.completed) return;
|
|
154
|
+
this.completed = true;
|
|
155
|
+
this.onEndCallbacks.forEach(function (callback) {
|
|
156
|
+
if (_this.closed) return;
|
|
157
|
+
try {
|
|
158
|
+
callback(code, message, trailers);
|
|
159
|
+
}
|
|
160
|
+
catch (e) {
|
|
161
|
+
setTimeout(function () {
|
|
162
|
+
throw e;
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
GrpcClient.prototype.rawOnHeaders = function (headers) {
|
|
168
|
+
this.props.debug && debug_1.debug('rawOnHeaders', headers);
|
|
169
|
+
if (this.completed) return;
|
|
170
|
+
this.onHeadersCallbacks.forEach(function (callback) {
|
|
171
|
+
try {
|
|
172
|
+
callback(headers);
|
|
173
|
+
}
|
|
174
|
+
catch (e) {
|
|
175
|
+
setTimeout(function () {
|
|
176
|
+
throw e;
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
GrpcClient.prototype.rawOnError = function (code, msg, trailers) {
|
|
182
|
+
var _this = this;
|
|
183
|
+
if (trailers === void 0) {
|
|
184
|
+
trailers = new metadata_1.Metadata();
|
|
185
|
+
}
|
|
186
|
+
this.props.debug && debug_1.debug('rawOnError', code, msg);
|
|
187
|
+
if (this.completed) return;
|
|
188
|
+
this.completed = true;
|
|
189
|
+
this.onEndCallbacks.forEach(function (callback) {
|
|
190
|
+
if (_this.closed) return;
|
|
191
|
+
try {
|
|
192
|
+
callback(code, msg, trailers);
|
|
193
|
+
}
|
|
194
|
+
catch (e) {
|
|
195
|
+
setTimeout(function () {
|
|
196
|
+
throw e;
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
GrpcClient.prototype.rawOnMessage = function (res) {
|
|
202
|
+
var _this = this;
|
|
203
|
+
//this.props.debug && debug_1.debug("rawOnMessage", res.toObject());
|
|
204
|
+
if (this.completed || this.closed) return;
|
|
205
|
+
this.onMessageCallbacks.forEach(function (callback) {
|
|
206
|
+
if (_this.closed) return;
|
|
207
|
+
try {
|
|
208
|
+
callback(res);
|
|
209
|
+
}
|
|
210
|
+
catch (e) {
|
|
211
|
+
setTimeout(function () {
|
|
212
|
+
throw e;
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
GrpcClient.prototype.onHeaders = function (callback) {
|
|
218
|
+
this.onHeadersCallbacks.push(callback);
|
|
219
|
+
};
|
|
220
|
+
GrpcClient.prototype.onMessage = function (callback) {
|
|
221
|
+
this.onMessageCallbacks.push(callback);
|
|
222
|
+
};
|
|
223
|
+
GrpcClient.prototype.onEnd = function (callback) {
|
|
224
|
+
this.onEndCallbacks.push(callback);
|
|
225
|
+
};
|
|
226
|
+
GrpcClient.prototype.start = function (metadata) {
|
|
227
|
+
if (this.started) {
|
|
228
|
+
throw new Error('Client already started - cannot .start()');
|
|
229
|
+
}
|
|
230
|
+
this.started = true;
|
|
231
|
+
var requestHeaders = new metadata_1.Metadata(metadata ? metadata : {});
|
|
232
|
+
requestHeaders.set('content-type', 'application/grpc-web+proto');
|
|
233
|
+
requestHeaders.set('x-grpc-web', '1');
|
|
234
|
+
this.transport.start(requestHeaders);
|
|
235
|
+
};
|
|
236
|
+
GrpcClient.prototype.send = function (msg) {
|
|
237
|
+
if (!this.started) {
|
|
238
|
+
throw new Error('Client not started - .start() must be called before .send()');
|
|
239
|
+
}
|
|
240
|
+
if (this.closed) {
|
|
241
|
+
throw new Error('Client already closed - cannot .send()');
|
|
242
|
+
}
|
|
243
|
+
if (this.finishedSending) {
|
|
244
|
+
throw new Error('Client already finished sending - cannot .send()');
|
|
245
|
+
}
|
|
246
|
+
if (!this.methodDefinition.requestStream && this.sentFirstMessage) {
|
|
247
|
+
throw new Error('Message already sent for non-client-streaming method - cannot .send()');
|
|
248
|
+
}
|
|
249
|
+
this.sentFirstMessage = true;
|
|
250
|
+
if (window.noProto) {
|
|
251
|
+
this.transport.sendMessage(msg);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
var msgBytes = util_1.frameRequest(msg);
|
|
255
|
+
this.transport.sendMessage(msgBytes);
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
GrpcClient.prototype.finishSend = function () {
|
|
259
|
+
if (!this.started) {
|
|
260
|
+
throw new Error('Client not started - .finishSend() must be called before .close()');
|
|
261
|
+
}
|
|
262
|
+
if (this.closed) {
|
|
263
|
+
throw new Error('Client already closed - cannot .send()');
|
|
264
|
+
}
|
|
265
|
+
if (this.finishedSending) {
|
|
266
|
+
throw new Error('Client already finished sending - cannot .finishSend()');
|
|
267
|
+
}
|
|
268
|
+
this.finishedSending = true;
|
|
269
|
+
this.transport.finishSend();
|
|
270
|
+
};
|
|
271
|
+
GrpcClient.prototype.close = function () {
|
|
272
|
+
if (!this.started) {
|
|
273
|
+
throw new Error('Client not started - .start() must be called before .close()');
|
|
274
|
+
}
|
|
275
|
+
if (!this.closed) {
|
|
276
|
+
this.closed = true;
|
|
277
|
+
this.props.debug && debug_1.debug('request.abort aborting request');
|
|
278
|
+
this.transport.cancel();
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
throw new Error('Client already closed - cannot .close()');
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
return GrpcClient;
|
|
285
|
+
})();
|
|
286
|
+
function getStatusFromHeaders(headers) {
|
|
287
|
+
var fromHeaders = headers.get('grpc-status') || [];
|
|
288
|
+
if (fromHeaders.length > 0) {
|
|
289
|
+
try {
|
|
290
|
+
var asString = fromHeaders[0];
|
|
291
|
+
return parseInt(asString, 10);
|
|
292
|
+
}
|
|
293
|
+
catch (e) {
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
-
function debug() {
|
|
4
|
-
var args = [];
|
|
5
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
6
|
-
args[_i] = arguments[_i];
|
|
7
|
-
}
|
|
8
|
-
if (console.debug) {
|
|
9
|
-
console.debug.apply(null, args);
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
console.log.apply(null, args);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.debug = debug;
|
|
16
|
-
//# sourceMappingURL=debug.js.map
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
function debug() {
|
|
4
|
+
var args = [];
|
|
5
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
6
|
+
args[_i] = arguments[_i];
|
|
7
|
+
}
|
|
8
|
+
if (console.debug) {
|
|
9
|
+
console.debug.apply(null, args);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
console.log.apply(null, args);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.debug = debug;
|
|
16
|
+
//# sourceMappingURL=debug.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
-
function detach(cb) {
|
|
4
|
-
cb();
|
|
5
|
-
}
|
|
6
|
-
exports.default = detach;
|
|
7
|
-
//# sourceMappingURL=detach.js.map
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
function detach(cb) {
|
|
4
|
+
cb();
|
|
5
|
+
}
|
|
6
|
+
exports.default = detach;
|
|
7
|
+
//# sourceMappingURL=detach.js.map
|