@fabrika/check 0.9.0-dev.4 → 0.9.0-dev.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -6
- package/src/check.ts +25 -6
- package/src/dialect.ts +29 -0
- package/src/endpoint-fixtures.ts +99 -13
- package/src/finding.ts +8 -3
- package/src/index.ts +2 -1
- package/src/layout.ts +8 -1
- package/src/reader/surface.ts +15 -0
- package/src/reader/value.ts +1 -1
- package/src/resolution.ts +2 -2
- package/src/rules/cloudflare.ts +59 -0
- package/src/rules/framework.ts +2 -2
- package/src/rules/isolation.ts +5 -1
- package/src/rules/migrations.ts +63 -0
- package/src/rules/modules.ts +3 -3
- package/src/rules/tests.ts +1 -1
- package/src/scaffold.ts +265 -38
- package/types/src/dialect.d.ts +8 -0
- package/types/src/endpoint-fixtures.d.ts +18 -0
- package/types/src/finding.d.ts +6 -5
- package/types/src/index.d.ts +2 -1
- package/types/src/layout.d.ts +6 -0
- package/types/src/rules/cloudflare.d.ts +9 -0
- package/types/src/rules/framework.d.ts +1 -1
- package/types/src/rules/migrations.d.ts +11 -0
- package/types/src/scaffold.d.ts +9 -3
|
@@ -6,6 +6,10 @@ export declare const MEMBERS_EXPORT = "members";
|
|
|
6
6
|
export declare const INVITATIONS_EXPORT = "invitations";
|
|
7
7
|
export declare const LINKS_EXPORT = "links";
|
|
8
8
|
export declare const ROWS_EXPORT = "rows";
|
|
9
|
+
export declare const APP_ROWS_EXPORT = "appRows";
|
|
10
|
+
export declare const FILES_EXPORT = "files";
|
|
11
|
+
export declare const REFUSALS_EXPORT = "refusals";
|
|
12
|
+
export declare const PINS_EXPORT = "pins";
|
|
9
13
|
type ById = Readonly<Record<string, Readonly<Record<string, Sample>>>>;
|
|
10
14
|
export interface EndpointFixtures {
|
|
11
15
|
/** The input each endpoint's cases send, by endpoint id. */
|
|
@@ -20,8 +24,22 @@ export interface EndpointFixtures {
|
|
|
20
24
|
readonly links: Readonly<Record<string, readonly string[]>>;
|
|
21
25
|
/** The input fields that name a row lying in the endpoint's object, with that row's table, by endpoint id. */
|
|
22
26
|
readonly rows: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
27
|
+
/** The rows of application tables the endpoint's own case reads, by table, each with its columns, by endpoint id. */
|
|
28
|
+
readonly appRows: Readonly<Record<string, Readonly<Record<string, Readonly<Record<string, Sample>>>>>>;
|
|
29
|
+
/** The file each case sends in a file field, a path relative to the application's root, by input field, by endpoint id. */
|
|
30
|
+
readonly files: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
31
|
+
/** The error types of the 400s an endpoint's handler may answer its own object with, by endpoint id. */
|
|
32
|
+
readonly refusals: Readonly<Record<string, readonly string[]>>;
|
|
33
|
+
/** The own scope's value of each pinned text column of the row the endpoint addresses, by endpoint id. */
|
|
34
|
+
readonly pins: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
23
35
|
}
|
|
24
36
|
export declare const NO_FIXTURES: EndpointFixtures;
|
|
37
|
+
/**
|
|
38
|
+
* Whether `path` may name a file fixture: relative to the application's root, `/`-separated, and each segment of
|
|
39
|
+
* letters, digits, `_`, `-` and `.` that starts with neither `.` nor `-`, so it never leaves the root, names no dotfile and
|
|
40
|
+
* reads the same as a URL path.
|
|
41
|
+
*/
|
|
42
|
+
export declare const isFixtureFilePath: (path: string) => boolean;
|
|
25
43
|
export declare function isSampleObject(value: Sample): value is {
|
|
26
44
|
readonly [key: string]: Sample;
|
|
27
45
|
};
|
package/types/src/finding.d.ts
CHANGED
|
@@ -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", "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", "cloudflare-scan", "cloudflare-job-segment", "cloudflare-current-timestamp", "cloudflare-framework-name"];
|
|
4
4
|
/** Rules that report a step out of the application architecture. */
|
|
5
5
|
export declare const STRUCTURE_HINT_RULE_IDS: readonly ["logic-data-access", "cross-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,
|
|
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", "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", "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", "cloudflare-scan", "cloudflare-job-segment", "cloudflare-current-timestamp", "cloudflare-framework-name", "logic-data-access", "cross-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];
|
package/types/src/index.d.ts
CHANGED
|
@@ -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, ZEROPS_FILES } from './layout';
|
|
4
5
|
export { type PackedSet, type PackedTarball, readPackedSet } from './packed';
|
|
5
6
|
export { GENERATED_TEST_HEADER, generatedTestHeader } from './rules/tests';
|
|
6
7
|
export { ENDPOINT_ACCESS_TEST, ENDPOINT_FIXTURES_FILE, type GeneratedTest, generatedTests, missingEndpointFixtures, POLICY_TESTS_DIR, policyTestPath, scaffoldInputs, } from './scaffold';
|
package/types/src/layout.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/** Where an application keeps what the checker reads. Paths are relative to the application root. */
|
|
2
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";
|
|
3
5
|
/** The named export of the contract module that holds `defineContract(…)`. */
|
|
4
6
|
export declare const CONTRACT_EXPORT = "contract";
|
|
5
7
|
export declare const TABLES_FILE = "src/db/tables.ts";
|
|
6
8
|
/** The named export of the tables module that holds `defineTables(…)(…)`. */
|
|
7
9
|
export declare const TABLES_EXPORT = "tables";
|
|
8
10
|
export declare const GENERATED_ENTRY_FILE = "fabrika/entry.generated.ts";
|
|
11
|
+
/** Where a Cloudflare deploy stages the SPA mounts' built files (`@fabrika/provider-cloudflare`): build output, never source. */
|
|
12
|
+
export declare const STAGED_ASSETS_DIR = "fabrika/assets/";
|
|
9
13
|
export declare const MIGRATIONS_DIR = "db/migrations/";
|
|
10
14
|
/** Where `fabrika db test-scaffold` writes the policy isolation tests, `<table>.policy-isolation.test.ts`. */
|
|
11
15
|
export declare const POLICY_TESTS_DIR = "src/db/__tests__/";
|
|
@@ -34,6 +38,8 @@ export declare const SPA_DIR = "web/";
|
|
|
34
38
|
export declare const SERVER_DIR = "src/";
|
|
35
39
|
/** Build output, installed packages and tool state are not application source and are never read. */
|
|
36
40
|
export declare const isIgnoredSegment: (segment: string) => boolean;
|
|
41
|
+
/** Whether the checker skips `path` (relative to the root): under a skipped segment, or the staged SPA files. */
|
|
42
|
+
export declare const isSkippedPath: (path: string) => boolean;
|
|
37
43
|
export declare const isSourceFile: (path: string) => boolean;
|
|
38
44
|
export declare const isTestFile: (path: string) => boolean;
|
|
39
45
|
/** A module that runs in the application's server process: under `src/`, not a test. */
|
|
@@ -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[];
|
|
@@ -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 `
|
|
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,17 @@
|
|
|
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[];
|
|
4
15
|
/** A declared file column: `table.column` holds files of `kind`. */
|
|
5
16
|
export interface FileColumn {
|
|
6
17
|
readonly table: string;
|
package/types/src/scaffold.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { type ContractArtifact, type TablePolicyArtifact } from '@fabrika/auth-core';
|
|
2
|
+
import { type Tables } from '@fabrika/db/tables';
|
|
3
|
+
import { type ApplicationDialect } from './dialect';
|
|
2
4
|
import { type EndpointFixtures } from './endpoint-fixtures';
|
|
3
5
|
import type { Finding } from './finding';
|
|
4
6
|
export { ENDPOINT_ACCESS_TEST, ENDPOINT_FIXTURES_FILE, POLICY_TEST_SUFFIX, POLICY_TESTS_DIR } from './layout';
|
|
@@ -11,13 +13,17 @@ export interface GeneratedTest {
|
|
|
11
13
|
type Policies = Readonly<Record<string, TablePolicyArtifact>>;
|
|
12
14
|
/**
|
|
13
15
|
* Every test the scaffold writes for these policies and, when the application has a contract, its artifact; by path.
|
|
14
|
-
* Endpoint access tests exist only for an application on `@fabrika/db`, which has policies to seed rows from.
|
|
16
|
+
* Endpoint access tests exist only for an application on `@fabrika/db`, which has policies to seed rows from. They
|
|
17
|
+
* open the test database of the application's dialect.
|
|
15
18
|
*/
|
|
16
|
-
export declare const generatedTests: (policies: Policies, artifact: ContractArtifact | null, fixtures?: EndpointFixtures) => Promise<ReadonlyMap<string, GeneratedTest>>;
|
|
19
|
+
export declare const generatedTests: (policies: Policies, artifact: ContractArtifact | null, fixtures?: EndpointFixtures, dialect?: ApplicationDialect) => Promise<ReadonlyMap<string, GeneratedTest>>;
|
|
17
20
|
export interface ScaffoldInputs {
|
|
21
|
+
/** What `src/db/tables.ts` defines, its column list included; `null` without the file. */
|
|
22
|
+
readonly tables: Tables<unknown, unknown> | null;
|
|
18
23
|
readonly policies: Policies;
|
|
19
24
|
readonly artifact: ContractArtifact | null;
|
|
20
25
|
readonly fixtures: EndpointFixtures;
|
|
26
|
+
readonly dialect: ApplicationDialect;
|
|
21
27
|
}
|
|
22
28
|
/** What the scaffold reads from an application's files; throws `ContractSourceError` or `ContractError` as the reader does. */
|
|
23
29
|
export declare const scaffoldInputs: (files: ReadonlyMap<string, string>) => ScaffoldInputs;
|
|
@@ -25,4 +31,4 @@ export declare const scaffoldInputs: (files: ReadonlyMap<string, string>) => Sca
|
|
|
25
31
|
* What stops the endpoint access tests from covering every endpoint: one whose input the scaffold cannot sample and
|
|
26
32
|
* the author gave no fixture, and a fixture of no tested endpoint. Each is an `endpoint-fixture` finding.
|
|
27
33
|
*/
|
|
28
|
-
export declare const missingEndpointFixtures: ({ policies, artifact, fixtures }: ScaffoldInputs) => readonly Finding[];
|
|
34
|
+
export declare const missingEndpointFixtures: ({ tables, policies, artifact, fixtures }: ScaffoldInputs) => readonly Finding[];
|