dolphindb 2.0.514 → 2.0.517

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/README.md CHANGED
@@ -128,12 +128,12 @@ class DdbObj <T extends DdbValue = DdbValue> {
128
128
  /** 2nd dimension */
129
129
  cols?: number
130
130
 
131
- /** the type of the value in matrix (only matrix has this field) */
132
- datatype?: DdbType
133
-
134
131
  /** the actual data. Different DdbForm, DdbType use different types in DdbValue to represent actual data */
135
132
  value: T
136
133
 
134
+ /** raw binary data, only top-level objects generated by parse_message when parse_object is false have this attribute */
135
+ buffer?: Uint8Array
136
+
137
137
  constructor (data: Partial<DdbObj> & { form: DdbForm, type: DdbType, length: number }) {
138
138
  Object.assign(this, data)
139
139
  }
package/README.zh.md CHANGED
@@ -129,12 +129,12 @@ class DdbObj <T extends DdbValue = DdbValue> {
129
129
  /** 第 2 维 */
130
130
  cols?: number
131
131
 
132
- /** matrix 中值的类型,仅 matrix 才有 */
133
- datatype?: DdbType
134
-
135
132
  /** 实际数据。不同的 DdbForm, DdbType 使用 DdbValue 中不同的类型来表示实际数据 */
136
133
  value: T
137
134
 
135
+ /** 原始二进制数据,仅在 parse_object 为 false 时通过 parse_message 生成的顶层对象有这个属性 */
136
+ buffer?: Uint8Array
137
+
138
138
  constructor (data: Partial<DdbObj> & { form: DdbForm, type: DdbType, length: number }) {
139
139
  Object.assign(this, data)
140
140
  }
package/browser.d.ts CHANGED
@@ -265,7 +265,7 @@ export declare function datetime2str(datetime: number, format?: string): string;
265
265
  export declare function timestamp2str(timestamp: bigint, format?: string): string;
266
266
  export declare function datehour2str(datehour: number, format?: string): string;
267
267
  /** parse timestamp string to bigint value
268
- - 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)
269
269
  - format?:
270
270
  The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
271
271
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
@@ -281,14 +281,14 @@ export declare function nanotime2str(nanotime: bigint, format?: string): string;
281
281
  */
282
282
  export declare function nanotimestamp2str(nanotimestamp: bigint, format?: string): string;
283
283
  /** parse nano timestamp string to bigint value
284
- - 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)
285
285
  - format?:
286
286
  The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
287
287
  Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
288
288
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
289
289
  */
290
290
  export declare function str2nanotimestamp(str: string, format?: string): bigint;
291
- export declare function ipaddr2str(buffer: Uint8Array, le?: boolean): string;
291
+ export declare function ipaddr2str(buffer: Uint8Array, le?: boolean, ipv6?: boolean): string;
292
292
  export declare function uuid2str(buffer: Uint8Array, le?: boolean): string;
293
293
  export declare function int1282str(buffer: Uint8Array, le?: boolean): string;
294
294
  export declare class DDB {
package/browser.js CHANGED
@@ -5,6 +5,8 @@ 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"));
7
7
  dayjs_1.default.extend(customParseFormat_js_1.default);
8
+ const ipaddr_js_1 = tslib_1.__importDefault(require("ipaddr.js"));
9
+ const { fromByteArray: buf2ipaddr } = ipaddr_js_1.default;
8
10
  require("xshell/prototype.browser");
9
11
  const utils_browser_1 = require("xshell/utils.browser");
10
12
  const net_browser_js_1 = require("xshell/net.browser.js");
@@ -913,7 +915,7 @@ class DdbObj {
913
915
  case DdbForm.dict:
914
916
  return `dict<${DdbType[this.value[0].type]}, ${DdbType[this.value[1].type]}>`;
915
917
  case DdbForm.matrix:
916
- return `matrix<${DdbType[this.type]}>[${this.rows}r][${this.cols}c]`;
918
+ return `matrix<${tname}>[${this.rows}r][${this.cols}c]`;
917
919
  default:
918
920
  return `${DdbForm[this.form]} ${tname}`;
919
921
  }
@@ -1088,7 +1090,12 @@ function format(type, value, le) {
1088
1090
  return String((value === null || value === exports.nulls.int8) ?
1089
1091
  null
1090
1092
  :
1091
- value);
1093
+ // ascii printable
1094
+ // http://facweb.cs.depaul.edu/sjost/it212/documents/ascii-pr.htm
1095
+ (32 <= value && value <= 126) ?
1096
+ String.fromCharCode(value).quote()
1097
+ :
1098
+ value);
1092
1099
  case DdbType.short:
1093
1100
  return String((value === null || value === exports.nulls.int16) ?
1094
1101
  null
@@ -1179,8 +1186,10 @@ function format(type, value, le) {
1179
1186
  case DdbType.int128:
1180
1187
  return int1282str(value, le);
1181
1188
  case DdbType.blob:
1182
- return DdbObj.dec.decode(value.subarray(0, 1000)).quote('single');
1183
- case DdbType.complex:
1189
+ return (value.length > 100 ?
1190
+ DdbObj.dec.decode(value.subarray(0, 98)) + '…'
1191
+ :
1192
+ DdbObj.dec.decode(value)).quote('single');
1184
1193
  case DdbType.point: {
1185
1194
  let [x, y] = value;
1186
1195
  if (x === exports.nulls.double)
@@ -1189,6 +1198,14 @@ function format(type, value, le) {
1189
1198
  y = null;
1190
1199
  return `(${String(x)}, ${String(y)})`;
1191
1200
  }
1201
+ case DdbType.complex: {
1202
+ let [x, y] = value;
1203
+ if (x === exports.nulls.double)
1204
+ x = null;
1205
+ if (y === exports.nulls.double)
1206
+ y = null;
1207
+ return `${String(x)}+${String(y)}i`;
1208
+ }
1192
1209
  case DdbType.duration: {
1193
1210
  const { data, unit } = value;
1194
1211
  return `${data}${DdbDurationUnit[unit]}`;
@@ -1509,32 +1526,32 @@ class DdbTable extends DdbObj {
1509
1526
  exports.DdbTable = DdbTable;
1510
1527
  function date2str(date, format = 'YYYY.MM.DD') {
1511
1528
  return (date === null || date === exports.nulls.int32) ?
1512
- ''
1529
+ 'null'
1513
1530
  :
1514
1531
  (0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * 24 * date).format(format);
1515
1532
  }
1516
1533
  exports.date2str = date2str;
1517
1534
  function month2str(month) {
1518
1535
  if (month === null || month === exports.nulls.int32)
1519
- return '';
1536
+ return 'null';
1520
1537
  if (month < 0)
1521
1538
  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')}`;
1539
+ const _month = month % 12;
1540
+ const year = Math.trunc(month / 12);
1541
+ return `${String(year).padStart(4, '0')}.${String(_month + 1).padStart(2, '0')}M`;
1525
1542
  }
1526
1543
  exports.month2str = month2str;
1527
1544
  function time2str(time, format = 'HH:mm:ss.SSS') {
1528
1545
  return (time === null || time === exports.nulls.int32) ?
1529
- ''
1546
+ 'null'
1530
1547
  :
1531
1548
  (0, dayjs_1.default)(exports.timezone_offset + time)
1532
1549
  .format(format);
1533
1550
  }
1534
1551
  exports.time2str = time2str;
1535
- function minute2str(minute, format = 'HH:mm') {
1552
+ function minute2str(minute, format = 'HH:mm[m]') {
1536
1553
  return (minute === null || minute === exports.nulls.int32) ?
1537
- ''
1554
+ 'null'
1538
1555
  :
1539
1556
  (0, dayjs_1.default)(exports.timezone_offset + 60 * 1000 * minute)
1540
1557
  .format(format);
@@ -1542,7 +1559,7 @@ function minute2str(minute, format = 'HH:mm') {
1542
1559
  exports.minute2str = minute2str;
1543
1560
  function second2str(second, format = 'HH:mm:ss') {
1544
1561
  return (second === null || second === exports.nulls.int32) ?
1545
- ''
1562
+ 'null'
1546
1563
  :
1547
1564
  (0, dayjs_1.default)(exports.timezone_offset + 1000 * second)
1548
1565
  .format(format);
@@ -1550,7 +1567,7 @@ function second2str(second, format = 'HH:mm:ss') {
1550
1567
  exports.second2str = second2str;
1551
1568
  function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
1552
1569
  return (datetime === null || datetime === exports.nulls.int32) ?
1553
- ''
1570
+ 'null'
1554
1571
  :
1555
1572
  (0, dayjs_1.default)(exports.timezone_offset + 1000 * datetime).format(format);
1556
1573
  }
@@ -1563,26 +1580,26 @@ exports.datetime2str = datetime2str;
1563
1580
  */
1564
1581
  function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1565
1582
  return (timestamp === null || timestamp === exports.nulls.int64) ?
1566
- ''
1583
+ 'null'
1567
1584
  :
1568
1585
  (0, dayjs_1.default)(exports.timezone_offset + Number(timestamp)).format(format);
1569
1586
  }
1570
1587
  exports.timestamp2str = timestamp2str;
1571
- function datehour2str(datehour, format = 'YYYY.MM.DD.HH') {
1588
+ function datehour2str(datehour, format = 'YYYY.MM.DDTHH') {
1572
1589
  return (datehour === null || datehour === exports.nulls.int32) ?
1573
- ''
1590
+ 'null'
1574
1591
  :
1575
1592
  (0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * datehour).format(format);
1576
1593
  }
1577
1594
  exports.datehour2str = datehour2str;
1578
1595
  /** parse timestamp string to bigint value
1579
- - str: timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
1596
+ - str: timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
1580
1597
  - format?:
1581
1598
  The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
1582
1599
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1583
1600
  */
1584
1601
  function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1585
- if (!str)
1602
+ if (!str || str === 'null')
1586
1603
  return exports.nulls.int64;
1587
1604
  if (str.length !== format.length)
1588
1605
  throw new Error('The length of the timestamp string is not equal to the length of the format string');
@@ -1591,6 +1608,10 @@ function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1591
1608
  }
1592
1609
  exports.str2timestamp = str2timestamp;
1593
1610
  function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
1611
+ if (nanotime === null || nanotime === exports.nulls.int64)
1612
+ return 'null';
1613
+ if (nanotime < 0n)
1614
+ return String(nanotime);
1594
1615
  const i_second_start = format.indexOf('ss');
1595
1616
  if (i_second_start === -1)
1596
1617
  throw new Error('格式串必须包含秒的格式 (ss)');
@@ -1611,8 +1632,14 @@ exports.nanotime2str = nanotime2str;
1611
1632
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1612
1633
  */
1613
1634
  function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1635
+ // tests:
1636
+ // nanotimestamp2str(0n)
1637
+ // nanotimestamp2str(-1n)
1638
+ // nanotimestamp2str(-9_9999_9999n)
1639
+ // nanotimestamp2str(-10_0000_0000n)
1640
+ // nanotimestamp2str(-10_0000_0001n)
1614
1641
  if (nanotimestamp === null || nanotimestamp === exports.nulls.int64)
1615
- return '';
1642
+ return 'null';
1616
1643
  const i_second_start = format.indexOf('ss');
1617
1644
  if (i_second_start === -1)
1618
1645
  throw new Error('The format string must contain the format for seconds (ss)');
@@ -1620,20 +1647,27 @@ function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSS
1620
1647
  const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
1621
1648
  if (i_nanosecond_start === -1)
1622
1649
  throw new Error('The format string must contain the format for nanoseconds (SSSSSSSSS)');
1623
- return ((0, dayjs_1.default)(exports.timezone_offset + (Number(nanotimestamp) / 1000000)).format(format.slice(0, i_second_end)) +
1650
+ const remainder = nanotimestamp % 1000000000n;
1651
+ const borrow = remainder < 0n;
1652
+ return ((0, dayjs_1.default)(exports.timezone_offset +
1653
+ // 去掉 9 位的纳秒部分,转化为毫秒
1654
+ Number((nanotimestamp - remainder + (borrow ? -1000000000n : 0n)) / 1000000n)).format(format.slice(0, i_second_end)) +
1624
1655
  format.slice(i_second_end, i_nanosecond_start) +
1625
- String(nanotimestamp % 1000000000n).padStart(9, '0'));
1656
+ String(borrow ?
1657
+ (remainder + 1000000000n) % 1000000000n
1658
+ :
1659
+ remainder).padStart(9, '0'));
1626
1660
  }
1627
1661
  exports.nanotimestamp2str = nanotimestamp2str;
1628
1662
  /** parse nano timestamp string to bigint value
1629
- - str: nano timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
1663
+ - str: nano timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
1630
1664
  - format?:
1631
1665
  The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
1632
1666
  Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
1633
1667
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1634
1668
  */
1635
1669
  function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1636
- if (!str)
1670
+ if (!str || str === 'null')
1637
1671
  return exports.nulls.int64;
1638
1672
  if (str.length !== format.length)
1639
1673
  throw new Error('nanotimestamp string length is not equal to format string length');
@@ -1650,14 +1684,14 @@ function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1650
1684
  BigInt(str.slice(i_nanosecond_start, i_nanosecond_start + 9)));
1651
1685
  }
1652
1686
  exports.str2nanotimestamp = str2nanotimestamp;
1653
- function ipaddr2str(buffer, le = true) {
1687
+ function ipaddr2str(buffer, le = true, ipv6) {
1654
1688
  let buf = buffer;
1655
1689
  if (le)
1656
1690
  buf = buffer.slice().reverse();
1657
1691
  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(':');
1692
+ if (ipv6 ||
1693
+ i_non_zero !== -1 && i_non_zero < 12) // ipv6
1694
+ return buf2ipaddr([...buf]).toString();
1661
1695
  else // ipv4
1662
1696
  return buf.subarray(12).join('.');
1663
1697
  }