dolphindb 3.1.25 → 3.1.28

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
@@ -369,6 +369,7 @@ export declare enum SqlStandard {
369
369
  }
370
370
  export interface DdbOptions {
371
371
  autologin?: boolean;
372
+ ticket?: string;
372
373
  username?: string;
373
374
  password?: string;
374
375
  python?: boolean;
@@ -404,6 +405,8 @@ export declare class DDB {
404
405
  static le_client: boolean;
405
406
  /** 是否在建立连接后自动登录,默认 true Whether to automatically log in after the connection is established, the default is true */
406
407
  autologin: boolean;
408
+ /** DolphinDB 登录 ticket,优先级比用户名密码更高,设置后不使用密码登录 */
409
+ ticket?: string;
407
410
  /** DolphinDB 登录用户名 DolphinDB username */
408
411
  username: string;
409
412
  /** DolphinDB 登录密码 DolphinDB password */
@@ -488,6 +491,10 @@ export declare class DDB {
488
491
  2. The session is stateful, and the previous state cannot be restored even after reconnection
489
492
  3. After disconnection, all previous ddb.call, ddb.eval should throw a connection error */
490
493
  connect(): Promise<void>;
494
+ /** 使用 ticket 登录
495
+ - ticket?: `this.ticket` 手动传入时会更新 this.ticket
496
+ - skip_connection_check? */
497
+ login_by_ticket(ticket?: string, skip_connection_check?: boolean): Promise<void>;
491
498
  get_rpc_options({ urgent, secondary, async: _async, pickle, clear, api, compress, cancellable, priority, parallelism, root_id, limit, }?: {
492
499
  urgent?: boolean;
493
500
  /** API 提交的任务, secondary 必须为 false */
package/browser.js CHANGED
@@ -3,7 +3,7 @@ import { blue, cyan, green, grey, magenta } from 'xshell/chalk.browser.js';
3
3
  import { concat, assert, Lock, genid, seq, zip_object, decode, check } from 'xshell/utils.browser.js';
4
4
  import { connect_websocket } from 'xshell/net.browser.js';
5
5
  import { t } from "./i18n/index.js";
6
- import { ddb_tensor_bytes, DdbChartType, DdbDurationUnit, DdbForm, generate_array_type, DdbFunctionType, DdbType, DdbVoidType, dictables, function_definition_patterns, get_big_int_128, get_time_ddbobj, get_duration_unit, get_type_name, int1282str, ipaddr2str, is_decimal_null_value, is_decimal_type, time_formatters, number_nulls, nulls, set_big_int_128, uuid2str, get_times_ddbobj, funcdefs, get_number_formatter } from "./common.js";
6
+ import { ddb_tensor_bytes, DdbChartType, DdbDurationUnit, DdbForm, generate_array_type, DdbFunctionType, DdbType, DdbVoidType, dictables, function_definition_patterns, get_big_int_128, get_time_ddbobj, get_duration_unit, get_type_name, int1282str, ipaddr2str, is_decimal_null_value, is_decimal_type, time_formatters, number_nulls, nulls, set_big_int_128, uuid2str, get_times_ddbobj, funcdefs, get_number_formatter, _urgent } from "./common.js";
7
7
  export * from "./common.js";
8
8
  /** 可以表示所有 DolphinDB 数据库中的数据类型 Can represent data types in all DolphinDB databases */
9
9
  export class DdbObj {
@@ -2425,6 +2425,8 @@ export class DDB {
2425
2425
  static le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
2426
2426
  /** 是否在建立连接后自动登录,默认 true Whether to automatically log in after the connection is established, the default is true */
2427
2427
  autologin = true;
2428
+ /** DolphinDB 登录 ticket,优先级比用户名密码更高,设置后不使用密码登录 */
2429
+ ticket;
2428
2430
  /** DolphinDB 登录用户名 DolphinDB username */
2429
2431
  username = 'admin';
2430
2432
  /** DolphinDB 登录密码 DolphinDB password */
@@ -2499,6 +2501,8 @@ export class DDB {
2499
2501
  this.verbose = options.verbose;
2500
2502
  if (options.autologin !== undefined)
2501
2503
  this.autologin = options.autologin;
2504
+ if (options.ticket)
2505
+ this.ticket = options.ticket;
2502
2506
  if (options.username !== undefined)
2503
2507
  this.username = options.username;
2504
2508
  if (options.password !== undefined)
@@ -2573,6 +2577,8 @@ export class DDB {
2573
2577
  try {
2574
2578
  assert(this.connected);
2575
2579
  await this.rpc('connect', { skip_connection_check: true });
2580
+ if (this.autologin && this.ticket)
2581
+ await this.login_by_ticket(undefined, true);
2576
2582
  if (this.streaming)
2577
2583
  await this.subscribe();
2578
2584
  resolve();
@@ -2583,6 +2589,14 @@ export class DDB {
2583
2589
  }
2584
2590
  });
2585
2591
  }
2592
+ /** 使用 ticket 登录
2593
+ - ticket?: `this.ticket` 手动传入时会更新 this.ticket
2594
+ - skip_connection_check? */
2595
+ async login_by_ticket(ticket, skip_connection_check = false) {
2596
+ if (ticket)
2597
+ this.ticket = ticket;
2598
+ await this.invoke('authenticateByTicket', [this.ticket], { urgent: true, skip_connection_check });
2599
+ }
2586
2600
  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 = 64, root_id = '', limit, } = {}) {
2587
2601
  let flag = 0;
2588
2602
  if (urgent)
@@ -2649,7 +2663,7 @@ export class DDB {
2649
2663
  const { script, func, args: _args = [], vars = [], urgent, listener, on_more_messages, } = options;
2650
2664
  if (func === 'pnode_run')
2651
2665
  try {
2652
- await (this.ppnode_run ??= this.eval(funcdefs.pnode_run[this.language], { urgent: true }));
2666
+ await (this.ppnode_run ??= this.eval(funcdefs.pnode_run[this.language], _urgent));
2653
2667
  }
2654
2668
  catch (error) {
2655
2669
  this.ppnode_run = undefined;
@@ -2701,7 +2715,7 @@ export class DDB {
2701
2715
  case 'connect':
2702
2716
  if (this.verbose)
2703
2717
  console.log('connect()' +
2704
- (this.autologin ?
2718
+ (this.autologin && !this.ticket ?
2705
2719
  '\n' +
2706
2720
  `login(${this.username.quote()}, ${this.password.quote()})`
2707
2721
  :
@@ -2710,7 +2724,7 @@ export class DDB {
2710
2724
  return 'connect\n' +
2711
2725
  // 详见 InterProcessIO.cpp#APISocketConsole::parseScript 中的
2712
2726
  // Util::startWith "connect"
2713
- (this.autologin ?
2727
+ (this.autologin && !this.ticket ?
2714
2728
  'login\n' +
2715
2729
  this.username + '\n' +
2716
2730
  this.password /* encrypted (可选参数) + '\n' + 'false' */
@@ -2822,7 +2836,7 @@ export class DDB {
2822
2836
  let args_ = args;
2823
2837
  if (node) {
2824
2838
  try {
2825
- await (this.pjsrpc ??= this.eval(funcdefs.jsrpc[this.language], { urgent: true }));
2839
+ await (this.pjsrpc ??= this.eval(funcdefs.jsrpc[this.language], _urgent));
2826
2840
  }
2827
2841
  catch (error) {
2828
2842
  this.pjsrpc = undefined;
@@ -2896,7 +2910,7 @@ export class DDB {
2896
2910
  if (has_ddbobj)
2897
2911
  throw new Error(t('调用 ddb.invoke 的参数中不能同时有 DdbObj 与复杂 js 原生对象'));
2898
2912
  try {
2899
- await (this.pinvoke ??= this.eval(funcdefs.invoke[this.language], { urgent: true }));
2913
+ await (this.pinvoke ??= this.eval(funcdefs.invoke[this.language], _urgent));
2900
2914
  }
2901
2915
  catch (error) {
2902
2916
  // invoke 没有正确执行时,重新将 pinvoke 赋值为 undefined
@@ -2929,6 +2943,7 @@ export class DDB {
2929
2943
  async cancel() {
2930
2944
  let ddb = new DDB(this.url, {
2931
2945
  autologin: this.autologin,
2946
+ ticket: this.ticket,
2932
2947
  username: this.username,
2933
2948
  password: this.password,
2934
2949
  verbose: this.verbose
@@ -2937,7 +2952,7 @@ export class DDB {
2937
2952
  // 因为是新建的连接,而且执行完脚本之后马上就关闭了,所以不用考虑变量泄漏的问题
2938
2953
  await ddb.eval(`jobs = exec rootJobId from getConsoleJobs() where sessionId = ${this.sid}\n` +
2939
2954
  'if (size(jobs))\n' +
2940
- ' cancelConsoleJob(jobs)\n', { urgent: true });
2955
+ ' cancelConsoleJob(jobs)\n', _urgent);
2941
2956
  }
2942
2957
  finally {
2943
2958
  ddb.disconnect();