dolphindb 2.0.1036 → 2.0.1101

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/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # Release Notes
2
+
3
+ ## Version: 2.0.1101
4
+
5
+ ### Feature Enhancement
6
+
7
+ Support the serializtion of DURATION vector.
8
+
9
+ ## Version: 2.0.1100
10
+
11
+ ### Feature Enhancement
12
+
13
+ Support for processing exchange identifiers as DURATION type.
14
+
15
+
@@ -0,0 +1,15 @@
1
+ # 版本发布说明
2
+
3
+ ## 版本:2.0.1101
4
+
5
+ ### 功能改善
6
+
7
+ 新增对 DURATION Vector 序列化的支持。
8
+
9
+ ## 版本: 2.0.1100
10
+
11
+ ### 功能改善
12
+
13
+ 新增 DURATION 类型对交易所标识的支持。
14
+
15
+
package/README.md CHANGED
@@ -24,25 +24,27 @@ https://www.npmjs.com/package/dolphindb
24
24
  - Use WebSocket to communicate with DolphinDB database, exchange data in binary format, and support real-time push of streaming data
25
25
  - Support running in browser environment and Node.js environment
26
26
  - Use TypedArray such as Int32Array in JavaScript to process binary data, with high performance
27
- - A single call supports serialized upload of up to 2GB of data, and the amount of downloaded data is not limited
27
+ - Support serialized upload of up to 2GB of data with a single call, and the amount of downloaded data is not limited
28
28
 
29
29
  ## Installation
30
- ```bash
31
- # 1. Install the latest version of Node.js and browser on the machine
32
-
33
- # 2. Create a new project (skip this step if you already have a project)
34
- mkdir dolphindb-example
35
- cd dolphindb-example
36
- npm init --yes
37
- # Open the package.json file with an editor, add the line "type": "module", below "main": "./index.js",
38
- # This enables the use of ECMAScript modules, and in the code behind you can use import { DDB } from 'dolphindb' to import npm packages
39
-
40
- # 3. Install npm packages in your project
41
- npm install dolphindb
42
- ```
30
+
31
+ 1. Install the latest version of Node.js and browser.
32
+ 2. (Optional) Create a new project (skip this step if there's an existing project):
33
+
34
+ ```bash
35
+ mkdir dolphindb-example
36
+ cd dolphindb-example
37
+ npm init --yes
38
+ ```
39
+ 3. Open the package.json file with an editor, and add the line `"type": "module"`, below `"main": "./index.js"`. This enables the ECMAScript modules. In the following code, you can use `import { DDB } from 'dolphindb'` to import npm packages.
40
+ 4. Install npm packages in your project.
41
+
42
+ ```bash
43
+ npm install dolphindb
44
+ ```
43
45
 
44
46
  ## Usage
45
- ### 0. Initialize and connect to DolphinDB
47
+ ### Initializing and connecting to DolphinDB
46
48
  #### NPM
47
49
  ```ts
48
50
  import { DDB } from 'dolphindb'
@@ -70,9 +72,9 @@ await ddb.connect()
70
72
  </script>
71
73
  ```
72
74
 
73
- Code completion, function prompt data:
74
- https://cdn.dolphindb.cn/assets/docs.zh.json
75
- https://cdn.dolphindb.cn/assets/docs.en.json
75
+ Data for code completion and function prompts:
76
+ - https://cdn.dolphindb.cn/assets/docs.zh.json
77
+ - https://cdn.dolphindb.cn/assets/docs.en.json
76
78
 
77
79
  #### DDB options
78
80
  ```ts
@@ -102,7 +104,7 @@ let ddbsecure = new DDB('wss://dolphindb.com', {
102
104
  ```
103
105
 
104
106
 
105
- ### 1. Call Functions
107
+ ### Calling functions
106
108
  #### Example
107
109
  ```ts
108
110
  import { DdbInt } from 'dolphindb'
@@ -113,19 +115,21 @@ const result = await ddb.call('add', [new DdbInt(1), new DdbInt(1)])
113
115
  console.log(result.value === 2) // true
114
116
  ```
115
117
 
116
- #### The DolphinDB JavaScript API uses DdbObj objects to represent data types in DolphinDB
117
- In the above example, two parameters 1 (corresponding to the int type in DolphinDB) are uploaded to the DolphinDB database as parameters of the add function, then the result of the function call is received.
118
+ #### Using DdbObj objects to represent data types in DolphinDB
119
+
120
+ In the preceding example, two parameters (`new DdbInt(1)`, corresponding to the INT type in DolphinDB) are uploaded to the DolphinDB database as parameters of the add function, then the result of the function call is received.
118
121
 
119
122
  `<DdbInt>` is used by TypeScript to infer the type of the return value
120
123
 
121
124
  - result is a `DdbInt`, which is also a `DdbObj<number>`
122
125
  - result.form is a `DdbForm.scalar`
123
126
  - result.type is a `DdbType.int`
124
- - result.value is native `number` in JavaScript (the value range and precision of int can be accurately represented by JavaScript number)
127
+ - result.value is data of `number` type in JavaScript (the value range and precision of INT can be accurately represented by JavaScript `number` type)
125
128
 
126
129
  It is recommended to first understand the concepts related to TypedArray in JavaScript, you can refer to:
127
- https://stackoverflow.com/questions/42416783/where-to-use-arraybuffer-vs-typed-array-in-javascript
128
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
130
+
131
+ - https://stackoverflow.com/questions/42416783/where-to-use-arraybuffer-vs-typed-array-in-javascript
132
+ - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
129
133
 
130
134
 
131
135
  ```ts
@@ -220,7 +224,10 @@ enum DdbType {
220
224
  }
221
225
  ```
222
226
 
223
- ##### If there is no shortcut class, you can also specify form and type to manually create a DdbObj object
227
+ ##### Specifying form and type to manually create a DdbObj object
228
+
229
+ If there is no shortcut class, you can also specify form and type to manually create a DdbObj object:
230
+
224
231
  ```ts
225
232
  // Created by the DdbDateTime shortcut class
226
233
  new DdbDateTime(1644573600)
@@ -257,7 +264,10 @@ const obj = new DdbSetInt(
257
264
  )
258
265
  ```
259
266
 
260
- ##### NULL object in the form of scalar, the value corresponding to DdbObj is null in JavaScript
267
+ ##### NULL object in the form of scalar
268
+
269
+ For the NULL object in the form of scalar, the value corresponding to DdbObj is null in JavaScript:
270
+
261
271
  ```ts
262
272
  ;(await ddb.eval('double()')).value === null
263
273
 
@@ -267,7 +277,7 @@ new DdbDouble(null)
267
277
  ```
268
278
 
269
279
 
270
- #### `call` Method Declaration
280
+ #### `call` method declaration
271
281
  ```ts
272
282
  async call <T extends DdbObj> (
273
283
  /** function name */
@@ -297,7 +307,7 @@ async call <T extends DdbObj> (
297
307
  ```
298
308
 
299
309
 
300
- ### 2. Execute Script
310
+ ### Executing the script
301
311
  #### Example
302
312
  ```ts
303
313
  const result = await ddb.eval(
@@ -314,7 +324,7 @@ const result = await ddb.eval(
314
324
  console.log(result.value === 2n) // true
315
325
  ```
316
326
 
317
- In the above example, a script is uploaded through a string to the DolphinDB database for execution, and the execution result of the last statement `foo(1l, 1l)` is received.
327
+ In the preceding example, a script is uploaded through a string to the DolphinDB database for execution, and the execution result of the last statement `foo(1l, 1l)` is received.
318
328
 
319
329
  `<DdbLong>` is used by TypeScript to infer the type of the return value
320
330
 
@@ -325,7 +335,8 @@ In the above example, a script is uploaded through a string to the DolphinDB dat
325
335
 
326
336
  As long as the WebSocket connection is not disconnected, the custom function `foo` will always exist in the subsequent session and can be reused, for example, you can use `await ddb.call<DdbInt>('foo', [new DdbInt(1), new DdbInt(1)])` to call this custom function
327
337
 
328
- #### `eval` Method Declaration
338
+ #### `eval` Method declaration
339
+
329
340
  ```ts
330
341
  async eval <T extends DdbObj> (
331
342
  /** the script to execute */
@@ -340,7 +351,7 @@ async eval <T extends DdbObj> (
340
351
  ```
341
352
 
342
353
 
343
- ### 3. Upload Variables
354
+ ### Uploading variables
344
355
  #### Example
345
356
  ```ts
346
357
  import { DdbVectorDouble } from 'dolphindb'
@@ -351,11 +362,11 @@ a.fill(1.0)
351
362
  ddb.upload(['bar1', 'bar2'], [new DdbVectorDouble(a), new DdbVectorDouble(a)])
352
363
  ```
353
364
 
354
- In the above example, two variables `bar1`, `bar2` are uploaded, and the variable value is a double vector of length 10000
365
+ In the preceding example, two variables, `bar1` and `bar2`, are uploaded, and the variable value is a double vector of length 10000
355
366
 
356
- As long as the WebSocket connection is not disconnected, the variables `bar1`, `bar2` will always exist in the subsequent session and can be reused
367
+ As long as the WebSocket connection is on, variables `bar1` and `bar2` will always exist in subsequent session and can be reused
357
368
 
358
- #### `upload` Method Declaration
369
+ #### `upload` method declaration
359
370
  ```ts
360
371
  async upload (
361
372
  /** variable names */
@@ -367,7 +378,7 @@ async upload (
367
378
  ```
368
379
 
369
380
 
370
- ### 4. Some Examples
381
+ ### Examples
371
382
  ```ts
372
383
  import { nulls, DdbInt, timestamp2str, DdbVectorSymbol, DdbTable, DdbVectorDouble } from 'dolphindb'
373
384
 
@@ -402,7 +413,8 @@ new DdbTable(
402
413
  )
403
414
  ```
404
415
 
405
- ### 5. Streaming Data
416
+ ### Streaming data
417
+
406
418
  ```ts
407
419
  // New Streaming Data Connection Configuration
408
420
  let sddb = new DDB('ws://192.168.0.43:8800', {
@@ -474,6 +486,7 @@ export interface StreamingData extends StreamingParams {
474
486
 
475
487
 
476
488
  ### Development
489
+
477
490
  ```shell
478
491
  # Install the latest version of nodejs
479
492
  # https://nodejs.org/en/download/current/
package/README.zh.md CHANGED
@@ -27,23 +27,24 @@ https://www.npmjs.com/package/dolphindb
27
27
  - 单次调用支持最大 2 GB 数据的序列化上传,下载数据量不受限制
28
28
 
29
29
  ## 安装
30
- ```bash
31
- # 1. 在机器上安装最新版的 Node.js 及浏览器
32
-
33
- # 2. 创建新项目
34
- mkdir dolphindb-example
35
- cd dolphindb-example
36
- npm init --yes
37
- # 用编辑器打开 package.json 文件,在 "main": "./index.js", 下面加入一行 "type": "module",
38
- # 这样能够启用 ECMAScript modules,在后面代码中可以使用 import { DDB } from 'dolphindb' 导入 npm 包
39
-
40
- # 3. 在项目中安装 npm 包
41
- npm install dolphindb
42
- ```
30
+
31
+ 1. 在机器上安装最新版的 Node.js 及浏览器。
32
+ 2. (可选)使用以下命令创建新项目。如果已有项目,可跳过此步。
33
+ ```bash
34
+ mkdir dolphindb-example
35
+ cd dolphindb-example
36
+ npm init --yes
37
+ ```
38
+ 3. 用编辑器打开 package.json 文件,在 `"main": "./index.js"` 下方加入一行 "type": "module", 这样能够启用 ECMAScript modules,在后面代码中可以使用 `import { DDB } from 'dolphindb'` 导入 npm 包。
39
+ 4. 在项目中安装 npm 包。
40
+ ```bash
41
+ npm install dolphindb
42
+ ```
43
43
 
44
44
  ## 用法
45
- ### 0. 初始化并连接到 DolphinDB
45
+ ### 初始化并连接到 DolphinDB
46
46
  #### NPM
47
+
47
48
  ```ts
48
49
  import { DDB } from 'dolphindb'
49
50
  // 已有的使用 CommonJS 模块的项目的导入方法为 const { DDB } = await import('dolphindb')
@@ -60,6 +61,7 @@ await ddb.connect()
60
61
  ```
61
62
 
62
63
  #### CDN
64
+
63
65
  ```html
64
66
  <script type="module">
65
67
  import { DDB } from 'https://cdn.dolphindb.cn/assets/api.js'
@@ -71,11 +73,12 @@ await ddb.connect()
71
73
  ```
72
74
 
73
75
  代码补全、函数提示数据:
74
- https://cdn.dolphindb.cn/assets/docs.zh.json
75
- https://cdn.dolphindb.cn/assets/docs.en.json
76
+ - https://cdn.dolphindb.cn/assets/docs.zh.json
77
+ - https://cdn.dolphindb.cn/assets/docs.en.json
76
78
 
77
79
 
78
80
  #### DDB 选项
81
+
79
82
  ```ts
80
83
  let ddb = new DDB('ws://127.0.0.1:8848', {
81
84
  // 是否在建立连接后自动登录,默认 `true`
@@ -100,7 +103,7 @@ let ddb = new DDB('ws://127.0.0.1:8848', {
100
103
  ```
101
104
 
102
105
 
103
- ### 1. 调用函数
106
+ ### 调用函数
104
107
  #### 例子
105
108
  ```ts
106
109
  import { DdbInt } from 'dolphindb'
@@ -111,7 +114,8 @@ const result = await ddb.call('add', [new DdbInt(1), new DdbInt(1)])
111
114
  console.log(result.value === 2) // true
112
115
  ```
113
116
 
114
- #### DolphinDB JavaScript API 用 DdbObj 对象来表示 DolphinDB 中的数据类型
117
+ ##### 用 DdbObj 对象来表示 DolphinDB 中的数据类型
118
+
115
119
  上面例子中,上传了两个参数 1 (对应 DolphinDB 中的 int 类型) 到 DolphinDB 数据库,作为 add 函数的参数,并接收函数调用的结果 result
116
120
 
117
121
  `<DdbInt>` 用于 TypeScript 推断返回值的类型
@@ -217,7 +221,10 @@ enum DdbType {
217
221
  }
218
222
  ```
219
223
 
220
- ##### 没有快捷类的类型,也可以指定 form 和 type 手动创建 DdbObj 对象
224
+ ##### 无快捷类的类型
225
+
226
+ 对于没有快捷类的类型,可指定 form 和 type 手动创建 DdbObj 对象
227
+
221
228
  ```ts
222
229
  // 通过 DdbDateTime 快捷类创建
223
230
  new DdbDateTime(1644573600)
@@ -254,7 +261,10 @@ const obj = new DdbSetInt(
254
261
  )
255
262
  ```
256
263
 
257
- ##### scalar 形式的 NULL 对象, 对应 DdbObj 的 value 为 JavaScript 中的 null
264
+ #### scalar 形式的 NULL 对象
265
+
266
+ scalar 形式的 NULL 对象,其对应 DdbObj 的 value 为 JavaScript 中的 null:
267
+
258
268
  ```ts
259
269
  ;(await ddb.eval('double()')).value === null
260
270
 
@@ -294,7 +304,7 @@ async call <T extends DdbObj> (
294
304
  ```
295
305
 
296
306
 
297
- ### 2. 执行脚本
307
+ ### 执行脚本
298
308
  #### 例子
299
309
  ```ts
300
310
  const result = await ddb.eval(
@@ -337,7 +347,7 @@ async eval <T extends DdbObj> (
337
347
  ```
338
348
 
339
349
 
340
- ### 3. 上传变量
350
+ ### 上传变量
341
351
  #### 例子
342
352
  ```ts
343
353
  import { DdbVectorDouble } from 'dolphindb'
@@ -364,7 +374,8 @@ async upload (
364
374
  ```
365
375
 
366
376
 
367
- ### 4. 一些例子
377
+ ### 其他例子
378
+
368
379
  ```ts
369
380
  import { nulls, DdbInt, timestamp2str, DdbVectorSymbol, DdbTable, DdbVectorDouble } from 'dolphindb'
370
381
 
@@ -400,7 +411,8 @@ new DdbTable(
400
411
  ```
401
412
 
402
413
 
403
- ### 5. 流数据
414
+ ### 流数据
415
+
404
416
  ```ts
405
417
  // 新建流数据连接配置
406
418
  let sddb = new DDB('ws://192.168.0.43:8800', {
@@ -471,7 +483,8 @@ export interface StreamingData extends StreamingParams {
471
483
  ```
472
484
 
473
485
 
474
- ### 开发
486
+ ### 开发方法
487
+
475
488
  ```shell
476
489
  # 安装最新版的 nodejs
477
490
  # https://nodejs.org/en/download/current/
package/browser.js CHANGED
@@ -9,7 +9,7 @@ import { concat, assert, Lock, genid } from 'xshell/utils.browser.js';
9
9
  import { connect_websocket } from 'xshell/net.browser.js';
10
10
  import { t } from './i18n/index.js';
11
11
  import { DdbDecimal128Serializor } from './data-types/decimal-128.js';
12
- import { is_decimal_type, is_decimal_null_value } from './shared/utils/decimal-type.js';
12
+ import { is_decimal_type, is_decimal_null_value, get_duration_unit } from './shared/utils.js';
13
13
  import { nulls, DdbChartType, DdbDurationUnit, DdbForm, DdbFunctionType, DdbType } from './shared/constants.js';
14
14
  export * from './shared/constants.js';
15
15
  /** 可以表示所有 DolphinDB 数据库中的数据类型 Can represent data types in all DolphinDB databases */
@@ -951,6 +951,14 @@ export class DdbObj {
951
951
  case DdbType.complex:
952
952
  case DdbType.point:
953
953
  return [value];
954
+ case DdbType.duration:
955
+ let bufs = new Int32Array(length * 2);
956
+ for (let i = 0; i < length; i++) {
957
+ const { data, unit } = value[i];
958
+ bufs[2 * i] = data;
959
+ bufs[2 * i + 1] = unit;
960
+ }
961
+ return [bufs];
954
962
  case DdbType.any: {
955
963
  // [1, 2, 'a', 'aaa']
956
964
  // any[4](<Buffer
@@ -1470,7 +1478,7 @@ export function format(type, value, le, options = {}) {
1470
1478
  }
1471
1479
  case DdbType.duration: {
1472
1480
  const { data, unit } = value;
1473
- const str = `${data}${DdbDurationUnit[unit]}`;
1481
+ const str = `${data}${DdbDurationUnit[unit] ?? get_duration_unit(unit)}`;
1474
1482
  return colors ? magenta(str) : str;
1475
1483
  }
1476
1484
  case DdbType.decimal32: