dolphindb 2.0.940 → 2.0.944
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 +10 -3
- package/browser.js +53 -22
- package/browser.js.map +1 -1
- package/index.d.ts +11 -5
- package/index.js +43 -16
- package/index.js.map +1 -1
- package/package.json +3 -3
package/browser.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import 'xshell/prototype.browser.js';
|
|
2
|
+
import { type WebSocketConnectionError } from 'xshell/net.browser.js';
|
|
2
3
|
export declare enum DdbForm {
|
|
3
4
|
scalar = 0,
|
|
4
5
|
vector = 1,
|
|
@@ -181,8 +182,8 @@ DdbSymbolExtendedValue | DdbArrayVectorValue | DdbDecimal32VectorValue | DdbDeci
|
|
|
181
182
|
export type DdbValue = DdbScalarValue | DdbVectorValue | DdbMatrixValue | DdbDictValue | DdbChartValue;
|
|
182
183
|
export type DdbStringObj = DdbObj<string>;
|
|
183
184
|
export type DdbVectorObj<TValue extends DdbVectorValue = DdbVectorValue> = DdbObj<TValue>;
|
|
184
|
-
export type DdbVectorAnyObj =
|
|
185
|
-
export type DdbVectorStringObj =
|
|
185
|
+
export type DdbVectorAnyObj = DdbVectorObj<DdbObj[]>;
|
|
186
|
+
export type DdbVectorStringObj = DdbVectorObj<string[]>;
|
|
186
187
|
export type DdbTableObj<TColumns extends DdbVectorObj[] = DdbVectorObj[]> = DdbObj<TColumns>;
|
|
187
188
|
export type DdbDictObj<TKeys extends DdbVectorObj = DdbVectorObj, TValues extends DdbVectorObj = DdbVectorObj> = DdbObj<[TKeys, TValues]>;
|
|
188
189
|
export type DdbMatrixObj<TValue extends DdbMatrixValue = DdbMatrixValue> = DdbObj<TValue>;
|
|
@@ -471,8 +472,9 @@ export interface DdbRpcOptions {
|
|
|
471
472
|
}
|
|
472
473
|
export declare class DdbConnectionError extends Error {
|
|
473
474
|
name: string;
|
|
475
|
+
cause?: WebSocketConnectionError;
|
|
474
476
|
ddb: DDB;
|
|
475
|
-
constructor(ddb: DDB,
|
|
477
|
+
constructor(ddb: DDB, error?: WebSocketConnectionError);
|
|
476
478
|
}
|
|
477
479
|
export declare class DdbDatabaseError extends Error {
|
|
478
480
|
name: string;
|
|
@@ -506,6 +508,8 @@ export declare class DDB {
|
|
|
506
508
|
python: boolean;
|
|
507
509
|
/** 是否为流数据连接,非流数据这个字段恒为 null Whether it is a streaming data connection, this field is always null for non-streaming data */
|
|
508
510
|
streaming: StreamingData;
|
|
511
|
+
/** 是否打印每个 rpc 的信息用于调试 */
|
|
512
|
+
verbose: boolean;
|
|
509
513
|
print_message_buffer: boolean;
|
|
510
514
|
print_object_buffer: boolean;
|
|
511
515
|
print_message: boolean;
|
|
@@ -528,6 +532,7 @@ export declare class DDB {
|
|
|
528
532
|
- password?: DolphinDB 登录密码,默认 `'123456'` DolphinDB password, default `'123456'`
|
|
529
533
|
- python?: 设置 python session flag,默认 `false` set python session flag, default `false`
|
|
530
534
|
- streaming?: 设置该选项后,该 WebSocket 连接只用于流数据 When this option is set, the WebSocket connection is only used for streaming data
|
|
535
|
+
- verbose?: 是否打印每个 rpc 的信息用于调试
|
|
531
536
|
|
|
532
537
|
@example
|
|
533
538
|
let ddb = new DDB('ws://127.0.0.1:8848')
|
|
@@ -546,8 +551,10 @@ export declare class DDB {
|
|
|
546
551
|
password?: string;
|
|
547
552
|
python?: boolean;
|
|
548
553
|
streaming?: StreamingParams;
|
|
554
|
+
verbose?: boolean;
|
|
549
555
|
});
|
|
550
556
|
private on_message;
|
|
557
|
+
private on_error;
|
|
551
558
|
/** 建立实际的 WebSocket 连接到 URL 对应的 DolphinDB Establish a actual websocket connection to the DolphindB corresponding to the URL
|
|
552
559
|
是幂等的,调用后会确保已连接到数据库 (确保 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
|
|
553
560
|
this.autologin 为 true 时自动登录 this.autologin automatically log in when it is true */
|
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, defer } from 'xshell/utils.browser.js';
|
|
9
|
-
import { connect_websocket
|
|
9
|
+
import { connect_websocket } from 'xshell/net.browser.js';
|
|
10
10
|
import { t } from './i18n/index.js';
|
|
11
11
|
export var DdbForm;
|
|
12
12
|
(function (DdbForm) {
|
|
@@ -2150,12 +2150,12 @@ export function int1282str(buffer, le = true) {
|
|
|
2150
2150
|
export const winsize = 10_0000;
|
|
2151
2151
|
export class DdbConnectionError extends Error {
|
|
2152
2152
|
name = 'DdbConnectionError';
|
|
2153
|
+
cause;
|
|
2153
2154
|
ddb;
|
|
2154
|
-
constructor(ddb,
|
|
2155
|
-
super(
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
`${ddb.url} ${t('连接出错了,可能由于网络原因连接已被关闭,或服务器断开连接')}`, error_options);
|
|
2155
|
+
constructor(ddb, error) {
|
|
2156
|
+
super(error?.message || `${ddb.url} ${t('连接出错了,可能由于网络原因连接已被关闭,或服务器断开连接')}`, { cause: error });
|
|
2157
|
+
if (error)
|
|
2158
|
+
this.cause = error;
|
|
2159
2159
|
this.ddb = ddb;
|
|
2160
2160
|
}
|
|
2161
2161
|
}
|
|
@@ -2196,6 +2196,8 @@ export class DDB {
|
|
|
2196
2196
|
python = false;
|
|
2197
2197
|
/** 是否为流数据连接,非流数据这个字段恒为 null Whether it is a streaming data connection, this field is always null for non-streaming data */
|
|
2198
2198
|
streaming = null;
|
|
2199
|
+
/** 是否打印每个 rpc 的信息用于调试 */
|
|
2200
|
+
verbose = false;
|
|
2199
2201
|
// --- 内部选项, 状态
|
|
2200
2202
|
print_message_buffer = false;
|
|
2201
2203
|
print_object_buffer = false;
|
|
@@ -2221,6 +2223,7 @@ export class DDB {
|
|
|
2221
2223
|
- password?: DolphinDB 登录密码,默认 `'123456'` DolphinDB password, default `'123456'`
|
|
2222
2224
|
- python?: 设置 python session flag,默认 `false` set python session flag, default `false`
|
|
2223
2225
|
- streaming?: 设置该选项后,该 WebSocket 连接只用于流数据 When this option is set, the WebSocket connection is only used for streaming data
|
|
2226
|
+
- verbose?: 是否打印每个 rpc 的信息用于调试
|
|
2224
2227
|
|
|
2225
2228
|
@example
|
|
2226
2229
|
let ddb = new DDB('ws://127.0.0.1:8848')
|
|
@@ -2234,14 +2237,20 @@ export class DDB {
|
|
|
2234
2237
|
})
|
|
2235
2238
|
*/
|
|
2236
2239
|
constructor(url, options = {}) {
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2240
|
+
const _url = new URL(location.href);
|
|
2241
|
+
const { searchParams, pathname } = _url;
|
|
2242
|
+
if (url)
|
|
2243
|
+
this.url = url;
|
|
2244
|
+
else {
|
|
2245
|
+
const dev = pathname.endsWith('/console/');
|
|
2246
|
+
const hostname = searchParams.get('hostname') || (dev ? '127.0.0.1' : location.hostname);
|
|
2247
|
+
const port = searchParams.get('port') || (dev ? '8848' : location.port);
|
|
2248
|
+
url = `${dev ? (searchParams.get('tls') === '1' ? 'wss' : 'ws') : (location.protocol === 'https:' ? 'wss' : 'ws')}://${hostname}${port ? `:${port}` : ''}/`;
|
|
2243
2249
|
}
|
|
2244
|
-
this.
|
|
2250
|
+
this.verbose = options.verbose === undefined ?
|
|
2251
|
+
searchParams.get('verbose') === '1'
|
|
2252
|
+
:
|
|
2253
|
+
options.verbose;
|
|
2245
2254
|
if (options.autologin !== undefined)
|
|
2246
2255
|
this.autologin = options.autologin;
|
|
2247
2256
|
if (options.username !== undefined)
|
|
@@ -2253,8 +2262,11 @@ export class DDB {
|
|
|
2253
2262
|
if (options.streaming !== undefined)
|
|
2254
2263
|
this.streaming = options.streaming;
|
|
2255
2264
|
}
|
|
2256
|
-
on_message(buffer) {
|
|
2257
|
-
// 这里的实现一定会被 connect 中的实现覆盖
|
|
2265
|
+
on_message(buffer, websocket) {
|
|
2266
|
+
// 这里的实现一定会被 connect, rpc 中的实现覆盖
|
|
2267
|
+
}
|
|
2268
|
+
on_error(error, websocket) {
|
|
2269
|
+
// 这里的实现一定会被 connect, rpc 中的实现覆盖
|
|
2258
2270
|
}
|
|
2259
2271
|
/** 建立实际的 WebSocket 连接到 URL 对应的 DolphinDB Establish a actual websocket connection to the DolphindB corresponding to the URL
|
|
2260
2272
|
是幂等的,调用后会确保已连接到数据库 (确保 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
|
|
@@ -2267,7 +2279,10 @@ export class DDB {
|
|
|
2267
2279
|
await ptail;
|
|
2268
2280
|
try {
|
|
2269
2281
|
if (!this.connected) {
|
|
2270
|
-
this.
|
|
2282
|
+
this.on_error = (error, websocket) => {
|
|
2283
|
+
pconnect.reject(new DdbConnectionError(this, error));
|
|
2284
|
+
};
|
|
2285
|
+
this.on_message = (buffer, websocket) => {
|
|
2271
2286
|
assert(false, t('这是在调用 this.rpc 之前默认的 on_message, 不应该被调用到,除非建立连接后 server 先推送了 message'));
|
|
2272
2287
|
};
|
|
2273
2288
|
this.presult = defer(null);
|
|
@@ -2280,16 +2295,16 @@ export class DDB {
|
|
|
2280
2295
|
if (this.python)
|
|
2281
2296
|
return 'python';
|
|
2282
2297
|
})(),
|
|
2283
|
-
on_message: (buffer) => {
|
|
2284
|
-
this.on_message(buffer);
|
|
2298
|
+
on_message: (buffer, websocket) => {
|
|
2299
|
+
this.on_message(buffer, websocket);
|
|
2300
|
+
},
|
|
2301
|
+
on_error: (error, websocket) => {
|
|
2302
|
+
this.on_error(error, websocket);
|
|
2285
2303
|
}
|
|
2286
2304
|
});
|
|
2287
2305
|
}
|
|
2288
2306
|
catch (error) {
|
|
2289
|
-
|
|
2290
|
-
throw new DdbConnectionError(this, { cause: error });
|
|
2291
|
-
else
|
|
2292
|
-
throw error;
|
|
2307
|
+
throw new DdbConnectionError(this, error);
|
|
2293
2308
|
}
|
|
2294
2309
|
if (this.streaming)
|
|
2295
2310
|
await this.subscribe();
|
|
@@ -2418,6 +2433,13 @@ export class DDB {
|
|
|
2418
2433
|
}
|
|
2419
2434
|
catch { }
|
|
2420
2435
|
// 临界区结束,只有一个 rpc 函数调用运行到这里,可以独占 this.on_message 然后写 WebSocket
|
|
2436
|
+
if (!this.connected) {
|
|
2437
|
+
presult.reject(new DdbConnectionError(this));
|
|
2438
|
+
return presult;
|
|
2439
|
+
}
|
|
2440
|
+
this.on_error = (error, websocket) => {
|
|
2441
|
+
presult.reject(new DdbConnectionError(this, error));
|
|
2442
|
+
};
|
|
2421
2443
|
this.on_message = buffer => {
|
|
2422
2444
|
try {
|
|
2423
2445
|
const buf = new Uint8Array(buffer);
|
|
@@ -2449,19 +2471,28 @@ export class DDB {
|
|
|
2449
2471
|
const command = this.enc.encode((() => {
|
|
2450
2472
|
switch (type) {
|
|
2451
2473
|
case 'function':
|
|
2474
|
+
if (this.verbose)
|
|
2475
|
+
console.log(func + args.map(arg => arg.toString()).join(', ').bracket());
|
|
2452
2476
|
return 'function\n' +
|
|
2453
2477
|
`${func}\n` +
|
|
2454
2478
|
`${args.length}\n` +
|
|
2455
2479
|
`${Number(DDB.le_client)}\n`;
|
|
2456
2480
|
case 'script':
|
|
2481
|
+
if (this.verbose)
|
|
2482
|
+
console.log(script);
|
|
2457
2483
|
return 'script\n' +
|
|
2458
2484
|
script;
|
|
2459
2485
|
case 'variable':
|
|
2486
|
+
if (this.verbose)
|
|
2487
|
+
for (let i = 0; i < vars.length; i++)
|
|
2488
|
+
console.log(`${vars[i]} = ${args[i].toString()}`);
|
|
2460
2489
|
return 'variable\n' +
|
|
2461
2490
|
`${vars.join(',')}\n` +
|
|
2462
2491
|
`${vars.length}\n` +
|
|
2463
2492
|
`${Number(DDB.le_client)}\n`;
|
|
2464
2493
|
case 'connect':
|
|
2494
|
+
if (this.verbose)
|
|
2495
|
+
console.log('connect()');
|
|
2465
2496
|
return 'connect\n';
|
|
2466
2497
|
}
|
|
2467
2498
|
})());
|