dolphindb 3.0.229 → 3.1.1

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
@@ -117,7 +117,7 @@ export declare class DdbObj<TValue extends DdbValue = DdbValue> {
117
117
  /** 将 DdbObj 转换为 js 原生数据类型
118
118
  - 标量对应 number, bigint 或者字符串 (其中时间类型转换为常用的字符串表示)
119
119
  - 数组对应 js 原生数组
120
- - 表格对应 DdbTableData
120
+ - 表格对应 TResult, 可以传入 table: 'full' 配置返回包含列名,列类型的 DdbTableData 结构
121
121
  - 矩阵对应 DdbMatrixData
122
122
  - 字典对应普通的 js 对象 Record<string, any>
123
123
  - 图对应 DdbChartValue */
@@ -548,7 +548,7 @@ export declare class DDB {
548
548
  Set this flag to true to skip connection status checks */
549
549
  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>;
550
550
  /** 调用 dolphindb 函数,传入 js 原生数组作为参数,返回 js 原生对象或值(调用 DdbObj.data() 后的结果)
551
- - func: 函数名
551
+ - func: 函数名,或者函数完整实现,会间接调用 define 进行预定义
552
552
  - args?: `[ ]` 调用参数,可以是 js 原生数组,参数在中间且想用 server 函数的默认参数值时可以传 null 占位
553
553
  - options?: 调用选项
554
554
  - urgent?: 紧急 flag。使用 urgent worker 执行,防止被其它作业阻塞
@@ -581,6 +581,8 @@ export declare class DDB {
581
581
  /** 定义函数并保存,避免下次重复执行定义,会自动提取脚本中的函数名,作为缓存 key,
582
582
  也同时作为返回值
583
583
  - definition: 函数完整定义
584
+ - options?:
585
+ - urgent?: 紧急 flag,确保提交的脚本使用 urgent worker 处理,防止被其它作业阻塞
584
586
  @example
585
587
  await ddb.invoke(
586
588
  await ddb.define(
@@ -588,7 +590,9 @@ export declare class DDB {
588
590
  ' print(bar)\n' +
589
591
  '}\n'),
590
592
  ['hello']) */
591
- define(definition: string): Promise<string>;
593
+ define(definition: string, { urgent }?: {
594
+ urgent?: boolean;
595
+ }): Promise<string>;
592
596
  }
593
597
  export interface DdbMessageListener {
594
598
  (message: DdbMessage, _this: DDB): any;
package/browser.js CHANGED
@@ -3,7 +3,7 @@ import { blue, cyan, green, grey, magenta } from 'xshell/chalk.browser.js';
3
3
  import { concat, assert, Lock, genid, seq, zip_object, decode, delay, check } from 'xshell/utils.browser.js';
4
4
  import { connect_websocket } from 'xshell/net.browser.js';
5
5
  import { t } from "./i18n/index.js";
6
- import { date2str, datehour2str, datetime2str, ddb_tensor_bytes, DdbChartType, DdbDurationUnit, DdbForm, DdbFunctionType, DdbType, DdbVoidType, dictables, generate_array_type, get_big_int_128, get_ddb_time_value, get_duration_unit, get_type_name, int1282str, ipaddr2str, is_decimal_null_value, is_decimal_type, minute2str, month2str, nanotime2str, nanotimestamp2str, nulls, second2str, set_big_int_128, time2str, timestamp2str, uuid2str } from "./common.js";
6
+ import { date2str, datehour2str, datetime2str, ddb_tensor_bytes, DdbChartType, DdbDurationUnit, DdbForm, DdbFunctionType, DdbType, DdbVoidType, dictables, function_definition_pattern, generate_array_type, get_big_int_128, get_ddb_time_value, get_duration_unit, get_type_name, int1282str, ipaddr2str, is_decimal_null_value, is_decimal_type, minute2str, month2str, nanotime2str, nanotimestamp2str, nulls, second2str, set_big_int_128, time2str, timestamp2str, uuid2str } from "./common.js";
7
7
  export * from "./common.js";
8
8
  /** 可以表示所有 DolphinDB 数据库中的数据类型 Can represent data types in all DolphinDB databases */
9
9
  export class DdbObj {
@@ -1114,13 +1114,17 @@ export class DdbObj {
1114
1114
  case DdbForm.table: {
1115
1115
  const cols = value;
1116
1116
  const jscols = cols.map(col => col.data(options));
1117
- const keys = cols.map(({ name }) => name);
1118
- return {
1119
- name: name || '',
1120
- columns: cols.map(({ name }) => name),
1121
- types: cols.map(({ type }) => type),
1122
- data: seq(rows, i => zip_object(keys, seq(cols.length, j => jscols[j][i])))
1123
- };
1117
+ const columns = cols.select('name');
1118
+ const data = seq(rows, i => zip_object(columns, seq(cols.length, j => jscols[j][i])));
1119
+ return options?.table === 'full' ?
1120
+ {
1121
+ name: name || '',
1122
+ columns,
1123
+ types: cols.select('type'),
1124
+ data
1125
+ }
1126
+ :
1127
+ data;
1124
1128
  }
1125
1129
  case DdbForm.dict: {
1126
1130
  const [keys, values] = value;
@@ -2925,7 +2929,7 @@ export class DDB {
2925
2929
  });
2926
2930
  }
2927
2931
  /** 调用 dolphindb 函数,传入 js 原生数组作为参数,返回 js 原生对象或值(调用 DdbObj.data() 后的结果)
2928
- - func: 函数名
2932
+ - func: 函数名,或者函数完整实现,会间接调用 define 进行预定义
2929
2933
  - args?: `[ ]` 调用参数,可以是 js 原生数组,参数在中间且想用 server 函数的默认参数值时可以传 null 占位
2930
2934
  - options?: 调用选项
2931
2935
  - urgent?: 紧急 flag。使用 urgent worker 执行,防止被其它作业阻塞
@@ -2952,6 +2956,8 @@ export class DDB {
2952
2956
  convertable = false;
2953
2957
  }
2954
2958
  let result;
2959
+ if (function_definition_pattern.test(func))
2960
+ func = await this.define(func);
2955
2961
  if (convertable)
2956
2962
  result = await this.call(func, args, options);
2957
2963
  else {
@@ -3112,7 +3118,7 @@ export class DDB {
3112
3118
  throw new Error(value.slice(value.indexOf(':') + 1).trim());
3113
3119
  }
3114
3120
  if (first) {
3115
- schema = data = obj.data();
3121
+ schema = data = obj.data({ table: 'full' });
3116
3122
  data.name ||= this.streaming.table;
3117
3123
  first = false;
3118
3124
  }
@@ -3120,7 +3126,7 @@ export class DDB {
3120
3126
  let rows;
3121
3127
  // 用了流数据过滤功能后,必然发 table
3122
3128
  if (obj.form === DdbForm.table) {
3123
- data = obj.data();
3129
+ data = obj.data({ table: 'full' });
3124
3130
  data.name ||= schema.name;
3125
3131
  rows = data.data.length;
3126
3132
  }
@@ -3166,6 +3172,8 @@ export class DDB {
3166
3172
  /** 定义函数并保存,避免下次重复执行定义,会自动提取脚本中的函数名,作为缓存 key,
3167
3173
  也同时作为返回值
3168
3174
  - definition: 函数完整定义
3175
+ - options?:
3176
+ - urgent?: 紧急 flag,确保提交的脚本使用 urgent worker 处理,防止被其它作业阻塞
3169
3177
  @example
3170
3178
  await ddb.invoke(
3171
3179
  await ddb.define(
@@ -3173,8 +3181,8 @@ export class DDB {
3173
3181
  ' print(bar)\n' +
3174
3182
  '}\n'),
3175
3183
  ['hello']) */
3176
- async define(definition) {
3177
- const matches = /\bdef (\w+) \(/.exec(definition);
3184
+ async define(definition, { urgent } = {}) {
3185
+ const matches = function_definition_pattern.exec(definition);
3178
3186
  if (!matches)
3179
3187
  throw new Error(t('DDB.define 方法传入的 definition 不符合函数定义格式 def xxx ()'));
3180
3188
  const func_name = matches[1];
@@ -3184,7 +3192,7 @@ export class DDB {
3184
3192
  // 防止并发调用 define 时多次重复定义
3185
3193
  let promise = this.pdefinitions.get(func_name);
3186
3194
  if (!promise)
3187
- this.pdefinitions.set(func_name, promise = this.execute(definition));
3195
+ this.pdefinitions.set(func_name, promise = this.execute(definition, { urgent }));
3188
3196
  await promise;
3189
3197
  this.definitions.set(func_name, definition);
3190
3198
  // 成功定义之后,definitions 中有了,就不需要通过 promise 来防止并发了,清理掉