processfocus 0.1.0-next.1 → 0.1.0-next.2

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/dist/index.mjs CHANGED
@@ -1802,6 +1802,7 @@ const validateFormRuleTargets = (formStep, representation, rules) => {
1802
1802
  }
1803
1803
  }
1804
1804
  };
1805
+ Data.TaggedError("FormSubmissionError");
1805
1806
  const defaultProviderUserDisplay = { display: (providerUserIdOrEmail) => Effect.succeed(providerUserIdOrEmail) };
1806
1807
  const toSummaryContext = (ctx) => {
1807
1808
  if ("providerUserDisplay" in ctx) return ctx;
@@ -1907,6 +1908,7 @@ var Form = class extends Step {
1907
1908
  * Request-local resolution of the static declaration's lazy expressions.
1908
1909
  */
1909
1910
  _formFn;
1911
+ _onSubmit;
1910
1912
  /**
1911
1913
  * The summary function, stored for computing summary from process state.
1912
1914
  */
@@ -1975,6 +1977,7 @@ var Form = class extends Step {
1975
1977
  ]);
1976
1978
  assertResolvedFormFields(this._formFields);
1977
1979
  const struct = Schema.Struct(this._formFields);
1980
+ this._onSubmit = props.onSubmit;
1978
1981
  this._schema = props.validate ? struct.pipe(Schema.filterEffect(props.validate)) : struct;
1979
1982
  const flatSubmission = submissionSchemaSync(struct);
1980
1983
  this._submissionEffectSchema = props.validate ? flatSubmission.pipe(Schema.filterEffect(props.validate)) : flatSubmission;
@@ -2063,6 +2066,10 @@ var Form = class extends Step {
2063
2066
  get outputSchema() {
2064
2067
  return this._schema;
2065
2068
  }
2069
+ /** Invoke only after the runtime has validated and authorized the submission. */
2070
+ executeSubmit(input) {
2071
+ return Effect.suspend(() => this._onSubmit?.(input) ?? Effect.void);
2072
+ }
2066
2073
  /**
2067
2074
  * Get the flat submission validation schema for this form.
2068
2075
  * Returns submissionSchema(fields) (wrapper fields flattened, read-only/
@@ -2576,6 +2583,8 @@ var List = class extends Construct {
2576
2583
  roles;
2577
2584
  /** Output schema defining the shape of list items */
2578
2585
  output;
2586
+ /** Start button metadata; visibility is authorized separately from List access. */
2587
+ startProcess;
2579
2588
  /** Default page size */
2580
2589
  defaultPageSize;
2581
2590
  /** The query function */
@@ -2606,6 +2615,16 @@ var List = class extends Construct {
2606
2615
  this._create = props.create;
2607
2616
  this.createFormFields = props.create?.form();
2608
2617
  if (this.createFormFields && Object.keys(submissionSchemaSync(Schema.Struct(this.createFormFields)).fields).length === 0) throw new Error(`List ${normalizePath(this.node.path)} create form requires at least one submittable field`);
2618
+ if (props.startProcess) {
2619
+ const starts = props.startProcess.startNodes();
2620
+ const start = starts[0];
2621
+ if (starts.length !== 1 || !isForm(start)) throw new Error(`List ${normalizePath(this.node.path)} startProcess must have exactly one start form`);
2622
+ this.startProcess = {
2623
+ path: normalizePath(props.startProcess.node.path),
2624
+ name: props.startProcess.props.name,
2625
+ startStepPath: normalizePath(start.node.path)
2626
+ };
2627
+ }
2609
2628
  this.name = props.name;
2610
2629
  if (props.detailName !== void 0) this.detailName = props.detailName;
2611
2630
  if (props.purpose !== void 0) this.purpose = props.purpose;
@@ -82,6 +82,15 @@ interface FormRuleAuthor<TInput extends Schema.Struct.Fields> {
82
82
  * Using Record prevents duplicate labels.
83
83
  */
84
84
  export type Summary = Record<string, string>;
85
+ declare const FormSubmissionError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
86
+ readonly _tag: "FormSubmissionError";
87
+ } & Readonly<A>;
88
+ /** Client-safe rejection from an authored form submission callback. */
89
+ export declare class FormSubmissionError extends FormSubmissionError_base<{
90
+ readonly field: string;
91
+ readonly message: string;
92
+ }> {
93
+ }
85
94
  export interface FormEmbedConfig {
86
95
  readonly sites: readonly string[];
87
96
  readonly thankYou: string;
@@ -221,6 +230,12 @@ interface FormStepPropsBase<TState, TSteps extends Record<string, StepMeta | For
221
230
  * it before persisting `to_do.assigned_to_provider_user`.
222
231
  */
223
232
  readonly assignee?: (state: TState, ctx: FlowContext<TSteps>, item: TItem) => AssigneeResult;
233
+ /**
234
+ * Persist domain data after validation, inside the submission transaction.
235
+ * Failure rolls back submission. Completion retries can rerun this callback:
236
+ * use transactional database writes, never irreversible external effects.
237
+ */
238
+ readonly onSubmit?: (input: InferFormSchemaType<TInput>) => Effect.Effect<void, FormSubmissionError, unknown>;
224
239
  /**
225
240
  * Optional struct-level validation that runs after individual field
226
241
  * validation during schema decode. Receives the flat decoded struct
@@ -341,6 +356,7 @@ export declare class Form<TState = Record<string, never>, TSteps extends Record<
341
356
  * Request-local resolution of the static declaration's lazy expressions.
342
357
  */
343
358
  private _formFn;
359
+ private readonly _onSubmit;
344
360
  /**
345
361
  * The summary function, stored for computing summary from process state.
346
362
  */
@@ -419,6 +435,8 @@ export declare class Form<TState = Record<string, never>, TSteps extends Record<
419
435
  * filterEffect when a `validate` callback was provided.
420
436
  */
421
437
  get outputSchema(): Schema.Schema.Any;
438
+ /** Invoke only after the runtime has validated and authorized the submission. */
439
+ executeSubmit(input: InferFormSchemaType<TInput>): Effect.Effect<void, FormSubmissionError, unknown>;
422
440
  /**
423
441
  * Get the flat submission validation schema for this form.
424
442
  * Returns submissionSchema(fields) (wrapper fields flattened, read-only/
@@ -6,6 +6,7 @@ import { type ClientFormDefinition, type WalkError } from "../../../form-client-
6
6
  import { type MetricBreakdownControl } from "../../../form-schema/src/index.js";
7
7
  import { type DeepWritable, type FlattenFields, submissionSchemaSync as makeSubmissionSchema } from "../../../form-submission-schema/src/index.js";
8
8
  import type { OrgUnit } from "./org-unit.js";
9
+ import type { Process } from "./process.js";
9
10
  import type { Role } from "./role.js";
10
11
  declare const ListItemQueryNotDefinedError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
11
12
  readonly _tag: "ListItemQueryNotDefinedError";
@@ -174,6 +175,8 @@ export interface ListProps<TOutput extends Schema.Struct.Fields, R = never, TFor
174
175
  readonly roles: readonly [Role, ...Role[]];
175
176
  /** Output schema defining the shape of list items `query` should return */
176
177
  readonly output: TOutput;
178
+ /** Optional button opening this process's single start form. Uses its start permission. */
179
+ readonly startProcess?: Process;
177
180
  /** Default page size (default: 20, max: 100) */
178
181
  readonly defaultPageSize?: number;
179
182
  /** Query function returning paginated results */
@@ -246,6 +249,12 @@ export declare class List<TOutput extends Schema.Struct.Fields = Schema.Struct.F
246
249
  readonly roles: readonly [Role, ...Role[]];
247
250
  /** Output schema defining the shape of list items */
248
251
  readonly output: TOutput;
252
+ /** Start button metadata; visibility is authorized separately from List access. */
253
+ readonly startProcess: {
254
+ readonly path: string;
255
+ readonly name: string;
256
+ readonly startStepPath: string;
257
+ } | undefined;
249
258
  /** Default page size */
250
259
  readonly defaultPageSize: number;
251
260
  /** The query function */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "processfocus",
3
- "version": "0.1.0-next.1",
3
+ "version": "0.1.0-next.2",
4
4
  "type": "module",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "repository": {
@@ -45,7 +45,7 @@
45
45
  "./package.json": "./package.json"
46
46
  },
47
47
  "dependencies": {
48
- "@processfocus/runtime": "0.1.0-next.1",
48
+ "@processfocus/runtime": "0.1.0-next.2",
49
49
  "constructs": "^10.8.1",
50
50
  "effect": "^3.22.2",
51
51
  "graphology": "^0.26.0",