dolphindb 2.0.513 → 2.0.516
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 +7 -4
- package/browser.js +83 -25
- package/browser.js.map +1 -1
- package/index.d.ts +10 -7
- package/index.js +89 -28
- package/index.js.map +1 -1
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -12,6 +12,10 @@ export declare enum DdbForm {
|
|
|
12
12
|
chart = 7,
|
|
13
13
|
chunk = 8
|
|
14
14
|
}
|
|
15
|
+
/** DolphinDB DataType
|
|
16
|
+
对应的 array vector 类型为 64 + 基本类型
|
|
17
|
+
对应的 extended 类型为 128 + 基本类型
|
|
18
|
+
*/
|
|
15
19
|
export declare enum DdbType {
|
|
16
20
|
void = 0,
|
|
17
21
|
bool = 1,
|
|
@@ -93,7 +97,7 @@ export interface DdbArrayVectorBlock {
|
|
|
93
97
|
unit: 1 | 2 | 4;
|
|
94
98
|
rows: number;
|
|
95
99
|
lengths: Uint8Array | Uint16Array | Uint32Array;
|
|
96
|
-
data:
|
|
100
|
+
data: Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array;
|
|
97
101
|
}
|
|
98
102
|
export interface DdbMatrixValue {
|
|
99
103
|
rows: DdbObj<DdbVectorValue>;
|
|
@@ -258,7 +262,7 @@ export declare function datetime2str(datetime: number, format?: string): string;
|
|
|
258
262
|
export declare function timestamp2str(timestamp: bigint, format?: string): string;
|
|
259
263
|
export declare function datehour2str(datehour: number, format?: string): string;
|
|
260
264
|
/** parse timestamp string to bigint value
|
|
261
|
-
- str: timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
|
|
265
|
+
- str: timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
|
|
262
266
|
- format?:
|
|
263
267
|
The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
|
|
264
268
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
@@ -274,7 +278,7 @@ export declare function nanotime2str(nanotime: bigint, format?: string): string;
|
|
|
274
278
|
*/
|
|
275
279
|
export declare function nanotimestamp2str(nanotimestamp: bigint, format?: string): string;
|
|
276
280
|
/** parse nano timestamp string to bigint value
|
|
277
|
-
- str: nano timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
|
|
281
|
+
- str: nano timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
|
|
278
282
|
- format?:
|
|
279
283
|
The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
|
|
280
284
|
Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
|
|
@@ -387,9 +391,9 @@ export declare class DDB {
|
|
|
387
391
|
- options:
|
|
388
392
|
- urgent?: 决定 `行为标识` 那一行字符串的取值(只适用于 script 和 function)
|
|
389
393
|
- vars?: type === 'variable' 时必传,variable 指令中待上传的变量名
|
|
390
|
-
-
|
|
391
|
-
- parse_object?:
|
|
392
|
-
|
|
394
|
+
- listener?: 处理本次 rpc 期间的消息 (DdbMessage)
|
|
395
|
+
- parse_object?: 在本次 rpc 期间设置 parse_object, 结束后恢复原有
|
|
396
|
+
为 false 时返回的 DdbObj 仅含有 buffer 和 le,不做解析,以便后续转发、序列化
|
|
393
397
|
*/
|
|
394
398
|
rpc<T extends DdbObj = DdbObj>(type: 'script' | 'function' | 'variable' | 'connect', { script, func, args, vars, urgent, listener, parse_object, }: {
|
|
395
399
|
script?: string;
|
|
@@ -469,4 +473,3 @@ export interface DdbErrorMessage {
|
|
|
469
473
|
data: Error;
|
|
470
474
|
}
|
|
471
475
|
export declare type DdbMessage = DdbPrintMessage | DdbObjectMessage | DdbErrorMessage;
|
|
472
|
-
export default DDB;
|
package/index.js
CHANGED
|
@@ -20,6 +20,10 @@ var DdbForm;
|
|
|
20
20
|
DdbForm[DdbForm["chart"] = 7] = "chart";
|
|
21
21
|
DdbForm[DdbForm["chunk"] = 8] = "chunk";
|
|
22
22
|
})(DdbForm = exports.DdbForm || (exports.DdbForm = {}));
|
|
23
|
+
/** DolphinDB DataType
|
|
24
|
+
对应的 array vector 类型为 64 + 基本类型
|
|
25
|
+
对应的 extended 类型为 128 + 基本类型
|
|
26
|
+
*/
|
|
23
27
|
var DdbType;
|
|
24
28
|
(function (DdbType) {
|
|
25
29
|
DdbType[DdbType["void"] = 0] = "void";
|
|
@@ -471,7 +475,7 @@ class DdbObj {
|
|
|
471
475
|
unit,
|
|
472
476
|
rows,
|
|
473
477
|
lengths,
|
|
474
|
-
data
|
|
478
|
+
data: data
|
|
475
479
|
});
|
|
476
480
|
i_block_start = i_data_start + len_items;
|
|
477
481
|
i_row += rows;
|
|
@@ -909,7 +913,7 @@ class DdbObj {
|
|
|
909
913
|
case DdbForm.dict:
|
|
910
914
|
return `dict<${DdbType[this.value[0].type]}, ${DdbType[this.value[1].type]}>`;
|
|
911
915
|
case DdbForm.matrix:
|
|
912
|
-
return `matrix<${
|
|
916
|
+
return `matrix<${tname}>[${this.rows}r][${this.cols}c]`;
|
|
913
917
|
default:
|
|
914
918
|
return `${DdbForm[this.form]} ${tname}`;
|
|
915
919
|
}
|
|
@@ -929,6 +933,34 @@ class DdbObj {
|
|
|
929
933
|
:
|
|
930
934
|
str_items.bracket('square');
|
|
931
935
|
}
|
|
936
|
+
if (64 <= this.type && this.type < 128) { // array vector
|
|
937
|
+
// 因为 array vector 目前只支持:Logical, Integral(不包括 INT128, COMPRESS 类型), Floating, Temporal
|
|
938
|
+
// 都对应 TypedArray 中的一格,所以直接根据 index 去取即可
|
|
939
|
+
// av = array(INT[], 0, 5)
|
|
940
|
+
// append!(av, [1..1])
|
|
941
|
+
// append!(av, [1..70000])
|
|
942
|
+
// append!(av, [1..1])
|
|
943
|
+
// append!(av, [1..500])
|
|
944
|
+
// ...
|
|
945
|
+
// av
|
|
946
|
+
const _type = this.type - 64;
|
|
947
|
+
const limit = 10;
|
|
948
|
+
let items = new Array(Math.min(limit, this.rows));
|
|
949
|
+
let i_items = 0;
|
|
950
|
+
for (const { lengths, data } of this.value) {
|
|
951
|
+
let acc_len = 0;
|
|
952
|
+
for (const length of lengths) {
|
|
953
|
+
let _items = new Array(Math.min(limit, length));
|
|
954
|
+
for (let i = 0; i < _items.length; i++)
|
|
955
|
+
_items[i] = format(_type, data[acc_len + i], this.le, options);
|
|
956
|
+
items[i_items++] = format_array(_items, length > limit);
|
|
957
|
+
acc_len += length;
|
|
958
|
+
}
|
|
959
|
+
if (i_items >= limit)
|
|
960
|
+
break;
|
|
961
|
+
}
|
|
962
|
+
return format_array(items, this.rows > limit);
|
|
963
|
+
}
|
|
932
964
|
switch (this.type) {
|
|
933
965
|
case DdbType.symbol_extended: {
|
|
934
966
|
const limit = 50;
|
|
@@ -1171,8 +1203,10 @@ function format(type, value, le, options) {
|
|
|
1171
1203
|
:
|
|
1172
1204
|
int1282str(value, le);
|
|
1173
1205
|
case DdbType.blob:
|
|
1174
|
-
return (0, utils_js_1.inspect)(
|
|
1175
|
-
|
|
1206
|
+
return (0, utils_js_1.inspect)(value.length > 100 ?
|
|
1207
|
+
DdbObj.dec.decode(value.subarray(0, 98)) + '…'
|
|
1208
|
+
:
|
|
1209
|
+
DdbObj.dec.decode(value), options);
|
|
1176
1210
|
case DdbType.point: {
|
|
1177
1211
|
let [x, y] = value;
|
|
1178
1212
|
if (x === exports.nulls.double)
|
|
@@ -1184,6 +1218,17 @@ function format(type, value, le, options) {
|
|
|
1184
1218
|
:
|
|
1185
1219
|
`(${String(x)}, ${String(y)})`;
|
|
1186
1220
|
}
|
|
1221
|
+
case DdbType.complex: {
|
|
1222
|
+
let [x, y] = value;
|
|
1223
|
+
if (x === exports.nulls.double)
|
|
1224
|
+
x = null;
|
|
1225
|
+
if (y === exports.nulls.double)
|
|
1226
|
+
y = null;
|
|
1227
|
+
return options.colors ?
|
|
1228
|
+
`${String(x).green}+${`${String(y)}i`.green}`
|
|
1229
|
+
:
|
|
1230
|
+
`${String(x)}+${String(y)}i`;
|
|
1231
|
+
}
|
|
1187
1232
|
case DdbType.duration: {
|
|
1188
1233
|
const { data, unit } = value;
|
|
1189
1234
|
const str = `${data}${DdbDurationUnit[unit]}`;
|
|
@@ -1505,32 +1550,32 @@ class DdbTable extends DdbObj {
|
|
|
1505
1550
|
exports.DdbTable = DdbTable;
|
|
1506
1551
|
function date2str(date, format = 'YYYY.MM.DD') {
|
|
1507
1552
|
return (date === null || date === exports.nulls.int32) ?
|
|
1508
|
-
''
|
|
1553
|
+
'null'
|
|
1509
1554
|
:
|
|
1510
1555
|
(0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * 24 * date).format(format);
|
|
1511
1556
|
}
|
|
1512
1557
|
exports.date2str = date2str;
|
|
1513
1558
|
function month2str(month) {
|
|
1514
1559
|
if (month === null || month === exports.nulls.int32)
|
|
1515
|
-
return '';
|
|
1560
|
+
return 'null';
|
|
1516
1561
|
if (month < 0)
|
|
1517
1562
|
return String(month);
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
return `${String(year).padStart(4, '0')}.${String(_month + 1).padStart(2, '0')}`;
|
|
1563
|
+
const _month = month % 12;
|
|
1564
|
+
const year = Math.trunc(month / 12);
|
|
1565
|
+
return `${String(year).padStart(4, '0')}.${String(_month + 1).padStart(2, '0')}M`;
|
|
1521
1566
|
}
|
|
1522
1567
|
exports.month2str = month2str;
|
|
1523
1568
|
function time2str(time, format = 'HH:mm:ss.SSS') {
|
|
1524
1569
|
return (time === null || time === exports.nulls.int32) ?
|
|
1525
|
-
''
|
|
1570
|
+
'null'
|
|
1526
1571
|
:
|
|
1527
1572
|
(0, dayjs_1.default)(exports.timezone_offset + time)
|
|
1528
1573
|
.format(format);
|
|
1529
1574
|
}
|
|
1530
1575
|
exports.time2str = time2str;
|
|
1531
|
-
function minute2str(minute, format = 'HH:mm') {
|
|
1576
|
+
function minute2str(minute, format = 'HH:mm[m]') {
|
|
1532
1577
|
return (minute === null || minute === exports.nulls.int32) ?
|
|
1533
|
-
''
|
|
1578
|
+
'null'
|
|
1534
1579
|
:
|
|
1535
1580
|
(0, dayjs_1.default)(exports.timezone_offset + 60 * 1000 * minute)
|
|
1536
1581
|
.format(format);
|
|
@@ -1538,7 +1583,7 @@ function minute2str(minute, format = 'HH:mm') {
|
|
|
1538
1583
|
exports.minute2str = minute2str;
|
|
1539
1584
|
function second2str(second, format = 'HH:mm:ss') {
|
|
1540
1585
|
return (second === null || second === exports.nulls.int32) ?
|
|
1541
|
-
''
|
|
1586
|
+
'null'
|
|
1542
1587
|
:
|
|
1543
1588
|
(0, dayjs_1.default)(exports.timezone_offset + 1000 * second)
|
|
1544
1589
|
.format(format);
|
|
@@ -1546,7 +1591,7 @@ function second2str(second, format = 'HH:mm:ss') {
|
|
|
1546
1591
|
exports.second2str = second2str;
|
|
1547
1592
|
function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
|
|
1548
1593
|
return (datetime === null || datetime === exports.nulls.int32) ?
|
|
1549
|
-
''
|
|
1594
|
+
'null'
|
|
1550
1595
|
:
|
|
1551
1596
|
(0, dayjs_1.default)(exports.timezone_offset + 1000 * datetime).format(format);
|
|
1552
1597
|
}
|
|
@@ -1559,26 +1604,26 @@ exports.datetime2str = datetime2str;
|
|
|
1559
1604
|
*/
|
|
1560
1605
|
function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
1561
1606
|
return (timestamp === null || timestamp === exports.nulls.int64) ?
|
|
1562
|
-
''
|
|
1607
|
+
'null'
|
|
1563
1608
|
:
|
|
1564
1609
|
(0, dayjs_1.default)(exports.timezone_offset + Number(timestamp)).format(format);
|
|
1565
1610
|
}
|
|
1566
1611
|
exports.timestamp2str = timestamp2str;
|
|
1567
|
-
function datehour2str(datehour, format = 'YYYY.MM.
|
|
1612
|
+
function datehour2str(datehour, format = 'YYYY.MM.DDTHH') {
|
|
1568
1613
|
return (datehour === null || datehour === exports.nulls.int32) ?
|
|
1569
|
-
''
|
|
1614
|
+
'null'
|
|
1570
1615
|
:
|
|
1571
1616
|
(0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * datehour).format(format);
|
|
1572
1617
|
}
|
|
1573
1618
|
exports.datehour2str = datehour2str;
|
|
1574
1619
|
/** parse timestamp string to bigint value
|
|
1575
|
-
- str: timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
|
|
1620
|
+
- str: timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
|
|
1576
1621
|
- format?:
|
|
1577
1622
|
The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
|
|
1578
1623
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1579
1624
|
*/
|
|
1580
1625
|
function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
1581
|
-
if (!str)
|
|
1626
|
+
if (!str || str === 'null')
|
|
1582
1627
|
return exports.nulls.int64;
|
|
1583
1628
|
if (str.length !== format.length)
|
|
1584
1629
|
throw new Error('The length of the timestamp string is not equal to the length of the format string');
|
|
@@ -1587,6 +1632,10 @@ function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
|
1587
1632
|
}
|
|
1588
1633
|
exports.str2timestamp = str2timestamp;
|
|
1589
1634
|
function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
|
|
1635
|
+
if (nanotime === null || nanotime === exports.nulls.int64)
|
|
1636
|
+
return 'null';
|
|
1637
|
+
if (nanotime < 0n)
|
|
1638
|
+
return String(nanotime);
|
|
1590
1639
|
const i_second_start = format.indexOf('ss');
|
|
1591
1640
|
if (i_second_start === -1)
|
|
1592
1641
|
throw new Error('The format string must contain the format for seconds (ss)');
|
|
@@ -1607,8 +1656,14 @@ exports.nanotime2str = nanotime2str;
|
|
|
1607
1656
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1608
1657
|
*/
|
|
1609
1658
|
function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
1659
|
+
// tests:
|
|
1660
|
+
// nanotimestamp2str(0n)
|
|
1661
|
+
// nanotimestamp2str(-1n)
|
|
1662
|
+
// nanotimestamp2str(-9_9999_9999n)
|
|
1663
|
+
// nanotimestamp2str(-10_0000_0000n)
|
|
1664
|
+
// nanotimestamp2str(-10_0000_0001n)
|
|
1610
1665
|
if (nanotimestamp === null || nanotimestamp === exports.nulls.int64)
|
|
1611
|
-
return '';
|
|
1666
|
+
return 'null';
|
|
1612
1667
|
const i_second_start = format.indexOf('ss');
|
|
1613
1668
|
if (i_second_start === -1)
|
|
1614
1669
|
throw new Error('The format string must contain the format for seconds (ss)');
|
|
@@ -1616,20 +1671,27 @@ function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSS
|
|
|
1616
1671
|
const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
|
|
1617
1672
|
if (i_nanosecond_start === -1)
|
|
1618
1673
|
throw new Error('The format string must contain the format for nanoseconds (SSSSSSSSS)');
|
|
1619
|
-
|
|
1674
|
+
const remainder = nanotimestamp % 1000000000n;
|
|
1675
|
+
const borrow = remainder < 0n;
|
|
1676
|
+
return ((0, dayjs_1.default)(exports.timezone_offset +
|
|
1677
|
+
// 去掉 9 位的纳秒部分,转化为毫秒
|
|
1678
|
+
Number((nanotimestamp - remainder + (borrow ? -1000000000n : 0n)) / 1000000n)).format(format.slice(0, i_second_end)) +
|
|
1620
1679
|
format.slice(i_second_end, i_nanosecond_start) +
|
|
1621
|
-
String(
|
|
1680
|
+
String(borrow ?
|
|
1681
|
+
(remainder + 1000000000n) % 1000000000n
|
|
1682
|
+
:
|
|
1683
|
+
remainder).padStart(9, '0'));
|
|
1622
1684
|
}
|
|
1623
1685
|
exports.nanotimestamp2str = nanotimestamp2str;
|
|
1624
1686
|
/** parse nano timestamp string to bigint value
|
|
1625
|
-
- str: nano timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
|
|
1687
|
+
- str: nano timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
|
|
1626
1688
|
- format?:
|
|
1627
1689
|
The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
|
|
1628
1690
|
Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
|
|
1629
1691
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1630
1692
|
*/
|
|
1631
1693
|
function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
1632
|
-
if (!str)
|
|
1694
|
+
if (!str || str === 'null')
|
|
1633
1695
|
return exports.nulls.int64;
|
|
1634
1696
|
if (str.length !== format.length)
|
|
1635
1697
|
throw new Error('nanotimestamp string length is not equal to format string length');
|
|
@@ -1844,9 +1906,9 @@ class DDB {
|
|
|
1844
1906
|
- options:
|
|
1845
1907
|
- urgent?: 决定 `行为标识` 那一行字符串的取值(只适用于 script 和 function)
|
|
1846
1908
|
- vars?: type === 'variable' 时必传,variable 指令中待上传的变量名
|
|
1847
|
-
-
|
|
1848
|
-
- parse_object?:
|
|
1849
|
-
|
|
1909
|
+
- listener?: 处理本次 rpc 期间的消息 (DdbMessage)
|
|
1910
|
+
- parse_object?: 在本次 rpc 期间设置 parse_object, 结束后恢复原有
|
|
1911
|
+
为 false 时返回的 DdbObj 仅含有 buffer 和 le,不做解析,以便后续转发、序列化
|
|
1850
1912
|
*/
|
|
1851
1913
|
async rpc(type, { script, func, args = [], vars = [], urgent, listener, parse_object, }) {
|
|
1852
1914
|
if (!this.websocket)
|
|
@@ -2070,5 +2132,4 @@ class DDB {
|
|
|
2070
2132
|
exports.DDB = DDB;
|
|
2071
2133
|
/** little endian (client) */
|
|
2072
2134
|
DDB.le_client = Boolean(new Uint8Array(Uint32Array.of(1).buffer)[0]);
|
|
2073
|
-
exports.default = DDB;
|
|
2074
2135
|
//# sourceMappingURL=index.js.map
|