dolphindb 2.0.514 → 2.0.515
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 +2 -2
- package/browser.js +44 -20
- package/browser.js.map +1 -1
- package/index.d.ts +4 -4
- package/index.js +49 -22
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -262,7 +262,7 @@ export declare function datetime2str(datetime: number, format?: string): string;
|
|
|
262
262
|
export declare function timestamp2str(timestamp: bigint, format?: string): string;
|
|
263
263
|
export declare function datehour2str(datehour: number, format?: string): string;
|
|
264
264
|
/** parse timestamp string to bigint value
|
|
265
|
-
- 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)
|
|
266
266
|
- format?:
|
|
267
267
|
The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
|
|
268
268
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
@@ -278,7 +278,7 @@ export declare function nanotime2str(nanotime: bigint, format?: string): string;
|
|
|
278
278
|
*/
|
|
279
279
|
export declare function nanotimestamp2str(nanotimestamp: bigint, format?: string): string;
|
|
280
280
|
/** parse nano timestamp string to bigint value
|
|
281
|
-
- 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)
|
|
282
282
|
- format?:
|
|
283
283
|
The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
|
|
284
284
|
Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
|
|
@@ -392,8 +392,8 @@ export declare class DDB {
|
|
|
392
392
|
- urgent?: 决定 `行为标识` 那一行字符串的取值(只适用于 script 和 function)
|
|
393
393
|
- vars?: type === 'variable' 时必传,variable 指令中待上传的变量名
|
|
394
394
|
- listener?: 处理本次 rpc 期间的消息 (DdbMessage)
|
|
395
|
-
- parse_object?:
|
|
396
|
-
|
|
395
|
+
- parse_object?: 在本次 rpc 期间设置 parse_object, 结束后恢复原有
|
|
396
|
+
为 false 时返回的 DdbObj 仅含有 buffer 和 le,不做解析,以便后续转发、序列化
|
|
397
397
|
*/
|
|
398
398
|
rpc<T extends DdbObj = DdbObj>(type: 'script' | 'function' | 'variable' | 'connect', { script, func, args, vars, urgent, listener, parse_object, }: {
|
|
399
399
|
script?: string;
|
package/index.js
CHANGED
|
@@ -1204,7 +1204,6 @@ function format(type, value, le, options) {
|
|
|
1204
1204
|
int1282str(value, le);
|
|
1205
1205
|
case DdbType.blob:
|
|
1206
1206
|
return (0, utils_js_1.inspect)(DdbObj.dec.decode(value.subarray(0, 1000)), options);
|
|
1207
|
-
case DdbType.complex:
|
|
1208
1207
|
case DdbType.point: {
|
|
1209
1208
|
let [x, y] = value;
|
|
1210
1209
|
if (x === exports.nulls.double)
|
|
@@ -1216,6 +1215,17 @@ function format(type, value, le, options) {
|
|
|
1216
1215
|
:
|
|
1217
1216
|
`(${String(x)}, ${String(y)})`;
|
|
1218
1217
|
}
|
|
1218
|
+
case DdbType.complex: {
|
|
1219
|
+
let [x, y] = value;
|
|
1220
|
+
if (x === exports.nulls.double)
|
|
1221
|
+
x = null;
|
|
1222
|
+
if (y === exports.nulls.double)
|
|
1223
|
+
y = null;
|
|
1224
|
+
return options.colors ?
|
|
1225
|
+
`${String(x).green}+${`${String(y)}i`.green}`
|
|
1226
|
+
:
|
|
1227
|
+
`${String(x)}+${String(y)}i`;
|
|
1228
|
+
}
|
|
1219
1229
|
case DdbType.duration: {
|
|
1220
1230
|
const { data, unit } = value;
|
|
1221
1231
|
const str = `${data}${DdbDurationUnit[unit]}`;
|
|
@@ -1537,24 +1547,24 @@ class DdbTable extends DdbObj {
|
|
|
1537
1547
|
exports.DdbTable = DdbTable;
|
|
1538
1548
|
function date2str(date, format = 'YYYY.MM.DD') {
|
|
1539
1549
|
return (date === null || date === exports.nulls.int32) ?
|
|
1540
|
-
''
|
|
1550
|
+
'null'
|
|
1541
1551
|
:
|
|
1542
1552
|
(0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * 24 * date).format(format);
|
|
1543
1553
|
}
|
|
1544
1554
|
exports.date2str = date2str;
|
|
1545
1555
|
function month2str(month) {
|
|
1546
1556
|
if (month === null || month === exports.nulls.int32)
|
|
1547
|
-
return '';
|
|
1557
|
+
return 'null';
|
|
1548
1558
|
if (month < 0)
|
|
1549
1559
|
return String(month);
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
return `${String(year).padStart(4, '0')}.${String(_month + 1).padStart(2, '0')}`;
|
|
1560
|
+
const _month = month % 12;
|
|
1561
|
+
const year = Math.trunc(month / 12);
|
|
1562
|
+
return `${String(year).padStart(4, '0')}.${String(_month + 1).padStart(2, '0')}M`;
|
|
1553
1563
|
}
|
|
1554
1564
|
exports.month2str = month2str;
|
|
1555
1565
|
function time2str(time, format = 'HH:mm:ss.SSS') {
|
|
1556
1566
|
return (time === null || time === exports.nulls.int32) ?
|
|
1557
|
-
''
|
|
1567
|
+
'null'
|
|
1558
1568
|
:
|
|
1559
1569
|
(0, dayjs_1.default)(exports.timezone_offset + time)
|
|
1560
1570
|
.format(format);
|
|
@@ -1562,7 +1572,7 @@ function time2str(time, format = 'HH:mm:ss.SSS') {
|
|
|
1562
1572
|
exports.time2str = time2str;
|
|
1563
1573
|
function minute2str(minute, format = 'HH:mm') {
|
|
1564
1574
|
return (minute === null || minute === exports.nulls.int32) ?
|
|
1565
|
-
''
|
|
1575
|
+
'null'
|
|
1566
1576
|
:
|
|
1567
1577
|
(0, dayjs_1.default)(exports.timezone_offset + 60 * 1000 * minute)
|
|
1568
1578
|
.format(format);
|
|
@@ -1570,7 +1580,7 @@ function minute2str(minute, format = 'HH:mm') {
|
|
|
1570
1580
|
exports.minute2str = minute2str;
|
|
1571
1581
|
function second2str(second, format = 'HH:mm:ss') {
|
|
1572
1582
|
return (second === null || second === exports.nulls.int32) ?
|
|
1573
|
-
''
|
|
1583
|
+
'null'
|
|
1574
1584
|
:
|
|
1575
1585
|
(0, dayjs_1.default)(exports.timezone_offset + 1000 * second)
|
|
1576
1586
|
.format(format);
|
|
@@ -1578,7 +1588,7 @@ function second2str(second, format = 'HH:mm:ss') {
|
|
|
1578
1588
|
exports.second2str = second2str;
|
|
1579
1589
|
function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
|
|
1580
1590
|
return (datetime === null || datetime === exports.nulls.int32) ?
|
|
1581
|
-
''
|
|
1591
|
+
'null'
|
|
1582
1592
|
:
|
|
1583
1593
|
(0, dayjs_1.default)(exports.timezone_offset + 1000 * datetime).format(format);
|
|
1584
1594
|
}
|
|
@@ -1591,26 +1601,26 @@ exports.datetime2str = datetime2str;
|
|
|
1591
1601
|
*/
|
|
1592
1602
|
function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
1593
1603
|
return (timestamp === null || timestamp === exports.nulls.int64) ?
|
|
1594
|
-
''
|
|
1604
|
+
'null'
|
|
1595
1605
|
:
|
|
1596
1606
|
(0, dayjs_1.default)(exports.timezone_offset + Number(timestamp)).format(format);
|
|
1597
1607
|
}
|
|
1598
1608
|
exports.timestamp2str = timestamp2str;
|
|
1599
|
-
function datehour2str(datehour, format = 'YYYY.MM.
|
|
1609
|
+
function datehour2str(datehour, format = 'YYYY.MM.DDTHH') {
|
|
1600
1610
|
return (datehour === null || datehour === exports.nulls.int32) ?
|
|
1601
|
-
''
|
|
1611
|
+
'null'
|
|
1602
1612
|
:
|
|
1603
1613
|
(0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * datehour).format(format);
|
|
1604
1614
|
}
|
|
1605
1615
|
exports.datehour2str = datehour2str;
|
|
1606
1616
|
/** parse timestamp string to bigint value
|
|
1607
|
-
- str: timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
|
|
1617
|
+
- str: timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
|
|
1608
1618
|
- format?:
|
|
1609
1619
|
The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
|
|
1610
1620
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1611
1621
|
*/
|
|
1612
1622
|
function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
1613
|
-
if (!str)
|
|
1623
|
+
if (!str || str === 'null')
|
|
1614
1624
|
return exports.nulls.int64;
|
|
1615
1625
|
if (str.length !== format.length)
|
|
1616
1626
|
throw new Error('The length of the timestamp string is not equal to the length of the format string');
|
|
@@ -1619,6 +1629,10 @@ function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
|
1619
1629
|
}
|
|
1620
1630
|
exports.str2timestamp = str2timestamp;
|
|
1621
1631
|
function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
|
|
1632
|
+
if (nanotime === null || nanotime === exports.nulls.int64)
|
|
1633
|
+
return 'null';
|
|
1634
|
+
if (nanotime < 0n)
|
|
1635
|
+
return String(nanotime);
|
|
1622
1636
|
const i_second_start = format.indexOf('ss');
|
|
1623
1637
|
if (i_second_start === -1)
|
|
1624
1638
|
throw new Error('The format string must contain the format for seconds (ss)');
|
|
@@ -1639,8 +1653,14 @@ exports.nanotime2str = nanotime2str;
|
|
|
1639
1653
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1640
1654
|
*/
|
|
1641
1655
|
function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
1656
|
+
// tests:
|
|
1657
|
+
// nanotimestamp2str(0n)
|
|
1658
|
+
// nanotimestamp2str(-1n)
|
|
1659
|
+
// nanotimestamp2str(-9_9999_9999n)
|
|
1660
|
+
// nanotimestamp2str(-10_0000_0000n)
|
|
1661
|
+
// nanotimestamp2str(-10_0000_0001n)
|
|
1642
1662
|
if (nanotimestamp === null || nanotimestamp === exports.nulls.int64)
|
|
1643
|
-
return '';
|
|
1663
|
+
return 'null';
|
|
1644
1664
|
const i_second_start = format.indexOf('ss');
|
|
1645
1665
|
if (i_second_start === -1)
|
|
1646
1666
|
throw new Error('The format string must contain the format for seconds (ss)');
|
|
@@ -1648,20 +1668,27 @@ function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSS
|
|
|
1648
1668
|
const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
|
|
1649
1669
|
if (i_nanosecond_start === -1)
|
|
1650
1670
|
throw new Error('The format string must contain the format for nanoseconds (SSSSSSSSS)');
|
|
1651
|
-
|
|
1671
|
+
const remainder = nanotimestamp % 1000000000n;
|
|
1672
|
+
const borrow = remainder < 0n;
|
|
1673
|
+
return ((0, dayjs_1.default)(exports.timezone_offset +
|
|
1674
|
+
// 去掉 9 位的纳秒部分,转化为毫秒
|
|
1675
|
+
Number((nanotimestamp - remainder + (borrow ? -1000000000n : 0n)) / 1000000n)).format(format.slice(0, i_second_end)) +
|
|
1652
1676
|
format.slice(i_second_end, i_nanosecond_start) +
|
|
1653
|
-
String(
|
|
1677
|
+
String(borrow ?
|
|
1678
|
+
(remainder + 1000000000n) % 1000000000n
|
|
1679
|
+
:
|
|
1680
|
+
remainder).padStart(9, '0'));
|
|
1654
1681
|
}
|
|
1655
1682
|
exports.nanotimestamp2str = nanotimestamp2str;
|
|
1656
1683
|
/** parse nano timestamp string to bigint value
|
|
1657
|
-
- str: nano timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
|
|
1684
|
+
- str: nano timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
|
|
1658
1685
|
- format?:
|
|
1659
1686
|
The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
|
|
1660
1687
|
Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
|
|
1661
1688
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1662
1689
|
*/
|
|
1663
1690
|
function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
1664
|
-
if (!str)
|
|
1691
|
+
if (!str || str === 'null')
|
|
1665
1692
|
return exports.nulls.int64;
|
|
1666
1693
|
if (str.length !== format.length)
|
|
1667
1694
|
throw new Error('nanotimestamp string length is not equal to format string length');
|
|
@@ -1877,8 +1904,8 @@ class DDB {
|
|
|
1877
1904
|
- urgent?: 决定 `行为标识` 那一行字符串的取值(只适用于 script 和 function)
|
|
1878
1905
|
- vars?: type === 'variable' 时必传,variable 指令中待上传的变量名
|
|
1879
1906
|
- listener?: 处理本次 rpc 期间的消息 (DdbMessage)
|
|
1880
|
-
- parse_object?:
|
|
1881
|
-
|
|
1907
|
+
- parse_object?: 在本次 rpc 期间设置 parse_object, 结束后恢复原有
|
|
1908
|
+
为 false 时返回的 DdbObj 仅含有 buffer 和 le,不做解析,以便后续转发、序列化
|
|
1882
1909
|
*/
|
|
1883
1910
|
async rpc(type, { script, func, args = [], vars = [], urgent, listener, parse_object, }) {
|
|
1884
1911
|
if (!this.websocket)
|