dolphindb 2.0.944 → 2.0.946

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,21 @@ 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
+ 如果是流数据连接,还会调用 publishTable 订阅流表
568
+ 后续调用检查上面的条件
569
+ 连接断开后禁止再次调用 connect 重连原有 ddb 对象,应该通过 new DDB() 的方式新建连接对象,原因是:
570
+ 1. on_error 回调和某个 websocket 绑定了,不方便解绑后重新绑定
571
+ 2. session 是有状态的,重连也无法恢复之前的状态
572
+ 3. 断线后所有之前的 ddb.call, ddb.eval 都应该抛出连接错误
573
+
574
+ 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
575
+ 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
576
+ 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:
577
+ 1. The on_error callback is bound to a certain websocket, and it is inconvenient to unbind and rebind
578
+ 2. The session is stateful, and the previous state cannot be restored even after reconnection
579
+ 3. After disconnection, all previous ddb.call, ddb.eval should throw a connection error */
561
580
  connect(): Promise<void>;
562
581
  get_rpc_options({ urgent, secondary, async: _async, pickle, clear, api, compress, cancellable, priority, parallelism, root_id, limit, }?: {
563
582
  urgent?: boolean;
@@ -583,10 +602,10 @@ export declare class DDB {
583
602
  limit?: boolean;
584
603
  }): string;
585
604
  disconnect(): void;
586
- /** rpc through websocket (function/script/variable command)
605
+ /** (内部使用的方法) rpc through websocket (function/script/variable command)
587
606
  未连接到 DDB 时调用会自动连接,连接断开时调用会抛出 DdbConnectionError
588
607
  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'
608
+ - type: API 类型: 'script' | 'function' | 'variable' | 'connect'
590
609
  - options:
591
610
  - urgent?: 决定 `行为标识` 那一行字符串的取值(只适用于 script 和 function)
592
611
  - vars?: type === 'variable' 时必传,variable 指令中待上传的变量名
@@ -634,7 +653,7 @@ export declare class DDB {
634
653
  When it is false, the returned DdbObj only contains buffer and le without parsing,
635
654
  so as to facilitate subsequent forwarding and serialization
636
655
  */
637
- call<TResult extends DdbObj>(func: string, args?: (DdbObj | string | boolean | ArrayBuffer)[], { urgent, node, nodes, func_type, add_node_alias, listener, parse_object, }?: {
656
+ call<TResult extends DdbObj>(func: string, args?: (DdbObj | string | boolean)[], { urgent, node, nodes, func_type, add_node_alias, listener, parse_object, }?: {
638
657
  urgent?: boolean;
639
658
  node?: string;
640
659
  nodes?: string[];
@@ -672,8 +691,7 @@ export interface DdbObjectMessage {
672
691
  }
673
692
  export interface DdbErrorMessage {
674
693
  type: 'error';
675
- data: Error;
694
+ data: DdbDatabaseError;
676
695
  }
677
696
  export type DdbMessage = DdbPrintMessage | DdbObjectMessage | DdbErrorMessage;
678
- export declare let ddb: DDB;
679
697
  export {};
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,20 +2247,9 @@ 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 {
2245
- const dev = pathname.endsWith('/console/');
2246
- const hostname = searchParams.get('hostname') || (dev ? '127.0.0.1' : location.hostname);
2247
- const port = searchParams.get('port') || (dev ? '8848' : location.port);
2248
- url = `${dev ? (searchParams.get('tls') === '1' ? 'wss' : 'ws') : (location.protocol === 'https:' ? 'wss' : 'ws')}://${hostname}${port ? `:${port}` : ''}/`;
2249
- }
2250
- this.verbose = options.verbose === undefined ?
2251
- searchParams.get('verbose') === '1'
2252
- :
2253
- options.verbose;
2250
+ this.url = url;
2251
+ if (options.verbose !== undefined)
2252
+ this.verbose = options.verbose;
2254
2253
  if (options.autologin !== undefined)
2255
2254
  this.autologin = options.autologin;
2256
2255
  if (options.username !== undefined)
@@ -2263,61 +2262,87 @@ export class DDB {
2263
2262
  this.streaming = options.streaming;
2264
2263
  }
2265
2264
  on_message(buffer, websocket) {
2266
- // 这里的实现一定会被 connect, rpc 中的实现覆盖
2265
+ throw t('这是在调用 this.rpc 之前默认的 on_message, 不应该被调用到,除非建立连接后 server 先推送了 message');
2267
2266
  }
2268
- on_error(error, websocket) {
2267
+ on_error() {
2269
2268
  // 这里的实现一定会被 connect, rpc 中的实现覆盖
2270
2269
  }
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 */
2270
+ /** 调用后会确保和数据库的连接是正常的 (this.connected === true && this.errored === false),否则抛出错误
2271
+ 这个方法是幂等的,首次调用建立实际的 WebSocket 连接到 URL 对应的 DolphinDB,然后执行自动登录,
2272
+ 如果是流数据连接,还会调用 publishTable 订阅流表
2273
+ 后续调用检查上面的条件
2274
+ 连接断开后禁止再次调用 connect 重连原有 ddb 对象,应该通过 new DDB() 的方式新建连接对象,原因是:
2275
+ 1. on_error 回调和某个 websocket 绑定了,不方便解绑后重新绑定
2276
+ 2. session 是有状态的,重连也无法恢复之前的状态
2277
+ 3. 断线后所有之前的 ddb.call, ddb.eval 都应该抛出连接错误
2278
+
2279
+ 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
2280
+ 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
2281
+ 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:
2282
+ 1. The on_error callback is bound to a certain websocket, and it is inconvenient to unbind and rebind
2283
+ 2. The session is stateful, and the previous state cannot be restored even after reconnection
2284
+ 3. After disconnection, all previous ddb.call, ddb.eval should throw a connection error */
2274
2285
  async connect() {
2286
+ if (this.errored)
2287
+ throw this.error || new DdbConnectionError(this);
2275
2288
  if (this.connected)
2276
2289
  return;
2277
- const ptail = this.pconnect;
2278
- const pconnect = this.pconnect = defer();
2279
- await ptail;
2290
+ // 准备进入 websocket 临界区
2291
+ const ptail = this.pwebsocket;
2292
+ let pwebsocket = this.pwebsocket = defer();
2293
+ // 避免 pwebsocket.reject 后出现 triggerUncaughtException
2294
+ pwebsocket.catch(() => { });
2295
+ // 上一个请求出现了 websocket 错误,那么直接抛出异常,且通过 reject 当前锁 (pwebsocket),安全退出临界区
2280
2296
  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 });
2297
+ await ptail;
2298
+ // 已进入 websocket 临界区
2299
+ }
2300
+ catch (error) {
2301
+ pwebsocket.reject(error);
2302
+ throw error;
2303
+ }
2304
+ if (this.errored) {
2305
+ const error = this.error || new DdbConnectionError(this);
2306
+ pwebsocket.reject(error);
2307
+ throw error;
2308
+ }
2309
+ if (this.connected) {
2310
+ pwebsocket.resolve();
2311
+ return;
2312
+ }
2313
+ this.on_error = () => {
2314
+ pwebsocket.reject(this.error /* 一定有,不需要再 || new DdbConnectionError(this) */);
2315
+ };
2316
+ try {
2317
+ this.websocket = await connect_websocket(this.url, {
2318
+ protocols: (() => {
2319
+ if (this.streaming)
2320
+ return 'streaming';
2321
+ if (this.python)
2322
+ return 'python';
2323
+ })(),
2324
+ on_message: (buffer, websocket) => {
2325
+ this.on_message(buffer, websocket);
2326
+ },
2327
+ on_error: error => {
2328
+ this.error ??= new DdbConnectionError(this, error);
2329
+ this.on_error();
2315
2330
  }
2316
- }
2331
+ });
2317
2332
  }
2318
- finally {
2319
- pconnect.resolve();
2333
+ catch (error) {
2334
+ this.error ??= new DdbConnectionError(this, error);
2335
+ pwebsocket.reject(error);
2336
+ throw this.error;
2320
2337
  }
2338
+ assert(this.connected);
2339
+ pwebsocket.resolve();
2340
+ // websocket 临界区结束
2341
+ await this.rpc('connect', {});
2342
+ if (this.autologin)
2343
+ await this.call('login', [this.username, this.password], { urgent: true });
2344
+ if (this.streaming)
2345
+ await this.subscribe();
2321
2346
  }
2322
2347
  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
2348
  let flag = 0;
@@ -2354,10 +2379,10 @@ export class DDB {
2354
2379
  if (this.connected)
2355
2380
  this.websocket.close(1000);
2356
2381
  }
2357
- /** rpc through websocket (function/script/variable command)
2382
+ /** (内部使用的方法) rpc through websocket (function/script/variable command)
2358
2383
  未连接到 DDB 时调用会自动连接,连接断开时调用会抛出 DdbConnectionError
2359
2384
  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'
2385
+ - type: API 类型: 'script' | 'function' | 'variable' | 'connect'
2361
2386
  - options:
2362
2387
  - urgent?: 决定 `行为标识` 那一行字符串的取值(只适用于 script 和 function)
2363
2388
  - vars?: type === 'variable' 时必传,variable 指令中待上传的变量名
@@ -2365,19 +2390,27 @@ export class DDB {
2365
2390
  - parse_object?: 在本次 rpc 期间设置 parse_object, 结束后恢复原有
2366
2391
  为 false 时返回的 DdbObj 仅含有 buffer 和 le,不做解析,以便后续转发、序列化 */
2367
2392
  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;
2393
+ // 保留调用栈信息
2394
+ let error = new DdbDatabaseError('', this, type, options);
2395
+ await this.connect();
2396
+ const { script, func, args: _args = [], vars = [], urgent, listener, } = options;
2374
2397
  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;
2398
+ // 准备进入 pnode_run 临界区,保证并发调用 rpc 时只定义一次 pnode_run
2399
+ const ptail = this.ppnode_run;
2400
+ let ppnode_run = this.ppnode_run = defer();
2401
+ // 避免 ppnode_run.reject 后出现 triggerUncaughtException
2402
+ ppnode_run.catch(() => { });
2403
+ // 如果之前的定义失败了,再定义一次也会失败,直接抛出之前的错误,且安全地退出临界区
2379
2404
  try {
2380
- if (!this.pnode_run_defined)
2405
+ await ptail;
2406
+ // 已进入 pnode_run 临界区
2407
+ }
2408
+ catch (error) {
2409
+ ppnode_run.reject(error);
2410
+ throw error;
2411
+ }
2412
+ if (!this.pnode_run_defined)
2413
+ try {
2381
2414
  await this.eval(this.python ?
2382
2415
  'def pnode_run (nodes, func_name, args, add_node_alias):\n' +
2383
2416
  ' nargs = size(args)\n' +
@@ -2413,95 +2446,108 @@ export class DDB {
2413
2446
  ' add_node_alias\n' +
2414
2447
  ' )\n' +
2415
2448
  '}\n', { urgent: true });
2416
- }
2417
- finally {
2418
- ppnoderun.resolve();
2419
- }
2449
+ this.pnode_run_defined = true;
2450
+ ppnode_run.resolve();
2451
+ }
2452
+ catch (error) {
2453
+ // 这次失败了,之后的执行肯定也会失败
2454
+ ppnode_run.reject(error);
2455
+ throw error;
2456
+ }
2420
2457
  }
2421
2458
  // this 上的当前配置需要在 message 到达后使用,先保存起来
2422
- const _handlers = [...this.listeners].reverse();
2423
- let error = new DdbDatabaseError('', this, type, options);
2424
- // 临界区:保证多个 rpc 并发时形成 promise 链
2459
+ const _listeners = [...this.listeners].reverse();
2460
+ // websocket 临界区:保证多个 rpc 并发时形成 promise 链
2425
2461
  // ddb 世界观:需要等待上一个 rpc 结果从 server 返回之后才能发起下一个调用
2426
2462
  // 违反世界观可能造成:
2427
2463
  // 1. 并发多个请求只返回第一个结果(阻塞,需后续请求疏通)
2428
2464
  // 2. windows 下 ddb server 返回多个相同的结果
2429
- const ptail = this.presult;
2430
- const presult = this.presult = defer();
2465
+ const ptail = this.pwebsocket;
2466
+ let pwebsocket = this.pwebsocket = defer();
2467
+ // 避免 pwebsocket.reject 后出现 triggerUncaughtException
2468
+ pwebsocket.catch(() => { });
2469
+ // 上一个请求出现了 websocket 错误,那么直接抛出异常,且通过 reject 当前锁 (pwebsocket),安全退出临界区
2431
2470
  try {
2432
2471
  await ptail;
2472
+ // 已进入临界区,只有一个 rpc 函数调用运行到这里,可以独占 this.on_message 然后写 WebSocket
2433
2473
  }
2434
- catch { }
2435
- // 临界区结束,只有一个 rpc 函数调用运行到这里,可以独占 this.on_message 然后写 WebSocket
2436
- if (!this.connected) {
2437
- presult.reject(new DdbConnectionError(this));
2438
- return presult;
2474
+ catch (error) {
2475
+ pwebsocket.reject(error);
2476
+ throw error;
2439
2477
  }
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;
2478
+ // 既然上一个请求没有出现 websocket error,且函数开头已经调用了 await this.connect() 检查过,
2479
+ // 这里也乐观的认为 this.connected && !this.errored 为 true
2480
+ return new Promise((resolve, reject) => {
2481
+ this.on_error = () => {
2482
+ pwebsocket.reject(this.error /* 这里一定有了 this.error, 不需要再 || new DdbConnectionError(this) */);
2483
+ reject(this.error);
2484
+ };
2485
+ this.on_message = buffer => {
2486
+ try {
2487
+ const buf = new Uint8Array(buffer);
2488
+ if (this.print_message_buffer)
2489
+ console.log(buf);
2490
+ const message = this.parse_message(buf, error);
2491
+ listener?.(message, this);
2492
+ for (const listener of _listeners)
2493
+ listener(message, this);
2494
+ const { type, data } = message;
2495
+ switch (type) {
2496
+ case 'print':
2497
+ if (this.print_message)
2498
+ console.log(data);
2499
+ break;
2500
+ case 'object':
2501
+ pwebsocket.resolve();
2502
+ resolve(data);
2503
+ break;
2504
+ case 'error':
2505
+ pwebsocket.resolve();
2506
+ reject(data);
2507
+ break;
2508
+ }
2509
+ }
2510
+ catch (error) {
2511
+ pwebsocket.resolve();
2512
+ // 这里的错误并非 websocket 错误,而是 rpc 错误
2513
+ reject(error);
2514
+ }
2515
+ };
2516
+ const args = DdbObj.to_ddbobjs(_args);
2517
+ const command = this.enc.encode((() => {
2453
2518
  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;
2519
+ case 'function':
2520
+ if (this.verbose)
2521
+ console.log(func + args.map(arg => arg.toString()).join(', ').bracket());
2522
+ return 'function\n' +
2523
+ `${func}\n` +
2524
+ `${args.length}\n` +
2525
+ `${Number(DDB.le_client)}\n`;
2526
+ case 'script':
2527
+ if (this.verbose)
2528
+ console.log(script);
2529
+ return 'script\n' +
2530
+ script;
2531
+ case 'variable':
2532
+ if (this.verbose)
2533
+ for (let i = 0; i < vars.length; i++)
2534
+ console.log(`${vars[i]} = ${args[i].toString()}`);
2535
+ return 'variable\n' +
2536
+ `${vars.join(',')}\n` +
2537
+ `${vars.length}\n` +
2538
+ `${Number(DDB.le_client)}\n`;
2539
+ case 'connect':
2540
+ if (this.verbose)
2541
+ console.log('connect()');
2542
+ return 'connect\n';
2464
2543
  }
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;
2544
+ })());
2545
+ this.websocket.send(concat([
2546
+ this.enc.encode(`API2 ${this.sid} ${command.length} / ${this.get_rpc_options({ urgent })}\n`),
2547
+ command,
2548
+ ...args.map(arg => arg.pack())
2549
+ ]));
2550
+ });
2505
2551
  }
2506
2552
  /** eval script through websocket (script command)
2507
2553
  - script?: 执行的脚本 Script to execute
@@ -2653,9 +2699,6 @@ export class DDB {
2653
2699
  }
2654
2700
  /** 内部的流订阅方法 Internal stream subscription method */
2655
2701
  async subscribe() {
2656
- await this.rpc('connect', {});
2657
- if (this.autologin)
2658
- await this.call('login', [this.username, this.password]);
2659
2702
  console.log(t('订阅流表成功') + ', colnames:',
2660
2703
  // string[3](['time', 'stock', 'price'])
2661
2704
  this.streaming.colnames = (await this.call('publishTable', [
@@ -2708,5 +2751,4 @@ export class DDB {
2708
2751
  return this.streaming;
2709
2752
  }
2710
2753
  }
2711
- export let ddb = window.ddb = new DDB();
2712
2754
  //# sourceMappingURL=browser.js.map