dolphindb 2.0.915 → 2.0.917
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 +39 -27
- package/browser.js +35 -20
- package/browser.js.map +1 -1
- package/docs.en.json +90 -26
- package/docs.zh.json +112 -126
- package/index.d.ts +31 -20
- package/index.js +37 -22
- package/index.js.map +1 -1
- package/package.json +3 -3
package/browser.d.ts
CHANGED
|
@@ -8,14 +8,15 @@ export declare enum DdbForm {
|
|
|
8
8
|
dict = 5,
|
|
9
9
|
table = 6,
|
|
10
10
|
chart = 7,
|
|
11
|
-
/** 结点内部通信可能会使用,调用函数执行脚本一般不会返回这种类型
|
|
11
|
+
/** 结点内部通信可能会使用,调用函数执行脚本一般不会返回这种类型
|
|
12
|
+
Node internal communication may be used, calling function execution script generally does not return this type */
|
|
12
13
|
chunk = 8,
|
|
13
14
|
/** sysobj */
|
|
14
15
|
object = 9
|
|
15
16
|
}
|
|
16
17
|
/** DolphinDB DataType
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
对应的 array vector 类型为 64 + 基本类型 The corresponding array vector type is 64 + base type
|
|
19
|
+
对应的 extended 类型为 128 + 基本类型 The corresponding extended type is 128 + base type
|
|
19
20
|
*/
|
|
20
21
|
export declare enum DdbType {
|
|
21
22
|
void = 0,
|
|
@@ -96,13 +97,13 @@ export interface DdbDurationValue {
|
|
|
96
97
|
export interface DdbDecimal32Value {
|
|
97
98
|
/** int32, data 需要除以 10^scale 得到原值 data needs to be divided by 10^scale to get the original value */
|
|
98
99
|
scale: number;
|
|
99
|
-
/** int32, 空值为 null */
|
|
100
|
+
/** int32, 空值为 null ddb null is js null */
|
|
100
101
|
data: number | null;
|
|
101
102
|
}
|
|
102
103
|
export interface DdbDecimal64Value {
|
|
103
104
|
/** int32, data 需要除以 10^scale 得到原值 data needs to be divided by 10^scale to get the original value */
|
|
104
105
|
scale: number;
|
|
105
|
-
/** int64, 空值为 null */
|
|
106
|
+
/** int64, 空值为 null empty value is null */
|
|
106
107
|
data: bigint | null;
|
|
107
108
|
}
|
|
108
109
|
export interface DdbDecimal32VectorValue {
|
|
@@ -145,7 +146,7 @@ export declare enum DdbChartType {
|
|
|
145
146
|
kline = 8
|
|
146
147
|
}
|
|
147
148
|
export interface DdbChartValue {
|
|
148
|
-
/** 原属性 chartType */
|
|
149
|
+
/** 原属性 chartType original: chartType */
|
|
149
150
|
type: DdbChartType;
|
|
150
151
|
stacking: boolean;
|
|
151
152
|
/** 直方图 (Histogram), plotHist 函数返回的 chart 可能具有该属性
|
|
@@ -196,7 +197,7 @@ export declare const nulls: {
|
|
|
196
197
|
readonly double: number;
|
|
197
198
|
readonly bytes16: Uint8Array;
|
|
198
199
|
};
|
|
199
|
-
/** 可以表示所有 DolphinDB 数据库中的数据类型 */
|
|
200
|
+
/** 可以表示所有 DolphinDB 数据库中的数据类型 Can represent data types in all DolphinDB databases */
|
|
200
201
|
export declare class DdbObj<TValue extends DdbValue = DdbValue> {
|
|
201
202
|
static dec: TextDecoder;
|
|
202
203
|
static enc: TextEncoder;
|
|
@@ -228,7 +229,8 @@ export declare class DdbObj<TValue extends DdbValue = DdbValue> {
|
|
|
228
229
|
rows?: number;
|
|
229
230
|
/** 第 2 维 */
|
|
230
231
|
cols?: number;
|
|
231
|
-
/** 实际数据。不同的 DdbForm, DdbType 使用 DdbValue 中不同的类型来表示实际数据
|
|
232
|
+
/** 实际数据。不同的 DdbForm, DdbType 使用 DdbValue 中不同的类型来表示实际数据
|
|
233
|
+
The actual data. Different DdbForm, DdbType use different types in DdbValue to represent actual data */
|
|
232
234
|
value: TValue;
|
|
233
235
|
/** 原始二进制数据,仅在 parse_object 为 false 时通过 parse_message 生成的顶层对象有这个属性 */
|
|
234
236
|
buffer?: Uint8Array;
|
|
@@ -262,11 +264,12 @@ export declare class DdbObj<TValue extends DdbValue = DdbValue> {
|
|
|
262
264
|
}[];
|
|
263
265
|
to_rows<T extends Record<string, any> = Record<string, any>>(): T[];
|
|
264
266
|
/** 将 dict<string, any> 自动转换为 js object (Record<string, any>) Automatically convert dict<string, any> to js object (Record<string, any>)
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
267
|
+
- options?:
|
|
268
|
+
- strip?: `false` 是否将 DdbObj 中的 value 直接提取、剥离出来作为 js object 的 value (丢弃 DdbObj 中的其余信息,只保留 value)
|
|
269
|
+
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)
|
|
270
|
+
- deep?: `false` 是否递归转换
|
|
271
|
+
Whether to convert recursively
|
|
272
|
+
*/
|
|
270
273
|
to_dict<T extends Record<string, DdbObj> = Record<string, DdbObj>>(): T;
|
|
271
274
|
to_dict<T extends Record<string, any> = Record<string, any>>(options: {
|
|
272
275
|
strip: true;
|
|
@@ -450,9 +453,25 @@ export interface StreamingData extends StreamingParams {
|
|
|
450
453
|
error?: Error;
|
|
451
454
|
}
|
|
452
455
|
export declare const winsize: 100000;
|
|
453
|
-
|
|
456
|
+
type DdbRpcType = 'script' | 'function' | 'variable' | 'connect';
|
|
457
|
+
export interface DdbRpcOptions {
|
|
458
|
+
script?: string;
|
|
459
|
+
func?: string;
|
|
460
|
+
args?: (DdbObj | string | boolean)[];
|
|
461
|
+
vars?: string[];
|
|
462
|
+
urgent?: boolean;
|
|
463
|
+
listener?: DdbMessageListener;
|
|
464
|
+
parse_object?: boolean;
|
|
465
|
+
}
|
|
466
|
+
export declare class DdbConnectionError extends Error {
|
|
467
|
+
ddb: DDB;
|
|
468
|
+
constructor(ddb: DDB, error_options?: ErrorOptions);
|
|
469
|
+
}
|
|
470
|
+
export declare class DdbDatabaseError extends Error {
|
|
454
471
|
ddb: DDB;
|
|
455
|
-
|
|
472
|
+
type: DdbRpcType;
|
|
473
|
+
options: DdbRpcOptions;
|
|
474
|
+
constructor(message: string, ddb: DDB, type: DdbRpcType, options: DdbRpcOptions);
|
|
456
475
|
}
|
|
457
476
|
export declare class DDB {
|
|
458
477
|
/** 当前的 session id (http 或 tcp) */
|
|
@@ -550,8 +569,8 @@ export declare class DDB {
|
|
|
550
569
|
}): string;
|
|
551
570
|
disconnect(): void;
|
|
552
571
|
/** rpc through websocket (function/script/variable command)
|
|
553
|
-
未连接到 DDB 时调用会自动连接,连接断开时调用会抛出
|
|
554
|
-
When the DDB is not connected, the call will be automatically connected. When the connection is disconnected, the call will throw the
|
|
572
|
+
未连接到 DDB 时调用会自动连接,连接断开时调用会抛出 DdbConnectionError
|
|
573
|
+
When the DDB is not connected, the call will be automatically connected. When the connection is disconnected, the call will throw the DdbConnectionError
|
|
555
574
|
- type: API 类型: 'script' | 'function' | 'variable'
|
|
556
575
|
- options:
|
|
557
576
|
- urgent?: 决定 `行为标识` 那一行字符串的取值(只适用于 script 和 function)
|
|
@@ -560,15 +579,7 @@ export declare class DDB {
|
|
|
560
579
|
- parse_object?: 在本次 rpc 期间设置 parse_object, 结束后恢复原有
|
|
561
580
|
为 false 时返回的 DdbObj 仅含有 buffer 和 le,不做解析,以便后续转发、序列化
|
|
562
581
|
*/
|
|
563
|
-
rpc<T extends DdbObj = DdbObj>(type:
|
|
564
|
-
script?: string;
|
|
565
|
-
func?: string;
|
|
566
|
-
args?: (DdbObj | string | boolean)[];
|
|
567
|
-
vars?: string[];
|
|
568
|
-
urgent?: boolean;
|
|
569
|
-
listener?: DdbMessageListener;
|
|
570
|
-
parse_object?: boolean;
|
|
571
|
-
}): Promise<T>;
|
|
582
|
+
rpc<T extends DdbObj = DdbObj>(type: DdbRpcType, options: DdbRpcOptions): Promise<T>;
|
|
572
583
|
/** eval script through websocket (script command)
|
|
573
584
|
- script?: 执行的脚本 Script to execute
|
|
574
585
|
- options?: 执行选项 execution options
|
|
@@ -630,7 +641,7 @@ export declare class DDB {
|
|
|
630
641
|
/** 取消当前 session id 对应的所有 console jobs Cancel all console jobs corresponding to the current session id */
|
|
631
642
|
cancel(): Promise<void>;
|
|
632
643
|
/** 解析服务端响应报文,返回去掉 header 的 data buf */
|
|
633
|
-
parse_message(buf: Uint8Array,
|
|
644
|
+
parse_message(buf: Uint8Array, error: DdbDatabaseError): DdbMessage;
|
|
634
645
|
/** 内部的流订阅方法 Internal stream subscription method */
|
|
635
646
|
subscribe(): Promise<StreamingData>;
|
|
636
647
|
}
|
|
@@ -651,3 +662,4 @@ export interface DdbErrorMessage {
|
|
|
651
662
|
}
|
|
652
663
|
export type DdbMessage = DdbPrintMessage | DdbObjectMessage | DdbErrorMessage;
|
|
653
664
|
export declare let ddb: DDB;
|
|
665
|
+
export {};
|
package/browser.js
CHANGED
|
@@ -18,14 +18,15 @@ export var DdbForm;
|
|
|
18
18
|
DdbForm[DdbForm["dict"] = 5] = "dict";
|
|
19
19
|
DdbForm[DdbForm["table"] = 6] = "table";
|
|
20
20
|
DdbForm[DdbForm["chart"] = 7] = "chart";
|
|
21
|
-
/** 结点内部通信可能会使用,调用函数执行脚本一般不会返回这种类型
|
|
21
|
+
/** 结点内部通信可能会使用,调用函数执行脚本一般不会返回这种类型
|
|
22
|
+
Node internal communication may be used, calling function execution script generally does not return this type */
|
|
22
23
|
DdbForm[DdbForm["chunk"] = 8] = "chunk";
|
|
23
24
|
/** sysobj */
|
|
24
25
|
DdbForm[DdbForm["object"] = 9] = "object";
|
|
25
26
|
})(DdbForm = DdbForm || (DdbForm = {}));
|
|
26
27
|
/** DolphinDB DataType
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
对应的 array vector 类型为 64 + 基本类型 The corresponding array vector type is 64 + base type
|
|
29
|
+
对应的 extended 类型为 128 + 基本类型 The corresponding extended type is 128 + base type
|
|
29
30
|
*/
|
|
30
31
|
export var DdbType;
|
|
31
32
|
(function (DdbType) {
|
|
@@ -119,7 +120,7 @@ export const nulls = {
|
|
|
119
120
|
double: -Number.MAX_VALUE,
|
|
120
121
|
bytes16: Uint8Array.from(new Array(16).fill(0))
|
|
121
122
|
};
|
|
122
|
-
/** 可以表示所有 DolphinDB 数据库中的数据类型 */
|
|
123
|
+
/** 可以表示所有 DolphinDB 数据库中的数据类型 Can represent data types in all DolphinDB databases */
|
|
123
124
|
export class DdbObj {
|
|
124
125
|
static dec = new TextDecoder('utf-8');
|
|
125
126
|
static enc = new TextEncoder();
|
|
@@ -151,7 +152,8 @@ export class DdbObj {
|
|
|
151
152
|
rows;
|
|
152
153
|
/** 第 2 维 */
|
|
153
154
|
cols;
|
|
154
|
-
/** 实际数据。不同的 DdbForm, DdbType 使用 DdbValue 中不同的类型来表示实际数据
|
|
155
|
+
/** 实际数据。不同的 DdbForm, DdbType 使用 DdbValue 中不同的类型来表示实际数据
|
|
156
|
+
The actual data. Different DdbForm, DdbType use different types in DdbValue to represent actual data */
|
|
155
157
|
value;
|
|
156
158
|
/** 原始二进制数据,仅在 parse_object 为 false 时通过 parse_message 生成的顶层对象有这个属性 */
|
|
157
159
|
buffer;
|
|
@@ -2119,13 +2121,24 @@ export function int1282str(buffer, le = true) {
|
|
|
2119
2121
|
.padStart(2, '0')).join('');
|
|
2120
2122
|
}
|
|
2121
2123
|
export const winsize = 10_0000;
|
|
2122
|
-
export class
|
|
2124
|
+
export class DdbConnectionError extends Error {
|
|
2123
2125
|
ddb;
|
|
2124
|
-
constructor(ddb) {
|
|
2125
|
-
super(`${ddb.url} ${t('已断开')}
|
|
2126
|
+
constructor(ddb, error_options) {
|
|
2127
|
+
super(`${ddb.url} ${t('已断开')}`, error_options);
|
|
2126
2128
|
this.ddb = ddb;
|
|
2127
2129
|
}
|
|
2128
2130
|
}
|
|
2131
|
+
export class DdbDatabaseError extends Error {
|
|
2132
|
+
ddb;
|
|
2133
|
+
type;
|
|
2134
|
+
options;
|
|
2135
|
+
constructor(message, ddb, type, options) {
|
|
2136
|
+
super(message);
|
|
2137
|
+
this.ddb = ddb;
|
|
2138
|
+
this.type = type;
|
|
2139
|
+
this.options = options;
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2129
2142
|
export class DDB {
|
|
2130
2143
|
/** 当前的 session id (http 或 tcp) */
|
|
2131
2144
|
sid = '0';
|
|
@@ -2290,8 +2303,8 @@ export class DDB {
|
|
|
2290
2303
|
this.websocket.close(1000);
|
|
2291
2304
|
}
|
|
2292
2305
|
/** rpc through websocket (function/script/variable command)
|
|
2293
|
-
未连接到 DDB 时调用会自动连接,连接断开时调用会抛出
|
|
2294
|
-
When the DDB is not connected, the call will be automatically connected. When the connection is disconnected, the call will throw the
|
|
2306
|
+
未连接到 DDB 时调用会自动连接,连接断开时调用会抛出 DdbConnectionError
|
|
2307
|
+
When the DDB is not connected, the call will be automatically connected. When the connection is disconnected, the call will throw the DdbConnectionError
|
|
2295
2308
|
- type: API 类型: 'script' | 'function' | 'variable'
|
|
2296
2309
|
- options:
|
|
2297
2310
|
- urgent?: 决定 `行为标识` 那一行字符串的取值(只适用于 script 和 function)
|
|
@@ -2300,11 +2313,13 @@ export class DDB {
|
|
|
2300
2313
|
- parse_object?: 在本次 rpc 期间设置 parse_object, 结束后恢复原有
|
|
2301
2314
|
为 false 时返回的 DdbObj 仅含有 buffer 和 le,不做解析,以便后续转发、序列化
|
|
2302
2315
|
*/
|
|
2303
|
-
async rpc(type,
|
|
2316
|
+
async rpc(type, options) {
|
|
2304
2317
|
if (!this.websocket)
|
|
2305
2318
|
await this.connect();
|
|
2306
2319
|
if (!this.connected)
|
|
2307
|
-
throw new
|
|
2320
|
+
throw new DdbConnectionError(this);
|
|
2321
|
+
const { script, func, vars = [], urgent, listener, } = options;
|
|
2322
|
+
let { args = [] } = options;
|
|
2308
2323
|
if (func === 'pnode_run' && !this.pnode_run_defined) {
|
|
2309
2324
|
// 保证并发调用 rpc 时只定义一次 pnode_run
|
|
2310
2325
|
const ptail = this.ppnoderun;
|
|
@@ -2357,6 +2372,7 @@ export class DDB {
|
|
|
2357
2372
|
}
|
|
2358
2373
|
// this 上的当前配置需要在 message 到达后使用,先保存起来
|
|
2359
2374
|
const _handlers = [...this.listeners].reverse();
|
|
2375
|
+
let error = new DdbDatabaseError('', this, type, options);
|
|
2360
2376
|
// 临界区:保证多个 rpc 并发时形成 promise 链
|
|
2361
2377
|
// ddb 世界观:需要等待上一个 rpc 结果从 server 返回之后才能发起下一个调用
|
|
2362
2378
|
// 违反世界观可能造成:
|
|
@@ -2379,7 +2395,7 @@ export class DDB {
|
|
|
2379
2395
|
const buf = new Uint8Array(buffer);
|
|
2380
2396
|
if (this.print_message_buffer)
|
|
2381
2397
|
console.log(buf);
|
|
2382
|
-
const message = this.parse_message(buf,
|
|
2398
|
+
const message = this.parse_message(buf, error);
|
|
2383
2399
|
listener?.(message, this);
|
|
2384
2400
|
for (const listener of _handlers)
|
|
2385
2401
|
listener(message, this);
|
|
@@ -2522,7 +2538,7 @@ export class DDB {
|
|
|
2522
2538
|
}
|
|
2523
2539
|
}
|
|
2524
2540
|
/** 解析服务端响应报文,返回去掉 header 的 data buf */
|
|
2525
|
-
parse_message(buf,
|
|
2541
|
+
parse_message(buf, error) {
|
|
2526
2542
|
// MSG\n
|
|
2527
2543
|
// <message>\0
|
|
2528
2544
|
// 'M'.codePointAt(0).to_hex_str()
|
|
@@ -2555,17 +2571,16 @@ export class DDB {
|
|
|
2555
2571
|
const ilf1 = buf.indexOf(0x0a, ils1); // '\n'
|
|
2556
2572
|
/** 'OK' 表示成功,其它文本表示失败 */
|
|
2557
2573
|
const message = this.dec.decode(buf.subarray(ils1, ilf1));
|
|
2558
|
-
if (message !== 'OK')
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
};
|
|
2574
|
+
if (message !== 'OK') {
|
|
2575
|
+
error.message = message;
|
|
2576
|
+
return { type: 'error', data: error };
|
|
2577
|
+
}
|
|
2563
2578
|
const bufobj = buf.subarray(ilf1 + 1);
|
|
2564
2579
|
if (this.print_object_buffer)
|
|
2565
2580
|
console.log(bufobj);
|
|
2566
2581
|
return {
|
|
2567
2582
|
type: 'object',
|
|
2568
|
-
data: parse_object ?
|
|
2583
|
+
data: error.options.parse_object ?? this.parse_object ?
|
|
2569
2584
|
DdbObj.parse(bufobj, this.le)
|
|
2570
2585
|
:
|
|
2571
2586
|
new DdbObj({
|