@fabrika/check 0.8.2 → 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.
Files changed (61) hide show
  1. package/package.json +12 -11
  2. package/src/check.ts +23 -6
  3. package/src/dialect.ts +29 -0
  4. package/src/endpoint-fixtures.ts +29 -9
  5. package/src/finding.ts +7 -3
  6. package/src/index.ts +2 -1
  7. package/src/layout.ts +2 -0
  8. package/src/reader/surface.ts +15 -0
  9. package/src/rules/cloudflare.ts +58 -0
  10. package/src/rules/framework.ts +2 -2
  11. package/src/rules/isolation.ts +5 -1
  12. package/src/rules/migrations.ts +31 -0
  13. package/src/rules/modules.ts +1 -1
  14. package/src/scaffold.ts +133 -33
  15. package/types/src/ast.d.ts +65 -0
  16. package/types/src/bun-plugin.d.ts +12 -0
  17. package/types/src/check.d.ts +19 -0
  18. package/types/src/cli.d.ts +2 -0
  19. package/types/src/contract.d.ts +58 -0
  20. package/types/src/dialect.d.ts +8 -0
  21. package/types/src/endpoint-fixtures.d.ts +39 -0
  22. package/types/src/finding.d.ts +39 -0
  23. package/types/src/graph.d.ts +68 -0
  24. package/types/src/index.d.ts +7 -0
  25. package/types/src/inputs.d.ts +9 -0
  26. package/types/src/jsonc.d.ts +2 -0
  27. package/types/src/layout.d.ts +65 -0
  28. package/types/src/limits.d.ts +15 -0
  29. package/types/src/lockfile.d.ts +19 -0
  30. package/types/src/packed.d.ts +15 -0
  31. package/types/src/reader/problems.d.ts +7 -0
  32. package/types/src/reader/schema.d.ts +18 -0
  33. package/types/src/reader/surface.d.ts +5 -0
  34. package/types/src/reader/tables.d.ts +6 -0
  35. package/types/src/reader/value.d.ts +113 -0
  36. package/types/src/references.d.ts +15 -0
  37. package/types/src/resolution.d.ts +20 -0
  38. package/types/src/rules/cloudflare.d.ts +9 -0
  39. package/types/src/rules/contract.d.ts +8 -0
  40. package/types/src/rules/crontab.d.ts +15 -0
  41. package/types/src/rules/framework.d.ts +19 -0
  42. package/types/src/rules/identity.d.ts +5 -0
  43. package/types/src/rules/isolation.d.ts +18 -0
  44. package/types/src/rules/json.d.ts +3 -0
  45. package/types/src/rules/literal.d.ts +63 -0
  46. package/types/src/rules/migrations.d.ts +34 -0
  47. package/types/src/rules/modules.d.ts +12 -0
  48. package/types/src/rules/packages.d.ts +7 -0
  49. package/types/src/rules/runtime.d.ts +32 -0
  50. package/types/src/rules/structure.d.ts +36 -0
  51. package/types/src/rules/tests.d.ts +22 -0
  52. package/types/src/rules/types.d.ts +4 -0
  53. package/types/src/scaffold-sample.d.ts +8 -0
  54. package/types/src/scaffold.d.ts +34 -0
  55. package/types/src/scope.d.ts +6 -0
  56. package/types/src/slice.d.ts +30 -0
  57. package/types/src/source-maps-cli.d.ts +4 -0
  58. package/types/src/source-maps.d.ts +32 -0
  59. package/types/src/toml.d.ts +30 -0
  60. package/types/src/trust.d.ts +15 -0
  61. package/types/src/version.d.ts +2 -0
@@ -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,7 @@
1
+ export { type ApplicationTree, checkApplication, type CheckInput, readApplicationTree } from './check';
2
+ export { type ApplicationDialect, applicationDialect } from './dialect';
3
+ export { type Finding, formatFinding, RULE_IDS, type RuleId } from './finding';
4
+ export { CONFIG_FILE, CONTRACT_FILE, GENERATED_ENTRY_FILE, MIGRATIONS_DIR, TABLES_FILE, ZEROPS_FILES } from './layout';
5
+ export { type PackedSet, type PackedTarball, readPackedSet } from './packed';
6
+ export { GENERATED_TEST_HEADER, generatedTestHeader } from './rules/tests';
7
+ 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,2 @@
1
+ /** The parsed value, or `undefined` when the text is not JSON with comments. */
2
+ export declare function parseJsonc(text: string): unknown;
@@ -0,0 +1,65 @@
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 provider-authored application config, whose `defineApp` names the provider. */
4
+ export declare const CONFIG_FILE = "fabrika.config.ts";
5
+ /** The named export of the contract module that holds `defineContract(…)`. */
6
+ export declare const CONTRACT_EXPORT = "contract";
7
+ export declare const TABLES_FILE = "src/db/tables.ts";
8
+ /** The named export of the tables module that holds `defineTables(…)(…)`. */
9
+ export declare const TABLES_EXPORT = "tables";
10
+ export declare const GENERATED_ENTRY_FILE = "fabrika/entry.generated.ts";
11
+ export declare const MIGRATIONS_DIR = "db/migrations/";
12
+ /** Where `fabrika db test-scaffold` writes the policy isolation tests, `<table>.policy-isolation.test.ts`. */
13
+ export declare const POLICY_TESTS_DIR = "src/db/__tests__/";
14
+ export declare const POLICY_TEST_SUFFIX = ".policy-isolation.test.ts";
15
+ /** The generated endpoint access tests; they import `src/app.ts`, whose default export they boot. */
16
+ export declare const ENDPOINT_ACCESS_TEST = "src/__tests__/endpoint-access.test.ts";
17
+ /** The inputs the author gives the endpoint access tests where the scaffold cannot sample one; read, never run. */
18
+ export declare const ENDPOINT_FIXTURES_FILE = "src/__tests__/endpoint-access.fixtures.ts";
19
+ export declare const ZEROPS_FILES: readonly ["zerops.yaml", "zerops.yml"];
20
+ /** The application architecture (docs/reference/application-architecture.md): where each layer's code lives. */
21
+ export declare const VOCABULARY_FILE = "src/vocabulary.ts";
22
+ export declare const APP_KIT_FILE = "src/app-kit.ts";
23
+ /** The shared zod schemas the shell and the SPA import: one module, or a directory of them once it grows. */
24
+ export declare const SCHEMAS_FILE = "src/schemas.ts";
25
+ export declare const SCHEMAS_DIR = "src/schemas/";
26
+ /** Pure code the SPA and every slice may import: it loads nothing but `zod/v4` and other modules of its own directory. */
27
+ export declare const SHARED_DIR = "src/shared/";
28
+ /** `src/db/`: the tables, the generated schema and their generated tests; never a slice. */
29
+ export declare const DATABASE_DIR = "src/db/";
30
+ /** A slice is a directory `src/<slice>/` that holds these modules, each optional. */
31
+ export declare const SLICE_ENDPOINTS_FILE = "endpoints.ts";
32
+ export declare const SLICE_LOGIC_FILE = "logic.ts";
33
+ export declare const SLICE_QUERIES_FILE = "queries.ts";
34
+ export declare const SPA_DIR = "web/";
35
+ /** The server half of an application: its modules run in the application's process. */
36
+ export declare const SERVER_DIR = "src/";
37
+ /** Build output, installed packages and tool state are not application source and are never read. */
38
+ export declare const isIgnoredSegment: (segment: string) => boolean;
39
+ export declare const isSourceFile: (path: string) => boolean;
40
+ export declare const isTestFile: (path: string) => boolean;
41
+ /** A module that runs in the application's server process: under `src/`, not a test. */
42
+ export declare const isServerModule: (path: string) => boolean;
43
+ export declare const isJsonFile: (path: string) => boolean;
44
+ /** Whether the checker reads this file at all. */
45
+ export declare const isCheckedFile: (path: string) => boolean;
46
+ /** Joins a relative specifier onto the importing file's directory; `undefined` when it climbs above the root. */
47
+ export declare const joinRelative: (fromFile: string, specifier: string) => string | undefined;
48
+ /**
49
+ * How a relative import resolves among the files that exist. Only an exact name, or exactly one extension candidate,
50
+ * is a `file`: with two candidates (`m.ts` and `m.tsx`) or a directory, Bun's choice is not one the checker repeats.
51
+ */
52
+ export type Resolution = {
53
+ readonly kind: 'file';
54
+ readonly path: string;
55
+ } | {
56
+ readonly kind: 'ambiguous';
57
+ readonly paths: readonly string[];
58
+ } | {
59
+ readonly kind: 'directory';
60
+ readonly paths: readonly string[];
61
+ } | {
62
+ readonly kind: 'missing';
63
+ };
64
+ export declare const resolveRelative: (exists: (path: string) => boolean, fromFile: string, specifier: string) => Resolution;
65
+ 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,9 @@
1
+ import type { ContractArtifact } from '@fabrika/auth-core';
2
+ import type { Finding } from '../finding';
3
+ /**
4
+ * What an application on Cloudflare cannot declare (ADR-0065): raw SQL, because a Durable Object's SQLite has no role
5
+ * under it and the classifier reads Postgres's lexical rules; a file kind that scans, because no scanner runs there.
6
+ * And a hint for a mutation that declares an outside call: the object runs one transaction at a time, and the mutation
7
+ * holds it while the call waits (backlog 216 item 7).
8
+ */
9
+ export declare const checkCloudflareContract: (artifact: ContractArtifact) => Finding[];
@@ -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 `openPostgres` 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,3 @@
1
+ import type { Report } from '../finding';
2
+ /** JSON can be imported as a module, so its strings fall under the same credential rule as source literals. */
3
+ export declare const checkJsonStrings: (text: string, report: Report) => void;
@@ -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,34 @@
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
+ /**
5
+ * On SQLite `DEFAULT CURRENT_TIMESTAMP` stores `YYYY-MM-DD HH:MM:SS`, which every read of the table refuses as
6
+ * `unexpected_row` (backlog 216 item 13). Refused with or without parentheses, at the line of `CURRENT_TIMESTAMP`.
7
+ */
8
+ export declare const checkCurrentTimestampDefaults: (files: ReadonlyMap<string, string>) => Finding[];
9
+ /** A declared file column: `table.column` holds files of `kind`. */
10
+ export interface FileColumn {
11
+ readonly table: string;
12
+ readonly column: string;
13
+ readonly kind: string;
14
+ }
15
+ /**
16
+ * Every declared file column needs a foreign key to `fabrika_files (id)`, which keeps the sweep from deleting a file a
17
+ * row references, and an index it leads, which the sweep's reference check and each file deletion read. Only what a
18
+ * migration creates counts: a `REFERENCES fabrika_files` on the column or a one-column foreign key, and a `CREATE
19
+ * INDEX` without `WHERE`, a `UNIQUE` or a `PRIMARY KEY` whose first column it is, minus a later `DROP INDEX`.
20
+ */
21
+ export declare const checkFileColumnMigrations: (files: ReadonlyMap<string, string>, columns: readonly FileColumn[]) => Finding[];
22
+ /** An `insert(values, { onConflict: { columns } })` the source makes, with the finding it gets when no index fits. */
23
+ export interface ConflictInsert {
24
+ readonly table: string;
25
+ readonly columns: readonly string[];
26
+ readonly finding: Finding;
27
+ }
28
+ /**
29
+ * `onConflict.columns` must name a unique index the migrations create, or Postgres refuses the insert at run time: the
30
+ * set of columns of a `UNIQUE` or `PRIMARY KEY` constraint, or of a `CREATE UNIQUE INDEX` without `WHERE` or expression,
31
+ * minus a later `DROP INDEX`. Order does not matter, as for Postgres. Only a table `src/db/tables.ts` declares is
32
+ * checked: another receiver of `insert` is no table of the data layer.
33
+ */
34
+ 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;