nitro-drizzle 0.3.0-beta.3 → 0.3.0-beta.4
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/README.md +24 -3
- package/dist/config/defineConfig.d.mts +4 -4
- package/dist/config/defineConfig.mjs +4 -4
- package/dist/config/defineConfig.mjs.map +1 -1
- package/dist/context/internal/async.mjs +8 -0
- package/dist/context/internal/async.mjs.map +1 -1
- package/dist/context/internal/codegen.mjs +28 -0
- package/dist/context/internal/codegen.mjs.map +1 -0
- package/dist/context/internal/config.mjs +6 -0
- package/dist/context/internal/config.mjs.map +1 -1
- package/dist/context/internal/format.mjs +6 -0
- package/dist/context/internal/format.mjs.map +1 -1
- package/dist/context/internal/fs.mjs +7 -0
- package/dist/context/internal/fs.mjs.map +1 -1
- package/dist/context/internal/logger.mjs +6 -0
- package/dist/context/internal/logger.mjs.map +1 -1
- package/dist/context/internal/templates.mjs +12 -12
- package/dist/context/internal/templates.mjs.map +1 -1
- package/dist/context/internal/virtual.mjs +8 -2
- package/dist/context/internal/virtual.mjs.map +1 -1
- package/dist/context.d.mts +5 -1
- package/dist/context.mjs +3 -2
- package/dist/context.mjs.map +1 -1
- package/dist/dialects/sqlite.d.mts +2 -2
- package/dist/dialects/sqlite.mjs +3 -3
- package/dist/dialects/sqlite.mjs.map +1 -1
- package/dist/drivers/d1/dialect.mjs +2 -1
- package/dist/drivers/d1/dialect.mjs.map +1 -1
- package/dist/drivers/d1-http.d.mts +1 -1
- package/dist/drivers/d1-http.mjs.map +1 -1
- package/dist/drivers/db0.d.mts +1 -0
- package/dist/drivers/db0.mjs.map +1 -1
- package/dist/drivers/index.d.mts +6 -1
- package/dist/drivers/index.mjs.map +1 -1
- package/dist/middleware/context.d.mts +8 -0
- package/dist/middleware/context.mjs +4 -0
- package/dist/middleware/context.mjs.map +1 -1
- package/dist/migrations/migrate.mjs +3 -2
- package/dist/migrations/migrate.mjs.map +1 -1
- package/dist/migrations/task.d.mts +4 -0
- package/dist/migrations/task.mjs +4 -0
- package/dist/migrations/task.mjs.map +1 -1
- package/dist/module/internal/fs.mjs +5 -0
- package/dist/module/internal/fs.mjs.map +1 -1
- package/dist/module/internal/path.mjs +6 -0
- package/dist/module/internal/path.mjs.map +1 -1
- package/dist/module/internal/reload.mjs +6 -0
- package/dist/module/internal/reload.mjs.map +1 -1
- package/dist/module/internal/resolver.mjs +6 -0
- package/dist/module/internal/resolver.mjs.map +1 -1
- package/dist/module/internal/rollup.mjs +5 -0
- package/dist/module/internal/rollup.mjs.map +1 -1
- package/dist/module/internal/types.mjs +16 -0
- package/dist/module/internal/types.mjs.map +1 -1
- package/dist/module/utils/assets.d.mts +5 -0
- package/dist/module/utils/assets.mjs +5 -0
- package/dist/module/utils/assets.mjs.map +1 -1
- package/dist/module/utils/externals.d.mts +5 -0
- package/dist/module/utils/externals.mjs +10 -0
- package/dist/module/utils/externals.mjs.map +1 -1
- package/dist/module/utils/nitro.d.mts +5 -0
- package/dist/module/utils/nitro.mjs +5 -0
- package/dist/module/utils/nitro.mjs.map +1 -1
- package/dist/module.d.mts +18 -1
- package/dist/module.mjs +12 -2
- package/dist/module.mjs.map +1 -1
- package/dist/runtime/internal/config.mjs +11 -0
- package/dist/runtime/internal/config.mjs.map +1 -1
- package/dist/runtime/internal/createDatasource.mjs +9 -0
- package/dist/runtime/internal/createDatasource.mjs.map +1 -1
- package/dist/runtime/useConfig.d.mts +6 -0
- package/dist/runtime/useConfig.mjs +6 -0
- package/dist/runtime/useConfig.mjs.map +1 -1
- package/dist/runtime/useDatasource.d.mts +5 -3
- package/dist/runtime/useDatasource.mjs +2 -1
- package/dist/runtime/useDatasource.mjs.map +1 -1
- package/dist/runtime/useDialect.d.mts +18 -6
- package/dist/runtime/useDialect.mjs +10 -0
- package/dist/runtime/useDialect.mjs.map +1 -1
- package/dist/runtime.d.mts +28 -17
- package/dist/shared/variants.d.mts +18 -1
- package/dist/shared/variants.mjs +5 -0
- package/dist/shared/variants.mjs.map +1 -1
- package/dist/shared.d.mts +3 -0
- package/package.json +4 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite.mjs","names":[],"sources":["../../src/dialects/sqlite.ts"],"sourcesContent":["import type { SQLiteInsertBase } from \"drizzle-orm/sqlite-core\";\nimport type { InferColumns, InferTable, OnConflictDoUpdateOptions } from \".\";\n\n/**\n * Adds an ON CONFLICT DO UPDATE clause to a SQLite insert statement.\n * @template TInsert - The insert type\n * @param target - Partial object of columns to target for conflict detection\n * @param insert - The insert statement\n * @param options - Options containing the SET values\n * @returns The modified insert statement\n */\nexport function onConflictDoUpdate<TInsert extends SQLiteInsertBase<any, any, any, any, any, any>>(\n target: Partial<InferColumns<InferTable<TInsert>>>,\n insert: TInsert,\n options: OnConflictDoUpdateOptions<TInsert>,\n): TInsert {\n return insert.onConflictDoUpdate({\n target: Object.values(target),\n set: options.set,\n });\n}\n\n/**\n * Adds an ON CONFLICT DO NOTHING clause to a SQLite insert statement.\n * @template TInsert - The insert type\n * @param
|
|
1
|
+
{"version":3,"file":"sqlite.mjs","names":[],"sources":["../../src/dialects/sqlite.ts"],"sourcesContent":["import type { SQLiteInsertBase } from \"drizzle-orm/sqlite-core\";\nimport type { InferColumns, InferTable, OnConflictDoUpdateOptions } from \".\";\n\n/**\n * Adds an ON CONFLICT DO UPDATE clause to a SQLite insert statement.\n * @template TInsert - The insert type\n * @param target - Partial object of columns to target for conflict detection\n * @param insert - The insert statement\n * @param options - Options containing the SET values\n * @returns The modified insert statement\n */\nexport function onConflictDoUpdate<TInsert extends SQLiteInsertBase<any, any, any, any, any, any>>(\n target: Partial<InferColumns<InferTable<TInsert>>>,\n insert: TInsert,\n options: OnConflictDoUpdateOptions<TInsert>,\n): TInsert {\n return insert.onConflictDoUpdate({\n target: Object.values(target),\n set: options.set,\n });\n}\n\n/**\n * Adds an ON CONFLICT DO NOTHING clause to a SQLite insert statement.\n * @template TInsert - The insert type\n * @param target - Partial object of columns\n * @param insert - The insert statement\n * @returns The modified insert statement with DO NOTHING\n */\nexport function onConflictDoNothing<TInsert extends SQLiteInsertBase<any, any, any, any, any, any>>(\n target: Partial<InferColumns<InferTable<TInsert>>>,\n insert: TInsert,\n): TInsert {\n return insert.onConflictDoNothing({\n target: Object.values(target),\n });\n}\n\n/**\n * Infers the table type from a SQLite insert statement.\n * @template T - The insert type\n */\nexport type InferSqliteTable<T extends SQLiteInsertBase<any, any, any, any, any, any>> =\n T extends SQLiteInsertBase<infer TTable, any, any, any, any, any> ? TTable : never;\n"],"mappings":";;;;;;;;;AAWA,SAAgB,mBACd,QACA,QACA,SACS;CACT,OAAO,OAAO,mBAAmB;EAC/B,QAAQ,OAAO,OAAO,MAAM;EAC5B,KAAK,QAAQ;CACf,CAAC;AACH;;;;;;;;AASA,SAAgB,oBACd,QACA,QACS;CACT,OAAO,OAAO,oBAAoB,EAChC,QAAQ,OAAO,OAAO,MAAM,EAC9B,CAAC;AACH"}
|
|
@@ -3,7 +3,8 @@ import { SQLiteAsyncDialect } from "drizzle-orm/sqlite-core";
|
|
|
3
3
|
import { SQLiteRaw } from "drizzle-orm/sqlite-core/query-builders/raw";
|
|
4
4
|
//#region src/drivers/d1/dialect.ts
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* SQLite dialect for Cloudflare D1 that uses batching instead of transactions for migrations.
|
|
7
|
+
* D1 does not support transactions, so migrations are executed as a batch.
|
|
7
8
|
* @see [Cloudflare D1 transaction not supported #2463](https://github.com/drizzle-team/drizzle-orm/issues/2463)
|
|
8
9
|
*/
|
|
9
10
|
var SQLiteD1Dialect = class extends SQLiteAsyncDialect {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialect.mjs","names":[],"sources":["../../../src/drivers/d1/dialect.ts"],"sourcesContent":["import { sql, type SQL } from \"drizzle-orm\";\nimport type { BatchItem } from \"drizzle-orm/batch\";\nimport type { SQLiteD1Session } from \"drizzle-orm/d1\";\nimport type { MigrationMeta, MigrationConfig } from \"drizzle-orm/migrator\";\nimport { SQLiteAsyncDialect, type SQLiteSession } from \"drizzle-orm/sqlite-core\";\nimport { SQLiteRaw } from \"drizzle-orm/sqlite-core/query-builders/raw\";\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"dialect.mjs","names":[],"sources":["../../../src/drivers/d1/dialect.ts"],"sourcesContent":["import { sql, type SQL } from \"drizzle-orm\";\nimport type { BatchItem } from \"drizzle-orm/batch\";\nimport type { SQLiteD1Session } from \"drizzle-orm/d1\";\nimport type { MigrationMeta, MigrationConfig } from \"drizzle-orm/migrator\";\nimport { SQLiteAsyncDialect, type SQLiteSession } from \"drizzle-orm/sqlite-core\";\nimport { SQLiteRaw } from \"drizzle-orm/sqlite-core/query-builders/raw\";\n\n/**\n * SQLite dialect for Cloudflare D1 that uses batching instead of transactions for migrations.\n * D1 does not support transactions, so migrations are executed as a batch.\n * @see [Cloudflare D1 transaction not supported #2463](https://github.com/drizzle-team/drizzle-orm/issues/2463)\n */\nexport class SQLiteD1Dialect extends SQLiteAsyncDialect {\n override async migrate(\n migrations: Iterable<MigrationMeta>,\n session: SQLiteD1Session<any, any>,\n config?: MigrationConfig,\n ): Promise<void> {\n const migrationsTable = config?.migrationsTable || \"__drizzle_migrations\";\n const migrationTableCreate = sql`\n CREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (\n id SERIAL PRIMARY KEY,\n hash text NOT NULL,\n created_at numeric\n )\n `;\n await session.run(migrationTableCreate);\n const dbMigrations = await session.values(\n sql`SELECT id, hash, created_at FROM ${sql.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1`,\n );\n const lastDbMigration = dbMigrations[0] ?? void 0;\n\n const statementsToBatch: SQL[] = [];\n for (const migration of migrations) {\n if (!lastDbMigration || Number(lastDbMigration[2]) < migration.folderMillis) {\n for (const stmt of migration.sql) {\n statementsToBatch.push(sql.raw(stmt));\n }\n statementsToBatch.push(\n sql`INSERT INTO ${sql.identifier(migrationsTable)} (\"hash\", \"created_at\") VALUES(${sql.raw(`'${migration.hash}'`)}, ${sql.raw(`${migration.folderMillis}`)})`,\n );\n }\n }\n if (statementsToBatch.length > 0) {\n await session.batch(\n statementsToBatch.map((sql) => {\n return createBatchItem({ session, dialect: this, sql });\n }),\n );\n }\n }\n}\n\nfunction createBatchItem<TResult>({\n session,\n dialect,\n sql,\n}: CreateBatchItemOptions): BatchItem<\"sqlite\"> {\n return new SQLiteRaw<TResult>(\n async () => await session.run(sql),\n () => sql,\n \"run\",\n dialect,\n (result) => result,\n );\n}\n\ntype CreateBatchItemOptions = {\n session: SQLiteSession<\"async\", any, any, any>;\n dialect: SQLiteAsyncDialect;\n sql: SQL<unknown>;\n};\n"],"mappings":";;;;;;;;;AAYA,IAAa,kBAAb,cAAqC,mBAAmB;CACtD,MAAe,QACb,YACA,SACA,QACe;EACf,MAAM,kBAAkB,QAAQ,mBAAmB;EACnD,MAAM,uBAAuB,GAAG;mCACD,IAAI,WAAW,eAAe,EAAE;;;;;;EAM/D,MAAM,QAAQ,IAAI,oBAAoB;EAItC,MAAM,mBAAkB,MAHG,QAAQ,OACjC,GAAG,oCAAoC,IAAI,WAAW,eAAe,EAAE,kCACzE,EAAA,CACqC,MAAM,KAAK;EAEhD,MAAM,oBAA2B,CAAC;EAClC,KAAK,MAAM,aAAa,YACtB,IAAI,CAAC,mBAAmB,OAAO,gBAAgB,EAAE,IAAI,UAAU,cAAc;GAC3E,KAAK,MAAM,QAAQ,UAAU,KAC3B,kBAAkB,KAAK,IAAI,IAAI,IAAI,CAAC;GAEtC,kBAAkB,KAChB,GAAG,eAAe,IAAI,WAAW,eAAe,EAAE,iCAAiC,IAAI,IAAI,IAAI,UAAU,KAAK,EAAE,EAAE,IAAI,IAAI,IAAI,GAAG,UAAU,cAAc,EAAE,EAC7J;EACF;EAEF,IAAI,kBAAkB,SAAS,GAC7B,MAAM,QAAQ,MACZ,kBAAkB,KAAK,QAAQ;GAC7B,OAAO,gBAAgB;IAAE;IAAS,SAAS;IAAM;GAAI,CAAC;EACxD,CAAC,CACH;CAEJ;AACF;AAEA,SAAS,gBAAyB,EAChC,SACA,SACA,OAC8C;CAC9C,OAAO,IAAI,UACT,YAAY,MAAM,QAAQ,IAAI,GAAG,SAC3B,KACN,OACA,UACC,WAAW,MACd;AACF"}
|
|
@@ -39,5 +39,5 @@ declare function d1HttpDriver(options: D1HttpOptions): D1HttpDriver;
|
|
|
39
39
|
declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(callback: RemoteCallback, config?: DrizzleConfig<TSchema>): SqliteRemoteDatabase<TSchema>;
|
|
40
40
|
declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(callback: RemoteCallback, batchCallback?: AsyncBatchRemoteCallback, config?: DrizzleConfig<TSchema>): SqliteRemoteDatabase<TSchema>;
|
|
41
41
|
//#endregion
|
|
42
|
-
export { d1HttpDriver, driver as default, drizzle };
|
|
42
|
+
export { D1HttpDriver, D1HttpOptions, d1HttpDriver, driver as default, drizzle };
|
|
43
43
|
//# sourceMappingURL=d1-http.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"d1-http.mjs","names":[],"sources":["../../src/drivers/d1-http.ts"],"sourcesContent":["import {\n type AsyncRemoteCallback,\n type AsyncBatchRemoteCallback,\n SqliteRemoteDatabase,\n SQLiteRemoteSession,\n type RemoteCallback,\n} from \"drizzle-orm/sqlite-proxy\";\nimport { defineConnector, type Schema } from \".\";\nimport {\n type DrizzleConfig,\n DefaultLogger,\n type RelationalSchemaConfig,\n type TablesRelationalConfig,\n extractTablesRelationalConfig,\n createTableRelationsHelpers,\n} from \"drizzle-orm\";\nimport { SQLiteD1Dialect } from \"./d1/dialect\";\nimport { SELECT_1 } from \"./internal/sql\";\n\n/**\n * Cloudflare D1 HTTP datasource driver for remote connections.\n * @template TSchema - The schema type\n * @param options - Driver configuration options\n * @param schema - The Drizzle schema\n * @returns A Datasource instance\n */\nconst driver = defineConnector(\n <TSchema extends Schema>(options: D1HttpOptions, schema: TSchema) => {\n const { callback, batchCallback } = d1HttpDriver(options);\n const database = drizzle(callback, batchCallback, { schema });\n return {\n database,\n schema,\n async waitReady() {\n await database.run(SELECT_1);\n },\n async close() {},\n };\n },\n);\n\nexport default driver;\n\n/** Configuration options for the Cloudflare D1 HTTP driver. */\
|
|
1
|
+
{"version":3,"file":"d1-http.mjs","names":[],"sources":["../../src/drivers/d1-http.ts"],"sourcesContent":["import {\n type AsyncRemoteCallback,\n type AsyncBatchRemoteCallback,\n SqliteRemoteDatabase,\n SQLiteRemoteSession,\n type RemoteCallback,\n} from \"drizzle-orm/sqlite-proxy\";\nimport { defineConnector, type Schema } from \".\";\nimport {\n type DrizzleConfig,\n DefaultLogger,\n type RelationalSchemaConfig,\n type TablesRelationalConfig,\n extractTablesRelationalConfig,\n createTableRelationsHelpers,\n} from \"drizzle-orm\";\nimport { SQLiteD1Dialect } from \"./d1/dialect\";\nimport { SELECT_1 } from \"./internal/sql\";\n\n/**\n * Cloudflare D1 HTTP datasource driver for remote connections.\n * @template TSchema - The schema type\n * @param options - Driver configuration options\n * @param schema - The Drizzle schema\n * @returns A Datasource instance\n */\nconst driver = defineConnector(\n <TSchema extends Schema>(options: D1HttpOptions, schema: TSchema) => {\n const { callback, batchCallback } = d1HttpDriver(options);\n const database = drizzle(callback, batchCallback, { schema });\n return {\n database,\n schema,\n async waitReady() {\n await database.run(SELECT_1);\n },\n async close() {},\n };\n },\n);\n\nexport default driver;\n\n/** Configuration options for the Cloudflare D1 HTTP driver. */\nexport type D1HttpOptions = {\n /** Cloudflare account ID. */\n accountId: string;\n /** D1 database ID. */\n databaseId: string;\n /** API token for authentication. */\n token: string;\n};\n\n/** Internal type for the HTTP driver callback functions. */\nexport type D1HttpDriver = {\n callback: AsyncRemoteCallback;\n batchCallback: AsyncBatchRemoteCallback;\n};\n\ntype D1Response =\n | {\n success: true;\n result: [Result, ...Result[]];\n }\n | {\n success: false;\n errors: { code: number; message: string }[];\n };\n\ntype Result = {\n results:\n | any[]\n | {\n columns: string[];\n rows: any[][];\n };\n};\n\ntype D1HttpQuery = {\n sql: string;\n params: any[];\n};\n\ntype FetchD1Body =\n | {\n batch: D1HttpQuery[];\n }\n | D1HttpQuery;\n\nasync function fetchD1(url: string | URL, body: FetchD1Body, options: D1HttpOptions) {\n const res = await fetch(url, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${options.token}`,\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(body),\n });\n\n const data = (await res.json()) as D1Response;\n\n if (!data.success) {\n throw new Error(data.errors.map((it) => `${it.code}: ${it.message}`).join(\"\\n\"));\n }\n\n const result = data.result[0].results;\n const rows = Array.isArray(result) ? result : result.rows;\n\n return { rows };\n}\n\n/**\n * Creates an HTTP driver for Cloudflare D1 API.\n * @param options - D1 HTTP configuration options\n * @returns Object containing callback and batchCallback functions\n * @see [Cloudflare API docs](https://developers.cloudflare.com/api/resources/d1/subresources/database/methods/raw/)\n */\nexport function d1HttpDriver(options: D1HttpOptions): D1HttpDriver {\n const url = new URL(\n `accounts/${options.accountId}/d1/database/${options.databaseId}/raw`,\n \"https://api.cloudflare.com/client/v4/\",\n );\n return {\n async callback(sql, params, _) {\n const body = { sql, params };\n const res = await fetchD1(url, body, options);\n return res;\n },\n async batchCallback(batch) {\n const body = {\n batch: batch.map(({ sql, params }) => {\n return {\n sql,\n params,\n };\n }),\n };\n const res = await fetchD1(url, body, options);\n return [res];\n },\n };\n}\n\nexport function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(\n callback: RemoteCallback,\n config?: DrizzleConfig<TSchema>,\n): SqliteRemoteDatabase<TSchema>;\nexport function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(\n callback: RemoteCallback,\n batchCallback?: AsyncBatchRemoteCallback,\n config?: DrizzleConfig<TSchema>,\n): SqliteRemoteDatabase<TSchema>;\nexport function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(\n callback: RemoteCallback,\n batchCallback?: AsyncBatchRemoteCallback | DrizzleConfig<TSchema>,\n config?: DrizzleConfig<TSchema>,\n): SqliteRemoteDatabase<TSchema> {\n const dialect = new SQLiteD1Dialect({ casing: config?.casing });\n let logger;\n let cache;\n let _batchCallback: AsyncBatchRemoteCallback | undefined;\n let _config: DrizzleConfig<TSchema> = {};\n\n if (batchCallback) {\n if (typeof batchCallback === \"function\") {\n _batchCallback = batchCallback as AsyncBatchRemoteCallback;\n _config = config ?? {};\n } else {\n _batchCallback = undefined;\n _config = batchCallback as DrizzleConfig<TSchema>;\n }\n\n if (_config.logger === true) {\n logger = new DefaultLogger();\n } else if (_config.logger !== false) {\n logger = _config.logger;\n cache = _config.cache;\n }\n }\n\n let schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined;\n if (_config.schema) {\n const tablesConfig = extractTablesRelationalConfig(_config.schema, createTableRelationsHelpers);\n schema = {\n fullSchema: _config.schema,\n schema: tablesConfig.tables,\n tableNamesMap: tablesConfig.tableNamesMap,\n };\n }\n\n const session = new SQLiteRemoteSession(callback, dialect, schema, _batchCallback, {\n logger,\n cache,\n });\n const db = new SqliteRemoteDatabase(\n \"async\",\n dialect,\n session,\n schema,\n ) as SqliteRemoteDatabase<TSchema>;\n (<any>db).$cache = cache;\n if ((<any>db).$cache) {\n (<any>db).$cache[\"invalidate\"] = cache?.onMutate;\n }\n return db;\n}\n"],"mappings":";;;;;;;;;;;;;AA0BA,MAAM,SAAS,iBACY,SAAwB,WAAoB;CACnE,MAAM,EAAE,UAAU,kBAAkB,aAAa,OAAO;CACxD,MAAM,WAAW,QAAQ,UAAU,eAAe,EAAE,OAAO,CAAC;CAC5D,OAAO;EACL;EACA;EACA,MAAM,YAAY;GAChB,MAAM,SAAS,IAAI,QAAQ;EAC7B;EACA,MAAM,QAAQ,CAAC;CACjB;AACF,CACF;AAkDA,eAAe,QAAQ,KAAmB,MAAmB,SAAwB;CAUnF,MAAM,OAAQ,OAAM,MATF,MAAM,KAAK;EAC3B,QAAQ;EACR,SAAS;GACP,eAAe,UAAU,QAAQ;GACjC,gBAAgB;EAClB;EACA,MAAM,KAAK,UAAU,IAAI;CAC3B,CAAC,EAAA,CAEuB,KAAK;CAE7B,IAAI,CAAC,KAAK,SACR,MAAM,IAAI,MAAM,KAAK,OAAO,KAAK,OAAO,GAAG,GAAG,KAAK,IAAI,GAAG,SAAS,CAAC,CAAC,KAAK,IAAI,CAAC;CAGjF,MAAM,SAAS,KAAK,OAAO,EAAE,CAAC;CAG9B,OAAO,EAAE,MAFI,MAAM,QAAQ,MAAM,IAAI,SAAS,OAAO,KAEvC;AAChB;;;;;;;AAQA,SAAgB,aAAa,SAAsC;CACjE,MAAM,MAAM,IAAI,IACd,YAAY,QAAQ,UAAU,eAAe,QAAQ,WAAW,OAChE,uCACF;CACA,OAAO;EACL,MAAM,SAAS,KAAK,QAAQ,GAAG;GAG7B,OAAO,MADW,QAAQ,KAAK;IADhB;IAAK;GACc,GAAG,OAAO;EAE9C;EACA,MAAM,cAAc,OAAO;GACzB,MAAM,OAAO,EACX,OAAO,MAAM,KAAK,EAAE,KAAK,aAAa;IACpC,OAAO;KACL;KACA;IACF;GACF,CAAC,EACH;GAEA,OAAO,CAAC,MADU,QAAQ,KAAK,MAAM,OAAO,CACjC;EACb;CACF;AACF;AAWA,SAAgB,QACd,UACA,eACA,QAC+B;CAC/B,MAAM,UAAU,IAAI,gBAAgB,EAAE,QAAQ,QAAQ,OAAO,CAAC;CAC9D,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI,UAAkC,CAAC;CAEvC,IAAI,eAAe;EACjB,IAAI,OAAO,kBAAkB,YAAY;GACvC,iBAAiB;GACjB,UAAU,UAAU,CAAC;EACvB,OAAO;GACL,iBAAiB,KAAA;GACjB,UAAU;EACZ;EAEA,IAAI,QAAQ,WAAW,MACrB,SAAS,IAAI,cAAc;OACtB,IAAI,QAAQ,WAAW,OAAO;GACnC,SAAS,QAAQ;GACjB,QAAQ,QAAQ;EAClB;CACF;CAEA,IAAI;CACJ,IAAI,QAAQ,QAAQ;EAClB,MAAM,eAAe,8BAA8B,QAAQ,QAAQ,2BAA2B;EAC9F,SAAS;GACP,YAAY,QAAQ;GACpB,QAAQ,aAAa;GACrB,eAAe,aAAa;EAC9B;CACF;CAMA,MAAM,KAAK,IAAI,qBACb,SACA,SACA,IAPkB,oBAAoB,UAAU,SAAS,QAAQ,gBAAgB;EACjF;EACA;CACF,CAIQ,GACN,MACF;CACA,GAAU,SAAS;CACnB,IAAU,GAAI,QACZ,GAAU,OAAO,gBAAgB,OAAO;CAE1C,OAAO;AACT"}
|
package/dist/drivers/db0.d.mts
CHANGED
|
@@ -13,6 +13,7 @@ declare const _default: <TSchema extends Schema>(options: Options, schema: TSche
|
|
|
13
13
|
waitReady: () => Promise<void>;
|
|
14
14
|
};
|
|
15
15
|
type Options = {
|
|
16
|
+
/** The name of the database to use from Nitro's built-in database configuration. */
|
|
16
17
|
name?: string;
|
|
17
18
|
};
|
|
18
19
|
//#endregion
|
package/dist/drivers/db0.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db0.mjs","names":[],"sources":["../../src/drivers/db0.ts"],"sourcesContent":["import { useDatabase } from \"nitropack/runtime\";\nimport { defineConnector, type Schema } from \".\";\nimport { drizzle } from \"db0/integrations/drizzle\";\nimport { SELECT_1 } from \"./internal/sql\";\n\n/**\n * DB0 datasource driver for Nitro's built-in database configuration.\n * @template TSchema - The schema type\n * @returns A Datasource instance using Nitro's database configuration\n */\nexport default defineConnector(<TSchema extends Schema>(options: Options, schema: TSchema) => {\n const db0 = useDatabase(options.name);\n const database = drizzle<TSchema>(db0);\n return {\n dialect: \"sqlite\",\n database,\n schema,\n close: async () => {\n await db0.dispose();\n },\n waitReady: async () => {\n await db0.exec(SELECT_1);\n },\n };\n});\n\nexport type Options = {\n name?: string;\n};\n"],"mappings":";;;;;;;;;;AAUA,IAAA,cAAe,iBAAyC,SAAkB,WAAoB;CAC5F,MAAM,MAAM,YAAY,QAAQ,IAAI;CAEpC,OAAO;EACL,SAAS;EACT,UAHe,QAAiB,GAGzB;EACP;EACA,OAAO,YAAY;GACjB,MAAM,IAAI,QAAQ;EACpB;EACA,WAAW,YAAY;GACrB,MAAM,IAAI,KAAK,QAAQ;EACzB;CACF;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"db0.mjs","names":[],"sources":["../../src/drivers/db0.ts"],"sourcesContent":["import { useDatabase } from \"nitropack/runtime\";\nimport { defineConnector, type Schema } from \".\";\nimport { drizzle } from \"db0/integrations/drizzle\";\nimport { SELECT_1 } from \"./internal/sql\";\n\n/**\n * DB0 datasource driver for Nitro's built-in database configuration.\n * @template TSchema - The schema type\n * @returns A Datasource instance using Nitro's database configuration\n */\nexport default defineConnector(<TSchema extends Schema>(options: Options, schema: TSchema) => {\n const db0 = useDatabase(options.name);\n const database = drizzle<TSchema>(db0);\n return {\n dialect: \"sqlite\",\n database,\n schema,\n close: async () => {\n await db0.dispose();\n },\n waitReady: async () => {\n await db0.exec(SELECT_1);\n },\n };\n});\n\nexport type Options = {\n /** The name of the database to use from Nitro's built-in database configuration. */\n name?: string;\n};\n"],"mappings":";;;;;;;;;;AAUA,IAAA,cAAe,iBAAyC,SAAkB,WAAoB;CAC5F,MAAM,MAAM,YAAY,QAAQ,IAAI;CAEpC,OAAO;EACL,SAAS;EACT,UAHe,QAAiB,GAGzB;EACP;EACA,OAAO,YAAY;GACjB,MAAM,IAAI,QAAQ;EACpB;EACA,WAAW,YAAY;GACrB,MAAM,IAAI,KAAK,QAAQ;EACzB;CACF;AACF,CAAC"}
|
package/dist/drivers/index.d.mts
CHANGED
|
@@ -8,7 +8,12 @@ type Schema = Record<string, any>;
|
|
|
8
8
|
* Factory function type for creating Drizzle datasource instances.
|
|
9
9
|
* @template TDatabase - The database type
|
|
10
10
|
*/
|
|
11
|
-
type Connector<TDialect extends string, TDatabase, TSchema extends Schema, TConfig
|
|
11
|
+
type Connector<TDialect extends string, TDatabase, TSchema extends Schema, TConfig> = (config: TConfig, schema: TSchema) => MaybePromise<Datasource<TDialect, TDatabase, TSchema>>;
|
|
12
|
+
/**
|
|
13
|
+
* Combines multiple schema types into an intersection type.
|
|
14
|
+
* @template T - The array of schema types
|
|
15
|
+
* @template Indices - The indices to include
|
|
16
|
+
*/
|
|
12
17
|
type MergeSchema<T extends readonly Schema[], Indices extends keyof T & number> = [Indices] extends [never] ? {} : UnionToIntersection<{ [K in Indices]: K extends keyof T ? T[K] : never; }[Indices]>;
|
|
13
18
|
/**
|
|
14
19
|
* Defines a driver factory function.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/drivers/index.ts"],"sourcesContent":["import type { MaybePromise, UnionToIntersection } from \"nitro-drizzle/shared\";\n\n/**\n * Schema type representing database tables.\n */\nexport type Schema = Record<string, any>;\n\n/**\n * Factory function type for creating Drizzle datasource instances.\n * @template TDatabase - The database type\n */\nexport type Connector
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/drivers/index.ts"],"sourcesContent":["import type { MaybePromise, UnionToIntersection } from \"nitro-drizzle/shared\";\n\n/**\n * Schema type representing database tables.\n */\nexport type Schema = Record<string, any>;\n\n/**\n * Factory function type for creating Drizzle datasource instances.\n * @template TDatabase - The database type\n */\nexport type Connector<TDialect extends string, TDatabase, TSchema extends Schema, TConfig> = (\n config: TConfig,\n schema: TSchema,\n) => MaybePromise<Datasource<TDialect, TDatabase, TSchema>>;\n\n/**\n * Combines multiple schema types into an intersection type.\n * @template T - The array of schema types\n * @template Indices - The indices to include\n */\nexport type MergeSchema<T extends readonly Schema[], Indices extends keyof T & number> = [\n Indices,\n] extends [never]\n ? {}\n : UnionToIntersection<\n {\n [K in Indices]: K extends keyof T ? T[K] : never;\n }[Indices]\n >;\n\n/**\n * Defines a driver factory function.\n * @template TConnector - The driver factory type\n * @param create - The driver factory function\n * @returns The same driver factory function\n */\nexport function defineConnector<\n TDialect extends string,\n TSchema extends Schema,\n TConnector extends Connector<TDialect, any, TSchema, any>,\n>(create: TConnector): TConnector {\n return create;\n}\n\n/**\n * Datasource interface representing a connected database with schema.\n * @template TDatabase - The database client type\n * @template TSchema - The schema type\n */\nexport interface Datasource<_TDialect, TDatabase, TSchema extends Schema> {\n /** The database client instance. */\n database: TDatabase;\n /** The schema definition. */\n schema: TSchema;\n /** Waits for the database connection to be ready. */\n waitReady: () => MaybePromise<void>;\n /** Closes the database connection. */\n close: () => MaybePromise<void>;\n}\n"],"mappings":";;;;;;;AAqCA,SAAgB,gBAId,QAAgC;CAChC,OAAO;AACT"}
|
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import { Middleware } from "nitro/h3";
|
|
2
2
|
//#region src/middleware/context.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Nitro middleware that initializes the Drizzle context on each request.
|
|
5
|
+
* Sets up the `drizzle` property on the event context with readiness state and wait capability.
|
|
6
|
+
*/
|
|
3
7
|
declare const middleware: Middleware;
|
|
8
|
+
/** The readiness state of the Drizzle initialization. */
|
|
4
9
|
type ReadyState = "pending" | "done" | "error";
|
|
10
|
+
/** Hooks for Drizzle initialization. */
|
|
5
11
|
type InitHooks = {
|
|
6
12
|
"drizzle:init": () => void;
|
|
7
13
|
};
|
|
8
14
|
declare module "nitro/types" {
|
|
9
15
|
interface NitroRuntimeHooks extends InitHooks {}
|
|
10
16
|
}
|
|
17
|
+
/** Context provided by the Drizzle middleware on the event context. */
|
|
11
18
|
interface DrizzleContext {
|
|
12
19
|
readonly readyState: ReadyState;
|
|
13
20
|
readonly waitReady: () => Promise<void>;
|
|
14
21
|
}
|
|
22
|
+
/** Event context extension for Drizzle. */
|
|
15
23
|
interface EventContext {
|
|
16
24
|
drizzle: DrizzleContext;
|
|
17
25
|
}
|
|
@@ -2,6 +2,10 @@ import { defineMiddleware } from "nitro";
|
|
|
2
2
|
import { useNitroHooks } from "nitro/app";
|
|
3
3
|
//#region src/middleware/context.ts
|
|
4
4
|
let eventContext;
|
|
5
|
+
/**
|
|
6
|
+
* Nitro middleware that initializes the Drizzle context on each request.
|
|
7
|
+
* Sets up the `drizzle` property on the event context with readiness state and wait capability.
|
|
8
|
+
*/
|
|
5
9
|
const middleware = defineMiddleware((event) => {
|
|
6
10
|
if (!eventContext) {
|
|
7
11
|
const hooks = useNitroHooks();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.mjs","names":[],"sources":["../../src/middleware/context.ts"],"sourcesContent":["import { defineMiddleware } from \"nitro\";\nimport { useNitroHooks } from \"nitro/app\";\nimport type { Middleware } from \"nitro/h3\";\n\nlet eventContext: DrizzleContext | undefined;\n\nconst middleware: Middleware = defineMiddleware((event): void => {\n if (!eventContext) {\n const hooks = useNitroHooks();\n\n let readyState: ReadyState = \"pending\";\n let initHook: Promise<void>;\n\n initHook = Promise.resolve(hooks.callHook(\"drizzle:init\"))\n .then(() => {\n readyState = \"done\";\n })\n .catch((err) => {\n readyState = \"error\";\n throw err;\n });\n\n eventContext = {\n get readyState() {\n return readyState;\n },\n waitReady: async () => {\n await initHook;\n },\n };\n }\n\n event.context.drizzle = eventContext;\n});\n\nexport default middleware;\n\nexport type ReadyState = \"pending\" | \"done\" | \"error\";\n\nexport type InitHooks = {\n \"drizzle:init\": () => void;\n};\n\ndeclare module \"nitro/types\" {\n interface NitroRuntimeHooks extends InitHooks {}\n}\n\nexport interface DrizzleContext {\n readonly readyState: ReadyState;\n readonly waitReady: () => Promise<void>;\n}\n\nexport interface EventContext {\n drizzle: DrizzleContext;\n}\n\ndeclare module \"srvx\" {\n interface ServerRequestContext extends EventContext {}\n}\n"],"mappings":";;;AAIA,IAAI
|
|
1
|
+
{"version":3,"file":"context.mjs","names":[],"sources":["../../src/middleware/context.ts"],"sourcesContent":["import { defineMiddleware } from \"nitro\";\nimport { useNitroHooks } from \"nitro/app\";\nimport type { Middleware } from \"nitro/h3\";\n\nlet eventContext: DrizzleContext | undefined;\n\n/**\n * Nitro middleware that initializes the Drizzle context on each request.\n * Sets up the `drizzle` property on the event context with readiness state and wait capability.\n */\nconst middleware: Middleware = defineMiddleware((event): void => {\n if (!eventContext) {\n const hooks = useNitroHooks();\n\n let readyState: ReadyState = \"pending\";\n let initHook: Promise<void>;\n\n initHook = Promise.resolve(hooks.callHook(\"drizzle:init\"))\n .then(() => {\n readyState = \"done\";\n })\n .catch((err) => {\n readyState = \"error\";\n throw err;\n });\n\n eventContext = {\n get readyState() {\n return readyState;\n },\n waitReady: async () => {\n await initHook;\n },\n };\n }\n\n event.context.drizzle = eventContext;\n});\n\nexport default middleware;\n\n/** The readiness state of the Drizzle initialization. */\nexport type ReadyState = \"pending\" | \"done\" | \"error\";\n\n/** Hooks for Drizzle initialization. */\nexport type InitHooks = {\n \"drizzle:init\": () => void;\n};\n\ndeclare module \"nitro/types\" {\n interface NitroRuntimeHooks extends InitHooks {}\n}\n\n/** Context provided by the Drizzle middleware on the event context. */\nexport interface DrizzleContext {\n readonly readyState: ReadyState;\n readonly waitReady: () => Promise<void>;\n}\n\n/** Event context extension for Drizzle. */\nexport interface EventContext {\n drizzle: DrizzleContext;\n}\n\ndeclare module \"srvx\" {\n interface ServerRequestContext extends EventContext {}\n}\n"],"mappings":";;;AAIA,IAAI;;;;;AAMJ,MAAM,aAAyB,kBAAkB,UAAgB;CAC/D,IAAI,CAAC,cAAc;EACjB,MAAM,QAAQ,cAAc;EAE5B,IAAI,aAAyB;EAC7B,IAAI;EAEJ,WAAW,QAAQ,QAAQ,MAAM,SAAS,cAAc,CAAC,CAAC,CACvD,WAAW;GACV,aAAa;EACf,CAAC,CAAC,CACD,OAAO,QAAQ;GACd,aAAa;GACb,MAAM;EACR,CAAC;EAEH,eAAe;GACb,IAAI,aAAa;IACf,OAAO;GACT;GACA,WAAW,YAAY;IACrB,MAAM;GACR;EACF;CACF;CAEA,MAAM,QAAQ,UAAU;AAC1B,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useMigrations } from "./useMigrations.mjs";
|
|
2
2
|
import { migrateDatabase } from "./internal/migrate.mjs";
|
|
3
|
-
import { useDatasource } from "nitro-drizzle/runtime";
|
|
3
|
+
import { useConfig, useDatasource } from "nitro-drizzle/runtime";
|
|
4
4
|
import { migrationConfig } from "#nitro-drizzle/migrations";
|
|
5
5
|
//#region src/migrations/migrate.ts
|
|
6
6
|
/**
|
|
@@ -10,9 +10,10 @@ import { migrationConfig } from "#nitro-drizzle/migrations";
|
|
|
10
10
|
* @returns Migration result
|
|
11
11
|
*/
|
|
12
12
|
async function migrate(name) {
|
|
13
|
+
const { driver } = useConfig(name);
|
|
13
14
|
const { database, waitReady } = await useDatasource(name);
|
|
14
15
|
const migrations = await useMigrations(name);
|
|
15
|
-
const config = migrationConfig[name];
|
|
16
|
+
const config = migrationConfig[name][driver];
|
|
16
17
|
await waitReady();
|
|
17
18
|
await migrateDatabase(database, migrations, config);
|
|
18
19
|
return {};
|
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"migrate.mjs","names":[],"sources":["../../src/migrations/migrate.ts"],"sourcesContent":["import { useConfig, 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 { driver } = useConfig(name);\n const { database, waitReady } = await useDatasource(name);\n const migrations = await useMigrations(name);\n const config = migrationConfig[name][driver];\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,WAAW,UAAU,IAAI;CACjC,MAAM,EAAE,UAAU,cAAc,MAAM,cAAc,IAAI;CACxD,MAAM,aAAa,MAAM,cAAc,IAAI;CAC3C,MAAM,SAAS,gBAAgB,KAAK,CAAC;CACrC,MAAM,UAAU;CAChB,MAAM,gBAAgB,UAAoC,YAAY,MAAM;CAC5E,OAAO,CAAC;AACV"}
|
|
@@ -2,6 +2,10 @@ import { MigrationResult } from "./migrate.mjs";
|
|
|
2
2
|
import { Task } from "nitropack/types";
|
|
3
3
|
import { Task as Task$1 } from "nitro/types";
|
|
4
4
|
//#region src/migrations/task.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Nitro task that runs Drizzle migrations for a datasource.
|
|
7
|
+
* Invoked via `npx nitro task drizzle:migrate` with the datasource name in the payload.
|
|
8
|
+
*/
|
|
5
9
|
declare const task: Task$1<MigrationResult> | Task<MigrationResult>;
|
|
6
10
|
//#endregion
|
|
7
11
|
export { task as default };
|
package/dist/migrations/task.mjs
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { migrate } from "./migrate.mjs";
|
|
2
2
|
//#region src/migrations/task.ts
|
|
3
|
+
/**
|
|
4
|
+
* Nitro task that runs Drizzle migrations for a datasource.
|
|
5
|
+
* Invoked via `npx nitro task drizzle:migrate` with the datasource name in the payload.
|
|
6
|
+
*/
|
|
3
7
|
const task = { async run(event) {
|
|
4
8
|
const { name } = event.payload;
|
|
5
9
|
return { result: await migrate(name) };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task.mjs","names":[],"sources":["../../src/migrations/task.ts"],"sourcesContent":["import { migrate, type MigrationResult } from \"./migrate\";\nimport type { DatasourceRegistry } from \"nitro-drizzle/runtime\";\nimport type { Task as LegacyTask } from \"nitropack/types\";\nimport type { Task } from \"nitro/types\";\n\nconst task: Task<MigrationResult> | LegacyTask<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\nexport default task;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"task.mjs","names":[],"sources":["../../src/migrations/task.ts"],"sourcesContent":["import { migrate, type MigrationResult } from \"./migrate\";\nimport type { DatasourceRegistry } from \"nitro-drizzle/runtime\";\nimport type { Task as LegacyTask } from \"nitropack/types\";\nimport type { Task } from \"nitro/types\";\n\n/**\n * Nitro task that runs Drizzle migrations for a datasource.\n * Invoked via `npx nitro task drizzle:migrate` with the datasource name in the payload.\n */\nconst task: Task<MigrationResult> | LegacyTask<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\nexport default task;\n"],"mappings":";;;;;;AASA,MAAM,OAA4D,EAChE,MAAM,IAAI,OAAO;CACf,MAAM,EAAE,SAAS,MAAM;CAEvB,OAAO,EAAE,QAAA,MADY,QAAQ,IAAI,EACjB;AAClB,EACF"}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { dirname } from "pathe";
|
|
2
2
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
3
|
//#region src/module/internal/fs.ts
|
|
4
|
+
/**
|
|
5
|
+
* Writes a file to disk, creating parent directories as needed.
|
|
6
|
+
* @param file - The file path to write
|
|
7
|
+
* @param contents - The content to write
|
|
8
|
+
*/
|
|
4
9
|
async function writeFile$1(file, contents) {
|
|
5
10
|
await mkdir(dirname(file), { recursive: true });
|
|
6
11
|
await writeFile(file, contents, typeof contents === "string" ? "utf8" : void 0);
|
|
@@ -1 +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":"
|
|
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\n/**\n * Writes a file to disk, creating parent directories as needed.\n * @param file - The file path to write\n * @param contents - The content to write\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":";;;;;;;;AAQA,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"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { relative } from "pathe";
|
|
2
2
|
//#region src/module/internal/path.ts
|
|
3
3
|
const RELATIVE_RE = /^\.{1,2}\//;
|
|
4
|
+
/**
|
|
5
|
+
* Computes a relative path from one directory to another, ensuring it starts with `./`.
|
|
6
|
+
* @param from - The source directory
|
|
7
|
+
* @param to - The target path
|
|
8
|
+
* @returns The relative path prefixed with `./` if not already relative
|
|
9
|
+
*/
|
|
4
10
|
function relativeWithDot(from, to) {
|
|
5
11
|
const rel = relative(from, to);
|
|
6
12
|
return RELATIVE_RE.test(rel) ? rel : "./" + rel;
|
|
@@ -1 +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
|
|
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\n/**\n * Computes a relative path from one directory to another, ensuring it starts with `./`.\n * @param from - The source directory\n * @param to - The target path\n * @returns The relative path prefixed with `./` if not already relative\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;;;;;;;AAQpB,SAAgB,gBAAgB,MAAc,IAAY;CACxD,MAAM,MAAM,SAAS,MAAM,EAAE;CAC7B,OAAO,YAAY,KAAK,GAAG,IAAI,MAAM,OAAO;AAC9C"}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { pkgName } from "nitro-drizzle/meta";
|
|
2
2
|
//#region src/module/internal/reload.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a Rollup plugin that watches the base directory and triggers a Nitro restart on changes.
|
|
5
|
+
* @param nitro - The Nitro instance
|
|
6
|
+
* @param options - Reload plugin options
|
|
7
|
+
* @returns A Rollup plugin
|
|
8
|
+
*/
|
|
3
9
|
function reloadPlugin(nitro, options) {
|
|
4
10
|
return {
|
|
5
11
|
name: `${pkgName}:rollup:watch`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reload.mjs","names":[],"sources":["../../../src/module/internal/reload.ts"],"sourcesContent":["import type { Nitro as NitroV1 } from \"nitropack/core\";\nimport type { Nitro } from \"nitro/types\";\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 | NitroV1, 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":"
|
|
1
|
+
{"version":3,"file":"reload.mjs","names":[],"sources":["../../../src/module/internal/reload.ts"],"sourcesContent":["import type { Nitro as NitroV1 } from \"nitropack/core\";\nimport type { Nitro } from \"nitro/types\";\nimport type { Plugin } from \"rollup\";\nimport { pkgName } from \"nitro-drizzle/meta\";\nimport type { ContextOptions } from \"nitro-drizzle/context\";\n\n/** Options for the reload plugin. */\nexport type ReloadPluginOptions = Pick<ContextOptions, \"baseDir\">;\n\n/**\n * Creates a Rollup plugin that watches the base directory and triggers a Nitro restart on changes.\n * @param nitro - The Nitro instance\n * @param options - Reload plugin options\n * @returns A Rollup plugin\n */\nexport function reloadPlugin(nitro: Nitro | NitroV1, 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":";;;;;;;;AAeA,SAAgB,aAAa,OAAwB,SAAsC;CACzF,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"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { createJiti } from "jiti";
|
|
2
2
|
import { fileURLToPath } from "url";
|
|
3
3
|
//#region src/module/internal/resolver.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates a module resolver using jiti.
|
|
6
|
+
* @param id - The base module ID for resolution
|
|
7
|
+
* @param options - Optional resolver configuration
|
|
8
|
+
* @returns A Resolver instance
|
|
9
|
+
*/
|
|
4
10
|
function createResolver(id, options) {
|
|
5
11
|
return new JitiResolver(id, { alias: options?.alias });
|
|
6
12
|
}
|
|
@@ -1 +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"],"mappings":"
|
|
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\n/**\n * Creates a module resolver using jiti.\n * @param id - The base module ID for resolution\n * @param options - Optional resolver configuration\n * @returns A Resolver instance\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"],"mappings":";;;;;;;;;AAUA,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;AACF"}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
//#region src/module/internal/rollup.ts
|
|
2
|
+
/**
|
|
3
|
+
* Adds a Rollup plugin to the Nitro rollup configuration.
|
|
4
|
+
* @param rollupConfig - The Rollup configuration
|
|
5
|
+
* @param plugin - The Rollup plugin to add
|
|
6
|
+
*/
|
|
2
7
|
async function addPlugin(rollupConfig, plugin) {
|
|
3
8
|
rollupConfig.plugins = [...[await rollupConfig.plugins].flat(), plugin];
|
|
4
9
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rollup.mjs","names":[],"sources":["../../../src/module/internal/rollup.ts"],"sourcesContent":["import type { RollupConfig as NitropackRollupConfig } from \"nitropack/types\";\nimport type { RollupConfig } from \"nitro/types\";\nimport type { Plugin } from \"rollup\";\n\nexport async function addPlugin(\n rollupConfig: RollupConfig | NitropackRollupConfig,\n plugin: Plugin,\n) {\n const plugins = [await rollupConfig.plugins].flat();\n rollupConfig.plugins = [...plugins, plugin];\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"rollup.mjs","names":[],"sources":["../../../src/module/internal/rollup.ts"],"sourcesContent":["import type { RollupConfig as NitropackRollupConfig } from \"nitropack/types\";\nimport type { RollupConfig } from \"nitro/types\";\nimport type { Plugin } from \"rollup\";\n\n/**\n * Adds a Rollup plugin to the Nitro rollup configuration.\n * @param rollupConfig - The Rollup configuration\n * @param plugin - The Rollup plugin to add\n */\nexport async function addPlugin(\n rollupConfig: RollupConfig | NitropackRollupConfig,\n plugin: Plugin,\n) {\n const plugins = [await rollupConfig.plugins].flat();\n rollupConfig.plugins = [...plugins, plugin];\n}\n"],"mappings":";;;;;;AASA,eAAsB,UACpB,cACA,QACA;CAEA,aAAa,UAAU,CAAC,GADR,CAAC,MAAM,aAAa,OAAO,CAAC,CAAC,KACZ,GAAG,MAAM;AAC5C"}
|
|
@@ -3,14 +3,30 @@ import { writeFile } from "./fs.mjs";
|
|
|
3
3
|
import { isLegacy } from "../utils/nitro.mjs";
|
|
4
4
|
import { dirname, join, resolve } from "pathe";
|
|
5
5
|
//#region src/module/internal/types.ts
|
|
6
|
+
/**
|
|
7
|
+
* Adds paths to the tsconfig include array.
|
|
8
|
+
* @param nitroTypes - The Nitro types configuration
|
|
9
|
+
* @param paths - The paths to add
|
|
10
|
+
*/
|
|
6
11
|
function addTsConfigInclude(nitroTypes, paths) {
|
|
7
12
|
nitroTypes.tsConfig ||= {};
|
|
8
13
|
nitroTypes.tsConfig.include ||= [];
|
|
9
14
|
nitroTypes.tsConfig.include.push(...paths);
|
|
10
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Writes type declaration files and adds them to the tsconfig include.
|
|
18
|
+
* @param nitroOptions - The Nitro options
|
|
19
|
+
* @param augmentations - The virtual modules containing type declarations
|
|
20
|
+
*/
|
|
11
21
|
async function addAugmentations(nitroOptions, nitroTypes, augmentations) {
|
|
12
22
|
addTsConfigInclude(nitroTypes, await writeTypeFiles(nitroOptions, augmentations));
|
|
13
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Adds type declaration path mappings to the tsconfig compiler options.
|
|
26
|
+
* @param nitro - The Nitro instance
|
|
27
|
+
* @param nitroTypes - The Nitro types configuration
|
|
28
|
+
* @param declarations - The virtual modules to write as type declarations
|
|
29
|
+
*/
|
|
14
30
|
async function addDeclarations(nitro, nitroTypes, declarations) {
|
|
15
31
|
nitroTypes.tsConfig ||= {};
|
|
16
32
|
nitroTypes.tsConfig.compilerOptions ||= {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","names":[],"sources":["../../../src/module/internal/types.ts"],"sourcesContent":["import type {\n Nitro as LegacyNitro,\n NitroOptions as LegacyNitroOptions,\n NitroTypes as LegacyNitroTypes,\n VirtualModule,\n} from \"nitropack/types\";\nimport type { Nitro, NitroOptions, NitroTypes } from \"nitro/types\";\nimport { dirname, join, resolve } from \"pathe\";\nimport { relativeWithDot } from \"./path\";\nimport { writeFile } from \"./fs\";\nimport type { VirtualModules } from \"nitro-drizzle/shared\";\nimport { isLegacy } from \"../utils/nitro\";\n\nexport function addTsConfigInclude(nitroTypes: LegacyNitroTypes, paths: readonly string[]) {\n nitroTypes.tsConfig ||= {};\n nitroTypes.tsConfig.include ||= [];\n nitroTypes.tsConfig.include.push(...paths);\n}\n\nexport async function addAugmentations(\n nitroOptions: Nitro | LegacyNitro,\n nitroTypes: LegacyNitroTypes,\n augmentations: VirtualModules<`${string}.d.ts`>,\n) {\n const paths = await writeTypeFiles(nitroOptions, augmentations);\n addTsConfigInclude(nitroTypes, paths);\n}\n\nexport async function addDeclarations(\n nitro: Nitro | LegacyNitro,\n nitroTypes: NitroTypes | LegacyNitroTypes,\n declarations: Record<string, VirtualModules<`${string}.d.ts`>>,\n) {\n nitroTypes.tsConfig ||= {};\n nitroTypes.tsConfig.compilerOptions ||= {};\n nitroTypes.tsConfig.compilerOptions.paths ||= {};\n\n for (const alias in declarations) {\n const paths = await writeTypeFiles(nitro, declarations[alias]);\n\n nitroTypes.tsConfig.compilerOptions.paths[alias] = paths.map((path) =>\n path.replace(/\\.d\\.ts$/, \"\"),\n );\n }\n}\n\nfunction getTypesDir(nitroOptions: NitroOptions | LegacyNitroOptions) {\n return join(nitroOptions.buildDir, \"types\");\n}\n\nfunction getTsConfigDir(nitro: Nitro | LegacyNitro) {\n const tsConfigPath = resolve(\n isLegacy(nitro) ? nitro.options.buildDir : getTypesDir(nitro.options),\n nitro.options.typescript.tsconfigPath || \"tsconfig.json\",\n );\n const tsconfigDir = dirname(tsConfigPath);\n return tsconfigDir;\n}\n\nasync function writeTypeFiles(nitro: Nitro | LegacyNitro, modules: VirtualModules) {\n const paths: string[] = [];\n const typesDir = getTypesDir(nitro.options);\n const tsConfigDir = getTsConfigDir(nitro);\n for (const filename in modules) {\n const typesFilename = join(typesDir, filename);\n await writeFile(typesFilename, await getContent(modules[filename]));\n const relativeFilename = relativeWithDot(tsConfigDir, typesFilename);\n paths.push(relativeFilename);\n }\n return paths;\n}\n\nasync function getContent(module: VirtualModule) {\n return \"string\" == typeof module ? module : await module();\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.mjs","names":[],"sources":["../../../src/module/internal/types.ts"],"sourcesContent":["import type {\n Nitro as LegacyNitro,\n NitroOptions as LegacyNitroOptions,\n NitroTypes as LegacyNitroTypes,\n VirtualModule,\n} from \"nitropack/types\";\nimport type { Nitro, NitroOptions, NitroTypes } from \"nitro/types\";\nimport { dirname, join, resolve } from \"pathe\";\nimport { relativeWithDot } from \"./path\";\nimport { writeFile } from \"./fs\";\nimport type { VirtualModules } from \"nitro-drizzle/shared\";\nimport { isLegacy } from \"../utils/nitro\";\n\n/**\n * Adds paths to the tsconfig include array.\n * @param nitroTypes - The Nitro types configuration\n * @param paths - The paths to add\n */\nexport function addTsConfigInclude(nitroTypes: LegacyNitroTypes, paths: readonly string[]) {\n nitroTypes.tsConfig ||= {};\n nitroTypes.tsConfig.include ||= [];\n nitroTypes.tsConfig.include.push(...paths);\n}\n\n/**\n * Writes type declaration files and adds them to the tsconfig include.\n * @param nitroOptions - The Nitro options\n * @param augmentations - The virtual modules containing type declarations\n */\nexport async function addAugmentations(\n nitroOptions: Nitro | LegacyNitro,\n nitroTypes: LegacyNitroTypes,\n augmentations: VirtualModules<`${string}.d.ts`>,\n) {\n const paths = await writeTypeFiles(nitroOptions, augmentations);\n addTsConfigInclude(nitroTypes, paths);\n}\n\n/**\n * Adds type declaration path mappings to the tsconfig compiler options.\n * @param nitro - The Nitro instance\n * @param nitroTypes - The Nitro types configuration\n * @param declarations - The virtual modules to write as type declarations\n */\nexport async function addDeclarations(\n nitro: Nitro | LegacyNitro,\n nitroTypes: NitroTypes | LegacyNitroTypes,\n declarations: Record<string, VirtualModules<`${string}.d.ts`>>,\n) {\n nitroTypes.tsConfig ||= {};\n nitroTypes.tsConfig.compilerOptions ||= {};\n nitroTypes.tsConfig.compilerOptions.paths ||= {};\n\n for (const alias in declarations) {\n const paths = await writeTypeFiles(nitro, declarations[alias]);\n\n nitroTypes.tsConfig.compilerOptions.paths[alias] = paths.map((path) =>\n path.replace(/\\.d\\.ts$/, \"\"),\n );\n }\n}\n\nfunction getTypesDir(nitroOptions: NitroOptions | LegacyNitroOptions) {\n return join(nitroOptions.buildDir, \"types\");\n}\n\nfunction getTsConfigDir(nitro: Nitro | LegacyNitro) {\n const tsConfigPath = resolve(\n isLegacy(nitro) ? nitro.options.buildDir : getTypesDir(nitro.options),\n nitro.options.typescript.tsconfigPath || \"tsconfig.json\",\n );\n const tsconfigDir = dirname(tsConfigPath);\n return tsconfigDir;\n}\n\nasync function writeTypeFiles(nitro: Nitro | LegacyNitro, modules: VirtualModules) {\n const paths: string[] = [];\n const typesDir = getTypesDir(nitro.options);\n const tsConfigDir = getTsConfigDir(nitro);\n for (const filename in modules) {\n const typesFilename = join(typesDir, filename);\n await writeFile(typesFilename, await getContent(modules[filename]));\n const relativeFilename = relativeWithDot(tsConfigDir, typesFilename);\n paths.push(relativeFilename);\n }\n return paths;\n}\n\nasync function getContent(module: VirtualModule) {\n return \"string\" == typeof module ? module : await module();\n}\n"],"mappings":";;;;;;;;;;AAkBA,SAAgB,mBAAmB,YAA8B,OAA0B;CACzF,WAAW,aAAa,CAAC;CACzB,WAAW,SAAS,YAAY,CAAC;CACjC,WAAW,SAAS,QAAQ,KAAK,GAAG,KAAK;AAC3C;;;;;;AAOA,eAAsB,iBACpB,cACA,YACA,eACA;CAEA,mBAAmB,YAAY,MADX,eAAe,cAAc,aAAa,CAC1B;AACtC;;;;;;;AAQA,eAAsB,gBACpB,OACA,YACA,cACA;CACA,WAAW,aAAa,CAAC;CACzB,WAAW,SAAS,oBAAoB,CAAC;CACzC,WAAW,SAAS,gBAAgB,UAAU,CAAC;CAE/C,KAAK,MAAM,SAAS,cAAc;EAChC,MAAM,QAAQ,MAAM,eAAe,OAAO,aAAa,MAAM;EAE7D,WAAW,SAAS,gBAAgB,MAAM,SAAS,MAAM,KAAK,SAC5D,KAAK,QAAQ,YAAY,EAAE,CAC7B;CACF;AACF;AAEA,SAAS,YAAY,cAAiD;CACpE,OAAO,KAAK,aAAa,UAAU,OAAO;AAC5C;AAEA,SAAS,eAAe,OAA4B;CAMlD,OADoB,QAJC,QACnB,SAAS,KAAK,IAAI,MAAM,QAAQ,WAAW,YAAY,MAAM,OAAO,GACpE,MAAM,QAAQ,WAAW,gBAAgB,eAEJ,CACtB;AACnB;AAEA,eAAe,eAAe,OAA4B,SAAyB;CACjF,MAAM,QAAkB,CAAC;CACzB,MAAM,WAAW,YAAY,MAAM,OAAO;CAC1C,MAAM,cAAc,eAAe,KAAK;CACxC,KAAK,MAAM,YAAY,SAAS;EAC9B,MAAM,gBAAgB,KAAK,UAAU,QAAQ;EAC7C,MAAM,UAAU,eAAe,MAAM,WAAW,QAAQ,SAAS,CAAC;EAClE,MAAM,mBAAmB,gBAAgB,aAAa,aAAa;EACnE,MAAM,KAAK,gBAAgB;CAC7B;CACA,OAAO;AACT;AAEA,eAAe,WAAW,QAAuB;CAC/C,OAAO,YAAY,OAAO,SAAS,SAAS,MAAM,OAAO;AAC3D"}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { NitroConfig, ServerAssetDir } from "nitropack/types";
|
|
2
2
|
import { NitroConfig as NitroConfig$1, ServerAssetDir as ServerAssetDir$1 } from "nitro/types";
|
|
3
3
|
//#region src/module/utils/assets.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Updates the server assets configuration, ensuring no duplicates.
|
|
6
|
+
* @param config - The Nitro configuration to update
|
|
7
|
+
* @param assets - The assets to add
|
|
8
|
+
*/
|
|
4
9
|
declare function updateServerAssets(config: NitroConfig$1 | NitroConfig, assets: readonly (ServerAssetDir$1 | ServerAssetDir)[]): void;
|
|
5
10
|
//#endregion
|
|
6
11
|
export { updateServerAssets };
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { consola } from "consola";
|
|
2
2
|
//#region src/module/utils/assets.ts
|
|
3
|
+
/**
|
|
4
|
+
* Updates the server assets configuration, ensuring no duplicates.
|
|
5
|
+
* @param config - The Nitro configuration to update
|
|
6
|
+
* @param assets - The assets to add
|
|
7
|
+
*/
|
|
3
8
|
function updateServerAssets(config, assets) {
|
|
4
9
|
consola.withTag("updateServerAssets").debug(assets);
|
|
5
10
|
config.serverAssets ||= [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assets.mjs","names":[],"sources":["../../../src/module/utils/assets.ts"],"sourcesContent":["import type {\n NitroConfig as LegacyNitroConfig,\n ServerAssetDir as LegacyServerAssetDir,\n} from \"nitropack/types\";\nimport type { NitroConfig, ServerAssetDir } from \"nitro/types\";\nimport { consola } from \"consola\";\n\nexport function updateServerAssets(\n config: NitroConfig | LegacyNitroConfig,\n assets: readonly (ServerAssetDir | LegacyServerAssetDir)[],\n) {\n consola.withTag(\"updateServerAssets\").debug(assets);\n config.serverAssets ||= [];\n config.serverAssets = config.serverAssets\n .filter((_assets) => {\n const baseName = _assets?.baseName;\n if (!baseName) {\n return true;\n }\n return assets.some((assets) => baseName == assets.baseName);\n })\n .concat(assets);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"assets.mjs","names":[],"sources":["../../../src/module/utils/assets.ts"],"sourcesContent":["import type {\n NitroConfig as LegacyNitroConfig,\n ServerAssetDir as LegacyServerAssetDir,\n} from \"nitropack/types\";\nimport type { NitroConfig, ServerAssetDir } from \"nitro/types\";\nimport { consola } from \"consola\";\n\n/**\n * Updates the server assets configuration, ensuring no duplicates.\n * @param config - The Nitro configuration to update\n * @param assets - The assets to add\n */\nexport function updateServerAssets(\n config: NitroConfig | LegacyNitroConfig,\n assets: readonly (ServerAssetDir | LegacyServerAssetDir)[],\n) {\n consola.withTag(\"updateServerAssets\").debug(assets);\n config.serverAssets ||= [];\n config.serverAssets = config.serverAssets\n .filter((_assets) => {\n const baseName = _assets?.baseName;\n if (!baseName) {\n return true;\n }\n return assets.some((assets) => baseName == assets.baseName);\n })\n .concat(assets);\n}\n"],"mappings":";;;;;;;AAYA,SAAgB,mBACd,QACA,QACA;CACA,QAAQ,QAAQ,oBAAoB,CAAC,CAAC,MAAM,MAAM;CAClD,OAAO,iBAAiB,CAAC;CACzB,OAAO,eAAe,OAAO,aAC1B,QAAQ,YAAY;EACnB,MAAM,WAAW,SAAS;EAC1B,IAAI,CAAC,UACH,OAAO;EAET,OAAO,OAAO,MAAM,WAAW,YAAY,OAAO,QAAQ;CAC5D,CAAC,CAAC,CACD,OAAO,MAAM;AAClB"}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { NitroOptions } from "nitropack/types";
|
|
2
2
|
import "nitro/types";
|
|
3
3
|
//#region src/module/utils/externals.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Adds module IDs to the inline externals list for legacy Nitro.
|
|
6
|
+
* @param nitroOptions - The legacy Nitro options
|
|
7
|
+
* @param moduleIds - The module IDs to add as inline externals
|
|
8
|
+
*/
|
|
4
9
|
declare function addInlineExternals(nitroOptions: NitroOptions, moduleIds: readonly string[]): void;
|
|
5
10
|
//#endregion
|
|
6
11
|
export { addInlineExternals };
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
//#region src/module/utils/externals.ts
|
|
2
|
+
/**
|
|
3
|
+
* Adds module IDs to the inline externals list for legacy Nitro.
|
|
4
|
+
* @param nitroOptions - The legacy Nitro options
|
|
5
|
+
* @param moduleIds - The module IDs to add as inline externals
|
|
6
|
+
*/
|
|
2
7
|
function addInlineExternals(nitroOptions, moduleIds) {
|
|
3
8
|
nitroOptions.externals ||= {};
|
|
4
9
|
nitroOptions.externals.inline ||= [];
|
|
5
10
|
nitroOptions.externals.inline.push(...moduleIds);
|
|
6
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Adds module IDs to the no-externals list for modern Nitro.
|
|
14
|
+
* @param nitroOptions - The Nitro options
|
|
15
|
+
* @param moduleIds - The module IDs to exclude from externals
|
|
16
|
+
*/
|
|
7
17
|
function addNoExternals(nitroOptions, moduleIds) {
|
|
8
18
|
if (true === nitroOptions.noExternals) return;
|
|
9
19
|
nitroOptions.noExternals ||= [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"externals.mjs","names":[],"sources":["../../../src/module/utils/externals.ts"],"sourcesContent":["import type { NitroOptions as LegacyNitroOptions } from \"nitropack/types\";\nimport type { NitroOptions } from \"nitro/types\";\n\nexport function addInlineExternals(nitroOptions: LegacyNitroOptions, moduleIds: readonly string[]) {\n // @ts-expect-error\n nitroOptions.externals ||= {};\n nitroOptions.externals.inline ||= [];\n nitroOptions.externals.inline.push(...moduleIds);\n}\n\nexport function addNoExternals(nitroOptions: NitroOptions, moduleIds: readonly string[]) {\n if (true === nitroOptions.noExternals) {\n return;\n }\n nitroOptions.noExternals ||= [];\n nitroOptions.noExternals.push(...moduleIds);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"externals.mjs","names":[],"sources":["../../../src/module/utils/externals.ts"],"sourcesContent":["import type { NitroOptions as LegacyNitroOptions } from \"nitropack/types\";\nimport type { NitroOptions } from \"nitro/types\";\n\n/**\n * Adds module IDs to the inline externals list for legacy Nitro.\n * @param nitroOptions - The legacy Nitro options\n * @param moduleIds - The module IDs to add as inline externals\n */\nexport function addInlineExternals(nitroOptions: LegacyNitroOptions, moduleIds: readonly string[]) {\n // @ts-expect-error\n nitroOptions.externals ||= {};\n nitroOptions.externals.inline ||= [];\n nitroOptions.externals.inline.push(...moduleIds);\n}\n\n/**\n * Adds module IDs to the no-externals list for modern Nitro.\n * @param nitroOptions - The Nitro options\n * @param moduleIds - The module IDs to exclude from externals\n */\nexport function addNoExternals(nitroOptions: NitroOptions, moduleIds: readonly string[]) {\n if (true === nitroOptions.noExternals) {\n return;\n }\n nitroOptions.noExternals ||= [];\n nitroOptions.noExternals.push(...moduleIds);\n}\n"],"mappings":";;;;;;AAQA,SAAgB,mBAAmB,cAAkC,WAA8B;CAEjG,aAAa,cAAc,CAAC;CAC5B,aAAa,UAAU,WAAW,CAAC;CACnC,aAAa,UAAU,OAAO,KAAK,GAAG,SAAS;AACjD;;;;;;AAOA,SAAgB,eAAe,cAA4B,WAA8B;CACvF,IAAI,SAAS,aAAa,aACxB;CAEF,aAAa,gBAAgB,CAAC;CAC9B,aAAa,YAAY,KAAK,GAAG,SAAS;AAC5C"}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { Nitro } from "nitropack/types";
|
|
2
2
|
import { Nitro as Nitro$1 } from "nitro/types";
|
|
3
3
|
//#region src/module/utils/nitro.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Checks if the given Nitro instance is using the legacy API (nitropack).
|
|
6
|
+
* @param nitro - The Nitro instance to check
|
|
7
|
+
* @returns `true` if the Nitro instance is legacy (major version < 3)
|
|
8
|
+
*/
|
|
4
9
|
declare function isLegacy(nitro: Nitro$1 | Nitro): nitro is Nitro;
|
|
5
10
|
//#endregion
|
|
6
11
|
export { isLegacy };
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
//#region src/module/utils/nitro.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if the given Nitro instance is using the legacy API (nitropack).
|
|
4
|
+
* @param nitro - The Nitro instance to check
|
|
5
|
+
* @returns `true` if the Nitro instance is legacy (major version < 3)
|
|
6
|
+
*/
|
|
2
7
|
function isLegacy(nitro) {
|
|
3
8
|
return nitro.meta.majorVersion < 3;
|
|
4
9
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nitro.mjs","names":[],"sources":["../../../src/module/utils/nitro.ts"],"sourcesContent":["import type { Nitro as LegacyNitro } from \"nitropack/types\";\nimport type { Nitro } from \"nitro/types\";\n\nexport function isLegacy(nitro: Nitro | LegacyNitro): nitro is LegacyNitro {\n return nitro.meta.majorVersion < 3;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"nitro.mjs","names":[],"sources":["../../../src/module/utils/nitro.ts"],"sourcesContent":["import type { Nitro as LegacyNitro } from \"nitropack/types\";\nimport type { Nitro } from \"nitro/types\";\n\n/**\n * Checks if the given Nitro instance is using the legacy API (nitropack).\n * @param nitro - The Nitro instance to check\n * @returns `true` if the Nitro instance is legacy (major version < 3)\n */\nexport function isLegacy(nitro: Nitro | LegacyNitro): nitro is LegacyNitro {\n return nitro.meta.majorVersion < 3;\n}\n"],"mappings":";;;;;;AAQA,SAAgB,SAAS,OAAkD;CACzE,OAAO,MAAM,KAAK,eAAe;AACnC"}
|
package/dist/module.d.mts
CHANGED
|
@@ -11,9 +11,14 @@ import { Connector } from "nitro-drizzle/drivers";
|
|
|
11
11
|
* Datasource-specific configuration options.
|
|
12
12
|
*/
|
|
13
13
|
type DatasourceOptionsMapper<T extends Variant<Connector<any, any, any, any>, ConnectorSpecifier>> = T extends any ? Variant<{
|
|
14
|
-
drivers: readonly string[]
|
|
14
|
+
drivers: readonly string[] | {
|
|
15
|
+
[name: string]: boolean;
|
|
16
|
+
};
|
|
15
17
|
}, Pick<T["selector"], "name">> : never;
|
|
16
18
|
type DatasourceOptionsVariants = DatasourceOptionsMapper<ConnectorVariants>;
|
|
19
|
+
/**
|
|
20
|
+
* Datasource-specific configuration options mapped by datasource name.
|
|
21
|
+
*/
|
|
17
22
|
type DatasourceOptions = ExpandVariants<DatasourceOptionsVariants, ["name"]>;
|
|
18
23
|
declare module "nitropack/types" {
|
|
19
24
|
interface NitroOptions {
|
|
@@ -40,9 +45,16 @@ interface ModuleOptions {
|
|
|
40
45
|
*/
|
|
41
46
|
migrations?: false | Partial<MigrationOptions>;
|
|
42
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Resolved module configuration with required fields.
|
|
50
|
+
*/
|
|
43
51
|
type ModuleConfig = Required<ModuleOptions> & {
|
|
44
52
|
migrations: false | Required<MigrationOptions>;
|
|
45
53
|
};
|
|
54
|
+
/**
|
|
55
|
+
* Creates the default module configuration options.
|
|
56
|
+
* @returns The default module configuration
|
|
57
|
+
*/
|
|
46
58
|
declare function createDefaultOptions(): {
|
|
47
59
|
readonly baseDir: "./drizzle";
|
|
48
60
|
readonly configPattern: readonly ["drizzle.config.{js,ts}", "drizzle-*.config.{js,ts}"];
|
|
@@ -52,6 +64,11 @@ declare function createDefaultOptions(): {
|
|
|
52
64
|
readonly migrateOnInit: false;
|
|
53
65
|
};
|
|
54
66
|
};
|
|
67
|
+
/**
|
|
68
|
+
* Merges user-provided module options with defaults.
|
|
69
|
+
* @param options - Optional module configuration overrides
|
|
70
|
+
* @returns The resolved module configuration
|
|
71
|
+
*/
|
|
55
72
|
declare function defineModuleConfig(options?: ModuleOptions): ModuleConfig;
|
|
56
73
|
declare const module: NitroModule & NitroModule$1;
|
|
57
74
|
//#endregion
|