dolphindb 2.0.904 → 2.0.906

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
@@ -386,7 +386,8 @@ export declare function datehour2str(datehour: number | null, format?: string):
386
386
  - str: timestamp string, 如果为空字符串或 'null' 会返回对应的空值 (nulls.int64)
387
387
  timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
388
388
  - format?:
389
- 对应传入字符串的格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSS` The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
389
+ 对应传入字符串的格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSS`
390
+ The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
390
391
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
391
392
  */
392
393
  export declare function str2timestamp(str: string, format?: string): bigint;
@@ -443,7 +444,8 @@ export interface StreamingData extends StreamingParams {
443
444
  /** 每次接收到的 data 组成的数组 An array of data received each time */
444
445
  segments: DdbObj<DdbVectorObj[]>[];
445
446
  };
446
- /** 成功订阅后,后续推送过来的 message 解析错误,则会设置 error 并调用 handler After successfully subscribed, if the subsequently pushed message is parsed incorrectly, the error will be set and the handler will be called. */
447
+ /** 成功订阅后,后续推送过来的 message 解析错误,则会设置 error 并调用 handler
448
+ After successfully subscribed, if the subsequently pushed message is parsed incorrectly, the error will be set and the handler will be called. */
447
449
  error?: Error;
448
450
  }
449
451
  export declare const winsize: 100000;
package/browser.js CHANGED
@@ -1080,7 +1080,7 @@ export class DdbObj {
1080
1080
  // append!(av, [1..500])
1081
1081
  // ...
1082
1082
  // av
1083
- const _type = this.type - 64;
1083
+ const type_ = this.type - 64;
1084
1084
  const limit = 10;
1085
1085
  let items = new Array(Math.min(limit, this.rows));
1086
1086
  let i_items = 0;
@@ -1089,18 +1089,28 @@ export class DdbObj {
1089
1089
  for (const length of lengths) {
1090
1090
  let _items = new Array(Math.min(limit, length));
1091
1091
  for (let i = 0; i < _items.length; i++)
1092
- if (_type === DdbType.decimal32 || _type === DdbType.decimal64) {
1093
- const x = data[acc_len + i];
1094
- if (x === nulls.int64 && _type === DdbType.decimal64 ||
1095
- x === nulls.int32 && _type === DdbType.decimal32)
1096
- return '';
1097
- const { scale } = this.value;
1098
- const s = String(x < 0 ? -x : x).padStart(scale, '0');
1099
- const str = (x < 0 ? '-' : '') + (scale ? `${s.slice(0, -scale) || '0'}.${s.slice(-scale)}` : s);
1100
- _items[i] = options.colors ? green(str) : str;
1092
+ switch (type_) {
1093
+ case DdbType.decimal32:
1094
+ case DdbType.decimal64:
1095
+ const x = data[acc_len + i];
1096
+ if (x === nulls.int64 /* && type_ === DdbType.decimal64 一定成立 */ ||
1097
+ x === nulls.int32 && type_ === DdbType.decimal32)
1098
+ return '';
1099
+ const { scale } = this.value;
1100
+ const s = String(x < 0 ? -x : x).padStart(scale, '0');
1101
+ const str = (x < 0 ? '-' : '') + (scale ? `${s.slice(0, -scale) || '0'}.${s.slice(-scale)}` : s);
1102
+ _items[i] = options.colors ? green(str) : str;
1103
+ break;
1104
+ case DdbType.complex:
1105
+ case DdbType.point: {
1106
+ const index = acc_len + i;
1107
+ _items[i] = format(type_, data.subarray(2 * index, 2 * (index + 1)), this.le, options);
1108
+ break;
1109
+ }
1110
+ default:
1111
+ _items[i] = format(type_, data[acc_len + i], this.le, options);
1112
+ break;
1101
1113
  }
1102
- else
1103
- _items[i] = format(_type, data[acc_len + i], this.le, options);
1104
1114
  items[i_items++] = format_array(_items, length > limit);
1105
1115
  acc_len += length;
1106
1116
  }
@@ -1493,7 +1503,7 @@ export function formati(obj, index, options = {}) {
1493
1503
  // append!(av, [1..500])
1494
1504
  // ...
1495
1505
  // av
1496
- const _type = obj.type - 64;
1506
+ const type_ = obj.type - 64;
1497
1507
  let offset = 0;
1498
1508
  for (const { lengths, data, rows } of obj.value) {
1499
1509
  let acc_len = 0;
@@ -1510,18 +1520,28 @@ export function formati(obj, index, options = {}) {
1510
1520
  const limit = 10;
1511
1521
  let items = new Array(Math.min(limit, length));
1512
1522
  for (let i = 0; i < items.length; i++)
1513
- if (_type === DdbType.decimal32 || _type === DdbType.decimal64) {
1514
- const x = data[acc_len + i];
1515
- if (x === nulls.int64 && _type === DdbType.decimal64 ||
1516
- x === nulls.int32 && _type === DdbType.decimal32)
1517
- return '';
1518
- const { scale } = obj.value;
1519
- const s = String(x < 0 ? -x : x).padStart(scale, '0');
1520
- const str = (x < 0 ? '-' : '') + (scale ? `${s.slice(0, -scale) || '0'}.${s.slice(-scale)}` : s);
1521
- items[i] = options.colors ? green(str) : str;
1523
+ switch (type_) {
1524
+ case DdbType.decimal32:
1525
+ case DdbType.decimal64:
1526
+ const x = data[acc_len + i];
1527
+ if (x === nulls.int64 /* && type_ === DdbType.decimal64 一定成立 */ ||
1528
+ x === nulls.int32 && type_ === DdbType.decimal32)
1529
+ return '';
1530
+ const { scale } = obj.value;
1531
+ const s = String(x < 0 ? -x : x).padStart(scale, '0');
1532
+ const str = (x < 0 ? '-' : '') + (scale ? `${s.slice(0, -scale) || '0'}.${s.slice(-scale)}` : s);
1533
+ items[i] = options.colors ? green(str) : str;
1534
+ break;
1535
+ case DdbType.complex:
1536
+ case DdbType.point: {
1537
+ const index = acc_len + i;
1538
+ items[i] = format(type_, data.subarray(2 * index, 2 * (index + 1)), obj.le, options);
1539
+ break;
1540
+ }
1541
+ default:
1542
+ items[i] = format(type_, data[acc_len + i], obj.le, options);
1543
+ break;
1522
1544
  }
1523
- else
1524
- items[i] = format(_type, data[acc_len + i], obj.le, options);
1525
1545
  return (items.join(', ') + (length > limit ? ', ...' : '')).bracket('square');
1526
1546
  }
1527
1547
  }
@@ -1861,15 +1881,14 @@ export function date2ms(date) {
1861
1881
  // 将 server 的本地时间 (以 ms 为单位,1970.01.01 00:00:00 作为零点) 当成是客户端这里的本地的时间,然后根据本地的时区信息转换为 utc 时间
1862
1882
  // 本地的时区与实际的时间值相关,timezone offset 可能会受到夏令时 (DST) 的影响
1863
1883
  // 得到的 utc 毫秒数交给 js date 或者 dayjs 去格式化
1884
+ if (date === null || date === nulls.int32)
1885
+ return null;
1864
1886
  const ms = 1000 * 3600 * 24 * date;
1865
- return (date === null || date === nulls.int32) ?
1866
- null
1867
- :
1868
- 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1887
+ return 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1869
1888
  }
1870
1889
  export function date2str(date, format = 'YYYY.MM.DD') {
1871
1890
  return (date === null || date === nulls.int32) ?
1872
- null
1891
+ 'null'
1873
1892
  :
1874
1893
  dayjs(date2ms(date)).format(format);
1875
1894
  }
@@ -1896,16 +1915,15 @@ export function time2ms(time) {
1896
1915
  }
1897
1916
  export function time2str(time, format = 'HH:mm:ss.SSS') {
1898
1917
  return (time === null || time === nulls.int32) ?
1899
- null
1918
+ 'null'
1900
1919
  :
1901
1920
  dayjs(time2ms(time)).format(format);
1902
1921
  }
1903
1922
  export function minute2ms(minute) {
1923
+ if (minute === null || minute === nulls.int32)
1924
+ return null;
1904
1925
  const ms = 60 * 1000 * minute;
1905
- return (minute === null || minute === nulls.int32) ?
1906
- null
1907
- :
1908
- 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1926
+ return 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1909
1927
  }
1910
1928
  export function minute2str(minute, format = 'HH:mm[m]') {
1911
1929
  return (minute === null || minute === nulls.int32) ?
@@ -1914,11 +1932,10 @@ export function minute2str(minute, format = 'HH:mm[m]') {
1914
1932
  dayjs(minute2ms(minute)).format(format);
1915
1933
  }
1916
1934
  export function second2ms(second) {
1935
+ if (second === null || second === nulls.int32)
1936
+ return null;
1917
1937
  const ms = 1000 * second;
1918
- return (second === null || second === nulls.int32) ?
1919
- null
1920
- :
1921
- 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1938
+ return 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1922
1939
  }
1923
1940
  export function second2str(second, format = 'HH:mm:ss') {
1924
1941
  return (second === null || second === nulls.int32) ?
@@ -1927,11 +1944,10 @@ export function second2str(second, format = 'HH:mm:ss') {
1927
1944
  dayjs(second2ms(second)).format(format);
1928
1945
  }
1929
1946
  export function datetime2ms(datetime) {
1947
+ if (datetime === null || datetime === nulls.int32)
1948
+ return null;
1930
1949
  const ms = 1000 * datetime;
1931
- return (datetime === null || datetime === nulls.int32) ?
1932
- null
1933
- :
1934
- 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1950
+ return 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1935
1951
  }
1936
1952
  export function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
1937
1953
  return (datetime === null || datetime === nulls.int32) ?
@@ -1940,11 +1956,10 @@ export function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
1940
1956
  dayjs(datetime2ms(datetime)).format(format);
1941
1957
  }
1942
1958
  export function timestamp2ms(timestamp) {
1959
+ if (timestamp === null || timestamp === nulls.int64)
1960
+ return null;
1943
1961
  const ms = Number(timestamp);
1944
- return (timestamp === null || timestamp === nulls.int64) ?
1945
- null
1946
- :
1947
- 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1962
+ return 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1948
1963
  }
1949
1964
  /** format timestamp (bigint) to string
1950
1965
  - timestamp: bigint value
@@ -1959,24 +1974,23 @@ export function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1959
1974
  dayjs(timestamp2ms(timestamp)).format(format);
1960
1975
  }
1961
1976
  export function datehour2ms(datehour) {
1977
+ if (datehour === null || datehour === nulls.int32)
1978
+ return null;
1962
1979
  const ms = 1000 * 3600 * datehour;
1963
- return (datehour === null || datehour === nulls.int32) ?
1964
- null
1965
- :
1966
- 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1980
+ return 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1967
1981
  }
1968
1982
  export function datehour2str(datehour, format = 'YYYY.MM.DDTHH') {
1983
+ if (datehour === null || datehour === nulls.int32)
1984
+ return 'null';
1969
1985
  const ms = 1000 * 3600 * datehour;
1970
- return (datehour === null || datehour === nulls.int32) ?
1971
- 'null'
1972
- :
1973
- dayjs(1000 * 60 * new Date(ms).getTimezoneOffset() + ms).format(format);
1986
+ return dayjs(1000 * 60 * new Date(ms).getTimezoneOffset() + ms).format(format);
1974
1987
  }
1975
1988
  /** parse timestamp string to bigint value
1976
1989
  - str: timestamp string, 如果为空字符串或 'null' 会返回对应的空值 (nulls.int64)
1977
1990
  timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
1978
1991
  - format?:
1979
- 对应传入字符串的格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSS` The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
1992
+ 对应传入字符串的格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSS`
1993
+ The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
1980
1994
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1981
1995
  */
1982
1996
  export function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
@@ -2006,11 +2020,10 @@ export function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
2006
2020
  String(nanotime % 1000000000n).padStart(9, '0'));
2007
2021
  }
2008
2022
  export function nanotimestamp2ns(nanotimestamp) {
2023
+ if (nanotimestamp === null || nanotimestamp === nulls.int64)
2024
+ return null;
2009
2025
  const ms = Number(nanotimestamp / 1000000n);
2010
- return (nanotimestamp === null || nanotimestamp === nulls.int64) ?
2011
- null
2012
- :
2013
- BigInt(1000 * 60 * new Date(ms).getTimezoneOffset()) * 1000000n + nanotimestamp;
2026
+ return BigInt(1000 * 60 * new Date(ms).getTimezoneOffset()) * 1000000n + nanotimestamp;
2014
2027
  }
2015
2028
  /** format nanotimestamp value (bigint) to string
2016
2029
  - nanotimestamp: bigint value
@@ -2499,11 +2512,15 @@ export class DDB {
2499
2512
  // MSG\n
2500
2513
  // <message>\0
2501
2514
  // 'M'.codePointAt(0).to_hex_str()
2502
- if (buf[0] === 0x4d && buf[1] === 0x53 && buf[2] === 0x47 && buf[3] === 0x0a)
2515
+ if (buf[0] === 0x4d && buf[1] === 0x53 && buf[2] === 0x47 && buf[3] === 0x0a) {
2516
+ assert(buf.at(-1) === 0, t('print 消息的 buffer 应该以 \\0 结束'));
2517
+ if (buf.indexOf(0) !== buf.length - 1)
2518
+ console.warn(t('print 消息的 buffer 中间不应该有 \\0'));
2503
2519
  return {
2504
2520
  type: 'print',
2505
- data: this.dec.decode(buf.subarray(4))
2521
+ data: this.dec.decode(buf.subarray(4, -1))
2506
2522
  };
2523
+ }
2507
2524
  // '1166953221 1 1\n'
2508
2525
  // 'OK\n'
2509
2526
  // '\x04\x00\x02\x00\x00\x00'