@flowrunner/cli 0.1.8 → 0.1.9-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +8 -8
  2. package/ai-docs/instructions/service-code-format/01-service-structure.md +4 -3
  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 +166 -10
  5. package/ai-docs/instructions/service-code-format/04-http-requests.md +19 -15
  6. package/ai-docs/instructions/service-code-format/05-dictionaries.md +14 -0
  7. package/ai-docs/instructions/service-code-format/06-oauth2.md +1 -5
  8. package/ai-docs/instructions/service-code-format/07-actions.md +18 -13
  9. package/ai-docs/instructions/service-code-format/11-output-model.md +42 -6
  10. package/ai-docs/instructions/service-code-format/12-service-readme.md +1 -1
  11. package/ai-docs/instructions/service-code-format/14-reference-service.md +5 -4
  12. package/ai-docs/instructions/service-code-format/15-unit-tests.md +2 -1
  13. package/ai-docs/instructions/service-code-format/16-gotchas.md +31 -1
  14. package/ai-docs/instructions/service-code-format/17-client-certificates.md +5 -3
  15. package/ai-docs/instructions/service-code-format/README.md +1 -1
  16. package/ai-docs/providers/claude/agents/flowrunner-service-test-engineer.md +1 -1
  17. package/dist/cli.js +285 -42
  18. package/dist/cli.js.map +3 -3
  19. package/dist/index.js +284 -41
  20. package/dist/index.js.map +3 -3
  21. package/dist/types/flow-extension-runner/src/v2/actions/action-method.d.ts +13 -9
  22. package/dist/types/flow-extension-runner/src/v2/loaders/loader-method.d.ts +52 -7
  23. package/dist/types/flow-extension-runner/src/v2/loaders/loader-owner.d.ts +4 -6
  24. package/dist/types/flow-extension-runner/src/v2/model/model-types.d.ts +2 -0
  25. package/dist/types/flow-extension-runner/src/v2/params/index.d.ts +2 -2
  26. package/dist/types/flow-extension-runner/src/v2/params/json/encode.d.ts +10 -2
  27. package/dist/types/flow-extension-runner/src/v2/params/json/types.d.ts +1 -0
  28. package/dist/types/flow-extension-runner/src/v2/params/zod.d.ts +29 -0
  29. package/dist/types/flow-extension-runner/src/v2/types.d.ts +21 -9
  30. package/dist/types/shared/src/constants/activity-log.d.ts +1496 -0
  31. package/dist/types/shared/src/constants/docs.d.ts +2 -0
  32. package/dist/types/shared/src/constants/notification-types.d.ts +11 -5
  33. package/dist/types/shared/src/scheme/activity-log-base.d.ts +35 -0
  34. package/dist/types/shared/src/scheme/data-types/java.dto.d.ts +2 -3
  35. package/dist/types/shared/src/scheme/flowrunner/custom-elements.d.ts +20 -0
  36. package/dist/types/shared/src/scheme/flowrunner/java.dto.d.ts +1 -0
  37. package/dist/types/shared/src/scheme/shared-extensions/base.d.ts +5 -0
  38. package/dist/types/shared/src/scheme/shared-extensions/custom-extensions.d.ts +147 -0
  39. package/dist/types/shared/src/scheme/shared-extensions/extension.d.ts +20 -0
  40. package/dist/types/shared/src/scheme/shared-extensions/methods.d.ts +33 -1
  41. package/dist/types/shared/src/scheme/shared-extensions/params-schema.d.ts +1 -0
  42. package/dist/types/shared/src/scheme/shared-extensions/resolve.d.ts +15 -0
  43. package/dist/types/shared/src/scheme/shared-extensions/search.d.ts +10 -0
  44. package/package.json +1 -1
  45. package/runtime/index.js +267 -41
  46. package/runtime/index.js.map +3 -3
  47. package/runtime/types/flow-extension-runner/src/v2/actions/action-method.d.ts +13 -9
  48. package/runtime/types/flow-extension-runner/src/v2/loaders/loader-method.d.ts +52 -7
  49. package/runtime/types/flow-extension-runner/src/v2/loaders/loader-owner.d.ts +4 -6
  50. package/runtime/types/flow-extension-runner/src/v2/model/model-types.d.ts +2 -0
  51. package/runtime/types/flow-extension-runner/src/v2/params/index.d.ts +2 -2
  52. package/runtime/types/flow-extension-runner/src/v2/params/json/encode.d.ts +10 -2
  53. package/runtime/types/flow-extension-runner/src/v2/params/json/types.d.ts +1 -0
  54. package/runtime/types/flow-extension-runner/src/v2/params/zod.d.ts +29 -0
  55. package/runtime/types/flow-extension-runner/src/v2/types.d.ts +21 -9
  56. package/runtime/types/shared/src/constants/activity-log.d.ts +1496 -0
  57. package/runtime/types/shared/src/constants/docs.d.ts +2 -0
  58. package/runtime/types/shared/src/constants/notification-types.d.ts +11 -5
  59. package/runtime/types/shared/src/scheme/activity-log-base.d.ts +35 -0
  60. package/runtime/types/shared/src/scheme/data-types/java.dto.d.ts +2 -3
  61. package/runtime/types/shared/src/scheme/flowrunner/custom-elements.d.ts +20 -0
  62. package/runtime/types/shared/src/scheme/flowrunner/java.dto.d.ts +1 -0
  63. package/runtime/types/shared/src/scheme/shared-extensions/base.d.ts +5 -0
  64. package/runtime/types/shared/src/scheme/shared-extensions/custom-extensions.d.ts +147 -0
  65. package/runtime/types/shared/src/scheme/shared-extensions/extension.d.ts +20 -0
  66. package/runtime/types/shared/src/scheme/shared-extensions/methods.d.ts +33 -1
  67. package/runtime/types/shared/src/scheme/shared-extensions/params-schema.d.ts +1 -0
  68. package/runtime/types/shared/src/scheme/shared-extensions/resolve.d.ts +15 -0
  69. package/runtime/types/shared/src/scheme/shared-extensions/search.d.ts +10 -0
  70. package/templates/blank/files/src/index.js +1 -1
  71. package/templates/demo-todo-list/files/src/index.js +7 -7
  72. package/templates/qa-test/files/src/index.js +33 -4
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,82 @@ 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 || !("execute" in spec)) {
5163
+ return;
5164
+ }
5165
+ if (typeof spec.execute !== "function") {
5166
+ refuse(
5167
+ `${subjectOf(source, path19)}: \`.dynamicProps()\` needs an \`execute\` function that returns the loaded fields.`,
5168
+ source,
5169
+ path19,
5170
+ typeof spec.execute
5171
+ );
5172
+ }
5173
+ if (spec.dependsOn !== void 0 && (!Array.isArray(spec.dependsOn) || spec.dependsOn.some((item) => typeof item !== "string"))) {
5174
+ refuse(
5175
+ `${subjectOf(source, path19)}: \`.dynamicProps()\` \`dependsOn\` must be an array of param names.`,
5176
+ source,
5177
+ path19,
5178
+ "dependsOn"
5179
+ );
5180
+ }
5181
+ for (const dependency of spec.dependsOn ?? []) {
5182
+ if (dependency === name || !siblings.includes(dependency)) {
5183
+ refuse(
5184
+ `${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"}.`,
5185
+ source,
5186
+ path19,
5187
+ dependency
5188
+ );
5189
+ }
5190
+ }
5191
+ if (ins.meta.frDictionary) {
5192
+ refuse(
5193
+ `${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.`,
5194
+ source,
5195
+ path19,
5196
+ "dictionary"
5197
+ );
5198
+ }
5199
+ const element = ins.resolvedType === "array" ? ins.core?._zod?.def?.element : void 0;
5200
+ if (!isLooseObject(schema) && !isLooseObject(element)) {
5201
+ refuse(
5202
+ `${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}`,
5203
+ source,
5204
+ path19,
5205
+ ins.resolvedType ?? "unknown"
5206
+ );
5207
+ }
5208
+ }
5209
+ function assertField(schema, source, path19, seen, topLevel = false) {
5146
5210
  if (!schema || seen.has(schema)) {
5147
5211
  return;
5148
5212
  }
5149
5213
  seen.add(schema);
5150
5214
  const ins = inspect(schema);
5215
+ if (ins.meta.frDynamicProps && !isDynamicPropsSlot(source, topLevel)) {
5216
+ refuse(
5217
+ `${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.`,
5218
+ source,
5219
+ path19,
5220
+ "dynamicProps"
5221
+ );
5222
+ }
5151
5223
  if (ins.resolvedType === "catch") {
5152
5224
  refuseCatch(source, path19);
5153
5225
  }
@@ -5176,8 +5248,13 @@ function assertSupportedSchema(scheme, source) {
5176
5248
  }
5177
5249
  const slot = source.slot ?? "schema";
5178
5250
  const seen = /* @__PURE__ */ new Set();
5179
- for (const [name, field] of shapeEntries(scheme)) {
5180
- assertField(field, source, `${slot}.${name}`, seen);
5251
+ const fields = shapeEntries(scheme);
5252
+ const names = fields.map(([name]) => name);
5253
+ for (const [name, field] of fields) {
5254
+ assertField(field, source, `${slot}.${name}`, seen, true);
5255
+ if (isDynamicPropsSlot(source, true)) {
5256
+ assertDynamicProps(field, name, names, source, `${slot}.${name}`);
5257
+ }
5181
5258
  }
5182
5259
  }
5183
5260
 
@@ -5999,6 +6076,9 @@ function extendPrototype() {
5999
6076
  proto.labels = function labels(byValue) {
6000
6077
  return this.meta({ frLabels: byValue });
6001
6078
  };
6079
+ proto.dynamicProps = function dynamicProps(spec) {
6080
+ return this.meta({ frDynamicProps: spec });
6081
+ };
6002
6082
  proto.map = function map() {
6003
6083
  throw new Error(
6004
6084
  "`.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 +6299,36 @@ function unwrap(schema) {
6219
6299
  }
6220
6300
  return result;
6221
6301
  }
6222
- function encodeMeta(meta) {
6223
- const encoded = toJsonValue2(meta);
6302
+ function isDynamicPropsSpec(value) {
6303
+ return !!value && typeof value === "object" && typeof value.execute === "function";
6304
+ }
6305
+ function hasFunction(value, depth = 0) {
6306
+ if (typeof value === "function") {
6307
+ return true;
6308
+ }
6309
+ if (!value || typeof value !== "object" || depth > MAX_UNWRAP_DEPTH) {
6310
+ return false;
6311
+ }
6312
+ return Object.values(value).some((inner) => hasFunction(inner, depth + 1));
6313
+ }
6314
+ function encodeMeta(meta, field, loaderId) {
6315
+ let source = meta;
6316
+ if (isDynamicPropsSpec(meta.frDynamicProps)) {
6317
+ if (!loaderId) {
6318
+ throw new Error(`Cannot encode "${field}": its \`.dynamicProps()\` has no loader method to publish.`);
6319
+ }
6320
+ source = { ...meta, frDynamicProps: { id: loaderId, dependsOn: meta.frDynamicProps.dependsOn ?? [] } };
6321
+ }
6322
+ if (hasFunction(source)) {
6323
+ throw new Error(`Cannot encode "${field}": its metadata holds a function, which has no wire form.`);
6324
+ }
6325
+ const encoded = toJsonValue2(source);
6224
6326
  return Object.keys(encoded).length ? encoded : void 0;
6225
6327
  }
6328
+ function isLoose(core) {
6329
+ const catchall = core?._zod?.def?.catchall;
6330
+ return catchall?._zod?.def?.type === "unknown";
6331
+ }
6226
6332
  function encodeValues(core, type) {
6227
6333
  if (type === "enum") {
6228
6334
  const entries = core?._zod?.def?.entries ?? {};
@@ -6234,7 +6340,7 @@ function encodeValues(core, type) {
6234
6340
  }
6235
6341
  return void 0;
6236
6342
  }
6237
- function encodeField(name, schema, seen = /* @__PURE__ */ new Set()) {
6343
+ function encodeField(name, schema, seen = /* @__PURE__ */ new Set(), loaderId) {
6238
6344
  if (seen.has(schema)) {
6239
6345
  return { name, type: "unknown", unsupported: ["recursion"] };
6240
6346
  }
@@ -6247,7 +6353,7 @@ function encodeField(name, schema, seen = /* @__PURE__ */ new Set()) {
6247
6353
  const isUnion = !!ins.branches;
6248
6354
  const format = isUnion ? void 0 : core?._zod?.def?.format;
6249
6355
  const { checks, unsupported: checkIssues } = isUnion ? { checks: [], unsupported: [] } : encodeChecks(core);
6250
- const meta = encodeMeta(ins.meta);
6356
+ const meta = encodeMeta(ins.meta, name, loaderId);
6251
6357
  const message = isUnion ? void 0 : messageOf(core?._zod?.def ?? {});
6252
6358
  const values = encodeValues(core, type);
6253
6359
  const problems = [...unsupported, ...checkIssues];
@@ -6265,6 +6371,7 @@ function encodeField(name, schema, seen = /* @__PURE__ */ new Set()) {
6265
6371
  ...values?.length ? { values } : {},
6266
6372
  ...meta ? { meta } : {},
6267
6373
  ...message ? { message } : {},
6374
+ ...type === "object" && isLoose(core) ? { loose: true } : {},
6268
6375
  ...type === "object" ? { properties: shapeEntries(core).map(([key, inner]) => encodeField(key, inner, seen)) } : {},
6269
6376
  ...type === "array" ? { element: encodeField("", core?._zod?.def?.element, seen) } : {},
6270
6377
  ...type === "record" ? { value: encodeField("", core?._zod?.def?.valueType, seen) } : {},
@@ -6274,14 +6381,14 @@ function encodeField(name, schema, seen = /* @__PURE__ */ new Set()) {
6274
6381
  seen.delete(schema);
6275
6382
  return encoded;
6276
6383
  }
6277
- function encodeParams(scheme) {
6384
+ function encodeParams(scheme, options = {}) {
6278
6385
  const schema = scheme;
6279
6386
  if (!schema?._zod) {
6280
6387
  return null;
6281
6388
  }
6282
6389
  return {
6283
6390
  v: SCHEMA_JSON_VERSION,
6284
- fields: shapeEntries(schema).map(([name, field]) => encodeField(name, field))
6391
+ fields: shapeEntries(schema).map(([name, field]) => encodeField(name, field, /* @__PURE__ */ new Set(), options.loaderIdOf?.(name)))
6285
6392
  };
6286
6393
  }
6287
6394
 
@@ -6597,11 +6704,50 @@ var ActionMethod = class extends ExtensionMethod {
6597
6704
  this.props = props;
6598
6705
  this.params = MethodParams.of(props.params, { serviceId: extension.id, kind: "action", itemId: props.id, slot: "params" });
6599
6706
  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"
6707
+ this.dynamicParams = props.dynamicParams ? this.#checkDynamicParams(props.dynamicParams) : void 0;
6708
+ }
6709
+ /**
6710
+ * `dynamicParams` takes the same `{ dependsOn, execute }` as `.dynamicProps()`. The old
6711
+ * `{ criteria, resolve }` shape is refused by name, so a service written against it fails at load with the
6712
+ * fix rather than publishing a loader that never runs.
6713
+ */
6714
+ #checkDynamicParams(def) {
6715
+ const source = { serviceId: this.extension.id, kind: "action", itemId: this.props.id, slot: "dynamicParams" };
6716
+ const fail2 = (message, received) => {
6717
+ throw new InvalidSchemaError(`[flow-extension:${this.extension.id}] action "${this.props.id}": ${message}`, { ...source, received });
6718
+ };
6719
+ const legacy = def;
6720
+ if (legacy.resolve !== void 0 || legacy.criteria !== void 0) {
6721
+ fail2(
6722
+ "`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() }) }",
6723
+ "criteria/resolve"
6724
+ );
6725
+ }
6726
+ if (typeof def.execute !== "function") {
6727
+ fail2("`dynamicParams` needs an `execute` function that returns the loaded params.", typeof def.execute);
6728
+ }
6729
+ if (def.dependsOn !== void 0 && (!Array.isArray(def.dependsOn) || def.dependsOn.some((item) => typeof item !== "string"))) {
6730
+ fail2("`dynamicParams.dependsOn` must be an array of param names.", def.dependsOn);
6731
+ }
6732
+ const declared = this.params.keys();
6733
+ for (const dependency of def.dependsOn ?? []) {
6734
+ if (!declared.includes(dependency)) {
6735
+ fail2(
6736
+ `\`dynamicParams\` depends on "${dependency}", which the action does not declare in \`params\`. Declared: ${declared.join(", ") || "none"}.`,
6737
+ dependency
6738
+ );
6739
+ }
6740
+ }
6741
+ return def;
6742
+ }
6743
+ /**
6744
+ * The top-level params declared with `.dynamicProps()`, and the def each one carries. Placement and shape
6745
+ * were checked when `params` was built (see ../params/schema/assert-supported-schema.ts).
6746
+ */
6747
+ dynamicPropsFields() {
6748
+ return this.params.fields().flatMap(([name, schema]) => {
6749
+ const def = inspect(schema).meta.frDynamicProps;
6750
+ return def && "execute" in def ? [[name, def]] : [];
6605
6751
  });
6606
6752
  }
6607
6753
  get id() {
@@ -6627,8 +6773,9 @@ var ActionMethod = class extends ExtensionMethod {
6627
6773
  * Normalize, coerce and validate against the declared `params` — the same pipeline every other declared
6628
6774
  * slot uses, so an author expresses optionality in the schema and nowhere else.
6629
6775
  *
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.
6776
+ * An action with `dynamicParams` carries the input's undeclared keys through, since its loaded top-level
6777
+ * fields are not in the static schema. A `.dynamicProps()` field needs nothing here: it is a loose object,
6778
+ * which keeps the loaded keys inside it.
6632
6779
  */
6633
6780
  validate(methodData) {
6634
6781
  return this.params.normalize(
@@ -6640,22 +6787,22 @@ var ActionMethod = class extends ExtensionMethod {
6640
6787
  execute(params, ctx) {
6641
6788
  return this.props.execute(ctx.bagWith({ params }));
6642
6789
  }
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
6790
  // ── output model ───────────────────────────────────────────────────────────
6648
6791
  toModel() {
6649
6792
  const [ownStart, ownEnd] = this.props.appearanceColors ?? [];
6650
6793
  const [colorStart, colorEnd] = this.extension.appearanceColors;
6794
+ const args = toArgs(this.params);
6651
6795
  const metaInfo = {
6652
- args: toArgs(this.params),
6796
+ args,
6653
6797
  ...this.result.toMetaInfo(this.id, this.params)
6654
6798
  };
6655
- if (this.hasDynamicParams()) {
6799
+ for (const [name, def] of this.dynamicPropsFields()) {
6800
+ args[name] = { ...args[name], schemaLoader: dynamicPropsLoaderName(this.id, name), dependsOn: def.dependsOn ?? [] };
6801
+ }
6802
+ if (this.dynamicParams) {
6656
6803
  metaInfo.dynamicParams = {
6657
6804
  methodName: dynamicParamsLoaderName(this.id),
6658
- dependsOn: this.dynamicParamsCriteria.keys()
6805
+ dependsOn: this.dynamicParams.dependsOn ?? []
6659
6806
  };
6660
6807
  }
6661
6808
  return {
@@ -6670,7 +6817,7 @@ var ActionMethod = class extends ExtensionMethod {
6670
6817
  returnType: this.result.returnType,
6671
6818
  queryParams: [],
6672
6819
  bodyParams: toBodyParams(this.params),
6673
- paramsSchema: encodeParams(this.params.scheme),
6820
+ paramsSchema: encodeParams(this.params.scheme, { loaderIdOf: (name) => dynamicPropsLoaderName(this.id, name) }),
6674
6821
  metaInfo
6675
6822
  };
6676
6823
  }
@@ -6932,7 +7079,11 @@ var LoaderMethod = class extends ExtensionMethod {
6932
7079
  validate(methodData) {
6933
7080
  const input = this.input(methodData);
6934
7081
  const payload = input.parseField("payload", LoaderPayloadSchema);
6935
- return this.criteria.normalize(payload.criteria, input.invalidCriteria(), { carryUnknown: true });
7082
+ return this.criteria.normalize(payload.criteria, input.invalidCriteria(), { carryUnknown: this.carryUnknown });
7083
+ }
7084
+ // Whether the criteria's undeclared keys ride through to the handler.
7085
+ get carryUnknown() {
7086
+ return true;
6936
7087
  }
6937
7088
  // Internal (SYSTEM-like): no icon, no colours, no sample. Its params are left opaque in the model — it is
6938
7089
  // invoked with `{ criteria }` at runtime, not through a rendered form.
@@ -6964,7 +7115,9 @@ var SampleResultLoaderMethod = class extends LoaderMethod {
6964
7115
  get returnType() {
6965
7116
  return "OBJECT";
6966
7117
  }
6967
- // The sample varies with ANY param of the owner, so all of them are its criteria.
7118
+ // The sample varies with ANY param of the owner, so all of them are its criteria. Undeclared keys ride
7119
+ // through too: the node's other params come along, and the owner's `result` fn may read fields its
7120
+ // `dynamicParams` loaded.
6968
7121
  get criteria() {
6969
7122
  return this.owner.params;
6970
7123
  }
@@ -6972,31 +7125,101 @@ var SampleResultLoaderMethod = class extends LoaderMethod {
6972
7125
  return this.owner.result.runLoader(ctx.bagWith({ params: criteria }));
6973
7126
  }
6974
7127
  };
6975
- var DynamicParamsLoaderMethod = class extends LoaderMethod {
6976
- constructor(extension, owner) {
7128
+ var isZod = (value) => !!value?._zod;
7129
+ var ParamsLoaderMethod = class extends LoaderMethod {
7130
+ constructor(extension, owner, def) {
6977
7131
  super(extension, owner);
6978
7132
  this.owner = owner;
7133
+ this.def = def;
6979
7134
  }
6980
- get name() {
6981
- return dynamicParamsLoaderName(this.owner.id);
6982
- }
7135
+ #criteria;
6983
7136
  get registerAs() {
6984
7137
  return "PARAM_SCHEMA_DEFINITION";
6985
7138
  }
6986
7139
  get returnType() {
6987
- return "LIST";
7140
+ return "OBJECT";
7141
+ }
7142
+ get carryUnknown() {
7143
+ return false;
6988
7144
  }
7145
+ // Built unguarded: the picked fields were already checked on the owner, and a picked sibling may itself
7146
+ // carry `.dynamicProps()`, which the guard only allows in an action's own `params`.
6989
7147
  get criteria() {
6990
- return this.owner.dynamicParamsCriteria;
7148
+ const dependsOn = this.def.dependsOn ?? [];
7149
+ this.#criteria ??= MethodParams.of(
7150
+ z.object(Object.fromEntries(this.owner.params.fields().filter(([name]) => dependsOn.includes(name)))),
7151
+ { serviceId: this.extension.id, kind: "loader criteria", itemId: this.name }
7152
+ );
7153
+ return this.#criteria;
6991
7154
  }
6992
7155
  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
- }));
7156
+ const loaded = await this.def.execute(ctx.bagWith({ criteria }));
7157
+ const params = this.toParams(loaded);
7158
+ return { paramsSchema: encodeParams(params.scheme), params: toProperties(params) };
7159
+ }
7160
+ // A plain shape is wrapped in `z.object()`; anything else that is not a `z.object` is refused by the same
7161
+ // guards a declared params slot goes through.
7162
+ toParams(loaded) {
7163
+ const source = { serviceId: this.extension.id, kind: "action", itemId: this.owner.id, slot: this.slot };
7164
+ const schema = loaded && typeof loaded === "object" && !isZod(loaded) ? z.object(loaded) : loaded;
7165
+ const returned = MethodParams.of(schema, source);
7166
+ const staticFields = this.staticFields;
7167
+ if (!staticFields.length) {
7168
+ return returned;
7169
+ }
7170
+ const staticNames = new Set(staticFields.map(([name]) => name));
7171
+ const repeated = returned.keys().filter((name) => staticNames.has(name));
7172
+ if (repeated.length) {
7173
+ throw new InvalidSchemaError(
7174
+ `[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.`,
7175
+ { ...source, received: repeated }
7176
+ );
7177
+ }
7178
+ return MethodParams.of(z.object(Object.fromEntries([...staticFields, ...returned.fields()])), source);
7179
+ }
7180
+ };
7181
+ var DynamicParamsLoaderMethod = class extends ParamsLoaderMethod {
7182
+ constructor(extension, owner) {
7183
+ super(extension, owner, owner.dynamicParams);
7184
+ }
7185
+ get name() {
7186
+ return dynamicParamsLoaderName(this.owner.id);
7187
+ }
7188
+ get slot() {
7189
+ return "dynamicParams.execute()";
7190
+ }
7191
+ get staticFields() {
7192
+ return [];
7193
+ }
7194
+ toParams(loaded) {
7195
+ const params = super.toParams(loaded);
7196
+ const declared = new Set(this.owner.params.keys());
7197
+ const shadowing = params.keys().filter((name) => declared.has(name));
7198
+ if (shadowing.length) {
7199
+ throw new InvalidSchemaError(
7200
+ `[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.`,
7201
+ { serviceId: this.extension.id, kind: "action", itemId: this.owner.id, slot: this.slot, received: shadowing }
7202
+ );
7203
+ }
7204
+ return params;
7205
+ }
7206
+ };
7207
+ var DynamicPropsLoaderMethod = class extends ParamsLoaderMethod {
7208
+ constructor(extension, owner, field, def) {
7209
+ super(extension, owner, def);
7210
+ this.field = field;
7211
+ }
7212
+ get name() {
7213
+ return dynamicPropsLoaderName(this.owner.id, this.field);
7214
+ }
7215
+ get slot() {
7216
+ return `params.${this.field}.dynamicProps().execute()`;
7217
+ }
7218
+ get staticFields() {
7219
+ const schema = this.owner.params.fields().find(([name]) => name === this.field)?.[1];
7220
+ const ins = inspect(schema);
7221
+ const object = ins.resolvedType === "array" ? ins.core?._zod?.def?.element : schema;
7222
+ return shapeEntries(inspect(object).core);
7000
7223
  }
7001
7224
  };
7002
7225
 
@@ -7909,6 +8132,9 @@ var Extension = class {
7909
8132
  if (action.hasDynamicParams()) {
7910
8133
  this.#addMethod(new DynamicParamsLoaderMethod(this, action), "dynamic params loader");
7911
8134
  }
8135
+ for (const [field, def] of action.dynamicPropsFields()) {
8136
+ this.#addMethod(new DynamicPropsLoaderMethod(this, action, field, def), "dynamic props loader");
8137
+ }
7912
8138
  }
7913
8139
  registerPollingTrigger(props) {
7914
8140
  this.#claimId(props.id, "polling trigger");
@@ -9653,6 +9879,22 @@ function writeReadme(projectRoot) {
9653
9879
  import_fs13.default.writeFileSync(fullPath, README(packageNameFrom(projectRoot)), "utf-8");
9654
9880
  return "created";
9655
9881
  }
9882
+ var JSCONFIG = {
9883
+ compilerOptions: {
9884
+ module: "node16",
9885
+ moduleResolution: "node16",
9886
+ types: [`${CLI_PACKAGE}/runtime`]
9887
+ },
9888
+ include: ["services/*/src/**/*.js"]
9889
+ };
9890
+ function writeJsconfig(projectRoot) {
9891
+ const fullPath = import_path18.default.join(projectRoot, "jsconfig.json");
9892
+ if (import_fs13.default.existsSync(fullPath)) {
9893
+ return "skipped";
9894
+ }
9895
+ import_fs13.default.writeFileSync(fullPath, JSON.stringify(JSCONFIG, null, 2) + "\n", "utf-8");
9896
+ return "created";
9897
+ }
9656
9898
  function git(projectRoot, args) {
9657
9899
  (0, import_child_process.execFileSync)("git", args, { cwd: projectRoot, stdio: "pipe" });
9658
9900
  }
@@ -9768,6 +10010,7 @@ async function init(options = {}) {
9768
10010
  const server = ensureServerUrl(projectRoot, requestedServerUrl);
9769
10011
  record(CONFIG_FILE, server.created ? "created" : server.updated ? "updated" : "skipped");
9770
10012
  record("README.md", writeReadme(projectRoot));
10013
+ record("jsconfig.json", writeJsconfig(projectRoot));
9771
10014
  const testing = tests ? writeTestingFiles(projectRoot) : { created: [], skipped: [] };
9772
10015
  testing.created.forEach((file) => record(file, "created"));
9773
10016
  testing.skipped.forEach((file) => record(file, "skipped"));