dolphindb 2.0.939 → 2.0.943
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.d.ts +6 -3
- package/browser.js +26 -15
- package/browser.js.map +1 -1
- package/index.d.ts +6 -4
- package/index.js +26 -15
- package/index.js.map +1 -1
- package/package.json +3 -3
package/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import type { InspectOptions as UtilInspectOptions } from 'util';
|
|
3
|
-
import { inspect } from 'xshell';
|
|
3
|
+
import { inspect, type WebSocketConnectionError } from 'xshell';
|
|
4
4
|
export declare enum DdbForm {
|
|
5
5
|
scalar = 0,
|
|
6
6
|
vector = 1,
|
|
@@ -183,8 +183,8 @@ DdbSymbolExtendedValue | DdbArrayVectorValue | DdbDecimal32VectorValue | DdbDeci
|
|
|
183
183
|
export type DdbValue = DdbScalarValue | DdbVectorValue | DdbMatrixValue | DdbDictValue | DdbChartValue;
|
|
184
184
|
export type DdbStringObj = DdbObj<string>;
|
|
185
185
|
export type DdbVectorObj<TValue extends DdbVectorValue = DdbVectorValue> = DdbObj<TValue>;
|
|
186
|
-
export type DdbVectorAnyObj =
|
|
187
|
-
export type DdbVectorStringObj =
|
|
186
|
+
export type DdbVectorAnyObj = DdbVectorObj<DdbObj[]>;
|
|
187
|
+
export type DdbVectorStringObj = DdbVectorObj<string[]>;
|
|
188
188
|
export type DdbTableObj<TColumns extends DdbVectorObj[] = DdbVectorObj[]> = DdbObj<TColumns>;
|
|
189
189
|
export type DdbDictObj<TKeys extends DdbVectorObj = DdbVectorObj, TValues extends DdbVectorObj = DdbVectorObj> = DdbObj<[TKeys, TValues]>;
|
|
190
190
|
export type DdbMatrixObj<TValue extends DdbMatrixValue = DdbMatrixValue> = DdbObj<TValue>;
|
|
@@ -462,8 +462,9 @@ export interface DdbRpcOptions {
|
|
|
462
462
|
}
|
|
463
463
|
export declare class DdbConnectionError extends Error {
|
|
464
464
|
name: string;
|
|
465
|
+
cause?: WebSocketConnectionError;
|
|
465
466
|
ddb: DDB;
|
|
466
|
-
constructor(ddb: DDB,
|
|
467
|
+
constructor(ddb: DDB, error?: WebSocketConnectionError);
|
|
467
468
|
}
|
|
468
469
|
export declare class DdbDatabaseError extends Error {
|
|
469
470
|
name: string;
|
|
@@ -538,6 +539,7 @@ export declare class DDB {
|
|
|
538
539
|
streaming?: StreamingParams;
|
|
539
540
|
});
|
|
540
541
|
private on_message;
|
|
542
|
+
private on_error;
|
|
541
543
|
/** 建立实际的 WebSocket 连接到 URL 对应的 DolphinDB Establish a actual websocket connection to the DolphindB corresponding to the URL
|
|
542
544
|
是幂等的,调用后会确保已连接到数据库 (确保 websocket.readyState 为 open),否则报错 After calling, it will ensure that it has been connected to the database (ensure that websocket.ReadyState is open), otherwise an error will be reported
|
|
543
545
|
this.autologin 为 true 时自动登录 this.autologin automatically log in when it is true */
|
package/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import DayjsCustomParseFormat from 'dayjs/plugin/customParseFormat.js';
|
|
|
4
4
|
dayjs.extend(DayjsCustomParseFormat);
|
|
5
5
|
import ipaddrjs from 'ipaddr.js';
|
|
6
6
|
const { fromByteArray: buf2ipaddr } = ipaddrjs;
|
|
7
|
-
import { concat, assert, inspect, typed_array_to_buffer, connect_websocket, WebSocket,
|
|
7
|
+
import { concat, assert, inspect, typed_array_to_buffer, connect_websocket, WebSocket, defer } from 'xshell';
|
|
8
8
|
import { t } from './i18n/index.js';
|
|
9
9
|
export var DdbForm;
|
|
10
10
|
(function (DdbForm) {
|
|
@@ -2134,12 +2134,10 @@ export function int1282str(buffer, le = true) {
|
|
|
2134
2134
|
export const winsize = 10_0000;
|
|
2135
2135
|
export class DdbConnectionError extends Error {
|
|
2136
2136
|
name = 'DdbConnectionError';
|
|
2137
|
+
cause;
|
|
2137
2138
|
ddb;
|
|
2138
|
-
constructor(ddb,
|
|
2139
|
-
super(
|
|
2140
|
-
error_options.cause.message
|
|
2141
|
-
:
|
|
2142
|
-
`${ddb.url} ${t('连接出错了,可能由于网络原因连接已被关闭,或服务器断开连接')}`, error_options);
|
|
2139
|
+
constructor(ddb, error) {
|
|
2140
|
+
super(error?.message || `${ddb.url} ${t('连接出错了,可能由于网络原因连接已被关闭,或服务器断开连接')}`, { cause: error });
|
|
2143
2141
|
this.ddb = ddb;
|
|
2144
2142
|
}
|
|
2145
2143
|
}
|
|
@@ -2234,8 +2232,11 @@ export class DDB {
|
|
|
2234
2232
|
if (options.streaming !== undefined)
|
|
2235
2233
|
this.streaming = options.streaming;
|
|
2236
2234
|
}
|
|
2237
|
-
on_message(buffer) {
|
|
2238
|
-
// 这里的实现一定会被 connect 中的实现覆盖
|
|
2235
|
+
on_message(buffer, websocket) {
|
|
2236
|
+
// 这里的实现一定会被 connect, rpc 中的实现覆盖
|
|
2237
|
+
}
|
|
2238
|
+
on_error(error, websocket) {
|
|
2239
|
+
// 这里的实现一定会被 connect, rpc 中的实现覆盖
|
|
2239
2240
|
}
|
|
2240
2241
|
/** 建立实际的 WebSocket 连接到 URL 对应的 DolphinDB Establish a actual websocket connection to the DolphindB corresponding to the URL
|
|
2241
2242
|
是幂等的,调用后会确保已连接到数据库 (确保 websocket.readyState 为 open),否则报错 After calling, it will ensure that it has been connected to the database (ensure that websocket.ReadyState is open), otherwise an error will be reported
|
|
@@ -2248,7 +2249,10 @@ export class DDB {
|
|
|
2248
2249
|
await ptail;
|
|
2249
2250
|
try {
|
|
2250
2251
|
if (!this.connected) {
|
|
2251
|
-
this.
|
|
2252
|
+
this.on_error = (error, websocket) => {
|
|
2253
|
+
pconnect.reject(new DdbConnectionError(this, error));
|
|
2254
|
+
};
|
|
2255
|
+
this.on_message = (buffer, websocket) => {
|
|
2252
2256
|
assert(false, t('这是在调用 this.rpc 之前默认的 on_message, 不应该被调用到,除非建立连接后 server 先推送了 message'));
|
|
2253
2257
|
};
|
|
2254
2258
|
this.presult = defer(null);
|
|
@@ -2261,16 +2265,16 @@ export class DDB {
|
|
|
2261
2265
|
if (this.python)
|
|
2262
2266
|
return 'python';
|
|
2263
2267
|
})(),
|
|
2264
|
-
on_message: (buffer) => {
|
|
2265
|
-
this.on_message(buffer);
|
|
2268
|
+
on_message: (buffer, websocket) => {
|
|
2269
|
+
this.on_message(buffer, websocket);
|
|
2270
|
+
},
|
|
2271
|
+
on_error: (error, websocket) => {
|
|
2272
|
+
this.on_error(error, websocket);
|
|
2266
2273
|
}
|
|
2267
2274
|
});
|
|
2268
2275
|
}
|
|
2269
2276
|
catch (error) {
|
|
2270
|
-
|
|
2271
|
-
throw new DdbConnectionError(this, { cause: error });
|
|
2272
|
-
else
|
|
2273
|
-
throw error;
|
|
2277
|
+
throw new DdbConnectionError(this, error);
|
|
2274
2278
|
}
|
|
2275
2279
|
if (this.streaming)
|
|
2276
2280
|
await this.subscribe();
|
|
@@ -2399,6 +2403,13 @@ export class DDB {
|
|
|
2399
2403
|
}
|
|
2400
2404
|
catch { }
|
|
2401
2405
|
// 临界区结束,只有一个 rpc 函数调用运行到这里,可以独占 this.on_message 然后写 WebSocket
|
|
2406
|
+
if (!this.connected) {
|
|
2407
|
+
presult.reject(new DdbConnectionError(this));
|
|
2408
|
+
return presult;
|
|
2409
|
+
}
|
|
2410
|
+
this.on_error = (error, websocket) => {
|
|
2411
|
+
presult.reject(new DdbConnectionError(this, error));
|
|
2412
|
+
};
|
|
2402
2413
|
this.on_message = buffer => {
|
|
2403
2414
|
try {
|
|
2404
2415
|
const buf = new Uint8Array(buffer);
|