@fabrika/check 0.9.0-dev.3 → 0.9.0-dev.31

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 (75) hide show
  1. package/package.json +12 -7
  2. package/src/ast.ts +69 -18
  3. package/src/bun-plugin.ts +4 -27
  4. package/src/check.ts +157 -44
  5. package/src/cli.ts +34 -8
  6. package/src/contract.ts +68 -11
  7. package/src/dialect.ts +29 -0
  8. package/src/finding.ts +21 -8
  9. package/src/graph.ts +49 -12
  10. package/src/index.ts +4 -12
  11. package/src/inputs.ts +5 -2
  12. package/src/layout.ts +41 -12
  13. package/src/limits.ts +15 -5
  14. package/src/migration-base.ts +85 -0
  15. package/src/reader/schema.ts +42 -512
  16. package/src/reader/surface.ts +48 -7
  17. package/src/reader/value.ts +41 -8
  18. package/src/references.ts +16 -1
  19. package/src/resolution.ts +2 -2
  20. package/src/rules/cloudflare.ts +59 -0
  21. package/src/rules/compile.ts +32 -0
  22. package/src/rules/contract.ts +3 -2
  23. package/src/rules/framework.ts +2 -2
  24. package/src/rules/identity.ts +6 -9
  25. package/src/rules/literal.ts +42 -9
  26. package/src/rules/migration-history.ts +70 -0
  27. package/src/rules/migrations.ts +248 -9
  28. package/src/rules/modules.ts +9 -3
  29. package/src/rules/platform-migrations.ts +100 -0
  30. package/src/rules/runtime.ts +45 -14
  31. package/src/rules/structure.ts +172 -19
  32. package/src/rules/tests.ts +9 -60
  33. package/src/rules/types.ts +17 -16
  34. package/src/shell-modules.ts +53 -0
  35. package/src/slice.ts +6 -5
  36. package/src/source-maps.ts +2 -0
  37. package/src/trust.ts +8 -4
  38. package/src/vite-plugin.ts +65 -0
  39. package/types/src/ast.d.ts +6 -2
  40. package/types/src/check.d.ts +3 -0
  41. package/types/src/contract.d.ts +13 -1
  42. package/types/src/dialect.d.ts +8 -0
  43. package/types/src/finding.d.ts +7 -6
  44. package/types/src/graph.d.ts +12 -2
  45. package/types/src/index.d.ts +4 -3
  46. package/types/src/layout.d.ts +25 -10
  47. package/types/src/limits.d.ts +14 -4
  48. package/types/src/migration-base.d.ts +9 -0
  49. package/types/src/reader/schema.d.ts +5 -2
  50. package/types/src/reader/value.d.ts +3 -3
  51. package/types/src/references.d.ts +6 -1
  52. package/types/src/rules/cloudflare.d.ts +9 -0
  53. package/types/src/rules/compile.d.ts +7 -0
  54. package/types/src/rules/framework.d.ts +1 -1
  55. package/types/src/rules/literal.d.ts +1 -1
  56. package/types/src/rules/migration-history.d.ts +12 -0
  57. package/types/src/rules/migrations.d.ts +28 -0
  58. package/types/src/rules/platform-migrations.d.ts +15 -0
  59. package/types/src/rules/runtime.d.ts +7 -2
  60. package/types/src/rules/structure.d.ts +18 -4
  61. package/types/src/rules/tests.d.ts +6 -14
  62. package/types/src/rules/types.d.ts +2 -0
  63. package/types/src/shell-modules.d.ts +7 -0
  64. package/types/src/slice.d.ts +8 -2
  65. package/types/src/vite-plugin.d.ts +27 -0
  66. package/src/endpoint-fixtures.ts +0 -221
  67. package/src/rules/crontab.ts +0 -147
  68. package/src/rules/isolation.ts +0 -79
  69. package/src/scaffold-sample.ts +0 -111
  70. package/src/scaffold.ts +0 -650
  71. package/types/src/endpoint-fixtures.d.ts +0 -36
  72. package/types/src/rules/crontab.d.ts +0 -15
  73. package/types/src/rules/isolation.d.ts +0 -18
  74. package/types/src/scaffold-sample.d.ts +0 -8
  75. package/types/src/scaffold.d.ts +0 -28
@@ -54,12 +54,16 @@ export declare const unwrap: (node: AstNode) => AstNode;
54
54
  export declare const memberPath: (node: AstNode) => readonly string[] | undefined;
55
55
  /** Whether an `Identifier` denotes a runtime value here, rather than a property name, a key, a label or a type. */
56
56
  export declare const isValueReference: (node: AstNode, parent: AstNode | undefined) => boolean;
57
+ /**
58
+ * A node's line and column (from 1), as the parser counts them, for a tree `parseModule` returns: its `loc` is the
59
+ * start of its line (`lineLocations`). A tree parsed any other way has no such `loc` and reads as 1:1.
60
+ */
57
61
  export declare const positionOf: (node: AstNode) => Position;
58
62
  /** Visits every node below `root`, depth first, with the chain of its ancestors (nearest last); `'skip'` prunes a subtree. */
59
63
  export declare const walk: (root: AstNode, visit: (node: AstNode, ancestors: readonly AstNode[]) => "skip" | undefined | void) => void;
60
64
  export declare const utf8Bytes: (text: string) => number;
61
65
  /** The nesting depth of the tree below `root`, measured without recursion, so a deep tree cannot exhaust the stack. */
62
66
  export declare const nodeDepth: (root: AstNode) => number;
67
+ /** The number of syntax nodes in the tree below `root`, `root` included, counted without recursion. */
68
+ export declare const nodeCount: (root: AstNode) => number;
63
69
  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[];
@@ -1,5 +1,6 @@
1
1
  import { type Finding } from './finding';
2
2
  import type { PackedSet } from './packed';
3
+ import { type MigrationBase } from './rules/migration-history';
3
4
  export interface CheckInput {
4
5
  /** The application's root directory. */
5
6
  readonly root: string;
@@ -7,6 +8,8 @@ export interface CheckInput {
7
8
  readonly files?: ReadonlyMap<string, string>;
8
9
  /** A local pack whose tarballs `package-replacement` accepts (`fabrika-check --packed`); a deploy build gives none. */
9
10
  readonly packed?: PackedSet;
11
+ /** The migrations of a shared branch the tree must still hold unchanged (`fabrika-check`, from git); a deploy build gives none. */
12
+ readonly migrationBase?: MigrationBase;
10
13
  }
11
14
  export interface ApplicationTree {
12
15
  readonly files: ReadonlyMap<string, string>;
@@ -4,7 +4,9 @@ import { type TablePolicies, type Tables } from '@fabrika/db/tables';
4
4
  import { type ParsedModule } from './ast';
5
5
  import { type Finding } from './finding';
6
6
  import { ModuleGraph } from './graph';
7
+ import { type Range } from './slice';
7
8
  export { ContractError } from '@fabrika/app/contract';
9
+ export { accessTables } from '@fabrika/db/tables';
8
10
  export { type Finding, formatFinding } from './finding';
9
11
  export { contractReaderInputs } from './inputs';
10
12
  export { CONTRACT_FILE, MIGRATIONS_DIR, TABLES_FILE } from './layout';
@@ -38,6 +40,16 @@ export declare function readTablesSource(files: ReadonlyMap<string, string>): Ta
38
40
  * `src/db/schema.generated.ts`) and the configuration `readContract` names. Throws `ContractSourceError`.
39
41
  */
40
42
  export declare function readTablesDefinition(files: ReadonlyMap<string, string>): Tables<unknown, unknown> | null;
43
+ /** The policies `readTablesDefinition` reads, and where the `defineTables(…)(…)` call that declares them stands. */
44
+ export interface TablesDeclaration {
45
+ readonly tables: Tables<unknown, unknown>;
46
+ /** The module of the call: `src/db/tables.ts`, or the module it re-exports `tables` from. */
47
+ readonly file: string;
48
+ /** The call's offsets in that module's text, the same in its shell slice. */
49
+ readonly call: Range;
50
+ }
51
+ /** `readTablesDefinition` with the place of the call; `null` when `files` has no `src/db/tables.ts`. */
52
+ export declare function readTablesDeclaration(files: ReadonlyMap<string, string>): TablesDeclaration | null;
41
53
  /**
42
54
  * The contract `defineContract` returns in the evaluated module, read from source; throws `ContractSourceError`.
43
55
  * Besides the contract's modules, `files` carries every `package.json`, `tsconfig.json`, `jsconfig.json` and
@@ -54,5 +66,5 @@ export type ContractRead = {
54
66
  };
55
67
  /** Reads the `contract` export of a graph whose contract modules already pass the literal rule. */
56
68
  export declare function readContractModule(graph: ModuleGraph): ContractRead;
57
- /** The contract module and every module its value imports reach. */
69
+ /** The contract module and every module its value imports and re-exports reach. */
58
70
  export declare function contractModules(graph: ModuleGraph, entry: ParsedModule): ParsedModule[];
@@ -0,0 +1,8 @@
1
+ /** The database an application's data layer runs on: SQLite in its Durable Object on Cloudflare (ADR-0065), else Postgres. */
2
+ export type ApplicationDialect = 'postgres' | 'sqlite';
3
+ /**
4
+ * Read statically from `fabrika.config.ts`: SQLite when its default export is a call of the `defineApp` that
5
+ * `@fabrika/provider-cloudflare` exports, the config every Cloudflare application writes. Postgres otherwise,
6
+ * including without a config or when the call's origin is not static.
7
+ */
8
+ export declare const applicationDialect: (files: ReadonlyMap<string, string>) => ApplicationDialect;
@@ -1,14 +1,15 @@
1
1
  import type { AstNode, Position } from './ast';
2
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"];
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", "access-view-key", "key-literal", "client-identity", "sensitive-log", "unsafe-html", "dynamic-code", "migration-name", "migration-refused", "backup-schema", "migration-edited", "file-column-migration", "package-replacement", "skipped-test", "test-without-assertion", "mock-module", "spa-server-import", "layer-import", "shared-import", "tool-import", "cloudflare-scan", "cloudflare-job-segment", "cloudflare-current-timestamp", "cloudflare-framework-name", "cloudflare-view-trigger"];
4
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"];
5
+ export declare const STRUCTURE_HINT_RULE_IDS: readonly ["logic-data-access", "cross-slice-queries", "single-slice-queries", "handler-location", "data-access-location"];
6
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.
7
+ * Rules whose findings never fail the check: the architecture's, a `ctx.sql` its site does not declare, a
8
+ * `{ member: true }` endpoint of a contract whose external role admits people from outside the organization, and a
9
+ * Cloudflare mutation that waits for an outside call inside the object's transaction.
9
10
  */
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"];
11
+ export declare const HINT_RULE_IDS: readonly ["logic-data-access", "cross-slice-queries", "single-slice-queries", "handler-location", "data-access-location", "sql-undeclared", "member-admits-external", "cloudflare-held-call"];
12
+ 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", "access-view-key", "key-literal", "client-identity", "sensitive-log", "unsafe-html", "dynamic-code", "migration-name", "migration-refused", "backup-schema", "migration-edited", "file-column-migration", "package-replacement", "skipped-test", "test-without-assertion", "mock-module", "spa-server-import", "layer-import", "shared-import", "tool-import", "cloudflare-scan", "cloudflare-job-segment", "cloudflare-current-timestamp", "cloudflare-framework-name", "cloudflare-view-trigger", "logic-data-access", "cross-slice-queries", "single-slice-queries", "handler-location", "data-access-location", "sql-undeclared", "member-admits-external", "cloudflare-held-call"];
12
13
  export type RefusalRuleId = (typeof REFUSAL_RULE_IDS)[number];
13
14
  export type HintRuleId = (typeof HINT_RULE_IDS)[number];
14
15
  export type RuleId = (typeof RULE_IDS)[number];
@@ -41,6 +41,8 @@ interface ModuleIndex {
41
41
  readonly imports: ReadonlyMap<string, ImportBinding>;
42
42
  /** Exported name → the local name it exports, or the default export's expression. */
43
43
  readonly exports: ReadonlyMap<string, string | AstNode>;
44
+ /** `export { x as y } from './m'`: the exported name (`local`) → the module and the name it takes from it. */
45
+ readonly reexports: ReadonlyMap<string, ImportBinding>;
44
46
  }
45
47
  /** Erased wrappers: `x satisfies T`, `x as const`, parentheses. */
46
48
  export declare const unwrapValue: (node: AstNode) => AstNode;
@@ -52,6 +54,8 @@ export declare class ModuleGraph {
52
54
  index(module: ParsedModule): ModuleIndex;
53
55
  /** How a relative specifier resolves among the checked modules. */
54
56
  resolution(from: string, specifier: string): Resolution;
57
+ /** What a module loads by name: its value imports and its re-exports. */
58
+ links(module: ParsedModule): readonly ImportBinding[];
55
59
  /** The checked module a relative specifier names; none when two candidates compete, the index of a directory import. */
56
60
  resolve(from: string, specifier: string): ParsedModule | undefined;
57
61
  /** What `name` denotes in `module`; an import is followed to the exporting module's declaration. */
@@ -63,6 +67,12 @@ export declare class ModuleGraph {
63
67
  /** The fixed string a value resolves to. */
64
68
  resolveString(located: Located): string | undefined;
65
69
  }
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;
70
+ /**
71
+ * The entries of an object literal by key, in the order the object holds them, as evaluating it would build them: a
72
+ * spread of a value that resolves to an object literal contributes its entries, and a later key overrides an earlier
73
+ * one. A computed key, a method and a spread of anything else are not followed.
74
+ */
75
+ export declare const objectEntries: (graph: ModuleGraph, located: Located, depth?: number) => ReadonlyMap<string, Located>;
76
+ /** The value of `key` in an object literal, read statically through `objectEntries`. */
77
+ export declare const propertyValue: (graph: ModuleGraph, located: Located, key: string) => Located | undefined;
68
78
  export {};
@@ -1,6 +1,7 @@
1
1
  export { type ApplicationTree, checkApplication, type CheckInput, readApplicationTree } from './check';
2
+ export { type ApplicationDialect, applicationDialect } from './dialect';
2
3
  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 { CONFIG_FILE, CONTRACT_FILE, GENERATED_ENTRY_FILE, MIGRATIONS_DIR, TABLES_FILE } from './layout';
5
+ export { readMigrationBase } from './migration-base';
4
6
  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';
7
+ export type { MigrationBase } from './rules/migration-history';
@@ -1,29 +1,29 @@
1
+ import { type ParsedModule } from './ast';
1
2
  /** Where an application keeps what the checker reads. Paths are relative to the application root. */
2
3
  export declare const CONTRACT_FILE = "fabrika.contract.ts";
4
+ /** The provider-authored application config, whose `defineApp` names the provider. */
5
+ export declare const CONFIG_FILE = "fabrika.config.ts";
3
6
  /** The named export of the contract module that holds `defineContract(…)`. */
4
7
  export declare const CONTRACT_EXPORT = "contract";
5
8
  export declare const TABLES_FILE = "src/db/tables.ts";
6
9
  /** The named export of the tables module that holds `defineTables(…)(…)`. */
7
10
  export declare const TABLES_EXPORT = "tables";
8
11
  export declare const GENERATED_ENTRY_FILE = "fabrika/entry.generated.ts";
12
+ /** Where a Cloudflare deploy stages the SPA mounts' built files (`@fabrika/provider-cloudflare`): build output, never source. */
13
+ export declare const STAGED_ASSETS_DIR = "fabrika/assets/";
9
14
  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
15
  /** The application architecture (docs/reference/application-architecture.md): where each layer's code lives. */
19
16
  export declare const VOCABULARY_FILE = "src/vocabulary.ts";
20
17
  export declare const APP_KIT_FILE = "src/app-kit.ts";
21
18
  /** The shared zod schemas the shell and the SPA import: one module, or a directory of them once it grows. */
22
19
  export declare const SCHEMAS_FILE = "src/schemas.ts";
23
20
  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. */
21
+ /**
22
+ * Pure code the SPA and every slice may import: it loads nothing but `zod/v4`, `@fabrika/app/schema` and other modules of
23
+ * its own directory.
24
+ */
25
25
  export declare const SHARED_DIR = "src/shared/";
26
- /** `src/db/`: the tables, the generated schema and their generated tests; never a slice. */
26
+ /** `src/db/`: the tables and the generated schema; never a slice. */
27
27
  export declare const DATABASE_DIR = "src/db/";
28
28
  /** A slice is a directory `src/<slice>/` that holds these modules, each optional. */
29
29
  export declare const SLICE_ENDPOINTS_FILE = "endpoints.ts";
@@ -32,13 +32,28 @@ export declare const SLICE_QUERIES_FILE = "queries.ts";
32
32
  export declare const SPA_DIR = "web/";
33
33
  /** The server half of an application: its modules run in the application's process. */
34
34
  export declare const SERVER_DIR = "src/";
35
+ /**
36
+ * A developer's tools, such as a command line over the contract: code that runs on a developer's machine and never in
37
+ * the application, so the rules for code that runs there do not apply, and no module outside it may load one.
38
+ */
39
+ export declare const TOOLS_DIR = "tools/";
35
40
  /** Build output, installed packages and tool state are not application source and are never read. */
36
41
  export declare const isIgnoredSegment: (segment: string) => boolean;
42
+ /** Whether the checker skips `path` (relative to the root): under a skipped segment, or the staged SPA files. */
43
+ export declare const isSkippedPath: (path: string) => boolean;
37
44
  export declare const isSourceFile: (path: string) => boolean;
38
45
  export declare const isTestFile: (path: string) => boolean;
39
46
  /** A module that runs in the application's server process: under `src/`, not a test. */
40
47
  export declare const isServerModule: (path: string) => boolean;
48
+ /** A module under `tools/`, tests included. */
49
+ export declare const isToolModule: (path: string) => boolean;
41
50
  export declare const isJsonFile: (path: string) => boolean;
51
+ /**
52
+ * A module a generator writes: named `<name>.gen.<ext>` or `<name>.generated.<ext>`, opening with a comment on its first
53
+ * line, before any statement, that says so (`@generated` or `auto-generated`, in any case). The rules about how source
54
+ * is written do not apply to it; every rule about what it does still does.
55
+ */
56
+ export declare const isGeneratedModule: (path: string, module: Pick<ParsedModule, "program" | "comments">) => boolean;
42
57
  /** Whether the checker reads this file at all. */
43
58
  export declare const isCheckedFile: (path: string) => boolean;
44
59
  /** Joins a relative specifier onto the importing file's directory; `undefined` when it climbs above the root. */
@@ -4,12 +4,22 @@
4
4
  * step runs.
5
5
  */
6
6
  export declare const CONTRACT_LIMITS: {
7
- /** UTF-8 bytes of `fabrika.contract.ts` and every module it imports, together. */
7
+ /**
8
+ * UTF-8 bytes of `fabrika.contract.ts` and every module it imports, together. Control reads them in a Cloudflare
9
+ * Worker, whose isolate has 128 MB; handler bodies are sliced out before the parse, so they cost bytes, not nodes.
10
+ */
8
11
  readonly sourceBytes: number;
12
+ /** UTF-8 bytes of one module: its own parse is the peak while it is read, and a dense one needs up to 340 times it. */
13
+ readonly moduleBytes: number;
14
+ /**
15
+ * Syntax nodes the reader holds over each graph (the contract's, the tables'), top-level type declarations left out.
16
+ * At this, `sourceBytes` and `schemaNodes` together, Control's read needs a 95 MB heap of its 128 MB isolate.
17
+ */
18
+ readonly astNodes: 400000;
9
19
  /** Nesting of syntax nodes in one module; the contracts in this repository reach 25. */
10
20
  readonly astDepth: 128;
11
21
  /** 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;
22
+ readonly schemaNodes: 60000;
23
+ /** Nesting of one schema: objects, arrays, unions and wrappers; it bounds the recursion of compiling and diffing one. */
24
+ readonly schemaDepth: 64;
15
25
  };
@@ -0,0 +1,9 @@
1
+ import type { MigrationBase } from './rules/migration-history';
2
+ /**
3
+ * The migrations at the merge base of HEAD and `ref` (the remote's default branch when omitted), compared against
4
+ * the merge base so that migrations the default branch added since the branch forked are not read as deleted.
5
+ * `null` when `root` is in no git work tree; `{ skipped }` when it is but the base cannot be read.
6
+ */
7
+ export declare const readMigrationBase: (root: string, ref?: string) => Promise<MigrationBase | {
8
+ readonly skipped: string;
9
+ } | null>;
@@ -1,15 +1,18 @@
1
+ import { DataSchema } from '@fabrika/app/schema';
1
2
  import { z } from 'zod/v4';
2
3
  import type { LiteralValue } from './value';
4
+ /** A schema the reader holds: one it read from a chain, or a framework schema (`signedToken()`, `file()`). */
5
+ export type ReadSchema = DataSchema | z.ZodType;
3
6
  export type SchemaStep = {
4
7
  readonly factory: string;
5
8
  readonly iso: boolean;
6
9
  } | {
7
10
  readonly method: string;
8
- readonly receiver: z.ZodType | undefined;
11
+ readonly receiver: ReadSchema | undefined;
9
12
  };
10
13
  export type BuiltSchema = {
11
14
  readonly ok: true;
12
- readonly schema: z.ZodType;
15
+ readonly schema: DataSchema;
13
16
  } | {
14
17
  readonly ok: false;
15
18
  readonly message: string;
@@ -1,7 +1,7 @@
1
- import type { z } from 'zod/v4';
2
1
  import { type AstNode, type ParsedModule } from '../ast';
3
- import type { Located, ModuleGraph } from '../graph';
2
+ import { type Located, type ModuleGraph } from '../graph';
4
3
  import type { ReaderProblems } from './problems';
4
+ import { type ReadSchema } from './schema';
5
5
  /**
6
6
  * The builder kit a call belongs to: `c` of `defineContract` and `l` of its link's `procedures`; `app`, the kit
7
7
  * `defineApp` returned; `c` of `app.contract` (`shell`) and `r` of a group, a link or an export (`endpoints`).
@@ -42,7 +42,7 @@ export type LiteralValue = {
42
42
  /** `nodes` counts the schema with every shared part expanded, as the artifact will hold it; `depth` its nesting. */
43
43
  | {
44
44
  readonly kind: 'schema';
45
- readonly schema: z.ZodType;
45
+ readonly schema: ReadSchema;
46
46
  readonly nodes: number;
47
47
  readonly depth: number;
48
48
  /** The chain that built it, factory first (`iso` for `z.iso.*`), across a const and the methods applied to it. */
@@ -1,4 +1,4 @@
1
- import { type AstNode } from './ast';
1
+ import { type AstNode, type ParsedModule } from './ast';
2
2
  /**
3
3
  * One way a module names another: a static import, a re-export, a dynamic `import()`, `require()` (also `module.require`
4
4
  * and `import.meta.require`) or `import x = require()`.
@@ -13,3 +13,8 @@ export interface ModuleReference {
13
13
  }
14
14
  export declare const isRequire: (callee: AstNode | undefined) => boolean;
15
15
  export declare const moduleReferences: (program: AstNode) => readonly ModuleReference[];
16
+ /**
17
+ * The sources of a module's import and re-export declarations that Bun evaluates: a type-only one, also one left with
18
+ * `type` specifiers alone once the slice removed the rest, is erased. `rules/literal.ts` decides which are allowed.
19
+ */
20
+ export declare const importedSpecifiers: (module: ParsedModule) => string[];
@@ -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,7 @@
1
+ import type { Finding } from '../finding';
2
+ /**
3
+ * What the reader refuses of `src/db/tables.ts`, and a contract that does not compile against its policies: Control
4
+ * reads the commit with the same calls and refuses the deploy. `readable` is false while the literal, trust or
5
+ * contract rules report the sources, so a refusal is not reported twice.
6
+ */
7
+ export declare const checkContractCompiles: (files: ReadonlyMap<string, string>, readable: boolean) => Finding[];
@@ -12,7 +12,7 @@ export type TrustedBindings = ReadonlyMap<string, readonly TrustedBinding[]>;
12
12
  export declare const trustedBindings: (file: string, program: AstNode, mappings: ImportMappings) => TrustedBindings;
13
13
  /**
14
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
15
+ * replaced `openPostgres` receives the database URL; a patched schema changes what the contract admits. A write
16
16
  * through a prototype is `prototype-assignment`'s. A local that shadows such a name is not one.
17
17
  */
18
18
  export declare const checkFrameworkWrite: (node: AstNode, ancestors: readonly AstNode[], bindings: TrustedBindings, report: Report) => void;
@@ -1,6 +1,6 @@
1
1
  import { type AstNode, type ParsedModule } from '../ast';
2
2
  import { type Finding } from '../finding';
3
- import type { ModuleGraph } from '../graph';
3
+ import { type ModuleGraph } from '../graph';
4
4
  /**
5
5
  * What a call root builds. `surface` is the parameter of a `defineContract` callback (`c`, `l`); `app` is
6
6
  * `defineApp`, `kit` a const it returned, `shell` the parameter of `app.contract`'s callback and `endpoints` that of
@@ -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[];
@@ -1,6 +1,22 @@
1
1
  import type { Finding } from '../finding';
2
2
  /** Migration file names sort by creation time, so parallel worktrees never claim the same name. */
3
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
+ /**
16
+ * A view is read-only (ADR-0072); on SQLite an INSTEAD OF trigger would make a view writable, so it is refused. SQLite
17
+ * takes INSTEAD OF only on a view, so the timing alone, written before the trigger's `ON`, names one.
18
+ */
19
+ export declare const checkSqliteViewTriggers: (files: ReadonlyMap<string, string>) => Finding[];
4
20
  /** A declared file column: `table.column` holds files of `kind`. */
5
21
  export interface FileColumn {
6
22
  readonly table: string;
@@ -27,3 +43,15 @@ export interface ConflictInsert {
27
43
  * checked: another receiver of `insert` is no table of the data layer.
28
44
  */
29
45
  export declare const checkConflictIndexes: (files: ReadonlyMap<string, string>, tables: ReadonlySet<string>, inserts: readonly ConflictInsert[]) => Finding[];
46
+ /** A table that names an access view under `key` (ADR-0076). */
47
+ export interface AccessKey {
48
+ readonly table: string;
49
+ readonly key: string;
50
+ readonly views: readonly string[];
51
+ }
52
+ /**
53
+ * A table that names an access view needs its key unique on its own, or the view's `row` names several rows at once
54
+ * (ADR-0076 section 1). A view as the target keeps its key unique by its SQL; any other name no migration creates as a
55
+ * table is refused, so a statement the reader does not follow fails closed.
56
+ */
57
+ export declare const checkAccessViewKeys: (files: ReadonlyMap<string, string>, keys: readonly AccessKey[]) => Finding[];
@@ -0,0 +1,15 @@
1
+ import { type MigrationDialect } from '@fabrika/platform-node/sql';
2
+ import type { Finding } from '../finding';
3
+ /**
4
+ * Every statement Control's classifier refuses, at its file and line, against the application's access tables and in its
5
+ * dialect. Control refuses a deploy whose new migration holds
6
+ * one (`migrations-refused`), and its run log names neither, so this is where the author finds it. Every file is
7
+ * checked, applied or not: the checker does not know which an environment holds.
8
+ */
9
+ export declare const checkMigrationClassification: (files: ReadonlyMap<string, string>, appId: string, accessTables: readonly string[], dialect: MigrationDialect) => Finding[];
10
+ /**
11
+ * On Cloudflare, the backup's refusal of the migrated schema (`planOpsDump`), at the newest migration that names the
12
+ * table. Every migration deploy backs the environment up first, so a schema the backup refuses blocks every migration
13
+ * after the one that made it. A migration set that does not apply is codegen's to report, so it finds nothing here.
14
+ */
15
+ export declare const checkBackupPlan: (files: ReadonlyMap<string, string>) => Promise<Finding[]>;
@@ -8,8 +8,11 @@ export interface SourceContext {
8
8
  readonly rawSql: ReadonlySet<string>;
9
9
  /** A module under `src/` that is not a test: it reaches no global object and no `Bun` at all. */
10
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;
11
+ /**
12
+ * A `fetch` of an absolute URL, by its static prefix and, for a template whose first label alone is interpolated, its
13
+ * authority with that label as `*`: refused once the contract shows that no site declares its origin in `egress`.
14
+ */
15
+ readonly absoluteFetch: (node: AstNode, target: string, labelled: string | undefined) => void;
13
16
  /** A `ctx.url('<endpoint id>', …)` with a literal id: refused once the contract shows that it names no procedure. */
14
17
  readonly appUrl: (node: AstNode, endpoint: string) => void;
15
18
  /** A `<table>.insert(values, { onConflict: { columns } })`: refused once the migrations show no unique index of them. */
@@ -28,5 +31,7 @@ export declare const crossAppFetchMessage: (target: string) => {
28
31
  };
29
32
  /** Whether an expression reaches a prototype: through `.prototype`, `.__proto__` or `Object.getPrototypeOf(…)`. */
30
33
  export declare const touchesPrototype: (node: AstNode | undefined) => boolean;
34
+ /** `key-literal` over a string or a template's text: also the one rule of this module a developer's tool is held to. */
35
+ export declare const checkKeyLiteralNode: (node: AstNode, report: Report) => void;
31
36
  /** The rules that read one node at a time, for every source file. */
32
37
  export declare const checkRuntimeNode: (node: AstNode, ancestors: readonly AstNode[], context: SourceContext) => void;
@@ -1,9 +1,9 @@
1
1
  import { type AstNode } from '../ast';
2
- import { type Report } from '../finding';
2
+ import { type Finding, type Report } from '../finding';
3
3
  import type { ModuleReference } from '../references';
4
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"];
5
+ /** The rules of the application architecture (docs/reference/application-architecture.md): three refusals and the hints. */
6
+ export declare const STRUCTURE_RULE_IDS: readonly ["spa-server-import", "layer-import", "shared-import", "logic-data-access", "cross-slice-queries", "single-slice-queries", "handler-location", "data-access-location"];
7
7
  type SlicePart = 'endpoints' | 'logic' | 'queries';
8
8
  /** Where a module sits in the architecture, which decides what it may import and call. */
9
9
  export interface StructurePlace {
@@ -12,14 +12,28 @@ export interface StructurePlace {
12
12
  readonly part: SlicePart | undefined;
13
13
  /** A test or the generated entrypoint: the structure hints do not apply to it. */
14
14
  readonly exempt: boolean;
15
+ /** A generated module (`isGeneratedModule`): the hints do not apply to it, the refusals do. */
16
+ readonly generated: boolean;
15
17
  }
16
- export declare const structurePlace: (file: string, isGeneratedEntry: boolean) => StructurePlace;
18
+ export declare const structurePlace: (file: string, isGeneratedEntry: boolean, generated: boolean) => StructurePlace;
17
19
  /** What the structure rules read beyond one module: every module's references, and how Bun resolves them. */
18
20
  export interface StructureGraph {
19
21
  readonly files: ReadonlyMap<string, string>;
20
22
  readonly mappings: ImportMappings;
21
23
  readonly referencesOf: (path: string) => readonly ModuleReference[];
22
24
  }
25
+ /**
26
+ * `single-slice-queries`: a function of `src/<a>/queries.ts` that exactly one other slice `src/<b>/` uses belongs in
27
+ * `src/<b>/queries.ts`. A caller is any module but a test, and a use is a named import or re-export; a function
28
+ * exported under two names is one function. A module outside every slice, and a whole-module load (`import *`,
29
+ * `export *`) from another slice, which names no function, leave every function they reach where it is.
30
+ */
31
+ export declare const checkSingleSliceQueries: (graph: StructureGraph, programs: ReadonlyMap<string, AstNode>) => Finding[];
32
+ /**
33
+ * A `package.json` under `tools/` makes a tool a package, which a workspace or a `file:` dependency lets the application
34
+ * load by its name, past `tool-import`, which judges the files an import resolves to.
35
+ */
36
+ export declare const checkToolPackages: (paths: readonly string[]) => Finding[];
23
37
  /** The architecture's rules over one module's imports, re-exports and loads, as Bun resolves them for that module. */
24
38
  export declare const checkStructureReferences: (graph: StructureGraph, place: StructurePlace, report: Report) => void;
25
39
  /** A `<x>.<builder>(…).handle(…)` call: the builder's name, its call (whose arguments hold the options) and `.handle`. */
@@ -1,22 +1,14 @@
1
- import { type AstNode, type Comment } from '../ast';
1
+ import { type AstNode } from '../ast';
2
2
  import type { Finding, Report } from '../finding';
3
3
  /** For test files: every test runs, and every test asserts. */
4
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
5
  /**
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.
6
+ * The `bunfig.toml` of an application must not narrow its own suite, which the platform build runs. A file outside the
7
+ * TOML subset is reported by the trust rules.
14
8
  */
15
9
  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
10
  /**
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.
11
+ * `mock.module(…)` of the test runner or a framework package would let application code replace what the test kit runs
12
+ * on; a computed specifier could name either. Refused anywhere in the application.
21
13
  */
22
- export declare const checkMockModule: (node: AstNode, file: string, files: ReadonlyMap<string, string>, report: Report) => void;
14
+ export declare const checkMockModule: (node: AstNode, report: Report) => void;
@@ -1,4 +1,6 @@
1
1
  import { type AstNode, type Comment } from '../ast';
2
2
  import type { Report } from '../finding';
3
+ /** `type-assertion` and `any-type`: how a module's own source is written, which a generated module is not held to. */
3
4
  export declare const checkTypeNode: (node: AstNode, report: Report) => void;
5
+ export declare const checkCapabilityNode: (node: AstNode, report: Report) => void;
4
6
  export declare const checkComments: (comments: readonly Comment[], report: Report) => void;
@@ -0,0 +1,7 @@
1
+ /** The application's own modules under `root`, outside `node_modules`: every extension the reader reads. */
2
+ export declare const applicationModules: (root: string) => RegExp;
3
+ /**
4
+ * The shell modules under `root`, by absolute path, as their slices; none without a `fabrika.contract.ts` there.
5
+ * Throws the reader's refusal when the static reader refuses the shell or the table policies.
6
+ */
7
+ export declare function shellModules(root: string): ReadonlyMap<string, string>;
@@ -1,5 +1,10 @@
1
1
  import { type AstNode, type ParsedModule, type ParseResult } from './ast';
2
2
  import type { Finding } from './finding';
3
+ export interface Range {
4
+ readonly start: number;
5
+ readonly end: number;
6
+ }
7
+ export declare const offsets: (node: AstNode) => Range | undefined;
3
8
  /** A `.handle(…)` the slice cannot keep out of the shell, at its `handle`; the reader and the SPA build refuse it. */
4
9
  export interface SliceRefusal {
5
10
  readonly node: AstNode;
@@ -13,9 +18,10 @@ export interface ShellSlice {
13
18
  }
14
19
  /**
15
20
  * 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.
21
+ * blanked. A module without a handler comes back unchanged. Each range of `removed` goes as a handler does, with what
22
+ * only it uses.
17
23
  */
18
- export declare function moduleSlice(module: ParsedModule, text: string): ShellSlice;
24
+ export declare function moduleSlice(module: ParsedModule, text: string, removed?: readonly Range[]): ShellSlice;
19
25
  /**
20
26
  * The slice of a module's text. Text that does not parse comes back unchanged, so the reader reports the parse error
21
27
  * where it is.
@@ -0,0 +1,27 @@
1
+ export interface ShellSliceOptions {
2
+ /** The application's root, where `fabrika.contract.ts` lies; the working directory by default. */
3
+ readonly root?: string;
4
+ }
5
+ /** What the plugin uses of Vite's plugin context. */
6
+ export interface WatchContext {
7
+ addWatchFile(id: string): void;
8
+ }
9
+ /** The part of Vite's `Plugin` this plugin implements; a value of it goes into `plugins` as it is. */
10
+ export interface ShellSliceVitePlugin {
11
+ readonly name: string;
12
+ readonly enforce: 'pre';
13
+ /**
14
+ * A shell module's slice, its file watched; `null` leaves the module to Vite's own load. Throws for a
15
+ * `fabrika.contract.ts` that is not the root's: Vite would bundle it, handlers included.
16
+ */
17
+ load(this: WatchContext, id: string): {
18
+ readonly code: string;
19
+ } | null;
20
+ /** Any change of a watched file: the next load reads the shell graph again. */
21
+ watchChange(): void;
22
+ }
23
+ /**
24
+ * Loads every module of the application's shell graph as its slice: no `.handle(…)`, and no import only a handler
25
+ * used. The build fails with the reader's findings when the static reader refuses the shell.
26
+ */
27
+ export declare function shellSlicePlugin(options?: ShellSliceOptions): ShellSliceVitePlugin;