dolphindb 2.0.1012 → 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 +7 -9
- package/browser.js +30 -27
- package/browser.js.map +1 -1
- package/index.d.ts +7 -9
- package/index.js +30 -27
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/test.js +28 -9
- package/test.js.map +1 -1
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:
|
|
323
|
+
handler(message: StreamingMessage): any;
|
|
324
324
|
}
|
|
325
|
-
export interface
|
|
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:
|
|
420
|
+
streaming: StreamingParams;
|
|
421
421
|
/** 是否打印每个 rpc 的信息用于调试 */
|
|
422
422
|
verbose: boolean;
|
|
423
423
|
print_message_buffer: boolean;
|
|
@@ -427,8 +427,7 @@ export declare class DDB {
|
|
|
427
427
|
pnode_run_defined: boolean;
|
|
428
428
|
/** 在 websocket 收到的第一个 error 时,
|
|
429
429
|
在 connect_websocket 的 on_error 回调中构造 DdbConnectionError 并保存到 DDB 对象上,
|
|
430
|
-
这个 error 的错误信息最准确
|
|
431
|
-
this.errored 为 true 时建议 throw this.error || new DdbConnectionError(this) */
|
|
430
|
+
这个 error 的错误信息最准确 */
|
|
432
431
|
error: DdbConnectionError;
|
|
433
432
|
/** DdbMessage listeners */
|
|
434
433
|
listeners: DdbMessageListener[];
|
|
@@ -437,7 +436,6 @@ export declare class DDB {
|
|
|
437
436
|
/** 首次定义 pnode_run 的 promise,保证并发调用 rpc 时只定义一次 pnode_run */
|
|
438
437
|
ppnode_run: Promise<DdbVoid>;
|
|
439
438
|
get connected(): boolean;
|
|
440
|
-
get errored(): boolean;
|
|
441
439
|
/**
|
|
442
440
|
使用 WebSocket URL 初始化连接到 DolphinDB 的实例(不建立实际的网络连接)
|
|
443
441
|
Initialize an instance of DolphinDB Client using the WebSocket URL (without establishing an actual network connection)
|
|
@@ -464,7 +462,7 @@ export declare class DDB {
|
|
|
464
462
|
constructor(url: string, options?: DdbOptions);
|
|
465
463
|
private on_message;
|
|
466
464
|
private on_error;
|
|
467
|
-
/** 调用后会确保和数据库的连接是正常的 (this.connected === true
|
|
465
|
+
/** 调用后会确保和数据库的连接是正常的 (this.connected === true),否则抛出错误
|
|
468
466
|
这个方法是幂等的,首次调用建立实际的 WebSocket 连接到 URL 对应的 DolphinDB,然后执行自动登录,
|
|
469
467
|
如果是流数据连接,还会调用 publishTable 订阅流表
|
|
470
468
|
后续调用检查上面的条件
|
|
@@ -473,7 +471,7 @@ export declare class DDB {
|
|
|
473
471
|
2. session 是有状态的,重连也无法恢复之前的状态
|
|
474
472
|
3. 断线后所有之前的 ddb.call, ddb.eval 都应该抛出连接错误
|
|
475
473
|
|
|
476
|
-
After calling, it will ensure that the connection with the database is normal (this.connected === true
|
|
474
|
+
After calling, it will ensure that the connection with the database is normal (this.connected === true), otherwise an error will be thrown
|
|
477
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
|
|
478
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:
|
|
479
477
|
1. The on_error callback is bound to a certain websocket, and it is inconvenient to unbind and rebind
|
|
@@ -584,7 +582,7 @@ export declare class DDB {
|
|
|
584
582
|
/** 解析服务端响应报文,返回去掉 header 的 data buf */
|
|
585
583
|
parse_message(buf: Uint8Array, error: DdbDatabaseError): DdbMessage;
|
|
586
584
|
/** 内部的流订阅方法 Internal stream subscription method */
|
|
587
|
-
subscribe(): Promise<
|
|
585
|
+
subscribe(): Promise<void>;
|
|
588
586
|
}
|
|
589
587
|
export interface DdbMessageListener {
|
|
590
588
|
(message: DdbMessage, _this: DDB): any;
|
package/index.js
CHANGED
|
@@ -2162,8 +2162,7 @@ export class DDB {
|
|
|
2162
2162
|
pnode_run_defined = false;
|
|
2163
2163
|
/** 在 websocket 收到的第一个 error 时,
|
|
2164
2164
|
在 connect_websocket 的 on_error 回调中构造 DdbConnectionError 并保存到 DDB 对象上,
|
|
2165
|
-
这个 error 的错误信息最准确
|
|
2166
|
-
this.errored 为 true 时建议 throw this.error || new DdbConnectionError(this) */
|
|
2165
|
+
这个 error 的错误信息最准确 */
|
|
2167
2166
|
error;
|
|
2168
2167
|
/** DdbMessage listeners */
|
|
2169
2168
|
listeners = [];
|
|
@@ -2174,9 +2173,6 @@ export class DDB {
|
|
|
2174
2173
|
get connected() {
|
|
2175
2174
|
return !this.error && this.lwebsocket.resource?.readyState === WebSocketOpen;
|
|
2176
2175
|
}
|
|
2177
|
-
get errored() {
|
|
2178
|
-
return Boolean(this.error || (this.lwebsocket.resource && this.lwebsocket.resource.readyState !== WebSocketOpen));
|
|
2179
|
-
}
|
|
2180
2176
|
/**
|
|
2181
2177
|
使用 WebSocket URL 初始化连接到 DolphinDB 的实例(不建立实际的网络连接)
|
|
2182
2178
|
Initialize an instance of DolphinDB Client using the WebSocket URL (without establishing an actual network connection)
|
|
@@ -2223,7 +2219,7 @@ export class DDB {
|
|
|
2223
2219
|
on_error() {
|
|
2224
2220
|
// 这里的实现一定会被 connect, rpc 中的实现覆盖
|
|
2225
2221
|
}
|
|
2226
|
-
/** 调用后会确保和数据库的连接是正常的 (this.connected === true
|
|
2222
|
+
/** 调用后会确保和数据库的连接是正常的 (this.connected === true),否则抛出错误
|
|
2227
2223
|
这个方法是幂等的,首次调用建立实际的 WebSocket 连接到 URL 对应的 DolphinDB,然后执行自动登录,
|
|
2228
2224
|
如果是流数据连接,还会调用 publishTable 订阅流表
|
|
2229
2225
|
后续调用检查上面的条件
|
|
@@ -2232,17 +2228,20 @@ export class DDB {
|
|
|
2232
2228
|
2. session 是有状态的,重连也无法恢复之前的状态
|
|
2233
2229
|
3. 断线后所有之前的 ddb.call, ddb.eval 都应该抛出连接错误
|
|
2234
2230
|
|
|
2235
|
-
After calling, it will ensure that the connection with the database is normal (this.connected === true
|
|
2231
|
+
After calling, it will ensure that the connection with the database is normal (this.connected === true), otherwise an error will be thrown
|
|
2236
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
|
|
2237
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:
|
|
2238
2234
|
1. The on_error callback is bound to a certain websocket, and it is inconvenient to unbind and rebind
|
|
2239
2235
|
2. The session is stateful, and the previous state cannot be restored even after reconnection
|
|
2240
2236
|
3. After disconnection, all previous ddb.call, ddb.eval should throw a connection error */
|
|
2241
2237
|
async connect() {
|
|
2242
|
-
if (this.errored)
|
|
2243
|
-
throw this.error || new DdbConnectionError(this);
|
|
2244
2238
|
if (this.connected)
|
|
2245
2239
|
return;
|
|
2240
|
+
if (this.error)
|
|
2241
|
+
throw this.error;
|
|
2242
|
+
const { resource: websocket } = this.lwebsocket;
|
|
2243
|
+
if (websocket && (websocket.readyState === WebSocketClosing || websocket.readyState === WebSocketClosed))
|
|
2244
|
+
throw this.error = new DdbConnectionError(this);
|
|
2246
2245
|
return this.pconnect ??= new Promise(async (resolve, reject) => {
|
|
2247
2246
|
this.on_error = () => {
|
|
2248
2247
|
reject(this.error /* 一定有,不需要再 || new DdbConnectionError(this) */);
|
|
@@ -2395,8 +2394,8 @@ export class DDB {
|
|
|
2395
2394
|
// 这里也乐观的认为 this.connected && !this.errored 为 true
|
|
2396
2395
|
return this.lwebsocket.request(async (websocket) => {
|
|
2397
2396
|
// 独占资源后先检查状态
|
|
2398
|
-
if (this.
|
|
2399
|
-
throw this.error
|
|
2397
|
+
if (this.error)
|
|
2398
|
+
throw this.error;
|
|
2400
2399
|
const args = DdbObj.to_ddbobjs(_args);
|
|
2401
2400
|
const id = genid() % 1000;
|
|
2402
2401
|
const rpc_id = ` (id = ${id})`;
|
|
@@ -2641,9 +2640,7 @@ export class DDB {
|
|
|
2641
2640
|
}
|
|
2642
2641
|
/** 内部的流订阅方法 Internal stream subscription method */
|
|
2643
2642
|
async subscribe() {
|
|
2644
|
-
|
|
2645
|
-
// string[3](['time', 'stock', 'price'])
|
|
2646
|
-
this.streaming.colnames = (await this.call('publishTable', [
|
|
2643
|
+
const { value: colnames } = await this.call('publishTable', [
|
|
2647
2644
|
'localhost',
|
|
2648
2645
|
new DdbInt(0),
|
|
2649
2646
|
this.streaming.table,
|
|
@@ -2651,27 +2648,25 @@ export class DDB {
|
|
|
2651
2648
|
// new DdbInt(-1), // offset
|
|
2652
2649
|
// filter
|
|
2653
2650
|
// allow exists
|
|
2654
|
-
], { skip_connection_check: true })
|
|
2655
|
-
|
|
2651
|
+
], { skip_connection_check: true });
|
|
2652
|
+
console.log(t('订阅流表成功') + ', colnames:',
|
|
2653
|
+
// string[3](['time', 'stock', 'price'])
|
|
2654
|
+
colnames);
|
|
2655
|
+
let win = {
|
|
2656
2656
|
offset: 0,
|
|
2657
2657
|
rows: 0,
|
|
2658
2658
|
segments: [],
|
|
2659
2659
|
};
|
|
2660
2660
|
// 先准备好收到 websocket message 的 callback
|
|
2661
2661
|
this.on_message = buffer => {
|
|
2662
|
-
// 复制一份,避免 handler 中异步直接使用传入的 streaming 这个对象时属性发生变化
|
|
2663
|
-
let streaming = { ...this.streaming, error: null };
|
|
2664
2662
|
try {
|
|
2665
2663
|
const dv = new DataView(buffer);
|
|
2666
2664
|
const buf = new Uint8Array(buffer);
|
|
2667
|
-
streaming.time = dv.getBigInt64(1, this.le);
|
|
2668
|
-
streaming.id = dv.getBigInt64(9, this.le);
|
|
2669
2665
|
const i_topic_end = buf.indexOf(0, 17);
|
|
2670
|
-
streaming.topic = this.dec.decode(buf.subarray(17, i_topic_end));
|
|
2671
2666
|
// 是 column 片段组成的 any vector
|
|
2672
|
-
const data =
|
|
2673
|
-
|
|
2674
|
-
win.rows +=
|
|
2667
|
+
const data = DdbObj.parse(buf.subarray(i_topic_end + 1), this.le);
|
|
2668
|
+
const { rows } = data.value[0];
|
|
2669
|
+
win.rows += rows;
|
|
2675
2670
|
win.segments.push(data);
|
|
2676
2671
|
if (win.rows >= winsize * 2 && win.segments.length >= 2) {
|
|
2677
2672
|
let winsize_ = 0;
|
|
@@ -2683,14 +2678,22 @@ export class DDB {
|
|
|
2683
2678
|
win.offset += win.rows - winsize_;
|
|
2684
2679
|
win.rows = winsize_;
|
|
2685
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
|
+
});
|
|
2686
2691
|
}
|
|
2687
2692
|
catch (error) {
|
|
2688
2693
|
// 将 error 交给 handler 处理
|
|
2689
|
-
streaming.
|
|
2694
|
+
this.streaming.handler({ ...this.streaming, error });
|
|
2690
2695
|
}
|
|
2691
|
-
this.streaming.handler(streaming);
|
|
2692
2696
|
};
|
|
2693
|
-
return this.streaming;
|
|
2694
2697
|
}
|
|
2695
2698
|
}
|
|
2696
2699
|
// const ddb_gateway = {
|