@valbuild/server 0.150.23 → 0.151.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.
- package/CHANGELOG.md +319 -0
- package/browser/dist/valbuild-server-browser.cjs.dev.js +5 -137
- package/browser/dist/valbuild-server-browser.cjs.prod.js +5 -137
- package/browser/dist/valbuild-server-browser.esm.js +4 -140
- package/dist/ValRouter-2827d620.esm.js +14489 -0
- package/dist/ValRouter-ca467c83.cjs.dev.js +14585 -0
- package/dist/ValRouter-d43e0a33.cjs.prod.js +14585 -0
- package/dist/{ValRouterCore-0c7ae881.cjs.prod.js → ValRouterCore-0921fe9c.cjs.dev.js} +3156 -1758
- package/dist/{ValRouterCore-5b6cccd4.esm.js → ValRouterCore-6c29fb75.esm.js} +3147 -1753
- package/dist/{ValRouterCore-cfa7b001.cjs.dev.js → ValRouterCore-eb1f53f5.cjs.prod.js} +3156 -1758
- package/dist/declarations/src/ValOps.d.ts +314 -68
- package/dist/declarations/src/ValOpsFS.d.ts +32 -0
- package/dist/declarations/src/ValOpsHttp.d.ts +93 -3
- package/dist/declarations/src/ValOpsMemory.d.ts +22 -47
- package/dist/declarations/src/ValRouter.d.ts +10 -0
- package/dist/declarations/src/ValServer.d.ts +0 -10
- package/dist/declarations/src/browser/inTabFetch.d.ts +19 -2
- package/dist/declarations/src/draftOverlay.d.ts +51 -0
- package/dist/declarations/src/draftReads.d.ts +103 -0
- package/dist/declarations/src/head.d.ts +312 -0
- package/dist/declarations/src/history/getJsonEntryAtCommit.d.ts +52 -0
- package/dist/declarations/src/index.d.ts +1 -0
- package/dist/declarations/src/internal/browser/index.d.ts +11 -0
- package/dist/declarations/src/internal/index.d.ts +15 -0
- package/dist/declarations/src/patch/jsonValuesPatch.d.ts +2 -165
- package/dist/declarations/src/patch/ts/jsonValuesModule.d.ts +38 -0
- package/dist/declarations/src/patch/ts/loadTypeScriptKit.d.ts +14 -0
- package/dist/declarations/src/patch/ts/ops.d.ts +45 -0
- package/dist/declarations/src/patch/ts/publishKit.d.ts +26 -0
- package/dist/declarations/src/platform.d.ts +14 -0
- package/dist/declarations/src/proposal.d.ts +54 -3
- package/dist/declarations/src/valRuntime.d.ts +35 -0
- package/dist/draftReads-05415ff6.cjs.dev.js +366 -0
- package/dist/draftReads-5f99edd3.esm.js +361 -0
- package/dist/draftReads-ea3946e0.cjs.prod.js +366 -0
- package/dist/inTabFetch-0cd45721.esm.js +176 -0
- package/dist/inTabFetch-35cf5698.cjs.prod.js +179 -0
- package/dist/inTabFetch-49db354b.cjs.dev.js +179 -0
- package/dist/{getJsonEntryAtCommit-acf8c269.cjs.prod.js → publishKit-24e1406b.cjs.prod.js} +55 -6
- package/dist/{getJsonEntryAtCommit-d9b5f753.cjs.dev.js → publishKit-3afe011d.cjs.dev.js} +55 -6
- package/dist/{getJsonEntryAtCommit-8ff81ef5.esm.js → publishKit-d2e3e44d.esm.js} +48 -5
- package/dist/valbuild-server.cjs.dev.js +160 -13319
- package/dist/valbuild-server.cjs.prod.js +160 -13319
- package/dist/valbuild-server.esm.js +34 -13174
- package/internal/browser/dist/valbuild-server-internal-browser.cjs.d.ts +2 -0
- package/internal/browser/dist/valbuild-server-internal-browser.cjs.dev.js +19 -0
- package/internal/browser/dist/valbuild-server-internal-browser.cjs.js +7 -0
- package/internal/browser/dist/valbuild-server-internal-browser.cjs.prod.js +19 -0
- package/internal/browser/dist/valbuild-server-internal-browser.esm.js +10 -0
- package/internal/browser/package.json +4 -0
- package/internal/dist/valbuild-server-internal.cjs.d.ts +2 -0
- package/internal/dist/valbuild-server-internal.cjs.dev.js +43 -0
- package/internal/dist/valbuild-server-internal.cjs.js +7 -0
- package/internal/dist/valbuild-server-internal.cjs.prod.js +43 -0
- package/internal/dist/valbuild-server-internal.esm.js +24 -0
- package/internal/package.json +4 -0
- package/package.json +17 -6
- package/dist/jsonValuesModule-235bd751.cjs.dev.js +0 -326
- package/dist/jsonValuesModule-23eb6f53.esm.js +0 -310
- package/dist/jsonValuesModule-625ebae8.cjs.prod.js +0 -326
- package/dist/ops-0e54b388.cjs.prod.js +0 -361
- package/dist/ops-9ca2ef2a.cjs.dev.js +0 -361
- package/dist/ops-b904007e.esm.js +0 -353
- package/dist/publishKit-34f71e50.cjs.dev.js +0 -42
- package/dist/publishKit-65e9e564.cjs.prod.js +0 -42
- package/dist/publishKit-7441c0fd.esm.js +0 -31
|
@@ -7,12 +7,19 @@ import type { HistoryError } from "./history/HistoryError.js";
|
|
|
7
7
|
import type { AffectedFile, StoredModuleVersion, CommitPage, CommitPatch, HistoricalCommit } from "./history/types.js";
|
|
8
8
|
import { ParentRef, ValCommit, ValDeployment } from "@valbuild/shared/internal";
|
|
9
9
|
import { result } from "@valbuild/core/fp";
|
|
10
|
+
import { type BuildRegistry } from "@valbuild/shared/internal";
|
|
10
11
|
import type { SketchpadStore } from "./sketchpads/SketchpadStore.js";
|
|
12
|
+
import { type TypeScriptKit } from "./patch/ts/loadTypeScriptKit.js";
|
|
11
13
|
declare const PatchId: z.ZodString & z.ZodType<PatchId, string, z.core.$ZodTypeInternals<PatchId, string>>;
|
|
12
14
|
declare const CommitSha: z.ZodString & z.ZodType<CommitSha, string, z.core.$ZodTypeInternals<CommitSha, string>>;
|
|
13
15
|
declare const BaseSha: z.ZodString & z.ZodType<BaseSha, string, z.core.$ZodTypeInternals<BaseSha, string>>;
|
|
14
16
|
declare const AuthorId: z.ZodString & z.ZodType<AuthorId, string, z.core.$ZodTypeInternals<AuthorId, string>>;
|
|
15
17
|
declare const ModuleFilePath: z.ZodString & z.ZodType<ModuleFilePath, string, z.core.$ZodTypeInternals<ModuleFilePath, string>>;
|
|
18
|
+
/**
|
|
19
|
+
* How long a content service that predates `GET /chain/version` is not
|
|
20
|
+
* asked it again: see `ValOpsHttp.chainSeq`.
|
|
21
|
+
*/
|
|
22
|
+
export declare const CHAIN_VERSION_RETRY_MS: number;
|
|
16
23
|
/**
|
|
17
24
|
* This client's own branch's entry in a per-branch version map.
|
|
18
25
|
*
|
|
@@ -40,11 +47,21 @@ export declare class ValOpsHttp extends ValOps {
|
|
|
40
47
|
* {@link ValApiOptions}.
|
|
41
48
|
*/
|
|
42
49
|
private readonly git;
|
|
50
|
+
/**
|
|
51
|
+
* Sent with every request to the content service: the credential, and
|
|
52
|
+
* `x-val-client` (see `VAL_CLIENT_HEADER` in `@valbuild/shared`), which is
|
|
53
|
+
* why every request spreads this rather than building its own.
|
|
54
|
+
*/
|
|
43
55
|
private readonly authHeaders;
|
|
44
56
|
private readonly root;
|
|
45
57
|
/** Val's content service owns the store. See {@link ValOps.patchesAreLocal}. */
|
|
46
58
|
readonly patchesAreLocal = false;
|
|
47
59
|
readonly kind = "http";
|
|
60
|
+
/**
|
|
61
|
+
* Always available: this data layer only runs on Node. See
|
|
62
|
+
* {@link ValOpsOptions.typescript}.
|
|
63
|
+
*/
|
|
64
|
+
protected loadTypeScriptKit(): Promise<TypeScriptKit>;
|
|
48
65
|
/** The content service's. See `sketchpads/httpSketchpadStore.ts`. */
|
|
49
66
|
readonly sketchpads: SketchpadStore;
|
|
50
67
|
/** See {@link ValOps.requiresAuth}. */
|
|
@@ -151,6 +168,41 @@ export declare class ValOpsHttp extends ValOps {
|
|
|
151
168
|
/** See `contentVersion` on {@link ValApiOptions}. */
|
|
152
169
|
contentVersion?: ValContentVersion;
|
|
153
170
|
});
|
|
171
|
+
/** `VAL_BUILD`, as the platform handed it over: see {@link buildRegistry}. */
|
|
172
|
+
private readonly platformBuild;
|
|
173
|
+
/**
|
|
174
|
+
* The platform's name for the build (`VAL_BUILD`), else the commit it was
|
|
175
|
+
* built from. Part of `ProjectVersion.build`; `seq` is the content
|
|
176
|
+
* service's `headVersion`, so this store keeps no counter of its own.
|
|
177
|
+
*/
|
|
178
|
+
private readonly buildName;
|
|
179
|
+
protected hostBuild(): string | null;
|
|
180
|
+
/**
|
|
181
|
+
* The platform's build emits its registry beside its client chunks, named
|
|
182
|
+
* after the build (`@valbuild/tanstack-build`), and the platform tells
|
|
183
|
+
* this server the build's name (`VAL_BUILD`). Whatever content version
|
|
184
|
+
* it serves: the code is the build's either way.
|
|
185
|
+
*/
|
|
186
|
+
buildRegistry(): BuildRegistry | null;
|
|
187
|
+
/**
|
|
188
|
+
* Until when the content service is taken to predate `GET /chain/version`
|
|
189
|
+
* (it answered a 404 that is not JSON: Express's own "Cannot GET", from a
|
|
190
|
+
* service without the route). Asked again after
|
|
191
|
+
* {@link CHAIN_VERSION_RETRY_MS}, since a service is upgraded under a
|
|
192
|
+
* running server. A JSON 404 is not that: it is "no such project", which
|
|
193
|
+
* every other call will report too, and stops nothing.
|
|
194
|
+
*/
|
|
195
|
+
private chainVersionUnansweredUntil;
|
|
196
|
+
/**
|
|
197
|
+
* "Has the chain moved?" as one small read: the branch's chain version
|
|
198
|
+
* (`headVersion`), which the content service bumps with every write,
|
|
199
|
+
* delete and publish and with each deployment going live -- the same
|
|
200
|
+
* counter `applicable/patches` answers with, read alone (valbuild/home
|
|
201
|
+
* `readChainVersion`). A branch nothing was written to answers 0.
|
|
202
|
+
* `null` when it cannot be read: from a content service that predates it,
|
|
203
|
+
* or on any failure, the head reads the whole chain as before.
|
|
204
|
+
*/
|
|
205
|
+
chainSeq(): Promise<number | null>;
|
|
154
206
|
/**
|
|
155
207
|
* A deployment that cannot mirror a project which expects to be mirrored.
|
|
156
208
|
*
|
|
@@ -282,10 +334,12 @@ export declare class ValOpsHttp extends ValOps {
|
|
|
282
334
|
publishApi(path: string, init: {
|
|
283
335
|
method: string;
|
|
284
336
|
body?: string;
|
|
337
|
+
ifNoneMatch?: string;
|
|
285
338
|
}): Promise<{
|
|
286
339
|
status: number;
|
|
287
340
|
body: string;
|
|
288
341
|
contentType: string;
|
|
342
|
+
etag?: string;
|
|
289
343
|
}>;
|
|
290
344
|
currentProposal(): {
|
|
291
345
|
name: string;
|
|
@@ -295,13 +349,17 @@ export declare class ValOpsHttp extends ValOps {
|
|
|
295
349
|
* Which proposal calls the browser may make, by method and the path after
|
|
296
350
|
* `/proposals`: list and open, read and rename one, read what its build
|
|
297
351
|
* targets and how far an upgrade's preparation is, render its build as a
|
|
298
|
-
* canary (`verify`),
|
|
352
|
+
* canary (`verify`), close, reopen and retry its setup, turn code mode on
|
|
353
|
+
* and off, and commit it to git (both at its own address only, see
|
|
354
|
+
* {@link ValOpsHttp.proposalFilesWrite}). Not `/save` -- the Studio saves through `/save`, which
|
|
299
355
|
* prepares the commit here -- and not `/patches`, which moves the site's
|
|
300
356
|
* changes into a proposal and has no screen yet.
|
|
301
357
|
*/
|
|
302
358
|
private static proposalsApiAllowed;
|
|
303
359
|
/**
|
|
304
|
-
* A write to a proposal's FILES --
|
|
360
|
+
* A write to a proposal's FILES -- or to what decides who may change
|
|
361
|
+
* them: code mode, committing them to git, and taking in somebody's push
|
|
362
|
+
* to its branch -- staging code, computing its lockfile
|
|
305
363
|
* (valbuild/home `docs/adept.md`, step 6), reporting the typecheck of
|
|
306
364
|
* them (step 7, decision 20), serving a build of it
|
|
307
365
|
* (valbuild/home `docs/hosted-publishing.md`, step 7), or moving it onto the
|
|
@@ -458,6 +516,20 @@ export declare class ValOpsHttp extends ValOps {
|
|
|
458
516
|
statusCode: 401 | 500;
|
|
459
517
|
error: GenericErrorMessage;
|
|
460
518
|
}>;
|
|
519
|
+
/**
|
|
520
|
+
* The chain `/stat` answers, relative to the live build, read again only
|
|
521
|
+
* when the chain version moved (`chainSeq`: one small read of the content
|
|
522
|
+
* service). Every Studio polls `/stat`, and each socket message makes it
|
|
523
|
+
* ask; reading the whole chain for each was the content service's busiest
|
|
524
|
+
* call. A deployment going live moves the version too, so "relative to the
|
|
525
|
+
* live build" cannot go stale under the same version.
|
|
526
|
+
*
|
|
527
|
+
* The version is read BEFORE the chain, so a write in between leaves the
|
|
528
|
+
* kept chain newer than the version it is kept under -- read again on the
|
|
529
|
+
* next call, never served stale.
|
|
530
|
+
*/
|
|
531
|
+
private statChain;
|
|
532
|
+
private keptStatChain;
|
|
461
533
|
getStat(params: {
|
|
462
534
|
baseSha: BaseSha;
|
|
463
535
|
schemaSha: SchemaSha;
|
|
@@ -510,9 +582,20 @@ export declare class ValOpsHttp extends ValOps {
|
|
|
510
582
|
* the commit this build was made from, or, for a build a tab made, its job.
|
|
511
583
|
*/
|
|
512
584
|
private position;
|
|
585
|
+
/**
|
|
586
|
+
* This build's base, as a report to the content service (`sources_sha`), or
|
|
587
|
+
* `null` when it cannot be read: a request must not fail for a report.
|
|
588
|
+
*/
|
|
589
|
+
private reportedBase;
|
|
513
590
|
/** The branch this server's patches are on, where it knows it. */
|
|
514
591
|
private ownBranch;
|
|
515
|
-
getWebSocketNonce(profileId: string
|
|
592
|
+
getWebSocketNonce(profileId: string,
|
|
593
|
+
/**
|
|
594
|
+
* `live`: when this is a previous build, the socket follows the chain the
|
|
595
|
+
* live build's `/stat` named (`relativeTo` on the stat's
|
|
596
|
+
* `applicable/patches`), so its `patches` messages and that stat agree.
|
|
597
|
+
*/
|
|
598
|
+
relativeTo?: "live"): Promise<{
|
|
516
599
|
status: "success";
|
|
517
600
|
data: {
|
|
518
601
|
nonce: string;
|
|
@@ -529,6 +612,13 @@ export declare class ValOpsHttp extends ValOps {
|
|
|
529
612
|
fetchPatchesInternal<ExcludePatchOps extends boolean>(filters: {
|
|
530
613
|
patchIds?: PatchId[];
|
|
531
614
|
excludePatchOps: ExcludePatchOps;
|
|
615
|
+
/**
|
|
616
|
+
* Ask for the chain relative to the branch's LIVE build when this one is
|
|
617
|
+
* a previous build (`relative_to=live`). Only `/stat` asks: every other
|
|
618
|
+
* reader applies the chain to this build's own base, which needs this
|
|
619
|
+
* build's chain. See {@link OrderedPatchesMetadata.chainBase}.
|
|
620
|
+
*/
|
|
621
|
+
relativeToLive?: boolean;
|
|
532
622
|
}): Promise<ExcludePatchOps extends true ? OrderedPatchesMetadata : OrderedPatches>;
|
|
533
623
|
protected saveSourceFilePatch(path: ModuleFilePath, patch: PatchT, patchId: PatchId, parentRef: ParentRefT, authorId: AuthorId | null, sessionId: string | null): Promise<SaveSourceFilePatchResult>;
|
|
534
624
|
/**
|
|
@@ -38,22 +38,6 @@ export type StoredFile = {
|
|
|
38
38
|
data: Uint8Array;
|
|
39
39
|
metadata: MetadataOfType<"file" | "image"> | undefined;
|
|
40
40
|
};
|
|
41
|
-
/**
|
|
42
|
-
* Where pending patches live.
|
|
43
|
-
*
|
|
44
|
-
* The point of the interface: `ValOpsMemory` is not tied to memory. The default
|
|
45
|
-
* implementation below is explicitly NOT durable -- it dies with the process,
|
|
46
|
-
* or in a Worker with the isolate -- and a durable one (a Durable Object, whose
|
|
47
|
-
* single-threaded execution is the lock Val's fs store builds out of a file)
|
|
48
|
-
* is a swap rather than a rewrite.
|
|
49
|
-
*
|
|
50
|
-
* ORDER IS THE CONTRACT. `list()` returns patch ids in the order they were
|
|
51
|
-
* written, and that order is the chain: entry i's parent is entry i-1. This is
|
|
52
|
-
* the same decision `ValOpsFS` makes with `patches.log` -- the server decides
|
|
53
|
-
* where a patch goes, and it goes last -- and it exists for the same reason: an
|
|
54
|
-
* order held in the patches themselves lets a client working from a stale view
|
|
55
|
-
* strand every patch behind a parent that never landed.
|
|
56
|
-
*/
|
|
57
41
|
export interface ValPatchStore {
|
|
58
42
|
list(): Promise<PatchId[]>;
|
|
59
43
|
get(patchId: PatchId): Promise<StoredPatch | null>;
|
|
@@ -138,37 +122,6 @@ export type ValOpsMemoryOptions = ValOpsOptions & {
|
|
|
138
122
|
*/
|
|
139
123
|
contentUrl?: string;
|
|
140
124
|
};
|
|
141
|
-
/**
|
|
142
|
-
* A `ValOps` for a host that is neither a developer's machine nor
|
|
143
|
-
* content.val.build.
|
|
144
|
-
*
|
|
145
|
-
* EXPERIMENTAL -- see VAL_PROMPT.md.
|
|
146
|
-
*
|
|
147
|
-
* `fs` mode assumes a working tree it can watch and write; `http` mode assumes
|
|
148
|
-
* the content API owns the patch chain and a commit means a git commit. A host
|
|
149
|
-
* that builds and publishes its own output is neither: it holds the source
|
|
150
|
-
* already, it has nowhere to watch, and its "commit" is a new build.
|
|
151
|
-
*
|
|
152
|
-
* What this deliberately does NOT do:
|
|
153
|
-
*
|
|
154
|
-
* - **No filesystem.** Source comes from `sourceFiles`, patches from a store.
|
|
155
|
-
* - **No watching.** `getStat` still long-polls -- the hold is what paces the
|
|
156
|
-
* client -- but it parks on a signal rather than racing a timer against an
|
|
157
|
-
* mtime poll that can never observe anything here. Nothing can edit files
|
|
158
|
-
* behind Val's back: source changes only when the host publishes, and that
|
|
159
|
-
* replaces the process.
|
|
160
|
-
* - **Pending binary files, but no PUBLISHED local ones.** An upload is held in
|
|
161
|
-
* the patch store like any other pending change, so the Studio can preview it
|
|
162
|
-
* before it is published. What this has no answer for is a file that is
|
|
163
|
-
* already published and served from a `/public` directory: this configuration
|
|
164
|
-
* uses Val's REMOTE files, where a published image lives on the content host
|
|
165
|
-
* and the source carries a URL. `getBinaryFile` answers `null` for those --
|
|
166
|
-
* a miss, not a fault -- and `getBinaryFileMetadata` refuses by name.
|
|
167
|
-
* - **No git history.** There is no repository here, so the history methods
|
|
168
|
-
* answer `not-supported-in-fs-mode` -- the same closed error `ValOpsFS`
|
|
169
|
-
* uses, so the History UI degrades the way it already knows how rather than
|
|
170
|
-
* inventing a commit list. See the note above `listCommits`.
|
|
171
|
-
*/
|
|
172
125
|
export declare class ValOpsMemory extends ValOps {
|
|
173
126
|
/**
|
|
174
127
|
* The host's own store -- see {@link ValOps.patchesAreLocal}. `true` for the
|
|
@@ -225,6 +178,27 @@ export declare class ValOpsMemory extends ValOps {
|
|
|
225
178
|
/** Wake every parked `getStat`. Called by this instance's own writes. */
|
|
226
179
|
private announceChange;
|
|
227
180
|
private currentStat;
|
|
181
|
+
/**
|
|
182
|
+
* The `seq` of this store: see {@link seqOf}. A new build counts itself
|
|
183
|
+
* once, when it first answers.
|
|
184
|
+
*/
|
|
185
|
+
protected ownSeq(build: string): Promise<number>;
|
|
186
|
+
/** Whether this instance has counted itself as a new build yet. */
|
|
187
|
+
private countedBuild;
|
|
188
|
+
/**
|
|
189
|
+
* "Has the chain moved?" from the counter only for a store in this process
|
|
190
|
+
* ({@link InMemoryPatchStore}): every write to it goes through an instance
|
|
191
|
+
* here, so the count is the store's. Any other store (a Durable Object
|
|
192
|
+
* shared by isolates) may have been written by another isolate, which this
|
|
193
|
+
* one's count never saw: `null`, so the head reads the chain each time.
|
|
194
|
+
*/
|
|
195
|
+
chainSeq(): Promise<number | null>;
|
|
196
|
+
/**
|
|
197
|
+
* The base the store's chain is relative to: the newest build's, made in
|
|
198
|
+
* this process (see `ValOps.chainBaseSha`).
|
|
199
|
+
*/
|
|
200
|
+
newestOps(): ValOps;
|
|
201
|
+
chainBaseSha(): Promise<SourcesSha>;
|
|
228
202
|
getStat(params: {
|
|
229
203
|
baseSha: BaseSha;
|
|
230
204
|
schemaSha: SchemaSha;
|
|
@@ -235,6 +209,7 @@ export declare class ValOpsMemory extends ValOps {
|
|
|
235
209
|
schemaSha: SchemaSha;
|
|
236
210
|
sourcesSha: SourcesSha;
|
|
237
211
|
patches: PatchId[];
|
|
212
|
+
seq: number;
|
|
238
213
|
}>;
|
|
239
214
|
/** Resolves on the next write here, or when the poll interval runs out. */
|
|
240
215
|
private parkUntilChange;
|
|
@@ -1,6 +1,7 @@
|
|
|
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";
|
|
4
5
|
type Versions = {
|
|
5
6
|
versions?: {
|
|
6
7
|
core?: string;
|
|
@@ -253,6 +254,15 @@ commitPrepared?: (commit: {
|
|
|
253
254
|
* `ValServerOptions.publishOverride`.
|
|
254
255
|
*/
|
|
255
256
|
publishOverride?: (context: CommitContext) => Promise<CommitResult>): Promise<ValServer>;
|
|
257
|
+
/**
|
|
258
|
+
* The runtime the draft readers read through (`initValContent`,
|
|
259
|
+
* `initValRsc`): the same one `createValServer` builds its server on, for the
|
|
260
|
+
* same `valModules` and options (`valRuntime`), so a save through the API
|
|
261
|
+
* moves what the readers read. The readers read its head directly, with the
|
|
262
|
+
* request's session (`ValRuntime.authorize`): no private server, and no
|
|
263
|
+
* request to it.
|
|
264
|
+
*/
|
|
265
|
+
export declare function createValRuntime(valModules: ValModules, route: string, opts: ValApiOptions, config: ValConfig): Promise<ValRuntime>;
|
|
256
266
|
/**
|
|
257
267
|
* `fs` and `path` are imported INSIDE this function, not at the top of the file.
|
|
258
268
|
*
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { ValContentVersion, ValProposal } from "./proposal.js";
|
|
2
2
|
import { ValModules, ValConfig } from "@valbuild/core";
|
|
3
3
|
import { Api, ServerOf } from "@valbuild/shared/internal";
|
|
4
|
-
import { z } from "zod";
|
|
5
4
|
import { AuthorId, CommitSha, type GenericErrorMessage, type PreparedCommit } from "./ValOps.js";
|
|
6
5
|
import type { ValPatchStore } from "./ValOpsMemory.js";
|
|
7
6
|
import type { ValServerPlatform } from "./platform.js";
|
|
@@ -197,14 +196,6 @@ export type ValServerCallbacks = {
|
|
|
197
196
|
onEnable: (success: boolean) => Promise<void>;
|
|
198
197
|
onDisable: (success: boolean) => Promise<void>;
|
|
199
198
|
};
|
|
200
|
-
declare const IntegratedServerJwtPayload: z.ZodObject<{
|
|
201
|
-
sub: z.ZodString;
|
|
202
|
-
exp: z.ZodNumber;
|
|
203
|
-
token: z.ZodString;
|
|
204
|
-
org: z.ZodString;
|
|
205
|
-
project: z.ZodString;
|
|
206
|
-
}, z.core.$strip>;
|
|
207
|
-
export type IntegratedServerJwtPayload = z.infer<typeof IntegratedServerJwtPayload>;
|
|
208
199
|
export declare const ENABLE_COOKIE_VALUE: {
|
|
209
200
|
readonly value: "true";
|
|
210
201
|
readonly options: {
|
|
@@ -222,4 +213,3 @@ export declare function getRedirectUrl(query: {
|
|
|
222
213
|
};
|
|
223
214
|
};
|
|
224
215
|
export declare function guessMimeTypeFromPath(filePath: string): string | null;
|
|
225
|
-
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ValConfig, type ValModules } from "@valbuild/core";
|
|
2
2
|
import { type ValServerConfig } from "../ValServer.js";
|
|
3
3
|
import type { ValPatchStore } from "../ValOpsMemory.js";
|
|
4
|
+
import type { ValRuntime } from "../valRuntime.js";
|
|
4
5
|
/** A `fetch`, as far as the Studio's client calls one. */
|
|
5
6
|
export type InTabFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
6
7
|
/**
|
|
@@ -16,7 +17,8 @@ export type InTabFetch = (input: RequestInfo | URL, init?: RequestInit) => Promi
|
|
|
16
17
|
* publish reads `.val.ts` text), and without authentication, because the only
|
|
17
18
|
* caller is the page this runs in.
|
|
18
19
|
*/
|
|
19
|
-
export declare function createInTabValFetch(valModules: ValModules, options:
|
|
20
|
+
export declare function createInTabValFetch(valModules: ValModules, options: InTabValOptions): InTabFetch;
|
|
21
|
+
export type InTabValOptions = {
|
|
20
22
|
config: ValConfig;
|
|
21
23
|
/**
|
|
22
24
|
* Where edits live. Memory by default, which is what the demo wants: the
|
|
@@ -27,4 +29,19 @@ export declare function createInTabValFetch(valModules: ValModules, options: {
|
|
|
27
29
|
route?: string;
|
|
28
30
|
/** The binding that started it, for the Studio's version list. */
|
|
29
31
|
framework?: ValServerConfig["framework"];
|
|
30
|
-
}
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* {@link createInTabValFetch}, and the runtime behind it: the data layer the
|
|
35
|
+
* server reads through, whose head (`runtime.ops.head`) is what a draft
|
|
36
|
+
* reader reads (`serverDraftSource`). So a caller that reads in-process reads
|
|
37
|
+
* what the API serves, through the same object, as `createValRuntime` gives
|
|
38
|
+
* a server's readers. The isolate probe (`scenarios/measure/isolate/`) reads
|
|
39
|
+
* a draft page this way.
|
|
40
|
+
*
|
|
41
|
+
* `authorize` lets every session read the draft: the server is made with
|
|
42
|
+
* `unsafelyAllowUnauthenticated`, and the only caller is the page it runs in.
|
|
43
|
+
*/
|
|
44
|
+
export declare function createInTabVal(valModules: ValModules, options: InTabValOptions): {
|
|
45
|
+
fetch: InTabFetch;
|
|
46
|
+
runtime: ValRuntime;
|
|
47
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ModuleFilePath, PatchId } from "@valbuild/core";
|
|
2
|
+
import type { ValCommit } from "@valbuild/shared/internal";
|
|
3
|
+
import type { CommitSha } from "./ValOps.js";
|
|
4
|
+
/**
|
|
5
|
+
* The patches a json entry render should apply, out of the whole chain:
|
|
6
|
+
*
|
|
7
|
+
* 1. this module's, since the chain is branch-wide;
|
|
8
|
+
* 2. a patch published after this build is kept: this build does not have it.
|
|
9
|
+
* One already in the build is dropped. `draftOverlay` decides which is
|
|
10
|
+
* which, from `commits`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function draftModulePatches<T extends {
|
|
13
|
+
path: ModuleFilePath;
|
|
14
|
+
patchId: PatchId;
|
|
15
|
+
appliedAt: {
|
|
16
|
+
commitSha: CommitSha;
|
|
17
|
+
} | null;
|
|
18
|
+
}>(patches: T[], moduleFilePath: ModuleFilePath,
|
|
19
|
+
/** The commits content says came after this build: see `draftOverlay`. */
|
|
20
|
+
commits?: Pick<ValCommit, "commitSha">[]): T[];
|
|
21
|
+
/**
|
|
22
|
+
* The patches a DRAFT applies on top of this build's own source: the pending
|
|
23
|
+
* ones, and the ones published AFTER this build, in chain order -- with
|
|
24
|
+
* `appliedAt` cleared on the latter, because this build has none of them.
|
|
25
|
+
*
|
|
26
|
+
* Content places every caller at its own build (`getApplicablePatchesAndCommits`
|
|
27
|
+
* in valbuild/home: "the earliest the caller has not seen") and returns the
|
|
28
|
+
* commits after it as `commits`. A patch applied at one of those was
|
|
29
|
+
* published after this build and is not in it, so a draft has to apply it --
|
|
30
|
+
* skipping it showed the build's old value from the publish until the next
|
|
31
|
+
* build went live. `/sources/~` already applies them (`getSources` walks every
|
|
32
|
+
* patch it is given); the `.jsonValues()` entry path skipped them.
|
|
33
|
+
*
|
|
34
|
+
* A patch applied at a commit NOT in that list is already in this build --
|
|
35
|
+
* content returns one only because it was asked for by id -- and is dropped:
|
|
36
|
+
* applying it again would apply it twice. Without `commits` (a store that
|
|
37
|
+
* does not report them) every applied patch is dropped, as before. Only
|
|
38
|
+
* `ValOpsHttp` ever reports `appliedAt`; `fs` and memory stores report `null`.
|
|
39
|
+
*
|
|
40
|
+
* Chain order, not published-first, because that is the order the Studio
|
|
41
|
+
* applies them in, and a draft page starts from the server's answer and is
|
|
42
|
+
* then kept up to date by the Studio's: the two must agree.
|
|
43
|
+
*
|
|
44
|
+
* For the reads that render a draft only. What to COMMIT still keys on
|
|
45
|
+
* `appliedAt`: a published patch must never be published again.
|
|
46
|
+
*/
|
|
47
|
+
export declare function draftOverlay<T extends {
|
|
48
|
+
appliedAt: {
|
|
49
|
+
commitSha: CommitSha;
|
|
50
|
+
} | null;
|
|
51
|
+
}>(patches: T[], commits: Pick<ValCommit, "commitSha">[] | undefined): T[];
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { type Json, type ModuleFilePath, type SelectorSource, type ValModule } from "@valbuild/core";
|
|
2
|
+
import { type ContentSource, type ModuleVersion } from "@valbuild/shared/internal";
|
|
3
|
+
import type { ValRuntime } from "./valRuntime.js";
|
|
4
|
+
type Cookies = {
|
|
5
|
+
get(name: string): {
|
|
6
|
+
name: string;
|
|
7
|
+
value: string;
|
|
8
|
+
} | undefined;
|
|
9
|
+
};
|
|
10
|
+
type Headers = {
|
|
11
|
+
get(name: string): string | null;
|
|
12
|
+
};
|
|
13
|
+
/** One module {@link readDraftChanges} read: what a reader's `reads` record. */
|
|
14
|
+
export type DraftModuleRead = {
|
|
15
|
+
path: ModuleFilePath;
|
|
16
|
+
from: "server-draft";
|
|
17
|
+
version: ModuleVersion | null;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* The modules the editor's draft CHANGES, for this request: what
|
|
21
|
+
* `fetchValDraft` hands to `<ValProvider draft>`, in `@valbuild/tanstack/server`
|
|
22
|
+
* and `@valbuild/next/rsc` alike -- this is the whole of the read, and the
|
|
23
|
+
* frameworks add only where draft mode and the cookies come from (and, in
|
|
24
|
+
* TanStack, a proposal's snapshot).
|
|
25
|
+
*
|
|
26
|
+
* `null` -- and no read at all -- unless draft mode is on: a visitor pays one
|
|
27
|
+
* cookie lookup. Otherwise the head's modules a patch touches or a publish
|
|
28
|
+
* wrote and the host has not rebuilt since, with the `.jsonValues()` entries
|
|
29
|
+
* the draft changes in place of their markers, and the version of each (so
|
|
30
|
+
* the page compares versions with what the Studio relays, not content).
|
|
31
|
+
*
|
|
32
|
+
* Also `null` when the session is not one the server accepts, and when the
|
|
33
|
+
* draft could not be read at all (logged): published content, as before this
|
|
34
|
+
* existed -- a draft page that renders the site is a degraded preview, one
|
|
35
|
+
* that fails to render is an outage.
|
|
36
|
+
*/
|
|
37
|
+
export declare function readDraftChanges(opts: {
|
|
38
|
+
runtime: Promise<ValRuntime>;
|
|
39
|
+
isEnabled: () => Promise<boolean>;
|
|
40
|
+
getCookies: () => Promise<Cookies>;
|
|
41
|
+
}): Promise<{
|
|
42
|
+
sources: Record<ModuleFilePath, Json>;
|
|
43
|
+
versions: Record<ModuleFilePath, ModuleVersion>;
|
|
44
|
+
reads: DraftModuleRead[];
|
|
45
|
+
} | null>;
|
|
46
|
+
/**
|
|
47
|
+
* The draft, as a source: this process's head, for this request's session.
|
|
48
|
+
* Created per request. A module whose newest version is the bundle's own
|
|
49
|
+
* passes, so the reader's bundle answers it and nothing is read; any other is
|
|
50
|
+
* the head's (with the `.jsonValues()` entries the draft changes filled in).
|
|
51
|
+
* An entry is the head's, resolved once per version.
|
|
52
|
+
*
|
|
53
|
+
* Every error is a `pass`, logged: a draft that cannot be read is the
|
|
54
|
+
* published content, which a page can render.
|
|
55
|
+
*
|
|
56
|
+
* The request reads ONE chain: the head is asked "has the chain moved?" once,
|
|
57
|
+
* at the first read, and every module and entry after it is read at that
|
|
58
|
+
* chain. In http mode that question is a request to the content service, and
|
|
59
|
+
* a page reads tens of modules and entries; and a page is one answer, never
|
|
60
|
+
* half of one chain and half of the next.
|
|
61
|
+
*
|
|
62
|
+
* `modules: false` (the single-entry readers): every module passes.
|
|
63
|
+
*/
|
|
64
|
+
export declare function serverDraftSource(opts: {
|
|
65
|
+
runtime: Promise<ValRuntime>;
|
|
66
|
+
session: string | undefined;
|
|
67
|
+
modules: boolean;
|
|
68
|
+
}): ContentSource;
|
|
69
|
+
/**
|
|
70
|
+
* Whether this request reads the draft, and the source to read it from.
|
|
71
|
+
*
|
|
72
|
+
* `enabled` is draft mode; it decides edit tags whether or not the draft can
|
|
73
|
+
* be read. The draft is `null` when draft mode is off, or the request's
|
|
74
|
+
* cookies cannot be read (outside a request: published content).
|
|
75
|
+
*
|
|
76
|
+
* `where` names where these readers may be called, for the errors a misuse
|
|
77
|
+
* gets; without it (the single-entry readers) they stay quiet, as they were.
|
|
78
|
+
*/
|
|
79
|
+
export declare function draftForRequest(opts: {
|
|
80
|
+
runtime: Promise<ValRuntime>;
|
|
81
|
+
isEnabled: () => Promise<boolean>;
|
|
82
|
+
getCookies: () => Promise<Cookies>;
|
|
83
|
+
/**
|
|
84
|
+
* For module reads (`fetchVal`). They ask for the request's host first, as
|
|
85
|
+
* `fetchVal` always did, and a request without one reads no module from
|
|
86
|
+
* the draft.
|
|
87
|
+
*/
|
|
88
|
+
modules?: {
|
|
89
|
+
getHeaders: () => Promise<Headers>;
|
|
90
|
+
};
|
|
91
|
+
where?: string;
|
|
92
|
+
}): Promise<{
|
|
93
|
+
enabled: boolean;
|
|
94
|
+
draft: ContentSource | null;
|
|
95
|
+
}>;
|
|
96
|
+
/**
|
|
97
|
+
* The version of the schema a reader's own code has for a module: what the
|
|
98
|
+
* readers hold a draft's version against (`layered`'s schema rule), so
|
|
99
|
+
* content is never read with a schema it was not made for. Hashed once per
|
|
100
|
+
* module object, which a build makes once: a load cost, not a read cost.
|
|
101
|
+
*/
|
|
102
|
+
export declare function readerSchemaVersion(module: ValModule<SelectorSource>): string | null;
|
|
103
|
+
export {};
|