dolphindb 2.0.513 → 2.0.516

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>;
@@ -261,7 +265,7 @@ export declare function datetime2str(datetime: number, format?: string): string;
261
265
  export declare function timestamp2str(timestamp: bigint, format?: string): string;
262
266
  export declare function datehour2str(datehour: number, format?: string): string;
263
267
  /** parse timestamp string to bigint value
264
- - 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)
265
269
  - format?:
266
270
  The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
267
271
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
@@ -277,7 +281,7 @@ export declare function nanotime2str(nanotime: bigint, format?: string): string;
277
281
  */
278
282
  export declare function nanotimestamp2str(nanotimestamp: bigint, format?: string): string;
279
283
  /** parse nano timestamp string to bigint value
280
- - 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)
281
285
  - format?:
282
286
  The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
283
287
  Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
@@ -473,4 +477,3 @@ export interface DdbErrorMessage {
473
477
  }
474
478
  export declare type DdbMessage = DdbPrintMessage | DdbObjectMessage | DdbErrorMessage;
475
479
  export declare let ddb: DDB;
476
- export default ddb;
package/browser.js CHANGED
@@ -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;
@@ -909,7 +913,7 @@ class DdbObj {
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}r][${this.cols}c]`;
916
+ return `matrix<${tname}>[${this.rows}r][${this.cols}c]`;
913
917
  default:
914
918
  return `${DdbForm[this.form]} ${tname}`;
915
919
  }
@@ -929,6 +933,34 @@ class DdbObj {
929
933
  :
930
934
  str_items.bracket('square');
931
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
+ }
932
964
  switch (this.type) {
933
965
  case DdbType.symbol_extended: {
934
966
  const limit = 50;
@@ -1147,8 +1179,10 @@ function format(type, value, le) {
1147
1179
  case DdbType.int128:
1148
1180
  return int1282str(value, le);
1149
1181
  case DdbType.blob:
1150
- return DdbObj.dec.decode(value.subarray(0, 1000)).quote('single');
1151
- case DdbType.complex:
1182
+ return (value.length > 100 ?
1183
+ DdbObj.dec.decode(value.subarray(0, 98)) + '…'
1184
+ :
1185
+ DdbObj.dec.decode(value)).quote('single');
1152
1186
  case DdbType.point: {
1153
1187
  let [x, y] = value;
1154
1188
  if (x === exports.nulls.double)
@@ -1157,6 +1191,14 @@ function format(type, value, le) {
1157
1191
  y = null;
1158
1192
  return `(${String(x)}, ${String(y)})`;
1159
1193
  }
1194
+ case DdbType.complex: {
1195
+ let [x, y] = value;
1196
+ if (x === exports.nulls.double)
1197
+ x = null;
1198
+ if (y === exports.nulls.double)
1199
+ y = null;
1200
+ return `${String(x)}+${String(y)}i`;
1201
+ }
1160
1202
  case DdbType.duration: {
1161
1203
  const { data, unit } = value;
1162
1204
  return `${data}${DdbDurationUnit[unit]}`;
@@ -1477,32 +1519,32 @@ class DdbTable extends DdbObj {
1477
1519
  exports.DdbTable = DdbTable;
1478
1520
  function date2str(date, format = 'YYYY.MM.DD') {
1479
1521
  return (date === null || date === exports.nulls.int32) ?
1480
- ''
1522
+ 'null'
1481
1523
  :
1482
1524
  (0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * 24 * date).format(format);
1483
1525
  }
1484
1526
  exports.date2str = date2str;
1485
1527
  function month2str(month) {
1486
1528
  if (month === null || month === exports.nulls.int32)
1487
- return '';
1529
+ return 'null';
1488
1530
  if (month < 0)
1489
1531
  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')}`;
1532
+ const _month = month % 12;
1533
+ const year = Math.trunc(month / 12);
1534
+ return `${String(year).padStart(4, '0')}.${String(_month + 1).padStart(2, '0')}M`;
1493
1535
  }
1494
1536
  exports.month2str = month2str;
1495
1537
  function time2str(time, format = 'HH:mm:ss.SSS') {
1496
1538
  return (time === null || time === exports.nulls.int32) ?
1497
- ''
1539
+ 'null'
1498
1540
  :
1499
1541
  (0, dayjs_1.default)(exports.timezone_offset + time)
1500
1542
  .format(format);
1501
1543
  }
1502
1544
  exports.time2str = time2str;
1503
- function minute2str(minute, format = 'HH:mm') {
1545
+ function minute2str(minute, format = 'HH:mm[m]') {
1504
1546
  return (minute === null || minute === exports.nulls.int32) ?
1505
- ''
1547
+ 'null'
1506
1548
  :
1507
1549
  (0, dayjs_1.default)(exports.timezone_offset + 60 * 1000 * minute)
1508
1550
  .format(format);
@@ -1510,7 +1552,7 @@ function minute2str(minute, format = 'HH:mm') {
1510
1552
  exports.minute2str = minute2str;
1511
1553
  function second2str(second, format = 'HH:mm:ss') {
1512
1554
  return (second === null || second === exports.nulls.int32) ?
1513
- ''
1555
+ 'null'
1514
1556
  :
1515
1557
  (0, dayjs_1.default)(exports.timezone_offset + 1000 * second)
1516
1558
  .format(format);
@@ -1518,7 +1560,7 @@ function second2str(second, format = 'HH:mm:ss') {
1518
1560
  exports.second2str = second2str;
1519
1561
  function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
1520
1562
  return (datetime === null || datetime === exports.nulls.int32) ?
1521
- ''
1563
+ 'null'
1522
1564
  :
1523
1565
  (0, dayjs_1.default)(exports.timezone_offset + 1000 * datetime).format(format);
1524
1566
  }
@@ -1531,26 +1573,26 @@ exports.datetime2str = datetime2str;
1531
1573
  */
1532
1574
  function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1533
1575
  return (timestamp === null || timestamp === exports.nulls.int64) ?
1534
- ''
1576
+ 'null'
1535
1577
  :
1536
1578
  (0, dayjs_1.default)(exports.timezone_offset + Number(timestamp)).format(format);
1537
1579
  }
1538
1580
  exports.timestamp2str = timestamp2str;
1539
- function datehour2str(datehour, format = 'YYYY.MM.DD.HH') {
1581
+ function datehour2str(datehour, format = 'YYYY.MM.DDTHH') {
1540
1582
  return (datehour === null || datehour === exports.nulls.int32) ?
1541
- ''
1583
+ 'null'
1542
1584
  :
1543
1585
  (0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * datehour).format(format);
1544
1586
  }
1545
1587
  exports.datehour2str = datehour2str;
1546
1588
  /** parse timestamp string to bigint value
1547
- - str: timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
1589
+ - str: timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
1548
1590
  - format?:
1549
1591
  The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
1550
1592
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1551
1593
  */
1552
1594
  function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1553
- if (!str)
1595
+ if (!str || str === 'null')
1554
1596
  return exports.nulls.int64;
1555
1597
  if (str.length !== format.length)
1556
1598
  throw new Error('The length of the timestamp string is not equal to the length of the format string');
@@ -1559,6 +1601,10 @@ function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1559
1601
  }
1560
1602
  exports.str2timestamp = str2timestamp;
1561
1603
  function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
1604
+ if (nanotime === null || nanotime === exports.nulls.int64)
1605
+ return 'null';
1606
+ if (nanotime < 0n)
1607
+ return String(nanotime);
1562
1608
  const i_second_start = format.indexOf('ss');
1563
1609
  if (i_second_start === -1)
1564
1610
  throw new Error('格式串必须包含秒的格式 (ss)');
@@ -1579,8 +1625,14 @@ exports.nanotime2str = nanotime2str;
1579
1625
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1580
1626
  */
1581
1627
  function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1628
+ // tests:
1629
+ // nanotimestamp2str(0n)
1630
+ // nanotimestamp2str(-1n)
1631
+ // nanotimestamp2str(-9_9999_9999n)
1632
+ // nanotimestamp2str(-10_0000_0000n)
1633
+ // nanotimestamp2str(-10_0000_0001n)
1582
1634
  if (nanotimestamp === null || nanotimestamp === exports.nulls.int64)
1583
- return '';
1635
+ return 'null';
1584
1636
  const i_second_start = format.indexOf('ss');
1585
1637
  if (i_second_start === -1)
1586
1638
  throw new Error('The format string must contain the format for seconds (ss)');
@@ -1588,20 +1640,27 @@ function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSS
1588
1640
  const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
1589
1641
  if (i_nanosecond_start === -1)
1590
1642
  throw new Error('The format string must contain the format for nanoseconds (SSSSSSSSS)');
1591
- return ((0, dayjs_1.default)(exports.timezone_offset + (Number(nanotimestamp) / 1000000)).format(format.slice(0, i_second_end)) +
1643
+ const remainder = nanotimestamp % 1000000000n;
1644
+ const borrow = remainder < 0n;
1645
+ return ((0, dayjs_1.default)(exports.timezone_offset +
1646
+ // 去掉 9 位的纳秒部分,转化为毫秒
1647
+ Number((nanotimestamp - remainder + (borrow ? -1000000000n : 0n)) / 1000000n)).format(format.slice(0, i_second_end)) +
1592
1648
  format.slice(i_second_end, i_nanosecond_start) +
1593
- String(nanotimestamp % 1000000000n).padStart(9, '0'));
1649
+ String(borrow ?
1650
+ (remainder + 1000000000n) % 1000000000n
1651
+ :
1652
+ remainder).padStart(9, '0'));
1594
1653
  }
1595
1654
  exports.nanotimestamp2str = nanotimestamp2str;
1596
1655
  /** parse nano timestamp string to bigint value
1597
- - str: nano timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
1656
+ - str: nano timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
1598
1657
  - format?:
1599
1658
  The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
1600
1659
  Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
1601
1660
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1602
1661
  */
1603
1662
  function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1604
- if (!str)
1663
+ if (!str || str === 'null')
1605
1664
  return exports.nulls.int64;
1606
1665
  if (str.length !== format.length)
1607
1666
  throw new Error('nanotimestamp string length is not equal to format string length');
@@ -2049,5 +2108,4 @@ exports.DDB = DDB;
2049
2108
  /** little endian (client) */
2050
2109
  DDB.le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
2051
2110
  exports.ddb = window.ddb = new DDB();
2052
- exports.default = exports.ddb;
2053
2111
  //# sourceMappingURL=browser.js.map