dolphindb 2.0.533 → 2.0.602

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 CHANGED
@@ -232,7 +232,13 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
232
232
  deep?: boolean;
233
233
  }): T;
234
234
  }
235
- export declare function format(type: DdbType, value: DdbValue, le: boolean): string;
235
+ interface InspectOptions {
236
+ colors?: boolean;
237
+ }
238
+ /** Formats a single element (value) as a string according to DdbType, null returns a 'null' string */
239
+ export declare function format(type: DdbType, value: DdbValue, le: boolean, options?: InspectOptions): string;
240
+ /** Format vector, the index-th item in the collection is a string, a null value returns a 'null' string */
241
+ export declare function formati(obj: DdbObj, index: number, options?: InspectOptions): string;
236
242
  export declare class DdbVoid extends DdbObj<undefined> {
237
243
  constructor();
238
244
  }
@@ -538,3 +544,4 @@ export interface DdbErrorMessage {
538
544
  }
539
545
  export declare type DdbMessage = DdbPrintMessage | DdbObjectMessage | DdbErrorMessage;
540
546
  export declare let ddb: DDB;
547
+ export {};
package/browser.js CHANGED
@@ -1200,7 +1200,8 @@ export class DdbObj {
1200
1200
  return obj;
1201
1201
  }
1202
1202
  }
1203
- export function format(type, value, le) {
1203
+ /** Formats a single element (value) as a string according to DdbType, null returns a 'null' string */
1204
+ export function format(type, value, le, options = {}) {
1204
1205
  switch (type) {
1205
1206
  case DdbType.bool:
1206
1207
  return String((value === null || value === nulls.int8) ?
@@ -1336,6 +1337,66 @@ export function format(type, value, le) {
1336
1337
  return String(value);
1337
1338
  }
1338
1339
  }
1340
+ /** Format vector, the index-th item in the collection is a string, a null value returns a 'null' string */
1341
+ export function formati(obj, index, options = {}) {
1342
+ if (64 <= obj.type && obj.type < 128) { // array vector
1343
+ // 因为 array vector 目前只支持:Logical, Integral(不包括 INT128, COMPRESS 类型), Floating, Temporal
1344
+ // 都对应 TypedArray 中的一格,所以 lengths.length 等于 block 中的 row 的个数
1345
+ // av = array(INT[], 0, 5)
1346
+ // append!(av, [1..1])
1347
+ // append!(av, [1..70000])
1348
+ // append!(av, [1..1])
1349
+ // append!(av, [1..500])
1350
+ // ...
1351
+ // av
1352
+ const _type = obj.type - 64;
1353
+ let offset = 0;
1354
+ for (const { lengths, data, rows } of obj.value) {
1355
+ let acc_len = 0;
1356
+ if (offset + rows <= index) {
1357
+ offset += rows;
1358
+ continue; // 跳过这个 block
1359
+ }
1360
+ for (const length of lengths) {
1361
+ if (offset < index) {
1362
+ offset++;
1363
+ acc_len += length;
1364
+ continue;
1365
+ }
1366
+ const limit = 10;
1367
+ let items = new Array(Math.min(limit, length));
1368
+ for (let i = 0; i < items.length; i++)
1369
+ items[i] = format(_type, data[acc_len + i], obj.le, options);
1370
+ return (items.join(', ') + (length > limit ? ', ...' : '')).bracket('square');
1371
+ }
1372
+ }
1373
+ }
1374
+ switch (obj.type) {
1375
+ case DdbType.string:
1376
+ case DdbType.symbol:
1377
+ return obj.value[index];
1378
+ case DdbType.symbol_extended: {
1379
+ const { base, data } = obj.value;
1380
+ return base[data[index]];
1381
+ }
1382
+ case DdbType.uuid:
1383
+ case DdbType.int128:
1384
+ case DdbType.ipaddr:
1385
+ return format(obj.type, obj.value.subarray(16 * index, 16 * (index + 1)), obj.le, options);
1386
+ case DdbType.blob: {
1387
+ const value = obj.value[index];
1388
+ return value.length > 100 ?
1389
+ DdbObj.dec.decode(value.subarray(0, 98)) + '…'
1390
+ :
1391
+ DdbObj.dec.decode(value);
1392
+ }
1393
+ case DdbType.complex:
1394
+ case DdbType.point:
1395
+ return format(obj.type, obj.value.subarray(2 * index, 2 * (index + 1)), obj.le, options);
1396
+ default:
1397
+ return format(obj.type, obj.value[index], obj.le, options);
1398
+ }
1399
+ }
1339
1400
  export class DdbVoid extends DdbObj {
1340
1401
  constructor() {
1341
1402
  super({