dolphindb 2.0.901 → 2.0.902

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.js CHANGED
@@ -6,6 +6,7 @@ import ipaddrjs from 'ipaddr.js';
6
6
  const { fromByteArray: buf2ipaddr } = ipaddrjs;
7
7
  import { concat, assert, inspect, typed_array_to_buffer } from 'xshell/utils.js';
8
8
  import { connect_websocket } from 'xshell/net.js';
9
+ import { t } from './i18n/index.js';
9
10
  export var DdbForm;
10
11
  (function (DdbForm) {
11
12
  DdbForm[DdbForm["scalar"] = 0] = "scalar";
@@ -16,7 +17,8 @@ export var DdbForm;
16
17
  DdbForm[DdbForm["dict"] = 5] = "dict";
17
18
  DdbForm[DdbForm["table"] = 6] = "table";
18
19
  DdbForm[DdbForm["chart"] = 7] = "chart";
19
- /** Node internal communication may be used, calling function execution script generally does not return this type */
20
+ /** 结点内部通信可能会使用,调用函数执行脚本一般不会返回这种类型
21
+ Node internal communication may be used, calling function execution script generally does not return this type */
20
22
  DdbForm[DdbForm["chunk"] = 8] = "chunk";
21
23
  /** sysobj */
22
24
  DdbForm[DdbForm["object"] = 9] = "object";
@@ -117,7 +119,7 @@ export const nulls = {
117
119
  double: -Number.MAX_VALUE,
118
120
  bytes16: Uint8Array.from(new Array(16).fill(0))
119
121
  };
120
- /** Can represent data types in all DolphinDB databases */
122
+ /** 可以表示所有 DolphinDB 数据库中的数据类型 Can represent data types in all DolphinDB databases */
121
123
  export class DdbObj {
122
124
  static dec = new TextDecoder('utf-8');
123
125
  static enc = new TextEncoder();
@@ -149,7 +151,7 @@ export class DdbObj {
149
151
  rows;
150
152
  /** 第 2 维 */
151
153
  cols;
152
- /** The actual data. Different DdbForm, DdbType use different types in DdbValue to represent actual data */
154
+ /** 实际数据。不同的 DdbForm, DdbType 使用 DdbValue 中不同的类型来表示实际数据 The actual data. Different DdbForm, DdbType use different types in DdbValue to represent actual data */
153
155
  value;
154
156
  /** 原始二进制数据,仅在 parse_object 为 false 时通过 parse_message 生成的顶层对象有这个属性 */
155
157
  buffer;
@@ -471,7 +473,7 @@ export class DdbObj {
471
473
  return [12, { scale: dv.getInt32(0, le), data: data === nulls.int64 ? null : data }];
472
474
  }
473
475
  default:
474
- throw new Error(`${DdbType[type] || type} 暂时不支持解析`);
476
+ throw new Error(String(DdbType[type] || type) + t(' 暂时不支持解析'));
475
477
  }
476
478
  }
477
479
  /** parse: rows, cols, items
@@ -566,7 +568,7 @@ export class DdbObj {
566
568
  lengths = new Uint32Array(lengths_buf.buffer);
567
569
  break;
568
570
  default:
569
- throw new Error(`array vector 存在非法 unit = ${unit}`);
571
+ throw new Error(t('array vector 存在非法 unit: {{unit}}', { unit }));
570
572
  }
571
573
  let total_length = 0;
572
574
  for (const x of lengths)
@@ -891,7 +893,7 @@ export class DdbObj {
891
893
  return [Int32Array.of(scale), BigInt64Array.of(data === null ? nulls.int64 : data)];
892
894
  }
893
895
  default:
894
- throw new Error(`${DdbType[type] || type} serialization is not currently supported`);
896
+ throw new Error(String(DdbType[type] || type) + t(' 暂时不支持序列化'));
895
897
  }
896
898
  case DdbForm.vector:
897
899
  case DdbForm.pair:
@@ -956,7 +958,7 @@ export class DdbObj {
956
958
  ];
957
959
  }
958
960
  default:
959
- throw new Error(`${DdbForm[form]} serialization is not currently supported`);
961
+ throw new Error(`${DdbForm[form] || form} ${t('暂时不支持序列化')}`);
960
962
  }
961
963
  })();
962
964
  if (!body)
@@ -1048,7 +1050,7 @@ export class DdbObj {
1048
1050
  return [Int32Array.of(scale), data];
1049
1051
  }
1050
1052
  default:
1051
- throw new Error(`vector ${DdbType[type]} 暂不支持序列化`);
1053
+ throw new Error(t('vector {{type}} 暂不支持序列化', { type: DdbType[type] || type }));
1052
1054
  }
1053
1055
  }
1054
1056
  [inspect.custom](depth, _options, _inspect) {
@@ -1201,7 +1203,7 @@ export class DdbObj {
1201
1203
  case 'boolean':
1202
1204
  return new DdbBool(value);
1203
1205
  default:
1204
- throw new Error(`Cannot automatically convert ${type} to DdbObj`);
1206
+ throw new Error(t('不能自动转换 {{type}} 至 DdbObj', { type }));
1205
1207
  }
1206
1208
  }
1207
1209
  /** 转换 js 数组为 DdbObj[] */
@@ -1209,7 +1211,7 @@ export class DdbObj {
1209
1211
  return values.map(value => this.to_ddbobj(value));
1210
1212
  }
1211
1213
  to_rows() {
1212
- assert(this.form === DdbForm.table, 'form must be DdbForm.table, otherwise it cannot to_rows');
1214
+ assert(this.form === DdbForm.table, t('form 必须是 DdbForm.table, 否则不能 to_rows'));
1213
1215
  let rows = new Array(this.rows);
1214
1216
  for (let i = 0; i < this.rows; i++) {
1215
1217
  let row = {};
@@ -1241,10 +1243,10 @@ export class DdbObj {
1241
1243
  return rows;
1242
1244
  }
1243
1245
  to_dict({ strip, deep, } = {}) {
1244
- assert(this.form === DdbForm.dict, 'this.form must be DdbForm.dict, otherwise to_dict cannot be called to convert to js object');
1246
+ assert(this.form === DdbForm.dict, t('this.form 必须是 DdbForm.dict, 否则不能调用 to_dict 转换为 js object'));
1245
1247
  const [{ value: keys, type: key_type }, { value: values, type: value_type }] = this.value;
1246
- assert(key_type === DdbType.string && value_type === DdbType.any, 'Currently only supports automatic conversion of dict<string, any> to js object');
1247
- assert(!(deep && !strip), 'strip = true must be set when deep = true');
1248
+ assert(key_type === DdbType.string && value_type === DdbType.any, t('当前只支持自动转换 dict<string, any> 为 js object'));
1249
+ assert(!(deep && !strip), t('deep = true 时必须设置 strip = true'));
1248
1250
  let obj = {};
1249
1251
  for (let i = 0; i < this.rows; i++) {
1250
1252
  let value = values[i];
@@ -1261,7 +1263,7 @@ let default_formatter = Intl.NumberFormat('en-US', { maximumFractionDigits: 20 }
1261
1263
  let _decimals = 20;
1262
1264
  /** 缓存,为了优化性能,通常 options.decimals 都是不变的 */
1263
1265
  let _formatter = Intl.NumberFormat('en-US', { maximumFractionDigits: 20 });
1264
- /** Formats a single element (value) as a string according to DdbType, null returns a 'null' string */
1266
+ /** 根据 DdbType 格式化单个元素 (value) 为字符串,空值返回 'null' 字符串 Formats a single element (value) as a string according to DdbType, null returns a 'null' string */
1265
1267
  export function format(type, value, le, options = {}) {
1266
1268
  const { decimals } = options;
1267
1269
  const formatter = (() => {
@@ -1466,7 +1468,7 @@ export function format(type, value, le, options = {}) {
1466
1468
  return inspect(value, options);
1467
1469
  }
1468
1470
  }
1469
- /** formatted vector, the index-th item in the collection is a string, a null value returns a 'null' string */
1471
+ /** 格式化向量、集合中的第 index 项为字符串,空值返回 'null' 字符串 formatted vector, the index-th item in the collection is a string, a null value returns a 'null' string */
1470
1472
  export function formati(obj, index, options = {}) {
1471
1473
  assert(index < obj.rows, 'index < obj.rows');
1472
1474
  if (64 <= obj.type && obj.type < 128) { // array vector
@@ -1801,10 +1803,9 @@ export class DdbSetString extends DdbObj {
1801
1803
  });
1802
1804
  }
1803
1805
  }
1804
- /** Constructs a DdbDict object, which supports two usages:
1805
- - The incoming type is the keys of DdbObj<DdbVectorValue>, and the two parameters of values directly form the DdbDict of dict<keys.type, values.type>
1806
- - Pass in js object (type is Record<string, boolean | string | DdbObj>), automatically converted to DdbDict of dict<string, any>
1807
- */
1806
+ /** 构造 DdbDict 对象,支持两种用法: Constructs a DdbDict object, which supports two usages:
1807
+ - 传入类型是 DdbVectorObj 的 keys, values 两个参数直接组成 dict<keys.type, values.type> 的 DdbDict The incoming type is the keys of DdbObj<DdbVectorValue>, and the two parameters of values directly form the DdbDict of dict<keys.type, values.type>
1808
+ - 传入 js object (类型是 Record<string, boolean | string | DdbObj>), 自动转换为 dict<string, any> 的 DdbDict Pass in js object (type is Record<string, boolean | string | DdbObj>), automatically converted to DdbDict of dict<string, any> */
1808
1809
  export class DdbDict extends DdbObj {
1809
1810
  constructor(arg0, arg1) {
1810
1811
  if (arg1)
@@ -1934,7 +1935,7 @@ export function timestamp2ms(timestamp) {
1934
1935
  /** format timestamp (bigint) to string
1935
1936
  - timestamp: bigint value
1936
1937
  - format?:
1937
- format string, default to `YYYY.MM.DD HH:mm:ss.SSS`
1938
+ 格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSS` format string, default to `YYYY.MM.DD HH:mm:ss.SSS`
1938
1939
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1939
1940
  */
1940
1941
  export function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
@@ -1958,15 +1959,17 @@ export function datehour2str(datehour, format = 'YYYY.MM.DDTHH') {
1958
1959
  dayjs(1000 * 60 * new Date(ms).getTimezoneOffset() + ms).format(format);
1959
1960
  }
1960
1961
  /** parse timestamp string to bigint value
1961
- - str: timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
1962
+ - str: str: timestamp string, 如果为空字符串或 'null' 会返回对应的空值 (nulls.int64)
1963
+ timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
1962
1964
  - format?:
1965
+ 对应传入字符串的格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSS`
1963
1966
  The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
1964
1967
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1965
1968
  */
1966
1969
  export function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1967
1970
  if (!str || str === 'null')
1968
1971
  return nulls.int64;
1969
- assert(str.length === format.length, 'The length of the timestamp string must be equal to the length of the format string');
1972
+ assert(str.length === format.length, t('timestamp 字符串长度必须等于格式串长度'));
1970
1973
  const ms = dayjs(str, format).valueOf();
1971
1974
  return BigInt(-(1000 * 60 * new Date(ms).getTimezoneOffset()) +
1972
1975
  ms);
@@ -1980,10 +1983,10 @@ export function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
1980
1983
  if (nanotime < 0n)
1981
1984
  return String(nanotime);
1982
1985
  const i_second_start = format.indexOf('ss');
1983
- assert(i_second_start !== -1, 'The format string must contain the format for seconds (ss)');
1986
+ assert(i_second_start !== -1, t('格式串必须包含秒的格式 (ss)'));
1984
1987
  const i_second_end = i_second_start + 2;
1985
1988
  const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
1986
- assert(i_nanosecond_start !== -1, 'Format string must contain nanosecond format (SSSSSSSSS)');
1989
+ assert(i_nanosecond_start !== -1, t('格式串必须包含纳秒的格式 (SSSSSSSSS)'));
1987
1990
  const ms = Number(nanotime) / 1000000;
1988
1991
  return (dayjs(1000 * 60 * new Date(ms).getTimezoneOffset() + ms).format(format.slice(0, i_second_end)) +
1989
1992
  format.slice(i_second_end, i_nanosecond_start) +
@@ -1999,8 +2002,8 @@ export function nanotimestamp2ns(nanotimestamp) {
1999
2002
  /** format nanotimestamp value (bigint) to string
2000
2003
  - nanotimestamp: bigint value
2001
2004
  - format?:
2002
- format string, default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
2003
- Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
2005
+ 格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSSSSSSSS` format string, default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
2006
+ 秒的格式为 ss (必须包含); 纳秒的格式为 SSSSSSSSS (必须包含) Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
2004
2007
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
2005
2008
  */
2006
2009
  export function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
@@ -2013,10 +2016,10 @@ export function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.S
2013
2016
  if (nanotimestamp === null || nanotimestamp === nulls.int64)
2014
2017
  return 'null';
2015
2018
  const i_second_start = format.indexOf('ss');
2016
- assert(i_second_start !== -1, 'The format string must contain the format for seconds (ss)');
2019
+ assert(i_second_start !== -1, t('格式串必须包含秒的格式 (ss)'));
2017
2020
  const i_second_end = i_second_start + 2;
2018
2021
  const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
2019
- assert(i_nanosecond_start !== -1, 'Format string must contain nanosecond format (SSSSSSSSS)');
2022
+ assert(i_nanosecond_start !== -1, t('格式串必须包含纳秒的格式 (SSSSSSSSS)'));
2020
2023
  const remainder = nanotimestamp % 1000000000n;
2021
2024
  const borrow = remainder < 0n;
2022
2025
  const ms = Number(nanotimestamp / 1000000n);
@@ -2030,21 +2033,22 @@ export function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.S
2030
2033
  remainder).padStart(9, '0'));
2031
2034
  }
2032
2035
  /** parse nano timestamp string to bigint value
2033
- - str: nano timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
2036
+ - str: nano timestamp string, 如果为空字符串或 'null' 会返回对应的空值 (nulls.int64)
2037
+ nano timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
2034
2038
  - format?:
2035
- The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
2036
- Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
2039
+ 对应传入字符串的格式串,默认是 `YYYY.MM.DD HH:mm:ss.SSSSSSSSS` The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
2040
+ 秒的格式为 ss (必须包含); 纳秒的格式为 SSSSSSSSS (必须包含) Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
2037
2041
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
2038
2042
  */
2039
2043
  export function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
2040
2044
  if (!str || str === 'null')
2041
2045
  return nulls.int64;
2042
- assert(str.length === format.length, 'nanotimestamp string length must be equal to format string length');
2046
+ assert(str.length === format.length, t('nanotimestamp 字符串长度必须等于格式串长度'));
2043
2047
  const i_second_start = format.indexOf('ss');
2044
- assert(i_second_start !== -1, 'The format string must contain the format for seconds (ss)');
2048
+ assert(i_second_start !== -1, t('格式串必须包含秒的格式 (ss)'));
2045
2049
  const i_second_end = i_second_start + 2;
2046
2050
  const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
2047
- assert(i_nanosecond_start !== -1, 'Format string must contain nanosecond format (SSSSSSSSS)');
2051
+ assert(i_nanosecond_start !== -1, t('格式串必须包含纳秒的格式 (SSSSSSSSS)'));
2048
2052
  const ms = dayjs(str.slice(0, i_second_end), format.slice(0, i_second_end)).valueOf();
2049
2053
  return (BigInt(-(1000 * 60 * new Date(ms).getTimezoneOffset()) +
2050
2054
  ms) * 1000000n
@@ -2077,7 +2081,7 @@ export const winsize = 10_0000;
2077
2081
  export class ConnectionError extends Error {
2078
2082
  ddb;
2079
2083
  constructor(ddb) {
2080
- super(`websocket is disconnected: ${ddb.url}`);
2084
+ super(`${t('websocket 连接已断开')}: ${ddb.url}`);
2081
2085
  this.ddb = ddb;
2082
2086
  }
2083
2087
  }
@@ -2104,7 +2108,7 @@ export class DDB {
2104
2108
  password = '123456';
2105
2109
  /** python session flag (2048) */
2106
2110
  python = false;
2107
- /** Whether it is a streaming data connection, this field is always null for non-streaming data */
2111
+ /** 是否为流数据连接,非流数据这个字段恒为 null Whether it is a streaming data connection, this field is always null for non-streaming data */
2108
2112
  streaming = null;
2109
2113
  // --- 内部选项, 状态
2110
2114
  print_message_buffer = false;
@@ -2121,20 +2125,20 @@ export class DDB {
2121
2125
  return this.websocket?.readyState === WebSocket.OPEN;
2122
2126
  }
2123
2127
  /**
2124
- Initialize an instance of DolphinDB Client using the WebSocket URL
2125
- (without establishing an actual network connection)
2128
+ 使用 WebSocket URL 初始化连接到 DolphinDB 的实例(不建立实际的网络连接)
2129
+ Initialize an instance of DolphinDB Client using the WebSocket URL (without establishing an actual network connection)
2126
2130
  - url: DolphinDB WebSocket URL. e.g.:`ws://127.0.0.1:8848`
2127
2131
  - options?:
2128
- - autologin?: Whether to log in automatically after establishing a connection, default `true`
2129
- - username?: DolphinDB username, default `'admin'`
2130
- - password?: DolphinDB password, default `'123456'`
2131
- - python?: set python session flag, default `false`
2132
- - streaming?: When this option is set, the WebSocket connection is only used for streaming data
2132
+ - autologin?: 是否在建立连接后自动登录,默认 `true` Whether to log in automatically after establishing a connection, default `true`
2133
+ - username?: DolphinDB 登录用户名,默认 `'admin'` DolphinDB username, default `'admin'`
2134
+ - password?: DolphinDB 登录密码,默认 `'123456'` DolphinDB password, default `'123456'`
2135
+ - python?: 设置 python session flag,默认 `false` set python session flag, default `false`
2136
+ - streaming?: 设置该选项后,该 WebSocket 连接只用于流数据 When this option is set, the WebSocket connection is only used for streaming data
2133
2137
 
2134
2138
  @example
2135
2139
  let ddb = new DDB('ws://127.0.0.1:8848')
2136
2140
 
2137
- // Encrypt with HTTPS
2141
+ // 使用 HTTPS 加密 Encrypt with HTTPS
2138
2142
  let ddbsecure = new DDB('wss://dolphindb.com', {
2139
2143
  autologin: true,
2140
2144
  username: 'admin',
@@ -2158,9 +2162,9 @@ export class DDB {
2158
2162
  on_message(event) {
2159
2163
  // 这里的实现一定会被 connect 中的实现覆盖
2160
2164
  }
2161
- /** Establish a actual websocket connection to the DolphindB corresponding to the URL
2162
- It is a power, and after calling, it will ensure that it has been connected to the database (ensure that websocket.ReadyState is open), otherwise an error will be reported
2163
- this.autologin automatically log in when it is true */
2165
+ /** 建立实际的 WebSocket 连接到 URL 对应的 DolphinDB Establish a actual websocket connection to the DolphindB corresponding to the URL
2166
+ 是幂等的,调用后会确保已连接到数据库 (确保 websocket.readyState 为 open),否则报错 It is a power, and after calling, it will ensure that it has been connected to the database (ensure that websocket.ReadyState is open), otherwise an error will be reported
2167
+ this.autologin 为 true 时自动登录 this.autologin automatically log in when it is true */
2164
2168
  async connect() {
2165
2169
  if (this.connected)
2166
2170
  return;
@@ -2173,7 +2177,7 @@ export class DDB {
2173
2177
  try {
2174
2178
  if (!this.connected) {
2175
2179
  this.on_message = (event) => {
2176
- assert(false, '这是在调用 this.rpc 之前默认的 on_message, 不应该被调用到,除非建立连接后 server 先推送了 message');
2180
+ assert(false, t('这是在调用 this.rpc 之前默认的 on_message, 不应该被调用到,除非建立连接后 server 先推送了 message'));
2177
2181
  };
2178
2182
  this.presult = Promise.resolve(null);
2179
2183
  this.pnode_run_defined = false;
@@ -2237,7 +2241,7 @@ export class DDB {
2237
2241
  this.websocket.close(1000);
2238
2242
  }
2239
2243
  /** rpc through websocket (function/script/variable command)
2240
- When the DDB is not connected, the call will be automatically connected. When the connection is disconnected, the call will throw the Connectionerror
2244
+ 未连接到 DDB 时调用会自动连接,连接断开时调用会抛出 ConnectionError When the DDB is not connected, the call will be automatically connected. When the connection is disconnected, the call will throw the Connectionerror
2241
2245
  - type: API 类型: 'script' | 'function' | 'variable'
2242
2246
  - options:
2243
2247
  - urgent?: 决定 `行为标识` 那一行字符串的取值(只适用于 script 和 function)
@@ -2375,11 +2379,15 @@ export class DDB {
2375
2379
  return presult;
2376
2380
  }
2377
2381
  /** eval script through websocket (script command)
2378
- - script?: Script to execute
2379
- - options?: execution options
2380
- - urgent?: Urgent flag to ensure that submitted scripts are processed by urgent workers to prevent being blocked by other jobs
2381
- - listener?: Process messages during this rpc (DdbMessage)
2382
- - parse_object?: Set parse_object during this rpc, and restore the original after the end.
2382
+ - script?: 执行的脚本 Script to execute
2383
+ - options?: 执行选项 execution options
2384
+ - urgent?: 紧急 flag,确保提交的脚本使用 urgent worker 处理,防止被其它作业阻塞
2385
+ Urgent flag to ensure that submitted scripts are processed by urgent workers to prevent being blocked by other jobs
2386
+ - listener?: 处理本次 rpc 期间的消息 (DdbMessage)
2387
+ Process messages during this rpc (DdbMessage)
2388
+ - parse_object?: 在该次 rpc 期间设置 parse_object, 结束后恢复原有,为 false 时返回的 DdbObj 仅含有 buffer 和 le,
2389
+ 不做解析,以便后续转发、序列化
2390
+ Set parse_object during this rpc, and restore the original after the end.
2383
2391
  When it is false, the returned DdbObj only contains buffer and le without parsing,
2384
2392
  so as to facilitate subsequent forwarding and serialization
2385
2393
  */
@@ -2387,22 +2395,30 @@ export class DDB {
2387
2395
  return this.rpc('script', { script, urgent, listener, parse_object });
2388
2396
  }
2389
2397
  /** call function through websocket (function command)
2390
- - func: function name
2391
- - args?: `[ ]` Call parameters (the incoming native string and boolean will be automatically converted to DdbObj<string> and DdbObj<boolean>)
2392
- - options?: call options
2393
- - urgent?: Emergency flag. Use urgent worker execution to prevent being blocked by other jobs
2394
- - node?: When the node alias is set, it is sent to the corresponding node in the cluster for execution (using the rpc method in DolphinDB)
2395
- - nodes?: When setting multiple node aliases, send them to the corresponding multiple nodes in the cluster for execution (using the pnodeRun method in DolphinDB)
2396
- - func_type?: It must be passed when setting the node parameter, the function type needs to be specified, and it is not passed in other cases
2397
- - add_node_alias?: Select to pass when setting the nodes parameter, otherwise not pass
2398
- - listener?: Process messages during this rpc (DdbMessage)
2399
- - parse_object?: Set parse_object during this rpc, and restore the original after the end.
2398
+ - func: 函数名 function name
2399
+ - args?: `[ ]` 调用参数 (传入的原生 string 和 boolean 会被自动转换为 DdbObj<string> 和 DdbObj<boolean>) Call parameters (the incoming native string and boolean will be automatically converted to DdbObj<string> and DdbObj<boolean>)
2400
+ - options?: 调用选项 call options
2401
+ - urgent?: 紧急 flag。使用 urgent worker 执行,防止被其它作业阻塞
2402
+ Emergency flag. Use urgent worker execution to prevent being blocked by other jobs
2403
+ - node?: 设置结点 alias 时发送到集群中对应的结点执行 (使用 DolphinDB 中的 rpc 方法)
2404
+ When the node alias is set, it is sent to the corresponding node in the cluster for execution (using the rpc method in DolphinDB)
2405
+ - nodes?: 设置多个结点 alias 时发送到集群中对应的多个结点执行 (使用 DolphinDB 中的 pnodeRun 方法)
2406
+ When setting multiple node aliases, send them to the corresponding multiple nodes in the cluster for execution (using the pnodeRun method in DolphinDB)
2407
+ - func_type?: 设置 node 参数时必传,需指定函数类型,其它情况下不传
2408
+ It must be passed when setting the node parameter, the function type needs to be specified, and it is not passed in other cases
2409
+ - add_node_alias?: 设置 nodes 参数时选传,其它情况不传
2410
+ Select to pass when setting the nodes parameter, otherwise not pass
2411
+ - listener?: 处理本次 rpc 期间的消息 (DdbMessage)
2412
+ Process messages during this rpc (DdbMessage)
2413
+ - parse_object?: 在该次 rpc 期间设置 parse_object, 结束后恢复原有,为 false 时返回的 DdbObj 仅含有 buffer 和 le,
2414
+ 不做解析,以便后续转发、序列化
2415
+ Set parse_object during this rpc, and restore the original after the end.
2400
2416
  When it is false, the returned DdbObj only contains buffer and le without parsing,
2401
2417
  so as to facilitate subsequent forwarding and serialization
2402
2418
  */
2403
2419
  async call(func, args = [], { urgent, node, nodes, func_type, add_node_alias, listener, parse_object, } = {}) {
2404
2420
  if (node) {
2405
- assert(func_type in DdbFunctionType, 'func_type must be set when specifying node');
2421
+ assert(func_type in DdbFunctionType, t('指定 node 时必须设置 func_type'));
2406
2422
  args = [
2407
2423
  node,
2408
2424
  new DdbFunction(func, func_type),
@@ -2435,14 +2451,14 @@ export class DDB {
2435
2451
  }
2436
2452
  /** upload variable through websocket (variable command) */
2437
2453
  async upload(
2438
- /** Uploaded variables' name */
2454
+ /** 上传的变量名 Uploaded variables' name */
2439
2455
  vars,
2440
- /** Uploaded variables' value */
2456
+ /** 上传的变量值 Uploaded variables' value */
2441
2457
  args, { listener, parse_object, } = {}) {
2442
- assert(args.length && args.length === vars.length, 'variable command parameter cannot be empty and parameter name cannot be empty, and the number should match');
2458
+ assert(args.length && args.length === vars.length, t('variable 指令参数不能为空且参数名不能为空,且数量应该匹配'));
2443
2459
  return this.rpc('variable', { vars, args, listener, parse_object });
2444
2460
  }
2445
- /** Cancel all console jobs corresponding to the current session id */
2461
+ /** 取消当前 session id 对应的所有 console jobs Cancel all console jobs corresponding to the current session id */
2446
2462
  async cancel() {
2447
2463
  let ddb = new DDB(this.url, this);
2448
2464
  try {
@@ -2474,7 +2490,7 @@ export class DDB {
2474
2490
  /** session id */
2475
2491
  const sid = parts[0];
2476
2492
  if (sid !== this.sid) {
2477
- console.log(`session.id: ${this.sid} -> ${sid}`);
2493
+ console.log(t('session id 从 {{sid}} 变为 {{sid_}}', { sid: this.sid, sid_: sid }));
2478
2494
  this.sid = sid;
2479
2495
  }
2480
2496
  /** 返回对象的数量 */
@@ -2507,12 +2523,12 @@ export class DDB {
2507
2523
  })
2508
2524
  };
2509
2525
  }
2510
- /** Internal stream subscription method */
2526
+ /** 内部的流订阅方法 Internal stream subscription method */
2511
2527
  async subscribe() {
2512
2528
  await this.rpc('connect', {});
2513
2529
  if (this.autologin)
2514
2530
  await this.call('login', [this.username, this.password]);
2515
- console.log('Subscribed to streaming table, colnames:',
2531
+ console.log(t('订阅流表成功') + ', colnames:',
2516
2532
  // string[3](['time', 'stock', 'price'])
2517
2533
  this.streaming.colnames = (await this.call('publishTable', [
2518
2534
  'localhost',