@valbuild/server 0.132.1 → 0.133.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 +63 -0
- package/dist/declarations/src/ValOps.d.ts +50 -1
- package/dist/declarations/src/ValOpsHttp.d.ts +83 -6
- package/dist/declarations/src/ValRouter.d.ts +23 -10
- package/dist/declarations/src/ValServer.d.ts +11 -2
- package/dist/declarations/src/history/types.d.ts +4 -2
- package/dist/valbuild-server.cjs.dev.js +346 -38
- package/dist/valbuild-server.cjs.prod.js +346 -38
- package/dist/valbuild-server.esm.js +346 -38
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,68 @@
|
|
|
1
1
|
# @valbuild/server
|
|
2
2
|
|
|
3
|
+
## 0.133.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#700](https://github.com/valbuild/val/pull/700) [`802412b`](https://github.com/valbuild/val/commit/802412b92c06bc1abbca78c86885e39c8710dd83) Thanks [@freekh](https://github.com/freekh)! - http mode no longer needs a git repository
|
|
8
|
+
|
|
9
|
+
A Val app can now run in http mode with no commit and no branch — its content
|
|
10
|
+
service is the store of record, and git is an optional mirror of the code. This
|
|
11
|
+
is what `fs` mode has always done: it has never had git, and it works.
|
|
12
|
+
|
|
13
|
+
Before this, `VAL_API_KEY` and `VAL_SECRET` were not enough. `VAL_GIT_COMMIT`
|
|
14
|
+
and `VAL_GIT_BRANCH` were required too, so a deployment with no commit to name
|
|
15
|
+
either threw at boot or fell through to `fs` mode and reached for a working
|
|
16
|
+
tree that was not there.
|
|
17
|
+
|
|
18
|
+
**Breaking, if you pass `http` options in code.** `gitCommit` and `gitBranch`
|
|
19
|
+
are replaced by one optional `git`:
|
|
20
|
+
|
|
21
|
+
```diff
|
|
22
|
+
initValServer(valModules, config, {
|
|
23
|
+
http: {
|
|
24
|
+
apiKey,
|
|
25
|
+
valSecret,
|
|
26
|
+
- gitCommit: process.env.VAL_GIT_COMMIT,
|
|
27
|
+
- gitBranch: "main",
|
|
28
|
+
+ // Only for a project whose content is mirrored into a repository.
|
|
29
|
+
+ // Omit it entirely otherwise.
|
|
30
|
+
+ git: { commit: process.env.VAL_GIT_COMMIT, branch: "main" },
|
|
31
|
+
},
|
|
32
|
+
})
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`VAL_GIT_COMMIT` and `VAL_GIT_BRANCH` still work and are still read; they are
|
|
36
|
+
simply no longer required. Set both or neither — a commit without a branch, or
|
|
37
|
+
a branch without a commit, is refused at startup with a message naming the
|
|
38
|
+
missing half, rather than failing later at a publish.
|
|
39
|
+
|
|
40
|
+
**What a commit is for, where you have one.** Turning pending patches into new
|
|
41
|
+
`.val.ts` text means reading the current text first, and that read goes to the
|
|
42
|
+
content service at that commit. It is the publish path, not the serving path: a
|
|
43
|
+
committed render reads the source compiled into the build and asks the content
|
|
44
|
+
service nothing. With no repository there is nothing to write `.val.ts` into,
|
|
45
|
+
so a publish records the module's data and its schema and skips the file — and
|
|
46
|
+
that data is what history reads, so nothing is lost.
|
|
47
|
+
|
|
48
|
+
**A publish can now be refused by name, before it is attempted.** If a project
|
|
49
|
+
mirrors its commits into a repository but the running deployment was built
|
|
50
|
+
before that repository existed, it has no commit to write the mirror against.
|
|
51
|
+
Publishing anyway would save the content and silently leave the repository
|
|
52
|
+
behind. The Studio now disables Publish and shows why, and `/save` refuses with
|
|
53
|
+
a `no-base` code instead of failing partway.
|
|
54
|
+
|
|
55
|
+
**Also:** `ValCommit` and `HistoricalCommit` have nullable `parentCommitSha`
|
|
56
|
+
and `clientCommitSha`, and `/stat`'s `commitSha` is optional. A root commit has
|
|
57
|
+
no parent, and a publisher with no repository does not report where it was. If
|
|
58
|
+
you read these fields, handle `null`.
|
|
59
|
+
|
|
60
|
+
### Patch Changes
|
|
61
|
+
|
|
62
|
+
- Updated dependencies [[`2b9a51b`](https://github.com/valbuild/val/commit/2b9a51b7dbe2dff53b7686a4f3b7eb9bc5784fae), [`802412b`](https://github.com/valbuild/val/commit/802412b92c06bc1abbca78c86885e39c8710dd83)]:
|
|
63
|
+
- @valbuild/ui@0.133.0
|
|
64
|
+
- @valbuild/shared@0.133.0
|
|
65
|
+
|
|
3
66
|
## 0.132.1
|
|
4
67
|
|
|
5
68
|
### Patch Changes
|
|
@@ -137,7 +137,8 @@ export declare abstract class ValOps {
|
|
|
137
137
|
nonce: string;
|
|
138
138
|
baseSha: BaseSha;
|
|
139
139
|
schemaSha: SchemaSha;
|
|
140
|
-
|
|
140
|
+
/** Absent for a project with no repository. See `git` on ValApiOptions. */
|
|
141
|
+
commitSha?: CommitSha;
|
|
141
142
|
sourcesSha: SourcesSha;
|
|
142
143
|
patches: PatchId[];
|
|
143
144
|
} | {
|
|
@@ -401,6 +402,42 @@ export declare abstract class ValOps {
|
|
|
401
402
|
} | {
|
|
402
403
|
errorType: "patch-head-conflict";
|
|
403
404
|
}>>;
|
|
405
|
+
/**
|
|
406
|
+
* Why a publish cannot happen here, or `null` when one can.
|
|
407
|
+
*
|
|
408
|
+
* Named rather than thrown, and asked BEFORE the click: the Studio shows the
|
|
409
|
+
* reason and disables the action, instead of letting someone write a commit
|
|
410
|
+
* message and then meeting a failure from four layers down.
|
|
411
|
+
*
|
|
412
|
+
* `no-base` is the only code so far and means what it says: there is nowhere
|
|
413
|
+
* for this publish's commit to be based. Note which way round that is --
|
|
414
|
+
* a project whose content service is the store of record always HAS a base
|
|
415
|
+
* (the service's own chain, which mints its own shas), so the refusal is not
|
|
416
|
+
* about missing git. It is about a deployment that cannot do what its
|
|
417
|
+
* project requires.
|
|
418
|
+
*/
|
|
419
|
+
publishRefusal(): PublishRefusal | null;
|
|
420
|
+
/**
|
|
421
|
+
* Whether a commit here produces `.val.ts` TEXT as well as data.
|
|
422
|
+
*
|
|
423
|
+
* True everywhere there is somewhere to put it: a working tree in `fs` mode,
|
|
424
|
+
* a host holding its own source in memory mode, a git repository in `http`
|
|
425
|
+
* mode. False for an `http` project whose content service is the store of
|
|
426
|
+
* record and which has no repository attached -- see `git` on
|
|
427
|
+
* {@link ValApiOptions}.
|
|
428
|
+
*
|
|
429
|
+
* WHAT IS NOT AFFECTED, and it is the part worth being sure of:
|
|
430
|
+
* `moduleVersions` -- what each changed module IS after the commit, with its
|
|
431
|
+
* schema -- comes from `getSources(analysis)`, which applies the ops to
|
|
432
|
+
* Source in the stores. It does not go near the file text. So a commit with
|
|
433
|
+
* no mirror still records everything history and a later `connect-github`
|
|
434
|
+
* fold need; what it does not record is a rendering of that data as code.
|
|
435
|
+
*
|
|
436
|
+
* WHAT IS: the ops are no longer applied to the file text as well, so a
|
|
437
|
+
* patch that would not fit the `.val.ts` is not reported here. That check
|
|
438
|
+
* only ever existed for the text being produced, and there is none.
|
|
439
|
+
*/
|
|
440
|
+
protected readonly mirrorsSourceFiles: boolean;
|
|
404
441
|
/**
|
|
405
442
|
* Take the `.val.ts` text a commit produced as the new committed source.
|
|
406
443
|
*
|
|
@@ -624,6 +661,18 @@ export type OpsMetadata<T extends "file" | "image"> = {
|
|
|
624
661
|
}))[];
|
|
625
662
|
};
|
|
626
663
|
export type BinaryFileType = "file" | "image";
|
|
664
|
+
/**
|
|
665
|
+
* Why a publish is refused, in a form a person can be shown.
|
|
666
|
+
*
|
|
667
|
+
* `code` is for the Studio to branch on and `message` is what it says. Both,
|
|
668
|
+
* rather than a code and a lookup table on the client: the server knows what
|
|
669
|
+
* is actually missing -- which branch, which commit -- and a client-side table
|
|
670
|
+
* could only ever say the generic version.
|
|
671
|
+
*/
|
|
672
|
+
export type PublishRefusal = {
|
|
673
|
+
code: "no-base";
|
|
674
|
+
message: string;
|
|
675
|
+
};
|
|
627
676
|
export type PreparedCommit = {
|
|
628
677
|
/**
|
|
629
678
|
* Updated / new source files that are ready to be committed / saved.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type PatchId, type ModuleFilePath, ValModules } from "@valbuild/core";
|
|
2
2
|
import type { Patch as PatchT, ParentRef as ParentRefT } from "@valbuild/core/patch";
|
|
3
|
-
import { type AuthorId, type BaseSha, BinaryFileType, type CommitSha, GenericErrorMessage, MetadataOfType, OpsMetadata, PreparedCommit, ValOps, ValOpsOptions, WithGenericError, SaveSourceFilePatchResult, type PatchGroupMembership, SchemaSha, OrderedPatchesMetadata, OrderedPatches, SourcesSha } from "./ValOps.js";
|
|
3
|
+
import { type AuthorId, type BaseSha, BinaryFileType, type CommitSha, GenericErrorMessage, MetadataOfType, OpsMetadata, PreparedCommit, ValOps, ValOpsOptions, WithGenericError, SaveSourceFilePatchResult, type PatchGroupMembership, SchemaSha, OrderedPatchesMetadata, OrderedPatches, SourcesSha, type PublishRefusal } from "./ValOps.js";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import type { HistoryError } from "./history/HistoryError.js";
|
|
6
6
|
import type { AffectedFile, StoredModuleVersion, CommitPage, CommitPatch, HistoricalCommit } from "./history/types.js";
|
|
@@ -23,16 +23,69 @@ export type PatchGroupMutationResult = {
|
|
|
23
23
|
export declare class ValOpsHttp extends ValOps {
|
|
24
24
|
private readonly contentUrl;
|
|
25
25
|
private readonly project;
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
/**
|
|
27
|
+
* The repository this project's commits are mirrored into, or `null`.
|
|
28
|
+
*
|
|
29
|
+
* `null` is a project whose content service is the store of record: it
|
|
30
|
+
* mints its own commit shas, and it knows this project's branch from the
|
|
31
|
+
* project itself. Every request below that would have carried a branch and
|
|
32
|
+
* a commit omits them instead, and the service answers from the project's
|
|
33
|
+
* own chain -- which is where those answers always came from.
|
|
34
|
+
*
|
|
35
|
+
* It is NOT a degraded mode. The one thing that genuinely needs a
|
|
36
|
+
* repository is producing the `.val.ts` text a commit mirrors, and a
|
|
37
|
+
* project with no repository has nothing to mirror into. See `git` on
|
|
38
|
+
* {@link ValApiOptions}.
|
|
39
|
+
*/
|
|
40
|
+
private readonly git;
|
|
28
41
|
private readonly authHeaders;
|
|
29
42
|
private readonly root;
|
|
30
43
|
/** Val's content service owns the store. See {@link ValOps.patchesAreLocal}. */
|
|
31
44
|
readonly patchesAreLocal = false;
|
|
32
45
|
/** See {@link ValOps.requiresAuth}. */
|
|
33
46
|
readonly requiresAuth = true;
|
|
34
|
-
|
|
35
|
-
|
|
47
|
+
/**
|
|
48
|
+
* A commit mirrors into `.val.ts` only when there is a repository.
|
|
49
|
+
*
|
|
50
|
+
* See {@link ValOps.mirrorsSourceFiles}. Set in the constructor rather than
|
|
51
|
+
* as an initialiser because it depends on `git`, and a class field
|
|
52
|
+
* initialiser runs before the constructor body has assigned it.
|
|
53
|
+
*/
|
|
54
|
+
protected readonly mirrorsSourceFiles: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* What the content service last said this project expects of its publisher.
|
|
57
|
+
*
|
|
58
|
+
* `null` until something has asked it, which in practice is the first poll.
|
|
59
|
+
* It is remembered rather than asked for on demand because the answer is
|
|
60
|
+
* only wanted on the publish path, and that path already fetches the
|
|
61
|
+
* patches it is publishing -- so a dedicated request would be a second round
|
|
62
|
+
* trip for two fields that just arrived.
|
|
63
|
+
*
|
|
64
|
+
* It can be one poll out of date, and that is the right amount: the thing it
|
|
65
|
+
* changes is whether this deployment can mirror commits into a repository,
|
|
66
|
+
* which changes when a project CONNECTS one -- and a project that has just
|
|
67
|
+
* connected is one whose builds are about to be replaced anyway.
|
|
68
|
+
*/
|
|
69
|
+
private projectExpectation;
|
|
70
|
+
constructor(contentUrl: string, project: string,
|
|
71
|
+
/**
|
|
72
|
+
* The repository this project's commits are mirrored into, or `null`.
|
|
73
|
+
*
|
|
74
|
+
* `null` is a project whose content service is the store of record: it
|
|
75
|
+
* mints its own commit shas, and it knows this project's branch from the
|
|
76
|
+
* project itself. Every request below that would have carried a branch and
|
|
77
|
+
* a commit omits them instead, and the service answers from the project's
|
|
78
|
+
* own chain -- which is where those answers always came from.
|
|
79
|
+
*
|
|
80
|
+
* It is NOT a degraded mode. The one thing that genuinely needs a
|
|
81
|
+
* repository is producing the `.val.ts` text a commit mirrors, and a
|
|
82
|
+
* project with no repository has nothing to mirror into. See `git` on
|
|
83
|
+
* {@link ValApiOptions}.
|
|
84
|
+
*/
|
|
85
|
+
git: {
|
|
86
|
+
commit: string;
|
|
87
|
+
branch: string;
|
|
88
|
+
} | null,
|
|
36
89
|
/**
|
|
37
90
|
* An api key (how the app itself authenticates) or a personal access token
|
|
38
91
|
* (how the CLI authenticates after `val login`). Same two shapes as
|
|
@@ -50,6 +103,29 @@ export declare class ValOpsHttp extends ValOps {
|
|
|
50
103
|
*/
|
|
51
104
|
root?: string;
|
|
52
105
|
});
|
|
106
|
+
/**
|
|
107
|
+
* A deployment that cannot mirror a project which expects to be mirrored.
|
|
108
|
+
*
|
|
109
|
+
* This is the one shape of "no base" that exists, and it is not the one it
|
|
110
|
+
* sounds like. A project with no repository is fine: the content service is
|
|
111
|
+
* the store of record for it and mints its own commit shas, so there is
|
|
112
|
+
* always somewhere for the commit to go. What is refused is the mismatch --
|
|
113
|
+
* a project whose commits are mirrored into a repository, being published by
|
|
114
|
+
* a build that was made before it had one and so has no commit to produce
|
|
115
|
+
* that mirror against.
|
|
116
|
+
*
|
|
117
|
+
* It is a REAL state rather than a defensive check: it is exactly what a
|
|
118
|
+
* deployment looks like between a project connecting a repository and its
|
|
119
|
+
* next build going out. Left unchecked, such a publish writes the data and
|
|
120
|
+
* silently fails to mirror it, and the repository quietly falls behind the
|
|
121
|
+
* content nobody is told about.
|
|
122
|
+
*
|
|
123
|
+
* `null` when the service did not say (see `project` on the response
|
|
124
|
+
* schema): an older content service is not evidence of anything, and
|
|
125
|
+
* refusing every publish against one would be a worse failure than not
|
|
126
|
+
* checking.
|
|
127
|
+
*/
|
|
128
|
+
publishRefusal(): PublishRefusal | null;
|
|
53
129
|
onInit(): Promise<void>;
|
|
54
130
|
getPresignedAuthNonce(profileId: string, corsOrigin: string): Promise<{
|
|
55
131
|
status: "success";
|
|
@@ -80,7 +156,8 @@ export declare class ValOpsHttp extends ValOps {
|
|
|
80
156
|
baseSha: BaseSha;
|
|
81
157
|
schemaSha: SchemaSha;
|
|
82
158
|
sourcesSha: SourcesSha;
|
|
83
|
-
|
|
159
|
+
/** Absent for a project with no repository. See `git` on ValApiOptions. */
|
|
160
|
+
commitSha?: CommitSha;
|
|
84
161
|
commits: ValCommit[];
|
|
85
162
|
deployments: ValDeployment[];
|
|
86
163
|
patches: PatchId[];
|
|
@@ -84,21 +84,34 @@ type ValServerOverrides = Partial<{
|
|
|
84
84
|
*/
|
|
85
85
|
patchStore: ValPatchStore;
|
|
86
86
|
/**
|
|
87
|
-
*
|
|
87
|
+
* The git commit this code was built from, and the branch a publish mirrors
|
|
88
|
+
* into -- for a project that HAS a repository.
|
|
88
89
|
*
|
|
89
|
-
*
|
|
90
|
+
* OPTIONAL, including in http mode, and absent is the normal case for a
|
|
91
|
+
* project whose content service is the store of record. It used to be
|
|
92
|
+
* required, which made a repository a precondition for editing anything: a
|
|
93
|
+
* deployment with no commit to name fell through to `fs` mode and reached
|
|
94
|
+
* for a working tree that was not there.
|
|
90
95
|
*
|
|
91
|
-
*
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
*
|
|
96
|
+
* What it is FOR, where there is one: a publish turns pending patches into
|
|
97
|
+
* new `.val.ts` text, and to patch a file you must first read it. That read
|
|
98
|
+
* goes to the content service AT THIS COMMIT. Give it a commit the deployed
|
|
99
|
+
* code did not come from and the publish writes over a different version of
|
|
100
|
+
* the file than the one the site is running.
|
|
96
101
|
*
|
|
97
|
-
*
|
|
102
|
+
* It is NOT what a committed render reads -- that reads the source compiled
|
|
103
|
+
* into the build and asks the content service nothing.
|
|
98
104
|
*
|
|
99
|
-
*
|
|
105
|
+
* A normal deploy bakes this at build time, because the commit really is a
|
|
106
|
+
* property of those bytes. `VAL_GIT_COMMIT` / `VAL_GIT_BRANCH` supply it
|
|
107
|
+
* where a build system sets environment variables instead.
|
|
108
|
+
*
|
|
109
|
+
* @example { commit: "e83c5163316f89bfbde7d9ab23ca2e25604af290", branch: "main" }
|
|
100
110
|
*/
|
|
101
|
-
|
|
111
|
+
git?: {
|
|
112
|
+
commit: string;
|
|
113
|
+
branch: string;
|
|
114
|
+
};
|
|
102
115
|
/**
|
|
103
116
|
* The base url of Val.
|
|
104
117
|
*
|
|
@@ -121,8 +121,17 @@ export type ValServerConfig = ValServerOptions & ({
|
|
|
121
121
|
mode: "http";
|
|
122
122
|
apiKey: string;
|
|
123
123
|
project: string;
|
|
124
|
-
|
|
125
|
-
|
|
124
|
+
/**
|
|
125
|
+
* The repository this project's commits are mirrored into, if any.
|
|
126
|
+
*
|
|
127
|
+
* Absent is a project whose content service is the store of record --
|
|
128
|
+
* which is every project that has not attached a repository, and the
|
|
129
|
+
* normal case. See `git` on {@link ValApiOptions}.
|
|
130
|
+
*/
|
|
131
|
+
git?: {
|
|
132
|
+
commit: string;
|
|
133
|
+
branch: string;
|
|
134
|
+
};
|
|
126
135
|
root?: string;
|
|
127
136
|
config: ValConfig;
|
|
128
137
|
}
|
|
@@ -4,8 +4,10 @@ import type { HistoryError } from "./HistoryError.js";
|
|
|
4
4
|
/** One commit, as history lists it. */
|
|
5
5
|
export type HistoricalCommit = {
|
|
6
6
|
commitSha: string;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
/** `null` for a root commit. See `ValCommit`. */
|
|
8
|
+
parentCommitSha: string | null;
|
|
9
|
+
/** `null` when the publisher did not say where it was. See `ValCommit`. */
|
|
10
|
+
clientCommitSha: string | null;
|
|
9
11
|
branch: string;
|
|
10
12
|
createdBranch: string | null;
|
|
11
13
|
creator: string | null;
|