@reqvire-org/ads-guard 0.0.0-stage → 0.5.0

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.
@@ -0,0 +1,46 @@
1
+ import type { SourceFile } from "typescript/ast";
2
+ import type { NativeProgram, ProgramOptions } from "./semantic.mts";
3
+ /** A resolved module: its file and whether resolution found it as a package. */
4
+ export interface ResolvedModule {
5
+ readonly file: string;
6
+ readonly external: boolean;
7
+ }
8
+ /**
9
+ * What a revision-scoped analysis provides. Every member is optional: a
10
+ * standalone request (no captured revision) reads the live project instead.
11
+ */
12
+ export interface AnalysisProviders {
13
+ readonly provideProgram?: (purpose: string, rootNames: readonly string[], options: ProgramOptions) => Promise<NativeProgram>;
14
+ readonly provideSource?: (file: string) => Promise<SourceFile | undefined>;
15
+ /** A captured file's text, or `null`/`undefined` when the revision has no such file. */
16
+ readonly readText?: (file: string) => string | null | undefined;
17
+ /** Immediate files of a captured directory. */
18
+ readonly listFiles?: (directory: string) => readonly string[];
19
+ /** Every captured file below a directory. */
20
+ readonly listTree?: (directory: string) => readonly string[];
21
+ readonly resolveModule?: (specifier: string, file: string, options: ProgramOptions) => Promise<string | null | undefined>;
22
+ readonly resolveModuleDetails?: (specifier: string, file: string, options: ProgramOptions) => Promise<ResolvedModule | null>;
23
+ /** The captured revision: owner of revision-lifetime facts. */
24
+ readonly revision?: object;
25
+ /** Identity of the revision's inputs outside its captured files (installed dependencies); absent when unknown. */
26
+ readonly environment?: () => string;
27
+ /**
28
+ * The captured validation inputs' revision (`inputRevision`, ./inputs.mts), the one `ads emit`
29
+ * records for the same bytes; absent when the request was not captured from a complete input read
30
+ * (a registered draft or candidate revision, a test's own revision). Never recomputed from disk.
31
+ */
32
+ readonly inputRevision?: string;
33
+ readonly runtime?: unknown;
34
+ }
35
+ export interface AnalysisContext extends AnalysisProviders {
36
+ readonly root: string;
37
+ /** Request-lifetime facts, by owner object. */
38
+ readonly facts: WeakMap<object, Map<string, unknown>>;
39
+ }
40
+ /** Runs `run` in an analysis of `root`; a plain nested request joins the enclosing one. */
41
+ export declare function runAnalysis<T>(root: string, run: (context: AnalysisContext) => T, providers?: AnalysisProviders): T;
42
+ export declare function currentAnalysis(): AnalysisContext | undefined;
43
+ /** Share pure project discovery during one fenced analysis operation. */
44
+ export declare function memoFact<T>(owner: object, key: string, compute: () => T): T;
45
+ /** Pure facts may live as long as their immutable program/tree or captured view, never by path alone. */
46
+ export declare function memoProgram<T>(program: object, key: string, compute: () => T): T;
@@ -0,0 +1,61 @@
1
+ import type { Node, SourceFile } from "typescript/ast";
2
+ export type DesignUsageProblem =
3
+ /** An import that authors design (an ADS authoring macro): design is declared in the design system only. */
4
+ {
5
+ readonly kind: "design-import";
6
+ readonly specifier: string;
7
+ }
8
+ /** A design-system component rendered outside every pattern: nothing owns its place on the screen. */
9
+ | {
10
+ readonly kind: "component-outside-pattern";
11
+ readonly name: string;
12
+ }
13
+ /** JSX other than something imported from the design system: a native element or a local component. */
14
+ | {
15
+ readonly kind: "local-markup";
16
+ readonly tag: string;
17
+ }
18
+ /** A JSX spread: props nothing can see. */
19
+ | {
20
+ readonly kind: "spread-props";
21
+ }
22
+ /** A design-carrying prop. */
23
+ | {
24
+ readonly kind: "design-prop";
25
+ readonly attribute: string;
26
+ }
27
+ /** Imperative style writes or DOM creation. */
28
+ | {
29
+ readonly kind: "imperative-design";
30
+ readonly member: string;
31
+ }
32
+ /** A recipe, profile or custom-property reference hidden in a string. */
33
+ | {
34
+ readonly kind: "hidden-definition";
35
+ };
36
+ /** A problem at its node. */
37
+ export interface DesignUsage {
38
+ readonly node: Node;
39
+ readonly problem: DesignUsageProblem;
40
+ }
41
+ /** What the check knows of the design system: the specifier it is imported from, and which of its exports are patterns. */
42
+ export interface DesignSystemEntry {
43
+ /** The specifier of the public entry (`@ds`). */
44
+ readonly publicEntry: string;
45
+ /** The exported names that are patterns: what arranges a screen. Every other export is a component, which fills a pattern. */
46
+ readonly patterns: ReadonlySet<string>;
47
+ }
48
+ /** What a source package may use beside the design system. A design system's mocks use none of it. */
49
+ export interface DesignUsageAllowance {
50
+ /**
51
+ * Components of other packages that carry no design (a router's outlet, a provider, the framework's
52
+ * own markers), by package specifier and exported name; `default` names a default import. An allowed
53
+ * component is not markup of the file's own, and it is transparent: what it wraps is where its
54
+ * parent put it.
55
+ */
56
+ readonly components?: ReadonlyMap<string, ReadonlySet<string>>;
57
+ /** Accept document metadata anywhere: `<title>`, `<meta>`, `<script>` and a `<link>` that is not a stylesheet. */
58
+ readonly metadata?: boolean;
59
+ }
60
+ /** Every design-use problem of `source`, in source order. */
61
+ export declare function designUsageProblems(source: SourceFile, { publicEntry, patterns }: DesignSystemEntry, allowance?: DesignUsageAllowance): readonly DesignUsage[];
@@ -0,0 +1,12 @@
1
+ /** A native module resolver: one per distinct compiler-options key. */
2
+ export interface NativeModuleResolver<R> {
3
+ readonly resolveModuleName: (specifier: string, directory: string) => Promise<R> | R;
4
+ readonly dispose: () => Promise<void> | void;
5
+ }
6
+ export interface ModuleResolvers<R> {
7
+ readonly resolve: (specifier: string, directory: string, options: unknown) => Promise<R>;
8
+ /** Waits for every request, then disposes every resolver; reports the first disposal failure. */
9
+ readonly close: () => Promise<void>;
10
+ }
11
+ /** Native resolver leases belong to one input capture, never live paths across captures. */
12
+ export declare function createModuleResolvers<R>(createResolver: (options: unknown) => NativeModuleResolver<R> | Promise<NativeModuleResolver<R>>): ModuleResolvers<R>;
@@ -0,0 +1,87 @@
1
+ import type { Node, SourceFile } from "typescript/ast";
2
+ import type { Diagnostic as NativeDiagnostic, RawCompilerOptions } from "typescript/async";
3
+ /** Options of one native program, as rules supply them. */
4
+ /** An option as callers may supply it: arrays and path maps read-only. */
5
+ type ReadonlyOption<V> = V extends readonly (infer Item)[] ? readonly Item[] : V extends Readonly<Record<string, readonly (infer Item)[]>> ? Readonly<Record<string, readonly Item[]>> : V;
6
+ export type ProgramOptions = {
7
+ readonly [K in keyof RawCompilerOptions]?: ReadonlyOption<RawCompilerOptions[K]>;
8
+ };
9
+ /** A symbol: its declarations already resolved to (relocated) nodes. */
10
+ export interface NativeSymbol {
11
+ readonly name: string;
12
+ readonly flags: number;
13
+ readonly declarations: readonly Node[] | undefined;
14
+ readonly valueDeclaration: Node | undefined;
15
+ }
16
+ /** A call or construct signature: its parameters already fetched. */
17
+ export interface NativeSignature {
18
+ readonly parameters: readonly NativeSymbol[];
19
+ /** What a call returns; for a construct signature, the instance type. */
20
+ readonly getReturnType: () => Promise<NativeType>;
21
+ }
22
+ /** A type: union, intersection and template constituents already fetched. */
23
+ export interface NativeType {
24
+ readonly id: number;
25
+ readonly flags: number;
26
+ readonly value?: unknown;
27
+ readonly types?: readonly NativeType[];
28
+ readonly isUnion: () => boolean;
29
+ readonly isIntersection: () => boolean;
30
+ readonly getProperties: () => Promise<readonly NativeSymbol[]>;
31
+ readonly getProperty: (name: string) => Promise<NativeSymbol | undefined>;
32
+ readonly getCallSignatures: () => Promise<readonly NativeSignature[]>;
33
+ readonly getConstructSignatures: () => Promise<readonly NativeSignature[]>;
34
+ readonly getStringIndexType: () => Promise<NativeType | undefined>;
35
+ readonly getNumberIndexType: () => Promise<NativeType | undefined>;
36
+ /** The type's own symbol (an interface, a class), if it has one. */
37
+ readonly getSymbol: () => Promise<NativeSymbol | undefined>;
38
+ /** The type alias it was written through (`ReactNode`), if any. */
39
+ readonly getAliasSymbol: () => Promise<NativeSymbol | undefined>;
40
+ /** A class or interface type's base types; `undefined` for any other type. */
41
+ readonly getBaseTypes: () => Promise<readonly NativeType[] | undefined>;
42
+ /** A generic instantiation's target (the generic declaration's type); throws for a type that is no instantiation. */
43
+ readonly getTarget: () => Promise<NativeType | undefined>;
44
+ }
45
+ export interface NativeChecker {
46
+ readonly getSymbolAtLocation: (node: Node) => Promise<NativeSymbol | undefined>;
47
+ readonly getAliasedSymbol: (symbol: NativeSymbol) => Promise<NativeSymbol>;
48
+ readonly getShorthandAssignmentValueSymbol: (node: Node) => Promise<NativeSymbol | undefined>;
49
+ readonly resolveName: (name: string, meaning: number, location: Node, excludeGlobals: boolean) => Promise<NativeSymbol | undefined>;
50
+ readonly getExportsOfModule: (symbol: NativeSymbol) => Promise<readonly NativeSymbol[]>;
51
+ readonly getTypeAtLocation: (node: Node) => Promise<NativeType>;
52
+ readonly getPropertyOfType: (type: NativeType, name: string) => Promise<NativeSymbol | undefined>;
53
+ readonly getTypeOfSymbolAtLocation: (symbol: NativeSymbol, location: Node) => Promise<NativeType>;
54
+ /** The type as the checker prints it, written from `enclosing` (a declaration); `flags` are `TypeFormatFlags`. */
55
+ readonly typeToString: (type: NativeType, enclosing?: Node, flags?: number) => Promise<string>;
56
+ }
57
+ /** A diagnostic message: text, or a chain in the classic compiler's shape. */
58
+ export type DiagnosticMessageChain = string | {
59
+ readonly messageText: string;
60
+ readonly code: number;
61
+ readonly category: number;
62
+ readonly next: readonly DiagnosticMessageChain[];
63
+ };
64
+ /** A native diagnostic with its file relocated and its message in the classic shape. */
65
+ export type ProgramDiagnostic = Omit<NativeDiagnostic, "fileName"> & {
66
+ readonly fileName: string | undefined;
67
+ readonly messageText: DiagnosticMessageChain;
68
+ };
69
+ export type SyntacticDiagnostic = ProgramDiagnostic & {
70
+ readonly start: number;
71
+ readonly length: number;
72
+ };
73
+ /** One program over a snapshot, as rules see it. */
74
+ export interface NativeProgram {
75
+ readonly getTypeChecker: () => NativeChecker;
76
+ readonly getDiagnostics: () => Promise<readonly ProgramDiagnostic[]>;
77
+ readonly getSourceFile: (file: string) => Promise<SourceFile | undefined>;
78
+ readonly hasSourceFile: (file: string) => boolean;
79
+ readonly getSourceFileNames: () => readonly string[];
80
+ /** Project sources: inside the root, outside `node_modules`. */
81
+ readonly getSourceFiles: () => Promise<readonly (SourceFile | undefined)[]>;
82
+ readonly getCompilerOptions: () => ProgramOptions;
83
+ readonly getRootFileNames: () => readonly string[];
84
+ readonly getCurrentDirectory: () => string;
85
+ readonly getSyntacticDiagnostics: (source?: SourceFile) => Promise<readonly SyntacticDiagnostic[]>;
86
+ }
87
+ export {};