dolphindb 3.0.224 → 3.0.227

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/browser.d.ts CHANGED
@@ -1,165 +1,18 @@
1
- import { type Dayjs } from 'dayjs';
1
+ import type { Dayjs } from 'dayjs';
2
2
  import 'xshell/prototype.browser.js';
3
3
  import { Lock } from 'xshell/utils.browser.js';
4
4
  import { type WebSocketConnectionError } from 'xshell/net.browser.js';
5
- export declare const nulls: {
6
- readonly int8: -128;
7
- readonly int16: -32768;
8
- readonly int32: -2147483648;
9
- readonly int64: -9223372036854775808n;
10
- readonly int128: -170141183460469231731687303715884105728n;
11
- readonly float32: -3.4028234663852886e+38;
12
- /** -Number.MAX_VALUE */
13
- readonly double: number;
14
- readonly bytes16: Uint8Array<ArrayBuffer>;
15
- };
16
- export declare enum DdbForm {
17
- scalar = 0,
18
- vector = 1,
19
- pair = 2,
20
- matrix = 3,
21
- set = 4,
22
- dict = 5,
23
- table = 6,
24
- chart = 7,
25
- /** 节点内部通信可能会使用,调用函数执行脚本一般不会返回这种类型 */
26
- chunk = 8,
27
- /** sysobj */
28
- object = 9,
29
- tensor = 10
30
- }
31
- /** DolphinDB DataType
32
- 对应的 array vector 类型为 64 + 基本类型
33
- 对应的 extended 类型为 128 + 基本类型 */
34
- export declare enum DdbType {
35
- void = 0,
36
- bool = 1,
37
- char = 2,
38
- short = 3,
39
- int = 4,
40
- long = 5,
41
- date = 6,
42
- month = 7,
43
- time = 8,
44
- minute = 9,
45
- second = 10,
46
- datetime = 11,
47
- timestamp = 12,
48
- nanotime = 13,
49
- nanotimestamp = 14,
50
- float = 15,
51
- double = 16,
52
- symbol = 17,
53
- string = 18,
54
- uuid = 19,
55
- functiondef = 20,
56
- handle = 21,
57
- code = 22,
58
- datasource = 23,
59
- resource = 24,
60
- any = 25,
61
- compressed = 26,
62
- dict = 27,
63
- datehour = 28,
64
- ipaddr = 30,
65
- int128 = 31,
66
- blob = 32,
67
- complex = 34,
68
- point = 35,
69
- duration = 36,
70
- decimal32 = 37,
71
- decimal64 = 38,
72
- decimal128 = 39,
73
- object = 40,
74
- iotany = 41,
75
- symbol_extended = 145
76
- }
77
- export declare enum DdbFunctionType {
78
- SystemFunc = 0,
79
- SystemProc = 1,
80
- OperatorFunc = 2,
81
- UserDefinedFunc = 3,
82
- PartialFunc = 4,
83
- DynamicFunc = 5,
84
- PiecewiseFunc = 6,
85
- JitFunc = 7,
86
- JitPartialFunc = 8
87
- }
88
- export declare enum DdbDurationUnit {
89
- ns = 0,
90
- us = 1,
91
- ms = 2,
92
- s = 3,
93
- m = 4,
94
- H = 5,
95
- d = 6,
96
- w = 7,
97
- M = 8,
98
- y = 9,
99
- B = 10
100
- }
101
- export declare enum DdbChartType {
102
- area = 0,
103
- bar = 1,
104
- column = 2,
105
- histogram = 3,
106
- line = 4,
107
- pie = 5,
108
- scatter = 6,
109
- trend = 7,
110
- kline = 8
111
- }
112
- export declare enum DdbVoidType {
113
- undefined = 0,
114
- null = 1,
115
- default = 2
116
- }
117
- export interface DdbFunctionDefValue {
118
- type: DdbFunctionType;
119
- name: string;
120
- }
121
- export interface DdbDurationValue {
122
- unit: DdbDurationUnit;
123
- /** int32 */
124
- data: number;
125
- }
126
- export interface DdbDecimal32Value {
127
- /** int32, data 需要除以 10^scale 得到原值 */
128
- scale: number;
129
- /** int32, 空值为 null ddb null is js null */
130
- data: number | null;
131
- }
132
- export interface DdbDecimal64Value {
133
- /** int32, data 需要除以 10^scale 得到原值 */
134
- scale: number;
135
- /** int64, 空值为 null empty value is null */
136
- data: bigint | null;
137
- }
138
- export interface DdbDecimal128Value {
139
- /** int32, data 需要除以 10^scale 得到原值 */
140
- scale: number;
141
- /** int128, 空值为 null empty value is null */
142
- data: bigint | null;
143
- }
144
- export interface DdbDecimal32VectorValue {
145
- scale: number;
146
- data: Int32Array;
147
- }
148
- export interface DdbDecimal64VectorValue {
149
- scale: number;
150
- data: BigInt64Array;
151
- }
5
+ import { DdbChartType, DdbForm, DdbFunctionType, DdbType, DdbVoidType, type ConvertOptions, type DdbDecimal32Value, type DdbDecimal32VectorValue, type DdbDecimal64Value, type DdbDecimal64VectorValue, type DdbDurationValue, type DdbDurationVectorValue, type DdbFunctionDefValue, type DdbRpcType, type DdbScalarValue, type DdbSymbolExtendedValue, type DdbTableData, type DdbTensorValue, type IotVectorItemValue, type TensorData } from './common.ts';
6
+ export * from './common.ts';
152
7
  export interface DdbDecimal128VectorValue {
153
8
  scale: number;
154
9
  data: BigInt128Array;
155
10
  }
156
11
  export type DdbDecimalVectorValue = DdbDecimal32VectorValue | DdbDecimal64VectorValue | DdbDecimal128VectorValue;
157
- export type DdbDurationVectorValue = DdbDurationValue[];
158
- export interface DdbSymbolExtendedValue {
159
- base_id: number;
160
- base: string[];
161
- data: Uint32Array;
162
- }
12
+ export type DdbVectorValue = null | Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | BigInt128Array | string[] | // string[]
13
+ Uint8Array[] | // blob
14
+ DdbObj[] | // any
15
+ IotVectorItemValue | DdbSymbolExtendedValue | DdbArrayVectorValue | DdbDecimalVectorValue | DdbDurationVectorValue;
163
16
  export interface DdbArrayVectorBlock {
164
17
  unit: 1 | 2 | 4;
165
18
  rows: number;
@@ -169,41 +22,11 @@ export interface DdbArrayVectorBlock {
169
22
  export type DdbArrayVectorValue = DdbArrayVectorBlock[] & /* decimal 数据会有这个属性 */ {
170
23
  scale?: number;
171
24
  };
172
- export declare const dictables: Set<DdbType>;
173
25
  export interface DdbMatrixValue {
174
26
  rows: DdbVectorObj | null;
175
27
  cols: DdbVectorObj | null;
176
28
  data: DdbVectorValue;
177
29
  }
178
- /** 工具,取得某个 DdbType 的字节数 */
179
- export declare const ddb_tensor_bytes: Record<DdbType.bool | DdbType.char | DdbType.short | DdbType.int | DdbType.long | DdbType.float | DdbType.double, number>;
180
- type TensorElem = TensorData | boolean | number | bigint | null | string;
181
- interface TensorData extends Array<TensorElem> {
182
- }
183
- interface DdbTensorMetadata {
184
- /** Tensor 的元素的数据类型 */
185
- data_type: DdbType;
186
- /** Tensor 类型 */
187
- tensor_type: number;
188
- /** 设备类型 */
189
- device_type: number;
190
- /** Tensor Flags */
191
- tensor_flags: number;
192
- /** 维度 */
193
- dimensions: number;
194
- /** shape, shape[i] 表示第 i 个维度的 size */
195
- shape: number[];
196
- /** strides, strides[i] 表示在第 i 个维度,一个元素与下一个元素的距离 */
197
- strides: number[];
198
- /** 保留值 */
199
- preserve_value: bigint;
200
- /** 元素个数 */
201
- elem_count: number;
202
- }
203
- export interface DdbTensorValue extends DdbTensorMetadata {
204
- /** 数据 */
205
- data: Uint8Array;
206
- }
207
30
  export type DdbDictValue = [DdbVectorObj, DdbVectorObj];
208
31
  export interface DdbChartValue {
209
32
  /** 原属性 chartType original: chartType */
@@ -228,16 +51,6 @@ export interface DdbChartValue {
228
51
  };
229
52
  data: DdbMatrixObj;
230
53
  }
231
- export type DdbScalarValue = null | boolean | number | bigint | string | Uint8Array | // uuid, ipaddr, int128, blob
232
- [
233
- number,
234
- number
235
- ] | // complex, point
236
- DdbFunctionDefValue | DdbDurationValue | DdbDecimal32Value | DdbDecimal64Value | DdbDecimal128Value;
237
- export type DdbVectorValue = null | Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | BigInt128Array | string[] | // string[]
238
- Uint8Array[] | // blob
239
- DdbObj[] | // any
240
- IotVectorItemValue | DdbSymbolExtendedValue | DdbArrayVectorValue | DdbDecimal32VectorValue | DdbDecimal64VectorValue | DdbDecimal128VectorValue | DdbDurationVectorValue;
241
54
  export type DdbValue = DdbScalarValue | DdbVectorValue | DdbMatrixValue | DdbDictValue | DdbChartValue | DdbTensorValue;
242
55
  export type DdbStringObj = DdbObj<string>;
243
56
  export type DdbVectorObj<TValue extends DdbVectorValue = DdbVectorValue> = DdbObj<TValue>;
@@ -248,38 +61,6 @@ export type DdbDictObj<TKeys extends DdbVectorObj = DdbVectorObj, TValues extend
248
61
  export type DdbMatrixObj<TValue extends DdbMatrixValue = DdbMatrixValue> = DdbObj<TValue>;
249
62
  export type DdbChartObj = DdbObj<DdbChartValue>;
250
63
  export type DdbTensorObj = DdbObj<DdbTensorValue>;
251
- /** DdbObj.data() 返回的表格对象 */
252
- export interface DdbTableData<TRow = any> {
253
- /** 表名 */
254
- name: string;
255
- /** 每一列的名称 */
256
- columns: string[];
257
- /** 每一列的原始 ddb 数据类型 */
258
- types: DdbType[];
259
- /** 表格数据,每一行的对象组成的数组 */
260
- data: TRow[];
261
- }
262
- /** DdbObj.data() 返回的 Tensor 对象 */
263
- export interface DdbTensorData extends DdbTensorMetadata {
264
- /** 数据 */
265
- data: TensorData;
266
- }
267
- /** DdbObj.data() 返回的矩阵对象 */
268
- export interface DdbMatrixData {
269
- /** 原始数据类型 */
270
- type: DdbType;
271
- /** 行数 */
272
- nrows: number;
273
- /** 列数 */
274
- ncolumns: number;
275
- /** 行名称 */
276
- rows?: any[];
277
- /** 列名称 */
278
- columns?: any[];
279
- /** 数据, data[0][1] 为第 0 行第 1 列数据 */
280
- data: any[][];
281
- }
282
- export type IotVectorItemValue = [number | string | bigint | boolean][];
283
64
  export type DdbIotAnyVector = DdbObj<IotVectorItemValue>;
284
65
  export type Convertable = DdbObj | string | boolean | null | undefined;
285
66
  /** 可以表示所有 DolphinDB 数据库中的数据类型 Can represent data types in all DolphinDB databases */
@@ -386,11 +167,6 @@ export declare class DdbObj<TValue extends DdbValue = DdbValue> {
386
167
  deep?: boolean;
387
168
  }): T;
388
169
  }
389
- /** 根据 DdbType 获取其名称,array vector type 自动在后面加上 [] */
390
- export declare function get_type_name(type: DdbType): string;
391
- export declare function is_decimal_type(type: DdbType): type is DdbType.decimal32 | DdbType.decimal64 | DdbType.decimal128;
392
- export declare function is_decimal_null_value(type: DdbType, value: number | bigint): boolean;
393
- export declare function get_duration_unit(code: number): string;
394
170
  export interface InspectOptions {
395
171
  /** `false` */
396
172
  colors?: boolean;
@@ -409,16 +185,6 @@ export interface InspectOptions {
409
185
  export declare function format(type: DdbType, value: DdbValue, le: boolean, options?: InspectOptions): string;
410
186
  /** 格式化向量、集合中的第 index 项为字符串,空值返回 'null' 字符串 formatted vector, the index-th item in the collection is a string, a null value returns a 'null' string */
411
187
  export declare function formati(obj: DdbVectorObj, index: number, options?: InspectOptions): string;
412
- export interface ConvertOptions {
413
- /** `'string'` blob 转换格式 */
414
- blob?: 'string' | 'binary';
415
- /** `'string'` char 转换格式: string 转为 string[],number 转为 number[] */
416
- char?: 'string' | 'number';
417
- /** `'strings'` char vector 转换格式: strings 转为 string[], binary 转为 Uint8Array */
418
- chars?: 'strings' | 'binary';
419
- /** `'ms'` timestamp 类型转换为字符串表示时显示到秒还是毫秒 */
420
- timestamp?: 's' | 'ms';
421
- }
422
188
  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;
423
189
  /** 转换一个向量到 js 原生数组 */
424
190
  export declare function converts(type: DdbType, value: DdbVectorValue, rows: number, le: boolean, options?: ConvertOptions): any[] | Uint8Array;
@@ -507,60 +273,6 @@ export declare class DdbDict extends DdbObj<DdbDictValue> {
507
273
  export declare class DdbTable extends DdbObj<DdbObj[]> {
508
274
  constructor(columns: DdbObj[], name?: string);
509
275
  }
510
- export declare function date2ms(date: number | null): number;
511
- export declare function date2str(date: number | null, format?: string): string;
512
- export declare function month2ms(month: number | null): number | null;
513
- export declare function month2str(month: number | null): string;
514
- export declare function time2ms(time: number | null): number | null;
515
- export declare function time2str(time: number | null, format?: string): string;
516
- export declare function minute2ms(minute: number | null): number | null;
517
- export declare function minute2str(minute: number | null, format?: string): string;
518
- export declare function second2ms(second: number | null): number | null;
519
- export declare function second2str(second: number | null, format?: string): string;
520
- export declare function datetime2ms(datetime: number | null): number | null;
521
- export declare function datetime2str(datetime: number | null, format?: string): string;
522
- /** _datetime_formatter.format 会在 date 为 Invalid Date 时抛出错误 */
523
- export declare function timestamp2ms(timestamp: bigint | number | null): number | null;
524
- /** format timestamp (bigint) to string
525
- - timestamp: bigint value
526
- - format?:
527
- 格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSS` format string, default to `YYYY.MM.DD HH:mm:ss.SSS`
528
- https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens */
529
- export declare function timestamp2str(timestamp: bigint | null, format?: string): string;
530
- export declare function datehour2ms(datehour: number | null): number | null;
531
- export declare function datehour2str(datehour: number | null, format?: string): string;
532
- /** parse timestamp string to bigint value
533
- - str: timestamp string, 如果为空字符串或 'null' 会返回对应的空值 (nulls.int64)
534
- timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
535
- - format?:
536
- 对应传入字符串的格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSS`
537
- The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
538
- https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens */
539
- export declare function str2timestamp(str: string, format?: string): bigint;
540
- export declare function nanotime2ns(nanotime: bigint | null): bigint | null;
541
- export declare function nanotime2str(nanotime: bigint | null, format?: string): string;
542
- export declare function nanotimestamp2ns(nanotimestamp: bigint | null): bigint | null;
543
- /** format nanotimestamp value (bigint) to string
544
- - nanotimestamp: bigint value
545
- - format?:
546
- 格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSSSSSSSS` format string, default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
547
- 秒的格式为 ss (必须包含); 纳秒的格式为 SSSSSSSSS (必须包含) Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
548
- https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
549
- */
550
- export declare function nanotimestamp2str(nanotimestamp: bigint | null, format?: string): string;
551
- /** parse nano timestamp string to bigint value
552
- - str: nano timestamp string, 如果为空字符串或 'null' 会返回对应的空值 (nulls.int64)
553
- nano timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
554
- - format?:
555
- 对应传入字符串的格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
556
- 秒的格式为 ss (必须包含); 纳秒的格式为 SSSSSSSSS (必须包含)
557
- https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
558
- The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
559
- Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included) */
560
- export declare function str2nanotimestamp(str: string, format?: string): bigint;
561
- export declare function ipaddr2str(buffer: Uint8Array, le?: boolean, ipv6?: boolean): string;
562
- export declare function uuid2str(buffer: Uint8Array, le?: boolean): string;
563
- export declare function int1282str(buffer: Uint8Array, le?: boolean): string;
564
276
  export interface StreamingParams {
565
277
  table: string;
566
278
  action?: string;
@@ -613,7 +325,6 @@ export interface DdbEvalOptions {
613
325
  }
614
326
  export interface DdbExecuteOptions extends DdbEvalOptions, ConvertOptions {
615
327
  }
616
- type DdbRpcType = 'script' | 'function' | 'variable' | 'connect';
617
328
  export interface DdbRpcOptions extends DdbEvalOptions {
618
329
  script?: string;
619
330
  func?: string;
@@ -712,6 +423,10 @@ export declare class DDB {
712
423
  pinvoke: Promise<DdbVoid>;
713
424
  /** 首次定义 jsrpc 的 promise,保证并发调用 rpc 时只定义一次 jsrpc */
714
425
  pjsrpc: Promise<DdbVoid>;
426
+ /** 函数定义缓存 */
427
+ definitions: Map<string, string>;
428
+ /** 函数定义锁,保证并发调用时不重复定义,直接返回第一次定义的结果 */
429
+ pdefinitions: Map<string, Promise<string>>;
715
430
  get connected(): boolean;
716
431
  /**
717
432
  使用 WebSocket URL 初始化连接到 DolphinDB 的实例(不建立实际的网络连接)
@@ -863,6 +578,17 @@ export declare class DDB {
863
578
  parse_message(buf: Uint8Array, error: DdbDatabaseError): DdbMessage;
864
579
  /** 内部的流订阅方法 Internal stream subscription method */
865
580
  subscribe(): Promise<void>;
581
+ /** 定义函数并保存,避免下次重复执行定义,会自动提取脚本中的函数名,作为缓存 key,
582
+ 也同时作为返回值
583
+ - definition: 函数完整定义
584
+ @example
585
+ await ddb.invoke(
586
+ await ddb.define(
587
+ 'def foo (bar) {\n' +
588
+ ' print(bar)\n' +
589
+ '}\n'),
590
+ ['hello']) */
591
+ define(definition: string): Promise<string>;
866
592
  }
867
593
  export interface DdbMessageListener {
868
594
  (message: DdbMessage, _this: DDB): any;
@@ -906,4 +632,3 @@ export declare class BigInt128Array {
906
632
  };
907
633
  toString(): string;
908
634
  }
909
- export {};