nitro-drizzle 0.2.11 → 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 -1
- 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/index.d.mts +2 -0
- package/dist/index.mjs +2 -0
- package/package.json +2 -1
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,7 +1,7 @@
|
|
|
1
1
|
import { Config } from "drizzle-kit";
|
|
2
2
|
//#region src/config/defineConfig.d.ts
|
|
3
3
|
/**
|
|
4
|
-
* Define Drizzle config compatible with both 'nitro-drizzle
|
|
4
|
+
* Define Drizzle config compatible with both 'nitro-drizzle' and 'drizzle-kit' packages.
|
|
5
5
|
*
|
|
6
6
|
* @param config
|
|
7
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}`, \"*\")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AO,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/index.d.mts
ADDED
package/dist/index.mjs
ADDED
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",
|