dolphindb 2.0.519 → 2.0.522

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,23 +289,39 @@ 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
  }
252
- export declare function date2str(date: number, format?: string): string;
303
+ export declare function date2ms(date: number | null): number;
304
+ export declare function date2str(date: number | null, format?: string): string;
305
+ export declare function month2ms(month: number | null): number | null;
253
306
  export declare function month2str(month: number | null): string;
254
- export declare function time2str(time: number, format?: string): string;
307
+ export declare function time2ms(time: number | null): number | null;
308
+ export declare function time2str(time: number | null, format?: string): string;
309
+ export declare function minute2ms(minute: number | null): number | null;
255
310
  export declare function minute2str(minute: number | null, format?: string): string;
311
+ export declare function second2ms(second: number | null): number | null;
256
312
  export declare function second2str(second: number | null, format?: string): string;
257
- export declare function datetime2str(datetime: number, format?: string): string;
313
+ export declare function datetime2ms(datetime: number | null): number | null;
314
+ export declare function datetime2str(datetime: number | null, format?: string): string;
315
+ export declare function timestamp2ms(timestamp: bigint | null): number | null;
258
316
  /** format timestamp (bigint) to string
259
317
  - timestamp: bigint value
260
318
  - format?:
261
319
  format string, default to `YYYY.MM.DD HH:mm:ss.SSS`
262
320
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
263
321
  */
264
- export declare function timestamp2str(timestamp: bigint, format?: string): string;
265
- export declare function datehour2str(datehour: number, format?: string): string;
322
+ export declare function timestamp2str(timestamp: bigint | null, format?: string): string;
323
+ export declare function datehour2ms(datehour: number | null): number | null;
324
+ export declare function datehour2str(datehour: number | null, format?: string): string;
266
325
  /** parse timestamp string to bigint value
267
326
  - str: timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
268
327
  - format?:
@@ -270,7 +329,9 @@ export declare function datehour2str(datehour: number, format?: string): string;
270
329
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
271
330
  */
272
331
  export declare function str2timestamp(str: string, format?: string): bigint;
273
- export declare function nanotime2str(nanotime: bigint, format?: string): string;
332
+ export declare function nanotime2ns(nanotime: bigint | null): bigint | null;
333
+ export declare function nanotime2str(nanotime: bigint | null, format?: string): string;
334
+ export declare function nanotimestamp2ns(nanotimestamp: bigint | null): bigint | null;
274
335
  /** format nanotimestamp value (bigint) to string
275
336
  - nanotimestamp: bigint value
276
337
  - format?:
@@ -278,7 +339,7 @@ export declare function nanotime2str(nanotime: bigint, format?: string): string;
278
339
  Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
279
340
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
280
341
  */
281
- export declare function nanotimestamp2str(nanotimestamp: bigint, format?: string): string;
342
+ export declare function nanotimestamp2str(nanotimestamp: bigint | null, format?: string): string;
282
343
  /** parse nano timestamp string to bigint value
283
344
  - str: nano timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
284
345
  - format?:
@@ -454,10 +515,6 @@ export declare class DDB {
454
515
  }): Promise<DdbObj<DdbValue>>;
455
516
  /** 解析服务端响应报文,返回去掉 header 的 data buf */
456
517
  parse_message(buf: Uint8Array, parse_object?: boolean): DdbMessage;
457
- /** 自动转换 js string, boolean 为 DdbObj */
458
- to_ddbobj(value: DdbObj | string | boolean): DdbObj;
459
- /** 转换 js 数组为 DdbObj[] */
460
- to_ddbobjs(values: any[]): DdbObj<DdbValue>[];
461
518
  }
462
519
  export interface DdbMessageListener {
463
520
  (message: DdbMessage, _this: DDB): any;
package/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DDB = exports.int1282str = exports.uuid2str = exports.ipaddr2str = exports.str2nanotimestamp = exports.nanotimestamp2str = exports.nanotime2str = exports.str2timestamp = exports.datehour2str = exports.timestamp2str = exports.datetime2str = exports.second2str = exports.minute2str = exports.time2str = exports.month2str = exports.date2str = 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;
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;
4
5
  const tslib_1 = require("tslib");
5
6
  const ws_1 = require("ws");
6
7
  const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
@@ -20,6 +21,7 @@ var DdbForm;
20
21
  DdbForm[DdbForm["dict"] = 5] = "dict";
21
22
  DdbForm[DdbForm["table"] = 6] = "table";
22
23
  DdbForm[DdbForm["chart"] = 7] = "chart";
24
+ /** Node internal communication may be used, calling function execution script generally does not return this type */
23
25
  DdbForm[DdbForm["chunk"] = 8] = "chunk";
24
26
  /** sysobj */
25
27
  DdbForm[DdbForm["object"] = 9] = "object";
@@ -94,6 +96,18 @@ var DdbDurationUnit;
94
96
  DdbDurationUnit[DdbDurationUnit["y"] = 9] = "y";
95
97
  DdbDurationUnit[DdbDurationUnit["B"] = 10] = "B";
96
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 = {}));
97
111
  exports.nulls = {
98
112
  int8: -0x80,
99
113
  int16: -32768,
@@ -198,7 +212,8 @@ class DdbObj {
198
212
  value,
199
213
  });
200
214
  }
201
- case DdbForm.dict: {
215
+ case DdbForm.dict:
216
+ case DdbForm.chart: {
202
217
  // <Buffer 19 05 type = any, form = dict
203
218
  // 12 01 keys.type = string, keys.form = vector
204
219
  // 03 00 00 00 01 00 00 00 keys.cols = 3, keys.rows = 1
@@ -210,9 +225,9 @@ class DdbObj {
210
225
  keys.length += 2;
211
226
  let values = this.parse_vector(buf_data.subarray(keys.length + 2), le, buf_data[keys.length]);
212
227
  values.length += 2;
213
- return new this({
228
+ let dict = new this({
214
229
  le,
215
- form,
230
+ form: DdbForm.dict,
216
231
  type,
217
232
  length: i_data + keys.length + values.length,
218
233
  rows: keys.rows,
@@ -222,6 +237,30 @@ class DdbObj {
222
237
  values
223
238
  ],
224
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
+ }
225
264
  }
226
265
  case DdbForm.matrix: {
227
266
  // rename!(
@@ -791,6 +830,23 @@ class DdbObj {
791
830
  value[0].pack(),
792
831
  value[1].pack(),
793
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
+ }
794
850
  case DdbForm.matrix: {
795
851
  const { rows, cols, data } = value;
796
852
  return [
@@ -916,6 +972,8 @@ class DdbObj {
916
972
  return `table[${this.rows}r][${this.cols}c]`;
917
973
  case DdbForm.dict:
918
974
  return `dict<${DdbType[this.value[0].type]}, ${DdbType[this.value[1].type]}>`;
975
+ case DdbForm.chart:
976
+ return `chart<${DdbChartType[this.value.type]}>`;
919
977
  case DdbForm.matrix:
920
978
  return `matrix<${tname}>[${this.rows}r][${this.cols}c]`;
921
979
  default:
@@ -1011,9 +1069,27 @@ class DdbObj {
1011
1069
  })();
1012
1070
  return `${options.colors ? type.blue : type}(${this.name ? `${(0, utils_js_1.inspect)(this.name, options)}, ` : ''}${data})`;
1013
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
+ }
1014
1090
  to_rows() {
1015
1091
  if (this.form !== DdbForm.table)
1016
- throw new Error('this.form 不是 DdbForm.table, 不能 to_rows');
1092
+ throw new Error('this.form is not DdbForm.table, cannot to_rows');
1017
1093
  let rows = new Array(this.rows);
1018
1094
  for (let i = 0; i < this.rows; i++) {
1019
1095
  let row = {};
@@ -1044,13 +1120,22 @@ class DdbObj {
1044
1120
  }
1045
1121
  return rows;
1046
1122
  }
1047
- to_dict() {
1123
+ to_dict({ strip, deep, } = {}) {
1048
1124
  if (this.form !== DdbForm.dict)
1049
- throw new Error('this.form 不是 DdbForm.dict, 不能转换为 Object');
1050
- 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');
1051
1131
  let obj = {};
1052
- for (let i = 0; i < this.rows; i++)
1053
- 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
+ }
1054
1139
  return obj;
1055
1140
  }
1056
1141
  }
@@ -1431,7 +1516,7 @@ class DdbVectorAny extends DdbObj {
1431
1516
  type: DdbType.any,
1432
1517
  rows: objs.length,
1433
1518
  cols: 1,
1434
- value: objs,
1519
+ value: DdbObj.to_ddbobjs(objs),
1435
1520
  name,
1436
1521
  });
1437
1522
  }
@@ -1523,6 +1608,36 @@ class DdbSetString extends DdbObj {
1523
1608
  }
1524
1609
  }
1525
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;
1526
1641
  class DdbTable extends DdbObj {
1527
1642
  constructor(columns, name = '') {
1528
1643
  super({
@@ -1536,13 +1651,27 @@ class DdbTable extends DdbObj {
1536
1651
  }
1537
1652
  }
1538
1653
  exports.DdbTable = DdbTable;
1654
+ function date2ms(date) {
1655
+ return (date === null || date === exports.nulls.int32) ?
1656
+ null
1657
+ :
1658
+ exports.timezone_offset + 1000 * 3600 * 24 * date;
1659
+ }
1660
+ exports.date2ms = date2ms;
1539
1661
  function date2str(date, format = 'YYYY.MM.DD') {
1540
1662
  return (date === null || date === exports.nulls.int32) ?
1541
- 'null'
1663
+ null
1542
1664
  :
1543
- (0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * 24 * date).format(format);
1665
+ (0, dayjs_1.default)(date2ms(date)).format(format);
1544
1666
  }
1545
1667
  exports.date2str = date2str;
1668
+ function month2ms(month) {
1669
+ return (month === null || month === exports.nulls.int32) ?
1670
+ null
1671
+ :
1672
+ (0, dayjs_1.default)(month2str(month), 'YYYY.MM[M]').valueOf();
1673
+ }
1674
+ exports.month2ms = month2ms;
1546
1675
  function month2str(month) {
1547
1676
  if (month === null || month === exports.nulls.int32)
1548
1677
  return 'null';
@@ -1553,37 +1682,69 @@ function month2str(month) {
1553
1682
  return `${String(year).padStart(4, '0')}.${String(_month + 1).padStart(2, '0')}M`;
1554
1683
  }
1555
1684
  exports.month2str = month2str;
1685
+ function time2ms(time) {
1686
+ return (time === null || time === exports.nulls.int32) ?
1687
+ null
1688
+ :
1689
+ exports.timezone_offset + time;
1690
+ }
1691
+ exports.time2ms = time2ms;
1556
1692
  function time2str(time, format = 'HH:mm:ss.SSS') {
1557
1693
  return (time === null || time === exports.nulls.int32) ?
1558
- 'null'
1694
+ null
1559
1695
  :
1560
- (0, dayjs_1.default)(exports.timezone_offset + time)
1561
- .format(format);
1696
+ (0, dayjs_1.default)(time2ms(time)).format(format);
1562
1697
  }
1563
1698
  exports.time2str = time2str;
1699
+ function minute2ms(minute) {
1700
+ return (minute === null || minute === exports.nulls.int32) ?
1701
+ null
1702
+ :
1703
+ exports.timezone_offset + 60 * 1000 * minute;
1704
+ }
1705
+ exports.minute2ms = minute2ms;
1564
1706
  function minute2str(minute, format = 'HH:mm[m]') {
1565
1707
  return (minute === null || minute === exports.nulls.int32) ?
1566
1708
  'null'
1567
1709
  :
1568
- (0, dayjs_1.default)(exports.timezone_offset + 60 * 1000 * minute)
1569
- .format(format);
1710
+ (0, dayjs_1.default)(minute2ms(minute)).format(format);
1570
1711
  }
1571
1712
  exports.minute2str = minute2str;
1713
+ function second2ms(second) {
1714
+ return (second === null || second === exports.nulls.int32) ?
1715
+ null
1716
+ :
1717
+ exports.timezone_offset + 1000 * second;
1718
+ }
1719
+ exports.second2ms = second2ms;
1572
1720
  function second2str(second, format = 'HH:mm:ss') {
1573
1721
  return (second === null || second === exports.nulls.int32) ?
1574
1722
  'null'
1575
1723
  :
1576
- (0, dayjs_1.default)(exports.timezone_offset + 1000 * second)
1577
- .format(format);
1724
+ (0, dayjs_1.default)(second2ms(second)).format(format);
1578
1725
  }
1579
1726
  exports.second2str = second2str;
1727
+ function datetime2ms(datetime) {
1728
+ return (datetime === null || datetime === exports.nulls.int32) ?
1729
+ null
1730
+ :
1731
+ exports.timezone_offset + 1000 * datetime;
1732
+ }
1733
+ exports.datetime2ms = datetime2ms;
1580
1734
  function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
1581
1735
  return (datetime === null || datetime === exports.nulls.int32) ?
1582
1736
  'null'
1583
1737
  :
1584
- (0, dayjs_1.default)(exports.timezone_offset + 1000 * datetime).format(format);
1738
+ (0, dayjs_1.default)(datetime2ms(datetime)).format(format);
1585
1739
  }
1586
1740
  exports.datetime2str = datetime2str;
1741
+ function timestamp2ms(timestamp) {
1742
+ return (timestamp === null || timestamp === exports.nulls.int64) ?
1743
+ null
1744
+ :
1745
+ exports.timezone_offset + Number(timestamp);
1746
+ }
1747
+ exports.timestamp2ms = timestamp2ms;
1587
1748
  /** format timestamp (bigint) to string
1588
1749
  - timestamp: bigint value
1589
1750
  - format?:
@@ -1594,9 +1755,16 @@ function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1594
1755
  return (timestamp === null || timestamp === exports.nulls.int64) ?
1595
1756
  'null'
1596
1757
  :
1597
- (0, dayjs_1.default)(exports.timezone_offset + Number(timestamp)).format(format);
1758
+ (0, dayjs_1.default)(timestamp2ms(timestamp)).format(format);
1598
1759
  }
1599
1760
  exports.timestamp2str = timestamp2str;
1761
+ function datehour2ms(datehour) {
1762
+ return (datehour === null || datehour === exports.nulls.int32) ?
1763
+ null
1764
+ :
1765
+ exports.timezone_offset + 1000 * 3600 * datehour;
1766
+ }
1767
+ exports.datehour2ms = datehour2ms;
1600
1768
  function datehour2str(datehour, format = 'YYYY.MM.DDTHH') {
1601
1769
  return (datehour === null || datehour === exports.nulls.int32) ?
1602
1770
  'null'
@@ -1619,6 +1787,10 @@ function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1619
1787
  (0, dayjs_1.default)(str, format).valueOf());
1620
1788
  }
1621
1789
  exports.str2timestamp = str2timestamp;
1790
+ function nanotime2ns(nanotime) {
1791
+ return nanotimestamp2ns(nanotime);
1792
+ }
1793
+ exports.nanotime2ns = nanotime2ns;
1622
1794
  function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
1623
1795
  if (nanotime === null || nanotime === exports.nulls.int64)
1624
1796
  return 'null';
@@ -1636,6 +1808,13 @@ function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
1636
1808
  String(nanotime % 1000000000n).padStart(9, '0'));
1637
1809
  }
1638
1810
  exports.nanotime2str = nanotime2str;
1811
+ function nanotimestamp2ns(nanotimestamp) {
1812
+ return (nanotimestamp === null || nanotimestamp === exports.nulls.int64) ?
1813
+ null
1814
+ :
1815
+ BigInt(exports.timezone_offset) * 1000000n + nanotimestamp;
1816
+ }
1817
+ exports.nanotimestamp2ns = nanotimestamp2ns;
1639
1818
  /** format nanotimestamp value (bigint) to string
1640
1819
  - nanotimestamp: bigint value
1641
1820
  - format?:
@@ -1949,7 +2128,7 @@ class DDB {
1949
2128
  reject(error);
1950
2129
  }
1951
2130
  };
1952
- args = this.to_ddbobjs(args);
2131
+ args = DdbObj.to_ddbobjs(args);
1953
2132
  const command = this.enc.encode((() => {
1954
2133
  switch (type) {
1955
2134
  case 'function':
@@ -2017,7 +2196,7 @@ class DDB {
2017
2196
  args = [
2018
2197
  new DdbVectorString(nodes),
2019
2198
  func,
2020
- new DdbVectorAny(this.to_ddbobjs(args)),
2199
+ new DdbVectorAny(args),
2021
2200
  ...(() => {
2022
2201
  if (typeof add_node_alias !== 'undefined')
2023
2202
  return [add_node_alias];
@@ -2098,24 +2277,6 @@ class DDB {
2098
2277
  })
2099
2278
  };
2100
2279
  }
2101
- /** 自动转换 js string, boolean 为 DdbObj */
2102
- to_ddbobj(value) {
2103
- if (value instanceof DdbObj)
2104
- return value;
2105
- const type = typeof value;
2106
- switch (type) {
2107
- case 'string':
2108
- return new DdbString(value);
2109
- case 'boolean':
2110
- return new DdbBool(value);
2111
- default:
2112
- throw new Error(`不能自动转换 ${type} 至 DdbObj`);
2113
- }
2114
- }
2115
- /** 转换 js 数组为 DdbObj[] */
2116
- to_ddbobjs(values) {
2117
- return values.map(value => this.to_ddbobj(value));
2118
- }
2119
2280
  }
2120
2281
  exports.DDB = DDB;
2121
2282
  /** little endian (client) */