symmetria-kit 1.0.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,372 @@
1
+ import { Driver } from "symmetria/driver";
2
+ import { CheckSnapshot, CompiledQuery, IndexSnapshot, QueryExecutor, SchemaSnapshot } from "symmetria";
3
+ //#region src/migrations/snapshot.d.ts
4
+ type MigrationColumn = {
5
+ name: string;
6
+ sqlType: string;
7
+ enumeration?: string;
8
+ notNull: boolean;
9
+ unique: boolean;
10
+ identity: boolean;
11
+ default?: string;
12
+ references?: {
13
+ table: string;
14
+ column: string;
15
+ onDelete: string;
16
+ };
17
+ };
18
+ type MigrationTable = {
19
+ name: string;
20
+ columns: MigrationColumn[];
21
+ primaryKey: string[];
22
+ indexes: IndexSnapshot[];
23
+ checks?: CheckSnapshot[];
24
+ };
25
+ type MigrationSnapshot = {
26
+ version: 1;
27
+ dialect: "postgresql";
28
+ tables: MigrationTable[];
29
+ enumerations: {
30
+ name: string;
31
+ values: string[];
32
+ }[];
33
+ /** Extensions created before any other DDL; absent when none are declared. */
34
+ extensions?: string[];
35
+ };
36
+ export declare const emptySnapshot: () => MigrationSnapshot;
37
+ export declare const migrationSnapshot: (schema: SchemaSnapshot) => MigrationSnapshot;
38
+ /** Validate persisted snapshots before diffing. SQL expressions remain author-owned SQL. */
39
+ export declare const parseMigrationSnapshot: (input: unknown) => MigrationSnapshot;
40
+ export declare const snapshotHash: (snapshot: MigrationSnapshot) => string;
41
+ //#endregion
42
+ //#region src/migrations/diff.d.ts
43
+ type RenameHints = {
44
+ /** Physical SQL names: old table -> new table. */
45
+ readonly tables?: Readonly<Record<string, string>>;
46
+ /** Keyed by the NEW table name: old column -> new column. */
47
+ readonly columns?: Readonly<Record<string, Readonly<Record<string, string>>>>;
48
+ };
49
+ type MigrationDiffOptions = {
50
+ /** Generate concurrent indexes, phased constraint validation and enum additions. Requires nontransactional execution. */
51
+ readonly online?: boolean;
52
+ readonly renames?: RenameHints;
53
+ /** SQL USING expressions, keyed by new table and column names. */
54
+ readonly using?: Readonly<Record<string, Readonly<Record<string, {
55
+ readonly up: string;
56
+ readonly down: string;
57
+ }>>>>;
58
+ };
59
+ type MigrationPlan = {
60
+ before: MigrationSnapshot;
61
+ after: MigrationSnapshot;
62
+ up: string[];
63
+ down: string[];
64
+ };
65
+ export declare const diffSchemas: (previous: SchemaSnapshot | MigrationSnapshot, next: SchemaSnapshot | MigrationSnapshot, options?: MigrationDiffOptions) => MigrationPlan;
66
+ export declare const createSchemaSQL: (snapshot: SchemaSnapshot | MigrationSnapshot) => CompiledQuery[];
67
+ //#endregion
68
+ //#region src/migrations/files.d.ts
69
+ type MigrationManifest = {
70
+ version: 1;
71
+ id: string;
72
+ parent: string | null;
73
+ before: string;
74
+ after: string;
75
+ /** Omitted/batch preserves atomic execution of all pending transactional migrations. */
76
+ transaction?: "batch" | "each" | "none";
77
+ };
78
+ type Migration = {
79
+ id: string;
80
+ manifest: MigrationManifest;
81
+ up: string;
82
+ down: string;
83
+ checksum: string;
84
+ };
85
+ type GeneratedMigration = Migration & {
86
+ snapshot: MigrationSnapshot;
87
+ };
88
+ type MigrationState = {
89
+ migrations: Migration[];
90
+ snapshot: MigrationSnapshot;
91
+ };
92
+ type GenerateMigrationOptions = MigrationDiffOptions & {
93
+ directory: string;
94
+ name: string;
95
+ snapshot?: SchemaSnapshot | MigrationSnapshot;
96
+ empty?: boolean;
97
+ allowDestructive?: boolean;
98
+ transaction?: "batch" | "each" | "none";
99
+ };
100
+ type SquashMigrationsOptions = {
101
+ directory: string;
102
+ name: string;
103
+ };
104
+ /** One current schema snapshot and a compact journal for the entire SQL chain. */
105
+ export declare const loadMigrationState: (directory: string) => Promise<MigrationState>;
106
+ export declare const loadMigrations: (directory: string) => Promise<Migration[]>;
107
+ /** Replace the SQL chain and journal with a baseline for the current snapshot. */
108
+ export declare const squashMigrations: (options: SquashMigrationsOptions) => Promise<GeneratedMigration | null>;
109
+ /** SQL files are editable before application; applied checksums include both directions. */
110
+ export declare const generateMigration: (options: GenerateMigrationOptions) => Promise<GeneratedMigration | null>;
111
+ //#endregion
112
+ //#region src/migrations/lint.d.ts
113
+ /**
114
+ * destructive: data is lost or becomes unrepresentable (generation requires
115
+ * allowDestructive); blocking: the statement fails on existing data;
116
+ * caution: locks, rewrites or deploy-order hazards.
117
+ */
118
+ type LintLevel = "destructive" | "blocking" | "caution";
119
+ type LintFinding = {
120
+ readonly level: LintLevel;
121
+ readonly table: string;
122
+ readonly column?: string;
123
+ readonly message: string;
124
+ readonly advice: string;
125
+ };
126
+ /** Review a diff for operations that fail or lose data on a populated database. */
127
+ export declare const lintMigration: (plan: MigrationPlan, renames?: RenameHints) => LintFinding[];
128
+ export declare const formatLintFindings: (findings: readonly LintFinding[]) => string;
129
+ //#endregion
130
+ //#region src/migrations/sql-lint.d.ts
131
+ type SQLFinding = LintFinding & {
132
+ readonly statement: number;
133
+ };
134
+ /** Inspect the SQL that will execute, ignoring comments, strings and function bodies. */
135
+ export declare const lintMigrationSQL: (sql: string, name?: string) => SQLFinding[];
136
+ //#endregion
137
+ //#region src/migrations/execution.d.ts
138
+ type ExecutionOptions = {
139
+ advisoryLockTimeoutMs?: number;
140
+ lockTimeoutMs?: number;
141
+ statementTimeoutMs?: number;
142
+ signal?: AbortSignal;
143
+ onEvent?: (event: MigrationEvent) => void;
144
+ };
145
+ type MigrationEvent = {
146
+ type: "statement-start" | "statement-end" | "statement-error";
147
+ migration: string;
148
+ direction: "up" | "down";
149
+ statement: number;
150
+ sql: string;
151
+ durationMs?: number;
152
+ sqlState?: string;
153
+ };
154
+ type ExecutionStep = {
155
+ id: string;
156
+ transaction: "batch" | "each" | "none";
157
+ group: number;
158
+ statements: string[];
159
+ };
160
+ export declare class MigrationExecutionError extends Error {
161
+ readonly migration: string;
162
+ readonly direction: "up" | "down";
163
+ readonly statement: number;
164
+ readonly sql: string;
165
+ readonly sqlState: string | undefined;
166
+ constructor(migration: string, direction: "up" | "down", statement: number, sql: string, cause: unknown);
167
+ }
168
+ //#endregion
169
+ //#region src/migrations/verify.d.ts
170
+ type VerificationContext = {
171
+ driver: Driver;
172
+ migration: string;
173
+ phase: "up" | "down" | "reapply";
174
+ };
175
+ type VerifyOptions = ExecutionOptions & {
176
+ directory: string;
177
+ /** A connection with CREATEDB permission. Only newly created databases receive migration SQL. */
178
+ url: string;
179
+ schemaName?: string;
180
+ metadataSchema?: string;
181
+ metadataTable?: string;
182
+ beforeMigration?: (context: VerificationContext) => Promise<void>;
183
+ afterMigration?: (context: VerificationContext) => Promise<void>;
184
+ };
185
+ /** Exercise fresh installation, populated upgrades, rollback and reapplication on real PostgreSQL. */
186
+ export declare const verifyMigrations: (options: VerifyOptions) => Promise<{
187
+ migrations: string[];
188
+ verified: true;
189
+ }>;
190
+ //#endregion
191
+ //#region src/migrations/publication.d.ts
192
+ /** Recover a process crash without discarding a live writer or guessing at incomplete metadata. */
193
+ export declare const recoverMigrationFiles: (directory: string) => Promise<void>;
194
+ //#endregion
195
+ //#region src/migrations/drift.d.ts
196
+ type DriftKind = "missing-table" | "extra-table" | "missing-column" | "extra-column" | "type-mismatch" | "nullability-mismatch" | "default-mismatch" | "identity-mismatch" | "missing-constraint" | "extra-constraint" | "constraint-mismatch" | "invalid-constraint" | "missing-enum" | "extra-enum" | "enum-mismatch" | "invalid-index" | "missing-index" | "index-mismatch" | "extra-index" | "missing-extension";
197
+ type DriftFinding = {
198
+ readonly kind: DriftKind;
199
+ readonly table: string;
200
+ readonly column?: string;
201
+ readonly expected?: string;
202
+ readonly actual?: string;
203
+ };
204
+ type DriftOptions = {
205
+ readonly execute: QueryExecutor;
206
+ readonly snapshot: SchemaSnapshot | MigrationSnapshot;
207
+ /** Schema to inspect; defaults to the connection's current_schema(). */
208
+ readonly schemaName?: string;
209
+ /** Schema containing the migration journal; defaults to public. */
210
+ readonly metadataSchema?: string;
211
+ readonly metadataTable?: string;
212
+ };
213
+ /** Compare declared and catalog types after resolving aliases such as timestamptz. */
214
+ export declare const normalizeSqlType: (sqlType: string) => string;
215
+ /**
216
+ * Detect manual changes: tables, columns, types, nullability and declared indexes
217
+ * are compared between the live catalog and the expected snapshot.
218
+ */
219
+ export declare const detectDrift: (options: DriftOptions) => Promise<DriftFinding[]>;
220
+ export declare const formatDriftFindings: (findings: readonly DriftFinding[]) => string;
221
+ //#endregion
222
+ //#region src/migrations/runner.d.ts
223
+ type MigratorOptions = ExecutionOptions & {
224
+ driver: Driver;
225
+ directory: string;
226
+ metadataSchema?: string;
227
+ metadataTable?: string;
228
+ /** Administrative URL used only to create disposable databases for historical verification. */
229
+ verificationDatabaseUrl?: string;
230
+ };
231
+ type MigrationStatus = {
232
+ id: string;
233
+ status: "applied" | "pending" | "incomplete";
234
+ appliedAt?: Date;
235
+ direction?: "up" | "down";
236
+ statement?: number;
237
+ error?: string;
238
+ };
239
+ export declare const migrator: (options: MigratorOptions) => Readonly<{
240
+ status: () => Promise<MigrationStatus[]>;
241
+ plan: (settings?: {
242
+ to?: string;
243
+ steps?: number;
244
+ direction?: "up" | "down";
245
+ }) => Promise<ExecutionStep[]>;
246
+ migrate: (settings?: {
247
+ to?: string;
248
+ }) => Promise<string[]>;
249
+ rollback: (settings?: {
250
+ steps?: number;
251
+ }) => Promise<string[]>;
252
+ adopt: (settings?: {
253
+ to?: string;
254
+ snapshot?: MigrationSnapshot;
255
+ }) => Promise<string[]>;
256
+ repair: (settings: {
257
+ id: string;
258
+ action: "retry" | "complete";
259
+ snapshot?: MigrationSnapshot;
260
+ }) => Promise<void>;
261
+ }>;
262
+ //#endregion
263
+ //#region src/migrations/config.d.ts
264
+ type MigrationConfig = ExecutionOptions & {
265
+ readonly schema?: {
266
+ $snapshot: () => SchemaSnapshot;
267
+ } | SchemaSnapshot;
268
+ readonly directory?: string;
269
+ readonly databaseUrl?: string | undefined;
270
+ /** Migration journal schema (default public); does not change the application search_path. */
271
+ readonly metadataSchema?: string;
272
+ readonly metadataTable?: string;
273
+ readonly verificationDatabaseUrl?: string;
274
+ readonly verify?: Pick<VerifyOptions, "schemaName" | "beforeMigration" | "afterMigration">;
275
+ };
276
+ export declare const defineMigrationConfig: (config: MigrationConfig) => MigrationConfig;
277
+ //#endregion
278
+ //#region src/introspection/model.d.ts
279
+ type PullWarningCode = "identity-by-default" | "serial" | "identity-type" | "generated-column" | "custom-type" | "constraint-name" | "foreign-key" | "unique-constraint" | "index" | "junction-index" | "check" | "enum" | "primary-key" | "name" | "partition" | "exclusion" | "extension";
280
+ type PullWarning = {
281
+ readonly code: PullWarningCode;
282
+ readonly table?: string;
283
+ readonly column?: string;
284
+ /** The constraint, index or type the warning is about. */
285
+ readonly object?: string;
286
+ readonly message: string;
287
+ /** SQL that makes the database match what the generated schema declares. */
288
+ readonly fix?: string;
289
+ };
290
+ //#endregion
291
+ //#region src/introspection/render.d.ts
292
+ type RenderOptions = {
293
+ /** Name of the exported schema constant (default: appSchema). */
294
+ readonly exportName?: string;
295
+ /** Module specifier for the runtime import (default: symmetria). */
296
+ readonly module?: string;
297
+ /** Comment lines placed at the top of the file. */
298
+ readonly header?: readonly string[];
299
+ /** Module specifier for the pgvector entry (default: `${module}/vector`). */
300
+ readonly vectorModule?: string;
301
+ };
302
+ //#endregion
303
+ //#region src/introspection/index.d.ts
304
+ type PullOptions = RenderOptions & {
305
+ readonly execute: QueryExecutor;
306
+ /** Schema to introspect; defaults to the connection's current_schema(). */
307
+ readonly schemaName?: string;
308
+ /** Location of the migration journal, which is never part of the declared schema. */
309
+ readonly metadataSchema?: string;
310
+ readonly metadataTable?: string;
311
+ };
312
+ type PullResult = {
313
+ /** The generated schema module. */
314
+ readonly source: string;
315
+ readonly schemaName: string;
316
+ /** SQL names of the declared tables. */
317
+ readonly tables: string[];
318
+ /** Enum types declared with oneOf(). */
319
+ readonly enumerations: string[];
320
+ /** Extensions declared through the schema options. */
321
+ readonly extensions: string[];
322
+ readonly warnings: PullWarning[];
323
+ };
324
+ export declare const pullSchema: (options: PullOptions) => Promise<PullResult>;
325
+ //#endregion
326
+ //#region src/graph/mermaid.d.ts
327
+ type GraphColumn = {
328
+ readonly name: string;
329
+ readonly type: string;
330
+ readonly primaryKey: boolean;
331
+ readonly foreignKey: boolean;
332
+ readonly unique: boolean;
333
+ readonly nullable: boolean;
334
+ readonly identity: boolean;
335
+ };
336
+ type GraphTable = {
337
+ readonly name: string;
338
+ readonly columns: readonly GraphColumn[];
339
+ /** A table whose primary key is exactly its two foreign keys. */
340
+ readonly junction: boolean;
341
+ };
342
+ type GraphEdge = {
343
+ /** The referenced (parent) table. */
344
+ readonly from: string;
345
+ /** The referencing (child) table. */
346
+ readonly to: string;
347
+ readonly column: string;
348
+ /** Relation name shown on the edge: the column without its `_id` suffix. */
349
+ readonly label: string;
350
+ /** The foreign key is nullable, so a child may have no parent. */
351
+ readonly optional: boolean;
352
+ /** The foreign key is unique, so the relation is one-to-one. */
353
+ readonly one: boolean;
354
+ /** The foreign key is part of the child's primary key. */
355
+ readonly identifying: boolean;
356
+ };
357
+ type SchemaGraph = {
358
+ readonly tables: readonly GraphTable[];
359
+ readonly edges: readonly GraphEdge[];
360
+ };
361
+ type MermaidOptions = {
362
+ /** Wrap the diagram in a ```mermaid fence for Markdown. */
363
+ readonly fenced?: boolean;
364
+ /** Leave out column lists and show only entities and relations. */
365
+ readonly compact?: boolean;
366
+ };
367
+ /** Tables, columns and foreign-key edges of a declared schema or a migration snapshot. */
368
+ export declare const schemaGraph: (snapshot: SchemaSnapshot | MigrationSnapshot) => SchemaGraph;
369
+ export declare const renderMermaid: (graph: SchemaGraph, options?: MermaidOptions) => string;
370
+ //#endregion
371
+ export type { DriftFinding, DriftKind, DriftOptions, ExecutionOptions, ExecutionStep, GenerateMigrationOptions, GeneratedMigration, GraphColumn, GraphEdge, GraphTable, LintFinding, LintLevel, MermaidOptions, Migration, MigrationColumn, MigrationConfig, MigrationDiffOptions, MigrationEvent, MigrationManifest, MigrationPlan, MigrationSnapshot, MigrationState, MigrationStatus, MigrationTable, MigratorOptions, PullOptions, PullResult, PullWarning, PullWarningCode, RenameHints, SQLFinding, SchemaGraph, SquashMigrationsOptions, VerificationContext, VerifyOptions };
372
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import { b as snapshotHash, g as migrationSnapshot, h as emptySnapshot, v as parseMigrationSnapshot } from "./ddl-BpRIXfCw.js";
2
+ import { n as diffSchemas, t as createSchemaSQL } from "./diff-ConfLt63.js";
3
+ import { _ as formatLintFindings, a as verifyMigrations, c as detectDrift, d as lintMigrationSQL, f as generateMigration, g as recoverMigrationFiles, h as squashMigrations, i as defineMigrationConfig, l as formatDriftFindings, m as loadMigrations, n as schemaGraph, o as migrator, p as loadMigrationState, r as pullSchema, s as MigrationExecutionError, t as renderMermaid, u as normalizeSqlType, v as lintMigration } from "./src-C2mBlLSB.js";
4
+ export { MigrationExecutionError, createSchemaSQL, defineMigrationConfig, detectDrift, diffSchemas, emptySnapshot, formatDriftFindings, formatLintFindings, generateMigration, lintMigration, lintMigrationSQL, loadMigrationState, loadMigrations, migrationSnapshot, migrator, normalizeSqlType, parseMigrationSnapshot, pullSchema, recoverMigrationFiles, renderMermaid, schemaGraph, snapshotHash, squashMigrations, verifyMigrations };