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