@fabrika/check 0.9.0-dev.1 → 0.9.0-dev.11

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 (74) hide show
  1. package/package.json +12 -11
  2. package/src/check.ts +58 -9
  3. package/src/cli.ts +23 -4
  4. package/src/dialect.ts +29 -0
  5. package/src/endpoint-fixtures.ts +99 -13
  6. package/src/finding.ts +12 -3
  7. package/src/index.ts +4 -1
  8. package/src/layout.ts +16 -1
  9. package/src/migration-base.ts +85 -0
  10. package/src/reader/surface.ts +15 -0
  11. package/src/reader/value.ts +1 -1
  12. package/src/resolution.ts +2 -2
  13. package/src/rules/cloudflare.ts +59 -0
  14. package/src/rules/framework.ts +2 -2
  15. package/src/rules/isolation.ts +5 -1
  16. package/src/rules/migration-history.ts +70 -0
  17. package/src/rules/migrations.ts +63 -0
  18. package/src/rules/modules.ts +3 -3
  19. package/src/rules/platform-migrations.ts +93 -0
  20. package/src/rules/runtime.ts +13 -7
  21. package/src/rules/structure.ts +26 -1
  22. package/src/rules/tests.ts +1 -1
  23. package/src/scaffold.ts +398 -71
  24. package/src/trust.ts +8 -4
  25. package/types/src/ast.d.ts +65 -0
  26. package/types/src/bun-plugin.d.ts +12 -0
  27. package/types/src/check.d.ts +22 -0
  28. package/types/src/cli.d.ts +2 -0
  29. package/types/src/contract.d.ts +58 -0
  30. package/types/src/dialect.d.ts +8 -0
  31. package/types/src/endpoint-fixtures.d.ts +54 -0
  32. package/types/src/finding.d.ts +39 -0
  33. package/types/src/graph.d.ts +68 -0
  34. package/types/src/index.d.ts +9 -0
  35. package/types/src/inputs.d.ts +9 -0
  36. package/types/src/jsonc.d.ts +2 -0
  37. package/types/src/layout.d.ts +76 -0
  38. package/types/src/limits.d.ts +15 -0
  39. package/types/src/lockfile.d.ts +19 -0
  40. package/types/src/migration-base.d.ts +9 -0
  41. package/types/src/packed.d.ts +15 -0
  42. package/types/src/reader/problems.d.ts +7 -0
  43. package/types/src/reader/schema.d.ts +18 -0
  44. package/types/src/reader/surface.d.ts +5 -0
  45. package/types/src/reader/tables.d.ts +6 -0
  46. package/types/src/reader/value.d.ts +113 -0
  47. package/types/src/references.d.ts +15 -0
  48. package/types/src/resolution.d.ts +20 -0
  49. package/types/src/rules/cloudflare.d.ts +9 -0
  50. package/types/src/rules/contract.d.ts +8 -0
  51. package/types/src/rules/crontab.d.ts +15 -0
  52. package/types/src/rules/framework.d.ts +19 -0
  53. package/types/src/rules/identity.d.ts +5 -0
  54. package/types/src/rules/isolation.d.ts +18 -0
  55. package/types/src/rules/json.d.ts +3 -0
  56. package/types/src/rules/literal.d.ts +63 -0
  57. package/types/src/rules/migration-history.d.ts +12 -0
  58. package/types/src/rules/migrations.d.ts +40 -0
  59. package/types/src/rules/modules.d.ts +12 -0
  60. package/types/src/rules/packages.d.ts +7 -0
  61. package/types/src/rules/platform-migrations.d.ts +13 -0
  62. package/types/src/rules/runtime.d.ts +34 -0
  63. package/types/src/rules/structure.d.ts +41 -0
  64. package/types/src/rules/tests.d.ts +22 -0
  65. package/types/src/rules/types.d.ts +4 -0
  66. package/types/src/scaffold-sample.d.ts +8 -0
  67. package/types/src/scaffold.d.ts +36 -0
  68. package/types/src/scope.d.ts +6 -0
  69. package/types/src/slice.d.ts +30 -0
  70. package/types/src/source-maps-cli.d.ts +4 -0
  71. package/types/src/source-maps.d.ts +32 -0
  72. package/types/src/toml.d.ts +30 -0
  73. package/types/src/trust.d.ts +15 -0
  74. package/types/src/version.d.ts +2 -0
@@ -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): a file kind that scans, because no scanner runs there; a
5
+ * job longer than one segment, because the object runs it inside an alarm or a request. And a hint for a mutation that
6
+ * declares an outside call: the object runs one transaction at a time, and the mutation holds it while the call waits
7
+ * (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,12 @@
1
+ import type { Finding } from '../finding';
2
+ /** The migrations of `db/migrations` at the commit the tree is compared with, by path relative to the root. */
3
+ export interface MigrationBase {
4
+ /** How the commit is named to the author, such as `origin/main`. */
5
+ readonly ref: string;
6
+ readonly files: ReadonlyMap<string, string>;
7
+ }
8
+ /**
9
+ * Each migration of `base` that the tree changed (at its first changed line) or no longer holds. A file renamed is one
10
+ * removed and one new, and the new one would run again where the old one ran, so the removal is what is reported.
11
+ */
12
+ export declare const checkMigrationHistory: (files: ReadonlyMap<string, string>, base: MigrationBase) => Finding[];
@@ -0,0 +1,40 @@
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
+ /**
10
+ * On SQLite an application migration runs verbatim, with no name rule, so a view or a trigger over a framework table
11
+ * would reach what `ctx.sql`'s name rule keeps it from. Every `fabrika_*` name is refused (any case, quoted, bracketed,
12
+ * or as a string SQLite may read as a name) but `fabrika_files` right after `REFERENCES`, a file column's foreign key.
13
+ */
14
+ export declare const checkSqliteFrameworkNames: (files: ReadonlyMap<string, string>) => Finding[];
15
+ /** A declared file column: `table.column` holds files of `kind`. */
16
+ export interface FileColumn {
17
+ readonly table: string;
18
+ readonly column: string;
19
+ readonly kind: string;
20
+ }
21
+ /**
22
+ * Every declared file column needs a foreign key to `fabrika_files (id)`, which keeps the sweep from deleting a file a
23
+ * row references, and an index it leads, which the sweep's reference check and each file deletion read. Only what a
24
+ * migration creates counts: a `REFERENCES fabrika_files` on the column or a one-column foreign key, and a `CREATE
25
+ * INDEX` without `WHERE`, a `UNIQUE` or a `PRIMARY KEY` whose first column it is, minus a later `DROP INDEX`.
26
+ */
27
+ export declare const checkFileColumnMigrations: (files: ReadonlyMap<string, string>, columns: readonly FileColumn[]) => Finding[];
28
+ /** An `insert(values, { onConflict: { columns } })` the source makes, with the finding it gets when no index fits. */
29
+ export interface ConflictInsert {
30
+ readonly table: string;
31
+ readonly columns: readonly string[];
32
+ readonly finding: Finding;
33
+ }
34
+ /**
35
+ * `onConflict.columns` must name a unique index the migrations create, or Postgres refuses the insert at run time: the
36
+ * set of columns of a `UNIQUE` or `PRIMARY KEY` constraint, or of a `CREATE UNIQUE INDEX` without `WHERE` or expression,
37
+ * minus a later `DROP INDEX`. Order does not matter, as for Postgres. Only a table `src/db/tables.ts` declares is
38
+ * checked: another receiver of `insert` is no table of the data layer.
39
+ */
40
+ 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,13 @@
1
+ import type { Finding } from '../finding';
2
+ /**
3
+ * Every statement Control's classifier refuses, at its file and line. Control refuses a deploy whose new migration holds
4
+ * one (`migrations-refused`), and its run log names neither, so this is where the author finds it. Every file is
5
+ * checked, applied or not: the checker does not know which an environment holds.
6
+ */
7
+ export declare const checkMigrationClassification: (files: ReadonlyMap<string, string>, appId: string) => Finding[];
8
+ /**
9
+ * On Cloudflare, the backup's refusal of the migrated schema (`planOpsDump`), at the newest migration that names the
10
+ * table. Every migration deploy backs the environment up first, so a schema the backup refuses blocks every migration
11
+ * after the one that made it. A migration set that does not apply is codegen's to report, so it finds nothing here.
12
+ */
13
+ export declare const checkBackupPlan: (files: ReadonlyMap<string, string>) => Promise<Finding[]>;
@@ -0,0 +1,34 @@
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
+ /** `key-literal` over a string or a template's text: also the one rule of this module a developer's tool is held to. */
32
+ export declare const checkKeyLiteralNode: (node: AstNode, report: Report) => void;
33
+ /** The rules that read one node at a time, for every source file. */
34
+ export declare const checkRuntimeNode: (node: AstNode, ancestors: readonly AstNode[], context: SourceContext) => void;
@@ -0,0 +1,41 @@
1
+ import { type AstNode } from '../ast';
2
+ import { type Finding, 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
+ /**
24
+ * A `package.json` under `tools/` makes a tool a package, which a workspace or a `file:` dependency lets the application
25
+ * load by its name, past `tool-import`, which judges the files an import resolves to.
26
+ */
27
+ export declare const checkToolPackages: (paths: readonly string[]) => Finding[];
28
+ /** The architecture's rules over one module's imports, re-exports and loads, as Bun resolves them for that module. */
29
+ export declare const checkStructureReferences: (graph: StructureGraph, place: StructurePlace, report: Report) => void;
30
+ /** A `<x>.<builder>(…).handle(…)` call: the builder's name, its call (whose arguments hold the options) and `.handle`. */
31
+ export interface HandledProcedure {
32
+ readonly builder: string;
33
+ readonly procedure: AstNode;
34
+ /** The `handle` property node, where a finding points. */
35
+ readonly handle: AstNode;
36
+ }
37
+ /** The procedure `node` hands a handler to, when `node` is `<x>.<builder>(…).handle(…)`. */
38
+ export declare const handledProcedure: (node: AstNode) => HandledProcedure | undefined;
39
+ /** The architecture's hints at one node: a handler outside `endpoints.ts`, data access outside `endpoints.ts`/`queries.ts`. */
40
+ export declare const checkStructureNode: (place: StructurePlace, node: AstNode, report: Report) => void;
41
+ 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,4 @@
1
+ import { type AstNode, type Comment } from '../ast';
2
+ import type { Report } from '../finding';
3
+ export declare const checkTypeNode: (node: AstNode, report: Report) => void;
4
+ export declare const checkComments: (comments: readonly Comment[], 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,36 @@
1
+ import { type ContractArtifact, type TablePolicyArtifact } from '@fabrika/auth-core';
2
+ import { type Tables } from '@fabrika/db/tables';
3
+ import { type ApplicationDialect } from './dialect';
4
+ import { type EndpointFixtures } from './endpoint-fixtures';
5
+ import type { Finding } from './finding';
6
+ export { ENDPOINT_ACCESS_TEST, ENDPOINT_FIXTURES_FILE, POLICY_TEST_SUFFIX, POLICY_TESTS_DIR } from './layout';
7
+ export declare const policyTestPath: (table: string) => string;
8
+ /** One generated test file: its full text, header included, and the name of every test case it registers. */
9
+ export interface GeneratedTest {
10
+ readonly text: string;
11
+ readonly cases: readonly string[];
12
+ /** What the test cannot check, one line each, which `fabrika db test-scaffold` prints: a ruled-out capability case. */
13
+ readonly notes: readonly string[];
14
+ }
15
+ type Policies = Readonly<Record<string, TablePolicyArtifact>>;
16
+ /**
17
+ * Every test the scaffold writes for these policies and, when the application has a contract, its artifact; by path.
18
+ * Endpoint access tests exist only for an application on `@fabrika/db`, which has policies to seed rows from. They
19
+ * open the test database of the application's dialect.
20
+ */
21
+ export declare const generatedTests: (policies: Policies, artifact: ContractArtifact | null, fixtures?: EndpointFixtures, dialect?: ApplicationDialect) => Promise<ReadonlyMap<string, GeneratedTest>>;
22
+ export interface ScaffoldInputs {
23
+ /** What `src/db/tables.ts` defines, its column list included; `null` without the file. */
24
+ readonly tables: Tables<unknown, unknown> | null;
25
+ readonly policies: Policies;
26
+ readonly artifact: ContractArtifact | null;
27
+ readonly fixtures: EndpointFixtures;
28
+ readonly dialect: ApplicationDialect;
29
+ }
30
+ /** What the scaffold reads from an application's files; throws `ContractSourceError` or `ContractError` as the reader does. */
31
+ export declare const scaffoldInputs: (files: ReadonlyMap<string, string>) => ScaffoldInputs;
32
+ /**
33
+ * What stops the endpoint access tests from covering every endpoint: one whose input the scaffold cannot sample and
34
+ * the author gave no fixture, and a fixture of no tested endpoint. Each is an `endpoint-fixture` finding.
35
+ */
36
+ export declare const missingEndpointFixtures: ({ tables, policies, artifact, fixtures }: ScaffoldInputs) => readonly Finding[];
@@ -0,0 +1,6 @@
1
+ import { type AstNode } from './ast';
2
+ /**
3
+ * The scope whose declaration `name` denotes at a node with these ancestors: the innermost one that declares it, or
4
+ * `undefined` for a global. A module's imports and top-level declarations belong to its `Program`.
5
+ */
6
+ export declare const declaringScope: (name: string, ancestors: readonly AstNode[]) => AstNode | undefined;
@@ -0,0 +1,30 @@
1
+ import { type AstNode, type ParsedModule, type ParseResult } from './ast';
2
+ import type { Finding } from './finding';
3
+ /** A `.handle(…)` the slice cannot keep out of the shell, at its `handle`; the reader and the SPA build refuse it. */
4
+ export interface SliceRefusal {
5
+ readonly node: AstNode;
6
+ readonly message: string;
7
+ readonly allowed: string;
8
+ }
9
+ /** A module's slice, and the `.handle(…)` forms it refused. */
10
+ export interface ShellSlice {
11
+ readonly text: string;
12
+ readonly refusals: readonly SliceRefusal[];
13
+ }
14
+ /**
15
+ * The slice of one parsed module: `module`'s text with every `.handle(…)` and everything only the handlers used
16
+ * blanked. A module without a handler comes back unchanged.
17
+ */
18
+ export declare function moduleSlice(module: ParsedModule, text: string): ShellSlice;
19
+ /**
20
+ * The slice of a module's text. Text that does not parse comes back unchanged, so the reader reports the parse error
21
+ * where it is.
22
+ */
23
+ export declare function shellSlice(file: string, text: string): ShellSlice;
24
+ /** A refused `.handle(…)` as the finding the reader, the checker and the SPA build report. */
25
+ export declare function sliceFinding(module: ParsedModule, refusal: SliceRefusal): Finding;
26
+ /** A module parsed as its slice, what the reader and input discovery read, with the `.handle(…)` forms it refused. */
27
+ export declare function parseShellModule(file: string, text: string): {
28
+ readonly parsed: ParseResult;
29
+ readonly refusals: readonly Finding[];
30
+ };
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env bun
2
+ import { type ArtifactFetch, type SourceMapUploadResult } from './source-maps';
3
+ /** Collect and upload; every failure is an incomplete result, and nothing it prints carries the bearer. */
4
+ export declare function runSourceMapUpload(root: string, environment: Readonly<Record<string, string | undefined>>, fetch: ArtifactFetch): Promise<SourceMapUploadResult>;
@@ -0,0 +1,32 @@
1
+ import { type OperationsArtifactUploadConfiguration, type OperationsAssetRoot, type OperationsSourceMapUploadState } from '@fabrika/operations-contract/releases';
2
+ /** Operations' own limits (`artifact-upload.ts`): a larger map or one past the run's budget is refused there. */
3
+ export declare const MAX_SOURCE_MAP_BYTES: number;
4
+ export declare const MAX_SOURCE_MAPS = 256;
5
+ export declare const MAX_SOURCE_MAP_TOTAL_BYTES: number;
6
+ export interface SourceMapArtifact {
7
+ logicalPath: string;
8
+ digest: string;
9
+ body: ArrayBuffer;
10
+ }
11
+ export interface SourceMapCollection {
12
+ artifacts: SourceMapArtifact[];
13
+ /** A map was skipped: over a limit, or without a logical path. */
14
+ incomplete: boolean;
15
+ }
16
+ export type ArtifactFetch = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
17
+ export interface SourceMapUploadResult {
18
+ uploaded: number;
19
+ state: OperationsSourceMapUploadState;
20
+ }
21
+ /** Every `*.map` of a checkout, at the logical path its own `file` field names (the Cloudflare runner). */
22
+ export declare function collectSourceMaps(cwd: string): Promise<SourceMapCollection>;
23
+ /**
24
+ * Every `*.map` under each asset root, at the URL path of the file it maps: `<prefix>/<path under dir>` without its
25
+ * `.map`, as the browser names that file in a stack frame. A root outside `root` is skipped as incomplete.
26
+ */
27
+ export declare function collectAssetSourceMaps(root: string, assetRoots: readonly OperationsAssetRoot[]): Promise<SourceMapCollection>;
28
+ /**
29
+ * Upload each map with the run's bearer. A refused or failed upload leaves the state incomplete and never throws, so a
30
+ * deploy succeeds without its maps; nothing about the request, the bearer included, is printed.
31
+ */
32
+ export declare function uploadSourceMaps(destination: OperationsArtifactUploadConfiguration, collection: SourceMapCollection, fetch: ArtifactFetch): Promise<SourceMapUploadResult>;