dolphindb 2.0.501 → 2.0.504
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/README.md +37 -32
- package/README.zh.md +29 -24
- package/browser.d.ts +52 -14
- package/browser.js +130 -26
- package/browser.js.map +1 -1
- package/index.d.ts +49 -13
- package/index.js +127 -25
- package/index.js.map +1 -1
- package/package.json +2 -2
- package/test.d.ts +0 -1
- package/test.js +0 -38
- package/test.js.map +0 -1
package/README.md
CHANGED
|
@@ -54,23 +54,24 @@ let ddb = new DDB('ws://127.0.0.1:8848')
|
|
|
54
54
|
await ddb.connect()
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
####
|
|
57
|
+
#### DDB options
|
|
58
58
|
```ts
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
59
|
+
let ddb = new DDB('ws://127.0.0.1:8848')
|
|
60
|
+
|
|
61
|
+
// Encrypt with HTTPS
|
|
62
|
+
let ddbsecure = new DDB('wss://dolphindb.com', {
|
|
63
|
+
// Whether to log in automatically after establishing a connection, default `true`
|
|
64
|
+
autologin: true,
|
|
65
|
+
|
|
66
|
+
// DolphinDB username, default `'admin'`
|
|
67
|
+
username: 'admin',
|
|
68
|
+
|
|
69
|
+
// DolphinDB password, default `'123456'`
|
|
70
|
+
password: '123456',
|
|
71
|
+
|
|
72
|
+
// set python session flag, default `false`
|
|
73
|
+
python: false
|
|
74
|
+
})
|
|
74
75
|
```
|
|
75
76
|
|
|
76
77
|
|
|
@@ -187,37 +188,41 @@ enum DdbType {
|
|
|
187
188
|
}
|
|
188
189
|
```
|
|
189
190
|
|
|
190
|
-
#####
|
|
191
|
+
##### If there is no shortcut class, you can also specify form and type to manually create a DdbObj object
|
|
191
192
|
```ts
|
|
193
|
+
// Created by the DdbDateTime shortcut class
|
|
194
|
+
new DdbDateTime(1644573600)
|
|
195
|
+
|
|
196
|
+
// Equivalent to manually creating an object of form = scalar, type = datetime through DdbObj
|
|
192
197
|
const obj = new DdbObj({
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
198
|
+
form: DdbForm.scalar,
|
|
199
|
+
type: DdbType.datetime,
|
|
200
|
+
value: 1644573600,
|
|
201
|
+
length: 0
|
|
197
202
|
})
|
|
198
|
-
```
|
|
199
203
|
|
|
200
|
-
The corresponding type and value of value property in js can refer to the result returned by `ddb.eval` (see below: `eval` Method Declaration)
|
|
201
204
|
|
|
202
|
-
|
|
205
|
+
// The corresponding type and value of value in js can refer to the result returned by ddb.eval (see the `eval` method declaration below)
|
|
203
206
|
const obj = await ddb.eval('2022.02.11 10:00:00')
|
|
204
207
|
console.log(obj.form === DdbForm.scalar)
|
|
205
208
|
console.log(obj.type === DdbType.datetime)
|
|
206
209
|
console.log(obj.value)
|
|
207
|
-
```
|
|
208
210
|
|
|
209
|
-
|
|
210
|
-
```ts
|
|
211
|
+
// Another example is to create a set
|
|
211
212
|
// refer to ddb.eval
|
|
212
213
|
// const obj = await ddb.eval('set([1, 2, 3])')
|
|
213
214
|
// console.log(obj.value)
|
|
214
|
-
|
|
215
215
|
const obj = new DdbObj({
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
216
|
+
form: DdbForm.set,
|
|
217
|
+
type: DdbType.int,
|
|
218
|
+
value: Int32Array.of(1, 2, 3),
|
|
219
|
+
length: 0
|
|
220
220
|
})
|
|
221
|
+
|
|
222
|
+
// It's easier to use shortcut classes
|
|
223
|
+
const obj = new DdbSetInt(
|
|
224
|
+
new Set([1, 2, 3])
|
|
225
|
+
)
|
|
221
226
|
```
|
|
222
227
|
|
|
223
228
|
##### NULL object in the form of scalar, the value corresponding to DdbObj is null in JavaScript
|
package/README.zh.md
CHANGED
|
@@ -55,23 +55,24 @@ let ddb = new DDB('ws://127.0.0.1:8848')
|
|
|
55
55
|
await ddb.connect()
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
-
####
|
|
58
|
+
#### DDB 选项
|
|
59
59
|
```ts
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
60
|
+
let ddb = new DDB('ws://127.0.0.1:8848')
|
|
61
|
+
|
|
62
|
+
// 使用 HTTPS 加密
|
|
63
|
+
let ddbsecure = new DDB('wss://dolphindb.com', {
|
|
64
|
+
// 是否在建立连接后自动登录,默认 `true`
|
|
65
|
+
autologin: true,
|
|
66
|
+
|
|
67
|
+
// DolphinDB 登录用户名,默认 `'admin'`
|
|
68
|
+
username: 'admin',
|
|
69
|
+
|
|
70
|
+
// DolphinDB 登录密码,默认 `'123456'`
|
|
71
|
+
password: '123456',
|
|
72
|
+
|
|
73
|
+
// 设置 python session flag,默认 `false`
|
|
74
|
+
python: false
|
|
75
|
+
})
|
|
75
76
|
```
|
|
76
77
|
|
|
77
78
|
|
|
@@ -188,37 +189,41 @@ enum DdbType {
|
|
|
188
189
|
}
|
|
189
190
|
```
|
|
190
191
|
|
|
191
|
-
#####
|
|
192
|
+
##### 没有快捷类的类型,也可以指定 form 和 type 手动创建 DdbObj 对象
|
|
192
193
|
```ts
|
|
194
|
+
// 通过 DdbDateTime 快捷类创建
|
|
195
|
+
new DdbDateTime(1644573600)
|
|
196
|
+
|
|
197
|
+
// 等价于手动通过 DdbObj 创建 form = scalar, type = datetime 的对象
|
|
193
198
|
const obj = new DdbObj({
|
|
194
199
|
form: DdbForm.scalar,
|
|
195
200
|
type: DdbType.datetime,
|
|
196
201
|
value: 1644573600,
|
|
197
202
|
length: 0
|
|
198
203
|
})
|
|
199
|
-
```
|
|
200
204
|
|
|
201
|
-
value 的在 js 中对应类型及取值可以参考 ddb.eval 返回的结果 (见后文 `eval` 方法声明)
|
|
202
205
|
|
|
203
|
-
|
|
206
|
+
// value 在 js 中对应类型及取值可以参考 ddb.eval 返回的结果 (见后文 `eval` 方法声明)
|
|
204
207
|
const obj = await ddb.eval('2022.02.11 10:00:00')
|
|
205
208
|
console.log(obj.form === DdbForm.scalar)
|
|
206
209
|
console.log(obj.type === DdbType.datetime)
|
|
207
210
|
console.log(obj.value)
|
|
208
|
-
```
|
|
209
211
|
|
|
210
|
-
|
|
211
|
-
```ts
|
|
212
|
+
// 再比如创建一个 set
|
|
212
213
|
// 参考 ddb.eval
|
|
213
214
|
// const obj = await ddb.eval('set([1, 2, 3])')
|
|
214
215
|
// console.log(obj.value)
|
|
215
|
-
|
|
216
216
|
const obj = new DdbObj({
|
|
217
217
|
form: DdbForm.set,
|
|
218
218
|
type: DdbType.int,
|
|
219
219
|
value: Int32Array.of(1, 2, 3),
|
|
220
220
|
length: 0
|
|
221
221
|
})
|
|
222
|
+
|
|
223
|
+
// 使用快捷类较为简单
|
|
224
|
+
const obj = new DdbSetInt(
|
|
225
|
+
new Set([1, 2, 3])
|
|
226
|
+
)
|
|
222
227
|
```
|
|
223
228
|
|
|
224
229
|
##### scalar 形式的 NULL 对象, 对应 DdbObj 的 value 为 JavaScript 中的 null
|
package/browser.d.ts
CHANGED
|
@@ -93,7 +93,9 @@ export declare const timezone_offset: number;
|
|
|
93
93
|
export declare class DdbObj<T extends DdbValue = DdbValue> {
|
|
94
94
|
static dec: TextDecoder;
|
|
95
95
|
static enc: TextEncoder;
|
|
96
|
-
/** 维护已解析的 symbol base,比如流数据中后续的 symbol 向量可能只发送一个 base.id, base.size == 0, 依赖之前发送的 symbol base
|
|
96
|
+
/** 维护已解析的 symbol base,比如流数据中后续的 symbol 向量可能只发送一个 base.id, base.size == 0, 依赖之前发送的 symbol base ?
|
|
97
|
+
只是暂存,如果一张表有多个 symbol 列,可能这个 symbol base 会被复用,不同的对象之间 symbol base 一般不复用
|
|
98
|
+
*/
|
|
97
99
|
static symbol_bases: Record<number, string[]>;
|
|
98
100
|
/** little endian (client) */
|
|
99
101
|
static le_client: boolean;
|
|
@@ -189,18 +191,27 @@ export declare class DdbFunction extends DdbObj<DdbFunctionDefValue> {
|
|
|
189
191
|
export declare class DdbVectorInt extends DdbObj<Int32Array> {
|
|
190
192
|
constructor(ints: (number | null)[] | Int32Array, name?: string);
|
|
191
193
|
}
|
|
192
|
-
export declare class DdbVectorString extends DdbObj<string[]> {
|
|
193
|
-
constructor(strings: string[], name?: string);
|
|
194
|
-
}
|
|
195
194
|
export declare class DdbVectorDouble extends DdbObj<Float64Array> {
|
|
196
195
|
constructor(doubles: (number | null)[] | Float64Array, name?: string);
|
|
197
196
|
}
|
|
197
|
+
export declare class DdbVectorString extends DdbObj<string[]> {
|
|
198
|
+
constructor(strings: string[], name?: string);
|
|
199
|
+
}
|
|
198
200
|
export declare class DdbVectorAny extends DdbObj {
|
|
199
201
|
constructor(objs: DdbObj<DdbValue>[], name?: string);
|
|
200
202
|
}
|
|
201
203
|
export declare class DdbVectorSymbol extends DdbObj<DdbSymbolExtendedValue> {
|
|
202
204
|
constructor(strings: string[], name?: string);
|
|
203
205
|
}
|
|
206
|
+
export declare class DdbSetInt extends DdbObj<Int32Array> {
|
|
207
|
+
constructor(ints: (number | null)[] | Set<number> | Int32Array);
|
|
208
|
+
}
|
|
209
|
+
export declare class DdbSetDouble extends DdbObj<Float64Array> {
|
|
210
|
+
constructor(doubles: (number | null)[] | Set<number> | Float64Array);
|
|
211
|
+
}
|
|
212
|
+
export declare class DdbSetString extends DdbObj<string[]> {
|
|
213
|
+
constructor(strings: string[] | Set<string>);
|
|
214
|
+
}
|
|
204
215
|
export declare class DdbTable extends DdbObj<DdbObj[]> {
|
|
205
216
|
constructor(columns: DdbObj[], name?: string);
|
|
206
217
|
}
|
|
@@ -251,6 +262,12 @@ export declare class DDB {
|
|
|
251
262
|
le: boolean;
|
|
252
263
|
/** little endian (client) */
|
|
253
264
|
static le_client: boolean;
|
|
265
|
+
/** Whether to automatically log in after the connection is established, the default is true */
|
|
266
|
+
autologin: boolean;
|
|
267
|
+
/** DolphinDB username */
|
|
268
|
+
username: string;
|
|
269
|
+
/** DolphinDB password */
|
|
270
|
+
password: string;
|
|
254
271
|
/** python session flag (2048) */
|
|
255
272
|
python: boolean;
|
|
256
273
|
message_hook: (message: Uint8Array) => any;
|
|
@@ -264,22 +281,43 @@ export declare class DDB {
|
|
|
264
281
|
/**
|
|
265
282
|
Initialize an instance of DolphinDB Client using the WebSocket URL
|
|
266
283
|
(without establishing an actual network connection)
|
|
284
|
+
- url?: DolphinDB WebSocket URL. e.g.:`ws://127.0.0.1:8848`, Defaults to the current page URL
|
|
285
|
+
- options?:
|
|
286
|
+
- autologin?: Whether to log in automatically after establishing a connection, default `true`
|
|
287
|
+
- username?: DolphinDB username, default `'admin'`
|
|
288
|
+
- password?: DolphinDB password, default `'123456'`
|
|
289
|
+
- python?: set python session flag, default `false`
|
|
290
|
+
|
|
267
291
|
@example
|
|
268
292
|
let ddb = new DDB('ws://127.0.0.1:8848')
|
|
269
|
-
|
|
293
|
+
|
|
294
|
+
// 使用 HTTPS 加密
|
|
295
|
+
let ddbsecure = new DDB('wss://dolphindb.com', {
|
|
296
|
+
autologin: true,
|
|
297
|
+
username: 'admin',
|
|
298
|
+
password: '123456',
|
|
299
|
+
python: false
|
|
300
|
+
})
|
|
301
|
+
*/
|
|
302
|
+
constructor(url?: string, options?: {
|
|
303
|
+
autologin?: boolean;
|
|
304
|
+
username?: string;
|
|
305
|
+
password?: string;
|
|
306
|
+
python?: boolean;
|
|
307
|
+
});
|
|
308
|
+
/** Establish the actual WebSocket connection to the DolphinDB corresponding to the URL
|
|
309
|
+
- options?:
|
|
310
|
+
- url?: DolphinDB WebSocket URL. By default, the WebSocket URL passed in when the instance is initialized is used
|
|
311
|
+
- autologin?: Whether to log in automatically after establishing a connection, default `true`
|
|
312
|
+
- username?: DolphinDB username, default `'admin'`
|
|
313
|
+
- password?: DolphinDB password, default `'123456'`
|
|
314
|
+
- python?: set python session flag, default `false`
|
|
270
315
|
*/
|
|
271
|
-
|
|
272
|
-
/** Establish the actual WebSocket connection to the DolphinDB corresponding to the URL */
|
|
273
|
-
connect({ url, login, username, password, python, }?: {
|
|
274
|
-
/** By default, the WebSocket URL passed in when the instance is initialized is used */
|
|
316
|
+
connect(options?: {
|
|
275
317
|
url?: string;
|
|
276
|
-
|
|
277
|
-
login?: boolean;
|
|
278
|
-
/** DolphinDB username */
|
|
318
|
+
autologin?: boolean;
|
|
279
319
|
username?: string;
|
|
280
|
-
/** DolphinDB password */
|
|
281
320
|
password?: string;
|
|
282
|
-
/** set python session flag */
|
|
283
321
|
python?: boolean;
|
|
284
322
|
}): Promise<void>;
|
|
285
323
|
get_rpc_options({ urgent, secondary, async: _async, pickle, clear, api, compress, cancellable, priority, parallelism, root_id, limit, }?: {
|
package/browser.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ddb = exports.DDB = exports.str2nanotimestamp = exports.nanotimestamp2str = exports.str2timestamp = exports.timestamp2str = exports.datetime2str = exports.date2str = exports.DdbTable = exports.DdbVectorSymbol = exports.DdbVectorAny = exports.
|
|
3
|
+
exports.ddb = exports.DDB = exports.str2nanotimestamp = exports.nanotimestamp2str = exports.str2timestamp = exports.timestamp2str = exports.datetime2str = exports.date2str = exports.DdbTable = exports.DdbSetString = exports.DdbSetDouble = exports.DdbSetInt = exports.DdbVectorSymbol = exports.DdbVectorAny = exports.DdbVectorString = exports.DdbVectorDouble = exports.DdbVectorInt = exports.DdbFunction = exports.DdbPair = exports.DdbNanoTimeStamp = exports.DdbTimeStamp = exports.DdbDateTime = exports.DdbDouble = exports.DdbLong = exports.DdbString = exports.DdbInt = exports.DdbChar = exports.DdbBool = exports.DdbVoid = exports.DdbObj = exports.timezone_offset = exports.nulls = exports.DdbFunctionType = exports.DdbType = exports.DdbForm = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
6
6
|
const customParseFormat_js_1 = tslib_1.__importDefault(require("dayjs/plugin/customParseFormat.js"));
|
|
@@ -915,7 +915,9 @@ class DdbObj {
|
|
|
915
915
|
exports.DdbObj = DdbObj;
|
|
916
916
|
DdbObj.dec = new TextDecoder('utf-8');
|
|
917
917
|
DdbObj.enc = new TextEncoder();
|
|
918
|
-
/** 维护已解析的 symbol base,比如流数据中后续的 symbol 向量可能只发送一个 base.id, base.size == 0, 依赖之前发送的 symbol base
|
|
918
|
+
/** 维护已解析的 symbol base,比如流数据中后续的 symbol 向量可能只发送一个 base.id, base.size == 0, 依赖之前发送的 symbol base ?
|
|
919
|
+
只是暂存,如果一张表有多个 symbol 列,可能这个 symbol base 会被复用,不同的对象之间 symbol base 一般不复用
|
|
920
|
+
*/
|
|
919
921
|
DdbObj.symbol_bases = {};
|
|
920
922
|
/** little endian (client) */
|
|
921
923
|
DdbObj.le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
|
|
@@ -1073,20 +1075,6 @@ class DdbVectorInt extends DdbObj {
|
|
|
1073
1075
|
}
|
|
1074
1076
|
}
|
|
1075
1077
|
exports.DdbVectorInt = DdbVectorInt;
|
|
1076
|
-
class DdbVectorString extends DdbObj {
|
|
1077
|
-
constructor(strings, name) {
|
|
1078
|
-
super({
|
|
1079
|
-
form: DdbForm.vector,
|
|
1080
|
-
type: DdbType.string,
|
|
1081
|
-
length: 0,
|
|
1082
|
-
rows: strings.length,
|
|
1083
|
-
cols: 1,
|
|
1084
|
-
value: strings,
|
|
1085
|
-
name,
|
|
1086
|
-
});
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
|
-
exports.DdbVectorString = DdbVectorString;
|
|
1090
1078
|
class DdbVectorDouble extends DdbObj {
|
|
1091
1079
|
constructor(doubles, name) {
|
|
1092
1080
|
super({
|
|
@@ -1107,6 +1095,20 @@ class DdbVectorDouble extends DdbObj {
|
|
|
1107
1095
|
}
|
|
1108
1096
|
}
|
|
1109
1097
|
exports.DdbVectorDouble = DdbVectorDouble;
|
|
1098
|
+
class DdbVectorString extends DdbObj {
|
|
1099
|
+
constructor(strings, name) {
|
|
1100
|
+
super({
|
|
1101
|
+
form: DdbForm.vector,
|
|
1102
|
+
type: DdbType.string,
|
|
1103
|
+
length: 0,
|
|
1104
|
+
rows: strings.length,
|
|
1105
|
+
cols: 1,
|
|
1106
|
+
value: strings,
|
|
1107
|
+
name,
|
|
1108
|
+
});
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
exports.DdbVectorString = DdbVectorString;
|
|
1110
1112
|
class DdbVectorAny extends DdbObj {
|
|
1111
1113
|
constructor(objs, name) {
|
|
1112
1114
|
super({
|
|
@@ -1152,6 +1154,65 @@ class DdbVectorSymbol extends DdbObj {
|
|
|
1152
1154
|
}
|
|
1153
1155
|
}
|
|
1154
1156
|
exports.DdbVectorSymbol = DdbVectorSymbol;
|
|
1157
|
+
class DdbSetInt extends DdbObj {
|
|
1158
|
+
constructor(ints) {
|
|
1159
|
+
super({
|
|
1160
|
+
form: DdbForm.set,
|
|
1161
|
+
type: DdbType.int,
|
|
1162
|
+
length: 0,
|
|
1163
|
+
rows: ints instanceof Set ?
|
|
1164
|
+
ints.size
|
|
1165
|
+
:
|
|
1166
|
+
ints.length,
|
|
1167
|
+
cols: 1,
|
|
1168
|
+
value: ints instanceof Int32Array ?
|
|
1169
|
+
ints
|
|
1170
|
+
:
|
|
1171
|
+
Int32Array.from(ints, v => v === null ?
|
|
1172
|
+
exports.nulls.int32
|
|
1173
|
+
:
|
|
1174
|
+
v),
|
|
1175
|
+
});
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
exports.DdbSetInt = DdbSetInt;
|
|
1179
|
+
class DdbSetDouble extends DdbObj {
|
|
1180
|
+
constructor(doubles) {
|
|
1181
|
+
super({
|
|
1182
|
+
form: DdbForm.set,
|
|
1183
|
+
type: DdbType.double,
|
|
1184
|
+
length: 0,
|
|
1185
|
+
rows: doubles instanceof Set ?
|
|
1186
|
+
doubles.size
|
|
1187
|
+
:
|
|
1188
|
+
doubles.length,
|
|
1189
|
+
cols: 1,
|
|
1190
|
+
value: doubles instanceof Int32Array ?
|
|
1191
|
+
doubles
|
|
1192
|
+
:
|
|
1193
|
+
Int32Array.from(doubles, v => v === null ?
|
|
1194
|
+
exports.nulls.int32
|
|
1195
|
+
:
|
|
1196
|
+
v),
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
exports.DdbSetDouble = DdbSetDouble;
|
|
1201
|
+
class DdbSetString extends DdbObj {
|
|
1202
|
+
constructor(strings) {
|
|
1203
|
+
if (strings instanceof Set)
|
|
1204
|
+
strings = [...strings];
|
|
1205
|
+
super({
|
|
1206
|
+
form: DdbForm.set,
|
|
1207
|
+
type: DdbType.string,
|
|
1208
|
+
length: 0,
|
|
1209
|
+
rows: strings.length,
|
|
1210
|
+
cols: 1,
|
|
1211
|
+
value: strings
|
|
1212
|
+
});
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
exports.DdbSetString = DdbSetString;
|
|
1155
1216
|
class DdbTable extends DdbObj {
|
|
1156
1217
|
constructor(columns, name = '') {
|
|
1157
1218
|
super({
|
|
@@ -1259,11 +1320,25 @@ class DDB {
|
|
|
1259
1320
|
/**
|
|
1260
1321
|
Initialize an instance of DolphinDB Client using the WebSocket URL
|
|
1261
1322
|
(without establishing an actual network connection)
|
|
1323
|
+
- url?: DolphinDB WebSocket URL. e.g.:`ws://127.0.0.1:8848`, Defaults to the current page URL
|
|
1324
|
+
- options?:
|
|
1325
|
+
- autologin?: Whether to log in automatically after establishing a connection, default `true`
|
|
1326
|
+
- username?: DolphinDB username, default `'admin'`
|
|
1327
|
+
- password?: DolphinDB password, default `'123456'`
|
|
1328
|
+
- python?: set python session flag, default `false`
|
|
1329
|
+
|
|
1262
1330
|
@example
|
|
1263
1331
|
let ddb = new DDB('ws://127.0.0.1:8848')
|
|
1264
|
-
|
|
1332
|
+
|
|
1333
|
+
// 使用 HTTPS 加密
|
|
1334
|
+
let ddbsecure = new DDB('wss://dolphindb.com', {
|
|
1335
|
+
autologin: true,
|
|
1336
|
+
username: 'admin',
|
|
1337
|
+
password: '123456',
|
|
1338
|
+
python: false
|
|
1339
|
+
})
|
|
1265
1340
|
*/
|
|
1266
|
-
constructor(url) {
|
|
1341
|
+
constructor(url, options = {}) {
|
|
1267
1342
|
/** 当前的 session id (http 或 tcp) */
|
|
1268
1343
|
this.sid = '0';
|
|
1269
1344
|
/** utf-8 text decoder */
|
|
@@ -1272,6 +1347,12 @@ class DDB {
|
|
|
1272
1347
|
this.websocket = null;
|
|
1273
1348
|
/** little endian (server) */
|
|
1274
1349
|
this.le = true;
|
|
1350
|
+
/** Whether to automatically log in after the connection is established, the default is true */
|
|
1351
|
+
this.autologin = true;
|
|
1352
|
+
/** DolphinDB username */
|
|
1353
|
+
this.username = 'admin';
|
|
1354
|
+
/** DolphinDB password */
|
|
1355
|
+
this.password = '123456';
|
|
1275
1356
|
/** python session flag (2048) */
|
|
1276
1357
|
this.python = false;
|
|
1277
1358
|
this.message_hook = null;
|
|
@@ -1283,6 +1364,14 @@ class DDB {
|
|
|
1283
1364
|
url = `${location.protocol === 'https:' ? 'wss' : 'ws'}://${hostname}${port ? `:${port}` : ''}/`;
|
|
1284
1365
|
}
|
|
1285
1366
|
this.url = url;
|
|
1367
|
+
if (options.autologin !== undefined)
|
|
1368
|
+
this.autologin = options.autologin;
|
|
1369
|
+
if (options.username !== undefined)
|
|
1370
|
+
this.username = options.username;
|
|
1371
|
+
if (options.password !== undefined)
|
|
1372
|
+
this.password = options.password;
|
|
1373
|
+
if (options.python !== undefined)
|
|
1374
|
+
this.python = options.python;
|
|
1286
1375
|
}
|
|
1287
1376
|
/** print message handler */
|
|
1288
1377
|
printer(message) {
|
|
@@ -1294,12 +1383,27 @@ class DDB {
|
|
|
1294
1383
|
get connected() {
|
|
1295
1384
|
return this.websocket?.readyState === WebSocket.OPEN;
|
|
1296
1385
|
}
|
|
1297
|
-
/** Establish the actual WebSocket connection to the DolphinDB corresponding to the URL
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1386
|
+
/** Establish the actual WebSocket connection to the DolphinDB corresponding to the URL
|
|
1387
|
+
- options?:
|
|
1388
|
+
- url?: DolphinDB WebSocket URL. By default, the WebSocket URL passed in when the instance is initialized is used
|
|
1389
|
+
- autologin?: Whether to log in automatically after establishing a connection, default `true`
|
|
1390
|
+
- username?: DolphinDB username, default `'admin'`
|
|
1391
|
+
- password?: DolphinDB password, default `'123456'`
|
|
1392
|
+
- python?: set python session flag, default `false`
|
|
1393
|
+
*/
|
|
1394
|
+
async connect(options = {}) {
|
|
1395
|
+
if (options.url !== undefined)
|
|
1396
|
+
this.url = options.url;
|
|
1397
|
+
if (options.autologin !== undefined)
|
|
1398
|
+
this.autologin = options.autologin;
|
|
1399
|
+
if (options.username !== undefined)
|
|
1400
|
+
this.username = options.username;
|
|
1401
|
+
if (options.password !== undefined)
|
|
1402
|
+
this.password = options.password;
|
|
1403
|
+
if (options.python !== undefined)
|
|
1404
|
+
this.python = options.python;
|
|
1301
1405
|
this.disconnect();
|
|
1302
|
-
let websocket = new WebSocket(url, python ? ['python'] : []);
|
|
1406
|
+
let websocket = new WebSocket(this.url, this.python ? ['python'] : []);
|
|
1303
1407
|
// https://stackoverflow.com/questions/11821096/what-is-the-difference-between-an-arraybuffer-and-a-blob/39951543
|
|
1304
1408
|
websocket.binaryType = 'arraybuffer';
|
|
1305
1409
|
this.websocket = websocket;
|
|
@@ -1351,11 +1455,11 @@ class DDB {
|
|
|
1351
1455
|
' add_node_alias\n' +
|
|
1352
1456
|
' )\n' +
|
|
1353
1457
|
'}\n', { urgent: true });
|
|
1354
|
-
if (
|
|
1458
|
+
if (this.autologin)
|
|
1355
1459
|
if (this.python)
|
|
1356
|
-
await this.eval(`login(${username.quote('double')}, ${password.quote('double')})`, { urgent: true });
|
|
1460
|
+
await this.eval(`login(${this.username.quote('double')}, ${this.password.quote('double')})`, { urgent: true });
|
|
1357
1461
|
else
|
|
1358
|
-
await this.call('login', [username, password], { urgent: true });
|
|
1462
|
+
await this.call('login', [this.username, this.password], { urgent: true });
|
|
1359
1463
|
}
|
|
1360
1464
|
get_rpc_options({ urgent = false, secondary = false, async: _async = false, pickle = false, clear = false, api = false, compress = false, cancellable = true, priority = urgent ? 8 : 4, parallelism = 8, root_id = '', limit, } = {}) {
|
|
1361
1465
|
let flag = 0;
|