dolphindb 2.0.510 → 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 +29 -1
- package/browser.js +302 -25
- package/browser.js.map +1 -1
- package/index.d.ts +29 -2
- package/index.js +346 -58
- package/index.js.map +1 -1
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -51,7 +51,6 @@ export declare enum DdbType {
|
|
|
51
51
|
object = 37,
|
|
52
52
|
symbol_extended = 145
|
|
53
53
|
}
|
|
54
|
-
export declare const ddb_sizes: readonly [0, 1, 1, 2, 4, 8, 4, 4, 4, 4, 4, 4, 8, 8, 8, 4, 8, 0, 0, 16, 0, 0, 0, 0, 0, 0, 1, 0, 0, 16, 16, 0, 0, 0, 0];
|
|
55
54
|
export declare enum DdbFunctionType {
|
|
56
55
|
SystemFunc = 0,
|
|
57
56
|
SystemProc = 1,
|
|
@@ -63,10 +62,28 @@ export declare enum DdbFunctionType {
|
|
|
63
62
|
JitFunc = 7,
|
|
64
63
|
JitPartialFunc = 8
|
|
65
64
|
}
|
|
65
|
+
export declare enum DdbDurationUnit {
|
|
66
|
+
ns = 0,
|
|
67
|
+
us = 1,
|
|
68
|
+
ms = 2,
|
|
69
|
+
s = 3,
|
|
70
|
+
m = 4,
|
|
71
|
+
H = 5,
|
|
72
|
+
d = 6,
|
|
73
|
+
w = 7,
|
|
74
|
+
M = 8,
|
|
75
|
+
y = 9,
|
|
76
|
+
B = 10
|
|
77
|
+
}
|
|
66
78
|
export interface DdbFunctionDefValue {
|
|
67
79
|
type: DdbFunctionType;
|
|
68
80
|
name: string;
|
|
69
81
|
}
|
|
82
|
+
export interface DdbDurationValue {
|
|
83
|
+
unit: DdbDurationUnit;
|
|
84
|
+
/** int32 */
|
|
85
|
+
data: number;
|
|
86
|
+
}
|
|
70
87
|
export interface DdbSymbolExtendedValue {
|
|
71
88
|
base_id: number;
|
|
72
89
|
base: string[];
|
|
@@ -88,7 +105,7 @@ export declare type DdbScalarValue = null | boolean | number | bigint | string |
|
|
|
88
105
|
number,
|
|
89
106
|
number
|
|
90
107
|
] | // complex, point
|
|
91
|
-
DdbFunctionDefValue;
|
|
108
|
+
DdbFunctionDefValue | DdbDurationValue;
|
|
92
109
|
export declare type DdbVectorValue = Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | string[] | // string[]
|
|
93
110
|
Uint8Array[] | // blob
|
|
94
111
|
DdbObj[] | // any
|
|
@@ -162,6 +179,7 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
|
|
|
162
179
|
to_rows<T extends Record<string, any> = Record<string, any>>(): T[];
|
|
163
180
|
to_dict<T = Record<string, any>>(): T;
|
|
164
181
|
}
|
|
182
|
+
export declare function format(type: DdbType, value: DdbValue, le: boolean, options: InspectOptions): string;
|
|
165
183
|
export declare class DdbVoid extends DdbObj<undefined> {
|
|
166
184
|
constructor();
|
|
167
185
|
}
|
|
@@ -226,6 +244,10 @@ export declare class DdbTable extends DdbObj<DdbObj[]> {
|
|
|
226
244
|
constructor(columns: DdbObj[], name?: string);
|
|
227
245
|
}
|
|
228
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;
|
|
229
251
|
export declare function datetime2str(datetime: number, format?: string): string;
|
|
230
252
|
/** format timestamp (bigint) to string
|
|
231
253
|
- timestamp: bigint value
|
|
@@ -234,6 +256,7 @@ export declare function datetime2str(datetime: number, format?: string): string;
|
|
|
234
256
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
235
257
|
*/
|
|
236
258
|
export declare function timestamp2str(timestamp: bigint, format?: string): string;
|
|
259
|
+
export declare function datehour2str(datehour: number, format?: string): string;
|
|
237
260
|
/** parse timestamp string to bigint value
|
|
238
261
|
- str: timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
|
|
239
262
|
- format?:
|
|
@@ -241,6 +264,7 @@ export declare function timestamp2str(timestamp: bigint, format?: string): strin
|
|
|
241
264
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
242
265
|
*/
|
|
243
266
|
export declare function str2timestamp(str: string, format?: string): bigint;
|
|
267
|
+
export declare function nanotime2str(nanotime: bigint, format?: string): string;
|
|
244
268
|
/** format nanotimestamp value (bigint) to string
|
|
245
269
|
- nanotimestamp: bigint value
|
|
246
270
|
- format?:
|
|
@@ -257,6 +281,9 @@ export declare function nanotimestamp2str(nanotimestamp: bigint, format?: string
|
|
|
257
281
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
258
282
|
*/
|
|
259
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;
|
|
260
287
|
export declare class DDB {
|
|
261
288
|
/** 当前的 session id (http 或 tcp) */
|
|
262
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.
|
|
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"));
|
|
@@ -60,43 +60,6 @@ var DdbType;
|
|
|
60
60
|
DdbType[DdbType["object"] = 37] = "object";
|
|
61
61
|
DdbType[DdbType["symbol_extended"] = 145] = "symbol_extended";
|
|
62
62
|
})(DdbType = exports.DdbType || (exports.DdbType = {}));
|
|
63
|
-
exports.ddb_sizes = [
|
|
64
|
-
0,
|
|
65
|
-
1,
|
|
66
|
-
1,
|
|
67
|
-
2,
|
|
68
|
-
4,
|
|
69
|
-
8,
|
|
70
|
-
4,
|
|
71
|
-
4,
|
|
72
|
-
4,
|
|
73
|
-
4,
|
|
74
|
-
4,
|
|
75
|
-
4,
|
|
76
|
-
8,
|
|
77
|
-
8,
|
|
78
|
-
8,
|
|
79
|
-
4,
|
|
80
|
-
8,
|
|
81
|
-
0,
|
|
82
|
-
0,
|
|
83
|
-
16,
|
|
84
|
-
0,
|
|
85
|
-
0,
|
|
86
|
-
0,
|
|
87
|
-
0,
|
|
88
|
-
0,
|
|
89
|
-
0,
|
|
90
|
-
1,
|
|
91
|
-
0,
|
|
92
|
-
0,
|
|
93
|
-
16,
|
|
94
|
-
16,
|
|
95
|
-
0,
|
|
96
|
-
0,
|
|
97
|
-
0,
|
|
98
|
-
0, // duration = 36,
|
|
99
|
-
];
|
|
100
63
|
var DdbFunctionType;
|
|
101
64
|
(function (DdbFunctionType) {
|
|
102
65
|
DdbFunctionType[DdbFunctionType["SystemFunc"] = 0] = "SystemFunc";
|
|
@@ -109,6 +72,20 @@ var DdbFunctionType;
|
|
|
109
72
|
DdbFunctionType[DdbFunctionType["JitFunc"] = 7] = "JitFunc";
|
|
110
73
|
DdbFunctionType[DdbFunctionType["JitPartialFunc"] = 8] = "JitPartialFunc";
|
|
111
74
|
})(DdbFunctionType = exports.DdbFunctionType || (exports.DdbFunctionType = {}));
|
|
75
|
+
var DdbDurationUnit;
|
|
76
|
+
(function (DdbDurationUnit) {
|
|
77
|
+
DdbDurationUnit[DdbDurationUnit["ns"] = 0] = "ns";
|
|
78
|
+
DdbDurationUnit[DdbDurationUnit["us"] = 1] = "us";
|
|
79
|
+
DdbDurationUnit[DdbDurationUnit["ms"] = 2] = "ms";
|
|
80
|
+
DdbDurationUnit[DdbDurationUnit["s"] = 3] = "s";
|
|
81
|
+
DdbDurationUnit[DdbDurationUnit["m"] = 4] = "m";
|
|
82
|
+
DdbDurationUnit[DdbDurationUnit["H"] = 5] = "H";
|
|
83
|
+
DdbDurationUnit[DdbDurationUnit["d"] = 6] = "d";
|
|
84
|
+
DdbDurationUnit[DdbDurationUnit["w"] = 7] = "w";
|
|
85
|
+
DdbDurationUnit[DdbDurationUnit["M"] = 8] = "M";
|
|
86
|
+
DdbDurationUnit[DdbDurationUnit["y"] = 9] = "y";
|
|
87
|
+
DdbDurationUnit[DdbDurationUnit["B"] = 10] = "B";
|
|
88
|
+
})(DdbDurationUnit = exports.DdbDurationUnit || (exports.DdbDurationUnit = {}));
|
|
112
89
|
exports.nulls = {
|
|
113
90
|
int8: -0x80,
|
|
114
91
|
int16: -32768,
|
|
@@ -359,6 +336,7 @@ class DdbObj {
|
|
|
359
336
|
case DdbType.string:
|
|
360
337
|
case DdbType.symbol:
|
|
361
338
|
case DdbType.code:
|
|
339
|
+
case DdbType.handle:
|
|
362
340
|
case DdbType.functiondef: {
|
|
363
341
|
const i_head = type === DdbType.functiondef ? 1 : 0;
|
|
364
342
|
let i_zero = buf.indexOf(0, i_head);
|
|
@@ -406,8 +384,18 @@ class DdbObj {
|
|
|
406
384
|
]
|
|
407
385
|
];
|
|
408
386
|
}
|
|
387
|
+
case DdbType.duration: {
|
|
388
|
+
const dv = new DataView(buf.buffer, buf.byteOffset);
|
|
389
|
+
return [
|
|
390
|
+
8,
|
|
391
|
+
{
|
|
392
|
+
unit: dv.getUint32(4, le),
|
|
393
|
+
data: dv.getInt32(0, le)
|
|
394
|
+
}
|
|
395
|
+
];
|
|
396
|
+
}
|
|
409
397
|
default:
|
|
410
|
-
|
|
398
|
+
throw new Error(`${DdbType[type] || type} 暂时不支持解析`);
|
|
411
399
|
}
|
|
412
400
|
}
|
|
413
401
|
/** parse: rows, cols, items
|
|
@@ -546,6 +534,7 @@ class DdbObj {
|
|
|
546
534
|
];
|
|
547
535
|
case DdbType.string:
|
|
548
536
|
case DdbType.symbol:
|
|
537
|
+
case DdbType.handle:
|
|
549
538
|
case DdbType.code: {
|
|
550
539
|
let value = new Array(length);
|
|
551
540
|
let i_head = 0, i_tail = i_head;
|
|
@@ -639,6 +628,13 @@ class DdbObj {
|
|
|
639
628
|
values
|
|
640
629
|
];
|
|
641
630
|
}
|
|
631
|
+
// case DdbType.duration: -> 实际会返回一个 any vector
|
|
632
|
+
// [2y, 1M, 3d, 7H, 11m, 12s, 15ms, 16us, 17ns]
|
|
633
|
+
// <Buffer 19 01 type = any, form = vector
|
|
634
|
+
// 09 00 00 00 01 00 00 00 rows = 9, cols = 1
|
|
635
|
+
// 24 00 type = DdbType.duration, form = scalar
|
|
636
|
+
// 02 00 00 00 09 00 00 00
|
|
637
|
+
// 24 00 01 00 00 00 08 00 00 00 24 00 03 00 00 00 06 00 00 00 24 00 07 00 00 00 05 00 00 00 ... 50 more bytes>
|
|
642
638
|
default:
|
|
643
639
|
return [0, buf];
|
|
644
640
|
}
|
|
@@ -718,6 +714,7 @@ class DdbObj {
|
|
|
718
714
|
case DdbType.string:
|
|
719
715
|
case DdbType.symbol:
|
|
720
716
|
case DdbType.code:
|
|
717
|
+
case DdbType.handle:
|
|
721
718
|
return [
|
|
722
719
|
DdbObj.enc.encode(value),
|
|
723
720
|
Uint8Array.of(0),
|
|
@@ -740,12 +737,12 @@ class DdbObj {
|
|
|
740
737
|
case DdbType.complex:
|
|
741
738
|
case DdbType.point:
|
|
742
739
|
return [Float64Array.from(this.value)];
|
|
743
|
-
case DdbType.duration:
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
740
|
+
case DdbType.duration: {
|
|
741
|
+
const { unit, data } = this.value;
|
|
742
|
+
return [Int32Array.of(data, unit)];
|
|
743
|
+
}
|
|
747
744
|
default:
|
|
748
|
-
throw new Error(`${DdbType[type]} 暂时不支持序列化`);
|
|
745
|
+
throw new Error(`${DdbType[type] || type} 暂时不支持序列化`);
|
|
749
746
|
}
|
|
750
747
|
case DdbForm.vector:
|
|
751
748
|
case DdbForm.pair:
|
|
@@ -838,6 +835,7 @@ class DdbObj {
|
|
|
838
835
|
return [value];
|
|
839
836
|
case DdbType.string:
|
|
840
837
|
case DdbType.symbol:
|
|
838
|
+
case DdbType.handle:
|
|
841
839
|
case DdbType.code: {
|
|
842
840
|
let bufs = new Array(length * 2);
|
|
843
841
|
for (let i = 0; i < length; i++) {
|
|
@@ -907,25 +905,69 @@ class DdbObj {
|
|
|
907
905
|
case DdbForm.set:
|
|
908
906
|
return `set<${tname}>[${this.rows}]`;
|
|
909
907
|
case DdbForm.table:
|
|
910
|
-
return `table[${this.rows}
|
|
908
|
+
return `table[${this.rows}r][${this.cols}c]`;
|
|
911
909
|
case DdbForm.dict:
|
|
912
910
|
return `dict<${DdbType[this.value[0].type]}, ${DdbType[this.value[1].type]}>`;
|
|
913
911
|
case DdbForm.matrix:
|
|
914
|
-
return `matrix<${DdbType[this.type]}>[${this.rows}
|
|
912
|
+
return `matrix<${DdbType[this.type]}>[${this.rows}r][${this.cols}c]`;
|
|
915
913
|
default:
|
|
916
914
|
return `${DdbForm[this.form]} ${tname}`;
|
|
917
915
|
}
|
|
918
916
|
})();
|
|
919
917
|
const data = (() => {
|
|
920
918
|
switch (this.form) {
|
|
921
|
-
case DdbForm.pair:
|
|
922
|
-
return `${(0, utils_js_1.inspect)(this.value[0], options)}, ${(0, utils_js_1.inspect)(this.value[1], options)}`;
|
|
923
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
|
+
}
|
|
924
932
|
switch (this.type) {
|
|
925
|
-
case DdbType.
|
|
926
|
-
|
|
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);
|
|
968
|
+
}
|
|
927
969
|
}
|
|
928
|
-
|
|
970
|
+
}
|
|
929
971
|
}
|
|
930
972
|
if (this.value instanceof Uint8Array)
|
|
931
973
|
return (0, utils_js_1.inspect)((0, utils_js_1.typed_array_to_buffer)(this.value), options);
|
|
@@ -935,7 +977,7 @@ class DdbObj {
|
|
|
935
977
|
}
|
|
936
978
|
to_rows() {
|
|
937
979
|
if (this.form !== DdbForm.table)
|
|
938
|
-
throw new Error('this.form
|
|
980
|
+
throw new Error('this.form 不是 DdbForm.table, 不能 to_rows');
|
|
939
981
|
let rows = new Array(this.rows);
|
|
940
982
|
for (let i = 0; i < this.rows; i++) {
|
|
941
983
|
let row = {};
|
|
@@ -968,7 +1010,7 @@ class DdbObj {
|
|
|
968
1010
|
}
|
|
969
1011
|
to_dict() {
|
|
970
1012
|
if (this.form !== DdbForm.dict)
|
|
971
|
-
throw new Error('this.form
|
|
1013
|
+
throw new Error('this.form 不是 DdbForm.dict, 不能转换为 Object');
|
|
972
1014
|
const [{ value: keys }, { value: values }] = this.value;
|
|
973
1015
|
let obj = {};
|
|
974
1016
|
for (let i = 0; i < this.rows; i++)
|
|
@@ -985,6 +1027,173 @@ DdbObj.enc = new TextEncoder();
|
|
|
985
1027
|
DdbObj.symbol_bases = {};
|
|
986
1028
|
/** little endian (client) */
|
|
987
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;
|
|
988
1197
|
class DdbVoid extends DdbObj {
|
|
989
1198
|
constructor() {
|
|
990
1199
|
super({
|
|
@@ -1295,14 +1504,48 @@ class DdbTable extends DdbObj {
|
|
|
1295
1504
|
}
|
|
1296
1505
|
exports.DdbTable = DdbTable;
|
|
1297
1506
|
function date2str(date, format = 'YYYY.MM.DD') {
|
|
1298
|
-
return date === exports.nulls.int32 ?
|
|
1507
|
+
return (date === null || date === exports.nulls.int32) ?
|
|
1299
1508
|
''
|
|
1300
1509
|
:
|
|
1301
1510
|
(0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * 24 * date).format(format);
|
|
1302
1511
|
}
|
|
1303
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;
|
|
1304
1547
|
function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
|
|
1305
|
-
return datetime === exports.nulls.int32 ?
|
|
1548
|
+
return (datetime === null || datetime === exports.nulls.int32) ?
|
|
1306
1549
|
''
|
|
1307
1550
|
:
|
|
1308
1551
|
(0, dayjs_1.default)(exports.timezone_offset + 1000 * datetime).format(format);
|
|
@@ -1315,12 +1558,19 @@ exports.datetime2str = datetime2str;
|
|
|
1315
1558
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1316
1559
|
*/
|
|
1317
1560
|
function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
1318
|
-
return timestamp === exports.nulls.int64 ?
|
|
1561
|
+
return (timestamp === null || timestamp === exports.nulls.int64) ?
|
|
1319
1562
|
''
|
|
1320
1563
|
:
|
|
1321
1564
|
(0, dayjs_1.default)(exports.timezone_offset + Number(timestamp)).format(format);
|
|
1322
1565
|
}
|
|
1323
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;
|
|
1324
1574
|
/** parse timestamp string to bigint value
|
|
1325
1575
|
- str: timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
|
|
1326
1576
|
- format?:
|
|
@@ -1336,6 +1586,19 @@ function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
|
1336
1586
|
(0, dayjs_1.default)(str, format).valueOf());
|
|
1337
1587
|
}
|
|
1338
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;
|
|
1339
1602
|
/** format nanotimestamp value (bigint) to string
|
|
1340
1603
|
- nanotimestamp: bigint value
|
|
1341
1604
|
- format?:
|
|
@@ -1344,7 +1607,7 @@ exports.str2timestamp = str2timestamp;
|
|
|
1344
1607
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1345
1608
|
*/
|
|
1346
1609
|
function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
1347
|
-
if (nanotimestamp === exports.nulls.int64)
|
|
1610
|
+
if (nanotimestamp === null || nanotimestamp === exports.nulls.int64)
|
|
1348
1611
|
return '';
|
|
1349
1612
|
const i_second_start = format.indexOf('ss');
|
|
1350
1613
|
if (i_second_start === -1)
|
|
@@ -1355,7 +1618,7 @@ function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSS
|
|
|
1355
1618
|
throw new Error('The format string must contain the format for nanoseconds (SSSSSSSSS)');
|
|
1356
1619
|
return ((0, dayjs_1.default)(exports.timezone_offset + (Number(nanotimestamp) / 1000000)).format(format.slice(0, i_second_end)) +
|
|
1357
1620
|
format.slice(i_second_end, i_nanosecond_start) +
|
|
1358
|
-
String(nanotimestamp % 1000000000n));
|
|
1621
|
+
String(nanotimestamp % 1000000000n).padStart(9, '0'));
|
|
1359
1622
|
}
|
|
1360
1623
|
exports.nanotimestamp2str = nanotimestamp2str;
|
|
1361
1624
|
/** parse nano timestamp string to bigint value
|
|
@@ -1383,6 +1646,31 @@ function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
|
1383
1646
|
BigInt(str.slice(i_nanosecond_start, i_nanosecond_start + 9)));
|
|
1384
1647
|
}
|
|
1385
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;
|
|
1386
1674
|
class DDB {
|
|
1387
1675
|
/**
|
|
1388
1676
|
Initialize an instance of DolphinDB Client using the WebSocket URL
|