dolphindb 3.0.205 → 3.0.209
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 +8 -7
- package/browser.js +47 -19
- package/browser.js.map +1 -1
- package/i18n/dict.json +3 -0
- package/index.d.ts +8 -7
- package/index.js +47 -19
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/test.js.map +1 -1
package/i18n/dict.json
CHANGED
package/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { InspectOptions as UtilInspectOptions } from 'util';
|
|
2
|
+
import { type Dayjs } from 'dayjs';
|
|
2
3
|
import { inspect, Lock, type WebSocket, type WebSocketConnectionError } from 'xshell';
|
|
3
4
|
export declare const nulls: {
|
|
4
5
|
readonly int8: -128;
|
|
@@ -406,7 +407,7 @@ export interface ConvertOptions {
|
|
|
406
407
|
/** `'ms'` timestamp 类型转换为字符串表示时显示到秒还是毫秒 */
|
|
407
408
|
timestamp?: 's' | 'ms';
|
|
408
409
|
}
|
|
409
|
-
export declare function convert(type: DdbType, value: DdbValue, le: boolean, { blob, char, timestamp }?: ConvertOptions): string | number | bigint | boolean |
|
|
410
|
+
export declare function convert(type: DdbType, value: DdbValue, le: boolean, { blob, char, timestamp }?: ConvertOptions): string | number | bigint | boolean | number[] | string[] | Uint8Array<ArrayBufferLike> | DdbFunctionDefValue | DdbDurationValue | DdbDecimal32Value | DdbDecimal64Value | Int8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | Float32Array<ArrayBufferLike> | Float64Array<ArrayBufferLike> | BigInt64Array<ArrayBufferLike> | BigInt128Array | Uint8Array<ArrayBufferLike>[] | DdbObj<DdbValue>[] | IotVectorItemValue | DdbSymbolExtendedValue | DdbArrayVectorValue | DdbDecimal32VectorValue | DdbDecimal64VectorValue | DdbDecimal128VectorValue | DdbDurationVectorValue | DdbMatrixValue | DdbChartValue | DdbTensorValue;
|
|
410
411
|
/** 转换一个向量到 js 原生数组 */
|
|
411
412
|
export declare function converts(type: DdbType, value: DdbVectorValue, rows: number, le: boolean, options?: ConvertOptions): any[] | Uint8Array;
|
|
412
413
|
export declare class DdbVoid extends DdbObj<undefined> {
|
|
@@ -431,16 +432,16 @@ export declare class DdbDouble extends DdbObj<number> {
|
|
|
431
432
|
constructor(value: number | null);
|
|
432
433
|
}
|
|
433
434
|
export declare class DdbDateTime extends DdbObj<number> {
|
|
434
|
-
constructor(value
|
|
435
|
+
constructor(value?: null | number | string | Date | Dayjs);
|
|
435
436
|
}
|
|
436
437
|
export declare class DdbTimeStamp extends DdbObj<bigint> {
|
|
437
|
-
|
|
438
|
-
new DdbTimeStamp(new Date().getTime())
|
|
439
|
-
new DdbTimeStamp(dayjs().valueOf()) */
|
|
440
|
-
constructor(value?: bigint | null | number);
|
|
438
|
+
constructor(value?: null | number | string | Date | Dayjs);
|
|
441
439
|
}
|
|
442
440
|
export declare class DdbNanoTimeStamp extends DdbObj<bigint> {
|
|
443
|
-
constructor(value
|
|
441
|
+
constructor(value?: null | number | string | Date | Dayjs);
|
|
442
|
+
}
|
|
443
|
+
export declare class DdbDate extends DdbObj<number> {
|
|
444
|
+
constructor(value?: null | number | string | Date | Dayjs);
|
|
444
445
|
}
|
|
445
446
|
export declare class DdbBlob extends DdbObj<Uint8Array> {
|
|
446
447
|
constructor(value: Uint8Array | ArrayBuffer);
|
package/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import dayjs from 'dayjs';
|
|
1
|
+
import { default as dayjs } from 'dayjs';
|
|
2
2
|
import DayjsCustomParseFormat from 'dayjs/plugin/customParseFormat.js';
|
|
3
3
|
dayjs.extend(DayjsCustomParseFormat);
|
|
4
4
|
import ipaddrjs from 'ipaddr.js';
|
|
5
5
|
const { fromByteArray: buf2ipaddr } = ipaddrjs;
|
|
6
|
-
import { concat, assert, inspect, typed_array_to_buffer, connect_websocket, Lock, genid, seq, zip_object, WebSocketOpen, WebSocketClosed, WebSocketClosing, decode, delay } from 'xshell';
|
|
6
|
+
import { concat, assert, inspect, typed_array_to_buffer, connect_websocket, Lock, genid, seq, zip_object, WebSocketOpen, WebSocketClosed, WebSocketClosing, decode, delay, check } from 'xshell';
|
|
7
7
|
import { t } from "./i18n/index.js";
|
|
8
8
|
export const nulls = {
|
|
9
9
|
int8: -0x80, // -128
|
|
@@ -2195,24 +2195,16 @@ export class DdbDateTime extends DdbObj {
|
|
|
2195
2195
|
super({
|
|
2196
2196
|
form: DdbForm.scalar,
|
|
2197
2197
|
type: DdbType.datetime,
|
|
2198
|
-
value
|
|
2198
|
+
value: get_ddb_time_value('DdbDateTime', value)
|
|
2199
2199
|
});
|
|
2200
2200
|
}
|
|
2201
2201
|
}
|
|
2202
2202
|
export class DdbTimeStamp extends DdbObj {
|
|
2203
|
-
/** @example
|
|
2204
|
-
new DdbTimeStamp(new Date().getTime())
|
|
2205
|
-
new DdbTimeStamp(dayjs().valueOf()) */
|
|
2206
2203
|
constructor(value) {
|
|
2207
|
-
if (value === undefined)
|
|
2208
|
-
value = new Date().getTime();
|
|
2209
|
-
if (typeof value === 'number')
|
|
2210
|
-
value = BigInt(-(1000 * 60 * new Date(value).getTimezoneOffset()) +
|
|
2211
|
-
value);
|
|
2212
2204
|
super({
|
|
2213
2205
|
form: DdbForm.scalar,
|
|
2214
2206
|
type: DdbType.timestamp,
|
|
2215
|
-
value
|
|
2207
|
+
value: get_ddb_time_value('DdbTimeStamp', value)
|
|
2216
2208
|
});
|
|
2217
2209
|
}
|
|
2218
2210
|
}
|
|
@@ -2221,10 +2213,46 @@ export class DdbNanoTimeStamp extends DdbObj {
|
|
|
2221
2213
|
super({
|
|
2222
2214
|
form: DdbForm.scalar,
|
|
2223
2215
|
type: DdbType.nanotimestamp,
|
|
2224
|
-
value
|
|
2216
|
+
value: get_ddb_time_value('DdbNanoTimeStamp', value)
|
|
2225
2217
|
});
|
|
2226
2218
|
}
|
|
2227
2219
|
}
|
|
2220
|
+
export class DdbDate extends DdbObj {
|
|
2221
|
+
constructor(value) {
|
|
2222
|
+
super({
|
|
2223
|
+
form: DdbForm.scalar,
|
|
2224
|
+
type: DdbType.date,
|
|
2225
|
+
value: get_ddb_time_value('DdbDate', value)
|
|
2226
|
+
});
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
function get_ddb_time_value(classname, value) {
|
|
2230
|
+
if (value === null)
|
|
2231
|
+
return null;
|
|
2232
|
+
if (classname === 'DdbNanoTimeStamp' && typeof value === 'string')
|
|
2233
|
+
return str2nanotimestamp(value);
|
|
2234
|
+
let date;
|
|
2235
|
+
if (value === undefined)
|
|
2236
|
+
date = new Date();
|
|
2237
|
+
else if (typeof value === 'number' || typeof value === 'string')
|
|
2238
|
+
date = new Date(value);
|
|
2239
|
+
else if (value instanceof Date)
|
|
2240
|
+
date = value;
|
|
2241
|
+
else if (dayjs.isDayjs(value))
|
|
2242
|
+
date = new Date(value.valueOf());
|
|
2243
|
+
else
|
|
2244
|
+
throw new Error(t('value 不能转换为 {{classname}}', { classname }));
|
|
2245
|
+
switch (classname) {
|
|
2246
|
+
case 'DdbDateTime':
|
|
2247
|
+
return (date.getTime() - 1000 * 60 * date.getTimezoneOffset()) / 1000;
|
|
2248
|
+
case 'DdbTimeStamp':
|
|
2249
|
+
return BigInt(date.getTime() - 1000 * 60 * date.getTimezoneOffset());
|
|
2250
|
+
case 'DdbNanoTimeStamp':
|
|
2251
|
+
return BigInt(date.getTime() - 1000 * 60 * date.getTimezoneOffset()) * 1000000n;
|
|
2252
|
+
case 'DdbDate':
|
|
2253
|
+
return Math.floor((date.getTime() - 1000 * 60 * date.getTimezoneOffset()) / (1000 * 3600 * 24));
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2228
2256
|
export class DdbBlob extends DdbObj {
|
|
2229
2257
|
constructor(value) {
|
|
2230
2258
|
assert(value, t('new DdbBlob 不能传空的 value'));
|
|
@@ -2527,7 +2555,7 @@ export function datetime2ms(datetime) {
|
|
|
2527
2555
|
if (datetime === null || datetime === nulls.int32)
|
|
2528
2556
|
return null;
|
|
2529
2557
|
const date = new Date(1000 * datetime);
|
|
2530
|
-
return new Date(`${_datetime_formatter.format(date)}.${date.getUTCMilliseconds()}`).valueOf();
|
|
2558
|
+
return new Date(`${_datetime_formatter.format(date)}.${String(date.getUTCMilliseconds()).padStart(3, '0')}`).valueOf();
|
|
2531
2559
|
}
|
|
2532
2560
|
export function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
|
|
2533
2561
|
return (datetime === null || datetime === nulls.int32) ?
|
|
@@ -2540,7 +2568,7 @@ export function timestamp2ms(timestamp) {
|
|
|
2540
2568
|
if (timestamp === null || timestamp === nulls.int64)
|
|
2541
2569
|
return null;
|
|
2542
2570
|
const date = new Date(Number(timestamp));
|
|
2543
|
-
return new Date(`${_datetime_formatter.format(date)}.${date.getUTCMilliseconds()}`).valueOf();
|
|
2571
|
+
return new Date(`${_datetime_formatter.format(date)}.${String(date.getUTCMilliseconds()).padStart(3, '0')}`).valueOf();
|
|
2544
2572
|
}
|
|
2545
2573
|
/** format timestamp (bigint) to string
|
|
2546
2574
|
- timestamp: bigint value
|
|
@@ -2602,7 +2630,7 @@ export function nanotimestamp2ns(nanotimestamp) {
|
|
|
2602
2630
|
if (nanotimestamp === null || nanotimestamp === nulls.int64)
|
|
2603
2631
|
return null;
|
|
2604
2632
|
const date = new Date(Number(nanotimestamp / 1000000n));
|
|
2605
|
-
return BigInt(new Date(`${_datetime_formatter.format(date)}.${date.getUTCMilliseconds()}`).valueOf()) * 1000000n + nanotimestamp % 1000000n;
|
|
2633
|
+
return BigInt(new Date(`${_datetime_formatter.format(date)}.${String(date.getUTCMilliseconds()).padStart(3, '0')}`).valueOf()) * 1000000n + nanotimestamp % 1000000n;
|
|
2606
2634
|
}
|
|
2607
2635
|
/** format nanotimestamp value (bigint) to string
|
|
2608
2636
|
- nanotimestamp: bigint value
|
|
@@ -2647,12 +2675,12 @@ export function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.S
|
|
|
2647
2675
|
export function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
2648
2676
|
if (!str || str === 'null')
|
|
2649
2677
|
return nulls.int64;
|
|
2650
|
-
|
|
2678
|
+
check(str.length === format.length, t('nanotimestamp 字符串长度必须等于格式串长度'));
|
|
2651
2679
|
const i_second_start = format.indexOf('ss');
|
|
2652
|
-
|
|
2680
|
+
check(i_second_start !== -1, t('格式串必须包含秒的格式 (ss)'));
|
|
2653
2681
|
const i_second_end = i_second_start + 2;
|
|
2654
2682
|
const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
|
|
2655
|
-
|
|
2683
|
+
check(i_nanosecond_start !== -1, t('格式串必须包含纳秒的格式 (SSSSSSSSS)'));
|
|
2656
2684
|
const ms = dayjs(str.slice(0, i_second_end), format.slice(0, i_second_end)).valueOf();
|
|
2657
2685
|
return (BigInt(-(1000 * 60 * new Date(ms).getTimezoneOffset()) +
|
|
2658
2686
|
ms) * 1000000n
|