dolphindb 2.0.914 → 2.0.916
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 +40 -27
- package/browser.js +35 -20
- package/browser.js.map +1 -1
- package/docs.en.json +166 -29
- package/docs.zh.json +115 -26
- package/index.d.ts +33 -21
- package/index.js +38 -25
- package/index.js.map +1 -1
- package/package.json +4 -5
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 } from 'xshell';
|
|
4
4
|
export declare enum DdbForm {
|
|
5
5
|
scalar = 0,
|
|
6
6
|
vector = 1,
|
|
@@ -17,8 +17,8 @@ export declare enum DdbForm {
|
|
|
17
17
|
object = 9
|
|
18
18
|
}
|
|
19
19
|
/** DolphinDB DataType
|
|
20
|
-
对应的 array vector 类型为 64 + 基本类型
|
|
21
|
-
对应的 extended 类型为 128 + 基本类型
|
|
20
|
+
对应的 array vector 类型为 64 + 基本类型 The corresponding array vector type is 64 + base type
|
|
21
|
+
对应的 extended 类型为 128 + 基本类型 The corresponding extended type is 128 + base type
|
|
22
22
|
*/
|
|
23
23
|
export declare enum DdbType {
|
|
24
24
|
void = 0,
|
|
@@ -181,6 +181,7 @@ Uint8Array[] | // blob
|
|
|
181
181
|
DdbObj[] | // any
|
|
182
182
|
DdbSymbolExtendedValue | DdbArrayVectorValue | DdbDecimal32VectorValue | DdbDecimal64VectorValue;
|
|
183
183
|
export type DdbValue = DdbScalarValue | DdbVectorValue | DdbMatrixValue | DdbDictValue | DdbChartValue;
|
|
184
|
+
export type DdbStringObj = DdbObj<string>;
|
|
184
185
|
export type DdbVectorObj = DdbObj<DdbVectorValue>;
|
|
185
186
|
export type DdbVectorAnyObj = DdbObj<DdbObj[]>;
|
|
186
187
|
export type DdbVectorStringObj = DdbObj<string[]>;
|
|
@@ -230,7 +231,8 @@ export declare class DdbObj<TValue extends DdbValue = DdbValue> {
|
|
|
230
231
|
rows?: number;
|
|
231
232
|
/** 第 2 维 */
|
|
232
233
|
cols?: number;
|
|
233
|
-
/** 实际数据。不同的 DdbForm, DdbType 使用 DdbValue 中不同的类型来表示实际数据
|
|
234
|
+
/** 实际数据。不同的 DdbForm, DdbType 使用 DdbValue 中不同的类型来表示实际数据
|
|
235
|
+
The actual data. Different DdbForm, DdbType use different types in DdbValue to represent actual data */
|
|
234
236
|
value: TValue;
|
|
235
237
|
/** 原始二进制数据,仅在 parse_object 为 false 时通过 parse_message 生成的顶层对象有这个属性 */
|
|
236
238
|
buffer?: Uint8Array;
|
|
@@ -258,7 +260,7 @@ export declare class DdbObj<TValue extends DdbValue = DdbValue> {
|
|
|
258
260
|
/** 转换 js 数组为 DdbObj[] */
|
|
259
261
|
static to_ddbobjs(values: any[]): DdbObj<DdbValue>[];
|
|
260
262
|
to_rows<T extends Record<string, any> = Record<string, any>>(): T[];
|
|
261
|
-
/** 将 dict<string, any> 自动转换为 js object (Record<string, any>) convert dict<string, any> to js object (Record<string, any>)
|
|
263
|
+
/** 将 dict<string, any> 自动转换为 js object (Record<string, any>) Automatically convert dict<string, any> to js object (Record<string, any>)
|
|
262
264
|
- options?:
|
|
263
265
|
- strip?: `false` 是否将 DdbObj 中的 value 直接提取、剥离出来作为 js object 的 value (丢弃 DdbObj 中的其余信息,只保留 value)
|
|
264
266
|
Whether to directly extract and strip the value in DdbObj as the value of js object (discard the rest of the information in DdbObj, only keep the value)
|
|
@@ -442,9 +444,25 @@ export interface StreamingData extends StreamingParams {
|
|
|
442
444
|
error?: Error;
|
|
443
445
|
}
|
|
444
446
|
export declare const winsize: 100000;
|
|
445
|
-
|
|
447
|
+
type DdbRpcType = 'script' | 'function' | 'variable' | 'connect';
|
|
448
|
+
export interface DdbRpcOptions {
|
|
449
|
+
script?: string;
|
|
450
|
+
func?: string;
|
|
451
|
+
args?: (DdbObj | string | boolean)[];
|
|
452
|
+
vars?: string[];
|
|
453
|
+
urgent?: boolean;
|
|
454
|
+
listener?: DdbMessageListener;
|
|
455
|
+
parse_object?: boolean;
|
|
456
|
+
}
|
|
457
|
+
export declare class DdbConnectionError extends Error {
|
|
446
458
|
ddb: DDB;
|
|
447
|
-
constructor(ddb: DDB);
|
|
459
|
+
constructor(ddb: DDB, error_options?: ErrorOptions);
|
|
460
|
+
}
|
|
461
|
+
export declare class DdbDatabaseError extends Error {
|
|
462
|
+
ddb: DDB;
|
|
463
|
+
type: DdbRpcType;
|
|
464
|
+
options: DdbRpcOptions;
|
|
465
|
+
constructor(message: string, ddb: DDB, type: DdbRpcType, options: DdbRpcOptions);
|
|
448
466
|
}
|
|
449
467
|
export declare class DDB {
|
|
450
468
|
/** 当前的 session id (http 或 tcp) */
|
|
@@ -541,7 +559,8 @@ export declare class DDB {
|
|
|
541
559
|
}): string;
|
|
542
560
|
disconnect(): void;
|
|
543
561
|
/** rpc through websocket (function/script/variable command)
|
|
544
|
-
未连接到 DDB 时调用会自动连接,连接断开时调用会抛出
|
|
562
|
+
未连接到 DDB 时调用会自动连接,连接断开时调用会抛出 DdbConnectionError
|
|
563
|
+
When the DDB is not connected, the call will be automatically connected. When the connection is disconnected, the call will throw the DdbConnectionError
|
|
545
564
|
- type: API 类型: 'script' | 'function' | 'variable'
|
|
546
565
|
- options:
|
|
547
566
|
- urgent?: 决定 `行为标识` 那一行字符串的取值(只适用于 script 和 function)
|
|
@@ -550,22 +569,13 @@ export declare class DDB {
|
|
|
550
569
|
- parse_object?: 在本次 rpc 期间设置 parse_object, 结束后恢复原有
|
|
551
570
|
为 false 时返回的 DdbObj 仅含有 buffer 和 le,不做解析,以便后续转发、序列化
|
|
552
571
|
*/
|
|
553
|
-
rpc<T extends DdbObj = DdbObj>(type:
|
|
554
|
-
script?: string;
|
|
555
|
-
func?: string;
|
|
556
|
-
args?: (DdbObj | string | boolean)[];
|
|
557
|
-
vars?: string[];
|
|
558
|
-
urgent?: boolean;
|
|
559
|
-
listener?: DdbMessageListener;
|
|
560
|
-
parse_object?: boolean;
|
|
561
|
-
}): Promise<T>;
|
|
572
|
+
rpc<T extends DdbObj = DdbObj>(type: DdbRpcType, options: DdbRpcOptions): Promise<T>;
|
|
562
573
|
/** eval script through websocket (script command)
|
|
563
574
|
- script?: 执行的脚本 Script to execute
|
|
564
575
|
- options?: 执行选项 execution options
|
|
565
576
|
- urgent?: 紧急 flag,确保提交的脚本使用 urgent worker 处理,防止被其它作业阻塞
|
|
566
577
|
Urgent flag to ensure that submitted scripts are processed by urgent workers to prevent being blocked by other jobs
|
|
567
|
-
- listener?: 处理本次 rpc 期间的消息 (DdbMessage)
|
|
568
|
-
Process messages during this rpc (DdbMessage)
|
|
578
|
+
- listener?: 处理本次 rpc 期间的消息 (DdbMessage) Process messages during this rpc (DdbMessage)
|
|
569
579
|
- parse_object?: 在该次 rpc 期间设置 parse_object, 结束后恢复原有,为 false 时返回的 DdbObj 仅含有 buffer 和 le,
|
|
570
580
|
不做解析,以便后续转发、序列化
|
|
571
581
|
Set parse_object during this rpc, and restore the original after the end.
|
|
@@ -579,7 +589,8 @@ export declare class DDB {
|
|
|
579
589
|
}): Promise<T>;
|
|
580
590
|
/** call function through websocket (function command)
|
|
581
591
|
- func: 函数名 function name
|
|
582
|
-
- args?: `[ ]` 调用参数 (传入的原生 string 和 boolean 会被自动转换为 DdbObj<string> 和 DdbObj<boolean>)
|
|
592
|
+
- args?: `[ ]` 调用参数 (传入的原生 string 和 boolean 会被自动转换为 DdbObj<string> 和 DdbObj<boolean>)
|
|
593
|
+
Call parameters (the incoming native string and boolean will be automatically converted to DdbObj<string> and DdbObj<boolean>)
|
|
583
594
|
- options?: 调用选项 call options
|
|
584
595
|
- urgent?: 紧急 flag。使用 urgent worker 执行,防止被其它作业阻塞
|
|
585
596
|
Emergency flag. Use urgent worker execution to prevent being blocked by other jobs
|
|
@@ -620,7 +631,7 @@ export declare class DDB {
|
|
|
620
631
|
/** 取消当前 session id 对应的所有 console jobs Cancel all console jobs corresponding to the current session id */
|
|
621
632
|
cancel(): Promise<void>;
|
|
622
633
|
/** 解析服务端响应报文,返回去掉 header 的 data buf */
|
|
623
|
-
parse_message(buf: Uint8Array,
|
|
634
|
+
parse_message(buf: Uint8Array, error: DdbDatabaseError): DdbMessage;
|
|
624
635
|
/** 内部的流订阅方法 Internal stream subscription method */
|
|
625
636
|
subscribe(): Promise<StreamingData>;
|
|
626
637
|
}
|
|
@@ -640,3 +651,4 @@ export interface DdbErrorMessage {
|
|
|
640
651
|
data: Error;
|
|
641
652
|
}
|
|
642
653
|
export type DdbMessage = DdbPrintMessage | DdbObjectMessage | DdbErrorMessage;
|
|
654
|
+
export {};
|
package/index.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
// import { table, getBorderCharacters, type TableUserConfig } from 'table'
|
|
2
|
-
import { WebSocket } from 'ws';
|
|
3
2
|
import dayjs from 'dayjs';
|
|
4
3
|
import DayjsCustomParseFormat from 'dayjs/plugin/customParseFormat.js';
|
|
5
4
|
dayjs.extend(DayjsCustomParseFormat);
|
|
6
5
|
import ipaddrjs from 'ipaddr.js';
|
|
7
6
|
const { fromByteArray: buf2ipaddr } = ipaddrjs;
|
|
8
|
-
import { concat, assert, inspect, typed_array_to_buffer } from 'xshell
|
|
9
|
-
import { connect_websocket } from 'xshell/net.js';
|
|
7
|
+
import { concat, assert, inspect, typed_array_to_buffer, connect_websocket, WebSocket } from 'xshell';
|
|
10
8
|
import { t } from './i18n/index.js';
|
|
11
9
|
export var DdbForm;
|
|
12
10
|
(function (DdbForm) {
|
|
@@ -25,8 +23,8 @@ export var DdbForm;
|
|
|
25
23
|
DdbForm[DdbForm["object"] = 9] = "object";
|
|
26
24
|
})(DdbForm = DdbForm || (DdbForm = {}));
|
|
27
25
|
/** DolphinDB DataType
|
|
28
|
-
对应的 array vector 类型为 64 + 基本类型
|
|
29
|
-
对应的 extended 类型为 128 + 基本类型
|
|
26
|
+
对应的 array vector 类型为 64 + 基本类型 The corresponding array vector type is 64 + base type
|
|
27
|
+
对应的 extended 类型为 128 + 基本类型 The corresponding extended type is 128 + base type
|
|
30
28
|
*/
|
|
31
29
|
export var DdbType;
|
|
32
30
|
(function (DdbType) {
|
|
@@ -152,7 +150,8 @@ export class DdbObj {
|
|
|
152
150
|
rows;
|
|
153
151
|
/** 第 2 维 */
|
|
154
152
|
cols;
|
|
155
|
-
/** 实际数据。不同的 DdbForm, DdbType 使用 DdbValue 中不同的类型来表示实际数据
|
|
153
|
+
/** 实际数据。不同的 DdbForm, DdbType 使用 DdbValue 中不同的类型来表示实际数据
|
|
154
|
+
The actual data. Different DdbForm, DdbType use different types in DdbValue to represent actual data */
|
|
156
155
|
value;
|
|
157
156
|
/** 原始二进制数据,仅在 parse_object 为 false 时通过 parse_message 生成的顶层对象有这个属性 */
|
|
158
157
|
buffer;
|
|
@@ -959,7 +958,7 @@ export class DdbObj {
|
|
|
959
958
|
];
|
|
960
959
|
}
|
|
961
960
|
default:
|
|
962
|
-
throw new Error(
|
|
961
|
+
throw new Error(t('vector {{type}} 暂不支持序列化', { type: DdbType[type] || type }));
|
|
963
962
|
}
|
|
964
963
|
})();
|
|
965
964
|
if (!body)
|
|
@@ -1051,7 +1050,7 @@ export class DdbObj {
|
|
|
1051
1050
|
return [Int32Array.of(scale), data];
|
|
1052
1051
|
}
|
|
1053
1052
|
default:
|
|
1054
|
-
throw new Error(t('vector {{type}} 暂不支持序列化', { type: DdbType[type] || type }));
|
|
1053
|
+
throw new Error(t('vector {{type}} 暂不支持序列化', { type: String(DdbType[type] || type) }));
|
|
1055
1054
|
}
|
|
1056
1055
|
}
|
|
1057
1056
|
[inspect.custom](depth, _options, _inspect) {
|
|
@@ -2106,13 +2105,24 @@ export function int1282str(buffer, le = true) {
|
|
|
2106
2105
|
.padStart(2, '0')).join('');
|
|
2107
2106
|
}
|
|
2108
2107
|
export const winsize = 10_0000;
|
|
2109
|
-
export class
|
|
2108
|
+
export class DdbConnectionError extends Error {
|
|
2110
2109
|
ddb;
|
|
2111
|
-
constructor(ddb) {
|
|
2112
|
-
super(`${ddb.url} ${t('已断开')}
|
|
2110
|
+
constructor(ddb, error_options) {
|
|
2111
|
+
super(`${ddb.url} ${t('已断开')}`, error_options);
|
|
2113
2112
|
this.ddb = ddb;
|
|
2114
2113
|
}
|
|
2115
2114
|
}
|
|
2115
|
+
export class DdbDatabaseError extends Error {
|
|
2116
|
+
ddb;
|
|
2117
|
+
type;
|
|
2118
|
+
options;
|
|
2119
|
+
constructor(message, ddb, type, options) {
|
|
2120
|
+
super(message);
|
|
2121
|
+
this.ddb = ddb;
|
|
2122
|
+
this.type = type;
|
|
2123
|
+
this.options = options;
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2116
2126
|
export class DDB {
|
|
2117
2127
|
/** 当前的 session id (http 或 tcp) */
|
|
2118
2128
|
sid = '0';
|
|
@@ -2274,7 +2284,8 @@ export class DDB {
|
|
|
2274
2284
|
this.websocket.close(1000);
|
|
2275
2285
|
}
|
|
2276
2286
|
/** rpc through websocket (function/script/variable command)
|
|
2277
|
-
未连接到 DDB 时调用会自动连接,连接断开时调用会抛出
|
|
2287
|
+
未连接到 DDB 时调用会自动连接,连接断开时调用会抛出 DdbConnectionError
|
|
2288
|
+
When the DDB is not connected, the call will be automatically connected. When the connection is disconnected, the call will throw the DdbConnectionError
|
|
2278
2289
|
- type: API 类型: 'script' | 'function' | 'variable'
|
|
2279
2290
|
- options:
|
|
2280
2291
|
- urgent?: 决定 `行为标识` 那一行字符串的取值(只适用于 script 和 function)
|
|
@@ -2283,11 +2294,13 @@ export class DDB {
|
|
|
2283
2294
|
- parse_object?: 在本次 rpc 期间设置 parse_object, 结束后恢复原有
|
|
2284
2295
|
为 false 时返回的 DdbObj 仅含有 buffer 和 le,不做解析,以便后续转发、序列化
|
|
2285
2296
|
*/
|
|
2286
|
-
async rpc(type,
|
|
2297
|
+
async rpc(type, options) {
|
|
2287
2298
|
if (!this.websocket)
|
|
2288
2299
|
await this.connect();
|
|
2289
2300
|
if (!this.connected)
|
|
2290
|
-
throw new
|
|
2301
|
+
throw new DdbConnectionError(this);
|
|
2302
|
+
const { script, func, vars = [], urgent, listener, } = options;
|
|
2303
|
+
let { args = [] } = options;
|
|
2291
2304
|
if (func === 'pnode_run' && !this.pnode_run_defined) {
|
|
2292
2305
|
// 保证并发调用 rpc 时只定义一次 pnode_run
|
|
2293
2306
|
const ptail = this.ppnoderun;
|
|
@@ -2340,6 +2353,7 @@ export class DDB {
|
|
|
2340
2353
|
}
|
|
2341
2354
|
// this 上的当前配置需要在 message 到达后使用,先保存起来
|
|
2342
2355
|
const _handlers = [...this.listeners].reverse();
|
|
2356
|
+
let error = new DdbDatabaseError('', this, type, options);
|
|
2343
2357
|
// 临界区:保证多个 rpc 并发时形成 promise 链
|
|
2344
2358
|
// ddb 世界观:需要等待上一个 rpc 结果从 server 返回之后才能发起下一个调用
|
|
2345
2359
|
// 违反世界观可能造成:
|
|
@@ -2362,7 +2376,7 @@ export class DDB {
|
|
|
2362
2376
|
const buf = new Uint8Array(buffer);
|
|
2363
2377
|
if (this.print_message_buffer)
|
|
2364
2378
|
console.log(typed_array_to_buffer(buf));
|
|
2365
|
-
const message = this.parse_message(buf,
|
|
2379
|
+
const message = this.parse_message(buf, error);
|
|
2366
2380
|
listener?.(message, this);
|
|
2367
2381
|
for (const listener of _handlers)
|
|
2368
2382
|
listener(message, this);
|
|
@@ -2416,8 +2430,7 @@ export class DDB {
|
|
|
2416
2430
|
- options?: 执行选项 execution options
|
|
2417
2431
|
- urgent?: 紧急 flag,确保提交的脚本使用 urgent worker 处理,防止被其它作业阻塞
|
|
2418
2432
|
Urgent flag to ensure that submitted scripts are processed by urgent workers to prevent being blocked by other jobs
|
|
2419
|
-
- listener?: 处理本次 rpc 期间的消息 (DdbMessage)
|
|
2420
|
-
Process messages during this rpc (DdbMessage)
|
|
2433
|
+
- listener?: 处理本次 rpc 期间的消息 (DdbMessage) Process messages during this rpc (DdbMessage)
|
|
2421
2434
|
- parse_object?: 在该次 rpc 期间设置 parse_object, 结束后恢复原有,为 false 时返回的 DdbObj 仅含有 buffer 和 le,
|
|
2422
2435
|
不做解析,以便后续转发、序列化
|
|
2423
2436
|
Set parse_object during this rpc, and restore the original after the end.
|
|
@@ -2429,7 +2442,8 @@ export class DDB {
|
|
|
2429
2442
|
}
|
|
2430
2443
|
/** call function through websocket (function command)
|
|
2431
2444
|
- func: 函数名 function name
|
|
2432
|
-
- args?: `[ ]` 调用参数 (传入的原生 string 和 boolean 会被自动转换为 DdbObj<string> 和 DdbObj<boolean>)
|
|
2445
|
+
- args?: `[ ]` 调用参数 (传入的原生 string 和 boolean 会被自动转换为 DdbObj<string> 和 DdbObj<boolean>)
|
|
2446
|
+
Call parameters (the incoming native string and boolean will be automatically converted to DdbObj<string> and DdbObj<boolean>)
|
|
2433
2447
|
- options?: 调用选项 call options
|
|
2434
2448
|
- urgent?: 紧急 flag。使用 urgent worker 执行,防止被其它作业阻塞
|
|
2435
2449
|
Emergency flag. Use urgent worker execution to prevent being blocked by other jobs
|
|
@@ -2505,7 +2519,7 @@ export class DDB {
|
|
|
2505
2519
|
}
|
|
2506
2520
|
}
|
|
2507
2521
|
/** 解析服务端响应报文,返回去掉 header 的 data buf */
|
|
2508
|
-
parse_message(buf,
|
|
2522
|
+
parse_message(buf, error) {
|
|
2509
2523
|
// MSG\n
|
|
2510
2524
|
// <message>\0
|
|
2511
2525
|
// 'M'.codePointAt(0).to_hex_str()
|
|
@@ -2538,17 +2552,16 @@ export class DDB {
|
|
|
2538
2552
|
const ilf1 = buf.indexOf(0x0a, ils1); // '\n'
|
|
2539
2553
|
/** 'OK' 表示成功,其它文本表示失败 */
|
|
2540
2554
|
const message = this.dec.decode(buf.subarray(ils1, ilf1));
|
|
2541
|
-
if (message !== 'OK')
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
};
|
|
2555
|
+
if (message !== 'OK') {
|
|
2556
|
+
error.message = message;
|
|
2557
|
+
return { type: 'error', data: error };
|
|
2558
|
+
}
|
|
2546
2559
|
const bufobj = buf.subarray(ilf1 + 1);
|
|
2547
2560
|
if (this.print_object_buffer)
|
|
2548
2561
|
console.log(typed_array_to_buffer(bufobj));
|
|
2549
2562
|
return {
|
|
2550
2563
|
type: 'object',
|
|
2551
|
-
data: parse_object ?
|
|
2564
|
+
data: error.options.parse_object ?? this.parse_object ?
|
|
2552
2565
|
DdbObj.parse(bufobj, this.le)
|
|
2553
2566
|
:
|
|
2554
2567
|
new DdbObj({
|