dolphindb 2.0.524 → 2.0.527
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 +3 -2
- package/browser.js +249 -259
- package/browser.js.map +1 -1
- package/index.d.ts +3 -2
- package/index.js +260 -272
- package/index.js.map +1 -1
- package/language.js +5 -8
- package/language.js.map +1 -1
- package/package.json +7 -7
package/browser.js
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const { fromByteArray: buf2ipaddr } = ipaddr_js_1.default;
|
|
11
|
-
require("xshell/prototype.browser.js");
|
|
12
|
-
const utils_browser_js_1 = require("xshell/utils.browser.js");
|
|
13
|
-
const net_browser_js_1 = require("xshell/net.browser.js");
|
|
14
|
-
var DdbForm;
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import DayjsCustomParseFormat from 'dayjs/plugin/customParseFormat.js';
|
|
3
|
+
dayjs.extend(DayjsCustomParseFormat);
|
|
4
|
+
import ipaddrjs from 'ipaddr.js';
|
|
5
|
+
const { fromByteArray: buf2ipaddr } = ipaddrjs;
|
|
6
|
+
import 'xshell/prototype.browser.js';
|
|
7
|
+
import { concat } from 'xshell/utils.browser.js';
|
|
8
|
+
import { connect_websocket } from 'xshell/net.browser.js';
|
|
9
|
+
export var DdbForm;
|
|
15
10
|
(function (DdbForm) {
|
|
16
11
|
DdbForm[DdbForm["scalar"] = 0] = "scalar";
|
|
17
12
|
DdbForm[DdbForm["vector"] = 1] = "vector";
|
|
@@ -25,12 +20,12 @@ var DdbForm;
|
|
|
25
20
|
DdbForm[DdbForm["chunk"] = 8] = "chunk";
|
|
26
21
|
/** sysobj */
|
|
27
22
|
DdbForm[DdbForm["object"] = 9] = "object";
|
|
28
|
-
})(DdbForm =
|
|
23
|
+
})(DdbForm = DdbForm || (DdbForm = {}));
|
|
29
24
|
/** DolphinDB DataType
|
|
30
25
|
The corresponding array vector type is 64 + base type
|
|
31
26
|
The corresponding extended type is 128 + base type
|
|
32
27
|
*/
|
|
33
|
-
var DdbType;
|
|
28
|
+
export var DdbType;
|
|
34
29
|
(function (DdbType) {
|
|
35
30
|
DdbType[DdbType["void"] = 0] = "void";
|
|
36
31
|
DdbType[DdbType["bool"] = 1] = "bool";
|
|
@@ -69,8 +64,8 @@ var DdbType;
|
|
|
69
64
|
DdbType[DdbType["duration"] = 36] = "duration";
|
|
70
65
|
DdbType[DdbType["object"] = 37] = "object";
|
|
71
66
|
DdbType[DdbType["symbol_extended"] = 145] = "symbol_extended";
|
|
72
|
-
})(DdbType =
|
|
73
|
-
var DdbFunctionType;
|
|
67
|
+
})(DdbType = DdbType || (DdbType = {}));
|
|
68
|
+
export var DdbFunctionType;
|
|
74
69
|
(function (DdbFunctionType) {
|
|
75
70
|
DdbFunctionType[DdbFunctionType["SystemFunc"] = 0] = "SystemFunc";
|
|
76
71
|
DdbFunctionType[DdbFunctionType["SystemProc"] = 1] = "SystemProc";
|
|
@@ -81,8 +76,8 @@ var DdbFunctionType;
|
|
|
81
76
|
DdbFunctionType[DdbFunctionType["PiecewiseFunc"] = 6] = "PiecewiseFunc";
|
|
82
77
|
DdbFunctionType[DdbFunctionType["JitFunc"] = 7] = "JitFunc";
|
|
83
78
|
DdbFunctionType[DdbFunctionType["JitPartialFunc"] = 8] = "JitPartialFunc";
|
|
84
|
-
})(DdbFunctionType =
|
|
85
|
-
var DdbDurationUnit;
|
|
79
|
+
})(DdbFunctionType = DdbFunctionType || (DdbFunctionType = {}));
|
|
80
|
+
export var DdbDurationUnit;
|
|
86
81
|
(function (DdbDurationUnit) {
|
|
87
82
|
DdbDurationUnit[DdbDurationUnit["ns"] = 0] = "ns";
|
|
88
83
|
DdbDurationUnit[DdbDurationUnit["us"] = 1] = "us";
|
|
@@ -95,8 +90,8 @@ var DdbDurationUnit;
|
|
|
95
90
|
DdbDurationUnit[DdbDurationUnit["M"] = 8] = "M";
|
|
96
91
|
DdbDurationUnit[DdbDurationUnit["y"] = 9] = "y";
|
|
97
92
|
DdbDurationUnit[DdbDurationUnit["B"] = 10] = "B";
|
|
98
|
-
})(DdbDurationUnit =
|
|
99
|
-
var DdbChartType;
|
|
93
|
+
})(DdbDurationUnit = DdbDurationUnit || (DdbDurationUnit = {}));
|
|
94
|
+
export var DdbChartType;
|
|
100
95
|
(function (DdbChartType) {
|
|
101
96
|
DdbChartType[DdbChartType["area"] = 0] = "area";
|
|
102
97
|
DdbChartType[DdbChartType["bar"] = 1] = "bar";
|
|
@@ -107,23 +102,55 @@ var DdbChartType;
|
|
|
107
102
|
DdbChartType[DdbChartType["scatter"] = 6] = "scatter";
|
|
108
103
|
DdbChartType[DdbChartType["trend"] = 7] = "trend";
|
|
109
104
|
DdbChartType[DdbChartType["kline"] = 8] = "kline";
|
|
110
|
-
})(DdbChartType =
|
|
111
|
-
|
|
105
|
+
})(DdbChartType = DdbChartType || (DdbChartType = {}));
|
|
106
|
+
export const nulls = {
|
|
112
107
|
int8: -0x80,
|
|
113
|
-
int16: -
|
|
114
|
-
int32: -
|
|
108
|
+
int16: -0x80_00,
|
|
109
|
+
int32: -0x80_00_00_00,
|
|
115
110
|
int64: -0x8000000000000000n,
|
|
116
111
|
float32: -3.4028234663852886e+38,
|
|
117
112
|
/** -Number.MAX_VALUE */
|
|
118
113
|
double: -Number.MAX_VALUE,
|
|
119
114
|
bytes16: Uint8Array.from(new Array(16).fill(0))
|
|
120
115
|
};
|
|
121
|
-
|
|
116
|
+
export const timezone_offset = 1000 * 60 * new Date().getTimezoneOffset();
|
|
122
117
|
/** 可以表示所有 DolphinDB 数据库中的数据类型 */
|
|
123
|
-
class DdbObj {
|
|
118
|
+
export class DdbObj {
|
|
119
|
+
static dec = new TextDecoder('utf-8');
|
|
120
|
+
static enc = new TextEncoder();
|
|
121
|
+
/** 维护已解析的 symbol base,比如流数据中后续的 symbol 向量可能只发送一个 base.id, base.size == 0, 依赖之前发送的 symbol base ?
|
|
122
|
+
只是暂存,如果一张表有多个 symbol 列,可能这个 symbol base 会被复用,不同的对象之间 symbol base 一般不复用
|
|
123
|
+
*/
|
|
124
|
+
static symbol_bases = {};
|
|
125
|
+
/** little endian (client) */
|
|
126
|
+
static le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
|
|
127
|
+
/** 是否为小端 (little endian) */
|
|
128
|
+
le = DdbObj.le_client;
|
|
129
|
+
/** 数据形式 https://www.dolphindb.cn/cn/help/DataTypesandStructures/DataForms/index.html */
|
|
130
|
+
form;
|
|
131
|
+
/** 数据类型 https://www.dolphindb.cn/cn/help/DataTypesandStructures/DataTypes/index.html */
|
|
132
|
+
type;
|
|
133
|
+
/** 占用 parse 时传入的 buf 的长度 */
|
|
134
|
+
length;
|
|
135
|
+
/** table name / column name */
|
|
136
|
+
name;
|
|
137
|
+
/**
|
|
138
|
+
最低维、第 1 维
|
|
139
|
+
- vector: rows = n, cols = 1
|
|
140
|
+
- pair: rows = 2, cols = 1
|
|
141
|
+
- matrix: rows = n, cols = m
|
|
142
|
+
- set: 同 vector
|
|
143
|
+
- dict: 包含 keys, values 向量
|
|
144
|
+
- table: 同 matrix
|
|
145
|
+
*/
|
|
146
|
+
rows;
|
|
147
|
+
/** 第 2 维 */
|
|
148
|
+
cols;
|
|
149
|
+
/** 实际数据。不同的 DdbForm, DdbType 使用 DdbValue 中不同的类型来表示实际数据 */
|
|
150
|
+
value;
|
|
151
|
+
/** 原始二进制数据,仅在 parse_object 为 false 时通过 parse_message 生成的顶层对象有这个属性 */
|
|
152
|
+
buffer;
|
|
124
153
|
constructor(data) {
|
|
125
|
-
/** 是否为小端 (little endian) */
|
|
126
|
-
this.le = DdbObj.le_client;
|
|
127
154
|
Object.assign(this, data);
|
|
128
155
|
}
|
|
129
156
|
static parse(buf, le) {
|
|
@@ -336,17 +363,17 @@ class DdbObj {
|
|
|
336
363
|
case DdbType.bool: {
|
|
337
364
|
const dv = new DataView(buf.buffer, buf.byteOffset);
|
|
338
365
|
const value = dv.getInt8(0);
|
|
339
|
-
return [1, value ===
|
|
366
|
+
return [1, value === nulls.int8 ? null : Boolean(value)];
|
|
340
367
|
}
|
|
341
368
|
case DdbType.char: {
|
|
342
369
|
const dv = new DataView(buf.buffer, buf.byteOffset);
|
|
343
370
|
const value = dv.getInt8(0);
|
|
344
|
-
return [1, value ===
|
|
371
|
+
return [1, value === nulls.int8 ? null : value];
|
|
345
372
|
}
|
|
346
373
|
case DdbType.short: {
|
|
347
374
|
const dv = new DataView(buf.buffer, buf.byteOffset);
|
|
348
375
|
const value = dv.getInt16(0, le);
|
|
349
|
-
return [2, value ===
|
|
376
|
+
return [2, value === nulls.int16 ? null : value];
|
|
350
377
|
}
|
|
351
378
|
case DdbType.int:
|
|
352
379
|
// datetime
|
|
@@ -359,17 +386,17 @@ class DdbObj {
|
|
|
359
386
|
case DdbType.datehour: {
|
|
360
387
|
const dv = new DataView(buf.buffer, buf.byteOffset);
|
|
361
388
|
const value = dv.getInt32(0, le);
|
|
362
|
-
return [4, value ===
|
|
389
|
+
return [4, value === nulls.int32 ? null : value];
|
|
363
390
|
}
|
|
364
391
|
case DdbType.float: {
|
|
365
392
|
const dv = new DataView(buf.buffer, buf.byteOffset);
|
|
366
393
|
const value = dv.getFloat32(0, le);
|
|
367
|
-
return [4, value ===
|
|
394
|
+
return [4, value === nulls.float32 ? null : value];
|
|
368
395
|
}
|
|
369
396
|
case DdbType.double: {
|
|
370
397
|
const dv = new DataView(buf.buffer, buf.byteOffset);
|
|
371
398
|
const value = dv.getFloat64(0, le);
|
|
372
|
-
return [8, value ===
|
|
399
|
+
return [8, value === nulls.double ? null : value];
|
|
373
400
|
}
|
|
374
401
|
case DdbType.long:
|
|
375
402
|
// timestamp
|
|
@@ -378,7 +405,7 @@ class DdbObj {
|
|
|
378
405
|
case DdbType.nanotimestamp: {
|
|
379
406
|
const dv = new DataView(buf.buffer, buf.byteOffset);
|
|
380
407
|
const value = dv.getBigInt64(0, le);
|
|
381
|
-
return [8, value ===
|
|
408
|
+
return [8, value === nulls.int64 ? null : value];
|
|
382
409
|
}
|
|
383
410
|
case DdbType.string:
|
|
384
411
|
case DdbType.symbol:
|
|
@@ -700,21 +727,21 @@ class DdbObj {
|
|
|
700
727
|
case DdbType.bool:
|
|
701
728
|
return [
|
|
702
729
|
Int8Array.of(value === null ?
|
|
703
|
-
|
|
730
|
+
nulls.int8
|
|
704
731
|
:
|
|
705
732
|
Number(value))
|
|
706
733
|
];
|
|
707
734
|
case DdbType.char:
|
|
708
735
|
return [
|
|
709
736
|
Int8Array.of((value === null ?
|
|
710
|
-
|
|
737
|
+
nulls.int8
|
|
711
738
|
:
|
|
712
739
|
value))
|
|
713
740
|
];
|
|
714
741
|
case DdbType.short:
|
|
715
742
|
return [
|
|
716
743
|
Int16Array.of(value === null ?
|
|
717
|
-
|
|
744
|
+
nulls.int16
|
|
718
745
|
:
|
|
719
746
|
value)
|
|
720
747
|
];
|
|
@@ -729,21 +756,21 @@ class DdbObj {
|
|
|
729
756
|
case DdbType.datehour:
|
|
730
757
|
return [
|
|
731
758
|
Int32Array.of(value === null ?
|
|
732
|
-
|
|
759
|
+
nulls.int32
|
|
733
760
|
:
|
|
734
761
|
value)
|
|
735
762
|
];
|
|
736
763
|
case DdbType.float:
|
|
737
764
|
return [
|
|
738
765
|
Float32Array.of(value === null ?
|
|
739
|
-
|
|
766
|
+
nulls.float32
|
|
740
767
|
:
|
|
741
768
|
value)
|
|
742
769
|
];
|
|
743
770
|
case DdbType.double:
|
|
744
771
|
return [
|
|
745
772
|
Float64Array.of(value === null ?
|
|
746
|
-
|
|
773
|
+
nulls.double
|
|
747
774
|
:
|
|
748
775
|
value)
|
|
749
776
|
];
|
|
@@ -754,7 +781,7 @@ class DdbObj {
|
|
|
754
781
|
case DdbType.nanotimestamp:
|
|
755
782
|
return [
|
|
756
783
|
BigInt64Array.of(value === null ?
|
|
757
|
-
|
|
784
|
+
nulls.int64
|
|
758
785
|
:
|
|
759
786
|
value)
|
|
760
787
|
];
|
|
@@ -864,7 +891,7 @@ class DdbObj {
|
|
|
864
891
|
})();
|
|
865
892
|
if (!body)
|
|
866
893
|
return new Uint8Array(0);
|
|
867
|
-
return
|
|
894
|
+
return concat([
|
|
868
895
|
header,
|
|
869
896
|
...body
|
|
870
897
|
]);
|
|
@@ -1062,6 +1089,8 @@ class DdbObj {
|
|
|
1062
1089
|
}
|
|
1063
1090
|
}
|
|
1064
1091
|
}
|
|
1092
|
+
case DdbForm.chart:
|
|
1093
|
+
return JSON.stringify(this.value, (key, value) => key === 'data' ? value.toString() : value, 4);
|
|
1065
1094
|
}
|
|
1066
1095
|
return String(this.value);
|
|
1067
1096
|
})();
|
|
@@ -1116,7 +1145,7 @@ class DdbObj {
|
|
|
1116
1145
|
switch (type) {
|
|
1117
1146
|
case DdbType.bool: {
|
|
1118
1147
|
const value = values[i];
|
|
1119
|
-
row[name] = value ===
|
|
1148
|
+
row[name] = value === nulls.int8 ?
|
|
1120
1149
|
null
|
|
1121
1150
|
:
|
|
1122
1151
|
Boolean(value);
|
|
@@ -1157,24 +1186,15 @@ class DdbObj {
|
|
|
1157
1186
|
return obj;
|
|
1158
1187
|
}
|
|
1159
1188
|
}
|
|
1160
|
-
|
|
1161
|
-
DdbObj.dec = new TextDecoder('utf-8');
|
|
1162
|
-
DdbObj.enc = new TextEncoder();
|
|
1163
|
-
/** 维护已解析的 symbol base,比如流数据中后续的 symbol 向量可能只发送一个 base.id, base.size == 0, 依赖之前发送的 symbol base ?
|
|
1164
|
-
只是暂存,如果一张表有多个 symbol 列,可能这个 symbol base 会被复用,不同的对象之间 symbol base 一般不复用
|
|
1165
|
-
*/
|
|
1166
|
-
DdbObj.symbol_bases = {};
|
|
1167
|
-
/** little endian (client) */
|
|
1168
|
-
DdbObj.le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
|
|
1169
|
-
function format(type, value, le) {
|
|
1189
|
+
export function format(type, value, le) {
|
|
1170
1190
|
switch (type) {
|
|
1171
1191
|
case DdbType.bool:
|
|
1172
|
-
return String((value === null || value ===
|
|
1192
|
+
return String((value === null || value === nulls.int8) ?
|
|
1173
1193
|
null
|
|
1174
1194
|
:
|
|
1175
1195
|
Boolean(value));
|
|
1176
1196
|
case DdbType.char:
|
|
1177
|
-
return String((value === null || value ===
|
|
1197
|
+
return String((value === null || value === nulls.int8) ?
|
|
1178
1198
|
null
|
|
1179
1199
|
:
|
|
1180
1200
|
// ascii printable
|
|
@@ -1184,72 +1204,72 @@ function format(type, value, le) {
|
|
|
1184
1204
|
:
|
|
1185
1205
|
value);
|
|
1186
1206
|
case DdbType.short:
|
|
1187
|
-
return String((value === null || value ===
|
|
1207
|
+
return String((value === null || value === nulls.int16) ?
|
|
1188
1208
|
null
|
|
1189
1209
|
:
|
|
1190
1210
|
value);
|
|
1191
1211
|
case DdbType.int:
|
|
1192
|
-
return String((value === null || value ===
|
|
1212
|
+
return String((value === null || value === nulls.int32) ?
|
|
1193
1213
|
null
|
|
1194
1214
|
:
|
|
1195
1215
|
value);
|
|
1196
1216
|
case DdbType.long:
|
|
1197
|
-
return (value === null || value ===
|
|
1217
|
+
return (value === null || value === nulls.int64) ?
|
|
1198
1218
|
'null'
|
|
1199
1219
|
:
|
|
1200
1220
|
String(value);
|
|
1201
1221
|
case DdbType.date:
|
|
1202
|
-
return (value === null || value ===
|
|
1222
|
+
return (value === null || value === nulls.int32) ?
|
|
1203
1223
|
'null'
|
|
1204
1224
|
:
|
|
1205
1225
|
date2str(value);
|
|
1206
1226
|
case DdbType.month:
|
|
1207
|
-
return (value === null || value ===
|
|
1227
|
+
return (value === null || value === nulls.int32) ?
|
|
1208
1228
|
'null'
|
|
1209
1229
|
:
|
|
1210
1230
|
month2str(value);
|
|
1211
1231
|
case DdbType.time:
|
|
1212
|
-
return (value === null || value ===
|
|
1232
|
+
return (value === null || value === nulls.int32) ?
|
|
1213
1233
|
'null'
|
|
1214
1234
|
:
|
|
1215
1235
|
time2str(value);
|
|
1216
1236
|
case DdbType.minute:
|
|
1217
|
-
return (value === null || value ===
|
|
1237
|
+
return (value === null || value === nulls.int32) ?
|
|
1218
1238
|
'null'
|
|
1219
1239
|
:
|
|
1220
1240
|
minute2str(value);
|
|
1221
1241
|
case DdbType.second:
|
|
1222
|
-
return (value === null || value ===
|
|
1242
|
+
return (value === null || value === nulls.int32) ?
|
|
1223
1243
|
'null'
|
|
1224
1244
|
:
|
|
1225
1245
|
second2str(value);
|
|
1226
1246
|
case DdbType.datetime:
|
|
1227
|
-
return (value === null || value ===
|
|
1247
|
+
return (value === null || value === nulls.int32) ?
|
|
1228
1248
|
'null'
|
|
1229
1249
|
:
|
|
1230
1250
|
datetime2str(value);
|
|
1231
1251
|
case DdbType.timestamp:
|
|
1232
|
-
return (value === null || value ===
|
|
1252
|
+
return (value === null || value === nulls.int64) ?
|
|
1233
1253
|
'null'
|
|
1234
1254
|
:
|
|
1235
1255
|
timestamp2str(value);
|
|
1236
1256
|
case DdbType.nanotime:
|
|
1237
|
-
return (value === null || value ===
|
|
1257
|
+
return (value === null || value === nulls.int64) ?
|
|
1238
1258
|
'null'
|
|
1239
1259
|
:
|
|
1240
1260
|
nanotime2str(value);
|
|
1241
1261
|
case DdbType.nanotimestamp:
|
|
1242
|
-
return (value === null || value ===
|
|
1262
|
+
return (value === null || value === nulls.int64) ?
|
|
1243
1263
|
'null'
|
|
1244
1264
|
:
|
|
1245
1265
|
nanotimestamp2str(value);
|
|
1246
1266
|
case DdbType.float:
|
|
1247
|
-
return (value === null || value ===
|
|
1267
|
+
return (value === null || value === nulls.float32) ?
|
|
1248
1268
|
'null'
|
|
1249
1269
|
:
|
|
1250
1270
|
String(value);
|
|
1251
1271
|
case DdbType.double:
|
|
1252
|
-
return (value === null || value ===
|
|
1272
|
+
return (value === null || value === nulls.double) ?
|
|
1253
1273
|
'null'
|
|
1254
1274
|
:
|
|
1255
1275
|
String(value);
|
|
@@ -1264,7 +1284,7 @@ function format(type, value, le) {
|
|
|
1264
1284
|
case DdbType.code:
|
|
1265
1285
|
return value.quote('single');
|
|
1266
1286
|
case DdbType.datehour:
|
|
1267
|
-
return (value === null || value ===
|
|
1287
|
+
return (value === null || value === nulls.int32) ?
|
|
1268
1288
|
'null'
|
|
1269
1289
|
:
|
|
1270
1290
|
datehour2str(value);
|
|
@@ -1279,17 +1299,17 @@ function format(type, value, le) {
|
|
|
1279
1299
|
DdbObj.dec.decode(value)).quote('single');
|
|
1280
1300
|
case DdbType.point: {
|
|
1281
1301
|
let [x, y] = value;
|
|
1282
|
-
if (x ===
|
|
1302
|
+
if (x === nulls.double)
|
|
1283
1303
|
x = null;
|
|
1284
|
-
if (y ===
|
|
1304
|
+
if (y === nulls.double)
|
|
1285
1305
|
y = null;
|
|
1286
1306
|
return `(${String(x)}, ${String(y)})`;
|
|
1287
1307
|
}
|
|
1288
1308
|
case DdbType.complex: {
|
|
1289
1309
|
let [x, y] = value;
|
|
1290
|
-
if (x ===
|
|
1310
|
+
if (x === nulls.double)
|
|
1291
1311
|
x = null;
|
|
1292
|
-
if (y ===
|
|
1312
|
+
if (y === nulls.double)
|
|
1293
1313
|
y = null;
|
|
1294
1314
|
return `${String(x)}+${String(y)}i`;
|
|
1295
1315
|
}
|
|
@@ -1301,8 +1321,7 @@ function format(type, value, le) {
|
|
|
1301
1321
|
return String(value);
|
|
1302
1322
|
}
|
|
1303
1323
|
}
|
|
1304
|
-
|
|
1305
|
-
class DdbVoid extends DdbObj {
|
|
1324
|
+
export class DdbVoid extends DdbObj {
|
|
1306
1325
|
constructor() {
|
|
1307
1326
|
super({
|
|
1308
1327
|
form: DdbForm.scalar,
|
|
@@ -1311,8 +1330,7 @@ class DdbVoid extends DdbObj {
|
|
|
1311
1330
|
});
|
|
1312
1331
|
}
|
|
1313
1332
|
}
|
|
1314
|
-
|
|
1315
|
-
class DdbBool extends DdbObj {
|
|
1333
|
+
export class DdbBool extends DdbObj {
|
|
1316
1334
|
constructor(value) {
|
|
1317
1335
|
super({
|
|
1318
1336
|
form: DdbForm.scalar,
|
|
@@ -1321,8 +1339,7 @@ class DdbBool extends DdbObj {
|
|
|
1321
1339
|
});
|
|
1322
1340
|
}
|
|
1323
1341
|
}
|
|
1324
|
-
|
|
1325
|
-
class DdbChar extends DdbObj {
|
|
1342
|
+
export class DdbChar extends DdbObj {
|
|
1326
1343
|
constructor(value) {
|
|
1327
1344
|
super({
|
|
1328
1345
|
form: DdbForm.scalar,
|
|
@@ -1334,8 +1351,7 @@ class DdbChar extends DdbObj {
|
|
|
1334
1351
|
});
|
|
1335
1352
|
}
|
|
1336
1353
|
}
|
|
1337
|
-
|
|
1338
|
-
class DdbInt extends DdbObj {
|
|
1354
|
+
export class DdbInt extends DdbObj {
|
|
1339
1355
|
constructor(value) {
|
|
1340
1356
|
super({
|
|
1341
1357
|
form: DdbForm.scalar,
|
|
@@ -1344,8 +1360,7 @@ class DdbInt extends DdbObj {
|
|
|
1344
1360
|
});
|
|
1345
1361
|
}
|
|
1346
1362
|
}
|
|
1347
|
-
|
|
1348
|
-
class DdbString extends DdbObj {
|
|
1363
|
+
export class DdbString extends DdbObj {
|
|
1349
1364
|
constructor(value) {
|
|
1350
1365
|
super({
|
|
1351
1366
|
form: DdbForm.scalar,
|
|
@@ -1354,8 +1369,7 @@ class DdbString extends DdbObj {
|
|
|
1354
1369
|
});
|
|
1355
1370
|
}
|
|
1356
1371
|
}
|
|
1357
|
-
|
|
1358
|
-
class DdbLong extends DdbObj {
|
|
1372
|
+
export class DdbLong extends DdbObj {
|
|
1359
1373
|
constructor(value) {
|
|
1360
1374
|
super({
|
|
1361
1375
|
form: DdbForm.scalar,
|
|
@@ -1364,8 +1378,7 @@ class DdbLong extends DdbObj {
|
|
|
1364
1378
|
});
|
|
1365
1379
|
}
|
|
1366
1380
|
}
|
|
1367
|
-
|
|
1368
|
-
class DdbDouble extends DdbObj {
|
|
1381
|
+
export class DdbDouble extends DdbObj {
|
|
1369
1382
|
constructor(value) {
|
|
1370
1383
|
super({
|
|
1371
1384
|
form: DdbForm.scalar,
|
|
@@ -1374,8 +1387,7 @@ class DdbDouble extends DdbObj {
|
|
|
1374
1387
|
});
|
|
1375
1388
|
}
|
|
1376
1389
|
}
|
|
1377
|
-
|
|
1378
|
-
class DdbDateTime extends DdbObj {
|
|
1390
|
+
export class DdbDateTime extends DdbObj {
|
|
1379
1391
|
constructor(value) {
|
|
1380
1392
|
super({
|
|
1381
1393
|
form: DdbForm.scalar,
|
|
@@ -1384,8 +1396,7 @@ class DdbDateTime extends DdbObj {
|
|
|
1384
1396
|
});
|
|
1385
1397
|
}
|
|
1386
1398
|
}
|
|
1387
|
-
|
|
1388
|
-
class DdbTimeStamp extends DdbObj {
|
|
1399
|
+
export class DdbTimeStamp extends DdbObj {
|
|
1389
1400
|
constructor(value) {
|
|
1390
1401
|
super({
|
|
1391
1402
|
form: DdbForm.scalar,
|
|
@@ -1394,8 +1405,7 @@ class DdbTimeStamp extends DdbObj {
|
|
|
1394
1405
|
});
|
|
1395
1406
|
}
|
|
1396
1407
|
}
|
|
1397
|
-
|
|
1398
|
-
class DdbNanoTimeStamp extends DdbObj {
|
|
1408
|
+
export class DdbNanoTimeStamp extends DdbObj {
|
|
1399
1409
|
constructor(value) {
|
|
1400
1410
|
super({
|
|
1401
1411
|
form: DdbForm.scalar,
|
|
@@ -1404,20 +1414,18 @@ class DdbNanoTimeStamp extends DdbObj {
|
|
|
1404
1414
|
});
|
|
1405
1415
|
}
|
|
1406
1416
|
}
|
|
1407
|
-
|
|
1408
|
-
class DdbPair extends DdbObj {
|
|
1417
|
+
export class DdbPair extends DdbObj {
|
|
1409
1418
|
constructor(l, r = null) {
|
|
1410
1419
|
super({
|
|
1411
1420
|
form: DdbForm.pair,
|
|
1412
1421
|
type: DdbType.int,
|
|
1413
1422
|
rows: 2,
|
|
1414
1423
|
cols: 1,
|
|
1415
|
-
value: Int32Array.of(l === null ?
|
|
1424
|
+
value: Int32Array.of(l === null ? nulls.int32 : l, r === null ? nulls.int32 : r)
|
|
1416
1425
|
});
|
|
1417
1426
|
}
|
|
1418
1427
|
}
|
|
1419
|
-
|
|
1420
|
-
class DdbFunction extends DdbObj {
|
|
1428
|
+
export class DdbFunction extends DdbObj {
|
|
1421
1429
|
constructor(name, type) {
|
|
1422
1430
|
super({
|
|
1423
1431
|
form: DdbForm.scalar,
|
|
@@ -1426,8 +1434,7 @@ class DdbFunction extends DdbObj {
|
|
|
1426
1434
|
});
|
|
1427
1435
|
}
|
|
1428
1436
|
}
|
|
1429
|
-
|
|
1430
|
-
class DdbVectorInt extends DdbObj {
|
|
1437
|
+
export class DdbVectorInt extends DdbObj {
|
|
1431
1438
|
constructor(ints, name) {
|
|
1432
1439
|
super({
|
|
1433
1440
|
form: DdbForm.vector,
|
|
@@ -1438,15 +1445,14 @@ class DdbVectorInt extends DdbObj {
|
|
|
1438
1445
|
ints
|
|
1439
1446
|
:
|
|
1440
1447
|
Int32Array.from(ints, v => v === null ?
|
|
1441
|
-
|
|
1448
|
+
nulls.int32
|
|
1442
1449
|
:
|
|
1443
1450
|
v),
|
|
1444
1451
|
name,
|
|
1445
1452
|
});
|
|
1446
1453
|
}
|
|
1447
1454
|
}
|
|
1448
|
-
|
|
1449
|
-
class DdbVectorDouble extends DdbObj {
|
|
1455
|
+
export class DdbVectorDouble extends DdbObj {
|
|
1450
1456
|
constructor(doubles, name) {
|
|
1451
1457
|
super({
|
|
1452
1458
|
form: DdbForm.vector,
|
|
@@ -1457,15 +1463,14 @@ class DdbVectorDouble extends DdbObj {
|
|
|
1457
1463
|
doubles
|
|
1458
1464
|
:
|
|
1459
1465
|
Float64Array.from(doubles, v => v === null ?
|
|
1460
|
-
|
|
1466
|
+
nulls.double
|
|
1461
1467
|
:
|
|
1462
1468
|
v),
|
|
1463
1469
|
name,
|
|
1464
1470
|
});
|
|
1465
1471
|
}
|
|
1466
1472
|
}
|
|
1467
|
-
|
|
1468
|
-
class DdbVectorString extends DdbObj {
|
|
1473
|
+
export class DdbVectorString extends DdbObj {
|
|
1469
1474
|
constructor(strings, name) {
|
|
1470
1475
|
super({
|
|
1471
1476
|
form: DdbForm.vector,
|
|
@@ -1477,8 +1482,7 @@ class DdbVectorString extends DdbObj {
|
|
|
1477
1482
|
});
|
|
1478
1483
|
}
|
|
1479
1484
|
}
|
|
1480
|
-
|
|
1481
|
-
class DdbVectorAny extends DdbObj {
|
|
1485
|
+
export class DdbVectorAny extends DdbObj {
|
|
1482
1486
|
constructor(objs, name) {
|
|
1483
1487
|
super({
|
|
1484
1488
|
form: DdbForm.vector,
|
|
@@ -1490,8 +1494,7 @@ class DdbVectorAny extends DdbObj {
|
|
|
1490
1494
|
});
|
|
1491
1495
|
}
|
|
1492
1496
|
}
|
|
1493
|
-
|
|
1494
|
-
class DdbVectorSymbol extends DdbObj {
|
|
1497
|
+
export class DdbVectorSymbol extends DdbObj {
|
|
1495
1498
|
constructor(strings, name) {
|
|
1496
1499
|
let map = new Map([
|
|
1497
1500
|
['', 0]
|
|
@@ -1520,8 +1523,7 @@ class DdbVectorSymbol extends DdbObj {
|
|
|
1520
1523
|
});
|
|
1521
1524
|
}
|
|
1522
1525
|
}
|
|
1523
|
-
|
|
1524
|
-
class DdbSetInt extends DdbObj {
|
|
1526
|
+
export class DdbSetInt extends DdbObj {
|
|
1525
1527
|
constructor(ints) {
|
|
1526
1528
|
super({
|
|
1527
1529
|
form: DdbForm.set,
|
|
@@ -1535,14 +1537,13 @@ class DdbSetInt extends DdbObj {
|
|
|
1535
1537
|
ints
|
|
1536
1538
|
:
|
|
1537
1539
|
Int32Array.from(ints, v => v === null ?
|
|
1538
|
-
|
|
1540
|
+
nulls.int32
|
|
1539
1541
|
:
|
|
1540
1542
|
v),
|
|
1541
1543
|
});
|
|
1542
1544
|
}
|
|
1543
1545
|
}
|
|
1544
|
-
|
|
1545
|
-
class DdbSetDouble extends DdbObj {
|
|
1546
|
+
export class DdbSetDouble extends DdbObj {
|
|
1546
1547
|
constructor(doubles) {
|
|
1547
1548
|
super({
|
|
1548
1549
|
form: DdbForm.set,
|
|
@@ -1556,14 +1557,13 @@ class DdbSetDouble extends DdbObj {
|
|
|
1556
1557
|
doubles
|
|
1557
1558
|
:
|
|
1558
1559
|
Int32Array.from(doubles, v => v === null ?
|
|
1559
|
-
|
|
1560
|
+
nulls.int32
|
|
1560
1561
|
:
|
|
1561
1562
|
v),
|
|
1562
1563
|
});
|
|
1563
1564
|
}
|
|
1564
1565
|
}
|
|
1565
|
-
|
|
1566
|
-
class DdbSetString extends DdbObj {
|
|
1566
|
+
export class DdbSetString extends DdbObj {
|
|
1567
1567
|
constructor(strings) {
|
|
1568
1568
|
if (strings instanceof Set)
|
|
1569
1569
|
strings = [...strings];
|
|
@@ -1576,12 +1576,11 @@ class DdbSetString extends DdbObj {
|
|
|
1576
1576
|
});
|
|
1577
1577
|
}
|
|
1578
1578
|
}
|
|
1579
|
-
exports.DdbSetString = DdbSetString;
|
|
1580
1579
|
/** Constructs a DdbDict object, which supports two usages:
|
|
1581
1580
|
- 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
1581
|
- Pass in js object (type is Record<string, boolean | string | DdbObj>), automatically converted to DdbDict of dict<string, any>
|
|
1583
1582
|
*/
|
|
1584
|
-
class DdbDict extends DdbObj {
|
|
1583
|
+
export class DdbDict extends DdbObj {
|
|
1585
1584
|
constructor(arg0, arg1) {
|
|
1586
1585
|
if (arg1)
|
|
1587
1586
|
super({
|
|
@@ -1606,8 +1605,7 @@ class DdbDict extends DdbObj {
|
|
|
1606
1605
|
}
|
|
1607
1606
|
}
|
|
1608
1607
|
}
|
|
1609
|
-
|
|
1610
|
-
class DdbTable extends DdbObj {
|
|
1608
|
+
export class DdbTable extends DdbObj {
|
|
1611
1609
|
constructor(columns, name = '') {
|
|
1612
1610
|
super({
|
|
1613
1611
|
form: DdbForm.table,
|
|
@@ -1619,30 +1617,26 @@ class DdbTable extends DdbObj {
|
|
|
1619
1617
|
});
|
|
1620
1618
|
}
|
|
1621
1619
|
}
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
return (date === null || date === exports.nulls.int32) ?
|
|
1620
|
+
export function date2ms(date) {
|
|
1621
|
+
return (date === null || date === nulls.int32) ?
|
|
1625
1622
|
null
|
|
1626
1623
|
:
|
|
1627
|
-
|
|
1624
|
+
timezone_offset + 1000 * 3600 * 24 * date;
|
|
1628
1625
|
}
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
return (date === null || date === exports.nulls.int32) ?
|
|
1626
|
+
export function date2str(date, format = 'YYYY.MM.DD') {
|
|
1627
|
+
return (date === null || date === nulls.int32) ?
|
|
1632
1628
|
null
|
|
1633
1629
|
:
|
|
1634
|
-
(
|
|
1630
|
+
dayjs(date2ms(date)).format(format);
|
|
1635
1631
|
}
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
return (month === null || month === exports.nulls.int32) ?
|
|
1632
|
+
export function month2ms(month) {
|
|
1633
|
+
return (month === null || month === nulls.int32) ?
|
|
1639
1634
|
null
|
|
1640
1635
|
:
|
|
1641
|
-
(
|
|
1636
|
+
dayjs(month2str(month), 'YYYY.MM[M]').valueOf();
|
|
1642
1637
|
}
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
if (month === null || month === exports.nulls.int32)
|
|
1638
|
+
export function month2str(month) {
|
|
1639
|
+
if (month === null || month === nulls.int32)
|
|
1646
1640
|
return 'null';
|
|
1647
1641
|
if (month < 0)
|
|
1648
1642
|
return String(month);
|
|
@@ -1650,118 +1644,103 @@ function month2str(month) {
|
|
|
1650
1644
|
const year = Math.trunc(month / 12);
|
|
1651
1645
|
return `${String(year).padStart(4, '0')}.${String(_month + 1).padStart(2, '0')}M`;
|
|
1652
1646
|
}
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
return (time === null || time === exports.nulls.int32) ?
|
|
1647
|
+
export function time2ms(time) {
|
|
1648
|
+
return (time === null || time === nulls.int32) ?
|
|
1656
1649
|
null
|
|
1657
1650
|
:
|
|
1658
|
-
|
|
1651
|
+
timezone_offset + time;
|
|
1659
1652
|
}
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
return (time === null || time === exports.nulls.int32) ?
|
|
1653
|
+
export function time2str(time, format = 'HH:mm:ss.SSS') {
|
|
1654
|
+
return (time === null || time === nulls.int32) ?
|
|
1663
1655
|
null
|
|
1664
1656
|
:
|
|
1665
|
-
(
|
|
1657
|
+
dayjs(time2ms(time)).format(format);
|
|
1666
1658
|
}
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
return (minute === null || minute === exports.nulls.int32) ?
|
|
1659
|
+
export function minute2ms(minute) {
|
|
1660
|
+
return (minute === null || minute === nulls.int32) ?
|
|
1670
1661
|
null
|
|
1671
1662
|
:
|
|
1672
|
-
|
|
1663
|
+
timezone_offset + 60 * 1000 * minute;
|
|
1673
1664
|
}
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
return (minute === null || minute === exports.nulls.int32) ?
|
|
1665
|
+
export function minute2str(minute, format = 'HH:mm[m]') {
|
|
1666
|
+
return (minute === null || minute === nulls.int32) ?
|
|
1677
1667
|
'null'
|
|
1678
1668
|
:
|
|
1679
|
-
(
|
|
1669
|
+
dayjs(minute2ms(minute)).format(format);
|
|
1680
1670
|
}
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
return (second === null || second === exports.nulls.int32) ?
|
|
1671
|
+
export function second2ms(second) {
|
|
1672
|
+
return (second === null || second === nulls.int32) ?
|
|
1684
1673
|
null
|
|
1685
1674
|
:
|
|
1686
|
-
|
|
1675
|
+
timezone_offset + 1000 * second;
|
|
1687
1676
|
}
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
return (second === null || second === exports.nulls.int32) ?
|
|
1677
|
+
export function second2str(second, format = 'HH:mm:ss') {
|
|
1678
|
+
return (second === null || second === nulls.int32) ?
|
|
1691
1679
|
'null'
|
|
1692
1680
|
:
|
|
1693
|
-
(
|
|
1681
|
+
dayjs(second2ms(second)).format(format);
|
|
1694
1682
|
}
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
return (datetime === null || datetime === exports.nulls.int32) ?
|
|
1683
|
+
export function datetime2ms(datetime) {
|
|
1684
|
+
return (datetime === null || datetime === nulls.int32) ?
|
|
1698
1685
|
null
|
|
1699
1686
|
:
|
|
1700
|
-
|
|
1687
|
+
timezone_offset + 1000 * datetime;
|
|
1701
1688
|
}
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
return (datetime === null || datetime === exports.nulls.int32) ?
|
|
1689
|
+
export function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
|
|
1690
|
+
return (datetime === null || datetime === nulls.int32) ?
|
|
1705
1691
|
'null'
|
|
1706
1692
|
:
|
|
1707
|
-
(
|
|
1693
|
+
dayjs(datetime2ms(datetime)).format(format);
|
|
1708
1694
|
}
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
return (timestamp === null || timestamp === exports.nulls.int64) ?
|
|
1695
|
+
export function timestamp2ms(timestamp) {
|
|
1696
|
+
return (timestamp === null || timestamp === nulls.int64) ?
|
|
1712
1697
|
null
|
|
1713
1698
|
:
|
|
1714
|
-
|
|
1699
|
+
timezone_offset + Number(timestamp);
|
|
1715
1700
|
}
|
|
1716
|
-
exports.timestamp2ms = timestamp2ms;
|
|
1717
1701
|
/** format timestamp (bigint) to string
|
|
1718
1702
|
- timestamp: bigint value
|
|
1719
1703
|
- format?:
|
|
1720
1704
|
format string, default to `YYYY.MM.DD HH:mm:ss.SSS`
|
|
1721
1705
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1722
1706
|
*/
|
|
1723
|
-
function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
1724
|
-
return (timestamp === null || timestamp ===
|
|
1707
|
+
export function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
1708
|
+
return (timestamp === null || timestamp === nulls.int64) ?
|
|
1725
1709
|
'null'
|
|
1726
1710
|
:
|
|
1727
|
-
(
|
|
1711
|
+
dayjs(timestamp2ms(timestamp)).format(format);
|
|
1728
1712
|
}
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
return (datehour === null || datehour === exports.nulls.int32) ?
|
|
1713
|
+
export function datehour2ms(datehour) {
|
|
1714
|
+
return (datehour === null || datehour === nulls.int32) ?
|
|
1732
1715
|
null
|
|
1733
1716
|
:
|
|
1734
|
-
|
|
1717
|
+
timezone_offset + 1000 * 3600 * datehour;
|
|
1735
1718
|
}
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
return (datehour === null || datehour === exports.nulls.int32) ?
|
|
1719
|
+
export function datehour2str(datehour, format = 'YYYY.MM.DDTHH') {
|
|
1720
|
+
return (datehour === null || datehour === nulls.int32) ?
|
|
1739
1721
|
'null'
|
|
1740
1722
|
:
|
|
1741
|
-
(
|
|
1723
|
+
dayjs(timezone_offset + 1000 * 3600 * datehour).format(format);
|
|
1742
1724
|
}
|
|
1743
|
-
exports.datehour2str = datehour2str;
|
|
1744
1725
|
/** parse timestamp string to bigint value
|
|
1745
1726
|
- str: timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
|
|
1746
1727
|
- format?:
|
|
1747
1728
|
The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
|
|
1748
1729
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1749
1730
|
*/
|
|
1750
|
-
function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
1731
|
+
export function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
1751
1732
|
if (!str || str === 'null')
|
|
1752
|
-
return
|
|
1733
|
+
return nulls.int64;
|
|
1753
1734
|
if (str.length !== format.length)
|
|
1754
1735
|
throw new Error('The length of the timestamp string is not equal to the length of the format string');
|
|
1755
|
-
return BigInt(-
|
|
1756
|
-
(
|
|
1736
|
+
return BigInt(-timezone_offset +
|
|
1737
|
+
dayjs(str, format).valueOf());
|
|
1757
1738
|
}
|
|
1758
|
-
|
|
1759
|
-
function nanotime2ns(nanotime) {
|
|
1739
|
+
export function nanotime2ns(nanotime) {
|
|
1760
1740
|
return nanotimestamp2ns(nanotime);
|
|
1761
1741
|
}
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
if (nanotime === null || nanotime === exports.nulls.int64)
|
|
1742
|
+
export function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
|
|
1743
|
+
if (nanotime === null || nanotime === nulls.int64)
|
|
1765
1744
|
return 'null';
|
|
1766
1745
|
if (nanotime < 0n)
|
|
1767
1746
|
return String(nanotime);
|
|
@@ -1772,18 +1751,16 @@ function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
|
|
|
1772
1751
|
const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
|
|
1773
1752
|
if (i_nanosecond_start === -1)
|
|
1774
1753
|
throw new Error('格式串必须包含纳秒的格式 (SSSSSSSSS)');
|
|
1775
|
-
return ((
|
|
1754
|
+
return (dayjs(timezone_offset + (Number(nanotime) / 1000000)).format(format.slice(0, i_second_end)) +
|
|
1776
1755
|
format.slice(i_second_end, i_nanosecond_start) +
|
|
1777
1756
|
String(nanotime % 1000000000n).padStart(9, '0'));
|
|
1778
1757
|
}
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
return (nanotimestamp === null || nanotimestamp === exports.nulls.int64) ?
|
|
1758
|
+
export function nanotimestamp2ns(nanotimestamp) {
|
|
1759
|
+
return (nanotimestamp === null || nanotimestamp === nulls.int64) ?
|
|
1782
1760
|
null
|
|
1783
1761
|
:
|
|
1784
|
-
BigInt(
|
|
1762
|
+
BigInt(timezone_offset) * 1000000n + nanotimestamp;
|
|
1785
1763
|
}
|
|
1786
|
-
exports.nanotimestamp2ns = nanotimestamp2ns;
|
|
1787
1764
|
/** format nanotimestamp value (bigint) to string
|
|
1788
1765
|
- nanotimestamp: bigint value
|
|
1789
1766
|
- format?:
|
|
@@ -1791,14 +1768,14 @@ exports.nanotimestamp2ns = nanotimestamp2ns;
|
|
|
1791
1768
|
Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
|
|
1792
1769
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1793
1770
|
*/
|
|
1794
|
-
function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
1771
|
+
export function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
1795
1772
|
// tests:
|
|
1796
1773
|
// nanotimestamp2str(0n)
|
|
1797
1774
|
// nanotimestamp2str(-1n)
|
|
1798
1775
|
// nanotimestamp2str(-9_9999_9999n)
|
|
1799
1776
|
// nanotimestamp2str(-10_0000_0000n)
|
|
1800
1777
|
// nanotimestamp2str(-10_0000_0001n)
|
|
1801
|
-
if (nanotimestamp === null || nanotimestamp ===
|
|
1778
|
+
if (nanotimestamp === null || nanotimestamp === nulls.int64)
|
|
1802
1779
|
return 'null';
|
|
1803
1780
|
const i_second_start = format.indexOf('ss');
|
|
1804
1781
|
if (i_second_start === -1)
|
|
@@ -1809,7 +1786,7 @@ function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSS
|
|
|
1809
1786
|
throw new Error('The format string must contain the format for nanoseconds (SSSSSSSSS)');
|
|
1810
1787
|
const remainder = nanotimestamp % 1000000000n;
|
|
1811
1788
|
const borrow = remainder < 0n;
|
|
1812
|
-
return ((
|
|
1789
|
+
return (dayjs(timezone_offset +
|
|
1813
1790
|
// 去掉 9 位的纳秒部分,转化为毫秒
|
|
1814
1791
|
Number((nanotimestamp - remainder + (borrow ? -1000000000n : 0n)) / 1000000n)).format(format.slice(0, i_second_end)) +
|
|
1815
1792
|
format.slice(i_second_end, i_nanosecond_start) +
|
|
@@ -1818,7 +1795,6 @@ function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSS
|
|
|
1818
1795
|
:
|
|
1819
1796
|
remainder).padStart(9, '0'));
|
|
1820
1797
|
}
|
|
1821
|
-
exports.nanotimestamp2str = nanotimestamp2str;
|
|
1822
1798
|
/** parse nano timestamp string to bigint value
|
|
1823
1799
|
- str: nano timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
|
|
1824
1800
|
- format?:
|
|
@@ -1826,9 +1802,9 @@ exports.nanotimestamp2str = nanotimestamp2str;
|
|
|
1826
1802
|
Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
|
|
1827
1803
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1828
1804
|
*/
|
|
1829
|
-
function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
1805
|
+
export function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
1830
1806
|
if (!str || str === 'null')
|
|
1831
|
-
return
|
|
1807
|
+
return nulls.int64;
|
|
1832
1808
|
if (str.length !== format.length)
|
|
1833
1809
|
throw new Error('nanotimestamp string length is not equal to format string length');
|
|
1834
1810
|
const i_second_start = format.indexOf('ss');
|
|
@@ -1838,13 +1814,12 @@ function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
|
1838
1814
|
const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
|
|
1839
1815
|
if (i_nanosecond_start === -1)
|
|
1840
1816
|
throw new Error('Format string must contain nanosecond format (SSSSSSSSS)');
|
|
1841
|
-
return (BigInt(-
|
|
1842
|
-
(
|
|
1817
|
+
return (BigInt(-timezone_offset +
|
|
1818
|
+
dayjs(str.slice(0, i_second_end), format.slice(0, i_second_end)).valueOf()) * 1000000n
|
|
1843
1819
|
+
|
|
1844
1820
|
BigInt(str.slice(i_nanosecond_start, i_nanosecond_start + 9)));
|
|
1845
1821
|
}
|
|
1846
|
-
|
|
1847
|
-
function ipaddr2str(buffer, le = true, ipv6) {
|
|
1822
|
+
export function ipaddr2str(buffer, le = true, ipv6) {
|
|
1848
1823
|
let buf = buffer;
|
|
1849
1824
|
if (le)
|
|
1850
1825
|
buf = buffer.slice().reverse();
|
|
@@ -1855,21 +1830,51 @@ function ipaddr2str(buffer, le = true, ipv6) {
|
|
|
1855
1830
|
else // ipv4
|
|
1856
1831
|
return buf.subarray(12).join('.');
|
|
1857
1832
|
}
|
|
1858
|
-
|
|
1859
|
-
function uuid2str(buffer, le = true) {
|
|
1833
|
+
export function uuid2str(buffer, le = true) {
|
|
1860
1834
|
const str = int1282str(buffer, le);
|
|
1861
1835
|
return `${str.slice(0, 8)}-${str.slice(8, 12)}-${str.slice(12, 16)}-${str.slice(16, 20)}-${str.slice(20)}`;
|
|
1862
1836
|
}
|
|
1863
|
-
|
|
1864
|
-
function int1282str(buffer, le = true) {
|
|
1837
|
+
export function int1282str(buffer, le = true) {
|
|
1865
1838
|
let buf = buffer;
|
|
1866
1839
|
if (le)
|
|
1867
1840
|
buf = buffer.slice().reverse();
|
|
1868
1841
|
return [...buf].map(x => x.toString(16)
|
|
1869
1842
|
.padStart(2, '0')).join('');
|
|
1870
1843
|
}
|
|
1871
|
-
|
|
1872
|
-
|
|
1844
|
+
export class DDB {
|
|
1845
|
+
/** 当前的 session id (http 或 tcp) */
|
|
1846
|
+
sid = '0';
|
|
1847
|
+
/** utf-8 text decoder */
|
|
1848
|
+
dec = new TextDecoder('utf-8');
|
|
1849
|
+
enc = new TextEncoder();
|
|
1850
|
+
/** DolphinDB WebSocket URL
|
|
1851
|
+
e.g. `ws://127.0.0.1:8848/`, `wss://dolphindb.com`
|
|
1852
|
+
*/
|
|
1853
|
+
url;
|
|
1854
|
+
websocket = null;
|
|
1855
|
+
/** little endian (server) */
|
|
1856
|
+
le = true;
|
|
1857
|
+
/** little endian (client) */
|
|
1858
|
+
static le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
|
|
1859
|
+
/** Whether to automatically log in after the connection is established, the default is true */
|
|
1860
|
+
autologin = true;
|
|
1861
|
+
/** DolphinDB username */
|
|
1862
|
+
username = 'admin';
|
|
1863
|
+
/** DolphinDB password */
|
|
1864
|
+
password = '123456';
|
|
1865
|
+
/** python session flag (2048) */
|
|
1866
|
+
python = false;
|
|
1867
|
+
print_message_buffer = false;
|
|
1868
|
+
print_object_buffer = false;
|
|
1869
|
+
print_message = true;
|
|
1870
|
+
parse_object = true;
|
|
1871
|
+
/** DdbMessage listeners */
|
|
1872
|
+
listeners = [];
|
|
1873
|
+
pconnect = Promise.resolve();
|
|
1874
|
+
presult = Promise.resolve(null);
|
|
1875
|
+
get connected() {
|
|
1876
|
+
return this.websocket?.readyState === WebSocket.OPEN;
|
|
1877
|
+
}
|
|
1873
1878
|
/**
|
|
1874
1879
|
Initialize an instance of DolphinDB Client using the WebSocket URL
|
|
1875
1880
|
(without establishing an actual network connection)
|
|
@@ -1892,29 +1897,6 @@ class DDB {
|
|
|
1892
1897
|
})
|
|
1893
1898
|
*/
|
|
1894
1899
|
constructor(url, options = {}) {
|
|
1895
|
-
/** 当前的 session id (http 或 tcp) */
|
|
1896
|
-
this.sid = '0';
|
|
1897
|
-
/** utf-8 text decoder */
|
|
1898
|
-
this.dec = new TextDecoder('utf-8');
|
|
1899
|
-
this.enc = new TextEncoder();
|
|
1900
|
-
this.websocket = null;
|
|
1901
|
-
/** little endian (server) */
|
|
1902
|
-
this.le = true;
|
|
1903
|
-
/** Whether to automatically log in after the connection is established, the default is true */
|
|
1904
|
-
this.autologin = true;
|
|
1905
|
-
/** DolphinDB username */
|
|
1906
|
-
this.username = 'admin';
|
|
1907
|
-
/** DolphinDB password */
|
|
1908
|
-
this.password = '123456';
|
|
1909
|
-
/** python session flag (2048) */
|
|
1910
|
-
this.python = false;
|
|
1911
|
-
this.print_message_buffer = false;
|
|
1912
|
-
this.print_object_buffer = false;
|
|
1913
|
-
this.print_message = true;
|
|
1914
|
-
this.parse_object = true;
|
|
1915
|
-
/** DdbMessage listeners */
|
|
1916
|
-
this.listeners = [];
|
|
1917
|
-
this.promise = Promise.resolve(null);
|
|
1918
1900
|
if (!url) {
|
|
1919
1901
|
const _url = new URL(location.href);
|
|
1920
1902
|
const hostname = _url.searchParams.get('hostname') || location.hostname;
|
|
@@ -1931,9 +1913,6 @@ class DDB {
|
|
|
1931
1913
|
if (options.python !== undefined)
|
|
1932
1914
|
this.python = options.python;
|
|
1933
1915
|
}
|
|
1934
|
-
get connected() {
|
|
1935
|
-
return this.websocket?.readyState === WebSocket.OPEN;
|
|
1936
|
-
}
|
|
1937
1916
|
on_message(event) { }
|
|
1938
1917
|
/** Establish the actual WebSocket connection to the DolphinDB corresponding to the URL
|
|
1939
1918
|
- options?:
|
|
@@ -1955,7 +1934,7 @@ class DDB {
|
|
|
1955
1934
|
if (options.python !== undefined)
|
|
1956
1935
|
this.python = options.python;
|
|
1957
1936
|
this.disconnect();
|
|
1958
|
-
await
|
|
1937
|
+
await connect_websocket(this.url, {
|
|
1959
1938
|
protocols: this.python ? ['python'] : [],
|
|
1960
1939
|
on_open: async (event, websocket) => {
|
|
1961
1940
|
this.websocket = websocket;
|
|
@@ -2041,7 +2020,8 @@ class DDB {
|
|
|
2041
2020
|
if (this.connected)
|
|
2042
2021
|
this.websocket.close(1000);
|
|
2043
2022
|
this.on_message = () => { };
|
|
2044
|
-
this.
|
|
2023
|
+
this.presult = Promise.resolve(null);
|
|
2024
|
+
this.pconnect = Promise.resolve();
|
|
2045
2025
|
}
|
|
2046
2026
|
/** rpc through websocket (function/script/variable command)
|
|
2047
2027
|
- type: API 类型: 'script' | 'function' | 'variable'
|
|
@@ -2053,8 +2033,21 @@ class DDB {
|
|
|
2053
2033
|
为 false 时返回的 DdbObj 仅含有 buffer 和 le,不做解析,以便后续转发、序列化
|
|
2054
2034
|
*/
|
|
2055
2035
|
async rpc(type, { script, func, args = [], vars = [], urgent, listener, parse_object, }) {
|
|
2056
|
-
if (!this.websocket)
|
|
2057
|
-
|
|
2036
|
+
if (!this.websocket) {
|
|
2037
|
+
const ptail = this.pconnect;
|
|
2038
|
+
let resolve;
|
|
2039
|
+
this.pconnect = new Promise((_resolve, _reject) => {
|
|
2040
|
+
resolve = _resolve;
|
|
2041
|
+
});
|
|
2042
|
+
await ptail;
|
|
2043
|
+
try {
|
|
2044
|
+
if (!this.websocket)
|
|
2045
|
+
await this.connect();
|
|
2046
|
+
}
|
|
2047
|
+
finally {
|
|
2048
|
+
resolve();
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2058
2051
|
if (!this.connected)
|
|
2059
2052
|
throw new Error(`${this.url} is already disconnected`);
|
|
2060
2053
|
// this 上的当前配置需要在 message 到达后使用,先保存起来
|
|
@@ -2064,10 +2057,10 @@ class DDB {
|
|
|
2064
2057
|
// 违反世界观可能造成:
|
|
2065
2058
|
// 1. 并发多个请求只返回第一个结果(阻塞,需后续请求疏通)
|
|
2066
2059
|
// 2. windows 下 ddb server 返回多个相同的结果
|
|
2067
|
-
const ptail = this.
|
|
2060
|
+
const ptail = this.presult;
|
|
2068
2061
|
let resolve;
|
|
2069
2062
|
let reject;
|
|
2070
|
-
const
|
|
2063
|
+
const presult = this.presult = new Promise((_resolve, _reject) => {
|
|
2071
2064
|
resolve = _resolve;
|
|
2072
2065
|
reject = _reject;
|
|
2073
2066
|
});
|
|
@@ -2123,12 +2116,12 @@ class DDB {
|
|
|
2123
2116
|
return 'connect\n';
|
|
2124
2117
|
}
|
|
2125
2118
|
})());
|
|
2126
|
-
this.websocket.send(
|
|
2119
|
+
this.websocket.send(concat([
|
|
2127
2120
|
this.enc.encode(`API2 ${this.sid} ${command.length} / ${this.get_rpc_options({ urgent })}\n`),
|
|
2128
2121
|
command,
|
|
2129
2122
|
...args.map((arg) => arg.pack())
|
|
2130
2123
|
]));
|
|
2131
|
-
return
|
|
2124
|
+
return presult;
|
|
2132
2125
|
}
|
|
2133
2126
|
/** eval script through websocket (script command)
|
|
2134
2127
|
- script?: Script to execute
|
|
@@ -2253,8 +2246,5 @@ class DDB {
|
|
|
2253
2246
|
};
|
|
2254
2247
|
}
|
|
2255
2248
|
}
|
|
2256
|
-
|
|
2257
|
-
/** little endian (client) */
|
|
2258
|
-
DDB.le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
|
|
2259
|
-
exports.ddb = window.ddb = new DDB();
|
|
2249
|
+
export let ddb = window.ddb = new DDB();
|
|
2260
2250
|
//# sourceMappingURL=browser.js.map
|