@entifix/core 0.13.0 → 0.14.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/base-entities/configuration-client/configuration-client-singleton.d.ts +12 -13
- package/dist/base-entities/configuration-client/configuration-client-singleton.d.ts.map +1 -1
- package/dist/base-entities/configuration-client/configuration-client-singleton.js +4 -17
- package/dist/base-entities/configuration-client/configuration-client-singleton.js.map +1 -1
- package/dist/base-entities/configuration-client/types.d.ts +13 -13
- package/dist/base-entities/configuration-client/types.d.ts.map +1 -1
- package/dist/base-entities/configuration-client/types.js.map +1 -1
- package/dist/command-palette/command-matching.d.ts.map +1 -1
- package/dist/command-palette/command-matching.js +1 -5
- package/dist/command-palette/command-matching.js.map +1 -1
- package/dist/entity-definition/describe/describe-child-columns.d.ts +3 -3
- package/dist/entity-definition/describe/describe-child-columns.d.ts.map +1 -1
- package/dist/entity-definition/describe/describe-child-columns.js +5 -10
- package/dist/entity-definition/describe/describe-child-columns.js.map +1 -1
- package/dist/entity-definition/describe/describe-entity-columns.d.ts.map +1 -1
- package/dist/entity-definition/describe/describe-entity-columns.js +6 -7
- package/dist/entity-definition/describe/describe-entity-columns.js.map +1 -1
- package/dist/entity-definition/describe/entity-view.d.ts.map +1 -1
- package/dist/entity-definition/describe/entity-view.js +2 -3
- package/dist/entity-definition/describe/entity-view.js.map +1 -1
- package/dist/entity-definition/helpers/entity-definition-helpers.d.ts.map +1 -1
- package/dist/entity-definition/helpers/entity-definition-helpers.js +4 -5
- package/dist/entity-definition/helpers/entity-definition-helpers.js.map +1 -1
- package/dist/entity-definition/links/apply-entity-links/apply-entity-links.d.ts +1 -1
- package/dist/entity-definition/links/apply-entity-links/apply-entity-links.d.ts.map +1 -1
- package/dist/entity-definition/links/apply-entity-links/apply-entity-links.js +2 -6
- package/dist/entity-definition/links/apply-entity-links/apply-entity-links.js.map +1 -1
- package/dist/entity-definition/links/entity-collection-link/entity-collection-link.d.ts +3 -3
- package/dist/entity-definition/links/entity-collection-link/entity-collection-link.d.ts.map +1 -1
- package/dist/entity-definition/links/entity-collection-link/entity-collection-link.js.map +1 -1
- package/dist/entity-definition/links/entity-link/entity-link.d.ts +4 -4
- package/dist/entity-definition/links/entity-link/entity-link.d.ts.map +1 -1
- package/dist/entity-definition/links/entity-link/entity-link.js.map +1 -1
- package/dist/entity-definition/links/entity-link-source/entity-link-source.d.ts +3 -3
- package/dist/entity-definition/links/entity-link-source/entity-link-source.d.ts.map +1 -1
- package/dist/entity-definition/links/entity-link-source/entity-link-source.js.map +1 -1
- package/dist/entity-definition/links/link-targets/link-targets.d.ts.map +1 -1
- package/dist/entity-definition/links/link-targets/link-targets.js +2 -3
- package/dist/entity-definition/links/link-targets/link-targets.js.map +1 -1
- package/dist/entity-definition/meta-entities/bounds.d.ts.map +1 -1
- package/dist/entity-definition/meta-entities/bounds.js +2 -3
- package/dist/entity-definition/meta-entities/bounds.js.map +1 -1
- package/dist/entity-definition/serializer/deserialize.d.ts +3 -3
- package/dist/entity-definition/serializer/deserialize.d.ts.map +1 -1
- package/dist/entity-definition/serializer/deserialize.js +11 -18
- package/dist/entity-definition/serializer/deserialize.js.map +1 -1
- package/dist/failure/failure.d.ts +0 -7
- package/dist/failure/failure.d.ts.map +1 -1
- package/dist/failure/failure.js.map +1 -1
- package/dist/failure/predicates.d.ts +6 -0
- package/dist/failure/predicates.d.ts.map +1 -1
- package/dist/failure/predicates.js +5 -0
- package/dist/failure/predicates.js.map +1 -1
- package/dist/hierarchy/hierarchy.d.ts.map +1 -1
- package/dist/hierarchy/hierarchy.js +1 -2
- package/dist/hierarchy/hierarchy.js.map +1 -1
- package/dist/i18n/locales.d.ts.map +1 -1
- package/dist/i18n/locales.js +19 -4
- package/dist/i18n/locales.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/query/in-memory-query.d.ts.map +1 -1
- package/dist/query/in-memory-query.js +1 -2
- package/dist/query/in-memory-query.js.map +1 -1
- package/dist/rsql/coerce-rsql.d.ts +1 -1
- package/dist/rsql/coerce-rsql.d.ts.map +1 -1
- package/dist/rsql/coerce-rsql.js +2 -3
- package/dist/rsql/coerce-rsql.js.map +1 -1
- package/dist/rsql/facet-query-url.d.ts +1 -1
- package/dist/rsql/facet-query-url.d.ts.map +1 -1
- package/dist/rsql/facet-query-url.js +4 -9
- package/dist/rsql/facet-query-url.js.map +1 -1
- package/dist/rsql/load-request-url.d.ts +1 -1
- package/dist/rsql/load-request-url.d.ts.map +1 -1
- package/dist/rsql/load-request-url.js +2 -5
- package/dist/rsql/load-request-url.js.map +1 -1
- package/dist/rsql/parse-rsql.d.ts +1 -1
- package/dist/rsql/parse-rsql.d.ts.map +1 -1
- package/dist/rsql/parse-rsql.js +2 -5
- package/dist/rsql/parse-rsql.js.map +1 -1
- package/dist/use-case-runner/entity-writer.d.ts +24 -0
- package/dist/use-case-runner/entity-writer.d.ts.map +1 -0
- package/dist/use-case-runner/entity-writer.js +12 -0
- package/dist/use-case-runner/entity-writer.js.map +1 -0
- package/dist/use-case-runner/index.d.ts +2 -0
- package/dist/use-case-runner/index.d.ts.map +1 -1
- package/dist/use-case-runner/index.js +2 -0
- package/dist/use-case-runner/index.js.map +1 -1
- package/dist/use-case-runner/use-case-runner.d.ts +9 -4
- package/dist/use-case-runner/use-case-runner.d.ts.map +1 -1
- package/dist/use-case-runner/use-case-runner.js.map +1 -1
- package/dist/use-case-runner/write-result.d.ts +36 -0
- package/dist/use-case-runner/write-result.d.ts.map +1 -0
- package/dist/use-case-runner/write-result.js +20 -0
- package/dist/use-case-runner/write-result.js.map +1 -0
- package/dist/wizard/wizard-definition.d.ts.map +1 -1
- package/dist/wizard/wizard-definition.js +10 -11
- package/dist/wizard/wizard-definition.js.map +1 -1
- package/dist/wizard/wizard-navigation.d.ts +1 -1
- package/dist/wizard/wizard-navigation.d.ts.map +1 -1
- package/dist/wizard/wizard-navigation.js +2 -3
- package/dist/wizard/wizard-navigation.js.map +1 -1
- package/package.json +3 -3
- package/dist/base-entities/entifix-error/entifix-error.d.ts +0 -31
- package/dist/base-entities/entifix-error/entifix-error.d.ts.map +0 -1
- package/dist/base-entities/entifix-error/entifix-error.js +0 -56
- package/dist/base-entities/entifix-error/entifix-error.js.map +0 -1
- package/dist/base-entities/entifix-error/index.d.ts +0 -2
- package/dist/base-entities/entifix-error/index.d.ts.map +0 -1
- package/dist/base-entities/entifix-error/index.js +0 -3
- package/dist/base-entities/entifix-error/index.js.map +0 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { EntifixBuildError } from '../base-entities/entifix-error/index.js';
|
|
2
1
|
/**
|
|
3
2
|
* What a step holds, which decides how its value is stored and edited.
|
|
4
3
|
*
|
|
@@ -16,7 +15,7 @@ import { EntifixBuildError } from '../base-entities/entifix-error/index.js';
|
|
|
16
15
|
/** The step a flow starts at: the first declared. */ export const entryStep = (definition)=>{
|
|
17
16
|
const [first] = definition.steps;
|
|
18
17
|
if (first === undefined) {
|
|
19
|
-
throw new
|
|
18
|
+
throw new Error(`wizard "${definition.key}" declares no steps`);
|
|
20
19
|
}
|
|
21
20
|
return first;
|
|
22
21
|
};
|
|
@@ -51,7 +50,7 @@ import { EntifixBuildError } from '../base-entities/entifix-error/index.js';
|
|
|
51
50
|
const ids = new Set();
|
|
52
51
|
for (const step of definition.steps){
|
|
53
52
|
if (ids.has(step.id)) {
|
|
54
|
-
throw new
|
|
53
|
+
throw new Error(`wizard "${definition.key}" declares step "${step.id}" twice`);
|
|
55
54
|
}
|
|
56
55
|
ids.add(step.id);
|
|
57
56
|
}
|
|
@@ -59,11 +58,11 @@ import { EntifixBuildError } from '../base-entities/entifix-error/index.js';
|
|
|
59
58
|
assertStepOptions(definition, step);
|
|
60
59
|
for (const target of step.to){
|
|
61
60
|
if (!ids.has(target)) {
|
|
62
|
-
throw new
|
|
61
|
+
throw new Error(`wizard "${definition.key}" step "${step.id}" leads to unknown step "${target}"`);
|
|
63
62
|
}
|
|
64
63
|
}
|
|
65
64
|
if (step.to.length > 1 && step.next === undefined) {
|
|
66
|
-
throw new
|
|
65
|
+
throw new Error(`wizard "${definition.key}" step "${step.id}" has ${step.to.length} edges and no next()`);
|
|
67
66
|
}
|
|
68
67
|
}
|
|
69
68
|
assertOneSummaryAtTheEnd(definition);
|
|
@@ -72,26 +71,26 @@ import { EntifixBuildError } from '../base-entities/entifix-error/index.js';
|
|
|
72
71
|
/** `options` belongs to `choice` and to nothing else. */ function assertStepOptions(definition, step) {
|
|
73
72
|
if (step.kind === 'choice') {
|
|
74
73
|
if (step.options === undefined || step.options.length === 0) {
|
|
75
|
-
throw new
|
|
74
|
+
throw new Error(`wizard "${definition.key}" choice step "${step.id}" offers no options`);
|
|
76
75
|
}
|
|
77
76
|
return;
|
|
78
77
|
}
|
|
79
78
|
if (step.options !== undefined) {
|
|
80
|
-
throw new
|
|
79
|
+
throw new Error(`wizard "${definition.key}" step "${step.id}" is a ${step.kind} step and cannot declare options`);
|
|
81
80
|
}
|
|
82
81
|
}
|
|
83
82
|
/** Exactly one summary, and it is the only step the flow may end on. */ function assertOneSummaryAtTheEnd(definition) {
|
|
84
83
|
const summaries = definition.steps.filter((step)=>step.kind === 'summary');
|
|
85
84
|
if (summaries.length !== 1) {
|
|
86
|
-
throw new
|
|
85
|
+
throw new Error(`wizard "${definition.key}" declares ${summaries.length} summary steps, and must declare exactly one`);
|
|
87
86
|
}
|
|
88
87
|
for (const step of definition.steps){
|
|
89
88
|
const terminal = step.to.length === 0;
|
|
90
89
|
if (terminal && step.kind !== 'summary') {
|
|
91
|
-
throw new
|
|
90
|
+
throw new Error(`wizard "${definition.key}" ends on "${step.id}", which is not its summary`);
|
|
92
91
|
}
|
|
93
92
|
if (!terminal && step.kind === 'summary') {
|
|
94
|
-
throw new
|
|
93
|
+
throw new Error(`wizard "${definition.key}" summary step "${step.id}" leads onward, and must end the flow`);
|
|
95
94
|
}
|
|
96
95
|
}
|
|
97
96
|
}
|
|
@@ -116,7 +115,7 @@ import { EntifixBuildError } from '../base-entities/entifix-error/index.js';
|
|
|
116
115
|
}
|
|
117
116
|
const stranded = definition.steps.filter((step)=>!seen.has(step.id)).map((step)=>step.id);
|
|
118
117
|
if (stranded.length > 0) {
|
|
119
|
-
throw new
|
|
118
|
+
throw new Error(`wizard "${definition.key}" cannot reach ${stranded.map((id)=>`"${id}"`).join(', ')} from "${first.id}"`);
|
|
120
119
|
}
|
|
121
120
|
}
|
|
122
121
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/wizard/wizard-definition.ts"],"sourcesContent":["import { EntifixBuildError } from '../base-entities/entifix-error/index.js';\n\n/**\n * What a step holds, which decides how its value is stored and edited.\n *\n * `form` is one `useEntityForm` instance over part of an entity; `selection` is\n * a table step whose value is a set of ids; `choice` is a branch point offering\n * a fixed list of options; `summary` is the read-only recap; `custom` is\n * anything else the host renders and reads itself.\n */\nexport const WizardStepKinds = [\n 'form',\n 'selection',\n 'choice',\n 'summary',\n 'custom',\n] as const;\nexport type WizardStepKind = (typeof WizardStepKinds)[number];\n\n/**\n * One step, and the edges out of it.\n *\n * **The graph is data; `next` only chooses along it.** `to` lists the steps this\n * one may lead to, so reachability, unknown targets, cycles and terminality are\n * decidable by reading the definition — no probing, no enumeration of the state\n * space, and no rule that \"only appears to hold\" because a `next` reading a form\n * value could never be enumerated. It is the move a saga definition makes for\n * its steps, for the same reason: a walkable definition is checkable\n * at load, and a function is not.\n *\n * A step with an empty `to` is **terminal**, and\n * {@link assertWizardDefinition} requires that to be the summary.\n */\nexport interface WizardStep {\n readonly id: string;\n readonly kind: WizardStepKind;\n /** Catalog key for the stepper's label. Resolved by the renderer, never here. */\n readonly labelKey: string;\n /**\n * The options a `choice` step offers, as stable identifiers.\n *\n * Required on `choice` and forbidden elsewhere: the value of a choice step is\n * one of these strings, so a choice with no options can never be answered and\n * options on a form step describe nothing.\n */\n readonly options?: readonly string[];\n /** Every step this one may lead to. Empty means the flow ends here. */\n readonly to: readonly string[];\n /**\n * Which of {@link WizardStep.to} comes next, given everything answered so far.\n *\n * Optional, and omitting it is the ordinary case: a step with exactly one edge\n * needs no function to pick it. A step with several **must** declare one, or\n * the definition cannot say where it goes.\n *\n * It returns a step id and never `undefined`: **the end of the flow is an\n * empty `to`, not a `next` that declines**. Two ways of saying the same thing\n * would let a step be terminal in one of them and not the other, and it is\n * `to` that {@link assertWizardDefinition} can read.\n */\n next?(state: WizardStateLike): string;\n}\n\n/**\n * The part of the state a `next` may read.\n *\n * Declared structurally rather than importing `WizardState`, so the definition\n * module stays below the state module and neither has to import the other.\n */\nexport interface WizardStateLike {\n readonly activeStep: string;\n readonly steps: { readonly [stepId: string]: unknown };\n}\n\n/**\n * A whole wizard: its key — which is also its screen key in a workspace address\n * — and its steps, the first of which is where the flow begins.\n */\nexport interface WizardDefinition {\n readonly key: string;\n readonly steps: readonly WizardStep[];\n}\n\n/** The step a flow starts at: the first declared. */\nexport const entryStep = (definition: WizardDefinition): WizardStep => {\n const [first] = definition.steps;\n if (first === undefined) {\n throw new EntifixBuildError(`wizard \"${definition.key}\" declares no steps`);\n }\n return first;\n};\n\n/** The step with this id, or `undefined` when the definition has none. */\nexport const findStep = (\n definition: WizardDefinition,\n stepId: string,\n): WizardStep | undefined => definition.steps.find(step => step.id === stepId);\n\n/**\n * Checks a definition the moment it is declared, and throws rather than\n * degrading.\n *\n * **Load time, not step time.** A wizard whose last step is missing, or whose\n * branch names a step that does not exist, must fail on the first render of any\n * surface rather than on the render of the step nobody reached — otherwise the\n * failure of the longest flow in the product arrives at the end of it. That is\n * the posture `assertLinkSourcesAreEditable` and `surfaceFor` already take.\n *\n * Six faults, each of which is silent otherwise:\n *\n * - **no steps**, which renders an empty frame with a disabled button;\n * - **a duplicate id**, which makes one step's stored value overwrite another's;\n * - **an unknown `to` target**, a typo that strands the flow mid-way;\n * - **several edges and no `next`**, which cannot say where the step goes;\n * - **a step nothing reaches**, which is either a dead branch or a missing edge;\n * - **the wrong terminal step** — the flow must end in the summary, and there\n * must be exactly one of those. A wizard ending anywhere else commits without\n * the operator ever seeing what they answered, which is not optional in a\n * long flow.\n *\n * A cycle needs no separate check: every step is reachable from the entry and\n * exactly one is terminal, so a cycle would leave the steps on it unable to\n * reach that terminal, which the walk below reports as unreachable-from-here.\n */\nexport function assertWizardDefinition(definition: WizardDefinition): void {\n const first = entryStep(definition);\n const ids = new Set<string>();\n\n for (const step of definition.steps) {\n if (ids.has(step.id)) {\n throw new EntifixBuildError(\n `wizard \"${definition.key}\" declares step \"${step.id}\" twice`,\n );\n }\n ids.add(step.id);\n }\n\n for (const step of definition.steps) {\n assertStepOptions(definition, step);\n\n for (const target of step.to) {\n if (!ids.has(target)) {\n throw new EntifixBuildError(\n `wizard \"${definition.key}\" step \"${step.id}\" leads to unknown step \"${target}\"`,\n );\n }\n }\n\n if (step.to.length > 1 && step.next === undefined) {\n throw new EntifixBuildError(\n `wizard \"${definition.key}\" step \"${step.id}\" has ${step.to.length} edges and no next()`,\n );\n }\n }\n\n assertOneSummaryAtTheEnd(definition);\n assertEveryStepIsReachable(definition, first);\n}\n\n/** `options` belongs to `choice` and to nothing else. */\nfunction assertStepOptions(\n definition: WizardDefinition,\n step: WizardStep,\n): void {\n if (step.kind === 'choice') {\n if (step.options === undefined || step.options.length === 0) {\n throw new EntifixBuildError(\n `wizard \"${definition.key}\" choice step \"${step.id}\" offers no options`,\n );\n }\n return;\n }\n if (step.options !== undefined) {\n throw new EntifixBuildError(\n `wizard \"${definition.key}\" step \"${step.id}\" is a ${step.kind} step and cannot declare options`,\n );\n }\n}\n\n/** Exactly one summary, and it is the only step the flow may end on. */\nfunction assertOneSummaryAtTheEnd(definition: WizardDefinition): void {\n const summaries = definition.steps.filter(step => step.kind === 'summary');\n if (summaries.length !== 1) {\n throw new EntifixBuildError(\n `wizard \"${definition.key}\" declares ${summaries.length} summary steps, and must declare exactly one`,\n );\n }\n\n for (const step of definition.steps) {\n const terminal = step.to.length === 0;\n if (terminal && step.kind !== 'summary') {\n throw new EntifixBuildError(\n `wizard \"${definition.key}\" ends on \"${step.id}\", which is not its summary`,\n );\n }\n if (!terminal && step.kind === 'summary') {\n throw new EntifixBuildError(\n `wizard \"${definition.key}\" summary step \"${step.id}\" leads onward, and must end the flow`,\n );\n }\n }\n}\n\n/** Every declared step is on some path out of the entry step. */\nfunction assertEveryStepIsReachable(\n definition: WizardDefinition,\n first: WizardStep,\n): void {\n const seen = new Set<string>([first.id]);\n\n // A fixpoint over `seen` rather than a queue of resolved steps: every target\n // has already been checked to name a declared step, so a walk that looked one\n // up would carry an `undefined` arm nothing can reach — and an unreachable\n // arm is indistinguishable from an untested one.\n for (let grew = true; grew;) {\n grew = false;\n for (const step of definition.steps) {\n if (!seen.has(step.id)) continue;\n for (const target of step.to) {\n if (seen.has(target)) continue;\n seen.add(target);\n grew = true;\n }\n }\n }\n\n const stranded = definition.steps\n .filter(step => !seen.has(step.id))\n .map(step => step.id);\n\n if (stranded.length > 0) {\n throw new EntifixBuildError(\n `wizard \"${definition.key}\" cannot reach ${stranded.map(id => `\"${id}\"`).join(', ')} from \"${first.id}\"`,\n );\n }\n}\n"],"names":["EntifixBuildError","WizardStepKinds","entryStep","definition","first","steps","undefined","key","findStep","stepId","find","step","id","assertWizardDefinition","ids","Set","has","add","assertStepOptions","target","to","length","next","assertOneSummaryAtTheEnd","assertEveryStepIsReachable","kind","options","summaries","filter","terminal","seen","grew","stranded","map","join"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,0CAA0C;AAE5E;;;;;;;CAOC,GACD,OAAO,MAAMC,kBAAkB;IAC7B;IACA;IACA;IACA;IACA;CACD,CAAU;AAmEX,mDAAmD,GACnD,OAAO,MAAMC,YAAY,CAACC;IACxB,MAAM,CAACC,MAAM,GAAGD,WAAWE,KAAK;IAChC,IAAID,UAAUE,WAAW;QACvB,MAAM,IAAIN,kBAAkB,CAAC,QAAQ,EAAEG,WAAWI,GAAG,CAAC,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2BACPrB,UAA4B,EAC5BC,KAAiB;IAEjB,MAAM0B,OAAO,IAAIf,IAAY;QAACX,MAAMQ,EAAE;KAAC;IAEvC,6EAA6E;IAC7E,8EAA8E;IAC9E,2EAA2E;IAC3E,iDAAiD;IACjD,IAAK,IAAImB,OAAO,MAAMA,MAAO;QAC3BA,OAAO;QACP,KAAK,MAAMpB,QAAQR,WAAWE,KAAK,CAAE;YACnC,IAAI,CAACyB,KAAKd,GAAG,CAACL,KAAKC,EAAE,GAAG;YACxB,KAAK,MAAMO,UAAUR,KAAKS,EAAE,CAAE;gBAC5B,IAAIU,KAAKd,GAAG,CAACG,SAAS;gBACtBW,KAAKb,GAAG,CAACE;gBACTY,OAAO;YACT;QACF;IACF;IAEA,MAAMC,WAAW7B,WAAWE,KAAK,CAC9BuB,MAAM,CAACjB,CAAAA,OAAQ,CAACmB,KAAKd,GAAG,CAACL,KAAKC,EAAE,GAChCqB,GAAG,CAACtB,CAAAA,OAAQA,KAAKC,EAAE;IAEtB,IAAIoB,SAASX,MAAM,GAAG,GAAG;QACvB,MAAM,IAAIrB,kBACR,CAAC,QAAQ,EAAEG,WAAWI,GAAG,CAAC,eAAe,EAAEyB,SAASC,GAAG,CAACrB,CAAAA,KAAM,CAAC,CAAC,EAAEA,GAAG,CAAC,CAAC,EAAEsB,IAAI,CAAC,MAAM,OAAO,EAAE9B,MAAMQ,EAAE,CAAC,CAAC,CAAC;IAE5G;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/wizard/wizard-definition.ts"],"sourcesContent":["/**\n * What a step holds, which decides how its value is stored and edited.\n *\n * `form` is one `useEntityForm` instance over part of an entity; `selection` is\n * a table step whose value is a set of ids; `choice` is a branch point offering\n * a fixed list of options; `summary` is the read-only recap; `custom` is\n * anything else the host renders and reads itself.\n */\nexport const WizardStepKinds = [\n 'form',\n 'selection',\n 'choice',\n 'summary',\n 'custom',\n] as const;\nexport type WizardStepKind = (typeof WizardStepKinds)[number];\n\n/**\n * One step, and the edges out of it.\n *\n * **The graph is data; `next` only chooses along it.** `to` lists the steps this\n * one may lead to, so reachability, unknown targets, cycles and terminality are\n * decidable by reading the definition — no probing, no enumeration of the state\n * space, and no rule that \"only appears to hold\" because a `next` reading a form\n * value could never be enumerated. It is the move a saga definition makes for\n * its steps, for the same reason: a walkable definition is checkable\n * at load, and a function is not.\n *\n * A step with an empty `to` is **terminal**, and\n * {@link assertWizardDefinition} requires that to be the summary.\n */\nexport interface WizardStep {\n readonly id: string;\n readonly kind: WizardStepKind;\n /** Catalog key for the stepper's label. Resolved by the renderer, never here. */\n readonly labelKey: string;\n /**\n * The options a `choice` step offers, as stable identifiers.\n *\n * Required on `choice` and forbidden elsewhere: the value of a choice step is\n * one of these strings, so a choice with no options can never be answered and\n * options on a form step describe nothing.\n */\n readonly options?: readonly string[];\n /** Every step this one may lead to. Empty means the flow ends here. */\n readonly to: readonly string[];\n /**\n * Which of {@link WizardStep.to} comes next, given everything answered so far.\n *\n * Optional, and omitting it is the ordinary case: a step with exactly one edge\n * needs no function to pick it. A step with several **must** declare one, or\n * the definition cannot say where it goes.\n *\n * It returns a step id and never `undefined`: **the end of the flow is an\n * empty `to`, not a `next` that declines**. Two ways of saying the same thing\n * would let a step be terminal in one of them and not the other, and it is\n * `to` that {@link assertWizardDefinition} can read.\n */\n next?(state: WizardStateLike): string;\n}\n\n/**\n * The part of the state a `next` may read.\n *\n * Declared structurally rather than importing `WizardState`, so the definition\n * module stays below the state module and neither has to import the other.\n */\nexport interface WizardStateLike {\n readonly activeStep: string;\n readonly steps: { readonly [stepId: string]: unknown };\n}\n\n/**\n * A whole wizard: its key — which is also its screen key in a workspace address\n * — and its steps, the first of which is where the flow begins.\n */\nexport interface WizardDefinition {\n readonly key: string;\n readonly steps: readonly WizardStep[];\n}\n\n/** The step a flow starts at: the first declared. */\nexport const entryStep = (definition: WizardDefinition): WizardStep => {\n const [first] = definition.steps;\n if (first === undefined) {\n throw new Error(`wizard \"${definition.key}\" declares no steps`);\n }\n return first;\n};\n\n/** The step with this id, or `undefined` when the definition has none. */\nexport const findStep = (\n definition: WizardDefinition,\n stepId: string,\n): WizardStep | undefined => definition.steps.find(step => step.id === stepId);\n\n/**\n * Checks a definition the moment it is declared, and throws rather than\n * degrading.\n *\n * **Load time, not step time.** A wizard whose last step is missing, or whose\n * branch names a step that does not exist, must fail on the first render of any\n * surface rather than on the render of the step nobody reached — otherwise the\n * failure of the longest flow in the product arrives at the end of it. That is\n * the posture `assertLinkSourcesAreEditable` and `surfaceFor` already take.\n *\n * Six faults, each of which is silent otherwise:\n *\n * - **no steps**, which renders an empty frame with a disabled button;\n * - **a duplicate id**, which makes one step's stored value overwrite another's;\n * - **an unknown `to` target**, a typo that strands the flow mid-way;\n * - **several edges and no `next`**, which cannot say where the step goes;\n * - **a step nothing reaches**, which is either a dead branch or a missing edge;\n * - **the wrong terminal step** — the flow must end in the summary, and there\n * must be exactly one of those. A wizard ending anywhere else commits without\n * the operator ever seeing what they answered, which is not optional in a\n * long flow.\n *\n * A cycle needs no separate check: every step is reachable from the entry and\n * exactly one is terminal, so a cycle would leave the steps on it unable to\n * reach that terminal, which the walk below reports as unreachable-from-here.\n */\nexport function assertWizardDefinition(definition: WizardDefinition): void {\n const first = entryStep(definition);\n const ids = new Set<string>();\n\n for (const step of definition.steps) {\n if (ids.has(step.id)) {\n throw new Error(\n `wizard \"${definition.key}\" declares step \"${step.id}\" twice`,\n );\n }\n ids.add(step.id);\n }\n\n for (const step of definition.steps) {\n assertStepOptions(definition, step);\n\n for (const target of step.to) {\n if (!ids.has(target)) {\n throw new Error(\n `wizard \"${definition.key}\" step \"${step.id}\" leads to unknown step \"${target}\"`,\n );\n }\n }\n\n if (step.to.length > 1 && step.next === undefined) {\n throw new Error(\n `wizard \"${definition.key}\" step \"${step.id}\" has ${step.to.length} edges and no next()`,\n );\n }\n }\n\n assertOneSummaryAtTheEnd(definition);\n assertEveryStepIsReachable(definition, first);\n}\n\n/** `options` belongs to `choice` and to nothing else. */\nfunction assertStepOptions(\n definition: WizardDefinition,\n step: WizardStep,\n): void {\n if (step.kind === 'choice') {\n if (step.options === undefined || step.options.length === 0) {\n throw new Error(\n `wizard \"${definition.key}\" choice step \"${step.id}\" offers no options`,\n );\n }\n return;\n }\n if (step.options !== undefined) {\n throw new Error(\n `wizard \"${definition.key}\" step \"${step.id}\" is a ${step.kind} step and cannot declare options`,\n );\n }\n}\n\n/** Exactly one summary, and it is the only step the flow may end on. */\nfunction assertOneSummaryAtTheEnd(definition: WizardDefinition): void {\n const summaries = definition.steps.filter(step => step.kind === 'summary');\n if (summaries.length !== 1) {\n throw new Error(\n `wizard \"${definition.key}\" declares ${summaries.length} summary steps, and must declare exactly one`,\n );\n }\n\n for (const step of definition.steps) {\n const terminal = step.to.length === 0;\n if (terminal && step.kind !== 'summary') {\n throw new Error(\n `wizard \"${definition.key}\" ends on \"${step.id}\", which is not its summary`,\n );\n }\n if (!terminal && step.kind === 'summary') {\n throw new Error(\n `wizard \"${definition.key}\" summary step \"${step.id}\" leads onward, and must end the flow`,\n );\n }\n }\n}\n\n/** Every declared step is on some path out of the entry step. */\nfunction assertEveryStepIsReachable(\n definition: WizardDefinition,\n first: WizardStep,\n): void {\n const seen = new Set<string>([first.id]);\n\n // A fixpoint over `seen` rather than a queue of resolved steps: every target\n // has already been checked to name a declared step, so a walk that looked one\n // up would carry an `undefined` arm nothing can reach — and an unreachable\n // arm is indistinguishable from an untested one.\n for (let grew = true; grew;) {\n grew = false;\n for (const step of definition.steps) {\n if (!seen.has(step.id)) continue;\n for (const target of step.to) {\n if (seen.has(target)) continue;\n seen.add(target);\n grew = true;\n }\n }\n }\n\n const stranded = definition.steps\n .filter(step => !seen.has(step.id))\n .map(step => step.id);\n\n if (stranded.length > 0) {\n throw new Error(\n `wizard \"${definition.key}\" cannot reach ${stranded.map(id => `\"${id}\"`).join(', ')} from \"${first.id}\"`,\n );\n }\n}\n"],"names":["WizardStepKinds","entryStep","definition","first","steps","undefined","Error","key","findStep","stepId","find","step","id","assertWizardDefinition","ids","Set","has","add","assertStepOptions","target","to","length","next","assertOneSummaryAtTheEnd","assertEveryStepIsReachable","kind","options","summaries","filter","terminal","seen","grew","stranded","map","join"],"mappings":"AAAA;;;;;;;CAOC,GACD,OAAO,MAAMA,kBAAkB;IAC7B;IACA;IACA;IACA;IACA;CACD,CAAU;AAmEX,mDAAmD,GACnD,OAAO,MAAMC,YAAY,CAACC;IACxB,MAAM,CAACC,MAAM,GAAGD,WAAWE,KAAK;IAChC,IAAID,UAAUE,WAAW;QACvB,MAAM,IAAIC,MAAM,CAAC,QAAQ,EAAEJ,WAAWK,GAAG,CAAC,mBAAmB,CAAC;IAChE;IACA,OAAOJ;AACT,EAAE;AAEF,wEAAwE,GACxE,OAAO,MAAMK,WAAW,CACtBN,YACAO,SAC2BP,WAAWE,KAAK,CAACM,IAAI,CAACC,CAAAA,OAAQA,KAAKC,EAAE,KAAKH,QAAQ;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;CAyBC,GACD,OAAO,SAASI,uBAAuBX,UAA4B;IACjE,MAAMC,QAAQF,UAAUC;IACxB,MAAMY,MAAM,IAAIC;IAEhB,KAAK,MAAMJ,QAAQT,WAAWE,KAAK,CAAE;QACnC,IAAIU,IAAIE,GAAG,CAACL,KAAKC,EAAE,GAAG;YACpB,MAAM,IAAIN,MACR,CAAC,QAAQ,EAAEJ,WAAWK,GAAG,CAAC,iBAAiB,EAAEI,KAAKC,EAAE,CAAC,OAAO,CAAC;QAEjE;QACAE,IAAIG,GAAG,CAACN,KAAKC,EAAE;IACjB;IAEA,KAAK,MAAMD,QAAQT,WAAWE,KAAK,CAAE;QACnCc,kBAAkBhB,YAAYS;QAE9B,KAAK,MAAMQ,UAAUR,KAAKS,EAAE,CAAE;YAC5B,IAAI,CAACN,IAAIE,GAAG,CAACG,SAAS;gBACpB,MAAM,IAAIb,MACR,CAAC,QAAQ,EAAEJ,WAAWK,GAAG,CAAC,QAAQ,EAAEI,KAAKC,EAAE,CAAC,yBA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AAMS,EAAE,CAAC,CAAC,CAAC;IAE5G;AACF"}
|
|
@@ -8,7 +8,7 @@ export type WizardStepStatus = (typeof WizardStepStatuses)[number];
|
|
|
8
8
|
*
|
|
9
9
|
* A step with one edge needs no `next`; a step with several declares one, and
|
|
10
10
|
* what it returns **must** be an edge the step declared. That check is an
|
|
11
|
-
*
|
|
11
|
+
* a plain `Error` rather than a silent fallback because the two ways
|
|
12
12
|
* of being wrong are both invisible otherwise: returning an id from another
|
|
13
13
|
* branch strands the operator on a step whose earlier answers were never given,
|
|
14
14
|
* and returning a typo would read as "this wizard has ended" one step early.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wizard-navigation.d.ts","sourceRoot":"","sources":["../../src/wizard/wizard-navigation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wizard-navigation.d.ts","sourceRoot":"","sources":["../../src/wizard/wizard-navigation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,uCAAuC;AACvC,eAAO,MAAM,kBAAkB,qDAKrB,CAAC;AACX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnE;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACxB,UAAU,EAAE,gBAAgB,EAC5B,KAAK,EAAE,WAAW,GACjB,MAAM,GAAG,SAAS,CAcpB;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,UAAU,EAAE,gBAAgB,EAC5B,KAAK,EAAE,WAAW,GACjB,WAAW,CASb;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW,CAS5D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,MAAM,GACb,WAAW,CASb;AAED,4EAA4E;AAC5E,eAAO,MAAM,SAAS,GACpB,YAAY,gBAAgB,EAC5B,OAAO,WAAW,KACjB,OAAsD,CAAC;AAE1D;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,UAAU,CACxB,UAAU,EAAE,gBAAgB,EAC5B,KAAK,EAAE,WAAW,GACjB,SAAS,MAAM,EAAE,CAcnB;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC1B,UAAU,EAAE,gBAAgB,EAC5B,KAAK,EAAE,WAAW,EAClB,OAAO,GAAE,SAAS,MAAM,EAAO,GAC9B,aAAa,CAAC;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAA;CAAE,CAAC,CAO3E"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
-
import { EntifixLogicError } from '../base-entities/entifix-error/index.js';
|
|
3
2
|
import { findStep } from './wizard-definition.js';
|
|
4
3
|
/** How a step reads in the stepper. */ export const WizardStepStatuses = [
|
|
5
4
|
'pending',
|
|
@@ -12,7 +11,7 @@ import { findStep } from './wizard-definition.js';
|
|
|
12
11
|
*
|
|
13
12
|
* A step with one edge needs no `next`; a step with several declares one, and
|
|
14
13
|
* what it returns **must** be an edge the step declared. That check is an
|
|
15
|
-
*
|
|
14
|
+
* a plain `Error` rather than a silent fallback because the two ways
|
|
16
15
|
* of being wrong are both invisible otherwise: returning an id from another
|
|
17
16
|
* branch strands the operator on a step whose earlier answers were never given,
|
|
18
17
|
* and returning a typo would read as "this wizard has ended" one step early.
|
|
@@ -24,7 +23,7 @@ import { findStep } from './wizard-definition.js';
|
|
|
24
23
|
// step ends a flow by declaring no edges rather than by returning nothing.
|
|
25
24
|
const chosen = (_ref = step.next == null ? void 0 : step.next.call(step, state)) != null ? _ref : step.to[0];
|
|
26
25
|
if (!step.to.includes(chosen)) {
|
|
27
|
-
throw new
|
|
26
|
+
throw new Error(`wizard "${definition.key}" step "${step.id}" chose "${chosen}", which is not one of its edges`);
|
|
28
27
|
}
|
|
29
28
|
return chosen;
|
|
30
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/wizard/wizard-navigation.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/wizard/wizard-navigation.ts"],"sourcesContent":["import { findStep, type WizardDefinition } from './wizard-definition.js';\nimport type { WizardState } from './wizard-state.js';\n\n/** How a step reads in the stepper. */\nexport const WizardStepStatuses = [\n 'pending',\n 'active',\n 'complete',\n 'error',\n] as const;\nexport type WizardStepStatus = (typeof WizardStepStatuses)[number];\n\n/**\n * Where the active step leads, or `undefined` when it ends the flow.\n *\n * A step with one edge needs no `next`; a step with several declares one, and\n * what it returns **must** be an edge the step declared. That check is an\n * a plain `Error` rather than a silent fallback because the two ways\n * of being wrong are both invisible otherwise: returning an id from another\n * branch strands the operator on a step whose earlier answers were never given,\n * and returning a typo would read as \"this wizard has ended\" one step early.\n */\nexport function nextStepId(\n definition: WizardDefinition,\n state: WizardState,\n): string | undefined {\n const step = findStep(definition, state.activeStep);\n if (step === undefined || step.to.length === 0) return undefined;\n\n // `to` is non-empty here, so the fallback always resolves — which is why a\n // step ends a flow by declaring no edges rather than by returning nothing.\n const chosen = step.next?.(state) ?? step.to[0];\n\n if (!step.to.includes(chosen)) {\n throw new Error(\n `wizard \"${definition.key}\" step \"${step.id}\" chose \"${chosen}\", which is not one of its edges`,\n );\n }\n return chosen;\n}\n\n/**\n * The state one step further on, or the same state when there is nowhere to go.\n *\n * Unchanged rather than throwing on a terminal step: the button that calls this\n * is the one {@link canFinish} turns into Finalizar, so reaching here means the\n * caller asked twice, not that the definition is wrong.\n */\nexport function advanceWizard(\n definition: WizardDefinition,\n state: WizardState,\n): WizardState {\n const next = nextStepId(definition, state);\n if (next === undefined) return state;\n\n return {\n ...state,\n activeStep: next,\n history: [...state.history, state.activeStep],\n };\n}\n\n/**\n * The state one step back, or the same state at the entry step.\n *\n * It pops {@link WizardState.history} rather than inverting `next`, which is the\n * whole reason that history is stored: a branch's inverse is ambiguous the\n * moment an earlier answer changes, so a computed one walks the operator back\n * through a path they were never on.\n */\nexport function goBackWizard(state: WizardState): WizardState {\n const previous = state.history.at(-1);\n if (previous === undefined) return state;\n\n return {\n ...state,\n activeStep: previous,\n history: state.history.slice(0, -1),\n };\n}\n\n/**\n * Jump to a step already visited.\n *\n * Backwards only, and to a step **on the current path** — a stepper may make a\n * completed step clickable, and nothing else. Jumping forward would skip the\n * per-step submit that validates the steps in between, which is the one thing\n * gating advancement at all; jumping to a step on an abandoned branch would put\n * the operator somewhere their current answers do not lead.\n *\n * The history truncates to before the target, exactly as arriving there by\n * pressing Back repeatedly would leave it.\n */\nexport function goToWizardStep(\n state: WizardState,\n stepId: string,\n): WizardState {\n const index = state.history.indexOf(stepId);\n if (index === -1) return state;\n\n return {\n ...state,\n activeStep: stepId,\n history: state.history.slice(0, index),\n };\n}\n\n/** Whether the active step ends the flow, so its button reads Finalizar. */\nexport const canFinish = (\n definition: WizardDefinition,\n state: WizardState,\n): boolean => nextStepId(definition, state) === undefined;\n\n/**\n * The steps this flow runs through, given what has been answered — the ones\n * already visited, the active one, and the ones ahead.\n *\n * **Projected, not the declared list.** A graph's step list contains branches\n * not taken, so rendering `definition.steps` would show a stepper promising a\n * \"duplicate\" step to an operator who chose to start blank. Walking forward from\n * the active step with the current answers is what makes the stepper honest:\n * it re-shapes as a branch point is answered, which is the visible half of the\n * step graph being a graph.\n *\n * The walk stops on a step it has already placed, which is what makes it\n * terminate: every pass either adds a step to a finite set or stops. A\n * definition that cycles therefore produces a finite path rather than hanging\n * the render — `assertWizardDefinition` has already refused such a definition at\n * load, and this exists because a render loop is a worse way to find out.\n */\nexport function wizardPath(\n definition: WizardDefinition,\n state: WizardState,\n): readonly string[] {\n const path = [...state.history, state.activeStep];\n const seen = new Set(path);\n\n let cursor = state.activeStep;\n for (;;) {\n const next = nextStepId(definition, { ...state, activeStep: cursor });\n if (next === undefined || seen.has(next)) break;\n path.push(next);\n seen.add(next);\n cursor = next;\n }\n\n return path;\n}\n\n/**\n * Each step on the projected path, with how it reads.\n *\n * `errored` is supplied by the caller rather than derived, because validity is\n * the step's own knowledge: a form step's errors live in its `useEntityForm`\n * instance, and this module is framework-free and holds none of them.\n *\n * An error wins over `complete` — a step the operator has been through and left\n * invalid is exactly the one the stepper has to point at.\n */\nexport function stepStatuses(\n definition: WizardDefinition,\n state: WizardState,\n errored: readonly string[] = [],\n): ReadonlyArray<{ readonly id: string; readonly status: WizardStepStatus }> {\n const visited = new Set(state.history);\n\n return wizardPath(definition, state).map(id => ({\n id,\n status: statusOf(id, state.activeStep, visited, errored),\n }));\n}\n\nfunction statusOf(\n id: string,\n activeStep: string,\n visited: ReadonlySet<string>,\n errored: readonly string[],\n): WizardStepStatus {\n if (errored.includes(id)) return 'error';\n if (id === activeStep) return 'active';\n return visited.has(id) ? 'complete' : 'pending';\n}\n"],"names":["findStep","WizardStepStatuses","nextStepId","definition","state","step","activeStep","undefined","to","length","chosen","next","includes","Error","key","id","advanceWizard","history","goBackWizard","previous","at","slice","goToWizardStep","stepId","index","indexOf","canFinish","wizardPath","path","seen","Set","cursor","has","push","add","stepStatuses","errored","visited","map","status","statusOf"],"mappings":";AAAA,SAASA,QAAQ,QAA+B,yBAAyB;AAGzE,qCAAqC,GACrC,OAAO,MAAMC,qBAAqB;IAChC;IACA;IACA;IACA;CACD,CAAU;AAGX;;;;;;;;;CASC,GACD,OAAO,SAASC,WACdC,UAA4B,EAC5BC,KAAkB;;IAElB,MAAMC,OAAOL,SAASG,YAAYC,MAAME,UAAU;IAClD,IAAID,SAASE,aAAaF,KAAKG,EAAE,CAACC,MAAM,KAAK,GAAG,OAAOF;IAEvD,2EAA2E;IAC3E,2EAA2E;IAC3E,MAAMG,iBAASL,KAAKM,IAAI,oBAATN,KAAKM,IAAI,MAAT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AAO,IAAIC,IAAIF;IAErB,IAAIG,SAAS3B,MAAME,UAAU;IAC7B,OAAS;QACP,MAAMK,OAAOT,WAAWC,YAAY,aAAKC;YAAOE,YAAYyB;;QAC5D,IAAIpB,SAASJ,aAAasB,KAAKG,GAAG,CAACrB,OAAO;QAC1CiB,KAAKK,IAAI,CAACtB;QACVkB,KAAKK,GAAG,CAACvB;QACToB,SAASpB;IACX;IAEA,OAAOiB;AACT;AAEA;;;;;;;;;CASC,GACD,OAAO,SAASO,aACdhC,UAA4B,EAC5BC,KAAkB,EAClBgC,UAA6B,EAAE;IAE/B,MAAMC,UAAU,IAAIP,IAAI1B,MAAMa,OAAO;IAErC,OAAOU,WAAWxB,YAAYC,OAAOkC,GAAG,CAACvB,CAAAA,KAAO,CAAA;YAC9CA;YACAwB,QAAQC,SAASzB,IAAIX,MAAME,UAAU,EAAE+B,SAASD;QAClD,CAAA;AACF;AAEA,SAASI,SACPzB,EAAU,EACVT,UAAkB,EAClB+B,OAA4B,EAC5BD,OAA0B;IAE1B,IAAIA,QAAQxB,QAAQ,CAACG,KAAK,OAAO;IACjC,IAAIA,OAAOT,YAAY,OAAO;IAC9B,OAAO+B,QAAQL,GAAG,CAACjB,MAAM,aAAa;AACxC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entifix/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "The entity system: decorators that make a class describe itself, entity serialization, the RSQL query protocol and the wire envelopes.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -53,9 +53,9 @@
|
|
|
53
53
|
"@swc/helpers": "0.5.23"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"effect": "^4.0.
|
|
56
|
+
"effect": "^4.0.7"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"effect": "4.0.
|
|
59
|
+
"effect": "4.0.7"
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export declare abstract class EntifixError extends Error {
|
|
2
|
-
abstract readonly _tag: string;
|
|
3
|
-
readonly cause: Error | undefined;
|
|
4
|
-
readonly details?: Record<string, unknown>;
|
|
5
|
-
constructor(message: string, cause?: unknown, details?: Record<string, unknown>);
|
|
6
|
-
}
|
|
7
|
-
export declare class EntifixBuildError extends EntifixError {
|
|
8
|
-
_tag: string;
|
|
9
|
-
}
|
|
10
|
-
export declare class EntifixLogicError extends EntifixError {
|
|
11
|
-
_tag: string;
|
|
12
|
-
}
|
|
13
|
-
export declare class EntifixConnError extends EntifixError {
|
|
14
|
-
_tag: string;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* A transaction/saga step failed (validate, execute, rollback, free) — distinct
|
|
18
|
-
* from a lock acquisition failure, which callers retry, and from a build error,
|
|
19
|
-
* which is the client's fault.
|
|
20
|
-
*/
|
|
21
|
-
export declare class EntifixTransactionError extends EntifixError {
|
|
22
|
-
_tag: string;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* A resource could not be locked within the allowed retries/TTL — a contention
|
|
26
|
-
* signal callers surface as a `409`/`423`, not a `500`.
|
|
27
|
-
*/
|
|
28
|
-
export declare class EntifixLockError extends EntifixError {
|
|
29
|
-
_tag: string;
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=entifix-error.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entifix-error.d.ts","sourceRoot":"","sources":["../../../src/base-entities/entifix-error/entifix-error.ts"],"names":[],"mappings":"AAUA,8BAAsB,YAAa,SAAQ,KAAK;IAE9C,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAC/B,SAAkB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;IAC3C,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAKzC,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,OAAO,EACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAOpC;AAED,qBAAa,iBAAkB,SAAQ,YAAY;IAExC,IAAI,SAAuB;CAErC;AAED,qBAAa,iBAAkB,SAAQ,YAAY;IAExC,IAAI,SAAuB;CAErC;AAED,qBAAa,gBAAiB,SAAQ,YAAY;IAEvC,IAAI,SAAsB;CAEpC;AAED;;;;GAIG;AACH,qBAAa,uBAAwB,SAAQ,YAAY;IAE9C,IAAI,SAA6B;CAE3C;AAED;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,YAAY;IAEvC,IAAI,SAAsB;CAEpC"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
function assertCause(cause) {
|
|
2
|
-
if (cause instanceof Error) {
|
|
3
|
-
return cause;
|
|
4
|
-
} else if (cause && typeof cause === 'object' && 'message' in cause) {
|
|
5
|
-
return new Error(String(cause['message']));
|
|
6
|
-
}
|
|
7
|
-
return undefined;
|
|
8
|
-
}
|
|
9
|
-
export class EntifixError extends Error {
|
|
10
|
-
// #endregion properties
|
|
11
|
-
// #region constructors
|
|
12
|
-
constructor(message, cause, details){
|
|
13
|
-
super(message);
|
|
14
|
-
this.cause = assertCause(cause);
|
|
15
|
-
this.details = details;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
export class EntifixBuildError extends EntifixError {
|
|
19
|
-
constructor(...args){
|
|
20
|
-
super(...args), // #region properties
|
|
21
|
-
this._tag = 'EntifixBuildError';
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
export class EntifixLogicError extends EntifixError {
|
|
25
|
-
constructor(...args){
|
|
26
|
-
super(...args), // #region properties
|
|
27
|
-
this._tag = 'EntifixLogicError';
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
export class EntifixConnError extends EntifixError {
|
|
31
|
-
constructor(...args){
|
|
32
|
-
super(...args), // #region properties
|
|
33
|
-
this._tag = 'EntifixConnError';
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* A transaction/saga step failed (validate, execute, rollback, free) — distinct
|
|
38
|
-
* from a lock acquisition failure, which callers retry, and from a build error,
|
|
39
|
-
* which is the client's fault.
|
|
40
|
-
*/ export class EntifixTransactionError extends EntifixError {
|
|
41
|
-
constructor(...args){
|
|
42
|
-
super(...args), // #region properties
|
|
43
|
-
this._tag = 'EntifixTransactionError';
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* A resource could not be locked within the allowed retries/TTL — a contention
|
|
48
|
-
* signal callers surface as a `409`/`423`, not a `500`.
|
|
49
|
-
*/ export class EntifixLockError extends EntifixError {
|
|
50
|
-
constructor(...args){
|
|
51
|
-
super(...args), // #region properties
|
|
52
|
-
this._tag = 'EntifixLockError';
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
//# sourceMappingURL=entifix-error.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/base-entities/entifix-error/entifix-error.ts"],"sourcesContent":["function assertCause(cause: unknown): Error | undefined {\n if (cause instanceof Error) {\n return cause;\n } else if (cause && typeof cause === 'object' && 'message' in cause) {\n return new Error(String(cause['message']));\n }\n\n return undefined;\n}\n\nexport abstract class EntifixError extends Error {\n // #region properties\n abstract readonly _tag: string;\n override readonly cause: Error | undefined;\n readonly details?: Record<string, unknown>;\n // #endregion properties\n\n // #region constructors\n constructor(\n message: string,\n cause?: unknown,\n details?: Record<string, unknown>,\n ) {\n super(message);\n this.cause = assertCause(cause);\n this.details = details;\n }\n // #endregion constructors\n}\n\nexport class EntifixBuildError extends EntifixError {\n // #region properties\n override _tag = 'EntifixBuildError';\n // #endregion properties\n}\n\nexport class EntifixLogicError extends EntifixError {\n // #region properties\n override _tag = 'EntifixLogicError';\n // #endregion properties\n}\n\nexport class EntifixConnError extends EntifixError {\n // #region properties\n override _tag = 'EntifixConnError';\n // #endregion properties\n}\n\n/**\n * A transaction/saga step failed (validate, execute, rollback, free) — distinct\n * from a lock acquisition failure, which callers retry, and from a build error,\n * which is the client's fault.\n */\nexport class EntifixTransactionError extends EntifixError {\n // #region properties\n override _tag = 'EntifixTransactionError';\n // #endregion properties\n}\n\n/**\n * A resource could not be locked within the allowed retries/TTL — a contention\n * signal callers surface as a `409`/`423`, not a `500`.\n */\nexport class EntifixLockError extends EntifixError {\n // #region properties\n override _tag = 'EntifixLockError';\n // #endregion properties\n}\n"],"names":["assertCause","cause","Error","String","undefined","EntifixError","message","details","EntifixBuildError","_tag","EntifixLogicError","EntifixConnError","EntifixTransactionError","EntifixLockError"],"mappings":"AAAA,SAASA,YAAYC,KAAc;IACjC,IAAIA,iBAAiBC,OAAO;QAC1B,OAAOD;IACT,OAAO,IAAIA,SAAS,OAAOA,UAAU,YAAY,aAAaA,OAAO;QACnE,OAAO,IAAIC,MAAMC,OAAOF,KAAK,CAAC,UAAU;IAC1C;IAEA,OAAOG;AACT;AAEA,OAAO,MAAeC,qBAAqBH;IAKzC,wBAAwB;IAExB,uBAAuB;IACvB,YACEI,OAAe,EACfL,KAAe,EACfM,OAAiC,CACjC;QACA,KAAK,CAACD;QACN,IAAI,CAACL,KAAK,GAAGD,YAAYC;QACzB,IAAI,CAACM,OAAO,GAAGA;IACjB;AAEF;AAEA,OAAO,MAAMC,0BAA0BH;;QAAhC,gBACL,qBAAqB;aACZI,OAAO;;AAElB;AAEA,OAAO,MAAMC,0BAA0BL;;QAAhC,gBACL,qBAAqB;aACZI,OAAO;;AAElB;AAEA,OAAO,MAAME,yBAAyBN;;QAA/B,gBACL,qBAAqB;aACZI,OAAO;;AAElB;AAEA;;;;CAIC,GACD,OAAO,MAAMG,gCAAgCP;;QAAtC,gBACL,qBAAqB;aACZI,OAAO;;AAElB;AAEA;;;CAGC,GACD,OAAO,MAAMI,yBAAyBR;;QAA/B,gBACL,qBAAqB;aACZI,OAAO;;AAElB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/base-entities/entifix-error/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/base-entities/entifix-error/index.ts"],"sourcesContent":["export * from './entifix-error.js';\n"],"names":[],"mappings":"AAAA,cAAc,qBAAqB"}
|