dolphindb 2.0.1130 → 3.0.1

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
@@ -26,57 +26,81 @@ https://www.npmjs.com/package/dolphindb
26
26
  - Use TypedArray such as Int32Array in JavaScript to process binary data, with high performance
27
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
- ## Installation
29
+ ## Usage
30
+ ### Initialize and connect to DolphinDB
30
31
 
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):
32
+ #### Method 1: Use the built CDN version directly in the browser
33
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.
34
+ Save the following content to the `example.html` file, open it with a browser and run it. F12 opens the debugging console to see the log.
41
35
 
42
- ```bash
43
- npm install dolphindb
44
- ```
36
+ ```html
37
+ <!doctype html>
38
+ <html>
39
+ <head>
40
+ <title>DolphinDB</title>
41
+ <meta charset='utf-8' />
42
+ </head>
43
+ <body>
44
+ <script type="module">
45
+ import { DDB } from 'https://cdn.dolphindb.cn/assets/api.js'
46
+
47
+ let ddb = new DDB('ws://127.0.0.1:8848')
48
+
49
+ await ddb.connect()
50
+
51
+ console.log(
52
+ await ddb.eval('1 + 1')
53
+ )
54
+ </script>
55
+ </body>
56
+ </html>
57
+ ```
58
+
59
+ #### Method 2: Install the npm package in the project and import it
60
+
61
+ ##### 1. Installation
62
+
63
+ 1.1. Install the latest version of Node.js and browser on the machine.
64
+ - windows: https://nodejs.org/en/download/current/
65
+ - linux: https://github.com/nodesource/distributions?tab=readme-ov-file#debian-and-ubuntu-based-distributions
66
+ 1.2. (Optional) Create a new project using the following command. If you already have a project, you can skip this step.
67
+ ```bash
68
+ mkdir dolphindb-example
69
+ cd dolphindb-example
70
+ npm init --yes
71
+ ```
72
+ 1.3. Open the package.json file with an editor and add a line "type": "module" below `"main": "./index.js"`. This will enable ECMAScript modules. You can use `import { DDB } from 'dolphindb'` to import npm package.
73
+ 1.4. Install the npm package in the project.
74
+ ```bash
75
+ npm install dolphindb
76
+ ```
77
+
78
+ ##### 2. Use
45
79
 
46
- ## Usage
47
- ### Initializing and connecting to DolphinDB
48
- #### NPM
49
80
  ```ts
50
- import { DDB } from 'dolphindb'
81
+ // 2.1 Use the following method to import in the browser environment
82
+ import { DDB } from 'dolphindb/browser.js'
83
+
84
+ // 2.1 Use the following method to import in Node.js environment
85
+ // import { DDB } from 'dolphindb'
51
86
  // The import method for existing projects using CommonJS modules is const { DDB } = await import('dolphindb')
52
- // Use in browser: import { DDB } from 'dolphindb/browser.js'
53
87
 
54
- // Initially connect to an instance of DolphinDB using the WebSocket URL (without establishing an actual network connection)
88
+ // 2.2 Use the WebSocket URL to initialize the connection to the DolphinDB instance (without establishing an actual network connection)
55
89
  let ddb = new DDB('ws://127.0.0.1:8848')
56
90
 
57
- // Encrypt with HTTPS
91
+ // Use HTTPS encryption
58
92
  // let ddb = new DDB('wss://dolphindb.com')
59
93
 
60
- // Establish a connection to DolphinDB (requires DolphinDB database version at least 1.30.16 or 2.00.4)
94
+ // 2.3 Establish a connection to DolphinDB (requires DolphinDB database version to be no less than 1.30.16 or 2.00.4)
61
95
  await ddb.connect()
62
96
  ```
63
97
 
64
- #### CDN
65
- ```html
66
- <script type="module">
67
- import { DDB } from 'https://cdn.dolphindb.cn/assets/api.js'
68
-
69
- let ddb = new DDB('ws://127.0.0.1:8848')
70
-
71
- await ddb.connect()
72
- </script>
73
- ```
74
-
75
- Data for code completion and function prompts:
76
- - https://cdn.dolphindb.cn/assets/docs.zh.json
98
+ #### Code completion, function prompt data
99
+ - https://cdn.dolphindb.cn/assets/docs.zh.json
77
100
  - https://cdn.dolphindb.cn/assets/docs.en.json
78
101
 
79
- #### DDB options
102
+
103
+ #### DDB Connection Options
80
104
  ```ts
81
105
  let ddb = new DDB('ws://127.0.0.1:8848')
82
106
 
package/README.zh.md CHANGED
@@ -26,58 +26,81 @@ https://www.npmjs.com/package/dolphindb
26
26
  - 使用了 JavaScript 中的 Int32Array 等 TypedArray 处理二进制数据,性能较高
27
27
  - 单次调用支持最大 2 GB 数据的序列化上传,下载数据量不受限制
28
28
 
29
- ## 安装
29
+ ## 用法
30
+ ### 初始化并连接到 DolphinDB
31
+
32
+ #### 方法一:在浏览器中直接使用构建好的 CDN 版本
33
+
34
+ 保存以下内容到 `example.html` 文件,用浏览器打开即可运行,F12 打开调试控制台可以看到日志
35
+
36
+ ```html
37
+ <!doctype html>
38
+ <html>
39
+ <head>
40
+ <title>DolphinDB</title>
41
+ <meta charset='utf-8' />
42
+ </head>
43
+ <body>
44
+ <script type="module">
45
+ import { DDB } from 'https://cdn.dolphindb.cn/assets/api.js'
46
+
47
+ let ddb = new DDB('ws://127.0.0.1:8848')
48
+
49
+ await ddb.connect()
50
+
51
+ console.log(
52
+ await ddb.eval('1 + 1')
53
+ )
54
+ </script>
55
+ </body>
56
+ </html>
57
+ ```
58
+
59
+ #### 方法二:在项目中安装 npm 包并导入
60
+
61
+ ##### 1. 安装
30
62
 
31
- 1. 在机器上安装最新版的 Node.js 及浏览器。
32
- 2. (可选)使用以下命令创建新项目。如果已有项目,可跳过此步。
63
+ 1.1. 在机器上安装最新版的 Node.js 及浏览器。
64
+ - windows: https://nodejs.org/en/download/current/
65
+ - linux: https://github.com/nodesource/distributions?tab=readme-ov-file#debian-and-ubuntu-based-distributions
66
+ 1.2. (可选)使用以下命令创建新项目。如果已有项目,可跳过此步。
33
67
  ```bash
34
68
  mkdir dolphindb-example
35
69
  cd dolphindb-example
36
70
  npm init --yes
37
71
  ```
38
- 3. 用编辑器打开 package.json 文件,在 `"main": "./index.js"` 下方加入一行 "type": "module", 这样能够启用 ECMAScript modules,在后面代码中可以使用 `import { DDB } from 'dolphindb'` 导入 npm 包。
39
- 4. 在项目中安装 npm 包。
72
+ 1.3. 用编辑器打开 package.json 文件,在 `"main": "./index.js"` 下方加入一行 "type": "module", 这样能够启用 ECMAScript modules,在后面代码中可以使用 `import { DDB } from 'dolphindb'` 导入 npm 包。
73
+ 1.4. 在项目中安装 npm 包。
40
74
  ```bash
41
75
  npm install dolphindb
42
76
  ```
43
77
 
44
- ## 用法
45
- ### 初始化并连接到 DolphinDB
46
- #### NPM
78
+ ##### 2. 使用
47
79
 
48
80
  ```ts
49
- import { DDB } from 'dolphindb'
81
+ // 2.1 在浏览器环境中用下面的方法导入
82
+ import { DDB } from 'dolphindb/browser.js'
83
+
84
+ // 2.1 在 Node.js 环境中用下面的方法导入
85
+ // import { DDB } from 'dolphindb'
50
86
  // 已有的使用 CommonJS 模块的项目的导入方法为 const { DDB } = await import('dolphindb')
51
- // 在浏览器中使用: import { DDB } from 'dolphindb/browser.js'
52
87
 
53
- // 使用 WebSocket URL 初始化连接到 DolphinDB 的实例(不建立实际的网络连接)
88
+ // 2.2 使用 WebSocket URL 初始化连接到 DolphinDB 的实例(不建立实际的网络连接)
54
89
  let ddb = new DDB('ws://127.0.0.1:8848')
55
90
 
56
91
  // 使用 HTTPS 加密
57
92
  // let ddb = new DDB('wss://dolphindb.com')
58
93
 
59
- // 建立到 DolphinDB 的连接(要求 DolphinDB 数据库版本不低于 1.30.16 或 2.00.4)
94
+ // 2.3 建立到 DolphinDB 的连接(要求 DolphinDB 数据库版本不低于 1.30.16 或 2.00.4)
60
95
  await ddb.connect()
61
96
  ```
62
97
 
63
- #### CDN
64
-
65
- ```html
66
- <script type="module">
67
- import { DDB } from 'https://cdn.dolphindb.cn/assets/api.js'
68
-
69
- let ddb = new DDB('ws://127.0.0.1:8848')
70
-
71
- await ddb.connect()
72
- </script>
73
- ```
74
-
75
- 代码补全、函数提示数据:
98
+ #### 代码补全、函数提示数据
76
99
  - https://cdn.dolphindb.cn/assets/docs.zh.json
77
100
  - https://cdn.dolphindb.cn/assets/docs.en.json
78
101
 
79
102
 
80
- #### DDB 选项
103
+ #### DDB 连接选项
81
104
 
82
105
  ```ts
83
106
  let ddb = new DDB('ws://127.0.0.1:8848', {
@@ -486,8 +509,7 @@ export interface StreamingData extends StreamingParams {
486
509
  ### 开发方法
487
510
 
488
511
  ```shell
489
- # 安装最新版的 nodejs
490
- # https://nodejs.org/en/download/current/
512
+ # 安装最新版的 nodejs (见上文)
491
513
 
492
514
  # 安装 pnpm 包管理器
493
515
  corepack enable
package/browser.d.ts CHANGED
@@ -167,8 +167,7 @@ export declare class DdbObj<TValue extends DdbValue = DdbValue> {
167
167
  to_rows<T extends Record<string, any> = Record<string, any>>(): T[];
168
168
  /** 将 dict<string, any> 自动转换为 js object (Record<string, any>) Automatically convert dict<string, any> to js object (Record<string, any>)
169
169
  - options?:
170
- - strip?: `false` 是否将 DdbObj 中的 value 直接提取、剥离出来作为 js object 的 value (丢弃 DdbObj 中的其余信息,只保留 value)
171
- Whether to directly extract and strip the value in DdbObj as the value of js object (discard the rest of the information in DdbObj, only keep the value)
170
+ - strip?: `false` 是否将 dict<string, any> 中的 value 直接提取、剥离出来作为 js object 的 value (丢弃 DdbObj 中的其余信息,只保留 value)
172
171
  - deep?: `false` 是否递归转换
173
172
  Whether to convert recursively
174
173
  */
package/browser.js CHANGED
@@ -10,7 +10,7 @@ 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
12
  import { is_decimal_type, is_decimal_null_value, get_duration_unit } from './shared/utils.js';
13
- import { nulls, DdbChartType, DdbDurationUnit, DdbForm, DdbFunctionType, DdbType, DdbVoidType } from './shared/constants.js';
13
+ import { nulls, DdbChartType, DdbDurationUnit, DdbForm, DdbFunctionType, DdbType, DdbVoidType, dictables } from './shared/constants.js';
14
14
  export * from './shared/constants.js';
15
15
  /** 可以表示所有 DolphinDB 数据库中的数据类型 Can represent data types in all DolphinDB databases */
16
16
  export class DdbObj {
@@ -1255,15 +1255,20 @@ export class DdbObj {
1255
1255
  to_dict({ strip, deep, } = {}) {
1256
1256
  assert(this.form === DdbForm.dict, t('this.form 必须是 DdbForm.dict, 否则不能调用 to_dict 转换为 js object'));
1257
1257
  const [{ value: keys, type: key_type }, { value: values, type: value_type }] = this.value;
1258
- assert(key_type === DdbType.string && value_type === DdbType.any, t('当前只支持自动转换 dict<string, any> 为 js object'));
1258
+ assert(key_type === DdbType.string && dictables.has(value_type), t('当前只支持自动转换 dict<string, any | ...dictables> 为 js object'));
1259
1259
  assert(!(deep && !strip), t('deep = true 时必须设置 strip = true'));
1260
1260
  let obj = {};
1261
1261
  for (let i = 0; i < this.rows; i++) {
1262
- let value = values[i];
1263
- if (deep && value.form === DdbForm.dict)
1264
- obj[keys[i]] = value.to_dict({ strip, deep });
1262
+ const key = keys[i];
1263
+ if (value_type === DdbType.any) {
1264
+ let value = values[i];
1265
+ if (deep && value.form === DdbForm.dict)
1266
+ obj[key] = value.to_dict({ strip, deep });
1267
+ else
1268
+ obj[key] = strip ? value.value : value;
1269
+ }
1265
1270
  else
1266
- obj[keys[i]] = strip ? value.value : value;
1271
+ obj[key] = values[i];
1267
1272
  }
1268
1273
  return obj;
1269
1274
  }
@@ -1275,7 +1280,7 @@ let _grouping = true;
1275
1280
  /** 缓存,为了优化性能,通常 options.decimals 都是不变的 Cache, in order to optimize performance, usually options.decimals are unchanged */
1276
1281
  let _formatter = new Intl.NumberFormat('en-US', { maximumFractionDigits: 20 });
1277
1282
  /** 用来处理时差 To deal with jet lag */
1278
- let _datetime_formatter = new Intl.DateTimeFormat('zh-CN', { dateStyle: 'short', timeStyle: 'medium', timeZone: 'UTC' });
1283
+ let _datetime_formatter = new Intl.DateTimeFormat('zh-CN', { dateStyle: 'short', timeStyle: 'medium', timeZone: 'UTC', hour12: false });
1279
1284
  /** 根据 DdbType 格式化单个元素 (value) 为字符串 Formats a single element (value) as a string according to DdbType, null returns a 'null' string */
1280
1285
  export function format(type, value, le, options = {}) {
1281
1286
  const { nullstr = false, colors = false, quote = false, grouping = true } = options;