@flowrunner/cli 0.1.18-dev.1 → 0.1.18-dev.2

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.
@@ -17,10 +17,10 @@ export interface FieldPlan {
17
17
  *
18
18
  * Carried because `coreType` alone stops describing the field: a union resolves to its first branch, so a
19
19
  * `z.union([z.email(), z.literal('')])` reports `'string'` and would then treat a blank as a VALUE. It is
20
- * not one — `''` has always been absence on a union, which is exactly what makes the documented
21
- * "blank means not set" spelling (`z.union([z.url(), z.literal('')]).optional()`) work.
20
+ * not one — `''` is absence on a union, unless the union declares it (`blankBranch`).
22
21
  */
23
22
  isUnion: boolean;
23
+ blankBranch: boolean;
24
24
  absence: AbsencePolicy;
25
25
  absorbsBlank: boolean;
26
26
  keepsEmpty: boolean;
@@ -53,6 +53,14 @@ export interface WidgetInfo {
53
53
  };
54
54
  }
55
55
  export declare function literalType(core: AnyZod): string | undefined;
56
+ /**
57
+ * True when a union declares `''` as one of its forms — a `z.literal('')` branch (FR-3933).
58
+ *
59
+ * On such a union `''` is a VALUE, not a blank: the author listed it, so it is the deliberate "empty" a flow
60
+ * sends (the Empty Text chip, a bound `''`), while `null` and a missing value stay "not provided". That is the
61
+ * only way a flow can clear a date: an untouched block field arrives as `null`, so `null` cannot mean "clear".
62
+ */
63
+ export declare function hasBlankBranch(ins: Inspected): boolean;
56
64
  export declare function deriveWidget(ins: Inspected): WidgetInfo;
57
65
  export declare function shapeEntries(schema: AnyZod | undefined): [name: string, schema: AnyZod][];
58
66
  export declare function fieldLabels(schema: AnyZod): Record<string, string> | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowrunner/cli",
3
- "version": "0.1.18-dev.1",
3
+ "version": "0.1.18-dev.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/runtime/index.js CHANGED
@@ -9836,8 +9836,8 @@ var require_get_intrinsic = __commonJS({
9836
9836
  throw new $SyntaxError("invalid intrinsic syntax, expected opening `%`");
9837
9837
  }
9838
9838
  var result = [];
9839
- $replace(string, rePropName, function(match, number, quote, subString) {
9840
- result[result.length] = quote ? $replace(subString, reEscapeChar, "$1") : number || match;
9839
+ $replace(string, rePropName, function(match, number, quote2, subString) {
9840
+ result[result.length] = quote2 ? $replace(subString, reEscapeChar, "$1") : number || match;
9841
9841
  });
9842
9842
  return result;
9843
9843
  };
@@ -12049,6 +12049,12 @@ function literalType(core) {
12049
12049
  const [kind] = [...kinds];
12050
12050
  return kinds.size === 1 && LITERAL_KINDS.has(kind) ? kind : void 0;
12051
12051
  }
12052
+ function hasBlankBranch(ins) {
12053
+ return !!ins.branches?.some((branch) => {
12054
+ const { core, coreType } = inspect(branch);
12055
+ return coreType === "literal" && (core._zod?.def?.values ?? []).includes("");
12056
+ });
12057
+ }
12052
12058
  function deriveWidget(ins) {
12053
12059
  const { coreType, core, meta } = ins;
12054
12060
  switch (coreType) {
@@ -12235,6 +12241,11 @@ function compilePattern(pattern, kind) {
12235
12241
  if (missing.length) {
12236
12242
  throw new DateFormatError(`is missing ${missing.join(", ")} \u2014 every part of a ${describeKind(kind)} must be in it`);
12237
12243
  }
12244
+ if ((names.includes("HH") || names.includes("H")) && names.includes("a")) {
12245
+ throw new DateFormatError(
12246
+ "uses a 24-hour clock (`HH` / `H`) with `a` \u2014 13:45 would be written `13:45 PM`, which cannot be read back. Use `hh` / `h` with `a`, or `HH` without it"
12247
+ );
12248
+ }
12238
12249
  if ((names.includes("hh") || names.includes("h")) && !names.includes("a")) {
12239
12250
  throw new DateFormatError(
12240
12251
  "uses a 12-hour clock (`hh` / `h`) without `a` \u2014 without AM/PM the value cannot be read back. Add `a`, or use `HH` for a 24-hour clock"
@@ -12383,7 +12394,21 @@ function canonicalToPattern(canonical, ins, kind) {
12383
12394
  const parts = parseIso(canonical, kind);
12384
12395
  return parts ? formatParts(parts, pattern, kind) : canonical;
12385
12396
  }
12386
- var isTimestamp = (value) => typeof value === "number" && Number.isFinite(value) || typeof value === "string" && /^-?\d+(\.\d+)?$/.test(value.trim());
12397
+ var MIN_TIMESTAMP_DIGITS = 13;
12398
+ function digitOnlyLength(pattern, kind) {
12399
+ const example = formatParts(EXAMPLE, pattern, kind);
12400
+ return /^\d+$/.test(example) ? example.length : void 0;
12401
+ }
12402
+ function isTimestamp(value, pattern, kind) {
12403
+ if (typeof value === "number") {
12404
+ return Number.isFinite(value);
12405
+ }
12406
+ if (typeof value !== "string") {
12407
+ return false;
12408
+ }
12409
+ const text2 = value.trim();
12410
+ return new RegExp(`^\\d{${MIN_TIMESTAMP_DIGITS},}$`).test(text2) && digitOnlyLength(pattern, kind) !== text2.length;
12411
+ }
12387
12412
  function timestampParts(value, kind) {
12388
12413
  const date = new Date(Number(value));
12389
12414
  if (Number.isNaN(date.getTime())) {
@@ -12400,15 +12425,15 @@ function timestampParts(value, kind) {
12400
12425
  }, kind);
12401
12426
  }
12402
12427
  function toDateString(value, ins, kind) {
12403
- if (typeof value === "string") {
12404
- const text2 = value.trim();
12405
- const pattern = ins.meta.frDateFormat;
12406
- const parts = (pattern ? parseInPattern(text2, pattern, kind) : void 0) ?? parseIso(text2, kind);
12428
+ const pattern = ins.meta.frDateFormat;
12429
+ const text2 = typeof value === "string" ? value.trim() : typeof value === "number" && Number.isInteger(value) && value >= 0 ? String(value) : void 0;
12430
+ if (text2 !== void 0) {
12431
+ const parts = (pattern ? parseInPattern(text2, pattern, kind) : void 0) ?? (typeof value === "string" ? parseIso(text2, kind) : void 0);
12407
12432
  if (parts) {
12408
12433
  return { canonical: toCanonical(parts, kind) };
12409
12434
  }
12410
12435
  }
12411
- if (DATE_STRINGS_ACCEPT_TIMESTAMPS && isTimestamp(value)) {
12436
+ if (DATE_STRINGS_ACCEPT_TIMESTAMPS && isTimestamp(value, patternOf(ins, kind), kind)) {
12412
12437
  const parts = timestampParts(value, kind);
12413
12438
  return parts ? { canonical: toCanonical(parts, kind), fromTimestamp: true } : {};
12414
12439
  }
@@ -12913,6 +12938,7 @@ function planField(name, schema) {
12913
12938
  label: labelOf(name, schema),
12914
12939
  coreType: ins.coreType,
12915
12940
  isUnion: !!ins.branches,
12941
+ blankBranch: hasBlankBranch(ins),
12916
12942
  absence,
12917
12943
  absorbsBlank,
12918
12944
  keepsEmpty,
@@ -13165,7 +13191,7 @@ function isBlank(value, ins, schema) {
13165
13191
  return false;
13166
13192
  }
13167
13193
  if (ins.branches) {
13168
- return true;
13194
+ return !hasBlankBranch(ins) || absenceOf(schema).absorbsBlank;
13169
13195
  }
13170
13196
  if (absenceOf(schema).blankIsValue) {
13171
13197
  return absenceOf(schema).absorbsBlank;
@@ -13234,6 +13260,73 @@ var EXPECTED = {
13234
13260
  record: "an object"
13235
13261
  };
13236
13262
  var requiredMessage = (plan) => `\xAB${plan.label}\xBB is required`;
13263
+ var quote = (value) => typeof value === "string" ? JSON.stringify(value) : String(value);
13264
+ var oneOf = (values) => values.length === 1 ? quote(values[0]) : `one of: ${values.map(quote).join(", ")}`;
13265
+ var formatPhrase = (format) => {
13266
+ const described = FORMAT_DESCRIPTIONS[format ?? ""];
13267
+ return described?.replace(/^Expects (.*?), e\.g\. (.*)$/, "$1 (e.g. $2)").replace(/^Expects /, "");
13268
+ };
13269
+ var distinct = (phrases) => [...new Set(phrases.filter((phrase) => !!phrase))];
13270
+ function unionPhrases(union, value) {
13271
+ return distinct((inspect(union).branches ?? []).map((branch) => {
13272
+ try {
13273
+ const result = branch.safeParse(value);
13274
+ return branchPhrase(branch, result.error?.issues[0]);
13275
+ } catch {
13276
+ return void 0;
13277
+ }
13278
+ }));
13279
+ }
13280
+ function remainingIssue(branch, value) {
13281
+ if (!branch) {
13282
+ return void 0;
13283
+ }
13284
+ try {
13285
+ const result = branch.safeParse(coerceDeep(value, branch));
13286
+ return result.success ? void 0 : result.error?.issues[0];
13287
+ } catch {
13288
+ return void 0;
13289
+ }
13290
+ }
13291
+ function branchPhrase(branch, issue) {
13292
+ if (!branch || !issue) {
13293
+ return void 0;
13294
+ }
13295
+ const ins = inspect(branch);
13296
+ const values = ins.core._zod?.def?.values ?? [];
13297
+ if (ins.coreType === "literal" && values.length === 1 && values[0] === "") {
13298
+ return void 0;
13299
+ }
13300
+ const dateKind = dateStringKind(ins);
13301
+ if (dateKind) {
13302
+ return expectedDateString(ins, dateKind);
13303
+ }
13304
+ switch (issue.code) {
13305
+ case "invalid_type":
13306
+ return EXPECTED[issue.expected ?? ""] ?? issue.expected;
13307
+ case "invalid_value":
13308
+ return oneOf(issue.values ?? values);
13309
+ case "invalid_format":
13310
+ return formatPhrase(issue.format);
13311
+ // A bound has no short phrase ("a number of at least 10"); the branch still names its type.
13312
+ case "too_small":
13313
+ case "too_big":
13314
+ return EXPECTED[ins.coreType === "literal" ? literalType(ins.core) ?? "" : ins.coreType];
13315
+ default:
13316
+ return void 0;
13317
+ }
13318
+ }
13319
+ function unionIssue(plan, issue, union, unionValue, fieldValue) {
13320
+ const branches = union ? inspect(union).branches : void 0;
13321
+ const errors = issue.errors ?? [];
13322
+ const deepIndex = errors.findIndex((branchIssues) => branchIssues.some((branchIssue) => (branchIssue.path ?? []).length));
13323
+ if (deepIndex >= 0) {
13324
+ const deep = remainingIssue(branches?.[deepIndex], unionValue) ?? errors[deepIndex].find((branchIssue) => (branchIssue.path ?? []).length);
13325
+ return toFieldIssue(plan, { ...deep, path: [...issue.path ?? [], ...deep.path ?? []] }, fieldValue);
13326
+ }
13327
+ const phrases = distinct(errors.map((branchIssues, index) => branchPhrase(branches?.[index], branchIssues[0])));
13328
+ return phrases.length ? { path: "", code: "invalid_union", message: `must be ${phrases.join(", or ")}` } : void 0;
13329
+ }
13237
13330
  var invalidTypeMessage = (plan, expected) => `\xAB${plan.label}\xBB must be ${EXPECTED[expected] ?? expected}`;
13238
13331
  var isIndex = (segment) => /^\d+$/.test(segment);
13239
13332
  function resolveTarget(plan, segments, fieldValue) {
@@ -13280,6 +13373,12 @@ function toFieldIssue(plan, issue, fieldValue) {
13280
13373
  if (isAuthored(issue)) {
13281
13374
  return { path: path2, code, message: issue.message };
13282
13375
  }
13376
+ if (code !== "invalid_union" && target.schema && inspect(target.schema).branches) {
13377
+ const combined = unionPhrases(target.schema, target.value);
13378
+ if (combined.length > 1) {
13379
+ return { path: path2, code: "invalid_union", message: `\xAB${target.label}\xBB must be ${combined.join(", or ")}` };
13380
+ }
13381
+ }
13283
13382
  const dateKind = target.schema ? dateStringKind(inspect(target.schema)) : void 0;
13284
13383
  const dateMissing = target.value == null || target.value === "";
13285
13384
  if (dateKind && (code === "invalid_type" || code === "invalid_format")) {
@@ -13297,13 +13396,18 @@ function toFieldIssue(plan, issue, fieldValue) {
13297
13396
  return { path: path2, code, message: `\xAB${target.label}\xBB must be at most ${bound(issue.maximum, plan)}` };
13298
13397
  }
13299
13398
  if (code === "invalid_value") {
13300
- const values = (issue.values ?? []).map(String);
13301
- return { path: path2, code, message: `\xAB${target.label}\xBB must be one of: ${values.join(", ")}` };
13399
+ return { path: path2, code, message: `\xAB${target.label}\xBB must be ${oneOf(issue.values ?? [])}` };
13302
13400
  }
13303
13401
  if (code === "invalid_format") {
13304
13402
  const described = FORMAT_DESCRIPTIONS[issue.format ?? ""];
13305
13403
  return described ? { path: path2, code, message: `\xAB${target.label}\xBB is invalid \u2014 ${described.replace(/^Expects /, "expects ")}` } : { path: path2, code, message: `\xAB${target.label}\xBB has an invalid format` };
13306
13404
  }
13405
+ if (code === "invalid_union") {
13406
+ const combined = unionIssue(plan, issue, target.schema, target.value, fieldValue);
13407
+ if (combined) {
13408
+ return combined.path ? combined : { path: path2, code, message: `\xAB${target.label}\xBB ${combined.message}` };
13409
+ }
13410
+ }
13307
13411
  return { path: path2, code, message: `\xAB${target.label}\xBB is invalid` };
13308
13412
  }
13309
13413
 
@@ -13324,7 +13428,7 @@ function isAbsent(value, plan) {
13324
13428
  return false;
13325
13429
  }
13326
13430
  if (plan.isUnion) {
13327
- return true;
13431
+ return !plan.blankBranch || plan.absorbsBlank;
13328
13432
  }
13329
13433
  if (plan.blankIsValue) {
13330
13434
  return plan.absorbsBlank;
@@ -14594,7 +14698,19 @@ var ExecutionContext = class _ExecutionContext {
14594
14698
  return this.#options.invocation ?? {};
14595
14699
  }
14596
14700
  get config() {
14597
- this.#config ??= this.#extension.config.resolve(this.#options.configs);
14701
+ if (!this.#config) {
14702
+ const { result, notices } = collectNotices(() => this.#extension.config.resolve(this.#options.configs));
14703
+ for (const { message, field, value, converted } of notices) {
14704
+ this.logger.warn(`[flow-extension:${this.#extension.id}] config item "${field ?? "?"}": ${message}`, {
14705
+ serviceId: this.#extension.id,
14706
+ configItem: field,
14707
+ value,
14708
+ converted,
14709
+ ...this.invocation
14710
+ });
14711
+ }
14712
+ this.#config = result;
14713
+ }
14598
14714
  return this.#config;
14599
14715
  }
14600
14716
  // The header access token plus its deserialized composite payload — or a throwing proxy when the