@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
@@ -1,15 +1,16 @@
1
- import { MediaSource, FileMetadata, FileSource, ImageMetadata, ModuleFilePath, PatchId, Schema, SelectorSource, SerializedSchema, Source, SourcePath, ValConfig, ValModules, ValidationError } from "@valbuild/core";
1
+ import { MediaSource, FileMetadata, FileSource, ImageMetadata, type Json, ModuleFilePath, PatchId, Schema, SelectorSource, SerializedSchema, Source, SourcePath, ValConfig, ValModules, ValidationError } from "@valbuild/core";
2
2
  import { result } from "@valbuild/core/fp";
3
- import { JSONValue, ParentRef, Patch, PatchError } from "@valbuild/core/patch";
3
+ import { JSONValue, ParentRef, Patch, PatchError, ReadonlyJSONValue } from "@valbuild/core/patch";
4
4
  import type { HistoryError } from "./history/HistoryError.js";
5
- import type { PlanRefusalErrorT } from "@valbuild/shared/internal";
5
+ import type { BuildRegistry, PlanRefusalErrorT } from "@valbuild/shared/internal";
6
6
  import type { AffectedFile, StoredModuleVersion, CommitPage, CommitPatch, HistoricalCommit } from "./history/types.js";
7
+ import type { TypeScriptKit } from "./patch/ts/loadTypeScriptKit.js";
7
8
  import { type RemoteFilesCheck, type RemoteNetwork } from "./remoteFileCheck.js";
8
9
  import type { ValSyntaxError, ValSyntaxErrorTree } from "./patch/ts/syntax.js";
9
10
  import { ParentPatchId } from "@valbuild/core";
10
- import type { ReifiedPreview } from "@valbuild/core";
11
- import { ValCommit, ValDeployment } from "@valbuild/shared/internal";
11
+ import { ValCommit, ValDeployment, type ModuleVersion, type ProjectVersion } from "@valbuild/shared/internal";
12
12
  import type { SketchpadStore } from "./sketchpads/SketchpadStore.js";
13
+ import { ValHead } from "./head.js";
13
14
  export type BaseSha = string & {
14
15
  readonly _tag: unique symbol;
15
16
  };
@@ -68,6 +69,40 @@ export type ValOpsOptions = {
68
69
  * this instance would leave them (`proposalJsonEntries` in `./proposal`).
69
70
  */
70
71
  snapshotJsonEntries?: Map<ModuleFilePath, Map<string, JSONValue>>;
72
+ /**
73
+ * At a proposal's address: the modules whose staged code this build was
74
+ * NOT made of (`stagedAfterBuild` in `./proposal`), each with its schema
75
+ * version `staged:<inputs>`. This server has not got their schema, so:
76
+ *
77
+ * - their Source is read from their staged text ({@link readSources}),
78
+ * over the snapshot, not taken from what the build evaluated;
79
+ * - their version is the staging's, on every answer, so a reader whose code
80
+ * is this build never reads them for its own (`layered`'s schema rule);
81
+ * - a save applies to that text and that Source with no schema, and says
82
+ * so per module (`moduleVersions[path].staged`);
83
+ * - one whose Source cannot be read from its text is HELD: a save that
84
+ * touches it is refused, saying why (`heldStaged`, read by `prepare`).
85
+ */
86
+ stagedAfterBuild?: {
87
+ versions: Record<ModuleFilePath, string>;
88
+ /**
89
+ * The Source each staged module file declares, read without running it
90
+ * (`stagedModuleSources`): one it cannot read is left out.
91
+ */
92
+ readSources: () => Promise<Record<string, JSONValue>>;
93
+ };
94
+ /**
95
+ * The TypeScript compiler, for {@link ValOps.prepare}: a publish rewrites
96
+ * each `.val.ts` it touches as text. `loadTypeScriptKit` on Node.
97
+ *
98
+ * Passed in rather than imported, because this class runs in a browser tab
99
+ * and in a Worker too, where the compiler would be 10.8 MB of a 12.9 MB
100
+ * bundle that never publishes (see `publishKit.ts`). `ValOpsFS` and
101
+ * `ValOpsHttp` only run on Node and load it themselves; `ValOpsMemory` has
102
+ * it when its host passes it (`createValOps` does), and refuses to publish
103
+ * without it.
104
+ */
105
+ typescript?: () => Promise<TypeScriptKit>;
71
106
  };
72
107
  export declare abstract class ValOps {
73
108
  private readonly valModules;
@@ -134,6 +169,54 @@ export declare abstract class ValOps {
134
169
  * holding only the latest content per key.
135
170
  */
136
171
  private adoptedJsonEntries;
172
+ /**
173
+ * Each module's `schema` and `base` version: hashed when the modules are
174
+ * evaluated and when a base is adopted (a snapshot, a publish), never when
175
+ * they are read. See `ModuleVersion` in `@valbuild/shared/internal`.
176
+ */
177
+ private baseVersions;
178
+ /**
179
+ * The build this instance serves, as {@link ProjectVersion.build} names it:
180
+ * the fold of what the modules evaluated to, frozen at evaluation (a publish
181
+ * moves the base, not the build), unless the host names its build.
182
+ */
183
+ private buildVersion;
184
+ /** Every module's `chain`, folded as the chain grows. See `ChainFold`. */
185
+ private readonly chainFold;
186
+ /**
187
+ * The modules staged after the build whose Source could not be read from
188
+ * their staged text, with why: a save that touches one is refused. See
189
+ * {@link ValOpsOptions.stagedAfterBuild}.
190
+ */
191
+ private heldStaged;
192
+ /**
193
+ * What the BUILD evaluated each module to, and its version: before a
194
+ * snapshot, a staging or a publish put anything over it. What a reader's
195
+ * own bundle holds, so where the head's version is this one a draft reader
196
+ * reads its bundle and the head reads nothing (`ValHead.draft`).
197
+ */
198
+ private bundleSources;
199
+ private bundleVersions;
200
+ /**
201
+ * The head: the content at the newest chain, kept in a store of modules by
202
+ * version, which every reader in the process reads through. See
203
+ * `head.ts`.
204
+ */
205
+ readonly head: ValHead;
206
+ /**
207
+ * Take a formatter for saves, when this instance was built without one.
208
+ *
209
+ * One instance serves every Val server in a process (`valRuntime`), and
210
+ * the readers that build it first never save, so they pass no formatter;
211
+ * the API route that saves does. An instance that already has one keeps it.
212
+ */
213
+ adoptFormatter(formatter: NonNullable<ValOpsOptions["formatter"]>): void;
214
+ /**
215
+ * The TypeScript compiler, loading, or `null` where this server has none.
216
+ * See {@link ValOpsOptions.typescript}; the Node-only data layers override
217
+ * this to load it themselves.
218
+ */
219
+ protected loadTypeScriptKit(): Promise<TypeScriptKit> | null;
137
220
  constructor(valModules: ValModules, options?: ValOpsOptions | undefined);
138
221
  /**
139
222
  * Get the status from Val
@@ -172,6 +255,11 @@ export declare abstract class ValOps {
172
255
  }[];
173
256
  /** FS mode only — see the `params` counterpart. */
174
257
  jsonEntriesSha?: string;
258
+ /**
259
+ * The store's own `seq` (fs, memory), read before the patches it
260
+ * answers with. See `ProjectVersion` and {@link projectVersion}.
261
+ */
262
+ seq?: number;
175
263
  } | {
176
264
  type: "use-websocket";
177
265
  url: string;
@@ -196,6 +284,15 @@ export declare abstract class ValOps {
196
284
  networkError?: boolean;
197
285
  }>;
198
286
  private initSources;
287
+ /**
288
+ * Each module staged after the build, read from its staged text (see
289
+ * {@link ValOpsOptions.stagedAfterBuild}), to lay over the snapshot; `null`
290
+ * when there is none. A module whose text says nothing this can read -- a
291
+ * Source built by code, a `.jsonValues()` record, whose entries a save
292
+ * routes through a schema this server has not got -- is held, and keeps
293
+ * what it had: its version says it is not this build's either way.
294
+ */
295
+ private readStagedSources;
199
296
  /**
200
297
  * In a proposal: the SITE's Source for every module the proposal has saved,
201
298
  * as the build it is based on evaluated it -- what the proposal is compared
@@ -252,7 +349,7 @@ export declare abstract class ValOps {
252
349
  * sources move would put a value other code compares against into
253
350
  * disagreement with what it describes. Moving them means a `fs`-mode base SHA
254
351
  * changes within a server's lifetime for the first time, which is a signal the
255
- * studio already knows how to read: `PatchStore.reconcileVanished` uses a
352
+ * studio already knows how to read: `PatchStore.settleVanished` uses a
256
353
  * moved base to tell "these patches were published" from "these patches were
257
354
  * discarded", and takes them out of the chain without reverting the fields —
258
355
  * which is what a second tab watching a publish needs and could not get
@@ -265,7 +362,161 @@ export declare abstract class ValOps {
265
362
  */
266
363
  protected promoteCommittedSources(patched: Sources): void;
267
364
  init(): Promise<void>;
365
+ /**
366
+ * Every module's version, for the patches a draft applies (in chain order:
367
+ * `draftOverlay`'s), or with the empty chain when `applied` is false -- an
368
+ * answer whose source has no patches applied (`apply_patches=false`).
369
+ *
370
+ * Nothing here hashes on a read: `schema` and `base` were hashed when the
371
+ * modules were evaluated or a base adopted, and the chains are extended
372
+ * only by the patches they gained since the last call (`ChainFold`).
373
+ */
374
+ moduleVersions(patches: readonly {
375
+ patchId: PatchId;
376
+ path: ModuleFilePath;
377
+ }[], applied?: boolean,
378
+ /**
379
+ * For a module whose chain stopped at a patch that does not apply, how
380
+ * many of its patches the answer's content is AT (`getSources`'s
381
+ * `stopped`): its version names that chain, not the whole one.
382
+ */
383
+ stopped?: Readonly<Record<ModuleFilePath, number>>): Promise<Record<ModuleFilePath, ModuleVersion>>;
384
+ /** One module's version: {@link moduleVersions}, for one path. */
385
+ moduleVersion(moduleFilePath: ModuleFilePath, patches: readonly {
386
+ patchId: PatchId;
387
+ path: ModuleFilePath;
388
+ }[], applied?: boolean,
389
+ /** See `stopped` on {@link moduleVersions}: this module's count. */
390
+ stoppedAt?: number): Promise<ModuleVersion | undefined>;
391
+ /**
392
+ * The project version an answer is relative to. `headVersion` is the
393
+ * content service's, for a store that keeps no counter of its own (http);
394
+ * fs and memory count their own writes ({@link ownSeq}).
395
+ */
396
+ projectVersion(headVersion?: number): Promise<ProjectVersion>;
397
+ /**
398
+ * The last few manifests this instance answered, by ETag: what a
399
+ * "since `seq` N" read is a delta from (`GET /manifest?since=N`). A few,
400
+ * not one: two Studios polling a project hold different ones. In this
401
+ * instance only -- a manifest another process answered is not here, and
402
+ * is answered whole.
403
+ */
404
+ private answeredManifests;
405
+ /** Keep a manifest this instance answered. See {@link manifestSince}. */
406
+ rememberManifest(etag: string, project: ProjectVersion, modules: Record<ModuleFilePath, ModuleVersion>): void;
407
+ private static readonly ANSWERED_MANIFESTS;
408
+ /**
409
+ * The modules of `modules` whose version moved since the manifest this
410
+ * instance answered with `etag` at `since`, or `null` when that one is not
411
+ * held (answered elsewhere, too long ago) or was another build's: then the
412
+ * answer is the whole manifest. Three strings compared per module; nothing
413
+ * hashed.
414
+ */
415
+ manifestSince(etag: string, since: number, project: ProjectVersion, modules: Record<ModuleFilePath, ModuleVersion>): Record<ModuleFilePath, ModuleVersion> | null;
416
+ /**
417
+ * A cheap identity for "the manifest has not moved": the build, the base
418
+ * fold, the seq and the chain fold's epoch. Concatenated, never hashed.
419
+ */
420
+ manifestTag(project: ProjectVersion): Promise<string>;
421
+ /**
422
+ * The `sourcesSha` of the base this store's chain is relative to: what a
423
+ * `/stat` answer names. Read by a Studio of the release before, which put
424
+ * the chain on that base (`BaseAlignment`), and compared by the fs and
425
+ * memory long poll with what a Studio echoes; this release's Studio takes
426
+ * each module's base from the manifest instead. Goes with `/stat`'s
427
+ * `sourcesSha` (see "Release-delayed deletions" in
428
+ * `docs/plans/one-content-model.md`).
429
+ *
430
+ * This instance's own, unless the store keeps one chain for every build
431
+ * and a newer build of the project has been made since this one, in this
432
+ * process (fs and memory: the patches are the store's, and they are
433
+ * relative to what the NEWEST build evaluated -- the files on disk, the
434
+ * modules hot reload brought). An instance still answering then (a long
435
+ * poll parked on it before the reload, a request routed to the previous
436
+ * build) would otherwise name its own, older base, and the Studio would
437
+ * fetch it and show the content from before the code change (S26,
438
+ * `scenarios/src/overlayAfterBuild.scenario.test.ts`). In http mode the
439
+ * content service answers each build with the patches THAT build does not
440
+ * contain, so its own base is the right one for that chain -- and when a
441
+ * newer build is live, only the content service knows, so `/stat` there
442
+ * asks it for the chain relative to the live build and names that build's
443
+ * base (`ValOpsHttp.getStat`, `OrderedPatchesMetadata.chainBase`).
444
+ *
445
+ * Newest by when the instance was MADE, not by when it first answered:
446
+ * hot reload makes the new one after the old, and an old one first asked
447
+ * after the new one is still the old one.
448
+ */
449
+ chainBaseSha(): Promise<SourcesSha>;
450
+ /**
451
+ * The data layer whose head answers what each module IS for this store's
452
+ * chain (`GET /manifest`, `GET /modules`): this one, unless the store keeps
453
+ * one chain for every build and a newer build was made since, in this
454
+ * process (fs and memory; see {@link chainBaseSha}). An instance still
455
+ * answering then -- a long poll parked on it across a hot reload, a request
456
+ * routed to the previous build -- would name its own, older bases, and a
457
+ * Studio reading them would show the content from before the code change
458
+ * (S26).
459
+ */
460
+ newestOps(): ValOps;
461
+ /**
462
+ * The host's own name for the build it runs, when it has one (a platform's
463
+ * build, a commit). `null`: the fold of what the modules evaluated to.
464
+ */
465
+ protected hostBuild(): string | null;
466
+ /**
467
+ * Where the code of the build this store runs in can be imported from,
468
+ * by a Studio opened on another build (`registry` on `GET /manifest`):
469
+ * only a build the platform made and names has an entry of its own
470
+ * (`valModulesEntryPath`). `null` everywhere else -- local development,
471
+ * where HMR brings the code, and a deploy the platform did not build.
472
+ */
473
+ buildRegistry(): BuildRegistry | null;
474
+ /**
475
+ * This store's own `seq`, or `null` for a store whose changes are counted
476
+ * by someone else (the content service's `headVersion`). Given the build,
477
+ * because a new build bumps it once.
478
+ */
479
+ protected ownSeq(_build: string): Promise<number | null>;
268
480
  getBaseSources(): Promise<Sources>;
481
+ /**
482
+ * A module as the BUILD evaluated it, with its version (the empty chain):
483
+ * what a reader's own bundle holds. `null` for a module the build has not
484
+ * got. See {@link bundleSources}.
485
+ */
486
+ bundleModule(moduleFilePath: ModuleFilePath): Promise<{
487
+ version: ModuleVersion;
488
+ source: Json;
489
+ } | null>;
490
+ /**
491
+ * A module's BASE as this build serves it -- the bundle's, or what a
492
+ * content version, a proposal's saves or a publish put in its place --
493
+ * with its version (the empty chain). `null` for no such module.
494
+ */
495
+ baseModule(moduleFilePath: ModuleFilePath): Promise<{
496
+ version: ModuleVersion;
497
+ source: Json;
498
+ } | null>;
499
+ /**
500
+ * "Has the chain moved?", cheaply: the store's `seq` (fs, memory), or
501
+ * the content service's chain version (http). `null` when the store
502
+ * cannot say without reading the chain; the head then reads it each time.
503
+ */
504
+ chainSeq(): Promise<number | null>;
505
+ /**
506
+ * {@link chainSeq}, with what it counts from: two positions are the same
507
+ * only when both are. A counter that can start again (fs: `.val` removed
508
+ * by hand) names its start in `epoch`, so coming back to the same number
509
+ * is not read as "nothing moved". `null` as for {@link chainSeq}.
510
+ */
511
+ chainPosition(): Promise<{
512
+ seq: number;
513
+ epoch: string;
514
+ } | null>;
515
+ /**
516
+ * A module's chain after its first `count` patches, of the chain the
517
+ * versions were last computed for. Hashes nothing. See `ChainFold.chainAt`.
518
+ */
519
+ chainAt(moduleFilePath: ModuleFilePath, count: number): string;
269
520
  /**
270
521
  * Resolves the content of ONE `.jsonValues()` entry.
271
522
  *
@@ -282,9 +533,11 @@ export declare abstract class ValOps {
282
533
  /** Passed straight through — see {@link getJsonEntries}. */
283
534
  opts?: {
284
535
  applyPatches?: boolean;
536
+ withVersion?: boolean;
285
537
  }): Promise<{
286
538
  status: "success";
287
- content: JSONValue | null;
539
+ content: ReadonlyJSONValue | null;
540
+ version?: ModuleVersion;
288
541
  } | {
289
542
  status: "not-found";
290
543
  message: string;
@@ -320,11 +573,13 @@ export declare abstract class ValOps {
320
573
  limit: number;
321
574
  }, opts?: {
322
575
  applyPatches?: boolean;
576
+ /** Answer the record module's version too (`/json` does). */
577
+ withVersion?: boolean;
323
578
  }): Promise<{
324
579
  status: "success";
325
580
  entries: {
326
581
  key: string;
327
- content: JSONValue | null;
582
+ content: ReadonlyJSONValue | null;
328
583
  }[];
329
584
  missing: string[];
330
585
  errors: {
@@ -334,6 +589,8 @@ export declare abstract class ValOps {
334
589
  total: number;
335
590
  offset?: number;
336
591
  limit?: number;
592
+ /** See `version` on `/json`. */
593
+ version?: ModuleVersion;
337
594
  } | {
338
595
  status: "not-found";
339
596
  message: string;
@@ -344,6 +601,16 @@ export declare abstract class ValOps {
344
601
  status: "unauthorized";
345
602
  message: string;
346
603
  }>;
604
+ /**
605
+ * One `.jsonValues()` entry's BASE content: what the chain starts from.
606
+ * `undefined` for a key the base record does not have; `null` for a marker
607
+ * with nothing behind it.
608
+ */
609
+ baseJsonEntry(moduleFilePath: ModuleFilePath, record: Record<string, unknown>, entryKey: string): Promise<{
610
+ content: JSONValue | undefined;
611
+ } | {
612
+ message: string;
613
+ }>;
347
614
  getSchemas(): Promise<Schemas>;
348
615
  getSerializedSchemas(): Promise<Record<ModuleFilePath, SerializedSchema>>;
349
616
  getModuleErrors(): Promise<ModulesError[]>;
@@ -353,20 +620,16 @@ export declare abstract class ValOps {
353
620
  getSchemaSha(): Promise<SchemaSha>;
354
621
  analyzePatches(sortedPatches: OrderedPatches["patches"], commits?: ValCommit[], currentCommitSha?: CommitSha): PatchAnalysis;
355
622
  /**
356
- * Reifies each module's previews from its schema INSTANCE.
623
+ * The modules' sources, with these patches applied -- ONLY the modules that
624
+ * had patches (see {@link getSourcesWithPatchesApplied} for all of them).
357
625
  *
358
- * Kept even though the Studio also computes previews client-side: a preview is
359
- * a user function that lives on the instance and is not part of the serialized
360
- * schema, so a host app that does not render `<ValModulesClient>` has no
361
- * instances in the browser and would otherwise get no previews at all. See
362
- * #470.
363
- *
364
- * A `render`, and a string's `multiline`, need none of this — they are static
365
- * config that travels with the serialized schema.
626
+ * The patches are applied by THE engine (`applyPatchRecord` in
627
+ * `@valbuild/shared`), copy-on-write, so an unpatched part of a module is
628
+ * the same object as in the base. A module's chain stops at its first patch
629
+ * that does not apply: that one is reported with `skipped: false`, every
630
+ * later one with `skipped: true`, and `stopped` says how many of the
631
+ * module's patches its source is AT, so its version can name that chain.
366
632
  */
367
- getPreviews(schemas: Schemas, sources: Sources): Promise<{
368
- previews: Record<ModuleFilePath, ReifiedPreview | null>;
369
- }>;
370
633
  getSources(analysis?: PatchAnalysis & OrderedPatches): Promise<{
371
634
  sources: Sources;
372
635
  errors: Record<ModuleFilePath, {
@@ -374,6 +637,11 @@ export declare abstract class ValOps {
374
637
  skipped: boolean;
375
638
  error: GenericErrorMessage;
376
639
  }[]>;
640
+ /**
641
+ * For a module whose chain stopped at a patch that does not apply: how
642
+ * many of its patches applied. Absent for a module whose patches all did.
643
+ */
644
+ stopped: Record<ModuleFilePath, number>;
377
645
  }>;
378
646
  /**
379
647
  * Every module's source, with the pending patches applied.
@@ -452,7 +720,7 @@ export declare abstract class ValOps {
452
720
  error: GenericErrorMessage;
453
721
  } | {
454
722
  errorType: "patch-head-conflict";
455
- } | PlanRefusedError>>;
723
+ } | PlanRefusedError | ServiceErrorSavingPatch>>;
456
724
  /**
457
725
  * Why a publish cannot happen here, or `null` when one can.
458
726
  *
@@ -533,10 +801,14 @@ export declare abstract class ValOps {
533
801
  publishApi(_path: string, _init: {
534
802
  method: string;
535
803
  body?: string;
804
+ /** A GET's `If-None-Match`, carried to content. */
805
+ ifNoneMatch?: string;
536
806
  }): Promise<{
537
807
  status: number;
538
808
  body: string;
539
809
  contentType: string;
810
+ /** Content's `ETag`, when it named its answer. */
811
+ etag?: string;
540
812
  }>;
541
813
  /**
542
814
  * The proposal this server runs at the address of, or `null` on the site --
@@ -783,7 +1055,25 @@ export type SaveSourceFilePatchResult = result.Result<{
783
1055
  errorType: "other";
784
1056
  } & GenericErrorMessage) | {
785
1057
  errorType: "patch-head-conflict";
786
- } | PlanRefusedError>;
1058
+ } | PlanRefusedError | ServiceErrorSavingPatch>;
1059
+ /**
1060
+ * The content service failed to take the patch: it answered with a server
1061
+ * error, or could not be reached at all.
1062
+ *
1063
+ * Its own error rather than an `other`, for the same reason
1064
+ * {@link PlanRefusedError} is: an `other` becomes a 400, and the Studio drops a
1065
+ * patch it is told is bad -- the field reverts and the edit is gone. Nothing is
1066
+ * wrong with this patch. The service is, and the Studio keeps the edit and
1067
+ * offers to send it again. Only `retryable` failures are this; a 4xx from the
1068
+ * service is still a refusal of the patch.
1069
+ */
1070
+ export type ServiceErrorSavingPatch = {
1071
+ errorType: "service-error";
1072
+ /** For the person. See `ContentServiceFailure`. */
1073
+ message: string;
1074
+ /** The status line and the service's own words. */
1075
+ details: string;
1076
+ };
787
1077
  /**
788
1078
  * The content API refused a write for the project's plan (a 403 that says why
789
1079
  * as data), as opposed to refusing the patch.
@@ -874,6 +1164,13 @@ export type PreparedCommit = {
874
1164
  moduleVersions: Record<ModuleFilePath, {
875
1165
  source: JSONValue | null;
876
1166
  schema: SerializedSchema;
1167
+ /**
1168
+ * `staged:<inputs>`: the module's code is staged in the proposal and
1169
+ * not in this build, so `schema` is not the one `source` fits; content
1170
+ * records this as the version's schema instead (valbuild/home,
1171
+ * "Staged schemas"). Absent for every other module.
1172
+ */
1173
+ staged?: string;
877
1174
  }>;
878
1175
  /**
879
1176
  * Diagnosis only: what the source file looks like with the appliable patches
@@ -921,54 +1218,7 @@ export type PatchReadError = {
921
1218
  parentPatchId: ParentPatchId;
922
1219
  message: string;
923
1220
  };
924
- /**
925
- * The patches a json entry render should apply, out of the whole chain:
926
- *
927
- * 1. this module's, since the chain is branch-wide;
928
- * 2. a patch published after this build is kept: this build does not have it.
929
- * One already in the build is dropped. `draftOverlay` decides which is
930
- * which, from `commits`.
931
- */
932
- export declare function draftModulePatches<T extends {
933
- path: ModuleFilePath;
934
- patchId: PatchId;
935
- appliedAt: {
936
- commitSha: CommitSha;
937
- } | null;
938
- }>(patches: T[], moduleFilePath: ModuleFilePath,
939
- /** The commits content says came after this build: see `draftOverlay`. */
940
- commits?: Pick<ValCommit, "commitSha">[]): T[];
941
- /**
942
- * The patches a DRAFT applies on top of this build's own source: the pending
943
- * ones, and the ones published AFTER this build, in chain order -- with
944
- * `appliedAt` cleared on the latter, because this build has none of them.
945
- *
946
- * Content places every caller at its own build (`getApplicablePatchesAndCommits`
947
- * in valbuild/home: "the earliest the caller has not seen") and returns the
948
- * commits after it as `commits`. A patch applied at one of those was
949
- * published after this build and is not in it, so a draft has to apply it --
950
- * skipping it showed the build's old value from the publish until the next
951
- * build went live. `/sources/~` already applies them (`getSources` walks every
952
- * patch it is given); the `.jsonValues()` entry path skipped them.
953
- *
954
- * A patch applied at a commit NOT in that list is already in this build --
955
- * content returns one only because it was asked for by id -- and is dropped:
956
- * applying it again would apply it twice. Without `commits` (a store that
957
- * does not report them) every applied patch is dropped, as before. Only
958
- * `ValOpsHttp` ever reports `appliedAt`; `fs` and memory stores report `null`.
959
- *
960
- * Chain order, not published-first, because that is the order the Studio
961
- * applies them in, and a draft page starts from the server's answer and is
962
- * then kept up to date by the Studio's: the two must agree.
963
- *
964
- * For the reads that render a draft only. What to COMMIT still keys on
965
- * `appliedAt`: a published patch must never be published again.
966
- */
967
- export declare function draftOverlay<T extends {
968
- appliedAt: {
969
- commitSha: CommitSha;
970
- } | null;
971
- }>(patches: T[], commits: Pick<ValCommit, "commitSha">[] | undefined): T[];
1221
+ export { draftModulePatches, draftOverlay } from "./draftOverlay.js";
972
1222
  export type OrderedPatches = {
973
1223
  patches: {
974
1224
  path: ModuleFilePath;
@@ -1028,6 +1278,13 @@ export type OrderedPatches = {
1028
1278
  * from an older content service. Only `ValOpsHttp` fills it.
1029
1279
  */
1030
1280
  heldBackPatches?: PatchId[];
1281
+ /**
1282
+ * The content service has counted a NEWER build of the branch live: this
1283
+ * one is a previous build still answering (S26; valbuild/home
1284
+ * `utils/liveBuild.ts`). Its chain is right for its own base, which is not
1285
+ * what the site serves any more. Only `ValOpsHttp` fills it.
1286
+ */
1287
+ superseded?: boolean;
1031
1288
  error?: GenericErrorMessage;
1032
1289
  errors?: PatchReadError[];
1033
1290
  unauthorized?: boolean;
@@ -1049,6 +1306,13 @@ export type OrderedPatchesMetadata = {
1049
1306
  publishingPatches?: OrderedPatches["publishingPatches"];
1050
1307
  /** See {@link OrderedPatches.heldBackPatches}. */
1051
1308
  heldBackPatches?: OrderedPatches["heldBackPatches"];
1309
+ /**
1310
+ * The base this list is relative to, when the content service answered it
1311
+ * relative to ANOTHER build than the one asking: the live build, when the
1312
+ * one asking is a previous build still answering (S26, http mode; see
1313
+ * `ValOpsHttp.getStat`). Absent: this build's own base.
1314
+ */
1315
+ chainBase?: SourcesSha;
1052
1316
  error?: GenericErrorMessage;
1053
1317
  errors?: OrderedPatches["errors"];
1054
1318
  unauthorized?: boolean;
@@ -6,6 +6,7 @@ import type { AffectedFile, StoredModuleVersion, CommitPage, CommitPatch, Histor
6
6
  import { result } from "@valbuild/core/fp";
7
7
  import { Buffer } from "buffer";
8
8
  import type { SketchpadStore } from "./sketchpads/SketchpadStore.js";
9
+ import { type TypeScriptKit } from "./patch/ts/loadTypeScriptKit.js";
9
10
  export declare class ValOpsFS extends ValOps {
10
11
  private readonly contentUrl;
11
12
  private readonly rootDir;
@@ -14,12 +15,23 @@ export declare class ValOpsFS extends ValOps {
14
15
  /** The developer's own working tree. See {@link ValOps.patchesAreLocal}. */
15
16
  readonly patchesAreLocal = true;
16
17
  readonly kind = "fs";
18
+ /**
19
+ * Always available: this data layer only runs on Node. See
20
+ * {@link ValOpsOptions.typescript}.
21
+ */
22
+ protected loadTypeScriptKit(): Promise<TypeScriptKit>;
17
23
  /**
18
24
  * The developer's own machine, where there is no credential to require and
19
25
  * nothing to protect it from. See {@link ValOps.requiresAuth}.
20
26
  */
21
27
  readonly requiresAuth = false;
22
28
  constructor(contentUrl: string, rootDir: string, valModules: ValModules, options?: ValOpsOptions);
29
+ /**
30
+ * The base the store's chain is relative to: the newest build's, made in
31
+ * this process (see `ValOps.chainBaseSha`).
32
+ */
33
+ newestOps(): ValOps;
34
+ chainBaseSha(): Promise<SourcesSha>;
23
35
  /** In `.val/sketchpads`. See `sketchpads/fsSketchpadStore.ts`. */
24
36
  readonly sketchpads: SketchpadStore;
25
37
  /**
@@ -75,6 +87,8 @@ export declare class ValOpsFS extends ValOps {
75
87
  reason: string;
76
88
  }[];
77
89
  jsonEntriesSha?: string;
90
+ /** The patch store's `seq`, read before the patches. See `patchSeq.ts`. */
91
+ seq?: number;
78
92
  } | {
79
93
  type: "use-websocket";
80
94
  url: string;
@@ -178,6 +192,24 @@ export declare class ValOpsFS extends ValOps {
178
192
  * whole directory, and a lock that moves away with it is not holding anything.
179
193
  */
180
194
  private getPatchLockFile;
195
+ /** Beside the lock, for the same reason: see `patchSeq.ts`. */
196
+ private getPatchSeqFile;
197
+ /**
198
+ * One more change counted. Called under the patch lock, after the change it
199
+ * counts is on disk: a reader takes `seq` BEFORE it reads the store, so an
200
+ * answer can be behind its `seq`'s change but never claim one it lacks.
201
+ *
202
+ * A counter that cannot be written does not fail the write it counts: the
203
+ * change is made, and answers stay ordered by what came before.
204
+ */
205
+ private countChange;
206
+ /** Whether this instance has counted itself as a new build yet. */
207
+ private countedBuild;
208
+ protected ownSeq(build: string): Promise<number>;
209
+ chainPosition(): Promise<{
210
+ seq: number;
211
+ epoch: string;
212
+ } | null>;
181
213
  listCommits(): Promise<result.Result<CommitPage, HistoryError>>;
182
214
  getCommitPatches(): Promise<result.Result<{
183
215
  commit: HistoricalCommit;