dolphindb 3.0.122 → 3.0.124

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
@@ -103,5 +103,8 @@
103
103
  },
104
104
  "iotany sub vector 不支持非 vector 类型": {
105
105
  "en": "iotany sub vector does not support non-vector types"
106
+ },
107
+ "iotany 的 meta vector 长度至少为 2": {
108
+ "en": "The length of the iotany meta vector is at least 2"
106
109
  }
107
110
  }
package/index.d.ts CHANGED
@@ -631,7 +631,6 @@ export interface DdbOptions {
631
631
  export interface DdbCallOptions extends DdbEvalOptions {
632
632
  node?: string;
633
633
  nodes?: string[];
634
- func_type?: DdbFunctionType;
635
634
  add_node_alias?: boolean;
636
635
  skip_connection_check?: boolean;
637
636
  on_more_messages?: DdbRpcOptions['on_more_messages'];
@@ -686,6 +685,8 @@ export declare class DDB {
686
685
  ppnode_run: Promise<DdbVoid>;
687
686
  /** 首次定义 invoke 的 promise,保证并发调用 rpc 时只定义一次 invoke */
688
687
  pinvoke: Promise<DdbVoid>;
688
+ /** 首次定义 jsrpc 的 promise,保证并发调用 rpc 时只定义一次 jsrpc */
689
+ pjsrpc: Promise<DdbVoid>;
689
690
  get connected(): boolean;
690
691
  /**
691
692
  使用 WebSocket URL 初始化连接到 DolphinDB 的实例(不建立实际的网络连接)
@@ -790,8 +791,6 @@ export declare class DDB {
790
791
  When the node alias is set, it is sent to the corresponding node in the cluster for execution (using the rpc method in DolphinDB)
791
792
  - nodes?: 设置多个结点 alias 时发送到集群中对应的多个结点执行 (使用 DolphinDB 中的 pnodeRun 方法)
792
793
  When setting multiple node aliases, send them to the corresponding multiple nodes in the cluster for execution (using the pnodeRun method in DolphinDB)
793
- - func_type?: 设置 node 参数时必传,需指定函数类型,其它情况下不传
794
- It must be passed when setting the node parameter, the function type needs to be specified, and it is not passed in other cases
795
794
  - add_node_alias?: 设置 nodes 参数时选传,其它情况不传
796
795
  Select to pass when setting the nodes parameter, otherwise not pass
797
796
  - listener?: 处理本次 rpc 期间的消息 (DdbMessage)
@@ -805,7 +804,7 @@ export declare class DDB {
805
804
  将这个 flag 设为 true 跳过连接状态检查
806
805
  (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.
807
806
  Set this flag to true to skip connection status checks */
808
- 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>;
807
+ 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>;
809
808
  /** 调用 dolphindb 函数,传入 js 原生数组作为参数,返回 js 原生对象或值(调用 DdbObj.data() 后的结果)
810
809
  - func: 函数名
811
810
  - args?: `[ ]` 调用参数,可以是 js 原生数组,参数在中间且想用 server 函数的默认参数值时可以传 null 占位
@@ -813,7 +812,6 @@ export declare class DDB {
813
812
  - urgent?: 紧急 flag。使用 urgent worker 执行,防止被其它作业阻塞
814
813
  - node?: 设置结点 alias 时发送到集群中对应的结点执行 (使用 DolphinDB 中的 rpc 方法)
815
814
  - nodes?: 设置多个结点 alias 时发送到集群中对应的多个结点执行 (使用 DolphinDB 中的 pnodeRun 方法)
816
- - func_type?: 设置 node 参数且参数数组为空时必传,需指定函数类型,其它情况下不传
817
815
  - add_node_alias?: 设置 nodes 参数时选传,其它情况不传
818
816
  - listener?: 处理本次 rpc 期间的消息 (DdbMessage) */
819
817
  invoke<TResult = any>(func: string, args?: any[], options?: DdbInvokeOptions): Promise<TResult>;
package/index.js CHANGED
@@ -822,41 +822,20 @@ export class DdbObj {
822
822
  ];
823
823
  }
824
824
  case DdbType.iotany: {
825
- // 构造 indexes
826
- const dv = new DataView(buf.buffer, buf.byteOffset);
827
- let i_value_start = 0;
828
- const size = Number(dv.getUint32(i_value_start, le));
829
- i_value_start += 4;
830
- const indexes = new Array(size * 2);
831
- for (let i = 0; i < size; i++) {
832
- const type = dv.getUint32(i_value_start, le);
833
- i_value_start += 4;
834
- const idx = dv.getUint32(i_value_start, le);
835
- i_value_start += 4;
836
- indexes[i * 2] = type;
837
- indexes[i * 2 + 1] = idx;
838
- }
839
- // 构造 sub vector
840
- const type_size = dv.getUint32(i_value_start, le);
841
- i_value_start += 4;
842
- const sub_vec = new Map();
843
- for (let i = 0; i < type_size; i++) {
844
- const flag = dv.getUint16(i_value_start, le);
845
- i_value_start += 2;
846
- const form = flag >> 8;
847
- const sub_type = flag & 0xff;
848
- assert(form === DdbForm.vector, t('iotany sub vector 不支持非 vector 类型'));
849
- const sub_size = dv.getUint32(i_value_start, le);
850
- i_value_start += 8; // 同时跳过 sub_size 和 cols
851
- let [len, vector] = this.parse_vector_items(buf.subarray(i_value_start), le, sub_type, sub_size);
852
- vector = converts(sub_type, vector, sub_size, le);
853
- i_value_start += len;
854
- sub_vec.set(sub_type, vector);
825
+ const [len, anys] = this.parse_vector_items(buf, le, DdbType.any, length);
826
+ const metas = anys[0].data();
827
+ assert(metas.length >= 2, t('iotany 的 meta vector 长度至少为 2'));
828
+ const size = metas[0];
829
+ // let sub_vec_count = meta_vec[1]
830
+ let sub_vecs = new Map();
831
+ for (let i = 1; i < length; i++) {
832
+ const sub_vector = anys[i];
833
+ const sub_type = sub_vector.type;
834
+ sub_vecs.set(sub_type, converts(sub_type, sub_vector.data(), sub_vector.length, le));
855
835
  }
856
836
  return [
857
- i_value_start,
858
- // 根据 indexes 数组构建最终的 value 数组
859
- seq(size, i => (sub_vec.get(indexes[i * 2]))[indexes[i * 2 + 1]])
837
+ len,
838
+ seq(size, i => (sub_vecs.get(metas[i + size + 2]))[metas[i + 2]])
860
839
  ];
861
840
  }
862
841
  // 25 01 type = decimal32, form = vector
@@ -2761,6 +2740,8 @@ export class DDB {
2761
2740
  ppnode_run;
2762
2741
  /** 首次定义 invoke 的 promise,保证并发调用 rpc 时只定义一次 invoke */
2763
2742
  pinvoke;
2743
+ /** 首次定义 jsrpc 的 promise,保证并发调用 rpc 时只定义一次 jsrpc */
2744
+ pjsrpc;
2764
2745
  get connected() {
2765
2746
  return !this.error && this.lwebsocket.resource?.readyState === WebSocketOpen;
2766
2747
  }
@@ -3151,8 +3132,6 @@ export class DDB {
3151
3132
  When the node alias is set, it is sent to the corresponding node in the cluster for execution (using the rpc method in DolphinDB)
3152
3133
  - nodes?: 设置多个结点 alias 时发送到集群中对应的多个结点执行 (使用 DolphinDB 中的 pnodeRun 方法)
3153
3134
  When setting multiple node aliases, send them to the corresponding multiple nodes in the cluster for execution (using the pnodeRun method in DolphinDB)
3154
- - func_type?: 设置 node 参数时必传,需指定函数类型,其它情况下不传
3155
- It must be passed when setting the node parameter, the function type needs to be specified, and it is not passed in other cases
3156
3135
  - add_node_alias?: 设置 nodes 参数时选传,其它情况不传
3157
3136
  Select to pass when setting the nodes parameter, otherwise not pass
3158
3137
  - listener?: 处理本次 rpc 期间的消息 (DdbMessage)
@@ -3166,18 +3145,41 @@ export class DDB {
3166
3145
  将这个 flag 设为 true 跳过连接状态检查
3167
3146
  (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.
3168
3147
  Set this flag to true to skip connection status checks */
3169
- async call(func, args = [], { urgent, node, nodes, func_type, add_node_alias, listener, parse_object, skip_connection_check, on_more_messages } = {}) {
3148
+ async call(func, args = [], { urgent, node, nodes, add_node_alias, listener, parse_object, skip_connection_check, on_more_messages } = {}) {
3149
+ let func_ = func;
3150
+ let args_ = args;
3170
3151
  if (node) {
3171
- assert(func_type in DdbFunctionType, t('指定 node 时必须设置 func_type'));
3172
- args = [
3152
+ try {
3153
+ await (this.pjsrpc ??= this.eval(this.python ?
3154
+ '\n' +
3155
+ 'def jsrpc (node, func_name, args):\n' +
3156
+ ' args_ = args\n' +
3157
+ ' if func_name == "invoke":\n' +
3158
+ ' args_[0] = funcByName(args[0])\n' +
3159
+ ' return rpc(node, unifiedCall, funcByName(func_name), args_)\n'
3160
+ :
3161
+ '\n' +
3162
+ 'def jsrpc (node, func_name, args) {\n' +
3163
+ ' args_ = args\n' +
3164
+ ' if (func_name == "invoke")\n' +
3165
+ ' args_[0] = funcByName(args[0])\n' +
3166
+ ' return rpc(node, unifiedCall, funcByName(func_name), args_)\n' +
3167
+ '}\n', { urgent: true }));
3168
+ }
3169
+ catch (error) {
3170
+ this.pjsrpc = undefined;
3171
+ throw error;
3172
+ }
3173
+ func_ = 'jsrpc';
3174
+ args_ = [
3173
3175
  node,
3174
- new DdbFunction(func, func_type),
3175
- ...args
3176
+ func,
3177
+ new DdbVectorAny(args)
3176
3178
  ];
3177
- func = 'rpc';
3178
3179
  }
3179
3180
  if (nodes) {
3180
- args = [
3181
+ func_ = 'pnode_run';
3182
+ args_ = [
3181
3183
  new DdbVectorString(nodes),
3182
3184
  func,
3183
3185
  new DdbVectorAny(args),
@@ -3189,11 +3191,10 @@ export class DDB {
3189
3191
  return [];
3190
3192
  })()
3191
3193
  ];
3192
- func = 'pnode_run';
3193
3194
  }
3194
3195
  return this.rpc('function', {
3195
- func,
3196
- args,
3196
+ func: func_,
3197
+ args: args_,
3197
3198
  urgent,
3198
3199
  listener,
3199
3200
  parse_object,
@@ -3208,25 +3209,37 @@ export class DDB {
3208
3209
  - urgent?: 紧急 flag。使用 urgent worker 执行,防止被其它作业阻塞
3209
3210
  - node?: 设置结点 alias 时发送到集群中对应的结点执行 (使用 DolphinDB 中的 rpc 方法)
3210
3211
  - nodes?: 设置多个结点 alias 时发送到集群中对应的多个结点执行 (使用 DolphinDB 中的 pnodeRun 方法)
3211
- - func_type?: 设置 node 参数且参数数组为空时必传,需指定函数类型,其它情况下不传
3212
3212
  - add_node_alias?: 设置 nodes 参数时选传,其它情况不传
3213
3213
  - listener?: 处理本次 rpc 期间的消息 (DdbMessage) */
3214
3214
  async invoke(func, args, options) {
3215
- await (this.pinvoke ??= this.eval(this.python ?
3216
- '\n' +
3217
- 'def invoke (func_name, args_json):\n' +
3218
- ' args = fromStdJson(args_json)\n' +
3219
- ' if type(args) != ANY:\n' +
3220
- ' args = cast(args, ANY)\n' +
3221
- ' return unifiedCall(funcByName(func_name), args)\n'
3222
- :
3215
+ try {
3216
+ await (this.pinvoke ??= this.eval(this.python ?
3223
3217
  '\n' +
3224
- 'def invoke (func_name, args_json) {\n' +
3218
+ 'def invoke (func, args_json):\n' +
3225
3219
  ' args = fromStdJson(args_json)\n' +
3226
- ' if (type(args) != ANY)\n' +
3220
+ ' func_ = func\n' +
3221
+ ' if type(func) == STRING:\n' +
3222
+ ' func_ = funcByName(func)\n' +
3223
+ ' if type(args) != ANY:\n' +
3227
3224
  ' args = cast(args, ANY)\n' +
3228
- ' return unifiedCall(funcByName(func_name), args)\n' +
3229
- '}\n', { urgent: true }));
3225
+ ' return unifiedCall(func_, args)\n'
3226
+ :
3227
+ '\n' +
3228
+ 'def invoke (func, args_json) {\n' +
3229
+ ' args = fromStdJson(args_json)\n' +
3230
+ ' func_ = func\n' +
3231
+ ' if (type(func) == STRING)\n' +
3232
+ ' func_ = funcByName(func)\n' +
3233
+ ' if (type(args) != ANY)\n' +
3234
+ ' args = cast(args, ANY)\n' +
3235
+ ' return unifiedCall(func_, args)\n' +
3236
+ '}\n', { urgent: true }));
3237
+ }
3238
+ catch (error) {
3239
+ // invoke 没有正确执行时,重新将 pinvoke 赋值为 undefined
3240
+ this.pinvoke = undefined;
3241
+ throw error;
3242
+ }
3230
3243
  // 检查 args 是否全部为简单参数,是则直接调用 call,避免 invoke 间接调用
3231
3244
  // 逻辑类似 DdbObj.to_ddbobjs, 需要同步修改
3232
3245
  let simple = true;
@@ -3243,12 +3256,8 @@ export class DDB {
3243
3256
  break;
3244
3257
  }
3245
3258
  }
3246
- if (!simple) {
3247
- if (has_ddbobj)
3248
- throw new Error(t('调用 ddb.invoke 的参数中不能同时有 DdbObj 与复杂 js 原生对象'));
3249
- if (options?.node)
3250
- options.func_type = DdbFunctionType.UserDefinedFunc;
3251
- }
3259
+ if (!simple && has_ddbobj)
3260
+ throw new Error(t('调用 ddb.invoke 的参数中不能同时有 DdbObj 与复杂 js 原生对象'));
3252
3261
  const result = simple
3253
3262
  ? await this.call(func, args, options)
3254
3263
  : await this.call('invoke', [func, JSON.stringify(args)], options);