@entifix/business 0.15.0 → 0.17.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.
- package/dist/compose/compose.d.ts +14 -0
- package/dist/compose/compose.d.ts.map +1 -1
- package/dist/compose/compose.js +21 -5
- package/dist/compose/compose.js.map +1 -1
- package/dist/flow/catalog.d.ts +6 -5
- package/dist/flow/catalog.d.ts.map +1 -1
- package/dist/flow/catalog.js +4 -1
- package/dist/flow/catalog.js.map +1 -1
- package/dist/flow/fragment.d.ts +6 -0
- package/dist/flow/fragment.d.ts.map +1 -1
- package/dist/flow/fragment.js +8 -1
- package/dist/flow/fragment.js.map +1 -1
- package/dist/flow/slip.d.ts +39 -2
- package/dist/flow/slip.d.ts.map +1 -1
- package/dist/flow/slip.js +25 -3
- package/dist/flow/slip.js.map +1 -1
- package/dist/flow/validate.d.ts +1 -1
- package/dist/flow/validate.d.ts.map +1 -1
- package/dist/flow/validate.js +27 -1
- package/dist/flow/validate.js.map +1 -1
- package/package.json +2 -2
|
@@ -17,12 +17,24 @@ export interface RecipeLine {
|
|
|
17
17
|
readonly key: string;
|
|
18
18
|
readonly parameters: Readonly<Record<string, unknown>>;
|
|
19
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
|
+
}
|
|
20
30
|
/** One step of a recipe: a fragment by its pinned reference, as a string. */
|
|
21
31
|
export interface RecipeStep<I> {
|
|
22
32
|
readonly ref: string;
|
|
23
33
|
/** The step's name in the slip; defaults to the fragment id. */
|
|
24
34
|
readonly step?: string;
|
|
25
35
|
readonly when?: RecipeGate<I>;
|
|
36
|
+
/** Runs only on these answers of an earlier wait; overrides its stage's. */
|
|
37
|
+
readonly on?: RecipeGuard;
|
|
26
38
|
/**
|
|
27
39
|
* Parameters pinned at composition: from the context's config, from the
|
|
28
40
|
* decoded start input, and from the segment and line the step was expanded
|
|
@@ -39,6 +51,8 @@ export interface RecipeStep<I> {
|
|
|
39
51
|
export interface RecipeStage<I> {
|
|
40
52
|
readonly name: string;
|
|
41
53
|
readonly when?: RecipeGate<I>;
|
|
54
|
+
/** A guard every step of the stage carries unless it names its own. */
|
|
55
|
+
readonly on?: RecipeGuard;
|
|
42
56
|
readonly perSegment?: boolean;
|
|
43
57
|
readonly steps: readonly RecipeStep<I>[];
|
|
44
58
|
}
|
|
@@ -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,MAAM,EAAE,MAAM,QAAQ,CAAC;AAExC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EACL,KAAK,IAAI,EAET,KAAK,iBAAiB,EAEtB,KAAK,WAAW,EAGjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAE1B,KAAK,aAAa,EAEnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAEL,KAAK,cAAc,EACnB,YAAY,EACb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEtE,gFAAgF;AAChF,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAC1B,OAAO,EAAE,eAAe,EACxB,KAAK,EAAE,CAAC,EACR,OAAO,CAAC,EA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SAAS,aAAa,EAAE,CAAC;CAC/C;AAOD;;;;;;;;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"}
|
package/dist/compose/compose.js
CHANGED
|
@@ -8,7 +8,7 @@ const segmentKey = (segment)=>[
|
|
|
8
8
|
segment.vendor,
|
|
9
9
|
segment.paymentMethod
|
|
10
10
|
].filter(Boolean).join('/');
|
|
11
|
-
const buildStep = (recipeStep, catalog, context, input, segment, line)=>{
|
|
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;
|
|
@@ -41,12 +41,28 @@ const buildStep = (recipeStep, catalog, context, input, segment, line)=>{
|
|
|
41
41
|
compensation: fragment.compensation
|
|
42
42
|
}, parameters === undefined ? {} : {
|
|
43
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
|
+
}
|
|
44
58
|
});
|
|
45
59
|
};
|
|
46
|
-
/** One step per line for a `perLine` fragment when the recipe names lines. */ const expand = (recipe, recipeStep, catalog, context, input, segment)=>{
|
|
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;
|
|
47
62
|
var _catalog_get;
|
|
48
|
-
|
|
49
|
-
|
|
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)
|
|
50
66
|
];
|
|
51
67
|
};
|
|
52
68
|
const resolutionOf = (resolutions, context)=>Effect.forEach(resolutions, ({ useCase, rules })=>{
|
|
@@ -74,7 +90,7 @@ const resolutionOf = (resolutions, context)=>Effect.forEach(resolutions, ({ useC
|
|
|
74
90
|
steps: each.flatMap((segment)=>stage.steps.filter((recipeStep)=>{
|
|
75
91
|
var _ref;
|
|
76
92
|
return (_ref = recipeStep.when == null ? void 0 : recipeStep.when.call(recipeStep, context, input, segment)) != null ? _ref : true;
|
|
77
|
-
}).flatMap((recipeStep)=>expand(recipe, recipeStep, catalog, context, input, segment)))
|
|
93
|
+
}).flatMap((recipeStep)=>expand(recipe, recipeStep, catalog, context, input, segment, stage.on)))
|
|
78
94
|
};
|
|
79
95
|
}).filter((stage)=>stage.steps.length > 0);
|
|
80
96
|
return _extends({
|
|
@@ -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 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/** 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 /**\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 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): 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 };\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): readonly SlipStep[] =>\n 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),\n )\n : [buildStep(recipeStep, catalog, context, input, segment, undefined)];\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(recipe, recipeStep, catalog, context, input, 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 ...(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","fragment","get","ref","name","step","id","own","parameters","undefined","prefix","key","cardinality","participant","call","compensation","expand","recipe","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","outcomes","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;AAmG/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;QAGaJ,MAAAA;IADb,MAAMK,WAAWJ,QAAQK,GA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AM,EAAE,sCAAsC,CAAC,GAC/DyC,QACG/D,GAAG,CACF0D,CAAAA,UACE,CAAC,EAAE,EAAEA,QAAQ/E,OAAO,CAAC,GAAG,EAAE+E,QAAQ9E,KAAK,CAAC,EAAE,CAAC,GAC3C8E,QAAQC,UAAU,CACf3D,GAAG,CAACkE,CAAAA,YAAa,GAAGA,UAAUC,GAAG,CAAC,EAAE,EAAED,UAAU9B,MAAM,CAAC,CAAC,CAAC,EACzD7D,IAAI,CAAC,OAEXA,IAAI,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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AWrC,MAAM,KAAK,IACjB,aACD9D,sBAAsBmG,cACnB,UACA;gBACTA;YACF;QACF,IACA;AAEJ;;;;CAIC,GACD,OAAO,MAAME,6BAA6B,CACxCnE;IAEA,MAAMoE,UAAUpE,SAAS1B,MAAM,CAAC0F,CAAAA,UAAWA,QAAQA,OAAO,KAAK;IAC/D,IAAII,QAAQxC,MAAM,GAAG,GACnB,MAAM,IAAIyC,MACR,GAAGC,OAAOF,QAAQxC,MAAM,EAAE,sCAAsC,CAAC,GAC/DwC,QACG9D,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"}
|
package/dist/flow/catalog.d.ts
CHANGED
|
@@ -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
|
|
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"}
|
package/dist/flow/catalog.js
CHANGED
|
@@ -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: {
|
package/dist/flow/catalog.js.map
CHANGED
|
@@ -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;QACtBO;QACAX,WAAWW,KAAKG,GAAG,CAACV,CAAAA,MAAOH,MAAMK,GAAG,CAACF;IACvC;AACF,EAAE;AAEF;;;;;CAKC,GACD,OAAO,MAAMW,kBAAkB,CAACC,UAA8B,CAAA;QAC5DhB,WAAWgB,QAAQhB,SAAS,CAACc,GAAG,CAACX,CAAAA;gBAcrBA,oBACIA,wBACHA,qBACDA,oBACIA;mBAlB8B;gBAC5CC,KAAKR,YAAYO;gBACjBc,IAAId,SAASc,EAAE;gBACfC,SAASf,SAASe,OAAO;gBACzBT,QAAQN,SAASM,MAAM;gBACvBU,MAAMhB,SAASgB,IAAI;gBACnBC,aAAajB,SAASiB,WAAW;eAC7BjB,SAASkB,WAAW,KAAKd,YACzB,CAAC,IACD;gBAAEc,aAAalB,SAASkB,WAAW;YAAC,GACpClB,SAASmB,IAAI,KAAKf,YAAY,CAAC,IAAI;gBAAEe,MAAMnB,SAASmB,IAAI;YAAC,GACzDnB,SAASoB,YAAY,KAAKhB,YAC1B,CAAC,IACD;gBAAEgB,cAAcpB,SAASoB,YAAY;YAAC;gBAC1CC,QAAQ,GAAErB,qBAAAA,SAASqB,QAAQ,YAAjBrB,qBAAqB;gBAC/BsB,YAAY,GAAEtB,yBAAAA,SAASsB,YAAY,YAArBtB,yBAAyB;gBACvCuB,SAAS,GAAEvB,sBAAAA,SAASuB,SAAS,YAAlBvB,sBAAsB;gBACjCwB,QAAQ,GAAExB,qBAAAA,SAASwB,QAAQ,YAAjBxB,qBAAqB,CAAC;gBAChCyB,YAAY,GAAEzB,yBAAAA,SAASyB,YAAY,YAArBzB,yBAAyB,CAAC;
|
|
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,CA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yB,YAAY,YAArBzB,yBAAyB,CAAC;eACpCA,SAAS0B,QAAQ,KAAKtB,YAAY,CAAC,IAAI;gBAAEsB,UAAU1B,SAAS0B,QAAQ;YAAC;gBACzEC,UAAUhC,aAAaK,SAAS2B,QAAQ;gBACxCC,UAAUjC,aAAaK,SAAS4B,QAAQ;gBACxCC,UAAU;oBACRC,OAAOpC,aAAaM,SAAS6B,QAAQ,CAACC,KAAK;oBAC3CC,QAAQrC,aAAaM,SAAS6B,QAAQ,CAACE,MAAM;oBAC7CC,SAAStC,aAAaM,SAAS6B,QAAQ,CAACG,OAAO;gBACjD;gBACAC,aAAazC,oBAAoBQ;;;IAErC,CAAA,EAAG"}
|
package/dist/flow/fragment.d.ts
CHANGED
|
@@ -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,CAA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;;;;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"}
|
package/dist/flow/fragment.js
CHANGED
|
@@ -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,CAAC;AAE3D,uDAAuD,GACvD,MAAMC,cAAc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L3C,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,KAAK,QAAQlB,SAASe,IAAI,KAAK,i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AI,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"}
|
package/dist/flow/slip.d.ts
CHANGED
|
@@ -5,7 +5,17 @@ import { Effect, Schema } from 'effect';
|
|
|
5
5
|
* flow that started under one grammar finishes under that grammar even after
|
|
6
6
|
* the next one ships.
|
|
7
7
|
*/
|
|
8
|
-
export declare const SLIP_VERSION:
|
|
8
|
+
export declare const SLIP_VERSION: 2;
|
|
9
|
+
/**
|
|
10
|
+
* Every grammar version a stored slip may be written in. A flow started under
|
|
11
|
+
* an earlier one still decodes and finishes under it.
|
|
12
|
+
*
|
|
13
|
+
* - `1` — the walk as first shipped.
|
|
14
|
+
* - `2` — the same walk, and a wait past the commit point announces
|
|
15
|
+
* `flow.waiting`: the caller's write has landed and what is left is someone
|
|
16
|
+
* else's, so a browser holding the write pending can let it go.
|
|
17
|
+
*/
|
|
18
|
+
export declare const SLIP_VERSIONS: readonly [1, 2];
|
|
9
19
|
/**
|
|
10
20
|
* Tags that place a step in a segment of the flow: whose lines, which payment.
|
|
11
21
|
* `entitlements` are the facts verified for the party the segment acts for —
|
|
@@ -18,6 +28,18 @@ export declare const SlipSegment: Schema.Struct<{
|
|
|
18
28
|
readonly entitlements: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
19
29
|
}>;
|
|
20
30
|
export type SlipSegment = typeof SlipSegment.Type;
|
|
31
|
+
/**
|
|
32
|
+
* A step that runs only when an earlier wait was answered with one of
|
|
33
|
+
* `outcomes` — the one branch a slip can take, decided by what the wait was
|
|
34
|
+
* told rather than by anything known at composition. A step guarded on a wait
|
|
35
|
+
* that was itself skipped is skipped too.
|
|
36
|
+
*/
|
|
37
|
+
export declare const SlipGuard: Schema.Struct<{
|
|
38
|
+
/** The step name of the wait, earlier in the slip. */
|
|
39
|
+
readonly wait: Schema.String;
|
|
40
|
+
readonly outcomes: Schema.$Array<Schema.String>;
|
|
41
|
+
}>;
|
|
42
|
+
export type SlipGuard = typeof SlipGuard.Type;
|
|
21
43
|
/** One pinned step: a fragment reference and everything resolved for it. */
|
|
22
44
|
export declare const SlipStep: Schema.Struct<{
|
|
23
45
|
/** `id@version`, pinned when the slip was composed. */
|
|
@@ -43,6 +65,11 @@ export declare const SlipStep: Schema.Struct<{
|
|
|
43
65
|
}>>;
|
|
44
66
|
/** Configuration pinned at composition — a hold's expiry, a limit. */
|
|
45
67
|
readonly parameters: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
68
|
+
readonly guard: Schema.optionalKey<Schema.Struct<{
|
|
69
|
+
/** The step name of the wait, earlier in the slip. */
|
|
70
|
+
readonly wait: Schema.String;
|
|
71
|
+
readonly outcomes: Schema.$Array<Schema.String>;
|
|
72
|
+
}>>;
|
|
46
73
|
}>;
|
|
47
74
|
export type SlipStep = typeof SlipStep.Type;
|
|
48
75
|
export declare const SlipStage: Schema.Struct<{
|
|
@@ -71,6 +98,11 @@ export declare const SlipStage: Schema.Struct<{
|
|
|
71
98
|
}>>;
|
|
72
99
|
/** Configuration pinned at composition — a hold's expiry, a limit. */
|
|
73
100
|
readonly parameters: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
101
|
+
readonly guard: Schema.optionalKey<Schema.Struct<{
|
|
102
|
+
/** The step name of the wait, earlier in the slip. */
|
|
103
|
+
readonly wait: Schema.String;
|
|
104
|
+
readonly outcomes: Schema.$Array<Schema.String>;
|
|
105
|
+
}>>;
|
|
74
106
|
}>>;
|
|
75
107
|
}>;
|
|
76
108
|
export type SlipStage = typeof SlipStage.Type;
|
|
@@ -94,7 +126,7 @@ export type SlipResolution = typeof SlipResolution.Type;
|
|
|
94
126
|
* flow that has already started.
|
|
95
127
|
*/
|
|
96
128
|
export declare const Slip: Schema.Struct<{
|
|
97
|
-
readonly slipVersion: Schema.
|
|
129
|
+
readonly slipVersion: Schema.Literals<readonly [1, 2]>;
|
|
98
130
|
readonly flowId: Schema.String;
|
|
99
131
|
readonly recipe: Schema.String;
|
|
100
132
|
/** The recipe demands a commit point even with no retriable step (a checkout). */
|
|
@@ -125,6 +157,11 @@ export declare const Slip: Schema.Struct<{
|
|
|
125
157
|
}>>;
|
|
126
158
|
/** Configuration pinned at composition — a hold's expiry, a limit. */
|
|
127
159
|
readonly parameters: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
160
|
+
readonly guard: Schema.optionalKey<Schema.Struct<{
|
|
161
|
+
/** The step name of the wait, earlier in the slip. */
|
|
162
|
+
readonly wait: Schema.String;
|
|
163
|
+
readonly outcomes: Schema.$Array<Schema.String>;
|
|
164
|
+
}>>;
|
|
128
165
|
}>>;
|
|
129
166
|
}>>;
|
|
130
167
|
readonly resolution: Schema.$Array<Schema.Struct<{
|
package/dist/flow/slip.d.ts.map
CHANGED
|
@@ -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;
|
|
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;AAEvC;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,iBAA6B,CAAC;AAOxD;;;;;GAKG;AACH,eAAO,MAAM,WAAW;;;;EAItB,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC,IAAI,CAAC;AAElD;;;;;GAKG;AACH,eAAO,MAAM,SAAS;IACpB,sDAAsD;;;EAGtD,CAAC;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,IAAI,CAAC;AAE9C,4EAA4E;AAC5E,eAAO,MAAM,QAAQ;IACnB,uDAAuD;;IAEvD,gFAAgF;;;;;;;;IAIhF,uEAAuE;;;;;;;;;;;IAKvE,sEAAsE;;;QAnBtE,sDAAsD;;;;EAsBtD,CAAC;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,IAAI,CAAC;AAE5C,eAAO,MAAM,SAAS;;;QAjBpB,uDAAuD;;QAEvD,gFAAgF;;;;;;;;QAIhF,uEAAuE;;;;;;;;;;;QAKvE,sEAAsE;;;YAnBtE,sDAAsD;;;;;EA4BtD,CAAC;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,IAAI,CAAC;AAE9C,yEAAyE;AACzE,eAAO,MAAM,iBAAiB;;;;EAI5B,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,iBAAiB,CAAC,IAAI,CAAC;AAE9D,kEAAkE;AAClE,eAAO,MAAM,cAAc;;;;EAIzB,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,cAAc,CAAC,IAAI,CAAC;AAExD;;;;GAIG;AACH,eAAO,MAAM,IAAI;;;;IAIf,kFAAkF;;;;;YAhDlF,uDAAuD;;YAEvD,gFAAgF;;;;;;;;YAIhF,uEAAuE;;;;;;;;;;;YAKvE,sEAAsE;;;gBAnBtE,sDAAsD;;;;;;;;;;;;IA6DtD;;;OAGG;;;;;;EAEH,CAAC;AACH,MAAM,MAAM,IAAI,GAAG,OAAO,IAAI,CAAC,IAAI,CAAC;AAEpC;;;;GAIG;AACH,eAAO,MAAM,UAAU,GACrB,OAAO,OAAO,KACb,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,eAAe,CAQnC,CAAC;AAEJ,4DAA4D;AAC5D,eAAO,MAAM,UAAU,GAAI,MAAM,IAAI,KAAG,OACT,CAAC;AAEhC,kDAAkD;AAClD,eAAO,MAAM,SAAS,GAAI,MAAM,IAAI,KAAG,SAAS,QAAQ,EACb,CAAC"}
|
package/dist/flow/slip.js
CHANGED
|
@@ -4,7 +4,19 @@ import { Effect, Schema } from 'effect';
|
|
|
4
4
|
* The grammar version a slip is written in. An interpreter branches on it, so a
|
|
5
5
|
* flow that started under one grammar finishes under that grammar even after
|
|
6
6
|
* the next one ships.
|
|
7
|
-
*/ export const SLIP_VERSION =
|
|
7
|
+
*/ export const SLIP_VERSION = 2;
|
|
8
|
+
/**
|
|
9
|
+
* Every grammar version a stored slip may be written in. A flow started under
|
|
10
|
+
* an earlier one still decodes and finishes under it.
|
|
11
|
+
*
|
|
12
|
+
* - `1` — the walk as first shipped.
|
|
13
|
+
* - `2` — the same walk, and a wait past the commit point announces
|
|
14
|
+
* `flow.waiting`: the caller's write has landed and what is left is someone
|
|
15
|
+
* else's, so a browser holding the write pending can let it go.
|
|
16
|
+
*/ export const SLIP_VERSIONS = [
|
|
17
|
+
1,
|
|
18
|
+
SLIP_VERSION
|
|
19
|
+
];
|
|
8
20
|
const Call = Schema.Struct({
|
|
9
21
|
method: Schema.Literals([
|
|
10
22
|
'GET',
|
|
@@ -25,6 +37,15 @@ const Call = Schema.Struct({
|
|
|
25
37
|
paymentMethod: Schema.optionalKey(Schema.String),
|
|
26
38
|
entitlements: Schema.optionalKey(Schema.Array(Schema.String))
|
|
27
39
|
});
|
|
40
|
+
/**
|
|
41
|
+
* A step that runs only when an earlier wait was answered with one of
|
|
42
|
+
* `outcomes` — the one branch a slip can take, decided by what the wait was
|
|
43
|
+
* told rather than by anything known at composition. A step guarded on a wait
|
|
44
|
+
* that was itself skipped is skipped too.
|
|
45
|
+
*/ export const SlipGuard = Schema.Struct({
|
|
46
|
+
/** The step name of the wait, earlier in the slip. */ wait: Schema.String,
|
|
47
|
+
outcomes: Schema.Array(Schema.String)
|
|
48
|
+
});
|
|
28
49
|
/** One pinned step: a fragment reference and everything resolved for it. */ export const SlipStep = Schema.Struct({
|
|
29
50
|
/** `id@version`, pinned when the slip was composed. */ ref: Schema.String,
|
|
30
51
|
/** Unique within the slip; what an Activity is named after (`segment:step`). */ step: Schema.String,
|
|
@@ -38,7 +59,8 @@ const Call = Schema.Struct({
|
|
|
38
59
|
participant: Schema.optionalKey(Schema.String),
|
|
39
60
|
call: Schema.optionalKey(Call),
|
|
40
61
|
compensation: Schema.optionalKey(Call),
|
|
41
|
-
/** Configuration pinned at composition — a hold's expiry, a limit. */ parameters: Schema.optionalKey(Schema.Record(Schema.String, Schema.Unknown))
|
|
62
|
+
/** Configuration pinned at composition — a hold's expiry, a limit. */ parameters: Schema.optionalKey(Schema.Record(Schema.String, Schema.Unknown)),
|
|
63
|
+
guard: Schema.optionalKey(SlipGuard)
|
|
42
64
|
});
|
|
43
65
|
export const SlipStage = Schema.Struct({
|
|
44
66
|
name: Schema.String,
|
|
@@ -63,7 +85,7 @@ export const SlipStage = Schema.Struct({
|
|
|
63
85
|
* stored as the flow's payload. Changing a recipe or a fragment never changes a
|
|
64
86
|
* flow that has already started.
|
|
65
87
|
*/ export const Slip = Schema.Struct({
|
|
66
|
-
slipVersion: Schema.
|
|
88
|
+
slipVersion: Schema.Literals(SLIP_VERSIONS),
|
|
67
89
|
flowId: Schema.String,
|
|
68
90
|
recipe: Schema.String,
|
|
69
91
|
/** The recipe demands a commit point even with no retriable step (a checkout). */ requiresCommitPoint: Schema.optionalKey(Schema.Boolean),
|
package/dist/flow/slip.js.map
CHANGED
|
@@ -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/**\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/** 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});\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.
|
|
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 = 2 as const;\n\n/**\n * Every grammar version a stored slip may be written in. A flow started under\n * an earlier one still decodes and finishes under it.\n *\n * - `1` — the walk as first shipped.\n * - `2` — the same walk, and a wait past the commit point announces\n * `flow.waiting`: the caller's write has landed and what is left is someone\n * else's, so a browser holding the write pending can let it go.\n */\nexport const SLIP_VERSIONS = [1, SLIP_VERSION] 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.Literals(SLIP_VERSIONS),\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","SLIP_VERSIONS","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","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;;;;;;;;CAQC,GACD,OAAO,MAAMC,gBAAgB;IAAC;IAAGD;CAAa,CAAU;AAExD,MAAME,OAAOH,OAAOI,MAAM,CAAC;IACzBC,QAAQL,OAAOM,QAAQ,CAAC;QAAC;QAAO;QAAQ;QAAO;QAAS;KAAS;IACjEC,MAAMP,OAAOQ,MAAM;AACrB;AAEA;;;;;CAKC,GACD,OAAO,MAAMC,cAAcT,OAAOI,MAAM,CAAC;IACvCM,QAAQV,OAAOW,WAAW,CAACX,OAAOQ,MAAM;IACxCI,eAAeZ,OAAOW,WAAW,CAACX,OAAOQ,MAAM;IAC/CK,cAAcb,OAAOW,WAAW,CAACX,OAAOc,KAAK,CAACd,OAAOQ,MAAM;AAC7D,GAAG;AAGH;;;;;CAKC,GACD,OAAO,MAAMO,YAAYf,OAAOI,MAAM,CAAC;IACrC,oDAAoD,GACpDY,MAAMhB,OAAOQ,MAAM;IACnBS,UAAUjB,OAAOc,KAAK,CAACd,OAAOQ,MAAM;AACtC,GAAG;AAGH,0EAA0E,GAC1E,OAAO,MAAMU,WAAWlB,OAAOI,MAAM,CAAC;IACpC,qDAAqD,GACrDe,KAAKnB,OAAOQ,MAAM;I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,OAAO;IACtDC,QAAQjD,OAAOc,KAAK,CAACiB;IACrBmB,YAAYlD,OAAOc,KAAK,CAACwB;IACzBa,YAAYnD,OAAOQ,MAAM;IACzB;;;GAGC,GACD4C,UAAUpD,OAAOW,WAAW,CAACX,OAAOc,KAAK,CAACoB;AAC5C,GAAG;AAGH;;;;CAIC,GACD,OAAO,MAAMmB,aAAa,CACxBC,QAEAtD,OAAOuD,mBAAmB,CAACZ,MAAMW,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,CAACpB,MAAMmB,MAAM;AAEhC,gDAAgD,GAChD,OAAO,MAAME,YAAY,CAACF,OACxBA,KAAKb,MAAM,CAACgB,OAAO,CAACC,CAAAA,QAASA,MAAMjC,KAAK,EAAE"}
|
package/dist/flow/validate.d.ts
CHANGED
|
@@ -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,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAExC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,oBAAoB,EAE1B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,IAAI,EAA4B,MAAM,WAAW,CAAC;AAEhE,+CAA+C;AAC/C,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,GAAG,EACR,iBAAiB,GACjB,eAAe,GACf,oBAAoB,GACpB,uBAAuB,GACvB,0BAA0B,GAC1B,0BAA0B,GAC1B,kBAAkB,GAClB,qBAAqB,GACrB,kBAAkB,GAClB,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/flow/validate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAExC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,oBAAoB,EAE1B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,IAAI,EAA4B,MAAM,WAAW,CAAC;AAEhE,+CAA+C;AAC/C,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,GAAG,EACR,iBAAiB,GACjB,eAAe,GACf,oBAAoB,GACpB,uBAAuB,GACvB,0BAA0B,GAC1B,0BAA0B,GAC1B,kBAAkB,GAClB,qBAAqB,GACrB,kBAAkB,GAClB,kBAAkB,GAClB,cAAc,CAAC;IACnB,iDAAiD;IACjD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,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SchemaOf } from './fragment.js';
|
|
5
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
|
+
};
|
|
6
14
|
const sameSchema = (a, b)=>a === b || JSON.stringify(jsonSchemaOf(a)) === JSON.stringify(jsonSchemaOf(b));
|
|
7
15
|
/** The requirements `facts` do not meet, described; empty when all are met. */ export const unmetRequirements = (requires, facts)=>{
|
|
8
16
|
var _requires_entitlements, _facts_entitlements, _requires_roles, _facts_roles, _facts_partyRole, _facts_channel;
|
|
@@ -58,8 +66,9 @@ const sameSchema = (a, b)=>a === b || JSON.stringify(jsonSchemaOf(a)) === JSON.s
|
|
|
58
66
|
detail: 'the slip needs one commit point — a pivot, or flow.commit@1 — before its first retriable step'
|
|
59
67
|
});
|
|
60
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();
|
|
61
70
|
resolved.forEach(({ step, fragment }, index)=>{
|
|
62
|
-
var _fragment_excludedFrom, _fragment_consumes, _fragment_provides;
|
|
71
|
+
var _fragment_outcomes, _fragment_excludedFrom, _fragment_consumes, _fragment_provides;
|
|
63
72
|
const beforeCommit = commitAt === -1 || index < commitAt;
|
|
64
73
|
const afterCommit = commitAt !== -1 && index > commitAt;
|
|
65
74
|
if (fragment.kind === 'retriable' && commitAt !== -1 && index < commitAt) violations.push({
|
|
@@ -82,6 +91,23 @@ const sameSchema = (a, b)=>a === b || JSON.stringify(jsonSchemaOf(a)) === JSON.s
|
|
|
82
91
|
step: step.step,
|
|
83
92
|
detail: `'${step.ref}' waits before the commit point, holding uncommitted state for as long as it waits`
|
|
84
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
|
+
]);
|
|
85
111
|
for (const [tag, values] of Object.entries((_fragment_excludedFrom = fragment.excludedFrom) != null ? _fragment_excludedFrom : {})){
|
|
86
112
|
var _step_segment;
|
|
87
113
|
const value = (_step_segment = step.segment) == null ? void 0 : _step_segment[tag];
|
|
@@ -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 * 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\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(\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","sameSchema","a","b","JSON","stringify","unmetRequirements","requires","facts","missing","entitlement","entitlements","includes","push","role","roles","partyRoles","undefined","partyRole","join","channels","channel","withSegmentFacts","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","onlyUnmet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;CAIC,GACD,OAAO,MAAM+C,kBAAkB,CAC7BxD,MACAC,SACAC,UAA+B,CAAC,CAAC;IAEjC,MAAMC,aAAaJ,aAAaC,MAAMC,SAASC;IAC/C,IAAIC,WAAWW,MAAM,KAAK,GAAG,OAAOzC,OAAOoF,OAAO,CAACzD;IACnD,OAAO3B,OAAOqF,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,EA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AACC;AAEH,yEAAyE,GACzE,OAAO,MAAM8D,wBAAwB,CACnCtD,aAEAA,WAAWU,MAAM,GAAG,KACpBV,WAAWuD,KAAK,CAACC,CAAAA,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.
|
|
3
|
+
"version": "0.17.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.
|
|
69
|
+
"@entifix/core": "0.17.0"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
72
|
"effect": "^4.0.7"
|