@valbuild/core 0.130.0 → 0.136.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.
@@ -0,0 +1,69 @@
1
+ import type { ValModule } from "../module.js";
2
+ import { Schema } from "../schema/index.js";
3
+ import type { GenericSelector, SelectorSource } from "../selector/index.js";
4
+ import type { ValView } from "../selector/view.js";
5
+ import type { Source, SourceObject } from "./index.js";
6
+ import { ValViewSource } from "./view.js";
7
+ /**
8
+ * Where a resolved view handle keeps the module it points at.
9
+ *
10
+ * A symbol, so it is invisible to `JSON.stringify`, `Object.keys`, the source
11
+ * SHAs and every walk that treats source as data — the handle still IS
12
+ * `{ view: "/foo.val.ts" }` everywhere that matters.
13
+ */
14
+ declare const ViewTargetModule: unique symbol;
15
+ /**
16
+ * A view's source with the module it names attached.
17
+ *
18
+ * `useVal(page.header)` needs the target's SOURCE and its SCHEMA, and the
19
+ * stored pointer has neither — it is a path. The app has no way to turn a path
20
+ * back into a module either: `val.modules` holds lazy `import()` thunks, and
21
+ * `<ValModulesClient>` is optional. So the module travels with the handle.
22
+ *
23
+ * Attached by the READ path (`stegaEncode`) rather than written into source,
24
+ * and that is the whole reason it works in draft mode: with an edit pending,
25
+ * the source comes from the overlay store as plain JSON that never went near a
26
+ * module. The schema is the module's own either way, so the encoder always has
27
+ * it to hand.
28
+ */
29
+ export type ValViewHandle = ValViewSource & {
30
+ readonly [ViewTargetModule]: unknown;
31
+ };
32
+ /** Attach the module a view names to its pointer. */
33
+ export declare function createViewHandle(source: ValViewSource, valModule: unknown): ValViewHandle;
34
+ /** Is this a view pointer that carries the module it names? */
35
+ export declare function isViewHandle(value: unknown): value is ValViewHandle;
36
+ /** The module a handle carries, or undefined if it carries none. */
37
+ export declare function viewHandleModule(value: unknown): unknown;
38
+ /**
39
+ * What a reader that needs a MODULE accepts, rather than a value.
40
+ *
41
+ * `useValKey`, `useValRoute`, `useValRouteUrl` and their `fetch*` counterparts
42
+ * all read a path, a schema and a source off what they are handed, so — unlike
43
+ * `useVal` — they cannot take an arbitrary selector. They CAN take a view
44
+ * pointing at one, which is the point of a page declaring which module it
45
+ * shows. {@link resolveViewedModule} is the runtime half, and takes exactly
46
+ * this, so the two cannot drift.
47
+ */
48
+ export type ResolvableModule<S extends Source = SourceObject> = ValModule<GenericSelector<S>> | ValView<S>;
49
+ /**
50
+ * What a reader was actually handed: the module itself, or — when it is a view
51
+ * handle — the module that view points at.
52
+ *
53
+ * Every reader that needs a module rather than a value goes through this:
54
+ * `useValKey`, `useValRoute`, `useValRouteUrl` and their `fetch*` counterparts
55
+ * all pull the path, the schema and the source off the thing they are given,
56
+ * and a view handle has none of those. It is `{ view: "/foo.val.ts" }` with the
57
+ * module on a symbol, so reading `Internal.getValPath` off it gives
58
+ * `undefined`, and every one of those readers treats `undefined` as its own
59
+ * "no route matched" answer. Without this the call is not an error — it is a
60
+ * silently empty one.
61
+ *
62
+ * A POINTER with no module on it throws rather than being passed through, for
63
+ * the same reason `stegaEncode` throws on one: symbols do not survive
64
+ * serialization, so a handle that crossed the server/client boundary as a prop
65
+ * arrives looking like content and is not.
66
+ */
67
+ export declare function resolveViewedModule<S extends Source>(selector: ResolvableModule<S>): ValModule<GenericSelector<S>>;
68
+ export declare function viewModulesOf(schema: Schema<SelectorSource> | undefined): Map<string, unknown>;
69
+ export {};