dolphindb 2.0.525 → 2.0.528

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,7 +988,7 @@ class DdbObj {
952
988
  throw new Error(`vector ${DdbType[type]} 暂不支持序列化`);
953
989
  }
954
990
  }
955
- [utils_js_1.inspect.custom](depth, options, _inspect) {
991
+ [inspect.custom](depth, options, _inspect) {
956
992
  const type = (() => {
957
993
  const tname = DdbType[this.type];
958
994
  switch (this.form) {
@@ -1029,7 +1065,7 @@ class DdbObj {
1029
1065
  const { base, data } = this.value;
1030
1066
  let items = new Array(Math.min(limit, data.length));
1031
1067
  for (let i = 0; i < items.length; i++)
1032
- items[i] = (0, utils_js_1.inspect)(base[data[i]], options);
1068
+ items[i] = inspect(base[data[i]], options);
1033
1069
  return format_array(items, data.length > limit);
1034
1070
  }
1035
1071
  case DdbType.uuid:
@@ -1064,10 +1100,10 @@ class DdbObj {
1064
1100
  }
1065
1101
  }
1066
1102
  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);
1103
+ return inspect(typed_array_to_buffer(this.value), options);
1104
+ return inspect(this.value, options);
1069
1105
  })();
1070
- return `${options.colors ? type.blue : type}(${this.name ? `${(0, utils_js_1.inspect)(this.name, options)}, ` : ''}${data})`;
1106
+ return `${options.colors ? type.blue : type}(${this.name ? `${inspect(this.name, options)}, ` : ''}${data})`;
1071
1107
  }
1072
1108
  /** 自动转换 js string, boolean 为 DdbObj */
1073
1109
  static to_ddbobj(value) {
@@ -1098,7 +1134,7 @@ class DdbObj {
1098
1134
  switch (type) {
1099
1135
  case DdbType.bool: {
1100
1136
  const value = values[i];
1101
- row[name] = value === exports.nulls.int8 ?
1137
+ row[name] = value === nulls.int8 ?
1102
1138
  null
1103
1139
  :
1104
1140
  Boolean(value);
@@ -1139,24 +1175,15 @@ class DdbObj {
1139
1175
  return obj;
1140
1176
  }
1141
1177
  }
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) {
1178
+ export function format(type, value, le, options) {
1152
1179
  switch (type) {
1153
1180
  case DdbType.bool:
1154
- return (0, utils_js_1.inspect)((value === null || value === exports.nulls.int8) ?
1181
+ return inspect((value === null || value === nulls.int8) ?
1155
1182
  null
1156
1183
  :
1157
1184
  Boolean(value), options);
1158
1185
  case DdbType.char:
1159
- return (0, utils_js_1.inspect)((value === null || value === exports.nulls.int8) ?
1186
+ return inspect((value === null || value === nulls.int8) ?
1160
1187
  null
1161
1188
  :
1162
1189
  // ascii printable
@@ -1166,17 +1193,17 @@ function format(type, value, le, options) {
1166
1193
  :
1167
1194
  value, options);
1168
1195
  case DdbType.short:
1169
- return (0, utils_js_1.inspect)((value === null || value === exports.nulls.int16) ?
1196
+ return inspect((value === null || value === nulls.int16) ?
1170
1197
  null
1171
1198
  :
1172
1199
  value, options);
1173
1200
  case DdbType.int:
1174
- return (0, utils_js_1.inspect)((value === null || value === exports.nulls.int32) ?
1201
+ return inspect((value === null || value === nulls.int32) ?
1175
1202
  null
1176
1203
  :
1177
1204
  value, options);
1178
1205
  case DdbType.long:
1179
- return (value === null || value === exports.nulls.int64) ?
1206
+ return (value === null || value === nulls.int64) ?
1180
1207
  'null'
1181
1208
  :
1182
1209
  options.colors ?
@@ -1184,7 +1211,7 @@ function format(type, value, le, options) {
1184
1211
  :
1185
1212
  String(value);
1186
1213
  case DdbType.date:
1187
- return (value === null || value === exports.nulls.int32) ?
1214
+ return (value === null || value === nulls.int32) ?
1188
1215
  'null'
1189
1216
  :
1190
1217
  options.colors ?
@@ -1192,7 +1219,7 @@ function format(type, value, le, options) {
1192
1219
  :
1193
1220
  date2str(value);
1194
1221
  case DdbType.month:
1195
- return (value === null || value === exports.nulls.int32) ?
1222
+ return (value === null || value === nulls.int32) ?
1196
1223
  'null'
1197
1224
  :
1198
1225
  options.colors ?
@@ -1200,7 +1227,7 @@ function format(type, value, le, options) {
1200
1227
  :
1201
1228
  month2str(value);
1202
1229
  case DdbType.time:
1203
- return (value === null || value === exports.nulls.int32) ?
1230
+ return (value === null || value === nulls.int32) ?
1204
1231
  'null'
1205
1232
  :
1206
1233
  options.colors ?
@@ -1208,7 +1235,7 @@ function format(type, value, le, options) {
1208
1235
  :
1209
1236
  time2str(value);
1210
1237
  case DdbType.minute:
1211
- return (value === null || value === exports.nulls.int32) ?
1238
+ return (value === null || value === nulls.int32) ?
1212
1239
  'null'
1213
1240
  :
1214
1241
  options.colors ?
@@ -1216,7 +1243,7 @@ function format(type, value, le, options) {
1216
1243
  :
1217
1244
  minute2str(value);
1218
1245
  case DdbType.second:
1219
- return (value === null || value === exports.nulls.int32) ?
1246
+ return (value === null || value === nulls.int32) ?
1220
1247
  'null'
1221
1248
  :
1222
1249
  options.colors ?
@@ -1224,7 +1251,7 @@ function format(type, value, le, options) {
1224
1251
  :
1225
1252
  second2str(value);
1226
1253
  case DdbType.datetime:
1227
- return (value === null || value === exports.nulls.int32) ?
1254
+ return (value === null || value === nulls.int32) ?
1228
1255
  'null'
1229
1256
  :
1230
1257
  options.colors ?
@@ -1232,7 +1259,7 @@ function format(type, value, le, options) {
1232
1259
  :
1233
1260
  datetime2str(value);
1234
1261
  case DdbType.timestamp:
1235
- return (value === null || value === exports.nulls.int64) ?
1262
+ return (value === null || value === nulls.int64) ?
1236
1263
  'null'
1237
1264
  :
1238
1265
  options.colors ?
@@ -1240,7 +1267,7 @@ function format(type, value, le, options) {
1240
1267
  :
1241
1268
  timestamp2str(value);
1242
1269
  case DdbType.nanotime:
1243
- return (value === null || value === exports.nulls.int64) ?
1270
+ return (value === null || value === nulls.int64) ?
1244
1271
  'null'
1245
1272
  :
1246
1273
  options.colors ?
@@ -1248,7 +1275,7 @@ function format(type, value, le, options) {
1248
1275
  :
1249
1276
  nanotime2str(value);
1250
1277
  case DdbType.nanotimestamp:
1251
- return (value === null || value === exports.nulls.int64) ?
1278
+ return (value === null || value === nulls.int64) ?
1252
1279
  'null'
1253
1280
  :
1254
1281
  options.colors ?
@@ -1256,30 +1283,30 @@ function format(type, value, le, options) {
1256
1283
  :
1257
1284
  nanotimestamp2str(value);
1258
1285
  case DdbType.float:
1259
- return (value === null || value === exports.nulls.float32) ?
1286
+ return (value === null || value === nulls.float32) ?
1260
1287
  'null'
1261
1288
  :
1262
- (0, utils_js_1.inspect)(value, options);
1289
+ inspect(value, options);
1263
1290
  case DdbType.double:
1264
- return (value === null || value === exports.nulls.double) ?
1291
+ return (value === null || value === nulls.double) ?
1265
1292
  'null'
1266
1293
  :
1267
- (0, utils_js_1.inspect)(value, options);
1294
+ inspect(value, options);
1268
1295
  case DdbType.symbol:
1269
1296
  case DdbType.string:
1270
- return (0, utils_js_1.inspect)(value, options);
1297
+ return inspect(value, options);
1271
1298
  case DdbType.uuid:
1272
1299
  return options.colors ?
1273
1300
  uuid2str(value, le).green
1274
1301
  :
1275
1302
  uuid2str(value, le);
1276
1303
  case DdbType.functiondef:
1277
- return (0, utils_js_1.inspect)(value.name, options);
1304
+ return inspect(value.name, options);
1278
1305
  case DdbType.handle:
1279
1306
  case DdbType.code:
1280
- return (0, utils_js_1.inspect)(value, options);
1307
+ return inspect(value, options);
1281
1308
  case DdbType.datehour:
1282
- return (value === null || value === exports.nulls.int32) ?
1309
+ return (value === null || value === nulls.int32) ?
1283
1310
  'null'
1284
1311
  :
1285
1312
  options.colors ?
@@ -1297,15 +1324,15 @@ function format(type, value, le, options) {
1297
1324
  :
1298
1325
  int1282str(value, le);
1299
1326
  case DdbType.blob:
1300
- return (0, utils_js_1.inspect)(value.length > 100 ?
1327
+ return inspect(value.length > 100 ?
1301
1328
  DdbObj.dec.decode(value.subarray(0, 98)) + '…'
1302
1329
  :
1303
1330
  DdbObj.dec.decode(value), options);
1304
1331
  case DdbType.point: {
1305
1332
  let [x, y] = value;
1306
- if (x === exports.nulls.double)
1333
+ if (x === nulls.double)
1307
1334
  x = null;
1308
- if (y === exports.nulls.double)
1335
+ if (y === nulls.double)
1309
1336
  y = null;
1310
1337
  return options.colors ?
1311
1338
  `(${String(x).green}, ${String(y).green})`
@@ -1314,9 +1341,9 @@ function format(type, value, le, options) {
1314
1341
  }
1315
1342
  case DdbType.complex: {
1316
1343
  let [x, y] = value;
1317
- if (x === exports.nulls.double)
1344
+ if (x === nulls.double)
1318
1345
  x = null;
1319
- if (y === exports.nulls.double)
1346
+ if (y === nulls.double)
1320
1347
  y = null;
1321
1348
  return options.colors ?
1322
1349
  `${String(x).green}+${`${String(y)}i`.green}`
@@ -1329,11 +1356,10 @@ function format(type, value, le, options) {
1329
1356
  return options.colors ? str.green : str;
1330
1357
  }
1331
1358
  default:
1332
- return (0, utils_js_1.inspect)(value, options);
1359
+ return inspect(value, options);
1333
1360
  }
1334
1361
  }
1335
- exports.format = format;
1336
- class DdbVoid extends DdbObj {
1362
+ export class DdbVoid extends DdbObj {
1337
1363
  constructor() {
1338
1364
  super({
1339
1365
  form: DdbForm.scalar,
@@ -1342,8 +1368,7 @@ class DdbVoid extends DdbObj {
1342
1368
  });
1343
1369
  }
1344
1370
  }
1345
- exports.DdbVoid = DdbVoid;
1346
- class DdbBool extends DdbObj {
1371
+ export class DdbBool extends DdbObj {
1347
1372
  constructor(value) {
1348
1373
  super({
1349
1374
  form: DdbForm.scalar,
@@ -1352,8 +1377,7 @@ class DdbBool extends DdbObj {
1352
1377
  });
1353
1378
  }
1354
1379
  }
1355
- exports.DdbBool = DdbBool;
1356
- class DdbChar extends DdbObj {
1380
+ export class DdbChar extends DdbObj {
1357
1381
  constructor(value) {
1358
1382
  super({
1359
1383
  form: DdbForm.scalar,
@@ -1365,8 +1389,7 @@ class DdbChar extends DdbObj {
1365
1389
  });
1366
1390
  }
1367
1391
  }
1368
- exports.DdbChar = DdbChar;
1369
- class DdbInt extends DdbObj {
1392
+ export class DdbInt extends DdbObj {
1370
1393
  constructor(value) {
1371
1394
  super({
1372
1395
  form: DdbForm.scalar,
@@ -1375,8 +1398,7 @@ class DdbInt extends DdbObj {
1375
1398
  });
1376
1399
  }
1377
1400
  }
1378
- exports.DdbInt = DdbInt;
1379
- class DdbString extends DdbObj {
1401
+ export class DdbString extends DdbObj {
1380
1402
  constructor(value) {
1381
1403
  super({
1382
1404
  form: DdbForm.scalar,
@@ -1385,8 +1407,7 @@ class DdbString extends DdbObj {
1385
1407
  });
1386
1408
  }
1387
1409
  }
1388
- exports.DdbString = DdbString;
1389
- class DdbLong extends DdbObj {
1410
+ export class DdbLong extends DdbObj {
1390
1411
  constructor(value) {
1391
1412
  super({
1392
1413
  form: DdbForm.scalar,
@@ -1395,8 +1416,7 @@ class DdbLong extends DdbObj {
1395
1416
  });
1396
1417
  }
1397
1418
  }
1398
- exports.DdbLong = DdbLong;
1399
- class DdbDouble extends DdbObj {
1419
+ export class DdbDouble extends DdbObj {
1400
1420
  constructor(value) {
1401
1421
  super({
1402
1422
  form: DdbForm.scalar,
@@ -1405,8 +1425,7 @@ class DdbDouble extends DdbObj {
1405
1425
  });
1406
1426
  }
1407
1427
  }
1408
- exports.DdbDouble = DdbDouble;
1409
- class DdbDateTime extends DdbObj {
1428
+ export class DdbDateTime extends DdbObj {
1410
1429
  constructor(value) {
1411
1430
  super({
1412
1431
  form: DdbForm.scalar,
@@ -1415,8 +1434,7 @@ class DdbDateTime extends DdbObj {
1415
1434
  });
1416
1435
  }
1417
1436
  }
1418
- exports.DdbDateTime = DdbDateTime;
1419
- class DdbTimeStamp extends DdbObj {
1437
+ export class DdbTimeStamp extends DdbObj {
1420
1438
  constructor(value) {
1421
1439
  super({
1422
1440
  form: DdbForm.scalar,
@@ -1425,8 +1443,7 @@ class DdbTimeStamp extends DdbObj {
1425
1443
  });
1426
1444
  }
1427
1445
  }
1428
- exports.DdbTimeStamp = DdbTimeStamp;
1429
- class DdbNanoTimeStamp extends DdbObj {
1446
+ export class DdbNanoTimeStamp extends DdbObj {
1430
1447
  constructor(value) {
1431
1448
  super({
1432
1449
  form: DdbForm.scalar,
@@ -1435,20 +1452,18 @@ class DdbNanoTimeStamp extends DdbObj {
1435
1452
  });
1436
1453
  }
1437
1454
  }
1438
- exports.DdbNanoTimeStamp = DdbNanoTimeStamp;
1439
- class DdbPair extends DdbObj {
1455
+ export class DdbPair extends DdbObj {
1440
1456
  constructor(l, r = null) {
1441
1457
  super({
1442
1458
  form: DdbForm.pair,
1443
1459
  type: DdbType.int,
1444
1460
  rows: 2,
1445
1461
  cols: 1,
1446
- value: Int32Array.of(l === null ? exports.nulls.int32 : l, r === null ? exports.nulls.int32 : r)
1462
+ value: Int32Array.of(l === null ? nulls.int32 : l, r === null ? nulls.int32 : r)
1447
1463
  });
1448
1464
  }
1449
1465
  }
1450
- exports.DdbPair = DdbPair;
1451
- class DdbFunction extends DdbObj {
1466
+ export class DdbFunction extends DdbObj {
1452
1467
  constructor(name, type) {
1453
1468
  super({
1454
1469
  form: DdbForm.scalar,
@@ -1457,8 +1472,7 @@ class DdbFunction extends DdbObj {
1457
1472
  });
1458
1473
  }
1459
1474
  }
1460
- exports.DdbFunction = DdbFunction;
1461
- class DdbVectorInt extends DdbObj {
1475
+ export class DdbVectorInt extends DdbObj {
1462
1476
  constructor(ints, name) {
1463
1477
  super({
1464
1478
  form: DdbForm.vector,
@@ -1469,15 +1483,14 @@ class DdbVectorInt extends DdbObj {
1469
1483
  ints
1470
1484
  :
1471
1485
  Int32Array.from(ints, v => v === null ?
1472
- exports.nulls.int32
1486
+ nulls.int32
1473
1487
  :
1474
1488
  v),
1475
1489
  name,
1476
1490
  });
1477
1491
  }
1478
1492
  }
1479
- exports.DdbVectorInt = DdbVectorInt;
1480
- class DdbVectorDouble extends DdbObj {
1493
+ export class DdbVectorDouble extends DdbObj {
1481
1494
  constructor(doubles, name) {
1482
1495
  super({
1483
1496
  form: DdbForm.vector,
@@ -1488,15 +1501,14 @@ class DdbVectorDouble extends DdbObj {
1488
1501
  doubles
1489
1502
  :
1490
1503
  Float64Array.from(doubles, v => v === null ?
1491
- exports.nulls.double
1504
+ nulls.double
1492
1505
  :
1493
1506
  v),
1494
1507
  name,
1495
1508
  });
1496
1509
  }
1497
1510
  }
1498
- exports.DdbVectorDouble = DdbVectorDouble;
1499
- class DdbVectorString extends DdbObj {
1511
+ export class DdbVectorString extends DdbObj {
1500
1512
  constructor(strings, name) {
1501
1513
  super({
1502
1514
  form: DdbForm.vector,
@@ -1508,8 +1520,7 @@ class DdbVectorString extends DdbObj {
1508
1520
  });
1509
1521
  }
1510
1522
  }
1511
- exports.DdbVectorString = DdbVectorString;
1512
- class DdbVectorAny extends DdbObj {
1523
+ export class DdbVectorAny extends DdbObj {
1513
1524
  constructor(objs, name) {
1514
1525
  super({
1515
1526
  form: DdbForm.vector,
@@ -1521,8 +1532,7 @@ class DdbVectorAny extends DdbObj {
1521
1532
  });
1522
1533
  }
1523
1534
  }
1524
- exports.DdbVectorAny = DdbVectorAny;
1525
- class DdbVectorSymbol extends DdbObj {
1535
+ export class DdbVectorSymbol extends DdbObj {
1526
1536
  constructor(strings, name) {
1527
1537
  let map = new Map([
1528
1538
  ['', 0]
@@ -1551,8 +1561,7 @@ class DdbVectorSymbol extends DdbObj {
1551
1561
  });
1552
1562
  }
1553
1563
  }
1554
- exports.DdbVectorSymbol = DdbVectorSymbol;
1555
- class DdbSetInt extends DdbObj {
1564
+ export class DdbSetInt extends DdbObj {
1556
1565
  constructor(ints) {
1557
1566
  super({
1558
1567
  form: DdbForm.set,
@@ -1566,14 +1575,13 @@ class DdbSetInt extends DdbObj {
1566
1575
  ints
1567
1576
  :
1568
1577
  Int32Array.from(ints, v => v === null ?
1569
- exports.nulls.int32
1578
+ nulls.int32
1570
1579
  :
1571
1580
  v),
1572
1581
  });
1573
1582
  }
1574
1583
  }
1575
- exports.DdbSetInt = DdbSetInt;
1576
- class DdbSetDouble extends DdbObj {
1584
+ export class DdbSetDouble extends DdbObj {
1577
1585
  constructor(doubles) {
1578
1586
  super({
1579
1587
  form: DdbForm.set,
@@ -1587,14 +1595,13 @@ class DdbSetDouble extends DdbObj {
1587
1595
  doubles
1588
1596
  :
1589
1597
  Int32Array.from(doubles, v => v === null ?
1590
- exports.nulls.int32
1598
+ nulls.int32
1591
1599
  :
1592
1600
  v),
1593
1601
  });
1594
1602
  }
1595
1603
  }
1596
- exports.DdbSetDouble = DdbSetDouble;
1597
- class DdbSetString extends DdbObj {
1604
+ export class DdbSetString extends DdbObj {
1598
1605
  constructor(strings) {
1599
1606
  if (strings instanceof Set)
1600
1607
  strings = [...strings];
@@ -1607,12 +1614,11 @@ class DdbSetString extends DdbObj {
1607
1614
  });
1608
1615
  }
1609
1616
  }
1610
- exports.DdbSetString = DdbSetString;
1611
1617
  /** Constructs a DdbDict object, which supports two usages:
1612
1618
  - 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
1619
  - Pass in js object (type is Record<string, boolean | string | DdbObj>), automatically converted to DdbDict of dict<string, any>
1614
1620
  */
1615
- class DdbDict extends DdbObj {
1621
+ export class DdbDict extends DdbObj {
1616
1622
  constructor(arg0, arg1) {
1617
1623
  if (arg1)
1618
1624
  super({
@@ -1637,8 +1643,7 @@ class DdbDict extends DdbObj {
1637
1643
  }
1638
1644
  }
1639
1645
  }
1640
- exports.DdbDict = DdbDict;
1641
- class DdbTable extends DdbObj {
1646
+ export class DdbTable extends DdbObj {
1642
1647
  constructor(columns, name = '') {
1643
1648
  super({
1644
1649
  form: DdbForm.table,
@@ -1650,30 +1655,26 @@ class DdbTable extends DdbObj {
1650
1655
  });
1651
1656
  }
1652
1657
  }
1653
- exports.DdbTable = DdbTable;
1654
- function date2ms(date) {
1655
- return (date === null || date === exports.nulls.int32) ?
1658
+ export function date2ms(date) {
1659
+ return (date === null || date === nulls.int32) ?
1656
1660
  null
1657
1661
  :
1658
- exports.timezone_offset + 1000 * 3600 * 24 * date;
1662
+ timezone_offset + 1000 * 3600 * 24 * date;
1659
1663
  }
1660
- exports.date2ms = date2ms;
1661
- function date2str(date, format = 'YYYY.MM.DD') {
1662
- return (date === null || date === exports.nulls.int32) ?
1664
+ export function date2str(date, format = 'YYYY.MM.DD') {
1665
+ return (date === null || date === nulls.int32) ?
1663
1666
  null
1664
1667
  :
1665
- (0, dayjs_1.default)(date2ms(date)).format(format);
1668
+ dayjs(date2ms(date)).format(format);
1666
1669
  }
1667
- exports.date2str = date2str;
1668
- function month2ms(month) {
1669
- return (month === null || month === exports.nulls.int32) ?
1670
+ export function month2ms(month) {
1671
+ return (month === null || month === nulls.int32) ?
1670
1672
  null
1671
1673
  :
1672
- (0, dayjs_1.default)(month2str(month), 'YYYY.MM[M]').valueOf();
1674
+ dayjs(month2str(month), 'YYYY.MM[M]').valueOf();
1673
1675
  }
1674
- exports.month2ms = month2ms;
1675
- function month2str(month) {
1676
- if (month === null || month === exports.nulls.int32)
1676
+ export function month2str(month) {
1677
+ if (month === null || month === nulls.int32)
1677
1678
  return 'null';
1678
1679
  if (month < 0)
1679
1680
  return String(month);
@@ -1681,118 +1682,103 @@ function month2str(month) {
1681
1682
  const year = Math.trunc(month / 12);
1682
1683
  return `${String(year).padStart(4, '0')}.${String(_month + 1).padStart(2, '0')}M`;
1683
1684
  }
1684
- exports.month2str = month2str;
1685
- function time2ms(time) {
1686
- return (time === null || time === exports.nulls.int32) ?
1685
+ export function time2ms(time) {
1686
+ return (time === null || time === nulls.int32) ?
1687
1687
  null
1688
1688
  :
1689
- exports.timezone_offset + time;
1689
+ timezone_offset + time;
1690
1690
  }
1691
- exports.time2ms = time2ms;
1692
- function time2str(time, format = 'HH:mm:ss.SSS') {
1693
- return (time === null || time === exports.nulls.int32) ?
1691
+ export function time2str(time, format = 'HH:mm:ss.SSS') {
1692
+ return (time === null || time === nulls.int32) ?
1694
1693
  null
1695
1694
  :
1696
- (0, dayjs_1.default)(time2ms(time)).format(format);
1695
+ dayjs(time2ms(time)).format(format);
1697
1696
  }
1698
- exports.time2str = time2str;
1699
- function minute2ms(minute) {
1700
- return (minute === null || minute === exports.nulls.int32) ?
1697
+ export function minute2ms(minute) {
1698
+ return (minute === null || minute === nulls.int32) ?
1701
1699
  null
1702
1700
  :
1703
- exports.timezone_offset + 60 * 1000 * minute;
1701
+ timezone_offset + 60 * 1000 * minute;
1704
1702
  }
1705
- exports.minute2ms = minute2ms;
1706
- function minute2str(minute, format = 'HH:mm[m]') {
1707
- return (minute === null || minute === exports.nulls.int32) ?
1703
+ export function minute2str(minute, format = 'HH:mm[m]') {
1704
+ return (minute === null || minute === nulls.int32) ?
1708
1705
  'null'
1709
1706
  :
1710
- (0, dayjs_1.default)(minute2ms(minute)).format(format);
1707
+ dayjs(minute2ms(minute)).format(format);
1711
1708
  }
1712
- exports.minute2str = minute2str;
1713
- function second2ms(second) {
1714
- return (second === null || second === exports.nulls.int32) ?
1709
+ export function second2ms(second) {
1710
+ return (second === null || second === nulls.int32) ?
1715
1711
  null
1716
1712
  :
1717
- exports.timezone_offset + 1000 * second;
1713
+ timezone_offset + 1000 * second;
1718
1714
  }
1719
- exports.second2ms = second2ms;
1720
- function second2str(second, format = 'HH:mm:ss') {
1721
- return (second === null || second === exports.nulls.int32) ?
1715
+ export function second2str(second, format = 'HH:mm:ss') {
1716
+ return (second === null || second === nulls.int32) ?
1722
1717
  'null'
1723
1718
  :
1724
- (0, dayjs_1.default)(second2ms(second)).format(format);
1719
+ dayjs(second2ms(second)).format(format);
1725
1720
  }
1726
- exports.second2str = second2str;
1727
- function datetime2ms(datetime) {
1728
- return (datetime === null || datetime === exports.nulls.int32) ?
1721
+ export function datetime2ms(datetime) {
1722
+ return (datetime === null || datetime === nulls.int32) ?
1729
1723
  null
1730
1724
  :
1731
- exports.timezone_offset + 1000 * datetime;
1725
+ timezone_offset + 1000 * datetime;
1732
1726
  }
1733
- exports.datetime2ms = datetime2ms;
1734
- function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
1735
- return (datetime === null || datetime === exports.nulls.int32) ?
1727
+ export function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
1728
+ return (datetime === null || datetime === nulls.int32) ?
1736
1729
  'null'
1737
1730
  :
1738
- (0, dayjs_1.default)(datetime2ms(datetime)).format(format);
1731
+ dayjs(datetime2ms(datetime)).format(format);
1739
1732
  }
1740
- exports.datetime2str = datetime2str;
1741
- function timestamp2ms(timestamp) {
1742
- return (timestamp === null || timestamp === exports.nulls.int64) ?
1733
+ export function timestamp2ms(timestamp) {
1734
+ return (timestamp === null || timestamp === nulls.int64) ?
1743
1735
  null
1744
1736
  :
1745
- exports.timezone_offset + Number(timestamp);
1737
+ timezone_offset + Number(timestamp);
1746
1738
  }
1747
- exports.timestamp2ms = timestamp2ms;
1748
1739
  /** format timestamp (bigint) to string
1749
1740
  - timestamp: bigint value
1750
1741
  - format?:
1751
1742
  format string, default to `YYYY.MM.DD HH:mm:ss.SSS`
1752
1743
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1753
1744
  */
1754
- function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1755
- return (timestamp === null || timestamp === exports.nulls.int64) ?
1745
+ export function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1746
+ return (timestamp === null || timestamp === nulls.int64) ?
1756
1747
  'null'
1757
1748
  :
1758
- (0, dayjs_1.default)(timestamp2ms(timestamp)).format(format);
1749
+ dayjs(timestamp2ms(timestamp)).format(format);
1759
1750
  }
1760
- exports.timestamp2str = timestamp2str;
1761
- function datehour2ms(datehour) {
1762
- return (datehour === null || datehour === exports.nulls.int32) ?
1751
+ export function datehour2ms(datehour) {
1752
+ return (datehour === null || datehour === nulls.int32) ?
1763
1753
  null
1764
1754
  :
1765
- exports.timezone_offset + 1000 * 3600 * datehour;
1755
+ timezone_offset + 1000 * 3600 * datehour;
1766
1756
  }
1767
- exports.datehour2ms = datehour2ms;
1768
- function datehour2str(datehour, format = 'YYYY.MM.DDTHH') {
1769
- return (datehour === null || datehour === exports.nulls.int32) ?
1757
+ export function datehour2str(datehour, format = 'YYYY.MM.DDTHH') {
1758
+ return (datehour === null || datehour === nulls.int32) ?
1770
1759
  'null'
1771
1760
  :
1772
- (0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * datehour).format(format);
1761
+ dayjs(timezone_offset + 1000 * 3600 * datehour).format(format);
1773
1762
  }
1774
- exports.datehour2str = datehour2str;
1775
1763
  /** parse timestamp string to bigint value
1776
1764
  - str: timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
1777
1765
  - format?:
1778
1766
  The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
1779
1767
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1780
1768
  */
1781
- function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1769
+ export function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1782
1770
  if (!str || str === 'null')
1783
- return exports.nulls.int64;
1771
+ return nulls.int64;
1784
1772
  if (str.length !== format.length)
1785
1773
  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());
1774
+ return BigInt(-timezone_offset +
1775
+ dayjs(str, format).valueOf());
1788
1776
  }
1789
- exports.str2timestamp = str2timestamp;
1790
- function nanotime2ns(nanotime) {
1777
+ export function nanotime2ns(nanotime) {
1791
1778
  return nanotimestamp2ns(nanotime);
1792
1779
  }
1793
- exports.nanotime2ns = nanotime2ns;
1794
- function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
1795
- if (nanotime === null || nanotime === exports.nulls.int64)
1780
+ export function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
1781
+ if (nanotime === null || nanotime === nulls.int64)
1796
1782
  return 'null';
1797
1783
  if (nanotime < 0n)
1798
1784
  return String(nanotime);
@@ -1803,18 +1789,16 @@ function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
1803
1789
  const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
1804
1790
  if (i_nanosecond_start === -1)
1805
1791
  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)) +
1792
+ return (dayjs(timezone_offset + (Number(nanotime) / 1000000)).format(format.slice(0, i_second_end)) +
1807
1793
  format.slice(i_second_end, i_nanosecond_start) +
1808
1794
  String(nanotime % 1000000000n).padStart(9, '0'));
1809
1795
  }
1810
- exports.nanotime2str = nanotime2str;
1811
- function nanotimestamp2ns(nanotimestamp) {
1812
- return (nanotimestamp === null || nanotimestamp === exports.nulls.int64) ?
1796
+ export function nanotimestamp2ns(nanotimestamp) {
1797
+ return (nanotimestamp === null || nanotimestamp === nulls.int64) ?
1813
1798
  null
1814
1799
  :
1815
- BigInt(exports.timezone_offset) * 1000000n + nanotimestamp;
1800
+ BigInt(timezone_offset) * 1000000n + nanotimestamp;
1816
1801
  }
1817
- exports.nanotimestamp2ns = nanotimestamp2ns;
1818
1802
  /** format nanotimestamp value (bigint) to string
1819
1803
  - nanotimestamp: bigint value
1820
1804
  - format?:
@@ -1822,14 +1806,14 @@ exports.nanotimestamp2ns = nanotimestamp2ns;
1822
1806
  Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
1823
1807
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1824
1808
  */
1825
- function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1809
+ export function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1826
1810
  // tests:
1827
1811
  // nanotimestamp2str(0n)
1828
1812
  // nanotimestamp2str(-1n)
1829
1813
  // nanotimestamp2str(-9_9999_9999n)
1830
1814
  // nanotimestamp2str(-10_0000_0000n)
1831
1815
  // nanotimestamp2str(-10_0000_0001n)
1832
- if (nanotimestamp === null || nanotimestamp === exports.nulls.int64)
1816
+ if (nanotimestamp === null || nanotimestamp === nulls.int64)
1833
1817
  return 'null';
1834
1818
  const i_second_start = format.indexOf('ss');
1835
1819
  if (i_second_start === -1)
@@ -1840,7 +1824,7 @@ function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSS
1840
1824
  throw new Error('The format string must contain the format for nanoseconds (SSSSSSSSS)');
1841
1825
  const remainder = nanotimestamp % 1000000000n;
1842
1826
  const borrow = remainder < 0n;
1843
- return ((0, dayjs_1.default)(exports.timezone_offset +
1827
+ return (dayjs(timezone_offset +
1844
1828
  // 去掉 9 位的纳秒部分,转化为毫秒
1845
1829
  Number((nanotimestamp - remainder + (borrow ? -1000000000n : 0n)) / 1000000n)).format(format.slice(0, i_second_end)) +
1846
1830
  format.slice(i_second_end, i_nanosecond_start) +
@@ -1849,7 +1833,6 @@ function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSS
1849
1833
  :
1850
1834
  remainder).padStart(9, '0'));
1851
1835
  }
1852
- exports.nanotimestamp2str = nanotimestamp2str;
1853
1836
  /** parse nano timestamp string to bigint value
1854
1837
  - str: nano timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
1855
1838
  - format?:
@@ -1857,9 +1840,9 @@ exports.nanotimestamp2str = nanotimestamp2str;
1857
1840
  Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
1858
1841
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1859
1842
  */
1860
- function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1843
+ export function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1861
1844
  if (!str || str === 'null')
1862
- return exports.nulls.int64;
1845
+ return nulls.int64;
1863
1846
  if (str.length !== format.length)
1864
1847
  throw new Error('nanotimestamp string length is not equal to format string length');
1865
1848
  const i_second_start = format.indexOf('ss');
@@ -1869,13 +1852,12 @@ function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1869
1852
  const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
1870
1853
  if (i_nanosecond_start === -1)
1871
1854
  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
1855
+ return (BigInt(-timezone_offset +
1856
+ dayjs(str.slice(0, i_second_end), format.slice(0, i_second_end)).valueOf()) * 1000000n
1874
1857
  +
1875
1858
  BigInt(str.slice(i_nanosecond_start, i_nanosecond_start + 9)));
1876
1859
  }
1877
- exports.str2nanotimestamp = str2nanotimestamp;
1878
- function ipaddr2str(buffer, le = true, ipv6) {
1860
+ export function ipaddr2str(buffer, le = true, ipv6) {
1879
1861
  let buf = buffer;
1880
1862
  if (le)
1881
1863
  buf = buffer.slice().reverse();
@@ -1886,21 +1868,51 @@ function ipaddr2str(buffer, le = true, ipv6) {
1886
1868
  else // ipv4
1887
1869
  return buf.subarray(12).join('.');
1888
1870
  }
1889
- exports.ipaddr2str = ipaddr2str;
1890
- function uuid2str(buffer, le = true) {
1871
+ export function uuid2str(buffer, le = true) {
1891
1872
  const str = int1282str(buffer, le);
1892
1873
  return `${str.slice(0, 8)}-${str.slice(8, 12)}-${str.slice(12, 16)}-${str.slice(16, 20)}-${str.slice(20)}`;
1893
1874
  }
1894
- exports.uuid2str = uuid2str;
1895
- function int1282str(buffer, le = true) {
1875
+ export function int1282str(buffer, le = true) {
1896
1876
  let buf = buffer;
1897
1877
  if (le)
1898
1878
  buf = buffer.slice().reverse();
1899
1879
  return [...buf].map(x => x.toString(16)
1900
1880
  .padStart(2, '0')).join('');
1901
1881
  }
1902
- exports.int1282str = int1282str;
1903
- class DDB {
1882
+ export class DDB {
1883
+ /** 当前的 session id (http 或 tcp) */
1884
+ sid = '0';
1885
+ /** utf-8 text decoder */
1886
+ dec = new TextDecoder('utf-8');
1887
+ enc = new TextEncoder();
1888
+ /** DolphinDB WebSocket URL
1889
+ e.g. `ws://127.0.0.1:8848/`, `wss://dolphindb.com`
1890
+ */
1891
+ url;
1892
+ websocket = null;
1893
+ /** little endian (server) */
1894
+ le = true;
1895
+ /** little endian (client) */
1896
+ static le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
1897
+ /** 是否在建立连接后自动登录,默认 true */
1898
+ autologin = true;
1899
+ /** DolphinDB 登录用户名 */
1900
+ username = 'admin';
1901
+ /** DolphinDB 登录密码 */
1902
+ password = '123456';
1903
+ /** python session flag (2048) */
1904
+ python = false;
1905
+ print_message_buffer = false;
1906
+ print_object_buffer = false;
1907
+ print_message = true;
1908
+ parse_object = true;
1909
+ /** DdbMessage listeners */
1910
+ listeners = [];
1911
+ pconnect = Promise.resolve();
1912
+ presult = Promise.resolve(null);
1913
+ get connected() {
1914
+ return this.websocket?.readyState === WebSocket.OPEN;
1915
+ }
1904
1916
  /**
1905
1917
  Initialize an instance of DolphinDB Client using the WebSocket URL
1906
1918
  (without establishing an actual network connection)
@@ -1923,29 +1935,6 @@ class DDB {
1923
1935
  })
1924
1936
  */
1925
1937
  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.promise = Promise.resolve(null);
1949
1938
  this.url = url;
1950
1939
  if (options.autologin !== undefined)
1951
1940
  this.autologin = options.autologin;
@@ -1956,9 +1945,6 @@ class DDB {
1956
1945
  if (options.python !== undefined)
1957
1946
  this.python = options.python;
1958
1947
  }
1959
- get connected() {
1960
- return this.websocket?.readyState === ws_1.WebSocket.OPEN;
1961
- }
1962
1948
  on_message(event) { }
1963
1949
  /** Establish the actual WebSocket connection to the DolphinDB corresponding to the URL
1964
1950
  - options?:
@@ -1980,7 +1966,7 @@ class DDB {
1980
1966
  if (options.python !== undefined)
1981
1967
  this.python = options.python;
1982
1968
  this.disconnect();
1983
- await (0, net_js_1.connect_websocket)(this.url, {
1969
+ await connect_websocket(this.url, {
1984
1970
  protocols: this.python ? ['python'] : [],
1985
1971
  on_open: async (event, websocket) => {
1986
1972
  this.websocket = websocket;
@@ -2066,7 +2052,8 @@ class DDB {
2066
2052
  if (this.connected)
2067
2053
  this.websocket.close(1000);
2068
2054
  this.on_message = () => { };
2069
- this.promise = Promise.resolve(null);
2055
+ this.presult = Promise.resolve(null);
2056
+ this.pconnect = Promise.resolve();
2070
2057
  }
2071
2058
  /** rpc through websocket (function/script/variable command)
2072
2059
  - type: API 类型: 'script' | 'function' | 'variable'
@@ -2078,8 +2065,21 @@ class DDB {
2078
2065
  为 false 时返回的 DdbObj 仅含有 buffer 和 le,不做解析,以便后续转发、序列化
2079
2066
  */
2080
2067
  async rpc(type, { script, func, args = [], vars = [], urgent, listener, parse_object, }) {
2081
- if (!this.websocket)
2082
- await this.connect();
2068
+ if (!this.websocket) {
2069
+ const ptail = this.pconnect;
2070
+ let resolve;
2071
+ this.pconnect = new Promise((_resolve, _reject) => {
2072
+ resolve = _resolve;
2073
+ });
2074
+ await ptail;
2075
+ try {
2076
+ if (!this.websocket)
2077
+ await this.connect();
2078
+ }
2079
+ finally {
2080
+ resolve();
2081
+ }
2082
+ }
2083
2083
  if (!this.connected)
2084
2084
  throw new Error(`${this.url} is already disconnected`);
2085
2085
  // this 上的当前配置需要在 message 到达后使用,先保存起来
@@ -2089,10 +2089,10 @@ class DDB {
2089
2089
  // 违反世界观可能造成:
2090
2090
  // 1. 并发多个请求只返回第一个结果(阻塞,需后续请求疏通)
2091
2091
  // 2. windows 下 ddb server 返回多个相同的结果
2092
- const ptail = this.promise;
2092
+ const ptail = this.presult;
2093
2093
  let resolve;
2094
2094
  let reject;
2095
- const promise = this.promise = new Promise((_resolve, _reject) => {
2095
+ const presult = this.presult = new Promise((_resolve, _reject) => {
2096
2096
  resolve = _resolve;
2097
2097
  reject = _reject;
2098
2098
  });
@@ -2105,7 +2105,7 @@ class DDB {
2105
2105
  try {
2106
2106
  const buf = new Uint8Array(buffer);
2107
2107
  if (this.print_message_buffer)
2108
- console.log((0, utils_js_1.typed_array_to_buffer)(buf));
2108
+ console.log(typed_array_to_buffer(buf));
2109
2109
  const message = this.parse_message(buf, parse_object);
2110
2110
  listener?.(message, this);
2111
2111
  for (const listener of _handlers)
@@ -2148,12 +2148,12 @@ class DDB {
2148
2148
  return 'connect\n';
2149
2149
  }
2150
2150
  })());
2151
- this.websocket.send((0, utils_js_1.concat)([
2151
+ this.websocket.send(concat([
2152
2152
  this.enc.encode(`API2 ${this.sid} ${command.length} / ${this.get_rpc_options({ urgent })}\n`),
2153
2153
  command,
2154
2154
  ...args.map((arg) => arg.pack())
2155
2155
  ]));
2156
- return promise;
2156
+ return presult;
2157
2157
  }
2158
2158
  /** eval script through websocket (script command)
2159
2159
  - script?: Script to execute
@@ -2262,7 +2262,7 @@ class DDB {
2262
2262
  };
2263
2263
  const buf_obj = buf.subarray(i_lf_1 + 1);
2264
2264
  if (this.print_object_buffer)
2265
- console.log((0, utils_js_1.typed_array_to_buffer)(buf_obj));
2265
+ console.log(typed_array_to_buffer(buf_obj));
2266
2266
  return {
2267
2267
  type: 'object',
2268
2268
  data: parse_object ?
@@ -2278,7 +2278,4 @@ class DDB {
2278
2278
  };
2279
2279
  }
2280
2280
  }
2281
- exports.DDB = DDB;
2282
- /** little endian (client) */
2283
- DDB.le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
2284
2281
  //# sourceMappingURL=index.js.map