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/browser.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.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 dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
6
7
|
const customParseFormat_js_1 = tslib_1.__importDefault(require("dayjs/plugin/customParseFormat.js"));
|
|
@@ -20,13 +21,14 @@ 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";
|
|
26
28
|
})(DdbForm = exports.DdbForm || (exports.DdbForm = {}));
|
|
27
29
|
/** DolphinDB DataType
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
The corresponding array vector type is 64 + base type
|
|
31
|
+
The corresponding extended type is 128 + base type
|
|
30
32
|
*/
|
|
31
33
|
var DdbType;
|
|
32
34
|
(function (DdbType) {
|
|
@@ -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 [
|
|
@@ -803,7 +860,7 @@ class DdbObj {
|
|
|
803
860
|
];
|
|
804
861
|
}
|
|
805
862
|
default:
|
|
806
|
-
throw new Error(`${DdbForm[form]}
|
|
863
|
+
throw new Error(`${DdbForm[form]} Serialization is not currently supported`);
|
|
807
864
|
}
|
|
808
865
|
})();
|
|
809
866
|
if (!body)
|
|
@@ -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:
|
|
@@ -1009,6 +1068,24 @@ class DdbObj {
|
|
|
1009
1068
|
})();
|
|
1010
1069
|
return `${type}(${this.name ? `'${this.name}', ` : ''}${data})\n`;
|
|
1011
1070
|
}
|
|
1071
|
+
/** 自动转换 js string, boolean 为 DdbObj */
|
|
1072
|
+
static to_ddbobj(value) {
|
|
1073
|
+
if (value && value instanceof DdbObj)
|
|
1074
|
+
return value;
|
|
1075
|
+
const type = typeof value;
|
|
1076
|
+
switch (type) {
|
|
1077
|
+
case 'string':
|
|
1078
|
+
return new DdbString(value);
|
|
1079
|
+
case 'boolean':
|
|
1080
|
+
return new DdbBool(value);
|
|
1081
|
+
default:
|
|
1082
|
+
throw new Error(`Cannot automatically convert ${type} to DdbObj`);
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
/** 转换 js 数组为 DdbObj[] */
|
|
1086
|
+
static to_ddbobjs(values) {
|
|
1087
|
+
return values.map(value => this.to_ddbobj(value));
|
|
1088
|
+
}
|
|
1012
1089
|
to_cols() {
|
|
1013
1090
|
return this.value.map(col => {
|
|
1014
1091
|
let col_ = {
|
|
@@ -1062,13 +1139,22 @@ class DdbObj {
|
|
|
1062
1139
|
}
|
|
1063
1140
|
return rows;
|
|
1064
1141
|
}
|
|
1065
|
-
to_dict() {
|
|
1142
|
+
to_dict({ strip, deep, } = {}) {
|
|
1066
1143
|
if (this.form !== DdbForm.dict)
|
|
1067
|
-
throw new Error('this.form is not DdbForm.dict
|
|
1068
|
-
const [{ value: keys }, { value: values }] = this.value;
|
|
1144
|
+
throw new Error('this.form is not DdbForm.dict and cannot be converted to js object');
|
|
1145
|
+
const [{ value: keys, type: key_type }, { value: values, type: value_type }] = this.value;
|
|
1146
|
+
if (key_type !== DdbType.string || value_type !== DdbType.any)
|
|
1147
|
+
throw new Error('Not dict<string, any>, automatic conversion to js object is not supported for the time being');
|
|
1148
|
+
if (deep && !strip)
|
|
1149
|
+
throw new Error('strip = true must be set when deep = true');
|
|
1069
1150
|
let obj = {};
|
|
1070
|
-
for (let i = 0; i < this.rows; i++)
|
|
1071
|
-
|
|
1151
|
+
for (let i = 0; i < this.rows; i++) {
|
|
1152
|
+
let value = values[i];
|
|
1153
|
+
if (deep && value.form === DdbForm.dict)
|
|
1154
|
+
obj[keys[i]] = value.to_dict({ strip, deep });
|
|
1155
|
+
else
|
|
1156
|
+
obj[keys[i]] = strip ? value.value : value;
|
|
1157
|
+
}
|
|
1072
1158
|
return obj;
|
|
1073
1159
|
}
|
|
1074
1160
|
}
|
|
@@ -1174,7 +1260,7 @@ function format(type, value, le) {
|
|
|
1174
1260
|
case DdbType.uuid:
|
|
1175
1261
|
return uuid2str(value, le);
|
|
1176
1262
|
case DdbType.functiondef:
|
|
1177
|
-
return value.quote('single');
|
|
1263
|
+
return value.name.quote('single');
|
|
1178
1264
|
case DdbType.handle:
|
|
1179
1265
|
case DdbType.code:
|
|
1180
1266
|
return value.quote('single');
|
|
@@ -1222,7 +1308,6 @@ class DdbVoid extends DdbObj {
|
|
|
1222
1308
|
super({
|
|
1223
1309
|
form: DdbForm.scalar,
|
|
1224
1310
|
type: DdbType.void,
|
|
1225
|
-
length: 0,
|
|
1226
1311
|
value: null,
|
|
1227
1312
|
});
|
|
1228
1313
|
}
|
|
@@ -1233,7 +1318,6 @@ class DdbBool extends DdbObj {
|
|
|
1233
1318
|
super({
|
|
1234
1319
|
form: DdbForm.scalar,
|
|
1235
1320
|
type: DdbType.bool,
|
|
1236
|
-
length: 1,
|
|
1237
1321
|
value,
|
|
1238
1322
|
});
|
|
1239
1323
|
}
|
|
@@ -1244,7 +1328,6 @@ class DdbChar extends DdbObj {
|
|
|
1244
1328
|
super({
|
|
1245
1329
|
form: DdbForm.scalar,
|
|
1246
1330
|
type: DdbType.char,
|
|
1247
|
-
length: 1,
|
|
1248
1331
|
value: typeof value === 'string' ?
|
|
1249
1332
|
value.charCodeAt(0)
|
|
1250
1333
|
:
|
|
@@ -1258,7 +1341,6 @@ class DdbInt extends DdbObj {
|
|
|
1258
1341
|
super({
|
|
1259
1342
|
form: DdbForm.scalar,
|
|
1260
1343
|
type: DdbType.int,
|
|
1261
|
-
length: 4,
|
|
1262
1344
|
value,
|
|
1263
1345
|
});
|
|
1264
1346
|
}
|
|
@@ -1269,7 +1351,6 @@ class DdbString extends DdbObj {
|
|
|
1269
1351
|
super({
|
|
1270
1352
|
form: DdbForm.scalar,
|
|
1271
1353
|
type: DdbType.string,
|
|
1272
|
-
length: 0,
|
|
1273
1354
|
value
|
|
1274
1355
|
});
|
|
1275
1356
|
}
|
|
@@ -1280,7 +1361,6 @@ class DdbLong extends DdbObj {
|
|
|
1280
1361
|
super({
|
|
1281
1362
|
form: DdbForm.scalar,
|
|
1282
1363
|
type: DdbType.long,
|
|
1283
|
-
length: 8,
|
|
1284
1364
|
value
|
|
1285
1365
|
});
|
|
1286
1366
|
}
|
|
@@ -1291,7 +1371,6 @@ class DdbDouble extends DdbObj {
|
|
|
1291
1371
|
super({
|
|
1292
1372
|
form: DdbForm.scalar,
|
|
1293
1373
|
type: DdbType.double,
|
|
1294
|
-
length: 8,
|
|
1295
1374
|
value
|
|
1296
1375
|
});
|
|
1297
1376
|
}
|
|
@@ -1302,7 +1381,6 @@ class DdbDateTime extends DdbObj {
|
|
|
1302
1381
|
super({
|
|
1303
1382
|
form: DdbForm.scalar,
|
|
1304
1383
|
type: DdbType.datetime,
|
|
1305
|
-
length: 4,
|
|
1306
1384
|
value
|
|
1307
1385
|
});
|
|
1308
1386
|
}
|
|
@@ -1313,7 +1391,6 @@ class DdbTimeStamp extends DdbObj {
|
|
|
1313
1391
|
super({
|
|
1314
1392
|
form: DdbForm.scalar,
|
|
1315
1393
|
type: DdbType.timestamp,
|
|
1316
|
-
length: 8,
|
|
1317
1394
|
value
|
|
1318
1395
|
});
|
|
1319
1396
|
}
|
|
@@ -1324,7 +1401,6 @@ class DdbNanoTimeStamp extends DdbObj {
|
|
|
1324
1401
|
super({
|
|
1325
1402
|
form: DdbForm.scalar,
|
|
1326
1403
|
type: DdbType.nanotimestamp,
|
|
1327
|
-
length: 8,
|
|
1328
1404
|
value
|
|
1329
1405
|
});
|
|
1330
1406
|
}
|
|
@@ -1335,7 +1411,6 @@ class DdbPair extends DdbObj {
|
|
|
1335
1411
|
super({
|
|
1336
1412
|
form: DdbForm.pair,
|
|
1337
1413
|
type: DdbType.int,
|
|
1338
|
-
length: 0,
|
|
1339
1414
|
rows: 2,
|
|
1340
1415
|
cols: 1,
|
|
1341
1416
|
value: Int32Array.of(l === null ? exports.nulls.int32 : l, r === null ? exports.nulls.int32 : r)
|
|
@@ -1348,7 +1423,6 @@ class DdbFunction extends DdbObj {
|
|
|
1348
1423
|
super({
|
|
1349
1424
|
form: DdbForm.scalar,
|
|
1350
1425
|
type: DdbType.functiondef,
|
|
1351
|
-
length: 0,
|
|
1352
1426
|
value: { type, name }
|
|
1353
1427
|
});
|
|
1354
1428
|
}
|
|
@@ -1359,7 +1433,6 @@ class DdbVectorInt extends DdbObj {
|
|
|
1359
1433
|
super({
|
|
1360
1434
|
form: DdbForm.vector,
|
|
1361
1435
|
type: DdbType.int,
|
|
1362
|
-
length: 0,
|
|
1363
1436
|
rows: ints.length,
|
|
1364
1437
|
cols: 1,
|
|
1365
1438
|
value: ints instanceof Int32Array ?
|
|
@@ -1379,7 +1452,6 @@ class DdbVectorDouble extends DdbObj {
|
|
|
1379
1452
|
super({
|
|
1380
1453
|
form: DdbForm.vector,
|
|
1381
1454
|
type: DdbType.double,
|
|
1382
|
-
length: 0,
|
|
1383
1455
|
rows: doubles.length,
|
|
1384
1456
|
cols: 1,
|
|
1385
1457
|
value: doubles instanceof Float64Array ?
|
|
@@ -1399,7 +1471,6 @@ class DdbVectorString extends DdbObj {
|
|
|
1399
1471
|
super({
|
|
1400
1472
|
form: DdbForm.vector,
|
|
1401
1473
|
type: DdbType.string,
|
|
1402
|
-
length: 0,
|
|
1403
1474
|
rows: strings.length,
|
|
1404
1475
|
cols: 1,
|
|
1405
1476
|
value: strings,
|
|
@@ -1413,10 +1484,9 @@ class DdbVectorAny extends DdbObj {
|
|
|
1413
1484
|
super({
|
|
1414
1485
|
form: DdbForm.vector,
|
|
1415
1486
|
type: DdbType.any,
|
|
1416
|
-
length: 0,
|
|
1417
1487
|
rows: objs.length,
|
|
1418
1488
|
cols: 1,
|
|
1419
|
-
value: objs,
|
|
1489
|
+
value: DdbObj.to_ddbobjs(objs),
|
|
1420
1490
|
name,
|
|
1421
1491
|
});
|
|
1422
1492
|
}
|
|
@@ -1440,7 +1510,6 @@ class DdbVectorSymbol extends DdbObj {
|
|
|
1440
1510
|
super({
|
|
1441
1511
|
form: DdbForm.vector,
|
|
1442
1512
|
type: DdbType.symbol_extended,
|
|
1443
|
-
length: 0,
|
|
1444
1513
|
rows: strings.length,
|
|
1445
1514
|
cols: 1,
|
|
1446
1515
|
value: {
|
|
@@ -1458,7 +1527,6 @@ class DdbSetInt extends DdbObj {
|
|
|
1458
1527
|
super({
|
|
1459
1528
|
form: DdbForm.set,
|
|
1460
1529
|
type: DdbType.int,
|
|
1461
|
-
length: 0,
|
|
1462
1530
|
rows: ints instanceof Set ?
|
|
1463
1531
|
ints.size
|
|
1464
1532
|
:
|
|
@@ -1480,7 +1548,6 @@ class DdbSetDouble extends DdbObj {
|
|
|
1480
1548
|
super({
|
|
1481
1549
|
form: DdbForm.set,
|
|
1482
1550
|
type: DdbType.double,
|
|
1483
|
-
length: 0,
|
|
1484
1551
|
rows: doubles instanceof Set ?
|
|
1485
1552
|
doubles.size
|
|
1486
1553
|
:
|
|
@@ -1504,7 +1571,6 @@ class DdbSetString extends DdbObj {
|
|
|
1504
1571
|
super({
|
|
1505
1572
|
form: DdbForm.set,
|
|
1506
1573
|
type: DdbType.string,
|
|
1507
|
-
length: 0,
|
|
1508
1574
|
rows: strings.length,
|
|
1509
1575
|
cols: 1,
|
|
1510
1576
|
value: strings
|
|
@@ -1512,12 +1578,41 @@ class DdbSetString extends DdbObj {
|
|
|
1512
1578
|
}
|
|
1513
1579
|
}
|
|
1514
1580
|
exports.DdbSetString = DdbSetString;
|
|
1581
|
+
/** Constructs a DdbDict object, which supports two usages:
|
|
1582
|
+
- 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>
|
|
1583
|
+
- Pass in js object (type is Record<string, boolean | string | DdbObj>), automatically converted to DdbDict of dict<string, any>
|
|
1584
|
+
*/
|
|
1585
|
+
class DdbDict extends DdbObj {
|
|
1586
|
+
constructor(arg0, arg1) {
|
|
1587
|
+
if (arg1)
|
|
1588
|
+
super({
|
|
1589
|
+
form: DdbForm.dict,
|
|
1590
|
+
type: arg1.type,
|
|
1591
|
+
rows: arg0.rows,
|
|
1592
|
+
cols: 2,
|
|
1593
|
+
value: [arg0, arg1]
|
|
1594
|
+
});
|
|
1595
|
+
else {
|
|
1596
|
+
const keys = Object.keys(arg0);
|
|
1597
|
+
super({
|
|
1598
|
+
form: DdbForm.dict,
|
|
1599
|
+
type: DdbType.any,
|
|
1600
|
+
rows: keys.length,
|
|
1601
|
+
cols: 2,
|
|
1602
|
+
value: [
|
|
1603
|
+
new DdbVectorString(keys),
|
|
1604
|
+
new DdbVectorAny(Object.values(arg0))
|
|
1605
|
+
]
|
|
1606
|
+
});
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
exports.DdbDict = DdbDict;
|
|
1515
1611
|
class DdbTable extends DdbObj {
|
|
1516
1612
|
constructor(columns, name = '') {
|
|
1517
1613
|
super({
|
|
1518
1614
|
form: DdbForm.table,
|
|
1519
1615
|
type: DdbType.void,
|
|
1520
|
-
length: 0,
|
|
1521
1616
|
rows: columns[0].rows,
|
|
1522
1617
|
cols: columns.length,
|
|
1523
1618
|
name,
|
|
@@ -1526,13 +1621,27 @@ class DdbTable extends DdbObj {
|
|
|
1526
1621
|
}
|
|
1527
1622
|
}
|
|
1528
1623
|
exports.DdbTable = DdbTable;
|
|
1624
|
+
function date2ms(date) {
|
|
1625
|
+
return (date === null || date === exports.nulls.int32) ?
|
|
1626
|
+
null
|
|
1627
|
+
:
|
|
1628
|
+
exports.timezone_offset + 1000 * 3600 * 24 * date;
|
|
1629
|
+
}
|
|
1630
|
+
exports.date2ms = date2ms;
|
|
1529
1631
|
function date2str(date, format = 'YYYY.MM.DD') {
|
|
1530
1632
|
return (date === null || date === exports.nulls.int32) ?
|
|
1531
|
-
|
|
1633
|
+
null
|
|
1532
1634
|
:
|
|
1533
|
-
(0, dayjs_1.default)(
|
|
1635
|
+
(0, dayjs_1.default)(date2ms(date)).format(format);
|
|
1534
1636
|
}
|
|
1535
1637
|
exports.date2str = date2str;
|
|
1638
|
+
function month2ms(month) {
|
|
1639
|
+
return (month === null || month === exports.nulls.int32) ?
|
|
1640
|
+
null
|
|
1641
|
+
:
|
|
1642
|
+
(0, dayjs_1.default)(month2str(month), 'YYYY.MM[M]').valueOf();
|
|
1643
|
+
}
|
|
1644
|
+
exports.month2ms = month2ms;
|
|
1536
1645
|
function month2str(month) {
|
|
1537
1646
|
if (month === null || month === exports.nulls.int32)
|
|
1538
1647
|
return 'null';
|
|
@@ -1543,37 +1652,69 @@ function month2str(month) {
|
|
|
1543
1652
|
return `${String(year).padStart(4, '0')}.${String(_month + 1).padStart(2, '0')}M`;
|
|
1544
1653
|
}
|
|
1545
1654
|
exports.month2str = month2str;
|
|
1655
|
+
function time2ms(time) {
|
|
1656
|
+
return (time === null || time === exports.nulls.int32) ?
|
|
1657
|
+
null
|
|
1658
|
+
:
|
|
1659
|
+
exports.timezone_offset + time;
|
|
1660
|
+
}
|
|
1661
|
+
exports.time2ms = time2ms;
|
|
1546
1662
|
function time2str(time, format = 'HH:mm:ss.SSS') {
|
|
1547
1663
|
return (time === null || time === exports.nulls.int32) ?
|
|
1548
|
-
|
|
1664
|
+
null
|
|
1549
1665
|
:
|
|
1550
|
-
(0, dayjs_1.default)(
|
|
1551
|
-
.format(format);
|
|
1666
|
+
(0, dayjs_1.default)(time2ms(time)).format(format);
|
|
1552
1667
|
}
|
|
1553
1668
|
exports.time2str = time2str;
|
|
1669
|
+
function minute2ms(minute) {
|
|
1670
|
+
return (minute === null || minute === exports.nulls.int32) ?
|
|
1671
|
+
null
|
|
1672
|
+
:
|
|
1673
|
+
exports.timezone_offset + 60 * 1000 * minute;
|
|
1674
|
+
}
|
|
1675
|
+
exports.minute2ms = minute2ms;
|
|
1554
1676
|
function minute2str(minute, format = 'HH:mm[m]') {
|
|
1555
1677
|
return (minute === null || minute === exports.nulls.int32) ?
|
|
1556
1678
|
'null'
|
|
1557
1679
|
:
|
|
1558
|
-
(0, dayjs_1.default)(
|
|
1559
|
-
.format(format);
|
|
1680
|
+
(0, dayjs_1.default)(minute2ms(minute)).format(format);
|
|
1560
1681
|
}
|
|
1561
1682
|
exports.minute2str = minute2str;
|
|
1683
|
+
function second2ms(second) {
|
|
1684
|
+
return (second === null || second === exports.nulls.int32) ?
|
|
1685
|
+
null
|
|
1686
|
+
:
|
|
1687
|
+
exports.timezone_offset + 1000 * second;
|
|
1688
|
+
}
|
|
1689
|
+
exports.second2ms = second2ms;
|
|
1562
1690
|
function second2str(second, format = 'HH:mm:ss') {
|
|
1563
1691
|
return (second === null || second === exports.nulls.int32) ?
|
|
1564
1692
|
'null'
|
|
1565
1693
|
:
|
|
1566
|
-
(0, dayjs_1.default)(
|
|
1567
|
-
.format(format);
|
|
1694
|
+
(0, dayjs_1.default)(second2ms(second)).format(format);
|
|
1568
1695
|
}
|
|
1569
1696
|
exports.second2str = second2str;
|
|
1697
|
+
function datetime2ms(datetime) {
|
|
1698
|
+
return (datetime === null || datetime === exports.nulls.int32) ?
|
|
1699
|
+
null
|
|
1700
|
+
:
|
|
1701
|
+
exports.timezone_offset + 1000 * datetime;
|
|
1702
|
+
}
|
|
1703
|
+
exports.datetime2ms = datetime2ms;
|
|
1570
1704
|
function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
|
|
1571
1705
|
return (datetime === null || datetime === exports.nulls.int32) ?
|
|
1572
1706
|
'null'
|
|
1573
1707
|
:
|
|
1574
|
-
(0, dayjs_1.default)(
|
|
1708
|
+
(0, dayjs_1.default)(datetime2ms(datetime)).format(format);
|
|
1575
1709
|
}
|
|
1576
1710
|
exports.datetime2str = datetime2str;
|
|
1711
|
+
function timestamp2ms(timestamp) {
|
|
1712
|
+
return (timestamp === null || timestamp === exports.nulls.int64) ?
|
|
1713
|
+
null
|
|
1714
|
+
:
|
|
1715
|
+
exports.timezone_offset + Number(timestamp);
|
|
1716
|
+
}
|
|
1717
|
+
exports.timestamp2ms = timestamp2ms;
|
|
1577
1718
|
/** format timestamp (bigint) to string
|
|
1578
1719
|
- timestamp: bigint value
|
|
1579
1720
|
- format?:
|
|
@@ -1584,9 +1725,16 @@ function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
|
1584
1725
|
return (timestamp === null || timestamp === exports.nulls.int64) ?
|
|
1585
1726
|
'null'
|
|
1586
1727
|
:
|
|
1587
|
-
(0, dayjs_1.default)(
|
|
1728
|
+
(0, dayjs_1.default)(timestamp2ms(timestamp)).format(format);
|
|
1588
1729
|
}
|
|
1589
1730
|
exports.timestamp2str = timestamp2str;
|
|
1731
|
+
function datehour2ms(datehour) {
|
|
1732
|
+
return (datehour === null || datehour === exports.nulls.int32) ?
|
|
1733
|
+
null
|
|
1734
|
+
:
|
|
1735
|
+
exports.timezone_offset + 1000 * 3600 * datehour;
|
|
1736
|
+
}
|
|
1737
|
+
exports.datehour2ms = datehour2ms;
|
|
1590
1738
|
function datehour2str(datehour, format = 'YYYY.MM.DDTHH') {
|
|
1591
1739
|
return (datehour === null || datehour === exports.nulls.int32) ?
|
|
1592
1740
|
'null'
|
|
@@ -1609,6 +1757,10 @@ function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
|
1609
1757
|
(0, dayjs_1.default)(str, format).valueOf());
|
|
1610
1758
|
}
|
|
1611
1759
|
exports.str2timestamp = str2timestamp;
|
|
1760
|
+
function nanotime2ns(nanotime) {
|
|
1761
|
+
return nanotimestamp2ns(nanotime);
|
|
1762
|
+
}
|
|
1763
|
+
exports.nanotime2ns = nanotime2ns;
|
|
1612
1764
|
function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
|
|
1613
1765
|
if (nanotime === null || nanotime === exports.nulls.int64)
|
|
1614
1766
|
return 'null';
|
|
@@ -1626,6 +1778,13 @@ function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
|
|
|
1626
1778
|
String(nanotime % 1000000000n).padStart(9, '0'));
|
|
1627
1779
|
}
|
|
1628
1780
|
exports.nanotime2str = nanotime2str;
|
|
1781
|
+
function nanotimestamp2ns(nanotimestamp) {
|
|
1782
|
+
return (nanotimestamp === null || nanotimestamp === exports.nulls.int64) ?
|
|
1783
|
+
null
|
|
1784
|
+
:
|
|
1785
|
+
BigInt(exports.timezone_offset) * 1000000n + nanotimestamp;
|
|
1786
|
+
}
|
|
1787
|
+
exports.nanotimestamp2ns = nanotimestamp2ns;
|
|
1629
1788
|
/** format nanotimestamp value (bigint) to string
|
|
1630
1789
|
- nanotimestamp: bigint value
|
|
1631
1790
|
- format?:
|
|
@@ -1945,7 +2104,7 @@ class DDB {
|
|
|
1945
2104
|
reject(error);
|
|
1946
2105
|
}
|
|
1947
2106
|
};
|
|
1948
|
-
args =
|
|
2107
|
+
args = DdbObj.to_ddbobjs(args);
|
|
1949
2108
|
const command = this.enc.encode((() => {
|
|
1950
2109
|
switch (type) {
|
|
1951
2110
|
case 'function':
|
|
@@ -2013,7 +2172,7 @@ class DDB {
|
|
|
2013
2172
|
args = [
|
|
2014
2173
|
new DdbVectorString(nodes),
|
|
2015
2174
|
func,
|
|
2016
|
-
new DdbVectorAny(
|
|
2175
|
+
new DdbVectorAny(args),
|
|
2017
2176
|
...(() => {
|
|
2018
2177
|
if (typeof add_node_alias !== 'undefined')
|
|
2019
2178
|
return [add_node_alias];
|
|
@@ -2094,24 +2253,6 @@ class DDB {
|
|
|
2094
2253
|
})
|
|
2095
2254
|
};
|
|
2096
2255
|
}
|
|
2097
|
-
/** 自动转换 js string, boolean 为 DdbObj */
|
|
2098
|
-
to_ddbobj(value) {
|
|
2099
|
-
if (value instanceof DdbObj)
|
|
2100
|
-
return value;
|
|
2101
|
-
const type = typeof value;
|
|
2102
|
-
switch (type) {
|
|
2103
|
-
case 'string':
|
|
2104
|
-
return new DdbString(value);
|
|
2105
|
-
case 'boolean':
|
|
2106
|
-
return new DdbBool(value);
|
|
2107
|
-
default:
|
|
2108
|
-
throw new Error(`不能自动转换 ${type} 至 DdbObj`);
|
|
2109
|
-
}
|
|
2110
|
-
}
|
|
2111
|
-
/** 转换 js 数组为 DdbObj[] */
|
|
2112
|
-
to_ddbobjs(values) {
|
|
2113
|
-
return values.map(value => this.to_ddbobj(value));
|
|
2114
|
-
}
|
|
2115
2256
|
}
|
|
2116
2257
|
exports.DDB = DDB;
|
|
2117
2258
|
/** little endian (client) */
|