dolphindb 2.0.918 → 2.0.920
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/browser.js +28 -17
- package/browser.js.map +1 -1
- package/docs.zh.json +17 -33
- package/i18n/dict.json +3 -0
- package/index.js +28 -17
- package/index.js.map +1 -1
- package/package.json +3 -3
package/browser.js
CHANGED
|
@@ -6,7 +6,7 @@ const { fromByteArray: buf2ipaddr } = ipaddrjs;
|
|
|
6
6
|
import 'xshell/prototype.browser.js';
|
|
7
7
|
import { blue, cyan, green, grey, magenta } from 'xshell/chalk.browser.js';
|
|
8
8
|
import { concat, assert } from 'xshell/utils.browser.js';
|
|
9
|
-
import { connect_websocket } from 'xshell/net.browser.js';
|
|
9
|
+
import { connect_websocket, WebSocketConnectionError } from 'xshell/net.browser.js';
|
|
10
10
|
import { t } from './i18n/index.js';
|
|
11
11
|
export var DdbForm;
|
|
12
12
|
(function (DdbForm) {
|
|
@@ -2125,7 +2125,10 @@ export class DdbConnectionError extends Error {
|
|
|
2125
2125
|
name = 'DdbConnectionError';
|
|
2126
2126
|
ddb;
|
|
2127
2127
|
constructor(ddb, error_options) {
|
|
2128
|
-
super(
|
|
2128
|
+
super(error_options?.cause ?
|
|
2129
|
+
error_options.cause.message
|
|
2130
|
+
:
|
|
2131
|
+
`${ddb.url} ${t('连接出错了,可能由于网络原因连接已被关闭,或服务器断开连接')}`, error_options);
|
|
2129
2132
|
this.ddb = ddb;
|
|
2130
2133
|
}
|
|
2131
2134
|
}
|
|
@@ -2223,7 +2226,7 @@ export class DDB {
|
|
|
2223
2226
|
if (options.streaming !== undefined)
|
|
2224
2227
|
this.streaming = options.streaming;
|
|
2225
2228
|
}
|
|
2226
|
-
on_message(
|
|
2229
|
+
on_message(buffer) {
|
|
2227
2230
|
// 这里的实现一定会被 connect 中的实现覆盖
|
|
2228
2231
|
}
|
|
2229
2232
|
/** 建立实际的 WebSocket 连接到 URL 对应的 DolphinDB Establish a actual websocket connection to the DolphindB corresponding to the URL
|
|
@@ -2240,22 +2243,30 @@ export class DDB {
|
|
|
2240
2243
|
await ptail;
|
|
2241
2244
|
try {
|
|
2242
2245
|
if (!this.connected) {
|
|
2243
|
-
this.on_message =
|
|
2246
|
+
this.on_message = buffer => {
|
|
2244
2247
|
assert(false, t('这是在调用 this.rpc 之前默认的 on_message, 不应该被调用到,除非建立连接后 server 先推送了 message'));
|
|
2245
2248
|
};
|
|
2246
2249
|
this.presult = Promise.resolve(null);
|
|
2247
2250
|
this.pnode_run_defined = false;
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2251
|
+
try {
|
|
2252
|
+
this.websocket = await connect_websocket(this.url, {
|
|
2253
|
+
protocols: (() => {
|
|
2254
|
+
if (this.streaming)
|
|
2255
|
+
return 'streaming';
|
|
2256
|
+
if (this.python)
|
|
2257
|
+
return 'python';
|
|
2258
|
+
})(),
|
|
2259
|
+
on_message: (buffer) => {
|
|
2260
|
+
this.on_message(buffer);
|
|
2261
|
+
}
|
|
2262
|
+
});
|
|
2263
|
+
}
|
|
2264
|
+
catch (error) {
|
|
2265
|
+
if (error instanceof WebSocketConnectionError)
|
|
2266
|
+
throw new DdbConnectionError(this, { cause: error });
|
|
2267
|
+
else
|
|
2268
|
+
throw error;
|
|
2269
|
+
}
|
|
2259
2270
|
if (this.streaming)
|
|
2260
2271
|
await this.subscribe();
|
|
2261
2272
|
else {
|
|
@@ -2392,7 +2403,7 @@ export class DDB {
|
|
|
2392
2403
|
}
|
|
2393
2404
|
catch { }
|
|
2394
2405
|
// 临界区结束,只有一个 rpc 函数调用运行到这里,可以独占 this.on_message 然后写 WebSocket
|
|
2395
|
-
this.on_message = (
|
|
2406
|
+
this.on_message = (buffer) => {
|
|
2396
2407
|
try {
|
|
2397
2408
|
const buf = new Uint8Array(buffer);
|
|
2398
2409
|
if (this.print_message_buffer)
|
|
@@ -2616,7 +2627,7 @@ export class DDB {
|
|
|
2616
2627
|
segments: [],
|
|
2617
2628
|
};
|
|
2618
2629
|
// 先准备好收到 websocket message 的 callback
|
|
2619
|
-
this.on_message =
|
|
2630
|
+
this.on_message = buffer => {
|
|
2620
2631
|
let { streaming } = this;
|
|
2621
2632
|
try {
|
|
2622
2633
|
const dv = new DataView(buffer);
|