dolphindb 2.0.1027 → 2.0.1029

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
@@ -330,6 +330,12 @@ export declare function int1282str(buffer: Uint8Array, le?: boolean): string;
330
330
  export interface StreamingParams {
331
331
  table: string;
332
332
  action?: string;
333
+ filters?: {
334
+ /** https://docs.dolphindb.cn/zh/help/FunctionsandCommands/FunctionReferences/s/subscribeTable.html#:~:text=%E8%BF%9E%E6%8E%A5%E6%96%B0%E7%9A%84%20leader%E3%80%82-,filter%20%E5%8F%82%E6%95%B0%E9%9C%80%E8%A6%81%E9%85%8D%E5%90%88,-setStreamTableFilterColumn%20%E5%87%BD%E6%95%B0%E4%B8%80%E8%B5%B7 */
335
+ column?: DdbObj;
336
+ /** 过滤条件的 DolphinDB 表达式 https://dolphindb1.atlassian.net/wiki/spaces/dev/pages/760840447/WebSocketConsole */
337
+ expression?: string;
338
+ };
333
339
  handler(message: StreamingMessage): any;
334
340
  }
335
341
  export interface StreamingMessage extends StreamingParams {
package/browser.js CHANGED
@@ -2291,8 +2291,11 @@ export class DDB {
2291
2291
  reject(this.error /* 一定有,不需要再 || new DdbConnectionError(this) */);
2292
2292
  };
2293
2293
  try {
2294
+ let url = new URL(this.url);
2295
+ if (this.streaming?.filters?.expression)
2296
+ url.searchParams.set('filter', this.streaming.filters.expression.trim());
2294
2297
  // 连接建立之前应该不会有别的调用占用 this.lwebsocket
2295
- this.lwebsocket.resource = await connect_websocket(this.url, {
2298
+ this.lwebsocket.resource = await connect_websocket(url, {
2296
2299
  protocols: this.streaming ? ['streaming'] : this.python ? ['python'] : undefined,
2297
2300
  on_message: (buffer, websocket) => {
2298
2301
  this.on_message(new Uint8Array(buffer), websocket);
@@ -2691,6 +2694,7 @@ export class DDB {
2691
2694
  segments: [],
2692
2695
  };
2693
2696
  let schema;
2697
+ let first_message = true;
2694
2698
  const { value: colnames } = await this.call('publishTable', [
2695
2699
  'localhost',
2696
2700
  new DdbInt(0),
@@ -2708,8 +2712,9 @@ export class DDB {
2708
2712
  const i_topic_end = buffer.indexOf(0, 17);
2709
2713
  // 首个 message 一定是 table schema, 后续消息是 column 片段组成的 any vector
2710
2714
  const data = DdbObj.parse(buffer.subarray(i_topic_end + 1), this.le);
2711
- if (data.form === DdbForm.table) {
2715
+ if (first_message) {
2712
2716
  schema = data;
2717
+ first_message = false;
2713
2718
  return;
2714
2719
  }
2715
2720
  assert(schema, t('流数据订阅后一定先返回 schema'));