dolphindb 3.0.127 → 3.0.128

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/index.d.ts CHANGED
@@ -399,10 +399,12 @@ export declare function formati(obj: DdbVectorObj, index: number, options?: Insp
399
399
  export interface ConvertOptions {
400
400
  /** `'string'` blob 类型数据的格式 */
401
401
  blob?: 'string' | 'binary';
402
- /** timestamp 类型转换为字符串表示时显示到秒还是毫秒 */
402
+ /** `'string'` char 类型数据的格式: string 解析成 string[],number 解析为 number[] */
403
+ char?: 'string' | 'number';
404
+ /** `'ms'` timestamp 类型转换为字符串表示时显示到秒还是毫秒 */
403
405
  timestamp?: 's' | 'ms';
404
406
  }
405
- export declare function convert(type: DdbType, value: DdbValue, le: boolean, { blob, timestamp }?: ConvertOptions): string | number | bigint | boolean | Uint8Array | number[] | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | string[] | Uint8Array[] | DdbFunctionDefValue | DdbDurationValue | DdbDecimal32Value | DdbDecimal64Value | BigInt128Array | DdbObj<DdbValue>[] | IotVectorItemValue | DdbSymbolExtendedValue | DdbArrayVectorValue | DdbDecimal32VectorValue | DdbDecimal64VectorValue | DdbDecimal128VectorValue | DdbDurationVectorValue | DdbMatrixValue | DdbChartValue | DdbTensorValue;
407
+ export declare function convert(type: DdbType, value: DdbValue, le: boolean, { blob, char, timestamp }?: ConvertOptions): string | number | bigint | boolean | Uint8Array | Int32Array | BigInt64Array | string[] | Int8Array | Int16Array | Float32Array | Float64Array | Uint8Array[] | number[] | DdbFunctionDefValue | DdbDurationValue | DdbDecimal32Value | DdbDecimal64Value | DdbDecimal32VectorValue | DdbDecimal64VectorValue | DdbDecimal128VectorValue | BigInt128Array | DdbSymbolExtendedValue | DdbArrayVectorValue | DdbMatrixValue | DdbObj<DdbValue>[] | IotVectorItemValue | DdbDurationVectorValue | DdbTensorValue | DdbChartValue;
406
408
  /** 转换一个向量到 js 原生数组 */
407
409
  export declare function converts(type: DdbType, value: DdbVectorValue, rows: number, le: boolean, options?: ConvertOptions): any[];
408
410
  export declare class DdbVoid extends DdbObj<undefined> {
@@ -421,7 +423,7 @@ export declare class DdbString extends DdbObj<string> {
421
423
  constructor(value: string);
422
424
  }
423
425
  export declare class DdbLong extends DdbObj<bigint> {
424
- constructor(value: bigint | null);
426
+ constructor(value: bigint | number | null);
425
427
  }
426
428
  export declare class DdbDouble extends DdbObj<number> {
427
429
  constructor(value: number | null);
@@ -430,7 +432,10 @@ export declare class DdbDateTime extends DdbObj<number> {
430
432
  constructor(value: number | null);
431
433
  }
432
434
  export declare class DdbTimeStamp extends DdbObj<bigint> {
433
- constructor(value: bigint | null);
435
+ /** @example
436
+ new DdbTimeStamp(new Date().getTime())
437
+ new DdbTimeStamp(dayjs().valueOf()) */
438
+ constructor(value?: bigint | null | number);
434
439
  }
435
440
  export declare class DdbNanoTimeStamp extends DdbObj<bigint> {
436
441
  constructor(value: bigint | null);
package/index.js CHANGED
@@ -1954,12 +1954,20 @@ export function formati(obj, index, options = {}) {
1954
1954
  }
1955
1955
  }
1956
1956
  }
1957
- export function convert(type, value, le, { blob = 'string', timestamp = 'ms' } = {}) {
1957
+ export function convert(type, value, le, { blob = 'string', char = 'string', timestamp = 'ms' } = {}) {
1958
1958
  switch (type) {
1959
1959
  case DdbType.void:
1960
1960
  return value === DdbVoidType.null ? null : undefined;
1961
1961
  case DdbType.char:
1962
- return value === null || value === nulls.int8 ? '' : String.fromCharCode(value);
1962
+ return char === 'string'
1963
+ ? value === null || value === nulls.int8
1964
+ ? ''
1965
+ : // ascii printable
1966
+ // http://facweb.cs.depaul.edu/sjost/it212/documents/ascii-pr.htm
1967
+ (32 <= value && value <= 126)
1968
+ ? String.fromCharCode(value)
1969
+ : `\\${value}`
1970
+ : value;
1963
1971
  case DdbType.bool:
1964
1972
  return value === null || value === nulls.int8 ? null : Boolean(value);
1965
1973
  case DdbType.short:
@@ -2157,6 +2165,8 @@ export class DdbString extends DdbObj {
2157
2165
  }
2158
2166
  export class DdbLong extends DdbObj {
2159
2167
  constructor(value) {
2168
+ if (typeof value === 'number')
2169
+ value = BigInt(value);
2160
2170
  super({
2161
2171
  form: DdbForm.scalar,
2162
2172
  type: DdbType.long,
@@ -2183,7 +2193,15 @@ export class DdbDateTime extends DdbObj {
2183
2193
  }
2184
2194
  }
2185
2195
  export class DdbTimeStamp extends DdbObj {
2196
+ /** @example
2197
+ new DdbTimeStamp(new Date().getTime())
2198
+ new DdbTimeStamp(dayjs().valueOf()) */
2186
2199
  constructor(value) {
2200
+ if (value === undefined)
2201
+ value = new Date().getTime();
2202
+ if (typeof value === 'number')
2203
+ value = BigInt(-(1000 * 60 * new Date(value).getTimezoneOffset()) +
2204
+ value);
2187
2205
  super({
2188
2206
  form: DdbForm.scalar,
2189
2207
  type: DdbType.timestamp,