nitro-drizzle 0.2.10 → 0.2.12
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 +3 -3
- package/dist/config/defineConfig.d.mts +1 -2
- package/dist/config/defineConfig.mjs +1 -1
- package/dist/config/defineConfig.mjs.map +1 -1
- package/dist/context/internal/templates.mjs +1 -1
- package/dist/context/internal/templates.mjs.map +1 -1
- package/dist/context.d.mts +0 -1
- package/dist/dialects/index.d.mts +3 -4
- package/dist/dialects/mysql.d.mts +0 -1
- package/dist/dialects/postgresql.d.mts +0 -1
- package/dist/dialects/sqlite.d.mts +0 -1
- package/dist/drivers/d1-http.d.mts +5 -3
- package/dist/drivers/d1.d.mts +2 -2
- package/dist/drivers/db0.d.mts +0 -1
- package/dist/drivers/mysql.d.mts +2 -2
- package/dist/drivers/pglite.d.mts +3 -2
- package/dist/drivers/postgresql.d.mts +2 -2
- package/dist/drivers/sqlite.d.mts +2 -2
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +2 -0
- package/dist/meta.d.mts +0 -1
- package/dist/migrations/internal/migrate.d.mts +3 -2
- package/dist/migrations/migrate.d.mts +0 -1
- package/dist/migrations/task.d.mts +0 -1
- package/dist/migrations/useMigrations.d.mts +0 -1
- package/dist/module/utils/assets.d.mts +0 -1
- package/dist/module/utils/externals.d.mts +0 -1
- package/dist/module.d.mts +11 -5
- package/dist/module.mjs.map +1 -1
- package/dist/plugins/migrate.d.mts +0 -1
- package/dist/runtime/useDatasource.d.mts +2 -2
- package/dist/runtime.d.mts +5 -6
- package/dist/shared.d.mts +0 -1
- package/dist/utils/usePrimaryKey.d.mts +0 -1
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -37,14 +37,14 @@ npm install @cloudflare/workers-types
|
|
|
37
37
|
|
|
38
38
|
### 1. Configure Nitro Module
|
|
39
39
|
|
|
40
|
-
Add `nitro-drizzle
|
|
40
|
+
Add `nitro-drizzle` to your `nitro.config.ts` modules:
|
|
41
41
|
|
|
42
42
|
```ts
|
|
43
43
|
// nitro.config.ts
|
|
44
44
|
import { defineNitroConfig } from "nitropack/config";
|
|
45
45
|
|
|
46
46
|
export default defineNitroConfig({
|
|
47
|
-
modules: ["nitro-drizzle
|
|
47
|
+
modules: ["nitro-drizzle"],
|
|
48
48
|
drizzle: {
|
|
49
49
|
datasources: {
|
|
50
50
|
content: { connector: "sqlite" },
|
|
@@ -175,7 +175,7 @@ const result = await myDatasource.database.select().from(myDatasource.schema.myT
|
|
|
175
175
|
|
|
176
176
|
### `defineConfig(config: DrizzleConfig, filename: string)`
|
|
177
177
|
|
|
178
|
-
- **Purpose**: Helper function to define Drizzle configuration files (`drizzle.config.ts`) that are compatible with both `nitro-drizzle
|
|
178
|
+
- **Purpose**: Helper function to define Drizzle configuration files (`drizzle.config.ts`) that are compatible with both `nitro-drizzle` and `drizzle-kit`. It handles path resolution automatically.
|
|
179
179
|
- **Parameters**:
|
|
180
180
|
- `config`: Your DrizzleKit configuration object.
|
|
181
181
|
- `filename`: Pass `import.meta.url` as the `filename` for correct relative path resolution.
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Config } from "drizzle-kit";
|
|
2
|
-
|
|
3
2
|
//#region src/config/defineConfig.d.ts
|
|
4
3
|
/**
|
|
5
|
-
* Define Drizzle config compatible with both 'nitro-drizzle
|
|
4
|
+
* Define Drizzle config compatible with both 'nitro-drizzle' and 'drizzle-kit' packages.
|
|
6
5
|
*
|
|
7
6
|
* @param config
|
|
8
7
|
* @param dirname
|
|
@@ -3,7 +3,7 @@ import { cwd } from "node:process";
|
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
//#region src/config/defineConfig.ts
|
|
5
5
|
/**
|
|
6
|
-
* Define Drizzle config compatible with both 'nitro-drizzle
|
|
6
|
+
* Define Drizzle config compatible with both 'nitro-drizzle' and 'drizzle-kit' packages.
|
|
7
7
|
*
|
|
8
8
|
* @param config
|
|
9
9
|
* @param dirname
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineConfig.mjs","names":["relativePath","resolvePath"],"sources":["../../src/config/defineConfig.ts"],"sourcesContent":["import type { Config as DrizzleConfig } from \"drizzle-kit\";\nimport { resolve as resolvePath, relative as relativePath } from \"pathe\";\nimport { cwd } from \"node:process\";\nimport { fileURLToPath } from \"node:url\";\n\n/**\n * Define Drizzle config compatible with both 'nitro-drizzle
|
|
1
|
+
{"version":3,"file":"defineConfig.mjs","names":["relativePath","resolvePath"],"sources":["../../src/config/defineConfig.ts"],"sourcesContent":["import type { Config as DrizzleConfig } from \"drizzle-kit\";\nimport { resolve as resolvePath, relative as relativePath } from \"pathe\";\nimport { cwd } from \"node:process\";\nimport { fileURLToPath } from \"node:url\";\n\n/**\n * Define Drizzle config compatible with both 'nitro-drizzle' and 'drizzle-kit' packages.\n *\n * @param config\n * @param dirname\n * @returns\n */\nexport function defineConfig(config: DrizzleConfig, filename: string) {\n const { schema, out, ...other } = config;\n\n const workingDir = cwd();\n\n const dirname = fileURLToPath(new URL(\".\", filename));\n\n return {\n schema: transformToPluginCompatiblePath(dirname, workingDir, schema),\n out: transformToPluginCompatiblePath(dirname, workingDir, out),\n ...other,\n };\n}\n\nfunction transformToPluginCompatiblePath(\n dirname: string,\n cwd: string,\n path: string | undefined,\n): string | undefined;\nfunction transformToPluginCompatiblePath(\n dirname: string,\n cwd: string,\n path: string | string[] | undefined,\n): string | string[] | undefined;\nfunction transformToPluginCompatiblePath(\n dirname: string,\n cwd: string,\n path: string | string[] | undefined,\n) {\n if (!path) return;\n if (Array.isArray(path)) {\n return path.flatMap((path) => transformToRelative(dirname, cwd, path));\n }\n return relativePath(cwd, resolvePath(dirname, path));\n}\n\nfunction transformToRelative(dirname: string, cwd: string, path: string) {\n path = resolvePath(dirname, path);\n return relativePath(cwd, path);\n}\n"],"mappings":";;;;;;;;;;;AAYA,SAAgB,aAAa,QAAuB,UAAkB;CACpE,MAAM,EAAE,QAAQ,KAAK,GAAG,UAAU;CAElC,MAAM,aAAa,IAAI;CAEvB,MAAM,UAAU,cAAc,IAAI,IAAI,KAAK,QAAQ,CAAC;CAEpD,OAAO;EACL,QAAQ,gCAAgC,SAAS,YAAY,MAAM;EACnE,KAAK,gCAAgC,SAAS,YAAY,GAAG;EAC7D,GAAG;CACL;AACF;AAYA,SAAS,gCACP,SACA,KACA,MACA;CACA,IAAI,CAAC,MAAM;CACX,IAAI,MAAM,QAAQ,IAAI,GACpB,OAAO,KAAK,SAAS,SAAS,oBAAoB,SAAS,KAAK,IAAI,CAAC;CAEvE,OAAOA,SAAa,KAAKC,QAAY,SAAS,IAAI,CAAC;AACrD;AAEA,SAAS,oBAAoB,SAAiB,KAAa,MAAc;CACvE,OAAOA,QAAY,SAAS,IAAI;CAChC,OAAOD,SAAa,KAAK,IAAI;AAC/B"}
|
|
@@ -18,7 +18,7 @@ function genReference(reference) {
|
|
|
18
18
|
function moduleTypeDeclarations(datasources) {
|
|
19
19
|
if (!datasources.length) return {};
|
|
20
20
|
const names = datasources.map((d) => d.name);
|
|
21
|
-
const moduleId = "nitro-drizzle
|
|
21
|
+
const moduleId = "nitro-drizzle";
|
|
22
22
|
return { "nitro-drizzle/module.d.ts": [
|
|
23
23
|
genReference({ types: moduleId }),
|
|
24
24
|
genAugmentation(moduleId, { DatasourceOptions: [{}, { extends: `Record<${names.map((n) => genString(n)).join(" | ")}, { connector: string; }>` }] }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.mjs","names":[],"sources":["../../../src/context/internal/templates.ts"],"sourcesContent":["import {\n genTypeImport,\n genAugmentation,\n genInlineTypeImport,\n genString,\n genExport,\n} from \"knitwork\";\nimport type { DatasourceInfo } from \"..\";\nimport type { VirtualModules } from \"nitro-drizzle/shared\";\n\nexport function runtimeDeclarations(datasources: readonly DatasourceInfo[]) {\n if (!datasources.length) {\n return \"\";\n }\n\n return [\n genTypeImport(\"nitro-drizzle/runtime\", [\"ToDatasourceProvider\"]),\n genAugmentation(\"nitro-drizzle/runtime\", {\n DatasourceRegistry: Object.fromEntries(\n datasources\n .filter((datasource) => {\n return datasource.enabled;\n })\n .map(({ name, imports }): [string, string] => {\n const schemaType = genSchemaType(imports.schema);\n const driverType = genInlineTypeImport(imports.connector);\n return [name, `${\"ToDatasourceProvider\"}<${schemaType}, ${driverType}<${schemaType}>>`];\n }),\n ),\n }),\n ].join(\"\\n\");\n}\n\nfunction genSchemaType(imports: string[]) {\n return imports.map((id) => `typeof import('${id}')`).join(\" & \");\n}\n\nexport type TypeReference = { types: string };\n\nexport type PathReference = { path: string };\n\nexport function genReference(reference: TypeReference | PathReference) {\n return /* ts */ `/// <reference ${Object.entries(reference)\n .map(([prop, value]) => `${prop}=\"${value}\"`)\n .join(\"\")} />`;\n}\n\nexport function moduleTypeDeclarations(\n datasources: readonly DatasourceInfo[],\n): VirtualModules<`${string}.d.ts`> {\n if (!datasources.length) {\n return {};\n }\n\n const names = datasources.map((d) => d.name);\n\n const moduleId = \"nitro-drizzle
|
|
1
|
+
{"version":3,"file":"templates.mjs","names":[],"sources":["../../../src/context/internal/templates.ts"],"sourcesContent":["import {\n genTypeImport,\n genAugmentation,\n genInlineTypeImport,\n genString,\n genExport,\n} from \"knitwork\";\nimport type { DatasourceInfo } from \"..\";\nimport type { VirtualModules } from \"nitro-drizzle/shared\";\n\nexport function runtimeDeclarations(datasources: readonly DatasourceInfo[]) {\n if (!datasources.length) {\n return \"\";\n }\n\n return [\n genTypeImport(\"nitro-drizzle/runtime\", [\"ToDatasourceProvider\"]),\n genAugmentation(\"nitro-drizzle/runtime\", {\n DatasourceRegistry: Object.fromEntries(\n datasources\n .filter((datasource) => {\n return datasource.enabled;\n })\n .map(({ name, imports }): [string, string] => {\n const schemaType = genSchemaType(imports.schema);\n const driverType = genInlineTypeImport(imports.connector);\n return [name, `${\"ToDatasourceProvider\"}<${schemaType}, ${driverType}<${schemaType}>>`];\n }),\n ),\n }),\n ].join(\"\\n\");\n}\n\nfunction genSchemaType(imports: string[]) {\n return imports.map((id) => `typeof import('${id}')`).join(\" & \");\n}\n\nexport type TypeReference = { types: string };\n\nexport type PathReference = { path: string };\n\nexport function genReference(reference: TypeReference | PathReference) {\n return /* ts */ `/// <reference ${Object.entries(reference)\n .map(([prop, value]) => `${prop}=\"${value}\"`)\n .join(\"\")} />`;\n}\n\nexport function moduleTypeDeclarations(\n datasources: readonly DatasourceInfo[],\n): VirtualModules<`${string}.d.ts`> {\n if (!datasources.length) {\n return {};\n }\n\n const names = datasources.map((d) => d.name);\n\n const moduleId = \"nitro-drizzle\";\n\n const content = [\n genReference({ types: moduleId }),\n genAugmentation(moduleId, {\n DatasourceOptions: [\n {},\n {\n extends: `Record<${names.map((n) => genString(n)).join(\" | \")}, { connector: string; }>`,\n },\n ],\n }),\n /* ts */ `export {};`,\n ].join(\"\\n\");\n\n return {\n \"nitro-drizzle/module.d.ts\": content,\n };\n}\n\nexport function dialectDeclarations(datasources: readonly DatasourceInfo[]) {\n return datasources\n .filter((d) => d.enabled)\n .map(({ name, dialect }) => {\n return /*ts*/ `\n declare module \"#nitro-drizzle/dialects/${name}\" {\n ${genExport(`nitro-drizzle/dialects/${dialect}`, \"*\")}\n }\n `;\n })\n .join(\"\\n\");\n}\n"],"mappings":";;AAUA,SAAgB,oBAAoB,aAAwC;CAC1E,IAAI,CAAC,YAAY,QACf,OAAO;CAGT,OAAO,CACL,cAAc,yBAAyB,CAAC,sBAAsB,CAAC,GAC/D,gBAAgB,yBAAyB,EACvC,oBAAoB,OAAO,YACzB,YACG,QAAQ,eAAe;EACtB,OAAO,WAAW;CACpB,CAAC,CAAC,CACD,KAAK,EAAE,MAAM,cAAgC;EAC5C,MAAM,aAAa,cAAc,QAAQ,MAAM;EAE/C,OAAO,CAAC,MAAM,wBAA6B,WAAW,IADnC,oBAAoB,QAAQ,SACoB,EAAE,GAAG,WAAW,GAAG;CACxF,CAAC,CACL,EACF,CAAC,CACH,CAAC,CAAC,KAAK,IAAI;AACb;AAEA,SAAS,cAAc,SAAmB;CACxC,OAAO,QAAQ,KAAK,OAAO,kBAAkB,GAAG,GAAG,CAAC,CAAC,KAAK,KAAK;AACjE;AAMA,SAAgB,aAAa,WAA0C;CACrE,OAAgB,kBAAkB,OAAO,QAAQ,SAAS,CAAC,CACxD,KAAK,CAAC,MAAM,WAAW,GAAG,KAAK,IAAI,MAAM,EAAE,CAAC,CAC5C,KAAK,EAAE,EAAE;AACd;AAEA,SAAgB,uBACd,aACkC;CAClC,IAAI,CAAC,YAAY,QACf,OAAO,CAAC;CAGV,MAAM,QAAQ,YAAY,KAAK,MAAM,EAAE,IAAI;CAE3C,MAAM,WAAW;CAejB,OAAO,EACL,6BAdc;EACd,aAAa,EAAE,OAAO,SAAS,CAAC;EAChC,gBAAgB,UAAU,EACxB,mBAAmB,CACjB,CAAC,GACD,EACE,SAAS,UAAU,MAAM,KAAK,MAAM,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,EAAE,2BAChE,CACF,EACF,CAAC;EACQ;CACX,CAAC,CAAC,KAAK,IAG8B,EACrC;AACF;AAEA,SAAgB,oBAAoB,aAAwC;CAC1E,OAAO,YACJ,QAAQ,MAAM,EAAE,OAAO,CAAC,CACxB,KAAK,EAAE,MAAM,cAAc;EAC1B,OAAc;kDAC8B,KAAK;YAC3C,UAAU,0BAA0B,WAAW,GAAG,EAAE;;;CAG5D,CAAC,CAAC,CACD,KAAK,IAAI;AACd"}
|
package/dist/context.d.mts
CHANGED
|
@@ -2,7 +2,6 @@ import { Config } from "drizzle-kit";
|
|
|
2
2
|
import { ConsolaInstance } from "consola";
|
|
3
3
|
import { MaybePromise, VirtualModules } from "nitro-drizzle/shared";
|
|
4
4
|
import { ServerAssetDir } from "nitropack/types";
|
|
5
|
-
|
|
6
5
|
//#region src/context/index.d.ts
|
|
7
6
|
/**
|
|
8
7
|
* Context interface for managing Drizzle datasource configurations.
|
|
@@ -5,7 +5,6 @@ import { Column, SQL, Table } from "drizzle-orm";
|
|
|
5
5
|
import { SQLiteInsertBase } from "drizzle-orm/sqlite-core";
|
|
6
6
|
import { MySqlInsertBase } from "drizzle-orm/mysql-core";
|
|
7
7
|
import { PgInsertBase } from "drizzle-orm/pg-core";
|
|
8
|
-
|
|
9
8
|
//#region src/dialects/index.d.ts
|
|
10
9
|
interface OnConflictOptions<TSet extends Record<string, SQL | undefined>> {
|
|
11
10
|
set: TSet;
|
|
@@ -14,7 +13,7 @@ interface OnConflictOptions<TSet extends Record<string, SQL | undefined>> {
|
|
|
14
13
|
* Options for ON CONFLICT DO UPDATE clause.
|
|
15
14
|
* @template T - The insert type
|
|
16
15
|
*/
|
|
17
|
-
type OnConflictDoUpdateOptions<T extends AnyInsert> = OnConflictOptions<{ [K in keyof InferColumns<InferTable<T>>]?: SQL }>;
|
|
16
|
+
type OnConflictDoUpdateOptions<T extends AnyInsert> = OnConflictOptions<{ [K in keyof InferColumns<InferTable<T>>]?: SQL; }>;
|
|
18
17
|
/**
|
|
19
18
|
* Infers column types from a Drizzle table.
|
|
20
19
|
* @template TTable - The table type
|
|
@@ -26,14 +25,14 @@ type AnyInsert = MySqlInsertBase<any, any, any, any, any, any> | PgInsertBase<an
|
|
|
26
25
|
* @template T - The insert type
|
|
27
26
|
*/
|
|
28
27
|
type InferTable<T extends AnyInsert> = T extends MySqlInsertBase<any, any, any, any, any, any> ? InferMysqlTable<T> : T extends PgInsertBase<any, any, any, any, any, any> ? InferPgTable<T> : T extends SQLiteInsertBase<any, any, any, any, any, any> ? InferSqliteTable<T> : never;
|
|
29
|
-
type RemoveNeverProps<T extends Record<string, any>> = { [K in keyof T as T[K] extends never ? never : K]: T[K] };
|
|
28
|
+
type RemoveNeverProps<T extends Record<string, any>> = { [K in keyof T as T[K] extends never ? never : K]: T[K]; };
|
|
30
29
|
/**
|
|
31
30
|
* Infers primary key columns from a Drizzle table.
|
|
32
31
|
* @template T - The table type
|
|
33
32
|
*/
|
|
34
33
|
type InferPrimaryColumns<T extends Table> = RemoveNeverProps<{ [K in keyof InferColumns<T>]: InferColumns<T>[K] extends Column<infer TColumnConfig> ? Extract<TColumnConfig, {
|
|
35
34
|
isPrimaryKey: true;
|
|
36
|
-
}> extends never ? never : InferColumns<T>[K] : never }>;
|
|
35
|
+
}> extends never ? never : InferColumns<T>[K] : never; }>;
|
|
37
36
|
//#endregion
|
|
38
37
|
export { InferColumns, InferPrimaryColumns, InferTable, OnConflictDoUpdateOptions };
|
|
39
38
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Schema } from "./index.mjs";
|
|
2
2
|
import { DrizzleConfig } from "drizzle-orm";
|
|
3
3
|
import { AsyncBatchRemoteCallback, AsyncRemoteCallback, RemoteCallback, SqliteRemoteDatabase } from "drizzle-orm/sqlite-proxy";
|
|
4
|
-
|
|
5
4
|
//#region src/drivers/d1-http.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* Cloudflare D1 HTTP datasource driver for remote connections.
|
|
@@ -18,8 +17,11 @@ declare const driver: <TSchema extends Schema>(options: D1HttpOptions, schema: T
|
|
|
18
17
|
};
|
|
19
18
|
/** Configuration options for the Cloudflare D1 HTTP driver. */
|
|
20
19
|
type D1HttpOptions = {
|
|
21
|
-
/** Cloudflare account ID. */
|
|
22
|
-
|
|
20
|
+
/** Cloudflare account ID. */
|
|
21
|
+
accountId: string;
|
|
22
|
+
/** D1 database ID. */
|
|
23
|
+
databaseId: string;
|
|
24
|
+
/** API token for authentication. */
|
|
23
25
|
token: string;
|
|
24
26
|
};
|
|
25
27
|
/** Internal type for the HTTP driver callback functions. */
|
package/dist/drivers/d1.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { DrizzleD1Database } from "drizzle-orm/d1";
|
|
2
2
|
import { D1Database } from "@cloudflare/workers-types";
|
|
3
|
-
|
|
4
3
|
//#region src/drivers/d1.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Cloudflare D1 datasource driver.
|
|
@@ -19,7 +18,8 @@ declare const _default: <TSchema extends Record<string, any>>(options: D1Options
|
|
|
19
18
|
}>;
|
|
20
19
|
/** Configuration options for the Cloudflare D1 driver. */
|
|
21
20
|
type D1Options = {
|
|
22
|
-
/** The binding name for the D1 database in Cloudflare Workers. */
|
|
21
|
+
/** The binding name for the D1 database in Cloudflare Workers. */
|
|
22
|
+
binding: string;
|
|
23
23
|
};
|
|
24
24
|
//#endregion
|
|
25
25
|
export { D1Options, _default as default };
|
package/dist/drivers/db0.d.mts
CHANGED
package/dist/drivers/mysql.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Schema } from "./index.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/drivers/mysql.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* MySQL datasource driver using mysql2.
|
|
@@ -20,7 +19,8 @@ declare const _default: <TSchema extends Schema>(config: Options, schema: TSchem
|
|
|
20
19
|
* Configuration options for the MySQL driver.
|
|
21
20
|
*/
|
|
22
21
|
type Options = {
|
|
23
|
-
/** Database connection URL. */
|
|
22
|
+
/** Database connection URL. */
|
|
23
|
+
url: string;
|
|
24
24
|
};
|
|
25
25
|
//#endregion
|
|
26
26
|
export { Options, _default as default };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Schema } from "./index.mjs";
|
|
2
2
|
import { PGlite, PGliteOptions } from "@electric-sql/pglite";
|
|
3
|
-
|
|
4
3
|
//#region src/drivers/pglite.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* PGlite datasource driver for PostgreSQL in the browser.
|
|
@@ -21,7 +20,9 @@ declare const _default: <TSchema extends Schema>(options: PGliteOptions, schema:
|
|
|
21
20
|
* Configuration options for the PGlite driver.
|
|
22
21
|
*/
|
|
23
22
|
type Config = {
|
|
24
|
-
/** Directory path for storing database data. */
|
|
23
|
+
/** Directory path for storing database data. */
|
|
24
|
+
dataDir?: string;
|
|
25
|
+
/** Additional PGlite options. */
|
|
25
26
|
options?: PGliteOptions;
|
|
26
27
|
};
|
|
27
28
|
//#endregion
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import createPostgres, { Options as Options$1 } from "postgres";
|
|
2
|
-
|
|
3
2
|
//#region src/drivers/postgresql.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* PostgreSQL datasource driver using postgres.js.
|
|
@@ -20,7 +19,8 @@ declare const _default: <TSchema extends Record<string, any>>(options: Options,
|
|
|
20
19
|
* Configuration options for the PostgreSQL driver.
|
|
21
20
|
*/
|
|
22
21
|
type Options = Options$1<Record<string, createPostgres.PostgresType>> & {
|
|
23
|
-
/** Connection URL string (optional if connection config is provided). */
|
|
22
|
+
/** Connection URL string (optional if connection config is provided). */
|
|
23
|
+
url?: string;
|
|
24
24
|
};
|
|
25
25
|
//#endregion
|
|
26
26
|
export { Options, _default as default };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Schema } from "./index.mjs";
|
|
2
2
|
import sqlite3, { Options as Options$1 } from "better-sqlite3";
|
|
3
|
-
|
|
4
3
|
//#region src/drivers/sqlite.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* SQLite datasource driver using better-sqlite3.
|
|
@@ -21,7 +20,8 @@ declare const _default: <TSchema extends Schema>(config: Options, schema: TSchem
|
|
|
21
20
|
* Configuration options for the SQLite driver.
|
|
22
21
|
*/
|
|
23
22
|
type Options = {
|
|
24
|
-
/** Database file path or URL. */
|
|
23
|
+
/** Database file path or URL. */
|
|
24
|
+
url: string;
|
|
25
25
|
} & Options$1;
|
|
26
26
|
//#endregion
|
|
27
27
|
export { Options, _default as default };
|
package/dist/index.d.mts
ADDED
package/dist/index.mjs
ADDED
package/dist/meta.d.mts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { MigrationMeta } from "drizzle-orm/migrator";
|
|
2
|
-
|
|
3
2
|
//#region src/migrations/internal/migrate.d.ts
|
|
4
3
|
/** Configuration options for database migrations. */
|
|
5
4
|
type MigrationConfig = Partial<{
|
|
6
|
-
/** Schema name for migrations. */
|
|
5
|
+
/** Schema name for migrations. */
|
|
6
|
+
schema: string;
|
|
7
|
+
/** Table name for storing migration metadata. */
|
|
7
8
|
table: string;
|
|
8
9
|
}>;
|
|
9
10
|
/** Migration information including SQL statements and metadata. */
|
package/dist/module.d.mts
CHANGED
|
@@ -2,7 +2,6 @@ import { updateServerAssets } from "./module/utils/assets.mjs";
|
|
|
2
2
|
import { addInlineExternals } from "./module/utils/externals.mjs";
|
|
3
3
|
import { ConfigPattern, MigrationOptions } from "nitro-drizzle/context";
|
|
4
4
|
import { NitroModule } from "nitropack/types";
|
|
5
|
-
|
|
6
5
|
//#region src/module/index.d.ts
|
|
7
6
|
/**
|
|
8
7
|
* Datasource-specific configuration options.
|
|
@@ -18,18 +17,25 @@ interface ModuleOptions {
|
|
|
18
17
|
/**
|
|
19
18
|
* Directory to search datasources
|
|
20
19
|
*/
|
|
21
|
-
baseDir
|
|
20
|
+
baseDir?: string;
|
|
22
21
|
/**
|
|
23
22
|
* Patterns to search Drizzle configs
|
|
24
23
|
*/
|
|
25
|
-
configPattern
|
|
24
|
+
configPattern?: ConfigPattern;
|
|
26
25
|
datasources?: DatasourceOptions;
|
|
27
26
|
/**
|
|
28
27
|
* Enable migrations storage
|
|
29
28
|
*/
|
|
30
|
-
migrations
|
|
29
|
+
migrations?: false | Partial<MigrationOptions>;
|
|
31
30
|
}
|
|
32
|
-
declare function createDefaultOptions():
|
|
31
|
+
declare function createDefaultOptions(): {
|
|
32
|
+
readonly baseDir: "~/drizzle";
|
|
33
|
+
readonly configPattern: readonly ["drizzle.config.{js,ts}", "drizzle-*.config.{js,ts}"];
|
|
34
|
+
readonly migrations: {
|
|
35
|
+
readonly storageBase: "drizzle:migrations";
|
|
36
|
+
readonly migrateOnInit: false;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
33
39
|
declare const module: NitroModule;
|
|
34
40
|
//#endregion
|
|
35
41
|
export { DatasourceOptions, ModuleOptions, addInlineExternals, createDefaultOptions, module as default, updateServerAssets };
|
package/dist/module.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.mjs","names":[],"sources":["../src/module/index.ts"],"sourcesContent":["import type { NitroModule } from \"nitropack/types\";\nimport { defu } from \"defu\";\nimport { resolve } from \"pathe\";\nimport { resolveAlias } from \"pathe/utils\";\n\nimport {\n createContext,\n type ConfigPattern,\n type ContextOptions,\n type MigrationOptions,\n} from \"nitro-drizzle/context\";\nimport type { VirtualModules, MaybePromise } from \"nitro-drizzle/shared\";\nimport { pkgName } from \"nitro-drizzle/meta\";\n\nimport { updateServerAssets } from \"./utils/assets\";\nimport { addInlineExternals } from \"./utils/externals\";\n\nimport { addAugmentations, addDeclarations } from \"./internal/types\";\nimport { createResolver } from \"./internal/resolver\";\nimport { reloadPlugin } from \"./internal/reload\";\nimport { addPlugin } from \"./internal/rollup\";\n\n/**\n * Datasource-specific configuration options.\n * This interface is augmented by the module with connector-specific options.\n */\nexport interface DatasourceOptions {\n // augmented by module\n}\n\ndeclare module \"nitropack/types\" {\n interface NitroOptions {\n drizzle: ModuleOptions;\n }\n}\n\nexport interface ModuleOptions {\n /**\n * Directory to search datasources\n */\n baseDir
|
|
1
|
+
{"version":3,"file":"module.mjs","names":[],"sources":["../src/module/index.ts"],"sourcesContent":["import type { NitroModule } from \"nitropack/types\";\nimport { defu } from \"defu\";\nimport { resolve } from \"pathe\";\nimport { resolveAlias } from \"pathe/utils\";\n\nimport {\n createContext,\n type ConfigPattern,\n type ContextOptions,\n type MigrationOptions,\n} from \"nitro-drizzle/context\";\nimport type { VirtualModules, MaybePromise } from \"nitro-drizzle/shared\";\nimport { pkgName } from \"nitro-drizzle/meta\";\n\nimport { updateServerAssets } from \"./utils/assets\";\nimport { addInlineExternals } from \"./utils/externals\";\n\nimport { addAugmentations, addDeclarations } from \"./internal/types\";\nimport { createResolver } from \"./internal/resolver\";\nimport { reloadPlugin } from \"./internal/reload\";\nimport { addPlugin } from \"./internal/rollup\";\n\n/**\n * Datasource-specific configuration options.\n * This interface is augmented by the module with connector-specific options.\n */\nexport interface DatasourceOptions {\n // augmented by module\n}\n\ndeclare module \"nitropack/types\" {\n interface NitroOptions {\n drizzle: ModuleOptions;\n }\n}\n\nexport interface ModuleOptions {\n /**\n * Directory to search datasources\n */\n baseDir?: string;\n /**\n * Patterns to search Drizzle configs\n */\n configPattern?: ConfigPattern;\n\n datasources?: DatasourceOptions;\n\n /**\n * Enable migrations storage\n */\n migrations?: false | Partial<MigrationOptions>;\n}\n\nexport function createDefaultOptions() {\n return {\n baseDir: \"~/drizzle\",\n configPattern: [\"drizzle.config.{js,ts}\", \"drizzle-*.config.{js,ts}\"],\n migrations: {\n storageBase: \"drizzle:migrations\",\n migrateOnInit: false,\n },\n } as const satisfies ModuleOptions;\n}\n\nconst module: NitroModule = {\n name: pkgName,\n async setup(nitro) {\n const moduleOptions = defu(nitro.options.drizzle, createDefaultOptions());\n\n const resolver = createResolver(nitro.options.rootDir, {\n alias: nitro.options.alias,\n });\n\n const baseDir = resolve(\n nitro.options.srcDir,\n resolveAlias(moduleOptions.baseDir, nitro.options.alias),\n );\n\n const contextOptions: ContextOptions = {\n cwd: process.cwd(),\n resolver: resolver,\n baseDir,\n logger: nitro.logger,\n configPattern: moduleOptions.configPattern,\n datasource: { ...moduleOptions.datasources },\n migrations: moduleOptions.migrations || void 0,\n\n tasks: nitro.options.experimental.tasks\n ? (tasks) => {\n nitro.options.tasks ||= {};\n Object.assign(nitro.options.tasks, tasks);\n }\n : void 0,\n\n plugins(plugins) {\n nitro.options.plugins.push(...plugins);\n },\n\n virtualModules(modules: VirtualModules): MaybePromise<void> {\n Object.assign(nitro.options.virtual, modules);\n },\n\n declarations(declarations): MaybePromise<void> {\n nitro.hooks.hook(\"types:extend\", async (types) => {\n await addAugmentations(nitro.options, types, {\n ...declarations.runtime,\n ...declarations.module,\n });\n\n await addDeclarations(nitro.options, types, declarations.virtual);\n });\n },\n\n assets(assets) {\n updateServerAssets(nitro.options, assets);\n },\n\n inlineExternals(modules: readonly string[]) {\n addInlineExternals(nitro.options, modules);\n },\n };\n\n const context = createContext(contextOptions);\n\n // auto-imports\n if (nitro.options.imports) {\n nitro.options.imports.imports ||= [];\n\n // TODO\n // nitro.options.imports.imports.push({\n // name: 'useMigrations',\n // as: 'useDrizzleMigrations',\n // from: 'nitro-drizzle/runtime',\n // })\n }\n\n nitro.hooks.hook(\"rollup:before\", async (nitro, config) => {\n await addPlugin(config, reloadPlugin(nitro, { baseDir }));\n });\n\n await context.init();\n },\n};\n\nexport default module;\n\nexport { addInlineExternals, updateServerAssets };\n"],"mappings":";;;;;;;;;;;;AAsDA,SAAgB,uBAAuB;CACrC,OAAO;EACL,SAAS;EACT,eAAe,CAAC,0BAA0B,0BAA0B;EACpE,YAAY;GACV,aAAa;GACb,eAAe;EACjB;CACF;AACF;AAEA,MAAM,SAAsB;CAC1B,MAAM;CACN,MAAM,MAAM,OAAO;EACjB,MAAM,gBAAgB,KAAK,MAAM,QAAQ,SAAS,qBAAqB,CAAC;EAExE,MAAM,WAAW,eAAe,MAAM,QAAQ,SAAS,EACrD,OAAO,MAAM,QAAQ,MACvB,CAAC;EAED,MAAM,UAAU,QACd,MAAM,QAAQ,QACd,aAAa,cAAc,SAAS,MAAM,QAAQ,KAAK,CACzD;EA8CA,MAAM,UAAU,cAAc;GA3C5B,KAAK,QAAQ,IAAI;GACP;GACV;GACA,QAAQ,MAAM;GACd,eAAe,cAAc;GAC7B,YAAY,EAAE,GAAG,cAAc,YAAY;GAC3C,YAAY,cAAc,cAAc,KAAK;GAE7C,OAAO,MAAM,QAAQ,aAAa,SAC7B,UAAU;IACT,MAAM,QAAQ,UAAU,CAAC;IACzB,OAAO,OAAO,MAAM,QAAQ,OAAO,KAAK;GAC1C,IACA,KAAK;GAET,QAAQ,SAAS;IACf,MAAM,QAAQ,QAAQ,KAAK,GAAG,OAAO;GACvC;GAEA,eAAe,SAA6C;IAC1D,OAAO,OAAO,MAAM,QAAQ,SAAS,OAAO;GAC9C;GAEA,aAAa,cAAkC;IAC7C,MAAM,MAAM,KAAK,gBAAgB,OAAO,UAAU;KAChD,MAAM,iBAAiB,MAAM,SAAS,OAAO;MAC3C,GAAG,aAAa;MAChB,GAAG,aAAa;KAClB,CAAC;KAED,MAAM,gBAAgB,MAAM,SAAS,OAAO,aAAa,OAAO;IAClE,CAAC;GACH;GAEA,OAAO,QAAQ;IACb,mBAAmB,MAAM,SAAS,MAAM;GAC1C;GAEA,gBAAgB,SAA4B;IAC1C,mBAAmB,MAAM,SAAS,OAAO;GAC3C;EAGyC,CAAC;EAG5C,IAAI,MAAM,QAAQ,SAChB,MAAM,QAAQ,QAAQ,YAAY,CAAC;EAUrC,MAAM,MAAM,KAAK,iBAAiB,OAAO,OAAO,WAAW;GACzD,MAAM,UAAU,QAAQ,aAAa,OAAO,EAAE,QAAQ,CAAC,CAAC;EAC1D,CAAC;EAED,MAAM,QAAQ,KAAK;CACrB;AACF"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { DatasourceRegistry } from "nitro-drizzle/runtime";
|
|
2
2
|
import { MigrationResult } from "nitro-drizzle/migrations";
|
|
3
3
|
import { NitroAppPlugin } from "nitropack/types";
|
|
4
|
-
|
|
5
4
|
//#region src/plugins/migrate.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* Nitro plugin that runs migrations on initialization.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Datasources } from "../runtime.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/runtime/useDatasource.d.ts
|
|
4
3
|
/** Options for datasource creation and lifecycle management. */
|
|
5
4
|
type UseDatasourceOptions = Partial<{
|
|
6
|
-
/** Whether to automatically close the datasource when Nitro app closes. */
|
|
5
|
+
/** Whether to automatically close the datasource when Nitro app closes. */
|
|
6
|
+
autoClose: boolean;
|
|
7
7
|
}>;
|
|
8
8
|
/**
|
|
9
9
|
* Gets or creates a datasource instance by name.
|
package/dist/runtime.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { UseDatasourceOptions, useDatasource } from "./runtime/useDatasource.mjs";
|
|
2
2
|
import { Datasource, DatasourceDriver, Schema } from "nitro-drizzle/drivers";
|
|
3
|
-
|
|
4
3
|
//#region src/runtime/index.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Provider interface for creating Drizzle datasource instances.
|
|
@@ -38,12 +37,12 @@ interface DatasourceRegistry {}
|
|
|
38
37
|
* Mapped type of all datasources from the registry.
|
|
39
38
|
* Provides access to datasource instances by name.
|
|
40
39
|
*/
|
|
41
|
-
type Datasources = { readonly [K in keyof DatasourceRegistry]: ToDatasource<DatasourceRegistry[K]
|
|
40
|
+
type Datasources = { readonly [K in keyof DatasourceRegistry]: ToDatasource<DatasourceRegistry[K]>; };
|
|
42
41
|
/**
|
|
43
42
|
* Recursively extracts primitive properties from a type.
|
|
44
43
|
* @template T - The type to extract primitive properties from
|
|
45
44
|
*/
|
|
46
|
-
type PrimitiveProps<T> = { [K in keyof T]: T[K] extends Record<string, any> ? PrimitiveProps<T[K]> : T[K] extends ((...args: any[]) => infer R) ? Awaited<R> extends Primitive ? Awaited<R> : never : T[K] extends Primitive ? T[K] : never };
|
|
45
|
+
type PrimitiveProps<T> = { [K in keyof T]: T[K] extends Record<string, any> ? PrimitiveProps<T[K]> : T[K] extends ((...args: any[]) => infer R) ? Awaited<R> extends Primitive ? Awaited<R> : never : T[K] extends Primitive ? T[K] : never; };
|
|
47
46
|
/**
|
|
48
47
|
* Primitive types supported by the runtime configuration.
|
|
49
48
|
*/
|
|
@@ -56,18 +55,18 @@ type DatasourceProviderConfig<T extends DatasourceProvider<any, any>> = T extend
|
|
|
56
55
|
/**
|
|
57
56
|
* Configuration type mapping datasource names to their configurations.
|
|
58
57
|
*/
|
|
59
|
-
type DatasourceConfig = { [K in keyof DatasourceRegistry]: DatasourceProviderConfig<DatasourceRegistry[K]
|
|
58
|
+
type DatasourceConfig = { [K in keyof DatasourceRegistry]: DatasourceProviderConfig<DatasourceRegistry[K]>; };
|
|
60
59
|
/**
|
|
61
60
|
* Runtime configuration type with primitive values for each datasource.
|
|
62
61
|
* Used for Nitro runtime config.
|
|
63
62
|
*/
|
|
64
|
-
type RuntimeConfig = { [K in keyof DatasourceConfig]: PrimitiveProps<DatasourceConfig[K]
|
|
63
|
+
type RuntimeConfig = { [K in keyof DatasourceConfig]: PrimitiveProps<DatasourceConfig[K]>; };
|
|
65
64
|
declare module "nitropack/types" {
|
|
66
65
|
interface NitroRuntimeConfig {
|
|
67
66
|
drizzle?: RuntimeConfig;
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
|
-
type ConfigHookArgs = { [K in keyof DatasourceConfig]: [name: K, config: DatasourceConfig[K]] }[keyof DatasourceConfig];
|
|
69
|
+
type ConfigHookArgs = { [K in keyof DatasourceConfig]: [name: K, config: DatasourceConfig[K]]; }[keyof DatasourceConfig];
|
|
71
70
|
interface ConfigHooks {
|
|
72
71
|
"drizzle:config": (...args: ConfigHookArgs) => void | Promise<void>;
|
|
73
72
|
}
|
package/dist/shared.d.mts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-drizzle",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.12",
|
|
4
4
|
"description": "Nitro module to integrate Drizzle ORM with ease.",
|
|
5
5
|
"homepage": "https://github.com/Myshkouski/nitro-drizzle#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
],
|
|
18
18
|
"type": "module",
|
|
19
19
|
"exports": {
|
|
20
|
+
".": "./dist/index.mjs",
|
|
20
21
|
"./shared": "./dist/shared.mjs",
|
|
21
22
|
"./migrations": "./dist/migrations.mjs",
|
|
22
23
|
"./migrations/task": "./dist/migrations/task.mjs",
|
|
@@ -40,10 +41,9 @@
|
|
|
40
41
|
"consola": "^3.4.2",
|
|
41
42
|
"db0": "^0.3.4",
|
|
42
43
|
"defu": "^6.1.7",
|
|
43
|
-
"drizzle-kit": "^0.31.10",
|
|
44
44
|
"jiti": "^2.7.0",
|
|
45
45
|
"knitwork": "^1.3.0",
|
|
46
|
-
"nitropack": "^2",
|
|
46
|
+
"nitropack": "^2.13.4",
|
|
47
47
|
"ohash": "^2.0.11",
|
|
48
48
|
"pathe": "^2.0.3",
|
|
49
49
|
"rollup": "^4.62.2",
|
|
@@ -53,32 +53,32 @@
|
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@arethetypeswrong/core": "^0.18.4",
|
|
56
|
-
"@cloudflare/workers-types": "^4.20260702.1",
|
|
57
56
|
"@testcontainers/mysql": "^12.0.4",
|
|
58
57
|
"@testcontainers/postgresql": "^12.0.4",
|
|
59
|
-
"@types/node": "^25.9.
|
|
58
|
+
"@types/node": "^25.9.5",
|
|
60
59
|
"@vitest/coverage-v8": "^4.1.10",
|
|
61
60
|
"@vitest/ui": "^4.1.10",
|
|
62
61
|
"changelogen": "^0.6.2",
|
|
63
|
-
"lefthook": "^2.1.
|
|
62
|
+
"lefthook": "^2.1.10",
|
|
64
63
|
"listhen": "^1.10.0",
|
|
65
|
-
"oxfmt": "^0.
|
|
66
|
-
"oxlint": "^1.
|
|
64
|
+
"oxfmt": "^0.58.0",
|
|
65
|
+
"oxlint": "^1.73.0",
|
|
67
66
|
"oxlint-tsgolint": "^0.24.0",
|
|
68
67
|
"publint": "^0.3.21",
|
|
69
68
|
"testcontainers": "^12.0.4",
|
|
70
|
-
"tsdown": "^0.22.
|
|
69
|
+
"tsdown": "^0.22.4",
|
|
71
70
|
"typescript": "^6.0.3",
|
|
72
71
|
"unplugin-unused": "^0.5.7",
|
|
73
72
|
"vitest": "^4.1.10"
|
|
74
73
|
},
|
|
75
74
|
"peerDependencies": {
|
|
76
|
-
"@cloudflare/workers-types": "^4.
|
|
75
|
+
"@cloudflare/workers-types": "^4.20260702.1",
|
|
77
76
|
"@electric-sql/pglite": "^0.5.4",
|
|
78
77
|
"better-sqlite3": "^12.11.1",
|
|
78
|
+
"drizzle-kit": "^0.31.10",
|
|
79
79
|
"drizzle-orm": "^0.45.2",
|
|
80
|
-
"h3": "^1",
|
|
81
|
-
"mysql2": "^3.22.
|
|
80
|
+
"h3": "^1.15.11",
|
|
81
|
+
"mysql2": "^3.22.6",
|
|
82
82
|
"postgres": "^3.4.9"
|
|
83
83
|
},
|
|
84
84
|
"peerDependenciesMeta": {
|