dolphindb 2.0.527 → 2.0.530

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
@@ -126,8 +126,8 @@ export interface DdbChartValue {
126
126
  x_axis: string;
127
127
  y_axis: string;
128
128
  };
129
- extras: {
130
- multi_y_axis: boolean;
129
+ extras?: {
130
+ multi_y_axes: boolean;
131
131
  };
132
132
  data: DdbObj<DdbMatrixValue>;
133
133
  }
@@ -206,7 +206,8 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
206
206
  ];
207
207
  pack(): Uint8Array;
208
208
  static pack_vector_body(value: DdbVectorValue, type: DdbType, length: number): ArrayBufferView[];
209
- toString(): any;
209
+ toString(colors?: boolean): any;
210
+ inspect_type(): string;
210
211
  /** 自动转换 js string, boolean 为 DdbObj */
211
212
  static to_ddbobj(value: DdbObj | string | boolean): DdbObj;
212
213
  /** 转换 js 数组为 DdbObj[] */
package/browser.js CHANGED
@@ -4,6 +4,7 @@ dayjs.extend(DayjsCustomParseFormat);
4
4
  import ipaddrjs from 'ipaddr.js';
5
5
  const { fromByteArray: buf2ipaddr } = ipaddrjs;
6
6
  import 'xshell/prototype.browser.js';
7
+ import { blue } from 'xshell/chalk.browser.js';
7
8
  import { concat } from 'xshell/utils.browser.js';
8
9
  import { connect_websocket } from 'xshell/net.browser.js';
9
10
  export var DdbForm;
@@ -269,7 +270,6 @@ export class DdbObj {
269
270
  else {
270
271
  const { chartType: type, stacking, title: titles, extras, data, ...others } = dict.to_dict();
271
272
  const [chart, x_axis, y_axis] = titles.value;
272
- const { multiYAxes: multi_y_axis, ...extras_others } = extras.to_dict({ strip: true });
273
273
  dict.form = DdbForm.chart;
274
274
  dict.value = {
275
275
  type: type.value,
@@ -279,10 +279,15 @@ export class DdbObj {
279
279
  x_axis,
280
280
  y_axis,
281
281
  },
282
- extras: {
283
- multi_y_axis,
284
- ...extras_others,
285
- },
282
+ ...extras ? (() => {
283
+ const { multiYAxes: multi_y_axes = false, ...extras_others } = extras.to_dict({ strip: true });
284
+ return {
285
+ extras: {
286
+ multi_y_axes,
287
+ ...extras_others,
288
+ }
289
+ };
290
+ })() : {},
286
291
  data,
287
292
  ...others,
288
293
  };
@@ -858,15 +863,20 @@ export class DdbObj {
858
863
  value[1].pack(),
859
864
  ];
860
865
  case DdbForm.chart: {
861
- const { type, stacking, titles: { chart, x_axis, y_axis, }, extras: { multi_y_axis, ...extras_other }, data } = this.value;
866
+ const { type, stacking, titles: { chart, x_axis, y_axis, }, extras, data } = this.value;
862
867
  const { value: [keys, values] } = new DdbDict({
863
868
  chartType: new DdbInt(type),
864
869
  stacking,
865
870
  title: new DdbVectorString([chart, x_axis, y_axis]),
866
- extras: new DdbDict({
867
- multiYAxis: multi_y_axis,
868
- ...extras_other
869
- }),
871
+ ...extras ? (() => {
872
+ const { multi_y_axes, ...extras_other } = extras;
873
+ return {
874
+ extras: new DdbDict({
875
+ multiYAxes: multi_y_axes,
876
+ ...extras_other
877
+ })
878
+ };
879
+ })() : {},
870
880
  data,
871
881
  });
872
882
  return [
@@ -979,34 +989,8 @@ export class DdbObj {
979
989
  throw new Error(`vector ${DdbType[type]} 暂不支持序列化`);
980
990
  }
981
991
  }
982
- toString() {
983
- const type = (() => {
984
- const tname = DdbType[this.type];
985
- switch (this.form) {
986
- case DdbForm.scalar:
987
- if (this.type === DdbType.functiondef)
988
- return `functiondef<${DdbFunctionType[this.value.type]}>`;
989
- return tname;
990
- case DdbForm.vector:
991
- if (64 <= this.type && this.type < 128)
992
- return `${DdbType[this.type - 64]}[][${this.rows}]`;
993
- return `${tname}[${this.rows}]`;
994
- case DdbForm.pair:
995
- return `pair<${tname}>`;
996
- case DdbForm.set:
997
- return `set<${tname}>[${this.rows}]`;
998
- case DdbForm.table:
999
- return `table[${this.rows}r][${this.cols}c]`;
1000
- case DdbForm.dict:
1001
- return `dict<${DdbType[this.value[0].type]}, ${DdbType[this.value[1].type]}>`;
1002
- case DdbForm.chart:
1003
- return `chart<${DdbChartType[this.value.type]}>`;
1004
- case DdbForm.matrix:
1005
- return `matrix<${tname}>[${this.rows}r][${this.cols}c]`;
1006
- default:
1007
- return `${DdbForm[this.form]} ${tname}`;
1008
- }
1009
- })();
992
+ toString(colors = false) {
993
+ const type = this.inspect_type();
1010
994
  const data = (() => {
1011
995
  switch (this.form) {
1012
996
  case DdbForm.scalar:
@@ -1094,7 +1078,34 @@ export class DdbObj {
1094
1078
  }
1095
1079
  return String(this.value);
1096
1080
  })();
1097
- return `${type}(${this.name ? `'${this.name}', ` : ''}${data})\n`;
1081
+ return `${colors ? blue(type) : type}(${this.name ? `'${this.name}', ` : ''}${data})\n`;
1082
+ }
1083
+ inspect_type() {
1084
+ const tname = DdbType[this.type];
1085
+ switch (this.form) {
1086
+ case DdbForm.scalar:
1087
+ if (this.type === DdbType.functiondef)
1088
+ return `functiondef<${DdbFunctionType[this.value.type]}>`;
1089
+ return tname;
1090
+ case DdbForm.vector:
1091
+ if (64 <= this.type && this.type < 128)
1092
+ return `${DdbType[this.type - 64]}[][${this.rows}]`;
1093
+ return `${tname}[${this.rows}]`;
1094
+ case DdbForm.pair:
1095
+ return `pair<${tname}>`;
1096
+ case DdbForm.set:
1097
+ return `set<${tname}>[${this.rows}]`;
1098
+ case DdbForm.table:
1099
+ return `table[${this.rows}r][${this.cols}c]`;
1100
+ case DdbForm.dict:
1101
+ return `dict<${DdbType[this.value[0].type]}, ${DdbType[this.value[1].type]}>`;
1102
+ case DdbForm.chart:
1103
+ return `chart<${DdbChartType[this.value.type]}>`;
1104
+ case DdbForm.matrix:
1105
+ return `matrix<${tname}>[${this.rows}r][${this.cols}c]`;
1106
+ default:
1107
+ return `${DdbForm[this.form]} ${tname}`;
1108
+ }
1098
1109
  }
1099
1110
  /** 自动转换 js string, boolean 为 DdbObj */
1100
1111
  static to_ddbobj(value) {