processfocus 0.1.0-next.1 → 0.1.0-next.3

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 (67) hide show
  1. package/dist/{auth-FmXptohB.mjs → auth-DWWupwJA.mjs} +57 -24
  2. package/dist/auth-config/src/lib/authentication-config.d.ts +13 -8
  3. package/dist/auth-config/src/lib/aws-role-binding.d.ts +21 -0
  4. package/dist/auth-config/src/lib/provider-types.d.ts +87 -76
  5. package/dist/auth-config/src/lib/workload-trust.d.ts +41 -0
  6. package/dist/auth.mjs +1 -2
  7. package/dist/business-calendar/src/lib/calendar-config.d.ts +73 -76
  8. package/dist/business-calendar/src/lib/calendar-period.d.ts +30 -30
  9. package/dist/business-calendar/src/lib/calendar-service.d.ts +10 -10
  10. package/dist/business-calendar/src/lib/datetime-utils.d.ts +1 -1
  11. package/dist/business-calendar/src/lib/holidays.d.ts +40 -40
  12. package/dist/business-calendar/src/lib/types.d.ts +29 -29
  13. package/dist/calendar.mjs +73 -63
  14. package/dist/form-schema/src/index.d.ts +4 -1
  15. package/dist/form-schema/src/lib/annotation-helpers.d.ts +2 -2
  16. package/dist/form-schema/src/lib/email.d.ts +2 -2
  17. package/dist/form-schema/src/lib/field-count.d.ts +2 -2
  18. package/dist/form-schema/src/lib/form-annotations.d.ts +6 -0
  19. package/dist/form-schema/src/lib/form-presentation.d.ts +30 -0
  20. package/dist/form-schema/src/lib/form-schema.d.ts +64 -34
  21. package/dist/form-schema/src/lib/number-from-string.d.ts +3 -0
  22. package/dist/form-schema/src/lib/phone.d.ts +2 -2
  23. package/dist/form-schema/src/lib/public-completion-correction.d.ts +5 -0
  24. package/dist/form-schema/src/lib/search-lookup-items.d.ts +3 -0
  25. package/dist/form-submission-schema/src/index.d.ts +3 -0
  26. package/dist/form-submission-schema/src/lib/executable-rules.d.ts +43 -0
  27. package/dist/form-submission-schema/src/lib/form-submission-schema.d.ts +33 -10
  28. package/dist/form-submission-schema/src/lib/json-schema.d.ts +3 -0
  29. package/dist/form-submission-schema/src/lib/submission-utils.d.ts +19 -0
  30. package/dist/forms.mjs +26 -2
  31. package/dist/frontend-manifest/src/lib/browser-plugin-artifact.d.ts +9 -0
  32. package/dist/frontend-manifest/src/lib/frontend-manifest.d.ts +8 -6
  33. package/dist/frontend-plugin-host/src/lib/frontend-plugin-host.d.ts +11 -1
  34. package/dist/index.d.ts +1 -1
  35. package/dist/index.mjs +485 -972
  36. package/dist/manifest.mjs +1 -2
  37. package/dist/plugin.mjs +1 -2
  38. package/dist/process/src/lib/form-authoring.d.ts +1 -1
  39. package/dist/process/src/lib/form-decoration.d.ts +3 -3
  40. package/dist/process/src/lib/form.d.ts +79 -97
  41. package/dist/process/src/lib/list.d.ts +45 -23
  42. package/dist/process/src/lib/lookup-accessor.d.ts +4 -1
  43. package/dist/process/src/lib/organisation.d.ts +14 -0
  44. package/dist/process/src/lib/process.d.ts +24 -2
  45. package/dist/process/src/lib/schedule.d.ts +1 -1
  46. package/dist/process/src/lib/step.d.ts +13 -3
  47. package/dist/process/src/lib/system-step-executor.d.ts +4 -4
  48. package/dist/process/src/lib/system-step.d.ts +11 -1
  49. package/dist/sdk/src/index.d.ts +1 -1
  50. package/dist/sdk/src/testing.d.ts +0 -1
  51. package/dist/{src-C-909PVQ.mjs → src-BQ55-khF.mjs} +118 -66
  52. package/dist/testing.d.ts +0 -1
  53. package/dist/testing.mjs +2 -4
  54. package/package.json +4 -4
  55. package/dist/form-client-representation/src/index.d.ts +0 -6
  56. package/dist/form-client-representation/src/lib/as-client-representation.d.ts +0 -31
  57. package/dist/form-client-representation/src/lib/client-form-definition.d.ts +0 -17
  58. package/dist/form-client-representation/src/lib/extract-annotations.d.ts +0 -20
  59. package/dist/form-client-representation/src/lib/plugin-registry.d.ts +0 -6
  60. package/dist/form-client-representation/src/lib/types.d.ts +0 -239
  61. package/dist/form-client-representation/src/lib/walker.d.ts +0 -68
  62. package/dist/form-rule/src/index.d.ts +0 -3
  63. package/dist/form-rule/src/lib/evaluator.d.ts +0 -2
  64. package/dist/form-rule/src/lib/paths.d.ts +0 -9
  65. package/dist/form-rule/src/lib/types.d.ts +0 -89
  66. package/dist/form-schema/src/lib/property-signature.d.ts +0 -3
  67. package/dist/paths-BkzLn-rG.mjs +0 -282
package/dist/index.mjs CHANGED
@@ -1,13 +1,10 @@
1
- import { A as LINK_URL_SYMBOL, C as FLATTEN_SYMBOL, Ct as FormRequired, D as LINK_COLOR_SYMBOL, Dt as FormTextAreaInput, Et as FormTableInput, F as METRIC_BREAKDOWN_SYMBOL, H as STRUCTURAL_ONLY_SYMBOL, K as TEXTBLOCK_CONTENT_SYMBOL, O as LINK_DISPLAY_SYMBOL, St as FormReadOnly, Tt as FormSuggestionInput, U as STRUCTURAL_TYPE_SYMBOL, X as TextBlock, _t as FormNumberInput, at as FormAutoComplete, bt as FormProviderUserInput, ct as FormDateInput, d as isDeferredValue, dt as FormEmailInput, f as fieldAnnotation, ft as FormFileInput, g as isReadOnlyField, gt as FormMessage, h as hasStructuralOnlyAnnotation, ht as FormLookupInput, it as isMetricBreakdownOptions, k as LINK_TEXT_SYMBOL, l as DeferredValueTypeId, lt as FormDefault, m as hasFlattenAnnotation, mt as FormListInput, ot as FormCalendarSlotInput, p as fieldInputAst, pt as FormLabel, q as TEXTBLOCK_DYNAMIC_CONTENT_SYMBOL, rt as isListFieldMetadata, t as mapFormPropertySignature, tt as isFieldPermissionMetadata, u as FormDeferredContent, ut as FormDescription, vt as FormPermission, wt as FormStaticText, xt as FormRadioInput, y as CurrentProviderUser, yt as FormPhoneInput } from "./src-C-909PVQ.mjs";
2
- import { r as evaluateFormRules, t as formRuleConditionPaths } from "./paths-BkzLn-rG.mjs";
3
- import { _ as AuthenticationConfig, a as KeycloakOAuthProviderConfigSchema, c as OAuthProviderConfigSchema, d as SecretClientConfigSchema, f as SlackOAuthProviderConfigSchema, g as isCustomEntitiesConfig, h as CustomEntitiesConfig, i as GoogleOAuthProviderConfigSchema, l as OAuthProviderNameSchema, m as isPoliciesConfig, n as CognitoOAuthProviderConfigSchema, o as MicrosoftOAuthProviderConfigSchema, p as PoliciesConfig, r as DEFAULT_OAUTH_PROVIDER_SCOPES, s as OAUTH_PROVIDER_NAMES, t as AppleOAuthProviderConfigSchema, u as PasskeyProviderConfigSchema, v as isAuthenticationConfig } from "./auth-FmXptohB.mjs";
1
+ import { At as FormProviderUserInput, B as METRIC_BREAKDOWN_SYMBOL, C as CurrentProviderUser, D as FLATTEN_SYMBOL, N as LINK_TEXT_SYMBOL, Nt as FormRequired, P as LINK_URL_SYMBOL, Pt as FormStaticText, Z as TEXTBLOCK_CONTENT_SYMBOL, _ as hasFlattenAnnotation, _t as FormDefault, dt as FormAutoComplete, f as DeferredValueTypeId, g as fieldInputAst, h as fieldAnnotation, m as isDeferredValue, p as FormDeferredContent, pt as FormCalendarSlotInput, q as STRUCTURAL_ONLY_SYMBOL, tt as TextBlock, ut as isMetricBreakdownOptions, v as hasStructuralOnlyAnnotation, vt as FormDescription, wt as FormLookupInput, xt as FormLabel, y as isReadOnlyField } from "./src-BQ55-khF.mjs";
2
+ import { _ as AuthenticationConfig, a as KeycloakOAuthProviderConfigSchema, c as OAuthProviderConfigSchema, d as SecretClientConfigSchema, f as SlackOAuthProviderConfigSchema, g as isCustomEntitiesConfig, h as CustomEntitiesConfig, i as GoogleOAuthProviderConfigSchema, l as OAuthProviderNameSchema, m as isPoliciesConfig, n as CognitoOAuthProviderConfigSchema, o as MicrosoftOAuthProviderConfigSchema, p as PoliciesConfig, r as DEFAULT_OAUTH_PROVIDER_SCOPES, s as OAUTH_PROVIDER_NAMES, t as AppleOAuthProviderConfigSchema, u as PasskeyProviderConfigSchema, v as isAuthenticationConfig } from "./auth-DWWupwJA.mjs";
4
3
  import { Construct } from "constructs";
5
- import { Context, Data, Duration, Effect, Either, JSONSchema, Match, Option, Schema, SchemaAST, String as String$1 } from "effect";
4
+ import { Array as Array$1, Context, Data, Duration, Effect, Match, Option, Result, Schema, SchemaAST, SchemaGetter, String as String$1 } from "effect";
6
5
  import * as AST from "effect/SchemaAST";
7
- import { TitleAnnotationId } from "effect/SchemaAST";
8
- import { getMatchingPlugin } from "@processfocus/runtime";
9
6
  import DirectedGraph from "graphology";
10
- //#region ../process/src/lib/app-icons.ts
7
+ // ../process/src/lib/app-icons.ts
11
8
  const VALID_MANIFEST_ICON_PURPOSES = /* @__PURE__ */ new Set([
12
9
  "any",
13
10
  "maskable",
@@ -29,8 +26,7 @@ var AppIcons = class extends Construct {
29
26
  this.manifest = props.manifest ?? [];
30
27
  }
31
28
  };
32
- //#endregion
33
- //#region ../process/src/lib/brands.ts
29
+ // ../process/src/lib/brands.ts
34
30
  const hasBrand = (value, brand) => typeof value === "object" && value !== null && brand in value && value[brand] === true;
35
31
  const isDocumentStore = (value) => hasBrand(value, "isDocumentStore");
36
32
  const isForm = (value) => hasBrand(value, "isForm");
@@ -42,8 +38,7 @@ const isProcess = (value) => hasBrand(value, "isProcess");
42
38
  const isRole = (value) => hasBrand(value, "isRole");
43
39
  const isStatsView = (value) => hasBrand(value, "isStatsView");
44
40
  const isStep = (value) => hasBrand(value, "isStep");
45
- //#endregion
46
- //#region ../process/src/lib/document-store.ts
41
+ // ../process/src/lib/document-store.ts
47
42
  const DEFAULT_MAX_FILE_SIZE = 104857600;
48
43
  /**
49
44
  * A document store for file uploads and downloads.
@@ -74,8 +69,7 @@ var DocumentStore = class extends Construct {
74
69
  if (this.expirationDays !== void 0 && this.expirationDays < 1) throw new Error(`DocumentStore "${id}": expirationDays must be >= 1`);
75
70
  }
76
71
  };
77
- //#endregion
78
- //#region ../process/src/lib/execution-failure-notifications.ts
72
+ // ../process/src/lib/execution-failure-notifications.ts
79
73
  /**
80
74
  * Org-wide configuration for fatal execution failure notifications.
81
75
  */
@@ -87,8 +81,7 @@ var ExecutionFailureNotifications = class extends Construct {
87
81
  this.roles = props.roles ?? [];
88
82
  }
89
83
  };
90
- //#endregion
91
- //#region ../process/src/lib/flow-path.ts
84
+ // ../process/src/lib/flow-path.ts
92
85
  function assertSameProcess(step, process) {
93
86
  if (step.process !== process) throw new Error(`Step "${step.node.path}" belongs to a different process than "${process.node.path}"`);
94
87
  }
@@ -225,392 +218,7 @@ var ElseBranch = class {
225
218
  return this.step;
226
219
  }
227
220
  };
228
- //#endregion
229
- //#region ../form-client-representation/src/lib/extract-annotations.ts
230
- const toFullPath = (path) => path.startsWith("/") ? path : `/${path}`;
231
- const defaultSchemaTitles = /* @__PURE__ */ new Set([
232
- "any",
233
- "bigint",
234
- "string",
235
- "number",
236
- "boolean",
237
- "null",
238
- "never",
239
- "object",
240
- "symbol",
241
- "undefined",
242
- "unknown",
243
- "void"
244
- ]);
245
- const isGeneratedSchemaTitle = (value) => defaultSchemaTitles.has(value) || /^[a-z]+\(.*\)$/i.test(value);
246
- const humanizeFieldName = (fieldName) => {
247
- const spaced = fieldName.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").trim();
248
- if (spaced.length === 0) return fieldName;
249
- return `${spaced.charAt(0).toUpperCase()}${spaced.slice(1).toLowerCase()}`;
250
- };
251
- /**
252
- * Extract FormLabel, FormDescription, and FormReadOnly annotations from AST.
253
- * Note: FormDefault is handled separately at runtime when process state is available.
254
- */
255
- const extractAnnotations = (annotations, fieldName) => {
256
- const labelValue = annotations[FormLabel];
257
- const titleValue = annotations[TitleAnnotationId];
258
- const title = typeof titleValue === "string" && !isGeneratedSchemaTitle(titleValue) ? titleValue : void 0;
259
- const result = { label: typeof labelValue === "string" && labelValue.length > 0 ? labelValue : title ?? humanizeFieldName(fieldName) };
260
- const descValue = annotations[FormDescription];
261
- if (typeof descValue === "string") result.description = descValue;
262
- const autoCompleteValue = annotations[FormAutoComplete];
263
- if (typeof autoCompleteValue === "string") result.autoComplete = autoCompleteValue;
264
- const readOnlyValue = annotations[FormReadOnly];
265
- if (typeof readOnlyValue === "boolean") result.readonly = readOnlyValue;
266
- const permissionValue = annotations[FormPermission];
267
- if (isFieldPermissionMetadata(permissionValue)) result.permission = { modify: toFullPath(permissionValue.modify.node.path) };
268
- const requiredValue = annotations[FormRequired];
269
- if (typeof requiredValue === "boolean") result.required = requiredValue;
270
- const staticTextValue = annotations[FormStaticText];
271
- if (typeof staticTextValue === "string") result.content = staticTextValue;
272
- return result;
273
- };
274
- //#endregion
275
- //#region ../form-client-representation/src/lib/walker.ts
276
- /**
277
- * Error types for walker failures
278
- */
279
- var UnknownSchemaFieldTypeError = class extends Data.TaggedError("UnknownSchemaFieldTypeError") {
280
- get message() {
281
- return `Cannot create form field "${this.fieldName}": schema type "${this.schemaType}" is not supported`;
282
- }
283
- };
284
- var IndexSignaturesNotSupportedError = class extends Data.TaggedError("IndexSignaturesNotSupportedError") {
285
- get message() {
286
- return "Index signatures are not supported in schemas";
287
- }
288
- };
289
- var UnrecognizedASTNodeError = class extends Data.TaggedError("UnrecognizedASTNodeError") {
290
- get message() {
291
- return `AST node type "${this.nodeTag}" is not recognized`;
292
- }
293
- };
294
- var InvalidPropertyKeyError = class extends Data.TaggedError("InvalidPropertyKeyError") {
295
- get message() {
296
- return `Property keys must be strings or numbers, got: ${String(this.propertyKey)}`;
297
- }
298
- };
299
- var InvalidFieldPermissionError = class extends Data.TaggedError("InvalidFieldPermissionError") {
300
- get message() {
301
- return `Cannot apply field permission to "${this.fieldName}": ${this.reason}`;
302
- }
303
- };
304
- var InvalidStaticLinkError = class extends Data.TaggedError("InvalidStaticLinkError") {
305
- get message() {
306
- return `Cannot create link field "${this.fieldName}": url must use http, https, or mailto and text must be a string`;
307
- }
308
- };
309
- /**
310
- * Validates that a property key is not a symbol
311
- * Returns an Effect that fails if the key is a symbol
312
- */
313
- const validatePropertyKey = (propertyKey) => {
314
- if (typeof propertyKey === "symbol") return Effect.fail(new InvalidPropertyKeyError({ propertyKey }));
315
- return Effect.succeed(String(propertyKey));
316
- };
317
- /**
318
- * Main walker function that processes Effect Schema AST and emits form structure
319
- *
320
- * @param ast - The Effect Schema AST to walk
321
- * @param parentPath - Current path prefix for building field paths
322
- */
323
- const walkAST = (ast, parentPath = "", nestingDepth = 0) => Match.type().pipe(Match.tag("Transformation", (transformation) => walkAST(transformation.from, parentPath, nestingDepth)), Match.tag("TypeLiteral", (typeLiteral) => Effect.gen(function* () {
324
- const result = {};
325
- for (const prop of typeLiteral.propertySignatures) {
326
- const fieldName = yield* validatePropertyKey(prop.name);
327
- result[fieldName] = yield* processProperty(prop, parentPath, nestingDepth);
328
- }
329
- if (typeLiteral.indexSignatures.length > 0) return yield* new IndexSignaturesNotSupportedError();
330
- return result;
331
- })), Match.orElse((node) => Effect.fail(new UnrecognizedASTNodeError({ nodeTag: node._tag }))))(ast);
332
- /**
333
- * Process a single property signature from the schema
334
- */
335
- const processProperty = (prop, parentPath, nestingDepth) => Effect.gen(function* () {
336
- const fieldName = yield* validatePropertyKey(prop.name);
337
- const fieldPath = {
338
- ...prop.type.annotations,
339
- ...prop.annotations
340
- }[FLATTEN_SYMBOL] ? parentPath : parentPath ? `${parentPath}.${fieldName}` : fieldName;
341
- return yield* processType(prop.type, prop.annotations, fieldName, fieldPath, prop.isOptional, nestingDepth);
342
- });
343
- const hasModifyPermission = (annotations) => {
344
- return isFieldPermissionMetadata(annotations[FormPermission]);
345
- };
346
- const hasDefault = (annotations) => annotations[FormDefault] !== void 0;
347
- const validatePermissionPlacement = (annotations, fieldName, isOptional, nestingDepth) => {
348
- if (!hasModifyPermission(annotations)) return Effect.void;
349
- if (nestingDepth > 0) return Effect.fail(new InvalidFieldPermissionError({
350
- fieldName,
351
- reason: "permissions are only supported on top-level submitted fields"
352
- }));
353
- if (annotations[FormReadOnly] === true) return Effect.fail(new InvalidFieldPermissionError({
354
- fieldName,
355
- reason: "read-only fields cannot declare modify permissions"
356
- }));
357
- if (!isOptional && !hasDefault(annotations)) return Effect.fail(new InvalidFieldPermissionError({
358
- fieldName,
359
- reason: "restricted required fields must either be optional or declare a default value"
360
- }));
361
- return Effect.void;
362
- };
363
- const rejectPermission = (annotations, fieldName, reason) => hasModifyPermission(annotations) ? Effect.fail(new InvalidFieldPermissionError({
364
- fieldName,
365
- reason
366
- })) : Effect.void;
367
- /**
368
- * Process an AST type node and return the corresponding form component
369
- */
370
- const processType = (type, annotations, fieldName, fieldPath, isOptional, nestingDepth) => {
371
- const mergedAnnotations = {
372
- ...type.annotations,
373
- ...annotations
374
- };
375
- const metadata = extractAnnotations(mergedAnnotations, fieldName);
376
- if (mergedAnnotations[FormRadioInput]) {
377
- const radioMeta = mergedAnnotations[FormRadioInput];
378
- return validatePermissionPlacement(mergedAnnotations, fieldName, isOptional, nestingDepth).pipe(Effect.as({
379
- field: fieldPath,
380
- _tag: "radio",
381
- ...metadata,
382
- options: radioMeta.options
383
- }));
384
- }
385
- const matchedPlugin = getMatchingPlugin(mergedAnnotations);
386
- if (matchedPlugin) return rejectPermission(mergedAnnotations, fieldName, "plugin field permissions are not supported").pipe(Effect.andThen(Effect.succeed({
387
- field: fieldPath,
388
- _tag: "plugin",
389
- pluginType: matchedPlugin.type,
390
- pluginData: matchedPlugin.extractData?.(mergedAnnotations),
391
- ...matchedPlugin.scripts !== void 0 && { scripts: matchedPlugin.scripts },
392
- ...metadata
393
- })));
394
- return Match.type().pipe(Match.tag("StringKeyword", () => {
395
- if (typeof mergedAnnotations[FormStaticText] === "string") return rejectPermission(mergedAnnotations, fieldName, "static fields cannot declare permissions").pipe(Effect.andThen(Effect.succeed({
396
- field: fieldPath,
397
- _tag: "static",
398
- ...metadata
399
- })));
400
- const validPermission = validatePermissionPlacement(mergedAnnotations, fieldName, isOptional, nestingDepth);
401
- if (mergedAnnotations[FormProviderUserInput]) return validPermission.pipe(Effect.andThen(Effect.succeed({
402
- field: fieldPath,
403
- _tag: "provider-user",
404
- ...metadata
405
- })));
406
- if (mergedAnnotations[FormLookupInput]) return validPermission.pipe(Effect.andThen(Effect.succeed({
407
- field: fieldPath,
408
- _tag: "lookup",
409
- ...metadata,
410
- ...mergedAnnotations[FormSuggestionInput] === true && { allowFreeText: true }
411
- })));
412
- if (mergedAnnotations[FormCalendarSlotInput]) {
413
- const slotMeta = mergedAnnotations[FormCalendarSlotInput];
414
- return validPermission.pipe(Effect.andThen(Effect.succeed({
415
- field: fieldPath,
416
- _tag: "calendar-slot",
417
- ...metadata,
418
- timeZone: slotMeta.timeZone,
419
- locale: slotMeta.locale,
420
- ...slotMeta.calendar != null && { calendar: slotMeta.calendar },
421
- ...slotMeta.emptyMessageHtml != null && { emptyMessageHtml: slotMeta.emptyMessageHtml },
422
- ...slotMeta.loadErrorMessageHtml != null && { loadErrorMessageHtml: slotMeta.loadErrorMessageHtml }
423
- })));
424
- }
425
- if (mergedAnnotations[FormFileInput]) {
426
- const fileMeta = mergedAnnotations[FormFileInput];
427
- return validPermission.pipe(Effect.andThen(Effect.succeed({
428
- field: fieldPath,
429
- _tag: "file",
430
- ...metadata,
431
- documentStore: fileMeta.documentStore,
432
- ...fileMeta.accept != null && { accept: fileMeta.accept },
433
- ...fileMeta.maxSize != null && { maxSize: fileMeta.maxSize }
434
- })));
435
- }
436
- let fieldType;
437
- if (mergedAnnotations[FormTextAreaInput]) fieldType = "textarea";
438
- else if (mergedAnnotations[FormDateInput]) fieldType = "date";
439
- else if (mergedAnnotations[FormEmailInput]) fieldType = "email";
440
- else if (mergedAnnotations[FormPhoneInput]) fieldType = "phone";
441
- else if (mergedAnnotations[FormNumberInput]) fieldType = "number";
442
- else fieldType = "text";
443
- return validPermission.pipe(Effect.andThen(Effect.succeed({
444
- field: fieldPath,
445
- _tag: fieldType,
446
- ...metadata
447
- })));
448
- }), Match.tag("NumberKeyword", () => validatePermissionPlacement(mergedAnnotations, fieldName, isOptional, nestingDepth).pipe(Effect.andThen(Effect.succeed({
449
- field: fieldPath,
450
- _tag: "number",
451
- ...metadata
452
- })))), Match.tag("Literal", (literal) => {
453
- if (typeof literal.literal !== "string") return Effect.fail(new UnknownSchemaFieldTypeError({
454
- fieldName,
455
- schemaType: type._tag
456
- }));
457
- return validatePermissionPlacement(mergedAnnotations, fieldName, isOptional, nestingDepth).pipe(Effect.as({
458
- ...metadata,
459
- _tag: "select",
460
- field: fieldPath,
461
- options: [literal.literal],
462
- ...isOptional ? { emptyValue: "undefined" } : {}
463
- }));
464
- }), Match.tag("BooleanKeyword", () => validatePermissionPlacement(mergedAnnotations, fieldName, isOptional, nestingDepth).pipe(Effect.andThen(Effect.succeed({
465
- field: fieldPath,
466
- _tag: "boolean",
467
- ...metadata
468
- })))), Match.tag("TypeLiteral", (typeLiteral) => rejectPermission(mergedAnnotations, fieldName, "wrapper-level and fieldset-level permissions are not supported").pipe(Effect.andThen(walkAST(typeLiteral, fieldPath, nestingDepth + 1).pipe(Effect.map((children) => ({
469
- _tag: "fieldset",
470
- ...metadata,
471
- children
472
- })))))), Match.tag("TupleType", (tuple) => {
473
- const restType = tuple.rest[0];
474
- const listMetadata = mergedAnnotations[FormListInput];
475
- if (!restType) return Effect.fail(new UnknownSchemaFieldTypeError({
476
- fieldName,
477
- schemaType: "TupleType (empty)"
478
- }));
479
- return rejectPermission(mergedAnnotations, fieldName, "list permissions are not supported").pipe(Effect.andThen(walkAST(restType.type, fieldPath, nestingDepth + 1).pipe(Effect.map((itemChildren) => ({
480
- _tag: mergedAnnotations[FormTableInput] ? "table" : "list",
481
- field: fieldPath,
482
- ...metadata,
483
- ...isListFieldMetadata(listMetadata) && listMetadata.addButtonLabel !== void 0 && { addButtonLabel: listMetadata.addButtonLabel },
484
- itemChildren
485
- })))));
486
- }), Match.tag("Refinement", (refinement) => processType(refinement.from, {
487
- ...annotations,
488
- ...refinement.annotations
489
- }, fieldName, fieldPath, isOptional, nestingDepth)), Match.tag("Transformation", (transformation) => processType(transformation.from, {
490
- ...annotations,
491
- ...transformation.annotations
492
- }, fieldName, fieldPath, isOptional, nestingDepth)), Match.tag("Union", (union) => {
493
- const nonNullMembers = union.types.filter((t) => !(t._tag === "Literal" && t.literal === null) && t._tag !== "UndefinedKeyword");
494
- const emptyValue = union.types.some((member) => member._tag === "Literal" && member.literal === null) ? "null" : isOptional || union.types.some((member) => member._tag === "UndefinedKeyword") ? "undefined" : void 0;
495
- if (nonNullMembers.length === 1 && nonNullMembers[0]) return processType(nonNullMembers[0], {
496
- ...annotations,
497
- ...union.annotations
498
- }, fieldName, fieldPath, isOptional, nestingDepth).pipe(Effect.map((component) => component._tag === "select" && emptyValue !== void 0 ? {
499
- ...component,
500
- emptyValue
501
- } : component));
502
- const options = nonNullMembers.flatMap((member) => member._tag === "Literal" && typeof member.literal === "string" ? [member.literal] : []);
503
- if (options.length > 0 && options.length === nonNullMembers.length) return validatePermissionPlacement(mergedAnnotations, fieldName, isOptional, nestingDepth).pipe(Effect.as({
504
- ...metadata,
505
- _tag: "select",
506
- field: fieldPath,
507
- options,
508
- ...emptyValue !== void 0 ? { emptyValue } : {}
509
- }));
510
- return Effect.fail(new UnknownSchemaFieldTypeError({
511
- fieldName,
512
- schemaType: type._tag
513
- }));
514
- }), Match.tag("UndefinedKeyword", () => {
515
- const structuralAnnotation = AST.getAnnotation(type, STRUCTURAL_ONLY_SYMBOL);
516
- if (Option.isSome(structuralAnnotation)) return rejectPermission(mergedAnnotations, fieldName, "structural-only fields cannot declare permissions").pipe(Effect.andThen(() => {
517
- const structuralTypeAnnotation = AST.getAnnotation(type, STRUCTURAL_TYPE_SYMBOL);
518
- const structuralType = Option.getOrUndefined(structuralTypeAnnotation);
519
- if (structuralType === "metric-breakdown") {
520
- const metricAnnotation = AST.getAnnotation(type, METRIC_BREAKDOWN_SYMBOL);
521
- const options = Option.getOrUndefined(metricAnnotation);
522
- if (isMetricBreakdownOptions(options)) return Effect.succeed({
523
- field: fieldPath,
524
- _tag: "metric-breakdown",
525
- label: metadata.label,
526
- readonly: true,
527
- title: options.title,
528
- buckets: options.buckets,
529
- ...options.badge !== void 0 && { badge: options.badge },
530
- ...options.currency !== void 0 && { currency: options.currency },
531
- ...options.fields !== void 0 && { fields: options.fields },
532
- ...options.controls !== void 0 && { controls: options.controls },
533
- ...options.contextFields !== void 0 && { contextFields: options.contextFields },
534
- ...options.dataSource !== void 0 && { dataSource: options.dataSource },
535
- ...options.rendererPluginType !== void 0 && { rendererPluginType: options.rendererPluginType },
536
- ...options.rendererPluginData !== void 0 && { rendererPluginData: options.rendererPluginData }
537
- });
538
- }
539
- if (structuralType === "link") {
540
- const url = mergedAnnotations[LINK_URL_SYMBOL];
541
- const text = mergedAnnotations[LINK_TEXT_SYMBOL];
542
- const display = mergedAnnotations[LINK_DISPLAY_SYMBOL];
543
- const color = mergedAnnotations[LINK_COLOR_SYMBOL];
544
- const isButtonLink = display === "button";
545
- if (typeof url === "string" && /^(https?:|mailto:)/.test(url) && typeof text === "string") return Effect.succeed({
546
- field: fieldPath,
547
- _tag: "link",
548
- readonly: true,
549
- url,
550
- text,
551
- ...isButtonLink ? { display } : { label: metadata.label },
552
- ...color === "blue" ? { color } : {}
553
- });
554
- return Effect.fail(new InvalidStaticLinkError({
555
- fieldName: fieldPath,
556
- url,
557
- text
558
- }));
559
- }
560
- const contentAnnotation = AST.getAnnotation(type, TEXTBLOCK_CONTENT_SYMBOL);
561
- const content = Option.getOrUndefined(contentAnnotation);
562
- return Effect.succeed({
563
- field: fieldPath,
564
- _tag: "static",
565
- label: metadata.label,
566
- description: metadata.description,
567
- readonly: true,
568
- content
569
- });
570
- }));
571
- return Effect.fail(new UnknownSchemaFieldTypeError({
572
- fieldName,
573
- schemaType: type._tag
574
- }));
575
- }), Match.orElse(() => Effect.fail(new UnknownSchemaFieldTypeError({
576
- fieldName,
577
- schemaType: type._tag
578
- }))))(type);
579
- };
580
- //#endregion
581
- //#region ../form-client-representation/src/lib/as-client-representation.ts
582
- /**
583
- * Convert an Effect Schema.Struct to its client-side form representation
584
- *
585
- * This function walks the schema's AST and generates a typed structure
586
- * that mirrors the schema's type shape, with each field mapped to its
587
- * corresponding form component (TextField, NumberField, etc.).
588
- *
589
- * **IMPORTANT**: Only Schema.Struct is supported. The type system prevents
590
- * passing any other schema type at compile time.
591
- *
592
- * @param schema - The Effect Schema.Struct to convert
593
- * @returns An Effect that produces the client representation
594
- *
595
- * @example
596
- * ```typescript
597
- * const schema = Schema.Struct({
598
- * username: Schema.String,
599
- * age: Schema.NumberFromString,
600
- * })
601
- *
602
- * const representation = await Effect.runPromise(asClientRepresentation(schema))
603
- * // {
604
- * // username: { field: "username", type: "text", label: "Username", ... },
605
- * // age: { field: "age", _tag: "number", label: "Age", ... }
606
- * // }
607
- * ```
608
- */
609
- const asClientRepresentation = (schema) => {
610
- return walkAST(schema.ast);
611
- };
612
- //#endregion
613
- //#region ../form-submission-schema/src/lib/form-submission-schema.ts
221
+ // ../form-submission-schema/src/lib/form-submission-schema.ts
614
222
  var FieldNameCollisionError = class extends Data.TaggedError("FieldNameCollisionError") {
615
223
  get message() {
616
224
  return `Field name collision: "${this.wrapperField}" is already present as "${this.fieldName}" in its parent struct`;
@@ -623,7 +231,7 @@ var InvalidFlattenAnnotationError = class extends Data.TaggedError("InvalidFlatt
623
231
  };
624
232
  const isFlattenableStruct = (field, fieldName) => Effect.gen(function* () {
625
233
  const hasFlatten = hasFlattenAnnotation(field);
626
- const isStructAst = field.ast._tag === "TypeLiteral";
234
+ const isStructAst = field.ast._tag === "Objects";
627
235
  if (hasFlatten && !isStructAst) return yield* new InvalidFlattenAnnotationError({
628
236
  fieldName,
629
237
  astTag: field.ast._tag
@@ -657,23 +265,18 @@ const submissionSchema = (schema) => Effect.gen(function* () {
657
265
  return Schema.Struct(flatFields);
658
266
  });
659
267
  /** Rebuild signatures without losing intrinsic defaults, key mappings or codecs. */
660
- const projectField = (field) => Effect.gen(function* () {
661
- if (!Schema.isPropertySignature(field)) return Schema.make(yield* projectNested(field.ast));
662
- const signature = field.ast;
663
- const input = yield* projectNested(signature._tag === "PropertySignatureDeclaration" ? signature.type : signature.from.type);
664
- const output = signature._tag === "PropertySignatureDeclaration" ? input : yield* projectNested(signature.to.type);
665
- return mapFormPropertySignature(field, (_ast, side) => side === "input" ? input : output);
666
- });
268
+ const projectField = (field) => Effect.map(projectNested(field.ast), (ast) => Schema.make(ast));
667
269
  const projectNested = (ast) => Effect.gen(function* () {
668
- if (ast._tag === "TypeLiteral") {
270
+ const encoding = ast.encoding ? yield* Effect.forEach(ast.encoding, (link) => Effect.map(projectNested(link.to), (to) => new SchemaAST.Link(to, link.transformation))) : void 0;
271
+ if (ast._tag === "Objects") {
669
272
  const properties = [];
670
273
  const names = /* @__PURE__ */ new Set();
671
274
  for (const property of ast.propertySignatures) {
672
- const field = Schema.make(SchemaAST.annotations(property.type, property.annotations));
275
+ const field = Schema.make(property.type);
673
276
  if (hasStructuralOnlyAnnotation(field) || isReadOnlyField(field)) continue;
674
277
  const flatten = yield* isFlattenableStruct(field, String(property.name));
675
278
  const projected = yield* projectNested(property.type);
676
- const children = flatten && projected._tag === "TypeLiteral" ? projected.propertySignatures : [new SchemaAST.PropertySignature(property.name, projected, property.isOptional, property.isReadonly, property.annotations)];
279
+ const children = flatten && projected._tag === "Objects" ? projected.propertySignatures : [new SchemaAST.PropertySignature(property.name, projected)];
677
280
  for (const child of children) {
678
281
  if (names.has(child.name)) return yield* new FieldNameCollisionError({
679
282
  fieldName: String(child.name),
@@ -683,37 +286,26 @@ const projectNested = (ast) => Effect.gen(function* () {
683
286
  properties.push(child);
684
287
  }
685
288
  }
686
- return new SchemaAST.TypeLiteral(properties, ast.indexSignatures, ast.annotations);
687
- }
688
- if (ast._tag === "Union") return SchemaAST.Union.make(yield* Effect.forEach(ast.types, projectNested), ast.annotations);
689
- if (ast._tag === "Refinement") return new SchemaAST.Refinement(yield* projectNested(ast.from), ast.filter, ast.annotations);
690
- if (ast._tag === "Transformation") {
691
- const from = yield* projectNested(ast.from);
692
- const to = yield* projectNested(ast.to);
693
- const transformation = ast.transformation._tag === "TypeLiteralTransformation" && from._tag === "TypeLiteral" && to._tag === "TypeLiteral" ? new SchemaAST.TypeLiteralTransformation(ast.transformation.propertySignatureTransformations.filter((property) => from.propertySignatures.some((p) => p.name === property.from) && to.propertySignatures.some((p) => p.name === property.to))) : ast.transformation;
694
- return new SchemaAST.Transformation(from, to, transformation, ast.annotations);
695
- }
696
- if (ast._tag === "TupleType") {
697
- const elements = yield* Effect.forEach(ast.elements, (element) => projectNested(element.type).pipe(Effect.map((type) => new SchemaAST.OptionalType(type, element.isOptional, element.annotations))));
698
- const rest = yield* Effect.forEach(ast.rest, (element) => projectNested(element.type).pipe(Effect.map((type) => new SchemaAST.Type(type, element.annotations))));
699
- return new SchemaAST.TupleType(elements, rest, ast.isReadonly, ast.annotations);
700
- }
701
- return ast;
289
+ return new SchemaAST.Objects(properties, ast.indexSignatures, ast.annotations, ast.checks, encoding, ast.context, ast.encodingChecks);
290
+ }
291
+ if (ast._tag === "Union") return new SchemaAST.Union(yield* Effect.forEach(ast.types, projectNested), ast.options, ast.annotations, ast.checks, encoding, ast.context, ast.encodingChecks);
292
+ if (ast._tag === "Arrays") return new SchemaAST.Arrays(ast.isMutable, yield* Effect.forEach(ast.elements, projectNested), yield* Effect.forEach(ast.rest, projectNested), ast.annotations, ast.checks, encoding, ast.context, ast.encodingChecks);
293
+ return encoding ? Object.assign(Object.create(Object.getPrototypeOf(ast)), ast, { encoding }) : ast;
702
294
  });
703
295
  /**
704
296
  * Synchronous boundary for model construction and other non-Effect call sites.
705
297
  * Rethrows the original TaggedError on failure (not a FiberFailure wrapper).
706
298
  */
707
299
  const submissionSchemaSync = (schema) => {
708
- const result = Effect.runSync(Effect.either(submissionSchema(schema)));
709
- if (Either.isLeft(result)) throw result.left;
710
- return result.right;
300
+ const result = Effect.runSync(Effect.result(submissionSchema(schema)));
301
+ if (Result.isFailure(result)) throw result.failure;
302
+ return result.success;
711
303
  };
712
304
  const expansionCache = /* @__PURE__ */ new WeakMap();
713
305
  const prepareExpansion = (source) => Effect.gen(function* () {
714
306
  const cached = expansionCache.get(source);
715
307
  if (cached) return cached;
716
- const ast = source;
308
+ const ast = SchemaAST.toEncoded(source);
717
309
  const members = /* @__PURE__ */ new Map();
718
310
  const visit = (node) => Effect.gen(function* () {
719
311
  if (node._tag === "Union") members.set(node, yield* Effect.forEach(node.types, (member) => Effect.gen(function* () {
@@ -721,15 +313,14 @@ const prepareExpansion = (source) => Effect.gen(function* () {
721
313
  yield* visit(member);
722
314
  return {
723
315
  ast: member,
724
- matches: Schema.is(Schema.encodedSchema(Schema.make(projected)))
316
+ matches: Schema.is(Schema.toEncoded(Schema.make(projected)))
725
317
  };
726
318
  })));
727
- else if (node._tag === "TypeLiteral") yield* Effect.forEach(node.propertySignatures, (property) => {
728
- const field = Schema.make(SchemaAST.annotations(property.type, property.annotations));
319
+ else if (node._tag === "Objects") yield* Effect.forEach(node.propertySignatures, (property) => {
320
+ const field = Schema.make(property.type);
729
321
  return hasStructuralOnlyAnnotation(field) || isReadOnlyField(field) ? Effect.void : visit(property.type);
730
322
  });
731
- else if (node._tag === "TupleType") yield* Effect.forEach([...node.elements, ...node.rest], (element) => visit(element.type));
732
- else if (node._tag === "Refinement" || node._tag === "Transformation") yield* visit(node.from);
323
+ else if (node._tag === "Arrays") yield* Effect.forEach([...node.elements, ...node.rest], (element) => visit(element));
733
324
  });
734
325
  yield* visit(ast);
735
326
  const prepared = {
@@ -739,8 +330,131 @@ const prepareExpansion = (source) => Effect.gen(function* () {
739
330
  expansionCache.set(source, prepared);
740
331
  return prepared;
741
332
  });
742
- //#endregion
743
- //#region ../form-submission-schema/src/lib/schema-defaults.ts
333
+ // ../form-submission-schema/src/lib/executable-rules.ts
334
+ const rulesAnnotation = Symbol.for("pf/form/executable-rules");
335
+ const record$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
336
+ const at = (value, path) => {
337
+ for (const key of path) if (Array.isArray(value)) value = value[Number(key)];
338
+ else if (record$1(value)) value = value[key];
339
+ else return void 0;
340
+ return value;
341
+ };
342
+ const set = (value, path, item) => {
343
+ const [key, ...rest] = path;
344
+ if (key === void 0) return;
345
+ if (Array.isArray(value)) {
346
+ const index = Number(key);
347
+ if (rest.length === 0) value[index] = item;
348
+ else {
349
+ const child = value[index];
350
+ if (record$1(child) || Array.isArray(child)) set(child, rest, item);
351
+ }
352
+ return;
353
+ }
354
+ if (rest.length === 0) {
355
+ if (item === void 0) delete value[key];
356
+ else value[key] = item;
357
+ return;
358
+ }
359
+ const child = value[key];
360
+ if (record$1(child) || Array.isArray(child)) set(child, rest, item);
361
+ else if (item !== void 0) {
362
+ const nested = {};
363
+ value[key] = nested;
364
+ set(nested, rest, item);
365
+ }
366
+ };
367
+ const struct = (ast) => {
368
+ if (ast._tag === "Objects") return ast;
369
+ if (ast._tag === "Union") for (const member of ast.types) {
370
+ const found = struct(member);
371
+ if (found) return found;
372
+ }
373
+ };
374
+ /** Invalid controlling values are unavailable, without rewriting raw editing state. */
375
+ const normalize = (schema, input) => {
376
+ const result = Schema.decodeUnknownResult(Schema.make(schema.ast))(input);
377
+ if (Result.isSuccess(result)) return result.success;
378
+ const nested = struct(schema.ast);
379
+ if (!nested || !record$1(input)) return void 0;
380
+ return Object.fromEntries(nested.propertySignatures.map((property) => [String(property.name), normalize(Schema.make(property.type), input[String(property.name)])]));
381
+ };
382
+ const executableFields = (schema, input, inaccessible = [], originals) => {
383
+ const declared = Reflect.get(schema.ast.annotations ?? {}, rulesAnnotation);
384
+ const rules = Array.isArray(declared) ? declared.filter((rule) => typeof rule === "function") : [];
385
+ const applicable = structuredClone(input);
386
+ for (const name of inaccessible) set(applicable, name.split("."), void 0);
387
+ const normalized = normalize(submissionSchemaSync(schema), applicable);
388
+ if (record$1(normalized)) for (const name of inaccessible) set(normalized, name.split("."), void 0);
389
+ const effects = rules.map((rule) => rule(record$1(normalized) ? normalized : {}));
390
+ const fields = [];
391
+ const walk = (ast, path, target, inherited, excluded = false, absentContainer = false) => {
392
+ const encoded = SchemaAST.toEncoded(ast.ast);
393
+ const intrinsicRequired = rules.length > 0 && !encoded.context?.isOptional && encoded._tag !== "Undefined" && encoded._tag !== "Null" && !(encoded._tag === "Union" && encoded.types.some((member) => member._tag === "Undefined" || member._tag === "Null"));
394
+ let state = {};
395
+ for (const effect of effects) {
396
+ const entry = at(effect, target);
397
+ if (!record$1(entry)) continue;
398
+ const own = record$1(entry["$self"]) ? entry["$self"] : entry;
399
+ state = {
400
+ ...state,
401
+ ...typeof own["hidden"] === "boolean" ? { hidden: own["hidden"] } : {},
402
+ ...typeof own["disabled"] === "boolean" ? { disabled: own["disabled"] } : {},
403
+ ...typeof own["required"] === "boolean" ? { required: own["required"] } : {},
404
+ ...typeof own["label"] === "string" ? { label: own["label"] } : {}
405
+ };
406
+ }
407
+ state = {
408
+ ...state,
409
+ ...inherited.hidden || inaccessible.some((name) => path.join(".") === name || path.join(".").startsWith(`${name}.`)) ? { hidden: true } : {},
410
+ ...inherited.disabled ? { disabled: true } : {},
411
+ ...fieldAnnotation(ast.ast, FormRequired) === true || intrinsicRequired && !absentContainer ? { required: true } : {}
412
+ };
413
+ const nested = struct(ast.ast);
414
+ const value = at(state.disabled && originals ? originals : input, path);
415
+ const display = excluded || hasStructuralOnlyAnnotation(ast) || isReadOnlyField(ast);
416
+ fields.push({
417
+ path,
418
+ target,
419
+ schema: ast,
420
+ state,
421
+ kind: display ? "display" : nested ? "container" : "input"
422
+ });
423
+ if (nested) for (const property of nested.propertySignatures) {
424
+ const child = Schema.make(property.type);
425
+ const name = String(property.name);
426
+ walk(Schema.make(child.ast), hasFlattenAnnotation(child) ? path : [...path, name], [...target, name], state, display, absentContainer || !hasFlattenAnnotation(ast) && !intrinsicRequired && value == null);
427
+ }
428
+ const array = encoded._tag === "Arrays" ? encoded : encoded._tag === "Union" ? encoded.types.find((member) => member._tag === "Arrays") : void 0;
429
+ const items = value;
430
+ if (array?._tag === "Arrays" && Array.isArray(items)) for (const [index] of items.entries()) {
431
+ const item = array.elements[index] ?? array.rest[0];
432
+ const children = item && struct(item);
433
+ if (!children) continue;
434
+ for (const property of children.propertySignatures) {
435
+ const name = String(property.name);
436
+ const child = Schema.make(property.type);
437
+ const itemPath = [...path, String(index)];
438
+ walk(child, hasFlattenAnnotation(child) ? itemPath : [...itemPath, name], [...target, name], state, display, absentContainer);
439
+ }
440
+ }
441
+ };
442
+ for (const [name, child] of Object.entries(schema.fields)) walk(Schema.make(child.ast), hasFlattenAnnotation(child) ? [] : [name], [name], {});
443
+ return fields;
444
+ };
445
+ /** Stored process values are decoded; authored defaults are already encoded. */
446
+ const executableOriginalValues = (schema, defaults, state = {}) => {
447
+ const values = structuredClone(defaults);
448
+ for (const field of executableFields(schema, defaults)) {
449
+ if (field.kind !== "input") continue;
450
+ const original = at(state, field.path);
451
+ if (original === void 0) continue;
452
+ const encoded = Schema.encodeUnknownResult(Schema.make(field.schema.ast))(original);
453
+ set(values, field.path, Result.isSuccess(encoded) ? encoded.success : original);
454
+ }
455
+ return values;
456
+ };
457
+ // ../form-submission-schema/src/lib/schema-defaults.ts
744
458
  /**
745
459
  * Generate type-compatible default values from Effect Schema fields.
746
460
  *
@@ -754,31 +468,29 @@ const getSchemaDefaults = (fields) => {
754
468
  for (const [key, fieldSchema] of Object.entries(fields)) {
755
469
  const schema = fieldSchema;
756
470
  if (hasStructuralOnlyAnnotation(schema) || isReadOnlyField(schema)) continue;
757
- if (hasFlattenAnnotation(schema) && schema.ast._tag === "TypeLiteral") {
758
- Object.assign(result, getDefaultsForTypeLiteral(schema.ast));
471
+ if (hasFlattenAnnotation(schema) && schema.ast._tag === "Objects") {
472
+ Object.assign(result, getDefaultsForObjects(schema.ast));
759
473
  continue;
760
474
  }
761
- const ast = fieldSchema.ast;
762
- if (ast._tag === "PropertySignatureDeclaration") result[key] = getDefaultForSchema(ast.type, ast.isOptional);
763
- else if (ast._tag === "PropertySignatureTransformation") result[key] = getDefaultForSchema(ast.from.type, ast.from.isOptional);
764
- else result[key] = getDefaultForSchema(ast);
475
+ const ast = AST.toEncoded(fieldSchema.ast);
476
+ result[key] = getDefaultForSchema(ast, ast.context?.isOptional);
765
477
  }
766
478
  return result;
767
479
  };
768
- const getDefaultsForTypeLiteral = (typeLiteral) => {
480
+ const getDefaultsForObjects = (typeLiteral) => {
769
481
  const result = {};
770
482
  for (const prop of typeLiteral.propertySignatures) {
771
483
  const key = String(prop.name);
772
484
  const fieldSchema = prop.type;
773
485
  const fieldAsSchema = { ast: fieldSchema };
774
486
  if (hasStructuralOnlyAnnotation(fieldAsSchema) || isReadOnlyField(fieldAsSchema)) continue;
775
- if (fieldSchema._tag === "TypeLiteral") {
487
+ if (fieldSchema._tag === "Objects") {
776
488
  if (hasFlattenAnnotation(fieldAsSchema)) {
777
- Object.assign(result, getDefaultsForTypeLiteral(fieldSchema));
489
+ Object.assign(result, getDefaultsForObjects(fieldSchema));
778
490
  continue;
779
491
  }
780
492
  }
781
- result[key] = getDefaultForSchema(fieldSchema, prop.isOptional);
493
+ result[key] = getDefaultForSchema(fieldSchema, prop.type.context?.isOptional);
782
494
  }
783
495
  return result;
784
496
  };
@@ -787,22 +499,28 @@ const unionMembers = (ast) => ast._tag === "Union" ? ast.types.flatMap(unionMemb
787
499
  * Get default value for a single schema AST node
788
500
  */
789
501
  const getDefaultForSchema = (ast, isOptional = false) => {
790
- return Match.type().pipe(Match.tag("StringKeyword", () => ""), Match.tag("NumberKeyword", () => 0), Match.tag("BooleanKeyword", () => false), Match.tag("Refinement", (refinement) => getDefaultForSchema(refinement.from, isOptional)), Match.tag("Transformation", (transformation) => getDefaultForSchema(transformation.from, isOptional)), Match.tag("Literal", (literal) => isOptional && typeof literal.literal === "string" ? void 0 : ""), Match.tag("Union", (union) => {
502
+ const lookup = fieldAnnotation(ast, FormLookupInput);
503
+ if (typeof lookup === "object" && lookup !== null && "mode" in lookup && (lookup.mode === "server" || lookup.mode === "local")) {
504
+ const members = unionMembers(AST.toEncoded(ast));
505
+ if (isOptional || members.some((member) => member._tag === "Undefined")) return void 0;
506
+ if (members.some((member) => member._tag === "Null")) return null;
507
+ }
508
+ return Match.type().pipe(Match.tag("String", () => ""), Match.tag("Number", () => 0), Match.tag("Boolean", () => false), Match.tag("Literal", (literal) => isOptional && typeof literal.literal === "string" ? void 0 : ""), Match.tag("Union", (union) => {
791
509
  const members = unionMembers(union);
792
- const choices = members.filter((member) => member._tag !== "UndefinedKeyword" && !(member._tag === "Literal" && member.literal === null));
510
+ if (members.some((member) => member._tag === "Boolean") && members.every((member) => member._tag === "Boolean" || member._tag === "Undefined")) return false;
511
+ const choices = members.filter((member) => member._tag !== "Undefined" && !(member._tag === "Null"));
793
512
  if (choices.length > 0 && choices.every((member) => member._tag === "Literal" && typeof member.literal === "string")) {
794
- if (members.some((member) => member._tag === "Literal" && member.literal === null)) return null;
795
- if (isOptional || members.some((member) => member._tag === "UndefinedKeyword")) return;
513
+ if (members.some((member) => member._tag === "Null")) return null;
514
+ if (isOptional || members.some((member) => member._tag === "Undefined")) return;
796
515
  }
797
516
  return "";
798
- }), Match.tag("TypeLiteral", (typeLiteral) => {
517
+ }), Match.tag("Objects", (typeLiteral) => {
799
518
  const nestedResult = {};
800
- for (const prop of typeLiteral.propertySignatures) nestedResult[String(prop.name)] = getDefaultForSchema(prop.type, prop.isOptional);
519
+ for (const prop of typeLiteral.propertySignatures) nestedResult[String(prop.name)] = getDefaultForSchema(prop.type, prop.type.context?.isOptional);
801
520
  return nestedResult;
802
- }), Match.tag("TupleType", () => []), Match.orElse(() => ""))(ast);
521
+ }), Match.tag("Arrays", () => []), Match.orElse(() => ""))(AST.toEncoded(ast));
803
522
  };
804
- //#endregion
805
- //#region ../process/src/lib/form-decoration.ts
523
+ // ../process/src/lib/form-decoration.ts
806
524
  var FormDecorationError = class extends Data.TaggedError("FormDecorationError") {};
807
525
  const fail$1 = (path, message) => {
808
526
  throw new FormDecorationError({
@@ -825,7 +543,7 @@ const calendarResult = Schema.Array(Schema.Struct({
825
543
  endsAt: Schema.String,
826
544
  label: Schema.optional(Schema.String)
827
545
  }));
828
- const decorateAst = (original, value, path) => {
546
+ const decorateAst = (original, value, path, inputAst = original) => {
829
547
  const operations = record(value, path);
830
548
  const annotations = {};
831
549
  for (const [key, operation] of Object.entries(operations)) {
@@ -845,8 +563,8 @@ const decorateAst = (original, value, path) => {
845
563
  annotations[key === "label" ? FormLabel : key === "description" ? FormDescription : FormAutoComplete] = operation;
846
564
  break;
847
565
  case "default": {
848
- if (original.annotations[STRUCTURAL_ONLY_SYMBOL]) fail$1(path, "structural fields cannot have defaults");
849
- const input = Schema.encodedSchema(Schema.make(original));
566
+ if (fieldAnnotation(original, STRUCTURAL_ONLY_SYMBOL)) fail$1(path, "structural fields cannot have defaults");
567
+ const input = Schema.toEncoded(Schema.make(inputAst));
850
568
  const checked = (candidate) => {
851
569
  if (!(candidate === CurrentProviderUser && fieldAnnotation(original, FormProviderUserInput) === true) && !Schema.is(input)(candidate)) fail$1(path, "default does not match the declared input type");
852
570
  return candidate;
@@ -870,7 +588,7 @@ const decorateAst = (original, value, path) => {
870
588
  path,
871
589
  message: "query must return an Effect"
872
590
  }));
873
- return result.pipe(Effect.flatMap((items) => lookup ? Schema.decodeUnknown(lookupResult)(items) : Schema.decodeUnknown(calendarResult)(items)));
591
+ return result.pipe(Effect.flatMap((items) => lookup ? Schema.decodeUnknownEffect(lookupResult)(items) : Schema.decodeUnknownEffect(calendarResult)(items)));
874
592
  })
875
593
  };
876
594
  break;
@@ -878,13 +596,18 @@ const decorateAst = (original, value, path) => {
878
596
  default: fail$1(path, `unsupported operation ${key}`);
879
597
  }
880
598
  }
881
- return SchemaAST.annotations(original, annotations);
599
+ return Schema.make(Object.assign(Object.create(Object.getPrototypeOf(original)), original, { annotations: {
600
+ ...original.annotations,
601
+ ...annotations
602
+ } })).annotate(annotations).ast;
882
603
  };
883
604
  /** Preserve property transformations and exact field types during safe resolution. */
884
605
  const mapFormFields = (fields, map, mapAnnotations = (annotations) => annotations, mapOutput = (ast) => ast) => {
885
606
  return Object.fromEntries(Object.entries(fields).map(([name, original]) => {
886
- if (Schema.isPropertySignature(original)) return [name, mapFormPropertySignature(original, (ast, side) => side === "input" ? map(ast, name) : mapOutput(ast, name), (annotations, input, side) => mapAnnotations(annotations, input, name, side))];
887
- return [name, schemaFromAst(map(original.ast, name), original)];
607
+ const mapped = map(original.ast, name);
608
+ const annotations = mapAnnotations({ ...mapped.annotations }, mapped, name, "input");
609
+ const output = mapped.encoding ? mapOutput(mapped, name) : mapped;
610
+ return [name, schemaFromAst(Schema.make(output).annotate(annotations).ast, original)];
888
611
  }));
889
612
  };
890
613
  const sourceStructFields = (source) => {
@@ -893,39 +616,18 @@ const sourceStructFields = (source) => {
893
616
  if (typeof fields !== "object" || fields === null) return void 0;
894
617
  const result = {};
895
618
  for (const [name, field] of Object.entries(fields)) {
896
- if (!Schema.isSchema(field) && !Schema.isPropertySignature(field)) return void 0;
619
+ if (!Schema.isSchema(field)) return void 0;
897
620
  result[name] = field;
898
621
  }
899
622
  return result;
900
623
  };
901
624
  function schemaFromAst(ast, source) {
902
625
  const sourceFields = sourceStructFields(source);
903
- const struct = ast._tag === "TypeLiteral" ? {
904
- input: ast,
905
- output: ast
906
- } : ast._tag === "Transformation" && ast.transformation._tag === "TypeLiteralTransformation" && ast.from._tag === "TypeLiteral" && ast.to._tag === "TypeLiteral" ? {
907
- input: ast.from,
908
- output: ast.to
909
- } : void 0;
910
- if (sourceFields && struct) {
911
- const inputs = new Map(struct.input.propertySignatures.map((p) => [p.name, p]));
912
- const outputs = new Map(struct.output.propertySignatures.map((p) => [p.name, p]));
913
- const property = (name, side) => {
914
- const original = sourceFields[name];
915
- const inputKey = Schema.isPropertySignature(original) && original.ast._tag === "PropertySignatureTransformation" ? original.ast.from.fromKey ?? name : name;
916
- const resolved = side === "input" ? inputs.get(inputKey) : outputs.get(name);
917
- if (!resolved) return fail$1(`form.${name}`, "projected struct field is missing");
918
- return resolved;
919
- };
920
- const fields = mapFormFields(sourceFields, (_ast, name) => property(name, "input").type, (annotations, _ast, name, side) => Object.fromEntries(Reflect.ownKeys(annotations).map((key) => [key, property(name, side).annotations[key]])), (_ast, name) => property(name, "output").type);
921
- return Object.assign(Schema.make(ast), { fields });
922
- }
923
- if (ast._tag !== "TypeLiteral") return Schema.make(ast);
924
- const fields = Object.fromEntries(ast.propertySignatures.map((property) => [property.name, property.isOptional ? Schema.optional(schemaFromAst(property.type)) : schemaFromAst(property.type)]));
626
+ if (ast._tag !== "Objects") return Schema.make(ast);
627
+ const fields = Object.fromEntries(ast.propertySignatures.map((property) => [property.name, schemaFromAst(property.type, sourceFields?.[property.name])]));
925
628
  return Object.assign(Schema.make(ast), { fields });
926
629
  }
927
- //#endregion
928
- //#region ../process/src/lib/form-authoring.ts
630
+ // ../process/src/lib/form-authoring.ts
929
631
  const fail = (path, message) => {
930
632
  throw new FormDecorationError({
931
633
  path,
@@ -933,7 +635,7 @@ const fail = (path, message) => {
933
635
  });
934
636
  };
935
637
  const structuralAst = (content, path) => {
936
- if (!Schema.isSchema(content) || content.ast._tag !== "UndefinedKeyword" || content.ast.annotations[STRUCTURAL_ONLY_SYMBOL] !== true || content.ast.annotations[FormDeferredContent] !== void 0) return fail(path, "content must be a structural leaf, not a value field or container");
638
+ if (!Schema.isSchema(content) || content.ast._tag !== "Undefined" || Reflect.get(content.ast.annotations ?? {}, STRUCTURAL_ONLY_SYMBOL) !== true || Reflect.get(content.ast.annotations ?? {}, FormDeferredContent) !== void 0) return fail(path, "content must be a structural leaf, not a value field or container");
937
639
  return content.ast;
938
640
  };
939
641
  /** Never let deferred descriptors reach schema walkers or serialized metadata. */
@@ -955,16 +657,23 @@ const operations = /* @__PURE__ */ new Map([
955
657
  ]);
956
658
  /** Walk both sides of transformations without changing their decoding contract. */
957
659
  const mapChildren = (ast, map, path, mapAnnotations) => {
660
+ const encoding = ast.encoding ? Array$1.map(ast.encoding, (link) => new SchemaAST.Link(map(link.to, path), link.transformation)) : void 0;
661
+ const context = ast.context ? new SchemaAST.Context(ast.context.isOptional, ast.context.isMutable, ast.context.constructorDefault, mapAnnotations({ ...ast.context.annotations }, ast, path)) : void 0;
958
662
  switch (ast._tag) {
959
- case "TypeLiteral": return new SchemaAST.TypeLiteral(ast.propertySignatures.map((property) => new SchemaAST.PropertySignature(property.name, map(property.type, `${path}.${String(property.name)}`), property.isOptional, property.isReadonly, mapAnnotations(property.annotations, property.type, `${path}.${String(property.name)}`))), ast.indexSignatures, ast.annotations);
960
- case "TupleType": return new SchemaAST.TupleType(ast.elements.map((element, index) => new SchemaAST.OptionalType(map(element.type, `${path}[${index}]`), element.isOptional, element.annotations)), ast.rest.map((element) => new SchemaAST.Type(map(element.type, `${path}[]`), element.annotations)), ast.isReadonly, ast.annotations);
961
- case "Union": return SchemaAST.Union.make(ast.types.map((type) => map(type, path)), ast.annotations);
962
- case "Refinement": return new SchemaAST.Refinement(map(ast.from, path), ast.filter, ast.annotations);
963
- case "Transformation": return new SchemaAST.Transformation(map(ast.from, path), map(ast.to, path), ast.transformation, ast.annotations);
663
+ case "Objects": return new SchemaAST.Objects(ast.propertySignatures.map((property) => new SchemaAST.PropertySignature(property.name, map(property.type, `${path}.${String(property.name)}`))), ast.indexSignatures, ast.annotations, ast.checks, encoding, context, ast.encodingChecks);
664
+ case "Arrays": return new SchemaAST.Arrays(ast.isMutable, ast.elements.map((element, index) => map(element, `${path}[${index}]`)), ast.rest.map((element) => map(element, `${path}[]`)), ast.annotations, ast.checks, encoding, context, ast.encodingChecks);
665
+ case "Union": return new SchemaAST.Union(ast.types.map((type) => map(type, path)), ast.options, ast.annotations, ast.checks, encoding, context, ast.encodingChecks);
964
666
  case "Suspend": return fail(path, "suspended form schemas are not supported");
965
- default: return ast;
667
+ default: return Object.assign(Object.create(Object.getPrototypeOf(ast)), ast, {
668
+ encoding,
669
+ context
670
+ });
966
671
  }
967
672
  };
673
+ const annotateAst = (ast, annotations) => Schema.make(Object.assign(Object.create(Object.getPrototypeOf(ast)), ast, { annotations: {
674
+ ...ast.annotations,
675
+ ...annotations
676
+ } })).annotate(annotations).ast;
968
677
  const createFormAuthoring = () => {
969
678
  const resolvers = /* @__PURE__ */ new WeakMap();
970
679
  const value = (resolve, fallback) => {
@@ -980,7 +689,7 @@ const createFormAuthoring = () => {
980
689
  query: value,
981
690
  content: (resolve, fallback = TextBlock("")) => {
982
691
  structuralAst(fallback, "content.fallback");
983
- return fallback.annotations({ [FormDeferredContent]: value(resolve, fallback) });
692
+ return fallback.annotate({ [FormDeferredContent]: value(resolve, fallback) });
984
693
  }
985
694
  };
986
695
  const project = (fields, args) => {
@@ -993,26 +702,48 @@ const createFormAuthoring = () => {
993
702
  const resolved = evaluated.get(descriptor);
994
703
  return resolved === void 0 ? descriptor.fallback : resolved;
995
704
  };
996
- const visit = (original, path) => {
997
- const content = original.annotations[FormDeferredContent];
705
+ const inputOwners = /* @__PURE__ */ new Map();
706
+ const visit = (source, path) => {
707
+ const annotations = { ...source.annotations };
708
+ const checks = source.checks ? Array$1.map(source.checks, (check) => {
709
+ const remaining = { ...check.annotations };
710
+ for (const key of [
711
+ ...operations.keys(),
712
+ FormLookupInput,
713
+ FormCalendarSlotInput,
714
+ FormDeferredContent
715
+ ]) {
716
+ const annotation = Reflect.get(remaining, key);
717
+ if (annotation === void 0) continue;
718
+ annotations[key] = annotation;
719
+ Reflect.deleteProperty(remaining, key);
720
+ }
721
+ return Object.assign(Object.create(Object.getPrototypeOf(check)), check, { annotations: remaining });
722
+ }) : void 0;
723
+ const original = Object.assign(Object.create(Object.getPrototypeOf(source)), source, {
724
+ annotations,
725
+ checks
726
+ });
727
+ if (!inputOwners.has(path)) inputOwners.set(path, original);
728
+ const content = Reflect.get(original.annotations ?? {}, FormDeferredContent);
998
729
  if (content !== void 0) {
999
730
  if (!isDeferredValue(content)) return fail(path, "invalid deferred content");
1000
731
  const resolved = resolve(content, path);
1001
732
  return structuralAst(resolved === void 0 ? content.fallback : resolved, path);
1002
733
  }
1003
734
  let ast = mapChildren(original, visit, path, visitAnnotations);
1004
- for (const key of Object.getOwnPropertySymbols(original.annotations)) {
1005
- const annotation = original.annotations[key];
735
+ for (const key of Object.getOwnPropertySymbols(original.annotations ?? {})) {
736
+ const annotation = Reflect.get(original.annotations ?? {}, key);
1006
737
  if (isDeferredValue(annotation)) {
1007
738
  const operation = operations.get(key);
1008
739
  if (!operation) return fail(path, "deferred value is not allowed in this schema annotation");
1009
- ast = SchemaAST.annotations(ast, { [key]: void 0 });
1010
- ast = decorateAst(ast, { [operation]: resolve(annotation, path) }, path);
740
+ ast = annotateAst(ast, { [key]: void 0 });
741
+ ast = decorateAst(ast, { [operation]: resolve(annotation, path) }, path, inputOwners.get(path));
1011
742
  } else if (key === FormLookupInput || key === FormCalendarSlotInput) {
1012
743
  if (typeof annotation !== "object" || annotation === null || !("query" in annotation)) continue;
1013
744
  if (!isDeferredValue(annotation.query)) continue;
1014
745
  const query = annotation.query;
1015
- ast = SchemaAST.annotations(ast, { [key]: {
746
+ ast = annotateAst(ast, { [key]: {
1016
747
  ...annotation,
1017
748
  query: void 0
1018
749
  } });
@@ -1028,8 +759,8 @@ const createFormAuthoring = () => {
1028
759
  };
1029
760
  const visitAnnotations = (annotations, ast, path) => {
1030
761
  if (!Object.getOwnPropertySymbols(annotations).some((key) => isDeferredValue(annotations[key]))) return annotations;
1031
- const resolved = visit(SchemaAST.annotations(ast, annotations), path).annotations;
1032
- return Object.fromEntries(Reflect.ownKeys(annotations).map((key) => [key, resolved[key]]));
762
+ const resolved = visit(annotateAst(ast, annotations), path).annotations;
763
+ return Object.fromEntries(Reflect.ownKeys(annotations).map((key) => [key, Reflect.get(resolved ?? {}, key)]));
1033
764
  };
1034
765
  const resolved = mapFormFields(fields, (ast, name) => visit(ast, `form.${name}`), (annotations, ast, name) => visitAnnotations(annotations, ast, `form.${name}`), (ast, name) => visit(ast, `form.${name}`));
1035
766
  assertResolvedFormFields(resolved);
@@ -1040,11 +771,10 @@ const createFormAuthoring = () => {
1040
771
  project
1041
772
  };
1042
773
  };
1043
- //#endregion
1044
- //#region ../process/src/lib/form-defaults.ts
774
+ // ../process/src/lib/form-defaults.ts
1045
775
  const nestedAst = (ast) => {
1046
- if (ast._tag === "TypeLiteral") return ast;
1047
- if (ast._tag === "Transformation" || ast._tag === "Refinement") return nestedAst(ast.from);
776
+ if (ast._tag === "Objects") return ast;
777
+ if (ast.encoding) return nestedAst(SchemaAST.toEncoded(ast));
1048
778
  if (ast._tag === "Union") for (const type of ast.types) {
1049
779
  const nested = nestedAst(type);
1050
780
  if (nested) return nested;
@@ -1067,7 +797,7 @@ const resolveFormFieldDefaults = (fields, currentProviderUser) => Effect.gen(fun
1067
797
  }
1068
798
  const nested = nestedAst(ast);
1069
799
  if (nested) {
1070
- const children = yield* resolveFormFieldDefaults(Object.fromEntries(nested.propertySignatures.map((property) => [property.name, Schema.make(SchemaAST.annotations(property.type, property.annotations))])), currentProviderUser);
800
+ const children = yield* resolveFormFieldDefaults(Object.fromEntries(nested.propertySignatures.map((property) => [property.name, Schema.make(property.type)])), currentProviderUser);
1071
801
  if (fieldAnnotation(ast, FLATTEN_SYMBOL)) Object.assign(defaults, children);
1072
802
  else if (Object.keys(children).length) defaults[name] = children;
1073
803
  }
@@ -1089,8 +819,7 @@ const mergeFormDefaults = (defaults, input) => {
1089
819
  }
1090
820
  return merged;
1091
821
  };
1092
- //#endregion
1093
- //#region ../process/src/lib/lookup-accessor.ts
822
+ // ../process/src/lib/lookup-accessor.ts
1094
823
  /**
1095
824
  * Typed accessor for a single lookup field on a Form.
1096
825
  *
@@ -1110,6 +839,10 @@ var LookupAccessor = class {
1110
839
  setQuery(query) {
1111
840
  this._store._setLookupOverride(this.fieldName, { query });
1112
841
  }
842
+ /** Server-owned eligibility and label lookup, independent of search mode. */
843
+ setResolver(resolve) {
844
+ this._store._setLookupResolver(this.fieldName, resolve);
845
+ }
1113
846
  /**
1114
847
  * Declare dependencies on other lookup fields, returning a builder
1115
848
  * whose `setQuery` receives the dependency values as typed input.
@@ -1141,8 +874,7 @@ var LookupBuilder = class {
1141
874
  });
1142
875
  }
1143
876
  };
1144
- //#endregion
1145
- //#region ../process/src/lib/org-utils.ts
877
+ // ../process/src/lib/org-utils.ts
1146
878
  /**
1147
879
  * Normalizes a path for database storage by ensuring it starts with a forward slash.
1148
880
  * Paths in constructs don't have a leading slash, but stored paths should have one
@@ -1188,8 +920,7 @@ const pathToPascalCase = (path) => {
1188
920
  return segment.replace(/-/g, " ").split(/\s+/).filter((word) => word.length > 0).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("");
1189
921
  }).join("");
1190
922
  };
1191
- //#endregion
1192
- //#region ../process/src/lib/flow-context.ts
923
+ // ../process/src/lib/flow-context.ts
1193
924
  /**
1194
925
  * Convert a string to a valid camelCase JavaScript identifier.
1195
926
  * Handles spaces, underscores, hyphens, and removes invalid characters.
@@ -1220,8 +951,7 @@ function toCamelCase(str) {
1220
951
  if (result.length === 0 || /^[0-9]/.test(result)) return `_${result}`;
1221
952
  return result;
1222
953
  }
1223
- //#endregion
1224
- //#region ../process/src/lib/step.ts
954
+ // ../process/src/lib/step.ts
1225
955
  var Step = class extends Construct {
1226
956
  props;
1227
957
  _output;
@@ -1263,6 +993,8 @@ var Step = class extends Construct {
1263
993
  * which fails when org.js is compiled separately from the job worker.
1264
994
  */
1265
995
  isSystemStep = false;
996
+ /** One-shot timing, evaluated against state before this activation completes. */
997
+ deadlines = [];
1266
998
  /**
1267
999
  * The output validation schema for this step.
1268
1000
  * Lazily builds Schema.Struct from output fields on first access.
@@ -1321,8 +1053,7 @@ var Step = class extends Construct {
1321
1053
  return step;
1322
1054
  }
1323
1055
  };
1324
- //#endregion
1325
- //#region ../process/src/lib/system-step.ts
1056
+ // ../process/src/lib/system-step.ts
1326
1057
  /**
1327
1058
  * Structural guard for AuthorTaggedError (cross-boundary safe; no instanceof).
1328
1059
  */
@@ -1350,7 +1081,7 @@ var NotAForEachStepError = class extends Data.TaggedError("NotAForEachStepError"
1350
1081
  * Use this from NodeStep `execute` callbacks that need the Todo identity
1351
1082
  * for replay-safe side effects.
1352
1083
  */
1353
- var CurrentStepJobContext = class extends Context.Tag("processfocus/process/CurrentStepJobContext")() {};
1084
+ var CurrentStepJobContext = class extends Context.Service()("processfocus/process/CurrentStepJobContext") {};
1354
1085
  /**
1355
1086
  * Abstract base class for system-executed steps.
1356
1087
  *
@@ -1454,7 +1185,7 @@ var SystemStep = class extends Step {
1454
1185
  * For forEach steps, the executor calls execute(input) directly with item_data.
1455
1186
  */
1456
1187
  executeWithInput(state, ctx) {
1457
- return Effect.gen(this, function* () {
1188
+ return Effect.gen({ self: this }, function* () {
1458
1189
  const input = yield* this.input(state, ctx);
1459
1190
  return yield* this.execute(input);
1460
1191
  });
@@ -1481,8 +1212,7 @@ var SystemStep = class extends Step {
1481
1212
  return createOnErrorFlowPath(this, target, this.process, options);
1482
1213
  }
1483
1214
  };
1484
- //#endregion
1485
- //#region ../process/src/lib/form.ts
1215
+ // ../process/src/lib/form.ts
1486
1216
  const astChildKeys = [
1487
1217
  "type",
1488
1218
  "types",
@@ -1498,12 +1228,12 @@ const getRawAnnotation = (value, annotationId) => {
1498
1228
  };
1499
1229
  const getSchemaAnnotationDeep = (schema, annotationId) => {
1500
1230
  const visit = (ast, seen) => {
1501
- const direct = SchemaAST.getAnnotation(ast, annotationId);
1231
+ const direct = getAnnotation(ast, annotationId);
1502
1232
  if (Option.isSome(direct)) return direct;
1503
1233
  if (seen.has(ast)) return Option.none();
1504
1234
  seen.add(ast);
1505
1235
  if (SchemaAST.isSuspend(ast)) {
1506
- const result = visit(ast.f(), seen);
1236
+ const result = visit(ast.thunk(), seen);
1507
1237
  if (Option.isSome(result)) return result;
1508
1238
  }
1509
1239
  const record = ast;
@@ -1545,24 +1275,11 @@ const getSchemaAnnotationDeep = (schema, annotationId) => {
1545
1275
  };
1546
1276
  return visit(schema.ast, /* @__PURE__ */ new Set());
1547
1277
  };
1548
- const dynamicTextBlockResolutionConcurrency = 5;
1549
- const isFieldSetComponent = (component) => component._tag === "fieldset";
1550
- const isStaticComponent = (component) => component._tag === "static";
1551
- const isListComponent = (component) => component._tag === "list";
1552
- const isTableComponent = (component) => component._tag === "table";
1553
- const isDynamicTextBlockContent = (value) => typeof value === "function";
1554
1278
  const getSchemaAst = (schema) => {
1555
- if (Schema.isPropertySignature(schema)) return fieldInputAst(schema);
1556
1279
  if (typeof schema !== "object" && typeof schema !== "function" || schema === null || !("ast" in schema)) return;
1557
1280
  const ast = schema.ast;
1558
1281
  return isAst(ast) ? ast : void 0;
1559
1282
  };
1560
- const getDynamicTextBlockContent = (schema) => {
1561
- const ast = isAst(schema) ? schema : getSchemaAst(schema);
1562
- if (!ast) return;
1563
- const content = Option.getOrUndefined(SchemaAST.getAnnotation(ast, TEXTBLOCK_DYNAMIC_CONTENT_SYMBOL));
1564
- return isDynamicTextBlockContent(content) ? content : void 0;
1565
- };
1566
1283
  const getStructFields = (schema) => {
1567
1284
  if (typeof schema !== "object" && typeof schema !== "function" || schema === null || !("fields" in schema)) return;
1568
1285
  const fields = schema.fields;
@@ -1570,7 +1287,7 @@ const getStructFields = (schema) => {
1570
1287
  };
1571
1288
  const getTypeLiteralFields = (ast) => {
1572
1289
  if (!ast) return void 0;
1573
- if (ast._tag === "Transformation" || ast._tag === "Refinement") return getTypeLiteralFields(ast.from);
1290
+ if (ast.encoding) return getTypeLiteralFields(SchemaAST.toEncoded(ast));
1574
1291
  if (ast._tag === "Union") {
1575
1292
  for (const member of ast.types) {
1576
1293
  const fields = getTypeLiteralFields(member);
@@ -1578,20 +1295,14 @@ const getTypeLiteralFields = (ast) => {
1578
1295
  }
1579
1296
  return;
1580
1297
  }
1581
- if (ast._tag !== "TypeLiteral") return void 0;
1582
- return Object.fromEntries(ast.propertySignatures.map((property) => [property.name, Schema.make(SchemaAST.annotations(property.type, property.annotations))]));
1298
+ if (ast._tag !== "Objects") return void 0;
1299
+ return Object.fromEntries(ast.propertySignatures.map((property) => [property.name, Schema.make(property.type)]));
1583
1300
  };
1584
1301
  const getAstFields = (schema) => {
1585
1302
  const ast = isAst(schema) ? schema : getSchemaAst(schema);
1586
1303
  return getTypeLiteralFields(ast);
1587
1304
  };
1588
1305
  const getNestedFields = (schema) => getStructFields(schema) ?? getAstFields(schema);
1589
- const getListItemFields = (schema) => {
1590
- const ast = getSchemaAst(schema);
1591
- if (ast?._tag !== "TupleType") return;
1592
- const itemAst = ast.rest?.[0]?.type;
1593
- return isAst(itemAst) ? getTypeLiteralFields(itemAst) : void 0;
1594
- };
1595
1306
  /**
1596
1307
  * Counts leaf fields in a nested structure.
1597
1308
  * A "leaf" is any primitive value or empty array.
@@ -1613,195 +1324,7 @@ const countLeafFields = (value) => {
1613
1324
  }
1614
1325
  return 1;
1615
1326
  };
1616
- const FormRuleSelf = Symbol.for("processfocus/process/form-rule-self");
1617
- const formRuleStateKeys = /* @__PURE__ */ new Set([
1618
- "hidden",
1619
- "disabled",
1620
- "required",
1621
- "label"
1622
- ]);
1623
- const formRuleStateTypes = {
1624
- hidden: "boolean",
1625
- disabled: "boolean",
1626
- required: "boolean",
1627
- label: "string"
1628
- };
1629
- const isFormRuleTargetState = (value) => {
1630
- if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
1631
- const keys = Object.keys(value);
1632
- return keys.length > 0 && keys.every((key) => {
1633
- if (!formRuleStateKeys.has(key)) return false;
1634
- const expected = formRuleStateTypes[key];
1635
- if (!expected) return false;
1636
- return typeof value[key] === expected;
1637
- });
1638
- };
1639
- const ruleFieldValue = (path) => ({
1640
- _tag: "field",
1641
- path
1642
- });
1643
- const ruleLiteralValue = (value) => ({
1644
- _tag: "literal",
1645
- value
1646
- });
1647
- const comparison = (tag, path, value) => ({
1648
- _tag: tag,
1649
- left: ruleFieldValue(path),
1650
- right: ruleLiteralValue(value)
1651
- });
1652
- const membership = (tag, path, values) => ({
1653
- _tag: tag,
1654
- value: ruleFieldValue(path),
1655
- candidates: ruleLiteralValue(values)
1656
- });
1657
- const ordering = (operator, path, value) => ({
1658
- _tag: typeof value === "number" ? "numberOrder" : "stringOrder",
1659
- operator,
1660
- left: ruleFieldValue(path),
1661
- right: ruleLiteralValue(value)
1662
- });
1663
- const makeValueAccessor = (path) => ({
1664
- equals: (value) => comparison("equals", path, value),
1665
- notEquals: (value) => comparison("notEquals", path, value),
1666
- in: (values) => membership("in", path, values),
1667
- notIn: (values) => membership("notIn", path, values),
1668
- blank: () => ({
1669
- _tag: "blank",
1670
- value: ruleFieldValue(path)
1671
- }),
1672
- present: () => ({
1673
- _tag: "present",
1674
- value: ruleFieldValue(path)
1675
- }),
1676
- lt: (value) => ordering("lt", path, value),
1677
- lte: (value) => ordering("lte", path, value),
1678
- gt: (value) => ordering("gt", path, value),
1679
- gte: (value) => ordering("gte", path, value)
1680
- });
1681
- const makeRuleAuthor = () => ({
1682
- when: (condition) => ({ effects: (effects, otherwise) => ({
1683
- condition,
1684
- effects: flattenRuleEffects(effects),
1685
- ...otherwise ? { otherwise: flattenRuleEffects(otherwise) } : {}
1686
- }) }),
1687
- and: (...expressions) => ({
1688
- _tag: "and",
1689
- expressions
1690
- }),
1691
- or: (...expressions) => ({
1692
- _tag: "or",
1693
- expressions
1694
- }),
1695
- not: (expression) => ({
1696
- _tag: "not",
1697
- expression
1698
- })
1699
- });
1700
- const makeValueAccessors = (fields, path = []) => Object.entries(fields).reduce((accessors, [key, schema]) => {
1701
- if (hasStructuralOnlyAnnotation(schema) || isReadOnlyField(schema)) return accessors;
1702
- const nextPath = [...path, key];
1703
- const nestedFields = getNestedFields(schema);
1704
- const isFlattened = hasFlattenAnnotation(schema);
1705
- if (nestedFields && isFlattened) {
1706
- Object.assign(accessors, makeValueAccessors(nestedFields, path));
1707
- return accessors;
1708
- }
1709
- accessors[key] = nestedFields ? makeValueAccessors(nestedFields, nextPath) : makeValueAccessor(nextPath);
1710
- return accessors;
1711
- }, {});
1712
- const flattenRuleEffects = (tree) => {
1713
- const effects = [];
1714
- const visit = (value, path) => {
1715
- if (isFormRuleTargetState(value)) {
1716
- effects.push({
1717
- target: path,
1718
- state: value
1719
- });
1720
- return;
1721
- }
1722
- if (typeof value !== "object" || value === null || Array.isArray(value)) return;
1723
- const record = value;
1724
- const selfState = record[FormRuleSelf];
1725
- if (selfState !== void 0 && isFormRuleTargetState(selfState)) effects.push({
1726
- target: path,
1727
- state: selfState
1728
- });
1729
- for (const [key, child] of Object.entries(record)) visit(child, [...path, key]);
1730
- };
1731
- visit(tree, []);
1732
- return effects;
1733
- };
1734
- const getFormRuleTargetComponent = (representation, path) => {
1735
- let current = representation;
1736
- let component;
1737
- for (const segment of path) {
1738
- if (typeof segment !== "string" || !current) return void 0;
1739
- component = current[segment];
1740
- if (!component) return void 0;
1741
- if (isFieldSetComponent(component)) current = component.children;
1742
- else if (isListComponent(component) || isTableComponent(component)) current = component.itemChildren;
1743
- else current = void 0;
1744
- }
1745
- return component;
1746
- };
1747
- const isStructuralOrStaticRuleTarget = (component) => {
1748
- switch (component._tag) {
1749
- case "fieldset":
1750
- case "static":
1751
- case "link":
1752
- case "metric-breakdown": return true;
1753
- case "table": return true;
1754
- case "text":
1755
- case "textarea":
1756
- case "number":
1757
- case "date":
1758
- case "email":
1759
- case "phone":
1760
- case "provider-user":
1761
- case "boolean":
1762
- case "select":
1763
- case "radio":
1764
- case "file":
1765
- case "list":
1766
- case "lookup":
1767
- case "calendar-slot":
1768
- case "plugin": return false;
1769
- default: return component;
1770
- }
1771
- };
1772
- const formRulePathToFieldName = (path) => path.every((segment) => typeof segment === "string") ? path.join(".") : void 0;
1773
- const hasFormRuleFieldName = (representation, fieldName) => {
1774
- for (const component of Object.values(representation)) {
1775
- if ("field" in component && component.field === fieldName) return true;
1776
- if (isFieldSetComponent(component) && hasFormRuleFieldName(component.children, fieldName)) return true;
1777
- }
1778
- return false;
1779
- };
1780
- const hasFormRuleFieldPath = (representation, path) => {
1781
- const fieldName = formRulePathToFieldName(path);
1782
- if (fieldName === void 0) return false;
1783
- if (hasFormRuleFieldName(representation, fieldName)) return true;
1784
- let current = representation;
1785
- let component;
1786
- for (const segment of path) {
1787
- if (typeof segment !== "string" || !current) return false;
1788
- component = current[segment];
1789
- if (!component) return false;
1790
- current = isFieldSetComponent(component) ? component.children : void 0;
1791
- }
1792
- return component !== void 0;
1793
- };
1794
- const validateFormRuleTargets = (formStep, representation, rules) => {
1795
- for (const rule of rules) {
1796
- const conditionPaths = formRuleConditionPaths({ expression: rule.condition });
1797
- for (const path of conditionPaths) if (!hasFormRuleFieldPath(representation, path)) throw new Error(`Form "${formStep}" rule condition references missing field "${path.join(".")}" in rendered form tree`);
1798
- for (const effect of [...rule.effects, ...rule.otherwise ?? []]) {
1799
- const target = getFormRuleTargetComponent(representation, effect.target);
1800
- if (!target) throw new Error(`Form "${formStep}" rule targets missing field "${effect.target.join(".")}" in rendered form tree`);
1801
- if (effect.state.required !== void 0 && isStructuralOrStaticRuleTarget(target)) throw new Error(`Form "${formStep}" rule target "${effect.target.join(".")}" cannot set required on structural or static display components`);
1802
- }
1803
- }
1804
- };
1327
+ Data.TaggedError("FormSubmissionError");
1805
1328
  const defaultProviderUserDisplay = { display: (providerUserIdOrEmail) => Effect.succeed(providerUserIdOrEmail) };
1806
1329
  const toSummaryContext = (ctx) => {
1807
1330
  if ("providerUserDisplay" in ctx) return ctx;
@@ -1845,7 +1368,7 @@ const flattenDefaults = (defaults, schema) => {
1845
1368
  for (const [key, field] of Object.entries(schema.fields)) {
1846
1369
  const fieldAsAny = field;
1847
1370
  if (hasStructuralOnlyAnnotation(fieldAsAny)) continue;
1848
- if (hasFlattenAnnotation(fieldAsAny) && fieldAsAny.ast._tag === "TypeLiteral" && "fields" in fieldAsAny) {
1371
+ if (hasFlattenAnnotation(fieldAsAny) && fieldAsAny.ast._tag === "Objects" && "fields" in fieldAsAny) {
1849
1372
  const nestedValue = defaults[key];
1850
1373
  const nestedFlat = flattenDefaults(typeof nestedValue === "object" && nestedValue !== null ? nestedValue : defaults, fieldAsAny);
1851
1374
  Object.assign(flat, nestedFlat);
@@ -1907,6 +1430,7 @@ var Form = class extends Step {
1907
1430
  * Request-local resolution of the static declaration's lazy expressions.
1908
1431
  */
1909
1432
  _formFn;
1433
+ _onSubmit;
1910
1434
  /**
1911
1435
  * The summary function, stored for computing summary from process state.
1912
1436
  */
@@ -1932,15 +1456,38 @@ var Form = class extends Step {
1932
1456
  * Lookup query overrides set via `this.lookups.<field>.setQuery()`.
1933
1457
  */
1934
1458
  _lookupOverrides = /* @__PURE__ */ new Map();
1935
- /**
1936
- * Typed accessors for lookup fields.
1937
- * Use `this.lookups.<field>.setQuery()` for independent lookups or
1938
- * `this.lookups.<field>.dependsOn([...]).setQuery()` for dependent lookups.
1939
- */
1940
- static self = FormRuleSelf;
1459
+ _lookupResolvers = /* @__PURE__ */ new Map();
1460
+ _setLookupResolver(fieldName, resolve) {
1461
+ this._lookupResolvers.set(fieldName, resolve);
1462
+ }
1463
+ resolveLookupSelection(fieldName, value, fields = this._formFields) {
1464
+ const field = submissionSchemaSync(Schema.Struct(fields)).fields[fieldName];
1465
+ const metadata = field ? Option.getOrUndefined(getSchemaAnnotationDeep(field, FormLookupInput)) : void 0;
1466
+ const resolve = this._lookupResolvers.get(fieldName) ?? metadata?.resolve;
1467
+ if (!metadata || this._lookupOverrides.get(fieldName)?.dependencies?.length || !resolve) return Effect.succeed(null);
1468
+ return resolve(value).pipe(Effect.map((item) => item?.value === value ? item : null));
1469
+ }
1941
1470
  isForm = true;
1471
+ /** Attach a deadline. The owner output is not yet available. */
1472
+ onDeadline(name, options) {
1473
+ if (!name.trim()) throw new Error("A deadline name must not be empty");
1474
+ if (this.deadlines.some((deadline) => deadline.name === name)) throw new Error(`Duplicate deadline "${name}" on ${this.node.path}`);
1475
+ assertSameProcess(options.handler, this.process);
1476
+ this.process.addEdge(this, options.handler, {
1477
+ deadlineName: name,
1478
+ interrupting: options.interrupting ?? false
1479
+ });
1480
+ this.deadlines.push({
1481
+ name,
1482
+ interrupting: options.interrupting ?? false,
1483
+ timing: options.at ? { at: options.at } : { after: options.after }
1484
+ });
1485
+ return wrapInFlowPath(options.handler, this.process);
1486
+ }
1942
1487
  lookups;
1943
- _rules = [];
1488
+ sharedSchema;
1489
+ browser;
1490
+ anonymousPage;
1944
1491
  embed;
1945
1492
  supportingRoles;
1946
1493
  publicCompletion;
@@ -1966,19 +1513,72 @@ var Form = class extends Step {
1966
1513
  };
1967
1514
  super(scope, id, stepProps);
1968
1515
  const authoring = createFormAuthoring();
1969
- const fields = Object.freeze({ ...props.form(authoring.helpers) });
1516
+ this.browser = props.browser;
1517
+ const fields = Object.freeze({ ...Schema.isSchema(props.form) ? props.form.fields : props.form(authoring.helpers) });
1518
+ this.sharedSchema = Schema.isSchema(props.form) ? props.form : Schema.Struct(fields);
1970
1519
  this._formFields = authoring.project(fields);
1971
- this._formFn = (state, ctx, item) => authoring.project(fields, [
1972
- state,
1973
- ctx,
1974
- item
1975
- ]);
1520
+ this._formFn = (state, ctx, item) => {
1521
+ const resolved = authoring.project(fields, [
1522
+ state,
1523
+ ctx,
1524
+ item
1525
+ ]);
1526
+ const bindings = props.bindings?.(state, ctx, item);
1527
+ if (!bindings) return resolved;
1528
+ const decorated = { ...resolved };
1529
+ for (const key of Object.keys(bindings)) if (!Object.hasOwn(resolved, key)) throw new FormDecorationError({
1530
+ path: `form.${key}`,
1531
+ message: `Unknown form binding: ${key}`
1532
+ });
1533
+ for (const key in resolved) {
1534
+ const binding = bindings[key];
1535
+ if (!binding) continue;
1536
+ const query = "query" in binding ? binding.query : void 0;
1537
+ const lookup = fieldAnnotation(resolved[key].ast, FormLookupInput);
1538
+ if (query !== void 0 && (typeof query !== "function" || lookup === void 0)) throw new FormDecorationError({
1539
+ path: `form.${key}`,
1540
+ message: `Invalid lookup binding: ${key}`
1541
+ });
1542
+ const annotations = {
1543
+ ...query === void 0 ? {} : { [FormLookupInput]: {
1544
+ ...typeof lookup === "object" && lookup !== null ? lookup : {},
1545
+ query
1546
+ } },
1547
+ ...binding.label === void 0 ? {} : { [FormLabel]: binding.label },
1548
+ ...binding.description === void 0 ? {} : { [FormDescription]: binding.description },
1549
+ ...binding.text === void 0 ? {} : {
1550
+ [FormStaticText]: binding.text,
1551
+ [TEXTBLOCK_CONTENT_SYMBOL]: binding.text,
1552
+ [LINK_TEXT_SYMBOL]: binding.text
1553
+ },
1554
+ ...binding.href === void 0 ? {} : { [LINK_URL_SYMBOL]: binding.href },
1555
+ ...binding.default === void 0 ? {} : { [FormDefault]: binding.default }
1556
+ };
1557
+ decorated[key] = mapFormFields({ field: resolved[key] }, (ast) => Schema.make(ast).annotate(annotations).ast, (existing) => ({
1558
+ ...existing,
1559
+ ...annotations
1560
+ })).field;
1561
+ }
1562
+ return decorated;
1563
+ };
1976
1564
  assertResolvedFormFields(this._formFields);
1977
1565
  const struct = Schema.Struct(this._formFields);
1978
- this._schema = props.validate ? struct.pipe(Schema.filterEffect(props.validate)) : struct;
1566
+ this._onSubmit = props.onSubmit;
1567
+ this._schema = props.validate ? struct.pipe(Schema.decode({
1568
+ decode: SchemaGetter.checkEffect(props.validate),
1569
+ encode: SchemaGetter.passthrough()
1570
+ })) : struct;
1979
1571
  const flatSubmission = submissionSchemaSync(struct);
1980
- this._submissionEffectSchema = props.validate ? flatSubmission.pipe(Schema.filterEffect(props.validate)) : flatSubmission;
1572
+ this._submissionEffectSchema = props.validate ? flatSubmission.pipe(Schema.decode({
1573
+ decode: SchemaGetter.checkEffect(props.validate),
1574
+ encode: SchemaGetter.passthrough()
1575
+ })) : flatSubmission;
1981
1576
  this.lookups = Object.fromEntries(Object.keys(this._formFields).map((k) => [k, new LookupAccessor(this, k)]));
1577
+ if (props.anonymousPage) {
1578
+ if (props.embed || props.publicCompletion) throw new Error("An Anonymous Page cannot also be an embed or public completion");
1579
+ if (!/^[A-Za-z0-9_-]+$/.test(props.anonymousPage.address)) throw new Error("Anonymous Page address must be a URL-safe path segment");
1580
+ }
1581
+ this.anonymousPage = props.anonymousPage;
1982
1582
  this.embed = props.embed ? normalizeEmbedConfig(props.embed, flatSubmission.fields) : void 0;
1983
1583
  this.supportingRoles = props.supportingRoles;
1984
1584
  this.publicCompletion = props.publicCompletion;
@@ -2000,18 +1600,24 @@ var Form = class extends Step {
2000
1600
  lookupOverrides() {
2001
1601
  return this._lookupOverrides;
2002
1602
  }
2003
- /**
2004
- * Append browser-safe form rules authored against typed field accessors and
2005
- * a typed target tree matching this form's schema.
2006
- */
2007
- rules(build) {
2008
- this._rules.push(...build(makeValueAccessors(this._formFields), makeRuleAuthor()));
1603
+ _prefill;
1604
+ /** Fresh selection-dependent values. Concealed fields still travel on submission. */
1605
+ prefillOn(dependency, options) {
1606
+ this._prefill = {
1607
+ dependency,
1608
+ fields: options.fields,
1609
+ concealed: options.concealed ?? [],
1610
+ load: options.load
1611
+ };
2009
1612
  return this;
2010
1613
  }
2011
- authoritativeFormRules() {
2012
- return [...this._rules];
1614
+ prefillQuery() {
1615
+ return this._prefill;
2013
1616
  }
2014
- flattenRuleTargetPath(path) {
1617
+ prefillQueryName() {
1618
+ return `${this.lookupQueryName("prefill")}Values`;
1619
+ }
1620
+ submissionPath(path) {
2015
1621
  const flat = [];
2016
1622
  let currentFields = this._formFields;
2017
1623
  for (const segment of path) {
@@ -2034,13 +1640,6 @@ var Form = class extends Step {
2034
1640
  }
2035
1641
  return flat;
2036
1642
  }
2037
- evaluateFormRules(values, baseValues) {
2038
- return evaluateFormRules({
2039
- rules: this._rules,
2040
- values,
2041
- ...baseValues === void 0 ? {} : { baseValues }
2042
- });
2043
- }
2044
1643
  /**
2045
1644
  * Returns the GraphQL query name for a dependent lookup field.
2046
1645
  * E.g. `lookupDevopsAddEnvironmentInputEnvironmentDetailsStageId`
@@ -2063,6 +1662,10 @@ var Form = class extends Step {
2063
1662
  get outputSchema() {
2064
1663
  return this._schema;
2065
1664
  }
1665
+ /** Invoke only after the runtime has validated and authorized the submission. */
1666
+ executeSubmit(input) {
1667
+ return Effect.suspend(() => this._onSubmit?.(input) ?? Effect.void);
1668
+ }
2066
1669
  /**
2067
1670
  * Get the flat submission validation schema for this form.
2068
1671
  * Returns submissionSchema(fields) (wrapper fields flattened, read-only/
@@ -2118,7 +1721,7 @@ var Form = class extends Step {
2118
1721
  getAssignee(state, ctx, item) {
2119
1722
  if (!this._assigneeFn) return Effect.succeed(void 0);
2120
1723
  const assigneeFn = this._assigneeFn;
2121
- return Effect.try(() => assigneeFn(state, ctx, item)).pipe(Effect.flatMap((assignee) => Effect.isEffect(assignee) ? assignee : Effect.succeed(assignee)), Effect.catchAllCause((cause) => Effect.logWarning(`Failed to resolve assignee for form "${this.node.id}"`, { cause }).pipe(Effect.as(void 0))));
1724
+ return Effect.try(() => assigneeFn(state, ctx, item)).pipe(Effect.flatMap((assignee) => Effect.isEffect(assignee) ? assignee : Effect.succeed(assignee)), Effect.catchCause((cause) => Effect.logWarning(`Failed to resolve assignee for form "${this.node.id}"`, { cause }).pipe(Effect.as(void 0))));
2122
1725
  }
2123
1726
  /**
2124
1727
  * Compute the summary for this form given the current process state.
@@ -2135,7 +1738,7 @@ var Form = class extends Step {
2135
1738
  if (!this._summaryFn) return Effect.succeed({});
2136
1739
  const summaryFn = this._summaryFn;
2137
1740
  const summaryCtx = toSummaryContext(ctx);
2138
- return Effect.try(() => summaryFn(state, summaryCtx, item)).pipe(Effect.flatMap((summary) => Effect.isEffect(summary) ? summary : Effect.succeed(summary)), Effect.catchAllCause((cause) => Effect.logWarning(`Failed to compute summary for form "${this.node.id}"`, { cause }).pipe(Effect.as({}))));
1741
+ return Effect.try(() => summaryFn(state, summaryCtx, item)).pipe(Effect.flatMap((summary) => Effect.isEffect(summary) ? summary : Effect.succeed(summary)), Effect.catchCause((cause) => Effect.logWarning(`Failed to compute summary for form "${this.node.id}"`, { cause }).pipe(Effect.as({}))));
2139
1742
  }
2140
1743
  /**
2141
1744
  * Resolve default values from schema annotations.
@@ -2169,121 +1772,12 @@ var Form = class extends Step {
2169
1772
  * This keeps start-step metadata from leaking symbolic defaults to clients.
2170
1773
  */
2171
1774
  resolveInitialDefaults(currentProviderUser) {
2172
- return Effect.gen(this, function* () {
1775
+ return Effect.gen({ self: this }, function* () {
2173
1776
  const resolvedDefaults = yield* this.resolveFieldDefaults(this._formFields, currentProviderUser);
2174
1777
  return flattenDefaults(mergeFormDefaults(this.defaults(), resolvedDefaults), Schema.Struct(this._formFields));
2175
1778
  });
2176
1779
  }
2177
1780
  /**
2178
- * Get the client representation for this form's fields.
2179
- * Used for rendering the form in the UI.
2180
- *
2181
- * Post-processes the representation to add `dependencies` and `queryName`
2182
- * to any lookup components that have dependent overrides.
2183
- *
2184
- * @returns Effect that produces the client representation
2185
- */
2186
- buildClientComponents(fields) {
2187
- const effectSchema = Schema.Struct(fields);
2188
- return Effect.gen(this, function* () {
2189
- const components = { ...yield* asClientRepresentation(effectSchema) };
2190
- for (const [fieldName, override] of this._lookupOverrides) if (override.dependencies && override.dependencies.length > 0) {
2191
- const component = components[fieldName];
2192
- if (component && component._tag === "lookup") components[fieldName] = {
2193
- ...component,
2194
- dependencies: override.dependencies,
2195
- queryName: this.lookupQueryName(fieldName)
2196
- };
2197
- }
2198
- return components;
2199
- });
2200
- }
2201
- buildClientFormDefinition(fields) {
2202
- return this.buildClientComponents(fields).pipe(Effect.map((components) => {
2203
- if (this._rules.length > 0) validateFormRuleTargets(this.stepKey, components, this._rules);
2204
- return {
2205
- components,
2206
- rules: this._rules
2207
- };
2208
- }));
2209
- }
2210
- resolveDynamicTextBlockComponent(fieldSchema, component) {
2211
- if (isFieldSetComponent(component)) {
2212
- const nestedFields = getNestedFields(fieldSchema);
2213
- if (!nestedFields) return Effect.succeed(component);
2214
- return this.resolveDynamicTextBlocks(nestedFields, component.children).pipe(Effect.map((children) => ({
2215
- ...component,
2216
- children
2217
- })));
2218
- }
2219
- if (isListComponent(component) || isTableComponent(component)) {
2220
- const itemFields = getListItemFields(fieldSchema);
2221
- if (!itemFields) return Effect.succeed(component);
2222
- return this.resolveDynamicTextBlocks(itemFields, component.itemChildren).pipe(Effect.map((itemChildren) => ({
2223
- ...component,
2224
- itemChildren
2225
- })));
2226
- }
2227
- if (!fieldSchema || !isStaticComponent(component)) return Effect.succeed(component);
2228
- const dynamicContent = getDynamicTextBlockContent(fieldSchema);
2229
- if (!dynamicContent) return Effect.succeed(component);
2230
- return dynamicContent().pipe(Effect.map((content) => ({
2231
- ...component,
2232
- content
2233
- })), Effect.catchAllCause((cause) => Effect.logWarning(`Failed to resolve dynamic text block for form "${this.node.id}"`, {
2234
- cause,
2235
- fieldName: component.field
2236
- }).pipe(Effect.as(component))));
2237
- }
2238
- resolveDynamicTextBlocks(fields, representation) {
2239
- return Effect.gen(this, function* () {
2240
- const entries = yield* Effect.forEach(Object.entries(representation), ([fieldName, component]) => {
2241
- const fieldSchema = fields[fieldName];
2242
- return this.resolveDynamicTextBlockComponent(fieldSchema, component).pipe(Effect.map((resolved) => [fieldName, resolved]));
2243
- }, { concurrency: dynamicTextBlockResolutionConcurrency });
2244
- return Object.fromEntries(entries);
2245
- });
2246
- }
2247
- buildRenderableClientFormDefinition(fields) {
2248
- return this.buildClientFormDefinition(fields).pipe(Effect.flatMap((definition) => this.resolveDynamicTextBlocks(fields, definition.components).pipe(Effect.map((components) => ({
2249
- components,
2250
- rules: definition.rules
2251
- })))));
2252
- }
2253
- clientFormDefinition() {
2254
- return this.buildClientFormDefinition(this.output);
2255
- }
2256
- renderableClientFormDefinition() {
2257
- return this.buildRenderableClientFormDefinition(this.output);
2258
- }
2259
- clientFormDefinitionWithState(state, ctx, item) {
2260
- return this.buildClientFormDefinition(this.getFieldsWithState(state, ctx, item));
2261
- }
2262
- renderableClientFormDefinitionWithState(state, ctx, item) {
2263
- return this.buildRenderableClientFormDefinition(this.getFieldsWithState(state, ctx, item));
2264
- }
2265
- /**
2266
- * Get the submission schema for form validation.
2267
- * Excludes read-only fields and removes additionalProperties constraint
2268
- * to allow form values to include read-only fields.
2269
- *
2270
- * @returns JSON schema object
2271
- */
2272
- submissionSchema() {
2273
- const effectSchema = Schema.Struct(this.output);
2274
- const submission = submissionSchemaSync(effectSchema);
2275
- const { additionalProperties: _, ...schema } = JSONSchema.make(submission);
2276
- const properties = schema["properties"];
2277
- if (properties && submission.ast._tag === "TypeLiteral") for (const prop of submission.ast.propertySignatures) {
2278
- const msg = SchemaAST.getAnnotation(prop.type, FormMessage);
2279
- if (Option.isSome(msg) && typeof msg.value === "string") {
2280
- const name = String(prop.name);
2281
- if (properties[name]) properties[name]["x-message"] = msg.value;
2282
- }
2283
- }
2284
- return schema;
2285
- }
2286
- /**
2287
1781
  * Execute a lookup query for a specific field in this form.
2288
1782
  *
2289
1783
  * Checks for an override (set via `this.lookups`) first, then falls back
@@ -2354,6 +1848,33 @@ var Form = class extends Step {
2354
1848
  const fields = this.getFieldsWithState(state, ctx, item);
2355
1849
  return this._runCalendarSlotQuery(fieldName, fields[fieldName]);
2356
1850
  }
1851
+ /** Encoded authoritative values, without form-initialization placeholders. */
1852
+ resolveOriginalValues(processState, ctx, item, currentProviderUser) {
1853
+ const fields = this.getFieldsWithState(processState, ctx, item);
1854
+ return this.resolveFieldDefaults(submissionSchemaSync(Schema.Struct(fields)).fields, currentProviderUser).pipe(Effect.map((defaults) => executableOriginalValues(this.sharedSchema, defaults, processState)));
1855
+ }
1856
+ resolvePresentation(processState, ctx, item) {
1857
+ const presentation = {};
1858
+ const fields = this.getFieldsWithState(processState, ctx, item);
1859
+ const visit = (fields, prefix) => {
1860
+ for (const [name, field] of Object.entries(fields)) {
1861
+ const target = prefix ? `${prefix}.${name}` : name;
1862
+ const label = fieldAnnotation(field.ast, FormLabel);
1863
+ const description = fieldAnnotation(field.ast, FormDescription);
1864
+ const text = fieldAnnotation(field.ast, FormStaticText) ?? fieldAnnotation(field.ast, TEXTBLOCK_CONTENT_SYMBOL) ?? fieldAnnotation(field.ast, LINK_TEXT_SYMBOL);
1865
+ const href = fieldAnnotation(field.ast, LINK_URL_SYMBOL);
1866
+ presentation[target] = {
1867
+ ...typeof label === "string" ? { label } : {},
1868
+ ...typeof description === "string" ? { description } : {},
1869
+ ...typeof text === "string" ? { text } : {},
1870
+ ...typeof href === "string" ? { href } : {}
1871
+ };
1872
+ if (field.ast._tag === "Objects") visit(Object.fromEntries(field.ast.propertySignatures.map((property) => [String(property.name), Schema.make(property.type)])), target);
1873
+ }
1874
+ };
1875
+ visit(fields, "");
1876
+ return presentation;
1877
+ }
2357
1878
  /**
2358
1879
  * Resolves all default values for this Form given the current process state.
2359
1880
  * Re-executes the form function with state to get fields with state-based defaults.
@@ -2365,7 +1886,7 @@ var Form = class extends Step {
2365
1886
  * @returns Record of field names to their resolved default values (flat)
2366
1887
  */
2367
1888
  resolveDefaults(processState, ctx, item, currentProviderUser) {
2368
- return Effect.gen(this, function* () {
1889
+ return Effect.gen({ self: this }, function* () {
2369
1890
  const defaults = this.defaults();
2370
1891
  const fieldsWithState = this.getFieldsWithState(processState, ctx, item);
2371
1892
  const resolvedDefaults = yield* this.resolveFieldDefaults(fieldsWithState, currentProviderUser);
@@ -2373,8 +1894,8 @@ var Form = class extends Step {
2373
1894
  });
2374
1895
  }
2375
1896
  };
2376
- //#endregion
2377
- //#region ../process/src/lib/invitation.ts
1897
+ const getAnnotation = (ast, key) => Option.fromNullishOr(fieldAnnotation(ast, key));
1898
+ // ../process/src/lib/invitation.ts
2378
1899
  /**
2379
1900
  * An invitation for a user to join the organisation with pre-assigned roles.
2380
1901
  *
@@ -2401,8 +1922,7 @@ var Invitation = class extends Construct {
2401
1922
  this.roles = props.roles;
2402
1923
  }
2403
1924
  };
2404
- //#endregion
2405
- //#region ../process/src/lib/list.ts
1925
+ // ../process/src/lib/list.ts
2406
1926
  /**
2407
1927
  * Error thrown when executeItemQuery is called on a List without an itemQuery defined.
2408
1928
  */
@@ -2448,36 +1968,33 @@ const defaultSchemaDescriptions = /* @__PURE__ */ new Set([
2448
1968
  ]);
2449
1969
  function isObjectLikeListColumnAst(ast) {
2450
1970
  switch (ast._tag) {
2451
- case "TypeLiteral":
2452
- case "TupleType": return true;
2453
- case "Refinement": return isObjectLikeListColumnAst(ast.from);
2454
- case "Transformation": return isObjectLikeListColumnAst(ast.to);
1971
+ case "Objects":
1972
+ case "Arrays": return true;
2455
1973
  case "Union": return ast.types.some((type) => isObjectLikeListColumnAst(type));
2456
1974
  default: return false;
2457
1975
  }
2458
1976
  }
2459
1977
  function isScalarListColumnAst(ast) {
1978
+ if (ast.encoding) return !isObjectLikeListColumnAst(ast) && isScalarListColumnAst(SchemaAST.toEncoded(ast));
2460
1979
  switch (ast._tag) {
2461
- case "StringKeyword":
2462
- case "NumberKeyword":
2463
- case "BooleanKeyword": return true;
1980
+ case "String":
1981
+ case "Number":
1982
+ case "Boolean": return true;
2464
1983
  case "Literal": return typeof ast.literal === "string" || typeof ast.literal === "number" || typeof ast.literal === "boolean";
2465
- case "Refinement": return isScalarListColumnAst(ast.from);
2466
- case "Transformation": return isScalarListColumnAst(ast.from) && !isObjectLikeListColumnAst(ast.to);
2467
1984
  case "Union": {
2468
- const sortableMembers = ast.types.filter((type) => !(type._tag === "Literal" && type.literal === null) && type._tag !== "UndefinedKeyword" && type._tag !== "VoidKeyword");
1985
+ const sortableMembers = ast.types.filter((type) => type._tag !== "Null" && type._tag !== "Undefined" && type._tag !== "Void");
2469
1986
  return sortableMembers.length > 0 && sortableMembers.every((member) => isScalarListColumnAst(member));
2470
1987
  }
2471
1988
  default: return false;
2472
1989
  }
2473
1990
  }
2474
1991
  function toListColumn(field, schema, options) {
2475
- const titleAnnotation = schema.ast.annotations[SchemaAST.TitleAnnotationId];
1992
+ const titleAnnotation = SchemaAST.resolveTitle(schema.ast);
2476
1993
  const label = typeof titleAnnotation === "string" ? titleAnnotation : String$1.capitalize(field);
2477
- const visibleInList = schema.ast.annotations[ListVisibleInList] !== false;
2478
- const sortableAnnotation = schema.ast.annotations[ListSortable];
1994
+ const visibleInList = Reflect.get(SchemaAST.resolve(schema.ast) ?? {}, ListVisibleInList) !== false;
1995
+ const sortableAnnotation = Reflect.get(SchemaAST.resolve(schema.ast) ?? {}, ListSortable);
2479
1996
  const sortable = options?.sortable ?? (typeof sortableAnnotation === "boolean" ? sortableAnnotation : visibleInList && isScalarListColumnAst(schema.ast));
2480
- const descriptionAnnotation = schema.ast.annotations[SchemaAST.DescriptionAnnotationId];
1997
+ const descriptionAnnotation = SchemaAST.resolveDescription(schema.ast);
2481
1998
  const description = typeof descriptionAnnotation === "string" && !defaultSchemaDescriptions.has(descriptionAnnotation) ? descriptionAnnotation : void 0;
2482
1999
  return description === void 0 ? {
2483
2000
  field,
@@ -2493,13 +2010,11 @@ function toListColumn(field, schema, options) {
2493
2010
  };
2494
2011
  }
2495
2012
  const collectMetricBreakdownControlsFromAst = (ast) => {
2496
- const metricAnnotation = SchemaAST.getAnnotation(ast, METRIC_BREAKDOWN_SYMBOL);
2013
+ const metricAnnotation = Option.fromNullishOr(Reflect.get(SchemaAST.resolve(ast) ?? {}, METRIC_BREAKDOWN_SYMBOL));
2497
2014
  const metricOptions = Option.getOrUndefined(metricAnnotation);
2498
2015
  const ownControls = isMetricBreakdownOptions(metricOptions) && metricOptions.dataSource === "item" ? metricOptions.controls ?? [] : [];
2499
2016
  switch (ast._tag) {
2500
- case "TypeLiteral": return [...ownControls, ...ast.propertySignatures.flatMap((property) => collectMetricBreakdownControlsFromAst(property.type))];
2501
- case "Refinement": return [...ownControls, ...collectMetricBreakdownControlsFromAst(ast.from)];
2502
- case "Transformation": return [...ownControls, ...collectMetricBreakdownControlsFromAst(ast.to)];
2017
+ case "Objects": return [...ownControls, ...ast.propertySignatures.flatMap((property) => collectMetricBreakdownControlsFromAst(property.type))];
2503
2018
  case "Union": return [...ownControls, ...ast.types.flatMap((type) => collectMetricBreakdownControlsFromAst(type))];
2504
2019
  default: return ownControls;
2505
2020
  }
@@ -2514,14 +2029,12 @@ const DEFAULT_PAGE_SIZE = 20;
2514
2029
  const MAX_PAGE_SIZE = 100;
2515
2030
  function isScalarExportAst(ast) {
2516
2031
  switch (ast._tag) {
2517
- case "StringKeyword":
2518
- case "NumberKeyword":
2519
- case "BooleanKeyword": return true;
2032
+ case "String":
2033
+ case "Number":
2034
+ case "Boolean": return true;
2520
2035
  case "Literal": return ast.literal === null || typeof ast.literal === "string" || typeof ast.literal === "number" || typeof ast.literal === "boolean";
2521
- case "Refinement": return isScalarExportAst(ast.from);
2522
- case "Transformation": return isScalarExportAst(ast.to);
2523
2036
  case "Union": {
2524
- const allowedMembers = ast.types.filter((type) => !(type._tag === "Literal" && type.literal === null) && type._tag !== "UndefinedKeyword" && type._tag !== "VoidKeyword");
2037
+ const allowedMembers = ast.types.filter((type) => type._tag !== "Null" && type._tag !== "Undefined" && type._tag !== "Void");
2525
2038
  return allowedMembers.length > 0 && allowedMembers.every((member) => isScalarExportAst(member));
2526
2039
  }
2527
2040
  default: return false;
@@ -2565,6 +2078,8 @@ function assertExportFieldsHaveQuery(listPath, output, exportOutput, hasExportQu
2565
2078
  var List = class extends Construct {
2566
2079
  isList = true;
2567
2080
  _create;
2081
+ browser;
2082
+ createBrowser;
2568
2083
  createFormFields;
2569
2084
  /** Display name for the list */
2570
2085
  name;
@@ -2576,6 +2091,10 @@ var List = class extends Construct {
2576
2091
  roles;
2577
2092
  /** Output schema defining the shape of list items */
2578
2093
  output;
2094
+ /** Start button metadata; visibility is authorized separately from List access. */
2095
+ startProcess;
2096
+ additionalStartProcesses;
2097
+ anonymousPage;
2579
2098
  /** Default page size */
2580
2099
  defaultPageSize;
2581
2100
  /** The query function */
@@ -2603,9 +2122,40 @@ var List = class extends Construct {
2603
2122
  */
2604
2123
  constructor(scope, id, props) {
2605
2124
  super(scope, id);
2125
+ this.browser = props.browser;
2126
+ this.createBrowser = props.create?.browser;
2606
2127
  this._create = props.create;
2607
2128
  this.createFormFields = props.create?.form();
2608
2129
  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`);
2130
+ if (props.startProcess) {
2131
+ const starts = props.startProcess.startNodes();
2132
+ const start = starts[0];
2133
+ if (starts.length !== 1 || !isForm(start)) throw new Error(`List ${normalizePath(this.node.path)} startProcess must have exactly one start form`);
2134
+ this.startProcess = {
2135
+ path: normalizePath(props.startProcess.node.path),
2136
+ name: props.startProcess.props.name,
2137
+ startStepPath: normalizePath(start.node.path)
2138
+ };
2139
+ }
2140
+ this.additionalStartProcesses = (props.additionalStartProcesses ?? []).map((process) => {
2141
+ const starts = process.startNodes();
2142
+ const start = starts[0];
2143
+ if (starts.length !== 1 || !isForm(start)) throw new Error("List additional starts require exactly one start form");
2144
+ return {
2145
+ path: normalizePath(process.node.path),
2146
+ name: process.props.name,
2147
+ startStepPath: normalizePath(start.node.path)
2148
+ };
2149
+ });
2150
+ if (props.anonymousPage) {
2151
+ const starts = props.anonymousPage.startNodes();
2152
+ const start = starts[0];
2153
+ if (starts.length !== 1 || !isForm(start) || !start.anonymousPage) throw new Error("List Anonymous Page must reference a configured start form");
2154
+ this.anonymousPage = {
2155
+ name: props.anonymousPage.props.name,
2156
+ path: `/public/start/${start.anonymousPage.address}`
2157
+ };
2158
+ }
2609
2159
  this.name = props.name;
2610
2160
  if (props.detailName !== void 0) this.detailName = props.detailName;
2611
2161
  if (props.purpose !== void 0) this.purpose = props.purpose;
@@ -2641,19 +2191,12 @@ var List = class extends Construct {
2641
2191
  createFormMetadata(currentProviderUser) {
2642
2192
  if (!this.createFormFields) return Effect.succeed(null);
2643
2193
  const fields = this.createFormFields;
2644
- const submission = submissionSchemaSync(Schema.Struct(fields));
2645
2194
  const createMutationName = this.createMutationName();
2646
2195
  const createInputTypeName = this.createInputTypeName();
2647
2196
  return Effect.gen(function* () {
2648
- const components = yield* asClientRepresentation(Schema.Struct(fields));
2649
2197
  const defaults = yield* resolveFormFieldDefaults(fields, currentProviderUser);
2650
2198
  return {
2651
- formDefinition: {
2652
- components,
2653
- rules: []
2654
- },
2655
2199
  defaultValues: mergeFormDefaults(getSchemaDefaults(fields), defaults),
2656
- jsonSchema: JSONSchema.make(submission),
2657
2200
  createMutationName,
2658
2201
  createInputTypeName
2659
2202
  };
@@ -2780,32 +2323,6 @@ var List = class extends Construct {
2780
2323
  return Object.entries(this._formFields).map(([field, schema]) => toListColumn(field, schema, { sortable: false }));
2781
2324
  }
2782
2325
  /**
2783
- * Generate the browser-safe form definition for the form fields.
2784
- * List forms do not currently support dynamic rules, so the canonical rule
2785
- * channel is always an empty array.
2786
- * Returns null if no form is defined.
2787
- */
2788
- clientFormDefinition() {
2789
- if (!this._formFields) return Effect.succeed(null);
2790
- const effectSchema = Schema.Struct(this._formFields);
2791
- return asClientRepresentation(effectSchema).pipe(Effect.map((components) => ({
2792
- components,
2793
- rules: []
2794
- })));
2795
- }
2796
- /**
2797
- * Generate JSON Schema for the form's submittable fields.
2798
- * Strips read-only and structural-only fields; removes additionalProperties.
2799
- * Returns null if no form is defined.
2800
- */
2801
- formSubmissionSchema() {
2802
- if (!this._formFields) return null;
2803
- const effectSchema = Schema.Struct(this.editableFormFields());
2804
- const submission = submissionSchemaSync(effectSchema);
2805
- const { additionalProperties: _, ...schema } = JSONSchema.make(submission);
2806
- return schema;
2807
- }
2808
- /**
2809
2326
  * Get default values for the form fields.
2810
2327
  * Returns null if no form is defined.
2811
2328
  */
@@ -2905,8 +2422,7 @@ var List = class extends Construct {
2905
2422
  return normalizePath(this.node.path);
2906
2423
  }
2907
2424
  };
2908
- //#endregion
2909
- //#region ../process/src/lib/node_step.ts
2425
+ // ../process/src/lib/node_step.ts
2910
2426
  /**
2911
2427
  * NodeStep is a concrete implementation of SystemStep that takes execute as a prop.
2912
2428
  *
@@ -2954,8 +2470,7 @@ var NodeStep = class extends SystemStep {
2954
2470
  return this._executeFn(input);
2955
2471
  }
2956
2472
  };
2957
- //#endregion
2958
- //#region ../process/src/lib/org-unit.ts
2473
+ // ../process/src/lib/org-unit.ts
2959
2474
  /**
2960
2475
  * Represents an organizational unit within the hierarchy.
2961
2476
  *
@@ -2993,8 +2508,7 @@ var OrgUnit = class extends Construct {
2993
2508
  if (props.acronym !== void 0) this.acronym = props.acronym;
2994
2509
  }
2995
2510
  };
2996
- //#endregion
2997
- //#region ../process/src/lib/process.ts
2511
+ Data.TaggedError("ProcessActivationConflict");
2998
2512
  var Process = class Process extends Construct {
2999
2513
  static START_NODE = "__start__";
3000
2514
  static END_NODE = "__end__";
@@ -3041,6 +2555,7 @@ var Process = class Process extends Construct {
3041
2555
  return `start${pathToPascalCase(this.node.path)}`;
3042
2556
  }
3043
2557
  start(initialStep) {
2558
+ if (initialStep.props.sla !== void 0) throw new Error(`Start step "${initialStep.node.path}" in process "${this.node.path}" cannot have an SLA`);
3044
2559
  this.graph.addDirectedEdge(Process.START_NODE, initialStep.node.path);
3045
2560
  return wrapInFlowPath(initialStep, this);
3046
2561
  }
@@ -3087,7 +2602,7 @@ var Process = class Process extends Construct {
3087
2602
  const multipleElse = [];
3088
2603
  const orphanElse = [];
3089
2604
  for (const nodeId of this.realNodes()) if (!reachable.has(nodeId)) unreachable.push(nodeId);
3090
- else if (this.graph.outDegree(nodeId) === 0) dangling.push(nodeId);
2605
+ else if ((this.graph.outEdges(nodeId) ?? []).every((edge) => this.graph.getEdgeAttributes(edge)["deadlineName"])) dangling.push(nodeId);
3091
2606
  else {
3092
2607
  const outEdges = this.graph.outEdges(nodeId) ?? [];
3093
2608
  let hasConditional = false;
@@ -3151,8 +2666,7 @@ var Process = class Process extends Construct {
3151
2666
  return result;
3152
2667
  }
3153
2668
  };
3154
- //#endregion
3155
- //#region ../process/src/lib/organisation.ts
2669
+ // ../process/src/lib/organisation.ts
3156
2670
  /**
3157
2671
  * Set of valid IANA timezone identifiers.
3158
2672
  * Cached for performance.
@@ -3191,6 +2705,8 @@ var Organisation = class extends OrgUnit {
3191
2705
  * IANA timezone identifier (e.g., "Europe/Amsterdam", "America/New_York").
3192
2706
  */
3193
2707
  timeZone;
2708
+ platformRef;
2709
+ platformSource;
3194
2710
  /**
3195
2711
  * BCP 47 locale used for organisation-authored date/time display.
3196
2712
  */
@@ -3200,6 +2716,7 @@ var Organisation = class extends OrgUnit {
3200
2716
  * Defines working hours, holidays, and special periods.
3201
2717
  */
3202
2718
  businessCalendar;
2719
+ notificationEmailLayer;
3203
2720
  constructor(props) {
3204
2721
  const timeZone = props.timeZone ?? "UTC";
3205
2722
  validateTimeZone(timeZone);
@@ -3209,8 +2726,11 @@ var Organisation = class extends OrgUnit {
3209
2726
  ...props.acronym !== void 0 && { acronym: props.acronym }
3210
2727
  });
3211
2728
  this.timeZone = timeZone;
2729
+ this.platformRef = props.platformRef;
2730
+ this.platformSource = props.platformSource;
3212
2731
  this.locale = props.locale ?? "en";
3213
2732
  this.businessCalendar = props.businessCalendar;
2733
+ this.notificationEmailLayer = props.notificationEmailLayer;
3214
2734
  }
3215
2735
  /**
3216
2736
  * Find a step by its path relative to the organisation root.
@@ -3370,8 +2890,7 @@ var Organisation = class extends OrgUnit {
3370
2890
  return results;
3371
2891
  }
3372
2892
  };
3373
- //#endregion
3374
- //#region ../process/src/lib/phase.ts
2893
+ // ../process/src/lib/phase.ts
3375
2894
  /**
3376
2895
  * Represents a phase in a process. Steps can be assigned a phase, and
3377
2896
  * will be visually indicates as being part of the given phase in a
@@ -3387,8 +2906,7 @@ var Phase = class extends Construct {
3387
2906
  this.orgUnit = scope;
3388
2907
  }
3389
2908
  };
3390
- //#endregion
3391
- //#region ../process/src/lib/public-form-branding.ts
2909
+ // ../process/src/lib/public-form-branding.ts
3392
2910
  var PublicFormBranding = class extends Construct {
3393
2911
  isPublicFormBranding = true;
3394
2912
  headerHtml;
@@ -3406,8 +2924,7 @@ const normalizeSnippet = (html) => {
3406
2924
  if (html === void 0 || html.trim().length === 0) return;
3407
2925
  return html;
3408
2926
  };
3409
- //#endregion
3410
- //#region ../process/src/lib/role.ts
2927
+ // ../process/src/lib/role.ts
3411
2928
  /**
3412
2929
  * Represents a role within an organizational unit.
3413
2930
  *
@@ -3436,8 +2953,7 @@ var Role = class extends Construct {
3436
2953
  this.orgUnit = scope;
3437
2954
  }
3438
2955
  };
3439
- //#endregion
3440
- //#region ../process/src/lib/schedule.ts
2956
+ // ../process/src/lib/schedule.ts
3441
2957
  /**
3442
2958
  * Schedule types for business-calendar-aware scheduling.
3443
2959
  *
@@ -3548,7 +3064,7 @@ const Schedule = {
3548
3064
  return {
3549
3065
  _tag: "ClockTime",
3550
3066
  from,
3551
- duration: Duration.decode(duration)
3067
+ duration: Duration.fromInputUnsafe(duration)
3552
3068
  };
3553
3069
  },
3554
3070
  /**
@@ -3621,8 +3137,7 @@ const Schedule = {
3621
3137
  }
3622
3138
  }
3623
3139
  };
3624
- //#endregion
3625
- //#region ../process/src/lib/sla.ts
3140
+ // ../process/src/lib/sla.ts
3626
3141
  const DEFAULT_WARNING_AT = .8;
3627
3142
  /**
3628
3143
  * Validates SLA options and returns the warning percentage (0-100).
@@ -3714,8 +3229,7 @@ const Sla = {
3714
3229
  };
3715
3230
  }
3716
3231
  };
3717
- //#endregion
3718
- //#region ../process/src/lib/stats-view.ts
3232
+ // ../process/src/lib/stats-view.ts
3719
3233
  /**
3720
3234
  * Stats view construct for defining custom analytics/visualization screens.
3721
3235
  *
@@ -3768,13 +3282,12 @@ Data.TaggedError("NotASystemStepError");
3768
3282
  Data.TaggedError("SystemStepExecutionError");
3769
3283
  Data.TaggedError("OutputValidationError");
3770
3284
  Data.TaggedError("LongDurationDispatchError");
3771
- Context.Tag("processfocus/process/LongDurationDispatcher")();
3285
+ Context.Service()("processfocus/process/LongDurationDispatcher");
3772
3286
  /**
3773
3287
  * Optional service that lets system steps read their process state at
3774
3288
  * execution time. Used by deferred steps to check idempotency guards
3775
3289
  * (e.g. has this Resend email already been sent on a previous retry?).
3776
3290
  */
3777
- var StepProcessStateReader = class extends Context.Tag("processfocus/process/StepProcessStateReader")() {};
3778
- Context.Tag("processfocus/process/SystemStepExecutor")();
3779
- //#endregion
3780
- export { AppIcons, AppleOAuthProviderConfigSchema, AuthenticationConfig, CognitoOAuthProviderConfigSchema, CurrentStepJobContext, CustomEntitiesConfig, DEFAULT_OAUTH_PROVIDER_SCOPES, DEFAULT_PAGE_SIZE, DocumentStore, ElseBranch, ExecutionFailureNotifications, FlowPath, Form, FormRuleSelf, GoogleOAuthProviderConfigSchema, Invitation, KeycloakOAuthProviderConfigSchema, List, ListSortable, ListUpdateValidationError, ListVisibleInList, LookupAccessor, LookupBuilder, LookupFieldNotFoundError, MAX_PAGE_SIZE, MicrosoftOAuthProviderConfigSchema, NodeStep, OAUTH_PROVIDER_NAMES, OAuthProviderConfigSchema, OAuthProviderNameSchema, OrgUnit, Organisation, PasskeyProviderConfigSchema, Phase, PoliciesConfig, Process, PublicFormBranding, Role, Schedule, SecretClientConfigSchema, Sla, SlackOAuthProviderConfigSchema, StatsView, Step, StepProcessStateReader, SystemStep, coerceAuthorTaggedError, isAuthenticationConfig, isAuthorTaggedError, isCustomEntitiesConfig, isDocumentStore, isForm, isInvitation, isList, isNonRetryableAuthorError, isOrgUnit, isOrganisation, isPoliciesConfig, isProcess, isRole, isStatsView, isStep };
3291
+ var StepProcessStateReader = class extends Context.Service()("processfocus/process/StepProcessStateReader") {};
3292
+ Context.Service()("processfocus/process/SystemStepExecutor");
3293
+ export { AppIcons, AppleOAuthProviderConfigSchema, AuthenticationConfig, CognitoOAuthProviderConfigSchema, CurrentStepJobContext, CustomEntitiesConfig, DEFAULT_OAUTH_PROVIDER_SCOPES, DEFAULT_PAGE_SIZE, DocumentStore, ElseBranch, ExecutionFailureNotifications, FlowPath, Form, GoogleOAuthProviderConfigSchema, Invitation, KeycloakOAuthProviderConfigSchema, List, ListSortable, ListUpdateValidationError, ListVisibleInList, LookupAccessor, LookupBuilder, LookupFieldNotFoundError, MAX_PAGE_SIZE, MicrosoftOAuthProviderConfigSchema, NodeStep, OAUTH_PROVIDER_NAMES, OAuthProviderConfigSchema, OAuthProviderNameSchema, OrgUnit, Organisation, PasskeyProviderConfigSchema, Phase, PoliciesConfig, Process, PublicFormBranding, Role, Schedule, SecretClientConfigSchema, Sla, SlackOAuthProviderConfigSchema, StatsView, Step, StepProcessStateReader, SystemStep, coerceAuthorTaggedError, isAuthenticationConfig, isAuthorTaggedError, isCustomEntitiesConfig, isDocumentStore, isForm, isInvitation, isList, isNonRetryableAuthorError, isOrgUnit, isOrganisation, isPoliciesConfig, isProcess, isRole, isStatsView, isStep };