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/browser.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.DDB = exports.int1282str = exports.uuid2str = exports.ipaddr2str = exports.str2nanotimestamp = exports.nanotimestamp2str = exports.nanotimestamp2ns = void 0;
5
- const tslib_1 = require("tslib");
6
- const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
7
- const customParseFormat_js_1 = tslib_1.__importDefault(require("dayjs/plugin/customParseFormat.js"));
8
- dayjs_1.default.extend(customParseFormat_js_1.default);
9
- const ipaddr_js_1 = tslib_1.__importDefault(require("ipaddr.js"));
10
- const { fromByteArray: buf2ipaddr } = ipaddr_js_1.default;
11
- require("xshell/prototype.browser.js");
12
- const utils_browser_js_1 = require("xshell/utils.browser.js");
13
- const net_browser_js_1 = require("xshell/net.browser.js");
14
- var DdbForm;
1
+ import dayjs from 'dayjs';
2
+ import DayjsCustomParseFormat from 'dayjs/plugin/customParseFormat.js';
3
+ dayjs.extend(DayjsCustomParseFormat);
4
+ import ipaddrjs from 'ipaddr.js';
5
+ const { fromByteArray: buf2ipaddr } = ipaddrjs;
6
+ import 'xshell/prototype.browser.js';
7
+ import { concat } from 'xshell/utils.browser.js';
8
+ import { connect_websocket } from 'xshell/net.browser.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
  The corresponding array vector type is 64 + base type
31
26
  The corresponding extended type is 128 + base type
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_browser_js_1.concat)([
903
+ return concat([
868
904
  header,
869
905
  ...body
870
906
  ]);
@@ -1062,6 +1098,8 @@ class DdbObj {
1062
1098
  }
1063
1099
  }
1064
1100
  }
1101
+ case DdbForm.chart:
1102
+ return JSON.stringify(this.value, (key, value) => key === 'data' ? value.toString() : value, 4);
1065
1103
  }
1066
1104
  return String(this.value);
1067
1105
  })();
@@ -1116,7 +1154,7 @@ class DdbObj {
1116
1154
  switch (type) {
1117
1155
  case DdbType.bool: {
1118
1156
  const value = values[i];
1119
- row[name] = value === exports.nulls.int8 ?
1157
+ row[name] = value === nulls.int8 ?
1120
1158
  null
1121
1159
  :
1122
1160
  Boolean(value);
@@ -1157,24 +1195,15 @@ class DdbObj {
1157
1195
  return obj;
1158
1196
  }
1159
1197
  }
1160
- exports.DdbObj = DdbObj;
1161
- DdbObj.dec = new TextDecoder('utf-8');
1162
- DdbObj.enc = new TextEncoder();
1163
- /** 维护已解析的 symbol base,比如流数据中后续的 symbol 向量可能只发送一个 base.id, base.size == 0, 依赖之前发送的 symbol base ?
1164
- 只是暂存,如果一张表有多个 symbol 列,可能这个 symbol base 会被复用,不同的对象之间 symbol base 一般不复用
1165
- */
1166
- DdbObj.symbol_bases = {};
1167
- /** little endian (client) */
1168
- DdbObj.le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
1169
- function format(type, value, le) {
1198
+ export function format(type, value, le) {
1170
1199
  switch (type) {
1171
1200
  case DdbType.bool:
1172
- return String((value === null || value === exports.nulls.int8) ?
1201
+ return String((value === null || value === nulls.int8) ?
1173
1202
  null
1174
1203
  :
1175
1204
  Boolean(value));
1176
1205
  case DdbType.char:
1177
- return String((value === null || value === exports.nulls.int8) ?
1206
+ return String((value === null || value === nulls.int8) ?
1178
1207
  null
1179
1208
  :
1180
1209
  // ascii printable
@@ -1184,72 +1213,72 @@ function format(type, value, le) {
1184
1213
  :
1185
1214
  value);
1186
1215
  case DdbType.short:
1187
- return String((value === null || value === exports.nulls.int16) ?
1216
+ return String((value === null || value === nulls.int16) ?
1188
1217
  null
1189
1218
  :
1190
1219
  value);
1191
1220
  case DdbType.int:
1192
- return String((value === null || value === exports.nulls.int32) ?
1221
+ return String((value === null || value === nulls.int32) ?
1193
1222
  null
1194
1223
  :
1195
1224
  value);
1196
1225
  case DdbType.long:
1197
- return (value === null || value === exports.nulls.int64) ?
1226
+ return (value === null || value === nulls.int64) ?
1198
1227
  'null'
1199
1228
  :
1200
1229
  String(value);
1201
1230
  case DdbType.date:
1202
- return (value === null || value === exports.nulls.int32) ?
1231
+ return (value === null || value === nulls.int32) ?
1203
1232
  'null'
1204
1233
  :
1205
1234
  date2str(value);
1206
1235
  case DdbType.month:
1207
- return (value === null || value === exports.nulls.int32) ?
1236
+ return (value === null || value === nulls.int32) ?
1208
1237
  'null'
1209
1238
  :
1210
1239
  month2str(value);
1211
1240
  case DdbType.time:
1212
- return (value === null || value === exports.nulls.int32) ?
1241
+ return (value === null || value === nulls.int32) ?
1213
1242
  'null'
1214
1243
  :
1215
1244
  time2str(value);
1216
1245
  case DdbType.minute:
1217
- return (value === null || value === exports.nulls.int32) ?
1246
+ return (value === null || value === nulls.int32) ?
1218
1247
  'null'
1219
1248
  :
1220
1249
  minute2str(value);
1221
1250
  case DdbType.second:
1222
- return (value === null || value === exports.nulls.int32) ?
1251
+ return (value === null || value === nulls.int32) ?
1223
1252
  'null'
1224
1253
  :
1225
1254
  second2str(value);
1226
1255
  case DdbType.datetime:
1227
- return (value === null || value === exports.nulls.int32) ?
1256
+ return (value === null || value === nulls.int32) ?
1228
1257
  'null'
1229
1258
  :
1230
1259
  datetime2str(value);
1231
1260
  case DdbType.timestamp:
1232
- return (value === null || value === exports.nulls.int64) ?
1261
+ return (value === null || value === nulls.int64) ?
1233
1262
  'null'
1234
1263
  :
1235
1264
  timestamp2str(value);
1236
1265
  case DdbType.nanotime:
1237
- return (value === null || value === exports.nulls.int64) ?
1266
+ return (value === null || value === nulls.int64) ?
1238
1267
  'null'
1239
1268
  :
1240
1269
  nanotime2str(value);
1241
1270
  case DdbType.nanotimestamp:
1242
- return (value === null || value === exports.nulls.int64) ?
1271
+ return (value === null || value === nulls.int64) ?
1243
1272
  'null'
1244
1273
  :
1245
1274
  nanotimestamp2str(value);
1246
1275
  case DdbType.float:
1247
- return (value === null || value === exports.nulls.float32) ?
1276
+ return (value === null || value === nulls.float32) ?
1248
1277
  'null'
1249
1278
  :
1250
1279
  String(value);
1251
1280
  case DdbType.double:
1252
- return (value === null || value === exports.nulls.double) ?
1281
+ return (value === null || value === nulls.double) ?
1253
1282
  'null'
1254
1283
  :
1255
1284
  String(value);
@@ -1264,7 +1293,7 @@ function format(type, value, le) {
1264
1293
  case DdbType.code:
1265
1294
  return value.quote('single');
1266
1295
  case DdbType.datehour:
1267
- return (value === null || value === exports.nulls.int32) ?
1296
+ return (value === null || value === nulls.int32) ?
1268
1297
  'null'
1269
1298
  :
1270
1299
  datehour2str(value);
@@ -1279,17 +1308,17 @@ function format(type, value, le) {
1279
1308
  DdbObj.dec.decode(value)).quote('single');
1280
1309
  case DdbType.point: {
1281
1310
  let [x, y] = value;
1282
- if (x === exports.nulls.double)
1311
+ if (x === nulls.double)
1283
1312
  x = null;
1284
- if (y === exports.nulls.double)
1313
+ if (y === nulls.double)
1285
1314
  y = null;
1286
1315
  return `(${String(x)}, ${String(y)})`;
1287
1316
  }
1288
1317
  case DdbType.complex: {
1289
1318
  let [x, y] = value;
1290
- if (x === exports.nulls.double)
1319
+ if (x === nulls.double)
1291
1320
  x = null;
1292
- if (y === exports.nulls.double)
1321
+ if (y === nulls.double)
1293
1322
  y = null;
1294
1323
  return `${String(x)}+${String(y)}i`;
1295
1324
  }
@@ -1301,8 +1330,7 @@ function format(type, value, le) {
1301
1330
  return String(value);
1302
1331
  }
1303
1332
  }
1304
- exports.format = format;
1305
- class DdbVoid extends DdbObj {
1333
+ export class DdbVoid extends DdbObj {
1306
1334
  constructor() {
1307
1335
  super({
1308
1336
  form: DdbForm.scalar,
@@ -1311,8 +1339,7 @@ class DdbVoid extends DdbObj {
1311
1339
  });
1312
1340
  }
1313
1341
  }
1314
- exports.DdbVoid = DdbVoid;
1315
- class DdbBool extends DdbObj {
1342
+ export class DdbBool extends DdbObj {
1316
1343
  constructor(value) {
1317
1344
  super({
1318
1345
  form: DdbForm.scalar,
@@ -1321,8 +1348,7 @@ class DdbBool extends DdbObj {
1321
1348
  });
1322
1349
  }
1323
1350
  }
1324
- exports.DdbBool = DdbBool;
1325
- class DdbChar extends DdbObj {
1351
+ export class DdbChar extends DdbObj {
1326
1352
  constructor(value) {
1327
1353
  super({
1328
1354
  form: DdbForm.scalar,
@@ -1334,8 +1360,7 @@ class DdbChar extends DdbObj {
1334
1360
  });
1335
1361
  }
1336
1362
  }
1337
- exports.DdbChar = DdbChar;
1338
- class DdbInt extends DdbObj {
1363
+ export class DdbInt extends DdbObj {
1339
1364
  constructor(value) {
1340
1365
  super({
1341
1366
  form: DdbForm.scalar,
@@ -1344,8 +1369,7 @@ class DdbInt extends DdbObj {
1344
1369
  });
1345
1370
  }
1346
1371
  }
1347
- exports.DdbInt = DdbInt;
1348
- class DdbString extends DdbObj {
1372
+ export class DdbString extends DdbObj {
1349
1373
  constructor(value) {
1350
1374
  super({
1351
1375
  form: DdbForm.scalar,
@@ -1354,8 +1378,7 @@ class DdbString extends DdbObj {
1354
1378
  });
1355
1379
  }
1356
1380
  }
1357
- exports.DdbString = DdbString;
1358
- class DdbLong extends DdbObj {
1381
+ export class DdbLong extends DdbObj {
1359
1382
  constructor(value) {
1360
1383
  super({
1361
1384
  form: DdbForm.scalar,
@@ -1364,8 +1387,7 @@ class DdbLong extends DdbObj {
1364
1387
  });
1365
1388
  }
1366
1389
  }
1367
- exports.DdbLong = DdbLong;
1368
- class DdbDouble extends DdbObj {
1390
+ export class DdbDouble extends DdbObj {
1369
1391
  constructor(value) {
1370
1392
  super({
1371
1393
  form: DdbForm.scalar,
@@ -1374,8 +1396,7 @@ class DdbDouble extends DdbObj {
1374
1396
  });
1375
1397
  }
1376
1398
  }
1377
- exports.DdbDouble = DdbDouble;
1378
- class DdbDateTime extends DdbObj {
1399
+ export class DdbDateTime extends DdbObj {
1379
1400
  constructor(value) {
1380
1401
  super({
1381
1402
  form: DdbForm.scalar,
@@ -1384,8 +1405,7 @@ class DdbDateTime extends DdbObj {
1384
1405
  });
1385
1406
  }
1386
1407
  }
1387
- exports.DdbDateTime = DdbDateTime;
1388
- class DdbTimeStamp extends DdbObj {
1408
+ export class DdbTimeStamp extends DdbObj {
1389
1409
  constructor(value) {
1390
1410
  super({
1391
1411
  form: DdbForm.scalar,
@@ -1394,8 +1414,7 @@ class DdbTimeStamp extends DdbObj {
1394
1414
  });
1395
1415
  }
1396
1416
  }
1397
- exports.DdbTimeStamp = DdbTimeStamp;
1398
- class DdbNanoTimeStamp extends DdbObj {
1417
+ export class DdbNanoTimeStamp extends DdbObj {
1399
1418
  constructor(value) {
1400
1419
  super({
1401
1420
  form: DdbForm.scalar,
@@ -1404,20 +1423,18 @@ class DdbNanoTimeStamp extends DdbObj {
1404
1423
  });
1405
1424
  }
1406
1425
  }
1407
- exports.DdbNanoTimeStamp = DdbNanoTimeStamp;
1408
- class DdbPair extends DdbObj {
1426
+ export class DdbPair extends DdbObj {
1409
1427
  constructor(l, r = null) {
1410
1428
  super({
1411
1429
  form: DdbForm.pair,
1412
1430
  type: DdbType.int,
1413
1431
  rows: 2,
1414
1432
  cols: 1,
1415
- value: Int32Array.of(l === null ? exports.nulls.int32 : l, r === null ? exports.nulls.int32 : r)
1433
+ value: Int32Array.of(l === null ? nulls.int32 : l, r === null ? nulls.int32 : r)
1416
1434
  });
1417
1435
  }
1418
1436
  }
1419
- exports.DdbPair = DdbPair;
1420
- class DdbFunction extends DdbObj {
1437
+ export class DdbFunction extends DdbObj {
1421
1438
  constructor(name, type) {
1422
1439
  super({
1423
1440
  form: DdbForm.scalar,
@@ -1426,8 +1443,7 @@ class DdbFunction extends DdbObj {
1426
1443
  });
1427
1444
  }
1428
1445
  }
1429
- exports.DdbFunction = DdbFunction;
1430
- class DdbVectorInt extends DdbObj {
1446
+ export class DdbVectorInt extends DdbObj {
1431
1447
  constructor(ints, name) {
1432
1448
  super({
1433
1449
  form: DdbForm.vector,
@@ -1438,15 +1454,14 @@ class DdbVectorInt extends DdbObj {
1438
1454
  ints
1439
1455
  :
1440
1456
  Int32Array.from(ints, v => v === null ?
1441
- exports.nulls.int32
1457
+ nulls.int32
1442
1458
  :
1443
1459
  v),
1444
1460
  name,
1445
1461
  });
1446
1462
  }
1447
1463
  }
1448
- exports.DdbVectorInt = DdbVectorInt;
1449
- class DdbVectorDouble extends DdbObj {
1464
+ export class DdbVectorDouble extends DdbObj {
1450
1465
  constructor(doubles, name) {
1451
1466
  super({
1452
1467
  form: DdbForm.vector,
@@ -1457,15 +1472,14 @@ class DdbVectorDouble extends DdbObj {
1457
1472
  doubles
1458
1473
  :
1459
1474
  Float64Array.from(doubles, v => v === null ?
1460
- exports.nulls.double
1475
+ nulls.double
1461
1476
  :
1462
1477
  v),
1463
1478
  name,
1464
1479
  });
1465
1480
  }
1466
1481
  }
1467
- exports.DdbVectorDouble = DdbVectorDouble;
1468
- class DdbVectorString extends DdbObj {
1482
+ export class DdbVectorString extends DdbObj {
1469
1483
  constructor(strings, name) {
1470
1484
  super({
1471
1485
  form: DdbForm.vector,
@@ -1477,8 +1491,7 @@ class DdbVectorString extends DdbObj {
1477
1491
  });
1478
1492
  }
1479
1493
  }
1480
- exports.DdbVectorString = DdbVectorString;
1481
- class DdbVectorAny extends DdbObj {
1494
+ export class DdbVectorAny extends DdbObj {
1482
1495
  constructor(objs, name) {
1483
1496
  super({
1484
1497
  form: DdbForm.vector,
@@ -1490,8 +1503,7 @@ class DdbVectorAny extends DdbObj {
1490
1503
  });
1491
1504
  }
1492
1505
  }
1493
- exports.DdbVectorAny = DdbVectorAny;
1494
- class DdbVectorSymbol extends DdbObj {
1506
+ export class DdbVectorSymbol extends DdbObj {
1495
1507
  constructor(strings, name) {
1496
1508
  let map = new Map([
1497
1509
  ['', 0]
@@ -1520,8 +1532,7 @@ class DdbVectorSymbol extends DdbObj {
1520
1532
  });
1521
1533
  }
1522
1534
  }
1523
- exports.DdbVectorSymbol = DdbVectorSymbol;
1524
- class DdbSetInt extends DdbObj {
1535
+ export class DdbSetInt extends DdbObj {
1525
1536
  constructor(ints) {
1526
1537
  super({
1527
1538
  form: DdbForm.set,
@@ -1535,14 +1546,13 @@ class DdbSetInt extends DdbObj {
1535
1546
  ints
1536
1547
  :
1537
1548
  Int32Array.from(ints, v => v === null ?
1538
- exports.nulls.int32
1549
+ nulls.int32
1539
1550
  :
1540
1551
  v),
1541
1552
  });
1542
1553
  }
1543
1554
  }
1544
- exports.DdbSetInt = DdbSetInt;
1545
- class DdbSetDouble extends DdbObj {
1555
+ export class DdbSetDouble extends DdbObj {
1546
1556
  constructor(doubles) {
1547
1557
  super({
1548
1558
  form: DdbForm.set,
@@ -1556,14 +1566,13 @@ class DdbSetDouble extends DdbObj {
1556
1566
  doubles
1557
1567
  :
1558
1568
  Int32Array.from(doubles, v => v === null ?
1559
- exports.nulls.int32
1569
+ nulls.int32
1560
1570
  :
1561
1571
  v),
1562
1572
  });
1563
1573
  }
1564
1574
  }
1565
- exports.DdbSetDouble = DdbSetDouble;
1566
- class DdbSetString extends DdbObj {
1575
+ export class DdbSetString extends DdbObj {
1567
1576
  constructor(strings) {
1568
1577
  if (strings instanceof Set)
1569
1578
  strings = [...strings];
@@ -1576,12 +1585,11 @@ class DdbSetString extends DdbObj {
1576
1585
  });
1577
1586
  }
1578
1587
  }
1579
- exports.DdbSetString = DdbSetString;
1580
1588
  /** Constructs a DdbDict object, which supports two usages:
1581
1589
  - 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>
1582
1590
  - Pass in js object (type is Record<string, boolean | string | DdbObj>), automatically converted to DdbDict of dict<string, any>
1583
1591
  */
1584
- class DdbDict extends DdbObj {
1592
+ export class DdbDict extends DdbObj {
1585
1593
  constructor(arg0, arg1) {
1586
1594
  if (arg1)
1587
1595
  super({
@@ -1606,8 +1614,7 @@ class DdbDict extends DdbObj {
1606
1614
  }
1607
1615
  }
1608
1616
  }
1609
- exports.DdbDict = DdbDict;
1610
- class DdbTable extends DdbObj {
1617
+ export class DdbTable extends DdbObj {
1611
1618
  constructor(columns, name = '') {
1612
1619
  super({
1613
1620
  form: DdbForm.table,
@@ -1619,30 +1626,26 @@ class DdbTable extends DdbObj {
1619
1626
  });
1620
1627
  }
1621
1628
  }
1622
- exports.DdbTable = DdbTable;
1623
- function date2ms(date) {
1624
- return (date === null || date === exports.nulls.int32) ?
1629
+ export function date2ms(date) {
1630
+ return (date === null || date === nulls.int32) ?
1625
1631
  null
1626
1632
  :
1627
- exports.timezone_offset + 1000 * 3600 * 24 * date;
1633
+ timezone_offset + 1000 * 3600 * 24 * date;
1628
1634
  }
1629
- exports.date2ms = date2ms;
1630
- function date2str(date, format = 'YYYY.MM.DD') {
1631
- return (date === null || date === exports.nulls.int32) ?
1635
+ export function date2str(date, format = 'YYYY.MM.DD') {
1636
+ return (date === null || date === nulls.int32) ?
1632
1637
  null
1633
1638
  :
1634
- (0, dayjs_1.default)(date2ms(date)).format(format);
1639
+ dayjs(date2ms(date)).format(format);
1635
1640
  }
1636
- exports.date2str = date2str;
1637
- function month2ms(month) {
1638
- return (month === null || month === exports.nulls.int32) ?
1641
+ export function month2ms(month) {
1642
+ return (month === null || month === nulls.int32) ?
1639
1643
  null
1640
1644
  :
1641
- (0, dayjs_1.default)(month2str(month), 'YYYY.MM[M]').valueOf();
1645
+ dayjs(month2str(month), 'YYYY.MM[M]').valueOf();
1642
1646
  }
1643
- exports.month2ms = month2ms;
1644
- function month2str(month) {
1645
- if (month === null || month === exports.nulls.int32)
1647
+ export function month2str(month) {
1648
+ if (month === null || month === nulls.int32)
1646
1649
  return 'null';
1647
1650
  if (month < 0)
1648
1651
  return String(month);
@@ -1650,118 +1653,103 @@ function month2str(month) {
1650
1653
  const year = Math.trunc(month / 12);
1651
1654
  return `${String(year).padStart(4, '0')}.${String(_month + 1).padStart(2, '0')}M`;
1652
1655
  }
1653
- exports.month2str = month2str;
1654
- function time2ms(time) {
1655
- return (time === null || time === exports.nulls.int32) ?
1656
+ export function time2ms(time) {
1657
+ return (time === null || time === nulls.int32) ?
1656
1658
  null
1657
1659
  :
1658
- exports.timezone_offset + time;
1660
+ timezone_offset + time;
1659
1661
  }
1660
- exports.time2ms = time2ms;
1661
- function time2str(time, format = 'HH:mm:ss.SSS') {
1662
- return (time === null || time === exports.nulls.int32) ?
1662
+ export function time2str(time, format = 'HH:mm:ss.SSS') {
1663
+ return (time === null || time === nulls.int32) ?
1663
1664
  null
1664
1665
  :
1665
- (0, dayjs_1.default)(time2ms(time)).format(format);
1666
+ dayjs(time2ms(time)).format(format);
1666
1667
  }
1667
- exports.time2str = time2str;
1668
- function minute2ms(minute) {
1669
- return (minute === null || minute === exports.nulls.int32) ?
1668
+ export function minute2ms(minute) {
1669
+ return (minute === null || minute === nulls.int32) ?
1670
1670
  null
1671
1671
  :
1672
- exports.timezone_offset + 60 * 1000 * minute;
1672
+ timezone_offset + 60 * 1000 * minute;
1673
1673
  }
1674
- exports.minute2ms = minute2ms;
1675
- function minute2str(minute, format = 'HH:mm[m]') {
1676
- return (minute === null || minute === exports.nulls.int32) ?
1674
+ export function minute2str(minute, format = 'HH:mm[m]') {
1675
+ return (minute === null || minute === nulls.int32) ?
1677
1676
  'null'
1678
1677
  :
1679
- (0, dayjs_1.default)(minute2ms(minute)).format(format);
1678
+ dayjs(minute2ms(minute)).format(format);
1680
1679
  }
1681
- exports.minute2str = minute2str;
1682
- function second2ms(second) {
1683
- return (second === null || second === exports.nulls.int32) ?
1680
+ export function second2ms(second) {
1681
+ return (second === null || second === nulls.int32) ?
1684
1682
  null
1685
1683
  :
1686
- exports.timezone_offset + 1000 * second;
1684
+ timezone_offset + 1000 * second;
1687
1685
  }
1688
- exports.second2ms = second2ms;
1689
- function second2str(second, format = 'HH:mm:ss') {
1690
- return (second === null || second === exports.nulls.int32) ?
1686
+ export function second2str(second, format = 'HH:mm:ss') {
1687
+ return (second === null || second === nulls.int32) ?
1691
1688
  'null'
1692
1689
  :
1693
- (0, dayjs_1.default)(second2ms(second)).format(format);
1690
+ dayjs(second2ms(second)).format(format);
1694
1691
  }
1695
- exports.second2str = second2str;
1696
- function datetime2ms(datetime) {
1697
- return (datetime === null || datetime === exports.nulls.int32) ?
1692
+ export function datetime2ms(datetime) {
1693
+ return (datetime === null || datetime === nulls.int32) ?
1698
1694
  null
1699
1695
  :
1700
- exports.timezone_offset + 1000 * datetime;
1696
+ timezone_offset + 1000 * datetime;
1701
1697
  }
1702
- exports.datetime2ms = datetime2ms;
1703
- function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
1704
- return (datetime === null || datetime === exports.nulls.int32) ?
1698
+ export function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
1699
+ return (datetime === null || datetime === nulls.int32) ?
1705
1700
  'null'
1706
1701
  :
1707
- (0, dayjs_1.default)(datetime2ms(datetime)).format(format);
1702
+ dayjs(datetime2ms(datetime)).format(format);
1708
1703
  }
1709
- exports.datetime2str = datetime2str;
1710
- function timestamp2ms(timestamp) {
1711
- return (timestamp === null || timestamp === exports.nulls.int64) ?
1704
+ export function timestamp2ms(timestamp) {
1705
+ return (timestamp === null || timestamp === nulls.int64) ?
1712
1706
  null
1713
1707
  :
1714
- exports.timezone_offset + Number(timestamp);
1708
+ timezone_offset + Number(timestamp);
1715
1709
  }
1716
- exports.timestamp2ms = timestamp2ms;
1717
1710
  /** format timestamp (bigint) to string
1718
1711
  - timestamp: bigint value
1719
1712
  - format?:
1720
1713
  format string, default to `YYYY.MM.DD HH:mm:ss.SSS`
1721
1714
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1722
1715
  */
1723
- function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1724
- return (timestamp === null || timestamp === exports.nulls.int64) ?
1716
+ export function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1717
+ return (timestamp === null || timestamp === nulls.int64) ?
1725
1718
  'null'
1726
1719
  :
1727
- (0, dayjs_1.default)(timestamp2ms(timestamp)).format(format);
1720
+ dayjs(timestamp2ms(timestamp)).format(format);
1728
1721
  }
1729
- exports.timestamp2str = timestamp2str;
1730
- function datehour2ms(datehour) {
1731
- return (datehour === null || datehour === exports.nulls.int32) ?
1722
+ export function datehour2ms(datehour) {
1723
+ return (datehour === null || datehour === nulls.int32) ?
1732
1724
  null
1733
1725
  :
1734
- exports.timezone_offset + 1000 * 3600 * datehour;
1726
+ timezone_offset + 1000 * 3600 * datehour;
1735
1727
  }
1736
- exports.datehour2ms = datehour2ms;
1737
- function datehour2str(datehour, format = 'YYYY.MM.DDTHH') {
1738
- return (datehour === null || datehour === exports.nulls.int32) ?
1728
+ export function datehour2str(datehour, format = 'YYYY.MM.DDTHH') {
1729
+ return (datehour === null || datehour === nulls.int32) ?
1739
1730
  'null'
1740
1731
  :
1741
- (0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * datehour).format(format);
1732
+ dayjs(timezone_offset + 1000 * 3600 * datehour).format(format);
1742
1733
  }
1743
- exports.datehour2str = datehour2str;
1744
1734
  /** parse timestamp string to bigint value
1745
1735
  - str: timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
1746
1736
  - format?:
1747
1737
  The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
1748
1738
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1749
1739
  */
1750
- function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1740
+ export function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1751
1741
  if (!str || str === 'null')
1752
- return exports.nulls.int64;
1742
+ return nulls.int64;
1753
1743
  if (str.length !== format.length)
1754
1744
  throw new Error('The length of the timestamp string is not equal to the length of the format string');
1755
- return BigInt(-exports.timezone_offset +
1756
- (0, dayjs_1.default)(str, format).valueOf());
1745
+ return BigInt(-timezone_offset +
1746
+ dayjs(str, format).valueOf());
1757
1747
  }
1758
- exports.str2timestamp = str2timestamp;
1759
- function nanotime2ns(nanotime) {
1748
+ export function nanotime2ns(nanotime) {
1760
1749
  return nanotimestamp2ns(nanotime);
1761
1750
  }
1762
- exports.nanotime2ns = nanotime2ns;
1763
- function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
1764
- if (nanotime === null || nanotime === exports.nulls.int64)
1751
+ export function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
1752
+ if (nanotime === null || nanotime === nulls.int64)
1765
1753
  return 'null';
1766
1754
  if (nanotime < 0n)
1767
1755
  return String(nanotime);
@@ -1772,18 +1760,16 @@ function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
1772
1760
  const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
1773
1761
  if (i_nanosecond_start === -1)
1774
1762
  throw new Error('格式串必须包含纳秒的格式 (SSSSSSSSS)');
1775
- return ((0, dayjs_1.default)(exports.timezone_offset + (Number(nanotime) / 1000000)).format(format.slice(0, i_second_end)) +
1763
+ return (dayjs(timezone_offset + (Number(nanotime) / 1000000)).format(format.slice(0, i_second_end)) +
1776
1764
  format.slice(i_second_end, i_nanosecond_start) +
1777
1765
  String(nanotime % 1000000000n).padStart(9, '0'));
1778
1766
  }
1779
- exports.nanotime2str = nanotime2str;
1780
- function nanotimestamp2ns(nanotimestamp) {
1781
- return (nanotimestamp === null || nanotimestamp === exports.nulls.int64) ?
1767
+ export function nanotimestamp2ns(nanotimestamp) {
1768
+ return (nanotimestamp === null || nanotimestamp === nulls.int64) ?
1782
1769
  null
1783
1770
  :
1784
- BigInt(exports.timezone_offset) * 1000000n + nanotimestamp;
1771
+ BigInt(timezone_offset) * 1000000n + nanotimestamp;
1785
1772
  }
1786
- exports.nanotimestamp2ns = nanotimestamp2ns;
1787
1773
  /** format nanotimestamp value (bigint) to string
1788
1774
  - nanotimestamp: bigint value
1789
1775
  - format?:
@@ -1791,14 +1777,14 @@ exports.nanotimestamp2ns = nanotimestamp2ns;
1791
1777
  Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
1792
1778
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1793
1779
  */
1794
- function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1780
+ export function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1795
1781
  // tests:
1796
1782
  // nanotimestamp2str(0n)
1797
1783
  // nanotimestamp2str(-1n)
1798
1784
  // nanotimestamp2str(-9_9999_9999n)
1799
1785
  // nanotimestamp2str(-10_0000_0000n)
1800
1786
  // nanotimestamp2str(-10_0000_0001n)
1801
- if (nanotimestamp === null || nanotimestamp === exports.nulls.int64)
1787
+ if (nanotimestamp === null || nanotimestamp === nulls.int64)
1802
1788
  return 'null';
1803
1789
  const i_second_start = format.indexOf('ss');
1804
1790
  if (i_second_start === -1)
@@ -1809,7 +1795,7 @@ function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSS
1809
1795
  throw new Error('The format string must contain the format for nanoseconds (SSSSSSSSS)');
1810
1796
  const remainder = nanotimestamp % 1000000000n;
1811
1797
  const borrow = remainder < 0n;
1812
- return ((0, dayjs_1.default)(exports.timezone_offset +
1798
+ return (dayjs(timezone_offset +
1813
1799
  // 去掉 9 位的纳秒部分,转化为毫秒
1814
1800
  Number((nanotimestamp - remainder + (borrow ? -1000000000n : 0n)) / 1000000n)).format(format.slice(0, i_second_end)) +
1815
1801
  format.slice(i_second_end, i_nanosecond_start) +
@@ -1818,7 +1804,6 @@ function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSS
1818
1804
  :
1819
1805
  remainder).padStart(9, '0'));
1820
1806
  }
1821
- exports.nanotimestamp2str = nanotimestamp2str;
1822
1807
  /** parse nano timestamp string to bigint value
1823
1808
  - str: nano timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
1824
1809
  - format?:
@@ -1826,9 +1811,9 @@ exports.nanotimestamp2str = nanotimestamp2str;
1826
1811
  Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
1827
1812
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1828
1813
  */
1829
- function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1814
+ export function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1830
1815
  if (!str || str === 'null')
1831
- return exports.nulls.int64;
1816
+ return nulls.int64;
1832
1817
  if (str.length !== format.length)
1833
1818
  throw new Error('nanotimestamp string length is not equal to format string length');
1834
1819
  const i_second_start = format.indexOf('ss');
@@ -1838,13 +1823,12 @@ function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1838
1823
  const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
1839
1824
  if (i_nanosecond_start === -1)
1840
1825
  throw new Error('Format string must contain nanosecond format (SSSSSSSSS)');
1841
- return (BigInt(-exports.timezone_offset +
1842
- (0, dayjs_1.default)(str.slice(0, i_second_end), format.slice(0, i_second_end)).valueOf()) * 1000000n
1826
+ return (BigInt(-timezone_offset +
1827
+ dayjs(str.slice(0, i_second_end), format.slice(0, i_second_end)).valueOf()) * 1000000n
1843
1828
  +
1844
1829
  BigInt(str.slice(i_nanosecond_start, i_nanosecond_start + 9)));
1845
1830
  }
1846
- exports.str2nanotimestamp = str2nanotimestamp;
1847
- function ipaddr2str(buffer, le = true, ipv6) {
1831
+ export function ipaddr2str(buffer, le = true, ipv6) {
1848
1832
  let buf = buffer;
1849
1833
  if (le)
1850
1834
  buf = buffer.slice().reverse();
@@ -1855,21 +1839,51 @@ function ipaddr2str(buffer, le = true, ipv6) {
1855
1839
  else // ipv4
1856
1840
  return buf.subarray(12).join('.');
1857
1841
  }
1858
- exports.ipaddr2str = ipaddr2str;
1859
- function uuid2str(buffer, le = true) {
1842
+ export function uuid2str(buffer, le = true) {
1860
1843
  const str = int1282str(buffer, le);
1861
1844
  return `${str.slice(0, 8)}-${str.slice(8, 12)}-${str.slice(12, 16)}-${str.slice(16, 20)}-${str.slice(20)}`;
1862
1845
  }
1863
- exports.uuid2str = uuid2str;
1864
- function int1282str(buffer, le = true) {
1846
+ export function int1282str(buffer, le = true) {
1865
1847
  let buf = buffer;
1866
1848
  if (le)
1867
1849
  buf = buffer.slice().reverse();
1868
1850
  return [...buf].map(x => x.toString(16)
1869
1851
  .padStart(2, '0')).join('');
1870
1852
  }
1871
- exports.int1282str = int1282str;
1872
- class DDB {
1853
+ export class DDB {
1854
+ /** 当前的 session id (http 或 tcp) */
1855
+ sid = '0';
1856
+ /** utf-8 text decoder */
1857
+ dec = new TextDecoder('utf-8');
1858
+ enc = new TextEncoder();
1859
+ /** DolphinDB WebSocket URL
1860
+ e.g. `ws://127.0.0.1:8848/`, `wss://dolphindb.com`
1861
+ */
1862
+ url;
1863
+ websocket = null;
1864
+ /** little endian (server) */
1865
+ le = true;
1866
+ /** little endian (client) */
1867
+ static le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
1868
+ /** Whether to automatically log in after the connection is established, the default is true */
1869
+ autologin = true;
1870
+ /** DolphinDB username */
1871
+ username = 'admin';
1872
+ /** DolphinDB password */
1873
+ password = '123456';
1874
+ /** python session flag (2048) */
1875
+ python = false;
1876
+ print_message_buffer = false;
1877
+ print_object_buffer = false;
1878
+ print_message = true;
1879
+ parse_object = true;
1880
+ /** DdbMessage listeners */
1881
+ listeners = [];
1882
+ pconnect = Promise.resolve();
1883
+ presult = Promise.resolve(null);
1884
+ get connected() {
1885
+ return this.websocket?.readyState === WebSocket.OPEN;
1886
+ }
1873
1887
  /**
1874
1888
  Initialize an instance of DolphinDB Client using the WebSocket URL
1875
1889
  (without establishing an actual network connection)
@@ -1892,29 +1906,6 @@ class DDB {
1892
1906
  })
1893
1907
  */
1894
1908
  constructor(url, options = {}) {
1895
- /** 当前的 session id (http 或 tcp) */
1896
- this.sid = '0';
1897
- /** utf-8 text decoder */
1898
- this.dec = new TextDecoder('utf-8');
1899
- this.enc = new TextEncoder();
1900
- this.websocket = null;
1901
- /** little endian (server) */
1902
- this.le = true;
1903
- /** Whether to automatically log in after the connection is established, the default is true */
1904
- this.autologin = true;
1905
- /** DolphinDB username */
1906
- this.username = 'admin';
1907
- /** DolphinDB password */
1908
- this.password = '123456';
1909
- /** python session flag (2048) */
1910
- this.python = false;
1911
- this.print_message_buffer = false;
1912
- this.print_object_buffer = false;
1913
- this.print_message = true;
1914
- this.parse_object = true;
1915
- /** DdbMessage listeners */
1916
- this.listeners = [];
1917
- this.promise = Promise.resolve(null);
1918
1909
  if (!url) {
1919
1910
  const _url = new URL(location.href);
1920
1911
  const hostname = _url.searchParams.get('hostname') || location.hostname;
@@ -1931,9 +1922,6 @@ class DDB {
1931
1922
  if (options.python !== undefined)
1932
1923
  this.python = options.python;
1933
1924
  }
1934
- get connected() {
1935
- return this.websocket?.readyState === WebSocket.OPEN;
1936
- }
1937
1925
  on_message(event) { }
1938
1926
  /** Establish the actual WebSocket connection to the DolphinDB corresponding to the URL
1939
1927
  - options?:
@@ -1955,7 +1943,7 @@ class DDB {
1955
1943
  if (options.python !== undefined)
1956
1944
  this.python = options.python;
1957
1945
  this.disconnect();
1958
- await (0, net_browser_js_1.connect_websocket)(this.url, {
1946
+ await connect_websocket(this.url, {
1959
1947
  protocols: this.python ? ['python'] : [],
1960
1948
  on_open: async (event, websocket) => {
1961
1949
  this.websocket = websocket;
@@ -2041,7 +2029,8 @@ class DDB {
2041
2029
  if (this.connected)
2042
2030
  this.websocket.close(1000);
2043
2031
  this.on_message = () => { };
2044
- this.promise = Promise.resolve(null);
2032
+ this.presult = Promise.resolve(null);
2033
+ this.pconnect = Promise.resolve();
2045
2034
  }
2046
2035
  /** rpc through websocket (function/script/variable command)
2047
2036
  - type: API 类型: 'script' | 'function' | 'variable'
@@ -2053,8 +2042,21 @@ class DDB {
2053
2042
  为 false 时返回的 DdbObj 仅含有 buffer 和 le,不做解析,以便后续转发、序列化
2054
2043
  */
2055
2044
  async rpc(type, { script, func, args = [], vars = [], urgent, listener, parse_object, }) {
2056
- if (!this.websocket)
2057
- await this.connect();
2045
+ if (!this.websocket) {
2046
+ const ptail = this.pconnect;
2047
+ let resolve;
2048
+ this.pconnect = new Promise((_resolve, _reject) => {
2049
+ resolve = _resolve;
2050
+ });
2051
+ await ptail;
2052
+ try {
2053
+ if (!this.websocket)
2054
+ await this.connect();
2055
+ }
2056
+ finally {
2057
+ resolve();
2058
+ }
2059
+ }
2058
2060
  if (!this.connected)
2059
2061
  throw new Error(`${this.url} is already disconnected`);
2060
2062
  // this 上的当前配置需要在 message 到达后使用,先保存起来
@@ -2064,10 +2066,10 @@ class DDB {
2064
2066
  // 违反世界观可能造成:
2065
2067
  // 1. 并发多个请求只返回第一个结果(阻塞,需后续请求疏通)
2066
2068
  // 2. windows 下 ddb server 返回多个相同的结果
2067
- const ptail = this.promise;
2069
+ const ptail = this.presult;
2068
2070
  let resolve;
2069
2071
  let reject;
2070
- const promise = this.promise = new Promise((_resolve, _reject) => {
2072
+ const presult = this.presult = new Promise((_resolve, _reject) => {
2071
2073
  resolve = _resolve;
2072
2074
  reject = _reject;
2073
2075
  });
@@ -2123,12 +2125,12 @@ class DDB {
2123
2125
  return 'connect\n';
2124
2126
  }
2125
2127
  })());
2126
- this.websocket.send((0, utils_browser_js_1.concat)([
2128
+ this.websocket.send(concat([
2127
2129
  this.enc.encode(`API2 ${this.sid} ${command.length} / ${this.get_rpc_options({ urgent })}\n`),
2128
2130
  command,
2129
2131
  ...args.map((arg) => arg.pack())
2130
2132
  ]));
2131
- return promise;
2133
+ return presult;
2132
2134
  }
2133
2135
  /** eval script through websocket (script command)
2134
2136
  - script?: Script to execute
@@ -2253,8 +2255,5 @@ class DDB {
2253
2255
  };
2254
2256
  }
2255
2257
  }
2256
- exports.DDB = DDB;
2257
- /** little endian (client) */
2258
- DDB.le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
2259
- exports.ddb = window.ddb = new DDB();
2258
+ export let ddb = window.ddb = new DDB();
2260
2259
  //# sourceMappingURL=browser.js.map