@fabrika/check 0.8.1 → 0.9.0-cloudflare.1
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/package.json +12 -11
- package/src/check.ts +23 -6
- package/src/dialect.ts +29 -0
- package/src/endpoint-fixtures.ts +29 -9
- package/src/finding.ts +7 -3
- package/src/index.ts +2 -1
- package/src/layout.ts +2 -0
- package/src/reader/surface.ts +15 -0
- package/src/rules/cloudflare.ts +58 -0
- package/src/rules/framework.ts +2 -2
- package/src/rules/isolation.ts +5 -1
- package/src/rules/migrations.ts +31 -0
- package/src/rules/modules.ts +1 -1
- package/src/scaffold.ts +133 -33
- package/types/src/ast.d.ts +65 -0
- package/types/src/bun-plugin.d.ts +12 -0
- package/types/src/check.d.ts +19 -0
- package/types/src/cli.d.ts +2 -0
- package/types/src/contract.d.ts +58 -0
- package/types/src/dialect.d.ts +8 -0
- package/types/src/endpoint-fixtures.d.ts +39 -0
- package/types/src/finding.d.ts +39 -0
- package/types/src/graph.d.ts +68 -0
- package/types/src/index.d.ts +7 -0
- package/types/src/inputs.d.ts +9 -0
- package/types/src/jsonc.d.ts +2 -0
- package/types/src/layout.d.ts +65 -0
- package/types/src/limits.d.ts +15 -0
- package/types/src/lockfile.d.ts +19 -0
- package/types/src/packed.d.ts +15 -0
- package/types/src/reader/problems.d.ts +7 -0
- package/types/src/reader/schema.d.ts +18 -0
- package/types/src/reader/surface.d.ts +5 -0
- package/types/src/reader/tables.d.ts +6 -0
- package/types/src/reader/value.d.ts +113 -0
- package/types/src/references.d.ts +15 -0
- package/types/src/resolution.d.ts +20 -0
- package/types/src/rules/cloudflare.d.ts +9 -0
- package/types/src/rules/contract.d.ts +8 -0
- package/types/src/rules/crontab.d.ts +15 -0
- package/types/src/rules/framework.d.ts +19 -0
- package/types/src/rules/identity.d.ts +5 -0
- package/types/src/rules/isolation.d.ts +18 -0
- package/types/src/rules/json.d.ts +3 -0
- package/types/src/rules/literal.d.ts +63 -0
- package/types/src/rules/migrations.d.ts +34 -0
- package/types/src/rules/modules.d.ts +12 -0
- package/types/src/rules/packages.d.ts +7 -0
- package/types/src/rules/runtime.d.ts +32 -0
- package/types/src/rules/structure.d.ts +36 -0
- package/types/src/rules/tests.d.ts +22 -0
- package/types/src/rules/types.d.ts +4 -0
- package/types/src/scaffold-sample.d.ts +8 -0
- package/types/src/scaffold.d.ts +34 -0
- package/types/src/scope.d.ts +6 -0
- package/types/src/slice.d.ts +30 -0
- package/types/src/source-maps-cli.d.ts +4 -0
- package/types/src/source-maps.d.ts +32 -0
- package/types/src/toml.d.ts +30 -0
- package/types/src/trust.d.ts +15 -0
- package/types/src/version.d.ts +2 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type AstNode } from '../ast';
|
|
2
|
+
import type { Report } from '../finding';
|
|
3
|
+
export interface SourceContext {
|
|
4
|
+
readonly report: Report;
|
|
5
|
+
/** The generated entrypoint is the one module that reads the framework's variables. */
|
|
6
|
+
readonly isGeneratedEntry: boolean;
|
|
7
|
+
/** The names the module binds to an imported `sql` (`rawSqlBindings`): a parameter of that name is not one of them. */
|
|
8
|
+
readonly rawSql: ReadonlySet<string>;
|
|
9
|
+
/** A module under `src/` that is not a test: it reaches no global object and no `Bun` at all. */
|
|
10
|
+
readonly isServerModule: boolean;
|
|
11
|
+
/** A `fetch` of an absolute URL: refused once the contract shows that no site declares its origin in `egress`. */
|
|
12
|
+
readonly absoluteFetch: (node: AstNode, target: string) => void;
|
|
13
|
+
/** A `ctx.url('<endpoint id>', …)` with a literal id: refused once the contract shows that it names no procedure. */
|
|
14
|
+
readonly appUrl: (node: AstNode, endpoint: string) => void;
|
|
15
|
+
/** A `<table>.insert(values, { onConflict: { columns } })`: refused once the migrations show no unique index of them. */
|
|
16
|
+
readonly conflictInsert: (node: AstNode, table: string, columns: readonly string[]) => void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The local names a module binds to a value named `sql` it loads: `import { sql as q } from 'kysely'` and
|
|
20
|
+
* `const { sql } = await import('bun')`. The raw-sql rule refuses a driver's tag by this origin, so a query function
|
|
21
|
+
* may take the declared `ctx.sql` tag as a parameter of any name.
|
|
22
|
+
*/
|
|
23
|
+
export declare const rawSqlBindings: (program: AstNode) => ReadonlySet<string>;
|
|
24
|
+
/** The finding of a `fetch` of an absolute URL whose origin no site of the contract declares. */
|
|
25
|
+
export declare const crossAppFetchMessage: (target: string) => {
|
|
26
|
+
readonly message: string;
|
|
27
|
+
readonly allowed: string;
|
|
28
|
+
};
|
|
29
|
+
/** Whether an expression reaches a prototype: through `.prototype`, `.__proto__` or `Object.getPrototypeOf(…)`. */
|
|
30
|
+
export declare const touchesPrototype: (node: AstNode | undefined) => boolean;
|
|
31
|
+
/** The rules that read one node at a time, for every source file. */
|
|
32
|
+
export declare const checkRuntimeNode: (node: AstNode, ancestors: readonly AstNode[], context: SourceContext) => void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type AstNode } from '../ast';
|
|
2
|
+
import { type Report } from '../finding';
|
|
3
|
+
import type { ModuleReference } from '../references';
|
|
4
|
+
import { type ImportMappings } from '../resolution';
|
|
5
|
+
/** The rules of the application architecture (docs/reference/application-architecture.md): four refusals and the hints. */
|
|
6
|
+
export declare const STRUCTURE_RULE_IDS: readonly ["spa-server-import", "layer-import", "generated-test-import", "shared-import", "logic-data-access", "cross-slice-queries", "handler-location", "data-access-location"];
|
|
7
|
+
type SlicePart = 'endpoints' | 'logic' | 'queries';
|
|
8
|
+
/** Where a module sits in the architecture, which decides what it may import and call. */
|
|
9
|
+
export interface StructurePlace {
|
|
10
|
+
readonly file: string;
|
|
11
|
+
readonly slice: string | undefined;
|
|
12
|
+
readonly part: SlicePart | undefined;
|
|
13
|
+
/** A test or the generated entrypoint: the structure hints do not apply to it. */
|
|
14
|
+
readonly exempt: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare const structurePlace: (file: string, isGeneratedEntry: boolean) => StructurePlace;
|
|
17
|
+
/** What the structure rules read beyond one module: every module's references, and how Bun resolves them. */
|
|
18
|
+
export interface StructureGraph {
|
|
19
|
+
readonly files: ReadonlyMap<string, string>;
|
|
20
|
+
readonly mappings: ImportMappings;
|
|
21
|
+
readonly referencesOf: (path: string) => readonly ModuleReference[];
|
|
22
|
+
}
|
|
23
|
+
/** The architecture's rules over one module's imports, re-exports and loads, as Bun resolves them for that module. */
|
|
24
|
+
export declare const checkStructureReferences: (graph: StructureGraph, place: StructurePlace, report: Report) => void;
|
|
25
|
+
/** A `<x>.<builder>(…).handle(…)` call: the builder's name, its call (whose arguments hold the options) and `.handle`. */
|
|
26
|
+
export interface HandledProcedure {
|
|
27
|
+
readonly builder: string;
|
|
28
|
+
readonly procedure: AstNode;
|
|
29
|
+
/** The `handle` property node, where a finding points. */
|
|
30
|
+
readonly handle: AstNode;
|
|
31
|
+
}
|
|
32
|
+
/** The procedure `node` hands a handler to, when `node` is `<x>.<builder>(…).handle(…)`. */
|
|
33
|
+
export declare const handledProcedure: (node: AstNode) => HandledProcedure | undefined;
|
|
34
|
+
/** The architecture's hints at one node: a handler outside `endpoints.ts`, data access outside `endpoints.ts`/`queries.ts`. */
|
|
35
|
+
export declare const checkStructureNode: (place: StructurePlace, node: AstNode, report: Report) => void;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type AstNode, type Comment } from '../ast';
|
|
2
|
+
import type { Finding, Report } from '../finding';
|
|
3
|
+
/** For test files: every test runs, and every test asserts. */
|
|
4
|
+
export declare const checkTestNode: (node: AstNode, ancestors: readonly AstNode[], report: Report) => void;
|
|
5
|
+
/** The first line of a test written by `fabrika db test-scaffold`, followed by the SHA-256 of everything after that line. */
|
|
6
|
+
export declare const GENERATED_TEST_HEADER = "// @generated by fabrika db test-scaffold sha256:";
|
|
7
|
+
/** The header `fabrika db test-scaffold` puts on a generated test with this body. */
|
|
8
|
+
export declare const generatedTestHeader: (body: string) => Promise<string>;
|
|
9
|
+
export declare const checkGeneratedTest: (text: string, comments: readonly Comment[], report: Report) => Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* The `bunfig.toml` of an application must not narrow its own suite. The platform's run of the generated tests ignores
|
|
12
|
+
* the file (`fabrika db test-isolation`); this keeps the application's own run whole too. A file outside the TOML
|
|
13
|
+
* subset is reported by the trust rules.
|
|
14
|
+
*/
|
|
15
|
+
export declare const checkTestSuiteConfig: (text: string) => Finding[];
|
|
16
|
+
/** Whether `path` is a file the scaffold generates: a policy isolation test, the endpoint access test, or one with the header. */
|
|
17
|
+
export declare const isGeneratedTestPath: (path: string, files: ReadonlyMap<string, string>) => boolean;
|
|
18
|
+
/**
|
|
19
|
+
* `mock.module(…)` of the test runner, a framework package or a generated test would let application code replace what
|
|
20
|
+
* the generated tests run on; a computed specifier could name any of them. Refused anywhere in the application.
|
|
21
|
+
*/
|
|
22
|
+
export declare const checkMockModule: (node: AstNode, file: string, files: ReadonlyMap<string, string>, report: Report) => void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SchemaShape } from '@fabrika/auth-core';
|
|
2
|
+
export type Sample = null | boolean | number | string | readonly Sample[] | {
|
|
3
|
+
readonly [key: string]: Sample;
|
|
4
|
+
};
|
|
5
|
+
/** A value `shape` admits, or `undefined`. */
|
|
6
|
+
export declare function sample(shape: SchemaShape): Sample | undefined;
|
|
7
|
+
/** The literal as dprint writes it: single quotes, bare keys where they are identifiers. */
|
|
8
|
+
export declare function renderSample(value: Sample): string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ContractArtifact, type TablePolicyArtifact } from '@fabrika/auth-core';
|
|
2
|
+
import { type Tables } from '@fabrika/db/tables';
|
|
3
|
+
import { type ApplicationDialect } from './dialect';
|
|
4
|
+
import { type EndpointFixtures } from './endpoint-fixtures';
|
|
5
|
+
import type { Finding } from './finding';
|
|
6
|
+
export { ENDPOINT_ACCESS_TEST, ENDPOINT_FIXTURES_FILE, POLICY_TEST_SUFFIX, POLICY_TESTS_DIR } from './layout';
|
|
7
|
+
export declare const policyTestPath: (table: string) => string;
|
|
8
|
+
/** One generated test file: its full text, header included, and the name of every test case it registers. */
|
|
9
|
+
export interface GeneratedTest {
|
|
10
|
+
readonly text: string;
|
|
11
|
+
readonly cases: readonly string[];
|
|
12
|
+
}
|
|
13
|
+
type Policies = Readonly<Record<string, TablePolicyArtifact>>;
|
|
14
|
+
/**
|
|
15
|
+
* Every test the scaffold writes for these policies and, when the application has a contract, its artifact; by path.
|
|
16
|
+
* Endpoint access tests exist only for an application on `@fabrika/db`, which has policies to seed rows from. They
|
|
17
|
+
* open the test database of the application's dialect.
|
|
18
|
+
*/
|
|
19
|
+
export declare const generatedTests: (policies: Policies, artifact: ContractArtifact | null, fixtures?: EndpointFixtures, dialect?: ApplicationDialect) => Promise<ReadonlyMap<string, GeneratedTest>>;
|
|
20
|
+
export interface ScaffoldInputs {
|
|
21
|
+
/** What `src/db/tables.ts` defines, its column list included; `null` without the file. */
|
|
22
|
+
readonly tables: Tables<unknown, unknown> | null;
|
|
23
|
+
readonly policies: Policies;
|
|
24
|
+
readonly artifact: ContractArtifact | null;
|
|
25
|
+
readonly fixtures: EndpointFixtures;
|
|
26
|
+
readonly dialect: ApplicationDialect;
|
|
27
|
+
}
|
|
28
|
+
/** What the scaffold reads from an application's files; throws `ContractSourceError` or `ContractError` as the reader does. */
|
|
29
|
+
export declare const scaffoldInputs: (files: ReadonlyMap<string, string>) => ScaffoldInputs;
|
|
30
|
+
/**
|
|
31
|
+
* What stops the endpoint access tests from covering every endpoint: one whose input the scaffold cannot sample and
|
|
32
|
+
* the author gave no fixture, and a fixture of no tested endpoint. Each is an `endpoint-fixture` finding.
|
|
33
|
+
*/
|
|
34
|
+
export declare const missingEndpointFixtures: ({ tables, policies, artifact, fixtures }: ScaffoldInputs) => readonly Finding[];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type AstNode } from './ast';
|
|
2
|
+
/**
|
|
3
|
+
* The scope whose declaration `name` denotes at a node with these ancestors: the innermost one that declares it, or
|
|
4
|
+
* `undefined` for a global. A module's imports and top-level declarations belong to its `Program`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const declaringScope: (name: string, ancestors: readonly AstNode[]) => AstNode | undefined;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type AstNode, type ParsedModule, type ParseResult } from './ast';
|
|
2
|
+
import type { Finding } from './finding';
|
|
3
|
+
/** A `.handle(…)` the slice cannot keep out of the shell, at its `handle`; the reader and the SPA build refuse it. */
|
|
4
|
+
export interface SliceRefusal {
|
|
5
|
+
readonly node: AstNode;
|
|
6
|
+
readonly message: string;
|
|
7
|
+
readonly allowed: string;
|
|
8
|
+
}
|
|
9
|
+
/** A module's slice, and the `.handle(…)` forms it refused. */
|
|
10
|
+
export interface ShellSlice {
|
|
11
|
+
readonly text: string;
|
|
12
|
+
readonly refusals: readonly SliceRefusal[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The slice of one parsed module: `module`'s text with every `.handle(…)` and everything only the handlers used
|
|
16
|
+
* blanked. A module without a handler comes back unchanged.
|
|
17
|
+
*/
|
|
18
|
+
export declare function moduleSlice(module: ParsedModule, text: string): ShellSlice;
|
|
19
|
+
/**
|
|
20
|
+
* The slice of a module's text. Text that does not parse comes back unchanged, so the reader reports the parse error
|
|
21
|
+
* where it is.
|
|
22
|
+
*/
|
|
23
|
+
export declare function shellSlice(file: string, text: string): ShellSlice;
|
|
24
|
+
/** A refused `.handle(…)` as the finding the reader, the checker and the SPA build report. */
|
|
25
|
+
export declare function sliceFinding(module: ParsedModule, refusal: SliceRefusal): Finding;
|
|
26
|
+
/** A module parsed as its slice, what the reader and input discovery read, with the `.handle(…)` forms it refused. */
|
|
27
|
+
export declare function parseShellModule(file: string, text: string): {
|
|
28
|
+
readonly parsed: ParseResult;
|
|
29
|
+
readonly refusals: readonly Finding[];
|
|
30
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { type ArtifactFetch, type SourceMapUploadResult } from './source-maps';
|
|
3
|
+
/** Collect and upload; every failure is an incomplete result, and nothing it prints carries the bearer. */
|
|
4
|
+
export declare function runSourceMapUpload(root: string, environment: Readonly<Record<string, string | undefined>>, fetch: ArtifactFetch): Promise<SourceMapUploadResult>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type OperationsArtifactUploadConfiguration, type OperationsAssetRoot, type OperationsSourceMapUploadState } from '@fabrika/operations-contract/releases';
|
|
2
|
+
/** Operations' own limits (`artifact-upload.ts`): a larger map or one past the run's budget is refused there. */
|
|
3
|
+
export declare const MAX_SOURCE_MAP_BYTES: number;
|
|
4
|
+
export declare const MAX_SOURCE_MAPS = 256;
|
|
5
|
+
export declare const MAX_SOURCE_MAP_TOTAL_BYTES: number;
|
|
6
|
+
export interface SourceMapArtifact {
|
|
7
|
+
logicalPath: string;
|
|
8
|
+
digest: string;
|
|
9
|
+
body: ArrayBuffer;
|
|
10
|
+
}
|
|
11
|
+
export interface SourceMapCollection {
|
|
12
|
+
artifacts: SourceMapArtifact[];
|
|
13
|
+
/** A map was skipped: over a limit, or without a logical path. */
|
|
14
|
+
incomplete: boolean;
|
|
15
|
+
}
|
|
16
|
+
export type ArtifactFetch = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
17
|
+
export interface SourceMapUploadResult {
|
|
18
|
+
uploaded: number;
|
|
19
|
+
state: OperationsSourceMapUploadState;
|
|
20
|
+
}
|
|
21
|
+
/** Every `*.map` of a checkout, at the logical path its own `file` field names (the Cloudflare runner). */
|
|
22
|
+
export declare function collectSourceMaps(cwd: string): Promise<SourceMapCollection>;
|
|
23
|
+
/**
|
|
24
|
+
* Every `*.map` under each asset root, at the URL path of the file it maps: `<prefix>/<path under dir>` without its
|
|
25
|
+
* `.map`, as the browser names that file in a stack frame. A root outside `root` is skipped as incomplete.
|
|
26
|
+
*/
|
|
27
|
+
export declare function collectAssetSourceMaps(root: string, assetRoots: readonly OperationsAssetRoot[]): Promise<SourceMapCollection>;
|
|
28
|
+
/**
|
|
29
|
+
* Upload each map with the run's bearer. A refused or failed upload leaves the state incomplete and never throws, so a
|
|
30
|
+
* deploy succeeds without its maps; nothing about the request, the bearer included, is printed.
|
|
31
|
+
*/
|
|
32
|
+
export declare function uploadSourceMaps(destination: OperationsArtifactUploadConfiguration, collection: SourceMapCollection, fetch: ArtifactFetch): Promise<SourceMapUploadResult>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type TomlValue = {
|
|
2
|
+
readonly kind: 'string';
|
|
3
|
+
readonly value: string;
|
|
4
|
+
} | {
|
|
5
|
+
readonly kind: 'array';
|
|
6
|
+
readonly items: readonly TomlValue[];
|
|
7
|
+
}
|
|
8
|
+
/** A number, boolean or date, kept as its source text. */
|
|
9
|
+
| {
|
|
10
|
+
readonly kind: 'scalar';
|
|
11
|
+
readonly raw: string;
|
|
12
|
+
};
|
|
13
|
+
export interface TomlEntry {
|
|
14
|
+
/** The full key: the table's key followed by the entry's own, each decoded. */
|
|
15
|
+
readonly key: readonly string[];
|
|
16
|
+
readonly value: TomlValue;
|
|
17
|
+
readonly line: number;
|
|
18
|
+
}
|
|
19
|
+
export type TomlDocument = {
|
|
20
|
+
readonly ok: true;
|
|
21
|
+
readonly entries: readonly TomlEntry[];
|
|
22
|
+
} | {
|
|
23
|
+
readonly ok: false;
|
|
24
|
+
readonly line: number;
|
|
25
|
+
readonly message: string;
|
|
26
|
+
};
|
|
27
|
+
/** Decode `text`, or say on which line it leaves the subset. */
|
|
28
|
+
export declare function parseToml(text: string): TomlDocument;
|
|
29
|
+
/** Whether the decoded key is `expected`. */
|
|
30
|
+
export declare const isKey: (entry: TomlEntry, ...expected: readonly string[]) => boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Finding } from './finding';
|
|
2
|
+
/** Packages whose exports the reader trusts by name, and the packages they rely on. */
|
|
3
|
+
export declare const isTrustedSpecifier: (specifier: string) => boolean;
|
|
4
|
+
/** Whether an import-map pattern (`zod/*`, `*`, `@fab*`, `zod`) can match a trusted specifier. */
|
|
5
|
+
export declare const patternMayMatchTrusted: (pattern: string) => boolean;
|
|
6
|
+
export declare const BUNFIG_FILE = "bunfig.toml";
|
|
7
|
+
/** The configuration files `checkTrustedResolution` reads, wherever they lie: Bun reads the nearest one. */
|
|
8
|
+
export declare const isResolutionConfig: (path: string) => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Every configuration among `files` that could make a trusted import load something else: a `paths` or `imports`
|
|
11
|
+
* pattern that can match it, a `baseUrl` (an application file shadows a package under it), an `extends` the check
|
|
12
|
+
* cannot follow, an unparseable `tsconfig.json`, and a runtime `preload` in `bunfig.toml` (a plugin can redirect any
|
|
13
|
+
* import).
|
|
14
|
+
*/
|
|
15
|
+
export declare const checkTrustedResolution: (files: ReadonlyMap<string, string>) => Finding[];
|