dolphindb 3.0.39 → 3.0.41

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/docs.d.ts CHANGED
@@ -32,7 +32,7 @@ export declare class DocsAnalyser {
32
32
  @returns */
33
33
  search_completion_items(query: string): {
34
34
  keywords: string[];
35
- constants: ("DFLT" | "NULL" | "true" | "false" | "pi" | "e" | "SCALAR" | "VECTOR" | "PAIR" | "MATRIX" | "SET" | "DICT" | "TABLE" | "VOID" | "BOOL" | "CHAR" | "SHORT" | "INT" | "INDEX" | "LONG" | "DATE" | "MONTH" | "TIME" | "MINUTE" | "SECOND" | "DATETIME" | "TIMESTAMP" | "NANOTIME" | "NANOTIMESTAMP" | "FLOAT" | "DOUBLE" | "SYMBOL" | "STRING" | "UUID" | "FUNCTIONDEF" | "HANDLE" | "CODE" | "DATASOURCE" | "RESOURCE" | "ANY" | "DICTIONARY" | "DATEHOUR" | "IPADDR" | "INT128" | "BLOB" | "COMPLEX" | "POINT" | "DURATION" | "OBJECT" | "DECIMAL32" | "DECIMAL64" | "DECIMAL128" | "SEQ" | "RANGE" | "HASH" | "VALUE" | "LIST" | "COMPO" | "VAR" | "SHARED" | "DEF" | "GLOBAL" | "TABLE_READ" | "TABLE_WRITE" | "TABLE_INSERT" | "TABLE_UPDATE" | "TABLE_DELETE" | "DBOBJ_CREATE" | "DBOBJ_DELETE" | "DB_DELETE" | "DB_INSERT" | "DB_MANAGE" | "DB_OWNER" | "DB_READ" | "DB_UPDATE" | "DB_WRITE" | "SCRIPT_EXEC" | "TASK_GROUP_MEM_LIMIT" | "TEST_EXEC" | "VIEW_EXEC" | "VIEW_OWNER" | "QUERY_RESULT_MEM_LIMIT" | "HINT_HASH" | "HINT_SNAPSHOT" | "HINT_KEEPORDER" | "HINT_SEQ" | "HINT_EXPLAIN" | "HINT_VECTORIZED" | "HEAD" | "CURRENT" | "TAIL" | "LINE" | "PIE" | "COLUMN" | "BAR" | "AREA" | "SCATTER" | "HISTOGRAM" | "KLINE" | "DEBUG" | "INFO" | "WARNING" | "ERROR" | "FIRST" | "LAST" | "ALL" | "NONE" | "HASH_PTN" | "True" | "False" | "None")[];
35
+ constants: ("true" | "false" | "DFLT" | "NULL" | "pi" | "e" | "SCALAR" | "VECTOR" | "PAIR" | "MATRIX" | "SET" | "DICT" | "TABLE" | "VOID" | "BOOL" | "CHAR" | "SHORT" | "INT" | "INDEX" | "LONG" | "DATE" | "MONTH" | "TIME" | "MINUTE" | "SECOND" | "DATETIME" | "TIMESTAMP" | "NANOTIME" | "NANOTIMESTAMP" | "FLOAT" | "DOUBLE" | "SYMBOL" | "STRING" | "UUID" | "FUNCTIONDEF" | "HANDLE" | "CODE" | "DATASOURCE" | "RESOURCE" | "ANY" | "DICTIONARY" | "DATEHOUR" | "IPADDR" | "INT128" | "BLOB" | "COMPLEX" | "POINT" | "DURATION" | "OBJECT" | "DECIMAL32" | "DECIMAL64" | "DECIMAL128" | "SEQ" | "RANGE" | "HASH" | "VALUE" | "LIST" | "COMPO" | "VAR" | "SHARED" | "DEF" | "GLOBAL" | "TABLE_READ" | "TABLE_WRITE" | "TABLE_INSERT" | "TABLE_UPDATE" | "TABLE_DELETE" | "DBOBJ_CREATE" | "DBOBJ_DELETE" | "DB_DELETE" | "DB_INSERT" | "DB_MANAGE" | "DB_OWNER" | "DB_READ" | "DB_UPDATE" | "DB_WRITE" | "SCRIPT_EXEC" | "TASK_GROUP_MEM_LIMIT" | "TEST_EXEC" | "VIEW_EXEC" | "VIEW_OWNER" | "QUERY_RESULT_MEM_LIMIT" | "HINT_HASH" | "HINT_SNAPSHOT" | "HINT_KEEPORDER" | "HINT_SEQ" | "HINT_EXPLAIN" | "HINT_VECTORIZED" | "HEAD" | "CURRENT" | "TAIL" | "LINE" | "PIE" | "COLUMN" | "BAR" | "AREA" | "SCATTER" | "HISTOGRAM" | "KLINE" | "DEBUG" | "INFO" | "WARNING" | "ERROR" | "FIRST" | "LAST" | "ALL" | "NONE" | "HASH_PTN" | "True" | "False" | "None")[];
36
36
  functions: string[];
37
37
  };
38
38
  }
package/i18n/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { I18N } from 'xshell/i18n/index.js';
2
2
  export declare let i18n: I18N;
3
3
  declare const t: (text: string, options?: {
4
- [key: string]: any;
5
4
  language?: import("xshell/i18n/index.js").Language;
6
5
  context?: string;
7
6
  count?: number;
7
+ [key: string]: any;
8
8
  }) => string, language: import("xshell/i18n/index.js").Language;
9
9
  export { t, language };
package/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import type { InspectOptions as UtilInspectOptions } from 'util';
3
2
  import { inspect, Lock, type WebSocket, type WebSocketConnectionError } from 'xshell';
4
3
  export declare const nulls: {
@@ -330,7 +329,7 @@ export declare class DdbObj<TValue extends DdbValue = DdbValue> {
330
329
  pack(): Uint8Array;
331
330
  static pack_vector_body(value: DdbVectorValue, type: DdbType, length: number): ArrayBufferView[];
332
331
  /** 将 DdbObj 转换为 js 原生数据类型
333
- - 标量对应 number, bigint 或者字符串
332
+ - 标量对应 number, bigint 或者字符串 (其中时间类型转换为常用的字符串表示)
334
333
  - 数组对应 js 原生数组
335
334
  - 表格对应 DdbTableData
336
335
  - 矩阵对应 DdbMatrixData
@@ -378,7 +377,7 @@ export declare class DdbObj<TValue extends DdbValue = DdbValue> {
378
377
  }
379
378
  /** 根据 DdbType 获取其名称,array vector type 自动在后面加上 [] */
380
379
  export declare function get_type_name(type: DdbType): string;
381
- export declare function is_decimal_type(type: DdbType): boolean;
380
+ export declare function is_decimal_type(type: DdbType): type is DdbType.decimal32 | DdbType.decimal64 | DdbType.decimal128;
382
381
  export declare function is_decimal_null_value(type: DdbType, value: number | bigint): boolean;
383
382
  export declare function get_duration_unit(code: number): string;
384
383
  export interface InspectOptions extends UtilInspectOptions {
@@ -388,6 +387,8 @@ export interface InspectOptions extends UtilInspectOptions {
388
387
  decimals?: number;
389
388
  /** `true` 决定格式化后的数据是否有千分位 */
390
389
  grouping?: boolean;
390
+ /** timestamp 类型转换为字符串表示时显示到秒还是毫秒 */
391
+ timestamp?: 's' | 'ms';
391
392
  }
392
393
  /** 根据 DdbType 格式化单个元素 (value) 为字符串,空值返回 'null' 字符串 */
393
394
  export declare function format(type: DdbType, value: DdbValue, le: boolean, options?: InspectOptions): string;
@@ -396,8 +397,10 @@ export declare function formati(obj: DdbVectorObj, index: number, options?: Insp
396
397
  export interface ConvertOptions {
397
398
  /** `'string'` blob 类型数据的格式 */
398
399
  blob?: 'string' | 'binary';
400
+ /** timestamp 类型转换为字符串表示时显示到秒还是毫秒 */
401
+ timestamp?: 's' | 'ms';
399
402
  }
400
- export declare function convert(type: DdbType, value: DdbValue, le: boolean, { blob }?: ConvertOptions): string | number | bigint | boolean | Uint8Array | Int32Array | BigInt64Array | string[] | Int8Array | Int16Array | Float32Array | Float64Array | Uint8Array[] | number[] | DdbFunctionDefValue | DdbDurationValue | DdbDecimal32Value | DdbDecimal64Value | DdbDecimal32VectorValue | DdbDecimal64VectorValue | DdbDecimal128VectorValue | BigInt128Array | DdbSymbolExtendedValue | DdbArrayVectorValue | DdbMatrixValue | DdbObj<DdbValue>[] | DdbDurationVectorValue | DdbTensorValue | DdbChartValue;
403
+ export declare function convert(type: DdbType, value: DdbValue, le: boolean, { blob, timestamp }?: ConvertOptions): string | number | bigint | boolean | Uint8Array | Int32Array | BigInt64Array | string[] | Int8Array | Int16Array | Float32Array | Float64Array | Uint8Array[] | number[] | DdbFunctionDefValue | DdbDurationValue | DdbDecimal32Value | DdbDecimal64Value | DdbDecimal32VectorValue | DdbDecimal64VectorValue | DdbDecimal128VectorValue | BigInt128Array | DdbSymbolExtendedValue | DdbArrayVectorValue | DdbMatrixValue | DdbObj<DdbValue>[] | DdbDurationVectorValue | DdbTensorValue | DdbChartValue;
401
404
  /** 转换一个向量到 js 原生数组 */
402
405
  export declare function converts(type: DdbType, value: DdbVectorValue, rows: number, le: boolean, options?: ConvertOptions): any[];
403
406
  export declare class DdbVoid extends DdbObj<undefined> {
@@ -561,10 +564,8 @@ export interface StreamingMessage<TRows = any> extends StreamingParams {
561
564
  window: {
562
565
  /** 建立连接开始 offset = 0, 随着 window 的移动逐渐增加 The establishment of the connection starts offset = 0, and gradually increases as the window moves */
563
566
  offset: number;
564
- /** segments 中 segment.row 的总和 sum of segment.row in segments */
565
- rows: number;
566
- /** 每次接收到的 data 组成的数组 An array of data received each time */
567
- segments: DdbTableData<TRows>[];
567
+ /** 历史数据 Historical data */
568
+ data: TRows[];
568
569
  /** 每次接收到的 obj 组成的数组 An array of obj received each time */
569
570
  objs: DdbObj<DdbVectorObj[]>[];
570
571
  };
package/index.js CHANGED
@@ -1065,6 +1065,38 @@ export class DdbObj {
1065
1065
  ...DdbObj.pack_vector_body(data, this.type, this.rows * this.cols)
1066
1066
  ];
1067
1067
  }
1068
+ case DdbForm.tensor: {
1069
+ const { le, value } = this;
1070
+ const { tensor_type, device_type, tensor_flags, dimensions, shape, strides, preserve_value, elem_count, data } = value;
1071
+ // 计算总的字节长度
1072
+ const totalLength = 10 + dimensions * 8 * 2 + 8 + 8 + data.length; // 12 字节元数据 + 维度信息 + 保留值和元素数量 + 数据部分
1073
+ const buffer = new ArrayBuffer(totalLength);
1074
+ const dv = new DataView(buffer);
1075
+ const uint8Array = new Uint8Array(buffer);
1076
+ // 写入元数据
1077
+ // uint8Array[0] = type;
1078
+ // uint8Array[1] = form;
1079
+ uint8Array[0] = tensor_type;
1080
+ uint8Array[1] = device_type;
1081
+ dv.setUint32(2, tensor_flags, le);
1082
+ dv.setInt32(6, dimensions, le);
1083
+ // 写入形状和步长
1084
+ const shapeStart = 10;
1085
+ const stridesStart = shapeStart + dimensions * 8;
1086
+ for (let d = 0; d < dimensions; d++) {
1087
+ dv.setBigInt64(shapeStart + d * 8, BigInt(shape[d]), le);
1088
+ dv.setBigInt64(stridesStart + d * 8, BigInt(strides[d]), le);
1089
+ }
1090
+ // 写入保留值和元素数量
1091
+ const preserveValueStart = stridesStart + dimensions * 8;
1092
+ dv.setBigInt64(preserveValueStart, preserve_value, le);
1093
+ const storageStart = preserveValueStart + 8;
1094
+ dv.setBigInt64(storageStart, BigInt(elem_count), le);
1095
+ // 写入数据
1096
+ const dataStart = storageStart + 8;
1097
+ uint8Array.set(data, dataStart);
1098
+ return [uint8Array];
1099
+ }
1068
1100
  default:
1069
1101
  throw new Error(t('vector {{type}} 暂不支持序列化', { type: get_type_name(type) }));
1070
1102
  }
@@ -1628,8 +1660,8 @@ let _formatter = new Intl.NumberFormat('en-US', { maximumFractionDigits: 20 });
1628
1660
  let _datetime_formatter = new Intl.DateTimeFormat('zh-CN', { dateStyle: 'short', timeStyle: 'medium', timeZone: 'UTC', hour12: false });
1629
1661
  /** 根据 DdbType 格式化单个元素 (value) 为字符串,空值返回 'null' 字符串 */
1630
1662
  export function format(type, value, le, options = {}) {
1663
+ const { grouping = true, timestamp = 'ms' } = options;
1631
1664
  const formatter = (() => {
1632
- const { grouping = true } = options;
1633
1665
  const decimals = options.decimals ?? _decimals;
1634
1666
  if (decimals !== _decimals || grouping !== _grouping) {
1635
1667
  _decimals = decimals;
@@ -1649,7 +1681,7 @@ export function format(type, value, le, options = {}) {
1649
1681
  let str;
1650
1682
  // formatter 可能会在 value 不属于 new Date() 有效值时,调用 抛出错误,这里统一处理
1651
1683
  try {
1652
- str = formatter(value);
1684
+ str = formatter(value, (type === DdbType.timestamp && timestamp === 's') ? 'YYYY.MM.DD HH:mm:ss' : undefined);
1653
1685
  }
1654
1686
  catch (error) {
1655
1687
  if (error instanceof RangeError)
@@ -1899,7 +1931,7 @@ export function formati(obj, index, options = {}) {
1899
1931
  }
1900
1932
  }
1901
1933
  }
1902
- export function convert(type, value, le, { blob = 'string' } = {}) {
1934
+ export function convert(type, value, le, { blob = 'string', timestamp = 'ms' } = {}) {
1903
1935
  switch (type) {
1904
1936
  case DdbType.void:
1905
1937
  return value === DdbVoidType.null ? null : undefined;
@@ -1954,7 +1986,7 @@ export function convert(type, value, le, { blob = 'string' } = {}) {
1954
1986
  case DdbType.decimal32:
1955
1987
  case DdbType.decimal64:
1956
1988
  case DdbType.decimal128:
1957
- return format(type, value, le, { colors: false });
1989
+ return format(type, value, le, { colors: false, timestamp });
1958
1990
  default:
1959
1991
  throw new Error(String(DdbType[type] || type) + t(' 暂时不支持转换为 js 对象'));
1960
1992
  }
@@ -3229,8 +3261,7 @@ export class DDB {
3229
3261
  let first = true;
3230
3262
  let win = {
3231
3263
  offset: 0,
3232
- rows: 0,
3233
- segments: [],
3264
+ data: [],
3234
3265
  objs: []
3235
3266
  };
3236
3267
  let schema;
@@ -3284,19 +3315,17 @@ export class DDB {
3284
3315
  data: seq(rows, i => zip_object(columns, seq(columns.length, j => _data[j][i])))
3285
3316
  };
3286
3317
  }
3287
- win.rows += rows;
3288
- win.segments.push(data);
3318
+ data.data.forEach(row => { win.data.push(row); });
3289
3319
  win.objs.push(obj);
3290
- if (win.rows >= winsize * 2 && win.segments.length >= 2) {
3320
+ if (win.data.length >= winsize * 2 && win.objs.length >= 2) {
3291
3321
  let winsize_ = 0;
3292
- let i = win.segments.length - 1;
3322
+ let i = win.objs.length - 1;
3293
3323
  // 往前移动至首个累计 winsize_ 超过 winsize 的位置
3294
3324
  for (; winsize_ < winsize; i--)
3295
- winsize_ += win.segments[i].data.length;
3296
- win.segments = win.segments.slice(i);
3325
+ winsize_ += win.objs[i].value[0].rows;
3326
+ win.offset += win.data.length - winsize_;
3327
+ win.data = win.data.slice(-winsize_);
3297
3328
  win.objs = win.objs.slice(i);
3298
- win.offset += win.rows - winsize_;
3299
- win.rows = winsize_;
3300
3329
  }
3301
3330
  }
3302
3331
  this.streaming.handler({