dolphindb 2.0.520 → 2.0.521

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/index.d.ts CHANGED
@@ -10,6 +10,7 @@ export declare enum DdbForm {
10
10
  dict = 5,
11
11
  table = 6,
12
12
  chart = 7,
13
+ /** Node internal communication may be used, calling function execution script generally does not return this type */
13
14
  chunk = 8,
14
15
  /** sysobj */
15
16
  object = 9
@@ -106,6 +107,33 @@ export interface DdbMatrixValue {
106
107
  cols: DdbObj<DdbVectorValue>;
107
108
  data: DdbVectorValue;
108
109
  }
110
+ export declare type DdbDictValue = [DdbObj<DdbVectorValue>, DdbObj<DdbVectorValue>];
111
+ export declare enum DdbChartType {
112
+ area = 0,
113
+ bar = 1,
114
+ column = 2,
115
+ histogram = 3,
116
+ line = 4,
117
+ pie = 5,
118
+ scatter = 6,
119
+ trend = 7,
120
+ kline = 8,
121
+ stack = 9
122
+ }
123
+ export interface DdbChartValue {
124
+ /** original: chartType */
125
+ type: DdbChartType;
126
+ stacking: boolean;
127
+ titles: {
128
+ chart: string;
129
+ x_axis: string;
130
+ y_axis: string;
131
+ };
132
+ extras: {
133
+ multi_y_axis: boolean;
134
+ };
135
+ data: DdbObj<DdbMatrixValue>;
136
+ }
109
137
  export declare type DdbScalarValue = null | boolean | number | bigint | string | Uint8Array | // uuid, ipaddr, int128, blob
110
138
  [
111
139
  number,
@@ -116,7 +144,7 @@ export declare type DdbVectorValue = Uint8Array | Int8Array | Int16Array | Int32
116
144
  Uint8Array[] | // blob
117
145
  DdbObj[] | // any
118
146
  DdbSymbolExtendedValue | DdbArrayVectorBlock[];
119
- export declare type DdbValue = DdbScalarValue | DdbVectorValue | DdbMatrixValue;
147
+ export declare type DdbValue = DdbScalarValue | DdbVectorValue | DdbMatrixValue | DdbDictValue | DdbChartValue;
120
148
  export declare const nulls: {
121
149
  readonly int8: -128;
122
150
  readonly int16: -32768;
@@ -182,8 +210,24 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
182
210
  pack(): Uint8Array;
183
211
  static pack_vector_body(value: DdbVectorValue, type: DdbType, length: number): ArrayBufferView[];
184
212
  [inspect.custom](depth: number, options: InspectOptions, _inspect: any): string;
213
+ /** 自动转换 js string, boolean 为 DdbObj */
214
+ static to_ddbobj(value: DdbObj | string | boolean): DdbObj;
215
+ /** 转换 js 数组为 DdbObj[] */
216
+ static to_ddbobjs(values: any[]): DdbObj<DdbValue>[];
185
217
  to_rows<T extends Record<string, any> = Record<string, any>>(): T[];
186
- to_dict<T = Record<string, any>>(): T;
218
+ /** convert dict<string, any> to js object (Record<string, any>)
219
+ - options?:
220
+ - strip?: `false` Whether to directly extract and strip the value in DdbObj as the value of js object (discard the rest of the information in DdbObj, only keep the value)
221
+ - deep?: `false` Whether to convert recursively
222
+ */
223
+ to_dict<T extends Record<string, DdbObj> = Record<string, DdbObj>>(): T;
224
+ to_dict<T extends Record<string, any> = Record<string, any>>(options: {
225
+ strip: true;
226
+ }): T;
227
+ to_dict<T extends Record<string, any> = Record<string, any>>(options?: {
228
+ strip?: boolean;
229
+ deep?: boolean;
230
+ }): T;
187
231
  }
188
232
  export declare function format(type: DdbType, value: DdbValue, le: boolean, options: InspectOptions): string;
189
233
  export declare class DdbVoid extends DdbObj<undefined> {
@@ -232,7 +276,7 @@ export declare class DdbVectorString extends DdbObj<string[]> {
232
276
  constructor(strings: string[], name?: string);
233
277
  }
234
278
  export declare class DdbVectorAny extends DdbObj {
235
- constructor(objs: DdbObj<DdbValue>[], name?: string);
279
+ constructor(objs: (DdbObj | string | boolean)[], name?: string);
236
280
  }
237
281
  export declare class DdbVectorSymbol extends DdbObj<DdbSymbolExtendedValue> {
238
282
  constructor(strings: string[], name?: string);
@@ -246,6 +290,14 @@ export declare class DdbSetDouble extends DdbObj<Float64Array> {
246
290
  export declare class DdbSetString extends DdbObj<string[]> {
247
291
  constructor(strings: string[] | Set<string>);
248
292
  }
293
+ /** Constructs a DdbDict object, which supports two usages:
294
+ - The incoming type is the keys of DdbObj<DdbVectorValue>, and the two parameters of values directly form the DdbDict of dict<keys.type, values.type>
295
+ - Pass in js object (type is Record<string, boolean | string | DdbObj>), automatically converted to DdbDict of dict<string, any>
296
+ */
297
+ export declare class DdbDict extends DdbObj<DdbDictValue> {
298
+ constructor(obj: Record<string, boolean | string | DdbObj>);
299
+ constructor(keys: DdbObj<DdbVectorValue>, values: DdbObj<DdbVectorValue>);
300
+ }
249
301
  export declare class DdbTable extends DdbObj<DdbObj[]> {
250
302
  constructor(columns: DdbObj[], name?: string);
251
303
  }
@@ -464,10 +516,6 @@ export declare class DDB {
464
516
  }): Promise<DdbObj<DdbValue>>;
465
517
  /** 解析服务端响应报文,返回去掉 header 的 data buf */
466
518
  parse_message(buf: Uint8Array, parse_object?: boolean): DdbMessage;
467
- /** 自动转换 js string, boolean 为 DdbObj */
468
- to_ddbobj(value: DdbObj | string | boolean): DdbObj;
469
- /** 转换 js 数组为 DdbObj[] */
470
- to_ddbobjs(values: any[]): DdbObj<DdbValue>[];
471
519
  }
472
520
  export interface DdbMessageListener {
473
521
  (message: DdbMessage, _this: DDB): any;
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.nanotimestamp2str = exports.nanotimestamp2ns = exports.nanotime2str = exports.nanotime2ns = exports.str2timestamp = exports.datehour2str = exports.datehour2ms = exports.timestamp2str = exports.timestamp2ms = exports.datetime2str = exports.datetime2ms = exports.second2str = exports.second2ms = exports.minute2str = exports.minute2ms = exports.time2str = exports.time2ms = exports.month2str = exports.month2ms = exports.date2str = exports.date2ms = exports.DdbTable = exports.DdbSetString = exports.DdbSetDouble = exports.DdbSetInt = exports.DdbVectorSymbol = exports.DdbVectorAny = exports.DdbVectorString = exports.DdbVectorDouble = exports.DdbVectorInt = exports.DdbFunction = exports.DdbPair = exports.DdbNanoTimeStamp = exports.DdbTimeStamp = exports.DdbDateTime = exports.DdbDouble = exports.DdbLong = exports.DdbString = exports.DdbInt = exports.DdbChar = exports.DdbBool = exports.DdbVoid = exports.format = exports.DdbObj = exports.timezone_offset = exports.nulls = exports.DdbDurationUnit = exports.DdbFunctionType = exports.DdbType = exports.DdbForm = void 0;
4
- exports.DDB = exports.int1282str = exports.uuid2str = exports.ipaddr2str = exports.str2nanotimestamp = void 0;
3
+ exports.nanotime2str = exports.nanotime2ns = exports.str2timestamp = exports.datehour2str = exports.datehour2ms = exports.timestamp2str = exports.timestamp2ms = exports.datetime2str = exports.datetime2ms = exports.second2str = exports.second2ms = exports.minute2str = exports.minute2ms = exports.time2str = exports.time2ms = exports.month2str = exports.month2ms = exports.date2str = exports.date2ms = exports.DdbTable = exports.DdbDict = exports.DdbSetString = exports.DdbSetDouble = exports.DdbSetInt = exports.DdbVectorSymbol = exports.DdbVectorAny = exports.DdbVectorString = exports.DdbVectorDouble = exports.DdbVectorInt = exports.DdbFunction = exports.DdbPair = exports.DdbNanoTimeStamp = exports.DdbTimeStamp = exports.DdbDateTime = exports.DdbDouble = exports.DdbLong = exports.DdbString = exports.DdbInt = exports.DdbChar = exports.DdbBool = exports.DdbVoid = exports.format = exports.DdbObj = exports.timezone_offset = exports.nulls = exports.DdbChartType = exports.DdbDurationUnit = exports.DdbFunctionType = exports.DdbType = exports.DdbForm = void 0;
4
+ exports.DDB = exports.int1282str = exports.uuid2str = exports.ipaddr2str = exports.str2nanotimestamp = exports.nanotimestamp2str = exports.nanotimestamp2ns = void 0;
5
5
  const tslib_1 = require("tslib");
6
6
  const ws_1 = require("ws");
7
7
  const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
@@ -21,6 +21,7 @@ var DdbForm;
21
21
  DdbForm[DdbForm["dict"] = 5] = "dict";
22
22
  DdbForm[DdbForm["table"] = 6] = "table";
23
23
  DdbForm[DdbForm["chart"] = 7] = "chart";
24
+ /** Node internal communication may be used, calling function execution script generally does not return this type */
24
25
  DdbForm[DdbForm["chunk"] = 8] = "chunk";
25
26
  /** sysobj */
26
27
  DdbForm[DdbForm["object"] = 9] = "object";
@@ -95,6 +96,19 @@ var DdbDurationUnit;
95
96
  DdbDurationUnit[DdbDurationUnit["y"] = 9] = "y";
96
97
  DdbDurationUnit[DdbDurationUnit["B"] = 10] = "B";
97
98
  })(DdbDurationUnit = exports.DdbDurationUnit || (exports.DdbDurationUnit = {}));
99
+ var DdbChartType;
100
+ (function (DdbChartType) {
101
+ DdbChartType[DdbChartType["area"] = 0] = "area";
102
+ DdbChartType[DdbChartType["bar"] = 1] = "bar";
103
+ DdbChartType[DdbChartType["column"] = 2] = "column";
104
+ DdbChartType[DdbChartType["histogram"] = 3] = "histogram";
105
+ DdbChartType[DdbChartType["line"] = 4] = "line";
106
+ DdbChartType[DdbChartType["pie"] = 5] = "pie";
107
+ DdbChartType[DdbChartType["scatter"] = 6] = "scatter";
108
+ DdbChartType[DdbChartType["trend"] = 7] = "trend";
109
+ DdbChartType[DdbChartType["kline"] = 8] = "kline";
110
+ DdbChartType[DdbChartType["stack"] = 9] = "stack";
111
+ })(DdbChartType = exports.DdbChartType || (exports.DdbChartType = {}));
98
112
  exports.nulls = {
99
113
  int8: -0x80,
100
114
  int16: -32768,
@@ -199,7 +213,8 @@ class DdbObj {
199
213
  value,
200
214
  });
201
215
  }
202
- case DdbForm.dict: {
216
+ case DdbForm.dict:
217
+ case DdbForm.chart: {
203
218
  // <Buffer 19 05 type = any, form = dict
204
219
  // 12 01 keys.type = string, keys.form = vector
205
220
  // 03 00 00 00 01 00 00 00 keys.cols = 3, keys.rows = 1
@@ -211,9 +226,9 @@ class DdbObj {
211
226
  keys.length += 2;
212
227
  let values = this.parse_vector(buf_data.subarray(keys.length + 2), le, buf_data[keys.length]);
213
228
  values.length += 2;
214
- return new this({
229
+ let dict = new this({
215
230
  le,
216
- form,
231
+ form: DdbForm.dict,
217
232
  type,
218
233
  length: i_data + keys.length + values.length,
219
234
  rows: keys.rows,
@@ -223,6 +238,30 @@ class DdbObj {
223
238
  values
224
239
  ],
225
240
  });
241
+ if (form === DdbForm.dict)
242
+ return dict;
243
+ else {
244
+ const { chartType: type, stacking, title: titles, extras, data, ...others } = dict.to_dict();
245
+ const [chart, x_axis, y_axis] = titles.value;
246
+ const { multiYAxes: multi_y_axis, ...extras_others } = extras.to_dict({ strip: true });
247
+ dict.form = DdbForm.chart;
248
+ dict.value = {
249
+ type: type.value,
250
+ stacking: stacking.value,
251
+ titles: {
252
+ chart,
253
+ x_axis,
254
+ y_axis,
255
+ },
256
+ extras: {
257
+ multi_y_axis,
258
+ ...extras_others,
259
+ },
260
+ data,
261
+ ...others,
262
+ };
263
+ return dict;
264
+ }
226
265
  }
227
266
  case DdbForm.matrix: {
228
267
  // rename!(
@@ -792,6 +831,23 @@ class DdbObj {
792
831
  value[0].pack(),
793
832
  value[1].pack(),
794
833
  ];
834
+ case DdbForm.chart: {
835
+ const { type, stacking, titles: { chart, x_axis, y_axis, }, extras: { multi_y_axis, ...extras_other }, data } = this.value;
836
+ const { value: [keys, values] } = new DdbDict({
837
+ chartType: new DdbInt(type),
838
+ stacking,
839
+ title: new DdbVectorString([chart, x_axis, y_axis]),
840
+ extras: new DdbDict({
841
+ multiYAxis: multi_y_axis,
842
+ ...extras_other
843
+ }),
844
+ data,
845
+ });
846
+ return [
847
+ keys.pack(),
848
+ values.pack(),
849
+ ];
850
+ }
795
851
  case DdbForm.matrix: {
796
852
  const { rows, cols, data } = value;
797
853
  return [
@@ -917,6 +973,8 @@ class DdbObj {
917
973
  return `table[${this.rows}r][${this.cols}c]`;
918
974
  case DdbForm.dict:
919
975
  return `dict<${DdbType[this.value[0].type]}, ${DdbType[this.value[1].type]}>`;
976
+ case DdbForm.chart:
977
+ return `chart<${DdbChartType[this.value.type]}>`;
920
978
  case DdbForm.matrix:
921
979
  return `matrix<${tname}>[${this.rows}r][${this.cols}c]`;
922
980
  default:
@@ -1012,9 +1070,27 @@ class DdbObj {
1012
1070
  })();
1013
1071
  return `${options.colors ? type.blue : type}(${this.name ? `${(0, utils_js_1.inspect)(this.name, options)}, ` : ''}${data})`;
1014
1072
  }
1073
+ /** 自动转换 js string, boolean 为 DdbObj */
1074
+ static to_ddbobj(value) {
1075
+ if (value && value instanceof DdbObj)
1076
+ return value;
1077
+ const type = typeof value;
1078
+ switch (type) {
1079
+ case 'string':
1080
+ return new DdbString(value);
1081
+ case 'boolean':
1082
+ return new DdbBool(value);
1083
+ default:
1084
+ throw new Error(`Cannot automatically convert ${type} to DdbObj`);
1085
+ }
1086
+ }
1087
+ /** 转换 js 数组为 DdbObj[] */
1088
+ static to_ddbobjs(values) {
1089
+ return values.map(value => this.to_ddbobj(value));
1090
+ }
1015
1091
  to_rows() {
1016
1092
  if (this.form !== DdbForm.table)
1017
- throw new Error('this.form 不是 DdbForm.table, 不能 to_rows');
1093
+ throw new Error('this.form is not DdbForm.table, cannot to_rows');
1018
1094
  let rows = new Array(this.rows);
1019
1095
  for (let i = 0; i < this.rows; i++) {
1020
1096
  let row = {};
@@ -1045,13 +1121,22 @@ class DdbObj {
1045
1121
  }
1046
1122
  return rows;
1047
1123
  }
1048
- to_dict() {
1124
+ to_dict({ strip, deep, } = {}) {
1049
1125
  if (this.form !== DdbForm.dict)
1050
- throw new Error('this.form 不是 DdbForm.dict, 不能转换为 Object');
1051
- const [{ value: keys }, { value: values }] = this.value;
1126
+ throw new Error('this.form is not DdbForm.dict and cannot be converted to js object');
1127
+ const [{ value: keys, type: key_type }, { value: values, type: value_type }] = this.value;
1128
+ if (key_type !== DdbType.string || value_type !== DdbType.any)
1129
+ throw new Error('Not dict<string, any>, automatic conversion to js object is not supported for the time being');
1130
+ if (deep && !strip)
1131
+ throw new Error('strip = true must be set when deep = true');
1052
1132
  let obj = {};
1053
- for (let i = 0; i < this.rows; i++)
1054
- obj[keys[i]] = values[i].value;
1133
+ for (let i = 0; i < this.rows; i++) {
1134
+ let value = values[i];
1135
+ if (deep && value.form === DdbForm.dict)
1136
+ obj[keys[i]] = value.to_dict({ strip, deep });
1137
+ else
1138
+ obj[keys[i]] = strip ? value.value : value;
1139
+ }
1055
1140
  return obj;
1056
1141
  }
1057
1142
  }
@@ -1432,7 +1517,7 @@ class DdbVectorAny extends DdbObj {
1432
1517
  type: DdbType.any,
1433
1518
  rows: objs.length,
1434
1519
  cols: 1,
1435
- value: objs,
1520
+ value: DdbObj.to_ddbobjs(objs),
1436
1521
  name,
1437
1522
  });
1438
1523
  }
@@ -1524,6 +1609,36 @@ class DdbSetString extends DdbObj {
1524
1609
  }
1525
1610
  }
1526
1611
  exports.DdbSetString = DdbSetString;
1612
+ /** Constructs a DdbDict object, which supports two usages:
1613
+ - The incoming type is the keys of DdbObj<DdbVectorValue>, and the two parameters of values directly form the DdbDict of dict<keys.type, values.type>
1614
+ - Pass in js object (type is Record<string, boolean | string | DdbObj>), automatically converted to DdbDict of dict<string, any>
1615
+ */
1616
+ class DdbDict extends DdbObj {
1617
+ constructor(arg0, arg1) {
1618
+ if (arg1)
1619
+ super({
1620
+ form: DdbForm.dict,
1621
+ type: arg1.type,
1622
+ rows: arg0.rows,
1623
+ cols: 2,
1624
+ value: [arg0, arg1]
1625
+ });
1626
+ else {
1627
+ const keys = Object.keys(arg0);
1628
+ super({
1629
+ form: DdbForm.dict,
1630
+ type: DdbType.any,
1631
+ rows: keys.length,
1632
+ cols: 2,
1633
+ value: [
1634
+ new DdbVectorString(keys),
1635
+ new DdbVectorAny(Object.values(arg0))
1636
+ ]
1637
+ });
1638
+ }
1639
+ }
1640
+ }
1641
+ exports.DdbDict = DdbDict;
1527
1642
  class DdbTable extends DdbObj {
1528
1643
  constructor(columns, name = '') {
1529
1644
  super({
@@ -2014,7 +2129,7 @@ class DDB {
2014
2129
  reject(error);
2015
2130
  }
2016
2131
  };
2017
- args = this.to_ddbobjs(args);
2132
+ args = DdbObj.to_ddbobjs(args);
2018
2133
  const command = this.enc.encode((() => {
2019
2134
  switch (type) {
2020
2135
  case 'function':
@@ -2082,7 +2197,7 @@ class DDB {
2082
2197
  args = [
2083
2198
  new DdbVectorString(nodes),
2084
2199
  func,
2085
- new DdbVectorAny(this.to_ddbobjs(args)),
2200
+ new DdbVectorAny(args),
2086
2201
  ...(() => {
2087
2202
  if (typeof add_node_alias !== 'undefined')
2088
2203
  return [add_node_alias];
@@ -2163,24 +2278,6 @@ class DDB {
2163
2278
  })
2164
2279
  };
2165
2280
  }
2166
- /** 自动转换 js string, boolean 为 DdbObj */
2167
- to_ddbobj(value) {
2168
- if (value instanceof DdbObj)
2169
- return value;
2170
- const type = typeof value;
2171
- switch (type) {
2172
- case 'string':
2173
- return new DdbString(value);
2174
- case 'boolean':
2175
- return new DdbBool(value);
2176
- default:
2177
- throw new Error(`不能自动转换 ${type} 至 DdbObj`);
2178
- }
2179
- }
2180
- /** 转换 js 数组为 DdbObj[] */
2181
- to_ddbobjs(values) {
2182
- return values.map(value => this.to_ddbobj(value));
2183
- }
2184
2281
  }
2185
2282
  exports.DDB = DDB;
2186
2283
  /** little endian (client) */