dolphindb 3.0.229 → 3.1.0

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 */
@@ -185,7 +185,7 @@ export interface InspectOptions {
185
185
  export declare function format(type: DdbType, value: DdbValue, le: boolean, options?: InspectOptions): string;
186
186
  /** 格式化向量、集合中的第 index 项为字符串,空值返回 'null' 字符串 formatted vector, the index-th item in the collection is a string, a null value returns a 'null' string */
187
187
  export declare function formati(obj: DdbVectorObj, index: number, options?: InspectOptions): string;
188
- export declare function convert(type: DdbType, value: DdbValue, le: boolean, { blob, char, timestamp }?: ConvertOptions): string | number | bigint | boolean | number[] | Uint8Array<ArrayBufferLike> | DdbFunctionDefValue | DdbDurationValue | DdbDecimal32Value | DdbDecimal64Value | Int8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | Float32Array<ArrayBufferLike> | Float64Array<ArrayBufferLike> | BigInt64Array<ArrayBufferLike> | BigInt128Array | string[] | Uint8Array<ArrayBufferLike>[] | DdbObj<DdbValue>[] | IotVectorItemValue | DdbSymbolExtendedValue | DdbArrayVectorValue | DdbDecimal32VectorValue | DdbDecimal64VectorValue | DdbDecimal128VectorValue | DdbDurationVectorValue | DdbMatrixValue | DdbChartValue | DdbTensorValue;
188
+ export declare function convert(type: DdbType, value: DdbValue, le: boolean, { blob, char, timestamp }?: ConvertOptions): string | number | bigint | boolean | string[] | number[] | DdbFunctionDefValue | DdbDurationValue | DdbDecimal32Value | DdbDecimal64Value | DdbDecimal32VectorValue | DdbDecimal64VectorValue | DdbSymbolExtendedValue | DdbTensorValue | Uint8Array<ArrayBufferLike> | Int8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | Float32Array<ArrayBufferLike> | Float64Array<ArrayBufferLike> | BigInt64Array<ArrayBufferLike> | BigInt128Array | Uint8Array<ArrayBufferLike>[] | DdbObj<DdbValue>[] | IotVectorItemValue | DdbArrayVectorValue | DdbDecimal128VectorValue | DdbDurationVectorValue | DdbMatrixValue | DdbChartValue;
189
189
  /** 转换一个向量到 js 原生数组 */
190
190
  export declare function converts(type: DdbType, value: DdbVectorValue, rows: number, le: boolean, options?: ConvertOptions): any[] | Uint8Array;
191
191
  /** 构造 void 类型,默认为 `DdbVoidType.undefined` */
@@ -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 执行,防止被其它作业阻塞
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
  }
@@ -3174,7 +3180,7 @@ export class DDB {
3174
3180
  '}\n'),
3175
3181
  ['hello']) */
3176
3182
  async define(definition) {
3177
- const matches = /\bdef (\w+) \(/.exec(definition);
3183
+ const matches = function_definition_pattern.exec(definition);
3178
3184
  if (!matches)
3179
3185
  throw new Error(t('DDB.define 方法传入的 definition 不符合函数定义格式 def xxx ()'));
3180
3186
  const func_name = matches[1];