dolphindb 2.0.944 → 2.0.945

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
@@ -257,7 +257,7 @@ export declare class DdbObj<TValue extends DdbValue = DdbValue> {
257
257
  /** 自动转换 js string, boolean 为 DdbObj */
258
258
  static to_ddbobj(value: DdbObj | string | boolean): DdbObj;
259
259
  /** 转换 js 数组为 DdbObj[] */
260
- static to_ddbobjs(values: any[]): DdbObj<DdbValue>[];
260
+ static to_ddbobjs(values: (DdbObj | string | boolean)[]): DdbObj<DdbValue>[];
261
261
  to_cols(): {
262
262
  title: string;
263
263
  dataIndex: string;
@@ -345,7 +345,7 @@ export declare class DdbVectorString extends DdbObj<string[]> {
345
345
  constructor(strings: string[], name?: string);
346
346
  }
347
347
  export declare class DdbVectorAny extends DdbObj {
348
- constructor(objs: (DdbObj | string | boolean | ArrayBuffer)[], name?: string);
348
+ constructor(objs: (DdbObj | string | boolean)[], name?: string);
349
349
  }
350
350
  export declare class DdbVectorSymbol extends DdbObj<DdbSymbolExtendedValue> {
351
351
  constructor(strings: string[], name?: string);
@@ -464,7 +464,7 @@ type DdbRpcType = 'script' | 'function' | 'variable' | 'connect';
464
464
  export interface DdbRpcOptions {
465
465
  script?: string;
466
466
  func?: string;
467
- args?: (DdbObj | string | boolean | ArrayBuffer)[];
467
+ args?: (DdbObj | string | boolean)[];
468
468
  vars?: string[];
469
469
  urgent?: boolean;
470
470
  listener?: DdbMessageListener;
@@ -515,12 +515,19 @@ export declare class DDB {
515
515
  print_message: boolean;
516
516
  parse_object: boolean;
517
517
  pnode_run_defined: boolean;
518
+ /** 在 websocket 收到的第一个 error 时,
519
+ 在 connect_websocket 的 on_error 回调中构造 DdbConnectionError 并保存到 DDB 对象上,
520
+ 这个 error 的错误信息最准确
521
+ this.errored 为 true 时建议 throw this.error || new DdbConnectionError(this) */
522
+ error: DdbConnectionError;
518
523
  /** DdbMessage listeners */
519
524
  listeners: DdbMessageListener[];
520
- pconnect: import("xshell/utils.browser.js").Deferred<void>;
521
- ppnoderun: import("xshell/utils.browser.js").Deferred<void>;
522
- presult: import("xshell/utils.browser.js").Deferred<DdbObj<DdbValue>>;
525
+ /** 为所有 websocket 操作加锁,包括设置 this.on_message, this.on_error, websocket.send */
526
+ pwebsocket: import("xshell/utils.browser.js").Deferred<void>;
527
+ /** 为定义 pnode_run 函数加锁,避免重复定义 */
528
+ ppnode_run: import("xshell/utils.browser.js").Deferred<void>;
523
529
  get connected(): boolean;
530
+ get errored(): boolean | DdbConnectionError;
524
531
  /**
525
532
  使用 WebSocket URL 初始化连接到 DolphinDB 的实例(不建立实际的网络连接)
526
533
  Initialize an instance of DolphinDB Client using the WebSocket URL (without establishing an actual network connection)
@@ -555,9 +562,19 @@ export declare class DDB {
555
562
  });
556
563
  private on_message;
557
564
  private on_error;
558
- /** 建立实际的 WebSocket 连接到 URL 对应的 DolphinDB Establish a actual websocket connection to the DolphindB corresponding to the URL
559
- 是幂等的,调用后会确保已连接到数据库 (确保 websocket.readyState 为 open),否则报错 After calling, it will ensure that it has been connected to the database (ensure that websocket.ReadyState is open), otherwise an error will be reported
560
- this.autologin 为 true 时自动登录 this.autologin automatically log in when it is true */
565
+ /** 调用后会确保和数据库的连接是正常的 (this.connected === true && this.errored === false),否则抛出错误
566
+ 这个方法是幂等的,首次调用建立实际的 WebSocket 连接到 URL 对应的 DolphinDB,后续调用检查上面的条件
567
+ 连接断开后禁止再次调用 connect 重连原有 ddb 对象,应该通过 new DDB() 的方式新建连接对象,原因是:
568
+ 1. on_error 回调和某个 websocket 绑定了,不方便解绑后重新绑定
569
+ 2. session 是有状态的,重连也无法恢复之前的状态
570
+ 3. 断线后所有之前的 ddb.call, ddb.eval 都应该抛出连接错误
571
+
572
+ After calling, it will ensure that the connection with the database is normal (this.connected === true && this.errored === false), otherwise an error will be thrown
573
+ This method is idempotent, the first call establishes an actual WebSocket connection to the DolphinDB corresponding to the URL, and subsequent calls check the above conditions
574
+ After the connection is disconnected, it is forbidden to call connect again to reconnect the original ddb object. You should use new DDB() to create a new connection object because:
575
+ 1. The on_error callback is bound to a certain websocket, and it is inconvenient to unbind and rebind
576
+ 2. The session is stateful, and the previous state cannot be restored even after reconnection
577
+ 3. After disconnection, all previous ddb.call, ddb.eval should throw a connection error */
561
578
  connect(): Promise<void>;
562
579
  get_rpc_options({ urgent, secondary, async: _async, pickle, clear, api, compress, cancellable, priority, parallelism, root_id, limit, }?: {
563
580
  urgent?: boolean;
@@ -583,10 +600,10 @@ export declare class DDB {
583
600
  limit?: boolean;
584
601
  }): string;
585
602
  disconnect(): void;
586
- /** rpc through websocket (function/script/variable command)
603
+ /** (内部使用的方法) rpc through websocket (function/script/variable command)
587
604
  未连接到 DDB 时调用会自动连接,连接断开时调用会抛出 DdbConnectionError
588
605
  When the DDB is not connected, the call will be automatically connected. When the connection is disconnected, the call will throw the DdbConnectionError
589
- - type: API 类型: 'script' | 'function' | 'variable'
606
+ - type: API 类型: 'script' | 'function' | 'variable' | 'connect'
590
607
  - options:
591
608
  - urgent?: 决定 `行为标识` 那一行字符串的取值(只适用于 script 和 function)
592
609
  - vars?: type === 'variable' 时必传,variable 指令中待上传的变量名
@@ -634,7 +651,7 @@ export declare class DDB {
634
651
  When it is false, the returned DdbObj only contains buffer and le without parsing,
635
652
  so as to facilitate subsequent forwarding and serialization
636
653
  */
637
- call<TResult extends DdbObj>(func: string, args?: (DdbObj | string | boolean | ArrayBuffer)[], { urgent, node, nodes, func_type, add_node_alias, listener, parse_object, }?: {
654
+ call<TResult extends DdbObj>(func: string, args?: (DdbObj | string | boolean)[], { urgent, node, nodes, func_type, add_node_alias, listener, parse_object, }?: {
638
655
  urgent?: boolean;
639
656
  node?: string;
640
657
  nodes?: string[];
@@ -672,7 +689,7 @@ export interface DdbObjectMessage {
672
689
  }
673
690
  export interface DdbErrorMessage {
674
691
  type: 'error';
675
- data: Error;
692
+ data: DdbDatabaseError;
676
693
  }
677
694
  export type DdbMessage = DdbPrintMessage | DdbObjectMessage | DdbErrorMessage;
678
695
  export declare let ddb: DDB;
package/browser.js CHANGED
@@ -1691,6 +1691,7 @@ export class DdbNanoTimeStamp extends DdbObj {
1691
1691
  }
1692
1692
  export class DdbBlob extends DdbObj {
1693
1693
  constructor(value) {
1694
+ assert(value, t('new DdbBlob 不能传空的 value'));
1694
1695
  super({
1695
1696
  form: DdbForm.scalar,
1696
1697
  type: DdbType.blob,
@@ -2204,13 +2205,22 @@ export class DDB {
2204
2205
  print_message = true;
2205
2206
  parse_object = true;
2206
2207
  pnode_run_defined = false;
2208
+ /** 在 websocket 收到的第一个 error 时,
2209
+ 在 connect_websocket 的 on_error 回调中构造 DdbConnectionError 并保存到 DDB 对象上,
2210
+ 这个 error 的错误信息最准确
2211
+ this.errored 为 true 时建议 throw this.error || new DdbConnectionError(this) */
2212
+ error;
2207
2213
  /** DdbMessage listeners */
2208
2214
  listeners = [];
2209
- pconnect = defer(null);
2210
- ppnoderun = defer(null);
2211
- presult = defer(null);
2215
+ /** 为所有 websocket 操作加锁,包括设置 this.on_message, this.on_error, websocket.send */
2216
+ pwebsocket = defer(null);
2217
+ /** 为定义 pnode_run 函数加锁,避免重复定义 */
2218
+ ppnode_run = defer(null);
2212
2219
  get connected() {
2213
- return this.websocket?.readyState === WebSocket.OPEN;
2220
+ return !this.error && this.websocket?.readyState === WebSocket.OPEN;
2221
+ }
2222
+ get errored() {
2223
+ return this.error || (this.websocket && this.websocket.readyState !== WebSocket.OPEN);
2214
2224
  }
2215
2225
  /**
2216
2226
  使用 WebSocket URL 初始化连接到 DolphinDB 的实例(不建立实际的网络连接)
@@ -2237,16 +2247,14 @@ export class DDB {
2237
2247
  })
2238
2248
  */
2239
2249
  constructor(url, options = {}) {
2240
- const _url = new URL(location.href);
2241
- const { searchParams, pathname } = _url;
2242
- if (url)
2243
- this.url = url;
2244
- else {
2250
+ const { searchParams, pathname } = new URL(location.href);
2251
+ if (!url) {
2245
2252
  const dev = pathname.endsWith('/console/');
2246
2253
  const hostname = searchParams.get('hostname') || (dev ? '127.0.0.1' : location.hostname);
2247
2254
  const port = searchParams.get('port') || (dev ? '8848' : location.port);
2248
2255
  url = `${dev ? (searchParams.get('tls') === '1' ? 'wss' : 'ws') : (location.protocol === 'https:' ? 'wss' : 'ws')}://${hostname}${port ? `:${port}` : ''}/`;
2249
2256
  }
2257
+ this.url = url;
2250
2258
  this.verbose = options.verbose === undefined ?
2251
2259
  searchParams.get('verbose') === '1'
2252
2260
  :
@@ -2263,61 +2271,85 @@ export class DDB {
2263
2271
  this.streaming = options.streaming;
2264
2272
  }
2265
2273
  on_message(buffer, websocket) {
2266
- // 这里的实现一定会被 connect, rpc 中的实现覆盖
2274
+ throw t('这是在调用 this.rpc 之前默认的 on_message, 不应该被调用到,除非建立连接后 server 先推送了 message');
2267
2275
  }
2268
- on_error(error, websocket) {
2276
+ on_error() {
2269
2277
  // 这里的实现一定会被 connect, rpc 中的实现覆盖
2270
2278
  }
2271
- /** 建立实际的 WebSocket 连接到 URL 对应的 DolphinDB Establish a actual websocket connection to the DolphindB corresponding to the URL
2272
- 是幂等的,调用后会确保已连接到数据库 (确保 websocket.readyState 为 open),否则报错 After calling, it will ensure that it has been connected to the database (ensure that websocket.ReadyState is open), otherwise an error will be reported
2273
- this.autologin 为 true 时自动登录 this.autologin automatically log in when it is true */
2279
+ /** 调用后会确保和数据库的连接是正常的 (this.connected === true && this.errored === false),否则抛出错误
2280
+ 这个方法是幂等的,首次调用建立实际的 WebSocket 连接到 URL 对应的 DolphinDB,后续调用检查上面的条件
2281
+ 连接断开后禁止再次调用 connect 重连原有 ddb 对象,应该通过 new DDB() 的方式新建连接对象,原因是:
2282
+ 1. on_error 回调和某个 websocket 绑定了,不方便解绑后重新绑定
2283
+ 2. session 是有状态的,重连也无法恢复之前的状态
2284
+ 3. 断线后所有之前的 ddb.call, ddb.eval 都应该抛出连接错误
2285
+
2286
+ After calling, it will ensure that the connection with the database is normal (this.connected === true && this.errored === false), otherwise an error will be thrown
2287
+ This method is idempotent, the first call establishes an actual WebSocket connection to the DolphinDB corresponding to the URL, and subsequent calls check the above conditions
2288
+ After the connection is disconnected, it is forbidden to call connect again to reconnect the original ddb object. You should use new DDB() to create a new connection object because:
2289
+ 1. The on_error callback is bound to a certain websocket, and it is inconvenient to unbind and rebind
2290
+ 2. The session is stateful, and the previous state cannot be restored even after reconnection
2291
+ 3. After disconnection, all previous ddb.call, ddb.eval should throw a connection error */
2274
2292
  async connect() {
2293
+ if (this.errored)
2294
+ throw this.error || new DdbConnectionError(this);
2275
2295
  if (this.connected)
2276
2296
  return;
2277
- const ptail = this.pconnect;
2278
- const pconnect = this.pconnect = defer();
2279
- await ptail;
2297
+ // 准备进入 websocket 临界区
2298
+ const ptail = this.pwebsocket;
2299
+ let pwebsocket = this.pwebsocket = defer();
2300
+ // 避免 pwebsocket.reject 后出现 triggerUncaughtException
2301
+ pwebsocket.catch(() => { });
2302
+ // 上一个请求出现了 websocket 错误,那么直接抛出异常,且通过 reject 当前锁 (pwebsocket),安全退出临界区
2280
2303
  try {
2281
- if (!this.connected) {
2282
- this.on_error = (error, websocket) => {
2283
- pconnect.reject(new DdbConnectionError(this, error));
2284
- };
2285
- this.on_message = (buffer, websocket) => {
2286
- assert(false, t('这是在调用 this.rpc 之前默认的 on_message, 不应该被调用到,除非建立连接后 server 先推送了 message'));
2287
- };
2288
- this.presult = defer(null);
2289
- this.pnode_run_defined = false;
2290
- try {
2291
- this.websocket = await connect_websocket(this.url, {
2292
- protocols: (() => {
2293
- if (this.streaming)
2294
- return 'streaming';
2295
- if (this.python)
2296
- return 'python';
2297
- })(),
2298
- on_message: (buffer, websocket) => {
2299
- this.on_message(buffer, websocket);
2300
- },
2301
- on_error: (error, websocket) => {
2302
- this.on_error(error, websocket);
2303
- }
2304
- });
2305
- }
2306
- catch (error) {
2307
- throw new DdbConnectionError(this, error);
2308
- }
2309
- if (this.streaming)
2310
- await this.subscribe();
2311
- else {
2312
- await this.rpc('connect', {});
2313
- if (this.autologin)
2314
- await this.call('login', [this.username, this.password], { urgent: true });
2304
+ await ptail;
2305
+ // 已进入 websocket 临界区
2306
+ }
2307
+ catch (error) {
2308
+ pwebsocket.reject(error);
2309
+ throw error;
2310
+ }
2311
+ if (this.errored) {
2312
+ const error = this.error || new DdbConnectionError(this);
2313
+ pwebsocket.reject(error);
2314
+ throw error;
2315
+ }
2316
+ if (this.connected) {
2317
+ pwebsocket.resolve();
2318
+ return;
2319
+ }
2320
+ this.on_error = () => {
2321
+ pwebsocket.reject(this.error /* 一定有,不需要再 || new DdbConnectionError(this) */);
2322
+ };
2323
+ try {
2324
+ this.websocket = await connect_websocket(this.url, {
2325
+ protocols: (() => {
2326
+ if (this.streaming)
2327
+ return 'streaming';
2328
+ if (this.python)
2329
+ return 'python';
2330
+ })(),
2331
+ on_message: (buffer, websocket) => {
2332
+ this.on_message(buffer, websocket);
2333
+ },
2334
+ on_error: error => {
2335
+ this.error ??= new DdbConnectionError(this, error);
2336
+ this.on_error();
2315
2337
  }
2316
- }
2338
+ });
2317
2339
  }
2318
- finally {
2319
- pconnect.resolve();
2340
+ catch (error) {
2341
+ this.error ??= new DdbConnectionError(this, error);
2342
+ pwebsocket.reject(error);
2343
+ throw this.error;
2320
2344
  }
2345
+ assert(this.connected);
2346
+ pwebsocket.resolve();
2347
+ // websocket 临界区结束
2348
+ await this.rpc('connect', {});
2349
+ if (this.autologin)
2350
+ await this.call('login', [this.username, this.password], { urgent: true });
2351
+ if (this.streaming)
2352
+ await this.subscribe();
2321
2353
  }
2322
2354
  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, } = {}) {
2323
2355
  let flag = 0;
@@ -2354,10 +2386,10 @@ export class DDB {
2354
2386
  if (this.connected)
2355
2387
  this.websocket.close(1000);
2356
2388
  }
2357
- /** rpc through websocket (function/script/variable command)
2389
+ /** (内部使用的方法) rpc through websocket (function/script/variable command)
2358
2390
  未连接到 DDB 时调用会自动连接,连接断开时调用会抛出 DdbConnectionError
2359
2391
  When the DDB is not connected, the call will be automatically connected. When the connection is disconnected, the call will throw the DdbConnectionError
2360
- - type: API 类型: 'script' | 'function' | 'variable'
2392
+ - type: API 类型: 'script' | 'function' | 'variable' | 'connect'
2361
2393
  - options:
2362
2394
  - urgent?: 决定 `行为标识` 那一行字符串的取值(只适用于 script 和 function)
2363
2395
  - vars?: type === 'variable' 时必传,variable 指令中待上传的变量名
@@ -2365,19 +2397,27 @@ export class DDB {
2365
2397
  - parse_object?: 在本次 rpc 期间设置 parse_object, 结束后恢复原有
2366
2398
  为 false 时返回的 DdbObj 仅含有 buffer 和 le,不做解析,以便后续转发、序列化 */
2367
2399
  async rpc(type, options) {
2368
- if (!this.websocket)
2369
- await this.connect();
2370
- if (!this.connected)
2371
- throw new DdbConnectionError(this);
2372
- const { script, func, vars = [], urgent, listener, } = options;
2373
- let { args = [] } = options;
2400
+ // 保留调用栈信息
2401
+ let error = new DdbDatabaseError('', this, type, options);
2402
+ await this.connect();
2403
+ const { script, func, args: _args = [], vars = [], urgent, listener, } = options;
2374
2404
  if (func === 'pnode_run' && !this.pnode_run_defined) {
2375
- // 保证并发调用 rpc 时只定义一次 pnode_run
2376
- const ptail = this.ppnoderun;
2377
- const ppnoderun = this.ppnoderun = defer();
2378
- await ptail;
2405
+ // 准备进入 pnode_run 临界区,保证并发调用 rpc 时只定义一次 pnode_run
2406
+ const ptail = this.ppnode_run;
2407
+ let ppnode_run = this.ppnode_run = defer();
2408
+ // 避免 ppnode_run.reject 后出现 triggerUncaughtException
2409
+ ppnode_run.catch(() => { });
2410
+ // 如果之前的定义失败了,再定义一次也会失败,直接抛出之前的错误,且安全地退出临界区
2379
2411
  try {
2380
- if (!this.pnode_run_defined)
2412
+ await ptail;
2413
+ // 已进入 pnode_run 临界区
2414
+ }
2415
+ catch (error) {
2416
+ ppnode_run.reject(error);
2417
+ throw error;
2418
+ }
2419
+ if (!this.pnode_run_defined)
2420
+ try {
2381
2421
  await this.eval(this.python ?
2382
2422
  'def pnode_run (nodes, func_name, args, add_node_alias):\n' +
2383
2423
  ' nargs = size(args)\n' +
@@ -2413,95 +2453,108 @@ export class DDB {
2413
2453
  ' add_node_alias\n' +
2414
2454
  ' )\n' +
2415
2455
  '}\n', { urgent: true });
2416
- }
2417
- finally {
2418
- ppnoderun.resolve();
2419
- }
2456
+ this.pnode_run_defined = true;
2457
+ ppnode_run.resolve();
2458
+ }
2459
+ catch (error) {
2460
+ // 这次失败了,之后的执行肯定也会失败
2461
+ ppnode_run.reject(error);
2462
+ throw error;
2463
+ }
2420
2464
  }
2421
2465
  // this 上的当前配置需要在 message 到达后使用,先保存起来
2422
- const _handlers = [...this.listeners].reverse();
2423
- let error = new DdbDatabaseError('', this, type, options);
2424
- // 临界区:保证多个 rpc 并发时形成 promise 链
2466
+ const _listeners = [...this.listeners].reverse();
2467
+ // websocket 临界区:保证多个 rpc 并发时形成 promise 链
2425
2468
  // ddb 世界观:需要等待上一个 rpc 结果从 server 返回之后才能发起下一个调用
2426
2469
  // 违反世界观可能造成:
2427
2470
  // 1. 并发多个请求只返回第一个结果(阻塞,需后续请求疏通)
2428
2471
  // 2. windows 下 ddb server 返回多个相同的结果
2429
- const ptail = this.presult;
2430
- const presult = this.presult = defer();
2472
+ const ptail = this.pwebsocket;
2473
+ let pwebsocket = this.pwebsocket = defer();
2474
+ // 避免 pwebsocket.reject 后出现 triggerUncaughtException
2475
+ pwebsocket.catch(() => { });
2476
+ // 上一个请求出现了 websocket 错误,那么直接抛出异常,且通过 reject 当前锁 (pwebsocket),安全退出临界区
2431
2477
  try {
2432
2478
  await ptail;
2479
+ // 已进入临界区,只有一个 rpc 函数调用运行到这里,可以独占 this.on_message 然后写 WebSocket
2433
2480
  }
2434
- catch { }
2435
- // 临界区结束,只有一个 rpc 函数调用运行到这里,可以独占 this.on_message 然后写 WebSocket
2436
- if (!this.connected) {
2437
- presult.reject(new DdbConnectionError(this));
2438
- return presult;
2481
+ catch (error) {
2482
+ pwebsocket.reject(error);
2483
+ throw error;
2439
2484
  }
2440
- this.on_error = (error, websocket) => {
2441
- presult.reject(new DdbConnectionError(this, error));
2442
- };
2443
- this.on_message = buffer => {
2444
- try {
2445
- const buf = new Uint8Array(buffer);
2446
- if (this.print_message_buffer)
2447
- console.log(buf);
2448
- const message = this.parse_message(buf, error);
2449
- listener?.(message, this);
2450
- for (const listener of _handlers)
2451
- listener(message, this);
2452
- const { type, data } = message;
2485
+ // 既然上一个请求没有出现 websocket error,且函数开头已经调用了 await this.connect() 检查过,
2486
+ // 这里也乐观的认为 this.connected && !this.errored 为 true
2487
+ return new Promise((resolve, reject) => {
2488
+ this.on_error = () => {
2489
+ pwebsocket.reject(this.error /* 这里一定有了 this.error, 不需要再 || new DdbConnectionError(this) */);
2490
+ reject(this.error);
2491
+ };
2492
+ this.on_message = buffer => {
2493
+ try {
2494
+ const buf = new Uint8Array(buffer);
2495
+ if (this.print_message_buffer)
2496
+ console.log(buf);
2497
+ const message = this.parse_message(buf, error);
2498
+ listener?.(message, this);
2499
+ for (const listener of _listeners)
2500
+ listener(message, this);
2501
+ const { type, data } = message;
2502
+ switch (type) {
2503
+ case 'print':
2504
+ if (this.print_message)
2505
+ console.log(data);
2506
+ break;
2507
+ case 'object':
2508
+ pwebsocket.resolve();
2509
+ resolve(data);
2510
+ break;
2511
+ case 'error':
2512
+ pwebsocket.resolve();
2513
+ reject(data);
2514
+ break;
2515
+ }
2516
+ }
2517
+ catch (error) {
2518
+ pwebsocket.resolve();
2519
+ // 这里的错误并非 websocket 错误,而是 rpc 错误
2520
+ reject(error);
2521
+ }
2522
+ };
2523
+ const args = DdbObj.to_ddbobjs(_args);
2524
+ const command = this.enc.encode((() => {
2453
2525
  switch (type) {
2454
- case 'print':
2455
- if (this.print_message)
2456
- console.log(data);
2457
- return;
2458
- case 'object':
2459
- presult.resolve(data);
2460
- return;
2461
- case 'error':
2462
- presult.reject(data);
2463
- return;
2526
+ case 'function':
2527
+ if (this.verbose)
2528
+ console.log(func + args.map(arg => arg.toString()).join(', ').bracket());
2529
+ return 'function\n' +
2530
+ `${func}\n` +
2531
+ `${args.length}\n` +
2532
+ `${Number(DDB.le_client)}\n`;
2533
+ case 'script':
2534
+ if (this.verbose)
2535
+ console.log(script);
2536
+ return 'script\n' +
2537
+ script;
2538
+ case 'variable':
2539
+ if (this.verbose)
2540
+ for (let i = 0; i < vars.length; i++)
2541
+ console.log(`${vars[i]} = ${args[i].toString()}`);
2542
+ return 'variable\n' +
2543
+ `${vars.join(',')}\n` +
2544
+ `${vars.length}\n` +
2545
+ `${Number(DDB.le_client)}\n`;
2546
+ case 'connect':
2547
+ if (this.verbose)
2548
+ console.log('connect()');
2549
+ return 'connect\n';
2464
2550
  }
2465
- }
2466
- catch (error) {
2467
- presult.reject(error);
2468
- }
2469
- };
2470
- args = DdbObj.to_ddbobjs(args);
2471
- const command = this.enc.encode((() => {
2472
- switch (type) {
2473
- case 'function':
2474
- if (this.verbose)
2475
- console.log(func + args.map(arg => arg.toString()).join(', ').bracket());
2476
- return 'function\n' +
2477
- `${func}\n` +
2478
- `${args.length}\n` +
2479
- `${Number(DDB.le_client)}\n`;
2480
- case 'script':
2481
- if (this.verbose)
2482
- console.log(script);
2483
- return 'script\n' +
2484
- script;
2485
- case 'variable':
2486
- if (this.verbose)
2487
- for (let i = 0; i < vars.length; i++)
2488
- console.log(`${vars[i]} = ${args[i].toString()}`);
2489
- return 'variable\n' +
2490
- `${vars.join(',')}\n` +
2491
- `${vars.length}\n` +
2492
- `${Number(DDB.le_client)}\n`;
2493
- case 'connect':
2494
- if (this.verbose)
2495
- console.log('connect()');
2496
- return 'connect\n';
2497
- }
2498
- })());
2499
- this.websocket.send(concat([
2500
- this.enc.encode(`API2 ${this.sid} ${command.length} / ${this.get_rpc_options({ urgent })}\n`),
2501
- command,
2502
- ...args.map((arg) => arg.pack())
2503
- ]));
2504
- return presult;
2551
+ })());
2552
+ this.websocket.send(concat([
2553
+ this.enc.encode(`API2 ${this.sid} ${command.length} / ${this.get_rpc_options({ urgent })}\n`),
2554
+ command,
2555
+ ...args.map(arg => arg.pack())
2556
+ ]));
2557
+ });
2505
2558
  }
2506
2559
  /** eval script through websocket (script command)
2507
2560
  - script?: 执行的脚本 Script to execute
@@ -2653,9 +2706,6 @@ export class DDB {
2653
2706
  }
2654
2707
  /** 内部的流订阅方法 Internal stream subscription method */
2655
2708
  async subscribe() {
2656
- await this.rpc('connect', {});
2657
- if (this.autologin)
2658
- await this.call('login', [this.username, this.password]);
2659
2709
  console.log(t('订阅流表成功') + ', colnames:',
2660
2710
  // string[3](['time', 'stock', 'price'])
2661
2711
  this.streaming.colnames = (await this.call('publishTable', [