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