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 CHANGED
@@ -60,10 +60,28 @@ export declare enum DdbFunctionType {
60
60
  JitFunc = 7,
61
61
  JitPartialFunc = 8
62
62
  }
63
+ export declare enum DdbDurationUnit {
64
+ ns = 0,
65
+ us = 1,
66
+ ms = 2,
67
+ s = 3,
68
+ m = 4,
69
+ H = 5,
70
+ d = 6,
71
+ w = 7,
72
+ M = 8,
73
+ y = 9,
74
+ B = 10
75
+ }
63
76
  export interface DdbFunctionDefValue {
64
77
  type: DdbFunctionType;
65
78
  name: string;
66
79
  }
80
+ export interface DdbDurationValue {
81
+ unit: DdbDurationUnit;
82
+ /** int32 */
83
+ data: number;
84
+ }
67
85
  export interface DdbSymbolExtendedValue {
68
86
  base_id: number;
69
87
  base: string[];
@@ -85,7 +103,7 @@ export declare type DdbScalarValue = null | boolean | number | bigint | string |
85
103
  number,
86
104
  number
87
105
  ] | // complex, point
88
- DdbFunctionDefValue;
106
+ DdbFunctionDefValue | DdbDurationValue;
89
107
  export declare type DdbVectorValue = Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | string[] | // string[]
90
108
  Uint8Array[] | // blob
91
109
  DdbObj[] | // any
@@ -164,6 +182,7 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
164
182
  to_rows<T extends Record<string, any> = Record<string, any>>(): T[];
165
183
  to_dict<T = Record<string, any>>(): T;
166
184
  }
185
+ export declare function format(type: DdbType, value: DdbValue, le: boolean): string;
167
186
  export declare class DdbVoid extends DdbObj<undefined> {
168
187
  constructor();
169
188
  }
@@ -228,6 +247,10 @@ export declare class DdbTable extends DdbObj<DdbObj[]> {
228
247
  constructor(columns: DdbObj[], name?: string);
229
248
  }
230
249
  export declare function date2str(date: number, format?: string): string;
250
+ export declare function month2str(month: number | null): string;
251
+ export declare function time2str(time: number, format?: string): string;
252
+ export declare function minute2str(minute: number | null, format?: string): string;
253
+ export declare function second2str(second: number | null, format?: string): string;
231
254
  export declare function datetime2str(datetime: number, format?: string): string;
232
255
  /** format timestamp (bigint) to string
233
256
  - timestamp: bigint value
@@ -236,6 +259,7 @@ export declare function datetime2str(datetime: number, format?: string): string;
236
259
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
237
260
  */
238
261
  export declare function timestamp2str(timestamp: bigint, format?: string): string;
262
+ export declare function datehour2str(datehour: number, format?: string): string;
239
263
  /** parse timestamp string to bigint value
240
264
  - str: timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
241
265
  - format?:
@@ -243,6 +267,7 @@ export declare function timestamp2str(timestamp: bigint, format?: string): strin
243
267
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
244
268
  */
245
269
  export declare function str2timestamp(str: string, format?: string): bigint;
270
+ export declare function nanotime2str(nanotime: bigint, format?: string): string;
246
271
  /** format nanotimestamp value (bigint) to string
247
272
  - nanotimestamp: bigint value
248
273
  - format?:
@@ -259,6 +284,9 @@ export declare function nanotimestamp2str(nanotimestamp: bigint, format?: string
259
284
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
260
285
  */
261
286
  export declare function str2nanotimestamp(str: string, format?: string): bigint;
287
+ export declare function ipaddr2str(buffer: Uint8Array, le?: boolean): string;
288
+ export declare function uuid2str(buffer: Uint8Array, le?: boolean): string;
289
+ export declare function int1282str(buffer: Uint8Array, le?: boolean): string;
262
290
  export declare class DDB {
263
291
  /** 当前的 session id (http 或 tcp) */
264
292
  sid: string;
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.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"));
@@ -72,6 +72,20 @@ var DdbFunctionType;
72
72
  DdbFunctionType[DdbFunctionType["JitFunc"] = 7] = "JitFunc";
73
73
  DdbFunctionType[DdbFunctionType["JitPartialFunc"] = 8] = "JitPartialFunc";
74
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 = {}));
75
89
  exports.nulls = {
76
90
  int8: -0x80,
77
91
  int16: -32768,
@@ -322,6 +336,7 @@ class DdbObj {
322
336
  case DdbType.string:
323
337
  case DdbType.symbol:
324
338
  case DdbType.code:
339
+ case DdbType.handle:
325
340
  case DdbType.functiondef: {
326
341
  const i_head = type === DdbType.functiondef ? 1 : 0;
327
342
  let i_zero = buf.indexOf(0, i_head);
@@ -369,8 +384,18 @@ class DdbObj {
369
384
  ]
370
385
  ];
371
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
+ }
372
397
  default:
373
- return [0, buf];
398
+ throw new Error(`${DdbType[type] || type} 暂时不支持解析`);
374
399
  }
375
400
  }
376
401
  /** parse: rows, cols, items
@@ -509,6 +534,7 @@ class DdbObj {
509
534
  ];
510
535
  case DdbType.string:
511
536
  case DdbType.symbol:
537
+ case DdbType.handle:
512
538
  case DdbType.code: {
513
539
  let value = new Array(length);
514
540
  let i_head = 0, i_tail = i_head;
@@ -602,6 +628,13 @@ class DdbObj {
602
628
  values
603
629
  ];
604
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>
605
638
  default:
606
639
  return [0, buf];
607
640
  }
@@ -681,6 +714,7 @@ class DdbObj {
681
714
  case DdbType.string:
682
715
  case DdbType.symbol:
683
716
  case DdbType.code:
717
+ case DdbType.handle:
684
718
  return [
685
719
  DdbObj.enc.encode(value),
686
720
  Uint8Array.of(0),
@@ -703,12 +737,12 @@ class DdbObj {
703
737
  case DdbType.complex:
704
738
  case DdbType.point:
705
739
  return [Float64Array.from(this.value)];
706
- case DdbType.duration:
707
- return [value];
708
- case DdbType.handle:
709
- throw new Error('DolphinDB Server 不支持 handle 的反序列化');
740
+ case DdbType.duration: {
741
+ const { unit, data } = this.value;
742
+ return [Int32Array.of(data, unit)];
743
+ }
710
744
  default:
711
- throw new Error(`${DdbType[type]} 暂时不支持序列化`);
745
+ throw new Error(`${DdbType[type] || type} 暂时不支持序列化`);
712
746
  }
713
747
  case DdbForm.vector:
714
748
  case DdbForm.pair:
@@ -801,6 +835,7 @@ class DdbObj {
801
835
  return [value];
802
836
  case DdbType.string:
803
837
  case DdbType.symbol:
838
+ case DdbType.handle:
804
839
  case DdbType.code: {
805
840
  let bufs = new Array(length * 2);
806
841
  for (let i = 0; i < length; i++) {
@@ -870,29 +905,71 @@ class DdbObj {
870
905
  case DdbForm.set:
871
906
  return `set<${tname}>[${this.rows}]`;
872
907
  case DdbForm.table:
873
- return `table[${this.rows} rows][${this.cols} cols]`;
908
+ return `table[${this.rows}r][${this.cols}c]`;
874
909
  case DdbForm.dict:
875
910
  return `dict<${DdbType[this.value[0].type]}, ${DdbType[this.value[1].type]}>`;
876
911
  case DdbForm.matrix:
877
- return `matrix<${DdbType[this.type]}>[${this.rows} rows][${this.cols} cols]`;
912
+ return `matrix<${DdbType[this.type]}>[${this.rows}r][${this.cols}c]`;
878
913
  default:
879
914
  return `${DdbForm[this.form]} ${tname}`;
880
915
  }
881
916
  })();
882
917
  const data = (() => {
883
918
  switch (this.form) {
884
- case DdbForm.pair:
885
- return `${this.value[0]}, ${this.value[1]}`;
886
919
  case DdbForm.scalar:
920
+ return format(this.type, this.value, this.le);
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
+ }
887
932
  switch (this.type) {
888
- case DdbType.functiondef:
889
- return `'${this.value.name}'`;
890
- case DdbType.string:
891
- return `'${this.value}'`;
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] = base[data[i]].quote('single');
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);
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);
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);
967
+ return format_array(items, this.value.length > limit);
968
+ }
892
969
  }
893
- break;
970
+ }
894
971
  }
895
- return this.value;
972
+ return String(this.value);
896
973
  })();
897
974
  return `${type}(${this.name ? `'${this.name}', ` : ''}${data})\n`;
898
975
  }
@@ -904,13 +981,13 @@ class DdbObj {
904
981
  };
905
982
  switch (col.type) {
906
983
  case DdbType.timestamp:
907
- col_.render = timestamp2str;
984
+ col_.render = value => timestamp2str(value);
908
985
  break;
909
986
  case DdbType.date:
910
- col_.render = date2str;
987
+ col_.render = value => date2str(value);
911
988
  break;
912
989
  case DdbType.ipaddr:
913
- col_.render = value => value.slice().reverse().join('.').replace(/^(0\.)+/, '');
990
+ col_.render = value => ipaddr2str(value, this.le);
914
991
  break;
915
992
  }
916
993
  return col_;
@@ -968,6 +1045,127 @@ DdbObj.enc = new TextEncoder();
968
1045
  DdbObj.symbol_bases = {};
969
1046
  /** little endian (client) */
970
1047
  DdbObj.le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
1048
+ function format(type, value, le) {
1049
+ switch (type) {
1050
+ case DdbType.bool:
1051
+ return String((value === null || value === exports.nulls.int8) ?
1052
+ null
1053
+ :
1054
+ Boolean(value));
1055
+ case DdbType.char:
1056
+ return String((value === null || value === exports.nulls.int8) ?
1057
+ null
1058
+ :
1059
+ value);
1060
+ case DdbType.short:
1061
+ return String((value === null || value === exports.nulls.int16) ?
1062
+ null
1063
+ :
1064
+ value);
1065
+ case DdbType.int:
1066
+ return String((value === null || value === exports.nulls.int32) ?
1067
+ null
1068
+ :
1069
+ value);
1070
+ case DdbType.long:
1071
+ return (value === null || value === exports.nulls.int64) ?
1072
+ 'null'
1073
+ :
1074
+ String(value);
1075
+ case DdbType.date:
1076
+ return (value === null || value === exports.nulls.int32) ?
1077
+ 'null'
1078
+ :
1079
+ date2str(value);
1080
+ case DdbType.month:
1081
+ return (value === null || value === exports.nulls.int32) ?
1082
+ 'null'
1083
+ :
1084
+ month2str(value);
1085
+ case DdbType.time:
1086
+ return (value === null || value === exports.nulls.int32) ?
1087
+ 'null'
1088
+ :
1089
+ time2str(value);
1090
+ case DdbType.minute:
1091
+ return (value === null || value === exports.nulls.int32) ?
1092
+ 'null'
1093
+ :
1094
+ minute2str(value);
1095
+ case DdbType.second:
1096
+ return (value === null || value === exports.nulls.int32) ?
1097
+ 'null'
1098
+ :
1099
+ second2str(value);
1100
+ case DdbType.datetime:
1101
+ return (value === null || value === exports.nulls.int32) ?
1102
+ 'null'
1103
+ :
1104
+ datetime2str(value);
1105
+ case DdbType.timestamp:
1106
+ return (value === null || value === exports.nulls.int64) ?
1107
+ 'null'
1108
+ :
1109
+ timestamp2str(value);
1110
+ case DdbType.nanotime:
1111
+ return (value === null || value === exports.nulls.int64) ?
1112
+ 'null'
1113
+ :
1114
+ nanotime2str(value);
1115
+ case DdbType.nanotimestamp:
1116
+ return (value === null || value === exports.nulls.int64) ?
1117
+ 'null'
1118
+ :
1119
+ nanotimestamp2str(value);
1120
+ case DdbType.float:
1121
+ return (value === null || value === exports.nulls.float32) ?
1122
+ 'null'
1123
+ :
1124
+ String(value);
1125
+ case DdbType.double:
1126
+ return (value === null || value === exports.nulls.double) ?
1127
+ 'null'
1128
+ :
1129
+ String(value);
1130
+ case DdbType.symbol:
1131
+ case DdbType.string:
1132
+ return value.quote('single');
1133
+ case DdbType.uuid:
1134
+ return uuid2str(value, le);
1135
+ case DdbType.functiondef:
1136
+ return value.quote('single');
1137
+ case DdbType.handle:
1138
+ case DdbType.code:
1139
+ return value.quote('single');
1140
+ case DdbType.datehour:
1141
+ return (value === null || value === exports.nulls.int32) ?
1142
+ 'null'
1143
+ :
1144
+ datehour2str(value);
1145
+ case DdbType.ipaddr:
1146
+ return ipaddr2str(value, le);
1147
+ case DdbType.int128:
1148
+ return int1282str(value, le);
1149
+ case DdbType.blob:
1150
+ return DdbObj.dec.decode(value.subarray(0, 1000)).quote('single');
1151
+ case DdbType.complex:
1152
+ case DdbType.point: {
1153
+ let [x, y] = value;
1154
+ if (x === exports.nulls.double)
1155
+ x = null;
1156
+ if (y === exports.nulls.double)
1157
+ y = null;
1158
+ return `(${String(x)}, ${String(y)})`;
1159
+ }
1160
+ case DdbType.duration: {
1161
+ const { data, unit } = value;
1162
+ return `${data}${DdbDurationUnit[unit]}`;
1163
+ }
1164
+ default:
1165
+ return String(value);
1166
+ }
1167
+ }
1168
+ exports.format = format;
971
1169
  class DdbVoid extends DdbObj {
972
1170
  constructor() {
973
1171
  super({
@@ -1278,14 +1476,48 @@ class DdbTable extends DdbObj {
1278
1476
  }
1279
1477
  exports.DdbTable = DdbTable;
1280
1478
  function date2str(date, format = 'YYYY.MM.DD') {
1281
- return date === exports.nulls.int32 ?
1479
+ return (date === null || date === exports.nulls.int32) ?
1282
1480
  ''
1283
1481
  :
1284
1482
  (0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * 24 * date).format(format);
1285
1483
  }
1286
1484
  exports.date2str = date2str;
1485
+ function month2str(month) {
1486
+ if (month === null || month === exports.nulls.int32)
1487
+ return '';
1488
+ if (month < 0)
1489
+ return String(month);
1490
+ let _month = month % 12;
1491
+ let year = Math.floor(month / 12);
1492
+ return `${String(year).padStart(4, '0')}.${String(_month + 1).padStart(2, '0')}`;
1493
+ }
1494
+ exports.month2str = month2str;
1495
+ function time2str(time, format = 'HH:mm:ss.SSS') {
1496
+ return (time === null || time === exports.nulls.int32) ?
1497
+ ''
1498
+ :
1499
+ (0, dayjs_1.default)(exports.timezone_offset + time)
1500
+ .format(format);
1501
+ }
1502
+ exports.time2str = time2str;
1503
+ function minute2str(minute, format = 'HH:mm') {
1504
+ return (minute === null || minute === exports.nulls.int32) ?
1505
+ ''
1506
+ :
1507
+ (0, dayjs_1.default)(exports.timezone_offset + 60 * 1000 * minute)
1508
+ .format(format);
1509
+ }
1510
+ exports.minute2str = minute2str;
1511
+ function second2str(second, format = 'HH:mm:ss') {
1512
+ return (second === null || second === exports.nulls.int32) ?
1513
+ ''
1514
+ :
1515
+ (0, dayjs_1.default)(exports.timezone_offset + 1000 * second)
1516
+ .format(format);
1517
+ }
1518
+ exports.second2str = second2str;
1287
1519
  function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
1288
- return datetime === exports.nulls.int32 ?
1520
+ return (datetime === null || datetime === exports.nulls.int32) ?
1289
1521
  ''
1290
1522
  :
1291
1523
  (0, dayjs_1.default)(exports.timezone_offset + 1000 * datetime).format(format);
@@ -1298,12 +1530,19 @@ exports.datetime2str = datetime2str;
1298
1530
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1299
1531
  */
1300
1532
  function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1301
- return timestamp === exports.nulls.int64 ?
1533
+ return (timestamp === null || timestamp === exports.nulls.int64) ?
1302
1534
  ''
1303
1535
  :
1304
1536
  (0, dayjs_1.default)(exports.timezone_offset + Number(timestamp)).format(format);
1305
1537
  }
1306
1538
  exports.timestamp2str = timestamp2str;
1539
+ function datehour2str(datehour, format = 'YYYY.MM.DD.HH') {
1540
+ return (datehour === null || datehour === exports.nulls.int32) ?
1541
+ ''
1542
+ :
1543
+ (0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * datehour).format(format);
1544
+ }
1545
+ exports.datehour2str = datehour2str;
1307
1546
  /** parse timestamp string to bigint value
1308
1547
  - str: timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
1309
1548
  - format?:
@@ -1319,6 +1558,19 @@ function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1319
1558
  (0, dayjs_1.default)(str, format).valueOf());
1320
1559
  }
1321
1560
  exports.str2timestamp = str2timestamp;
1561
+ function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
1562
+ const i_second_start = format.indexOf('ss');
1563
+ if (i_second_start === -1)
1564
+ throw new Error('格式串必须包含秒的格式 (ss)');
1565
+ const i_second_end = i_second_start + 2;
1566
+ const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
1567
+ if (i_nanosecond_start === -1)
1568
+ throw new Error('格式串必须包含纳秒的格式 (SSSSSSSSS)');
1569
+ return ((0, dayjs_1.default)(exports.timezone_offset + (Number(nanotime) / 1000000)).format(format.slice(0, i_second_end)) +
1570
+ format.slice(i_second_end, i_nanosecond_start) +
1571
+ String(nanotime % 1000000000n).padStart(9, '0'));
1572
+ }
1573
+ exports.nanotime2str = nanotime2str;
1322
1574
  /** format nanotimestamp value (bigint) to string
1323
1575
  - nanotimestamp: bigint value
1324
1576
  - format?:
@@ -1327,7 +1579,7 @@ exports.str2timestamp = str2timestamp;
1327
1579
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1328
1580
  */
1329
1581
  function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1330
- if (nanotimestamp === exports.nulls.int64)
1582
+ if (nanotimestamp === null || nanotimestamp === exports.nulls.int64)
1331
1583
  return '';
1332
1584
  const i_second_start = format.indexOf('ss');
1333
1585
  if (i_second_start === -1)
@@ -1338,7 +1590,7 @@ function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSS
1338
1590
  throw new Error('The format string must contain the format for nanoseconds (SSSSSSSSS)');
1339
1591
  return ((0, dayjs_1.default)(exports.timezone_offset + (Number(nanotimestamp) / 1000000)).format(format.slice(0, i_second_end)) +
1340
1592
  format.slice(i_second_end, i_nanosecond_start) +
1341
- String(nanotimestamp % 1000000000n));
1593
+ String(nanotimestamp % 1000000000n).padStart(9, '0'));
1342
1594
  }
1343
1595
  exports.nanotimestamp2str = nanotimestamp2str;
1344
1596
  /** parse nano timestamp string to bigint value
@@ -1366,6 +1618,31 @@ function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1366
1618
  BigInt(str.slice(i_nanosecond_start, i_nanosecond_start + 9)));
1367
1619
  }
1368
1620
  exports.str2nanotimestamp = str2nanotimestamp;
1621
+ function ipaddr2str(buffer, le = true) {
1622
+ let buf = buffer;
1623
+ if (le)
1624
+ buf = buffer.slice().reverse();
1625
+ const i_non_zero = buf.findIndex(x => x);
1626
+ if (i_non_zero !== -1 && i_non_zero < 12) // ipv6 (i_non_zero === -1 或 0 < i_non_zero < 12)
1627
+ return [...buf].map(x => x.toString(16)
1628
+ .padStart(2, '0')).join(':');
1629
+ else // ipv4
1630
+ return buf.subarray(12).join('.');
1631
+ }
1632
+ exports.ipaddr2str = ipaddr2str;
1633
+ function uuid2str(buffer, le = true) {
1634
+ const str = int1282str(buffer, le);
1635
+ return `${str.slice(0, 8)}-${str.slice(8, 12)}-${str.slice(12, 16)}-${str.slice(16, 20)}-${str.slice(20)}`;
1636
+ }
1637
+ exports.uuid2str = uuid2str;
1638
+ function int1282str(buffer, le = true) {
1639
+ let buf = buffer;
1640
+ if (le)
1641
+ buf = buffer.slice().reverse();
1642
+ return [...buf].map(x => x.toString(16)
1643
+ .padStart(2, '0')).join('');
1644
+ }
1645
+ exports.int1282str = int1282str;
1369
1646
  class DDB {
1370
1647
  /**
1371
1648
  Initialize an instance of DolphinDB Client using the WebSocket URL