@valbuild/server 0.150.23 → 0.152.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 (66) hide show
  1. package/CHANGELOG.md +341 -0
  2. package/browser/dist/valbuild-server-browser.cjs.dev.js +5 -137
  3. package/browser/dist/valbuild-server-browser.cjs.prod.js +5 -137
  4. package/browser/dist/valbuild-server-browser.esm.js +4 -140
  5. package/dist/ValRouter-05fcb0da.esm.js +14663 -0
  6. package/dist/ValRouter-afcba447.cjs.dev.js +14759 -0
  7. package/dist/ValRouter-b4e5b412.cjs.prod.js +14759 -0
  8. package/dist/{ValRouterCore-0c7ae881.cjs.prod.js → ValRouterCore-a0ea46bf.cjs.prod.js} +3324 -1883
  9. package/dist/{ValRouterCore-5b6cccd4.esm.js → ValRouterCore-b5d70504.esm.js} +3316 -1879
  10. package/dist/{ValRouterCore-cfa7b001.cjs.dev.js → ValRouterCore-d16c3327.cjs.dev.js} +3324 -1883
  11. package/dist/declarations/src/ValOps.d.ts +334 -70
  12. package/dist/declarations/src/ValOpsFS.d.ts +32 -0
  13. package/dist/declarations/src/ValOpsHttp.d.ts +93 -3
  14. package/dist/declarations/src/ValOpsMemory.d.ts +22 -47
  15. package/dist/declarations/src/ValRouter.d.ts +10 -0
  16. package/dist/declarations/src/ValServer.d.ts +0 -10
  17. package/dist/declarations/src/browser/inTabFetch.d.ts +19 -2
  18. package/dist/declarations/src/draftOverlay.d.ts +51 -0
  19. package/dist/declarations/src/draftReads.d.ts +103 -0
  20. package/dist/declarations/src/head.d.ts +312 -0
  21. package/dist/declarations/src/history/getJsonEntryAtCommit.d.ts +52 -0
  22. package/dist/declarations/src/index.d.ts +1 -0
  23. package/dist/declarations/src/internal/browser/index.d.ts +11 -0
  24. package/dist/declarations/src/internal/index.d.ts +15 -0
  25. package/dist/declarations/src/patch/jsonValuesPatch.d.ts +2 -165
  26. package/dist/declarations/src/patch/ts/jsonValuesModule.d.ts +38 -0
  27. package/dist/declarations/src/patch/ts/loadTypeScriptKit.d.ts +14 -0
  28. package/dist/declarations/src/patch/ts/ops.d.ts +45 -0
  29. package/dist/declarations/src/patch/ts/publishKit.d.ts +26 -0
  30. package/dist/declarations/src/platform.d.ts +14 -0
  31. package/dist/declarations/src/proposal.d.ts +54 -3
  32. package/dist/declarations/src/valRuntime.d.ts +35 -0
  33. package/dist/draftReads-05415ff6.cjs.dev.js +366 -0
  34. package/dist/draftReads-5f99edd3.esm.js +361 -0
  35. package/dist/draftReads-ea3946e0.cjs.prod.js +366 -0
  36. package/dist/inTabFetch-095bb2be.cjs.prod.js +179 -0
  37. package/dist/inTabFetch-2cbbfaa4.cjs.dev.js +179 -0
  38. package/dist/inTabFetch-91c3e85e.esm.js +176 -0
  39. package/dist/{getJsonEntryAtCommit-d9b5f753.cjs.dev.js → publishKit-4e2b0014.cjs.dev.js} +55 -6
  40. package/dist/{getJsonEntryAtCommit-acf8c269.cjs.prod.js → publishKit-6e52ffa6.cjs.prod.js} +55 -6
  41. package/dist/{getJsonEntryAtCommit-8ff81ef5.esm.js → publishKit-af14cd7a.esm.js} +48 -5
  42. package/dist/valbuild-server.cjs.dev.js +160 -13319
  43. package/dist/valbuild-server.cjs.prod.js +160 -13319
  44. package/dist/valbuild-server.esm.js +34 -13174
  45. package/internal/browser/dist/valbuild-server-internal-browser.cjs.d.ts +2 -0
  46. package/internal/browser/dist/valbuild-server-internal-browser.cjs.dev.js +19 -0
  47. package/internal/browser/dist/valbuild-server-internal-browser.cjs.js +7 -0
  48. package/internal/browser/dist/valbuild-server-internal-browser.cjs.prod.js +19 -0
  49. package/internal/browser/dist/valbuild-server-internal-browser.esm.js +10 -0
  50. package/internal/browser/package.json +4 -0
  51. package/internal/dist/valbuild-server-internal.cjs.d.ts +2 -0
  52. package/internal/dist/valbuild-server-internal.cjs.dev.js +43 -0
  53. package/internal/dist/valbuild-server-internal.cjs.js +7 -0
  54. package/internal/dist/valbuild-server-internal.cjs.prod.js +43 -0
  55. package/internal/dist/valbuild-server-internal.esm.js +24 -0
  56. package/internal/package.json +4 -0
  57. package/package.json +17 -6
  58. package/dist/jsonValuesModule-235bd751.cjs.dev.js +0 -326
  59. package/dist/jsonValuesModule-23eb6f53.esm.js +0 -310
  60. package/dist/jsonValuesModule-625ebae8.cjs.prod.js +0 -326
  61. package/dist/ops-0e54b388.cjs.prod.js +0 -361
  62. package/dist/ops-9ca2ef2a.cjs.dev.js +0 -361
  63. package/dist/ops-b904007e.esm.js +0 -353
  64. package/dist/publishKit-34f71e50.cjs.dev.js +0 -42
  65. package/dist/publishKit-65e9e564.cjs.prod.js +0 -42
  66. package/dist/publishKit-7441c0fd.esm.js +0 -31
@@ -0,0 +1,312 @@
1
+ import { type Json, type ModuleFilePath, type PatchId } from "@valbuild/core";
2
+ import type { SerializedSchema } from "@valbuild/core";
3
+ import type { ReadonlyJSONValue } from "@valbuild/core/patch";
4
+ import { type EntryVersion, type MemoryTierStats, type ModuleVersion, type PatchRecord, type ProjectVersion, type StoredModule } from "@valbuild/shared/internal";
5
+ import type { GenericErrorMessage, OrderedPatches, PatchAnalysis, ValOps } from "./ValOps.js";
6
+ /**
7
+ * What the head may hold beyond what the build holds anyway: 16 MB, about
8
+ * where a deployed isolate beside 64 MB of other heap stopped outliving a
9
+ * validated whole-tree draft read (`scenarios/measure/results.md`, "The
10
+ * deployed isolate").
11
+ */
12
+ export declare const HEAD_BUDGET_BYTES: number;
13
+ /** The current version of each module and the one before it. */
14
+ export declare const HEAD_VERSIONS_PER_MODULE = 2;
15
+ /**
16
+ * Counted work, in this process, for every head: never reset, so two readers
17
+ * of it cannot disturb each other. A test takes it before and after.
18
+ */
19
+ declare const counted: {
20
+ /** "Has the chain moved?" asked. */
21
+ seqReads: number;
22
+ /** The chain fetched, because it had. */
23
+ chainReads: number;
24
+ /** Modules made from a base or an older version. */
25
+ materialized: number;
26
+ /** Of those, made by extending the version before by the new patches alone. */
27
+ extended: number;
28
+ /**
29
+ * A record's whole key list walked: once per record object (a base, a
30
+ * version), never per request -- see {@link recordKeysOf}.
31
+ */
32
+ recordScans: number;
33
+ /** `.jsonValues()` entries resolved: once per entry and version. */
34
+ entriesResolved: number;
35
+ };
36
+ /**
37
+ * A record's keys, in order: walked once per record OBJECT and kept beside
38
+ * it. A record is immutable (a base, or a version the engine made), so the
39
+ * same object has the same keys for good -- and an entry request, which only
40
+ * needs the count (`total`) or a window of them, costs what it asks for,
41
+ * not the size of the record. Before, every `GET /json` walked the whole
42
+ * record (`Object.keys`), so reading 10,000 entries one request at a time
43
+ * was 10,000 x 10,000 (phase 10's baseline).
44
+ */
45
+ export declare function recordKeysOf(record: object): readonly string[];
46
+ /** See {@link counted}. */
47
+ export declare function headWork(): Readonly<typeof counted>;
48
+ /** The chain, as the head last read it. */
49
+ export type HeadChain = {
50
+ /** The `seq` it was read at, when the store keeps one; `null`: always re-read. */
51
+ readonly seq: number | null;
52
+ /** What {@link seq} counts from (`ValOps.chainPosition`). */
53
+ readonly epoch: string;
54
+ /** The base it is relative to (`sourcesSha`): a publish moves it. */
55
+ readonly base: string;
56
+ readonly project: ProjectVersion;
57
+ /** As fetched, ops and all. */
58
+ readonly fetched: OrderedPatches;
59
+ /** What a draft applies, in chain order (`draftOverlay`). */
60
+ readonly overlay: OrderedPatches["patches"];
61
+ readonly byModule: ReadonlyMap<ModuleFilePath, readonly PatchRecord[]>;
62
+ /** Every module's version at the whole of its chain. */
63
+ readonly versions: Readonly<Record<ModuleFilePath, ModuleVersion>>;
64
+ readonly analysis: PatchAnalysis;
65
+ };
66
+ export type HeadError = {
67
+ message: string;
68
+ unauthorized?: boolean;
69
+ networkError?: boolean;
70
+ };
71
+ export type HeadResult<T> = {
72
+ ok: T;
73
+ } | {
74
+ error: HeadError;
75
+ };
76
+ /** A module as the head answers it. */
77
+ export type HeadModule = {
78
+ readonly module: StoredModule;
79
+ /** The version at the whole chain: what was asked for. */
80
+ readonly asked: ModuleVersion;
81
+ readonly failed: {
82
+ patchId: PatchId;
83
+ message: string;
84
+ } | null;
85
+ readonly applied: number;
86
+ /** The module's patches in the chain, applied or not. */
87
+ readonly records: readonly PatchRecord[];
88
+ };
89
+ /**
90
+ * What a draft reader is given for a module: the bundle's own (read the
91
+ * bundle), or the head's source in its wire shape -- `.jsonValues()` markers
92
+ * without their `import()`, and the entries the draft changes in place of
93
+ * theirs.
94
+ */
95
+ export type Draft = {
96
+ kind: "bundle";
97
+ version: ModuleVersion;
98
+ } | {
99
+ kind: "draft";
100
+ version: ModuleVersion;
101
+ source: Json;
102
+ /**
103
+ * Whether a draft changes it: a patch in its chain, or an entry a
104
+ * publish wrote that the bundle does not have yet. A module that is
105
+ * neither and still not the bundle's is a content version's or a
106
+ * proposal's base.
107
+ */
108
+ changed: boolean;
109
+ /** The entries it changes could not all be read: `source` has markers. */
110
+ entriesFailed: boolean;
111
+ };
112
+ /** One entry, as `/json` and the draft readers answer it. */
113
+ export type HeadEntries = {
114
+ entries: {
115
+ key: string;
116
+ content: ReadonlyJSONValue | null;
117
+ }[];
118
+ missing: string[];
119
+ errors: {
120
+ key: string;
121
+ message: string;
122
+ }[];
123
+ total: number;
124
+ version: ModuleVersion;
125
+ /** Each read entry's own version. */
126
+ entryVersions: Record<string, EntryVersion>;
127
+ };
128
+ export declare class ValHead {
129
+ private readonly ops;
130
+ private readonly memory;
131
+ private readonly store;
132
+ private readonly facts;
133
+ private chain;
134
+ private fetching;
135
+ private serialized;
136
+ private wholeTree;
137
+ constructor(ops: ValOps, opts?: {
138
+ budgetBytes?: number;
139
+ lastPerModule?: number;
140
+ });
141
+ /** What the head holds now. */
142
+ stats(): MemoryTierStats;
143
+ /**
144
+ * The chain, re-read only when `seq` moved (or the base did: a publish
145
+ * adopted). A read that finds a fetch already under way at the `seq` it
146
+ * saw joins it: that fetch reads at that `seq` or later.
147
+ *
148
+ * Asks "has the chain moved?" once per call -- in http mode one request to
149
+ * the content service. A caller that reads several modules for ONE answer
150
+ * (a draft page's request) syncs once and passes the chain it got to
151
+ * {@link draft}, {@link entries} and {@link changed}, so a page of thirty
152
+ * modules asks once, not thirty times, and reads all of them at one chain.
153
+ */
154
+ sync(): Promise<HeadResult<HeadChain>>;
155
+ /** The chain a read is answered at: the one given, or the newest. */
156
+ private at;
157
+ private fetchChain;
158
+ /**
159
+ * Every module's serialized schema, serialized once per data layer (a new
160
+ * build is a new one): what the engine reads `.jsonValues()` records from,
161
+ * and MCP's tools their schemas.
162
+ */
163
+ serializedSchemas(): Promise<Record<ModuleFilePath, SerializedSchema | undefined>>;
164
+ /**
165
+ * A module at the newest chain (or at `chain`, from {@link sync}), or
166
+ * `null` when there is no such module.
167
+ */
168
+ module(path: ModuleFilePath, chain?: HeadChain): Promise<HeadResult<HeadModule | null>>;
169
+ private moduleIn;
170
+ /**
171
+ * A module at `asked`, from the newest version held of the same base when
172
+ * its chain is a start of this one (a keystroke: the new patch alone), and
173
+ * from its base otherwise (a discard, a publish, an eviction).
174
+ */
175
+ private make;
176
+ private factsOf;
177
+ /**
178
+ * `.jsonValues()` entries at the newest chain (or at `chain`, from
179
+ * {@link sync}), by key: what the module's chain made of each, and for an
180
+ * entry it holds edits for but nobody has loaded, those edits on the base
181
+ * entry. Made once per entry and version.
182
+ */
183
+ entries(path: ModuleFilePath, keys: readonly string[], chain?: HeadChain): Promise<HeadEntriesResult>;
184
+ private entriesIn;
185
+ /**
186
+ * An entry on `module`, resolved once and kept on it -- unless it could
187
+ * not be read (`transient`): that is tried again on the next read rather
188
+ * than kept for the version's life.
189
+ */
190
+ private resolved;
191
+ private resolve;
192
+ /**
193
+ * A module as a draft reader is given it ({@link Draft}): `bundle` when the
194
+ * newest version is the bundle's own -- the reader's bundle answers, and
195
+ * nothing is read -- and otherwise the head's, made once per version.
196
+ */
197
+ draft(path: ModuleFilePath, chain?: HeadChain): Promise<HeadResult<Draft | null>>;
198
+ /**
199
+ * The draft of `held`, its entries read at `chain` -- the chain `held` was
200
+ * made at, so the entries are the same version's even when the chain has
201
+ * moved since.
202
+ */
203
+ private makeDraft;
204
+ /**
205
+ * The modules a draft changes: a patch in their chain, or an entry a
206
+ * publish wrote that the bundle has not got. What `fetchValDraft` sends.
207
+ */
208
+ changed(at?: HeadChain): Promise<HeadResult<ModuleFilePath[]>>;
209
+ /** {@link changed}, made once per chain: it looks at every record's markers. */
210
+ private changedIn;
211
+ private changedOf;
212
+ /**
213
+ * Every module at the newest chain: the patched ones made (once per
214
+ * version), the rest the base's own objects. What `PUT /sources/~` and
215
+ * MCP read; made once per chain.
216
+ */
217
+ tree(): Promise<HeadResult<HeadTree>>;
218
+ private makeTree;
219
+ /**
220
+ * `GET /modules`: one module at a version. `v` the version wanted (by
221
+ * default the newest); `have` the version the caller holds, from which the
222
+ * answer is a delta -- the patches from it -- when the caller's chain is a
223
+ * start of this one under the same schema and base.
224
+ */
225
+ answer(path: ModuleFilePath, opts: {
226
+ v?: string;
227
+ have?: string;
228
+ }): Promise<HeadResult<ModuleAnswer | {
229
+ kind: "not-held";
230
+ current: ModuleVersion;
231
+ } | null>>;
232
+ }
233
+ /** What {@link ValHead.entries} answers. */
234
+ export type HeadEntriesResult = {
235
+ status: "success";
236
+ value: HeadEntries;
237
+ } | {
238
+ status: "not-found";
239
+ message: string;
240
+ } | {
241
+ status: "error";
242
+ message: string;
243
+ };
244
+ /**
245
+ * Whether an answer of {@link ValHead.answer} is the same for good, so an
246
+ * answer for an asked version may be cached as immutable: not when an
247
+ * entry's content could not be READ (it carries no `patchId`; its base's
248
+ * `import()` failed, and the next read may succeed). An entry a patch could
249
+ * not be applied to names that patch, and is the version's for good.
250
+ */
251
+ export declare function isLastingAnswer(answer: ModuleAnswer): boolean;
252
+ /** What {@link ValHead.tree} answers. */
253
+ export type HeadTree = {
254
+ chain: HeadChain;
255
+ sources: Record<ModuleFilePath, Json>;
256
+ errors: Record<ModuleFilePath, {
257
+ patchId: PatchId;
258
+ skipped: boolean;
259
+ error: GenericErrorMessage;
260
+ }[]>;
261
+ /** For a module whose chain stopped: how many of its patches applied. */
262
+ stopped: Record<ModuleFilePath, number>;
263
+ /** Each module's version as answered: where its chain stopped, if it did. */
264
+ versions: Record<ModuleFilePath, ModuleVersion>;
265
+ };
266
+ export type ModuleAnswerEntries = Record<string, {
267
+ content: Json;
268
+ version: EntryVersion;
269
+ } | {
270
+ deleted: true;
271
+ version: EntryVersion;
272
+ } | {
273
+ error: string;
274
+ /** The patch that made it unreadable, when known. */
275
+ patchId?: PatchId;
276
+ version: EntryVersion;
277
+ }>;
278
+ /** What `GET /modules` answers: see `ModuleAnswer` in the plan. */
279
+ export type ModuleAnswer = {
280
+ kind: "module";
281
+ version: ModuleVersion;
282
+ /** `.jsonValues()` markers without their `import()`. */
283
+ source: Json;
284
+ /** The entries its chain touched, read. Every other entry is the base's. */
285
+ entries: ModuleAnswerEntries;
286
+ /**
287
+ * The patch ids its chain is made of, in chain order: what a client
288
+ * holding it knows the server already has (the Studio's own edits
289
+ * beyond them are its local layer, `withLocalEdits`).
290
+ */
291
+ patches: PatchId[];
292
+ /** Where its chain stopped, when a patch did not apply. */
293
+ failed?: {
294
+ patchId: PatchId;
295
+ message: string;
296
+ };
297
+ } | {
298
+ kind: "delta";
299
+ from: ModuleVersion;
300
+ to: ModuleVersion;
301
+ patches: PatchRecord[];
302
+ };
303
+ /**
304
+ * What `next` holds that `base` does not: every container copy-on-write made
305
+ * (8 bytes a slot, as the engine counts them) and every string a patch
306
+ * brought, walking only where the two differ -- a subtree the patches did not
307
+ * touch is the base's own object, which the build holds anyway. A child that
308
+ * is one of the base container's own children (moved, or shifted by an
309
+ * insert) costs nothing. What the head's byte budget is measured in.
310
+ */
311
+ export declare function heldBeyond(base: unknown, next: unknown): number;
312
+ export {};
@@ -0,0 +1,52 @@
1
+ import { ModuleFilePath } from "@valbuild/core";
2
+ import { result } from "@valbuild/core/fp";
3
+ import type { Json } from "@valbuild/core";
4
+ import type { ValOps } from "../ValOps.js";
5
+ import type { HistoryError } from "./HistoryError.js";
6
+ /**
7
+ * One `.jsonValues()` entry's content, as it was at a commit.
8
+ *
9
+ * The history pane renders a commit through the real field components, and a
10
+ * `.jsonValues()` record's source is only `{_type:"json"}` markers - the
11
+ * content lives in a separate `*.val.json` per entry, fetched on demand. The
12
+ * live Studio fetches it from `GET /json`; the commit pane had nothing to
13
+ * fetch from, so every entry stayed a marker and rendered as though the field
14
+ * were empty. Which is worse than an error: an empty value is a claim, and it
15
+ * was a false one.
16
+ *
17
+ * ## Why this needs the module's own `.val.ts`
18
+ *
19
+ * There is no derivable relationship between a record key and its entry file.
20
+ * From the example app:
21
+ *
22
+ * "/support/getting-started": c.json(() => import("./content/getting-started.val.json"))
23
+ * "/support/faq": c.json(() => import("./content/faq.val.json"))
24
+ *
25
+ * The key is a route and the path is whatever the author wrote. The only place
26
+ * the two are related is the `import()` literal inside the `.val.ts`, which is
27
+ * why `findJsonEntryFilePathsInSource` reads them out of the AST too. The
28
+ * commit archive stores the module's SOURCE (the markers) and its schema, not
29
+ * its text - so the text is fetched from git at that commit and parsed here.
30
+ *
31
+ * Two round trips per entry, then: the module, and the entry. The module's
32
+ * parse is worth caching per (commit, module) by the caller; nothing here does,
33
+ * because a `ValOps` is not a cache and the endpoint above it is the layer that
34
+ * knows how long a commit stays interesting.
35
+ */
36
+ export declare function getJsonEntryAtCommit(ops: ValOps, commitSha: string, moduleFilePath: ModuleFilePath, key: string): Promise<result.Result<Json, HistoryError>>;
37
+ /**
38
+ * The `import()` path a key's entry is behind, from the module's text.
39
+ *
40
+ * Exported for its own test: this is the part with a real chance of being
41
+ * wrong, and it is pure.
42
+ */
43
+ export declare function findEntryImportPath(moduleFilePath: ModuleFilePath,
44
+ /**
45
+ * The same module, repository-relative, for error reporting only.
46
+ *
47
+ * A `gitPath` in a HistoryError is a REPOSITORY path - that is what every
48
+ * other history helper reports, and what a reader can paste into a `git show`
49
+ * - so reporting the project-relative ModuleFilePath here named a file that
50
+ * does not exist at that path for any project not rooted at the repo root.
51
+ */
52
+ moduleGitPath: string, valTsSource: string, key: string): result.Result<string, HistoryError>;
@@ -50,6 +50,7 @@ export type { ModulePathMap } from "./modulePathMap.js";
50
50
  export { ValOpsFS } from "./ValOpsFS.js";
51
51
  export { ValOpsHttp } from "./ValOpsHttp.js";
52
52
  export { ValOpsMemory, InMemoryPatchStore, type ValPatchStore, type StoredPatch, type ValOpsMemoryOptions, } from "./ValOpsMemory.js";
53
+ export { loadTypeScriptKit, type TypeScriptKit, } from "./patch/ts/loadTypeScriptKit.js";
53
54
  export { loadValModules, createValModuleFileInspector, findDefaultExport, } from "./loadValModules.js";
54
55
  export type { ValModuleFileInspection } from "./loadValModules.js";
55
56
  export { formatPatchSourceError } from "./ValOps.js";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * `@valbuild/server/internal/browser`: the in-tab server's internals, for the
3
+ * isolate probe (`scenarios/measure/isolate/`). Not public API.
4
+ *
5
+ * Bundleable for a browser, like `@valbuild/server/browser`:
6
+ * `noNodeFromBrowser.test.ts` walks this entry too.
7
+ */
8
+ export { createInTabVal, type InTabValOptions } from "../../browser/inTabFetch.js";
9
+ export { serverDraftSource } from "../../draftReads.js";
10
+ export type { ValRuntime } from "../../valRuntime.js";
11
+ export type { ValHead } from "../../head.js";
@@ -0,0 +1,15 @@
1
+ /**
2
+ * `@valbuild/server/internal`: what `@valbuild/next`, `@valbuild/tanstack`,
3
+ * `@valbuild/mcp` and the scenarios share of the server, and nothing an app
4
+ * should import. Not public API: it changes without a major version.
5
+ *
6
+ * The runtime every server and reader in a process shares (`valRuntime`,
7
+ * `createValRuntime`), its head (`ValHead`), and the draft the server-side
8
+ * readers read from it (`draftForRequest` and friends).
9
+ */
10
+ export { createValRuntime } from "../ValRouter.js";
11
+ export { draftForRequest, readDraftChanges, readerSchemaVersion, serverDraftSource, } from "../draftReads.js";
12
+ export type { DraftModuleRead } from "../draftReads.js";
13
+ export { proposalAsBuilt, stagedAfterBuild } from "../proposal.js";
14
+ export { valRuntime, type ValRuntime } from "../valRuntime.js";
15
+ 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,103 +1,7 @@
1
- import { type PatchId, type SerializedSchema } from "@valbuild/core";
1
+ import { type SerializedSchema } from "@valbuild/core";
2
2
  import type { PatchSourceError } from "../ValOps.js";
3
3
  import { result } from "@valbuild/core/fp";
4
- import { JSONValue, Operation, Patch, PatchError } from "@valbuild/core/patch";
5
- /**
6
- * Classification of a single patch op against a module's serialized schema,
7
- * used by the commit flow to route ops for `.jsonValues()` records:
8
- *
9
- * - `normal`: the op does not descend into a `.jsonValues()` entry; apply it to
10
- * the `.val.ts` as usual.
11
- * - `entry`: the op targets a `.jsonValues()` entry. `recordPath` is the path to
12
- * the record within the module source (empty for a root record/router),
13
- * `entryKey` is the entry key, and `subPath` is the remaining path inside the
14
- * entry (empty when the op targets the entry value itself, e.g. add/remove of
15
- * the whole entry).
16
- */
17
- export type JsonValuesOpClass = {
18
- kind: "normal";
19
- } | {
20
- kind: "entry";
21
- recordPath: string[];
22
- entryKey: string;
23
- subPath: string[];
24
- };
25
- /**
26
- * Walks the serialized schema following the op path. When a `.jsonValues()`
27
- * record is encountered, the next path segment is the entry key and everything
28
- * after it lives inside the entry's `*.val.json` (so it does not touch the
29
- * `.val.ts`). Returns `{ kind: "normal" }` when the op never enters a
30
- * `.jsonValues()` record.
31
- */
32
- export declare function classifyJsonValuesOp(schema: SerializedSchema, opPath: string[]): JsonValuesOpClass;
33
- /**
34
- * Is this op a write of the WHOLE record at the root of a `.jsonValues()`
35
- * module?
36
- *
37
- * The one op {@link classifyJsonValuesOp} cannot classify: it finds the entry
38
- * key by walking the op path, and the root path has no segments to walk, so a
39
- * root write reads as `normal` and gets applied to the `.val.ts` - writing
40
- * markers over the `c.json(() => import(...))` calls that make the entries load
41
- * at all. {@link expandJsonValuesRootOp} turns it into ops that DO name a key,
42
- * which everything downstream already handles.
43
- *
44
- * `add` counts as well as `replace`: at the root both mean "the document is now
45
- * this" (see `JSONOps`), so both have to be expanded or the unexpanded one is
46
- * the same bug again.
47
- *
48
- * The value has to BE a record, and that is part of the question rather than a
49
- * check inside the expansion: a `.jsonValues()` record can be nullable, and
50
- * `null` at the root means the module no longer has a record at all - there are
51
- * no entries to write, and it is an ordinary `.val.ts` write, exactly as it was
52
- * before any of this existed. Same for any other non-record value: not a
53
- * whole-record write, so not this conversion's to route.
54
- */
55
- export declare function isJsonValuesRootOp(schema: SerializedSchema, op: Operation): boolean;
56
- /**
57
- * One entry as it stands right now, for {@link expandJsonValuesRootOp} to
58
- * expand against.
59
- *
60
- * The key set decides add-vs-replace-vs-remove. The content, where the caller
61
- * has it, decides whether an op is emitted at all: an entry whose content is
62
- * already what the root write says is left alone rather than rewritten, so
63
- * putting a module back does not touch every `*.val.json` it did not change.
64
- * `undefined` means "this entry exists, content unknown" - which is what the
65
- * Studio's draft source has, because the source holds markers - and yields a
66
- * `replace`, the safe answer.
67
- */
68
- export type CurrentJsonEntries = ReadonlyMap<string, JSONValue | undefined>;
69
- /**
70
- * Fans a whole-record write at a `.jsonValues()` module's root out into ops
71
- * that each name an entry key.
72
- *
73
- * This is THE conversion, and it has exactly one implementation on purpose: the
74
- * commit flow (`ValOps.prepare`) and the read side that builds draft content
75
- * ({@link applyJsonValuesEntryPatches}) both expand through here, so a draft
76
- * cannot show something other than what publishing writes. A second
77
- * implementation of the same rule would differ silently, which is the whole
78
- * failure mode this exists to prevent.
79
- *
80
- * The value must be the entries' CONTENT. A module's Source is markers, not
81
- * content, so a Source handed over here is refused rather than written: that is
82
- * the shape of the original bug (a revert replaying the archived Source), and
83
- * it is not recoverable afterwards - the markers replace the entries' content
84
- * on disk.
85
- */
86
- export declare function expandJsonValuesRootOp(op: Operation, currentEntries: CurrentJsonEntries): result.Result<Operation[], PatchError>;
87
- /**
88
- * What a whole-record write says about ONE entry: the same rule
89
- * {@link expandJsonValuesRootOp} applies to all of them.
90
- *
91
- * For a reader that is about one entry. Expanding the whole record to find the
92
- * one op that names its key costs an op per entry per entry read - the record
93
- * squared, on exactly the large records this feature is for. The rule itself is
94
- * `writeForEntry`, shared with the expansion above, so the two cannot come to
95
- * disagree; only the loop around it differs.
96
- *
97
- * `null` means the write says nothing about this entry: it holds that content
98
- * already, or the record does not name it and it does not exist.
99
- */
100
- export declare function expandJsonValuesRootOpForKey(op: Operation, entryKey: string, currentEntries: CurrentJsonEntries): result.Result<Operation | null, PatchError>;
4
+ export { classifyJsonValuesOp, expandJsonValuesRootOp, expandJsonValuesRootOpForKey, isJsonValuesRootOp, rebaseContentOp, wholeEntryKey, type CurrentJsonEntries, type JsonValuesOpClass, } from "@valbuild/shared/internal";
101
5
  /**
102
6
  * Finds every `.jsonValues()` record in a module's schema that is NOT the
103
7
  * module's root, returning the path to each within the module source.
@@ -124,73 +28,6 @@ export declare function getNewJsonEntryPaths(moduleFilePath: string, entryKey: s
124
28
  jsonPath: string;
125
29
  importPath: string;
126
30
  }, PatchSourceError>;
127
- /**
128
- * Rebases a patch op that targets a `.jsonValues()` entry's content so its paths
129
- * are relative to the entry's `*.val.json` root (drops the record + entry-key
130
- * prefix). Used to replay the op against the backing JSON file.
131
- */
132
- export declare function rebaseContentOp(op: Operation, prefixLen: number): result.Result<Operation, PatchError>;
133
- /** The outcome of replaying pending patches onto one `.jsonValues()` entry. */
134
- export type JsonEntryResolution = {
135
- kind: "content";
136
- content: JSONValue | null;
137
- appliedPatchIds: PatchId[];
138
- } | {
139
- kind: "deleted";
140
- appliedPatchIds: PatchId[];
141
- } | {
142
- kind: "error";
143
- message: string;
144
- patchId?: PatchId;
145
- };
146
- /**
147
- * Replays the ops of `patches` that target ONE `.jsonValues()` entry onto its
148
- * committed content, yielding the entry's draft content.
149
- *
150
- * This is the read-side counterpart to the commit flow in `ValOps.prepare`:
151
- * both route ops with {@link classifyJsonValuesOp} and replay content sub-ops
152
- * with {@link rebaseContentOp}, but this one produces a value instead of files
153
- * and never touches the `.val.ts`.
154
- *
155
- * Root-only, like the rest of the `.jsonValues()` machinery: ops targeting a
156
- * nested record are ignored (nested `.jsonValues()` is rejected at startup).
157
- */
158
- export declare function applyJsonValuesEntryPatches(args: {
159
- serializedSchema: SerializedSchema | undefined;
160
- entryKey: string;
161
- /** `undefined` when the entry does not exist in the committed source. */
162
- baseContent: JSONValue | undefined;
163
- /** Ordered, already filtered to the entry's module. */
164
- patches: {
165
- patchId: PatchId;
166
- patch: Patch;
167
- }[];
168
- /**
169
- * The committed content of the OTHER entries of the record, for a
170
- * whole-entry `move` or `copy` into this key: its content is the source
171
- * entry's at that point in the chain, which is a different `*.val.json`.
172
- *
173
- * `undefined` for an entry the caller did not load, and then such an op is
174
- * an error, as it is when this is not given at all. `{ content: undefined }`
175
- * is an entry the committed source does not have.
176
- */
177
- baseContentOf?: (entryKey: string) => {
178
- content: JSONValue | undefined;
179
- } | undefined;
180
- /**
181
- * Replay only the ops before this one: patch index, then op index in it.
182
- * How a move's source is read as it stood when the move was made.
183
- */
184
- stopBefore?: {
185
- patch: number;
186
- op: number;
187
- };
188
- }): JsonEntryResolution;
189
- /**
190
- * The entry a path names when it names a WHOLE entry of the root
191
- * `.jsonValues()` record, and `undefined` for anything else.
192
- */
193
- export declare function wholeEntryKey(serializedSchema: SerializedSchema | undefined, path: string[]): string | undefined;
194
31
  /**
195
32
  * Resolves an EXISTING entry's `*.val.json` path (relative to rootDir) from the
196
33
  * `import(...)` path recorded in the `.val.ts` thunk (from
@@ -0,0 +1,38 @@
1
+ import ts from "typescript";
2
+ import { result } from "@valbuild/core/fp";
3
+ import type { JSONValue } from "@valbuild/core/patch";
4
+ import { type ValSyntaxErrorTree } from "./syntax.js";
5
+ export type JsonValuesEntry = {
6
+ /** The string literal inside `import("...")` in the entry's thunk. */
7
+ importPath: string;
8
+ };
9
+ /**
10
+ * Given the `source` object-literal expression of a `.jsonValues()` record /
11
+ * router (the 3rd argument to `c.define`, via {@link analyzeValModule}),
12
+ * extracts each entry's `c.json(() => import("..."))` import path, keyed by
13
+ * entry key. Entries whose value is not a `c.json(...)` call are skipped.
14
+ */
15
+ export declare function analyzeJsonValuesEntries(source: ts.Expression): Map<string, JsonValuesEntry>;
16
+ /**
17
+ * Every key of a `.jsonValues()` record's source literal, thunked or not.
18
+ *
19
+ * {@link analyzeJsonValuesEntries} answers "which entries have a file behind
20
+ * them", which is the question for resolving a path. This is the other one:
21
+ * which keys the record HAS. They differ on a value that is not a
22
+ * `c.json(...)` call - written inline, or mid-edit - and telling an existing
23
+ * key from a new one is what decides whether a whole-record write adds a
24
+ * `c.json(...)` thunk or replaces one. Using the thunk set for that would
25
+ * insert a second property with a key the literal already has.
26
+ */
27
+ export declare function jsonValuesRecordKeys(source: ts.Expression): string[];
28
+ /**
29
+ * The Source a `c.define(...)` literal declares, as a module's Source is
30
+ * stored: each `.jsonValues()` entry's `c.json(() => import("..."))` as the
31
+ * marker `{ _type: "json" }` its content stands behind, and every other value
32
+ * as written. An error for anything that is not a literal.
33
+ *
34
+ * What a staging records for a module (`stagedModuleSources`): without the
35
+ * markers, an entry the design tab added to a record was in the module's code
36
+ * and not in its Source, and an edit into it was undone.
37
+ */
38
+ export declare function evaluateModuleSource(source: ts.Expression): result.Result<JSONValue, ValSyntaxErrorTree>;
@@ -0,0 +1,14 @@
1
+ import type * as publishKit from "./publishKit.js";
2
+ /** What {@link loadTypeScriptKit} loads: see `publishKit.ts`. */
3
+ export type TypeScriptKit = typeof publishKit;
4
+ /**
5
+ * The TypeScript compiler's half of Val's server, loaded the first time a
6
+ * publish or the history reader asks for it rather than with the server.
7
+ *
8
+ * Node only, by where it is imported from rather than by what it imports:
9
+ * `nodePlatform`, `createValOps` and the two data layers that only run on
10
+ * Node (`ValOpsFS`, `ValOpsHttp`). Nothing the browser entry reaches may
11
+ * import this -- `noNodeFromBrowser.test.ts` follows the `import()` below,
12
+ * as a bundler does.
13
+ */
14
+ export declare function loadTypeScriptKit(): Promise<TypeScriptKit>;