dolphindb 3.0.224 → 3.0.227

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/common.js ADDED
@@ -0,0 +1,465 @@
1
+ import { default as dayjs } from 'dayjs';
2
+ import DayjsCustomParseFormat from 'dayjs/plugin/customParseFormat.js';
3
+ dayjs.extend(DayjsCustomParseFormat);
4
+ import 'xshell/prototype.common.js';
5
+ import { check } from 'xshell/utils.common.js';
6
+ import ipaddrjs from 'ipaddr.js';
7
+ const { fromByteArray: buf2ipaddr } = ipaddrjs;
8
+ import { t } from "./i18n/index.js";
9
+ export const nulls = {
10
+ int8: -0x80, // -128
11
+ int16: -0x80_00, // -32768
12
+ int32: -0x80_00_00_00, // -21_4748_3648
13
+ int64: -0x8000000000000000n, // -922_3372_0368_5477_5808
14
+ int128: -0x80000000000000000000000000000000n, // -170_1411_8346_0469_2317_3168_7303_7158_8410_5728
15
+ float32: -3.4028234663852886e+38,
16
+ /** -Number.MAX_VALUE */
17
+ double: -Number.MAX_VALUE,
18
+ bytes16: Uint8Array.from(new Array(16).fill(0))
19
+ };
20
+ export var DdbForm;
21
+ (function (DdbForm) {
22
+ DdbForm[DdbForm["scalar"] = 0] = "scalar";
23
+ DdbForm[DdbForm["vector"] = 1] = "vector";
24
+ DdbForm[DdbForm["pair"] = 2] = "pair";
25
+ DdbForm[DdbForm["matrix"] = 3] = "matrix";
26
+ DdbForm[DdbForm["set"] = 4] = "set";
27
+ DdbForm[DdbForm["dict"] = 5] = "dict";
28
+ DdbForm[DdbForm["table"] = 6] = "table";
29
+ DdbForm[DdbForm["chart"] = 7] = "chart";
30
+ /** 节点内部通信可能会使用,调用函数执行脚本一般不会返回这种类型 */
31
+ DdbForm[DdbForm["chunk"] = 8] = "chunk";
32
+ /** sysobj */
33
+ DdbForm[DdbForm["object"] = 9] = "object";
34
+ DdbForm[DdbForm["tensor"] = 10] = "tensor";
35
+ })(DdbForm || (DdbForm = {}));
36
+ /** DolphinDB DataType
37
+ 对应的 array vector 类型为 64 + 基本类型
38
+ 对应的 extended 类型为 128 + 基本类型 */
39
+ export var DdbType;
40
+ (function (DdbType) {
41
+ DdbType[DdbType["void"] = 0] = "void";
42
+ DdbType[DdbType["bool"] = 1] = "bool";
43
+ DdbType[DdbType["char"] = 2] = "char";
44
+ DdbType[DdbType["short"] = 3] = "short";
45
+ DdbType[DdbType["int"] = 4] = "int";
46
+ DdbType[DdbType["long"] = 5] = "long";
47
+ DdbType[DdbType["date"] = 6] = "date";
48
+ DdbType[DdbType["month"] = 7] = "month";
49
+ DdbType[DdbType["time"] = 8] = "time";
50
+ DdbType[DdbType["minute"] = 9] = "minute";
51
+ DdbType[DdbType["second"] = 10] = "second";
52
+ DdbType[DdbType["datetime"] = 11] = "datetime";
53
+ DdbType[DdbType["timestamp"] = 12] = "timestamp";
54
+ DdbType[DdbType["nanotime"] = 13] = "nanotime";
55
+ DdbType[DdbType["nanotimestamp"] = 14] = "nanotimestamp";
56
+ DdbType[DdbType["float"] = 15] = "float";
57
+ DdbType[DdbType["double"] = 16] = "double";
58
+ DdbType[DdbType["symbol"] = 17] = "symbol";
59
+ DdbType[DdbType["string"] = 18] = "string";
60
+ DdbType[DdbType["uuid"] = 19] = "uuid";
61
+ DdbType[DdbType["functiondef"] = 20] = "functiondef";
62
+ DdbType[DdbType["handle"] = 21] = "handle";
63
+ DdbType[DdbType["code"] = 22] = "code";
64
+ DdbType[DdbType["datasource"] = 23] = "datasource";
65
+ DdbType[DdbType["resource"] = 24] = "resource";
66
+ DdbType[DdbType["any"] = 25] = "any";
67
+ DdbType[DdbType["compressed"] = 26] = "compressed";
68
+ DdbType[DdbType["dict"] = 27] = "dict";
69
+ DdbType[DdbType["datehour"] = 28] = "datehour";
70
+ DdbType[DdbType["ipaddr"] = 30] = "ipaddr";
71
+ DdbType[DdbType["int128"] = 31] = "int128";
72
+ DdbType[DdbType["blob"] = 32] = "blob";
73
+ DdbType[DdbType["complex"] = 34] = "complex";
74
+ DdbType[DdbType["point"] = 35] = "point";
75
+ DdbType[DdbType["duration"] = 36] = "duration";
76
+ DdbType[DdbType["decimal32"] = 37] = "decimal32";
77
+ DdbType[DdbType["decimal64"] = 38] = "decimal64";
78
+ DdbType[DdbType["decimal128"] = 39] = "decimal128";
79
+ DdbType[DdbType["object"] = 40] = "object";
80
+ DdbType[DdbType["iotany"] = 41] = "iotany";
81
+ DdbType[DdbType["symbol_extended"] = 145] = "symbol_extended";
82
+ })(DdbType || (DdbType = {}));
83
+ export var DdbFunctionType;
84
+ (function (DdbFunctionType) {
85
+ DdbFunctionType[DdbFunctionType["SystemFunc"] = 0] = "SystemFunc";
86
+ DdbFunctionType[DdbFunctionType["SystemProc"] = 1] = "SystemProc";
87
+ DdbFunctionType[DdbFunctionType["OperatorFunc"] = 2] = "OperatorFunc";
88
+ DdbFunctionType[DdbFunctionType["UserDefinedFunc"] = 3] = "UserDefinedFunc";
89
+ DdbFunctionType[DdbFunctionType["PartialFunc"] = 4] = "PartialFunc";
90
+ DdbFunctionType[DdbFunctionType["DynamicFunc"] = 5] = "DynamicFunc";
91
+ DdbFunctionType[DdbFunctionType["PiecewiseFunc"] = 6] = "PiecewiseFunc";
92
+ DdbFunctionType[DdbFunctionType["JitFunc"] = 7] = "JitFunc";
93
+ DdbFunctionType[DdbFunctionType["JitPartialFunc"] = 8] = "JitPartialFunc";
94
+ })(DdbFunctionType || (DdbFunctionType = {}));
95
+ export var DdbDurationUnit;
96
+ (function (DdbDurationUnit) {
97
+ DdbDurationUnit[DdbDurationUnit["ns"] = 0] = "ns";
98
+ DdbDurationUnit[DdbDurationUnit["us"] = 1] = "us";
99
+ DdbDurationUnit[DdbDurationUnit["ms"] = 2] = "ms";
100
+ DdbDurationUnit[DdbDurationUnit["s"] = 3] = "s";
101
+ DdbDurationUnit[DdbDurationUnit["m"] = 4] = "m";
102
+ DdbDurationUnit[DdbDurationUnit["H"] = 5] = "H";
103
+ DdbDurationUnit[DdbDurationUnit["d"] = 6] = "d";
104
+ DdbDurationUnit[DdbDurationUnit["w"] = 7] = "w";
105
+ DdbDurationUnit[DdbDurationUnit["M"] = 8] = "M";
106
+ DdbDurationUnit[DdbDurationUnit["y"] = 9] = "y";
107
+ DdbDurationUnit[DdbDurationUnit["B"] = 10] = "B";
108
+ })(DdbDurationUnit || (DdbDurationUnit = {}));
109
+ export var DdbChartType;
110
+ (function (DdbChartType) {
111
+ DdbChartType[DdbChartType["area"] = 0] = "area";
112
+ DdbChartType[DdbChartType["bar"] = 1] = "bar";
113
+ DdbChartType[DdbChartType["column"] = 2] = "column";
114
+ DdbChartType[DdbChartType["histogram"] = 3] = "histogram";
115
+ DdbChartType[DdbChartType["line"] = 4] = "line";
116
+ DdbChartType[DdbChartType["pie"] = 5] = "pie";
117
+ DdbChartType[DdbChartType["scatter"] = 6] = "scatter";
118
+ DdbChartType[DdbChartType["trend"] = 7] = "trend";
119
+ DdbChartType[DdbChartType["kline"] = 8] = "kline";
120
+ })(DdbChartType || (DdbChartType = {}));
121
+ // server 实现中区分了 0: NULL (nothing), 1: NULL (null), 2: DFLT (default)
122
+ // Void::serialize()
123
+ // (isNothing() ? 0 : 1) + (isDefault_ ? 2 : 0);
124
+ export var DdbVoidType;
125
+ (function (DdbVoidType) {
126
+ DdbVoidType[DdbVoidType["undefined"] = 0] = "undefined";
127
+ DdbVoidType[DdbVoidType["null"] = 1] = "null";
128
+ DdbVoidType[DdbVoidType["default"] = 2] = "default";
129
+ })(DdbVoidType || (DdbVoidType = {}));
130
+ export const dictables = new Set([DdbType.any, DdbType.string, DdbType.double, DdbType.float, DdbType.int, DdbType.long]);
131
+ /** 工具,取得某个 DdbType 的字节数 */
132
+ export const ddb_tensor_bytes = {
133
+ [DdbType.bool]: 1,
134
+ [DdbType.char]: 1,
135
+ [DdbType.short]: 2,
136
+ [DdbType.int]: 4,
137
+ [DdbType.long]: 8,
138
+ [DdbType.float]: 4,
139
+ [DdbType.double]: 8,
140
+ };
141
+ /** 根据 DdbType 获取其名称,array vector type 自动在后面加上 [] */
142
+ export function get_type_name(type) {
143
+ return `${DdbType[type] || type}${64 <= type && type < 128 ? '[]' : ''}`;
144
+ }
145
+ export function is_decimal_type(type) {
146
+ return type === DdbType.decimal32 || type === DdbType.decimal64 || type === DdbType.decimal128;
147
+ }
148
+ export function is_decimal_null_value(type, value) {
149
+ return ((value === nulls.int128 && type === DdbType.decimal128) ||
150
+ (value === nulls.int64 && type === DdbType.decimal64) ||
151
+ (value === nulls.int32 && type === DdbType.decimal32));
152
+ }
153
+ export function get_duration_unit(code) {
154
+ let str = String.fromCharCode((code >> 24) & 0xff);
155
+ str += String.fromCharCode((code >> 16) & 0xff);
156
+ str += String.fromCharCode((code >> 8) & 0xff);
157
+ str += String.fromCharCode(code & 0xff);
158
+ return str;
159
+ }
160
+ export function get_ddb_time_value(classname, value) {
161
+ if (value === null)
162
+ return null;
163
+ if (classname === 'DdbNanoTimeStamp' && typeof value === 'string')
164
+ return str2nanotimestamp(value);
165
+ let date;
166
+ if (value === undefined)
167
+ date = new Date();
168
+ else if (typeof value === 'number' || typeof value === 'string')
169
+ date = new Date(value);
170
+ else if (value instanceof Date)
171
+ date = value;
172
+ else if (dayjs.isDayjs(value))
173
+ date = new Date(value.valueOf());
174
+ else
175
+ throw new Error(t('value 不能转换为 {{classname}}', { classname }));
176
+ switch (classname) {
177
+ case 'DdbDateTime':
178
+ return (date.getTime() - 1000 * 60 * date.getTimezoneOffset()) / 1000;
179
+ case 'DdbTimeStamp':
180
+ return BigInt(date.getTime() - 1000 * 60 * date.getTimezoneOffset());
181
+ case 'DdbNanoTimeStamp':
182
+ return BigInt(date.getTime() - 1000 * 60 * date.getTimezoneOffset()) * 1000000n;
183
+ case 'DdbDate':
184
+ return Math.floor((date.getTime() - 1000 * 60 * date.getTimezoneOffset()) / (1000 * 3600 * 24));
185
+ }
186
+ }
187
+ // DataView Extends for bigint 128 operations
188
+ export function get_big_uint_128(dataview, byte_offset, le = true) {
189
+ let cursor = byte_offset + (le ? 15 : 0);
190
+ const end = byte_offset + (le ? -1 : 16);
191
+ const step = le ? -1 : 1;
192
+ let value = 0n;
193
+ while (cursor !== end) {
194
+ value = value << 8n | BigInt(dataview.getUint8(cursor));
195
+ cursor += step;
196
+ }
197
+ return value;
198
+ }
199
+ export function get_big_int_128(dataview, byte_offset, le = true) {
200
+ return BigInt.asIntN(128, get_big_uint_128(dataview, byte_offset, le));
201
+ }
202
+ export function set_big_uint_128(dataView, byte_offset, value, le = true) {
203
+ let cursor = byte_offset + (le ? 0 : 15);
204
+ const end = byte_offset + (le ? 16 : -1);
205
+ const step = le ? 1 : -1;
206
+ while (cursor !== end) {
207
+ dataView.setUint8(cursor, Number(value & 0xffn));
208
+ value = value >> 8n;
209
+ cursor += step;
210
+ }
211
+ }
212
+ export function set_big_int_128(dataview, byte_offset, value, le = true) {
213
+ set_big_uint_128(dataview, byte_offset, value, le);
214
+ }
215
+ export function generate_array_type(baseType, dimensions) {
216
+ let result = baseType;
217
+ dimensions.forEach(dimension => {
218
+ result += `[${dimension}]`;
219
+ });
220
+ return result;
221
+ }
222
+ // 大端
223
+ // const dataBE = new ArrayBuffer(16)
224
+ // const dataViewBE = new DataView(dataBE)
225
+ // set_big_int_128(dataViewBE, 0, -34355n, false)
226
+ // console.log(dataViewBE.buffer)
227
+ // const bigInt128BE = get_big_int_128(dataViewBE, 0, false)
228
+ // const bigUint128BE = get_big_uint_128(dataViewBE, 0, false)
229
+ // console.log(bigInt128BE.toString(), bigUint128BE.toString())
230
+ // 小端
231
+ // const dataLE = new ArrayBuffer(16)
232
+ // const dataViewLE = new DataView(dataLE)
233
+ // set_big_int_128(dataViewLE, 0, -34355n, true)
234
+ // console.log(dataViewLE.buffer)
235
+ // const bigInt128LE = get_big_int_128(dataViewLE, 0, true)
236
+ // const bigUint128LE = get_big_uint_128(dataViewLE, 0, true)
237
+ // console.log(bigInt128LE.toString(), bigUint128LE.toString())
238
+ /** 用来处理时差 To deal with jet lag */
239
+ let _datetime_formatter = new Intl.DateTimeFormat('zh-CN', { dateStyle: 'short', timeStyle: 'medium', timeZone: 'UTC', hour12: false });
240
+ export function date2ms(date) {
241
+ // 将 server 的本地时间 (以 ms 为单位,1970.01.01 00:00:00 作为零点) 作为 UTC-0 格式化为字符串,然后根据本地的时区解析这个字符串转换为 UTC-8
242
+ // 本地的时区与实际的时间值相关,getTimezoneOffset() 可能会受到夏令时 (DST) 的影响,不能使用
243
+ // 得到的 utc 毫秒数交给 js date 或者 dayjs 去格式化
244
+ if (date === null || date === nulls.int32)
245
+ return null;
246
+ const ms = 1000 * 3600 * 24 * date;
247
+ return timestamp2ms(ms);
248
+ }
249
+ export function date2str(date, format = 'YYYY.MM.DD') {
250
+ return (date === null || date === nulls.int32) ?
251
+ 'null'
252
+ :
253
+ dayjs(date2ms(date)).format(format);
254
+ }
255
+ export function month2ms(month) {
256
+ return (month === null || month === nulls.int32) ?
257
+ null
258
+ :
259
+ dayjs(month2str(month), 'YYYY.MM[M]').valueOf();
260
+ }
261
+ export function month2str(month) {
262
+ if (month === null || month === nulls.int32)
263
+ return 'null';
264
+ if (month < 0)
265
+ return String(month);
266
+ const _month = month % 12;
267
+ const year = Math.trunc(month / 12);
268
+ return `${String(year).padStart(4, '0')}.${String(_month + 1).padStart(2, '0')}M`;
269
+ }
270
+ export function time2ms(time) {
271
+ return (time === null || time === nulls.int32) ?
272
+ null
273
+ :
274
+ timestamp2ms(time);
275
+ }
276
+ export function time2str(time, format = 'HH:mm:ss.SSS') {
277
+ return (time === null || time === nulls.int32) ?
278
+ 'null'
279
+ :
280
+ dayjs(time2ms(time)).format(format);
281
+ }
282
+ export function minute2ms(minute) {
283
+ if (minute === null || minute === nulls.int32)
284
+ return null;
285
+ const ms = 60 * 1000 * minute;
286
+ return timestamp2ms(ms);
287
+ }
288
+ export function minute2str(minute, format = 'HH:mm[m]') {
289
+ return (minute === null || minute === nulls.int32) ?
290
+ 'null'
291
+ :
292
+ dayjs(minute2ms(minute)).format(format);
293
+ }
294
+ export function second2ms(second) {
295
+ if (second === null || second === nulls.int32)
296
+ return null;
297
+ const ms = 1000 * second;
298
+ return timestamp2ms(ms);
299
+ }
300
+ export function second2str(second, format = 'HH:mm:ss') {
301
+ return (second === null || second === nulls.int32) ?
302
+ 'null'
303
+ :
304
+ dayjs(second2ms(second)).format(format);
305
+ }
306
+ export function datetime2ms(datetime) {
307
+ if (datetime === null || datetime === nulls.int32)
308
+ return null;
309
+ const date = new Date(1000 * datetime);
310
+ return new Date(`${_datetime_formatter.format(date)}.${String(date.getUTCMilliseconds()).padStart(3, '0')}`).valueOf();
311
+ }
312
+ export function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
313
+ return (datetime === null || datetime === nulls.int32) ?
314
+ 'null'
315
+ :
316
+ dayjs(datetime2ms(datetime)).format(format);
317
+ }
318
+ /** _datetime_formatter.format 会在 date 为 Invalid Date 时抛出错误 */
319
+ export function timestamp2ms(timestamp) {
320
+ if (timestamp === null || timestamp === nulls.int64)
321
+ return null;
322
+ const date = new Date(Number(timestamp));
323
+ return new Date(`${_datetime_formatter.format(date)}.${String(date.getUTCMilliseconds()).padStart(3, '0')}`).valueOf();
324
+ }
325
+ /** format timestamp (bigint) to string
326
+ - timestamp: bigint value
327
+ - format?:
328
+ 格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSS` format string, default to `YYYY.MM.DD HH:mm:ss.SSS`
329
+ https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens */
330
+ export function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
331
+ return (timestamp === null || timestamp === nulls.int64) ?
332
+ 'null'
333
+ :
334
+ dayjs(timestamp2ms(timestamp)).format(format);
335
+ }
336
+ export function datehour2ms(datehour) {
337
+ if (datehour === null || datehour === nulls.int32)
338
+ return null;
339
+ const ms = 1000 * 3600 * datehour;
340
+ return timestamp2ms(ms);
341
+ }
342
+ export function datehour2str(datehour, format = 'YYYY.MM.DDTHH') {
343
+ if (datehour === null || datehour === nulls.int32)
344
+ return 'null';
345
+ const ms = 1000 * 3600 * datehour;
346
+ return dayjs(timestamp2ms(ms)).format(format);
347
+ }
348
+ /** parse timestamp string to bigint value
349
+ - str: timestamp string, 如果为空字符串或 'null' 会返回对应的空值 (nulls.int64)
350
+ timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
351
+ - format?:
352
+ 对应传入字符串的格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSS`
353
+ The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
354
+ https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens */
355
+ export function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
356
+ if (!str || str === 'null')
357
+ return nulls.int64;
358
+ check(str.length === format.length, t('timestamp 字符串长度必须等于格式串长度'));
359
+ const ms = dayjs(str, format).valueOf();
360
+ return BigInt(-(1000 * 60 * new Date(ms).getTimezoneOffset()) +
361
+ ms);
362
+ }
363
+ export function nanotime2ns(nanotime) {
364
+ return nanotimestamp2ns(nanotime);
365
+ }
366
+ export function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
367
+ if (nanotime === null || nanotime === nulls.int64)
368
+ return 'null';
369
+ if (nanotime < 0n)
370
+ return String(nanotime);
371
+ const i_second_start = format.indexOf('ss');
372
+ check(i_second_start !== -1, t('格式串必须包含秒的格式 (ss)'));
373
+ const i_second_end = i_second_start + 2;
374
+ const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
375
+ check(i_nanosecond_start !== -1, t('格式串必须包含纳秒的格式 (SSSSSSSSS)'));
376
+ const ms = Number(nanotime) / 1000000;
377
+ return (dayjs(timestamp2ms(ms)).format(format.slice(0, i_second_end)) +
378
+ format.slice(i_second_end, i_nanosecond_start) +
379
+ String(nanotime % 1000000000n).padStart(9, '0'));
380
+ }
381
+ export function nanotimestamp2ns(nanotimestamp) {
382
+ if (nanotimestamp === null || nanotimestamp === nulls.int64)
383
+ return null;
384
+ const date = new Date(Number(nanotimestamp / 1000000n));
385
+ return BigInt(new Date(`${_datetime_formatter.format(date)}.${String(date.getUTCMilliseconds()).padStart(3, '0')}`).valueOf()) * 1000000n + nanotimestamp % 1000000n;
386
+ }
387
+ /** format nanotimestamp value (bigint) to string
388
+ - nanotimestamp: bigint value
389
+ - format?:
390
+ 格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSSSSSSSS` format string, default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
391
+ 秒的格式为 ss (必须包含); 纳秒的格式为 SSSSSSSSS (必须包含) Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
392
+ https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
393
+ */
394
+ export function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
395
+ // tests:
396
+ // nanotimestamp2str(0n)
397
+ // nanotimestamp2str(-1n)
398
+ // nanotimestamp2str(-9_9999_9999n)
399
+ // nanotimestamp2str(-10_0000_0000n)
400
+ // nanotimestamp2str(-10_0000_0001n)
401
+ if (nanotimestamp === null || nanotimestamp === nulls.int64)
402
+ return 'null';
403
+ const i_second_start = format.indexOf('ss');
404
+ check(i_second_start !== -1, t('格式串必须包含秒的格式 (ss)'));
405
+ const i_second_end = i_second_start + 2;
406
+ const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
407
+ check(i_nanosecond_start !== -1, t('格式串必须包含纳秒的格式 (SSSSSSSSS)'));
408
+ const remainder = nanotimestamp % 1000000000n;
409
+ const borrow = remainder < 0n;
410
+ const ms = Number((nanotimestamp - remainder + (borrow ? -1000000000n : 0n)) / 1000000n);
411
+ return (dayjs(_datetime_formatter.format(new Date(ms))).format(format.slice(0, i_second_end)) +
412
+ format.slice(i_second_end, i_nanosecond_start) +
413
+ String(borrow ?
414
+ (remainder + 1000000000n) % 1000000000n
415
+ :
416
+ remainder).padStart(9, '0'));
417
+ }
418
+ /** parse nano timestamp string to bigint value
419
+ - str: nano timestamp string, 如果为空字符串或 'null' 会返回对应的空值 (nulls.int64)
420
+ nano timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
421
+ - format?:
422
+ 对应传入字符串的格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
423
+ 秒的格式为 ss (必须包含); 纳秒的格式为 SSSSSSSSS (必须包含)
424
+ https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
425
+ The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
426
+ Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included) */
427
+ export function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
428
+ if (!str || str === 'null')
429
+ return nulls.int64;
430
+ check(str.length === format.length, t('nanotimestamp 字符串长度必须等于格式串长度'));
431
+ const i_second_start = format.indexOf('ss');
432
+ check(i_second_start !== -1, t('格式串必须包含秒的格式 (ss)'));
433
+ const i_second_end = i_second_start + 2;
434
+ const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
435
+ check(i_nanosecond_start !== -1, t('格式串必须包含纳秒的格式 (SSSSSSSSS)'));
436
+ const ms = dayjs(str.slice(0, i_second_end), format.slice(0, i_second_end)).valueOf();
437
+ return (BigInt(-(1000 * 60 * new Date(ms).getTimezoneOffset()) +
438
+ ms) * 1000000n
439
+ +
440
+ BigInt(str.slice(i_nanosecond_start, i_nanosecond_start + 9)));
441
+ }
442
+ export function ipaddr2str(buffer, le = true, ipv6) {
443
+ let buf = buffer;
444
+ if (le)
445
+ buf = buffer.slice().reverse();
446
+ const i_non_zero = buf.findIndex(x => x !== 0);
447
+ if (ipv6 ||
448
+ i_non_zero !== -1 && i_non_zero < 12) // ipv6
449
+ return buf2ipaddr([...buf]).toString();
450
+ else // ipv4
451
+ return buf.subarray(12).join('.');
452
+ }
453
+ export function uuid2str(buffer, le = true) {
454
+ const str = int1282str(buffer, le);
455
+ return `${str.slice(0, 8)}-${str.slice(8, 12)}-${str.slice(12, 16)}-${str.slice(16, 20)}-${str.slice(20)}`;
456
+ }
457
+ export function int1282str(buffer, le = true) {
458
+ let buf = buffer;
459
+ if (le)
460
+ buf = buffer.slice().reverse();
461
+ return [...buf].map(x => x.toString(16)
462
+ .padStart(2, '0')).join('');
463
+ }
464
+ export const winsize = 10000;
465
+ //# sourceMappingURL=common.js.map
package/common.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,KAAK,EAAc,MAAM,OAAO,CAAA;AACpD,OAAO,sBAAsB,MAAM,mCAAmC,CAAA;AACtE,KAAK,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAA;AAEpC,OAAO,4BAA4B,CAAA;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAE9C,OAAO,QAAQ,MAAM,WAAW,CAAA;AAChC,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,QAAQ,CAAA;AAE9C,OAAO,EAAE,CAAC,EAAE,MAAM,iBAAiB,CAAA;AAGnC,MAAM,CAAC,MAAM,KAAK,GAAG;IACjB,IAAI,EAAE,CAAC,IAAI,EAAG,OAAO;IACrB,KAAK,EAAE,CAAC,OAAO,EAAG,SAAS;IAC3B,KAAK,EAAE,CAAC,aAAa,EAAG,gBAAgB;IACxC,KAAK,EAAE,CAAC,mBAA0B,EAAG,2BAA2B;IAChE,MAAM,EAAE,CAAC,mCAAkD,EAAG,oDAAoD;IAClH,OAAO,EAAE,CAAC,sBAAsB;IAEhC,wBAAwB;IACxB,MAAM,EAAE,CAAC,MAAM,CAAC,SAAS;IAEzB,OAAO,EAAE,UAAU,CAAC,IAAI,CACpB,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CACxB;CACK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 'dayjs'\nimport DayjsCustomParseFormat from 'dayjs/plugin/customParseFormat.js'\ndayjs.extend(DayjsCustomParseFormat)\n\nimport 'xshell/prototype.common.js'\nimport { check } from 'xshell/utils.common.js'\n\nimport ipaddrjs from 'ipaddr.js'\nconst { fromByteArray: buf2ipaddr } = ipaddrjs\n\nimport { t } from './i18n/index.ts'\n\n\nexport const nulls = {\n int8: -0x80, // -128\n int16: -0x80_00, // -32768\n int32: -0x80_00_00_00, // -21_4748_3648\n int64: -0x80_00_00_00_00_00_00_00n, // -922_3372_0368_5477_5808\n int128: -0x80_00_00_00_00_00_00_00_00_00_00_00_00_00_00_00n, // -170_1411_8346_0469_2317_3168_7303_7158_8410_5728\n float32: -3.4028234663852886e+38,\n \n /** -Number.MAX_VALUE */\n double: -Number.MAX_VALUE,\n \n bytes16: Uint8Array.from(\n new Array(16).fill(0)\n )\n} as const\n\n\nexport enum DdbForm {\n scalar = 0,\n vector = 1,\n pair = 2,\n matrix = 3,\n set = 4,\n dict = 5,\n table = 6,\n chart = 7,\n \n /** 节点内部通信可能会使用,调用函数执行脚本一般不会返回这种类型 */\n chunk = 8,\n \n /** sysobj */\n object = 9,\n tensor = 10,\n}\n\n\n/** DolphinDB DataType \n 对应的 array vector 类型为 64 + 基本类型\n 对应的 extended 类型为 128 + 基本类型 */\nexport enum DdbType {\n void = 0,\n bool = 1,\n char = 2,\n short = 3,\n int = 4,\n long = 5,\n date = 6,\n month = 7,\n time = 8,\n minute = 9,\n second = 10,\n datetime = 11,\n timestamp = 12,\n nanotime = 13,\n nanotimestamp = 14,\n float = 15,\n double = 16,\n symbol = 17,\n string = 18,\n uuid = 19,\n functiondef = 20,\n handle = 21,\n code = 22,\n datasource = 23,\n resource = 24,\n any = 25,\n compressed = 26,\n dict = 27,\n datehour = 28,\n ipaddr = 30,\n int128 = 31,\n blob = 32,\n complex = 34,\n point = 35,\n duration = 36,\n \n decimal32 = 37,\n decimal64 = 38,\n decimal128 = 39,\n \n object = 40,\n iotany = 41,\n \n symbol_extended = 145, // 128 + DdbType.symbol\n}\n\n\nexport enum DdbFunctionType {\n SystemFunc = 0,\n SystemProc = 1,\n OperatorFunc = 2,\n UserDefinedFunc = 3,\n PartialFunc = 4,\n DynamicFunc = 5,\n PiecewiseFunc = 6,\n JitFunc = 7,\n JitPartialFunc = 8,\n}\n\n\nexport enum DdbDurationUnit {\n ns = 0,\n us = 1,\n ms = 2,\n s = 3,\n m = 4,\n H = 5,\n d = 6,\n w = 7,\n M = 8,\n y = 9,\n B = 10\n}\n\n\nexport enum DdbChartType {\n area = 0,\n bar = 1,\n column = 2,\n histogram = 3,\n line = 4,\n pie = 5,\n scatter = 6,\n trend = 7,\n kline = 8,\n}\n\n\n// server 实现中区分了 0: NULL (nothing), 1: NULL (null), 2: DFLT (default)\n// Void::serialize()\n// (isNothing() ? 0 : 1) + (isDefault_ ? 2 : 0);\nexport enum DdbVoidType {\n undefined = 0,\n null = 1,\n default = 2\n}\n\n\nexport interface DdbFunctionDefValue {\n type: DdbFunctionType\n name: string\n}\n\nexport interface DdbDurationValue {\n unit: DdbDurationUnit\n \n /** int32 */\n data: number\n}\n\n\nexport interface DdbDecimal32Value {\n /** int32, data 需要除以 10^scale 得到原值 */\n scale: number\n \n /** int32, 空值为 null ddb null is js null */\n data: number | null\n}\n\nexport interface DdbDecimal64Value {\n /** int32, data 需要除以 10^scale 得到原值 */\n scale: number\n \n /** int64, 空值为 null empty value is null */\n data: bigint | null\n}\n\nexport interface DdbDecimal128Value {\n /** int32, data 需要除以 10^scale 得到原值 */\n scale: number\n \n /** int128, 空值为 null empty value is null */\n data: bigint | null\n}\n\nexport interface DdbDecimal32VectorValue {\n scale: number\n \n data: Int32Array\n}\n\nexport interface DdbDecimal64VectorValue {\n scale: number\n \n data: BigInt64Array\n}\n\n\nexport type DdbDurationVectorValue = DdbDurationValue[]\n\n\nexport interface DdbSymbolExtendedValue {\n base_id: number\n base: string[]\n data: Uint32Array\n}\n\n\nexport const dictables = new Set([DdbType.any, DdbType.string, DdbType.double, DdbType.float, DdbType.int, DdbType.long])\n\n\n/** 工具,取得某个 DdbType 的字节数 */\nexport const ddb_tensor_bytes: Record<\n DdbType.bool | DdbType.char | DdbType.short | DdbType.int | DdbType.long | DdbType.float | DdbType.double, \n number\n> = {\n [DdbType.bool]: 1,\n [DdbType.char]: 1,\n [DdbType.short]: 2,\n [DdbType.int]: 4,\n [DdbType.long]: 8,\n [DdbType.float]: 4,\n [DdbType.double]: 8,\n}\n\n\nexport type TensorElem = TensorData | boolean | number | bigint | null | string\nexport interface TensorData extends Array<TensorElem> { }\n\nexport interface DdbTensorMetadata {\n /** Tensor 的元素的数据类型 */\n data_type: DdbType\n \n /** Tensor 类型 */\n tensor_type: number\n \n /** 设备类型 */\n device_type: number\n \n /** Tensor Flags */\n tensor_flags: number\n \n /** 维度 */\n dimensions: number\n \n /** shape, shape[i] 表示第 i 个维度的 size */\n shape: number[]\n \n /** strides, strides[i] 表示在第 i 个维度,一个元素与下一个元素的距离 */\n strides: number[]\n \n /** 保留值 */\n preserve_value: bigint\n \n /** 元素个数 */\n elem_count: number\n}\n\nexport interface DdbTensorValue extends DdbTensorMetadata {\n /** 数据 */\n data: Uint8Array\n}\n\n\n/** DdbObj.data() 返回的表格对象 */\nexport interface DdbTableData <TRow = any> {\n /** 表名 */\n name: string\n \n /** 每一列的名称 */\n columns: string[]\n \n /** 每一列的原始 ddb 数据类型 */\n types: DdbType[]\n \n /** 表格数据,每一行的对象组成的数组 */\n data: TRow[]\n}\n\n/** DdbObj.data() 返回的 Tensor 对象 */\nexport interface DdbTensorData extends DdbTensorMetadata {\n /** 数据 */\n data: TensorData\n}\n\n\n/** DdbObj.data() 返回的矩阵对象 */\nexport interface DdbMatrixData {\n /** 原始数据类型 */\n type: DdbType\n \n /** 行数 */\n nrows: number\n \n /** 列数 */\n ncolumns: number\n \n /** 行名称 */\n rows?: any[]\n \n /** 列名称 */\n columns?: any[]\n \n /** 数据, data[0][1] 为第 0 行第 1 列数据 */\n data: any[][]\n}\n\n\nexport type DdbScalarValue = \n null | boolean | number | bigint | string |\n Uint8Array | // uuid, ipaddr, int128, blob\n [number, number] | // complex, point\n DdbFunctionDefValue |\n DdbDurationValue | \n DdbDecimal32Value | DdbDecimal64Value | DdbDecimal128Value\n\n\nexport type IotVectorItemValue = [number | string | bigint | boolean][]\n\n\n/** 根据 DdbType 获取其名称,array vector type 自动在后面加上 [] */\nexport function get_type_name (type: DdbType) {\n return `${DdbType[type] || type}${ 64 <= type && type < 128 ? '[]' : '' }`\n}\n\n\nexport function is_decimal_type (type: DdbType) {\n return type === DdbType.decimal32 || type === DdbType.decimal64 || type === DdbType.decimal128\n}\n\n\nexport function is_decimal_null_value (type: DdbType, value: number | bigint) {\n return (\n (value === nulls.int128 && type === DdbType.decimal128) ||\n (value === nulls.int64 && type === DdbType.decimal64) ||\n (value === nulls.int32 && type === DdbType.decimal32)\n )\n}\n\nexport function get_duration_unit (code: number) {\n let str = String.fromCharCode((code >> 24) & 0xff)\n str += String.fromCharCode((code >> 16) & 0xff)\n str += String.fromCharCode((code >> 8) & 0xff)\n str += String.fromCharCode(code & 0xff)\n return str\n}\n\n\nexport function get_ddb_time_value (\n classname: 'DdbDateTime' | 'DdbTimeStamp' | 'DdbNanoTimeStamp' | 'DdbDate',\n value: null | number | string | Date | Dayjs,\n): number | bigint | null {\n if (value === null)\n return null\n \n if (classname === 'DdbNanoTimeStamp' && typeof value === 'string')\n return str2nanotimestamp(value)\n \n let date: Date\n \n if (value === undefined)\n date = new Date()\n else if (typeof value === 'number' || typeof value === 'string')\n date = new Date(value)\n else if (value instanceof Date)\n date = value\n else if (dayjs.isDayjs(value))\n date = new Date(value.valueOf())\n else\n throw new Error(t('value 不能转换为 {{classname}}', { classname }))\n \n switch (classname) {\n case 'DdbDateTime':\n return (date.getTime() - 1000 * 60 * date.getTimezoneOffset()) / 1000\n \n case 'DdbTimeStamp':\n return BigInt(date.getTime() - 1000 * 60 * date.getTimezoneOffset())\n \n case 'DdbNanoTimeStamp':\n return BigInt(date.getTime() - 1000 * 60 * date.getTimezoneOffset()) * 1000000n\n \n case 'DdbDate':\n return Math.floor((date.getTime() - 1000 * 60 * date.getTimezoneOffset()) / (1000 * 3600 * 24))\n }\n}\n\n\n// DataView Extends for bigint 128 operations\nexport function get_big_uint_128 (dataview: DataView, byte_offset: number, le = true) {\n let cursor = byte_offset + (le ? 15 : 0)\n const end = byte_offset + (le ? -1 : 16)\n const step = le ? -1 : 1\n let value = 0n\n \n while (cursor !== end) {\n value = value << 8n | BigInt(dataview.getUint8(cursor))\n cursor += step\n }\n \n return value\n}\n\nexport function get_big_int_128 (dataview: DataView, byte_offset: number, le = true) {\n return BigInt.asIntN(128, get_big_uint_128(dataview, byte_offset, le))\n}\n\n\nexport function set_big_uint_128 (dataView: DataView, byte_offset: number, value: bigint, le = true) {\n let cursor = byte_offset + (le ? 0 : 15)\n const end = byte_offset + (le ? 16 : -1)\n const step = le ? 1 : -1\n \n while (cursor !== end) {\n dataView.setUint8(cursor, Number(value & 0xffn))\n value = value >> 8n\n cursor += step\n }\n}\n\nexport function set_big_int_128 (dataview: DataView, byte_offset: number, value: bigint, le = true) {\n set_big_uint_128(dataview, byte_offset, value, le)\n}\n\nexport function generate_array_type (baseType: string, dimensions: number[]): string {\n let result = baseType\n dimensions.forEach(dimension => {\n result += `[${dimension}]`\n })\n return result\n}\n\n\n// 大端\n// const dataBE = new ArrayBuffer(16)\n// const dataViewBE = new DataView(dataBE)\n// set_big_int_128(dataViewBE, 0, -34355n, false)\n// console.log(dataViewBE.buffer)\n// const bigInt128BE = get_big_int_128(dataViewBE, 0, false)\n// const bigUint128BE = get_big_uint_128(dataViewBE, 0, false)\n// console.log(bigInt128BE.toString(), bigUint128BE.toString())\n\n// 小端\n// const dataLE = new ArrayBuffer(16)\n// const dataViewLE = new DataView(dataLE)\n// set_big_int_128(dataViewLE, 0, -34355n, true)\n// console.log(dataViewLE.buffer)\n// const bigInt128LE = get_big_int_128(dataViewLE, 0, true)\n// const bigUint128LE = get_big_uint_128(dataViewLE, 0, true)\n// console.log(bigInt128LE.toString(), bigUint128LE.toString())\n\n\n/** 用来处理时差 To deal with jet lag */\nlet _datetime_formatter = new Intl.DateTimeFormat('zh-CN', { dateStyle: 'short', timeStyle: 'medium', timeZone: 'UTC', hour12: false })\n\n\nexport function date2ms (date: number | null) {\n // 将 server 的本地时间 (以 ms 为单位,1970.01.01 00:00:00 作为零点) 作为 UTC-0 格式化为字符串,然后根据本地的时区解析这个字符串转换为 UTC-8\n // 本地的时区与实际的时间值相关,getTimezoneOffset() 可能会受到夏令时 (DST) 的影响,不能使用\n // 得到的 utc 毫秒数交给 js date 或者 dayjs 去格式化\n \n if (date === null || date === nulls.int32)\n return null\n \n const ms = 1000 * 3600 * 24 * date\n \n return timestamp2ms(ms)\n}\n\nexport function date2str (date: number | null, format = 'YYYY.MM.DD') {\n return (date === null || date === nulls.int32) ? \n 'null'\n :\n dayjs(\n date2ms(date)\n ).format(format)\n}\n\nexport function month2ms (month: number | null): number | null {\n return (month === null || month === nulls.int32) ?\n null\n :\n dayjs(\n month2str(month),\n 'YYYY.MM[M]'\n ).valueOf()\n}\n\nexport function month2str (month: number | null) {\n if (month === null || month === nulls.int32)\n return 'null'\n \n if (month < 0)\n return String(month)\n \n const _month = month % 12\n const year = Math.trunc(month / 12)\n return `${String(year).padStart(4, '0')}.${String(_month + 1).padStart(2, '0')}M`\n}\n\nexport function time2ms (time: number | null): number | null {\n return (time === null || time === nulls.int32) ?\n null\n :\n timestamp2ms(time)\n}\n\nexport function time2str (time: number | null, format = 'HH:mm:ss.SSS') {\n return (time === null || time === nulls.int32) ?\n 'null'\n :\n dayjs(\n time2ms(time)\n ).format(format)\n}\n\nexport function minute2ms (minute: number | null): number | null {\n if (minute === null || minute === nulls.int32)\n return null\n \n const ms = 60 * 1000 * minute\n \n return timestamp2ms(ms)\n}\n\nexport function minute2str (minute: number | null, format = 'HH:mm[m]') {\n return (minute === null || minute === nulls.int32) ?\n 'null'\n :\n dayjs(\n minute2ms(minute)\n ).format(format)\n}\n\nexport function second2ms (second: number | null): number | null {\n if (second === null || second === nulls.int32)\n return null\n \n const ms = 1000 * second\n \n return timestamp2ms(ms)\n}\n\nexport function second2str (second: number | null, format = 'HH:mm:ss') {\n return (second === null || second === nulls.int32) ?\n 'null'\n :\n dayjs(\n second2ms(second)\n ).format(format)\n}\n\nexport function datetime2ms (datetime: number | null): number | null {\n if (datetime === null || datetime === nulls.int32)\n return null\n \n const date = new Date(1000 * datetime)\n return new Date(`${_datetime_formatter.format(date)}.${String(date.getUTCMilliseconds()).padStart(3, '0')}`).valueOf()\n}\n\nexport function datetime2str (datetime: number | null, format = 'YYYY.MM.DD HH:mm:ss') {\n return (datetime === null || datetime === nulls.int32) ?\n 'null'\n :\n dayjs(\n datetime2ms(datetime)\n ).format(format)\n}\n\n/** _datetime_formatter.format 会在 date 为 Invalid Date 时抛出错误 */\nexport function timestamp2ms (timestamp: bigint | number | null): number | null {\n if (timestamp === null || timestamp === nulls.int64)\n return null\n \n const date = new Date(Number(timestamp))\n return new Date(`${_datetime_formatter.format(date)}.${String(date.getUTCMilliseconds()).padStart(3, '0')}`).valueOf()\n}\n\n\n/** format timestamp (bigint) to string \n - timestamp: bigint value\n - format?: \n 格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSS` format string, default to `YYYY.MM.DD HH:mm:ss.SSS` \n https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens */\nexport function timestamp2str (timestamp: bigint | null, format = 'YYYY.MM.DD HH:mm:ss.SSS') {\n return (timestamp === null || timestamp === nulls.int64) ?\n 'null'\n :\n dayjs(\n timestamp2ms(timestamp)\n ).format(format)\n}\n\nexport function datehour2ms (datehour: number | null): number | null {\n if (datehour === null || datehour === nulls.int32)\n return null\n \n const ms = 1000 * 3600 * datehour\n \n return timestamp2ms(ms)\n}\n\nexport function datehour2str (datehour: number | null, format = 'YYYY.MM.DDTHH') {\n if (datehour === null || datehour === nulls.int32)\n return 'null'\n \n const ms = 1000 * 3600 * datehour\n \n return dayjs(\n timestamp2ms(ms)\n ).format(format)\n}\n\n\n/** parse timestamp string to bigint value \n - str: timestamp string, 如果为空字符串或 'null' 会返回对应的空值 (nulls.int64) \n timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)\n - format?: \n 对应传入字符串的格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSS` \n The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS` \n https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens */\nexport function str2timestamp (str: string, format = 'YYYY.MM.DD HH:mm:ss.SSS') {\n if (!str || str === 'null')\n return nulls.int64\n \n check(str.length === format.length, t('timestamp 字符串长度必须等于格式串长度'))\n \n const ms = dayjs(str, format).valueOf()\n \n return BigInt(\n -(1000 * 60 * new Date(ms).getTimezoneOffset()) +\n ms\n )\n}\n\nexport function nanotime2ns (nanotime: bigint | null): bigint | null {\n return nanotimestamp2ns(nanotime)\n}\n\nexport function nanotime2str (nanotime: bigint | null, format = 'HH:mm:ss.SSSSSSSSS') {\n if (nanotime === null || nanotime === nulls.int64)\n return 'null'\n \n if (nanotime < 0n)\n return String(nanotime)\n \n const i_second_start = format.indexOf('ss')\n check(i_second_start !== -1, t('格式串必须包含秒的格式 (ss)'))\n \n const i_second_end = i_second_start + 2\n \n const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end)\n check(i_nanosecond_start !== -1, t('格式串必须包含纳秒的格式 (SSSSSSSSS)'))\n \n const ms = Number(nanotime) / 1000000\n \n return (\n dayjs(\n timestamp2ms(ms)\n ).format(\n format.slice(0, i_second_end)\n ) + \n format.slice(i_second_end, i_nanosecond_start) + \n String(nanotime % 1000000000n).padStart(9, '0')\n )\n}\n\nexport function nanotimestamp2ns (nanotimestamp: bigint | null): bigint | null {\n if (nanotimestamp === null || nanotimestamp === nulls.int64)\n return null\n \n const date = new Date(Number(nanotimestamp / 1000000n))\n return BigInt(\n new Date(`${_datetime_formatter.format(date)}.${String(date.getUTCMilliseconds()).padStart(3, '0')}`).valueOf()\n ) * 1000000n + nanotimestamp % 1000000n\n}\n\n/** format nanotimestamp value (bigint) to string \n - nanotimestamp: bigint value\n - format?: \n 格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSSSSSSSS` format string, default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS` \n 秒的格式为 ss (必须包含); 纳秒的格式为 SSSSSSSSS (必须包含) Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included) \n https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens\n*/\nexport function nanotimestamp2str (nanotimestamp: bigint | null, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {\n // tests:\n // nanotimestamp2str(0n)\n // nanotimestamp2str(-1n)\n // nanotimestamp2str(-9_9999_9999n)\n // nanotimestamp2str(-10_0000_0000n)\n // nanotimestamp2str(-10_0000_0001n)\n \n if (nanotimestamp === null || nanotimestamp === nulls.int64)\n return 'null'\n \n const i_second_start = format.indexOf('ss')\n check(i_second_start !== -1, t('格式串必须包含秒的格式 (ss)'))\n \n const i_second_end = i_second_start + 2\n \n const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end)\n check(i_nanosecond_start !== -1, t('格式串必须包含纳秒的格式 (SSSSSSSSS)'))\n \n const remainder = nanotimestamp % 1000000000n\n const borrow = remainder < 0n\n \n const ms = Number((nanotimestamp - remainder + (borrow ? -1000000000n : 0n)) / 1000000n)\n \n return (\n dayjs(\n _datetime_formatter.format(new Date(ms))\n ).format(\n format.slice(0, i_second_end)\n ) + \n format.slice(i_second_end, i_nanosecond_start) + \n String(\n borrow ?\n (remainder + 1000000000n) % 1000000000n\n :\n remainder\n ).padStart(9, '0')\n )\n}\n\n/** parse nano timestamp string to bigint value \n - str: nano timestamp string, 如果为空字符串或 'null' 会返回对应的空值 (nulls.int64) \n nano timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)\n - format?: \n 对应传入字符串的格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSSSSSSSS` \n 秒的格式为 ss (必须包含); 纳秒的格式为 SSSSSSSSS (必须包含) \n https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens \n The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS` \n Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included) */\nexport function str2nanotimestamp (str: string, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {\n if (!str || str === 'null')\n return nulls.int64\n \n check(str.length === format.length, t('nanotimestamp 字符串长度必须等于格式串长度'))\n \n const i_second_start = format.indexOf('ss')\n check(i_second_start !== -1, t('格式串必须包含秒的格式 (ss)'))\n \n const i_second_end = i_second_start + 2\n \n const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end)\n check(i_nanosecond_start !== -1, t('格式串必须包含纳秒的格式 (SSSSSSSSS)'))\n \n const ms = dayjs(\n str.slice(0, i_second_end),\n format.slice(0, i_second_end)\n ).valueOf()\n \n return (\n BigInt(\n -(1000 * 60 * new Date(ms).getTimezoneOffset()) +\n ms\n ) * 1000000n\n +\n BigInt(\n str.slice(i_nanosecond_start, i_nanosecond_start + 9)\n )\n )\n}\n\n\nexport function ipaddr2str (buffer: Uint8Array, le = true, ipv6?: boolean) {\n let buf = buffer\n \n if (le)\n buf = buffer.slice().reverse()\n \n const i_non_zero = buf.findIndex(x => x !== 0)\n \n if (\n ipv6 || \n i_non_zero !== -1 && i_non_zero < 12\n ) // ipv6\n return buf2ipaddr([...buf]).toString()\n else // ipv4\n return buf.subarray(12).join('.')\n}\n\nexport function uuid2str (buffer: Uint8Array, le = true) {\n const str = int1282str(buffer, le)\n return `${str.slice(0, 8)}-${str.slice(8, 12)}-${str.slice(12, 16)}-${str.slice(16, 20)}-${str.slice(20)}`\n}\n\nexport function int1282str (buffer: Uint8Array, le = true) {\n let buf = buffer\n \n if (le)\n buf = buffer.slice().reverse()\n \n return [...buf].map(x => \n x.toString(16)\n .padStart(2, '0')\n ).join('')\n}\n\n\nexport interface ConvertOptions {\n /** `'string'` blob 转换格式 */\n blob?: 'string' | 'binary'\n \n /** `'string'` char 转换格式: string 转为 string[],number 转为 number[] */\n char?: 'string' | 'number'\n \n /** `'strings'` char vector 转换格式: strings 转为 string[], binary 转为 Uint8Array */\n chars?: 'strings' | 'binary'\n \n /** `'ms'` timestamp 类型转换为字符串表示时显示到秒还是毫秒 */\n timestamp?: 's' | 'ms'\n}\n\n\nexport const winsize = 10000 as const\n\nexport type DdbRpcType = 'script' | 'function' | 'variable' | 'connect'\n"]}
package/i18n/dict.json CHANGED
@@ -109,5 +109,8 @@
109
109
  },
110
110
  "value 不能转换为 {{classname}}": {
111
111
  "en": "value cannot be converted to {{classname}}"
112
+ },
113
+ "DDB.define 方法传入的 definition 不符合函数定义格式": {
114
+ "en": "The definition passed in by the DDB.define method does not conform to the function definition format"
112
115
  }
113
116
  }