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.d.ts +1 -1
- package/browser.js +229 -254
- package/browser.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +240 -267
- package/index.js.map +1 -1
- package/language.js +5 -8
- package/language.js.map +1 -1
- package/package.json +7 -7
package/index.js
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const ipaddr_js_1 = tslib_1.__importDefault(require("ipaddr.js"));
|
|
11
|
-
const { fromByteArray: buf2ipaddr } = ipaddr_js_1.default;
|
|
12
|
-
const net_js_1 = require("xshell/net.js");
|
|
13
|
-
const utils_js_1 = require("xshell/utils.js");
|
|
14
|
-
var DdbForm;
|
|
1
|
+
import { WebSocket } from 'ws';
|
|
2
|
+
import dayjs from 'dayjs';
|
|
3
|
+
import DayjsCustomParseFormat from 'dayjs/plugin/customParseFormat.js';
|
|
4
|
+
dayjs.extend(DayjsCustomParseFormat);
|
|
5
|
+
import ipaddrjs from 'ipaddr.js';
|
|
6
|
+
const { fromByteArray: buf2ipaddr } = ipaddrjs;
|
|
7
|
+
import { connect_websocket } from 'xshell/net.js';
|
|
8
|
+
import { concat, inspect, typed_array_to_buffer } from 'xshell/utils.js';
|
|
9
|
+
export var DdbForm;
|
|
15
10
|
(function (DdbForm) {
|
|
16
11
|
DdbForm[DdbForm["scalar"] = 0] = "scalar";
|
|
17
12
|
DdbForm[DdbForm["vector"] = 1] = "vector";
|
|
@@ -25,12 +20,12 @@ var DdbForm;
|
|
|
25
20
|
DdbForm[DdbForm["chunk"] = 8] = "chunk";
|
|
26
21
|
/** sysobj */
|
|
27
22
|
DdbForm[DdbForm["object"] = 9] = "object";
|
|
28
|
-
})(DdbForm =
|
|
23
|
+
})(DdbForm = DdbForm || (DdbForm = {}));
|
|
29
24
|
/** DolphinDB DataType
|
|
30
25
|
对应的 array vector 类型为 64 + 基本类型
|
|
31
26
|
对应的 extended 类型为 128 + 基本类型
|
|
32
27
|
*/
|
|
33
|
-
var DdbType;
|
|
28
|
+
export var DdbType;
|
|
34
29
|
(function (DdbType) {
|
|
35
30
|
DdbType[DdbType["void"] = 0] = "void";
|
|
36
31
|
DdbType[DdbType["bool"] = 1] = "bool";
|
|
@@ -69,8 +64,8 @@ var DdbType;
|
|
|
69
64
|
DdbType[DdbType["duration"] = 36] = "duration";
|
|
70
65
|
DdbType[DdbType["object"] = 37] = "object";
|
|
71
66
|
DdbType[DdbType["symbol_extended"] = 145] = "symbol_extended";
|
|
72
|
-
})(DdbType =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
111
|
-
|
|
105
|
+
})(DdbChartType = DdbChartType || (DdbChartType = {}));
|
|
106
|
+
export const nulls = {
|
|
112
107
|
int8: -0x80,
|
|
113
|
-
int16: -
|
|
114
|
-
int32: -
|
|
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
|
-
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
894
|
+
return concat([
|
|
868
895
|
header,
|
|
869
896
|
...body
|
|
870
897
|
]);
|
|
@@ -952,7 +979,7 @@ class DdbObj {
|
|
|
952
979
|
throw new Error(`vector ${DdbType[type]} 暂不支持序列化`);
|
|
953
980
|
}
|
|
954
981
|
}
|
|
955
|
-
[
|
|
982
|
+
[inspect.custom](depth, options, _inspect) {
|
|
956
983
|
const type = (() => {
|
|
957
984
|
const tname = DdbType[this.type];
|
|
958
985
|
switch (this.form) {
|
|
@@ -1029,7 +1056,7 @@ class DdbObj {
|
|
|
1029
1056
|
const { base, data } = this.value;
|
|
1030
1057
|
let items = new Array(Math.min(limit, data.length));
|
|
1031
1058
|
for (let i = 0; i < items.length; i++)
|
|
1032
|
-
items[i] =
|
|
1059
|
+
items[i] = inspect(base[data[i]], options);
|
|
1033
1060
|
return format_array(items, data.length > limit);
|
|
1034
1061
|
}
|
|
1035
1062
|
case DdbType.uuid:
|
|
@@ -1064,10 +1091,10 @@ class DdbObj {
|
|
|
1064
1091
|
}
|
|
1065
1092
|
}
|
|
1066
1093
|
if (this.value instanceof Uint8Array)
|
|
1067
|
-
return
|
|
1068
|
-
return
|
|
1094
|
+
return inspect(typed_array_to_buffer(this.value), options);
|
|
1095
|
+
return inspect(this.value, options);
|
|
1069
1096
|
})();
|
|
1070
|
-
return `${options.colors ? type.blue : type}(${this.name ? `${
|
|
1097
|
+
return `${options.colors ? type.blue : type}(${this.name ? `${inspect(this.name, options)}, ` : ''}${data})`;
|
|
1071
1098
|
}
|
|
1072
1099
|
/** 自动转换 js string, boolean 为 DdbObj */
|
|
1073
1100
|
static to_ddbobj(value) {
|
|
@@ -1098,7 +1125,7 @@ class DdbObj {
|
|
|
1098
1125
|
switch (type) {
|
|
1099
1126
|
case DdbType.bool: {
|
|
1100
1127
|
const value = values[i];
|
|
1101
|
-
row[name] = value ===
|
|
1128
|
+
row[name] = value === nulls.int8 ?
|
|
1102
1129
|
null
|
|
1103
1130
|
:
|
|
1104
1131
|
Boolean(value);
|
|
@@ -1139,24 +1166,15 @@ class DdbObj {
|
|
|
1139
1166
|
return obj;
|
|
1140
1167
|
}
|
|
1141
1168
|
}
|
|
1142
|
-
|
|
1143
|
-
DdbObj.dec = new TextDecoder('utf-8');
|
|
1144
|
-
DdbObj.enc = new TextEncoder();
|
|
1145
|
-
/** 维护已解析的 symbol base,比如流数据中后续的 symbol 向量可能只发送一个 base.id, base.size == 0, 依赖之前发送的 symbol base ?
|
|
1146
|
-
只是暂存,如果一张表有多个 symbol 列,可能这个 symbol base 会被复用,不同的对象之间 symbol base 一般不复用
|
|
1147
|
-
*/
|
|
1148
|
-
DdbObj.symbol_bases = {};
|
|
1149
|
-
/** little endian (client) */
|
|
1150
|
-
DdbObj.le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
|
|
1151
|
-
function format(type, value, le, options) {
|
|
1169
|
+
export function format(type, value, le, options) {
|
|
1152
1170
|
switch (type) {
|
|
1153
1171
|
case DdbType.bool:
|
|
1154
|
-
return
|
|
1172
|
+
return inspect((value === null || value === nulls.int8) ?
|
|
1155
1173
|
null
|
|
1156
1174
|
:
|
|
1157
1175
|
Boolean(value), options);
|
|
1158
1176
|
case DdbType.char:
|
|
1159
|
-
return
|
|
1177
|
+
return inspect((value === null || value === nulls.int8) ?
|
|
1160
1178
|
null
|
|
1161
1179
|
:
|
|
1162
1180
|
// ascii printable
|
|
@@ -1166,17 +1184,17 @@ function format(type, value, le, options) {
|
|
|
1166
1184
|
:
|
|
1167
1185
|
value, options);
|
|
1168
1186
|
case DdbType.short:
|
|
1169
|
-
return
|
|
1187
|
+
return inspect((value === null || value === nulls.int16) ?
|
|
1170
1188
|
null
|
|
1171
1189
|
:
|
|
1172
1190
|
value, options);
|
|
1173
1191
|
case DdbType.int:
|
|
1174
|
-
return
|
|
1192
|
+
return inspect((value === null || value === nulls.int32) ?
|
|
1175
1193
|
null
|
|
1176
1194
|
:
|
|
1177
1195
|
value, options);
|
|
1178
1196
|
case DdbType.long:
|
|
1179
|
-
return (value === null || value ===
|
|
1197
|
+
return (value === null || value === nulls.int64) ?
|
|
1180
1198
|
'null'
|
|
1181
1199
|
:
|
|
1182
1200
|
options.colors ?
|
|
@@ -1184,7 +1202,7 @@ function format(type, value, le, options) {
|
|
|
1184
1202
|
:
|
|
1185
1203
|
String(value);
|
|
1186
1204
|
case DdbType.date:
|
|
1187
|
-
return (value === null || value ===
|
|
1205
|
+
return (value === null || value === nulls.int32) ?
|
|
1188
1206
|
'null'
|
|
1189
1207
|
:
|
|
1190
1208
|
options.colors ?
|
|
@@ -1192,7 +1210,7 @@ function format(type, value, le, options) {
|
|
|
1192
1210
|
:
|
|
1193
1211
|
date2str(value);
|
|
1194
1212
|
case DdbType.month:
|
|
1195
|
-
return (value === null || value ===
|
|
1213
|
+
return (value === null || value === nulls.int32) ?
|
|
1196
1214
|
'null'
|
|
1197
1215
|
:
|
|
1198
1216
|
options.colors ?
|
|
@@ -1200,7 +1218,7 @@ function format(type, value, le, options) {
|
|
|
1200
1218
|
:
|
|
1201
1219
|
month2str(value);
|
|
1202
1220
|
case DdbType.time:
|
|
1203
|
-
return (value === null || value ===
|
|
1221
|
+
return (value === null || value === nulls.int32) ?
|
|
1204
1222
|
'null'
|
|
1205
1223
|
:
|
|
1206
1224
|
options.colors ?
|
|
@@ -1208,7 +1226,7 @@ function format(type, value, le, options) {
|
|
|
1208
1226
|
:
|
|
1209
1227
|
time2str(value);
|
|
1210
1228
|
case DdbType.minute:
|
|
1211
|
-
return (value === null || value ===
|
|
1229
|
+
return (value === null || value === nulls.int32) ?
|
|
1212
1230
|
'null'
|
|
1213
1231
|
:
|
|
1214
1232
|
options.colors ?
|
|
@@ -1216,7 +1234,7 @@ function format(type, value, le, options) {
|
|
|
1216
1234
|
:
|
|
1217
1235
|
minute2str(value);
|
|
1218
1236
|
case DdbType.second:
|
|
1219
|
-
return (value === null || value ===
|
|
1237
|
+
return (value === null || value === nulls.int32) ?
|
|
1220
1238
|
'null'
|
|
1221
1239
|
:
|
|
1222
1240
|
options.colors ?
|
|
@@ -1224,7 +1242,7 @@ function format(type, value, le, options) {
|
|
|
1224
1242
|
:
|
|
1225
1243
|
second2str(value);
|
|
1226
1244
|
case DdbType.datetime:
|
|
1227
|
-
return (value === null || value ===
|
|
1245
|
+
return (value === null || value === nulls.int32) ?
|
|
1228
1246
|
'null'
|
|
1229
1247
|
:
|
|
1230
1248
|
options.colors ?
|
|
@@ -1232,7 +1250,7 @@ function format(type, value, le, options) {
|
|
|
1232
1250
|
:
|
|
1233
1251
|
datetime2str(value);
|
|
1234
1252
|
case DdbType.timestamp:
|
|
1235
|
-
return (value === null || value ===
|
|
1253
|
+
return (value === null || value === nulls.int64) ?
|
|
1236
1254
|
'null'
|
|
1237
1255
|
:
|
|
1238
1256
|
options.colors ?
|
|
@@ -1240,7 +1258,7 @@ function format(type, value, le, options) {
|
|
|
1240
1258
|
:
|
|
1241
1259
|
timestamp2str(value);
|
|
1242
1260
|
case DdbType.nanotime:
|
|
1243
|
-
return (value === null || value ===
|
|
1261
|
+
return (value === null || value === nulls.int64) ?
|
|
1244
1262
|
'null'
|
|
1245
1263
|
:
|
|
1246
1264
|
options.colors ?
|
|
@@ -1248,7 +1266,7 @@ function format(type, value, le, options) {
|
|
|
1248
1266
|
:
|
|
1249
1267
|
nanotime2str(value);
|
|
1250
1268
|
case DdbType.nanotimestamp:
|
|
1251
|
-
return (value === null || value ===
|
|
1269
|
+
return (value === null || value === nulls.int64) ?
|
|
1252
1270
|
'null'
|
|
1253
1271
|
:
|
|
1254
1272
|
options.colors ?
|
|
@@ -1256,30 +1274,30 @@ function format(type, value, le, options) {
|
|
|
1256
1274
|
:
|
|
1257
1275
|
nanotimestamp2str(value);
|
|
1258
1276
|
case DdbType.float:
|
|
1259
|
-
return (value === null || value ===
|
|
1277
|
+
return (value === null || value === nulls.float32) ?
|
|
1260
1278
|
'null'
|
|
1261
1279
|
:
|
|
1262
|
-
|
|
1280
|
+
inspect(value, options);
|
|
1263
1281
|
case DdbType.double:
|
|
1264
|
-
return (value === null || value ===
|
|
1282
|
+
return (value === null || value === nulls.double) ?
|
|
1265
1283
|
'null'
|
|
1266
1284
|
:
|
|
1267
|
-
|
|
1285
|
+
inspect(value, options);
|
|
1268
1286
|
case DdbType.symbol:
|
|
1269
1287
|
case DdbType.string:
|
|
1270
|
-
return
|
|
1288
|
+
return inspect(value, options);
|
|
1271
1289
|
case DdbType.uuid:
|
|
1272
1290
|
return options.colors ?
|
|
1273
1291
|
uuid2str(value, le).green
|
|
1274
1292
|
:
|
|
1275
1293
|
uuid2str(value, le);
|
|
1276
1294
|
case DdbType.functiondef:
|
|
1277
|
-
return
|
|
1295
|
+
return inspect(value.name, options);
|
|
1278
1296
|
case DdbType.handle:
|
|
1279
1297
|
case DdbType.code:
|
|
1280
|
-
return
|
|
1298
|
+
return inspect(value, options);
|
|
1281
1299
|
case DdbType.datehour:
|
|
1282
|
-
return (value === null || value ===
|
|
1300
|
+
return (value === null || value === nulls.int32) ?
|
|
1283
1301
|
'null'
|
|
1284
1302
|
:
|
|
1285
1303
|
options.colors ?
|
|
@@ -1297,15 +1315,15 @@ function format(type, value, le, options) {
|
|
|
1297
1315
|
:
|
|
1298
1316
|
int1282str(value, le);
|
|
1299
1317
|
case DdbType.blob:
|
|
1300
|
-
return
|
|
1318
|
+
return inspect(value.length > 100 ?
|
|
1301
1319
|
DdbObj.dec.decode(value.subarray(0, 98)) + '…'
|
|
1302
1320
|
:
|
|
1303
1321
|
DdbObj.dec.decode(value), options);
|
|
1304
1322
|
case DdbType.point: {
|
|
1305
1323
|
let [x, y] = value;
|
|
1306
|
-
if (x ===
|
|
1324
|
+
if (x === nulls.double)
|
|
1307
1325
|
x = null;
|
|
1308
|
-
if (y ===
|
|
1326
|
+
if (y === nulls.double)
|
|
1309
1327
|
y = null;
|
|
1310
1328
|
return options.colors ?
|
|
1311
1329
|
`(${String(x).green}, ${String(y).green})`
|
|
@@ -1314,9 +1332,9 @@ function format(type, value, le, options) {
|
|
|
1314
1332
|
}
|
|
1315
1333
|
case DdbType.complex: {
|
|
1316
1334
|
let [x, y] = value;
|
|
1317
|
-
if (x ===
|
|
1335
|
+
if (x === nulls.double)
|
|
1318
1336
|
x = null;
|
|
1319
|
-
if (y ===
|
|
1337
|
+
if (y === nulls.double)
|
|
1320
1338
|
y = null;
|
|
1321
1339
|
return options.colors ?
|
|
1322
1340
|
`${String(x).green}+${`${String(y)}i`.green}`
|
|
@@ -1329,11 +1347,10 @@ function format(type, value, le, options) {
|
|
|
1329
1347
|
return options.colors ? str.green : str;
|
|
1330
1348
|
}
|
|
1331
1349
|
default:
|
|
1332
|
-
return
|
|
1350
|
+
return inspect(value, options);
|
|
1333
1351
|
}
|
|
1334
1352
|
}
|
|
1335
|
-
|
|
1336
|
-
class DdbVoid extends DdbObj {
|
|
1353
|
+
export class DdbVoid extends DdbObj {
|
|
1337
1354
|
constructor() {
|
|
1338
1355
|
super({
|
|
1339
1356
|
form: DdbForm.scalar,
|
|
@@ -1342,8 +1359,7 @@ class DdbVoid extends DdbObj {
|
|
|
1342
1359
|
});
|
|
1343
1360
|
}
|
|
1344
1361
|
}
|
|
1345
|
-
|
|
1346
|
-
class DdbBool extends DdbObj {
|
|
1362
|
+
export class DdbBool extends DdbObj {
|
|
1347
1363
|
constructor(value) {
|
|
1348
1364
|
super({
|
|
1349
1365
|
form: DdbForm.scalar,
|
|
@@ -1352,8 +1368,7 @@ class DdbBool extends DdbObj {
|
|
|
1352
1368
|
});
|
|
1353
1369
|
}
|
|
1354
1370
|
}
|
|
1355
|
-
|
|
1356
|
-
class DdbChar extends DdbObj {
|
|
1371
|
+
export class DdbChar extends DdbObj {
|
|
1357
1372
|
constructor(value) {
|
|
1358
1373
|
super({
|
|
1359
1374
|
form: DdbForm.scalar,
|
|
@@ -1365,8 +1380,7 @@ class DdbChar extends DdbObj {
|
|
|
1365
1380
|
});
|
|
1366
1381
|
}
|
|
1367
1382
|
}
|
|
1368
|
-
|
|
1369
|
-
class DdbInt extends DdbObj {
|
|
1383
|
+
export class DdbInt extends DdbObj {
|
|
1370
1384
|
constructor(value) {
|
|
1371
1385
|
super({
|
|
1372
1386
|
form: DdbForm.scalar,
|
|
@@ -1375,8 +1389,7 @@ class DdbInt extends DdbObj {
|
|
|
1375
1389
|
});
|
|
1376
1390
|
}
|
|
1377
1391
|
}
|
|
1378
|
-
|
|
1379
|
-
class DdbString extends DdbObj {
|
|
1392
|
+
export class DdbString extends DdbObj {
|
|
1380
1393
|
constructor(value) {
|
|
1381
1394
|
super({
|
|
1382
1395
|
form: DdbForm.scalar,
|
|
@@ -1385,8 +1398,7 @@ class DdbString extends DdbObj {
|
|
|
1385
1398
|
});
|
|
1386
1399
|
}
|
|
1387
1400
|
}
|
|
1388
|
-
|
|
1389
|
-
class DdbLong extends DdbObj {
|
|
1401
|
+
export class DdbLong extends DdbObj {
|
|
1390
1402
|
constructor(value) {
|
|
1391
1403
|
super({
|
|
1392
1404
|
form: DdbForm.scalar,
|
|
@@ -1395,8 +1407,7 @@ class DdbLong extends DdbObj {
|
|
|
1395
1407
|
});
|
|
1396
1408
|
}
|
|
1397
1409
|
}
|
|
1398
|
-
|
|
1399
|
-
class DdbDouble extends DdbObj {
|
|
1410
|
+
export class DdbDouble extends DdbObj {
|
|
1400
1411
|
constructor(value) {
|
|
1401
1412
|
super({
|
|
1402
1413
|
form: DdbForm.scalar,
|
|
@@ -1405,8 +1416,7 @@ class DdbDouble extends DdbObj {
|
|
|
1405
1416
|
});
|
|
1406
1417
|
}
|
|
1407
1418
|
}
|
|
1408
|
-
|
|
1409
|
-
class DdbDateTime extends DdbObj {
|
|
1419
|
+
export class DdbDateTime extends DdbObj {
|
|
1410
1420
|
constructor(value) {
|
|
1411
1421
|
super({
|
|
1412
1422
|
form: DdbForm.scalar,
|
|
@@ -1415,8 +1425,7 @@ class DdbDateTime extends DdbObj {
|
|
|
1415
1425
|
});
|
|
1416
1426
|
}
|
|
1417
1427
|
}
|
|
1418
|
-
|
|
1419
|
-
class DdbTimeStamp extends DdbObj {
|
|
1428
|
+
export class DdbTimeStamp extends DdbObj {
|
|
1420
1429
|
constructor(value) {
|
|
1421
1430
|
super({
|
|
1422
1431
|
form: DdbForm.scalar,
|
|
@@ -1425,8 +1434,7 @@ class DdbTimeStamp extends DdbObj {
|
|
|
1425
1434
|
});
|
|
1426
1435
|
}
|
|
1427
1436
|
}
|
|
1428
|
-
|
|
1429
|
-
class DdbNanoTimeStamp extends DdbObj {
|
|
1437
|
+
export class DdbNanoTimeStamp extends DdbObj {
|
|
1430
1438
|
constructor(value) {
|
|
1431
1439
|
super({
|
|
1432
1440
|
form: DdbForm.scalar,
|
|
@@ -1435,20 +1443,18 @@ class DdbNanoTimeStamp extends DdbObj {
|
|
|
1435
1443
|
});
|
|
1436
1444
|
}
|
|
1437
1445
|
}
|
|
1438
|
-
|
|
1439
|
-
class DdbPair extends DdbObj {
|
|
1446
|
+
export class DdbPair extends DdbObj {
|
|
1440
1447
|
constructor(l, r = null) {
|
|
1441
1448
|
super({
|
|
1442
1449
|
form: DdbForm.pair,
|
|
1443
1450
|
type: DdbType.int,
|
|
1444
1451
|
rows: 2,
|
|
1445
1452
|
cols: 1,
|
|
1446
|
-
value: Int32Array.of(l === null ?
|
|
1453
|
+
value: Int32Array.of(l === null ? nulls.int32 : l, r === null ? nulls.int32 : r)
|
|
1447
1454
|
});
|
|
1448
1455
|
}
|
|
1449
1456
|
}
|
|
1450
|
-
|
|
1451
|
-
class DdbFunction extends DdbObj {
|
|
1457
|
+
export class DdbFunction extends DdbObj {
|
|
1452
1458
|
constructor(name, type) {
|
|
1453
1459
|
super({
|
|
1454
1460
|
form: DdbForm.scalar,
|
|
@@ -1457,8 +1463,7 @@ class DdbFunction extends DdbObj {
|
|
|
1457
1463
|
});
|
|
1458
1464
|
}
|
|
1459
1465
|
}
|
|
1460
|
-
|
|
1461
|
-
class DdbVectorInt extends DdbObj {
|
|
1466
|
+
export class DdbVectorInt extends DdbObj {
|
|
1462
1467
|
constructor(ints, name) {
|
|
1463
1468
|
super({
|
|
1464
1469
|
form: DdbForm.vector,
|
|
@@ -1469,15 +1474,14 @@ class DdbVectorInt extends DdbObj {
|
|
|
1469
1474
|
ints
|
|
1470
1475
|
:
|
|
1471
1476
|
Int32Array.from(ints, v => v === null ?
|
|
1472
|
-
|
|
1477
|
+
nulls.int32
|
|
1473
1478
|
:
|
|
1474
1479
|
v),
|
|
1475
1480
|
name,
|
|
1476
1481
|
});
|
|
1477
1482
|
}
|
|
1478
1483
|
}
|
|
1479
|
-
|
|
1480
|
-
class DdbVectorDouble extends DdbObj {
|
|
1484
|
+
export class DdbVectorDouble extends DdbObj {
|
|
1481
1485
|
constructor(doubles, name) {
|
|
1482
1486
|
super({
|
|
1483
1487
|
form: DdbForm.vector,
|
|
@@ -1488,15 +1492,14 @@ class DdbVectorDouble extends DdbObj {
|
|
|
1488
1492
|
doubles
|
|
1489
1493
|
:
|
|
1490
1494
|
Float64Array.from(doubles, v => v === null ?
|
|
1491
|
-
|
|
1495
|
+
nulls.double
|
|
1492
1496
|
:
|
|
1493
1497
|
v),
|
|
1494
1498
|
name,
|
|
1495
1499
|
});
|
|
1496
1500
|
}
|
|
1497
1501
|
}
|
|
1498
|
-
|
|
1499
|
-
class DdbVectorString extends DdbObj {
|
|
1502
|
+
export class DdbVectorString extends DdbObj {
|
|
1500
1503
|
constructor(strings, name) {
|
|
1501
1504
|
super({
|
|
1502
1505
|
form: DdbForm.vector,
|
|
@@ -1508,8 +1511,7 @@ class DdbVectorString extends DdbObj {
|
|
|
1508
1511
|
});
|
|
1509
1512
|
}
|
|
1510
1513
|
}
|
|
1511
|
-
|
|
1512
|
-
class DdbVectorAny extends DdbObj {
|
|
1514
|
+
export class DdbVectorAny extends DdbObj {
|
|
1513
1515
|
constructor(objs, name) {
|
|
1514
1516
|
super({
|
|
1515
1517
|
form: DdbForm.vector,
|
|
@@ -1521,8 +1523,7 @@ class DdbVectorAny extends DdbObj {
|
|
|
1521
1523
|
});
|
|
1522
1524
|
}
|
|
1523
1525
|
}
|
|
1524
|
-
|
|
1525
|
-
class DdbVectorSymbol extends DdbObj {
|
|
1526
|
+
export class DdbVectorSymbol extends DdbObj {
|
|
1526
1527
|
constructor(strings, name) {
|
|
1527
1528
|
let map = new Map([
|
|
1528
1529
|
['', 0]
|
|
@@ -1551,8 +1552,7 @@ class DdbVectorSymbol extends DdbObj {
|
|
|
1551
1552
|
});
|
|
1552
1553
|
}
|
|
1553
1554
|
}
|
|
1554
|
-
|
|
1555
|
-
class DdbSetInt extends DdbObj {
|
|
1555
|
+
export class DdbSetInt extends DdbObj {
|
|
1556
1556
|
constructor(ints) {
|
|
1557
1557
|
super({
|
|
1558
1558
|
form: DdbForm.set,
|
|
@@ -1566,14 +1566,13 @@ class DdbSetInt extends DdbObj {
|
|
|
1566
1566
|
ints
|
|
1567
1567
|
:
|
|
1568
1568
|
Int32Array.from(ints, v => v === null ?
|
|
1569
|
-
|
|
1569
|
+
nulls.int32
|
|
1570
1570
|
:
|
|
1571
1571
|
v),
|
|
1572
1572
|
});
|
|
1573
1573
|
}
|
|
1574
1574
|
}
|
|
1575
|
-
|
|
1576
|
-
class DdbSetDouble extends DdbObj {
|
|
1575
|
+
export class DdbSetDouble extends DdbObj {
|
|
1577
1576
|
constructor(doubles) {
|
|
1578
1577
|
super({
|
|
1579
1578
|
form: DdbForm.set,
|
|
@@ -1587,14 +1586,13 @@ class DdbSetDouble extends DdbObj {
|
|
|
1587
1586
|
doubles
|
|
1588
1587
|
:
|
|
1589
1588
|
Int32Array.from(doubles, v => v === null ?
|
|
1590
|
-
|
|
1589
|
+
nulls.int32
|
|
1591
1590
|
:
|
|
1592
1591
|
v),
|
|
1593
1592
|
});
|
|
1594
1593
|
}
|
|
1595
1594
|
}
|
|
1596
|
-
|
|
1597
|
-
class DdbSetString extends DdbObj {
|
|
1595
|
+
export class DdbSetString extends DdbObj {
|
|
1598
1596
|
constructor(strings) {
|
|
1599
1597
|
if (strings instanceof Set)
|
|
1600
1598
|
strings = [...strings];
|
|
@@ -1607,12 +1605,11 @@ class DdbSetString extends DdbObj {
|
|
|
1607
1605
|
});
|
|
1608
1606
|
}
|
|
1609
1607
|
}
|
|
1610
|
-
exports.DdbSetString = DdbSetString;
|
|
1611
1608
|
/** Constructs a DdbDict object, which supports two usages:
|
|
1612
1609
|
- The incoming type is the keys of DdbObj<DdbVectorValue>, and the two parameters of values directly form the DdbDict of dict<keys.type, values.type>
|
|
1613
1610
|
- Pass in js object (type is Record<string, boolean | string | DdbObj>), automatically converted to DdbDict of dict<string, any>
|
|
1614
1611
|
*/
|
|
1615
|
-
class DdbDict extends DdbObj {
|
|
1612
|
+
export class DdbDict extends DdbObj {
|
|
1616
1613
|
constructor(arg0, arg1) {
|
|
1617
1614
|
if (arg1)
|
|
1618
1615
|
super({
|
|
@@ -1637,8 +1634,7 @@ class DdbDict extends DdbObj {
|
|
|
1637
1634
|
}
|
|
1638
1635
|
}
|
|
1639
1636
|
}
|
|
1640
|
-
|
|
1641
|
-
class DdbTable extends DdbObj {
|
|
1637
|
+
export class DdbTable extends DdbObj {
|
|
1642
1638
|
constructor(columns, name = '') {
|
|
1643
1639
|
super({
|
|
1644
1640
|
form: DdbForm.table,
|
|
@@ -1650,30 +1646,26 @@ class DdbTable extends DdbObj {
|
|
|
1650
1646
|
});
|
|
1651
1647
|
}
|
|
1652
1648
|
}
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
return (date === null || date === exports.nulls.int32) ?
|
|
1649
|
+
export function date2ms(date) {
|
|
1650
|
+
return (date === null || date === nulls.int32) ?
|
|
1656
1651
|
null
|
|
1657
1652
|
:
|
|
1658
|
-
|
|
1653
|
+
timezone_offset + 1000 * 3600 * 24 * date;
|
|
1659
1654
|
}
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
return (date === null || date === exports.nulls.int32) ?
|
|
1655
|
+
export function date2str(date, format = 'YYYY.MM.DD') {
|
|
1656
|
+
return (date === null || date === nulls.int32) ?
|
|
1663
1657
|
null
|
|
1664
1658
|
:
|
|
1665
|
-
(
|
|
1659
|
+
dayjs(date2ms(date)).format(format);
|
|
1666
1660
|
}
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
return (month === null || month === exports.nulls.int32) ?
|
|
1661
|
+
export function month2ms(month) {
|
|
1662
|
+
return (month === null || month === nulls.int32) ?
|
|
1670
1663
|
null
|
|
1671
1664
|
:
|
|
1672
|
-
(
|
|
1665
|
+
dayjs(month2str(month), 'YYYY.MM[M]').valueOf();
|
|
1673
1666
|
}
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
if (month === null || month === exports.nulls.int32)
|
|
1667
|
+
export function month2str(month) {
|
|
1668
|
+
if (month === null || month === nulls.int32)
|
|
1677
1669
|
return 'null';
|
|
1678
1670
|
if (month < 0)
|
|
1679
1671
|
return String(month);
|
|
@@ -1681,118 +1673,103 @@ function month2str(month) {
|
|
|
1681
1673
|
const year = Math.trunc(month / 12);
|
|
1682
1674
|
return `${String(year).padStart(4, '0')}.${String(_month + 1).padStart(2, '0')}M`;
|
|
1683
1675
|
}
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
return (time === null || time === exports.nulls.int32) ?
|
|
1676
|
+
export function time2ms(time) {
|
|
1677
|
+
return (time === null || time === nulls.int32) ?
|
|
1687
1678
|
null
|
|
1688
1679
|
:
|
|
1689
|
-
|
|
1680
|
+
timezone_offset + time;
|
|
1690
1681
|
}
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
return (time === null || time === exports.nulls.int32) ?
|
|
1682
|
+
export function time2str(time, format = 'HH:mm:ss.SSS') {
|
|
1683
|
+
return (time === null || time === nulls.int32) ?
|
|
1694
1684
|
null
|
|
1695
1685
|
:
|
|
1696
|
-
(
|
|
1686
|
+
dayjs(time2ms(time)).format(format);
|
|
1697
1687
|
}
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
return (minute === null || minute === exports.nulls.int32) ?
|
|
1688
|
+
export function minute2ms(minute) {
|
|
1689
|
+
return (minute === null || minute === nulls.int32) ?
|
|
1701
1690
|
null
|
|
1702
1691
|
:
|
|
1703
|
-
|
|
1692
|
+
timezone_offset + 60 * 1000 * minute;
|
|
1704
1693
|
}
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
return (minute === null || minute === exports.nulls.int32) ?
|
|
1694
|
+
export function minute2str(minute, format = 'HH:mm[m]') {
|
|
1695
|
+
return (minute === null || minute === nulls.int32) ?
|
|
1708
1696
|
'null'
|
|
1709
1697
|
:
|
|
1710
|
-
(
|
|
1698
|
+
dayjs(minute2ms(minute)).format(format);
|
|
1711
1699
|
}
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
return (second === null || second === exports.nulls.int32) ?
|
|
1700
|
+
export function second2ms(second) {
|
|
1701
|
+
return (second === null || second === nulls.int32) ?
|
|
1715
1702
|
null
|
|
1716
1703
|
:
|
|
1717
|
-
|
|
1704
|
+
timezone_offset + 1000 * second;
|
|
1718
1705
|
}
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
return (second === null || second === exports.nulls.int32) ?
|
|
1706
|
+
export function second2str(second, format = 'HH:mm:ss') {
|
|
1707
|
+
return (second === null || second === nulls.int32) ?
|
|
1722
1708
|
'null'
|
|
1723
1709
|
:
|
|
1724
|
-
(
|
|
1710
|
+
dayjs(second2ms(second)).format(format);
|
|
1725
1711
|
}
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
return (datetime === null || datetime === exports.nulls.int32) ?
|
|
1712
|
+
export function datetime2ms(datetime) {
|
|
1713
|
+
return (datetime === null || datetime === nulls.int32) ?
|
|
1729
1714
|
null
|
|
1730
1715
|
:
|
|
1731
|
-
|
|
1716
|
+
timezone_offset + 1000 * datetime;
|
|
1732
1717
|
}
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
return (datetime === null || datetime === exports.nulls.int32) ?
|
|
1718
|
+
export function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
|
|
1719
|
+
return (datetime === null || datetime === nulls.int32) ?
|
|
1736
1720
|
'null'
|
|
1737
1721
|
:
|
|
1738
|
-
(
|
|
1722
|
+
dayjs(datetime2ms(datetime)).format(format);
|
|
1739
1723
|
}
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
return (timestamp === null || timestamp === exports.nulls.int64) ?
|
|
1724
|
+
export function timestamp2ms(timestamp) {
|
|
1725
|
+
return (timestamp === null || timestamp === nulls.int64) ?
|
|
1743
1726
|
null
|
|
1744
1727
|
:
|
|
1745
|
-
|
|
1728
|
+
timezone_offset + Number(timestamp);
|
|
1746
1729
|
}
|
|
1747
|
-
exports.timestamp2ms = timestamp2ms;
|
|
1748
1730
|
/** format timestamp (bigint) to string
|
|
1749
1731
|
- timestamp: bigint value
|
|
1750
1732
|
- format?:
|
|
1751
1733
|
format string, default to `YYYY.MM.DD HH:mm:ss.SSS`
|
|
1752
1734
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1753
1735
|
*/
|
|
1754
|
-
function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
1755
|
-
return (timestamp === null || timestamp ===
|
|
1736
|
+
export function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
1737
|
+
return (timestamp === null || timestamp === nulls.int64) ?
|
|
1756
1738
|
'null'
|
|
1757
1739
|
:
|
|
1758
|
-
(
|
|
1740
|
+
dayjs(timestamp2ms(timestamp)).format(format);
|
|
1759
1741
|
}
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
return (datehour === null || datehour === exports.nulls.int32) ?
|
|
1742
|
+
export function datehour2ms(datehour) {
|
|
1743
|
+
return (datehour === null || datehour === nulls.int32) ?
|
|
1763
1744
|
null
|
|
1764
1745
|
:
|
|
1765
|
-
|
|
1746
|
+
timezone_offset + 1000 * 3600 * datehour;
|
|
1766
1747
|
}
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
return (datehour === null || datehour === exports.nulls.int32) ?
|
|
1748
|
+
export function datehour2str(datehour, format = 'YYYY.MM.DDTHH') {
|
|
1749
|
+
return (datehour === null || datehour === nulls.int32) ?
|
|
1770
1750
|
'null'
|
|
1771
1751
|
:
|
|
1772
|
-
(
|
|
1752
|
+
dayjs(timezone_offset + 1000 * 3600 * datehour).format(format);
|
|
1773
1753
|
}
|
|
1774
|
-
exports.datehour2str = datehour2str;
|
|
1775
1754
|
/** parse timestamp string to bigint value
|
|
1776
1755
|
- str: timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
|
|
1777
1756
|
- format?:
|
|
1778
1757
|
The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
|
|
1779
1758
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1780
1759
|
*/
|
|
1781
|
-
function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
1760
|
+
export function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
1782
1761
|
if (!str || str === 'null')
|
|
1783
|
-
return
|
|
1762
|
+
return nulls.int64;
|
|
1784
1763
|
if (str.length !== format.length)
|
|
1785
1764
|
throw new Error('The length of the timestamp string is not equal to the length of the format string');
|
|
1786
|
-
return BigInt(-
|
|
1787
|
-
(
|
|
1765
|
+
return BigInt(-timezone_offset +
|
|
1766
|
+
dayjs(str, format).valueOf());
|
|
1788
1767
|
}
|
|
1789
|
-
|
|
1790
|
-
function nanotime2ns(nanotime) {
|
|
1768
|
+
export function nanotime2ns(nanotime) {
|
|
1791
1769
|
return nanotimestamp2ns(nanotime);
|
|
1792
1770
|
}
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
if (nanotime === null || nanotime === exports.nulls.int64)
|
|
1771
|
+
export function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
|
|
1772
|
+
if (nanotime === null || nanotime === nulls.int64)
|
|
1796
1773
|
return 'null';
|
|
1797
1774
|
if (nanotime < 0n)
|
|
1798
1775
|
return String(nanotime);
|
|
@@ -1803,18 +1780,16 @@ function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
|
|
|
1803
1780
|
const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
|
|
1804
1781
|
if (i_nanosecond_start === -1)
|
|
1805
1782
|
throw new Error('The format string must contain the format for nanoseconds (SSSSSSSSS)');
|
|
1806
|
-
return ((
|
|
1783
|
+
return (dayjs(timezone_offset + (Number(nanotime) / 1000000)).format(format.slice(0, i_second_end)) +
|
|
1807
1784
|
format.slice(i_second_end, i_nanosecond_start) +
|
|
1808
1785
|
String(nanotime % 1000000000n).padStart(9, '0'));
|
|
1809
1786
|
}
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
return (nanotimestamp === null || nanotimestamp === exports.nulls.int64) ?
|
|
1787
|
+
export function nanotimestamp2ns(nanotimestamp) {
|
|
1788
|
+
return (nanotimestamp === null || nanotimestamp === nulls.int64) ?
|
|
1813
1789
|
null
|
|
1814
1790
|
:
|
|
1815
|
-
BigInt(
|
|
1791
|
+
BigInt(timezone_offset) * 1000000n + nanotimestamp;
|
|
1816
1792
|
}
|
|
1817
|
-
exports.nanotimestamp2ns = nanotimestamp2ns;
|
|
1818
1793
|
/** format nanotimestamp value (bigint) to string
|
|
1819
1794
|
- nanotimestamp: bigint value
|
|
1820
1795
|
- format?:
|
|
@@ -1822,14 +1797,14 @@ exports.nanotimestamp2ns = nanotimestamp2ns;
|
|
|
1822
1797
|
Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
|
|
1823
1798
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1824
1799
|
*/
|
|
1825
|
-
function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
1800
|
+
export function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
1826
1801
|
// tests:
|
|
1827
1802
|
// nanotimestamp2str(0n)
|
|
1828
1803
|
// nanotimestamp2str(-1n)
|
|
1829
1804
|
// nanotimestamp2str(-9_9999_9999n)
|
|
1830
1805
|
// nanotimestamp2str(-10_0000_0000n)
|
|
1831
1806
|
// nanotimestamp2str(-10_0000_0001n)
|
|
1832
|
-
if (nanotimestamp === null || nanotimestamp ===
|
|
1807
|
+
if (nanotimestamp === null || nanotimestamp === nulls.int64)
|
|
1833
1808
|
return 'null';
|
|
1834
1809
|
const i_second_start = format.indexOf('ss');
|
|
1835
1810
|
if (i_second_start === -1)
|
|
@@ -1840,7 +1815,7 @@ function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSS
|
|
|
1840
1815
|
throw new Error('The format string must contain the format for nanoseconds (SSSSSSSSS)');
|
|
1841
1816
|
const remainder = nanotimestamp % 1000000000n;
|
|
1842
1817
|
const borrow = remainder < 0n;
|
|
1843
|
-
return ((
|
|
1818
|
+
return (dayjs(timezone_offset +
|
|
1844
1819
|
// 去掉 9 位的纳秒部分,转化为毫秒
|
|
1845
1820
|
Number((nanotimestamp - remainder + (borrow ? -1000000000n : 0n)) / 1000000n)).format(format.slice(0, i_second_end)) +
|
|
1846
1821
|
format.slice(i_second_end, i_nanosecond_start) +
|
|
@@ -1849,7 +1824,6 @@ function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSS
|
|
|
1849
1824
|
:
|
|
1850
1825
|
remainder).padStart(9, '0'));
|
|
1851
1826
|
}
|
|
1852
|
-
exports.nanotimestamp2str = nanotimestamp2str;
|
|
1853
1827
|
/** parse nano timestamp string to bigint value
|
|
1854
1828
|
- str: nano timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
|
|
1855
1829
|
- format?:
|
|
@@ -1857,9 +1831,9 @@ exports.nanotimestamp2str = nanotimestamp2str;
|
|
|
1857
1831
|
Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
|
|
1858
1832
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1859
1833
|
*/
|
|
1860
|
-
function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
1834
|
+
export function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
1861
1835
|
if (!str || str === 'null')
|
|
1862
|
-
return
|
|
1836
|
+
return nulls.int64;
|
|
1863
1837
|
if (str.length !== format.length)
|
|
1864
1838
|
throw new Error('nanotimestamp string length is not equal to format string length');
|
|
1865
1839
|
const i_second_start = format.indexOf('ss');
|
|
@@ -1869,13 +1843,12 @@ function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
|
1869
1843
|
const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
|
|
1870
1844
|
if (i_nanosecond_start === -1)
|
|
1871
1845
|
throw new Error('Format string must contain nanosecond format (SSSSSSSSS)');
|
|
1872
|
-
return (BigInt(-
|
|
1873
|
-
(
|
|
1846
|
+
return (BigInt(-timezone_offset +
|
|
1847
|
+
dayjs(str.slice(0, i_second_end), format.slice(0, i_second_end)).valueOf()) * 1000000n
|
|
1874
1848
|
+
|
|
1875
1849
|
BigInt(str.slice(i_nanosecond_start, i_nanosecond_start + 9)));
|
|
1876
1850
|
}
|
|
1877
|
-
|
|
1878
|
-
function ipaddr2str(buffer, le = true, ipv6) {
|
|
1851
|
+
export function ipaddr2str(buffer, le = true, ipv6) {
|
|
1879
1852
|
let buf = buffer;
|
|
1880
1853
|
if (le)
|
|
1881
1854
|
buf = buffer.slice().reverse();
|
|
@@ -1886,21 +1859,51 @@ function ipaddr2str(buffer, le = true, ipv6) {
|
|
|
1886
1859
|
else // ipv4
|
|
1887
1860
|
return buf.subarray(12).join('.');
|
|
1888
1861
|
}
|
|
1889
|
-
|
|
1890
|
-
function uuid2str(buffer, le = true) {
|
|
1862
|
+
export function uuid2str(buffer, le = true) {
|
|
1891
1863
|
const str = int1282str(buffer, le);
|
|
1892
1864
|
return `${str.slice(0, 8)}-${str.slice(8, 12)}-${str.slice(12, 16)}-${str.slice(16, 20)}-${str.slice(20)}`;
|
|
1893
1865
|
}
|
|
1894
|
-
|
|
1895
|
-
function int1282str(buffer, le = true) {
|
|
1866
|
+
export function int1282str(buffer, le = true) {
|
|
1896
1867
|
let buf = buffer;
|
|
1897
1868
|
if (le)
|
|
1898
1869
|
buf = buffer.slice().reverse();
|
|
1899
1870
|
return [...buf].map(x => x.toString(16)
|
|
1900
1871
|
.padStart(2, '0')).join('');
|
|
1901
1872
|
}
|
|
1902
|
-
|
|
1903
|
-
|
|
1873
|
+
export class DDB {
|
|
1874
|
+
/** 当前的 session id (http 或 tcp) */
|
|
1875
|
+
sid = '0';
|
|
1876
|
+
/** utf-8 text decoder */
|
|
1877
|
+
dec = new TextDecoder('utf-8');
|
|
1878
|
+
enc = new TextEncoder();
|
|
1879
|
+
/** DolphinDB WebSocket URL
|
|
1880
|
+
e.g. `ws://127.0.0.1:8848/`, `wss://dolphindb.com`
|
|
1881
|
+
*/
|
|
1882
|
+
url;
|
|
1883
|
+
websocket = null;
|
|
1884
|
+
/** little endian (server) */
|
|
1885
|
+
le = true;
|
|
1886
|
+
/** little endian (client) */
|
|
1887
|
+
static le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
|
|
1888
|
+
/** 是否在建立连接后自动登录,默认 true */
|
|
1889
|
+
autologin = true;
|
|
1890
|
+
/** DolphinDB 登录用户名 */
|
|
1891
|
+
username = 'admin';
|
|
1892
|
+
/** DolphinDB 登录密码 */
|
|
1893
|
+
password = '123456';
|
|
1894
|
+
/** python session flag (2048) */
|
|
1895
|
+
python = false;
|
|
1896
|
+
print_message_buffer = false;
|
|
1897
|
+
print_object_buffer = false;
|
|
1898
|
+
print_message = true;
|
|
1899
|
+
parse_object = true;
|
|
1900
|
+
/** DdbMessage listeners */
|
|
1901
|
+
listeners = [];
|
|
1902
|
+
pconnect = Promise.resolve();
|
|
1903
|
+
presult = Promise.resolve(null);
|
|
1904
|
+
get connected() {
|
|
1905
|
+
return this.websocket?.readyState === WebSocket.OPEN;
|
|
1906
|
+
}
|
|
1904
1907
|
/**
|
|
1905
1908
|
Initialize an instance of DolphinDB Client using the WebSocket URL
|
|
1906
1909
|
(without establishing an actual network connection)
|
|
@@ -1923,30 +1926,6 @@ class DDB {
|
|
|
1923
1926
|
})
|
|
1924
1927
|
*/
|
|
1925
1928
|
constructor(url, options = {}) {
|
|
1926
|
-
/** 当前的 session id (http 或 tcp) */
|
|
1927
|
-
this.sid = '0';
|
|
1928
|
-
/** utf-8 text decoder */
|
|
1929
|
-
this.dec = new TextDecoder('utf-8');
|
|
1930
|
-
this.enc = new TextEncoder();
|
|
1931
|
-
this.websocket = null;
|
|
1932
|
-
/** little endian (server) */
|
|
1933
|
-
this.le = true;
|
|
1934
|
-
/** 是否在建立连接后自动登录,默认 true */
|
|
1935
|
-
this.autologin = true;
|
|
1936
|
-
/** DolphinDB 登录用户名 */
|
|
1937
|
-
this.username = 'admin';
|
|
1938
|
-
/** DolphinDB 登录密码 */
|
|
1939
|
-
this.password = '123456';
|
|
1940
|
-
/** python session flag (2048) */
|
|
1941
|
-
this.python = false;
|
|
1942
|
-
this.print_message_buffer = false;
|
|
1943
|
-
this.print_object_buffer = false;
|
|
1944
|
-
this.print_message = true;
|
|
1945
|
-
this.parse_object = true;
|
|
1946
|
-
/** DdbMessage listeners */
|
|
1947
|
-
this.listeners = [];
|
|
1948
|
-
this.pconnect = Promise.resolve();
|
|
1949
|
-
this.presult = Promise.resolve(null);
|
|
1950
1929
|
this.url = url;
|
|
1951
1930
|
if (options.autologin !== undefined)
|
|
1952
1931
|
this.autologin = options.autologin;
|
|
@@ -1957,9 +1936,6 @@ class DDB {
|
|
|
1957
1936
|
if (options.python !== undefined)
|
|
1958
1937
|
this.python = options.python;
|
|
1959
1938
|
}
|
|
1960
|
-
get connected() {
|
|
1961
|
-
return this.websocket?.readyState === ws_1.WebSocket.OPEN;
|
|
1962
|
-
}
|
|
1963
1939
|
on_message(event) { }
|
|
1964
1940
|
/** Establish the actual WebSocket connection to the DolphinDB corresponding to the URL
|
|
1965
1941
|
- options?:
|
|
@@ -1981,7 +1957,7 @@ class DDB {
|
|
|
1981
1957
|
if (options.python !== undefined)
|
|
1982
1958
|
this.python = options.python;
|
|
1983
1959
|
this.disconnect();
|
|
1984
|
-
await
|
|
1960
|
+
await connect_websocket(this.url, {
|
|
1985
1961
|
protocols: this.python ? ['python'] : [],
|
|
1986
1962
|
on_open: async (event, websocket) => {
|
|
1987
1963
|
this.websocket = websocket;
|
|
@@ -2120,7 +2096,7 @@ class DDB {
|
|
|
2120
2096
|
try {
|
|
2121
2097
|
const buf = new Uint8Array(buffer);
|
|
2122
2098
|
if (this.print_message_buffer)
|
|
2123
|
-
console.log(
|
|
2099
|
+
console.log(typed_array_to_buffer(buf));
|
|
2124
2100
|
const message = this.parse_message(buf, parse_object);
|
|
2125
2101
|
listener?.(message, this);
|
|
2126
2102
|
for (const listener of _handlers)
|
|
@@ -2163,7 +2139,7 @@ class DDB {
|
|
|
2163
2139
|
return 'connect\n';
|
|
2164
2140
|
}
|
|
2165
2141
|
})());
|
|
2166
|
-
this.websocket.send(
|
|
2142
|
+
this.websocket.send(concat([
|
|
2167
2143
|
this.enc.encode(`API2 ${this.sid} ${command.length} / ${this.get_rpc_options({ urgent })}\n`),
|
|
2168
2144
|
command,
|
|
2169
2145
|
...args.map((arg) => arg.pack())
|
|
@@ -2277,7 +2253,7 @@ class DDB {
|
|
|
2277
2253
|
};
|
|
2278
2254
|
const buf_obj = buf.subarray(i_lf_1 + 1);
|
|
2279
2255
|
if (this.print_object_buffer)
|
|
2280
|
-
console.log(
|
|
2256
|
+
console.log(typed_array_to_buffer(buf_obj));
|
|
2281
2257
|
return {
|
|
2282
2258
|
type: 'object',
|
|
2283
2259
|
data: parse_object ?
|
|
@@ -2293,7 +2269,4 @@ class DDB {
|
|
|
2293
2269
|
};
|
|
2294
2270
|
}
|
|
2295
2271
|
}
|
|
2296
|
-
exports.DDB = DDB;
|
|
2297
|
-
/** little endian (client) */
|
|
2298
|
-
DDB.le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
|
|
2299
2272
|
//# sourceMappingURL=index.js.map
|