@supacloud/compiler 0.28.0 → 0.29.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,39 @@
1
+ import type { Diagnostic } from "./types";
2
+ import type { DiagnosticRepair } from "./repair-plan";
3
+ /** Shared source for CLI JSON consumers, editor diagnostics and AI repair tools. */
4
+ export interface DiagnosticReportEntry {
5
+ diagnostic: Diagnostic;
6
+ repair?: DiagnosticRepair;
7
+ guidance?: string;
8
+ }
9
+ export interface DiagnosticReport {
10
+ format: 1;
11
+ entries: DiagnosticReportEntry[];
12
+ }
13
+ export declare function createDiagnosticReport(diagnostics: readonly Diagnostic[]): DiagnosticReport;
14
+ /** LSP-shaped data only. It neither starts a language server nor applies unreviewed edits. */
15
+ export declare function toEditorDiagnostics(diagnostics: readonly Diagnostic[]): {
16
+ message: string;
17
+ data: {
18
+ diagnostic: Diagnostic;
19
+ repair?: DiagnosticRepair;
20
+ guidance?: string;
21
+ format: 1;
22
+ };
23
+ codeDescription?: {
24
+ href: string;
25
+ } | undefined;
26
+ range: {
27
+ start: {
28
+ line: number;
29
+ character: number;
30
+ };
31
+ end: {
32
+ line: number;
33
+ character: number;
34
+ };
35
+ };
36
+ severity: 1 | 2;
37
+ source: string;
38
+ code: string;
39
+ }[];
@@ -0,0 +1,73 @@
1
+ // src/repair-plan.ts
2
+ function createDiagnosticRepairPlan(diagnostics) {
3
+ return diagnostics.flatMap((diagnostic) => {
4
+ const fix = diagnostic.fix;
5
+ if (!fix)
6
+ return [];
7
+ return [{
8
+ code: diagnostic.code,
9
+ ...diagnostic.errorCode === undefined ? {} : { errorCode: diagnostic.errorCode },
10
+ ...diagnostic.file === undefined ? {} : { file: diagnostic.file },
11
+ ...diagnostic.line === undefined ? {} : { line: diagnostic.line },
12
+ type: fix.type,
13
+ targetFile: fix.targetFile,
14
+ fix,
15
+ ...classifyFix(fix)
16
+ }];
17
+ });
18
+ }
19
+ function classifyFix(fix) {
20
+ switch (fix.type) {
21
+ case "set_command_mode":
22
+ if (fix.value !== "required" && fix.value !== "none") {
23
+ return { readiness: "input-required", reason: "Choose an explicit transaction or idempotency policy; no policy is inferred." };
24
+ }
25
+ break;
26
+ case "add_command_permission":
27
+ if (!fix.permission?.trim()) {
28
+ return { readiness: "input-required", reason: "Choose an explicit business permission; privileges are never inferred." };
29
+ }
30
+ break;
31
+ case "add_module_import":
32
+ if (!fix.importPath || !fix.symbol) {
33
+ return { readiness: "input-required", reason: "Supply the module import path and exported symbol before previewing." };
34
+ }
35
+ break;
36
+ case "add_route_parameter_binding":
37
+ break;
38
+ default:
39
+ return { readiness: "manual", reason: "The semantic fix executor does not implement this suggestion; edit and verify it manually." };
40
+ }
41
+ return { readiness: "preview", reason: "Preview with the semantic fix executor; source preconditions are checked before writing." };
42
+ }
43
+
44
+ // src/diagnostics.ts
45
+ function createDiagnosticReport(diagnostics) {
46
+ return { format: 1, entries: diagnostics.map((diagnostic) => {
47
+ const repair = createDiagnosticRepairPlan([diagnostic])[0];
48
+ return {
49
+ diagnostic: { ...diagnostic },
50
+ ...repair ? { repair } : {},
51
+ ...diagnostic.suggestion ? { guidance: diagnostic.suggestion } : {}
52
+ };
53
+ }) };
54
+ }
55
+ function toEditorDiagnostics(diagnostics) {
56
+ return createDiagnosticReport(diagnostics).entries.map((entry) => ({
57
+ range: {
58
+ start: { line: Math.max(0, (entry.diagnostic.line ?? 1) - 1), character: 0 },
59
+ end: { line: Math.max(0, (entry.diagnostic.line ?? 1) - 1), character: 0 }
60
+ },
61
+ severity: entry.diagnostic.severity === "error" ? 1 : 2,
62
+ source: "supacloud",
63
+ code: entry.diagnostic.errorCode ?? entry.diagnostic.code,
64
+ ...entry.diagnostic.docsUrl ? { codeDescription: { href: entry.diagnostic.docsUrl } } : {},
65
+ message: entry.diagnostic.message + (entry.guidance ? `
66
+ ${entry.guidance}` : ""),
67
+ data: { format: 1, ...entry }
68
+ }));
69
+ }
70
+ export {
71
+ createDiagnosticReport,
72
+ toEditorDiagnostics
73
+ };
@@ -0,0 +1,6 @@
1
+ import * as ts from "@typescript/typescript6";
2
+ import type { SourceMigrationResult } from "./migrations";
3
+ import type { Diagnostic } from "./types";
4
+ /** Never replaces the root array helper in constructor/custom pipeline usages. */
5
+ export declare function migrateHttpProviderImports(source: string, fileName: string): SourceMigrationResult;
6
+ export declare function scanHttpProviderImports(source: ts.SourceFile, file: string): Diagnostic[];