nitro-drizzle 0.0.0 → 0.2.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.
- package/LICENSE +21 -0
- package/README.md +247 -0
- package/dist/config/defineConfig.d.mts +410 -0
- package/dist/config/defineConfig.mjs +34 -0
- package/dist/config/defineConfig.mjs.map +1 -0
- package/dist/config.d.mts +2 -0
- package/dist/config.mjs +2 -0
- package/dist/context/internal/async.mjs +15 -0
- package/dist/context/internal/async.mjs.map +1 -0
- package/dist/context/internal/config.mjs +31 -0
- package/dist/context/internal/config.mjs.map +1 -0
- package/dist/context/internal/fs.mjs +15 -0
- package/dist/context/internal/fs.mjs.map +1 -0
- package/dist/context/internal/logger.mjs +20 -0
- package/dist/context/internal/logger.mjs.map +1 -0
- package/dist/context/internal/templates.mjs +40 -0
- package/dist/context/internal/templates.mjs.map +1 -0
- package/dist/context/internal/virtual.mjs +71 -0
- package/dist/context/internal/virtual.mjs.map +1 -0
- package/dist/context.d.mts +113 -0
- package/dist/context.mjs +78 -0
- package/dist/context.mjs.map +1 -0
- package/dist/dialects/index.d.mts +39 -0
- package/dist/dialects/index.mjs +1 -0
- package/dist/dialects/mysql.d.mts +30 -0
- package/dist/dialects/mysql.mjs +30 -0
- package/dist/dialects/mysql.mjs.map +1 -0
- package/dist/dialects/postgresql.d.mts +29 -0
- package/dist/dialects/postgresql.mjs +29 -0
- package/dist/dialects/postgresql.mjs.map +1 -0
- package/dist/dialects/sqlite.d.mts +29 -0
- package/dist/dialects/sqlite.mjs +29 -0
- package/dist/dialects/sqlite.mjs.map +1 -0
- package/dist/drivers/d1-http.d.mts +41 -0
- package/dist/drivers/d1-http.mjs +105 -0
- package/dist/drivers/d1-http.mjs.map +1 -0
- package/dist/drivers/d1.d.mts +26 -0
- package/dist/drivers/d1.mjs +52 -0
- package/dist/drivers/d1.mjs.map +1 -0
- package/dist/drivers/db0.d.mts +20 -0
- package/dist/drivers/db0.mjs +27 -0
- package/dist/drivers/db0.mjs.map +1 -0
- package/dist/drivers/index.d.mts +35 -0
- package/dist/drivers/index.mjs +14 -0
- package/dist/drivers/index.mjs.map +1 -0
- package/dist/drivers/internal/d1-dialect.mjs +41 -0
- package/dist/drivers/internal/d1-dialect.mjs.map +1 -0
- package/dist/drivers/internal/sql.mjs +6 -0
- package/dist/drivers/internal/sql.mjs.map +1 -0
- package/dist/drivers/mysql.d.mts +27 -0
- package/dist/drivers/mysql.mjs +32 -0
- package/dist/drivers/mysql.mjs.map +1 -0
- package/dist/drivers/pglite.d.mts +29 -0
- package/dist/drivers/pglite.mjs +29 -0
- package/dist/drivers/pglite.mjs.map +1 -0
- package/dist/drivers/postgresql.d.mts +27 -0
- package/dist/drivers/postgresql.mjs +30 -0
- package/dist/drivers/postgresql.mjs.map +1 -0
- package/dist/drivers/sqlite.d.mts +28 -0
- package/dist/drivers/sqlite.mjs +30 -0
- package/dist/drivers/sqlite.mjs.map +1 -0
- package/dist/meta.d.mts +8 -0
- package/dist/meta.mjs +9 -0
- package/dist/meta.mjs.map +1 -0
- package/dist/migrations/internal/migrate.d.mts +16 -0
- package/dist/migrations/internal/migrate.mjs +33 -0
- package/dist/migrations/internal/migrate.mjs.map +1 -0
- package/dist/migrations/migrate.d.mts +16 -0
- package/dist/migrations/migrate.mjs +23 -0
- package/dist/migrations/migrate.mjs.map +1 -0
- package/dist/migrations/task.d.mts +7 -0
- package/dist/migrations/task.mjs +11 -0
- package/dist/migrations/task.mjs.map +1 -0
- package/dist/migrations/useMigrations.d.mts +46 -0
- package/dist/migrations/useMigrations.mjs +57 -0
- package/dist/migrations/useMigrations.mjs.map +1 -0
- package/dist/migrations.d.mts +4 -0
- package/dist/migrations.mjs +3 -0
- package/dist/module/internal/assets.d.mts +12 -0
- package/dist/module/internal/assets.mjs +21 -0
- package/dist/module/internal/assets.mjs.map +1 -0
- package/dist/module/internal/externals.mjs +19 -0
- package/dist/module/internal/externals.mjs.map +1 -0
- package/dist/module/internal/fs.mjs +11 -0
- package/dist/module/internal/fs.mjs.map +1 -0
- package/dist/module/internal/path.mjs +11 -0
- package/dist/module/internal/path.mjs.map +1 -0
- package/dist/module/internal/reload.mjs +17 -0
- package/dist/module/internal/reload.mjs.map +1 -0
- package/dist/module/internal/resolver.mjs +27 -0
- package/dist/module/internal/resolver.mjs.map +1 -0
- package/dist/module/internal/rollup.mjs +8 -0
- package/dist/module/internal/rollup.mjs.map +1 -0
- package/dist/module/internal/types.mjs +39 -0
- package/dist/module/internal/types.mjs.map +1 -0
- package/dist/module/internal/virtual.mjs +23 -0
- package/dist/module/internal/virtual.mjs.map +1 -0
- package/dist/module.d.mts +37 -0
- package/dist/module.mjs +82 -0
- package/dist/module.mjs.map +1 -0
- package/dist/plugins/init.d.mts +24 -0
- package/dist/plugins/init.mjs +33 -0
- package/dist/plugins/init.mjs.map +1 -0
- package/dist/plugins/migrate.d.mts +22 -0
- package/dist/plugins/migrate.mjs +25 -0
- package/dist/plugins/migrate.mjs.map +1 -0
- package/dist/runtime/internal/config.mjs +24 -0
- package/dist/runtime/internal/config.mjs.map +1 -0
- package/dist/runtime/internal/createDatasource.mjs +15 -0
- package/dist/runtime/internal/createDatasource.mjs.map +1 -0
- package/dist/runtime/useDatasource.d.mts +19 -0
- package/dist/runtime/useDatasource.mjs +35 -0
- package/dist/runtime/useDatasource.mjs.map +1 -0
- package/dist/runtime.d.mts +79 -0
- package/dist/runtime.mjs +2 -0
- package/dist/shared.d.mts +12 -0
- package/dist/shared.mjs +1 -0
- package/dist/utils/usePrimaryKey.d.mts +14 -0
- package/dist/utils/usePrimaryKey.mjs +19 -0
- package/dist/utils/usePrimaryKey.mjs.map +1 -0
- package/dist/utils.d.mts +2 -0
- package/dist/utils.mjs +2 -0
- package/package.json +100 -3
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { defineDriver } from "./index.mjs";
|
|
2
|
+
import { drizzle } from "drizzle-orm/pglite";
|
|
3
|
+
import { PGlite } from "@electric-sql/pglite";
|
|
4
|
+
//#region src/drivers/pglite.ts
|
|
5
|
+
/**
|
|
6
|
+
* PGlite datasource driver for PostgreSQL in the browser.
|
|
7
|
+
* @template TSchema - The schema type
|
|
8
|
+
* @param options - PGlite configuration options
|
|
9
|
+
* @param schema - The Drizzle schema
|
|
10
|
+
* @returns A Datasource instance
|
|
11
|
+
*/
|
|
12
|
+
var pglite_default = defineDriver((options, schema) => {
|
|
13
|
+
const { dataDir, ...other } = options;
|
|
14
|
+
const database = drizzle(new PGlite(dataDir, other), { schema });
|
|
15
|
+
return {
|
|
16
|
+
database,
|
|
17
|
+
schema,
|
|
18
|
+
async waitReady() {
|
|
19
|
+
await database.$client.waitReady;
|
|
20
|
+
},
|
|
21
|
+
async close() {
|
|
22
|
+
await database.$client.close();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
//#endregion
|
|
27
|
+
export { pglite_default as default };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=pglite.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pglite.mjs","names":[],"sources":["../../src/drivers/pglite.ts"],"sourcesContent":["import { drizzle } from \"drizzle-orm/pglite\";\nimport { PGlite, type PGliteOptions } from \"@electric-sql/pglite\";\nimport { defineDriver, type Schema } from \".\";\n\n/**\n * PGlite datasource driver for PostgreSQL in the browser.\n * @template TSchema - The schema type\n * @param options - PGlite configuration options\n * @param schema - The Drizzle schema\n * @returns A Datasource instance\n */\nexport default defineDriver(<TSchema extends Schema>(options: PGliteOptions, schema: TSchema) => {\n const { dataDir, ...other } = options;\n const connector = new PGlite(dataDir, other);\n const database = drizzle(connector, { schema });\n return {\n database,\n schema,\n async waitReady() {\n await database.$client.waitReady;\n },\n async close() {\n await database.$client.close();\n },\n };\n});\n\n/**\n * Configuration options for the PGlite driver.\n */\nexport type Config = {\n /** Directory path for storing database data. */\n dataDir?: string;\n /** Additional PGlite options. */\n options?: PGliteOptions;\n};\n"],"mappings":";;;;;;;;;;;AAWA,IAAA,iBAAe,cAAsC,SAAwB,WAAoB;CAC/F,MAAM,EAAE,SAAS,GAAG,UAAU;CAE9B,MAAM,WAAW,QAAQ,IADH,OAAO,SAAS,KACL,GAAG,EAAE,OAAO,CAAC;CAC9C,OAAO;EACL;EACA;EACA,MAAM,YAAY;GAChB,MAAM,SAAS,QAAQ;EACzB;EACA,MAAM,QAAQ;GACZ,MAAM,SAAS,QAAQ,MAAM;EAC/B;CACF;AACF,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import createPostgres, { Options as Options$1 } from "postgres";
|
|
2
|
+
|
|
3
|
+
//#region src/drivers/postgresql.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* PostgreSQL datasource driver using postgres.js.
|
|
6
|
+
* @template TSchema - The schema type
|
|
7
|
+
* @param options - Driver configuration options
|
|
8
|
+
* @param schema - The Drizzle schema
|
|
9
|
+
* @returns A Datasource instance
|
|
10
|
+
*/
|
|
11
|
+
declare const _default: <TSchema extends Record<string, any>>(options: Options, schema: TSchema) => {
|
|
12
|
+
database: import("drizzle-orm/postgres-js").PostgresJsDatabase<TSchema> & {
|
|
13
|
+
$client: createPostgres.Sql<{}>;
|
|
14
|
+
};
|
|
15
|
+
schema: TSchema;
|
|
16
|
+
waitReady(): Promise<void>;
|
|
17
|
+
close(): Promise<void>;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Configuration options for the PostgreSQL driver.
|
|
21
|
+
*/
|
|
22
|
+
type Options = Options$1<Record<string, createPostgres.PostgresType>> & {
|
|
23
|
+
/** Connection URL string (optional if connection config is provided). */url?: string;
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
export { Options, _default as default };
|
|
27
|
+
//# sourceMappingURL=postgresql.d.mts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { defineDriver } from "./index.mjs";
|
|
2
|
+
import { SELECT_1 } from "./internal/sql.mjs";
|
|
3
|
+
import { drizzle } from "drizzle-orm/postgres-js";
|
|
4
|
+
import createPostgres from "postgres";
|
|
5
|
+
//#region src/drivers/postgresql.ts
|
|
6
|
+
/**
|
|
7
|
+
* PostgreSQL datasource driver using postgres.js.
|
|
8
|
+
* @template TSchema - The schema type
|
|
9
|
+
* @param options - Driver configuration options
|
|
10
|
+
* @param schema - The Drizzle schema
|
|
11
|
+
* @returns A Datasource instance
|
|
12
|
+
*/
|
|
13
|
+
var postgresql_default = defineDriver((options, schema) => {
|
|
14
|
+
const { url, ...other } = options;
|
|
15
|
+
const database = drizzle(url ? createPostgres(url, other) : createPostgres(other), { schema });
|
|
16
|
+
return {
|
|
17
|
+
database,
|
|
18
|
+
schema,
|
|
19
|
+
async waitReady() {
|
|
20
|
+
await database.execute(SELECT_1);
|
|
21
|
+
},
|
|
22
|
+
async close() {
|
|
23
|
+
await database.$client.end();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
//#endregion
|
|
28
|
+
export { postgresql_default as default };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=postgresql.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgresql.mjs","names":[],"sources":["../../src/drivers/postgresql.ts"],"sourcesContent":["import { drizzle } from \"drizzle-orm/postgres-js\";\nimport createPostgres, { type Options as PostgresOptions } from \"postgres\";\nimport { defineDriver } from \".\";\nimport { SELECT_1 } from \"./internal/sql\";\n\n/**\n * PostgreSQL datasource driver using postgres.js.\n * @template TSchema - The schema type\n * @param options - Driver configuration options\n * @param schema - The Drizzle schema\n * @returns A Datasource instance\n */\nexport default defineDriver(\n <TSchema extends Record<string, any>>(options: Options, schema: TSchema) => {\n const { url, ...other } = options;\n const client = url ? createPostgres(url, other) : createPostgres(other);\n const database = drizzle(client, { schema });\n return {\n database,\n schema,\n async waitReady() {\n await database.execute(SELECT_1);\n },\n async close() {\n await database.$client.end();\n },\n };\n },\n);\n\n/**\n * Configuration options for the PostgreSQL driver.\n */\nexport type Options = PostgresOptions<Record<string, createPostgres.PostgresType>> & {\n /** Connection URL string (optional if connection config is provided). */\n url?: string;\n};\n"],"mappings":";;;;;;;;;;;;AAYA,IAAA,qBAAe,cACyB,SAAkB,WAAoB;CAC1E,MAAM,EAAE,KAAK,GAAG,UAAU;CAE1B,MAAM,WAAW,QADF,MAAM,eAAe,KAAK,KAAK,IAAI,eAAe,KAAK,GACrC,EAAE,OAAO,CAAC;CAC3C,OAAO;EACL;EACA;EACA,MAAM,YAAY;GAChB,MAAM,SAAS,QAAQ,QAAQ;EACjC;EACA,MAAM,QAAQ;GACZ,MAAM,SAAS,QAAQ,IAAI;EAC7B;CACF;AACF,CACF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Schema } from "./index.mjs";
|
|
2
|
+
import sqlite3, { Options as Options$1 } from "better-sqlite3";
|
|
3
|
+
|
|
4
|
+
//#region src/drivers/sqlite.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* SQLite datasource driver using better-sqlite3.
|
|
7
|
+
* @template TSchema - The schema type
|
|
8
|
+
* @param config - Driver configuration options
|
|
9
|
+
* @param schema - The Drizzle schema
|
|
10
|
+
* @returns A Datasource instance
|
|
11
|
+
*/
|
|
12
|
+
declare const _default: <TSchema extends Schema>(config: Options, schema: TSchema) => {
|
|
13
|
+
database: import("drizzle-orm/better-sqlite3").BetterSQLite3Database<TSchema> & {
|
|
14
|
+
$client: sqlite3.Database;
|
|
15
|
+
};
|
|
16
|
+
schema: TSchema;
|
|
17
|
+
waitReady(): Promise<void>;
|
|
18
|
+
close(): Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Configuration options for the SQLite driver.
|
|
22
|
+
*/
|
|
23
|
+
type Options = {
|
|
24
|
+
/** Database file path or URL. */url: string;
|
|
25
|
+
} & Options$1;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { Options, _default as default };
|
|
28
|
+
//# sourceMappingURL=sqlite.d.mts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { defineDriver } from "./index.mjs";
|
|
2
|
+
import { SELECT_1 } from "./internal/sql.mjs";
|
|
3
|
+
import sqlite3 from "better-sqlite3";
|
|
4
|
+
import { drizzle } from "drizzle-orm/better-sqlite3";
|
|
5
|
+
//#region src/drivers/sqlite.ts
|
|
6
|
+
/**
|
|
7
|
+
* SQLite datasource driver using better-sqlite3.
|
|
8
|
+
* @template TSchema - The schema type
|
|
9
|
+
* @param config - Driver configuration options
|
|
10
|
+
* @param schema - The Drizzle schema
|
|
11
|
+
* @returns A Datasource instance
|
|
12
|
+
*/
|
|
13
|
+
var sqlite_default = defineDriver((config, schema) => {
|
|
14
|
+
const { url, ...options } = config;
|
|
15
|
+
const database = drizzle(sqlite3(url, options), { schema });
|
|
16
|
+
return {
|
|
17
|
+
database,
|
|
18
|
+
schema,
|
|
19
|
+
async waitReady() {
|
|
20
|
+
if (!database.$client.open) database.run(SELECT_1);
|
|
21
|
+
},
|
|
22
|
+
async close() {
|
|
23
|
+
database.$client.close();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
//#endregion
|
|
28
|
+
export { sqlite_default as default };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=sqlite.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite.mjs","names":[],"sources":["../../src/drivers/sqlite.ts"],"sourcesContent":["import sqlite3, { type Options as BetterSqlite3Options } from \"better-sqlite3\";\nimport { drizzle } from \"drizzle-orm/better-sqlite3\";\nimport { defineDriver, type Schema } from \".\";\nimport { SELECT_1 } from \"./internal/sql\";\n\n/**\n * SQLite datasource driver using better-sqlite3.\n * @template TSchema - The schema type\n * @param config - Driver configuration options\n * @param schema - The Drizzle schema\n * @returns A Datasource instance\n */\nexport default defineDriver(<TSchema extends Schema>(config: Options, schema: TSchema) => {\n const { url, ...options } = config;\n const sqlite = sqlite3(url, options);\n const database = drizzle(sqlite, { schema });\n return {\n database,\n schema,\n async waitReady() {\n if (!database.$client.open) {\n database.run(SELECT_1);\n }\n },\n async close() {\n database.$client.close();\n },\n };\n});\n\n/**\n * Configuration options for the SQLite driver.\n */\nexport type Options = {\n /** Database file path or URL. */\n url: string;\n} & BetterSqlite3Options;\n"],"mappings":";;;;;;;;;;;;AAYA,IAAA,iBAAe,cAAsC,QAAiB,WAAoB;CACxF,MAAM,EAAE,KAAK,GAAG,YAAY;CAE5B,MAAM,WAAW,QADF,QAAQ,KAAK,OACE,GAAG,EAAE,OAAO,CAAC;CAC3C,OAAO;EACL;EACA;EACA,MAAM,YAAY;GAChB,IAAI,CAAC,SAAS,QAAQ,MACpB,SAAS,IAAI,QAAQ;EAEzB;EACA,MAAM,QAAQ;GACZ,SAAS,QAAQ,MAAM;EACzB;CACF;AACF,CAAC"}
|
package/dist/meta.d.mts
ADDED
package/dist/meta.mjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { URL, fileURLToPath } from "node:url";
|
|
2
|
+
import { name as pkgName } from "nitro-drizzle/package.json" with { type: "json" };
|
|
3
|
+
//#region src/meta.ts
|
|
4
|
+
/** Directory path of the package. */
|
|
5
|
+
const pkgDir = fileURLToPath(new URL(".", import.meta.resolve("nitro-drizzle/package.json")));
|
|
6
|
+
//#endregion
|
|
7
|
+
export { pkgDir, pkgName };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=meta.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meta.mjs","names":[],"sources":["../src/meta.ts"],"sourcesContent":["import { fileURLToPath, URL } from \"node:url\";\nimport { name as pkgName } from \"nitro-drizzle/package.json\" with { type: \"json\" };\n\nexport { pkgName };\n\n/** Directory path of the package. */\nexport const pkgDir: string = fileURLToPath(\n new URL(\".\", import.meta.resolve(\"nitro-drizzle/package.json\")),\n);\n"],"mappings":";;;;AAMA,MAAa,SAAiB,cAC5B,IAAI,IAAI,KAAK,OAAO,KAAK,QAAQ,4BAA4B,CAAC,CAChE"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { MigrationMeta } from "drizzle-orm/migrator";
|
|
2
|
+
|
|
3
|
+
//#region src/migrations/internal/migrate.d.ts
|
|
4
|
+
/** Configuration options for database migrations. */
|
|
5
|
+
type MigrationConfig = Partial<{
|
|
6
|
+
/** Schema name for migrations. */schema: string; /** Table name for storing migration metadata. */
|
|
7
|
+
table: string;
|
|
8
|
+
}>;
|
|
9
|
+
/** Migration information including SQL statements and metadata. */
|
|
10
|
+
interface Migration extends MigrationMeta {
|
|
11
|
+
idx: number;
|
|
12
|
+
filename: string;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { Migration, MigrationConfig };
|
|
16
|
+
//# sourceMappingURL=migrate.d.mts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/migrations/internal/migrate.ts
|
|
2
|
+
/**
|
|
3
|
+
* Migrates a database using the provided migrations.
|
|
4
|
+
* @template TSession - The session type
|
|
5
|
+
* @param database - The Drizzle database instance
|
|
6
|
+
* @param migrations - Iterable or async iterable of migrations
|
|
7
|
+
* @param config - Migration configuration options
|
|
8
|
+
*/
|
|
9
|
+
async function migrateDatabase(database, migrations, config) {
|
|
10
|
+
for await (const { filename, idx, ...migrationsMeta } of migrations) try {
|
|
11
|
+
await database.dialect.migrate([migrationsMeta], database.session, {
|
|
12
|
+
migrationsSchema: config?.schema,
|
|
13
|
+
migrationsTable: config?.table
|
|
14
|
+
});
|
|
15
|
+
} catch (cause) {
|
|
16
|
+
throw new MigrationError({ migration: {
|
|
17
|
+
idx,
|
|
18
|
+
filename
|
|
19
|
+
} }, cause);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** Error thrown when a migration fails. */
|
|
23
|
+
var MigrationError = class extends Error {
|
|
24
|
+
data;
|
|
25
|
+
constructor(data, cause) {
|
|
26
|
+
super(`Migration failed: ${data.migration.filename}#${data.migration.idx}`, { cause });
|
|
27
|
+
this.data = data;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { MigrationError, migrateDatabase };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=migrate.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate.mjs","names":[],"sources":["../../../src/migrations/internal/migrate.ts"],"sourcesContent":["import type {\n MigrationConfig as DrizzleMigrationConfig,\n MigrationMeta,\n} from \"drizzle-orm/migrator\";\n\n/** Configuration options for database migrations. */\nexport type MigrationConfig = Partial<{\n /** Schema name for migrations. */\n schema: string;\n /** Table name for storing migration metadata. */\n table: string;\n}>;\n\n/**\n * Migrates a database using the provided migrations.\n * @template TSession - The session type\n * @param database - The Drizzle database instance\n * @param migrations - Iterable or async iterable of migrations\n * @param config - Migration configuration options\n */\nexport async function migrateDatabase<TSession = any>(\n database: DrizzleDatabase<TSession>,\n migrations: Iterable<Migration> | AsyncIterable<Migration>,\n config?: MigrationConfig,\n) {\n for await (const { filename, idx, ...migrationsMeta } of migrations) {\n try {\n await database.dialect.migrate([migrationsMeta], database.session, {\n migrationsSchema: config?.schema,\n migrationsTable: config?.table,\n });\n } catch (cause) {\n throw new MigrationError({ migration: { idx, filename } }, cause);\n }\n }\n}\n\n/** Options for creating a MigrationError. */\nexport interface MigrationErrorOptions {\n migration: Pick<Migration, \"idx\" | \"filename\">;\n}\n\n/** Error thrown when a migration fails. */\nexport class MigrationError extends Error {\n constructor(\n readonly data: MigrationErrorOptions,\n cause: unknown,\n ) {\n super(`Migration failed: ${data.migration.filename}#${data.migration.idx}`, { cause });\n }\n}\n\n/** Interface for a Drizzle database dialect with migrate capabilities. */\nexport interface DrizzleDatabaseDialect<TSession = any> {\n migrate(\n migrations: Iterable<MigrationMeta>,\n session: TSession,\n config: Partial<DrizzleMigrationConfig> | string,\n ): any;\n}\n\n/** Interface for a Drizzle database instance. */\nexport interface DrizzleDatabase<TSession = any> {\n dialect: DrizzleDatabaseDialect<TSession>;\n session: TSession;\n}\n\n/** Migration information including SQL statements and metadata. */\nexport interface Migration extends MigrationMeta {\n idx: number;\n filename: string;\n}\n"],"mappings":";;;;;;;;AAoBA,eAAsB,gBACpB,UACA,YACA,QACA;CACA,WAAW,MAAM,EAAE,UAAU,KAAK,GAAG,oBAAoB,YACvD,IAAI;EACF,MAAM,SAAS,QAAQ,QAAQ,CAAC,cAAc,GAAG,SAAS,SAAS;GACjE,kBAAkB,QAAQ;GAC1B,iBAAiB,QAAQ;EAC3B,CAAC;CACH,SAAS,OAAO;EACd,MAAM,IAAI,eAAe,EAAE,WAAW;GAAE;GAAK;EAAS,EAAE,GAAG,KAAK;CAClE;AAEJ;;AAQA,IAAa,iBAAb,cAAoC,MAAM;CAE7B;CADX,YACE,MACA,OACA;EACA,MAAM,qBAAqB,KAAK,UAAU,SAAS,GAAG,KAAK,UAAU,OAAO,EAAE,MAAM,CAAC;EAH5E,KAAA,OAAA;CAIX;AACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { MigrationConfig } from "./internal/migrate.mjs";
|
|
2
|
+
import { DatasourceRegistry } from "nitro-drizzle/runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/migrations/migrate.d.ts
|
|
5
|
+
/** Result of a migration operation. */
|
|
6
|
+
type MigrationResult = {};
|
|
7
|
+
/**
|
|
8
|
+
* Runs migrations for a specific datasource.
|
|
9
|
+
* @template TName - The datasource name
|
|
10
|
+
* @param name - The datasource name to migrate
|
|
11
|
+
* @returns Migration result
|
|
12
|
+
*/
|
|
13
|
+
declare function migrate<TName extends keyof DatasourceRegistry & string>(name: TName): Promise<MigrationResult>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { type MigrationConfig, MigrationResult, migrate };
|
|
16
|
+
//# sourceMappingURL=migrate.d.mts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useMigrations } from "./useMigrations.mjs";
|
|
2
|
+
import { migrateDatabase } from "./internal/migrate.mjs";
|
|
3
|
+
import { migrationConfig } from "#nitro-drizzle/migrations";
|
|
4
|
+
import { useDatasource } from "nitro-drizzle/runtime";
|
|
5
|
+
//#region src/migrations/migrate.ts
|
|
6
|
+
/**
|
|
7
|
+
* Runs migrations for a specific datasource.
|
|
8
|
+
* @template TName - The datasource name
|
|
9
|
+
* @param name - The datasource name to migrate
|
|
10
|
+
* @returns Migration result
|
|
11
|
+
*/
|
|
12
|
+
async function migrate(name) {
|
|
13
|
+
const { database, waitReady } = await useDatasource(name);
|
|
14
|
+
const migrations = await useMigrations(name);
|
|
15
|
+
const config = migrationConfig[name];
|
|
16
|
+
await waitReady();
|
|
17
|
+
await migrateDatabase(database, migrations, config);
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { migrate };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=migrate.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate.mjs","names":[],"sources":["../../src/migrations/migrate.ts"],"sourcesContent":["import { useDatasource, type DatasourceRegistry } from \"nitro-drizzle/runtime\";\nimport { migrationConfig } from \"#nitro-drizzle/migrations\";\nimport { useMigrations } from \"./useMigrations\";\nimport { migrateDatabase, type DrizzleDatabase, type MigrationConfig } from \"./internal/migrate\";\n\n/** Result of a migration operation. */\nexport type MigrationResult = {};\n\nexport type { MigrationConfig };\n\n/**\n * Runs migrations for a specific datasource.\n * @template TName - The datasource name\n * @param name - The datasource name to migrate\n * @returns Migration result\n */\nexport async function migrate<TName extends keyof DatasourceRegistry & string>(\n name: TName,\n): Promise<MigrationResult> {\n const { database, waitReady } = await useDatasource(name);\n const migrations = await useMigrations(name);\n const config = migrationConfig[name];\n await waitReady();\n await migrateDatabase(database as any as DrizzleDatabase, migrations, config);\n return {};\n}\n"],"mappings":";;;;;;;;;;;AAgBA,eAAsB,QACpB,MAC0B;CAC1B,MAAM,EAAE,UAAU,cAAc,MAAM,cAAc,IAAI;CACxD,MAAM,aAAa,MAAM,cAAc,IAAI;CAC3C,MAAM,SAAS,gBAAgB;CAC/B,MAAM,UAAU;CAChB,MAAM,gBAAgB,UAAoC,YAAY,MAAM;CAC5E,OAAO,CAAC;AACV"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { migrate } from "./migrate.mjs";
|
|
2
|
+
import { defineTask } from "nitropack/runtime";
|
|
3
|
+
//#region src/migrations/task.ts
|
|
4
|
+
var task_default = defineTask({ async run(event) {
|
|
5
|
+
const { name } = event.payload;
|
|
6
|
+
return { result: await migrate(name) };
|
|
7
|
+
} });
|
|
8
|
+
//#endregion
|
|
9
|
+
export { task_default as default };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=task.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task.mjs","names":[],"sources":["../../src/migrations/task.ts"],"sourcesContent":["import { defineTask } from \"nitropack/runtime\";\nimport { migrate, type MigrationResult } from \"./migrate\";\nimport type { DatasourceRegistry } from \"nitro-drizzle/runtime\";\n\nexport default defineTask<MigrationResult>({\n async run(event) {\n const { name } = event.payload as { name: keyof DatasourceRegistry & string };\n const result = await migrate(name);\n return { result };\n },\n});\n"],"mappings":";;;AAIA,IAAA,eAAe,WAA4B,EACzC,MAAM,IAAI,OAAO;CACf,MAAM,EAAE,SAAS,MAAM;CAEvB,OAAO,EAAE,QAAA,MADY,QAAQ,IAAI,EACjB;AAClB,EACF,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Migration } from "./internal/migrate.mjs";
|
|
2
|
+
import { DatasourceRegistry } from "nitro-drizzle/runtime";
|
|
3
|
+
import { Storage } from "unstorage";
|
|
4
|
+
|
|
5
|
+
//#region src/migrations/useMigrations.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Gets the storage for a specific datasource's migrations.
|
|
8
|
+
* @template TName - The datasource name
|
|
9
|
+
* @param name - The datasource name
|
|
10
|
+
* @returns Storage instance for migrations
|
|
11
|
+
*/
|
|
12
|
+
declare function useMigrationsStorage<TName extends keyof DatasourceRegistry>(name: TName): Storage<string>;
|
|
13
|
+
/** Storage key for the migration journal. */
|
|
14
|
+
declare const JOURNAL_STORAGE_KEY: "meta/_journal.json";
|
|
15
|
+
/**
|
|
16
|
+
* Gets an async iterable of migrations for a specific datasource.
|
|
17
|
+
* @template TName - The datasource name
|
|
18
|
+
* @param name - The datasource name
|
|
19
|
+
* @returns Async iterable of migrations
|
|
20
|
+
* @throws If migration journal is not found
|
|
21
|
+
*/
|
|
22
|
+
declare function useMigrations<TName extends keyof DatasourceRegistry>(name: TName): Promise<AsyncIterable<Migration>>;
|
|
23
|
+
/** Single entry in the migration journal. */
|
|
24
|
+
interface MigrationJournalItem {
|
|
25
|
+
/** Migration index/order number. */
|
|
26
|
+
idx: number;
|
|
27
|
+
/** Migration version string. */
|
|
28
|
+
version: string;
|
|
29
|
+
/** Timestamp when migration was created. */
|
|
30
|
+
when: number;
|
|
31
|
+
/** Migration tag/identifier. */
|
|
32
|
+
tag: string;
|
|
33
|
+
/** Indicates if this entry has breakpoints. */
|
|
34
|
+
breakpoints: true;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Migration journal containing all migration entries.
|
|
38
|
+
* @see https://github.com/drizzle-team/drizzle-orm/blob/48e5406027103a9fca6eb66417187c4a8b5c6aa3/drizzle-kit/src/utils.ts#L63
|
|
39
|
+
*/
|
|
40
|
+
interface MigrationJournal {
|
|
41
|
+
/** List of migration entries. */
|
|
42
|
+
entries: Iterable<MigrationJournalItem>;
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { JOURNAL_STORAGE_KEY, MigrationJournal, MigrationJournalItem, useMigrations, useMigrationsStorage };
|
|
46
|
+
//# sourceMappingURL=useMigrations.d.mts.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { useStorage } from "nitropack/runtime";
|
|
2
|
+
import { createError } from "h3";
|
|
3
|
+
import { digest } from "ohash";
|
|
4
|
+
import { MIGRATIONS_STORAGE_BASE } from "#nitro-drizzle/migrations";
|
|
5
|
+
//#region src/migrations/useMigrations.ts
|
|
6
|
+
/**
|
|
7
|
+
* Gets the storage for a specific datasource's migrations.
|
|
8
|
+
* @template TName - The datasource name
|
|
9
|
+
* @param name - The datasource name
|
|
10
|
+
* @returns Storage instance for migrations
|
|
11
|
+
*/
|
|
12
|
+
function useMigrationsStorage(name) {
|
|
13
|
+
return useStorage(`assets:${MIGRATIONS_STORAGE_BASE}:${name}`);
|
|
14
|
+
}
|
|
15
|
+
/** Storage key for the migration journal. */
|
|
16
|
+
const JOURNAL_STORAGE_KEY = "meta/_journal.json";
|
|
17
|
+
/**
|
|
18
|
+
* Gets an async iterable of migrations for a specific datasource.
|
|
19
|
+
* @template TName - The datasource name
|
|
20
|
+
* @param name - The datasource name
|
|
21
|
+
* @returns Async iterable of migrations
|
|
22
|
+
* @throws If migration journal is not found
|
|
23
|
+
*/
|
|
24
|
+
async function useMigrations(name) {
|
|
25
|
+
const storage = useMigrationsStorage(name);
|
|
26
|
+
const journal = await storage.getItem(JOURNAL_STORAGE_KEY);
|
|
27
|
+
if (!journal) throw createError({
|
|
28
|
+
fatal: true,
|
|
29
|
+
message: `Cannot find migration journal for '${name}'`,
|
|
30
|
+
data: { datasource: name }
|
|
31
|
+
});
|
|
32
|
+
return generate(journal, storage);
|
|
33
|
+
}
|
|
34
|
+
const STATEMENT_BREAKPOINT = "--> statement-breakpoint";
|
|
35
|
+
async function* generate(journal, storage) {
|
|
36
|
+
for (const { idx, when, tag, breakpoints } of journal.entries) {
|
|
37
|
+
const filename = tag + ".sql";
|
|
38
|
+
const query = await storage.getItem(filename);
|
|
39
|
+
if (!query) throw createError({
|
|
40
|
+
fatal: true,
|
|
41
|
+
message: `Cannot find migration filename: ${filename}`,
|
|
42
|
+
data: { filename }
|
|
43
|
+
});
|
|
44
|
+
yield {
|
|
45
|
+
filename,
|
|
46
|
+
idx,
|
|
47
|
+
sql: query.split(STATEMENT_BREAKPOINT),
|
|
48
|
+
hash: digest(query),
|
|
49
|
+
folderMillis: when,
|
|
50
|
+
bps: breakpoints
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
export { JOURNAL_STORAGE_KEY, useMigrations, useMigrationsStorage };
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=useMigrations.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMigrations.mjs","names":[],"sources":["../../src/migrations/useMigrations.ts"],"sourcesContent":["import { createError } from \"h3\";\nimport { useStorage } from \"nitropack/runtime\";\nimport type { Storage } from \"unstorage\";\nimport { digest } from \"ohash\";\nimport type { DatasourceRegistry } from \"nitro-drizzle/runtime\";\nimport { MIGRATIONS_STORAGE_BASE } from \"#nitro-drizzle/migrations\";\nimport type { Migration } from \"./internal/migrate\";\n\n/**\n * Gets the storage for a specific datasource's migrations.\n * @template TName - The datasource name\n * @param name - The datasource name\n * @returns Storage instance for migrations\n */\nexport function useMigrationsStorage<TName extends keyof DatasourceRegistry>(\n name: TName,\n): Storage<string> {\n return useStorage<string>(`assets:${MIGRATIONS_STORAGE_BASE}:${name}`);\n}\n\n/** Storage key for the migration journal. */\nexport const JOURNAL_STORAGE_KEY = \"meta/_journal.json\" as const;\n\n/**\n * Gets an async iterable of migrations for a specific datasource.\n * @template TName - The datasource name\n * @param name - The datasource name\n * @returns Async iterable of migrations\n * @throws If migration journal is not found\n */\nexport async function useMigrations<TName extends keyof DatasourceRegistry>(\n name: TName,\n): Promise<AsyncIterable<Migration>> {\n const storage = useMigrationsStorage(name);\n const journal = await storage.getItem<MigrationJournal>(JOURNAL_STORAGE_KEY);\n if (!journal) {\n throw createError({\n fatal: true,\n message: `Cannot find migration journal for '${name}'`,\n data: {\n datasource: name,\n },\n });\n }\n\n return generate(journal, storage);\n}\n\nconst STATEMENT_BREAKPOINT = \"--> statement-breakpoint\" as const;\n\nasync function* generate(journal: MigrationJournal, storage: Storage<string>) {\n for (const { idx, when, tag, breakpoints } of journal.entries) {\n const filename = tag + \".sql\";\n const query = await storage.getItem<string>(filename);\n\n if (!query) {\n throw createError({\n fatal: true,\n message: `Cannot find migration filename: ${filename}`,\n data: {\n filename,\n },\n });\n }\n\n const migration: Migration = {\n filename,\n idx,\n sql: query.split(STATEMENT_BREAKPOINT),\n hash: digest(query),\n folderMillis: when,\n bps: breakpoints,\n };\n\n yield migration;\n }\n}\n\n/** Single entry in the migration journal. */\nexport interface MigrationJournalItem {\n /** Migration index/order number. */\n idx: number;\n /** Migration version string. */\n version: string;\n /** Timestamp when migration was created. */\n when: number;\n /** Migration tag/identifier. */\n tag: string;\n /** Indicates if this entry has breakpoints. */\n breakpoints: true;\n}\n\n/**\n * Migration journal containing all migration entries.\n * @see https://github.com/drizzle-team/drizzle-orm/blob/48e5406027103a9fca6eb66417187c4a8b5c6aa3/drizzle-kit/src/utils.ts#L63\n */\nexport interface MigrationJournal {\n /** List of migration entries. */\n entries: Iterable<MigrationJournalItem>;\n}\n"],"mappings":";;;;;;;;;;;AAcA,SAAgB,qBACd,MACiB;CACjB,OAAO,WAAmB,UAAU,wBAAwB,GAAG,MAAM;AACvE;;AAGA,MAAa,sBAAsB;;;;;;;;AASnC,eAAsB,cACpB,MACmC;CACnC,MAAM,UAAU,qBAAqB,IAAI;CACzC,MAAM,UAAU,MAAM,QAAQ,QAA0B,mBAAmB;CAC3E,IAAI,CAAC,SACH,MAAM,YAAY;EAChB,OAAO;EACP,SAAS,sCAAsC,KAAK;EACpD,MAAM,EACJ,YAAY,KACd;CACF,CAAC;CAGH,OAAO,SAAS,SAAS,OAAO;AAClC;AAEA,MAAM,uBAAuB;AAE7B,gBAAgB,SAAS,SAA2B,SAA0B;CAC5E,KAAK,MAAM,EAAE,KAAK,MAAM,KAAK,iBAAiB,QAAQ,SAAS;EAC7D,MAAM,WAAW,MAAM;EACvB,MAAM,QAAQ,MAAM,QAAQ,QAAgB,QAAQ;EAEpD,IAAI,CAAC,OACH,MAAM,YAAY;GAChB,OAAO;GACP,SAAS,mCAAmC;GAC5C,MAAM,EACJ,SACF;EACF,CAAC;EAYH,MAAM;GARJ;GACA;GACA,KAAK,MAAM,MAAM,oBAAoB;GACrC,MAAM,OAAO,KAAK;GAClB,cAAc;GACd,KAAK;EAGO;CAChB;AACF"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { MigrationConfig } from "./migrations/internal/migrate.mjs";
|
|
2
|
+
import { JOURNAL_STORAGE_KEY, MigrationJournal, MigrationJournalItem, useMigrations, useMigrationsStorage } from "./migrations/useMigrations.mjs";
|
|
3
|
+
import { MigrationResult, migrate } from "./migrations/migrate.mjs";
|
|
4
|
+
export { JOURNAL_STORAGE_KEY, type MigrationConfig, MigrationJournal, MigrationJournalItem, MigrationResult, migrate, useMigrations, useMigrationsStorage };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DatasourceOptions } from "../../module.mjs";
|
|
2
|
+
//#region src/module/internal/assets.d.ts
|
|
3
|
+
/** Options for configuring migration storage. */
|
|
4
|
+
interface MigrationOptions {
|
|
5
|
+
/** Base storage key path for migrations. */
|
|
6
|
+
storageBase: string;
|
|
7
|
+
/** Whether and which datasources to migrate on initialization. */
|
|
8
|
+
migrateOnInit: boolean | readonly (keyof DatasourceOptions extends never ? string : keyof DatasourceOptions)[];
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { MigrationOptions };
|
|
12
|
+
//# sourceMappingURL=assets.d.mts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/module/internal/assets.ts
|
|
2
|
+
/**
|
|
3
|
+
* Updates Nitro's server assets configuration with migration directories.
|
|
4
|
+
* @see [function serverAssets(nitro: Nitro)](https://github.com/nitrojs/nitro/blob/ef01b092b5fa09d28acb5bd0668ae80505f7c6b4/src/build/virtual/server-assets.ts#L18)
|
|
5
|
+
*/
|
|
6
|
+
async function updateMigrationAssets(context, config, migrationOptions) {
|
|
7
|
+
const migrationAssets = (await context.datasources()).map(({ name, migrations }) => {
|
|
8
|
+
const dir = migrations.assets;
|
|
9
|
+
if (dir) return {
|
|
10
|
+
baseName: `${migrationOptions.storageBase}:${name}`,
|
|
11
|
+
dir
|
|
12
|
+
};
|
|
13
|
+
}).filter((value) => !!value);
|
|
14
|
+
config.serverAssets = [config.serverAssets ?? []].flat().filter((serverAsset) => {
|
|
15
|
+
return serverAsset?.baseName?.startsWith(migrationOptions.storageBase);
|
|
16
|
+
}).concat(migrationAssets);
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { updateMigrationAssets };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=assets.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets.mjs","names":[],"sources":["../../../src/module/internal/assets.ts"],"sourcesContent":["import type { ServerAssetDir, NitroConfig } from \"nitropack/types\";\nimport type { Context } from \"nitro-drizzle/context\";\nimport type { DatasourceOptions } from \"..\";\n\n/** Options for configuring migration storage. */\nexport interface MigrationOptions {\n /** Base storage key path for migrations. */\n storageBase: string;\n /** Whether and which datasources to migrate on initialization. */\n migrateOnInit:\n | boolean\n | readonly (keyof DatasourceOptions extends never ? string : keyof DatasourceOptions)[];\n}\n\n/**\n * Updates Nitro's server assets configuration with migration directories.\n * @see [function serverAssets(nitro: Nitro)](https://github.com/nitrojs/nitro/blob/ef01b092b5fa09d28acb5bd0668ae80505f7c6b4/src/build/virtual/server-assets.ts#L18)\n */\nexport async function updateMigrationAssets(\n context: Context,\n config: NitroConfig,\n migrationOptions: MigrationOptions,\n) {\n const datasources = await context.datasources();\n\n const migrationAssets: ServerAssetDir[] = datasources\n .map(({ name, migrations }) => {\n const dir = migrations.assets;\n if (dir) {\n return {\n baseName: `${migrationOptions.storageBase}:${name}`,\n dir,\n /**\n * @todo Doesn't work in dev mode - 'fs' driver does not support 'pattern'\n * Disabled - include all files to use with meta/_journal.json\n */\n // pattern: '*.sql',\n };\n }\n })\n .filter((value) => !!value);\n\n config.serverAssets = [config.serverAssets ?? []]\n .flat()\n .filter((serverAsset) => {\n return serverAsset?.baseName?.startsWith(migrationOptions.storageBase);\n })\n .concat(migrationAssets);\n}\n"],"mappings":";;;;;AAkBA,eAAsB,sBACpB,SACA,QACA,kBACA;CAGA,MAAM,mBAAoC,MAFhB,QAAQ,YAAY,EAAA,CAG3C,KAAK,EAAE,MAAM,iBAAiB;EAC7B,MAAM,MAAM,WAAW;EACvB,IAAI,KACF,OAAO;GACL,UAAU,GAAG,iBAAiB,YAAY,GAAG;GAC7C;EAMF;CAEJ,CAAC,CAAC,CACD,QAAQ,UAAU,CAAC,CAAC,KAAK;CAE5B,OAAO,eAAe,CAAC,OAAO,gBAAgB,CAAC,CAAC,CAAC,CAC9C,KAAK,CAAC,CACN,QAAQ,gBAAgB;EACvB,OAAO,aAAa,UAAU,WAAW,iBAAiB,WAAW;CACvE,CAAC,CAAC,CACD,OAAO,eAAe;AAC3B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { pkgDir, pkgName } from "nitro-drizzle/meta";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
//#region src/module/internal/externals.ts
|
|
4
|
+
const inlineModuleIds = [
|
|
5
|
+
"runtime",
|
|
6
|
+
"plugins",
|
|
7
|
+
"migrations"
|
|
8
|
+
].flatMap((id) => {
|
|
9
|
+
return [join(pkgName, id), join(pkgDir, "dist", id)];
|
|
10
|
+
});
|
|
11
|
+
function addInlineExternals(nitroOptions) {
|
|
12
|
+
nitroOptions.externals ||= {};
|
|
13
|
+
nitroOptions.externals.inline ||= [];
|
|
14
|
+
nitroOptions.externals.inline.push(...inlineModuleIds);
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { addInlineExternals };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=externals.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"externals.mjs","names":[],"sources":["../../../src/module/internal/externals.ts"],"sourcesContent":["import type { NitroOptions } from \"nitropack/types\";\nimport { pkgDir, pkgName } from \"nitro-drizzle/meta\";\nimport { join } from \"node:path\";\n\nconst inlineModuleIds = [\"runtime\", \"plugins\", \"migrations\"].flatMap((id) => {\n return [join(pkgName, id), join(pkgDir, \"dist\", id)];\n});\n\nexport function addInlineExternals(nitroOptions: NitroOptions) {\n // @ts-expect-error\n nitroOptions.externals ||= {};\n nitroOptions.externals.inline ||= [];\n nitroOptions.externals.inline.push(...inlineModuleIds);\n}\n"],"mappings":";;;AAIA,MAAM,kBAAkB;CAAC;CAAW;CAAW;AAAY,CAAC,CAAC,SAAS,OAAO;CAC3E,OAAO,CAAC,KAAK,SAAS,EAAE,GAAG,KAAK,QAAQ,QAAQ,EAAE,CAAC;AACrD,CAAC;AAED,SAAgB,mBAAmB,cAA4B;CAE7D,aAAa,cAAc,CAAC;CAC5B,aAAa,UAAU,WAAW,CAAC;CACnC,aAAa,UAAU,OAAO,KAAK,GAAG,eAAe;AACvD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { dirname } from "pathe";
|
|
2
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
+
//#region src/module/internal/fs.ts
|
|
4
|
+
async function writeFile$1(file, contents) {
|
|
5
|
+
await mkdir(dirname(file), { recursive: true });
|
|
6
|
+
await writeFile(file, contents, typeof contents === "string" ? "utf8" : void 0);
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { writeFile$1 as writeFile };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=fs.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs.mjs","names":["writeFile","fspWriteFile"],"sources":["../../../src/module/internal/fs.ts"],"sourcesContent":["import { mkdir, writeFile as fspWriteFile } from \"node:fs/promises\";\nimport { dirname } from \"pathe\";\n\nexport async function writeFile(file: string, contents: Buffer | string) {\n await mkdir(dirname(file), { recursive: true });\n await fspWriteFile(file, contents, typeof contents === \"string\" ? \"utf8\" : undefined);\n}\n"],"mappings":";;;AAGA,eAAsBA,YAAU,MAAc,UAA2B;CACvE,MAAM,MAAM,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;CAC9C,MAAMC,UAAa,MAAM,UAAU,OAAO,aAAa,WAAW,SAAS,KAAA,CAAS;AACtF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { relative } from "pathe";
|
|
2
|
+
//#region src/module/internal/path.ts
|
|
3
|
+
const RELATIVE_RE = /^\.{1,2}\//;
|
|
4
|
+
function relativeWithDot(from, to) {
|
|
5
|
+
const rel = relative(from, to);
|
|
6
|
+
return RELATIVE_RE.test(rel) ? rel : "./" + rel;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { relativeWithDot };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=path.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.mjs","names":[],"sources":["../../../src/module/internal/path.ts"],"sourcesContent":["import { relative } from \"pathe\";\n\nconst RELATIVE_RE = /^\\.{1,2}\\//;\n\nexport function relativeWithDot(from: string, to: string) {\n const rel = relative(from, to);\n return RELATIVE_RE.test(rel) ? rel : \"./\" + rel;\n}\n"],"mappings":";;AAEA,MAAM,cAAc;AAEpB,SAAgB,gBAAgB,MAAc,IAAY;CACxD,MAAM,MAAM,SAAS,MAAM,EAAE;CAC7B,OAAO,YAAY,KAAK,GAAG,IAAI,MAAM,OAAO;AAC9C"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { pkgName } from "nitro-drizzle/meta";
|
|
2
|
+
//#region src/module/internal/reload.ts
|
|
3
|
+
function reloadPlugin(nitro, options) {
|
|
4
|
+
return {
|
|
5
|
+
name: `${pkgName}:rollup:watch`,
|
|
6
|
+
buildStart() {
|
|
7
|
+
this.addWatchFile(options.baseDir);
|
|
8
|
+
},
|
|
9
|
+
async watchChange(id) {
|
|
10
|
+
if (id.startsWith(options.baseDir)) await nitro.hooks.callHook("restart");
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { reloadPlugin };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=reload.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reload.mjs","names":[],"sources":["../../../src/module/internal/reload.ts"],"sourcesContent":["import type { Nitro } from \"nitropack/core\";\nimport type { Plugin } from \"rollup\";\nimport { pkgName } from \"nitro-drizzle/meta\";\nimport type { ContextOptions } from \"nitro-drizzle/context\";\n\nexport type ReloadPluginOptions = Pick<ContextOptions, \"baseDir\">;\n\nexport function reloadPlugin(nitro: Nitro, options: ReloadPluginOptions): Plugin {\n return {\n name: `${pkgName}:rollup:watch`,\n\n buildStart() {\n this.addWatchFile(options.baseDir);\n },\n\n async watchChange(id) {\n if (id.startsWith(options.baseDir)) {\n await nitro.hooks.callHook(\"restart\");\n }\n },\n };\n}\n"],"mappings":";;AAOA,SAAgB,aAAa,OAAc,SAAsC;CAC/E,OAAO;EACL,MAAM,GAAG,QAAQ;EAEjB,aAAa;GACX,KAAK,aAAa,QAAQ,OAAO;EACnC;EAEA,MAAM,YAAY,IAAI;GACpB,IAAI,GAAG,WAAW,QAAQ,OAAO,GAC/B,MAAM,MAAM,MAAM,SAAS,SAAS;EAExC;CACF;AACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createJiti } from "jiti";
|
|
2
|
+
import { fileURLToPath } from "url";
|
|
3
|
+
//#region src/module/internal/resolver.ts
|
|
4
|
+
function createResolver(id, options) {
|
|
5
|
+
return new JitiResolver(id, { alias: options?.alias });
|
|
6
|
+
}
|
|
7
|
+
var JitiResolver = class {
|
|
8
|
+
#jiti;
|
|
9
|
+
constructor(id, options) {
|
|
10
|
+
this.#jiti = createJiti(id, options);
|
|
11
|
+
}
|
|
12
|
+
resolve(id) {
|
|
13
|
+
return fileURLToPath(this.#jiti.esmResolve(id));
|
|
14
|
+
}
|
|
15
|
+
tryResolve(id) {
|
|
16
|
+
try {
|
|
17
|
+
return this.resolve(id);
|
|
18
|
+
} catch {}
|
|
19
|
+
}
|
|
20
|
+
async import(id, options) {
|
|
21
|
+
return await this.#jiti.import(id, { default: options?.default || void 0 });
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
export { createResolver };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=resolver.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolver.mjs","names":["#jiti"],"sources":["../../../src/module/internal/resolver.ts"],"sourcesContent":["import { createJiti, type Jiti, type JitiOptions } from \"jiti\";\nimport type { Resolver } from \"nitro-drizzle/context\";\nimport { fileURLToPath } from \"url\";\n\nexport function createResolver(id: string, options?: { alias?: Record<string, string> }): Resolver {\n return new JitiResolver(id, {\n alias: options?.alias,\n });\n}\n\nclass JitiResolver implements Resolver {\n readonly #jiti: Jiti;\n\n constructor(id: string, options?: JitiOptions) {\n this.#jiti = createJiti(id, options);\n }\n\n resolve(id: string): string {\n return fileURLToPath(this.#jiti.esmResolve(id));\n }\n\n tryResolve(id: string): string | undefined {\n try {\n return this.resolve(id);\n } catch {}\n }\n\n async import<T>(id: string, options?: { default: boolean }): Promise<T> {\n return await this.#jiti.import<T>(id, { default: options?.default || undefined });\n }\n}\n"],"mappings":";;;AAIA,SAAgB,eAAe,IAAY,SAAwD;CACjG,OAAO,IAAI,aAAa,IAAI,EAC1B,OAAO,SAAS,MAClB,CAAC;AACH;AAEA,IAAM,eAAN,MAAuC;CACrC;CAEA,YAAY,IAAY,SAAuB;EAC7C,KAAKA,QAAQ,WAAW,IAAI,OAAO;CACrC;CAEA,QAAQ,IAAoB;EAC1B,OAAO,cAAc,KAAKA,MAAM,WAAW,EAAE,CAAC;CAChD;CAEA,WAAW,IAAgC;EACzC,IAAI;GACF,OAAO,KAAK,QAAQ,EAAE;EACxB,QAAQ,CAAC;CACX;CAEA,MAAM,OAAU,IAAY,SAA4C;EACtE,OAAO,MAAM,KAAKA,MAAM,OAAU,IAAI,EAAE,SAAS,SAAS,WAAW,KAAA,EAAU,CAAC;CAClF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rollup.mjs","names":[],"sources":["../../../src/module/internal/rollup.ts"],"sourcesContent":["import type { RollupConfig } from \"nitropack/types\";\nimport type { Plugin } from \"rollup\";\n\nexport async function addPlugin(rollupConfig: RollupConfig, plugin: Plugin) {\n const plugins = [await rollupConfig.plugins].flat();\n rollupConfig.plugins = [...plugins, plugin];\n}\n"],"mappings":";AAGA,eAAsB,UAAU,cAA4B,QAAgB;CAE1E,aAAa,UAAU,CAAC,GADR,CAAC,MAAM,aAAa,OAAO,CAAC,CAAC,KACZ,GAAG,MAAM;AAC5C"}
|