dolphindb 2.0.1013 → 2.0.1015
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 +8 -6
- package/browser.js +29 -19
- package/browser.js.map +1 -1
- package/docs.en.json +9614 -526
- package/docs.zh.json +5541 -847
- package/index.d.ts +8 -6
- package/index.js +29 -19
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/test.js +21 -9
- package/test.js.map +1 -1
package/browser.d.ts
CHANGED
|
@@ -329,15 +329,17 @@ 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:
|
|
332
|
+
handler(message: StreamingMessage): any;
|
|
333
333
|
}
|
|
334
|
-
export interface
|
|
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;
|
|
338
338
|
/** message id */
|
|
339
339
|
id: bigint;
|
|
340
340
|
colnames: string[];
|
|
341
|
+
/** 最新的 server 有可能先推一个 table schema 过来 */
|
|
342
|
+
schema?: DdbTableObj;
|
|
341
343
|
/** 订阅主题,即一个订阅的名称。 Subscription topic, which is the name of a subscription.
|
|
342
344
|
它是一个字符串,由订阅表所在节点的别名、流数据表名称和订阅任务名称(如果指定了 actionName)组合而成,使用 `/` 分隔
|
|
343
345
|
It is a string consisting of the alias of the node where the subscription table is located, the stream data table name, and the subscription task name (if actionName is specified), separated by `/` */
|
|
@@ -426,7 +428,7 @@ export declare class DDB {
|
|
|
426
428
|
/** 表示本次会话执行的 SQL 标准 */
|
|
427
429
|
sql: SqlStandard;
|
|
428
430
|
/** 是否为流数据连接,非流数据这个字段恒为 null Whether it is a streaming data connection, this field is always null for non-streaming data */
|
|
429
|
-
streaming:
|
|
431
|
+
streaming: StreamingParams;
|
|
430
432
|
/** 是否打印每个 rpc 的信息用于调试 */
|
|
431
433
|
verbose: boolean;
|
|
432
434
|
print_message_buffer: boolean;
|
|
@@ -472,7 +474,7 @@ export declare class DDB {
|
|
|
472
474
|
constructor(url: string, options?: DdbOptions);
|
|
473
475
|
private on_message;
|
|
474
476
|
private on_error;
|
|
475
|
-
/** 调用后会确保和数据库的连接是正常的 (this.connected === true
|
|
477
|
+
/** 调用后会确保和数据库的连接是正常的 (this.connected === true),否则抛出错误
|
|
476
478
|
这个方法是幂等的,首次调用建立实际的 WebSocket 连接到 URL 对应的 DolphinDB,然后执行自动登录,
|
|
477
479
|
如果是流数据连接,还会调用 publishTable 订阅流表
|
|
478
480
|
后续调用检查上面的条件
|
|
@@ -481,7 +483,7 @@ export declare class DDB {
|
|
|
481
483
|
2. session 是有状态的,重连也无法恢复之前的状态
|
|
482
484
|
3. 断线后所有之前的 ddb.call, ddb.eval 都应该抛出连接错误
|
|
483
485
|
|
|
484
|
-
After calling, it will ensure that the connection with the database is normal (this.connected === true
|
|
486
|
+
After calling, it will ensure that the connection with the database is normal (this.connected === true), otherwise an error will be thrown
|
|
485
487
|
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
488
|
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
489
|
1. The on_error callback is bound to a certain websocket, and it is inconvenient to unbind and rebind
|
|
@@ -592,7 +594,7 @@ export declare class DDB {
|
|
|
592
594
|
/** 解析服务端响应报文,返回去掉 header 的 data buf */
|
|
593
595
|
parse_message(buf: Uint8Array, error: DdbDatabaseError): DdbMessage;
|
|
594
596
|
/** 内部的流订阅方法 Internal stream subscription method */
|
|
595
|
-
subscribe(): Promise<
|
|
597
|
+
subscribe(): Promise<void>;
|
|
596
598
|
}
|
|
597
599
|
export interface DdbMessageListener {
|
|
598
600
|
(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
|
|
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
|
|
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
|
-
|
|
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,30 @@ export class DDB {
|
|
|
2651
2649
|
// new DdbInt(-1), // offset
|
|
2652
2650
|
// filter
|
|
2653
2651
|
// allow exists
|
|
2654
|
-
], { skip_connection_check: true })
|
|
2655
|
-
|
|
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
|
};
|
|
2661
|
+
let schema;
|
|
2660
2662
|
// 先准备好收到 websocket message 的 callback
|
|
2661
2663
|
this.on_message = buffer => {
|
|
2662
|
-
// 复制一份,避免 handler 中异步直接使用传入的 streaming 这个对象时属性发生变化
|
|
2663
|
-
let streaming = { ...this.streaming, error: null };
|
|
2664
2664
|
try {
|
|
2665
2665
|
const dv = new DataView(buffer);
|
|
2666
2666
|
const buf = new Uint8Array(buffer);
|
|
2667
|
-
streaming.time = dv.getBigInt64(1, this.le);
|
|
2668
|
-
streaming.id = dv.getBigInt64(9, this.le);
|
|
2669
2667
|
const i_topic_end = buf.indexOf(0, 17);
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2668
|
+
// 首个 message 可能是 table schema, 后续消息是 column 片段组成的 any vector
|
|
2669
|
+
const data = DdbObj.parse(buf.subarray(i_topic_end + 1), this.le);
|
|
2670
|
+
if (data.form === DdbForm.table) {
|
|
2671
|
+
schema = data;
|
|
2672
|
+
return;
|
|
2673
|
+
}
|
|
2674
|
+
const { rows } = data.value[0];
|
|
2675
|
+
win.rows += rows;
|
|
2675
2676
|
win.segments.push(data);
|
|
2676
2677
|
if (win.rows >= winsize * 2 && win.segments.length >= 2) {
|
|
2677
2678
|
let winsize_ = 0;
|
|
@@ -2683,14 +2684,23 @@ export class DDB {
|
|
|
2683
2684
|
win.offset += win.rows - winsize_;
|
|
2684
2685
|
win.rows = winsize_;
|
|
2685
2686
|
}
|
|
2687
|
+
this.streaming.handler({
|
|
2688
|
+
...this.streaming,
|
|
2689
|
+
id: dv.getBigInt64(9, this.le),
|
|
2690
|
+
time: dv.getBigInt64(1, this.le),
|
|
2691
|
+
rows,
|
|
2692
|
+
topic: this.dec.decode(buf.subarray(17, i_topic_end)),
|
|
2693
|
+
colnames,
|
|
2694
|
+
schema,
|
|
2695
|
+
data,
|
|
2696
|
+
window: win,
|
|
2697
|
+
});
|
|
2686
2698
|
}
|
|
2687
2699
|
catch (error) {
|
|
2688
2700
|
// 将 error 交给 handler 处理
|
|
2689
|
-
streaming.
|
|
2701
|
+
this.streaming.handler({ ...this.streaming, error });
|
|
2690
2702
|
}
|
|
2691
|
-
this.streaming.handler(streaming);
|
|
2692
2703
|
};
|
|
2693
|
-
return this.streaming;
|
|
2694
2704
|
}
|
|
2695
2705
|
}
|
|
2696
2706
|
//# sourceMappingURL=browser.js.map
|