@valbuild/tanstack 0.146.4 → 0.148.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 (39) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/client/dist/valbuild-tanstack-client.cjs.dev.js +6 -6
  3. package/client/dist/valbuild-tanstack-client.cjs.prod.js +6 -6
  4. package/client/dist/valbuild-tanstack-client.esm.js +4 -4
  5. package/demo/dist/valbuild-tanstack-demo.cjs.d.ts +2 -0
  6. package/demo/dist/valbuild-tanstack-demo.cjs.dev.js +105 -0
  7. package/demo/dist/valbuild-tanstack-demo.cjs.js +7 -0
  8. package/demo/dist/valbuild-tanstack-demo.cjs.prod.js +105 -0
  9. package/demo/dist/valbuild-tanstack-demo.esm.js +101 -0
  10. package/demo/package.json +4 -0
  11. package/dist/{ValOverlayContext-3f080cce.cjs.dev.js → ValOverlayContext-510328ec.cjs.dev.js} +17 -17
  12. package/dist/{ValOverlayContext-59a0b19f.esm.js → ValOverlayContext-6278320b.esm.js} +1 -1
  13. package/dist/{ValOverlayContext-3e2c48a6.cjs.prod.js → ValOverlayContext-d3acd157.cjs.prod.js} +17 -17
  14. package/dist/{version-4da65f4f.esm.js → asyncToGenerator-500f022f.esm.js} +1 -149
  15. package/dist/{version-2cbea560.cjs.prod.js → asyncToGenerator-8e5c36c8.cjs.prod.js} +0 -151
  16. package/dist/{version-1f65da50.cjs.dev.js → asyncToGenerator-c3823d62.cjs.dev.js} +0 -151
  17. package/dist/declarations/src/ValApp.d.ts +15 -1
  18. package/dist/declarations/src/ValProvider.d.ts +1 -0
  19. package/dist/declarations/src/demo/index.d.ts +7 -0
  20. package/dist/declarations/src/demo/initValDemoServer.d.ts +27 -0
  21. package/dist/demoServiceWorker-382e1b63.cjs.dev.js +60 -0
  22. package/dist/demoServiceWorker-56fd96cf.esm.js +55 -0
  23. package/dist/demoServiceWorker-994710f7.cjs.prod.js +60 -0
  24. package/dist/{routeFromVal-385ee69c.cjs.dev.js → routeFromVal-0ea4586f.cjs.dev.js} +17 -24
  25. package/dist/{routeFromVal-ffa948ef.cjs.prod.js → routeFromVal-97a52f43.cjs.prod.js} +17 -24
  26. package/dist/{routeFromVal-ae54a17e.esm.js → routeFromVal-9f1f8725.esm.js} +7 -13
  27. package/dist/{createForOfIteratorHelper-93a62170.esm.js → typeof-66e2d869.esm.js} +11 -1
  28. package/dist/{createForOfIteratorHelper-9afd7d2d.cjs.prod.js → typeof-8998e126.cjs.prod.js} +11 -0
  29. package/dist/{createForOfIteratorHelper-4497beef.cjs.dev.js → typeof-dd0246a1.cjs.dev.js} +11 -0
  30. package/dist/valbuild-tanstack.cjs.dev.js +371 -42
  31. package/dist/valbuild-tanstack.cjs.prod.js +371 -42
  32. package/dist/valbuild-tanstack.esm.js +337 -8
  33. package/dist/version-32d982ef.cjs.prod.js +179 -0
  34. package/dist/version-c2d4fa07.esm.js +174 -0
  35. package/dist/version-e7d79f54.cjs.dev.js +179 -0
  36. package/package.json +16 -10
  37. package/server/dist/valbuild-tanstack-server.cjs.dev.js +60 -75
  38. package/server/dist/valbuild-tanstack-server.cjs.prod.js +60 -75
  39. package/server/dist/valbuild-tanstack-server.esm.js +4 -19
package/CHANGELOG.md CHANGED
@@ -1,5 +1,66 @@
1
1
  # @valbuild/tanstack
2
2
 
3
+ ## 0.148.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`df5544c`](https://github.com/valbuild/val/commit/df5544c6e92a4c3a52765630c9de191e854ee723), [`562d032`](https://github.com/valbuild/val/commit/562d03280c3fcf97a80562e8b017dd2125ac4ad1), [`562d032`](https://github.com/valbuild/val/commit/562d03280c3fcf97a80562e8b017dd2125ac4ad1), [`562d032`](https://github.com/valbuild/val/commit/562d03280c3fcf97a80562e8b017dd2125ac4ad1), [`562d032`](https://github.com/valbuild/val/commit/562d03280c3fcf97a80562e8b017dd2125ac4ad1), [`4176757`](https://github.com/valbuild/val/commit/41767579b01849473a94779122fd39c07dd99234), [`562d032`](https://github.com/valbuild/val/commit/562d03280c3fcf97a80562e8b017dd2125ac4ad1), [`562d032`](https://github.com/valbuild/val/commit/562d03280c3fcf97a80562e8b017dd2125ac4ad1), [`562d032`](https://github.com/valbuild/val/commit/562d03280c3fcf97a80562e8b017dd2125ac4ad1), [`562d032`](https://github.com/valbuild/val/commit/562d03280c3fcf97a80562e8b017dd2125ac4ad1)]:
8
+ - @valbuild/server@0.148.0
9
+ - @valbuild/shared@0.148.0
10
+ - @valbuild/ui@0.148.0
11
+ - @valbuild/mcp@0.148.0
12
+ - @valbuild/core@0.148.0
13
+ - @valbuild/language-server@0.148.0
14
+ - @valbuild/react@0.148.0
15
+
16
+ ## 0.147.0
17
+
18
+ ### Minor Changes
19
+
20
+ - [#816](https://github.com/valbuild/val/pull/816) [`2f09cd5`](https://github.com/valbuild/val/commit/2f09cd5e2f4fc37f06917899f24f9ad2ee8d3a8b) Thanks [@freekh](https://github.com/freekh)! - Routers can give each route parameter a schema, and a URL can say which language a page is in.
21
+
22
+ - **`s.router(router, params, item)`** takes a schema per route parameter, by the name the route file gives it (`$slug`, `[slug]`, `{-$locale}`). Each key's parameters are validated against them, and a name the route does not have is a schema error.
23
+
24
+ ```ts
25
+ s.router(tanstackRouter, { locale: urlLocale, slug: s.string() }, item);
26
+ ```
27
+
28
+ - **`s.enum(...).locales({ ... })`** says which of the project's languages each value means, so `/nb/…` can mean `nb-NO`. The tags are checked against `locales.available` in the settings module, like `s.locale()`. On a nullable enum, a second argument names the language of a URL that leaves the segment out, which only a router parameter may use:
29
+
30
+ ```ts
31
+ const urlLocale = s
32
+ .enum("nb")
33
+ .nullable()
34
+ .locales({ nb: "nb-NO" }, { null: "en-US" });
35
+ ```
36
+
37
+ A router with a locale parameter makes each page a locale scope, so the Studio and validation know which language every page is in.
38
+
39
+ - **A route's language segment can no longer be forgotten.** In a project that declares `locales.available`, a page route with a `locale` or `lang` segment (`{-$locale}`, `[lang]`) whose module gives that parameter no schema is reported, saying what to add. Any schema answers it, so a `$lang` that is not a language is silenced with its own, e.g. `{ lang: s.enum("typescript", "python") }`. It is an ordinary validation error: the Studio still opens and `val validate` lists it, but a project that already has such a route will see it after upgrading, and it blocks publishing until the parameter has a schema.
40
+ - **The Studio's new-page form offers a language as a list.** A route parameter whose schema is a locale is picked from the project's languages, each named in its own language, with "no prefix" where the URL may leave the segment out. Other enum parameters get a list of their values, and every parameter's description is shown under it. The URL row previews what the choice puts there.
41
+ - **TanStack optional segments (`{-$param}`)** are now understood: route validation, `useValRoute` and the Studio's new-page form accept keys with and without the segment.
42
+
43
+ - [#876](https://github.com/valbuild/val/pull/876) [`cb04e58`](https://github.com/valbuild/val/commit/cb04e586db1e3ffd20ec1fee744561b1c8f8cffd) Thanks [@freekh](https://github.com/freekh)! - Demo mode: run the Val Studio with no account and no backend (TanStack Start).
44
+
45
+ `<ValApp demo>` starts Val's own server in the visitor's browser tab, and the Studio talks to it there instead of to `/api/val`. Edits show up in the page as they are typed and are held in the tab's memory: nothing is sent anywhere, and a reload starts over. Images and videos can be uploaded too: a small service worker, served by `initValDemoServer()`, hands the upload and the unpublished files to the server in the tab, so an uploaded photo or video shows in the page with nothing leaving the browser. Uploads are capped by their size after encoding. Pair `<ValApp demo>` with `<ValProvider demo>` on the site and `initValDemoServer()` from the new `@valbuild/tanstack/demo` entry on the API route. In a demo the Studio opens with a guided tour, Publish explains what it would do instead of publishing, and Preview in a new tab is shown but disabled.
46
+
47
+ Also:
48
+
49
+ - `@valbuild/server/browser` is a new entry: Val's request handling, bundleable for a browser. The TypeScript compiler, which only publishing and history need, is loaded when they ask for it, so a browser bundle of the server is about 140 KB rather than 3.6 MB.
50
+ - `s.image({ encode })` now scales an image down in browsers that cannot write WebP (Safari), as a JPEG or PNG in the image's own format, instead of uploading it at full size.
51
+ - `GET /profiles` answers with no profiles, rather than an error, when edits are stored locally and no project is configured.
52
+
53
+ ### Patch Changes
54
+
55
+ - Updated dependencies [[`2f09cd5`](https://github.com/valbuild/val/commit/2f09cd5e2f4fc37f06917899f24f9ad2ee8d3a8b), [`cb04e58`](https://github.com/valbuild/val/commit/cb04e586db1e3ffd20ec1fee744561b1c8f8cffd), [`cb04e58`](https://github.com/valbuild/val/commit/cb04e586db1e3ffd20ec1fee744561b1c8f8cffd)]:
56
+ - @valbuild/core@0.147.0
57
+ - @valbuild/shared@0.147.0
58
+ - @valbuild/ui@0.147.0
59
+ - @valbuild/server@0.147.0
60
+ - @valbuild/language-server@0.147.0
61
+ - @valbuild/mcp@0.147.0
62
+ - @valbuild/react@0.147.0
63
+
3
64
  ## 0.146.4
4
65
 
5
66
  ### Patch Changes
@@ -2,15 +2,15 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var routeFromVal = require('../../dist/routeFromVal-385ee69c.cjs.dev.js');
5
+ var _typeof = require('../../dist/typeof-dd0246a1.cjs.dev.js');
6
6
  var core = require('@valbuild/core');
7
7
  var stega = require('@valbuild/react/stega');
8
8
  var React = require('react');
9
- var ValOverlayContext = require('../../dist/ValOverlayContext-3f080cce.cjs.dev.js');
10
- require('../../dist/createForOfIteratorHelper-4497beef.cjs.dev.js');
11
- require('@valbuild/shared/client');
9
+ var ValOverlayContext = require('../../dist/ValOverlayContext-510328ec.cjs.dev.js');
10
+ var routeFromVal = require('../../dist/routeFromVal-0ea4586f.cjs.dev.js');
12
11
  require('@valbuild/core/patch');
13
12
  require('react/jsx-runtime');
13
+ require('@valbuild/shared/client');
14
14
 
15
15
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
16
16
 
@@ -205,7 +205,7 @@ function draftJsonEntry(draftSource, key) {
205
205
  status: "absent"
206
206
  };
207
207
  }
208
- if (draftSource === undefined || routeFromVal._typeof(draftSource) !== "object" || Array.isArray(draftSource)) {
208
+ if (draftSource === undefined || _typeof._typeof(draftSource) !== "object" || Array.isArray(draftSource)) {
209
209
  return {
210
210
  status: "unavailable"
211
211
  };
@@ -292,7 +292,7 @@ function useValKeyStega(selector, key) {
292
292
  */
293
293
  function readCommittedJsonEntry(selector, key) {
294
294
  var source = selector && core.Internal.getSource(selector);
295
- var marker = source && routeFromVal._typeof(source) === "object" ? source[key] : undefined;
295
+ var marker = source && _typeof._typeof(source) === "object" ? source[key] : undefined;
296
296
  if (!core.Internal.isJson(marker)) {
297
297
  return undefined;
298
298
  }
@@ -2,15 +2,15 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var routeFromVal = require('../../dist/routeFromVal-ffa948ef.cjs.prod.js');
5
+ var _typeof = require('../../dist/typeof-8998e126.cjs.prod.js');
6
6
  var core = require('@valbuild/core');
7
7
  var stega = require('@valbuild/react/stega');
8
8
  var React = require('react');
9
- var ValOverlayContext = require('../../dist/ValOverlayContext-3e2c48a6.cjs.prod.js');
10
- require('../../dist/createForOfIteratorHelper-9afd7d2d.cjs.prod.js');
11
- require('@valbuild/shared/client');
9
+ var ValOverlayContext = require('../../dist/ValOverlayContext-d3acd157.cjs.prod.js');
10
+ var routeFromVal = require('../../dist/routeFromVal-97a52f43.cjs.prod.js');
12
11
  require('@valbuild/core/patch');
13
12
  require('react/jsx-runtime');
13
+ require('@valbuild/shared/client');
14
14
 
15
15
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
16
16
 
@@ -205,7 +205,7 @@ function draftJsonEntry(draftSource, key) {
205
205
  status: "absent"
206
206
  };
207
207
  }
208
- if (draftSource === undefined || routeFromVal._typeof(draftSource) !== "object" || Array.isArray(draftSource)) {
208
+ if (draftSource === undefined || _typeof._typeof(draftSource) !== "object" || Array.isArray(draftSource)) {
209
209
  return {
210
210
  status: "unavailable"
211
211
  };
@@ -292,7 +292,7 @@ function useValKeyStega(selector, key) {
292
292
  */
293
293
  function readCommittedJsonEntry(selector, key) {
294
294
  var source = selector && core.Internal.getSource(selector);
295
- var marker = source && routeFromVal._typeof(source) === "object" ? source[key] : undefined;
295
+ var marker = source && _typeof._typeof(source) === "object" ? source[key] : undefined;
296
296
  if (!core.Internal.isJson(marker)) {
297
297
  return undefined;
298
298
  }
@@ -1,12 +1,12 @@
1
- import { j as jsonValuesRecordToFill, f as fillJsonValuesRecord, g as getJsonEntryStegaRoot, _ as _typeof, b as bundledJsonEntryImport, i as isJsonValuesRecordSchema, a as getValRouteUrlFromVal, c as initValRouteFromVal } from '../../dist/routeFromVal-ae54a17e.esm.js';
1
+ import { c as _typeof } from '../../dist/typeof-66e2d869.esm.js';
2
2
  import { Internal } from '@valbuild/core';
3
3
  import { getModuleIds, stegaEncode } from '@valbuild/react/stega';
4
4
  import React from 'react';
5
- import { u as useValOverlayContext } from '../../dist/ValOverlayContext-59a0b19f.esm.js';
6
- import '../../dist/createForOfIteratorHelper-93a62170.esm.js';
7
- import '@valbuild/shared/client';
5
+ import { u as useValOverlayContext } from '../../dist/ValOverlayContext-6278320b.esm.js';
6
+ import { j as jsonValuesRecordToFill, f as fillJsonValuesRecord, g as getJsonEntryStegaRoot, b as bundledJsonEntryImport, i as isJsonValuesRecordSchema, a as getValRouteUrlFromVal, c as initValRouteFromVal } from '../../dist/routeFromVal-9f1f8725.esm.js';
8
7
  import '@valbuild/core/patch';
9
8
  import 'react/jsx-runtime';
9
+ import '@valbuild/shared/client';
10
10
 
11
11
  var subscribeNever = function subscribeNever() {
12
12
  return function () {};
@@ -0,0 +1,2 @@
1
+ export * from "../../dist/declarations/src/demo/index.js";
2
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmFsYnVpbGQtdGFuc3RhY2stZGVtby5janMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL2Rpc3QvZGVjbGFyYXRpb25zL3NyYy9kZW1vL2luZGV4LmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEifQ==
@@ -0,0 +1,105 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var asyncToGenerator = require('../../dist/asyncToGenerator-c3823d62.cjs.dev.js');
6
+ var server = require('@valbuild/ui/server');
7
+ var demoServiceWorker = require('../../dist/demoServiceWorker-382e1b63.cjs.dev.js');
8
+
9
+ /**
10
+ * The server half of a Val demo: the Studio's own files and the demo's service
11
+ * worker, and nothing else.
12
+ *
13
+ * In a demo the Studio runs Val's API in the visitor's tab
14
+ * (`@valbuild/server/browser`, started by `<ValApp demo>`), so the app has no
15
+ * content or patch endpoint at all -- nothing to authenticate, nothing to
16
+ * abuse. What it still serves is the Studio's scripts and styles, which the
17
+ * page loads from `/api/val/static/...`.
18
+ *
19
+ * Its own entry, `@valbuild/tanstack/demo`, rather than beside
20
+ * `initValServer`: importing Val's server loads all of it -- the TypeScript
21
+ * compiler included -- and a demo's server needs none of it.
22
+ *
23
+ * Mount it where `initValServer`'s handler would go:
24
+ *
25
+ * @example
26
+ * // src/routes/api/val.$.ts
27
+ * import { initValDemoServer } from "@valbuild/tanstack/demo";
28
+ * const { valApiHandler } = initValDemoServer();
29
+ * export const Route = createFileRoute("/api/val/$")({
30
+ * server: { handlers: { GET: ({ request }) => valApiHandler(request) } },
31
+ * });
32
+ */
33
+ function initValDemoServer() {
34
+ var route = "/api/val";
35
+ var uiRequestHandler = server.createUIRequestHandler();
36
+ var valApiHandler = /*#__PURE__*/function () {
37
+ var _ref = asyncToGenerator._asyncToGenerator(/*#__PURE__*/asyncToGenerator._regenerator().m(function _callee(req) {
38
+ var url, path, _t;
39
+ return asyncToGenerator._regenerator().w(function (_context) {
40
+ while (1) switch (_context.n) {
41
+ case 0:
42
+ url = new URL(req.url);
43
+ path = url.pathname.startsWith(route) ? url.pathname.slice(route.length) : null;
44
+ if (!(path === demoServiceWorker.DEMO_SERVICE_WORKER_PATH)) {
45
+ _context.n = 1;
46
+ break;
47
+ }
48
+ return _context.a(2, new Response(demoServiceWorker.DEMO_SERVICE_WORKER_SOURCE, {
49
+ headers: {
50
+ "Content-Type": "text/javascript; charset=utf-8",
51
+ "Service-Worker-Allowed": "/",
52
+ "Cache-Control": "no-cache"
53
+ }
54
+ }));
55
+ case 1:
56
+ if (!(path !== null && path.startsWith("/static"))) {
57
+ _context.n = 3;
58
+ break;
59
+ }
60
+ _t = toResponse;
61
+ _context.n = 2;
62
+ return uiRequestHandler(path.slice("/static".length), url.href);
63
+ case 2:
64
+ return _context.a(2, _t(_context.v));
65
+ case 3:
66
+ return _context.a(2, toResponse({
67
+ status: 404,
68
+ json: {
69
+ message: "Val's API is not served here: this is a demo, and the Studio runs it in the browser."
70
+ }
71
+ }));
72
+ }
73
+ }, _callee);
74
+ }));
75
+ return function valApiHandler(_x) {
76
+ return _ref.apply(this, arguments);
77
+ };
78
+ }();
79
+ return {
80
+ valApiHandler: valApiHandler
81
+ };
82
+ }
83
+ function toResponse(valRes) {
84
+ var headers = new Headers();
85
+ var valResHeaders = "headers" in valRes && valRes.headers || {};
86
+ for (var key in valResHeaders) {
87
+ var value = valResHeaders[key];
88
+ if (typeof value === "string") {
89
+ headers.set(key, value);
90
+ }
91
+ }
92
+ if ("json" in valRes) {
93
+ headers.set("Content-Type", "application/json");
94
+ return new Response(JSON.stringify(valRes.json), {
95
+ headers: headers,
96
+ status: valRes.status
97
+ });
98
+ }
99
+ return new Response("body" in valRes ? valRes.body : null, {
100
+ headers: headers,
101
+ status: valRes.status
102
+ });
103
+ }
104
+
105
+ exports.initValDemoServer = initValDemoServer;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./valbuild-tanstack-demo.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./valbuild-tanstack-demo.cjs.dev.js");
7
+ }
@@ -0,0 +1,105 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var asyncToGenerator = require('../../dist/asyncToGenerator-8e5c36c8.cjs.prod.js');
6
+ var server = require('@valbuild/ui/server');
7
+ var demoServiceWorker = require('../../dist/demoServiceWorker-994710f7.cjs.prod.js');
8
+
9
+ /**
10
+ * The server half of a Val demo: the Studio's own files and the demo's service
11
+ * worker, and nothing else.
12
+ *
13
+ * In a demo the Studio runs Val's API in the visitor's tab
14
+ * (`@valbuild/server/browser`, started by `<ValApp demo>`), so the app has no
15
+ * content or patch endpoint at all -- nothing to authenticate, nothing to
16
+ * abuse. What it still serves is the Studio's scripts and styles, which the
17
+ * page loads from `/api/val/static/...`.
18
+ *
19
+ * Its own entry, `@valbuild/tanstack/demo`, rather than beside
20
+ * `initValServer`: importing Val's server loads all of it -- the TypeScript
21
+ * compiler included -- and a demo's server needs none of it.
22
+ *
23
+ * Mount it where `initValServer`'s handler would go:
24
+ *
25
+ * @example
26
+ * // src/routes/api/val.$.ts
27
+ * import { initValDemoServer } from "@valbuild/tanstack/demo";
28
+ * const { valApiHandler } = initValDemoServer();
29
+ * export const Route = createFileRoute("/api/val/$")({
30
+ * server: { handlers: { GET: ({ request }) => valApiHandler(request) } },
31
+ * });
32
+ */
33
+ function initValDemoServer() {
34
+ var route = "/api/val";
35
+ var uiRequestHandler = server.createUIRequestHandler();
36
+ var valApiHandler = /*#__PURE__*/function () {
37
+ var _ref = asyncToGenerator._asyncToGenerator(/*#__PURE__*/asyncToGenerator._regenerator().m(function _callee(req) {
38
+ var url, path, _t;
39
+ return asyncToGenerator._regenerator().w(function (_context) {
40
+ while (1) switch (_context.n) {
41
+ case 0:
42
+ url = new URL(req.url);
43
+ path = url.pathname.startsWith(route) ? url.pathname.slice(route.length) : null;
44
+ if (!(path === demoServiceWorker.DEMO_SERVICE_WORKER_PATH)) {
45
+ _context.n = 1;
46
+ break;
47
+ }
48
+ return _context.a(2, new Response(demoServiceWorker.DEMO_SERVICE_WORKER_SOURCE, {
49
+ headers: {
50
+ "Content-Type": "text/javascript; charset=utf-8",
51
+ "Service-Worker-Allowed": "/",
52
+ "Cache-Control": "no-cache"
53
+ }
54
+ }));
55
+ case 1:
56
+ if (!(path !== null && path.startsWith("/static"))) {
57
+ _context.n = 3;
58
+ break;
59
+ }
60
+ _t = toResponse;
61
+ _context.n = 2;
62
+ return uiRequestHandler(path.slice("/static".length), url.href);
63
+ case 2:
64
+ return _context.a(2, _t(_context.v));
65
+ case 3:
66
+ return _context.a(2, toResponse({
67
+ status: 404,
68
+ json: {
69
+ message: "Val's API is not served here: this is a demo, and the Studio runs it in the browser."
70
+ }
71
+ }));
72
+ }
73
+ }, _callee);
74
+ }));
75
+ return function valApiHandler(_x) {
76
+ return _ref.apply(this, arguments);
77
+ };
78
+ }();
79
+ return {
80
+ valApiHandler: valApiHandler
81
+ };
82
+ }
83
+ function toResponse(valRes) {
84
+ var headers = new Headers();
85
+ var valResHeaders = "headers" in valRes && valRes.headers || {};
86
+ for (var key in valResHeaders) {
87
+ var value = valResHeaders[key];
88
+ if (typeof value === "string") {
89
+ headers.set(key, value);
90
+ }
91
+ }
92
+ if ("json" in valRes) {
93
+ headers.set("Content-Type", "application/json");
94
+ return new Response(JSON.stringify(valRes.json), {
95
+ headers: headers,
96
+ status: valRes.status
97
+ });
98
+ }
99
+ return new Response("body" in valRes ? valRes.body : null, {
100
+ headers: headers,
101
+ status: valRes.status
102
+ });
103
+ }
104
+
105
+ exports.initValDemoServer = initValDemoServer;
@@ -0,0 +1,101 @@
1
+ import { _ as _asyncToGenerator, a as _regenerator } from '../../dist/asyncToGenerator-500f022f.esm.js';
2
+ import { createUIRequestHandler } from '@valbuild/ui/server';
3
+ import { a as DEMO_SERVICE_WORKER_PATH, c as DEMO_SERVICE_WORKER_SOURCE } from '../../dist/demoServiceWorker-56fd96cf.esm.js';
4
+
5
+ /**
6
+ * The server half of a Val demo: the Studio's own files and the demo's service
7
+ * worker, and nothing else.
8
+ *
9
+ * In a demo the Studio runs Val's API in the visitor's tab
10
+ * (`@valbuild/server/browser`, started by `<ValApp demo>`), so the app has no
11
+ * content or patch endpoint at all -- nothing to authenticate, nothing to
12
+ * abuse. What it still serves is the Studio's scripts and styles, which the
13
+ * page loads from `/api/val/static/...`.
14
+ *
15
+ * Its own entry, `@valbuild/tanstack/demo`, rather than beside
16
+ * `initValServer`: importing Val's server loads all of it -- the TypeScript
17
+ * compiler included -- and a demo's server needs none of it.
18
+ *
19
+ * Mount it where `initValServer`'s handler would go:
20
+ *
21
+ * @example
22
+ * // src/routes/api/val.$.ts
23
+ * import { initValDemoServer } from "@valbuild/tanstack/demo";
24
+ * const { valApiHandler } = initValDemoServer();
25
+ * export const Route = createFileRoute("/api/val/$")({
26
+ * server: { handlers: { GET: ({ request }) => valApiHandler(request) } },
27
+ * });
28
+ */
29
+ function initValDemoServer() {
30
+ var route = "/api/val";
31
+ var uiRequestHandler = createUIRequestHandler();
32
+ var valApiHandler = /*#__PURE__*/function () {
33
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(req) {
34
+ var url, path, _t;
35
+ return _regenerator().w(function (_context) {
36
+ while (1) switch (_context.n) {
37
+ case 0:
38
+ url = new URL(req.url);
39
+ path = url.pathname.startsWith(route) ? url.pathname.slice(route.length) : null;
40
+ if (!(path === DEMO_SERVICE_WORKER_PATH)) {
41
+ _context.n = 1;
42
+ break;
43
+ }
44
+ return _context.a(2, new Response(DEMO_SERVICE_WORKER_SOURCE, {
45
+ headers: {
46
+ "Content-Type": "text/javascript; charset=utf-8",
47
+ "Service-Worker-Allowed": "/",
48
+ "Cache-Control": "no-cache"
49
+ }
50
+ }));
51
+ case 1:
52
+ if (!(path !== null && path.startsWith("/static"))) {
53
+ _context.n = 3;
54
+ break;
55
+ }
56
+ _t = toResponse;
57
+ _context.n = 2;
58
+ return uiRequestHandler(path.slice("/static".length), url.href);
59
+ case 2:
60
+ return _context.a(2, _t(_context.v));
61
+ case 3:
62
+ return _context.a(2, toResponse({
63
+ status: 404,
64
+ json: {
65
+ message: "Val's API is not served here: this is a demo, and the Studio runs it in the browser."
66
+ }
67
+ }));
68
+ }
69
+ }, _callee);
70
+ }));
71
+ return function valApiHandler(_x) {
72
+ return _ref.apply(this, arguments);
73
+ };
74
+ }();
75
+ return {
76
+ valApiHandler: valApiHandler
77
+ };
78
+ }
79
+ function toResponse(valRes) {
80
+ var headers = new Headers();
81
+ var valResHeaders = "headers" in valRes && valRes.headers || {};
82
+ for (var key in valResHeaders) {
83
+ var value = valResHeaders[key];
84
+ if (typeof value === "string") {
85
+ headers.set(key, value);
86
+ }
87
+ }
88
+ if ("json" in valRes) {
89
+ headers.set("Content-Type", "application/json");
90
+ return new Response(JSON.stringify(valRes.json), {
91
+ headers: headers,
92
+ status: valRes.status
93
+ });
94
+ }
95
+ return new Response("body" in valRes ? valRes.body : null, {
96
+ headers: headers,
97
+ status: valRes.status
98
+ });
99
+ }
100
+
101
+ export { initValDemoServer };
@@ -0,0 +1,4 @@
1
+ {
2
+ "main": "dist/valbuild-tanstack-demo.cjs.js",
3
+ "module": "dist/valbuild-tanstack-demo.esm.js"
4
+ }
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var createForOfIteratorHelper = require('./createForOfIteratorHelper-4497beef.cjs.dev.js');
3
+ var _typeof = require('./typeof-dd0246a1.cjs.dev.js');
4
4
  var patch = require('@valbuild/core/patch');
5
5
  var React = require('react');
6
6
  var jsxRuntime = require('react/jsx-runtime');
@@ -16,7 +16,7 @@ function _classCallCheck(a, n) {
16
16
  function _defineProperties(e, r) {
17
17
  for (var t = 0; t < r.length; t++) {
18
18
  var o = r[t];
19
- o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, createForOfIteratorHelper._toPropertyKey(o.key), o);
19
+ o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _typeof._toPropertyKey(o.key), o);
20
20
  }
21
21
  }
22
22
  function _createClass(e, r, t) {
@@ -30,20 +30,20 @@ var ValExternalStore = /*#__PURE__*/function () {
30
30
  function ValExternalStore() {
31
31
  var _this = this;
32
32
  _classCallCheck(this, ValExternalStore);
33
- createForOfIteratorHelper._defineProperty(this, "listeners", void 0);
34
- createForOfIteratorHelper._defineProperty(this, "loadPromises", void 0);
33
+ _typeof._defineProperty(this, "listeners", void 0);
34
+ _typeof._defineProperty(this, "loadPromises", void 0);
35
35
  // Path-keyed cache of every source seen via update(). The single source of
36
36
  // truth: load state and snapshots are both derived from this, so data can be
37
37
  // queried for any combination of paths even before a subscriber registers.
38
- createForOfIteratorHelper._defineProperty(this, "loadedSources", void 0);
38
+ _typeof._defineProperty(this, "loadedSources", void 0);
39
39
  // Reference-stable per-subscriberId snapshot cache for useSyncExternalStore.
40
40
  // Built lazily from loadedSources in get() and invalidated in update().
41
- createForOfIteratorHelper._defineProperty(this, "snapshots", void 0);
41
+ _typeof._defineProperty(this, "snapshots", void 0);
42
42
  // One-shot listeners used solely by waitForLoad. Kept separate from the
43
43
  // useSyncExternalStore listeners so waitForLoad never has to register (and
44
44
  // leak) a subscriberId.
45
- createForOfIteratorHelper._defineProperty(this, "loadListeners", void 0);
46
- createForOfIteratorHelper._defineProperty(this, "subscribe", function (paths) {
45
+ _typeof._defineProperty(this, "loadListeners", void 0);
46
+ _typeof._defineProperty(this, "subscribe", function (paths) {
47
47
  return function (listener) {
48
48
  var subscriberId = createSubscriberId(paths);
49
49
  var existing = _this.listeners.get(subscriberId);
@@ -61,17 +61,17 @@ var ValExternalStore = /*#__PURE__*/function () {
61
61
  };
62
62
  };
63
63
  });
64
- createForOfIteratorHelper._defineProperty(this, "getSnapshot", function (paths) {
64
+ _typeof._defineProperty(this, "getSnapshot", function (paths) {
65
65
  return function () {
66
66
  return _this.get(paths);
67
67
  };
68
68
  });
69
- createForOfIteratorHelper._defineProperty(this, "getServerSnapshot", function (paths) {
69
+ _typeof._defineProperty(this, "getServerSnapshot", function (paths) {
70
70
  return function () {
71
71
  return _this.get(paths);
72
72
  };
73
73
  });
74
- createForOfIteratorHelper._defineProperty(this, "get", function (paths) {
74
+ _typeof._defineProperty(this, "get", function (paths) {
75
75
  var subscriberId = createSubscriberId(paths);
76
76
  if (_this.snapshots.has(subscriberId)) {
77
77
  return _this.snapshots.get(subscriberId);
@@ -80,7 +80,7 @@ var ValExternalStore = /*#__PURE__*/function () {
80
80
  // before this subscriber registered is still returned. Cache it for a
81
81
  // reference-stable result (required by useSyncExternalStore).
82
82
  var record;
83
- var _iterator = createForOfIteratorHelper._createForOfIteratorHelper(paths),
83
+ var _iterator = _typeof._createForOfIteratorHelper(paths),
84
84
  _step;
85
85
  try {
86
86
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
@@ -102,8 +102,8 @@ var ValExternalStore = /*#__PURE__*/function () {
102
102
  _this.snapshots.set(subscriberId, record);
103
103
  return record;
104
104
  });
105
- createForOfIteratorHelper._defineProperty(this, "hasAllLoaded", function (paths) {
106
- var _iterator2 = createForOfIteratorHelper._createForOfIteratorHelper(paths),
105
+ _typeof._defineProperty(this, "hasAllLoaded", function (paths) {
106
+ var _iterator2 = _typeof._createForOfIteratorHelper(paths),
107
107
  _step2;
108
108
  try {
109
109
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
@@ -131,7 +131,7 @@ var ValExternalStore = /*#__PURE__*/function () {
131
131
  * hang it resolves anyway after `LOAD_TIMEOUT_MS`, logging an error so the
132
132
  * failure is diagnosable while the page still renders with partial data.
133
133
  */
134
- createForOfIteratorHelper._defineProperty(this, "waitForLoad", function (paths) {
134
+ _typeof._defineProperty(this, "waitForLoad", function (paths) {
135
135
  if (_this.hasAllLoaded(paths)) {
136
136
  return Promise.resolve();
137
137
  }
@@ -218,7 +218,7 @@ var ValExternalStore = /*#__PURE__*/function () {
218
218
  this.snapshots["delete"](subscriberId);
219
219
  }
220
220
  }
221
- var _iterator3 = createForOfIteratorHelper._createForOfIteratorHelper(this.listeners.keys()),
221
+ var _iterator3 = _typeof._createForOfIteratorHelper(this.listeners.keys()),
222
222
  _step3;
223
223
  try {
224
224
  for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
@@ -242,7 +242,7 @@ var ValExternalStore = /*#__PURE__*/function () {
242
242
  key: "emitChange",
243
243
  value: function emitChange(subscriberId) {
244
244
  var _this$listeners$get;
245
- var _iterator4 = createForOfIteratorHelper._createForOfIteratorHelper((_this$listeners$get = this.listeners.get(subscriberId)) !== null && _this$listeners$get !== void 0 ? _this$listeners$get : []),
245
+ var _iterator4 = _typeof._createForOfIteratorHelper((_this$listeners$get = this.listeners.get(subscriberId)) !== null && _this$listeners$get !== void 0 ? _this$listeners$get : []),
246
246
  _step4;
247
247
  try {
248
248
  for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
@@ -1,4 +1,4 @@
1
- import { c as _toPropertyKey, b as _createForOfIteratorHelper, d as _defineProperty } from './createForOfIteratorHelper-93a62170.esm.js';
1
+ import { f as _toPropertyKey, b as _createForOfIteratorHelper, g as _defineProperty } from './typeof-66e2d869.esm.js';
2
2
  import { deepEqual } from '@valbuild/core/patch';
3
3
  import React from 'react';
4
4
  import { jsx } from 'react/jsx-runtime';