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