dolphindb 2.0.602 → 2.0.603

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/README.md CHANGED
@@ -46,6 +46,7 @@ npm install dolphindb
46
46
  ```ts
47
47
  import { DDB } from 'dolphindb'
48
48
  // The import method for existing projects using CommonJS modules is const { DDB } = require('dolphindb')
49
+ // Use in browser: import { DDB } form 'dolphindb/browser.js'
49
50
 
50
51
  // Create a database object and initialize the WebSocket URL
51
52
  let ddb = new DDB('ws://127.0.0.1:8848')
package/browser.d.ts CHANGED
@@ -121,6 +121,15 @@ export interface DdbChartValue {
121
121
  /** 原属性 chartType */
122
122
  type: DdbChartType;
123
123
  stacking: boolean;
124
+ /** 直方图 (Histogram), plotHist 函数返回的 chart 可能具有该属性
125
+ 原属性 binStart
126
+ 数值类型的 DdbObj 都有可能?
127
+ */
128
+ bin_start?: DdbObj;
129
+ /** 原属性 binEnd */
130
+ bin_end?: DdbObj;
131
+ /** 原属性 binCount */
132
+ bin_count?: DdbObj;
124
133
  titles: {
125
134
  chart: string;
126
135
  x_axis: string;
@@ -388,9 +397,11 @@ export declare class DDB {
388
397
  print_object_buffer: boolean;
389
398
  print_message: boolean;
390
399
  parse_object: boolean;
400
+ pnode_run_defined: boolean;
391
401
  /** DdbMessage listeners */
392
402
  listeners: DdbMessageListener[];
393
403
  pconnect: Promise<void>;
404
+ ppnoderun: Promise<void>;
394
405
  presult: Promise<any>;
395
406
  get connected(): boolean;
396
407
  /**
package/browser.js CHANGED
@@ -268,7 +268,7 @@ export class DdbObj {
268
268
  if (form === DdbForm.dict)
269
269
  return dict;
270
270
  else {
271
- const { chartType: type, stacking, title: titles, extras, data, ...others } = dict.to_dict();
271
+ const { chartType: type, stacking, binStart: bin_start, binEnd: bin_end, binCount: bin_count, title: titles, extras, data, ...others } = dict.to_dict();
272
272
  const [chart, x_axis, y_axis] = titles.value;
273
273
  dict.form = DdbForm.chart;
274
274
  dict.value = {
@@ -279,6 +279,8 @@ export class DdbObj {
279
279
  x_axis,
280
280
  y_axis,
281
281
  },
282
+ ...bin_start ? { bin_start, bin_end, } : {},
283
+ ...bin_count ? { bin_count } : {},
282
284
  ...extras ? (() => {
283
285
  const { multiYAxes: multi_y_axes = false, ...extras_others } = extras.to_dict({ strip: true });
284
286
  return {
@@ -866,10 +868,17 @@ export class DdbObj {
866
868
  value[1].pack(),
867
869
  ];
868
870
  case DdbForm.chart: {
869
- const { type, stacking, titles: { chart, x_axis, y_axis, }, extras, data } = this.value;
871
+ const { type, stacking, bin_start, bin_end, bin_count, titles: { chart, x_axis, y_axis, }, extras, data } = this.value;
870
872
  const { value: [keys, values] } = new DdbDict({
871
873
  chartType: new DdbInt(type),
872
874
  stacking,
875
+ ...bin_start ? {
876
+ binStart: bin_start,
877
+ binEnd: bin_end
878
+ } : {},
879
+ ...bin_count ? {
880
+ binCount: bin_count
881
+ } : {},
873
882
  title: new DdbVectorString([chart, x_axis, y_axis]),
874
883
  ...extras ? (() => {
875
884
  const { multi_y_axes, ...extras_other } = extras;
@@ -1101,7 +1110,7 @@ export class DdbObj {
1101
1110
  case DdbForm.table:
1102
1111
  return `table[${this.rows}r][${this.cols}c]`;
1103
1112
  case DdbForm.dict:
1104
- return `dict<${DdbType[this.value[0].type]}, ${DdbType[this.value[1].type]}>`;
1113
+ return `dict<${DdbType[this.value[0].type]}, ${DdbType[this.value[1].type]}>[${this.rows}]`;
1105
1114
  case DdbForm.chart:
1106
1115
  return `chart<${DdbChartType[this.value.type]}>`;
1107
1116
  case DdbForm.matrix:
@@ -1940,13 +1949,16 @@ export class DDB {
1940
1949
  password = '123456';
1941
1950
  /** python session flag (2048) */
1942
1951
  python = false;
1952
+ // 内部选项, 状态
1943
1953
  print_message_buffer = false;
1944
1954
  print_object_buffer = false;
1945
1955
  print_message = true;
1946
1956
  parse_object = true;
1957
+ pnode_run_defined = false;
1947
1958
  /** DdbMessage listeners */
1948
1959
  listeners = [];
1949
1960
  pconnect = Promise.resolve();
1961
+ ppnoderun = Promise.resolve();
1950
1962
  presult = Promise.resolve(null);
1951
1963
  get connected() {
1952
1964
  return this.websocket?.readyState === WebSocket.OPEN;
@@ -2020,41 +2032,6 @@ export class DDB {
2020
2032
  this.on_message(event);
2021
2033
  }
2022
2034
  });
2023
- await this.eval(this.python ?
2024
- 'def pnode_run (nodes, func_name, args, add_node_alias):\n' +
2025
- ' nargs = size(args)\n' +
2026
- ' func = funcByName(func_name)\n' +
2027
- ' \n' +
2028
- ' if not nargs:\n' +
2029
- ' return pnodeRun(func, nodes, add_node_alias)\n' +
2030
- ' \n' +
2031
- ' args_partial = [ ]\n' +
2032
- ' args_partial.append(func)\n' +
2033
- ' for a in args:\n' +
2034
- ' args_partial.append(a)\n' +
2035
- ' \n' +
2036
- ' return pnodeRun(\n' +
2037
- ' unifiedCall(partial, args_partial),\n' +
2038
- ' nodes,\n' +
2039
- ' add_node_alias\n' +
2040
- ' )\n'
2041
- :
2042
- 'def pnode_run (nodes, func_name, args, add_node_alias = true) {\n' +
2043
- ' nargs = size(args)\n' +
2044
- ' func = funcByName(func_name)\n' +
2045
- ' \n' +
2046
- ' if (!nargs)\n' +
2047
- ' return pnodeRun(func, nodes, add_node_alias)\n' +
2048
- ' \n' +
2049
- ' args_partial = array(any, 1 + nargs, 1 + nargs)\n' +
2050
- ' args_partial[0] = func\n' +
2051
- ' args_partial[1:] = args\n' +
2052
- ' return pnodeRun(\n' +
2053
- ' unifiedCall(partial, args_partial),\n' +
2054
- ' nodes,\n' +
2055
- ' add_node_alias\n' +
2056
- ' )\n' +
2057
- '}\n', { urgent: true });
2058
2035
  if (this.autologin)
2059
2036
  if (this.python)
2060
2037
  await this.eval(`login(${this.username.quote('double')}, ${this.password.quote('double')})`, { urgent: true });
@@ -2098,6 +2075,7 @@ export class DDB {
2098
2075
  this.on_message = () => { };
2099
2076
  this.presult = Promise.resolve(null);
2100
2077
  this.pconnect = Promise.resolve();
2078
+ this.pnode_run_defined = false;
2101
2079
  }
2102
2080
  /** rpc through websocket (function/script/variable command)
2103
2081
  - type: API 类型: 'script' | 'function' | 'variable'
@@ -2126,6 +2104,55 @@ export class DDB {
2126
2104
  }
2127
2105
  if (!this.connected)
2128
2106
  throw new Error(`${this.url} is already disconnected`);
2107
+ if (func === 'pnode_run' && !this.pnode_run_defined) {
2108
+ const ptail = this.ppnoderun;
2109
+ let resolve;
2110
+ this.ppnoderun = new Promise((_resolve, _reject) => {
2111
+ resolve = _resolve;
2112
+ });
2113
+ await ptail;
2114
+ try {
2115
+ if (!this.pnode_run_defined)
2116
+ await this.eval(this.python ?
2117
+ 'def pnode_run (nodes, func_name, args, add_node_alias):\n' +
2118
+ ' nargs = size(args)\n' +
2119
+ ' func = funcByName(func_name)\n' +
2120
+ ' \n' +
2121
+ ' if not nargs:\n' +
2122
+ ' return pnodeRun(func, nodes, add_node_alias)\n' +
2123
+ ' \n' +
2124
+ ' args_partial = [ ]\n' +
2125
+ ' args_partial.append(func)\n' +
2126
+ ' for a in args:\n' +
2127
+ ' args_partial.append(a)\n' +
2128
+ ' \n' +
2129
+ ' return pnodeRun(\n' +
2130
+ ' unifiedCall(partial, args_partial),\n' +
2131
+ ' nodes,\n' +
2132
+ ' add_node_alias\n' +
2133
+ ' )\n'
2134
+ :
2135
+ 'def pnode_run (nodes, func_name, args, add_node_alias = true) {\n' +
2136
+ ' nargs = size(args)\n' +
2137
+ ' func = funcByName(func_name)\n' +
2138
+ ' \n' +
2139
+ ' if (!nargs)\n' +
2140
+ ' return pnodeRun(func, nodes, add_node_alias)\n' +
2141
+ ' \n' +
2142
+ ' args_partial = array(any, 1 + nargs, 1 + nargs)\n' +
2143
+ ' args_partial[0] = func\n' +
2144
+ ' args_partial[1:] = args\n' +
2145
+ ' return pnodeRun(\n' +
2146
+ ' unifiedCall(partial, args_partial),\n' +
2147
+ ' nodes,\n' +
2148
+ ' add_node_alias\n' +
2149
+ ' )\n' +
2150
+ '}\n', { urgent: true });
2151
+ }
2152
+ finally {
2153
+ resolve();
2154
+ }
2155
+ }
2129
2156
  // this 上的当前配置需要在 message 到达后使用,先保存起来
2130
2157
  const _handlers = [...this.listeners].reverse();
2131
2158
  // 临界区:保证多个 rpc 并发时形成 promise 链