dolphindb 2.0.512 → 2.0.515
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 +17 -4
- package/browser.js +326 -33
- package/browser.js.map +1 -1
- package/index.d.ts +20 -7
- package/index.js +376 -33
- package/index.js.map +1 -1
- package/package.json +2 -2
package/browser.d.ts
CHANGED
|
@@ -10,6 +10,10 @@ export declare enum DdbForm {
|
|
|
10
10
|
chart = 7,
|
|
11
11
|
chunk = 8
|
|
12
12
|
}
|
|
13
|
+
/** DolphinDB DataType
|
|
14
|
+
对应的 array vector 类型为 64 + 基本类型
|
|
15
|
+
对应的 extended 类型为 128 + 基本类型
|
|
16
|
+
*/
|
|
13
17
|
export declare enum DdbType {
|
|
14
18
|
void = 0,
|
|
15
19
|
bool = 1,
|
|
@@ -91,7 +95,7 @@ export interface DdbArrayVectorBlock {
|
|
|
91
95
|
unit: 1 | 2 | 4;
|
|
92
96
|
rows: number;
|
|
93
97
|
lengths: Uint8Array | Uint16Array | Uint32Array;
|
|
94
|
-
data:
|
|
98
|
+
data: Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array;
|
|
95
99
|
}
|
|
96
100
|
export interface DdbMatrixValue {
|
|
97
101
|
rows: DdbObj<DdbVectorValue>;
|
|
@@ -182,6 +186,7 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
|
|
|
182
186
|
to_rows<T extends Record<string, any> = Record<string, any>>(): T[];
|
|
183
187
|
to_dict<T = Record<string, any>>(): T;
|
|
184
188
|
}
|
|
189
|
+
export declare function format(type: DdbType, value: DdbValue, le: boolean): string;
|
|
185
190
|
export declare class DdbVoid extends DdbObj<undefined> {
|
|
186
191
|
constructor();
|
|
187
192
|
}
|
|
@@ -246,6 +251,10 @@ export declare class DdbTable extends DdbObj<DdbObj[]> {
|
|
|
246
251
|
constructor(columns: DdbObj[], name?: string);
|
|
247
252
|
}
|
|
248
253
|
export declare function date2str(date: number, format?: string): string;
|
|
254
|
+
export declare function month2str(month: number | null): string;
|
|
255
|
+
export declare function time2str(time: number, format?: string): string;
|
|
256
|
+
export declare function minute2str(minute: number | null, format?: string): string;
|
|
257
|
+
export declare function second2str(second: number | null, format?: string): string;
|
|
249
258
|
export declare function datetime2str(datetime: number, format?: string): string;
|
|
250
259
|
/** format timestamp (bigint) to string
|
|
251
260
|
- timestamp: bigint value
|
|
@@ -254,13 +263,15 @@ export declare function datetime2str(datetime: number, format?: string): string;
|
|
|
254
263
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
255
264
|
*/
|
|
256
265
|
export declare function timestamp2str(timestamp: bigint, format?: string): string;
|
|
266
|
+
export declare function datehour2str(datehour: number, format?: string): string;
|
|
257
267
|
/** parse timestamp string to bigint value
|
|
258
|
-
- str: timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
|
|
268
|
+
- str: timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
|
|
259
269
|
- format?:
|
|
260
270
|
The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
|
|
261
271
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
262
272
|
*/
|
|
263
273
|
export declare function str2timestamp(str: string, format?: string): bigint;
|
|
274
|
+
export declare function nanotime2str(nanotime: bigint, format?: string): string;
|
|
264
275
|
/** format nanotimestamp value (bigint) to string
|
|
265
276
|
- nanotimestamp: bigint value
|
|
266
277
|
- format?:
|
|
@@ -270,13 +281,16 @@ export declare function str2timestamp(str: string, format?: string): bigint;
|
|
|
270
281
|
*/
|
|
271
282
|
export declare function nanotimestamp2str(nanotimestamp: bigint, format?: string): string;
|
|
272
283
|
/** parse nano timestamp string to bigint value
|
|
273
|
-
- str: nano timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
|
|
284
|
+
- str: nano timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
|
|
274
285
|
- format?:
|
|
275
286
|
The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
|
|
276
287
|
Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
|
|
277
288
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
278
289
|
*/
|
|
279
290
|
export declare function str2nanotimestamp(str: string, format?: string): bigint;
|
|
291
|
+
export declare function ipaddr2str(buffer: Uint8Array, le?: boolean): string;
|
|
292
|
+
export declare function uuid2str(buffer: Uint8Array, le?: boolean): string;
|
|
293
|
+
export declare function int1282str(buffer: Uint8Array, le?: boolean): string;
|
|
280
294
|
export declare class DDB {
|
|
281
295
|
/** 当前的 session id (http 或 tcp) */
|
|
282
296
|
sid: string;
|
|
@@ -463,4 +477,3 @@ export interface DdbErrorMessage {
|
|
|
463
477
|
}
|
|
464
478
|
export declare type DdbMessage = DdbPrintMessage | DdbObjectMessage | DdbErrorMessage;
|
|
465
479
|
export declare let ddb: DDB;
|
|
466
|
-
export default ddb;
|
package/browser.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ddb = 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.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 dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
6
6
|
const customParseFormat_js_1 = tslib_1.__importDefault(require("dayjs/plugin/customParseFormat.js"));
|
|
@@ -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";
|
|
@@ -471,7 +475,7 @@ class DdbObj {
|
|
|
471
475
|
unit,
|
|
472
476
|
rows,
|
|
473
477
|
lengths,
|
|
474
|
-
data
|
|
478
|
+
data: data
|
|
475
479
|
});
|
|
476
480
|
i_block_start = i_data_start + len_items;
|
|
477
481
|
i_row += rows;
|
|
@@ -905,33 +909,99 @@ class DdbObj {
|
|
|
905
909
|
case DdbForm.set:
|
|
906
910
|
return `set<${tname}>[${this.rows}]`;
|
|
907
911
|
case DdbForm.table:
|
|
908
|
-
return `table[${this.rows}
|
|
912
|
+
return `table[${this.rows}r][${this.cols}c]`;
|
|
909
913
|
case DdbForm.dict:
|
|
910
914
|
return `dict<${DdbType[this.value[0].type]}, ${DdbType[this.value[1].type]}>`;
|
|
911
915
|
case DdbForm.matrix:
|
|
912
|
-
return `matrix<${DdbType[this.type]}>[${this.rows}
|
|
916
|
+
return `matrix<${DdbType[this.type]}>[${this.rows}r][${this.cols}c]`;
|
|
913
917
|
default:
|
|
914
918
|
return `${DdbForm[this.form]} ${tname}`;
|
|
915
919
|
}
|
|
916
920
|
})();
|
|
917
921
|
const data = (() => {
|
|
918
922
|
switch (this.form) {
|
|
919
|
-
case DdbForm.pair:
|
|
920
|
-
return `${this.value[0]}, ${this.value[1]}`;
|
|
921
923
|
case DdbForm.scalar:
|
|
924
|
+
return format(this.type, this.value, this.le);
|
|
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);
|
|
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
|
+
}
|
|
922
964
|
switch (this.type) {
|
|
923
|
-
case DdbType.
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
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] = base[data[i]].quote('single');
|
|
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);
|
|
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);
|
|
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);
|
|
999
|
+
return format_array(items, this.value.length > limit);
|
|
928
1000
|
}
|
|
929
|
-
case DdbType.string:
|
|
930
|
-
return `'${this.value}'`;
|
|
931
1001
|
}
|
|
932
|
-
|
|
1002
|
+
}
|
|
933
1003
|
}
|
|
934
|
-
return this.value;
|
|
1004
|
+
return String(this.value);
|
|
935
1005
|
})();
|
|
936
1006
|
return `${type}(${this.name ? `'${this.name}', ` : ''}${data})\n`;
|
|
937
1007
|
}
|
|
@@ -943,13 +1013,13 @@ class DdbObj {
|
|
|
943
1013
|
};
|
|
944
1014
|
switch (col.type) {
|
|
945
1015
|
case DdbType.timestamp:
|
|
946
|
-
col_.render = timestamp2str;
|
|
1016
|
+
col_.render = value => timestamp2str(value);
|
|
947
1017
|
break;
|
|
948
1018
|
case DdbType.date:
|
|
949
|
-
col_.render = date2str;
|
|
1019
|
+
col_.render = value => date2str(value);
|
|
950
1020
|
break;
|
|
951
1021
|
case DdbType.ipaddr:
|
|
952
|
-
col_.render = value => value.
|
|
1022
|
+
col_.render = value => ipaddr2str(value, this.le);
|
|
953
1023
|
break;
|
|
954
1024
|
}
|
|
955
1025
|
return col_;
|
|
@@ -1007,6 +1077,134 @@ DdbObj.enc = new TextEncoder();
|
|
|
1007
1077
|
DdbObj.symbol_bases = {};
|
|
1008
1078
|
/** little endian (client) */
|
|
1009
1079
|
DdbObj.le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
|
|
1080
|
+
function format(type, value, le) {
|
|
1081
|
+
switch (type) {
|
|
1082
|
+
case DdbType.bool:
|
|
1083
|
+
return String((value === null || value === exports.nulls.int8) ?
|
|
1084
|
+
null
|
|
1085
|
+
:
|
|
1086
|
+
Boolean(value));
|
|
1087
|
+
case DdbType.char:
|
|
1088
|
+
return String((value === null || value === exports.nulls.int8) ?
|
|
1089
|
+
null
|
|
1090
|
+
:
|
|
1091
|
+
value);
|
|
1092
|
+
case DdbType.short:
|
|
1093
|
+
return String((value === null || value === exports.nulls.int16) ?
|
|
1094
|
+
null
|
|
1095
|
+
:
|
|
1096
|
+
value);
|
|
1097
|
+
case DdbType.int:
|
|
1098
|
+
return String((value === null || value === exports.nulls.int32) ?
|
|
1099
|
+
null
|
|
1100
|
+
:
|
|
1101
|
+
value);
|
|
1102
|
+
case DdbType.long:
|
|
1103
|
+
return (value === null || value === exports.nulls.int64) ?
|
|
1104
|
+
'null'
|
|
1105
|
+
:
|
|
1106
|
+
String(value);
|
|
1107
|
+
case DdbType.date:
|
|
1108
|
+
return (value === null || value === exports.nulls.int32) ?
|
|
1109
|
+
'null'
|
|
1110
|
+
:
|
|
1111
|
+
date2str(value);
|
|
1112
|
+
case DdbType.month:
|
|
1113
|
+
return (value === null || value === exports.nulls.int32) ?
|
|
1114
|
+
'null'
|
|
1115
|
+
:
|
|
1116
|
+
month2str(value);
|
|
1117
|
+
case DdbType.time:
|
|
1118
|
+
return (value === null || value === exports.nulls.int32) ?
|
|
1119
|
+
'null'
|
|
1120
|
+
:
|
|
1121
|
+
time2str(value);
|
|
1122
|
+
case DdbType.minute:
|
|
1123
|
+
return (value === null || value === exports.nulls.int32) ?
|
|
1124
|
+
'null'
|
|
1125
|
+
:
|
|
1126
|
+
minute2str(value);
|
|
1127
|
+
case DdbType.second:
|
|
1128
|
+
return (value === null || value === exports.nulls.int32) ?
|
|
1129
|
+
'null'
|
|
1130
|
+
:
|
|
1131
|
+
second2str(value);
|
|
1132
|
+
case DdbType.datetime:
|
|
1133
|
+
return (value === null || value === exports.nulls.int32) ?
|
|
1134
|
+
'null'
|
|
1135
|
+
:
|
|
1136
|
+
datetime2str(value);
|
|
1137
|
+
case DdbType.timestamp:
|
|
1138
|
+
return (value === null || value === exports.nulls.int64) ?
|
|
1139
|
+
'null'
|
|
1140
|
+
:
|
|
1141
|
+
timestamp2str(value);
|
|
1142
|
+
case DdbType.nanotime:
|
|
1143
|
+
return (value === null || value === exports.nulls.int64) ?
|
|
1144
|
+
'null'
|
|
1145
|
+
:
|
|
1146
|
+
nanotime2str(value);
|
|
1147
|
+
case DdbType.nanotimestamp:
|
|
1148
|
+
return (value === null || value === exports.nulls.int64) ?
|
|
1149
|
+
'null'
|
|
1150
|
+
:
|
|
1151
|
+
nanotimestamp2str(value);
|
|
1152
|
+
case DdbType.float:
|
|
1153
|
+
return (value === null || value === exports.nulls.float32) ?
|
|
1154
|
+
'null'
|
|
1155
|
+
:
|
|
1156
|
+
String(value);
|
|
1157
|
+
case DdbType.double:
|
|
1158
|
+
return (value === null || value === exports.nulls.double) ?
|
|
1159
|
+
'null'
|
|
1160
|
+
:
|
|
1161
|
+
String(value);
|
|
1162
|
+
case DdbType.symbol:
|
|
1163
|
+
case DdbType.string:
|
|
1164
|
+
return value.quote('single');
|
|
1165
|
+
case DdbType.uuid:
|
|
1166
|
+
return uuid2str(value, le);
|
|
1167
|
+
case DdbType.functiondef:
|
|
1168
|
+
return value.quote('single');
|
|
1169
|
+
case DdbType.handle:
|
|
1170
|
+
case DdbType.code:
|
|
1171
|
+
return value.quote('single');
|
|
1172
|
+
case DdbType.datehour:
|
|
1173
|
+
return (value === null || value === exports.nulls.int32) ?
|
|
1174
|
+
'null'
|
|
1175
|
+
:
|
|
1176
|
+
datehour2str(value);
|
|
1177
|
+
case DdbType.ipaddr:
|
|
1178
|
+
return ipaddr2str(value, le);
|
|
1179
|
+
case DdbType.int128:
|
|
1180
|
+
return int1282str(value, le);
|
|
1181
|
+
case DdbType.blob:
|
|
1182
|
+
return DdbObj.dec.decode(value.subarray(0, 1000)).quote('single');
|
|
1183
|
+
case DdbType.point: {
|
|
1184
|
+
let [x, y] = value;
|
|
1185
|
+
if (x === exports.nulls.double)
|
|
1186
|
+
x = null;
|
|
1187
|
+
if (y === exports.nulls.double)
|
|
1188
|
+
y = null;
|
|
1189
|
+
return `(${String(x)}, ${String(y)})`;
|
|
1190
|
+
}
|
|
1191
|
+
case DdbType.complex: {
|
|
1192
|
+
let [x, y] = value;
|
|
1193
|
+
if (x === exports.nulls.double)
|
|
1194
|
+
x = null;
|
|
1195
|
+
if (y === exports.nulls.double)
|
|
1196
|
+
y = null;
|
|
1197
|
+
return `${String(x)}+${String(y)}i`;
|
|
1198
|
+
}
|
|
1199
|
+
case DdbType.duration: {
|
|
1200
|
+
const { data, unit } = value;
|
|
1201
|
+
return `${data}${DdbDurationUnit[unit]}`;
|
|
1202
|
+
}
|
|
1203
|
+
default:
|
|
1204
|
+
return String(value);
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
exports.format = format;
|
|
1010
1208
|
class DdbVoid extends DdbObj {
|
|
1011
1209
|
constructor() {
|
|
1012
1210
|
super({
|
|
@@ -1317,15 +1515,49 @@ class DdbTable extends DdbObj {
|
|
|
1317
1515
|
}
|
|
1318
1516
|
exports.DdbTable = DdbTable;
|
|
1319
1517
|
function date2str(date, format = 'YYYY.MM.DD') {
|
|
1320
|
-
return date === exports.nulls.int32 ?
|
|
1321
|
-
''
|
|
1518
|
+
return (date === null || date === exports.nulls.int32) ?
|
|
1519
|
+
'null'
|
|
1322
1520
|
:
|
|
1323
1521
|
(0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * 24 * date).format(format);
|
|
1324
1522
|
}
|
|
1325
1523
|
exports.date2str = date2str;
|
|
1524
|
+
function month2str(month) {
|
|
1525
|
+
if (month === null || month === exports.nulls.int32)
|
|
1526
|
+
return 'null';
|
|
1527
|
+
if (month < 0)
|
|
1528
|
+
return String(month);
|
|
1529
|
+
const _month = month % 12;
|
|
1530
|
+
const year = Math.trunc(month / 12);
|
|
1531
|
+
return `${String(year).padStart(4, '0')}.${String(_month + 1).padStart(2, '0')}M`;
|
|
1532
|
+
}
|
|
1533
|
+
exports.month2str = month2str;
|
|
1534
|
+
function time2str(time, format = 'HH:mm:ss.SSS') {
|
|
1535
|
+
return (time === null || time === exports.nulls.int32) ?
|
|
1536
|
+
'null'
|
|
1537
|
+
:
|
|
1538
|
+
(0, dayjs_1.default)(exports.timezone_offset + time)
|
|
1539
|
+
.format(format);
|
|
1540
|
+
}
|
|
1541
|
+
exports.time2str = time2str;
|
|
1542
|
+
function minute2str(minute, format = 'HH:mm') {
|
|
1543
|
+
return (minute === null || minute === exports.nulls.int32) ?
|
|
1544
|
+
'null'
|
|
1545
|
+
:
|
|
1546
|
+
(0, dayjs_1.default)(exports.timezone_offset + 60 * 1000 * minute)
|
|
1547
|
+
.format(format);
|
|
1548
|
+
}
|
|
1549
|
+
exports.minute2str = minute2str;
|
|
1550
|
+
function second2str(second, format = 'HH:mm:ss') {
|
|
1551
|
+
return (second === null || second === exports.nulls.int32) ?
|
|
1552
|
+
'null'
|
|
1553
|
+
:
|
|
1554
|
+
(0, dayjs_1.default)(exports.timezone_offset + 1000 * second)
|
|
1555
|
+
.format(format);
|
|
1556
|
+
}
|
|
1557
|
+
exports.second2str = second2str;
|
|
1326
1558
|
function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
|
|
1327
|
-
return datetime === exports.nulls.int32 ?
|
|
1328
|
-
''
|
|
1559
|
+
return (datetime === null || datetime === exports.nulls.int32) ?
|
|
1560
|
+
'null'
|
|
1329
1561
|
:
|
|
1330
1562
|
(0, dayjs_1.default)(exports.timezone_offset + 1000 * datetime).format(format);
|
|
1331
1563
|
}
|
|
@@ -1337,20 +1569,27 @@ exports.datetime2str = datetime2str;
|
|
|
1337
1569
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1338
1570
|
*/
|
|
1339
1571
|
function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
1340
|
-
return timestamp === exports.nulls.int64 ?
|
|
1341
|
-
''
|
|
1572
|
+
return (timestamp === null || timestamp === exports.nulls.int64) ?
|
|
1573
|
+
'null'
|
|
1342
1574
|
:
|
|
1343
1575
|
(0, dayjs_1.default)(exports.timezone_offset + Number(timestamp)).format(format);
|
|
1344
1576
|
}
|
|
1345
1577
|
exports.timestamp2str = timestamp2str;
|
|
1578
|
+
function datehour2str(datehour, format = 'YYYY.MM.DDTHH') {
|
|
1579
|
+
return (datehour === null || datehour === exports.nulls.int32) ?
|
|
1580
|
+
'null'
|
|
1581
|
+
:
|
|
1582
|
+
(0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * datehour).format(format);
|
|
1583
|
+
}
|
|
1584
|
+
exports.datehour2str = datehour2str;
|
|
1346
1585
|
/** parse timestamp string to bigint value
|
|
1347
|
-
- str: timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
|
|
1586
|
+
- str: timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
|
|
1348
1587
|
- format?:
|
|
1349
1588
|
The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
|
|
1350
1589
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1351
1590
|
*/
|
|
1352
1591
|
function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
1353
|
-
if (!str)
|
|
1592
|
+
if (!str || str === 'null')
|
|
1354
1593
|
return exports.nulls.int64;
|
|
1355
1594
|
if (str.length !== format.length)
|
|
1356
1595
|
throw new Error('The length of the timestamp string is not equal to the length of the format string');
|
|
@@ -1358,6 +1597,23 @@ function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
|
1358
1597
|
(0, dayjs_1.default)(str, format).valueOf());
|
|
1359
1598
|
}
|
|
1360
1599
|
exports.str2timestamp = str2timestamp;
|
|
1600
|
+
function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
|
|
1601
|
+
if (nanotime === null || nanotime === exports.nulls.int64)
|
|
1602
|
+
return 'null';
|
|
1603
|
+
if (nanotime < 0n)
|
|
1604
|
+
return String(nanotime);
|
|
1605
|
+
const i_second_start = format.indexOf('ss');
|
|
1606
|
+
if (i_second_start === -1)
|
|
1607
|
+
throw new Error('格式串必须包含秒的格式 (ss)');
|
|
1608
|
+
const i_second_end = i_second_start + 2;
|
|
1609
|
+
const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
|
|
1610
|
+
if (i_nanosecond_start === -1)
|
|
1611
|
+
throw new Error('格式串必须包含纳秒的格式 (SSSSSSSSS)');
|
|
1612
|
+
return ((0, dayjs_1.default)(exports.timezone_offset + (Number(nanotime) / 1000000)).format(format.slice(0, i_second_end)) +
|
|
1613
|
+
format.slice(i_second_end, i_nanosecond_start) +
|
|
1614
|
+
String(nanotime % 1000000000n).padStart(9, '0'));
|
|
1615
|
+
}
|
|
1616
|
+
exports.nanotime2str = nanotime2str;
|
|
1361
1617
|
/** format nanotimestamp value (bigint) to string
|
|
1362
1618
|
- nanotimestamp: bigint value
|
|
1363
1619
|
- format?:
|
|
@@ -1366,8 +1622,14 @@ exports.str2timestamp = str2timestamp;
|
|
|
1366
1622
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1367
1623
|
*/
|
|
1368
1624
|
function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
1369
|
-
|
|
1370
|
-
|
|
1625
|
+
// tests:
|
|
1626
|
+
// nanotimestamp2str(0n)
|
|
1627
|
+
// nanotimestamp2str(-1n)
|
|
1628
|
+
// nanotimestamp2str(-9_9999_9999n)
|
|
1629
|
+
// nanotimestamp2str(-10_0000_0000n)
|
|
1630
|
+
// nanotimestamp2str(-10_0000_0001n)
|
|
1631
|
+
if (nanotimestamp === null || nanotimestamp === exports.nulls.int64)
|
|
1632
|
+
return 'null';
|
|
1371
1633
|
const i_second_start = format.indexOf('ss');
|
|
1372
1634
|
if (i_second_start === -1)
|
|
1373
1635
|
throw new Error('The format string must contain the format for seconds (ss)');
|
|
@@ -1375,20 +1637,27 @@ function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSS
|
|
|
1375
1637
|
const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
|
|
1376
1638
|
if (i_nanosecond_start === -1)
|
|
1377
1639
|
throw new Error('The format string must contain the format for nanoseconds (SSSSSSSSS)');
|
|
1378
|
-
|
|
1640
|
+
const remainder = nanotimestamp % 1000000000n;
|
|
1641
|
+
const borrow = remainder < 0n;
|
|
1642
|
+
return ((0, dayjs_1.default)(exports.timezone_offset +
|
|
1643
|
+
// 去掉 9 位的纳秒部分,转化为毫秒
|
|
1644
|
+
Number((nanotimestamp - remainder + (borrow ? -1000000000n : 0n)) / 1000000n)).format(format.slice(0, i_second_end)) +
|
|
1379
1645
|
format.slice(i_second_end, i_nanosecond_start) +
|
|
1380
|
-
String(
|
|
1646
|
+
String(borrow ?
|
|
1647
|
+
(remainder + 1000000000n) % 1000000000n
|
|
1648
|
+
:
|
|
1649
|
+
remainder).padStart(9, '0'));
|
|
1381
1650
|
}
|
|
1382
1651
|
exports.nanotimestamp2str = nanotimestamp2str;
|
|
1383
1652
|
/** parse nano timestamp string to bigint value
|
|
1384
|
-
- str: nano timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
|
|
1653
|
+
- str: nano timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
|
|
1385
1654
|
- format?:
|
|
1386
1655
|
The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
|
|
1387
1656
|
Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
|
|
1388
1657
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1389
1658
|
*/
|
|
1390
1659
|
function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
1391
|
-
if (!str)
|
|
1660
|
+
if (!str || str === 'null')
|
|
1392
1661
|
return exports.nulls.int64;
|
|
1393
1662
|
if (str.length !== format.length)
|
|
1394
1663
|
throw new Error('nanotimestamp string length is not equal to format string length');
|
|
@@ -1405,6 +1674,31 @@ function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
|
1405
1674
|
BigInt(str.slice(i_nanosecond_start, i_nanosecond_start + 9)));
|
|
1406
1675
|
}
|
|
1407
1676
|
exports.str2nanotimestamp = str2nanotimestamp;
|
|
1677
|
+
function ipaddr2str(buffer, le = true) {
|
|
1678
|
+
let buf = buffer;
|
|
1679
|
+
if (le)
|
|
1680
|
+
buf = buffer.slice().reverse();
|
|
1681
|
+
const i_non_zero = buf.findIndex(x => x);
|
|
1682
|
+
if (i_non_zero !== -1 && i_non_zero < 12) // ipv6 (i_non_zero === -1 或 0 < i_non_zero < 12)
|
|
1683
|
+
return [...buf].map(x => x.toString(16)
|
|
1684
|
+
.padStart(2, '0')).join(':');
|
|
1685
|
+
else // ipv4
|
|
1686
|
+
return buf.subarray(12).join('.');
|
|
1687
|
+
}
|
|
1688
|
+
exports.ipaddr2str = ipaddr2str;
|
|
1689
|
+
function uuid2str(buffer, le = true) {
|
|
1690
|
+
const str = int1282str(buffer, le);
|
|
1691
|
+
return `${str.slice(0, 8)}-${str.slice(8, 12)}-${str.slice(12, 16)}-${str.slice(16, 20)}-${str.slice(20)}`;
|
|
1692
|
+
}
|
|
1693
|
+
exports.uuid2str = uuid2str;
|
|
1694
|
+
function int1282str(buffer, le = true) {
|
|
1695
|
+
let buf = buffer;
|
|
1696
|
+
if (le)
|
|
1697
|
+
buf = buffer.slice().reverse();
|
|
1698
|
+
return [...buf].map(x => x.toString(16)
|
|
1699
|
+
.padStart(2, '0')).join('');
|
|
1700
|
+
}
|
|
1701
|
+
exports.int1282str = int1282str;
|
|
1408
1702
|
class DDB {
|
|
1409
1703
|
/**
|
|
1410
1704
|
Initialize an instance of DolphinDB Client using the WebSocket URL
|
|
@@ -1811,5 +2105,4 @@ exports.DDB = DDB;
|
|
|
1811
2105
|
/** little endian (client) */
|
|
1812
2106
|
DDB.le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
|
|
1813
2107
|
exports.ddb = window.ddb = new DDB();
|
|
1814
|
-
exports.default = exports.ddb;
|
|
1815
2108
|
//# sourceMappingURL=browser.js.map
|