@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
package/dist/cli.js
CHANGED
|
@@ -4185,7 +4185,7 @@ var require_package = __commonJS({
|
|
|
4185
4185
|
"package.json"(exports2, module2) {
|
|
4186
4186
|
module2.exports = {
|
|
4187
4187
|
name: "@flowrunner/cli",
|
|
4188
|
-
version: "0.1.
|
|
4188
|
+
version: "0.1.10",
|
|
4189
4189
|
publishConfig: {
|
|
4190
4190
|
access: "public"
|
|
4191
4191
|
},
|
|
@@ -5397,6 +5397,7 @@ var InvalidDictionaryOutputScheme = class extends FlowExtensionError {
|
|
|
5397
5397
|
// ../../flow-extension-runner/src/v2/loaders/loader-owner.ts
|
|
5398
5398
|
var sampleResultLoaderName = (ownerId) => `${ownerId}_SampleResultLoader`;
|
|
5399
5399
|
var dynamicParamsLoaderName = (ownerId) => `${ownerId}_DynamicParams`;
|
|
5400
|
+
var dynamicPropsLoaderName = (ownerId, field) => `${ownerId}_${field}_DynamicProps`;
|
|
5400
5401
|
|
|
5401
5402
|
// ../../flow-extension-runner/src/v2/params/schema/assert-object-schema.ts
|
|
5402
5403
|
var WRAPPERS = /* @__PURE__ */ new Set(["optional", "nullable", "nullish", "default", "prefault"]);
|
|
@@ -5440,8 +5441,9 @@ function assertObjectSchema(scheme, source) {
|
|
|
5440
5441
|
const isReturn = slot.endsWith("()");
|
|
5441
5442
|
const subject = source.itemId ? `${kind} "${source.itemId}": ` : "";
|
|
5442
5443
|
const received = describe(scheme);
|
|
5444
|
+
const expected = slot.endsWith(".execute()") ? "a z.object({ \u2026 }) or a shape of zod fields" : "a z.object({ \u2026 })";
|
|
5443
5445
|
throw new InvalidSchemaError(
|
|
5444
|
-
`[flow-extension:${source.serviceId}] ${subject}\`${slot}\` ${isReturn ? "must return" : "must be"}
|
|
5446
|
+
`[flow-extension:${source.serviceId}] ${subject}\`${slot}\` ${isReturn ? "must return" : "must be"} ${expected} \u2014 received ${received}${hint(scheme, slot, isReturn)}`,
|
|
5445
5447
|
{ serviceId: source.serviceId, kind, itemId: source.itemId, slot, received }
|
|
5446
5448
|
);
|
|
5447
5449
|
}
|
|
@@ -5664,12 +5666,85 @@ function refuseType(source, path23, type) {
|
|
|
5664
5666
|
type ?? "unknown"
|
|
5665
5667
|
);
|
|
5666
5668
|
}
|
|
5667
|
-
|
|
5669
|
+
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.";
|
|
5670
|
+
function isLooseObject(schema) {
|
|
5671
|
+
if (!schema) {
|
|
5672
|
+
return false;
|
|
5673
|
+
}
|
|
5674
|
+
const ins = inspect(schema);
|
|
5675
|
+
const catchall = ins.core?._zod?.def?.catchall;
|
|
5676
|
+
return ins.resolvedType === "object" && catchall?._zod?.def?.type === "unknown";
|
|
5677
|
+
}
|
|
5678
|
+
function isDynamicPropsSlot(source, topLevel) {
|
|
5679
|
+
return topLevel && source.kind === "action" && source.slot === "params";
|
|
5680
|
+
}
|
|
5681
|
+
function assertDynamicProps(schema, name, siblings, source, path23) {
|
|
5682
|
+
const ins = inspect(schema);
|
|
5683
|
+
const spec = ins.meta.frDynamicProps;
|
|
5684
|
+
if (!spec) {
|
|
5685
|
+
return;
|
|
5686
|
+
}
|
|
5687
|
+
if (typeof spec.id === "string" && !("execute" in spec)) {
|
|
5688
|
+
return;
|
|
5689
|
+
}
|
|
5690
|
+
if (typeof spec.execute !== "function") {
|
|
5691
|
+
refuse(
|
|
5692
|
+
`${subjectOf(source, path23)}: \`.dynamicProps()\` needs an \`execute\` function that returns the loaded fields.`,
|
|
5693
|
+
source,
|
|
5694
|
+
path23,
|
|
5695
|
+
typeof spec.execute
|
|
5696
|
+
);
|
|
5697
|
+
}
|
|
5698
|
+
if (spec.dependsOn !== void 0 && (!Array.isArray(spec.dependsOn) || spec.dependsOn.some((item) => typeof item !== "string"))) {
|
|
5699
|
+
refuse(
|
|
5700
|
+
`${subjectOf(source, path23)}: \`.dynamicProps()\` \`dependsOn\` must be an array of param names.`,
|
|
5701
|
+
source,
|
|
5702
|
+
path23,
|
|
5703
|
+
"dependsOn"
|
|
5704
|
+
);
|
|
5705
|
+
}
|
|
5706
|
+
for (const dependency of spec.dependsOn ?? []) {
|
|
5707
|
+
if (dependency === name || !siblings.includes(dependency)) {
|
|
5708
|
+
refuse(
|
|
5709
|
+
`${subjectOf(source, path23)}: \`.dynamicProps()\` depends on "${dependency}", which is not another param of this action. Name its sibling params: ${siblings.filter((sibling) => sibling !== name).join(", ") || "none"}.`,
|
|
5710
|
+
source,
|
|
5711
|
+
path23,
|
|
5712
|
+
dependency
|
|
5713
|
+
);
|
|
5714
|
+
}
|
|
5715
|
+
}
|
|
5716
|
+
if (ins.meta.frDictionary) {
|
|
5717
|
+
refuse(
|
|
5718
|
+
`${subjectOf(source, path23)} 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.`,
|
|
5719
|
+
source,
|
|
5720
|
+
path23,
|
|
5721
|
+
"dictionary"
|
|
5722
|
+
);
|
|
5723
|
+
}
|
|
5724
|
+
const element = ins.resolvedType === "array" ? ins.core?._zod?.def?.element : void 0;
|
|
5725
|
+
if (!isLooseObject(schema) && !isLooseObject(element)) {
|
|
5726
|
+
refuse(
|
|
5727
|
+
`${subjectOf(source, path23)}: \`.dynamicProps()\` needs a loose object \u2014 the loaded fields are not declared, so a plain \`z.object()\` would strip them. ${DYNAMIC_PROPS_FIX}`,
|
|
5728
|
+
source,
|
|
5729
|
+
path23,
|
|
5730
|
+
ins.resolvedType ?? "unknown"
|
|
5731
|
+
);
|
|
5732
|
+
}
|
|
5733
|
+
}
|
|
5734
|
+
function assertField(schema, source, path23, seen, topLevel = false) {
|
|
5668
5735
|
if (!schema || seen.has(schema)) {
|
|
5669
5736
|
return;
|
|
5670
5737
|
}
|
|
5671
5738
|
seen.add(schema);
|
|
5672
5739
|
const ins = inspect(schema);
|
|
5740
|
+
if (ins.meta.frDynamicProps && !isDynamicPropsSlot(source, topLevel)) {
|
|
5741
|
+
refuse(
|
|
5742
|
+
`${subjectOf(source, path23)} 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.`,
|
|
5743
|
+
source,
|
|
5744
|
+
path23,
|
|
5745
|
+
"dynamicProps"
|
|
5746
|
+
);
|
|
5747
|
+
}
|
|
5673
5748
|
if (ins.resolvedType === "catch") {
|
|
5674
5749
|
refuseCatch(source, path23);
|
|
5675
5750
|
}
|
|
@@ -5698,8 +5773,13 @@ function assertSupportedSchema(scheme, source) {
|
|
|
5698
5773
|
}
|
|
5699
5774
|
const slot = source.slot ?? "schema";
|
|
5700
5775
|
const seen = /* @__PURE__ */ new Set();
|
|
5701
|
-
|
|
5702
|
-
|
|
5776
|
+
const fields = shapeEntries(scheme);
|
|
5777
|
+
const names = fields.map(([name]) => name);
|
|
5778
|
+
for (const [name, field] of fields) {
|
|
5779
|
+
assertField(field, source, `${slot}.${name}`, seen, true);
|
|
5780
|
+
if (isDynamicPropsSlot(source, true)) {
|
|
5781
|
+
assertDynamicProps(field, name, names, source, `${slot}.${name}`);
|
|
5782
|
+
}
|
|
5703
5783
|
}
|
|
5704
5784
|
}
|
|
5705
5785
|
|
|
@@ -6521,6 +6601,14 @@ function extendPrototype() {
|
|
|
6521
6601
|
proto.labels = function labels(byValue) {
|
|
6522
6602
|
return this.meta({ frLabels: byValue });
|
|
6523
6603
|
};
|
|
6604
|
+
proto.dynamicProps = function dynamicProps(spec) {
|
|
6605
|
+
if (!spec || typeof spec !== "object") {
|
|
6606
|
+
throw new Error(
|
|
6607
|
+
"`.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 }) })"
|
|
6608
|
+
);
|
|
6609
|
+
}
|
|
6610
|
+
return this.meta({ frDynamicProps: spec });
|
|
6611
|
+
};
|
|
6524
6612
|
proto.map = function map() {
|
|
6525
6613
|
throw new Error(
|
|
6526
6614
|
"`.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' })"
|
|
@@ -6741,10 +6829,36 @@ function unwrap(schema) {
|
|
|
6741
6829
|
}
|
|
6742
6830
|
return result;
|
|
6743
6831
|
}
|
|
6744
|
-
function
|
|
6745
|
-
|
|
6832
|
+
function isDynamicPropsSpec(value) {
|
|
6833
|
+
return !!value && typeof value === "object" && typeof value.execute === "function";
|
|
6834
|
+
}
|
|
6835
|
+
function hasFunction(value, depth = 0) {
|
|
6836
|
+
if (typeof value === "function") {
|
|
6837
|
+
return true;
|
|
6838
|
+
}
|
|
6839
|
+
if (!value || typeof value !== "object" || depth > MAX_UNWRAP_DEPTH) {
|
|
6840
|
+
return false;
|
|
6841
|
+
}
|
|
6842
|
+
return Object.values(value).some((inner) => hasFunction(inner, depth + 1));
|
|
6843
|
+
}
|
|
6844
|
+
function encodeMeta(meta, field, loaderId) {
|
|
6845
|
+
let source = meta;
|
|
6846
|
+
if (isDynamicPropsSpec(meta.frDynamicProps)) {
|
|
6847
|
+
if (!loaderId) {
|
|
6848
|
+
throw new Error(`Cannot encode "${field}": its \`.dynamicProps()\` has no loader method to publish.`);
|
|
6849
|
+
}
|
|
6850
|
+
source = { ...meta, frDynamicProps: { id: loaderId, dependsOn: meta.frDynamicProps.dependsOn ?? [] } };
|
|
6851
|
+
}
|
|
6852
|
+
if (hasFunction(source)) {
|
|
6853
|
+
throw new Error(`Cannot encode "${field}": its metadata holds a function, which has no wire form.`);
|
|
6854
|
+
}
|
|
6855
|
+
const encoded = toJsonValue2(source);
|
|
6746
6856
|
return Object.keys(encoded).length ? encoded : void 0;
|
|
6747
6857
|
}
|
|
6858
|
+
function isLoose(core) {
|
|
6859
|
+
const catchall = core?._zod?.def?.catchall;
|
|
6860
|
+
return catchall?._zod?.def?.type === "unknown";
|
|
6861
|
+
}
|
|
6748
6862
|
function encodeValues(core, type) {
|
|
6749
6863
|
if (type === "enum") {
|
|
6750
6864
|
const entries = core?._zod?.def?.entries ?? {};
|
|
@@ -6756,7 +6870,7 @@ function encodeValues(core, type) {
|
|
|
6756
6870
|
}
|
|
6757
6871
|
return void 0;
|
|
6758
6872
|
}
|
|
6759
|
-
function encodeField(name, schema, seen = /* @__PURE__ */ new Set()) {
|
|
6873
|
+
function encodeField(name, schema, seen = /* @__PURE__ */ new Set(), loaderId) {
|
|
6760
6874
|
if (seen.has(schema)) {
|
|
6761
6875
|
return { name, type: "unknown", unsupported: ["recursion"] };
|
|
6762
6876
|
}
|
|
@@ -6769,7 +6883,7 @@ function encodeField(name, schema, seen = /* @__PURE__ */ new Set()) {
|
|
|
6769
6883
|
const isUnion = !!ins.branches;
|
|
6770
6884
|
const format = isUnion ? void 0 : core?._zod?.def?.format;
|
|
6771
6885
|
const { checks, unsupported: checkIssues } = isUnion ? { checks: [], unsupported: [] } : encodeChecks(core);
|
|
6772
|
-
const meta = encodeMeta(ins.meta);
|
|
6886
|
+
const meta = encodeMeta(ins.meta, name, loaderId);
|
|
6773
6887
|
const message = isUnion ? void 0 : messageOf(core?._zod?.def ?? {});
|
|
6774
6888
|
const values = encodeValues(core, type);
|
|
6775
6889
|
const problems = [...unsupported, ...checkIssues];
|
|
@@ -6787,6 +6901,7 @@ function encodeField(name, schema, seen = /* @__PURE__ */ new Set()) {
|
|
|
6787
6901
|
...values?.length ? { values } : {},
|
|
6788
6902
|
...meta ? { meta } : {},
|
|
6789
6903
|
...message ? { message } : {},
|
|
6904
|
+
...type === "object" && isLoose(core) ? { loose: true } : {},
|
|
6790
6905
|
...type === "object" ? { properties: shapeEntries(core).map(([key, inner]) => encodeField(key, inner, seen)) } : {},
|
|
6791
6906
|
...type === "array" ? { element: encodeField("", core?._zod?.def?.element, seen) } : {},
|
|
6792
6907
|
...type === "record" ? { value: encodeField("", core?._zod?.def?.valueType, seen) } : {},
|
|
@@ -6796,14 +6911,14 @@ function encodeField(name, schema, seen = /* @__PURE__ */ new Set()) {
|
|
|
6796
6911
|
seen.delete(schema);
|
|
6797
6912
|
return encoded;
|
|
6798
6913
|
}
|
|
6799
|
-
function encodeParams(scheme) {
|
|
6914
|
+
function encodeParams(scheme, options = {}) {
|
|
6800
6915
|
const schema = scheme;
|
|
6801
6916
|
if (!schema?._zod) {
|
|
6802
6917
|
return null;
|
|
6803
6918
|
}
|
|
6804
6919
|
return {
|
|
6805
6920
|
v: SCHEMA_JSON_VERSION,
|
|
6806
|
-
fields: shapeEntries(schema).map(([name, field]) => encodeField(name, field))
|
|
6921
|
+
fields: shapeEntries(schema).map(([name, field]) => encodeField(name, field, /* @__PURE__ */ new Set(), options.loaderIdOf?.(name)))
|
|
6807
6922
|
};
|
|
6808
6923
|
}
|
|
6809
6924
|
|
|
@@ -7119,11 +7234,50 @@ var ActionMethod = class extends ExtensionMethod {
|
|
|
7119
7234
|
this.props = props;
|
|
7120
7235
|
this.params = MethodParams.of(props.params, { serviceId: extension.id, kind: "action", itemId: props.id, slot: "params" });
|
|
7121
7236
|
this.result = ResultSpec.from(props.result);
|
|
7122
|
-
this.
|
|
7123
|
-
|
|
7124
|
-
|
|
7125
|
-
|
|
7126
|
-
|
|
7237
|
+
this.dynamicParams = props.dynamicParams ? this.#checkDynamicParams(props.dynamicParams) : void 0;
|
|
7238
|
+
}
|
|
7239
|
+
/**
|
|
7240
|
+
* `dynamicParams` takes the same `{ dependsOn, execute }` as `.dynamicProps()`. The old
|
|
7241
|
+
* `{ criteria, resolve }` shape is refused by name, so a service written against it fails at load with the
|
|
7242
|
+
* fix rather than publishing a loader that never runs.
|
|
7243
|
+
*/
|
|
7244
|
+
#checkDynamicParams(def) {
|
|
7245
|
+
const source = { serviceId: this.extension.id, kind: "action", itemId: this.props.id, slot: "dynamicParams" };
|
|
7246
|
+
const fail3 = (message, received) => {
|
|
7247
|
+
throw new InvalidSchemaError(`[flow-extension:${this.extension.id}] action "${this.props.id}": ${message}`, { ...source, received });
|
|
7248
|
+
};
|
|
7249
|
+
const legacy = def;
|
|
7250
|
+
if (legacy.resolve !== void 0 || legacy.criteria !== void 0) {
|
|
7251
|
+
fail3(
|
|
7252
|
+
"`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() }) }",
|
|
7253
|
+
"criteria/resolve"
|
|
7254
|
+
);
|
|
7255
|
+
}
|
|
7256
|
+
if (typeof def.execute !== "function") {
|
|
7257
|
+
fail3("`dynamicParams` needs an `execute` function that returns the loaded params.", typeof def.execute);
|
|
7258
|
+
}
|
|
7259
|
+
if (def.dependsOn !== void 0 && (!Array.isArray(def.dependsOn) || def.dependsOn.some((item) => typeof item !== "string"))) {
|
|
7260
|
+
fail3("`dynamicParams.dependsOn` must be an array of param names.", def.dependsOn);
|
|
7261
|
+
}
|
|
7262
|
+
const declared = this.params.keys();
|
|
7263
|
+
for (const dependency of def.dependsOn ?? []) {
|
|
7264
|
+
if (!declared.includes(dependency)) {
|
|
7265
|
+
fail3(
|
|
7266
|
+
`\`dynamicParams\` depends on "${dependency}", which the action does not declare in \`params\`. Declared: ${declared.join(", ") || "none"}.`,
|
|
7267
|
+
dependency
|
|
7268
|
+
);
|
|
7269
|
+
}
|
|
7270
|
+
}
|
|
7271
|
+
return def;
|
|
7272
|
+
}
|
|
7273
|
+
/**
|
|
7274
|
+
* The top-level params declared with `.dynamicProps()`, and the def each one carries. Placement and shape
|
|
7275
|
+
* were checked when `params` was built (see ../params/schema/assert-supported-schema.ts).
|
|
7276
|
+
*/
|
|
7277
|
+
dynamicPropsFields() {
|
|
7278
|
+
return this.params.fields().flatMap(([name, schema]) => {
|
|
7279
|
+
const def = inspect(schema).meta.frDynamicProps;
|
|
7280
|
+
return def && !(typeof def.id === "string" && !("execute" in def)) ? [[name, def]] : [];
|
|
7127
7281
|
});
|
|
7128
7282
|
}
|
|
7129
7283
|
get id() {
|
|
@@ -7149,8 +7303,9 @@ var ActionMethod = class extends ExtensionMethod {
|
|
|
7149
7303
|
* Normalize, coerce and validate against the declared `params` — the same pipeline every other declared
|
|
7150
7304
|
* slot uses, so an author expresses optionality in the schema and nowhere else.
|
|
7151
7305
|
*
|
|
7152
|
-
* An action with `dynamicParams` carries the input's undeclared keys through, since its
|
|
7153
|
-
*
|
|
7306
|
+
* An action with `dynamicParams` carries the input's undeclared keys through, since its loaded top-level
|
|
7307
|
+
* fields are not in the static schema. A `.dynamicProps()` field needs nothing here: it is a loose object,
|
|
7308
|
+
* which keeps the loaded keys inside it.
|
|
7154
7309
|
*/
|
|
7155
7310
|
validate(methodData) {
|
|
7156
7311
|
return this.params.normalize(
|
|
@@ -7162,22 +7317,22 @@ var ActionMethod = class extends ExtensionMethod {
|
|
|
7162
7317
|
execute(params, ctx) {
|
|
7163
7318
|
return this.props.execute(ctx.bagWith({ params }));
|
|
7164
7319
|
}
|
|
7165
|
-
// Resolve the extra top-level param fields this action generates at runtime (see 03-parameters.md).
|
|
7166
|
-
resolveDynamicParams(bag) {
|
|
7167
|
-
return this.props.dynamicParams.resolve(bag);
|
|
7168
|
-
}
|
|
7169
7320
|
// ── output model ───────────────────────────────────────────────────────────
|
|
7170
7321
|
toModel() {
|
|
7171
7322
|
const [ownStart, ownEnd] = this.props.appearanceColors ?? [];
|
|
7172
7323
|
const [colorStart, colorEnd] = this.extension.appearanceColors;
|
|
7324
|
+
const args = toArgs(this.params);
|
|
7173
7325
|
const metaInfo = {
|
|
7174
|
-
args
|
|
7326
|
+
args,
|
|
7175
7327
|
...this.result.toMetaInfo(this.id, this.params)
|
|
7176
7328
|
};
|
|
7177
|
-
|
|
7329
|
+
for (const [name, def] of this.dynamicPropsFields()) {
|
|
7330
|
+
args[name] = { ...args[name], schemaLoader: dynamicPropsLoaderName(this.id, name), dependsOn: def.dependsOn ?? [] };
|
|
7331
|
+
}
|
|
7332
|
+
if (this.dynamicParams) {
|
|
7178
7333
|
metaInfo.dynamicParams = {
|
|
7179
7334
|
methodName: dynamicParamsLoaderName(this.id),
|
|
7180
|
-
dependsOn: this.
|
|
7335
|
+
dependsOn: this.dynamicParams.dependsOn ?? []
|
|
7181
7336
|
};
|
|
7182
7337
|
}
|
|
7183
7338
|
return {
|
|
@@ -7192,7 +7347,7 @@ var ActionMethod = class extends ExtensionMethod {
|
|
|
7192
7347
|
returnType: this.result.returnType,
|
|
7193
7348
|
queryParams: [],
|
|
7194
7349
|
bodyParams: toBodyParams(this.params),
|
|
7195
|
-
paramsSchema: encodeParams(this.params.scheme),
|
|
7350
|
+
paramsSchema: encodeParams(this.params.scheme, { loaderIdOf: (name) => dynamicPropsLoaderName(this.id, name) }),
|
|
7196
7351
|
metaInfo
|
|
7197
7352
|
};
|
|
7198
7353
|
}
|
|
@@ -7454,7 +7609,11 @@ var LoaderMethod = class extends ExtensionMethod {
|
|
|
7454
7609
|
validate(methodData) {
|
|
7455
7610
|
const input = this.input(methodData);
|
|
7456
7611
|
const payload = input.parseField("payload", LoaderPayloadSchema);
|
|
7457
|
-
return this.criteria.normalize(payload.criteria, input.invalidCriteria(), { carryUnknown:
|
|
7612
|
+
return this.criteria.normalize(payload.criteria, input.invalidCriteria(), { carryUnknown: this.carryUnknown });
|
|
7613
|
+
}
|
|
7614
|
+
// Whether the criteria's undeclared keys ride through to the handler.
|
|
7615
|
+
get carryUnknown() {
|
|
7616
|
+
return true;
|
|
7458
7617
|
}
|
|
7459
7618
|
// Internal (SYSTEM-like): no icon, no colours, no sample. Its params are left opaque in the model — it is
|
|
7460
7619
|
// invoked with `{ criteria }` at runtime, not through a rendered form.
|
|
@@ -7486,7 +7645,9 @@ var SampleResultLoaderMethod = class extends LoaderMethod {
|
|
|
7486
7645
|
get returnType() {
|
|
7487
7646
|
return "OBJECT";
|
|
7488
7647
|
}
|
|
7489
|
-
// The sample varies with ANY param of the owner, so all of them are its criteria.
|
|
7648
|
+
// The sample varies with ANY param of the owner, so all of them are its criteria. Undeclared keys ride
|
|
7649
|
+
// through too: the node's other params come along, and the owner's `result` fn may read fields its
|
|
7650
|
+
// `dynamicParams` loaded.
|
|
7490
7651
|
get criteria() {
|
|
7491
7652
|
return this.owner.params;
|
|
7492
7653
|
}
|
|
@@ -7494,31 +7655,101 @@ var SampleResultLoaderMethod = class extends LoaderMethod {
|
|
|
7494
7655
|
return this.owner.result.runLoader(ctx.bagWith({ params: criteria }));
|
|
7495
7656
|
}
|
|
7496
7657
|
};
|
|
7497
|
-
var
|
|
7498
|
-
|
|
7658
|
+
var isZod = (value) => !!value?._zod;
|
|
7659
|
+
var ParamsLoaderMethod = class extends LoaderMethod {
|
|
7660
|
+
constructor(extension, owner, def) {
|
|
7499
7661
|
super(extension, owner);
|
|
7500
7662
|
this.owner = owner;
|
|
7663
|
+
this.def = def;
|
|
7501
7664
|
}
|
|
7502
|
-
|
|
7503
|
-
return dynamicParamsLoaderName(this.owner.id);
|
|
7504
|
-
}
|
|
7665
|
+
#criteria;
|
|
7505
7666
|
get registerAs() {
|
|
7506
7667
|
return "PARAM_SCHEMA_DEFINITION";
|
|
7507
7668
|
}
|
|
7508
7669
|
get returnType() {
|
|
7509
|
-
return "
|
|
7670
|
+
return "OBJECT";
|
|
7510
7671
|
}
|
|
7672
|
+
get carryUnknown() {
|
|
7673
|
+
return false;
|
|
7674
|
+
}
|
|
7675
|
+
// Built unguarded: the picked fields were already checked on the owner, and a picked sibling may itself
|
|
7676
|
+
// carry `.dynamicProps()`, which the guard only allows in an action's own `params`.
|
|
7511
7677
|
get criteria() {
|
|
7512
|
-
|
|
7678
|
+
const dependsOn = this.def.dependsOn ?? [];
|
|
7679
|
+
this.#criteria ??= MethodParams.of(
|
|
7680
|
+
z2.object(Object.fromEntries(this.owner.params.fields().filter(([name]) => dependsOn.includes(name)))),
|
|
7681
|
+
{ serviceId: this.extension.id, kind: "loader criteria", itemId: this.name }
|
|
7682
|
+
);
|
|
7683
|
+
return this.#criteria;
|
|
7513
7684
|
}
|
|
7514
7685
|
async execute(criteria, ctx) {
|
|
7515
|
-
const
|
|
7516
|
-
|
|
7517
|
-
|
|
7518
|
-
|
|
7519
|
-
|
|
7520
|
-
|
|
7521
|
-
|
|
7686
|
+
const loaded = await this.def.execute(ctx.bagWith({ criteria }));
|
|
7687
|
+
const params = this.toParams(loaded);
|
|
7688
|
+
return { paramsSchema: encodeParams(params.scheme), params: toProperties(params) };
|
|
7689
|
+
}
|
|
7690
|
+
// A plain shape is wrapped in `z.object()`; anything else that is not a `z.object` is refused by the same
|
|
7691
|
+
// guards a declared params slot goes through.
|
|
7692
|
+
toParams(loaded) {
|
|
7693
|
+
const source = { serviceId: this.extension.id, kind: "action", itemId: this.owner.id, slot: this.slot };
|
|
7694
|
+
const schema = loaded && typeof loaded === "object" && !isZod(loaded) ? z2.object(loaded) : loaded;
|
|
7695
|
+
const returned = MethodParams.of(schema, source);
|
|
7696
|
+
const staticFields = this.staticFields;
|
|
7697
|
+
if (!staticFields.length) {
|
|
7698
|
+
return returned;
|
|
7699
|
+
}
|
|
7700
|
+
const staticNames = new Set(staticFields.map(([name]) => name));
|
|
7701
|
+
const repeated = returned.keys().filter((name) => staticNames.has(name));
|
|
7702
|
+
if (repeated.length) {
|
|
7703
|
+
throw new InvalidSchemaError(
|
|
7704
|
+
`[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.`,
|
|
7705
|
+
{ ...source, received: repeated }
|
|
7706
|
+
);
|
|
7707
|
+
}
|
|
7708
|
+
return MethodParams.of(z2.object(Object.fromEntries([...staticFields, ...returned.fields()])), source);
|
|
7709
|
+
}
|
|
7710
|
+
};
|
|
7711
|
+
var DynamicParamsLoaderMethod = class extends ParamsLoaderMethod {
|
|
7712
|
+
constructor(extension, owner) {
|
|
7713
|
+
super(extension, owner, owner.dynamicParams);
|
|
7714
|
+
}
|
|
7715
|
+
get name() {
|
|
7716
|
+
return dynamicParamsLoaderName(this.owner.id);
|
|
7717
|
+
}
|
|
7718
|
+
get slot() {
|
|
7719
|
+
return "dynamicParams.execute()";
|
|
7720
|
+
}
|
|
7721
|
+
get staticFields() {
|
|
7722
|
+
return [];
|
|
7723
|
+
}
|
|
7724
|
+
toParams(loaded) {
|
|
7725
|
+
const params = super.toParams(loaded);
|
|
7726
|
+
const declared = new Set(this.owner.params.keys());
|
|
7727
|
+
const shadowing = params.keys().filter((name) => declared.has(name));
|
|
7728
|
+
if (shadowing.length) {
|
|
7729
|
+
throw new InvalidSchemaError(
|
|
7730
|
+
`[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.`,
|
|
7731
|
+
{ serviceId: this.extension.id, kind: "action", itemId: this.owner.id, slot: this.slot, received: shadowing }
|
|
7732
|
+
);
|
|
7733
|
+
}
|
|
7734
|
+
return params;
|
|
7735
|
+
}
|
|
7736
|
+
};
|
|
7737
|
+
var DynamicPropsLoaderMethod = class extends ParamsLoaderMethod {
|
|
7738
|
+
constructor(extension, owner, field, def) {
|
|
7739
|
+
super(extension, owner, def);
|
|
7740
|
+
this.field = field;
|
|
7741
|
+
}
|
|
7742
|
+
get name() {
|
|
7743
|
+
return dynamicPropsLoaderName(this.owner.id, this.field);
|
|
7744
|
+
}
|
|
7745
|
+
get slot() {
|
|
7746
|
+
return `params.${this.field}.dynamicProps().execute()`;
|
|
7747
|
+
}
|
|
7748
|
+
get staticFields() {
|
|
7749
|
+
const schema = this.owner.params.fields().find(([name]) => name === this.field)?.[1];
|
|
7750
|
+
const ins = inspect(schema);
|
|
7751
|
+
const object = ins.resolvedType === "array" ? ins.core?._zod?.def?.element : schema;
|
|
7752
|
+
return shapeEntries(inspect(object).core);
|
|
7522
7753
|
}
|
|
7523
7754
|
};
|
|
7524
7755
|
|
|
@@ -8431,6 +8662,9 @@ var Extension = class {
|
|
|
8431
8662
|
if (action.hasDynamicParams()) {
|
|
8432
8663
|
this.#addMethod(new DynamicParamsLoaderMethod(this, action), "dynamic params loader");
|
|
8433
8664
|
}
|
|
8665
|
+
for (const [field, def] of action.dynamicPropsFields()) {
|
|
8666
|
+
this.#addMethod(new DynamicPropsLoaderMethod(this, action, field, def), "dynamic props loader");
|
|
8667
|
+
}
|
|
8434
8668
|
}
|
|
8435
8669
|
registerPollingTrigger(props) {
|
|
8436
8670
|
this.#claimId(props.id, "polling trigger");
|