zenstack-kit 0.1.1

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 (93) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +313 -0
  3. package/dist/cli/app.d.ts +12 -0
  4. package/dist/cli/app.d.ts.map +1 -0
  5. package/dist/cli/app.js +253 -0
  6. package/dist/cli/commands.d.ts +70 -0
  7. package/dist/cli/commands.d.ts.map +1 -0
  8. package/dist/cli/commands.js +308 -0
  9. package/dist/cli/index.d.ts +12 -0
  10. package/dist/cli/index.d.ts.map +1 -0
  11. package/dist/cli/index.js +12 -0
  12. package/dist/cli/prompt-provider.d.ts +10 -0
  13. package/dist/cli/prompt-provider.d.ts.map +1 -0
  14. package/dist/cli/prompt-provider.js +41 -0
  15. package/dist/cli/prompts.d.ts +27 -0
  16. package/dist/cli/prompts.d.ts.map +1 -0
  17. package/dist/cli/prompts.js +133 -0
  18. package/dist/cli.d.ts +12 -0
  19. package/dist/cli.d.ts.map +1 -0
  20. package/dist/cli.js +240 -0
  21. package/dist/config/index.d.ts +96 -0
  22. package/dist/config/index.d.ts.map +1 -0
  23. package/dist/config/index.js +48 -0
  24. package/dist/config/loader.d.ts +11 -0
  25. package/dist/config/loader.d.ts.map +1 -0
  26. package/dist/config/loader.js +44 -0
  27. package/dist/config-loader.d.ts +6 -0
  28. package/dist/config-loader.d.ts.map +1 -0
  29. package/dist/config-loader.js +36 -0
  30. package/dist/config.d.ts +62 -0
  31. package/dist/config.d.ts.map +1 -0
  32. package/dist/config.js +44 -0
  33. package/dist/index.d.ts +19 -0
  34. package/dist/index.d.ts.map +1 -0
  35. package/dist/index.js +23 -0
  36. package/dist/init-prompts.d.ts +13 -0
  37. package/dist/init-prompts.d.ts.map +1 -0
  38. package/dist/init-prompts.js +64 -0
  39. package/dist/introspect.d.ts +54 -0
  40. package/dist/introspect.d.ts.map +1 -0
  41. package/dist/introspect.js +75 -0
  42. package/dist/kysely-adapter.d.ts +49 -0
  43. package/dist/kysely-adapter.d.ts.map +1 -0
  44. package/dist/kysely-adapter.js +74 -0
  45. package/dist/migrate-apply.d.ts +18 -0
  46. package/dist/migrate-apply.d.ts.map +1 -0
  47. package/dist/migrate-apply.js +61 -0
  48. package/dist/migrate.d.ts +108 -0
  49. package/dist/migrate.d.ts.map +1 -0
  50. package/dist/migrate.js +127 -0
  51. package/dist/migrations/apply.d.ts +18 -0
  52. package/dist/migrations/apply.d.ts.map +1 -0
  53. package/dist/migrations/apply.js +61 -0
  54. package/dist/migrations/diff.d.ts +161 -0
  55. package/dist/migrations/diff.d.ts.map +1 -0
  56. package/dist/migrations/diff.js +620 -0
  57. package/dist/migrations/prisma.d.ts +193 -0
  58. package/dist/migrations/prisma.d.ts.map +1 -0
  59. package/dist/migrations/prisma.js +929 -0
  60. package/dist/migrations.d.ts +161 -0
  61. package/dist/migrations.d.ts.map +1 -0
  62. package/dist/migrations.js +620 -0
  63. package/dist/prisma-migrations.d.ts +160 -0
  64. package/dist/prisma-migrations.d.ts.map +1 -0
  65. package/dist/prisma-migrations.js +789 -0
  66. package/dist/prompts.d.ts +10 -0
  67. package/dist/prompts.d.ts.map +1 -0
  68. package/dist/prompts.js +41 -0
  69. package/dist/pull.d.ts +23 -0
  70. package/dist/pull.d.ts.map +1 -0
  71. package/dist/pull.js +424 -0
  72. package/dist/schema/introspect.d.ts +54 -0
  73. package/dist/schema/introspect.d.ts.map +1 -0
  74. package/dist/schema/introspect.js +75 -0
  75. package/dist/schema/pull.d.ts +23 -0
  76. package/dist/schema/pull.d.ts.map +1 -0
  77. package/dist/schema/pull.js +424 -0
  78. package/dist/schema/snapshot.d.ts +46 -0
  79. package/dist/schema/snapshot.d.ts.map +1 -0
  80. package/dist/schema/snapshot.js +278 -0
  81. package/dist/schema-snapshot.d.ts +45 -0
  82. package/dist/schema-snapshot.d.ts.map +1 -0
  83. package/dist/schema-snapshot.js +265 -0
  84. package/dist/sql/compiler.d.ts +74 -0
  85. package/dist/sql/compiler.d.ts.map +1 -0
  86. package/dist/sql/compiler.js +270 -0
  87. package/dist/sql/kysely-adapter.d.ts +49 -0
  88. package/dist/sql/kysely-adapter.d.ts.map +1 -0
  89. package/dist/sql/kysely-adapter.js +74 -0
  90. package/dist/sql-compiler.d.ts +74 -0
  91. package/dist/sql-compiler.d.ts.map +1 -0
  92. package/dist/sql-compiler.js +243 -0
  93. package/package.json +81 -0
@@ -0,0 +1,193 @@
1
+ /**
2
+ * Prisma-compatible migrations
3
+ *
4
+ * Generates migrations in Prisma format:
5
+ * - Folder structure: migrations/<timestamp>_<name>/migration.sql
6
+ * - Tracks migrations in _prisma_migrations table
7
+ * - Compatible with `prisma migrate deploy`
8
+ */
9
+ import type { KyselyDialect } from "../sql/kysely-adapter.js";
10
+ import type { SchemaSnapshot } from "../schema/snapshot.js";
11
+ export interface PrismaMigrationOptions {
12
+ /** Migration name */
13
+ name: string;
14
+ /** Path to ZenStack schema file */
15
+ schemaPath: string;
16
+ /** Output directory for migration files */
17
+ outputPath: string;
18
+ /** Database dialect for SQL generation */
19
+ dialect: KyselyDialect;
20
+ /** Table rename mappings */
21
+ renameTables?: Array<{
22
+ from: string;
23
+ to: string;
24
+ }>;
25
+ /** Column rename mappings */
26
+ renameColumns?: Array<{
27
+ table: string;
28
+ from: string;
29
+ to: string;
30
+ }>;
31
+ }
32
+ export interface PrismaMigration {
33
+ /** Migration folder name (timestamp_name) */
34
+ folderName: string;
35
+ /** Full path to migration folder */
36
+ folderPath: string;
37
+ /** SQL content */
38
+ sql: string;
39
+ /** Timestamp */
40
+ timestamp: number;
41
+ }
42
+ export interface ApplyPrismaMigrationsOptions {
43
+ /** Migrations folder path */
44
+ migrationsFolder: string;
45
+ /** Database dialect */
46
+ dialect: KyselyDialect;
47
+ /** Database connection URL */
48
+ connectionUrl?: string;
49
+ /** SQLite database path */
50
+ databasePath?: string;
51
+ /** Migrations table name (default: _prisma_migrations) */
52
+ migrationsTable?: string;
53
+ /** Migrations schema (PostgreSQL only, default: public) */
54
+ migrationsSchema?: string;
55
+ }
56
+ export interface ApplyPrismaMigrationsResult {
57
+ applied: Array<{
58
+ migrationName: string;
59
+ duration: number;
60
+ }>;
61
+ alreadyApplied: string[];
62
+ failed?: {
63
+ migrationName: string;
64
+ error: string;
65
+ };
66
+ }
67
+ export interface PreviewPrismaMigrationsResult {
68
+ pending: Array<{
69
+ name: string;
70
+ sql: string;
71
+ }>;
72
+ alreadyApplied: string[];
73
+ }
74
+ /**
75
+ * Generate timestamp string for migration folder name
76
+ */
77
+ export declare function generateTimestamp(): string;
78
+ /**
79
+ * Get paths for snapshot file
80
+ */
81
+ declare function getSnapshotPaths(outputPath: string): {
82
+ metaDir: string;
83
+ snapshotPath: string;
84
+ };
85
+ /**
86
+ * Write snapshot to file
87
+ */
88
+ export declare function writeSnapshot(snapshotPath: string, schema: SchemaSnapshot): Promise<void>;
89
+ /**
90
+ * Create a Prisma-compatible migration
91
+ */
92
+ export declare function createPrismaMigration(options: PrismaMigrationOptions): Promise<PrismaMigration | null>;
93
+ export interface CreateInitialMigrationOptions {
94
+ /** Migration name (default: "init") */
95
+ name?: string;
96
+ /** Path to ZenStack schema file */
97
+ schemaPath: string;
98
+ /** Output directory for migration files */
99
+ outputPath: string;
100
+ /** Database dialect for SQL generation */
101
+ dialect: KyselyDialect;
102
+ }
103
+ /**
104
+ * Create an initial migration that creates all tables from scratch.
105
+ * This is used when initializing a project where the database is empty.
106
+ */
107
+ export declare function createInitialMigration(options: CreateInitialMigrationOptions): Promise<PrismaMigration>;
108
+ /**
109
+ * Calculate SHA256 checksum of migration SQL
110
+ */
111
+ export declare function calculateChecksum(sql: string): string;
112
+ /**
113
+ * Apply pending Prisma migrations
114
+ */
115
+ export declare function applyPrismaMigrations(options: ApplyPrismaMigrationsOptions): Promise<ApplyPrismaMigrationsResult>;
116
+ /**
117
+ * Preview pending migrations without applying them
118
+ */
119
+ export declare function previewPrismaMigrations(options: ApplyPrismaMigrationsOptions): Promise<PreviewPrismaMigrationsResult>;
120
+ /**
121
+ * Check if there are schema changes
122
+ */
123
+ export declare function hasPrismaSchemaChanges(options: {
124
+ schemaPath: string;
125
+ outputPath: string;
126
+ }): Promise<boolean>;
127
+ export interface PotentialTableRename {
128
+ from: string;
129
+ to: string;
130
+ }
131
+ export interface PotentialColumnRename {
132
+ table: string;
133
+ from: string;
134
+ to: string;
135
+ }
136
+ export interface PotentialRenames {
137
+ tables: PotentialTableRename[];
138
+ columns: PotentialColumnRename[];
139
+ }
140
+ /**
141
+ * Detect potential renames by finding removed+added pairs.
142
+ * A table rename is detected when one table is removed and one is added.
143
+ * A column rename is detected when within the same table, one column is removed and one is added.
144
+ */
145
+ export declare function detectPotentialRenames(options: {
146
+ schemaPath: string;
147
+ outputPath: string;
148
+ }): Promise<PotentialRenames>;
149
+ export interface MigrationLogEntry {
150
+ /** Migration folder name e.g. "20260108120000_init" */
151
+ name: string;
152
+ /** SHA256 checksum of migration.sql content (64 hex chars) */
153
+ checksum: string;
154
+ }
155
+ /**
156
+ * Get the path to the migration log file
157
+ */
158
+ export declare function getMigrationLogPath(outputPath: string): string;
159
+ /**
160
+ * Read migration log file
161
+ */
162
+ export declare function readMigrationLog(outputPath: string): Promise<MigrationLogEntry[]>;
163
+ /**
164
+ * Write migration log file
165
+ */
166
+ export declare function writeMigrationLog(outputPath: string, entries: MigrationLogEntry[]): Promise<void>;
167
+ /**
168
+ * Append a single entry to the migration log
169
+ */
170
+ export declare function appendToMigrationLog(outputPath: string, entry: MigrationLogEntry): Promise<void>;
171
+ /**
172
+ * Scan migration folders and compute checksums for each
173
+ */
174
+ export declare function scanMigrationFolders(outputPath: string): Promise<MigrationLogEntry[]>;
175
+ /**
176
+ * Check if snapshot exists
177
+ */
178
+ export declare function hasSnapshot(outputPath: string): Promise<boolean>;
179
+ /**
180
+ * Initialize snapshot from schema without generating migration
181
+ */
182
+ export declare function initializeSnapshot(options: {
183
+ schemaPath: string;
184
+ outputPath: string;
185
+ }): Promise<{
186
+ snapshotPath: string;
187
+ tableCount: number;
188
+ }>;
189
+ /**
190
+ * Export getSnapshotPaths for external use
191
+ */
192
+ export { getSnapshotPaths };
193
+ //# sourceMappingURL=prisma.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prisma.d.ts","sourceRoot":"","sources":["../../src/migrations/prisma.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,KAAK,EAAE,cAAc,EAA6B,MAAM,uBAAuB,CAAC;AAkBvF,MAAM,WAAW,sBAAsB;IACrC,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,mCAAmC;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAC;IACnB,0CAA0C;IAC1C,OAAO,EAAE,aAAa,CAAC;IACvB,4BAA4B;IAC5B,YAAY,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACnD,6BAA6B;IAC7B,aAAa,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACpE;AAED,MAAM,WAAW,eAAe;IAC9B,6CAA6C;IAC7C,UAAU,EAAE,MAAM,CAAC;IACnB,oCAAoC;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,kBAAkB;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,4BAA4B;IAC3C,6BAA6B;IAC7B,gBAAgB,EAAE,MAAM,CAAC;IACzB,uBAAuB;IACvB,OAAO,EAAE,aAAa,CAAC;IACvB,8BAA8B;IAC9B,aAAa,CAAC,EAAE,MAAM,CAA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