dolphindb 2.0.905 → 2.0.907

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/index.d.ts CHANGED
@@ -399,10 +399,11 @@ export declare function nanotimestamp2str(nanotimestamp: bigint | null, format?:
399
399
  - str: nano timestamp string, 如果为空字符串或 'null' 会返回对应的空值 (nulls.int64)
400
400
  nano timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
401
401
  - format?:
402
- 对应传入字符串的格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSSSSSSSS` The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
403
- 秒的格式为 ss (必须包含); 纳秒的格式为 SSSSSSSSS (必须包含) Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
402
+ 对应传入字符串的格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
403
+ 秒的格式为 ss (必须包含); 纳秒的格式为 SSSSSSSSS (必须包含)
404
404
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
405
- */
405
+ The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
406
+ Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included) */
406
407
  export declare function str2nanotimestamp(str: string, format?: string): bigint;
407
408
  export declare function ipaddr2str(buffer: Uint8Array, le?: boolean, ipv6?: boolean): string;
408
409
  export declare function uuid2str(buffer: Uint8Array, le?: boolean): string;
@@ -413,10 +414,8 @@ export interface StreamingParams {
413
414
  handler(message: StreamingData): any;
414
415
  }
415
416
  export interface StreamingData extends StreamingParams {
416
- /**
417
- server 发送消息的时间 (nano seconds since epoch) The time the server sent the message (nano seconds since epoch)
418
- std::chrono::system_clock::now().time_since_epoch() / std::chrono::nanoseconds(1)
419
- */
417
+ /** server 发送消息的时间 (nano seconds since epoch) The time the server sent the message (nano seconds since epoch)
418
+ std::chrono::system_clock::now().time_since_epoch() / std::chrono::nanoseconds(1) */
420
419
  time: bigint;
421
420
  /** message id */
422
421
  id: bigint;
@@ -462,11 +461,11 @@ export declare class DDB {
462
461
  le: boolean;
463
462
  /** little endian (client) */
464
463
  static le_client: boolean;
465
- /** 是否在建立连接后自动登录,默认 true */
464
+ /** 是否在建立连接后自动登录,默认 true Whether to automatically log in after the connection is established, the default is true */
466
465
  autologin: boolean;
467
- /** DolphinDB 登录用户名 */
466
+ /** DolphinDB 登录用户名 DolphinDB username */
468
467
  username: string;
469
- /** DolphinDB 登录密码 */
468
+ /** DolphinDB 登录密码 DolphinDB password */
470
469
  password: string;
471
470
  /** python session flag (2048) */
472
471
  python: boolean;
@@ -514,7 +513,7 @@ export declare class DDB {
514
513
  });
515
514
  private on_message;
516
515
  /** 建立实际的 WebSocket 连接到 URL 对应的 DolphinDB Establish a actual websocket connection to the DolphindB corresponding to the URL
517
- 是幂等的,调用后会确保已连接到数据库 (确保 websocket.readyState 为 open),否则报错 It is a power, and after calling, it will ensure that it has been connected to the database (ensure that websocket.ReadyState is open), otherwise an error will be reported
516
+ 是幂等的,调用后会确保已连接到数据库 (确保 websocket.readyState 为 open),否则报错 After calling, it will ensure that it has been connected to the database (ensure that websocket.ReadyState is open), otherwise an error will be reported
518
517
  this.autologin 为 true 时自动登录 this.autologin automatically log in when it is true */
519
518
  connect(): Promise<void>;
520
519
  get_rpc_options({ urgent, secondary, async: _async, pickle, clear, api, compress, cancellable, priority, parallelism, root_id, limit, }?: {
package/index.js CHANGED
@@ -1082,34 +1082,51 @@ export class DdbObj {
1082
1082
  // append!(av, [1..500])
1083
1083
  // ...
1084
1084
  // av
1085
- const _type = this.type - 64;
1085
+ const type_ = this.type - 64;
1086
1086
  const limit = 10;
1087
- let items = new Array(Math.min(limit, this.rows));
1087
+ let array_items = new Array(Math.min(limit, this.rows));
1088
1088
  let i_items = 0;
1089
1089
  for (const { lengths, data } of this.value) {
1090
1090
  let acc_len = 0;
1091
1091
  for (const length of lengths) {
1092
- let _items = new Array(Math.min(limit, length));
1093
- for (let i = 0; i < _items.length; i++)
1094
- if (_type === DdbType.decimal32 || _type === 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 ? str.green : str;
1092
+ let items = new Array(Math.min(limit, length));
1093
+ for (let i = 0; i < items.length; i++)
1094
+ switch (type_) {
1095
+ case DdbType.decimal32:
1096
+ case DdbType.decimal64:
1097
+ const x = data[acc_len + i];
1098
+ if (x === nulls.int64 /* && _type === DdbType.decimal64 一定成立 */ ||
1099
+ x === nulls.int32 && type_ === DdbType.decimal32)
1100
+ return '';
1101
+ const { scale } = this.value;
1102
+ const s = String(x < 0 ? -x : x).padStart(scale, '0');
1103
+ const str = (x < 0 ? '-' : '') + (scale ? `${s.slice(0, -scale) || '0'}.${s.slice(-scale)}` : s);
1104
+ items[i] = options.colors ? str.green : str;
1105
+ break;
1106
+ case DdbType.complex:
1107
+ case DdbType.point: {
1108
+ const index = acc_len + i;
1109
+ items[i] = format(type_, data.subarray(2 * index, 2 * (index + 1)), this.le, options);
1110
+ break;
1111
+ }
1112
+ case DdbType.uuid:
1113
+ case DdbType.int128:
1114
+ case DdbType.ipaddr: {
1115
+ const index = acc_len + i;
1116
+ items[i] = format(type_, data.subarray(16 * index, 16 * (index + 1)), this.le, options);
1117
+ break;
1118
+ }
1119
+ default:
1120
+ items[i] = format(type_, data[acc_len + i], this.le, options);
1121
+ break;
1103
1122
  }
1104
- else
1105
- _items[i] = format(_type, data[acc_len + i], this.le, options);
1106
- items[i_items++] = format_array(_items, length > limit);
1123
+ array_items[i_items++] = format_array(items, length > limit);
1107
1124
  acc_len += length;
1108
1125
  }
1109
1126
  if (i_items >= limit)
1110
1127
  break;
1111
1128
  }
1112
- return format_array(items, this.rows > limit);
1129
+ return format_array(array_items, this.rows > limit);
1113
1130
  }
1114
1131
  switch (this.type) {
1115
1132
  case DdbType.symbol_extended: {
@@ -1482,7 +1499,7 @@ export function formati(obj, index, options = {}) {
1482
1499
  // append!(av, [1..500])
1483
1500
  // ...
1484
1501
  // av
1485
- const _type = obj.type - 64;
1502
+ const type_ = obj.type - 64;
1486
1503
  let offset = 0;
1487
1504
  for (const { lengths, data, rows } of obj.value) {
1488
1505
  let acc_len = 0;
@@ -1499,18 +1516,35 @@ export function formati(obj, index, options = {}) {
1499
1516
  const limit = 10;
1500
1517
  let items = new Array(Math.min(limit, length));
1501
1518
  for (let i = 0; i < items.length; i++)
1502
- if (_type === DdbType.decimal32 || _type === DdbType.decimal64) {
1503
- const x = data[acc_len + i];
1504
- if (x === nulls.int64 && _type === DdbType.decimal64 ||
1505
- x === nulls.int32 && _type === DdbType.decimal32)
1506
- return '';
1507
- const { scale } = obj.value;
1508
- const s = String(x < 0 ? -x : x).padStart(scale, '0');
1509
- const str = (x < 0 ? '-' : '') + (scale ? `${s.slice(0, -scale) || '0'}.${s.slice(-scale)}` : s);
1510
- items[i] = options.colors ? str.green : str;
1519
+ switch (type_) {
1520
+ case DdbType.decimal32:
1521
+ case DdbType.decimal64:
1522
+ const x = data[acc_len + i];
1523
+ if (x === nulls.int64 /* && _type === DdbType.decimal64 一定成立 */ ||
1524
+ x === nulls.int32 && type_ === DdbType.decimal32)
1525
+ return '';
1526
+ const { scale } = obj.value;
1527
+ const s = String(x < 0 ? -x : x).padStart(scale, '0');
1528
+ const str = (x < 0 ? '-' : '') + (scale ? `${s.slice(0, -scale) || '0'}.${s.slice(-scale)}` : s);
1529
+ items[i] = options.colors ? str.green : str;
1530
+ break;
1531
+ case DdbType.complex:
1532
+ case DdbType.point: {
1533
+ const index = acc_len + i;
1534
+ items[i] = format(type_, data.subarray(2 * index, 2 * (index + 1)), obj.le, options);
1535
+ break;
1536
+ }
1537
+ case DdbType.uuid:
1538
+ case DdbType.int128:
1539
+ case DdbType.ipaddr: {
1540
+ const index = acc_len + i;
1541
+ items[i] = format(type_, data.subarray(16 * index, 16 * (index + 1)), obj.le, options);
1542
+ break;
1543
+ }
1544
+ default:
1545
+ items[i] = format(type_, data[acc_len + i], obj.le, options);
1546
+ break;
1511
1547
  }
1512
- else
1513
- items[i] = format(_type, data[acc_len + i], obj.le, options);
1514
1548
  return (items.join(', ') + (length > limit ? ', ...' : '')).bracket('square');
1515
1549
  }
1516
1550
  }
@@ -1848,15 +1882,14 @@ export function date2ms(date) {
1848
1882
  // 将 server 的本地时间 (以 ms 为单位,1970.01.01 00:00:00 作为零点) 当成是客户端这里的本地的时间,然后根据本地的时区信息转换为 utc 时间
1849
1883
  // 本地的时区与实际的时间值相关,timezone offset 可能会受到夏令时 (DST) 的影响
1850
1884
  // 得到的 utc 毫秒数交给 js date 或者 dayjs 去格式化
1885
+ if (date === null || date === nulls.int32)
1886
+ return null;
1851
1887
  const ms = 1000 * 3600 * 24 * date;
1852
- return (date === null || date === nulls.int32) ?
1853
- null
1854
- :
1855
- 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1888
+ return 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1856
1889
  }
1857
1890
  export function date2str(date, format = 'YYYY.MM.DD') {
1858
1891
  return (date === null || date === nulls.int32) ?
1859
- null
1892
+ 'null'
1860
1893
  :
1861
1894
  dayjs(date2ms(date)).format(format);
1862
1895
  }
@@ -1883,16 +1916,15 @@ export function time2ms(time) {
1883
1916
  }
1884
1917
  export function time2str(time, format = 'HH:mm:ss.SSS') {
1885
1918
  return (time === null || time === nulls.int32) ?
1886
- null
1919
+ 'null'
1887
1920
  :
1888
1921
  dayjs(time2ms(time)).format(format);
1889
1922
  }
1890
1923
  export function minute2ms(minute) {
1924
+ if (minute === null || minute === nulls.int32)
1925
+ return null;
1891
1926
  const ms = 60 * 1000 * minute;
1892
- return (minute === null || minute === nulls.int32) ?
1893
- null
1894
- :
1895
- 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1927
+ return 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1896
1928
  }
1897
1929
  export function minute2str(minute, format = 'HH:mm[m]') {
1898
1930
  return (minute === null || minute === nulls.int32) ?
@@ -1901,11 +1933,10 @@ export function minute2str(minute, format = 'HH:mm[m]') {
1901
1933
  dayjs(minute2ms(minute)).format(format);
1902
1934
  }
1903
1935
  export function second2ms(second) {
1936
+ if (second === null || second === nulls.int32)
1937
+ return null;
1904
1938
  const ms = 1000 * second;
1905
- return (second === null || second === nulls.int32) ?
1906
- null
1907
- :
1908
- 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1939
+ return 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1909
1940
  }
1910
1941
  export function second2str(second, format = 'HH:mm:ss') {
1911
1942
  return (second === null || second === nulls.int32) ?
@@ -1914,11 +1945,10 @@ export function second2str(second, format = 'HH:mm:ss') {
1914
1945
  dayjs(second2ms(second)).format(format);
1915
1946
  }
1916
1947
  export function datetime2ms(datetime) {
1948
+ if (datetime === null || datetime === nulls.int32)
1949
+ return null;
1917
1950
  const ms = 1000 * datetime;
1918
- return (datetime === null || datetime === nulls.int32) ?
1919
- null
1920
- :
1921
- 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1951
+ return 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1922
1952
  }
1923
1953
  export function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
1924
1954
  return (datetime === null || datetime === nulls.int32) ?
@@ -1927,11 +1957,10 @@ export function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
1927
1957
  dayjs(datetime2ms(datetime)).format(format);
1928
1958
  }
1929
1959
  export function timestamp2ms(timestamp) {
1960
+ if (timestamp === null || timestamp === nulls.int64)
1961
+ return null;
1930
1962
  const ms = Number(timestamp);
1931
- return (timestamp === null || timestamp === nulls.int64) ?
1932
- null
1933
- :
1934
- 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1963
+ return 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1935
1964
  }
1936
1965
  /** format timestamp (bigint) to string
1937
1966
  - timestamp: bigint value
@@ -1946,18 +1975,16 @@ export function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1946
1975
  dayjs(timestamp2ms(timestamp)).format(format);
1947
1976
  }
1948
1977
  export function datehour2ms(datehour) {
1978
+ if (datehour === null || datehour === nulls.int32)
1979
+ return null;
1949
1980
  const ms = 1000 * 3600 * datehour;
1950
- return (datehour === null || datehour === nulls.int32) ?
1951
- null
1952
- :
1953
- 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1981
+ return 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1954
1982
  }
1955
1983
  export function datehour2str(datehour, format = 'YYYY.MM.DDTHH') {
1984
+ if (datehour === null || datehour === nulls.int32)
1985
+ return 'null';
1956
1986
  const ms = 1000 * 3600 * datehour;
1957
- return (datehour === null || datehour === nulls.int32) ?
1958
- 'null'
1959
- :
1960
- dayjs(1000 * 60 * new Date(ms).getTimezoneOffset() + ms).format(format);
1987
+ return dayjs(1000 * 60 * new Date(ms).getTimezoneOffset() + ms).format(format);
1961
1988
  }
1962
1989
  /** parse timestamp string to bigint value
1963
1990
  - str: timestamp string, 如果为空字符串或 'null' 会返回对应的空值 (nulls.int64)
@@ -1994,11 +2021,10 @@ export function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
1994
2021
  String(nanotime % 1000000000n).padStart(9, '0'));
1995
2022
  }
1996
2023
  export function nanotimestamp2ns(nanotimestamp) {
2024
+ if (nanotimestamp === null || nanotimestamp === nulls.int64)
2025
+ return null;
1997
2026
  const ms = Number(nanotimestamp / 1000000n);
1998
- return (nanotimestamp === null || nanotimestamp === nulls.int64) ?
1999
- null
2000
- :
2001
- BigInt(1000 * 60 * new Date(ms).getTimezoneOffset()) * 1000000n + nanotimestamp;
2027
+ return BigInt(1000 * 60 * new Date(ms).getTimezoneOffset()) * 1000000n + nanotimestamp;
2002
2028
  }
2003
2029
  /** format nanotimestamp value (bigint) to string
2004
2030
  - nanotimestamp: bigint value
@@ -2037,10 +2063,11 @@ export function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.S
2037
2063
  - str: nano timestamp string, 如果为空字符串或 'null' 会返回对应的空值 (nulls.int64)
2038
2064
  nano timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
2039
2065
  - format?:
2040
- 对应传入字符串的格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSSSSSSSS` The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
2041
- 秒的格式为 ss (必须包含); 纳秒的格式为 SSSSSSSSS (必须包含) Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
2066
+ 对应传入字符串的格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
2067
+ 秒的格式为 ss (必须包含); 纳秒的格式为 SSSSSSSSS (必须包含)
2042
2068
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
2043
- */
2069
+ The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
2070
+ Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included) */
2044
2071
  export function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
2045
2072
  if (!str || str === 'null')
2046
2073
  return nulls.int64;
@@ -2106,11 +2133,11 @@ export class DDB {
2106
2133
  le = true;
2107
2134
  /** little endian (client) */
2108
2135
  static le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
2109
- /** 是否在建立连接后自动登录,默认 true */
2136
+ /** 是否在建立连接后自动登录,默认 true Whether to automatically log in after the connection is established, the default is true */
2110
2137
  autologin = true;
2111
- /** DolphinDB 登录用户名 */
2138
+ /** DolphinDB 登录用户名 DolphinDB username */
2112
2139
  username = 'admin';
2113
- /** DolphinDB 登录密码 */
2140
+ /** DolphinDB 登录密码 DolphinDB password */
2114
2141
  password = '123456';
2115
2142
  /** python session flag (2048) */
2116
2143
  python = false;
@@ -2169,7 +2196,7 @@ export class DDB {
2169
2196
  // 这里的实现一定会被 connect 中的实现覆盖
2170
2197
  }
2171
2198
  /** 建立实际的 WebSocket 连接到 URL 对应的 DolphinDB Establish a actual websocket connection to the DolphindB corresponding to the URL
2172
- 是幂等的,调用后会确保已连接到数据库 (确保 websocket.readyState 为 open),否则报错 It is a power, and after calling, it will ensure that it has been connected to the database (ensure that websocket.ReadyState is open), otherwise an error will be reported
2199
+ 是幂等的,调用后会确保已连接到数据库 (确保 websocket.readyState 为 open),否则报错 After calling, it will ensure that it has been connected to the database (ensure that websocket.ReadyState is open), otherwise an error will be reported
2173
2200
  this.autologin 为 true 时自动登录 this.autologin automatically log in when it is true */
2174
2201
  async connect() {
2175
2202
  if (this.connected)