@fabrika/check 0.9.0-dev.1 → 0.9.0-dev.2
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/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/endpoint-fixtures.d.ts +36 -0
- package/types/src/finding.d.ts +38 -0
- package/types/src/graph.d.ts +68 -0
- package/types/src/index.d.ts +6 -0
- package/types/src/inputs.d.ts +9 -0
- package/types/src/jsonc.d.ts +2 -0
- package/types/src/layout.d.ts +63 -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/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 +29 -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 +28 -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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabrika/check",
|
|
3
|
-
"version": "0.9.0-dev.
|
|
3
|
+
"version": "0.9.0-dev.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,27 +16,28 @@
|
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
18
|
"src",
|
|
19
|
-
"!src/**/__tests__/**"
|
|
19
|
+
"!src/**/__tests__/**",
|
|
20
|
+
"types"
|
|
20
21
|
],
|
|
21
22
|
"exports": {
|
|
22
23
|
".": {
|
|
23
24
|
"bun": "./src/index.ts",
|
|
24
|
-
"types": "./src/index.ts",
|
|
25
|
+
"types": "./types/src/index.d.ts",
|
|
25
26
|
"default": "./src/index.ts"
|
|
26
27
|
},
|
|
27
28
|
"./contract": {
|
|
28
29
|
"bun": "./src/contract.ts",
|
|
29
|
-
"types": "./src/contract.ts",
|
|
30
|
+
"types": "./types/src/contract.d.ts",
|
|
30
31
|
"default": "./src/contract.ts"
|
|
31
32
|
},
|
|
32
33
|
"./bun-plugin": {
|
|
33
34
|
"bun": "./src/bun-plugin.ts",
|
|
34
|
-
"types": "./src/bun-plugin.ts",
|
|
35
|
+
"types": "./types/src/bun-plugin.d.ts",
|
|
35
36
|
"default": "./src/bun-plugin.ts"
|
|
36
37
|
},
|
|
37
38
|
"./source-maps": {
|
|
38
39
|
"bun": "./src/source-maps.ts",
|
|
39
|
-
"types": "./src/source-maps.ts",
|
|
40
|
+
"types": "./types/src/source-maps.d.ts",
|
|
40
41
|
"default": "./src/source-maps.ts"
|
|
41
42
|
}
|
|
42
43
|
},
|
|
@@ -46,11 +47,11 @@
|
|
|
46
47
|
},
|
|
47
48
|
"dependencies": {
|
|
48
49
|
"@babel/parser": "8.0.7",
|
|
49
|
-
"@fabrika/app": "0.9.0-dev.
|
|
50
|
-
"@fabrika/auth-core": "0.9.0-dev.
|
|
51
|
-
"@fabrika/db": "0.9.0-dev.
|
|
52
|
-
"@fabrika/operations-contract": "0.9.0-dev.
|
|
53
|
-
"@fabrika/platform-node": "0.9.0-dev.
|
|
50
|
+
"@fabrika/app": "0.9.0-dev.2",
|
|
51
|
+
"@fabrika/auth-core": "0.9.0-dev.2",
|
|
52
|
+
"@fabrika/db": "0.9.0-dev.2",
|
|
53
|
+
"@fabrika/operations-contract": "0.9.0-dev.2",
|
|
54
|
+
"@fabrika/platform-node": "0.9.0-dev.2",
|
|
54
55
|
"zod": "^3.25.76"
|
|
55
56
|
}
|
|
56
57
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** An ESTree node as `@babel/parser` returns it with the `estree` plugin, read structurally. */
|
|
2
|
+
export interface AstNode {
|
|
3
|
+
readonly type: string;
|
|
4
|
+
readonly [key: string]: unknown;
|
|
5
|
+
}
|
|
6
|
+
export interface Position {
|
|
7
|
+
readonly line: number;
|
|
8
|
+
readonly column: number;
|
|
9
|
+
}
|
|
10
|
+
export interface Comment {
|
|
11
|
+
readonly text: string;
|
|
12
|
+
readonly position: Position;
|
|
13
|
+
}
|
|
14
|
+
export interface ParsedModule {
|
|
15
|
+
readonly file: string;
|
|
16
|
+
readonly program: AstNode;
|
|
17
|
+
readonly comments: readonly Comment[];
|
|
18
|
+
/** The UTF-8 size of the source text. */
|
|
19
|
+
readonly bytes: number;
|
|
20
|
+
}
|
|
21
|
+
export type ParseResult = {
|
|
22
|
+
readonly ok: true;
|
|
23
|
+
readonly module: ParsedModule;
|
|
24
|
+
} | {
|
|
25
|
+
readonly ok: false;
|
|
26
|
+
readonly message: string;
|
|
27
|
+
readonly position: Position;
|
|
28
|
+
};
|
|
29
|
+
export declare const isNode: (value: unknown) => value is AstNode;
|
|
30
|
+
/** Whether the source wraps a node in parentheses, which the parser records beside the node rather than as one. */
|
|
31
|
+
export declare const isParenthesized: (node: AstNode) => boolean;
|
|
32
|
+
export declare const child: (node: AstNode, key: string) => AstNode | undefined;
|
|
33
|
+
/** The nodes of an array property; holes (`[a, , b]`) come back as `null`. */
|
|
34
|
+
export declare const children: (node: AstNode, key: string) => readonly (AstNode | null)[];
|
|
35
|
+
export declare const stringField: (node: AstNode, key: string) => string | undefined;
|
|
36
|
+
/** The name of an `Identifier`, or `undefined` for any other node. */
|
|
37
|
+
export declare const identifierName: (node: AstNode | undefined) => string | undefined;
|
|
38
|
+
/** The text of a node whose value is a fixed string: a string `Literal`, or a template with no `${…}`. */
|
|
39
|
+
export declare const staticString: (node: AstNode | undefined) => string | undefined;
|
|
40
|
+
/** A `TemplateElement`'s source text and its decoded value (`undefined` for an invalid escape in a tagged template). */
|
|
41
|
+
export declare const templateText: (element: AstNode) => {
|
|
42
|
+
readonly raw: string;
|
|
43
|
+
readonly cooked: string | undefined;
|
|
44
|
+
};
|
|
45
|
+
/** A property or member key read statically: `a.b`, `a['b']`, ``a[`b`]``, `{ b: … }`, `{ 'b': … }`. */
|
|
46
|
+
export declare const staticKey: (node: AstNode, keyField: "property" | "key") => string | undefined;
|
|
47
|
+
/** The static property names at the end of a member chain, whatever its root: `load().db.sql.raw` → `['db', 'sql', 'raw']`. */
|
|
48
|
+
export declare const memberSuffix: (node: AstNode) => readonly string[];
|
|
49
|
+
/** `as const` and `<const>x` fix a literal's type; they assert nothing. */
|
|
50
|
+
export declare const isConstAssertion: (node: AstNode) => boolean;
|
|
51
|
+
/** Strips the wrappers that do not change which value an expression denotes. */
|
|
52
|
+
export declare const unwrap: (node: AstNode) => AstNode;
|
|
53
|
+
/** `a.b.c` as `['a', 'b', 'c']`; `undefined` when a link is computed or the root is not an identifier. */
|
|
54
|
+
export declare const memberPath: (node: AstNode) => readonly string[] | undefined;
|
|
55
|
+
/** Whether an `Identifier` denotes a runtime value here, rather than a property name, a key, a label or a type. */
|
|
56
|
+
export declare const isValueReference: (node: AstNode, parent: AstNode | undefined) => boolean;
|
|
57
|
+
export declare const positionOf: (node: AstNode) => Position;
|
|
58
|
+
/** Visits every node below `root`, depth first, with the chain of its ancestors (nearest last); `'skip'` prunes a subtree. */
|
|
59
|
+
export declare const walk: (root: AstNode, visit: (node: AstNode, ancestors: readonly AstNode[]) => "skip" | undefined | void) => void;
|
|
60
|
+
export declare const utf8Bytes: (text: string) => number;
|
|
61
|
+
/** The nesting depth of the tree below `root`, measured without recursion, so a deep tree cannot exhaust the stack. */
|
|
62
|
+
export declare const nodeDepth: (root: AstNode) => number;
|
|
63
|
+
export declare const parseModule: (file: string, text: string) => ParseResult;
|
|
64
|
+
/** The sources of a module's import and re-export declarations; `rules/literal.ts` decides which of them are allowed. */
|
|
65
|
+
export declare const importedSpecifiers: (module: ParsedModule) => string[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { BunPlugin } from 'bun';
|
|
2
|
+
export interface ShellSliceOptions {
|
|
3
|
+
/** The application's root, where `fabrika.contract.ts` lies; the working directory by default. */
|
|
4
|
+
readonly root?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Loads every module of the application's shell graph as its slice: no `.handle(…)`, and no import only a handler
|
|
8
|
+
* used. The build fails with the reader's findings when the static reader refuses the shell.
|
|
9
|
+
*/
|
|
10
|
+
export declare function shellSlicePlugin(options?: ShellSliceOptions): BunPlugin;
|
|
11
|
+
declare const _default: BunPlugin;
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Finding } from './finding';
|
|
2
|
+
import type { PackedSet } from './packed';
|
|
3
|
+
export interface CheckInput {
|
|
4
|
+
/** The application's root directory. */
|
|
5
|
+
readonly root: string;
|
|
6
|
+
/** The application's files keyed by path relative to `root` with `/` separators; read from disk under `root` when omitted. */
|
|
7
|
+
readonly files?: ReadonlyMap<string, string>;
|
|
8
|
+
/** A local pack whose tarballs `package-replacement` accepts (`fabrika-check --packed`); a deploy build gives none. */
|
|
9
|
+
readonly packed?: PackedSet;
|
|
10
|
+
}
|
|
11
|
+
export interface ApplicationTree {
|
|
12
|
+
readonly files: ReadonlyMap<string, string>;
|
|
13
|
+
/** Symbolic links outside the skipped directories; the checker does not follow them. */
|
|
14
|
+
readonly links: readonly string[];
|
|
15
|
+
}
|
|
16
|
+
/** Every file the checker reads, by relative path, and the symbolic links it refuses to follow. */
|
|
17
|
+
export declare const readApplicationTree: (root: string) => Promise<ApplicationTree>;
|
|
18
|
+
/** Runs every rule over one application and returns the findings in file, line and column order. */
|
|
19
|
+
export declare const checkApplication: (input: CheckInput) => Promise<Finding[]>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type AnyContract } from '@fabrika/app/contract';
|
|
2
|
+
import type { ContractArtifact, TablePolicyArtifact } from '@fabrika/auth-core';
|
|
3
|
+
import { type TablePolicies, type Tables } from '@fabrika/db/tables';
|
|
4
|
+
import { type ParsedModule } from './ast';
|
|
5
|
+
import { type Finding } from './finding';
|
|
6
|
+
import { ModuleGraph } from './graph';
|
|
7
|
+
export { ContractError } from '@fabrika/app/contract';
|
|
8
|
+
export { type Finding, formatFinding } from './finding';
|
|
9
|
+
export { contractReaderInputs } from './inputs';
|
|
10
|
+
export { CONTRACT_FILE, MIGRATIONS_DIR, TABLES_FILE } from './layout';
|
|
11
|
+
export { CONTRACT_LIMITS } from './limits';
|
|
12
|
+
export { lockedRegistryVersion, LOCKFILE } from './lockfile';
|
|
13
|
+
export { CHECKER_VERSION } from './version';
|
|
14
|
+
/** Every form the reader refuses, each with its file, line, column and the allowed form. */
|
|
15
|
+
export declare class ContractSourceError extends Error {
|
|
16
|
+
readonly name = "ContractSourceError";
|
|
17
|
+
readonly findings: readonly Finding[];
|
|
18
|
+
constructor(findings: readonly Finding[]);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The contract artifact of an application, read from the text of its files (path relative to the application root →
|
|
22
|
+
* text): `fabrika.contract.ts`, every module it imports and the configuration that applies to them (`readContract`),
|
|
23
|
+
* and `src/db/tables.ts` with the modules it imports (`readTablesDefinition`). `tables`, when given, replaces what
|
|
24
|
+
* `src/db/tables.ts` declares: its parsed policies, or the artifact form of each policy.
|
|
25
|
+
*
|
|
26
|
+
* Throws `ContractSourceError` for a form the reader refuses, and `ContractError` with the same problems
|
|
27
|
+
* `compileContract` reports for a contract that does not compile.
|
|
28
|
+
*/
|
|
29
|
+
export declare function readContractSource(files: ReadonlyMap<string, string>, tables?: Tables<unknown, unknown> | Readonly<Record<string, TablePolicyArtifact>>): ContractArtifact;
|
|
30
|
+
/**
|
|
31
|
+
* The table policies of `src/db/tables.ts` in their artifact form (`readTablesDefinition`); none when `files` has no
|
|
32
|
+
* such file. Throws `ContractSourceError`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function readTablesSource(files: ReadonlyMap<string, string>): TablePolicies;
|
|
35
|
+
/**
|
|
36
|
+
* The table policies of `src/db/tables.ts`, read from source and parsed by `@fabrika/db`'s own policy parse, as
|
|
37
|
+
* `defineTables` returns them; `null` when `files` has no such file. `files` carries its imports (the generated
|
|
38
|
+
* `src/db/schema.generated.ts`) and the configuration `readContract` names. Throws `ContractSourceError`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function readTablesDefinition(files: ReadonlyMap<string, string>): Tables<unknown, unknown> | null;
|
|
41
|
+
/**
|
|
42
|
+
* The contract `defineContract` returns in the evaluated module, read from source; throws `ContractSourceError`.
|
|
43
|
+
* Besides the contract's modules, `files` carries every `package.json`, `tsconfig.json`, `jsconfig.json` and
|
|
44
|
+
* `bunfig.toml` that applies to them (the root and each directory of a contract module): one of them can redirect the
|
|
45
|
+
* packages the reader trusts by name, and the reader cannot tell a missing file from an absent one.
|
|
46
|
+
*/
|
|
47
|
+
export declare function readContract(files: ReadonlyMap<string, string>): AnyContract;
|
|
48
|
+
export type ContractRead = {
|
|
49
|
+
readonly ok: true;
|
|
50
|
+
readonly contract: AnyContract;
|
|
51
|
+
} | {
|
|
52
|
+
readonly ok: false;
|
|
53
|
+
readonly findings: readonly Finding[];
|
|
54
|
+
};
|
|
55
|
+
/** Reads the `contract` export of a graph whose contract modules already pass the literal rule. */
|
|
56
|
+
export declare function readContractModule(graph: ModuleGraph): ContractRead;
|
|
57
|
+
/** The contract module and every module its value imports reach. */
|
|
58
|
+
export declare function contractModules(graph: ModuleGraph, entry: ParsedModule): ParsedModule[];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Finding } from './finding';
|
|
2
|
+
import type { Sample } from './scaffold-sample';
|
|
3
|
+
export declare const FIXTURES_EXPORT = "fixtures";
|
|
4
|
+
export declare const SEEDS_EXPORT = "seeds";
|
|
5
|
+
export declare const MEMBERS_EXPORT = "members";
|
|
6
|
+
export declare const INVITATIONS_EXPORT = "invitations";
|
|
7
|
+
export declare const LINKS_EXPORT = "links";
|
|
8
|
+
export declare const ROWS_EXPORT = "rows";
|
|
9
|
+
type ById = Readonly<Record<string, Readonly<Record<string, Sample>>>>;
|
|
10
|
+
export interface EndpointFixtures {
|
|
11
|
+
/** The input each endpoint's cases send, by endpoint id. */
|
|
12
|
+
readonly inputs: ById;
|
|
13
|
+
/** The columns of the row each endpoint addresses, as both scopes' rows are seeded, by endpoint id. */
|
|
14
|
+
readonly seeds: ById;
|
|
15
|
+
/** The input fields that name a member of the endpoint's member directory, by endpoint id. */
|
|
16
|
+
readonly members: Readonly<Record<string, readonly string[]>>;
|
|
17
|
+
/** The input fields that name an invitation the endpoint cancels, by endpoint id. */
|
|
18
|
+
readonly invitations: Readonly<Record<string, readonly string[]>>;
|
|
19
|
+
/** The input fields that name a share link the endpoint revokes, by endpoint id. */
|
|
20
|
+
readonly links: Readonly<Record<string, readonly string[]>>;
|
|
21
|
+
/** The input fields that name a row lying in the endpoint's object, with that row's table, by endpoint id. */
|
|
22
|
+
readonly rows: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
23
|
+
}
|
|
24
|
+
export declare const NO_FIXTURES: EndpointFixtures;
|
|
25
|
+
export declare function isSampleObject(value: Sample): value is {
|
|
26
|
+
readonly [key: string]: Sample;
|
|
27
|
+
};
|
|
28
|
+
/** The fixtures of `files`, by endpoint id; none without the file. */
|
|
29
|
+
export declare function readEndpointFixtures(files: ReadonlyMap<string, string>): {
|
|
30
|
+
readonly ok: true;
|
|
31
|
+
readonly fixtures: EndpointFixtures;
|
|
32
|
+
} | {
|
|
33
|
+
readonly ok: false;
|
|
34
|
+
readonly findings: readonly Finding[];
|
|
35
|
+
};
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { AstNode, Position } from './ast';
|
|
2
|
+
/** Rules whose finding fails the check: the framework's forms and platform integrity. */
|
|
3
|
+
export declare const REFUSAL_RULE_IDS: readonly ["parse-error", "literal", "contract", "forbidden-import", "test-only-import", "unchecked-import", "forbidden-global", "raw-sql", "type-assertion", "any-type", "suppression-comment", "capability-widening", "prototype-assignment", "framework-write", "env-read", "public-env", "cross-app-fetch", "url-endpoint", "on-conflict-index", "key-literal", "client-identity", "sensitive-log", "unsafe-html", "dynamic-code", "migration-name", "file-column-migration", "crontab", "package-replacement", "skipped-test", "test-without-assertion", "generated-test-hash", "mock-module", "endpoint-fixture", "spa-server-import", "layer-import", "generated-test-import", "shared-import"];
|
|
4
|
+
/** Rules that report a step out of the application architecture. */
|
|
5
|
+
export declare const STRUCTURE_HINT_RULE_IDS: readonly ["logic-data-access", "cross-slice-queries", "handler-location", "data-access-location"];
|
|
6
|
+
/**
|
|
7
|
+
* Rules whose findings never fail the check: the architecture's, a `ctx.sql` its site does not declare, and a
|
|
8
|
+
* `{ member: true }` endpoint of a contract whose external role admits people from outside the organization.
|
|
9
|
+
*/
|
|
10
|
+
export declare const HINT_RULE_IDS: readonly ["logic-data-access", "cross-slice-queries", "handler-location", "data-access-location", "sql-undeclared", "member-admits-external"];
|
|
11
|
+
export declare const RULE_IDS: readonly ["parse-error", "literal", "contract", "forbidden-import", "test-only-import", "unchecked-import", "forbidden-global", "raw-sql", "type-assertion", "any-type", "suppression-comment", "capability-widening", "prototype-assignment", "framework-write", "env-read", "public-env", "cross-app-fetch", "url-endpoint", "on-conflict-index", "key-literal", "client-identity", "sensitive-log", "unsafe-html", "dynamic-code", "migration-name", "file-column-migration", "crontab", "package-replacement", "skipped-test", "test-without-assertion", "generated-test-hash", "mock-module", "endpoint-fixture", "spa-server-import", "layer-import", "generated-test-import", "shared-import", "logic-data-access", "cross-slice-queries", "handler-location", "data-access-location", "sql-undeclared", "member-admits-external"];
|
|
12
|
+
export type RefusalRuleId = (typeof REFUSAL_RULE_IDS)[number];
|
|
13
|
+
export type HintRuleId = (typeof HINT_RULE_IDS)[number];
|
|
14
|
+
export type RuleId = (typeof RULE_IDS)[number];
|
|
15
|
+
export type Severity = 'refusal' | 'hint';
|
|
16
|
+
interface FindingFields {
|
|
17
|
+
/** Relative to the application root, with `/` separators. */
|
|
18
|
+
readonly file: string;
|
|
19
|
+
readonly line: number;
|
|
20
|
+
readonly column: number;
|
|
21
|
+
readonly message: string;
|
|
22
|
+
/** What to write instead; every finding names it, because the reader is often an agent with no other feedback. */
|
|
23
|
+
readonly allowed: string;
|
|
24
|
+
}
|
|
25
|
+
/** A finding's severity is its rule's: a refusal rule never reports a hint, nor the reverse. */
|
|
26
|
+
export type Finding = (FindingFields & {
|
|
27
|
+
readonly severity: 'refusal';
|
|
28
|
+
readonly rule: RefusalRuleId;
|
|
29
|
+
}) | (FindingFields & {
|
|
30
|
+
readonly severity: 'hint';
|
|
31
|
+
readonly rule: HintRuleId;
|
|
32
|
+
});
|
|
33
|
+
export declare const isHintRule: (rule: RuleId) => rule is HintRuleId;
|
|
34
|
+
export type Report = (at: AstNode | Position, rule: RuleId, message: string, allowed: string) => void;
|
|
35
|
+
export declare const reporter: (file: string, findings: Finding[]) => Report;
|
|
36
|
+
export declare const formatFinding: (finding: Finding) => string;
|
|
37
|
+
export declare const compareFindings: (left: Finding, right: Finding) => number;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type AstNode, type ParsedModule } from './ast';
|
|
2
|
+
import { type Resolution } from './layout';
|
|
3
|
+
export interface Located {
|
|
4
|
+
readonly module: ParsedModule;
|
|
5
|
+
readonly node: AstNode;
|
|
6
|
+
}
|
|
7
|
+
export interface ImportBinding {
|
|
8
|
+
readonly local: string;
|
|
9
|
+
readonly specifier: string;
|
|
10
|
+
/** `default`, `*` or the imported name. */
|
|
11
|
+
readonly imported: string;
|
|
12
|
+
/** The specifier node, where a finding about this import is reported. */
|
|
13
|
+
readonly node: AstNode;
|
|
14
|
+
}
|
|
15
|
+
/** What a name denotes, followed through imports and exports to its declaration. */
|
|
16
|
+
export type Binding = {
|
|
17
|
+
readonly kind: 'const';
|
|
18
|
+
readonly module: ParsedModule;
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly init: AstNode | undefined;
|
|
21
|
+
} | {
|
|
22
|
+
readonly kind: 'default';
|
|
23
|
+
readonly module: ParsedModule;
|
|
24
|
+
readonly expression: AstNode;
|
|
25
|
+
} | {
|
|
26
|
+
readonly kind: 'package';
|
|
27
|
+
readonly specifier: string;
|
|
28
|
+
readonly imported: string;
|
|
29
|
+
} | {
|
|
30
|
+
readonly kind: 'other';
|
|
31
|
+
readonly module: ParsedModule;
|
|
32
|
+
readonly name: string;
|
|
33
|
+
} | {
|
|
34
|
+
readonly kind: 'unresolved';
|
|
35
|
+
readonly reason: string;
|
|
36
|
+
};
|
|
37
|
+
interface ModuleIndex {
|
|
38
|
+
readonly consts: ReadonlyMap<string, AstNode | undefined>;
|
|
39
|
+
/** Top-level names that are not consts: `let`, `var`, functions, classes. */
|
|
40
|
+
readonly others: ReadonlySet<string>;
|
|
41
|
+
readonly imports: ReadonlyMap<string, ImportBinding>;
|
|
42
|
+
/** Exported name → the local name it exports, or the default export's expression. */
|
|
43
|
+
readonly exports: ReadonlyMap<string, string | AstNode>;
|
|
44
|
+
}
|
|
45
|
+
/** Erased wrappers: `x satisfies T`, `x as const`, parentheses. */
|
|
46
|
+
export declare const unwrapValue: (node: AstNode) => AstNode;
|
|
47
|
+
/** The application's modules, read statically: what each name denotes, without executing anything. */
|
|
48
|
+
export declare class ModuleGraph {
|
|
49
|
+
#private;
|
|
50
|
+
constructor(modules: ReadonlyMap<string, ParsedModule>);
|
|
51
|
+
module(file: string): ParsedModule | undefined;
|
|
52
|
+
index(module: ParsedModule): ModuleIndex;
|
|
53
|
+
/** How a relative specifier resolves among the checked modules. */
|
|
54
|
+
resolution(from: string, specifier: string): Resolution;
|
|
55
|
+
/** The checked module a relative specifier names; none when two candidates compete, the index of a directory import. */
|
|
56
|
+
resolve(from: string, specifier: string): ParsedModule | undefined;
|
|
57
|
+
/** What `name` denotes in `module`; an import is followed to the exporting module's declaration. */
|
|
58
|
+
binding(module: ParsedModule, name: string, seen?: ReadonlySet<string>): Binding;
|
|
59
|
+
/** What an exported name of `module` denotes. */
|
|
60
|
+
exported(module: ParsedModule, name: string, seen?: ReadonlySet<string>): Binding;
|
|
61
|
+
/** Follows identifiers and erased wrappers to the expression a value is written as; `undefined` when it is not static. */
|
|
62
|
+
resolveValue(located: Located, depth?: number): Located | undefined;
|
|
63
|
+
/** The fixed string a value resolves to. */
|
|
64
|
+
resolveString(located: Located): string | undefined;
|
|
65
|
+
}
|
|
66
|
+
/** The value of `key` in an object literal, read statically; spreads and computed keys are not followed. */
|
|
67
|
+
export declare const propertyValue: (located: Located, key: string) => Located | undefined;
|
|
68
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { type ApplicationTree, checkApplication, type CheckInput, readApplicationTree } from './check';
|
|
2
|
+
export { type Finding, formatFinding, RULE_IDS, type RuleId } from './finding';
|
|
3
|
+
export { CONTRACT_FILE, GENERATED_ENTRY_FILE, MIGRATIONS_DIR, TABLES_FILE, ZEROPS_FILES } from './layout';
|
|
4
|
+
export { type PackedSet, type PackedTarball, readPackedSet } from './packed';
|
|
5
|
+
export { GENERATED_TEST_HEADER, generatedTestHeader } from './rules/tests';
|
|
6
|
+
export { ENDPOINT_ACCESS_TEST, ENDPOINT_FIXTURES_FILE, type GeneratedTest, generatedTests, missingEndpointFixtures, POLICY_TESTS_DIR, policyTestPath, scaffoldInputs, } from './scaffold';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The paths `readContractSource` reads that `files` does not hold yet, among the paths that `exists` at the commit:
|
|
3
|
+
* `fabrika.contract.ts` and `src/db/tables.ts`, every module the shell slice of each imports (an import only a
|
|
4
|
+
* colocated handler uses is never followed) with every candidate of an import, the
|
|
5
|
+
* `package.json`, `tsconfig.json` and `jsconfig.json` of each such module's directories, a root `bunfig.toml`, and the
|
|
6
|
+
* files a `tsconfig.json` extends. A module is followed only once its text is in `files`, so the caller reads the answer,
|
|
7
|
+
* adds it to `files` and asks again until the answer is empty.
|
|
8
|
+
*/
|
|
9
|
+
export declare function contractReaderInputs(files: ReadonlyMap<string, string>, exists: (path: string) => boolean): string[];
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** Where an application keeps what the checker reads. Paths are relative to the application root. */
|
|
2
|
+
export declare const CONTRACT_FILE = "fabrika.contract.ts";
|
|
3
|
+
/** The named export of the contract module that holds `defineContract(…)`. */
|
|
4
|
+
export declare const CONTRACT_EXPORT = "contract";
|
|
5
|
+
export declare const TABLES_FILE = "src/db/tables.ts";
|
|
6
|
+
/** The named export of the tables module that holds `defineTables(…)(…)`. */
|
|
7
|
+
export declare const TABLES_EXPORT = "tables";
|
|
8
|
+
export declare const GENERATED_ENTRY_FILE = "fabrika/entry.generated.ts";
|
|
9
|
+
export declare const MIGRATIONS_DIR = "db/migrations/";
|
|
10
|
+
/** Where `fabrika db test-scaffold` writes the policy isolation tests, `<table>.policy-isolation.test.ts`. */
|
|
11
|
+
export declare const POLICY_TESTS_DIR = "src/db/__tests__/";
|
|
12
|
+
export declare const POLICY_TEST_SUFFIX = ".policy-isolation.test.ts";
|
|
13
|
+
/** The generated endpoint access tests; they import `src/app.ts`, whose default export they boot. */
|
|
14
|
+
export declare const ENDPOINT_ACCESS_TEST = "src/__tests__/endpoint-access.test.ts";
|
|
15
|
+
/** The inputs the author gives the endpoint access tests where the scaffold cannot sample one; read, never run. */
|
|
16
|
+
export declare const ENDPOINT_FIXTURES_FILE = "src/__tests__/endpoint-access.fixtures.ts";
|
|
17
|
+
export declare const ZEROPS_FILES: readonly ["zerops.yaml", "zerops.yml"];
|
|
18
|
+
/** The application architecture (docs/reference/application-architecture.md): where each layer's code lives. */
|
|
19
|
+
export declare const VOCABULARY_FILE = "src/vocabulary.ts";
|
|
20
|
+
export declare const APP_KIT_FILE = "src/app-kit.ts";
|
|
21
|
+
/** The shared zod schemas the shell and the SPA import: one module, or a directory of them once it grows. */
|
|
22
|
+
export declare const SCHEMAS_FILE = "src/schemas.ts";
|
|
23
|
+
export declare const SCHEMAS_DIR = "src/schemas/";
|
|
24
|
+
/** Pure code the SPA and every slice may import: it loads nothing but `zod/v4` and other modules of its own directory. */
|
|
25
|
+
export declare const SHARED_DIR = "src/shared/";
|
|
26
|
+
/** `src/db/`: the tables, the generated schema and their generated tests; never a slice. */
|
|
27
|
+
export declare const DATABASE_DIR = "src/db/";
|
|
28
|
+
/** A slice is a directory `src/<slice>/` that holds these modules, each optional. */
|
|
29
|
+
export declare const SLICE_ENDPOINTS_FILE = "endpoints.ts";
|
|
30
|
+
export declare const SLICE_LOGIC_FILE = "logic.ts";
|
|
31
|
+
export declare const SLICE_QUERIES_FILE = "queries.ts";
|
|
32
|
+
export declare const SPA_DIR = "web/";
|
|
33
|
+
/** The server half of an application: its modules run in the application's process. */
|
|
34
|
+
export declare const SERVER_DIR = "src/";
|
|
35
|
+
/** Build output, installed packages and tool state are not application source and are never read. */
|
|
36
|
+
export declare const isIgnoredSegment: (segment: string) => boolean;
|
|
37
|
+
export declare const isSourceFile: (path: string) => boolean;
|
|
38
|
+
export declare const isTestFile: (path: string) => boolean;
|
|
39
|
+
/** A module that runs in the application's server process: under `src/`, not a test. */
|
|
40
|
+
export declare const isServerModule: (path: string) => boolean;
|
|
41
|
+
export declare const isJsonFile: (path: string) => boolean;
|
|
42
|
+
/** Whether the checker reads this file at all. */
|
|
43
|
+
export declare const isCheckedFile: (path: string) => boolean;
|
|
44
|
+
/** Joins a relative specifier onto the importing file's directory; `undefined` when it climbs above the root. */
|
|
45
|
+
export declare const joinRelative: (fromFile: string, specifier: string) => string | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* How a relative import resolves among the files that exist. Only an exact name, or exactly one extension candidate,
|
|
48
|
+
* is a `file`: with two candidates (`m.ts` and `m.tsx`) or a directory, Bun's choice is not one the checker repeats.
|
|
49
|
+
*/
|
|
50
|
+
export type Resolution = {
|
|
51
|
+
readonly kind: 'file';
|
|
52
|
+
readonly path: string;
|
|
53
|
+
} | {
|
|
54
|
+
readonly kind: 'ambiguous';
|
|
55
|
+
readonly paths: readonly string[];
|
|
56
|
+
} | {
|
|
57
|
+
readonly kind: 'directory';
|
|
58
|
+
readonly paths: readonly string[];
|
|
59
|
+
} | {
|
|
60
|
+
readonly kind: 'missing';
|
|
61
|
+
};
|
|
62
|
+
export declare const resolveRelative: (exists: (path: string) => boolean, fromFile: string, specifier: string) => Resolution;
|
|
63
|
+
export declare const isRelativeSpecifier: (specifier: string) => boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The resource budget of reading a contract from source. Control reads an application's commit, so a contract may
|
|
3
|
+
* not make the reader or `compileContract` do unbounded work; each limit is enforced while reading, before the next
|
|
4
|
+
* step runs.
|
|
5
|
+
*/
|
|
6
|
+
export declare const CONTRACT_LIMITS: {
|
|
7
|
+
/** UTF-8 bytes of `fabrika.contract.ts` and every module it imports, together. */
|
|
8
|
+
readonly sourceBytes: number;
|
|
9
|
+
/** Nesting of syntax nodes in one module; the contracts in this repository reach 25. */
|
|
10
|
+
readonly astDepth: 128;
|
|
11
|
+
/** Schema nodes once every shared schema is expanded where the contract uses it, over the whole contract. */
|
|
12
|
+
readonly schemaNodes: 20000;
|
|
13
|
+
/** Nesting of one schema: objects, arrays, unions and wrappers. */
|
|
14
|
+
readonly schemaDepth: 32;
|
|
15
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const LOCKFILE = "bun.lock";
|
|
2
|
+
/** An exact version, as `bun install` records one resolved from the registry. */
|
|
3
|
+
export declare const EXACT_VERSION: RegExp;
|
|
4
|
+
/** One `packages` entry: `[<name>@<version>, <registry>, <metadata>, <integrity>]`; a tarball has no registry. */
|
|
5
|
+
export interface LockfileEntry {
|
|
6
|
+
/** What follows `<name>@` in the resolution, or empty when the resolution names another package. */
|
|
7
|
+
readonly version: string;
|
|
8
|
+
readonly registry: unknown;
|
|
9
|
+
readonly integrity: unknown;
|
|
10
|
+
}
|
|
11
|
+
/** The `packages` of a `bun.lock` by key; null when the text is not a lockfile bun writes. */
|
|
12
|
+
export declare function lockfilePackages(text: string): Readonly<Record<string, unknown>> | null;
|
|
13
|
+
export declare function lockfileEntry(name: string, entry: unknown): LockfileEntry;
|
|
14
|
+
/**
|
|
15
|
+
* The registry version the lockfile resolves the package `name` to for the application itself: its top-level entry,
|
|
16
|
+
* not one nested under another package. Null when the text is not a lockfile, holds no such entry, or resolves it from
|
|
17
|
+
* anywhere but the npm registry.
|
|
18
|
+
*/
|
|
19
|
+
export declare function lockedRegistryVersion(text: string, name: string): string | null;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** One package of the set: the tarball `release:pack` wrote and the sha512 integrity of its bytes. */
|
|
2
|
+
export interface PackedTarball {
|
|
3
|
+
readonly filename: string;
|
|
4
|
+
readonly integrity: string;
|
|
5
|
+
}
|
|
6
|
+
export interface PackedSet {
|
|
7
|
+
/** The version the pack gave every package of the set. */
|
|
8
|
+
readonly version: string;
|
|
9
|
+
/** Each package's tarball, by package name. */
|
|
10
|
+
readonly packages: ReadonlyMap<string, PackedTarball>;
|
|
11
|
+
/** The sha512 integrity of every file under the root named like one of the tarballs, by path relative to the root. */
|
|
12
|
+
readonly tarballs: ReadonlyMap<string, string>;
|
|
13
|
+
}
|
|
14
|
+
/** The packed set `manifestText` (a `release-manifest.json`) describes, with the tarballs found under `root`. */
|
|
15
|
+
export declare const readPackedSet: (root: string, manifestText: string) => Promise<PackedSet>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Finding } from '../finding';
|
|
2
|
+
import type { Located } from '../graph';
|
|
3
|
+
/** Every form the reader refuses, as findings of the `contract` rule with where it is and the allowed form. */
|
|
4
|
+
export declare class ReaderProblems {
|
|
5
|
+
readonly findings: Finding[];
|
|
6
|
+
add(at: Located, message: string, allowed: string): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from 'zod/v4';
|
|
2
|
+
import type { LiteralValue } from './value';
|
|
3
|
+
export type SchemaStep = {
|
|
4
|
+
readonly factory: string;
|
|
5
|
+
readonly iso: boolean;
|
|
6
|
+
} | {
|
|
7
|
+
readonly method: string;
|
|
8
|
+
readonly receiver: z.ZodType | undefined;
|
|
9
|
+
};
|
|
10
|
+
export type BuiltSchema = {
|
|
11
|
+
readonly ok: true;
|
|
12
|
+
readonly schema: z.ZodType;
|
|
13
|
+
} | {
|
|
14
|
+
readonly ok: false;
|
|
15
|
+
readonly message: string;
|
|
16
|
+
readonly allowed: string;
|
|
17
|
+
};
|
|
18
|
+
export declare function buildSchema(step: SchemaStep, args: readonly LiteralValue[]): BuiltSchema;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type AnyContract } from '@fabrika/app/contract';
|
|
2
|
+
import type { ReaderProblems } from './problems';
|
|
3
|
+
import { type LiteralValue } from './value';
|
|
4
|
+
/** Reads a `defineContract(…)` value into the contract `defineContract` returns; `null` after recording why not. */
|
|
5
|
+
export declare function readContractValue(value: LiteralValue, problems: ReaderProblems): AnyContract | null;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Tables } from '@fabrika/db/tables';
|
|
2
|
+
import { type ParsedModule } from '../ast';
|
|
3
|
+
import type { ModuleGraph } from '../graph';
|
|
4
|
+
import type { ReaderProblems } from './problems';
|
|
5
|
+
/** The policies of `src/db/tables.ts`, as `defineTables` returns them; `null` after recording why not. */
|
|
6
|
+
export declare function readTablesValue(graph: ModuleGraph, module: ParsedModule, problems: ReaderProblems): Tables<unknown, unknown> | null;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { z } from 'zod/v4';
|
|
2
|
+
import { type AstNode, type ParsedModule } from '../ast';
|
|
3
|
+
import type { Located, ModuleGraph } from '../graph';
|
|
4
|
+
import type { ReaderProblems } from './problems';
|
|
5
|
+
/**
|
|
6
|
+
* The builder kit a call belongs to: `c` of `defineContract` and `l` of its link's `procedures`; `app`, the kit
|
|
7
|
+
* `defineApp` returned; `c` of `app.contract` (`shell`) and `r` of a group, a link or an export (`endpoints`).
|
|
8
|
+
*/
|
|
9
|
+
export type Kit = 'surface' | 'link' | 'app' | 'shell' | 'endpoints';
|
|
10
|
+
/** The parameter name a kit is written with, in messages. */
|
|
11
|
+
export declare const kitName: (kit: Kit) => string;
|
|
12
|
+
export type LiteralValue = {
|
|
13
|
+
readonly kind: 'string';
|
|
14
|
+
readonly value: string;
|
|
15
|
+
readonly at: Located;
|
|
16
|
+
} | {
|
|
17
|
+
readonly kind: 'number';
|
|
18
|
+
readonly value: number;
|
|
19
|
+
readonly at: Located;
|
|
20
|
+
} | {
|
|
21
|
+
readonly kind: 'boolean';
|
|
22
|
+
readonly value: boolean;
|
|
23
|
+
readonly at: Located;
|
|
24
|
+
} | {
|
|
25
|
+
readonly kind: 'null';
|
|
26
|
+
readonly at: Located;
|
|
27
|
+
} | {
|
|
28
|
+
readonly kind: 'regex';
|
|
29
|
+
readonly value: RegExp;
|
|
30
|
+
readonly at: Located;
|
|
31
|
+
} | {
|
|
32
|
+
readonly kind: 'array';
|
|
33
|
+
readonly items: readonly LiteralValue[];
|
|
34
|
+
readonly at: Located;
|
|
35
|
+
}
|
|
36
|
+
/** Entries in source order; a repeated key keeps its first position and its last value, as in an object literal. */
|
|
37
|
+
| {
|
|
38
|
+
readonly kind: 'object';
|
|
39
|
+
readonly entries: ReadonlyMap<string, LiteralValue>;
|
|
40
|
+
readonly at: Located;
|
|
41
|
+
}
|
|
42
|
+
/** `nodes` counts the schema with every shared part expanded, as the artifact will hold it; `depth` its nesting. */
|
|
43
|
+
| {
|
|
44
|
+
readonly kind: 'schema';
|
|
45
|
+
readonly schema: z.ZodType;
|
|
46
|
+
readonly nodes: number;
|
|
47
|
+
readonly depth: number;
|
|
48
|
+
/** The chain that built it, factory first (`iso` for `z.iso.*`), across a const and the methods applied to it. */
|
|
49
|
+
readonly steps: readonly string[];
|
|
50
|
+
readonly at: Located;
|
|
51
|
+
}
|
|
52
|
+
/** `c.rpc(…)` or `l.query(…)`, with its arguments read. */
|
|
53
|
+
| {
|
|
54
|
+
readonly kind: 'builder';
|
|
55
|
+
readonly kit: Kit;
|
|
56
|
+
readonly name: string;
|
|
57
|
+
readonly args: readonly LiteralValue[];
|
|
58
|
+
readonly at: Located;
|
|
59
|
+
} | {
|
|
60
|
+
readonly kind: 'contract';
|
|
61
|
+
readonly args: readonly LiteralValue[];
|
|
62
|
+
readonly at: Located;
|
|
63
|
+
}
|
|
64
|
+
/** `defineApp(vocabulary, tables, options?)`: the vocabulary and the options; the tables are `src/db/tables.ts`'. */
|
|
65
|
+
| AppValue
|
|
66
|
+
/** `app.contract((c) => ({ … }))`, with the kit it was called on. */
|
|
67
|
+
| {
|
|
68
|
+
readonly kind: 'kit-contract';
|
|
69
|
+
readonly app: AppValue;
|
|
70
|
+
readonly args: readonly LiteralValue[];
|
|
71
|
+
readonly at: Located;
|
|
72
|
+
}
|
|
73
|
+
/** `attachment({ … })`, with its argument read; `surface.ts` builds the output schema the evaluated module holds. */
|
|
74
|
+
| {
|
|
75
|
+
readonly kind: 'attachment';
|
|
76
|
+
readonly args: readonly LiteralValue[];
|
|
77
|
+
readonly at: Located;
|
|
78
|
+
}
|
|
79
|
+
/** `redirect({ … })`, with its argument read; `surface.ts` builds the output schema the evaluated module holds. */
|
|
80
|
+
| {
|
|
81
|
+
readonly kind: 'redirect';
|
|
82
|
+
readonly args: readonly LiteralValue[];
|
|
83
|
+
readonly at: Located;
|
|
84
|
+
}
|
|
85
|
+
/** `token(Claims, { maxDays })` of `defineApp`'s options, with its arguments read; `surface.ts` reads the purpose. */
|
|
86
|
+
| {
|
|
87
|
+
readonly kind: 'token';
|
|
88
|
+
readonly args: readonly LiteralValue[];
|
|
89
|
+
readonly at: Located;
|
|
90
|
+
}
|
|
91
|
+
/** A builder callback: its parameter is only ever a kit, so its body is read once, as a value. */
|
|
92
|
+
| {
|
|
93
|
+
readonly kind: 'callback';
|
|
94
|
+
readonly result: LiteralValue;
|
|
95
|
+
readonly at: Located;
|
|
96
|
+
};
|
|
97
|
+
export interface AppValue {
|
|
98
|
+
readonly kind: 'app';
|
|
99
|
+
readonly vocabulary: LiteralValue;
|
|
100
|
+
readonly options: LiteralValue | undefined;
|
|
101
|
+
readonly at: Located;
|
|
102
|
+
}
|
|
103
|
+
export declare class ValueReader {
|
|
104
|
+
#private;
|
|
105
|
+
constructor(graph: ModuleGraph, problems: ReaderProblems);
|
|
106
|
+
/** The value of one expression outside any builder callback, or `null` after recording why there is none. */
|
|
107
|
+
value(located: Located): LiteralValue | null;
|
|
108
|
+
/** The value `name` is exported as from `module`, or `null` after recording why there is none. */
|
|
109
|
+
exported(module: ParsedModule, name: string, at: AstNode): LiteralValue | null;
|
|
110
|
+
}
|
|
111
|
+
export declare const schemaLimits: () => string;
|
|
112
|
+
/** The name of a value kind, for a problem that names what was expected. */
|
|
113
|
+
export declare const describeKind: (value: LiteralValue) => string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type AstNode } from './ast';
|
|
2
|
+
/**
|
|
3
|
+
* One way a module names another: a static import, a re-export, a dynamic `import()`, `require()` (also `module.require`
|
|
4
|
+
* and `import.meta.require`) or `import x = require()`.
|
|
5
|
+
*/
|
|
6
|
+
export interface ModuleReference {
|
|
7
|
+
readonly specifier: string;
|
|
8
|
+
readonly node: AstNode;
|
|
9
|
+
/** The names taken from the module: imported or re-exported names, `default`, or `*` for the whole module. */
|
|
10
|
+
readonly names: readonly string[];
|
|
11
|
+
/** Erased at compile time: `import type`, or a declaration whose every specifier is `type`. */
|
|
12
|
+
readonly typeOnly: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare const isRequire: (callee: AstNode | undefined) => boolean;
|
|
15
|
+
export declare const moduleReferences: (program: AstNode) => readonly ModuleReference[];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Pattern → targets. A target is a bare specifier, an absolute path, or `./<path from the root>` (`../…` above it). */
|
|
2
|
+
type MappingTable = ReadonlyMap<string, readonly string[]>;
|
|
3
|
+
/**
|
|
4
|
+
* The application's own import mappings, as Bun applies them to one module: `compilerOptions.paths` of the nearest
|
|
5
|
+
* `tsconfig.json` (or `jsconfig.json`), with its local `extends`, then `imports` of the nearest `package.json`.
|
|
6
|
+
*/
|
|
7
|
+
export interface ImportMappings {
|
|
8
|
+
readonly paths: (file: string) => MappingTable;
|
|
9
|
+
readonly imports: (file: string) => MappingTable;
|
|
10
|
+
/** Whether Bun may find a module at a target; one outside what the checker reads counts, so a rule still sees it. */
|
|
11
|
+
readonly mayExist: (target: string) => boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare const readImportMappings: (files: ReadonlyMap<string, string>) => ImportMappings;
|
|
14
|
+
/**
|
|
15
|
+
* What a bare specifier in `file` is mapped to, in Bun's order: a builtin is never mapped; then the first `paths`
|
|
16
|
+
* target that exists; when none does, the package scope's `imports`; `undefined` when nothing maps it, so it is loaded
|
|
17
|
+
* as a package. A relative target is `./<path from the root>` (`../…` above it).
|
|
18
|
+
*/
|
|
19
|
+
export declare const mappedTargets: (mappings: ImportMappings, file: string, specifier: string) => readonly string[] | undefined;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Finding } from '../finding';
|
|
2
|
+
import type { ModuleGraph } from '../graph';
|
|
3
|
+
/**
|
|
4
|
+
* What Control's static reader refuses, reported in the build: a form the reader cannot read into the contract, and a
|
|
5
|
+
* schema `describeContract` refuses. Runs only once the literal rule passes. Table policies are not read yet (A8b), so
|
|
6
|
+
* the checks `buildArtifact` makes against them run only where the tables are known.
|
|
7
|
+
*/
|
|
8
|
+
export declare const checkContractRead: (graph: ModuleGraph) => Finding[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ParsedModule } from '../ast';
|
|
2
|
+
import type { Finding } from '../finding';
|
|
3
|
+
import { type ModuleGraph } from '../graph';
|
|
4
|
+
export interface ContractJob {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
/** `undefined` when the contract's schedule is not a static string. */
|
|
7
|
+
readonly schedule: string | undefined;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Every `<name>: c.cron('<schedule>', { … })` in the contract, and every `<name>` there that names a const of the
|
|
11
|
+
* kit's `app.cron('<schedule>', { … })`; the schedule is resolved through literal consts.
|
|
12
|
+
*/
|
|
13
|
+
export declare const contractJobs: (contract: ParsedModule, graph: ModuleGraph) => readonly ContractJob[];
|
|
14
|
+
/** Each setup that runs the application carries exactly the contract's jobs as crontab entries, and nothing else. */
|
|
15
|
+
export declare const checkCrontab: (file: string, text: string, jobs: readonly ContractJob[]) => Finding[];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type AstNode } from '../ast';
|
|
2
|
+
import type { Report } from '../finding';
|
|
3
|
+
import { type ImportMappings } from '../resolution';
|
|
4
|
+
/** One name bound to a trusted package's value, in the scope that declares it. */
|
|
5
|
+
interface TrustedBinding {
|
|
6
|
+
readonly specifier: string;
|
|
7
|
+
readonly scope: AstNode | undefined;
|
|
8
|
+
}
|
|
9
|
+
/** Local name → each declaration of it that holds a trusted package's value. */
|
|
10
|
+
export type TrustedBindings = ReadonlyMap<string, readonly TrustedBinding[]>;
|
|
11
|
+
/** What a module binds to a trusted package's values: its imports, `import x = require()`, and direct loads into a `const`. */
|
|
12
|
+
export declare const trustedBindings: (file: string, program: AstNode, mappings: ImportMappings) => TrustedBindings;
|
|
13
|
+
/**
|
|
14
|
+
* A write to a member of a value from `@fabrika/*` or `zod`: an assignment, `delete`, `++`, or a writer call on it. A
|
|
15
|
+
* replaced `Database.postgres` receives the database URL; a patched schema changes what the contract admits. A write
|
|
16
|
+
* through a prototype is `prototype-assignment`'s. A local that shadows such a name is not one.
|
|
17
|
+
*/
|
|
18
|
+
export declare const checkFrameworkWrite: (node: AstNode, ancestors: readonly AstNode[], bindings: TrustedBindings, report: Report) => void;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type ParsedModule } from '../ast';
|
|
2
|
+
import { type Finding } from '../finding';
|
|
3
|
+
import { type ModuleGraph } from '../graph';
|
|
4
|
+
/** Endpoint inputs that carry the caller's identity or tenant, outside the `in`/`on` form that checks it. */
|
|
5
|
+
export declare const checkClientIdentity: (contract: ParsedModule, graph: ModuleGraph) => Finding[];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Finding } from '../finding';
|
|
2
|
+
import { type GeneratedTest } from '../scaffold';
|
|
3
|
+
/** The tests the scaffold writes for these files, or the findings that stop it from reading them. */
|
|
4
|
+
export declare const expectedGeneratedTests: (files: ReadonlyMap<string, string>) => Promise<{
|
|
5
|
+
readonly ok: true;
|
|
6
|
+
readonly tests: ReadonlyMap<string, GeneratedTest>;
|
|
7
|
+
readonly missing: readonly Finding[];
|
|
8
|
+
} | {
|
|
9
|
+
readonly ok: false;
|
|
10
|
+
readonly findings: readonly Finding[];
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Every generated test is byte for byte what the scaffold writes from the current contract and policies: a missing,
|
|
14
|
+
* edited or replaced one is a finding, header or not, and so is a generated test the scaffold no longer writes.
|
|
15
|
+
* `readable` is false while the literal or trust rules report the sources; otherwise what the reader refuses is
|
|
16
|
+
* reported here, so a source it cannot read does not silence the check.
|
|
17
|
+
*/
|
|
18
|
+
export declare const checkGeneratedTests: (files: ReadonlyMap<string, string>, readable: boolean) => Promise<Finding[]>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type AstNode, type ParsedModule } from '../ast';
|
|
2
|
+
import { type Finding } from '../finding';
|
|
3
|
+
import type { ModuleGraph } from '../graph';
|
|
4
|
+
/**
|
|
5
|
+
* What a call root builds. `surface` is the parameter of a `defineContract` callback (`c`, `l`); `app` is
|
|
6
|
+
* `defineApp`, `kit` a const it returned, `shell` the parameter of `app.contract`'s callback and `endpoints` that of
|
|
7
|
+
* a group's, a link's or an export's; `attachment` is the output `attachment({ … })`, `file` a file field or output;
|
|
8
|
+
* `value` is a schema the package exports, read as it is (`WebhookSecret`).
|
|
9
|
+
*/
|
|
10
|
+
export type BuilderKind = 'zod' | 'contract' | 'vocabulary' | 'tables' | 'surface' | 'app' | 'kit' | 'shell' | 'endpoints' | 'attachment' | 'redirect' | 'file' | 'value' | 'token' | 'signedToken';
|
|
11
|
+
/** The only imported names a literal module may use: the builders the platform reads without executing them. */
|
|
12
|
+
export declare const BUILDER_IMPORTS: Readonly<Record<string, Readonly<Record<string, BuilderKind>>>>;
|
|
13
|
+
/** The methods of the kit `defineApp` returns. */
|
|
14
|
+
export declare const KIT_BUILDERS: ReadonlySet<string>;
|
|
15
|
+
/** The builders of `app.contract`'s callback: the mounts that take no handler, and `rpc`, which mounts groups. */
|
|
16
|
+
export declare const SHELL_BUILDERS: ReadonlySet<string>;
|
|
17
|
+
/** The builders of a group's, a link's and an export's callback. */
|
|
18
|
+
export declare const ENDPOINT_BUILDERS: ReadonlySet<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Where a kit method takes a builder callback, and the kit its parameter denotes: a group's endpoints, the contract's
|
|
21
|
+
* mounts, a link's and an export's `procedures` (`options: true`).
|
|
22
|
+
*/
|
|
23
|
+
export declare const KIT_CALLBACKS: Readonly<Record<string, {
|
|
24
|
+
readonly position: number;
|
|
25
|
+
readonly kind: BuilderKind;
|
|
26
|
+
readonly options: boolean;
|
|
27
|
+
}>>;
|
|
28
|
+
/** Whether `init` is `defineApp(…)`, `defineApp` imported from `@fabrika/app/contract` into `module`. */
|
|
29
|
+
export declare const isAppCall: (graph: ModuleGraph, module: ParsedModule, init: AstNode) => boolean;
|
|
30
|
+
/** Whether `name` in `module` denotes a const `defineApp(…)` returned: the application's kit. */
|
|
31
|
+
export declare const isKitName: (graph: ModuleGraph, module: ParsedModule, name: string) => boolean;
|
|
32
|
+
export type Link = {
|
|
33
|
+
readonly kind: 'member';
|
|
34
|
+
readonly name: string | undefined;
|
|
35
|
+
readonly node: AstNode;
|
|
36
|
+
} | {
|
|
37
|
+
readonly kind: 'call';
|
|
38
|
+
readonly node: AstNode;
|
|
39
|
+
};
|
|
40
|
+
/** `z['string']()` names the same builder, but a key read through a const is no longer a name the reader sees. */
|
|
41
|
+
export declare const isComputedMember: (link: Link) => boolean;
|
|
42
|
+
/** `z.string().min(1)` → root `z`, links `.string` `()` `.min` `(1)`. */
|
|
43
|
+
export declare const decompose: (node: AstNode) => {
|
|
44
|
+
readonly root: AstNode;
|
|
45
|
+
readonly links: readonly Link[];
|
|
46
|
+
};
|
|
47
|
+
export interface StringStepProblem {
|
|
48
|
+
/** The step that makes the chain order-dependent: 0 is the factory, then each method in turn. */
|
|
49
|
+
readonly index: number;
|
|
50
|
+
readonly message: string;
|
|
51
|
+
readonly allowed: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The artifact keeps a string's checks unordered (`@fabrika/app`'s schema-shape.ts), so the chain may not depend on
|
|
55
|
+
* their order: `z.url()` rewrites the value the checks after it see, and an affix overlaps a format. `steps` is the
|
|
56
|
+
* factory (`iso` for `z.iso.*`) and then the methods, also across a schema const and the methods applied to it.
|
|
57
|
+
*/
|
|
58
|
+
export declare const stringStepProblem: (steps: readonly string[]) => StringStepProblem | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* The contract, its schema modules and the table policies are literals (D5), so that the platform can read them from a
|
|
61
|
+
* commit without executing them. `entries` are the graph's roots; relative value imports pull further modules in.
|
|
62
|
+
*/
|
|
63
|
+
export declare const checkLiteralGraph: (entries: readonly string[], graph: ModuleGraph) => Finding[];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Finding } from '../finding';
|
|
2
|
+
/** Migration file names sort by creation time, so parallel worktrees never claim the same name. */
|
|
3
|
+
export declare const checkMigrationNames: (paths: readonly string[]) => Finding[];
|
|
4
|
+
/** A declared file column: `table.column` holds files of `kind`. */
|
|
5
|
+
export interface FileColumn {
|
|
6
|
+
readonly table: string;
|
|
7
|
+
readonly column: string;
|
|
8
|
+
readonly kind: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Every declared file column needs a foreign key to `fabrika_files (id)`, which keeps the sweep from deleting a file a
|
|
12
|
+
* row references, and an index it leads, which the sweep's reference check and each file deletion read. Only what a
|
|
13
|
+
* migration creates counts: a `REFERENCES fabrika_files` on the column or a one-column foreign key, and a `CREATE
|
|
14
|
+
* INDEX` without `WHERE`, a `UNIQUE` or a `PRIMARY KEY` whose first column it is, minus a later `DROP INDEX`.
|
|
15
|
+
*/
|
|
16
|
+
export declare const checkFileColumnMigrations: (files: ReadonlyMap<string, string>, columns: readonly FileColumn[]) => Finding[];
|
|
17
|
+
/** An `insert(values, { onConflict: { columns } })` the source makes, with the finding it gets when no index fits. */
|
|
18
|
+
export interface ConflictInsert {
|
|
19
|
+
readonly table: string;
|
|
20
|
+
readonly columns: readonly string[];
|
|
21
|
+
readonly finding: Finding;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* `onConflict.columns` must name a unique index the migrations create, or Postgres refuses the insert at run time: the
|
|
25
|
+
* set of columns of a `UNIQUE` or `PRIMARY KEY` constraint, or of a `CREATE UNIQUE INDEX` without `WHERE` or expression,
|
|
26
|
+
* minus a later `DROP INDEX`. Order does not matter, as for Postgres. Only a table `src/db/tables.ts` declares is
|
|
27
|
+
* checked: another receiver of `insert` is no table of the data layer.
|
|
28
|
+
*/
|
|
29
|
+
export declare const checkConflictIndexes: (files: ReadonlyMap<string, string>, tables: ReadonlySet<string>, inserts: readonly ConflictInsert[]) => Finding[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Report } from '../finding';
|
|
2
|
+
import type { ModuleReference } from '../references';
|
|
3
|
+
import { type ImportMappings } from '../resolution';
|
|
4
|
+
interface Forbidden {
|
|
5
|
+
readonly what: string;
|
|
6
|
+
readonly allowed: string;
|
|
7
|
+
}
|
|
8
|
+
/** The `Bun` globals that open a server, a socket, a database, a bucket or a process; imported by name from `bun`, the same bypass. */
|
|
9
|
+
export declare const FORBIDDEN_BUN_MEMBERS: ReadonlyMap<string, Forbidden>;
|
|
10
|
+
export declare const isTestKit: (specifier: string) => boolean;
|
|
11
|
+
export declare const checkModuleReferences: (file: string, references: readonly ModuleReference[], mappings: ImportMappings, exists: (path: string) => boolean, report: Report, isGeneratedEntry: boolean, isTest: boolean) => void;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type AstNode } from '../ast';
|
|
2
|
+
import type { Finding, Report } from '../finding';
|
|
3
|
+
import type { PackedSet } from '../packed';
|
|
4
|
+
export declare const NPMRC_FILE = ".npmrc";
|
|
5
|
+
export declare const checkPackageReplacement: (files: ReadonlyMap<string, string>, packed?: PackedSet) => Finding[];
|
|
6
|
+
/** `declare module '@fabrika/app'` retypes a trusted package for the type check without changing what runs. */
|
|
7
|
+
export declare const checkAmbientModule: (node: AstNode, report: Report) => void;
|
|
@@ -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,28 @@
|
|
|
1
|
+
import { type ContractArtifact, type TablePolicyArtifact } from '@fabrika/auth-core';
|
|
2
|
+
import { type EndpointFixtures } from './endpoint-fixtures';
|
|
3
|
+
import type { Finding } from './finding';
|
|
4
|
+
export { ENDPOINT_ACCESS_TEST, ENDPOINT_FIXTURES_FILE, POLICY_TEST_SUFFIX, POLICY_TESTS_DIR } from './layout';
|
|
5
|
+
export declare const policyTestPath: (table: string) => string;
|
|
6
|
+
/** One generated test file: its full text, header included, and the name of every test case it registers. */
|
|
7
|
+
export interface GeneratedTest {
|
|
8
|
+
readonly text: string;
|
|
9
|
+
readonly cases: readonly string[];
|
|
10
|
+
}
|
|
11
|
+
type Policies = Readonly<Record<string, TablePolicyArtifact>>;
|
|
12
|
+
/**
|
|
13
|
+
* Every test the scaffold writes for these policies and, when the application has a contract, its artifact; by path.
|
|
14
|
+
* Endpoint access tests exist only for an application on `@fabrika/db`, which has policies to seed rows from.
|
|
15
|
+
*/
|
|
16
|
+
export declare const generatedTests: (policies: Policies, artifact: ContractArtifact | null, fixtures?: EndpointFixtures) => Promise<ReadonlyMap<string, GeneratedTest>>;
|
|
17
|
+
export interface ScaffoldInputs {
|
|
18
|
+
readonly policies: Policies;
|
|
19
|
+
readonly artifact: ContractArtifact | null;
|
|
20
|
+
readonly fixtures: EndpointFixtures;
|
|
21
|
+
}
|
|
22
|
+
/** What the scaffold reads from an application's files; throws `ContractSourceError` or `ContractError` as the reader does. */
|
|
23
|
+
export declare const scaffoldInputs: (files: ReadonlyMap<string, string>) => ScaffoldInputs;
|
|
24
|
+
/**
|
|
25
|
+
* What stops the endpoint access tests from covering every endpoint: one whose input the scaffold cannot sample and
|
|
26
|
+
* the author gave no fixture, and a fixture of no tested endpoint. Each is an `endpoint-fixture` finding.
|
|
27
|
+
*/
|
|
28
|
+
export declare const missingEndpointFixtures: ({ 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[];
|