@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.
Files changed (70) hide show
  1. package/README.md +8 -8
  2. package/ai-docs/instructions/service-code-format/01-service-structure.md +3 -2
  3. package/ai-docs/instructions/service-code-format/02-zod-types.md +8 -0
  4. package/ai-docs/instructions/service-code-format/03-parameters.md +181 -10
  5. package/ai-docs/instructions/service-code-format/04-http-requests.md +2 -2
  6. package/ai-docs/instructions/service-code-format/05-dictionaries.md +14 -0
  7. package/ai-docs/instructions/service-code-format/07-actions.md +5 -4
  8. package/ai-docs/instructions/service-code-format/11-output-model.md +42 -6
  9. package/ai-docs/instructions/service-code-format/12-service-readme.md +1 -1
  10. package/ai-docs/instructions/service-code-format/13-runtime-contracts.md +4 -1
  11. package/ai-docs/instructions/service-code-format/15-unit-tests.md +2 -1
  12. package/ai-docs/instructions/service-code-format/16-gotchas.md +39 -1
  13. package/ai-docs/instructions/service-code-format/README.md +1 -1
  14. package/ai-docs/providers/claude/agents/flowrunner-service-test-engineer.md +1 -1
  15. package/dist/cli.js +276 -42
  16. package/dist/cli.js.map +3 -3
  17. package/dist/index.js +275 -41
  18. package/dist/index.js.map +3 -3
  19. package/dist/types/flow-extension-runner/src/v2/actions/action-method.d.ts +13 -9
  20. package/dist/types/flow-extension-runner/src/v2/loaders/loader-method.d.ts +52 -7
  21. package/dist/types/flow-extension-runner/src/v2/loaders/loader-owner.d.ts +4 -6
  22. package/dist/types/flow-extension-runner/src/v2/model/model-types.d.ts +2 -0
  23. package/dist/types/flow-extension-runner/src/v2/params/index.d.ts +2 -2
  24. package/dist/types/flow-extension-runner/src/v2/params/json/encode.d.ts +10 -2
  25. package/dist/types/flow-extension-runner/src/v2/params/json/types.d.ts +1 -0
  26. package/dist/types/flow-extension-runner/src/v2/params/zod.d.ts +29 -0
  27. package/dist/types/flow-extension-runner/src/v2/types.d.ts +20 -8
  28. package/dist/types/shared/src/constants/activity-log.d.ts +1496 -0
  29. package/dist/types/shared/src/constants/docs.d.ts +2 -0
  30. package/dist/types/shared/src/constants/notification-types.d.ts +9 -3
  31. package/dist/types/shared/src/scheme/activity-log-base.d.ts +35 -0
  32. package/dist/types/shared/src/scheme/data-types/java.dto.d.ts +2 -3
  33. package/dist/types/shared/src/scheme/flowrunner/custom-elements.d.ts +20 -0
  34. package/dist/types/shared/src/scheme/flowrunner/java.dto.d.ts +1 -0
  35. package/dist/types/shared/src/scheme/shared-extensions/base.d.ts +5 -0
  36. package/dist/types/shared/src/scheme/shared-extensions/custom-extensions.d.ts +147 -0
  37. package/dist/types/shared/src/scheme/shared-extensions/extension.d.ts +20 -0
  38. package/dist/types/shared/src/scheme/shared-extensions/methods.d.ts +33 -1
  39. package/dist/types/shared/src/scheme/shared-extensions/params-schema.d.ts +1 -0
  40. package/dist/types/shared/src/scheme/shared-extensions/resolve.d.ts +15 -0
  41. package/dist/types/shared/src/scheme/shared-extensions/search.d.ts +10 -0
  42. package/package.json +1 -1
  43. package/runtime/index.js +275 -41
  44. package/runtime/index.js.map +3 -3
  45. package/runtime/types/flow-extension-runner/src/v2/actions/action-method.d.ts +13 -9
  46. package/runtime/types/flow-extension-runner/src/v2/loaders/loader-method.d.ts +52 -7
  47. package/runtime/types/flow-extension-runner/src/v2/loaders/loader-owner.d.ts +4 -6
  48. package/runtime/types/flow-extension-runner/src/v2/model/model-types.d.ts +2 -0
  49. package/runtime/types/flow-extension-runner/src/v2/params/index.d.ts +2 -2
  50. package/runtime/types/flow-extension-runner/src/v2/params/json/encode.d.ts +10 -2
  51. package/runtime/types/flow-extension-runner/src/v2/params/json/types.d.ts +1 -0
  52. package/runtime/types/flow-extension-runner/src/v2/params/zod.d.ts +29 -0
  53. package/runtime/types/flow-extension-runner/src/v2/types.d.ts +20 -8
  54. package/runtime/types/shared/src/constants/activity-log.d.ts +1496 -0
  55. package/runtime/types/shared/src/constants/docs.d.ts +2 -0
  56. package/runtime/types/shared/src/constants/notification-types.d.ts +9 -3
  57. package/runtime/types/shared/src/scheme/activity-log-base.d.ts +35 -0
  58. package/runtime/types/shared/src/scheme/data-types/java.dto.d.ts +2 -3
  59. package/runtime/types/shared/src/scheme/flowrunner/custom-elements.d.ts +20 -0
  60. package/runtime/types/shared/src/scheme/flowrunner/java.dto.d.ts +1 -0
  61. package/runtime/types/shared/src/scheme/shared-extensions/base.d.ts +5 -0
  62. package/runtime/types/shared/src/scheme/shared-extensions/custom-extensions.d.ts +147 -0
  63. package/runtime/types/shared/src/scheme/shared-extensions/extension.d.ts +20 -0
  64. package/runtime/types/shared/src/scheme/shared-extensions/methods.d.ts +33 -1
  65. package/runtime/types/shared/src/scheme/shared-extensions/params-schema.d.ts +1 -0
  66. package/runtime/types/shared/src/scheme/shared-extensions/resolve.d.ts +15 -0
  67. package/runtime/types/shared/src/scheme/shared-extensions/search.d.ts +10 -0
  68. package/templates/demo-todo-list/files/src/index.js +6 -6
  69. package/templates/qa-test/files/README.md +23 -8
  70. package/templates/qa-test/files/src/index.js +368 -37
package/dist/index.js CHANGED
@@ -4875,6 +4875,7 @@ var InvalidDictionaryOutputScheme = class extends FlowExtensionError {
4875
4875
  // ../../flow-extension-runner/src/v2/loaders/loader-owner.ts
4876
4876
  var sampleResultLoaderName = (ownerId) => `${ownerId}_SampleResultLoader`;
4877
4877
  var dynamicParamsLoaderName = (ownerId) => `${ownerId}_DynamicParams`;
4878
+ var dynamicPropsLoaderName = (ownerId, field) => `${ownerId}_${field}_DynamicProps`;
4878
4879
 
4879
4880
  // ../../flow-extension-runner/src/v2/params/schema/assert-object-schema.ts
4880
4881
  var WRAPPERS = /* @__PURE__ */ new Set(["optional", "nullable", "nullish", "default", "prefault"]);
@@ -4918,8 +4919,9 @@ function assertObjectSchema(scheme, source) {
4918
4919
  const isReturn = slot.endsWith("()");
4919
4920
  const subject = source.itemId ? `${kind} "${source.itemId}": ` : "";
4920
4921
  const received = describe(scheme);
4922
+ const expected = slot.endsWith(".execute()") ? "a z.object({ \u2026 }) or a shape of zod fields" : "a z.object({ \u2026 })";
4921
4923
  throw new InvalidSchemaError(
4922
- `[flow-extension:${source.serviceId}] ${subject}\`${slot}\` ${isReturn ? "must return" : "must be"} a z.object({ \u2026 }) \u2014 received ${received}${hint(scheme, slot, isReturn)}`,
4924
+ `[flow-extension:${source.serviceId}] ${subject}\`${slot}\` ${isReturn ? "must return" : "must be"} ${expected} \u2014 received ${received}${hint(scheme, slot, isReturn)}`,
4923
4925
  { serviceId: source.serviceId, kind, itemId: source.itemId, slot, received }
4924
4926
  );
4925
4927
  }
@@ -5142,12 +5144,85 @@ function refuseType(source, path19, type) {
5142
5144
  type ?? "unknown"
5143
5145
  );
5144
5146
  }
5145
- function assertField(schema, source, path19, seen) {
5147
+ 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.";
5148
+ function isLooseObject(schema) {
5149
+ if (!schema) {
5150
+ return false;
5151
+ }
5152
+ const ins = inspect(schema);
5153
+ const catchall = ins.core?._zod?.def?.catchall;
5154
+ return ins.resolvedType === "object" && catchall?._zod?.def?.type === "unknown";
5155
+ }
5156
+ function isDynamicPropsSlot(source, topLevel) {
5157
+ return topLevel && source.kind === "action" && source.slot === "params";
5158
+ }
5159
+ function assertDynamicProps(schema, name, siblings, source, path19) {
5160
+ const ins = inspect(schema);
5161
+ const spec = ins.meta.frDynamicProps;
5162
+ if (!spec) {
5163
+ return;
5164
+ }
5165
+ if (typeof spec.id === "string" && !("execute" in spec)) {
5166
+ return;
5167
+ }
5168
+ if (typeof spec.execute !== "function") {
5169
+ refuse(
5170
+ `${subjectOf(source, path19)}: \`.dynamicProps()\` needs an \`execute\` function that returns the loaded fields.`,
5171
+ source,
5172
+ path19,
5173
+ typeof spec.execute
5174
+ );
5175
+ }
5176
+ if (spec.dependsOn !== void 0 && (!Array.isArray(spec.dependsOn) || spec.dependsOn.some((item) => typeof item !== "string"))) {
5177
+ refuse(
5178
+ `${subjectOf(source, path19)}: \`.dynamicProps()\` \`dependsOn\` must be an array of param names.`,
5179
+ source,
5180
+ path19,
5181
+ "dependsOn"
5182
+ );
5183
+ }
5184
+ for (const dependency of spec.dependsOn ?? []) {
5185
+ if (dependency === name || !siblings.includes(dependency)) {
5186
+ refuse(
5187
+ `${subjectOf(source, path19)}: \`.dynamicProps()\` depends on "${dependency}", which is not another param of this action. Name its sibling params: ${siblings.filter((sibling) => sibling !== name).join(", ") || "none"}.`,
5188
+ source,
5189
+ path19,
5190
+ dependency
5191
+ );
5192
+ }
5193
+ }
5194
+ if (ins.meta.frDictionary) {
5195
+ refuse(
5196
+ `${subjectOf(source, path19)} 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.`,
5197
+ source,
5198
+ path19,
5199
+ "dictionary"
5200
+ );
5201
+ }
5202
+ const element = ins.resolvedType === "array" ? ins.core?._zod?.def?.element : void 0;
5203
+ if (!isLooseObject(schema) && !isLooseObject(element)) {
5204
+ refuse(
5205
+ `${subjectOf(source, path19)}: \`.dynamicProps()\` needs a loose object \u2014 the loaded fields are not declared, so a plain \`z.object()\` would strip them. ${DYNAMIC_PROPS_FIX}`,
5206
+ source,
5207
+ path19,
5208
+ ins.resolvedType ?? "unknown"
5209
+ );
5210
+ }
5211
+ }
5212
+ function assertField(schema, source, path19, seen, topLevel = false) {
5146
5213
  if (!schema || seen.has(schema)) {
5147
5214
  return;
5148
5215
  }
5149
5216
  seen.add(schema);
5150
5217
  const ins = inspect(schema);
5218
+ if (ins.meta.frDynamicProps && !isDynamicPropsSlot(source, topLevel)) {
5219
+ refuse(
5220
+ `${subjectOf(source, path19)} 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.`,
5221
+ source,
5222
+ path19,
5223
+ "dynamicProps"
5224
+ );
5225
+ }
5151
5226
  if (ins.resolvedType === "catch") {
5152
5227
  refuseCatch(source, path19);
5153
5228
  }
@@ -5176,8 +5251,13 @@ function assertSupportedSchema(scheme, source) {
5176
5251
  }
5177
5252
  const slot = source.slot ?? "schema";
5178
5253
  const seen = /* @__PURE__ */ new Set();
5179
- for (const [name, field] of shapeEntries(scheme)) {
5180
- assertField(field, source, `${slot}.${name}`, seen);
5254
+ const fields = shapeEntries(scheme);
5255
+ const names = fields.map(([name]) => name);
5256
+ for (const [name, field] of fields) {
5257
+ assertField(field, source, `${slot}.${name}`, seen, true);
5258
+ if (isDynamicPropsSlot(source, true)) {
5259
+ assertDynamicProps(field, name, names, source, `${slot}.${name}`);
5260
+ }
5181
5261
  }
5182
5262
  }
5183
5263
 
@@ -5999,6 +6079,14 @@ function extendPrototype() {
5999
6079
  proto.labels = function labels(byValue) {
6000
6080
  return this.meta({ frLabels: byValue });
6001
6081
  };
6082
+ proto.dynamicProps = function dynamicProps(spec) {
6083
+ if (!spec || typeof spec !== "object") {
6084
+ throw new Error(
6085
+ "`.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 }) })"
6086
+ );
6087
+ }
6088
+ return this.meta({ frDynamicProps: spec });
6089
+ };
6002
6090
  proto.map = function map() {
6003
6091
  throw new Error(
6004
6092
  "`.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' })"
@@ -6219,10 +6307,36 @@ function unwrap(schema) {
6219
6307
  }
6220
6308
  return result;
6221
6309
  }
6222
- function encodeMeta(meta) {
6223
- const encoded = toJsonValue2(meta);
6310
+ function isDynamicPropsSpec(value) {
6311
+ return !!value && typeof value === "object" && typeof value.execute === "function";
6312
+ }
6313
+ function hasFunction(value, depth = 0) {
6314
+ if (typeof value === "function") {
6315
+ return true;
6316
+ }
6317
+ if (!value || typeof value !== "object" || depth > MAX_UNWRAP_DEPTH) {
6318
+ return false;
6319
+ }
6320
+ return Object.values(value).some((inner) => hasFunction(inner, depth + 1));
6321
+ }
6322
+ function encodeMeta(meta, field, loaderId) {
6323
+ let source = meta;
6324
+ if (isDynamicPropsSpec(meta.frDynamicProps)) {
6325
+ if (!loaderId) {
6326
+ throw new Error(`Cannot encode "${field}": its \`.dynamicProps()\` has no loader method to publish.`);
6327
+ }
6328
+ source = { ...meta, frDynamicProps: { id: loaderId, dependsOn: meta.frDynamicProps.dependsOn ?? [] } };
6329
+ }
6330
+ if (hasFunction(source)) {
6331
+ throw new Error(`Cannot encode "${field}": its metadata holds a function, which has no wire form.`);
6332
+ }
6333
+ const encoded = toJsonValue2(source);
6224
6334
  return Object.keys(encoded).length ? encoded : void 0;
6225
6335
  }
6336
+ function isLoose(core) {
6337
+ const catchall = core?._zod?.def?.catchall;
6338
+ return catchall?._zod?.def?.type === "unknown";
6339
+ }
6226
6340
  function encodeValues(core, type) {
6227
6341
  if (type === "enum") {
6228
6342
  const entries = core?._zod?.def?.entries ?? {};
@@ -6234,7 +6348,7 @@ function encodeValues(core, type) {
6234
6348
  }
6235
6349
  return void 0;
6236
6350
  }
6237
- function encodeField(name, schema, seen = /* @__PURE__ */ new Set()) {
6351
+ function encodeField(name, schema, seen = /* @__PURE__ */ new Set(), loaderId) {
6238
6352
  if (seen.has(schema)) {
6239
6353
  return { name, type: "unknown", unsupported: ["recursion"] };
6240
6354
  }
@@ -6247,7 +6361,7 @@ function encodeField(name, schema, seen = /* @__PURE__ */ new Set()) {
6247
6361
  const isUnion = !!ins.branches;
6248
6362
  const format = isUnion ? void 0 : core?._zod?.def?.format;
6249
6363
  const { checks, unsupported: checkIssues } = isUnion ? { checks: [], unsupported: [] } : encodeChecks(core);
6250
- const meta = encodeMeta(ins.meta);
6364
+ const meta = encodeMeta(ins.meta, name, loaderId);
6251
6365
  const message = isUnion ? void 0 : messageOf(core?._zod?.def ?? {});
6252
6366
  const values = encodeValues(core, type);
6253
6367
  const problems = [...unsupported, ...checkIssues];
@@ -6265,6 +6379,7 @@ function encodeField(name, schema, seen = /* @__PURE__ */ new Set()) {
6265
6379
  ...values?.length ? { values } : {},
6266
6380
  ...meta ? { meta } : {},
6267
6381
  ...message ? { message } : {},
6382
+ ...type === "object" && isLoose(core) ? { loose: true } : {},
6268
6383
  ...type === "object" ? { properties: shapeEntries(core).map(([key, inner]) => encodeField(key, inner, seen)) } : {},
6269
6384
  ...type === "array" ? { element: encodeField("", core?._zod?.def?.element, seen) } : {},
6270
6385
  ...type === "record" ? { value: encodeField("", core?._zod?.def?.valueType, seen) } : {},
@@ -6274,14 +6389,14 @@ function encodeField(name, schema, seen = /* @__PURE__ */ new Set()) {
6274
6389
  seen.delete(schema);
6275
6390
  return encoded;
6276
6391
  }
6277
- function encodeParams(scheme) {
6392
+ function encodeParams(scheme, options = {}) {
6278
6393
  const schema = scheme;
6279
6394
  if (!schema?._zod) {
6280
6395
  return null;
6281
6396
  }
6282
6397
  return {
6283
6398
  v: SCHEMA_JSON_VERSION,
6284
- fields: shapeEntries(schema).map(([name, field]) => encodeField(name, field))
6399
+ fields: shapeEntries(schema).map(([name, field]) => encodeField(name, field, /* @__PURE__ */ new Set(), options.loaderIdOf?.(name)))
6285
6400
  };
6286
6401
  }
6287
6402
 
@@ -6597,11 +6712,50 @@ var ActionMethod = class extends ExtensionMethod {
6597
6712
  this.props = props;
6598
6713
  this.params = MethodParams.of(props.params, { serviceId: extension.id, kind: "action", itemId: props.id, slot: "params" });
6599
6714
  this.result = ResultSpec.from(props.result);
6600
- this.dynamicParamsCriteria = MethodParams.of(props.dynamicParams?.criteria, {
6601
- serviceId: extension.id,
6602
- kind: "action",
6603
- itemId: props.id,
6604
- slot: "dynamicParams.criteria"
6715
+ this.dynamicParams = props.dynamicParams ? this.#checkDynamicParams(props.dynamicParams) : void 0;
6716
+ }
6717
+ /**
6718
+ * `dynamicParams` takes the same `{ dependsOn, execute }` as `.dynamicProps()`. The old
6719
+ * `{ criteria, resolve }` shape is refused by name, so a service written against it fails at load with the
6720
+ * fix rather than publishing a loader that never runs.
6721
+ */
6722
+ #checkDynamicParams(def) {
6723
+ const source = { serviceId: this.extension.id, kind: "action", itemId: this.props.id, slot: "dynamicParams" };
6724
+ const fail2 = (message, received) => {
6725
+ throw new InvalidSchemaError(`[flow-extension:${this.extension.id}] action "${this.props.id}": ${message}`, { ...source, received });
6726
+ };
6727
+ const legacy = def;
6728
+ if (legacy.resolve !== void 0 || legacy.criteria !== void 0) {
6729
+ fail2(
6730
+ "`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() }) }",
6731
+ "criteria/resolve"
6732
+ );
6733
+ }
6734
+ if (typeof def.execute !== "function") {
6735
+ fail2("`dynamicParams` needs an `execute` function that returns the loaded params.", typeof def.execute);
6736
+ }
6737
+ if (def.dependsOn !== void 0 && (!Array.isArray(def.dependsOn) || def.dependsOn.some((item) => typeof item !== "string"))) {
6738
+ fail2("`dynamicParams.dependsOn` must be an array of param names.", def.dependsOn);
6739
+ }
6740
+ const declared = this.params.keys();
6741
+ for (const dependency of def.dependsOn ?? []) {
6742
+ if (!declared.includes(dependency)) {
6743
+ fail2(
6744
+ `\`dynamicParams\` depends on "${dependency}", which the action does not declare in \`params\`. Declared: ${declared.join(", ") || "none"}.`,
6745
+ dependency
6746
+ );
6747
+ }
6748
+ }
6749
+ return def;
6750
+ }
6751
+ /**
6752
+ * The top-level params declared with `.dynamicProps()`, and the def each one carries. Placement and shape
6753
+ * were checked when `params` was built (see ../params/schema/assert-supported-schema.ts).
6754
+ */
6755
+ dynamicPropsFields() {
6756
+ return this.params.fields().flatMap(([name, schema]) => {
6757
+ const def = inspect(schema).meta.frDynamicProps;
6758
+ return def && !(typeof def.id === "string" && !("execute" in def)) ? [[name, def]] : [];
6605
6759
  });
6606
6760
  }
6607
6761
  get id() {
@@ -6627,8 +6781,9 @@ var ActionMethod = class extends ExtensionMethod {
6627
6781
  * Normalize, coerce and validate against the declared `params` — the same pipeline every other declared
6628
6782
  * slot uses, so an author expresses optionality in the schema and nowhere else.
6629
6783
  *
6630
- * An action with `dynamicParams` carries the input's undeclared keys through, since its runtime-generated
6631
- * top-level fields are not in the static schema.
6784
+ * An action with `dynamicParams` carries the input's undeclared keys through, since its loaded top-level
6785
+ * fields are not in the static schema. A `.dynamicProps()` field needs nothing here: it is a loose object,
6786
+ * which keeps the loaded keys inside it.
6632
6787
  */
6633
6788
  validate(methodData) {
6634
6789
  return this.params.normalize(
@@ -6640,22 +6795,22 @@ var ActionMethod = class extends ExtensionMethod {
6640
6795
  execute(params, ctx) {
6641
6796
  return this.props.execute(ctx.bagWith({ params }));
6642
6797
  }
6643
- // Resolve the extra top-level param fields this action generates at runtime (see 03-parameters.md).
6644
- resolveDynamicParams(bag) {
6645
- return this.props.dynamicParams.resolve(bag);
6646
- }
6647
6798
  // ── output model ───────────────────────────────────────────────────────────
6648
6799
  toModel() {
6649
6800
  const [ownStart, ownEnd] = this.props.appearanceColors ?? [];
6650
6801
  const [colorStart, colorEnd] = this.extension.appearanceColors;
6802
+ const args = toArgs(this.params);
6651
6803
  const metaInfo = {
6652
- args: toArgs(this.params),
6804
+ args,
6653
6805
  ...this.result.toMetaInfo(this.id, this.params)
6654
6806
  };
6655
- if (this.hasDynamicParams()) {
6807
+ for (const [name, def] of this.dynamicPropsFields()) {
6808
+ args[name] = { ...args[name], schemaLoader: dynamicPropsLoaderName(this.id, name), dependsOn: def.dependsOn ?? [] };
6809
+ }
6810
+ if (this.dynamicParams) {
6656
6811
  metaInfo.dynamicParams = {
6657
6812
  methodName: dynamicParamsLoaderName(this.id),
6658
- dependsOn: this.dynamicParamsCriteria.keys()
6813
+ dependsOn: this.dynamicParams.dependsOn ?? []
6659
6814
  };
6660
6815
  }
6661
6816
  return {
@@ -6670,7 +6825,7 @@ var ActionMethod = class extends ExtensionMethod {
6670
6825
  returnType: this.result.returnType,
6671
6826
  queryParams: [],
6672
6827
  bodyParams: toBodyParams(this.params),
6673
- paramsSchema: encodeParams(this.params.scheme),
6828
+ paramsSchema: encodeParams(this.params.scheme, { loaderIdOf: (name) => dynamicPropsLoaderName(this.id, name) }),
6674
6829
  metaInfo
6675
6830
  };
6676
6831
  }
@@ -6932,7 +7087,11 @@ var LoaderMethod = class extends ExtensionMethod {
6932
7087
  validate(methodData) {
6933
7088
  const input = this.input(methodData);
6934
7089
  const payload = input.parseField("payload", LoaderPayloadSchema);
6935
- return this.criteria.normalize(payload.criteria, input.invalidCriteria(), { carryUnknown: true });
7090
+ return this.criteria.normalize(payload.criteria, input.invalidCriteria(), { carryUnknown: this.carryUnknown });
7091
+ }
7092
+ // Whether the criteria's undeclared keys ride through to the handler.
7093
+ get carryUnknown() {
7094
+ return true;
6936
7095
  }
6937
7096
  // Internal (SYSTEM-like): no icon, no colours, no sample. Its params are left opaque in the model — it is
6938
7097
  // invoked with `{ criteria }` at runtime, not through a rendered form.
@@ -6964,7 +7123,9 @@ var SampleResultLoaderMethod = class extends LoaderMethod {
6964
7123
  get returnType() {
6965
7124
  return "OBJECT";
6966
7125
  }
6967
- // The sample varies with ANY param of the owner, so all of them are its criteria.
7126
+ // The sample varies with ANY param of the owner, so all of them are its criteria. Undeclared keys ride
7127
+ // through too: the node's other params come along, and the owner's `result` fn may read fields its
7128
+ // `dynamicParams` loaded.
6968
7129
  get criteria() {
6969
7130
  return this.owner.params;
6970
7131
  }
@@ -6972,31 +7133,101 @@ var SampleResultLoaderMethod = class extends LoaderMethod {
6972
7133
  return this.owner.result.runLoader(ctx.bagWith({ params: criteria }));
6973
7134
  }
6974
7135
  };
6975
- var DynamicParamsLoaderMethod = class extends LoaderMethod {
6976
- constructor(extension, owner) {
7136
+ var isZod = (value) => !!value?._zod;
7137
+ var ParamsLoaderMethod = class extends LoaderMethod {
7138
+ constructor(extension, owner, def) {
6977
7139
  super(extension, owner);
6978
7140
  this.owner = owner;
7141
+ this.def = def;
6979
7142
  }
6980
- get name() {
6981
- return dynamicParamsLoaderName(this.owner.id);
6982
- }
7143
+ #criteria;
6983
7144
  get registerAs() {
6984
7145
  return "PARAM_SCHEMA_DEFINITION";
6985
7146
  }
6986
7147
  get returnType() {
6987
- return "LIST";
7148
+ return "OBJECT";
6988
7149
  }
7150
+ get carryUnknown() {
7151
+ return false;
7152
+ }
7153
+ // Built unguarded: the picked fields were already checked on the owner, and a picked sibling may itself
7154
+ // carry `.dynamicProps()`, which the guard only allows in an action's own `params`.
6989
7155
  get criteria() {
6990
- return this.owner.dynamicParamsCriteria;
7156
+ const dependsOn = this.def.dependsOn ?? [];
7157
+ this.#criteria ??= MethodParams.of(
7158
+ z.object(Object.fromEntries(this.owner.params.fields().filter(([name]) => dependsOn.includes(name)))),
7159
+ { serviceId: this.extension.id, kind: "loader criteria", itemId: this.name }
7160
+ );
7161
+ return this.#criteria;
6991
7162
  }
6992
7163
  async execute(criteria, ctx) {
6993
- const schema = await this.owner.resolveDynamicParams(ctx.bagWith({ criteria }));
6994
- return toBodyParams(MethodParams.of(schema, {
6995
- serviceId: this.extension.id,
6996
- kind: "action",
6997
- itemId: this.owner.id,
6998
- slot: "dynamicParams.resolve()"
6999
- }));
7164
+ const loaded = await this.def.execute(ctx.bagWith({ criteria }));
7165
+ const params = this.toParams(loaded);
7166
+ return { paramsSchema: encodeParams(params.scheme), params: toProperties(params) };
7167
+ }
7168
+ // A plain shape is wrapped in `z.object()`; anything else that is not a `z.object` is refused by the same
7169
+ // guards a declared params slot goes through.
7170
+ toParams(loaded) {
7171
+ const source = { serviceId: this.extension.id, kind: "action", itemId: this.owner.id, slot: this.slot };
7172
+ const schema = loaded && typeof loaded === "object" && !isZod(loaded) ? z.object(loaded) : loaded;
7173
+ const returned = MethodParams.of(schema, source);
7174
+ const staticFields = this.staticFields;
7175
+ if (!staticFields.length) {
7176
+ return returned;
7177
+ }
7178
+ const staticNames = new Set(staticFields.map(([name]) => name));
7179
+ const repeated = returned.keys().filter((name) => staticNames.has(name));
7180
+ if (repeated.length) {
7181
+ throw new InvalidSchemaError(
7182
+ `[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.`,
7183
+ { ...source, received: repeated }
7184
+ );
7185
+ }
7186
+ return MethodParams.of(z.object(Object.fromEntries([...staticFields, ...returned.fields()])), source);
7187
+ }
7188
+ };
7189
+ var DynamicParamsLoaderMethod = class extends ParamsLoaderMethod {
7190
+ constructor(extension, owner) {
7191
+ super(extension, owner, owner.dynamicParams);
7192
+ }
7193
+ get name() {
7194
+ return dynamicParamsLoaderName(this.owner.id);
7195
+ }
7196
+ get slot() {
7197
+ return "dynamicParams.execute()";
7198
+ }
7199
+ get staticFields() {
7200
+ return [];
7201
+ }
7202
+ toParams(loaded) {
7203
+ const params = super.toParams(loaded);
7204
+ const declared = new Set(this.owner.params.keys());
7205
+ const shadowing = params.keys().filter((name) => declared.has(name));
7206
+ if (shadowing.length) {
7207
+ throw new InvalidSchemaError(
7208
+ `[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.`,
7209
+ { serviceId: this.extension.id, kind: "action", itemId: this.owner.id, slot: this.slot, received: shadowing }
7210
+ );
7211
+ }
7212
+ return params;
7213
+ }
7214
+ };
7215
+ var DynamicPropsLoaderMethod = class extends ParamsLoaderMethod {
7216
+ constructor(extension, owner, field, def) {
7217
+ super(extension, owner, def);
7218
+ this.field = field;
7219
+ }
7220
+ get name() {
7221
+ return dynamicPropsLoaderName(this.owner.id, this.field);
7222
+ }
7223
+ get slot() {
7224
+ return `params.${this.field}.dynamicProps().execute()`;
7225
+ }
7226
+ get staticFields() {
7227
+ const schema = this.owner.params.fields().find(([name]) => name === this.field)?.[1];
7228
+ const ins = inspect(schema);
7229
+ const object = ins.resolvedType === "array" ? ins.core?._zod?.def?.element : schema;
7230
+ return shapeEntries(inspect(object).core);
7000
7231
  }
7001
7232
  };
7002
7233
 
@@ -7909,6 +8140,9 @@ var Extension = class {
7909
8140
  if (action.hasDynamicParams()) {
7910
8141
  this.#addMethod(new DynamicParamsLoaderMethod(this, action), "dynamic params loader");
7911
8142
  }
8143
+ for (const [field, def] of action.dynamicPropsFields()) {
8144
+ this.#addMethod(new DynamicPropsLoaderMethod(this, action, field, def), "dynamic props loader");
8145
+ }
7912
8146
  }
7913
8147
  registerPollingTrigger(props) {
7914
8148
  this.#claimId(props.id, "polling trigger");