dolphindb 2.0.507 → 2.0.510

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
@@ -75,8 +75,22 @@ export interface DdbArrayVectorBlock {
75
75
  lengths: Uint8Array | Uint16Array | Uint32Array;
76
76
  data: DdbVectorValue;
77
77
  }
78
- export declare type DdbValue = null | boolean | number | [number, number] | bigint | string | string[] | Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | Uint8Array[] | DdbObj[] | DdbFunctionDefValue | DdbSymbolExtendedValue | DdbArrayVectorBlock[];
79
- export declare type DdbVectorValue = string | string[] | Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | Uint8Array[] | DdbObj[] | DdbSymbolExtendedValue | DdbArrayVectorBlock[];
78
+ export interface DdbMatrixValue {
79
+ rows: DdbObj<DdbVectorValue>;
80
+ cols: DdbObj<DdbVectorValue>;
81
+ data: DdbVectorValue;
82
+ }
83
+ export declare type DdbScalarValue = null | boolean | number | bigint | string | Uint8Array | // uuid, ipaddr, int128, blob
84
+ [
85
+ number,
86
+ number
87
+ ] | // complex, point
88
+ DdbFunctionDefValue;
89
+ export declare type DdbVectorValue = Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | string[] | // string[]
90
+ Uint8Array[] | // blob
91
+ DdbObj[] | // any
92
+ DdbSymbolExtendedValue | DdbArrayVectorBlock[];
93
+ export declare type DdbValue = DdbScalarValue | DdbVectorValue | DdbMatrixValue;
80
94
  export declare const nulls: {
81
95
  readonly int8: -128;
82
96
  readonly int16: -32768;
@@ -120,8 +134,6 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
120
134
  rows?: number;
121
135
  /** 第 2 维 */
122
136
  cols?: number;
123
- /** matrix 中值的类型,仅 matrix 才有 */
124
- datatype?: DdbType;
125
137
  /** 实际数据。不同的 DdbForm, DdbType 使用 DdbValue 中不同的类型来表示实际数据 */
126
138
  value: T;
127
139
  /** 原始二进制数据,仅在 parse_object 为 false 时通过 parse_message 生成的顶层对象有这个属性 */
@@ -131,11 +143,11 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
131
143
  type: DdbType;
132
144
  });
133
145
  static parse(buf: Uint8Array, le: boolean): DdbObj<DdbValue>;
134
- static parse_scalar(buf: Uint8Array, le: boolean, type: DdbType): [number, DdbValue];
146
+ static parse_scalar(buf: Uint8Array, le: boolean, type: DdbType): [number, DdbScalarValue];
135
147
  /** parse: rows, cols, items
136
148
  返回的 ddbobj.length 不包括 vector 的 type 和 form
137
149
  */
138
- static parse_vector(buf: Uint8Array, le: boolean, type: DdbType): DdbObj;
150
+ static parse_vector(buf: Uint8Array, le: boolean, type: DdbType): DdbObj<DdbVectorValue>;
139
151
  /** 有可能没有字节对齐,不能直接使用原有 message 的 arraybuffer, 统一复制出来,让原有 arraybuffer 被回收掉比较好 */
140
152
  static parse_vector_items(buf: Uint8Array, le: boolean, type: DdbType, length: number): [
141
153
  number,
package/browser.js CHANGED
@@ -202,34 +202,60 @@ class DdbObj {
202
202
  });
203
203
  }
204
204
  case DdbForm.matrix: {
205
- // matrix([
205
+ // rename!(
206
+ // 1..9$3:3,
206
207
  // [1, 2, 3],
207
- // [3, 2, 1]
208
- // ])
209
- // <Buffer 00 has_row_label = , has_col_label =
210
- // 04 03 type = int, form = matrix
211
- // 03 00 00 00 02 00 00 00 rows = 3, cols = 2
212
- // 01 00 00 00 02 00 00 00 03 00 00 00 03 00 00 00 02 00 00 00 01 00 00 00>
208
+ // ['c1', 'c2', 'c3']
209
+ // )
210
+ // <Buffer 04 03 type = int, form = matrix
211
+ // 03 has_row_label (& 0x01) = 1, has_col_label (& 0x02) = 1
212
+ // row labels
213
+ // 04 01 type = int, form = vector
214
+ // 03 00 00 00 01 00 00 00 rows = 3, cols = 1
215
+ // 01 00 00 00 02 00 00 00 03 00 00 00 vector values
216
+ // col labels
217
+ // 12 01 type = string, form = vector
218
+ // 03 00 00 00 01 00 00 00 rows = 3, cols = 1
219
+ // 63 31 00 63 32 00 63 33 00
220
+ // matrix data
221
+ // 04 03 type = matrix.type, form = matrix
222
+ // 03 00 00 00 03 00 00 00 rows = 3, cols = 3
213
223
  const dv = new DataView(buf.buffer, buf.byteOffset + i_data);
214
224
  const label_flags = buf_data[0];
215
225
  const has_row_labels = Boolean(label_flags & 0x01);
216
226
  const has_col_labels = Boolean(label_flags & 0x02);
217
- if (has_row_labels || has_col_labels)
218
- throw new Error('matrix 暂不支持 row labels 和 col labels');
219
- const datatype = buf_data[1];
220
- const rows = dv.getUint32(3, le);
221
- const cols = dv.getUint32(7, le);
222
- const [len_items, value] = this.parse_vector_items(buf_data.subarray(11), le, datatype, rows * cols // 假设小于 2**32
227
+ let row_labels = null;
228
+ let col_labels = null;
229
+ let offset = 1;
230
+ if (has_row_labels) {
231
+ row_labels = this.parse_vector(buf_data.subarray(offset + 2), le, buf_data[offset]);
232
+ row_labels.length += 2;
233
+ offset += row_labels.length;
234
+ }
235
+ if (has_col_labels) {
236
+ col_labels = this.parse_vector(buf_data.subarray(offset + 2), le, buf_data[offset]);
237
+ col_labels.length += 2;
238
+ offset += col_labels.length;
239
+ }
240
+ if (buf_data[offset] !== type)
241
+ throw new Error('matrix.datatype !== matrix.type');
242
+ const rows = dv.getUint32(offset + 2, le);
243
+ const cols = dv.getUint32(offset + 6, le);
244
+ const [len_items, data] = this.parse_vector_items(buf_data.subarray(offset + 10), le, type, rows * cols // 假设小于 2**32
223
245
  );
246
+ offset += 10 + len_items;
224
247
  return new this({
225
248
  le,
226
249
  form,
227
250
  type,
228
- length: i_data + 11 + len_items,
251
+ length: i_data + offset,
229
252
  rows,
230
253
  cols,
231
- datatype,
232
- value,
254
+ value: {
255
+ rows: row_labels,
256
+ cols: col_labels,
257
+ data,
258
+ },
233
259
  });
234
260
  }
235
261
  default:
@@ -457,6 +483,7 @@ class DdbObj {
457
483
  case DdbType.minute:
458
484
  case DdbType.second:
459
485
  case DdbType.datetime:
486
+ case DdbType.datehour:
460
487
  return [
461
488
  4 * length,
462
489
  new Int32Array(buf.buffer.slice(buf.byteOffset, buf.byteOffset + 4 * length))
@@ -581,7 +608,7 @@ class DdbObj {
581
608
  }
582
609
  pack() {
583
610
  const { form, type, value } = this;
584
- let header = new Uint8Array(new ArrayBuffer(2));
611
+ let header = new Uint8Array(2);
585
612
  header[0] = type;
586
613
  header[1] = form;
587
614
  const body = (() => {
@@ -722,12 +749,17 @@ class DdbObj {
722
749
  value[0].pack(),
723
750
  value[1].pack(),
724
751
  ];
725
- case DdbForm.matrix:
752
+ case DdbForm.matrix: {
753
+ const { rows, cols, data } = value;
726
754
  return [
727
- Uint8Array.of(0, this.datatype, this.form),
755
+ Uint8Array.of((rows && 0x01) | (cols && 0x02)),
756
+ ...rows ? [rows.pack()] : [],
757
+ ...cols ? [cols.pack()] : [],
758
+ Uint8Array.of(this.type, this.form),
728
759
  Uint32Array.of(this.rows, this.cols),
729
- ...DdbObj.pack_vector_body(value, this.datatype, this.rows * this.cols)
760
+ ...DdbObj.pack_vector_body(data, this.type, this.rows * this.cols)
730
761
  ];
762
+ }
731
763
  default:
732
764
  throw new Error(`${DdbForm[form]} 暂不支持序列化`);
733
765
  }
@@ -755,6 +787,7 @@ class DdbObj {
755
787
  case DdbType.minute:
756
788
  case DdbType.second:
757
789
  case DdbType.datetime:
790
+ case DdbType.datehour:
758
791
  return [value];
759
792
  case DdbType.float:
760
793
  return [value];
@@ -841,7 +874,7 @@ class DdbObj {
841
874
  case DdbForm.dict:
842
875
  return `dict<${DdbType[this.value[0].type]}, ${DdbType[this.value[1].type]}>`;
843
876
  case DdbForm.matrix:
844
- return `matrix<${DdbType[this.datatype]}>[${this.rows} rows][${this.cols} cols]`;
877
+ return `matrix<${DdbType[this.type]}>[${this.rows} rows][${this.cols} cols]`;
845
878
  default:
846
879
  return `${DdbForm[this.form]} ${tname}`;
847
880
  }
@@ -1541,25 +1574,30 @@ class DDB {
1541
1574
  catch { }
1542
1575
  // 临界区结束,只有一个 rpc 函数调用运行到这里,可以独占 this.on_message 然后写 WebSocket
1543
1576
  this.on_message = ({ data: buffer }) => {
1544
- const buf = new Uint8Array(buffer);
1545
- if (this.print_message_buffer)
1546
- console.log(buf);
1547
- const message = this.parse_message(buf, parse_object);
1548
- listener?.(message, this);
1549
- for (const listener of _handlers)
1550
- listener(message, this);
1551
- const { type, data } = message;
1552
- switch (type) {
1553
- case 'print':
1554
- if (this.print_message)
1555
- console.log(data);
1556
- return;
1557
- case 'object':
1558
- resolve(data);
1559
- return;
1560
- case 'error':
1561
- reject(data);
1562
- return;
1577
+ try {
1578
+ const buf = new Uint8Array(buffer);
1579
+ if (this.print_message_buffer)
1580
+ console.log(buf);
1581
+ const message = this.parse_message(buf, parse_object);
1582
+ listener?.(message, this);
1583
+ for (const listener of _handlers)
1584
+ listener(message, this);
1585
+ const { type, data } = message;
1586
+ switch (type) {
1587
+ case 'print':
1588
+ if (this.print_message)
1589
+ console.log(data);
1590
+ return;
1591
+ case 'object':
1592
+ resolve(data);
1593
+ return;
1594
+ case 'error':
1595
+ reject(data);
1596
+ return;
1597
+ }
1598
+ }
1599
+ catch (error) {
1600
+ reject(error);
1563
1601
  }
1564
1602
  };
1565
1603
  args = this.to_ddbobjs(args);