dolphindb 2.0.500 → 2.0.503
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 +13 -3
- package/README.zh.md +13 -3
- package/browser.d.ts +51 -21
- package/browser.js +114 -60
- package/browser.js.map +1 -1
- package/index.d.ts +48 -20
- package/index.js +111 -59
- 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
|
@@ -330,14 +330,15 @@ async upload (
|
|
|
330
330
|
```
|
|
331
331
|
|
|
332
332
|
|
|
333
|
-
###
|
|
333
|
+
### Some Examples
|
|
334
334
|
```ts
|
|
335
|
-
import { nulls, DdbInt, timestamp2str, DdbVectorSymbol } from 'dolphindb'
|
|
335
|
+
import { nulls, DdbInt, timestamp2str, DdbVectorSymbol, DdbTable, DdbVectorDouble } from 'dolphindb'
|
|
336
336
|
|
|
337
337
|
// Format timestamp in DolphinDB as string
|
|
338
338
|
timestamp2str(
|
|
339
339
|
(
|
|
340
|
-
await ddb.call
|
|
340
|
+
await ddb.call('now', [false])
|
|
341
|
+
// TypeScript: await ddb.call<DdbObj<bigint>>('now', [false])
|
|
341
342
|
).value
|
|
342
343
|
) === '2022.02.23 17:23:13.494'
|
|
343
344
|
|
|
@@ -353,5 +354,14 @@ av[0] = 0.1
|
|
|
353
354
|
av[1] = nulls.double
|
|
354
355
|
av[2] = 0.3
|
|
355
356
|
new DdbVectorDouble(av)
|
|
357
|
+
|
|
358
|
+
// create DdbTable
|
|
359
|
+
new DdbTable(
|
|
360
|
+
[
|
|
361
|
+
new DdbVectorDouble([0.1, 0.2, null], 'col0'),
|
|
362
|
+
new DdbVectorSymbol(['a', 'b', 'c'], 'col1')
|
|
363
|
+
],
|
|
364
|
+
'mytable'
|
|
365
|
+
)
|
|
356
366
|
```
|
|
357
367
|
|
package/README.zh.md
CHANGED
|
@@ -331,14 +331,15 @@ async upload (
|
|
|
331
331
|
```
|
|
332
332
|
|
|
333
333
|
|
|
334
|
-
###
|
|
334
|
+
### 一些例子
|
|
335
335
|
```ts
|
|
336
|
-
import { nulls, DdbInt, timestamp2str, DdbVectorSymbol } from 'dolphindb'
|
|
336
|
+
import { nulls, DdbInt, timestamp2str, DdbVectorSymbol, DdbTable, DdbVectorDouble } from 'dolphindb'
|
|
337
337
|
|
|
338
338
|
// 将 DolphinDB 中的 timestamp 格式化为 string
|
|
339
339
|
timestamp2str(
|
|
340
340
|
(
|
|
341
|
-
await ddb.call
|
|
341
|
+
await ddb.call('now', [false])
|
|
342
|
+
// TypeScript: await ddb.call<DdbObj<bigint>>('now', [false])
|
|
342
343
|
).value
|
|
343
344
|
) === '2022.02.23 17:23:13.494'
|
|
344
345
|
|
|
@@ -354,4 +355,13 @@ av[0] = 0.1
|
|
|
354
355
|
av[1] = nulls.double
|
|
355
356
|
av[2] = 0.3
|
|
356
357
|
new DdbVectorDouble(av)
|
|
358
|
+
|
|
359
|
+
// 创建 DdbTable
|
|
360
|
+
new DdbTable(
|
|
361
|
+
[
|
|
362
|
+
new DdbVectorDouble([0.1, 0.2, null], 'col0'),
|
|
363
|
+
new DdbVectorSymbol(['a', 'b', 'c'], 'col1')
|
|
364
|
+
],
|
|
365
|
+
'mytable'
|
|
366
|
+
)
|
|
357
367
|
```
|
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;
|
|
@@ -180,26 +182,29 @@ export declare class DdbTimeStamp extends DdbObj<bigint> {
|
|
|
180
182
|
export declare class DdbNanoTimeStamp extends DdbObj<bigint> {
|
|
181
183
|
constructor(value: bigint | null);
|
|
182
184
|
}
|
|
185
|
+
export declare class DdbPair extends DdbObj<Int32Array> {
|
|
186
|
+
constructor(l: number | null, r?: number | null);
|
|
187
|
+
}
|
|
188
|
+
export declare class DdbFunction extends DdbObj<DdbFunctionDefValue> {
|
|
189
|
+
constructor(name: string, type: DdbFunctionType);
|
|
190
|
+
}
|
|
183
191
|
export declare class DdbVectorInt extends DdbObj<Int32Array> {
|
|
184
|
-
constructor(
|
|
192
|
+
constructor(ints: (number | null)[] | Int32Array, name?: string);
|
|
185
193
|
}
|
|
186
194
|
export declare class DdbVectorString extends DdbObj<string[]> {
|
|
187
|
-
constructor(
|
|
195
|
+
constructor(strings: string[], name?: string);
|
|
188
196
|
}
|
|
189
197
|
export declare class DdbVectorDouble extends DdbObj<Float64Array> {
|
|
190
|
-
constructor(
|
|
198
|
+
constructor(doubles: (number | null)[] | Float64Array, name?: string);
|
|
191
199
|
}
|
|
192
200
|
export declare class DdbVectorAny extends DdbObj {
|
|
193
|
-
constructor(
|
|
201
|
+
constructor(objs: DdbObj<DdbValue>[], name?: string);
|
|
194
202
|
}
|
|
195
203
|
export declare class DdbVectorSymbol extends DdbObj<DdbSymbolExtendedValue> {
|
|
196
|
-
constructor(
|
|
204
|
+
constructor(strings: string[], name?: string);
|
|
197
205
|
}
|
|
198
|
-
export declare class
|
|
199
|
-
constructor(
|
|
200
|
-
}
|
|
201
|
-
export declare class DdbFunction extends DdbObj<DdbFunctionDefValue> {
|
|
202
|
-
constructor(name: string, type: DdbFunctionType);
|
|
206
|
+
export declare class DdbTable extends DdbObj<DdbObj[]> {
|
|
207
|
+
constructor(columns: DdbObj[], name?: string);
|
|
203
208
|
}
|
|
204
209
|
export declare function date2str(date: number, format?: string): string;
|
|
205
210
|
export declare function datetime2str(datetime: number, format?: string): string;
|
|
@@ -248,6 +253,12 @@ export declare class DDB {
|
|
|
248
253
|
le: boolean;
|
|
249
254
|
/** little endian (client) */
|
|
250
255
|
static le_client: boolean;
|
|
256
|
+
/** Whether to automatically log in after the connection is established, the default is true */
|
|
257
|
+
autologin: boolean;
|
|
258
|
+
/** DolphinDB username */
|
|
259
|
+
username: string;
|
|
260
|
+
/** DolphinDB password */
|
|
261
|
+
password: string;
|
|
251
262
|
/** python session flag (2048) */
|
|
252
263
|
python: boolean;
|
|
253
264
|
message_hook: (message: Uint8Array) => any;
|
|
@@ -261,22 +272,41 @@ export declare class DDB {
|
|
|
261
272
|
/**
|
|
262
273
|
Initialize an instance of DolphinDB Client using the WebSocket URL
|
|
263
274
|
(without establishing an actual network connection)
|
|
275
|
+
- url?: DolphinDB WebSocket URL. e.g.:`ws://127.0.0.1:8848`, Defaults to the current page URL
|
|
276
|
+
- options?:
|
|
277
|
+
- autologin?: Whether to log in automatically after establishing a connection, default `true`
|
|
278
|
+
- username?: DolphinDB username, default `'admin'`
|
|
279
|
+
- password?: DolphinDB password, default `'123456'`
|
|
280
|
+
- python?: set python session flag, default `false`
|
|
281
|
+
|
|
264
282
|
@example
|
|
265
283
|
let ddb = new DDB('ws://127.0.0.1:8848')
|
|
266
|
-
let
|
|
284
|
+
let ddbsecure = new DDB('wss://dolphindb.com', {
|
|
285
|
+
autologin: true,
|
|
286
|
+
username: 'admin',
|
|
287
|
+
password: '123456',
|
|
288
|
+
python: false
|
|
289
|
+
})
|
|
290
|
+
*/
|
|
291
|
+
constructor(url?: string, options?: {
|
|
292
|
+
autologin?: boolean;
|
|
293
|
+
username?: string;
|
|
294
|
+
password?: string;
|
|
295
|
+
python?: boolean;
|
|
296
|
+
});
|
|
297
|
+
/** Establish the actual WebSocket connection to the DolphinDB corresponding to the URL
|
|
298
|
+
- options?:
|
|
299
|
+
- url?: DolphinDB WebSocket URL. By default, the WebSocket URL passed in when the instance is initialized is used
|
|
300
|
+
- autologin?: Whether to log in automatically after establishing a connection, default `true`
|
|
301
|
+
- username?: DolphinDB username, default `'admin'`
|
|
302
|
+
- password?: DolphinDB password, default `'123456'`
|
|
303
|
+
- python?: set python session flag, default `false`
|
|
267
304
|
*/
|
|
268
|
-
|
|
269
|
-
/** Establish the actual WebSocket connection to the DolphinDB corresponding to the URL */
|
|
270
|
-
connect({ url, login, username, password, python, }?: {
|
|
271
|
-
/** By default, the WebSocket URL passed in when the instance is initialized is used */
|
|
305
|
+
connect(options?: {
|
|
272
306
|
url?: string;
|
|
273
|
-
|
|
274
|
-
login?: boolean;
|
|
275
|
-
/** DolphinDB username */
|
|
307
|
+
autologin?: boolean;
|
|
276
308
|
username?: string;
|
|
277
|
-
/** DolphinDB password */
|
|
278
309
|
password?: string;
|
|
279
|
-
/** set python session flag */
|
|
280
310
|
python?: boolean;
|
|
281
311
|
}): Promise<void>;
|
|
282
312
|
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.
|
|
3
|
+
exports.ddb = exports.DDB = exports.str2nanotimestamp = exports.nanotimestamp2str = exports.str2timestamp = exports.timestamp2str = exports.datetime2str = exports.date2str = exports.DdbTable = exports.DdbVectorSymbol = exports.DdbVectorAny = exports.DdbVectorDouble = exports.DdbVectorString = 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"));
|
|
@@ -709,15 +709,12 @@ class DdbObj {
|
|
|
709
709
|
case DdbForm.table:
|
|
710
710
|
return [
|
|
711
711
|
Uint32Array.of(this.rows, this.cols),
|
|
712
|
-
DdbObj.enc.encode(this.name),
|
|
712
|
+
DdbObj.enc.encode(this.name || ''),
|
|
713
|
+
// column names
|
|
713
714
|
Uint8Array.of(0),
|
|
714
|
-
...DdbObj.pack_vector_body(this.value.map(col => col.name), DdbType.string, this.cols),
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
for (let i = 0; i < cols.length; i++)
|
|
718
|
-
cols[i] = this.value[i].pack();
|
|
719
|
-
return cols;
|
|
720
|
-
})()
|
|
715
|
+
...DdbObj.pack_vector_body(this.value.map((col, i) => col.name || `col${i}`), DdbType.string, this.cols),
|
|
716
|
+
// column vectors
|
|
717
|
+
...this.value.map(col => col.pack())
|
|
721
718
|
];
|
|
722
719
|
case DdbForm.dict:
|
|
723
720
|
return [
|
|
@@ -918,7 +915,9 @@ class DdbObj {
|
|
|
918
915
|
exports.DdbObj = DdbObj;
|
|
919
916
|
DdbObj.dec = new TextDecoder('utf-8');
|
|
920
917
|
DdbObj.enc = new TextEncoder();
|
|
921
|
-
/** 维护已解析的 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
|
+
*/
|
|
922
921
|
DdbObj.symbol_bases = {};
|
|
923
922
|
/** little endian (client) */
|
|
924
923
|
DdbObj.le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
|
|
@@ -1032,18 +1031,42 @@ class DdbNanoTimeStamp extends DdbObj {
|
|
|
1032
1031
|
}
|
|
1033
1032
|
}
|
|
1034
1033
|
exports.DdbNanoTimeStamp = DdbNanoTimeStamp;
|
|
1034
|
+
class DdbPair extends DdbObj {
|
|
1035
|
+
constructor(l, r = null) {
|
|
1036
|
+
super({
|
|
1037
|
+
form: DdbForm.pair,
|
|
1038
|
+
type: DdbType.int,
|
|
1039
|
+
length: 0,
|
|
1040
|
+
rows: 2,
|
|
1041
|
+
cols: 1,
|
|
1042
|
+
value: Int32Array.of(l === null ? exports.nulls.int32 : l, r === null ? exports.nulls.int32 : r)
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
exports.DdbPair = DdbPair;
|
|
1047
|
+
class DdbFunction extends DdbObj {
|
|
1048
|
+
constructor(name, type) {
|
|
1049
|
+
super({
|
|
1050
|
+
form: DdbForm.scalar,
|
|
1051
|
+
type: DdbType.functiondef,
|
|
1052
|
+
length: 0,
|
|
1053
|
+
value: { type, name }
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
exports.DdbFunction = DdbFunction;
|
|
1035
1058
|
class DdbVectorInt extends DdbObj {
|
|
1036
|
-
constructor(
|
|
1059
|
+
constructor(ints, name) {
|
|
1037
1060
|
super({
|
|
1038
1061
|
form: DdbForm.vector,
|
|
1039
1062
|
type: DdbType.int,
|
|
1040
1063
|
length: 0,
|
|
1041
|
-
rows:
|
|
1064
|
+
rows: ints.length,
|
|
1042
1065
|
cols: 1,
|
|
1043
|
-
value:
|
|
1044
|
-
|
|
1066
|
+
value: ints instanceof Int32Array ?
|
|
1067
|
+
ints
|
|
1045
1068
|
:
|
|
1046
|
-
Int32Array.from(
|
|
1069
|
+
Int32Array.from(ints, v => v === null ?
|
|
1047
1070
|
exports.nulls.int32
|
|
1048
1071
|
:
|
|
1049
1072
|
v),
|
|
@@ -1053,31 +1076,31 @@ class DdbVectorInt extends DdbObj {
|
|
|
1053
1076
|
}
|
|
1054
1077
|
exports.DdbVectorInt = DdbVectorInt;
|
|
1055
1078
|
class DdbVectorString extends DdbObj {
|
|
1056
|
-
constructor(
|
|
1079
|
+
constructor(strings, name) {
|
|
1057
1080
|
super({
|
|
1058
1081
|
form: DdbForm.vector,
|
|
1059
1082
|
type: DdbType.string,
|
|
1060
1083
|
length: 0,
|
|
1061
|
-
rows:
|
|
1084
|
+
rows: strings.length,
|
|
1062
1085
|
cols: 1,
|
|
1063
|
-
value,
|
|
1086
|
+
value: strings,
|
|
1064
1087
|
name,
|
|
1065
1088
|
});
|
|
1066
1089
|
}
|
|
1067
1090
|
}
|
|
1068
1091
|
exports.DdbVectorString = DdbVectorString;
|
|
1069
1092
|
class DdbVectorDouble extends DdbObj {
|
|
1070
|
-
constructor(
|
|
1093
|
+
constructor(doubles, name) {
|
|
1071
1094
|
super({
|
|
1072
1095
|
form: DdbForm.vector,
|
|
1073
1096
|
type: DdbType.double,
|
|
1074
1097
|
length: 0,
|
|
1075
|
-
rows:
|
|
1098
|
+
rows: doubles.length,
|
|
1076
1099
|
cols: 1,
|
|
1077
|
-
value:
|
|
1078
|
-
|
|
1100
|
+
value: doubles instanceof Float64Array ?
|
|
1101
|
+
doubles
|
|
1079
1102
|
:
|
|
1080
|
-
Float64Array.from(
|
|
1103
|
+
Float64Array.from(doubles, v => v === null ?
|
|
1081
1104
|
exports.nulls.double
|
|
1082
1105
|
:
|
|
1083
1106
|
v),
|
|
@@ -1087,27 +1110,27 @@ class DdbVectorDouble extends DdbObj {
|
|
|
1087
1110
|
}
|
|
1088
1111
|
exports.DdbVectorDouble = DdbVectorDouble;
|
|
1089
1112
|
class DdbVectorAny extends DdbObj {
|
|
1090
|
-
constructor(
|
|
1113
|
+
constructor(objs, name) {
|
|
1091
1114
|
super({
|
|
1092
1115
|
form: DdbForm.vector,
|
|
1093
1116
|
type: DdbType.any,
|
|
1094
1117
|
length: 0,
|
|
1095
|
-
rows:
|
|
1118
|
+
rows: objs.length,
|
|
1096
1119
|
cols: 1,
|
|
1097
|
-
value,
|
|
1120
|
+
value: objs,
|
|
1098
1121
|
name,
|
|
1099
1122
|
});
|
|
1100
1123
|
}
|
|
1101
1124
|
}
|
|
1102
1125
|
exports.DdbVectorAny = DdbVectorAny;
|
|
1103
1126
|
class DdbVectorSymbol extends DdbObj {
|
|
1104
|
-
constructor(
|
|
1127
|
+
constructor(strings, name) {
|
|
1105
1128
|
let map = new Map([
|
|
1106
1129
|
['', 0]
|
|
1107
1130
|
]);
|
|
1108
|
-
let data = new Uint32Array(
|
|
1109
|
-
for (let i = 0; i <
|
|
1110
|
-
const x =
|
|
1131
|
+
let data = new Uint32Array(strings.length);
|
|
1132
|
+
for (let i = 0; i < strings.length; i++) {
|
|
1133
|
+
const x = strings[i];
|
|
1111
1134
|
let index = map.get(x);
|
|
1112
1135
|
if (index === undefined) {
|
|
1113
1136
|
index = map.size;
|
|
@@ -1119,7 +1142,7 @@ class DdbVectorSymbol extends DdbObj {
|
|
|
1119
1142
|
form: DdbForm.vector,
|
|
1120
1143
|
type: DdbType.symbol_extended,
|
|
1121
1144
|
length: 0,
|
|
1122
|
-
rows:
|
|
1145
|
+
rows: strings.length,
|
|
1123
1146
|
cols: 1,
|
|
1124
1147
|
value: {
|
|
1125
1148
|
base: [...map.keys()],
|
|
@@ -1131,30 +1154,20 @@ class DdbVectorSymbol extends DdbObj {
|
|
|
1131
1154
|
}
|
|
1132
1155
|
}
|
|
1133
1156
|
exports.DdbVectorSymbol = DdbVectorSymbol;
|
|
1134
|
-
class
|
|
1135
|
-
constructor(
|
|
1157
|
+
class DdbTable extends DdbObj {
|
|
1158
|
+
constructor(columns, name = '') {
|
|
1136
1159
|
super({
|
|
1137
|
-
form: DdbForm.
|
|
1138
|
-
type: DdbType.
|
|
1139
|
-
length: 0,
|
|
1140
|
-
rows: 2,
|
|
1141
|
-
cols: 1,
|
|
1142
|
-
value: Int32Array.of(l === null ? exports.nulls.int32 : l, r === null ? exports.nulls.int32 : r)
|
|
1143
|
-
});
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
|
-
exports.DdbPair = DdbPair;
|
|
1147
|
-
class DdbFunction extends DdbObj {
|
|
1148
|
-
constructor(name, type) {
|
|
1149
|
-
super({
|
|
1150
|
-
form: DdbForm.scalar,
|
|
1151
|
-
type: DdbType.functiondef,
|
|
1160
|
+
form: DdbForm.table,
|
|
1161
|
+
type: DdbType.void,
|
|
1152
1162
|
length: 0,
|
|
1153
|
-
|
|
1163
|
+
rows: columns[0].rows,
|
|
1164
|
+
cols: columns.length,
|
|
1165
|
+
name,
|
|
1166
|
+
value: columns,
|
|
1154
1167
|
});
|
|
1155
1168
|
}
|
|
1156
1169
|
}
|
|
1157
|
-
exports.
|
|
1170
|
+
exports.DdbTable = DdbTable;
|
|
1158
1171
|
function date2str(date, format = 'YYYY.MM.DD') {
|
|
1159
1172
|
return date === exports.nulls.int32 ?
|
|
1160
1173
|
''
|
|
@@ -1248,11 +1261,23 @@ class DDB {
|
|
|
1248
1261
|
/**
|
|
1249
1262
|
Initialize an instance of DolphinDB Client using the WebSocket URL
|
|
1250
1263
|
(without establishing an actual network connection)
|
|
1264
|
+
- url?: DolphinDB WebSocket URL. e.g.:`ws://127.0.0.1:8848`, Defaults to the current page URL
|
|
1265
|
+
- options?:
|
|
1266
|
+
- autologin?: Whether to log in automatically after establishing a connection, default `true`
|
|
1267
|
+
- username?: DolphinDB username, default `'admin'`
|
|
1268
|
+
- password?: DolphinDB password, default `'123456'`
|
|
1269
|
+
- python?: set python session flag, default `false`
|
|
1270
|
+
|
|
1251
1271
|
@example
|
|
1252
1272
|
let ddb = new DDB('ws://127.0.0.1:8848')
|
|
1253
|
-
let
|
|
1273
|
+
let ddbsecure = new DDB('wss://dolphindb.com', {
|
|
1274
|
+
autologin: true,
|
|
1275
|
+
username: 'admin',
|
|
1276
|
+
password: '123456',
|
|
1277
|
+
python: false
|
|
1278
|
+
})
|
|
1254
1279
|
*/
|
|
1255
|
-
constructor(url) {
|
|
1280
|
+
constructor(url, options = {}) {
|
|
1256
1281
|
/** 当前的 session id (http 或 tcp) */
|
|
1257
1282
|
this.sid = '0';
|
|
1258
1283
|
/** utf-8 text decoder */
|
|
@@ -1261,6 +1286,12 @@ class DDB {
|
|
|
1261
1286
|
this.websocket = null;
|
|
1262
1287
|
/** little endian (server) */
|
|
1263
1288
|
this.le = true;
|
|
1289
|
+
/** Whether to automatically log in after the connection is established, the default is true */
|
|
1290
|
+
this.autologin = true;
|
|
1291
|
+
/** DolphinDB username */
|
|
1292
|
+
this.username = 'admin';
|
|
1293
|
+
/** DolphinDB password */
|
|
1294
|
+
this.password = '123456';
|
|
1264
1295
|
/** python session flag (2048) */
|
|
1265
1296
|
this.python = false;
|
|
1266
1297
|
this.message_hook = null;
|
|
@@ -1272,6 +1303,14 @@ class DDB {
|
|
|
1272
1303
|
url = `${location.protocol === 'https:' ? 'wss' : 'ws'}://${hostname}${port ? `:${port}` : ''}/`;
|
|
1273
1304
|
}
|
|
1274
1305
|
this.url = url;
|
|
1306
|
+
if (options.autologin !== undefined)
|
|
1307
|
+
this.autologin = options.autologin;
|
|
1308
|
+
if (options.username !== undefined)
|
|
1309
|
+
this.username = options.username;
|
|
1310
|
+
if (options.password !== undefined)
|
|
1311
|
+
this.password = options.password;
|
|
1312
|
+
if (options.python !== undefined)
|
|
1313
|
+
this.python = options.python;
|
|
1275
1314
|
}
|
|
1276
1315
|
/** print message handler */
|
|
1277
1316
|
printer(message) {
|
|
@@ -1283,12 +1322,27 @@ class DDB {
|
|
|
1283
1322
|
get connected() {
|
|
1284
1323
|
return this.websocket?.readyState === WebSocket.OPEN;
|
|
1285
1324
|
}
|
|
1286
|
-
/** Establish the actual WebSocket connection to the DolphinDB corresponding to the URL
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1325
|
+
/** Establish the actual WebSocket connection to the DolphinDB corresponding to the URL
|
|
1326
|
+
- options?:
|
|
1327
|
+
- url?: DolphinDB WebSocket URL. By default, the WebSocket URL passed in when the instance is initialized is used
|
|
1328
|
+
- autologin?: Whether to log in automatically after establishing a connection, default `true`
|
|
1329
|
+
- username?: DolphinDB username, default `'admin'`
|
|
1330
|
+
- password?: DolphinDB password, default `'123456'`
|
|
1331
|
+
- python?: set python session flag, default `false`
|
|
1332
|
+
*/
|
|
1333
|
+
async connect(options = {}) {
|
|
1334
|
+
if (options.url !== undefined)
|
|
1335
|
+
this.url = options.url;
|
|
1336
|
+
if (options.autologin !== undefined)
|
|
1337
|
+
this.autologin = options.autologin;
|
|
1338
|
+
if (options.username !== undefined)
|
|
1339
|
+
this.username = options.username;
|
|
1340
|
+
if (options.password !== undefined)
|
|
1341
|
+
this.password = options.password;
|
|
1342
|
+
if (options.python !== undefined)
|
|
1343
|
+
this.python = options.python;
|
|
1290
1344
|
this.disconnect();
|
|
1291
|
-
let websocket = new WebSocket(url, python ? ['python'] : []);
|
|
1345
|
+
let websocket = new WebSocket(this.url, this.python ? ['python'] : []);
|
|
1292
1346
|
// https://stackoverflow.com/questions/11821096/what-is-the-difference-between-an-arraybuffer-and-a-blob/39951543
|
|
1293
1347
|
websocket.binaryType = 'arraybuffer';
|
|
1294
1348
|
this.websocket = websocket;
|
|
@@ -1340,11 +1394,11 @@ class DDB {
|
|
|
1340
1394
|
' add_node_alias\n' +
|
|
1341
1395
|
' )\n' +
|
|
1342
1396
|
'}\n', { urgent: true });
|
|
1343
|
-
if (
|
|
1397
|
+
if (this.autologin)
|
|
1344
1398
|
if (this.python)
|
|
1345
|
-
await this.eval(`login(${username.quote('double')}, ${password.quote('double')})`, { urgent: true });
|
|
1399
|
+
await this.eval(`login(${this.username.quote('double')}, ${this.password.quote('double')})`, { urgent: true });
|
|
1346
1400
|
else
|
|
1347
|
-
await this.call('login', [username, password], { urgent: true });
|
|
1401
|
+
await this.call('login', [this.username, this.password], { urgent: true });
|
|
1348
1402
|
}
|
|
1349
1403
|
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, } = {}) {
|
|
1350
1404
|
let flag = 0;
|