@hcmai/sdk 0.4.14 → 0.4.16

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/dist/index.d.ts CHANGED
@@ -266,11 +266,22 @@ interface CreateResult {
266
266
  id: string;
267
267
  [key: string]: unknown;
268
268
  }
269
+ interface WriteOpts {
270
+ /**
271
+ * 多语言字段的写入形态(后端 `?i18n=` 查询参数)。
272
+ *
273
+ * - 不传 / false(默认):多语言字段收**字符串**,只更新当前语言,其余语言保留
274
+ * - true:多语言字段收 **Map**(键是 `zh-CN` / `en-US` 这类连字符形),完整替换所有语言
275
+ *
276
+ * 🔴 形态与模式必须匹配,否则后端报 `DTO转换错误`——而错误里不会告诉你缺的是这个开关。
277
+ */
278
+ i18n?: boolean;
279
+ }
269
280
  /** 创建一条 Model 记录,走后端 Model 层完整校验。
270
281
  * 注:返回体形态(尤其 id 字段名)见 spec §12.3,实现期对真后端核实。 */
271
- declare function create(http: AxiosInstance, model: string, data: Record<string, unknown>): Promise<CreateResult>;
282
+ declare function create(http: AxiosInstance, model: string, data: Record<string, unknown>, opts?: WriteOpts): Promise<CreateResult>;
272
283
 
273
- declare function update(http: AxiosInstance, model: string, id: string, data: Record<string, unknown>): Promise<CreateResult>;
284
+ declare function update(http: AxiosInstance, model: string, id: string, data: Record<string, unknown>, opts?: WriteOpts): Promise<CreateResult>;
274
285
 
275
286
  interface RemoveResult {
276
287
  id: string;
@@ -416,8 +427,8 @@ declare class HcmClient {
416
427
  /** 列出目标环境有哪些 Model —— `describe` 的上一步。 */
417
428
  listModels(): Promise<ModelEntry[]>;
418
429
  describe(model: string, opts?: DescribeOpts): Promise<ModelDescription>;
419
- create(model: string, data: Record<string, unknown>): Promise<CreateResult>;
420
- update(model: string, id: string, data: Record<string, unknown>): Promise<CreateResult>;
430
+ create(model: string, data: Record<string, unknown>, opts?: WriteOpts): Promise<CreateResult>;
431
+ update(model: string, id: string, data: Record<string, unknown>, opts?: WriteOpts): Promise<CreateResult>;
421
432
  remove(model: string, id: string): Promise<RemoveResult>;
422
433
  /** 按业务键查已存在记录的 id(幂等用);命中返回 id,否则 null。 */
423
434
  findIdByKey(model: string, keyField: string, keyValue: string): Promise<string | null>;
package/dist/index.js CHANGED
@@ -1365,14 +1365,17 @@ async function listModels(http) {
1365
1365
  }
1366
1366
 
1367
1367
  // src/models/create.ts
1368
- async function create(http, model, data) {
1369
- const resp = await http.post(`/api/models/${model}`, data);
1368
+ function writeParams(opts) {
1369
+ return opts?.i18n ? { params: { i18n: "true" } } : {};
1370
+ }
1371
+ async function create(http, model, data, opts) {
1372
+ const resp = await http.post(`/api/models/${model}`, data, writeParams(opts));
1370
1373
  return resp.data;
1371
1374
  }
1372
1375
 
1373
1376
  // src/models/update.ts
1374
- async function update(http, model, id, data) {
1375
- const resp = await http.put(`/api/models/${model}/${id}`, data);
1377
+ async function update(http, model, id, data, opts) {
1378
+ const resp = await http.put(`/api/models/${model}/${id}`, data, writeParams(opts));
1376
1379
  return resp.data;
1377
1380
  }
1378
1381
 
@@ -1620,11 +1623,11 @@ var HcmClient = class _HcmClient {
1620
1623
  describe(model, opts) {
1621
1624
  return describe(this.http, model, opts);
1622
1625
  }
1623
- create(model, data) {
1624
- return create(this.http, model, data);
1626
+ create(model, data, opts) {
1627
+ return create(this.http, model, data, opts);
1625
1628
  }
1626
- update(model, id, data) {
1627
- return update(this.http, model, id, data);
1629
+ update(model, id, data, opts) {
1630
+ return update(this.http, model, id, data, opts);
1628
1631
  }
1629
1632
  remove(model, id) {
1630
1633
  return remove(this.http, model, id);