dolphindb 2.0.958 → 2.0.960

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/.eslintrc.json CHANGED
@@ -9,6 +9,7 @@
9
9
  "parserOptions": {
10
10
  "ecmaVersion": "latest",
11
11
  "sourceType": "module",
12
+ "project": "./tsconfig.json",
12
13
  "ecmaFeatures": {
13
14
  "jsx": true
14
15
  }
@@ -30,7 +31,6 @@
30
31
  },
31
32
 
32
33
  "rules": {
33
- "semi": "off",
34
34
  "@typescript-eslint/semi": ["error", "never"],
35
35
  "@typescript-eslint/no-extra-semi": "error",
36
36
  "semi-style": ["error", "first"],
@@ -38,8 +38,21 @@
38
38
  // 使用 ===
39
39
  "eqeqeq": "error",
40
40
 
41
+ // 父类尽量返回 this 类型
42
+ "@typescript-eslint/prefer-return-this-type": "error",
43
+
44
+ // 尽量使用 . 访问属性而不是 []
45
+ "@typescript-eslint/dot-notation": "error",
46
+
47
+ // 必须 throw Error
48
+ "@typescript-eslint/no-throw-literal": "error",
49
+
50
+ // ------------ async
51
+ // 返回 Promise 的函数一定要标记为 async 函数
52
+ "@typescript-eslint/promise-function-async": "error",
53
+
41
54
  // 不要 return await promise, 直接 return promise, 除非外面有 try catch
42
- "no-return-await": "error",
55
+ "@typescript-eslint/return-await": "error",
43
56
 
44
57
  // ------------ 括号
45
58
 
@@ -57,7 +70,13 @@
57
70
  // ------------ 空格
58
71
 
59
72
  // { a, b } 这样的对象,大括号里面要有空格
60
- "object-curly-spacing": ["error", "always"],
73
+ "@typescript-eslint/object-curly-spacing": ["error", "always"],
74
+
75
+ // [a, b, c]
76
+ "@typescript-eslint/comma-spacing": "error",
77
+
78
+ // foo()
79
+ "@typescript-eslint/func-call-spacing": "error",
61
80
 
62
81
  // a => { } 中箭头左右两边空格
63
82
  "arrow-spacing": ["error"],
@@ -72,17 +91,32 @@
72
91
  "block-spacing": ["error", "always"],
73
92
 
74
93
  // aaa: 123
75
- "key-spacing": ["error", { "beforeColon": false, "afterColon": true, "mode": "minimum" }],
94
+ "@typescript-eslint/key-spacing": ["error", { "beforeColon": false, "afterColon": true, "mode": "minimum" }],
95
+
96
+ // aaa: string
97
+ "@typescript-eslint/type-annotation-spacing": ["error"],
76
98
 
77
99
  // if ()
78
- "keyword-spacing": ["error", { "before": true, "after": true }],
100
+ "@typescript-eslint/keyword-spacing": ["error", { "before": true, "after": true }],
101
+
102
+ // if (1) { }
103
+ "@typescript-eslint/space-before-blocks": "error",
104
+
105
+ // case 1: ...
106
+ "switch-colon-spacing": "error",
79
107
 
80
108
  // a + b
81
- "space-infix-ops": ["error"],
109
+ "@typescript-eslint/space-infix-ops": "error",
110
+
111
+ // 不允许使用 tab
112
+ "no-tabs": "error",
82
113
 
83
114
  // 使用 \n 换行
84
115
  "linebreak-style": ["error", "unix"],
85
116
 
117
+ // 文件以 \n 结尾
118
+ "eol-last": ["error", "always"],
119
+
86
120
  // ------------ 引号
87
121
 
88
122
  // 用单引号
@@ -92,6 +126,23 @@
92
126
  "quotes": ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": false }],
93
127
 
94
128
  // 不要冗余的引号包裹属性
95
- "quote-props": ["error", "as-needed", { "keywords": false, "unnecessary": true }]
129
+ "quote-props": ["error", "as-needed", { "keywords": false, "unnecessary": true }],
130
+
131
+ // ------------ 其它
132
+ // 单行类型声明用 `,` 分割,多行类型声明结尾不要加分号
133
+ "@typescript-eslint/member-delimiter-style": ["error", {
134
+ "multiline": {
135
+ "delimiter": "none",
136
+ "requireLast": false
137
+ },
138
+ "singleline": {
139
+ "delimiter": "comma",
140
+ "requireLast": false
141
+ }
142
+ }],
143
+
144
+ "@typescript-eslint/prefer-includes": "error",
145
+
146
+ "@typescript-eslint/prefer-regexp-exec": "error"
96
147
  }
97
148
  }
package/README.md CHANGED
@@ -46,7 +46,7 @@ npm install dolphindb
46
46
  ```ts
47
47
  import { DDB } from 'dolphindb'
48
48
  // The import method for existing projects using CommonJS modules is const { DDB } = require('dolphindb')
49
- // Use in browser: import { DDB } form 'dolphindb/browser.js'
49
+ // Use in browser: import { DDB } from 'dolphindb/browser.js'
50
50
 
51
51
  // Initially connect to an instance of DolphinDB using the WebSocket URL (without establishing an actual network connection)
52
52
  let ddb = new DDB('ws://127.0.0.1:8848')
@@ -451,3 +451,41 @@ export interface StreamingData extends StreamingParams {
451
451
  error?: Error
452
452
  }
453
453
  ```
454
+
455
+
456
+ ### Development
457
+ ```shell
458
+ # Install the latest version of nodejs
459
+ # https://nodejs.org/en/download/current/
460
+
461
+ # Install the pnpm package manager
462
+ corepack enable
463
+ corepack prepare pnpm@latest --activate
464
+
465
+ git clone https://github.com/dolphindb/api-javascript.git
466
+
467
+ cd api-javascript
468
+
469
+ # Install project dependencies
470
+ pnpm install
471
+
472
+ # Copy .vscode/settings.template.json to .vscode/settings.json
473
+ cp .vscode/settings.template.json .vscode/settings.json
474
+
475
+ # Refer to scripts in package.json
476
+
477
+ # Construct
478
+ pnpm run build
479
+
480
+ #lint
481
+ pnpm run lint
482
+
483
+ # test
484
+ pnpm run test
485
+
486
+ # scan entries
487
+ pnpm run scan
488
+ # Manually complete untranslated entries
489
+ # Run the scan again to update the dictionary file dict.json
490
+ pnpm run scan
491
+ ```
package/README.zh.md CHANGED
@@ -46,7 +46,7 @@ npm install dolphindb
46
46
  ```ts
47
47
  import { DDB } from 'dolphindb'
48
48
  // 已有的使用 CommonJS 模块的项目的导入方法为 const { DDB } = require('dolphindb')
49
- // 在浏览器中使用: import { DDB } form 'dolphindb/browser.js'
49
+ // 在浏览器中使用: import { DDB } from 'dolphindb/browser.js'
50
50
 
51
51
  // 使用 WebSocket URL 初始化连接到 DolphinDB 的实例(不建立实际的网络连接)
52
52
  let ddb = new DDB('ws://127.0.0.1:8848')
@@ -448,3 +448,41 @@ export interface StreamingData extends StreamingParams {
448
448
  error?: Error
449
449
  }
450
450
  ```
451
+
452
+
453
+ ### 开发
454
+ ```shell
455
+ # 安装最新版的 nodejs
456
+ # https://nodejs.org/en/download/current/
457
+
458
+ # 安装 pnpm 包管理器
459
+ corepack enable
460
+ corepack prepare pnpm@latest --activate
461
+
462
+ git clone https://github.com/dolphindb/api-javascript.git
463
+
464
+ cd api-javascript
465
+
466
+ # 安装项目依赖
467
+ pnpm install
468
+
469
+ # 将 .vscode/settings.template.json 复制为 .vscode/settings.json
470
+ cp .vscode/settings.template.json .vscode/settings.json
471
+
472
+ # 参考 package.json 中的 scripts
473
+
474
+ # 构建
475
+ pnpm run build
476
+
477
+ # lint
478
+ pnpm run lint
479
+
480
+ # 测试
481
+ pnpm run test
482
+
483
+ # 扫描词条
484
+ pnpm run scan
485
+ # 手动补全未翻译词条
486
+ # 再次运行扫描以更新词典文件 dict.json
487
+ pnpm run scan
488
+ ```
package/browser.d.ts CHANGED
@@ -108,6 +108,7 @@ export interface DdbDecimal64Value {
108
108
  /** int64, 空值为 null empty value is null */
109
109
  data: bigint | null;
110
110
  }
111
+ export type DdbDurationVectorValue = DdbDurationValue[];
111
112
  export interface DdbDecimal32VectorValue {
112
113
  scale: number;
113
114
  data: Int32Array;
@@ -176,10 +177,10 @@ export type DdbScalarValue = null | boolean | number | bigint | string | Uint8Ar
176
177
  number
177
178
  ] | // complex, point
178
179
  DdbFunctionDefValue | DdbDurationValue | DdbDecimal32Value | DdbDecimal64Value;
179
- export type DdbVectorValue = Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | string[] | // string[]
180
+ export type DdbVectorValue = null | Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | string[] | // string[]
180
181
  Uint8Array[] | // blob
181
182
  DdbObj[] | // any
182
- DdbSymbolExtendedValue | DdbArrayVectorValue | DdbDecimal32VectorValue | DdbDecimal64VectorValue;
183
+ DdbSymbolExtendedValue | DdbArrayVectorValue | DdbDecimal32VectorValue | DdbDecimal64VectorValue | DdbDurationVectorValue;
183
184
  export type DdbValue = DdbScalarValue | DdbVectorValue | DdbMatrixValue | DdbDictValue | DdbChartValue;
184
185
  export type DdbStringObj = DdbObj<string>;
185
186
  export type DdbVectorObj<TValue extends DdbVectorValue = DdbVectorValue> = DdbObj<TValue>;
package/browser.js CHANGED
@@ -612,6 +612,8 @@ class DdbObj {
612
612
  /** 有可能没有字节对齐,不能直接使用原有 message 的 arraybuffer, 统一复制出来,让原有 arraybuffer 被回收掉比较好 */
613
613
  static parse_vector_items(buf, le, type, length) {
614
614
  switch (type) {
615
+ case DdbType.void:
616
+ return [0, null];
615
617
  case DdbType.bool:
616
618
  case DdbType.char:
617
619
  return [
@@ -777,15 +779,31 @@ class DdbObj {
777
779
  }
778
780
  ];
779
781
  }
780
- // case DdbType.duration: -> 实际会返回一个 any vector
782
+ // 以下情况时, DdbType.duration 实际会返回一个 any vector
781
783
  // [2y, 1M, 3d, 7H, 11m, 12s, 15ms, 16us, 17ns]
782
784
  // <Buffer 19 01 type = any, form = vector
783
785
  // 09 00 00 00 01 00 00 00 rows = 9, cols = 1
784
786
  // 24 00 type = DdbType.duration, form = scalar
785
787
  // 02 00 00 00 09 00 00 00
786
788
  // 24 00 01 00 00 00 08 00 00 00 24 00 03 00 00 00 06 00 00 00 24 00 07 00 00 00 05 00 00 00 ... 50 more bytes>
789
+ // 其余情况 (目前仅 pair) 下, 会返回特殊的 duration 序列化
790
+ // 4 bytes data 4 bytes unit
791
+ // 01 00 00 00 data: 1
792
+ // 01 00 00 00 unit: 1
793
+ // 02 00 00 00 data: 2
794
+ // 02 00 00 00 unit: 2
795
+ case DdbType.duration: {
796
+ const dv = new DataView(buf.buffer, buf.byteOffset);
797
+ let durations = [];
798
+ for (let i = 0; i < length; i++)
799
+ durations.push({
800
+ data: dv.getInt32(0 + 8 * i, le),
801
+ unit: dv.getInt32(4 + 8 * i, le)
802
+ });
803
+ return [8 * length, durations];
804
+ }
787
805
  default:
788
- return [0, buf];
806
+ throw new Error(t('vector<{{type}}> 暂时不支持解析', { type: String(DdbType[type] || type) }));
789
807
  }
790
808
  }
791
809
  pack() {
@@ -972,6 +990,8 @@ class DdbObj {
972
990
  }
973
991
  static pack_vector_body(value, type, length) {
974
992
  switch (type) {
993
+ case DdbType.void:
994
+ return [];
975
995
  case DdbType.bool:
976
996
  return [value];
977
997
  case DdbType.char:
@@ -1141,6 +1161,8 @@ class DdbObj {
1141
1161
  items[i] = base[data[i]].quote('single');
1142
1162
  return format_array(items, data.length > limit);
1143
1163
  }
1164
+ case DdbType.void:
1165
+ return format(this.type, this.value, this.le, options);
1144
1166
  case DdbType.uuid:
1145
1167
  case DdbType.int128:
1146
1168
  case DdbType.ipaddr: {
@@ -1573,6 +1595,8 @@ export function formati(obj, index, options = {}) {
1573
1595
  const { base, data } = obj.value;
1574
1596
  return format(DdbType.string, base[data[index]], obj.le, options);
1575
1597
  }
1598
+ case DdbType.void:
1599
+ return format(obj.type, obj.value, obj.le, options);
1576
1600
  case DdbType.uuid:
1577
1601
  case DdbType.int128:
1578
1602
  case DdbType.ipaddr:
@@ -2268,7 +2292,7 @@ class DDB {
2268
2292
  this.streaming = options.streaming;
2269
2293
  }
2270
2294
  on_message(buffer, websocket) {
2271
- throw t('这是在调用 this.rpc 之前默认的 on_message, 不应该被调用到,除非建立连接后 server 先推送了 message');
2295
+ throw new Error(t('这是在调用 this.rpc 之前默认的 on_message, 不应该被调用到,除非建立连接后 server 先推送了 message'));
2272
2296
  }
2273
2297
  on_error() {
2274
2298
  // 这里的实现一定会被 connect, rpc 中的实现覆盖