zenstack-kit 0.1.1 → 0.1.2
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.
- package/dist/cli/app.d.ts.map +1 -1
- package/dist/cli/app.js +9 -28
- package/dist/cli/commands.d.ts +3 -1
- package/dist/cli/commands.d.ts.map +1 -1
- package/dist/cli/commands.js +17 -1
- package/dist/cli/index.js +0 -0
- package/dist/cli/prompts.d.ts +9 -0
- package/dist/cli/prompts.d.ts.map +1 -1
- package/dist/cli/prompts.js +57 -1
- package/package.json +1 -5
- package/dist/cli.d.ts +0 -12
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -240
- package/dist/config-loader.d.ts +0 -6
- package/dist/config-loader.d.ts.map +0 -1
- package/dist/config-loader.js +0 -36
- package/dist/config.d.ts +0 -62
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -44
- package/dist/init-prompts.d.ts +0 -13
- package/dist/init-prompts.d.ts.map +0 -1
- package/dist/init-prompts.js +0 -64
- package/dist/introspect.d.ts +0 -54
- package/dist/introspect.d.ts.map +0 -1
- package/dist/introspect.js +0 -75
- package/dist/kysely-adapter.d.ts +0 -49
- package/dist/kysely-adapter.d.ts.map +0 -1
- package/dist/kysely-adapter.js +0 -74
- package/dist/migrate-apply.d.ts +0 -18
- package/dist/migrate-apply.d.ts.map +0 -1
- package/dist/migrate-apply.js +0 -61
- package/dist/migrations.d.ts +0 -161
- package/dist/migrations.d.ts.map +0 -1
- package/dist/migrations.js +0 -620
- package/dist/prisma-migrations.d.ts +0 -160
- package/dist/prisma-migrations.d.ts.map +0 -1
- package/dist/prisma-migrations.js +0 -789
- package/dist/prompts.d.ts +0 -10
- package/dist/prompts.d.ts.map +0 -1
- package/dist/prompts.js +0 -41
- package/dist/pull.d.ts +0 -23
- package/dist/pull.d.ts.map +0 -1
- package/dist/pull.js +0 -424
- package/dist/schema-snapshot.d.ts +0 -45
- package/dist/schema-snapshot.d.ts.map +0 -1
- package/dist/schema-snapshot.js +0 -265
- package/dist/sql-compiler.d.ts +0 -74
- package/dist/sql-compiler.d.ts.map +0 -1
- package/dist/sql-compiler.js +0 -243
package/dist/config.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Configuration utilities for zenstack-kit
|
|
3
|
-
*
|
|
4
|
-
* Provides a type-safe way to define configuration similar to drizzle-kit's config.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Define zenstack-kit configuration
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* // zenstack-kit.config.ts
|
|
12
|
-
* import { defineConfig } from "zenstack-kit";
|
|
13
|
-
*
|
|
14
|
-
* export default defineConfig({
|
|
15
|
-
* schema: "./prisma/schema.zmodel",
|
|
16
|
-
* out: "./src/db",
|
|
17
|
-
* dialect: "postgres",
|
|
18
|
-
* dbCredentials: {
|
|
19
|
-
* url: process.env.DATABASE_URL,
|
|
20
|
-
* },
|
|
21
|
-
* });
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export function defineConfig(config) {
|
|
25
|
-
return {
|
|
26
|
-
// Default values
|
|
27
|
-
dialect: "sqlite",
|
|
28
|
-
verbose: false,
|
|
29
|
-
strict: false,
|
|
30
|
-
...config,
|
|
31
|
-
out: config.out ?? "./generated",
|
|
32
|
-
migrations: {
|
|
33
|
-
migrationsFolder: "./prisma/migrations",
|
|
34
|
-
migrationsTable: "_prisma_migrations",
|
|
35
|
-
migrationsSchema: "public",
|
|
36
|
-
...config.migrations,
|
|
37
|
-
},
|
|
38
|
-
codegen: {
|
|
39
|
-
camelCase: true,
|
|
40
|
-
generateIndex: true,
|
|
41
|
-
...config.codegen,
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
}
|
package/dist/init-prompts.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interactive prompts for the init command using ink
|
|
3
|
-
*/
|
|
4
|
-
export type InitChoice = "skip" | "reinitialize" | "baseline" | "create_initial";
|
|
5
|
-
/**
|
|
6
|
-
* Prompt user when snapshot already exists (Case A)
|
|
7
|
-
*/
|
|
8
|
-
export declare function promptSnapshotExists(): Promise<InitChoice>;
|
|
9
|
-
/**
|
|
10
|
-
* Prompt user for fresh init when no migrations exist (Case C)
|
|
11
|
-
*/
|
|
12
|
-
export declare function promptFreshInit(): Promise<InitChoice>;
|
|
13
|
-
//# sourceMappingURL=init-prompts.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"init-prompts.d.ts","sourceRoot":"","sources":["../src/init-prompts.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAMH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,cAAc,GAAG,UAAU,GAAG,gBAAgB,CAAC;AAsCjF;;GAEG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,UAAU,CAAC,CAyBhE;AAED;;GAEG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,UAAU,CAAC,CAyB3D"}
|
package/dist/init-prompts.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
/**
|
|
3
|
-
* Interactive prompts for the init command using ink
|
|
4
|
-
*/
|
|
5
|
-
import { useState } from "react";
|
|
6
|
-
import { render, Box, Text } from "ink";
|
|
7
|
-
import SelectInput from "ink-select-input";
|
|
8
|
-
function SelectPrompt({ message, items, onSelect }) {
|
|
9
|
-
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
10
|
-
const handleSelect = (item) => {
|
|
11
|
-
onSelect(item.value);
|
|
12
|
-
};
|
|
13
|
-
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { marginBottom: 1, children: [_jsx(Text, { color: "cyan", children: "? " }), _jsx(Text, { children: message })] }), _jsx(SelectInput, { items: items, onSelect: handleSelect, onHighlight: (item) => {
|
|
14
|
-
const idx = items.findIndex((i) => i.value === item.value);
|
|
15
|
-
if (idx !== -1)
|
|
16
|
-
setSelectedIndex(idx);
|
|
17
|
-
} }), items[selectedIndex]?.description && (_jsx(Box, { marginTop: 1, children: _jsxs(Text, { dimColor: true, children: [" ", items[selectedIndex].description] }) }))] }));
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Prompt user when snapshot already exists (Case A)
|
|
21
|
-
*/
|
|
22
|
-
export async function promptSnapshotExists() {
|
|
23
|
-
return new Promise((resolve) => {
|
|
24
|
-
const { unmount, waitUntilExit } = render(_jsx(SelectPrompt, { message: "Snapshot already exists. What would you like to do?", items: [
|
|
25
|
-
{
|
|
26
|
-
label: "Skip",
|
|
27
|
-
value: "skip",
|
|
28
|
-
description: "Do nothing and exit",
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
label: "Reinitialize",
|
|
32
|
-
value: "reinitialize",
|
|
33
|
-
description: "Overwrite snapshot and rebuild migration log from existing migrations",
|
|
34
|
-
},
|
|
35
|
-
], onSelect: (value) => {
|
|
36
|
-
unmount();
|
|
37
|
-
resolve(value);
|
|
38
|
-
} }));
|
|
39
|
-
waitUntilExit();
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Prompt user for fresh init when no migrations exist (Case C)
|
|
44
|
-
*/
|
|
45
|
-
export async function promptFreshInit() {
|
|
46
|
-
return new Promise((resolve) => {
|
|
47
|
-
const { unmount, waitUntilExit } = render(_jsx(SelectPrompt, { message: "No migrations found. What would you like to do?", items: [
|
|
48
|
-
{
|
|
49
|
-
label: "Baseline only",
|
|
50
|
-
value: "baseline",
|
|
51
|
-
description: "Create snapshot only - use when database already matches schema",
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
label: "Create initial migration",
|
|
55
|
-
value: "create_initial",
|
|
56
|
-
description: "Create snapshot + initial migration - use when database is empty",
|
|
57
|
-
},
|
|
58
|
-
], onSelect: (value) => {
|
|
59
|
-
unmount();
|
|
60
|
-
resolve(value);
|
|
61
|
-
} }));
|
|
62
|
-
waitUntilExit();
|
|
63
|
-
});
|
|
64
|
-
}
|
package/dist/introspect.d.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Schema introspection utilities
|
|
3
|
-
*
|
|
4
|
-
* Provides functionality to introspect ZenStack schemas and databases,
|
|
5
|
-
* extracting model and field information for code generation.
|
|
6
|
-
*/
|
|
7
|
-
export interface FieldInfo {
|
|
8
|
-
/** Field name */
|
|
9
|
-
name: string;
|
|
10
|
-
/** Field type (String, Int, Boolean, etc.) */
|
|
11
|
-
type: string;
|
|
12
|
-
/** Whether the field is optional */
|
|
13
|
-
isOptional: boolean;
|
|
14
|
-
/** Whether the field is an array */
|
|
15
|
-
isArray: boolean;
|
|
16
|
-
/** Whether this is a relation field */
|
|
17
|
-
isRelation: boolean;
|
|
18
|
-
/** Whether this is the primary key */
|
|
19
|
-
isId: boolean;
|
|
20
|
-
/** Whether the field has a default value */
|
|
21
|
-
hasDefault: boolean;
|
|
22
|
-
/** Whether the field is unique */
|
|
23
|
-
isUnique: boolean;
|
|
24
|
-
/** Related model name (for relations) */
|
|
25
|
-
relationModel?: string;
|
|
26
|
-
}
|
|
27
|
-
export interface ModelInfo {
|
|
28
|
-
/** Model name */
|
|
29
|
-
name: string;
|
|
30
|
-
/** Table name in database */
|
|
31
|
-
tableName: string;
|
|
32
|
-
/** Model fields */
|
|
33
|
-
fields: FieldInfo[];
|
|
34
|
-
}
|
|
35
|
-
export interface SchemaInfo {
|
|
36
|
-
/** All models in the schema */
|
|
37
|
-
models: ModelInfo[];
|
|
38
|
-
/** Schema version or hash */
|
|
39
|
-
version: string;
|
|
40
|
-
}
|
|
41
|
-
interface IntrospectOptions {
|
|
42
|
-
/** Path to ZenStack schema file */
|
|
43
|
-
schemaPath?: string;
|
|
44
|
-
/** Database connection URL (for database introspection) */
|
|
45
|
-
databaseUrl?: string;
|
|
46
|
-
/** Output path for generated schema */
|
|
47
|
-
outputPath?: string;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Introspect schema from file or database
|
|
51
|
-
*/
|
|
52
|
-
export declare function introspectSchema(options: IntrospectOptions): Promise<SchemaInfo>;
|
|
53
|
-
export {};
|
|
54
|
-
//# sourceMappingURL=introspect.d.ts.map
|
package/dist/introspect.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"introspect.d.ts","sourceRoot":"","sources":["../src/introspect.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,MAAM,WAAW,SAAS;IACxB,iBAAiB;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,oCAAoC;IACpC,UAAU,EAAE,OAAO,CAAC;IACpB,oCAAoC;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,uCAAuC;IACvC,UAAU,EAAE,OAAO,CAAC;IACpB,sCAAsC;IACtC,IAAI,EAAE,OAAO,CAAC;IACd,4CAA4C;IAC5C,UAAU,EAAE,OAAO,CAAC;IACpB,kCAAkC;IAClC,QAAQ,EAAE,OAAO,CAAC;IAClB,yCAAyC;IACzC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,SAAS;IACxB,iBAAiB;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,6BAA6B;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,mBAAmB;IACnB,MAAM,EAAE,SAAS,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,UAAU;IACzB,+BAA+B;IAC/B,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,6BAA6B;IAC7B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,iBAAiB;IACzB,mCAAmC;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2DAA2D;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uCAAuC;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAoED;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,UAAU,CAAC,CAUtF"}
|
package/dist/introspect.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Schema introspection utilities
|
|
3
|
-
*
|
|
4
|
-
* Provides functionality to introspect ZenStack schemas and databases,
|
|
5
|
-
* extracting model and field information for code generation.
|
|
6
|
-
*/
|
|
7
|
-
import * as fs from "fs/promises";
|
|
8
|
-
/**
|
|
9
|
-
* Parse a .zmodel file and extract schema information
|
|
10
|
-
* This is a simplified parser - in production, you'd use ZenStack's AST
|
|
11
|
-
*/
|
|
12
|
-
async function parseZModelFile(schemaPath) {
|
|
13
|
-
const content = await fs.readFile(schemaPath, "utf-8");
|
|
14
|
-
const models = [];
|
|
15
|
-
// Simple regex-based parser for demonstration
|
|
16
|
-
// In production, integrate with ZenStack's parser
|
|
17
|
-
const modelRegex = /model\s+(\w+)\s*\{([^}]+)\}/g;
|
|
18
|
-
const fieldRegex = /^\s*(\w+)\s+(\w+)(\[\])?\s*(\?)?\s*(.*?)$/gm;
|
|
19
|
-
let modelMatch;
|
|
20
|
-
while ((modelMatch = modelRegex.exec(content)) !== null) {
|
|
21
|
-
const modelName = modelMatch[1];
|
|
22
|
-
const modelBody = modelMatch[2];
|
|
23
|
-
const fields = [];
|
|
24
|
-
let fieldMatch;
|
|
25
|
-
const fieldPattern = /^\s*(\w+)\s+(\w+)(\[\])?\s*(\?)?(.*)$/gm;
|
|
26
|
-
while ((fieldMatch = fieldPattern.exec(modelBody)) !== null) {
|
|
27
|
-
const [, name, type, isArray, isOptional, modifiers] = fieldMatch;
|
|
28
|
-
// Skip if it looks like a directive
|
|
29
|
-
if (name.startsWith("@@") || name.startsWith("//"))
|
|
30
|
-
continue;
|
|
31
|
-
const isId = modifiers?.includes("@id") || false;
|
|
32
|
-
const hasDefault = modifiers?.includes("@default") || false;
|
|
33
|
-
const isUnique = modifiers?.includes("@unique") || isId;
|
|
34
|
-
const isRelation = modifiers?.includes("@relation") || false;
|
|
35
|
-
fields.push({
|
|
36
|
-
name,
|
|
37
|
-
type,
|
|
38
|
-
isOptional: !!isOptional,
|
|
39
|
-
isArray: !!isArray,
|
|
40
|
-
isRelation,
|
|
41
|
-
isId,
|
|
42
|
-
hasDefault,
|
|
43
|
-
isUnique,
|
|
44
|
-
relationModel: isRelation ? type : undefined,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
models.push({
|
|
48
|
-
name: modelName,
|
|
49
|
-
tableName: modelName.toLowerCase(),
|
|
50
|
-
fields,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
// Generate a simple version hash
|
|
54
|
-
const version = Buffer.from(content).toString("base64").slice(0, 8);
|
|
55
|
-
return { models, version };
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Introspect a database and generate schema information
|
|
59
|
-
*/
|
|
60
|
-
async function introspectDatabase(databaseUrl) {
|
|
61
|
-
void databaseUrl;
|
|
62
|
-
throw new Error("Database introspection is not supported.");
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Introspect schema from file or database
|
|
66
|
-
*/
|
|
67
|
-
export async function introspectSchema(options) {
|
|
68
|
-
if (options.schemaPath) {
|
|
69
|
-
return parseZModelFile(options.schemaPath);
|
|
70
|
-
}
|
|
71
|
-
if (options.databaseUrl) {
|
|
72
|
-
return introspectDatabase(options.databaseUrl);
|
|
73
|
-
}
|
|
74
|
-
throw new Error("Either schemaPath or databaseUrl must be provided");
|
|
75
|
-
}
|
package/dist/kysely-adapter.d.ts
DELETED
|
@@ -1,49 +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
|
-
import type { Kysely } from "kysely";
|
|
8
|
-
export type KyselyDialect = "sqlite" | "postgres" | "mysql";
|
|
9
|
-
export interface KyselyAdapterOptions {
|
|
10
|
-
/** Database dialect */
|
|
11
|
-
dialect: KyselyDialect;
|
|
12
|
-
/** Database connection URL */
|
|
13
|
-
connectionUrl?: string;
|
|
14
|
-
/** SQLite database path (for SQLite dialect) */
|
|
15
|
-
databasePath?: string;
|
|
16
|
-
/** Connection pool settings */
|
|
17
|
-
pool?: {
|
|
18
|
-
min?: number;
|
|
19
|
-
max?: number;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
export interface KyselyAdapter<DB> {
|
|
23
|
-
/** The Kysely instance */
|
|
24
|
-
db: Kysely<DB>;
|
|
25
|
-
/** Destroy the connection pool */
|
|
26
|
-
destroy: () => Promise<void>;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Creates a Kysely adapter for use with ZenStack schemas
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```ts
|
|
33
|
-
* import { createKyselyAdapter } from "zenstack-kit";
|
|
34
|
-
* import type { Database } from "./generated/kysely-types";
|
|
35
|
-
*
|
|
36
|
-
* const { db, destroy } = await createKyselyAdapter<Database>({
|
|
37
|
-
* dialect: "postgres",
|
|
38
|
-
* connectionUrl: process.env.DATABASE_URL,
|
|
39
|
-
* });
|
|
40
|
-
*
|
|
41
|
-
* // Use db for queries
|
|
42
|
-
* const users = await db.selectFrom("user").selectAll().execute();
|
|
43
|
-
*
|
|
44
|
-
* // Clean up
|
|
45
|
-
* await destroy();
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
export declare function createKyselyAdapter<DB>(options: KyselyAdapterOptions): Promise<KyselyAdapter<DB>>;
|
|
49
|
-
//# sourceMappingURL=kysely-adapter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"kysely-adapter.d.ts","sourceRoot":"","sources":["../src/kysely-adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAW,MAAM,QAAQ,CAAC;AAE9C,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,UAAU,GAAG,OAAO,CAAC;AAE5D,MAAM,WAAW,oBAAoB;IACnC,uBAAuB;IACvB,OAAO,EAAE,aAAa,CAAC;IACvB,8BAA8B;IAC9B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gDAAgD;IAChD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+BAA+B;IAC/B,IAAI,CAAC,EAAE;QACL,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,GAAG,CAAC,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED,MAAM,WAAW,aAAa,CAAC,EAAE;IAC/B,0BAA0B;IAC1B,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;IACf,kCAAkC;IAClC,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,mBAAmB,CAAC,EAAE,EAC1C,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,CAwD5B"}
|
package/dist/kysely-adapter.js
DELETED
|
@@ -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
|
-
}
|
package/dist/migrate-apply.d.ts
DELETED
|
@@ -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"}
|
package/dist/migrate-apply.js
DELETED
|
@@ -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
|
-
}
|
package/dist/migrations.d.ts
DELETED
|
@@ -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
|
package/dist/migrations.d.ts.map
DELETED
|
@@ -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;IACtC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,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,SAAS;IACxB,yBAAyB;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,yCAAyC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