dolphindb 3.0.41 → 3.0.42
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 +221 -122
- package/browser.d.ts +1 -1
- package/docs.en.json +8278 -8278
- package/docs.zh.json +2004 -1980
- package/index.d.ts +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -16,120 +16,179 @@
|
|
|
16
16
|
## English | [中文](./README.zh.md)
|
|
17
17
|
|
|
18
18
|
## Overview
|
|
19
|
-
DolphinDB JavaScript API is a JavaScript library that encapsulates
|
|
19
|
+
The DolphinDB JavaScript API is a JavaScript library that encapsulates interactions with the DolphinDB database, such as connecting to the database, executing scripts, calling functions, uploading variables, etc.
|
|
20
20
|
|
|
21
21
|
https://www.npmjs.com/package/dolphindb
|
|
22
22
|
|
|
23
23
|
## Features
|
|
24
|
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
24
|
+
|
|
25
|
+
- Communicates with the DolphinDB database using WebSocket and exchanges data in binary format, supporting real-time streaming data.
|
|
26
|
+
- Supports running in both browser and Node.js environments.
|
|
27
|
+
- Uses TypedArray in JavaScript such as Int32Array to handle binary data.
|
|
28
|
+
- Supports serialized upload of up to 2 GB of data in a single call, with no limit on the amount of downloaded data.
|
|
28
29
|
|
|
29
30
|
## Usage
|
|
30
|
-
|
|
31
|
+
|
|
32
|
+
### Connecting to DolphinDB
|
|
31
33
|
|
|
32
34
|
#### Method 1: Use the built CDN version directly in the browser
|
|
33
35
|
|
|
34
|
-
Save the following content to
|
|
36
|
+
Save the following content to an `example.html` file and open it with a browser to run it. Press F12 to open the debug console and check the logs.
|
|
35
37
|
|
|
36
38
|
```html
|
|
37
39
|
<!doctype html>
|
|
38
40
|
<html>
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
<head>
|
|
42
|
+
<title>DolphinDB</title>
|
|
43
|
+
<meta charset='utf-8' />
|
|
44
|
+
</head>
|
|
45
|
+
<body>
|
|
46
|
+
<script type="module">
|
|
47
|
+
import { DDB } from 'https://cdn.dolphindb.cn/assets/api.js'
|
|
48
|
+
|
|
49
|
+
let ddb = new DDB('ws://127.0.0.1:8848')
|
|
46
50
|
|
|
47
|
-
|
|
51
|
+
await ddb.connect()
|
|
48
52
|
|
|
49
|
-
|
|
53
|
+
console.log(
|
|
54
|
+
await ddb.execute('1 + 1')
|
|
55
|
+
)
|
|
50
56
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
console.log(
|
|
58
|
+
await ddb.invoke('add', [1, 1])
|
|
59
|
+
)
|
|
60
|
+
</script>
|
|
61
|
+
</body>
|
|
56
62
|
</html>
|
|
57
63
|
```
|
|
58
64
|
|
|
59
|
-
#### Method 2: Install the npm package
|
|
65
|
+
#### Method 2: Install the npm package and import to the project
|
|
60
66
|
|
|
61
67
|
##### 1. Installation
|
|
62
68
|
|
|
63
|
-
1.1. Install the latest version of Node.js and browser on
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
1.1. Install the latest version of Node.js and browser on your machine.
|
|
70
|
+
- Windows: https://nodejs.org/en/download/prebuilt-installer/current
|
|
71
|
+
- Linux: https://github.com/nodesource/distributions?tab=readme-ov-file#debian-and-ubuntu-based-distributions
|
|
72
|
+
|
|
73
|
+
1.2. (Optional) Create a new project using the following command. Skip this step if you already have a project.
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
mkdir dolphindb-example
|
|
77
|
+
cd dolphindb-example
|
|
78
|
+
npm init --yes
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
1.3. Open the `package.json` file with an editor and add a line `"type": "module"` below `"main": "./index.js"` to enable ECMAScript modules. In the following code, you can use `import { DDB } from 'dolphindb'` to import npm package.
|
|
82
|
+
|
|
73
83
|
1.4. Install the npm package in the project.
|
|
74
|
-
```bash
|
|
75
|
-
npm install dolphindb
|
|
76
|
-
```
|
|
77
84
|
|
|
78
|
-
|
|
85
|
+
```bash
|
|
86
|
+
npm install dolphindb
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
##### 2. Usage
|
|
79
90
|
|
|
80
91
|
```ts
|
|
81
|
-
// 2.1
|
|
92
|
+
// 2.1 import in the browser environment
|
|
82
93
|
import { DDB } from 'dolphindb/browser.js'
|
|
83
94
|
|
|
84
|
-
// 2.1
|
|
95
|
+
// 2.1 import in the Node.js environment
|
|
85
96
|
// import { DDB } from 'dolphindb'
|
|
86
|
-
//
|
|
97
|
+
// For existing projects using CommonJS modules, import as follows: const { DDB } = await import('dolphindb')
|
|
87
98
|
|
|
88
|
-
// 2.2
|
|
99
|
+
// 2.2 Initialize the instance to connect to DolphinDB using the WebSocket URL (no actual network connection is established)
|
|
89
100
|
let ddb = new DDB('ws://127.0.0.1:8848')
|
|
90
101
|
|
|
91
102
|
// Use HTTPS encryption
|
|
92
103
|
// let ddb = new DDB('wss://dolphindb.com')
|
|
93
104
|
|
|
94
|
-
// 2.3 Establish a connection to DolphinDB (requires DolphinDB database version
|
|
105
|
+
// 2.3 Establish a connection to DolphinDB (requires DolphinDB database version no less than 1.30.16 or 2.00.4)
|
|
95
106
|
await ddb.connect()
|
|
96
107
|
```
|
|
97
108
|
|
|
98
|
-
#### Code completion
|
|
99
|
-
- https://cdn.dolphindb.cn/assets/docs.zh.json
|
|
100
|
-
- https://cdn.dolphindb.cn/assets/docs.en.json
|
|
109
|
+
#### Code completion and function prompt
|
|
101
110
|
|
|
111
|
+
See https://cdn.dolphindb.cn/assets/docs.en.json
|
|
112
|
+
or https://cdn.dolphindb.cn/assets/docs.zh.json
|
|
102
113
|
|
|
103
|
-
####
|
|
104
|
-
```ts
|
|
105
|
-
let ddb = new DDB('ws://127.0.0.1:8848')
|
|
114
|
+
#### Connection options
|
|
106
115
|
|
|
107
|
-
|
|
108
|
-
let
|
|
109
|
-
// Whether to log in
|
|
116
|
+
```ts
|
|
117
|
+
let ddb = new DDB('ws://127.0.0.1:8848', {
|
|
118
|
+
// Whether to automatically log in after establishing a connection, default is true
|
|
110
119
|
autologin: true,
|
|
111
120
|
|
|
112
|
-
// DolphinDB username, default
|
|
121
|
+
// DolphinDB login username, default is 'admin'
|
|
113
122
|
username: 'admin',
|
|
114
123
|
|
|
115
|
-
// DolphinDB password, default
|
|
124
|
+
// DolphinDB login password, default is '123456'
|
|
116
125
|
password: '123456',
|
|
117
126
|
|
|
118
|
-
//
|
|
127
|
+
// Set python session flag, default is false
|
|
119
128
|
python: false,
|
|
120
129
|
|
|
121
|
-
//
|
|
130
|
+
// Set the SQL standard to execute in the current session, use the SqlStandard enum, default is DolphinDB
|
|
122
131
|
// sql: SqlStandard.MySQL,
|
|
123
132
|
// sql: SqlStandard.Oracle,
|
|
124
133
|
|
|
125
|
-
//
|
|
134
|
+
// Set this option for the database connection to be used only for streaming data, see `5. Streaming Data` for details
|
|
126
135
|
streaming: undefined
|
|
127
136
|
})
|
|
128
137
|
```
|
|
129
138
|
|
|
130
|
-
|
|
131
139
|
### Calling functions
|
|
132
|
-
####
|
|
140
|
+
#### `invoke` method
|
|
141
|
+
##### Code example
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
const result = await ddb.invoke('add', [1, 1])
|
|
145
|
+
// TypeScript: const result = await ddb.invoke<number>('add', [1, 1])
|
|
146
|
+
|
|
147
|
+
console.log(result === 2) // true
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
In the example above, two parameters 1 (corresponding to the int type in DolphinDB) are uploaded to the DolphinDB database as parameters of the `add` function, and the result of the function call is received in `result`.
|
|
151
|
+
|
|
152
|
+
`<number>` is used for TypeScript to infer the type of the return value.
|
|
153
|
+
|
|
154
|
+
##### Method declaration
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
/** Call a dolphindb function, passing in a native JS array as parameters, and return a native JS object or value (result after calling DdbObj.data()) */
|
|
158
|
+
async invoke <TResult = any> (
|
|
159
|
+
/** Function name */
|
|
160
|
+
func: string,
|
|
161
|
+
|
|
162
|
+
/** `[ ]` Call parameters, can be a native JS array */
|
|
163
|
+
args?: any[],
|
|
164
|
+
|
|
165
|
+
/** Call options */
|
|
166
|
+
options?: {
|
|
167
|
+
/** Urgent flag. Use urgent worker to execute, preventing being blocked by other jobs */
|
|
168
|
+
urgent?: boolean
|
|
169
|
+
|
|
170
|
+
/** When setting node alias, send to the corresponding node in the cluster to execute (using DolphinDB's rpc method) */
|
|
171
|
+
node?: string
|
|
172
|
+
|
|
173
|
+
/** When setting multiple node aliases, send to the corresponding multiple nodes in the cluster to execute (using DolphinDB's pnodeRun method) */
|
|
174
|
+
nodes?: string[]
|
|
175
|
+
|
|
176
|
+
/** Required when setting the node parameter and the parameter array is empty, specify the function type, not passed in other cases */
|
|
177
|
+
func_type?: DdbFunctionType
|
|
178
|
+
|
|
179
|
+
/** Optionally passed when setting the nodes parameter, not passed in other cases */
|
|
180
|
+
add_node_alias?: boolean
|
|
181
|
+
|
|
182
|
+
/** Handle messages (DdbMessage) during this rpc */
|
|
183
|
+
listener?: DdbMessageListener
|
|
184
|
+
} = { }
|
|
185
|
+
): Promise<TResult>
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
#### `call` method
|
|
189
|
+
|
|
190
|
+
##### Code example
|
|
191
|
+
|
|
133
192
|
```ts
|
|
134
193
|
import { DdbInt } from 'dolphindb'
|
|
135
194
|
|
|
@@ -139,22 +198,21 @@ const result = await ddb.call('add', [new DdbInt(1), new DdbInt(1)])
|
|
|
139
198
|
console.log(result.value === 2) // true
|
|
140
199
|
```
|
|
141
200
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
In the preceding example, two parameters (`new DdbInt(1)`, corresponding to the INT type in DolphinDB) are uploaded to the DolphinDB database as parameters of the add function, then the result of the function call is received.
|
|
201
|
+
###### Using DdbObj objects to represent data types in DolphinDB
|
|
145
202
|
|
|
146
|
-
|
|
203
|
+
In the example above, two parameters `new DdbInt(1)`, corresponding to the INT type in DolphinDB, are uploaded to the DolphinDB database as arguments of the `add` function, and the result of the function call is received in `result`.
|
|
147
204
|
|
|
148
|
-
|
|
149
|
-
- result.form is a `DdbForm.scalar`
|
|
150
|
-
- result.type is a `DdbType.int`
|
|
151
|
-
- result.value is data of `number` type in JavaScript (the value range and precision of INT can be accurately represented by JavaScript `number` type)
|
|
205
|
+
<DdbInt> is used by TypeScript to infer the type of the return value
|
|
152
206
|
|
|
153
|
-
|
|
207
|
+
- result is a DdbInt, which is also a DdbObj<number>
|
|
208
|
+
- result.form is a DdbForm.scalar
|
|
209
|
+
- result.type is a DdbType.int
|
|
210
|
+
- result.value is data of number type in JavaScript (the value range and precision of INT can be accurately represented by JavaScript number type)
|
|
154
211
|
|
|
155
|
-
|
|
156
|
-
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
|
|
212
|
+
It is recommended to first understand the concepts related to TypedArray in JavaScript, you can refer to:
|
|
157
213
|
|
|
214
|
+
- https://stackoverflow.com/questions/42416783/where-to-use-arraybuffer-vs-typed-array-in-javascript
|
|
215
|
+
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
|
|
158
216
|
|
|
159
217
|
```ts
|
|
160
218
|
/** Can represent all data types in DolphinDB databases */
|
|
@@ -162,10 +220,10 @@ class DdbObj <T extends DdbValue = DdbValue> {
|
|
|
162
220
|
/** is it little endian */
|
|
163
221
|
le: boolean
|
|
164
222
|
|
|
165
|
-
/** data form
|
|
223
|
+
/** DolphinDB data form */
|
|
166
224
|
form: DdbForm
|
|
167
225
|
|
|
168
|
-
/** data type
|
|
226
|
+
/** DolphinDB data type */
|
|
169
227
|
type: DdbType
|
|
170
228
|
|
|
171
229
|
/** consumed length in buf parsed */
|
|
@@ -282,13 +340,13 @@ const obj = new DdbObj({
|
|
|
282
340
|
length: 0
|
|
283
341
|
})
|
|
284
342
|
|
|
285
|
-
//
|
|
343
|
+
// easier to use shortcut classes
|
|
286
344
|
const obj = new DdbSetInt(
|
|
287
345
|
new Set([1, 2, 3])
|
|
288
346
|
)
|
|
289
347
|
```
|
|
290
348
|
|
|
291
|
-
##### NULL object in
|
|
349
|
+
##### NULL object in scalar
|
|
292
350
|
|
|
293
351
|
For the NULL object in the form of scalar, the value corresponding to DdbObj is null in JavaScript:
|
|
294
352
|
|
|
@@ -300,8 +358,8 @@ new DdbInt(null)
|
|
|
300
358
|
new DdbDouble(null)
|
|
301
359
|
```
|
|
302
360
|
|
|
361
|
+
##### Method declaration
|
|
303
362
|
|
|
304
|
-
#### `call` method declaration
|
|
305
363
|
```ts
|
|
306
364
|
async call <T extends DdbObj> (
|
|
307
365
|
/** function name */
|
|
@@ -330,9 +388,11 @@ async call <T extends DdbObj> (
|
|
|
330
388
|
): Promise<T>
|
|
331
389
|
```
|
|
332
390
|
|
|
391
|
+
### Executing scripts
|
|
392
|
+
|
|
393
|
+
#### `execute` method
|
|
394
|
+
##### Code example
|
|
333
395
|
|
|
334
|
-
### Executing the script
|
|
335
|
-
#### Example
|
|
336
396
|
```ts
|
|
337
397
|
const result = await ddb.eval(
|
|
338
398
|
'def foo (a, b) {\n' +
|
|
@@ -359,24 +419,70 @@ In the preceding example, a script is uploaded through a string to the DolphinDB
|
|
|
359
419
|
|
|
360
420
|
As long as the WebSocket connection is not disconnected, the custom function `foo` will always exist in the subsequent session and can be reused, for example, you can use `await ddb.call<DdbInt>('foo', [new DdbInt(1), new DdbInt(1)])` to call this custom function
|
|
361
421
|
|
|
362
|
-
|
|
422
|
+
##### Method declaration
|
|
423
|
+
|
|
424
|
+
```ts
|
|
425
|
+
/** Execute DolphinDB script and return a native JS object or value (result after calling DdbObj.data()) */
|
|
426
|
+
async execute <TResult = any> (
|
|
427
|
+
/** Script to execute */
|
|
428
|
+
script: string,
|
|
429
|
+
|
|
430
|
+
/** Execution options */
|
|
431
|
+
options?: {
|
|
432
|
+
/** Urgent flag, ensure the submitted script is processed using an urgent worker to prevent blocking by other jobs */
|
|
433
|
+
urgent?: boolean
|
|
434
|
+
/** listener?: Handle messages (DdbMessage) during this rpc */
|
|
435
|
+
listener?: DdbMessageListener
|
|
436
|
+
}
|
|
437
|
+
): Promise<TResult>
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
#### `eval` Method
|
|
441
|
+
|
|
442
|
+
##### Code example
|
|
443
|
+
```ts
|
|
444
|
+
const result = await ddb.eval(
|
|
445
|
+
'def foo (a, b) {\n' +
|
|
446
|
+
' return a + b\n' +
|
|
447
|
+
'}\n' +
|
|
448
|
+
'foo(1l, 1l)\n'
|
|
449
|
+
)
|
|
450
|
+
|
|
451
|
+
// TypeScript:
|
|
452
|
+
// import type { DdbLong } from 'dolphindb'
|
|
453
|
+
// const result = await ddb.eval<DdbLong>(...)
|
|
454
|
+
|
|
455
|
+
console.log(result.value === 2n) // true
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
In the example above, a script is uploaded as a string to the DolphinDB database for execution, and the result of the last statement `foo(1l, 1l)` is received in `result`.
|
|
459
|
+
|
|
460
|
+
`<DdbLong>` is used for TypeScript to infer the return value type.
|
|
461
|
+
|
|
462
|
+
- result is a `DdbLong`, also `DdbObj<bigint>`
|
|
463
|
+
- result.form is `DdbForm.scalar`
|
|
464
|
+
- result.type is `DdbType.long`
|
|
465
|
+
- result.value is a native `bigint` in JavaScript (the precision of long cannot be accurately represented by JavaScript's number, but can be represented by bigint)
|
|
466
|
+
|
|
467
|
+
##### Method declaration
|
|
363
468
|
|
|
364
469
|
```ts
|
|
470
|
+
/** Execute DolphinDB script and return a DdbObj object */
|
|
365
471
|
async eval <T extends DdbObj> (
|
|
366
|
-
/**
|
|
472
|
+
/** Script to execute */
|
|
367
473
|
script: string,
|
|
368
474
|
|
|
369
|
-
/**
|
|
475
|
+
/** Execution options */
|
|
370
476
|
options: {
|
|
371
|
-
/** Urgent flag
|
|
477
|
+
/** Urgent flag, ensure the submitted script is processed using an urgent worker to prevent blocking by other jobs */
|
|
372
478
|
urgent?: boolean
|
|
373
479
|
} = { }
|
|
374
480
|
): Promise<T>
|
|
375
481
|
```
|
|
376
482
|
|
|
483
|
+
### Upload Variables
|
|
484
|
+
#### Code example
|
|
377
485
|
|
|
378
|
-
### Uploading variables
|
|
379
|
-
#### Example
|
|
380
486
|
```ts
|
|
381
487
|
import { DdbVectorDouble } from 'dolphindb'
|
|
382
488
|
|
|
@@ -386,27 +492,28 @@ a.fill(1.0)
|
|
|
386
492
|
ddb.upload(['bar1', 'bar2'], [new DdbVectorDouble(a), new DdbVectorDouble(a)])
|
|
387
493
|
```
|
|
388
494
|
|
|
389
|
-
In the
|
|
495
|
+
In the example above, two variables `bar1` and `bar2` are uploaded, with values being double vectors of length 10000.
|
|
496
|
+
|
|
497
|
+
As long as the WebSocket connection is not disconnected, these variables `bar1` and `bar2` will always exist in subsequent sessions and can be reused.
|
|
390
498
|
|
|
391
|
-
|
|
499
|
+
#### Method declaration
|
|
392
500
|
|
|
393
|
-
#### `upload` method declaration
|
|
394
501
|
```ts
|
|
395
502
|
async upload (
|
|
396
|
-
/**
|
|
503
|
+
/** Variable names to upload */
|
|
397
504
|
vars: string[],
|
|
398
505
|
|
|
399
|
-
/**
|
|
506
|
+
/** Variable values to upload */
|
|
400
507
|
args: (DdbObj | string | boolean)[]
|
|
401
508
|
): Promise<void>
|
|
402
509
|
```
|
|
403
510
|
|
|
511
|
+
### Other Examples
|
|
404
512
|
|
|
405
|
-
### Examples
|
|
406
513
|
```ts
|
|
407
514
|
import { nulls, DdbInt, timestamp2str, DdbVectorSymbol, DdbTable, DdbVectorDouble } from 'dolphindb'
|
|
408
515
|
|
|
409
|
-
// Format timestamp in DolphinDB
|
|
516
|
+
// Format timestamp in DolphinDB to string
|
|
410
517
|
timestamp2str(
|
|
411
518
|
(
|
|
412
519
|
await ddb.call('now', [false])
|
|
@@ -414,20 +521,20 @@ timestamp2str(
|
|
|
414
521
|
).value
|
|
415
522
|
) === '2022.02.23 17:23:13.494'
|
|
416
523
|
|
|
417
|
-
//
|
|
524
|
+
// Create symbol vector
|
|
418
525
|
new DdbVectorSymbol(['aaa', 'aaa', 'aaa', 'aaa', 'aaa', 'bbb'])
|
|
419
526
|
|
|
420
|
-
// Create
|
|
527
|
+
// Create double vector with NULL values using native JavaScript array
|
|
421
528
|
new DdbVectorDouble([0.1, null, 0.3])
|
|
422
529
|
|
|
423
|
-
//
|
|
530
|
+
// Create double vector more efficiently and memory-saving using JavaScript TypedArray
|
|
424
531
|
let av = new Float64Array(3)
|
|
425
532
|
av[0] = 0.1
|
|
426
533
|
av[1] = nulls.double
|
|
427
534
|
av[2] = 0.3
|
|
428
535
|
new DdbVectorDouble(av)
|
|
429
536
|
|
|
430
|
-
//
|
|
537
|
+
// Create DdbTable
|
|
431
538
|
new DdbTable(
|
|
432
539
|
[
|
|
433
540
|
new DdbVectorDouble([0.1, 0.2, null], 'col0'),
|
|
@@ -437,18 +544,18 @@ new DdbTable(
|
|
|
437
544
|
)
|
|
438
545
|
```
|
|
439
546
|
|
|
440
|
-
### Streaming
|
|
547
|
+
### Streaming Data
|
|
441
548
|
|
|
442
549
|
```ts
|
|
443
|
-
//
|
|
550
|
+
// Create new streaming data connection configuration
|
|
444
551
|
let sddb = new DDB('ws://192.168.0.43:8800', {
|
|
445
552
|
autologin: true,
|
|
446
553
|
username: 'admin',
|
|
447
554
|
password: '123456',
|
|
448
555
|
streaming: {
|
|
449
|
-
table: '
|
|
556
|
+
table: 'name of the stream table to subscribe to',
|
|
450
557
|
|
|
451
|
-
//
|
|
558
|
+
// Stream data processing callback, message type is StreamingMessage
|
|
452
559
|
handler (message) {
|
|
453
560
|
console.log(message)
|
|
454
561
|
}
|
|
@@ -459,7 +566,7 @@ let sddb = new DDB('ws://192.168.0.43:8800', {
|
|
|
459
566
|
await sddb.connect()
|
|
460
567
|
```
|
|
461
568
|
|
|
462
|
-
|
|
569
|
+
After the connection is established, the received streaming data will be called as the `message` parameter of the `handler`, and the message type is `StreamingMessage`, as follows:
|
|
463
570
|
|
|
464
571
|
```ts
|
|
465
572
|
export interface StreamingParams {
|
|
@@ -470,50 +577,42 @@ export interface StreamingParams {
|
|
|
470
577
|
}
|
|
471
578
|
|
|
472
579
|
export interface StreamingMessage <TRows = any> extends StreamingParams {
|
|
473
|
-
/**
|
|
474
|
-
|
|
475
|
-
std::chrono::system_clock::now().time_since_epoch() / std::chrono::nanoseconds(1)
|
|
476
|
-
*/
|
|
580
|
+
/** The time when the server sends the message (nano seconds since epoch)
|
|
581
|
+
std::chrono::system_clock::now().time_since_epoch() / std::chrono::nanoseconds(1) */
|
|
477
582
|
time: bigint
|
|
478
583
|
|
|
479
|
-
/**
|
|
584
|
+
/** Message ID */
|
|
480
585
|
id: bigint
|
|
481
586
|
|
|
482
|
-
/** Subscription topic,
|
|
483
|
-
It is a string
|
|
484
|
-
*/
|
|
587
|
+
/** Subscription topic, i.e., the name of a subscription.
|
|
588
|
+
It is a string composed of the alias of the node where the subscription table is located, the name of the stream table, and the name of the subscription task (if actionName is specified), separated by `/` */
|
|
485
589
|
topic: string
|
|
486
590
|
|
|
487
|
-
/** Streaming data
|
|
488
|
-
obj: DdbObj<DdbVectorObj[]>
|
|
489
|
-
|
|
490
|
-
/** Streaming data, each element of the data attribute in the object corresponds to a row in the incremental data of the subscribed table */
|
|
591
|
+
/** Streaming data */
|
|
491
592
|
data: DdbTableData<TRows>
|
|
492
593
|
|
|
493
594
|
window: {
|
|
494
|
-
/**
|
|
595
|
+
/** Offset from the start of the connection, starting at 0, and increasing as the window moves */
|
|
495
596
|
offset: number
|
|
496
597
|
|
|
497
598
|
/** Historical data */
|
|
498
599
|
data: TRows[]
|
|
499
600
|
|
|
500
|
-
/**
|
|
601
|
+
/** Array of objects received each time */
|
|
501
602
|
objs: DdbObj<DdbVectorObj[]>[]
|
|
502
603
|
}
|
|
503
604
|
|
|
504
|
-
/**
|
|
605
|
+
/** If there is an error in parsing the message pushed after the successful subscription, the error is set and the handler is called */
|
|
505
606
|
error?: Error
|
|
506
607
|
}
|
|
507
608
|
```
|
|
508
609
|
|
|
509
|
-
|
|
510
|
-
### Development
|
|
610
|
+
## Development Method
|
|
511
611
|
|
|
512
612
|
```shell
|
|
513
|
-
# Install the latest version of nodejs
|
|
514
|
-
# https://nodejs.org/en/download/current/
|
|
613
|
+
# Install the latest version of nodejs (see above)
|
|
515
614
|
|
|
516
|
-
# Install
|
|
615
|
+
# Install pnpm package manager
|
|
517
616
|
npm install -g pnpm
|
|
518
617
|
|
|
519
618
|
git clone https://github.com/dolphindb/api-javascript.git
|
|
@@ -526,18 +625,18 @@ pnpm install
|
|
|
526
625
|
# Copy .vscode/settings.template.json to .vscode/settings.json
|
|
527
626
|
cp .vscode/settings.template.json .vscode/settings.json
|
|
528
627
|
|
|
529
|
-
# Refer to scripts in package.json
|
|
628
|
+
# Refer to the scripts in package.json
|
|
530
629
|
|
|
531
|
-
#
|
|
630
|
+
# Build
|
|
532
631
|
pnpm run build
|
|
533
632
|
|
|
534
|
-
#
|
|
633
|
+
# Lint
|
|
535
634
|
pnpm run lint
|
|
536
635
|
|
|
537
|
-
#
|
|
636
|
+
# Test
|
|
538
637
|
pnpm run test
|
|
539
638
|
|
|
540
|
-
#
|
|
639
|
+
# Scan entries
|
|
541
640
|
pnpm run scan
|
|
542
641
|
# Manually complete untranslated entries
|
|
543
642
|
# Run the scan again to update the dictionary file dict.json
|
package/browser.d.ts
CHANGED
|
@@ -411,7 +411,7 @@ export interface ConvertOptions {
|
|
|
411
411
|
/** timestamp 类型转换为字符串表示时显示到秒还是毫秒 */
|
|
412
412
|
timestamp?: 's' | 'ms';
|
|
413
413
|
}
|
|
414
|
-
export declare function convert(type: DdbType, value: DdbValue, le: boolean, { blob, timestamp }?: ConvertOptions): string | number | bigint | boolean | Uint8Array | DdbFunctionDefValue | DdbDurationValue | DdbDecimal32Value | DdbDecimal64Value |
|
|
414
|
+
export declare function convert(type: DdbType, value: DdbValue, le: boolean, { blob, timestamp }?: ConvertOptions): string | number | bigint | boolean | Uint8Array | number[] | DdbFunctionDefValue | DdbDurationValue | DdbDecimal32Value | DdbDecimal64Value | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | BigInt128Array | string[] | Uint8Array[] | DdbObj<DdbValue>[] | DdbSymbolExtendedValue | DdbArrayVectorValue | DdbDecimal32VectorValue | DdbDecimal64VectorValue | DdbDecimal128VectorValue | DdbDurationVectorValue | DdbMatrixValue | DdbChartValue | DdbTensorValue;
|
|
415
415
|
/** 转换一个向量到 js 原生数组 */
|
|
416
416
|
export declare function converts(type: DdbType, value: DdbVectorValue, rows: number, le: boolean, options?: ConvertOptions): any[];
|
|
417
417
|
export declare class DdbVoid extends DdbObj<undefined> {
|