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 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: DdbVectorValue;
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,6 +263,7 @@ 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
268
  - str: timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
259
269
  - format?:
@@ -261,6 +271,7 @@ export declare function timestamp2str(timestamp: bigint, format?: string): strin
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?:
@@ -277,6 +288,9 @@ export declare function nanotimestamp2str(nanotimestamp: bigint, format?: string
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";
@@ -336,6 +340,7 @@ class DdbObj {
336
340
  case DdbType.string:
337
341
  case DdbType.symbol:
338
342
  case DdbType.code:
343
+ case DdbType.handle:
339
344
  case DdbType.functiondef: {
340
345
  const i_head = type === DdbType.functiondef ? 1 : 0;
341
346
  let i_zero = buf.indexOf(0, i_head);
@@ -394,7 +399,7 @@ class DdbObj {
394
399
  ];
395
400
  }
396
401
  default:
397
- return [0, buf];
402
+ throw new Error(`${DdbType[type] || type} 暂时不支持解析`);
398
403
  }
399
404
  }
400
405
  /** parse: rows, cols, items
@@ -470,7 +475,7 @@ class DdbObj {
470
475
  unit,
471
476
  rows,
472
477
  lengths,
473
- data
478
+ data: data
474
479
  });
475
480
  i_block_start = i_data_start + len_items;
476
481
  i_row += rows;
@@ -533,6 +538,7 @@ class DdbObj {
533
538
  ];
534
539
  case DdbType.string:
535
540
  case DdbType.symbol:
541
+ case DdbType.handle:
536
542
  case DdbType.code: {
537
543
  let value = new Array(length);
538
544
  let i_head = 0, i_tail = i_head;
@@ -712,6 +718,7 @@ class DdbObj {
712
718
  case DdbType.string:
713
719
  case DdbType.symbol:
714
720
  case DdbType.code:
721
+ case DdbType.handle:
715
722
  return [
716
723
  DdbObj.enc.encode(value),
717
724
  Uint8Array.of(0),
@@ -738,10 +745,8 @@ class DdbObj {
738
745
  const { unit, data } = this.value;
739
746
  return [Int32Array.of(data, unit)];
740
747
  }
741
- case DdbType.handle:
742
- throw new Error('DolphinDB Server 不支持 handle 的反序列化');
743
748
  default:
744
- throw new Error(`${DdbType[type]} 暂时不支持序列化`);
749
+ throw new Error(`${DdbType[type] || type} 暂时不支持序列化`);
745
750
  }
746
751
  case DdbForm.vector:
747
752
  case DdbForm.pair:
@@ -834,6 +839,7 @@ class DdbObj {
834
839
  return [value];
835
840
  case DdbType.string:
836
841
  case DdbType.symbol:
842
+ case DdbType.handle:
837
843
  case DdbType.code: {
838
844
  let bufs = new Array(length * 2);
839
845
  for (let i = 0; i < length; i++) {
@@ -903,33 +909,99 @@ class DdbObj {
903
909
  case DdbForm.set:
904
910
  return `set<${tname}>[${this.rows}]`;
905
911
  case DdbForm.table:
906
- return `table[${this.rows} rows][${this.cols} cols]`;
912
+ return `table[${this.rows}r][${this.cols}c]`;
907
913
  case DdbForm.dict:
908
914
  return `dict<${DdbType[this.value[0].type]}, ${DdbType[this.value[1].type]}>`;
909
915
  case DdbForm.matrix:
910
- return `matrix<${DdbType[this.type]}>[${this.rows} rows][${this.cols} cols]`;
916
+ return `matrix<${DdbType[this.type]}>[${this.rows}r][${this.cols}c]`;
911
917
  default:
912
918
  return `${DdbForm[this.form]} ${tname}`;
913
919
  }
914
920
  })();
915
921
  const data = (() => {
916
922
  switch (this.form) {
917
- case DdbForm.pair:
918
- return `${this.value[0]}, ${this.value[1]}`;
919
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
+ }
920
964
  switch (this.type) {
921
- case DdbType.functiondef:
922
- return `'${this.value.name}'`;
923
- case DdbType.duration: {
924
- const { data, unit } = this.value;
925
- return `${data}${DdbDurationUnit[unit]}`;
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);
926
1000
  }
927
- case DdbType.string:
928
- return `'${this.value}'`;
929
1001
  }
930
- break;
1002
+ }
931
1003
  }
932
- return this.value;
1004
+ return String(this.value);
933
1005
  })();
934
1006
  return `${type}(${this.name ? `'${this.name}', ` : ''}${data})\n`;
935
1007
  }
@@ -941,13 +1013,13 @@ class DdbObj {
941
1013
  };
942
1014
  switch (col.type) {
943
1015
  case DdbType.timestamp:
944
- col_.render = timestamp2str;
1016
+ col_.render = value => timestamp2str(value);
945
1017
  break;
946
1018
  case DdbType.date:
947
- col_.render = date2str;
1019
+ col_.render = value => date2str(value);
948
1020
  break;
949
1021
  case DdbType.ipaddr:
950
- col_.render = value => value.slice().reverse().join('.').replace(/^(0\.)+/, '');
1022
+ col_.render = value => ipaddr2str(value, this.le);
951
1023
  break;
952
1024
  }
953
1025
  return col_;
@@ -1005,6 +1077,127 @@ DdbObj.enc = new TextEncoder();
1005
1077
  DdbObj.symbol_bases = {};
1006
1078
  /** little endian (client) */
1007
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.complex:
1184
+ case DdbType.point: {
1185
+ let [x, y] = value;
1186
+ if (x === exports.nulls.double)
1187
+ x = null;
1188
+ if (y === exports.nulls.double)
1189
+ y = null;
1190
+ return `(${String(x)}, ${String(y)})`;
1191
+ }
1192
+ case DdbType.duration: {
1193
+ const { data, unit } = value;
1194
+ return `${data}${DdbDurationUnit[unit]}`;
1195
+ }
1196
+ default:
1197
+ return String(value);
1198
+ }
1199
+ }
1200
+ exports.format = format;
1008
1201
  class DdbVoid extends DdbObj {
1009
1202
  constructor() {
1010
1203
  super({
@@ -1315,14 +1508,48 @@ class DdbTable extends DdbObj {
1315
1508
  }
1316
1509
  exports.DdbTable = DdbTable;
1317
1510
  function date2str(date, format = 'YYYY.MM.DD') {
1318
- return date === exports.nulls.int32 ?
1511
+ return (date === null || date === exports.nulls.int32) ?
1319
1512
  ''
1320
1513
  :
1321
1514
  (0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * 24 * date).format(format);
1322
1515
  }
1323
1516
  exports.date2str = date2str;
1517
+ function month2str(month) {
1518
+ if (month === null || month === exports.nulls.int32)
1519
+ return '';
1520
+ if (month < 0)
1521
+ return String(month);
1522
+ let _month = month % 12;
1523
+ let year = Math.floor(month / 12);
1524
+ return `${String(year).padStart(4, '0')}.${String(_month + 1).padStart(2, '0')}`;
1525
+ }
1526
+ exports.month2str = month2str;
1527
+ function time2str(time, format = 'HH:mm:ss.SSS') {
1528
+ return (time === null || time === exports.nulls.int32) ?
1529
+ ''
1530
+ :
1531
+ (0, dayjs_1.default)(exports.timezone_offset + time)
1532
+ .format(format);
1533
+ }
1534
+ exports.time2str = time2str;
1535
+ function minute2str(minute, format = 'HH:mm') {
1536
+ return (minute === null || minute === exports.nulls.int32) ?
1537
+ ''
1538
+ :
1539
+ (0, dayjs_1.default)(exports.timezone_offset + 60 * 1000 * minute)
1540
+ .format(format);
1541
+ }
1542
+ exports.minute2str = minute2str;
1543
+ function second2str(second, format = 'HH:mm:ss') {
1544
+ return (second === null || second === exports.nulls.int32) ?
1545
+ ''
1546
+ :
1547
+ (0, dayjs_1.default)(exports.timezone_offset + 1000 * second)
1548
+ .format(format);
1549
+ }
1550
+ exports.second2str = second2str;
1324
1551
  function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
1325
- return datetime === exports.nulls.int32 ?
1552
+ return (datetime === null || datetime === exports.nulls.int32) ?
1326
1553
  ''
1327
1554
  :
1328
1555
  (0, dayjs_1.default)(exports.timezone_offset + 1000 * datetime).format(format);
@@ -1335,12 +1562,19 @@ exports.datetime2str = datetime2str;
1335
1562
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1336
1563
  */
1337
1564
  function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1338
- return timestamp === exports.nulls.int64 ?
1565
+ return (timestamp === null || timestamp === exports.nulls.int64) ?
1339
1566
  ''
1340
1567
  :
1341
1568
  (0, dayjs_1.default)(exports.timezone_offset + Number(timestamp)).format(format);
1342
1569
  }
1343
1570
  exports.timestamp2str = timestamp2str;
1571
+ function datehour2str(datehour, format = 'YYYY.MM.DD.HH') {
1572
+ return (datehour === null || datehour === exports.nulls.int32) ?
1573
+ ''
1574
+ :
1575
+ (0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * datehour).format(format);
1576
+ }
1577
+ exports.datehour2str = datehour2str;
1344
1578
  /** parse timestamp string to bigint value
1345
1579
  - str: timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
1346
1580
  - format?:
@@ -1356,6 +1590,19 @@ function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1356
1590
  (0, dayjs_1.default)(str, format).valueOf());
1357
1591
  }
1358
1592
  exports.str2timestamp = str2timestamp;
1593
+ function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
1594
+ const i_second_start = format.indexOf('ss');
1595
+ if (i_second_start === -1)
1596
+ throw new Error('格式串必须包含秒的格式 (ss)');
1597
+ const i_second_end = i_second_start + 2;
1598
+ const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
1599
+ if (i_nanosecond_start === -1)
1600
+ throw new Error('格式串必须包含纳秒的格式 (SSSSSSSSS)');
1601
+ return ((0, dayjs_1.default)(exports.timezone_offset + (Number(nanotime) / 1000000)).format(format.slice(0, i_second_end)) +
1602
+ format.slice(i_second_end, i_nanosecond_start) +
1603
+ String(nanotime % 1000000000n).padStart(9, '0'));
1604
+ }
1605
+ exports.nanotime2str = nanotime2str;
1359
1606
  /** format nanotimestamp value (bigint) to string
1360
1607
  - nanotimestamp: bigint value
1361
1608
  - format?:
@@ -1364,7 +1611,7 @@ exports.str2timestamp = str2timestamp;
1364
1611
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1365
1612
  */
1366
1613
  function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1367
- if (nanotimestamp === exports.nulls.int64)
1614
+ if (nanotimestamp === null || nanotimestamp === exports.nulls.int64)
1368
1615
  return '';
1369
1616
  const i_second_start = format.indexOf('ss');
1370
1617
  if (i_second_start === -1)
@@ -1375,7 +1622,7 @@ function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSS
1375
1622
  throw new Error('The format string must contain the format for nanoseconds (SSSSSSSSS)');
1376
1623
  return ((0, dayjs_1.default)(exports.timezone_offset + (Number(nanotimestamp) / 1000000)).format(format.slice(0, i_second_end)) +
1377
1624
  format.slice(i_second_end, i_nanosecond_start) +
1378
- String(nanotimestamp % 1000000000n));
1625
+ String(nanotimestamp % 1000000000n).padStart(9, '0'));
1379
1626
  }
1380
1627
  exports.nanotimestamp2str = nanotimestamp2str;
1381
1628
  /** parse nano timestamp string to bigint value
@@ -1403,6 +1650,31 @@ function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1403
1650
  BigInt(str.slice(i_nanosecond_start, i_nanosecond_start + 9)));
1404
1651
  }
1405
1652
  exports.str2nanotimestamp = str2nanotimestamp;
1653
+ function ipaddr2str(buffer, le = true) {
1654
+ let buf = buffer;
1655
+ if (le)
1656
+ buf = buffer.slice().reverse();
1657
+ const i_non_zero = buf.findIndex(x => x);
1658
+ if (i_non_zero !== -1 && i_non_zero < 12) // ipv6 (i_non_zero === -1 或 0 < i_non_zero < 12)
1659
+ return [...buf].map(x => x.toString(16)
1660
+ .padStart(2, '0')).join(':');
1661
+ else // ipv4
1662
+ return buf.subarray(12).join('.');
1663
+ }
1664
+ exports.ipaddr2str = ipaddr2str;
1665
+ function uuid2str(buffer, le = true) {
1666
+ const str = int1282str(buffer, le);
1667
+ return `${str.slice(0, 8)}-${str.slice(8, 12)}-${str.slice(12, 16)}-${str.slice(16, 20)}-${str.slice(20)}`;
1668
+ }
1669
+ exports.uuid2str = uuid2str;
1670
+ function int1282str(buffer, le = true) {
1671
+ let buf = buffer;
1672
+ if (le)
1673
+ buf = buffer.slice().reverse();
1674
+ return [...buf].map(x => x.toString(16)
1675
+ .padStart(2, '0')).join('');
1676
+ }
1677
+ exports.int1282str = int1282str;
1406
1678
  class DDB {
1407
1679
  /**
1408
1680
  Initialize an instance of DolphinDB Client using the WebSocket URL
@@ -1809,5 +2081,4 @@ exports.DDB = DDB;
1809
2081
  /** little endian (client) */
1810
2082
  DDB.le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
1811
2083
  exports.ddb = window.ddb = new DDB();
1812
- exports.default = exports.ddb;
1813
2084
  //# sourceMappingURL=browser.js.map