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/browser.d.ts +73 -16
- package/browser.js +205 -44
- package/browser.js.map +1 -1
- package/index.d.ts +71 -14
- package/index.js +203 -42
- package/index.js.map +1 -1
- package/language.d.ts +53 -0
- package/language.js +828 -0
- package/language.js.map +1 -0
- package/package.json +6 -6
package/browser.d.ts
CHANGED
|
@@ -8,13 +8,14 @@ export declare enum DdbForm {
|
|
|
8
8
|
dict = 5,
|
|
9
9
|
table = 6,
|
|
10
10
|
chart = 7,
|
|
11
|
+
/** Node internal communication may be used, calling function execution script generally does not return this type */
|
|
11
12
|
chunk = 8,
|
|
12
13
|
/** sysobj */
|
|
13
14
|
object = 9
|
|
14
15
|
}
|
|
15
16
|
/** DolphinDB DataType
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
The corresponding array vector type is 64 + base type
|
|
18
|
+
The corresponding extended type is 128 + base type
|
|
18
19
|
*/
|
|
19
20
|
export declare enum DdbType {
|
|
20
21
|
void = 0,
|
|
@@ -104,6 +105,32 @@ export interface DdbMatrixValue {
|
|
|
104
105
|
cols: DdbObj<DdbVectorValue>;
|
|
105
106
|
data: DdbVectorValue;
|
|
106
107
|
}
|
|
108
|
+
export declare type DdbDictValue = [DdbObj<DdbVectorValue>, DdbObj<DdbVectorValue>];
|
|
109
|
+
export declare enum DdbChartType {
|
|
110
|
+
area = 0,
|
|
111
|
+
bar = 1,
|
|
112
|
+
column = 2,
|
|
113
|
+
histogram = 3,
|
|
114
|
+
line = 4,
|
|
115
|
+
pie = 5,
|
|
116
|
+
scatter = 6,
|
|
117
|
+
trend = 7,
|
|
118
|
+
kline = 8
|
|
119
|
+
}
|
|
120
|
+
export interface DdbChartValue {
|
|
121
|
+
/** 原属性 chartType */
|
|
122
|
+
type: DdbChartType;
|
|
123
|
+
stacking: boolean;
|
|
124
|
+
titles: {
|
|
125
|
+
chart: string;
|
|
126
|
+
x_axis: string;
|
|
127
|
+
y_axis: string;
|
|
128
|
+
};
|
|
129
|
+
extras: {
|
|
130
|
+
multi_y_axis: boolean;
|
|
131
|
+
};
|
|
132
|
+
data: DdbObj<DdbMatrixValue>;
|
|
133
|
+
}
|
|
107
134
|
export declare type DdbScalarValue = null | boolean | number | bigint | string | Uint8Array | // uuid, ipaddr, int128, blob
|
|
108
135
|
[
|
|
109
136
|
number,
|
|
@@ -114,7 +141,7 @@ export declare type DdbVectorValue = Uint8Array | Int8Array | Int16Array | Int32
|
|
|
114
141
|
Uint8Array[] | // blob
|
|
115
142
|
DdbObj[] | // any
|
|
116
143
|
DdbSymbolExtendedValue | DdbArrayVectorBlock[];
|
|
117
|
-
export declare type DdbValue = DdbScalarValue | DdbVectorValue | DdbMatrixValue;
|
|
144
|
+
export declare type DdbValue = DdbScalarValue | DdbVectorValue | DdbMatrixValue | DdbDictValue | DdbChartValue;
|
|
118
145
|
export declare const nulls: {
|
|
119
146
|
readonly int8: -128;
|
|
120
147
|
readonly int16: -32768;
|
|
@@ -180,13 +207,29 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
|
|
|
180
207
|
pack(): Uint8Array;
|
|
181
208
|
static pack_vector_body(value: DdbVectorValue, type: DdbType, length: number): ArrayBufferView[];
|
|
182
209
|
toString(): string;
|
|
210
|
+
/** 自动转换 js string, boolean 为 DdbObj */
|
|
211
|
+
static to_ddbobj(value: DdbObj | string | boolean): DdbObj;
|
|
212
|
+
/** 转换 js 数组为 DdbObj[] */
|
|
213
|
+
static to_ddbobjs(values: any[]): DdbObj<DdbValue>[];
|
|
183
214
|
to_cols(): {
|
|
184
215
|
title: string;
|
|
185
216
|
dataIndex: string;
|
|
186
217
|
render?: any;
|
|
187
218
|
}[];
|
|
188
219
|
to_rows<T extends Record<string, any> = Record<string, any>>(): T[];
|
|
189
|
-
|
|
220
|
+
/** Automatically convert dict<string, any> to js object (Record<string, any>)
|
|
221
|
+
- options?:
|
|
222
|
+
- 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)
|
|
223
|
+
- deep?: `false` whether to convert recursively
|
|
224
|
+
*/
|
|
225
|
+
to_dict<T extends Record<string, DdbObj> = Record<string, DdbObj>>(): T;
|
|
226
|
+
to_dict<T extends Record<string, any> = Record<string, any>>(options: {
|
|
227
|
+
strip: true;
|
|
228
|
+
}): T;
|
|
229
|
+
to_dict<T extends Record<string, any> = Record<string, any>>(options?: {
|
|
230
|
+
strip?: boolean;
|
|
231
|
+
deep?: boolean;
|
|
232
|
+
}): T;
|
|
190
233
|
}
|
|
191
234
|
export declare function format(type: DdbType, value: DdbValue, le: boolean): string;
|
|
192
235
|
export declare class DdbVoid extends DdbObj<undefined> {
|
|
@@ -235,7 +278,7 @@ export declare class DdbVectorString extends DdbObj<string[]> {
|
|
|
235
278
|
constructor(strings: string[], name?: string);
|
|
236
279
|
}
|
|
237
280
|
export declare class DdbVectorAny extends DdbObj {
|
|
238
|
-
constructor(objs: DdbObj
|
|
281
|
+
constructor(objs: (DdbObj | string | boolean)[], name?: string);
|
|
239
282
|
}
|
|
240
283
|
export declare class DdbVectorSymbol extends DdbObj<DdbSymbolExtendedValue> {
|
|
241
284
|
constructor(strings: string[], name?: string);
|
|
@@ -249,23 +292,39 @@ export declare class DdbSetDouble extends DdbObj<Float64Array> {
|
|
|
249
292
|
export declare class DdbSetString extends DdbObj<string[]> {
|
|
250
293
|
constructor(strings: string[] | Set<string>);
|
|
251
294
|
}
|
|
295
|
+
/** Constructs a DdbDict object, which supports two usages:
|
|
296
|
+
- 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>
|
|
297
|
+
- Pass in js object (type is Record<string, boolean | string | DdbObj>), automatically converted to DdbDict of dict<string, any>
|
|
298
|
+
*/
|
|
299
|
+
export declare class DdbDict extends DdbObj<DdbDictValue> {
|
|
300
|
+
constructor(obj: Record<string, boolean | string | DdbObj>);
|
|
301
|
+
constructor(keys: DdbObj<DdbVectorValue>, values: DdbObj<DdbVectorValue>);
|
|
302
|
+
}
|
|
252
303
|
export declare class DdbTable extends DdbObj<DdbObj[]> {
|
|
253
304
|
constructor(columns: DdbObj[], name?: string);
|
|
254
305
|
}
|
|
255
|
-
export declare function
|
|
306
|
+
export declare function date2ms(date: number | null): number;
|
|
307
|
+
export declare function date2str(date: number | null, format?: string): string;
|
|
308
|
+
export declare function month2ms(month: number | null): number | null;
|
|
256
309
|
export declare function month2str(month: number | null): string;
|
|
257
|
-
export declare function
|
|
310
|
+
export declare function time2ms(time: number | null): number | null;
|
|
311
|
+
export declare function time2str(time: number | null, format?: string): string;
|
|
312
|
+
export declare function minute2ms(minute: number | null): number | null;
|
|
258
313
|
export declare function minute2str(minute: number | null, format?: string): string;
|
|
314
|
+
export declare function second2ms(second: number | null): number | null;
|
|
259
315
|
export declare function second2str(second: number | null, format?: string): string;
|
|
260
|
-
export declare function
|
|
316
|
+
export declare function datetime2ms(datetime: number | null): number | null;
|
|
317
|
+
export declare function datetime2str(datetime: number | null, format?: string): string;
|
|
318
|
+
export declare function timestamp2ms(timestamp: bigint | null): number | null;
|
|
261
319
|
/** format timestamp (bigint) to string
|
|
262
320
|
- timestamp: bigint value
|
|
263
321
|
- format?:
|
|
264
322
|
format string, default to `YYYY.MM.DD HH:mm:ss.SSS`
|
|
265
323
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
266
324
|
*/
|
|
267
|
-
export declare function timestamp2str(timestamp: bigint, format?: string): string;
|
|
268
|
-
export declare function
|
|
325
|
+
export declare function timestamp2str(timestamp: bigint | null, format?: string): string;
|
|
326
|
+
export declare function datehour2ms(datehour: number | null): number | null;
|
|
327
|
+
export declare function datehour2str(datehour: number | null, format?: string): string;
|
|
269
328
|
/** parse timestamp string to bigint value
|
|
270
329
|
- str: timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
|
|
271
330
|
- format?:
|
|
@@ -273,7 +332,9 @@ export declare function datehour2str(datehour: number, format?: string): string;
|
|
|
273
332
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
274
333
|
*/
|
|
275
334
|
export declare function str2timestamp(str: string, format?: string): bigint;
|
|
276
|
-
export declare function
|
|
335
|
+
export declare function nanotime2ns(nanotime: bigint | null): bigint | null;
|
|
336
|
+
export declare function nanotime2str(nanotime: bigint | null, format?: string): string;
|
|
337
|
+
export declare function nanotimestamp2ns(nanotimestamp: bigint | null): bigint | null;
|
|
277
338
|
/** format nanotimestamp value (bigint) to string
|
|
278
339
|
- nanotimestamp: bigint value
|
|
279
340
|
- format?:
|
|
@@ -281,7 +342,7 @@ export declare function nanotime2str(nanotime: bigint, format?: string): string;
|
|
|
281
342
|
Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
|
|
282
343
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
283
344
|
*/
|
|
284
|
-
export declare function nanotimestamp2str(nanotimestamp: bigint, format?: string): string;
|
|
345
|
+
export declare function nanotimestamp2str(nanotimestamp: bigint | null, format?: string): string;
|
|
285
346
|
/** parse nano timestamp string to bigint value
|
|
286
347
|
- str: nano timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
|
|
287
348
|
- format?:
|
|
@@ -457,10 +518,6 @@ export declare class DDB {
|
|
|
457
518
|
}): Promise<DdbObj<DdbValue>>;
|
|
458
519
|
/** 解析服务端响应报文,返回去掉 header 的 data buf */
|
|
459
520
|
parse_message(buf: Uint8Array, parse_object?: boolean): DdbMessage;
|
|
460
|
-
/** 自动转换 js string, boolean 为 DdbObj */
|
|
461
|
-
to_ddbobj(value: DdbObj | string | boolean): DdbObj;
|
|
462
|
-
/** 转换 js 数组为 DdbObj[] */
|
|
463
|
-
to_ddbobjs(values: any[]): DdbObj<DdbValue>[];
|
|
464
521
|
}
|
|
465
522
|
export interface DdbMessageListener {
|
|
466
523
|
(message: DdbMessage, _this: DDB): any;
|
package/browser.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
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.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 dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
6
7
|
const customParseFormat_js_1 = tslib_1.__importDefault(require("dayjs/plugin/customParseFormat.js"));
|
|
@@ -20,13 +21,14 @@ 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";
|
|
26
28
|
})(DdbForm = exports.DdbForm || (exports.DdbForm = {}));
|
|
27
29
|
/** DolphinDB DataType
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
The corresponding array vector type is 64 + base type
|
|
31
|
+
The corresponding extended type is 128 + base type
|
|
30
32
|
*/
|
|
31
33
|
var DdbType;
|
|
32
34
|
(function (DdbType) {
|
|
@@ -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
|
-
|
|
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 [
|
|
@@ -803,7 +859,7 @@ class DdbObj {
|
|
|
803
859
|
];
|
|
804
860
|
}
|
|
805
861
|
default:
|
|
806
|
-
throw new Error(`${DdbForm[form]}
|
|
862
|
+
throw new Error(`${DdbForm[form]} Serialization is not currently supported`);
|
|
807
863
|
}
|
|
808
864
|
})();
|
|
809
865
|
if (!body)
|
|
@@ -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:
|
|
@@ -1009,6 +1067,24 @@ class DdbObj {
|
|
|
1009
1067
|
})();
|
|
1010
1068
|
return `${type}(${this.name ? `'${this.name}', ` : ''}${data})\n`;
|
|
1011
1069
|
}
|
|
1070
|
+
/** 自动转换 js string, boolean 为 DdbObj */
|
|
1071
|
+
static to_ddbobj(value) {
|
|
1072
|
+
if (value && value instanceof DdbObj)
|
|
1073
|
+
return value;
|
|
1074
|
+
const type = typeof value;
|
|
1075
|
+
switch (type) {
|
|
1076
|
+
case 'string':
|
|
1077
|
+
return new DdbString(value);
|
|
1078
|
+
case 'boolean':
|
|
1079
|
+
return new DdbBool(value);
|
|
1080
|
+
default:
|
|
1081
|
+
throw new Error(`Cannot automatically convert ${type} to DdbObj`);
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
/** 转换 js 数组为 DdbObj[] */
|
|
1085
|
+
static to_ddbobjs(values) {
|
|
1086
|
+
return values.map(value => this.to_ddbobj(value));
|
|
1087
|
+
}
|
|
1012
1088
|
to_cols() {
|
|
1013
1089
|
return this.value.map(col => {
|
|
1014
1090
|
let col_ = {
|
|
@@ -1062,13 +1138,22 @@ class DdbObj {
|
|
|
1062
1138
|
}
|
|
1063
1139
|
return rows;
|
|
1064
1140
|
}
|
|
1065
|
-
to_dict() {
|
|
1141
|
+
to_dict({ strip, deep, } = {}) {
|
|
1066
1142
|
if (this.form !== DdbForm.dict)
|
|
1067
|
-
throw new Error('this.form is not DdbForm.dict
|
|
1068
|
-
const [{ value: keys }, { value: values }] = this.value;
|
|
1143
|
+
throw new Error('this.form is not DdbForm.dict and cannot be converted to js object');
|
|
1144
|
+
const [{ value: keys, type: key_type }, { value: values, type: value_type }] = this.value;
|
|
1145
|
+
if (key_type !== DdbType.string || value_type !== DdbType.any)
|
|
1146
|
+
throw new Error('Not dict<string, any>, automatic conversion to js object is not supported for the time being');
|
|
1147
|
+
if (deep && !strip)
|
|
1148
|
+
throw new Error('strip = true must be set when deep = true');
|
|
1069
1149
|
let obj = {};
|
|
1070
|
-
for (let i = 0; i < this.rows; i++)
|
|
1071
|
-
|
|
1150
|
+
for (let i = 0; i < this.rows; i++) {
|
|
1151
|
+
let value = values[i];
|
|
1152
|
+
if (deep && value.form === DdbForm.dict)
|
|
1153
|
+
obj[keys[i]] = value.to_dict({ strip, deep });
|
|
1154
|
+
else
|
|
1155
|
+
obj[keys[i]] = strip ? value.value : value;
|
|
1156
|
+
}
|
|
1072
1157
|
return obj;
|
|
1073
1158
|
}
|
|
1074
1159
|
}
|
|
@@ -1400,7 +1485,7 @@ class DdbVectorAny extends DdbObj {
|
|
|
1400
1485
|
type: DdbType.any,
|
|
1401
1486
|
rows: objs.length,
|
|
1402
1487
|
cols: 1,
|
|
1403
|
-
value: objs,
|
|
1488
|
+
value: DdbObj.to_ddbobjs(objs),
|
|
1404
1489
|
name,
|
|
1405
1490
|
});
|
|
1406
1491
|
}
|
|
@@ -1492,6 +1577,36 @@ class DdbSetString extends DdbObj {
|
|
|
1492
1577
|
}
|
|
1493
1578
|
}
|
|
1494
1579
|
exports.DdbSetString = DdbSetString;
|
|
1580
|
+
/** Constructs a DdbDict object, which supports two usages:
|
|
1581
|
+
- 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>
|
|
1582
|
+
- Pass in js object (type is Record<string, boolean | string | DdbObj>), automatically converted to DdbDict of dict<string, any>
|
|
1583
|
+
*/
|
|
1584
|
+
class DdbDict extends DdbObj {
|
|
1585
|
+
constructor(arg0, arg1) {
|
|
1586
|
+
if (arg1)
|
|
1587
|
+
super({
|
|
1588
|
+
form: DdbForm.dict,
|
|
1589
|
+
type: arg1.type,
|
|
1590
|
+
rows: arg0.rows,
|
|
1591
|
+
cols: 2,
|
|
1592
|
+
value: [arg0, arg1]
|
|
1593
|
+
});
|
|
1594
|
+
else {
|
|
1595
|
+
const keys = Object.keys(arg0);
|
|
1596
|
+
super({
|
|
1597
|
+
form: DdbForm.dict,
|
|
1598
|
+
type: DdbType.any,
|
|
1599
|
+
rows: keys.length,
|
|
1600
|
+
cols: 2,
|
|
1601
|
+
value: [
|
|
1602
|
+
new DdbVectorString(keys),
|
|
1603
|
+
new DdbVectorAny(Object.values(arg0))
|
|
1604
|
+
]
|
|
1605
|
+
});
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
exports.DdbDict = DdbDict;
|
|
1495
1610
|
class DdbTable extends DdbObj {
|
|
1496
1611
|
constructor(columns, name = '') {
|
|
1497
1612
|
super({
|
|
@@ -1505,13 +1620,27 @@ class DdbTable extends DdbObj {
|
|
|
1505
1620
|
}
|
|
1506
1621
|
}
|
|
1507
1622
|
exports.DdbTable = DdbTable;
|
|
1623
|
+
function date2ms(date) {
|
|
1624
|
+
return (date === null || date === exports.nulls.int32) ?
|
|
1625
|
+
null
|
|
1626
|
+
:
|
|
1627
|
+
exports.timezone_offset + 1000 * 3600 * 24 * date;
|
|
1628
|
+
}
|
|
1629
|
+
exports.date2ms = date2ms;
|
|
1508
1630
|
function date2str(date, format = 'YYYY.MM.DD') {
|
|
1509
1631
|
return (date === null || date === exports.nulls.int32) ?
|
|
1510
|
-
|
|
1632
|
+
null
|
|
1511
1633
|
:
|
|
1512
|
-
(0, dayjs_1.default)(
|
|
1634
|
+
(0, dayjs_1.default)(date2ms(date)).format(format);
|
|
1513
1635
|
}
|
|
1514
1636
|
exports.date2str = date2str;
|
|
1637
|
+
function month2ms(month) {
|
|
1638
|
+
return (month === null || month === exports.nulls.int32) ?
|
|
1639
|
+
null
|
|
1640
|
+
:
|
|
1641
|
+
(0, dayjs_1.default)(month2str(month), 'YYYY.MM[M]').valueOf();
|
|
1642
|
+
}
|
|
1643
|
+
exports.month2ms = month2ms;
|
|
1515
1644
|
function month2str(month) {
|
|
1516
1645
|
if (month === null || month === exports.nulls.int32)
|
|
1517
1646
|
return 'null';
|
|
@@ -1522,37 +1651,69 @@ function month2str(month) {
|
|
|
1522
1651
|
return `${String(year).padStart(4, '0')}.${String(_month + 1).padStart(2, '0')}M`;
|
|
1523
1652
|
}
|
|
1524
1653
|
exports.month2str = month2str;
|
|
1654
|
+
function time2ms(time) {
|
|
1655
|
+
return (time === null || time === exports.nulls.int32) ?
|
|
1656
|
+
null
|
|
1657
|
+
:
|
|
1658
|
+
exports.timezone_offset + time;
|
|
1659
|
+
}
|
|
1660
|
+
exports.time2ms = time2ms;
|
|
1525
1661
|
function time2str(time, format = 'HH:mm:ss.SSS') {
|
|
1526
1662
|
return (time === null || time === exports.nulls.int32) ?
|
|
1527
|
-
|
|
1663
|
+
null
|
|
1528
1664
|
:
|
|
1529
|
-
(0, dayjs_1.default)(
|
|
1530
|
-
.format(format);
|
|
1665
|
+
(0, dayjs_1.default)(time2ms(time)).format(format);
|
|
1531
1666
|
}
|
|
1532
1667
|
exports.time2str = time2str;
|
|
1668
|
+
function minute2ms(minute) {
|
|
1669
|
+
return (minute === null || minute === exports.nulls.int32) ?
|
|
1670
|
+
null
|
|
1671
|
+
:
|
|
1672
|
+
exports.timezone_offset + 60 * 1000 * minute;
|
|
1673
|
+
}
|
|
1674
|
+
exports.minute2ms = minute2ms;
|
|
1533
1675
|
function minute2str(minute, format = 'HH:mm[m]') {
|
|
1534
1676
|
return (minute === null || minute === exports.nulls.int32) ?
|
|
1535
1677
|
'null'
|
|
1536
1678
|
:
|
|
1537
|
-
(0, dayjs_1.default)(
|
|
1538
|
-
.format(format);
|
|
1679
|
+
(0, dayjs_1.default)(minute2ms(minute)).format(format);
|
|
1539
1680
|
}
|
|
1540
1681
|
exports.minute2str = minute2str;
|
|
1682
|
+
function second2ms(second) {
|
|
1683
|
+
return (second === null || second === exports.nulls.int32) ?
|
|
1684
|
+
null
|
|
1685
|
+
:
|
|
1686
|
+
exports.timezone_offset + 1000 * second;
|
|
1687
|
+
}
|
|
1688
|
+
exports.second2ms = second2ms;
|
|
1541
1689
|
function second2str(second, format = 'HH:mm:ss') {
|
|
1542
1690
|
return (second === null || second === exports.nulls.int32) ?
|
|
1543
1691
|
'null'
|
|
1544
1692
|
:
|
|
1545
|
-
(0, dayjs_1.default)(
|
|
1546
|
-
.format(format);
|
|
1693
|
+
(0, dayjs_1.default)(second2ms(second)).format(format);
|
|
1547
1694
|
}
|
|
1548
1695
|
exports.second2str = second2str;
|
|
1696
|
+
function datetime2ms(datetime) {
|
|
1697
|
+
return (datetime === null || datetime === exports.nulls.int32) ?
|
|
1698
|
+
null
|
|
1699
|
+
:
|
|
1700
|
+
exports.timezone_offset + 1000 * datetime;
|
|
1701
|
+
}
|
|
1702
|
+
exports.datetime2ms = datetime2ms;
|
|
1549
1703
|
function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
|
|
1550
1704
|
return (datetime === null || datetime === exports.nulls.int32) ?
|
|
1551
1705
|
'null'
|
|
1552
1706
|
:
|
|
1553
|
-
(0, dayjs_1.default)(
|
|
1707
|
+
(0, dayjs_1.default)(datetime2ms(datetime)).format(format);
|
|
1554
1708
|
}
|
|
1555
1709
|
exports.datetime2str = datetime2str;
|
|
1710
|
+
function timestamp2ms(timestamp) {
|
|
1711
|
+
return (timestamp === null || timestamp === exports.nulls.int64) ?
|
|
1712
|
+
null
|
|
1713
|
+
:
|
|
1714
|
+
exports.timezone_offset + Number(timestamp);
|
|
1715
|
+
}
|
|
1716
|
+
exports.timestamp2ms = timestamp2ms;
|
|
1556
1717
|
/** format timestamp (bigint) to string
|
|
1557
1718
|
- timestamp: bigint value
|
|
1558
1719
|
- format?:
|
|
@@ -1563,9 +1724,16 @@ function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
|
1563
1724
|
return (timestamp === null || timestamp === exports.nulls.int64) ?
|
|
1564
1725
|
'null'
|
|
1565
1726
|
:
|
|
1566
|
-
(0, dayjs_1.default)(
|
|
1727
|
+
(0, dayjs_1.default)(timestamp2ms(timestamp)).format(format);
|
|
1567
1728
|
}
|
|
1568
1729
|
exports.timestamp2str = timestamp2str;
|
|
1730
|
+
function datehour2ms(datehour) {
|
|
1731
|
+
return (datehour === null || datehour === exports.nulls.int32) ?
|
|
1732
|
+
null
|
|
1733
|
+
:
|
|
1734
|
+
exports.timezone_offset + 1000 * 3600 * datehour;
|
|
1735
|
+
}
|
|
1736
|
+
exports.datehour2ms = datehour2ms;
|
|
1569
1737
|
function datehour2str(datehour, format = 'YYYY.MM.DDTHH') {
|
|
1570
1738
|
return (datehour === null || datehour === exports.nulls.int32) ?
|
|
1571
1739
|
'null'
|
|
@@ -1588,6 +1756,10 @@ function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
|
1588
1756
|
(0, dayjs_1.default)(str, format).valueOf());
|
|
1589
1757
|
}
|
|
1590
1758
|
exports.str2timestamp = str2timestamp;
|
|
1759
|
+
function nanotime2ns(nanotime) {
|
|
1760
|
+
return nanotimestamp2ns(nanotime);
|
|
1761
|
+
}
|
|
1762
|
+
exports.nanotime2ns = nanotime2ns;
|
|
1591
1763
|
function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
|
|
1592
1764
|
if (nanotime === null || nanotime === exports.nulls.int64)
|
|
1593
1765
|
return 'null';
|
|
@@ -1605,6 +1777,13 @@ function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
|
|
|
1605
1777
|
String(nanotime % 1000000000n).padStart(9, '0'));
|
|
1606
1778
|
}
|
|
1607
1779
|
exports.nanotime2str = nanotime2str;
|
|
1780
|
+
function nanotimestamp2ns(nanotimestamp) {
|
|
1781
|
+
return (nanotimestamp === null || nanotimestamp === exports.nulls.int64) ?
|
|
1782
|
+
null
|
|
1783
|
+
:
|
|
1784
|
+
BigInt(exports.timezone_offset) * 1000000n + nanotimestamp;
|
|
1785
|
+
}
|
|
1786
|
+
exports.nanotimestamp2ns = nanotimestamp2ns;
|
|
1608
1787
|
/** format nanotimestamp value (bigint) to string
|
|
1609
1788
|
- nanotimestamp: bigint value
|
|
1610
1789
|
- format?:
|
|
@@ -1924,7 +2103,7 @@ class DDB {
|
|
|
1924
2103
|
reject(error);
|
|
1925
2104
|
}
|
|
1926
2105
|
};
|
|
1927
|
-
args =
|
|
2106
|
+
args = DdbObj.to_ddbobjs(args);
|
|
1928
2107
|
const command = this.enc.encode((() => {
|
|
1929
2108
|
switch (type) {
|
|
1930
2109
|
case 'function':
|
|
@@ -1992,7 +2171,7 @@ class DDB {
|
|
|
1992
2171
|
args = [
|
|
1993
2172
|
new DdbVectorString(nodes),
|
|
1994
2173
|
func,
|
|
1995
|
-
new DdbVectorAny(
|
|
2174
|
+
new DdbVectorAny(args),
|
|
1996
2175
|
...(() => {
|
|
1997
2176
|
if (typeof add_node_alias !== 'undefined')
|
|
1998
2177
|
return [add_node_alias];
|
|
@@ -2073,24 +2252,6 @@ class DDB {
|
|
|
2073
2252
|
})
|
|
2074
2253
|
};
|
|
2075
2254
|
}
|
|
2076
|
-
/** 自动转换 js string, boolean 为 DdbObj */
|
|
2077
|
-
to_ddbobj(value) {
|
|
2078
|
-
if (value instanceof DdbObj)
|
|
2079
|
-
return value;
|
|
2080
|
-
const type = typeof value;
|
|
2081
|
-
switch (type) {
|
|
2082
|
-
case 'string':
|
|
2083
|
-
return new DdbString(value);
|
|
2084
|
-
case 'boolean':
|
|
2085
|
-
return new DdbBool(value);
|
|
2086
|
-
default:
|
|
2087
|
-
throw new Error(`不能自动转换 ${type} 至 DdbObj`);
|
|
2088
|
-
}
|
|
2089
|
-
}
|
|
2090
|
-
/** 转换 js 数组为 DdbObj[] */
|
|
2091
|
-
to_ddbobjs(values) {
|
|
2092
|
-
return values.map(value => this.to_ddbobj(value));
|
|
2093
|
-
}
|
|
2094
2255
|
}
|
|
2095
2256
|
exports.DDB = DDB;
|
|
2096
2257
|
/** little endian (client) */
|