dolphindb 2.0.1013 → 2.0.1014

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
@@ -320,9 +320,9 @@ export declare function int1282str(buffer: Uint8Array, le?: boolean): string;
320
320
  export interface StreamingParams {
321
321
  table: string;
322
322
  action?: string;
323
- handler(message: StreamingData): any;
323
+ handler(message: StreamingMessage): any;
324
324
  }
325
- export interface StreamingData extends StreamingParams {
325
+ export interface StreamingMessage extends StreamingParams {
326
326
  /** server 发送消息的时间 (nano seconds since epoch) The time the server sent the message (nano seconds since epoch)
327
327
  std::chrono::system_clock::now().time_since_epoch() / std::chrono::nanoseconds(1) */
328
328
  time: bigint;
@@ -417,7 +417,7 @@ export declare class DDB {
417
417
  /** 表示本次会话执行的 SQL 标准 */
418
418
  sql: SqlStandard;
419
419
  /** 是否为流数据连接,非流数据这个字段恒为 null Whether it is a streaming data connection, this field is always null for non-streaming data */
420
- streaming: StreamingData;
420
+ streaming: StreamingParams;
421
421
  /** 是否打印每个 rpc 的信息用于调试 */
422
422
  verbose: boolean;
423
423
  print_message_buffer: boolean;
@@ -462,7 +462,7 @@ export declare class DDB {
462
462
  constructor(url: string, options?: DdbOptions);
463
463
  private on_message;
464
464
  private on_error;
465
- /** 调用后会确保和数据库的连接是正常的 (this.connected === true && this.errored === false),否则抛出错误
465
+ /** 调用后会确保和数据库的连接是正常的 (this.connected === true),否则抛出错误
466
466
  这个方法是幂等的,首次调用建立实际的 WebSocket 连接到 URL 对应的 DolphinDB,然后执行自动登录,
467
467
  如果是流数据连接,还会调用 publishTable 订阅流表
468
468
  后续调用检查上面的条件
@@ -471,7 +471,7 @@ export declare class DDB {
471
471
  2. session 是有状态的,重连也无法恢复之前的状态
472
472
  3. 断线后所有之前的 ddb.call, ddb.eval 都应该抛出连接错误
473
473
 
474
- After calling, it will ensure that the connection with the database is normal (this.connected === true && this.errored === false), otherwise an error will be thrown
474
+ After calling, it will ensure that the connection with the database is normal (this.connected === true), otherwise an error will be thrown
475
475
  This method is idempotent, the first call establishes an actual WebSocket connection to the DolphinDB corresponding to the URL, and subsequent calls check the above conditions
476
476
  After the connection is disconnected, it is forbidden to call connect again to reconnect the original ddb object. You should use new DDB() to create a new connection object because:
477
477
  1. The on_error callback is bound to a certain websocket, and it is inconvenient to unbind and rebind
@@ -582,7 +582,7 @@ export declare class DDB {
582
582
  /** 解析服务端响应报文,返回去掉 header 的 data buf */
583
583
  parse_message(buf: Uint8Array, error: DdbDatabaseError): DdbMessage;
584
584
  /** 内部的流订阅方法 Internal stream subscription method */
585
- subscribe(): Promise<StreamingData>;
585
+ subscribe(): Promise<void>;
586
586
  }
587
587
  export interface DdbMessageListener {
588
588
  (message: DdbMessage, _this: DDB): any;
package/index.js CHANGED
@@ -2219,7 +2219,7 @@ export class DDB {
2219
2219
  on_error() {
2220
2220
  // 这里的实现一定会被 connect, rpc 中的实现覆盖
2221
2221
  }
2222
- /** 调用后会确保和数据库的连接是正常的 (this.connected === true && this.errored === false),否则抛出错误
2222
+ /** 调用后会确保和数据库的连接是正常的 (this.connected === true),否则抛出错误
2223
2223
  这个方法是幂等的,首次调用建立实际的 WebSocket 连接到 URL 对应的 DolphinDB,然后执行自动登录,
2224
2224
  如果是流数据连接,还会调用 publishTable 订阅流表
2225
2225
  后续调用检查上面的条件
@@ -2228,7 +2228,7 @@ export class DDB {
2228
2228
  2. session 是有状态的,重连也无法恢复之前的状态
2229
2229
  3. 断线后所有之前的 ddb.call, ddb.eval 都应该抛出连接错误
2230
2230
 
2231
- After calling, it will ensure that the connection with the database is normal (this.connected === true && this.errored === false), otherwise an error will be thrown
2231
+ After calling, it will ensure that the connection with the database is normal (this.connected === true), otherwise an error will be thrown
2232
2232
  This method is idempotent, the first call establishes an actual WebSocket connection to the DolphinDB corresponding to the URL, and subsequent calls check the above conditions
2233
2233
  After the connection is disconnected, it is forbidden to call connect again to reconnect the original ddb object. You should use new DDB() to create a new connection object because:
2234
2234
  1. The on_error callback is bound to a certain websocket, and it is inconvenient to unbind and rebind
@@ -2640,9 +2640,7 @@ export class DDB {
2640
2640
  }
2641
2641
  /** 内部的流订阅方法 Internal stream subscription method */
2642
2642
  async subscribe() {
2643
- console.log(t('订阅流表成功') + ', colnames:',
2644
- // string[3](['time', 'stock', 'price'])
2645
- this.streaming.colnames = (await this.call('publishTable', [
2643
+ const { value: colnames } = await this.call('publishTable', [
2646
2644
  'localhost',
2647
2645
  new DdbInt(0),
2648
2646
  this.streaming.table,
@@ -2650,27 +2648,25 @@ export class DDB {
2650
2648
  // new DdbInt(-1), // offset
2651
2649
  // filter
2652
2650
  // allow exists
2653
- ], { skip_connection_check: true })).value);
2654
- this.streaming.window = {
2651
+ ], { skip_connection_check: true });
2652
+ console.log(t('订阅流表成功') + ', colnames:',
2653
+ // string[3](['time', 'stock', 'price'])
2654
+ colnames);
2655
+ let win = {
2655
2656
  offset: 0,
2656
2657
  rows: 0,
2657
2658
  segments: [],
2658
2659
  };
2659
2660
  // 先准备好收到 websocket message 的 callback
2660
2661
  this.on_message = buffer => {
2661
- // 复制一份,避免 handler 中异步直接使用传入的 streaming 这个对象时属性发生变化
2662
- let streaming = { ...this.streaming, error: null };
2663
2662
  try {
2664
2663
  const dv = new DataView(buffer);
2665
2664
  const buf = new Uint8Array(buffer);
2666
- streaming.time = dv.getBigInt64(1, this.le);
2667
- streaming.id = dv.getBigInt64(9, this.le);
2668
2665
  const i_topic_end = buf.indexOf(0, 17);
2669
- streaming.topic = this.dec.decode(buf.subarray(17, i_topic_end));
2670
2666
  // 是 column 片段组成的 any vector
2671
- const data = streaming.data = DdbObj.parse(buf.subarray(i_topic_end + 1), this.le);
2672
- let { window: win } = streaming;
2673
- win.rows += streaming.rows = data.value[0].rows;
2667
+ const data = DdbObj.parse(buf.subarray(i_topic_end + 1), this.le);
2668
+ const { rows } = data.value[0];
2669
+ win.rows += rows;
2674
2670
  win.segments.push(data);
2675
2671
  if (win.rows >= winsize * 2 && win.segments.length >= 2) {
2676
2672
  let winsize_ = 0;
@@ -2682,14 +2678,22 @@ export class DDB {
2682
2678
  win.offset += win.rows - winsize_;
2683
2679
  win.rows = winsize_;
2684
2680
  }
2681
+ this.streaming.handler({
2682
+ ...this.streaming,
2683
+ id: dv.getBigInt64(9, this.le),
2684
+ time: dv.getBigInt64(1, this.le),
2685
+ rows,
2686
+ topic: this.dec.decode(buf.subarray(17, i_topic_end)),
2687
+ colnames,
2688
+ data,
2689
+ window: win,
2690
+ });
2685
2691
  }
2686
2692
  catch (error) {
2687
2693
  // 将 error 交给 handler 处理
2688
- streaming.error = error;
2694
+ this.streaming.handler({ ...this.streaming, error });
2689
2695
  }
2690
- this.streaming.handler(streaming);
2691
2696
  };
2692
- return this.streaming;
2693
2697
  }
2694
2698
  }
2695
2699
  // const ddb_gateway = {