dolphindb 2.0.503 → 2.0.506
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 +37 -32
- package/README.zh.md +29 -24
- package/browser.d.ts +82 -38
- package/browser.js +233 -108
- package/browser.js.map +1 -1
- package/index.d.ts +72 -31
- package/index.js +222 -108
- package/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -54,23 +54,24 @@ let ddb = new DDB('ws://127.0.0.1:8848')
|
|
|
54
54
|
await ddb.connect()
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
####
|
|
57
|
+
#### DDB options
|
|
58
58
|
```ts
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
59
|
+
let ddb = new DDB('ws://127.0.0.1:8848')
|
|
60
|
+
|
|
61
|
+
// Encrypt with HTTPS
|
|
62
|
+
let ddbsecure = new DDB('wss://dolphindb.com', {
|
|
63
|
+
// Whether to log in automatically after establishing a connection, default `true`
|
|
64
|
+
autologin: true,
|
|
65
|
+
|
|
66
|
+
// DolphinDB username, default `'admin'`
|
|
67
|
+
username: 'admin',
|
|
68
|
+
|
|
69
|
+
// DolphinDB password, default `'123456'`
|
|
70
|
+
password: '123456',
|
|
71
|
+
|
|
72
|
+
// set python session flag, default `false`
|
|
73
|
+
python: false
|
|
74
|
+
})
|
|
74
75
|
```
|
|
75
76
|
|
|
76
77
|
|
|
@@ -187,37 +188,41 @@ enum DdbType {
|
|
|
187
188
|
}
|
|
188
189
|
```
|
|
189
190
|
|
|
190
|
-
#####
|
|
191
|
+
##### If there is no shortcut class, you can also specify form and type to manually create a DdbObj object
|
|
191
192
|
```ts
|
|
193
|
+
// Created by the DdbDateTime shortcut class
|
|
194
|
+
new DdbDateTime(1644573600)
|
|
195
|
+
|
|
196
|
+
// Equivalent to manually creating an object of form = scalar, type = datetime through DdbObj
|
|
192
197
|
const obj = new DdbObj({
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
198
|
+
form: DdbForm.scalar,
|
|
199
|
+
type: DdbType.datetime,
|
|
200
|
+
value: 1644573600,
|
|
201
|
+
length: 0
|
|
197
202
|
})
|
|
198
|
-
```
|
|
199
203
|
|
|
200
|
-
The corresponding type and value of value property in js can refer to the result returned by `ddb.eval` (see below: `eval` Method Declaration)
|
|
201
204
|
|
|
202
|
-
|
|
205
|
+
// The corresponding type and value of value in js can refer to the result returned by ddb.eval (see the `eval` method declaration below)
|
|
203
206
|
const obj = await ddb.eval('2022.02.11 10:00:00')
|
|
204
207
|
console.log(obj.form === DdbForm.scalar)
|
|
205
208
|
console.log(obj.type === DdbType.datetime)
|
|
206
209
|
console.log(obj.value)
|
|
207
|
-
```
|
|
208
210
|
|
|
209
|
-
|
|
210
|
-
```ts
|
|
211
|
+
// Another example is to create a set
|
|
211
212
|
// refer to ddb.eval
|
|
212
213
|
// const obj = await ddb.eval('set([1, 2, 3])')
|
|
213
214
|
// console.log(obj.value)
|
|
214
|
-
|
|
215
215
|
const obj = new DdbObj({
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
216
|
+
form: DdbForm.set,
|
|
217
|
+
type: DdbType.int,
|
|
218
|
+
value: Int32Array.of(1, 2, 3),
|
|
219
|
+
length: 0
|
|
220
220
|
})
|
|
221
|
+
|
|
222
|
+
// It's easier to use shortcut classes
|
|
223
|
+
const obj = new DdbSetInt(
|
|
224
|
+
new Set([1, 2, 3])
|
|
225
|
+
)
|
|
221
226
|
```
|
|
222
227
|
|
|
223
228
|
##### NULL object in the form of scalar, the value corresponding to DdbObj is null in JavaScript
|
package/README.zh.md
CHANGED
|
@@ -55,23 +55,24 @@ let ddb = new DDB('ws://127.0.0.1:8848')
|
|
|
55
55
|
await ddb.connect()
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
-
####
|
|
58
|
+
#### DDB 选项
|
|
59
59
|
```ts
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
60
|
+
let ddb = new DDB('ws://127.0.0.1:8848')
|
|
61
|
+
|
|
62
|
+
// 使用 HTTPS 加密
|
|
63
|
+
let ddbsecure = new DDB('wss://dolphindb.com', {
|
|
64
|
+
// 是否在建立连接后自动登录,默认 `true`
|
|
65
|
+
autologin: true,
|
|
66
|
+
|
|
67
|
+
// DolphinDB 登录用户名,默认 `'admin'`
|
|
68
|
+
username: 'admin',
|
|
69
|
+
|
|
70
|
+
// DolphinDB 登录密码,默认 `'123456'`
|
|
71
|
+
password: '123456',
|
|
72
|
+
|
|
73
|
+
// 设置 python session flag,默认 `false`
|
|
74
|
+
python: false
|
|
75
|
+
})
|
|
75
76
|
```
|
|
76
77
|
|
|
77
78
|
|
|
@@ -188,37 +189,41 @@ enum DdbType {
|
|
|
188
189
|
}
|
|
189
190
|
```
|
|
190
191
|
|
|
191
|
-
#####
|
|
192
|
+
##### 没有快捷类的类型,也可以指定 form 和 type 手动创建 DdbObj 对象
|
|
192
193
|
```ts
|
|
194
|
+
// 通过 DdbDateTime 快捷类创建
|
|
195
|
+
new DdbDateTime(1644573600)
|
|
196
|
+
|
|
197
|
+
// 等价于手动通过 DdbObj 创建 form = scalar, type = datetime 的对象
|
|
193
198
|
const obj = new DdbObj({
|
|
194
199
|
form: DdbForm.scalar,
|
|
195
200
|
type: DdbType.datetime,
|
|
196
201
|
value: 1644573600,
|
|
197
202
|
length: 0
|
|
198
203
|
})
|
|
199
|
-
```
|
|
200
204
|
|
|
201
|
-
value 的在 js 中对应类型及取值可以参考 ddb.eval 返回的结果 (见后文 `eval` 方法声明)
|
|
202
205
|
|
|
203
|
-
|
|
206
|
+
// value 在 js 中对应类型及取值可以参考 ddb.eval 返回的结果 (见后文 `eval` 方法声明)
|
|
204
207
|
const obj = await ddb.eval('2022.02.11 10:00:00')
|
|
205
208
|
console.log(obj.form === DdbForm.scalar)
|
|
206
209
|
console.log(obj.type === DdbType.datetime)
|
|
207
210
|
console.log(obj.value)
|
|
208
|
-
```
|
|
209
211
|
|
|
210
|
-
|
|
211
|
-
```ts
|
|
212
|
+
// 再比如创建一个 set
|
|
212
213
|
// 参考 ddb.eval
|
|
213
214
|
// const obj = await ddb.eval('set([1, 2, 3])')
|
|
214
215
|
// console.log(obj.value)
|
|
215
|
-
|
|
216
216
|
const obj = new DdbObj({
|
|
217
217
|
form: DdbForm.set,
|
|
218
218
|
type: DdbType.int,
|
|
219
219
|
value: Int32Array.of(1, 2, 3),
|
|
220
220
|
length: 0
|
|
221
221
|
})
|
|
222
|
+
|
|
223
|
+
// 使用快捷类较为简单
|
|
224
|
+
const obj = new DdbSetInt(
|
|
225
|
+
new Set([1, 2, 3])
|
|
226
|
+
)
|
|
222
227
|
```
|
|
223
228
|
|
|
224
229
|
##### scalar 形式的 NULL 对象, 对应 DdbObj 的 value 为 JavaScript 中的 null
|
package/browser.d.ts
CHANGED
|
@@ -75,11 +75,10 @@ export interface DdbArrayVectorBlock {
|
|
|
75
75
|
lengths: Uint8Array | Uint16Array | Uint32Array;
|
|
76
76
|
data: DdbVectorValue;
|
|
77
77
|
}
|
|
78
|
-
export declare type DdbValue = null | boolean | number | [number, number] | bigint | string | string[] | Uint8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | Uint8Array[] | DdbObj[] | DdbFunctionDefValue | DdbSymbolExtendedValue | DdbArrayVectorBlock[];
|
|
79
|
-
export declare type DdbVectorValue = string | string[] | Uint8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | Uint8Array[] | DdbObj[] | DdbSymbolExtendedValue | DdbArrayVectorBlock[];
|
|
78
|
+
export declare type DdbValue = null | boolean | number | [number, number] | bigint | string | string[] | Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | Uint8Array[] | DdbObj[] | DdbFunctionDefValue | DdbSymbolExtendedValue | DdbArrayVectorBlock[];
|
|
79
|
+
export declare type DdbVectorValue = string | string[] | Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | Uint8Array[] | DdbObj[] | DdbSymbolExtendedValue | DdbArrayVectorBlock[];
|
|
80
80
|
export declare const nulls: {
|
|
81
|
-
readonly
|
|
82
|
-
readonly char: "";
|
|
81
|
+
readonly int8: -128;
|
|
83
82
|
readonly int16: -32768;
|
|
84
83
|
readonly int32: -2147483648;
|
|
85
84
|
readonly int64: -9223372036854775808n;
|
|
@@ -125,6 +124,8 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
|
|
|
125
124
|
datatype?: DdbType;
|
|
126
125
|
/** 实际数据。不同的 DdbForm, DdbType 使用 DdbValue 中不同的类型来表示实际数据 */
|
|
127
126
|
value: T;
|
|
127
|
+
/** 原始二进制数据 */
|
|
128
|
+
buffer?: Uint8Array;
|
|
128
129
|
constructor(data: Partial<DdbObj> & {
|
|
129
130
|
form: DdbForm;
|
|
130
131
|
type: DdbType;
|
|
@@ -159,7 +160,7 @@ export declare class DdbBool extends DdbObj<boolean> {
|
|
|
159
160
|
constructor(value: boolean | null);
|
|
160
161
|
}
|
|
161
162
|
export declare class DdbChar extends DdbObj<string> {
|
|
162
|
-
constructor(value: string | null);
|
|
163
|
+
constructor(value: string | number | null);
|
|
163
164
|
}
|
|
164
165
|
export declare class DdbInt extends DdbObj<number> {
|
|
165
166
|
constructor(value: number | null);
|
|
@@ -191,18 +192,27 @@ export declare class DdbFunction extends DdbObj<DdbFunctionDefValue> {
|
|
|
191
192
|
export declare class DdbVectorInt extends DdbObj<Int32Array> {
|
|
192
193
|
constructor(ints: (number | null)[] | Int32Array, name?: string);
|
|
193
194
|
}
|
|
194
|
-
export declare class DdbVectorString extends DdbObj<string[]> {
|
|
195
|
-
constructor(strings: string[], name?: string);
|
|
196
|
-
}
|
|
197
195
|
export declare class DdbVectorDouble extends DdbObj<Float64Array> {
|
|
198
196
|
constructor(doubles: (number | null)[] | Float64Array, name?: string);
|
|
199
197
|
}
|
|
198
|
+
export declare class DdbVectorString extends DdbObj<string[]> {
|
|
199
|
+
constructor(strings: string[], name?: string);
|
|
200
|
+
}
|
|
200
201
|
export declare class DdbVectorAny extends DdbObj {
|
|
201
202
|
constructor(objs: DdbObj<DdbValue>[], name?: string);
|
|
202
203
|
}
|
|
203
204
|
export declare class DdbVectorSymbol extends DdbObj<DdbSymbolExtendedValue> {
|
|
204
205
|
constructor(strings: string[], name?: string);
|
|
205
206
|
}
|
|
207
|
+
export declare class DdbSetInt extends DdbObj<Int32Array> {
|
|
208
|
+
constructor(ints: (number | null)[] | Set<number> | Int32Array);
|
|
209
|
+
}
|
|
210
|
+
export declare class DdbSetDouble extends DdbObj<Float64Array> {
|
|
211
|
+
constructor(doubles: (number | null)[] | Set<number> | Float64Array);
|
|
212
|
+
}
|
|
213
|
+
export declare class DdbSetString extends DdbObj<string[]> {
|
|
214
|
+
constructor(strings: string[] | Set<string>);
|
|
215
|
+
}
|
|
206
216
|
export declare class DdbTable extends DdbObj<DdbObj[]> {
|
|
207
217
|
constructor(columns: DdbObj[], name?: string);
|
|
208
218
|
}
|
|
@@ -261,13 +271,16 @@ export declare class DDB {
|
|
|
261
271
|
password: string;
|
|
262
272
|
/** python session flag (2048) */
|
|
263
273
|
python: boolean;
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
274
|
+
print_message_buffer: boolean;
|
|
275
|
+
print_object_buffer: boolean;
|
|
276
|
+
print_message: boolean;
|
|
277
|
+
parse_object: boolean;
|
|
278
|
+
/** message handlers */
|
|
279
|
+
handlers: DdbMessageHandler[];
|
|
267
280
|
/** resolver, rejector, promise of last rpc */
|
|
268
|
-
presolver(
|
|
281
|
+
presolver(ddbobj: DdbObj): void;
|
|
269
282
|
prejector(error: Error): void;
|
|
270
|
-
presult: Promise<
|
|
283
|
+
presult: Promise<DdbObj<DdbValue>>;
|
|
271
284
|
get connected(): boolean;
|
|
272
285
|
/**
|
|
273
286
|
Initialize an instance of DolphinDB Client using the WebSocket URL
|
|
@@ -281,6 +294,8 @@ export declare class DDB {
|
|
|
281
294
|
|
|
282
295
|
@example
|
|
283
296
|
let ddb = new DDB('ws://127.0.0.1:8848')
|
|
297
|
+
|
|
298
|
+
// Encrypt with HTTPS
|
|
284
299
|
let ddbsecure = new DDB('wss://dolphindb.com', {
|
|
285
300
|
autologin: true,
|
|
286
301
|
username: 'admin',
|
|
@@ -338,58 +353,87 @@ export declare class DDB {
|
|
|
338
353
|
- options:
|
|
339
354
|
- urgent?: 决定 `行为标识` 那一行字符串的取值(只适用于 script 和 function)
|
|
340
355
|
- vars?: type === 'variable' 时必传,variable 指令中待上传的变量名
|
|
356
|
+
- handler?: 处理本次 rpc 期间的消息
|
|
357
|
+
- parse_object?: 在本次 rpc 期间设置 parse_object, 结束后恢复原有
|
|
358
|
+
为 false 时返回的 DdbObj 仅含有 buffer 和 le,不做解析,以便后续转发、序列化
|
|
341
359
|
*/
|
|
342
|
-
rpc<T extends DdbObj = DdbObj>(type: 'script' | 'function' | 'variable' | 'connect', { script, func, args, vars, urgent, }: {
|
|
360
|
+
rpc<T extends DdbObj = DdbObj>(type: 'script' | 'function' | 'variable' | 'connect', { script, func, args, vars, urgent, handler, parse_object, }: {
|
|
343
361
|
script?: string;
|
|
344
362
|
func?: string;
|
|
345
363
|
args?: (DdbObj | string | boolean)[];
|
|
346
364
|
vars?: string[];
|
|
347
365
|
urgent?: boolean;
|
|
366
|
+
handler?: DdbMessageHandler;
|
|
367
|
+
parse_object?: boolean;
|
|
348
368
|
}): Promise<T>;
|
|
349
|
-
/** eval script through websocket (script command)
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
369
|
+
/** eval script through websocket (script command)
|
|
370
|
+
- script?: Script to execute
|
|
371
|
+
- options?: execution options
|
|
372
|
+
- urgent?: Urgent flag to ensure that submitted scripts are processed by urgent workers to prevent being blocked by other jobs
|
|
373
|
+
- handler?: Process messages during this rpc
|
|
374
|
+
- parse_object?: Set parse_object during this rpc, and restore the original after the end.
|
|
375
|
+
When it is false, the returned DdbObj only contains buffer and le without parsing,
|
|
376
|
+
so as to facilitate subsequent forwarding and serialization
|
|
377
|
+
*/
|
|
378
|
+
eval<T extends DdbObj>(script: string, { urgent, handler, parse_object, }?: {
|
|
356
379
|
urgent?: boolean;
|
|
380
|
+
handler?: DdbMessageHandler;
|
|
381
|
+
parse_object?: boolean;
|
|
357
382
|
}): Promise<T>;
|
|
358
383
|
/** call function through websocket (function command)
|
|
359
|
-
- func:
|
|
360
|
-
- args?: `[ ]`
|
|
361
|
-
- options?:
|
|
362
|
-
- urgent?:
|
|
363
|
-
- node?:
|
|
364
|
-
- nodes?:
|
|
365
|
-
- func_type?:
|
|
366
|
-
- add_node_alias?:
|
|
384
|
+
- func: function name
|
|
385
|
+
- args?: `[ ]` Call parameters (the incoming native string and boolean will be automatically converted to DdbObj<string> and DdbObj<boolean>)
|
|
386
|
+
- options?: call options
|
|
387
|
+
- urgent?: Emergency flag. Use urgent worker execution to prevent being blocked by other jobs
|
|
388
|
+
- node?: When the node alias is set, it is sent to the corresponding node in the cluster for execution (using the rpc method in DolphinDB)
|
|
389
|
+
- nodes?: When setting multiple node aliases, send them to the corresponding multiple nodes in the cluster for execution (using the pnodeRun method in DolphinDB)
|
|
390
|
+
- func_type?: It must be passed when setting the node parameter, the function type needs to be specified, and it is not passed in other cases
|
|
391
|
+
- add_node_alias?: Select to pass when setting the nodes parameter, otherwise not pass
|
|
392
|
+
- handler?: Process messages during this rpc
|
|
393
|
+
- parse_object?: Set parse_object during this rpc, and restore the original after the end.
|
|
394
|
+
When it is false, the returned DdbObj only contains buffer and le without parsing,
|
|
395
|
+
so as to facilitate subsequent forwarding and serialization
|
|
367
396
|
*/
|
|
368
|
-
call<T extends DdbObj>(func: string, args?: (DdbObj | string | boolean)[], { urgent, node, nodes, func_type, add_node_alias }?: {
|
|
397
|
+
call<T extends DdbObj>(func: string, args?: (DdbObj | string | boolean)[], { urgent, node, nodes, func_type, add_node_alias, handler, parse_object, }?: {
|
|
369
398
|
urgent?: boolean;
|
|
370
399
|
node?: string;
|
|
371
400
|
nodes?: string[];
|
|
372
401
|
func_type?: DdbFunctionType;
|
|
373
402
|
add_node_alias?: boolean;
|
|
403
|
+
handler?: DdbMessageHandler;
|
|
404
|
+
parse_object?: boolean;
|
|
374
405
|
}): Promise<T>;
|
|
375
406
|
/** upload variable through websocket (variable command) */
|
|
376
407
|
upload(
|
|
377
408
|
/** Uploaded variables' name */
|
|
378
409
|
vars: string[],
|
|
379
410
|
/** Uploaded variables' value */
|
|
380
|
-
args: (DdbObj | string | boolean)[]
|
|
411
|
+
args: (DdbObj | string | boolean)[], { handler, parse_object, }?: {
|
|
412
|
+
handler?: DdbMessageHandler;
|
|
413
|
+
parse_object?: boolean;
|
|
414
|
+
}): Promise<DdbObj<DdbValue>>;
|
|
381
415
|
/** 解析服务端响应报文,返回去掉 header 的 data buf */
|
|
382
|
-
parse_message(buf: Uint8Array):
|
|
383
|
-
type: "message";
|
|
384
|
-
data: string;
|
|
385
|
-
} | {
|
|
386
|
-
type: "object";
|
|
387
|
-
data: Uint8Array;
|
|
388
|
-
};
|
|
416
|
+
parse_message(buf: Uint8Array, parse_object?: boolean): DdbMessage;
|
|
389
417
|
/** 自动转换 js string, boolean 为 DdbObj */
|
|
390
418
|
to_ddbobj(value: DdbObj | string | boolean): DdbObj;
|
|
391
419
|
/** 转换 js 数组为 DdbObj[] */
|
|
392
420
|
to_ddbobjs(values: any[]): DdbObj<DdbValue>[];
|
|
393
421
|
}
|
|
422
|
+
export interface DdbMessageHandler {
|
|
423
|
+
(message: DdbMessage, _this: DDB): any;
|
|
424
|
+
}
|
|
425
|
+
export interface DdbPrintMessage {
|
|
426
|
+
type: 'print';
|
|
427
|
+
data: string;
|
|
428
|
+
}
|
|
429
|
+
export interface DdbObjectMessage {
|
|
430
|
+
type: 'object';
|
|
431
|
+
data: DdbObj;
|
|
432
|
+
}
|
|
433
|
+
export interface DdbErrorMessage {
|
|
434
|
+
type: 'error';
|
|
435
|
+
data: Error;
|
|
436
|
+
}
|
|
437
|
+
export declare type DdbMessage = DdbPrintMessage | DdbObjectMessage | DdbErrorMessage;
|
|
394
438
|
export declare let ddb: DDB;
|
|
395
439
|
export default ddb;
|