dolphindb 3.1.13 → 3.1.15

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
@@ -102,8 +102,11 @@ let ddb = new DDB('ws://127.0.0.1:8848')
102
102
  // Use HTTPS encryption
103
103
  // let ddb = new DDB('wss://dolphindb.com')
104
104
 
105
- // 2.3 Establish a connection to DolphinDB (requires DolphinDB database version no less than 1.30.16 or 2.00.4)
106
- await ddb.connect()
105
+ // 2.3 Call the DolphinDB add function, automatically connecting to the database (requires DolphinDB version 1.30.16 or 2.00.4 or higher)
106
+ console.log(await ddb.invoke('add', [1, 2])) // Output 3
107
+
108
+ // 2.4 Disconnect after use to release resources
109
+ ddb.disconnect()
107
110
  ```
108
111
 
109
112
  #### Code completion and function prompt
@@ -539,6 +542,12 @@ console.log(
539
542
  )
540
543
  ```
541
544
 
545
+ ### Close the connection
546
+ ```ts
547
+ ddb.disconnect()
548
+ ```
549
+
550
+
542
551
  ### Other Examples
543
552
 
544
553
  ```ts
package/README.zh.md CHANGED
@@ -98,8 +98,11 @@ let ddb = new DDB('ws://127.0.0.1:8848')
98
98
  // 使用 HTTPS 加密
99
99
  // let ddb = new DDB('wss://dolphindb.com')
100
100
 
101
- // 2.3 建立到 DolphinDB 的连接(要求 DolphinDB 数据库版本不低于 1.30.16 或 2.00.4)
102
- await ddb.connect()
101
+ // 2.3 调用 DolphinDB add 函数,调用时自动连接到数据库(要求 DolphinDB 数据库版本不低于 1.30.16 或 2.00.4)
102
+ console.log(await ddb.invoke('add', [1, 2])) // 输出 3
103
+
104
+ // 2.4 使用完毕,断开连接释放资源
105
+ ddb.disconnect()
103
106
  ```
104
107
 
105
108
  #### 代码补全、函数提示数据
@@ -519,6 +522,11 @@ console.log(
519
522
  )
520
523
  ```
521
524
 
525
+ ### 关闭连接
526
+ ```ts
527
+ ddb.disconnect()
528
+ ```
529
+
522
530
  ### 其他例子
523
531
 
524
532
  ```ts
package/browser.d.ts CHANGED
@@ -184,7 +184,7 @@ export interface InspectOptions {
184
184
  export declare function format(type: DdbType, value: DdbValue, le: boolean, options?: InspectOptions): string;
185
185
  /** 格式化向量、集合中的第 index 项为字符串,空值返回 'null' 字符串 formatted vector, the index-th item in the collection is a string, a null value returns a 'null' string */
186
186
  export declare function formati(obj: DdbVectorObj, index: number, options?: InspectOptions): string;
187
- export declare function convert(type: DdbType, value: DdbValue, le: boolean, { blob, char, timestamp }?: ConvertOptions): string | number | bigint | boolean | string[] | number[] | DdbFunctionDefValue | DdbDurationValue | DdbDecimal32Value | DdbDecimal64Value | DdbDecimal32VectorValue | DdbDecimal64VectorValue | DdbSymbolExtendedValue | DdbExtObjValue | DdbTensorValue | Uint8Array<ArrayBufferLike> | Int8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | Float32Array<ArrayBufferLike> | Float64Array<ArrayBufferLike> | BigInt64Array<ArrayBufferLike> | BigInt128Array | Uint8Array<ArrayBufferLike>[] | DdbObj<DdbValue>[] | IotVectorItemValue | DdbArrayVectorValue | DdbDecimal128VectorValue | DdbDurationVectorValue | DdbMatrixValue | DdbChartValue;
187
+ export declare function convert(type: DdbType, value: DdbValue, le: boolean, { blob, char, timestamp }?: ConvertOptions): string | number | bigint | boolean | number[] | Uint8Array<ArrayBufferLike> | DdbFunctionDefValue | DdbDurationValue | DdbDecimal32Value | DdbDecimal64Value | Int8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | Float32Array<ArrayBufferLike> | Float64Array<ArrayBufferLike> | BigInt64Array<ArrayBufferLike> | BigInt128Array | string[] | Uint8Array<ArrayBufferLike>[] | DdbObj<DdbValue>[] | IotVectorItemValue | DdbSymbolExtendedValue | DdbArrayVectorValue | DdbDecimal32VectorValue | DdbDecimal64VectorValue | DdbDecimal128VectorValue | DdbDurationVectorValue | DdbMatrixValue | DdbChartValue | DdbTensorValue | DdbExtObjValue;
188
188
  /** 转换一个向量到 js 原生数组 */
189
189
  export declare function converts(type: DdbType, value: DdbVectorValue, rows: number, le: boolean, options?: ConvertOptions): any[] | Uint8Array;
190
190
  /** 构造 void 类型,默认为 `DdbVoidType.undefined` */
package/browser.js CHANGED
@@ -3,7 +3,7 @@ import { blue, cyan, green, grey, magenta } from 'xshell/chalk.browser.js';
3
3
  import { concat, assert, Lock, genid, seq, zip_object, decode, delay, check } from 'xshell/utils.browser.js';
4
4
  import { connect_websocket } from 'xshell/net.browser.js';
5
5
  import { t } from "./i18n/index.js";
6
- import { date2str, datehour2str, datetime2str, ddb_tensor_bytes, DdbChartType, DdbDurationUnit, DdbForm, DdbFunctionType, DdbType, DdbVoidType, dictables, function_definition_patterns, generate_array_type, get_big_int_128, get_time_ddbobj, get_duration_unit, get_type_name, int1282str, ipaddr2str, is_decimal_null_value, is_decimal_type, minute2str, month2str, nanotime2str, nanotimestamp2str, nulls, second2str, set_big_int_128, time2str, timestamp2str, uuid2str, get_times_ddbobj, funcdefs } from "./common.js";
6
+ import { date2str, datehour2str, datetime2str, ddb_tensor_bytes, DdbChartType, DdbDurationUnit, DdbForm, DdbFunctionType, DdbType, DdbVoidType, dictables, function_definition_patterns, generate_array_type, get_big_int_128, get_time_ddbobj, get_duration_unit, get_type_name, int1282str, ipaddr2str, is_decimal_null_value, is_decimal_type, minute2str, month2str, nanotime2str, nanotimestamp2str, nulls, second2str, set_big_int_128, time2str, timestamp2str, uuid2str, get_times_ddbobj, funcdefs, get_number_formatter } from "./common.js";
7
7
  export * from "./common.js";
8
8
  /** 可以表示所有 DolphinDB 数据库中的数据类型 Can represent data types in all DolphinDB databases */
9
9
  export class DdbObj {
@@ -871,7 +871,7 @@ export class DdbObj {
871
871
  case DdbType.handle:
872
872
  case DdbType.datasource:
873
873
  case DdbType.resource:
874
- assert(!value.includes('\0'), t('pack 时字符串中间不能含有 \\0, 否则上传给 DolphinDB 会导致连接断开'));
874
+ check(!value.includes('\0'), t('pack 时字符串中间不能含有 \\0, 否则上传给 DolphinDB 会导致连接断开'));
875
875
  return [
876
876
  DdbObj.enc.encode(value),
877
877
  Uint8Array.of(0),
@@ -1057,7 +1057,7 @@ export class DdbObj {
1057
1057
  let bufs = new Array(length * 2);
1058
1058
  for (let i = 0; i < length; i++) {
1059
1059
  const s = value[i];
1060
- assert(!s.includes('\0'), t('pack 时字符串中间不能含有 \\0, 否则上传给 DolphinDB 会导致连接断开'));
1060
+ check(!s.includes('\0'), t('pack 时字符串中间不能含有 \\0, 否则上传给 DolphinDB 会导致连接断开'));
1061
1061
  bufs[2 * i] = this.enc.encode(s);
1062
1062
  bufs[2 * i + 1] = Uint8Array.of(0);
1063
1063
  }
@@ -1566,29 +1566,10 @@ export class DdbObj {
1566
1566
  return obj;
1567
1567
  }
1568
1568
  }
1569
- /** 整数一定用这个 number formatter, InspectOptions.decimals 不传也用这个 */
1570
- let default_formatter = new Intl.NumberFormat('en-US', { maximumFractionDigits: 20 });
1571
- let _decimals = 20;
1572
- let _grouping = true;
1573
- /** 缓存,为了优化性能,通常 options.decimals 都是不变的 */
1574
- let _formatter = new Intl.NumberFormat('en-US', { maximumFractionDigits: 20 });
1575
1569
  /** 根据 DdbType 格式化单个元素 (value) 为字符串 */
1576
1570
  export function format(type, value, le, options = {}) {
1577
- const { nullstr = false, colors = false, quote = false, grouping = true, timestamp = 'ms' } = options;
1578
- const formatter = (() => {
1579
- const decimals = options.decimals ?? _decimals;
1580
- if (decimals !== _decimals || grouping !== _grouping) {
1581
- _decimals = decimals;
1582
- _grouping = grouping;
1583
- default_formatter = new Intl.NumberFormat('en-US', { maximumFractionDigits: 20, useGrouping: grouping });
1584
- _formatter = new Intl.NumberFormat('en-US', {
1585
- maximumFractionDigits: decimals,
1586
- minimumFractionDigits: decimals,
1587
- useGrouping: grouping
1588
- });
1589
- }
1590
- return options.decimals === undefined || options.decimals === null ? default_formatter : _formatter;
1591
- })();
1571
+ const { nullstr = false, colors = false, quote = false, timestamp = 'ms' } = options;
1572
+ const number_formatter = get_number_formatter(options.decimals, options.grouping);
1592
1573
  function get_nullstr() {
1593
1574
  const str = value === DdbVoidType.default ? 'default' : 'null';
1594
1575
  return nullstr ?
@@ -1641,21 +1622,21 @@ export function format(type, value, le, options = {}) {
1641
1622
  if (value === null || value === nulls.int16)
1642
1623
  return get_nullstr();
1643
1624
  else {
1644
- const str = default_formatter.format(value);
1625
+ const str = number_formatter.format(value);
1645
1626
  return colors ? green(str) : str;
1646
1627
  }
1647
1628
  case DdbType.int:
1648
1629
  if (value === null || value === nulls.int32)
1649
1630
  return get_nullstr();
1650
1631
  else {
1651
- const str = default_formatter.format(value);
1632
+ const str = number_formatter.format(value);
1652
1633
  return colors ? green(str) : str;
1653
1634
  }
1654
1635
  case DdbType.long:
1655
1636
  if (value === null || value === nulls.int64)
1656
1637
  return get_nullstr();
1657
1638
  else {
1658
- const str = default_formatter.format(value);
1639
+ const str = number_formatter.format(value);
1659
1640
  return colors ? green(str) : str;
1660
1641
  }
1661
1642
  case DdbType.date:
@@ -1680,14 +1661,14 @@ export function format(type, value, le, options = {}) {
1680
1661
  if (value === null || value === nulls.float32)
1681
1662
  return get_nullstr();
1682
1663
  else {
1683
- const str = formatter.format(value);
1664
+ const str = number_formatter.format(value);
1684
1665
  return colors ? green(str) : str;
1685
1666
  }
1686
1667
  case DdbType.double:
1687
1668
  if (value === null || value === nulls.double)
1688
1669
  return get_nullstr();
1689
1670
  else {
1690
- const str = formatter.format(value);
1671
+ const str = number_formatter.format(value);
1691
1672
  return colors ? green(str) : str;
1692
1673
  }
1693
1674
  case DdbType.symbol:
@@ -1759,7 +1740,7 @@ export function format(type, value, le, options = {}) {
1759
1740
  }
1760
1741
  /** 格式化向量、集合中的第 index 项为字符串,空值返回 'null' 字符串 formatted vector, the index-th item in the collection is a string, a null value returns a 'null' string */
1761
1742
  export function formati(obj, index, options = {}) {
1762
- assert(index < obj.rows, 'index < obj.rows');
1743
+ check(index < obj.rows, 'index < obj.rows');
1763
1744
  if (obj.type < 64 || obj.type >= 128) // 普通数组
1764
1745
  switch (obj.type) {
1765
1746
  case DdbType.symbol_extended: {
@@ -1793,6 +1774,8 @@ export function formati(obj, index, options = {}) {
1793
1774
  const str = (x < 0 ? '-' : '') + (scale ? `${s.slice(0, -scale) || '0'}.${s.slice(-scale)}` : s);
1794
1775
  return options.colors ? green(str) : str;
1795
1776
  }
1777
+ case DdbType.any:
1778
+ return obj.value[index].toString(options);
1796
1779
  default:
1797
1780
  return format(obj.type, obj.value[index], obj.le, options);
1798
1781
  }
@@ -2117,7 +2100,7 @@ export class DdbDate extends DdbObj {
2117
2100
  }
2118
2101
  export class DdbBlob extends DdbObj {
2119
2102
  constructor(value) {
2120
- assert(value, t('new DdbBlob 不能传空的 value'));
2103
+ check(value, t('new DdbBlob 不能传空的 value'));
2121
2104
  super({
2122
2105
  form: DdbForm.scalar,
2123
2106
  type: DdbType.blob,