nitro-drizzle 0.3.0-beta.2 → 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.
Files changed (109) hide show
  1. package/README.md +24 -3
  2. package/dist/config/defineConfig.d.mts +4 -4
  3. package/dist/config/defineConfig.mjs +4 -4
  4. package/dist/config/defineConfig.mjs.map +1 -1
  5. package/dist/context/internal/async.mjs +8 -0
  6. package/dist/context/internal/async.mjs.map +1 -1
  7. package/dist/context/internal/codegen.mjs +28 -0
  8. package/dist/context/internal/codegen.mjs.map +1 -0
  9. package/dist/context/internal/config.mjs +9 -4
  10. package/dist/context/internal/config.mjs.map +1 -1
  11. package/dist/context/internal/format.mjs +6 -0
  12. package/dist/context/internal/format.mjs.map +1 -1
  13. package/dist/context/internal/fs.mjs +7 -0
  14. package/dist/context/internal/fs.mjs.map +1 -1
  15. package/dist/context/internal/logger.mjs +6 -0
  16. package/dist/context/internal/logger.mjs.map +1 -1
  17. package/dist/context/internal/templates.mjs +84 -31
  18. package/dist/context/internal/templates.mjs.map +1 -1
  19. package/dist/context/internal/virtual.mjs +51 -26
  20. package/dist/context/internal/virtual.mjs.map +1 -1
  21. package/dist/context.d.mts +22 -15
  22. package/dist/context.mjs +58 -15
  23. package/dist/context.mjs.map +1 -1
  24. package/dist/dialects/sqlite.d.mts +2 -2
  25. package/dist/dialects/sqlite.mjs +3 -3
  26. package/dist/dialects/sqlite.mjs.map +1 -1
  27. package/dist/drivers/{internal/d1-dialect.mjs → d1/dialect.mjs} +4 -3
  28. package/dist/drivers/d1/dialect.mjs.map +1 -0
  29. package/dist/drivers/d1-http.d.mts +1 -1
  30. package/dist/drivers/d1-http.mjs +3 -3
  31. package/dist/drivers/d1-http.mjs.map +1 -1
  32. package/dist/drivers/d1.d.mts +2 -1
  33. package/dist/drivers/d1.mjs +3 -3
  34. package/dist/drivers/d1.mjs.map +1 -1
  35. package/dist/drivers/db0.d.mts +2 -0
  36. package/dist/drivers/db0.mjs +3 -2
  37. package/dist/drivers/db0.mjs.map +1 -1
  38. package/dist/drivers/index.d.mts +14 -7
  39. package/dist/drivers/index.mjs +3 -3
  40. package/dist/drivers/index.mjs.map +1 -1
  41. package/dist/drivers/mysql.mjs +2 -2
  42. package/dist/drivers/mysql.mjs.map +1 -1
  43. package/dist/drivers/pglite.d.mts +1 -0
  44. package/dist/drivers/pglite.mjs +3 -2
  45. package/dist/drivers/pglite.mjs.map +1 -1
  46. package/dist/drivers/postgresql.d.mts +2 -1
  47. package/dist/drivers/postgresql.mjs +2 -2
  48. package/dist/drivers/postgresql.mjs.map +1 -1
  49. package/dist/drivers/sqlite.mjs +2 -2
  50. package/dist/drivers/sqlite.mjs.map +1 -1
  51. package/dist/middleware/context.d.mts +8 -0
  52. package/dist/middleware/context.mjs +4 -0
  53. package/dist/middleware/context.mjs.map +1 -1
  54. package/dist/migrations/migrate.mjs +3 -2
  55. package/dist/migrations/migrate.mjs.map +1 -1
  56. package/dist/migrations/task.d.mts +4 -0
  57. package/dist/migrations/task.mjs +4 -0
  58. package/dist/migrations/task.mjs.map +1 -1
  59. package/dist/migrations/useMigrations.d.mts +2 -2
  60. package/dist/migrations/useMigrations.mjs +3 -1
  61. package/dist/migrations/useMigrations.mjs.map +1 -1
  62. package/dist/module/internal/fs.mjs +5 -0
  63. package/dist/module/internal/fs.mjs.map +1 -1
  64. package/dist/module/internal/path.mjs +6 -0
  65. package/dist/module/internal/path.mjs.map +1 -1
  66. package/dist/module/internal/reload.mjs +6 -0
  67. package/dist/module/internal/reload.mjs.map +1 -1
  68. package/dist/module/internal/resolver.mjs +6 -0
  69. package/dist/module/internal/resolver.mjs.map +1 -1
  70. package/dist/module/internal/rollup.mjs +5 -0
  71. package/dist/module/internal/rollup.mjs.map +1 -1
  72. package/dist/module/internal/types.mjs +16 -0
  73. package/dist/module/internal/types.mjs.map +1 -1
  74. package/dist/module/utils/assets.d.mts +5 -0
  75. package/dist/module/utils/assets.mjs +7 -0
  76. package/dist/module/utils/assets.mjs.map +1 -1
  77. package/dist/module/utils/externals.d.mts +5 -0
  78. package/dist/module/utils/externals.mjs +10 -0
  79. package/dist/module/utils/externals.mjs.map +1 -1
  80. package/dist/module/utils/nitro.d.mts +5 -0
  81. package/dist/module/utils/nitro.mjs +5 -0
  82. package/dist/module/utils/nitro.mjs.map +1 -1
  83. package/dist/module.d.mts +24 -2
  84. package/dist/module.mjs +21 -2
  85. package/dist/module.mjs.map +1 -1
  86. package/dist/plugins/legacy/init.mjs +27 -10
  87. package/dist/plugins/legacy/init.mjs.map +1 -1
  88. package/dist/runtime/internal/config.mjs +18 -6
  89. package/dist/runtime/internal/config.mjs.map +1 -1
  90. package/dist/runtime/internal/createDatasource.mjs +24 -5
  91. package/dist/runtime/internal/createDatasource.mjs.map +1 -1
  92. package/dist/runtime/useConfig.d.mts +15 -0
  93. package/dist/runtime/useConfig.mjs +22 -0
  94. package/dist/runtime/useConfig.mjs.map +1 -0
  95. package/dist/runtime/useDatasource.d.mts +5 -2
  96. package/dist/runtime/useDatasource.mjs +2 -1
  97. package/dist/runtime/useDatasource.mjs.map +1 -1
  98. package/dist/runtime/useDialect.d.mts +26 -0
  99. package/dist/runtime/useDialect.mjs +22 -0
  100. package/dist/runtime/useDialect.mjs.map +1 -0
  101. package/dist/runtime.d.mts +45 -28
  102. package/dist/runtime.mjs +3 -1
  103. package/dist/shared/variants.d.mts +35 -0
  104. package/dist/shared/variants.mjs +17 -0
  105. package/dist/shared/variants.mjs.map +1 -0
  106. package/dist/shared.d.mts +11 -3
  107. package/dist/shared.mjs +2 -1
  108. package/package.json +7 -5
  109. package/dist/drivers/internal/d1-dialect.mjs.map +0 -1
@@ -1,3 +1,4 @@
1
+ import { MaybePromise, UnionToIntersection } from "nitro-drizzle/shared";
1
2
  //#region src/drivers/index.d.ts
2
3
  /**
3
4
  * Schema type representing database tables.
@@ -7,29 +8,35 @@ type Schema = Record<string, any>;
7
8
  * Factory function type for creating Drizzle datasource instances.
8
9
  * @template TDatabase - The database type
9
10
  */
10
- type DatasourceDriver<TDatabase> = <TSchema extends Schema>(config: any, schema: TSchema) => Datasource<TDatabase, TSchema> | Promise<Datasource<TDatabase, TSchema>>;
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
+ */
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]>;
11
18
  /**
12
19
  * Defines a driver factory function.
13
- * @template TFactory - The driver factory type
20
+ * @template TConnector - The driver factory type
14
21
  * @param create - The driver factory function
15
22
  * @returns The same driver factory function
16
23
  */
17
- declare function defineDriver<TFactory extends DatasourceDriver<any>>(create: TFactory): TFactory;
24
+ declare function defineConnector<TDialect extends string, TSchema extends Schema, TConnector extends Connector<TDialect, any, TSchema, any>>(create: TConnector): TConnector;
18
25
  /**
19
26
  * Datasource interface representing a connected database with schema.
20
27
  * @template TDatabase - The database client type
21
28
  * @template TSchema - The schema type
22
29
  */
23
- interface Datasource<TDatabase, TSchema extends Schema> {
30
+ interface Datasource<_TDialect, TDatabase, TSchema extends Schema> {
24
31
  /** The database client instance. */
25
32
  database: TDatabase;
26
33
  /** The schema definition. */
27
34
  schema: TSchema;
28
35
  /** Waits for the database connection to be ready. */
29
- waitReady: () => Promise<void>;
36
+ waitReady: () => MaybePromise<void>;
30
37
  /** Closes the database connection. */
31
- close: () => Promise<void>;
38
+ close: () => MaybePromise<void>;
32
39
  }
33
40
  //#endregion
34
- export { Datasource, DatasourceDriver, Schema, defineDriver };
41
+ export { Connector, Datasource, MergeSchema, Schema, defineConnector };
35
42
  //# sourceMappingURL=index.d.mts.map
@@ -1,14 +1,14 @@
1
1
  //#region src/drivers/index.ts
2
2
  /**
3
3
  * Defines a driver factory function.
4
- * @template TFactory - The driver factory type
4
+ * @template TConnector - The driver factory type
5
5
  * @param create - The driver factory function
6
6
  * @returns The same driver factory function
7
7
  */
8
- function defineDriver(create) {
8
+ function defineConnector(create) {
9
9
  return create;
10
10
  }
11
11
  //#endregion
12
- export { defineDriver };
12
+ export { defineConnector };
13
13
 
14
14
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/drivers/index.ts"],"sourcesContent":["/**\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 DatasourceDriver<TDatabase> = <TSchema extends Schema>(\n config: any,\n schema: TSchema,\n) => Datasource<TDatabase, TSchema> | Promise<Datasource<TDatabase, TSchema>>;\n\n/**\n * Defines a driver factory function.\n * @template TFactory - The driver factory type\n * @param create - The driver factory function\n * @returns The same driver factory function\n */\nexport function defineDriver<TFactory extends DatasourceDriver<any>>(create: TFactory): TFactory {\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<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: () => Promise<void>;\n /** Closes the database connection. */\n close: () => Promise<void>;\n}\n"],"mappings":";;;;;;;AAoBA,SAAgB,aAAqD,QAA4B;CAC/F,OAAO;AACT"}
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,4 +1,4 @@
1
- import { defineDriver } from "./index.mjs";
1
+ import { defineConnector } from "./index.mjs";
2
2
  import { SELECT_1 } from "./internal/sql.mjs";
3
3
  import { drizzle } from "drizzle-orm/mysql2";
4
4
  import { createConnection } from "mysql2/promise";
@@ -10,7 +10,7 @@ import { createConnection } from "mysql2/promise";
10
10
  * @param schema - The Drizzle schema
11
11
  * @returns A Datasource instance
12
12
  */
13
- var mysql_default = defineDriver(async (config, schema) => {
13
+ var mysql_default = defineConnector(async (config, schema) => {
14
14
  const database = drizzle(await createConnection(config.url), {
15
15
  schema,
16
16
  mode: "default"
@@ -1 +1 @@
1
- {"version":3,"file":"mysql.mjs","names":[],"sources":["../../src/drivers/mysql.ts"],"sourcesContent":["import { drizzle } from \"drizzle-orm/mysql2\";\nimport { createConnection } from \"mysql2/promise\";\nimport { defineDriver, type Schema } from \".\";\nimport { SELECT_1 } from \"./internal/sql\";\n\n/**\n * MySQL datasource driver using mysql2.\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(async <TSchema extends Schema>(config: Options, schema: TSchema) => {\n const connection = await createConnection(config.url);\n const database = drizzle(connection, { schema, mode: \"default\" });\n return {\n database,\n schema,\n waitReady: async () => {\n await database.execute(SELECT_1);\n },\n close: async () => {\n await database.$client.end();\n },\n };\n});\n\n/**\n * Configuration options for the MySQL driver.\n */\nexport type Options = {\n /** Database connection URL. */\n url: string;\n};\n"],"mappings":";;;;;;;;;;;;AAYA,IAAA,gBAAe,aAAa,OAA+B,QAAiB,WAAoB;CAE9F,MAAM,WAAW,QAAQ,MADA,iBAAiB,OAAO,GAAG,GACf;EAAE;EAAQ,MAAM;CAAU,CAAC;CAChE,OAAO;EACL;EACA;EACA,WAAW,YAAY;GACrB,MAAM,SAAS,QAAQ,QAAQ;EACjC;EACA,OAAO,YAAY;GACjB,MAAM,SAAS,QAAQ,IAAI;EAC7B;CACF;AACF,CAAC"}
1
+ {"version":3,"file":"mysql.mjs","names":[],"sources":["../../src/drivers/mysql.ts"],"sourcesContent":["import { drizzle } from \"drizzle-orm/mysql2\";\nimport { createConnection } from \"mysql2/promise\";\nimport { defineConnector, type Schema } from \".\";\nimport { SELECT_1 } from \"./internal/sql\";\n\n/**\n * MySQL datasource driver using mysql2.\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 defineConnector(async <TSchema extends Schema>(config: Options, schema: TSchema) => {\n const connection = await createConnection(config.url);\n const database = drizzle(connection, { schema, mode: \"default\" });\n return {\n database,\n schema,\n waitReady: async () => {\n await database.execute(SELECT_1);\n },\n close: async () => {\n await database.$client.end();\n },\n };\n});\n\n/**\n * Configuration options for the MySQL driver.\n */\nexport type Options = {\n /** Database connection URL. */\n url: string;\n};\n"],"mappings":";;;;;;;;;;;;AAYA,IAAA,gBAAe,gBAAgB,OAA+B,QAAiB,WAAoB;CAEjG,MAAM,WAAW,QAAQ,MADA,iBAAiB,OAAO,GAAG,GACf;EAAE;EAAQ,MAAM;CAAU,CAAC;CAChE,OAAO;EACL;EACA;EACA,WAAW,YAAY;GACrB,MAAM,SAAS,QAAQ,QAAQ;EACjC;EACA,OAAO,YAAY;GACjB,MAAM,SAAS,QAAQ,IAAI;EAC7B;CACF;AACF,CAAC"}
@@ -9,6 +9,7 @@ import { PGlite, PGliteOptions } from "@electric-sql/pglite";
9
9
  * @returns A Datasource instance
10
10
  */
11
11
  declare const _default: <TSchema extends Schema>(options: PGliteOptions, schema: TSchema) => {
12
+ dialect: string;
12
13
  database: import("drizzle-orm/pglite").PgliteDatabase<TSchema> & {
13
14
  $client: PGlite;
14
15
  };
@@ -1,4 +1,4 @@
1
- import { defineDriver } from "./index.mjs";
1
+ import { defineConnector } from "./index.mjs";
2
2
  import { drizzle } from "drizzle-orm/pglite";
3
3
  import { PGlite } from "@electric-sql/pglite";
4
4
  //#region src/drivers/pglite.ts
@@ -9,9 +9,10 @@ import { PGlite } from "@electric-sql/pglite";
9
9
  * @param schema - The Drizzle schema
10
10
  * @returns A Datasource instance
11
11
  */
12
- var pglite_default = defineDriver((options, schema) => {
12
+ var pglite_default = defineConnector((options, schema) => {
13
13
  const database = drizzle(new PGlite(options), { schema });
14
14
  return {
15
+ dialect: "postgresql",
15
16
  database,
16
17
  schema,
17
18
  async waitReady() {
@@ -1 +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 connector = new PGlite(options);\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"],"mappings":";;;;;;;;;;;AAWA,IAAA,iBAAe,cAAsC,SAAwB,WAAoB;CAE/F,MAAM,WAAW,QAAQ,IADH,OAAO,OACI,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"}
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 { defineConnector, 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 defineConnector(\n <TSchema extends Schema>(options: PGliteOptions, schema: TSchema) => {\n const driver = new PGlite(options);\n const database = drizzle(driver, { schema });\n return {\n dialect: \"postgresql\",\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"],"mappings":";;;;;;;;;;;AAWA,IAAA,iBAAe,iBACY,SAAwB,WAAoB;CAEnE,MAAM,WAAW,QAAQ,IADN,OAAO,OACI,GAAG,EAAE,OAAO,CAAC;CAC3C,OAAO;EACL,SAAS;EACT;EACA;EACA,MAAM,YAAY;GAChB,MAAM,SAAS,QAAQ;EACzB;EACA,MAAM,QAAQ;GACZ,MAAM,SAAS,QAAQ,MAAM;EAC/B;CACF;AACF,CACF"}
@@ -1,3 +1,4 @@
1
+ import { Schema } from "./index.mjs";
1
2
  import createPostgres, { Options as Options$1 } from "postgres";
2
3
  //#region src/drivers/postgresql.d.ts
3
4
  /**
@@ -7,7 +8,7 @@ import createPostgres, { Options as Options$1 } from "postgres";
7
8
  * @param schema - The Drizzle schema
8
9
  * @returns A Datasource instance
9
10
  */
10
- declare const _default: <TSchema extends Record<string, any>>(options: Options, schema: TSchema) => {
11
+ declare const _default: <TSchema extends Schema>(options: Options, schema: TSchema) => {
11
12
  database: import("drizzle-orm/postgres-js").PostgresJsDatabase<TSchema> & {
12
13
  $client: createPostgres.Sql<{}>;
13
14
  };
@@ -1,4 +1,4 @@
1
- import { defineDriver } from "./index.mjs";
1
+ import { defineConnector } from "./index.mjs";
2
2
  import { SELECT_1 } from "./internal/sql.mjs";
3
3
  import { drizzle } from "drizzle-orm/postgres-js";
4
4
  import createPostgres from "postgres";
@@ -10,7 +10,7 @@ import createPostgres from "postgres";
10
10
  * @param schema - The Drizzle schema
11
11
  * @returns A Datasource instance
12
12
  */
13
- var postgresql_default = defineDriver((options, schema) => {
13
+ var postgresql_default = defineConnector((options, schema) => {
14
14
  const { url, ...other } = options;
15
15
  const database = drizzle(url ? createPostgres(url, other) : createPostgres(other), { schema });
16
16
  return {
@@ -1 +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"}
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 { defineConnector, type Schema } 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 defineConnector(<TSchema extends Schema>(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 * 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,iBAAyC,SAAkB,WAAoB;CAC5F,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,CAAC"}
@@ -1,4 +1,4 @@
1
- import { defineDriver } from "./index.mjs";
1
+ import { defineConnector } from "./index.mjs";
2
2
  import { SELECT_1 } from "./internal/sql.mjs";
3
3
  import sqlite3 from "better-sqlite3";
4
4
  import { drizzle } from "drizzle-orm/better-sqlite3";
@@ -10,7 +10,7 @@ import { drizzle } from "drizzle-orm/better-sqlite3";
10
10
  * @param schema - The Drizzle schema
11
11
  * @returns A Datasource instance
12
12
  */
13
- var sqlite_default = defineDriver((config, schema) => {
13
+ var sqlite_default = defineConnector((config, schema) => {
14
14
  const { url, ...options } = config;
15
15
  const database = drizzle(sqlite3(url, options), { schema });
16
16
  return {
@@ -1 +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"}
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 { defineConnector, 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 defineConnector(<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,iBAAyC,QAAiB,WAAoB;CAC3F,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"}
@@ -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;AAEJ,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
+ {"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,7 +1,7 @@
1
1
  import { useMigrations } from "./useMigrations.mjs";
2
2
  import { migrateDatabase } from "./internal/migrate.mjs";
3
+ import { useConfig, useDatasource } from "nitro-drizzle/runtime";
3
4
  import { migrationConfig } from "#nitro-drizzle/migrations";
4
- import { useDatasource } from "nitro-drizzle/runtime";
5
5
  //#region src/migrations/migrate.ts
6
6
  /**
7
7
  * Runs migrations for a specific datasource.
@@ -10,9 +10,10 @@ import { useDatasource } from "nitro-drizzle/runtime";
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;CAC/B,MAAM,UAAU;CAChB,MAAM,gBAAgB,UAAoC,YAAY,MAAM;CAC5E,OAAO,CAAC;AACV"}
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 };
@@ -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":";;AAKA,MAAM,OAA4D,EAChE,MAAM,IAAI,OAAO;CACf,MAAM,EAAE,SAAS,MAAM;CAEvB,OAAO,EAAE,QAAA,MADY,QAAQ,IAAI,EACjB;AAClB,EACF"}
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"}
@@ -8,7 +8,7 @@ import { Storage } from "unstorage";
8
8
  * @param name - The datasource name
9
9
  * @returns Storage instance for migrations
10
10
  */
11
- declare function useMigrationsStorage<TName extends keyof DatasourceRegistry>(name: TName): Storage<string>;
11
+ declare function useMigrationsStorage<TName extends keyof DatasourceRegistry & string>(name: TName): Storage<string>;
12
12
  /** Storage key for the migration journal. */
13
13
  declare const JOURNAL_STORAGE_KEY: "meta/_journal.json";
14
14
  /**
@@ -18,7 +18,7 @@ declare const JOURNAL_STORAGE_KEY: "meta/_journal.json";
18
18
  * @returns Async iterable of migrations
19
19
  * @throws If migration journal is not found
20
20
  */
21
- declare function useMigrations<TName extends keyof DatasourceRegistry>(name: TName): Promise<AsyncIterable<Migration>>;
21
+ declare function useMigrations<TName extends keyof DatasourceRegistry & string>(name: TName): Promise<AsyncIterable<Migration>>;
22
22
  /** Single entry in the migration journal. */
23
23
  interface MigrationJournalItem {
24
24
  /** Migration index/order number. */
@@ -1,4 +1,5 @@
1
1
  import { useStorage } from "#nitro-drizzle/runtime";
2
+ import { useConfig } from "nitro-drizzle/runtime";
2
3
  import { digest } from "ohash";
3
4
  import { MIGRATIONS_STORAGE_BASE } from "#nitro-drizzle/migrations";
4
5
  //#region src/migrations/useMigrations.ts
@@ -9,7 +10,8 @@ import { MIGRATIONS_STORAGE_BASE } from "#nitro-drizzle/migrations";
9
10
  * @returns Storage instance for migrations
10
11
  */
11
12
  function useMigrationsStorage(name) {
12
- return useStorage(`assets:${MIGRATIONS_STORAGE_BASE}:${name}`);
13
+ const { driver } = useConfig(name);
14
+ return useStorage(`assets:${MIGRATIONS_STORAGE_BASE}:${name}:${driver}`);
13
15
  }
14
16
  /** Storage key for the migration journal. */
15
17
  const JOURNAL_STORAGE_KEY = "meta/_journal.json";
@@ -1 +1 @@
1
- {"version":3,"file":"useMigrations.mjs","names":[],"sources":["../../src/migrations/useMigrations.ts"],"sourcesContent":["import type { Storage } from \"unstorage\";\nimport { digest } from \"ohash\";\nimport type { DatasourceRegistry } from \"nitro-drizzle/runtime\";\nimport { MIGRATIONS_STORAGE_BASE } from \"#nitro-drizzle/migrations\";\nimport { useStorage } from \"#nitro-drizzle/runtime\";\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(`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 new Error(`Cannot find migration journal for '${name}'`);\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 new Error(`Cannot find migration filename: ${filename}`);\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":";;;;;;;;;;AAaA,SAAgB,qBACd,MACiB;CACjB,OAAO,WAAW,UAAU,wBAAwB,GAAG,MAAM;AAC/D;;AAGA,MAAa,sBAAsB;;;;;;;;AASnC,eAAsB,cACpB,MACmC;CACnC,MAAM,UAAU,qBAAqB,IAAI;CACzC,MAAM,UAAU,MAAM,QAAQ,QAA0B,mBAAmB;CAC3E,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,sCAAsC,KAAK,EAAE;CAG/D,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,IAAI,MAAM,mCAAmC,UAAU;EAY/D,MAAM;GARJ;GACA;GACA,KAAK,MAAM,MAAM,oBAAoB;GACrC,MAAM,OAAO,KAAK;GAClB,cAAc;GACd,KAAK;EAGO;CAChB;AACF"}
1
+ {"version":3,"file":"useMigrations.mjs","names":[],"sources":["../../src/migrations/useMigrations.ts"],"sourcesContent":["import type { Storage } from \"unstorage\";\nimport { digest } from \"ohash\";\nimport type { DatasourceRegistry } from \"nitro-drizzle/runtime\";\nimport { MIGRATIONS_STORAGE_BASE } from \"#nitro-drizzle/migrations\";\nimport { useStorage } from \"#nitro-drizzle/runtime\";\nimport type { Migration } from \"./internal/migrate\";\nimport { useConfig } from \"nitro-drizzle/runtime\";\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 & string>(\n name: TName,\n): Storage<string> {\n const { driver } = useConfig(name);\n return useStorage(`assets:${MIGRATIONS_STORAGE_BASE}:${name}:${driver}`);\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 & string>(\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 new Error(`Cannot find migration journal for '${name}'`);\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 new Error(`Cannot find migration filename: ${filename}`);\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,MAAM,EAAE,WAAW,UAAU,IAAI;CACjC,OAAO,WAAW,UAAU,wBAAwB,GAAG,KAAK,GAAG,QAAQ;AACzE;;AAGA,MAAa,sBAAsB;;;;;;;;AASnC,eAAsB,cACpB,MACmC;CACnC,MAAM,UAAU,qBAAqB,IAAI;CACzC,MAAM,UAAU,MAAM,QAAQ,QAA0B,mBAAmB;CAC3E,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,sCAAsC,KAAK,EAAE;CAG/D,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,IAAI,MAAM,mCAAmC,UAAU;EAY/D,MAAM;GARJ;GACA;GACA,KAAK,MAAM,MAAM,oBAAoB;GACrC,MAAM,OAAO,KAAK;GAClB,cAAc;GACd,KAAK;EAGO;CAChB;AACF"}
@@ -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":";;;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"}
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;AAEpB,SAAgB,gBAAgB,MAAc,IAAY;CACxD,MAAM,MAAM,SAAS,MAAM,EAAE;CAC7B,OAAO,YAAY,KAAK,GAAG,IAAI,MAAM,OAAO;AAC9C"}
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":";;AAQA,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
+ {"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":";;;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;AACF"}
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":";AAIA,eAAsB,UACpB,cACA,QACA;CAEA,aAAa,UAAU,CAAC,GADR,CAAC,MAAM,aAAa,OAAO,CAAC,CAAC,KACZ,GAAG,MAAM;AAC5C"}
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":";;;;;AAaA,SAAgB,mBAAmB,YAA8B,OAA0B;CACzF,WAAW,aAAa,CAAC;CACzB,WAAW,SAAS,YAAY,CAAC;CACjC,WAAW,SAAS,QAAQ,KAAK,GAAG,KAAK;AAC3C;AAEA,eAAsB,iBACpB,cACA,YACA,eACA;CAEA,mBAAmB,YAAY,MADX,eAAe,cAAc,aAAa,CAC1B;AACtC;AAEA,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
+ {"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,12 @@
1
+ import { consola } from "consola";
1
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
+ */
2
8
  function updateServerAssets(config, assets) {
9
+ consola.withTag("updateServerAssets").debug(assets);
3
10
  config.serverAssets ||= [];
4
11
  config.serverAssets = config.serverAssets.filter((_assets) => {
5
12
  const baseName = _assets?.baseName;
@@ -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\";\n\nexport function updateServerAssets(\n config: NitroConfig | LegacyNitroConfig,\n assets: readonly (ServerAssetDir | LegacyServerAssetDir)[],\n) {\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":";AAMA,SAAgB,mBACd,QACA,QACA;CACA,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
+ {"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 };