dolphindb 2.0.801 → 2.0.900

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
@@ -21,7 +21,7 @@ DolphinDB JavaScript API is a JavaScript library that encapsulates the ability t
21
21
  https://www.npmjs.com/package/dolphindb
22
22
 
23
23
  ## Features
24
- - Communicate with DolphinDB database using WebSocket, exchange data in binary format
24
+ - Use WebSocket to communicate with DolphinDB database, exchange data in binary format, and support real-time push of streaming data
25
25
  - Support running in browser environment and Node.js environment
26
26
  - Use TypedArray such as Int32Array in JavaScript to process binary data, with high performance
27
27
  - A single call supports serialized upload of up to 2GB of data, and the amount of downloaded data is not limited
@@ -48,10 +48,13 @@ import { DDB } from 'dolphindb'
48
48
  // The import method for existing projects using CommonJS modules is const { DDB } = require('dolphindb')
49
49
  // Use in browser: import { DDB } form 'dolphindb/browser.js'
50
50
 
51
- // Create a database object and initialize the WebSocket URL
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')
53
53
 
54
- // Establish a WebSocket connection to DolphinDB (requires DolphinDB database version at least 1.30.16 or 2.00.4)
54
+ // Encrypt with HTTPS
55
+ // let ddb = new DDB('wss://dolphindb.com')
56
+
57
+ // Establish a connection to DolphinDB (requires DolphinDB database version at least 1.30.16 or 2.00.4)
55
58
  await ddb.connect()
56
59
  ```
57
60
 
@@ -71,7 +74,10 @@ let ddbsecure = new DDB('wss://dolphindb.com', {
71
74
  password: '123456',
72
75
 
73
76
  // set python session flag, default `false`
74
- python: false
77
+ python: false,
78
+
79
+ // After setting this option, the database connection is only used for streaming data. For details, see `5. Streaming Data`
80
+ streaming: undefined
75
81
  })
76
82
  ```
77
83
 
@@ -336,7 +342,7 @@ async upload (
336
342
  ```
337
343
 
338
344
 
339
- ### Some Examples
345
+ ### 4. Some Examples
340
346
  ```ts
341
347
  import { nulls, DdbInt, timestamp2str, DdbVectorSymbol, DdbTable, DdbVectorDouble } from 'dolphindb'
342
348
 
@@ -371,3 +377,72 @@ new DdbTable(
371
377
  )
372
378
  ```
373
379
 
380
+ ### 5. Streaming Data
381
+ ```ts
382
+ // New Streaming Data Connection Configuration
383
+ let sddb = new DDB('ws://192.168.0.43:8800', {
384
+ autologin: true,
385
+ username: 'admin',
386
+ password: '123456',
387
+ streaming: {
388
+ table: 'Streaming table name to subscribe to',
389
+
390
+ // Streaming data processing callback, the type of message is StreamingData
391
+ handler (message) {
392
+ console.log(message)
393
+ }
394
+ }
395
+ })
396
+
397
+ // Establish connection
398
+ await sddb.connect()
399
+ ```
400
+
401
+ The streaming data received after the connection is established will be used as the message parameter of the handler. The type of the message is StreamingData, as follows:
402
+
403
+ ```ts
404
+ export interface StreamingParams {
405
+ table: string
406
+ action?: string
407
+
408
+ handler (message: StreamingData): any
409
+ }
410
+
411
+ export interface StreamingData extends StreamingParams {
412
+ /**
413
+ The time the server sent the message (nano seconds since epoch)
414
+ std::chrono::system_clock::now().time_since_epoch() / std::chrono::nanoseconds(1)
415
+ */
416
+ time: bigint
417
+
418
+ /** message id */
419
+ id: bigint
420
+
421
+ colnames: string[]
422
+
423
+ /** Subscription topic, which is the name of a subscription.
424
+ 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 `/`
425
+ */
426
+ topic: string
427
+
428
+ /** Streaming 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 */
429
+ data: DdbObj<DdbVectorObj[]>
430
+
431
+ /** Number of new streaming data rows */
432
+ rows: number
433
+
434
+ window: {
435
+ /** The establishment of the connection starts offset = 0, and gradually increases as the window moves */
436
+ offset: number
437
+
438
+ /** sum of segment.row in segments */
439
+ rows: number
440
+
441
+ /** An array of data received each time */
442
+ segments: DdbObj<DdbVectorObj[]>[]
443
+ }
444
+
445
+ /** After successfully subscribed, if the subsequently pushed message is parsed incorrectly, the error will be set and the handler will be called. */
446
+ error?: Error
447
+ }
448
+ ```
package/README.zh.md CHANGED
@@ -21,7 +21,7 @@ DolphinDB JavaScript API 是一个 JavaScript 库,封装了操作 DolphinDB
21
21
  https://www.npmjs.com/package/dolphindb
22
22
 
23
23
  ## 特性
24
- - 使用 WebSocket 与 DolphinDB 数据库通信,用二进制格式进行数据交换
24
+ - 使用 WebSocket 与 DolphinDB 数据库通信,用二进制格式进行数据交换,支持流数据实时推送
25
25
  - 支持在浏览器环境和 Node.js 环境中运行
26
26
  - 使用了 JavaScript 中的 Int32Array 等 TypedArray 处理二进制数据,性能较高
27
27
  - 单次调用支持最大 2 GB 数据的序列化上传,下载数据量不受限制
@@ -48,19 +48,19 @@ import { DDB } from 'dolphindb'
48
48
  // 已有的使用 CommonJS 模块的项目的导入方法为 const { DDB } = require('dolphindb')
49
49
  // 在浏览器中使用: import { DDB } form 'dolphindb/browser.js'
50
50
 
51
- // 创建数据库对象,初始化 WebSocket 连接地址
51
+ // 使用 WebSocket URL 初始化连接到 DolphinDB 的实例(不建立实际的网络连接)
52
52
  let ddb = new DDB('ws://127.0.0.1:8848')
53
53
 
54
- // 建立到 DolphinDB 的 WebSocket 连接(要求 DolphinDB 数据库版本不低于 1.30.16 或 2.00.4)
54
+ // 使用 HTTPS 加密
55
+ // let ddb = new DDB('wss://dolphindb.com')
56
+
57
+ // 建立到 DolphinDB 的连接(要求 DolphinDB 数据库版本不低于 1.30.16 或 2.00.4)
55
58
  await ddb.connect()
56
59
  ```
57
60
 
58
61
  #### DDB 选项
59
62
  ```ts
60
- let ddb = new DDB('ws://127.0.0.1:8848')
61
-
62
- // 使用 HTTPS 加密
63
- let ddbsecure = new DDB('wss://dolphindb.com', {
63
+ let ddb = new DDB('ws://127.0.0.1:8848', {
64
64
  // 是否在建立连接后自动登录,默认 `true`
65
65
  autologin: true,
66
66
 
@@ -71,7 +71,10 @@ let ddbsecure = new DDB('wss://dolphindb.com', {
71
71
  password: '123456',
72
72
 
73
73
  // 设置 python session flag,默认 `false`
74
- python: false
74
+ python: false,
75
+
76
+ // 设置该选项后,该数据库连接只用于流数据,详细用法见后文 `5. 流数据`
77
+ streaming: undefined
75
78
  })
76
79
  ```
77
80
 
@@ -336,7 +339,7 @@ async upload (
336
339
  ```
337
340
 
338
341
 
339
- ### 一些例子
342
+ ### 4. 一些例子
340
343
  ```ts
341
344
  import { nulls, DdbInt, timestamp2str, DdbVectorSymbol, DdbTable, DdbVectorDouble } from 'dolphindb'
342
345
 
@@ -370,3 +373,74 @@ new DdbTable(
370
373
  'mytable'
371
374
  )
372
375
  ```
376
+
377
+
378
+ ### 5. 流数据
379
+ ```ts
380
+ // 新建流数据连接配置
381
+ let sddb = new DDB('ws://192.168.0.43:8800', {
382
+ autologin: true,
383
+ username: 'admin',
384
+ password: '123456',
385
+ streaming: {
386
+ table: '要订阅的流表名称',
387
+
388
+ // 流数据处理回调, message 的类型是 StreamingData
389
+ handler (message) {
390
+ console.log(message)
391
+ }
392
+ }
393
+ })
394
+
395
+ // 建立连接
396
+ await sddb.connect()
397
+ ```
398
+
399
+ 连接建立后接收到的流数据会作为 message 参数调用 handler, message 的类型是 StreamingData, 如下:
400
+
401
+ ```ts
402
+ export interface StreamingParams {
403
+ table: string
404
+ action?: string
405
+
406
+ handler (message: StreamingData): any
407
+ }
408
+
409
+ export interface StreamingData extends StreamingParams {
410
+ /**
411
+ server 发送消息的时间 (nano seconds since epoch)
412
+ std::chrono::system_clock::now().time_since_epoch() / std::chrono::nanoseconds(1)
413
+ */
414
+ time: bigint
415
+
416
+ /** message id */
417
+ id: bigint
418
+
419
+ colnames: string[]
420
+
421
+ /** 订阅主题,即一个订阅的名称。
422
+ 它是一个字符串,由订阅表所在节点的别名、流数据表名称和订阅任务名称(如果指定了 actionName)组合而成,使用 `/` 分隔
423
+ */
424
+ topic: string
425
+
426
+ /** 流数据,类型是 any vector, 其中的每一个元素对应被订阅表的一个列 (没有 name),列 (DdbObj<DdbVectorValue>) 中的内容是新增的数据值 */
427
+ data: DdbObj<DdbVectorObj[]>
428
+
429
+ /** 新增的流数据行数 */
430
+ rows: number
431
+
432
+ window: {
433
+ /** 建立连接开始 offset = 0, 随着 window 的移动逐渐增加 */
434
+ offset: number
435
+
436
+ /** segments 中 segment.row 的总和 */
437
+ rows: number
438
+
439
+ /** 每次接收到的 data 组成的数组 */
440
+ segments: DdbObj<DdbVectorObj[]>[]
441
+ }
442
+
443
+ /** 成功订阅后,后续推送过来的 message 解析错误,则会设置 error 并调用 handler */
444
+ error?: Error
445
+ }
446
+ ```
package/browser.d.ts CHANGED
@@ -124,12 +124,15 @@ export interface DdbArrayVectorBlock {
124
124
  lengths: Uint8Array | Uint16Array | Uint32Array;
125
125
  data: Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array;
126
126
  }
127
+ export type DdbArrayVectorValue = DdbArrayVectorBlock[] & /* decimal32, decimal64 会有这个属性 */ {
128
+ scale?: number;
129
+ };
127
130
  export interface DdbMatrixValue {
128
131
  rows: DdbVectorObj;
129
132
  cols: DdbVectorObj;
130
133
  data: DdbVectorValue;
131
134
  }
132
- export declare type DdbDictValue = [DdbVectorObj, DdbVectorObj];
135
+ export type DdbDictValue = [DdbVectorObj, DdbVectorObj];
133
136
  export declare enum DdbChartType {
134
137
  area = 0,
135
138
  bar = 1,
@@ -164,24 +167,24 @@ export interface DdbChartValue {
164
167
  };
165
168
  data: DdbMatrixObj;
166
169
  }
167
- export declare type DdbScalarValue = null | boolean | number | bigint | string | Uint8Array | // uuid, ipaddr, int128, blob
170
+ export type DdbScalarValue = null | boolean | number | bigint | string | Uint8Array | // uuid, ipaddr, int128, blob
168
171
  [
169
172
  number,
170
173
  number
171
174
  ] | // complex, point
172
175
  DdbFunctionDefValue | DdbDurationValue | DdbDecimal32Value | DdbDecimal64Value;
173
- export declare type DdbVectorValue = Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | string[] | // string[]
176
+ export type DdbVectorValue = Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | string[] | // string[]
174
177
  Uint8Array[] | // blob
175
178
  DdbObj[] | // any
176
- DdbSymbolExtendedValue | DdbArrayVectorBlock[] | DdbDecimal32VectorValue | DdbDecimal64VectorValue;
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>;
179
+ DdbSymbolExtendedValue | DdbArrayVectorValue | DdbDecimal32VectorValue | DdbDecimal64VectorValue;
180
+ export type DdbValue = DdbScalarValue | DdbVectorValue | DdbMatrixValue | DdbDictValue | DdbChartValue;
181
+ export type DdbVectorObj = DdbObj<DdbVectorValue>;
182
+ export type DdbVectorAnyObj = DdbObj<DdbObj[]>;
183
+ export type DdbVectorStringObj = DdbObj<string[]>;
184
+ export type DdbTableObj = DdbObj<DdbVectorObj[]>;
185
+ export type DdbDictObj = DdbObj<[DdbVectorObj, DdbVectorObj]>;
186
+ export type DdbMatrixObj = DdbObj<DdbMatrixValue>;
187
+ export type DdbChartObj = DdbObj<DdbChartValue>;
185
188
  export declare const nulls: {
186
189
  readonly int8: -128;
187
190
  readonly int16: -32768;
@@ -192,14 +195,6 @@ export declare const nulls: {
192
195
  readonly double: number;
193
196
  readonly bytes16: Uint8Array;
194
197
  };
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
- }
203
198
  /** 可以表示所有 DolphinDB 数据库中的数据类型 */
204
199
  export declare class DdbObj<TValue extends DdbValue = DdbValue> {
205
200
  static dec: TextDecoder;
@@ -432,10 +427,10 @@ export interface StreamingData extends StreamingParams {
432
427
  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 `/`
433
428
  */
434
429
  topic: string;
435
- /** 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 */
436
- schema: DdbTableObj;
437
430
  /** 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 */
438
431
  data: DdbObj<DdbVectorObj[]>;
432
+ /** Number of new streaming data rows */
433
+ rows: number;
439
434
  window: {
440
435
  /** The establishment of the connection starts offset = 0, and gradually increases as the window moves */
441
436
  offset: number;
@@ -444,8 +439,10 @@ export interface StreamingData extends StreamingParams {
444
439
  /** An array of data received each time */
445
440
  segments: DdbObj<DdbVectorObj[]>[];
446
441
  };
442
+ /** After successfully subscribed, if the subsequently pushed message is parsed incorrectly, the error will be set and the handler will be called. */
443
+ error?: Error;
447
444
  }
448
- export declare const winsize: 40;
445
+ export declare const winsize: 100000;
449
446
  export declare class ConnectionError extends Error {
450
447
  ddb: DDB;
451
448
  constructor(ddb: DDB);
@@ -614,7 +611,7 @@ export declare class DDB {
614
611
  /** 解析服务端响应报文,返回去掉 header 的 data buf */
615
612
  parse_message(buf: Uint8Array, parse_object?: boolean): DdbMessage;
616
613
  /** Internal stream subscription method */
617
- subscribe(): Promise<DdbTableObj>;
614
+ subscribe(): Promise<StreamingData>;
618
615
  }
619
616
  export interface DdbMessageListener {
620
617
  (message: DdbMessage, _this: DDB): any;
@@ -631,5 +628,5 @@ export interface DdbErrorMessage {
631
628
  type: 'error';
632
629
  data: Error;
633
630
  }
634
- export declare type DdbMessage = DdbPrintMessage | DdbObjectMessage | DdbErrorMessage;
631
+ export type DdbMessage = DdbPrintMessage | DdbObjectMessage | DdbErrorMessage;
635
632
  export declare let ddb: DDB;