@valbuild/tanstack 0.124.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/LICENSE.md +7 -0
  2. package/README.md +380 -0
  3. package/client/dist/valbuild-tanstack-client.cjs.d.ts +2 -0
  4. package/client/dist/valbuild-tanstack-client.cjs.dev.js +288 -0
  5. package/client/dist/valbuild-tanstack-client.cjs.js +7 -0
  6. package/client/dist/valbuild-tanstack-client.cjs.prod.js +288 -0
  7. package/client/dist/valbuild-tanstack-client.esm.js +280 -0
  8. package/client/package.json +4 -0
  9. package/dist/ValOverlayContext-87cb022d.esm.js +284 -0
  10. package/dist/ValOverlayContext-abd6ab9a.cjs.prod.js +292 -0
  11. package/dist/ValOverlayContext-d3bfacb1.cjs.dev.js +292 -0
  12. package/dist/createForOfIteratorHelper-0324e063.cjs.prod.js +157 -0
  13. package/dist/createForOfIteratorHelper-485c2ce1.esm.js +151 -0
  14. package/dist/createForOfIteratorHelper-e75681d7.cjs.dev.js +157 -0
  15. package/dist/declarations/src/ValApp.d.ts +6 -0
  16. package/dist/declarations/src/ValImage.d.ts +24 -0
  17. package/dist/declarations/src/ValModulesClient.d.ts +34 -0
  18. package/dist/declarations/src/ValProvider.d.ts +6 -0
  19. package/dist/declarations/src/ValTypes.d.ts +4 -0
  20. package/dist/declarations/src/client/index.d.ts +1 -0
  21. package/dist/declarations/src/client/initValClient.d.ts +27 -0
  22. package/dist/declarations/src/decodeValPathsOfString.d.ts +2 -0
  23. package/dist/declarations/src/external_exempt_from_val_quickjs.d.ts +41 -0
  24. package/dist/declarations/src/getUnpatchedUnencodedVal.d.ts +3 -0
  25. package/dist/declarations/src/index.d.ts +2 -0
  26. package/dist/declarations/src/initVal.d.ts +74 -0
  27. package/dist/declarations/src/server/index.d.ts +5 -0
  28. package/dist/declarations/src/server/initValContent.d.ts +122 -0
  29. package/dist/declarations/src/server/initValMcp.d.ts +27 -0
  30. package/dist/declarations/src/server/initValServer.d.ts +41 -0
  31. package/dist/declarations/src/server/valDraftMode.d.ts +49 -0
  32. package/dist/declarations/src/version.d.ts +1 -0
  33. package/dist/routeFromVal-6693e037.cjs.prod.js +218 -0
  34. package/dist/routeFromVal-728295a0.esm.js +212 -0
  35. package/dist/routeFromVal-a9147ceb.cjs.dev.js +218 -0
  36. package/dist/valbuild-tanstack.cjs.d.ts +2 -0
  37. package/dist/valbuild-tanstack.cjs.dev.js +2005 -0
  38. package/dist/valbuild-tanstack.cjs.js +7 -0
  39. package/dist/valbuild-tanstack.cjs.prod.js +2005 -0
  40. package/dist/valbuild-tanstack.esm.js +1950 -0
  41. package/dist/version-1a88fd21.cjs.dev.js +229 -0
  42. package/dist/version-5ac70ccf.cjs.prod.js +229 -0
  43. package/dist/version-ac8df696.esm.js +225 -0
  44. package/package.json +84 -0
  45. package/server/dist/valbuild-tanstack-server.cjs.d.ts +2 -0
  46. package/server/dist/valbuild-tanstack-server.cjs.dev.js +1032 -0
  47. package/server/dist/valbuild-tanstack-server.cjs.js +7 -0
  48. package/server/dist/valbuild-tanstack-server.cjs.prod.js +1032 -0
  49. package/server/dist/valbuild-tanstack-server.esm.js +1005 -0
  50. package/server/package.json +4 -0
@@ -0,0 +1,157 @@
1
+ 'use strict';
2
+
3
+ function _toPrimitive(t, r) {
4
+ if ("object" != typeof t || !t) return t;
5
+ var e = t[Symbol.toPrimitive];
6
+ if (void 0 !== e) {
7
+ var i = e.call(t, r || "default");
8
+ if ("object" != typeof i) return i;
9
+ throw new TypeError("@@toPrimitive must return a primitive value.");
10
+ }
11
+ return ("string" === r ? String : Number)(t);
12
+ }
13
+
14
+ function _toPropertyKey(t) {
15
+ var i = _toPrimitive(t, "string");
16
+ return "symbol" == typeof i ? i : i + "";
17
+ }
18
+
19
+ function _defineProperty(e, r, t) {
20
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
21
+ value: t,
22
+ enumerable: !0,
23
+ configurable: !0,
24
+ writable: !0
25
+ }) : e[r] = t, e;
26
+ }
27
+
28
+ function ownKeys(e, r) {
29
+ var t = Object.keys(e);
30
+ if (Object.getOwnPropertySymbols) {
31
+ var o = Object.getOwnPropertySymbols(e);
32
+ r && (o = o.filter(function (r) {
33
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
34
+ })), t.push.apply(t, o);
35
+ }
36
+ return t;
37
+ }
38
+ function _objectSpread2(e) {
39
+ for (var r = 1; r < arguments.length; r++) {
40
+ var t = null != arguments[r] ? arguments[r] : {};
41
+ r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
42
+ _defineProperty(e, r, t[r]);
43
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
44
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
45
+ });
46
+ }
47
+ return e;
48
+ }
49
+
50
+ function _arrayWithHoles(r) {
51
+ if (Array.isArray(r)) return r;
52
+ }
53
+
54
+ function _iterableToArrayLimit(r, l) {
55
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
56
+ if (null != t) {
57
+ var e,
58
+ n,
59
+ i,
60
+ u,
61
+ a = [],
62
+ f = !0,
63
+ o = !1;
64
+ try {
65
+ if (i = (t = t.call(r)).next, 0 === l) {
66
+ if (Object(t) !== t) return;
67
+ f = !1;
68
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
69
+ } catch (r) {
70
+ o = !0, n = r;
71
+ } finally {
72
+ try {
73
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
74
+ } finally {
75
+ if (o) throw n;
76
+ }
77
+ }
78
+ return a;
79
+ }
80
+ }
81
+
82
+ function _arrayLikeToArray(r, a) {
83
+ (null == a || a > r.length) && (a = r.length);
84
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
85
+ return n;
86
+ }
87
+
88
+ function _unsupportedIterableToArray(r, a) {
89
+ if (r) {
90
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
91
+ var t = {}.toString.call(r).slice(8, -1);
92
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
93
+ }
94
+ }
95
+
96
+ function _nonIterableRest() {
97
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
98
+ }
99
+
100
+ function _slicedToArray(r, e) {
101
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
102
+ }
103
+
104
+ function _createForOfIteratorHelper(r, e) {
105
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
106
+ if (!t) {
107
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
108
+ t && (r = t);
109
+ var n = 0,
110
+ F = function () {};
111
+ return {
112
+ s: F,
113
+ n: function () {
114
+ return n >= r.length ? {
115
+ done: !0
116
+ } : {
117
+ done: !1,
118
+ value: r[n++]
119
+ };
120
+ },
121
+ e: function (r) {
122
+ throw r;
123
+ },
124
+ f: F
125
+ };
126
+ }
127
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
128
+ }
129
+ var o,
130
+ a = !0,
131
+ u = !1;
132
+ return {
133
+ s: function () {
134
+ t = t.call(r);
135
+ },
136
+ n: function () {
137
+ var r = t.next();
138
+ return a = r.done, r;
139
+ },
140
+ e: function (r) {
141
+ u = !0, o = r;
142
+ },
143
+ f: function () {
144
+ try {
145
+ a || null == t.return || t.return();
146
+ } finally {
147
+ if (u) throw o;
148
+ }
149
+ }
150
+ };
151
+ }
152
+
153
+ exports._createForOfIteratorHelper = _createForOfIteratorHelper;
154
+ exports._defineProperty = _defineProperty;
155
+ exports._objectSpread2 = _objectSpread2;
156
+ exports._slicedToArray = _slicedToArray;
157
+ exports._toPropertyKey = _toPropertyKey;
@@ -0,0 +1,6 @@
1
+ import { ValConfig } from "@valbuild/core";
2
+ import { type ReactNode } from "react";
3
+ export declare const ValApp: ({ config, children, }: {
4
+ config: ValConfig;
5
+ children?: ReactNode;
6
+ }) => import("react").JSX.Element;
@@ -0,0 +1,24 @@
1
+ import { Image } from "@valbuild/react/stega";
2
+ /**
3
+ * An `<img>` for a Val image, with the edit tags kept where the Studio can see
4
+ * them.
5
+ *
6
+ * The Next package wraps `next/image`. TanStack Start has no image component,
7
+ * so this is a plain `<img>` — which means it also carries what `next/image`
8
+ * would have supplied on its own: the intrinsic `width`/`height` from the
9
+ * source (so the browser can reserve the space) and `hotspot` as
10
+ * `object-position`.
11
+ *
12
+ * What it exists for is the tags. `src.url` is stega-encoded, so it cannot be
13
+ * put in an `src` attribute as-is: the invisible characters would be sent to
14
+ * the server. `raw()` strips them and the paths they carried are re-attached as
15
+ * `data-val-path` / `data-val-attr-*`, which is what makes the image
16
+ * click-to-edit.
17
+ */
18
+ export type ValImageProps = Omit<React.ComponentProps<"img">, "src" | "alt" | "srcSet"> & {
19
+ alt?: string;
20
+ src: Image;
21
+ /** Ignore the image's hotspot instead of applying it as object-position. */
22
+ disableHotspot?: boolean;
23
+ };
24
+ export declare function ValImage(props: ValImageProps): import("react").JSX.Element;
@@ -0,0 +1,34 @@
1
+ import type { ValModules } from "@valbuild/core";
2
+ declare global {
3
+ interface Window {
4
+ __VAL_MODULES__?: ValModules;
5
+ }
6
+ }
7
+ /**
8
+ * Registers the user's `val.modules` registry on `window.__VAL_MODULES__` so
9
+ * the Val editor SPA (both the `/val` app and the on-page overlay) can read it.
10
+ *
11
+ * Must be called from a component that statically imports `val.modules`: the
12
+ * module `def` entries are function closures, so the registry cannot be
13
+ * serialized through a loader and has to be pulled into the client bundle and
14
+ * registered via the window global instead.
15
+ *
16
+ * Re-runs when the `modules` reference changes (e.g. on HMR) and dispatches
17
+ * `val-modules-updated` so the SPA picks up the new registry.
18
+ */
19
+ export declare function useRegisterValModules(modules: ValModules): void;
20
+ /**
21
+ * Registers the user's `val.modules` registry for the Val editor SPA.
22
+ *
23
+ * Render this inside both `<ValProvider>` (the root route) and `<ValApp>` (the
24
+ * `/val` route), passing your `val.modules` default export:
25
+ *
26
+ * @example
27
+ * import { ValModulesClient } from "@valbuild/tanstack";
28
+ * import valModules from "../val.modules";
29
+ *
30
+ * <ValModulesClient modules={valModules} />
31
+ */
32
+ export declare function ValModulesClient({ modules }: {
33
+ modules: ValModules;
34
+ }): null;
@@ -0,0 +1,6 @@
1
+ export declare const ValProvider: (props: {
2
+ children: React.ReactNode | React.ReactNode[];
3
+ config: import("@valbuild/core").ValConfig;
4
+ disableRefresh?: boolean;
5
+ suspend?: boolean;
6
+ }) => import("react").JSX.Element;
@@ -0,0 +1,4 @@
1
+ import type { UseValType } from "./client/initValClient.js";
2
+ import { Schema, SelectorSource } from "@valbuild/core";
3
+ import { SelectorOfSchema } from "@valbuild/core";
4
+ export type inferSchema<S extends Schema<SelectorSource>> = UseValType<SelectorOfSchema<S>>;
@@ -0,0 +1 @@
1
+ export { initValClient } from "./initValClient.js";
@@ -0,0 +1,27 @@
1
+ import { GenericSelector, JsonSource, SelectorOf, SelectorSource, SourceObject, ValModule } from "@valbuild/core";
2
+ import { StegaOfSource } from "@valbuild/react/stega";
3
+ import { ValConfig } from "@valbuild/core";
4
+ export type UseValType<T extends SelectorSource> = SelectorOf<T> extends GenericSelector<infer S> ? StegaOfSource<S> : never;
5
+ declare function useValStega<T extends SelectorSource>(selector: T): UseValType<T>;
6
+ type JsonEntryContentOf<T extends ValModule<GenericSelector<SourceObject>>> = T extends ValModule<infer S> ? S extends Record<string, infer V> ? V extends JsonSource<infer C> ? C : never : never : never;
7
+ /**
8
+ * Client counterpart to `fetchValKey`: resolves a SINGLE `.jsonValues()` entry
9
+ * by key, loading only that entry's backing `*.val.json` (one dynamic import).
10
+ * Suspends (via `React.use`) until the entry loads, so it must be rendered
11
+ * inside a `<Suspense>` boundary.
12
+ *
13
+ * In draft mode it renders the editor's unpublished content, taken from the
14
+ * overlay; in production — and whenever there is no draft view — it resolves the
15
+ * entry's lazy import thunk from the local module.
16
+ */
17
+ declare function useValKeyStega<T extends ValModule<GenericSelector<SourceObject>>>(selector: T, key: string): JsonEntryContentOf<T> | undefined;
18
+ type UseValRouteReturnType<T extends ValModule<GenericSelector<SourceObject>>> = T extends ValModule<infer S> ? S extends SourceObject ? NonNullable<S>[string] extends JsonSource<infer C> ? C | null : StegaOfSource<NonNullable<S>[string]> | null : never : never;
19
+ declare function useValRouteStega<T extends ValModule<GenericSelector<SourceObject>>>(selector: T, params: Record<string, string | string[]> | Promise<Record<string, string | string[]>>): UseValRouteReturnType<T>;
20
+ declare function useValRouteUrl<T extends ValModule<GenericSelector<SourceObject>>>(selector: T, params?: Record<string, string | string[]> | Promise<Record<string, string | string[]>>): string | null;
21
+ export declare function initValClient(config: ValConfig): {
22
+ useValStega: typeof useValStega;
23
+ useValKeyStega: typeof useValKeyStega;
24
+ useValRouteStega: typeof useValRouteStega;
25
+ useValRouteUrl: typeof useValRouteUrl;
26
+ };
27
+ export {};
@@ -0,0 +1,2 @@
1
+ import { ValEncodedString } from "@valbuild/react/stega";
2
+ export declare function decodeValPathsOfString(encodedString: ValEncodedString): string[] | undefined;
@@ -0,0 +1,41 @@
1
+ export { Schema, type SerializedSchema } from "@valbuild/core";
2
+ export type { SourceObject, SourcePrimitive, Source } from "@valbuild/core";
3
+ export type { ValModule, SerializedModule } from "@valbuild/core";
4
+ export type { FileSource, ImageSource, MediaSource } from "@valbuild/core";
5
+ export type { RichTextSource } from "@valbuild/core";
6
+ export { type Val, type SerializedVal, type ModuleFilePath, type ModulePath, type SourcePath, type JsonOfSource, } from "@valbuild/core";
7
+ export { modules, type ValModules } from "@valbuild/core";
8
+ export type { Json, JsonPrimitive } from "@valbuild/core";
9
+ export type { ValidationErrors, ValidationError } from "@valbuild/core";
10
+ export type { ValidationFix } from "@valbuild/core";
11
+ export * as expr from "@valbuild/core";
12
+ export { VAL_EXTENSION, type SourceArray } from "@valbuild/core";
13
+ export { derefPatch } from "@valbuild/core";
14
+ export { type SelectorSource, type SelectorOf, GenericSelector, } from "@valbuild/core";
15
+ export { ValRichText } from "@valbuild/react/internal";
16
+ export { type ValEncodedString, type File, type Image, type RichText, } from "@valbuild/react/stega";
17
+ export { ValProvider } from "./ValProvider.js";
18
+ export { ValImage, type ValImageProps } from "./ValImage.js";
19
+ export { ValApp } from "./ValApp.js";
20
+ export { ValModulesClient, useRegisterValModules } from "./ValModulesClient.js";
21
+ import { Internal as InternalCore } from "@valbuild/core";
22
+ import { VERSION } from "./version.js";
23
+ export type * as t from "./ValTypes.js";
24
+ export type { DecodeVal } from "@valbuild/react/stega";
25
+ /**
26
+ * Annotated rather than inferred.
27
+ *
28
+ * The inferred type of the spread below reaches into @valbuild/core's internal
29
+ * declaration files for names like `NonEmptyArray` and `createValPathOfItem`,
30
+ * which the declaration emitter cannot write down portably: `preconstruct
31
+ * build` fails with a wall of TS2883 "the inferred type of 'Internal' cannot be
32
+ * named without a reference to ..." while `tsc --noEmit` stays happy, so it only
33
+ * shows up in the build job. Naming the type in terms of `typeof InternalCore`
34
+ * keeps everything the emitter needs reachable through the package entry point.
35
+ */
36
+ type InternalWithTanStackVersion = Omit<typeof InternalCore, "VERSION"> & {
37
+ VERSION: typeof InternalCore.VERSION & {
38
+ tanstack: typeof VERSION;
39
+ };
40
+ };
41
+ export declare const Internal: InternalWithTanStackVersion;
@@ -0,0 +1,3 @@
1
+ import type { GenericSelector, SelectorOf, SelectorSource } from "@valbuild/core";
2
+ import { type StegaOfSource } from "@valbuild/react/stega";
3
+ export declare function getUnpatchedUnencodedVal<T extends SelectorSource>(selector: T): SelectorOf<T> extends GenericSelector<infer S> ? StegaOfSource<S> : never;
@@ -0,0 +1,2 @@
1
+ export { initVal } from "./initVal.js";
2
+ export * from "./external_exempt_from_val_quickjs.js";
@@ -0,0 +1,74 @@
1
+ import { type ValConfig, type InitVal, type ValConstructor, ValRouter } from "@valbuild/core";
2
+ import { raw } from "@valbuild/react/stega";
3
+ import { getUnpatchedUnencodedVal } from "./getUnpatchedUnencodedVal.js";
4
+ import { decodeValPathsOfString } from "./decodeValPathsOfString.js";
5
+ import { attrs } from "@valbuild/react/stega";
6
+ /**
7
+ * Returns true if the Val Enable cookie is set. Must be called on the server —
8
+ * inside a server function, a server route handler, or during SSR — and
9
+ * returns false anywhere else.
10
+ *
11
+ * Not needed for the `suspend` prop on ValProvider, which detects the cookie
12
+ * client-side; reserve it for advanced server-side conditionals.
13
+ */
14
+ declare function isValEnabled(): Promise<boolean>;
15
+ export declare const initVal: (config?: ValConfig) => InitVal & {
16
+ /**
17
+ * Returns true if the Val Enable cookie is set. Must be called on the
18
+ * server — inside a server function, a server route handler, or during SSR —
19
+ * and returns false anywhere else.
20
+ *
21
+ * Not needed for the `suspend` prop on ValProvider, which detects the cookie
22
+ * client-side; reserve it for advanced server-side conditionals.
23
+ */
24
+ isValEnabled: typeof isValEnabled;
25
+ val: ValConstructor & {
26
+ /**
27
+ * Returns the original module data, without any applied patches or stega encoding.
28
+ *
29
+ * This represents the raw, canonical state of the module as it was initially defined.
30
+ * NOTE: images and files, will be transformed (and will therefore) include the url property.
31
+ *
32
+ * ⚠️ Prefer using `fetchVal` (on the server) or `useVal` (in components)
33
+ * for most application logic.
34
+ *
35
+ * This method is primarily intended for tooling and other advanced use cases
36
+ * outside of the actual application.
37
+ */
38
+ unstable_getUnpatchedUnencodedVal: typeof getUnpatchedUnencodedVal;
39
+ /**
40
+ * Convert any object that is encoded with Val stega encoding back to the original values
41
+ */
42
+ raw: typeof raw;
43
+ /**
44
+ * Get the Val paths of attributes for any object.
45
+ *
46
+ * This is typically used to manually set the data-val-path attribute for visual editing on any element.
47
+ *
48
+ * @example
49
+ * const page = useVal(pageVal)
50
+ * <a href={page.url.href} {...val.attrs(page)}>
51
+ * {page.url.label}
52
+ * </a>
53
+ */
54
+ attrs: typeof attrs;
55
+ unstable_decodeValPathsOfString: typeof decodeValPathsOfString;
56
+ };
57
+ /**
58
+ * The TanStack Router for use on s.record().router(...)
59
+ *
60
+ * The Val module of a route is named after the route file it sits beside:
61
+ * `src/routes/posts.$postId.tsx` is served content by
62
+ * `src/routes/posts.$postId.val.ts`. Directory notation
63
+ * (`src/routes/posts/$postId.val.ts`) is the same route.
64
+ *
65
+ * @example
66
+ * const pages = s.record(s.object({ title: s.string() })).router(tanstackRouter);
67
+ * export default c.define("/src/routes/posts.$postId.val.ts", pages, {
68
+ * "/posts/hello-world": { title: "Hello world" },
69
+ * });
70
+ */
71
+ tanstackRouter: ValRouter;
72
+ externalPageRouter: ValRouter;
73
+ };
74
+ export {};
@@ -0,0 +1,5 @@
1
+ export { initValServer } from "./initValServer.js";
2
+ export { initValContent } from "./initValContent.js";
3
+ export { valDraftMode, hasValEnableCookieOnServer, VAL_DRAFT_MODE_COOKIE, type ValDraftMode, } from "./valDraftMode.js";
4
+ export { initValMcp } from "./initValMcp.js";
5
+ export type { ValMcp, ValMcpAuthorizationResult, ValMcpMetadataHandlers, ValOAuthConfig, ValToolImpl, } from "@valbuild/mcp";
@@ -0,0 +1,122 @@
1
+ import { type StegaOfSource } from "@valbuild/react/stega";
2
+ import { SelectorSource, SelectorOf, GenericSelector, ValConfig, ValModules, ValModule, SourceObject, JsonSource } from "@valbuild/core";
3
+ import { ValServer } from "@valbuild/server";
4
+ import { type ValDraftMode } from "./valDraftMode.js";
5
+ declare const initFetchValStega: (config: ValConfig, valApiEndpoints: string, valServerPromise: Promise<ValServer>, isEnabled: () => Promise<boolean>, getHeaders: () => Promise<{
6
+ get(name: string): string | null;
7
+ }>, getCookies: () => Promise<{
8
+ get(name: string): {
9
+ name: string;
10
+ value: string;
11
+ } | undefined;
12
+ }>) => <T extends SelectorSource>(selector: T) => Promise<SelectorOf<T> extends GenericSelector<infer S> ? StegaOfSource<S> : never>;
13
+ type FetchValRouteReturnType<T extends ValModule<GenericSelector<SourceObject>>> = T extends ValModule<infer S> ? S extends SourceObject ? NonNullable<S>[string] extends JsonSource<infer C> ? C | null : StegaOfSource<NonNullable<S>[string]> | null : never : never;
14
+ declare const initFetchValRouteStega: (config: ValConfig, valApiEndpoints: string, valServerPromise: Promise<ValServer>, isEnabled: () => Promise<boolean>, getHeaders: () => Promise<{
15
+ get(name: string): string | null;
16
+ }>, getCookies: () => Promise<{
17
+ get(name: string): {
18
+ name: string;
19
+ value: string;
20
+ } | undefined;
21
+ }>) => <T extends ValModule<GenericSelector<SourceObject>>>(selector: T, params: Promise<Record<string, string | string[]>> | Record<string, string | string[]> | unknown) => Promise<FetchValRouteReturnType<T>>;
22
+ /**
23
+ * Loads a single `.jsonValues()` entry's DRAFT content via the in-process
24
+ * `/json` endpoint (which replays pending patches). Returns `undefined` when the
25
+ * entry has no draft content to serve — the caller then falls back to the
26
+ * locally-bundled committed content.
27
+ */
28
+ /**
29
+ * What the draft state says about an entry.
30
+ *
31
+ * The three cases have to stay distinct: `absent` is an ANSWER — the entry is not
32
+ * there in the draft state, e.g. a pending patch removed it — while `unavailable`
33
+ * means we could not ask. Collapsing them into `undefined` is what made a
34
+ * draft-deleted entry keep rendering its committed content: the caller could not
35
+ * tell "it is gone" from "ask the committed source instead".
36
+ */
37
+ /**
38
+ * The slice of `ValServer` the single-entry readers actually use. Narrower than
39
+ * `ValServer` on purpose: it says what the dependency IS, and it lets a test
40
+ * drive these readers with a one-route fake instead of casting a partial object
41
+ * to the whole server type.
42
+ */
43
+ export type JsonEntryValServer = Pick<ValServer, "/json">;
44
+ export type DraftJsonEntry = {
45
+ status: "content";
46
+ content: unknown;
47
+ } | {
48
+ status: "absent";
49
+ } | {
50
+ status: "unavailable";
51
+ };
52
+ /**
53
+ * Picks the content a draft-aware single-entry read should render.
54
+ *
55
+ * The rule the two callers share: the draft state WINS when it has an answer —
56
+ * including the answer "this entry is gone" — and the committed content is used
57
+ * only when there is no draft answer to be had (Val disabled, or we could not
58
+ * ask). Returning `undefined` means "render nothing"; both callers turn that into
59
+ * a null/undefined result.
60
+ */
61
+ export declare function resolveDraftOrCommittedEntry(draft: DraftJsonEntry, loadCommitted: () => Promise<unknown | undefined>): Promise<unknown | undefined>;
62
+ type JsonEntryContentOf<T extends ValModule<GenericSelector<SourceObject>>> = T extends ValModule<infer S> ? S extends Record<string, infer V> ? V extends JsonSource<infer C> ? C : never : never : never;
63
+ /**
64
+ * Resolves ONE `.jsonValues()` entry by key, loading only that entry instead of
65
+ * the whole record — the runtime-scaling counterpart to the eager `fetchVal`.
66
+ *
67
+ * Production (Val disabled): resolves the entry's lazy import thunk from the
68
+ * locally-bundled module. One dynamic import, no server round-trip.
69
+ *
70
+ * Enabled (draft mode): reads the entry through `/json`, which replays pending
71
+ * patches, so uncommitted Studio edits show up. Falls back to the local thunk if
72
+ * the draft read yields nothing.
73
+ */
74
+ export declare const initFetchValKeyStega: (valServerPromise: Promise<JsonEntryValServer>, isEnabled: () => Promise<boolean>, getCookies: () => Promise<{
75
+ get(name: string): {
76
+ name: string;
77
+ value: string;
78
+ } | undefined;
79
+ }>) => <T extends ValModule<GenericSelector<SourceObject>>>(selector: T, key: string) => Promise<JsonEntryContentOf<T> | undefined>;
80
+ declare const initFetchValRouteUrl: (config: ValConfig, valApiEndpoints: string, valServerPromise: Promise<ValServer>, isEnabled: () => Promise<boolean>, getHeaders: () => Promise<{
81
+ get(name: string): string | null;
82
+ }>, getCookies: () => Promise<{
83
+ get(name: string): {
84
+ name: string;
85
+ value: string;
86
+ } | undefined;
87
+ }>) => <T extends ValModule<GenericSelector<SourceObject>>>(selector: T, params?: Promise<Record<string, string | string[]>> | Record<string, string | string[]> | unknown) => Promise<string | null>;
88
+ /**
89
+ * Val's content readers for the server side of a TanStack Start app.
90
+ *
91
+ * Use them where the server runs: a route `loader` during SSR, a
92
+ * `createServerFn`, or a server route handler. In the browser — a client
93
+ * navigation re-running a loader, say — there is no request to read draft
94
+ * state from, so they resolve the published content, which is the same answer
95
+ * the visitor would get.
96
+ *
97
+ * @example
98
+ * // src/val/server.ts
99
+ * import { initValContent } from "@valbuild/tanstack/server";
100
+ * import { config } from "../val.config";
101
+ * import valModules from "../val.modules";
102
+ *
103
+ * export const {
104
+ * fetchValStega: fetchVal,
105
+ * fetchValRouteStega: fetchValRoute,
106
+ * } = initValContent(config, valModules);
107
+ */
108
+ export declare function initValContent(config: ValConfig, valModules: ValModules, opts?: {
109
+ /**
110
+ * How preview mode is stored for a browser.
111
+ *
112
+ * Defaults to Val's own cookie. Pass the SAME object `initValServer` got:
113
+ * the API turns preview on and these readers are what has to notice.
114
+ */
115
+ draftMode?: ValDraftMode;
116
+ }): {
117
+ fetchValStega: ReturnType<typeof initFetchValStega>;
118
+ fetchValKeyStega: ReturnType<typeof initFetchValKeyStega>;
119
+ fetchValRouteStega: ReturnType<typeof initFetchValRouteStega>;
120
+ fetchValRouteUrl: ReturnType<typeof initFetchValRouteUrl>;
121
+ };
122
+ export {};
@@ -0,0 +1,27 @@
1
+ import type { ValConfig, ValModules } from "@valbuild/core";
2
+ import { type ValMcp, type ValToolImpl, type ValOAuthConfig } from "@valbuild/mcp";
3
+ /**
4
+ * Val's tools over MCP, bound to this package.
5
+ *
6
+ * The MCP endpoint itself — the tools, the request guards, the access-token
7
+ * verification — lives in `@valbuild/mcp`, which knows nothing about any
8
+ * framework. All that is left here is the one thing this package can answer and
9
+ * that one cannot: which version of `@valbuild/tanstack` is running, which
10
+ * `initHandlerOptions` insists on before it will build a proxy-mode config.
11
+ *
12
+ * The version goes in the `next` field because that is the field name in the
13
+ * wire contract; see `initValServer`.
14
+ */
15
+ export declare function initValMcp(valModules: ValModules, config: ValConfig, opts?: {
16
+ formatter?: (code: string, filePath: string) => string | Promise<string>;
17
+ /**
18
+ * Where to authorize, and what audience to expect. Required for proxy
19
+ * mode; see `initValMcp` in `@valbuild/mcp` for what omitting it means.
20
+ */
21
+ oauth?: ValOAuthConfig;
22
+ /**
23
+ * Tools to serve alongside the built-in ones — the image tool arrives this
24
+ * way. See `createValImageTools` in `@valbuild/mcp`.
25
+ */
26
+ extraTools?: ValToolImpl[];
27
+ }): ValMcp;
@@ -0,0 +1,41 @@
1
+ import { ValConfig, ValModules } from "@valbuild/core";
2
+ import { type ValDraftMode } from "./valDraftMode.js";
3
+ export declare function initValServer(valModules: ValModules, config: ValConfig & {
4
+ disableCache?: boolean;
5
+ }, opts?: {
6
+ formatter?: (code: string, filePath: string) => Promise<string> | string;
7
+ /**
8
+ * How preview mode is stored for a browser.
9
+ *
10
+ * Defaults to Val's own cookie (`valDraftMode()`), which is what an app
11
+ * wants unless it already has a preview mechanism of its own to hang this
12
+ * off. Whatever is passed here MUST be the same object the content readers
13
+ * get, or the API will enable a preview the loaders cannot see.
14
+ */
15
+ draftMode?: ValDraftMode;
16
+ }): {
17
+ /**
18
+ * The Val API. Mount it on `/api/val/$` for every method:
19
+ *
20
+ * @example
21
+ * // src/routes/api/val.$.ts
22
+ * import { createFileRoute } from "@tanstack/react-router";
23
+ * import { valApiHandler } from "../../val/server";
24
+ *
25
+ * export const Route = createFileRoute("/api/val/$")({
26
+ * server: {
27
+ * handlers: {
28
+ * GET: ({ request }) => valApiHandler(request),
29
+ * POST: ({ request }) => valApiHandler(request),
30
+ * PUT: ({ request }) => valApiHandler(request),
31
+ * PATCH: ({ request }) => valApiHandler(request),
32
+ * DELETE: ({ request }) => valApiHandler(request),
33
+ * HEAD: ({ request }) => valApiHandler(request),
34
+ * },
35
+ * },
36
+ * });
37
+ */
38
+ valApiHandler: (req: Request) => Promise<Response>;
39
+ /** The draft-mode flag this server reads and writes. */
40
+ draftMode: ValDraftMode;
41
+ };
@@ -0,0 +1,49 @@
1
+ /**
2
+ * The cookie that says a request is previewing unpublished content.
3
+ *
4
+ * Next has `draftMode()` for this; TanStack Start has no such notion, so Val
5
+ * brings its own. Deliberately NOT the thing that grants access: every draft
6
+ * read also carries the Val session cookie, which is a signed JWT the server
7
+ * verifies, and a request with this cookie and no session gets published
8
+ * content and a 401 in the log. So this is a mode switch, not a credential —
9
+ * which is why an ordinary cookie is enough.
10
+ */
11
+ export declare const VAL_DRAFT_MODE_COOKIE = "val_draft_mode";
12
+ /**
13
+ * Reading and writing the draft-mode flag for the current request.
14
+ *
15
+ * Handed to `createValServer` as its callbacks, and exported so an app can ask
16
+ * the same question its loaders ask.
17
+ */
18
+ export type ValDraftMode = {
19
+ /** Whether this request is previewing unpublished content. */
20
+ isEnabled(): Promise<boolean>;
21
+ /** Turn preview on for this browser. Called by `/api/val/draft/enable`. */
22
+ enable(): Promise<void>;
23
+ /** Turn preview off again. Called by `/api/val/draft/disable`. */
24
+ disable(): Promise<void>;
25
+ };
26
+ /**
27
+ * The draft-mode flag, read from and written to the current request.
28
+ *
29
+ * TanStack's request helpers resolve the current request out of async local
30
+ * storage, so this only works where there IS one: a server route handler, a
31
+ * server function, or an SSR render. Everywhere else — a client navigation, a
32
+ * build-time render — it answers "off", which is the right answer: there is no
33
+ * session to authorize a draft read either.
34
+ *
35
+ * The import is dynamic for the same reason it is in `isValEnabled`: this
36
+ * module is reachable from the package's server entry, and pulling TanStack's
37
+ * server half in eagerly would put it in front of anything that merely
38
+ * type-imports from here.
39
+ */
40
+ export declare function valDraftMode(): ValDraftMode;
41
+ /**
42
+ * The Val Enable cookie, as seen by the current request.
43
+ *
44
+ * Separate from draft mode: enabling Val is what makes the Studio overlay mount
45
+ * at all, and draft mode is what makes the content it shows be the unpublished
46
+ * one. The Studio turns the first on for the browser and the second on per
47
+ * preview.
48
+ */
49
+ export declare function hasValEnableCookieOnServer(): Promise<boolean>;
@@ -0,0 +1 @@
1
+ export declare const VERSION: string | null;