dolphindb 2.0.520 → 2.0.523

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,32 @@ 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
+ }
122
+ export interface DdbChartValue {
123
+ /** original: chartType */
124
+ type: DdbChartType;
125
+ stacking: boolean;
126
+ titles: {
127
+ chart: string;
128
+ x_axis: string;
129
+ y_axis: string;
130
+ };
131
+ extras: {
132
+ multi_y_axis: boolean;
133
+ };
134
+ data: DdbObj<DdbMatrixValue>;
135
+ }
109
136
  export declare type DdbScalarValue = null | boolean | number | bigint | string | Uint8Array | // uuid, ipaddr, int128, blob
110
137
  [
111
138
  number,
@@ -116,7 +143,7 @@ export declare type DdbVectorValue = Uint8Array | Int8Array | Int16Array | Int32
116
143
  Uint8Array[] | // blob
117
144
  DdbObj[] | // any
118
145
  DdbSymbolExtendedValue | DdbArrayVectorBlock[];
119
- export declare type DdbValue = DdbScalarValue | DdbVectorValue | DdbMatrixValue;
146
+ export declare type DdbValue = DdbScalarValue | DdbVectorValue | DdbMatrixValue | DdbDictValue | DdbChartValue;
120
147
  export declare const nulls: {
121
148
  readonly int8: -128;
122
149
  readonly int16: -32768;
@@ -182,8 +209,24 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
182
209
  pack(): Uint8Array;
183
210
  static pack_vector_body(value: DdbVectorValue, type: DdbType, length: number): ArrayBufferView[];
184
211
  [inspect.custom](depth: number, options: InspectOptions, _inspect: any): string;
212
+ /** 自动转换 js string, boolean 为 DdbObj */
213
+ static to_ddbobj(value: DdbObj | string | boolean): DdbObj;
214
+ /** 转换 js 数组为 DdbObj[] */
215
+ static to_ddbobjs(values: any[]): DdbObj<DdbValue>[];
185
216
  to_rows<T extends Record<string, any> = Record<string, any>>(): T[];
186
- to_dict<T = Record<string, any>>(): T;
217
+ /** convert dict<string, any> to js object (Record<string, any>)
218
+ - options?:
219
+ - 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)
220
+ - deep?: `false` Whether to convert recursively
221
+ */
222
+ to_dict<T extends Record<string, DdbObj> = Record<string, DdbObj>>(): T;
223
+ to_dict<T extends Record<string, any> = Record<string, any>>(options: {
224
+ strip: true;
225
+ }): T;
226
+ to_dict<T extends Record<string, any> = Record<string, any>>(options?: {
227
+ strip?: boolean;
228
+ deep?: boolean;
229
+ }): T;
187
230
  }
188
231
  export declare function format(type: DdbType, value: DdbValue, le: boolean, options: InspectOptions): string;
189
232
  export declare class DdbVoid extends DdbObj<undefined> {
@@ -232,7 +275,7 @@ export declare class DdbVectorString extends DdbObj<string[]> {
232
275
  constructor(strings: string[], name?: string);
233
276
  }
234
277
  export declare class DdbVectorAny extends DdbObj {
235
- constructor(objs: DdbObj<DdbValue>[], name?: string);
278
+ constructor(objs: (DdbObj | string | boolean)[], name?: string);
236
279
  }
237
280
  export declare class DdbVectorSymbol extends DdbObj<DdbSymbolExtendedValue> {
238
281
  constructor(strings: string[], name?: string);
@@ -246,6 +289,14 @@ export declare class DdbSetDouble extends DdbObj<Float64Array> {
246
289
  export declare class DdbSetString extends DdbObj<string[]> {
247
290
  constructor(strings: string[] | Set<string>);
248
291
  }
292
+ /** Constructs a DdbDict object, which supports two usages:
293
+ - 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>
294
+ - Pass in js object (type is Record<string, boolean | string | DdbObj>), automatically converted to DdbDict of dict<string, any>
295
+ */
296
+ export declare class DdbDict extends DdbObj<DdbDictValue> {
297
+ constructor(obj: Record<string, boolean | string | DdbObj>);
298
+ constructor(keys: DdbObj<DdbVectorValue>, values: DdbObj<DdbVectorValue>);
299
+ }
249
300
  export declare class DdbTable extends DdbObj<DdbObj[]> {
250
301
  constructor(columns: DdbObj[], name?: string);
251
302
  }
@@ -464,10 +515,6 @@ export declare class DDB {
464
515
  }): Promise<DdbObj<DdbValue>>;
465
516
  /** 解析服务端响应报文,返回去掉 header 的 data buf */
466
517
  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
518
  }
472
519
  export interface DdbMessageListener {
473
520
  (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,18 @@ 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 = exports.DdbChartType || (exports.DdbChartType = {}));
98
111
  exports.nulls = {
99
112
  int8: -0x80,
100
113
  int16: -32768,
@@ -199,7 +212,8 @@ class DdbObj {
199
212
  value,
200
213
  });
201
214
  }
202
- case DdbForm.dict: {
215
+ case DdbForm.dict:
216
+ case DdbForm.chart: {
203
217
  // <Buffer 19 05 type = any, form = dict
204
218
  // 12 01 keys.type = string, keys.form = vector
205
219
  // 03 00 00 00 01 00 00 00 keys.cols = 3, keys.rows = 1
@@ -211,9 +225,9 @@ class DdbObj {
211
225
  keys.length += 2;
212
226
  let values = this.parse_vector(buf_data.subarray(keys.length + 2), le, buf_data[keys.length]);
213
227
  values.length += 2;
214
- return new this({
228
+ let dict = new this({
215
229
  le,
216
- form,
230
+ form: DdbForm.dict,
217
231
  type,
218
232
  length: i_data + keys.length + values.length,
219
233
  rows: keys.rows,
@@ -223,6 +237,30 @@ class DdbObj {
223
237
  values
224
238
  ],
225
239
  });
240
+ if (form === DdbForm.dict)
241
+ return dict;
242
+ else {
243
+ const { chartType: type, stacking, title: titles, extras, data, ...others } = dict.to_dict();
244
+ const [chart, x_axis, y_axis] = titles.value;
245
+ const { multiYAxes: multi_y_axis, ...extras_others } = extras.to_dict({ strip: true });
246
+ dict.form = DdbForm.chart;
247
+ dict.value = {
248
+ type: type.value,
249
+ stacking: stacking.value,
250
+ titles: {
251
+ chart,
252
+ x_axis,
253
+ y_axis,
254
+ },
255
+ extras: {
256
+ multi_y_axis,
257
+ ...extras_others,
258
+ },
259
+ data,
260
+ ...others,
261
+ };
262
+ return dict;
263
+ }
226
264
  }
227
265
  case DdbForm.matrix: {
228
266
  // rename!(
@@ -792,6 +830,23 @@ class DdbObj {
792
830
  value[0].pack(),
793
831
  value[1].pack(),
794
832
  ];
833
+ case DdbForm.chart: {
834
+ const { type, stacking, titles: { chart, x_axis, y_axis, }, extras: { multi_y_axis, ...extras_other }, data } = this.value;
835
+ const { value: [keys, values] } = new DdbDict({
836
+ chartType: new DdbInt(type),
837
+ stacking,
838
+ title: new DdbVectorString([chart, x_axis, y_axis]),
839
+ extras: new DdbDict({
840
+ multiYAxis: multi_y_axis,
841
+ ...extras_other
842
+ }),
843
+ data,
844
+ });
845
+ return [
846
+ keys.pack(),
847
+ values.pack(),
848
+ ];
849
+ }
795
850
  case DdbForm.matrix: {
796
851
  const { rows, cols, data } = value;
797
852
  return [
@@ -917,6 +972,8 @@ class DdbObj {
917
972
  return `table[${this.rows}r][${this.cols}c]`;
918
973
  case DdbForm.dict:
919
974
  return `dict<${DdbType[this.value[0].type]}, ${DdbType[this.value[1].type]}>`;
975
+ case DdbForm.chart:
976
+ return `chart<${DdbChartType[this.value.type]}>`;
920
977
  case DdbForm.matrix:
921
978
  return `matrix<${tname}>[${this.rows}r][${this.cols}c]`;
922
979
  default:
@@ -1012,9 +1069,27 @@ class DdbObj {
1012
1069
  })();
1013
1070
  return `${options.colors ? type.blue : type}(${this.name ? `${(0, utils_js_1.inspect)(this.name, options)}, ` : ''}${data})`;
1014
1071
  }
1072
+ /** 自动转换 js string, boolean 为 DdbObj */
1073
+ static to_ddbobj(value) {
1074
+ if (value && value instanceof DdbObj)
1075
+ return value;
1076
+ const type = typeof value;
1077
+ switch (type) {
1078
+ case 'string':
1079
+ return new DdbString(value);
1080
+ case 'boolean':
1081
+ return new DdbBool(value);
1082
+ default:
1083
+ throw new Error(`Cannot automatically convert ${type} to DdbObj`);
1084
+ }
1085
+ }
1086
+ /** 转换 js 数组为 DdbObj[] */
1087
+ static to_ddbobjs(values) {
1088
+ return values.map(value => this.to_ddbobj(value));
1089
+ }
1015
1090
  to_rows() {
1016
1091
  if (this.form !== DdbForm.table)
1017
- throw new Error('this.form 不是 DdbForm.table, 不能 to_rows');
1092
+ throw new Error('this.form is not DdbForm.table, cannot to_rows');
1018
1093
  let rows = new Array(this.rows);
1019
1094
  for (let i = 0; i < this.rows; i++) {
1020
1095
  let row = {};
@@ -1045,13 +1120,22 @@ class DdbObj {
1045
1120
  }
1046
1121
  return rows;
1047
1122
  }
1048
- to_dict() {
1123
+ to_dict({ strip, deep, } = {}) {
1049
1124
  if (this.form !== DdbForm.dict)
1050
- throw new Error('this.form 不是 DdbForm.dict, 不能转换为 Object');
1051
- const [{ value: keys }, { value: values }] = this.value;
1125
+ throw new Error('this.form is not DdbForm.dict and cannot be converted to js object');
1126
+ const [{ value: keys, type: key_type }, { value: values, type: value_type }] = this.value;
1127
+ if (key_type !== DdbType.string || value_type !== DdbType.any)
1128
+ throw new Error('Not dict<string, any>, automatic conversion to js object is not supported for the time being');
1129
+ if (deep && !strip)
1130
+ throw new Error('strip = true must be set when deep = true');
1052
1131
  let obj = {};
1053
- for (let i = 0; i < this.rows; i++)
1054
- obj[keys[i]] = values[i].value;
1132
+ for (let i = 0; i < this.rows; i++) {
1133
+ let value = values[i];
1134
+ if (deep && value.form === DdbForm.dict)
1135
+ obj[keys[i]] = value.to_dict({ strip, deep });
1136
+ else
1137
+ obj[keys[i]] = strip ? value.value : value;
1138
+ }
1055
1139
  return obj;
1056
1140
  }
1057
1141
  }
@@ -1432,7 +1516,7 @@ class DdbVectorAny extends DdbObj {
1432
1516
  type: DdbType.any,
1433
1517
  rows: objs.length,
1434
1518
  cols: 1,
1435
- value: objs,
1519
+ value: DdbObj.to_ddbobjs(objs),
1436
1520
  name,
1437
1521
  });
1438
1522
  }
@@ -1524,6 +1608,36 @@ class DdbSetString extends DdbObj {
1524
1608
  }
1525
1609
  }
1526
1610
  exports.DdbSetString = DdbSetString;
1611
+ /** Constructs a DdbDict object, which supports two usages:
1612
+ - 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>
1613
+ - Pass in js object (type is Record<string, boolean | string | DdbObj>), automatically converted to DdbDict of dict<string, any>
1614
+ */
1615
+ class DdbDict extends DdbObj {
1616
+ constructor(arg0, arg1) {
1617
+ if (arg1)
1618
+ super({
1619
+ form: DdbForm.dict,
1620
+ type: arg1.type,
1621
+ rows: arg0.rows,
1622
+ cols: 2,
1623
+ value: [arg0, arg1]
1624
+ });
1625
+ else {
1626
+ const keys = Object.keys(arg0);
1627
+ super({
1628
+ form: DdbForm.dict,
1629
+ type: DdbType.any,
1630
+ rows: keys.length,
1631
+ cols: 2,
1632
+ value: [
1633
+ new DdbVectorString(keys),
1634
+ new DdbVectorAny(Object.values(arg0))
1635
+ ]
1636
+ });
1637
+ }
1638
+ }
1639
+ }
1640
+ exports.DdbDict = DdbDict;
1527
1641
  class DdbTable extends DdbObj {
1528
1642
  constructor(columns, name = '') {
1529
1643
  super({
@@ -2014,7 +2128,7 @@ class DDB {
2014
2128
  reject(error);
2015
2129
  }
2016
2130
  };
2017
- args = this.to_ddbobjs(args);
2131
+ args = DdbObj.to_ddbobjs(args);
2018
2132
  const command = this.enc.encode((() => {
2019
2133
  switch (type) {
2020
2134
  case 'function':
@@ -2082,7 +2196,7 @@ class DDB {
2082
2196
  args = [
2083
2197
  new DdbVectorString(nodes),
2084
2198
  func,
2085
- new DdbVectorAny(this.to_ddbobjs(args)),
2199
+ new DdbVectorAny(args),
2086
2200
  ...(() => {
2087
2201
  if (typeof add_node_alias !== 'undefined')
2088
2202
  return [add_node_alias];
@@ -2163,24 +2277,6 @@ class DDB {
2163
2277
  })
2164
2278
  };
2165
2279
  }
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
2280
  }
2185
2281
  exports.DDB = DDB;
2186
2282
  /** little endian (client) */