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

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.3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/runtime/index.js CHANGED
@@ -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,72 @@ var EXPECTED = {
13234
13260
  record: "an object"
13235
13261
  };
13236
13262
  var requiredMessage = (plan) => `\xAB${plan.label}\xBB is required`;
13263
+ var oneOf = (values) => `one of: ${values.map(String).join(", ")}`;
13264
+ var formatPhrase = (format) => {
13265
+ const described = FORMAT_DESCRIPTIONS[format ?? ""];
13266
+ return described?.replace(/^Expects (.*?), e\.g\. (.*)$/, "$1 (e.g. $2)").replace(/^Expects /, "");
13267
+ };
13268
+ var distinct = (phrases) => [...new Set(phrases.filter((phrase) => !!phrase))];
13269
+ function unionPhrases(union, value) {
13270
+ return distinct((inspect(union).branches ?? []).map((branch) => {
13271
+ try {
13272
+ const result = branch.safeParse(value);
13273
+ return branchPhrase(branch, result.error?.issues[0]);
13274
+ } catch {
13275
+ return void 0;
13276
+ }
13277
+ }));
13278
+ }
13279
+ function remainingIssue(branch, value) {
13280
+ if (!branch) {
13281
+ return void 0;
13282
+ }
13283
+ try {
13284
+ const result = branch.safeParse(coerceDeep(value, branch));
13285
+ return result.success ? void 0 : result.error?.issues[0];
13286
+ } catch {
13287
+ return void 0;
13288
+ }
13289
+ }
13290
+ function branchPhrase(branch, issue) {
13291
+ if (!branch || !issue) {
13292
+ return void 0;
13293
+ }
13294
+ const ins = inspect(branch);
13295
+ const values = ins.core._zod?.def?.values ?? [];
13296
+ if (ins.coreType === "literal" && values.length === 1 && values[0] === "") {
13297
+ return void 0;
13298
+ }
13299
+ const dateKind = dateStringKind(ins);
13300
+ if (dateKind) {
13301
+ return expectedDateString(ins, dateKind);
13302
+ }
13303
+ switch (issue.code) {
13304
+ case "invalid_type":
13305
+ return EXPECTED[issue.expected ?? ""] ?? issue.expected;
13306
+ case "invalid_value":
13307
+ return oneOf(issue.values ?? values);
13308
+ case "invalid_format":
13309
+ return formatPhrase(issue.format);
13310
+ // A bound has no short phrase ("a number of at least 10"); the branch still names its type.
13311
+ case "too_small":
13312
+ case "too_big":
13313
+ return EXPECTED[ins.coreType === "literal" ? literalType(ins.core) ?? "" : ins.coreType];
13314
+ default:
13315
+ return void 0;
13316
+ }
13317
+ }
13318
+ function unionIssue(plan, issue, union, unionValue, fieldValue) {
13319
+ const branches = union ? inspect(union).branches : void 0;
13320
+ const errors = issue.errors ?? [];
13321
+ const deepIndex = errors.findIndex((branchIssues) => branchIssues.some((branchIssue) => (branchIssue.path ?? []).length));
13322
+ if (deepIndex >= 0) {
13323
+ const deep = remainingIssue(branches?.[deepIndex], unionValue) ?? errors[deepIndex].find((branchIssue) => (branchIssue.path ?? []).length);
13324
+ return toFieldIssue(plan, { ...deep, path: [...issue.path ?? [], ...deep.path ?? []] }, fieldValue);
13325
+ }
13326
+ const phrases = distinct(errors.map((branchIssues, index) => branchPhrase(branches?.[index], branchIssues[0])));
13327
+ return phrases.length ? { path: "", code: "invalid_union", message: `must be ${phrases.join(", or ")}` } : void 0;
13328
+ }
13237
13329
  var invalidTypeMessage = (plan, expected) => `\xAB${plan.label}\xBB must be ${EXPECTED[expected] ?? expected}`;
13238
13330
  var isIndex = (segment) => /^\d+$/.test(segment);
13239
13331
  function resolveTarget(plan, segments, fieldValue) {
@@ -13280,6 +13372,12 @@ function toFieldIssue(plan, issue, fieldValue) {
13280
13372
  if (isAuthored(issue)) {
13281
13373
  return { path: path2, code, message: issue.message };
13282
13374
  }
13375
+ if (code !== "invalid_union" && target.schema && inspect(target.schema).branches) {
13376
+ const combined = unionPhrases(target.schema, target.value);
13377
+ if (combined.length > 1) {
13378
+ return { path: path2, code: "invalid_union", message: `\xAB${target.label}\xBB must be ${combined.join(", or ")}` };
13379
+ }
13380
+ }
13283
13381
  const dateKind = target.schema ? dateStringKind(inspect(target.schema)) : void 0;
13284
13382
  const dateMissing = target.value == null || target.value === "";
13285
13383
  if (dateKind && (code === "invalid_type" || code === "invalid_format")) {
@@ -13297,13 +13395,18 @@ function toFieldIssue(plan, issue, fieldValue) {
13297
13395
  return { path: path2, code, message: `\xAB${target.label}\xBB must be at most ${bound(issue.maximum, plan)}` };
13298
13396
  }
13299
13397
  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(", ")}` };
13398
+ return { path: path2, code, message: `\xAB${target.label}\xBB must be ${oneOf(issue.values ?? [])}` };
13302
13399
  }
13303
13400
  if (code === "invalid_format") {
13304
13401
  const described = FORMAT_DESCRIPTIONS[issue.format ?? ""];
13305
13402
  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
13403
  }
13404
+ if (code === "invalid_union") {
13405
+ const combined = unionIssue(plan, issue, target.schema, target.value, fieldValue);
13406
+ if (combined) {
13407
+ return combined.path ? combined : { path: path2, code, message: `\xAB${target.label}\xBB ${combined.message}` };
13408
+ }
13409
+ }
13307
13410
  return { path: path2, code, message: `\xAB${target.label}\xBB is invalid` };
13308
13411
  }
13309
13412
 
@@ -13324,7 +13427,7 @@ function isAbsent(value, plan) {
13324
13427
  return false;
13325
13428
  }
13326
13429
  if (plan.isUnion) {
13327
- return true;
13430
+ return !plan.blankBranch || plan.absorbsBlank;
13328
13431
  }
13329
13432
  if (plan.blankIsValue) {
13330
13433
  return plan.absorbsBlank;
@@ -14594,7 +14697,19 @@ var ExecutionContext = class _ExecutionContext {
14594
14697
  return this.#options.invocation ?? {};
14595
14698
  }
14596
14699
  get config() {
14597
- this.#config ??= this.#extension.config.resolve(this.#options.configs);
14700
+ if (!this.#config) {
14701
+ const { result, notices } = collectNotices(() => this.#extension.config.resolve(this.#options.configs));
14702
+ for (const { message, field, value, converted } of notices) {
14703
+ this.logger.warn(`[flow-extension:${this.#extension.id}] config item "${field ?? "?"}": ${message}`, {
14704
+ serviceId: this.#extension.id,
14705
+ configItem: field,
14706
+ value,
14707
+ converted,
14708
+ ...this.invocation
14709
+ });
14710
+ }
14711
+ this.#config = result;
14712
+ }
14598
14713
  return this.#config;
14599
14714
  }
14600
14715
  // The header access token plus its deserialized composite payload — or a throwing proxy when the