@entifix/business 0.10.2 → 0.11.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 +100 -0
- package/dist/compose/compose.d.ts.map +1 -0
- package/dist/compose/compose.js +143 -0
- package/dist/compose/compose.js.map +1 -0
- package/dist/compose/index.d.ts +2 -0
- package/dist/compose/index.d.ts.map +1 -0
- package/dist/compose/index.js +3 -0
- package/dist/compose/index.js.map +1 -0
- package/dist/flow/catalog.d.ts +51 -0
- package/dist/flow/catalog.d.ts.map +1 -0
- package/dist/flow/catalog.js +63 -0
- package/dist/flow/catalog.js.map +1 -0
- package/dist/flow/fragment.d.ts +105 -0
- package/dist/flow/fragment.d.ts.map +1 -0
- package/dist/flow/fragment.js +77 -0
- package/dist/flow/fragment.js.map +1 -0
- package/dist/flow/index.d.ts +5 -0
- package/dist/flow/index.d.ts.map +1 -0
- package/dist/flow/index.js +6 -0
- package/dist/flow/index.js.map +1 -0
- package/dist/flow/slip.d.ts +126 -0
- package/dist/flow/slip.d.ts.map +1 -0
- package/dist/flow/slip.js +68 -0
- package/dist/flow/slip.js.map +1 -0
- package/dist/flow/validate.d.ts +49 -0
- package/dist/flow/validate.d.ts.map +1 -0
- package/dist/flow/validate.js +126 -0
- package/dist/flow/validate.js.map +1 -0
- package/dist/idempotency/idempotency-store.d.ts +53 -0
- package/dist/idempotency/idempotency-store.d.ts.map +1 -0
- package/dist/idempotency/idempotency-store.js +5 -0
- package/dist/idempotency/idempotency-store.js.map +1 -0
- package/dist/idempotency/index.d.ts +2 -0
- package/dist/idempotency/index.d.ts.map +1 -0
- package/dist/idempotency/index.js +3 -0
- package/dist/idempotency/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/resolve/index.d.ts +3 -0
- package/dist/resolve/index.d.ts.map +1 -0
- package/dist/resolve/index.js +4 -0
- package/dist/resolve/index.js.map +1 -0
- package/dist/resolve/resolve.d.ts +70 -0
- package/dist/resolve/resolve.d.ts.map +1 -0
- package/dist/resolve/resolve.js +69 -0
- package/dist/resolve/resolve.js.map +1 -0
- package/dist/resolve/verified-context.d.ts +45 -0
- package/dist/resolve/verified-context.d.ts.map +1 -0
- package/dist/resolve/verified-context.js +8 -0
- package/dist/resolve/verified-context.js.map +1 -0
- package/dist/verified/index.d.ts +10 -0
- package/dist/verified/index.d.ts.map +1 -0
- package/dist/verified/index.js +10 -0
- package/dist/verified/index.js.map +1 -0
- package/package.json +17 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/flow/fragment.ts"],"sourcesContent":["import { Schema } from 'effect';\n\n/**\n * How a step behaves when a later one fails\n * ([ADR 0015](../../../../../docs/adr/0015-composed-flows-and-use-case-resolution.md)).\n *\n * - `compensatable` — can be undone, so it sits before the commit point;\n * - `pivot` — the point of no return, at most one per slip;\n * - `retriable` — after the commit point, retried until it succeeds;\n * - `wait` — a durable wait for a signal, after the commit point.\n */\nexport type FragmentKind = 'compensatable' | 'pivot' | 'retriable' | 'wait';\n\n/** How many calls one step makes: one, one per vendor segment, or one per line. */\nexport type FragmentCardinality = 'one' | 'perVendor' | 'perLine';\n\n/**\n * The countermeasure a step relies on for the isolation a saga lacks — what\n * keeps a concurrent flow from seeing, or undoing, its intermediate state.\n */\nexport type FragmentIsolation =\n | 'commutative'\n | 'semanticLock'\n | 'reRead'\n | 'pessimisticView'\n | 'versionFile'\n | 'none';\n\n/** One HTTP call a step makes on its participant: the public path, never a template. */\nexport interface FragmentCall {\n readonly method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n readonly path: `/${string}`;\n}\n\n/** The facts of a verified context a step may require. */\nexport interface FragmentRequirements {\n readonly entitlements?: readonly string[];\n readonly roles?: readonly string[];\n readonly partyRoles?: readonly string[];\n readonly channels?: readonly string[];\n}\n\n/** A step's contract, as Schemas: what it is given, answers, and refuses with. */\nexport interface FragmentContract<I, O, F> {\n readonly input: Schema.Codec<I, unknown>;\n readonly output: Schema.Codec<O, unknown>;\n readonly failure: Schema.Codec<F, unknown>;\n}\n\n/** Keys a step reads from earlier steps, or makes available to later ones. */\nexport type FragmentKeys = Readonly<\n Record<string, Schema.Codec<unknown, unknown>>\n>;\n\n/**\n * One step a module contributes to a flow, declared beside the use case it\n * calls. Versioned (`id@version`) and typed, so a contract change without a\n * version bump is visible to a catalog snapshot before it reaches a running\n * flow.\n */\nexport interface FragmentDescriptor<I = unknown, O = unknown, F = unknown> {\n readonly id: string;\n readonly version: number;\n /** The module that owns the step — its domain. */\n readonly module: string;\n readonly kind: FragmentKind;\n /** The service the step calls. Absent only on a marker such as `flow.commit@1`. */\n readonly participant?: string;\n readonly call?: FragmentCall;\n /** Required on a compensatable step unless it is `readOnly`; forbidden otherwise. */\n readonly compensation?: FragmentCall;\n /** A compensatable step that changes nothing, and so has nothing to undo. */\n readonly readOnly?: boolean;\n readonly contract: FragmentContract<I, O, F>;\n readonly requires?: FragmentRequirements;\n readonly consumes?: FragmentKeys;\n readonly provides?: FragmentKeys;\n /** A step whose effect no compensation can reverse — money moved, goods shipped. */\n readonly irreversible?: boolean;\n readonly isolation?: FragmentIsolation;\n readonly cardinality: FragmentCardinality;\n /**\n * Segments this step may not run in, by tag. A card capture excludes the\n * cash-on-delivery segment; the framework names neither.\n */\n readonly excludedFrom?: Readonly<Record<string, readonly string[]>>;\n}\n\n/** The pinned reference a slip carries: `stock.reserve@1`. */\nexport const fragmentRef = (fragment: {\n readonly id: string;\n readonly version: number;\n}): string => `${fragment.id}@${String(fragment.version)}`;\n\n/** `domain.verb`, lower kebab, at least two segments. */\nconst FRAGMENT_ID = /^[a-z][a-z0-9-]*(\\.[a-z][a-z0-9-]*)+$/;\n\nconst shapeProblems = (fragment: FragmentDescriptor): string[] => {\n const problems: string[] = [];\n if (!FRAGMENT_ID.test(fragment.id))\n problems.push(`its id must be 'domain.verb' in lower kebab case`);\n if (!Number.isInteger(fragment.version) || fragment.version < 1)\n problems.push('its version must be a positive integer');\n const marker =\n fragment.participant === undefined && fragment.call === undefined;\n if (\n !marker &&\n (fragment.participant === undefined || fragment.call === undefined)\n )\n problems.push('it names a participant and a call together, or neither');\n if (marker && fragment.kind !== 'pivot')\n problems.push(\n 'only a pivot may be a marker with no participant and no call',\n );\n if (fragment.kind === 'compensatable') {\n if (fragment.compensation === undefined && fragment.readOnly !== true)\n problems.push(\n 'a compensatable step declares its compensation, or is readOnly',\n );\n } else if (fragment.compensation !== undefined) {\n problems.push(`a ${fragment.kind} step cannot declare a compensation`);\n }\n if (fragment.irreversible === true && fragment.kind === 'compensatable')\n problems.push('a compensatable step cannot be irreversible');\n return problems;\n};\n\n/**\n * Declares a fragment, checking its shape at module load: a malformed\n * descriptor is a programming error and fails the boot, not the first flow\n * that reaches it. What depends on *other* fragments — order, inputs, the\n * commit point — is the validator's, over a whole slip.\n */\nexport const defineFragment = <I, O, F>(\n fragment: FragmentDescriptor<I, O, F>,\n): FragmentDescriptor<I, O, F> => {\n const problems = shapeProblems(fragment as FragmentDescriptor);\n if (problems.length > 0)\n throw new Error(\n `fragment '${fragment.id}@${String(fragment.version)}' is malformed: ${problems.join('; ')}`,\n );\n return fragment;\n};\n\n/**\n * The commit point of a flow that has no real pivot: a pivot with no\n * participant and no call. A cash-on-delivery checkout takes no money, and\n * still needs a line past which its stock conversions are retried rather than\n * compensated.\n */\nexport const flowCommit = defineFragment({\n id: 'flow.commit',\n version: 1,\n module: 'flow',\n kind: 'pivot',\n cardinality: 'one',\n contract: {\n input: Schema.Unknown,\n output: Schema.Unknown,\n failure: Schema.Never,\n },\n});\n\n/** A stable 53-bit hash of a string, as hex — enough to see that a contract moved. */\nconst hash = (text: string): string => {\n let h1 = 0xdeadbeef;\n let h2 = 0x41c6ce57;\n for (let index = 0; index < text.length; index += 1) {\n const code = text.charCodeAt(index);\n h1 = Math.imul(h1 ^ code, 2654435761);\n h2 = Math.imul(h2 ^ code, 1597334677);\n }\n h1 =\n Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^\n Math.imul(h2 ^ (h2 >>> 13), 3266489909);\n h2 =\n Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^\n Math.imul(h1 ^ (h1 >>> 13), 3266489909);\n return (4294967296 * (2097151 & h2) + (h1 >>> 0))\n .toString(16)\n .padStart(14, '0');\n};\n\n/** The JSON Schema of a codec, as a plain object. */\nexport const jsonSchemaOf = (schema: Schema.Codec<unknown, unknown>): unknown =>\n Schema.toJsonSchemaDocument(schema);\n\n/** Consumed or provided keys as JSON Schema, ordered by key. */\nexport const keysDocument = (keys: FragmentKeys | undefined) =>\n Object.fromEntries(\n Object.entries(keys ?? {})\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([key, schema]) => [key, jsonSchemaOf(schema)]),\n );\n\n/**\n * A fingerprint of what a fragment promises: its contract and the keys it\n * consumes and provides. It changes when any of those change and on nothing\n * else, so renaming a module or rewording a description never looks like a\n * contract change — and a contract change without a version bump fails the\n * catalog snapshot.\n */\nexport const fragmentFingerprint = (fragment: FragmentDescriptor): string =>\n hash(\n JSON.stringify({\n input: jsonSchemaOf(\n fragment.contract.input as Schema.Codec<unknown, unknown>,\n ),\n output: jsonSchemaOf(\n fragment.contract.output as Schema.Codec<unknown, unknown>,\n ),\n failure: jsonSchemaOf(\n fragment.contract.failure as Schema.Codec<unknown, unknown>,\n ),\n consumes: keysDocument(fragment.consumes),\n provides: keysDocument(fragment.provides),\n }),\n );\n"],"names":["Schema","fragmentRef","fragment","id","String","version","FRAGMENT_ID","shapeProblems","problems","test","push","Number","isInteger","marker","participant","undefined","call","kind","compensation","readOnly","irreversible","defineFragment","length","Error","join","flowCommit","module","cardinality","contract","input","Unknown","output","failure","Never","hash","text","h1","h2","index","code","charCodeAt","Math","imul","toString","padStart","jsonSchemaOf","schema","toJsonSchemaDocument","keysDocument","keys","Object","fromEntries","entries","sort","a","b","localeCompare","map","key","fragmentFingerpr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,GAAKD,EAAEE,aAAa,CAACD,IACnCE,GAAG,CAAC,CAAC,CAACC,KAAKZ,OAAO,GAAK;YAACY;YAAKb,aAAaC;SAAQ,GACrD;AAEJ;;;;;;CAMC,GACD,OAAO,MAAMa,sBAAsB,CAACzD,WAClCgC,KACE0B,KAAKC,SAAS,CAAC;QACbhC,OAAOgB,aACL3C,SAAS0B,QAAQ,CAACC,KAAK;QAEzBE,QAAQc,aACN3C,SAAS0B,QAAQ,CAACG,MAAM;QAE1BC,SAASa,aACP3C,SAAS0B,QAAQ,CAACI,OAAO;QAE3B8B,UAAUd,aAAa9C,SAAS4D,QAAQ;QACxCC,UAAUf,aAAa9C,SAAS6D,QAAQ;IAC1C,IACA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/flow/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/flow/index.ts"],"sourcesContent":["export * from './catalog.js';\nexport * from './fragment.js';\nexport * from './slip.js';\nexport * from './validate.js';\n"],"names":[],"mappings":"AAAA,cAAc,eAAe;AAC7B,cAAc,gBAAgB;AAC9B,cAAc,YAAY;AAC1B,cAAc,gBAAgB"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { ProtocolFailure } from '@entifix/core';
|
|
2
|
+
import { Effect, Schema } from 'effect';
|
|
3
|
+
/**
|
|
4
|
+
* The grammar version a slip is written in. An interpreter branches on it, so a
|
|
5
|
+
* flow that started under one grammar finishes under that grammar even after
|
|
6
|
+
* the next one ships.
|
|
7
|
+
*/
|
|
8
|
+
export declare const SLIP_VERSION: 1;
|
|
9
|
+
/** Tags that place a step in a segment of the flow: whose lines, which payment. */
|
|
10
|
+
export declare const SlipSegment: Schema.Struct<{
|
|
11
|
+
readonly vendor: Schema.optionalKey<Schema.String>;
|
|
12
|
+
readonly paymentMethod: Schema.optionalKey<Schema.String>;
|
|
13
|
+
}>;
|
|
14
|
+
export type SlipSegment = typeof SlipSegment.Type;
|
|
15
|
+
/** One pinned step: a fragment reference and everything resolved for it. */
|
|
16
|
+
export declare const SlipStep: Schema.Struct<{
|
|
17
|
+
/** `id@version`, pinned when the slip was composed. */
|
|
18
|
+
readonly ref: Schema.String;
|
|
19
|
+
/** Unique within the slip; what an Activity is named after (`segment:step`). */
|
|
20
|
+
readonly step: Schema.String;
|
|
21
|
+
readonly cardinality: Schema.Literals<readonly ["one", "perVendor", "perLine"]>;
|
|
22
|
+
readonly segment: Schema.optionalKey<Schema.Struct<{
|
|
23
|
+
readonly vendor: Schema.optionalKey<Schema.String>;
|
|
24
|
+
readonly paymentMethod: Schema.optionalKey<Schema.String>;
|
|
25
|
+
}>>;
|
|
26
|
+
readonly participant: Schema.optionalKey<Schema.String>;
|
|
27
|
+
readonly call: Schema.optionalKey<Schema.Struct<{
|
|
28
|
+
readonly method: Schema.Literals<readonly ["GET", "POST", "PUT", "PATCH", "DELETE"]>;
|
|
29
|
+
readonly path: Schema.String;
|
|
30
|
+
}>>;
|
|
31
|
+
readonly compensation: Schema.optionalKey<Schema.Struct<{
|
|
32
|
+
readonly method: Schema.Literals<readonly ["GET", "POST", "PUT", "PATCH", "DELETE"]>;
|
|
33
|
+
readonly path: Schema.String;
|
|
34
|
+
}>>;
|
|
35
|
+
/** Configuration pinned at composition — a hold's expiry, a limit. */
|
|
36
|
+
readonly parameters: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
37
|
+
}>;
|
|
38
|
+
export type SlipStep = typeof SlipStep.Type;
|
|
39
|
+
export declare const SlipStage: Schema.Struct<{
|
|
40
|
+
readonly name: Schema.String;
|
|
41
|
+
readonly steps: Schema.$Array<Schema.Struct<{
|
|
42
|
+
/** `id@version`, pinned when the slip was composed. */
|
|
43
|
+
readonly ref: Schema.String;
|
|
44
|
+
/** Unique within the slip; what an Activity is named after (`segment:step`). */
|
|
45
|
+
readonly step: Schema.String;
|
|
46
|
+
readonly cardinality: Schema.Literals<readonly ["one", "perVendor", "perLine"]>;
|
|
47
|
+
readonly segment: Schema.optionalKey<Schema.Struct<{
|
|
48
|
+
readonly vendor: Schema.optionalKey<Schema.String>;
|
|
49
|
+
readonly paymentMethod: Schema.optionalKey<Schema.String>;
|
|
50
|
+
}>>;
|
|
51
|
+
readonly participant: Schema.optionalKey<Schema.String>;
|
|
52
|
+
readonly call: Schema.optionalKey<Schema.Struct<{
|
|
53
|
+
readonly method: Schema.Literals<readonly ["GET", "POST", "PUT", "PATCH", "DELETE"]>;
|
|
54
|
+
readonly path: Schema.String;
|
|
55
|
+
}>>;
|
|
56
|
+
readonly compensation: Schema.optionalKey<Schema.Struct<{
|
|
57
|
+
readonly method: Schema.Literals<readonly ["GET", "POST", "PUT", "PATCH", "DELETE"]>;
|
|
58
|
+
readonly path: Schema.String;
|
|
59
|
+
}>>;
|
|
60
|
+
/** Configuration pinned at composition — a hold's expiry, a limit. */
|
|
61
|
+
readonly parameters: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
62
|
+
}>>;
|
|
63
|
+
}>;
|
|
64
|
+
export type SlipStage = typeof SlipStage.Type;
|
|
65
|
+
/** Which variant each use case resolved to, and by which rule. */
|
|
66
|
+
export declare const SlipResolution: Schema.Struct<{
|
|
67
|
+
readonly useCase: Schema.String;
|
|
68
|
+
readonly variant: Schema.String;
|
|
69
|
+
readonly rule: Schema.Number;
|
|
70
|
+
}>;
|
|
71
|
+
export type SlipResolution = typeof SlipResolution.Type;
|
|
72
|
+
/**
|
|
73
|
+
* A routing slip: ordered stages of pinned steps, composed once at start and
|
|
74
|
+
* stored as the flow's payload. Changing a recipe or a fragment never changes a
|
|
75
|
+
* flow that has already started.
|
|
76
|
+
*/
|
|
77
|
+
export declare const Slip: Schema.Struct<{
|
|
78
|
+
readonly slipVersion: Schema.Literal<1>;
|
|
79
|
+
readonly flowId: Schema.String;
|
|
80
|
+
readonly recipe: Schema.String;
|
|
81
|
+
/** The recipe demands a commit point even with no retriable step (a checkout). */
|
|
82
|
+
readonly requiresCommitPoint: Schema.optionalKey<Schema.Boolean>;
|
|
83
|
+
readonly stages: Schema.$Array<Schema.Struct<{
|
|
84
|
+
readonly name: Schema.String;
|
|
85
|
+
readonly steps: Schema.$Array<Schema.Struct<{
|
|
86
|
+
/** `id@version`, pinned when the slip was composed. */
|
|
87
|
+
readonly ref: Schema.String;
|
|
88
|
+
/** Unique within the slip; what an Activity is named after (`segment:step`). */
|
|
89
|
+
readonly step: Schema.String;
|
|
90
|
+
readonly cardinality: Schema.Literals<readonly ["one", "perVendor", "perLine"]>;
|
|
91
|
+
readonly segment: Schema.optionalKey<Schema.Struct<{
|
|
92
|
+
readonly vendor: Schema.optionalKey<Schema.String>;
|
|
93
|
+
readonly paymentMethod: Schema.optionalKey<Schema.String>;
|
|
94
|
+
}>>;
|
|
95
|
+
readonly participant: Schema.optionalKey<Schema.String>;
|
|
96
|
+
readonly call: Schema.optionalKey<Schema.Struct<{
|
|
97
|
+
readonly method: Schema.Literals<readonly ["GET", "POST", "PUT", "PATCH", "DELETE"]>;
|
|
98
|
+
readonly path: Schema.String;
|
|
99
|
+
}>>;
|
|
100
|
+
readonly compensation: Schema.optionalKey<Schema.Struct<{
|
|
101
|
+
readonly method: Schema.Literals<readonly ["GET", "POST", "PUT", "PATCH", "DELETE"]>;
|
|
102
|
+
readonly path: Schema.String;
|
|
103
|
+
}>>;
|
|
104
|
+
/** Configuration pinned at composition — a hold's expiry, a limit. */
|
|
105
|
+
readonly parameters: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
106
|
+
}>>;
|
|
107
|
+
}>>;
|
|
108
|
+
readonly resolution: Schema.$Array<Schema.Struct<{
|
|
109
|
+
readonly useCase: Schema.String;
|
|
110
|
+
readonly variant: Schema.String;
|
|
111
|
+
readonly rule: Schema.Number;
|
|
112
|
+
}>>;
|
|
113
|
+
readonly composedAt: Schema.String;
|
|
114
|
+
}>;
|
|
115
|
+
export type Slip = typeof Slip.Type;
|
|
116
|
+
/**
|
|
117
|
+
* Decodes a stored or received slip. An unknown `slipVersion`, like any shape
|
|
118
|
+
* the grammar does not describe, is a protocol failure: an interpreter must
|
|
119
|
+
* never guess at a grammar it was not built for.
|
|
120
|
+
*/
|
|
121
|
+
export declare const decodeSlip: (input: unknown) => Effect.Effect<Slip, ProtocolFailure>;
|
|
122
|
+
/** Encodes a slip as the workflow payload it travels as. */
|
|
123
|
+
export declare const encodeSlip: (slip: Slip) => unknown;
|
|
124
|
+
/** Every step of a slip, in the order it runs. */
|
|
125
|
+
export declare const slipSteps: (slip: Slip) => readonly SlipStep[];
|
|
126
|
+
//# sourceMappingURL=slip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slip.d.ts","sourceRoot":"","sources":["../../src/flow/slip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAExC;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAG,CAAU,CAAC;AAOvC,mFAAmF;AACnF,eAAO,MAAM,WAAW;;;EAGtB,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC,IAAI,CAAC;AAElD,4EAA4E;AAC5E,eAAO,MAAM,QAAQ;IACnB,uDAAuD;;IAEvD,gFAAgF;;;;;;;;;;;;;;;;IAOhF,sEAAsE;;EAEtE,CAAC;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,IAAI,CAAC;AAE5C,eAAO,MAAM,SAAS;;;QAdpB,uDAAuD;;QAEvD,gFAAgF;;;;;;;;;;;;;;;;QAOhF,sEAAsE;;;EAQtE,CAAC;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,IAAI,CAAC;AAE9C,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;;;;;YArClF,uDAAuD;;YAEvD,gFAAgF;;;;;;;;;;;;;;;;YAOhF,sEAAsE;;;;;;;;;;EAiCtE,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"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ProtocolFailure } from '@entifix/core';
|
|
2
|
+
import { Effect, Schema } from 'effect';
|
|
3
|
+
/**
|
|
4
|
+
* The grammar version a slip is written in. An interpreter branches on it, so a
|
|
5
|
+
* flow that started under one grammar finishes under that grammar even after
|
|
6
|
+
* the next one ships.
|
|
7
|
+
*/ export const SLIP_VERSION = 1;
|
|
8
|
+
const Call = Schema.Struct({
|
|
9
|
+
method: Schema.Literals([
|
|
10
|
+
'GET',
|
|
11
|
+
'POST',
|
|
12
|
+
'PUT',
|
|
13
|
+
'PATCH',
|
|
14
|
+
'DELETE'
|
|
15
|
+
]),
|
|
16
|
+
path: Schema.String
|
|
17
|
+
});
|
|
18
|
+
/** Tags that place a step in a segment of the flow: whose lines, which payment. */ export const SlipSegment = Schema.Struct({
|
|
19
|
+
vendor: Schema.optionalKey(Schema.String),
|
|
20
|
+
paymentMethod: Schema.optionalKey(Schema.String)
|
|
21
|
+
});
|
|
22
|
+
/** One pinned step: a fragment reference and everything resolved for it. */ export const SlipStep = Schema.Struct({
|
|
23
|
+
/** `id@version`, pinned when the slip was composed. */ ref: Schema.String,
|
|
24
|
+
/** Unique within the slip; what an Activity is named after (`segment:step`). */ step: Schema.String,
|
|
25
|
+
cardinality: Schema.Literals([
|
|
26
|
+
'one',
|
|
27
|
+
'perVendor',
|
|
28
|
+
'perLine'
|
|
29
|
+
]),
|
|
30
|
+
segment: Schema.optionalKey(SlipSegment),
|
|
31
|
+
participant: Schema.optionalKey(Schema.String),
|
|
32
|
+
call: Schema.optionalKey(Call),
|
|
33
|
+
compensation: Schema.optionalKey(Call),
|
|
34
|
+
/** Configuration pinned at composition — a hold's expiry, a limit. */ parameters: Schema.optionalKey(Schema.Record(Schema.String, Schema.Unknown))
|
|
35
|
+
});
|
|
36
|
+
export const SlipStage = Schema.Struct({
|
|
37
|
+
name: Schema.String,
|
|
38
|
+
steps: Schema.Array(SlipStep)
|
|
39
|
+
});
|
|
40
|
+
/** Which variant each use case resolved to, and by which rule. */ export const SlipResolution = Schema.Struct({
|
|
41
|
+
useCase: Schema.String,
|
|
42
|
+
variant: Schema.String,
|
|
43
|
+
rule: Schema.Number
|
|
44
|
+
});
|
|
45
|
+
/**
|
|
46
|
+
* A routing slip: ordered stages of pinned steps, composed once at start and
|
|
47
|
+
* stored as the flow's payload. Changing a recipe or a fragment never changes a
|
|
48
|
+
* flow that has already started.
|
|
49
|
+
*/ export const Slip = Schema.Struct({
|
|
50
|
+
slipVersion: Schema.Literal(SLIP_VERSION),
|
|
51
|
+
flowId: Schema.String,
|
|
52
|
+
recipe: Schema.String,
|
|
53
|
+
/** The recipe demands a commit point even with no retriable step (a checkout). */ requiresCommitPoint: Schema.optionalKey(Schema.Boolean),
|
|
54
|
+
stages: Schema.Array(SlipStage),
|
|
55
|
+
resolution: Schema.Array(SlipResolution),
|
|
56
|
+
composedAt: Schema.String
|
|
57
|
+
});
|
|
58
|
+
/**
|
|
59
|
+
* Decodes a stored or received slip. An unknown `slipVersion`, like any shape
|
|
60
|
+
* the grammar does not describe, is a protocol failure: an interpreter must
|
|
61
|
+
* never guess at a grammar it was not built for.
|
|
62
|
+
*/ export const decodeSlip = (input)=>Schema.decodeUnknownEffect(Slip)(input).pipe(Effect.mapError((error)=>new ProtocolFailure({
|
|
63
|
+
reason: `the slip does not decode: ${error.message}`
|
|
64
|
+
})));
|
|
65
|
+
/** Encodes a slip as the workflow payload it travels as. */ export const encodeSlip = (slip)=>Schema.encodeSync(Slip)(slip);
|
|
66
|
+
/** Every step of a slip, in the order it runs. */ export const slipSteps = (slip)=>slip.stages.flatMap((stage)=>stage.steps);
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=slip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/flow/slip.ts"],"sourcesContent":["import { ProtocolFailure } from '@entifix/core';\nimport { Effect, Schema } from 'effect';\n\n/**\n * The grammar version a slip is written in. An interpreter branches on it, so a\n * flow that started under one grammar finishes under that grammar even after\n * the next one ships.\n */\nexport const SLIP_VERSION = 1 as const;\n\nconst Call = Schema.Struct({\n method: Schema.Literals(['GET', 'POST', 'PUT', 'PATCH', 'DELETE']),\n path: Schema.String,\n});\n\n/** Tags that place a step in a segment of the flow: whose lines, which payment. */\nexport const SlipSegment = Schema.Struct({\n vendor: Schema.optionalKey(Schema.String),\n paymentMethod: Schema.optionalKey(Schema.String),\n});\nexport type SlipSegment = typeof SlipSegment.Type;\n\n/** One pinned step: a fragment reference and everything resolved for it. */\nexport const SlipStep = Schema.Struct({\n /** `id@version`, pinned when the slip was composed. */\n ref: Schema.String,\n /** Unique within the slip; what an Activity is named after (`segment:step`). */\n step: Schema.String,\n cardinality: Schema.Literals(['one', 'perVendor', 'perLine']),\n segment: Schema.optionalKey(SlipSegment),\n participant: Schema.optionalKey(Schema.String),\n call: Schema.optionalKey(Call),\n compensation: Schema.optionalKey(Call),\n /** Configuration pinned at composition — a hold's expiry, a limit. */\n parameters: Schema.optionalKey(Schema.Record(Schema.String, Schema.Unknown)),\n});\nexport type SlipStep = typeof SlipStep.Type;\n\nexport const SlipStage = Schema.Struct({\n name: Schema.String,\n steps: Schema.Array(SlipStep),\n});\nexport type SlipStage = typeof SlipStage.Type;\n\n/** 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});\nexport type Slip = typeof Slip.Type;\n\n/**\n * Decodes a stored or received slip. An unknown `slipVersion`, like any shape\n * the grammar does not describe, is a protocol failure: an interpreter must\n * never guess at a grammar it was not built for.\n */\nexport const decodeSlip = (\n input: unknown,\n): Effect.Effect<Slip, ProtocolFailure> =>\n Schema.decodeUnknownEffect(Slip)(input).pipe(\n Effect.mapError(\n error =>\n new ProtocolFailure({\n reason: `the slip does not decode: ${error.message}`,\n }),\n ),\n );\n\n/** Encodes a slip as the workflow payload it travels as. */\nexport const encodeSlip = (slip: Slip): unknown =>\n Schema.encodeSync(Slip)(slip);\n\n/** Every step of a slip, in the order it runs. */\nexport const slipSteps = (slip: Slip): readonly SlipStep[] =>\n slip.stages.flatMap(stage => stage.steps);\n"],"names":["ProtocolFailure","Effect","Schema","SLIP_VERSION","Call","Struct","method","Literals","path","String","SlipSegment","vendor","optionalKey","paymentMethod","SlipStep","ref","step","cardinality","segment","participant","call","compensation","parameters","Record","Unknown","SlipStage","name","steps","Array","SlipResolution","useCase","variant","rule","Number","Slip","slipVersion","Literal","flowId","recipe","requiresCommitPoint","Boolean","stages","resolution","composedAt","decodeSlip","input","decodeUnknownEffect","pipe","mapError","error","reason","message","encodeSlip","slip","encodeSync","slipSteps","flatMap","stage"],"mappings":"AAAA,SAASA,eAAe,QAAQ,gBAAgB;AAChD,SAASC,MAAM,EAAEC,MAAM,QAAQ,SAAS;AAExC;;;;CAIC,GACD,OAAO,MAAMC,eAAe,EAAW;AAEvC,MAAMC,OAAOF,OAAOG,MAAM,CAAC;IACzBC,QAAQJ,OAAOK,QAAQ,CAAC;QAAC;QAAO;QAAQ;QAAO;QAAS;KAAS;IACjEC,MAAMN,OAAOO,MAAM;AACrB;AAEA,iFAAiF,GACjF,OAAO,MAAMC,cAAcR,OAAOG,MAAM,CAAC;IACvCM,QAAQT,OAAOU,WAAW,CAACV,OAAOO,MAAM;IACxCI,eAAeX,OAAOU,WAAW,CAACV,OAAOO,MAAM;AACjD,GAAG;AAGH,0EAA0E,GAC1E,OAAO,MAAMK,WAAWZ,OAAOG,MAAM,CAAC;IACpC,qDAAqD,GACrDU,KAAKb,OAAOO,MAAM;IAClB,8EAA8E,GAC9EO,MAAMd,OAAOO,MAAM;IACnBQ,aAAaf,OAAOK,QAAQ,CAAC;QAAC;QAAO;QAAa;KAAU;IAC5DW,SAAShB,OAAOU,WAAW,CAACF;IAC5BS,aAAajB,OAAOU,WAAW,CAACV,OAAOO,MAAM;IAC7CW,MAAMlB,OAAOU,WAAW,CAACR;IACzBiB,cAAcnB,OAAOU,WAAW,CAACR;IACjC,oEAAoE,GACpEkB,YAAYpB,OAAOU,WAAW,CAACV,OAAOqB,MAAM,CAACrB,OAAOO,MAAM,EAAEP,OAAOsB,OAAO;AAC5E,GAAG;AAGH,OAAO,MAAMC,YAAYvB,OAAOG,MAAM,CAAC;IACrCqB,MAAMxB,OAAOO,MAAM;IACnBkB,OAAOzB,OAAO0B,KAAK,CAACd;AACtB,GAAG;AAGH,gEAAgE,GAChE,OAAO,MAAMe,iBAAiB3B,OAAOG,MAAM,CAAC;IAC1CyB,SAAS5B,OAAOO,MAAM;IACtBsB,SAAS7B,OAAOO,MAAM;IACtBuB,MAAM9B,OAAO+B,MAAM;AACrB,GAAG;AAGH;;;;CAIC,GACD,OAAO,MAAMC,OAAOhC,OAAOG,MAAM,CAAC;IAChC8B,aAAajC,OAAOkC,OAAO,CAACjC;IAC5BkC,QAAQnC,OAAOO,MAAM;IACrB6B,QAAQpC,OAAOO,MAAM;IACrB,gFAAgF,GAChF8B,qBAAqBrC,OAAOU,WAAW,CAACV,OAAOsC,OAAO;IACtDC,QAAQvC,OAAO0B,KAAK,CAACH;IACrBiB,YAAYxC,OAAO0B,KAAK,CAACC;IACzBc,YAAYzC,OAAOO,MAAM;AAC3B,GAAG;AAGH;;;;CAIC,GACD,OAAO,MAAMmC,aAAa,CACxBC,QAEA3C,OAAO4C,mBAAmB,CAACZ,MAAMW,OAAOE,IAAI,CAC1C9C,OAAO+C,QAAQ,CACbC,CAAAA,QACE,IAAIjD,gBAAgB;YAClBkD,QAAQ,CAAC,0BAA0B,EAAED,MAAME,OAAO,EAAE;QACtD,KAEJ;AAEJ,0DAA0D,GAC1D,OAAO,MAAMC,aAAa,CAACC,OACzBnD,OAAOoD,UAAU,CAACpB,MAAMmB,MAAM;AAEhC,gDAAgD,GAChD,OAAO,MAAME,YAAY,CAACF,OACxBA,KAAKZ,MAAM,CAACe,OAAO,CAACC,CAAAA,QAASA,MAAM9B,KAAK,EAAE"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Effect, Schema } from 'effect';
|
|
2
|
+
import type { FragmentCatalog } from './catalog.js';
|
|
3
|
+
import { type FragmentKeys, type FragmentRequirements } from './fragment.js';
|
|
4
|
+
import { type Slip } from './slip.js';
|
|
5
|
+
/** One rule a slip broke, named by its tag. */
|
|
6
|
+
export interface SlipViolation {
|
|
7
|
+
readonly tag: 'UnknownFragment' | 'TooManyPivots' | 'MissingCommitPoint' | 'RetriableBeforeCommit' | 'CompensatableAfterCommit' | 'IrreversibleBeforeCommit' | 'WaitBeforeCommit' | 'ExcludedFromSegment' | 'UnsatisfiedInput' | 'UnmetRequirement';
|
|
8
|
+
/** The step that broke it, when one step did. */
|
|
9
|
+
readonly step?: string;
|
|
10
|
+
readonly detail: string;
|
|
11
|
+
}
|
|
12
|
+
/** The facts of a verified context a slip's requirements are checked against. */
|
|
13
|
+
export interface RequirementFacts {
|
|
14
|
+
readonly entitlements?: readonly string[];
|
|
15
|
+
readonly roles?: readonly string[];
|
|
16
|
+
readonly partyRole?: string;
|
|
17
|
+
readonly channel?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ValidateSlipOptions {
|
|
20
|
+
/** The facts the caller was verified with; requirements go unchecked without them. */
|
|
21
|
+
readonly context?: RequirementFacts;
|
|
22
|
+
/** Keys the flow's start input provides, with their schemas. */
|
|
23
|
+
readonly start?: FragmentKeys;
|
|
24
|
+
}
|
|
25
|
+
/** The requirements `facts` do not meet, described; empty when all are met. */
|
|
26
|
+
export declare const unmetRequirements: (requires: FragmentRequirements, facts: RequirementFacts) => string[];
|
|
27
|
+
/**
|
|
28
|
+
* Checks a slip against its catalog and returns **every** violation, one tag
|
|
29
|
+
* per rule, rather than throwing at the first — so a CI job enumerating every
|
|
30
|
+
* composition reports them all in one run. Pure: no clock, no I/O.
|
|
31
|
+
*/
|
|
32
|
+
export declare const validateSlip: (slip: Slip, catalog: FragmentCatalog, options?: ValidateSlipOptions) => readonly SlipViolation[];
|
|
33
|
+
declare const CompositionRefused_base: Schema.Class<CompositionRefused, Schema.TaggedStruct<"CompositionRefused", {
|
|
34
|
+
readonly violations: Schema.$Array<Schema.Struct<{
|
|
35
|
+
readonly tag: Schema.String;
|
|
36
|
+
readonly step: Schema.optionalKey<Schema.String>;
|
|
37
|
+
readonly detail: Schema.String;
|
|
38
|
+
}>>;
|
|
39
|
+
}>, import("effect/Cause").YieldableError & import("@entifix/core").FailureFacts<"flowNotComposable", "declined">>;
|
|
40
|
+
/**
|
|
41
|
+
* A flow that cannot be composed for this caller: the slip broke at least one
|
|
42
|
+
* rule. Every violation travels with it.
|
|
43
|
+
*/
|
|
44
|
+
export declare class CompositionRefused extends CompositionRefused_base {
|
|
45
|
+
}
|
|
46
|
+
/** Validates a slip, failing with {@link CompositionRefused} on any violation. */
|
|
47
|
+
export declare const assertValidSlip: (slip: Slip, catalog: FragmentCatalog, options?: ValidateSlipOptions) => Effect.Effect<Slip, CompositionRefused>;
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/flow/validate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAExC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,oBAAoB,EAE1B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,IAAI,EAA4B,MAAM,WAAW,CAAC;AAEhE,+CAA+C;AAC/C,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,GAAG,EACR,iBAAiB,GACjB,eAAe,GACf,oBAAoB,GACpB,uBAAuB,GACvB,0BAA0B,GAC1B,0BAA0B,GAC1B,kBAAkB,GAClB,qBAAqB,GACrB,kBAAkB,GAClB,kBAAkB,CAAC;IACvB,iDAAiD;IACjD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,iFAAiF;AACjF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1C,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,mBAAmB;IAClC,sFAAsF;IACtF,QAAQ,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC;IACpC,gEAAgE;IAChE,QAAQ,CAAC,KAAK,CAAC,EAAE,YAAY,CAAC;CAC/B;AASD,+EAA+E;AAC/E,eAAO,MAAM,iBAAiB,GAC5B,UAAU,oBAAoB,EAC9B,OAAO,gBAAgB,KACtB,MAAM,EAkBR,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,YAAY,GACvB,MAAM,IAAI,EACV,SAAS,eAAe,EACxB,UAAS,mBAAwB,KAChC,SAAS,aAAa,EAuHxB,CAAC;;;;;;;;AAQF;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,uBAQvC;CAAG;AAEJ,kFAAkF;AAClF,eAAO,MAAM,eAAe,GAC1B,MAAM,IAAI,EACV,SAAS,eAAe,EACxB,UAAS,mBAAwB,KAChC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,kBAAkB,CAKxC,CAAC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { Failure } from '@entifix/core';
|
|
2
|
+
import { Effect, Schema } from 'effect';
|
|
3
|
+
import { jsonSchemaOf } from './fragment.js';
|
|
4
|
+
import { slipSteps } from './slip.js';
|
|
5
|
+
const sameSchema = (a, b)=>a === b || JSON.stringify(jsonSchemaOf(a)) === JSON.stringify(jsonSchemaOf(b));
|
|
6
|
+
/** The requirements `facts` do not meet, described; empty when all are met. */ export const unmetRequirements = (requires, facts)=>{
|
|
7
|
+
var _requires_entitlements, _facts_entitlements, _requires_roles, _facts_roles, _facts_partyRole, _facts_channel;
|
|
8
|
+
const missing = [];
|
|
9
|
+
for (const entitlement of (_requires_entitlements = requires.entitlements) != null ? _requires_entitlements : [])if (!((_facts_entitlements = facts.entitlements) != null ? _facts_entitlements : []).includes(entitlement)) missing.push(`entitlement '${entitlement}'`);
|
|
10
|
+
for (const role of (_requires_roles = requires.roles) != null ? _requires_roles : [])if (!((_facts_roles = facts.roles) != null ? _facts_roles : []).includes(role)) missing.push(`role '${role}'`);
|
|
11
|
+
if (requires.partyRoles !== undefined && !requires.partyRoles.includes((_facts_partyRole = facts.partyRole) != null ? _facts_partyRole : '')) missing.push(`party role in ${requires.partyRoles.join(', ')}`);
|
|
12
|
+
if (requires.channels !== undefined && !requires.channels.includes((_facts_channel = facts.channel) != null ? _facts_channel : '')) missing.push(`channel in ${requires.channels.join(', ')}`);
|
|
13
|
+
return missing;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Checks a slip against its catalog and returns **every** violation, one tag
|
|
17
|
+
* per rule, rather than throwing at the first — so a CI job enumerating every
|
|
18
|
+
* composition reports them all in one run. Pure: no clock, no I/O.
|
|
19
|
+
*/ export const validateSlip = (slip, catalog, options = {})=>{
|
|
20
|
+
var _options_start;
|
|
21
|
+
const violations = [];
|
|
22
|
+
const resolved = [];
|
|
23
|
+
for (const step of slipSteps(slip)){
|
|
24
|
+
const fragment = catalog.get(step.ref);
|
|
25
|
+
if (fragment === undefined) violations.push({
|
|
26
|
+
tag: 'UnknownFragment',
|
|
27
|
+
step: step.step,
|
|
28
|
+
detail: `'${step.ref}' is not in the catalog`
|
|
29
|
+
});
|
|
30
|
+
else resolved.push({
|
|
31
|
+
step,
|
|
32
|
+
fragment
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const pivots = resolved.filter(({ fragment })=>fragment.kind === 'pivot');
|
|
36
|
+
if (pivots.length > 1) violations.push({
|
|
37
|
+
tag: 'TooManyPivots',
|
|
38
|
+
detail: `the slip has ${String(pivots.length)} pivots (${pivots.map(({ step })=>step.step).join(', ')}); a flow has one point of no return`
|
|
39
|
+
});
|
|
40
|
+
const commitAt = resolved.findIndex(({ fragment })=>fragment.kind === 'pivot');
|
|
41
|
+
const hasRetriable = resolved.some(({ fragment })=>fragment.kind === 'retriable');
|
|
42
|
+
if (commitAt === -1 && (hasRetriable || slip.requiresCommitPoint === true)) violations.push({
|
|
43
|
+
tag: 'MissingCommitPoint',
|
|
44
|
+
detail: 'the slip needs one commit point — a pivot, or flow.commit@1 — before its first retriable step'
|
|
45
|
+
});
|
|
46
|
+
const provided = new Map(Object.entries((_options_start = options.start) != null ? _options_start : {}));
|
|
47
|
+
resolved.forEach(({ step, fragment }, index)=>{
|
|
48
|
+
var _fragment_excludedFrom, _fragment_consumes, _fragment_provides;
|
|
49
|
+
const beforeCommit = commitAt === -1 || index < commitAt;
|
|
50
|
+
const afterCommit = commitAt !== -1 && index > commitAt;
|
|
51
|
+
if (fragment.kind === 'retriable' && commitAt !== -1 && index < commitAt) violations.push({
|
|
52
|
+
tag: 'RetriableBeforeCommit',
|
|
53
|
+
step: step.step,
|
|
54
|
+
detail: `'${step.ref}' is retriable and runs before the commit point, where a failure must compensate`
|
|
55
|
+
});
|
|
56
|
+
if (fragment.kind === 'compensatable' && afterCommit) violations.push({
|
|
57
|
+
tag: 'CompensatableAfterCommit',
|
|
58
|
+
step: step.step,
|
|
59
|
+
detail: `'${step.ref}' is compensatable and runs after the commit point, where nothing is undone`
|
|
60
|
+
});
|
|
61
|
+
if (fragment.irreversible === true && fragment.kind !== 'pivot' && beforeCommit) violations.push({
|
|
62
|
+
tag: 'IrreversibleBeforeCommit',
|
|
63
|
+
step: step.step,
|
|
64
|
+
detail: `'${step.ref}' cannot be undone and runs before the commit point`
|
|
65
|
+
});
|
|
66
|
+
if (fragment.kind === 'wait' && beforeCommit) violations.push({
|
|
67
|
+
tag: 'WaitBeforeCommit',
|
|
68
|
+
step: step.step,
|
|
69
|
+
detail: `'${step.ref}' waits before the commit point, holding uncommitted state for as long as it waits`
|
|
70
|
+
});
|
|
71
|
+
for (const [tag, values] of Object.entries((_fragment_excludedFrom = fragment.excludedFrom) != null ? _fragment_excludedFrom : {})){
|
|
72
|
+
var _step_segment;
|
|
73
|
+
const value = (_step_segment = step.segment) == null ? void 0 : _step_segment[tag];
|
|
74
|
+
if (value !== undefined && values.includes(value)) violations.push({
|
|
75
|
+
tag: 'ExcludedFromSegment',
|
|
76
|
+
step: step.step,
|
|
77
|
+
detail: `'${step.ref}' may not run in a segment whose ${tag} is '${value}'`
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
for (const [key, schema] of Object.entries((_fragment_consumes = fragment.consumes) != null ? _fragment_consumes : {})){
|
|
81
|
+
const earlier = provided.get(key);
|
|
82
|
+
if (earlier === undefined) violations.push({
|
|
83
|
+
tag: 'UnsatisfiedInput',
|
|
84
|
+
step: step.step,
|
|
85
|
+
detail: `'${step.ref}' consumes '${key}', which nothing before it provides`
|
|
86
|
+
});
|
|
87
|
+
else if (!sameSchema(earlier, schema)) violations.push({
|
|
88
|
+
tag: 'UnsatisfiedInput',
|
|
89
|
+
step: step.step,
|
|
90
|
+
detail: `'${step.ref}' consumes '${key}' with a schema other than the one provided`
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
for (const [key, schema] of Object.entries((_fragment_provides = fragment.provides) != null ? _fragment_provides : {}))provided.set(key, schema);
|
|
94
|
+
if (options.context !== undefined && fragment.requires !== undefined) {
|
|
95
|
+
const missing = unmetRequirements(fragment.requires, options.context);
|
|
96
|
+
if (missing.length > 0) violations.push({
|
|
97
|
+
tag: 'UnmetRequirement',
|
|
98
|
+
step: step.step,
|
|
99
|
+
detail: `'${step.ref}' requires ${missing.join(', ')}`
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
return violations;
|
|
104
|
+
};
|
|
105
|
+
const SlipViolationSchema = Schema.Struct({
|
|
106
|
+
tag: Schema.String,
|
|
107
|
+
step: Schema.optionalKey(Schema.String),
|
|
108
|
+
detail: Schema.String
|
|
109
|
+
});
|
|
110
|
+
/**
|
|
111
|
+
* A flow that cannot be composed for this caller: the slip broke at least one
|
|
112
|
+
* rule. Every violation travels with it.
|
|
113
|
+
*/ export class CompositionRefused extends Failure.declined()('CompositionRefused', 'flowNotComposable', {
|
|
114
|
+
violations: Schema.Array(SlipViolationSchema)
|
|
115
|
+
}, {
|
|
116
|
+
message: ({ violations })=>`the flow cannot be composed: ${violations.map((v)=>v.tag).join(', ')}`
|
|
117
|
+
}) {
|
|
118
|
+
}
|
|
119
|
+
/** Validates a slip, failing with {@link CompositionRefused} on any violation. */ export const assertValidSlip = (slip, catalog, options = {})=>{
|
|
120
|
+
const violations = validateSlip(slip, catalog, options);
|
|
121
|
+
return violations.length === 0 ? Effect.succeed(slip) : Effect.fail(new CompositionRefused({
|
|
122
|
+
violations
|
|
123
|
+
}));
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +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/** Validates a slip, failing with {@link CompositionRefused} on any violation. */\nexport const assertValidSlip = (\n slip: Slip,\n catalog: FragmentCatalog,\n options: ValidateSlipOptions = {},\n): Effect.Effect<Slip, CompositionRefused> => {\n const violations = validateSlip(slip, catalog, options);\n return violations.length === 0\n ? Effect.succeed(slip)\n : Effect.fail(new CompositionRefused({ violations }));\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","CompositionR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L,KAAKG,GAAG,CAAC,WAAW,EAAEtB,QAAQU,IAAI,CAAC,OAAO;YACxD;QACJ;IACF;IAEA,OAAOO;AACT,EAAE;AAEF,MAAMwC,sBAAsBpE,OAAOqE,MAAM,CAAC;IACxCnC,KAAKlC,OAAOwC,MAAM;IAClBV,MAAM9B,OAAOsE,WAAW,CAACtE,OAAOwC,MAAM;IACtCL,QAAQnC,OAAOwC,MAAM;AACvB;AAEA;;;CAGC,GACD,OAAO,MAAM+B,2BAA2BzE,QAAQ0E,QAAQ,GACtD,sBACA,qBACA;IAAE5C,YAAY5B,OAAOyE,KAAK,CAACL;AAAqB,GAChD;IACEM,SAAS,CAAC,EAAE9C,UAAU,EAAE,GACtB,CAAC,6BAA6B,EAAEA,WAAWa,GAAG,CAACkC,CAAAA,IAAKA,EAAEzC,GAAG,EAAEb,IAAI,CAAC,OAAO;AAC3E;AACC;AAEH,gFAAgF,GAChF,OAAO,MAAMuD,kBAAkB,CAC7BnD,MACAC,SACAC,UAA+B,CAAC,CAAC;IAEjC,MAAMC,aAAaJ,aAAaC,MAAMC,SAASC;IAC/C,OAAOC,WAAWW,MAAM,KAAK,IACzBxC,OAAO8E,OAAO,CAACpD,QACf1B,OAAO+E,IAAI,CAAC,IAAIP,mBAAmB;QAAE3C;IAAW;AACtD,EAAE"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { StoreFailure } from '@entifix/core';
|
|
2
|
+
import { Context, type Effect } from 'effect';
|
|
3
|
+
/** A response as it is replayed: status, content type and body text. */
|
|
4
|
+
export interface StoredResponse {
|
|
5
|
+
readonly status: number;
|
|
6
|
+
readonly contentType?: string;
|
|
7
|
+
readonly body: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* One request's claim on its `Idempotency-Key`. The dedup key is the caller,
|
|
11
|
+
* the route and the key together, so two callers — or two routes — choosing
|
|
12
|
+
* the same key never collide; the fingerprint is what tells a retry from a
|
|
13
|
+
* different request reusing a key.
|
|
14
|
+
*/
|
|
15
|
+
export interface IdempotencyRecord {
|
|
16
|
+
readonly dedupKey: string;
|
|
17
|
+
readonly fingerprint: string;
|
|
18
|
+
readonly state: 'inFlight' | 'completed';
|
|
19
|
+
readonly response?: StoredResponse;
|
|
20
|
+
/** ISO-8601. Past it, the record is treated as absent. */
|
|
21
|
+
readonly expiresAt: string;
|
|
22
|
+
}
|
|
23
|
+
/** What a claim found: nothing, so this request owns the key, or a live record. */
|
|
24
|
+
export type IdempotencyClaim = {
|
|
25
|
+
readonly _tag: 'claimed';
|
|
26
|
+
} | {
|
|
27
|
+
readonly _tag: 'existing';
|
|
28
|
+
readonly record: IdempotencyRecord;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Where a route remembers the requests it has answered under an
|
|
32
|
+
* `Idempotency-Key` — what makes a redelivered command, or a client's retry,
|
|
33
|
+
* answer what the first one did instead of acting twice.
|
|
34
|
+
*
|
|
35
|
+
* Retention is the implementation's, passed by the composition root: a record
|
|
36
|
+
* is kept until `expiresAt`, and an expired one is treated as never written.
|
|
37
|
+
*/
|
|
38
|
+
export interface IdempotencyStore {
|
|
39
|
+
/** Claims `dedupKey` atomically: exactly one concurrent caller gets `claimed`. */
|
|
40
|
+
readonly claim: (dedupKey: string, fingerprint: string) => Effect.Effect<IdempotencyClaim, StoreFailure>;
|
|
41
|
+
/** Records the answer, so a completed duplicate replays it. */
|
|
42
|
+
readonly complete: (dedupKey: string, response: StoredResponse) => Effect.Effect<void, StoreFailure>;
|
|
43
|
+
/**
|
|
44
|
+
* Gives the key back after a failure that was not an answer — an outage —
|
|
45
|
+
* so a retry is allowed to try again rather than being told it is in flight.
|
|
46
|
+
*/
|
|
47
|
+
readonly release: (dedupKey: string) => Effect.Effect<void, StoreFailure>;
|
|
48
|
+
}
|
|
49
|
+
declare const IdempotencyStoreTag_base: Context.ServiceClass<IdempotencyStoreTag, "@entifix/business/IdempotencyStore", IdempotencyStore>;
|
|
50
|
+
export declare class IdempotencyStoreTag extends IdempotencyStoreTag_base {
|
|
51
|
+
}
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=idempotency-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"idempotency-store.d.ts","sourceRoot":"","sources":["../../src/idempotency/idempotency-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE9C,wEAAwE;AACxE,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CAAC;IACzC,QAAQ,CAAC,QAAQ,CAAC,EAAE,cAAc,CAAC;IACnC,0DAA0D;IAC1D,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,mFAAmF;AACnF,MAAM,MAAM,gBAAgB,GACxB;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GAC5B;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAA;CAAE,CAAC;AAEtE;;;;;;;GAOG;AACH,MAAM,WAAW,gBAAgB;IAC/B,kFAAkF;IAClF,QAAQ,CAAC,KAAK,EAAE,CACd,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,KAChB,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAAC;IACnD,+DAA+D;IAC/D,QAAQ,CAAC,QAAQ,EAAE,CACjB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,cAAc,KACrB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IACvC;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;CAC3E;;AAED,qBAAa,mBAAoB,SAAQ,wBAGA;CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/idempotency/idempotency-store.ts"],"sourcesContent":["import type { StoreFailure } from '@entifix/core';\nimport { Context, type Effect } from 'effect';\n\n/** A response as it is replayed: status, content type and body text. */\nexport interface StoredResponse {\n readonly status: number;\n readonly contentType?: string;\n readonly body: string;\n}\n\n/**\n * One request's claim on its `Idempotency-Key`. The dedup key is the caller,\n * the route and the key together, so two callers — or two routes — choosing\n * the same key never collide; the fingerprint is what tells a retry from a\n * different request reusing a key.\n */\nexport interface IdempotencyRecord {\n readonly dedupKey: string;\n readonly fingerprint: string;\n readonly state: 'inFlight' | 'completed';\n readonly response?: StoredResponse;\n /** ISO-8601. Past it, the record is treated as absent. */\n readonly expiresAt: string;\n}\n\n/** What a claim found: nothing, so this request owns the key, or a live record. */\nexport type IdempotencyClaim =\n | { readonly _tag: 'claimed' }\n | { readonly _tag: 'existing'; readonly record: IdempotencyRecord };\n\n/**\n * Where a route remembers the requests it has answered under an\n * `Idempotency-Key` — what makes a redelivered command, or a client's retry,\n * answer what the first one did instead of acting twice.\n *\n * Retention is the implementation's, passed by the composition root: a record\n * is kept until `expiresAt`, and an expired one is treated as never written.\n */\nexport interface IdempotencyStore {\n /** Claims `dedupKey` atomically: exactly one concurrent caller gets `claimed`. */\n readonly claim: (\n dedupKey: string,\n fingerprint: string,\n ) => Effect.Effect<IdempotencyClaim, StoreFailure>;\n /** Records the answer, so a completed duplicate replays it. */\n readonly complete: (\n dedupKey: string,\n response: StoredResponse,\n ) => Effect.Effect<void, StoreFailure>;\n /**\n * Gives the key back after a failure that was not an answer — an outage —\n * so a retry is allowed to try again rather than being told it is in flight.\n */\n readonly release: (dedupKey: string) => Effect.Effect<void, StoreFailure>;\n}\n\nexport class IdempotencyStoreTag extends Context.Service<\n IdempotencyStoreTag,\n IdempotencyStore\n>()('@entifix/business/IdempotencyStore') {}\n"],"names":["Context","IdempotencyStoreTag","Service"],"mappings":"AACA,SAASA,OAAO,QAAqB,SAAS;AAuD9C,OAAO,MAAMC,4BAA4BD,QAAQE,OAAO,GAGpD;AAAuC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/idempotency/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/idempotency/index.ts"],"sourcesContent":["export * from './idempotency-store.js';\n"],"names":[],"mappings":"AAAA,cAAc,yBAAyB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
export * from './health/health-registry.js';
|
|
2
|
+
export * from './idempotency/index.js';
|
|
2
3
|
export * from './repository/config.repository.js';
|
|
3
4
|
export * from './repository/entity.repository.js';
|
|
4
5
|
export * from './repository/entity-facet-counter.js';
|
|
5
6
|
export * from './repository/entity-link-resolver.repository.js';
|
|
6
7
|
export * from './repository/entity-mixins.repository.js';
|
|
7
8
|
export * from './repository/entity-repository-factory.js';
|
|
9
|
+
export * from './resolve/index.js';
|
|
8
10
|
export * from './sessions/one-time-token-store.js';
|
|
9
11
|
export * from './sessions/session-store.js';
|
|
10
12
|
export * from './shutdown/shutdown-registry.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mCAAmC,CAAC;AAClD,cAAc,mCAAmC,CAAC;AAClD,cAAc,sCAAsC,CAAC;AACrD,cAAc,iDAAiD,CAAC;AAChE,cAAc,0CAA0C,CAAC;AACzD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,oCAAoC,CAAC;AACnD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,mCAAmC,CAAC;AAClD,cAAc,mCAAmC,CAAC;AAClD,cAAc,sCAAsC,CAAC;AACrD,cAAc,iDAAiD,CAAC;AAChE,cAAc,0CAA0C,CAAC;AACzD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,oBAAoB,CAAC;AACnC,cAAc,oCAAoC,CAAC;AACnD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
export * from './health/health-registry.js';
|
|
2
|
+
export * from './idempotency/index.js';
|
|
2
3
|
export * from './repository/config.repository.js';
|
|
3
4
|
export * from './repository/entity.repository.js';
|
|
4
5
|
export * from './repository/entity-facet-counter.js';
|
|
5
6
|
export * from './repository/entity-link-resolver.repository.js';
|
|
6
7
|
export * from './repository/entity-mixins.repository.js';
|
|
7
8
|
export * from './repository/entity-repository-factory.js';
|
|
9
|
+
export * from './resolve/index.js';
|
|
8
10
|
export * from './sessions/one-time-token-store.js';
|
|
9
11
|
export * from './sessions/session-store.js';
|
|
10
12
|
export * from './shutdown/shutdown-registry.js';
|