@flowrunner/cli 0.1.15 → 0.1.17
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/ai-docs/instructions/service-code-format/02-zod-types.md +96 -18
- package/ai-docs/instructions/service-code-format/07-actions.md +4 -0
- package/ai-docs/instructions/service-code-format/16-gotchas.md +35 -0
- package/dist/cli.js +94 -15
- package/dist/cli.js.map +3 -3
- package/dist/index.js +93 -14
- package/dist/index.js.map +3 -3
- package/dist/types/flow-extension-runner/src/v2/params/schema/field-plan.d.ts +9 -4
- package/dist/types/flow-extension-runner/src/v2/params/zod.d.ts +12 -0
- package/package.json +1 -1
- package/runtime/index.js +93 -14
- package/runtime/index.js.map +3 -3
- package/runtime/types/flow-extension-runner/src/v2/params/schema/field-plan.d.ts +9 -4
- package/runtime/types/flow-extension-runner/src/v2/params/zod.d.ts +12 -0
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { type AnyZod } from './introspect';
|
|
2
2
|
export type AbsencePolicy = 'as-received' | 'undefined' | 'null' | 'required';
|
|
3
|
+
export interface Absence {
|
|
4
|
+
absence: AbsencePolicy;
|
|
5
|
+
absorbsBlank: boolean;
|
|
6
|
+
keepsEmpty: boolean;
|
|
7
|
+
blankIsValue: boolean;
|
|
8
|
+
}
|
|
3
9
|
export interface FieldPlan {
|
|
4
10
|
name: string;
|
|
5
11
|
schema: AnyZod;
|
|
@@ -16,6 +22,8 @@ export interface FieldPlan {
|
|
|
16
22
|
isUnion: boolean;
|
|
17
23
|
absence: AbsencePolicy;
|
|
18
24
|
absorbsBlank: boolean;
|
|
25
|
+
keepsEmpty: boolean;
|
|
26
|
+
blankIsValue: boolean;
|
|
19
27
|
/**
|
|
20
28
|
* True for a `z.date()` whose value must reach the handler UNCHANGED — validated through a converted copy,
|
|
21
29
|
* handed over as the host sent it. False for `z.coerce.date()`, which the author asked to convert.
|
|
@@ -26,8 +34,5 @@ export interface FieldPlan {
|
|
|
26
34
|
restoresDates: boolean;
|
|
27
35
|
}
|
|
28
36
|
/** The absent forms a schema accepts, at any depth. Same question `planField` asks for a top-level field. */
|
|
29
|
-
export declare function absenceOf(schema: AnyZod | undefined):
|
|
30
|
-
absence: AbsencePolicy;
|
|
31
|
-
absorbsBlank: boolean;
|
|
32
|
-
};
|
|
37
|
+
export declare function absenceOf(schema: AnyZod | undefined): Absence;
|
|
33
38
|
export declare function planField(name: string, schema: AnyZod): FieldPlan;
|
|
@@ -83,6 +83,18 @@ declare module 'zod' {
|
|
|
83
83
|
/** @deprecated Inverted and renamed — see `labels`. Throws, so the change cannot pass silently. */
|
|
84
84
|
map(mapping: Record<string, unknown>): never;
|
|
85
85
|
}
|
|
86
|
+
interface ZodUnknown {
|
|
87
|
+
/**
|
|
88
|
+
* Mark the field required — the same as zod's `.nonoptional()`. `z.unknown()` is optional unless marked;
|
|
89
|
+
* `z.unknown().required()` takes any value (text, number, boolean, `null`, an object, a list, a date) but
|
|
90
|
+
* refuses a missing one.
|
|
91
|
+
*/
|
|
92
|
+
required(): this;
|
|
93
|
+
}
|
|
94
|
+
interface ZodAny {
|
|
95
|
+
/** Mark the field required — see `ZodUnknown.required`. */
|
|
96
|
+
required(): this;
|
|
97
|
+
}
|
|
86
98
|
}
|
|
87
99
|
declare function text(): baseZod.ZodString;
|
|
88
100
|
/**
|
package/package.json
CHANGED
package/runtime/index.js
CHANGED
|
@@ -12469,16 +12469,39 @@ function declaredAbsence(schema) {
|
|
|
12469
12469
|
current = def.innerType;
|
|
12470
12470
|
}
|
|
12471
12471
|
const absence = acceptsUndefined && acceptsNull ? "as-received" : acceptsUndefined ? "undefined" : acceptsNull ? "null" : "required";
|
|
12472
|
-
return { absence, absorbsBlank };
|
|
12472
|
+
return { absence, absorbsBlank, keepsEmpty: false, blankIsValue: false };
|
|
12473
12473
|
}
|
|
12474
12474
|
function coerces(schema) {
|
|
12475
12475
|
return inspect(schema).core?._zod?.def?.coerce === true;
|
|
12476
12476
|
}
|
|
12477
12477
|
var parsesJson = (schema) => !!inspect(schema).meta.frJson;
|
|
12478
|
+
var OPEN_TYPES = /* @__PURE__ */ new Set(["unknown", "any"]);
|
|
12479
|
+
var isOpenType = (schema) => OPEN_TYPES.has(inspect(schema).coreType);
|
|
12480
|
+
function requiredOpenType(schema) {
|
|
12481
|
+
if (!isOpenType(schema)) {
|
|
12482
|
+
return false;
|
|
12483
|
+
}
|
|
12484
|
+
let current = schema;
|
|
12485
|
+
while (current?._zod) {
|
|
12486
|
+
const def = current._zod.def ?? {};
|
|
12487
|
+
const type = def.type;
|
|
12488
|
+
if (type === "nonoptional") {
|
|
12489
|
+
return true;
|
|
12490
|
+
}
|
|
12491
|
+
if (!TRANSPARENT_WRAPPERS.has(type)) {
|
|
12492
|
+
return false;
|
|
12493
|
+
}
|
|
12494
|
+
current = innerOf(def, type);
|
|
12495
|
+
}
|
|
12496
|
+
return false;
|
|
12497
|
+
}
|
|
12478
12498
|
function probeAbsence(schema) {
|
|
12479
12499
|
if (coerces(schema) || parsesJson(schema)) {
|
|
12480
12500
|
return declaredAbsence(schema);
|
|
12481
12501
|
}
|
|
12502
|
+
if (requiredOpenType(schema)) {
|
|
12503
|
+
return { absence: "required", absorbsBlank: false, keepsEmpty: true, blankIsValue: true };
|
|
12504
|
+
}
|
|
12482
12505
|
const parse = (value) => {
|
|
12483
12506
|
try {
|
|
12484
12507
|
return schema.safeParse(value);
|
|
@@ -12489,24 +12512,24 @@ function probeAbsence(schema) {
|
|
|
12489
12512
|
const asUndefined = parse(void 0);
|
|
12490
12513
|
const asNull = parse(null);
|
|
12491
12514
|
const absence = asUndefined.success && asNull.success ? "as-received" : asUndefined.success ? "undefined" : asNull.success ? "null" : "required";
|
|
12492
|
-
return { absence, absorbsBlank: asUndefined.success && asUndefined.data !== void 0 };
|
|
12515
|
+
return { absence, absorbsBlank: asUndefined.success && asUndefined.data !== void 0, keepsEmpty: false, blankIsValue: false };
|
|
12493
12516
|
}
|
|
12494
12517
|
var probeCache = /* @__PURE__ */ new WeakMap();
|
|
12495
12518
|
function absenceOf(schema) {
|
|
12496
12519
|
if (!schema || typeof schema !== "object") {
|
|
12497
|
-
return { absence: "as-received", absorbsBlank: false };
|
|
12520
|
+
return { absence: "as-received", absorbsBlank: false, keepsEmpty: false, blankIsValue: false };
|
|
12498
12521
|
}
|
|
12499
12522
|
const cached = probeCache.get(schema);
|
|
12500
12523
|
if (cached) {
|
|
12501
12524
|
return cached;
|
|
12502
12525
|
}
|
|
12503
|
-
const probed = probeAbsence(schema);
|
|
12526
|
+
const probed = { ...probeAbsence(schema), blankIsValue: isOpenType(schema) && !parsesJson(schema) };
|
|
12504
12527
|
probeCache.set(schema, probed);
|
|
12505
12528
|
return probed;
|
|
12506
12529
|
}
|
|
12507
12530
|
function planField(name, schema) {
|
|
12508
12531
|
const ins = inspect(schema);
|
|
12509
|
-
const { absence, absorbsBlank } =
|
|
12532
|
+
const { absence, absorbsBlank, keepsEmpty, blankIsValue } = absenceOf(schema);
|
|
12510
12533
|
return {
|
|
12511
12534
|
name,
|
|
12512
12535
|
schema,
|
|
@@ -12515,6 +12538,8 @@ function planField(name, schema) {
|
|
|
12515
12538
|
isUnion: !!ins.branches,
|
|
12516
12539
|
absence,
|
|
12517
12540
|
absorbsBlank,
|
|
12541
|
+
keepsEmpty,
|
|
12542
|
+
blankIsValue,
|
|
12518
12543
|
passThroughDate: passesDateThrough(ins),
|
|
12519
12544
|
restoresDates: hasPassThroughDate(schema, inspect, shapeEntries)
|
|
12520
12545
|
};
|
|
@@ -12532,8 +12557,29 @@ function toStringValue(value) {
|
|
|
12532
12557
|
if (typeof value === "boolean") {
|
|
12533
12558
|
return ok(String(value));
|
|
12534
12559
|
}
|
|
12560
|
+
if (value !== null && typeof value === "object") {
|
|
12561
|
+
return ok(value instanceof Date ? value.toISOString() : JSON.stringify(value));
|
|
12562
|
+
}
|
|
12535
12563
|
return typeof value === "number" && Number.isFinite(value) ? ok(String(value)) : fail("string");
|
|
12536
12564
|
}
|
|
12565
|
+
var OPENS = { array: "[", object: "{" };
|
|
12566
|
+
function parseContainerText(value, kind) {
|
|
12567
|
+
if (typeof value !== "string") {
|
|
12568
|
+
return value;
|
|
12569
|
+
}
|
|
12570
|
+
const text2 = value.trim();
|
|
12571
|
+
if (!text2.startsWith(OPENS[kind])) {
|
|
12572
|
+
return value;
|
|
12573
|
+
}
|
|
12574
|
+
try {
|
|
12575
|
+
const parsed = JSON.parse(text2);
|
|
12576
|
+
const isList = Array.isArray(parsed);
|
|
12577
|
+
const fits = kind === "array" ? isList : parsed !== null && typeof parsed === "object" && !isList;
|
|
12578
|
+
return fits ? parsed : value;
|
|
12579
|
+
} catch {
|
|
12580
|
+
return value;
|
|
12581
|
+
}
|
|
12582
|
+
}
|
|
12537
12583
|
function toNumberValue(value) {
|
|
12538
12584
|
if (typeof value === "number") {
|
|
12539
12585
|
return Number.isFinite(value) ? ok(value) : fail("number");
|
|
@@ -12613,7 +12659,14 @@ function accepts(schema, value) {
|
|
|
12613
12659
|
}
|
|
12614
12660
|
}
|
|
12615
12661
|
function coerceUnion(value, branches) {
|
|
12662
|
+
if (branches.some((branch) => accepts(branch, value))) {
|
|
12663
|
+
return value;
|
|
12664
|
+
}
|
|
12665
|
+
const isStructure = value !== null && typeof value === "object";
|
|
12616
12666
|
for (const branch of branches) {
|
|
12667
|
+
if (isStructure && inspect(branch).coreType === "string") {
|
|
12668
|
+
continue;
|
|
12669
|
+
}
|
|
12617
12670
|
const coerced = coerceDeep(value, branch);
|
|
12618
12671
|
if (accepts(branch, coerced)) {
|
|
12619
12672
|
return coerced;
|
|
@@ -12638,22 +12691,25 @@ function coerceDeep(value, schema) {
|
|
|
12638
12691
|
}
|
|
12639
12692
|
if (ins.coreType === "array") {
|
|
12640
12693
|
const element = ins.core?._zod?.def?.element;
|
|
12641
|
-
|
|
12694
|
+
const list = parseContainerText(value, "array");
|
|
12695
|
+
return Array.isArray(list) ? list.map((item) => coerceDeep(item, element)) : list;
|
|
12642
12696
|
}
|
|
12643
12697
|
if (ins.coreType === "record") {
|
|
12644
|
-
|
|
12645
|
-
|
|
12698
|
+
const map = parseContainerText(value, "object");
|
|
12699
|
+
if (typeof map !== "object" || Array.isArray(map)) {
|
|
12700
|
+
return map;
|
|
12646
12701
|
}
|
|
12647
12702
|
const valueType = ins.core?._zod?.def?.valueType;
|
|
12648
12703
|
return Object.fromEntries(
|
|
12649
|
-
Object.entries(
|
|
12704
|
+
Object.entries(map).map(([key, item]) => [key, coerceDeep(item, valueType)])
|
|
12650
12705
|
);
|
|
12651
12706
|
}
|
|
12652
12707
|
if (ins.coreType === "object") {
|
|
12653
|
-
|
|
12654
|
-
|
|
12708
|
+
const parsed = parseContainerText(value, "object");
|
|
12709
|
+
if (typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
12710
|
+
return parsed;
|
|
12655
12711
|
}
|
|
12656
|
-
const source =
|
|
12712
|
+
const source = parsed;
|
|
12657
12713
|
const coerced = { ...source };
|
|
12658
12714
|
for (const [name, property] of shapeEntries(ins.core)) {
|
|
12659
12715
|
if (name in source) {
|
|
@@ -12688,7 +12744,13 @@ function coerceLeaf(value, ins) {
|
|
|
12688
12744
|
return coerceValue(value, ins.coreType);
|
|
12689
12745
|
}
|
|
12690
12746
|
function isBlank(value, ins, schema) {
|
|
12691
|
-
if (value === void 0
|
|
12747
|
+
if (value === void 0) {
|
|
12748
|
+
return true;
|
|
12749
|
+
}
|
|
12750
|
+
if (absenceOf(schema).keepsEmpty) {
|
|
12751
|
+
return false;
|
|
12752
|
+
}
|
|
12753
|
+
if (value === null) {
|
|
12692
12754
|
return true;
|
|
12693
12755
|
}
|
|
12694
12756
|
if (value !== "") {
|
|
@@ -12697,6 +12759,9 @@ function isBlank(value, ins, schema) {
|
|
|
12697
12759
|
if (ins.branches) {
|
|
12698
12760
|
return true;
|
|
12699
12761
|
}
|
|
12762
|
+
if (absenceOf(schema).blankIsValue) {
|
|
12763
|
+
return absenceOf(schema).absorbsBlank;
|
|
12764
|
+
}
|
|
12700
12765
|
return ins.coreType !== "string" || absenceOf(schema).absorbsBlank;
|
|
12701
12766
|
}
|
|
12702
12767
|
function absentAs(schema, value) {
|
|
@@ -12757,6 +12822,8 @@ var EXPECTED = {
|
|
|
12757
12822
|
date: "a date",
|
|
12758
12823
|
object: "an object",
|
|
12759
12824
|
array: "an array",
|
|
12825
|
+
// zod's own token for `z.record()`, which the author declared as a map — to a person it is an object.
|
|
12826
|
+
record: "an object",
|
|
12760
12827
|
// `z.json()`. Not a zod token — ./coerce.ts raises it when the submitted text will not parse.
|
|
12761
12828
|
json: "valid JSON"
|
|
12762
12829
|
};
|
|
@@ -12833,7 +12900,13 @@ function toFieldIssue(plan, issue, fieldValue) {
|
|
|
12833
12900
|
var resolved = (value) => ({ value, present: true, issues: [] });
|
|
12834
12901
|
var rejected = (issues) => ({ present: false, issues });
|
|
12835
12902
|
function isAbsent(value, plan) {
|
|
12836
|
-
if (value === void 0
|
|
12903
|
+
if (value === void 0) {
|
|
12904
|
+
return true;
|
|
12905
|
+
}
|
|
12906
|
+
if (plan.keepsEmpty) {
|
|
12907
|
+
return false;
|
|
12908
|
+
}
|
|
12909
|
+
if (value === null) {
|
|
12837
12910
|
return true;
|
|
12838
12911
|
}
|
|
12839
12912
|
if (value !== "") {
|
|
@@ -12842,6 +12915,9 @@ function isAbsent(value, plan) {
|
|
|
12842
12915
|
if (plan.isUnion) {
|
|
12843
12916
|
return true;
|
|
12844
12917
|
}
|
|
12918
|
+
if (plan.blankIsValue) {
|
|
12919
|
+
return plan.absorbsBlank;
|
|
12920
|
+
}
|
|
12845
12921
|
return plan.coreType !== "string" || plan.absorbsBlank;
|
|
12846
12922
|
}
|
|
12847
12923
|
function normalizeAbsence(value, plan) {
|
|
@@ -13129,6 +13205,9 @@ function extendPrototype() {
|
|
|
13129
13205
|
const existing = this.meta()?.examples ?? [];
|
|
13130
13206
|
return this.meta({ examples: [...existing, value] });
|
|
13131
13207
|
};
|
|
13208
|
+
proto.required = function required() {
|
|
13209
|
+
return this.nonoptional();
|
|
13210
|
+
};
|
|
13132
13211
|
proto.shared = function shared() {
|
|
13133
13212
|
return this.meta({ frShared: true });
|
|
13134
13213
|
};
|