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/index.d.ts
CHANGED
|
@@ -180,26 +180,29 @@ export declare class DdbTimeStamp extends DdbObj<bigint> {
|
|
|
180
180
|
export declare class DdbNanoTimeStamp extends DdbObj<bigint> {
|
|
181
181
|
constructor(value: bigint | null);
|
|
182
182
|
}
|
|
183
|
+
export declare class DdbPair extends DdbObj<Int32Array> {
|
|
184
|
+
constructor(l: number | null, r?: number | null);
|
|
185
|
+
}
|
|
186
|
+
export declare class DdbFunction extends DdbObj<DdbFunctionDefValue> {
|
|
187
|
+
constructor(name: string, type: DdbFunctionType);
|
|
188
|
+
}
|
|
183
189
|
export declare class DdbVectorInt extends DdbObj<Int32Array> {
|
|
184
|
-
constructor(
|
|
190
|
+
constructor(ints: (number | null)[] | Int32Array, name?: string);
|
|
185
191
|
}
|
|
186
192
|
export declare class DdbVectorString extends DdbObj<string[]> {
|
|
187
|
-
constructor(
|
|
193
|
+
constructor(strings: string[], name?: string);
|
|
188
194
|
}
|
|
189
195
|
export declare class DdbVectorDouble extends DdbObj<Float64Array> {
|
|
190
|
-
constructor(
|
|
196
|
+
constructor(doubles: (number | null)[] | Float64Array, name?: string);
|
|
191
197
|
}
|
|
192
198
|
export declare class DdbVectorAny extends DdbObj {
|
|
193
|
-
constructor(
|
|
199
|
+
constructor(objs: DdbObj<DdbValue>[], name?: string);
|
|
194
200
|
}
|
|
195
201
|
export declare class DdbVectorSymbol extends DdbObj<DdbSymbolExtendedValue> {
|
|
196
|
-
constructor(
|
|
197
|
-
}
|
|
198
|
-
export declare class DdbPair extends DdbObj<Int32Array> {
|
|
199
|
-
constructor(l: number | null, r?: number | null);
|
|
202
|
+
constructor(strings: string[], name?: string);
|
|
200
203
|
}
|
|
201
|
-
export declare class
|
|
202
|
-
constructor(
|
|
204
|
+
export declare class DdbTable extends DdbObj<DdbObj[]> {
|
|
205
|
+
constructor(columns: DdbObj[], name?: string);
|
|
203
206
|
}
|
|
204
207
|
export declare function date2str(date: number, format?: string): string;
|
|
205
208
|
export declare function datetime2str(datetime: number, format?: string): string;
|
|
@@ -249,6 +252,12 @@ export declare class DDB {
|
|
|
249
252
|
le: boolean;
|
|
250
253
|
/** little endian (client) */
|
|
251
254
|
static le_client: boolean;
|
|
255
|
+
/** 是否在建立连接后自动登录,默认 true */
|
|
256
|
+
autologin: boolean;
|
|
257
|
+
/** DolphinDB 登录用户名 */
|
|
258
|
+
username: string;
|
|
259
|
+
/** DolphinDB 登录密码 */
|
|
260
|
+
password: string;
|
|
252
261
|
/** python session flag (2048) */
|
|
253
262
|
python: boolean;
|
|
254
263
|
message_hook: (message: Uint8Array) => any;
|
|
@@ -262,22 +271,41 @@ export declare class DDB {
|
|
|
262
271
|
/**
|
|
263
272
|
Initialize an instance of DolphinDB Client using the WebSocket URL
|
|
264
273
|
(without establishing an actual network connection)
|
|
274
|
+
- url: DolphinDB WebSocket URL. e.g.:`ws://127.0.0.1:8848`
|
|
275
|
+
- options?:
|
|
276
|
+
- autologin?: Whether to log in automatically after establishing a connection, default `true`
|
|
277
|
+
- username?: DolphinDB username, default `'admin'`
|
|
278
|
+
- password?: DolphinDB password, default `'123456'`
|
|
279
|
+
- python?: set python session flag, default `false`
|
|
280
|
+
|
|
265
281
|
@example
|
|
266
282
|
let ddb = new DDB('ws://127.0.0.1:8848')
|
|
267
|
-
let
|
|
283
|
+
let ddbsecure = new DDB('wss://dolphindb.com', {
|
|
284
|
+
autologin: true,
|
|
285
|
+
username: 'admin',
|
|
286
|
+
password: '123456',
|
|
287
|
+
python: false
|
|
288
|
+
})
|
|
289
|
+
*/
|
|
290
|
+
constructor(url: string, options?: {
|
|
291
|
+
autologin?: boolean;
|
|
292
|
+
username?: string;
|
|
293
|
+
password?: string;
|
|
294
|
+
python?: boolean;
|
|
295
|
+
});
|
|
296
|
+
/** Establish the actual WebSocket connection to the DolphinDB corresponding to the URL
|
|
297
|
+
- options?:
|
|
298
|
+
- url?: DolphinDB WebSocket URL. By default, the WebSocket URL passed in when the instance is initialized is used
|
|
299
|
+
- autologin?: Whether to log in automatically after establishing a connection, default `true`
|
|
300
|
+
- username?: DolphinDB username, default `'admin'`
|
|
301
|
+
- password?: DolphinDB password, default `'123456'`
|
|
302
|
+
- python?: set python session flag, default `false`
|
|
268
303
|
*/
|
|
269
|
-
|
|
270
|
-
/** Establish the actual WebSocket connection to the DolphinDB corresponding to the URL */
|
|
271
|
-
connect({ url, login, username, password, python, }?: {
|
|
272
|
-
/** By default, the WebSocket URL passed in when the instance is initialized is used */
|
|
304
|
+
connect(options?: {
|
|
273
305
|
url?: string;
|
|
274
|
-
|
|
275
|
-
login?: boolean;
|
|
276
|
-
/** DolphinDB username */
|
|
306
|
+
autologin?: boolean;
|
|
277
307
|
username?: string;
|
|
278
|
-
/** DolphinDB password */
|
|
279
308
|
password?: string;
|
|
280
|
-
/** set python session flag */
|
|
281
309
|
python?: boolean;
|
|
282
310
|
}): Promise<void>;
|
|
283
311
|
get_rpc_options({ urgent, secondary, async: _async, pickle, clear, api, compress, cancellable, priority, parallelism, root_id, limit, }?: {
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DDB = exports.str2nanotimestamp = exports.nanotimestamp2str = exports.str2timestamp = exports.timestamp2str = exports.datetime2str = exports.date2str = exports.
|
|
3
|
+
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.ddb_sizes = exports.DdbType = exports.DdbForm = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const ws_1 = require("ws");
|
|
6
6
|
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
@@ -746,15 +746,12 @@ class DdbObj {
|
|
|
746
746
|
case DdbForm.table:
|
|
747
747
|
return [
|
|
748
748
|
Uint32Array.of(this.rows, this.cols),
|
|
749
|
-
DdbObj.enc.encode(this.name),
|
|
749
|
+
DdbObj.enc.encode(this.name || ''),
|
|
750
|
+
// column names
|
|
750
751
|
Uint8Array.of(0),
|
|
751
|
-
...DdbObj.pack_vector_body(this.value.map(col => col.name), DdbType.string, this.cols),
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
for (let i = 0; i < cols.length; i++)
|
|
755
|
-
cols[i] = this.value[i].pack();
|
|
756
|
-
return cols;
|
|
757
|
-
})()
|
|
752
|
+
...DdbObj.pack_vector_body(this.value.map((col, i) => col.name || `col${i}`), DdbType.string, this.cols),
|
|
753
|
+
// column vectors
|
|
754
|
+
...this.value.map(col => col.pack())
|
|
758
755
|
];
|
|
759
756
|
case DdbForm.dict:
|
|
760
757
|
return [
|
|
@@ -1053,18 +1050,42 @@ class DdbNanoTimeStamp extends DdbObj {
|
|
|
1053
1050
|
}
|
|
1054
1051
|
}
|
|
1055
1052
|
exports.DdbNanoTimeStamp = DdbNanoTimeStamp;
|
|
1053
|
+
class DdbPair extends DdbObj {
|
|
1054
|
+
constructor(l, r = null) {
|
|
1055
|
+
super({
|
|
1056
|
+
form: DdbForm.pair,
|
|
1057
|
+
type: DdbType.int,
|
|
1058
|
+
length: 0,
|
|
1059
|
+
rows: 2,
|
|
1060
|
+
cols: 1,
|
|
1061
|
+
value: Int32Array.of(l === null ? exports.nulls.int32 : l, r === null ? exports.nulls.int32 : r)
|
|
1062
|
+
});
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
exports.DdbPair = DdbPair;
|
|
1066
|
+
class DdbFunction extends DdbObj {
|
|
1067
|
+
constructor(name, type) {
|
|
1068
|
+
super({
|
|
1069
|
+
form: DdbForm.scalar,
|
|
1070
|
+
type: DdbType.functiondef,
|
|
1071
|
+
length: 0,
|
|
1072
|
+
value: { type, name }
|
|
1073
|
+
});
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
exports.DdbFunction = DdbFunction;
|
|
1056
1077
|
class DdbVectorInt extends DdbObj {
|
|
1057
|
-
constructor(
|
|
1078
|
+
constructor(ints, name) {
|
|
1058
1079
|
super({
|
|
1059
1080
|
form: DdbForm.vector,
|
|
1060
1081
|
type: DdbType.int,
|
|
1061
1082
|
length: 0,
|
|
1062
|
-
rows:
|
|
1083
|
+
rows: ints.length,
|
|
1063
1084
|
cols: 1,
|
|
1064
|
-
value:
|
|
1065
|
-
|
|
1085
|
+
value: ints instanceof Int32Array ?
|
|
1086
|
+
ints
|
|
1066
1087
|
:
|
|
1067
|
-
Int32Array.from(
|
|
1088
|
+
Int32Array.from(ints, v => v === null ?
|
|
1068
1089
|
exports.nulls.int32
|
|
1069
1090
|
:
|
|
1070
1091
|
v),
|
|
@@ -1074,31 +1095,31 @@ class DdbVectorInt extends DdbObj {
|
|
|
1074
1095
|
}
|
|
1075
1096
|
exports.DdbVectorInt = DdbVectorInt;
|
|
1076
1097
|
class DdbVectorString extends DdbObj {
|
|
1077
|
-
constructor(
|
|
1098
|
+
constructor(strings, name) {
|
|
1078
1099
|
super({
|
|
1079
1100
|
form: DdbForm.vector,
|
|
1080
1101
|
type: DdbType.string,
|
|
1081
1102
|
length: 0,
|
|
1082
|
-
rows:
|
|
1103
|
+
rows: strings.length,
|
|
1083
1104
|
cols: 1,
|
|
1084
|
-
value,
|
|
1105
|
+
value: strings,
|
|
1085
1106
|
name,
|
|
1086
1107
|
});
|
|
1087
1108
|
}
|
|
1088
1109
|
}
|
|
1089
1110
|
exports.DdbVectorString = DdbVectorString;
|
|
1090
1111
|
class DdbVectorDouble extends DdbObj {
|
|
1091
|
-
constructor(
|
|
1112
|
+
constructor(doubles, name) {
|
|
1092
1113
|
super({
|
|
1093
1114
|
form: DdbForm.vector,
|
|
1094
1115
|
type: DdbType.double,
|
|
1095
1116
|
length: 0,
|
|
1096
|
-
rows:
|
|
1117
|
+
rows: doubles.length,
|
|
1097
1118
|
cols: 1,
|
|
1098
|
-
value:
|
|
1099
|
-
|
|
1119
|
+
value: doubles instanceof Float64Array ?
|
|
1120
|
+
doubles
|
|
1100
1121
|
:
|
|
1101
|
-
Float64Array.from(
|
|
1122
|
+
Float64Array.from(doubles, v => v === null ?
|
|
1102
1123
|
exports.nulls.double
|
|
1103
1124
|
:
|
|
1104
1125
|
v),
|
|
@@ -1108,27 +1129,27 @@ class DdbVectorDouble extends DdbObj {
|
|
|
1108
1129
|
}
|
|
1109
1130
|
exports.DdbVectorDouble = DdbVectorDouble;
|
|
1110
1131
|
class DdbVectorAny extends DdbObj {
|
|
1111
|
-
constructor(
|
|
1132
|
+
constructor(objs, name) {
|
|
1112
1133
|
super({
|
|
1113
1134
|
form: DdbForm.vector,
|
|
1114
1135
|
type: DdbType.any,
|
|
1115
1136
|
length: 0,
|
|
1116
|
-
rows:
|
|
1137
|
+
rows: objs.length,
|
|
1117
1138
|
cols: 1,
|
|
1118
|
-
value,
|
|
1139
|
+
value: objs,
|
|
1119
1140
|
name,
|
|
1120
1141
|
});
|
|
1121
1142
|
}
|
|
1122
1143
|
}
|
|
1123
1144
|
exports.DdbVectorAny = DdbVectorAny;
|
|
1124
1145
|
class DdbVectorSymbol extends DdbObj {
|
|
1125
|
-
constructor(
|
|
1146
|
+
constructor(strings, name) {
|
|
1126
1147
|
let map = new Map([
|
|
1127
1148
|
['', 0]
|
|
1128
1149
|
]);
|
|
1129
|
-
let data = new Uint32Array(
|
|
1130
|
-
for (let i = 0; i <
|
|
1131
|
-
const x =
|
|
1150
|
+
let data = new Uint32Array(strings.length);
|
|
1151
|
+
for (let i = 0; i < strings.length; i++) {
|
|
1152
|
+
const x = strings[i];
|
|
1132
1153
|
let index = map.get(x);
|
|
1133
1154
|
if (index === undefined) {
|
|
1134
1155
|
index = map.size;
|
|
@@ -1140,7 +1161,7 @@ class DdbVectorSymbol extends DdbObj {
|
|
|
1140
1161
|
form: DdbForm.vector,
|
|
1141
1162
|
type: DdbType.symbol_extended,
|
|
1142
1163
|
length: 0,
|
|
1143
|
-
rows:
|
|
1164
|
+
rows: strings.length,
|
|
1144
1165
|
cols: 1,
|
|
1145
1166
|
value: {
|
|
1146
1167
|
base: [...map.keys()],
|
|
@@ -1152,30 +1173,20 @@ class DdbVectorSymbol extends DdbObj {
|
|
|
1152
1173
|
}
|
|
1153
1174
|
}
|
|
1154
1175
|
exports.DdbVectorSymbol = DdbVectorSymbol;
|
|
1155
|
-
class
|
|
1156
|
-
constructor(
|
|
1157
|
-
super({
|
|
1158
|
-
form: DdbForm.pair,
|
|
1159
|
-
type: DdbType.int,
|
|
1160
|
-
length: 0,
|
|
1161
|
-
rows: 2,
|
|
1162
|
-
cols: 1,
|
|
1163
|
-
value: Int32Array.of(l === null ? exports.nulls.int32 : l, r === null ? exports.nulls.int32 : r)
|
|
1164
|
-
});
|
|
1165
|
-
}
|
|
1166
|
-
}
|
|
1167
|
-
exports.DdbPair = DdbPair;
|
|
1168
|
-
class DdbFunction extends DdbObj {
|
|
1169
|
-
constructor(name, type) {
|
|
1176
|
+
class DdbTable extends DdbObj {
|
|
1177
|
+
constructor(columns, name = '') {
|
|
1170
1178
|
super({
|
|
1171
|
-
form: DdbForm.
|
|
1172
|
-
type: DdbType.
|
|
1179
|
+
form: DdbForm.table,
|
|
1180
|
+
type: DdbType.void,
|
|
1173
1181
|
length: 0,
|
|
1174
|
-
|
|
1182
|
+
rows: columns[0].rows,
|
|
1183
|
+
cols: columns.length,
|
|
1184
|
+
name,
|
|
1185
|
+
value: columns,
|
|
1175
1186
|
});
|
|
1176
1187
|
}
|
|
1177
1188
|
}
|
|
1178
|
-
exports.
|
|
1189
|
+
exports.DdbTable = DdbTable;
|
|
1179
1190
|
function date2str(date, format = 'YYYY.MM.DD') {
|
|
1180
1191
|
return date === exports.nulls.int32 ?
|
|
1181
1192
|
''
|
|
@@ -1269,11 +1280,23 @@ class DDB {
|
|
|
1269
1280
|
/**
|
|
1270
1281
|
Initialize an instance of DolphinDB Client using the WebSocket URL
|
|
1271
1282
|
(without establishing an actual network connection)
|
|
1283
|
+
- url: DolphinDB WebSocket URL. e.g.:`ws://127.0.0.1:8848`
|
|
1284
|
+
- options?:
|
|
1285
|
+
- autologin?: Whether to log in automatically after establishing a connection, default `true`
|
|
1286
|
+
- username?: DolphinDB username, default `'admin'`
|
|
1287
|
+
- password?: DolphinDB password, default `'123456'`
|
|
1288
|
+
- python?: set python session flag, default `false`
|
|
1289
|
+
|
|
1272
1290
|
@example
|
|
1273
1291
|
let ddb = new DDB('ws://127.0.0.1:8848')
|
|
1274
|
-
let
|
|
1292
|
+
let ddbsecure = new DDB('wss://dolphindb.com', {
|
|
1293
|
+
autologin: true,
|
|
1294
|
+
username: 'admin',
|
|
1295
|
+
password: '123456',
|
|
1296
|
+
python: false
|
|
1297
|
+
})
|
|
1275
1298
|
*/
|
|
1276
|
-
constructor(url) {
|
|
1299
|
+
constructor(url, options = {}) {
|
|
1277
1300
|
/** 当前的 session id (http 或 tcp) */
|
|
1278
1301
|
this.sid = '0';
|
|
1279
1302
|
/** utf-8 text decoder */
|
|
@@ -1283,11 +1306,25 @@ class DDB {
|
|
|
1283
1306
|
this.websocket = null;
|
|
1284
1307
|
/** little endian (server) */
|
|
1285
1308
|
this.le = true;
|
|
1309
|
+
/** 是否在建立连接后自动登录,默认 true */
|
|
1310
|
+
this.autologin = true;
|
|
1311
|
+
/** DolphinDB 登录用户名 */
|
|
1312
|
+
this.username = 'admin';
|
|
1313
|
+
/** DolphinDB 登录密码 */
|
|
1314
|
+
this.password = '123456';
|
|
1286
1315
|
/** python session flag (2048) */
|
|
1287
1316
|
this.python = false;
|
|
1288
1317
|
this.message_hook = null;
|
|
1289
1318
|
this.presult = Promise.resolve(null);
|
|
1290
1319
|
this.url = url;
|
|
1320
|
+
if (options.autologin !== undefined)
|
|
1321
|
+
this.autologin = options.autologin;
|
|
1322
|
+
if (options.username !== undefined)
|
|
1323
|
+
this.username = options.username;
|
|
1324
|
+
if (options.password !== undefined)
|
|
1325
|
+
this.password = options.password;
|
|
1326
|
+
if (options.python !== undefined)
|
|
1327
|
+
this.python = options.python;
|
|
1291
1328
|
}
|
|
1292
1329
|
/** print message handler */
|
|
1293
1330
|
printer(message) {
|
|
@@ -1299,12 +1336,27 @@ class DDB {
|
|
|
1299
1336
|
get connected() {
|
|
1300
1337
|
return this.websocket?.readyState === ws_1.WebSocket.OPEN;
|
|
1301
1338
|
}
|
|
1302
|
-
/** Establish the actual WebSocket connection to the DolphinDB corresponding to the URL
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1339
|
+
/** Establish the actual WebSocket connection to the DolphinDB corresponding to the URL
|
|
1340
|
+
- options?:
|
|
1341
|
+
- url?: DolphinDB WebSocket URL. By default, the WebSocket URL passed in when the instance is initialized is used
|
|
1342
|
+
- autologin?: Whether to log in automatically after establishing a connection, default `true`
|
|
1343
|
+
- username?: DolphinDB username, default `'admin'`
|
|
1344
|
+
- password?: DolphinDB password, default `'123456'`
|
|
1345
|
+
- python?: set python session flag, default `false`
|
|
1346
|
+
*/
|
|
1347
|
+
async connect(options = {}) {
|
|
1348
|
+
if (options.url !== undefined)
|
|
1349
|
+
this.url = options.url;
|
|
1350
|
+
if (options.autologin !== undefined)
|
|
1351
|
+
this.autologin = options.autologin;
|
|
1352
|
+
if (options.username !== undefined)
|
|
1353
|
+
this.username = options.username;
|
|
1354
|
+
if (options.password !== undefined)
|
|
1355
|
+
this.password = options.password;
|
|
1356
|
+
if (options.python !== undefined)
|
|
1357
|
+
this.python = options.python;
|
|
1306
1358
|
this.disconnect();
|
|
1307
|
-
let websocket = new ws_1.WebSocket(url, python ? ['python'] : [], {
|
|
1359
|
+
let websocket = new ws_1.WebSocket(this.url, this.python ? ['python'] : [], {
|
|
1308
1360
|
maxPayload: 2 ** 33 // 8 GB
|
|
1309
1361
|
});
|
|
1310
1362
|
// https://stackoverflow.com/questions/11821096/what-is-the-difference-between-an-arraybuffer-and-a-blob/39951543
|
|
@@ -1358,11 +1410,11 @@ class DDB {
|
|
|
1358
1410
|
' add_node_alias\n' +
|
|
1359
1411
|
' )\n' +
|
|
1360
1412
|
'}\n', { urgent: true });
|
|
1361
|
-
if (
|
|
1413
|
+
if (this.autologin)
|
|
1362
1414
|
if (this.python)
|
|
1363
|
-
await this.eval(`login(${username.quote('double')}, ${password.quote('double')})`, { urgent: true });
|
|
1415
|
+
await this.eval(`login(${this.username.quote('double')}, ${this.password.quote('double')})`, { urgent: true });
|
|
1364
1416
|
else
|
|
1365
|
-
await this.call('login', [username, password], { urgent: true });
|
|
1417
|
+
await this.call('login', [this.username, this.password], { urgent: true });
|
|
1366
1418
|
}
|
|
1367
1419
|
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, } = {}) {
|
|
1368
1420
|
let flag = 0;
|