@flowrunner/cli 0.1.15 → 0.1.16
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 +59 -15
- package/ai-docs/instructions/service-code-format/16-gotchas.md +4 -0
- package/dist/cli.js +57 -8
- package/dist/cli.js.map +2 -2
- package/dist/index.js +56 -7
- package/dist/index.js.map +2 -2
- 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 +56 -7
- package/runtime/index.js.map +2 -2
- 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
|
};
|
|
@@ -12613,6 +12638,9 @@ function accepts(schema, value) {
|
|
|
12613
12638
|
}
|
|
12614
12639
|
}
|
|
12615
12640
|
function coerceUnion(value, branches) {
|
|
12641
|
+
if (branches.some((branch) => accepts(branch, value))) {
|
|
12642
|
+
return value;
|
|
12643
|
+
}
|
|
12616
12644
|
for (const branch of branches) {
|
|
12617
12645
|
const coerced = coerceDeep(value, branch);
|
|
12618
12646
|
if (accepts(branch, coerced)) {
|
|
@@ -12688,7 +12716,13 @@ function coerceLeaf(value, ins) {
|
|
|
12688
12716
|
return coerceValue(value, ins.coreType);
|
|
12689
12717
|
}
|
|
12690
12718
|
function isBlank(value, ins, schema) {
|
|
12691
|
-
if (value === void 0
|
|
12719
|
+
if (value === void 0) {
|
|
12720
|
+
return true;
|
|
12721
|
+
}
|
|
12722
|
+
if (absenceOf(schema).keepsEmpty) {
|
|
12723
|
+
return false;
|
|
12724
|
+
}
|
|
12725
|
+
if (value === null) {
|
|
12692
12726
|
return true;
|
|
12693
12727
|
}
|
|
12694
12728
|
if (value !== "") {
|
|
@@ -12697,6 +12731,9 @@ function isBlank(value, ins, schema) {
|
|
|
12697
12731
|
if (ins.branches) {
|
|
12698
12732
|
return true;
|
|
12699
12733
|
}
|
|
12734
|
+
if (absenceOf(schema).blankIsValue) {
|
|
12735
|
+
return absenceOf(schema).absorbsBlank;
|
|
12736
|
+
}
|
|
12700
12737
|
return ins.coreType !== "string" || absenceOf(schema).absorbsBlank;
|
|
12701
12738
|
}
|
|
12702
12739
|
function absentAs(schema, value) {
|
|
@@ -12833,7 +12870,13 @@ function toFieldIssue(plan, issue, fieldValue) {
|
|
|
12833
12870
|
var resolved = (value) => ({ value, present: true, issues: [] });
|
|
12834
12871
|
var rejected = (issues) => ({ present: false, issues });
|
|
12835
12872
|
function isAbsent(value, plan) {
|
|
12836
|
-
if (value === void 0
|
|
12873
|
+
if (value === void 0) {
|
|
12874
|
+
return true;
|
|
12875
|
+
}
|
|
12876
|
+
if (plan.keepsEmpty) {
|
|
12877
|
+
return false;
|
|
12878
|
+
}
|
|
12879
|
+
if (value === null) {
|
|
12837
12880
|
return true;
|
|
12838
12881
|
}
|
|
12839
12882
|
if (value !== "") {
|
|
@@ -12842,6 +12885,9 @@ function isAbsent(value, plan) {
|
|
|
12842
12885
|
if (plan.isUnion) {
|
|
12843
12886
|
return true;
|
|
12844
12887
|
}
|
|
12888
|
+
if (plan.blankIsValue) {
|
|
12889
|
+
return plan.absorbsBlank;
|
|
12890
|
+
}
|
|
12845
12891
|
return plan.coreType !== "string" || plan.absorbsBlank;
|
|
12846
12892
|
}
|
|
12847
12893
|
function normalizeAbsence(value, plan) {
|
|
@@ -13129,6 +13175,9 @@ function extendPrototype() {
|
|
|
13129
13175
|
const existing = this.meta()?.examples ?? [];
|
|
13130
13176
|
return this.meta({ examples: [...existing, value] });
|
|
13131
13177
|
};
|
|
13178
|
+
proto.required = function required() {
|
|
13179
|
+
return this.nonoptional();
|
|
13180
|
+
};
|
|
13132
13181
|
proto.shared = function shared() {
|
|
13133
13182
|
return this.meta({ frShared: true });
|
|
13134
13183
|
};
|