dolphindb 2.0.939 → 2.0.943

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
@@ -1,4 +1,5 @@
1
1
  import 'xshell/prototype.browser.js';
2
+ import { type WebSocketConnectionError } from 'xshell/net.browser.js';
2
3
  export declare enum DdbForm {
3
4
  scalar = 0,
4
5
  vector = 1,
@@ -181,8 +182,8 @@ DdbSymbolExtendedValue | DdbArrayVectorValue | DdbDecimal32VectorValue | DdbDeci
181
182
  export type DdbValue = DdbScalarValue | DdbVectorValue | DdbMatrixValue | DdbDictValue | DdbChartValue;
182
183
  export type DdbStringObj = DdbObj<string>;
183
184
  export type DdbVectorObj<TValue extends DdbVectorValue = DdbVectorValue> = DdbObj<TValue>;
184
- export type DdbVectorAnyObj = DdbObj<DdbObj[]>;
185
- export type DdbVectorStringObj = DdbObj<string[]>;
185
+ export type DdbVectorAnyObj = DdbVectorObj<DdbObj[]>;
186
+ export type DdbVectorStringObj = DdbVectorObj<string[]>;
186
187
  export type DdbTableObj<TColumns extends DdbVectorObj[] = DdbVectorObj[]> = DdbObj<TColumns>;
187
188
  export type DdbDictObj<TKeys extends DdbVectorObj = DdbVectorObj, TValues extends DdbVectorObj = DdbVectorObj> = DdbObj<[TKeys, TValues]>;
188
189
  export type DdbMatrixObj<TValue extends DdbMatrixValue = DdbMatrixValue> = DdbObj<TValue>;
@@ -471,8 +472,9 @@ export interface DdbRpcOptions {
471
472
  }
472
473
  export declare class DdbConnectionError extends Error {
473
474
  name: string;
475
+ cause?: WebSocketConnectionError;
474
476
  ddb: DDB;
475
- constructor(ddb: DDB, error_options?: ErrorOptions);
477
+ constructor(ddb: DDB, error?: WebSocketConnectionError);
476
478
  }
477
479
  export declare class DdbDatabaseError extends Error {
478
480
  name: string;
@@ -548,6 +550,7 @@ export declare class DDB {
548
550
  streaming?: StreamingParams;
549
551
  });
550
552
  private on_message;
553
+ private on_error;
551
554
  /** 建立实际的 WebSocket 连接到 URL 对应的 DolphinDB Establish a actual websocket connection to the DolphindB corresponding to the URL
552
555
  是幂等的,调用后会确保已连接到数据库 (确保 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
553
556
  this.autologin 为 true 时自动登录 this.autologin automatically log in when it is true */
package/browser.js CHANGED
@@ -6,7 +6,7 @@ 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
8
  import { concat, assert, defer } from 'xshell/utils.browser.js';
9
- import { connect_websocket, WebSocketConnectionError } from 'xshell/net.browser.js';
9
+ import { connect_websocket } from 'xshell/net.browser.js';
10
10
  import { t } from './i18n/index.js';
11
11
  export var DdbForm;
12
12
  (function (DdbForm) {
@@ -2150,12 +2150,10 @@ export function int1282str(buffer, le = true) {
2150
2150
  export const winsize = 10_0000;
2151
2151
  export class DdbConnectionError extends Error {
2152
2152
  name = 'DdbConnectionError';
2153
+ cause;
2153
2154
  ddb;
2154
- constructor(ddb, error_options) {
2155
- super(error_options?.cause ?
2156
- error_options.cause.message
2157
- :
2158
- `${ddb.url} ${t('连接出错了,可能由于网络原因连接已被关闭,或服务器断开连接')}`, error_options);
2155
+ constructor(ddb, error) {
2156
+ super(error?.message || `${ddb.url} ${t('连接出错了,可能由于网络原因连接已被关闭,或服务器断开连接')}`, { cause: error });
2159
2157
  this.ddb = ddb;
2160
2158
  }
2161
2159
  }
@@ -2253,8 +2251,11 @@ export class DDB {
2253
2251
  if (options.streaming !== undefined)
2254
2252
  this.streaming = options.streaming;
2255
2253
  }
2256
- on_message(buffer) {
2257
- // 这里的实现一定会被 connect 中的实现覆盖
2254
+ on_message(buffer, websocket) {
2255
+ // 这里的实现一定会被 connect, rpc 中的实现覆盖
2256
+ }
2257
+ on_error(error, websocket) {
2258
+ // 这里的实现一定会被 connect, rpc 中的实现覆盖
2258
2259
  }
2259
2260
  /** 建立实际的 WebSocket 连接到 URL 对应的 DolphinDB Establish a actual websocket connection to the DolphindB corresponding to the URL
2260
2261
  是幂等的,调用后会确保已连接到数据库 (确保 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
@@ -2267,7 +2268,10 @@ export class DDB {
2267
2268
  await ptail;
2268
2269
  try {
2269
2270
  if (!this.connected) {
2270
- this.on_message = buffer => {
2271
+ this.on_error = (error, websocket) => {
2272
+ pconnect.reject(new DdbConnectionError(this, error));
2273
+ };
2274
+ this.on_message = (buffer, websocket) => {
2271
2275
  assert(false, t('这是在调用 this.rpc 之前默认的 on_message, 不应该被调用到,除非建立连接后 server 先推送了 message'));
2272
2276
  };
2273
2277
  this.presult = defer(null);
@@ -2280,16 +2284,16 @@ export class DDB {
2280
2284
  if (this.python)
2281
2285
  return 'python';
2282
2286
  })(),
2283
- on_message: (buffer) => {
2284
- this.on_message(buffer);
2287
+ on_message: (buffer, websocket) => {
2288
+ this.on_message(buffer, websocket);
2289
+ },
2290
+ on_error: (error, websocket) => {
2291
+ this.on_error(error, websocket);
2285
2292
  }
2286
2293
  });
2287
2294
  }
2288
2295
  catch (error) {
2289
- if (error instanceof WebSocketConnectionError)
2290
- throw new DdbConnectionError(this, { cause: error });
2291
- else
2292
- throw error;
2296
+ throw new DdbConnectionError(this, error);
2293
2297
  }
2294
2298
  if (this.streaming)
2295
2299
  await this.subscribe();
@@ -2418,6 +2422,13 @@ export class DDB {
2418
2422
  }
2419
2423
  catch { }
2420
2424
  // 临界区结束,只有一个 rpc 函数调用运行到这里,可以独占 this.on_message 然后写 WebSocket
2425
+ if (!this.connected) {
2426
+ presult.reject(new DdbConnectionError(this));
2427
+ return presult;
2428
+ }
2429
+ this.on_error = (error, websocket) => {
2430
+ presult.reject(new DdbConnectionError(this, error));
2431
+ };
2421
2432
  this.on_message = buffer => {
2422
2433
  try {
2423
2434
  const buf = new Uint8Array(buffer);