@mistriwork/engine 1.0.0-rc.15 → 1.0.0-rc.16
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/dist/server/cli/startup.js +7 -2
- package/dist/server/cli/usage.d.ts +2 -0
- package/dist/server/cli/usage.js +12 -1
- package/dist/server/clientHttp.js +20 -3
- package/dist/server/config/profile.d.ts +10 -3
- package/dist/server/config/profile.js +28 -4
- package/dist/server/http/baselineHeaders.d.ts +13 -3
- package/dist/server/http/baselineHeaders.js +6 -0
- package/dist/server/http/frontDoor.d.ts +41 -0
- package/dist/server/http/frontDoor.js +36 -0
- package/dist/server/http/recordCompose.d.ts +3 -0
- package/dist/server/http/recordCompose.js +1 -0
- package/dist/server/http/serverCore.d.ts +2 -2
- package/dist/server/http/serverCore.js +16 -32
- package/dist/server/migrate/cli.js +8 -1
- package/dist/server/migrate/target.d.ts +8 -0
- package/dist/server/migrate/target.js +15 -0
- package/dist/server/seed/seed.js +46 -11
- package/dist/shared/appCards.d.ts +4 -0
- package/dist/shared/appCards.js +5 -0
- package/dist/shared/breakdown.js +8 -2
- package/dist/shared/computed.d.ts +16 -2
- package/dist/shared/computed.js +23 -4
- package/dist/shared/computedValue.js +23 -0
- package/dist/shared/mentionLookup.js +3 -1
- package/dist/shared/page.js +23 -5
- package/dist/shared/pageAnatomy.js +2 -0
- package/dist/shared/pageConfig.d.ts +1 -1
- package/dist/shared/pageConfig.js +68 -18
- package/dist/shared/pageModel.d.ts +42 -5
- package/dist/shared/pagePaths.js +4 -1
- package/dist/shared/pagePlans.d.ts +2 -2
- package/dist/shared/pagePlans.js +3 -3
- package/dist/shared/recordLabel.d.ts +12 -3
- package/dist/shared/recordLabel.js +39 -18
- package/dist/shared/recordReads.d.ts +6 -30
- package/dist/shared/recordReads.js +13 -1
- package/dist/shared/rollups.d.ts +4 -4
- package/dist/shared/rollups.js +1 -1
- package/dist/shared/schema.d.ts +7 -0
- package/dist/shared/schema.js +17 -0
- package/dist/shared/viewLabels.js +22 -17
- package/package.json +3 -2
|
@@ -10,7 +10,7 @@ import { configureServerSettings } from '../../adapters/serverSettings.js';
|
|
|
10
10
|
import { configurePostgresPools } from '../../adapters/postgresPool.js';
|
|
11
11
|
import { configureLockTimeout, configureWriterPool } from '../../adapters/writeLanes.js';
|
|
12
12
|
import { postgresPoolFlags, shutdownTimings } from './args.js';
|
|
13
|
-
import { didYouMean, packageVersion } from './usage.js';
|
|
13
|
+
import { commandsTaking, didYouMean, packageVersion } from './usage.js';
|
|
14
14
|
import { envName } from '../product.js';
|
|
15
15
|
/**
|
|
16
16
|
* `--help`, `--version`, a retired spelling, an unknown flag, a command one slip away: answered before anything
|
|
@@ -39,7 +39,12 @@ export async function answeredFirst(opts, product) {
|
|
|
39
39
|
line that said what was wrong. */
|
|
40
40
|
if (opts.unknown) {
|
|
41
41
|
const flag = opts.unknown.split(/[ =]/)[0];
|
|
42
|
-
|
|
42
|
+
/* A flag the usage does spell, typed where it does not apply: say where it does, not that it is unknown. A flag
|
|
43
|
+
given twice ("--jobs (may be supplied only once)") applies here; it is said as it is. */
|
|
44
|
+
const homes = product.flagWords.includes(flag) && !opts.unknown.includes('(') ? commandsTaking(product.usage, bin, flag) : [];
|
|
45
|
+
console.error(homes.length
|
|
46
|
+
? `${bin}: ${flag} is an option of ${homes.map((home) => `${bin} ${home}`).join(' and ')}, not of a start: name the command first (${bin} ${homes[0]} … ${flag}). ${bin} --help lists the options.`
|
|
47
|
+
: `${bin}: unknown option "${opts.unknown}".${opts.unknown === flag ? await didYouMean(flag, product.flagWords) : ''} ${bin} --help lists the options.`);
|
|
43
48
|
process.exit(1);
|
|
44
49
|
}
|
|
45
50
|
/* A word that is no file and is one slip from a command (`tablewalk chek`) was opened as a SQLite file of that
|
|
@@ -14,3 +14,5 @@ export declare function didYouMean(said: string, among: readonly string[]): Prom
|
|
|
14
14
|
* else the package's. Every package of the workspace carries the one version.
|
|
15
15
|
*/
|
|
16
16
|
export declare function packageVersion(): Promise<string>;
|
|
17
|
+
/** The commands whose usage spells `flag` (`mistri schema --brief`), for a flag typed where no command takes it. */
|
|
18
|
+
export declare function commandsTaking(usage: string, bin: string, flag: string): string[];
|
package/dist/server/cli/usage.js
CHANGED
|
@@ -15,7 +15,8 @@ export function flagWordsOf(usage) {
|
|
|
15
15
|
/** What was probably meant, said the way a person would type it, or nothing when nothing is near. */
|
|
16
16
|
export async function didYouMean(said, among) {
|
|
17
17
|
const { distance, nearest } = await import('../../shared/suggest.js');
|
|
18
|
-
|
|
18
|
+
/* Never the spelling that was typed: "Did you mean --brief?" to --brief is no help. */
|
|
19
|
+
const near = nearest(said, among.filter((word) => word !== said));
|
|
19
20
|
return near !== undefined && distance(said.toLowerCase(), near.toLowerCase()) <= Math.max(1, Math.floor(said.length / 3))
|
|
20
21
|
? ` Did you mean ${near}?`
|
|
21
22
|
: '';
|
|
@@ -36,3 +37,13 @@ export async function packageVersion() {
|
|
|
36
37
|
return '0.0.0';
|
|
37
38
|
}
|
|
38
39
|
}
|
|
40
|
+
/** The commands whose usage spells `flag` (`mistri schema --brief`), for a flag typed where no command takes it. */
|
|
41
|
+
export function commandsTaking(usage, bin, flag) {
|
|
42
|
+
const out = new Set();
|
|
43
|
+
for (const line of usage.split('\n')) {
|
|
44
|
+
const command = new RegExp(`^ {2}${bin} ([a-z][a-z-]*)(?=\\s|$)`).exec(line)?.[1];
|
|
45
|
+
if (command && new RegExp(`(?<![\\w-])${flag}(?![\\w-])`).test(line))
|
|
46
|
+
out.add(command);
|
|
47
|
+
}
|
|
48
|
+
return [...out];
|
|
49
|
+
}
|
|
@@ -9,6 +9,7 @@ import { headingWeight, inheritThemePreset, lookNavRole } from '../shared/themeP
|
|
|
9
9
|
import { typeTokens } from '../shared/themeType.js';
|
|
10
10
|
import { fieldEdge } from '../shared/themeColor.js';
|
|
11
11
|
import { recipeAttributes } from '../shared/themeRecipes.js';
|
|
12
|
+
import { APP_PAGE_PERMISSIONS_POLICY } from './http/baselineHeaders.js';
|
|
12
13
|
const MIME = {
|
|
13
14
|
'.html': 'text/html; charset=utf-8',
|
|
14
15
|
'.js': 'text/javascript; charset=utf-8',
|
|
@@ -112,6 +113,11 @@ function withFrameAncestors(policy, origins) {
|
|
|
112
113
|
return policy;
|
|
113
114
|
return policy.replace("frame-ancestors 'self'", ["frame-ancestors 'self'", ...origins].join(' '));
|
|
114
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* An App's page may use the camera (the scan input); the database browser's
|
|
118
|
+
* has no such input and keeps the baseline's refusal (http/baselineHeaders.ts).
|
|
119
|
+
*/
|
|
120
|
+
const pagePermissions = (shell) => shell?.workbench ? {} : { 'permissions-policy': APP_PAGE_PERMISSIONS_POLICY };
|
|
115
121
|
/** A page's whole policy: its own, the served Apps' egress, and who may frame it. */
|
|
116
122
|
const pagePolicy = (policy, shell) => shell?.unframed
|
|
117
123
|
? withEgress(policy, shell.egress).replace("frame-ancestors 'self'", "frame-ancestors 'none'")
|
|
@@ -451,6 +457,7 @@ export async function serveClient(files, req, res, shell) {
|
|
|
451
457
|
...(data || shell?.branding?.private ? { vary: 'Cookie' } : {}),
|
|
452
458
|
'x-content-type-options': 'nosniff',
|
|
453
459
|
'content-security-policy': pagePolicy(shellPolicy(html, { fromSource: true, socket: vite.socket }), shell),
|
|
460
|
+
...pagePermissions(shell),
|
|
454
461
|
});
|
|
455
462
|
res.end(head ? undefined : html);
|
|
456
463
|
}
|
|
@@ -621,7 +628,12 @@ export function builtClient(dir) {
|
|
|
621
628
|
'x-content-type-options': 'nosniff',
|
|
622
629
|
'content-type': asset.type,
|
|
623
630
|
vary: asset.variants.length > 1 ? 'Accept-Encoding, Cookie' : 'Cookie',
|
|
624
|
-
...(asset.policy
|
|
631
|
+
...(asset.policy
|
|
632
|
+
? {
|
|
633
|
+
'content-security-policy': pagePolicy(shell.mount?.base ? shellPolicy(text) : asset.policy, shell),
|
|
634
|
+
...pagePermissions(shell),
|
|
635
|
+
}
|
|
636
|
+
: {}),
|
|
625
637
|
};
|
|
626
638
|
if (head) {
|
|
627
639
|
res.writeHead(200, headers).end();
|
|
@@ -645,7 +657,12 @@ export function builtClient(dir) {
|
|
|
645
657
|
'cache-control': privately ? PERSONAL : 'no-cache',
|
|
646
658
|
...(!privately ? { etag: strongTag(body) } : {}),
|
|
647
659
|
'x-content-type-options': 'nosniff',
|
|
648
|
-
...(asset.policy
|
|
660
|
+
...(asset.policy
|
|
661
|
+
? {
|
|
662
|
+
'content-security-policy': pagePolicy(shell?.mount?.base ? shellPolicy(text) : asset.policy, shell),
|
|
663
|
+
...pagePermissions(shell),
|
|
664
|
+
}
|
|
665
|
+
: {}),
|
|
649
666
|
...(asset.variants.length > 1 || privately
|
|
650
667
|
? { vary: [asset.variants.length > 1 ? 'Accept-Encoding' : '', privately ? 'Cookie' : ''].filter(Boolean).join(', ') }
|
|
651
668
|
: {}),
|
|
@@ -669,7 +686,7 @@ export function builtClient(dir) {
|
|
|
669
686
|
'cache-control': asset.cache,
|
|
670
687
|
etag: variant.etag,
|
|
671
688
|
'x-content-type-options': 'nosniff',
|
|
672
|
-
...(asset.policy ? { 'content-security-policy': pagePolicy(asset.policy, shell) } : {}),
|
|
689
|
+
...(asset.policy ? { 'content-security-policy': pagePolicy(asset.policy, shell), ...pagePermissions(shell) } : {}),
|
|
673
690
|
};
|
|
674
691
|
if (asset.variants.length > 1)
|
|
675
692
|
headers.vary = 'Accept-Encoding';
|
|
@@ -27,7 +27,7 @@ interface ProjectContext {
|
|
|
27
27
|
};
|
|
28
28
|
readonly app?: {
|
|
29
29
|
readonly path: string;
|
|
30
|
-
readonly from: 'flag' | 'profile';
|
|
30
|
+
readonly from: 'flag' | 'profile' | 'cwd';
|
|
31
31
|
};
|
|
32
32
|
readonly entries: Partial<Record<ProfileEntry, {
|
|
33
33
|
readonly path: string;
|
|
@@ -42,13 +42,20 @@ export declare class ProfileRefusal extends Error {
|
|
|
42
42
|
/** What an App command takes of the profile: the App, and which entries. */
|
|
43
43
|
export interface ProfileTakes {
|
|
44
44
|
readonly entries: readonly ProfileEntry[];
|
|
45
|
-
/** `
|
|
46
|
-
readonly
|
|
45
|
+
/** Without `--app` or a profile's `dir`, the working directory is the App when it holds an App entry. */
|
|
46
|
+
readonly cwdApp?: boolean;
|
|
47
47
|
/** The command prints the context in its own output and `--json` (check, migrate); another says it on stderr. */
|
|
48
48
|
readonly says?: boolean;
|
|
49
49
|
/** False where the command reads no App (`migrate diff` reads schema.sql and the config's connection). */
|
|
50
50
|
readonly app?: boolean;
|
|
51
51
|
}
|
|
52
|
+
/** Whether a directory holds an App entry. */
|
|
53
|
+
export declare const holdsApp: (dir: string) => boolean;
|
|
54
|
+
/**
|
|
55
|
+
* A word typed where a database, a route or a target goes that is an App's directory: the App is named with
|
|
56
|
+
* `--app`, never by position, so it is refused rather than read as one. Undefined when the word is anything else.
|
|
57
|
+
*/
|
|
58
|
+
export declare function appDirectoryWord(command: string, word: string | undefined): string | undefined;
|
|
52
59
|
/**
|
|
53
60
|
* The config file a run reads, by the one order: `--config`, the App's own, the working directory's, the person's
|
|
54
61
|
* own. Undefined when there is none (a run on a database named by `--db`).
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* The block takes paths and nothing else: a `${NAME}` reference, a key it does not know, or a file that is not
|
|
16
16
|
* there is refused by name. It is not a second App definition: it names modules and defines nothing.
|
|
17
17
|
*/
|
|
18
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
18
|
+
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
19
19
|
import { homedir } from 'node:os';
|
|
20
20
|
import { dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
21
21
|
import { configFileName, product } from '../product.js';
|
|
@@ -25,6 +25,26 @@ const PROFILE_KEYS = ['dir', ...Object.keys(PROFILE_ENTRIES)];
|
|
|
25
25
|
/** A profile that cannot be used: refused before anything is read. */
|
|
26
26
|
export class ProfileRefusal extends Error {
|
|
27
27
|
}
|
|
28
|
+
/** The files an App's directory is known by: the entry `loadApp` reads. */
|
|
29
|
+
const APP_ENTRY_FILES = ['app.ts', 'app.mjs', 'app.json'];
|
|
30
|
+
/** Whether a directory holds an App entry. */
|
|
31
|
+
export const holdsApp = (dir) => APP_ENTRY_FILES.some((name) => existsSync(join(dir, name)));
|
|
32
|
+
/**
|
|
33
|
+
* A word typed where a database, a route or a target goes that is an App's directory: the App is named with
|
|
34
|
+
* `--app`, never by position, so it is refused rather than read as one. Undefined when the word is anything else.
|
|
35
|
+
*/
|
|
36
|
+
export function appDirectoryWord(command, word) {
|
|
37
|
+
if (word === undefined || word.startsWith('-'))
|
|
38
|
+
return undefined;
|
|
39
|
+
try {
|
|
40
|
+
if (!statSync(word).isDirectory() || !holdsApp(word))
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
return `${word} is an App's directory, and an App is named with --app: ${command} --app ${word}`;
|
|
47
|
+
}
|
|
28
48
|
const shown = (path) => {
|
|
29
49
|
const near = relative(process.cwd(), path);
|
|
30
50
|
return !near ? '.' : near.startsWith('..') || isAbsolute(near) ? path : near;
|
|
@@ -117,8 +137,7 @@ export function applyProfile(argv, takes, env = process.env) {
|
|
|
117
137
|
/* A suite's Apps are the suite's to name (`migrate stores up --suite`): the profile's one App is not added to it. */
|
|
118
138
|
const suite = out.includes('--suite');
|
|
119
139
|
const apps = flagged(out, '--app');
|
|
120
|
-
const
|
|
121
|
-
const named = apps.length === 1 ? apps[0] : positional;
|
|
140
|
+
const named = apps.length === 1 ? apps[0] : undefined;
|
|
122
141
|
const explicit = flagged(out, '--config').at(-1);
|
|
123
142
|
const naming = out.includes('--db') || out.includes('-d');
|
|
124
143
|
const found = naming && explicit === undefined
|
|
@@ -139,6 +158,11 @@ export function applyProfile(argv, takes, env = process.env) {
|
|
|
139
158
|
app = { path: profile.dir, from: 'profile' };
|
|
140
159
|
out.push('--app', shown(profile.dir));
|
|
141
160
|
}
|
|
161
|
+
else if (apps.length === 0 && takes.cwdApp && !suite && takes.app !== false && holdsApp('.')) {
|
|
162
|
+
/* The one rule: no --app and no profile, the App is the directory the person is in, when it is one. */
|
|
163
|
+
app = { path: resolve('.'), from: 'cwd' };
|
|
164
|
+
out.push('--app', '.');
|
|
165
|
+
}
|
|
142
166
|
const entries = {};
|
|
143
167
|
if (apps.length <= 1 && !suite && takes.app !== false)
|
|
144
168
|
for (const entry of takes.entries) {
|
|
@@ -202,7 +226,7 @@ export function contextLines(context, more = {}) {
|
|
|
202
226
|
const lines = [`Context: ${where}`];
|
|
203
227
|
const row = (key, path, from) => lines.push(` ${key.padEnd(9)} ${(path ?? '—').padEnd(13)} ${from}`);
|
|
204
228
|
if (context.app)
|
|
205
|
-
row('app', shown(context.app.path), context.app.from === 'profile' ? 'mistri.json' : over(context, 'dir', 'flag'));
|
|
229
|
+
row('app', shown(context.app.path), context.app.from === 'profile' ? 'mistri.json' : context.app.from === 'cwd' ? 'the working directory' : over(context, 'dir', 'flag'));
|
|
206
230
|
for (const entry of ['commands', 'jobs', 'policy', 'entry']) {
|
|
207
231
|
const own = context.entries[entry] ?? more[entry];
|
|
208
232
|
if (!own) {
|
|
@@ -6,9 +6,13 @@
|
|
|
6
6
|
* - `Referrer-Policy: strict-origin-when-cross-origin`: an address under a
|
|
7
7
|
* record (`/compass/leads/127?search=…`) leaves this origin as the origin
|
|
8
8
|
* alone, and never over plain http.
|
|
9
|
-
* - `Permissions-Policy`: no page here uses a
|
|
10
|
-
*
|
|
11
|
-
* whatever frames or is framed.
|
|
9
|
+
* - `Permissions-Policy`: no page here uses a microphone, a location or a
|
|
10
|
+
* payment sheet, and nothing but an App's page draws a camera, so none is
|
|
11
|
+
* granted — to a component, or to whatever frames or is framed. An App's
|
|
12
|
+
* own HTML (clientHttp.ts) replaces this with `APP_PAGE_PERMISSIONS_POLICY`,
|
|
13
|
+
* which lets its own origin ask for the camera: the scan input
|
|
14
|
+
* (`field.text({ as: 'scan' })`) reads a code through `getUserMedia`, and
|
|
15
|
+
* a form with one can be a signed-in page or a public one.
|
|
12
16
|
* - `Strict-Transport-Security`, only on an answer that arrived over https
|
|
13
17
|
* (trust.ts `arrivedOverHttps`): the socket's own TLS, an https public
|
|
14
18
|
* address, or a proxy this server trusts saying it forwarded https. A
|
|
@@ -21,6 +25,12 @@ import { type ProxyRange } from './trust.js';
|
|
|
21
25
|
export declare const REFERRER_POLICY = "strict-origin-when-cross-origin";
|
|
22
26
|
/** @public the database browser's (scripts/boundary/entries.json, "host") */
|
|
23
27
|
export declare const PERMISSIONS_POLICY: string;
|
|
28
|
+
/**
|
|
29
|
+
* An App's page: `PERMISSIONS_POLICY` with the camera allowed for this origin
|
|
30
|
+
* alone. Only the HTML says it — the API, the assets and every refusal keep
|
|
31
|
+
* the baseline — and a frame from another origin is still not granted it.
|
|
32
|
+
*/
|
|
33
|
+
export declare const APP_PAGE_PERMISSIONS_POLICY: string;
|
|
24
34
|
/** A year, and the names under this one: the time browsers ask of a name kept on https. */
|
|
25
35
|
export declare const STRICT_TRANSPORT = "max-age=31536000; includeSubDomains";
|
|
26
36
|
export declare function setBaselineHeaders(req: Pick<IncomingMessage, 'headers' | 'socket'>, res: ServerResponse, trustedProxies?: readonly ProxyRange[]): void;
|
|
@@ -4,6 +4,12 @@ export const REFERRER_POLICY = 'strict-origin-when-cross-origin';
|
|
|
4
4
|
/** @public the database browser's (scripts/boundary/entries.json, "host") */
|
|
5
5
|
export const PERMISSIONS_POLICY = 'camera=(), microphone=(), geolocation=(), payment=(), usb=(), serial=(), bluetooth=(), hid=(), midi=(), ' +
|
|
6
6
|
'magnetometer=(), gyroscope=(), accelerometer=(), display-capture=(), browsing-topics=()';
|
|
7
|
+
/**
|
|
8
|
+
* An App's page: `PERMISSIONS_POLICY` with the camera allowed for this origin
|
|
9
|
+
* alone. Only the HTML says it — the API, the assets and every refusal keep
|
|
10
|
+
* the baseline — and a frame from another origin is still not granted it.
|
|
11
|
+
*/
|
|
12
|
+
export const APP_PAGE_PERMISSIONS_POLICY = PERMISSIONS_POLICY.replace('camera=()', 'camera=(self)');
|
|
7
13
|
/** A year, and the names under this one: the time browsers ask of a name kept on https. */
|
|
8
14
|
export const STRICT_TRANSPORT = 'max-age=31536000; includeSubDomains';
|
|
9
15
|
export function setBaselineHeaders(req, res, trustedProxies = []) {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one place an HTTP server is made. Every listener that takes a person's
|
|
3
|
+
* request (the single-App server, the tenant servers and the suite) is
|
|
4
|
+
* `frontDoor(options, handle)`, so what no surface may forget is done here
|
|
5
|
+
* once, before its handler reads anything:
|
|
6
|
+
*
|
|
7
|
+
* - the request waits in a pool's line as its client's, read through the
|
|
8
|
+
* proxies this server trusts (poolAdmission.ts, trust.ts `forwardedClient`);
|
|
9
|
+
* - the baseline headers (baselineHeaders.ts), set before anything is routed
|
|
10
|
+
* so a reply that names its own still wins;
|
|
11
|
+
* - the guard (`guard`), the surface's first refusal: a Host it does not
|
|
12
|
+
* serve (trust.ts `hostRefusal`, `doorRefusal`), or a stop in progress.
|
|
13
|
+
* It runs after the headers, so a refusal carries them as an answer does.
|
|
14
|
+
*
|
|
15
|
+
* A surface's own refusals, in the shapes its callers read, stay in the
|
|
16
|
+
* surface; what they have in common is the part here. A `createServer` call
|
|
17
|
+
* anywhere else in a package's source is refused by
|
|
18
|
+
* `test/front-door-structure.test.ts`, which names the few that are not a door.
|
|
19
|
+
*/
|
|
20
|
+
import { type IncomingMessage, type Server, type ServerResponse } from 'node:http';
|
|
21
|
+
import { type ProxyRange } from './trust.js';
|
|
22
|
+
interface FrontDoorOptions {
|
|
23
|
+
/** The proxies whose forwarded address and protocol are read; read per request, so a late binding is seen. */
|
|
24
|
+
readonly trustedProxies?: readonly ProxyRange[] | (() => readonly ProxyRange[] | undefined);
|
|
25
|
+
/** False for a server nobody queues at, whose callers a front has already admitted; default true. */
|
|
26
|
+
readonly admit?: boolean;
|
|
27
|
+
/** Seen first, after admission: the operator's meters (operations/diagnostics.ts). */
|
|
28
|
+
readonly diagnostics?: {
|
|
29
|
+
observe(req: IncomingMessage, res: ServerResponse): void;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Outermost, around admission: the request's span (traceRequest.ts) covers
|
|
33
|
+
* the line it waits in. Call `run` once.
|
|
34
|
+
*/
|
|
35
|
+
readonly around?: (req: IncomingMessage, res: ServerResponse, run: () => void) => void;
|
|
36
|
+
/** The first refusal: true when it answered, and nothing further is read. */
|
|
37
|
+
readonly guard?: (req: IncomingMessage, res: ServerResponse) => boolean;
|
|
38
|
+
}
|
|
39
|
+
/** The server, made but not listening. */
|
|
40
|
+
export declare function frontDoor(options: FrontDoorOptions, handle: (req: IncomingMessage, res: ServerResponse) => void): Server;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one place an HTTP server is made. Every listener that takes a person's
|
|
3
|
+
* request (the single-App server, the tenant servers and the suite) is
|
|
4
|
+
* `frontDoor(options, handle)`, so what no surface may forget is done here
|
|
5
|
+
* once, before its handler reads anything:
|
|
6
|
+
*
|
|
7
|
+
* - the request waits in a pool's line as its client's, read through the
|
|
8
|
+
* proxies this server trusts (poolAdmission.ts, trust.ts `forwardedClient`);
|
|
9
|
+
* - the baseline headers (baselineHeaders.ts), set before anything is routed
|
|
10
|
+
* so a reply that names its own still wins;
|
|
11
|
+
* - the guard (`guard`), the surface's first refusal: a Host it does not
|
|
12
|
+
* serve (trust.ts `hostRefusal`, `doorRefusal`), or a stop in progress.
|
|
13
|
+
* It runs after the headers, so a refusal carries them as an answer does.
|
|
14
|
+
*
|
|
15
|
+
* A surface's own refusals, in the shapes its callers read, stay in the
|
|
16
|
+
* surface; what they have in common is the part here. A `createServer` call
|
|
17
|
+
* anywhere else in a package's source is refused by
|
|
18
|
+
* `test/front-door-structure.test.ts`, which names the few that are not a door.
|
|
19
|
+
*/
|
|
20
|
+
import { createServer } from 'node:http';
|
|
21
|
+
import { withAdmission } from '../../adapters/poolAdmission.js';
|
|
22
|
+
import { setBaselineHeaders } from './baselineHeaders.js';
|
|
23
|
+
import { forwardedClient } from './trust.js';
|
|
24
|
+
/** The server, made but not listening. */
|
|
25
|
+
export function frontDoor(options, handle) {
|
|
26
|
+
const proxies = () => (typeof options.trustedProxies === 'function' ? options.trustedProxies() : options.trustedProxies) ?? [];
|
|
27
|
+
const through = (req, res) => {
|
|
28
|
+
options.diagnostics?.observe(req, res);
|
|
29
|
+
setBaselineHeaders(req, res, proxies());
|
|
30
|
+
if (options.guard?.(req, res))
|
|
31
|
+
return;
|
|
32
|
+
handle(req, res);
|
|
33
|
+
};
|
|
34
|
+
const admitted = (req, res) => options.admit === false ? through(req, res) : withAdmission(forwardedClient(req, proxies()), () => through(req, res));
|
|
35
|
+
return createServer((req, res) => (options.around ? options.around(req, res, () => admitted(req, res)) : admitted(req, res)));
|
|
36
|
+
}
|
|
@@ -55,6 +55,7 @@ export async function composeRecordPage({ ctx, source, body, post, hooks, }) {
|
|
|
55
55
|
app: ctx.appConfigured,
|
|
56
56
|
recordLabel: (table) => resources[table]?.recordLabel,
|
|
57
57
|
defined: (table) => resources[table]?.defined,
|
|
58
|
+
display: (table, column) => resources[table]?.display?.[column],
|
|
58
59
|
};
|
|
59
60
|
const options = { rows, history: true, ...(tab === undefined ? {} : { tab: tab }) };
|
|
60
61
|
/* What the page reads that its plan does not decide — the record's row,
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
* malformed target is answered with, what an error's status is, which
|
|
13
13
|
* requests a close waits for — would agree only by convention.
|
|
14
14
|
*/
|
|
15
|
-
import {
|
|
15
|
+
import type { IncomingMessage, Server, ServerResponse } from 'node:http';
|
|
16
16
|
import type { RequestDiagnostics } from '../operations/diagnostics.js';
|
|
17
17
|
import { type AddressMount } from '../../shared/mount.js';
|
|
18
|
-
import {
|
|
18
|
+
import type { Bound } from './trust.js';
|
|
19
19
|
/**
|
|
20
20
|
* The request read through the server's mounts (shared/mount.ts): the base
|
|
21
21
|
* path taken off `req.url`, which the static files, the App API and Better
|
|
@@ -1,24 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The HTTP server every product's dispatcher listens on: a `node:http`
|
|
3
|
-
* server with the request's span, the baseline headers, the address read
|
|
4
|
-
* through the mounts, the orchestrator's probes, and the error-to-status
|
|
5
|
-
* mapping the tests pin — and, in the middle, the product's own answer
|
|
6
|
-
* (`Answering`). The database browser's server (browserServer.ts) and the
|
|
7
|
-
* App framework's (server.ts) are each this, with what their product adds.
|
|
8
|
-
*
|
|
9
|
-
* Kept whole rather than rebuilt per product, for the reason `createApp`
|
|
10
|
-
* was pulled out of `main` in the first place: a wiring a product wrote for
|
|
11
|
-
* itself would be the one its tests prove, and the shared parts — what a
|
|
12
|
-
* malformed target is answered with, what an error's status is, which
|
|
13
|
-
* requests a close waits for — would agree only by convention.
|
|
14
|
-
*/
|
|
15
|
-
import { createServer } from 'node:http';
|
|
16
1
|
import { SOURCE_CLIENT, attachDevClient } from '../devclient.js';
|
|
17
2
|
import { applyServerTimeouts } from '../serverTimeouts.js';
|
|
18
3
|
import { Refusal, WriteConflict } from '../../adapters/adapter.js';
|
|
19
4
|
import { HttpSourceError } from '../../adapters/http/egress.js';
|
|
20
5
|
import { isPoolBusy } from '../../adapters/poolMetrics.js';
|
|
21
|
-
import { withAdmission } from '../../adapters/poolAdmission.js';
|
|
22
6
|
import { AppAccessDenied } from '../columnGrants.js';
|
|
23
7
|
import { wrongTypeValue } from '../constraints.js';
|
|
24
8
|
import { PathError } from '../../shared/view.js';
|
|
@@ -28,8 +12,7 @@ import { probe } from './probes.js';
|
|
|
28
12
|
import { reportRefusal } from './refusalReport.js';
|
|
29
13
|
import { HttpError, send, sendBusy } from './reply.js';
|
|
30
14
|
import { routedPath, servedApp, traceRequest } from './traceRequest.js';
|
|
31
|
-
import {
|
|
32
|
-
import { forwardedClient } from './trust.js';
|
|
15
|
+
import { frontDoor } from './frontDoor.js';
|
|
33
16
|
import { timeRequests } from '../../adapters/telemetry/serverTiming.js';
|
|
34
17
|
/* From source, Vite's modules are addressed from the root whatever the base
|
|
35
18
|
(devclient.ts): its own paths and the client's files, never a page, the
|
|
@@ -99,12 +82,13 @@ export function listen(options, answering) {
|
|
|
99
82
|
/* The span of each request (traceRequest.ts) names its route from the
|
|
100
83
|
address after routeAddress has read it inward, never as the browser
|
|
101
84
|
spelled it: under a base path or a root mount it is the same route. */
|
|
102
|
-
const server =
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
options.diagnostics
|
|
107
|
-
|
|
85
|
+
const server = frontDoor({
|
|
86
|
+
/* Its pool checkouts wait in line as its client's until its session names the account
|
|
87
|
+
(adapters/poolAdmission.ts, http/door.ts). */
|
|
88
|
+
trustedProxies: () => options.bound.trustedProxies,
|
|
89
|
+
diagnostics: options.diagnostics,
|
|
90
|
+
around: (req, res, run) => traceRequest(req, res, run),
|
|
91
|
+
}, (req, res) => {
|
|
108
92
|
// Node accepts request targets that URL cannot parse. Refuse them before
|
|
109
93
|
// dispatch, and reuse this parse in error mapping and drain tracking too.
|
|
110
94
|
let url;
|
|
@@ -112,7 +96,7 @@ export function listen(options, answering) {
|
|
|
112
96
|
url = new URL(req.url ?? '/', 'http://localhost');
|
|
113
97
|
}
|
|
114
98
|
catch {
|
|
115
|
-
return send(res, 400, { error: 'Invalid request target.' });
|
|
99
|
+
return void send(res, 400, { error: 'Invalid request target.' });
|
|
116
100
|
}
|
|
117
101
|
const mount = answering.mount();
|
|
118
102
|
if (answering.outside?.(req, res, url))
|
|
@@ -130,17 +114,17 @@ export function listen(options, answering) {
|
|
|
130
114
|
if (answering.failed?.(err, req, res, url))
|
|
131
115
|
return;
|
|
132
116
|
/* The client left: its request was cut off mid-body, or it closed the
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
117
|
+
socket before the answer, and what failed was the read it no longer
|
|
118
|
+
waits for. Nobody can be answered and nothing went wrong on this
|
|
119
|
+
side, so it is not a 500 on the operator's terminal: the request's
|
|
120
|
+
span still says it was aborted (traceRequest.ts). */
|
|
137
121
|
if (clientLeft(req, res, err)) {
|
|
138
122
|
res.destroy();
|
|
139
123
|
return;
|
|
140
124
|
}
|
|
141
125
|
/* The pool had no connection to give within its budget: the server is
|
|
142
|
-
|
|
143
|
-
|
|
126
|
+
busy, which is neither the caller's mistake nor a failure, and a 500
|
|
127
|
+
after ten seconds said both. Answered now, with when to come back. */
|
|
144
128
|
if (isPoolBusy(err) && !res.headersSent) {
|
|
145
129
|
reportRefusal(req, 503, 'server_busy', err.message, err);
|
|
146
130
|
return sendBusy(res, {}, false, err);
|
|
@@ -155,7 +139,7 @@ export function listen(options, answering) {
|
|
|
155
139
|
pending.add(operation);
|
|
156
140
|
void operation.finally(() => pending.delete(operation));
|
|
157
141
|
}
|
|
158
|
-
})
|
|
142
|
+
});
|
|
159
143
|
commandOperations.set(server, pending);
|
|
160
144
|
if (SOURCE_CLIENT && options.sourceClient !== false)
|
|
161
145
|
attachDevClient(server);
|
|
@@ -29,7 +29,7 @@ import { compareVersions, newMigration, readMigrations } from './files.js';
|
|
|
29
29
|
import { FLYWAY_COMMANDS, runFlyway } from './flyway.js';
|
|
30
30
|
import { migrateBaseline, migrateRepair, migrateUp, migrateValidate, migrationStatus, recordAround } from './runner.js';
|
|
31
31
|
import { sayChange } from './snapshot.js';
|
|
32
|
-
import { resolveTarget, targetDir } from './target.js';
|
|
32
|
+
import { migrateWriteRefusal, resolveTarget, targetDir } from './target.js';
|
|
33
33
|
import { product } from '../product.js';
|
|
34
34
|
import { claimContext, contextJson, contextLines, fromProfile, projectContext } from '../config/profile.js';
|
|
35
35
|
const migrateUsage = () => product() +
|
|
@@ -89,6 +89,8 @@ export async function runMigrate(argv, write = (line) => process.stdout.write(`$
|
|
|
89
89
|
'With --app, status prints the bootstrap plan (migrations, stores, sign-in store, seed, check) and up carries it out:\n' +
|
|
90
90
|
' the stores the App uses (--commands, --jobs, --policy name its modules), a PostgreSQL auth.store, then the check.\n' +
|
|
91
91
|
' validate --app exits 2 while any phase is pending. --json prints the plan as data.\n' +
|
|
92
|
+
'up, baseline and repair write to the database: without --app, a connection a config names must say "writable": true\n' +
|
|
93
|
+
'(a database named with --db, and --dry-run, are not asked).\n' +
|
|
92
94
|
'Exit codes: 1 could not run, 2 files and history disagree, 3 a migration failed, 4 applied but the App no longer checks,\n' +
|
|
93
95
|
'5 a store step failed.\n' +
|
|
94
96
|
'mistri docs migrate is the guide.');
|
|
@@ -278,6 +280,11 @@ export async function runMigrate(argv, write = (line) => process.stdout.write(`$
|
|
|
278
280
|
return EXIT.ok;
|
|
279
281
|
}
|
|
280
282
|
const target = await resolveTarget(registry, config, flags, appDir, loaded?.binding);
|
|
283
|
+
/* An App's own database is the App's to migrate (`--app`): the plan it carries out is the deployment, and the
|
|
284
|
+
connection is the one it binds. The database browser, and a run with no App, answer to the flag. */
|
|
285
|
+
const refused = loaded ? undefined : migrateWriteRefusal(target.connection, command, dryRun);
|
|
286
|
+
if (refused)
|
|
287
|
+
return fail(refused);
|
|
281
288
|
if (DESIRED.includes(command)) {
|
|
282
289
|
const file = schemaFile !== undefined ? resolve(schemaFile) : defaultSchemaFile(target.dir);
|
|
283
290
|
/* The first migration is schema.sql itself: written before any diff tool
|
|
@@ -27,6 +27,14 @@ interface ResolvedTarget extends MigrateTarget {
|
|
|
27
27
|
}
|
|
28
28
|
/** The connection the run is about: named, the App's home source's, or the only one. `tablewalk seed` reads it the same way. */
|
|
29
29
|
export declare function targetConnection(registry: Registry, flags: Pick<TargetFlags, 'connection' | 'argument'>, binding?: TargetBinding, purpose?: string): ConnectionConfig;
|
|
30
|
+
/**
|
|
31
|
+
* Why a run may not write to this connection, or undefined. `"writable": true` is the config's statement about one
|
|
32
|
+
* named database (connections.ts), enforced wherever the server writes; migrate wrote DDL and its history table to a
|
|
33
|
+
* connection that said nothing of the kind. Only a connection a config names carries the flag: a database handed
|
|
34
|
+
* over on the command line (`<db>`, --db, DATABASE_URL) is the person's own act, as it always was, and a run that
|
|
35
|
+
* only prints a plan writes nothing, so neither is refused.
|
|
36
|
+
*/
|
|
37
|
+
export declare function migrateWriteRefusal(connection: ConnectionConfig, command: string, dryRun?: boolean): string | undefined;
|
|
30
38
|
/** The directory alone, for `migrate new`, which writes a file and opens no database. */
|
|
31
39
|
export declare function targetDir(registry: Registry, config: StartupConfig, flags: TargetFlags, appDir?: string, binding?: TargetBinding): string;
|
|
32
40
|
export declare function resolveTarget(registry: Registry, config: StartupConfig, flags: TargetFlags, appDir?: string, binding?: TargetBinding): Promise<ResolvedTarget>;
|
|
@@ -38,6 +38,21 @@ export function targetConnection(registry, flags, binding, purpose = 'migrate')
|
|
|
38
38
|
throw new Error(`several connections are configured (${configs.map((config) => config.name).join(', ')}): name one with --connection.`);
|
|
39
39
|
throw new Error(`no database to ${purpose}. Name it — a SQLite file, --db <url>, or --config <file> — or keep a ${configFileName()} beside where you run it.`);
|
|
40
40
|
}
|
|
41
|
+
/** The commands that write DDL and history to the database; the rest only read it. */
|
|
42
|
+
const WRITING = new Set(['up', 'baseline', 'repair']);
|
|
43
|
+
/**
|
|
44
|
+
* Why a run may not write to this connection, or undefined. `"writable": true` is the config's statement about one
|
|
45
|
+
* named database (connections.ts), enforced wherever the server writes; migrate wrote DDL and its history table to a
|
|
46
|
+
* connection that said nothing of the kind. Only a connection a config names carries the flag: a database handed
|
|
47
|
+
* over on the command line (`<db>`, --db, DATABASE_URL) is the person's own act, as it always was, and a run that
|
|
48
|
+
* only prints a plan writes nothing, so neither is refused.
|
|
49
|
+
*/
|
|
50
|
+
export function migrateWriteRefusal(connection, command, dryRun = false) {
|
|
51
|
+
if (!WRITING.has(command) || dryRun || connection.source !== 'config' || connection.writable)
|
|
52
|
+
return undefined;
|
|
53
|
+
return (`"${connection.name}" is not writable, and ${command} changes its schema and its history table. ` +
|
|
54
|
+
`Set "writable": true on the connection in ${configFileName()} to allow it, or name the database with --db <url> if it is one you mean to change.`);
|
|
55
|
+
}
|
|
41
56
|
function directoryOf(connection, config, flags, appDir) {
|
|
42
57
|
const base = config.configPath ? dirname(config.configPath) : process.cwd();
|
|
43
58
|
return flags.migrations !== undefined
|