dolphindb 2.0.518 → 2.0.521
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser.d.ts +77 -19
- package/browser.js +207 -66
- package/browser.js.map +1 -1
- package/index.d.ts +72 -14
- package/index.js +204 -63
- package/index.js.map +1 -1
- package/package.json +6 -6
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.nanotime2str = exports.nanotime2ns = exports.str2timestamp = exports.datehour2str = exports.datehour2ms = exports.timestamp2str = exports.timestamp2ms = exports.datetime2str = exports.datetime2ms = exports.second2str = exports.second2ms = exports.minute2str = exports.minute2ms = exports.time2str = exports.time2ms = exports.month2str = exports.month2ms = exports.date2str = exports.date2ms = exports.DdbTable = exports.DdbDict = exports.DdbSetString = exports.DdbSetDouble = exports.DdbSetInt = exports.DdbVectorSymbol = exports.DdbVectorAny = exports.DdbVectorString = exports.DdbVectorDouble = exports.DdbVectorInt = exports.DdbFunction = exports.DdbPair = exports.DdbNanoTimeStamp = exports.DdbTimeStamp = exports.DdbDateTime = exports.DdbDouble = exports.DdbLong = exports.DdbString = exports.DdbInt = exports.DdbChar = exports.DdbBool = exports.DdbVoid = exports.format = exports.DdbObj = exports.timezone_offset = exports.nulls = exports.DdbChartType = exports.DdbDurationUnit = exports.DdbFunctionType = exports.DdbType = exports.DdbForm = void 0;
|
|
4
|
+
exports.DDB = exports.int1282str = exports.uuid2str = exports.ipaddr2str = exports.str2nanotimestamp = exports.nanotimestamp2str = exports.nanotimestamp2ns = void 0;
|
|
4
5
|
const tslib_1 = require("tslib");
|
|
5
6
|
const ws_1 = require("ws");
|
|
6
7
|
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
@@ -20,6 +21,7 @@ var DdbForm;
|
|
|
20
21
|
DdbForm[DdbForm["dict"] = 5] = "dict";
|
|
21
22
|
DdbForm[DdbForm["table"] = 6] = "table";
|
|
22
23
|
DdbForm[DdbForm["chart"] = 7] = "chart";
|
|
24
|
+
/** Node internal communication may be used, calling function execution script generally does not return this type */
|
|
23
25
|
DdbForm[DdbForm["chunk"] = 8] = "chunk";
|
|
24
26
|
/** sysobj */
|
|
25
27
|
DdbForm[DdbForm["object"] = 9] = "object";
|
|
@@ -94,6 +96,19 @@ var DdbDurationUnit;
|
|
|
94
96
|
DdbDurationUnit[DdbDurationUnit["y"] = 9] = "y";
|
|
95
97
|
DdbDurationUnit[DdbDurationUnit["B"] = 10] = "B";
|
|
96
98
|
})(DdbDurationUnit = exports.DdbDurationUnit || (exports.DdbDurationUnit = {}));
|
|
99
|
+
var DdbChartType;
|
|
100
|
+
(function (DdbChartType) {
|
|
101
|
+
DdbChartType[DdbChartType["area"] = 0] = "area";
|
|
102
|
+
DdbChartType[DdbChartType["bar"] = 1] = "bar";
|
|
103
|
+
DdbChartType[DdbChartType["column"] = 2] = "column";
|
|
104
|
+
DdbChartType[DdbChartType["histogram"] = 3] = "histogram";
|
|
105
|
+
DdbChartType[DdbChartType["line"] = 4] = "line";
|
|
106
|
+
DdbChartType[DdbChartType["pie"] = 5] = "pie";
|
|
107
|
+
DdbChartType[DdbChartType["scatter"] = 6] = "scatter";
|
|
108
|
+
DdbChartType[DdbChartType["trend"] = 7] = "trend";
|
|
109
|
+
DdbChartType[DdbChartType["kline"] = 8] = "kline";
|
|
110
|
+
DdbChartType[DdbChartType["stack"] = 9] = "stack";
|
|
111
|
+
})(DdbChartType = exports.DdbChartType || (exports.DdbChartType = {}));
|
|
97
112
|
exports.nulls = {
|
|
98
113
|
int8: -0x80,
|
|
99
114
|
int16: -32768,
|
|
@@ -198,7 +213,8 @@ class DdbObj {
|
|
|
198
213
|
value,
|
|
199
214
|
});
|
|
200
215
|
}
|
|
201
|
-
case DdbForm.dict:
|
|
216
|
+
case DdbForm.dict:
|
|
217
|
+
case DdbForm.chart: {
|
|
202
218
|
// <Buffer 19 05 type = any, form = dict
|
|
203
219
|
// 12 01 keys.type = string, keys.form = vector
|
|
204
220
|
// 03 00 00 00 01 00 00 00 keys.cols = 3, keys.rows = 1
|
|
@@ -210,9 +226,9 @@ class DdbObj {
|
|
|
210
226
|
keys.length += 2;
|
|
211
227
|
let values = this.parse_vector(buf_data.subarray(keys.length + 2), le, buf_data[keys.length]);
|
|
212
228
|
values.length += 2;
|
|
213
|
-
|
|
229
|
+
let dict = new this({
|
|
214
230
|
le,
|
|
215
|
-
form,
|
|
231
|
+
form: DdbForm.dict,
|
|
216
232
|
type,
|
|
217
233
|
length: i_data + keys.length + values.length,
|
|
218
234
|
rows: keys.rows,
|
|
@@ -222,6 +238,30 @@ class DdbObj {
|
|
|
222
238
|
values
|
|
223
239
|
],
|
|
224
240
|
});
|
|
241
|
+
if (form === DdbForm.dict)
|
|
242
|
+
return dict;
|
|
243
|
+
else {
|
|
244
|
+
const { chartType: type, stacking, title: titles, extras, data, ...others } = dict.to_dict();
|
|
245
|
+
const [chart, x_axis, y_axis] = titles.value;
|
|
246
|
+
const { multiYAxes: multi_y_axis, ...extras_others } = extras.to_dict({ strip: true });
|
|
247
|
+
dict.form = DdbForm.chart;
|
|
248
|
+
dict.value = {
|
|
249
|
+
type: type.value,
|
|
250
|
+
stacking: stacking.value,
|
|
251
|
+
titles: {
|
|
252
|
+
chart,
|
|
253
|
+
x_axis,
|
|
254
|
+
y_axis,
|
|
255
|
+
},
|
|
256
|
+
extras: {
|
|
257
|
+
multi_y_axis,
|
|
258
|
+
...extras_others,
|
|
259
|
+
},
|
|
260
|
+
data,
|
|
261
|
+
...others,
|
|
262
|
+
};
|
|
263
|
+
return dict;
|
|
264
|
+
}
|
|
225
265
|
}
|
|
226
266
|
case DdbForm.matrix: {
|
|
227
267
|
// rename!(
|
|
@@ -791,6 +831,23 @@ class DdbObj {
|
|
|
791
831
|
value[0].pack(),
|
|
792
832
|
value[1].pack(),
|
|
793
833
|
];
|
|
834
|
+
case DdbForm.chart: {
|
|
835
|
+
const { type, stacking, titles: { chart, x_axis, y_axis, }, extras: { multi_y_axis, ...extras_other }, data } = this.value;
|
|
836
|
+
const { value: [keys, values] } = new DdbDict({
|
|
837
|
+
chartType: new DdbInt(type),
|
|
838
|
+
stacking,
|
|
839
|
+
title: new DdbVectorString([chart, x_axis, y_axis]),
|
|
840
|
+
extras: new DdbDict({
|
|
841
|
+
multiYAxis: multi_y_axis,
|
|
842
|
+
...extras_other
|
|
843
|
+
}),
|
|
844
|
+
data,
|
|
845
|
+
});
|
|
846
|
+
return [
|
|
847
|
+
keys.pack(),
|
|
848
|
+
values.pack(),
|
|
849
|
+
];
|
|
850
|
+
}
|
|
794
851
|
case DdbForm.matrix: {
|
|
795
852
|
const { rows, cols, data } = value;
|
|
796
853
|
return [
|
|
@@ -916,6 +973,8 @@ class DdbObj {
|
|
|
916
973
|
return `table[${this.rows}r][${this.cols}c]`;
|
|
917
974
|
case DdbForm.dict:
|
|
918
975
|
return `dict<${DdbType[this.value[0].type]}, ${DdbType[this.value[1].type]}>`;
|
|
976
|
+
case DdbForm.chart:
|
|
977
|
+
return `chart<${DdbChartType[this.value.type]}>`;
|
|
919
978
|
case DdbForm.matrix:
|
|
920
979
|
return `matrix<${tname}>[${this.rows}r][${this.cols}c]`;
|
|
921
980
|
default:
|
|
@@ -1011,9 +1070,27 @@ class DdbObj {
|
|
|
1011
1070
|
})();
|
|
1012
1071
|
return `${options.colors ? type.blue : type}(${this.name ? `${(0, utils_js_1.inspect)(this.name, options)}, ` : ''}${data})`;
|
|
1013
1072
|
}
|
|
1073
|
+
/** 自动转换 js string, boolean 为 DdbObj */
|
|
1074
|
+
static to_ddbobj(value) {
|
|
1075
|
+
if (value && value instanceof DdbObj)
|
|
1076
|
+
return value;
|
|
1077
|
+
const type = typeof value;
|
|
1078
|
+
switch (type) {
|
|
1079
|
+
case 'string':
|
|
1080
|
+
return new DdbString(value);
|
|
1081
|
+
case 'boolean':
|
|
1082
|
+
return new DdbBool(value);
|
|
1083
|
+
default:
|
|
1084
|
+
throw new Error(`Cannot automatically convert ${type} to DdbObj`);
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
/** 转换 js 数组为 DdbObj[] */
|
|
1088
|
+
static to_ddbobjs(values) {
|
|
1089
|
+
return values.map(value => this.to_ddbobj(value));
|
|
1090
|
+
}
|
|
1014
1091
|
to_rows() {
|
|
1015
1092
|
if (this.form !== DdbForm.table)
|
|
1016
|
-
throw new Error('this.form
|
|
1093
|
+
throw new Error('this.form is not DdbForm.table, cannot to_rows');
|
|
1017
1094
|
let rows = new Array(this.rows);
|
|
1018
1095
|
for (let i = 0; i < this.rows; i++) {
|
|
1019
1096
|
let row = {};
|
|
@@ -1044,13 +1121,22 @@ class DdbObj {
|
|
|
1044
1121
|
}
|
|
1045
1122
|
return rows;
|
|
1046
1123
|
}
|
|
1047
|
-
to_dict() {
|
|
1124
|
+
to_dict({ strip, deep, } = {}) {
|
|
1048
1125
|
if (this.form !== DdbForm.dict)
|
|
1049
|
-
throw new Error('this.form
|
|
1050
|
-
const [{ value: keys }, { value: values }] = this.value;
|
|
1126
|
+
throw new Error('this.form is not DdbForm.dict and cannot be converted to js object');
|
|
1127
|
+
const [{ value: keys, type: key_type }, { value: values, type: value_type }] = this.value;
|
|
1128
|
+
if (key_type !== DdbType.string || value_type !== DdbType.any)
|
|
1129
|
+
throw new Error('Not dict<string, any>, automatic conversion to js object is not supported for the time being');
|
|
1130
|
+
if (deep && !strip)
|
|
1131
|
+
throw new Error('strip = true must be set when deep = true');
|
|
1051
1132
|
let obj = {};
|
|
1052
|
-
for (let i = 0; i < this.rows; i++)
|
|
1053
|
-
|
|
1133
|
+
for (let i = 0; i < this.rows; i++) {
|
|
1134
|
+
let value = values[i];
|
|
1135
|
+
if (deep && value.form === DdbForm.dict)
|
|
1136
|
+
obj[keys[i]] = value.to_dict({ strip, deep });
|
|
1137
|
+
else
|
|
1138
|
+
obj[keys[i]] = strip ? value.value : value;
|
|
1139
|
+
}
|
|
1054
1140
|
return obj;
|
|
1055
1141
|
}
|
|
1056
1142
|
}
|
|
@@ -1253,7 +1339,6 @@ class DdbVoid extends DdbObj {
|
|
|
1253
1339
|
super({
|
|
1254
1340
|
form: DdbForm.scalar,
|
|
1255
1341
|
type: DdbType.void,
|
|
1256
|
-
length: 0,
|
|
1257
1342
|
value: null,
|
|
1258
1343
|
});
|
|
1259
1344
|
}
|
|
@@ -1264,7 +1349,6 @@ class DdbBool extends DdbObj {
|
|
|
1264
1349
|
super({
|
|
1265
1350
|
form: DdbForm.scalar,
|
|
1266
1351
|
type: DdbType.bool,
|
|
1267
|
-
length: 1,
|
|
1268
1352
|
value,
|
|
1269
1353
|
});
|
|
1270
1354
|
}
|
|
@@ -1275,7 +1359,6 @@ class DdbChar extends DdbObj {
|
|
|
1275
1359
|
super({
|
|
1276
1360
|
form: DdbForm.scalar,
|
|
1277
1361
|
type: DdbType.char,
|
|
1278
|
-
length: 1,
|
|
1279
1362
|
value: typeof value === 'string' ?
|
|
1280
1363
|
value.charCodeAt(0)
|
|
1281
1364
|
:
|
|
@@ -1289,7 +1372,6 @@ class DdbInt extends DdbObj {
|
|
|
1289
1372
|
super({
|
|
1290
1373
|
form: DdbForm.scalar,
|
|
1291
1374
|
type: DdbType.int,
|
|
1292
|
-
length: 4,
|
|
1293
1375
|
value,
|
|
1294
1376
|
});
|
|
1295
1377
|
}
|
|
@@ -1300,7 +1382,6 @@ class DdbString extends DdbObj {
|
|
|
1300
1382
|
super({
|
|
1301
1383
|
form: DdbForm.scalar,
|
|
1302
1384
|
type: DdbType.string,
|
|
1303
|
-
length: 0,
|
|
1304
1385
|
value
|
|
1305
1386
|
});
|
|
1306
1387
|
}
|
|
@@ -1311,7 +1392,6 @@ class DdbLong extends DdbObj {
|
|
|
1311
1392
|
super({
|
|
1312
1393
|
form: DdbForm.scalar,
|
|
1313
1394
|
type: DdbType.long,
|
|
1314
|
-
length: 8,
|
|
1315
1395
|
value
|
|
1316
1396
|
});
|
|
1317
1397
|
}
|
|
@@ -1322,7 +1402,6 @@ class DdbDouble extends DdbObj {
|
|
|
1322
1402
|
super({
|
|
1323
1403
|
form: DdbForm.scalar,
|
|
1324
1404
|
type: DdbType.double,
|
|
1325
|
-
length: 8,
|
|
1326
1405
|
value
|
|
1327
1406
|
});
|
|
1328
1407
|
}
|
|
@@ -1333,7 +1412,6 @@ class DdbDateTime extends DdbObj {
|
|
|
1333
1412
|
super({
|
|
1334
1413
|
form: DdbForm.scalar,
|
|
1335
1414
|
type: DdbType.datetime,
|
|
1336
|
-
length: 4,
|
|
1337
1415
|
value
|
|
1338
1416
|
});
|
|
1339
1417
|
}
|
|
@@ -1344,7 +1422,6 @@ class DdbTimeStamp extends DdbObj {
|
|
|
1344
1422
|
super({
|
|
1345
1423
|
form: DdbForm.scalar,
|
|
1346
1424
|
type: DdbType.timestamp,
|
|
1347
|
-
length: 8,
|
|
1348
1425
|
value
|
|
1349
1426
|
});
|
|
1350
1427
|
}
|
|
@@ -1355,7 +1432,6 @@ class DdbNanoTimeStamp extends DdbObj {
|
|
|
1355
1432
|
super({
|
|
1356
1433
|
form: DdbForm.scalar,
|
|
1357
1434
|
type: DdbType.nanotimestamp,
|
|
1358
|
-
length: 8,
|
|
1359
1435
|
value
|
|
1360
1436
|
});
|
|
1361
1437
|
}
|
|
@@ -1366,7 +1442,6 @@ class DdbPair extends DdbObj {
|
|
|
1366
1442
|
super({
|
|
1367
1443
|
form: DdbForm.pair,
|
|
1368
1444
|
type: DdbType.int,
|
|
1369
|
-
length: 0,
|
|
1370
1445
|
rows: 2,
|
|
1371
1446
|
cols: 1,
|
|
1372
1447
|
value: Int32Array.of(l === null ? exports.nulls.int32 : l, r === null ? exports.nulls.int32 : r)
|
|
@@ -1379,7 +1454,6 @@ class DdbFunction extends DdbObj {
|
|
|
1379
1454
|
super({
|
|
1380
1455
|
form: DdbForm.scalar,
|
|
1381
1456
|
type: DdbType.functiondef,
|
|
1382
|
-
length: 0,
|
|
1383
1457
|
value: { type, name }
|
|
1384
1458
|
});
|
|
1385
1459
|
}
|
|
@@ -1390,7 +1464,6 @@ class DdbVectorInt extends DdbObj {
|
|
|
1390
1464
|
super({
|
|
1391
1465
|
form: DdbForm.vector,
|
|
1392
1466
|
type: DdbType.int,
|
|
1393
|
-
length: 0,
|
|
1394
1467
|
rows: ints.length,
|
|
1395
1468
|
cols: 1,
|
|
1396
1469
|
value: ints instanceof Int32Array ?
|
|
@@ -1410,7 +1483,6 @@ class DdbVectorDouble extends DdbObj {
|
|
|
1410
1483
|
super({
|
|
1411
1484
|
form: DdbForm.vector,
|
|
1412
1485
|
type: DdbType.double,
|
|
1413
|
-
length: 0,
|
|
1414
1486
|
rows: doubles.length,
|
|
1415
1487
|
cols: 1,
|
|
1416
1488
|
value: doubles instanceof Float64Array ?
|
|
@@ -1430,7 +1502,6 @@ class DdbVectorString extends DdbObj {
|
|
|
1430
1502
|
super({
|
|
1431
1503
|
form: DdbForm.vector,
|
|
1432
1504
|
type: DdbType.string,
|
|
1433
|
-
length: 0,
|
|
1434
1505
|
rows: strings.length,
|
|
1435
1506
|
cols: 1,
|
|
1436
1507
|
value: strings,
|
|
@@ -1444,10 +1515,9 @@ class DdbVectorAny extends DdbObj {
|
|
|
1444
1515
|
super({
|
|
1445
1516
|
form: DdbForm.vector,
|
|
1446
1517
|
type: DdbType.any,
|
|
1447
|
-
length: 0,
|
|
1448
1518
|
rows: objs.length,
|
|
1449
1519
|
cols: 1,
|
|
1450
|
-
value: objs,
|
|
1520
|
+
value: DdbObj.to_ddbobjs(objs),
|
|
1451
1521
|
name,
|
|
1452
1522
|
});
|
|
1453
1523
|
}
|
|
@@ -1471,7 +1541,6 @@ class DdbVectorSymbol extends DdbObj {
|
|
|
1471
1541
|
super({
|
|
1472
1542
|
form: DdbForm.vector,
|
|
1473
1543
|
type: DdbType.symbol_extended,
|
|
1474
|
-
length: 0,
|
|
1475
1544
|
rows: strings.length,
|
|
1476
1545
|
cols: 1,
|
|
1477
1546
|
value: {
|
|
@@ -1489,7 +1558,6 @@ class DdbSetInt extends DdbObj {
|
|
|
1489
1558
|
super({
|
|
1490
1559
|
form: DdbForm.set,
|
|
1491
1560
|
type: DdbType.int,
|
|
1492
|
-
length: 0,
|
|
1493
1561
|
rows: ints instanceof Set ?
|
|
1494
1562
|
ints.size
|
|
1495
1563
|
:
|
|
@@ -1511,7 +1579,6 @@ class DdbSetDouble extends DdbObj {
|
|
|
1511
1579
|
super({
|
|
1512
1580
|
form: DdbForm.set,
|
|
1513
1581
|
type: DdbType.double,
|
|
1514
|
-
length: 0,
|
|
1515
1582
|
rows: doubles instanceof Set ?
|
|
1516
1583
|
doubles.size
|
|
1517
1584
|
:
|
|
@@ -1535,7 +1602,6 @@ class DdbSetString extends DdbObj {
|
|
|
1535
1602
|
super({
|
|
1536
1603
|
form: DdbForm.set,
|
|
1537
1604
|
type: DdbType.string,
|
|
1538
|
-
length: 0,
|
|
1539
1605
|
rows: strings.length,
|
|
1540
1606
|
cols: 1,
|
|
1541
1607
|
value: strings
|
|
@@ -1543,12 +1609,41 @@ class DdbSetString extends DdbObj {
|
|
|
1543
1609
|
}
|
|
1544
1610
|
}
|
|
1545
1611
|
exports.DdbSetString = DdbSetString;
|
|
1612
|
+
/** Constructs a DdbDict object, which supports two usages:
|
|
1613
|
+
- 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>
|
|
1614
|
+
- Pass in js object (type is Record<string, boolean | string | DdbObj>), automatically converted to DdbDict of dict<string, any>
|
|
1615
|
+
*/
|
|
1616
|
+
class DdbDict extends DdbObj {
|
|
1617
|
+
constructor(arg0, arg1) {
|
|
1618
|
+
if (arg1)
|
|
1619
|
+
super({
|
|
1620
|
+
form: DdbForm.dict,
|
|
1621
|
+
type: arg1.type,
|
|
1622
|
+
rows: arg0.rows,
|
|
1623
|
+
cols: 2,
|
|
1624
|
+
value: [arg0, arg1]
|
|
1625
|
+
});
|
|
1626
|
+
else {
|
|
1627
|
+
const keys = Object.keys(arg0);
|
|
1628
|
+
super({
|
|
1629
|
+
form: DdbForm.dict,
|
|
1630
|
+
type: DdbType.any,
|
|
1631
|
+
rows: keys.length,
|
|
1632
|
+
cols: 2,
|
|
1633
|
+
value: [
|
|
1634
|
+
new DdbVectorString(keys),
|
|
1635
|
+
new DdbVectorAny(Object.values(arg0))
|
|
1636
|
+
]
|
|
1637
|
+
});
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
exports.DdbDict = DdbDict;
|
|
1546
1642
|
class DdbTable extends DdbObj {
|
|
1547
1643
|
constructor(columns, name = '') {
|
|
1548
1644
|
super({
|
|
1549
1645
|
form: DdbForm.table,
|
|
1550
1646
|
type: DdbType.void,
|
|
1551
|
-
length: 0,
|
|
1552
1647
|
rows: columns[0].rows,
|
|
1553
1648
|
cols: columns.length,
|
|
1554
1649
|
name,
|
|
@@ -1557,13 +1652,27 @@ class DdbTable extends DdbObj {
|
|
|
1557
1652
|
}
|
|
1558
1653
|
}
|
|
1559
1654
|
exports.DdbTable = DdbTable;
|
|
1655
|
+
function date2ms(date) {
|
|
1656
|
+
return (date === null || date === exports.nulls.int32) ?
|
|
1657
|
+
null
|
|
1658
|
+
:
|
|
1659
|
+
exports.timezone_offset + 1000 * 3600 * 24 * date;
|
|
1660
|
+
}
|
|
1661
|
+
exports.date2ms = date2ms;
|
|
1560
1662
|
function date2str(date, format = 'YYYY.MM.DD') {
|
|
1561
1663
|
return (date === null || date === exports.nulls.int32) ?
|
|
1562
|
-
|
|
1664
|
+
null
|
|
1563
1665
|
:
|
|
1564
|
-
(0, dayjs_1.default)(
|
|
1666
|
+
(0, dayjs_1.default)(date2ms(date)).format(format);
|
|
1565
1667
|
}
|
|
1566
1668
|
exports.date2str = date2str;
|
|
1669
|
+
function month2ms(month) {
|
|
1670
|
+
return (month === null || month === exports.nulls.int32) ?
|
|
1671
|
+
null
|
|
1672
|
+
:
|
|
1673
|
+
(0, dayjs_1.default)(month2str(month), 'YYYY.MM[M]').valueOf();
|
|
1674
|
+
}
|
|
1675
|
+
exports.month2ms = month2ms;
|
|
1567
1676
|
function month2str(month) {
|
|
1568
1677
|
if (month === null || month === exports.nulls.int32)
|
|
1569
1678
|
return 'null';
|
|
@@ -1574,37 +1683,69 @@ function month2str(month) {
|
|
|
1574
1683
|
return `${String(year).padStart(4, '0')}.${String(_month + 1).padStart(2, '0')}M`;
|
|
1575
1684
|
}
|
|
1576
1685
|
exports.month2str = month2str;
|
|
1686
|
+
function time2ms(time) {
|
|
1687
|
+
return (time === null || time === exports.nulls.int32) ?
|
|
1688
|
+
null
|
|
1689
|
+
:
|
|
1690
|
+
exports.timezone_offset + time;
|
|
1691
|
+
}
|
|
1692
|
+
exports.time2ms = time2ms;
|
|
1577
1693
|
function time2str(time, format = 'HH:mm:ss.SSS') {
|
|
1578
1694
|
return (time === null || time === exports.nulls.int32) ?
|
|
1579
|
-
|
|
1695
|
+
null
|
|
1580
1696
|
:
|
|
1581
|
-
(0, dayjs_1.default)(
|
|
1582
|
-
.format(format);
|
|
1697
|
+
(0, dayjs_1.default)(time2ms(time)).format(format);
|
|
1583
1698
|
}
|
|
1584
1699
|
exports.time2str = time2str;
|
|
1700
|
+
function minute2ms(minute) {
|
|
1701
|
+
return (minute === null || minute === exports.nulls.int32) ?
|
|
1702
|
+
null
|
|
1703
|
+
:
|
|
1704
|
+
exports.timezone_offset + 60 * 1000 * minute;
|
|
1705
|
+
}
|
|
1706
|
+
exports.minute2ms = minute2ms;
|
|
1585
1707
|
function minute2str(minute, format = 'HH:mm[m]') {
|
|
1586
1708
|
return (minute === null || minute === exports.nulls.int32) ?
|
|
1587
1709
|
'null'
|
|
1588
1710
|
:
|
|
1589
|
-
(0, dayjs_1.default)(
|
|
1590
|
-
.format(format);
|
|
1711
|
+
(0, dayjs_1.default)(minute2ms(minute)).format(format);
|
|
1591
1712
|
}
|
|
1592
1713
|
exports.minute2str = minute2str;
|
|
1714
|
+
function second2ms(second) {
|
|
1715
|
+
return (second === null || second === exports.nulls.int32) ?
|
|
1716
|
+
null
|
|
1717
|
+
:
|
|
1718
|
+
exports.timezone_offset + 1000 * second;
|
|
1719
|
+
}
|
|
1720
|
+
exports.second2ms = second2ms;
|
|
1593
1721
|
function second2str(second, format = 'HH:mm:ss') {
|
|
1594
1722
|
return (second === null || second === exports.nulls.int32) ?
|
|
1595
1723
|
'null'
|
|
1596
1724
|
:
|
|
1597
|
-
(0, dayjs_1.default)(
|
|
1598
|
-
.format(format);
|
|
1725
|
+
(0, dayjs_1.default)(second2ms(second)).format(format);
|
|
1599
1726
|
}
|
|
1600
1727
|
exports.second2str = second2str;
|
|
1728
|
+
function datetime2ms(datetime) {
|
|
1729
|
+
return (datetime === null || datetime === exports.nulls.int32) ?
|
|
1730
|
+
null
|
|
1731
|
+
:
|
|
1732
|
+
exports.timezone_offset + 1000 * datetime;
|
|
1733
|
+
}
|
|
1734
|
+
exports.datetime2ms = datetime2ms;
|
|
1601
1735
|
function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
|
|
1602
1736
|
return (datetime === null || datetime === exports.nulls.int32) ?
|
|
1603
1737
|
'null'
|
|
1604
1738
|
:
|
|
1605
|
-
(0, dayjs_1.default)(
|
|
1739
|
+
(0, dayjs_1.default)(datetime2ms(datetime)).format(format);
|
|
1606
1740
|
}
|
|
1607
1741
|
exports.datetime2str = datetime2str;
|
|
1742
|
+
function timestamp2ms(timestamp) {
|
|
1743
|
+
return (timestamp === null || timestamp === exports.nulls.int64) ?
|
|
1744
|
+
null
|
|
1745
|
+
:
|
|
1746
|
+
exports.timezone_offset + Number(timestamp);
|
|
1747
|
+
}
|
|
1748
|
+
exports.timestamp2ms = timestamp2ms;
|
|
1608
1749
|
/** format timestamp (bigint) to string
|
|
1609
1750
|
- timestamp: bigint value
|
|
1610
1751
|
- format?:
|
|
@@ -1615,9 +1756,16 @@ function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
|
1615
1756
|
return (timestamp === null || timestamp === exports.nulls.int64) ?
|
|
1616
1757
|
'null'
|
|
1617
1758
|
:
|
|
1618
|
-
(0, dayjs_1.default)(
|
|
1759
|
+
(0, dayjs_1.default)(timestamp2ms(timestamp)).format(format);
|
|
1619
1760
|
}
|
|
1620
1761
|
exports.timestamp2str = timestamp2str;
|
|
1762
|
+
function datehour2ms(datehour) {
|
|
1763
|
+
return (datehour === null || datehour === exports.nulls.int32) ?
|
|
1764
|
+
null
|
|
1765
|
+
:
|
|
1766
|
+
exports.timezone_offset + 1000 * 3600 * datehour;
|
|
1767
|
+
}
|
|
1768
|
+
exports.datehour2ms = datehour2ms;
|
|
1621
1769
|
function datehour2str(datehour, format = 'YYYY.MM.DDTHH') {
|
|
1622
1770
|
return (datehour === null || datehour === exports.nulls.int32) ?
|
|
1623
1771
|
'null'
|
|
@@ -1640,6 +1788,10 @@ function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
|
1640
1788
|
(0, dayjs_1.default)(str, format).valueOf());
|
|
1641
1789
|
}
|
|
1642
1790
|
exports.str2timestamp = str2timestamp;
|
|
1791
|
+
function nanotime2ns(nanotime) {
|
|
1792
|
+
return nanotimestamp2ns(nanotime);
|
|
1793
|
+
}
|
|
1794
|
+
exports.nanotime2ns = nanotime2ns;
|
|
1643
1795
|
function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
|
|
1644
1796
|
if (nanotime === null || nanotime === exports.nulls.int64)
|
|
1645
1797
|
return 'null';
|
|
@@ -1657,6 +1809,13 @@ function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
|
|
|
1657
1809
|
String(nanotime % 1000000000n).padStart(9, '0'));
|
|
1658
1810
|
}
|
|
1659
1811
|
exports.nanotime2str = nanotime2str;
|
|
1812
|
+
function nanotimestamp2ns(nanotimestamp) {
|
|
1813
|
+
return (nanotimestamp === null || nanotimestamp === exports.nulls.int64) ?
|
|
1814
|
+
null
|
|
1815
|
+
:
|
|
1816
|
+
BigInt(exports.timezone_offset) * 1000000n + nanotimestamp;
|
|
1817
|
+
}
|
|
1818
|
+
exports.nanotimestamp2ns = nanotimestamp2ns;
|
|
1660
1819
|
/** format nanotimestamp value (bigint) to string
|
|
1661
1820
|
- nanotimestamp: bigint value
|
|
1662
1821
|
- format?:
|
|
@@ -1970,7 +2129,7 @@ class DDB {
|
|
|
1970
2129
|
reject(error);
|
|
1971
2130
|
}
|
|
1972
2131
|
};
|
|
1973
|
-
args =
|
|
2132
|
+
args = DdbObj.to_ddbobjs(args);
|
|
1974
2133
|
const command = this.enc.encode((() => {
|
|
1975
2134
|
switch (type) {
|
|
1976
2135
|
case 'function':
|
|
@@ -2038,7 +2197,7 @@ class DDB {
|
|
|
2038
2197
|
args = [
|
|
2039
2198
|
new DdbVectorString(nodes),
|
|
2040
2199
|
func,
|
|
2041
|
-
new DdbVectorAny(
|
|
2200
|
+
new DdbVectorAny(args),
|
|
2042
2201
|
...(() => {
|
|
2043
2202
|
if (typeof add_node_alias !== 'undefined')
|
|
2044
2203
|
return [add_node_alias];
|
|
@@ -2119,24 +2278,6 @@ class DDB {
|
|
|
2119
2278
|
})
|
|
2120
2279
|
};
|
|
2121
2280
|
}
|
|
2122
|
-
/** 自动转换 js string, boolean 为 DdbObj */
|
|
2123
|
-
to_ddbobj(value) {
|
|
2124
|
-
if (value instanceof DdbObj)
|
|
2125
|
-
return value;
|
|
2126
|
-
const type = typeof value;
|
|
2127
|
-
switch (type) {
|
|
2128
|
-
case 'string':
|
|
2129
|
-
return new DdbString(value);
|
|
2130
|
-
case 'boolean':
|
|
2131
|
-
return new DdbBool(value);
|
|
2132
|
-
default:
|
|
2133
|
-
throw new Error(`不能自动转换 ${type} 至 DdbObj`);
|
|
2134
|
-
}
|
|
2135
|
-
}
|
|
2136
|
-
/** 转换 js 数组为 DdbObj[] */
|
|
2137
|
-
to_ddbobjs(values) {
|
|
2138
|
-
return values.map(value => this.to_ddbobj(value));
|
|
2139
|
-
}
|
|
2140
2281
|
}
|
|
2141
2282
|
exports.DDB = DDB;
|
|
2142
2283
|
/** little endian (client) */
|