dolphindb 2.0.509 → 2.0.512

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[];
@@ -85,7 +103,7 @@ export declare type DdbScalarValue = null | boolean | number | bigint | string |
85
103
  number,
86
104
  number
87
105
  ] | // complex, point
88
- DdbFunctionDefValue;
106
+ DdbFunctionDefValue | DdbDurationValue;
89
107
  export declare type DdbVectorValue = Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | string[] | // string[]
90
108
  Uint8Array[] | // blob
91
109
  DdbObj[] | // any
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,
@@ -322,6 +336,7 @@ class DdbObj {
322
336
  case DdbType.string:
323
337
  case DdbType.symbol:
324
338
  case DdbType.code:
339
+ case DdbType.handle:
325
340
  case DdbType.functiondef: {
326
341
  const i_head = type === DdbType.functiondef ? 1 : 0;
327
342
  let i_zero = buf.indexOf(0, i_head);
@@ -369,8 +384,18 @@ class DdbObj {
369
384
  ]
370
385
  ];
371
386
  }
387
+ case DdbType.duration: {
388
+ const dv = new DataView(buf.buffer, buf.byteOffset);
389
+ return [
390
+ 8,
391
+ {
392
+ unit: dv.getUint32(4, le),
393
+ data: dv.getInt32(0, le)
394
+ }
395
+ ];
396
+ }
372
397
  default:
373
- return [0, buf];
398
+ throw new Error(`${DdbType[type] || type} 暂时不支持解析`);
374
399
  }
375
400
  }
376
401
  /** parse: rows, cols, items
@@ -509,6 +534,7 @@ class DdbObj {
509
534
  ];
510
535
  case DdbType.string:
511
536
  case DdbType.symbol:
537
+ case DdbType.handle:
512
538
  case DdbType.code: {
513
539
  let value = new Array(length);
514
540
  let i_head = 0, i_tail = i_head;
@@ -602,6 +628,13 @@ class DdbObj {
602
628
  values
603
629
  ];
604
630
  }
631
+ // case DdbType.duration: -> 实际会返回一个 any vector
632
+ // [2y, 1M, 3d, 7H, 11m, 12s, 15ms, 16us, 17ns]
633
+ // <Buffer 19 01 type = any, form = vector
634
+ // 09 00 00 00 01 00 00 00 rows = 9, cols = 1
635
+ // 24 00 type = DdbType.duration, form = scalar
636
+ // 02 00 00 00 09 00 00 00
637
+ // 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>
605
638
  default:
606
639
  return [0, buf];
607
640
  }
@@ -681,6 +714,7 @@ class DdbObj {
681
714
  case DdbType.string:
682
715
  case DdbType.symbol:
683
716
  case DdbType.code:
717
+ case DdbType.handle:
684
718
  return [
685
719
  DdbObj.enc.encode(value),
686
720
  Uint8Array.of(0),
@@ -703,12 +737,12 @@ class DdbObj {
703
737
  case DdbType.complex:
704
738
  case DdbType.point:
705
739
  return [Float64Array.from(this.value)];
706
- case DdbType.duration:
707
- return [value];
708
- case DdbType.handle:
709
- throw new Error('DolphinDB Server 不支持 handle 的反序列化');
740
+ case DdbType.duration: {
741
+ const { unit, data } = this.value;
742
+ return [Int32Array.of(data, unit)];
743
+ }
710
744
  default:
711
- throw new Error(`${DdbType[type]} 暂时不支持序列化`);
745
+ throw new Error(`${DdbType[type] || type} 暂时不支持序列化`);
712
746
  }
713
747
  case DdbForm.vector:
714
748
  case DdbForm.pair:
@@ -801,6 +835,7 @@ class DdbObj {
801
835
  return [value];
802
836
  case DdbType.string:
803
837
  case DdbType.symbol:
838
+ case DdbType.handle:
804
839
  case DdbType.code: {
805
840
  let bufs = new Array(length * 2);
806
841
  for (let i = 0; i < length; i++) {
@@ -887,6 +922,10 @@ class DdbObj {
887
922
  switch (this.type) {
888
923
  case DdbType.functiondef:
889
924
  return `'${this.value.name}'`;
925
+ case DdbType.duration: {
926
+ const { data, unit } = this.value;
927
+ return `${data}${DdbDurationUnit[unit]}`;
928
+ }
890
929
  case DdbType.string:
891
930
  return `'${this.value}'`;
892
931
  }
@@ -1574,25 +1613,30 @@ class DDB {
1574
1613
  catch { }
1575
1614
  // 临界区结束,只有一个 rpc 函数调用运行到这里,可以独占 this.on_message 然后写 WebSocket
1576
1615
  this.on_message = ({ data: buffer }) => {
1577
- const buf = new Uint8Array(buffer);
1578
- if (this.print_message_buffer)
1579
- console.log(buf);
1580
- const message = this.parse_message(buf, parse_object);
1581
- listener?.(message, this);
1582
- for (const listener of _handlers)
1583
- listener(message, this);
1584
- const { type, data } = message;
1585
- switch (type) {
1586
- case 'print':
1587
- if (this.print_message)
1588
- console.log(data);
1589
- return;
1590
- case 'object':
1591
- resolve(data);
1592
- return;
1593
- case 'error':
1594
- reject(data);
1595
- return;
1616
+ try {
1617
+ const buf = new Uint8Array(buffer);
1618
+ if (this.print_message_buffer)
1619
+ console.log(buf);
1620
+ const message = this.parse_message(buf, parse_object);
1621
+ listener?.(message, this);
1622
+ for (const listener of _handlers)
1623
+ listener(message, this);
1624
+ const { type, data } = message;
1625
+ switch (type) {
1626
+ case 'print':
1627
+ if (this.print_message)
1628
+ console.log(data);
1629
+ return;
1630
+ case 'object':
1631
+ resolve(data);
1632
+ return;
1633
+ case 'error':
1634
+ reject(data);
1635
+ return;
1636
+ }
1637
+ }
1638
+ catch (error) {
1639
+ reject(error);
1596
1640
  }
1597
1641
  };
1598
1642
  args = this.to_ddbobjs(args);