dolphindb 3.0.2 → 3.0.20

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
@@ -516,8 +516,7 @@ export interface StreamingData extends StreamingParams {
516
516
  # https://nodejs.org/en/download/current/
517
517
 
518
518
  # Install the pnpm package manager
519
- corepack enable
520
- corepack prepare pnpm@latest --activate
519
+ npm install -g pnpm
521
520
 
522
521
  git clone https://github.com/dolphindb/api-javascript.git
523
522
 
package/README.zh.md CHANGED
@@ -512,8 +512,7 @@ export interface StreamingData extends StreamingParams {
512
512
  # 安装最新版的 nodejs (见上文)
513
513
 
514
514
  # 安装 pnpm 包管理器
515
- corepack enable
516
- corepack prepare pnpm@latest --activate
515
+ npm install -g pnpm
517
516
 
518
517
  git clone https://github.com/dolphindb/api-javascript.git
519
518
 
package/browser.d.ts CHANGED
@@ -1,11 +1,117 @@
1
1
  import 'xshell/prototype.browser.js';
2
2
  import { Lock } from 'xshell/utils.browser.js';
3
3
  import { type WebSocketConnectionError } from 'xshell/net.browser.js';
4
- import { type DdbDecimal128Value, type DdbDecimal128VectorValue } from './data-types/decimal-128.js';
5
- import type { BigInt128Array } from './shared/bigint-128-array.js';
6
- import { DdbChartType, DdbDurationUnit, DdbForm, DdbFunctionType, DdbType, DdbVoidType } from './shared/constants.js';
7
- export * from './shared/constants.js';
8
- export type { DdbDecimal128Value, DdbDecimal128VectorValue } from './data-types/decimal-128.js';
4
+ export declare const nulls: {
5
+ readonly int8: -128;
6
+ readonly int16: -32768;
7
+ readonly int32: -2147483648;
8
+ readonly int64: -9223372036854775808n;
9
+ readonly int128: -170141183460469231731687303715884105728n;
10
+ readonly float32: -3.4028234663852886e+38;
11
+ /** -Number.MAX_VALUE */
12
+ readonly double: number;
13
+ readonly bytes16: Uint8Array;
14
+ };
15
+ export declare enum DdbForm {
16
+ scalar = 0,
17
+ vector = 1,
18
+ pair = 2,
19
+ matrix = 3,
20
+ set = 4,
21
+ dict = 5,
22
+ table = 6,
23
+ chart = 7,
24
+ /** 节点内部通信可能会使用,调用函数执行脚本一般不会返回这种类型 */
25
+ chunk = 8,
26
+ /** sysobj */
27
+ object = 9
28
+ }
29
+ /** DolphinDB DataType
30
+ 对应的 array vector 类型为 64 + 基本类型
31
+ 对应的 extended 类型为 128 + 基本类型 */
32
+ export declare enum DdbType {
33
+ void = 0,
34
+ bool = 1,
35
+ char = 2,
36
+ short = 3,
37
+ int = 4,
38
+ long = 5,
39
+ date = 6,
40
+ month = 7,
41
+ time = 8,
42
+ minute = 9,
43
+ second = 10,
44
+ datetime = 11,
45
+ timestamp = 12,
46
+ nanotime = 13,
47
+ nanotimestamp = 14,
48
+ float = 15,
49
+ double = 16,
50
+ symbol = 17,
51
+ string = 18,
52
+ uuid = 19,
53
+ functiondef = 20,
54
+ handle = 21,
55
+ code = 22,
56
+ datasource = 23,
57
+ resource = 24,
58
+ any = 25,
59
+ compressed = 26,
60
+ dict = 27,
61
+ datehour = 28,
62
+ ipaddr = 30,
63
+ int128 = 31,
64
+ blob = 32,
65
+ complex = 34,
66
+ point = 35,
67
+ duration = 36,
68
+ decimal32 = 37,
69
+ decimal64 = 38,
70
+ decimal128 = 39,
71
+ object = 40,
72
+ pynone = 41,
73
+ symbol_extended = 145
74
+ }
75
+ export declare enum DdbFunctionType {
76
+ SystemFunc = 0,
77
+ SystemProc = 1,
78
+ OperatorFunc = 2,
79
+ UserDefinedFunc = 3,
80
+ PartialFunc = 4,
81
+ DynamicFunc = 5,
82
+ PiecewiseFunc = 6,
83
+ JitFunc = 7,
84
+ JitPartialFunc = 8
85
+ }
86
+ export declare enum DdbDurationUnit {
87
+ ns = 0,
88
+ us = 1,
89
+ ms = 2,
90
+ s = 3,
91
+ m = 4,
92
+ H = 5,
93
+ d = 6,
94
+ w = 7,
95
+ M = 8,
96
+ y = 9,
97
+ B = 10
98
+ }
99
+ export declare enum DdbChartType {
100
+ area = 0,
101
+ bar = 1,
102
+ column = 2,
103
+ histogram = 3,
104
+ line = 4,
105
+ pie = 5,
106
+ scatter = 6,
107
+ trend = 7,
108
+ kline = 8
109
+ }
110
+ export declare enum DdbVoidType {
111
+ undefined = 0,
112
+ null = 1,
113
+ default = 2
114
+ }
9
115
  export interface DdbFunctionDefValue {
10
116
  type: DdbFunctionType;
11
117
  name: string;
@@ -16,17 +122,23 @@ export interface DdbDurationValue {
16
122
  data: number;
17
123
  }
18
124
  export interface DdbDecimal32Value {
19
- /** int32, data 需要除以 10^scale 得到原值 data needs to be divided by 10^scale to get the original value */
125
+ /** int32, data 需要除以 10^scale 得到原值 */
20
126
  scale: number;
21
127
  /** int32, 空值为 null ddb null is js null */
22
128
  data: number | null;
23
129
  }
24
130
  export interface DdbDecimal64Value {
25
- /** int32, data 需要除以 10^scale 得到原值 data needs to be divided by 10^scale to get the original value */
131
+ /** int32, data 需要除以 10^scale 得到原值 */
26
132
  scale: number;
27
133
  /** int64, 空值为 null empty value is null */
28
134
  data: bigint | null;
29
135
  }
136
+ export interface DdbDecimal128Value {
137
+ /** int32, data 需要除以 10^scale 得到原值 */
138
+ scale: number;
139
+ /** int128, 空值为 null empty value is null */
140
+ data: bigint | null;
141
+ }
30
142
  export interface DdbDecimal32VectorValue {
31
143
  scale: number;
32
144
  data: Int32Array;
@@ -35,6 +147,11 @@ export interface DdbDecimal64VectorValue {
35
147
  scale: number;
36
148
  data: BigInt64Array;
37
149
  }
150
+ export interface DdbDecimal128VectorValue {
151
+ scale: number;
152
+ data: BigInt128Array;
153
+ }
154
+ export type DdbDecimalVectorValue = DdbDecimal32VectorValue | DdbDecimal64VectorValue | DdbDecimal128VectorValue;
38
155
  export type DdbDurationVectorValue = DdbDurationValue[];
39
156
  export interface DdbSymbolExtendedValue {
40
157
  base_id: number;
@@ -50,9 +167,10 @@ export interface DdbArrayVectorBlock {
50
167
  export type DdbArrayVectorValue = DdbArrayVectorBlock[] & /* decimal 数据会有这个属性 */ {
51
168
  scale?: number;
52
169
  };
170
+ export declare const dictables: Set<DdbType>;
53
171
  export interface DdbMatrixValue {
54
- rows: DdbVectorObj;
55
- cols: DdbVectorObj;
172
+ rows: DdbVectorObj | null;
173
+ cols: DdbVectorObj | null;
56
174
  data: DdbVectorValue;
57
175
  }
58
176
  export type DdbDictValue = [DdbVectorObj, DdbVectorObj];
@@ -98,6 +216,32 @@ export type DdbTableObj<TColumns extends DdbVectorObj[] = DdbVectorObj[]> = DdbO
98
216
  export type DdbDictObj<TKeys extends DdbVectorObj = DdbVectorObj, TValues extends DdbVectorObj = DdbVectorObj> = DdbObj<[TKeys, TValues]>;
99
217
  export type DdbMatrixObj<TValue extends DdbMatrixValue = DdbMatrixValue> = DdbObj<TValue>;
100
218
  export type DdbChartObj = DdbObj<DdbChartValue>;
219
+ /** DdbObj.data() 返回的表格对象 */
220
+ export interface DdbTableData<TRow = any> {
221
+ /** 表名 */
222
+ name: string;
223
+ /** 每一列的名称 */
224
+ columns: string[];
225
+ /** 每一列的原始 ddb 数据类型 */
226
+ types: DdbType[];
227
+ /** 表格数据,每一行的对象组成的数组 */
228
+ data: TRow[];
229
+ }
230
+ /** DdbObj.data() 返回的矩阵对象 */
231
+ export interface DdbMatrixData {
232
+ /** 原始数据类型 */
233
+ type: DdbType;
234
+ /** 行数 */
235
+ nrows: number;
236
+ /** 列数 */
237
+ ncolumns: number;
238
+ /** 行名称 */
239
+ rows?: any[];
240
+ /** 列名称 */
241
+ columns?: any[];
242
+ /** 数据, data[0][1] 为第 0 行第 1 列数据 */
243
+ data: any[][];
244
+ }
101
245
  /** 可以表示所有 DolphinDB 数据库中的数据类型 Can represent data types in all DolphinDB databases */
102
246
  export declare class DdbObj<TValue extends DdbValue = DdbValue> {
103
247
  static dec: TextDecoder;
@@ -118,15 +262,13 @@ export declare class DdbObj<TValue extends DdbValue = DdbValue> {
118
262
  length: number;
119
263
  /** table name / column name */
120
264
  name?: string;
121
- /**
122
- 最低维、第 1 维
265
+ /** 最低维、第 1 维
123
266
  - vector: rows = n, cols = 1
124
267
  - pair: rows = 2, cols = 1
125
268
  - matrix: rows = n, cols = m
126
269
  - set: 同 vector
127
270
  - dict: 包含 keys, values 向量
128
- - table: 同 matrix
129
- */
271
+ - table: 同 matrix */
130
272
  rows?: number;
131
273
  /** 第 2 维 */
132
274
  cols?: number;
@@ -142,8 +284,7 @@ export declare class DdbObj<TValue extends DdbValue = DdbValue> {
142
284
  static parse(buf: Uint8Array, le: boolean): DdbObj<DdbValue>;
143
285
  static parse_scalar(buf: Uint8Array, le: boolean, type: DdbType): [number, DdbScalarValue];
144
286
  /** parse: rows, cols, items
145
- 返回的 ddbobj.length 不包括 vector 的 type 和 form
146
- */
287
+ 返回的 ddbobj.length 不包括 vector 的 type 和 form */
147
288
  static parse_vector(buf: Uint8Array, le: boolean, type: DdbType): DdbVectorObj;
148
289
  /** 有可能没有字节对齐,不能直接使用原有 message 的 arraybuffer, 统一复制出来,让原有 arraybuffer 被回收掉比较好 */
149
290
  static parse_vector_items(buf: Uint8Array, le: boolean, type: DdbType, length: number): [
@@ -152,25 +293,36 @@ export declare class DdbObj<TValue extends DdbValue = DdbValue> {
152
293
  ];
153
294
  pack(): Uint8Array;
154
295
  static pack_vector_body(value: DdbVectorValue, type: DdbType, length: number): ArrayBufferView[];
296
+ /** 将 DdbObj 转换为 js 原生数据类型
297
+ - 标量对应 number, bigint 或者字符串
298
+ - 数组对应 js 原生数组
299
+ - 表格对应 DdbTableData
300
+ - 矩阵对应 DdbMatrixData
301
+ - 字典对应普通的 js 对象 Record<string, any>
302
+ - 图对应 DdbChartValue */
303
+ data<TResult extends any[]>(this: DdbVectorObj): TResult;
304
+ data<TResult = any>(this: DdbObj): TResult;
155
305
  toString(options?: InspectOptions): string;
156
306
  inspect_type(): string;
157
307
  /** 自动转换 js string, boolean 为 DdbObj */
158
308
  static to_ddbobj(value: DdbObj | string | boolean): DdbObj;
159
309
  /** 转换 js 数组为 DdbObj[] */
160
310
  static to_ddbobjs(values: (DdbObj | string | boolean)[]): DdbObj<DdbValue>[];
311
+ /** @deprecated 用 data() */
161
312
  to_cols(): {
162
313
  title: string;
163
314
  dataIndex: string;
164
315
  render: (value: any) => string;
165
316
  }[];
166
- /** 将 table 转换为 rows,空值转换为 null */
317
+ /** 将 table 转换为 rows,空值转换为 null
318
+ @deprecated 用 data() */
167
319
  to_rows<T extends Record<string, any> = Record<string, any>>(): T[];
168
320
  /** 将 dict<string, any> 自动转换为 js object (Record<string, any>) Automatically convert dict<string, any> to js object (Record<string, any>)
321
+ @deprecated 用 data()
169
322
  - options?:
170
323
  - strip?: `false` 是否将 dict<string, any> 中的 value 直接提取、剥离出来作为 js object 的 value (丢弃 DdbObj 中的其余信息,只保留 value)
171
324
  - deep?: `false` 是否递归转换
172
- Whether to convert recursively
173
- */
325
+ Whether to convert recursively */
174
326
  to_dict<T extends Record<string, DdbObj> = Record<string, DdbObj>>(): T;
175
327
  to_dict<T extends Record<string, any> = Record<string, any>>(options: {
176
328
  strip: true;
@@ -180,6 +332,11 @@ export declare class DdbObj<TValue extends DdbValue = DdbValue> {
180
332
  deep?: boolean;
181
333
  }): T;
182
334
  }
335
+ /** 根据 DdbType 获取其名称,array vector type 自动在后面加上 [] */
336
+ export declare function get_type_name(type: DdbType): string;
337
+ export declare function is_decimal_type(type: DdbType): boolean;
338
+ export declare function is_decimal_null_value(type: DdbType, value: number | bigint): boolean;
339
+ export declare function get_duration_unit(code: number): string;
183
340
  export interface InspectOptions {
184
341
  /** `false` */
185
342
  colors?: boolean;
@@ -187,7 +344,7 @@ export interface InspectOptions {
187
344
  decimals?: number;
188
345
  /** `false` 决定 null 值如何返回. nullstr ? 'null' : '' */
189
346
  nullstr?: boolean;
190
- /** `false` 决定 string, symbol, char 类型是否加引号 */
347
+ /** `在 format 中默认为 false,在 toString 中默认为 true` 决定 string, symbol, char 类型是否加引号 */
191
348
  quote?: boolean;
192
349
  /** `true` 决定格式化后的数据是否有千分位 */
193
350
  grouping?: boolean;
@@ -196,6 +353,9 @@ export interface InspectOptions {
196
353
  export declare function format(type: DdbType, value: DdbValue, le: boolean, options?: InspectOptions): string;
197
354
  /** 格式化向量、集合中的第 index 项为字符串,空值返回 'null' 字符串 formatted vector, the index-th item in the collection is a string, a null value returns a 'null' string */
198
355
  export declare function formati(obj: DdbVectorObj, index: number, options?: InspectOptions): string;
356
+ export declare function convert(type: DdbType, value: DdbValue, le: boolean): string | number | bigint | boolean | Uint8Array | DdbFunctionDefValue | DdbDurationValue | DdbDecimal32Value | DdbDecimal64Value | DdbDecimal32VectorValue | Int32Array | DdbDecimal64VectorValue | BigInt64Array | DdbDecimal128VectorValue | BigInt128Array | DdbSymbolExtendedValue | string[] | Int8Array | Int16Array | Float32Array | Float64Array | DdbArrayVectorValue | DdbMatrixValue | Uint8Array[] | DdbObj<DdbValue>[] | DdbDurationVectorValue | DdbChartValue | number[];
357
+ /** 转换一个向量到 js 原生数组 */
358
+ export declare function converts(type: DdbType, value: DdbVectorValue, rows: number, le: boolean): any[];
199
359
  export declare class DdbVoid extends DdbObj<undefined> {
200
360
  constructor(value?: DdbVoidType);
201
361
  }
@@ -370,15 +530,17 @@ export interface StreamingMessage extends StreamingParams {
370
530
  error?: Error;
371
531
  }
372
532
  export declare const winsize: 100000;
533
+ export interface DdbEvalOptions {
534
+ urgent?: boolean;
535
+ listener?: DdbMessageListener;
536
+ parse_object?: boolean;
537
+ }
373
538
  type DdbRpcType = 'script' | 'function' | 'variable' | 'connect';
374
- export interface DdbRpcOptions {
539
+ export interface DdbRpcOptions extends DdbEvalOptions {
375
540
  script?: string;
376
541
  func?: string;
377
542
  args?: (DdbObj | string | boolean)[];
378
543
  vars?: string[];
379
- urgent?: boolean;
380
- listener?: DdbMessageListener;
381
- parse_object?: boolean;
382
544
  skip_connection_check?: boolean;
383
545
  on_more_messages?: (buffer: Uint8Array) => void;
384
546
  }
@@ -410,6 +572,15 @@ export interface DdbOptions {
410
572
  sql?: SqlStandard;
411
573
  streaming?: StreamingParams;
412
574
  verbose?: boolean;
575
+ proxy?: string;
576
+ }
577
+ export interface DdbCallOptions extends DdbEvalOptions {
578
+ node?: string;
579
+ nodes?: string[];
580
+ func_type?: DdbFunctionType;
581
+ add_node_alias?: boolean;
582
+ skip_connection_check?: boolean;
583
+ on_more_messages?: DdbRpcOptions['on_more_messages'];
413
584
  }
414
585
  export declare class DDB {
415
586
  /** 当前的 session id (http 或 tcp) */
@@ -418,8 +589,7 @@ export declare class DDB {
418
589
  dec: TextDecoder;
419
590
  enc: TextEncoder;
420
591
  /** DolphinDB WebSocket URL
421
- e.g. `ws://127.0.0.1:8848/`, `wss://dolphindb.com`
422
- */
592
+ e.g. `ws://127.0.0.1:8848/`, `wss://dolphindb.com` */
423
593
  url: string;
424
594
  /** 为所有 websocket 操作加锁,包括设置 this.on_message, this.on_error, websocket.send */
425
595
  lwebsocket: Lock<WebSocket>;
@@ -445,7 +615,6 @@ export declare class DDB {
445
615
  print_object_buffer: boolean;
446
616
  print_message: boolean;
447
617
  parse_object: boolean;
448
- pnode_run_defined: boolean;
449
618
  /** 在 websocket 收到的第一个 error 时,
450
619
  在 connect_websocket 的 on_error 回调中构造 DdbConnectionError 并保存到 DDB 对象上,
451
620
  这个 error 的错误信息最准确 */
@@ -456,6 +625,8 @@ export declare class DDB {
456
625
  pconnect: Promise<void>;
457
626
  /** 首次定义 pnode_run 的 promise,保证并发调用 rpc 时只定义一次 pnode_run */
458
627
  ppnode_run: Promise<DdbVoid>;
628
+ /** 首次定义 invoke 的 promise,保证并发调用 rpc 时只定义一次 invoke */
629
+ pinvoke: Promise<DdbVoid>;
459
630
  get connected(): boolean;
460
631
  /**
461
632
  使用 WebSocket URL 初始化连接到 DolphinDB 的实例(不建立实际的网络连接)
@@ -547,13 +718,8 @@ export declare class DDB {
547
718
  不做解析,以便后续转发、序列化
548
719
  Set parse_object during this rpc, and restore the original after the end.
549
720
  When it is false, the returned DdbObj only contains buffer and le without parsing,
550
- so as to facilitate subsequent forwarding and serialization
551
- */
552
- eval<T extends DdbObj>(script: string, { urgent, listener, parse_object, }?: {
553
- urgent?: boolean;
554
- listener?: DdbMessageListener;
555
- parse_object?: boolean;
556
- }): Promise<T>;
721
+ so as to facilitate subsequent forwarding and serialization */
722
+ eval<T extends DdbObj>(script: string, { urgent, listener, parse_object, }?: DdbEvalOptions): Promise<T>;
557
723
  /** call function through websocket (function command)
558
724
  - func: 函数名 function name
559
725
  - args?: `[ ]` 调用参数 (传入的原生 string 和 boolean 会被自动转换为 DdbObj<string> 和 DdbObj<boolean>)
@@ -580,17 +746,24 @@ export declare class DDB {
580
746
  将这个 flag 设为 true 跳过连接状态检查
581
747
  (internal use) When await ddb.connect() establishes a connection for the first time, you cannot call await this.connect() again to ensure the connection status, which will lead to circular dependencies.
582
748
  Set this flag to true to skip connection status checks */
583
- call<TResult extends DdbObj>(func: string, args?: (DdbObj | string | boolean)[], { urgent, node, nodes, func_type, add_node_alias, listener, parse_object, skip_connection_check, on_more_messages }?: {
584
- urgent?: boolean;
585
- node?: string;
586
- nodes?: string[];
587
- func_type?: DdbFunctionType;
588
- add_node_alias?: boolean;
589
- listener?: DdbMessageListener;
590
- parse_object?: boolean;
591
- skip_connection_check?: boolean;
592
- on_more_messages?: DdbRpcOptions['on_more_messages'];
593
- }): Promise<TResult>;
749
+ call<TResult extends DdbObj>(func: string, args?: (DdbObj | string | boolean)[], { urgent, node, nodes, func_type, add_node_alias, listener, parse_object, skip_connection_check, on_more_messages }?: DdbCallOptions): Promise<TResult>;
750
+ /** 调用 dolphindb 函数,传入 js 原生数组作为参数,返回 js 原生对象或值(调用 DdbObj.data() 后的结果)
751
+ - func: 函数名
752
+ - args?: `[ ]` 调用参数,可以是 js 原生数组
753
+ - options?: 调用选项
754
+ - urgent?: 紧急 flag。使用 urgent worker 执行,防止被其它作业阻塞
755
+ - node?: 设置结点 alias 时发送到集群中对应的结点执行 (使用 DolphinDB 中的 rpc 方法)
756
+ - nodes?: 设置多个结点 alias 时发送到集群中对应的多个结点执行 (使用 DolphinDB 中的 pnodeRun 方法)
757
+ - func_type?: 设置 node 参数且参数数组为空时必传,需指定函数类型,其它情况下不传
758
+ - add_node_alias?: 设置 nodes 参数时选传,其它情况不传
759
+ - listener?: 处理本次 rpc 期间的消息 (DdbMessage) */
760
+ invoke<TResult = any>(func: string, args?: any[], options?: DdbCallOptions): Promise<TResult>;
761
+ /** 执行 dolphindb 脚本,返回 js 原生对象或值(调用 DdbObj.data() 后的结果)
762
+ - script?: 执行的脚本
763
+ - options?: 执行选项
764
+ - urgent?: 紧急 flag,确保提交的脚本使用 urgent worker 处理,防止被其它作业阻塞
765
+ - listener?: 处理本次 rpc 期间的消息 (DdbMessage) */
766
+ execute<TResult = any>(script: string, options?: DdbEvalOptions): Promise<TResult>;
594
767
  /** upload variable through websocket (variable command) */
595
768
  upload(
596
769
  /** 上传的变量名 Uploaded variables' name */
@@ -623,3 +796,30 @@ export interface DdbErrorMessage {
623
796
  data: DdbDatabaseError;
624
797
  }
625
798
  export type DdbMessage = DdbPrintMessage | DdbObjectMessage | DdbErrorMessage;
799
+ export declare class BigInt128Array {
800
+ static of(...items: bigint[]): BigInt128Array;
801
+ static from(arrayLike: ArrayLike<bigint>): BigInt128Array;
802
+ static from<U>(arrayLike: ArrayLike<U>, mapfn: (v: U, k: number) => bigint, thisArg?: any): BigInt128Array;
803
+ readonly BYTES_PER_ELEMENT: number;
804
+ readonly buffer: ArrayBufferLike;
805
+ readonly byteLength: number;
806
+ readonly byteOffset: number;
807
+ constructor(length?: number);
808
+ constructor(array: Iterable<bigint>);
809
+ constructor(buffer: ArrayBufferLike, byteOffset?: number, length?: number);
810
+ get length(): number;
811
+ set(array: ArrayLike<bigint>, offset?: number): void;
812
+ at(index: number): bigint;
813
+ subarray(begin?: number, end?: number): BigInt128Array;
814
+ [Symbol.iterator](): {
815
+ next(): {
816
+ value: bigint;
817
+ done: boolean;
818
+ } | {
819
+ done: boolean;
820
+ value?: undefined;
821
+ };
822
+ };
823
+ toString(): string;
824
+ }
825
+ export {};