@tuanhv/op-cli 0.3.0 → 0.3.1

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.
@@ -1,7 +1,7 @@
1
1
  import { OpCliError, writeRefusal } from "../core/errors.js";
2
2
  import { buildWpFilters, filtersQuery, } from "../core/filters.js";
3
3
  import { defineCollectionCommand, emitRows, PAGED_JSON_HELP, } from "../core/define.js";
4
- import { flattenHalRecord, isFlatLink } from "../core/hal.js";
4
+ import { flattenHalRecord, isFlatLink, toFormattable } from "../core/hal.js";
5
5
  import { apiDelete, apiGet, apiPost, apiPatchRaw, apiPostRaw, authenticate, } from "../core/http.js";
6
6
  import { allPageSize, DEFAULT_PAGE_SIZE, halElements, parsePageSize, withPageSize, } from "../core/paginate.js";
7
7
  import { explicitCustomFieldKey, isIdForm, matchByName, rankByCloseness, resolveName, } from "../context/resolve.js";
@@ -1008,6 +1008,9 @@ async function resolveNamedValues(runtime, profile, options, memo) {
1008
1008
  // option would have gone.
1009
1009
  await listFieldValues(runtime, profile, field, [], links, refs, memo);
1010
1010
  }
1011
+ else if (field.is_formattable === true) {
1012
+ payload[field.key] = toFormattable("");
1013
+ }
1011
1014
  else {
1012
1015
  payload[field.key] = null;
1013
1016
  }
@@ -1031,6 +1034,13 @@ async function resolveNamedValues(runtime, profile, options, memo) {
1031
1034
  await userFieldValue(runtime, profile, field, pairs[0]?.value ?? "", payload, refs, memo);
1032
1035
  continue;
1033
1036
  }
1037
+ if (field.is_formattable === true) {
1038
+ if (pairs.length > 1) {
1039
+ throw new OpCliError("USAGE_ERROR", `--field "${field.name}" holds one value.`, "long-text fields take a single value.");
1040
+ }
1041
+ payload[field.key] = toFormattable(pairs[0]?.value ?? "");
1042
+ continue;
1043
+ }
1034
1044
  const values = pairs.map((pair) => pair.value);
1035
1045
  payload[field.key] = values.length === 1 ? values[0] : values;
1036
1046
  }
@@ -171,8 +171,8 @@ function customFieldEntries(schema) {
171
171
  continue;
172
172
  }
173
173
  // The schema `type` decides input validation downstream; anything
174
- // beyond Boolean/User/CustomOption stays unmarked and passes through
175
- // as text. A multi-valued field spells its kind "[]Kind".
174
+ // beyond Boolean/User/Formattable/CustomOption stays unmarked and
175
+ // passes through as text. A multi-valued field spells its kind "[]Kind".
176
176
  const kind = asString(property.type).toLowerCase();
177
177
  const single = kind.replace(/^\[\]/, "");
178
178
  const isUser = kind === "user";
@@ -193,6 +193,7 @@ function customFieldEntries(schema) {
193
193
  : {}),
194
194
  ...(kind === "boolean" ? { is_boolean: true } : {}),
195
195
  ...(isUser ? { is_user: true } : {}),
196
+ ...(kind === "formattable" ? { is_formattable: true } : {}),
196
197
  ...(isList ? { is_list: true, allowed_options: options } : {}),
197
198
  ...(kind.startsWith("[]") ? { is_multi: true } : {}),
198
199
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuanhv/op-cli",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "A resolving command-line client for OpenProject",
5
5
  "license": "MIT",
6
6
  "author": "hoangvantuan",