lanka 1.3.0 → 2.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.
- package/README.md +1 -1
- package/dist/ILankaReadableVM-BoPzHEPV.d.ts +72 -0
- package/dist/{LankaScenarioLocator-CAENLhDO.d.ts → LankaScenarioLocator-Dki2Es3O.d.ts} +2 -2
- package/dist/{LankaSharedStoreLocator-zS2kLu-S.d.ts → LankaSharedStoreLocator-jsz_gnUm.d.ts} +1 -1
- package/dist/_extend/index.d.ts +228 -5
- package/dist/_extend/index.js +137 -8
- package/dist/_extend/index.js.map +1 -1
- package/dist/_internal/index.d.ts +3 -3
- package/dist/_internal/index.js +9 -3
- package/dist/_internal/index.js.map +1 -1
- package/dist/{activeRuntime-BYd2D6Lx.d.ts → activeRuntime-BO-qY0yY.d.ts} +50 -3
- package/dist/bootstrap/index.d.ts +6 -6
- package/dist/bootstrap/index.js +7 -8
- package/dist/{chunk-D27MREPB.js → chunk-7DQUF2QR.js} +2 -2
- package/dist/{chunk-UJEC7H6K.js → chunk-BHQ2SQ7P.js} +2 -2
- package/dist/chunk-EYDMBI5T.js +550 -0
- package/dist/chunk-EYDMBI5T.js.map +1 -0
- package/dist/{chunk-C2HP7CRD.js → chunk-FII3PW2G.js} +2 -2
- package/dist/{chunk-DTO27QFR.js → chunk-H5TIUKRK.js} +2 -2
- package/dist/{chunk-NDCJBO47.js → chunk-O5EUTNR6.js} +2 -2
- package/dist/{chunk-RKYKK6MN.js → chunk-RUMUFHSL.js} +2 -2
- package/dist/{chunk-UBGXDTXC.js → chunk-SZVNPK24.js} +11 -13
- package/dist/chunk-SZVNPK24.js.map +1 -0
- package/dist/chunk-UDP6IXDS.js +17 -0
- package/dist/chunk-UDP6IXDS.js.map +1 -0
- package/dist/{chunk-5MAQVBI2.js → chunk-UMPSR4US.js} +3 -3
- package/dist/{chunk-BGVDPDX4.js → chunk-XGMXT4XZ.js} +20 -3
- package/dist/chunk-XGMXT4XZ.js.map +1 -0
- package/dist/config/index.js +3 -3
- package/dist/{createLanka-NrlvN-WQ.d.ts → createLanka-x4oSMs7P.d.ts} +2 -2
- package/dist/{createLankaScope-BiFxNQgl.d.ts → createLankaScope-DomNbEvb.d.ts} +1 -1
- package/dist/errors/index.js +3 -3
- package/dist/gateway/index.js +9 -9
- package/dist/index.d.ts +5 -5
- package/dist/index.js +8 -9
- package/dist/locator/index.d.ts +2 -2
- package/dist/locator/index.js +2 -2
- package/dist/logger/index.js +3 -3
- package/dist/mock/index.js +3 -3
- package/dist/scenario/index.d.ts +25 -0
- package/dist/scenario/index.js +6 -8
- package/dist/scenario/index.js.map +1 -1
- package/dist/stream/index.d.ts +5 -5
- package/dist/viewmodel/index.d.ts +137 -27
- package/dist/viewmodel/index.js +94 -126
- package/dist/viewmodel/index.js.map +1 -1
- package/package.json +3 -4
- package/skills/lanka-core/SKILL.md +18 -16
- package/skills/lanka-core/reference.md +135 -58
- package/skills/lanka-packages/SKILL.md +94 -22
- package/dist/chunk-B7EYIAW7.js +0 -216
- package/dist/chunk-B7EYIAW7.js.map +0 -1
- package/dist/chunk-BGVDPDX4.js.map +0 -1
- package/dist/chunk-O5ROO7QF.js +0 -315
- package/dist/chunk-O5ROO7QF.js.map +0 -1
- package/dist/chunk-UBGXDTXC.js.map +0 -1
- /package/dist/{chunk-D27MREPB.js.map → chunk-7DQUF2QR.js.map} +0 -0
- /package/dist/{chunk-UJEC7H6K.js.map → chunk-BHQ2SQ7P.js.map} +0 -0
- /package/dist/{chunk-C2HP7CRD.js.map → chunk-FII3PW2G.js.map} +0 -0
- /package/dist/{chunk-DTO27QFR.js.map → chunk-H5TIUKRK.js.map} +0 -0
- /package/dist/{chunk-NDCJBO47.js.map → chunk-O5EUTNR6.js.map} +0 -0
- /package/dist/{chunk-RKYKK6MN.js.map → chunk-RUMUFHSL.js.map} +0 -0
- /package/dist/{chunk-5MAQVBI2.js.map → chunk-UMPSR4US.js.map} +0 -0
package/README.md
CHANGED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a view binding needs of a ViewModel, and nothing else.
|
|
3
|
+
*
|
|
4
|
+
* The reading half: a name, the current state, a way to hear about the next one,
|
|
5
|
+
* and whether this ViewModel wants access tracking. Writing is deliberately
|
|
6
|
+
* absent — a binding renders, and a binding that could write would be a second
|
|
7
|
+
* place actions live.
|
|
8
|
+
*
|
|
9
|
+
* ## Why this is the port and not `StoreApi`
|
|
10
|
+
*
|
|
11
|
+
* All three ViewModel shapes answer it, and they are built out of different
|
|
12
|
+
* things: the stateful one over a store of its own, the shared-store one over a
|
|
13
|
+
* slice of somebody else's, the stateless one over a plain object with no store
|
|
14
|
+
* at all. A binding written against a store type would work for one of the three.
|
|
15
|
+
*
|
|
16
|
+
* It is also what keeps zustand inside core. `@lankajs/react`, `@lankajs/vue`
|
|
17
|
+
* and every later member of the shelf see this interface and never `StoreApi`,
|
|
18
|
+
* so the store underneath can change without a binding hearing about it — and if
|
|
19
|
+
* a binding ever needs something zustand-shaped, the abstraction leaked and the
|
|
20
|
+
* fix belongs here rather than there. Canon: `skills/hosts/SKILL.md` §1a.
|
|
21
|
+
*
|
|
22
|
+
* @see ILankaVM for the half that also writes, which `hydrateLankaVM` needs.
|
|
23
|
+
*/
|
|
24
|
+
interface ILankaReadableVM<TState extends object> {
|
|
25
|
+
/**
|
|
26
|
+
* Names the ViewModel in logs, the scenario registry and the blind-spot
|
|
27
|
+
* warning — and in whatever a binding's devtools shows.
|
|
28
|
+
*/
|
|
29
|
+
readonly name: string;
|
|
30
|
+
/**
|
|
31
|
+
* The current state, in full — and the SAME object until something changes.
|
|
32
|
+
*
|
|
33
|
+
* The identity is part of the contract, not an accident of the six factories
|
|
34
|
+
* that keep it. Every binding on the shelf holds something against it: the
|
|
35
|
+
* access tracker caches its recording proxy by the identity of the state it
|
|
36
|
+
* wrapped, and `@lankajs/react` holds a selector's answer the same way. An
|
|
37
|
+
* implementation that composes a fresh object on every call hands React a
|
|
38
|
+
* snapshot that never agrees with itself between the render read and the
|
|
39
|
+
* post-commit one, and the component renders until React stops it — a crash
|
|
40
|
+
* whose stack names React and not the ViewModel.
|
|
41
|
+
*
|
|
42
|
+
* It costs an implementer nothing to keep: answer a held object, and build a
|
|
43
|
+
* new one when you write. A ViewModel that composes its state from somewhere
|
|
44
|
+
* else memoises the composition against what it composed from —
|
|
45
|
+
* `createSharedStoreLankaVM` is the worked example.
|
|
46
|
+
*/
|
|
47
|
+
getState(): TState;
|
|
48
|
+
/**
|
|
49
|
+
* Hears about every change, with both states in FULL shape.
|
|
50
|
+
*
|
|
51
|
+
* A shared-store ViewModel composes its full state from a store slice, and
|
|
52
|
+
* does so HERE rather than in the binding: a binding compares two states, it
|
|
53
|
+
* does not know how one is assembled.
|
|
54
|
+
*
|
|
55
|
+
* A stateless ViewModel has nothing that changes, so its implementation
|
|
56
|
+
* returns an unsubscribe and never calls the listener. That is not a gap —
|
|
57
|
+
* it is what makes the same binding work for all three without asking which
|
|
58
|
+
* it was handed.
|
|
59
|
+
*/
|
|
60
|
+
subscribe(listener: (next: TState, prev: TState) => void): () => void;
|
|
61
|
+
/**
|
|
62
|
+
* Whether this ViewModel wants a reader to track which keys it read.
|
|
63
|
+
*
|
|
64
|
+
* `enableAccessTrackingOptimization`, as a binding sees it. A binding that
|
|
65
|
+
* ignores it is not merely slower: the blind spot documented on `ALankaVM`
|
|
66
|
+
* becomes a frozen screen, because the ViewModel turned tracking OFF for
|
|
67
|
+
* exactly the reason that it derives what the view shows.
|
|
68
|
+
*/
|
|
69
|
+
readonly isAccessTracked: boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export type { ILankaReadableVM as I };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { a as ILankaScenario, I as ILankaScenarioVM } from './ILankaScenarioVM-DpKFL3iE.js';
|
|
2
2
|
import { I as ILankaScenarioMetadata } from './ILankaScenarioMetadata-Dj4GCqmX.js';
|
|
3
3
|
import { A as ALankaGateway } from './ALankaGateway-BrVPaZN5.js';
|
|
4
|
-
import { A as ALankaLocator } from './LankaSharedStoreLocator-
|
|
4
|
+
import { A as ALankaLocator } from './LankaSharedStoreLocator-jsz_gnUm.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* The scenario registry: both those that registered themselves and those
|
|
@@ -146,4 +146,4 @@ declare class LankaScenarioLocator extends ALankaLocator<ILankaScenario<unknown>
|
|
|
146
146
|
constructor();
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
export {
|
|
149
|
+
export { LankaScenariosRegistry as L, LankaScenarioVMRegistry as a, LankaGatewayLocator as b, LankaScenarioLocator as c };
|
package/dist/{LankaSharedStoreLocator-zS2kLu-S.d.ts → LankaSharedStoreLocator-jsz_gnUm.d.ts}
RENAMED
|
@@ -144,4 +144,4 @@ declare class LankaSharedStoreLocator extends ALankaLocator<ALankaSharedStore<TS
|
|
|
144
144
|
constructor(config?: ILankaSharedStoreLocatorConfig);
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
export { ALankaLocator as A, type ILankaLocatorConfig as I,
|
|
147
|
+
export { ALankaLocator as A, type ILankaLocatorConfig as I, LankaSingletonLocator as L, LankaSharedStoreLocator as a, type ILankaLocator as b, type ILankaSharedStoreLocatorConfig as c, type ILankaSingletonLocatorConfig as d };
|
package/dist/_extend/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
export {
|
|
2
|
-
import {
|
|
3
|
-
export { A as ALankaLocator,
|
|
4
|
-
export { c as createLankaScope } from '../createLankaScope-
|
|
1
|
+
export { b as LankaGatewayLocator, c as LankaScenarioLocator, a as LankaScenarioVMRegistry, L as LankaScenariosRegistry } from '../LankaScenarioLocator-Dki2Es3O.js';
|
|
2
|
+
import { b as ILankaLocator } from '../LankaSharedStoreLocator-jsz_gnUm.js';
|
|
3
|
+
export { A as ALankaLocator, a as LankaSharedStoreLocator, L as LankaSingletonLocator } from '../LankaSharedStoreLocator-jsz_gnUm.js';
|
|
4
|
+
export { c as createLankaScope } from '../createLankaScope-DomNbEvb.js';
|
|
5
5
|
export { c as composeLankaRequestMiddleware } from '../lankaRequestMiddleware-DAC5kCb7.js';
|
|
6
|
+
import { I as ILankaReadableVM } from '../ILankaReadableVM-BoPzHEPV.js';
|
|
6
7
|
import '../ILankaScenarioVM-DpKFL3iE.js';
|
|
7
8
|
import '../ILankaScenarioMetadata-Dj4GCqmX.js';
|
|
8
9
|
import '../ALankaGateway-BrVPaZN5.js';
|
|
@@ -32,4 +33,226 @@ interface ILankaLocatorProxyConfig<TInstance> {
|
|
|
32
33
|
*/
|
|
33
34
|
declare function createLankaLocatorProxy<TInstance, TType extends Record<string, TInstance>>(config: ILankaLocatorProxyConfig<TInstance>): TType;
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
interface ILankaAccessTracker<TState extends object> {
|
|
37
|
+
/**
|
|
38
|
+
* The state as a recording Proxy: every key read off it is remembered.
|
|
39
|
+
*
|
|
40
|
+
* Cached by the IDENTITY of the state it wrapped, so a second read while
|
|
41
|
+
* nothing has changed hands back the same proxy — and therefore the same
|
|
42
|
+
* recorded keys — rather than starting the recording over.
|
|
43
|
+
*
|
|
44
|
+
* A ViewModel that turned tracking off gets the state itself, and every
|
|
45
|
+
* change then notifies. That is its decision, not a fallback: it turned
|
|
46
|
+
* tracking off because it DERIVES what the screen shows, and a recording that
|
|
47
|
+
* cannot see those reads would skip renders the screen needs.
|
|
48
|
+
*/
|
|
49
|
+
read(): TState;
|
|
50
|
+
/**
|
|
51
|
+
* Whether a change touches anything this reader actually looked at.
|
|
52
|
+
*
|
|
53
|
+
* A reader that has looked at NOTHING yet is notified of everything: it has
|
|
54
|
+
* not had the chance to record a key, and staying silent would mean its first
|
|
55
|
+
* render never arrives.
|
|
56
|
+
*/
|
|
57
|
+
shouldNotify(next: TState, prev: TState): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Says, in development, that a change was skipped — so the framework can warn
|
|
60
|
+
* if the screen reads the changed key through a getter.
|
|
61
|
+
*
|
|
62
|
+
* Called by a binding exactly when `shouldNotify` answered `false`. In
|
|
63
|
+
* production, and for a ViewModel with no trap, it does nothing.
|
|
64
|
+
*/
|
|
65
|
+
reportSkipped(next: TState, prev: TState): void;
|
|
66
|
+
/**
|
|
67
|
+
* The state itself, never the proxy.
|
|
68
|
+
*
|
|
69
|
+
* For a render that happens once and is thrown away — a server snapshot. There
|
|
70
|
+
* is nothing to skip on a second render that will not happen, so recording
|
|
71
|
+
* reads would be work whose result nothing consults.
|
|
72
|
+
*/
|
|
73
|
+
readPlain(): TState;
|
|
74
|
+
/** The keys read so far. Handed to the blind-spot diagnostic, which names them. */
|
|
75
|
+
readonly trackedKeys: ReadonlySet<string>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Which state keys one reader looked at, and whether a change touched them.
|
|
79
|
+
*
|
|
80
|
+
* This is the whole of access tracking, and it is deliberately ignorant of how
|
|
81
|
+
* anybody subscribes. A component re-renders only for keys it READ off the proxy
|
|
82
|
+
* this returns; every framework asks that question the same way and answers it
|
|
83
|
+
* with a different mechanism — `useSyncExternalStore`, a `shallowRef`, a signal —
|
|
84
|
+
* so the question lives here and the mechanism lives in the binding.
|
|
85
|
+
*
|
|
86
|
+
* **This is the one piece of core a binding author needs.** It is published
|
|
87
|
+
* through `lanka/extend` for exactly that: a binding is then a subscription, a
|
|
88
|
+
* render trigger and these four calls, and the behaviour a consumer sees is the
|
|
89
|
+
* framework's rather than each binding's re-reading of it. Canon:
|
|
90
|
+
* `skills/parity/SKILL.md`.
|
|
91
|
+
*
|
|
92
|
+
* ## One tracker per reader, not per store
|
|
93
|
+
*
|
|
94
|
+
* The recorded keys are the property of whoever did the reading. Two components
|
|
95
|
+
* over one ViewModel read different keys and must re-render for different
|
|
96
|
+
* changes, so each holds its own tracker — which is also why this is a factory
|
|
97
|
+
* with closed-over state rather than a set of pure functions over a shared map:
|
|
98
|
+
* the lifetime of the recording is exactly the lifetime of the reader.
|
|
99
|
+
*
|
|
100
|
+
* ## The blind spot this cannot see, and reports instead
|
|
101
|
+
*
|
|
102
|
+
* Tracking sees reads made DIRECTLY off the proxy. A key reached only inside a
|
|
103
|
+
* derived getter — an action calling `get()` — is invisible here, so a change to
|
|
104
|
+
* it answers `shouldNotify` with `false` and the screen does not move. That is
|
|
105
|
+
* what `reportSkipped` is for: core kept a trap for this ViewModel, and in
|
|
106
|
+
* development it names the ViewModel and the key rather than leaving a frozen
|
|
107
|
+
* screen with no error anywhere.
|
|
108
|
+
*/
|
|
109
|
+
declare const createLankaAccessTracker: <TState extends object>(viewModel: ILankaReadableVM<TState>) => ILankaAccessTracker<TState>;
|
|
110
|
+
|
|
111
|
+
/** One reader's live view of a ViewModel. */
|
|
112
|
+
interface ILankaViewSubscription<TState extends object> {
|
|
113
|
+
/**
|
|
114
|
+
* The current state, RECORDED.
|
|
115
|
+
*
|
|
116
|
+
* Every key read off it is remembered, which is what lets the next change be
|
|
117
|
+
* skipped when it touched none of them. Call it again on every read: it asks
|
|
118
|
+
* the ViewModel for its state each time, so it is never a snapshot.
|
|
119
|
+
*/
|
|
120
|
+
read: () => TState;
|
|
121
|
+
/** Releases the subscription. */
|
|
122
|
+
stop: () => void;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The TRACKED half of a view binding, minus the framework.
|
|
126
|
+
*
|
|
127
|
+
* The tracked half, and not the whole: all five shipped members also publish a
|
|
128
|
+
* selector arm, which this deliberately does not serve — the reason is below,
|
|
129
|
+
* under "Why it does not take a selector".
|
|
130
|
+
*
|
|
131
|
+
* ```ts
|
|
132
|
+
* // a binding for a framework this repository has never heard of
|
|
133
|
+
* export const useMyFrameworkVM = (viewModel) => {
|
|
134
|
+
* const view = createLankaViewSubscription(viewModel, () => invalidate());
|
|
135
|
+
* onTeardown(view.stop);
|
|
136
|
+
*
|
|
137
|
+
* return view.read;
|
|
138
|
+
* };
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* Subscribe, ask whether the change touched anything this reader looked at,
|
|
142
|
+
* report the skip so the blind-spot diagnostic can fire, and hand back a read
|
|
143
|
+
* that records. Five packages wrote those four steps out by hand, identically —
|
|
144
|
+
* and five copies of a decision diverge on the day one of them gains a line.
|
|
145
|
+
*
|
|
146
|
+
* ## What a caller still owns
|
|
147
|
+
*
|
|
148
|
+
* `onChange` and the teardown, which are the only framework-shaped things left.
|
|
149
|
+
* That is the seam: a binding says how its framework is WOKEN and when a reader
|
|
150
|
+
* has gone, and everything about which changes are worth waking for is here.
|
|
151
|
+
*
|
|
152
|
+
* ## Why it does not take a selector
|
|
153
|
+
*
|
|
154
|
+
* A selector BYPASSES tracking — the selector decides, and there is nothing to
|
|
155
|
+
* record — so a subscription that took one would be two mechanisms behind one
|
|
156
|
+
* name, each right half the time. A binding with a selector arm calls
|
|
157
|
+
* `createLankaAccessTracker` directly, which is what the shelf's members do, and
|
|
158
|
+
* the four steps are worth writing out where they genuinely differ.
|
|
159
|
+
*
|
|
160
|
+
* ## What it is not
|
|
161
|
+
*
|
|
162
|
+
* Not a store, not a cache, not a second place state lives. It holds a tracker
|
|
163
|
+
* and an unsubscribe, and everything it answers comes from the ViewModel on the
|
|
164
|
+
* call.
|
|
165
|
+
*/
|
|
166
|
+
declare const createLankaViewSubscription: <TState extends object>(viewModel: ILankaReadableVM<TState>, onChange: () => void) => ILankaViewSubscription<TState>;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The brand that makes a definition impossible to write by hand.
|
|
170
|
+
*
|
|
171
|
+
* Not exported, and that is the whole mechanism. A structural interface with
|
|
172
|
+
* `name` and `build` on it would let a consumer author one, and the moment one
|
|
173
|
+
* does, `ILankaVMDefinition` stops being a type the framework implements and
|
|
174
|
+
* becomes a PORT — after which every member added to it is a compile error in
|
|
175
|
+
* code nobody touched. Publishing an opaque type costs one line and keeps the
|
|
176
|
+
* option space: a `dispose`, a `scope` field, even a call signature so that
|
|
177
|
+
* `missionsVM()` could mean `resolveLankaVM(missionsVM)`, all stay additive.
|
|
178
|
+
*/
|
|
179
|
+
declare const LANKA_VM_DEFINITION: unique symbol;
|
|
180
|
+
/**
|
|
181
|
+
* A ViewModel that has not been built yet.
|
|
182
|
+
*
|
|
183
|
+
* Hold it, pass it, type against it. There is nothing on it to call, because
|
|
184
|
+
* calling it is `resolveLankaVM`'s job and a definition built by hand would be
|
|
185
|
+
* an instance outside every scope's map.
|
|
186
|
+
*/
|
|
187
|
+
interface ILankaVMDefinition<TViewModel extends ILankaReadableVM<object>> {
|
|
188
|
+
readonly [LANKA_VM_DEFINITION]: TViewModel;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Declares a ViewModel WITHOUT building it.
|
|
192
|
+
*
|
|
193
|
+
* ## When NOT to use this
|
|
194
|
+
*
|
|
195
|
+
* A browser-only application needs none of it. One module is one instance per
|
|
196
|
+
* TAB there, so a module-level `createLankaVM` is still the shape, and wrapping
|
|
197
|
+
* the nine factories in this one buys nothing but a lookup per read. Reach for
|
|
198
|
+
* it when the same ViewModel has to exist on a SERVER, where one module is one
|
|
199
|
+
* instance per PROCESS — shared by every user connected to it, so the first
|
|
200
|
+
* request to write a draft into it serves that draft to the next stranger.
|
|
201
|
+
*
|
|
202
|
+
* ```ts
|
|
203
|
+
* export const missionsVM = defineLankaVM({
|
|
204
|
+
* name: "MissionsVM",
|
|
205
|
+
* build: () => createLankaVM({ … }),
|
|
206
|
+
* });
|
|
207
|
+
* ```
|
|
208
|
+
*
|
|
209
|
+
* ## What it is not
|
|
210
|
+
*
|
|
211
|
+
* Not a tenth way to write a ViewModel. `build` returns whatever the nine
|
|
212
|
+
* existing factories return and nothing here reaches inside it — a definition
|
|
213
|
+
* adds a lifetime and takes nothing away.
|
|
214
|
+
*
|
|
215
|
+
* Not lazy in the sense `createLazyLankaVM` is. That one defers the STORE until
|
|
216
|
+
* first read and still has one per module; this defers WHICH INSTANCE, and the
|
|
217
|
+
* two compose.
|
|
218
|
+
*/
|
|
219
|
+
declare const defineLankaVM: <TViewModel extends ILankaReadableVM<object>>(config: {
|
|
220
|
+
name: string;
|
|
221
|
+
build: () => TViewModel;
|
|
222
|
+
}) => ILankaVMDefinition<TViewModel>;
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* The instance of a definition that belongs to the CURRENT scope.
|
|
226
|
+
*
|
|
227
|
+
* Called twice in one scope it answers the same instance; called in two scopes
|
|
228
|
+
* it answers two, and neither can see the other's state. In a browser there is
|
|
229
|
+
* one scope for the life of the tab, so this is the module-level ViewModel a
|
|
230
|
+
* consumer already knows — written once and correct on a server as well.
|
|
231
|
+
*
|
|
232
|
+
* ## It throws outside a scope, and that is the feature
|
|
233
|
+
*
|
|
234
|
+
* On a server the answer comes from the SCOPE seam rather than from the active
|
|
235
|
+
* runtime, and the difference is not academic. `runInLankaServerScope` creates
|
|
236
|
+
* its instance inside the scope and `createLanka` activates every instance it
|
|
237
|
+
* builds, so during a request the process pointer and the scope's runtime are
|
|
238
|
+
* the same object — keying on the runtime would make "inside a request" and
|
|
239
|
+
* "after one ended" indistinguishable, and a call made after would be handed the
|
|
240
|
+
* last stranger's ViewModel.
|
|
241
|
+
*
|
|
242
|
+
* So: a scope resolver installed and answering `null` means this ran outside
|
|
243
|
+
* every request, and that fails loudly. No fallback, for the same reason
|
|
244
|
+
* `requireActiveRuntime` has none — a wrong answer here is one user's data in
|
|
245
|
+
* another user's page, and it would surface three layers from the call.
|
|
246
|
+
*
|
|
247
|
+
* ## Why the build is wrapped
|
|
248
|
+
*
|
|
249
|
+
* `ALankaVM.build()` declares a ViewModel that has scenario handlers into a
|
|
250
|
+
* PROCESS-wide list, so that every instance ever created adopts it. That is
|
|
251
|
+
* right for a module-level ViewModel and catastrophic for a scoped one: the list
|
|
252
|
+
* would grow per request forever, and request N+1 would adopt request N's
|
|
253
|
+
* ViewModel and run N's handlers against N's gateways. `buildScoped` is the seam
|
|
254
|
+
* that keeps a scoped declaration out of it.
|
|
255
|
+
*/
|
|
256
|
+
declare const resolveLankaVM: <TViewModel extends ILankaReadableVM<object>>(definition: ILankaVMDefinition<TViewModel>) => TViewModel;
|
|
257
|
+
|
|
258
|
+
export { type ILankaAccessTracker, type ILankaLocatorProxyConfig, type ILankaVMDefinition, type ILankaViewSubscription, createLankaAccessTracker, createLankaLocatorProxy, createLankaViewSubscription, defineLankaVM, resolveLankaVM };
|
package/dist/_extend/index.js
CHANGED
|
@@ -1,26 +1,151 @@
|
|
|
1
|
+
import {
|
|
2
|
+
lankaBlindSpotRegistry
|
|
3
|
+
} from "../chunk-UDP6IXDS.js";
|
|
1
4
|
import {
|
|
2
5
|
LankaGatewayLocator,
|
|
3
6
|
LankaScenarioLocator,
|
|
4
7
|
createLankaScope
|
|
5
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-UMPSR4US.js";
|
|
6
9
|
import {
|
|
7
10
|
LankaScenarioVMRegistry,
|
|
8
|
-
LankaScenariosRegistry
|
|
9
|
-
|
|
11
|
+
LankaScenariosRegistry,
|
|
12
|
+
lankaScenarioBootstrap
|
|
13
|
+
} from "../chunk-EYDMBI5T.js";
|
|
10
14
|
import {
|
|
11
15
|
composeLankaRequestMiddleware
|
|
12
16
|
} from "../chunk-YR4MZXMU.js";
|
|
13
17
|
import {
|
|
14
18
|
createLankaLocatorProxy
|
|
15
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-H5TIUKRK.js";
|
|
16
20
|
import {
|
|
17
21
|
ALankaLocator,
|
|
18
22
|
LankaSharedStoreLocator,
|
|
19
23
|
LankaSingletonLocator
|
|
20
24
|
} from "../chunk-UE2C76OR.js";
|
|
21
|
-
import "../chunk-
|
|
22
|
-
import "../chunk-
|
|
23
|
-
import
|
|
25
|
+
import "../chunk-FII3PW2G.js";
|
|
26
|
+
import "../chunk-7DQUF2QR.js";
|
|
27
|
+
import {
|
|
28
|
+
getActiveLankaScope,
|
|
29
|
+
hasLankaScopeResolver,
|
|
30
|
+
requireActiveRuntime
|
|
31
|
+
} from "../chunk-XGMXT4XZ.js";
|
|
32
|
+
|
|
33
|
+
// src/viewmodel/_internal/create-lanka-access-tracker/createLankaAccessTracker.ts
|
|
34
|
+
var asRecord = (state) => state;
|
|
35
|
+
var recordReadsInto = (state, keys) => new Proxy(state, {
|
|
36
|
+
get(target, prop, receiver) {
|
|
37
|
+
const value = Reflect.get(target, prop, receiver);
|
|
38
|
+
if (typeof prop === "string" && typeof value !== "function" && Object.hasOwn(target, prop)) {
|
|
39
|
+
keys.add(prop);
|
|
40
|
+
}
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
var trackedReadOf = (read) => {
|
|
45
|
+
let keys = /* @__PURE__ */ new Set();
|
|
46
|
+
let state = null;
|
|
47
|
+
let proxy = null;
|
|
48
|
+
return {
|
|
49
|
+
keys: () => keys,
|
|
50
|
+
current: () => {
|
|
51
|
+
const next = read();
|
|
52
|
+
if (state === next && proxy) return proxy;
|
|
53
|
+
keys = /* @__PURE__ */ new Set();
|
|
54
|
+
state = next;
|
|
55
|
+
proxy = recordReadsInto(next, keys);
|
|
56
|
+
return proxy;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
var anyKeyMoved = (keys, next, prev) => {
|
|
61
|
+
const nextRecord = asRecord(next);
|
|
62
|
+
const prevRecord = asRecord(prev);
|
|
63
|
+
for (const key of keys) {
|
|
64
|
+
if (!Object.is(nextRecord[key], prevRecord[key])) return true;
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
};
|
|
68
|
+
var createLankaAccessTracker = (viewModel) => {
|
|
69
|
+
const trap = lankaBlindSpotRegistry.of(viewModel);
|
|
70
|
+
const isTracked = viewModel.isAccessTracked;
|
|
71
|
+
const tracked = trackedReadOf(() => viewModel.getState());
|
|
72
|
+
return {
|
|
73
|
+
get trackedKeys() {
|
|
74
|
+
return isTracked ? tracked.keys() : /* @__PURE__ */ new Set();
|
|
75
|
+
},
|
|
76
|
+
read() {
|
|
77
|
+
return isTracked ? tracked.current() : viewModel.getState();
|
|
78
|
+
},
|
|
79
|
+
shouldNotify(next, prev) {
|
|
80
|
+
if (!isTracked) return true;
|
|
81
|
+
const keys = tracked.keys();
|
|
82
|
+
return keys.size === 0 || anyKeyMoved(keys, next, prev);
|
|
83
|
+
},
|
|
84
|
+
reportSkipped(next, prev) {
|
|
85
|
+
trap?.report(new Set(tracked.keys()), asRecord(next), asRecord(prev));
|
|
86
|
+
},
|
|
87
|
+
readPlain() {
|
|
88
|
+
return viewModel.getState();
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// src/viewmodel/_factories/create-lanka-view-subscription/createLankaViewSubscription.ts
|
|
94
|
+
var createLankaViewSubscription = (viewModel, onChange) => {
|
|
95
|
+
const tracker = createLankaAccessTracker(viewModel);
|
|
96
|
+
const stop = viewModel.subscribe((next, prev) => {
|
|
97
|
+
if (!tracker.shouldNotify(next, prev)) {
|
|
98
|
+
tracker.reportSkipped(next, prev);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
onChange();
|
|
102
|
+
});
|
|
103
|
+
return { read: () => tracker.read(), stop };
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// src/viewmodel/_internal/lanka-vm-recipes/lankaVMRecipes.ts
|
|
107
|
+
var lankaVMRecipes = {
|
|
108
|
+
recipes: /* @__PURE__ */ new WeakMap(),
|
|
109
|
+
instances: /* @__PURE__ */ new WeakMap(),
|
|
110
|
+
/** The instances belonging to one scope, created on first use. */
|
|
111
|
+
forScope(scope) {
|
|
112
|
+
const existing = this.instances.get(scope);
|
|
113
|
+
if (existing) return existing;
|
|
114
|
+
const created = /* @__PURE__ */ new WeakMap();
|
|
115
|
+
this.instances.set(scope, created);
|
|
116
|
+
return created;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// src/viewmodel/_factories/define-lanka-vm/defineLankaVM.ts
|
|
121
|
+
var defineLankaVM = (config) => {
|
|
122
|
+
const definition = Object.freeze({});
|
|
123
|
+
lankaVMRecipes.recipes.set(definition, config);
|
|
124
|
+
return definition;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// src/viewmodel/_factories/resolve-lanka-vm/resolveLankaVM.ts
|
|
128
|
+
var resolveLankaVM = (definition) => {
|
|
129
|
+
const recipe = lankaVMRecipes.recipes.get(definition);
|
|
130
|
+
if (!recipe) {
|
|
131
|
+
throw new Error(
|
|
132
|
+
"resolveLankaVM was given something defineLankaVM did not make. A definition is opaque on purpose: build it with defineLankaVM rather than by hand."
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
const runtime = requireActiveRuntime();
|
|
136
|
+
const scope = getActiveLankaScope();
|
|
137
|
+
if (hasLankaScopeResolver() && !scope) {
|
|
138
|
+
throw new Error(
|
|
139
|
+
`resolveLankaVM("${recipe.name}") ran outside every scope. A scope resolver is installed, which on a server means this code ran outside a request \u2014 and a ViewModel resolved there would be the previous request's. Do this work inside the scope, or start one.`
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
const instances = lankaVMRecipes.forScope(scope ?? runtime);
|
|
143
|
+
const held = instances.get(definition);
|
|
144
|
+
if (held) return held;
|
|
145
|
+
const built = lankaScenarioBootstrap.buildScoped(() => recipe.build());
|
|
146
|
+
instances.set(definition, built);
|
|
147
|
+
return built;
|
|
148
|
+
};
|
|
24
149
|
export {
|
|
25
150
|
ALankaLocator,
|
|
26
151
|
LankaGatewayLocator,
|
|
@@ -30,7 +155,11 @@ export {
|
|
|
30
155
|
LankaSharedStoreLocator,
|
|
31
156
|
LankaSingletonLocator,
|
|
32
157
|
composeLankaRequestMiddleware,
|
|
158
|
+
createLankaAccessTracker,
|
|
33
159
|
createLankaLocatorProxy,
|
|
34
|
-
createLankaScope
|
|
160
|
+
createLankaScope,
|
|
161
|
+
createLankaViewSubscription,
|
|
162
|
+
defineLankaVM,
|
|
163
|
+
resolveLankaVM
|
|
35
164
|
};
|
|
36
165
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/viewmodel/_internal/create-lanka-access-tracker/createLankaAccessTracker.ts","../../src/viewmodel/_factories/create-lanka-view-subscription/createLankaViewSubscription.ts","../../src/viewmodel/_internal/lanka-vm-recipes/lankaVMRecipes.ts","../../src/viewmodel/_factories/define-lanka-vm/defineLankaVM.ts","../../src/viewmodel/_factories/resolve-lanka-vm/resolveLankaVM.ts"],"sourcesContent":["import { lankaBlindSpotRegistry } from \"../lanka-blind-spot-registry/lankaBlindSpotRegistry\";\nimport type { ILankaReadableVM } from \"../../_interfaces/ILankaReadableVM\";\n\nexport interface ILankaAccessTracker<TState extends object> {\n\t/**\n\t * The state as a recording Proxy: every key read off it is remembered.\n\t *\n\t * Cached by the IDENTITY of the state it wrapped, so a second read while\n\t * nothing has changed hands back the same proxy — and therefore the same\n\t * recorded keys — rather than starting the recording over.\n\t *\n\t * A ViewModel that turned tracking off gets the state itself, and every\n\t * change then notifies. That is its decision, not a fallback: it turned\n\t * tracking off because it DERIVES what the screen shows, and a recording that\n\t * cannot see those reads would skip renders the screen needs.\n\t */\n\tread(): TState;\n\t/**\n\t * Whether a change touches anything this reader actually looked at.\n\t *\n\t * A reader that has looked at NOTHING yet is notified of everything: it has\n\t * not had the chance to record a key, and staying silent would mean its first\n\t * render never arrives.\n\t */\n\tshouldNotify(next: TState, prev: TState): boolean;\n\t/**\n\t * Says, in development, that a change was skipped — so the framework can warn\n\t * if the screen reads the changed key through a getter.\n\t *\n\t * Called by a binding exactly when `shouldNotify` answered `false`. In\n\t * production, and for a ViewModel with no trap, it does nothing.\n\t */\n\treportSkipped(next: TState, prev: TState): void;\n\t/**\n\t * The state itself, never the proxy.\n\t *\n\t * For a render that happens once and is thrown away — a server snapshot. There\n\t * is nothing to skip on a second render that will not happen, so recording\n\t * reads would be work whose result nothing consults.\n\t */\n\treadPlain(): TState;\n\t/** The keys read so far. Handed to the blind-spot diagnostic, which names them. */\n\treadonly trackedKeys: ReadonlySet<string>;\n}\n\nconst asRecord = (state: object): Record<string, unknown> => state as Record<string, unknown>;\n\n/**\n * A view of `state` that records the keys a READER depends on.\n *\n * Three things are excluded, and each was found by a reader going deaf rather\n * than by review. What they have in common is that none of them can ever make\n * `shouldNotify` answer true — so recording one cannot cause a render, and can\n * only switch off the rule that a reader who has read NOTHING hears about\n * everything.\n *\n * **Symbols.** `shouldNotify` compares keys by name, so a recorded symbol could\n * never be consulted, and every symbol a runtime asks for while inspecting an\n * object would join the set.\n *\n * **Keys the state does not have.** A framework probes an unfamiliar object\n * before it will hold it: Vue's `shallowRef` reads `__v_isRef`, a promise\n * resolution reads `then`, React reads `$$typeof`. Each went through this proxy\n * and was recorded, and `undefined === undefined` on every later comparison.\n * That is what made `defineLankaStore(vm)` deaf to its own first change — the\n * ONE key it had recorded was `__v_isRef`, and a template reading a real key\n * during its first render is what hid it everywhere else.\n *\n * **Functions.** An action is one object for the life of the store, so a\n * recorded action can never differ. `await store.load()` before any other read\n * is the shape that found it. A state key holding a function that genuinely\n * changes is the case this gives up, and it is the right one: a callback living\n * in state is state two readers cannot agree about, and every ViewModel here and\n * in the applications keeps its functions in actions.\n */\nconst recordReadsInto = <TState extends object>(state: TState, keys: Set<string>): TState =>\n\tnew Proxy(state, {\n\t\tget(target, prop, receiver) {\n\t\t\tconst value = Reflect.get(target, prop, receiver) as unknown;\n\n\t\t\tif (\n\t\t\t\ttypeof prop === \"string\" &&\n\t\t\t\ttypeof value !== \"function\" &&\n\t\t\t\tObject.hasOwn(target, prop)\n\t\t\t) {\n\t\t\t\tkeys.add(prop);\n\t\t\t}\n\n\t\t\treturn value;\n\t\t},\n\t});\n\n/**\n * The recording one reader currently holds, rebuilt when the state moves.\n *\n * Its own unit because it is the stateful half: a proxy, the keys it has\n * collected, and the identity of the state it was made for. What is left around\n * it is a comparison and a report, neither of which remembers anything.\n */\nconst trackedReadOf = <TState extends object>(read: () => TState) => {\n\tlet keys = new Set<string>();\n\tlet state: TState | null = null;\n\tlet proxy: TState | null = null;\n\n\treturn {\n\t\tkeys: (): ReadonlySet<string> => keys,\n\n\t\tcurrent: (): TState => {\n\t\t\tconst next = read();\n\t\t\tif (state === next && proxy) return proxy;\n\n\t\t\t// A FRESH set per state: the keys a reader looks at can change between\n\t\t\t// renders — a branch stops being taken, a list empties — and keeping the\n\t\t\t// old ones would re-render for a key nobody reads any more, forever.\n\t\t\tkeys = new Set<string>();\n\t\t\tstate = next;\n\t\t\tproxy = recordReadsInto(next, keys);\n\n\t\t\treturn proxy;\n\t\t},\n\t};\n};\n\n/** Whether the two states disagree on any of the keys a reader looked at. */\nconst anyKeyMoved = (keys: ReadonlySet<string>, next: object, prev: object): boolean => {\n\tconst nextRecord = asRecord(next);\n\tconst prevRecord = asRecord(prev);\n\n\tfor (const key of keys) {\n\t\tif (!Object.is(nextRecord[key], prevRecord[key])) return true;\n\t}\n\n\treturn false;\n};\n\n/**\n * Which state keys one reader looked at, and whether a change touched them.\n *\n * This is the whole of access tracking, and it is deliberately ignorant of how\n * anybody subscribes. A component re-renders only for keys it READ off the proxy\n * this returns; every framework asks that question the same way and answers it\n * with a different mechanism — `useSyncExternalStore`, a `shallowRef`, a signal —\n * so the question lives here and the mechanism lives in the binding.\n *\n * **This is the one piece of core a binding author needs.** It is published\n * through `lanka/extend` for exactly that: a binding is then a subscription, a\n * render trigger and these four calls, and the behaviour a consumer sees is the\n * framework's rather than each binding's re-reading of it. Canon:\n * `skills/parity/SKILL.md`.\n *\n * ## One tracker per reader, not per store\n *\n * The recorded keys are the property of whoever did the reading. Two components\n * over one ViewModel read different keys and must re-render for different\n * changes, so each holds its own tracker — which is also why this is a factory\n * with closed-over state rather than a set of pure functions over a shared map:\n * the lifetime of the recording is exactly the lifetime of the reader.\n *\n * ## The blind spot this cannot see, and reports instead\n *\n * Tracking sees reads made DIRECTLY off the proxy. A key reached only inside a\n * derived getter — an action calling `get()` — is invisible here, so a change to\n * it answers `shouldNotify` with `false` and the screen does not move. That is\n * what `reportSkipped` is for: core kept a trap for this ViewModel, and in\n * development it names the ViewModel and the key rather than leaving a frozen\n * screen with no error anywhere.\n */\nexport const createLankaAccessTracker = <TState extends object>(\n\tviewModel: ILankaReadableVM<TState>,\n): ILankaAccessTracker<TState> => {\n\tconst trap = lankaBlindSpotRegistry.of(viewModel);\n\tconst isTracked = viewModel.isAccessTracked;\n\tconst tracked = trackedReadOf(() => viewModel.getState());\n\n\treturn {\n\t\tget trackedKeys(): ReadonlySet<string> {\n\t\t\treturn isTracked ? tracked.keys() : new Set<string>();\n\t\t},\n\n\t\tread(): TState {\n\t\t\treturn isTracked ? tracked.current() : viewModel.getState();\n\t\t},\n\n\t\tshouldNotify(next: TState, prev: TState): boolean {\n\t\t\tif (!isTracked) return true;\n\n\t\t\tconst keys = tracked.keys();\n\n\t\t\treturn keys.size === 0 || anyKeyMoved(keys, next, prev);\n\t\t},\n\n\t\treportSkipped(next: TState, prev: TState): void {\n\t\t\ttrap?.report(new Set(tracked.keys()), asRecord(next), asRecord(prev));\n\t\t},\n\n\t\treadPlain(): TState {\n\t\t\treturn viewModel.getState();\n\t\t},\n\t};\n};\n","import { createLankaAccessTracker } from \"../../_internal/create-lanka-access-tracker/createLankaAccessTracker\";\nimport type { ILankaReadableVM } from \"../../_interfaces/ILankaReadableVM\";\n\n/** One reader's live view of a ViewModel. */\nexport interface ILankaViewSubscription<TState extends object> {\n\t/**\n\t * The current state, RECORDED.\n\t *\n\t * Every key read off it is remembered, which is what lets the next change be\n\t * skipped when it touched none of them. Call it again on every read: it asks\n\t * the ViewModel for its state each time, so it is never a snapshot.\n\t */\n\tread: () => TState;\n\t/** Releases the subscription. */\n\tstop: () => void;\n}\n\n/**\n * The TRACKED half of a view binding, minus the framework.\n *\n * The tracked half, and not the whole: all five shipped members also publish a\n * selector arm, which this deliberately does not serve — the reason is below,\n * under \"Why it does not take a selector\".\n *\n * ```ts\n * // a binding for a framework this repository has never heard of\n * export const useMyFrameworkVM = (viewModel) => {\n * \tconst view = createLankaViewSubscription(viewModel, () => invalidate());\n * \tonTeardown(view.stop);\n *\n * \treturn view.read;\n * };\n * ```\n *\n * Subscribe, ask whether the change touched anything this reader looked at,\n * report the skip so the blind-spot diagnostic can fire, and hand back a read\n * that records. Five packages wrote those four steps out by hand, identically —\n * and five copies of a decision diverge on the day one of them gains a line.\n *\n * ## What a caller still owns\n *\n * `onChange` and the teardown, which are the only framework-shaped things left.\n * That is the seam: a binding says how its framework is WOKEN and when a reader\n * has gone, and everything about which changes are worth waking for is here.\n *\n * ## Why it does not take a selector\n *\n * A selector BYPASSES tracking — the selector decides, and there is nothing to\n * record — so a subscription that took one would be two mechanisms behind one\n * name, each right half the time. A binding with a selector arm calls\n * `createLankaAccessTracker` directly, which is what the shelf's members do, and\n * the four steps are worth writing out where they genuinely differ.\n *\n * ## What it is not\n *\n * Not a store, not a cache, not a second place state lives. It holds a tracker\n * and an unsubscribe, and everything it answers comes from the ViewModel on the\n * call.\n */\nexport const createLankaViewSubscription = <TState extends object>(\n\tviewModel: ILankaReadableVM<TState>,\n\tonChange: () => void,\n): ILankaViewSubscription<TState> => {\n\tconst tracker = createLankaAccessTracker(viewModel);\n\n\tconst stop = viewModel.subscribe((next, prev) => {\n\t\tif (!tracker.shouldNotify(next, prev)) {\n\t\t\t// No update will follow. If the changed key is linked to this reader\n\t\t\t// through a getter it read, the screen froze — and in development core\n\t\t\t// names the ViewModel and the key rather than leaving it silent.\n\t\t\ttracker.reportSkipped(next, prev);\n\t\t\treturn;\n\t\t}\n\n\t\tonChange();\n\t});\n\n\treturn { read: () => tracker.read(), stop };\n};\n","import type { ILankaReadableVM } from \"../../_interfaces/ILankaReadableVM\";\n\n/** What a definition actually holds, kept where a consumer cannot reach it. */\nexport interface ILankaVMRecipe {\n\treadonly name: string;\n\treadonly build: () => ILankaReadableVM<object>;\n}\n\n/**\n * What `defineLankaVM` writes and `resolveLankaVM` reads.\n *\n * One object rather than two exported maps, because a file here holds one\n * runtime identity — and because the two halves are one mechanism: a recipe\n * nobody can resolve and an instance map keyed by nothing are each meaningless\n * alone.\n *\n * ## Weak at both ends, and both ends matter\n *\n * `recipes` is weak so a definition dropped by its module takes its recipe with\n * it. `instances` is weak in the SCOPE so a finished request's ViewModels go\n * when its scope does, and weak in the DEFINITION because the published type\n * invites `defineLankaVM({...})` written inline in a component or a loop — in a\n * browser the scope key is the framework instance and lives as long as the tab,\n * so a strong inner map would hold every inline definition and its ViewModel\n * for the life of the page.\n */\nexport const lankaVMRecipes = {\n\trecipes: new WeakMap<object, ILankaVMRecipe>(),\n\tinstances: new WeakMap<object, WeakMap<object, ILankaReadableVM<object>>>(),\n\n\t/** The instances belonging to one scope, created on first use. */\n\tforScope(scope: object): WeakMap<object, ILankaReadableVM<object>> {\n\t\tconst existing = this.instances.get(scope);\n\n\t\tif (existing) return existing;\n\n\t\tconst created = new WeakMap<object, ILankaReadableVM<object>>();\n\n\t\tthis.instances.set(scope, created);\n\n\t\treturn created;\n\t},\n};\n","import { lankaVMRecipes } from \"../../_internal/lanka-vm-recipes/lankaVMRecipes\";\nimport type { ILankaReadableVM } from \"../../_interfaces/ILankaReadableVM\";\n\n/**\n * The brand that makes a definition impossible to write by hand.\n *\n * Not exported, and that is the whole mechanism. A structural interface with\n * `name` and `build` on it would let a consumer author one, and the moment one\n * does, `ILankaVMDefinition` stops being a type the framework implements and\n * becomes a PORT — after which every member added to it is a compile error in\n * code nobody touched. Publishing an opaque type costs one line and keeps the\n * option space: a `dispose`, a `scope` field, even a call signature so that\n * `missionsVM()` could mean `resolveLankaVM(missionsVM)`, all stay additive.\n */\ndeclare const LANKA_VM_DEFINITION: unique symbol;\n\n/**\n * A ViewModel that has not been built yet.\n *\n * Hold it, pass it, type against it. There is nothing on it to call, because\n * calling it is `resolveLankaVM`'s job and a definition built by hand would be\n * an instance outside every scope's map.\n */\nexport interface ILankaVMDefinition<TViewModel extends ILankaReadableVM<object>> {\n\treadonly [LANKA_VM_DEFINITION]: TViewModel;\n}\n\n/**\n * Declares a ViewModel WITHOUT building it.\n *\n * ## When NOT to use this\n *\n * A browser-only application needs none of it. One module is one instance per\n * TAB there, so a module-level `createLankaVM` is still the shape, and wrapping\n * the nine factories in this one buys nothing but a lookup per read. Reach for\n * it when the same ViewModel has to exist on a SERVER, where one module is one\n * instance per PROCESS — shared by every user connected to it, so the first\n * request to write a draft into it serves that draft to the next stranger.\n *\n * ```ts\n * export const missionsVM = defineLankaVM({\n * \tname: \"MissionsVM\",\n * \tbuild: () => createLankaVM({ … }),\n * });\n * ```\n *\n * ## What it is not\n *\n * Not a tenth way to write a ViewModel. `build` returns whatever the nine\n * existing factories return and nothing here reaches inside it — a definition\n * adds a lifetime and takes nothing away.\n *\n * Not lazy in the sense `createLazyLankaVM` is. That one defers the STORE until\n * first read and still has one per module; this defers WHICH INSTANCE, and the\n * two compose.\n */\nexport const defineLankaVM = <TViewModel extends ILankaReadableVM<object>>(config: {\n\tname: string;\n\tbuild: () => TViewModel;\n}): ILankaVMDefinition<TViewModel> => {\n\tconst definition = Object.freeze({});\n\n\tlankaVMRecipes.recipes.set(definition, config);\n\n\treturn definition as ILankaVMDefinition<TViewModel>;\n};\n","import {\n\tgetActiveLankaScope,\n\thasLankaScopeResolver,\n\trequireActiveRuntime,\n} from \"../../../_internal/active-runtime/activeRuntime\";\nimport { lankaScenarioBootstrap } from \"../../../scenario/lanka-scenario-bootstrap/LankaScenarioBootstrap\";\nimport { lankaVMRecipes } from \"../../_internal/lanka-vm-recipes/lankaVMRecipes\";\nimport type { ILankaVMDefinition } from \"../define-lanka-vm/defineLankaVM\";\nimport type { ILankaReadableVM } from \"../../_interfaces/ILankaReadableVM\";\n\n/**\n * The instance of a definition that belongs to the CURRENT scope.\n *\n * Called twice in one scope it answers the same instance; called in two scopes\n * it answers two, and neither can see the other's state. In a browser there is\n * one scope for the life of the tab, so this is the module-level ViewModel a\n * consumer already knows — written once and correct on a server as well.\n *\n * ## It throws outside a scope, and that is the feature\n *\n * On a server the answer comes from the SCOPE seam rather than from the active\n * runtime, and the difference is not academic. `runInLankaServerScope` creates\n * its instance inside the scope and `createLanka` activates every instance it\n * builds, so during a request the process pointer and the scope's runtime are\n * the same object — keying on the runtime would make \"inside a request\" and\n * \"after one ended\" indistinguishable, and a call made after would be handed the\n * last stranger's ViewModel.\n *\n * So: a scope resolver installed and answering `null` means this ran outside\n * every request, and that fails loudly. No fallback, for the same reason\n * `requireActiveRuntime` has none — a wrong answer here is one user's data in\n * another user's page, and it would surface three layers from the call.\n *\n * ## Why the build is wrapped\n *\n * `ALankaVM.build()` declares a ViewModel that has scenario handlers into a\n * PROCESS-wide list, so that every instance ever created adopts it. That is\n * right for a module-level ViewModel and catastrophic for a scoped one: the list\n * would grow per request forever, and request N+1 would adopt request N's\n * ViewModel and run N's handlers against N's gateways. `buildScoped` is the seam\n * that keeps a scoped declaration out of it.\n */\nexport const resolveLankaVM = <TViewModel extends ILankaReadableVM<object>>(\n\tdefinition: ILankaVMDefinition<TViewModel>,\n): TViewModel => {\n\tconst recipe = lankaVMRecipes.recipes.get(definition);\n\n\tif (!recipe) {\n\t\tthrow new Error(\n\t\t\t\"resolveLankaVM was given something defineLankaVM did not make. A definition \" +\n\t\t\t\t\"is opaque on purpose: build it with defineLankaVM rather than by hand.\",\n\t\t);\n\t}\n\n\tconst runtime = requireActiveRuntime();\n\tconst scope = getActiveLankaScope();\n\n\tif (hasLankaScopeResolver() && !scope) {\n\t\tthrow new Error(\n\t\t\t`resolveLankaVM(\"${recipe.name}\") ran outside every scope. A scope resolver is ` +\n\t\t\t\t\"installed, which on a server means this code ran outside a request — and a \" +\n\t\t\t\t\"ViewModel resolved there would be the previous request's. Do this work inside \" +\n\t\t\t\t\"the scope, or start one.\",\n\t\t);\n\t}\n\n\t// The runtime when nothing knows about scopes: a browser tab is one scope for\n\t// its whole life, and the instance is what identifies it.\n\tconst instances = lankaVMRecipes.forScope(scope ?? runtime);\n\tconst held = instances.get(definition);\n\n\tif (held) return held as TViewModel;\n\n\tconst built = lankaScenarioBootstrap.buildScoped(() => recipe.build());\n\n\tinstances.set(definition, built);\n\n\treturn built as TViewModel;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,IAAM,WAAW,CAAC,UAA2C;AA8B7D,IAAM,kBAAkB,CAAwB,OAAe,SAC9D,IAAI,MAAM,OAAO;AAAA,EAChB,IAAI,QAAQ,MAAM,UAAU;AAC3B,UAAM,QAAQ,QAAQ,IAAI,QAAQ,MAAM,QAAQ;AAEhD,QACC,OAAO,SAAS,YAChB,OAAO,UAAU,cACjB,OAAO,OAAO,QAAQ,IAAI,GACzB;AACD,WAAK,IAAI,IAAI;AAAA,IACd;AAEA,WAAO;AAAA,EACR;AACD,CAAC;AASF,IAAM,gBAAgB,CAAwB,SAAuB;AACpE,MAAI,OAAO,oBAAI,IAAY;AAC3B,MAAI,QAAuB;AAC3B,MAAI,QAAuB;AAE3B,SAAO;AAAA,IACN,MAAM,MAA2B;AAAA,IAEjC,SAAS,MAAc;AACtB,YAAM,OAAO,KAAK;AAClB,UAAI,UAAU,QAAQ,MAAO,QAAO;AAKpC,aAAO,oBAAI,IAAY;AACvB,cAAQ;AACR,cAAQ,gBAAgB,MAAM,IAAI;AAElC,aAAO;AAAA,IACR;AAAA,EACD;AACD;AAGA,IAAM,cAAc,CAAC,MAA2B,MAAc,SAA0B;AACvF,QAAM,aAAa,SAAS,IAAI;AAChC,QAAM,aAAa,SAAS,IAAI;AAEhC,aAAW,OAAO,MAAM;AACvB,QAAI,CAAC,OAAO,GAAG,WAAW,GAAG,GAAG,WAAW,GAAG,CAAC,EAAG,QAAO;AAAA,EAC1D;AAEA,SAAO;AACR;AAkCO,IAAM,2BAA2B,CACvC,cACiC;AACjC,QAAM,OAAO,uBAAuB,GAAG,SAAS;AAChD,QAAM,YAAY,UAAU;AAC5B,QAAM,UAAU,cAAc,MAAM,UAAU,SAAS,CAAC;AAExD,SAAO;AAAA,IACN,IAAI,cAAmC;AACtC,aAAO,YAAY,QAAQ,KAAK,IAAI,oBAAI,IAAY;AAAA,IACrD;AAAA,IAEA,OAAe;AACd,aAAO,YAAY,QAAQ,QAAQ,IAAI,UAAU,SAAS;AAAA,IAC3D;AAAA,IAEA,aAAa,MAAc,MAAuB;AACjD,UAAI,CAAC,UAAW,QAAO;AAEvB,YAAM,OAAO,QAAQ,KAAK;AAE1B,aAAO,KAAK,SAAS,KAAK,YAAY,MAAM,MAAM,IAAI;AAAA,IACvD;AAAA,IAEA,cAAc,MAAc,MAAoB;AAC/C,YAAM,OAAO,IAAI,IAAI,QAAQ,KAAK,CAAC,GAAG,SAAS,IAAI,GAAG,SAAS,IAAI,CAAC;AAAA,IACrE;AAAA,IAEA,YAAoB;AACnB,aAAO,UAAU,SAAS;AAAA,IAC3B;AAAA,EACD;AACD;;;AC5IO,IAAM,8BAA8B,CAC1C,WACA,aACoC;AACpC,QAAM,UAAU,yBAAyB,SAAS;AAElD,QAAM,OAAO,UAAU,UAAU,CAAC,MAAM,SAAS;AAChD,QAAI,CAAC,QAAQ,aAAa,MAAM,IAAI,GAAG;AAItC,cAAQ,cAAc,MAAM,IAAI;AAChC;AAAA,IACD;AAEA,aAAS;AAAA,EACV,CAAC;AAED,SAAO,EAAE,MAAM,MAAM,QAAQ,KAAK,GAAG,KAAK;AAC3C;;;ACpDO,IAAM,iBAAiB;AAAA,EAC7B,SAAS,oBAAI,QAAgC;AAAA,EAC7C,WAAW,oBAAI,QAA2D;AAAA;AAAA,EAG1E,SAAS,OAA0D;AAClE,UAAM,WAAW,KAAK,UAAU,IAAI,KAAK;AAEzC,QAAI,SAAU,QAAO;AAErB,UAAM,UAAU,oBAAI,QAA0C;AAE9D,SAAK,UAAU,IAAI,OAAO,OAAO;AAEjC,WAAO;AAAA,EACR;AACD;;;ACcO,IAAM,gBAAgB,CAA8C,WAGrC;AACrC,QAAM,aAAa,OAAO,OAAO,CAAC,CAAC;AAEnC,iBAAe,QAAQ,IAAI,YAAY,MAAM;AAE7C,SAAO;AACR;;;ACvBO,IAAM,iBAAiB,CAC7B,eACgB;AAChB,QAAM,SAAS,eAAe,QAAQ,IAAI,UAAU;AAEpD,MAAI,CAAC,QAAQ;AACZ,UAAM,IAAI;AAAA,MACT;AAAA,IAED;AAAA,EACD;AAEA,QAAM,UAAU,qBAAqB;AACrC,QAAM,QAAQ,oBAAoB;AAElC,MAAI,sBAAsB,KAAK,CAAC,OAAO;AACtC,UAAM,IAAI;AAAA,MACT,mBAAmB,OAAO,IAAI;AAAA,IAI/B;AAAA,EACD;AAIA,QAAM,YAAY,eAAe,SAAS,SAAS,OAAO;AAC1D,QAAM,OAAO,UAAU,IAAI,UAAU;AAErC,MAAI,KAAM,QAAO;AAEjB,QAAM,QAAQ,uBAAuB,YAAY,MAAM,OAAO,MAAM,CAAC;AAErE,YAAU,IAAI,YAAY,KAAK;AAE/B,SAAO;AACR;","names":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export { I as ILankaRuntime, T as TLankaRuntimeResolver, s as setLankaRuntimeResolver } from '../activeRuntime-
|
|
1
|
+
export { I as ILankaRuntime, T as TLankaRuntimeResolver, a as TLankaScopeResolver, g as getLankaProcessRuntime, s as setActiveLankaRuntime, b as setLankaRuntimeResolver, c as setLankaScopeResolver } from '../activeRuntime-BO-qY0yY.js';
|
|
2
2
|
import { a as TLankaValidationResult } from '../lankaStandardValidator-BUFnysK0.js';
|
|
3
3
|
import '../ILankaScenarioVM-DpKFL3iE.js';
|
|
4
|
-
import '../LankaScenarioLocator-
|
|
4
|
+
import '../LankaScenarioLocator-Dki2Es3O.js';
|
|
5
5
|
import '../ILankaScenarioMetadata-Dj4GCqmX.js';
|
|
6
6
|
import '../ALankaGateway-BrVPaZN5.js';
|
|
7
|
-
import '../LankaSharedStoreLocator-
|
|
7
|
+
import '../LankaSharedStoreLocator-jsz_gnUm.js';
|
|
8
8
|
import '../ALankaSharedStore-B7uepuuk.js';
|
|
9
9
|
import 'zustand/vanilla';
|
|
10
10
|
import '../ILankaRuntimeConfig-Vl436GWK.js';
|
package/dist/_internal/index.js
CHANGED
|
@@ -7,8 +7,11 @@ import {
|
|
|
7
7
|
} from "../chunk-J5LA3Q6D.js";
|
|
8
8
|
import "../chunk-G32H73QY.js";
|
|
9
9
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
getLankaProcessRuntime,
|
|
11
|
+
setActiveLankaRuntime,
|
|
12
|
+
setLankaRuntimeResolver,
|
|
13
|
+
setLankaScopeResolver
|
|
14
|
+
} from "../chunk-XGMXT4XZ.js";
|
|
12
15
|
|
|
13
16
|
// src/_internal/generate-uuid/generateUuid.ts
|
|
14
17
|
function generateUuid() {
|
|
@@ -50,10 +53,13 @@ var lankaValueOrThrow = (result, context) => {
|
|
|
50
53
|
};
|
|
51
54
|
export {
|
|
52
55
|
generateUuid,
|
|
56
|
+
getLankaProcessRuntime,
|
|
53
57
|
getStringField,
|
|
54
58
|
isRecord,
|
|
55
59
|
lankaForeignSchemaMessage,
|
|
56
60
|
lankaValueOrThrow,
|
|
57
|
-
|
|
61
|
+
setActiveLankaRuntime,
|
|
62
|
+
setLankaRuntimeResolver,
|
|
63
|
+
setLankaScopeResolver
|
|
58
64
|
};
|
|
59
65
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/_internal/generate-uuid/generateUuid.ts","../../src/_internal/lanka-foreign-schema-message/lankaForeignSchemaMessage.ts","../../src/_internal/lanka-value-or-throw/lankaValueOrThrow.ts"],"sourcesContent":["export function generateUuid() {\n\tif (typeof crypto !== \"undefined\" && typeof crypto.randomUUID === \"function\") {\n\t\treturn crypto.randomUUID();\n\t}\n\n\tlet d = new Date().getTime();\n\n\tlet d2 =\n\t\t(typeof performance !== \"undefined\" && performance.now && performance.now() * 1000) || 0;\n\n\treturn \"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\".replace(/[xy]/g, function (c) {\n\t\tlet r = Math.random() * 16;\n\n\t\tif (d > 0) {\n\t\t\tr = ((d + r) % 16) | 0;\n\t\t\td = Math.floor(d / 16);\n\t\t} else {\n\t\t\tr = ((d2 + r) % 16) | 0;\n\t\t\td2 = Math.floor(d2 / 16);\n\t\t}\n\n\t\treturn (c === \"x\" ? r : (r & 0x3) | 0x8).toString(16);\n\t});\n}\n","/**\n * What to say when a validator is handed a schema from another library.\n *\n * ## Why this is not three sentences in three packages\n *\n * `@lankajs/yup`, `@lankajs/typebox` and `@lankajs/effect` each refuse a schema\n * they do not own, and each has to answer the same follow-up: is this a schema at\n * all, and if so whose? The answer is identical in all three because the\n * SITUATION is identical — only the lead differs, because only the marker each\n * looked for differs.\n *\n * Written three times it was three copies, and `check:composition` said so. Made\n * deliberately different to satisfy the gate it would have been worse: three\n * wordings of one fact, and a consumer who met two of them would be entitled to\n * think they meant different things.\n *\n * ## Why `lanka/internal` and not the facade\n *\n * This tier exists for exactly this: \"a sibling package needs these and must not\n * reach into another package's `src/`\". It promises nothing beyond a patch, which\n * is the right promise for a sentence.\n *\n * A facade `isStandardSchema` was proposed first and refused, for a reason worth\n * keeping: it would answer `true` for every yup schema, and `lankaStandardValidator`\n * throws on every yup schema. A consumer writing `if (isStandardSchema(s))\n * validate(s, …)` would have written the exact bug the family works to prevent,\n * and the name would have told them it was safe.\n */\nexport const lankaForeignSchemaMessage = (schema: unknown, { lead }: { lead: string }): string => {\n\t// Object OR function: arktype's schema is callable, with `~standard` on its\n\t// prototype, and a check reading only objects would tell an arktype user\n\t// their schema is not a schema.\n\tconst indexable =\n\t\tschema !== null && (typeof schema === \"object\" || typeof schema === \"function\");\n\n\tif (indexable && \"~standard\" in schema) {\n\t\treturn (\n\t\t\t`${lead} It does carry \\`~standard\\`, so it belongs to another library in ` +\n\t\t\t\"`modules/validators/` — validate it with that package's validator, or with \" +\n\t\t\t\"`lankaStandardValidator`.\"\n\t\t);\n\t}\n\n\treturn (\n\t\t`${lead} Either it is not a schema at all, or it belongs to a library with its ` +\n\t\t\"own package in `modules/validators/`.\"\n\t);\n};\n","import { LankaValidationError } from \"../../validation/lanka-validation-error/LankaValidationError\";\nimport type { TLankaValidationResult } from \"../../validation/_types/TLankaValidationResult\";\n\n/**\n * The strict path, built from the safe one.\n *\n * `ILankaValidator` publishes two methods over one answer: `validateSafe`\n * returns an outcome, and `validate` is that outcome with the failure raised.\n * Every implementation of the port therefore writes the same five lines, and\n * three of them in this repository did — `check:composition` counted them.\n *\n * It is a GENERIC over the outcome rather than a helper returning `unknown`,\n * which is the whole reason it can be shared: `@lankajs/typebox` returns\n * `Static<TSchema>` and `@lankajs/effect` returns `Schema.Schema.Type<TAlias>`,\n * and a helper that erased those would have cost each package its inference —\n * a worse trade than the duplication it removed.\n *\n * `lanka/internal` because a sibling package needs it and must not reach into\n * core's `src/`. It promises nothing beyond a patch, which is right for five\n * lines that only restate what the port already says.\n */\nexport const lankaValueOrThrow = <TOutput>(\n\tresult: TLankaValidationResult<TOutput>,\n\tcontext: string,\n): TOutput => {\n\tif (result.success) return result.data;\n\n\tthrow new LankaValidationError(\n\t\t`Validation failed for ${context}`,\n\t\tresult.errors,\n\t\tresult.fields,\n\t);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/_internal/generate-uuid/generateUuid.ts","../../src/_internal/lanka-foreign-schema-message/lankaForeignSchemaMessage.ts","../../src/_internal/lanka-value-or-throw/lankaValueOrThrow.ts"],"sourcesContent":["export function generateUuid() {\n\tif (typeof crypto !== \"undefined\" && typeof crypto.randomUUID === \"function\") {\n\t\treturn crypto.randomUUID();\n\t}\n\n\tlet d = new Date().getTime();\n\n\tlet d2 =\n\t\t(typeof performance !== \"undefined\" && performance.now && performance.now() * 1000) || 0;\n\n\treturn \"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\".replace(/[xy]/g, function (c) {\n\t\tlet r = Math.random() * 16;\n\n\t\tif (d > 0) {\n\t\t\tr = ((d + r) % 16) | 0;\n\t\t\td = Math.floor(d / 16);\n\t\t} else {\n\t\t\tr = ((d2 + r) % 16) | 0;\n\t\t\td2 = Math.floor(d2 / 16);\n\t\t}\n\n\t\treturn (c === \"x\" ? r : (r & 0x3) | 0x8).toString(16);\n\t});\n}\n","/**\n * What to say when a validator is handed a schema from another library.\n *\n * ## Why this is not three sentences in three packages\n *\n * `@lankajs/yup`, `@lankajs/typebox` and `@lankajs/effect` each refuse a schema\n * they do not own, and each has to answer the same follow-up: is this a schema at\n * all, and if so whose? The answer is identical in all three because the\n * SITUATION is identical — only the lead differs, because only the marker each\n * looked for differs.\n *\n * Written three times it was three copies, and `check:composition` said so. Made\n * deliberately different to satisfy the gate it would have been worse: three\n * wordings of one fact, and a consumer who met two of them would be entitled to\n * think they meant different things.\n *\n * ## Why `lanka/internal` and not the facade\n *\n * This tier exists for exactly this: \"a sibling package needs these and must not\n * reach into another package's `src/`\". It promises nothing beyond a patch, which\n * is the right promise for a sentence.\n *\n * A facade `isStandardSchema` was proposed first and refused, for a reason worth\n * keeping: it would answer `true` for every yup schema, and `lankaStandardValidator`\n * throws on every yup schema. A consumer writing `if (isStandardSchema(s))\n * validate(s, …)` would have written the exact bug the family works to prevent,\n * and the name would have told them it was safe.\n */\nexport const lankaForeignSchemaMessage = (schema: unknown, { lead }: { lead: string }): string => {\n\t// Object OR function: arktype's schema is callable, with `~standard` on its\n\t// prototype, and a check reading only objects would tell an arktype user\n\t// their schema is not a schema.\n\tconst indexable =\n\t\tschema !== null && (typeof schema === \"object\" || typeof schema === \"function\");\n\n\tif (indexable && \"~standard\" in schema) {\n\t\treturn (\n\t\t\t`${lead} It does carry \\`~standard\\`, so it belongs to another library in ` +\n\t\t\t\"`modules/validators/` — validate it with that package's validator, or with \" +\n\t\t\t\"`lankaStandardValidator`.\"\n\t\t);\n\t}\n\n\treturn (\n\t\t`${lead} Either it is not a schema at all, or it belongs to a library with its ` +\n\t\t\"own package in `modules/validators/`.\"\n\t);\n};\n","import { LankaValidationError } from \"../../validation/lanka-validation-error/LankaValidationError\";\nimport type { TLankaValidationResult } from \"../../validation/_types/TLankaValidationResult\";\n\n/**\n * The strict path, built from the safe one.\n *\n * `ILankaValidator` publishes two methods over one answer: `validateSafe`\n * returns an outcome, and `validate` is that outcome with the failure raised.\n * Every implementation of the port therefore writes the same five lines, and\n * three of them in this repository did — `check:composition` counted them.\n *\n * It is a GENERIC over the outcome rather than a helper returning `unknown`,\n * which is the whole reason it can be shared: `@lankajs/typebox` returns\n * `Static<TSchema>` and `@lankajs/effect` returns `Schema.Schema.Type<TAlias>`,\n * and a helper that erased those would have cost each package its inference —\n * a worse trade than the duplication it removed.\n *\n * `lanka/internal` because a sibling package needs it and must not reach into\n * core's `src/`. It promises nothing beyond a patch, which is right for five\n * lines that only restate what the port already says.\n */\nexport const lankaValueOrThrow = <TOutput>(\n\tresult: TLankaValidationResult<TOutput>,\n\tcontext: string,\n): TOutput => {\n\tif (result.success) return result.data;\n\n\tthrow new LankaValidationError(\n\t\t`Validation failed for ${context}`,\n\t\tresult.errors,\n\t\tresult.fields,\n\t);\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAAO,SAAS,eAAe;AAC9B,MAAI,OAAO,WAAW,eAAe,OAAO,OAAO,eAAe,YAAY;AAC7E,WAAO,OAAO,WAAW;AAAA,EAC1B;AAEA,MAAI,KAAI,oBAAI,KAAK,GAAE,QAAQ;AAE3B,MAAI,KACF,OAAO,gBAAgB,eAAe,YAAY,OAAO,YAAY,IAAI,IAAI,OAAS;AAExF,SAAO,uCAAuC,QAAQ,SAAS,SAAU,GAAG;AAC3E,QAAI,IAAI,KAAK,OAAO,IAAI;AAExB,QAAI,IAAI,GAAG;AACV,WAAM,IAAI,KAAK,KAAM;AACrB,UAAI,KAAK,MAAM,IAAI,EAAE;AAAA,IACtB,OAAO;AACN,WAAM,KAAK,KAAK,KAAM;AACtB,WAAK,KAAK,MAAM,KAAK,EAAE;AAAA,IACxB;AAEA,YAAQ,MAAM,MAAM,IAAK,IAAI,IAAO,GAAK,SAAS,EAAE;AAAA,EACrD,CAAC;AACF;;;ACKO,IAAM,4BAA4B,CAAC,QAAiB,EAAE,KAAK,MAAgC;AAIjG,QAAM,YACL,WAAW,SAAS,OAAO,WAAW,YAAY,OAAO,WAAW;AAErE,MAAI,aAAa,eAAe,QAAQ;AACvC,WACC,GAAG,IAAI;AAAA,EAIT;AAEA,SACC,GAAG,IAAI;AAGT;;;AC1BO,IAAM,oBAAoB,CAChC,QACA,YACa;AACb,MAAI,OAAO,QAAS,QAAO,OAAO;AAElC,QAAM,IAAI;AAAA,IACT,yBAAyB,OAAO;AAAA,IAChC,OAAO;AAAA,IACP,OAAO;AAAA,EACR;AACD;","names":[]}
|