dolphindb 2.0.1008 → 2.0.1010

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
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  import type { InspectOptions as UtilInspectOptions } from 'util';
3
- import { inspect, WebSocket, Lock, type WebSocketConnectionError } from 'xshell';
3
+ import { inspect, Lock, type WebSocket, type WebSocketConnectionError } from 'xshell';
4
4
  import { type DdbDecimal128Value, type DdbDecimal128VectorValue } from './data-types/decimal-128.js';
5
5
  import { BigInt128Array } from './shared/bigint-128-array.js';
6
6
  import { DdbChartType, DdbDurationUnit, DdbForm, DdbFunctionType, DdbType } from './shared/constants.js';
@@ -152,7 +152,7 @@ export declare class DdbObj<TValue extends DdbValue = DdbValue> {
152
152
  ];
153
153
  pack(): Uint8Array;
154
154
  static pack_vector_body(value: DdbVectorValue, type: DdbType, length: number): ArrayBufferView[];
155
- [inspect.custom](depth: number, _options: InspectOptions, _inspect: any): string;
155
+ [inspect.custom](depth: number, _options: InspectOptions, _inspect: any): string | TValue;
156
156
  inspect_type(): string;
157
157
  /** 自动转换 js string, boolean 为 DdbObj */
158
158
  static to_ddbobj(value: DdbObj | string | boolean): DdbObj;
package/index.js CHANGED
@@ -4,7 +4,7 @@ import DayjsCustomParseFormat from 'dayjs/plugin/customParseFormat.js';
4
4
  dayjs.extend(DayjsCustomParseFormat);
5
5
  import ipaddrjs from 'ipaddr.js';
6
6
  const { fromByteArray: buf2ipaddr } = ipaddrjs;
7
- import { concat, assert, inspect, typed_array_to_buffer, connect_websocket, WebSocket, Lock, genid } from 'xshell';
7
+ import { concat, assert, inspect, typed_array_to_buffer, connect_websocket, Lock, genid, WebSocketOpen, WebSocketClosed, WebSocketClosing } from 'xshell';
8
8
  import { t } from './i18n/index.js';
9
9
  import { DdbDecimal128Serializor } from './data-types/decimal-128.js';
10
10
  import { BigInt128Array } from './shared/bigint-128-array.js';
@@ -995,7 +995,11 @@ export class DdbObj {
995
995
  const data = (() => {
996
996
  switch (this.form) {
997
997
  case DdbForm.scalar:
998
- return format(this.type, this.value, this.le, options);
998
+ // 如果类型为 string, 则不进行格式化处理
999
+ if (this.type === DdbType.string)
1000
+ return this.value;
1001
+ else
1002
+ return format(this.type, this.value, this.le, options);
999
1003
  case DdbForm.vector:
1000
1004
  case DdbForm.pair:
1001
1005
  case DdbForm.set: {
@@ -1121,7 +1125,11 @@ export class DdbObj {
1121
1125
  return inspect(typed_array_to_buffer(this.value), options);
1122
1126
  return inspect(this.value, options);
1123
1127
  })();
1124
- return `${options.colors ? type.blue : type}(${this.name ? `${inspect(this.name, options)}, ` : ''}${data})`;
1128
+ // 如果类型为 string 则不需要加上类型名
1129
+ if (this.form === DdbForm.scalar && this.type === DdbType.string)
1130
+ return data;
1131
+ else
1132
+ return `${options.colors ? type.blue : type}(${this.name ? `${inspect(this.name, options)}, ` : ''}${data})`;
1125
1133
  }
1126
1134
  inspect_type() {
1127
1135
  const tname = DdbType[this.type];
@@ -2164,10 +2172,10 @@ export class DDB {
2164
2172
  /** 首次定义 pnode_run 的 promise,保证并发调用 rpc 时只定义一次 pnode_run */
2165
2173
  ppnode_run;
2166
2174
  get connected() {
2167
- return !this.error && this.lwebsocket.resource?.readyState === WebSocket.OPEN;
2175
+ return !this.error && this.lwebsocket.resource?.readyState === WebSocketOpen;
2168
2176
  }
2169
2177
  get errored() {
2170
- return Boolean(this.error || (this.lwebsocket.resource && this.lwebsocket.resource.readyState !== WebSocket.OPEN));
2178
+ return Boolean(this.error || (this.lwebsocket.resource && this.lwebsocket.resource.readyState !== WebSocketOpen));
2171
2179
  }
2172
2180
  /**
2173
2181
  使用 WebSocket URL 初始化连接到 DolphinDB 的实例(不建立实际的网络连接)
@@ -2312,7 +2320,7 @@ export class DDB {
2312
2320
  const { resource } = this.lwebsocket;
2313
2321
  if (resource) {
2314
2322
  const { readyState } = resource;
2315
- if (readyState !== WebSocket.CLOSED && readyState !== WebSocket.CLOSING)
2323
+ if (readyState !== WebSocketClosed && readyState !== WebSocketClosing)
2316
2324
  // 这里不获取 lock,直接关闭连接
2317
2325
  resource.close(1000);
2318
2326
  }