dolphindb 2.0.502 → 2.0.505

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
@@ -54,23 +54,24 @@ let ddb = new DDB('ws://127.0.0.1:8848')
54
54
  await ddb.connect()
55
55
  ```
56
56
 
57
- #### Connect Method Declaration
57
+ #### DDB options
58
58
  ```ts
59
- async connect (
60
- options?: {
61
- /** by default, the WebSocket URL passed in when the instance is initialized is used */
62
- ws_url?: string
63
-
64
- /** whether to automatically log in after the connection is established, the default is true */
65
- login?: boolean
66
-
67
- /** DolphinDB username */
68
- username?: string
69
-
70
- /** DolphinDB password */
71
- password?: string
72
- } = { }
73
- ): Promise<void>
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
- ##### For types that are not in the utility classes, such as the datetime type in DolphinDB, we can specify form and type to create a DdbObj object
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
- form: DdbForm.scalar,
194
- type: DdbType.datetime,
195
- value: 1644573600,
196
- length: 0
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
- ```ts
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
- ##### Another example is to create a set
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
- form: DdbForm.set,
217
- type: DdbType.int,
218
- value: Int32Array.of(1, 2, 3),
219
- length: 0
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
- #### connect 方法声明
58
+ #### DDB 选项
59
59
  ```ts
60
- async connect (
61
- options?: {
62
- /** 默认使用实例初始化时传入的 WebSocket 链接 */
63
- ws_url?: string
64
-
65
- /** 是否在建立连接后自动登录,默认 true */
66
- login?: boolean
67
-
68
- /** DolphinDB 登录用户名 */
69
- username?: string
70
-
71
- /** DolphinDB 登录密码 */
72
- password?: string
73
- } = { }
74
- ): Promise<void>
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
- ##### 不在快捷类中的类型,比如 DolphinDB 中的 datetime 类型, 可以指定 form 和 type 创建 DdbObj 对象
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
- ```ts
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
- ##### 再比如创建一个 set
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 bool: 128;
82
- readonly char: "€";
81
+ readonly int8: -128;
83
82
  readonly int16: -32768;
84
83
  readonly int32: -2147483648;
85
84
  readonly int64: -9223372036854775808n;
@@ -93,7 +92,9 @@ export declare const timezone_offset: number;
93
92
  export declare class DdbObj<T extends DdbValue = DdbValue> {
94
93
  static dec: TextDecoder;
95
94
  static enc: TextEncoder;
96
- /** 维护已解析的 symbol base,比如流数据中后续的 symbol 向量可能只发送一个 base.id, base.size == 0, 依赖之前发送的 symbol base */
95
+ /** 维护已解析的 symbol base,比如流数据中后续的 symbol 向量可能只发送一个 base.id, base.size == 0, 依赖之前发送的 symbol base ?
96
+ 只是暂存,如果一张表有多个 symbol 列,可能这个 symbol base 会被复用,不同的对象之间 symbol base 一般不复用
97
+ */
97
98
  static symbol_bases: Record<number, string[]>;
98
99
  /** little endian (client) */
99
100
  static le_client: boolean;
@@ -123,6 +124,8 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
123
124
  datatype?: DdbType;
124
125
  /** 实际数据。不同的 DdbForm, DdbType 使用 DdbValue 中不同的类型来表示实际数据 */
125
126
  value: T;
127
+ /** 原始二进制数据 */
128
+ buffer?: Uint8Array;
126
129
  constructor(data: Partial<DdbObj> & {
127
130
  form: DdbForm;
128
131
  type: DdbType;
@@ -157,7 +160,7 @@ export declare class DdbBool extends DdbObj<boolean> {
157
160
  constructor(value: boolean | null);
158
161
  }
159
162
  export declare class DdbChar extends DdbObj<string> {
160
- constructor(value: string | null);
163
+ constructor(value: string | number | null);
161
164
  }
162
165
  export declare class DdbInt extends DdbObj<number> {
163
166
  constructor(value: number | null);
@@ -189,18 +192,27 @@ export declare class DdbFunction extends DdbObj<DdbFunctionDefValue> {
189
192
  export declare class DdbVectorInt extends DdbObj<Int32Array> {
190
193
  constructor(ints: (number | null)[] | Int32Array, name?: string);
191
194
  }
192
- export declare class DdbVectorString extends DdbObj<string[]> {
193
- constructor(strings: string[], name?: string);
194
- }
195
195
  export declare class DdbVectorDouble extends DdbObj<Float64Array> {
196
196
  constructor(doubles: (number | null)[] | Float64Array, name?: string);
197
197
  }
198
+ export declare class DdbVectorString extends DdbObj<string[]> {
199
+ constructor(strings: string[], name?: string);
200
+ }
198
201
  export declare class DdbVectorAny extends DdbObj {
199
202
  constructor(objs: DdbObj<DdbValue>[], name?: string);
200
203
  }
201
204
  export declare class DdbVectorSymbol extends DdbObj<DdbSymbolExtendedValue> {
202
205
  constructor(strings: string[], name?: string);
203
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
+ }
204
216
  export declare class DdbTable extends DdbObj<DdbObj[]> {
205
217
  constructor(columns: DdbObj[], name?: string);
206
218
  }
@@ -251,35 +263,62 @@ export declare class DDB {
251
263
  le: boolean;
252
264
  /** little endian (client) */
253
265
  static le_client: boolean;
266
+ /** Whether to automatically log in after the connection is established, the default is true */
267
+ autologin: boolean;
268
+ /** DolphinDB username */
269
+ username: string;
270
+ /** DolphinDB password */
271
+ password: string;
254
272
  /** python session flag (2048) */
255
273
  python: boolean;
256
- message_hook: (message: Uint8Array) => any;
257
- /** print message handler */
258
- printer(message: string): void;
274
+ parse_object: boolean;
275
+ /** message handler */
276
+ on_message({ type, data }: DdbMessage, _this: DDB): void;
259
277
  /** resolver, rejector, promise of last rpc */
260
- presolver(buf: Uint8Array): void;
278
+ presolver(message: DdbMessage): void;
261
279
  prejector(error: Error): void;
262
- presult: Promise<Uint8Array>;
280
+ presult: Promise<DdbMessage>;
263
281
  get connected(): boolean;
264
282
  /**
265
283
  Initialize an instance of DolphinDB Client using the WebSocket URL
266
284
  (without establishing an actual network connection)
285
+ - url?: DolphinDB WebSocket URL. e.g.:`ws://127.0.0.1:8848`, Defaults to the current page URL
286
+ - options?:
287
+ - autologin?: Whether to log in automatically after establishing a connection, default `true`
288
+ - username?: DolphinDB username, default `'admin'`
289
+ - password?: DolphinDB password, default `'123456'`
290
+ - python?: set python session flag, default `false`
291
+
267
292
  @example
268
293
  let ddb = new DDB('ws://127.0.0.1:8848')
269
- let ddb_secure = new DDB('wss://dolphindb.com')
294
+
295
+ // 使用 HTTPS 加密
296
+ let ddbsecure = new DDB('wss://dolphindb.com', {
297
+ autologin: true,
298
+ username: 'admin',
299
+ password: '123456',
300
+ python: false
301
+ })
270
302
  */
271
- constructor(url?: string);
272
- /** Establish the actual WebSocket connection to the DolphinDB corresponding to the URL */
273
- connect({ url, login, username, password, python, }?: {
274
- /** By default, the WebSocket URL passed in when the instance is initialized is used */
303
+ constructor(url?: string, options?: {
304
+ autologin?: boolean;
305
+ username?: string;
306
+ password?: string;
307
+ python?: boolean;
308
+ });
309
+ /** Establish the actual WebSocket connection to the DolphinDB corresponding to the URL
310
+ - options?:
311
+ - url?: DolphinDB WebSocket URL. By default, the WebSocket URL passed in when the instance is initialized is used
312
+ - autologin?: Whether to log in automatically after establishing a connection, default `true`
313
+ - username?: DolphinDB username, default `'admin'`
314
+ - password?: DolphinDB password, default `'123456'`
315
+ - python?: set python session flag, default `false`
316
+ */
317
+ connect(options?: {
275
318
  url?: string;
276
- /** Whether to automatically log in after the connection is established, the default is true */
277
- login?: boolean;
278
- /** DolphinDB username */
319
+ autologin?: boolean;
279
320
  username?: string;
280
- /** DolphinDB password */
281
321
  password?: string;
282
- /** set python session flag */
283
322
  python?: boolean;
284
323
  }): Promise<void>;
285
324
  get_rpc_options({ urgent, secondary, async: _async, pickle, clear, api, compress, cancellable, priority, parallelism, root_id, limit, }?: {
@@ -311,58 +350,80 @@ export declare class DDB {
311
350
  - options:
312
351
  - urgent?: 决定 `行为标识` 那一行字符串的取值(只适用于 script 和 function)
313
352
  - vars?: type === 'variable' 时必传,variable 指令中待上传的变量名
353
+ - on_message?: 在该次 rpc 期间设置 message handler, 结束后恢复原有
354
+ - parse_object?: 在该次 rpc 期间设置 parse_object, 结束后恢复原有,为 false 时返回的 DdbObj 仅含有 buffer 和 le,
355
+ 不做解析,以便后续转发、序列化
314
356
  */
315
- rpc<T extends DdbObj = DdbObj>(type: 'script' | 'function' | 'variable' | 'connect', { script, func, args, vars, urgent, }: {
357
+ rpc<T extends DdbObj = DdbObj>(type: 'script' | 'function' | 'variable' | 'connect', { script, func, args, vars, urgent, on_message, parse_object, }: {
316
358
  script?: string;
317
359
  func?: string;
318
360
  args?: (DdbObj | string | boolean)[];
319
361
  vars?: string[];
320
362
  urgent?: boolean;
363
+ on_message?: DDB['on_message'];
364
+ parse_object?: boolean;
321
365
  }): Promise<T>;
322
- /** eval script through websocket (script command) */
323
- eval<T extends DdbObj>(
324
- /** 执行的脚本 */
325
- script: string,
326
- /** 执行选项 */
327
- { urgent }?: {
328
- /** 紧急 flag,确保提交的脚本使用 urgent worker 处理,防止被其它作业阻塞 */
366
+ /** eval script through websocket (script command)
367
+ - script?: Script to execute
368
+ - options?: execution options
369
+ - urgent?: Urgent flag to ensure that submitted scripts are processed by urgent workers to prevent being blocked by other jobs
370
+ - on_message?: Set the message handler during this rpc, and restore the original after the end
371
+ - parse_object?: Set parse_object during this rpc, and restore the original after the end.
372
+ When it is false, the returned DdbObj only contains buffer and le without parsing,
373
+ so as to facilitate subsequent forwarding and serialization
374
+ */
375
+ eval<T extends DdbObj>(script: string, { urgent, on_message, parse_object, }?: {
329
376
  urgent?: boolean;
377
+ on_message?: DDB['on_message'];
378
+ parse_object?: boolean;
330
379
  }): Promise<T>;
331
380
  /** call function through websocket (function command)
332
- - func: 函数名
333
- - args?: `[ ]` 调用参数 (传入的原生 string 和 boolean 会被自动转换为 DdbObj<string> 和 DdbObj<boolean>)
334
- - options?: 调用选项
335
- - urgent?: 紧急 flag。使用 urgent worker 执行,防止被其它作业阻塞
336
- - node?: 设置结点 alias 时发送到集群中对应的结点执行 (使用 DolphinDB 中的 rpc 方法)
337
- - nodes?: 设置多个结点 alias 时发送到集群中对应的多个结点执行 (使用 DolphinDB 中的 pnodeRun 方法)
338
- - func_type?: 设置 node 参数时必传,需指定函数类型,其它情况下不传
339
- - add_node_alias?: 设置 nodes 参数时选传,其它情况不传
381
+ - func: function name
382
+ - args?: `[ ]` Call parameters (the incoming native string and boolean will be automatically converted to DdbObj<string> and DdbObj<boolean>)
383
+ - options?: call options
384
+ - urgent?: Emergency flag. Use urgent worker execution to prevent being blocked by other jobs
385
+ - 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)
386
+ - nodes?: When setting multiple node aliases, send them to the corresponding multiple nodes in the cluster for execution (using the pnodeRun method in DolphinDB)
387
+ - 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
388
+ - add_node_alias?: Select to pass when setting the nodes parameter, otherwise not pass
389
+ - on_message?: Set the message handler during this rpc, and restore the original after the end
390
+ - parse_object?: Set parse_object during this rpc, and restore the original after the end.
391
+ When it is false, the returned DdbObj only contains buffer and le without parsing,
392
+ so as to facilitate subsequent forwarding and serialization
340
393
  */
341
- call<T extends DdbObj>(func: string, args?: (DdbObj | string | boolean)[], { urgent, node, nodes, func_type, add_node_alias }?: {
394
+ call<T extends DdbObj>(func: string, args?: (DdbObj | string | boolean)[], { urgent, node, nodes, func_type, add_node_alias, on_message, parse_object, }?: {
342
395
  urgent?: boolean;
343
396
  node?: string;
344
397
  nodes?: string[];
345
398
  func_type?: DdbFunctionType;
346
399
  add_node_alias?: boolean;
400
+ on_message?: DDB['on_message'];
401
+ parse_object?: boolean;
347
402
  }): Promise<T>;
348
403
  /** upload variable through websocket (variable command) */
349
404
  upload(
350
405
  /** Uploaded variables' name */
351
406
  vars: string[],
352
407
  /** Uploaded variables' value */
353
- args: (DdbObj | string | boolean)[]): Promise<DdbObj<DdbValue>>;
408
+ args: (DdbObj | string | boolean)[], { on_message, parse_object, }?: {
409
+ on_message?: DDB['on_message'];
410
+ parse_object?: boolean;
411
+ }): Promise<DdbObj<DdbValue>>;
354
412
  /** 解析服务端响应报文,返回去掉 header 的 data buf */
355
- parse_message(buf: Uint8Array): {
356
- type: "message";
357
- data: string;
358
- } | {
359
- type: "object";
360
- data: Uint8Array;
361
- };
413
+ parse_message(buf: Uint8Array, parse_object?: boolean): DdbMessage;
362
414
  /** 自动转换 js string, boolean 为 DdbObj */
363
415
  to_ddbobj(value: DdbObj | string | boolean): DdbObj;
364
416
  /** 转换 js 数组为 DdbObj[] */
365
417
  to_ddbobjs(values: any[]): DdbObj<DdbValue>[];
366
418
  }
419
+ export interface DdbPrintMessage {
420
+ type: 'print';
421
+ data: string;
422
+ }
423
+ export interface DdbObjectMessage {
424
+ type: 'object';
425
+ data: DdbObj;
426
+ }
427
+ export declare type DdbMessage = DdbPrintMessage | DdbObjectMessage;
367
428
  export declare let ddb: DDB;
368
429
  export default ddb;