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/browser.d.ts CHANGED
@@ -60,10 +60,28 @@ export declare enum DdbFunctionType {
60
60
  JitFunc = 7,
61
61
  JitPartialFunc = 8
62
62
  }
63
+ export declare enum DdbDurationUnit {
64
+ ns = 0,
65
+ us = 1,
66
+ ms = 2,
67
+ s = 3,
68
+ m = 4,
69
+ H = 5,
70
+ d = 6,
71
+ w = 7,
72
+ M = 8,
73
+ y = 9,
74
+ B = 10
75
+ }
63
76
  export interface DdbFunctionDefValue {
64
77
  type: DdbFunctionType;
65
78
  name: string;
66
79
  }
80
+ export interface DdbDurationValue {
81
+ unit: DdbDurationUnit;
82
+ /** int32 */
83
+ data: number;
84
+ }
67
85
  export interface DdbSymbolExtendedValue {
68
86
  base_id: number;
69
87
  base: string[];
@@ -76,12 +94,21 @@ export interface DdbArrayVectorBlock {
76
94
  data: DdbVectorValue;
77
95
  }
78
96
  export interface DdbMatrixValue {
79
- rows: DdbObj;
80
- cols: DdbObj;
97
+ rows: DdbObj<DdbVectorValue>;
98
+ cols: DdbObj<DdbVectorValue>;
81
99
  data: DdbVectorValue;
82
100
  }
83
- 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;
84
- export declare type DdbVectorValue = string | string[] | Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | Uint8Array[] | DdbObj[] | DdbSymbolExtendedValue | DdbArrayVectorBlock[];
101
+ export declare type DdbScalarValue = null | boolean | number | bigint | string | Uint8Array | // uuid, ipaddr, int128, blob
102
+ [
103
+ number,
104
+ number
105
+ ] | // complex, point
106
+ DdbFunctionDefValue | DdbDurationValue;
107
+ export declare type DdbVectorValue = Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | string[] | // string[]
108
+ Uint8Array[] | // blob
109
+ DdbObj[] | // any
110
+ DdbSymbolExtendedValue | DdbArrayVectorBlock[];
111
+ export declare type DdbValue = DdbScalarValue | DdbVectorValue | DdbMatrixValue;
85
112
  export declare const nulls: {
86
113
  readonly int8: -128;
87
114
  readonly int16: -32768;
@@ -134,7 +161,7 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
134
161
  type: DdbType;
135
162
  });
136
163
  static parse(buf: Uint8Array, le: boolean): DdbObj<DdbValue>;
137
- static parse_scalar(buf: Uint8Array, le: boolean, type: DdbType): [number, DdbValue];
164
+ static parse_scalar(buf: Uint8Array, le: boolean, type: DdbType): [number, DdbScalarValue];
138
165
  /** parse: rows, cols, items
139
166
  返回的 ddbobj.length 不包括 vector 的 type 和 form
140
167
  */
package/browser.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ddb = 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.DdbType = exports.DdbForm = void 0;
3
+ exports.ddb = 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.DdbType = exports.DdbForm = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
6
6
  const customParseFormat_js_1 = tslib_1.__importDefault(require("dayjs/plugin/customParseFormat.js"));
@@ -72,6 +72,20 @@ var DdbFunctionType;
72
72
  DdbFunctionType[DdbFunctionType["JitFunc"] = 7] = "JitFunc";
73
73
  DdbFunctionType[DdbFunctionType["JitPartialFunc"] = 8] = "JitPartialFunc";
74
74
  })(DdbFunctionType = exports.DdbFunctionType || (exports.DdbFunctionType = {}));
75
+ var DdbDurationUnit;
76
+ (function (DdbDurationUnit) {
77
+ DdbDurationUnit[DdbDurationUnit["ns"] = 0] = "ns";
78
+ DdbDurationUnit[DdbDurationUnit["us"] = 1] = "us";
79
+ DdbDurationUnit[DdbDurationUnit["ms"] = 2] = "ms";
80
+ DdbDurationUnit[DdbDurationUnit["s"] = 3] = "s";
81
+ DdbDurationUnit[DdbDurationUnit["m"] = 4] = "m";
82
+ DdbDurationUnit[DdbDurationUnit["H"] = 5] = "H";
83
+ DdbDurationUnit[DdbDurationUnit["d"] = 6] = "d";
84
+ DdbDurationUnit[DdbDurationUnit["w"] = 7] = "w";
85
+ DdbDurationUnit[DdbDurationUnit["M"] = 8] = "M";
86
+ DdbDurationUnit[DdbDurationUnit["y"] = 9] = "y";
87
+ DdbDurationUnit[DdbDurationUnit["B"] = 10] = "B";
88
+ })(DdbDurationUnit = exports.DdbDurationUnit || (exports.DdbDurationUnit = {}));
75
89
  exports.nulls = {
76
90
  int8: -0x80,
77
91
  int16: -32768,
@@ -369,6 +383,16 @@ class DdbObj {
369
383
  ]
370
384
  ];
371
385
  }
386
+ case DdbType.duration: {
387
+ const dv = new DataView(buf.buffer, buf.byteOffset);
388
+ return [
389
+ 8,
390
+ {
391
+ unit: dv.getUint32(4, le),
392
+ data: dv.getInt32(0, le)
393
+ }
394
+ ];
395
+ }
372
396
  default:
373
397
  return [0, buf];
374
398
  }
@@ -483,6 +507,7 @@ class DdbObj {
483
507
  case DdbType.minute:
484
508
  case DdbType.second:
485
509
  case DdbType.datetime:
510
+ case DdbType.datehour:
486
511
  return [
487
512
  4 * length,
488
513
  new Int32Array(buf.buffer.slice(buf.byteOffset, buf.byteOffset + 4 * length))
@@ -601,6 +626,13 @@ class DdbObj {
601
626
  values
602
627
  ];
603
628
  }
629
+ // case DdbType.duration: -> 实际会返回一个 any vector
630
+ // [2y, 1M, 3d, 7H, 11m, 12s, 15ms, 16us, 17ns]
631
+ // <Buffer 19 01 type = any, form = vector
632
+ // 09 00 00 00 01 00 00 00 rows = 9, cols = 1
633
+ // 24 00 type = DdbType.duration, form = scalar
634
+ // 02 00 00 00 09 00 00 00
635
+ // 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>
604
636
  default:
605
637
  return [0, buf];
606
638
  }
@@ -702,8 +734,10 @@ class DdbObj {
702
734
  case DdbType.complex:
703
735
  case DdbType.point:
704
736
  return [Float64Array.from(this.value)];
705
- case DdbType.duration:
706
- return [value];
737
+ case DdbType.duration: {
738
+ const { unit, data } = this.value;
739
+ return [Int32Array.of(data, unit)];
740
+ }
707
741
  case DdbType.handle:
708
742
  throw new Error('DolphinDB Server 不支持 handle 的反序列化');
709
743
  default:
@@ -786,6 +820,7 @@ class DdbObj {
786
820
  case DdbType.minute:
787
821
  case DdbType.second:
788
822
  case DdbType.datetime:
823
+ case DdbType.datehour:
789
824
  return [value];
790
825
  case DdbType.float:
791
826
  return [value];
@@ -885,6 +920,10 @@ class DdbObj {
885
920
  switch (this.type) {
886
921
  case DdbType.functiondef:
887
922
  return `'${this.value.name}'`;
923
+ case DdbType.duration: {
924
+ const { data, unit } = this.value;
925
+ return `${data}${DdbDurationUnit[unit]}`;
926
+ }
888
927
  case DdbType.string:
889
928
  return `'${this.value}'`;
890
929
  }
@@ -1572,25 +1611,30 @@ class DDB {
1572
1611
  catch { }
1573
1612
  // 临界区结束,只有一个 rpc 函数调用运行到这里,可以独占 this.on_message 然后写 WebSocket
1574
1613
  this.on_message = ({ data: buffer }) => {
1575
- const buf = new Uint8Array(buffer);
1576
- if (this.print_message_buffer)
1577
- console.log(buf);
1578
- const message = this.parse_message(buf, parse_object);
1579
- listener?.(message, this);
1580
- for (const listener of _handlers)
1581
- listener(message, this);
1582
- const { type, data } = message;
1583
- switch (type) {
1584
- case 'print':
1585
- if (this.print_message)
1586
- console.log(data);
1587
- return;
1588
- case 'object':
1589
- resolve(data);
1590
- return;
1591
- case 'error':
1592
- reject(data);
1593
- return;
1614
+ try {
1615
+ const buf = new Uint8Array(buffer);
1616
+ if (this.print_message_buffer)
1617
+ console.log(buf);
1618
+ const message = this.parse_message(buf, parse_object);
1619
+ listener?.(message, this);
1620
+ for (const listener of _handlers)
1621
+ listener(message, this);
1622
+ const { type, data } = message;
1623
+ switch (type) {
1624
+ case 'print':
1625
+ if (this.print_message)
1626
+ console.log(data);
1627
+ return;
1628
+ case 'object':
1629
+ resolve(data);
1630
+ return;
1631
+ case 'error':
1632
+ reject(data);
1633
+ return;
1634
+ }
1635
+ }
1636
+ catch (error) {
1637
+ reject(error);
1594
1638
  }
1595
1639
  };
1596
1640
  args = this.to_ddbobjs(args);