dolphindb 2.0.957 → 2.0.959

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/i18n/dict.json CHANGED
@@ -73,5 +73,8 @@
73
73
  },
74
74
  "new DdbBlob 不能传空的 value": {
75
75
  "en": "new DdbBlob cannot pass an empty value"
76
+ },
77
+ "vector<{{type}}> 暂时不支持解析": {
78
+ "en": "cannot parse vector<{{type}}>"
76
79
  }
77
80
  }
package/index.d.ts CHANGED
@@ -116,6 +116,7 @@ export interface DdbDecimal64VectorValue {
116
116
  scale: number;
117
117
  data: BigInt64Array;
118
118
  }
119
+ export type DdbDurationVectorValue = DdbDurationValue[];
119
120
  export interface DdbSymbolExtendedValue {
120
121
  base_id: number;
121
122
  base: string[];
@@ -176,10 +177,10 @@ export type DdbScalarValue = null | boolean | number | bigint | string | Uint8Ar
176
177
  number
177
178
  ] | // complex, point
178
179
  DdbFunctionDefValue | DdbDurationValue | DdbDecimal32Value | DdbDecimal64Value;
179
- export type DdbVectorValue = Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | string[] | // string[]
180
+ export type DdbVectorValue = null | Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | string[] | // string[]
180
181
  Uint8Array[] | // blob
181
182
  DdbObj[] | // any
182
- DdbSymbolExtendedValue | DdbArrayVectorValue | DdbDecimal32VectorValue | DdbDecimal64VectorValue;
183
+ DdbSymbolExtendedValue | DdbArrayVectorValue | DdbDecimal32VectorValue | DdbDecimal64VectorValue | DdbDurationVectorValue;
183
184
  export type DdbValue = DdbScalarValue | DdbVectorValue | DdbMatrixValue | DdbDictValue | DdbChartValue;
184
185
  export type DdbStringObj = DdbObj<string>;
185
186
  export type DdbVectorObj<TValue extends DdbVectorValue = DdbVectorValue> = DdbObj<TValue>;
package/index.js CHANGED
@@ -610,6 +610,8 @@ class DdbObj {
610
610
  /** 有可能没有字节对齐,不能直接使用原有 message 的 arraybuffer, 统一复制出来,让原有 arraybuffer 被回收掉比较好 */
611
611
  static parse_vector_items(buf, le, type, length) {
612
612
  switch (type) {
613
+ case DdbType.void:
614
+ return [0, null];
613
615
  case DdbType.bool:
614
616
  case DdbType.char:
615
617
  return [
@@ -775,15 +777,31 @@ class DdbObj {
775
777
  }
776
778
  ];
777
779
  }
778
- // case DdbType.duration: -> 实际会返回一个 any vector
780
+ // 以下情况时, DdbType.duration 实际会返回一个 any vector
779
781
  // [2y, 1M, 3d, 7H, 11m, 12s, 15ms, 16us, 17ns]
780
782
  // <Buffer 19 01 type = any, form = vector
781
783
  // 09 00 00 00 01 00 00 00 rows = 9, cols = 1
782
784
  // 24 00 type = DdbType.duration, form = scalar
783
785
  // 02 00 00 00 09 00 00 00
784
786
  // 24 00 01 00 00 00 08 00 00 00 24 00 03 00 00 00 06 00 00 00 24 00 07 00 00 00 05 00 00 00 ... 50 more bytes>
787
+ // 其余情况 (目前仅 pair) 下, 会返回特殊的 duration 序列化
788
+ // 4 bytes data 4 bytes unit
789
+ // 01 00 00 00 data: 1
790
+ // 01 00 00 00 unit: 1
791
+ // 02 00 00 00 data: 2
792
+ // 02 00 00 00 unit: 2
793
+ case DdbType.duration: {
794
+ const dv = new DataView(buf.buffer, buf.byteOffset);
795
+ let durations = [];
796
+ for (let i = 0; i < length; i++)
797
+ durations.push({
798
+ data: dv.getInt32(0 + 8 * i, le),
799
+ unit: dv.getInt32(4 + 8 * i, le)
800
+ });
801
+ return [8 * length, durations];
802
+ }
785
803
  default:
786
- return [0, buf];
804
+ throw new Error(t('vector<{{type}}> 暂时不支持解析', { type: String(DdbType[type] || type) }));
787
805
  }
788
806
  }
789
807
  pack() {
@@ -970,6 +988,8 @@ class DdbObj {
970
988
  }
971
989
  static pack_vector_body(value, type, length) {
972
990
  switch (type) {
991
+ case DdbType.void:
992
+ return [];
973
993
  case DdbType.bool:
974
994
  return [value];
975
995
  case DdbType.char:
@@ -1140,6 +1160,8 @@ class DdbObj {
1140
1160
  items[i] = inspect(base[data[i]], options);
1141
1161
  return format_array(items, data.length > limit);
1142
1162
  }
1163
+ case DdbType.void:
1164
+ return format(this.type, this.value, this.le, options);
1143
1165
  case DdbType.uuid:
1144
1166
  case DdbType.int128:
1145
1167
  case DdbType.ipaddr: {
@@ -2258,7 +2280,7 @@ class DDB {
2258
2280
  this.streaming = options.streaming;
2259
2281
  }
2260
2282
  on_message(buffer, websocket) {
2261
- throw t('这是在调用 this.rpc 之前默认的 on_message, 不应该被调用到,除非建立连接后 server 先推送了 message');
2283
+ throw new Error(t('这是在调用 this.rpc 之前默认的 on_message, 不应该被调用到,除非建立连接后 server 先推送了 message'));
2262
2284
  }
2263
2285
  on_error() {
2264
2286
  // 这里的实现一定会被 connect, rpc 中的实现覆盖
@@ -2313,8 +2335,6 @@ class DDB {
2313
2335
  try {
2314
2336
  assert(this.connected);
2315
2337
  await this.rpc('connect', { skip_connection_check: true });
2316
- if (this.autologin)
2317
- await this.call('login', [this.username, this.password], { urgent: true, skip_connection_check: true });
2318
2338
  if (this.streaming)
2319
2339
  await this.subscribe();
2320
2340
  resolve();
@@ -2496,8 +2516,21 @@ class DDB {
2496
2516
  `${Number(DDB.le_client)}\n`;
2497
2517
  case 'connect':
2498
2518
  if (this.verbose)
2499
- console.log('connect()');
2500
- return 'connect\n';
2519
+ console.log('connect()' +
2520
+ (this.autologin ?
2521
+ '\n' +
2522
+ `login(${this.username.quote()}, ${this.password.quote()})`
2523
+ :
2524
+ ''));
2525
+ return 'connect\n' +
2526
+ // 详见 InterProcessIO.cpp#APISocketConsole::parseScript 中的
2527
+ // Util::startWith "connect"
2528
+ (this.autologin ?
2529
+ 'login\n' +
2530
+ this.username + '\n' +
2531
+ this.password /* encrypted (可选参数) + '\n' + 'false' */
2532
+ :
2533
+ '');
2501
2534
  }
2502
2535
  })());
2503
2536
  websocket.send(concat([