@akal/supaforge 0.0.0-stage → 0.0.32

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 (97) hide show
  1. package/README.md +350 -2
  2. package/bin/dev.js +10 -0
  3. package/bin/run.js +18 -0
  4. package/dist/base-command.d.ts +135 -0
  5. package/dist/base-command.js +9 -0
  6. package/dist/base-command.js.map +1 -0
  7. package/dist/branch-C4ndfoj5.d.ts +58 -0
  8. package/dist/chunk-2SELREHW.js +156 -0
  9. package/dist/chunk-2SELREHW.js.map +1 -0
  10. package/dist/chunk-3HGAV5CC.js +2073 -0
  11. package/dist/chunk-3HGAV5CC.js.map +1 -0
  12. package/dist/chunk-4IVN7QVY.js +632 -0
  13. package/dist/chunk-4IVN7QVY.js.map +1 -0
  14. package/dist/chunk-6LJERPUN.js +499 -0
  15. package/dist/chunk-6LJERPUN.js.map +1 -0
  16. package/dist/chunk-6Q7MHFBM.js +13 -0
  17. package/dist/chunk-6Q7MHFBM.js.map +1 -0
  18. package/dist/chunk-6WAMNZLO.js +336 -0
  19. package/dist/chunk-6WAMNZLO.js.map +1 -0
  20. package/dist/chunk-7NAZGZPV.js +868 -0
  21. package/dist/chunk-7NAZGZPV.js.map +1 -0
  22. package/dist/chunk-BLKJWDTL.js +153 -0
  23. package/dist/chunk-BLKJWDTL.js.map +1 -0
  24. package/dist/chunk-BUOWHE36.js +1311 -0
  25. package/dist/chunk-BUOWHE36.js.map +1 -0
  26. package/dist/chunk-DMIWAJRB.js +602 -0
  27. package/dist/chunk-DMIWAJRB.js.map +1 -0
  28. package/dist/chunk-DQQ5E563.js +64 -0
  29. package/dist/chunk-DQQ5E563.js.map +1 -0
  30. package/dist/chunk-G2DIPIYU.js +94 -0
  31. package/dist/chunk-G2DIPIYU.js.map +1 -0
  32. package/dist/chunk-GEHPTPNZ.js +240 -0
  33. package/dist/chunk-GEHPTPNZ.js.map +1 -0
  34. package/dist/chunk-GZREXCQZ.js +207 -0
  35. package/dist/chunk-GZREXCQZ.js.map +1 -0
  36. package/dist/chunk-MIRLB5JM.js +1292 -0
  37. package/dist/chunk-MIRLB5JM.js.map +1 -0
  38. package/dist/chunk-NTUASFQ3.js +248 -0
  39. package/dist/chunk-NTUASFQ3.js.map +1 -0
  40. package/dist/chunk-ORQJVE57.js +642 -0
  41. package/dist/chunk-ORQJVE57.js.map +1 -0
  42. package/dist/chunk-SC2XHGIS.js +122 -0
  43. package/dist/chunk-SC2XHGIS.js.map +1 -0
  44. package/dist/chunk-SQPCWGQO.js +657 -0
  45. package/dist/chunk-SQPCWGQO.js.map +1 -0
  46. package/dist/chunk-UWAVXC57.js +916 -0
  47. package/dist/chunk-UWAVXC57.js.map +1 -0
  48. package/dist/commands/clone.d.ts +66 -0
  49. package/dist/commands/clone.js +416 -0
  50. package/dist/commands/clone.js.map +1 -0
  51. package/dist/commands/diff.d.ts +81 -0
  52. package/dist/commands/diff.js +23 -0
  53. package/dist/commands/diff.js.map +1 -0
  54. package/dist/commands/help.d.ts +32 -0
  55. package/dist/commands/help.js +36 -0
  56. package/dist/commands/help.js.map +1 -0
  57. package/dist/commands/hukam.d.ts +13 -0
  58. package/dist/commands/hukam.js +28 -0
  59. package/dist/commands/hukam.js.map +1 -0
  60. package/dist/commands/init.d.ts +47 -0
  61. package/dist/commands/init.js +388 -0
  62. package/dist/commands/init.js.map +1 -0
  63. package/dist/commands/mcp.d.ts +13 -0
  64. package/dist/commands/mcp.js +43 -0
  65. package/dist/commands/mcp.js.map +1 -0
  66. package/dist/commands/migrate/baseline.d.ts +24 -0
  67. package/dist/commands/migrate/baseline.js +69 -0
  68. package/dist/commands/migrate/baseline.js.map +1 -0
  69. package/dist/commands/migrate/create.d.ts +36 -0
  70. package/dist/commands/migrate/create.js +127 -0
  71. package/dist/commands/migrate/create.js.map +1 -0
  72. package/dist/commands/migrate/list.d.ts +23 -0
  73. package/dist/commands/migrate/list.js +110 -0
  74. package/dist/commands/migrate/list.js.map +1 -0
  75. package/dist/commands/migrate/run.d.ts +61 -0
  76. package/dist/commands/migrate/run.js +18 -0
  77. package/dist/commands/migrate/run.js.map +1 -0
  78. package/dist/commands/report.d.ts +27 -0
  79. package/dist/commands/report.js +210 -0
  80. package/dist/commands/report.js.map +1 -0
  81. package/dist/commands/restore.d.ts +26 -0
  82. package/dist/commands/restore.js +266 -0
  83. package/dist/commands/restore.js.map +1 -0
  84. package/dist/commands/snapshot.d.ts +33 -0
  85. package/dist/commands/snapshot.js +249 -0
  86. package/dist/commands/snapshot.js.map +1 -0
  87. package/dist/commands/sync.d.ts +16 -0
  88. package/dist/commands/sync.js +38 -0
  89. package/dist/commands/sync.js.map +1 -0
  90. package/dist/config-CTbeRlJk.d.ts +134 -0
  91. package/dist/help.d.ts +28 -0
  92. package/dist/help.js +64 -0
  93. package/dist/help.js.map +1 -0
  94. package/dist/index.d.ts +498 -0
  95. package/dist/index.js +147 -0
  96. package/dist/index.js.map +1 -0
  97. package/package.json +74 -4
@@ -0,0 +1,498 @@
1
+ import { E as EnvironmentConfig, S as SupaForgeConfig, a as SnapshotManifest, M as MigrationFile } from './config-CTbeRlJk.js';
2
+ export { C as ChecksConfig, b as MigrationAction, c as SnapshotLayerInfo } from './config-CTbeRlJk.js';
3
+ export { B as BRANCH_DB_PREFIX, a as BranchMeta, b as BranchesManifest, C as CreateBranchOptions, c as branchDbName, d as createBranch, e as deleteBranch, l as listBranches, f as loadManifest, r as replaceDbName } from './branch-C4ndfoj5.js';
4
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
5
+
6
+ /**
7
+ * Lightweight hook bus for SupaForge extensibility.
8
+ * Provides actions (fire-and-forget) and filters (transform pipeline) with priority ordering.
9
+ */
10
+ type Listener = (...args: any[]) => unknown | Promise<unknown>;
11
+ type FilterFn<T = any> = (value: T, ...args: any[]) => T | Promise<T>;
12
+ declare class HookBus {
13
+ private actions;
14
+ private filters;
15
+ on(hook: string, fn: Listener, priority?: number): () => void;
16
+ emit(hook: string, ...args: unknown[]): Promise<void>;
17
+ addFilter<T>(hook: string, fn: FilterFn<T>, priority?: number): () => void;
18
+ applyFilter<T>(hook: string, value: T, ...args: unknown[]): Promise<T>;
19
+ clear(): void;
20
+ }
21
+
22
+ declare const CHECK_NAMES: readonly ["schema", "rls", "rls-coverage", "edge-functions", "storage", "auth", "cron", "data", "webhooks", "realtime", "vault", "extensions", "migrations", "roles"];
23
+ type CheckName = (typeof CHECK_NAMES)[number];
24
+ type Severity = 'critical' | 'warning' | 'info';
25
+ declare const CHECK_META: Record<CheckName, {
26
+ number: number;
27
+ emoji: string;
28
+ label: string;
29
+ }>;
30
+ /** API-based sync action for non-SQL drift fixes. */
31
+ interface SyncAction {
32
+ /** HTTP method */
33
+ method: 'POST' | 'PUT' | 'PATCH' | 'DELETE';
34
+ /** Full URL (resolved at scan time, using target projectRef). */
35
+ url: string;
36
+ /** Request headers (Authorization injected by promote). */
37
+ headers?: Record<string, string>;
38
+ /** JSON body to send. */
39
+ body?: unknown;
40
+ /** Human-readable description of what this action does. */
41
+ label: string;
42
+ }
43
+ interface DriftIssue {
44
+ id: string;
45
+ check: CheckName;
46
+ severity: Severity;
47
+ title: string;
48
+ description: string;
49
+ sourceValue?: unknown;
50
+ targetValue?: unknown;
51
+ sql?: {
52
+ up: string;
53
+ down: string;
54
+ };
55
+ /** API-based sync action (for non-SQL fixes like storage buckets, auth config, edge functions). */
56
+ action?: SyncAction;
57
+ /**
58
+ * Why this difference has no automatic fix, and what to do instead.
59
+ *
60
+ * For findings that are real but cannot be applied: a Vault secret whose
61
+ * value exists only in the source, an Edge Function that needs deploying.
62
+ * Set it rather than inventing SQL — the vault check used to emit
63
+ * `vault.create_secret('PLACEHOLDER_VALUE', …)`, and `--apply` ran it, which
64
+ * left the target holding a live secret with a bogus value (issue #91).
65
+ *
66
+ * Reported as the skip reason at apply time, so the user is told the command
67
+ * instead of being told there is nothing to be done.
68
+ */
69
+ manualOnly?: string;
70
+ /**
71
+ * Why this fix waits for --allow-destructive, when that isn't visible from
72
+ * its SQL: a webhook is a trigger, and dropping a trigger usually isn't.
73
+ */
74
+ destructive?: string;
75
+ }
76
+ interface CheckResult {
77
+ check: CheckName;
78
+ status: 'clean' | 'drifted' | 'error' | 'skipped';
79
+ issues: DriftIssue[];
80
+ error?: string;
81
+ /**
82
+ * Why the check declined to run — missing credentials, an absent extension,
83
+ * nothing configured to compare.
84
+ *
85
+ * Present only when status is 'skipped'. Without it a skipped layer was
86
+ * indistinguishable from a clean one in both the terminal output and the
87
+ * JSON payload (issue #42).
88
+ */
89
+ skipReason?: string;
90
+ /**
91
+ * Findings left out because another check reports the same object — the
92
+ * schema check's policy findings where the RLS check has them (issue #97),
93
+ * its extension findings where the extensions check has them. Counted so
94
+ * the difference from the live progress line is explained.
95
+ */
96
+ folded?: Array<{
97
+ count: number;
98
+ into: CheckName;
99
+ }>;
100
+ durationMs: number;
101
+ }
102
+ interface ScanResult {
103
+ timestamp: string;
104
+ source: string;
105
+ target: string;
106
+ checks: CheckResult[];
107
+ /**
108
+ * How closely the two environments match, 0–100, over the comparison checks
109
+ * only. Posture findings are excluded so a genuinely synchronised pair can
110
+ * reach 100 even when it carries pre-existing findings on both sides.
111
+ */
112
+ score: number;
113
+ /**
114
+ * The target's own security and tracking posture, 0–100, over the posture
115
+ * checks only. `null` when none of them ran.
116
+ */
117
+ postureScore: number | null;
118
+ summary: {
119
+ total: number;
120
+ critical: number;
121
+ warning: number;
122
+ info: number;
123
+ };
124
+ }
125
+
126
+ /**
127
+ * Which tables a diff should look at.
128
+ *
129
+ * Empty/undefined means "everything", which is the default and what every
130
+ * existing caller gets. Patterns are passed to @dbdiff/cli verbatim, so its
131
+ * glob support (`*`, `?`) works here too.
132
+ */
133
+ interface TableFilter {
134
+ /** Only compare these. Undefined means all. */
135
+ tables?: string[];
136
+ /** Never compare these. Applied after `tables`. */
137
+ excludeTables?: string[];
138
+ }
139
+
140
+ interface CheckContext {
141
+ /**
142
+ * Which tables this run is scoped to, resolved from `checks.tables` /
143
+ * `checks.excludeTables` and the `--tables` / `--exclude-tables` flags.
144
+ *
145
+ * Only the schema and data layers act on it — they are the ones backed by
146
+ * @dbdiff/cli, which is where the table concept exists (issue #43). Absent
147
+ * or empty means every table, which is the default.
148
+ */
149
+ tableFilter?: TableFilter;
150
+ /**
151
+ * Optional sink for sub-check progress, e.g. the table counter emitted
152
+ * during a long schema diff (issue #29). Checks that have nothing
153
+ * fine-grained to report simply ignore it.
154
+ */
155
+ onDetail?: (detail: string) => void;
156
+ source: EnvironmentConfig;
157
+ target: EnvironmentConfig;
158
+ config: SupaForgeConfig;
159
+ }
160
+ declare abstract class Check {
161
+ abstract readonly name: CheckName;
162
+ abstract scan(ctx: CheckContext): Promise<DriftIssue[]>;
163
+ }
164
+
165
+ declare class CheckRegistry {
166
+ private checks;
167
+ register(check: Check): void;
168
+ get(name: CheckName): Check | undefined;
169
+ all(): Check[];
170
+ has(name: CheckName): boolean;
171
+ }
172
+
173
+ type ScanProgressEvent = {
174
+ phase: 'check:start';
175
+ check: CheckName;
176
+ index: number;
177
+ total: number;
178
+ } | {
179
+ phase: 'check:done';
180
+ check: CheckName;
181
+ index: number;
182
+ total: number;
183
+ status: CheckResult['status'];
184
+ issueCount: number;
185
+ durationMs: number;
186
+ skipReason?: string;
187
+ };
188
+ interface ScanOptions {
189
+ config: SupaForgeConfig;
190
+ /** Whitelist: only run these checks. Defaults to all checks. */
191
+ checks?: CheckName[];
192
+ /** Blacklist: skip these checks (CLI --skip flag). Merged with config.checks.exclude. */
193
+ skip?: CheckName[];
194
+ onProgress?: (event: ScanProgressEvent) => void;
195
+ /** Fine-grained progress from within a single check, e.g. "42 tables · users". */
196
+ onDetail?: (check: CheckName, detail: string) => void;
197
+ /**
198
+ * Scope the schema and data comparisons to a subset of tables (issue #43).
199
+ * Merged with the config's own `checks.tables` / `checks.excludeTables`.
200
+ */
201
+ tableFilter?: TableFilter;
202
+ }
203
+ declare function scan(registry: CheckRegistry, options: ScanOptions, bus?: HookBus): Promise<ScanResult>;
204
+
205
+ declare function loadConfig(cwd?: string): Promise<SupaForgeConfig>;
206
+ declare function resolveConfig(config: SupaForgeConfig): SupaForgeConfig;
207
+ declare function validateConfig(config: SupaForgeConfig): string[];
208
+ /**
209
+ * Validate config for single-environment operations (snapshot, clone, backup, restore).
210
+ * Only requires that the specified environment exists and has a dbUrl.
211
+ */
212
+ declare function validateSingleEnvConfig(config: SupaForgeConfig, envName: string): string[];
213
+
214
+ type QueryFn = (dbUrl: string, sql: string, params?: unknown[]) => Promise<Record<string, unknown>[]>;
215
+
216
+ interface RegistryOptions {
217
+ /** Enable file-level drift detection in the storage check. */
218
+ includeFiles?: boolean;
219
+ }
220
+ declare function createDefaultRegistry(options?: RegistryOptions): CheckRegistry;
221
+
222
+ declare function summarize(results: CheckResult[]): {
223
+ total: number;
224
+ critical: number;
225
+ warning: number;
226
+ info: number;
227
+ };
228
+ /**
229
+ * Compute the drift score, 0–100.
230
+ *
231
+ * 100 = the two environments match. Critical issues penalise heavily, and an
232
+ * errored check also penalises — we can't confirm that layer is clean.
233
+ *
234
+ * Counts the comparison checks only. RLS Coverage and Migration History report
235
+ * on the target's own posture and fire identically whichever pair you diff, so
236
+ * including them meant a diff of an environment against *itself* could never
237
+ * reach 100 (issue #40). A project with any long-standing RLS gap scored 0 no
238
+ * matter how well synchronised its environments were, which made the number
239
+ * useless as a sync signal. Those findings are scored separately by
240
+ * computePostureScore — they are not discarded.
241
+ */
242
+ declare function computeScore(results: CheckResult[]): number;
243
+
244
+ declare function renderSummary(result: ScanResult): string;
245
+ declare function renderDetailed(result: ScanResult): string;
246
+
247
+ type FetchFn$2 = (url: string, init?: RequestInit) => Promise<Response>;
248
+ interface PromoteOptions {
249
+ /** Target database connection string */
250
+ dbUrl: string;
251
+ /** The scan result with SQL fixes to apply */
252
+ scanResult: ScanResult;
253
+ /** Only promote specific checks */
254
+ checks?: string[];
255
+ /** Also apply posture fixes; off by default — see planWork */
256
+ applyPosture?: boolean;
257
+ /** Dry-run mode — print SQL without executing */
258
+ dryRun?: boolean;
259
+ /**
260
+ * Permit statements that destroy data (DROP TABLE, DROP COLUMN).
261
+ *
262
+ * Off by default: those are reported as drift but skipped at apply time, so
263
+ * `supaforge diff --apply` can never drop a table or column without the user
264
+ * asking for it. Set by the `--allow-destructive` flag.
265
+ */
266
+ allowDestructive?: boolean;
267
+ /**
268
+ * The table scope the diff ran under.
269
+ *
270
+ * Needed at apply time as well as scan time. `--tables` reaches dbdiff, which
271
+ * scopes *tables* only, so a narrowed fix set still arrives carrying the
272
+ * views, triggers and indexes that hang off the tables it excluded. Applying
273
+ * those fails, because the column or table they need was deliberately not
274
+ * added (issue #48).
275
+ */
276
+ tableFilter?: TableFilter;
277
+ /**
278
+ * Apply only these issues, by id. Globs allowed. Undefined means all.
279
+ *
280
+ * Every issue in `--json` already carries a stable id, so a review step can
281
+ * pick a subset out of one diff and apply exactly that, with no new matching
282
+ * syntax to learn.
283
+ */
284
+ only?: string[];
285
+ /**
286
+ * Run every SQL fix in one transaction, rolling the whole set back if any
287
+ * statement fails. On by default — see `executeSql`.
288
+ */
289
+ transactional?: boolean;
290
+ /** Fetch function for API-based sync actions (defaults to globalThis.fetch) */
291
+ fetchFn?: FetchFn$2;
292
+ }
293
+ /** Where a fix came from: which check reported it, and under which issue id. */
294
+ interface FixOrigin {
295
+ check: string;
296
+ issueId: string;
297
+ }
298
+ type PlannedSkip = FixOrigin & {
299
+ reason: string;
300
+ };
301
+ interface PromoteResult {
302
+ applied: (FixOrigin & {
303
+ sql?: string;
304
+ action?: string;
305
+ })[];
306
+ skipped: PlannedSkip[];
307
+ errors: (FixOrigin & {
308
+ error: string;
309
+ })[];
310
+ /**
311
+ * Fixes that ran and were then undone because a later statement in the same
312
+ * transaction failed. Reported separately from `applied`, which only ever
313
+ * lists what is actually in the target now.
314
+ */
315
+ rolledBack?: (FixOrigin & {
316
+ sql?: string;
317
+ })[];
318
+ }
319
+ declare function promote(options: PromoteOptions): Promise<PromoteResult>;
320
+
321
+ type FetchFn$1 = (url: string, init?: RequestInit) => Promise<Response>;
322
+ interface SnapshotOptions {
323
+ envName: string;
324
+ env: EnvironmentConfig;
325
+ config: SupaForgeConfig;
326
+ /** Base output directory (defaults to cwd) */
327
+ cwd?: string;
328
+ /** Custom output directory — snapshot files are written here directly (with timestamp subfolder). */
329
+ outputDir?: string;
330
+ queryFn?: QueryFn;
331
+ fetchFn?: FetchFn$1;
332
+ }
333
+ interface SnapshotResult {
334
+ manifest: SnapshotManifest;
335
+ dir: string;
336
+ timestamp: string;
337
+ }
338
+ /**
339
+ * Capture a full snapshot of a single Supabase environment.
340
+ * Each layer is exported independently; failures in one layer don't block others.
341
+ */
342
+ declare function captureSnapshot(options: SnapshotOptions): Promise<SnapshotResult>;
343
+ /** Load the manifest from a snapshot directory. */
344
+ declare function loadSnapshot(dir: string): Promise<SnapshotManifest>;
345
+ /** Find the latest snapshot directory. */
346
+ declare function findLatestSnapshot(cwd?: string): Promise<string | null>;
347
+ /** List all snapshot directories with their manifests. */
348
+ declare function listSnapshots(cwd?: string): Promise<{
349
+ dir: string;
350
+ manifest: SnapshotManifest;
351
+ }[]>;
352
+
353
+ interface BackupOptions extends Omit<SnapshotOptions, 'cwd'> {
354
+ cwd?: string;
355
+ description?: string;
356
+ }
357
+ interface BackupResult {
358
+ snapshot: SnapshotResult;
359
+ migration: MigrationFile | null;
360
+ migrationFile: string | null;
361
+ /** True if this is the first snapshot (baseline, no diff possible). */
362
+ isBaseline: boolean;
363
+ }
364
+ /**
365
+ * Create a backup: capture a new snapshot and generate a migration file
366
+ * containing the diff against the previous snapshot.
367
+ *
368
+ * If no previous snapshot exists, the migration is a "baseline" containing
369
+ * the full state.
370
+ */
371
+ declare function backup(options: BackupOptions): Promise<BackupResult>;
372
+ /** Load all migration files in timestamp order. */
373
+ declare function loadMigrations(cwd?: string): Promise<MigrationFile[]>;
374
+ /** List migration files with metadata. */
375
+ declare function listMigrationFiles(cwd?: string): Promise<{
376
+ file: string;
377
+ version: string;
378
+ description: string;
379
+ layers: string[];
380
+ }[]>;
381
+
382
+ type FetchFn = (url: string, init?: RequestInit) => Promise<Response>;
383
+ interface RestoreOptions {
384
+ /** Target database URL to restore into. */
385
+ targetUrl: string;
386
+ /** Project ref for API-based operations (auth, storage, edge functions). */
387
+ targetProjectRef?: string;
388
+ /** Access token for Supabase Management API. */
389
+ targetAccessToken?: string;
390
+ /** Restore from a specific snapshot directory. */
391
+ snapshotDir?: string;
392
+ /** Or restore from migrations up to a specific version. */
393
+ toVersion?: string;
394
+ /** Starting version (skip migrations before this). */
395
+ fromVersion?: string;
396
+ /** Working directory for .supaforge/ */
397
+ cwd?: string;
398
+ /** Query function for DB operations. */
399
+ queryFn?: QueryFn;
400
+ /** Fetch function for API operations. */
401
+ fetchFn?: FetchFn;
402
+ /**
403
+ * Apply each statement on its own, keeping whatever succeeds.
404
+ *
405
+ * Off by default. A restore used to run this way always, so a failure part
406
+ * way through left a half-restored database and the errors were listed only
407
+ * at the end (issue #95). PostgreSQL has transactional DDL, so the whole
408
+ * restore now succeeds or leaves the target exactly as it was.
409
+ */
410
+ noTransaction?: boolean;
411
+ /**
412
+ * Drop the schemas the snapshot covers before replaying into them.
413
+ *
414
+ * What `--force` now means. It used to only skip the "target is not empty"
415
+ * check, so restoring over an existing database failed on every object that
416
+ * was already there and replaced nothing (issue #95).
417
+ */
418
+ replace?: boolean;
419
+ }
420
+ interface RestoreResult {
421
+ applied: {
422
+ type: 'sql' | 'api';
423
+ label: string;
424
+ }[];
425
+ skipped: {
426
+ type: 'sql' | 'api';
427
+ label: string;
428
+ reason: string;
429
+ }[];
430
+ errors: {
431
+ type: 'sql' | 'api';
432
+ label: string;
433
+ error: string;
434
+ }[];
435
+ mode: 'snapshot' | 'migrations';
436
+ /**
437
+ * Objects of the snapshot left out because they need something this target
438
+ * cannot have — an extension it does not ship, a Supabase schema it lacks —
439
+ * listed in `skipped`. The rest was restored; the copy is not complete.
440
+ */
441
+ incomplete?: boolean;
442
+ /**
443
+ * Statements that ran and were then rolled back, when the restore was
444
+ * transactional and something failed.
445
+ *
446
+ * Reported apart from `applied`, which is emptied: a restore that rolled
447
+ * back applied nothing, and saying it applied 60 operations would be the
448
+ * most misleading thing this command could tell anyone (issue #95).
449
+ */
450
+ rolledBack?: {
451
+ type: 'sql' | 'api';
452
+ label: string;
453
+ }[];
454
+ }
455
+ /**
456
+ * Restore a Supabase environment from a snapshot directory.
457
+ * Applies all SQL files (schema, RLS, cron, webhooks, extensions, data).
458
+ * API layers (auth, storage buckets, edge functions) log what would need manual action.
459
+ */
460
+ declare function restoreFromSnapshot(options: RestoreOptions): Promise<RestoreResult>;
461
+ /**
462
+ * Restore by replaying migration files in order.
463
+ * Tracks applied migrations in a `_supaforge_migrations` table.
464
+ */
465
+ declare function restoreFromMigrations(options: RestoreOptions): Promise<RestoreResult>;
466
+ /** Preview what a snapshot restore would apply (no DB connection required). */
467
+ declare function previewSnapshotRestore(snapshotDir: string): Promise<{
468
+ layer: string;
469
+ statements: string[];
470
+ }[]>;
471
+ /** Preview what migration restore would apply. */
472
+ declare function previewMigrationRestore(cwd?: string, toVersion?: string, fromVersion?: string): Promise<MigrationFile[]>;
473
+
474
+ /**
475
+ * Create and configure the SupaForge MCP server.
476
+ *
477
+ * @param cwd - Working directory to resolve config files from (defaults to process.cwd())
478
+ */
479
+ interface ServerOptions {
480
+ /**
481
+ * Honour a `configPath` argument from the client.
482
+ *
483
+ * Off by default. Every tool accepted an arbitrary path and resolved its
484
+ * working directory from it, so a tool call — or a prompt injected into one —
485
+ * could point the server at any `supaforge.config.json` on disk, including
486
+ * one holding production credentials, bypassing the config the server was
487
+ * started with (issue #96). Enabled with `supaforge mcp --allow-config-path`
488
+ * for the case where an agent legitimately manages several projects.
489
+ */
490
+ allowConfigPath?: boolean;
491
+ }
492
+ declare function createServer(cwd?: string, options?: ServerOptions): McpServer;
493
+
494
+ declare function setLastScanResult(result: ScanResult): void;
495
+ declare function getLastScanResult(): ScanResult | null;
496
+ declare function clearLastScanResult(): void;
497
+
498
+ export { CHECK_META, CHECK_NAMES, Check, type CheckName, CheckRegistry, type CheckResult, type DriftIssue, EnvironmentConfig, HookBus, MigrationFile, type ScanResult, type Severity, SnapshotManifest, SupaForgeConfig, type SyncAction, backup, captureSnapshot, clearLastScanResult, computeScore, createDefaultRegistry, createServer, findLatestSnapshot, getLastScanResult, listMigrationFiles, listSnapshots, loadConfig, loadMigrations, loadSnapshot, previewMigrationRestore, previewSnapshotRestore, promote, renderDetailed, renderSummary, resolveConfig, restoreFromMigrations, restoreFromSnapshot, scan, setLastScanResult, summarize, validateConfig, validateSingleEnvConfig };
package/dist/index.js ADDED
@@ -0,0 +1,147 @@
1
+ import {
2
+ clearLastScanResult,
3
+ createServer,
4
+ getLastScanResult,
5
+ setLastScanResult
6
+ } from "./chunk-6LJERPUN.js";
7
+ import {
8
+ previewMigrationRestore,
9
+ previewSnapshotRestore,
10
+ restoreFromMigrations,
11
+ restoreFromSnapshot
12
+ } from "./chunk-7NAZGZPV.js";
13
+ import {
14
+ backup,
15
+ listMigrationFiles,
16
+ loadMigrations
17
+ } from "./chunk-NTUASFQ3.js";
18
+ import "./chunk-SC2XHGIS.js";
19
+ import {
20
+ renderDetailed,
21
+ renderSummary
22
+ } from "./chunk-GEHPTPNZ.js";
23
+ import {
24
+ CheckRegistry,
25
+ computeScore,
26
+ createDefaultRegistry,
27
+ scan,
28
+ summarize
29
+ } from "./chunk-3HGAV5CC.js";
30
+ import "./chunk-DMIWAJRB.js";
31
+ import {
32
+ CHECK_META,
33
+ CHECK_NAMES,
34
+ promote
35
+ } from "./chunk-UWAVXC57.js";
36
+ import "./chunk-BUOWHE36.js";
37
+ import "./chunk-G2DIPIYU.js";
38
+ import {
39
+ BRANCH_DB_PREFIX,
40
+ branchDbName,
41
+ createBranch,
42
+ deleteBranch,
43
+ listBranches,
44
+ loadManifest,
45
+ replaceDbName
46
+ } from "./chunk-ORQJVE57.js";
47
+ import {
48
+ captureSnapshot,
49
+ findLatestSnapshot,
50
+ listSnapshots,
51
+ loadSnapshot
52
+ } from "./chunk-MIRLB5JM.js";
53
+ import "./chunk-DQQ5E563.js";
54
+ import {
55
+ Check
56
+ } from "./chunk-SQPCWGQO.js";
57
+ import {
58
+ loadConfig,
59
+ resolveConfig,
60
+ validateConfig,
61
+ validateSingleEnvConfig
62
+ } from "./chunk-6WAMNZLO.js";
63
+
64
+ // src/hooks.ts
65
+ var HookBus = class {
66
+ actions = /* @__PURE__ */ new Map();
67
+ filters = /* @__PURE__ */ new Map();
68
+ on(hook, fn, priority = 10) {
69
+ const bucket = this.actions.get(hook) ?? [];
70
+ const entry = { fn, priority };
71
+ bucket.push(entry);
72
+ bucket.sort((a, b) => a.priority - b.priority);
73
+ this.actions.set(hook, bucket);
74
+ return () => {
75
+ const b = this.actions.get(hook);
76
+ if (b) this.actions.set(hook, b.filter((e) => e !== entry));
77
+ };
78
+ }
79
+ async emit(hook, ...args) {
80
+ for (const entry of this.actions.get(hook) ?? []) {
81
+ await entry.fn(...args);
82
+ }
83
+ }
84
+ addFilter(hook, fn, priority = 10) {
85
+ const bucket = this.filters.get(hook) ?? [];
86
+ const entry = { fn, priority };
87
+ bucket.push(entry);
88
+ bucket.sort((a, b) => a.priority - b.priority);
89
+ this.filters.set(hook, bucket);
90
+ return () => {
91
+ const b = this.filters.get(hook);
92
+ if (b) this.filters.set(hook, b.filter((e) => e !== entry));
93
+ };
94
+ }
95
+ async applyFilter(hook, value, ...args) {
96
+ let result = value;
97
+ for (const entry of this.filters.get(hook) ?? []) {
98
+ result = await entry.fn(result, ...args);
99
+ }
100
+ return result;
101
+ }
102
+ clear() {
103
+ this.actions.clear();
104
+ this.filters.clear();
105
+ }
106
+ };
107
+ export {
108
+ BRANCH_DB_PREFIX,
109
+ CHECK_META,
110
+ CHECK_NAMES,
111
+ Check,
112
+ CheckRegistry,
113
+ HookBus,
114
+ backup,
115
+ branchDbName,
116
+ captureSnapshot,
117
+ clearLastScanResult,
118
+ computeScore,
119
+ createBranch,
120
+ createDefaultRegistry,
121
+ createServer,
122
+ deleteBranch,
123
+ findLatestSnapshot,
124
+ getLastScanResult,
125
+ listBranches,
126
+ listMigrationFiles,
127
+ listSnapshots,
128
+ loadConfig,
129
+ loadManifest,
130
+ loadMigrations,
131
+ loadSnapshot,
132
+ previewMigrationRestore,
133
+ previewSnapshotRestore,
134
+ promote,
135
+ renderDetailed,
136
+ renderSummary,
137
+ replaceDbName,
138
+ resolveConfig,
139
+ restoreFromMigrations,
140
+ restoreFromSnapshot,
141
+ scan,
142
+ setLastScanResult,
143
+ summarize,
144
+ validateConfig,
145
+ validateSingleEnvConfig
146
+ };
147
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks.ts"],"sourcesContent":["/**\n * Lightweight hook bus for SupaForge extensibility.\n * Provides actions (fire-and-forget) and filters (transform pipeline) with priority ordering.\n */\n\ntype Listener = (...args: any[]) => unknown | Promise<unknown>\ntype FilterFn<T = any> = (value: T, ...args: any[]) => T | Promise<T>\n\ninterface Entry { fn: Listener; priority: number }\n\nexport class HookBus {\n private actions = new Map<string, Entry[]>()\n private filters = new Map<string, Entry[]>()\n\n on(hook: string, fn: Listener, priority = 10): () => void {\n const bucket = this.actions.get(hook) ?? []\n const entry = { fn, priority }\n bucket.push(entry)\n bucket.sort((a, b) => a.priority - b.priority)\n this.actions.set(hook, bucket)\n return () => {\n const b = this.actions.get(hook)\n if (b) this.actions.set(hook, b.filter(e => e !== entry))\n }\n }\n\n async emit(hook: string, ...args: unknown[]): Promise<void> {\n for (const entry of this.actions.get(hook) ?? []) {\n await entry.fn(...args)\n }\n }\n\n addFilter<T>(hook: string, fn: FilterFn<T>, priority = 10): () => void {\n const bucket = this.filters.get(hook) ?? []\n const entry: Entry = { fn: fn as Listener, priority }\n bucket.push(entry)\n bucket.sort((a, b) => a.priority - b.priority)\n this.filters.set(hook, bucket)\n return () => {\n const b = this.filters.get(hook)\n if (b) this.filters.set(hook, b.filter(e => e !== entry))\n }\n }\n\n async applyFilter<T>(hook: string, value: T, ...args: unknown[]): Promise<T> {\n let result = value\n for (const entry of this.filters.get(hook) ?? []) {\n result = await (entry.fn as FilterFn<T>)(result, ...args)\n }\n return result\n }\n\n clear(): void {\n this.actions.clear()\n this.filters.clear()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUO,IAAM,UAAN,MAAc;AAAA,EACX,UAAU,oBAAI,IAAqB;AAAA,EACnC,UAAU,oBAAI,IAAqB;AAAA,EAE3C,GAAG,MAAc,IAAc,WAAW,IAAgB;AACxD,UAAM,SAAS,KAAK,QAAQ,IAAI,IAAI,KAAK,CAAC;AAC1C,UAAM,QAAQ,EAAE,IAAI,SAAS;AAC7B,WAAO,KAAK,KAAK;AACjB,WAAO,KAAK,CAAC,GAAG,MAAM,EAAE,WAAW,EAAE,QAAQ;AAC7C,SAAK,QAAQ,IAAI,MAAM,MAAM;AAC7B,WAAO,MAAM;AACX,YAAM,IAAI,KAAK,QAAQ,IAAI,IAAI;AAC/B,UAAI,EAAG,MAAK,QAAQ,IAAI,MAAM,EAAE,OAAO,OAAK,MAAM,KAAK,CAAC;AAAA,IAC1D;AAAA,EACF;AAAA,EAEA,MAAM,KAAK,SAAiB,MAAgC;AAC1D,eAAW,SAAS,KAAK,QAAQ,IAAI,IAAI,KAAK,CAAC,GAAG;AAChD,YAAM,MAAM,GAAG,GAAG,IAAI;AAAA,IACxB;AAAA,EACF;AAAA,EAEA,UAAa,MAAc,IAAiB,WAAW,IAAgB;AACrE,UAAM,SAAS,KAAK,QAAQ,IAAI,IAAI,KAAK,CAAC;AAC1C,UAAM,QAAe,EAAE,IAAoB,SAAS;AACpD,WAAO,KAAK,KAAK;AACjB,WAAO,KAAK,CAAC,GAAG,MAAM,EAAE,WAAW,EAAE,QAAQ;AAC7C,SAAK,QAAQ,IAAI,MAAM,MAAM;AAC7B,WAAO,MAAM;AACX,YAAM,IAAI,KAAK,QAAQ,IAAI,IAAI;AAC/B,UAAI,EAAG,MAAK,QAAQ,IAAI,MAAM,EAAE,OAAO,OAAK,MAAM,KAAK,CAAC;AAAA,IAC1D;AAAA,EACF;AAAA,EAEA,MAAM,YAAe,MAAc,UAAa,MAA6B;AAC3E,QAAI,SAAS;AACb,eAAW,SAAS,KAAK,QAAQ,IAAI,IAAI,KAAK,CAAC,GAAG;AAChD,eAAS,MAAO,MAAM,GAAmB,QAAQ,GAAG,IAAI;AAAA,IAC1D;AACA,WAAO;AAAA,EACT;AAAA,EAEA,QAAc;AACZ,SAAK,QAAQ,MAAM;AACnB,SAAK,QAAQ,MAAM;AAAA,EACrB;AACF;","names":[]}