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