dolphindb 3.0.114 → 3.0.118

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/i18n/dict.json CHANGED
@@ -97,5 +97,8 @@
97
97
  },
98
98
  "调用 ddb.invoke 的参数中不能同时有 DdbObj 与复杂 js 原生对象": {
99
99
  "en": "The parameters of calling ddb.invoke cannot contain both DdbObj and complex js native objects"
100
+ },
101
+ "iife 执行的脚本行数应该至少为 2 行": {
102
+ "en": "The number of script lines executed by iife should be at least 2"
100
103
  }
101
104
  }
package/index.d.ts CHANGED
@@ -544,7 +544,7 @@ export interface StreamingParams {
544
544
  offset 与流数据表创建时的第一行对应。如果某些行因为内存限制被删除,在决定订阅开始的位置时,这些行仍然考虑在内。 */
545
545
  offset?: number;
546
546
  filters?: {
547
- /** https://docs.dolphindb.cn/zh/help/FunctionsandCommands/FunctionReferences/s/subscribeTable.html#:~:text=%E8%BF%9E%E6%8E%A5%E6%96%B0%E7%9A%84%20leader%E3%80%82-,filter%20%E5%8F%82%E6%95%B0%E9%9C%80%E8%A6%81%E9%85%8D%E5%90%88,-setStreamTableFilterColumn%20%E5%87%BD%E6%95%B0%E4%B8%80%E8%B5%B7 */
547
+ /** https://test.dolphindb.cn/zh/funcs/s/subscribeTable.html#:~:text=filter%20%E5%8F%82%E6%95%B0%E9%9C%80%E8%A6%81%E9%85%8D%E5%90%88%20setStreamTableFilterColumn%20%E5%87%BD%E6%95%B0%E4%B8%80%E8%B5%B7%E4%BD%BF%E7%94%A8 */
548
548
  column?: DdbObj;
549
549
  /** 过滤条件的 DolphinDB 表达式 https://dolphindb1.atlassian.net/wiki/spaces/dev/pages/760840447/WebSocketConsole */
550
550
  expression?: string;
@@ -583,6 +583,9 @@ export interface DdbEvalOptions {
583
583
  urgent?: boolean;
584
584
  listener?: DdbMessageListener;
585
585
  parse_object?: boolean;
586
+ iife?: boolean;
587
+ }
588
+ export interface DdbExecuteOptions extends DdbEvalOptions, ConvertOptions {
586
589
  }
587
590
  type DdbRpcType = 'script' | 'function' | 'variable' | 'connect';
588
591
  export interface DdbRpcOptions extends DdbEvalOptions {
@@ -631,6 +634,8 @@ export interface DdbCallOptions extends DdbEvalOptions {
631
634
  skip_connection_check?: boolean;
632
635
  on_more_messages?: DdbRpcOptions['on_more_messages'];
633
636
  }
637
+ export interface DdbInvokeOptions extends DdbCallOptions, ConvertOptions {
638
+ }
634
639
  export declare class DDB {
635
640
  /** 当前的 session id (http 或 tcp) */
636
641
  sid: string;
@@ -769,8 +774,9 @@ export declare class DDB {
769
774
  不做解析,以便后续转发、序列化
770
775
  Set parse_object during this rpc, and restore the original after the end.
771
776
  When it is false, the returned DdbObj only contains buffer and le without parsing,
772
- so as to facilitate subsequent forwarding and serialization */
773
- eval<T extends DdbObj>(script: string, { urgent, listener, parse_object, }?: DdbEvalOptions): Promise<T>;
777
+ so as to facilitate subsequent forwarding and serialization
778
+ - iife?: 使用 `def () { ... } ()` 包裹脚本,return 最后一行,避免变量泄漏 */
779
+ eval<T extends DdbObj>(script: string, { urgent, listener, parse_object, iife, }?: DdbEvalOptions): Promise<T>;
774
780
  /** call function through websocket (function command)
775
781
  - func: 函数名 function name
776
782
  - args?: `[ ]` 调用参数 (传入的原生 string 和 boolean 会被自动转换为 DdbObj<string> 和 DdbObj<boolean>)
@@ -808,13 +814,13 @@ export declare class DDB {
808
814
  - func_type?: 设置 node 参数且参数数组为空时必传,需指定函数类型,其它情况下不传
809
815
  - add_node_alias?: 设置 nodes 参数时选传,其它情况不传
810
816
  - listener?: 处理本次 rpc 期间的消息 (DdbMessage) */
811
- invoke<TResult = any>(func: string, args?: any[], options?: DdbCallOptions): Promise<TResult>;
817
+ invoke<TResult = any>(func: string, args?: any[], options?: DdbInvokeOptions): Promise<TResult>;
812
818
  /** 执行 dolphindb 脚本,返回 js 原生对象或值(调用 DdbObj.data() 后的结果)
813
819
  - script?: 执行的脚本
814
820
  - options?: 执行选项
815
821
  - urgent?: 紧急 flag,确保提交的脚本使用 urgent worker 处理,防止被其它作业阻塞
816
822
  - listener?: 处理本次 rpc 期间的消息 (DdbMessage) */
817
- execute<TResult = any>(script: string, options?: DdbEvalOptions): Promise<TResult>;
823
+ execute<TResult = any>(script: string, options?: DdbExecuteOptions): Promise<TResult>;
818
824
  /** upload variable through websocket (variable command) */
819
825
  upload(
820
826
  /** 上传的变量名 Uploaded variables' name */
package/index.js CHANGED
@@ -3082,8 +3082,19 @@ export class DDB {
3082
3082
  不做解析,以便后续转发、序列化
3083
3083
  Set parse_object during this rpc, and restore the original after the end.
3084
3084
  When it is false, the returned DdbObj only contains buffer and le without parsing,
3085
- so as to facilitate subsequent forwarding and serialization */
3086
- async eval(script, { urgent, listener, parse_object, } = {}) {
3085
+ so as to facilitate subsequent forwarding and serialization
3086
+ - iife?: 使用 `def () { ... } ()` 包裹脚本,return 最后一行,避免变量泄漏 */
3087
+ async eval(script, { urgent, listener, parse_object, iife, } = {}) {
3088
+ if (iife) {
3089
+ const lines = script.split_lines();
3090
+ if (lines.length < 2)
3091
+ throw new Error(t('iife 执行的脚本行数应该至少为 2 行'));
3092
+ script =
3093
+ 'def () {\n' +
3094
+ lines.slice(0, -1).indent().join_lines() +
3095
+ ` return ${lines.last}\n`;
3096
+ '} ()\n';
3097
+ }
3087
3098
  return this.rpc('script', { script, urgent, listener, parse_object });
3088
3099
  }
3089
3100
  /** call function through websocket (function command)
@@ -3199,7 +3210,7 @@ export class DDB {
3199
3210
  const result = simple
3200
3211
  ? await this.call(func, args, options)
3201
3212
  : await this.call('invoke', [func, JSON.stringify(args)], options);
3202
- return result.data();
3213
+ return result.data(options);
3203
3214
  }
3204
3215
  /** 执行 dolphindb 脚本,返回 js 原生对象或值(调用 DdbObj.data() 后的结果)
3205
3216
  - script?: 执行的脚本
@@ -3208,7 +3219,7 @@ export class DDB {
3208
3219
  - listener?: 处理本次 rpc 期间的消息 (DdbMessage) */
3209
3220
  async execute(script, options) {
3210
3221
  return (await this.eval(script, options))
3211
- .data();
3222
+ .data(options);
3212
3223
  }
3213
3224
  /** upload variable through websocket (variable command) */
3214
3225
  async upload(