@mistriwork/engine 1.0.0-rc.12 → 1.0.0-rc.14

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.
@@ -212,7 +212,7 @@ export class HttpAdapter {
212
212
  throw new Refusal(`${view.base} comes from an API, so a view over it ${why}`);
213
213
  };
214
214
  if (view.aggregates?.length || view.orderBy?.some((order) => order.alias))
215
- refuse('cannot summarise the records that point at it.');
215
+ refuse('cannot summarize the records that point at it.');
216
216
  if (view.filter?.groups.some((group) => group.some((condition) => condition.any)))
217
217
  refuse('cannot ask about the records that point at it.');
218
218
  const deep = compiled.columns.find((column) => column.hops > 1);
@@ -1,6 +1,6 @@
1
1
  /**
2
- * What each binary's entry does before its main, the one way: `tablewalk` (packages/tablewalk/src/server/index.ts)
3
- * and `mistri` (packages/mistri/src/server/index.ts) each call `runBin` with their own main, and nothing else.
2
+ * What each binary's entry does before its main, the one way: `mistri` (packages/mistri/src/server/index.ts) and
3
+ * `tablewalk` (the database browser's, in its own repository) each call `runBin` with their own main, and nothing else.
4
4
  *
5
5
  * Two binaries, not one bin that hands a start across: a person types `npx tablewalk <db>` for the database browser
6
6
  * and `npx @mistriwork/mistri dev` for an App, and each refuses the other's start by the other's name. Neither entry imports the
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * What every start does before its mode, whichever binary runs it: the questions answered without starting
3
3
  * anything (`--help`, `--version`, a typo), and the process's settings the flags make (the proxies it believes,
4
- * its pools). Both mains call these (packages/tablewalk/src/server/cli/browserMain.ts,
5
- * packages/mistri/src/server/cli/mistriMain.ts), each with its own words (`Product`), and each binary runs its own
4
+ * its pools). Both mains call these (packages/mistri/src/server/cli/mistriMain.ts here, the database browser's in
5
+ * its own repository), each with its own words (`Product`), and each binary runs its own
6
6
  * main (bin.ts).
7
7
  */
8
8
  import { parseClientAddressPolicy, parseTrustedProxies } from '../http/trust.js';
@@ -73,9 +73,11 @@ export function exposureLines(host, apps, authProxyHeader) {
73
73
  return [];
74
74
  if (authProxyHeader)
75
75
  return [];
76
- const remedy = 'Bind --host 127.0.0.1, put it behind a proxy that signs people in (--auth-proxy-header), or give the App sign-in.';
76
+ const way = 'Bind --host 127.0.0.1, put it behind a proxy that signs people in (--auth-proxy-header)';
77
+ /* No App is served (the database browser, or a Workbench): there is no App sign-in to give. */
77
78
  if (!apps.length)
78
- return [`Warning: bound to ${host}, beyond loopback, with no sign-in. Anyone who can reach this port can read the database. ${remedy}`];
79
+ return [`Warning: bound to ${host}, beyond loopback, with no sign-in. Anyone who can reach this port can read the database. ${way}.`];
80
+ const remedy = `${way}, or give the App sign-in.`;
79
81
  return apps.map((app) => !app.auth
80
82
  ? `Warning: bound to ${host}, beyond loopback, and "${app.name}" signs no one in: anyone who can reach this port reads what it shows. ${remedy}`
81
83
  : app.auth.public?.read.length
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * What both command lines share about their words: the near miss a typo is told, the version, and how a usage text
3
- * is read for its command and flag words. Each binary keeps its own `USAGE` (packages/tablewalk/src/server/cli/usage.ts,
4
- * packages/mistri/src/server/cli/usage.ts), and test/prose.test.ts holds each one to its own README.
3
+ * is read for its command and flag words. Each binary keeps its own `USAGE` (packages/mistri/src/server/cli/usage.ts
4
+ * here, the database browser's in its own repository), and each is held to its own README.
5
5
  */
6
6
  /** The command words a usage names (`tablewalk migrate`, `mistri check`, …), for a near miss's suggestion. */
7
7
  export declare function commandWordsOf(usage: string, bin: string): string[];
@@ -9,5 +9,8 @@ export declare function commandWordsOf(usage: string, bin: string): string[];
9
9
  export declare function flagWordsOf(usage: string): string[];
10
10
  /** What was probably meant, said the way a person would type it, or nothing when nothing is near. */
11
11
  export declare function didYouMean(said: string, among: readonly string[]): Promise<string>;
12
- /** What the package says it is, best effort. Every package of the workspace carries the one version. */
12
+ /**
13
+ * What this process says it is, best effort: the host product's own version when its main gave one (`setProduct`),
14
+ * else the package's. Every package of the workspace carries the one version.
15
+ */
13
16
  export declare function packageVersion(): Promise<string>;
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * What both command lines share about their words: the near miss a typo is told, the version, and how a usage text
3
- * is read for its command and flag words. Each binary keeps its own `USAGE` (packages/tablewalk/src/server/cli/usage.ts,
4
- * packages/mistri/src/server/cli/usage.ts), and test/prose.test.ts holds each one to its own README.
3
+ * is read for its command and flag words. Each binary keeps its own `USAGE` (packages/mistri/src/server/cli/usage.ts
4
+ * here, the database browser's in its own repository), and each is held to its own README.
5
5
  */
6
+ import { productVersion } from '../product.js';
6
7
  /** The command words a usage names (`tablewalk migrate`, `mistri check`, …), for a near miss's suggestion. */
7
8
  export function commandWordsOf(usage, bin) {
8
9
  return [...new Set([...usage.matchAll(new RegExp(`^ {2}${bin} ([a-z][a-z-]*)(?=\\s|$)`, 'gm'))].map((match) => match[1]))];
@@ -19,8 +20,14 @@ export async function didYouMean(said, among) {
19
20
  ? ` Did you mean ${near}?`
20
21
  : '';
21
22
  }
22
- /** What the package says it is, best effort. Every package of the workspace carries the one version. */
23
+ /**
24
+ * What this process says it is, best effort: the host product's own version when its main gave one (`setProduct`),
25
+ * else the package's. Every package of the workspace carries the one version.
26
+ */
23
27
  export async function packageVersion() {
28
+ const host = productVersion();
29
+ if (host)
30
+ return host;
24
31
  try {
25
32
  const { runtimeVersion } = await import('../packageVersion.js');
26
33
  return runtimeVersion();
@@ -19,7 +19,7 @@
19
19
  */
20
20
  import { readFile, writeFile, mkdir } from 'node:fs/promises';
21
21
  import { dirname, resolve } from 'node:path';
22
- import { connect } from '../adapters/connect.js';
22
+ import { connect, MYSQL_REFUSAL } from '../adapters/connect.js';
23
23
  import { UNTRUSTED_NETWORK } from '../adapters/net/untrustedDatabase.js';
24
24
  import { configLocations } from './config/locations.js';
25
25
  import { redact, scrubSecrets } from './connectionRedaction.js';
@@ -445,6 +445,11 @@ export class Registry {
445
445
  adapter = opened.adapter;
446
446
  }
447
447
  else {
448
+ /* Before any secret is looked for: a mysql:// address has no password worth resolving, and "no password
449
+ found" said first hid the refusal that is the actual answer. connect() says it again for a reference
450
+ that only resolves to one. */
451
+ if (/^(mysql|mariadb):\/\//i.test(entry.config.url))
452
+ throw new Error(MYSQL_REFUSAL);
448
453
  resolved = await resolveConnection(entry.config.name, entry.config.url, {
449
454
  secrets: !entry.untrustedUrl,
450
455
  environment: this.environment,
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * Build the demo database.
3
3
  *
4
- * Lives in `src/` (not `test/`) because it ships: `tablewalk --demo` builds
4
+ * Lives in `src/` (not `test/`) because it ships: `--demo` builds
5
5
  * one of these at runtime so a new install has something to walk without
6
6
  * hunting for a database first. `test/make-demo-db.ts` re-exports it, so the
7
- * suite and `npm run demo` keep the path they have always used.
7
+ * suite keeps the path it has always used.
8
8
  *
9
9
  * A demo that ships as a binary file is a demo nobody can review, so this
10
10
  * writes one from source instead. The shape is chosen to exercise the parts
@@ -17,7 +17,9 @@
17
17
  */
18
18
  import type { IncomingMessage, ServerResponse } from 'node:http';
19
19
  import { type ProxyRange } from './trust.js';
20
+ /** @public the database browser's (scripts/boundary/entries.json, "host") */
20
21
  export declare const REFERRER_POLICY = "strict-origin-when-cross-origin";
22
+ /** @public the database browser's (scripts/boundary/entries.json, "host") */
21
23
  export declare const PERMISSIONS_POLICY: string;
22
24
  /** A year, and the names under this one: the time browsers ask of a name kept on https. */
23
25
  export declare const STRICT_TRANSPORT = "max-age=31536000; includeSubDomains";
@@ -1,5 +1,7 @@
1
1
  import { arrivedOverHttps } from './trust.js';
2
+ /** @public the database browser's (scripts/boundary/entries.json, "host") */
2
3
  export const REFERRER_POLICY = 'strict-origin-when-cross-origin';
4
+ /** @public the database browser's (scripts/boundary/entries.json, "host") */
3
5
  export const PERMISSIONS_POLICY = 'camera=(), microphone=(), geolocation=(), payment=(), usb=(), serial=(), bluetooth=(), hid=(), midi=(), ' +
4
6
  'magnetometer=(), gyroscope=(), accelerometer=(), display-capture=(), browsing-topics=()';
5
7
  /** A year, and the names under this one: the time browsers ask of a name kept on https. */
@@ -11,5 +11,8 @@ export declare const ROBOTS_PATH = "/robots.txt";
11
11
  export declare function sendText(req: IncomingMessage, res: ServerResponse, status: number, type: string, body: string): true;
12
12
  /** True when `path` is a crawler's question: answered as a GET or HEAD only. */
13
13
  export declare function crawlerAsks(req: IncomingMessage, res: ServerResponse, path: string): boolean;
14
- /** The answer of a server with nothing public: crawl nothing, list nothing. False for any other address. */
14
+ /**
15
+ * The answer of a server with nothing public: crawl nothing, list nothing. False for any other address.
16
+ * @public the database browser's (scripts/boundary/entries.json, "host")
17
+ */
15
18
  export declare function closedToCrawlers(req: IncomingMessage, res: ServerResponse, path: string): boolean;
@@ -20,7 +20,10 @@ export function crawlerAsks(req, res, path) {
20
20
  }
21
21
  return false;
22
22
  }
23
- /** The answer of a server with nothing public: crawl nothing, list nothing. False for any other address. */
23
+ /**
24
+ * The answer of a server with nothing public: crawl nothing, list nothing. False for any other address.
25
+ * @public the database browser's (scripts/boundary/entries.json, "host")
26
+ */
24
27
  export function closedToCrawlers(req, res, path) {
25
28
  if (path !== ROBOTS_PATH && path !== SITEMAP_PATH)
26
29
  return false;
@@ -1,5 +1,8 @@
1
1
  import type { PostContext } from './context.js';
2
- /** Why this request cannot try an API, or undefined when it can. */
2
+ /**
3
+ * Why this request cannot try an API, or undefined when it can.
4
+ * @public the database browser's (scripts/boundary/entries.json, "host")
5
+ */
3
6
  export declare function operationRefusal(request: {
4
7
  appConfigured: boolean;
5
8
  dialect: string;
@@ -1,7 +1,10 @@
1
1
  import { send } from './reply.js';
2
2
  const DESCRIBE = '/api/http/operations';
3
3
  const TRY = '/api/http/operation';
4
- /** Why this request cannot try an API, or undefined when it can. */
4
+ /**
5
+ * Why this request cannot try an API, or undefined when it can.
6
+ * @public the database browser's (scripts/boundary/entries.json, "host")
7
+ */
5
8
  export function operationRefusal(request) {
6
9
  if (request.appConfigured)
7
10
  return { status: 403, error: 'Trying an API is part of the database browser; an application does not offer it.' };
@@ -116,6 +116,7 @@ export declare class HttpError extends Error {
116
116
  * reads `.error` showed a blank message on exactly the endpoints where the
117
117
  * message mattered most. Both are sent — the list stays the shape the view
118
118
  * editor reads, and `error` is the first of them.
119
+ * @public the database browser's (scripts/boundary/entries.json, "host")
119
120
  */
120
121
  export declare function refuse(res: ServerResponse, status: number, messages: string[]): void;
121
122
  /**
@@ -330,6 +330,7 @@ export class HttpError extends Error {
330
330
  * reads `.error` showed a blank message on exactly the endpoints where the
331
331
  * message mattered most. Both are sent — the list stays the shape the view
332
332
  * editor reads, and `error` is the first of them.
333
+ * @public the database browser's (scripts/boundary/entries.json, "host")
333
334
  */
334
335
  export function refuse(res, status, messages) {
335
336
  send(res, status, {
@@ -60,6 +60,7 @@ export declare function parseTrustedProxies(values: readonly string[]): {
60
60
  * it is a peer whose `X-Forwarded-For` the limiter may read; with the `--auth-proxy-from` list (`Bound.identityProxies`)
61
61
  * it is a peer whose `--auth-proxy-header` value `identityFor` believes. The two lists are never swapped: one
62
62
  * grants a client address, the other a person.
63
+ * @public the database browser's (scripts/boundary/entries.json, "host")
63
64
  */
64
65
  export declare function trustedProxyPeer(address: string | undefined, trusted?: readonly ProxyRange[]): boolean;
65
66
  /** Whether a public address (MISTRI_PUBLIC_URL) is an https one: what `ServerSettings.httpsFront` is set from. */
@@ -136,6 +136,7 @@ function inRange(groups, range) {
136
136
  * it is a peer whose `X-Forwarded-For` the limiter may read; with the `--auth-proxy-from` list (`Bound.identityProxies`)
137
137
  * it is a peer whose `--auth-proxy-header` value `identityFor` believes. The two lists are never swapped: one
138
138
  * grants a client address, the other a person.
139
+ * @public the database browser's (scripts/boundary/entries.json, "host")
139
140
  */
140
141
  export function trustedProxyPeer(address, trusted = []) {
141
142
  if (loopbackPeer(address))
@@ -2,14 +2,20 @@
2
2
  * Which product this process is: the database browser (`tablewalk`) or the App framework (`mistri`). The engine is
3
3
  * both binaries', and what an operator sets is said in the binary's own name: `TABLEWALK_READ_POOL` for the
4
4
  * browser, `MISTRI_READ_POOL` for an App, read by the same code here. Each main says which it is before it reads a
5
- * flag (packages/tablewalk/src/server/cli/browserMain.ts, packages/mistri/src/server/cli/mistriMain.ts); anything
5
+ * flag (packages/mistri/src/server/cli/mistriMain.ts here, the database browser's main in its own repository); anything
6
6
  * else that runs the engine — an App mounted in a host's server (`createHandler`), a test — is an App's.
7
7
  *
8
8
  * Only the variables both binaries read go through here. A variable one product alone reads names itself.
9
9
  */
10
10
  type ProductName = 'tablewalk' | 'mistri';
11
- /** Say which product this process is. A main calls it first. */
12
- export declare function setProduct(name: ProductName): void;
11
+ /**
12
+ * Say which product this process is. A main calls it first. A host product that runs the engine from npm passes
13
+ * its own version too: `--version`, MCP's serverInfo and telemetry (`packageVersion`) then report it, where the
14
+ * engine's number is the framework's and moves on its own schedule. Left out, they report the engine's.
15
+ */
16
+ export declare function setProduct(name: ProductName, version?: string): void;
17
+ /** The version the host said it is, if it said one (`setProduct`). */
18
+ export declare const productVersion: () => string | undefined;
13
19
  export declare const product: () => ProductName;
14
20
  /** The config file a project keeps beside it: `mistri.json` for an App, `tablewalk.json` for the browser. */
15
21
  export declare const configFileName: () => string;
@@ -1,8 +1,16 @@
1
1
  let current = 'mistri';
2
- /** Say which product this process is. A main calls it first. */
3
- export function setProduct(name) {
2
+ let hostVersion;
3
+ /**
4
+ * Say which product this process is. A main calls it first. A host product that runs the engine from npm passes
5
+ * its own version too: `--version`, MCP's serverInfo and telemetry (`packageVersion`) then report it, where the
6
+ * engine's number is the framework's and moves on its own schedule. Left out, they report the engine's.
7
+ */
8
+ export function setProduct(name, version) {
4
9
  current = name;
10
+ hostVersion = version;
5
11
  }
12
+ /** The version the host said it is, if it said one (`setProduct`). */
13
+ export const productVersion = () => hostVersion;
6
14
  export const product = () => current;
7
15
  /** The config file a project keeps beside it: `mistri.json` for an App, `tablewalk.json` for the browser. */
8
16
  export const configFileName = () => `${current}.json`;
@@ -98,7 +98,8 @@ export declare function recordedImport(options: RecordWriteOptions, inputs: read
98
98
  */
99
99
  export declare function recordedDelete(options: RecordWriteOptions, input: DeleteRequest, dependents?: Dependents): Promise<Recorded<DeleteResult>>;
100
100
  /** The incoming references a deletion of `table` would change rows through:
101
- * every rule but a refusal, an unreported one included. */
101
+ * every rule but a refusal, an unreported one included.
102
+ * @public the database browser's (scripts/boundary/entries.json, "host") */
102
103
  export declare function changingReferences(schema: DatabaseSchema, table: string): ForeignKey[];
103
104
  /**
104
105
  * A deletion's dependents read off the database's own catalog, never an
@@ -303,7 +303,8 @@ async function touchesDependents(tx, key, dependents) {
303
303
  return false;
304
304
  }
305
305
  /** The incoming references a deletion of `table` would change rows through:
306
- * every rule but a refusal, an unreported one included. */
306
+ * every rule but a refusal, an unreported one included.
307
+ * @public the database browser's (scripts/boundary/entries.json, "host") */
307
308
  export function changingReferences(schema, table) {
308
309
  return referencesTo(schema, table).filter((fk) => !fk.declared && fk.onDelete !== 'restrict' && fk.onDelete !== 'no action');
309
310
  }
@@ -68,6 +68,7 @@ export declare function dispatchResourceReadHttp(path: string, body: Record<stri
68
68
  * The adapter picks its own style when it runs the statement; this is the
69
69
  * copy the user reads, and it has to agree with what actually ran or the
70
70
  * panel is teaching the wrong thing.
71
+ * @public the database browser's (scripts/boundary/entries.json, "host")
71
72
  */
72
73
  export declare function styleFor(schema: DatabaseSchema): SqlStyle;
73
74
  /**
@@ -561,6 +561,7 @@ async function runViewForBar(adapter, schema, view, body, app, countMode = 'exac
561
561
  * The adapter picks its own style when it runs the statement; this is the
562
562
  * copy the user reads, and it has to agree with what actually ran or the
563
563
  * panel is teaching the wrong thing.
564
+ * @public the database browser's (scripts/boundary/entries.json, "host")
564
565
  */
565
566
  export function styleFor(schema) {
566
567
  if (schema.dialect === 'postgres')
@@ -895,7 +895,7 @@ function parseAggregates(raw, at, name) {
895
895
  if (typeof a.via !== 'string' || !a.via.trim())
896
896
  throw new Error(`${where} has no "via".`);
897
897
  if (a.fn !== 'count' && (typeof a.column !== 'string' || !a.column.trim())) {
898
- throw new Error(`${where} is a ${a.fn} and needs a "column" to summarise.`);
898
+ throw new Error(`${where} is a ${a.fn} and needs a "column" to summarize.`);
899
899
  }
900
900
  if (a.on !== undefined && typeof a.on !== 'string') {
901
901
  throw new Error(`${where} has an "on" that is not a string.`);
@@ -255,7 +255,7 @@ export function resolveAggregate(schema, baseId, aggregate) {
255
255
  let column;
256
256
  if (aggregate.fn !== 'count') {
257
257
  if (!aggregate.column) {
258
- fail(`${aggregate.fn} needs a column on ${child.name} to summarise.`, aggregate.via);
258
+ fail(`${aggregate.fn} needs a column on ${child.name} to summarize.`, aggregate.via);
259
259
  }
260
260
  column = child.columns.find((c) => c.name === aggregate.column);
261
261
  if (!column) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mistriwork/engine",
3
- "version": "1.0.0-rc.12",
3
+ "version": "1.0.0-rc.14",
4
4
  "description": "The engine both products stand on: the adapters (SQLite, Postgres), the catalog, the query language, keyset pages, the HTTP kit and the shared rules. No React.",
5
5
  "homepage": "https://mistriwork.dev",
6
6
  "bugs": {
@@ -29,6 +29,9 @@
29
29
  "./adapters/connect.js": "./dist/adapters/connect.js",
30
30
  "./adapters/connectionBudget.js": "./dist/adapters/connectionBudget.js",
31
31
  "./adapters/http/egress.js": "./dist/adapters/http/egress.js",
32
+ "./adapters/http/httpAdapter.js": "./dist/adapters/http/httpAdapter.js",
33
+ "./adapters/http/httpDescription.js": "./dist/adapters/http/httpDescription.js",
34
+ "./adapters/http/openapi.js": "./dist/adapters/http/openapi.js",
32
35
  "./adapters/layoutRefusal.js": "./dist/adapters/layoutRefusal.js",
33
36
  "./adapters/net/networkPolicy.js": "./dist/adapters/net/networkPolicy.js",
34
37
  "./adapters/net/untrustedDatabase.js": "./dist/adapters/net/untrustedDatabase.js",