dolphindb 2.0.502 → 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/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;
@@ -251,6 +253,12 @@ export declare class DDB {
251
253
  le: boolean;
252
254
  /** little endian (client) */
253
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;
254
262
  /** python session flag (2048) */
255
263
  python: boolean;
256
264
  message_hook: (message: Uint8Array) => any;
@@ -264,22 +272,41 @@ export declare class DDB {
264
272
  /**
265
273
  Initialize an instance of DolphinDB Client using the WebSocket URL
266
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
+
267
282
  @example
268
283
  let ddb = new DDB('ws://127.0.0.1:8848')
269
- let ddb_secure = new DDB('wss://dolphindb.com')
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`
270
304
  */
271
- constructor(url?: string);
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 */
305
+ connect(options?: {
275
306
  url?: string;
276
- /** Whether to automatically log in after the connection is established, the default is true */
277
- login?: boolean;
278
- /** DolphinDB username */
307
+ autologin?: boolean;
279
308
  username?: string;
280
- /** DolphinDB password */
281
309
  password?: string;
282
- /** set python session flag */
283
310
  python?: boolean;
284
311
  }): Promise<void>;
285
312
  get_rpc_options({ urgent, secondary, async: _async, pickle, clear, api, compress, cancellable, priority, parallelism, root_id, limit, }?: {
package/browser.js CHANGED
@@ -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]);
@@ -1259,11 +1261,23 @@ class DDB {
1259
1261
  /**
1260
1262
  Initialize an instance of DolphinDB Client using the WebSocket URL
1261
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
+
1262
1271
  @example
1263
1272
  let ddb = new DDB('ws://127.0.0.1:8848')
1264
- let ddb_secure = new DDB('wss://dolphindb.com')
1273
+ let ddbsecure = new DDB('wss://dolphindb.com', {
1274
+ autologin: true,
1275
+ username: 'admin',
1276
+ password: '123456',
1277
+ python: false
1278
+ })
1265
1279
  */
1266
- constructor(url) {
1280
+ constructor(url, options = {}) {
1267
1281
  /** 当前的 session id (http 或 tcp) */
1268
1282
  this.sid = '0';
1269
1283
  /** utf-8 text decoder */
@@ -1272,6 +1286,12 @@ class DDB {
1272
1286
  this.websocket = null;
1273
1287
  /** little endian (server) */
1274
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';
1275
1295
  /** python session flag (2048) */
1276
1296
  this.python = false;
1277
1297
  this.message_hook = null;
@@ -1283,6 +1303,14 @@ class DDB {
1283
1303
  url = `${location.protocol === 'https:' ? 'wss' : 'ws'}://${hostname}${port ? `:${port}` : ''}/`;
1284
1304
  }
1285
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;
1286
1314
  }
1287
1315
  /** print message handler */
1288
1316
  printer(message) {
@@ -1294,12 +1322,27 @@ class DDB {
1294
1322
  get connected() {
1295
1323
  return this.websocket?.readyState === WebSocket.OPEN;
1296
1324
  }
1297
- /** Establish the actual WebSocket connection to the DolphinDB corresponding to the URL */
1298
- async connect({ url = this.url, login = true, username = 'admin', password = '123456', python = false, } = {}) {
1299
- this.url = url;
1300
- this.python = python;
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;
1301
1344
  this.disconnect();
1302
- let websocket = new WebSocket(url, python ? ['python'] : []);
1345
+ let websocket = new WebSocket(this.url, this.python ? ['python'] : []);
1303
1346
  // https://stackoverflow.com/questions/11821096/what-is-the-difference-between-an-arraybuffer-and-a-blob/39951543
1304
1347
  websocket.binaryType = 'arraybuffer';
1305
1348
  this.websocket = websocket;
@@ -1351,11 +1394,11 @@ class DDB {
1351
1394
  ' add_node_alias\n' +
1352
1395
  ' )\n' +
1353
1396
  '}\n', { urgent: true });
1354
- if (login)
1397
+ if (this.autologin)
1355
1398
  if (this.python)
1356
- 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 });
1357
1400
  else
1358
- await this.call('login', [username, password], { urgent: true });
1401
+ await this.call('login', [this.username, this.password], { urgent: true });
1359
1402
  }
1360
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, } = {}) {
1361
1404
  let flag = 0;