@entifix/business 0.14.0 → 0.16.0

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.
@@ -2,20 +2,46 @@ import { Invalid } from '@entifix/core';
2
2
  import { Effect, Schema } from 'effect';
3
3
  import type { FragmentCatalog } from '../flow/catalog.js';
4
4
  import type { FragmentKeys } from '../flow/fragment.js';
5
- import { type Slip, type SlipSegment } from '../flow/slip.js';
5
+ import { type Slip, type SlipAudienceEntry, type SlipSegment } from '../flow/slip.js';
6
6
  import { type CompositionRefused, type FlowRequirementsUnmet, type SlipViolation } from '../flow/validate.js';
7
7
  import { type ResolutionRule, Unresolvable } from '../resolve/resolve.js';
8
8
  import type { VerifiedContext } from '../resolve/verified-context.js';
9
9
  /** A gate over what is known when the flow starts. Never over anything else. */
10
10
  export type RecipeGate<I> = (context: VerifiedContext, input: I, segment?: SlipSegment) => boolean;
11
+ /**
12
+ * One line of a segment — an item in a vendor's part of a basket — that a
13
+ * `perLine` step is expanded for. Its `key` names the step (`segment:line:step`)
14
+ * and its parameters are pinned on that step beneath the recipe step's own.
15
+ */
16
+ export interface RecipeLine {
17
+ readonly key: string;
18
+ readonly parameters: Readonly<Record<string, unknown>>;
19
+ }
20
+ /**
21
+ * A branch on an earlier wait's answer: the step runs only when the wait —
22
+ * named as the recipe names it, its `step` or its fragment id, in the same
23
+ * segment — was answered with one of `outcomes`. Unlike `when`, which is
24
+ * decided at composition, this is decided by what the wait is told.
25
+ */
26
+ export interface RecipeGuard {
27
+ readonly wait: string;
28
+ readonly outcomes: readonly string[];
29
+ }
11
30
  /** One step of a recipe: a fragment by its pinned reference, as a string. */
12
31
  export interface RecipeStep<I> {
13
32
  readonly ref: string;
14
33
  /** The step's name in the slip; defaults to the fragment id. */
15
34
  readonly step?: string;
16
35
  readonly when?: RecipeGate<I>;
17
- /** Parameters pinned at composition, read from the context's config. */
18
- readonly parameters?: (context: VerifiedContext) => Readonly<Record<string, unknown>>;
36
+ /** Runs only on these answers of an earlier wait; overrides its stage's. */
37
+ readonly on?: RecipeGuard;
38
+ /**
39
+ * Parameters pinned at composition: from the context's config, from the
40
+ * decoded start input, and from the segment and line the step was expanded
41
+ * for. What a participant is told travels here and nowhere else, so a slip
42
+ * read back says exactly what each call was given.
43
+ */
44
+ readonly parameters?: (context: VerifiedContext, input: I, segment?: SlipSegment, line?: RecipeLine) => Readonly<Record<string, unknown>>;
19
45
  }
20
46
  /**
21
47
  * One stage of a recipe. A `perSegment` stage is expanded once per segment the
@@ -25,6 +51,8 @@ export interface RecipeStep<I> {
25
51
  export interface RecipeStage<I> {
26
52
  readonly name: string;
27
53
  readonly when?: RecipeGate<I>;
54
+ /** A guard every step of the stage carries unless it names its own. */
55
+ readonly on?: RecipeGuard;
28
56
  readonly perSegment?: boolean;
29
57
  readonly steps: readonly RecipeStep<I>[];
30
58
  }
@@ -48,6 +76,18 @@ export interface Recipe<I> {
48
76
  readonly requiresCommitPoint?: boolean;
49
77
  /** The segments a `perSegment` stage expands over. */
50
78
  readonly segments?: (input: I) => readonly SlipSegment[];
79
+ /**
80
+ * The lines a `perLine` step expands over — in its segment when it has one,
81
+ * else across the flow. A `perLine` step in a recipe with no lines is one
82
+ * step, as before.
83
+ */
84
+ readonly lines?: (input: I, segment?: SlipSegment) => readonly RecipeLine[];
85
+ /**
86
+ * Who the flow's events reach beside the flow itself: the organizations and
87
+ * parties it acts for, and a flow entry with the digest of a capability an
88
+ * anonymous caller holds. Pinned on the slip at composition.
89
+ */
90
+ readonly audience?: (input: I, context: VerifiedContext, flowId: string) => readonly SlipAudienceEntry[];
51
91
  readonly resolve?: readonly RecipeResolution[];
52
92
  readonly stages: readonly RecipeStage<I>[];
53
93
  }
@@ -1 +1 @@
1
- {"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../../src/compose/compose.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,OAAO,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MA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;;GAQG;AACH,eAAO,MAAM,qBAAqB,GAAI,CAAC,EACrC,QAAQ,MAAM,CAAC,CAAC,CAAC,EACjB,SAAS,eAAe,EACxB,MAAM,eAAe,CAAC,CAAC,CAAC,KACvB,SAAS,kBAAkB,EAwC3B,CAAC;AAEJ;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,GACrC,UAAU,SAAS,kBAAkB,EAAE,KACtC,IAeF,CAAC"}
@@ -8,17 +8,31 @@ const segmentKey = (segment)=>[
8
8
  segment.vendor,
9
9
  segment.paymentMethod
10
10
  ].filter(Boolean).join('/');
11
- const buildStep = (recipeStep, catalog, context, segment)=>{
11
+ const buildStep = (recipeStep, catalog, context, input, segment, line, guard)=>{
12
12
  var _ref, _recipeStep_step, _ref1;
13
13
  const fragment = catalog.get(recipeStep.ref);
14
14
  const name = (_ref = (_recipeStep_step = recipeStep.step) != null ? _recipeStep_step : fragment == null ? void 0 : fragment.id) != null ? _ref : recipeStep.ref;
15
- const parameters = recipeStep.parameters == null ? void 0 : recipeStep.parameters.call(recipeStep, context);
15
+ const own = recipeStep.parameters == null ? void 0 : recipeStep.parameters.call(recipeStep, context, input, segment, line);
16
+ const parameters = line === undefined ? own : _extends({}, line.parameters, own != null ? own : {});
17
+ const prefix = [
18
+ ...segment === undefined ? [] : [
19
+ segmentKey(segment)
20
+ ],
21
+ ...line === undefined ? [] : [
22
+ line.key
23
+ ]
24
+ ];
16
25
  return _extends({
17
26
  ref: recipeStep.ref,
18
- step: segment === undefined ? name : `${segmentKey(segment)}:${name}`,
27
+ step: [
28
+ ...prefix,
29
+ name
30
+ ].join(':'),
19
31
  cardinality: (_ref1 = fragment == null ? void 0 : fragment.cardinality) != null ? _ref1 : 'one'
20
32
  }, segment === undefined ? {} : {
21
33
  segment
34
+ }, line === undefined ? {} : {
35
+ line: line.key
22
36
  }, (fragment == null ? void 0 : fragment.participant) === undefined ? {} : {
23
37
  participant: fragment.participant
24
38
  }, (fragment == null ? void 0 : fragment.call) === undefined ? {} : {
@@ -27,8 +41,30 @@ const buildStep = (recipeStep, catalog, context, segment)=>{
27
41
  compensation: fragment.compensation
28
42
  }, parameters === undefined ? {} : {
29
43
  parameters
44
+ }, guard === undefined ? {} : {
45
+ guard: {
46
+ // A wait is never expanded per line, so its name in the slip is
47
+ // the segment's prefix and its own name.
48
+ wait: [
49
+ ...segment === undefined ? [] : [
50
+ segmentKey(segment)
51
+ ],
52
+ guard.wait
53
+ ].join(':'),
54
+ outcomes: [
55
+ ...guard.outcomes
56
+ ]
57
+ }
30
58
  });
31
59
  };
60
+ /** One step per line for a `perLine` fragment when the recipe names lines. */ const expand = (recipe, recipeStep, catalog, context, input, segment, stageGuard)=>{
61
+ var _recipeStep_on;
62
+ var _catalog_get;
63
+ const guard = (_recipeStep_on = recipeStep.on) != null ? _recipeStep_on : stageGuard;
64
+ return ((_catalog_get = catalog.get(recipeStep.ref)) == null ? void 0 : _catalog_get.cardinality) === 'perLine' && recipe.lines !== undefined ? recipe.lines(input, segment).map((line)=>buildStep(recipeStep, catalog, context, input, segment, line, guard)) : [
65
+ buildStep(recipeStep, catalog, context, input, segment, undefined, guard)
66
+ ];
67
+ };
32
68
  const resolutionOf = (resolutions, context)=>Effect.forEach(resolutions, ({ useCase, rules })=>{
33
69
  const chosen = dryRun(rules, context);
34
70
  return chosen === undefined ? Effect.fail(new Unresolvable({
@@ -54,7 +90,7 @@ const resolutionOf = (resolutions, context)=>Effect.forEach(resolutions, ({ useC
54
90
  steps: each.flatMap((segment)=>stage.steps.filter((recipeStep)=>{
55
91
  var _ref;
56
92
  return (_ref = recipeStep.when == null ? void 0 : recipeStep.when.call(recipeStep, context, input, segment)) != null ? _ref : true;
57
- }).map((recipeStep)=>buildStep(recipeStep, catalog, context, segment)))
93
+ }).flatMap((recipeStep)=>expand(recipe, recipeStep, catalog, context, input, segment, stage.on)))
58
94
  };
59
95
  }).filter((stage)=>stage.steps.length > 0);
60
96
  return _extends({
@@ -67,6 +103,8 @@ const resolutionOf = (resolutions, context)=>Effect.forEach(resolutions, ({ useC
67
103
  stages,
68
104
  resolution,
69
105
  composedAt: options.composedAt
106
+ }, recipe.audience === undefined ? {} : {
107
+ audience: recipe.audience(input, context, options.flowId)
70
108
  });
71
109
  };
72
110
  const decodeInput = (recipe, input)=>Schema.decodeUnknownEffect(recipe.input)(input).pipe(Effect.mapError((error)=>new Invalid({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/compose/compose.ts"],"sourcesContent":["import { FieldProblem, Invalid } from '@entifix/core';\nimport { Effect, Schema } from 'effect';\n\nimport type { FragmentCatalog } from '../flow/catalog.js';\nimport type { FragmentKeys } from '../flow/fragment.js';\nimport {\n type Slip,\n SLIP_VERSION,\n type SlipResolution,\n type SlipSegment,\n type SlipStep,\n slipSteps,\n} from '../flow/slip.js';\nimport {\n assertValidSlip,\n type CompositionRefused,\n type FlowRequirementsUnmet,\n onlyUnmetRequirements,\n type SlipViolation,\n validateSlip,\n} from '../flow/validate.js';\nimport {\n dryRun,\n type ResolutionRule,\n Unresolvable,\n} from '../resolve/resolve.js';\nimport type { VerifiedContext } from '../resolve/verified-context.js';\n\n/** A gate over what is known when the flow starts. Never over anything else. */\nexport type RecipeGate<I> = (\n context: VerifiedContext,\n input: I,\n segment?: SlipSegment,\n) => boolean;\n\n/** One step of a recipe: a fragment by its pinned reference, as a string. */\nexport interface RecipeStep<I> {\n readonly ref: string;\n /** The step's name in the slip; defaults to the fragment id. */\n readonly step?: string;\n readonly when?: RecipeGate<I>;\n /** Parameters pinned at composition, read from the context's config. */\n readonly parameters?: (\n context: VerifiedContext,\n ) => Readonly<Record<string, unknown>>;\n}\n\n/**\n * One stage of a recipe. A `perSegment` stage is expanded once per segment the\n * start input names — one per vendor, say — each step tagged with its segment\n * and named `<segment key>:<step>`.\n */\nexport interface RecipeStage<I> {\n readonly name: string;\n readonly when?: RecipeGate<I>;\n readonly perSegment?: boolean;\n readonly steps: readonly RecipeStep<I>[];\n}\n\n/** A use case the recipe resolves, recorded on the slip as it was resolved. */\nexport interface RecipeResolution {\n readonly useCase: string;\n readonly rules: readonly ResolutionRule<unknown>[];\n}\n\n/**\n * A named template a slip is composed from. It references fragments by\n * `id@n` strings, never by import, so no domain imports another to take part in\n * a flow.\n */\nexport interface Recipe<I> {\n readonly name: string;\n /** The start input, decoded before anything else is read from it. */\n readonly input: Schema.Codec<I, unknown>;\n /** Keys the start input provides to the first steps, with their schemas. */\n readonly provides?: FragmentKeys;\n /** A checkout needs a commit point even with nothing retriable in it. */\n readonly requiresCommitPoint?: boolean;\n /** The segments a `perSegment` stage expands over. */\n readonly segments?: (input: I) => readonly SlipSegment[];\n readonly resolve?: readonly RecipeResolution[];\n readonly stages: readonly RecipeStage<I>[];\n}\n\n/** What a composition is stamped with: both are inputs, so composing is deterministic. */\nexport interface ComposeOptions {\n readonly flowId: string;\n readonly composedAt: string;\n}\n\nconst segmentKey = (segment: SlipSegment): string =>\n [segment.vendor, segment.paymentMethod].filter(Boolean).join('/');\n\nconst buildStep = <I>(\n recipeStep: RecipeStep<I>,\n catalog: FragmentCatalog,\n context: VerifiedContext,\n segment: SlipSegment | undefined,\n): SlipStep => {\n const fragment = catalog.get(recipeStep.ref);\n const name = recipeStep.step ?? fragment?.id ?? recipeStep.ref;\n const parameters = recipeStep.parameters?.(context);\n return {\n ref: recipeStep.ref,\n step: segment === undefined ? name : `${segmentKey(segment)}:${name}`,\n cardinality: fragment?.cardinality ?? 'one',\n ...(segment === undefined ? {} : { segment }),\n ...(fragment?.participant === undefined\n ? {}\n : { participant: fragment.participant }),\n ...(fragment?.call === undefined ? {} : { call: fragment.call }),\n ...(fragment?.compensation === undefined\n ? {}\n : { compensation: fragment.compensation }),\n ...(parameters === undefined ? {} : { parameters }),\n };\n};\n\nconst resolutionOf = (\n resolutions: readonly RecipeResolution[],\n context: VerifiedContext,\n): Effect.Effect<readonly SlipResolution[], Unresolvable> =>\n Effect.forEach(resolutions, ({ useCase, rules }) => {\n const chosen = dryRun(rules, context);\n return chosen === undefined\n ? Effect.fail(new Unresolvable({ useCase }))\n : Effect.succeed({ useCase, variant: chosen.variant, rule: chosen.rule });\n });\n\n/** Expands the recipe into an unvalidated slip. */\nconst draft = <I>(\n recipe: Recipe<I>,\n catalog: FragmentCatalog,\n context: VerifiedContext,\n input: I,\n resolution: readonly SlipResolution[],\n options: ComposeOptions,\n): Slip => {\n const segments = recipe.segments?.(input) ?? [];\n const stages = recipe.stages\n .filter(stage => stage.when?.(context, input) ?? true)\n .map(stage => {\n const each: readonly (SlipSegment | undefined)[] =\n stage.perSegment === true ? segments : [undefined];\n return {\n name: stage.name,\n steps: each.flatMap(segment =>\n stage.steps\n .filter(\n recipeStep => recipeStep.when?.(context, input, segment) ?? true,\n )\n .map(recipeStep =>\n buildStep(recipeStep, catalog, context, segment),\n ),\n ),\n };\n })\n .filter(stage => stage.steps.length > 0);\n return {\n slipVersion: SLIP_VERSION,\n flowId: options.flowId,\n recipe: recipe.name,\n ...(recipe.requiresCommitPoint === undefined\n ? {}\n : { requiresCommitPoint: recipe.requiresCommitPoint }),\n stages,\n resolution,\n composedAt: options.composedAt,\n };\n};\n\nconst decodeInput = <I>(recipe: Recipe<I>, input: unknown) =>\n Schema.decodeUnknownEffect(recipe.input)(input).pipe(\n Effect.mapError(\n error =>\n new Invalid({\n errors: [\n FieldProblem.make({\n pointer: '',\n detail: error.message,\n code: 'invalidFlowInput',\n }),\n ],\n }),\n ),\n );\n\n/**\n * Composes a recipe into a pinned, validated slip for one caller: decodes the\n * start input, resolves the recipe's use cases, expands per-segment stages,\n * pins versions and parameters, stamps `slipVersion`, validates, and annotates\n * the span with `entifix.slip.version` and `entifix.slip.fragments`.\n *\n * An unknown `id@n` is a `CompositionRefused` carrying `UnknownFragment`, never\n * a throw; a caller who lacks only what steps require is `FlowRequirementsUnmet`. The same context, input and options always give the same slip.\n */\nexport const compose = <I>(\n recipe: Recipe<I>,\n catalog: FragmentCatalog,\n context: VerifiedContext,\n input: unknown,\n options: ComposeOptions,\n): Effect.Effect<\n Slip,\n CompositionRefused | FlowRequirementsUnmet | Unresolvable | Invalid\n> =>\n Effect.gen(function* () {\n const decoded = yield* decodeInput(recipe, input);\n const resolution = yield* resolutionOf(recipe.resolve ?? [], context);\n const slip = yield* assertValidSlip(\n draft(recipe, catalog, context, decoded, resolution, options),\n catalog,\n {\n context,\n ...(recipe.provides === undefined ? {} : { start: recipe.provides }),\n },\n );\n yield* Effect.annotateCurrentSpan({\n 'entifix.slip.version': slip.slipVersion,\n 'entifix.slip.fragments': slipSteps(slip)\n .map(step => step.ref)\n .join(','),\n });\n return slip;\n });\n\n/** One axis value, labelled so a report can say which combination broke. */\nexport interface Labelled<T> {\n readonly label: string;\n readonly value: T;\n}\n\n/** The axes a recipe is enumerated over. */\nexport interface CompositionAxes<I> {\n readonly contexts: readonly Labelled<VerifiedContext>[];\n readonly inputs: readonly Labelled<I>[];\n}\n\n/** How one combination composed. */\nexport interface CompositionOutcome {\n readonly context: string;\n readonly input: string;\n /**\n * `composed`; `unresolvable`, the caller is offered no variant; `unmet`, the\n * caller lacks what a step requires; or `refused`, the slip broke a rule\n * that no caller could repair — a defect.\n */\n readonly outcome: 'composed' | 'unresolvable' | 'unmet' | 'refused';\n readonly violations: readonly SlipViolation[];\n}\n\nconst ENUMERATED: ComposeOptions = {\n flowId: 'enumerated',\n composedAt: '1970-01-01T00:00:00.000Z',\n};\n\n/**\n * Composes the recipe for every context × input and reports each outcome —\n * what a CI job runs to prove that every combination a recipe can produce is a\n * valid slip before it ships. An unresolvable combination is a caller who is\n * offered nothing, and an unmet one a caller who lacks an entitlement, a role\n * or a channel a step requires — neither is a defect, but a host asserts which\n * combinations are which, since a caller wrongly left without an entitlement\n * looks exactly like one rightly refused. A refused combination is a defect.\n */\nexport const enumerateCompositions = <I>(\n recipe: Recipe<I>,\n catalog: FragmentCatalog,\n axes: CompositionAxes<I>,\n): readonly CompositionOutcome[] =>\n axes.contexts.flatMap(context =>\n axes.inputs.map(input => {\n const resolved = Effect.runSync(\n Effect.result(resolutionOf(recipe.resolve ?? [], context.value)),\n );\n if (resolved._tag === 'Failure')\n return {\n context: context.label,\n input: input.label,\n outcome: 'unresolvable' as const,\n violations: [],\n };\n const violations = validateSlip(\n draft(\n recipe,\n catalog,\n context.value,\n input.value,\n resolved.success,\n ENUMERATED,\n ),\n catalog,\n {\n context: context.value,\n ...(recipe.provides === undefined ? {} : { start: recipe.provides }),\n },\n );\n return {\n context: context.label,\n input: input.label,\n outcome:\n violations.length === 0\n ? ('composed' as const)\n : onlyUnmetRequirements(violations)\n ? ('unmet' as const)\n : ('refused' as const),\n violations,\n };\n }),\n );\n\n/**\n * Throws, listing every refused combination, unless all of them composed,\n * were unresolvable or were unmet. Framework-neutral on purpose: any test runner reports a\n * thrown error.\n */\nexport const expectAllCompositionsValid = (\n outcomes: readonly CompositionOutcome[],\n): void => {\n const refused = outcomes.filter(outcome => outcome.outcome === 'refused');\n if (refused.length > 0)\n throw new Error(\n `${String(refused.length)} composition(s) are not valid slips:\\n` +\n refused\n .map(\n outcome =>\n ` ${outcome.context} × ${outcome.input}: ` +\n outcome.violations\n .map(violation => `${violation.tag} (${violation.detail})`)\n .join('; '),\n )\n .join('\\n'),\n );\n};\n"],"names":["FieldProblem","Invalid","Effect","Schema","SLIP_VERSION","slipSteps","assertValidSlip","onlyUnmetRequirements","validateSlip","dryRun","Unresolvable","segmentKey","segment","vendor","paymentMethod","filter","Boolean","join","buildStep","recipeStep","catalog","context","fragment","get","ref","name","step","id","parameters","undefined","cardinality","participant","call","compensation","resolutionOf","resolutions","forEach","useCase","rules","chosen","fail","succeed","variant","rule","draft","recipe","input","resolution","options","segments","stages","stage","when","map","each","perSegment","steps","flatMap","length","slipVersion","flowId","requiresCommitPoint","composedAt","decodeInput","decodeUnknownEffect","pipe","mapError","error","errors","make","pointer","detail","message","code","compose","gen","decoded","resolve","slip","provides","start","annotateCurrentSpan","ENUMERATED","enumerateCompositions","axes","contexts","inputs","resolved","runSync","result","value","_tag","label","outcome","violations","success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CAAC;AAEhB,EAAE"}
1
+ {"version":3,"sources":["../../src/compose/compose.ts"],"sourcesContent":["import { FieldProblem, Invalid } from '@entifix/core';\nimport { Effect, Schema } from 'effect';\n\nimport type { FragmentCatalog } from '../flow/catalog.js';\nimport type { FragmentKeys } from '../flow/fragment.js';\nimport {\n type Slip,\n SLIP_VERSION,\n type SlipAudienceEntry,\n type SlipResolution,\n type SlipSegment,\n type SlipStep,\n slipSteps,\n} from '../flow/slip.js';\nimport {\n assertValidSlip,\n type CompositionRefused,\n type FlowRequirementsUnmet,\n onlyUnmetRequirements,\n type SlipViolation,\n validateSlip,\n} from '../flow/validate.js';\nimport {\n dryRun,\n type ResolutionRule,\n Unresolvable,\n} from '../resolve/resolve.js';\nimport type { VerifiedContext } from '../resolve/verified-context.js';\n\n/** A gate over what is known when the flow starts. Never over anything else. */\nexport type RecipeGate<I> = (\n context: VerifiedContext,\n input: I,\n segment?: SlipSegment,\n) => boolean;\n\n/**\n * One line of a segment — an item in a vendor's part of a basket — that a\n * `perLine` step is expanded for. Its `key` names the step (`segment:line:step`)\n * and its parameters are pinned on that step beneath the recipe step's own.\n */\nexport interface RecipeLine {\n readonly key: string;\n readonly parameters: Readonly<Record<string, unknown>>;\n}\n\n/**\n * A branch on an earlier wait's answer: the step runs only when the wait —\n * named as the recipe names it, its `step` or its fragment id, in the same\n * segment — was answered with one of `outcomes`. Unlike `when`, which is\n * decided at composition, this is decided by what the wait is told.\n */\nexport interface RecipeGuard {\n readonly wait: string;\n readonly outcomes: readonly string[];\n}\n\n/** One step of a recipe: a fragment by its pinned reference, as a string. */\nexport interface RecipeStep<I> {\n readonly ref: string;\n /** The step's name in the slip; defaults to the fragment id. */\n readonly step?: string;\n readonly when?: RecipeGate<I>;\n /** Runs only on these answers of an earlier wait; overrides its stage's. */\n readonly on?: RecipeGuard;\n /**\n * Parameters pinned at composition: from the context's config, from the\n * decoded start input, and from the segment and line the step was expanded\n * for. What a participant is told travels here and nowhere else, so a slip\n * read back says exactly what each call was given.\n */\n readonly parameters?: (\n context: VerifiedContext,\n input: I,\n segment?: SlipSegment,\n line?: RecipeLine,\n ) => Readonly<Record<string, unknown>>;\n}\n\n/**\n * One stage of a recipe. A `perSegment` stage is expanded once per segment the\n * start input names — one per vendor, say — each step tagged with its segment\n * and named `<segment key>:<step>`.\n */\nexport interface RecipeStage<I> {\n readonly name: string;\n readonly when?: RecipeGate<I>;\n /** A guard every step of the stage carries unless it names its own. */\n readonly on?: RecipeGuard;\n readonly perSegment?: boolean;\n readonly steps: readonly RecipeStep<I>[];\n}\n\n/** A use case the recipe resolves, recorded on the slip as it was resolved. */\nexport interface RecipeResolution {\n readonly useCase: string;\n readonly rules: readonly ResolutionRule<unknown>[];\n}\n\n/**\n * A named template a slip is composed from. It references fragments by\n * `id@n` strings, never by import, so no domain imports another to take part in\n * a flow.\n */\nexport interface Recipe<I> {\n readonly name: string;\n /** The start input, decoded before anything else is read from it. */\n readonly input: Schema.Codec<I, unknown>;\n /** Keys the start input provides to the first steps, with their schemas. */\n readonly provides?: FragmentKeys;\n /** A checkout needs a commit point even with nothing retriable in it. */\n readonly requiresCommitPoint?: boolean;\n /** The segments a `perSegment` stage expands over. */\n readonly segments?: (input: I) => readonly SlipSegment[];\n /**\n * The lines a `perLine` step expands over — in its segment when it has one,\n * else across the flow. A `perLine` step in a recipe with no lines is one\n * step, as before.\n */\n readonly lines?: (input: I, segment?: SlipSegment) => readonly RecipeLine[];\n /**\n * Who the flow's events reach beside the flow itself: the organizations and\n * parties it acts for, and a flow entry with the digest of a capability an\n * anonymous caller holds. Pinned on the slip at composition.\n */\n readonly audience?: (\n input: I,\n context: VerifiedContext,\n flowId: string,\n ) => readonly SlipAudienceEntry[];\n readonly resolve?: readonly RecipeResolution[];\n readonly stages: readonly RecipeStage<I>[];\n}\n\n/** What a composition is stamped with: both are inputs, so composing is deterministic. */\nexport interface ComposeOptions {\n readonly flowId: string;\n readonly composedAt: string;\n}\n\nconst segmentKey = (segment: SlipSegment): string =>\n [segment.vendor, segment.paymentMethod].filter(Boolean).join('/');\n\nconst buildStep = <I>(\n recipeStep: RecipeStep<I>,\n catalog: FragmentCatalog,\n context: VerifiedContext,\n input: I,\n segment: SlipSegment | undefined,\n line: RecipeLine | undefined,\n guard: RecipeGuard | undefined,\n): SlipStep => {\n const fragment = catalog.get(recipeStep.ref);\n const name = recipeStep.step ?? fragment?.id ?? recipeStep.ref;\n const own = recipeStep.parameters?.(context, input, segment, line);\n const parameters =\n line === undefined ? own : { ...line.parameters, ...(own ?? {}) };\n const prefix = [\n ...(segment === undefined ? [] : [segmentKey(segment)]),\n ...(line === undefined ? [] : [line.key]),\n ];\n return {\n ref: recipeStep.ref,\n step: [...prefix, name].join(':'),\n cardinality: fragment?.cardinality ?? 'one',\n ...(segment === undefined ? {} : { segment }),\n ...(line === undefined ? {} : { line: line.key }),\n ...(fragment?.participant === undefined\n ? {}\n : { participant: fragment.participant }),\n ...(fragment?.call === undefined ? {} : { call: fragment.call }),\n ...(fragment?.compensation === undefined\n ? {}\n : { compensation: fragment.compensation }),\n ...(parameters === undefined ? {} : { parameters }),\n ...(guard === undefined\n ? {}\n : {\n guard: {\n // A wait is never expanded per line, so its name in the slip is\n // the segment's prefix and its own name.\n wait: [\n ...(segment === undefined ? [] : [segmentKey(segment)]),\n guard.wait,\n ].join(':'),\n outcomes: [...guard.outcomes],\n },\n }),\n };\n};\n\n/** One step per line for a `perLine` fragment when the recipe names lines. */\nconst expand = <I>(\n recipe: Recipe<I>,\n recipeStep: RecipeStep<I>,\n catalog: FragmentCatalog,\n context: VerifiedContext,\n input: I,\n segment: SlipSegment | undefined,\n stageGuard: RecipeGuard | undefined,\n): readonly SlipStep[] => {\n const guard = recipeStep.on ?? stageGuard;\n return catalog.get(recipeStep.ref)?.cardinality === 'perLine' &&\n recipe.lines !== undefined\n ? recipe\n .lines(input, segment)\n .map(line =>\n buildStep(recipeStep, catalog, context, input, segment, line, guard),\n )\n : [\n buildStep(\n recipeStep,\n catalog,\n context,\n input,\n segment,\n undefined,\n guard,\n ),\n ];\n};\n\nconst resolutionOf = (\n resolutions: readonly RecipeResolution[],\n context: VerifiedContext,\n): Effect.Effect<readonly SlipResolution[], Unresolvable> =>\n Effect.forEach(resolutions, ({ useCase, rules }) => {\n const chosen = dryRun(rules, context);\n return chosen === undefined\n ? Effect.fail(new Unresolvable({ useCase }))\n : Effect.succeed({ useCase, variant: chosen.variant, rule: chosen.rule });\n });\n\n/** Expands the recipe into an unvalidated slip. */\nconst draft = <I>(\n recipe: Recipe<I>,\n catalog: FragmentCatalog,\n context: VerifiedContext,\n input: I,\n resolution: readonly SlipResolution[],\n options: ComposeOptions,\n): Slip => {\n const segments = recipe.segments?.(input) ?? [];\n const stages = recipe.stages\n .filter(stage => stage.when?.(context, input) ?? true)\n .map(stage => {\n const each: readonly (SlipSegment | undefined)[] =\n stage.perSegment === true ? segments : [undefined];\n return {\n name: stage.name,\n steps: each.flatMap(segment =>\n stage.steps\n .filter(\n recipeStep => recipeStep.when?.(context, input, segment) ?? true,\n )\n .flatMap(recipeStep =>\n expand(\n recipe,\n recipeStep,\n catalog,\n context,\n input,\n segment,\n stage.on,\n ),\n ),\n ),\n };\n })\n .filter(stage => stage.steps.length > 0);\n return {\n slipVersion: SLIP_VERSION,\n flowId: options.flowId,\n recipe: recipe.name,\n ...(recipe.requiresCommitPoint === undefined\n ? {}\n : { requiresCommitPoint: recipe.requiresCommitPoint }),\n stages,\n resolution,\n composedAt: options.composedAt,\n ...(recipe.audience === undefined\n ? {}\n : { audience: recipe.audience(input, context, options.flowId) }),\n };\n};\n\nconst decodeInput = <I>(recipe: Recipe<I>, input: unknown) =>\n Schema.decodeUnknownEffect(recipe.input)(input).pipe(\n Effect.mapError(\n error =>\n new Invalid({\n errors: [\n FieldProblem.make({\n pointer: '',\n detail: error.message,\n code: 'invalidFlowInput',\n }),\n ],\n }),\n ),\n );\n\n/**\n * Composes a recipe into a pinned, validated slip for one caller: decodes the\n * start input, resolves the recipe's use cases, expands per-segment stages,\n * pins versions and parameters, stamps `slipVersion`, validates, and annotates\n * the span with `entifix.slip.version` and `entifix.slip.fragments`.\n *\n * An unknown `id@n` is a `CompositionRefused` carrying `UnknownFragment`, never\n * a throw; a caller who lacks only what steps require is `FlowRequirementsUnmet`. The same context, input and options always give the same slip.\n */\nexport const compose = <I>(\n recipe: Recipe<I>,\n catalog: FragmentCatalog,\n context: VerifiedContext,\n input: unknown,\n options: ComposeOptions,\n): Effect.Effect<\n Slip,\n CompositionRefused | FlowRequirementsUnmet | Unresolvable | Invalid\n> =>\n Effect.gen(function* () {\n const decoded = yield* decodeInput(recipe, input);\n const resolution = yield* resolutionOf(recipe.resolve ?? [], context);\n const slip = yield* assertValidSlip(\n draft(recipe, catalog, context, decoded, resolution, options),\n catalog,\n {\n context,\n ...(recipe.provides === undefined ? {} : { start: recipe.provides }),\n },\n );\n yield* Effect.annotateCurrentSpan({\n 'entifix.slip.version': slip.slipVersion,\n 'entifix.slip.fragments': slipSteps(slip)\n .map(step => step.ref)\n .join(','),\n });\n return slip;\n });\n\n/** One axis value, labelled so a report can say which combination broke. */\nexport interface Labelled<T> {\n readonly label: string;\n readonly value: T;\n}\n\n/** The axes a recipe is enumerated over. */\nexport interface CompositionAxes<I> {\n readonly contexts: readonly Labelled<VerifiedContext>[];\n readonly inputs: readonly Labelled<I>[];\n}\n\n/** How one combination composed. */\nexport interface CompositionOutcome {\n readonly context: string;\n readonly input: string;\n /**\n * `composed`; `unresolvable`, the caller is offered no variant; `unmet`, the\n * caller lacks what a step requires; or `refused`, the slip broke a rule\n * that no caller could repair — a defect.\n */\n readonly outcome: 'composed' | 'unresolvable' | 'unmet' | 'refused';\n readonly violations: readonly SlipViolation[];\n}\n\nconst ENUMERATED: ComposeOptions = {\n flowId: 'enumerated',\n composedAt: '1970-01-01T00:00:00.000Z',\n};\n\n/**\n * Composes the recipe for every context × input and reports each outcome —\n * what a CI job runs to prove that every combination a recipe can produce is a\n * valid slip before it ships. An unresolvable combination is a caller who is\n * offered nothing, and an unmet one a caller who lacks an entitlement, a role\n * or a channel a step requires — neither is a defect, but a host asserts which\n * combinations are which, since a caller wrongly left without an entitlement\n * looks exactly like one rightly refused. A refused combination is a defect.\n */\nexport const enumerateCompositions = <I>(\n recipe: Recipe<I>,\n catalog: FragmentCatalog,\n axes: CompositionAxes<I>,\n): readonly CompositionOutcome[] =>\n axes.contexts.flatMap(context =>\n axes.inputs.map(input => {\n const resolved = Effect.runSync(\n Effect.result(resolutionOf(recipe.resolve ?? [], context.value)),\n );\n if (resolved._tag === 'Failure')\n return {\n context: context.label,\n input: input.label,\n outcome: 'unresolvable' as const,\n violations: [],\n };\n const violations = validateSlip(\n draft(\n recipe,\n catalog,\n context.value,\n input.value,\n resolved.success,\n ENUMERATED,\n ),\n catalog,\n {\n context: context.value,\n ...(recipe.provides === undefined ? {} : { start: recipe.provides }),\n },\n );\n return {\n context: context.label,\n input: input.label,\n outcome:\n violations.length === 0\n ? ('composed' as const)\n : onlyUnmetRequirements(violations)\n ? ('unmet' as const)\n : ('refused' as const),\n violations,\n };\n }),\n );\n\n/**\n * Throws, listing every refused combination, unless all of them composed,\n * were unresolvable or were unmet. Framework-neutral on purpose: any test runner reports a\n * thrown error.\n */\nexport const expectAllCompositionsValid = (\n outcomes: readonly CompositionOutcome[],\n): void => {\n const refused = outcomes.filter(outcome => outcome.outcome === 'refused');\n if (refused.length > 0)\n throw new Error(\n `${String(refused.length)} composition(s) are not valid slips:\\n` +\n refused\n .map(\n outcome =>\n ` ${outcome.context} × ${outcome.input}: ` +\n outcome.violations\n .map(violation => `${violation.tag} (${violation.detail})`)\n .join('; '),\n )\n .join('\\n'),\n );\n};\n"],"names":["FieldProblem","Invalid","Effect","Schema","SLIP_VERSION","slipSteps","assertValidSlip","onlyUnmetRequirements","validateSlip","dryRun","Unresolvable","segmentKey","segment","vendor","paymentMethod","filter","Boolean","join","buildStep","recipeStep","catalog","context","input","line","guard","fragment","get","ref","name","step","id","own","parameters","undefined","prefix","key","cardinality","participant","call","compensation","wait","outcomes","expand","recipe","stageGuard","on","lines","map","resolutionOf","resolutions","forEach","useCase","rules","chosen","fail","succeed","variant","rule","draft","resolution","options","segments","stages","stage","when","each","perSegment","steps","flatMap","length","slipVersion","flowId","requiresCommitPoint","composedAt","audience","decodeInput","decodeUnknownEffect","pipe","mapError","error","errors","make","pointer","detail","message","code","compose","gen","decoded","resolve","slip","provides","start","annotateCurrentSpan","ENUMERATED","enumerateCompositions","axes","contexts","inputs","resolved","runSync","result","value","_tag","label","outcome","violations","success","expectAllCompositionsValid","refused","Error","String","violation","tag"],"mappings":";AAAA,SAASA,YAAY,EAAEC,OAAO,QAAQ,gBAAgB;AACtD,SAASC,MAAM,EAAEC,MAAM,QAAQ,SAAS;AAIxC,SAEEC,YAAY,EAKZC,SAAS,QACJ,kBAAkB;AACzB,SACEC,eAAe,EAGfC,qBAAqB,EAErBC,YAAY,QACP,sBAAsB;AAC7B,SACEC,MAAM,EAENC,YAAY,QACP,wBAAwB;AAkH/B,MAAMC,aAAa,CAACC,UAClB;QAACA,QAAQC,MAAM;QAAED,QAAQE,aAAa;KAAC,CAACC,MAAM,CAACC,SAASC,IAAI,CAAC;AAE/D,MAAMC,YAAY,CAChBC,YACAC,SACAC,SACAC,OACAV,SACAW,MACAC;QAGaL,MAAAA;IADb,MAAMM,WAAWL,QAAQM,GAAG,CAACP,WAAWQ,GAAG;IAC3C,MAAMC,QAAOT,QAAAA,mBAAAA,WAAWU,IAAI,YAAfV,mBAAmBM,4BAAAA,SAAUK,EAAE,YAA/BX,OAAmCA,WAAWQ,GAAG;IAC9D,MAAMI,MAAMZ,WAAWa,UAAU,oBAArBb,WAAWa,UAAU,MAArBb,YAAwBE,SAASC,OAAOV,SAASW;IAC7D,MAAMS,aACJT,SAASU,YAAYF,MAAM,aAAKR,KAAKS,UAAU,EAAMD,cAAAA,MAAO,CAAC;IAC/D,MAAMG,SAAS;WACTtB,YAAYqB,YAAY,EAAE,GAAG;YAACtB,WAAWC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ACG9D,GAAG,CACF0D,CAAAA,UACE,CAAC,EAAE,EAAEA,QAAQpF,OAAO,CAAC,GAAG,EAAEoF,QAAQnF,KAAK,CAAC,EAAE,CAAC,GAC3CmF,QAAQC,UAAU,CACf3D,GAAG,CAACiE,CAAAA,YAAa,GAAGA,UAAUC,GAAG,CAAC,EAAE,EAAED,UAAU7B,MAAM,CAAC,CAAC,CAAC,EACzDlE,IAAI,CAAC,OAEXA,IAAI,CAAC;AAEhB,EAAE"}
@@ -75,6 +75,8 @@ export interface VerbEndpoint<R> {
75
75
  /** Defaults to the group's write guard. */
76
76
  readonly guard?: EntityApiGuard;
77
77
  readonly idempotent?: EndpointIdempotency;
78
+ /** The verb starts a flow and answers `202` with what to follow. */
79
+ readonly accepted?: boolean;
78
80
  readonly handler: (request: EntityApiRequest, context: EntityApiContext) => Effect.Effect<unknown, EntifixFailure, R>;
79
81
  /**
80
82
  * The same verb over a selection, for a record-bound verb that also sits in
@@ -1 +1 @@
1
- {"version":3,"file":"entity-api.d.ts","sourceRoot":"","sources":["../../src/entity-api/entity-api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,MAAM,EACX,KAAK,iBAAiB,EACtB,KAAK,QAAQ,EAEb,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACxB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEtE,8DAA8D;AAC9D,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,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AC;IAElC,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;IACtC,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;IAChB,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;CACrB;AAED,+DAA+D;AAC/D,KAAK,KAAK,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;AAExE;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAC1B,CAAC,SAAS,MAAM,EAChB,KAAK,CAAC,CAAC,SAAS,MAAM,EAEtB,KAAK,CAAC,CAAC,SAAS,gBAAgB,CAAC,CAAC,EAAE,GAAG,CAAC,EAExC,QAAQ,iBAAiB,CAAC,CAAC,CAAC,EAC5B,KAAK,CAAC,EAEN,SAAS,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,KAC1C,oBAAoB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAA+B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/entity-api/entity-api.ts"],"sourcesContent":["import {\n type EndpointIdempotency,\n type EndpointSchema,\n type EntifixEnvelopeLink,\n type EntifixFailure,\n type Entity,\n type EntityConstructor,\n type EntityId,\n extractUseCase,\n type FailureClass,\n type FilterGroup,\n type MetaUseCase,\n type UseCaseConstructor,\n} from '@entifix/core';\nimport type { Effect } from 'effect';\n\nimport type { RequestPrincipal } from '../request/request-context.js';\nimport type { ResolutionRule } from '../resolve/resolve.js';\nimport type { VerifiedContext } from '../resolve/verified-context.js';\n\n/** The five generic verbs an entity's endpoints can serve. */\nexport type EntityApiVerb = 'list' | 'get' | 'create' | 'update' | 'delete';\n\n/**\n * Who may reach an entity's endpoints. The permission is derived from the\n * entity and the verb, so it is never written here.\n */\nexport type EntityApiGuard =\n | { readonly kind: 'public' }\n | { readonly kind: 'permission' }\n | { readonly kind: 'organization' }\n | { readonly kind: 'crossing'; readonly organization: boolean };\n\n/** The affordances an entity's endpoints derive from the verbs they serve. */\nexport interface EntityApiLinks {\n readonly record: (id: EntityId) => EntifixEnvelopeLink[];\n readonly collection: () => EntifixEnvelopeLink[];\n}\n\n/** What a `prepare`, an override or a verb knows about the caller. */\nexport interface EntityApiContext {\n readonly organizationId?: string;\n readonly principal?: RequestPrincipal;\n readonly verified?: VerifiedContext;\n readonly links: EntityApiLinks;\n}\n\n/** What an override's handler receives: the decoded parts of its request. */\nexport interface EntityApiRequest {\n readonly params?: { readonly id?: string };\n readonly payload?: unknown;\n}\n\n/**\n * Which records of an entity a caller may see: every one, none, or those a\n * filter keeps ([ADR 0015](../../../../../docs/adr/0015-composed-flows-and-use-case-resolution.md)).\n * A filter is conjoined onto the load request, so a query string can only\n * narrow it further and no `or` in it can escape.\n */\nexport type Narrowing<T extends Entity> =\n 'unscoped' | 'nothing' | FilterGroup<T>;\n\n/**\n * A read's narrowing as ordered resolver rules over the verified context: the\n * first variant the caller is entitled to and whose predicate holds builds the\n * narrowing. A caller no rule matches sees **nothing** — the direction a\n * missing rule must fail in.\n */\nexport type NarrowingRules<T extends Entity> = readonly ResolutionRule<\n (context: VerifiedContext) => Narrowing<T>\n>[];\n\n/**\n * One verb served by a handler of the host's instead of the generic one. It\n * keeps the group's path and links, and may change the guard, the payload,\n * the failures and the idempotency the verb declares.\n */\nexport interface EntityVerbOverride<R> {\n readonly guard?: EntityApiGuard;\n readonly idempotent?: EndpointIdempotency;\n readonly errors?: readonly FailureClass[];\n /** The body the verb takes instead of an entity envelope. */\n readonly payload?: EndpointSchema;\n readonly handler: (\n request: EntityApiRequest,\n context: EntityApiContext,\n ) => Effect.Effect<unknown, EntifixFailure, R>;\n}\n\n/**\n * A `@useCase()` verb's endpoint: its path, method, permission and contract\n * come from the declaration, and only who may call it and what it does are\n * written here.\n */\nexport interface VerbEndpoint<R> {\n readonly useCase: MetaUseCase;\n /** Defaults to the group's write guard. */\n readonly guard?: EntityApiGuard;\n readonly idempotent?: EndpointIdempotency;\n readonly handler: (\n request: EntityApiRequest,\n context: EntityApiContext,\n ) => Effect.Effect<unknown, EntifixFailure, R>;\n /**\n * The same verb over a selection, for a record-bound verb that also sits in\n * a collection cell (`alsoAt`): one permission for one act, whether it is\n * asked of a record or of twenty. Required exactly when that cell is\n * declared; its request carries the selection as its payload.\n */\n readonly bulk?: (\n request: EntityApiRequest,\n context: EntityApiContext,\n ) => Effect.Effect<unknown, EntifixFailure, R>;\n}\n\n/** Serve a `@useCase()` class's verb on its entity's endpoints. */\nexport const verbEndpoint = <\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- inferred from the options\n const O extends Omit<VerbEndpoint<any>, 'useCase'>,\n>(\n useCaseClass: UseCaseConstructor,\n options: O,\n): O & { readonly useCase: MetaUseCase } => ({\n ...options,\n useCase: extractUseCase(useCaseClass),\n});\n\n/** What an entity's endpoints serve, and under which rules. */\nexport interface EntityApiOptions<T extends Entity, R> {\n readonly verbs: readonly EntityApiVerb[];\n /** One guard for every verb, or one for the reads and one for the writes. */\n readonly guard:\n | EntityApiGuard\n | { readonly read: EntityApiGuard; readonly write: EntityApiGuard };\n /** Narrows the reads, and the facet counts, to what this caller may see. */\n readonly narrowing?: NarrowingRules<T>;\n /** Serve `$facets` beside the list, under the list's guard and narrowing. */\n readonly facets?: boolean;\n /** Runs on every generic create and update, before the save. */\n readonly prepare?: (\n entity: T,\n context: EntityApiContext & { readonly verb: 'create' | 'update' },\n ) => Effect.Effect<T, EntifixFailure, R>;\n /** The business failures `prepare` may answer with, for the contract. */\n readonly errors?: readonly FailureClass[];\n readonly override?: Partial<Record<EntityApiVerb, EntityVerbOverride<R>>>;\n /**\n * The entity's `@useCase()` verbs, one endpoint each. Every verb the entity\n * declares must be here and none another entity declares, or serving the\n * declaration throws.\n */\n readonly useCases?: readonly VerbEndpoint<R>[];\n}\n\n/**\n * An entity's endpoints as a value: which verbs, behind which guards, with\n * which handlers. Declaring them needs no HTTP — a domain's cell declares, and\n * the shell serves the declaration with `entityApi`\n * ([ADR 0020](../../../../../docs/adr/0020-endpoints-are-descriptors-and-the-shell-builds-an-httpapi.md)).\n */\nexport interface EntityApiDeclaration<\n T extends Entity,\n K extends string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- inferred from the options\n O extends EntityApiOptions<T, any>,\n> {\n readonly entity: EntityConstructor<T>;\n readonly key: K;\n readonly options: O;\n}\n\n/** `O`, with every key `Shape` does not name typed `never`. */\ntype Exact<O, Shape> = O & Record<Exclude<keyof O, keyof Shape>, never>;\n\n/**\n * Declare an entity's endpoints, to be served by the shell. An option the\n * declaration does not know is a compile error rather than a value nobody\n * reads — `compositions` included, which the shell adds when it serves.\n */\nexport const defineEntityApi = <\n T extends Entity,\n const K extends string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- inferred from the options\n const O extends EntityApiOptions<T, any>,\n>(\n entity: EntityConstructor<T>,\n key: K,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- inferred from the options\n options: Exact<O, EntityApiOptions<T, any>>,\n): EntityApiDeclaration<T, K, O> => ({ entity, key, options });\n"],"names":["extractUseCase","verbEndpoint","useCaseClass","options","useCase","defineEntityApi","entity","key"],"mappings":";AAAA,SAQEA,cAAc,QAKT,gBAAgB;AAsGvB,iEAAiE,GACjE,OAAO,MAAMC,eAAe,CAI1BC,cACAC,UAC2C,aACxCA;QACHC,SAASJ,eAAeE;OACvB;AAiDH;;;;CAIC,GACD,OAAO,MAAMG,kBAAkB,CAM7BC,QACAC,KACA,2FAA2F;AAC3FJ,UACmC,CAAA;QAAEG;QAAQC;QAAKJ;IAAQ,CAAA,EAAG"}
1
+ {"version":3,"sources":["../../src/entity-api/entity-api.ts"],"sourcesContent":["import {\n type EndpointIdempotency,\n type EndpointSchema,\n type EntifixEnvelopeLink,\n type EntifixFailure,\n type Entity,\n type EntityConstructor,\n type EntityId,\n extractUseCase,\n type FailureClass,\n type FilterGroup,\n type MetaUseCase,\n type UseCaseConstructor,\n} from '@entifix/core';\nimport type { Effect } from 'effect';\n\nimport type { RequestPrincipal } from '../request/request-context.js';\nimport type { ResolutionRule } from '../resolve/resolve.js';\nimport type { VerifiedContext } from '../resolve/verified-context.js';\n\n/** The five generic verbs an entity's endpoints can serve. */\nexport type EntityApiVerb = 'list' | 'get' | 'create' | 'update' | 'delete';\n\n/**\n * Who may reach an entity's endpoints. The permission is derived from the\n * entity and the verb, so it is never written here.\n */\nexport type EntityApiGuard =\n | { readonly kind: 'public' }\n | { readonly kind: 'permission' }\n | { readonly kind: 'organization' }\n | { readonly kind: 'crossing'; readonly organization: boolean };\n\n/** The affordances an entity's endpoints derive from the verbs they serve. */\nexport interface EntityApiLinks {\n readonly record: (id: EntityId) => EntifixEnvelopeLink[];\n readonly collection: () => EntifixEnvelopeLink[];\n}\n\n/** What a `prepare`, an override or a verb knows about the caller. */\nexport interface EntityApiContext {\n readonly organizationId?: string;\n readonly principal?: RequestPrincipal;\n readonly verified?: VerifiedContext;\n readonly links: EntityApiLinks;\n}\n\n/** What an override's handler receives: the decoded parts of its request. */\nexport interface EntityApiRequest {\n readonly params?: { readonly id?: string };\n readonly payload?: unknown;\n}\n\n/**\n * Which records of an entity a caller may see: every one, none, or those a\n * filter keeps ([ADR 0015](../../../../../docs/adr/0015-composed-flows-and-use-case-resolution.md)).\n * A filter is conjoined onto the load request, so a query string can only\n * narrow it further and no `or` in it can escape.\n */\nexport type Narrowing<T extends Entity> =\n 'unscoped' | 'nothing' | FilterGroup<T>;\n\n/**\n * A read's narrowing as ordered resolver rules over the verified context: the\n * first variant the caller is entitled to and whose predicate holds builds the\n * narrowing. A caller no rule matches sees **nothing** — the direction a\n * missing rule must fail in.\n */\nexport type NarrowingRules<T extends Entity> = readonly ResolutionRule<\n (context: VerifiedContext) => Narrowing<T>\n>[];\n\n/**\n * One verb served by a handler of the host's instead of the generic one. It\n * keeps the group's path and links, and may change the guard, the payload,\n * the failures and the idempotency the verb declares.\n */\nexport interface EntityVerbOverride<R> {\n readonly guard?: EntityApiGuard;\n readonly idempotent?: EndpointIdempotency;\n readonly errors?: readonly FailureClass[];\n /** The body the verb takes instead of an entity envelope. */\n readonly payload?: EndpointSchema;\n readonly handler: (\n request: EntityApiRequest,\n context: EntityApiContext,\n ) => Effect.Effect<unknown, EntifixFailure, R>;\n}\n\n/**\n * A `@useCase()` verb's endpoint: its path, method, permission and contract\n * come from the declaration, and only who may call it and what it does are\n * written here.\n */\nexport interface VerbEndpoint<R> {\n readonly useCase: MetaUseCase;\n /** Defaults to the group's write guard. */\n readonly guard?: EntityApiGuard;\n readonly idempotent?: EndpointIdempotency;\n /** The verb starts a flow and answers `202` with what to follow. */\n readonly accepted?: boolean;\n readonly handler: (\n request: EntityApiRequest,\n context: EntityApiContext,\n ) => Effect.Effect<unknown, EntifixFailure, R>;\n /**\n * The same verb over a selection, for a record-bound verb that also sits in\n * a collection cell (`alsoAt`): one permission for one act, whether it is\n * asked of a record or of twenty. Required exactly when that cell is\n * declared; its request carries the selection as its payload.\n */\n readonly bulk?: (\n request: EntityApiRequest,\n context: EntityApiContext,\n ) => Effect.Effect<unknown, EntifixFailure, R>;\n}\n\n/** Serve a `@useCase()` class's verb on its entity's endpoints. */\nexport const verbEndpoint = <\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- inferred from the options\n const O extends Omit<VerbEndpoint<any>, 'useCase'>,\n>(\n useCaseClass: UseCaseConstructor,\n options: O,\n): O & { readonly useCase: MetaUseCase } => ({\n ...options,\n useCase: extractUseCase(useCaseClass),\n});\n\n/** What an entity's endpoints serve, and under which rules. */\nexport interface EntityApiOptions<T extends Entity, R> {\n readonly verbs: readonly EntityApiVerb[];\n /** One guard for every verb, or one for the reads and one for the writes. */\n readonly guard:\n | EntityApiGuard\n | { readonly read: EntityApiGuard; readonly write: EntityApiGuard };\n /** Narrows the reads, and the facet counts, to what this caller may see. */\n readonly narrowing?: NarrowingRules<T>;\n /** Serve `$facets` beside the list, under the list's guard and narrowing. */\n readonly facets?: boolean;\n /** Runs on every generic create and update, before the save. */\n readonly prepare?: (\n entity: T,\n context: EntityApiContext & { readonly verb: 'create' | 'update' },\n ) => Effect.Effect<T, EntifixFailure, R>;\n /** The business failures `prepare` may answer with, for the contract. */\n readonly errors?: readonly FailureClass[];\n readonly override?: Partial<Record<EntityApiVerb, EntityVerbOverride<R>>>;\n /**\n * The entity's `@useCase()` verbs, one endpoint each. Every verb the entity\n * declares must be here and none another entity declares, or serving the\n * declaration throws.\n */\n readonly useCases?: readonly VerbEndpoint<R>[];\n}\n\n/**\n * An entity's endpoints as a value: which verbs, behind which guards, with\n * which handlers. Declaring them needs no HTTP — a domain's cell declares, and\n * the shell serves the declaration with `entityApi`\n * ([ADR 0020](../../../../../docs/adr/0020-endpoints-are-descriptors-and-the-shell-builds-an-httpapi.md)).\n */\nexport interface EntityApiDeclaration<\n T extends Entity,\n K extends string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- inferred from the options\n O extends EntityApiOptions<T, any>,\n> {\n readonly entity: EntityConstructor<T>;\n readonly key: K;\n readonly options: O;\n}\n\n/** `O`, with every key `Shape` does not name typed `never`. */\ntype Exact<O, Shape> = O & Record<Exclude<keyof O, keyof Shape>, never>;\n\n/**\n * Declare an entity's endpoints, to be served by the shell. An option the\n * declaration does not know is a compile error rather than a value nobody\n * reads — `compositions` included, which the shell adds when it serves.\n */\nexport const defineEntityApi = <\n T extends Entity,\n const K extends string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- inferred from the options\n const O extends EntityApiOptions<T, any>,\n>(\n entity: EntityConstructor<T>,\n key: K,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- inferred from the options\n options: Exact<O, EntityApiOptions<T, any>>,\n): EntityApiDeclaration<T, K, O> => ({ entity, key, options });\n"],"names":["extractUseCase","verbEndpoint","useCaseClass","options","useCase","defineEntityApi","entity","key"],"mappings":";AAAA,SAQEA,cAAc,QAKT,gBAAgB;AAwGvB,iEAAiE,GACjE,OAAO,MAAMC,eAAe,CAI1BC,cACAC,UAC2C,aACxCA;QACHC,SAASJ,eAAeE;OACvB;AAiDH;;;;CAIC,GACD,OAAO,MAAMG,kBAAkB,CAM7BC,QACAC,KACA,2FAA2F;AAC3FJ,UACmC,CAAA;QAAEG;QAAQC;QAAKJ;IAAQ,CAAA,EAAG"}
@@ -19,11 +19,6 @@ export declare const defineCatalog: (fragments: readonly FragmentDescriptor[]) =
19
19
  */
20
20
  export declare const catalogDocument: (catalog: FragmentCatalog) => {
21
21
  fragments: {
22
- readOnly: boolean;
23
- irreversible: boolean;
24
- isolation: import("./fragment.js").FragmentIsolation;
25
- requires: import("./fragment.js").FragmentRequirements;
26
- excludedFrom: Readonly<Record<string, readonly string[]>>;
27
22
  consumes: {
28
23
  [k: string]: unknown;
29
24
  };
@@ -36,6 +31,12 @@ export declare const catalogDocument: (catalog: FragmentCatalog) => {
36
31
  failure: unknown;
37
32
  };
38
33
  fingerprint: string;
34
+ outcomes?: readonly string[] | undefined;
35
+ readOnly: boolean;
36
+ irreversible: boolean;
37
+ isolation: import("./fragment.js").FragmentIsolation;
38
+ requires: import("./fragment.js").FragmentRequirements;
39
+ excludedFrom: Readonly<Record<string, readonly string[]>>;
39
40
  compensation?: import("./fragment.js").FragmentCall | undefined;
40
41
  call?: import("./fragment.js").FragmentCall | undefined;
41
42
  participant?: string | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../src/flow/catalog.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EAKxB,MAAM,eAAe,CAAC;AAEvB,sEAAsE;AACtE,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,kBAAkB,GAAG,SAAS,CAAC;IAC9D,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,CAAC,SAAS,EAAE,SAAS,kBAAkB,EAAE,CAAC;CACnD;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,GACxB,WAAW,SAAS,kBAAkB,EAAE,KACvC,eAkBF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAAI,SAAS,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BtD,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC"}
1
+ {"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../src/flow/catalog.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EAKxB,MAAM,eAAe,CAAC;AAEvB,sEAAsE;AACtE,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,kBAAkB,GAAG,SAAS,CAAC;IAC9D,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,CAAC,SAAS,EAAE,SAAS,kBAAkB,EAAE,CAAC;CACnD;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,GACxB,WAAW,SAAS,kBAAkB,EAAE,KACvC,eAkBF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAAI,SAAS,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BtD,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC"}
@@ -47,7 +47,10 @@ import { fragmentFingerprint, fragmentRef, jsonSchemaOf, keysDocument } from './
47
47
  irreversible: (_fragment_irreversible = fragment.irreversible) != null ? _fragment_irreversible : false,
48
48
  isolation: (_fragment_isolation = fragment.isolation) != null ? _fragment_isolation : 'none',
49
49
  requires: (_fragment_requires = fragment.requires) != null ? _fragment_requires : {},
50
- excludedFrom: (_fragment_excludedFrom = fragment.excludedFrom) != null ? _fragment_excludedFrom : {},
50
+ excludedFrom: (_fragment_excludedFrom = fragment.excludedFrom) != null ? _fragment_excludedFrom : {}
51
+ }, fragment.outcomes === undefined ? {} : {
52
+ outcomes: fragment.outcomes
53
+ }, {
51
54
  consumes: keysDocument(fragment.consumes),
52
55
  provides: keysDocument(fragment.provides),
53
56
  contract: {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/flow/catalog.ts"],"sourcesContent":["import {\n type FragmentDescriptor,\n fragmentFingerprint,\n fragmentRef,\n jsonSchemaOf,\n keysDocument,\n} from './fragment.js';\n\n/** Every fragment a host composes flows from, by pinned reference. */\nexport interface FragmentCatalog {\n readonly get: (ref: string) => FragmentDescriptor | undefined;\n readonly refs: readonly string[];\n readonly fragments: readonly FragmentDescriptor[];\n}\n\n/**\n * Assembles a catalog. Two fragments claiming one `id@version` throw: a pinned\n * reference must name exactly one contract, or a slip pinned to it means\n * whichever module happened to load last.\n */\nexport const defineCatalog = (\n fragments: readonly FragmentDescriptor[],\n): FragmentCatalog => {\n const byRef = new Map<string, FragmentDescriptor>();\n for (const fragment of fragments) {\n const ref = fragmentRef(fragment);\n const existing = byRef.get(ref);\n if (existing !== undefined && existing !== fragment)\n throw new Error(\n `fragment '${ref}' is declared twice, by '${existing.module}' and '${fragment.module}'. ` +\n 'A pinned reference names one contract: bump one of them.',\n );\n byRef.set(ref, fragment);\n }\n const refs = [...byRef.keys()].sort();\n return {\n get: ref => byRef.get(ref),\n refs,\n fragments: refs.map(ref => byRef.get(ref) as FragmentDescriptor),\n };\n};\n\n/**\n * The catalog as a JSON document: every fragment with its contract as JSON\n * Schema and its fingerprint, ordered by reference so it is snapshot-stable. It\n * is what a CI check diffs, and what a register check reads without importing\n * the packages that declare the fragments.\n */\nexport const catalogDocument = (catalog: FragmentCatalog) => ({\n fragments: catalog.fragments.map(fragment => ({\n ref: fragmentRef(fragment),\n id: fragment.id,\n version: fragment.version,\n module: fragment.module,\n kind: fragment.kind,\n cardinality: fragment.cardinality,\n ...(fragment.participant === undefined\n ? {}\n : { participant: fragment.participant }),\n ...(fragment.call === undefined ? {} : { call: fragment.call }),\n ...(fragment.compensation === undefined\n ? {}\n : { compensation: fragment.compensation }),\n readOnly: fragment.readOnly ?? false,\n irreversible: fragment.irreversible ?? false,\n isolation: fragment.isolation ?? 'none',\n requires: fragment.requires ?? {},\n excludedFrom: fragment.excludedFrom ?? {},\n consumes: keysDocument(fragment.consumes),\n provides: keysDocument(fragment.provides),\n contract: {\n input: jsonSchemaOf(fragment.contract.input),\n output: jsonSchemaOf(fragment.contract.output),\n failure: jsonSchemaOf(fragment.contract.failure),\n },\n fingerprint: fragmentFingerprint(fragment),\n })),\n});\n\nexport type CatalogDocument = ReturnType<typeof catalogDocument>;\n"],"names":["fragmentFingerprint","fragmentRef","jsonSchemaOf","keysDocument","defineCatalog","fragments","byRef","Map","fragment","ref","existing","get","undefined","Error","module","set","refs","keys","sort","map","catalogDocument","catalog","id","version","kind","cardinality","participant","call","compensation","readOnly","irreversible","isolation","requires","excludedFrom","consumes","provides","contract","input","output","failure","fingerprint"],"mappings":";AAAA,SAEEA,mBAAmB,EACnBC,WAAW,EACXC,YAAY,EACZC,YAAY,QACP,gBAAgB;AASvB;;;;CAIC,GACD,OAAO,MAAMC,gBAAgB,CAC3BC;IAEA,MAAMC,QAAQ,IAAIC;IAClB,KAAK,MAAMC,YAAYH,UAAW;QAChC,MAAMI,MAAMR,YAAYO;QACxB,MAAME,WAAWJ,MAAMK,GAAG,CAACF;QAC3B,IAAIC,aAAaE,aAAaF,aAAaF,UACzC,MAAM,IAAIK,MACR,CAAC,UAAU,EAAEJ,IAAI,yBAAyB,EAAEC,SAASI,MAAM,CAAC,OAAO,EAAEN,SAASM,MAAM,CAAC,GAAG,CAAC,GACvF;QAENR,MAAMS,GAAG,CAACN,KAAKD;IACjB;IACA,MAAMQ,OAAO;WAAIV,MAAMW,IAAI;KAAG,CAACC,IAAI;IACnC,OAAO;QACLP,KAAKF,CAAAA,MAAOH,MAAMK,GAAG,CAACF;QACt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AQ,CAACG,OAAO;gBACjD;gBACAC,aAAaxC,oBAAoBQ;;;IAErC,CAAA,EAAG"}
1
+ {"version":3,"sources":["../../src/flow/catalog.ts"],"sourcesContent":["import {\n type FragmentDescriptor,\n fragmentFingerprint,\n fragmentRef,\n jsonSchemaOf,\n keysDocument,\n} from './fragment.js';\n\n/** Every fragment a host composes flows from, by pinned reference. */\nexport interface FragmentCatalog {\n readonly get: (ref: string) => FragmentDescriptor | undefined;\n readonly refs: readonly string[];\n readonly fragments: readonly FragmentDescriptor[];\n}\n\n/**\n * Assembles a catalog. Two fragments claiming one `id@version` throw: a pinned\n * reference must name exactly one contract, or a slip pinned to it means\n * whichever module happened to load last.\n */\nexport const defineCatalog = (\n fragments: readonly FragmentDescriptor[],\n): FragmentCatalog => {\n const byRef = new Map<string, FragmentDescriptor>();\n for (const fragment of fragments) {\n const ref = fragmentRef(fragment);\n const existing = byRef.get(ref);\n if (existing !== undefined && existing !== fragment)\n throw new Error(\n `fragment '${ref}' is declared twice, by '${existing.module}' and '${fragment.module}'. ` +\n 'A pinned reference names one contract: bump one of them.',\n );\n byRef.set(ref, fragment);\n }\n const refs = [...byRef.keys()].sort();\n return {\n get: ref => byRef.get(ref),\n refs,\n fragments: refs.map(ref => byRef.get(ref) as FragmentDescriptor),\n };\n};\n\n/**\n * The catalog as a JSON document: every fragment with its contract as JSON\n * Schema and its fingerprint, ordered by reference so it is snapshot-stable. It\n * is what a CI check diffs, and what a register check reads without importing\n * the packages that declare the fragments.\n */\nexport const catalogDocument = (catalog: FragmentCatalog) => ({\n fragments: catalog.fragments.map(fragment => ({\n ref: fragmentRef(fragment),\n id: fragment.id,\n version: fragment.version,\n module: fragment.module,\n kind: fragment.kind,\n cardinality: fragment.cardinality,\n ...(fragment.participant === undefined\n ? {}\n : { participant: fragment.participant }),\n ...(fragment.call === undefined ? {} : { call: fragment.call }),\n ...(fragment.compensation === undefined\n ? {}\n : { compensation: fragment.compensation }),\n readOnly: fragment.readOnly ?? false,\n irreversible: fragment.irreversible ?? false,\n isolation: fragment.isolation ?? 'none',\n requires: fragment.requires ?? {},\n excludedFrom: fragment.excludedFrom ?? {},\n ...(fragment.outcomes === undefined ? {} : { outcomes: fragment.outcomes }),\n consumes: keysDocument(fragment.consumes),\n provides: keysDocument(fragment.provides),\n contract: {\n input: jsonSchemaOf(fragment.contract.input),\n output: jsonSchemaOf(fragment.contract.output),\n failure: jsonSchemaOf(fragment.contract.failure),\n },\n fingerprint: fragmentFingerprint(fragment),\n })),\n});\n\nexport type CatalogDocument = ReturnType<typeof catalogDocument>;\n"],"names":["fragmentFingerprint","fragmentRef","jsonSchemaOf","keysDocument","defineCatalog","fragments","byRef","Map","fragment","ref","existing","get","undefined","Error","module","set","refs","keys","sort","map","catalogDocument","catalog","id","version","kind","cardinality","participant","call","compensation","readOnly","irreversible","isolation","requires","excludedFrom","outcomes","consumes","provides","contract","input","output","failure","fingerprint"],"mappings":";AAAA,SAEEA,mBAAmB,EACnBC,WAAW,EACXC,YAAY,EACZC,YAAY,QACP,gBAAgB;AASvB;;;;CAIC,GACD,OAAO,MAAMC,gBAAgB,CAC3BC;IAEA,MAAMC,QAAQ,IAAIC;IAClB,KAAK,MAAMC,YAAYH,UAAW;QAChC,MAAMI,MAAMR,YAAYO;QACxB,MAAME,WAAWJ,MAAMK,GAAG,CAACF;QAC3B,IAAIC,aAAaE,aAAaF,aAAaF,UACzC,MAAM,IAAIK,MACR,CAAC,UAAU,EAAEJ,IAAI,yBAAyB,EAAEC,SAASI,MAAM,CAAC,OAAO,EAAEN,SAASM,MAAM,CAAC,GAAG,CAAC,GACvF;QAENR,MAAMS,GAAG,CAACN,KAAKD;IACjB;IACA,MAAMQ,OAAO;WAAIV,MAAMW,IAAI;KAAG,CAACC,IAAI;IACnC,OAAO;QACLP,KAAKF,CAAAA,MAAOH,MAAMK,GAAG,CAACF;QACtBO;QACAX,WAAWW,KAAKG,GAAG,CAACV,CAAAA,MAAOH,MAAMK,GAAG,CAACF;IACvC;AAC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AAS6B,QAAQ,CAACG,OAAO;gBACjD;gBACAC,aAAazC,oBAAoBQ;;;IAErC,CAAA,EAAG"}
@@ -68,6 +68,12 @@ export interface FragmentDescriptor<I = unknown, O = unknown, F = unknown> {
68
68
  * cash-on-delivery segment; the framework names neither.
69
69
  */
70
70
  readonly excludedFrom?: Readonly<Record<string, readonly string[]>>;
71
+ /**
72
+ * What a `wait` can be answered with: the values a signal's `outcome` may
73
+ * take. A later step guards on them, and a correlated signal naming any
74
+ * other is refused rather than taken by the wrong wait. A wait only.
75
+ */
76
+ readonly outcomes?: readonly string[];
71
77
  }
72
78
  /** The pinned reference a slip carries: `stock.reserve@1`. */
73
79
  export declare const fragmentRef: (fragment: {
@@ -1 +1 @@
1
- {"version":3,"file":"fragment.d.ts","sourceRoot":"","sources":["../../src/flow/fragment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,GAAG,eAAe,GAAG,OAAO,GAAG,WAAW,GAAG,MAAM,CAAC;AAE5E,mFAAmF;AACnF,MAAM,MAAM,mBAAmB,GAAG,KAAK,GAAG,WAAW,GAAG,SAAS,CAAC;AAElE;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GACzB,aAAa,GACb,cAAc,GACd,QAAQ,GACR,iBAAiB,GACjB,aAAa,GACb,MAAM,CAAC;AAEX,wFAAwF;AACxF,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;IAC7D,QAAQ,CAAC,IAAI,EAAE,IAAI,MAAM,EAAE,CAAC;CAC7B;AAED,0DAA0D;AAC1D,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1C,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CA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AQ,CAAC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACvC;AAED,8DAA8D;AAC9D,eAAO,MAAM,WAAW,GAAI,UAAU;IACpC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,KAAG,MAAsD,CAAC;AA4C3D;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EACpC,UAAU,kBAAkB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KACpC,kBAAkB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAO5B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,6CAWrB,CAAC;AAsBH,qDAAqD;AACrD,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,KAAG,OACjC,CAAC;AAEtC,gEAAgE;AAChE,eAAO,MAAM,YAAY,GAAI,MAAM,YAAY,GAAG,SAAS;;CAKxD,CAAC;AAEJ;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAAI,UAAU,kBAAkB,KAAG,MAkBhE,CAAC"}
@@ -14,6 +14,10 @@ const shapeProblems = (fragment)=>{
14
14
  problems.push(`a ${fragment.kind} step cannot declare a compensation`);
15
15
  }
16
16
  if (fragment.irreversible === true && fragment.kind === 'compensatable') problems.push('a compensatable step cannot be irreversible');
17
+ if (fragment.outcomes !== undefined) {
18
+ if (fragment.kind !== 'wait') problems.push('only a wait declares the outcomes it is answered with');
19
+ else if (fragment.outcomes.length === 0 || new Set(fragment.outcomes).size !== fragment.outcomes.length) problems.push('its outcomes are at least one, and distinct');
20
+ }
17
21
  return problems;
18
22
  };
19
23
  /**
@@ -71,7 +75,10 @@ const shapeProblems = (fragment)=>{
71
75
  output: jsonSchemaOf(fragment.contract.output),
72
76
  failure: jsonSchemaOf(fragment.contract.failure),
73
77
  consumes: keysDocument(fragment.consumes),
74
- provides: keysDocument(fragment.provides)
78
+ provides: keysDocument(fragment.provides),
79
+ // Absent on every fragment but a wait that declares them, and dropped
80
+ // from the JSON then, so declaring none changes no fingerprint.
81
+ outcomes: fragment.outcomes
75
82
  }));
76
83
 
77
84
  //# sourceMappingURL=fragment.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/flow/fragment.ts"],"sourcesContent":["import { Schema } from 'effect';\n\n/**\n * How a step behaves when a later one fails\n * ([ADR 0015](../../../../../docs/adr/0015-composed-flows-and-use-case-resolution.md)).\n *\n * - `compensatable` — can be undone, so it sits before the commit point;\n * - `pivot` — the point of no return, at most one per slip;\n * - `retriable` — after the commit point, retried until it succeeds;\n * - `wait` — a durable wait for a signal, after the commit point.\n */\nexport type FragmentKind = 'compensatable' | 'pivot' | 'retriable' | 'wait';\n\n/** How many calls one step makes: one, one per vendor segment, or one per line. */\nexport type FragmentCardinality = 'one' | 'perVendor' | 'perLine';\n\n/**\n * The countermeasure a step relies on for the isolation a saga lacks — what\n * keeps a concurrent flow from seeing, or undoing, its intermediate state.\n */\nexport type FragmentIsolation =\n | 'commutative'\n | 'semanticLock'\n | 'reRead'\n | 'pessimisticView'\n | 'versionFile'\n | 'none';\n\n/** One HTTP call a step makes on its participant: the public path, never a template. */\nexport interface FragmentCall {\n readonly method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n readonly path: `/${string}`;\n}\n\n/** The facts of a verified context a step may require. */\nexport interface FragmentRequirements {\n readonly entitlements?: readonly string[];\n readonly roles?: readonly string[];\n readonly partyRoles?: readonly string[];\n readonly channels?: readonly string[];\n}\n\n/** A step's contract, as Schemas: what it is given, answers, and refuses with. */\nexport interface FragmentContract<I, O, F> {\n readonly input: Schema.Codec<I, unknown>;\n readonly output: Schema.Codec<O, unknown>;\n readonly failure: Schema.Codec<F, unknown>;\n}\n\n/** Keys a step reads from earlier steps, or makes available to later ones. */\nexport type FragmentKeys = Readonly<\n Record<string, Schema.Codec<unknown, unknown>>\n>;\n\n/**\n * One step a module contributes to a flow, declared beside the use case it\n * calls. Versioned (`id@version`) and typed, so a contract change without a\n * version bump is visible to a catalog snapshot before it reaches a running\n * flow.\n */\nexport interface FragmentDescriptor<I = unknown, O = unknown, F = unknown> {\n readonly id: string;\n readonly version: number;\n /** The module that owns the step — its domain. */\n readonly module: string;\n readonly kind: FragmentKind;\n /** The service the step calls. Absent only on a marker such as `flow.commit@1`. */\n readonly participant?: string;\n readonly call?: FragmentCall;\n /** Required on a compensatable step unless it is `readOnly`; forbidden otherwise. */\n readonly compensation?: FragmentCall;\n /** A compensatable step that changes nothing, and so has nothing to undo. */\n readonly readOnly?: boolean;\n readonly contract: FragmentContract<I, O, F>;\n readonly requires?: FragmentRequirements;\n readonly consumes?: FragmentKeys;\n readonly provides?: FragmentKeys;\n /** A step whose effect no compensation can reverse — money moved, goods shipped. */\n readonly irreversible?: boolean;\n readonly isolation?: FragmentIsolation;\n readonly cardinality: FragmentCardinality;\n /**\n * Segments this step may not run in, by tag. A card capture excludes the\n * cash-on-delivery segment; the framework names neither.\n */\n readonly excludedFrom?: Readonly<Record<string, readonly string[]>>;\n}\n\n/** The pinned reference a slip carries: `stock.reserve@1`. */\nexport const fragmentRef = (fragment: {\n readonly id: string;\n readonly version: number;\n}): string => `${fragment.id}@${String(fragment.version)}`;\n\n/** `domain.verb`, lower kebab, at least two segments. */\nconst FRAGMENT_ID = /^[a-z][a-z0-9-]*(\\.[a-z][a-z0-9-]*)+$/;\n\nconst shapeProblems = (fragment: FragmentDescriptor): string[] => {\n const problems: string[] = [];\n if (!FRAGMENT_ID.test(fragment.id))\n problems.push(`its id must be 'domain.verb' in lower kebab case`);\n if (!Number.isInteger(fragment.version) || fragment.version < 1)\n problems.push('its version must be a positive integer');\n const marker =\n fragment.participant === undefined && fragment.call === undefined;\n if (\n !marker &&\n (fragment.participant === undefined || fragment.call === undefined)\n )\n problems.push('it names a participant and a call together, or neither');\n if (marker && fragment.kind !== 'pivot')\n problems.push(\n 'only a pivot may be a marker with no participant and no call',\n );\n if (fragment.kind === 'compensatable') {\n if (fragment.compensation === undefined && fragment.readOnly !== true)\n problems.push(\n 'a compensatable step declares its compensation, or is readOnly',\n );\n } else if (fragment.compensation !== undefined) {\n problems.push(`a ${fragment.kind} step cannot declare a compensation`);\n }\n if (fragment.irreversible === true && fragment.kind === 'compensatable')\n problems.push('a compensatable step cannot be irreversible');\n return problems;\n};\n\n/**\n * Declares a fragment, checking its shape at module load: a malformed\n * descriptor is a programming error and fails the boot, not the first flow\n * that reaches it. What depends on *other* fragments — order, inputs, the\n * commit point — is the validator's, over a whole slip.\n */\nexport const defineFragment = <I, O, F>(\n fragment: FragmentDescriptor<I, O, F>,\n): FragmentDescriptor<I, O, F> => {\n const problems = shapeProblems(fragment as FragmentDescriptor);\n if (problems.length > 0)\n throw new Error(\n `fragment '${fragment.id}@${String(fragment.version)}' is malformed: ${problems.join('; ')}`,\n );\n return fragment;\n};\n\n/**\n * The commit point of a flow that has no real pivot: a pivot with no\n * participant and no call. A cash-on-delivery checkout takes no money, and\n * still needs a line past which its stock conversions are retried rather than\n * compensated.\n */\nexport const flowCommit = defineFragment({\n id: 'flow.commit',\n version: 1,\n module: 'flow',\n kind: 'pivot',\n cardinality: 'one',\n contract: {\n input: Schema.Unknown,\n output: Schema.Unknown,\n failure: Schema.Never,\n },\n});\n\n/** A stable 53-bit hash of a string, as hex — enough to see that a contract moved. */\nconst hash = (text: string): string => {\n let h1 = 0xdeadbeef;\n let h2 = 0x41c6ce57;\n for (let index = 0; index < text.length; index += 1) {\n const code = text.charCodeAt(index);\n h1 = Math.imul(h1 ^ code, 2654435761);\n h2 = Math.imul(h2 ^ code, 1597334677);\n }\n h1 =\n Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^\n Math.imul(h2 ^ (h2 >>> 13), 3266489909);\n h2 =\n Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^\n Math.imul(h1 ^ (h1 >>> 13), 3266489909);\n return (4294967296 * (2097151 & h2) + (h1 >>> 0))\n .toString(16)\n .padStart(14, '0');\n};\n\n/** The JSON Schema of a codec, as a plain object. */\nexport const jsonSchemaOf = (schema: Schema.Codec<unknown, unknown>): unknown =>\n Schema.toJsonSchemaDocument(schema);\n\n/** Consumed or provided keys as JSON Schema, ordered by key. */\nexport const keysDocument = (keys: FragmentKeys | undefined) =>\n Object.fromEntries(\n Object.entries(keys ?? {})\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([key, schema]) => [key, jsonSchemaOf(schema)]),\n );\n\n/**\n * A fingerprint of what a fragment promises: its contract and the keys it\n * consumes and provides. It changes when any of those change and on nothing\n * else, so renaming a module or rewording a description never looks like a\n * contract change — and a contract change without a version bump fails the\n * catalog snapshot.\n */\nexport const fragmentFingerprint = (fragment: FragmentDescriptor): string =>\n hash(\n JSON.stringify({\n input: jsonSchemaOf(\n fragment.contract.input as Schema.Codec<unknown, unknown>,\n ),\n output: jsonSchemaOf(\n fragment.contract.output as Schema.Codec<unknown, unknown>,\n ),\n failure: jsonSchemaOf(\n fragment.contract.failure as Schema.Codec<unknown, unknown>,\n ),\n consumes: keysDocument(fragment.consumes),\n provides: keysDocument(fragment.provides),\n }),\n );\n"],"names":["Schema","fragmentRef","fragment","id","String","version","FRAGMENT_ID","shapeProblems","problems","test","push","Number","isInteger","marker","participant","undefined","call","kind","compensation","readOnly","irreversible","defineFragment","length","Error","join","flowCommit","module","cardinality","contract","input","Unknown","output","failure","Never","hash","text","h1","h2","index","code","charCodeAt","Math","imul","toString","padStart","jsonSchemaOf","schema","toJsonSchemaDocument","keysDocument","keys","Object","fromEntries","entries","sort","a","b","localeCompare","map","key","fragmentFingerprint","JSON","stringify","consumes","provides"],"mappings":"AAAA,SAASA,MAAM,QAAQ,SAAS;AAwFhC,4DAA4D,GAC5D,OAAO,MAAMC,cAAc,CAACC,WAGd,GAAGA,SAASC,EAAE,CAAC,CAAC,EAAEC,OAAOF,SAASG,OAAO,GAAG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0B,KAAKC,SAAS,CAAC;QACbhC,OAAOgB,aACL3C,SAAS0B,QAAQ,CAACC,KAAK;QAEzBE,QAAQc,aACN3C,SAAS0B,QAAQ,CAACG,MAAM;QAE1BC,SAASa,aACP3C,SAAS0B,QAAQ,CAACI,OAAO;QAE3B8B,UAAUd,aAAa9C,SAAS4D,QAAQ;QACxCC,UAAUf,aAAa9C,SAAS6D,QAAQ;IAC1C,IACA"}
1
+ {"version":3,"sources":["../../src/flow/fragment.ts"],"sourcesContent":["import { Schema } from 'effect';\n\n/**\n * How a step behaves when a later one fails\n * ([ADR 0015](../../../../../docs/adr/0015-composed-flows-and-use-case-resolution.md)).\n *\n * - `compensatable` — can be undone, so it sits before the commit point;\n * - `pivot` — the point of no return, at most one per slip;\n * - `retriable` — after the commit point, retried until it succeeds;\n * - `wait` — a durable wait for a signal, after the commit point.\n */\nexport type FragmentKind = 'compensatable' | 'pivot' | 'retriable' | 'wait';\n\n/** How many calls one step makes: one, one per vendor segment, or one per line. */\nexport type FragmentCardinality = 'one' | 'perVendor' | 'perLine';\n\n/**\n * The countermeasure a step relies on for the isolation a saga lacks — what\n * keeps a concurrent flow from seeing, or undoing, its intermediate state.\n */\nexport type FragmentIsolation =\n | 'commutative'\n | 'semanticLock'\n | 'reRead'\n | 'pessimisticView'\n | 'versionFile'\n | 'none';\n\n/** One HTTP call a step makes on its participant: the public path, never a template. */\nexport interface FragmentCall {\n readonly method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n readonly path: `/${string}`;\n}\n\n/** The facts of a verified context a step may require. */\nexport interface FragmentRequirements {\n readonly entitlements?: readonly string[];\n readonly roles?: readonly string[];\n readonly partyRoles?: readonly string[];\n readonly channels?: readonly string[];\n}\n\n/** A step's contract, as Schemas: what it is given, answers, and refuses with. */\nexport interface FragmentContract<I, O, F> {\n readonly input: Schema.Codec<I, unknown>;\n readonly output: Schema.Codec<O, unknown>;\n readonly failure: Schema.Codec<F, unknown>;\n}\n\n/** Keys a step reads from earlier steps, or makes available to later ones. */\nexport type FragmentKeys = Readonly<\n Record<string, Schema.Codec<unknown, unknown>>\n>;\n\n/**\n * One step a module contributes to a flow, declared beside the use case it\n * calls. Versioned (`id@version`) and typed, so a contract change without a\n * version bump is visible to a catalog snapshot before it reaches a running\n * flow.\n */\nexport interface FragmentDescriptor<I = unknown, O = unknown, F = unknown> {\n readonly id: string;\n readonly version: number;\n /** The module that owns the step — its domain. */\n readonly module: string;\n readonly kind: FragmentKind;\n /** The service the step calls. Absent only on a marker such as `flow.commit@1`. */\n readonly participant?: string;\n readonly call?: FragmentCall;\n /** Required on a compensatable step unless it is `readOnly`; forbidden otherwise. */\n readonly compensation?: FragmentCall;\n /** A compensatable step that changes nothing, and so has nothing to undo. */\n readonly readOnly?: boolean;\n readonly contract: FragmentContract<I, O, F>;\n readonly requires?: FragmentRequirements;\n readonly consumes?: FragmentKeys;\n readonly provides?: FragmentKeys;\n /** A step whose effect no compensation can reverse — money moved, goods shipped. */\n readonly irreversible?: boolean;\n readonly isolation?: FragmentIsolation;\n readonly cardinality: FragmentCardinality;\n /**\n * Segments this step may not run in, by tag. A card capture excludes the\n * cash-on-delivery segment; the framework names neither.\n */\n readonly excludedFrom?: Readonly<Record<string, readonly string[]>>;\n /**\n * What a `wait` can be answered with: the values a signal's `outcome` may\n * take. A later step guards on them, and a correlated signal naming any\n * other is refused rather than taken by the wrong wait. A wait only.\n */\n readonly outcomes?: readonly string[];\n}\n\n/** The pinned reference a slip carries: `stock.reserve@1`. */\nexport const fragmentRef = (fragment: {\n readonly id: string;\n readonly version: number;\n}): string => `${fragment.id}@${String(fragment.version)}`;\n\n/** `domain.verb`, lower kebab, at least two segments. */\nconst FRAGMENT_ID = /^[a-z][a-z0-9-]*(\\.[a-z][a-z0-9-]*)+$/;\n\nconst shapeProblems = (fragment: FragmentDescriptor): string[] => {\n const problems: string[] = [];\n if (!FRAGMENT_ID.test(fragment.id))\n problems.push(`its id must be 'domain.verb' in lower kebab case`);\n if (!Number.isInteger(fragment.version) || fragment.version < 1)\n problems.push('its version must be a positive integer');\n const marker =\n fragment.participant === undefined && fragment.call === undefined;\n if (\n !marker &&\n (fragment.participant === undefined || fragment.call === undefined)\n )\n problems.push('it names a participant and a call together, or neither');\n if (marker && fragment.kind !== 'pivot')\n problems.push(\n 'only a pivot may be a marker with no participant and no call',\n );\n if (fragment.kind === 'compensatable') {\n if (fragment.compensation === undefined && fragment.readOnly !== true)\n problems.push(\n 'a compensatable step declares its compensation, or is readOnly',\n );\n } else if (fragment.compensation !== undefined) {\n problems.push(`a ${fragment.kind} step cannot declare a compensation`);\n }\n if (fragment.irreversible === true && fragment.kind === 'compensatable')\n problems.push('a compensatable step cannot be irreversible');\n if (fragment.outcomes !== undefined) {\n if (fragment.kind !== 'wait')\n problems.push('only a wait declares the outcomes it is answered with');\n else if (\n fragment.outcomes.length === 0 ||\n new Set(fragment.outcomes).size !== fragment.outcomes.length\n )\n problems.push('its outcomes are at least one, and distinct');\n }\n return problems;\n};\n\n/**\n * Declares a fragment, checking its shape at module load: a malformed\n * descriptor is a programming error and fails the boot, not the first flow\n * that reaches it. What depends on *other* fragments — order, inputs, the\n * commit point — is the validator's, over a whole slip.\n */\nexport const defineFragment = <I, O, F>(\n fragment: FragmentDescriptor<I, O, F>,\n): FragmentDescriptor<I, O, F> => {\n const problems = shapeProblems(fragment as FragmentDescriptor);\n if (problems.length > 0)\n throw new Error(\n `fragment '${fragment.id}@${String(fragment.version)}' is malformed: ${problems.join('; ')}`,\n );\n return fragment;\n};\n\n/**\n * The commit point of a flow that has no real pivot: a pivot with no\n * participant and no call. A cash-on-delivery checkout takes no money, and\n * still needs a line past which its stock conversions are retried rather than\n * compensated.\n */\nexport const flowCommit = defineFragment({\n id: 'flow.commit',\n version: 1,\n module: 'flow',\n kind: 'pivot',\n cardinality: 'one',\n contract: {\n input: Schema.Unknown,\n output: Schema.Unknown,\n failure: Schema.Never,\n },\n});\n\n/** A stable 53-bit hash of a string, as hex — enough to see that a contract moved. */\nconst hash = (text: string): string => {\n let h1 = 0xdeadbeef;\n let h2 = 0x41c6ce57;\n for (let index = 0; index < text.length; index += 1) {\n const code = text.charCodeAt(index);\n h1 = Math.imul(h1 ^ code, 2654435761);\n h2 = Math.imul(h2 ^ code, 1597334677);\n }\n h1 =\n Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^\n Math.imul(h2 ^ (h2 >>> 13), 3266489909);\n h2 =\n Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^\n Math.imul(h1 ^ (h1 >>> 13), 3266489909);\n return (4294967296 * (2097151 & h2) + (h1 >>> 0))\n .toString(16)\n .padStart(14, '0');\n};\n\n/** The JSON Schema of a codec, as a plain object. */\nexport const jsonSchemaOf = (schema: Schema.Codec<unknown, unknown>): unknown =>\n Schema.toJsonSchemaDocument(schema);\n\n/** Consumed or provided keys as JSON Schema, ordered by key. */\nexport const keysDocument = (keys: FragmentKeys | undefined) =>\n Object.fromEntries(\n Object.entries(keys ?? {})\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([key, schema]) => [key, jsonSchemaOf(schema)]),\n );\n\n/**\n * A fingerprint of what a fragment promises: its contract and the keys it\n * consumes and provides. It changes when any of those change and on nothing\n * else, so renaming a module or rewording a description never looks like a\n * contract change — and a contract change without a version bump fails the\n * catalog snapshot.\n */\nexport const fragmentFingerprint = (fragment: FragmentDescriptor): string =>\n hash(\n JSON.stringify({\n input: jsonSchemaOf(\n fragment.contract.input as Schema.Codec<unknown, unknown>,\n ),\n output: jsonSchemaOf(\n fragment.contract.output as Schema.Codec<unknown, unknown>,\n ),\n failure: jsonSchemaOf(\n fragment.contract.failure as Schema.Codec<unknown, unknown>,\n ),\n consumes: keysDocument(fragment.consumes),\n provides: keysDocument(fragment.provides),\n // Absent on every fragment but a wait that declares them, and dropped\n // from the JSON then, so declaring none changes no fingerprint.\n outcomes: fragment.outcomes,\n }),\n );\n"],"names":["Schema","fragmentRef","fragment","id","String","version","FRAGMENT_ID","shapeProblems","problems","test","push","Number","isInteger","marker","participant","undefined","call","kind","compensation","readOnly","irreversible","outcomes","length","Set","size","defineFragment","Error","join","flowCommit","module","cardinality","contract","input","Unknown","output","failure","Never","hash","text","h1","h2","index","code","charCodeAt","Math","imul","toString","padStart","jsonSchemaOf","schema","toJsonSchemaDocument","keysDocument","keys","Object","fromEntries","entries","sort","a","b","localeCompare","map","key","fragmentFingerprint","JSON","stringify","consumes","provides"],"mappings":"AAAA,SAASA,MAAM,QAAQ,SAAS;AA8FhC,4DAA4D,GAC5D,OAAO,MAAMC,cAAc,CAACC,WAGd,GAAGA,SAASC,EAAE,CAAC,CAAC,EAAEC,OAAOF,SAASG,OAAO,GAAG,CAAC;AAE3D,uDAAuD,GACvD,MAAMC,cAAc;AAEpB,MAAMC,gBAAgB,CAACL;IACrB,MAAMM,WAAqB,EAAE;IAC7B,IAAI,CAACF,YAAYG,IAAI,CAACP,SAASC,EAAE,GAC/BK,SAASE,IAAI,CAAC,CAAC,gDAAgD,CAAC;IAClE,IAAI,CAACC,OAAOC,SAAS,CAACV,SAASG,OAAO,KAAKH,SAASG,OAAO,GAAG,GAC5DG,SAASE,IAAI,CAAC;IAChB,MAAMG,SACJX,SAASY,WAAW,KAAKC,aAAab,SAASc,IAAI,KAAKD;IAC1D,IACE,CAACF,UACAX,CAAAA,SAASY,WAAW,KAAKC,aAAab,SAASc,IAAI,KAAKD,SAAQ,GAEjEP,SAASE,IAAI,CAAC;IAChB,IAAIG,UAAUX,SAASe,IAAI,KAAK,SAC9BT,SAASE,IAAI,CACX;IAEJ,IAAIR,SAASe,IAAI,KAAK,iBAAiB;QACrC,IAAIf,SAASgB,YAAY,KAAKH,aAAab,SAASiB,QAAQ,KAAK,MAC/DX,SAASE,IAAI,CACX;IAEN,OAAO,IAAIR,SAASgB,YAAY,KAAKH,WAAW;QAC9CP,SAASE,IAAI,CAAC,CAAC,EAAE,EAAER,SAASe,IAAI,CAAC,mCAAmC,CAAC;IACvE;IACA,IAAIf,SAASkB,YAAY,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AO,IAAK;IAC9BA,KACEI,KAAKC,IAAI,CAACL,KAAMA,OAAO,IAAK,cAC5BI,KAAKC,IAAI,CAACN,KAAMA,OAAO,IAAK;IAC9B,OAAO,AAAC,CAAA,aAAc,CAAA,UAAUC,EAAC,IAAMD,CAAAA,OAAO,CAAA,CAAC,EAC5CO,QAAQ,CAAC,IACTC,QAAQ,CAAC,IAAI;AAClB;AAEA,mDAAmD,GACnD,OAAO,MAAMC,eAAe,CAACC,SAC3BjD,OAAOkD,oBAAoB,CAACD,QAAQ;AAEtC,8DAA8D,GAC9D,OAAO,MAAME,eAAe,CAACC,OAC3BC,OAAOC,WAAW,CAChBD,OAAOE,OAAO,CAACH,eAAAA,OAAQ,CAAC,GACrBI,IAAI,CAAC,CAAC,CAACC,EAAE,EAAE,CAACC,EAAE,GAAKD,EAAEE,aAAa,CAACD,IACnCE,GAAG,CAAC,CAAC,CAACC,KAAKZ,OAAO,GAAK;YAACY;YAAKb,aAAaC;SAAQ,GACrD;AAEJ;;;;;;CAMC,GACD,OAAO,MAAMa,sBAAsB,CAAC5D,WAClCmC,KACE0B,KAAKC,SAAS,CAAC;QACbhC,OAAOgB,aACL9C,SAAS6B,QAAQ,CAACC,KAAK;QAEzBE,QAAQc,aACN9C,SAAS6B,QAAQ,CAACG,MAAM;QAE1BC,SAASa,aACP9C,SAAS6B,QAAQ,CAACI,OAAO;QAE3B8B,UAAUd,aAAajD,SAAS+D,QAAQ;QACxCC,UAAUf,aAAajD,SAASgE,QAAQ;QACxC,sEAAsE;QACtE,gEAAgE;QAChE7C,UAAUnB,SAASmB,QAAQ;IAC7B,IACA"}
@@ -6,12 +6,30 @@ import { Effect, Schema } from 'effect';
6
6
  * the next one ships.
7
7
  */
8
8
  export declare const SLIP_VERSION: 1;
9
- /** Tags that place a step in a segment of the flow: whose lines, which payment. */
9
+ /**
10
+ * Tags that place a step in a segment of the flow: whose lines, which payment.
11
+ * `entitlements` are the facts verified for the party the segment acts for —
12
+ * a vendor's provisioning, never the caller's — and a segment's steps are
13
+ * checked against them beside the flow's context.
14
+ */
10
15
  export declare const SlipSegment: Schema.Struct<{
11
16
  readonly vendor: Schema.optionalKey<Schema.String>;
12
17
  readonly paymentMethod: Schema.optionalKey<Schema.String>;
18
+ readonly entitlements: Schema.optionalKey<Schema.$Array<Schema.String>>;
13
19
  }>;
14
20
  export type SlipSegment = typeof SlipSegment.Type;
21
+ /**
22
+ * A step that runs only when an earlier wait was answered with one of
23
+ * `outcomes` — the one branch a slip can take, decided by what the wait was
24
+ * told rather than by anything known at composition. A step guarded on a wait
25
+ * that was itself skipped is skipped too.
26
+ */
27
+ export declare const SlipGuard: Schema.Struct<{
28
+ /** The step name of the wait, earlier in the slip. */
29
+ readonly wait: Schema.String;
30
+ readonly outcomes: Schema.$Array<Schema.String>;
31
+ }>;
32
+ export type SlipGuard = typeof SlipGuard.Type;
15
33
  /** One pinned step: a fragment reference and everything resolved for it. */
16
34
  export declare const SlipStep: Schema.Struct<{
17
35
  /** `id@version`, pinned when the slip was composed. */
@@ -22,7 +40,10 @@ export declare const SlipStep: Schema.Struct<{
22
40
  readonly segment: Schema.optionalKey<Schema.Struct<{
23
41
  readonly vendor: Schema.optionalKey<Schema.String>;
24
42
  readonly paymentMethod: Schema.optionalKey<Schema.String>;
43
+ readonly entitlements: Schema.optionalKey<Schema.$Array<Schema.String>>;
25
44
  }>>;
45
+ /** The line a `perLine` step was expanded for, by the recipe's key. */
46
+ readonly line: Schema.optionalKey<Schema.String>;
26
47
  readonly participant: Schema.optionalKey<Schema.String>;
27
48
  readonly call: Schema.optionalKey<Schema.Struct<{
28
49
  readonly method: Schema.Literals<readonly ["GET", "POST", "PUT", "PATCH", "DELETE"]>;
@@ -34,6 +55,11 @@ export declare const SlipStep: Schema.Struct<{
34
55
  }>>;
35
56
  /** Configuration pinned at composition — a hold's expiry, a limit. */
36
57
  readonly parameters: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
58
+ readonly guard: Schema.optionalKey<Schema.Struct<{
59
+ /** The step name of the wait, earlier in the slip. */
60
+ readonly wait: Schema.String;
61
+ readonly outcomes: Schema.$Array<Schema.String>;
62
+ }>>;
37
63
  }>;
38
64
  export type SlipStep = typeof SlipStep.Type;
39
65
  export declare const SlipStage: Schema.Struct<{
@@ -47,7 +73,10 @@ export declare const SlipStage: Schema.Struct<{
47
73
  readonly segment: Schema.optionalKey<Schema.Struct<{
48
74
  readonly vendor: Schema.optionalKey<Schema.String>;
49
75
  readonly paymentMethod: Schema.optionalKey<Schema.String>;
76
+ readonly entitlements: Schema.optionalKey<Schema.$Array<Schema.String>>;
50
77
  }>>;
78
+ /** The line a `perLine` step was expanded for, by the recipe's key. */
79
+ readonly line: Schema.optionalKey<Schema.String>;
51
80
  readonly participant: Schema.optionalKey<Schema.String>;
52
81
  readonly call: Schema.optionalKey<Schema.Struct<{
53
82
  readonly method: Schema.Literals<readonly ["GET", "POST", "PUT", "PATCH", "DELETE"]>;
@@ -59,6 +88,11 @@ export declare const SlipStage: Schema.Struct<{
59
88
  }>>;
60
89
  /** Configuration pinned at composition — a hold's expiry, a limit. */
61
90
  readonly parameters: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
91
+ readonly guard: Schema.optionalKey<Schema.Struct<{
92
+ /** The step name of the wait, earlier in the slip. */
93
+ readonly wait: Schema.String;
94
+ readonly outcomes: Schema.$Array<Schema.String>;
95
+ }>>;
62
96
  }>>;
63
97
  }>;
64
98
  export type SlipStage = typeof SlipStage.Type;
@@ -68,6 +102,7 @@ export declare const SlipAudienceEntry: Schema.Struct<{
68
102
  readonly id: Schema.String;
69
103
  readonly digest: Schema.optionalKey<Schema.String>;
70
104
  }>;
105
+ export type SlipAudienceEntry = typeof SlipAudienceEntry.Type;
71
106
  /** Which variant each use case resolved to, and by which rule. */
72
107
  export declare const SlipResolution: Schema.Struct<{
73
108
  readonly useCase: Schema.String;
@@ -97,7 +132,10 @@ export declare const Slip: Schema.Struct<{
97
132
  readonly segment: Schema.optionalKey<Schema.Struct<{
98
133
  readonly vendor: Schema.optionalKey<Schema.String>;
99
134
  readonly paymentMethod: Schema.optionalKey<Schema.String>;
135
+ readonly entitlements: Schema.optionalKey<Schema.$Array<Schema.String>>;
100
136
  }>>;
137
+ /** The line a `perLine` step was expanded for, by the recipe's key. */
138
+ readonly line: Schema.optionalKey<Schema.String>;
101
139
  readonly participant: Schema.optionalKey<Schema.String>;
102
140
  readonly call: Schema.optionalKey<Schema.Struct<{
103
141
  readonly method: Schema.Literals<readonly ["GET", "POST", "PUT", "PATCH", "DELETE"]>;
@@ -109,6 +147,11 @@ export declare const Slip: Schema.Struct<{
109
147
  }>>;
110
148
  /** Configuration pinned at composition — a hold's expiry, a limit. */
111
149
  readonly parameters: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
150
+ readonly guard: Schema.optionalKey<Schema.Struct<{
151
+ /** The step name of the wait, earlier in the slip. */
152
+ readonly wait: Schema.String;
153
+ readonly outcomes: Schema.$Array<Schema.String>;
154
+ }>>;
112
155
  }>>;
113
156
  }>>;
114
157
  readonly resolution: Schema.$Array<Schema.Struct<{
@@ -1 +1 @@
1
- {"version":3,"file":"slip.d.ts","sourceRoot":"","sources":["../../src/flow/slip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAExC;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAG,CAAU,CAAC;AAOvC,mFAAmF;AACnF,eAAO,MAAM,WAAW;;;EAGtB,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC,IAAI,CAAC;AAElD,4EAA4E;AAC5E,eAAO,MAAM,QAAQ;IACnB,uDAAuD;;IAEvD,gFAAgF;;;;;;;;;;;;;;;;IAOhF,sEAAsE;;EAEtE,CAAC;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,IA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AAM,IAAI,KAAG,OACT,CAAC;AAEhC,kDAAkD;AAClD,eAAO,MAAM,SAAS,GAAI,MAAM,IAAI,KAAG,SAAS,QAAQ,EACb,CAAC"}
package/dist/flow/slip.js CHANGED
@@ -15,9 +15,24 @@ const Call = Schema.Struct({
15
15
  ]),
16
16
  path: Schema.String
17
17
  });
18
- /** Tags that place a step in a segment of the flow: whose lines, which payment. */ export const SlipSegment = Schema.Struct({
18
+ /**
19
+ * Tags that place a step in a segment of the flow: whose lines, which payment.
20
+ * `entitlements` are the facts verified for the party the segment acts for —
21
+ * a vendor's provisioning, never the caller's — and a segment's steps are
22
+ * checked against them beside the flow's context.
23
+ */ export const SlipSegment = Schema.Struct({
19
24
  vendor: Schema.optionalKey(Schema.String),
20
- paymentMethod: Schema.optionalKey(Schema.String)
25
+ paymentMethod: Schema.optionalKey(Schema.String),
26
+ entitlements: Schema.optionalKey(Schema.Array(Schema.String))
27
+ });
28
+ /**
29
+ * A step that runs only when an earlier wait was answered with one of
30
+ * `outcomes` — the one branch a slip can take, decided by what the wait was
31
+ * told rather than by anything known at composition. A step guarded on a wait
32
+ * that was itself skipped is skipped too.
33
+ */ export const SlipGuard = Schema.Struct({
34
+ /** The step name of the wait, earlier in the slip. */ wait: Schema.String,
35
+ outcomes: Schema.Array(Schema.String)
21
36
  });
22
37
  /** One pinned step: a fragment reference and everything resolved for it. */ export const SlipStep = Schema.Struct({
23
38
  /** `id@version`, pinned when the slip was composed. */ ref: Schema.String,
@@ -28,10 +43,12 @@ const Call = Schema.Struct({
28
43
  'perLine'
29
44
  ]),
30
45
  segment: Schema.optionalKey(SlipSegment),
46
+ /** The line a `perLine` step was expanded for, by the recipe's key. */ line: Schema.optionalKey(Schema.String),
31
47
  participant: Schema.optionalKey(Schema.String),
32
48
  call: Schema.optionalKey(Call),
33
49
  compensation: Schema.optionalKey(Call),
34
- /** Configuration pinned at composition — a hold's expiry, a limit. */ parameters: Schema.optionalKey(Schema.Record(Schema.String, Schema.Unknown))
50
+ /** Configuration pinned at composition — a hold's expiry, a limit. */ parameters: Schema.optionalKey(Schema.Record(Schema.String, Schema.Unknown)),
51
+ guard: Schema.optionalKey(SlipGuard)
35
52
  });
36
53
  export const SlipStage = Schema.Struct({
37
54
  name: Schema.String,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/flow/slip.ts"],"sourcesContent":["import { ProtocolFailure } from '@entifix/core';\nimport { Effect, Schema } from 'effect';\n\n/**\n * The grammar version a slip is written in. An interpreter branches on it, so a\n * flow that started under one grammar finishes under that grammar even after\n * the next one ships.\n */\nexport const SLIP_VERSION = 1 as const;\n\nconst Call = Schema.Struct({\n method: Schema.Literals(['GET', 'POST', 'PUT', 'PATCH', 'DELETE']),\n path: Schema.String,\n});\n\n/** Tags that place a step in a segment of the flow: whose lines, which payment. */\nexport const SlipSegment = Schema.Struct({\n vendor: Schema.optionalKey(Schema.String),\n paymentMethod: Schema.optionalKey(Schema.String),\n});\nexport type SlipSegment = typeof SlipSegment.Type;\n\n/** One pinned step: a fragment reference and everything resolved for it. */\nexport const SlipStep = Schema.Struct({\n /** `id@version`, pinned when the slip was composed. */\n ref: Schema.String,\n /** Unique within the slip; what an Activity is named after (`segment:step`). */\n step: Schema.String,\n cardinality: Schema.Literals(['one', 'perVendor', 'perLine']),\n segment: Schema.optionalKey(SlipSegment),\n participant: Schema.optionalKey(Schema.String),\n call: Schema.optionalKey(Call),\n compensation: Schema.optionalKey(Call),\n /** Configuration pinned at composition — a hold's expiry, a limit. */\n parameters: Schema.optionalKey(Schema.Record(Schema.String, Schema.Unknown)),\n});\nexport type SlipStep = typeof SlipStep.Type;\n\nexport const SlipStage = Schema.Struct({\n name: Schema.String,\n steps: Schema.Array(SlipStep),\n});\nexport type SlipStage = typeof SlipStage.Type;\n\n/** Who may receive what the flow announces — the envelope's audience. */\nexport const SlipAudienceEntry = Schema.Struct({\n kind: Schema.Literals(['organization', 'party', 'flow']),\n id: Schema.String,\n digest: Schema.optionalKey(Schema.String),\n});\n\n/** Which variant each use case resolved to, and by which rule. */\nexport const SlipResolution = Schema.Struct({\n useCase: Schema.String,\n variant: Schema.String,\n rule: Schema.Number,\n});\nexport type SlipResolution = typeof SlipResolution.Type;\n\n/**\n * A routing slip: ordered stages of pinned steps, composed once at start and\n * stored as the flow's payload. Changing a recipe or a fragment never changes a\n * flow that has already started.\n */\nexport const Slip = Schema.Struct({\n slipVersion: Schema.Literal(SLIP_VERSION),\n flowId: Schema.String,\n recipe: Schema.String,\n /** The recipe demands a commit point even with no retriable step (a checkout). */\n requiresCommitPoint: Schema.optionalKey(Schema.Boolean),\n stages: Schema.Array(SlipStage),\n resolution: Schema.Array(SlipResolution),\n composedAt: Schema.String,\n /**\n * Who the flow's `flow.*` events reach beside the flow itself — the\n * organizations and parties it acts for, pinned when it was composed.\n */\n audience: Schema.optionalKey(Schema.Array(SlipAudienceEntry)),\n});\nexport type Slip = typeof Slip.Type;\n\n/**\n * Decodes a stored or received slip. An unknown `slipVersion`, like any shape\n * the grammar does not describe, is a protocol failure: an interpreter must\n * never guess at a grammar it was not built for.\n */\nexport const decodeSlip = (\n input: unknown,\n): Effect.Effect<Slip, ProtocolFailure> =>\n Schema.decodeUnknownEffect(Slip)(input).pipe(\n Effect.mapError(\n error =>\n new ProtocolFailure({\n reason: `the slip does not decode: ${error.message}`,\n }),\n ),\n );\n\n/** Encodes a slip as the workflow payload it travels as. */\nexport const encodeSlip = (slip: Slip): unknown =>\n Schema.encodeSync(Slip)(slip);\n\n/** Every step of a slip, in the order it runs. */\nexport const slipSteps = (slip: Slip): readonly SlipStep[] =>\n slip.stages.flatMap(stage => stage.steps);\n"],"names":["ProtocolFailure","Effect","Schema","SLIP_VERSION","Call","Struct","method","Literals","path","String","SlipSegment","vendor","optionalKey","paymentMethod","SlipStep","ref","step","cardinality","segment","participant","call","compensation","parameters","Record","Unknown","SlipStage","name","steps","Array","SlipAudienceEntry","kind","id","digest","SlipResolution","useCase","variant","rule","Number","Slip","slipVersion","Literal","flowId","recipe","requiresCommitPoint","Boolean","stages","resolution","composedAt","audience","decodeSlip","input","decodeUnknownEffect","pipe","mapError","error","reason","message","encodeSlip","slip","encodeSync","slipSteps","flatMap","stage"],"mappings":"AAAA,SAASA,eAAe,QAAQ,gBAAgB;AAChD,SAASC,MAAM,EAAEC,MAAM,QAAQ,SAAS;AAExC;;;;CAIC,GACD,OAAO,MAAMC,eAAe,EAAW;AAEvC,MAAMC,OAAOF,OAAOG,MAAM,CAAC;IACzBC,QAAQJ,OAAOK,QAAQ,CAAC;QAAC;QAAO;QAAQ;QAAO;QAAS;KAAS;IACjEC,MAAMN,OAAOO,MAAM;AACrB;AAEA,iFAAiF,GACjF,OAAO,MAAMC,cAAcR,OAAOG,MAAM,CAAC;IACvCM,QAAQT,OAAOU,WAAW,CAACV,OAAOO,MAAM;IACxCI,eAAeX,OAAOU,WAAW,CAACV,OAAOO,MAAM;AACjD,GAAG;AAGH,0EAA0E,GAC1E,OAAO,MAAMK,WAAWZ,OAAOG,MAAM,CAAC;IACpC,qDAAqD,GACrDU,KAAKb,OAAOO,MAAM;IAClB,8EAA8E,GAC9EO,MAAMd,OAAOO,MAAM;IACnBQ,aAAaf,OAAOK,QAAQ,CAAC;QAAC;QAAO;QAAa;KAAU;IAC5DW,SAAShB,OAAOU,WAAW,CAACF;IAC5BS,aAAajB,OAAOU,WAAW,CAACV,OAAOO,MAAM;IAC7CW,MAAMlB,OAAOU,WAAW,CAACR;IACzBiB,cAAcnB,OAAOU,WAAW,CAACR;IACjC,oEAAoE,GACpEkB,YAAYpB,OAAOU,WAAW,CAACV,OAAOqB,MAAM,CAACrB,OAAOO,MAAM,EAAEP,OAAOsB,OAAO;AAC5E,GAAG;AAGH,OAAO,MAAMC,YAAYvB,OAAOG,MAAM,CAAC;IACrCqB,MAAMxB,OAAOO,MAAM;IACnBkB,OAAOzB,OAAO0B,KAAK,CAACd;AACtB,GAAG;AAGH,uEAAuE,GACvE,OAAO,MAAMe,oBAAoB3B,OAAOG,MAAM,CA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ProtocolFailure } from '@entifix/core';\nimport { Effect, Schema } from 'effect';\n\n/**\n * The grammar version a slip is written in. An interpreter branches on it, so a\n * flow that started under one grammar finishes under that grammar even after\n * the next one ships.\n */\nexport const SLIP_VERSION = 1 as const;\n\nconst Call = Schema.Struct({\n method: Schema.Literals(['GET', 'POST', 'PUT', 'PATCH', 'DELETE']),\n path: Schema.String,\n});\n\n/**\n * Tags that place a step in a segment of the flow: whose lines, which payment.\n * `entitlements` are the facts verified for the party the segment acts for —\n * a vendor's provisioning, never the caller's — and a segment's steps are\n * checked against them beside the flow's context.\n */\nexport const SlipSegment = Schema.Struct({\n vendor: Schema.optionalKey(Schema.String),\n paymentMethod: Schema.optionalKey(Schema.String),\n entitlements: Schema.optionalKey(Schema.Array(Schema.String)),\n});\nexport type SlipSegment = typeof SlipSegment.Type;\n\n/**\n * A step that runs only when an earlier wait was answered with one of\n * `outcomes` — the one branch a slip can take, decided by what the wait was\n * told rather than by anything known at composition. A step guarded on a wait\n * that was itself skipped is skipped too.\n */\nexport const SlipGuard = Schema.Struct({\n /** The step name of the wait, earlier in the slip. */\n wait: Schema.String,\n outcomes: Schema.Array(Schema.String),\n});\nexport type SlipGuard = typeof SlipGuard.Type;\n\n/** One pinned step: a fragment reference and everything resolved for it. */\nexport const SlipStep = Schema.Struct({\n /** `id@version`, pinned when the slip was composed. */\n ref: Schema.String,\n /** Unique within the slip; what an Activity is named after (`segment:step`). */\n step: Schema.String,\n cardinality: Schema.Literals(['one', 'perVendor', 'perLine']),\n segment: Schema.optionalKey(SlipSegment),\n /** The line a `perLine` step was expanded for, by the recipe's key. */\n line: Schema.optionalKey(Schema.String),\n participant: Schema.optionalKey(Schema.String),\n call: Schema.optionalKey(Call),\n compensation: Schema.optionalKey(Call),\n /** Configuration pinned at composition — a hold's expiry, a limit. */\n parameters: Schema.optionalKey(Schema.Record(Schema.String, Schema.Unknown)),\n guard: Schema.optionalKey(SlipGuard),\n});\nexport type SlipStep = typeof SlipStep.Type;\n\nexport const SlipStage = Schema.Struct({\n name: Schema.String,\n steps: Schema.Array(SlipStep),\n});\nexport type SlipStage = typeof SlipStage.Type;\n\n/** Who may receive what the flow announces — the envelope's audience. */\nexport const SlipAudienceEntry = Schema.Struct({\n kind: Schema.Literals(['organization', 'party', 'flow']),\n id: Schema.String,\n digest: Schema.optionalKey(Schema.String),\n});\nexport type SlipAudienceEntry = typeof SlipAudienceEntry.Type;\n\n/** Which variant each use case resolved to, and by which rule. */\nexport const SlipResolution = Schema.Struct({\n useCase: Schema.String,\n variant: Schema.String,\n rule: Schema.Number,\n});\nexport type SlipResolution = typeof SlipResolution.Type;\n\n/**\n * A routing slip: ordered stages of pinned steps, composed once at start and\n * stored as the flow's payload. Changing a recipe or a fragment never changes a\n * flow that has already started.\n */\nexport const Slip = Schema.Struct({\n slipVersion: Schema.Literal(SLIP_VERSION),\n flowId: Schema.String,\n recipe: Schema.String,\n /** The recipe demands a commit point even with no retriable step (a checkout). */\n requiresCommitPoint: Schema.optionalKey(Schema.Boolean),\n stages: Schema.Array(SlipStage),\n resolution: Schema.Array(SlipResolution),\n composedAt: Schema.String,\n /**\n * Who the flow's `flow.*` events reach beside the flow itself — the\n * organizations and parties it acts for, pinned when it was composed.\n */\n audience: Schema.optionalKey(Schema.Array(SlipAudienceEntry)),\n});\nexport type Slip = typeof Slip.Type;\n\n/**\n * Decodes a stored or received slip. An unknown `slipVersion`, like any shape\n * the grammar does not describe, is a protocol failure: an interpreter must\n * never guess at a grammar it was not built for.\n */\nexport const decodeSlip = (\n input: unknown,\n): Effect.Effect<Slip, ProtocolFailure> =>\n Schema.decodeUnknownEffect(Slip)(input).pipe(\n Effect.mapError(\n error =>\n new ProtocolFailure({\n reason: `the slip does not decode: ${error.message}`,\n }),\n ),\n );\n\n/** Encodes a slip as the workflow payload it travels as. */\nexport const encodeSlip = (slip: Slip): unknown =>\n Schema.encodeSync(Slip)(slip);\n\n/** Every step of a slip, in the order it runs. */\nexport const slipSteps = (slip: Slip): readonly SlipStep[] =>\n slip.stages.flatMap(stage => stage.steps);\n"],"names":["ProtocolFailure","Effect","Schema","SLIP_VERSION","Call","Struct","method","Literals","path","String","SlipSegment","vendor","optionalKey","paymentMethod","entitlements","Array","SlipGuard","wait","outcomes","SlipStep","ref","step","cardinality","segment","line","participant","call","compensation","parameters","Record","Unknown","guard","SlipStage","name","steps","SlipAudienceEntry","kind","id","digest","SlipResolution","useCase","variant","rule","Number","Slip","slipVersion","Literal","flowId","recipe","requiresCommitPoint","Boolean","stages","resolution","composedAt","audience","decodeSlip","input","decodeUnknownEffect","pipe","mapError","error","reason","message","encodeSlip","slip","encodeSync","slipSteps","flatMap","stage"],"mappings":"AAAA,SAASA,eAAe,QAAQ,gBAAgB;AAChD,SAASC,MAAM,EAAEC,MAAM,QAAQ,SAAS;AAExC;;;;CAIC,GACD,OAAO,MAAMC,eAAe,EAAW;AAEvC,MAAMC,OAAOF,OAAOG,MAAM,CAAC;IACzBC,QAAQJ,OAAOK,QAAQ,CAAC;QAAC;QAAO;QAAQ;QAAO;QAAS;KAAS;IACjEC,MAAMN,OAAOO,MAAM;AACrB;AAEA;;;;;CAKC,GACD,OAAO,MAAMC,cAAcR,OAAOG,MAAM,CAAC;IACvCM,QAAQT,OAAOU,WAAW,CAACV,OAAOO,MAAM;IACxCI,eAAeX,OAAOU,WAAW,CAACV,OAAOO,MAAM;IAC/CK,cAAcZ,OAAOU,WAAW,CAACV,OAAOa,KAAK,CAACb,OAAOO,MAAM;AAC7D,GAAG;AAGH;;;;;CAKC,GACD,OAAO,MAAMO,YAAYd,OAAOG,MAAM,CAAC;IACrC,oDAAoD,GACpDY,MAAMf,OAAOO,MAAM;IACnBS,UAAUhB,OAAOa,KAAK,CAACb,OAAOO,MAAM;AACtC,GAAG;AAGH,0EAA0E,GAC1E,OAAO,MAAMU,WAAWjB,OAAOG,MAAM,CAAC;IACpC,qDAAqD,GACrDe,KAAKlB,OAAOO,MAAM;IAClB,8EAA8E,GAC9EY,MAAMnB,OAAOO,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YAAYlD,OAAOa,KAAK,CAACwB;IACzBc,YAAYnD,OAAOO,MAAM;IACzB;;;GAGC,GACD6C,UAAUpD,OAAOU,WAAW,CAACV,OAAOa,KAAK,CAACoB;AAC5C,GAAG;AAGH;;;;CAIC,GACD,OAAO,MAAMoB,aAAa,CACxBC,QAEAtD,OAAOuD,mBAAmB,CAACb,MAAMY,OAAOE,IAAI,CAC1CzD,OAAO0D,QAAQ,CACbC,CAAAA,QACE,IAAI5D,gBAAgB;YAClB6D,QAAQ,CAAC,0BAA0B,EAAED,MAAME,OAAO,EAAE;QACtD,KAEJ;AAEJ,0DAA0D,GAC1D,OAAO,MAAMC,aAAa,CAACC,OACzB9D,OAAO+D,UAAU,CAACrB,MAAMoB,MAAM;AAEhC,gDAAgD,GAChD,OAAO,MAAME,YAAY,CAACF,OACxBA,KAAKb,MAAM,CAACgB,OAAO,CAACC,CAAAA,QAASA,MAAMlC,KAAK,EAAE"}
@@ -4,7 +4,7 @@ import { type FragmentKeys, type FragmentRequirements } from './fragment.js';
4
4
  import { type Slip } from './slip.js';
5
5
  /** One rule a slip broke, named by its tag. */
6
6
  export interface SlipViolation {
7
- readonly tag: 'UnknownFragment' | 'TooManyPivots' | 'MissingCommitPoint' | 'RetriableBeforeCommit' | 'CompensatableAfterCommit' | 'IrreversibleBeforeCommit' | 'WaitBeforeCommit' | 'ExcludedFromSegment' | 'UnsatisfiedInput' | 'UnmetRequirement';
7
+ readonly tag: 'UnknownFragment' | 'TooManyPivots' | 'MissingCommitPoint' | 'RetriableBeforeCommit' | 'CompensatableAfterCommit' | 'IrreversibleBeforeCommit' | 'WaitBeforeCommit' | 'ExcludedFromSegment' | 'UnsatisfiedInput' | 'UnmetRequirement' | 'UnknownGuard';
8
8
  /** The step that broke it, when one step did. */
9
9
  readonly step?: string;
10
10
  readonly detail: string;
@@ -1 +1 @@
1
- {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/flow/validate.ts"],"names":[],"mappings":"AACA,OAAO,EAA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QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,mBAAmB;IAClC,sFAAsF;IACtF,QAAQ,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC;IACpC,gEAAgE;IAChE,QAAQ,CAAC,KAAK,CAAC,EAAE,YAAY,CAAC;CAC/B;AASD,+EAA+E;AAC/E,eAAO,MAAM,iBAAiB,GAC5B,UAAU,oBAAoB,EAC9B,OAAO,gBAAgB,KACtB,MAAM,EAkBR,CAAC;AAkBF;;;;GAIG;AACH,eAAO,MAAM,YAAY,GACvB,MAAM,IAAI,EACV,SAAS,eAAe,EACxB,UAAS,mBAAwB,KAChC,SAAS,aAAa,EAmJxB,CAAC;;;;;;;;AAQF;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,uBAQvC;CAAG;;;;;;;;AAEJ;;;;;GAKG;AACH,qBAAa,qBAAsB,SAAQ,0BAQ1C;CAAG;AAEJ,2EAA2E;AAC3E,eAAO,MAAM,qBAAqB,GAChC,YAAY,SAAS,aAAa,EAAE,KACnC,OAEkE,CAAC;AAEtE;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAC1B,MAAM,IAAI,EACV,SAAS,eAAe,EACxB,UAAS,mBAAwB,KAChC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,kBAAkB,GAAG,qBAAqB,CAQhE,CAAC"}
@@ -1,7 +1,16 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
1
2
  import { Failure } from '@entifix/core';
2
3
  import { Effect, Schema } from 'effect';
3
4
  import { jsonSchemaOf } from './fragment.js';
4
5
  import { slipSteps } from './slip.js';
6
+ /** The outcome a wait's timeout answers with, when it names one rather than stranding. */ const timeoutOutcomeOf = (step)=>{
7
+ var _step_parameters;
8
+ const onTimeout = (_step_parameters = step.parameters) == null ? void 0 : _step_parameters['onTimeout'];
9
+ const outcome = typeof onTimeout === 'object' && onTimeout !== null ? onTimeout.outcome : undefined;
10
+ return typeof outcome === 'string' ? [
11
+ outcome
12
+ ] : [];
13
+ };
5
14
  const sameSchema = (a, b)=>a === b || JSON.stringify(jsonSchemaOf(a)) === JSON.stringify(jsonSchemaOf(b));
6
15
  /** The requirements `facts` do not meet, described; empty when all are met. */ export const unmetRequirements = (requires, facts)=>{
7
16
  var _requires_entitlements, _facts_entitlements, _requires_roles, _facts_roles, _facts_partyRole, _facts_channel;
@@ -12,6 +21,19 @@ const sameSchema = (a, b)=>a === b || JSON.stringify(jsonSchemaOf(a)) === JSON.s
12
21
  if (requires.channels !== undefined && !requires.channels.includes((_facts_channel = facts.channel) != null ? _facts_channel : '')) missing.push(`channel in ${requires.channels.join(', ')}`);
13
22
  return missing;
14
23
  };
24
+ /**
25
+ * The facts a segment's step is checked against: the flow's, plus what was
26
+ * verified for the party the segment acts for. A storefront buyer holds no
27
+ * entitlement, and the vendor whose stock a step holds does.
28
+ */ const withSegmentFacts = (facts, entitlements)=>{
29
+ var _facts_entitlements;
30
+ return entitlements === undefined ? facts : _extends({}, facts, {
31
+ entitlements: [
32
+ ...(_facts_entitlements = facts.entitlements) != null ? _facts_entitlements : [],
33
+ ...entitlements
34
+ ]
35
+ });
36
+ };
15
37
  /**
16
38
  * Checks a slip against its catalog and returns **every** violation, one tag
17
39
  * per rule, rather than throwing at the first — so a CI job enumerating every
@@ -44,8 +66,9 @@ const sameSchema = (a, b)=>a === b || JSON.stringify(jsonSchemaOf(a)) === JSON.s
44
66
  detail: 'the slip needs one commit point — a pivot, or flow.commit@1 — before its first retriable step'
45
67
  });
46
68
  const provided = new Map(Object.entries((_options_start = options.start) != null ? _options_start : {}));
69
+ /** Every wait seen so far, by step name, with what it can be answered. */ const waits = new Map();
47
70
  resolved.forEach(({ step, fragment }, index)=>{
48
- var _fragment_excludedFrom, _fragment_consumes, _fragment_provides;
71
+ var _fragment_outcomes, _fragment_excludedFrom, _fragment_consumes, _fragment_provides;
49
72
  const beforeCommit = commitAt === -1 || index < commitAt;
50
73
  const afterCommit = commitAt !== -1 && index > commitAt;
51
74
  if (fragment.kind === 'retriable' && commitAt !== -1 && index < commitAt) violations.push({
@@ -68,6 +91,23 @@ const sameSchema = (a, b)=>a === b || JSON.stringify(jsonSchemaOf(a)) === JSON.s
68
91
  step: step.step,
69
92
  detail: `'${step.ref}' waits before the commit point, holding uncommitted state for as long as it waits`
70
93
  });
94
+ if (step.guard !== undefined) {
95
+ const answers = waits.get(step.guard.wait);
96
+ if (answers === undefined) violations.push({
97
+ tag: 'UnknownGuard',
98
+ step: step.step,
99
+ detail: `'${step.ref}' is guarded on '${step.guard.wait}', which is no wait before it`
100
+ });
101
+ else for (const outcome of step.guard.outcomes)if (!answers.includes(outcome)) violations.push({
102
+ tag: 'UnknownGuard',
103
+ step: step.step,
104
+ detail: `'${step.ref}' is guarded on '${outcome}', which '${step.guard.wait}' is never answered with`
105
+ });
106
+ }
107
+ if (fragment.kind === 'wait') waits.set(step.step, [
108
+ ...(_fragment_outcomes = fragment.outcomes) != null ? _fragment_outcomes : [],
109
+ ...timeoutOutcomeOf(step)
110
+ ]);
71
111
  for (const [tag, values] of Object.entries((_fragment_excludedFrom = fragment.excludedFrom) != null ? _fragment_excludedFrom : {})){
72
112
  var _step_segment;
73
113
  const value = (_step_segment = step.segment) == null ? void 0 : _step_segment[tag];
@@ -92,7 +132,8 @@ const sameSchema = (a, b)=>a === b || JSON.stringify(jsonSchemaOf(a)) === JSON.s
92
132
  }
93
133
  for (const [key, schema] of Object.entries((_fragment_provides = fragment.provides) != null ? _fragment_provides : {}))provided.set(key, schema);
94
134
  if (options.context !== undefined && fragment.requires !== undefined) {
95
- const missing = unmetRequirements(fragment.requires, options.context);
135
+ var _step_segment1;
136
+ const missing = unmetRequirements(fragment.requires, withSegmentFacts(options.context, (_step_segment1 = step.segment) == null ? void 0 : _step_segment1.entitlements));
96
137
  if (missing.length > 0) violations.push({
97
138
  tag: 'UnmetRequirement',
98
139
  step: step.step,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/flow/validate.ts"],"sourcesContent":["import { Failure } from '@entifix/core';\nimport { Effect, Schema } from 'effect';\n\nimport type { FragmentCatalog } from './catalog.js';\nimport {\n type FragmentDescriptor,\n type FragmentKeys,\n type FragmentRequirements,\n jsonSchemaOf,\n} from './fragment.js';\nimport { type Slip, type SlipStep, slipSteps } from './slip.js';\n\n/** One rule a slip broke, named by its tag. */\nexport interface SlipViolation {\n readonly tag:\n | 'UnknownFragment'\n | 'TooManyPivots'\n | 'MissingCommitPoint'\n | 'RetriableBeforeCommit'\n | 'CompensatableAfterCommit'\n | 'IrreversibleBeforeCommit'\n | 'WaitBeforeCommit'\n | 'ExcludedFromSegment'\n | 'UnsatisfiedInput'\n | 'UnmetRequirement';\n /** The step that broke it, when one step did. */\n readonly step?: string;\n readonly detail: string;\n}\n\n/** The facts of a verified context a slip's requirements are checked against. */\nexport interface RequirementFacts {\n readonly entitlements?: readonly string[];\n readonly roles?: readonly string[];\n readonly partyRole?: string;\n readonly channel?: string;\n}\n\nexport interface ValidateSlipOptions {\n /** The facts the caller was verified with; requirements go unchecked without them. */\n readonly context?: RequirementFacts;\n /** Keys the flow's start input provides, with their schemas. */\n readonly start?: FragmentKeys;\n}\n\nconst sameSchema = (\n a: Schema.Codec<unknown, unknown>,\n b: Schema.Codec<unknown, unknown>,\n): boolean =>\n a === b ||\n JSON.stringify(jsonSchemaOf(a)) === JSON.stringify(jsonSchemaOf(b));\n\n/** The requirements `facts` do not meet, described; empty when all are met. */\nexport const unmetRequirements = (\n requires: FragmentRequirements,\n facts: RequirementFacts,\n): string[] => {\n const missing: string[] = [];\n for (const entitlement of requires.entitlements ?? [])\n if (!(facts.entitlements ?? []).includes(entitlement))\n missing.push(`entitlement '${entitlement}'`);\n for (const role of requires.roles ?? [])\n if (!(facts.roles ?? []).includes(role)) missing.push(`role '${role}'`);\n if (\n requires.partyRoles !== undefined &&\n !requires.partyRoles.includes(facts.partyRole ?? '')\n )\n missing.push(`party role in ${requires.partyRoles.join(', ')}`);\n if (\n requires.channels !== undefined &&\n !requires.channels.includes(facts.channel ?? '')\n )\n missing.push(`channel in ${requires.channels.join(', ')}`);\n return missing;\n};\n\n/**\n * Checks a slip against its catalog and returns **every** violation, one tag\n * per rule, rather than throwing at the first — so a CI job enumerating every\n * composition reports them all in one run. Pure: no clock, no I/O.\n */\nexport const validateSlip = (\n slip: Slip,\n catalog: FragmentCatalog,\n options: ValidateSlipOptions = {},\n): readonly SlipViolation[] => {\n const violations: SlipViolation[] = [];\n const resolved: {\n readonly step: SlipStep;\n readonly fragment: FragmentDescriptor;\n }[] = [];\n\n for (const step of slipSteps(slip)) {\n const fragment = catalog.get(step.ref);\n if (fragment === undefined)\n violations.push({\n tag: 'UnknownFragment',\n step: step.step,\n detail: `'${step.ref}' is not in the catalog`,\n });\n else resolved.push({ step, fragment });\n }\n\n const pivots = resolved.filter(({ fragment }) => fragment.kind === 'pivot');\n if (pivots.length > 1)\n violations.push({\n tag: 'TooManyPivots',\n detail: `the slip has ${String(pivots.length)} pivots (${pivots\n .map(({ step }) => step.step)\n .join(', ')}); a flow has one point of no return`,\n });\n\n const commitAt = resolved.findIndex(\n ({ fragment }) => fragment.kind === 'pivot',\n );\n const hasRetriable = resolved.some(\n ({ fragment }) => fragment.kind === 'retriable',\n );\n if (commitAt === -1 && (hasRetriable || slip.requiresCommitPoint === true))\n violations.push({\n tag: 'MissingCommitPoint',\n detail:\n 'the slip needs one commit point — a pivot, or flow.commit@1 — before its first retriable step',\n });\n\n const provided = new Map<string, Schema.Codec<unknown, unknown>>(\n Object.entries(options.start ?? {}),\n );\n\n resolved.forEach(({ step, fragment }, index) => {\n const beforeCommit = commitAt === -1 || index < commitAt;\n const afterCommit = commitAt !== -1 && index > commitAt;\n\n if (fragment.kind === 'retriable' && commitAt !== -1 && index < commitAt)\n violations.push({\n tag: 'RetriableBeforeCommit',\n step: step.step,\n detail: `'${step.ref}' is retriable and runs before the commit point, where a failure must compensate`,\n });\n if (fragment.kind === 'compensatable' && afterCommit)\n violations.push({\n tag: 'CompensatableAfterCommit',\n step: step.step,\n detail: `'${step.ref}' is compensatable and runs after the commit point, where nothing is undone`,\n });\n if (\n fragment.irreversible === true &&\n fragment.kind !== 'pivot' &&\n beforeCommit\n )\n violations.push({\n tag: 'IrreversibleBeforeCommit',\n step: step.step,\n detail: `'${step.ref}' cannot be undone and runs before the commit point`,\n });\n if (fragment.kind === 'wait' && beforeCommit)\n violations.push({\n tag: 'WaitBeforeCommit',\n step: step.step,\n detail: `'${step.ref}' waits before the commit point, holding uncommitted state for as long as it waits`,\n });\n\n for (const [tag, values] of Object.entries(fragment.excludedFrom ?? {})) {\n const value = (\n step.segment as Record<string, string | undefined> | undefined\n )?.[tag];\n if (value !== undefined && values.includes(value))\n violations.push({\n tag: 'ExcludedFromSegment',\n step: step.step,\n detail: `'${step.ref}' may not run in a segment whose ${tag} is '${value}'`,\n });\n }\n\n for (const [key, schema] of Object.entries(fragment.consumes ?? {})) {\n const earlier = provided.get(key);\n if (earlier === undefined)\n violations.push({\n tag: 'UnsatisfiedInput',\n step: step.step,\n detail: `'${step.ref}' consumes '${key}', which nothing before it provides`,\n });\n else if (!sameSchema(earlier, schema))\n violations.push({\n tag: 'UnsatisfiedInput',\n step: step.step,\n detail: `'${step.ref}' consumes '${key}' with a schema other than the one provided`,\n });\n }\n for (const [key, schema] of Object.entries(fragment.provides ?? {}))\n provided.set(key, schema);\n\n if (options.context !== undefined && fragment.requires !== undefined) {\n const missing = unmetRequirements(fragment.requires, options.context);\n if (missing.length > 0)\n violations.push({\n tag: 'UnmetRequirement',\n step: step.step,\n detail: `'${step.ref}' requires ${missing.join(', ')}`,\n });\n }\n });\n\n return violations;\n};\n\nconst SlipViolationSchema = Schema.Struct({\n tag: Schema.String,\n step: Schema.optionalKey(Schema.String),\n detail: Schema.String,\n});\n\n/**\n * A flow that cannot be composed for this caller: the slip broke at least one\n * rule. Every violation travels with it.\n */\nexport class CompositionRefused extends Failure.declined<CompositionRefused>()(\n 'CompositionRefused',\n 'flowNotComposable',\n { violations: Schema.Array(SlipViolationSchema) },\n {\n message: ({ violations }) =>\n `the flow cannot be composed: ${violations.map(v => v.tag).join(', ')}`,\n },\n) {}\n\n/**\n * A flow this caller is not offered: every rule the slip broke is a step's\n * requirement — an entitlement, a role, a party role or a channel — that the\n * verified context lacks. The recipe is sound; the caller may not run it, so\n * it is `forbidden` rather than a slip that could not be built.\n */\nexport class FlowRequirementsUnmet extends Failure.forbidden<FlowRequirementsUnmet>()(\n 'FlowRequirementsUnmet',\n 'flowRequirementsUnmet',\n { violations: Schema.Array(SlipViolationSchema) },\n {\n message: ({ violations }) =>\n `the flow is not offered to this caller: ${violations.map(v => v.detail).join('; ')}`,\n },\n) {}\n\n/** Every violation is a requirement the caller lacks, and there is one. */\nexport const onlyUnmetRequirements = (\n violations: readonly SlipViolation[],\n): boolean =>\n violations.length > 0 &&\n violations.every(violation => violation.tag === 'UnmetRequirement');\n\n/**\n * Validates a slip, failing on any violation: with {@link FlowRequirementsUnmet}\n * when the caller lacks only what steps require, and otherwise with\n * {@link CompositionRefused}, which carries every violation.\n */\nexport const assertValidSlip = (\n slip: Slip,\n catalog: FragmentCatalog,\n options: ValidateSlipOptions = {},\n): Effect.Effect<Slip, CompositionRefused | FlowRequirementsUnmet> => {\n const violations = validateSlip(slip, catalog, options);\n if (violations.length === 0) return Effect.succeed(slip);\n return Effect.fail(\n onlyUnmetRequirements(violations)\n ? new FlowRequirementsUnmet({ violations })\n : new CompositionRefused({ violations }),\n );\n};\n"],"names":["Failure","Effect","Schema","jsonSchemaOf","slipSteps","sameSchema","a","b","JSON","stringify","unmetRequirements","requires","facts","missing","entitlement","entitlements","includes","push","role","roles","partyRoles","undefined","partyRole","join","channels","channel","validateSlip","slip","catalog","options","violations","resolved","step","fragment","get","ref","tag","detail","pivots","filter","kind","length","String","map","commitAt","findIndex","hasRetriable","some","requiresCommitPoint","provided","Map","Object","entries","start","forEach","index","beforeCommit","afterCommit","irreversible","values","excludedFrom","value","segment","key","schema","consumes","earlier","provides","set","context","SlipViolationSchema","Struct","optionalKey","CompositionRefused","declined","Array","message","v","FlowRequirementsUnmet","forbidden","onlyUnmetRequirements","every","violation","assertValidSlip","succeed","fail"],"mappings":"AAAA,SAASA,OAAO,QAAQ,gBAAgB;AACxC,SAASC,MAAM,EAAEC,MAAM,QAAQ,SAAS;AAGxC,SAIEC,YAAY,QACP,gBAAgB;AACvB,SAAmCC,SAAS,QAAQ,YAAY;AAmChE,MAAMC,aAAa,CACjBC,GACAC,IAEAD,MAAMC,KACNC,KAAKC,SAAS,CAACN,aAAaG,QAAQE,KAAKC,SAAS,CAACN,aAAaI;AAElE,6EAA6E,GAC7E,OAAO,MAAMG,oBAAoB,CAC/BC,UACAC;QAG0BD,wBAClBC,qBAEWD,iBACXC,cAGwBA,kBAKFA;IAb9B,MAAMC,UAAoB,EAAE;IAC5B,KAAK,MAAMC,gBAAeH,yBAAAA,SAASI,YAAY,YAArBJ,yBAAyB,EAAE,CACnD,IAAI,CAAC,EAACC,sBAAAA,MAAMG,YAAY,YAAlBH,sBAAsB,EAAE,EAAEI,QAAQ,CAACF,cACvCD,QAAQI,IAAI,CAAC,CAAC,aAAa,EAAEH,YAAY,CAAC,CAAC;IAC/C,KAAK,MAAMI,SAAQP,kBAAAA,SAASQ,KAAK,YAAdR,kBAAkB,EAAE,CACrC,IAAI,CAAC,EAACC,eAAAA,MAAMO,KAAK,YAAXP,eAAe,EAAE,EAAEI,QAAQ,CAACE,OAAOL,QAAQI,IAAI,CAAC,CAAC,MAAM,EAAEC,KAAK,CAAC,CAAC;IACxE,IACEP,SAASS,UAAU,KAAKC,aACxB,CAACV,SAASS,UAAU,CAACJ,QAAQ,EAACJ,mBAAAA,MAAMU,SAAS,YAAfV,mBAAmB,KAEjDC,QAAQI,IAAI,CAAC,CAAC,cAAc,EAAEN,SAASS,UAAU,CAACG,IAAI,CAAC,OAAO;IAChE,IACEZ,SAASa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MAAMC,SAASC;IAC/C,IAAIC,WAAWW,MAAM,KAAK,GAAG,OAAOxC,OAAOmF,OAAO,CAACzD;IACnD,OAAO1B,OAAOoF,IAAI,CAChBL,sBAAsBlD,cAClB,IAAIgD,sBAAsB;QAAEhD;IAAW,KACvC,IAAI2C,mBAAmB;QAAE3C;IAAW;AAE5C,EAAE"}
1
+ {"version":3,"sources":["../../src/flow/validate.ts"],"sourcesContent":["import { Failure } from '@entifix/core';\nimport { Effect, Schema } from 'effect';\n\nimport type { FragmentCatalog } from './catalog.js';\nimport {\n type FragmentDescriptor,\n type FragmentKeys,\n type FragmentRequirements,\n jsonSchemaOf,\n} from './fragment.js';\nimport { type Slip, type SlipStep, slipSteps } from './slip.js';\n\n/** One rule a slip broke, named by its tag. */\nexport interface SlipViolation {\n readonly tag:\n | 'UnknownFragment'\n | 'TooManyPivots'\n | 'MissingCommitPoint'\n | 'RetriableBeforeCommit'\n | 'CompensatableAfterCommit'\n | 'IrreversibleBeforeCommit'\n | 'WaitBeforeCommit'\n | 'ExcludedFromSegment'\n | 'UnsatisfiedInput'\n | 'UnmetRequirement'\n | 'UnknownGuard';\n /** The step that broke it, when one step did. */\n readonly step?: string;\n readonly detail: string;\n}\n\n/** The outcome a wait's timeout answers with, when it names one rather than stranding. */\nconst timeoutOutcomeOf = (step: SlipStep): readonly string[] => {\n const onTimeout = step.parameters?.['onTimeout'];\n const outcome =\n typeof onTimeout === 'object' && onTimeout !== null\n ? (onTimeout as { readonly outcome?: unknown }).outcome\n : undefined;\n return typeof outcome === 'string' ? [outcome] : [];\n};\n\n/** The facts of a verified context a slip's requirements are checked against. */\nexport interface RequirementFacts {\n readonly entitlements?: readonly string[];\n readonly roles?: readonly string[];\n readonly partyRole?: string;\n readonly channel?: string;\n}\n\nexport interface ValidateSlipOptions {\n /** The facts the caller was verified with; requirements go unchecked without them. */\n readonly context?: RequirementFacts;\n /** Keys the flow's start input provides, with their schemas. */\n readonly start?: FragmentKeys;\n}\n\nconst sameSchema = (\n a: Schema.Codec<unknown, unknown>,\n b: Schema.Codec<unknown, unknown>,\n): boolean =>\n a === b ||\n JSON.stringify(jsonSchemaOf(a)) === JSON.stringify(jsonSchemaOf(b));\n\n/** The requirements `facts` do not meet, described; empty when all are met. */\nexport const unmetRequirements = (\n requires: FragmentRequirements,\n facts: RequirementFacts,\n): string[] => {\n const missing: string[] = [];\n for (const entitlement of requires.entitlements ?? [])\n if (!(facts.entitlements ?? []).includes(entitlement))\n missing.push(`entitlement '${entitlement}'`);\n for (const role of requires.roles ?? [])\n if (!(facts.roles ?? []).includes(role)) missing.push(`role '${role}'`);\n if (\n requires.partyRoles !== undefined &&\n !requires.partyRoles.includes(facts.partyRole ?? '')\n )\n missing.push(`party role in ${requires.partyRoles.join(', ')}`);\n if (\n requires.channels !== undefined &&\n !requires.channels.includes(facts.channel ?? '')\n )\n missing.push(`channel in ${requires.channels.join(', ')}`);\n return missing;\n};\n\n/**\n * The facts a segment's step is checked against: the flow's, plus what was\n * verified for the party the segment acts for. A storefront buyer holds no\n * entitlement, and the vendor whose stock a step holds does.\n */\nconst withSegmentFacts = (\n facts: RequirementFacts,\n entitlements: readonly string[] | undefined,\n): RequirementFacts =>\n entitlements === undefined\n ? facts\n : {\n ...facts,\n entitlements: [...(facts.entitlements ?? []), ...entitlements],\n };\n\n/**\n * Checks a slip against its catalog and returns **every** violation, one tag\n * per rule, rather than throwing at the first — so a CI job enumerating every\n * composition reports them all in one run. Pure: no clock, no I/O.\n */\nexport const validateSlip = (\n slip: Slip,\n catalog: FragmentCatalog,\n options: ValidateSlipOptions = {},\n): readonly SlipViolation[] => {\n const violations: SlipViolation[] = [];\n const resolved: {\n readonly step: SlipStep;\n readonly fragment: FragmentDescriptor;\n }[] = [];\n\n for (const step of slipSteps(slip)) {\n const fragment = catalog.get(step.ref);\n if (fragment === undefined)\n violations.push({\n tag: 'UnknownFragment',\n step: step.step,\n detail: `'${step.ref}' is not in the catalog`,\n });\n else resolved.push({ step, fragment });\n }\n\n const pivots = resolved.filter(({ fragment }) => fragment.kind === 'pivot');\n if (pivots.length > 1)\n violations.push({\n tag: 'TooManyPivots',\n detail: `the slip has ${String(pivots.length)} pivots (${pivots\n .map(({ step }) => step.step)\n .join(', ')}); a flow has one point of no return`,\n });\n\n const commitAt = resolved.findIndex(\n ({ fragment }) => fragment.kind === 'pivot',\n );\n const hasRetriable = resolved.some(\n ({ fragment }) => fragment.kind === 'retriable',\n );\n if (commitAt === -1 && (hasRetriable || slip.requiresCommitPoint === true))\n violations.push({\n tag: 'MissingCommitPoint',\n detail:\n 'the slip needs one commit point — a pivot, or flow.commit@1 — before its first retriable step',\n });\n\n const provided = new Map<string, Schema.Codec<unknown, unknown>>(\n Object.entries(options.start ?? {}),\n );\n /** Every wait seen so far, by step name, with what it can be answered. */\n const waits = new Map<string, readonly string[]>();\n\n resolved.forEach(({ step, fragment }, index) => {\n const beforeCommit = commitAt === -1 || index < commitAt;\n const afterCommit = commitAt !== -1 && index > commitAt;\n\n if (fragment.kind === 'retriable' && commitAt !== -1 && index < commitAt)\n violations.push({\n tag: 'RetriableBeforeCommit',\n step: step.step,\n detail: `'${step.ref}' is retriable and runs before the commit point, where a failure must compensate`,\n });\n if (fragment.kind === 'compensatable' && afterCommit)\n violations.push({\n tag: 'CompensatableAfterCommit',\n step: step.step,\n detail: `'${step.ref}' is compensatable and runs after the commit point, where nothing is undone`,\n });\n if (\n fragment.irreversible === true &&\n fragment.kind !== 'pivot' &&\n beforeCommit\n )\n violations.push({\n tag: 'IrreversibleBeforeCommit',\n step: step.step,\n detail: `'${step.ref}' cannot be undone and runs before the commit point`,\n });\n if (fragment.kind === 'wait' && beforeCommit)\n violations.push({\n tag: 'WaitBeforeCommit',\n step: step.step,\n detail: `'${step.ref}' waits before the commit point, holding uncommitted state for as long as it waits`,\n });\n\n if (step.guard !== undefined) {\n const answers = waits.get(step.guard.wait);\n if (answers === undefined)\n violations.push({\n tag: 'UnknownGuard',\n step: step.step,\n detail: `'${step.ref}' is guarded on '${step.guard.wait}', which is no wait before it`,\n });\n else\n for (const outcome of step.guard.outcomes)\n if (!answers.includes(outcome))\n violations.push({\n tag: 'UnknownGuard',\n step: step.step,\n detail: `'${step.ref}' is guarded on '${outcome}', which '${step.guard.wait}' is never answered with`,\n });\n }\n if (fragment.kind === 'wait')\n waits.set(step.step, [\n ...(fragment.outcomes ?? []),\n ...timeoutOutcomeOf(step),\n ]);\n\n for (const [tag, values] of Object.entries(fragment.excludedFrom ?? {})) {\n const value = (\n step.segment as Record<string, string | undefined> | undefined\n )?.[tag];\n if (value !== undefined && values.includes(value))\n violations.push({\n tag: 'ExcludedFromSegment',\n step: step.step,\n detail: `'${step.ref}' may not run in a segment whose ${tag} is '${value}'`,\n });\n }\n\n for (const [key, schema] of Object.entries(fragment.consumes ?? {})) {\n const earlier = provided.get(key);\n if (earlier === undefined)\n violations.push({\n tag: 'UnsatisfiedInput',\n step: step.step,\n detail: `'${step.ref}' consumes '${key}', which nothing before it provides`,\n });\n else if (!sameSchema(earlier, schema))\n violations.push({\n tag: 'UnsatisfiedInput',\n step: step.step,\n detail: `'${step.ref}' consumes '${key}' with a schema other than the one provided`,\n });\n }\n for (const [key, schema] of Object.entries(fragment.provides ?? {}))\n provided.set(key, schema);\n\n if (options.context !== undefined && fragment.requires !== undefined) {\n const missing = unmetRequirements(\n fragment.requires,\n withSegmentFacts(options.context, step.segment?.entitlements),\n );\n if (missing.length > 0)\n violations.push({\n tag: 'UnmetRequirement',\n step: step.step,\n detail: `'${step.ref}' requires ${missing.join(', ')}`,\n });\n }\n });\n\n return violations;\n};\n\nconst SlipViolationSchema = Schema.Struct({\n tag: Schema.String,\n step: Schema.optionalKey(Schema.String),\n detail: Schema.String,\n});\n\n/**\n * A flow that cannot be composed for this caller: the slip broke at least one\n * rule. Every violation travels with it.\n */\nexport class CompositionRefused extends Failure.declined<CompositionRefused>()(\n 'CompositionRefused',\n 'flowNotComposable',\n { violations: Schema.Array(SlipViolationSchema) },\n {\n message: ({ violations }) =>\n `the flow cannot be composed: ${violations.map(v => v.tag).join(', ')}`,\n },\n) {}\n\n/**\n * A flow this caller is not offered: every rule the slip broke is a step's\n * requirement — an entitlement, a role, a party role or a channel — that the\n * verified context lacks. The recipe is sound; the caller may not run it, so\n * it is `forbidden` rather than a slip that could not be built.\n */\nexport class FlowRequirementsUnmet extends Failure.forbidden<FlowRequirementsUnmet>()(\n 'FlowRequirementsUnmet',\n 'flowRequirementsUnmet',\n { violations: Schema.Array(SlipViolationSchema) },\n {\n message: ({ violations }) =>\n `the flow is not offered to this caller: ${violations.map(v => v.detail).join('; ')}`,\n },\n) {}\n\n/** Every violation is a requirement the caller lacks, and there is one. */\nexport const onlyUnmetRequirements = (\n violations: readonly SlipViolation[],\n): boolean =>\n violations.length > 0 &&\n violations.every(violation => violation.tag === 'UnmetRequirement');\n\n/**\n * Validates a slip, failing on any violation: with {@link FlowRequirementsUnmet}\n * when the caller lacks only what steps require, and otherwise with\n * {@link CompositionRefused}, which carries every violation.\n */\nexport const assertValidSlip = (\n slip: Slip,\n catalog: FragmentCatalog,\n options: ValidateSlipOptions = {},\n): Effect.Effect<Slip, CompositionRefused | FlowRequirementsUnmet> => {\n const violations = validateSlip(slip, catalog, options);\n if (violations.length === 0) return Effect.succeed(slip);\n return Effect.fail(\n onlyUnmetRequirements(violations)\n ? new FlowRequirementsUnmet({ violations })\n : new CompositionRefused({ violations }),\n );\n};\n"],"names":["Failure","Effect","Schema","jsonSchemaOf","slipSteps","timeoutOutcomeOf","step","onTimeout","parameters","outcome","undefined","sameSchema","a","b","JSON","stringify","unmetRequirements","requires","facts","missing","entitlement","entitlements","includes","push","role","roles","partyRoles","partyRole","join","channels","channel","withSegmentFacts","validateSlip","slip","catalog","options","violations","resolved","fragment","get","ref","tag","detail","pivots","filter","kind","length","String","map","commitAt","findIndex","hasRetriable","some","requiresCommitPoint","provided","Map","Object","entries","start","waits","forEach","index","beforeCommit","afterCommit","irreversible","guard","answers","wait","outcomes","set","values","excludedFrom","value","segment","key","schema","consumes","earlier","provides","context","SlipViolationSchema","Struct","optionalKey","CompositionRefused","declined","Array","message","v","FlowRequirementsUnmet","forbidden","onlyUnmetRequirements","every","violation","assertValidSlip","succeed","fail"],"mappings":";AAAA,SAASA,OAAO,QAAQ,gBAAgB;AACxC,SAASC,MAAM,EAAEC,MAAM,QAAQ,SAAS;AAGxC,SAIEC,YAAY,QACP,gBAAgB;AACvB,SAAmCC,SAAS,QAAQ,YAAY;AAqBhE,wFAAwF,GACxF,MAAMC,mBAAmB,CAACC;QACNA;IAAlB,MAAMC,aAAYD,mBAAAA,KAAKE,UAAU,qBAAfF,gBAAiB,CAAC,YAAY;IAChD,MAAMG,UACJ,OAAOF,cAAc,YAAYA,cAAc,OAC3C,AAACA,UAA6CE,OAAO,GACrDC;IACN,OAAO,OAAOD,YAAY,WAAW;QAACA;KAAQ,GAAG,EAAE;AACrD;AAiBA,MAAME,aAAa,CACjBC,GACAC,IAEAD,MAAMC,KACNC,KAAKC,SAAS,CAACZ,aAAaS,QAAQE,KAAKC,SAAS,CAACZ,aAAaU;AAElE,6EAA6E,GAC7E,OAAO,MAAMG,oBAAoB,CAC/BC,UACAC;QAG0BD,wBAClBC,qBAEWD,iBACXC,cAGwBA,kBAKFA;IAb9B,MAAMC,UAAoB,EAAE;IAC5B,KAAK,MAAMC,gBAAeH,yBAAAA,SAASI,YAAY,YAArBJ,yBAAyB,EAAE,CACnD,IAAI,CAAC,EAACC,sBAAAA,MAAMG,YAAY,YAAlBH,sBAAsB,EAAE,EAAEI,QAAQ,CAACF,cACvCD,QAAQI,IAAI,CAAC,CAAC,aAAa,EAAEH,YAAY,CAAC,CAAC;IAC/C,KAAK,MAAMI,SAAQP,kBAAAA,SAASQ,KAAK,YAAdR,kBAAkB,EAAE,CACrC,IAAI,CAAC,EAACC,eAAAA,MAAMO,KAAK,YAAXP,eAAe,EAAE,EAAEI,QAAQ,CAACE,OAAOL,QAAQI,IAAI,CAAC,CAAC,MAAM,EAAEC,KAA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AAA,YAAaA,UAAUnD,GAAG,KAAK,oBAAoB;AAEtE;;;;CAIC,GACD,OAAO,MAAMoD,kBAAkB,CAC7B5D,MACAC,SACAC,UAA+B,CAAC,CAAC;IAEjC,MAAMC,aAAaJ,aAAaC,MAAMC,SAASC;IAC/C,IAAIC,WAAWU,MAAM,KAAK,GAAG,OAAO7C,OAAO6F,OAAO,CAAC7D;IACnD,OAAOhC,OAAO8F,IAAI,CAChBL,sBAAsBtD,cAClB,IAAIoD,sBAAsB;QAAEpD;IAAW,KACvC,IAAI+C,mBAAmB;QAAE/C;IAAW;AAE5C,EAAE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@entifix/business",
3
- "version": "0.14.0",
3
+ "version": "0.16.0",
4
4
  "description": "The ports every adapter implements — repository, session, token, health — and the generic get, load, save and delete use-cases.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -66,7 +66,7 @@
66
66
  },
67
67
  "dependencies": {
68
68
  "@swc/helpers": "0.5.23",
69
- "@entifix/core": "0.14.0"
69
+ "@entifix/core": "0.16.0"
70
70
  },
71
71
  "peerDependencies": {
72
72
  "effect": "^4.0.7"