zenstack-kit 0.1.1 → 0.1.3

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 (52) hide show
  1. package/dist/cli/app.d.ts.map +1 -1
  2. package/dist/cli/app.js +9 -28
  3. package/dist/cli/commands.d.ts +3 -1
  4. package/dist/cli/commands.d.ts.map +1 -1
  5. package/dist/cli/commands.js +34 -1
  6. package/dist/cli/index.js +0 -0
  7. package/dist/cli/prompts.d.ts +9 -0
  8. package/dist/cli/prompts.d.ts.map +1 -1
  9. package/dist/cli/prompts.js +57 -1
  10. package/dist/migrations/prisma.d.ts +10 -0
  11. package/dist/migrations/prisma.d.ts.map +1 -1
  12. package/dist/migrations/prisma.js +85 -3
  13. package/package.json +1 -5
  14. package/dist/cli.d.ts +0 -12
  15. package/dist/cli.d.ts.map +0 -1
  16. package/dist/cli.js +0 -240
  17. package/dist/config-loader.d.ts +0 -6
  18. package/dist/config-loader.d.ts.map +0 -1
  19. package/dist/config-loader.js +0 -36
  20. package/dist/config.d.ts +0 -62
  21. package/dist/config.d.ts.map +0 -1
  22. package/dist/config.js +0 -44
  23. package/dist/init-prompts.d.ts +0 -13
  24. package/dist/init-prompts.d.ts.map +0 -1
  25. package/dist/init-prompts.js +0 -64
  26. package/dist/introspect.d.ts +0 -54
  27. package/dist/introspect.d.ts.map +0 -1
  28. package/dist/introspect.js +0 -75
  29. package/dist/kysely-adapter.d.ts +0 -49
  30. package/dist/kysely-adapter.d.ts.map +0 -1
  31. package/dist/kysely-adapter.js +0 -74
  32. package/dist/migrate-apply.d.ts +0 -18
  33. package/dist/migrate-apply.d.ts.map +0 -1
  34. package/dist/migrate-apply.js +0 -61
  35. package/dist/migrations.d.ts +0 -161
  36. package/dist/migrations.d.ts.map +0 -1
  37. package/dist/migrations.js +0 -620
  38. package/dist/prisma-migrations.d.ts +0 -160
  39. package/dist/prisma-migrations.d.ts.map +0 -1
  40. package/dist/prisma-migrations.js +0 -789
  41. package/dist/prompts.d.ts +0 -10
  42. package/dist/prompts.d.ts.map +0 -1
  43. package/dist/prompts.js +0 -41
  44. package/dist/pull.d.ts +0 -23
  45. package/dist/pull.d.ts.map +0 -1
  46. package/dist/pull.js +0 -424
  47. package/dist/schema-snapshot.d.ts +0 -45
  48. package/dist/schema-snapshot.d.ts.map +0 -1
  49. package/dist/schema-snapshot.js +0 -265
  50. package/dist/sql-compiler.d.ts +0 -74
  51. package/dist/sql-compiler.d.ts.map +0 -1
  52. package/dist/sql-compiler.js +0 -243
@@ -1,74 +0,0 @@
1
- /**
2
- * Kysely database adapter
3
- *
4
- * Provides utilities to create Kysely instances configured for use
5
- * with ZenStack-generated types.
6
- */
7
- /**
8
- * Creates a Kysely adapter for use with ZenStack schemas
9
- *
10
- * @example
11
- * ```ts
12
- * import { createKyselyAdapter } from "zenstack-kit";
13
- * import type { Database } from "./generated/kysely-types";
14
- *
15
- * const { db, destroy } = await createKyselyAdapter<Database>({
16
- * dialect: "postgres",
17
- * connectionUrl: process.env.DATABASE_URL,
18
- * });
19
- *
20
- * // Use db for queries
21
- * const users = await db.selectFrom("user").selectAll().execute();
22
- *
23
- * // Clean up
24
- * await destroy();
25
- * ```
26
- */
27
- export async function createKyselyAdapter(options) {
28
- // Dynamic imports based on dialect to avoid bundling unused drivers
29
- let dialect;
30
- switch (options.dialect) {
31
- case "sqlite": {
32
- const { default: Database } = await import("better-sqlite3");
33
- const { SqliteDialect } = await import("kysely");
34
- dialect = new SqliteDialect({
35
- database: new Database(options.databasePath || ":memory:"),
36
- });
37
- break;
38
- }
39
- case "postgres": {
40
- // Note: User needs to install pg package
41
- const { Pool } = await import("pg");
42
- const { PostgresDialect } = await import("kysely");
43
- dialect = new PostgresDialect({
44
- pool: new Pool({
45
- connectionString: options.connectionUrl,
46
- min: options.pool?.min ?? 2,
47
- max: options.pool?.max ?? 10,
48
- }),
49
- });
50
- break;
51
- }
52
- case "mysql": {
53
- // Note: User needs to install mysql2 package
54
- const mysql = await import("mysql2");
55
- const { MysqlDialect } = await import("kysely");
56
- dialect = new MysqlDialect({
57
- pool: mysql.createPool({
58
- uri: options.connectionUrl,
59
- }),
60
- });
61
- break;
62
- }
63
- default:
64
- throw new Error(`Unsupported dialect: ${options.dialect}`);
65
- }
66
- const { Kysely } = await import("kysely");
67
- const db = new Kysely({ dialect });
68
- return {
69
- db,
70
- destroy: async () => {
71
- await db.destroy();
72
- },
73
- };
74
- }
@@ -1,18 +0,0 @@
1
- /**
2
- * Apply migrations using Kysely's migrator
3
- */
4
- import type { KyselyDialect } from "./kysely-adapter.js";
5
- export interface ApplyMigrationsOptions {
6
- migrationsFolder: string;
7
- dialect: KyselyDialect;
8
- connectionUrl?: string;
9
- databasePath?: string;
10
- }
11
- export interface ApplyMigrationsResult {
12
- results: Array<{
13
- migrationName: string;
14
- status: string;
15
- }>;
16
- }
17
- export declare function applyMigrations(options: ApplyMigrationsOptions): Promise<ApplyMigrationsResult>;
18
- //# sourceMappingURL=migrate-apply.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"migrate-apply.d.ts","sourceRoot":"","sources":["../src/migrate-apply.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGzD,MAAM,WAAW,sBAAsB;IACrC,gBAAgB,EAAE,MAAM,CAAC;IACzB,OAAO,EAAE,aAAa,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,KAAK,CAAC;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAC1D;AAED,wBAAsB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CA4DrG"}
@@ -1,61 +0,0 @@
1
- /**
2
- * Apply migrations using Kysely's migrator
3
- */
4
- import * as path from "path";
5
- import { createKyselyAdapter } from "./kysely-adapter.js";
6
- export async function applyMigrations(options) {
7
- const databasePath = options.databasePath ??
8
- (options.dialect === "sqlite" ? resolveSqlitePath(options.connectionUrl) : undefined);
9
- const { db, destroy } = await createKyselyAdapter({
10
- dialect: options.dialect,
11
- connectionUrl: options.connectionUrl,
12
- databasePath,
13
- });
14
- try {
15
- const { Migrator } = await import("kysely");
16
- const fs = await import("fs/promises");
17
- const { default: jiti } = await import("jiti");
18
- const loader = jiti(import.meta.url, { interopDefault: true });
19
- const provider = {
20
- async getMigrations() {
21
- const entries = await fs.readdir(options.migrationsFolder);
22
- const files = entries
23
- .filter((file) => /\.(ts|js|mjs|cjs)$/.test(file))
24
- .sort((a, b) => a.localeCompare(b));
25
- const migrations = {};
26
- for (const file of files) {
27
- const filePath = path.join(options.migrationsFolder, file);
28
- const mod = loader(filePath);
29
- const migration = mod.default ?? mod;
30
- if (!migration?.up || !migration?.down) {
31
- throw new Error(`Migration file is missing up/down exports: ${file}`);
32
- }
33
- migrations[path.parse(file).name] = migration;
34
- }
35
- return migrations;
36
- },
37
- };
38
- const migrator = new Migrator({ db, provider });
39
- const { error, results } = await migrator.migrateToLatest();
40
- if (error) {
41
- throw error;
42
- }
43
- return {
44
- results: results?.map((result) => ({
45
- migrationName: result.migrationName,
46
- status: result.status,
47
- })) ?? [],
48
- };
49
- }
50
- finally {
51
- await destroy();
52
- }
53
- }
54
- function resolveSqlitePath(url) {
55
- if (!url)
56
- return undefined;
57
- if (url.startsWith("file:")) {
58
- return url.slice("file:".length);
59
- }
60
- return url;
61
- }
@@ -1,161 +0,0 @@
1
- /**
2
- * Migration generation and management
3
- *
4
- * Creates and manages database migrations based on ZenStack schema changes
5
- * using AST-based diffs and Kysely schema builder operations.
6
- */
7
- import { type SchemaTable, type SchemaColumn } from "./schema-snapshot.js";
8
- export interface MigrationOptions {
9
- /** Migration name */
10
- name?: string;
11
- /** Path to ZenStack schema file */
12
- schemaPath: string;
13
- /** Output directory for migration files */
14
- outputPath: string;
15
- /** Optional snapshot file override */
16
- snapshotPath?: string;
17
- /** Table rename mappings */
18
- renameTables?: Array<{
19
- from: string;
20
- to: string;
21
- }>;
22
- /** Column rename mappings */
23
- renameColumns?: Array<{
24
- table: string;
25
- from: string;
26
- to: string;
27
- }>;
28
- }
29
- export interface Migration {
30
- /** Migration filename */
31
- filename: string;
32
- /** Kysely schema builder up migration */
33
- up: string;
34
- /** Kysely schema builder down migration */
35
- down: string;
36
- /** Timestamp */
37
- timestamp: number;
38
- }
39
- interface FieldChange {
40
- model: SchemaTable;
41
- tableName: string;
42
- columnName: string;
43
- previous: SchemaColumn;
44
- current: SchemaColumn;
45
- changes: {
46
- typeChanged: boolean;
47
- requiredChanged: boolean;
48
- defaultChanged: boolean;
49
- listChanged: boolean;
50
- };
51
- }
52
- interface DiffResult {
53
- addedModels: SchemaTable[];
54
- removedModels: SchemaTable[];
55
- addedFields: Array<{
56
- model: SchemaTable;
57
- tableName: string;
58
- field: SchemaColumn;
59
- columnName: string;
60
- }>;
61
- removedFields: Array<{
62
- model: SchemaTable;
63
- tableName: string;
64
- field: SchemaColumn;
65
- columnName: string;
66
- }>;
67
- alteredFields: FieldChange[];
68
- renamedTables: Array<{
69
- from: string;
70
- to: string;
71
- }>;
72
- renamedColumns: Array<{
73
- tableName: string;
74
- from: string;
75
- to: string;
76
- }>;
77
- addedUniqueConstraints: Array<{
78
- tableName: string;
79
- constraint: {
80
- name: string;
81
- columns: string[];
82
- };
83
- }>;
84
- removedUniqueConstraints: Array<{
85
- tableName: string;
86
- constraint: {
87
- name: string;
88
- columns: string[];
89
- };
90
- }>;
91
- addedIndexes: Array<{
92
- tableName: string;
93
- index: {
94
- name: string;
95
- columns: string[];
96
- };
97
- }>;
98
- removedIndexes: Array<{
99
- tableName: string;
100
- index: {
101
- name: string;
102
- columns: string[];
103
- };
104
- }>;
105
- addedForeignKeys: Array<{
106
- tableName: string;
107
- foreignKey: {
108
- name: string;
109
- columns: string[];
110
- referencedTable: string;
111
- referencedColumns: string[];
112
- };
113
- }>;
114
- removedForeignKeys: Array<{
115
- tableName: string;
116
- foreignKey: {
117
- name: string;
118
- columns: string[];
119
- referencedTable: string;
120
- referencedColumns: string[];
121
- };
122
- }>;
123
- primaryKeyChanges: Array<{
124
- tableName: string;
125
- previous?: {
126
- name: string;
127
- columns: string[];
128
- };
129
- current?: {
130
- name: string;
131
- columns: string[];
132
- };
133
- }>;
134
- }
135
- export declare function getSchemaDiff(options: MigrationOptions): Promise<DiffResult>;
136
- export declare function hasSchemaChanges(options: MigrationOptions): Promise<boolean>;
137
- export interface InitSnapshotOptions {
138
- /** Path to ZenStack schema file */
139
- schemaPath: string;
140
- /** Output directory for migrations (snapshot will be in meta subfolder) */
141
- outputPath: string;
142
- /** Optional snapshot file override */
143
- snapshotPath?: string;
144
- }
145
- export interface InitSnapshotResult {
146
- /** Path to the created snapshot file */
147
- snapshotPath: string;
148
- /** Number of tables in the snapshot */
149
- tableCount: number;
150
- }
151
- /**
152
- * Initialize a snapshot from the current schema without generating a migration.
153
- * Use this to baseline an existing database before starting to track migrations.
154
- */
155
- export declare function initSnapshot(options: InitSnapshotOptions): Promise<InitSnapshotResult>;
156
- /**
157
- * Create a migration file from schema changes
158
- */
159
- export declare function createMigration(options: MigrationOptions): Promise<Migration | null>;
160
- export {};
161
- //# sourceMappingURL=migrations.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../src/migrations.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAGL,KAAK,WAAW,EAChB,KAAK,YAAY,EAGlB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,WAAW,gBAAgB;IAC/B,qBAAqB;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mCAAmC;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAC;IACnB,sCAAsC;IAC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