@hardfin/cli 0.1.1-dev.57 → 0.1.1-dev.58

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
@@ -79,7 +79,8 @@ Inside a `key=value` flag, `=` gives a value as you typed it and `:=` gives it a
79
79
  | `value=36` | the text "36", because a custom field may hold a serial number |
80
80
  | `value:=36` | the number 36 |
81
81
  | `value:=true` | the boolean true |
82
- | `deliverAt:=null` | null |
82
+ | `deliverAt=null` | null, because the field takes it |
83
+ | `deliverAt="null"` | the text "null" |
83
84
  | `order=2` or `order:=2` | the number 2, because the document types `order` as a whole number |
84
85
 
85
86
  A value the field does not take fails locally with exit code 2, such as `order=two`, or
@@ -104,7 +105,18 @@ hardfin location create --input location.json
104
105
  echo '{"name": "Dock 4, north side"}' | hardfin location create --input -
105
106
  ```
106
107
 
107
- Clear a field with `--unset`, naming the flag:
108
+ The word `null` clears a field the API takes null for. It is read before anything else,
109
+ whatever the field holds, and `"null"` in quotes is the text.
110
+
111
+ ```sh
112
+ hardfin asset accounting update ast_4f9xk2mq7plr8stz --useful-life null # clears it
113
+ hardfin asset update ast_4f9xk2mq7plr8stz --description '"null"' # the text null
114
+ ```
115
+
116
+ A field the API does not take null for is sent the word as text. The same holds inside a
117
+ `key=value` flag, as in `deliverAt=null`.
118
+
119
+ `--unset` clears a field too, naming the flag:
108
120
 
109
121
  ```sh
110
122
  hardfin asset accounting update ast_4f9xk2mq7plr8stz --unset useful-life
package/dist/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="1c7d3a24-925a-543e-a2eb-caf5f5968ada")}catch(e){}}();
3
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="a7e96225-360e-5093-91ec-0d60c0a9c032")}catch(e){}}();
4
4
  import module from "node:module";
5
5
  //#region src/cli.ts
6
6
  module.enableCompileCache?.();
@@ -14,7 +14,7 @@ process.on("unhandledRejection", (error) => void toCrash(error));
14
14
  try {
15
15
  const answer = await toQuickAnswer(process.argv.slice(2));
16
16
  if (answer === void 0) {
17
- const { toCli, toParseExitCode, wasReportAttempted } = await import("./program-PaNgBWFL.js");
17
+ const { toCli, toParseExitCode, wasReportAttempted } = await import("./program-C2DP0mVy.js");
18
18
  try {
19
19
  await toCli().parseAsync(process.argv);
20
20
  } catch (error) {
@@ -33,7 +33,7 @@ async function toCrash(error) {
33
33
  isCrashing = true;
34
34
  const isJSON = process.argv.includes("--json") || !process.stdout.isTTY;
35
35
  try {
36
- const { toReported, writeCrash } = await import("./program-PaNgBWFL.js");
36
+ const { toReported, writeCrash } = await import("./program-C2DP0mVy.js");
37
37
  writeCrash(error, isJSON);
38
38
  await toReported(error, isJSON, void 0, "fatal");
39
39
  } catch {
@@ -54,4 +54,4 @@ async function toQuickAnswer(args) {
54
54
  export {};
55
55
 
56
56
  //# sourceMappingURL=cli.js.map
57
- //# debugId=1c7d3a24-925a-543e-a2eb-caf5f5968ada
57
+ //# debugId=a7e96225-360e-5093-91ec-0d60c0a9c032
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="566d9b65-d8fb-507d-8b0e-a21deb646246")}catch(e){}}();
3
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="b26e6779-10c9-5732-b40c-04e75265338c")}catch(e){}}();
4
4
  import { a as defineCommand, i as GLOBAL_FLAGS, r as ExitCode, t as toInvocation } from "./scrub-BZ0egWxC.js";
5
5
  import { n as toAnswer$1, r as toCompletion, t as PATH_VALUES } from "./completion-tree-DLC6ARLR.js";
6
6
  import { createRequire } from "node:module";
@@ -1568,6 +1568,16 @@ function toJSONInput(source) {
1568
1568
  function toEnum(values) {
1569
1569
  return z.string().transform((value) => values.find((allowed) => allowed.toLowerCase() === value.toLowerCase()) ?? value).pipe(z.enum(values));
1570
1570
  }
1571
+ /** The word that clears a field the API takes null for, and the way to send that word as text. */
1572
+ const NULL_WORD = "null";
1573
+ /**
1574
+ * toNullOrText reads the word null before anything else. A field the API takes null for is
1575
+ * cleared by it, and "null" in quotes is the text. Any other value comes back as it was.
1576
+ */
1577
+ function toNullOrText(value, isNullable) {
1578
+ if (value === "\"null\"") return NULL_WORD;
1579
+ return isNullable && value === "null" ? null : value;
1580
+ }
1571
1581
  const UNSET_FLAG = {
1572
1582
  name: "unset",
1573
1583
  description: "A field to clear, named as its flag is, repeatable",
@@ -1798,8 +1808,14 @@ function toBody(operation, flags, given) {
1798
1808
  hasField = true;
1799
1809
  continue;
1800
1810
  }
1801
- const parsed = flag.schema.safeParse(value);
1802
- set(body, flag.jsonPath, parsed.success ? parsed.data : value);
1811
+ const given = toNullOrText(value, flag.nullable === true);
1812
+ if (given === null) {
1813
+ set(body, flag.jsonPath, null);
1814
+ hasField = true;
1815
+ continue;
1816
+ }
1817
+ const parsed = flag.schema.safeParse(given);
1818
+ set(body, flag.jsonPath, parsed.success ? parsed.data : given);
1803
1819
  hasField = true;
1804
1820
  }
1805
1821
  const cleared = toCleared(operation, flags, body);
@@ -1850,8 +1866,9 @@ const NUMBER = /^-?\d+(\.\d+)?$/;
1850
1866
  * field that takes no text has only one reading, so order=2 is sent as the number.
1851
1867
  */
1852
1868
  function toTyped(text, types) {
1869
+ const given = toNullOrText(text, types?.includes("null") === true);
1870
+ if (given === null || given !== text) return given;
1853
1871
  if (types === void 0 || types.includes("string")) return text;
1854
- if (types.includes("null") && text === "null") return null;
1855
1872
  if ((types.includes("integer") || types.includes("number")) && NUMBER.test(text)) {
1856
1873
  const value = Number(text);
1857
1874
  if (types.includes("number") || Number.isInteger(value)) return value;
@@ -4796,6 +4813,7 @@ const commands = [
4796
4813
  jsonPath: ["depreciationModel"],
4797
4814
  description: "The method one unit is depreciated by, or null to clear it",
4798
4815
  valueName: "value",
4816
+ nullable: true,
4799
4817
  schema: toEnum([
4800
4818
  "DOUBLE_DECLINING",
4801
4819
  "STRAIGHT_LINE",
@@ -5161,6 +5179,7 @@ const commands = [
5161
5179
  jsonPath: ["depreciationModel"],
5162
5180
  description: "The method one unit is depreciated by, or null to clear it",
5163
5181
  valueName: "value",
5182
+ nullable: true,
5164
5183
  schema: toEnum([
5165
5184
  "DOUBLE_DECLINING",
5166
5185
  "STRAIGHT_LINE",
@@ -6537,6 +6556,7 @@ const commands = [
6537
6556
  jsonPath: ["depreciationModel"],
6538
6557
  description: "The method one unit is depreciated by, or null to clear it",
6539
6558
  valueName: "value",
6559
+ nullable: true,
6540
6560
  schema: toEnum([
6541
6561
  "DOUBLE_DECLINING",
6542
6562
  "STRAIGHT_LINE",
@@ -6970,6 +6990,7 @@ const commands = [
6970
6990
  jsonPath: ["type"],
6971
6991
  description: "SITE for a site, or ZONE for a zone within a site",
6972
6992
  valueName: "value",
6993
+ nullable: true,
6973
6994
  schema: toEnum([
6974
6995
  "SITE",
6975
6996
  "UNKNOWN",
@@ -7130,6 +7151,7 @@ const commands = [
7130
7151
  jsonPath: ["type"],
7131
7152
  description: "SITE for a site, or ZONE for a zone within a site",
7132
7153
  valueName: "value",
7154
+ nullable: true,
7133
7155
  schema: toEnum([
7134
7156
  "SITE",
7135
7157
  "UNKNOWN",
@@ -7270,7 +7292,9 @@ function toRejectedFlag(command, flags) {
7270
7292
  for (const flag of command.flags) {
7271
7293
  const value = flags[toOptionKey(flag.name)];
7272
7294
  if (value === void 0) continue;
7273
- if (!flag.schema.safeParse(value).success) return `--${flag.name} does not accept ${JSON.stringify(value)}`;
7295
+ const given = toNullOrText(value, flag.nullable === true);
7296
+ if (given === null) continue;
7297
+ if (!flag.schema.safeParse(given).success) return `--${flag.name} does not accept ${JSON.stringify(value)}`;
7274
7298
  }
7275
7299
  }
7276
7300
  //#endregion
@@ -7357,5 +7381,5 @@ async function toReported(error, isJSON, resolved, level = "error") {
7357
7381
  //#endregion
7358
7382
  export { toCli, toParseExitCode, toReported, wasReportAttempted, writeCrash };
7359
7383
 
7360
- //# sourceMappingURL=program-PaNgBWFL.js.map
7361
- //# debugId=566d9b65-d8fb-507d-8b0e-a21deb646246
7384
+ //# sourceMappingURL=program-C2DP0mVy.js.map
7385
+ //# debugId=b26e6779-10c9-5732-b40c-04e75265338c
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hardfin/cli",
3
- "version": "0.1.1-dev.57",
3
+ "version": "0.1.1-dev.58",
4
4
  "description": "Command line interface for the Hardfin API",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Hardfin, Inc.",