@entifix/business 0.13.0 → 0.15.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 +29 -3
- package/dist/compose/compose.d.ts.map +1 -1
- package/dist/compose/compose.js +26 -4
- package/dist/compose/compose.js.map +1 -1
- package/dist/entity-api/entity-api.d.ts +2 -0
- package/dist/entity-api/entity-api.d.ts.map +1 -1
- package/dist/entity-api/entity-api.js.map +1 -1
- package/dist/flow/slip.d.ts +17 -1
- package/dist/flow/slip.d.ts.map +1 -1
- package/dist/flow/slip.js +9 -2
- package/dist/flow/slip.js.map +1 -1
- package/dist/flow/validate.d.ts.map +1 -1
- package/dist/flow/validate.js +16 -1
- package/dist/flow/validate.js.map +1 -1
- package/dist/repository/entity-link-resolver.repository.d.ts.map +1 -1
- package/dist/repository/entity-link-resolver.repository.js.map +1 -1
- package/dist/repository/entity.repository.d.ts +2 -2
- package/dist/repository/entity.repository.d.ts.map +1 -1
- package/dist/repository/entity.repository.js.map +1 -1
- package/dist/use-case/delete/delete.uc.d.ts +1 -1
- package/dist/use-case/delete/delete.uc.d.ts.map +1 -1
- package/dist/use-case/facets/facet-counts.uc.d.ts +1 -1
- package/dist/use-case/facets/facet-counts.uc.d.ts.map +1 -1
- package/dist/use-case/get/get.uc.d.ts +1 -1
- package/dist/use-case/get/get.uc.d.ts.map +1 -1
- package/dist/use-case/load/load-all.uc.d.ts +1 -1
- package/dist/use-case/load/load-all.uc.d.ts.map +1 -1
- package/dist/use-case/load/load.uc.d.ts +1 -1
- package/dist/use-case/load/load.uc.d.ts.map +1 -1
- package/dist/use-case/load/resolve-links.uc.d.ts +2 -2
- package/dist/use-case/load/resolve-links.uc.d.ts.map +1 -1
- package/dist/use-case/load/resolve-links.uc.js.map +1 -1
- package/dist/use-case/save/save.uc.d.ts +1 -1
- package/dist/use-case/save/save.uc.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -2,20 +2,34 @@ import { Invalid } from '@entifix/core';
|
|
|
2
2
|
import { Effect, Schema } from 'effect';
|
|
3
3
|
import type { FragmentCatalog } from '../flow/catalog.js';
|
|
4
4
|
import type { FragmentKeys } from '../flow/fragment.js';
|
|
5
|
-
import { type Slip, type SlipSegment } from '../flow/slip.js';
|
|
5
|
+
import { type Slip, type SlipAudienceEntry, type SlipSegment } from '../flow/slip.js';
|
|
6
6
|
import { type CompositionRefused, type FlowRequirementsUnmet, type SlipViolation } from '../flow/validate.js';
|
|
7
7
|
import { type ResolutionRule, Unresolvable } from '../resolve/resolve.js';
|
|
8
8
|
import type { VerifiedContext } from '../resolve/verified-context.js';
|
|
9
9
|
/** A gate over what is known when the flow starts. Never over anything else. */
|
|
10
10
|
export type RecipeGate<I> = (context: VerifiedContext, input: I, segment?: SlipSegment) => boolean;
|
|
11
|
+
/**
|
|
12
|
+
* One line of a segment — an item in a vendor's part of a basket — that a
|
|
13
|
+
* `perLine` step is expanded for. Its `key` names the step (`segment:line:step`)
|
|
14
|
+
* and its parameters are pinned on that step beneath the recipe step's own.
|
|
15
|
+
*/
|
|
16
|
+
export interface RecipeLine {
|
|
17
|
+
readonly key: string;
|
|
18
|
+
readonly parameters: Readonly<Record<string, unknown>>;
|
|
19
|
+
}
|
|
11
20
|
/** One step of a recipe: a fragment by its pinned reference, as a string. */
|
|
12
21
|
export interface RecipeStep<I> {
|
|
13
22
|
readonly ref: string;
|
|
14
23
|
/** The step's name in the slip; defaults to the fragment id. */
|
|
15
24
|
readonly step?: string;
|
|
16
25
|
readonly when?: RecipeGate<I>;
|
|
17
|
-
/**
|
|
18
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Parameters pinned at composition: from the context's config, from the
|
|
28
|
+
* decoded start input, and from the segment and line the step was expanded
|
|
29
|
+
* for. What a participant is told travels here and nowhere else, so a slip
|
|
30
|
+
* read back says exactly what each call was given.
|
|
31
|
+
*/
|
|
32
|
+
readonly parameters?: (context: VerifiedContext, input: I, segment?: SlipSegment, line?: RecipeLine) => Readonly<Record<string, unknown>>;
|
|
19
33
|
}
|
|
20
34
|
/**
|
|
21
35
|
* One stage of a recipe. A `perSegment` stage is expanded once per segment the
|
|
@@ -48,6 +62,18 @@ export interface Recipe<I> {
|
|
|
48
62
|
readonly requiresCommitPoint?: boolean;
|
|
49
63
|
/** The segments a `perSegment` stage expands over. */
|
|
50
64
|
readonly segments?: (input: I) => readonly SlipSegment[];
|
|
65
|
+
/**
|
|
66
|
+
* The lines a `perLine` step expands over — in its segment when it has one,
|
|
67
|
+
* else across the flow. A `perLine` step in a recipe with no lines is one
|
|
68
|
+
* step, as before.
|
|
69
|
+
*/
|
|
70
|
+
readonly lines?: (input: I, segment?: SlipSegment) => readonly RecipeLine[];
|
|
71
|
+
/**
|
|
72
|
+
* Who the flow's events reach beside the flow itself: the organizations and
|
|
73
|
+
* parties it acts for, and a flow entry with the digest of a capability an
|
|
74
|
+
* anonymous caller holds. Pinned on the slip at composition.
|
|
75
|
+
*/
|
|
76
|
+
readonly audience?: (input: I, context: VerifiedContext, flowId: string) => readonly SlipAudienceEntry[];
|
|
51
77
|
readonly resolve?: readonly RecipeResolution[];
|
|
52
78
|
readonly stages: readonly RecipeStage<I>[];
|
|
53
79
|
}
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../../src/compose/compose.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,OAAO,EAAE,MAAM,eA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AAM,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,17 +8,31 @@ const segmentKey = (segment)=>[
|
|
|
8
8
|
segment.vendor,
|
|
9
9
|
segment.paymentMethod
|
|
10
10
|
].filter(Boolean).join('/');
|
|
11
|
-
const buildStep = (recipeStep, catalog, context, segment)=>{
|
|
11
|
+
const buildStep = (recipeStep, catalog, context, input, segment, line)=>{
|
|
12
12
|
var _ref, _recipeStep_step, _ref1;
|
|
13
13
|
const fragment = catalog.get(recipeStep.ref);
|
|
14
14
|
const name = (_ref = (_recipeStep_step = recipeStep.step) != null ? _recipeStep_step : fragment == null ? void 0 : fragment.id) != null ? _ref : recipeStep.ref;
|
|
15
|
-
const
|
|
15
|
+
const own = recipeStep.parameters == null ? void 0 : recipeStep.parameters.call(recipeStep, context, input, segment, line);
|
|
16
|
+
const parameters = line === undefined ? own : _extends({}, line.parameters, own != null ? own : {});
|
|
17
|
+
const prefix = [
|
|
18
|
+
...segment === undefined ? [] : [
|
|
19
|
+
segmentKey(segment)
|
|
20
|
+
],
|
|
21
|
+
...line === undefined ? [] : [
|
|
22
|
+
line.key
|
|
23
|
+
]
|
|
24
|
+
];
|
|
16
25
|
return _extends({
|
|
17
26
|
ref: recipeStep.ref,
|
|
18
|
-
step:
|
|
27
|
+
step: [
|
|
28
|
+
...prefix,
|
|
29
|
+
name
|
|
30
|
+
].join(':'),
|
|
19
31
|
cardinality: (_ref1 = fragment == null ? void 0 : fragment.cardinality) != null ? _ref1 : 'one'
|
|
20
32
|
}, segment === undefined ? {} : {
|
|
21
33
|
segment
|
|
34
|
+
}, line === undefined ? {} : {
|
|
35
|
+
line: line.key
|
|
22
36
|
}, (fragment == null ? void 0 : fragment.participant) === undefined ? {} : {
|
|
23
37
|
participant: fragment.participant
|
|
24
38
|
}, (fragment == null ? void 0 : fragment.call) === undefined ? {} : {
|
|
@@ -29,6 +43,12 @@ const buildStep = (recipeStep, catalog, context, segment)=>{
|
|
|
29
43
|
parameters
|
|
30
44
|
});
|
|
31
45
|
};
|
|
46
|
+
/** One step per line for a `perLine` fragment when the recipe names lines. */ const expand = (recipe, recipeStep, catalog, context, input, segment)=>{
|
|
47
|
+
var _catalog_get;
|
|
48
|
+
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)) : [
|
|
49
|
+
buildStep(recipeStep, catalog, context, input, segment, undefined)
|
|
50
|
+
];
|
|
51
|
+
};
|
|
32
52
|
const resolutionOf = (resolutions, context)=>Effect.forEach(resolutions, ({ useCase, rules })=>{
|
|
33
53
|
const chosen = dryRun(rules, context);
|
|
34
54
|
return chosen === undefined ? Effect.fail(new Unresolvable({
|
|
@@ -54,7 +74,7 @@ const resolutionOf = (resolutions, context)=>Effect.forEach(resolutions, ({ useC
|
|
|
54
74
|
steps: each.flatMap((segment)=>stage.steps.filter((recipeStep)=>{
|
|
55
75
|
var _ref;
|
|
56
76
|
return (_ref = recipeStep.when == null ? void 0 : recipeStep.when.call(recipeStep, context, input, segment)) != null ? _ref : true;
|
|
57
|
-
}).
|
|
77
|
+
}).flatMap((recipeStep)=>expand(recipe, recipeStep, catalog, context, input, segment)))
|
|
58
78
|
};
|
|
59
79
|
}).filter((stage)=>stage.steps.length > 0);
|
|
60
80
|
return _extends({
|
|
@@ -67,6 +87,8 @@ const resolutionOf = (resolutions, context)=>Effect.forEach(resolutions, ({ useC
|
|
|
67
87
|
stages,
|
|
68
88
|
resolution,
|
|
69
89
|
composedAt: options.composedAt
|
|
90
|
+
}, recipe.audience === undefined ? {} : {
|
|
91
|
+
audience: recipe.audience(input, context, options.flowId)
|
|
70
92
|
});
|
|
71
93
|
};
|
|
72
94
|
const decodeInput = (recipe, input)=>Schema.decodeUnknownEffect(recipe.input)(input).pipe(Effect.mapError((error)=>new Invalid({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/compose/compose.ts"],"sourcesContent":["import { FieldProblem, Invalid } from '@entifix/core';\nimport { Effect, Schema } from 'effect';\n\nimport type { FragmentCatalog } from '../flow/catalog.js';\nimport type { FragmentKeys } from '../flow/fragment.js';\nimport {\n type Slip,\n SLIP_VERSION,\n type SlipResolution,\n type SlipSegment,\n type SlipStep,\n slipSteps,\n} from '../flow/slip.js';\nimport {\n assertValidSlip,\n type CompositionRefused,\n type FlowRequirementsUnmet,\n onlyUnmetRequirements,\n type SlipViolation,\n validateSlip,\n} from '../flow/validate.js';\nimport {\n dryRun,\n type ResolutionRule,\n Unresolvable,\n} from '../resolve/resolve.js';\nimport type { VerifiedContext } from '../resolve/verified-context.js';\n\n/** A gate over what is known when the flow starts. Never over anything else. */\nexport type RecipeGate<I> = (\n context: VerifiedContext,\n input: I,\n segment?: SlipSegment,\n) => boolean;\n\n/** One step of a recipe: a fragment by its pinned reference, as a string. */\nexport interface RecipeStep<I> {\n readonly ref: string;\n /** The step's name in the slip; defaults to the fragment id. */\n readonly step?: string;\n readonly when?: RecipeGate<I>;\n /** Parameters pinned at composition, read from the context's config. */\n readonly parameters?: (\n context: VerifiedContext,\n ) => Readonly<Record<string, unknown>>;\n}\n\n/**\n * One stage of a recipe. A `perSegment` stage is expanded once per segment the\n * start input names — one per vendor, say — each step tagged with its segment\n * and named `<segment key>:<step>`.\n */\nexport interface RecipeStage<I> {\n readonly name: string;\n readonly when?: RecipeGate<I>;\n readonly perSegment?: boolean;\n readonly steps: readonly RecipeStep<I>[];\n}\n\n/** A use case the recipe resolves, recorded on the slip as it was resolved. */\nexport interface RecipeResolution {\n readonly useCase: string;\n readonly rules: readonly ResolutionRule<unknown>[];\n}\n\n/**\n * A named template a slip is composed from. It references fragments by\n * `id@n` strings, never by import, so no domain imports another to take part in\n * a flow.\n */\nexport interface Recipe<I> {\n readonly name: string;\n /** The start input, decoded before anything else is read from it. */\n readonly input: Schema.Codec<I, unknown>;\n /** Keys the start input provides to the first steps, with their schemas. */\n readonly provides?: FragmentKeys;\n /** A checkout needs a commit point even with nothing retriable in it. */\n readonly requiresCommitPoint?: boolean;\n /** The segments a `perSegment` stage expands over. */\n readonly segments?: (input: I) => readonly SlipSegment[];\n readonly resolve?: readonly RecipeResolution[];\n readonly stages: readonly RecipeStage<I>[];\n}\n\n/** What a composition is stamped with: both are inputs, so composing is deterministic. */\nexport interface ComposeOptions {\n readonly flowId: string;\n readonly composedAt: string;\n}\n\nconst segmentKey = (segment: SlipSegment): string =>\n [segment.vendor, segment.paymentMethod].filter(Boolean).join('/');\n\nconst buildStep = <I>(\n recipeStep: RecipeStep<I>,\n catalog: FragmentCatalog,\n context: VerifiedContext,\n segment: SlipSegment | undefined,\n): SlipStep => {\n const fragment = catalog.get(recipeStep.ref);\n const name = recipeStep.step ?? fragment?.id ?? recipeStep.ref;\n const parameters = recipeStep.parameters?.(context);\n return {\n ref: recipeStep.ref,\n step: segment === undefined ? name : `${segmentKey(segment)}:${name}`,\n cardinality: fragment?.cardinality ?? 'one',\n ...(segment === undefined ? {} : { segment }),\n ...(fragment?.participant === undefined\n ? {}\n : { participant: fragment.participant }),\n ...(fragment?.call === undefined ? {} : { call: fragment.call }),\n ...(fragment?.compensation === undefined\n ? {}\n : { compensation: fragment.compensation }),\n ...(parameters === undefined ? {} : { parameters }),\n };\n};\n\nconst resolutionOf = (\n resolutions: readonly RecipeResolution[],\n context: VerifiedContext,\n): Effect.Effect<readonly SlipResolution[], Unresolvable> =>\n Effect.forEach(resolutions, ({ useCase, rules }) => {\n const chosen = dryRun(rules, context);\n return chosen === undefined\n ? Effect.fail(new Unresolvable({ useCase }))\n : Effect.succeed({ useCase, variant: chosen.variant, rule: chosen.rule });\n });\n\n/** Expands the recipe into an unvalidated slip. */\nconst draft = <I>(\n recipe: Recipe<I>,\n catalog: FragmentCatalog,\n context: VerifiedContext,\n input: I,\n resolution: readonly SlipResolution[],\n options: ComposeOptions,\n): Slip => {\n const segments = recipe.segments?.(input) ?? [];\n const stages = recipe.stages\n .filter(stage => stage.when?.(context, input) ?? true)\n .map(stage => {\n const each: readonly (SlipSegment | undefined)[] =\n stage.perSegment === true ? segments : [undefined];\n return {\n name: stage.name,\n steps: each.flatMap(segment =>\n stage.steps\n .filter(\n recipeStep => recipeStep.when?.(context, input, segment) ?? true,\n )\n .map(recipeStep =>\n buildStep(recipeStep, catalog, context, segment),\n ),\n ),\n };\n })\n .filter(stage => stage.steps.length > 0);\n return {\n slipVersion: SLIP_VERSION,\n flowId: options.flowId,\n recipe: recipe.name,\n ...(recipe.requiresCommitPoint === undefined\n ? {}\n : { requiresCommitPoint: recipe.requiresCommitPoint }),\n stages,\n resolution,\n composedAt: options.composedAt,\n };\n};\n\nconst decodeInput = <I>(recipe: Recipe<I>, input: unknown) =>\n Schema.decodeUnknownEffect(recipe.input)(input).pipe(\n Effect.mapError(\n error =>\n new Invalid({\n errors: [\n FieldProblem.make({\n pointer: '',\n detail: error.message,\n code: 'invalidFlowInput',\n }),\n ],\n }),\n ),\n );\n\n/**\n * Composes a recipe into a pinned, validated slip for one caller: decodes the\n * start input, resolves the recipe's use cases, expands per-segment stages,\n * pins versions and parameters, stamps `slipVersion`, validates, and annotates\n * the span with `entifix.slip.version` and `entifix.slip.fragments`.\n *\n * An unknown `id@n` is a `CompositionRefused` carrying `UnknownFragment`, never\n * a throw; a caller who lacks only what steps require is `FlowRequirementsUnmet`. The same context, input and options always give the same slip.\n */\nexport const compose = <I>(\n recipe: Recipe<I>,\n catalog: FragmentCatalog,\n context: VerifiedContext,\n input: unknown,\n options: ComposeOptions,\n): Effect.Effect<\n Slip,\n CompositionRefused | FlowRequirementsUnmet | Unresolvable | Invalid\n> =>\n Effect.gen(function* () {\n const decoded = yield* decodeInput(recipe, input);\n const resolution = yield* resolutionOf(recipe.resolve ?? [], context);\n const slip = yield* assertValidSlip(\n draft(recipe, catalog, context, decoded, resolution, options),\n catalog,\n {\n context,\n ...(recipe.provides === undefined ? {} : { start: recipe.provides }),\n },\n );\n yield* Effect.annotateCurrentSpan({\n 'entifix.slip.version': slip.slipVersion,\n 'entifix.slip.fragments': slipSteps(slip)\n .map(step => step.ref)\n .join(','),\n });\n return slip;\n });\n\n/** One axis value, labelled so a report can say which combination broke. */\nexport interface Labelled<T> {\n readonly label: string;\n readonly value: T;\n}\n\n/** The axes a recipe is enumerated over. */\nexport interface CompositionAxes<I> {\n readonly contexts: readonly Labelled<VerifiedContext>[];\n readonly inputs: readonly Labelled<I>[];\n}\n\n/** How one combination composed. */\nexport interface CompositionOutcome {\n readonly context: string;\n readonly input: string;\n /**\n * `composed`; `unresolvable`, the caller is offered no variant; `unmet`, the\n * caller lacks what a step requires; or `refused`, the slip broke a rule\n * that no caller could repair — a defect.\n */\n readonly outcome: 'composed' | 'unresolvable' | 'unmet' | 'refused';\n readonly violations: readonly SlipViolation[];\n}\n\nconst ENUMERATED: ComposeOptions = {\n flowId: 'enumerated',\n composedAt: '1970-01-01T00:00:00.000Z',\n};\n\n/**\n * Composes the recipe for every context × input and reports each outcome —\n * what a CI job runs to prove that every combination a recipe can produce is a\n * valid slip before it ships. An unresolvable combination is a caller who is\n * offered nothing, and an unmet one a caller who lacks an entitlement, a role\n * or a channel a step requires — neither is a defect, but a host asserts which\n * combinations are which, since a caller wrongly left without an entitlement\n * looks exactly like one rightly refused. A refused combination is a defect.\n */\nexport const enumerateCompositions = <I>(\n recipe: Recipe<I>,\n catalog: FragmentCatalog,\n axes: CompositionAxes<I>,\n): readonly CompositionOutcome[] =>\n axes.contexts.flatMap(context =>\n axes.inputs.map(input => {\n const resolved = Effect.runSync(\n Effect.result(resolutionOf(recipe.resolve ?? [], context.value)),\n );\n if (resolved._tag === 'Failure')\n return {\n context: context.label,\n input: input.label,\n outcome: 'unresolvable' as const,\n violations: [],\n };\n const violations = validateSlip(\n draft(\n recipe,\n catalog,\n context.value,\n input.value,\n resolved.success,\n ENUMERATED,\n ),\n catalog,\n {\n context: context.value,\n ...(recipe.provides === undefined ? {} : { start: recipe.provides }),\n },\n );\n return {\n context: context.label,\n input: input.label,\n outcome:\n violations.length === 0\n ? ('composed' as const)\n : onlyUnmetRequirements(violations)\n ? ('unmet' as const)\n : ('refused' as const),\n violations,\n };\n }),\n );\n\n/**\n * Throws, listing every refused combination, unless all of them composed,\n * were unresolvable or were unmet. Framework-neutral on purpose: any test runner reports a\n * thrown error.\n */\nexport const expectAllCompositionsValid = (\n outcomes: readonly CompositionOutcome[],\n): void => {\n const refused = outcomes.filter(outcome => outcome.outcome === 'refused');\n if (refused.length > 0)\n throw new Error(\n `${String(refused.length)} composition(s) are not valid slips:\\n` +\n refused\n .map(\n outcome =>\n ` ${outcome.context} × ${outcome.input}: ` +\n outcome.violations\n .map(violation => `${violation.tag} (${violation.detail})`)\n .join('; '),\n )\n .join('\\n'),\n );\n};\n"],"names":["FieldProblem","Invalid","Effect","Schema","SLIP_VERSION","slipSteps","assertValidSlip","onlyUnmetRequirements","validateSlip","dryRun","Unresolvable","segmentKey","segment","vendor","paymentMethod","filter","Boolean","join","buildStep","recipeStep","catalog","context","fragment","get","ref","name","step","id","parameters","undefined","cardinality","participant","call","compensation","resolutionOf","resolutions","forEach","useCase","rules","chosen","fail","succeed","variant","rule","draft","recipe","input","resolution","options","segments","stages","stage","when","map","each","perSegment","steps","flatMap","length","slipVersion","flowId","requiresCommitPoint","composedAt","decodeInput","decodeUnknownEffect","pipe","mapError","error","errors","make","pointer","detail","message","code","compose","gen","decoded","resolve","slip","provides","start","annotateCurrentSpan","ENUMERATED","enumerateCompositions","axes","contexts","inputs","resolved","runSync","result","value","_tag","label","outcome","violations","success","expectAllCompositionsValid","outcomes","refused","Error","String","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+
{"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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;;;;CAIC,GACD,OAAO,MAAME,6BAA6B,CACxCC;IAEA,MAAMC,UAAUD,SAASzF,MAAM,CAACqF,CAAAA,UAAWA,QAAQA,OAAO,KAAK;IAC/D,IAAIK,QAAQzC,MAAM,GAAG,GACnB,MAAM,IAAI0C,MACR,GAAGC,OAAOF,QAAQzC,MAAM,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"}
|
|
@@ -75,6 +75,8 @@ export interface VerbEndpoint<R> {
|
|
|
75
75
|
/** Defaults to the group's write guard. */
|
|
76
76
|
readonly guard?: EntityApiGuard;
|
|
77
77
|
readonly idempotent?: EndpointIdempotency;
|
|
78
|
+
/** The verb starts a flow and answers `202` with what to follow. */
|
|
79
|
+
readonly accepted?: boolean;
|
|
78
80
|
readonly handler: (request: EntityApiRequest, context: EntityApiContext) => Effect.Effect<unknown, EntifixFailure, R>;
|
|
79
81
|
/**
|
|
80
82
|
* The same verb over a selection, for a record-bound verb that also sits in
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-api.d.ts","sourceRoot":"","sources":["../../src/entity-api/entity-api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,MAAM,EACX,KAAK,iBAAiB,EACtB,KAAK,QAAQ,EAEb,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACxB,MAAM,eAAe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,CAAC,MAAM,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1E;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;CAChD;AAED;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB,CACnC,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,MAAM,EAEhB,CAAC,SAAS,gBAAgB,CAAC,CAAC,EAAE,GAAG,CAAC;IAElC,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;IACtC,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;IAChB,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;CACrB;AAED,+DAA+D;AAC/D,KAAK,KAAK,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;AAExE;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAC1B,CAAC,SAAS,MAAM,EAChB,KAAK,CAAC,CAAC,SAAS,MAAM,EAEtB,KAAK,CAAC,CAAC,SAAS,gBAAgB,CAAC,CAAC,EAAE,GAAG,CAAC,EAExC,QAAQ,iBAAiB,CAAC,CAAC,CAAC,EAC5B,KAAK,CAAC,EAEN,SAAS,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,KAC1C,oBAAoB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAA+B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/entity-api/entity-api.ts"],"sourcesContent":["import {\n type EndpointIdempotency,\n type EndpointSchema,\n type EntifixEnvelopeLink,\n type EntifixFailure,\n type Entity,\n type EntityConstructor,\n type EntityId,\n extractUseCase,\n type FailureClass,\n type FilterGroup,\n type MetaUseCase,\n type UseCaseConstructor,\n} from '@entifix/core';\nimport type { Effect } from 'effect';\n\nimport type { RequestPrincipal } from '../request/request-context.js';\nimport type { ResolutionRule } from '../resolve/resolve.js';\nimport type { VerifiedContext } from '../resolve/verified-context.js';\n\n/** The five generic verbs an entity's endpoints can serve. */\nexport type EntityApiVerb = 'list' | 'get' | 'create' | 'update' | 'delete';\n\n/**\n * Who may reach an entity's endpoints. The permission is derived from the\n * entity and the verb, so it is never written here.\n */\nexport type EntityApiGuard =\n | { readonly kind: 'public' }\n | { readonly kind: 'permission' }\n | { readonly kind: 'organization' }\n | { readonly kind: 'crossing'; readonly organization: boolean };\n\n/** The affordances an entity's endpoints derive from the verbs they serve. */\nexport interface EntityApiLinks {\n readonly record: (id: EntityId) => EntifixEnvelopeLink[];\n readonly collection: () => EntifixEnvelopeLink[];\n}\n\n/** What a `prepare`, an override or a verb knows about the caller. */\nexport interface EntityApiContext {\n readonly organizationId?: string;\n readonly principal?: RequestPrincipal;\n readonly verified?: VerifiedContext;\n readonly links: EntityApiLinks;\n}\n\n/** What an override's handler receives: the decoded parts of its request. */\nexport interface EntityApiRequest {\n readonly params?: { readonly id?: string };\n readonly payload?: unknown;\n}\n\n/**\n * Which records of an entity a caller may see: every one, none, or those a\n * filter keeps ([ADR 0015](../../../../../docs/adr/0015-composed-flows-and-use-case-resolution.md)).\n * A filter is conjoined onto the load request, so a query string can only\n * narrow it further and no `or` in it can escape.\n */\nexport type Narrowing<T extends Entity> =\n 'unscoped' | 'nothing' | FilterGroup<T>;\n\n/**\n * A read's narrowing as ordered resolver rules over the verified context: the\n * first variant the caller is entitled to and whose predicate holds builds the\n * narrowing. A caller no rule matches sees **nothing** — the direction a\n * missing rule must fail in.\n */\nexport type NarrowingRules<T extends Entity> = readonly ResolutionRule<\n (context: VerifiedContext) => Narrowing<T>\n>[];\n\n/**\n * One verb served by a handler of the host's instead of the generic one. It\n * keeps the group's path and links, and may change the guard, the payload,\n * the failures and the idempotency the verb declares.\n */\nexport interface EntityVerbOverride<R> {\n readonly guard?: EntityApiGuard;\n readonly idempotent?: EndpointIdempotency;\n readonly errors?: readonly FailureClass[];\n /** The body the verb takes instead of an entity envelope. */\n readonly payload?: EndpointSchema;\n readonly handler: (\n request: EntityApiRequest,\n context: EntityApiContext,\n ) => Effect.Effect<unknown, EntifixFailure, R>;\n}\n\n/**\n * A `@useCase()` verb's endpoint: its path, method, permission and contract\n * come from the declaration, and only who may call it and what it does are\n * written here.\n */\nexport interface VerbEndpoint<R> {\n readonly useCase: MetaUseCase;\n /** Defaults to the group's write guard. */\n readonly guard?: EntityApiGuard;\n readonly idempotent?: EndpointIdempotency;\n readonly handler: (\n request: EntityApiRequest,\n context: EntityApiContext,\n ) => Effect.Effect<unknown, EntifixFailure, R>;\n /**\n * The same verb over a selection, for a record-bound verb that also sits in\n * a collection cell (`alsoAt`): one permission for one act, whether it is\n * asked of a record or of twenty. Required exactly when that cell is\n * declared; its request carries the selection as its payload.\n */\n readonly bulk?: (\n request: EntityApiRequest,\n context: EntityApiContext,\n ) => Effect.Effect<unknown, EntifixFailure, R>;\n}\n\n/** Serve a `@useCase()` class's verb on its entity's endpoints. */\nexport const verbEndpoint = <\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- inferred from the options\n const O extends Omit<VerbEndpoint<any>, 'useCase'>,\n>(\n useCaseClass: UseCaseConstructor,\n options: O,\n): O & { readonly useCase: MetaUseCase } => ({\n ...options,\n useCase: extractUseCase(useCaseClass),\n});\n\n/** What an entity's endpoints serve, and under which rules. */\nexport interface EntityApiOptions<T extends Entity, R> {\n readonly verbs: readonly EntityApiVerb[];\n /** One guard for every verb, or one for the reads and one for the writes. */\n readonly guard:\n | EntityApiGuard\n | { readonly read: EntityApiGuard; readonly write: EntityApiGuard };\n /** Narrows the reads, and the facet counts, to what this caller may see. */\n readonly narrowing?: NarrowingRules<T>;\n /** Serve `$facets` beside the list, under the list's guard and narrowing. */\n readonly facets?: boolean;\n /** Runs on every generic create and update, before the save. */\n readonly prepare?: (\n entity: T,\n context: EntityApiContext & { readonly verb: 'create' | 'update' },\n ) => Effect.Effect<T, EntifixFailure, R>;\n /** The business failures `prepare` may answer with, for the contract. */\n readonly errors?: readonly FailureClass[];\n readonly override?: Partial<Record<EntityApiVerb, EntityVerbOverride<R>>>;\n /**\n * The entity's `@useCase()` verbs, one endpoint each. Every verb the entity\n * declares must be here and none another entity declares, or serving the\n * declaration throws.\n */\n readonly useCases?: readonly VerbEndpoint<R>[];\n}\n\n/**\n * An entity's endpoints as a value: which verbs, behind which guards, with\n * which handlers. Declaring them needs no HTTP — a domain's cell declares, and\n * the shell serves the declaration with `entityApi`\n * ([ADR 0020](../../../../../docs/adr/0020-endpoints-are-descriptors-and-the-shell-builds-an-httpapi.md)).\n */\nexport interface EntityApiDeclaration<\n T extends Entity,\n K extends string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- inferred from the options\n O extends EntityApiOptions<T, any>,\n> {\n readonly entity: EntityConstructor<T>;\n readonly key: K;\n readonly options: O;\n}\n\n/** `O`, with every key `Shape` does not name typed `never`. */\ntype Exact<O, Shape> = O & Record<Exclude<keyof O, keyof Shape>, never>;\n\n/**\n * Declare an entity's endpoints, to be served by the shell. An option the\n * declaration does not know is a compile error rather than a value nobody\n * reads — `compositions` included, which the shell adds when it serves.\n */\nexport const defineEntityApi = <\n T extends Entity,\n const K extends string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- inferred from the options\n const O extends EntityApiOptions<T, any>,\n>(\n entity: EntityConstructor<T>,\n key: K,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- inferred from the options\n options: Exact<O, EntityApiOptions<T, any>>,\n): EntityApiDeclaration<T, K, O> => ({ entity, key, options });\n"],"names":["extractUseCase","verbEndpoint","useCaseClass","options","useCase","defineEntityApi","entity","key"],"mappings":";AAAA,SAQEA,cAAc,QAKT,gBAAgB;
|
|
1
|
+
{"version":3,"sources":["../../src/entity-api/entity-api.ts"],"sourcesContent":["import {\n type EndpointIdempotency,\n type EndpointSchema,\n type EntifixEnvelopeLink,\n type EntifixFailure,\n type Entity,\n type EntityConstructor,\n type EntityId,\n extractUseCase,\n type FailureClass,\n type FilterGroup,\n type MetaUseCase,\n type UseCaseConstructor,\n} from '@entifix/core';\nimport type { Effect } from 'effect';\n\nimport type { RequestPrincipal } from '../request/request-context.js';\nimport type { ResolutionRule } from '../resolve/resolve.js';\nimport type { VerifiedContext } from '../resolve/verified-context.js';\n\n/** The five generic verbs an entity's endpoints can serve. */\nexport type EntityApiVerb = 'list' | 'get' | 'create' | 'update' | 'delete';\n\n/**\n * Who may reach an entity's endpoints. The permission is derived from the\n * entity and the verb, so it is never written here.\n */\nexport type EntityApiGuard =\n | { readonly kind: 'public' }\n | { readonly kind: 'permission' }\n | { readonly kind: 'organization' }\n | { readonly kind: 'crossing'; readonly organization: boolean };\n\n/** The affordances an entity's endpoints derive from the verbs they serve. */\nexport interface EntityApiLinks {\n readonly record: (id: EntityId) => EntifixEnvelopeLink[];\n readonly collection: () => EntifixEnvelopeLink[];\n}\n\n/** What a `prepare`, an override or a verb knows about the caller. */\nexport interface EntityApiContext {\n readonly organizationId?: string;\n readonly principal?: RequestPrincipal;\n readonly verified?: VerifiedContext;\n readonly links: EntityApiLinks;\n}\n\n/** What an override's handler receives: the decoded parts of its request. */\nexport interface EntityApiRequest {\n readonly params?: { readonly id?: string };\n readonly payload?: unknown;\n}\n\n/**\n * Which records of an entity a caller may see: every one, none, or those a\n * filter keeps ([ADR 0015](../../../../../docs/adr/0015-composed-flows-and-use-case-resolution.md)).\n * A filter is conjoined onto the load request, so a query string can only\n * narrow it further and no `or` in it can escape.\n */\nexport type Narrowing<T extends Entity> =\n 'unscoped' | 'nothing' | FilterGroup<T>;\n\n/**\n * A read's narrowing as ordered resolver rules over the verified context: the\n * first variant the caller is entitled to and whose predicate holds builds the\n * narrowing. A caller no rule matches sees **nothing** — the direction a\n * missing rule must fail in.\n */\nexport type NarrowingRules<T extends Entity> = readonly ResolutionRule<\n (context: VerifiedContext) => Narrowing<T>\n>[];\n\n/**\n * One verb served by a handler of the host's instead of the generic one. It\n * keeps the group's path and links, and may change the guard, the payload,\n * the failures and the idempotency the verb declares.\n */\nexport interface EntityVerbOverride<R> {\n readonly guard?: EntityApiGuard;\n readonly idempotent?: EndpointIdempotency;\n readonly errors?: readonly FailureClass[];\n /** The body the verb takes instead of an entity envelope. */\n readonly payload?: EndpointSchema;\n readonly handler: (\n request: EntityApiRequest,\n context: EntityApiContext,\n ) => Effect.Effect<unknown, EntifixFailure, R>;\n}\n\n/**\n * A `@useCase()` verb's endpoint: its path, method, permission and contract\n * come from the declaration, and only who may call it and what it does are\n * written here.\n */\nexport interface VerbEndpoint<R> {\n readonly useCase: MetaUseCase;\n /** Defaults to the group's write guard. */\n readonly guard?: EntityApiGuard;\n readonly idempotent?: EndpointIdempotency;\n /** The verb starts a flow and answers `202` with what to follow. */\n readonly accepted?: boolean;\n readonly handler: (\n request: EntityApiRequest,\n context: EntityApiContext,\n ) => Effect.Effect<unknown, EntifixFailure, R>;\n /**\n * The same verb over a selection, for a record-bound verb that also sits in\n * a collection cell (`alsoAt`): one permission for one act, whether it is\n * asked of a record or of twenty. Required exactly when that cell is\n * declared; its request carries the selection as its payload.\n */\n readonly bulk?: (\n request: EntityApiRequest,\n context: EntityApiContext,\n ) => Effect.Effect<unknown, EntifixFailure, R>;\n}\n\n/** Serve a `@useCase()` class's verb on its entity's endpoints. */\nexport const verbEndpoint = <\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- inferred from the options\n const O extends Omit<VerbEndpoint<any>, 'useCase'>,\n>(\n useCaseClass: UseCaseConstructor,\n options: O,\n): O & { readonly useCase: MetaUseCase } => ({\n ...options,\n useCase: extractUseCase(useCaseClass),\n});\n\n/** What an entity's endpoints serve, and under which rules. */\nexport interface EntityApiOptions<T extends Entity, R> {\n readonly verbs: readonly EntityApiVerb[];\n /** One guard for every verb, or one for the reads and one for the writes. */\n readonly guard:\n | EntityApiGuard\n | { readonly read: EntityApiGuard; readonly write: EntityApiGuard };\n /** Narrows the reads, and the facet counts, to what this caller may see. */\n readonly narrowing?: NarrowingRules<T>;\n /** Serve `$facets` beside the list, under the list's guard and narrowing. */\n readonly facets?: boolean;\n /** Runs on every generic create and update, before the save. */\n readonly prepare?: (\n entity: T,\n context: EntityApiContext & { readonly verb: 'create' | 'update' },\n ) => Effect.Effect<T, EntifixFailure, R>;\n /** The business failures `prepare` may answer with, for the contract. */\n readonly errors?: readonly FailureClass[];\n readonly override?: Partial<Record<EntityApiVerb, EntityVerbOverride<R>>>;\n /**\n * The entity's `@useCase()` verbs, one endpoint each. Every verb the entity\n * declares must be here and none another entity declares, or serving the\n * declaration throws.\n */\n readonly useCases?: readonly VerbEndpoint<R>[];\n}\n\n/**\n * An entity's endpoints as a value: which verbs, behind which guards, with\n * which handlers. Declaring them needs no HTTP — a domain's cell declares, and\n * the shell serves the declaration with `entityApi`\n * ([ADR 0020](../../../../../docs/adr/0020-endpoints-are-descriptors-and-the-shell-builds-an-httpapi.md)).\n */\nexport interface EntityApiDeclaration<\n T extends Entity,\n K extends string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- inferred from the options\n O extends EntityApiOptions<T, any>,\n> {\n readonly entity: EntityConstructor<T>;\n readonly key: K;\n readonly options: O;\n}\n\n/** `O`, with every key `Shape` does not name typed `never`. */\ntype Exact<O, Shape> = O & Record<Exclude<keyof O, keyof Shape>, never>;\n\n/**\n * Declare an entity's endpoints, to be served by the shell. An option the\n * declaration does not know is a compile error rather than a value nobody\n * reads — `compositions` included, which the shell adds when it serves.\n */\nexport const defineEntityApi = <\n T extends Entity,\n const K extends string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- inferred from the options\n const O extends EntityApiOptions<T, any>,\n>(\n entity: EntityConstructor<T>,\n key: K,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- inferred from the options\n options: Exact<O, EntityApiOptions<T, any>>,\n): EntityApiDeclaration<T, K, O> => ({ entity, key, options });\n"],"names":["extractUseCase","verbEndpoint","useCaseClass","options","useCase","defineEntityApi","entity","key"],"mappings":";AAAA,SAQEA,cAAc,QAKT,gBAAgB;AAwGvB,iEAAiE,GACjE,OAAO,MAAMC,eAAe,CAI1BC,cACAC,UAC2C,aACxCA;QACHC,SAASJ,eAAeE;OACvB;AAiDH;;;;CAIC,GACD,OAAO,MAAMG,kBAAkB,CAM7BC,QACAC,KACA,2FAA2F;AAC3FJ,UACmC,CAAA;QAAEG;QAAQC;QAAKJ;IAAQ,CAAA,EAAG"}
|
package/dist/flow/slip.d.ts
CHANGED
|
@@ -6,10 +6,16 @@ import { Effect, Schema } from 'effect';
|
|
|
6
6
|
* the next one ships.
|
|
7
7
|
*/
|
|
8
8
|
export declare const SLIP_VERSION: 1;
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Tags that place a step in a segment of the flow: whose lines, which payment.
|
|
11
|
+
* `entitlements` are the facts verified for the party the segment acts for —
|
|
12
|
+
* a vendor's provisioning, never the caller's — and a segment's steps are
|
|
13
|
+
* checked against them beside the flow's context.
|
|
14
|
+
*/
|
|
10
15
|
export declare const SlipSegment: Schema.Struct<{
|
|
11
16
|
readonly vendor: Schema.optionalKey<Schema.String>;
|
|
12
17
|
readonly paymentMethod: Schema.optionalKey<Schema.String>;
|
|
18
|
+
readonly entitlements: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
13
19
|
}>;
|
|
14
20
|
export type SlipSegment = typeof SlipSegment.Type;
|
|
15
21
|
/** One pinned step: a fragment reference and everything resolved for it. */
|
|
@@ -22,7 +28,10 @@ export declare const SlipStep: Schema.Struct<{
|
|
|
22
28
|
readonly segment: Schema.optionalKey<Schema.Struct<{
|
|
23
29
|
readonly vendor: Schema.optionalKey<Schema.String>;
|
|
24
30
|
readonly paymentMethod: Schema.optionalKey<Schema.String>;
|
|
31
|
+
readonly entitlements: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
25
32
|
}>>;
|
|
33
|
+
/** The line a `perLine` step was expanded for, by the recipe's key. */
|
|
34
|
+
readonly line: Schema.optionalKey<Schema.String>;
|
|
26
35
|
readonly participant: Schema.optionalKey<Schema.String>;
|
|
27
36
|
readonly call: Schema.optionalKey<Schema.Struct<{
|
|
28
37
|
readonly method: Schema.Literals<readonly ["GET", "POST", "PUT", "PATCH", "DELETE"]>;
|
|
@@ -47,7 +56,10 @@ export declare const SlipStage: Schema.Struct<{
|
|
|
47
56
|
readonly segment: Schema.optionalKey<Schema.Struct<{
|
|
48
57
|
readonly vendor: Schema.optionalKey<Schema.String>;
|
|
49
58
|
readonly paymentMethod: Schema.optionalKey<Schema.String>;
|
|
59
|
+
readonly entitlements: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
50
60
|
}>>;
|
|
61
|
+
/** The line a `perLine` step was expanded for, by the recipe's key. */
|
|
62
|
+
readonly line: Schema.optionalKey<Schema.String>;
|
|
51
63
|
readonly participant: Schema.optionalKey<Schema.String>;
|
|
52
64
|
readonly call: Schema.optionalKey<Schema.Struct<{
|
|
53
65
|
readonly method: Schema.Literals<readonly ["GET", "POST", "PUT", "PATCH", "DELETE"]>;
|
|
@@ -68,6 +80,7 @@ export declare const SlipAudienceEntry: Schema.Struct<{
|
|
|
68
80
|
readonly id: Schema.String;
|
|
69
81
|
readonly digest: Schema.optionalKey<Schema.String>;
|
|
70
82
|
}>;
|
|
83
|
+
export type SlipAudienceEntry = typeof SlipAudienceEntry.Type;
|
|
71
84
|
/** Which variant each use case resolved to, and by which rule. */
|
|
72
85
|
export declare const SlipResolution: Schema.Struct<{
|
|
73
86
|
readonly useCase: Schema.String;
|
|
@@ -97,7 +110,10 @@ export declare const Slip: Schema.Struct<{
|
|
|
97
110
|
readonly segment: Schema.optionalKey<Schema.Struct<{
|
|
98
111
|
readonly vendor: Schema.optionalKey<Schema.String>;
|
|
99
112
|
readonly paymentMethod: Schema.optionalKey<Schema.String>;
|
|
113
|
+
readonly entitlements: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
100
114
|
}>>;
|
|
115
|
+
/** The line a `perLine` step was expanded for, by the recipe's key. */
|
|
116
|
+
readonly line: Schema.optionalKey<Schema.String>;
|
|
101
117
|
readonly participant: Schema.optionalKey<Schema.String>;
|
|
102
118
|
readonly call: Schema.optionalKey<Schema.Struct<{
|
|
103
119
|
readonly method: Schema.Literals<readonly ["GET", "POST", "PUT", "PATCH", "DELETE"]>;
|
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;AAOvC
|
|
1
|
+
{"version":3,"file":"slip.d.ts","sourceRoot":"","sources":["../../src/flow/slip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAExC;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAG,CAAU,CAAC;AAOvC;;;;;GAKG;AACH,eAAO,MAAM,WAAW;;;;EAItB,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC,IAAI,CAAC;AAElD,4EAA4E;AAC5E,eAAO,MAAM,QAAQ;IACnB,uDAAuD;;IAEvD,gFAAgF;;;;;;;;IAIhF,uEAAuE;;;;;;;;;;;IAKvE,sEAAsE;;EAEtE,CAAC;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,IAAI,CAAC;AAE5C,eAAO,MAAM,SAAS;;;QAhBpB,uDAAuD;;QAEvD,gFAAgF;;;;;;;;QAIhF,uEAAuE;;;;;;;;;;;QAKvE,sEAAsE;;;EAQtE,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;;;;;YA/ClF,uDAAuD;;YAEvD,gFAAgF;;;;;;;;YAIhF,uEAAuE;;;;;;;;;;;YAKvE,sEAAsE;;;;;;;;;;IAyCtE;;;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
|
@@ -15,9 +15,15 @@ const Call = Schema.Struct({
|
|
|
15
15
|
]),
|
|
16
16
|
path: Schema.String
|
|
17
17
|
});
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Tags that place a step in a segment of the flow: whose lines, which payment.
|
|
20
|
+
* `entitlements` are the facts verified for the party the segment acts for —
|
|
21
|
+
* a vendor's provisioning, never the caller's — and a segment's steps are
|
|
22
|
+
* checked against them beside the flow's context.
|
|
23
|
+
*/ export const SlipSegment = Schema.Struct({
|
|
19
24
|
vendor: Schema.optionalKey(Schema.String),
|
|
20
|
-
paymentMethod: Schema.optionalKey(Schema.String)
|
|
25
|
+
paymentMethod: Schema.optionalKey(Schema.String),
|
|
26
|
+
entitlements: Schema.optionalKey(Schema.Array(Schema.String))
|
|
21
27
|
});
|
|
22
28
|
/** One pinned step: a fragment reference and everything resolved for it. */ export const SlipStep = Schema.Struct({
|
|
23
29
|
/** `id@version`, pinned when the slip was composed. */ ref: Schema.String,
|
|
@@ -28,6 +34,7 @@ const Call = Schema.Struct({
|
|
|
28
34
|
'perLine'
|
|
29
35
|
]),
|
|
30
36
|
segment: Schema.optionalKey(SlipSegment),
|
|
37
|
+
/** The line a `perLine` step was expanded for, by the recipe's key. */ line: Schema.optionalKey(Schema.String),
|
|
31
38
|
participant: Schema.optionalKey(Schema.String),
|
|
32
39
|
call: Schema.optionalKey(Call),
|
|
33
40
|
compensation: Schema.optionalKey(Call),
|
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
|
|
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.Literal(SLIP_VERSION),\n flowId: Schema.String,\n recipe: Schema.String,\n /** The recipe demands a commit point even with no retriable step (a checkout). */\n requiresCommitPoint: Schema.optionalKey(Schema.Boolean),\n stages: Schema.Array(SlipStage),\n resolution: Schema.Array(SlipResolution),\n composedAt: Schema.String,\n /**\n * Who the flow's `flow.*` events reach beside the flow itself — the\n * organizations and parties it acts for, pinned when it was composed.\n */\n audience: Schema.optionalKey(Schema.Array(SlipAudienceEntry)),\n});\nexport type Slip = typeof Slip.Type;\n\n/**\n * Decodes a stored or received slip. An unknown `slipVersion`, like any shape\n * the grammar does not describe, is a protocol failure: an interpreter must\n * never guess at a grammar it was not built for.\n */\nexport const decodeSlip = (\n input: unknown,\n): Effect.Effect<Slip, ProtocolFailure> =>\n Schema.decodeUnknownEffect(Slip)(input).pipe(\n Effect.mapError(\n error =>\n new ProtocolFailure({\n reason: `the slip does not decode: ${error.message}`,\n }),\n ),\n );\n\n/** Encodes a slip as the workflow payload it travels as. */\nexport const encodeSlip = (slip: Slip): unknown =>\n Schema.encodeSync(Slip)(slip);\n\n/** Every step of a slip, in the order it runs. */\nexport const slipSteps = (slip: Slip): readonly SlipStep[] =>\n slip.stages.flatMap(stage => stage.steps);\n"],"names":["ProtocolFailure","Effect","Schema","SLIP_VERSION","Call","Struct","method","Literals","path","String","SlipSegment","vendor","optionalKey","paymentMethod","entitlements","Array","SlipStep","ref","step","cardinality","segment","line","participant","call","compensation","parameters","Record","Unknown","SlipStage","name","steps","SlipAudienceEntry","kind","id","digest","SlipResolution","useCase","variant","rule","Number","Slip","slipVersion","Literal","flowId","recipe","requiresCommitPoint","Boolean","stages","resolution","composedAt","audience","decodeSlip","input","decodeUnknownEffect","pipe","mapError","error","reason","message","encodeSlip","slip","encodeSync","slipSteps","flatMap","stage"],"mappings":"AAAA,SAASA,eAAe,QAAQ,gBAAgB;AAChD,SAASC,MAAM,EAAEC,MAAM,QAAQ,SAAS;AAExC;;;;CAIC,GACD,OAAO,MAAMC,eAAe,EAAW;AAEvC,MAAMC,OAAOF,OAAOG,MAA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AQ1C;CAAG;AAEJ,2EAA2E;AAC3E,eAAO,MAAM,qBAAqB,GAChC,YAAY,SAAS,aAAa,EAAE,KACnC,OAEkE,CAAC;AAEtE;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAC1B,MAAM,IAAI,EACV,SAAS,eAAe,EACxB,UAAS,mBAAwB,KAChC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,kBAAkB,GAAG,qBAAqB,CAQhE,CAAC"}
|
package/dist/flow/validate.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
1
2
|
import { Failure } from '@entifix/core';
|
|
2
3
|
import { Effect, Schema } from 'effect';
|
|
3
4
|
import { jsonSchemaOf } from './fragment.js';
|
|
@@ -12,6 +13,19 @@ const sameSchema = (a, b)=>a === b || JSON.stringify(jsonSchemaOf(a)) === JSON.s
|
|
|
12
13
|
if (requires.channels !== undefined && !requires.channels.includes((_facts_channel = facts.channel) != null ? _facts_channel : '')) missing.push(`channel in ${requires.channels.join(', ')}`);
|
|
13
14
|
return missing;
|
|
14
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* The facts a segment's step is checked against: the flow's, plus what was
|
|
18
|
+
* verified for the party the segment acts for. A storefront buyer holds no
|
|
19
|
+
* entitlement, and the vendor whose stock a step holds does.
|
|
20
|
+
*/ const withSegmentFacts = (facts, entitlements)=>{
|
|
21
|
+
var _facts_entitlements;
|
|
22
|
+
return entitlements === undefined ? facts : _extends({}, facts, {
|
|
23
|
+
entitlements: [
|
|
24
|
+
...(_facts_entitlements = facts.entitlements) != null ? _facts_entitlements : [],
|
|
25
|
+
...entitlements
|
|
26
|
+
]
|
|
27
|
+
});
|
|
28
|
+
};
|
|
15
29
|
/**
|
|
16
30
|
* Checks a slip against its catalog and returns **every** violation, one tag
|
|
17
31
|
* per rule, rather than throwing at the first — so a CI job enumerating every
|
|
@@ -92,7 +106,8 @@ const sameSchema = (a, b)=>a === b || JSON.stringify(jsonSchemaOf(a)) === JSON.s
|
|
|
92
106
|
}
|
|
93
107
|
for (const [key, schema] of Object.entries((_fragment_provides = fragment.provides) != null ? _fragment_provides : {}))provided.set(key, schema);
|
|
94
108
|
if (options.context !== undefined && fragment.requires !== undefined) {
|
|
95
|
-
|
|
109
|
+
var _step_segment1;
|
|
110
|
+
const missing = unmetRequirements(fragment.requires, withSegmentFacts(options.context, (_step_segment1 = step.segment) == null ? void 0 : _step_segment1.entitlements));
|
|
96
111
|
if (missing.length > 0) violations.push({
|
|
97
112
|
tag: 'UnmetRequirement',
|
|
98
113
|
step: step.step,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/flow/validate.ts"],"sourcesContent":["import { Failure } from '@entifix/core';\nimport { Effect, Schema } from 'effect';\n\nimport type { FragmentCatalog } from './catalog.js';\nimport {\n type FragmentDescriptor,\n type FragmentKeys,\n type FragmentRequirements,\n jsonSchemaOf,\n} from './fragment.js';\nimport { type Slip, type SlipStep, slipSteps } from './slip.js';\n\n/** One rule a slip broke, named by its tag. */\nexport interface SlipViolation {\n readonly tag:\n | 'UnknownFragment'\n | 'TooManyPivots'\n | 'MissingCommitPoint'\n | 'RetriableBeforeCommit'\n | 'CompensatableAfterCommit'\n | 'IrreversibleBeforeCommit'\n | 'WaitBeforeCommit'\n | 'ExcludedFromSegment'\n | 'UnsatisfiedInput'\n | 'UnmetRequirement';\n /** The step that broke it, when one step did. */\n readonly step?: string;\n readonly detail: string;\n}\n\n/** The facts of a verified context a slip's requirements are checked against. */\nexport interface RequirementFacts {\n readonly entitlements?: readonly string[];\n readonly roles?: readonly string[];\n readonly partyRole?: string;\n readonly channel?: string;\n}\n\nexport interface ValidateSlipOptions {\n /** The facts the caller was verified with; requirements go unchecked without them. */\n readonly context?: RequirementFacts;\n /** Keys the flow's start input provides, with their schemas. */\n readonly start?: FragmentKeys;\n}\n\nconst sameSchema = (\n a: Schema.Codec<unknown, unknown>,\n b: Schema.Codec<unknown, unknown>,\n): boolean =>\n a === b ||\n JSON.stringify(jsonSchemaOf(a)) === JSON.stringify(jsonSchemaOf(b));\n\n/** The requirements `facts` do not meet, described; empty when all are met. */\nexport const unmetRequirements = (\n requires: FragmentRequirements,\n facts: RequirementFacts,\n): string[] => {\n const missing: string[] = [];\n for (const entitlement of requires.entitlements ?? [])\n if (!(facts.entitlements ?? []).includes(entitlement))\n missing.push(`entitlement '${entitlement}'`);\n for (const role of requires.roles ?? [])\n if (!(facts.roles ?? []).includes(role)) missing.push(`role '${role}'`);\n if (\n requires.partyRoles !== undefined &&\n !requires.partyRoles.includes(facts.partyRole ?? '')\n )\n missing.push(`party role in ${requires.partyRoles.join(', ')}`);\n if (\n requires.channels !== undefined &&\n !requires.channels.includes(facts.channel ?? '')\n )\n missing.push(`channel in ${requires.channels.join(', ')}`);\n return missing;\n};\n\n/**\n * Checks a slip against its catalog and returns **every** violation, one tag\n * per rule, rather than throwing at the first — so a CI job enumerating every\n * composition reports them all in one run. Pure: no clock, no I/O.\n */\nexport const validateSlip = (\n slip: Slip,\n catalog: FragmentCatalog,\n options: ValidateSlipOptions = {},\n): readonly SlipViolation[] => {\n const violations: SlipViolation[] = [];\n const resolved: {\n readonly step: SlipStep;\n readonly fragment: FragmentDescriptor;\n }[] = [];\n\n for (const step of slipSteps(slip)) {\n const fragment = catalog.get(step.ref);\n if (fragment === undefined)\n violations.push({\n tag: 'UnknownFragment',\n step: step.step,\n detail: `'${step.ref}' is not in the catalog`,\n });\n else resolved.push({ step, fragment });\n }\n\n const pivots = resolved.filter(({ fragment }) => fragment.kind === 'pivot');\n if (pivots.length > 1)\n violations.push({\n tag: 'TooManyPivots',\n detail: `the slip has ${String(pivots.length)} pivots (${pivots\n .map(({ step }) => step.step)\n .join(', ')}); a flow has one point of no return`,\n });\n\n const commitAt = resolved.findIndex(\n ({ fragment }) => fragment.kind === 'pivot',\n );\n const hasRetriable = resolved.some(\n ({ fragment }) => fragment.kind === 'retriable',\n );\n if (commitAt === -1 && (hasRetriable || slip.requiresCommitPoint === true))\n violations.push({\n tag: 'MissingCommitPoint',\n detail:\n 'the slip needs one commit point — a pivot, or flow.commit@1 — before its first retriable step',\n });\n\n const provided = new Map<string, Schema.Codec<unknown, unknown>>(\n Object.entries(options.start ?? {}),\n );\n\n resolved.forEach(({ step, fragment }, index) => {\n const beforeCommit = commitAt === -1 || index < commitAt;\n const afterCommit = commitAt !== -1 && index > commitAt;\n\n if (fragment.kind === 'retriable' && commitAt !== -1 && index < commitAt)\n violations.push({\n tag: 'RetriableBeforeCommit',\n step: step.step,\n detail: `'${step.ref}' is retriable and runs before the commit point, where a failure must compensate`,\n });\n if (fragment.kind === 'compensatable' && afterCommit)\n violations.push({\n tag: 'CompensatableAfterCommit',\n step: step.step,\n detail: `'${step.ref}' is compensatable and runs after the commit point, where nothing is undone`,\n });\n if (\n fragment.irreversible === true &&\n fragment.kind !== 'pivot' &&\n beforeCommit\n )\n violations.push({\n tag: 'IrreversibleBeforeCommit',\n step: step.step,\n detail: `'${step.ref}' cannot be undone and runs before the commit point`,\n });\n if (fragment.kind === 'wait' && beforeCommit)\n violations.push({\n tag: 'WaitBeforeCommit',\n step: step.step,\n detail: `'${step.ref}' waits before the commit point, holding uncommitted state for as long as it waits`,\n });\n\n for (const [tag, values] of Object.entries(fragment.excludedFrom ?? {})) {\n const value = (\n step.segment as Record<string, string | undefined> | undefined\n )?.[tag];\n if (value !== undefined && values.includes(value))\n violations.push({\n tag: 'ExcludedFromSegment',\n step: step.step,\n detail: `'${step.ref}' may not run in a segment whose ${tag} is '${value}'`,\n });\n }\n\n for (const [key, schema] of Object.entries(fragment.consumes ?? {})) {\n const earlier = provided.get(key);\n if (earlier === undefined)\n violations.push({\n tag: 'UnsatisfiedInput',\n step: step.step,\n detail: `'${step.ref}' consumes '${key}', which nothing before it provides`,\n });\n else if (!sameSchema(earlier, schema))\n violations.push({\n tag: 'UnsatisfiedInput',\n step: step.step,\n detail: `'${step.ref}' consumes '${key}' with a schema other than the one provided`,\n });\n }\n for (const [key, schema] of Object.entries(fragment.provides ?? {}))\n provided.set(key, schema);\n\n if (options.context !== undefined && fragment.requires !== undefined) {\n const missing = unmetRequirements(fragment.requires, options.context);\n if (missing.length > 0)\n violations.push({\n tag: 'UnmetRequirement',\n step: step.step,\n detail: `'${step.ref}' requires ${missing.join(', ')}`,\n });\n }\n });\n\n return violations;\n};\n\nconst SlipViolationSchema = Schema.Struct({\n tag: Schema.String,\n step: Schema.optionalKey(Schema.String),\n detail: Schema.String,\n});\n\n/**\n * A flow that cannot be composed for this caller: the slip broke at least one\n * rule. Every violation travels with it.\n */\nexport class CompositionRefused extends Failure.declined<CompositionRefused>()(\n 'CompositionRefused',\n 'flowNotComposable',\n { violations: Schema.Array(SlipViolationSchema) },\n {\n message: ({ violations }) =>\n `the flow cannot be composed: ${violations.map(v => v.tag).join(', ')}`,\n },\n) {}\n\n/**\n * A flow this caller is not offered: every rule the slip broke is a step's\n * requirement — an entitlement, a role, a party role or a channel — that the\n * verified context lacks. The recipe is sound; the caller may not run it, so\n * it is `forbidden` rather than a slip that could not be built.\n */\nexport class FlowRequirementsUnmet extends Failure.forbidden<FlowRequirementsUnmet>()(\n 'FlowRequirementsUnmet',\n 'flowRequirementsUnmet',\n { violations: Schema.Array(SlipViolationSchema) },\n {\n message: ({ violations }) =>\n `the flow is not offered to this caller: ${violations.map(v => v.detail).join('; ')}`,\n },\n) {}\n\n/** Every violation is a requirement the caller lacks, and there is one. */\nexport const onlyUnmetRequirements = (\n violations: readonly SlipViolation[],\n): boolean =>\n violations.length > 0 &&\n violations.every(violation => violation.tag === 'UnmetRequirement');\n\n/**\n * Validates a slip, failing on any violation: with {@link FlowRequirementsUnmet}\n * when the caller lacks only what steps require, and otherwise with\n * {@link CompositionRefused}, which carries every violation.\n */\nexport const assertValidSlip = (\n slip: Slip,\n catalog: FragmentCatalog,\n options: ValidateSlipOptions = {},\n): Effect.Effect<Slip, CompositionRefused | FlowRequirementsUnmet> => {\n const violations = validateSlip(slip, catalog, options);\n if (violations.length === 0) return Effect.succeed(slip);\n return Effect.fail(\n onlyUnmetRequirements(violations)\n ? new FlowRequirementsUnmet({ violations })\n : new CompositionRefused({ violations }),\n );\n};\n"],"names":["Failure","Effect","Schema","jsonSchemaOf","slipSteps","sameSchema","a","b","JSON","stringify","unmetRequirements","requires","facts","missing","entitlement","entitlements","includes","push","role","roles","partyRoles","undefined","partyRole","join","channels","channel","validateSlip","slip","catalog","options","violations","resolved","step","fragment","get","ref","tag","detail","pivots","filter","kind","length","String","map","commitAt","findIndex","hasRetriable","some","requiresCommitPoint","provided","Map","Object","entries","start","forEach","index","beforeCommit","afterCommit","irreversible","values","excludedFrom","value","segment","key","schema","consumes","earlier","provides","set","context","SlipViolationSchema","Struct","optionalKey","CompositionRefused","declined","Array","message","v","FlowRequirementsUnmet","forbidden","onlyUnmetRequirements","every","violation","assertValidSlip","succeed","fail"],"mappings":"AAAA,SAASA,OAAO,QAAQ,gBAAgB;AACxC,SAASC,MAAM,EAAEC,MAAM,QAAQ,SAAS;AAGxC,SAIEC,YAAY,QACP,gBAAgB;AACvB,SAAmCC,SAAS,QAAQ,YAAY;AAmChE,MAAMC,aAAa,CACjBC,GACAC,IAEAD,MAAMC,KACNC,KAAKC,SAAS,CAACN,aAAaG,QAAQE,KAAKC,SAAS,CAACN,aAAaI;AAElE,6EAA6E,GAC7E,OAAO,MAAMG,oBAAoB,CAC/BC,UACAC;QAG0BD,wBAClBC,qBAEWD,iBACXC,cAGwBA,kBAKFA;IAb9B,MAAMC,UAAoB,EAAE;IAC5B,KAAK,MAAMC,gBAAeH,yBAAAA,SAASI,YAAY,YAArBJ,yBAAyB,EAAE,CACnD,IAAI,CAAC,EAACC,sBAAAA,MAAMG,YAAY,YAAlBH,sBAAsB,EAAE,EAAEI,QAAQ,CAACF,cACvCD,QAAQI,IAAI,CAAC,CAAC,aAAa,EAAEH,YAAY,CAAC,CAAC;IAC/C,KAAK,MAAMI,SAAQP,kBAAAA,SAASQ,KA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,UAAU,EAAE,GACtB,CAAC,wCAAwC,EAAEA,WAAWa,GAAG,CAACkC,CAAAA,IAAKA,EAAExC,MAAM,EAAEd,IAAI,CAAC,OAAO;AACzF;AACC;AAEH,yEAAyE,GACzE,OAAO,MAAMyD,wBAAwB,CACnClD,aAEAA,WAAWW,MAAM,GAAG,KACpBX,WAAWmD,KAAK,CAACC,CAAAA,YAAaA,UAAU9C,GAAG,KAAK,oBAAoB;AAEtE;;;;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,OAAOxC,OAAOmF,OAAO,CAACzD;IACnD,OAAO1B,OAAOoF,IAAI,CAChBL,sBAAsBlD,cAClB,IAAIgD,sBAAsB;QAAEhD;IAAW,KACvC,IAAI2C,mBAAmB;QAAE3C;IAAW;AAE5C,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../../src/flow/validate.ts"],"sourcesContent":["import { Failure } from '@entifix/core';\nimport { Effect, Schema } from 'effect';\n\nimport type { FragmentCatalog } from './catalog.js';\nimport {\n type FragmentDescriptor,\n type FragmentKeys,\n type FragmentRequirements,\n jsonSchemaOf,\n} from './fragment.js';\nimport { type Slip, type SlipStep, slipSteps } from './slip.js';\n\n/** One rule a slip broke, named by its tag. */\nexport interface SlipViolation {\n readonly tag:\n | 'UnknownFragment'\n | 'TooManyPivots'\n | 'MissingCommitPoint'\n | 'RetriableBeforeCommit'\n | 'CompensatableAfterCommit'\n | 'IrreversibleBeforeCommit'\n | 'WaitBeforeCommit'\n | 'ExcludedFromSegment'\n | 'UnsatisfiedInput'\n | 'UnmetRequirement';\n /** 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","onlyUnmetRequirements","every","violation","assertValidSlip","succeed","fail"],"mappings":";AAAA,SAASA,OAAO,QAAQ,gBAAgB;AACxC,SAASC,MAAM,EAAEC,MAAM,QAAQ,SAAS;AAGxC,SAIEC,YAAY,QACP,gBAAgB;AACvB,SAAmCC,SAAS,QAAQ,YAAY;AAmChE,MAAMC,aAAa,CACjBC,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IAAI,CAChBL,sBAAsBlD,cAClB,IAAIgD,sBAAsB;QAAEhD;IAAW,KACvC,IAAI2C,mBAAmB;QAAE3C;IAAW;AAE5C,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-link-resolver.repository.d.ts","sourceRoot":"","sources":["../../src/repository/entity-link-resolver.repository.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"entity-link-resolver.repository.d.ts","sourceRoot":"","sources":["../../src/repository/entity-link-resolver.repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,MAAM,EACX,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EAExB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,OAAO,EAAU,MAAM,QAAQ,CAAC;AAEzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;;AAE7D;;;;;;GAMG;AACH,qBAAa,qBAAsB,SAAQ,0BAGf;CAAG;AAE/B,8EAA8E;AAC9E,MAAM,MAAM,sBAAsB,GAAG,SAAS;IAC5C,iBAAiB,CAAC,MAAM,CAAC;IACzB,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC;CACrC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CACtC,aAAa,EAAE,aAAa,CAAC,sBAAsB,CAAC,GACnD,OAAO,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAwBxC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/repository/entity-link-resolver.repository.ts"],"sourcesContent":["import {\n type Entity,\n type EntityConstructor,\n type EntityLinkResolver,\n Internal,\n
|
|
1
|
+
{"version":3,"sources":["../../src/repository/entity-link-resolver.repository.ts"],"sourcesContent":["import {\n type EntifixFailure,\n type Entity,\n type EntityConstructor,\n type EntityLinkResolver,\n Internal,\n} from '@entifix/core';\nimport { Context, Effect } from 'effect';\n\nimport { EntityRepositoryTag } from './entity.repository.js';\n\n/**\n * DI tag for the {@link EntityLinkResolver} an environment provides so entity\n * links can materialize their targets. The composition root supplies a resolver\n * backed by the appropriate adapters (REST on the web, Mongo on the backend),\n * and use-cases that follow links yield this tag rather than depending on any\n * concrete repository.\n */\nexport class EntityLinkResolverTag extends Context.Service<\n EntityLinkResolverTag,\n EntityLinkResolver\n>()('EntityLinkResolverTag') {}\n\n/** Maps a link target constructor to the repository adapter that loads it. */\nexport type EntityLinkRegistration = readonly [\n EntityConstructor<Entity>,\n Context.Context<EntityRepositoryTag>,\n];\n\n/**\n * Assembles an {@link EntityLinkResolverTag} context from repository adapters\n * that already exist. A repository requires nothing from its environment, so\n * neither does the resolver built from them.\n *\n * It lives here, beside the tag, rather than with React's `useEntityLinkResolver`\n * — which is only a `useMemo` around it — because nothing about it is React.\n * A server component that imported it from the React package would pull that\n * package's whole barrel, hooks included, and Next rejects `useState` reaching\n * a server module. Framework-free code belongs at a framework-free layer.\n */\nexport function createEntityLinkResolver(\n registrations: ReadonlyArray<EntityLinkRegistration>,\n): Context.Context<EntityLinkResolverTag> {\n const repositoryByConstructor = new Map(\n registrations.map(\n ([entityConstructor, repositoryContext]) =>\n [\n entityConstructor,\n Context.get(repositoryContext, EntityRepositoryTag),\n ] as const,\n ),\n );\n\n const resolver: EntityLinkResolver = {\n resolve(entityConstructor, id) {\n const repository = repositoryByConstructor.get(\n entityConstructor as EntityConstructor<Entity>,\n );\n if (!repository) {\n return Effect.fail(new Internal());\n }\n return repository.get(id) as Effect.Effect<never, EntifixFailure>;\n },\n };\n\n return Context.make(EntityLinkResolverTag, resolver);\n}\n"],"names":["Internal","Context","Effect","EntityRepositoryTag","EntityLinkResolverTag","Service","createEntityLinkResolver","registrations","repositoryByConstructor","Map","map","entityConstructor","repositoryContext","get","resolver","resolve","id","repository","fail","make"],"mappings":"AAAA,SAKEA,QAAQ,QACH,gBAAgB;AACvB,SAASC,OAAO,EAAEC,MAAM,QAAQ,SAAS;AAEzC,SAASC,mBAAmB,QAAQ,yBAAyB;AAE7D;;;;;;CAMC,GACD,OAAO,MAAMC,8BAA8BH,QAAQI,OAAO,GAGtD;AAA0B;AAQ9B;;;;;;;;;;CAUC,GACD,OAAO,SAASC,yBACdC,aAAoD;IAEpD,MAAMC,0BAA0B,IAAIC,IAClCF,cAAcG,GAAG,CACf,CAAC,CAACC,mBAAmBC,kBAAkB,GACrC;YACED;YACAV,QAAQY,GAAG,CAACD,mBAAmBT;SAChC;IAIP,MAAMW,WAA+B;QACnCC,SAAQJ,iBAAiB,EAAEK,EAAE;YAC3B,MAAMC,aAAaT,wBAAwBK,GAAG,CAC5CF;YAEF,IAAI,CAACM,YAAY;gBACf,OAAOf,OAAOgB,IAAI,CAAC,IAAIlB;YACzB;YACA,OAAOiB,WAAWJ,GAAG,CAACG;QACxB;IACF;IAEA,OAAOf,QAAQkB,IAAI,CAACf,uBAAuBU;AAC7C"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Entity, EntityId, EntityLoadRequest, EntityPage
|
|
1
|
+
import type { EntifixFailure, Entity, EntityId, EntityLoadRequest, EntityPage } from '@entifix/core';
|
|
2
2
|
import { Context } from 'effect';
|
|
3
3
|
import { Effect } from 'effect/Effect';
|
|
4
4
|
/**
|
|
@@ -7,7 +7,7 @@ import { Effect } from 'effect/Effect';
|
|
|
7
7
|
* the old class tree, or a categorised failure — an `InvalidEnvelope` from a
|
|
8
8
|
* transport, a `DuplicateKey` from a store.
|
|
9
9
|
*/
|
|
10
|
-
export type RepositoryFailure =
|
|
10
|
+
export type RepositoryFailure = EntifixFailure;
|
|
11
11
|
/**
|
|
12
12
|
* Where a use case reads and writes one entity's records.
|
|
13
13
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.repository.d.ts","sourceRoot":"","sources":["../../src/repository/entity.repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EACN,QAAQ,EACR,iBAAiB,EACjB,UAAU,
|
|
1
|
+
{"version":3,"file":"entity.repository.d.ts","sourceRoot":"","sources":["../../src/repository/entity.repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,MAAM,EACN,QAAQ,EACR,iBAAiB,EACjB,UAAU,EACX,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,cAAc,CAAC;AAE/C;;;;;;;;;GASG;AACH,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,OAAO,SAAS,MAAM,EAAE,EAAE,EAAE,QAAQ,GAAG,MAAM,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;IAC9E,IAAI,CAAC,OAAO,SAAS,MAAM,EACzB,OAAO,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAClC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAC;IAClD,IAAI,CAAC,OAAO,SAAS,MAAM,EACzB,MAAM,EAAE,OAAO,GACd,MAAM,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;IACtC,MAAM,CAAC,OAAO,SAAS,MAAM,EAC3B,UAAU,EAAE,QAAQ,GAAG,OAAO,GAC7B,MAAM,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;CACpC;;AAED,qBAAa,mBAAoB,SAAQ,wBAGf;CAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/repository/entity.repository.ts"],"sourcesContent":["import type {\n Entity,\n EntityId,\n EntityLoadRequest,\n EntityPage,\n
|
|
1
|
+
{"version":3,"sources":["../../src/repository/entity.repository.ts"],"sourcesContent":["import type {\n EntifixFailure,\n Entity,\n EntityId,\n EntityLoadRequest,\n EntityPage,\n} from '@entifix/core';\nimport { Context } from 'effect';\nimport { Effect } from 'effect/Effect';\n\n/**\n * What a repository fails with while the adapters move to typed failures\n * ([ADR 0013](../../../../../docs/adr/0013-failures-are-typed-values-decided-at-the-shell.md)):\n * the old class tree, or a categorised failure — an `InvalidEnvelope` from a\n * transport, a `DuplicateKey` from a store.\n */\nexport type RepositoryFailure = EntifixFailure;\n\n/**\n * Where a use case reads and writes one entity's records.\n *\n * ⚠️ **Every method requires nothing from its environment.** An adapter that\n * needs something to do its job — a REST client's base URL, a database handle —\n * binds it when the adapter is built, so the port says only what every adapter\n * has in common. A requirement here would be one adapter's mechanism leaked into\n * every use case, and every caller of a static or in-memory adapter would have\n * to provide a value it never reads.\n */\nexport interface EntityRepository {\n get<TEntity extends Entity>(id: EntityId): Effect<TEntity, RepositoryFailure>;\n load<TEntity extends Entity>(\n request: EntityLoadRequest<TEntity>,\n ): Effect<EntityPage<TEntity>, RepositoryFailure>;\n save<TEntity extends Entity>(\n entity: TEntity,\n ): Effect<TEntity, RepositoryFailure>;\n delete<TEntity extends Entity>(\n entityOrId: EntityId | TEntity,\n ): Effect<void, RepositoryFailure>;\n}\n\nexport class EntityRepositoryTag extends Context.Service<\n EntityRepositoryTag,\n EntityRepository\n>()('EntityRepositoryTag') {}\n"],"names":["Context","EntityRepositoryTag","Service"],"mappings":"AAOA,SAASA,OAAO,QAAQ,SAAS;AAkCjC,OAAO,MAAMC,4BAA4BD,QAAQE,OAAO,GAGpD;AAAwB"}
|
|
@@ -9,5 +9,5 @@ import { EntityIdTag } from '../../repository/entity-mixins.repository.js';
|
|
|
9
9
|
* the only shape a caller ever has at the point of deletion (a table row, a
|
|
10
10
|
* route param), so that is what this exposes.
|
|
11
11
|
*/
|
|
12
|
-
export declare function deleteUCFactory<TEntity extends Entity>(): Effect.Effect<void, import("
|
|
12
|
+
export declare function deleteUCFactory<TEntity extends Entity>(): Effect.Effect<void, import("../../index.js").RepositoryFailure, EntityRepositoryTag | EntityIdTag>;
|
|
13
13
|
//# sourceMappingURL=delete.uc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete.uc.d.ts","sourceRoot":"","sources":["../../../src/use-case/delete/delete.uc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,8CAA8C,CAAC;AAE3E;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,SAAS,MAAM,
|
|
1
|
+
{"version":3,"file":"delete.uc.d.ts","sourceRoot":"","sources":["../../../src/use-case/delete/delete.uc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,8CAA8C,CAAC;AAE3E;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,SAAS,MAAM,wGAOrD"}
|
|
@@ -8,5 +8,5 @@ import { EntityFacetCounterTag } from '../../repository/entity-facet-counter.js'
|
|
|
8
8
|
* entity's type, and the cast a load request needs to cross one is exactly
|
|
9
9
|
* what this use case has no reason to inherit.
|
|
10
10
|
*/
|
|
11
|
-
export declare const facetCountsUCFactory: <TEntity extends Entity>(queries: readonly EntityFacetQuery<TEntity>[]) => Effect.Effect<Readonly<Record<string, readonly import("@entifix/core").EntityFacetValue[]>>, import("
|
|
11
|
+
export declare const facetCountsUCFactory: <TEntity extends Entity>(queries: readonly EntityFacetQuery<TEntity>[]) => Effect.Effect<Readonly<Record<string, readonly import("@entifix/core").EntityFacetValue[]>>, import("../../index.js").RepositoryFailure, EntityFacetCounterTag>;
|
|
12
12
|
//# sourceMappingURL=facet-counts.uc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"facet-counts.uc.d.ts","sourceRoot":"","sources":["../../../src/use-case/facets/facet-counts.uc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AAEjF;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAAI,OAAO,SAAS,MAAM,EACzD,SAAS,SAAS,gBAAgB,CAAC,OAAO,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"facet-counts.uc.d.ts","sourceRoot":"","sources":["../../../src/use-case/facets/facet-counts.uc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AAEjF;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAAI,OAAO,SAAS,MAAM,EACzD,SAAS,SAAS,gBAAgB,CAAC,OAAO,CAAC,EAAE,oKAK3C,CAAC"}
|
|
@@ -8,5 +8,5 @@ import { EntityIdTag } from '../../repository/entity-mixins.repository.js';
|
|
|
8
8
|
* The factory's type parameter is what makes the result usable without a cast
|
|
9
9
|
* at the call site — {@link EntityIdTag} carries no entity type of its own.
|
|
10
10
|
*/
|
|
11
|
-
export declare function getUCFactory<TEntity extends Entity>(): Effect.Effect<TEntity, import("
|
|
11
|
+
export declare function getUCFactory<TEntity extends Entity>(): Effect.Effect<TEntity, import("../../index.js").RepositoryFailure, EntityRepositoryTag | EntityIdTag>;
|
|
12
12
|
//# sourceMappingURL=get.uc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get.uc.d.ts","sourceRoot":"","sources":["../../../src/use-case/get/get.uc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,8CAA8C,CAAC;AAE3E;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,SAAS,MAAM,
|
|
1
|
+
{"version":3,"file":"get.uc.d.ts","sourceRoot":"","sources":["../../../src/use-case/get/get.uc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,8CAA8C,CAAC;AAE3E;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,SAAS,MAAM,2GASlD"}
|
|
@@ -15,5 +15,5 @@ export declare const LOAD_ALL_PAGE_SIZE = 100;
|
|
|
15
15
|
* as large as can be counted works against an in-memory source, but a real
|
|
16
16
|
* adapter would hand that size to its database.
|
|
17
17
|
*/
|
|
18
|
-
export declare function loadAllUCFactory<TEntity extends Entity>(pageSize?: number): Effect.Effect<TEntity[], import("
|
|
18
|
+
export declare function loadAllUCFactory<TEntity extends Entity>(pageSize?: number): Effect.Effect<TEntity[], import("../../index.js").RepositoryFailure, EntityRepositoryTag | EntityLoadRequestTag>;
|
|
19
19
|
//# sourceMappingURL=load-all.uc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-all.uc.d.ts","sourceRoot":"","sources":["../../../src/use-case/load/load-all.uc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,8CAA8C,CAAC;AAEpF,4EAA4E;AAC5E,MAAM,MAAM,cAAc,CAAC,OAAO,SAAS,MAAM,IAAI,IAAI,CACvD,iBAAiB,CAAC,OAAO,CAAC,EAC1B,MAAM,GAAG,UAAU,CACpB,CAAC;AAEF,6EAA6E;AAC7E,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAEtC;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,MAAM,EACrD,QAAQ,GAAE,MAA2B,
|
|
1
|
+
{"version":3,"file":"load-all.uc.d.ts","sourceRoot":"","sources":["../../../src/use-case/load/load-all.uc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,8CAA8C,CAAC;AAEpF,4EAA4E;AAC5E,MAAM,MAAM,cAAc,CAAC,OAAO,SAAS,MAAM,IAAI,IAAI,CACvD,iBAAiB,CAAC,OAAO,CAAC,EAC1B,MAAM,GAAG,UAAU,CACpB,CAAC;AAEF,6EAA6E;AAC7E,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAEtC;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,MAAM,EACrD,QAAQ,GAAE,MAA2B,oHAuBtC"}
|
|
@@ -2,5 +2,5 @@ import { Entity } from '@entifix/core';
|
|
|
2
2
|
import { Effect } from 'effect';
|
|
3
3
|
import { EntityRepositoryTag } from '../../repository/entity.repository.js';
|
|
4
4
|
import { EntityLoadRequestTag } from '../../repository/entity-mixins.repository.js';
|
|
5
|
-
export declare function loadUCFactory<TEntity extends Entity>(): Effect.Effect<import("@entifix/core").EntityPage<TEntity>, import("
|
|
5
|
+
export declare function loadUCFactory<TEntity extends Entity>(): Effect.Effect<import("@entifix/core").EntityPage<TEntity>, import("../../index.js").RepositoryFailure, EntityRepositoryTag | EntityLoadRequestTag>;
|
|
6
6
|
//# sourceMappingURL=load.uc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load.uc.d.ts","sourceRoot":"","sources":["../../../src/use-case/load/load.uc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAqB,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,8CAA8C,CAAC;AAEpF,wBAAgB,aAAa,CAAC,OAAO,SAAS,MAAM,
|
|
1
|
+
{"version":3,"file":"load.uc.d.ts","sourceRoot":"","sources":["../../../src/use-case/load/load.uc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAqB,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,8CAA8C,CAAC;AAEpF,wBAAgB,aAAa,CAAC,OAAO,SAAS,MAAM,wJAenD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type EntifixFailure, type Entity } from '@entifix/core';
|
|
2
2
|
import { Effect } from 'effect';
|
|
3
3
|
import { EntityLinkResolverTag } from '../../repository/entity-link-resolver.repository.js';
|
|
4
4
|
/** The members of an entity that link to other records. */
|
|
@@ -16,5 +16,5 @@ export type LinkMember<TEntity> = {
|
|
|
16
16
|
* each through `targetOf`/`targetsOf`, with no `id → record` map built by
|
|
17
17
|
* hand. Every link resolves concurrently; one that fails fails the whole.
|
|
18
18
|
*/
|
|
19
|
-
export declare function resolveLinksUCFactory<TEntity extends Entity>(records: readonly TEntity[], members: readonly LinkMember<TEntity>[]): Effect.Effect<TEntity[],
|
|
19
|
+
export declare function resolveLinksUCFactory<TEntity extends Entity>(records: readonly TEntity[], members: readonly LinkMember<TEntity>[]): Effect.Effect<TEntity[], EntifixFailure<string, string, import("@entifix/core").FailureCategory>, EntityLinkResolverTag>;
|
|
20
20
|
//# sourceMappingURL=resolve-links.uc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-links.uc.d.ts","sourceRoot":"","sources":["../../../src/use-case/load/resolve-links.uc.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,
|
|
1
|
+
{"version":3,"file":"resolve-links.uc.d.ts","sourceRoot":"","sources":["../../../src/use-case/load/resolve-links.uc.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,MAAM,EAEZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,qBAAqB,EAAE,MAAM,qDAAqD,CAAC;AAE5F,2DAA2D;AAC3D,MAAM,MAAM,UAAU,CAAC,OAAO,IAAI;KAC/B,IAAI,IAAI,MAAM,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS;QACtD,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAC;QACpC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;KAC5B,GACG,IAAI,GACJ,KAAK;CACV,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC;AAM1B;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,MAAM,EAC1D,OAAO,EAAE,SAAS,OAAO,EAAE,EAC3B,OAAO,EAAE,SAAS,UAAU,CAAC,OAAO,CAAC,EAAE,4HAexC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/use-case/load/resolve-links.uc.ts"],"sourcesContent":["import {\n type
|
|
1
|
+
{"version":3,"sources":["../../../src/use-case/load/resolve-links.uc.ts"],"sourcesContent":["import {\n type EntifixFailure,\n type Entity,\n type EntityLinkResolver,\n} from '@entifix/core';\nimport { Effect } from 'effect';\n\nimport { EntityLinkResolverTag } from '../../repository/entity-link-resolver.repository.js';\n\n/** The members of an entity that link to other records. */\nexport type LinkMember<TEntity> = {\n [TKey in keyof TEntity & string]: TEntity[TKey] extends {\n readonly entityConstructor: unknown;\n readonly isLoaded: boolean;\n }\n ? TKey\n : never;\n}[keyof TEntity & string];\n\ntype ResolvableLink = {\n resolve(resolver: EntityLinkResolver): Effect.Effect<unknown, EntifixFailure>;\n};\n\n/**\n * Resolves `members` of every record, in place, through the\n * `EntityLinkResolverTag` in context, and hands the records back.\n *\n * A record read with its linked records (a post with its tags) then reads\n * each through `targetOf`/`targetsOf`, with no `id → record` map built by\n * hand. Every link resolves concurrently; one that fails fails the whole.\n */\nexport function resolveLinksUCFactory<TEntity extends Entity>(\n records: readonly TEntity[],\n members: readonly LinkMember<TEntity>[],\n) {\n return Effect.gen(function* () {\n const resolver = yield* EntityLinkResolverTag;\n yield* Effect.forEach(\n records.flatMap(record =>\n members.map(member =>\n (record[member] as ResolvableLink).resolve(resolver),\n ),\n ),\n resolved => resolved,\n { concurrency: 'unbounded', discard: true },\n );\n return [...records];\n });\n}\n"],"names":["Effect","EntityLinkResolverTag","resolveLinksUCFactory","records","members","gen","resolver","forEach","flatMap","record","map","member","resolve","resolved","concurrency","discard"],"mappings":"AAKA,SAASA,MAAM,QAAQ,SAAS;AAEhC,SAASC,qBAAqB,QAAQ,sDAAsD;AAgB5F;;;;;;;CAOC,GACD,OAAO,SAASC,sBACdC,OAA2B,EAC3BC,OAAuC;IAEvC,OAAOJ,OAAOK,GAAG,CAAC;QAChB,MAAMC,WAAW,OAAOL;QACxB,OAAOD,OAAOO,OAAO,CACnBJ,QAAQK,OAAO,CAACC,CAAAA,SACdL,QAAQM,GAAG,CAACC,CAAAA,SACV,AAACF,MAAM,CAACE,OAAO,CAAoBC,OAAO,CAACN,aAG/CO,CAAAA,WAAYA,UACZ;YAAEC,aAAa;YAAaC,SAAS;QAAK;QAE5C,OAAO;eAAIZ;SAAQ;IACrB;AACF"}
|
|
@@ -12,5 +12,5 @@ import { EntityTag } from '../../repository/entity-mixins.repository.js';
|
|
|
12
12
|
* taking them as arguments, so the same use-case saves over REST on the web and
|
|
13
13
|
* over Mongo on a backend.
|
|
14
14
|
*/
|
|
15
|
-
export declare function saveUCFactory<TEntity extends Entity>(): Effect.Effect<TEntity, [Effect.Effect<import("../../index.js").EntityRepository, never, EntityRepositoryTag> | Effect.Effect<Entity, never, EntityTag> | Effect.Effect<TEntity, import("
|
|
15
|
+
export declare function saveUCFactory<TEntity extends Entity>(): Effect.Effect<TEntity, [Effect.Effect<import("../../index.js").EntityRepository, never, EntityRepositoryTag> | Effect.Effect<Entity, never, EntityTag> | Effect.Effect<TEntity, import("../../index.js").RepositoryFailure, never>] extends [Effect.Effect<infer _A, infer E, infer _R>] ? E : never, [Effect.Effect<import("../../index.js").EntityRepository, never, EntityRepositoryTag> | Effect.Effect<Entity, never, EntityTag> | Effect.Effect<TEntity, import("../../index.js").RepositoryFailure, never>] extends [Effect.Effect<infer _A_1, infer _E, infer R>] ? R : never>;
|
|
16
16
|
//# sourceMappingURL=save.uc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"save.uc.d.ts","sourceRoot":"","sources":["../../../src/use-case/save/save.uc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,8CAA8C,CAAC;AAEzE;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,OAAO,SAAS,MAAM,
|
|
1
|
+
{"version":3,"file":"save.uc.d.ts","sourceRoot":"","sources":["../../../src/use-case/save/save.uc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,8CAA8C,CAAC;AAEzE;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,OAAO,SAAS,MAAM,4jBAWnD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entifix/business",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.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,12 +66,12 @@
|
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
68
|
"@swc/helpers": "0.5.23",
|
|
69
|
-
"@entifix/core": "0.
|
|
69
|
+
"@entifix/core": "0.15.0"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
|
-
"effect": "^4.0.
|
|
72
|
+
"effect": "^4.0.7"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"effect": "4.0.
|
|
75
|
+
"effect": "4.0.7"
|
|
76
76
|
}
|
|
77
77
|
}
|