dolphindb 3.0.1 → 3.0.2
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 +2 -1
- package/browser.js +17 -6
- package/browser.js.map +1 -1
- package/i18n/dict.json +2 -2
- package/index.d.ts +6 -3
- package/index.js +21 -164
- package/index.js.map +1 -1
- package/package.json +5 -5
- package/test.d.ts +0 -1
- package/test.js +26 -15
- package/test.js.map +1 -1
- package/unused.d.ts +1 -0
- package/unused.js +473 -0
- package/unused.js.map +1 -0
package/i18n/dict.json
CHANGED
|
@@ -74,8 +74,8 @@
|
|
|
74
74
|
"new DdbBlob 不能传空的 value": {
|
|
75
75
|
"en": "new DdbBlob cannot pass an empty value"
|
|
76
76
|
},
|
|
77
|
-
"
|
|
78
|
-
"en": "cannot parse
|
|
77
|
+
"{{form}}<{{type}}> 暂时不支持解析": {
|
|
78
|
+
"en": "cannot parse {{form}}<{{type}}>"
|
|
79
79
|
},
|
|
80
80
|
"流数据订阅后一定先返回 schema": {
|
|
81
81
|
"en": "After subscribing to streaming data, the schema must be returned first."
|
package/index.d.ts
CHANGED
|
@@ -176,13 +176,14 @@ export declare class DdbObj<TValue extends DdbValue = DdbValue> {
|
|
|
176
176
|
}): T;
|
|
177
177
|
}
|
|
178
178
|
export interface InspectOptions extends UtilInspectOptions {
|
|
179
|
+
/** `util.inspect.defaultOptions.colors` */
|
|
179
180
|
colors?: boolean;
|
|
180
181
|
/** `null` decimal places 小数位数 */
|
|
181
182
|
decimals?: number;
|
|
182
183
|
/** `true` 决定格式化后的数据是否有千分位 */
|
|
183
184
|
grouping?: boolean;
|
|
184
185
|
}
|
|
185
|
-
/** 根据 DdbType 格式化单个元素 (value) 为字符串,空值返回 'null' 字符串
|
|
186
|
+
/** 根据 DdbType 格式化单个元素 (value) 为字符串,空值返回 'null' 字符串 */
|
|
186
187
|
export declare function format(type: DdbType, value: DdbValue, le: boolean, options?: InspectOptions): string;
|
|
187
188
|
/** 格式化向量、集合中的第 index 项为字符串,空值返回 'null' 字符串 formatted vector, the index-th item in the collection is a string, a null value returns a 'null' string */
|
|
188
189
|
export declare function formati(obj: DdbVectorObj, index: number, options?: InspectOptions): string;
|
|
@@ -400,6 +401,7 @@ export interface DdbOptions {
|
|
|
400
401
|
sql?: SqlStandard;
|
|
401
402
|
streaming?: StreamingParams;
|
|
402
403
|
verbose?: boolean;
|
|
404
|
+
proxy?: string;
|
|
403
405
|
}
|
|
404
406
|
export declare class DDB {
|
|
405
407
|
/** 当前的 session id (http 或 tcp) */
|
|
@@ -408,8 +410,7 @@ export declare class DDB {
|
|
|
408
410
|
dec: TextDecoder;
|
|
409
411
|
enc: TextEncoder;
|
|
410
412
|
/** DolphinDB WebSocket URL
|
|
411
|
-
e.g. `ws://127.0.0.1:8848/`, `wss://dolphindb.com`
|
|
412
|
-
*/
|
|
413
|
+
e.g. `ws://127.0.0.1:8848/`, `wss://dolphindb.com` */
|
|
413
414
|
url: string;
|
|
414
415
|
/** 为所有 websocket 操作加锁,包括设置 this.on_message, this.on_error, websocket.send */
|
|
415
416
|
lwebsocket: Lock<WebSocket>;
|
|
@@ -431,6 +432,8 @@ export declare class DDB {
|
|
|
431
432
|
streaming: StreamingParams;
|
|
432
433
|
/** 是否打印每个 rpc 的信息用于调试 */
|
|
433
434
|
verbose: boolean;
|
|
435
|
+
/** websocket 连接所使用的 http 代理 */
|
|
436
|
+
proxy: string;
|
|
434
437
|
print_message_buffer: boolean;
|
|
435
438
|
print_object_buffer: boolean;
|
|
436
439
|
print_message: boolean;
|
package/index.js
CHANGED
|
@@ -16,7 +16,7 @@ BigInt128Array.prototype[inspect.custom] = function () {
|
|
|
16
16
|
const values = [];
|
|
17
17
|
for (const value of this)
|
|
18
18
|
values.push(value);
|
|
19
|
-
const value_str = values.length ? ` ${values.map(v => v
|
|
19
|
+
const value_str = values.length ? ` ${values.map(v => String(v) + 'n').join(', ')} ` : '';
|
|
20
20
|
return `${this[Symbol.toStringTag]}(${this.length}) [${value_str}]`;
|
|
21
21
|
};
|
|
22
22
|
/** 可以表示所有 DolphinDB 数据库中的数据类型 Can represent data types in all DolphinDB databases */
|
|
@@ -127,6 +127,8 @@ export class DdbObj {
|
|
|
127
127
|
let i_start = i_items_start + len_items;
|
|
128
128
|
for (let i = 0; i < cols; i++) {
|
|
129
129
|
const type = buf_data[i_start];
|
|
130
|
+
if (type === DdbType.compress)
|
|
131
|
+
throw new Error(t('{{form}}<{{type}}> 暂时不支持解析', { form: 'table', type: 'compress' }));
|
|
130
132
|
let col = this.parse_vector(buf_data.subarray(i_start + 2), le, type);
|
|
131
133
|
col.length += 2;
|
|
132
134
|
col.name = colnames[i];
|
|
@@ -708,8 +710,16 @@ export class DdbObj {
|
|
|
708
710
|
});
|
|
709
711
|
return [8 * length, durations];
|
|
710
712
|
}
|
|
713
|
+
case DdbType.compress:
|
|
714
|
+
return [
|
|
715
|
+
length,
|
|
716
|
+
new Uint8Array(buf.buffer.slice(buf.byteOffset, buf.byteOffset + length))
|
|
717
|
+
];
|
|
711
718
|
default:
|
|
712
|
-
throw new Error(t('
|
|
719
|
+
throw new Error(t('{{form}}<{{type}}> 暂时不支持解析', {
|
|
720
|
+
form: 'vector',
|
|
721
|
+
type: String(DdbType[type] || type)
|
|
722
|
+
}));
|
|
713
723
|
}
|
|
714
724
|
}
|
|
715
725
|
pack() {
|
|
@@ -940,6 +950,7 @@ export class DdbObj {
|
|
|
940
950
|
case DdbType.uuid:
|
|
941
951
|
case DdbType.ipaddr:
|
|
942
952
|
case DdbType.int128:
|
|
953
|
+
case DdbType.compress:
|
|
943
954
|
return [value];
|
|
944
955
|
case DdbType.blob: {
|
|
945
956
|
let bufs = new Array(length * 2);
|
|
@@ -1120,7 +1131,7 @@ export class DdbObj {
|
|
|
1120
1131
|
return format_array(items, data.length > limit);
|
|
1121
1132
|
}
|
|
1122
1133
|
default: {
|
|
1123
|
-
const limit = 50;
|
|
1134
|
+
const limit = this.type === DdbType.compress ? 5 : 50;
|
|
1124
1135
|
let items = new Array(Math.min(limit, this.value.length));
|
|
1125
1136
|
for (let i = 0; i < items.length; i++)
|
|
1126
1137
|
items[i] = format(this.type, this.value[i], this.le, options);
|
|
@@ -1282,7 +1293,7 @@ let _grouping = true;
|
|
|
1282
1293
|
let _formatter = new Intl.NumberFormat('en-US', { maximumFractionDigits: 20 });
|
|
1283
1294
|
/** 用来处理时差 To deal with jet lag */
|
|
1284
1295
|
let _datetime_formatter = new Intl.DateTimeFormat('zh-CN', { dateStyle: 'short', timeStyle: 'medium', timeZone: 'UTC', hour12: false });
|
|
1285
|
-
/** 根据 DdbType 格式化单个元素 (value) 为字符串,空值返回 'null' 字符串
|
|
1296
|
+
/** 根据 DdbType 格式化单个元素 (value) 为字符串,空值返回 'null' 字符串 */
|
|
1286
1297
|
export function format(type, value, le, options = {}) {
|
|
1287
1298
|
const formatter = (() => {
|
|
1288
1299
|
const { grouping = true } = options;
|
|
@@ -2145,14 +2156,8 @@ export class DDB {
|
|
|
2145
2156
|
/** utf-8 text decoder */
|
|
2146
2157
|
dec = new TextDecoder('utf-8');
|
|
2147
2158
|
enc = new TextEncoder();
|
|
2148
|
-
// port = 8848
|
|
2149
|
-
// /** ddb 连接状态 */
|
|
2150
|
-
// state = '未连接'
|
|
2151
|
-
// socket = null as Socket
|
|
2152
|
-
// clients = new Set<Duplex>()
|
|
2153
2159
|
/** DolphinDB WebSocket URL
|
|
2154
|
-
e.g. `ws://127.0.0.1:8848/`, `wss://dolphindb.com`
|
|
2155
|
-
*/
|
|
2160
|
+
e.g. `ws://127.0.0.1:8848/`, `wss://dolphindb.com` */
|
|
2156
2161
|
url;
|
|
2157
2162
|
/** 为所有 websocket 操作加锁,包括设置 this.on_message, this.on_error, websocket.send */
|
|
2158
2163
|
lwebsocket = new Lock();
|
|
@@ -2174,6 +2179,8 @@ export class DDB {
|
|
|
2174
2179
|
streaming = null;
|
|
2175
2180
|
/** 是否打印每个 rpc 的信息用于调试 */
|
|
2176
2181
|
verbose = false;
|
|
2182
|
+
/** websocket 连接所使用的 http 代理 */
|
|
2183
|
+
proxy;
|
|
2177
2184
|
// --- 内部选项, 状态
|
|
2178
2185
|
print_message_buffer = false;
|
|
2179
2186
|
print_object_buffer = false;
|
|
@@ -2232,6 +2239,8 @@ export class DDB {
|
|
|
2232
2239
|
this.sql = options.sql;
|
|
2233
2240
|
if (options.streaming !== undefined)
|
|
2234
2241
|
this.streaming = options.streaming;
|
|
2242
|
+
if (options.proxy)
|
|
2243
|
+
this.proxy = options.proxy;
|
|
2235
2244
|
}
|
|
2236
2245
|
on_message(buffer, websocket) {
|
|
2237
2246
|
throw new Error(t('这是在调用 this.rpc 之前默认的 on_message, 不应该被调用到,除非建立连接后 server 先推送了 message'));
|
|
@@ -2273,6 +2282,7 @@ export class DDB {
|
|
|
2273
2282
|
// 连接建立之前应该不会有别的调用占用 this.lwebsocket
|
|
2274
2283
|
this.lwebsocket.resource = await connect_websocket(url, {
|
|
2275
2284
|
protocols: this.streaming ? ['streaming'] : this.python ? ['python'] : undefined,
|
|
2285
|
+
proxy: this.proxy,
|
|
2276
2286
|
on_message: (buffer, websocket) => {
|
|
2277
2287
|
this.on_message(new Uint8Array(buffer), websocket);
|
|
2278
2288
|
},
|
|
@@ -2734,157 +2744,4 @@ export class DDB {
|
|
|
2734
2744
|
colnames);
|
|
2735
2745
|
}
|
|
2736
2746
|
}
|
|
2737
|
-
// const ddb_gateway = {
|
|
2738
|
-
// server: null as SocketServer,
|
|
2739
|
-
// clients: new Set<Socket>(),
|
|
2740
|
-
// port: 8849,
|
|
2741
|
-
// controllers: {
|
|
2742
|
-
// /** alias */
|
|
2743
|
-
// c0: {
|
|
2744
|
-
// hostname: '127.0.0.1',
|
|
2745
|
-
// port: 8850,
|
|
2746
|
-
// },
|
|
2747
|
-
// c1: {
|
|
2748
|
-
// hostname: '127.0.0.1',
|
|
2749
|
-
// port: 8851,
|
|
2750
|
-
// },
|
|
2751
|
-
// c2: {
|
|
2752
|
-
// hostname: '127.0.0.1',
|
|
2753
|
-
// port: 8852,
|
|
2754
|
-
// }
|
|
2755
|
-
// },
|
|
2756
|
-
// master: '',
|
|
2757
|
-
// sids: new Map<string, string>(),
|
|
2758
|
-
// state: 'init',
|
|
2759
|
-
// async start () {
|
|
2760
|
-
// for (const alias in this.controllers) {
|
|
2761
|
-
// this.master = alias
|
|
2762
|
-
// break
|
|
2763
|
-
// }
|
|
2764
|
-
// this.server = create_socket_server(
|
|
2765
|
-
// {
|
|
2766
|
-
// allowHalfOpen: false,
|
|
2767
|
-
// pauseOnConnect: false,
|
|
2768
|
-
// },
|
|
2769
|
-
// this.accept.bind(this)
|
|
2770
|
-
// )
|
|
2771
|
-
// this.server.on('error', error => {
|
|
2772
|
-
// console.log(new Date(), 'gateway 出错:', error)
|
|
2773
|
-
// })
|
|
2774
|
-
// await new Promise<void>(resolve => {
|
|
2775
|
-
// this.server.listen(this.port, resolve)
|
|
2776
|
-
// })
|
|
2777
|
-
// this.auto_switch_master()
|
|
2778
|
-
// console.log(new Date(), 'gateway 成功启动')
|
|
2779
|
-
// },
|
|
2780
|
-
// async stop () {
|
|
2781
|
-
// this.state = 'stopping'
|
|
2782
|
-
// console.log(new Date(), '正在停止 auto_switch_master')
|
|
2783
|
-
// for (const client of this.clients)
|
|
2784
|
-
// client.end()
|
|
2785
|
-
// await new Promise<void>((resolve, reject) => {
|
|
2786
|
-
// this.server.close(error => {
|
|
2787
|
-
// if (error) {
|
|
2788
|
-
// reject(error)
|
|
2789
|
-
// return
|
|
2790
|
-
// }
|
|
2791
|
-
// resolve()
|
|
2792
|
-
// })
|
|
2793
|
-
// })
|
|
2794
|
-
// },
|
|
2795
|
-
// /** 接收到 client tcp 连接 */
|
|
2796
|
-
// async accept (client: Socket) {
|
|
2797
|
-
// this.clients.add(client)
|
|
2798
|
-
// const port = client.remotePort
|
|
2799
|
-
// // ---
|
|
2800
|
-
// console.log(port, new Date(), 'gateway accept client 连接,开始建立管道')
|
|
2801
|
-
// let controller = new Socket({
|
|
2802
|
-
// allowHalfOpen: false,
|
|
2803
|
-
// readable: true,
|
|
2804
|
-
// writable: true,
|
|
2805
|
-
// })
|
|
2806
|
-
// controller.on('lookup', (error, address, family, host) => {
|
|
2807
|
-
// console.log(port, new Date(), 'controller 域名解析 (lookup) 完成', error, address, family, host)
|
|
2808
|
-
// })
|
|
2809
|
-
// controller.on('close', has_error => {
|
|
2810
|
-
// console.log(port, new Date(), 'controller 关闭连接,是否出错:', has_error)
|
|
2811
|
-
// })
|
|
2812
|
-
// controller.on('timeout', () => {
|
|
2813
|
-
// console.log(port, new Date(), 'controller 超时')
|
|
2814
|
-
// })
|
|
2815
|
-
// controller.on('error', error => {
|
|
2816
|
-
// console.log(port, new Date(), 'controller 出错了:', error)
|
|
2817
|
-
// client.end()
|
|
2818
|
-
// })
|
|
2819
|
-
// // --- client 错误处理
|
|
2820
|
-
// client.on('error', error => {
|
|
2821
|
-
// console.log(port, new Date(), 'client 出错,关闭与 controller 的连接', error)
|
|
2822
|
-
// controller.end()
|
|
2823
|
-
// })
|
|
2824
|
-
// client.on('close', has_error => {
|
|
2825
|
-
// this.clients.delete(client)
|
|
2826
|
-
// console.log(port, new Date(), 'client 关闭连接,是否出错:', has_error)
|
|
2827
|
-
// })
|
|
2828
|
-
// // ---
|
|
2829
|
-
// console.log(port, new Date(), 'gateway 开始连接到 controller')
|
|
2830
|
-
// const { hostname, port: master_port } = this.controllers[this.master]
|
|
2831
|
-
// await new Promise<void>(resolve => {
|
|
2832
|
-
// // callback 会被 socket.once('connect', callback)
|
|
2833
|
-
// controller.connect({
|
|
2834
|
-
// port: master_port,
|
|
2835
|
-
// host: hostname,
|
|
2836
|
-
// // host: '127.0.0.1',
|
|
2837
|
-
// family: 0,
|
|
2838
|
-
// }, resolve)
|
|
2839
|
-
// })
|
|
2840
|
-
// console.log(port, new Date(), 'gateway 已连接到 controller')
|
|
2841
|
-
// // ---
|
|
2842
|
-
// console.log(port, new Date(), 'gateway 建立 client <-> controller')
|
|
2843
|
-
// client.pipe(controller)
|
|
2844
|
-
// controller.pipe(client)
|
|
2845
|
-
// },
|
|
2846
|
-
// /** https://www.dolphindb.cn/cn/help/FunctionsandCommands/FunctionReferences/g/getActiveMaster.html?highlight=getactivemaster */
|
|
2847
|
-
// async get_active_master () {
|
|
2848
|
-
// for (const alias in this.controllers) {
|
|
2849
|
-
// const { hostname, port } = this.controllers[alias] as { hostname: string, port: number }
|
|
2850
|
-
// const sid = this.sids.get(alias)
|
|
2851
|
-
// try {
|
|
2852
|
-
// const master = (
|
|
2853
|
-
// await ddb.rpc_json('getActiveMaster()', { hostname, port, sid })
|
|
2854
|
-
// ).value as string
|
|
2855
|
-
// console.log(new Date(), `${alias}.getActiveMaster() -> ${this.master}`)
|
|
2856
|
-
// this.sids.set(alias, sid)
|
|
2857
|
-
// if (!master)
|
|
2858
|
-
// throw new Error(`${new Date().toString()} getActiveMaster 得到的 master 为空`)
|
|
2859
|
-
// return master
|
|
2860
|
-
// } catch (error) {
|
|
2861
|
-
// console.log(new Date(), error)
|
|
2862
|
-
// }
|
|
2863
|
-
// }
|
|
2864
|
-
// return this.master
|
|
2865
|
-
// },
|
|
2866
|
-
// async auto_switch_master () {
|
|
2867
|
-
// if (this.state === 'stopping') {
|
|
2868
|
-
// this.state = 'running'
|
|
2869
|
-
// console.log('gateway 恢复 auto_switch_master')
|
|
2870
|
-
// return
|
|
2871
|
-
// }
|
|
2872
|
-
// this.state = 'running'
|
|
2873
|
-
// for (; this.state === 'running'; ) {
|
|
2874
|
-
// const master = this.master
|
|
2875
|
-
// const master_ = await this.get_active_master()
|
|
2876
|
-
// if (master === master_) {
|
|
2877
|
-
// await delay(10 * 1000)
|
|
2878
|
-
// continue
|
|
2879
|
-
// }
|
|
2880
|
-
// this.master = master_
|
|
2881
|
-
// console.log(new Date(), `master 从 ${master} 切换为 ${master_}, 断开所有 clients`)
|
|
2882
|
-
// for (const client of this.clients)
|
|
2883
|
-
// client.end()
|
|
2884
|
-
// await delay(3 * 1000)
|
|
2885
|
-
// }
|
|
2886
|
-
// console.log(new Date(), `gateway.state === ${this.state}, 停止 auto_switch_master`)
|
|
2887
|
-
// this.state = 'stopped'
|
|
2888
|
-
// }
|
|
2889
|
-
// }
|
|
2890
2747
|
//# sourceMappingURL=index.js.map
|