dolphindb 2.0.526 → 2.0.527

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) {
@@ -336,17 +363,17 @@ class DdbObj {
336
363
  case DdbType.bool: {
337
364
  const dv = new DataView(buf.buffer, buf.byteOffset);
338
365
  const value = dv.getInt8(0);
339
- return [1, value === exports.nulls.int8 ? null : Boolean(value)];
366
+ return [1, value === nulls.int8 ? null : Boolean(value)];
340
367
  }
341
368
  case DdbType.char: {
342
369
  const dv = new DataView(buf.buffer, buf.byteOffset);
343
370
  const value = dv.getInt8(0);
344
- return [1, value === exports.nulls.int8 ? null : value];
371
+ return [1, value === nulls.int8 ? null : value];
345
372
  }
346
373
  case DdbType.short: {
347
374
  const dv = new DataView(buf.buffer, buf.byteOffset);
348
375
  const value = dv.getInt16(0, le);
349
- return [2, value === exports.nulls.int16 ? null : value];
376
+ return [2, value === nulls.int16 ? null : value];
350
377
  }
351
378
  case DdbType.int:
352
379
  // datetime
@@ -359,17 +386,17 @@ class DdbObj {
359
386
  case DdbType.datehour: {
360
387
  const dv = new DataView(buf.buffer, buf.byteOffset);
361
388
  const value = dv.getInt32(0, le);
362
- return [4, value === exports.nulls.int32 ? null : value];
389
+ return [4, value === nulls.int32 ? null : value];
363
390
  }
364
391
  case DdbType.float: {
365
392
  const dv = new DataView(buf.buffer, buf.byteOffset);
366
393
  const value = dv.getFloat32(0, le);
367
- return [4, value === exports.nulls.float32 ? null : value];
394
+ return [4, value === nulls.float32 ? null : value];
368
395
  }
369
396
  case DdbType.double: {
370
397
  const dv = new DataView(buf.buffer, buf.byteOffset);
371
398
  const value = dv.getFloat64(0, le);
372
- return [8, value === exports.nulls.double ? null : value];
399
+ return [8, value === nulls.double ? null : value];
373
400
  }
374
401
  case DdbType.long:
375
402
  // timestamp
@@ -378,7 +405,7 @@ class DdbObj {
378
405
  case DdbType.nanotimestamp: {
379
406
  const dv = new DataView(buf.buffer, buf.byteOffset);
380
407
  const value = dv.getBigInt64(0, le);
381
- return [8, value === exports.nulls.int64 ? null : value];
408
+ return [8, value === nulls.int64 ? null : value];
382
409
  }
383
410
  case DdbType.string:
384
411
  case DdbType.symbol:
@@ -700,21 +727,21 @@ class DdbObj {
700
727
  case DdbType.bool:
701
728
  return [
702
729
  Int8Array.of(value === null ?
703
- exports.nulls.int8
730
+ nulls.int8
704
731
  :
705
732
  Number(value))
706
733
  ];
707
734
  case DdbType.char:
708
735
  return [
709
736
  Int8Array.of((value === null ?
710
- exports.nulls.int8
737
+ nulls.int8
711
738
  :
712
739
  value))
713
740
  ];
714
741
  case DdbType.short:
715
742
  return [
716
743
  Int16Array.of(value === null ?
717
- exports.nulls.int16
744
+ nulls.int16
718
745
  :
719
746
  value)
720
747
  ];
@@ -729,21 +756,21 @@ class DdbObj {
729
756
  case DdbType.datehour:
730
757
  return [
731
758
  Int32Array.of(value === null ?
732
- exports.nulls.int32
759
+ nulls.int32
733
760
  :
734
761
  value)
735
762
  ];
736
763
  case DdbType.float:
737
764
  return [
738
765
  Float32Array.of(value === null ?
739
- exports.nulls.float32
766
+ nulls.float32
740
767
  :
741
768
  value)
742
769
  ];
743
770
  case DdbType.double:
744
771
  return [
745
772
  Float64Array.of(value === null ?
746
- exports.nulls.double
773
+ nulls.double
747
774
  :
748
775
  value)
749
776
  ];
@@ -754,7 +781,7 @@ class DdbObj {
754
781
  case DdbType.nanotimestamp:
755
782
  return [
756
783
  BigInt64Array.of(value === null ?
757
- exports.nulls.int64
784
+ nulls.int64
758
785
  :
759
786
  value)
760
787
  ];
@@ -864,7 +891,7 @@ class DdbObj {
864
891
  })();
865
892
  if (!body)
866
893
  return new Uint8Array(0);
867
- return (0, utils_browser_js_1.concat)([
894
+ return concat([
868
895
  header,
869
896
  ...body
870
897
  ]);
@@ -1062,6 +1089,8 @@ class DdbObj {
1062
1089
  }
1063
1090
  }
1064
1091
  }
1092
+ case DdbForm.chart:
1093
+ return JSON.stringify(this.value, (key, value) => key === 'data' ? value.toString() : value, 4);
1065
1094
  }
1066
1095
  return String(this.value);
1067
1096
  })();
@@ -1116,7 +1145,7 @@ class DdbObj {
1116
1145
  switch (type) {
1117
1146
  case DdbType.bool: {
1118
1147
  const value = values[i];
1119
- row[name] = value === exports.nulls.int8 ?
1148
+ row[name] = value === nulls.int8 ?
1120
1149
  null
1121
1150
  :
1122
1151
  Boolean(value);
@@ -1157,24 +1186,15 @@ class DdbObj {
1157
1186
  return obj;
1158
1187
  }
1159
1188
  }
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) {
1189
+ export function format(type, value, le) {
1170
1190
  switch (type) {
1171
1191
  case DdbType.bool:
1172
- return String((value === null || value === exports.nulls.int8) ?
1192
+ return String((value === null || value === nulls.int8) ?
1173
1193
  null
1174
1194
  :
1175
1195
  Boolean(value));
1176
1196
  case DdbType.char:
1177
- return String((value === null || value === exports.nulls.int8) ?
1197
+ return String((value === null || value === nulls.int8) ?
1178
1198
  null
1179
1199
  :
1180
1200
  // ascii printable
@@ -1184,72 +1204,72 @@ function format(type, value, le) {
1184
1204
  :
1185
1205
  value);
1186
1206
  case DdbType.short:
1187
- return String((value === null || value === exports.nulls.int16) ?
1207
+ return String((value === null || value === nulls.int16) ?
1188
1208
  null
1189
1209
  :
1190
1210
  value);
1191
1211
  case DdbType.int:
1192
- return String((value === null || value === exports.nulls.int32) ?
1212
+ return String((value === null || value === nulls.int32) ?
1193
1213
  null
1194
1214
  :
1195
1215
  value);
1196
1216
  case DdbType.long:
1197
- return (value === null || value === exports.nulls.int64) ?
1217
+ return (value === null || value === nulls.int64) ?
1198
1218
  'null'
1199
1219
  :
1200
1220
  String(value);
1201
1221
  case DdbType.date:
1202
- return (value === null || value === exports.nulls.int32) ?
1222
+ return (value === null || value === nulls.int32) ?
1203
1223
  'null'
1204
1224
  :
1205
1225
  date2str(value);
1206
1226
  case DdbType.month:
1207
- return (value === null || value === exports.nulls.int32) ?
1227
+ return (value === null || value === nulls.int32) ?
1208
1228
  'null'
1209
1229
  :
1210
1230
  month2str(value);
1211
1231
  case DdbType.time:
1212
- return (value === null || value === exports.nulls.int32) ?
1232
+ return (value === null || value === nulls.int32) ?
1213
1233
  'null'
1214
1234
  :
1215
1235
  time2str(value);
1216
1236
  case DdbType.minute:
1217
- return (value === null || value === exports.nulls.int32) ?
1237
+ return (value === null || value === nulls.int32) ?
1218
1238
  'null'
1219
1239
  :
1220
1240
  minute2str(value);
1221
1241
  case DdbType.second:
1222
- return (value === null || value === exports.nulls.int32) ?
1242
+ return (value === null || value === nulls.int32) ?
1223
1243
  'null'
1224
1244
  :
1225
1245
  second2str(value);
1226
1246
  case DdbType.datetime:
1227
- return (value === null || value === exports.nulls.int32) ?
1247
+ return (value === null || value === nulls.int32) ?
1228
1248
  'null'
1229
1249
  :
1230
1250
  datetime2str(value);
1231
1251
  case DdbType.timestamp:
1232
- return (value === null || value === exports.nulls.int64) ?
1252
+ return (value === null || value === nulls.int64) ?
1233
1253
  'null'
1234
1254
  :
1235
1255
  timestamp2str(value);
1236
1256
  case DdbType.nanotime:
1237
- return (value === null || value === exports.nulls.int64) ?
1257
+ return (value === null || value === nulls.int64) ?
1238
1258
  'null'
1239
1259
  :
1240
1260
  nanotime2str(value);
1241
1261
  case DdbType.nanotimestamp:
1242
- return (value === null || value === exports.nulls.int64) ?
1262
+ return (value === null || value === nulls.int64) ?
1243
1263
  'null'
1244
1264
  :
1245
1265
  nanotimestamp2str(value);
1246
1266
  case DdbType.float:
1247
- return (value === null || value === exports.nulls.float32) ?
1267
+ return (value === null || value === nulls.float32) ?
1248
1268
  'null'
1249
1269
  :
1250
1270
  String(value);
1251
1271
  case DdbType.double:
1252
- return (value === null || value === exports.nulls.double) ?
1272
+ return (value === null || value === nulls.double) ?
1253
1273
  'null'
1254
1274
  :
1255
1275
  String(value);
@@ -1264,7 +1284,7 @@ function format(type, value, le) {
1264
1284
  case DdbType.code:
1265
1285
  return value.quote('single');
1266
1286
  case DdbType.datehour:
1267
- return (value === null || value === exports.nulls.int32) ?
1287
+ return (value === null || value === nulls.int32) ?
1268
1288
  'null'
1269
1289
  :
1270
1290
  datehour2str(value);
@@ -1279,17 +1299,17 @@ function format(type, value, le) {
1279
1299
  DdbObj.dec.decode(value)).quote('single');
1280
1300
  case DdbType.point: {
1281
1301
  let [x, y] = value;
1282
- if (x === exports.nulls.double)
1302
+ if (x === nulls.double)
1283
1303
  x = null;
1284
- if (y === exports.nulls.double)
1304
+ if (y === nulls.double)
1285
1305
  y = null;
1286
1306
  return `(${String(x)}, ${String(y)})`;
1287
1307
  }
1288
1308
  case DdbType.complex: {
1289
1309
  let [x, y] = value;
1290
- if (x === exports.nulls.double)
1310
+ if (x === nulls.double)
1291
1311
  x = null;
1292
- if (y === exports.nulls.double)
1312
+ if (y === nulls.double)
1293
1313
  y = null;
1294
1314
  return `${String(x)}+${String(y)}i`;
1295
1315
  }
@@ -1301,8 +1321,7 @@ function format(type, value, le) {
1301
1321
  return String(value);
1302
1322
  }
1303
1323
  }
1304
- exports.format = format;
1305
- class DdbVoid extends DdbObj {
1324
+ export class DdbVoid extends DdbObj {
1306
1325
  constructor() {
1307
1326
  super({
1308
1327
  form: DdbForm.scalar,
@@ -1311,8 +1330,7 @@ class DdbVoid extends DdbObj {
1311
1330
  });
1312
1331
  }
1313
1332
  }
1314
- exports.DdbVoid = DdbVoid;
1315
- class DdbBool extends DdbObj {
1333
+ export class DdbBool extends DdbObj {
1316
1334
  constructor(value) {
1317
1335
  super({
1318
1336
  form: DdbForm.scalar,
@@ -1321,8 +1339,7 @@ class DdbBool extends DdbObj {
1321
1339
  });
1322
1340
  }
1323
1341
  }
1324
- exports.DdbBool = DdbBool;
1325
- class DdbChar extends DdbObj {
1342
+ export class DdbChar extends DdbObj {
1326
1343
  constructor(value) {
1327
1344
  super({
1328
1345
  form: DdbForm.scalar,
@@ -1334,8 +1351,7 @@ class DdbChar extends DdbObj {
1334
1351
  });
1335
1352
  }
1336
1353
  }
1337
- exports.DdbChar = DdbChar;
1338
- class DdbInt extends DdbObj {
1354
+ export class DdbInt extends DdbObj {
1339
1355
  constructor(value) {
1340
1356
  super({
1341
1357
  form: DdbForm.scalar,
@@ -1344,8 +1360,7 @@ class DdbInt extends DdbObj {
1344
1360
  });
1345
1361
  }
1346
1362
  }
1347
- exports.DdbInt = DdbInt;
1348
- class DdbString extends DdbObj {
1363
+ export class DdbString extends DdbObj {
1349
1364
  constructor(value) {
1350
1365
  super({
1351
1366
  form: DdbForm.scalar,
@@ -1354,8 +1369,7 @@ class DdbString extends DdbObj {
1354
1369
  });
1355
1370
  }
1356
1371
  }
1357
- exports.DdbString = DdbString;
1358
- class DdbLong extends DdbObj {
1372
+ export class DdbLong extends DdbObj {
1359
1373
  constructor(value) {
1360
1374
  super({
1361
1375
  form: DdbForm.scalar,
@@ -1364,8 +1378,7 @@ class DdbLong extends DdbObj {
1364
1378
  });
1365
1379
  }
1366
1380
  }
1367
- exports.DdbLong = DdbLong;
1368
- class DdbDouble extends DdbObj {
1381
+ export class DdbDouble extends DdbObj {
1369
1382
  constructor(value) {
1370
1383
  super({
1371
1384
  form: DdbForm.scalar,
@@ -1374,8 +1387,7 @@ class DdbDouble extends DdbObj {
1374
1387
  });
1375
1388
  }
1376
1389
  }
1377
- exports.DdbDouble = DdbDouble;
1378
- class DdbDateTime extends DdbObj {
1390
+ export class DdbDateTime extends DdbObj {
1379
1391
  constructor(value) {
1380
1392
  super({
1381
1393
  form: DdbForm.scalar,
@@ -1384,8 +1396,7 @@ class DdbDateTime extends DdbObj {
1384
1396
  });
1385
1397
  }
1386
1398
  }
1387
- exports.DdbDateTime = DdbDateTime;
1388
- class DdbTimeStamp extends DdbObj {
1399
+ export class DdbTimeStamp extends DdbObj {
1389
1400
  constructor(value) {
1390
1401
  super({
1391
1402
  form: DdbForm.scalar,
@@ -1394,8 +1405,7 @@ class DdbTimeStamp extends DdbObj {
1394
1405
  });
1395
1406
  }
1396
1407
  }
1397
- exports.DdbTimeStamp = DdbTimeStamp;
1398
- class DdbNanoTimeStamp extends DdbObj {
1408
+ export class DdbNanoTimeStamp extends DdbObj {
1399
1409
  constructor(value) {
1400
1410
  super({
1401
1411
  form: DdbForm.scalar,
@@ -1404,20 +1414,18 @@ class DdbNanoTimeStamp extends DdbObj {
1404
1414
  });
1405
1415
  }
1406
1416
  }
1407
- exports.DdbNanoTimeStamp = DdbNanoTimeStamp;
1408
- class DdbPair extends DdbObj {
1417
+ export class DdbPair extends DdbObj {
1409
1418
  constructor(l, r = null) {
1410
1419
  super({
1411
1420
  form: DdbForm.pair,
1412
1421
  type: DdbType.int,
1413
1422
  rows: 2,
1414
1423
  cols: 1,
1415
- value: Int32Array.of(l === null ? exports.nulls.int32 : l, r === null ? exports.nulls.int32 : r)
1424
+ value: Int32Array.of(l === null ? nulls.int32 : l, r === null ? nulls.int32 : r)
1416
1425
  });
1417
1426
  }
1418
1427
  }
1419
- exports.DdbPair = DdbPair;
1420
- class DdbFunction extends DdbObj {
1428
+ export class DdbFunction extends DdbObj {
1421
1429
  constructor(name, type) {
1422
1430
  super({
1423
1431
  form: DdbForm.scalar,
@@ -1426,8 +1434,7 @@ class DdbFunction extends DdbObj {
1426
1434
  });
1427
1435
  }
1428
1436
  }
1429
- exports.DdbFunction = DdbFunction;
1430
- class DdbVectorInt extends DdbObj {
1437
+ export class DdbVectorInt extends DdbObj {
1431
1438
  constructor(ints, name) {
1432
1439
  super({
1433
1440
  form: DdbForm.vector,
@@ -1438,15 +1445,14 @@ class DdbVectorInt extends DdbObj {
1438
1445
  ints
1439
1446
  :
1440
1447
  Int32Array.from(ints, v => v === null ?
1441
- exports.nulls.int32
1448
+ nulls.int32
1442
1449
  :
1443
1450
  v),
1444
1451
  name,
1445
1452
  });
1446
1453
  }
1447
1454
  }
1448
- exports.DdbVectorInt = DdbVectorInt;
1449
- class DdbVectorDouble extends DdbObj {
1455
+ export class DdbVectorDouble extends DdbObj {
1450
1456
  constructor(doubles, name) {
1451
1457
  super({
1452
1458
  form: DdbForm.vector,
@@ -1457,15 +1463,14 @@ class DdbVectorDouble extends DdbObj {
1457
1463
  doubles
1458
1464
  :
1459
1465
  Float64Array.from(doubles, v => v === null ?
1460
- exports.nulls.double
1466
+ nulls.double
1461
1467
  :
1462
1468
  v),
1463
1469
  name,
1464
1470
  });
1465
1471
  }
1466
1472
  }
1467
- exports.DdbVectorDouble = DdbVectorDouble;
1468
- class DdbVectorString extends DdbObj {
1473
+ export class DdbVectorString extends DdbObj {
1469
1474
  constructor(strings, name) {
1470
1475
  super({
1471
1476
  form: DdbForm.vector,
@@ -1477,8 +1482,7 @@ class DdbVectorString extends DdbObj {
1477
1482
  });
1478
1483
  }
1479
1484
  }
1480
- exports.DdbVectorString = DdbVectorString;
1481
- class DdbVectorAny extends DdbObj {
1485
+ export class DdbVectorAny extends DdbObj {
1482
1486
  constructor(objs, name) {
1483
1487
  super({
1484
1488
  form: DdbForm.vector,
@@ -1490,8 +1494,7 @@ class DdbVectorAny extends DdbObj {
1490
1494
  });
1491
1495
  }
1492
1496
  }
1493
- exports.DdbVectorAny = DdbVectorAny;
1494
- class DdbVectorSymbol extends DdbObj {
1497
+ export class DdbVectorSymbol extends DdbObj {
1495
1498
  constructor(strings, name) {
1496
1499
  let map = new Map([
1497
1500
  ['', 0]
@@ -1520,8 +1523,7 @@ class DdbVectorSymbol extends DdbObj {
1520
1523
  });
1521
1524
  }
1522
1525
  }
1523
- exports.DdbVectorSymbol = DdbVectorSymbol;
1524
- class DdbSetInt extends DdbObj {
1526
+ export class DdbSetInt extends DdbObj {
1525
1527
  constructor(ints) {
1526
1528
  super({
1527
1529
  form: DdbForm.set,
@@ -1535,14 +1537,13 @@ class DdbSetInt extends DdbObj {
1535
1537
  ints
1536
1538
  :
1537
1539
  Int32Array.from(ints, v => v === null ?
1538
- exports.nulls.int32
1540
+ nulls.int32
1539
1541
  :
1540
1542
  v),
1541
1543
  });
1542
1544
  }
1543
1545
  }
1544
- exports.DdbSetInt = DdbSetInt;
1545
- class DdbSetDouble extends DdbObj {
1546
+ export class DdbSetDouble extends DdbObj {
1546
1547
  constructor(doubles) {
1547
1548
  super({
1548
1549
  form: DdbForm.set,
@@ -1556,14 +1557,13 @@ class DdbSetDouble extends DdbObj {
1556
1557
  doubles
1557
1558
  :
1558
1559
  Int32Array.from(doubles, v => v === null ?
1559
- exports.nulls.int32
1560
+ nulls.int32
1560
1561
  :
1561
1562
  v),
1562
1563
  });
1563
1564
  }
1564
1565
  }
1565
- exports.DdbSetDouble = DdbSetDouble;
1566
- class DdbSetString extends DdbObj {
1566
+ export class DdbSetString extends DdbObj {
1567
1567
  constructor(strings) {
1568
1568
  if (strings instanceof Set)
1569
1569
  strings = [...strings];
@@ -1576,12 +1576,11 @@ class DdbSetString extends DdbObj {
1576
1576
  });
1577
1577
  }
1578
1578
  }
1579
- exports.DdbSetString = DdbSetString;
1580
1579
  /** Constructs a DdbDict object, which supports two usages:
1581
1580
  - 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
1581
  - Pass in js object (type is Record<string, boolean | string | DdbObj>), automatically converted to DdbDict of dict<string, any>
1583
1582
  */
1584
- class DdbDict extends DdbObj {
1583
+ export class DdbDict extends DdbObj {
1585
1584
  constructor(arg0, arg1) {
1586
1585
  if (arg1)
1587
1586
  super({
@@ -1606,8 +1605,7 @@ class DdbDict extends DdbObj {
1606
1605
  }
1607
1606
  }
1608
1607
  }
1609
- exports.DdbDict = DdbDict;
1610
- class DdbTable extends DdbObj {
1608
+ export class DdbTable extends DdbObj {
1611
1609
  constructor(columns, name = '') {
1612
1610
  super({
1613
1611
  form: DdbForm.table,
@@ -1619,30 +1617,26 @@ class DdbTable extends DdbObj {
1619
1617
  });
1620
1618
  }
1621
1619
  }
1622
- exports.DdbTable = DdbTable;
1623
- function date2ms(date) {
1624
- return (date === null || date === exports.nulls.int32) ?
1620
+ export function date2ms(date) {
1621
+ return (date === null || date === nulls.int32) ?
1625
1622
  null
1626
1623
  :
1627
- exports.timezone_offset + 1000 * 3600 * 24 * date;
1624
+ timezone_offset + 1000 * 3600 * 24 * date;
1628
1625
  }
1629
- exports.date2ms = date2ms;
1630
- function date2str(date, format = 'YYYY.MM.DD') {
1631
- return (date === null || date === exports.nulls.int32) ?
1626
+ export function date2str(date, format = 'YYYY.MM.DD') {
1627
+ return (date === null || date === nulls.int32) ?
1632
1628
  null
1633
1629
  :
1634
- (0, dayjs_1.default)(date2ms(date)).format(format);
1630
+ dayjs(date2ms(date)).format(format);
1635
1631
  }
1636
- exports.date2str = date2str;
1637
- function month2ms(month) {
1638
- return (month === null || month === exports.nulls.int32) ?
1632
+ export function month2ms(month) {
1633
+ return (month === null || month === nulls.int32) ?
1639
1634
  null
1640
1635
  :
1641
- (0, dayjs_1.default)(month2str(month), 'YYYY.MM[M]').valueOf();
1636
+ dayjs(month2str(month), 'YYYY.MM[M]').valueOf();
1642
1637
  }
1643
- exports.month2ms = month2ms;
1644
- function month2str(month) {
1645
- if (month === null || month === exports.nulls.int32)
1638
+ export function month2str(month) {
1639
+ if (month === null || month === nulls.int32)
1646
1640
  return 'null';
1647
1641
  if (month < 0)
1648
1642
  return String(month);
@@ -1650,118 +1644,103 @@ function month2str(month) {
1650
1644
  const year = Math.trunc(month / 12);
1651
1645
  return `${String(year).padStart(4, '0')}.${String(_month + 1).padStart(2, '0')}M`;
1652
1646
  }
1653
- exports.month2str = month2str;
1654
- function time2ms(time) {
1655
- return (time === null || time === exports.nulls.int32) ?
1647
+ export function time2ms(time) {
1648
+ return (time === null || time === nulls.int32) ?
1656
1649
  null
1657
1650
  :
1658
- exports.timezone_offset + time;
1651
+ timezone_offset + time;
1659
1652
  }
1660
- exports.time2ms = time2ms;
1661
- function time2str(time, format = 'HH:mm:ss.SSS') {
1662
- return (time === null || time === exports.nulls.int32) ?
1653
+ export function time2str(time, format = 'HH:mm:ss.SSS') {
1654
+ return (time === null || time === nulls.int32) ?
1663
1655
  null
1664
1656
  :
1665
- (0, dayjs_1.default)(time2ms(time)).format(format);
1657
+ dayjs(time2ms(time)).format(format);
1666
1658
  }
1667
- exports.time2str = time2str;
1668
- function minute2ms(minute) {
1669
- return (minute === null || minute === exports.nulls.int32) ?
1659
+ export function minute2ms(minute) {
1660
+ return (minute === null || minute === nulls.int32) ?
1670
1661
  null
1671
1662
  :
1672
- exports.timezone_offset + 60 * 1000 * minute;
1663
+ timezone_offset + 60 * 1000 * minute;
1673
1664
  }
1674
- exports.minute2ms = minute2ms;
1675
- function minute2str(minute, format = 'HH:mm[m]') {
1676
- return (minute === null || minute === exports.nulls.int32) ?
1665
+ export function minute2str(minute, format = 'HH:mm[m]') {
1666
+ return (minute === null || minute === nulls.int32) ?
1677
1667
  'null'
1678
1668
  :
1679
- (0, dayjs_1.default)(minute2ms(minute)).format(format);
1669
+ dayjs(minute2ms(minute)).format(format);
1680
1670
  }
1681
- exports.minute2str = minute2str;
1682
- function second2ms(second) {
1683
- return (second === null || second === exports.nulls.int32) ?
1671
+ export function second2ms(second) {
1672
+ return (second === null || second === nulls.int32) ?
1684
1673
  null
1685
1674
  :
1686
- exports.timezone_offset + 1000 * second;
1675
+ timezone_offset + 1000 * second;
1687
1676
  }
1688
- exports.second2ms = second2ms;
1689
- function second2str(second, format = 'HH:mm:ss') {
1690
- return (second === null || second === exports.nulls.int32) ?
1677
+ export function second2str(second, format = 'HH:mm:ss') {
1678
+ return (second === null || second === nulls.int32) ?
1691
1679
  'null'
1692
1680
  :
1693
- (0, dayjs_1.default)(second2ms(second)).format(format);
1681
+ dayjs(second2ms(second)).format(format);
1694
1682
  }
1695
- exports.second2str = second2str;
1696
- function datetime2ms(datetime) {
1697
- return (datetime === null || datetime === exports.nulls.int32) ?
1683
+ export function datetime2ms(datetime) {
1684
+ return (datetime === null || datetime === nulls.int32) ?
1698
1685
  null
1699
1686
  :
1700
- exports.timezone_offset + 1000 * datetime;
1687
+ timezone_offset + 1000 * datetime;
1701
1688
  }
1702
- exports.datetime2ms = datetime2ms;
1703
- function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
1704
- return (datetime === null || datetime === exports.nulls.int32) ?
1689
+ export function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
1690
+ return (datetime === null || datetime === nulls.int32) ?
1705
1691
  'null'
1706
1692
  :
1707
- (0, dayjs_1.default)(datetime2ms(datetime)).format(format);
1693
+ dayjs(datetime2ms(datetime)).format(format);
1708
1694
  }
1709
- exports.datetime2str = datetime2str;
1710
- function timestamp2ms(timestamp) {
1711
- return (timestamp === null || timestamp === exports.nulls.int64) ?
1695
+ export function timestamp2ms(timestamp) {
1696
+ return (timestamp === null || timestamp === nulls.int64) ?
1712
1697
  null
1713
1698
  :
1714
- exports.timezone_offset + Number(timestamp);
1699
+ timezone_offset + Number(timestamp);
1715
1700
  }
1716
- exports.timestamp2ms = timestamp2ms;
1717
1701
  /** format timestamp (bigint) to string
1718
1702
  - timestamp: bigint value
1719
1703
  - format?:
1720
1704
  format string, default to `YYYY.MM.DD HH:mm:ss.SSS`
1721
1705
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1722
1706
  */
1723
- function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1724
- return (timestamp === null || timestamp === exports.nulls.int64) ?
1707
+ export function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1708
+ return (timestamp === null || timestamp === nulls.int64) ?
1725
1709
  'null'
1726
1710
  :
1727
- (0, dayjs_1.default)(timestamp2ms(timestamp)).format(format);
1711
+ dayjs(timestamp2ms(timestamp)).format(format);
1728
1712
  }
1729
- exports.timestamp2str = timestamp2str;
1730
- function datehour2ms(datehour) {
1731
- return (datehour === null || datehour === exports.nulls.int32) ?
1713
+ export function datehour2ms(datehour) {
1714
+ return (datehour === null || datehour === nulls.int32) ?
1732
1715
  null
1733
1716
  :
1734
- exports.timezone_offset + 1000 * 3600 * datehour;
1717
+ timezone_offset + 1000 * 3600 * datehour;
1735
1718
  }
1736
- exports.datehour2ms = datehour2ms;
1737
- function datehour2str(datehour, format = 'YYYY.MM.DDTHH') {
1738
- return (datehour === null || datehour === exports.nulls.int32) ?
1719
+ export function datehour2str(datehour, format = 'YYYY.MM.DDTHH') {
1720
+ return (datehour === null || datehour === nulls.int32) ?
1739
1721
  'null'
1740
1722
  :
1741
- (0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * datehour).format(format);
1723
+ dayjs(timezone_offset + 1000 * 3600 * datehour).format(format);
1742
1724
  }
1743
- exports.datehour2str = datehour2str;
1744
1725
  /** parse timestamp string to bigint value
1745
1726
  - str: timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
1746
1727
  - format?:
1747
1728
  The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
1748
1729
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1749
1730
  */
1750
- function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1731
+ export function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1751
1732
  if (!str || str === 'null')
1752
- return exports.nulls.int64;
1733
+ return nulls.int64;
1753
1734
  if (str.length !== format.length)
1754
1735
  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());
1736
+ return BigInt(-timezone_offset +
1737
+ dayjs(str, format).valueOf());
1757
1738
  }
1758
- exports.str2timestamp = str2timestamp;
1759
- function nanotime2ns(nanotime) {
1739
+ export function nanotime2ns(nanotime) {
1760
1740
  return nanotimestamp2ns(nanotime);
1761
1741
  }
1762
- exports.nanotime2ns = nanotime2ns;
1763
- function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
1764
- if (nanotime === null || nanotime === exports.nulls.int64)
1742
+ export function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
1743
+ if (nanotime === null || nanotime === nulls.int64)
1765
1744
  return 'null';
1766
1745
  if (nanotime < 0n)
1767
1746
  return String(nanotime);
@@ -1772,18 +1751,16 @@ function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
1772
1751
  const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
1773
1752
  if (i_nanosecond_start === -1)
1774
1753
  throw new Error('格式串必须包含纳秒的格式 (SSSSSSSSS)');
1775
- return ((0, dayjs_1.default)(exports.timezone_offset + (Number(nanotime) / 1000000)).format(format.slice(0, i_second_end)) +
1754
+ return (dayjs(timezone_offset + (Number(nanotime) / 1000000)).format(format.slice(0, i_second_end)) +
1776
1755
  format.slice(i_second_end, i_nanosecond_start) +
1777
1756
  String(nanotime % 1000000000n).padStart(9, '0'));
1778
1757
  }
1779
- exports.nanotime2str = nanotime2str;
1780
- function nanotimestamp2ns(nanotimestamp) {
1781
- return (nanotimestamp === null || nanotimestamp === exports.nulls.int64) ?
1758
+ export function nanotimestamp2ns(nanotimestamp) {
1759
+ return (nanotimestamp === null || nanotimestamp === nulls.int64) ?
1782
1760
  null
1783
1761
  :
1784
- BigInt(exports.timezone_offset) * 1000000n + nanotimestamp;
1762
+ BigInt(timezone_offset) * 1000000n + nanotimestamp;
1785
1763
  }
1786
- exports.nanotimestamp2ns = nanotimestamp2ns;
1787
1764
  /** format nanotimestamp value (bigint) to string
1788
1765
  - nanotimestamp: bigint value
1789
1766
  - format?:
@@ -1791,14 +1768,14 @@ exports.nanotimestamp2ns = nanotimestamp2ns;
1791
1768
  Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
1792
1769
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1793
1770
  */
1794
- function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1771
+ export function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1795
1772
  // tests:
1796
1773
  // nanotimestamp2str(0n)
1797
1774
  // nanotimestamp2str(-1n)
1798
1775
  // nanotimestamp2str(-9_9999_9999n)
1799
1776
  // nanotimestamp2str(-10_0000_0000n)
1800
1777
  // nanotimestamp2str(-10_0000_0001n)
1801
- if (nanotimestamp === null || nanotimestamp === exports.nulls.int64)
1778
+ if (nanotimestamp === null || nanotimestamp === nulls.int64)
1802
1779
  return 'null';
1803
1780
  const i_second_start = format.indexOf('ss');
1804
1781
  if (i_second_start === -1)
@@ -1809,7 +1786,7 @@ function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSS
1809
1786
  throw new Error('The format string must contain the format for nanoseconds (SSSSSSSSS)');
1810
1787
  const remainder = nanotimestamp % 1000000000n;
1811
1788
  const borrow = remainder < 0n;
1812
- return ((0, dayjs_1.default)(exports.timezone_offset +
1789
+ return (dayjs(timezone_offset +
1813
1790
  // 去掉 9 位的纳秒部分,转化为毫秒
1814
1791
  Number((nanotimestamp - remainder + (borrow ? -1000000000n : 0n)) / 1000000n)).format(format.slice(0, i_second_end)) +
1815
1792
  format.slice(i_second_end, i_nanosecond_start) +
@@ -1818,7 +1795,6 @@ function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSS
1818
1795
  :
1819
1796
  remainder).padStart(9, '0'));
1820
1797
  }
1821
- exports.nanotimestamp2str = nanotimestamp2str;
1822
1798
  /** parse nano timestamp string to bigint value
1823
1799
  - str: nano timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
1824
1800
  - format?:
@@ -1826,9 +1802,9 @@ exports.nanotimestamp2str = nanotimestamp2str;
1826
1802
  Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
1827
1803
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1828
1804
  */
1829
- function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1805
+ export function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1830
1806
  if (!str || str === 'null')
1831
- return exports.nulls.int64;
1807
+ return nulls.int64;
1832
1808
  if (str.length !== format.length)
1833
1809
  throw new Error('nanotimestamp string length is not equal to format string length');
1834
1810
  const i_second_start = format.indexOf('ss');
@@ -1838,13 +1814,12 @@ function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1838
1814
  const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
1839
1815
  if (i_nanosecond_start === -1)
1840
1816
  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
1817
+ return (BigInt(-timezone_offset +
1818
+ dayjs(str.slice(0, i_second_end), format.slice(0, i_second_end)).valueOf()) * 1000000n
1843
1819
  +
1844
1820
  BigInt(str.slice(i_nanosecond_start, i_nanosecond_start + 9)));
1845
1821
  }
1846
- exports.str2nanotimestamp = str2nanotimestamp;
1847
- function ipaddr2str(buffer, le = true, ipv6) {
1822
+ export function ipaddr2str(buffer, le = true, ipv6) {
1848
1823
  let buf = buffer;
1849
1824
  if (le)
1850
1825
  buf = buffer.slice().reverse();
@@ -1855,21 +1830,51 @@ function ipaddr2str(buffer, le = true, ipv6) {
1855
1830
  else // ipv4
1856
1831
  return buf.subarray(12).join('.');
1857
1832
  }
1858
- exports.ipaddr2str = ipaddr2str;
1859
- function uuid2str(buffer, le = true) {
1833
+ export function uuid2str(buffer, le = true) {
1860
1834
  const str = int1282str(buffer, le);
1861
1835
  return `${str.slice(0, 8)}-${str.slice(8, 12)}-${str.slice(12, 16)}-${str.slice(16, 20)}-${str.slice(20)}`;
1862
1836
  }
1863
- exports.uuid2str = uuid2str;
1864
- function int1282str(buffer, le = true) {
1837
+ export function int1282str(buffer, le = true) {
1865
1838
  let buf = buffer;
1866
1839
  if (le)
1867
1840
  buf = buffer.slice().reverse();
1868
1841
  return [...buf].map(x => x.toString(16)
1869
1842
  .padStart(2, '0')).join('');
1870
1843
  }
1871
- exports.int1282str = int1282str;
1872
- class DDB {
1844
+ export class DDB {
1845
+ /** 当前的 session id (http 或 tcp) */
1846
+ sid = '0';
1847
+ /** utf-8 text decoder */
1848
+ dec = new TextDecoder('utf-8');
1849
+ enc = new TextEncoder();
1850
+ /** DolphinDB WebSocket URL
1851
+ e.g. `ws://127.0.0.1:8848/`, `wss://dolphindb.com`
1852
+ */
1853
+ url;
1854
+ websocket = null;
1855
+ /** little endian (server) */
1856
+ le = true;
1857
+ /** little endian (client) */
1858
+ static le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
1859
+ /** Whether to automatically log in after the connection is established, the default is true */
1860
+ autologin = true;
1861
+ /** DolphinDB username */
1862
+ username = 'admin';
1863
+ /** DolphinDB password */
1864
+ password = '123456';
1865
+ /** python session flag (2048) */
1866
+ python = false;
1867
+ print_message_buffer = false;
1868
+ print_object_buffer = false;
1869
+ print_message = true;
1870
+ parse_object = true;
1871
+ /** DdbMessage listeners */
1872
+ listeners = [];
1873
+ pconnect = Promise.resolve();
1874
+ presult = Promise.resolve(null);
1875
+ get connected() {
1876
+ return this.websocket?.readyState === WebSocket.OPEN;
1877
+ }
1873
1878
  /**
1874
1879
  Initialize an instance of DolphinDB Client using the WebSocket URL
1875
1880
  (without establishing an actual network connection)
@@ -1892,30 +1897,6 @@ class DDB {
1892
1897
  })
1893
1898
  */
1894
1899
  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.pconnect = Promise.resolve();
1918
- this.presult = Promise.resolve(null);
1919
1900
  if (!url) {
1920
1901
  const _url = new URL(location.href);
1921
1902
  const hostname = _url.searchParams.get('hostname') || location.hostname;
@@ -1932,9 +1913,6 @@ class DDB {
1932
1913
  if (options.python !== undefined)
1933
1914
  this.python = options.python;
1934
1915
  }
1935
- get connected() {
1936
- return this.websocket?.readyState === WebSocket.OPEN;
1937
- }
1938
1916
  on_message(event) { }
1939
1917
  /** Establish the actual WebSocket connection to the DolphinDB corresponding to the URL
1940
1918
  - options?:
@@ -1956,7 +1934,7 @@ class DDB {
1956
1934
  if (options.python !== undefined)
1957
1935
  this.python = options.python;
1958
1936
  this.disconnect();
1959
- await (0, net_browser_js_1.connect_websocket)(this.url, {
1937
+ await connect_websocket(this.url, {
1960
1938
  protocols: this.python ? ['python'] : [],
1961
1939
  on_open: async (event, websocket) => {
1962
1940
  this.websocket = websocket;
@@ -2138,7 +2116,7 @@ class DDB {
2138
2116
  return 'connect\n';
2139
2117
  }
2140
2118
  })());
2141
- this.websocket.send((0, utils_browser_js_1.concat)([
2119
+ this.websocket.send(concat([
2142
2120
  this.enc.encode(`API2 ${this.sid} ${command.length} / ${this.get_rpc_options({ urgent })}\n`),
2143
2121
  command,
2144
2122
  ...args.map((arg) => arg.pack())
@@ -2268,8 +2246,5 @@ class DDB {
2268
2246
  };
2269
2247
  }
2270
2248
  }
2271
- exports.DDB = DDB;
2272
- /** little endian (client) */
2273
- DDB.le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
2274
- exports.ddb = window.ddb = new DDB();
2249
+ export let ddb = window.ddb = new DDB();
2275
2250
  //# sourceMappingURL=browser.js.map