dolphindb 2.0.970 → 2.0.971

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.js CHANGED
@@ -5,7 +5,7 @@ import ipaddrjs from 'ipaddr.js';
5
5
  const { fromByteArray: buf2ipaddr } = ipaddrjs;
6
6
  import 'xshell/prototype.browser.js';
7
7
  import { blue, cyan, green, grey, magenta } from 'xshell/chalk.browser.js';
8
- import { concat, assert, Lock } from 'xshell/utils.browser.js';
8
+ import { concat, assert, Lock, genid } from 'xshell/utils.browser.js';
9
9
  import { connect_websocket } from 'xshell/net.browser.js';
10
10
  import { t } from './i18n/index.js';
11
11
  import { DdbDecimal128Serializor } from './data-types/decimal-128.js';
@@ -2377,8 +2377,53 @@ class DDB {
2377
2377
  // 独占资源后先检查状态
2378
2378
  if (this.errored || !this.connected)
2379
2379
  throw this.error || new DdbConnectionError(this);
2380
+ const args = DdbObj.to_ddbobjs(_args);
2381
+ const id = genid() % 1000;
2382
+ const rpc_id = ` (id = ${id})`;
2383
+ const command = this.enc.encode((() => {
2384
+ switch (type) {
2385
+ case 'function':
2386
+ if (this.verbose)
2387
+ console.log(func + args.map(arg => arg.toString()).join(', ').bracket() + rpc_id);
2388
+ return 'function\n' +
2389
+ `${func}\n` +
2390
+ `${args.length}\n` +
2391
+ `${Number(DDB.le_client)}\n`;
2392
+ case 'script':
2393
+ if (this.verbose)
2394
+ console.log(script + rpc_id);
2395
+ return 'script\n' +
2396
+ script;
2397
+ case 'variable':
2398
+ if (this.verbose)
2399
+ for (let i = 0; i < vars.length; i++)
2400
+ console.log(`${vars[i]} = ${args[i].toString()}`);
2401
+ return 'variable\n' +
2402
+ `${vars.join(',')}\n` +
2403
+ `${vars.length}\n` +
2404
+ `${Number(DDB.le_client)}\n`;
2405
+ case 'connect':
2406
+ if (this.verbose)
2407
+ console.log('connect()' +
2408
+ (this.autologin ?
2409
+ '\n' +
2410
+ `login(${this.username.quote()}, ${this.password.quote()})`
2411
+ :
2412
+ '') +
2413
+ rpc_id);
2414
+ return 'connect\n' +
2415
+ // 详见 InterProcessIO.cpp#APISocketConsole::parseScript 中的
2416
+ // Util::startWith "connect"
2417
+ (this.autologin ?
2418
+ 'login\n' +
2419
+ this.username + '\n' +
2420
+ this.password /* encrypted (可选参数) + '\n' + 'false' */
2421
+ :
2422
+ '');
2423
+ }
2424
+ })());
2380
2425
  // 使用资源发送请求并等待请求完成
2381
- return new Promise((resolve, reject) => {
2426
+ const result = new Promise((resolve, reject) => {
2382
2427
  this.on_error = () => {
2383
2428
  // 这里一定有了 this.error, 不需要再 || new DdbConnectionError(this)
2384
2429
  reject(this.error);
@@ -2411,54 +2456,15 @@ class DDB {
2411
2456
  reject(error);
2412
2457
  }
2413
2458
  };
2414
- const args = DdbObj.to_ddbobjs(_args);
2415
- const command = this.enc.encode((() => {
2416
- switch (type) {
2417
- case 'function':
2418
- if (this.verbose)
2419
- console.log(func + args.map(arg => arg.toString()).join(', ').bracket());
2420
- return 'function\n' +
2421
- `${func}\n` +
2422
- `${args.length}\n` +
2423
- `${Number(DDB.le_client)}\n`;
2424
- case 'script':
2425
- if (this.verbose)
2426
- console.log(script);
2427
- return 'script\n' +
2428
- script;
2429
- case 'variable':
2430
- if (this.verbose)
2431
- for (let i = 0; i < vars.length; i++)
2432
- console.log(`${vars[i]} = ${args[i].toString()}`);
2433
- return 'variable\n' +
2434
- `${vars.join(',')}\n` +
2435
- `${vars.length}\n` +
2436
- `${Number(DDB.le_client)}\n`;
2437
- case 'connect':
2438
- if (this.verbose)
2439
- console.log('connect()' +
2440
- (this.autologin ?
2441
- '\n' +
2442
- `login(${this.username.quote()}, ${this.password.quote()})`
2443
- :
2444
- ''));
2445
- return 'connect\n' +
2446
- // 详见 InterProcessIO.cpp#APISocketConsole::parseScript 中的
2447
- // Util::startWith "connect"
2448
- (this.autologin ?
2449
- 'login\n' +
2450
- this.username + '\n' +
2451
- this.password /* encrypted (可选参数) + '\n' + 'false' */
2452
- :
2453
- '');
2454
- }
2455
- })());
2456
2459
  websocket.send(concat([
2457
2460
  this.enc.encode(`API2 ${this.sid} ${command.length} / ${this.get_rpc_options({ urgent })}\n`),
2458
2461
  command,
2459
2462
  ...args.map(arg => arg.pack())
2460
2463
  ]));
2461
2464
  });
2465
+ if (this.verbose)
2466
+ console.log(result, rpc_id);
2467
+ return result;
2462
2468
  });
2463
2469
  }
2464
2470
  /** eval script through websocket (script command)