@flowrunner/cli 0.1.9 → 0.1.10
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 +3 -2
- package/ai-docs/instructions/service-code-format/02-zod-types.md +8 -0
- package/ai-docs/instructions/service-code-format/03-parameters.md +181 -10
- package/ai-docs/instructions/service-code-format/04-http-requests.md +2 -2
- package/ai-docs/instructions/service-code-format/05-dictionaries.md +14 -0
- package/ai-docs/instructions/service-code-format/07-actions.md +5 -4
- 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/13-runtime-contracts.md +4 -1
- package/ai-docs/instructions/service-code-format/15-unit-tests.md +2 -1
- package/ai-docs/instructions/service-code-format/16-gotchas.md +39 -1
- 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 +276 -42
- package/dist/cli.js.map +3 -3
- package/dist/index.js +275 -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 +20 -8
- 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 +9 -3
- 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 +275 -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 +20 -8
- 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 +9 -3
- 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/demo-todo-list/files/src/index.js +6 -6
- package/templates/qa-test/files/README.md +23 -8
- package/templates/qa-test/files/src/index.js +368 -37
|
@@ -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,85 @@ 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) {
|
|
1850
|
+
return;
|
|
1851
|
+
}
|
|
1852
|
+
if (typeof spec.id === "string" && !("execute" in spec)) {
|
|
1853
|
+
return;
|
|
1854
|
+
}
|
|
1855
|
+
if (typeof spec.execute !== "function") {
|
|
1856
|
+
refuse(
|
|
1857
|
+
`${subjectOf(source, path2)}: \`.dynamicProps()\` needs an \`execute\` function that returns the loaded fields.`,
|
|
1858
|
+
source,
|
|
1859
|
+
path2,
|
|
1860
|
+
typeof spec.execute
|
|
1861
|
+
);
|
|
1862
|
+
}
|
|
1863
|
+
if (spec.dependsOn !== void 0 && (!Array.isArray(spec.dependsOn) || spec.dependsOn.some((item) => typeof item !== "string"))) {
|
|
1864
|
+
refuse(
|
|
1865
|
+
`${subjectOf(source, path2)}: \`.dynamicProps()\` \`dependsOn\` must be an array of param names.`,
|
|
1866
|
+
source,
|
|
1867
|
+
path2,
|
|
1868
|
+
"dependsOn"
|
|
1869
|
+
);
|
|
1870
|
+
}
|
|
1871
|
+
for (const dependency of spec.dependsOn ?? []) {
|
|
1872
|
+
if (dependency === name || !siblings.includes(dependency)) {
|
|
1873
|
+
refuse(
|
|
1874
|
+
`${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"}.`,
|
|
1875
|
+
source,
|
|
1876
|
+
path2,
|
|
1877
|
+
dependency
|
|
1878
|
+
);
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
if (ins.meta.frDictionary) {
|
|
1882
|
+
refuse(
|
|
1883
|
+
`${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.`,
|
|
1884
|
+
source,
|
|
1885
|
+
path2,
|
|
1886
|
+
"dictionary"
|
|
1887
|
+
);
|
|
1888
|
+
}
|
|
1889
|
+
const element = ins.resolvedType === "array" ? ins.core?._zod?.def?.element : void 0;
|
|
1890
|
+
if (!isLooseObject(schema) && !isLooseObject(element)) {
|
|
1891
|
+
refuse(
|
|
1892
|
+
`${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}`,
|
|
1893
|
+
source,
|
|
1894
|
+
path2,
|
|
1895
|
+
ins.resolvedType ?? "unknown"
|
|
1896
|
+
);
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
function assertField(schema, source, path2, seen, topLevel = false) {
|
|
1833
1900
|
if (!schema || seen.has(schema)) {
|
|
1834
1901
|
return;
|
|
1835
1902
|
}
|
|
1836
1903
|
seen.add(schema);
|
|
1837
1904
|
const ins = inspect(schema);
|
|
1905
|
+
if (ins.meta.frDynamicProps && !isDynamicPropsSlot(source, topLevel)) {
|
|
1906
|
+
refuse(
|
|
1907
|
+
`${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.`,
|
|
1908
|
+
source,
|
|
1909
|
+
path2,
|
|
1910
|
+
"dynamicProps"
|
|
1911
|
+
);
|
|
1912
|
+
}
|
|
1838
1913
|
if (ins.resolvedType === "catch") {
|
|
1839
1914
|
refuseCatch(source, path2);
|
|
1840
1915
|
}
|
|
@@ -1863,8 +1938,13 @@ function assertSupportedSchema(scheme, source) {
|
|
|
1863
1938
|
}
|
|
1864
1939
|
const slot = source.slot ?? "schema";
|
|
1865
1940
|
const seen = /* @__PURE__ */ new Set();
|
|
1866
|
-
|
|
1867
|
-
|
|
1941
|
+
const fields = shapeEntries(scheme);
|
|
1942
|
+
const names = fields.map(([name]) => name);
|
|
1943
|
+
for (const [name, field] of fields) {
|
|
1944
|
+
assertField(field, source, `${slot}.${name}`, seen, true);
|
|
1945
|
+
if (isDynamicPropsSlot(source, true)) {
|
|
1946
|
+
assertDynamicProps(field, name, names, source, `${slot}.${name}`);
|
|
1947
|
+
}
|
|
1868
1948
|
}
|
|
1869
1949
|
}
|
|
1870
1950
|
|
|
@@ -2686,6 +2766,14 @@ function extendPrototype() {
|
|
|
2686
2766
|
proto.labels = function labels(byValue) {
|
|
2687
2767
|
return this.meta({ frLabels: byValue });
|
|
2688
2768
|
};
|
|
2769
|
+
proto.dynamicProps = function dynamicProps(spec) {
|
|
2770
|
+
if (!spec || typeof spec !== "object") {
|
|
2771
|
+
throw new Error(
|
|
2772
|
+
"`.dynamicProps()` takes `{ dependsOn, execute }` \u2014 the params the fields depend on, and a function that returns them. e.g. .dynamicProps({ dependsOn: ['tableName'], execute: async ({ criteria }) => ({ \u2026 }) })"
|
|
2773
|
+
);
|
|
2774
|
+
}
|
|
2775
|
+
return this.meta({ frDynamicProps: spec });
|
|
2776
|
+
};
|
|
2689
2777
|
proto.map = function map() {
|
|
2690
2778
|
throw new Error(
|
|
2691
2779
|
"`.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 +2994,36 @@ function unwrap(schema) {
|
|
|
2906
2994
|
}
|
|
2907
2995
|
return result;
|
|
2908
2996
|
}
|
|
2909
|
-
function
|
|
2910
|
-
|
|
2997
|
+
function isDynamicPropsSpec(value) {
|
|
2998
|
+
return !!value && typeof value === "object" && typeof value.execute === "function";
|
|
2999
|
+
}
|
|
3000
|
+
function hasFunction(value, depth = 0) {
|
|
3001
|
+
if (typeof value === "function") {
|
|
3002
|
+
return true;
|
|
3003
|
+
}
|
|
3004
|
+
if (!value || typeof value !== "object" || depth > MAX_UNWRAP_DEPTH) {
|
|
3005
|
+
return false;
|
|
3006
|
+
}
|
|
3007
|
+
return Object.values(value).some((inner) => hasFunction(inner, depth + 1));
|
|
3008
|
+
}
|
|
3009
|
+
function encodeMeta(meta, field, loaderId) {
|
|
3010
|
+
let source = meta;
|
|
3011
|
+
if (isDynamicPropsSpec(meta.frDynamicProps)) {
|
|
3012
|
+
if (!loaderId) {
|
|
3013
|
+
throw new Error(`Cannot encode "${field}": its \`.dynamicProps()\` has no loader method to publish.`);
|
|
3014
|
+
}
|
|
3015
|
+
source = { ...meta, frDynamicProps: { id: loaderId, dependsOn: meta.frDynamicProps.dependsOn ?? [] } };
|
|
3016
|
+
}
|
|
3017
|
+
if (hasFunction(source)) {
|
|
3018
|
+
throw new Error(`Cannot encode "${field}": its metadata holds a function, which has no wire form.`);
|
|
3019
|
+
}
|
|
3020
|
+
const encoded = toJsonValue2(source);
|
|
2911
3021
|
return Object.keys(encoded).length ? encoded : void 0;
|
|
2912
3022
|
}
|
|
3023
|
+
function isLoose(core) {
|
|
3024
|
+
const catchall = core?._zod?.def?.catchall;
|
|
3025
|
+
return catchall?._zod?.def?.type === "unknown";
|
|
3026
|
+
}
|
|
2913
3027
|
function encodeValues(core, type) {
|
|
2914
3028
|
if (type === "enum") {
|
|
2915
3029
|
const entries = core?._zod?.def?.entries ?? {};
|
|
@@ -2921,7 +3035,7 @@ function encodeValues(core, type) {
|
|
|
2921
3035
|
}
|
|
2922
3036
|
return void 0;
|
|
2923
3037
|
}
|
|
2924
|
-
function encodeField(name, schema, seen = /* @__PURE__ */ new Set()) {
|
|
3038
|
+
function encodeField(name, schema, seen = /* @__PURE__ */ new Set(), loaderId) {
|
|
2925
3039
|
if (seen.has(schema)) {
|
|
2926
3040
|
return { name, type: "unknown", unsupported: ["recursion"] };
|
|
2927
3041
|
}
|
|
@@ -2934,7 +3048,7 @@ function encodeField(name, schema, seen = /* @__PURE__ */ new Set()) {
|
|
|
2934
3048
|
const isUnion = !!ins.branches;
|
|
2935
3049
|
const format = isUnion ? void 0 : core?._zod?.def?.format;
|
|
2936
3050
|
const { checks, unsupported: checkIssues } = isUnion ? { checks: [], unsupported: [] } : encodeChecks(core);
|
|
2937
|
-
const meta = encodeMeta(ins.meta);
|
|
3051
|
+
const meta = encodeMeta(ins.meta, name, loaderId);
|
|
2938
3052
|
const message = isUnion ? void 0 : messageOf(core?._zod?.def ?? {});
|
|
2939
3053
|
const values = encodeValues(core, type);
|
|
2940
3054
|
const problems = [...unsupported, ...checkIssues];
|
|
@@ -2952,6 +3066,7 @@ function encodeField(name, schema, seen = /* @__PURE__ */ new Set()) {
|
|
|
2952
3066
|
...values?.length ? { values } : {},
|
|
2953
3067
|
...meta ? { meta } : {},
|
|
2954
3068
|
...message ? { message } : {},
|
|
3069
|
+
...type === "object" && isLoose(core) ? { loose: true } : {},
|
|
2955
3070
|
...type === "object" ? { properties: shapeEntries(core).map(([key, inner]) => encodeField(key, inner, seen)) } : {},
|
|
2956
3071
|
...type === "array" ? { element: encodeField("", core?._zod?.def?.element, seen) } : {},
|
|
2957
3072
|
...type === "record" ? { value: encodeField("", core?._zod?.def?.valueType, seen) } : {},
|
|
@@ -2961,14 +3076,14 @@ function encodeField(name, schema, seen = /* @__PURE__ */ new Set()) {
|
|
|
2961
3076
|
seen.delete(schema);
|
|
2962
3077
|
return encoded;
|
|
2963
3078
|
}
|
|
2964
|
-
function encodeParams(scheme) {
|
|
3079
|
+
function encodeParams(scheme, options = {}) {
|
|
2965
3080
|
const schema = scheme;
|
|
2966
3081
|
if (!schema?._zod) {
|
|
2967
3082
|
return null;
|
|
2968
3083
|
}
|
|
2969
3084
|
return {
|
|
2970
3085
|
v: SCHEMA_JSON_VERSION,
|
|
2971
|
-
fields: shapeEntries(schema).map(([name, field]) => encodeField(name, field))
|
|
3086
|
+
fields: shapeEntries(schema).map(([name, field]) => encodeField(name, field, /* @__PURE__ */ new Set(), options.loaderIdOf?.(name)))
|
|
2972
3087
|
};
|
|
2973
3088
|
}
|
|
2974
3089
|
|
|
@@ -3284,11 +3399,50 @@ var ActionMethod = class extends ExtensionMethod {
|
|
|
3284
3399
|
this.props = props;
|
|
3285
3400
|
this.params = MethodParams.of(props.params, { serviceId: extension.id, kind: "action", itemId: props.id, slot: "params" });
|
|
3286
3401
|
this.result = ResultSpec.from(props.result);
|
|
3287
|
-
this.
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3402
|
+
this.dynamicParams = props.dynamicParams ? this.#checkDynamicParams(props.dynamicParams) : void 0;
|
|
3403
|
+
}
|
|
3404
|
+
/**
|
|
3405
|
+
* `dynamicParams` takes the same `{ dependsOn, execute }` as `.dynamicProps()`. The old
|
|
3406
|
+
* `{ criteria, resolve }` shape is refused by name, so a service written against it fails at load with the
|
|
3407
|
+
* fix rather than publishing a loader that never runs.
|
|
3408
|
+
*/
|
|
3409
|
+
#checkDynamicParams(def) {
|
|
3410
|
+
const source = { serviceId: this.extension.id, kind: "action", itemId: this.props.id, slot: "dynamicParams" };
|
|
3411
|
+
const fail2 = (message, received) => {
|
|
3412
|
+
throw new InvalidSchemaError(`[flow-extension:${this.extension.id}] action "${this.props.id}": ${message}`, { ...source, received });
|
|
3413
|
+
};
|
|
3414
|
+
const legacy = def;
|
|
3415
|
+
if (legacy.resolve !== void 0 || legacy.criteria !== void 0) {
|
|
3416
|
+
fail2(
|
|
3417
|
+
"`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() }) }",
|
|
3418
|
+
"criteria/resolve"
|
|
3419
|
+
);
|
|
3420
|
+
}
|
|
3421
|
+
if (typeof def.execute !== "function") {
|
|
3422
|
+
fail2("`dynamicParams` needs an `execute` function that returns the loaded params.", typeof def.execute);
|
|
3423
|
+
}
|
|
3424
|
+
if (def.dependsOn !== void 0 && (!Array.isArray(def.dependsOn) || def.dependsOn.some((item) => typeof item !== "string"))) {
|
|
3425
|
+
fail2("`dynamicParams.dependsOn` must be an array of param names.", def.dependsOn);
|
|
3426
|
+
}
|
|
3427
|
+
const declared = this.params.keys();
|
|
3428
|
+
for (const dependency of def.dependsOn ?? []) {
|
|
3429
|
+
if (!declared.includes(dependency)) {
|
|
3430
|
+
fail2(
|
|
3431
|
+
`\`dynamicParams\` depends on "${dependency}", which the action does not declare in \`params\`. Declared: ${declared.join(", ") || "none"}.`,
|
|
3432
|
+
dependency
|
|
3433
|
+
);
|
|
3434
|
+
}
|
|
3435
|
+
}
|
|
3436
|
+
return def;
|
|
3437
|
+
}
|
|
3438
|
+
/**
|
|
3439
|
+
* The top-level params declared with `.dynamicProps()`, and the def each one carries. Placement and shape
|
|
3440
|
+
* were checked when `params` was built (see ../params/schema/assert-supported-schema.ts).
|
|
3441
|
+
*/
|
|
3442
|
+
dynamicPropsFields() {
|
|
3443
|
+
return this.params.fields().flatMap(([name, schema]) => {
|
|
3444
|
+
const def = inspect(schema).meta.frDynamicProps;
|
|
3445
|
+
return def && !(typeof def.id === "string" && !("execute" in def)) ? [[name, def]] : [];
|
|
3292
3446
|
});
|
|
3293
3447
|
}
|
|
3294
3448
|
get id() {
|
|
@@ -3314,8 +3468,9 @@ var ActionMethod = class extends ExtensionMethod {
|
|
|
3314
3468
|
* Normalize, coerce and validate against the declared `params` — the same pipeline every other declared
|
|
3315
3469
|
* slot uses, so an author expresses optionality in the schema and nowhere else.
|
|
3316
3470
|
*
|
|
3317
|
-
* An action with `dynamicParams` carries the input's undeclared keys through, since its
|
|
3318
|
-
*
|
|
3471
|
+
* An action with `dynamicParams` carries the input's undeclared keys through, since its loaded top-level
|
|
3472
|
+
* fields are not in the static schema. A `.dynamicProps()` field needs nothing here: it is a loose object,
|
|
3473
|
+
* which keeps the loaded keys inside it.
|
|
3319
3474
|
*/
|
|
3320
3475
|
validate(methodData) {
|
|
3321
3476
|
return this.params.normalize(
|
|
@@ -3327,22 +3482,22 @@ var ActionMethod = class extends ExtensionMethod {
|
|
|
3327
3482
|
execute(params, ctx) {
|
|
3328
3483
|
return this.props.execute(ctx.bagWith({ params }));
|
|
3329
3484
|
}
|
|
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
3485
|
// ── output model ───────────────────────────────────────────────────────────
|
|
3335
3486
|
toModel() {
|
|
3336
3487
|
const [ownStart, ownEnd] = this.props.appearanceColors ?? [];
|
|
3337
3488
|
const [colorStart, colorEnd] = this.extension.appearanceColors;
|
|
3489
|
+
const args = toArgs(this.params);
|
|
3338
3490
|
const metaInfo = {
|
|
3339
|
-
args
|
|
3491
|
+
args,
|
|
3340
3492
|
...this.result.toMetaInfo(this.id, this.params)
|
|
3341
3493
|
};
|
|
3342
|
-
|
|
3494
|
+
for (const [name, def] of this.dynamicPropsFields()) {
|
|
3495
|
+
args[name] = { ...args[name], schemaLoader: dynamicPropsLoaderName(this.id, name), dependsOn: def.dependsOn ?? [] };
|
|
3496
|
+
}
|
|
3497
|
+
if (this.dynamicParams) {
|
|
3343
3498
|
metaInfo.dynamicParams = {
|
|
3344
3499
|
methodName: dynamicParamsLoaderName(this.id),
|
|
3345
|
-
dependsOn: this.
|
|
3500
|
+
dependsOn: this.dynamicParams.dependsOn ?? []
|
|
3346
3501
|
};
|
|
3347
3502
|
}
|
|
3348
3503
|
return {
|
|
@@ -3357,7 +3512,7 @@ var ActionMethod = class extends ExtensionMethod {
|
|
|
3357
3512
|
returnType: this.result.returnType,
|
|
3358
3513
|
queryParams: [],
|
|
3359
3514
|
bodyParams: toBodyParams(this.params),
|
|
3360
|
-
paramsSchema: encodeParams(this.params.scheme),
|
|
3515
|
+
paramsSchema: encodeParams(this.params.scheme, { loaderIdOf: (name) => dynamicPropsLoaderName(this.id, name) }),
|
|
3361
3516
|
metaInfo
|
|
3362
3517
|
};
|
|
3363
3518
|
}
|
|
@@ -3744,7 +3899,11 @@ var LoaderMethod = class extends ExtensionMethod {
|
|
|
3744
3899
|
validate(methodData) {
|
|
3745
3900
|
const input = this.input(methodData);
|
|
3746
3901
|
const payload = input.parseField("payload", LoaderPayloadSchema);
|
|
3747
|
-
return this.criteria.normalize(payload.criteria, input.invalidCriteria(), { carryUnknown:
|
|
3902
|
+
return this.criteria.normalize(payload.criteria, input.invalidCriteria(), { carryUnknown: this.carryUnknown });
|
|
3903
|
+
}
|
|
3904
|
+
// Whether the criteria's undeclared keys ride through to the handler.
|
|
3905
|
+
get carryUnknown() {
|
|
3906
|
+
return true;
|
|
3748
3907
|
}
|
|
3749
3908
|
// Internal (SYSTEM-like): no icon, no colours, no sample. Its params are left opaque in the model — it is
|
|
3750
3909
|
// invoked with `{ criteria }` at runtime, not through a rendered form.
|
|
@@ -3776,7 +3935,9 @@ var SampleResultLoaderMethod = class extends LoaderMethod {
|
|
|
3776
3935
|
get returnType() {
|
|
3777
3936
|
return "OBJECT";
|
|
3778
3937
|
}
|
|
3779
|
-
// The sample varies with ANY param of the owner, so all of them are its criteria.
|
|
3938
|
+
// The sample varies with ANY param of the owner, so all of them are its criteria. Undeclared keys ride
|
|
3939
|
+
// through too: the node's other params come along, and the owner's `result` fn may read fields its
|
|
3940
|
+
// `dynamicParams` loaded.
|
|
3780
3941
|
get criteria() {
|
|
3781
3942
|
return this.owner.params;
|
|
3782
3943
|
}
|
|
@@ -3784,31 +3945,101 @@ var SampleResultLoaderMethod = class extends LoaderMethod {
|
|
|
3784
3945
|
return this.owner.result.runLoader(ctx.bagWith({ params: criteria }));
|
|
3785
3946
|
}
|
|
3786
3947
|
};
|
|
3787
|
-
var
|
|
3788
|
-
|
|
3948
|
+
var isZod = (value) => !!value?._zod;
|
|
3949
|
+
var ParamsLoaderMethod = class extends LoaderMethod {
|
|
3950
|
+
constructor(extension, owner, def) {
|
|
3789
3951
|
super(extension, owner);
|
|
3790
3952
|
this.owner = owner;
|
|
3953
|
+
this.def = def;
|
|
3791
3954
|
}
|
|
3792
|
-
|
|
3793
|
-
return dynamicParamsLoaderName(this.owner.id);
|
|
3794
|
-
}
|
|
3955
|
+
#criteria;
|
|
3795
3956
|
get registerAs() {
|
|
3796
3957
|
return "PARAM_SCHEMA_DEFINITION";
|
|
3797
3958
|
}
|
|
3798
3959
|
get returnType() {
|
|
3799
|
-
return "
|
|
3960
|
+
return "OBJECT";
|
|
3800
3961
|
}
|
|
3962
|
+
get carryUnknown() {
|
|
3963
|
+
return false;
|
|
3964
|
+
}
|
|
3965
|
+
// Built unguarded: the picked fields were already checked on the owner, and a picked sibling may itself
|
|
3966
|
+
// carry `.dynamicProps()`, which the guard only allows in an action's own `params`.
|
|
3801
3967
|
get criteria() {
|
|
3802
|
-
|
|
3968
|
+
const dependsOn = this.def.dependsOn ?? [];
|
|
3969
|
+
this.#criteria ??= MethodParams.of(
|
|
3970
|
+
z.object(Object.fromEntries(this.owner.params.fields().filter(([name]) => dependsOn.includes(name)))),
|
|
3971
|
+
{ serviceId: this.extension.id, kind: "loader criteria", itemId: this.name }
|
|
3972
|
+
);
|
|
3973
|
+
return this.#criteria;
|
|
3803
3974
|
}
|
|
3804
3975
|
async execute(criteria, ctx) {
|
|
3805
|
-
const
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3976
|
+
const loaded = await this.def.execute(ctx.bagWith({ criteria }));
|
|
3977
|
+
const params = this.toParams(loaded);
|
|
3978
|
+
return { paramsSchema: encodeParams(params.scheme), params: toProperties(params) };
|
|
3979
|
+
}
|
|
3980
|
+
// A plain shape is wrapped in `z.object()`; anything else that is not a `z.object` is refused by the same
|
|
3981
|
+
// guards a declared params slot goes through.
|
|
3982
|
+
toParams(loaded) {
|
|
3983
|
+
const source = { serviceId: this.extension.id, kind: "action", itemId: this.owner.id, slot: this.slot };
|
|
3984
|
+
const schema = loaded && typeof loaded === "object" && !isZod(loaded) ? z.object(loaded) : loaded;
|
|
3985
|
+
const returned = MethodParams.of(schema, source);
|
|
3986
|
+
const staticFields = this.staticFields;
|
|
3987
|
+
if (!staticFields.length) {
|
|
3988
|
+
return returned;
|
|
3989
|
+
}
|
|
3990
|
+
const staticNames = new Set(staticFields.map(([name]) => name));
|
|
3991
|
+
const repeated = returned.keys().filter((name) => staticNames.has(name));
|
|
3992
|
+
if (repeated.length) {
|
|
3993
|
+
throw new InvalidSchemaError(
|
|
3994
|
+
`[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.`,
|
|
3995
|
+
{ ...source, received: repeated }
|
|
3996
|
+
);
|
|
3997
|
+
}
|
|
3998
|
+
return MethodParams.of(z.object(Object.fromEntries([...staticFields, ...returned.fields()])), source);
|
|
3999
|
+
}
|
|
4000
|
+
};
|
|
4001
|
+
var DynamicParamsLoaderMethod = class extends ParamsLoaderMethod {
|
|
4002
|
+
constructor(extension, owner) {
|
|
4003
|
+
super(extension, owner, owner.dynamicParams);
|
|
4004
|
+
}
|
|
4005
|
+
get name() {
|
|
4006
|
+
return dynamicParamsLoaderName(this.owner.id);
|
|
4007
|
+
}
|
|
4008
|
+
get slot() {
|
|
4009
|
+
return "dynamicParams.execute()";
|
|
4010
|
+
}
|
|
4011
|
+
get staticFields() {
|
|
4012
|
+
return [];
|
|
4013
|
+
}
|
|
4014
|
+
toParams(loaded) {
|
|
4015
|
+
const params = super.toParams(loaded);
|
|
4016
|
+
const declared = new Set(this.owner.params.keys());
|
|
4017
|
+
const shadowing = params.keys().filter((name) => declared.has(name));
|
|
4018
|
+
if (shadowing.length) {
|
|
4019
|
+
throw new InvalidSchemaError(
|
|
4020
|
+
`[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.`,
|
|
4021
|
+
{ serviceId: this.extension.id, kind: "action", itemId: this.owner.id, slot: this.slot, received: shadowing }
|
|
4022
|
+
);
|
|
4023
|
+
}
|
|
4024
|
+
return params;
|
|
4025
|
+
}
|
|
4026
|
+
};
|
|
4027
|
+
var DynamicPropsLoaderMethod = class extends ParamsLoaderMethod {
|
|
4028
|
+
constructor(extension, owner, field, def) {
|
|
4029
|
+
super(extension, owner, def);
|
|
4030
|
+
this.field = field;
|
|
4031
|
+
}
|
|
4032
|
+
get name() {
|
|
4033
|
+
return dynamicPropsLoaderName(this.owner.id, this.field);
|
|
4034
|
+
}
|
|
4035
|
+
get slot() {
|
|
4036
|
+
return `params.${this.field}.dynamicProps().execute()`;
|
|
4037
|
+
}
|
|
4038
|
+
get staticFields() {
|
|
4039
|
+
const schema = this.owner.params.fields().find(([name]) => name === this.field)?.[1];
|
|
4040
|
+
const ins = inspect(schema);
|
|
4041
|
+
const object = ins.resolvedType === "array" ? ins.core?._zod?.def?.element : schema;
|
|
4042
|
+
return shapeEntries(inspect(object).core);
|
|
3812
4043
|
}
|
|
3813
4044
|
};
|
|
3814
4045
|
|
|
@@ -4721,6 +4952,9 @@ var Extension = class {
|
|
|
4721
4952
|
if (action.hasDynamicParams()) {
|
|
4722
4953
|
this.#addMethod(new DynamicParamsLoaderMethod(this, action), "dynamic params loader");
|
|
4723
4954
|
}
|
|
4955
|
+
for (const [field, def] of action.dynamicPropsFields()) {
|
|
4956
|
+
this.#addMethod(new DynamicPropsLoaderMethod(this, action, field, def), "dynamic props loader");
|
|
4957
|
+
}
|
|
4724
4958
|
}
|
|
4725
4959
|
registerPollingTrigger(props) {
|
|
4726
4960
|
this.#claimId(props.id, "polling trigger");
|