dolphindb 2.0.526 → 2.0.529

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.js CHANGED
@@ -1,17 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.nanotime2str = exports.nanotime2ns = exports.str2timestamp = exports.datehour2str = exports.datehour2ms = exports.timestamp2str = exports.timestamp2ms = exports.datetime2str = exports.datetime2ms = exports.second2str = exports.second2ms = exports.minute2str = exports.minute2ms = exports.time2str = exports.time2ms = exports.month2str = exports.month2ms = exports.date2str = exports.date2ms = exports.DdbTable = exports.DdbDict = 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.format = exports.DdbObj = exports.timezone_offset = exports.nulls = exports.DdbChartType = exports.DdbDurationUnit = exports.DdbFunctionType = exports.DdbType = exports.DdbForm = void 0;
4
- exports.DDB = exports.int1282str = exports.uuid2str = exports.ipaddr2str = exports.str2nanotimestamp = exports.nanotimestamp2str = exports.nanotimestamp2ns = void 0;
5
- const tslib_1 = require("tslib");
6
- const ws_1 = require("ws");
7
- const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
8
- const customParseFormat_js_1 = tslib_1.__importDefault(require("dayjs/plugin/customParseFormat.js"));
9
- dayjs_1.default.extend(customParseFormat_js_1.default);
10
- const ipaddr_js_1 = tslib_1.__importDefault(require("ipaddr.js"));
11
- const { fromByteArray: buf2ipaddr } = ipaddr_js_1.default;
12
- const net_js_1 = require("xshell/net.js");
13
- const utils_js_1 = require("xshell/utils.js");
14
- var DdbForm;
1
+ import { WebSocket } from 'ws';
2
+ import dayjs from 'dayjs';
3
+ import DayjsCustomParseFormat from 'dayjs/plugin/customParseFormat.js';
4
+ dayjs.extend(DayjsCustomParseFormat);
5
+ import ipaddrjs from 'ipaddr.js';
6
+ const { fromByteArray: buf2ipaddr } = ipaddrjs;
7
+ import { connect_websocket } from 'xshell/net.js';
8
+ import { concat, inspect, typed_array_to_buffer } from 'xshell/utils.js';
9
+ export var DdbForm;
15
10
  (function (DdbForm) {
16
11
  DdbForm[DdbForm["scalar"] = 0] = "scalar";
17
12
  DdbForm[DdbForm["vector"] = 1] = "vector";
@@ -25,12 +20,12 @@ var DdbForm;
25
20
  DdbForm[DdbForm["chunk"] = 8] = "chunk";
26
21
  /** sysobj */
27
22
  DdbForm[DdbForm["object"] = 9] = "object";
28
- })(DdbForm = exports.DdbForm || (exports.DdbForm = {}));
23
+ })(DdbForm = DdbForm || (DdbForm = {}));
29
24
  /** DolphinDB DataType
30
25
  对应的 array vector 类型为 64 + 基本类型
31
26
  对应的 extended 类型为 128 + 基本类型
32
27
  */
33
- var DdbType;
28
+ export var DdbType;
34
29
  (function (DdbType) {
35
30
  DdbType[DdbType["void"] = 0] = "void";
36
31
  DdbType[DdbType["bool"] = 1] = "bool";
@@ -69,8 +64,8 @@ var DdbType;
69
64
  DdbType[DdbType["duration"] = 36] = "duration";
70
65
  DdbType[DdbType["object"] = 37] = "object";
71
66
  DdbType[DdbType["symbol_extended"] = 145] = "symbol_extended";
72
- })(DdbType = exports.DdbType || (exports.DdbType = {}));
73
- var DdbFunctionType;
67
+ })(DdbType = DdbType || (DdbType = {}));
68
+ export var DdbFunctionType;
74
69
  (function (DdbFunctionType) {
75
70
  DdbFunctionType[DdbFunctionType["SystemFunc"] = 0] = "SystemFunc";
76
71
  DdbFunctionType[DdbFunctionType["SystemProc"] = 1] = "SystemProc";
@@ -81,8 +76,8 @@ var DdbFunctionType;
81
76
  DdbFunctionType[DdbFunctionType["PiecewiseFunc"] = 6] = "PiecewiseFunc";
82
77
  DdbFunctionType[DdbFunctionType["JitFunc"] = 7] = "JitFunc";
83
78
  DdbFunctionType[DdbFunctionType["JitPartialFunc"] = 8] = "JitPartialFunc";
84
- })(DdbFunctionType = exports.DdbFunctionType || (exports.DdbFunctionType = {}));
85
- var DdbDurationUnit;
79
+ })(DdbFunctionType = DdbFunctionType || (DdbFunctionType = {}));
80
+ export var DdbDurationUnit;
86
81
  (function (DdbDurationUnit) {
87
82
  DdbDurationUnit[DdbDurationUnit["ns"] = 0] = "ns";
88
83
  DdbDurationUnit[DdbDurationUnit["us"] = 1] = "us";
@@ -95,8 +90,8 @@ var DdbDurationUnit;
95
90
  DdbDurationUnit[DdbDurationUnit["M"] = 8] = "M";
96
91
  DdbDurationUnit[DdbDurationUnit["y"] = 9] = "y";
97
92
  DdbDurationUnit[DdbDurationUnit["B"] = 10] = "B";
98
- })(DdbDurationUnit = exports.DdbDurationUnit || (exports.DdbDurationUnit = {}));
99
- var DdbChartType;
93
+ })(DdbDurationUnit = DdbDurationUnit || (DdbDurationUnit = {}));
94
+ export var DdbChartType;
100
95
  (function (DdbChartType) {
101
96
  DdbChartType[DdbChartType["area"] = 0] = "area";
102
97
  DdbChartType[DdbChartType["bar"] = 1] = "bar";
@@ -107,23 +102,55 @@ var DdbChartType;
107
102
  DdbChartType[DdbChartType["scatter"] = 6] = "scatter";
108
103
  DdbChartType[DdbChartType["trend"] = 7] = "trend";
109
104
  DdbChartType[DdbChartType["kline"] = 8] = "kline";
110
- })(DdbChartType = exports.DdbChartType || (exports.DdbChartType = {}));
111
- exports.nulls = {
105
+ })(DdbChartType = DdbChartType || (DdbChartType = {}));
106
+ export const nulls = {
112
107
  int8: -0x80,
113
- int16: -32768,
114
- int32: -2147483648,
108
+ int16: -0x80_00,
109
+ int32: -0x80_00_00_00,
115
110
  int64: -0x8000000000000000n,
116
111
  float32: -3.4028234663852886e+38,
117
112
  /** -Number.MAX_VALUE */
118
113
  double: -Number.MAX_VALUE,
119
114
  bytes16: Uint8Array.from(new Array(16).fill(0))
120
115
  };
121
- exports.timezone_offset = 1000 * 60 * new Date().getTimezoneOffset();
116
+ export const timezone_offset = 1000 * 60 * new Date().getTimezoneOffset();
122
117
  /** 可以表示所有 DolphinDB 数据库中的数据类型 */
123
- class DdbObj {
118
+ export class DdbObj {
119
+ static dec = new TextDecoder('utf-8');
120
+ static enc = new TextEncoder();
121
+ /** 维护已解析的 symbol base,比如流数据中后续的 symbol 向量可能只发送一个 base.id, base.size == 0, 依赖之前发送的 symbol base ?
122
+ 只是暂存,如果一张表有多个 symbol 列,可能这个 symbol base 会被复用,不同的对象之间 symbol base 一般不复用
123
+ */
124
+ static symbol_bases = {};
125
+ /** little endian (client) */
126
+ static le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
127
+ /** 是否为小端 (little endian) */
128
+ le = DdbObj.le_client;
129
+ /** 数据形式 https://www.dolphindb.cn/cn/help/DataTypesandStructures/DataForms/index.html */
130
+ form;
131
+ /** 数据类型 https://www.dolphindb.cn/cn/help/DataTypesandStructures/DataTypes/index.html */
132
+ type;
133
+ /** 占用 parse 时传入的 buf 的长度 */
134
+ length;
135
+ /** table name / column name */
136
+ name;
137
+ /**
138
+ 最低维、第 1 维
139
+ - vector: rows = n, cols = 1
140
+ - pair: rows = 2, cols = 1
141
+ - matrix: rows = n, cols = m
142
+ - set: 同 vector
143
+ - dict: 包含 keys, values 向量
144
+ - table: 同 matrix
145
+ */
146
+ rows;
147
+ /** 第 2 维 */
148
+ cols;
149
+ /** 实际数据。不同的 DdbForm, DdbType 使用 DdbValue 中不同的类型来表示实际数据 */
150
+ value;
151
+ /** 原始二进制数据,仅在 parse_object 为 false 时通过 parse_message 生成的顶层对象有这个属性 */
152
+ buffer;
124
153
  constructor(data) {
125
- /** 是否为小端 (little endian) */
126
- this.le = DdbObj.le_client;
127
154
  Object.assign(this, data);
128
155
  }
129
156
  static parse(buf, le) {
@@ -242,7 +269,6 @@ class DdbObj {
242
269
  else {
243
270
  const { chartType: type, stacking, title: titles, extras, data, ...others } = dict.to_dict();
244
271
  const [chart, x_axis, y_axis] = titles.value;
245
- const { multiYAxes: multi_y_axis, ...extras_others } = extras.to_dict({ strip: true });
246
272
  dict.form = DdbForm.chart;
247
273
  dict.value = {
248
274
  type: type.value,
@@ -252,10 +278,15 @@ class DdbObj {
252
278
  x_axis,
253
279
  y_axis,
254
280
  },
255
- extras: {
256
- multi_y_axis,
257
- ...extras_others,
258
- },
281
+ ...extras ? (() => {
282
+ const { multiYAxes: multi_y_axes = false, ...extras_others } = extras.to_dict({ strip: true });
283
+ return {
284
+ extras: {
285
+ multi_y_axes,
286
+ ...extras_others,
287
+ }
288
+ };
289
+ })() : {},
259
290
  data,
260
291
  ...others,
261
292
  };
@@ -336,17 +367,17 @@ class DdbObj {
336
367
  case DdbType.bool: {
337
368
  const dv = new DataView(buf.buffer, buf.byteOffset);
338
369
  const value = dv.getInt8(0);
339
- return [1, value === exports.nulls.int8 ? null : Boolean(value)];
370
+ return [1, value === nulls.int8 ? null : Boolean(value)];
340
371
  }
341
372
  case DdbType.char: {
342
373
  const dv = new DataView(buf.buffer, buf.byteOffset);
343
374
  const value = dv.getInt8(0);
344
- return [1, value === exports.nulls.int8 ? null : value];
375
+ return [1, value === nulls.int8 ? null : value];
345
376
  }
346
377
  case DdbType.short: {
347
378
  const dv = new DataView(buf.buffer, buf.byteOffset);
348
379
  const value = dv.getInt16(0, le);
349
- return [2, value === exports.nulls.int16 ? null : value];
380
+ return [2, value === nulls.int16 ? null : value];
350
381
  }
351
382
  case DdbType.int:
352
383
  // datetime
@@ -359,17 +390,17 @@ class DdbObj {
359
390
  case DdbType.datehour: {
360
391
  const dv = new DataView(buf.buffer, buf.byteOffset);
361
392
  const value = dv.getInt32(0, le);
362
- return [4, value === exports.nulls.int32 ? null : value];
393
+ return [4, value === nulls.int32 ? null : value];
363
394
  }
364
395
  case DdbType.float: {
365
396
  const dv = new DataView(buf.buffer, buf.byteOffset);
366
397
  const value = dv.getFloat32(0, le);
367
- return [4, value === exports.nulls.float32 ? null : value];
398
+ return [4, value === nulls.float32 ? null : value];
368
399
  }
369
400
  case DdbType.double: {
370
401
  const dv = new DataView(buf.buffer, buf.byteOffset);
371
402
  const value = dv.getFloat64(0, le);
372
- return [8, value === exports.nulls.double ? null : value];
403
+ return [8, value === nulls.double ? null : value];
373
404
  }
374
405
  case DdbType.long:
375
406
  // timestamp
@@ -378,7 +409,7 @@ class DdbObj {
378
409
  case DdbType.nanotimestamp: {
379
410
  const dv = new DataView(buf.buffer, buf.byteOffset);
380
411
  const value = dv.getBigInt64(0, le);
381
- return [8, value === exports.nulls.int64 ? null : value];
412
+ return [8, value === nulls.int64 ? null : value];
382
413
  }
383
414
  case DdbType.string:
384
415
  case DdbType.symbol:
@@ -700,21 +731,21 @@ class DdbObj {
700
731
  case DdbType.bool:
701
732
  return [
702
733
  Int8Array.of(value === null ?
703
- exports.nulls.int8
734
+ nulls.int8
704
735
  :
705
736
  Number(value))
706
737
  ];
707
738
  case DdbType.char:
708
739
  return [
709
740
  Int8Array.of((value === null ?
710
- exports.nulls.int8
741
+ nulls.int8
711
742
  :
712
743
  value))
713
744
  ];
714
745
  case DdbType.short:
715
746
  return [
716
747
  Int16Array.of(value === null ?
717
- exports.nulls.int16
748
+ nulls.int16
718
749
  :
719
750
  value)
720
751
  ];
@@ -729,21 +760,21 @@ class DdbObj {
729
760
  case DdbType.datehour:
730
761
  return [
731
762
  Int32Array.of(value === null ?
732
- exports.nulls.int32
763
+ nulls.int32
733
764
  :
734
765
  value)
735
766
  ];
736
767
  case DdbType.float:
737
768
  return [
738
769
  Float32Array.of(value === null ?
739
- exports.nulls.float32
770
+ nulls.float32
740
771
  :
741
772
  value)
742
773
  ];
743
774
  case DdbType.double:
744
775
  return [
745
776
  Float64Array.of(value === null ?
746
- exports.nulls.double
777
+ nulls.double
747
778
  :
748
779
  value)
749
780
  ];
@@ -754,7 +785,7 @@ class DdbObj {
754
785
  case DdbType.nanotimestamp:
755
786
  return [
756
787
  BigInt64Array.of(value === null ?
757
- exports.nulls.int64
788
+ nulls.int64
758
789
  :
759
790
  value)
760
791
  ];
@@ -831,15 +862,20 @@ class DdbObj {
831
862
  value[1].pack(),
832
863
  ];
833
864
  case DdbForm.chart: {
834
- const { type, stacking, titles: { chart, x_axis, y_axis, }, extras: { multi_y_axis, ...extras_other }, data } = this.value;
865
+ const { type, stacking, titles: { chart, x_axis, y_axis, }, extras, data } = this.value;
835
866
  const { value: [keys, values] } = new DdbDict({
836
867
  chartType: new DdbInt(type),
837
868
  stacking,
838
869
  title: new DdbVectorString([chart, x_axis, y_axis]),
839
- extras: new DdbDict({
840
- multiYAxis: multi_y_axis,
841
- ...extras_other
842
- }),
870
+ ...extras ? (() => {
871
+ const { multi_y_axes, ...extras_other } = extras;
872
+ return {
873
+ extras: new DdbDict({
874
+ multiYAxes: multi_y_axes,
875
+ ...extras_other
876
+ })
877
+ };
878
+ })() : {},
843
879
  data,
844
880
  });
845
881
  return [
@@ -864,7 +900,7 @@ class DdbObj {
864
900
  })();
865
901
  if (!body)
866
902
  return new Uint8Array(0);
867
- return (0, utils_js_1.concat)([
903
+ return concat([
868
904
  header,
869
905
  ...body
870
906
  ]);
@@ -952,34 +988,8 @@ class DdbObj {
952
988
  throw new Error(`vector ${DdbType[type]} 暂不支持序列化`);
953
989
  }
954
990
  }
955
- [utils_js_1.inspect.custom](depth, options, _inspect) {
956
- const type = (() => {
957
- const tname = DdbType[this.type];
958
- switch (this.form) {
959
- case DdbForm.scalar:
960
- if (this.type === DdbType.functiondef)
961
- return `functiondef<${DdbFunctionType[this.value.type]}>`;
962
- return tname;
963
- case DdbForm.vector:
964
- if (64 <= this.type && this.type < 128)
965
- return `${DdbType[this.type - 64]}[][${this.rows}]`;
966
- return `${tname}[${this.rows}]`;
967
- case DdbForm.pair:
968
- return `pair<${tname}>`;
969
- case DdbForm.set:
970
- return `set<${tname}>[${this.rows}]`;
971
- case DdbForm.table:
972
- return `table[${this.rows}r][${this.cols}c]`;
973
- case DdbForm.dict:
974
- return `dict<${DdbType[this.value[0].type]}, ${DdbType[this.value[1].type]}>`;
975
- case DdbForm.chart:
976
- return `chart<${DdbChartType[this.value.type]}>`;
977
- case DdbForm.matrix:
978
- return `matrix<${tname}>[${this.rows}r][${this.cols}c]`;
979
- default:
980
- return `${DdbForm[this.form]} ${tname}`;
981
- }
982
- })();
991
+ [inspect.custom](depth, options, _inspect) {
992
+ const type = this.inspect_type();
983
993
  const data = (() => {
984
994
  switch (this.form) {
985
995
  case DdbForm.scalar:
@@ -1029,7 +1039,7 @@ class DdbObj {
1029
1039
  const { base, data } = this.value;
1030
1040
  let items = new Array(Math.min(limit, data.length));
1031
1041
  for (let i = 0; i < items.length; i++)
1032
- items[i] = (0, utils_js_1.inspect)(base[data[i]], options);
1042
+ items[i] = inspect(base[data[i]], options);
1033
1043
  return format_array(items, data.length > limit);
1034
1044
  }
1035
1045
  case DdbType.uuid:
@@ -1064,10 +1074,37 @@ class DdbObj {
1064
1074
  }
1065
1075
  }
1066
1076
  if (this.value instanceof Uint8Array)
1067
- return (0, utils_js_1.inspect)((0, utils_js_1.typed_array_to_buffer)(this.value), options);
1068
- return (0, utils_js_1.inspect)(this.value, options);
1077
+ return inspect(typed_array_to_buffer(this.value), options);
1078
+ return inspect(this.value, options);
1069
1079
  })();
1070
- return `${options.colors ? type.blue : type}(${this.name ? `${(0, utils_js_1.inspect)(this.name, options)}, ` : ''}${data})`;
1080
+ return `${options.colors ? type.blue : type}(${this.name ? `${inspect(this.name, options)}, ` : ''}${data})`;
1081
+ }
1082
+ inspect_type() {
1083
+ const tname = DdbType[this.type];
1084
+ switch (this.form) {
1085
+ case DdbForm.scalar:
1086
+ if (this.type === DdbType.functiondef)
1087
+ return `functiondef<${DdbFunctionType[this.value.type]}>`;
1088
+ return tname;
1089
+ case DdbForm.vector:
1090
+ if (64 <= this.type && this.type < 128)
1091
+ return `${DdbType[this.type - 64]}[][${this.rows}]`;
1092
+ return `${tname}[${this.rows}]`;
1093
+ case DdbForm.pair:
1094
+ return `pair<${tname}>`;
1095
+ case DdbForm.set:
1096
+ return `set<${tname}>[${this.rows}]`;
1097
+ case DdbForm.table:
1098
+ return `table[${this.rows}r][${this.cols}c]`;
1099
+ case DdbForm.dict:
1100
+ return `dict<${DdbType[this.value[0].type]}, ${DdbType[this.value[1].type]}>`;
1101
+ case DdbForm.chart:
1102
+ return `chart<${DdbChartType[this.value.type]}>`;
1103
+ case DdbForm.matrix:
1104
+ return `matrix<${tname}>[${this.rows}r][${this.cols}c]`;
1105
+ default:
1106
+ return `${DdbForm[this.form]} ${tname}`;
1107
+ }
1071
1108
  }
1072
1109
  /** 自动转换 js string, boolean 为 DdbObj */
1073
1110
  static to_ddbobj(value) {
@@ -1098,7 +1135,7 @@ class DdbObj {
1098
1135
  switch (type) {
1099
1136
  case DdbType.bool: {
1100
1137
  const value = values[i];
1101
- row[name] = value === exports.nulls.int8 ?
1138
+ row[name] = value === nulls.int8 ?
1102
1139
  null
1103
1140
  :
1104
1141
  Boolean(value);
@@ -1139,24 +1176,15 @@ class DdbObj {
1139
1176
  return obj;
1140
1177
  }
1141
1178
  }
1142
- exports.DdbObj = DdbObj;
1143
- DdbObj.dec = new TextDecoder('utf-8');
1144
- DdbObj.enc = new TextEncoder();
1145
- /** 维护已解析的 symbol base,比如流数据中后续的 symbol 向量可能只发送一个 base.id, base.size == 0, 依赖之前发送的 symbol base ?
1146
- 只是暂存,如果一张表有多个 symbol 列,可能这个 symbol base 会被复用,不同的对象之间 symbol base 一般不复用
1147
- */
1148
- DdbObj.symbol_bases = {};
1149
- /** little endian (client) */
1150
- DdbObj.le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
1151
- function format(type, value, le, options) {
1179
+ export function format(type, value, le, options) {
1152
1180
  switch (type) {
1153
1181
  case DdbType.bool:
1154
- return (0, utils_js_1.inspect)((value === null || value === exports.nulls.int8) ?
1182
+ return inspect((value === null || value === nulls.int8) ?
1155
1183
  null
1156
1184
  :
1157
1185
  Boolean(value), options);
1158
1186
  case DdbType.char:
1159
- return (0, utils_js_1.inspect)((value === null || value === exports.nulls.int8) ?
1187
+ return inspect((value === null || value === nulls.int8) ?
1160
1188
  null
1161
1189
  :
1162
1190
  // ascii printable
@@ -1166,17 +1194,17 @@ function format(type, value, le, options) {
1166
1194
  :
1167
1195
  value, options);
1168
1196
  case DdbType.short:
1169
- return (0, utils_js_1.inspect)((value === null || value === exports.nulls.int16) ?
1197
+ return inspect((value === null || value === nulls.int16) ?
1170
1198
  null
1171
1199
  :
1172
1200
  value, options);
1173
1201
  case DdbType.int:
1174
- return (0, utils_js_1.inspect)((value === null || value === exports.nulls.int32) ?
1202
+ return inspect((value === null || value === nulls.int32) ?
1175
1203
  null
1176
1204
  :
1177
1205
  value, options);
1178
1206
  case DdbType.long:
1179
- return (value === null || value === exports.nulls.int64) ?
1207
+ return (value === null || value === nulls.int64) ?
1180
1208
  'null'
1181
1209
  :
1182
1210
  options.colors ?
@@ -1184,7 +1212,7 @@ function format(type, value, le, options) {
1184
1212
  :
1185
1213
  String(value);
1186
1214
  case DdbType.date:
1187
- return (value === null || value === exports.nulls.int32) ?
1215
+ return (value === null || value === nulls.int32) ?
1188
1216
  'null'
1189
1217
  :
1190
1218
  options.colors ?
@@ -1192,7 +1220,7 @@ function format(type, value, le, options) {
1192
1220
  :
1193
1221
  date2str(value);
1194
1222
  case DdbType.month:
1195
- return (value === null || value === exports.nulls.int32) ?
1223
+ return (value === null || value === nulls.int32) ?
1196
1224
  'null'
1197
1225
  :
1198
1226
  options.colors ?
@@ -1200,7 +1228,7 @@ function format(type, value, le, options) {
1200
1228
  :
1201
1229
  month2str(value);
1202
1230
  case DdbType.time:
1203
- return (value === null || value === exports.nulls.int32) ?
1231
+ return (value === null || value === nulls.int32) ?
1204
1232
  'null'
1205
1233
  :
1206
1234
  options.colors ?
@@ -1208,7 +1236,7 @@ function format(type, value, le, options) {
1208
1236
  :
1209
1237
  time2str(value);
1210
1238
  case DdbType.minute:
1211
- return (value === null || value === exports.nulls.int32) ?
1239
+ return (value === null || value === nulls.int32) ?
1212
1240
  'null'
1213
1241
  :
1214
1242
  options.colors ?
@@ -1216,7 +1244,7 @@ function format(type, value, le, options) {
1216
1244
  :
1217
1245
  minute2str(value);
1218
1246
  case DdbType.second:
1219
- return (value === null || value === exports.nulls.int32) ?
1247
+ return (value === null || value === nulls.int32) ?
1220
1248
  'null'
1221
1249
  :
1222
1250
  options.colors ?
@@ -1224,7 +1252,7 @@ function format(type, value, le, options) {
1224
1252
  :
1225
1253
  second2str(value);
1226
1254
  case DdbType.datetime:
1227
- return (value === null || value === exports.nulls.int32) ?
1255
+ return (value === null || value === nulls.int32) ?
1228
1256
  'null'
1229
1257
  :
1230
1258
  options.colors ?
@@ -1232,7 +1260,7 @@ function format(type, value, le, options) {
1232
1260
  :
1233
1261
  datetime2str(value);
1234
1262
  case DdbType.timestamp:
1235
- return (value === null || value === exports.nulls.int64) ?
1263
+ return (value === null || value === nulls.int64) ?
1236
1264
  'null'
1237
1265
  :
1238
1266
  options.colors ?
@@ -1240,7 +1268,7 @@ function format(type, value, le, options) {
1240
1268
  :
1241
1269
  timestamp2str(value);
1242
1270
  case DdbType.nanotime:
1243
- return (value === null || value === exports.nulls.int64) ?
1271
+ return (value === null || value === nulls.int64) ?
1244
1272
  'null'
1245
1273
  :
1246
1274
  options.colors ?
@@ -1248,7 +1276,7 @@ function format(type, value, le, options) {
1248
1276
  :
1249
1277
  nanotime2str(value);
1250
1278
  case DdbType.nanotimestamp:
1251
- return (value === null || value === exports.nulls.int64) ?
1279
+ return (value === null || value === nulls.int64) ?
1252
1280
  'null'
1253
1281
  :
1254
1282
  options.colors ?
@@ -1256,30 +1284,30 @@ function format(type, value, le, options) {
1256
1284
  :
1257
1285
  nanotimestamp2str(value);
1258
1286
  case DdbType.float:
1259
- return (value === null || value === exports.nulls.float32) ?
1287
+ return (value === null || value === nulls.float32) ?
1260
1288
  'null'
1261
1289
  :
1262
- (0, utils_js_1.inspect)(value, options);
1290
+ inspect(value, options);
1263
1291
  case DdbType.double:
1264
- return (value === null || value === exports.nulls.double) ?
1292
+ return (value === null || value === nulls.double) ?
1265
1293
  'null'
1266
1294
  :
1267
- (0, utils_js_1.inspect)(value, options);
1295
+ inspect(value, options);
1268
1296
  case DdbType.symbol:
1269
1297
  case DdbType.string:
1270
- return (0, utils_js_1.inspect)(value, options);
1298
+ return inspect(value, options);
1271
1299
  case DdbType.uuid:
1272
1300
  return options.colors ?
1273
1301
  uuid2str(value, le).green
1274
1302
  :
1275
1303
  uuid2str(value, le);
1276
1304
  case DdbType.functiondef:
1277
- return (0, utils_js_1.inspect)(value.name, options);
1305
+ return inspect(value.name, options);
1278
1306
  case DdbType.handle:
1279
1307
  case DdbType.code:
1280
- return (0, utils_js_1.inspect)(value, options);
1308
+ return inspect(value, options);
1281
1309
  case DdbType.datehour:
1282
- return (value === null || value === exports.nulls.int32) ?
1310
+ return (value === null || value === nulls.int32) ?
1283
1311
  'null'
1284
1312
  :
1285
1313
  options.colors ?
@@ -1297,15 +1325,15 @@ function format(type, value, le, options) {
1297
1325
  :
1298
1326
  int1282str(value, le);
1299
1327
  case DdbType.blob:
1300
- return (0, utils_js_1.inspect)(value.length > 100 ?
1328
+ return inspect(value.length > 100 ?
1301
1329
  DdbObj.dec.decode(value.subarray(0, 98)) + '…'
1302
1330
  :
1303
1331
  DdbObj.dec.decode(value), options);
1304
1332
  case DdbType.point: {
1305
1333
  let [x, y] = value;
1306
- if (x === exports.nulls.double)
1334
+ if (x === nulls.double)
1307
1335
  x = null;
1308
- if (y === exports.nulls.double)
1336
+ if (y === nulls.double)
1309
1337
  y = null;
1310
1338
  return options.colors ?
1311
1339
  `(${String(x).green}, ${String(y).green})`
@@ -1314,9 +1342,9 @@ function format(type, value, le, options) {
1314
1342
  }
1315
1343
  case DdbType.complex: {
1316
1344
  let [x, y] = value;
1317
- if (x === exports.nulls.double)
1345
+ if (x === nulls.double)
1318
1346
  x = null;
1319
- if (y === exports.nulls.double)
1347
+ if (y === nulls.double)
1320
1348
  y = null;
1321
1349
  return options.colors ?
1322
1350
  `${String(x).green}+${`${String(y)}i`.green}`
@@ -1329,11 +1357,10 @@ function format(type, value, le, options) {
1329
1357
  return options.colors ? str.green : str;
1330
1358
  }
1331
1359
  default:
1332
- return (0, utils_js_1.inspect)(value, options);
1360
+ return inspect(value, options);
1333
1361
  }
1334
1362
  }
1335
- exports.format = format;
1336
- class DdbVoid extends DdbObj {
1363
+ export class DdbVoid extends DdbObj {
1337
1364
  constructor() {
1338
1365
  super({
1339
1366
  form: DdbForm.scalar,
@@ -1342,8 +1369,7 @@ class DdbVoid extends DdbObj {
1342
1369
  });
1343
1370
  }
1344
1371
  }
1345
- exports.DdbVoid = DdbVoid;
1346
- class DdbBool extends DdbObj {
1372
+ export class DdbBool extends DdbObj {
1347
1373
  constructor(value) {
1348
1374
  super({
1349
1375
  form: DdbForm.scalar,
@@ -1352,8 +1378,7 @@ class DdbBool extends DdbObj {
1352
1378
  });
1353
1379
  }
1354
1380
  }
1355
- exports.DdbBool = DdbBool;
1356
- class DdbChar extends DdbObj {
1381
+ export class DdbChar extends DdbObj {
1357
1382
  constructor(value) {
1358
1383
  super({
1359
1384
  form: DdbForm.scalar,
@@ -1365,8 +1390,7 @@ class DdbChar extends DdbObj {
1365
1390
  });
1366
1391
  }
1367
1392
  }
1368
- exports.DdbChar = DdbChar;
1369
- class DdbInt extends DdbObj {
1393
+ export class DdbInt extends DdbObj {
1370
1394
  constructor(value) {
1371
1395
  super({
1372
1396
  form: DdbForm.scalar,
@@ -1375,8 +1399,7 @@ class DdbInt extends DdbObj {
1375
1399
  });
1376
1400
  }
1377
1401
  }
1378
- exports.DdbInt = DdbInt;
1379
- class DdbString extends DdbObj {
1402
+ export class DdbString extends DdbObj {
1380
1403
  constructor(value) {
1381
1404
  super({
1382
1405
  form: DdbForm.scalar,
@@ -1385,8 +1408,7 @@ class DdbString extends DdbObj {
1385
1408
  });
1386
1409
  }
1387
1410
  }
1388
- exports.DdbString = DdbString;
1389
- class DdbLong extends DdbObj {
1411
+ export class DdbLong extends DdbObj {
1390
1412
  constructor(value) {
1391
1413
  super({
1392
1414
  form: DdbForm.scalar,
@@ -1395,8 +1417,7 @@ class DdbLong extends DdbObj {
1395
1417
  });
1396
1418
  }
1397
1419
  }
1398
- exports.DdbLong = DdbLong;
1399
- class DdbDouble extends DdbObj {
1420
+ export class DdbDouble extends DdbObj {
1400
1421
  constructor(value) {
1401
1422
  super({
1402
1423
  form: DdbForm.scalar,
@@ -1405,8 +1426,7 @@ class DdbDouble extends DdbObj {
1405
1426
  });
1406
1427
  }
1407
1428
  }
1408
- exports.DdbDouble = DdbDouble;
1409
- class DdbDateTime extends DdbObj {
1429
+ export class DdbDateTime extends DdbObj {
1410
1430
  constructor(value) {
1411
1431
  super({
1412
1432
  form: DdbForm.scalar,
@@ -1415,8 +1435,7 @@ class DdbDateTime extends DdbObj {
1415
1435
  });
1416
1436
  }
1417
1437
  }
1418
- exports.DdbDateTime = DdbDateTime;
1419
- class DdbTimeStamp extends DdbObj {
1438
+ export class DdbTimeStamp extends DdbObj {
1420
1439
  constructor(value) {
1421
1440
  super({
1422
1441
  form: DdbForm.scalar,
@@ -1425,8 +1444,7 @@ class DdbTimeStamp extends DdbObj {
1425
1444
  });
1426
1445
  }
1427
1446
  }
1428
- exports.DdbTimeStamp = DdbTimeStamp;
1429
- class DdbNanoTimeStamp extends DdbObj {
1447
+ export class DdbNanoTimeStamp extends DdbObj {
1430
1448
  constructor(value) {
1431
1449
  super({
1432
1450
  form: DdbForm.scalar,
@@ -1435,20 +1453,18 @@ class DdbNanoTimeStamp extends DdbObj {
1435
1453
  });
1436
1454
  }
1437
1455
  }
1438
- exports.DdbNanoTimeStamp = DdbNanoTimeStamp;
1439
- class DdbPair extends DdbObj {
1456
+ export class DdbPair extends DdbObj {
1440
1457
  constructor(l, r = null) {
1441
1458
  super({
1442
1459
  form: DdbForm.pair,
1443
1460
  type: DdbType.int,
1444
1461
  rows: 2,
1445
1462
  cols: 1,
1446
- value: Int32Array.of(l === null ? exports.nulls.int32 : l, r === null ? exports.nulls.int32 : r)
1463
+ value: Int32Array.of(l === null ? nulls.int32 : l, r === null ? nulls.int32 : r)
1447
1464
  });
1448
1465
  }
1449
1466
  }
1450
- exports.DdbPair = DdbPair;
1451
- class DdbFunction extends DdbObj {
1467
+ export class DdbFunction extends DdbObj {
1452
1468
  constructor(name, type) {
1453
1469
  super({
1454
1470
  form: DdbForm.scalar,
@@ -1457,8 +1473,7 @@ class DdbFunction extends DdbObj {
1457
1473
  });
1458
1474
  }
1459
1475
  }
1460
- exports.DdbFunction = DdbFunction;
1461
- class DdbVectorInt extends DdbObj {
1476
+ export class DdbVectorInt extends DdbObj {
1462
1477
  constructor(ints, name) {
1463
1478
  super({
1464
1479
  form: DdbForm.vector,
@@ -1469,15 +1484,14 @@ class DdbVectorInt extends DdbObj {
1469
1484
  ints
1470
1485
  :
1471
1486
  Int32Array.from(ints, v => v === null ?
1472
- exports.nulls.int32
1487
+ nulls.int32
1473
1488
  :
1474
1489
  v),
1475
1490
  name,
1476
1491
  });
1477
1492
  }
1478
1493
  }
1479
- exports.DdbVectorInt = DdbVectorInt;
1480
- class DdbVectorDouble extends DdbObj {
1494
+ export class DdbVectorDouble extends DdbObj {
1481
1495
  constructor(doubles, name) {
1482
1496
  super({
1483
1497
  form: DdbForm.vector,
@@ -1488,15 +1502,14 @@ class DdbVectorDouble extends DdbObj {
1488
1502
  doubles
1489
1503
  :
1490
1504
  Float64Array.from(doubles, v => v === null ?
1491
- exports.nulls.double
1505
+ nulls.double
1492
1506
  :
1493
1507
  v),
1494
1508
  name,
1495
1509
  });
1496
1510
  }
1497
1511
  }
1498
- exports.DdbVectorDouble = DdbVectorDouble;
1499
- class DdbVectorString extends DdbObj {
1512
+ export class DdbVectorString extends DdbObj {
1500
1513
  constructor(strings, name) {
1501
1514
  super({
1502
1515
  form: DdbForm.vector,
@@ -1508,8 +1521,7 @@ class DdbVectorString extends DdbObj {
1508
1521
  });
1509
1522
  }
1510
1523
  }
1511
- exports.DdbVectorString = DdbVectorString;
1512
- class DdbVectorAny extends DdbObj {
1524
+ export class DdbVectorAny extends DdbObj {
1513
1525
  constructor(objs, name) {
1514
1526
  super({
1515
1527
  form: DdbForm.vector,
@@ -1521,8 +1533,7 @@ class DdbVectorAny extends DdbObj {
1521
1533
  });
1522
1534
  }
1523
1535
  }
1524
- exports.DdbVectorAny = DdbVectorAny;
1525
- class DdbVectorSymbol extends DdbObj {
1536
+ export class DdbVectorSymbol extends DdbObj {
1526
1537
  constructor(strings, name) {
1527
1538
  let map = new Map([
1528
1539
  ['', 0]
@@ -1551,8 +1562,7 @@ class DdbVectorSymbol extends DdbObj {
1551
1562
  });
1552
1563
  }
1553
1564
  }
1554
- exports.DdbVectorSymbol = DdbVectorSymbol;
1555
- class DdbSetInt extends DdbObj {
1565
+ export class DdbSetInt extends DdbObj {
1556
1566
  constructor(ints) {
1557
1567
  super({
1558
1568
  form: DdbForm.set,
@@ -1566,14 +1576,13 @@ class DdbSetInt extends DdbObj {
1566
1576
  ints
1567
1577
  :
1568
1578
  Int32Array.from(ints, v => v === null ?
1569
- exports.nulls.int32
1579
+ nulls.int32
1570
1580
  :
1571
1581
  v),
1572
1582
  });
1573
1583
  }
1574
1584
  }
1575
- exports.DdbSetInt = DdbSetInt;
1576
- class DdbSetDouble extends DdbObj {
1585
+ export class DdbSetDouble extends DdbObj {
1577
1586
  constructor(doubles) {
1578
1587
  super({
1579
1588
  form: DdbForm.set,
@@ -1587,14 +1596,13 @@ class DdbSetDouble extends DdbObj {
1587
1596
  doubles
1588
1597
  :
1589
1598
  Int32Array.from(doubles, v => v === null ?
1590
- exports.nulls.int32
1599
+ nulls.int32
1591
1600
  :
1592
1601
  v),
1593
1602
  });
1594
1603
  }
1595
1604
  }
1596
- exports.DdbSetDouble = DdbSetDouble;
1597
- class DdbSetString extends DdbObj {
1605
+ export class DdbSetString extends DdbObj {
1598
1606
  constructor(strings) {
1599
1607
  if (strings instanceof Set)
1600
1608
  strings = [...strings];
@@ -1607,12 +1615,11 @@ class DdbSetString extends DdbObj {
1607
1615
  });
1608
1616
  }
1609
1617
  }
1610
- exports.DdbSetString = DdbSetString;
1611
1618
  /** Constructs a DdbDict object, which supports two usages:
1612
1619
  - The incoming type is the keys of DdbObj<DdbVectorValue>, and the two parameters of values directly form the DdbDict of dict<keys.type, values.type>
1613
1620
  - Pass in js object (type is Record<string, boolean | string | DdbObj>), automatically converted to DdbDict of dict<string, any>
1614
1621
  */
1615
- class DdbDict extends DdbObj {
1622
+ export class DdbDict extends DdbObj {
1616
1623
  constructor(arg0, arg1) {
1617
1624
  if (arg1)
1618
1625
  super({
@@ -1637,8 +1644,7 @@ class DdbDict extends DdbObj {
1637
1644
  }
1638
1645
  }
1639
1646
  }
1640
- exports.DdbDict = DdbDict;
1641
- class DdbTable extends DdbObj {
1647
+ export class DdbTable extends DdbObj {
1642
1648
  constructor(columns, name = '') {
1643
1649
  super({
1644
1650
  form: DdbForm.table,
@@ -1650,30 +1656,26 @@ class DdbTable extends DdbObj {
1650
1656
  });
1651
1657
  }
1652
1658
  }
1653
- exports.DdbTable = DdbTable;
1654
- function date2ms(date) {
1655
- return (date === null || date === exports.nulls.int32) ?
1659
+ export function date2ms(date) {
1660
+ return (date === null || date === nulls.int32) ?
1656
1661
  null
1657
1662
  :
1658
- exports.timezone_offset + 1000 * 3600 * 24 * date;
1663
+ timezone_offset + 1000 * 3600 * 24 * date;
1659
1664
  }
1660
- exports.date2ms = date2ms;
1661
- function date2str(date, format = 'YYYY.MM.DD') {
1662
- return (date === null || date === exports.nulls.int32) ?
1665
+ export function date2str(date, format = 'YYYY.MM.DD') {
1666
+ return (date === null || date === nulls.int32) ?
1663
1667
  null
1664
1668
  :
1665
- (0, dayjs_1.default)(date2ms(date)).format(format);
1669
+ dayjs(date2ms(date)).format(format);
1666
1670
  }
1667
- exports.date2str = date2str;
1668
- function month2ms(month) {
1669
- return (month === null || month === exports.nulls.int32) ?
1671
+ export function month2ms(month) {
1672
+ return (month === null || month === nulls.int32) ?
1670
1673
  null
1671
1674
  :
1672
- (0, dayjs_1.default)(month2str(month), 'YYYY.MM[M]').valueOf();
1675
+ dayjs(month2str(month), 'YYYY.MM[M]').valueOf();
1673
1676
  }
1674
- exports.month2ms = month2ms;
1675
- function month2str(month) {
1676
- if (month === null || month === exports.nulls.int32)
1677
+ export function month2str(month) {
1678
+ if (month === null || month === nulls.int32)
1677
1679
  return 'null';
1678
1680
  if (month < 0)
1679
1681
  return String(month);
@@ -1681,118 +1683,103 @@ function month2str(month) {
1681
1683
  const year = Math.trunc(month / 12);
1682
1684
  return `${String(year).padStart(4, '0')}.${String(_month + 1).padStart(2, '0')}M`;
1683
1685
  }
1684
- exports.month2str = month2str;
1685
- function time2ms(time) {
1686
- return (time === null || time === exports.nulls.int32) ?
1686
+ export function time2ms(time) {
1687
+ return (time === null || time === nulls.int32) ?
1687
1688
  null
1688
1689
  :
1689
- exports.timezone_offset + time;
1690
+ timezone_offset + time;
1690
1691
  }
1691
- exports.time2ms = time2ms;
1692
- function time2str(time, format = 'HH:mm:ss.SSS') {
1693
- return (time === null || time === exports.nulls.int32) ?
1692
+ export function time2str(time, format = 'HH:mm:ss.SSS') {
1693
+ return (time === null || time === nulls.int32) ?
1694
1694
  null
1695
1695
  :
1696
- (0, dayjs_1.default)(time2ms(time)).format(format);
1696
+ dayjs(time2ms(time)).format(format);
1697
1697
  }
1698
- exports.time2str = time2str;
1699
- function minute2ms(minute) {
1700
- return (minute === null || minute === exports.nulls.int32) ?
1698
+ export function minute2ms(minute) {
1699
+ return (minute === null || minute === nulls.int32) ?
1701
1700
  null
1702
1701
  :
1703
- exports.timezone_offset + 60 * 1000 * minute;
1702
+ timezone_offset + 60 * 1000 * minute;
1704
1703
  }
1705
- exports.minute2ms = minute2ms;
1706
- function minute2str(minute, format = 'HH:mm[m]') {
1707
- return (minute === null || minute === exports.nulls.int32) ?
1704
+ export function minute2str(minute, format = 'HH:mm[m]') {
1705
+ return (minute === null || minute === nulls.int32) ?
1708
1706
  'null'
1709
1707
  :
1710
- (0, dayjs_1.default)(minute2ms(minute)).format(format);
1708
+ dayjs(minute2ms(minute)).format(format);
1711
1709
  }
1712
- exports.minute2str = minute2str;
1713
- function second2ms(second) {
1714
- return (second === null || second === exports.nulls.int32) ?
1710
+ export function second2ms(second) {
1711
+ return (second === null || second === nulls.int32) ?
1715
1712
  null
1716
1713
  :
1717
- exports.timezone_offset + 1000 * second;
1714
+ timezone_offset + 1000 * second;
1718
1715
  }
1719
- exports.second2ms = second2ms;
1720
- function second2str(second, format = 'HH:mm:ss') {
1721
- return (second === null || second === exports.nulls.int32) ?
1716
+ export function second2str(second, format = 'HH:mm:ss') {
1717
+ return (second === null || second === nulls.int32) ?
1722
1718
  'null'
1723
1719
  :
1724
- (0, dayjs_1.default)(second2ms(second)).format(format);
1720
+ dayjs(second2ms(second)).format(format);
1725
1721
  }
1726
- exports.second2str = second2str;
1727
- function datetime2ms(datetime) {
1728
- return (datetime === null || datetime === exports.nulls.int32) ?
1722
+ export function datetime2ms(datetime) {
1723
+ return (datetime === null || datetime === nulls.int32) ?
1729
1724
  null
1730
1725
  :
1731
- exports.timezone_offset + 1000 * datetime;
1726
+ timezone_offset + 1000 * datetime;
1732
1727
  }
1733
- exports.datetime2ms = datetime2ms;
1734
- function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
1735
- return (datetime === null || datetime === exports.nulls.int32) ?
1728
+ export function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
1729
+ return (datetime === null || datetime === nulls.int32) ?
1736
1730
  'null'
1737
1731
  :
1738
- (0, dayjs_1.default)(datetime2ms(datetime)).format(format);
1732
+ dayjs(datetime2ms(datetime)).format(format);
1739
1733
  }
1740
- exports.datetime2str = datetime2str;
1741
- function timestamp2ms(timestamp) {
1742
- return (timestamp === null || timestamp === exports.nulls.int64) ?
1734
+ export function timestamp2ms(timestamp) {
1735
+ return (timestamp === null || timestamp === nulls.int64) ?
1743
1736
  null
1744
1737
  :
1745
- exports.timezone_offset + Number(timestamp);
1738
+ timezone_offset + Number(timestamp);
1746
1739
  }
1747
- exports.timestamp2ms = timestamp2ms;
1748
1740
  /** format timestamp (bigint) to string
1749
1741
  - timestamp: bigint value
1750
1742
  - format?:
1751
1743
  format string, default to `YYYY.MM.DD HH:mm:ss.SSS`
1752
1744
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1753
1745
  */
1754
- function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1755
- return (timestamp === null || timestamp === exports.nulls.int64) ?
1746
+ export function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1747
+ return (timestamp === null || timestamp === nulls.int64) ?
1756
1748
  'null'
1757
1749
  :
1758
- (0, dayjs_1.default)(timestamp2ms(timestamp)).format(format);
1750
+ dayjs(timestamp2ms(timestamp)).format(format);
1759
1751
  }
1760
- exports.timestamp2str = timestamp2str;
1761
- function datehour2ms(datehour) {
1762
- return (datehour === null || datehour === exports.nulls.int32) ?
1752
+ export function datehour2ms(datehour) {
1753
+ return (datehour === null || datehour === nulls.int32) ?
1763
1754
  null
1764
1755
  :
1765
- exports.timezone_offset + 1000 * 3600 * datehour;
1756
+ timezone_offset + 1000 * 3600 * datehour;
1766
1757
  }
1767
- exports.datehour2ms = datehour2ms;
1768
- function datehour2str(datehour, format = 'YYYY.MM.DDTHH') {
1769
- return (datehour === null || datehour === exports.nulls.int32) ?
1758
+ export function datehour2str(datehour, format = 'YYYY.MM.DDTHH') {
1759
+ return (datehour === null || datehour === nulls.int32) ?
1770
1760
  'null'
1771
1761
  :
1772
- (0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * datehour).format(format);
1762
+ dayjs(timezone_offset + 1000 * 3600 * datehour).format(format);
1773
1763
  }
1774
- exports.datehour2str = datehour2str;
1775
1764
  /** parse timestamp string to bigint value
1776
1765
  - str: timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
1777
1766
  - format?:
1778
1767
  The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
1779
1768
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1780
1769
  */
1781
- function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1770
+ export function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1782
1771
  if (!str || str === 'null')
1783
- return exports.nulls.int64;
1772
+ return nulls.int64;
1784
1773
  if (str.length !== format.length)
1785
1774
  throw new Error('The length of the timestamp string is not equal to the length of the format string');
1786
- return BigInt(-exports.timezone_offset +
1787
- (0, dayjs_1.default)(str, format).valueOf());
1775
+ return BigInt(-timezone_offset +
1776
+ dayjs(str, format).valueOf());
1788
1777
  }
1789
- exports.str2timestamp = str2timestamp;
1790
- function nanotime2ns(nanotime) {
1778
+ export function nanotime2ns(nanotime) {
1791
1779
  return nanotimestamp2ns(nanotime);
1792
1780
  }
1793
- exports.nanotime2ns = nanotime2ns;
1794
- function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
1795
- if (nanotime === null || nanotime === exports.nulls.int64)
1781
+ export function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
1782
+ if (nanotime === null || nanotime === nulls.int64)
1796
1783
  return 'null';
1797
1784
  if (nanotime < 0n)
1798
1785
  return String(nanotime);
@@ -1803,18 +1790,16 @@ function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
1803
1790
  const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
1804
1791
  if (i_nanosecond_start === -1)
1805
1792
  throw new Error('The format string must contain the format for nanoseconds (SSSSSSSSS)');
1806
- return ((0, dayjs_1.default)(exports.timezone_offset + (Number(nanotime) / 1000000)).format(format.slice(0, i_second_end)) +
1793
+ return (dayjs(timezone_offset + (Number(nanotime) / 1000000)).format(format.slice(0, i_second_end)) +
1807
1794
  format.slice(i_second_end, i_nanosecond_start) +
1808
1795
  String(nanotime % 1000000000n).padStart(9, '0'));
1809
1796
  }
1810
- exports.nanotime2str = nanotime2str;
1811
- function nanotimestamp2ns(nanotimestamp) {
1812
- return (nanotimestamp === null || nanotimestamp === exports.nulls.int64) ?
1797
+ export function nanotimestamp2ns(nanotimestamp) {
1798
+ return (nanotimestamp === null || nanotimestamp === nulls.int64) ?
1813
1799
  null
1814
1800
  :
1815
- BigInt(exports.timezone_offset) * 1000000n + nanotimestamp;
1801
+ BigInt(timezone_offset) * 1000000n + nanotimestamp;
1816
1802
  }
1817
- exports.nanotimestamp2ns = nanotimestamp2ns;
1818
1803
  /** format nanotimestamp value (bigint) to string
1819
1804
  - nanotimestamp: bigint value
1820
1805
  - format?:
@@ -1822,14 +1807,14 @@ exports.nanotimestamp2ns = nanotimestamp2ns;
1822
1807
  Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
1823
1808
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1824
1809
  */
1825
- function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1810
+ export function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1826
1811
  // tests:
1827
1812
  // nanotimestamp2str(0n)
1828
1813
  // nanotimestamp2str(-1n)
1829
1814
  // nanotimestamp2str(-9_9999_9999n)
1830
1815
  // nanotimestamp2str(-10_0000_0000n)
1831
1816
  // nanotimestamp2str(-10_0000_0001n)
1832
- if (nanotimestamp === null || nanotimestamp === exports.nulls.int64)
1817
+ if (nanotimestamp === null || nanotimestamp === nulls.int64)
1833
1818
  return 'null';
1834
1819
  const i_second_start = format.indexOf('ss');
1835
1820
  if (i_second_start === -1)
@@ -1840,7 +1825,7 @@ function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSS
1840
1825
  throw new Error('The format string must contain the format for nanoseconds (SSSSSSSSS)');
1841
1826
  const remainder = nanotimestamp % 1000000000n;
1842
1827
  const borrow = remainder < 0n;
1843
- return ((0, dayjs_1.default)(exports.timezone_offset +
1828
+ return (dayjs(timezone_offset +
1844
1829
  // 去掉 9 位的纳秒部分,转化为毫秒
1845
1830
  Number((nanotimestamp - remainder + (borrow ? -1000000000n : 0n)) / 1000000n)).format(format.slice(0, i_second_end)) +
1846
1831
  format.slice(i_second_end, i_nanosecond_start) +
@@ -1849,7 +1834,6 @@ function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSS
1849
1834
  :
1850
1835
  remainder).padStart(9, '0'));
1851
1836
  }
1852
- exports.nanotimestamp2str = nanotimestamp2str;
1853
1837
  /** parse nano timestamp string to bigint value
1854
1838
  - str: nano timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
1855
1839
  - format?:
@@ -1857,9 +1841,9 @@ exports.nanotimestamp2str = nanotimestamp2str;
1857
1841
  Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
1858
1842
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1859
1843
  */
1860
- function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1844
+ export function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1861
1845
  if (!str || str === 'null')
1862
- return exports.nulls.int64;
1846
+ return nulls.int64;
1863
1847
  if (str.length !== format.length)
1864
1848
  throw new Error('nanotimestamp string length is not equal to format string length');
1865
1849
  const i_second_start = format.indexOf('ss');
@@ -1869,13 +1853,12 @@ function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1869
1853
  const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
1870
1854
  if (i_nanosecond_start === -1)
1871
1855
  throw new Error('Format string must contain nanosecond format (SSSSSSSSS)');
1872
- return (BigInt(-exports.timezone_offset +
1873
- (0, dayjs_1.default)(str.slice(0, i_second_end), format.slice(0, i_second_end)).valueOf()) * 1000000n
1856
+ return (BigInt(-timezone_offset +
1857
+ dayjs(str.slice(0, i_second_end), format.slice(0, i_second_end)).valueOf()) * 1000000n
1874
1858
  +
1875
1859
  BigInt(str.slice(i_nanosecond_start, i_nanosecond_start + 9)));
1876
1860
  }
1877
- exports.str2nanotimestamp = str2nanotimestamp;
1878
- function ipaddr2str(buffer, le = true, ipv6) {
1861
+ export function ipaddr2str(buffer, le = true, ipv6) {
1879
1862
  let buf = buffer;
1880
1863
  if (le)
1881
1864
  buf = buffer.slice().reverse();
@@ -1886,21 +1869,51 @@ function ipaddr2str(buffer, le = true, ipv6) {
1886
1869
  else // ipv4
1887
1870
  return buf.subarray(12).join('.');
1888
1871
  }
1889
- exports.ipaddr2str = ipaddr2str;
1890
- function uuid2str(buffer, le = true) {
1872
+ export function uuid2str(buffer, le = true) {
1891
1873
  const str = int1282str(buffer, le);
1892
1874
  return `${str.slice(0, 8)}-${str.slice(8, 12)}-${str.slice(12, 16)}-${str.slice(16, 20)}-${str.slice(20)}`;
1893
1875
  }
1894
- exports.uuid2str = uuid2str;
1895
- function int1282str(buffer, le = true) {
1876
+ export function int1282str(buffer, le = true) {
1896
1877
  let buf = buffer;
1897
1878
  if (le)
1898
1879
  buf = buffer.slice().reverse();
1899
1880
  return [...buf].map(x => x.toString(16)
1900
1881
  .padStart(2, '0')).join('');
1901
1882
  }
1902
- exports.int1282str = int1282str;
1903
- class DDB {
1883
+ export class DDB {
1884
+ /** 当前的 session id (http 或 tcp) */
1885
+ sid = '0';
1886
+ /** utf-8 text decoder */
1887
+ dec = new TextDecoder('utf-8');
1888
+ enc = new TextEncoder();
1889
+ /** DolphinDB WebSocket URL
1890
+ e.g. `ws://127.0.0.1:8848/`, `wss://dolphindb.com`
1891
+ */
1892
+ url;
1893
+ websocket = null;
1894
+ /** little endian (server) */
1895
+ le = true;
1896
+ /** little endian (client) */
1897
+ static le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
1898
+ /** 是否在建立连接后自动登录,默认 true */
1899
+ autologin = true;
1900
+ /** DolphinDB 登录用户名 */
1901
+ username = 'admin';
1902
+ /** DolphinDB 登录密码 */
1903
+ password = '123456';
1904
+ /** python session flag (2048) */
1905
+ python = false;
1906
+ print_message_buffer = false;
1907
+ print_object_buffer = false;
1908
+ print_message = true;
1909
+ parse_object = true;
1910
+ /** DdbMessage listeners */
1911
+ listeners = [];
1912
+ pconnect = Promise.resolve();
1913
+ presult = Promise.resolve(null);
1914
+ get connected() {
1915
+ return this.websocket?.readyState === WebSocket.OPEN;
1916
+ }
1904
1917
  /**
1905
1918
  Initialize an instance of DolphinDB Client using the WebSocket URL
1906
1919
  (without establishing an actual network connection)
@@ -1923,30 +1936,6 @@ class DDB {
1923
1936
  })
1924
1937
  */
1925
1938
  constructor(url, options = {}) {
1926
- /** 当前的 session id (http 或 tcp) */
1927
- this.sid = '0';
1928
- /** utf-8 text decoder */
1929
- this.dec = new TextDecoder('utf-8');
1930
- this.enc = new TextEncoder();
1931
- this.websocket = null;
1932
- /** little endian (server) */
1933
- this.le = true;
1934
- /** 是否在建立连接后自动登录,默认 true */
1935
- this.autologin = true;
1936
- /** DolphinDB 登录用户名 */
1937
- this.username = 'admin';
1938
- /** DolphinDB 登录密码 */
1939
- this.password = '123456';
1940
- /** python session flag (2048) */
1941
- this.python = false;
1942
- this.print_message_buffer = false;
1943
- this.print_object_buffer = false;
1944
- this.print_message = true;
1945
- this.parse_object = true;
1946
- /** DdbMessage listeners */
1947
- this.listeners = [];
1948
- this.pconnect = Promise.resolve();
1949
- this.presult = Promise.resolve(null);
1950
1939
  this.url = url;
1951
1940
  if (options.autologin !== undefined)
1952
1941
  this.autologin = options.autologin;
@@ -1957,9 +1946,6 @@ class DDB {
1957
1946
  if (options.python !== undefined)
1958
1947
  this.python = options.python;
1959
1948
  }
1960
- get connected() {
1961
- return this.websocket?.readyState === ws_1.WebSocket.OPEN;
1962
- }
1963
1949
  on_message(event) { }
1964
1950
  /** Establish the actual WebSocket connection to the DolphinDB corresponding to the URL
1965
1951
  - options?:
@@ -1981,7 +1967,7 @@ class DDB {
1981
1967
  if (options.python !== undefined)
1982
1968
  this.python = options.python;
1983
1969
  this.disconnect();
1984
- await (0, net_js_1.connect_websocket)(this.url, {
1970
+ await connect_websocket(this.url, {
1985
1971
  protocols: this.python ? ['python'] : [],
1986
1972
  on_open: async (event, websocket) => {
1987
1973
  this.websocket = websocket;
@@ -2120,7 +2106,7 @@ class DDB {
2120
2106
  try {
2121
2107
  const buf = new Uint8Array(buffer);
2122
2108
  if (this.print_message_buffer)
2123
- console.log((0, utils_js_1.typed_array_to_buffer)(buf));
2109
+ console.log(typed_array_to_buffer(buf));
2124
2110
  const message = this.parse_message(buf, parse_object);
2125
2111
  listener?.(message, this);
2126
2112
  for (const listener of _handlers)
@@ -2163,7 +2149,7 @@ class DDB {
2163
2149
  return 'connect\n';
2164
2150
  }
2165
2151
  })());
2166
- this.websocket.send((0, utils_js_1.concat)([
2152
+ this.websocket.send(concat([
2167
2153
  this.enc.encode(`API2 ${this.sid} ${command.length} / ${this.get_rpc_options({ urgent })}\n`),
2168
2154
  command,
2169
2155
  ...args.map((arg) => arg.pack())
@@ -2277,7 +2263,7 @@ class DDB {
2277
2263
  };
2278
2264
  const buf_obj = buf.subarray(i_lf_1 + 1);
2279
2265
  if (this.print_object_buffer)
2280
- console.log((0, utils_js_1.typed_array_to_buffer)(buf_obj));
2266
+ console.log(typed_array_to_buffer(buf_obj));
2281
2267
  return {
2282
2268
  type: 'object',
2283
2269
  data: parse_object ?
@@ -2293,7 +2279,4 @@ class DDB {
2293
2279
  };
2294
2280
  }
2295
2281
  }
2296
- exports.DDB = DDB;
2297
- /** little endian (client) */
2298
- DDB.le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
2299
2282
  //# sourceMappingURL=index.js.map