dolphindb 2.0.602 → 2.0.800

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
@@ -46,6 +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
50
 
50
51
  // Create a database object and initialize the WebSocket URL
51
52
  let ddb = new DDB('ws://127.0.0.1:8848')
package/browser.d.ts CHANGED
@@ -53,7 +53,11 @@ export declare enum DdbType {
53
53
  complex = 34,
54
54
  point = 35,
55
55
  duration = 36,
56
- object = 37,
56
+ decimal32 = 37,
57
+ decimal64 = 38,
58
+ decimal128 = 39,
59
+ object = 40,
60
+ pynone = 41,
57
61
  symbol_extended = 145
58
62
  }
59
63
  export declare enum DdbFunctionType {
@@ -89,6 +93,26 @@ export interface DdbDurationValue {
89
93
  /** int32 */
90
94
  data: number;
91
95
  }
96
+ export interface DdbDecimal32Value {
97
+ /** int32, data needs to be divided by 10^scale to get the original value */
98
+ scale: number;
99
+ /** int32, 空值为 null */
100
+ data: number | null;
101
+ }
102
+ export interface DdbDecimal64Value {
103
+ /** int32, data needs to be divided by 10^scale to get the original value */
104
+ scale: number;
105
+ /** int64, 空值为 null */
106
+ data: bigint | null;
107
+ }
108
+ export interface DdbDecimal32VectorValue {
109
+ scale: number;
110
+ data: Int32Array;
111
+ }
112
+ export interface DdbDecimal64VectorValue {
113
+ scale: number;
114
+ data: BigInt64Array;
115
+ }
92
116
  export interface DdbSymbolExtendedValue {
93
117
  base_id: number;
94
118
  base: string[];
@@ -101,11 +125,11 @@ export interface DdbArrayVectorBlock {
101
125
  data: Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array;
102
126
  }
103
127
  export interface DdbMatrixValue {
104
- rows: DdbObj<DdbVectorValue>;
105
- cols: DdbObj<DdbVectorValue>;
128
+ rows: DdbVectorObj;
129
+ cols: DdbVectorObj;
106
130
  data: DdbVectorValue;
107
131
  }
108
- export declare type DdbDictValue = [DdbObj<DdbVectorValue>, DdbObj<DdbVectorValue>];
132
+ export declare type DdbDictValue = [DdbVectorObj, DdbVectorObj];
109
133
  export declare enum DdbChartType {
110
134
  area = 0,
111
135
  bar = 1,
@@ -121,6 +145,15 @@ export interface DdbChartValue {
121
145
  /** 原属性 chartType */
122
146
  type: DdbChartType;
123
147
  stacking: boolean;
148
+ /** 直方图 (Histogram), plotHist 函数返回的 chart 可能具有该属性
149
+ 原属性 binStart
150
+ 数值类型的 DdbObj 都有可能?
151
+ */
152
+ bin_start?: DdbObj;
153
+ /** 原属性 binEnd */
154
+ bin_end?: DdbObj;
155
+ /** 原属性 binCount */
156
+ bin_count?: DdbObj;
124
157
  titles: {
125
158
  chart: string;
126
159
  x_axis: string;
@@ -129,19 +162,26 @@ export interface DdbChartValue {
129
162
  extras?: {
130
163
  multi_y_axes: boolean;
131
164
  };
132
- data: DdbObj<DdbMatrixValue>;
165
+ data: DdbMatrixObj;
133
166
  }
134
167
  export declare type DdbScalarValue = null | boolean | number | bigint | string | Uint8Array | // uuid, ipaddr, int128, blob
135
168
  [
136
169
  number,
137
170
  number
138
171
  ] | // complex, point
139
- DdbFunctionDefValue | DdbDurationValue;
172
+ DdbFunctionDefValue | DdbDurationValue | DdbDecimal32Value | DdbDecimal64Value;
140
173
  export declare type DdbVectorValue = Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | string[] | // string[]
141
174
  Uint8Array[] | // blob
142
175
  DdbObj[] | // any
143
- DdbSymbolExtendedValue | DdbArrayVectorBlock[];
176
+ DdbSymbolExtendedValue | DdbArrayVectorBlock[] | DdbDecimal32VectorValue | DdbDecimal64VectorValue;
144
177
  export declare type DdbValue = DdbScalarValue | DdbVectorValue | DdbMatrixValue | DdbDictValue | DdbChartValue;
178
+ export declare type DdbVectorObj = DdbObj<DdbVectorValue>;
179
+ export declare type DdbVectorAnyObj = DdbObj<DdbObj[]>;
180
+ export declare type DdbVectorStringObj = DdbObj<string[]>;
181
+ export declare type DdbTableObj = DdbObj<DdbVectorObj[]>;
182
+ export declare type DdbDictObj = DdbObj<[DdbVectorObj, DdbVectorObj]>;
183
+ export declare type DdbMatrixObj = DdbObj<DdbMatrixValue>;
184
+ export declare type DdbChartObj = DdbObj<DdbChartValue>;
145
185
  export declare const nulls: {
146
186
  readonly int8: -128;
147
187
  readonly int16: -32768;
@@ -153,8 +193,15 @@ export declare const nulls: {
153
193
  readonly bytes16: Uint8Array;
154
194
  };
155
195
  export declare const timezone_offset: number;
196
+ export declare enum StreamingStatusCode {
197
+ ok = 0,
198
+ connection_existed = 1,
199
+ not_leader = 2,
200
+ other = 3,
201
+ error = 4
202
+ }
156
203
  /** 可以表示所有 DolphinDB 数据库中的数据类型 */
157
- export declare class DdbObj<T extends DdbValue = DdbValue> {
204
+ export declare class DdbObj<TValue extends DdbValue = DdbValue> {
158
205
  static dec: TextDecoder;
159
206
  static enc: TextEncoder;
160
207
  /** 维护已解析的 symbol base,比如流数据中后续的 symbol 向量可能只发送一个 base.id, base.size == 0, 依赖之前发送的 symbol base ?
@@ -186,7 +233,7 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
186
233
  /** 第 2 维 */
187
234
  cols?: number;
188
235
  /** 实际数据。不同的 DdbForm, DdbType 使用 DdbValue 中不同的类型来表示实际数据 */
189
- value: T;
236
+ value: TValue;
190
237
  /** 原始二进制数据,仅在 parse_object 为 false 时通过 parse_message 生成的顶层对象有这个属性 */
191
238
  buffer?: Uint8Array;
192
239
  constructor(data: Partial<DdbObj> & {
@@ -198,7 +245,7 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
198
245
  /** parse: rows, cols, items
199
246
  返回的 ddbobj.length 不包括 vector 的 type 和 form
200
247
  */
201
- static parse_vector(buf: Uint8Array, le: boolean, type: DdbType): DdbObj<DdbVectorValue>;
248
+ static parse_vector(buf: Uint8Array, le: boolean, type: DdbType): DdbVectorObj;
202
249
  /** 有可能没有字节对齐,不能直接使用原有 message 的 arraybuffer, 统一复制出来,让原有 arraybuffer 被回收掉比较好 */
203
250
  static parse_vector_items(buf: Uint8Array, le: boolean, type: DdbType, length: number): [
204
251
  number,
@@ -206,7 +253,7 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
206
253
  ];
207
254
  pack(): Uint8Array;
208
255
  static pack_vector_body(value: DdbVectorValue, type: DdbType, length: number): ArrayBufferView[];
209
- toString(colors?: boolean): any;
256
+ toString(options?: InspectOptions): string;
210
257
  inspect_type(): string;
211
258
  /** 自动转换 js string, boolean 为 DdbObj */
212
259
  static to_ddbobj(value: DdbObj | string | boolean): DdbObj;
@@ -232,13 +279,15 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
232
279
  deep?: boolean;
233
280
  }): T;
234
281
  }
235
- interface InspectOptions {
282
+ export interface InspectOptions {
236
283
  colors?: boolean;
284
+ /** decimal places */
285
+ decimals?: number;
237
286
  }
238
287
  /** Formats a single element (value) as a string according to DdbType, null returns a 'null' string */
239
288
  export declare function format(type: DdbType, value: DdbValue, le: boolean, options?: InspectOptions): string;
240
- /** Format vector, the index-th item in the collection is a string, a null value returns a 'null' string */
241
- export declare function formati(obj: DdbObj, index: number, options?: InspectOptions): string;
289
+ /** formatted vector, the index-th item in the collection is a string, a null value returns a 'null' string */
290
+ export declare function formati(obj: DdbVectorObj, index: number, options?: InspectOptions): string;
242
291
  export declare class DdbVoid extends DdbObj<undefined> {
243
292
  constructor();
244
293
  }
@@ -305,7 +354,7 @@ export declare class DdbSetString extends DdbObj<string[]> {
305
354
  */
306
355
  export declare class DdbDict extends DdbObj<DdbDictValue> {
307
356
  constructor(obj: Record<string, boolean | string | DdbObj>);
308
- constructor(keys: DdbObj<DdbVectorValue>, values: DdbObj<DdbVectorValue>);
357
+ constructor(keys: DdbVectorObj, values: DdbVectorObj);
309
358
  }
310
359
  export declare class DdbTable extends DdbObj<DdbObj[]> {
311
360
  constructor(columns: DdbObj[], name?: string);
@@ -361,6 +410,38 @@ export declare function str2nanotimestamp(str: string, format?: string): bigint;
361
410
  export declare function ipaddr2str(buffer: Uint8Array, le?: boolean, ipv6?: boolean): string;
362
411
  export declare function uuid2str(buffer: Uint8Array, le?: boolean): string;
363
412
  export declare function int1282str(buffer: Uint8Array, le?: boolean): string;
413
+ export interface StreamingParams {
414
+ table: string;
415
+ action?: string;
416
+ handler(message: StreamingData): any;
417
+ }
418
+ export interface StreamingData extends StreamingParams {
419
+ /**
420
+ The time the server sent the message (nano seconds since epoch)
421
+ std::chrono::system_clock::now().time_since_epoch() / std::chrono::nanoseconds(1)
422
+ */
423
+ time: bigint;
424
+ /** message id */
425
+ id: bigint;
426
+ colnames: string[];
427
+ /** Subscription topic, which is the name of a subscription.
428
+ It is a string consisting of the alias of the node where the subscription table is located, the stream data table name, and the subscription task name (if actionName is specified), separated by `/`
429
+ */
430
+ topic: string;
431
+ /** The schema of the flow table, the type is table, there is no data in the column vector (rows === 0), only the column name and type */
432
+ schema: DdbTableObj;
433
+ /** Stream data, the type is any vector, each element of which corresponds to a column (without name) of the subscribed table, and the content in the column (DdbObj<DdbVectorValue>) is the new data value */
434
+ data: DdbObj<DdbVectorObj[]>;
435
+ window: {
436
+ /** The establishment of the connection starts offset = 0, and gradually increases as the window moves */
437
+ offset: number;
438
+ /** sum of segment.row in segments */
439
+ rows: number;
440
+ /** An array of data received each time */
441
+ segments: DdbObj<DdbVectorObj[]>[];
442
+ };
443
+ }
444
+ export declare const winsize: 40;
364
445
  export declare class DDB {
365
446
  /** 当前的 session id (http 或 tcp) */
366
447
  sid: string;
@@ -384,13 +465,17 @@ export declare class DDB {
384
465
  password: string;
385
466
  /** python session flag (2048) */
386
467
  python: boolean;
468
+ /** Whether it is a streaming data connection, this field is always null for non-streaming data */
469
+ streaming: StreamingData;
387
470
  print_message_buffer: boolean;
388
471
  print_object_buffer: boolean;
389
472
  print_message: boolean;
390
473
  parse_object: boolean;
474
+ pnode_run_defined: boolean;
391
475
  /** DdbMessage listeners */
392
476
  listeners: DdbMessageListener[];
393
477
  pconnect: Promise<void>;
478
+ ppnoderun: Promise<void>;
394
479
  presult: Promise<any>;
395
480
  get connected(): boolean;
396
481
  /**
@@ -402,6 +487,7 @@ export declare class DDB {
402
487
  - username?: DolphinDB username, default `'admin'`
403
488
  - password?: DolphinDB password, default `'123456'`
404
489
  - python?: set python session flag, default `false`
490
+ - streaming?: When this option is set, the WebSocket connection is only used for streaming data
405
491
 
406
492
  @example
407
493
  let ddb = new DDB('ws://127.0.0.1:8848')
@@ -419,6 +505,7 @@ export declare class DDB {
419
505
  username?: string;
420
506
  password?: string;
421
507
  python?: boolean;
508
+ streaming?: StreamingParams;
422
509
  });
423
510
  private on_message;
424
511
  /** Establish the actual WebSocket connection to the DolphinDB corresponding to the URL
@@ -428,13 +515,15 @@ export declare class DDB {
428
515
  - username?: DolphinDB username, default `'admin'`
429
516
  - password?: DolphinDB password, default `'123456'`
430
517
  - python?: set python session flag, default `false`
518
+ - streaming?: When this option is set, the WebSocket connection is only used for streaming data
431
519
  */
432
- connect(options?: {
520
+ connect({ url, autologin, username, password, python, streaming }?: {
433
521
  url?: string;
434
522
  autologin?: boolean;
435
523
  username?: string;
436
524
  password?: string;
437
525
  python?: boolean;
526
+ streaming?: StreamingParams;
438
527
  }): Promise<void>;
439
528
  get_rpc_options({ urgent, secondary, async: _async, pickle, clear, api, compress, cancellable, priority, parallelism, root_id, limit, }?: {
440
529
  urgent?: boolean;
@@ -524,8 +613,12 @@ export declare class DDB {
524
613
  listener?: DdbMessageListener;
525
614
  parse_object?: boolean;
526
615
  }): Promise<DdbObj<DdbValue>>;
616
+ /** Cancel all console jobs corresponding to the current session id */
617
+ cancel(): Promise<void>;
527
618
  /** 解析服务端响应报文,返回去掉 header 的 data buf */
528
619
  parse_message(buf: Uint8Array, parse_object?: boolean): DdbMessage;
620
+ /** Internal stream subscription method */
621
+ subscribe(): Promise<DdbTableObj>;
529
622
  }
530
623
  export interface DdbMessageListener {
531
624
  (message: DdbMessage, _this: DDB): any;
@@ -544,4 +637,3 @@ export interface DdbErrorMessage {
544
637
  }
545
638
  export declare type DdbMessage = DdbPrintMessage | DdbObjectMessage | DdbErrorMessage;
546
639
  export declare let ddb: DDB;
547
- export {};