@valbuild/server 0.154.0 → 0.154.2

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 (58) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/browser/dist/valbuild-server-browser.cjs.dev.js +6 -3
  3. package/browser/dist/valbuild-server-browser.cjs.prod.js +6 -3
  4. package/browser/dist/valbuild-server-browser.esm.js +6 -3
  5. package/dist/{ValRouterCore-fe985e4c.esm.js → ValOpsMemory-611f33d2.esm.js} +44 -1988
  6. package/dist/{ValRouterCore-4be8eaf1.cjs.prod.js → ValOpsMemory-6ebbb3ba.cjs.prod.js} +53 -2009
  7. package/dist/{ValRouterCore-0c088c9e.cjs.dev.js → ValOpsMemory-d8bf9f5d.cjs.dev.js} +53 -2009
  8. package/dist/ValPatchStore-2f92eced.cjs.prod.js +1128 -0
  9. package/dist/ValPatchStore-df8cdbe7.cjs.dev.js +1128 -0
  10. package/dist/ValPatchStore-e23070df.esm.js +1119 -0
  11. package/dist/ValRouterCore-5b747abb.cjs.prod.js +612 -0
  12. package/dist/ValRouterCore-73eb843d.esm.js +608 -0
  13. package/dist/ValRouterCore-86757d56.cjs.dev.js +612 -0
  14. package/dist/createPrettierFormatter-05ad7480.cjs.prod.js +692 -0
  15. package/dist/createPrettierFormatter-1edca494.esm.js +673 -0
  16. package/dist/createPrettierFormatter-851fcf99.cjs.dev.js +692 -0
  17. package/dist/createValRuntime-2dc83070.cjs.prod.js +47 -0
  18. package/dist/createValRuntime-62836dbe.esm.js +45 -0
  19. package/dist/createValRuntime-fd9b673d.cjs.dev.js +47 -0
  20. package/dist/declarations/src/ValOpsMemory.d.ts +3 -73
  21. package/dist/declarations/src/ValPatchStore.d.ts +92 -0
  22. package/dist/declarations/src/ValRouter.d.ts +1 -11
  23. package/dist/declarations/src/createPrettierFormatter.d.ts +18 -3
  24. package/dist/declarations/src/createValRuntime.d.ts +12 -0
  25. package/dist/declarations/src/draftReads.d.ts +11 -3
  26. package/dist/declarations/src/index.d.ts +4 -2
  27. package/dist/declarations/src/internal/index.d.ts +28 -6
  28. package/dist/declarations/src/proposal.d.ts +13 -25
  29. package/dist/declarations/src/proposalJsonEntries.d.ts +30 -0
  30. package/dist/declarations/src/serverMode.d.ts +31 -0
  31. package/dist/{draftReads-0dcddf72.cjs.prod.js → draftReads-3f7dcda5.cjs.prod.js} +10 -2
  32. package/dist/{draftReads-df44e629.cjs.dev.js → draftReads-a300a02f.cjs.dev.js} +10 -2
  33. package/dist/{draftReads-1f29aedd.esm.js → draftReads-bca0d49c.esm.js} +10 -2
  34. package/dist/{inTabFetch-f6694ad2.cjs.prod.js → inTabFetch-0124da2e.cjs.prod.js} +5 -4
  35. package/dist/{inTabFetch-c8966e73.cjs.dev.js → inTabFetch-d0c9c58a.cjs.dev.js} +5 -4
  36. package/dist/{inTabFetch-877e7d11.esm.js → inTabFetch-e48a801e.esm.js} +2 -1
  37. package/dist/jsonValuesPatch-13acc674.esm.js +276 -0
  38. package/dist/jsonValuesPatch-88bc661d.cjs.dev.js +281 -0
  39. package/dist/jsonValuesPatch-92798812.cjs.prod.js +281 -0
  40. package/dist/proposalJsonEntries-0669f027.esm.js +480 -0
  41. package/dist/proposalJsonEntries-26f397bd.cjs.dev.js +500 -0
  42. package/dist/proposalJsonEntries-9e537244.cjs.prod.js +500 -0
  43. package/dist/{publishKit-cfe1273d.cjs.dev.js → publishKit-96522d5a.cjs.prod.js} +20 -22
  44. package/dist/{publishKit-e7f7db7c.cjs.prod.js → publishKit-b06031dc.cjs.dev.js} +20 -22
  45. package/dist/{publishKit-0709423c.esm.js → publishKit-b8929fe8.esm.js} +8 -9
  46. package/dist/{ValRouter-1f427c38.cjs.dev.js → valRuntime-ba8ff718.cjs.prod.js} +158 -6038
  47. package/dist/{ValRouter-cd6e854a.cjs.prod.js → valRuntime-c8c82b24.cjs.dev.js} +158 -6038
  48. package/dist/{ValRouter-558dc66d.esm.js → valRuntime-ccbbbfad.esm.js} +107 -5937
  49. package/dist/valbuild-server.cjs.dev.js +5146 -352
  50. package/dist/valbuild-server.cjs.prod.js +5146 -352
  51. package/dist/valbuild-server.esm.js +4902 -132
  52. package/internal/browser/dist/valbuild-server-internal-browser.cjs.dev.js +7 -4
  53. package/internal/browser/dist/valbuild-server-internal-browser.cjs.prod.js +7 -4
  54. package/internal/browser/dist/valbuild-server-internal-browser.esm.js +7 -4
  55. package/internal/dist/valbuild-server-internal.cjs.dev.js +47 -31
  56. package/internal/dist/valbuild-server-internal.cjs.prod.js +47 -31
  57. package/internal/dist/valbuild-server-internal.esm.js +38 -22
  58. package/package.json +4 -4
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ var valRuntime = require('./valRuntime-ba8ff718.cjs.prod.js');
4
+ require('@valbuild/core');
5
+ require('./ValOpsMemory-6ebbb3ba.cjs.prod.js');
6
+ require('zod');
7
+ require('@valbuild/shared/internal');
8
+ require('./jsonValuesPatch-92798812.cjs.prod.js');
9
+ require('@valbuild/core/fp');
10
+ require('zod-validation-error');
11
+ require('./ValPatchStore-2f92eced.cjs.prod.js');
12
+ require('@valbuild/core/patch');
13
+ require('image-size');
14
+ require('path');
15
+ require('typescript');
16
+ require('fs');
17
+ require('./proposalJsonEntries-9e537244.cjs.prod.js');
18
+ require('./createPrettierFormatter-05ad7480.cjs.prod.js');
19
+ require('os');
20
+ require('crypto');
21
+ require('buffer');
22
+ require('node:vm');
23
+ require('node:module');
24
+
25
+ /**
26
+ * The runtime the draft readers read through (`initValContent`,
27
+ * `initValRsc`): the same one `createValServer` builds its server on, for the
28
+ * same `valModules` and options (`valRuntime`), so a save through the API
29
+ * moves what the readers read. The readers read its head directly, with the
30
+ * request's session (`ValRuntime.authorize`): no private server, and no
31
+ * request to it.
32
+ */
33
+ async function createValRuntime(valModules, route, opts, config) {
34
+ var _opts$versions;
35
+ const valServerConfig = await valRuntime.initHandlerOptions(route, opts, config);
36
+ return valRuntime.valRuntime(valModules, {
37
+ ...((_opts$versions = opts.versions) !== null && _opts$versions !== void 0 && _opts$versions.framework && opts.versions.next ? {
38
+ framework: {
39
+ name: opts.versions.framework,
40
+ version: opts.versions.next
41
+ }
42
+ } : {}),
43
+ ...valServerConfig
44
+ });
45
+ }
46
+
47
+ exports.createValRuntime = createValRuntime;
@@ -0,0 +1,45 @@
1
+ import { i as initHandlerOptions, v as valRuntime } from './valRuntime-ccbbbfad.esm.js';
2
+ import '@valbuild/core';
3
+ import './ValOpsMemory-611f33d2.esm.js';
4
+ import 'zod';
5
+ import '@valbuild/shared/internal';
6
+ import './jsonValuesPatch-13acc674.esm.js';
7
+ import '@valbuild/core/fp';
8
+ import 'zod-validation-error';
9
+ import './ValPatchStore-e23070df.esm.js';
10
+ import '@valbuild/core/patch';
11
+ import 'image-size';
12
+ import 'path';
13
+ import 'typescript';
14
+ import 'fs';
15
+ import './proposalJsonEntries-0669f027.esm.js';
16
+ import './createPrettierFormatter-1edca494.esm.js';
17
+ import 'os';
18
+ import 'crypto';
19
+ import 'buffer';
20
+ import 'node:vm';
21
+ import 'node:module';
22
+
23
+ /**
24
+ * The runtime the draft readers read through (`initValContent`,
25
+ * `initValRsc`): the same one `createValServer` builds its server on, for the
26
+ * same `valModules` and options (`valRuntime`), so a save through the API
27
+ * moves what the readers read. The readers read its head directly, with the
28
+ * request's session (`ValRuntime.authorize`): no private server, and no
29
+ * request to it.
30
+ */
31
+ async function createValRuntime(valModules, route, opts, config) {
32
+ var _opts$versions;
33
+ const valServerConfig = await initHandlerOptions(route, opts, config);
34
+ return valRuntime(valModules, {
35
+ ...((_opts$versions = opts.versions) !== null && _opts$versions !== void 0 && _opts$versions.framework && opts.versions.next ? {
36
+ framework: {
37
+ name: opts.versions.framework,
38
+ version: opts.versions.next
39
+ }
40
+ } : {}),
41
+ ...valServerConfig
42
+ });
43
+ }
44
+
45
+ export { createValRuntime };
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ var valRuntime = require('./valRuntime-c8c82b24.cjs.dev.js');
4
+ require('@valbuild/core');
5
+ require('./ValOpsMemory-d8bf9f5d.cjs.dev.js');
6
+ require('zod');
7
+ require('@valbuild/shared/internal');
8
+ require('./jsonValuesPatch-88bc661d.cjs.dev.js');
9
+ require('@valbuild/core/fp');
10
+ require('zod-validation-error');
11
+ require('./ValPatchStore-df8cdbe7.cjs.dev.js');
12
+ require('@valbuild/core/patch');
13
+ require('image-size');
14
+ require('path');
15
+ require('typescript');
16
+ require('fs');
17
+ require('./proposalJsonEntries-26f397bd.cjs.dev.js');
18
+ require('./createPrettierFormatter-851fcf99.cjs.dev.js');
19
+ require('os');
20
+ require('crypto');
21
+ require('buffer');
22
+ require('node:vm');
23
+ require('node:module');
24
+
25
+ /**
26
+ * The runtime the draft readers read through (`initValContent`,
27
+ * `initValRsc`): the same one `createValServer` builds its server on, for the
28
+ * same `valModules` and options (`valRuntime`), so a save through the API
29
+ * moves what the readers read. The readers read its head directly, with the
30
+ * request's session (`ValRuntime.authorize`): no private server, and no
31
+ * request to it.
32
+ */
33
+ async function createValRuntime(valModules, route, opts, config) {
34
+ var _opts$versions;
35
+ const valServerConfig = await valRuntime.initHandlerOptions(route, opts, config);
36
+ return valRuntime.valRuntime(valModules, {
37
+ ...((_opts$versions = opts.versions) !== null && _opts$versions !== void 0 && _opts$versions.framework && opts.versions.next ? {
38
+ framework: {
39
+ name: opts.versions.framework,
40
+ version: opts.versions.next
41
+ }
42
+ } : {}),
43
+ ...valServerConfig
44
+ });
45
+ }
46
+
47
+ exports.createValRuntime = createValRuntime;
@@ -5,79 +5,9 @@ import type { HistoryError } from "./history/HistoryError.js";
5
5
  import type { AffectedFile, CommitPage, CommitPatch, HistoricalCommit, StoredModuleVersion } from "./history/types.js";
6
6
  import { result } from "@valbuild/core/fp";
7
7
  import { type SketchpadStore } from "./sketchpads/SketchpadStore.js";
8
- /**
9
- * One stored patch. Everything the ordered chain needs and nothing else.
10
- */
11
- export type StoredPatch = {
12
- patchId: PatchId;
13
- path: ModuleFilePath;
14
- patch: Patch;
15
- authorId: AuthorId | null;
16
- createdAt: string;
17
- baseSha: BaseSha;
18
- };
19
- /**
20
- * One pending binary file: an upload that has not been published yet.
21
- *
22
- * Keyed by the patch that carries it, exactly as `fs` mode keys the directory
23
- * it writes to. The patch's own `file` op holds a hash, not the bytes, so these
24
- * arrive on their own request and are joined up by `(patchId, filePath)`.
25
- */
26
- export type StoredFile = {
27
- patchId: PatchId;
28
- /**
29
- * Where the file will live once published.
30
- *
31
- * For a LOCAL file that is `/public/val/photo.jpg`. For a REMOTE one it is
32
- * the path INSIDE the ref, not the ref itself -- `splitRemoteRef` has already
33
- * taken it apart by the time the bytes get here, and both readers are keyed
34
- * the same way. This is why neither takes `remote` into account: the caller
35
- * has resolved that before it asks.
36
- */
37
- filePath: string;
38
- data: Uint8Array;
39
- metadata: MetadataOfType<"file" | "image"> | undefined;
40
- };
41
- export interface ValPatchStore {
42
- list(): Promise<PatchId[]>;
43
- get(patchId: PatchId): Promise<StoredPatch | null>;
44
- append(patch: StoredPatch): Promise<void>;
45
- /** The patches AND every file they carry. */
46
- delete(patchIds: PatchId[]): Promise<void>;
47
- /**
48
- * Hold an uploaded file until its patch is published or dropped.
49
- *
50
- * Uploads arrive BEFORE the patch record does -- the record's `file` op
51
- * carries only a hash, so it would otherwise point at nothing. So a file for
52
- * a patch id that does not exist yet is normal and must be accepted. `fs`
53
- * mode stages these outside its store and moves them in when the record
54
- * lands, because a directory of files with no `patch.json` is indistinguishable
55
- * from a patch whose contents were lost, and its repair pass deletes those.
56
- * Nothing sweeps this store, so the two-step is not needed here -- at the cost
57
- * that bytes uploaded for a patch that is never recorded stay until the store
58
- * is dropped.
59
- */
60
- putFile(file: StoredFile): Promise<void>;
61
- getFile(patchId: PatchId, filePath: string): Promise<StoredFile | null>;
62
- deleteFile(patchId: PatchId, filePath: string): Promise<void>;
63
- /** Every file held for a patch, which is what the publish step uploads. */
64
- filesOf(patchId: PatchId): Promise<StoredFile[]>;
65
- }
66
- /** The default store. Not durable, deliberately and visibly. */
67
- export declare class InMemoryPatchStore implements ValPatchStore {
68
- private readonly order;
69
- private readonly byId;
70
- list(): Promise<PatchId[]>;
71
- get(patchId: PatchId): Promise<StoredPatch | null>;
72
- append(patch: StoredPatch): Promise<void>;
73
- delete(patchIds: PatchId[]): Promise<void>;
74
- private static fileKey;
75
- private readonly files;
76
- putFile(file: StoredFile): Promise<void>;
77
- getFile(patchId: PatchId, filePath: string): Promise<StoredFile | null>;
78
- deleteFile(patchId: PatchId, filePath: string): Promise<void>;
79
- filesOf(patchId: PatchId): Promise<StoredFile[]>;
80
- }
8
+ import { InMemoryPatchStore, type ValPatchStore } from "./ValPatchStore.js";
9
+ export { InMemoryPatchStore };
10
+ export type { StoredFile, StoredPatch, ValPatchStore } from "./ValPatchStore.js";
81
11
  export type ValOpsMemoryOptions = ValOpsOptions & {
82
12
  /**
83
13
  * The project's source, by path, as the host already holds it.
@@ -0,0 +1,92 @@
1
+ import type { ModuleFilePath, PatchId } from "@valbuild/core";
2
+ import type { Patch } from "@valbuild/shared/internal";
3
+ import type { AuthorId, BaseSha, MetadataOfType } from "./ValOps.js";
4
+ /**
5
+ * One stored patch. Everything the ordered chain needs and nothing else.
6
+ */
7
+ export type StoredPatch = {
8
+ patchId: PatchId;
9
+ path: ModuleFilePath;
10
+ patch: Patch;
11
+ authorId: AuthorId | null;
12
+ createdAt: string;
13
+ baseSha: BaseSha;
14
+ };
15
+ /**
16
+ * One pending binary file: an upload that has not been published yet.
17
+ *
18
+ * Keyed by the patch that carries it, exactly as `fs` mode keys the directory
19
+ * it writes to. The patch's own `file` op holds a hash, not the bytes, so these
20
+ * arrive on their own request and are joined up by `(patchId, filePath)`.
21
+ */
22
+ export type StoredFile = {
23
+ patchId: PatchId;
24
+ /**
25
+ * Where the file will live once published.
26
+ *
27
+ * For a LOCAL file that is `/public/val/photo.jpg`. For a REMOTE one it is
28
+ * the path INSIDE the ref, not the ref itself -- `splitRemoteRef` has already
29
+ * taken it apart by the time the bytes get here, and both readers are keyed
30
+ * the same way. This is why neither takes `remote` into account: the caller
31
+ * has resolved that before it asks.
32
+ */
33
+ filePath: string;
34
+ data: Uint8Array;
35
+ metadata: MetadataOfType<"file" | "image"> | undefined;
36
+ };
37
+ /**
38
+ * Where pending patches live.
39
+ *
40
+ * The point of the interface: `ValOpsMemory` is not tied to memory. The default
41
+ * implementation below is explicitly NOT durable -- it dies with the process,
42
+ * or in a Worker with the isolate -- and a durable one (a Durable Object, whose
43
+ * single-threaded execution is the lock Val's fs store builds out of a file)
44
+ * is a swap rather than a rewrite.
45
+ *
46
+ * ORDER IS THE CONTRACT. `list()` returns patch ids in the order they were
47
+ * written, and that order is the chain: entry i's parent is entry i-1. This is
48
+ * the same decision `ValOpsFS` makes with `patches.log` -- the server decides
49
+ * where a patch goes, and it goes last -- and it exists for the same reason: an
50
+ * order held in the patches themselves lets a client working from a stale view
51
+ * strand every patch behind a parent that never landed.
52
+ */
53
+ export interface ValPatchStore {
54
+ list(): Promise<PatchId[]>;
55
+ get(patchId: PatchId): Promise<StoredPatch | null>;
56
+ append(patch: StoredPatch): Promise<void>;
57
+ /** The patches AND every file they carry. */
58
+ delete(patchIds: PatchId[]): Promise<void>;
59
+ /**
60
+ * Hold an uploaded file until its patch is published or dropped.
61
+ *
62
+ * Uploads arrive BEFORE the patch record does -- the record's `file` op
63
+ * carries only a hash, so it would otherwise point at nothing. So a file for
64
+ * a patch id that does not exist yet is normal and must be accepted. `fs`
65
+ * mode stages these outside its store and moves them in when the record
66
+ * lands, because a directory of files with no `patch.json` is indistinguishable
67
+ * from a patch whose contents were lost, and its repair pass deletes those.
68
+ * Nothing sweeps this store, so the two-step is not needed here -- at the cost
69
+ * that bytes uploaded for a patch that is never recorded stay until the store
70
+ * is dropped.
71
+ */
72
+ putFile(file: StoredFile): Promise<void>;
73
+ getFile(patchId: PatchId, filePath: string): Promise<StoredFile | null>;
74
+ deleteFile(patchId: PatchId, filePath: string): Promise<void>;
75
+ /** Every file held for a patch, which is what the publish step uploads. */
76
+ filesOf(patchId: PatchId): Promise<StoredFile[]>;
77
+ }
78
+ /** The default store. Not durable, deliberately and visibly. */
79
+ export declare class InMemoryPatchStore implements ValPatchStore {
80
+ private readonly order;
81
+ private readonly byId;
82
+ list(): Promise<PatchId[]>;
83
+ get(patchId: PatchId): Promise<StoredPatch | null>;
84
+ append(patch: StoredPatch): Promise<void>;
85
+ delete(patchIds: PatchId[]): Promise<void>;
86
+ private static fileKey;
87
+ private readonly files;
88
+ putFile(file: StoredFile): Promise<void>;
89
+ getFile(patchId: PatchId, filePath: string): Promise<StoredFile | null>;
90
+ deleteFile(patchId: PatchId, filePath: string): Promise<void>;
91
+ filesOf(patchId: PatchId): Promise<StoredFile[]>;
92
+ }
@@ -1,7 +1,6 @@
1
1
  import { ValConfig, ValModules } from "@valbuild/core";
2
2
  import type { ValServerGenericResult } from "@valbuild/shared/internal";
3
3
  import { ValServer, ValServerCallbacks } from "./ValServer.js";
4
- import { type ValRuntime } from "./valRuntime.js";
5
4
  type Versions = {
6
5
  versions?: {
7
6
  core?: string;
@@ -264,15 +263,7 @@ commitPrepared?: (commit: {
264
263
  * `ValServerOptions.publishOverride`.
265
264
  */
266
265
  publishOverride?: (context: CommitContext) => Promise<CommitResult>): Promise<ValServer>;
267
- /**
268
- * The runtime the draft readers read through (`initValContent`,
269
- * `initValRsc`): the same one `createValServer` builds its server on, for the
270
- * same `valModules` and options (`valRuntime`), so a save through the API
271
- * moves what the readers read. The readers read its head directly, with the
272
- * request's session (`ValRuntime.authorize`): no private server, and no
273
- * request to it.
274
- */
275
- export declare function createValRuntime(valModules: ValModules, route: string, opts: ValApiOptions, config: ValConfig): Promise<ValRuntime>;
266
+ export { createValRuntime } from "./createValRuntime.js";
276
267
  /**
277
268
  * `fs` and `path` are imported INSIDE this function, not at the top of the file.
278
269
  *
@@ -291,4 +282,3 @@ export declare function safeReadGit(cwd: string): Promise<{
291
282
  branch?: string;
292
283
  }>;
293
284
  export declare function createValApiRouter<Res>(route: string, valServerPromise: Promise<ValServer>, convert: (valServerRes: ValServerGenericResult) => Res): (req: Request) => Promise<Res>;
294
- export {};
@@ -44,6 +44,16 @@ export type PrettierLike = {
44
44
  ignored: boolean;
45
45
  };
46
46
  };
47
+ /**
48
+ * `prettier`, loaded when the first file is formatted: `() => import("prettier")`.
49
+ *
50
+ * What an app's `val.server.ts` should pass. That module is imported by every
51
+ * page (it holds the readers too), so a static `import prettier from
52
+ * "prettier"` there makes every cold start of the site evaluate prettier --
53
+ * for a formatter that only runs when an editor saves. The loader is called at
54
+ * most once.
55
+ */
56
+ export type PrettierLoader = () => Promise<PrettierLike>;
47
57
  /**
48
58
  * A {@link ValFormatter} that formats the way the project itself does.
49
59
  *
@@ -58,15 +68,20 @@ export type PrettierLike = {
58
68
  * job in any repo that checks formatting in CI.
59
69
  *
60
70
  * ```ts
61
- * import prettier from "prettier";
62
71
  * import { createPrettierFormatter } from "@valbuild/next/server";
63
72
  *
64
73
  * initValServer(valModules, config, {
65
74
  * draftMode,
66
- * formatter: createPrettierFormatter(prettier, { projectRoot: process.cwd() }),
75
+ * formatter: createPrettierFormatter(() => import("prettier"), {
76
+ * projectRoot: process.cwd(),
77
+ * }),
67
78
  * });
68
79
  * ```
69
80
  *
81
+ * `prettier` itself is accepted too (`createPrettierFormatter(prettier, …)`),
82
+ * for a caller that has it loaded anyway, like the CLI; a server should pass
83
+ * the loader ({@link PrettierLoader}).
84
+ *
70
85
  * `projectRoot` is what a project-relative path is resolved against, and is
71
86
  * therefore also where `.prettierignore` is looked for. Prettier's own config
72
87
  * search walks UP from the resolved file, so a monorepo package with its own
@@ -82,6 +97,6 @@ export type PrettierLike = {
82
97
  * the file is formatted with prettier's defaults, which is what a project
83
98
  * without a config has asked for.
84
99
  */
85
- export declare function createPrettierFormatter(prettier: PrettierLike, options: {
100
+ export declare function createPrettierFormatter(prettierOrLoader: PrettierLike | PrettierLoader, options: {
86
101
  projectRoot: string;
87
102
  }): ValFormatter;
@@ -0,0 +1,12 @@
1
+ import type { ValConfig, ValModules } from "@valbuild/core";
2
+ import { type ValRuntime } from "./valRuntime.js";
3
+ import type { ValApiOptions } from "./ValRouter.js";
4
+ /**
5
+ * The runtime the draft readers read through (`initValContent`,
6
+ * `initValRsc`): the same one `createValServer` builds its server on, for the
7
+ * same `valModules` and options (`valRuntime`), so a save through the API
8
+ * moves what the readers read. The readers read its head directly, with the
9
+ * request's session (`ValRuntime.authorize`): no private server, and no
10
+ * request to it.
11
+ */
12
+ export declare function createValRuntime(valModules: ValModules, route: string, opts: ValApiOptions, config: ValConfig): Promise<ValRuntime>;
@@ -10,6 +10,14 @@ type Cookies = {
10
10
  type Headers = {
11
11
  get(name: string): string | null;
12
12
  };
13
+ /**
14
+ * The runtime a reader reads the draft through, asked for when a read first
15
+ * needs it (`createValRuntime`). A function rather than a promise, so that
16
+ * building the readers does not build the runtime: the runtime is the data
17
+ * layer, and a visitor -- draft mode off -- never needs it. A caller that
18
+ * already has one passes `() => runtime`; it is asked at most once a read.
19
+ */
20
+ export type ReaderRuntime = () => Promise<ValRuntime>;
13
21
  /** One module {@link readDraftChanges} read: what a reader's `reads` record. */
14
22
  export type DraftModuleRead = {
15
23
  path: ModuleFilePath;
@@ -35,7 +43,7 @@ export type DraftModuleRead = {
35
43
  * that fails to render is an outage.
36
44
  */
37
45
  export declare function readDraftChanges(opts: {
38
- runtime: Promise<ValRuntime>;
46
+ runtime: ReaderRuntime;
39
47
  isEnabled: () => Promise<boolean>;
40
48
  getCookies: () => Promise<Cookies>;
41
49
  }): Promise<{
@@ -62,7 +70,7 @@ export declare function readDraftChanges(opts: {
62
70
  * `modules: false` (the single-entry readers): every module passes.
63
71
  */
64
72
  export declare function serverDraftSource(opts: {
65
- runtime: Promise<ValRuntime>;
73
+ runtime: ReaderRuntime;
66
74
  session: string | undefined;
67
75
  modules: boolean;
68
76
  }): ContentSource;
@@ -77,7 +85,7 @@ export declare function serverDraftSource(opts: {
77
85
  * gets; without it (the single-entry readers) they stay quiet, as they were.
78
86
  */
79
87
  export declare function draftForRequest(opts: {
80
- runtime: Promise<ValRuntime>;
88
+ runtime: ReaderRuntime;
81
89
  isEnabled: () => Promise<boolean>;
82
90
  getCookies: () => Promise<Cookies>;
83
91
  /**
@@ -2,9 +2,11 @@ export { createService, Service } from "./Service.js";
2
2
  export { defineExternal, ok, err, isExternalResult, EXTERNAL_RESULT, } from "./externalRecords.js";
3
3
  export type { AdapterFor, BoundExternalRecord, ExternalAuthor, ExternalBuilder, ExternalCtx, ExternalDefinition, ExternalFile, ExternalIssue, ExternalKeyPage, ExternalRecords, ExternalResult, ExternalSearchHit, ExternalSearchPage, ExternalSort, ItemOfModule, ReadonlyRecordHasNoWrites, Returns, } from "./externalRecords.js";
4
4
  export { createValApiRouter, createValServer, safeReadGit } from "./ValRouter.js";
5
- export { contentFromEnv, proposalFromEnv, layeredSnapshot, proposalSnapshot, proposalSnapshotForReaders, } from "./proposal.js";
5
+ export { contentFromEnv, proposalFromEnv, layeredSnapshot, proposalSnapshot, } from "./proposal.js";
6
+ export { proposalSnapshotForReaders } from "./proposalJsonEntries.js";
6
7
  export type { ValContentVersion, ValProposal } from "./proposal.js";
7
8
  export { initHandlerOptions, createValOps } from "./valServerConfig.js";
9
+ export { valRuntime, type ValRuntime } from "./valRuntime.js";
8
10
  export { resolveRemoteFileAuth } from "./valServerConfig.js";
9
11
  export { APP_MODE_REQUIRES_REMOTE_FILES } from "./valServerConfig.js";
10
12
  export type { RemoteFileAuth, ResolveRemoteFileAuthResult, } from "./valServerConfig.js";
@@ -36,7 +38,7 @@ export { checkRemoteRef, downloadFileFromRemote, getCachedRemoteFileDir, getCach
36
38
  export { hasRemoteFileSchema } from "@valbuild/core";
37
39
  export { getFileExt } from "./getFileExt.js";
38
40
  export { createPrettierFormatter } from "./createPrettierFormatter.js";
39
- export type { PrettierLike, PrettierLikeConfig, ValFormatter, } from "./createPrettierFormatter.js";
41
+ export type { PrettierLike, PrettierLikeConfig, PrettierLoader, ValFormatter, } from "./createPrettierFormatter.js";
40
42
  export { evalValConfigFile, findAndEvalValConfigFile, } from "./evalValConfigFile.js";
41
43
  export { startValLogin, awaitValLoginConfirmation, persistPersonalAccessToken, ValLoginError, DEFAULT_LOGIN_HOST, DEFAULT_LOGIN_EXPIRES_IN_SECONDS, DEFAULT_LOGIN_POLL_INTERVAL_SECONDS, } from "./login.js";
42
44
  export type { ValLoginErrorCode, ValLoginResult, ValDeviceAuthorization, } from "./login.js";
@@ -3,13 +3,35 @@
3
3
  * `@valbuild/mcp` and the scenarios share of the server, and nothing an app
4
4
  * should import. Not public API: it changes without a major version.
5
5
  *
6
- * The runtime every server and reader in a process shares (`valRuntime`,
7
- * `createValRuntime`), its head (`ValHead`), and the draft the server-side
6
+ * The runtime every server and reader in a process shares
7
+ * (`createValRuntime`), its head (`ValHead`), and the draft the server-side
8
8
  * readers read from it (`draftForRequest` and friends).
9
+ *
10
+ * THIS ENTRY IS ON EVERY PAGE'S PATH. The server-side readers
11
+ * (`initValContent`, `initValRsc`) import it, and they run for every visitor,
12
+ * so everything it imports statically is evaluated by a cold isolate before
13
+ * it can answer anyone. What a visitor's page never needs -- the data layer
14
+ * (`ValOps*`), TypeScript, sucrase, prettier, the Studio's assets
15
+ * (`@valbuild/ui/server`) -- is reached from here only through a dynamic
16
+ * `import()` at the point of first use: a draft read, a save, the Val API.
17
+ * `servingPath.test.ts` in `@valbuild/tanstack` fails when it is not.
18
+ */
19
+ import type { ValConfig, ValModules } from "@valbuild/core";
20
+ import type { ValApiOptions } from "../ValRouter.js";
21
+ import type { ValRuntime } from "../valRuntime.js";
22
+ /**
23
+ * The runtime the draft readers read through: see `createValRuntime` in
24
+ * `../createValRuntime`. Loaded when it is first asked for -- by a draft read,
25
+ * since a visitor's read never asks -- because building it evaluates the data
26
+ * layer and everything that imports.
9
27
  */
10
- export { createValRuntime } from "../ValRouter.js";
28
+ export declare function createValRuntime(valModules: ValModules, route: string, opts: ValApiOptions, config: ValConfig): Promise<ValRuntime>;
11
29
  export { draftForRequest, readDraftChanges, serverDraftSource, } from "../draftReads.js";
12
- export type { DraftModuleRead } from "../draftReads.js";
13
- export { proposalAsBuilt, servingBuildOf, stagedAfterBuild, type ServingBuild, } from "../proposal.js";
14
- export { valRuntime, type ValRuntime } from "../valRuntime.js";
30
+ export type { DraftModuleRead, ReaderRuntime } from "../draftReads.js";
31
+ export { layeredSnapshot, proposalAsBuilt, readerSnapshot, servingBuildOf, stagedAfterBuild, type ServingBuild, } from "../proposal.js";
32
+ export type { ValRuntime } from "../valRuntime.js";
33
+ export type { ValApiOptions };
34
+ export { serverCanStartLazily } from "../serverMode.js";
35
+ export { InMemoryPatchStore, type StoredFile, type StoredPatch, type ValPatchStore, } from "../ValPatchStore.js";
36
+ export { createPrettierFormatter, type PrettierLike, type PrettierLoader, type ValFormatter, } from "../createPrettierFormatter.js";
15
37
  export { ValHead, headWork, HEAD_BUDGET_BYTES, HEAD_VERSIONS_PER_MODULE, type Draft, type HeadChain, type HeadEntries, type HeadModule, type HeadTree, type ModuleAnswer, } from "../head.js";
@@ -1,5 +1,4 @@
1
1
  import { type Json, type ModuleFilePath } from "@valbuild/core";
2
- import type { JSONValue } from "@valbuild/core/patch";
3
2
  import { STAGED_SCHEMA_PREFIX } from "@valbuild/shared/internal";
4
3
  /**
5
4
  * A proposal this server runs at the address of: an editor-managed branch of
@@ -192,29 +191,18 @@ export declare function proposalAsBuilt<P extends Pick<ValProposal, "modules" |
192
191
  */
193
192
  export declare function proposalSnapshot(proposal: Pick<ValProposal, "modules">): Record<ModuleFilePath, Json>;
194
193
  /**
195
- * The `.jsonValues()` entries the proposal saved, by module and key.
194
+ * `proposalSnapshotForReaders`, loading the compiler only when the snapshot
195
+ * needs it: what the server-side readers render over the bundle.
196
196
  *
197
- * An entry's content is not in its module's Source -- that holds a marker per
198
- * entry -- but in the entry's own `*.val.json`, and a save writes that file:
199
- * it reaches the proposal's address as saved TEXT ({@link ValProposal.files}),
200
- * not as Source. So the snapshot alone shows the build's entries. This is the
201
- * other half: each saved `*.val.json`, read as the entry its module names.
202
- *
203
- * Which entry a file is comes from the module's `.val.ts`, whose
204
- * `c.json(() => import("..."))` thunks name the files -- the saved text if
205
- * the save rewrote it, else the build's own (`projectSource`). An entry whose
206
- * module cannot be read that way is left to the build, as before: this adds
207
- * what it can find and never fails the address.
208
- */
209
- export declare function proposalJsonEntries(proposal: Pick<ValProposal, "modules" | "files">, projectSource?: Record<string, string>): Map<ModuleFilePath, Map<string, JSONValue>>;
210
- /**
211
- * The snapshot as a page reads it: {@link proposalSnapshot}, with each saved
212
- * `.jsonValues()` entry's content in place of its marker -- the shape a draft
213
- * already has, where the entries it edits hold content and the rest are
214
- * markers the readers resolve from the build. See {@link proposalJsonEntries}.
215
- *
216
- * For the readers only. Val's own server keeps the markers
217
- * ({@link proposalSnapshot}): its patching works on them, and it takes the
218
- * saved entries separately.
197
+ * A saved `.jsonValues()` entry is found through its module's `.val.ts`, which
198
+ * takes TypeScript to read (`./proposalJsonEntries`). Without one -- every
199
+ * site serving published content, and a proposal or content version that saved
200
+ * no entry -- the snapshot is {@link proposalSnapshot} and nothing is loaded:
201
+ * the readers are on every page's path, and a cold isolate pays for every
202
+ * module it evaluates.
219
203
  */
220
- export declare function proposalSnapshotForReaders(proposal: Pick<ValProposal, "modules" | "files">, projectSource?: Record<string, string>): Record<ModuleFilePath, Json>;
204
+ export declare function readerSnapshot(proposal: Pick<ValProposal, "modules" | "files">, projectSource?: Record<string, string>): Promise<Record<ModuleFilePath, Json>>;
205
+ /** A plain object: not `null`, not an array. */
206
+ export declare function isObject(value: unknown): value is Record<string, unknown>;
207
+ /** What `JSON.parse` can produce, checked rather than assumed. */
208
+ export declare function isJsonValue(value: unknown): value is Json;
@@ -0,0 +1,30 @@
1
+ import type { Json, ModuleFilePath } from "@valbuild/core";
2
+ import type { JSONValue } from "@valbuild/core/patch";
3
+ import { type ValProposal } from "./proposal.js";
4
+ /**
5
+ * The `.jsonValues()` entries the proposal saved, by module and key.
6
+ *
7
+ * An entry's content is not in its module's Source -- that holds a marker per
8
+ * entry -- but in the entry's own `*.val.json`, and a save writes that file:
9
+ * it reaches the proposal's address as saved TEXT ({@link ValProposal.files}),
10
+ * not as Source. So the snapshot alone shows the build's entries. This is the
11
+ * other half: each saved `*.val.json`, read as the entry its module names.
12
+ *
13
+ * Which entry a file is comes from the module's `.val.ts`, whose
14
+ * `c.json(() => import("..."))` thunks name the files -- the saved text if
15
+ * the save rewrote it, else the build's own (`projectSource`). An entry whose
16
+ * module cannot be read that way is left to the build, as before: this adds
17
+ * what it can find and never fails the address.
18
+ */
19
+ export declare function proposalJsonEntries(proposal: Pick<ValProposal, "modules" | "files">, projectSource?: Record<string, string>): Map<ModuleFilePath, Map<string, JSONValue>>;
20
+ /**
21
+ * The snapshot as a page reads it: {@link proposalSnapshot}, with each saved
22
+ * `.jsonValues()` entry's content in place of its marker -- the shape a draft
23
+ * already has, where the entries it edits hold content and the rest are
24
+ * markers the readers resolve from the build. See {@link proposalJsonEntries}.
25
+ *
26
+ * For the readers only. Val's own server keeps the markers
27
+ * ({@link proposalSnapshot}): its patching works on them, and it takes the
28
+ * saved entries separately.
29
+ */
30
+ export declare function proposalSnapshotForReaders(proposal: Pick<ValProposal, "modules" | "files">, projectSource?: Record<string, string>): Record<ModuleFilePath, Json>;
@@ -0,0 +1,31 @@
1
+ import type { ValApiOptions } from "./ValRouter.js";
2
+ /** Which mode the environment SAYS this is, and which variable said so. */
3
+ export type NamedMode = {
4
+ mode: string;
5
+ from: "VAL_MODE" | "VAL_ENV";
6
+ };
7
+ /**
8
+ * `null` is "the environment did not say", which is the normal case.
9
+ *
10
+ * The two variables differ in what can be DONE with an answer, and the
11
+ * difference is whether the environment holds everything the mode needs.
12
+ * `http` does -- an api key, a secret, a project, a commit and a branch are all
13
+ * env vars -- so `VAL_ENV=app` SELECTS it, and the checks in
14
+ * {@link initHandlerOptions} name whichever one is missing. `memory` does not:
15
+ * it needs the host's own source files, which nothing in an environment can
16
+ * supply, so `VAL_MODE=memory` can only ever turn a fall-through into an error.
17
+ */
18
+ export declare function namedMode(): NamedMode | null;
19
+ /**
20
+ * Whether these options select `http` mode, as `initHandlerOptions` decides
21
+ * it: a mode of "proxy", the Val app's environment, or a credential with no
22
+ * mode given. `sourceFiles` (memory mode) is decided before this is asked,
23
+ * and the environment's refusals are `initHandlerOptions`'s to throw.
24
+ */
25
+ export declare function selectsHttpMode(opts: Pick<ValApiOptions, "mode" | "apiKey" | "valSecret">, declared?: NamedMode | null): boolean;
26
+ /**
27
+ * Whether a server with these options can be built at its first request
28
+ * rather than when the app starts: only in `http` mode, for the reason at
29
+ * the top of this file. Memory mode is selected by `sourceFiles` alone.
30
+ */
31
+ export declare function serverCanStartLazily(opts: Pick<ValApiOptions, "sourceFiles" | "mode" | "apiKey" | "valSecret">): boolean;