nitro-drizzle 0.2.6 → 0.2.8
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 +54 -66
- package/dist/context.d.mts +0 -8
- package/dist/context.mjs +3 -2
- package/dist/context.mjs.map +1 -1
- package/dist/module/internal/plugins.mjs +3 -2
- package/dist/module/internal/plugins.mjs.map +1 -1
- package/dist/module/internal/resolver.mjs +0 -3
- package/dist/module/internal/resolver.mjs.map +1 -1
- package/dist/module.mjs +1 -1
- package/dist/module.mjs.map +1 -1
- package/package.json +22 -16
package/README.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/nitro-drizzle)
|
|
4
4
|
[](https://github.com/Myshkouski/nitro-drizzle/actions/workflows/ci.yml)
|
|
5
|
+
[](https://codecov.io/github/myshkouski/nitro-drizzle)
|
|
5
6
|
[](https://github.com/Myshkouski/nitro-drizzle/blob/main/LICENSE)
|
|
6
7
|
|
|
7
8
|
`nitro-drizzle` is a powerful module designed to seamlessly integrate the [Drizzle ORM](https://orm.drizzle.team/) with your [Nitro](https://nitro.unjs.io/) applications. It simplifies database management, schema definition, and migrations, allowing you to build robust and scalable backend services with ease.
|
|
@@ -46,7 +47,7 @@ export default defineNitroConfig({
|
|
|
46
47
|
modules: ["nitro-drizzle/module"],
|
|
47
48
|
drizzle: {
|
|
48
49
|
datasources: {
|
|
49
|
-
|
|
50
|
+
content: { connector: "sqlite" },
|
|
50
51
|
},
|
|
51
52
|
},
|
|
52
53
|
});
|
|
@@ -56,9 +57,9 @@ See [ModuleOptions](src/module/index.ts) for all available options.
|
|
|
56
57
|
|
|
57
58
|
### 2. Define Drizzle Config and Schema
|
|
58
59
|
|
|
59
|
-
Create your Drizzle configuration files and schemas in the `baseDir` specified in `nitro.config.ts` (e.g., `server/drizzle/
|
|
60
|
+
Create your Drizzle configuration files and schemas in the `baseDir` specified in `nitro.config.ts` (e.g., `server/drizzle/content/drizzle-sqlite.config.ts` and `server/drizzle/content/sqlite/schema.ts`).
|
|
60
61
|
|
|
61
|
-
#### Example: `server/drizzle/
|
|
62
|
+
#### Example: `server/drizzle/content/drizzle-sqlite.config.ts`
|
|
62
63
|
|
|
63
64
|
```ts
|
|
64
65
|
import { defineConfig } from "nitro-drizzle/config";
|
|
@@ -68,94 +69,59 @@ export default defineConfig(
|
|
|
68
69
|
strict: true,
|
|
69
70
|
dialect: "sqlite",
|
|
70
71
|
out: "./sqlite/migrations", // Migration output directory
|
|
71
|
-
schema:
|
|
72
|
+
schema: "./sqlite/schema.ts", // Path to your schema files
|
|
72
73
|
migrations: {
|
|
73
74
|
table: "drizzle_migrations", // Table to track migrations
|
|
74
75
|
},
|
|
75
76
|
},
|
|
76
|
-
import.meta.url, // Pass import.meta.url for
|
|
77
|
+
import.meta.url, // Pass import.meta.url for compatibility with "drizzle-kit"
|
|
77
78
|
);
|
|
78
79
|
```
|
|
79
80
|
|
|
80
|
-
#### Example: `server/drizzle/
|
|
81
|
+
#### Example: `server/drizzle/content/sqlite/schema.ts`
|
|
81
82
|
|
|
82
83
|
```ts
|
|
83
84
|
import { sqliteTable, integer, text } from "drizzle-orm/sqlite-core";
|
|
84
85
|
|
|
85
|
-
export const
|
|
86
|
-
id: integer("id").primaryKey(),
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
export const posts = sqliteTable("posts", {
|
|
87
|
+
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
88
|
+
title: text("title").notNull(),
|
|
89
|
+
description: text("description").notNull(),
|
|
90
|
+
image: text("image").notNull(),
|
|
91
|
+
date: integer("date", { mode: "timestamp" }).notNull().defaultNow(),
|
|
92
|
+
authors: text("authors", { mode: "json" }).$type<number[]>(),
|
|
89
93
|
});
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
#### Example: `server/drizzle/bar/drizzle-pglite.config.ts`
|
|
93
|
-
|
|
94
|
-
```ts
|
|
95
|
-
import { defineConfig } from "nitro-drizzle/config";
|
|
96
94
|
|
|
97
|
-
export
|
|
98
|
-
{
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
table: "drizzle_migrations",
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
import.meta.url,
|
|
108
|
-
);
|
|
95
|
+
export const comments = sqliteTable("comments", {
|
|
96
|
+
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
97
|
+
postId: integer("post_id").notNull(),
|
|
98
|
+
authorId: integer("author_id").notNull(),
|
|
99
|
+
content: text("content").notNull(),
|
|
100
|
+
createdAt: integer("created_at", { mode: "timestamp" }).notNull(),
|
|
101
|
+
});
|
|
109
102
|
```
|
|
110
103
|
|
|
111
|
-
|
|
104
|
+
### 3. Generate migrations
|
|
112
105
|
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
export const products = pgTable("products", {
|
|
117
|
-
id: serial("id").primaryKey(),
|
|
118
|
-
name: text("name").notNull(),
|
|
119
|
-
description: text("description"),
|
|
120
|
-
});
|
|
106
|
+
```shell
|
|
107
|
+
drizzle-kit generate --config server/drizzle/content/drizzle-sqlite.config.ts
|
|
121
108
|
```
|
|
122
109
|
|
|
123
|
-
###
|
|
110
|
+
### 4. Use Datasources in API Routes
|
|
124
111
|
|
|
125
112
|
You can access your configured datasources in your Nitro API routes using `useDatasource`.
|
|
126
113
|
|
|
127
114
|
```ts
|
|
128
115
|
// server/routes/index.ts
|
|
129
|
-
import {
|
|
116
|
+
import { defineEventHandler } from "h3";
|
|
130
117
|
import { useDatasource } from "nitro-drizzle/runtime";
|
|
131
118
|
|
|
132
|
-
export default
|
|
133
|
-
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
await
|
|
137
|
-
|
|
138
|
-
// Example usage with 'foo' (SQLite)
|
|
139
|
-
const newUsers = await fooDatasource.database
|
|
140
|
-
.insert(fooDatasource.schema.users)
|
|
141
|
-
.values([
|
|
142
|
-
{ name: "Alice", email: "alice@example.com" },
|
|
143
|
-
{ name: "Bob", email: "bob@example.com" },
|
|
144
|
-
])
|
|
145
|
-
.returning()
|
|
146
|
-
.all();
|
|
147
|
-
|
|
148
|
-
// Example usage with 'bar' (PostgreSQL with pglite)
|
|
149
|
-
const newProducts = await barDatasource.database
|
|
150
|
-
.insert(barDatasource.schema.products)
|
|
151
|
-
.values([
|
|
152
|
-
{ name: "Laptop", description: "Powerful laptop" },
|
|
153
|
-
{ name: "Mouse", description: "Wireless mouse" },
|
|
154
|
-
])
|
|
155
|
-
.returning()
|
|
156
|
-
.all();
|
|
157
|
-
|
|
158
|
-
return { newUsers, newProducts };
|
|
119
|
+
export default defineEventHandler(async () => {
|
|
120
|
+
await event.context.drizzle.waitReady(); // Wait for "drizzle:init" hook finished
|
|
121
|
+
const { database, waitReady } = await useDatasource("content"); // Access the 'content' datasource
|
|
122
|
+
await waitReady(); // Wait datasource is ready
|
|
123
|
+
const posts = await database.select().from(schema.posts).limit(10);
|
|
124
|
+
return { posts };
|
|
159
125
|
});
|
|
160
126
|
```
|
|
161
127
|
|
|
@@ -167,6 +133,28 @@ If you enabled Nitro tasks in `nitro.config.ts`, you can run migrations via the
|
|
|
167
133
|
npx nitro task drizzle:migrate
|
|
168
134
|
```
|
|
169
135
|
|
|
136
|
+
## 📁 Sample Project Structure
|
|
137
|
+
|
|
138
|
+
A minimal layout with SQLite database for `content` and PostgreSQL database for `users`. Each datasource has its own drizzle config, schema, and migrations folder.
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
blog-api/
|
|
142
|
+
├── nitro.config.ts
|
|
143
|
+
├── package.json
|
|
144
|
+
└── server/
|
|
145
|
+
└── drizzle/
|
|
146
|
+
├── content/
|
|
147
|
+
│ ├── drizzle-sqlite.config.ts
|
|
148
|
+
│ └── sqlite/
|
|
149
|
+
│ ├── migrations/*.sql
|
|
150
|
+
│ └── schema/*.ts
|
|
151
|
+
└── users/
|
|
152
|
+
├── drizzle-postgresql.config.ts
|
|
153
|
+
└── postgresql/
|
|
154
|
+
├── migrations/*.sql
|
|
155
|
+
└── schema.ts
|
|
156
|
+
```
|
|
157
|
+
|
|
170
158
|
## 📖 API Documentation
|
|
171
159
|
|
|
172
160
|
### `useDatasource(name: string, options?: UseDatasourceOptions)`
|
package/dist/context.d.mts
CHANGED
|
@@ -39,14 +39,6 @@ interface Resolver {
|
|
|
39
39
|
* Attempts to resolve a module ID, returns undefined if not found.
|
|
40
40
|
*/
|
|
41
41
|
tryResolve(id: string): string | undefined;
|
|
42
|
-
/**
|
|
43
|
-
* Imports a module dynamically.
|
|
44
|
-
* @param id - Module identifier to import
|
|
45
|
-
* @param options - Import options, set default: true to import default export
|
|
46
|
-
*/
|
|
47
|
-
import<T>(id: string, options?: {
|
|
48
|
-
default?: boolean;
|
|
49
|
-
}): Promise<T>;
|
|
50
42
|
}
|
|
51
43
|
interface ContextOptions {
|
|
52
44
|
logger?: ConsolaInstance;
|
package/dist/context.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { dialectDeclarations, genReference, moduleTypeDeclarations, runtimeDecla
|
|
|
5
5
|
import { transformDrizzleConfig } from "./context/internal/config.mjs";
|
|
6
6
|
import { dialectVirtualModules, runtimeVirtualModule } from "./context/internal/virtual.mjs";
|
|
7
7
|
import { colorize } from "consola/utils";
|
|
8
|
+
import { loadConfig } from "c12";
|
|
8
9
|
//#region src/context/index.ts
|
|
9
10
|
var DefaultContext = class {
|
|
10
11
|
#datasources = null;
|
|
@@ -17,7 +18,7 @@ var DefaultContext = class {
|
|
|
17
18
|
if (!this.#datasources) {
|
|
18
19
|
logger?.info("Searching drizzle datasources in", colorize("blue", baseDir));
|
|
19
20
|
let datasources = await mapAsync(await resolveFiles(baseDir, [configPattern].flat().map((pattern) => "*/" + pattern)), async (path) => {
|
|
20
|
-
const config = await
|
|
21
|
+
const { config } = await loadConfig({ configFile: path });
|
|
21
22
|
const [_, dirName] = path.match(/(.+\/(.+))\/.+$/).slice(1, 3);
|
|
22
23
|
return await transformDrizzleConfig(config, {
|
|
23
24
|
cwd: this.#options.cwd,
|
|
@@ -28,7 +29,7 @@ var DefaultContext = class {
|
|
|
28
29
|
});
|
|
29
30
|
datasources = Object.entries(datasourceOptions).reduce((_datasources, [name, options]) => {
|
|
30
31
|
const datasource = datasources.find((d) => d.name == name && options.connector == (d.driver ? d.driver : d.dialect));
|
|
31
|
-
if (!datasource)
|
|
32
|
+
if (!datasource) return _datasources;
|
|
32
33
|
return [..._datasources, datasource];
|
|
33
34
|
}, []);
|
|
34
35
|
logger?.info("Found drizzle datasources:", datasources.toSorted((datasource) => {
|
package/dist/context.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.mjs","names":["#options","#datasources"],"sources":["../src/context/index.ts"],"sourcesContent":["import type { ConsolaInstance } from \"consola\";\nimport { colorize, type ColorName } from \"consola/utils\";\nimport type { Config, Config as DrizzleConfig } from \"drizzle-kit\";\n\nimport { mapAsync } from \"./internal/async\";\nimport { accent } from \"./internal/logger\";\nimport { resolveFiles } from \"./internal/fs\";\nimport {\n dialectDeclarations,\n genReference,\n moduleTypeDeclarations,\n runtimeDeclarations,\n} from \"./internal/templates\";\nimport { transformDrizzleConfig } from \"./internal/config\";\nimport { dialectVirtualModules, runtimeVirtualModule } from \"./internal/virtual\";\n\nimport type { MaybePromise, VirtualModules } from \"nitro-drizzle/shared\";\n\n/**\n * Context interface for managing Drizzle datasource configurations.\n */\nexport interface Context {\n /**\n * Reloads the context, clearing any cached datasource information.\n */\n reload(): MaybePromise<void>;\n /**\n * Returns a list of all resolved datasource information.\n */\n datasources(): MaybePromise<DatasourceInfo[]>;\n /**\n * Returns virtual module code for runtime datasource access.\n */\n virtualModules(): MaybePromise<VirtualModules>;\n virtualTypeDeclarations(): MaybePromise<Record<string, VirtualModules>>;\n moduleTypeDeclarations(): MaybePromise<VirtualModules<`${string}.d.ts`>>;\n runtimeTypeDeclarations(\n // options?: RuntimeDeclarationOptions,\n ): MaybePromise<VirtualModules<`${string}.d.ts`>>;\n}\n\nclass DefaultContext implements Context {\n #datasources: DatasourceInfo[] | null = null;\n readonly #options: ContextOptions;\n\n constructor(options: ContextOptions) {\n this.#options = options;\n }\n\n async datasources() {\n const {\n logger,\n baseDir,\n configPattern,\n resolver,\n datasource: datasourceOptions,\n } = this.#options;\n\n if (!this.#datasources) {\n logger?.info(\"Searching drizzle datasources in\", colorize(\"blue\", baseDir));\n\n const drizzleConfigsResolvedPaths = await resolveFiles(\n baseDir,\n [configPattern].flat().map((pattern) => \"*/\" + pattern),\n );\n\n let datasources: DatasourceInfo[] = await mapAsync(\n drizzleConfigsResolvedPaths,\n async (path) => {\n const config = await this.#options.resolver.import<DrizzleConfig>(path, {\n default: true,\n });\n const [_, dirName] = path.match(/(.+\\/(.+))\\/.+$/)!.slice(1, 3) as [string, string];\n\n return await transformDrizzleConfig(config, {\n cwd: this.#options.cwd,\n path,\n dirName,\n resolver,\n });\n },\n );\n\n datasources = Object.entries(datasourceOptions).reduce((_datasources, [name, options]) => {\n const datasource = datasources.find(\n (d) => d.name == name && options.connector == (d.driver ? d.driver : d.dialect),\n );\n if (!datasource) {\n throw new Error(\"Unable to resolve datasource \" + name);\n }\n return [..._datasources, datasource];\n }, [] as DatasourceInfo[]);\n\n logger?.info(\n \"Found drizzle datasources:\",\n datasources\n .toSorted((datasource) => {\n return datasource.enabled ? -1 : 1;\n })\n .map((datasource) => {\n let msg = [datasource.name];\n let color: ColorName;\n if (datasource.enabled) {\n color = \"greenBright\";\n } else {\n color = \"gray\";\n msg.push(\"(disabled)\");\n }\n return colorize(color, msg.join(\" \"));\n })\n .join(\", \"),\n );\n\n const enabledDatasources = datasources.filter((d) => d.enabled);\n\n logger?.info(\n accent`Using ${enabledDatasources.length} of ${datasources.length} resolved datasources` +\n (enabledDatasources.length > 0 ? \":\" : \"\"),\n enabledDatasources\n .map((datasource) => {\n return [\n colorize(\"greenBright\", datasource.name),\n colorize(\"yellow\", \"(\" + (datasource.driver || datasource.dialect) + \")\"),\n ].join(\" \");\n })\n .join(\", \"),\n );\n\n this.#datasources = datasources;\n }\n\n return this.#datasources;\n }\n\n async virtualTypeDeclarations(): Promise<Record<string, VirtualModules<`${string}.d.ts`>>> {\n const datasources = [...(await this.datasources())].filter((d) => d.enabled);\n return {\n \"#nitro-drizzle/*\": {\n \"nitro-drizzle/virtual.d.ts\": [dialectDeclarations(datasources)].join(\"\\n\"),\n },\n };\n }\n\n async moduleTypeDeclarations(): Promise<VirtualModules> {\n return moduleTypeDeclarations(await this.datasources());\n }\n\n async runtimeTypeDeclarations(\n // options?: RuntimeDeclarationOptions,\n ): Promise<VirtualModules<`${string}.d.ts`>> {\n const datasources = await this.datasources();\n const references = new Set([\n { types: \"nitro-drizzle/runtime\" },\n ...this.#options.plugins.map((pluginId) => {\n return { types: pluginId };\n }),\n ]);\n const content = [\n ...[...references.values()].map((reference) => genReference(reference)),\n runtimeDeclarations(datasources),\n /* ts */ `export {};`,\n ].join(\"\\n\");\n return {\n \"nitro-drizzle/runtime.d.ts\": content,\n };\n }\n\n async virtualModules(): Promise<VirtualModules<`#nitro-drizzle/${string}`>> {\n const datasources = await this.datasources();\n return {\n \"#nitro-drizzle/runtime\": runtimeVirtualModule(datasources),\n ...dialectVirtualModules(datasources),\n };\n }\n\n reload() {\n this.#datasources = null;\n }\n}\n\n/**\n * Glob pattern or array of patterns to match Drizzle configuration files.\n */\nexport type ConfigPattern = string | readonly string[];\n\n/**\n * Resolver interface for importing modules and resolving paths.\n */\nexport interface Resolver {\n /**\n * Resolves a module ID to its full path.\n */\n resolve(id: string): string;\n /**\n * Attempts to resolve a module ID, returns undefined if not found.\n */\n tryResolve(id: string): string | undefined;\n /**\n * Imports a module dynamically.\n * @param id - Module identifier to import\n * @param options - Import options, set default: true to import default export\n */\n import<T>(id: string, options?: { default?: boolean }): Promise<T>;\n}\n\nexport interface ContextOptions {\n logger?: ConsolaInstance;\n /**\n * Current working directory\n */\n cwd: string;\n /**\n * Base project directory to search drizzle config files\n */\n baseDir: string;\n /**\n * Pattern for drizzle config files\n */\n configPattern: ConfigPattern;\n /**\n * Nuxt Kit resolver\n */\n resolver: Resolver;\n /**\n * Connector options\n */\n datasource: Record<string, { connector: string }>;\n\n plugins: readonly string[];\n}\n\n/**\n * Creates a Context instance for managing Drizzle datasource configurations.\n * @param options - Configuration options for the context\n * @returns A Context instance\n */\nexport function createContext(options: ContextOptions): Context {\n return new DefaultContext(options);\n}\n\n/**\n * Information about a resolved Drizzle datasource.\n */\nexport interface DatasourceInfo {\n /** Directory name of the datasource (derived from config file location). */\n dirName: string;\n /** Unique name identifier for the datasource. */\n name: string;\n /** Whether the datasource is enabled (filtered by connector configuration). */\n enabled: boolean;\n /** Database dialect (e.g., 'sqlite', 'postgresql', 'mysql'). */\n dialect: string;\n /** Driver type if specified in config, otherwise undefined. */\n driver: string | undefined;\n /** Import paths for schema, connector, and helpers. */\n imports: {\n config: string;\n schema: string[];\n connector: string;\n helpers: string;\n };\n /** Migration configuration for this datasource. */\n migrations: {\n assets?: string;\n config?: Config[\"migrations\"];\n };\n}\n"],"mappings":";;;;;;;;AAyCA,IAAM,iBAAN,MAAwC;CACtC,eAAwC;CACxC;CAEA,YAAY,SAAyB;EACnC,KAAKA,WAAW;CAClB;CAEA,MAAM,cAAc;EAClB,MAAM,EACJ,QACA,SACA,eACA,UACA,YAAY,sBACV,KAAKA;EAET,IAAI,CAAC,KAAKC,cAAc;GACtB,QAAQ,KAAK,oCAAoC,SAAS,QAAQ,OAAO,CAAC;GAO1E,IAAI,cAAgC,MAAM,SACxC,MANwC,aACxC,SACA,CAAC,aAAa,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,YAAY,OAAO,OAAO,CACxD,GAIE,OAAO,SAAS;IACd,MAAM,SAAS,MAAM,KAAKD,SAAS,SAAS,OAAsB,MAAM,EACtE,SAAS,KACX,CAAC;IACD,MAAM,CAAC,GAAG,WAAW,KAAK,MAAM,iBAAiB,CAAC,CAAE,MAAM,G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,CAAC,QAAQ,MAAM,EAAE,OAGH,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,EAC5E,EACF;CACF;CAEA,MAAM,yBAAkD;EACtD,OAAO,uBAAuB,MAAM,KAAK,YAAY,CAAC;CACxD;CAEA,MAAM,0BAEuC;EAC3C,MAAM,cAAc,MAAM,KAAK,YAAY;EAY3C,OAAO,EACL,8BANc;GACd,GAAG,CAAC,oBAAG,IAPc,IAAI,CACzB,EAAE,OAAO,wBAAwB,GACjC,GAAG,KAAKD,SAAS,QAAQ,KAAK,aAAa;IACzC,OAAO,EAAE,OAAO,SAAS;GAC3B,CAAC,CACH,CAEkB,EAAA,CAAE,OAAO,CAAC,CAAC,CAAC,KAAK,cAAc,aAAa,SAAS,CAAC;GACtE,oBAAoB,WAAW;GACtB;EACX,CAAC,CAAC,KAAK,IAE+B,EACtC;CACF;CAEA,MAAM,iBAAsE;EAC1E,MAAM,cAAc,MAAM,KAAK,YAAY;EAC3C,OAAO;GACL,0BAA0B,qBAAqB,WAAW;GAC1D,GAAG,sBAAsB,WAAW;EACtC;CACF;CAEA,SAAS;EACP,KAAKC,eAAe;CACtB;AACF;;;;;;AA0DA,SAAgB,cAAc,SAAkC;CAC9D,OAAO,IAAI,eAAe,OAAO;AACnC"}
|
|
1
|
+
{"version":3,"file":"context.mjs","names":["#options","#datasources"],"sources":["../src/context/index.ts"],"sourcesContent":["import type { ConsolaInstance } from \"consola\";\nimport { colorize, type ColorName } from \"consola/utils\";\nimport type { Config, Config as DrizzleConfig } from \"drizzle-kit\";\nimport { loadConfig } from \"c12\";\n\nimport { mapAsync } from \"./internal/async\";\nimport { accent } from \"./internal/logger\";\nimport { resolveFiles } from \"./internal/fs\";\nimport {\n dialectDeclarations,\n genReference,\n moduleTypeDeclarations,\n runtimeDeclarations,\n} from \"./internal/templates\";\nimport { transformDrizzleConfig } from \"./internal/config\";\nimport { dialectVirtualModules, runtimeVirtualModule } from \"./internal/virtual\";\n\nimport type { MaybePromise, VirtualModules } from \"nitro-drizzle/shared\";\n\n/**\n * Context interface for managing Drizzle datasource configurations.\n */\nexport interface Context {\n /**\n * Reloads the context, clearing any cached datasource information.\n */\n reload(): MaybePromise<void>;\n /**\n * Returns a list of all resolved datasource information.\n */\n datasources(): MaybePromise<DatasourceInfo[]>;\n /**\n * Returns virtual module code for runtime datasource access.\n */\n virtualModules(): MaybePromise<VirtualModules>;\n virtualTypeDeclarations(): MaybePromise<Record<string, VirtualModules>>;\n moduleTypeDeclarations(): MaybePromise<VirtualModules<`${string}.d.ts`>>;\n runtimeTypeDeclarations(): MaybePromise<VirtualModules<`${string}.d.ts`>>;\n}\n\nclass DefaultContext implements Context {\n #datasources: DatasourceInfo[] | null = null;\n readonly #options: ContextOptions;\n\n constructor(options: ContextOptions) {\n this.#options = options;\n }\n\n async datasources() {\n const {\n logger,\n baseDir,\n configPattern,\n resolver,\n datasource: datasourceOptions,\n } = this.#options;\n\n if (!this.#datasources) {\n logger?.info(\"Searching drizzle datasources in\", colorize(\"blue\", baseDir));\n\n const drizzleConfigsResolvedPaths = await resolveFiles(\n baseDir,\n [configPattern].flat().map((pattern) => \"*/\" + pattern),\n );\n\n let datasources: DatasourceInfo[] = await mapAsync(\n drizzleConfigsResolvedPaths,\n async (path) => {\n const { config } = await loadConfig<DrizzleConfig>({\n configFile: path,\n });\n const [_, dirName] = path.match(/(.+\\/(.+))\\/.+$/)!.slice(1, 3) as [string, string];\n\n return await transformDrizzleConfig(config, {\n cwd: this.#options.cwd,\n path,\n dirName,\n resolver,\n });\n },\n );\n\n datasources = Object.entries(datasourceOptions).reduce((_datasources, [name, options]) => {\n const datasource = datasources.find(\n (d) => d.name == name && options.connector == (d.driver ? d.driver : d.dialect),\n );\n if (!datasource) {\n return _datasources;\n }\n return [..._datasources, datasource];\n }, [] as DatasourceInfo[]);\n\n logger?.info(\n \"Found drizzle datasources:\",\n datasources\n .toSorted((datasource) => {\n return datasource.enabled ? -1 : 1;\n })\n .map((datasource) => {\n let msg = [datasource.name];\n let color: ColorName;\n if (datasource.enabled) {\n color = \"greenBright\";\n } else {\n color = \"gray\";\n msg.push(\"(disabled)\");\n }\n return colorize(color, msg.join(\" \"));\n })\n .join(\", \"),\n );\n\n const enabledDatasources = datasources.filter((d) => d.enabled);\n\n logger?.info(\n accent`Using ${enabledDatasources.length} of ${datasources.length} resolved datasources` +\n (enabledDatasources.length > 0 ? \":\" : \"\"),\n enabledDatasources\n .map((datasource) => {\n return [\n colorize(\"greenBright\", datasource.name),\n colorize(\"yellow\", \"(\" + (datasource.driver || datasource.dialect) + \")\"),\n ].join(\" \");\n })\n .join(\", \"),\n );\n\n this.#datasources = datasources;\n }\n\n return this.#datasources;\n }\n\n async virtualTypeDeclarations(): Promise<Record<string, VirtualModules<`${string}.d.ts`>>> {\n const datasources = [...(await this.datasources())].filter((d) => d.enabled);\n return {\n \"#nitro-drizzle/*\": {\n \"nitro-drizzle/virtual.d.ts\": [dialectDeclarations(datasources)].join(\"\\n\"),\n },\n };\n }\n\n async moduleTypeDeclarations(): Promise<VirtualModules> {\n return moduleTypeDeclarations(await this.datasources());\n }\n\n async runtimeTypeDeclarations(): Promise<VirtualModules<`${string}.d.ts`>> {\n const datasources = await this.datasources();\n const references = new Set([\n { types: \"nitro-drizzle/runtime\" },\n ...this.#options.plugins.map((pluginId) => {\n return { types: pluginId };\n }),\n ]);\n const content = [\n ...[...references.values()].map((reference) => genReference(reference)),\n runtimeDeclarations(datasources),\n /* ts */ `export {};`,\n ].join(\"\\n\");\n return {\n \"nitro-drizzle/runtime.d.ts\": content,\n };\n }\n\n async virtualModules(): Promise<VirtualModules<`#nitro-drizzle/${string}`>> {\n const datasources = await this.datasources();\n return {\n \"#nitro-drizzle/runtime\": runtimeVirtualModule(datasources),\n ...dialectVirtualModules(datasources),\n };\n }\n\n reload() {\n this.#datasources = null;\n }\n}\n\n/**\n * Glob pattern or array of patterns to match Drizzle configuration files.\n */\nexport type ConfigPattern = string | readonly string[];\n\n/**\n * Resolver interface for importing modules and resolving paths.\n */\nexport interface Resolver {\n /**\n * Resolves a module ID to its full path.\n */\n resolve(id: string): string;\n /**\n * Attempts to resolve a module ID, returns undefined if not found.\n */\n tryResolve(id: string): string | undefined;\n}\n\nexport interface ContextOptions {\n logger?: ConsolaInstance;\n /**\n * Current working directory\n */\n cwd: string;\n /**\n * Base project directory to search drizzle config files\n */\n baseDir: string;\n /**\n * Pattern for drizzle config files\n */\n configPattern: ConfigPattern;\n /**\n * Nuxt Kit resolver\n */\n resolver: Resolver;\n /**\n * Connector options\n */\n datasource: Record<string, { connector: string }>;\n\n plugins: readonly string[];\n}\n\n/**\n * Creates a Context instance for managing Drizzle datasource configurations.\n * @param options - Configuration options for the context\n * @returns A Context instance\n */\nexport function createContext(options: ContextOptions): Context {\n return new DefaultContext(options);\n}\n\n/**\n * Information about a resolved Drizzle datasource.\n */\nexport interface DatasourceInfo {\n /** Directory name of the datasource (derived from config file location). */\n dirName: string;\n /** Unique name identifier for the datasource. */\n name: string;\n /** Whether the datasource is enabled (filtered by connector configuration). */\n enabled: boolean;\n /** Database dialect (e.g., 'sqlite', 'postgresql', 'mysql'). */\n dialect: string;\n /** Driver type if specified in config, otherwise undefined. */\n driver: string | undefined;\n /** Import paths for schema, connector, and helpers. */\n imports: {\n config: string;\n schema: string[];\n connector: string;\n helpers: string;\n };\n /** Migration configuration for this datasource. */\n migrations: {\n assets?: string;\n config?: Config[\"migrations\"];\n };\n}\n"],"mappings":";;;;;;;;;AAwCA,IAAM,iBAAN,MAAwC;CACtC,eAAwC;CACxC;CAEA,YAAY,SAAyB;EACnC,KAAKA,WAAW;CAClB;CAEA,MAAM,cAAc;EAClB,MAAM,EACJ,QACA,SACA,eACA,UACA,YAAY,sBACV,KAAKA;EAET,IAAI,CAAC,KAAKC,cAAc;GACtB,QAAQ,KAAK,oCAAoC,SAAS,QAAQ,OAAO,CAAC;GAO1E,IAAI,cAAgC,MAAM,SACxC,MANwC,aACxC,SACA,CAAC,aAAa,CAAC,CAAC,KAAK,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,KAAKC,eAAe;EACtB;EAEA,OAAO,KAAKA;CACd;CAEA,MAAM,0BAAqF;EAEzF,OAAO,EACL,oBAAoB,EAClB,8BAA8B,CAAC,oBAHf,CAAC,GAAI,MAAM,KAAK,YAAY,CAAE,CAAC,CAAC,QAAQ,MAAM,EAAE,OAGH,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,EAC5E,EACF;CACF;CAEA,MAAM,yBAAkD;EACtD,OAAO,uBAAuB,MAAM,KAAK,YAAY,CAAC;CACxD;CAEA,MAAM,0BAAqE;EACzE,MAAM,cAAc,MAAM,KAAK,YAAY;EAY3C,OAAO,EACL,8BANc;GACd,GAAG,CAAC,oBAAG,IAPc,IAAI,CACzB,EAAE,OAAO,wBAAwB,GACjC,GAAG,KAAKD,SAAS,QAAQ,KAAK,aAAa;IACzC,OAAO,EAAE,OAAO,SAAS;GAC3B,CAAC,CACH,CAEkB,EAAA,CAAE,OAAO,CAAC,CAAC,CAAC,KAAK,cAAc,aAAa,SAAS,CAAC;GACtE,oBAAoB,WAAW;GACtB;EACX,CAAC,CAAC,KAAK,IAE+B,EACtC;CACF;CAEA,MAAM,iBAAsE;EAC1E,MAAM,cAAc,MAAM,KAAK,YAAY;EAC3C,OAAO;GACL,0BAA0B,qBAAqB,WAAW;GAC1D,GAAG,sBAAsB,WAAW;EACtC;CACF;CAEA,SAAS;EACP,KAAKC,eAAe;CACtB;AACF;;;;;;AAoDA,SAAgB,cAAc,SAAkC;CAC9D,OAAO,IAAI,eAAe,OAAO;AACnC"}
|
|
@@ -3,8 +3,9 @@ function enablePlugins(nitroOptions, moduleOptions) {
|
|
|
3
3
|
const plugins = [];
|
|
4
4
|
if (moduleOptions.migrations && moduleOptions.migrations.migrateOnInit) plugins.push("migrate");
|
|
5
5
|
plugins.push("init");
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const pluginIds = plugins.map((pluginName) => `nitro-drizzle/plugins/${pluginName}`);
|
|
7
|
+
nitroOptions.plugins.push(...pluginIds);
|
|
8
|
+
return pluginIds;
|
|
8
9
|
}
|
|
9
10
|
//#endregion
|
|
10
11
|
export { enablePlugins };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.mjs","names":[],"sources":["../../../src/module/internal/plugins.ts"],"sourcesContent":["import type { NitroOptions } from \"nitropack\";\nimport type { ModuleOptions } from \"..\";\n\nexport function enablePlugins(\n nitroOptions: NitroOptions,\n moduleOptions: ModuleOptions,\n): readonly string[] {\n const plugins: (\"init\" | \"migrate\")[] = [];\n\n if (moduleOptions.migrations && moduleOptions.migrations.migrateOnInit) {\n plugins.push(\"migrate\");\n }\n\n plugins.push(\"init\");\n\n
|
|
1
|
+
{"version":3,"file":"plugins.mjs","names":[],"sources":["../../../src/module/internal/plugins.ts"],"sourcesContent":["import type { NitroOptions } from \"nitropack\";\nimport type { ModuleOptions } from \"..\";\n\nexport function enablePlugins(\n nitroOptions: NitroOptions,\n moduleOptions: ModuleOptions,\n): readonly string[] {\n const plugins: (\"init\" | \"migrate\")[] = [];\n\n if (moduleOptions.migrations && moduleOptions.migrations.migrateOnInit) {\n plugins.push(\"migrate\");\n }\n\n plugins.push(\"init\");\n\n const pluginIds = plugins.map((pluginName) => `nitro-drizzle/plugins/${pluginName}`);\n\n nitroOptions.plugins.push(...pluginIds);\n\n return pluginIds;\n}\n"],"mappings":";AAGA,SAAgB,cACd,cACA,eACmB;CACnB,MAAM,UAAkC,CAAC;CAEzC,IAAI,cAAc,cAAc,cAAc,WAAW,eACvD,QAAQ,KAAK,SAAS;CAGxB,QAAQ,KAAK,MAAM;CAEnB,MAAM,YAAY,QAAQ,KAAK,eAAe,yBAAyB,YAAY;CAEnF,aAAa,QAAQ,KAAK,GAAG,SAAS;CAEtC,OAAO;AACT"}
|
|
@@ -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 tryResolve(id: string): string | undefined {\n try {\n return this.resolve(id);\n } catch {}\n }\n
|
|
1
|
+
{"version":3,"file":"resolver.mjs","names":["#jiti"],"sources":["../../../src/module/internal/resolver.ts"],"sourcesContent":["import { createJiti, type Jiti, type JitiOptions } from \"jiti\";\nimport type { Resolver } from \"nitro-drizzle/context\";\nimport { fileURLToPath } from \"url\";\n\nexport function createResolver(id: string, options?: { alias?: Record<string, string> }): Resolver {\n return new JitiResolver(id, {\n alias: options?.alias,\n });\n}\n\nclass JitiResolver implements Resolver {\n readonly #jiti: Jiti;\n\n constructor(id: string, options?: JitiOptions) {\n this.#jiti = createJiti(id, options);\n }\n\n resolve(id: string): string {\n return fileURLToPath(this.#jiti.esmResolve(id));\n }\n\n tryResolve(id: string): string | undefined {\n try {\n return this.resolve(id);\n } catch {}\n }\n}\n"],"mappings":";;;AAIA,SAAgB,eAAe,IAAY,SAAwD;CACjG,OAAO,IAAI,aAAa,IAAI,EAC1B,OAAO,SAAS,MAClB,CAAC;AACH;AAEA,IAAM,eAAN,MAAuC;CACrC;CAEA,YAAY,IAAY,SAAuB;EAC7C,KAAKA,QAAQ,WAAW,IAAI,OAAO;CACrC;CAEA,QAAQ,IAAoB;EAC1B,OAAO,cAAc,KAAKA,MAAM,WAAW,EAAE,CAAC;CAChD;CAEA,WAAW,IAAgC;EACzC,IAAI;GACF,OAAO,KAAK,QAAQ,EAAE;EACxB,QAAQ,CAAC;CACX;AACF"}
|
package/dist/module.mjs
CHANGED
|
@@ -14,7 +14,7 @@ import { pkgName } from "nitro-drizzle/meta";
|
|
|
14
14
|
//#region src/module/index.ts
|
|
15
15
|
const defaultModuleOptions = {
|
|
16
16
|
baseDir: "~/drizzle",
|
|
17
|
-
configPattern: ["drizzle.config
|
|
17
|
+
configPattern: ["drizzle.config.{js,ts}", "drizzle-*.config.{js,ts}"],
|
|
18
18
|
migrations: {
|
|
19
19
|
storageBase: "drizzle:migrations",
|
|
20
20
|
migrateOnInit: false
|
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 { createContext, type ConfigPattern, type ContextOptions } from \"nitro-drizzle/context\";\nimport { pkgName } from \"nitro-drizzle/meta\";\n\nimport { addAugmentations, addDeclarations } from \"./internal/types\";\nimport { createResolver } from \"./internal/resolver\";\nimport { updateMigrationAssets, type MigrationOptions } from \"./internal/assets\";\nimport { addInlineExternals } from \"./internal/externals\";\nimport { reloadPlugin } from \"./internal/reload\";\nimport { addPlugin } from \"./internal/rollup\";\nimport { migrationsVirtualModule } from \"./internal/virtual\";\nimport { enablePlugins } from \"./internal/plugins\";\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 | MigrationOptions;\n}\n\nconst defaultModuleOptions: ModuleOptions = {\n baseDir: \"~/drizzle\",\n configPattern: [\"drizzle.config
|
|
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 { createContext, type ConfigPattern, type ContextOptions } from \"nitro-drizzle/context\";\nimport { pkgName } from \"nitro-drizzle/meta\";\n\nimport { addAugmentations, addDeclarations } from \"./internal/types\";\nimport { createResolver } from \"./internal/resolver\";\nimport { updateMigrationAssets, type MigrationOptions } from \"./internal/assets\";\nimport { addInlineExternals } from \"./internal/externals\";\nimport { reloadPlugin } from \"./internal/reload\";\nimport { addPlugin } from \"./internal/rollup\";\nimport { migrationsVirtualModule } from \"./internal/virtual\";\nimport { enablePlugins } from \"./internal/plugins\";\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 | MigrationOptions;\n}\n\nconst defaultModuleOptions: ModuleOptions = {\n baseDir: \"~/drizzle\",\n configPattern: [\"drizzle.config.{js,ts}\", \"drizzle-*.config.{js,ts}\"],\n migrations: {\n storageBase: \"drizzle:migrations\",\n migrateOnInit: false,\n },\n};\n\nconst module: NitroModule = {\n name: pkgName,\n async setup(nitro) {\n const moduleOptions = defu(nitro.options.drizzle, defaultModuleOptions);\n\n const plugins = enablePlugins(nitro.options, moduleOptions);\n\n const resolver = createResolver(nitro.options.rootDir, {\n alias: nitro.options.alias,\n });\n\n const resolvedBaseDir = 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: resolvedBaseDir,\n logger: nitro.logger,\n configPattern: moduleOptions.configPattern,\n datasource: { ...moduleOptions.datasources },\n plugins,\n };\n\n const context = createContext(contextOptions);\n\n // add inline externals\n addInlineExternals(nitro.options);\n\n // add virtual modules\n Object.assign(\n nitro.options.virtual,\n await context.virtualModules(),\n migrationsVirtualModule(await context.datasources(), moduleOptions.migrations),\n );\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 // server assets\n if (moduleOptions.migrations) {\n await updateMigrationAssets(context, nitro.options, moduleOptions.migrations);\n\n if (nitro.options.experimental.tasks) {\n nitro.options.tasks ||= {};\n nitro.options.tasks[\"drizzle:migrate\"] = {\n description: \"Run drizzle migrations for a datasource.\",\n handler: \"nitro-drizzle/migrations/task\",\n };\n }\n }\n\n // watch options\n nitro.hooks.hook(\"rollup:before\", async (nitro, config) => {\n await addPlugin(config, reloadPlugin(nitro, contextOptions));\n });\n\n // extend types\n nitro.hooks.hook(\"types:extend\", async (types) => {\n const runtimeTypeDeclarations = await context.runtimeTypeDeclarations();\n const moduleTypeDeclarations = await context.moduleTypeDeclarations();\n\n await addAugmentations(nitro.options, types, {\n ...runtimeTypeDeclarations,\n ...moduleTypeDeclarations,\n });\n\n const virtualTypeDeclarations = await context.virtualTypeDeclarations();\n await addDeclarations(nitro.options, types, virtualTypeDeclarations);\n });\n },\n};\n\nexport default module;\n"],"mappings":";;;;;;;;;;;;;;AAiDA,MAAM,uBAAsC;CAC1C,SAAS;CACT,eAAe,CAAC,0BAA0B,0BAA0B;CACpE,YAAY;EACV,aAAa;EACb,eAAe;CACjB;AACF;AAEA,MAAM,SAAsB;CAC1B,MAAM;CACN,MAAM,MAAM,OAAO;EACjB,MAAM,gBAAgB,KAAK,MAAM,QAAQ,SAAS,oBAAoB;EAEtE,MAAM,UAAU,cAA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ED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-drizzle",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "Nitro module to integrate Drizzle ORM with ease.",
|
|
5
5
|
"homepage": "https://github.com/Myshkouski/nitro-drizzle#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -36,41 +36,46 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@types/better-sqlite3": "^7.6.13",
|
|
38
38
|
"@typescript/native-preview": "7.0.0-dev.20260606.1",
|
|
39
|
+
"c12": "^3.3.4",
|
|
39
40
|
"consola": "^3.4.2",
|
|
40
41
|
"db0": "^0.3.4",
|
|
41
42
|
"defu": "^6.1.7",
|
|
42
43
|
"drizzle-kit": "^0.31.10",
|
|
43
|
-
"exsolve": "^1.0.8",
|
|
44
|
-
"h3": "^1.15.11",
|
|
45
44
|
"jiti": "^2.7.0",
|
|
46
45
|
"knitwork": "^1.3.0",
|
|
47
|
-
"nitropack": "^2
|
|
46
|
+
"nitropack": "^2",
|
|
48
47
|
"ohash": "^2.0.11",
|
|
49
48
|
"pathe": "^2.0.3",
|
|
50
|
-
"rollup": "^4.62.
|
|
49
|
+
"rollup": "^4.62.2",
|
|
51
50
|
"strip-indent": "^4.1.1",
|
|
52
51
|
"tinyglobby": "^0.2.17",
|
|
53
52
|
"unstorage": "^1.17.5"
|
|
54
53
|
},
|
|
55
54
|
"devDependencies": {
|
|
56
|
-
"@cloudflare/workers-types": "^4.
|
|
57
|
-
"@
|
|
58
|
-
"
|
|
55
|
+
"@cloudflare/workers-types": "^4.20260702.1",
|
|
56
|
+
"@testcontainers/mysql": "^12.0.4",
|
|
57
|
+
"@testcontainers/postgresql": "^12.0.4",
|
|
58
|
+
"@types/node": "^25.9.4",
|
|
59
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
60
|
+
"@vitest/ui": "^4.1.10",
|
|
61
|
+
"changelogen": "^0.6.2",
|
|
62
|
+
"lefthook": "^2.1.9",
|
|
59
63
|
"listhen": "^1.10.0",
|
|
60
64
|
"oxfmt": "^0.57.0",
|
|
61
|
-
"oxlint": "^1.
|
|
62
|
-
"oxlint-tsgolint": "^0.
|
|
63
|
-
"
|
|
65
|
+
"oxlint": "^1.72.0",
|
|
66
|
+
"oxlint-tsgolint": "^0.24.0",
|
|
67
|
+
"testcontainers": "^12.0.4",
|
|
68
|
+
"tsdown": "^0.22.3",
|
|
64
69
|
"typescript": "^6.0.3",
|
|
65
|
-
"vitest": "^4.1.
|
|
70
|
+
"vitest": "^4.1.10"
|
|
66
71
|
},
|
|
67
72
|
"peerDependencies": {
|
|
68
73
|
"@cloudflare/workers-types": "^4.20260624.1",
|
|
69
|
-
"@electric-sql/pglite": "^0.5.
|
|
70
|
-
"better-sqlite3": "^12.
|
|
74
|
+
"@electric-sql/pglite": "^0.5.4",
|
|
75
|
+
"better-sqlite3": "^12.11.1",
|
|
71
76
|
"drizzle-orm": "^0.45.2",
|
|
72
|
-
"h3": "^1
|
|
73
|
-
"mysql2": "^3.22.
|
|
77
|
+
"h3": "^1",
|
|
78
|
+
"mysql2": "^3.22.5",
|
|
74
79
|
"postgres": "^3.4.9"
|
|
75
80
|
},
|
|
76
81
|
"peerDependenciesMeta": {
|
|
@@ -98,6 +103,7 @@
|
|
|
98
103
|
"lint": "oxlint",
|
|
99
104
|
"playground": "nitro dev playground",
|
|
100
105
|
"test": "vitest run",
|
|
106
|
+
"test:coverage": "vitest run --coverage",
|
|
101
107
|
"typecheck": "tsc --noEmit",
|
|
102
108
|
"release": "changelogen --release"
|
|
103
109
|
}
|