dolphindb 3.0.122 → 3.0.123

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/browser.d.ts CHANGED
@@ -642,7 +642,6 @@ export interface DdbOptions {
642
642
  export interface DdbCallOptions extends DdbEvalOptions {
643
643
  node?: string;
644
644
  nodes?: string[];
645
- func_type?: DdbFunctionType;
646
645
  add_node_alias?: boolean;
647
646
  skip_connection_check?: boolean;
648
647
  on_more_messages?: DdbRpcOptions['on_more_messages'];
@@ -695,6 +694,8 @@ export declare class DDB {
695
694
  ppnode_run: Promise<DdbVoid>;
696
695
  /** 首次定义 invoke 的 promise,保证并发调用 rpc 时只定义一次 invoke */
697
696
  pinvoke: Promise<DdbVoid>;
697
+ /** 首次定义 jsrpc 的 promise,保证并发调用 rpc 时只定义一次 jsrpc */
698
+ pjsrpc: Promise<DdbVoid>;
698
699
  get connected(): boolean;
699
700
  /**
700
701
  使用 WebSocket URL 初始化连接到 DolphinDB 的实例(不建立实际的网络连接)
@@ -800,8 +801,6 @@ export declare class DDB {
800
801
  When the node alias is set, it is sent to the corresponding node in the cluster for execution (using the rpc method in DolphinDB)
801
802
  - nodes?: 设置多个结点 alias 时发送到集群中对应的多个结点执行 (使用 DolphinDB 中的 pnodeRun 方法)
802
803
  When setting multiple node aliases, send them to the corresponding multiple nodes in the cluster for execution (using the pnodeRun method in DolphinDB)
803
- - func_type?: 设置 node 参数时必传,需指定函数类型,其它情况下不传
804
- It must be passed when setting the node parameter, the function type needs to be specified, and it is not passed in other cases
805
804
  - add_node_alias?: 设置 nodes 参数时选传,其它情况不传
806
805
  Select to pass when setting the nodes parameter, otherwise not pass
807
806
  - listener?: 处理本次 rpc 期间的消息 (DdbMessage)
@@ -815,7 +814,7 @@ export declare class DDB {
815
814
  将这个 flag 设为 true 跳过连接状态检查
816
815
  (internal use) When await ddb.connect() establishes a connection for the first time, you cannot call await this.connect() again to ensure the connection status, which will lead to circular dependencies.
817
816
  Set this flag to true to skip connection status checks */
818
- call<TResult extends DdbObj>(func: string, args?: (DdbObj | string | boolean)[], { urgent, node, nodes, func_type, add_node_alias, listener, parse_object, skip_connection_check, on_more_messages }?: DdbCallOptions): Promise<TResult>;
817
+ call<TResult extends DdbObj>(func: string, args?: (DdbObj | string | boolean)[], { urgent, node, nodes, add_node_alias, listener, parse_object, skip_connection_check, on_more_messages }?: DdbCallOptions): Promise<TResult>;
819
818
  /** 调用 dolphindb 函数,传入 js 原生数组作为参数,返回 js 原生对象或值(调用 DdbObj.data() 后的结果)
820
819
  - func: 函数名
821
820
  - args?: `[ ]` 调用参数,可以是 js 原生数组,参数在中间且想用 server 函数的默认参数值时可以传 null 占位
@@ -823,7 +822,6 @@ export declare class DDB {
823
822
  - urgent?: 紧急 flag。使用 urgent worker 执行,防止被其它作业阻塞
824
823
  - node?: 设置结点 alias 时发送到集群中对应的结点执行 (使用 DolphinDB 中的 rpc 方法)
825
824
  - nodes?: 设置多个结点 alias 时发送到集群中对应的多个结点执行 (使用 DolphinDB 中的 pnodeRun 方法)
826
- - func_type?: 设置 node 参数且参数数组为空时必传,需指定函数类型,其它情况下不传
827
825
  - add_node_alias?: 设置 nodes 参数时选传,其它情况不传
828
826
  - listener?: 处理本次 rpc 期间的消息 (DdbMessage) */
829
827
  invoke<TResult = any>(func: string, args?: any[], options?: DdbInvokeOptions): Promise<TResult>;
package/browser.js CHANGED
@@ -2785,6 +2785,8 @@ export class DDB {
2785
2785
  ppnode_run;
2786
2786
  /** 首次定义 invoke 的 promise,保证并发调用 rpc 时只定义一次 invoke */
2787
2787
  pinvoke;
2788
+ /** 首次定义 jsrpc 的 promise,保证并发调用 rpc 时只定义一次 jsrpc */
2789
+ pjsrpc;
2788
2790
  get connected() {
2789
2791
  return !this.error && this.lwebsocket.resource?.readyState === WebSocket.OPEN;
2790
2792
  }
@@ -3173,8 +3175,6 @@ export class DDB {
3173
3175
  When the node alias is set, it is sent to the corresponding node in the cluster for execution (using the rpc method in DolphinDB)
3174
3176
  - nodes?: 设置多个结点 alias 时发送到集群中对应的多个结点执行 (使用 DolphinDB 中的 pnodeRun 方法)
3175
3177
  When setting multiple node aliases, send them to the corresponding multiple nodes in the cluster for execution (using the pnodeRun method in DolphinDB)
3176
- - func_type?: 设置 node 参数时必传,需指定函数类型,其它情况下不传
3177
- It must be passed when setting the node parameter, the function type needs to be specified, and it is not passed in other cases
3178
3178
  - add_node_alias?: 设置 nodes 参数时选传,其它情况不传
3179
3179
  Select to pass when setting the nodes parameter, otherwise not pass
3180
3180
  - listener?: 处理本次 rpc 期间的消息 (DdbMessage)
@@ -3188,18 +3188,41 @@ export class DDB {
3188
3188
  将这个 flag 设为 true 跳过连接状态检查
3189
3189
  (internal use) When await ddb.connect() establishes a connection for the first time, you cannot call await this.connect() again to ensure the connection status, which will lead to circular dependencies.
3190
3190
  Set this flag to true to skip connection status checks */
3191
- async call(func, args = [], { urgent, node, nodes, func_type, add_node_alias, listener, parse_object, skip_connection_check, on_more_messages } = {}) {
3191
+ async call(func, args = [], { urgent, node, nodes, add_node_alias, listener, parse_object, skip_connection_check, on_more_messages } = {}) {
3192
+ let func_ = func;
3193
+ let args_ = args;
3192
3194
  if (node) {
3193
- assert(func_type in DdbFunctionType, t('指定 node 时必须设置 func_type'));
3194
- args = [
3195
+ try {
3196
+ await (this.pjsrpc ??= this.eval(this.python ?
3197
+ '\n' +
3198
+ 'def jsrpc (node, func_name, args):\n' +
3199
+ ' args_ = args\n' +
3200
+ ' if func_name == "invoke":\n' +
3201
+ ' args_[0] = funcByName(args[0])\n' +
3202
+ ' return rpc(node, unifiedCall, funcByName(func_name), args_)\n'
3203
+ :
3204
+ '\n' +
3205
+ 'def jsrpc (node, func_name, args) {\n' +
3206
+ ' args_ = args\n' +
3207
+ ' if (func_name == "invoke")\n' +
3208
+ ' args_[0] = funcByName(args[0])\n' +
3209
+ ' return rpc(node, unifiedCall, funcByName(func_name), args_)\n' +
3210
+ '}\n', { urgent: true }));
3211
+ }
3212
+ catch (error) {
3213
+ this.pjsrpc = undefined;
3214
+ throw error;
3215
+ }
3216
+ func_ = 'jsrpc';
3217
+ args_ = [
3195
3218
  node,
3196
- new DdbFunction(func, func_type),
3197
- ...args
3219
+ func,
3220
+ new DdbVectorAny(args)
3198
3221
  ];
3199
- func = 'rpc';
3200
3222
  }
3201
3223
  if (nodes) {
3202
- args = [
3224
+ func_ = 'pnode_run';
3225
+ args_ = [
3203
3226
  new DdbVectorString(nodes),
3204
3227
  func,
3205
3228
  new DdbVectorAny(args),
@@ -3211,11 +3234,10 @@ export class DDB {
3211
3234
  return [];
3212
3235
  })()
3213
3236
  ];
3214
- func = 'pnode_run';
3215
3237
  }
3216
3238
  return this.rpc('function', {
3217
- func,
3218
- args,
3239
+ func: func_,
3240
+ args: args_,
3219
3241
  urgent,
3220
3242
  listener,
3221
3243
  parse_object,
@@ -3230,25 +3252,37 @@ export class DDB {
3230
3252
  - urgent?: 紧急 flag。使用 urgent worker 执行,防止被其它作业阻塞
3231
3253
  - node?: 设置结点 alias 时发送到集群中对应的结点执行 (使用 DolphinDB 中的 rpc 方法)
3232
3254
  - nodes?: 设置多个结点 alias 时发送到集群中对应的多个结点执行 (使用 DolphinDB 中的 pnodeRun 方法)
3233
- - func_type?: 设置 node 参数且参数数组为空时必传,需指定函数类型,其它情况下不传
3234
3255
  - add_node_alias?: 设置 nodes 参数时选传,其它情况不传
3235
3256
  - listener?: 处理本次 rpc 期间的消息 (DdbMessage) */
3236
3257
  async invoke(func, args, options) {
3237
- await (this.pinvoke ??= this.eval(this.python ?
3238
- '\n' +
3239
- 'def invoke (func_name, args_json):\n' +
3240
- ' args = fromStdJson(args_json)\n' +
3241
- ' if type(args) != ANY:\n' +
3242
- ' args = cast(args, ANY)\n' +
3243
- ' return unifiedCall(funcByName(func_name), args)\n'
3244
- :
3258
+ try {
3259
+ await (this.pinvoke ??= this.eval(this.python ?
3245
3260
  '\n' +
3246
- 'def invoke (func_name, args_json) {\n' +
3261
+ 'def invoke (func, args_json):\n' +
3247
3262
  ' args = fromStdJson(args_json)\n' +
3248
- ' if (type(args) != ANY)\n' +
3263
+ ' func_ = func\n' +
3264
+ ' if type(func) == STRING:\n' +
3265
+ ' func_ = funcByName(func)\n' +
3266
+ ' if type(args) != ANY:\n' +
3249
3267
  ' args = cast(args, ANY)\n' +
3250
- ' return unifiedCall(funcByName(func_name), args)\n' +
3251
- '}\n', { urgent: true }));
3268
+ ' return unifiedCall(func_, args)\n'
3269
+ :
3270
+ '\n' +
3271
+ 'def invoke (func, args_json) {\n' +
3272
+ ' args = fromStdJson(args_json)\n' +
3273
+ ' func_ = func\n' +
3274
+ ' if (type(func) == STRING)\n' +
3275
+ ' func_ = funcByName(func)\n' +
3276
+ ' if (type(args) != ANY)\n' +
3277
+ ' args = cast(args, ANY)\n' +
3278
+ ' return unifiedCall(func_, args)\n' +
3279
+ '}\n', { urgent: true }));
3280
+ }
3281
+ catch (error) {
3282
+ // invoke 没有正确执行时,重新将 pinvoke 赋值为 undefined
3283
+ this.pinvoke = undefined;
3284
+ throw error;
3285
+ }
3252
3286
  // 检查 args 是否全部为简单参数,是则直接调用 call,避免 invoke 间接调用
3253
3287
  // 逻辑类似 DdbObj.to_ddbobjs, 需要同步修改
3254
3288
  let simple = true;
@@ -3265,12 +3299,8 @@ export class DDB {
3265
3299
  break;
3266
3300
  }
3267
3301
  }
3268
- if (!simple) {
3269
- if (has_ddbobj)
3270
- throw new Error(t('调用 ddb.invoke 的参数中不能同时有 DdbObj 与复杂 js 原生对象'));
3271
- if (options?.node)
3272
- options.func_type = DdbFunctionType.UserDefinedFunc;
3273
- }
3302
+ if (!simple && has_ddbobj)
3303
+ throw new Error(t('调用 ddb.invoke 的参数中不能同时有 DdbObj 与复杂 js 原生对象'));
3274
3304
  const result = simple
3275
3305
  ? await this.call(func, args, options)
3276
3306
  : await this.call('invoke', [func, JSON.stringify(args)], options);