better-call 0.0.0-experimental.06264e12
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/LICENSE +21 -0
- package/README.md +254 -0
- package/dist/error.cjs +67 -0
- package/dist/error.cjs.map +1 -0
- package/dist/error.d.cts +46 -0
- package/dist/error.d.mts +46 -0
- package/dist/error.mjs +64 -0
- package/dist/error.mjs.map +1 -0
- package/dist/fn.cjs +335 -0
- package/dist/fn.cjs.map +1 -0
- package/dist/fn.d.cts +312 -0
- package/dist/fn.d.mts +312 -0
- package/dist/fn.mjs +335 -0
- package/dist/fn.mjs.map +1 -0
- package/dist/index.cjs +37 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +46 -0
- package/dist/index.d.mts +46 -0
- package/dist/index.mjs +24 -0
- package/dist/index.mjs.map +1 -0
- package/dist/module.cjs +111 -0
- package/dist/module.cjs.map +1 -0
- package/dist/module.d.cts +249 -0
- package/dist/module.d.mts +249 -0
- package/dist/module.mjs +102 -0
- package/dist/module.mjs.map +1 -0
- package/dist/plugins/http.cjs +185 -0
- package/dist/plugins/http.cjs.map +1 -0
- package/dist/plugins/http.d.cts +1261 -0
- package/dist/plugins/http.d.mts +1261 -0
- package/dist/plugins/http.mjs +175 -0
- package/dist/plugins/http.mjs.map +1 -0
- package/dist/plugins/read-only.cjs +19 -0
- package/dist/plugins/read-only.cjs.map +1 -0
- package/dist/plugins/read-only.d.cts +17 -0
- package/dist/plugins/read-only.d.mts +17 -0
- package/dist/plugins/read-only.mjs +19 -0
- package/dist/plugins/read-only.mjs.map +1 -0
- package/dist/schema.cjs +167 -0
- package/dist/schema.cjs.map +1 -0
- package/dist/schema.d.cts +225 -0
- package/dist/schema.d.mts +225 -0
- package/dist/schema.mjs +159 -0
- package/dist/schema.mjs.map +1 -0
- package/dist/scope.d.cts +18 -0
- package/dist/scope.d.mts +18 -0
- package/dist/storage.cjs +256 -0
- package/dist/storage.cjs.map +1 -0
- package/dist/storage.d.cts +195 -0
- package/dist/storage.d.mts +195 -0
- package/dist/storage.mjs +253 -0
- package/dist/storage.mjs.map +1 -0
- package/dist/types.d.cts +8 -0
- package/dist/types.d.mts +8 -0
- package/dist/var.cjs +162 -0
- package/dist/var.cjs.map +1 -0
- package/dist/var.d.cts +36 -0
- package/dist/var.d.mts +36 -0
- package/dist/var.mjs +154 -0
- package/dist/var.mjs.map +1 -0
- package/package.json +92 -0
package/dist/fn.cjs
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
const require_error = require("./error.cjs");
|
|
2
|
+
const require_schema = require("./schema.cjs");
|
|
3
|
+
const require_module = require("./module.cjs");
|
|
4
|
+
const require_var = require("./var.cjs");
|
|
5
|
+
//#region src/fn.ts
|
|
6
|
+
const isThenable = (value) => typeof value?.then === "function";
|
|
7
|
+
const STORE = Symbol("var-store");
|
|
8
|
+
const ACTIVE = Symbol("active-plugins");
|
|
9
|
+
const EXTS = Symbol("active-var-extensions");
|
|
10
|
+
const READONLY = Symbol("readonly-lock");
|
|
11
|
+
const WITH = Symbol("with-overrides");
|
|
12
|
+
const defineFn = (key, options, declared) => {
|
|
13
|
+
const modules = require_module.resolveModules(options.use ?? []);
|
|
14
|
+
const own = [];
|
|
15
|
+
const ownExts = [];
|
|
16
|
+
const scanMembers = (mod) => {
|
|
17
|
+
for (const value of Object.values(mod)) if (require_module.isOn(value) && !own.includes(value)) own.push(value);
|
|
18
|
+
else if (require_module.isVarExtension(value)) ownExts.push(value);
|
|
19
|
+
else if (require_module.isNamespace(value)) scanMembers(value);
|
|
20
|
+
};
|
|
21
|
+
for (const mod of modules) scanMembers(mod);
|
|
22
|
+
const usable = require_module.collectUsable(modules);
|
|
23
|
+
const tupleInput = Array.isArray(options.input) ? options.input : void 0;
|
|
24
|
+
const declaredErrors = options.errors;
|
|
25
|
+
const outputValidation = require_schema.outputContract(options.output).validation;
|
|
26
|
+
const errorTypes = declaredErrors ? Object.fromEntries(Object.entries(declaredErrors).map(([tag, schema]) => [tag, require_schema.asType(schema)])) : void 0;
|
|
27
|
+
const inputVars = [];
|
|
28
|
+
const declaredInput = options.input;
|
|
29
|
+
const wholeVar = declaredInput && require_schema.isVar(declaredInput) ? declaredInput.name : void 0;
|
|
30
|
+
if (declaredInput && !wholeVar) {
|
|
31
|
+
for (const [field, def] of Object.entries(declaredInput)) if (require_schema.isVar(def)) inputVars.push([field, def.name]);
|
|
32
|
+
}
|
|
33
|
+
if (options.readonly) {
|
|
34
|
+
if (options.provides?.length) throw new require_error.ValidationError(`${key}.readonly`, "a readonly fn cannot declare provides - it promises writes");
|
|
35
|
+
if (wholeVar !== void 0 || inputVars.length > 0) throw new require_error.ValidationError(`${key}.readonly`, "a readonly fn cannot bind input to vars - that is a write");
|
|
36
|
+
}
|
|
37
|
+
const callable = (...callArgs) => {
|
|
38
|
+
const input = tupleInput ? callArgs.slice(0, tupleInput.length) : callArgs[0];
|
|
39
|
+
const parent = tupleInput ? callArgs[tupleInput.length] : callArgs[1];
|
|
40
|
+
const cells = parent?.[STORE] ?? {};
|
|
41
|
+
const lockedBy = options.readonly ? key : parent?.[READONLY];
|
|
42
|
+
const inherited = parent?.[ACTIVE] ?? [];
|
|
43
|
+
const active = own.length === 0 ? inherited : [...inherited, ...own.filter((e) => !inherited.includes(e))];
|
|
44
|
+
const chain = active.filter((entry) => require_module.matchesTarget(entry.target, key));
|
|
45
|
+
const withFns = parent?.[WITH];
|
|
46
|
+
const inheritedExts = parent?.[EXTS] ?? [];
|
|
47
|
+
const exts = ownExts.length === 0 ? inheritedExts : [...inheritedExts, ...ownExts.filter((e) => !inheritedExts.includes(e))];
|
|
48
|
+
let ctx;
|
|
49
|
+
const frame = {
|
|
50
|
+
cells,
|
|
51
|
+
key,
|
|
52
|
+
lockedBy,
|
|
53
|
+
entries: active
|
|
54
|
+
};
|
|
55
|
+
const extendValue = (name, raw, value) => {
|
|
56
|
+
let merged = value;
|
|
57
|
+
for (const ext of exts) {
|
|
58
|
+
if (ext.name !== name) continue;
|
|
59
|
+
const extra = require_schema.validate(require_schema.asType(ext.schema), raw, `${key}.${name}`);
|
|
60
|
+
merged = {
|
|
61
|
+
...merged,
|
|
62
|
+
...extra
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return merged;
|
|
66
|
+
};
|
|
67
|
+
let parsed;
|
|
68
|
+
if (tupleInput) {
|
|
69
|
+
const issues = [];
|
|
70
|
+
parsed = tupleInput.map((def, index) => {
|
|
71
|
+
try {
|
|
72
|
+
return require_schema.validate(require_schema.asType(def), input[index], `${key}[${index}]`);
|
|
73
|
+
} catch (thrown) {
|
|
74
|
+
if (!(thrown instanceof require_error.ValidationError)) throw thrown;
|
|
75
|
+
issues.push(...thrown.issues);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
const firstIssue = issues[0];
|
|
80
|
+
if (firstIssue) throw new require_error.ValidationError(firstIssue.path, firstIssue.message, issues);
|
|
81
|
+
} else parsed = options.input === void 0 ? input : require_schema.validate(require_schema.asType(options.input), input, key);
|
|
82
|
+
for (const entry of chain) {
|
|
83
|
+
if (!entry.extend?.input || tupleInput) continue;
|
|
84
|
+
const extra = require_schema.validate(require_schema.asType(entry.extend.input), input, `${key}.on`);
|
|
85
|
+
parsed = {
|
|
86
|
+
...parsed ?? {},
|
|
87
|
+
...extra
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (wholeVar !== void 0 && parsed !== void 0) {
|
|
91
|
+
parsed = extendValue(wholeVar, input, parsed);
|
|
92
|
+
require_var.writeVar(frame, wholeVar, parsed);
|
|
93
|
+
}
|
|
94
|
+
for (const [field, name] of inputVars) {
|
|
95
|
+
const raw = input?.[field];
|
|
96
|
+
const value = parsed?.[field];
|
|
97
|
+
if (value === void 0) continue;
|
|
98
|
+
const merged = extendValue(name, raw, value);
|
|
99
|
+
parsed[field] = merged;
|
|
100
|
+
require_var.writeVar(frame, name, merged);
|
|
101
|
+
}
|
|
102
|
+
const base = {
|
|
103
|
+
input: parsed,
|
|
104
|
+
error: (tag, data) => {
|
|
105
|
+
const schema = errorTypes?.[tag];
|
|
106
|
+
if (!schema) throw new require_error.ValidationError(`${key}.errors.${tag}`, errorTypes ? `"${tag}" is not a declared error of "${key}"` : `"${key}" declares no errors`);
|
|
107
|
+
return new require_error.FnError(tag, require_schema.validate(schema, data ?? {}, `${key}.errors.${tag}`), key);
|
|
108
|
+
},
|
|
109
|
+
[STORE]: cells,
|
|
110
|
+
[ACTIVE]: active,
|
|
111
|
+
[EXTS]: exts,
|
|
112
|
+
[READONLY]: lockedBy,
|
|
113
|
+
[WITH]: withFns,
|
|
114
|
+
fn: builderFn(key === "anonymous" ? "" : key, { use: options.use ?? [] }),
|
|
115
|
+
types: require_schema.vTypes
|
|
116
|
+
};
|
|
117
|
+
ctx = require_var.contextScope(frame, base);
|
|
118
|
+
const bindUsable = (target, map, overrides) => {
|
|
119
|
+
for (const [name, used] of Object.entries(map)) {
|
|
120
|
+
const override = overrides?.[name];
|
|
121
|
+
if (require_schema.isVar(used)) {
|
|
122
|
+
const varName = used.name;
|
|
123
|
+
Object.defineProperty(target, name, {
|
|
124
|
+
get: () => require_var.readVarThrough(frame, varName),
|
|
125
|
+
set: (value) => require_var.writeVar(frame, varName, value),
|
|
126
|
+
enumerable: true,
|
|
127
|
+
configurable: true
|
|
128
|
+
});
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (!require_module.isFn(used)) {
|
|
132
|
+
const group = {};
|
|
133
|
+
bindUsable(group, used, require_module.isFn(override) ? void 0 : override);
|
|
134
|
+
target[name] = group;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (override !== void 0) {
|
|
138
|
+
target[name] = require_module.isFn(override) ? (i) => override(i, ctx) : override;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const usedArity = used.$arity;
|
|
142
|
+
target[name] = usedArity === void 0 ? (i) => used(i, ctx) : (...args) => {
|
|
143
|
+
const padded = args.slice(0, usedArity);
|
|
144
|
+
while (padded.length < usedArity) padded.push(void 0);
|
|
145
|
+
return used(...padded, ctx);
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
bindUsable(base, usable, withFns);
|
|
150
|
+
const missing = (name) => {
|
|
151
|
+
const value = require_var.readVar(cells, name);
|
|
152
|
+
return value === void 0 || value === null;
|
|
153
|
+
};
|
|
154
|
+
const checkRequires = () => {
|
|
155
|
+
for (const name of options.requires ?? []) if (missing(name)) throw new require_error.ValidationError(`${key}.requires.${name}`, `required var "${name}" is not set${parent === void 0 ? " - called without a parent context" : ""}`);
|
|
156
|
+
};
|
|
157
|
+
let bodyRan = false;
|
|
158
|
+
const declaredTracked = (c) => {
|
|
159
|
+
bodyRan = true;
|
|
160
|
+
return declared(c);
|
|
161
|
+
};
|
|
162
|
+
const body = chain.reduceRight((next, entry) => (c) => entry.handler(c, () => next(c)), declaredTracked);
|
|
163
|
+
const finish = (result) => {
|
|
164
|
+
if (outputValidation !== void 0) require_schema.validate(require_schema.asType(outputValidation), result, `${key}.output`);
|
|
165
|
+
if (bodyRan) {
|
|
166
|
+
for (const name of options.provides ?? []) if (missing(name)) throw new require_error.ValidationError(`${key}.provides.${name}`, `declared to provide "${name}" but it was left unset`);
|
|
167
|
+
}
|
|
168
|
+
return result;
|
|
169
|
+
};
|
|
170
|
+
const decorate = (thrown) => {
|
|
171
|
+
if (thrown instanceof require_error.FnError || thrown instanceof require_error.UnexpectedError) {
|
|
172
|
+
if (thrown.trail[thrown.trail.length - 1] !== key) thrown.trail.push(key);
|
|
173
|
+
return thrown;
|
|
174
|
+
}
|
|
175
|
+
return errorTypes ? new require_error.UnexpectedError(thrown, key) : thrown;
|
|
176
|
+
};
|
|
177
|
+
const run = () => {
|
|
178
|
+
checkRequires();
|
|
179
|
+
let result;
|
|
180
|
+
try {
|
|
181
|
+
result = body(ctx);
|
|
182
|
+
} catch (thrown) {
|
|
183
|
+
throw decorate(thrown);
|
|
184
|
+
}
|
|
185
|
+
return isThenable(result) ? result.then(finish, (thrown) => {
|
|
186
|
+
throw decorate(thrown);
|
|
187
|
+
}) : finish(result);
|
|
188
|
+
};
|
|
189
|
+
return run();
|
|
190
|
+
};
|
|
191
|
+
/** `.try`: declared errors as a value, everything else still throws. */
|
|
192
|
+
const tryCall = (...callArgs) => {
|
|
193
|
+
const settle = (thrown) => {
|
|
194
|
+
if (thrown instanceof require_error.FnError) return {
|
|
195
|
+
ok: false,
|
|
196
|
+
error: thrown
|
|
197
|
+
};
|
|
198
|
+
throw thrown;
|
|
199
|
+
};
|
|
200
|
+
try {
|
|
201
|
+
const result = callable(...callArgs);
|
|
202
|
+
return isThenable(result) ? result.then((value) => ({
|
|
203
|
+
ok: true,
|
|
204
|
+
value
|
|
205
|
+
}), settle) : {
|
|
206
|
+
ok: true,
|
|
207
|
+
value: result
|
|
208
|
+
};
|
|
209
|
+
} catch (thrown) {
|
|
210
|
+
return settle(thrown);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* `.with`: a hand-built context. Keys naming one of this fn's `use`
|
|
215
|
+
* fns become OVERRIDES (carried by the subtree via `WITH`); everything
|
|
216
|
+
* else SEEDS a var in a fresh store. A parent given to the bound call
|
|
217
|
+
* is forked - its cells are copied, so seeds and writes inside never
|
|
218
|
+
* leak back into it.
|
|
219
|
+
*/
|
|
220
|
+
const withCall = (context) => {
|
|
221
|
+
const makeParent = (given) => {
|
|
222
|
+
const source = given?.[STORE] ?? {};
|
|
223
|
+
const cells = Object.fromEntries(Object.entries(source).map(([name, cell]) => [name, { ...cell }]));
|
|
224
|
+
const seedFrame = {
|
|
225
|
+
cells,
|
|
226
|
+
key: `${key}.with`,
|
|
227
|
+
lockedBy: void 0,
|
|
228
|
+
entries: []
|
|
229
|
+
};
|
|
230
|
+
const overrides = { ...given?.[WITH] };
|
|
231
|
+
const applyWith = (map, entries, target) => {
|
|
232
|
+
for (const [name, value] of Object.entries(entries)) {
|
|
233
|
+
const member = map?.[name];
|
|
234
|
+
if (member === void 0) require_var.writeVar(seedFrame, name, value);
|
|
235
|
+
else if (require_schema.isVar(member)) require_var.writeVar(seedFrame, member.name, value);
|
|
236
|
+
else if (require_module.isFn(member) || typeof value !== "object" || !value) target[name] = value;
|
|
237
|
+
else {
|
|
238
|
+
const existing = target[name];
|
|
239
|
+
const sub = existing && typeof existing === "object" ? existing : {};
|
|
240
|
+
target[name] = sub;
|
|
241
|
+
applyWith(member, value, sub);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
applyWith(usable, context, overrides);
|
|
246
|
+
return {
|
|
247
|
+
[STORE]: cells,
|
|
248
|
+
[ACTIVE]: given?.[ACTIVE],
|
|
249
|
+
[EXTS]: given?.[EXTS],
|
|
250
|
+
[READONLY]: given?.[READONLY],
|
|
251
|
+
[WITH]: Object.keys(overrides).length > 0 ? overrides : void 0
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
const rewrite = (callArgs) => {
|
|
255
|
+
if (tupleInput) {
|
|
256
|
+
const padded = callArgs.slice(0, tupleInput.length);
|
|
257
|
+
while (padded.length < tupleInput.length) padded.push(void 0);
|
|
258
|
+
return [...padded, makeParent(callArgs[tupleInput.length])];
|
|
259
|
+
}
|
|
260
|
+
return [callArgs[0], makeParent(callArgs[1])];
|
|
261
|
+
};
|
|
262
|
+
const bound = (...callArgs) => callable(...rewrite(callArgs));
|
|
263
|
+
bound.try = (...callArgs) => tryCall(...rewrite(callArgs));
|
|
264
|
+
return bound;
|
|
265
|
+
};
|
|
266
|
+
return Object.assign(callable, {
|
|
267
|
+
$fn: true,
|
|
268
|
+
key,
|
|
269
|
+
provides: options.provides ?? [],
|
|
270
|
+
try: tryCall,
|
|
271
|
+
with: withCall,
|
|
272
|
+
...tupleInput ? { $arity: tupleInput.length } : {},
|
|
273
|
+
$schema: {
|
|
274
|
+
...options.input !== void 0 ? { input: options.input } : {},
|
|
275
|
+
...options.output !== void 0 ? { output: options.output } : {},
|
|
276
|
+
...declaredErrors ? { errors: declaredErrors } : {},
|
|
277
|
+
...options.requires?.length ? { requires: options.requires } : {},
|
|
278
|
+
...options.idempotent === true ? { idempotent: true } : {}
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
/**
|
|
283
|
+
* The builder half of `v.fn`: no handler yet, so calls accumulate. Keys
|
|
284
|
+
* CONCATENATE ("auth" then ".create" -> "auth.create"), `use`/`requires`/
|
|
285
|
+
* `provides` merge, other options child-wins - and the returned `.fn`
|
|
286
|
+
* follows the same one rule recursively: a handler terminates, anything
|
|
287
|
+
* else keeps building.
|
|
288
|
+
*/
|
|
289
|
+
const mergeOptions = (base, child) => ({
|
|
290
|
+
...base,
|
|
291
|
+
...child,
|
|
292
|
+
use: [...base.use ?? [], ...child.use ?? []],
|
|
293
|
+
requires: [...base.requires ?? [], ...child.requires ?? []],
|
|
294
|
+
provides: [...base.provides ?? [], ...child.provides ?? []],
|
|
295
|
+
...base.errors || child.errors ? { errors: {
|
|
296
|
+
...base.errors ?? {},
|
|
297
|
+
...child.errors ?? {}
|
|
298
|
+
} } : {}
|
|
299
|
+
});
|
|
300
|
+
const builderFn = (baseKey, base) => {
|
|
301
|
+
const build = (...args) => {
|
|
302
|
+
const hasKey = typeof args[0] === "string";
|
|
303
|
+
const childKey = hasKey ? args[0] : "";
|
|
304
|
+
const rest = hasKey ? args.slice(1) : args;
|
|
305
|
+
const first = rest[0];
|
|
306
|
+
const handler = typeof first === "function" ? first : rest[1];
|
|
307
|
+
const childOptions = typeof first === "function" ? {} : first ?? {};
|
|
308
|
+
const key = baseKey + childKey;
|
|
309
|
+
const options = mergeOptions(base, childOptions);
|
|
310
|
+
if (typeof handler !== "function") return {
|
|
311
|
+
fn: builderFn(key, options),
|
|
312
|
+
$fnSchema: {
|
|
313
|
+
input: options.input,
|
|
314
|
+
output: options.output
|
|
315
|
+
},
|
|
316
|
+
on: (target, a, b) => require_module.on(typeof target === "string" && !target.startsWith("var.") && !target.startsWith("scope.") ? key + target : target, a, b)
|
|
317
|
+
};
|
|
318
|
+
return defineFn(key || "anonymous", options, handler);
|
|
319
|
+
};
|
|
320
|
+
return Object.assign(build, {
|
|
321
|
+
$fnSchema: {
|
|
322
|
+
input: base.input,
|
|
323
|
+
output: base.output
|
|
324
|
+
},
|
|
325
|
+
type: (signature = {}) => ({ $fnSchema: {
|
|
326
|
+
input: signature.input,
|
|
327
|
+
output: signature.output
|
|
328
|
+
} })
|
|
329
|
+
});
|
|
330
|
+
};
|
|
331
|
+
const fnImpl = builderFn("", {});
|
|
332
|
+
//#endregion
|
|
333
|
+
exports.fnImpl = fnImpl;
|
|
334
|
+
|
|
335
|
+
//# sourceMappingURL=fn.cjs.map
|
package/dist/fn.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fn.cjs","names":["resolveModules","isOn","isVarExtension","isNamespace","collectUsable","outputContract","asType","isVar","ValidationError","matchesTarget","validate","FnError","vTypes","contextScope","readVarThrough","writeVar","isFn","readVar","UnexpectedError","onImpl"],"sources":["../src/fn.ts"],"sourcesContent":["import { FnError, type Issue, UnexpectedError, ValidationError } from \"./error\";\nimport {\n\ttype ApplyOns,\n\tcollectUsable,\n\tisFn,\n\tisNamespace,\n\tisOn,\n\tisVarExtension,\n\ttype Module,\n\ttype ModuleFns,\n\tmatchesTarget,\n\ttype OnEntry,\n\ton as onImpl,\n\tresolveModules,\n\ttype TargetMatches,\n\ttype VarExtension,\n\ttype VarGetContext,\n\ttype VarSetContext,\n\ttype WithDerived,\n} from \"./module\";\nimport {\n\tasType,\n\ttype InferArgs,\n\ttype InferInput,\n\tisVar,\n\ttype OutputSchemaOf,\n\toutputContract,\n\tvalidate,\n\tvTypes,\n} from \"./schema\";\nimport type { ResolvedVars, ScopeOf, VarName, VarScope } from \"./scope\";\nimport type { LiteralString, Prettify } from \"./types\";\nimport {\n\ttype Cells,\n\tcontextScope,\n\ttype Frame,\n\treadVar,\n\treadVarThrough,\n\ttype VarDefination,\n\twriteVar,\n} from \"./var\";\n\nexport type ParentContext = Record<string, any>;\n\n/** The call shape: a TUPLE input spreads - one parameter per position,\n * the parent context last. Everything else takes (input?, parent?). */\ntype CallArgs<A, I> = I extends readonly unknown[]\n\t? A extends readonly unknown[]\n\t\t? [...A] | [...A, ParentContext]\n\t\t: never\n\t: [A] extends [void]\n\t\t? [input?: undefined, parent?: ParentContext]\n\t\t: [input: A, parent?: ParentContext];\n\n/** The union of a fn's DECLARED errors, as thrown values. */\nexport type FnErrorsOf<Er> = {\n\t[T in keyof Er & string]: FnError<T, InferInput<Er[T]>>;\n}[keyof Er & string];\n\n/** The declared-error union of a fn - for typing catch sites. */\nexport type FnErrors<F> =\n\tF extends FnDefination<any, any, any, any, any, infer Er>\n\t\t? FnErrorsOf<Er>\n\t\t: never;\n\ntype TryResult<R, Er> =\n\tR extends Promise<infer V>\n\t\t? Promise<{ ok: true; value: V } | { ok: false; error: FnErrorsOf<Er> }>\n\t\t: { ok: true; value: R } | { ok: false; error: FnErrorsOf<Er> };\n\n/** No declared errors - the default error channel. */\ntype NoErrors = Record<never, never>;\n\n/** The `use` half of `.with`: fn overrides by name, recursing into\n * GROUPS so a nested binding can be overridden too. A var alias takes a\n * SEED for the var it points at. */\ntype WithFns<U> = {\n\t[K in keyof U]?: U[K] extends FnDefination<any, any, any, any, any, any>\n\t\t? BoundFn<U[K]>\n\t\t: U[K] extends VarDefination<any, infer T, any, any>\n\t\t\t? T\n\t\t\t: WithFns<U[K]>;\n};\n\n/** The context `.with` accepts: any var of the fn's WHOLE chain scope\n * (the builder's `use` included, not just the fn's own), plus any `use`\n * fn as an override - and nothing else. Kept as PLAIN mapped types: with\n * `RV`/`U` unknown both halves collapse to `{}`, which keeps every\n * `extends FnDefination<any, ...>` structural check passing.\n *\n * Prefer {@link WithSeed} for values stored on {@link FnDefination} - it\n * is what `v.fn` returns, and stays declaration-emit safe. */\nexport type WithContext<RV, U> = { [K in keyof RV]?: RV[K] } & WithFns<U>;\n\n/** Storage (or the FnEntries slice of one): anything carrying `$models`.\n * Nested under a module as `{ db }`, it must not flow into `.with` seeds -\n * model schemas alone blow past declaration serialize limits. ModuleFns\n * drops `$adapter`/`$on`/collections, so duck-typing `$models` alone. */\ntype StorageLike = { $models: object };\n\n/** Flatten `use` members to `.with` overrides: bound call signatures, var\n * alias values, nested groups. Storage is dropped (mount-only). */\ntype WithFnsSeed<U> = {\n\t[K in keyof U as U[K] extends StorageLike\n\t\t? never\n\t\t: K]?: U[K] extends FnDefination<any, any, any, any, any, any>\n\t\t? BoundFn<U[K]>\n\t\t: U[K] extends VarDefination<any, infer T, any, any>\n\t\t\t? T\n\t\t\t: WithFnsSeed<U[K]>;\n};\n\n/**\n * Flat `.with` seed map stored on exported fns. Evaluating ScopeOf /\n * ModuleFns here (instead of embedding those wrappers as type arguments)\n * keeps declaration emit small: `.d.ts` shows leaf var shapes and bound\n * call signatures, not `ScopeOf<ResolvedVars<entire module graph>>`.\n */\nexport type WithSeed<RV, U> = Prettify<\n\t{ [K in keyof RV]?: RV[K] } & WithFnsSeed<U>\n>;\n\n/** What `v.fn` / `e.fn` returns: contract params plus a flat {@link WithSeed}\n * for `.with`, never the raw ScopeOf / ModuleFns graph. */\ntype PublicFn<\n\tA,\n\tR,\n\tK extends string,\n\tI,\n\tP extends readonly string[],\n\tEr,\n\tRV,\n\tU,\n\tO = unknown,\n> = FnDefination<A, R, K, I, P, Er, WithSeed<RV, U>, O>;\n\n/** What `.with` returns: the same callable, context baked in. */\nexport interface BoundCall<A, R, I, Er> {\n\t(...args: CallArgs<A, I>): R;\n\ttry(...args: CallArgs<A, I>): TryResult<R, Er>;\n}\n\nexport interface FnDefination<\n\tA,\n\tR,\n\tK extends string = string,\n\tI = unknown,\n\tP extends readonly string[] = readonly string[],\n\tEr = NoErrors,\n\t/** `.with` seed map ({@link WithSeed}). Defaults keep structural\n\t * `extends FnDefination<any, ...>` checks passing. */\n\tW = unknown,\n\tO = unknown,\n> {\n\t(...args: CallArgs<A, I>): R;\n\t/**\n\t * Call with DECLARED errors caught as a value: `{ ok: true, value }`\n\t * or `{ ok: false, error }`, narrowed by `error.tag`. Only tagged,\n\t * expected errors become results - defects and contract violations\n\t * still throw, exactly as they should.\n\t */\n\ttry(...args: CallArgs<A, I>): TryResult<R, Er>;\n\t/**\n\t * Call with a HAND-BUILT context. Keys naming a var SEED that var in a\n\t * fresh scope; keys naming a `use` fn OVERRIDE that binding for the\n\t * whole subtree below. Both are typed from the fn's chain - what the\n\t * BUILDER mounted counts, so `signOut.with({ user })` type-checks even\n\t * though `signOut` itself never says `use: [user]`. A parent passed to\n\t * the bound call is FORKED: its vars are copied in, never written back.\n\t */\n\twith(context: W): BoundCall<A, R, I, Er>;\n\t/** Brand, so a plugin module can be scanned for its fns. */\n\treadonly $fn: true;\n\t/** The name interceptors target - literal, so `ApplyOn` can match it. */\n\treadonly key: K;\n\t/** The declared contract, retained AS WRITTEN for runtime\n\t * introspection (tool cards, docs renderers): the raw input/output\n\t * schemas, error tag map, and required vars. Optional so structural\n\t * `extends FnDefination` checks keep passing for hand-built fns. */\n\treadonly $schema?: {\n\t\tinput?: unknown;\n\t\toutput?: unknown;\n\t\terrors?: Record<string, unknown>;\n\t\trequires?: readonly string[];\n\t\t/** Declared idempotence - same args, same result, safe to repeat. */\n\t\tidempotent?: boolean;\n\t};\n\t/** Vars this fn promises to set when ITS OWN body runs - the literal\n\t * list, readable by graph tooling at both type and runtime level. */\n\treadonly provides: P;\n\t/** Phantom: the raw declared input, so extensions of the vars it\n\t * references can widen used-fn call sites. Never set at runtime. */\n\treadonly $input?: I;\n\t/** Phantom: the raw declared output, the counterpart of `$input` - the\n\t * schema as written, for type-level introspection. Never set at runtime. */\n\treadonly $output?: O;\n\t/** Phantom: declared error tags -> payload schemas. */\n\treadonly $errors?: Er;\n}\n\nexport type ArgsOf<I> = I extends readonly unknown[]\n\t? { -readonly [K in keyof I]: InferArgs<I[K]> }\n\t: unknown extends I\n\t\t? void\n\t\t: InferArgs<I>;\n\nexport type OptionType<\n\tI,\n\tO,\n\tP,\n\tQ,\n\tPL,\n\tRO extends boolean = boolean,\n\tEr = any,\n> = {\n\t/**\n\t * The fn's DECLARED failures: tag -> payload schema. The THIRD\n\t * contract door - input validates on entry, output on exit, errors at\n\t * `throw c.error(tag, data)`. Once declared, any UNTAGGED throw\n\t * escaping the body is a defect and comes out as `UnexpectedError` -\n\t * callers can tell a domain refusal from a bug without string\n\t * matching.\n\t */\n\terrors?: Er;\n\t/**\n\t * A readonly fn cannot write vars - not in its handler, not in\n\t * anything it calls, not from interceptors mounted on it. Enforced at\n\t * the type level (vars readonly on `c`, declared writers uncallable)\n\t * and at runtime (the whole subtree's store locks).\n\t */\n\treadonly?: RO;\n\t/**\n\t * Declared idempotence: calling with the same args always produces the\n\t * same result and repeating the call is harmless - a read, a lookup, a\n\t * pure computation. Part of the retained contract (`$schema`), so\n\t * hosts may DEDUPE calls: the script engine serves repeated\n\t * same-args calls to an idempotent fn from one dispatch per session.\n\t * Note this is a different promise than `readonly` (writes no vars) -\n\t * an fn can be readonly and still hit a non-idempotent API.\n\t */\n\tidempotent?: boolean;\n\tinput?: I;\n\t/**\n\t * The fn's return contract. A bare schema is BOTH the signature and\n\t * the exit check; the wrapper `{ def?, validation? }` splits them -\n\t * `{ def }` documents the return (tool cards, handler typing) without\n\t * runtime validation, `validation` is the schema the exit check runs\n\t * (defaults to none in the wrapper form).\n\t */\n\toutput?: O;\n\t/** Vars this fn guarantees to set. Checked on exit. */\n\tprovides?: P;\n\t/** Vars that must already be set. Checked on entry, before the body. */\n\trequires?: Q;\n\t/**\n\t * Module namespaces to pull in. Their vars come into scope, their fns\n\t * land directly on `c` already bound to this context (a plain-record\n\t * member nests as a NAMESPACE: `c.cookies.setCookie`), and their `on`\n\t * entries stay active for everything below.\n\t */\n\tuse?: PL;\n};\n\n/** A used fn, with the parent context already applied. A tuple-input fn\n * keeps its positional signature. */\ntype BoundFn<F> =\n\tF extends FnDefination<infer A, infer R, string, infer I, any, any>\n\t\t? I extends readonly unknown[]\n\t\t\t? A extends readonly unknown[]\n\t\t\t\t? (...args: [...A]) => R\n\t\t\t\t: never\n\t\t\t: [A] extends [void]\n\t\t\t\t? () => R\n\t\t\t\t: (input: A) => R\n\t\t: never;\n\n/** Keys of a usable map whose member is a VAR alias. */\ntype UseVarKeys<U> = {\n\t[K in keyof U]: U[K] extends VarDefination<any, any, any, any> ? K : never;\n}[keyof U];\n\n/** A var alias' surface: the var's VALUE, read and written in place. */\ntype UseVarValue<V> =\n\tV extends VarDefination<any, infer T, any, any> ? T : never;\n\nexport type UseApi<U> = Prettify<\n\t{\n\t\t[K in Exclude<keyof U, UseVarKeys<U>>]: U[K] extends FnDefination<\n\t\t\tany,\n\t\t\tany,\n\t\t\tany,\n\t\t\tany,\n\t\t\tany,\n\t\t\tany\n\t\t>\n\t\t\t? BoundFn<U[K]>\n\t\t\t: UseApi<U[K]>;\n\t} & { [K in UseVarKeys<U>]: UseVarValue<U[K]> }\n>;\n\n/** Used fns inside a readonly fn: declared writers become uncallable,\n * with the reason on hover instead of a generic type error; var aliases\n * become readonly properties. */\ntype ReadUseApi<U> = Prettify<\n\t{\n\t\t[K in Exclude<keyof U, UseVarKeys<U>>]: U[K] extends FnDefination<\n\t\t\tany,\n\t\t\tany,\n\t\t\tany,\n\t\t\tany,\n\t\t\tinfer P,\n\t\t\tany\n\t\t>\n\t\t\t? P extends readonly []\n\t\t\t\t? BoundFn<U[K]>\n\t\t\t\t: `writes \"${P[number] & string}\" - not callable from a readonly fn`\n\t\t\t: ReadUseApi<U[K]>;\n\t} & { readonly [K in UseVarKeys<U>]: UseVarValue<U[K]> }\n>;\n\nexport type Context<\n\tI,\n\tRV,\n\tRequired,\n\tU = unknown,\n\tFnApi = Fn,\n\tRO extends boolean = false,\n\tErrs = NoErrors,\n> = {\n\tinput: InferInput<I>;\n\t/**\n\t * Mint a DECLARED error - tag-checked, payload validated at creation:\n\t * `throw c.error(\"invalid_credentials\", { attempts: 3 })`. Only tags\n\t * from this fn's `errors` exist; the payload validates like input.\n\t */\n\terror: <T extends keyof Errs & string>(\n\t\ttag: T,\n\t\t...data: Record<never, never> extends InferArgs<Errs[T]>\n\t\t\t? [data?: InferArgs<Errs[T]>]\n\t\t\t: [data: InferArgs<Errs[T]>]\n\t) => FnError<T, InferInput<Errs[T]>>;\n\t/** Define fns from inside: this fn's scope and key carry over, so\n\t * anything built here is typed exactly like a chained builder. */\n\tfn: FnApi;\n\t/** The schema constructors (string, number, object, ...). */\n\ttypes: typeof vTypes;\n} & /** Every var in scope, directly on `c`: read `c.session`, write by\n * plain assignment (`c.session = {...}`). Every var is a readonly\n * property on a readonly fn. */ VarScope<RV, Required, RO> &\n\t/** Fns from `use`, directly on `c` and already threaded with this\n\t * context: `c.createUser({...})`. */\n\t(RO extends true ? ReadUseApi<U> : UseApi<U>);\n\nexport type InferReturn<O> = unknown extends O\n\t? unknown\n\t: InferInput<OutputSchemaOf<O>>;\n\nexport interface Fn<\n\tBase = unknown,\n\tBaseFns = unknown,\n\tBasePL extends readonly Module[] = [],\n\tPrefix extends string = \"\",\n> {\n\t/**\n\t * The builder FN is a schema too: `create: v.fn` (never called) declares\n\t * \"any function\" - typed `(...args: any[]) => any`, runtime checks only\n\t * `typeof value === \"function\"`.\n\t */\n\treadonly $fnSchema: { input?: unknown; output?: unknown };\n\t/**\n\t * \"A fn with THIS signature\", as a schema: `create: v.fn.type({ input,\n\t * output })` types the field as that fn and validates what a signature\n\t * CAN be validated for - the value is a function, and a plain closure\n\t * gets the declared input checked at its door on every call.\n\t *\n\t * This exists apart from a handler-less `v.fn({ input, output })` for\n\t * INLINE use: `v.fn`'s handler overloads return a callable, which makes\n\t * TypeScript defer any inline `v.fn(...)` call inside another generic\n\t * call's arguments (higher-order inference) - the enclosing `v.object`/\n\t * `v.var` then loses its shape inference entirely. `v.fn.type` returns a\n\t * plain carrier, so it composes inline anywhere.\n\t */\n\treadonly type: <I = unknown, O = unknown>(signature?: {\n\t\tinput?: I;\n\t\toutput?: O;\n\t}) => { readonly $fnSchema: { input?: I; output?: O } };\n\n\t/* ---- a handler TERMINATES: these four produce a callable fn ---- */\n\t<R>(\n\t\tfn: (\n\t\t\tctx: Context<\n\t\t\t\tunknown,\n\t\t\t\tScopeOf<[], Base, BasePL>,\n\t\t\t\tnever,\n\t\t\t\tBaseFns,\n\t\t\t\tFn<Base, BaseFns, BasePL, Prefix>\n\t\t\t>,\n\t\t) => R,\n\t): PublicFn<\n\t\tvoid,\n\t\tR,\n\t\tPrefix extends \"\" ? string : Prefix,\n\t\tunknown,\n\t\treadonly string[],\n\t\tNoErrors,\n\t\tScopeOf<[], Base, BasePL>,\n\t\tBaseFns\n\t>;\n\t<K extends LiteralString, R>(\n\t\tkey: K,\n\t\tfn: (\n\t\t\tctx: Context<\n\t\t\t\tunknown,\n\t\t\t\tScopeOf<[], Base, BasePL>,\n\t\t\t\tnever,\n\t\t\t\tBaseFns,\n\t\t\t\tFn<Base, BaseFns, BasePL, `${Prefix}${K}`>\n\t\t\t>,\n\t\t) => R,\n\t): PublicFn<\n\t\tvoid,\n\t\tR,\n\t\t`${Prefix}${K}`,\n\t\tunknown,\n\t\treadonly string[],\n\t\tNoErrors,\n\t\tScopeOf<[], Base, BasePL>,\n\t\tBaseFns\n\t>;\n\n\t<\n\t\tconst I,\n\t\tO,\n\t\tR extends InferReturn<O> | Promise<InferReturn<O>>,\n\t\tconst PL extends readonly Module[] = [],\n\t\tconst P extends readonly VarName<ScopeOf<PL, Base>>[] = readonly [],\n\t\tconst Q extends readonly VarName<ScopeOf<PL, Base>>[] = readonly [],\n\t\tRO extends boolean = false,\n\t\tEr extends Record<string, unknown> = NoErrors,\n\t>(\n\t\toptions: OptionType<I, O, P, Q, PL, RO, Er>,\n\t\tfn: (\n\t\t\tctx: Context<\n\t\t\t\tI,\n\t\t\t\tScopeOf<PL, Base, readonly [...BasePL, ...PL]>,\n\t\t\t\tWithDerived<PL, BasePL, Q[number]>,\n\t\t\t\tApplyOns<ModuleFns<PL>, PL> & BaseFns,\n\t\t\t\tFn<\n\t\t\t\t\tBase & ResolvedVars<PL>,\n\t\t\t\t\tApplyOns<ModuleFns<PL>, PL> & BaseFns,\n\t\t\t\t\treadonly [...BasePL, ...PL],\n\t\t\t\t\tPrefix\n\t\t\t\t>,\n\t\t\t\tRO,\n\t\t\t\tEr\n\t\t\t>,\n\t\t) => R,\n\t): PublicFn<\n\t\tArgsOf<I>,\n\t\tR,\n\t\tPrefix extends \"\" ? string : Prefix,\n\t\tI,\n\t\tP,\n\t\tEr,\n\t\tScopeOf<PL, Base, readonly [...BasePL, ...PL]>,\n\t\tApplyOns<ModuleFns<PL>, PL> & BaseFns,\n\t\tO\n\t>;\n\t<\n\t\tK extends LiteralString,\n\t\tconst I,\n\t\tO,\n\t\tR extends InferReturn<O> | Promise<InferReturn<O>>,\n\t\tconst PL extends readonly Module[] = [],\n\t\tconst P extends readonly VarName<ScopeOf<PL, Base>>[] = readonly [],\n\t\tconst Q extends readonly VarName<ScopeOf<PL, Base>>[] = readonly [],\n\t\tRO extends boolean = false,\n\t\tEr extends Record<string, unknown> = NoErrors,\n\t>(\n\t\tkey: K,\n\t\toptions: OptionType<I, O, P, Q, PL, RO, Er>,\n\t\tfn: (\n\t\t\tctx: Context<\n\t\t\t\tI,\n\t\t\t\tScopeOf<PL, Base, readonly [...BasePL, ...PL]>,\n\t\t\t\tWithDerived<PL, BasePL, Q[number]>,\n\t\t\t\tApplyOns<ModuleFns<PL>, PL> & BaseFns,\n\t\t\t\tFn<\n\t\t\t\t\tBase & ResolvedVars<PL>,\n\t\t\t\t\tApplyOns<ModuleFns<PL>, PL> & BaseFns,\n\t\t\t\t\treadonly [...BasePL, ...PL],\n\t\t\t\t\t`${Prefix}${K}`\n\t\t\t\t>,\n\t\t\t\tRO,\n\t\t\t\tEr\n\t\t\t>,\n\t\t) => R,\n\t): PublicFn<\n\t\tArgsOf<I>,\n\t\tR,\n\t\t`${Prefix}${K}`,\n\t\tI,\n\t\tP,\n\t\tEr,\n\t\tScopeOf<PL, Base, readonly [...BasePL, ...PL]>,\n\t\tApplyOns<ModuleFns<PL>, PL> & BaseFns,\n\t\tO\n\t>;\n\n\t/* ---- NO handler: a builder. Keys concatenate, `use` accumulates,\n\t and its `.fn` follows the same rule recursively. ---- */\n\t<K extends LiteralString>(\n\t\tkey: K,\n\t): Instance<Base, BaseFns, BasePL, `${Prefix}${K}`>;\n\t<\n\t\tI,\n\t\tO,\n\t\tconst PL extends readonly Module[] = [],\n\t\tconst P extends readonly VarName<ScopeOf<PL, Base>>[] = readonly [],\n\t\tconst Q extends readonly VarName<ScopeOf<PL, Base>>[] = readonly [],\n\t>(\n\t\toptions: OptionType<I, O, P, Q, PL>,\n\t): Instance<\n\t\tBase & ResolvedVars<PL>,\n\t\tBaseFns & ApplyOns<ModuleFns<PL>, PL>,\n\t\treadonly [...BasePL, ...PL],\n\t\tPrefix,\n\t\tI,\n\t\tO\n\t>;\n\t<\n\t\tK extends LiteralString,\n\t\tI,\n\t\tO,\n\t\tconst PL extends readonly Module[] = [],\n\t\tconst P extends readonly VarName<ScopeOf<PL, Base>>[] = readonly [],\n\t\tconst Q extends readonly VarName<ScopeOf<PL, Base>>[] = readonly [],\n\t>(\n\t\tkey: K,\n\t\toptions: OptionType<I, O, P, Q, PL>,\n\t): Instance<\n\t\tBase & ResolvedVars<PL>,\n\t\tBaseFns & ApplyOns<ModuleFns<PL>, PL>,\n\t\treadonly [...BasePL, ...PL],\n\t\t`${Prefix}${K}`,\n\t\tI,\n\t\tO\n\t>;\n}\n\nconst isThenable = (value: any): value is Promise<unknown> =>\n\ttypeof value?.then === \"function\";\n\nconst STORE = Symbol(\"var-store\");\nconst ACTIVE = Symbol(\"active-plugins\");\nconst EXTS = Symbol(\"active-var-extensions\");\nconst READONLY = Symbol(\"readonly-lock\");\nconst WITH = Symbol(\"with-overrides\");\n\nconst defineFn = (\n\tkey: string,\n\toptions: OptionType<any, any, any, any, any>,\n\tdeclared: (c: any) => any,\n) => {\n\tconst modules = resolveModules((options.use ?? []) as Module[]);\n\n\t// Interceptors and var extensions this fn brings, from its modules -\n\t// nested GROUPS included. The SAME entry mounted twice (two views of\n\t// one storage, a module and its re-export) applies once - identity\n\t// dedup, like inheritance.\n\tconst own: OnEntry<string>[] = [];\n\tconst ownExts: VarExtension<string, any>[] = [];\n\tconst scanMembers = (mod: Record<string, unknown>) => {\n\t\tfor (const value of Object.values(mod)) {\n\t\t\tif (isOn(value) && !own.includes(value)) own.push(value);\n\t\t\telse if (isVarExtension(value)) ownExts.push(value);\n\t\t\telse if (isNamespace(value)) scanMembers(value);\n\t\t}\n\t};\n\tfor (const mod of modules) scanMembers(mod);\n\n\tconst usable = collectUsable(modules);\n\n\t// A tuple input means POSITIONAL args: the callable takes one arg per\n\t// declared position, then the parent context.\n\tconst tupleInput = Array.isArray(options.input)\n\t\t? (options.input as unknown[])\n\t\t: undefined;\n\n\t// Declared errors: tag -> payload schema, the THIRD contract door\n\t// (input on entry, output on exit, errors at throw). Declaring any\n\t// also flips the defect rule on: untagged throws come out wrapped.\n\tconst declaredErrors = options.errors as Record<string, unknown> | undefined;\n\n\t// Only the VALIDATION half of the output contract is checked on exit -\n\t// a `{ def }`-only output is a documented promise, never a check.\n\tconst outputValidation = outputContract(options.output).validation;\n\tconst errorTypes = declaredErrors\n\t\t? Object.fromEntries(\n\t\t\t\tObject.entries(declaredErrors).map(([tag, schema]) => [\n\t\t\t\t\ttag,\n\t\t\t\t\tasType(schema),\n\t\t\t\t]),\n\t\t\t)\n\t\t: undefined;\n\n\t// Input that references vars: a var FIELD sets that var from the field\n\t// value; a whole-var input (`input: user`) sets it from the whole args.\n\t// For a tuple the \"fields\" are the positions (\"0\", \"1\", ...).\n\tconst inputVars: Array<[field: string, name: string]> = [];\n\tconst declaredInput = options.input as Record<string, any> | undefined;\n\tconst wholeVar: string | undefined =\n\t\tdeclaredInput && isVar(declaredInput)\n\t\t\t? (declaredInput as { name: string }).name\n\t\t\t: undefined;\n\tif (declaredInput && !wholeVar) {\n\t\tfor (const [field, def] of Object.entries(declaredInput)) {\n\t\t\tif (isVar(def)) inputVars.push([field, def.name]);\n\t\t}\n\t}\n\n\t// Contradictions caught at DEFINITION, not first call: a readonly fn\n\t// promising to set vars, or binding input into vars, makes no sense.\n\tif (options.readonly) {\n\t\tif (options.provides?.length) {\n\t\t\tthrow new ValidationError(\n\t\t\t\t`${key}.readonly`,\n\t\t\t\t\"a readonly fn cannot declare provides - it promises writes\",\n\t\t\t);\n\t\t}\n\t\tif (wholeVar !== undefined || inputVars.length > 0) {\n\t\t\tthrow new ValidationError(\n\t\t\t\t`${key}.readonly`,\n\t\t\t\t\"a readonly fn cannot bind input to vars - that is a write\",\n\t\t\t);\n\t\t}\n\t}\n\n\tconst callable = (...callArgs: any[]) => {\n\t\tconst input: unknown = tupleInput\n\t\t\t? callArgs.slice(0, tupleInput.length)\n\t\t\t: callArgs[0];\n\t\tconst parent: any = tupleInput ? callArgs[tupleInput.length] : callArgs[1];\n\t\tconst cells: Cells = parent?.[STORE] ?? {};\n\t\t// The lock travels the whole subtree: once any frame above is\n\t\t// readonly, every write below throws - handlers, nested fns,\n\t\t// interceptors, input-var seeding, all of it.\n\t\tconst lockedBy: string | undefined = options.readonly\n\t\t\t? key\n\t\t\t: parent?.[READONLY];\n\n\t\t// The active set travels down the call tree, so a fn that declares\n\t\t// plugins keeps them in force for everything it calls with `c`.\n\t\t// Deduped by identity: an instance mounts its modules on every fn,\n\t\t// so a nested call would otherwise stack the same entry twice.\n\t\tconst inherited: OnEntry<string>[] = parent?.[ACTIVE] ?? [];\n\t\tconst active =\n\t\t\town.length === 0\n\t\t\t\t? inherited\n\t\t\t\t: [...inherited, ...own.filter((e) => !inherited.includes(e))];\n\t\tconst chain = active.filter((entry) => matchesTarget(entry.target, key));\n\n\t\t// Fn overrides from `.with`, travelling down like the active set: a\n\t\t// mocked `use` fn stays mocked for the whole subtree.\n\t\tconst withFns: Record<string, unknown> | undefined = parent?.[WITH];\n\n\t\tconst inheritedExts: VarExtension<string, any>[] = parent?.[EXTS] ?? [];\n\t\tconst exts =\n\t\t\townExts.length === 0\n\t\t\t\t? inheritedExts\n\t\t\t\t: [\n\t\t\t\t\t\t...inheritedExts,\n\t\t\t\t\t\t...ownExts.filter((e) => !inheritedExts.includes(e)),\n\t\t\t\t\t];\n\n\t\tlet ctx: any;\n\t\tconst frame: Frame = {\n\t\t\tcells,\n\t\t\tkey,\n\t\t\tlockedBy,\n\t\t\tentries: active,\n\t\t};\n\n\t\t// Widen a var-referencing input with the mounted extensions of that\n\t\t// var: their fields validate off the same raw value and merge in.\n\t\tconst extendValue = (name: string, raw: unknown, value: unknown) => {\n\t\t\tlet merged = value;\n\t\t\tfor (const ext of exts) {\n\t\t\t\tif (ext.name !== name) continue;\n\t\t\t\tconst extra = validate(asType(ext.schema), raw, `${key}.${name}`);\n\t\t\t\tmerged = { ...(merged as Record<string, unknown>), ...extra };\n\t\t\t}\n\t\t\treturn merged;\n\t\t};\n\n\t\t// Tuple positions validate like object fields: every bad position\n\t\t// reports, together, in one error.\n\t\tlet parsed: any;\n\t\tif (tupleInput) {\n\t\t\tconst issues: Issue[] = [];\n\t\t\tparsed = tupleInput.map((def, index) => {\n\t\t\t\ttry {\n\t\t\t\t\treturn validate(\n\t\t\t\t\t\tasType(def),\n\t\t\t\t\t\t(input as unknown[])[index],\n\t\t\t\t\t\t`${key}[${index}]`,\n\t\t\t\t\t);\n\t\t\t\t} catch (thrown) {\n\t\t\t\t\tif (!(thrown instanceof ValidationError)) throw thrown;\n\t\t\t\t\tissues.push(...thrown.issues);\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t});\n\t\t\tconst firstIssue = issues[0];\n\t\t\tif (firstIssue) {\n\t\t\t\tthrow new ValidationError(firstIssue.path, firstIssue.message, issues);\n\t\t\t}\n\t\t} else {\n\t\t\tparsed =\n\t\t\t\toptions.input === undefined\n\t\t\t\t\t? input\n\t\t\t\t\t: validate(asType(options.input), input, key);\n\t\t}\n\n\t\t// Mounted extensions widen the accepted input: each validates its\n\t\t// own fields off the same raw input and merges onto `parsed`.\n\t\t// Extensions extend RECORD inputs - positional args have no field\n\t\t// to merge into, so a tuple fn skips them.\n\t\tfor (const entry of chain) {\n\t\t\tif (!entry.extend?.input || tupleInput) continue;\n\t\t\tconst extra = validate(asType(entry.extend.input), input, `${key}.on`);\n\t\t\tparsed = { ...((parsed as Record<string, unknown>) ?? {}), ...extra };\n\t\t}\n\n\t\t// A whole-var input IS the var: the merged value becomes both the\n\t\t// parsed input and the var for the rest of the call tree.\n\t\tif (wholeVar !== undefined && parsed !== undefined) {\n\t\t\tparsed = extendValue(wholeVar, input, parsed);\n\t\t\twriteVar(frame, wholeVar, parsed);\n\t\t}\n\n\t\t// An absent field leaves the var alone, so its default (or whatever\n\t\t// a parent already set) survives. Only `undefined` counts as absent -\n\t\t// an explicit `null` is a value and does overwrite.\n\t\tfor (const [field, name] of inputVars) {\n\t\t\tconst raw = (input as Record<string, unknown>)?.[field];\n\t\t\tconst value = (parsed as Record<string, unknown>)?.[field];\n\t\t\tif (value === undefined) continue;\n\t\t\tconst merged = extendValue(name, raw, value);\n\t\t\t(parsed as Record<string, unknown>)[field] = merged;\n\t\t\twriteVar(frame, name, merged);\n\t\t}\n\n\t\t// The context's FIXED surface; everything not on it is a var, read\n\t\t// and written straight on `c` through the proxy below.\n\t\tconst base: any = {\n\t\t\tinput: parsed,\n\t\t\t// Mint a declared error: tag must be declared, payload validates\n\t\t\t// at creation - an error is a contract too.\n\t\t\terror: (tag: string, data?: unknown) => {\n\t\t\t\tconst schema = errorTypes?.[tag];\n\t\t\t\tif (!schema) {\n\t\t\t\t\tthrow new ValidationError(\n\t\t\t\t\t\t`${key}.errors.${tag}`,\n\t\t\t\t\t\terrorTypes\n\t\t\t\t\t\t\t? `\"${tag}\" is not a declared error of \"${key}\"`\n\t\t\t\t\t\t\t: `\"${key}\" declares no errors`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn new FnError(\n\t\t\t\t\ttag,\n\t\t\t\t\tvalidate(schema, data ?? {}, `${key}.errors.${tag}`),\n\t\t\t\t\tkey,\n\t\t\t\t);\n\t\t\t},\n\t\t\t[STORE]: cells,\n\t\t\t[ACTIVE]: active,\n\t\t\t[EXTS]: exts,\n\t\t\t[READONLY]: lockedBy,\n\t\t\t[WITH]: withFns,\n\t\t\tfn: builderFn(key === \"anonymous\" ? \"\" : key, {\n\t\t\t\tuse: options.use ?? [],\n\t\t\t}),\n\t\t\ttypes: vTypes,\n\t\t};\n\t\tctx = contextScope(frame, base);\n\t\t// Used fns land DIRECTLY on the context (`c.createUser(...)`), bound\n\t\t// to `ctx` so they share this store and active set without the caller\n\t\t// having to thread `c` by hand. A GROUP binds recursively and lands\n\t\t// as a namespace (`c.cookie.setCookie(...)`); a VAR member becomes a\n\t\t// live ALIAS under its export name (`c.cookie.options` reads and\n\t\t// writes the var, hooks and readonly lock included). A tuple-input\n\t\t// fn gets its args padded to full arity so the context always lands\n\t\t// in the parent slot, however many args the caller actually passed.\n\t\tconst bindUsable = (\n\t\t\ttarget: any,\n\t\t\tmap: Record<string, unknown>,\n\t\t\toverrides: Record<string, unknown> | undefined,\n\t\t) => {\n\t\t\tfor (const [name, used] of Object.entries(map)) {\n\t\t\t\tconst override = overrides?.[name];\n\t\t\t\tif (isVar(used)) {\n\t\t\t\t\tconst varName = (used as { name: string }).name;\n\t\t\t\t\tObject.defineProperty(target, name, {\n\t\t\t\t\t\tget: () => readVarThrough(frame, varName),\n\t\t\t\t\t\tset: (value: unknown) => writeVar(frame, varName, value),\n\t\t\t\t\t\tenumerable: true,\n\t\t\t\t\t\tconfigurable: true,\n\t\t\t\t\t});\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (!isFn(used)) {\n\t\t\t\t\tconst group: any = {};\n\t\t\t\t\tbindUsable(\n\t\t\t\t\t\tgroup,\n\t\t\t\t\t\tused as Record<string, unknown>,\n\t\t\t\t\t\tisFn(override) ? undefined : (override as any),\n\t\t\t\t\t);\n\t\t\t\t\ttarget[name] = group;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// A `.with` override REPLACES the binding - a fn override still\n\t\t\t\t// joins this context, a plain function is called as given.\n\t\t\t\tif (override !== undefined) {\n\t\t\t\t\ttarget[name] = isFn(override)\n\t\t\t\t\t\t? (i?: unknown) => (override as any)(i, ctx)\n\t\t\t\t\t\t: override;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst usedArity = (used as { $arity?: number }).$arity;\n\t\t\t\ttarget[name] =\n\t\t\t\t\tusedArity === undefined\n\t\t\t\t\t\t? (i?: unknown) => (used as any)(i, ctx)\n\t\t\t\t\t\t: (...args: unknown[]) => {\n\t\t\t\t\t\t\t\tconst padded = args.slice(0, usedArity);\n\t\t\t\t\t\t\t\twhile (padded.length < usedArity) padded.push(undefined);\n\t\t\t\t\t\t\t\treturn (used as any)(...padded, ctx);\n\t\t\t\t\t\t\t};\n\t\t\t}\n\t\t};\n\t\tbindUsable(base, usable, withFns);\n\n\t\tconst missing = (name: string) => {\n\t\t\tconst value = readVar(cells, name);\n\t\t\treturn value === undefined || value === null;\n\t\t};\n\t\tconst checkRequires = () => {\n\t\t\tfor (const name of options.requires ?? []) {\n\t\t\t\tif (missing(name)) {\n\t\t\t\t\tthrow new ValidationError(\n\t\t\t\t\t\t`${key}.requires.${name}`,\n\t\t\t\t\t\t`required var \"${name}\" is not set${parent === undefined ? \" - called without a parent context\" : \"\"}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\t// Interceptors replace the BODY. `provides` is only enforced when\n\t\t// the DECLARED body actually ran: an interceptor that returns\n\t\t// without `next()` visibly takes the contract over - that is a\n\t\t// veto, not a bug - while an author whose own body forgets to set\n\t\t// a promised var still fails loudly.\n\t\tlet bodyRan = false;\n\t\tconst declaredTracked = (c: any) => {\n\t\t\tbodyRan = true;\n\t\t\treturn declared(c);\n\t\t};\n\t\tconst body = chain.reduceRight<(c: any) => any>(\n\t\t\t(next, entry) => (c) => entry.handler(c, () => next(c)),\n\t\t\tdeclaredTracked,\n\t\t);\n\n\t\t// Exit contracts run after the body, whether or not it was async.\n\t\tconst finish = (result: unknown) => {\n\t\t\tif (outputValidation !== undefined) {\n\t\t\t\tvalidate(asType(outputValidation), result, `${key}.output`);\n\t\t\t}\n\t\t\tif (bodyRan) {\n\t\t\t\tfor (const name of options.provides ?? []) {\n\t\t\t\t\tif (missing(name)) {\n\t\t\t\t\t\tthrow new ValidationError(\n\t\t\t\t\t\t\t`${key}.provides.${name}`,\n\t\t\t\t\t\t\t`declared to provide \"${name}\" but it was left unset`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t};\n\n\t\t// Errors crossing this frame: tagged errors and defects collect the\n\t\t// TRAIL (origin fn first, then every frame outward). Once a fn\n\t\t// declares `errors`, anything untagged escaping its body is a\n\t\t// DEFECT - wrapped with the cause kept - so a domain refusal and a\n\t\t// bug are never the same shape.\n\t\tconst decorate = (thrown: unknown): unknown => {\n\t\t\tif (thrown instanceof FnError || thrown instanceof UnexpectedError) {\n\t\t\t\tif (thrown.trail[thrown.trail.length - 1] !== key) {\n\t\t\t\t\tthrown.trail.push(key);\n\t\t\t\t}\n\t\t\t\treturn thrown;\n\t\t\t}\n\t\t\treturn errorTypes ? new UnexpectedError(thrown, key) : thrown;\n\t\t};\n\n\t\tconst run = () => {\n\t\t\tcheckRequires();\n\t\t\tlet result: unknown;\n\t\t\ttry {\n\t\t\t\tresult = body(ctx);\n\t\t\t} catch (thrown) {\n\t\t\t\tthrow decorate(thrown);\n\t\t\t}\n\t\t\t// A sync handler stays sync: only chain when something is thenable.\n\t\t\treturn isThenable(result)\n\t\t\t\t? result.then(finish, (thrown) => {\n\t\t\t\t\t\tthrow decorate(thrown);\n\t\t\t\t\t})\n\t\t\t\t: finish(result);\n\t\t};\n\n\t\treturn run();\n\t};\n\n\t/** `.try`: declared errors as a value, everything else still throws. */\n\tconst tryCall = (...callArgs: any[]) => {\n\t\tconst settle = (thrown: unknown) => {\n\t\t\tif (thrown instanceof FnError) {\n\t\t\t\treturn { ok: false as const, error: thrown };\n\t\t\t}\n\t\t\tthrow thrown;\n\t\t};\n\t\ttry {\n\t\t\tconst result = callable(...callArgs);\n\t\t\treturn isThenable(result)\n\t\t\t\t? result.then((value) => ({ ok: true as const, value }), settle)\n\t\t\t\t: { ok: true as const, value: result };\n\t\t} catch (thrown) {\n\t\t\treturn settle(thrown);\n\t\t}\n\t};\n\n\t/**\n\t * `.with`: a hand-built context. Keys naming one of this fn's `use`\n\t * fns become OVERRIDES (carried by the subtree via `WITH`); everything\n\t * else SEEDS a var in a fresh store. A parent given to the bound call\n\t * is forked - its cells are copied, so seeds and writes inside never\n\t * leak back into it.\n\t */\n\tconst withCall = (context: Record<string, unknown>) => {\n\t\tconst makeParent = (given: any) => {\n\t\t\tconst source: Cells = given?.[STORE] ?? {};\n\t\t\tconst cells: Cells = Object.fromEntries(\n\t\t\t\tObject.entries(source).map(([name, cell]) => [name, { ...cell }]),\n\t\t\t);\n\t\t\tconst seedFrame: Frame = {\n\t\t\t\tcells,\n\t\t\t\tkey: `${key}.with`,\n\t\t\t\tlockedBy: undefined,\n\t\t\t\tentries: [],\n\t\t\t};\n\t\t\tconst overrides: Record<string, unknown> = { ...given?.[WITH] };\n\t\t\t// Walk the given context against the usable tree: a fn member is\n\t\t\t// an OVERRIDE, a var member (top-level or inside a group) SEEDS\n\t\t\t// the var under its DECLARED name, a group recurses, and anything\n\t\t\t// unknown seeds a var by the given key.\n\t\t\tconst applyWith = (\n\t\t\t\tmap: Record<string, unknown> | undefined,\n\t\t\t\tentries: Record<string, unknown>,\n\t\t\t\ttarget: Record<string, unknown>,\n\t\t\t) => {\n\t\t\t\tfor (const [name, value] of Object.entries(entries)) {\n\t\t\t\t\tconst member = map?.[name];\n\t\t\t\t\tif (member === undefined) {\n\t\t\t\t\t\twriteVar(seedFrame, name, value);\n\t\t\t\t\t} else if (isVar(member)) {\n\t\t\t\t\t\twriteVar(seedFrame, (member as { name: string }).name, value);\n\t\t\t\t\t} else if (isFn(member) || typeof value !== \"object\" || !value) {\n\t\t\t\t\t\ttarget[name] = value;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst existing = target[name];\n\t\t\t\t\t\tconst sub =\n\t\t\t\t\t\t\texisting && typeof existing === \"object\"\n\t\t\t\t\t\t\t\t? (existing as Record<string, unknown>)\n\t\t\t\t\t\t\t\t: {};\n\t\t\t\t\t\ttarget[name] = sub;\n\t\t\t\t\t\tapplyWith(\n\t\t\t\t\t\t\tmember as Record<string, unknown>,\n\t\t\t\t\t\t\tvalue as Record<string, unknown>,\n\t\t\t\t\t\t\tsub,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\t\t\tapplyWith(usable, context, overrides);\n\t\t\treturn {\n\t\t\t\t[STORE]: cells,\n\t\t\t\t[ACTIVE]: given?.[ACTIVE],\n\t\t\t\t[EXTS]: given?.[EXTS],\n\t\t\t\t[READONLY]: given?.[READONLY],\n\t\t\t\t[WITH]: Object.keys(overrides).length > 0 ? overrides : undefined,\n\t\t\t};\n\t\t};\n\t\tconst rewrite = (callArgs: any[]) => {\n\t\t\tif (tupleInput) {\n\t\t\t\tconst padded = callArgs.slice(0, tupleInput.length);\n\t\t\t\twhile (padded.length < tupleInput.length) padded.push(undefined);\n\t\t\t\treturn [...padded, makeParent(callArgs[tupleInput.length])];\n\t\t\t}\n\t\t\treturn [callArgs[0], makeParent(callArgs[1])];\n\t\t};\n\t\tconst bound = (...callArgs: any[]) => callable(...rewrite(callArgs));\n\t\tbound.try = (...callArgs: any[]) => tryCall(...rewrite(callArgs));\n\t\treturn bound;\n\t};\n\n\treturn Object.assign(callable, {\n\t\t$fn: true as const,\n\t\tkey,\n\t\tprovides: (options.provides ?? []) as readonly string[],\n\t\ttry: tryCall,\n\t\twith: withCall,\n\t\t// Positional arg count, so used-fn bindings know where ctx goes.\n\t\t...(tupleInput ? { $arity: tupleInput.length } : {}),\n\t\t// The declared contract, as written - introspectable by hosts that\n\t\t// render the fn to an authorizer or an authoring model.\n\t\t$schema: {\n\t\t\t...(options.input !== undefined ? { input: options.input } : {}),\n\t\t\t...(options.output !== undefined ? { output: options.output } : {}),\n\t\t\t...(declaredErrors ? { errors: declaredErrors } : {}),\n\t\t\t...(options.requires?.length\n\t\t\t\t? { requires: options.requires as readonly string[] }\n\t\t\t\t: {}),\n\t\t\t...(options.idempotent === true ? { idempotent: true } : {}),\n\t\t},\n\t});\n};\n\n/* --------------------------------- create --------------------------------- */\n\n/** Every target worth suggesting on a builder's `on`: the mounted fns'\n * keys (prefix-stripped, so they are valid RELATIVE targets), the scope's\n * var-write events by name, and the two wildcards. Arbitrary strings stay\n * legal - these only feed completion. */\ntype OnTargetSuggest<Base, BaseFns, Prefix extends string> =\n\t| FnTargetSuggest<BaseFns, Prefix>\n\t| `var.set.${keyof ScopeOf<[], Base> & string}`\n\t| \"var.set.*\"\n\t| `var.get.${keyof ScopeOf<[], Base> & string}`\n\t| \"var.get.*\"\n\t| \"*\";\n\ntype FnTargetSuggest<Fns, Prefix extends string> = {\n\t[K in keyof Fns]: Fns[K] extends FnDefination<\n\t\tany,\n\t\tany,\n\t\tinfer FK,\n\t\tany,\n\t\tany,\n\t\tany\n\t>\n\t\t? FK extends `${Prefix}${infer Rest}`\n\t\t\t? Rest\n\t\t\t: never\n\t\t: never;\n}[keyof Fns];\n\ntype VarNameOfT<T extends string> = T extends `var.${\"set\" | \"get\"}.${infer N}`\n\t? N extends `${string}*${string}`\n\t\t? string\n\t\t: N\n\t: string;\n\n/** The scope's value for a var-event target - `unknown` when inexact. */\ntype VarValueOfT<T extends string, Base> =\n\tVarNameOfT<T> extends keyof ScopeOf<[], Base>\n\t\t? ScopeOf<[], Base>[VarNameOfT<T>]\n\t\t: unknown;\n\n/** The fns among `Fns` whose key the (already prefixed) target hits. */\ntype MatchedFn<Fns, T extends string> = {\n\t[K in keyof Fns]: Fns[K] extends FnDefination<\n\t\tany,\n\t\tany,\n\t\tinfer FK,\n\t\tany,\n\t\tany,\n\t\tany\n\t>\n\t\t? TargetMatches<T, FK & string> extends true\n\t\t\t? Fns[K]\n\t\t\t: never\n\t\t: never;\n}[keyof Fns];\n\n/** The intercepted input: the matched fn's (a union under wildcards),\n * or an open record when the target names nothing the builder knows. */\ntype MatchedInput<F> = [F] extends [never]\n\t? Record<string, any>\n\t: F extends FnDefination<any, any, any, infer I, any, any>\n\t\t? InferInput<I>\n\t\t: never;\n\n/** What `next()` resolves to: the matched fn's own result. */\ntype MatchedResult<F> = [F] extends [never]\n\t? any\n\t: F extends FnDefination<any, infer R, any, any, any, any>\n\t\t? Awaited<R>\n\t\t: never;\n\n/** What a builder-scoped `on` handler sees: vars and `use` fns directly\n * on `c` from the builder, `input` from the TARGET fn when known. */\ntype OnContext<Base, BaseFns, F, Ext = unknown> = {\n\tinput: MatchedInput<F> & (unknown extends Ext ? unknown : InferInput<Ext>);\n\ttypes: typeof vTypes;\n\tfn: unknown;\n} & VarScope<ScopeOf<[], Base>, never> &\n\tUseApi<BaseFns>;\n\n/** `v.on`, scoped: string targets get the builder's key prefix; the\n * handler's `c` and `next()` are typed against the matched target fn. */\nexport interface InstanceOn<Base, BaseFns, Prefix extends string> {\n\t/** A fn REFERENCE targets its own key - never prefixed, fully typed\n\t * from the fn itself plus the builder's scope. */\n\t<F extends FnDefination<any, any, string, any, any, any>>(\n\t\ttarget: F,\n\t\thandler: (\n\t\t\tc: OnContext<Base, BaseFns, F>,\n\t\t\tnext: () => Promise<MatchedResult<F>>,\n\t\t) => any,\n\t): OnEntry<F[\"key\"]>;\n\t/** Var-write events: never prefixed (vars are global), and `value`\n\t * is typed from the builder's scope when the target is exact. */\n\t<\n\t\tT extends\n\t\t\t| `var.set.${keyof ScopeOf<[], Base> & string}`\n\t\t\t| \"var.set.*\"\n\t\t\t| `var.set.${string}`,\n\t>(\n\t\ttarget: T,\n\t\thandler: (\n\t\t\tc: VarSetContext<VarNameOfT<T>> & { value: VarValueOfT<T, Base> },\n\t\t\tnext: () => void,\n\t\t) => void,\n\t): OnEntry<T>;\n\t/** Var-read events: `next()` yields the stored value and the handler's\n\t * return becomes the read result - typed from the scope when exact. */\n\t<\n\t\tT extends\n\t\t\t| `var.get.${keyof ScopeOf<[], Base> & string}`\n\t\t\t| \"var.get.*\"\n\t\t\t| `var.get.${string}`,\n\t>(\n\t\ttarget: T,\n\t\thandler: (\n\t\t\tc: VarGetContext<VarNameOfT<T>>,\n\t\t\tnext: () => VarValueOfT<T, Base>,\n\t\t) => VarValueOfT<T, Base>,\n\t): OnEntry<T>;\n\t(\n\t\ttarget: RegExp,\n\t\thandler: (\n\t\t\tc: OnContext<Base, BaseFns, never>,\n\t\t\tnext: () => Promise<any>,\n\t\t) => any,\n\t): OnEntry<string>;\n\t<N extends OnTargetSuggest<Base, BaseFns, Prefix> | LiteralString>(\n\t\ttarget: N,\n\t\thandler: (\n\t\t\tc: OnContext<Base, BaseFns, MatchedFn<BaseFns, `${Prefix}${N}`>>,\n\t\t\tnext: () => Promise<MatchedResult<MatchedFn<BaseFns, `${Prefix}${N}`>>>,\n\t\t) => any,\n\t): OnEntry<`${Prefix}${N}`>;\n\t<const Ext>(\n\t\ttarget: RegExp,\n\t\textend: { input: Ext },\n\t\thandler: (\n\t\t\tc: OnContext<Base, BaseFns, never, Ext>,\n\t\t\tnext: () => Promise<any>,\n\t\t) => any,\n\t): OnEntry<string, Ext>;\n\t<N extends OnTargetSuggest<Base, BaseFns, Prefix> | LiteralString, const Ext>(\n\t\ttarget: N,\n\t\textend: { input: Ext },\n\t\thandler: (\n\t\t\tc: OnContext<Base, BaseFns, MatchedFn<BaseFns, `${Prefix}${N}`>, Ext>,\n\t\t\tnext: () => Promise<MatchedResult<MatchedFn<BaseFns, `${Prefix}${N}`>>>,\n\t\t) => any,\n\t): OnEntry<`${Prefix}${N}`, Ext>;\n}\n\nexport type Instance<\n\tBase,\n\tBaseFns,\n\tPL extends readonly Module[] = [],\n\tPrefix extends string = \"\",\n\tI = unknown,\n\tO = unknown,\n> = {\n\t/** Same as `v.fn`, with this builder's key prefix and options baked in. */\n\tfn: Fn<Base, BaseFns, PL, Prefix>;\n\t/**\n\t * A handler-less builder doubles as an input SCHEMA: used as `input`\n\t * (or an input field) it declares \"a FN from `input` to `output`\" -\n\t * the value crossing is the fn itself. Carries the declared schemas\n\t * for inference here and validation at runtime (see `isFnSchema`).\n\t */\n\treadonly $fnSchema: { input?: I; output?: O };\n\t/** Same as `v.on`, with the prefix on string targets and the handler\n\t * typed against the matched target fn. */\n\ton: InstanceOn<Base, BaseFns, Prefix>;\n\t/**\n\t * The context a handler on this builder receives - a TYPE carrier for\n\t * `typeof f.ctx` (helper signatures, plugin contracts). Every handler\n\t * context on this builder is assignable to it: `input` and `fn` are\n\t * loosened since they vary per fn. A real context only exists per\n\t * invocation, so this is `undefined` at runtime.\n\t */\n\treadonly ctx: Context<\n\t\tunknown,\n\t\tScopeOf<[], Base, PL>,\n\t\tnever,\n\t\tBaseFns,\n\t\tunknown\n\t>;\n};\n\n/**\n * The builder half of `v.fn`: no handler yet, so calls accumulate. Keys\n * CONCATENATE (\"auth\" then \".create\" -> \"auth.create\"), `use`/`requires`/\n * `provides` merge, other options child-wins - and the returned `.fn`\n * follows the same one rule recursively: a handler terminates, anything\n * else keeps building.\n */\nconst mergeOptions = (\n\tbase: Record<string, any>,\n\tchild: Record<string, any>,\n) => ({\n\t...base,\n\t...child,\n\tuse: [...(base.use ?? []), ...(child.use ?? [])],\n\trequires: [...(base.requires ?? []), ...(child.requires ?? [])],\n\tprovides: [...(base.provides ?? []), ...(child.provides ?? [])],\n\t// Error declarations accumulate tag-wise, child wins per tag. Only\n\t// materialized when declared somewhere - an empty `errors` would flip\n\t// the defect-wrapping rule on for every fn.\n\t...(base.errors || child.errors\n\t\t? { errors: { ...(base.errors ?? {}), ...(child.errors ?? {}) } }\n\t\t: {}),\n});\n\nconst builderFn = (baseKey: string, base: Record<string, any>) => {\n\tconst build = (...args: any[]) => {\n\t\tconst hasKey = typeof args[0] === \"string\";\n\t\tconst childKey: string = hasKey ? args[0] : \"\";\n\t\tconst rest = hasKey ? args.slice(1) : args;\n\t\tconst first = rest[0];\n\t\tconst handler = typeof first === \"function\" ? first : rest[1];\n\t\tconst childOptions = typeof first === \"function\" ? {} : (first ?? {});\n\t\tconst key = baseKey + childKey;\n\t\tconst options = mergeOptions(base, childOptions);\n\t\tif (typeof handler !== \"function\") {\n\t\t\treturn {\n\t\t\t\tfn: builderFn(key, options),\n\t\t\t\t// A handler-less builder doubles as an input schema: \"a fn\n\t\t\t\t// from `input` to `output`\" (see `isFnSchema`).\n\t\t\t\t$fnSchema: {\n\t\t\t\t\tinput: (options as OptionType<any, any, any, any, any>).input,\n\t\t\t\t\toutput: (options as OptionType<any, any, any, any, any>).output,\n\t\t\t\t},\n\t\t\t\ton: (target: any, a?: any, b?: any) =>\n\t\t\t\t\t(onImpl as any)(\n\t\t\t\t\t\t// var and scope events live in a global namespace - no prefix.\n\t\t\t\t\t\ttypeof target === \"string\" &&\n\t\t\t\t\t\t\t!target.startsWith(\"var.\") &&\n\t\t\t\t\t\t\t!target.startsWith(\"scope.\")\n\t\t\t\t\t\t\t? key + target\n\t\t\t\t\t\t\t: target,\n\t\t\t\t\t\ta,\n\t\t\t\t\t\tb,\n\t\t\t\t\t),\n\t\t\t};\n\t\t}\n\t\treturn defineFn(key || \"anonymous\", options, handler);\n\t};\n\t// The builder FN doubles as a schema itself: bare `v.fn` (never called)\n\t// declares \"any function\", `v.fn.type({ input, output })` a specific\n\t// signature, and a chained builder's `.fn` carries whatever input/output\n\t// it has accumulated - same contract as the handler-less builder object\n\t// (see `isFnSchema`).\n\treturn Object.assign(build, {\n\t\t$fnSchema: { input: base.input, output: base.output },\n\t\ttype: (signature: { input?: unknown; output?: unknown } = {}) => ({\n\t\t\t$fnSchema: { input: signature.input, output: signature.output },\n\t\t}),\n\t});\n};\n\nexport const fnImpl = builderFn(\"\", {});\n"],"mappings":";;;;;AAsiBA,MAAM,cAAc,UACnB,OAAO,OAAO,SAAS;AAExB,MAAM,QAAQ,OAAO,WAAW;AAChC,MAAM,SAAS,OAAO,gBAAgB;AACtC,MAAM,OAAO,OAAO,uBAAuB;AAC3C,MAAM,WAAW,OAAO,eAAe;AACvC,MAAM,OAAO,OAAO,gBAAgB;AAEpC,MAAM,YACL,KACA,SACA,aACI;CACJ,MAAM,UAAUA,eAAAA,eAAgB,QAAQ,OAAO,CAAC,CAAc;CAM9D,MAAM,MAAyB,CAAC;CAChC,MAAM,UAAuC,CAAC;CAC9C,MAAM,eAAe,QAAiC;EACrD,KAAK,MAAM,SAAS,OAAO,OAAO,GAAG,GACpC,IAAIC,eAAAA,KAAK,KAAK,KAAK,CAAC,IAAI,SAAS,KAAK,GAAG,IAAI,KAAK,KAAK;OAClD,IAAIC,eAAAA,eAAe,KAAK,GAAG,QAAQ,KAAK,KAAK;OAC7C,IAAIC,eAAAA,YAAY,KAAK,GAAG,YAAY,KAAK;CAEhD;CACA,KAAK,MAAM,OAAO,SAAS,YAAY,GAAG;CAE1C,MAAM,SAASC,eAAAA,cAAc,OAAO;CAIpC,MAAM,aAAa,MAAM,QAAQ,QAAQ,KAAK,IAC1C,QAAQ,QACT,KAAA;CAKH,MAAM,iBAAiB,QAAQ;CAI/B,MAAM,mBAAmBC,eAAAA,eAAe,QAAQ,MAAM,CAAC,CAAC;CACxD,MAAM,aAAa,iBAChB,OAAO,YACP,OAAO,QAAQ,cAAc,CAAC,CAAC,KAAK,CAAC,KAAK,YAAY,CACrD,KACAC,eAAAA,OAAO,MAAM,CACd,CAAC,CACF,IACC,KAAA;CAKH,MAAM,YAAkD,CAAC;CACzD,MAAM,gBAAgB,QAAQ;CAC9B,MAAM,WACL,iBAAiBC,eAAAA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