dolphindb 2.0.508 → 2.0.511

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
@@ -63,10 +63,28 @@ export declare enum DdbFunctionType {
63
63
  JitFunc = 7,
64
64
  JitPartialFunc = 8
65
65
  }
66
+ export declare enum DdbDurationUnit {
67
+ ns = 0,
68
+ us = 1,
69
+ ms = 2,
70
+ s = 3,
71
+ m = 4,
72
+ H = 5,
73
+ d = 6,
74
+ w = 7,
75
+ M = 8,
76
+ y = 9,
77
+ B = 10
78
+ }
66
79
  export interface DdbFunctionDefValue {
67
80
  type: DdbFunctionType;
68
81
  name: string;
69
82
  }
83
+ export interface DdbDurationValue {
84
+ unit: DdbDurationUnit;
85
+ /** int32 */
86
+ data: number;
87
+ }
70
88
  export interface DdbSymbolExtendedValue {
71
89
  base_id: number;
72
90
  base: string[];
@@ -79,12 +97,21 @@ export interface DdbArrayVectorBlock {
79
97
  data: DdbVectorValue;
80
98
  }
81
99
  export interface DdbMatrixValue {
82
- rows: DdbObj;
83
- cols: DdbObj;
100
+ rows: DdbObj<DdbVectorValue>;
101
+ cols: DdbObj<DdbVectorValue>;
84
102
  data: DdbVectorValue;
85
103
  }
86
- export declare type DdbValue = null | boolean | number | [number, number] | bigint | string | string[] | Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | Uint8Array[] | DdbObj[] | DdbFunctionDefValue | DdbSymbolExtendedValue | DdbArrayVectorBlock[] | DdbMatrixValue;
87
- export declare type DdbVectorValue = string | string[] | Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | Uint8Array[] | DdbObj[] | DdbSymbolExtendedValue | DdbArrayVectorBlock[];
104
+ export declare type DdbScalarValue = null | boolean | number | bigint | string | Uint8Array | // uuid, ipaddr, int128, blob
105
+ [
106
+ number,
107
+ number
108
+ ] | // complex, point
109
+ DdbFunctionDefValue | DdbDurationValue;
110
+ export declare type DdbVectorValue = Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | string[] | // string[]
111
+ Uint8Array[] | // blob
112
+ DdbObj[] | // any
113
+ DdbSymbolExtendedValue | DdbArrayVectorBlock[];
114
+ export declare type DdbValue = DdbScalarValue | DdbVectorValue | DdbMatrixValue;
88
115
  export declare const nulls: {
89
116
  readonly int8: -128;
90
117
  readonly int16: -32768;
@@ -137,7 +164,7 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
137
164
  type: DdbType;
138
165
  });
139
166
  static parse(buf: Uint8Array, le: boolean): DdbObj<DdbValue>;
140
- static parse_scalar(buf: Uint8Array, le: boolean, type: DdbType): [number, DdbValue];
167
+ static parse_scalar(buf: Uint8Array, le: boolean, type: DdbType): [number, DdbScalarValue];
141
168
  /** parse: rows, cols, items
142
169
  返回的 ddbobj.length 不包括 vector 的 type 和 form
143
170
  */
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DDB = exports.str2nanotimestamp = exports.nanotimestamp2str = exports.str2timestamp = exports.timestamp2str = exports.datetime2str = exports.date2str = exports.DdbTable = exports.DdbSetString = exports.DdbSetDouble = exports.DdbSetInt = exports.DdbVectorSymbol = exports.DdbVectorAny = exports.DdbVectorString = exports.DdbVectorDouble = exports.DdbVectorInt = exports.DdbFunction = exports.DdbPair = exports.DdbNanoTimeStamp = exports.DdbTimeStamp = exports.DdbDateTime = exports.DdbDouble = exports.DdbLong = exports.DdbString = exports.DdbInt = exports.DdbChar = exports.DdbBool = exports.DdbVoid = exports.DdbObj = exports.timezone_offset = exports.nulls = exports.DdbFunctionType = exports.ddb_sizes = exports.DdbType = exports.DdbForm = void 0;
3
+ exports.DDB = exports.str2nanotimestamp = exports.nanotimestamp2str = exports.str2timestamp = exports.timestamp2str = exports.datetime2str = exports.date2str = exports.DdbTable = exports.DdbSetString = exports.DdbSetDouble = exports.DdbSetInt = exports.DdbVectorSymbol = exports.DdbVectorAny = exports.DdbVectorString = exports.DdbVectorDouble = exports.DdbVectorInt = exports.DdbFunction = exports.DdbPair = exports.DdbNanoTimeStamp = exports.DdbTimeStamp = exports.DdbDateTime = exports.DdbDouble = exports.DdbLong = exports.DdbString = exports.DdbInt = exports.DdbChar = exports.DdbBool = exports.DdbVoid = exports.DdbObj = exports.timezone_offset = exports.nulls = exports.DdbDurationUnit = exports.DdbFunctionType = exports.ddb_sizes = exports.DdbType = exports.DdbForm = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const ws_1 = require("ws");
6
6
  const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
@@ -109,6 +109,20 @@ var DdbFunctionType;
109
109
  DdbFunctionType[DdbFunctionType["JitFunc"] = 7] = "JitFunc";
110
110
  DdbFunctionType[DdbFunctionType["JitPartialFunc"] = 8] = "JitPartialFunc";
111
111
  })(DdbFunctionType = exports.DdbFunctionType || (exports.DdbFunctionType = {}));
112
+ var DdbDurationUnit;
113
+ (function (DdbDurationUnit) {
114
+ DdbDurationUnit[DdbDurationUnit["ns"] = 0] = "ns";
115
+ DdbDurationUnit[DdbDurationUnit["us"] = 1] = "us";
116
+ DdbDurationUnit[DdbDurationUnit["ms"] = 2] = "ms";
117
+ DdbDurationUnit[DdbDurationUnit["s"] = 3] = "s";
118
+ DdbDurationUnit[DdbDurationUnit["m"] = 4] = "m";
119
+ DdbDurationUnit[DdbDurationUnit["H"] = 5] = "H";
120
+ DdbDurationUnit[DdbDurationUnit["d"] = 6] = "d";
121
+ DdbDurationUnit[DdbDurationUnit["w"] = 7] = "w";
122
+ DdbDurationUnit[DdbDurationUnit["M"] = 8] = "M";
123
+ DdbDurationUnit[DdbDurationUnit["y"] = 9] = "y";
124
+ DdbDurationUnit[DdbDurationUnit["B"] = 10] = "B";
125
+ })(DdbDurationUnit = exports.DdbDurationUnit || (exports.DdbDurationUnit = {}));
112
126
  exports.nulls = {
113
127
  int8: -0x80,
114
128
  int16: -32768,
@@ -406,6 +420,16 @@ class DdbObj {
406
420
  ]
407
421
  ];
408
422
  }
423
+ case DdbType.duration: {
424
+ const dv = new DataView(buf.buffer, buf.byteOffset);
425
+ return [
426
+ 8,
427
+ {
428
+ unit: dv.getUint32(4, le),
429
+ data: dv.getInt32(0, le)
430
+ }
431
+ ];
432
+ }
409
433
  default:
410
434
  return [0, buf];
411
435
  }
@@ -520,6 +544,7 @@ class DdbObj {
520
544
  case DdbType.minute:
521
545
  case DdbType.second:
522
546
  case DdbType.datetime:
547
+ case DdbType.datehour:
523
548
  return [
524
549
  4 * length,
525
550
  new Int32Array(buf.buffer.slice(buf.byteOffset, buf.byteOffset + 4 * length))
@@ -638,6 +663,13 @@ class DdbObj {
638
663
  values
639
664
  ];
640
665
  }
666
+ // case DdbType.duration: -> 实际会返回一个 any vector
667
+ // [2y, 1M, 3d, 7H, 11m, 12s, 15ms, 16us, 17ns]
668
+ // <Buffer 19 01 type = any, form = vector
669
+ // 09 00 00 00 01 00 00 00 rows = 9, cols = 1
670
+ // 24 00 type = DdbType.duration, form = scalar
671
+ // 02 00 00 00 09 00 00 00
672
+ // 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>
641
673
  default:
642
674
  return [0, buf];
643
675
  }
@@ -739,8 +771,10 @@ class DdbObj {
739
771
  case DdbType.complex:
740
772
  case DdbType.point:
741
773
  return [Float64Array.from(this.value)];
742
- case DdbType.duration:
743
- return [value];
774
+ case DdbType.duration: {
775
+ const { unit, data } = this.value;
776
+ return [Int32Array.of(data, unit)];
777
+ }
744
778
  case DdbType.handle:
745
779
  throw new Error('DolphinDB Server 不支持 handle 的反序列化');
746
780
  default:
@@ -823,6 +857,7 @@ class DdbObj {
823
857
  case DdbType.minute:
824
858
  case DdbType.second:
825
859
  case DdbType.datetime:
860
+ case DdbType.datehour:
826
861
  return [value];
827
862
  case DdbType.float:
828
863
  return [value];
@@ -922,6 +957,11 @@ class DdbObj {
922
957
  switch (this.type) {
923
958
  case DdbType.functiondef:
924
959
  return (0, utils_js_1.inspect)(this.value.name, options);
960
+ case DdbType.duration: {
961
+ const { data, unit } = this.value;
962
+ const str = `${data}${DdbDurationUnit[unit]}`;
963
+ return options.colors ? str.green : str;
964
+ }
925
965
  }
926
966
  break;
927
967
  }
@@ -1583,25 +1623,30 @@ class DDB {
1583
1623
  catch { }
1584
1624
  // 临界区结束,只有一个 rpc 函数调用运行到这里,可以独占 this.on_message 然后写 WebSocket
1585
1625
  this.on_message = ({ data: buffer }) => {
1586
- const buf = new Uint8Array(buffer);
1587
- if (this.print_message_buffer)
1588
- console.log((0, utils_js_1.typed_array_to_buffer)(buf));
1589
- const message = this.parse_message(buf, parse_object);
1590
- listener?.(message, this);
1591
- for (const listener of _handlers)
1592
- listener(message, this);
1593
- const { type, data } = message;
1594
- switch (type) {
1595
- case 'print':
1596
- if (this.print_message)
1597
- console.log(data);
1598
- return;
1599
- case 'object':
1600
- resolve(data);
1601
- return;
1602
- case 'error':
1603
- reject(data);
1604
- return;
1626
+ try {
1627
+ const buf = new Uint8Array(buffer);
1628
+ if (this.print_message_buffer)
1629
+ console.log((0, utils_js_1.typed_array_to_buffer)(buf));
1630
+ const message = this.parse_message(buf, parse_object);
1631
+ listener?.(message, this);
1632
+ for (const listener of _handlers)
1633
+ listener(message, this);
1634
+ const { type, data } = message;
1635
+ switch (type) {
1636
+ case 'print':
1637
+ if (this.print_message)
1638
+ console.log(data);
1639
+ return;
1640
+ case 'object':
1641
+ resolve(data);
1642
+ return;
1643
+ case 'error':
1644
+ reject(data);
1645
+ return;
1646
+ }
1647
+ }
1648
+ catch (error) {
1649
+ reject(error);
1605
1650
  }
1606
1651
  };
1607
1652
  args = this.to_ddbobjs(args);