dolphindb 2.0.511 → 2.0.514
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 +15 -2
- package/browser.js +299 -28
- package/browser.js.map +1 -1
- package/index.d.ts +16 -4
- package/index.js +344 -63
- package/index.js.map +1 -1
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -12,6 +12,10 @@ export declare enum DdbForm {
|
|
|
12
12
|
chart = 7,
|
|
13
13
|
chunk = 8
|
|
14
14
|
}
|
|
15
|
+
/** DolphinDB DataType
|
|
16
|
+
对应的 array vector 类型为 64 + 基本类型
|
|
17
|
+
对应的 extended 类型为 128 + 基本类型
|
|
18
|
+
*/
|
|
15
19
|
export declare enum DdbType {
|
|
16
20
|
void = 0,
|
|
17
21
|
bool = 1,
|
|
@@ -51,7 +55,6 @@ export declare enum DdbType {
|
|
|
51
55
|
object = 37,
|
|
52
56
|
symbol_extended = 145
|
|
53
57
|
}
|
|
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
58
|
export declare enum DdbFunctionType {
|
|
56
59
|
SystemFunc = 0,
|
|
57
60
|
SystemProc = 1,
|
|
@@ -94,7 +97,7 @@ export interface DdbArrayVectorBlock {
|
|
|
94
97
|
unit: 1 | 2 | 4;
|
|
95
98
|
rows: number;
|
|
96
99
|
lengths: Uint8Array | Uint16Array | Uint32Array;
|
|
97
|
-
data:
|
|
100
|
+
data: Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array;
|
|
98
101
|
}
|
|
99
102
|
export interface DdbMatrixValue {
|
|
100
103
|
rows: DdbObj<DdbVectorValue>;
|
|
@@ -180,6 +183,7 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
|
|
|
180
183
|
to_rows<T extends Record<string, any> = Record<string, any>>(): T[];
|
|
181
184
|
to_dict<T = Record<string, any>>(): T;
|
|
182
185
|
}
|
|
186
|
+
export declare function format(type: DdbType, value: DdbValue, le: boolean, options: InspectOptions): string;
|
|
183
187
|
export declare class DdbVoid extends DdbObj<undefined> {
|
|
184
188
|
constructor();
|
|
185
189
|
}
|
|
@@ -244,6 +248,10 @@ export declare class DdbTable extends DdbObj<DdbObj[]> {
|
|
|
244
248
|
constructor(columns: DdbObj[], name?: string);
|
|
245
249
|
}
|
|
246
250
|
export declare function date2str(date: number, format?: string): string;
|
|
251
|
+
export declare function month2str(month: number | null): string;
|
|
252
|
+
export declare function time2str(time: number, format?: string): string;
|
|
253
|
+
export declare function minute2str(minute: number | null, format?: string): string;
|
|
254
|
+
export declare function second2str(second: number | null, format?: string): string;
|
|
247
255
|
export declare function datetime2str(datetime: number, format?: string): string;
|
|
248
256
|
/** format timestamp (bigint) to string
|
|
249
257
|
- timestamp: bigint value
|
|
@@ -252,6 +260,7 @@ export declare function datetime2str(datetime: number, format?: string): string;
|
|
|
252
260
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
253
261
|
*/
|
|
254
262
|
export declare function timestamp2str(timestamp: bigint, format?: string): string;
|
|
263
|
+
export declare function datehour2str(datehour: number, format?: string): string;
|
|
255
264
|
/** parse timestamp string to bigint value
|
|
256
265
|
- str: timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
|
|
257
266
|
- format?:
|
|
@@ -259,6 +268,7 @@ export declare function timestamp2str(timestamp: bigint, format?: string): strin
|
|
|
259
268
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
260
269
|
*/
|
|
261
270
|
export declare function str2timestamp(str: string, format?: string): bigint;
|
|
271
|
+
export declare function nanotime2str(nanotime: bigint, format?: string): string;
|
|
262
272
|
/** format nanotimestamp value (bigint) to string
|
|
263
273
|
- nanotimestamp: bigint value
|
|
264
274
|
- format?:
|
|
@@ -275,6 +285,9 @@ export declare function nanotimestamp2str(nanotimestamp: bigint, format?: string
|
|
|
275
285
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
276
286
|
*/
|
|
277
287
|
export declare function str2nanotimestamp(str: string, format?: string): bigint;
|
|
288
|
+
export declare function ipaddr2str(buffer: Uint8Array, le?: boolean): string;
|
|
289
|
+
export declare function uuid2str(buffer: Uint8Array, le?: boolean): string;
|
|
290
|
+
export declare function int1282str(buffer: Uint8Array, le?: boolean): string;
|
|
278
291
|
export declare class DDB {
|
|
279
292
|
/** 当前的 session id (http 或 tcp) */
|
|
280
293
|
sid: string;
|
|
@@ -378,7 +391,7 @@ export declare class DDB {
|
|
|
378
391
|
- options:
|
|
379
392
|
- urgent?: 决定 `行为标识` 那一行字符串的取值(只适用于 script 和 function)
|
|
380
393
|
- vars?: type === 'variable' 时必传,variable 指令中待上传的变量名
|
|
381
|
-
-
|
|
394
|
+
- listener?: 处理本次 rpc 期间的消息 (DdbMessage)
|
|
382
395
|
- parse_object?: 在该次 rpc 期间设置 parse_object, 结束后恢复原有,为 false 时返回的 DdbObj 仅含有 buffer 和 le,
|
|
383
396
|
不做解析,以便后续转发、序列化
|
|
384
397
|
*/
|
|
@@ -460,4 +473,3 @@ export interface DdbErrorMessage {
|
|
|
460
473
|
data: Error;
|
|
461
474
|
}
|
|
462
475
|
export declare type DdbMessage = DdbPrintMessage | DdbObjectMessage | DdbErrorMessage;
|
|
463
|
-
export default DDB;
|
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.
|
|
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"));
|
|
@@ -20,6 +20,10 @@ var DdbForm;
|
|
|
20
20
|
DdbForm[DdbForm["chart"] = 7] = "chart";
|
|
21
21
|
DdbForm[DdbForm["chunk"] = 8] = "chunk";
|
|
22
22
|
})(DdbForm = exports.DdbForm || (exports.DdbForm = {}));
|
|
23
|
+
/** DolphinDB DataType
|
|
24
|
+
对应的 array vector 类型为 64 + 基本类型
|
|
25
|
+
对应的 extended 类型为 128 + 基本类型
|
|
26
|
+
*/
|
|
23
27
|
var DdbType;
|
|
24
28
|
(function (DdbType) {
|
|
25
29
|
DdbType[DdbType["void"] = 0] = "void";
|
|
@@ -60,43 +64,6 @@ var DdbType;
|
|
|
60
64
|
DdbType[DdbType["object"] = 37] = "object";
|
|
61
65
|
DdbType[DdbType["symbol_extended"] = 145] = "symbol_extended";
|
|
62
66
|
})(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
67
|
var DdbFunctionType;
|
|
101
68
|
(function (DdbFunctionType) {
|
|
102
69
|
DdbFunctionType[DdbFunctionType["SystemFunc"] = 0] = "SystemFunc";
|
|
@@ -373,6 +340,7 @@ class DdbObj {
|
|
|
373
340
|
case DdbType.string:
|
|
374
341
|
case DdbType.symbol:
|
|
375
342
|
case DdbType.code:
|
|
343
|
+
case DdbType.handle:
|
|
376
344
|
case DdbType.functiondef: {
|
|
377
345
|
const i_head = type === DdbType.functiondef ? 1 : 0;
|
|
378
346
|
let i_zero = buf.indexOf(0, i_head);
|
|
@@ -431,7 +399,7 @@ class DdbObj {
|
|
|
431
399
|
];
|
|
432
400
|
}
|
|
433
401
|
default:
|
|
434
|
-
|
|
402
|
+
throw new Error(`${DdbType[type] || type} 暂时不支持解析`);
|
|
435
403
|
}
|
|
436
404
|
}
|
|
437
405
|
/** parse: rows, cols, items
|
|
@@ -507,7 +475,7 @@ class DdbObj {
|
|
|
507
475
|
unit,
|
|
508
476
|
rows,
|
|
509
477
|
lengths,
|
|
510
|
-
data
|
|
478
|
+
data: data
|
|
511
479
|
});
|
|
512
480
|
i_block_start = i_data_start + len_items;
|
|
513
481
|
i_row += rows;
|
|
@@ -570,6 +538,7 @@ class DdbObj {
|
|
|
570
538
|
];
|
|
571
539
|
case DdbType.string:
|
|
572
540
|
case DdbType.symbol:
|
|
541
|
+
case DdbType.handle:
|
|
573
542
|
case DdbType.code: {
|
|
574
543
|
let value = new Array(length);
|
|
575
544
|
let i_head = 0, i_tail = i_head;
|
|
@@ -749,6 +718,7 @@ class DdbObj {
|
|
|
749
718
|
case DdbType.string:
|
|
750
719
|
case DdbType.symbol:
|
|
751
720
|
case DdbType.code:
|
|
721
|
+
case DdbType.handle:
|
|
752
722
|
return [
|
|
753
723
|
DdbObj.enc.encode(value),
|
|
754
724
|
Uint8Array.of(0),
|
|
@@ -775,10 +745,8 @@ class DdbObj {
|
|
|
775
745
|
const { unit, data } = this.value;
|
|
776
746
|
return [Int32Array.of(data, unit)];
|
|
777
747
|
}
|
|
778
|
-
case DdbType.handle:
|
|
779
|
-
throw new Error('DolphinDB Server 不支持 handle 的反序列化');
|
|
780
748
|
default:
|
|
781
|
-
throw new Error(`${DdbType[type]} 暂时不支持序列化`);
|
|
749
|
+
throw new Error(`${DdbType[type] || type} 暂时不支持序列化`);
|
|
782
750
|
}
|
|
783
751
|
case DdbForm.vector:
|
|
784
752
|
case DdbForm.pair:
|
|
@@ -871,6 +839,7 @@ class DdbObj {
|
|
|
871
839
|
return [value];
|
|
872
840
|
case DdbType.string:
|
|
873
841
|
case DdbType.symbol:
|
|
842
|
+
case DdbType.handle:
|
|
874
843
|
case DdbType.code: {
|
|
875
844
|
let bufs = new Array(length * 2);
|
|
876
845
|
for (let i = 0; i < length; i++) {
|
|
@@ -940,30 +909,97 @@ class DdbObj {
|
|
|
940
909
|
case DdbForm.set:
|
|
941
910
|
return `set<${tname}>[${this.rows}]`;
|
|
942
911
|
case DdbForm.table:
|
|
943
|
-
return `table[${this.rows}
|
|
912
|
+
return `table[${this.rows}r][${this.cols}c]`;
|
|
944
913
|
case DdbForm.dict:
|
|
945
914
|
return `dict<${DdbType[this.value[0].type]}, ${DdbType[this.value[1].type]}>`;
|
|
946
915
|
case DdbForm.matrix:
|
|
947
|
-
return `matrix<${DdbType[this.type]}>[${this.rows}
|
|
916
|
+
return `matrix<${DdbType[this.type]}>[${this.rows}r][${this.cols}c]`;
|
|
948
917
|
default:
|
|
949
918
|
return `${DdbForm[this.form]} ${tname}`;
|
|
950
919
|
}
|
|
951
920
|
})();
|
|
952
921
|
const data = (() => {
|
|
953
922
|
switch (this.form) {
|
|
954
|
-
case DdbForm.pair:
|
|
955
|
-
return `${(0, utils_js_1.inspect)(this.value[0], options)}, ${(0, utils_js_1.inspect)(this.value[1], options)}`;
|
|
956
923
|
case DdbForm.scalar:
|
|
924
|
+
return format(this.type, this.value, this.le, options);
|
|
925
|
+
case DdbForm.vector:
|
|
926
|
+
case DdbForm.pair:
|
|
927
|
+
case DdbForm.set: {
|
|
928
|
+
const form = this.form;
|
|
929
|
+
function format_array(items, ellipsis) {
|
|
930
|
+
const str_items = items.join(', ') + (ellipsis ? ', ...' : '');
|
|
931
|
+
return form === DdbForm.pair ?
|
|
932
|
+
str_items
|
|
933
|
+
:
|
|
934
|
+
str_items.bracket('square');
|
|
935
|
+
}
|
|
936
|
+
if (64 <= this.type && this.type < 128) { // array vector
|
|
937
|
+
// 因为 array vector 目前只支持:Logical, Integral(不包括 INT128, COMPRESS 类型), Floating, Temporal
|
|
938
|
+
// 都对应 TypedArray 中的一格,所以直接根据 index 去取即可
|
|
939
|
+
// av = array(INT[], 0, 5)
|
|
940
|
+
// append!(av, [1..1])
|
|
941
|
+
// append!(av, [1..70000])
|
|
942
|
+
// append!(av, [1..1])
|
|
943
|
+
// append!(av, [1..500])
|
|
944
|
+
// ...
|
|
945
|
+
// av
|
|
946
|
+
const _type = this.type - 64;
|
|
947
|
+
const limit = 10;
|
|
948
|
+
let items = new Array(Math.min(limit, this.rows));
|
|
949
|
+
let i_items = 0;
|
|
950
|
+
for (const { lengths, data } of this.value) {
|
|
951
|
+
let acc_len = 0;
|
|
952
|
+
for (const length of lengths) {
|
|
953
|
+
let _items = new Array(Math.min(limit, length));
|
|
954
|
+
for (let i = 0; i < _items.length; i++)
|
|
955
|
+
_items[i] = format(_type, data[acc_len + i], this.le, options);
|
|
956
|
+
items[i_items++] = format_array(_items, length > limit);
|
|
957
|
+
acc_len += length;
|
|
958
|
+
}
|
|
959
|
+
if (i_items >= limit)
|
|
960
|
+
break;
|
|
961
|
+
}
|
|
962
|
+
return format_array(items, this.rows > limit);
|
|
963
|
+
}
|
|
957
964
|
switch (this.type) {
|
|
958
|
-
case DdbType.
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
965
|
+
case DdbType.symbol_extended: {
|
|
966
|
+
const limit = 50;
|
|
967
|
+
const { base, data } = this.value;
|
|
968
|
+
let items = new Array(Math.min(limit, data.length));
|
|
969
|
+
for (let i = 0; i < items.length; i++)
|
|
970
|
+
items[i] = (0, utils_js_1.inspect)(base[data[i]], options);
|
|
971
|
+
return format_array(items, data.length > limit);
|
|
972
|
+
}
|
|
973
|
+
case DdbType.uuid:
|
|
974
|
+
case DdbType.int128:
|
|
975
|
+
case DdbType.ipaddr: {
|
|
976
|
+
const limit = 10;
|
|
977
|
+
const value = this.value;
|
|
978
|
+
const len_data = value.length / 16;
|
|
979
|
+
let items = new Array(Math.min(limit, len_data));
|
|
980
|
+
for (let i = 0; i < items.length; i++)
|
|
981
|
+
items[i] = format(this.type, value.subarray(16 * i, 16 * (i + 1)), this.le, options);
|
|
982
|
+
return format_array(items, len_data > limit);
|
|
983
|
+
}
|
|
984
|
+
case DdbType.complex:
|
|
985
|
+
case DdbType.point: {
|
|
986
|
+
const limit = 20;
|
|
987
|
+
const value = this.value;
|
|
988
|
+
const len_data = value.length / 2;
|
|
989
|
+
let items = new Array(Math.min(limit, len_data));
|
|
990
|
+
for (let i = 0; i < items.length; i++)
|
|
991
|
+
items[i] = format(this.type, value.subarray(2 * i, 2 * (i + 1)), this.le, options);
|
|
992
|
+
return format_array(items, len_data > limit);
|
|
993
|
+
}
|
|
994
|
+
default: {
|
|
995
|
+
const limit = 50;
|
|
996
|
+
let items = new Array(Math.min(limit, this.value.length));
|
|
997
|
+
for (let i = 0; i < items.length; i++)
|
|
998
|
+
items[i] = format(this.type, this.value[i], this.le, options);
|
|
999
|
+
return format_array(items, this.value.length > limit);
|
|
964
1000
|
}
|
|
965
1001
|
}
|
|
966
|
-
|
|
1002
|
+
}
|
|
967
1003
|
}
|
|
968
1004
|
if (this.value instanceof Uint8Array)
|
|
969
1005
|
return (0, utils_js_1.inspect)((0, utils_js_1.typed_array_to_buffer)(this.value), options);
|
|
@@ -973,7 +1009,7 @@ class DdbObj {
|
|
|
973
1009
|
}
|
|
974
1010
|
to_rows() {
|
|
975
1011
|
if (this.form !== DdbForm.table)
|
|
976
|
-
throw new Error('this.form
|
|
1012
|
+
throw new Error('this.form 不是 DdbForm.table, 不能 to_rows');
|
|
977
1013
|
let rows = new Array(this.rows);
|
|
978
1014
|
for (let i = 0; i < this.rows; i++) {
|
|
979
1015
|
let row = {};
|
|
@@ -1006,7 +1042,7 @@ class DdbObj {
|
|
|
1006
1042
|
}
|
|
1007
1043
|
to_dict() {
|
|
1008
1044
|
if (this.form !== DdbForm.dict)
|
|
1009
|
-
throw new Error('this.form
|
|
1045
|
+
throw new Error('this.form 不是 DdbForm.dict, 不能转换为 Object');
|
|
1010
1046
|
const [{ value: keys }, { value: values }] = this.value;
|
|
1011
1047
|
let obj = {};
|
|
1012
1048
|
for (let i = 0; i < this.rows; i++)
|
|
@@ -1023,6 +1059,173 @@ DdbObj.enc = new TextEncoder();
|
|
|
1023
1059
|
DdbObj.symbol_bases = {};
|
|
1024
1060
|
/** little endian (client) */
|
|
1025
1061
|
DdbObj.le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
|
|
1062
|
+
function format(type, value, le, options) {
|
|
1063
|
+
switch (type) {
|
|
1064
|
+
case DdbType.bool:
|
|
1065
|
+
return (0, utils_js_1.inspect)((value === null || value === exports.nulls.int8) ?
|
|
1066
|
+
null
|
|
1067
|
+
:
|
|
1068
|
+
Boolean(value), options);
|
|
1069
|
+
case DdbType.char:
|
|
1070
|
+
return (0, utils_js_1.inspect)((value === null || value === exports.nulls.int8) ?
|
|
1071
|
+
null
|
|
1072
|
+
:
|
|
1073
|
+
value, options);
|
|
1074
|
+
case DdbType.short:
|
|
1075
|
+
return (0, utils_js_1.inspect)((value === null || value === exports.nulls.int16) ?
|
|
1076
|
+
null
|
|
1077
|
+
:
|
|
1078
|
+
value, options);
|
|
1079
|
+
case DdbType.int:
|
|
1080
|
+
return (0, utils_js_1.inspect)((value === null || value === exports.nulls.int32) ?
|
|
1081
|
+
null
|
|
1082
|
+
:
|
|
1083
|
+
value, options);
|
|
1084
|
+
case DdbType.long:
|
|
1085
|
+
return (value === null || value === exports.nulls.int64) ?
|
|
1086
|
+
'null'
|
|
1087
|
+
:
|
|
1088
|
+
options.colors ?
|
|
1089
|
+
String(value).green
|
|
1090
|
+
:
|
|
1091
|
+
String(value);
|
|
1092
|
+
case DdbType.date:
|
|
1093
|
+
return (value === null || value === exports.nulls.int32) ?
|
|
1094
|
+
'null'
|
|
1095
|
+
:
|
|
1096
|
+
options.colors ?
|
|
1097
|
+
date2str(value).green
|
|
1098
|
+
:
|
|
1099
|
+
date2str(value);
|
|
1100
|
+
case DdbType.month:
|
|
1101
|
+
return (value === null || value === exports.nulls.int32) ?
|
|
1102
|
+
'null'
|
|
1103
|
+
:
|
|
1104
|
+
options.colors ?
|
|
1105
|
+
month2str(value).green
|
|
1106
|
+
:
|
|
1107
|
+
month2str(value);
|
|
1108
|
+
case DdbType.time:
|
|
1109
|
+
return (value === null || value === exports.nulls.int32) ?
|
|
1110
|
+
'null'
|
|
1111
|
+
:
|
|
1112
|
+
options.colors ?
|
|
1113
|
+
time2str(value).green
|
|
1114
|
+
:
|
|
1115
|
+
time2str(value);
|
|
1116
|
+
case DdbType.minute:
|
|
1117
|
+
return (value === null || value === exports.nulls.int32) ?
|
|
1118
|
+
'null'
|
|
1119
|
+
:
|
|
1120
|
+
options.colors ?
|
|
1121
|
+
minute2str(value).green
|
|
1122
|
+
:
|
|
1123
|
+
minute2str(value);
|
|
1124
|
+
case DdbType.second:
|
|
1125
|
+
return (value === null || value === exports.nulls.int32) ?
|
|
1126
|
+
'null'
|
|
1127
|
+
:
|
|
1128
|
+
options.colors ?
|
|
1129
|
+
second2str(value).green
|
|
1130
|
+
:
|
|
1131
|
+
second2str(value);
|
|
1132
|
+
case DdbType.datetime:
|
|
1133
|
+
return (value === null || value === exports.nulls.int32) ?
|
|
1134
|
+
'null'
|
|
1135
|
+
:
|
|
1136
|
+
options.colors ?
|
|
1137
|
+
datetime2str(value).green
|
|
1138
|
+
:
|
|
1139
|
+
datetime2str(value);
|
|
1140
|
+
case DdbType.timestamp:
|
|
1141
|
+
return (value === null || value === exports.nulls.int64) ?
|
|
1142
|
+
'null'
|
|
1143
|
+
:
|
|
1144
|
+
options.colors ?
|
|
1145
|
+
timestamp2str(value).green
|
|
1146
|
+
:
|
|
1147
|
+
timestamp2str(value);
|
|
1148
|
+
case DdbType.nanotime:
|
|
1149
|
+
return (value === null || value === exports.nulls.int64) ?
|
|
1150
|
+
'null'
|
|
1151
|
+
:
|
|
1152
|
+
options.colors ?
|
|
1153
|
+
nanotime2str(value).green
|
|
1154
|
+
:
|
|
1155
|
+
nanotime2str(value);
|
|
1156
|
+
case DdbType.nanotimestamp:
|
|
1157
|
+
return (value === null || value === exports.nulls.int64) ?
|
|
1158
|
+
'null'
|
|
1159
|
+
:
|
|
1160
|
+
options.colors ?
|
|
1161
|
+
nanotimestamp2str(value).green
|
|
1162
|
+
:
|
|
1163
|
+
nanotimestamp2str(value);
|
|
1164
|
+
case DdbType.float:
|
|
1165
|
+
return (value === null || value === exports.nulls.float32) ?
|
|
1166
|
+
'null'
|
|
1167
|
+
:
|
|
1168
|
+
(0, utils_js_1.inspect)(value, options);
|
|
1169
|
+
case DdbType.double:
|
|
1170
|
+
return (value === null || value === exports.nulls.double) ?
|
|
1171
|
+
'null'
|
|
1172
|
+
:
|
|
1173
|
+
(0, utils_js_1.inspect)(value, options);
|
|
1174
|
+
case DdbType.symbol:
|
|
1175
|
+
case DdbType.string:
|
|
1176
|
+
return (0, utils_js_1.inspect)(value, options);
|
|
1177
|
+
case DdbType.uuid:
|
|
1178
|
+
return options.colors ?
|
|
1179
|
+
uuid2str(value, le).green
|
|
1180
|
+
:
|
|
1181
|
+
uuid2str(value, le);
|
|
1182
|
+
case DdbType.functiondef:
|
|
1183
|
+
return (0, utils_js_1.inspect)(value.name, options);
|
|
1184
|
+
case DdbType.handle:
|
|
1185
|
+
case DdbType.code:
|
|
1186
|
+
return (0, utils_js_1.inspect)(value, options);
|
|
1187
|
+
case DdbType.datehour:
|
|
1188
|
+
return (value === null || value === exports.nulls.int32) ?
|
|
1189
|
+
'null'
|
|
1190
|
+
:
|
|
1191
|
+
options.colors ?
|
|
1192
|
+
datehour2str(value).green
|
|
1193
|
+
:
|
|
1194
|
+
datehour2str(value);
|
|
1195
|
+
case DdbType.ipaddr:
|
|
1196
|
+
return options.colors ?
|
|
1197
|
+
ipaddr2str(value, le).green
|
|
1198
|
+
:
|
|
1199
|
+
ipaddr2str(value, le);
|
|
1200
|
+
case DdbType.int128:
|
|
1201
|
+
return options.colors ?
|
|
1202
|
+
int1282str(value, le).green
|
|
1203
|
+
:
|
|
1204
|
+
int1282str(value, le);
|
|
1205
|
+
case DdbType.blob:
|
|
1206
|
+
return (0, utils_js_1.inspect)(DdbObj.dec.decode(value.subarray(0, 1000)), options);
|
|
1207
|
+
case DdbType.complex:
|
|
1208
|
+
case DdbType.point: {
|
|
1209
|
+
let [x, y] = value;
|
|
1210
|
+
if (x === exports.nulls.double)
|
|
1211
|
+
x = null;
|
|
1212
|
+
if (y === exports.nulls.double)
|
|
1213
|
+
y = null;
|
|
1214
|
+
return options.colors ?
|
|
1215
|
+
`(${String(x).green}, ${String(y).green})`
|
|
1216
|
+
:
|
|
1217
|
+
`(${String(x)}, ${String(y)})`;
|
|
1218
|
+
}
|
|
1219
|
+
case DdbType.duration: {
|
|
1220
|
+
const { data, unit } = value;
|
|
1221
|
+
const str = `${data}${DdbDurationUnit[unit]}`;
|
|
1222
|
+
return options.colors ? str.green : str;
|
|
1223
|
+
}
|
|
1224
|
+
default:
|
|
1225
|
+
return (0, utils_js_1.inspect)(value, options);
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
exports.format = format;
|
|
1026
1229
|
class DdbVoid extends DdbObj {
|
|
1027
1230
|
constructor() {
|
|
1028
1231
|
super({
|
|
@@ -1333,14 +1536,48 @@ class DdbTable extends DdbObj {
|
|
|
1333
1536
|
}
|
|
1334
1537
|
exports.DdbTable = DdbTable;
|
|
1335
1538
|
function date2str(date, format = 'YYYY.MM.DD') {
|
|
1336
|
-
return date === exports.nulls.int32 ?
|
|
1539
|
+
return (date === null || date === exports.nulls.int32) ?
|
|
1337
1540
|
''
|
|
1338
1541
|
:
|
|
1339
1542
|
(0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * 24 * date).format(format);
|
|
1340
1543
|
}
|
|
1341
1544
|
exports.date2str = date2str;
|
|
1545
|
+
function month2str(month) {
|
|
1546
|
+
if (month === null || month === exports.nulls.int32)
|
|
1547
|
+
return '';
|
|
1548
|
+
if (month < 0)
|
|
1549
|
+
return String(month);
|
|
1550
|
+
let _month = month % 12;
|
|
1551
|
+
let year = Math.floor(month / 12);
|
|
1552
|
+
return `${String(year).padStart(4, '0')}.${String(_month + 1).padStart(2, '0')}`;
|
|
1553
|
+
}
|
|
1554
|
+
exports.month2str = month2str;
|
|
1555
|
+
function time2str(time, format = 'HH:mm:ss.SSS') {
|
|
1556
|
+
return (time === null || time === exports.nulls.int32) ?
|
|
1557
|
+
''
|
|
1558
|
+
:
|
|
1559
|
+
(0, dayjs_1.default)(exports.timezone_offset + time)
|
|
1560
|
+
.format(format);
|
|
1561
|
+
}
|
|
1562
|
+
exports.time2str = time2str;
|
|
1563
|
+
function minute2str(minute, format = 'HH:mm') {
|
|
1564
|
+
return (minute === null || minute === exports.nulls.int32) ?
|
|
1565
|
+
''
|
|
1566
|
+
:
|
|
1567
|
+
(0, dayjs_1.default)(exports.timezone_offset + 60 * 1000 * minute)
|
|
1568
|
+
.format(format);
|
|
1569
|
+
}
|
|
1570
|
+
exports.minute2str = minute2str;
|
|
1571
|
+
function second2str(second, format = 'HH:mm:ss') {
|
|
1572
|
+
return (second === null || second === exports.nulls.int32) ?
|
|
1573
|
+
''
|
|
1574
|
+
:
|
|
1575
|
+
(0, dayjs_1.default)(exports.timezone_offset + 1000 * second)
|
|
1576
|
+
.format(format);
|
|
1577
|
+
}
|
|
1578
|
+
exports.second2str = second2str;
|
|
1342
1579
|
function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
|
|
1343
|
-
return datetime === exports.nulls.int32 ?
|
|
1580
|
+
return (datetime === null || datetime === exports.nulls.int32) ?
|
|
1344
1581
|
''
|
|
1345
1582
|
:
|
|
1346
1583
|
(0, dayjs_1.default)(exports.timezone_offset + 1000 * datetime).format(format);
|
|
@@ -1353,12 +1590,19 @@ exports.datetime2str = datetime2str;
|
|
|
1353
1590
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1354
1591
|
*/
|
|
1355
1592
|
function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
1356
|
-
return timestamp === exports.nulls.int64 ?
|
|
1593
|
+
return (timestamp === null || timestamp === exports.nulls.int64) ?
|
|
1357
1594
|
''
|
|
1358
1595
|
:
|
|
1359
1596
|
(0, dayjs_1.default)(exports.timezone_offset + Number(timestamp)).format(format);
|
|
1360
1597
|
}
|
|
1361
1598
|
exports.timestamp2str = timestamp2str;
|
|
1599
|
+
function datehour2str(datehour, format = 'YYYY.MM.DD.HH') {
|
|
1600
|
+
return (datehour === null || datehour === exports.nulls.int32) ?
|
|
1601
|
+
''
|
|
1602
|
+
:
|
|
1603
|
+
(0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * datehour).format(format);
|
|
1604
|
+
}
|
|
1605
|
+
exports.datehour2str = datehour2str;
|
|
1362
1606
|
/** parse timestamp string to bigint value
|
|
1363
1607
|
- str: timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
|
|
1364
1608
|
- format?:
|
|
@@ -1374,6 +1618,19 @@ function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
|
1374
1618
|
(0, dayjs_1.default)(str, format).valueOf());
|
|
1375
1619
|
}
|
|
1376
1620
|
exports.str2timestamp = str2timestamp;
|
|
1621
|
+
function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
|
|
1622
|
+
const i_second_start = format.indexOf('ss');
|
|
1623
|
+
if (i_second_start === -1)
|
|
1624
|
+
throw new Error('The format string must contain the format for seconds (ss)');
|
|
1625
|
+
const i_second_end = i_second_start + 2;
|
|
1626
|
+
const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
|
|
1627
|
+
if (i_nanosecond_start === -1)
|
|
1628
|
+
throw new Error('The format string must contain the format for nanoseconds (SSSSSSSSS)');
|
|
1629
|
+
return ((0, dayjs_1.default)(exports.timezone_offset + (Number(nanotime) / 1000000)).format(format.slice(0, i_second_end)) +
|
|
1630
|
+
format.slice(i_second_end, i_nanosecond_start) +
|
|
1631
|
+
String(nanotime % 1000000000n).padStart(9, '0'));
|
|
1632
|
+
}
|
|
1633
|
+
exports.nanotime2str = nanotime2str;
|
|
1377
1634
|
/** format nanotimestamp value (bigint) to string
|
|
1378
1635
|
- nanotimestamp: bigint value
|
|
1379
1636
|
- format?:
|
|
@@ -1382,7 +1639,7 @@ exports.str2timestamp = str2timestamp;
|
|
|
1382
1639
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1383
1640
|
*/
|
|
1384
1641
|
function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
1385
|
-
if (nanotimestamp === exports.nulls.int64)
|
|
1642
|
+
if (nanotimestamp === null || nanotimestamp === exports.nulls.int64)
|
|
1386
1643
|
return '';
|
|
1387
1644
|
const i_second_start = format.indexOf('ss');
|
|
1388
1645
|
if (i_second_start === -1)
|
|
@@ -1393,7 +1650,7 @@ function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSS
|
|
|
1393
1650
|
throw new Error('The format string must contain the format for nanoseconds (SSSSSSSSS)');
|
|
1394
1651
|
return ((0, dayjs_1.default)(exports.timezone_offset + (Number(nanotimestamp) / 1000000)).format(format.slice(0, i_second_end)) +
|
|
1395
1652
|
format.slice(i_second_end, i_nanosecond_start) +
|
|
1396
|
-
String(nanotimestamp % 1000000000n));
|
|
1653
|
+
String(nanotimestamp % 1000000000n).padStart(9, '0'));
|
|
1397
1654
|
}
|
|
1398
1655
|
exports.nanotimestamp2str = nanotimestamp2str;
|
|
1399
1656
|
/** parse nano timestamp string to bigint value
|
|
@@ -1421,6 +1678,31 @@ function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
|
1421
1678
|
BigInt(str.slice(i_nanosecond_start, i_nanosecond_start + 9)));
|
|
1422
1679
|
}
|
|
1423
1680
|
exports.str2nanotimestamp = str2nanotimestamp;
|
|
1681
|
+
function ipaddr2str(buffer, le = true) {
|
|
1682
|
+
let buf = buffer;
|
|
1683
|
+
if (le)
|
|
1684
|
+
buf = buffer.slice().reverse();
|
|
1685
|
+
const i_non_zero = buf.findIndex(x => x);
|
|
1686
|
+
if (i_non_zero !== -1 && i_non_zero < 12) // ipv6 (i_non_zero === -1 或 0 < i_non_zero < 12)
|
|
1687
|
+
return [...buf].map(x => x.toString(16)
|
|
1688
|
+
.padStart(2, '0')).join(':');
|
|
1689
|
+
else // ipv4
|
|
1690
|
+
return buf.subarray(12).join('.');
|
|
1691
|
+
}
|
|
1692
|
+
exports.ipaddr2str = ipaddr2str;
|
|
1693
|
+
function uuid2str(buffer, le = true) {
|
|
1694
|
+
const str = int1282str(buffer, le);
|
|
1695
|
+
return `${str.slice(0, 8)}-${str.slice(8, 12)}-${str.slice(12, 16)}-${str.slice(16, 20)}-${str.slice(20)}`;
|
|
1696
|
+
}
|
|
1697
|
+
exports.uuid2str = uuid2str;
|
|
1698
|
+
function int1282str(buffer, le = true) {
|
|
1699
|
+
let buf = buffer;
|
|
1700
|
+
if (le)
|
|
1701
|
+
buf = buffer.slice().reverse();
|
|
1702
|
+
return [...buf].map(x => x.toString(16)
|
|
1703
|
+
.padStart(2, '0')).join('');
|
|
1704
|
+
}
|
|
1705
|
+
exports.int1282str = int1282str;
|
|
1424
1706
|
class DDB {
|
|
1425
1707
|
/**
|
|
1426
1708
|
Initialize an instance of DolphinDB Client using the WebSocket URL
|
|
@@ -1594,7 +1876,7 @@ class DDB {
|
|
|
1594
1876
|
- options:
|
|
1595
1877
|
- urgent?: 决定 `行为标识` 那一行字符串的取值(只适用于 script 和 function)
|
|
1596
1878
|
- vars?: type === 'variable' 时必传,variable 指令中待上传的变量名
|
|
1597
|
-
-
|
|
1879
|
+
- listener?: 处理本次 rpc 期间的消息 (DdbMessage)
|
|
1598
1880
|
- parse_object?: 在该次 rpc 期间设置 parse_object, 结束后恢复原有,为 false 时返回的 DdbObj 仅含有 buffer 和 le,
|
|
1599
1881
|
不做解析,以便后续转发、序列化
|
|
1600
1882
|
*/
|
|
@@ -1820,5 +2102,4 @@ class DDB {
|
|
|
1820
2102
|
exports.DDB = DDB;
|
|
1821
2103
|
/** little endian (client) */
|
|
1822
2104
|
DDB.le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
|
|
1823
|
-
exports.default = DDB;
|
|
1824
2105
|
//# sourceMappingURL=index.js.map
|