@flowrunner/cli 0.1.8 → 0.1.9-dev.1
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 +8 -8
- package/ai-docs/instructions/service-code-format/01-service-structure.md +4 -3
- package/ai-docs/instructions/service-code-format/02-zod-types.md +8 -0
- package/ai-docs/instructions/service-code-format/03-parameters.md +166 -10
- package/ai-docs/instructions/service-code-format/04-http-requests.md +19 -15
- package/ai-docs/instructions/service-code-format/05-dictionaries.md +14 -0
- package/ai-docs/instructions/service-code-format/06-oauth2.md +1 -5
- package/ai-docs/instructions/service-code-format/07-actions.md +18 -13
- package/ai-docs/instructions/service-code-format/11-output-model.md +42 -6
- package/ai-docs/instructions/service-code-format/12-service-readme.md +1 -1
- package/ai-docs/instructions/service-code-format/14-reference-service.md +5 -4
- package/ai-docs/instructions/service-code-format/15-unit-tests.md +2 -1
- package/ai-docs/instructions/service-code-format/16-gotchas.md +31 -1
- package/ai-docs/instructions/service-code-format/17-client-certificates.md +5 -3
- package/ai-docs/instructions/service-code-format/README.md +1 -1
- package/ai-docs/providers/claude/agents/flowrunner-service-test-engineer.md +1 -1
- package/dist/cli.js +285 -42
- package/dist/cli.js.map +3 -3
- package/dist/index.js +284 -41
- package/dist/index.js.map +3 -3
- package/dist/types/flow-extension-runner/src/v2/actions/action-method.d.ts +13 -9
- package/dist/types/flow-extension-runner/src/v2/loaders/loader-method.d.ts +52 -7
- package/dist/types/flow-extension-runner/src/v2/loaders/loader-owner.d.ts +4 -6
- package/dist/types/flow-extension-runner/src/v2/model/model-types.d.ts +2 -0
- package/dist/types/flow-extension-runner/src/v2/params/index.d.ts +2 -2
- package/dist/types/flow-extension-runner/src/v2/params/json/encode.d.ts +10 -2
- package/dist/types/flow-extension-runner/src/v2/params/json/types.d.ts +1 -0
- package/dist/types/flow-extension-runner/src/v2/params/zod.d.ts +29 -0
- package/dist/types/flow-extension-runner/src/v2/types.d.ts +21 -9
- package/dist/types/shared/src/constants/activity-log.d.ts +1496 -0
- package/dist/types/shared/src/constants/docs.d.ts +2 -0
- package/dist/types/shared/src/constants/notification-types.d.ts +11 -5
- package/dist/types/shared/src/scheme/activity-log-base.d.ts +35 -0
- package/dist/types/shared/src/scheme/data-types/java.dto.d.ts +2 -3
- package/dist/types/shared/src/scheme/flowrunner/custom-elements.d.ts +20 -0
- package/dist/types/shared/src/scheme/flowrunner/java.dto.d.ts +1 -0
- package/dist/types/shared/src/scheme/shared-extensions/base.d.ts +5 -0
- package/dist/types/shared/src/scheme/shared-extensions/custom-extensions.d.ts +147 -0
- package/dist/types/shared/src/scheme/shared-extensions/extension.d.ts +20 -0
- package/dist/types/shared/src/scheme/shared-extensions/methods.d.ts +33 -1
- package/dist/types/shared/src/scheme/shared-extensions/params-schema.d.ts +1 -0
- package/dist/types/shared/src/scheme/shared-extensions/resolve.d.ts +15 -0
- package/dist/types/shared/src/scheme/shared-extensions/search.d.ts +10 -0
- package/package.json +1 -1
- package/runtime/index.js +267 -41
- package/runtime/index.js.map +3 -3
- package/runtime/types/flow-extension-runner/src/v2/actions/action-method.d.ts +13 -9
- package/runtime/types/flow-extension-runner/src/v2/loaders/loader-method.d.ts +52 -7
- package/runtime/types/flow-extension-runner/src/v2/loaders/loader-owner.d.ts +4 -6
- package/runtime/types/flow-extension-runner/src/v2/model/model-types.d.ts +2 -0
- package/runtime/types/flow-extension-runner/src/v2/params/index.d.ts +2 -2
- package/runtime/types/flow-extension-runner/src/v2/params/json/encode.d.ts +10 -2
- package/runtime/types/flow-extension-runner/src/v2/params/json/types.d.ts +1 -0
- package/runtime/types/flow-extension-runner/src/v2/params/zod.d.ts +29 -0
- package/runtime/types/flow-extension-runner/src/v2/types.d.ts +21 -9
- package/runtime/types/shared/src/constants/activity-log.d.ts +1496 -0
- package/runtime/types/shared/src/constants/docs.d.ts +2 -0
- package/runtime/types/shared/src/constants/notification-types.d.ts +11 -5
- package/runtime/types/shared/src/scheme/activity-log-base.d.ts +35 -0
- package/runtime/types/shared/src/scheme/data-types/java.dto.d.ts +2 -3
- package/runtime/types/shared/src/scheme/flowrunner/custom-elements.d.ts +20 -0
- package/runtime/types/shared/src/scheme/flowrunner/java.dto.d.ts +1 -0
- package/runtime/types/shared/src/scheme/shared-extensions/base.d.ts +5 -0
- package/runtime/types/shared/src/scheme/shared-extensions/custom-extensions.d.ts +147 -0
- package/runtime/types/shared/src/scheme/shared-extensions/extension.d.ts +20 -0
- package/runtime/types/shared/src/scheme/shared-extensions/methods.d.ts +33 -1
- package/runtime/types/shared/src/scheme/shared-extensions/params-schema.d.ts +1 -0
- package/runtime/types/shared/src/scheme/shared-extensions/resolve.d.ts +15 -0
- package/runtime/types/shared/src/scheme/shared-extensions/search.d.ts +10 -0
- package/templates/blank/files/src/index.js +1 -1
- package/templates/demo-todo-list/files/src/index.js +7 -7
- package/templates/qa-test/files/src/index.js +33 -4
|
@@ -91,12 +91,17 @@ export declare const ExtensionResolveUpdatedSchema: z.ZodObject<{
|
|
|
91
91
|
dictionary: z.ZodOptional<z.ZodString>;
|
|
92
92
|
dependsOn: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
93
93
|
uiComponent: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
94
|
+
schemaLoader: z.ZodOptional<z.ZodString>;
|
|
94
95
|
}, z.core.$strip>>>;
|
|
95
96
|
sampleResult: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
|
|
96
97
|
sampleResultLoader: z.ZodNullable<z.ZodObject<{
|
|
97
98
|
methodName: z.ZodString;
|
|
98
99
|
dependsOn: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
99
100
|
}, z.core.$strip>>;
|
|
101
|
+
dynamicParams: z.ZodOptional<z.ZodObject<{
|
|
102
|
+
methodName: z.ZodString;
|
|
103
|
+
dependsOn: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
104
|
+
}, z.core.$strip>>;
|
|
100
105
|
}, z.core.$strip>;
|
|
101
106
|
paramsSchema: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
102
107
|
v: z.ZodNumber;
|
|
@@ -202,12 +207,17 @@ export declare const ExtensionResolveResultItemSchema: z.ZodDiscriminatedUnion<[
|
|
|
202
207
|
dictionary: z.ZodOptional<z.ZodString>;
|
|
203
208
|
dependsOn: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
204
209
|
uiComponent: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
210
|
+
schemaLoader: z.ZodOptional<z.ZodString>;
|
|
205
211
|
}, z.core.$strip>>>;
|
|
206
212
|
sampleResult: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
|
|
207
213
|
sampleResultLoader: z.ZodNullable<z.ZodObject<{
|
|
208
214
|
methodName: z.ZodString;
|
|
209
215
|
dependsOn: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
210
216
|
}, z.core.$strip>>;
|
|
217
|
+
dynamicParams: z.ZodOptional<z.ZodObject<{
|
|
218
|
+
methodName: z.ZodString;
|
|
219
|
+
dependsOn: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
220
|
+
}, z.core.$strip>>;
|
|
211
221
|
}, z.core.$strip>;
|
|
212
222
|
paramsSchema: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
213
223
|
v: z.ZodNumber;
|
|
@@ -312,12 +322,17 @@ export declare const ExtensionResolveResponseSchema: z.ZodArray<z.ZodDiscriminat
|
|
|
312
322
|
dictionary: z.ZodOptional<z.ZodString>;
|
|
313
323
|
dependsOn: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
314
324
|
uiComponent: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
325
|
+
schemaLoader: z.ZodOptional<z.ZodString>;
|
|
315
326
|
}, z.core.$strip>>>;
|
|
316
327
|
sampleResult: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
|
|
317
328
|
sampleResultLoader: z.ZodNullable<z.ZodObject<{
|
|
318
329
|
methodName: z.ZodString;
|
|
319
330
|
dependsOn: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
320
331
|
}, z.core.$strip>>;
|
|
332
|
+
dynamicParams: z.ZodOptional<z.ZodObject<{
|
|
333
|
+
methodName: z.ZodString;
|
|
334
|
+
dependsOn: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
335
|
+
}, z.core.$strip>>;
|
|
321
336
|
}, z.core.$strip>;
|
|
322
337
|
paramsSchema: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
323
338
|
v: z.ZodNumber;
|
|
@@ -23,12 +23,17 @@ export declare const SharedExtensionSearchResultMethodSchema: z.ZodObject<{
|
|
|
23
23
|
dictionary: z.ZodOptional<z.ZodString>;
|
|
24
24
|
dependsOn: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
25
25
|
uiComponent: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
26
|
+
schemaLoader: z.ZodOptional<z.ZodString>;
|
|
26
27
|
}, z.core.$strip>>>;
|
|
27
28
|
sampleResult: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
|
|
28
29
|
sampleResultLoader: z.ZodNullable<z.ZodObject<{
|
|
29
30
|
methodName: z.ZodString;
|
|
30
31
|
dependsOn: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
31
32
|
}, z.core.$strip>>;
|
|
33
|
+
dynamicParams: z.ZodOptional<z.ZodObject<{
|
|
34
|
+
methodName: z.ZodString;
|
|
35
|
+
dependsOn: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
36
|
+
}, z.core.$strip>>;
|
|
32
37
|
}, z.core.$strip>;
|
|
33
38
|
paramsSchema: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
34
39
|
v: z.ZodNumber;
|
|
@@ -116,12 +121,17 @@ export declare const SearchSharedExtensionsResponseSchema: z.ZodObject<{
|
|
|
116
121
|
dictionary: z.ZodOptional<z.ZodString>;
|
|
117
122
|
dependsOn: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
118
123
|
uiComponent: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
124
|
+
schemaLoader: z.ZodOptional<z.ZodString>;
|
|
119
125
|
}, z.core.$strip>>>;
|
|
120
126
|
sampleResult: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
|
|
121
127
|
sampleResultLoader: z.ZodNullable<z.ZodObject<{
|
|
122
128
|
methodName: z.ZodString;
|
|
123
129
|
dependsOn: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
124
130
|
}, z.core.$strip>>;
|
|
131
|
+
dynamicParams: z.ZodOptional<z.ZodObject<{
|
|
132
|
+
methodName: z.ZodString;
|
|
133
|
+
dependsOn: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
134
|
+
}, z.core.$strip>>;
|
|
125
135
|
}, z.core.$strip>;
|
|
126
136
|
paramsSchema: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
127
137
|
v: z.ZodNumber;
|
package/package.json
CHANGED
package/runtime/index.js
CHANGED
|
@@ -1562,6 +1562,7 @@ var InvalidDictionaryOutputScheme = class extends FlowExtensionError {
|
|
|
1562
1562
|
// ../../flow-extension-runner/src/v2/loaders/loader-owner.ts
|
|
1563
1563
|
var sampleResultLoaderName = (ownerId) => `${ownerId}_SampleResultLoader`;
|
|
1564
1564
|
var dynamicParamsLoaderName = (ownerId) => `${ownerId}_DynamicParams`;
|
|
1565
|
+
var dynamicPropsLoaderName = (ownerId, field) => `${ownerId}_${field}_DynamicProps`;
|
|
1565
1566
|
|
|
1566
1567
|
// ../../flow-extension-runner/src/v2/params/schema/assert-object-schema.ts
|
|
1567
1568
|
var WRAPPERS = /* @__PURE__ */ new Set(["optional", "nullable", "nullish", "default", "prefault"]);
|
|
@@ -1605,8 +1606,9 @@ function assertObjectSchema(scheme, source) {
|
|
|
1605
1606
|
const isReturn = slot.endsWith("()");
|
|
1606
1607
|
const subject = source.itemId ? `${kind} "${source.itemId}": ` : "";
|
|
1607
1608
|
const received = describe(scheme);
|
|
1609
|
+
const expected = slot.endsWith(".execute()") ? "a z.object({ \u2026 }) or a shape of zod fields" : "a z.object({ \u2026 })";
|
|
1608
1610
|
throw new InvalidSchemaError(
|
|
1609
|
-
`[flow-extension:${source.serviceId}] ${subject}\`${slot}\` ${isReturn ? "must return" : "must be"}
|
|
1611
|
+
`[flow-extension:${source.serviceId}] ${subject}\`${slot}\` ${isReturn ? "must return" : "must be"} ${expected} \u2014 received ${received}${hint(scheme, slot, isReturn)}`,
|
|
1610
1612
|
{ serviceId: source.serviceId, kind, itemId: source.itemId, slot, received }
|
|
1611
1613
|
);
|
|
1612
1614
|
}
|
|
@@ -1829,12 +1831,82 @@ function refuseType(source, path2, type) {
|
|
|
1829
1831
|
type ?? "unknown"
|
|
1830
1832
|
);
|
|
1831
1833
|
}
|
|
1832
|
-
|
|
1834
|
+
var DYNAMIC_PROPS_FIX = "Declare it as `z.looseObject({ \u2026 }).dynamicProps({ dependsOn, execute })`, or `z.array(z.looseObject({ \u2026 })).dynamicProps(\u2026)` for a list of objects.";
|
|
1835
|
+
function isLooseObject(schema) {
|
|
1836
|
+
if (!schema) {
|
|
1837
|
+
return false;
|
|
1838
|
+
}
|
|
1839
|
+
const ins = inspect(schema);
|
|
1840
|
+
const catchall = ins.core?._zod?.def?.catchall;
|
|
1841
|
+
return ins.resolvedType === "object" && catchall?._zod?.def?.type === "unknown";
|
|
1842
|
+
}
|
|
1843
|
+
function isDynamicPropsSlot(source, topLevel) {
|
|
1844
|
+
return topLevel && source.kind === "action" && source.slot === "params";
|
|
1845
|
+
}
|
|
1846
|
+
function assertDynamicProps(schema, name, siblings, source, path2) {
|
|
1847
|
+
const ins = inspect(schema);
|
|
1848
|
+
const spec = ins.meta.frDynamicProps;
|
|
1849
|
+
if (!spec || !("execute" in spec)) {
|
|
1850
|
+
return;
|
|
1851
|
+
}
|
|
1852
|
+
if (typeof spec.execute !== "function") {
|
|
1853
|
+
refuse(
|
|
1854
|
+
`${subjectOf(source, path2)}: \`.dynamicProps()\` needs an \`execute\` function that returns the loaded fields.`,
|
|
1855
|
+
source,
|
|
1856
|
+
path2,
|
|
1857
|
+
typeof spec.execute
|
|
1858
|
+
);
|
|
1859
|
+
}
|
|
1860
|
+
if (spec.dependsOn !== void 0 && (!Array.isArray(spec.dependsOn) || spec.dependsOn.some((item) => typeof item !== "string"))) {
|
|
1861
|
+
refuse(
|
|
1862
|
+
`${subjectOf(source, path2)}: \`.dynamicProps()\` \`dependsOn\` must be an array of param names.`,
|
|
1863
|
+
source,
|
|
1864
|
+
path2,
|
|
1865
|
+
"dependsOn"
|
|
1866
|
+
);
|
|
1867
|
+
}
|
|
1868
|
+
for (const dependency of spec.dependsOn ?? []) {
|
|
1869
|
+
if (dependency === name || !siblings.includes(dependency)) {
|
|
1870
|
+
refuse(
|
|
1871
|
+
`${subjectOf(source, path2)}: \`.dynamicProps()\` depends on "${dependency}", which is not another param of this action. Name its sibling params: ${siblings.filter((sibling) => sibling !== name).join(", ") || "none"}.`,
|
|
1872
|
+
source,
|
|
1873
|
+
path2,
|
|
1874
|
+
dependency
|
|
1875
|
+
);
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
if (ins.meta.frDictionary) {
|
|
1879
|
+
refuse(
|
|
1880
|
+
`${subjectOf(source, path2)} declares both \`.dynamicProps()\` and \`.dictionary()\`. A dictionary offers values for one field; dynamic props load the fields inside an object \u2014 use one or the other.`,
|
|
1881
|
+
source,
|
|
1882
|
+
path2,
|
|
1883
|
+
"dictionary"
|
|
1884
|
+
);
|
|
1885
|
+
}
|
|
1886
|
+
const element = ins.resolvedType === "array" ? ins.core?._zod?.def?.element : void 0;
|
|
1887
|
+
if (!isLooseObject(schema) && !isLooseObject(element)) {
|
|
1888
|
+
refuse(
|
|
1889
|
+
`${subjectOf(source, path2)}: \`.dynamicProps()\` needs a loose object \u2014 the loaded fields are not declared, so a plain \`z.object()\` would strip them. ${DYNAMIC_PROPS_FIX}`,
|
|
1890
|
+
source,
|
|
1891
|
+
path2,
|
|
1892
|
+
ins.resolvedType ?? "unknown"
|
|
1893
|
+
);
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
function assertField(schema, source, path2, seen, topLevel = false) {
|
|
1833
1897
|
if (!schema || seen.has(schema)) {
|
|
1834
1898
|
return;
|
|
1835
1899
|
}
|
|
1836
1900
|
seen.add(schema);
|
|
1837
1901
|
const ins = inspect(schema);
|
|
1902
|
+
if (ins.meta.frDynamicProps && !isDynamicPropsSlot(source, topLevel)) {
|
|
1903
|
+
refuse(
|
|
1904
|
+
`${subjectOf(source, path2)} uses \`.dynamicProps()\`, which is supported on top-level action params only. For a list of objects, put it on the array rather than on its element.`,
|
|
1905
|
+
source,
|
|
1906
|
+
path2,
|
|
1907
|
+
"dynamicProps"
|
|
1908
|
+
);
|
|
1909
|
+
}
|
|
1838
1910
|
if (ins.resolvedType === "catch") {
|
|
1839
1911
|
refuseCatch(source, path2);
|
|
1840
1912
|
}
|
|
@@ -1863,8 +1935,13 @@ function assertSupportedSchema(scheme, source) {
|
|
|
1863
1935
|
}
|
|
1864
1936
|
const slot = source.slot ?? "schema";
|
|
1865
1937
|
const seen = /* @__PURE__ */ new Set();
|
|
1866
|
-
|
|
1867
|
-
|
|
1938
|
+
const fields = shapeEntries(scheme);
|
|
1939
|
+
const names = fields.map(([name]) => name);
|
|
1940
|
+
for (const [name, field] of fields) {
|
|
1941
|
+
assertField(field, source, `${slot}.${name}`, seen, true);
|
|
1942
|
+
if (isDynamicPropsSlot(source, true)) {
|
|
1943
|
+
assertDynamicProps(field, name, names, source, `${slot}.${name}`);
|
|
1944
|
+
}
|
|
1868
1945
|
}
|
|
1869
1946
|
}
|
|
1870
1947
|
|
|
@@ -2686,6 +2763,9 @@ function extendPrototype() {
|
|
|
2686
2763
|
proto.labels = function labels(byValue) {
|
|
2687
2764
|
return this.meta({ frLabels: byValue });
|
|
2688
2765
|
};
|
|
2766
|
+
proto.dynamicProps = function dynamicProps(spec) {
|
|
2767
|
+
return this.meta({ frDynamicProps: spec });
|
|
2768
|
+
};
|
|
2689
2769
|
proto.map = function map() {
|
|
2690
2770
|
throw new Error(
|
|
2691
2771
|
"`.map({ Label: value })` has been replaced by `.labels({ value: 'Label' })` \u2014 declare the VALUES in the enum and the labels here, so a flow element stores the value and renaming a label is safe. e.g. z.enum(['asc', 'desc']).labels({ asc: 'Ascending', desc: 'Descending' })"
|
|
@@ -2906,10 +2986,36 @@ function unwrap(schema) {
|
|
|
2906
2986
|
}
|
|
2907
2987
|
return result;
|
|
2908
2988
|
}
|
|
2909
|
-
function
|
|
2910
|
-
|
|
2989
|
+
function isDynamicPropsSpec(value) {
|
|
2990
|
+
return !!value && typeof value === "object" && typeof value.execute === "function";
|
|
2991
|
+
}
|
|
2992
|
+
function hasFunction(value, depth = 0) {
|
|
2993
|
+
if (typeof value === "function") {
|
|
2994
|
+
return true;
|
|
2995
|
+
}
|
|
2996
|
+
if (!value || typeof value !== "object" || depth > MAX_UNWRAP_DEPTH) {
|
|
2997
|
+
return false;
|
|
2998
|
+
}
|
|
2999
|
+
return Object.values(value).some((inner) => hasFunction(inner, depth + 1));
|
|
3000
|
+
}
|
|
3001
|
+
function encodeMeta(meta, field, loaderId) {
|
|
3002
|
+
let source = meta;
|
|
3003
|
+
if (isDynamicPropsSpec(meta.frDynamicProps)) {
|
|
3004
|
+
if (!loaderId) {
|
|
3005
|
+
throw new Error(`Cannot encode "${field}": its \`.dynamicProps()\` has no loader method to publish.`);
|
|
3006
|
+
}
|
|
3007
|
+
source = { ...meta, frDynamicProps: { id: loaderId, dependsOn: meta.frDynamicProps.dependsOn ?? [] } };
|
|
3008
|
+
}
|
|
3009
|
+
if (hasFunction(source)) {
|
|
3010
|
+
throw new Error(`Cannot encode "${field}": its metadata holds a function, which has no wire form.`);
|
|
3011
|
+
}
|
|
3012
|
+
const encoded = toJsonValue2(source);
|
|
2911
3013
|
return Object.keys(encoded).length ? encoded : void 0;
|
|
2912
3014
|
}
|
|
3015
|
+
function isLoose(core) {
|
|
3016
|
+
const catchall = core?._zod?.def?.catchall;
|
|
3017
|
+
return catchall?._zod?.def?.type === "unknown";
|
|
3018
|
+
}
|
|
2913
3019
|
function encodeValues(core, type) {
|
|
2914
3020
|
if (type === "enum") {
|
|
2915
3021
|
const entries = core?._zod?.def?.entries ?? {};
|
|
@@ -2921,7 +3027,7 @@ function encodeValues(core, type) {
|
|
|
2921
3027
|
}
|
|
2922
3028
|
return void 0;
|
|
2923
3029
|
}
|
|
2924
|
-
function encodeField(name, schema, seen = /* @__PURE__ */ new Set()) {
|
|
3030
|
+
function encodeField(name, schema, seen = /* @__PURE__ */ new Set(), loaderId) {
|
|
2925
3031
|
if (seen.has(schema)) {
|
|
2926
3032
|
return { name, type: "unknown", unsupported: ["recursion"] };
|
|
2927
3033
|
}
|
|
@@ -2934,7 +3040,7 @@ function encodeField(name, schema, seen = /* @__PURE__ */ new Set()) {
|
|
|
2934
3040
|
const isUnion = !!ins.branches;
|
|
2935
3041
|
const format = isUnion ? void 0 : core?._zod?.def?.format;
|
|
2936
3042
|
const { checks, unsupported: checkIssues } = isUnion ? { checks: [], unsupported: [] } : encodeChecks(core);
|
|
2937
|
-
const meta = encodeMeta(ins.meta);
|
|
3043
|
+
const meta = encodeMeta(ins.meta, name, loaderId);
|
|
2938
3044
|
const message = isUnion ? void 0 : messageOf(core?._zod?.def ?? {});
|
|
2939
3045
|
const values = encodeValues(core, type);
|
|
2940
3046
|
const problems = [...unsupported, ...checkIssues];
|
|
@@ -2952,6 +3058,7 @@ function encodeField(name, schema, seen = /* @__PURE__ */ new Set()) {
|
|
|
2952
3058
|
...values?.length ? { values } : {},
|
|
2953
3059
|
...meta ? { meta } : {},
|
|
2954
3060
|
...message ? { message } : {},
|
|
3061
|
+
...type === "object" && isLoose(core) ? { loose: true } : {},
|
|
2955
3062
|
...type === "object" ? { properties: shapeEntries(core).map(([key, inner]) => encodeField(key, inner, seen)) } : {},
|
|
2956
3063
|
...type === "array" ? { element: encodeField("", core?._zod?.def?.element, seen) } : {},
|
|
2957
3064
|
...type === "record" ? { value: encodeField("", core?._zod?.def?.valueType, seen) } : {},
|
|
@@ -2961,14 +3068,14 @@ function encodeField(name, schema, seen = /* @__PURE__ */ new Set()) {
|
|
|
2961
3068
|
seen.delete(schema);
|
|
2962
3069
|
return encoded;
|
|
2963
3070
|
}
|
|
2964
|
-
function encodeParams(scheme) {
|
|
3071
|
+
function encodeParams(scheme, options = {}) {
|
|
2965
3072
|
const schema = scheme;
|
|
2966
3073
|
if (!schema?._zod) {
|
|
2967
3074
|
return null;
|
|
2968
3075
|
}
|
|
2969
3076
|
return {
|
|
2970
3077
|
v: SCHEMA_JSON_VERSION,
|
|
2971
|
-
fields: shapeEntries(schema).map(([name, field]) => encodeField(name, field))
|
|
3078
|
+
fields: shapeEntries(schema).map(([name, field]) => encodeField(name, field, /* @__PURE__ */ new Set(), options.loaderIdOf?.(name)))
|
|
2972
3079
|
};
|
|
2973
3080
|
}
|
|
2974
3081
|
|
|
@@ -3284,11 +3391,50 @@ var ActionMethod = class extends ExtensionMethod {
|
|
|
3284
3391
|
this.props = props;
|
|
3285
3392
|
this.params = MethodParams.of(props.params, { serviceId: extension.id, kind: "action", itemId: props.id, slot: "params" });
|
|
3286
3393
|
this.result = ResultSpec.from(props.result);
|
|
3287
|
-
this.
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3394
|
+
this.dynamicParams = props.dynamicParams ? this.#checkDynamicParams(props.dynamicParams) : void 0;
|
|
3395
|
+
}
|
|
3396
|
+
/**
|
|
3397
|
+
* `dynamicParams` takes the same `{ dependsOn, execute }` as `.dynamicProps()`. The old
|
|
3398
|
+
* `{ criteria, resolve }` shape is refused by name, so a service written against it fails at load with the
|
|
3399
|
+
* fix rather than publishing a loader that never runs.
|
|
3400
|
+
*/
|
|
3401
|
+
#checkDynamicParams(def) {
|
|
3402
|
+
const source = { serviceId: this.extension.id, kind: "action", itemId: this.props.id, slot: "dynamicParams" };
|
|
3403
|
+
const fail2 = (message, received) => {
|
|
3404
|
+
throw new InvalidSchemaError(`[flow-extension:${this.extension.id}] action "${this.props.id}": ${message}`, { ...source, received });
|
|
3405
|
+
};
|
|
3406
|
+
const legacy = def;
|
|
3407
|
+
if (legacy.resolve !== void 0 || legacy.criteria !== void 0) {
|
|
3408
|
+
fail2(
|
|
3409
|
+
"`dynamicParams: { criteria, resolve }` has been replaced by `dynamicParams: { dependsOn, execute }` \u2014 name the params it depends on and return the loaded fields from `execute`. e.g. dynamicParams: { dependsOn: ['tableName'], execute: async ({ criteria }) => ({ name: z.string() }) }",
|
|
3410
|
+
"criteria/resolve"
|
|
3411
|
+
);
|
|
3412
|
+
}
|
|
3413
|
+
if (typeof def.execute !== "function") {
|
|
3414
|
+
fail2("`dynamicParams` needs an `execute` function that returns the loaded params.", typeof def.execute);
|
|
3415
|
+
}
|
|
3416
|
+
if (def.dependsOn !== void 0 && (!Array.isArray(def.dependsOn) || def.dependsOn.some((item) => typeof item !== "string"))) {
|
|
3417
|
+
fail2("`dynamicParams.dependsOn` must be an array of param names.", def.dependsOn);
|
|
3418
|
+
}
|
|
3419
|
+
const declared = this.params.keys();
|
|
3420
|
+
for (const dependency of def.dependsOn ?? []) {
|
|
3421
|
+
if (!declared.includes(dependency)) {
|
|
3422
|
+
fail2(
|
|
3423
|
+
`\`dynamicParams\` depends on "${dependency}", which the action does not declare in \`params\`. Declared: ${declared.join(", ") || "none"}.`,
|
|
3424
|
+
dependency
|
|
3425
|
+
);
|
|
3426
|
+
}
|
|
3427
|
+
}
|
|
3428
|
+
return def;
|
|
3429
|
+
}
|
|
3430
|
+
/**
|
|
3431
|
+
* The top-level params declared with `.dynamicProps()`, and the def each one carries. Placement and shape
|
|
3432
|
+
* were checked when `params` was built (see ../params/schema/assert-supported-schema.ts).
|
|
3433
|
+
*/
|
|
3434
|
+
dynamicPropsFields() {
|
|
3435
|
+
return this.params.fields().flatMap(([name, schema]) => {
|
|
3436
|
+
const def = inspect(schema).meta.frDynamicProps;
|
|
3437
|
+
return def && "execute" in def ? [[name, def]] : [];
|
|
3292
3438
|
});
|
|
3293
3439
|
}
|
|
3294
3440
|
get id() {
|
|
@@ -3314,8 +3460,9 @@ var ActionMethod = class extends ExtensionMethod {
|
|
|
3314
3460
|
* Normalize, coerce and validate against the declared `params` — the same pipeline every other declared
|
|
3315
3461
|
* slot uses, so an author expresses optionality in the schema and nowhere else.
|
|
3316
3462
|
*
|
|
3317
|
-
* An action with `dynamicParams` carries the input's undeclared keys through, since its
|
|
3318
|
-
*
|
|
3463
|
+
* An action with `dynamicParams` carries the input's undeclared keys through, since its loaded top-level
|
|
3464
|
+
* fields are not in the static schema. A `.dynamicProps()` field needs nothing here: it is a loose object,
|
|
3465
|
+
* which keeps the loaded keys inside it.
|
|
3319
3466
|
*/
|
|
3320
3467
|
validate(methodData) {
|
|
3321
3468
|
return this.params.normalize(
|
|
@@ -3327,22 +3474,22 @@ var ActionMethod = class extends ExtensionMethod {
|
|
|
3327
3474
|
execute(params, ctx) {
|
|
3328
3475
|
return this.props.execute(ctx.bagWith({ params }));
|
|
3329
3476
|
}
|
|
3330
|
-
// Resolve the extra top-level param fields this action generates at runtime (see 03-parameters.md).
|
|
3331
|
-
resolveDynamicParams(bag) {
|
|
3332
|
-
return this.props.dynamicParams.resolve(bag);
|
|
3333
|
-
}
|
|
3334
3477
|
// ── output model ───────────────────────────────────────────────────────────
|
|
3335
3478
|
toModel() {
|
|
3336
3479
|
const [ownStart, ownEnd] = this.props.appearanceColors ?? [];
|
|
3337
3480
|
const [colorStart, colorEnd] = this.extension.appearanceColors;
|
|
3481
|
+
const args = toArgs(this.params);
|
|
3338
3482
|
const metaInfo = {
|
|
3339
|
-
args
|
|
3483
|
+
args,
|
|
3340
3484
|
...this.result.toMetaInfo(this.id, this.params)
|
|
3341
3485
|
};
|
|
3342
|
-
|
|
3486
|
+
for (const [name, def] of this.dynamicPropsFields()) {
|
|
3487
|
+
args[name] = { ...args[name], schemaLoader: dynamicPropsLoaderName(this.id, name), dependsOn: def.dependsOn ?? [] };
|
|
3488
|
+
}
|
|
3489
|
+
if (this.dynamicParams) {
|
|
3343
3490
|
metaInfo.dynamicParams = {
|
|
3344
3491
|
methodName: dynamicParamsLoaderName(this.id),
|
|
3345
|
-
dependsOn: this.
|
|
3492
|
+
dependsOn: this.dynamicParams.dependsOn ?? []
|
|
3346
3493
|
};
|
|
3347
3494
|
}
|
|
3348
3495
|
return {
|
|
@@ -3357,7 +3504,7 @@ var ActionMethod = class extends ExtensionMethod {
|
|
|
3357
3504
|
returnType: this.result.returnType,
|
|
3358
3505
|
queryParams: [],
|
|
3359
3506
|
bodyParams: toBodyParams(this.params),
|
|
3360
|
-
paramsSchema: encodeParams(this.params.scheme),
|
|
3507
|
+
paramsSchema: encodeParams(this.params.scheme, { loaderIdOf: (name) => dynamicPropsLoaderName(this.id, name) }),
|
|
3361
3508
|
metaInfo
|
|
3362
3509
|
};
|
|
3363
3510
|
}
|
|
@@ -3744,7 +3891,11 @@ var LoaderMethod = class extends ExtensionMethod {
|
|
|
3744
3891
|
validate(methodData) {
|
|
3745
3892
|
const input = this.input(methodData);
|
|
3746
3893
|
const payload = input.parseField("payload", LoaderPayloadSchema);
|
|
3747
|
-
return this.criteria.normalize(payload.criteria, input.invalidCriteria(), { carryUnknown:
|
|
3894
|
+
return this.criteria.normalize(payload.criteria, input.invalidCriteria(), { carryUnknown: this.carryUnknown });
|
|
3895
|
+
}
|
|
3896
|
+
// Whether the criteria's undeclared keys ride through to the handler.
|
|
3897
|
+
get carryUnknown() {
|
|
3898
|
+
return true;
|
|
3748
3899
|
}
|
|
3749
3900
|
// Internal (SYSTEM-like): no icon, no colours, no sample. Its params are left opaque in the model — it is
|
|
3750
3901
|
// invoked with `{ criteria }` at runtime, not through a rendered form.
|
|
@@ -3776,7 +3927,9 @@ var SampleResultLoaderMethod = class extends LoaderMethod {
|
|
|
3776
3927
|
get returnType() {
|
|
3777
3928
|
return "OBJECT";
|
|
3778
3929
|
}
|
|
3779
|
-
// The sample varies with ANY param of the owner, so all of them are its criteria.
|
|
3930
|
+
// The sample varies with ANY param of the owner, so all of them are its criteria. Undeclared keys ride
|
|
3931
|
+
// through too: the node's other params come along, and the owner's `result` fn may read fields its
|
|
3932
|
+
// `dynamicParams` loaded.
|
|
3780
3933
|
get criteria() {
|
|
3781
3934
|
return this.owner.params;
|
|
3782
3935
|
}
|
|
@@ -3784,31 +3937,101 @@ var SampleResultLoaderMethod = class extends LoaderMethod {
|
|
|
3784
3937
|
return this.owner.result.runLoader(ctx.bagWith({ params: criteria }));
|
|
3785
3938
|
}
|
|
3786
3939
|
};
|
|
3787
|
-
var
|
|
3788
|
-
|
|
3940
|
+
var isZod = (value) => !!value?._zod;
|
|
3941
|
+
var ParamsLoaderMethod = class extends LoaderMethod {
|
|
3942
|
+
constructor(extension, owner, def) {
|
|
3789
3943
|
super(extension, owner);
|
|
3790
3944
|
this.owner = owner;
|
|
3945
|
+
this.def = def;
|
|
3791
3946
|
}
|
|
3792
|
-
|
|
3793
|
-
return dynamicParamsLoaderName(this.owner.id);
|
|
3794
|
-
}
|
|
3947
|
+
#criteria;
|
|
3795
3948
|
get registerAs() {
|
|
3796
3949
|
return "PARAM_SCHEMA_DEFINITION";
|
|
3797
3950
|
}
|
|
3798
3951
|
get returnType() {
|
|
3799
|
-
return "
|
|
3952
|
+
return "OBJECT";
|
|
3953
|
+
}
|
|
3954
|
+
get carryUnknown() {
|
|
3955
|
+
return false;
|
|
3800
3956
|
}
|
|
3957
|
+
// Built unguarded: the picked fields were already checked on the owner, and a picked sibling may itself
|
|
3958
|
+
// carry `.dynamicProps()`, which the guard only allows in an action's own `params`.
|
|
3801
3959
|
get criteria() {
|
|
3802
|
-
|
|
3960
|
+
const dependsOn = this.def.dependsOn ?? [];
|
|
3961
|
+
this.#criteria ??= MethodParams.of(
|
|
3962
|
+
z.object(Object.fromEntries(this.owner.params.fields().filter(([name]) => dependsOn.includes(name)))),
|
|
3963
|
+
{ serviceId: this.extension.id, kind: "loader criteria", itemId: this.name }
|
|
3964
|
+
);
|
|
3965
|
+
return this.#criteria;
|
|
3803
3966
|
}
|
|
3804
3967
|
async execute(criteria, ctx) {
|
|
3805
|
-
const
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3968
|
+
const loaded = await this.def.execute(ctx.bagWith({ criteria }));
|
|
3969
|
+
const params = this.toParams(loaded);
|
|
3970
|
+
return { paramsSchema: encodeParams(params.scheme), params: toProperties(params) };
|
|
3971
|
+
}
|
|
3972
|
+
// A plain shape is wrapped in `z.object()`; anything else that is not a `z.object` is refused by the same
|
|
3973
|
+
// guards a declared params slot goes through.
|
|
3974
|
+
toParams(loaded) {
|
|
3975
|
+
const source = { serviceId: this.extension.id, kind: "action", itemId: this.owner.id, slot: this.slot };
|
|
3976
|
+
const schema = loaded && typeof loaded === "object" && !isZod(loaded) ? z.object(loaded) : loaded;
|
|
3977
|
+
const returned = MethodParams.of(schema, source);
|
|
3978
|
+
const staticFields = this.staticFields;
|
|
3979
|
+
if (!staticFields.length) {
|
|
3980
|
+
return returned;
|
|
3981
|
+
}
|
|
3982
|
+
const staticNames = new Set(staticFields.map(([name]) => name));
|
|
3983
|
+
const repeated = returned.keys().filter((name) => staticNames.has(name));
|
|
3984
|
+
if (repeated.length) {
|
|
3985
|
+
throw new InvalidSchemaError(
|
|
3986
|
+
`[flow-extension:${this.extension.id}] action "${this.owner.id}": \`${this.slot}\` returned ${repeated.map((name) => `"${name}"`).join(", ")}, which ${repeated.length > 1 ? "are" : "is"} already declared statically. A loaded field may not replace a declared one \u2014 rename it.`,
|
|
3987
|
+
{ ...source, received: repeated }
|
|
3988
|
+
);
|
|
3989
|
+
}
|
|
3990
|
+
return MethodParams.of(z.object(Object.fromEntries([...staticFields, ...returned.fields()])), source);
|
|
3991
|
+
}
|
|
3992
|
+
};
|
|
3993
|
+
var DynamicParamsLoaderMethod = class extends ParamsLoaderMethod {
|
|
3994
|
+
constructor(extension, owner) {
|
|
3995
|
+
super(extension, owner, owner.dynamicParams);
|
|
3996
|
+
}
|
|
3997
|
+
get name() {
|
|
3998
|
+
return dynamicParamsLoaderName(this.owner.id);
|
|
3999
|
+
}
|
|
4000
|
+
get slot() {
|
|
4001
|
+
return "dynamicParams.execute()";
|
|
4002
|
+
}
|
|
4003
|
+
get staticFields() {
|
|
4004
|
+
return [];
|
|
4005
|
+
}
|
|
4006
|
+
toParams(loaded) {
|
|
4007
|
+
const params = super.toParams(loaded);
|
|
4008
|
+
const declared = new Set(this.owner.params.keys());
|
|
4009
|
+
const shadowing = params.keys().filter((name) => declared.has(name));
|
|
4010
|
+
if (shadowing.length) {
|
|
4011
|
+
throw new InvalidSchemaError(
|
|
4012
|
+
`[flow-extension:${this.extension.id}] action "${this.owner.id}": \`${this.slot}\` returned ${shadowing.map((name) => `"${name}"`).join(", ")}, which the action already declares in \`params\`. A loaded param may not shadow a declared one \u2014 rename it.`,
|
|
4013
|
+
{ serviceId: this.extension.id, kind: "action", itemId: this.owner.id, slot: this.slot, received: shadowing }
|
|
4014
|
+
);
|
|
4015
|
+
}
|
|
4016
|
+
return params;
|
|
4017
|
+
}
|
|
4018
|
+
};
|
|
4019
|
+
var DynamicPropsLoaderMethod = class extends ParamsLoaderMethod {
|
|
4020
|
+
constructor(extension, owner, field, def) {
|
|
4021
|
+
super(extension, owner, def);
|
|
4022
|
+
this.field = field;
|
|
4023
|
+
}
|
|
4024
|
+
get name() {
|
|
4025
|
+
return dynamicPropsLoaderName(this.owner.id, this.field);
|
|
4026
|
+
}
|
|
4027
|
+
get slot() {
|
|
4028
|
+
return `params.${this.field}.dynamicProps().execute()`;
|
|
4029
|
+
}
|
|
4030
|
+
get staticFields() {
|
|
4031
|
+
const schema = this.owner.params.fields().find(([name]) => name === this.field)?.[1];
|
|
4032
|
+
const ins = inspect(schema);
|
|
4033
|
+
const object = ins.resolvedType === "array" ? ins.core?._zod?.def?.element : schema;
|
|
4034
|
+
return shapeEntries(inspect(object).core);
|
|
3812
4035
|
}
|
|
3813
4036
|
};
|
|
3814
4037
|
|
|
@@ -4721,6 +4944,9 @@ var Extension = class {
|
|
|
4721
4944
|
if (action.hasDynamicParams()) {
|
|
4722
4945
|
this.#addMethod(new DynamicParamsLoaderMethod(this, action), "dynamic params loader");
|
|
4723
4946
|
}
|
|
4947
|
+
for (const [field, def] of action.dynamicPropsFields()) {
|
|
4948
|
+
this.#addMethod(new DynamicPropsLoaderMethod(this, action, field, def), "dynamic props loader");
|
|
4949
|
+
}
|
|
4724
4950
|
}
|
|
4725
4951
|
registerPollingTrigger(props) {
|
|
4726
4952
|
this.#claimId(props.id, "polling trigger");
|