dolphindb 2.0.1019 → 2.0.1021

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/index.d.ts CHANGED
@@ -367,15 +367,16 @@ export interface DdbRpcOptions {
367
367
  export declare class DdbConnectionError extends Error {
368
368
  name: string;
369
369
  cause?: WebSocketConnectionError;
370
- ddb: DDB;
371
- constructor(ddb: DDB, error?: WebSocketConnectionError);
370
+ url: string;
371
+ constructor(url: string, error?: WebSocketConnectionError);
372
372
  }
373
373
  export declare class DdbDatabaseError extends Error {
374
374
  name: string;
375
- ddb: DDB;
375
+ url: string;
376
+ id: number;
376
377
  type: DdbRpcType;
377
378
  options: DdbRpcOptions;
378
- constructor(message: string, ddb: DDB, type: DdbRpcType, options: DdbRpcOptions);
379
+ constructor(message: string, url: string, type: DdbRpcType, options: DdbRpcOptions, id: number);
379
380
  }
380
381
  /** SQL Standrd 标准类型 */
381
382
  export declare enum SqlStandard {
package/index.js CHANGED
@@ -2092,24 +2092,28 @@ export const winsize = 10_0000;
2092
2092
  export class DdbConnectionError extends Error {
2093
2093
  name = 'DdbConnectionError';
2094
2094
  cause;
2095
- ddb;
2096
- constructor(ddb, error) {
2097
- super(error?.message || `${ddb.url} ${t('连接出错了,可能由于网络原因连接已被关闭,或服务器断开连接')}`, { cause: error });
2095
+ url;
2096
+ // 这里不保留 ddb 的引用,会导致无法序列化
2097
+ constructor(url, error) {
2098
+ super(error?.message || `${url} ${t('连接出错了,可能由于网络原因连接已被关闭,或服务器断开连接')}`, { cause: error });
2099
+ this.url = url;
2098
2100
  if (error)
2099
2101
  this.cause = error;
2100
- this.ddb = ddb;
2101
2102
  }
2102
2103
  }
2103
2104
  export class DdbDatabaseError extends Error {
2104
2105
  name = 'DdbDatabaseError';
2105
- ddb;
2106
+ url;
2107
+ // 这里不保留 ddb 的引用,会导致无法序列化
2108
+ id;
2106
2109
  type;
2107
2110
  options;
2108
- constructor(message, ddb, type, options) {
2111
+ constructor(message, url, type, options, id) {
2109
2112
  super(message);
2110
- this.ddb = ddb;
2113
+ this.url = url;
2111
2114
  this.type = type;
2112
2115
  this.options = options;
2116
+ this.id = id;
2113
2117
  }
2114
2118
  }
2115
2119
  /** SQL Standrd 标准类型 */
@@ -2241,7 +2245,7 @@ export class DDB {
2241
2245
  throw this.error;
2242
2246
  const { resource: websocket } = this.lwebsocket;
2243
2247
  if (websocket && (websocket.readyState === WebSocketClosing || websocket.readyState === WebSocketClosed))
2244
- throw this.error = new DdbConnectionError(this);
2248
+ throw this.error = new DdbConnectionError(this.url);
2245
2249
  return this.pconnect ??= new Promise(async (resolve, reject) => {
2246
2250
  this.on_error = () => {
2247
2251
  reject(this.error /* 一定有,不需要再 || new DdbConnectionError(this) */);
@@ -2249,23 +2253,18 @@ export class DDB {
2249
2253
  try {
2250
2254
  // 连接建立之前应该不会有别的调用占用 this.lwebsocket
2251
2255
  this.lwebsocket.resource = await connect_websocket(this.url, {
2252
- protocols: (() => {
2253
- if (this.streaming)
2254
- return 'streaming';
2255
- if (this.python)
2256
- return 'python';
2257
- })(),
2256
+ protocols: this.streaming ? ['streaming'] : this.python ? ['python'] : undefined,
2258
2257
  on_message: (buffer, websocket) => {
2259
2258
  this.on_message(buffer, websocket);
2260
2259
  },
2261
2260
  on_error: error => {
2262
- this.error ??= new DdbConnectionError(this, error);
2261
+ this.error ??= new DdbConnectionError(this.url, error);
2263
2262
  this.on_error();
2264
2263
  }
2265
2264
  });
2266
2265
  }
2267
2266
  catch (error) {
2268
- this.error ??= new DdbConnectionError(this, error);
2267
+ this.error ??= new DdbConnectionError(this.url, error);
2269
2268
  reject(this.error);
2270
2269
  return;
2271
2270
  }
@@ -2338,7 +2337,8 @@ export class DDB {
2338
2337
  将这个 flag 设为 true 跳过连接状态检查 */
2339
2338
  async rpc(type, options) {
2340
2339
  // 保留调用栈信息
2341
- let error = new DdbDatabaseError('', this, type, options);
2340
+ const id = genid() % 1000;
2341
+ let error = new DdbDatabaseError('', this.url, type, options, id);
2342
2342
  if (!options.skip_connection_check)
2343
2343
  await this.connect();
2344
2344
  const { script, func, args: _args = [], vars = [], urgent, listener, } = options;
@@ -2397,7 +2397,6 @@ export class DDB {
2397
2397
  if (this.error)
2398
2398
  throw this.error;
2399
2399
  const args = DdbObj.to_ddbobjs(_args);
2400
- const id = genid() % 1000;
2401
2400
  const rpc_id = ` (id = ${id})`;
2402
2401
  const command = this.enc.encode((() => {
2403
2402
  switch (type) {