lanka 1.0.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.
Files changed (97) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +242 -0
  3. package/dist/ALankaGateway-ExlRGT3D.d.ts +122 -0
  4. package/dist/ALankaSharedStore-B7uepuuk.d.ts +29 -0
  5. package/dist/ILankaApiError-zI_2bNs0.d.ts +16 -0
  6. package/dist/ILankaRuntimeConfig-Vl436GWK.d.ts +62 -0
  7. package/dist/ILankaScenarioMetadata-Bu-yggTZ.d.ts +14 -0
  8. package/dist/ILankaScenarioVM-DuCyPoyT.d.ts +260 -0
  9. package/dist/LankaError-B1HtuIkw.d.ts +86 -0
  10. package/dist/LankaScenarioLocator-BGQHwf3n.d.ts +144 -0
  11. package/dist/LankaSharedStoreLocator-MvCpav5F.d.ts +126 -0
  12. package/dist/TLankaErrorHandler-Yfqtdh1M.d.ts +3 -0
  13. package/dist/_extend/index.d.ts +34 -0
  14. package/dist/_extend/index.js +36 -0
  15. package/dist/_extend/index.js.map +1 -0
  16. package/dist/_internal/index.d.ts +43 -0
  17. package/dist/_internal/index.js +34 -0
  18. package/dist/_internal/index.js.map +1 -0
  19. package/dist/activeRuntime-FcsSJvUg.d.ts +84 -0
  20. package/dist/bootstrap/index.d.ts +242 -0
  21. package/dist/bootstrap/index.js +22 -0
  22. package/dist/bootstrap/index.js.map +1 -0
  23. package/dist/chunk-73IVH3C6.js +52 -0
  24. package/dist/chunk-73IVH3C6.js.map +1 -0
  25. package/dist/chunk-BGVDPDX4.js +29 -0
  26. package/dist/chunk-BGVDPDX4.js.map +1 -0
  27. package/dist/chunk-C2HP7CRD.js +224 -0
  28. package/dist/chunk-C2HP7CRD.js.map +1 -0
  29. package/dist/chunk-D27MREPB.js +13 -0
  30. package/dist/chunk-D27MREPB.js.map +1 -0
  31. package/dist/chunk-DTO27QFR.js +59 -0
  32. package/dist/chunk-DTO27QFR.js.map +1 -0
  33. package/dist/chunk-EWVDJYCC.js +296 -0
  34. package/dist/chunk-EWVDJYCC.js.map +1 -0
  35. package/dist/chunk-FIR4XTBL.js +136 -0
  36. package/dist/chunk-FIR4XTBL.js.map +1 -0
  37. package/dist/chunk-ILQNYQY5.js +200 -0
  38. package/dist/chunk-ILQNYQY5.js.map +1 -0
  39. package/dist/chunk-J5LA3Q6D.js +14 -0
  40. package/dist/chunk-J5LA3Q6D.js.map +1 -0
  41. package/dist/chunk-MDZ42XRH.js +10 -0
  42. package/dist/chunk-MDZ42XRH.js.map +1 -0
  43. package/dist/chunk-Q3SOVBIJ.js +176 -0
  44. package/dist/chunk-Q3SOVBIJ.js.map +1 -0
  45. package/dist/chunk-Q7QESSYF.js +49 -0
  46. package/dist/chunk-Q7QESSYF.js.map +1 -0
  47. package/dist/chunk-RKYKK6MN.js +19 -0
  48. package/dist/chunk-RKYKK6MN.js.map +1 -0
  49. package/dist/chunk-RYFZCAQ3.js +637 -0
  50. package/dist/chunk-RYFZCAQ3.js.map +1 -0
  51. package/dist/chunk-UJEC7H6K.js +39 -0
  52. package/dist/chunk-UJEC7H6K.js.map +1 -0
  53. package/dist/chunk-XESL274R.js +23 -0
  54. package/dist/chunk-XESL274R.js.map +1 -0
  55. package/dist/chunk-YR4MZXMU.js +13 -0
  56. package/dist/chunk-YR4MZXMU.js.map +1 -0
  57. package/dist/config/index.d.ts +63 -0
  58. package/dist/config/index.js +16 -0
  59. package/dist/config/index.js.map +1 -0
  60. package/dist/createLankaScope-Bc_vChRs.d.ts +30 -0
  61. package/dist/errors/index.d.ts +37 -0
  62. package/dist/errors/index.js +16 -0
  63. package/dist/errors/index.js.map +1 -0
  64. package/dist/gateway/index.d.ts +258 -0
  65. package/dist/gateway/index.js +438 -0
  66. package/dist/gateway/index.js.map +1 -0
  67. package/dist/index.d.ts +20 -0
  68. package/dist/index.js +43 -0
  69. package/dist/index.js.map +1 -0
  70. package/dist/lankaHttpInFlight-Bk1eIuSx.d.ts +43 -0
  71. package/dist/lankaRequestMiddleware-DAC5kCb7.d.ts +62 -0
  72. package/dist/lankaStandardValidator-CL-r-zEV.d.ts +34 -0
  73. package/dist/locator/index.d.ts +282 -0
  74. package/dist/locator/index.js +67 -0
  75. package/dist/locator/index.js.map +1 -0
  76. package/dist/logger/index.d.ts +146 -0
  77. package/dist/logger/index.js +11 -0
  78. package/dist/logger/index.js.map +1 -0
  79. package/dist/mock/index.d.ts +16 -0
  80. package/dist/mock/index.js +58 -0
  81. package/dist/mock/index.js.map +1 -0
  82. package/dist/role/index.d.ts +48 -0
  83. package/dist/role/index.js +7 -0
  84. package/dist/role/index.js.map +1 -0
  85. package/dist/scenario/index.d.ts +204 -0
  86. package/dist/scenario/index.js +28 -0
  87. package/dist/scenario/index.js.map +1 -0
  88. package/dist/validation/index.d.ts +18 -0
  89. package/dist/validation/index.js +53 -0
  90. package/dist/validation/index.js.map +1 -0
  91. package/dist/viewmodel/index.d.ts +478 -0
  92. package/dist/viewmodel/index.js +701 -0
  93. package/dist/viewmodel/index.js.map +1 -0
  94. package/package.json +99 -0
  95. package/skills/lanka-core/SKILL.md +241 -0
  96. package/skills/lanka-core/reference.md +1090 -0
  97. package/skills/lanka-packages/SKILL.md +70 -0
@@ -0,0 +1,176 @@
1
+ import {
2
+ ALankaScenario,
3
+ LankaScenarioVMRegistry,
4
+ LankaScenariosRegistry,
5
+ Scenarios_exports,
6
+ lankaEventBus
7
+ } from "./chunk-EWVDJYCC.js";
8
+ import {
9
+ lankaLogger
10
+ } from "./chunk-C2HP7CRD.js";
11
+ import {
12
+ getActiveRuntime,
13
+ requireActiveRuntime
14
+ } from "./chunk-BGVDPDX4.js";
15
+
16
+ // src/scenario/lanka-scenario-bootstrap/LankaScenarioBootstrap.ts
17
+ var LankaScenarioBootstrap = class {
18
+ /**
19
+ * The bootstrapped flag and the set of initialised VMs live on the INSTANCE.
20
+ *
21
+ * As static fields, a second framework in the same process would exit
22
+ * `bootstrap()` on someone else's flag — never starting at all, with no symptom
23
+ * except that no scenario works.
24
+ */
25
+ get state() {
26
+ return requireActiveRuntime().scenarioState;
27
+ }
28
+ isScenarioLayerBootstrapped() {
29
+ return this.state.bootstrapped;
30
+ }
31
+ forceInstantiateAllScenarios() {
32
+ for (const exported of Object.values(Scenarios_exports)) {
33
+ if (typeof exported !== "function") continue;
34
+ try {
35
+ new exported();
36
+ } catch {
37
+ }
38
+ }
39
+ }
40
+ registerScenarioEvents(scenarios) {
41
+ const registeredEventTypes = /* @__PURE__ */ new Set();
42
+ scenarios.forEach((scenario) => {
43
+ if (!registeredEventTypes.has(scenario.eventType)) {
44
+ registeredEventTypes.add(scenario.eventType);
45
+ lankaLogger.printScenarioLog("REGISTER SCENARIO EVENT", scenario.name);
46
+ lankaEventBus.registerEvent(scenario.eventType, {
47
+ dataType: scenario.dataTypeName,
48
+ description: `Scenario: ${scenario.name}`,
49
+ usedBy: [scenario.name],
50
+ priority: 0
51
+ });
52
+ }
53
+ if (scenario.initialize) {
54
+ lankaLogger.printScenarioLog("INITIALIZE SCENARIO", scenario.name);
55
+ scenario.initialize();
56
+ }
57
+ });
58
+ }
59
+ initializeAlreadyCreatedViewModels() {
60
+ const viewModels = LankaScenarioVMRegistry.getInstance().getAllViewModels();
61
+ viewModels.forEach((vm) => {
62
+ if (!this.state.initialized.has(vm)) {
63
+ this.state.initialized.add(vm);
64
+ vm.initializeScenario();
65
+ }
66
+ });
67
+ }
68
+ /**
69
+ * Brings up the scenario layer.
70
+ *
71
+ * Constructs the scenario classes so they can be collected, declares their
72
+ * events on the bus, calls `initialize()` where present, and initialises
73
+ * ViewModels that already exist — which happens in tests and under unusual
74
+ * import order.
75
+ *
76
+ * Idempotent.
77
+ */
78
+ bootstrap() {
79
+ if (this.state.bootstrapped) return;
80
+ lankaLogger.printScenarioLog("BOOTSTRAP SCENARIOS START");
81
+ this.forceInstantiateAllScenarios();
82
+ const registry = LankaScenariosRegistry.getInstance();
83
+ registry.collectAutoRegisteredScenarios();
84
+ const scenarios = registry.getAllScenarios();
85
+ this.registerScenarioEvents(scenarios);
86
+ this.state.bootstrapped = true;
87
+ this.initializeAlreadyCreatedViewModels();
88
+ lankaLogger.printScenarioLog("BOOTSTRAP SCENARIOS FINISH");
89
+ }
90
+ /**
91
+ * Called by a ViewModel factory when the ViewModel declares scenario handlers.
92
+ *
93
+ * Registers the ViewModel and, if the layer is already up, initialises it
94
+ * immediately. Duplicate registration and duplicate initialisation are
95
+ * impossible.
96
+ *
97
+ * @param viewModel What to register
98
+ * @param name Name for the log
99
+ */
100
+ /**
101
+ * ViewModels DECLARED in this process.
102
+ *
103
+ * Module-level deliberately, the same case as the scenario pool: a registry of
104
+ * DEFINITIONS, not runtime state. Splitting it between instances would be
105
+ * divergence, not isolation — the classes come from the same modules and both
106
+ * instances must see one list.
107
+ *
108
+ * Two reasons it exists:
109
+ *
110
+ * 1. Declaring a ViewModel is a declaration, not work. A screen file creates it
111
+ * at module level, and import order decides whether that happens before or
112
+ * after `createLanka()`. Requiring a live instance at declaration time
113
+ * requires an import order the consumer does not control.
114
+ * 2. Instances come one after another: every test creates its own. The list is
115
+ * NOT drained by the first — otherwise the second instance would know no
116
+ * module-level ViewModel and its `dispose()` would not remove their
117
+ * subscriptions, so a test would receive events the previous one subscribed
118
+ * to.
119
+ */
120
+ declaredViewModels = [];
121
+ /** Registers everything declared into a NEW instance. Called by `createLanka`. */
122
+ adoptDeclaredViewModels() {
123
+ for (const { viewModel, name } of [...this.declaredViewModels]) {
124
+ this.attachViewModel(viewModel, name);
125
+ }
126
+ }
127
+ registerViewModel(viewModel, name) {
128
+ const isKnown = this.declaredViewModels.some(
129
+ (declared) => declared.viewModel === viewModel
130
+ );
131
+ if (!isKnown) this.declaredViewModels.push({ viewModel, name });
132
+ if (!getActiveRuntime()) return;
133
+ this.attachViewModel(viewModel, name);
134
+ }
135
+ attachViewModel(viewModel, name) {
136
+ const registry = LankaScenarioVMRegistry.getInstance();
137
+ if (registry.isRegistered(viewModel)) {
138
+ if (name) {
139
+ lankaLogger.printViewModelLog("VM Already Registered (skipped)", name);
140
+ }
141
+ return;
142
+ }
143
+ registry.register(viewModel);
144
+ if (name) {
145
+ lankaLogger.printViewModelLog("Register Scenario VM", name);
146
+ }
147
+ if (this.state.bootstrapped) {
148
+ if (!this.state.initialized.has(viewModel)) {
149
+ this.state.initialized.add(viewModel);
150
+ viewModel.initializeScenario();
151
+ }
152
+ }
153
+ }
154
+ /**
155
+ * Resets the whole scenario layer. Without it tests are not isolated.
156
+ *
157
+ * Clears the self-registration list, the scenario registry with its metadata,
158
+ * the ViewModel registry together with all their subscriptions, and the bus —
159
+ * events and
160
+ * middleware.
161
+ */
162
+ reset() {
163
+ ALankaScenario.clearAutoRegisteredScenarios();
164
+ LankaScenariosRegistry.getInstance().clear();
165
+ LankaScenarioVMRegistry.getInstance().resetAll();
166
+ lankaEventBus.clearAllEvents();
167
+ this.state.bootstrapped = false;
168
+ this.state.initialized = /* @__PURE__ */ new WeakSet();
169
+ }
170
+ };
171
+ var lankaScenarioBootstrap = new LankaScenarioBootstrap();
172
+
173
+ export {
174
+ lankaScenarioBootstrap
175
+ };
176
+ //# sourceMappingURL=chunk-Q3SOVBIJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/scenario/lanka-scenario-bootstrap/LankaScenarioBootstrap.ts"],"sourcesContent":["import type { ILankaScenario } from \"../_interfaces/ILankaScenario\";\nimport type { ILankaScenarioVM } from \"../_interfaces/ILankaScenarioVM\";\nimport { LankaScenariosRegistry } from \"../_registries/lanka-scenarios-registry/LankaScenariosRegistry\";\nimport { LankaScenarioVMRegistry } from \"../_registries/lanka-scenario-vm-registry/LankaScenarioVMRegistry\";\nimport { ALankaScenario } from \"../_abstractions/lanka-scenario/ALankaScenario\";\nimport { lankaLogger } from \"../../logger/lanka-logger/LankaLogger\";\n\n/**\n * Brings up the scenario layer — deliberately React-free.\n *\n * Two jobs: declare every scenario's events on the bus as early as possible,\n * before the first ViewModel exists; and let a ViewModel raise its own\n * subscriptions at construction.\n *\n * Called from the application entry point before ViewModels are imported.\n */\n\n// The barrel of every scenario class: what keeps bootstrap in step with the list.\nimport * as ScenariosModule from \"@lanka_di/Scenarios\";\nimport { lankaEventBus } from \"../event-bus/_facades/lanka-event-bus/lankaEventBus\";\nimport {\n\tgetActiveRuntime,\n\trequireActiveRuntime,\n} from \"../../_internal/active-runtime/activeRuntime\";\n\n/**\n * Bootstrapping the scenario layer, for callers with no instance in hand.\n *\n * An ordinary class with an ordinary instance: the declared-ViewModel list below\n * is deliberately shared across instances — every test builds a new framework and\n * module-level ViewModels are declared once — so the single instance IS the\n * shared list, and a second one would be a second list nobody adopts.\n */\nexport class LankaScenarioBootstrap {\n\t/**\n\t * The bootstrapped flag and the set of initialised VMs live on the INSTANCE.\n\t *\n\t * As static fields, a second framework in the same process would exit\n\t * `bootstrap()` on someone else's flag — never starting at all, with no symptom\n\t * except that no scenario works.\n\t */\n\tprivate get state() {\n\t\treturn requireActiveRuntime().scenarioState;\n\t}\n\n\tpublic isScenarioLayerBootstrapped(): boolean {\n\t\treturn this.state.bootstrapped;\n\t}\n\n\tprivate forceInstantiateAllScenarios(): void {\n\t\tfor (const exported of Object.values(ScenariosModule)) {\n\t\t\t// Only class constructors are relevant.\n\t\t\tif (typeof exported !== \"function\") continue;\n\n\t\t\ttry {\n\t\t\t\t// Constructing an ALankaScenario subclass puts it into the\n\t\t\t\t// self-registration pool — see ALankaScenario.\n\t\t\t\tnew (exported as unknown as new () => unknown)();\n\t\t\t} catch {\n\t\t\t\t// Not every export is constructible; skip those.\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate registerScenarioEvents(scenarios: ILankaScenario<unknown>[]): void {\n\t\tconst registeredEventTypes = new Set<string>();\n\n\t\tscenarios.forEach((scenario) => {\n\t\t\tif (!registeredEventTypes.has(scenario.eventType)) {\n\t\t\t\tregisteredEventTypes.add(scenario.eventType);\n\n\t\t\t\tlankaLogger.printScenarioLog(\"REGISTER SCENARIO EVENT\", scenario.name);\n\t\t\t\tlankaEventBus.registerEvent(scenario.eventType, {\n\t\t\t\t\tdataType: scenario.dataTypeName,\n\t\t\t\t\tdescription: `Scenario: ${scenario.name}`,\n\t\t\t\t\tusedBy: [scenario.name],\n\t\t\t\t\tpriority: 0,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (scenario.initialize) {\n\t\t\t\tlankaLogger.printScenarioLog(\"INITIALIZE SCENARIO\", scenario.name);\n\t\t\t\tscenario.initialize();\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate initializeAlreadyCreatedViewModels(): void {\n\t\tconst viewModels = LankaScenarioVMRegistry.getInstance().getAllViewModels();\n\t\tviewModels.forEach((vm) => {\n\t\t\tif (!this.state.initialized.has(vm)) {\n\t\t\t\tthis.state.initialized.add(vm);\n\t\t\t\tvm.initializeScenario();\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Brings up the scenario layer.\n\t *\n\t * Constructs the scenario classes so they can be collected, declares their\n\t * events on the bus, calls `initialize()` where present, and initialises\n\t * ViewModels that already exist — which happens in tests and under unusual\n\t * import order.\n\t *\n\t * Idempotent.\n\t */\n\tpublic bootstrap(): void {\n\t\tif (this.state.bootstrapped) return;\n\n\t\tlankaLogger.printScenarioLog(\"BOOTSTRAP SCENARIOS START\");\n\n\t\t// Instances must exist, or the registry has nothing to collect.\n\t\tthis.forceInstantiateAllScenarios();\n\n\t\tconst registry = LankaScenariosRegistry.getInstance();\n\t\tregistry.collectAutoRegisteredScenarios();\n\n\t\tconst scenarios = registry.getAllScenarios();\n\t\tthis.registerScenarioEvents(scenarios);\n\n\t\tthis.state.bootstrapped = true;\n\n\t\t// Some ViewModels may predate bootstrap — in tests, or under unusual import\n\t\t// order; initialise them now.\n\t\tthis.initializeAlreadyCreatedViewModels();\n\n\t\tlankaLogger.printScenarioLog(\"BOOTSTRAP SCENARIOS FINISH\");\n\t}\n\n\t/**\n\t * Called by a ViewModel factory when the ViewModel declares scenario handlers.\n\t *\n\t * Registers the ViewModel and, if the layer is already up, initialises it\n\t * immediately. Duplicate registration and duplicate initialisation are\n\t * impossible.\n\t *\n\t * @param viewModel What to register\n\t * @param name Name for the log\n\t */\n\t/**\n\t * ViewModels DECLARED in this process.\n\t *\n\t * Module-level deliberately, the same case as the scenario pool: a registry of\n\t * DEFINITIONS, not runtime state. Splitting it between instances would be\n\t * divergence, not isolation — the classes come from the same modules and both\n\t * instances must see one list.\n\t *\n\t * Two reasons it exists:\n\t *\n\t * 1. Declaring a ViewModel is a declaration, not work. A screen file creates it\n\t * at module level, and import order decides whether that happens before or\n\t * after `createLanka()`. Requiring a live instance at declaration time\n\t * requires an import order the consumer does not control.\n\t * 2. Instances come one after another: every test creates its own. The list is\n\t * NOT drained by the first — otherwise the second instance would know no\n\t * module-level ViewModel and its `dispose()` would not remove their\n\t * subscriptions, so a test would receive events the previous one subscribed\n\t * to.\n\t */\n\tprivate readonly declaredViewModels: { viewModel: ILankaScenarioVM; name?: string }[] = [];\n\n\t/** Registers everything declared into a NEW instance. Called by `createLanka`. */\n\tpublic adoptDeclaredViewModels(): void {\n\t\tfor (const { viewModel, name } of [...this.declaredViewModels]) {\n\t\t\tthis.attachViewModel(viewModel, name);\n\t\t}\n\t}\n\n\tpublic registerViewModel(viewModel: ILankaScenarioVM, name?: string): void {\n\t\tconst isKnown = this.declaredViewModels.some(\n\t\t\t(declared) => declared.viewModel === viewModel,\n\t\t);\n\t\tif (!isKnown) this.declaredViewModels.push({ viewModel, name });\n\n\t\t// No instance yet: the declaration came before bootstrap, and whoever\n\t\t// bootstraps will pick it up.\n\t\tif (!getActiveRuntime()) return;\n\n\t\tthis.attachViewModel(viewModel, name);\n\t}\n\n\tprivate attachViewModel(viewModel: ILankaScenarioVM, name?: string): void {\n\t\tconst registry = LankaScenarioVMRegistry.getInstance();\n\n\t\t// Already registered — nothing to do.\n\t\tif (registry.isRegistered(viewModel)) {\n\t\t\tif (name) {\n\t\t\t\tlankaLogger.printViewModelLog(\"VM Already Registered (skipped)\", name);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Register it.\n\t\tregistry.register(viewModel);\n\n\t\tif (name) {\n\t\t\tlankaLogger.printViewModelLog(\"Register Scenario VM\", name);\n\t\t}\n\n\t\t// The layer is already up — initialise it now rather than at the next\n\t\t// bootstrap.\n\t\tif (this.state.bootstrapped) {\n\t\t\tif (!this.state.initialized.has(viewModel)) {\n\t\t\t\tthis.state.initialized.add(viewModel);\n\t\t\t\tviewModel.initializeScenario();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Resets the whole scenario layer. Without it tests are not isolated.\n\t *\n\t * Clears the self-registration list, the scenario registry with its metadata,\n\t * the ViewModel registry together with all their subscriptions, and the bus —\n\t * events and\n\t * middleware.\n\t */\n\tpublic reset(): void {\n\t\tALankaScenario.clearAutoRegisteredScenarios();\n\t\tLankaScenariosRegistry.getInstance().clear();\n\t\tLankaScenarioVMRegistry.getInstance().resetAll();\n\t\tlankaEventBus.clearAllEvents();\n\t\tthis.state.bootstrapped = false;\n\t\tthis.state.initialized = new WeakSet<ILankaScenarioVM>();\n\t}\n}\n\n/** The one every caller wants. */\nexport const lankaScenarioBootstrap = new LankaScenarioBootstrap();\n"],"mappings":";;;;;;;;;;;;;;;;AAiCO,IAAM,yBAAN,MAA6B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQnC,IAAY,QAAQ;AACnB,WAAO,qBAAqB,EAAE;AAAA,EAC/B;AAAA,EAEO,8BAAuC;AAC7C,WAAO,KAAK,MAAM;AAAA,EACnB;AAAA,EAEQ,+BAAqC;AAC5C,eAAW,YAAY,OAAO,OAAO,iBAAe,GAAG;AAEtD,UAAI,OAAO,aAAa,WAAY;AAEpC,UAAI;AAGH,YAAK,SAA0C;AAAA,MAChD,QAAQ;AAAA,MAER;AAAA,IACD;AAAA,EACD;AAAA,EAEQ,uBAAuB,WAA4C;AAC1E,UAAM,uBAAuB,oBAAI,IAAY;AAE7C,cAAU,QAAQ,CAAC,aAAa;AAC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/LankaError.ts
2
+ var LankaError = class _LankaError extends Error {
3
+ kind;
4
+ status;
5
+ code;
6
+ issues;
7
+ /** The parsed error response body; core carries it without reading it. */
8
+ body;
9
+ constructor(init) {
10
+ super(init.message, init.cause === void 0 ? void 0 : { cause: init.cause });
11
+ this.name = "LankaError";
12
+ this.kind = init.kind;
13
+ this.status = init.status;
14
+ this.code = init.code;
15
+ this.issues = init.issues;
16
+ this.body = init.body;
17
+ Object.setPrototypeOf(this, _LankaError.prototype);
18
+ }
19
+ /** The `ILankaApiError` field. The details are the message list. */
20
+ get errors() {
21
+ return this.issues ? [...this.issues] : void 0;
22
+ }
23
+ /**
24
+ * Whether to show this to the user.
25
+ *
26
+ * A cancelled request is the one failure that must NOT be reported: its cause
27
+ * is that the user left before the response, and a toast would catch them on
28
+ * another screen.
29
+ */
30
+ get isSilent() {
31
+ return this.kind === "aborted";
32
+ }
33
+ /**
34
+ * Recognises our error among others.
35
+ *
36
+ * Checks the name rather than `instanceof` alone: a consumer may end up with
37
+ * two copies of the package — adjacent majors in the dependency tree — and
38
+ * then `instanceof` answers `false` for an error that is ours by every other
39
+ * sign.
40
+ */
41
+ static is(value) {
42
+ return value instanceof _LankaError || value instanceof Error && value.name === "LankaError";
43
+ }
44
+ };
45
+
46
+ export {
47
+ LankaError
48
+ };
49
+ //# sourceMappingURL=chunk-Q7QESSYF.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors/lanka-error/LankaError.ts"],"sourcesContent":["import type { ILankaApiError } from \"../_interfaces/ILankaApiError\";\n\n/**\n * How a request ended.\n *\n * Six kinds rather than one, for one reason: each demands something DIFFERENT of\n * the interface. A distinction that implies no different behaviour is\n * superfluous, which is why there is no seventh.\n */\nexport type TLankaErrorKind =\n\t/** Never reached the server: dropped link, DNS failure, no network. Offer a retry. */\n\t| \"network\"\n\t/** Reached it; the response never came. Also a retry, but a different message. */\n\t| \"timeout\"\n\t/** Cancelled by the caller. Nothing to show: the user left. */\n\t| \"aborted\"\n\t/** The server answered with an error status; what to show depends on it. */\n\t| \"http\"\n\t/** A response arrived in the wrong shape. A break, not the user's fault. */\n\t| \"schema\"\n\t/** The server refused deliberately and named the reason. Show what it said. */\n\t| \"domain\";\n\nexport interface ILankaErrorInit {\n\tkind: TLankaErrorKind;\n\tmessage: string;\n\t/** HTTP status, when there was one. */\n\tstatus?: number;\n\t/** The domain failure code — what the application branches on. */\n\tcode?: string;\n\t/** Details: server messages, or paths to the fields that failed validation. */\n\tissues?: readonly string[];\n\t/**\n\t * The parsed ERROR response body, when there was one and it was JSON.\n\t *\n\t * Travels with the error because a `Response` is read once: without this field\n\t * a plugin extracting the domain failure code would read an already-drained\n\t * stream and get nothing. Core does not look into the body; it carries it.\n\t */\n\tbody?: unknown;\n\t/** The original error, when this one wraps it. */\n\tcause?: unknown;\n}\n\n/**\n * One failure type for every layer of the framework.\n *\n * Without a tagged kind, an app cannot tell a network failure from a timeout,\n * from a broken schema, from a deliberate domain refusal — so it builds its own\n * error contract ON TOP of the framework, and builds it once per application.\n *\n * Implements `ILankaApiError`: `status` and `errors` are present, so code reading\n * them the old way keeps working.\n *\n * What is NOT here: parsing a particular response body format. Which JSON a\n * backend sends is policy, and policy lives in `@lankajs/plugin-http`. Core knows\n * only that it has a failure and must name its kind.\n */\nexport class LankaError extends Error implements ILankaApiError {\n\treadonly kind: TLankaErrorKind;\n\treadonly status?: number;\n\treadonly code?: string;\n\treadonly issues?: readonly string[];\n\t/** The parsed error response body; core carries it without reading it. */\n\treadonly body?: unknown;\n\n\tconstructor(init: ILankaErrorInit) {\n\t\tsuper(init.message, init.cause === undefined ? undefined : { cause: init.cause });\n\t\tthis.name = \"LankaError\";\n\t\tthis.kind = init.kind;\n\t\tthis.status = init.status;\n\t\tthis.code = init.code;\n\t\tthis.issues = init.issues;\n\t\tthis.body = init.body;\n\n\t\t// The prototype chain is pinned explicitly: without it `instanceof` breaks\n\t\t// for a consumer whose bundler downlevels to ES5, and breaks silently —\n\t\t// `catch` simply fails to recognise its own error.\n\t\tObject.setPrototypeOf(this, LankaError.prototype);\n\t}\n\n\t/** The `ILankaApiError` field. The details are the message list. */\n\tget errors(): string[] | undefined {\n\t\treturn this.issues ? [...this.issues] : undefined;\n\t}\n\n\t/**\n\t * Whether to show this to the user.\n\t *\n\t * A cancelled request is the one failure that must NOT be reported: its cause\n\t * is that the user left before the response, and a toast would catch them on\n\t * another screen.\n\t */\n\tget isSilent(): boolean {\n\t\treturn this.kind === \"aborted\";\n\t}\n\n\t/**\n\t * Recognises our error among others.\n\t *\n\t * Checks the name rather than `instanceof` alone: a consumer may end up with\n\t * two copies of the package — adjacent majors in the dependency tree — and\n\t * then `instanceof` answers `false` for an error that is ours by every other\n\t * sign.\n\t */\n\tstatic is(value: unknown): value is LankaError {\n\t\treturn (\n\t\t\tvalue instanceof LankaError || (value instanceof Error && value.name === \"LankaError\")\n\t\t);\n\t}\n}\n"],"mappings":";AA0DO,IAAM,aAAN,MAAM,oBAAmB,MAAgC;AAAA,EACtD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAEA;AAAA,EAET,YAAY,MAAuB;AAClC,UAAM,KAAK,SAAS,KAAK,UAAU,SAAY,SAAY,EAAE,OAAO,KAAK,MAAM,CAAC;AAChF,SAAK,OAAO;AACZ,SAAK,OAAO,KAAK;AACjB,SAAK,SAAS,KAAK;AACnB,SAAK,OAAO,KAAK;AACjB,SAAK,SAAS,KAAK;AACnB,SAAK,OAAO,KAAK;AAKjB,WAAO,eAAe,MAAM,YAAW,SAAS;AAAA,EACjD;AAAA;AAAA,EAGA,IAAI,SAA+B;AAClC,WAAO,KAAK,SAAS,CAAC,GAAG,KAAK,MAAM,IAAI;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,IAAI,WAAoB;AACvB,WAAO,KAAK,SAAS;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,OAAO,GAAG,OAAqC;AAC9C,WACC,iBAAiB,eAAe,iBAAiB,SAAS,MAAM,SAAS;AAAA,EAE3E;AACD;","names":[]}
@@ -0,0 +1,19 @@
1
+ import {
2
+ requireActiveRuntime
3
+ } from "./chunk-BGVDPDX4.js";
4
+
5
+ // src/config/get-lanka-host/getLankaHost.ts
6
+ function getLankaHost() {
7
+ const host = requireActiveRuntime().config.host;
8
+ if (!host) {
9
+ throw new Error(
10
+ "lanka used before a host was configured. Call createLanka({ host }): the framework needs the application's HTTP error copy and its API base URL, and neither has a default that would be correct for every application."
11
+ );
12
+ }
13
+ return host;
14
+ }
15
+
16
+ export {
17
+ getLankaHost
18
+ };
19
+ //# sourceMappingURL=chunk-RKYKK6MN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/config/get-lanka-host/getLankaHost.ts"],"sourcesContent":["import { requireActiveRuntime } from \"../../_internal/active-runtime/activeRuntime\";\nimport type { ILankaHost } from \"../_interfaces/ILankaHost\";\n\n/**\n * The host of the active instance.\n *\n * Unlike flags, a missing host IS an error: every field of `ILankaHost` is a\n * product decision with no correct default, so there is nothing to fall back to.\n */\nexport function getLankaHost(): ILankaHost {\n\tconst host = requireActiveRuntime().config.host;\n\tif (!host) {\n\t\tthrow new Error(\n\t\t\t\"lanka used before a host was configured. Call createLanka({ host }): the \" +\n\t\t\t\t\"framework needs the application's HTTP error copy and its API base URL, \" +\n\t\t\t\t\"and neither has a default that would be correct for every application.\",\n\t\t);\n\t}\n\treturn host;\n}\n"],"mappings":";;;;;AASO,SAAS,eAA2B;AAC1C,QAAM,OAAO,qBAAqB,EAAE,OAAO;AAC3C,MAAI,CAAC,MAAM;AACV,UAAM,IAAI;AAAA,MACT;AAAA,IAGD;AAAA,EACD;AACA,SAAO;AACR;","names":[]}