dolphindb 2.0.512 → 2.0.513
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 +10 -0
- package/browser.js +260 -22
- package/browser.js.map +1 -1
- package/index.d.ts +10 -0
- package/index.js +304 -19
- package/index.js.map +1 -1
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -179,6 +179,7 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
|
|
|
179
179
|
to_rows<T extends Record<string, any> = Record<string, any>>(): T[];
|
|
180
180
|
to_dict<T = Record<string, any>>(): T;
|
|
181
181
|
}
|
|
182
|
+
export declare function format(type: DdbType, value: DdbValue, le: boolean, options: InspectOptions): string;
|
|
182
183
|
export declare class DdbVoid extends DdbObj<undefined> {
|
|
183
184
|
constructor();
|
|
184
185
|
}
|
|
@@ -243,6 +244,10 @@ export declare class DdbTable extends DdbObj<DdbObj[]> {
|
|
|
243
244
|
constructor(columns: DdbObj[], name?: string);
|
|
244
245
|
}
|
|
245
246
|
export declare function date2str(date: number, format?: string): string;
|
|
247
|
+
export declare function month2str(month: number | null): string;
|
|
248
|
+
export declare function time2str(time: number, format?: string): string;
|
|
249
|
+
export declare function minute2str(minute: number | null, format?: string): string;
|
|
250
|
+
export declare function second2str(second: number | null, format?: string): string;
|
|
246
251
|
export declare function datetime2str(datetime: number, format?: string): string;
|
|
247
252
|
/** format timestamp (bigint) to string
|
|
248
253
|
- timestamp: bigint value
|
|
@@ -251,6 +256,7 @@ export declare function datetime2str(datetime: number, format?: string): string;
|
|
|
251
256
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
252
257
|
*/
|
|
253
258
|
export declare function timestamp2str(timestamp: bigint, format?: string): string;
|
|
259
|
+
export declare function datehour2str(datehour: number, format?: string): string;
|
|
254
260
|
/** parse timestamp string to bigint value
|
|
255
261
|
- str: timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
|
|
256
262
|
- format?:
|
|
@@ -258,6 +264,7 @@ export declare function timestamp2str(timestamp: bigint, format?: string): strin
|
|
|
258
264
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
259
265
|
*/
|
|
260
266
|
export declare function str2timestamp(str: string, format?: string): bigint;
|
|
267
|
+
export declare function nanotime2str(nanotime: bigint, format?: string): string;
|
|
261
268
|
/** format nanotimestamp value (bigint) to string
|
|
262
269
|
- nanotimestamp: bigint value
|
|
263
270
|
- format?:
|
|
@@ -274,6 +281,9 @@ export declare function nanotimestamp2str(nanotimestamp: bigint, format?: string
|
|
|
274
281
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
275
282
|
*/
|
|
276
283
|
export declare function str2nanotimestamp(str: string, format?: string): bigint;
|
|
284
|
+
export declare function ipaddr2str(buffer: Uint8Array, le?: boolean): string;
|
|
285
|
+
export declare function uuid2str(buffer: Uint8Array, le?: boolean): string;
|
|
286
|
+
export declare function int1282str(buffer: Uint8Array, le?: boolean): string;
|
|
277
287
|
export declare class DDB {
|
|
278
288
|
/** 当前的 session id (http 或 tcp) */
|
|
279
289
|
sid: string;
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DDB = exports.str2nanotimestamp = exports.nanotimestamp2str = exports.str2timestamp = exports.timestamp2str = exports.datetime2str = exports.date2str = exports.DdbTable = 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.DdbObj = exports.timezone_offset = exports.nulls = exports.DdbDurationUnit = exports.DdbFunctionType = exports.DdbType = exports.DdbForm = void 0;
|
|
3
|
+
exports.DDB = exports.int1282str = exports.uuid2str = exports.ipaddr2str = exports.str2nanotimestamp = exports.nanotimestamp2str = exports.nanotime2str = exports.str2timestamp = exports.datehour2str = exports.timestamp2str = exports.datetime2str = exports.second2str = exports.minute2str = exports.time2str = exports.month2str = exports.date2str = exports.DdbTable = 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.DdbDurationUnit = exports.DdbFunctionType = exports.DdbType = exports.DdbForm = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const ws_1 = require("ws");
|
|
6
6
|
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
@@ -905,30 +905,69 @@ class DdbObj {
|
|
|
905
905
|
case DdbForm.set:
|
|
906
906
|
return `set<${tname}>[${this.rows}]`;
|
|
907
907
|
case DdbForm.table:
|
|
908
|
-
return `table[${this.rows}
|
|
908
|
+
return `table[${this.rows}r][${this.cols}c]`;
|
|
909
909
|
case DdbForm.dict:
|
|
910
910
|
return `dict<${DdbType[this.value[0].type]}, ${DdbType[this.value[1].type]}>`;
|
|
911
911
|
case DdbForm.matrix:
|
|
912
|
-
return `matrix<${DdbType[this.type]}>[${this.rows}
|
|
912
|
+
return `matrix<${DdbType[this.type]}>[${this.rows}r][${this.cols}c]`;
|
|
913
913
|
default:
|
|
914
914
|
return `${DdbForm[this.form]} ${tname}`;
|
|
915
915
|
}
|
|
916
916
|
})();
|
|
917
917
|
const data = (() => {
|
|
918
918
|
switch (this.form) {
|
|
919
|
-
case DdbForm.pair:
|
|
920
|
-
return `${(0, utils_js_1.inspect)(this.value[0], options)}, ${(0, utils_js_1.inspect)(this.value[1], options)}`;
|
|
921
919
|
case DdbForm.scalar:
|
|
920
|
+
return format(this.type, this.value, this.le, options);
|
|
921
|
+
case DdbForm.vector:
|
|
922
|
+
case DdbForm.pair:
|
|
923
|
+
case DdbForm.set: {
|
|
924
|
+
const form = this.form;
|
|
925
|
+
function format_array(items, ellipsis) {
|
|
926
|
+
const str_items = items.join(', ') + (ellipsis ? ', ...' : '');
|
|
927
|
+
return form === DdbForm.pair ?
|
|
928
|
+
str_items
|
|
929
|
+
:
|
|
930
|
+
str_items.bracket('square');
|
|
931
|
+
}
|
|
922
932
|
switch (this.type) {
|
|
923
|
-
case DdbType.
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
933
|
+
case DdbType.symbol_extended: {
|
|
934
|
+
const limit = 50;
|
|
935
|
+
const { base, data } = this.value;
|
|
936
|
+
let items = new Array(Math.min(limit, data.length));
|
|
937
|
+
for (let i = 0; i < items.length; i++)
|
|
938
|
+
items[i] = (0, utils_js_1.inspect)(base[data[i]], options);
|
|
939
|
+
return format_array(items, data.length > limit);
|
|
940
|
+
}
|
|
941
|
+
case DdbType.uuid:
|
|
942
|
+
case DdbType.int128:
|
|
943
|
+
case DdbType.ipaddr: {
|
|
944
|
+
const limit = 10;
|
|
945
|
+
const value = this.value;
|
|
946
|
+
const len_data = value.length / 16;
|
|
947
|
+
let items = new Array(Math.min(limit, len_data));
|
|
948
|
+
for (let i = 0; i < items.length; i++)
|
|
949
|
+
items[i] = format(this.type, value.subarray(16 * i, 16 * (i + 1)), this.le, options);
|
|
950
|
+
return format_array(items, len_data > limit);
|
|
951
|
+
}
|
|
952
|
+
case DdbType.complex:
|
|
953
|
+
case DdbType.point: {
|
|
954
|
+
const limit = 20;
|
|
955
|
+
const value = this.value;
|
|
956
|
+
const len_data = value.length / 2;
|
|
957
|
+
let items = new Array(Math.min(limit, len_data));
|
|
958
|
+
for (let i = 0; i < items.length; i++)
|
|
959
|
+
items[i] = format(this.type, value.subarray(2 * i, 2 * (i + 1)), this.le, options);
|
|
960
|
+
return format_array(items, len_data > limit);
|
|
961
|
+
}
|
|
962
|
+
default: {
|
|
963
|
+
const limit = 50;
|
|
964
|
+
let items = new Array(Math.min(limit, this.value.length));
|
|
965
|
+
for (let i = 0; i < items.length; i++)
|
|
966
|
+
items[i] = format(this.type, this.value[i], this.le, options);
|
|
967
|
+
return format_array(items, this.value.length > limit);
|
|
929
968
|
}
|
|
930
969
|
}
|
|
931
|
-
|
|
970
|
+
}
|
|
932
971
|
}
|
|
933
972
|
if (this.value instanceof Uint8Array)
|
|
934
973
|
return (0, utils_js_1.inspect)((0, utils_js_1.typed_array_to_buffer)(this.value), options);
|
|
@@ -938,7 +977,7 @@ class DdbObj {
|
|
|
938
977
|
}
|
|
939
978
|
to_rows() {
|
|
940
979
|
if (this.form !== DdbForm.table)
|
|
941
|
-
throw new Error('this.form
|
|
980
|
+
throw new Error('this.form 不是 DdbForm.table, 不能 to_rows');
|
|
942
981
|
let rows = new Array(this.rows);
|
|
943
982
|
for (let i = 0; i < this.rows; i++) {
|
|
944
983
|
let row = {};
|
|
@@ -971,7 +1010,7 @@ class DdbObj {
|
|
|
971
1010
|
}
|
|
972
1011
|
to_dict() {
|
|
973
1012
|
if (this.form !== DdbForm.dict)
|
|
974
|
-
throw new Error('this.form
|
|
1013
|
+
throw new Error('this.form 不是 DdbForm.dict, 不能转换为 Object');
|
|
975
1014
|
const [{ value: keys }, { value: values }] = this.value;
|
|
976
1015
|
let obj = {};
|
|
977
1016
|
for (let i = 0; i < this.rows; i++)
|
|
@@ -988,6 +1027,173 @@ DdbObj.enc = new TextEncoder();
|
|
|
988
1027
|
DdbObj.symbol_bases = {};
|
|
989
1028
|
/** little endian (client) */
|
|
990
1029
|
DdbObj.le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
|
|
1030
|
+
function format(type, value, le, options) {
|
|
1031
|
+
switch (type) {
|
|
1032
|
+
case DdbType.bool:
|
|
1033
|
+
return (0, utils_js_1.inspect)((value === null || value === exports.nulls.int8) ?
|
|
1034
|
+
null
|
|
1035
|
+
:
|
|
1036
|
+
Boolean(value), options);
|
|
1037
|
+
case DdbType.char:
|
|
1038
|
+
return (0, utils_js_1.inspect)((value === null || value === exports.nulls.int8) ?
|
|
1039
|
+
null
|
|
1040
|
+
:
|
|
1041
|
+
value, options);
|
|
1042
|
+
case DdbType.short:
|
|
1043
|
+
return (0, utils_js_1.inspect)((value === null || value === exports.nulls.int16) ?
|
|
1044
|
+
null
|
|
1045
|
+
:
|
|
1046
|
+
value, options);
|
|
1047
|
+
case DdbType.int:
|
|
1048
|
+
return (0, utils_js_1.inspect)((value === null || value === exports.nulls.int32) ?
|
|
1049
|
+
null
|
|
1050
|
+
:
|
|
1051
|
+
value, options);
|
|
1052
|
+
case DdbType.long:
|
|
1053
|
+
return (value === null || value === exports.nulls.int64) ?
|
|
1054
|
+
'null'
|
|
1055
|
+
:
|
|
1056
|
+
options.colors ?
|
|
1057
|
+
String(value).green
|
|
1058
|
+
:
|
|
1059
|
+
String(value);
|
|
1060
|
+
case DdbType.date:
|
|
1061
|
+
return (value === null || value === exports.nulls.int32) ?
|
|
1062
|
+
'null'
|
|
1063
|
+
:
|
|
1064
|
+
options.colors ?
|
|
1065
|
+
date2str(value).green
|
|
1066
|
+
:
|
|
1067
|
+
date2str(value);
|
|
1068
|
+
case DdbType.month:
|
|
1069
|
+
return (value === null || value === exports.nulls.int32) ?
|
|
1070
|
+
'null'
|
|
1071
|
+
:
|
|
1072
|
+
options.colors ?
|
|
1073
|
+
month2str(value).green
|
|
1074
|
+
:
|
|
1075
|
+
month2str(value);
|
|
1076
|
+
case DdbType.time:
|
|
1077
|
+
return (value === null || value === exports.nulls.int32) ?
|
|
1078
|
+
'null'
|
|
1079
|
+
:
|
|
1080
|
+
options.colors ?
|
|
1081
|
+
time2str(value).green
|
|
1082
|
+
:
|
|
1083
|
+
time2str(value);
|
|
1084
|
+
case DdbType.minute:
|
|
1085
|
+
return (value === null || value === exports.nulls.int32) ?
|
|
1086
|
+
'null'
|
|
1087
|
+
:
|
|
1088
|
+
options.colors ?
|
|
1089
|
+
minute2str(value).green
|
|
1090
|
+
:
|
|
1091
|
+
minute2str(value);
|
|
1092
|
+
case DdbType.second:
|
|
1093
|
+
return (value === null || value === exports.nulls.int32) ?
|
|
1094
|
+
'null'
|
|
1095
|
+
:
|
|
1096
|
+
options.colors ?
|
|
1097
|
+
second2str(value).green
|
|
1098
|
+
:
|
|
1099
|
+
second2str(value);
|
|
1100
|
+
case DdbType.datetime:
|
|
1101
|
+
return (value === null || value === exports.nulls.int32) ?
|
|
1102
|
+
'null'
|
|
1103
|
+
:
|
|
1104
|
+
options.colors ?
|
|
1105
|
+
datetime2str(value).green
|
|
1106
|
+
:
|
|
1107
|
+
datetime2str(value);
|
|
1108
|
+
case DdbType.timestamp:
|
|
1109
|
+
return (value === null || value === exports.nulls.int64) ?
|
|
1110
|
+
'null'
|
|
1111
|
+
:
|
|
1112
|
+
options.colors ?
|
|
1113
|
+
timestamp2str(value).green
|
|
1114
|
+
:
|
|
1115
|
+
timestamp2str(value);
|
|
1116
|
+
case DdbType.nanotime:
|
|
1117
|
+
return (value === null || value === exports.nulls.int64) ?
|
|
1118
|
+
'null'
|
|
1119
|
+
:
|
|
1120
|
+
options.colors ?
|
|
1121
|
+
nanotime2str(value).green
|
|
1122
|
+
:
|
|
1123
|
+
nanotime2str(value);
|
|
1124
|
+
case DdbType.nanotimestamp:
|
|
1125
|
+
return (value === null || value === exports.nulls.int64) ?
|
|
1126
|
+
'null'
|
|
1127
|
+
:
|
|
1128
|
+
options.colors ?
|
|
1129
|
+
nanotimestamp2str(value).green
|
|
1130
|
+
:
|
|
1131
|
+
nanotimestamp2str(value);
|
|
1132
|
+
case DdbType.float:
|
|
1133
|
+
return (value === null || value === exports.nulls.float32) ?
|
|
1134
|
+
'null'
|
|
1135
|
+
:
|
|
1136
|
+
(0, utils_js_1.inspect)(value, options);
|
|
1137
|
+
case DdbType.double:
|
|
1138
|
+
return (value === null || value === exports.nulls.double) ?
|
|
1139
|
+
'null'
|
|
1140
|
+
:
|
|
1141
|
+
(0, utils_js_1.inspect)(value, options);
|
|
1142
|
+
case DdbType.symbol:
|
|
1143
|
+
case DdbType.string:
|
|
1144
|
+
return (0, utils_js_1.inspect)(value, options);
|
|
1145
|
+
case DdbType.uuid:
|
|
1146
|
+
return options.colors ?
|
|
1147
|
+
uuid2str(value, le).green
|
|
1148
|
+
:
|
|
1149
|
+
uuid2str(value, le);
|
|
1150
|
+
case DdbType.functiondef:
|
|
1151
|
+
return (0, utils_js_1.inspect)(value.name, options);
|
|
1152
|
+
case DdbType.handle:
|
|
1153
|
+
case DdbType.code:
|
|
1154
|
+
return (0, utils_js_1.inspect)(value, options);
|
|
1155
|
+
case DdbType.datehour:
|
|
1156
|
+
return (value === null || value === exports.nulls.int32) ?
|
|
1157
|
+
'null'
|
|
1158
|
+
:
|
|
1159
|
+
options.colors ?
|
|
1160
|
+
datehour2str(value).green
|
|
1161
|
+
:
|
|
1162
|
+
datehour2str(value);
|
|
1163
|
+
case DdbType.ipaddr:
|
|
1164
|
+
return options.colors ?
|
|
1165
|
+
ipaddr2str(value, le).green
|
|
1166
|
+
:
|
|
1167
|
+
ipaddr2str(value, le);
|
|
1168
|
+
case DdbType.int128:
|
|
1169
|
+
return options.colors ?
|
|
1170
|
+
int1282str(value, le).green
|
|
1171
|
+
:
|
|
1172
|
+
int1282str(value, le);
|
|
1173
|
+
case DdbType.blob:
|
|
1174
|
+
return (0, utils_js_1.inspect)(DdbObj.dec.decode(value.subarray(0, 1000)), options);
|
|
1175
|
+
case DdbType.complex:
|
|
1176
|
+
case DdbType.point: {
|
|
1177
|
+
let [x, y] = value;
|
|
1178
|
+
if (x === exports.nulls.double)
|
|
1179
|
+
x = null;
|
|
1180
|
+
if (y === exports.nulls.double)
|
|
1181
|
+
y = null;
|
|
1182
|
+
return options.colors ?
|
|
1183
|
+
`(${String(x).green}, ${String(y).green})`
|
|
1184
|
+
:
|
|
1185
|
+
`(${String(x)}, ${String(y)})`;
|
|
1186
|
+
}
|
|
1187
|
+
case DdbType.duration: {
|
|
1188
|
+
const { data, unit } = value;
|
|
1189
|
+
const str = `${data}${DdbDurationUnit[unit]}`;
|
|
1190
|
+
return options.colors ? str.green : str;
|
|
1191
|
+
}
|
|
1192
|
+
default:
|
|
1193
|
+
return (0, utils_js_1.inspect)(value, options);
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
exports.format = format;
|
|
991
1197
|
class DdbVoid extends DdbObj {
|
|
992
1198
|
constructor() {
|
|
993
1199
|
super({
|
|
@@ -1298,14 +1504,48 @@ class DdbTable extends DdbObj {
|
|
|
1298
1504
|
}
|
|
1299
1505
|
exports.DdbTable = DdbTable;
|
|
1300
1506
|
function date2str(date, format = 'YYYY.MM.DD') {
|
|
1301
|
-
return date === exports.nulls.int32 ?
|
|
1507
|
+
return (date === null || date === exports.nulls.int32) ?
|
|
1302
1508
|
''
|
|
1303
1509
|
:
|
|
1304
1510
|
(0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * 24 * date).format(format);
|
|
1305
1511
|
}
|
|
1306
1512
|
exports.date2str = date2str;
|
|
1513
|
+
function month2str(month) {
|
|
1514
|
+
if (month === null || month === exports.nulls.int32)
|
|
1515
|
+
return '';
|
|
1516
|
+
if (month < 0)
|
|
1517
|
+
return String(month);
|
|
1518
|
+
let _month = month % 12;
|
|
1519
|
+
let year = Math.floor(month / 12);
|
|
1520
|
+
return `${String(year).padStart(4, '0')}.${String(_month + 1).padStart(2, '0')}`;
|
|
1521
|
+
}
|
|
1522
|
+
exports.month2str = month2str;
|
|
1523
|
+
function time2str(time, format = 'HH:mm:ss.SSS') {
|
|
1524
|
+
return (time === null || time === exports.nulls.int32) ?
|
|
1525
|
+
''
|
|
1526
|
+
:
|
|
1527
|
+
(0, dayjs_1.default)(exports.timezone_offset + time)
|
|
1528
|
+
.format(format);
|
|
1529
|
+
}
|
|
1530
|
+
exports.time2str = time2str;
|
|
1531
|
+
function minute2str(minute, format = 'HH:mm') {
|
|
1532
|
+
return (minute === null || minute === exports.nulls.int32) ?
|
|
1533
|
+
''
|
|
1534
|
+
:
|
|
1535
|
+
(0, dayjs_1.default)(exports.timezone_offset + 60 * 1000 * minute)
|
|
1536
|
+
.format(format);
|
|
1537
|
+
}
|
|
1538
|
+
exports.minute2str = minute2str;
|
|
1539
|
+
function second2str(second, format = 'HH:mm:ss') {
|
|
1540
|
+
return (second === null || second === exports.nulls.int32) ?
|
|
1541
|
+
''
|
|
1542
|
+
:
|
|
1543
|
+
(0, dayjs_1.default)(exports.timezone_offset + 1000 * second)
|
|
1544
|
+
.format(format);
|
|
1545
|
+
}
|
|
1546
|
+
exports.second2str = second2str;
|
|
1307
1547
|
function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
|
|
1308
|
-
return datetime === exports.nulls.int32 ?
|
|
1548
|
+
return (datetime === null || datetime === exports.nulls.int32) ?
|
|
1309
1549
|
''
|
|
1310
1550
|
:
|
|
1311
1551
|
(0, dayjs_1.default)(exports.timezone_offset + 1000 * datetime).format(format);
|
|
@@ -1318,12 +1558,19 @@ exports.datetime2str = datetime2str;
|
|
|
1318
1558
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1319
1559
|
*/
|
|
1320
1560
|
function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
1321
|
-
return timestamp === exports.nulls.int64 ?
|
|
1561
|
+
return (timestamp === null || timestamp === exports.nulls.int64) ?
|
|
1322
1562
|
''
|
|
1323
1563
|
:
|
|
1324
1564
|
(0, dayjs_1.default)(exports.timezone_offset + Number(timestamp)).format(format);
|
|
1325
1565
|
}
|
|
1326
1566
|
exports.timestamp2str = timestamp2str;
|
|
1567
|
+
function datehour2str(datehour, format = 'YYYY.MM.DD.HH') {
|
|
1568
|
+
return (datehour === null || datehour === exports.nulls.int32) ?
|
|
1569
|
+
''
|
|
1570
|
+
:
|
|
1571
|
+
(0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * datehour).format(format);
|
|
1572
|
+
}
|
|
1573
|
+
exports.datehour2str = datehour2str;
|
|
1327
1574
|
/** parse timestamp string to bigint value
|
|
1328
1575
|
- str: timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
|
|
1329
1576
|
- format?:
|
|
@@ -1339,6 +1586,19 @@ function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
|
1339
1586
|
(0, dayjs_1.default)(str, format).valueOf());
|
|
1340
1587
|
}
|
|
1341
1588
|
exports.str2timestamp = str2timestamp;
|
|
1589
|
+
function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
|
|
1590
|
+
const i_second_start = format.indexOf('ss');
|
|
1591
|
+
if (i_second_start === -1)
|
|
1592
|
+
throw new Error('The format string must contain the format for seconds (ss)');
|
|
1593
|
+
const i_second_end = i_second_start + 2;
|
|
1594
|
+
const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
|
|
1595
|
+
if (i_nanosecond_start === -1)
|
|
1596
|
+
throw new Error('The format string must contain the format for nanoseconds (SSSSSSSSS)');
|
|
1597
|
+
return ((0, dayjs_1.default)(exports.timezone_offset + (Number(nanotime) / 1000000)).format(format.slice(0, i_second_end)) +
|
|
1598
|
+
format.slice(i_second_end, i_nanosecond_start) +
|
|
1599
|
+
String(nanotime % 1000000000n).padStart(9, '0'));
|
|
1600
|
+
}
|
|
1601
|
+
exports.nanotime2str = nanotime2str;
|
|
1342
1602
|
/** format nanotimestamp value (bigint) to string
|
|
1343
1603
|
- nanotimestamp: bigint value
|
|
1344
1604
|
- format?:
|
|
@@ -1347,7 +1607,7 @@ exports.str2timestamp = str2timestamp;
|
|
|
1347
1607
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1348
1608
|
*/
|
|
1349
1609
|
function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
1350
|
-
if (nanotimestamp === exports.nulls.int64)
|
|
1610
|
+
if (nanotimestamp === null || nanotimestamp === exports.nulls.int64)
|
|
1351
1611
|
return '';
|
|
1352
1612
|
const i_second_start = format.indexOf('ss');
|
|
1353
1613
|
if (i_second_start === -1)
|
|
@@ -1358,7 +1618,7 @@ function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSS
|
|
|
1358
1618
|
throw new Error('The format string must contain the format for nanoseconds (SSSSSSSSS)');
|
|
1359
1619
|
return ((0, dayjs_1.default)(exports.timezone_offset + (Number(nanotimestamp) / 1000000)).format(format.slice(0, i_second_end)) +
|
|
1360
1620
|
format.slice(i_second_end, i_nanosecond_start) +
|
|
1361
|
-
String(nanotimestamp % 1000000000n));
|
|
1621
|
+
String(nanotimestamp % 1000000000n).padStart(9, '0'));
|
|
1362
1622
|
}
|
|
1363
1623
|
exports.nanotimestamp2str = nanotimestamp2str;
|
|
1364
1624
|
/** parse nano timestamp string to bigint value
|
|
@@ -1386,6 +1646,31 @@ function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
|
1386
1646
|
BigInt(str.slice(i_nanosecond_start, i_nanosecond_start + 9)));
|
|
1387
1647
|
}
|
|
1388
1648
|
exports.str2nanotimestamp = str2nanotimestamp;
|
|
1649
|
+
function ipaddr2str(buffer, le = true) {
|
|
1650
|
+
let buf = buffer;
|
|
1651
|
+
if (le)
|
|
1652
|
+
buf = buffer.slice().reverse();
|
|
1653
|
+
const i_non_zero = buf.findIndex(x => x);
|
|
1654
|
+
if (i_non_zero !== -1 && i_non_zero < 12) // ipv6 (i_non_zero === -1 或 0 < i_non_zero < 12)
|
|
1655
|
+
return [...buf].map(x => x.toString(16)
|
|
1656
|
+
.padStart(2, '0')).join(':');
|
|
1657
|
+
else // ipv4
|
|
1658
|
+
return buf.subarray(12).join('.');
|
|
1659
|
+
}
|
|
1660
|
+
exports.ipaddr2str = ipaddr2str;
|
|
1661
|
+
function uuid2str(buffer, le = true) {
|
|
1662
|
+
const str = int1282str(buffer, le);
|
|
1663
|
+
return `${str.slice(0, 8)}-${str.slice(8, 12)}-${str.slice(12, 16)}-${str.slice(16, 20)}-${str.slice(20)}`;
|
|
1664
|
+
}
|
|
1665
|
+
exports.uuid2str = uuid2str;
|
|
1666
|
+
function int1282str(buffer, le = true) {
|
|
1667
|
+
let buf = buffer;
|
|
1668
|
+
if (le)
|
|
1669
|
+
buf = buffer.slice().reverse();
|
|
1670
|
+
return [...buf].map(x => x.toString(16)
|
|
1671
|
+
.padStart(2, '0')).join('');
|
|
1672
|
+
}
|
|
1673
|
+
exports.int1282str = int1282str;
|
|
1389
1674
|
class DDB {
|
|
1390
1675
|
/**
|
|
1391
1676
|
Initialize an instance of DolphinDB Client using the WebSocket URL
|