nitro-drizzle 0.2.3 → 0.2.5

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.
@@ -1,6 +1,7 @@
1
1
  import { genAugmentation, genInlineTypeImport, genString, genTypeImport } from "knitwork";
2
2
  //#region src/context/internal/templates.ts
3
3
  function runtimeDeclarations(datasources) {
4
+ if (!datasources.length) return "";
4
5
  return [genTypeImport("nitro-drizzle/runtime", ["ToDatasourceProvider"]), genAugmentation("nitro-drizzle/runtime", { DatasourceRegistry: Object.fromEntries(datasources.filter((datasource) => {
5
6
  return datasource.enabled;
6
7
  }).map(({ name, imports }) => {
@@ -12,8 +13,8 @@ function genSchemaType(imports) {
12
13
  return imports.map((id) => `typeof import('${id}')`).join(" & ");
13
14
  }
14
15
  function moduleDeclarations(datasources) {
15
- const names = datasources.map((d) => d.name);
16
- return [genTypeImport("nitro-drizzle/module", ["ModuleOptions"]), genAugmentation("nitro-drizzle/module", { DatasourceOptions: [{}, { extends: `Record<${names.map((n) => genString(n)).join(" | ")}, { connector: string; }>` }] })].join("\n");
16
+ if (!datasources.length) return "";
17
+ return [genAugmentation("nitro-drizzle/module", { DatasourceOptions: [{}, { extends: `Record<${datasources.map((d) => d.name).map((n) => genString(n)).join(" | ")}, { connector: string; }>` }] })].join("\n");
17
18
  }
18
19
  function augmentations(datasources) {
19
20
  return { "nitro-drizzle/augmentations.d.ts": [
@@ -1 +1 @@
1
- {"version":3,"file":"templates.mjs","names":[],"sources":["../../../src/context/internal/templates.ts"],"sourcesContent":["import { genTypeImport, genAugmentation, genInlineTypeImport, genString } from \"knitwork\";\nimport type { DatasourceInfo } from \"..\";\nimport type { VirtualModules } from \"nitro-drizzle/shared\";\n\nfunction runtimeDeclarations(datasources: DatasourceInfo[]) {\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\nfunction moduleDeclarations(datasources: DatasourceInfo[]) {\n const names = datasources.map((d) => d.name);\n\n return [\n genTypeImport(\"nitro-drizzle/module\", [\"ModuleOptions\"]),\n genAugmentation(\"nitro-drizzle/module\", {\n DatasourceOptions: [\n {},\n {\n extends: `Record<${names.map((n) => genString(n)).join(\" | \")}, { connector: string; }>`,\n },\n ],\n }),\n ].join(\"\\n\");\n}\n\nexport function augmentations(datasources: DatasourceInfo[]): VirtualModules<`${string}.d.ts`> {\n return {\n \"nitro-drizzle/augmentations.d.ts\": [\n runtimeDeclarations(datasources),\n moduleDeclarations(datasources),\n /* ts */ `export {};`,\n ].join(\"\\n\"),\n };\n}\n\nfunction dialectDeclarations(datasources: DatasourceInfo[]) {\n return datasources\n .filter((d) => d.enabled)\n .map(({ name, dialect }) => {\n return /*ts*/ `\n declare module \"#nitro-drizzle/dialects/${name}\" {\n export * from \"nitro-drizzle/dialects/${dialect}\";\n }\n `;\n })\n .join(\"\\n\");\n}\n\nexport function declarations(\n datasources: DatasourceInfo[],\n): Record<string, VirtualModules<`${string}.d.ts`>> {\n return {\n \"#nitro-drizzle/*\": {\n \"nitro-drizzle/declarations.d.ts\": [dialectDeclarations(datasources)].join(\"\\n\"),\n },\n };\n}\n"],"mappings":";;AAIA,SAAS,oBAAoB,aAA+B;CAC1D,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;AAEA,SAAS,mBAAmB,aAA+B;CACzD,MAAM,QAAQ,YAAY,KAAK,MAAM,EAAE,IAAI;CAE3C,OAAO,CACL,cAAc,wBAAwB,CAAC,eAAe,CAAC,GACvD,gBAAgB,wBAAwB,EACtC,mBAAmB,CACjB,CAAC,GACD,EACE,SAAS,UAAU,MAAM,KAAK,MAAM,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,EAAE,2BAChE,CACF,EACF,CAAC,CACH,CAAC,CAAC,KAAK,IAAI;AACb;AAEA,SAAgB,cAAc,aAAiE;CAC7F,OAAO,EACL,oCAAoC;EAClC,oBAAoB,WAAW;EAC/B,mBAAmB,WAAW;EACrB;CACX,CAAC,CAAC,KAAK,IAAI,EACb;AACF;AAEA,SAAS,oBAAoB,aAA+B;CAC1D,OAAO,YACJ,QAAQ,MAAM,EAAE,OAAO,CAAC,CACxB,KAAK,EAAE,MAAM,cAAc;EAC1B,OAAc;gDAC4B,KAAK;gDACL,QAAQ;;;CAGpD,CAAC,CAAC,CACD,KAAK,IAAI;AACd;AAEA,SAAgB,aACd,aACkD;CAClD,OAAO,EACL,oBAAoB,EAClB,mCAAmC,CAAC,oBAAoB,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,EACjF,EACF;AACF"}
1
+ {"version":3,"file":"templates.mjs","names":[],"sources":["../../../src/context/internal/templates.ts"],"sourcesContent":["import { genTypeImport, genAugmentation, genInlineTypeImport, genString } from \"knitwork\";\nimport type { DatasourceInfo } from \"..\";\nimport type { VirtualModules } from \"nitro-drizzle/shared\";\n\nfunction runtimeDeclarations(datasources: 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\nfunction moduleDeclarations(datasources: DatasourceInfo[]) {\n if (!datasources.length) {\n return \"\";\n }\n\n const names = datasources.map((d) => d.name);\n\n return [\n genAugmentation(\"nitro-drizzle/module\", {\n DatasourceOptions: [\n {},\n {\n extends: `Record<${names.map((n) => genString(n)).join(\" | \")}, { connector: string; }>`,\n },\n ],\n }),\n ].join(\"\\n\");\n}\n\nexport function augmentations(datasources: DatasourceInfo[]): VirtualModules<`${string}.d.ts`> {\n return {\n \"nitro-drizzle/augmentations.d.ts\": [\n runtimeDeclarations(datasources),\n moduleDeclarations(datasources),\n /* ts */ `export {};`,\n ].join(\"\\n\"),\n };\n}\n\nfunction dialectDeclarations(datasources: DatasourceInfo[]) {\n return datasources\n .filter((d) => d.enabled)\n .map(({ name, dialect }) => {\n return /*ts*/ `\n declare module \"#nitro-drizzle/dialects/${name}\" {\n export * from \"nitro-drizzle/dialects/${dialect}\";\n }\n `;\n })\n .join(\"\\n\");\n}\n\nexport function declarations(\n datasources: DatasourceInfo[],\n): Record<string, VirtualModules<`${string}.d.ts`>> {\n return {\n \"#nitro-drizzle/*\": {\n \"nitro-drizzle/declarations.d.ts\": [dialectDeclarations(datasources)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B,aACd,aACkD;CAClD,OAAO,EACL,oBAAoB,EAClB,mCAAmC,CAAC,oBAAoB,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,EACjF,EACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.mjs","names":[],"sources":["../../../src/module/internal/types.ts"],"sourcesContent":["import type { NitroOptions, NitroTypes, VirtualModule } from \"nitropack/types\";\nimport { dirname, join, resolve } from \"pathe\";\nimport { relativeWithDot } from \"./path\";\nimport { writeFile } from \"./fs\";\nimport type { VirtualModules } from \"nitro-drizzle/shared\";\n\nexport async function addAugmentations(\n nitroOptions: NitroOptions,\n nitroTypes: NitroTypes,\n augmentations: VirtualModules,\n) {\n nitroTypes.tsConfig ||= {};\n nitroTypes.tsConfig.include ||= [];\n const paths = await writeTypeFiles(nitroOptions, augmentations);\n nitroTypes.tsConfig.include.push(...paths);\n}\n\nexport async function addDeclarations(\n nitroOptions: NitroOptions,\n nitroTypes: NitroTypes,\n declarations: Record<string, VirtualModules>,\n) {\n nitroTypes.tsConfig ||= {};\n\n for (const alias in declarations) {\n nitroTypes.tsConfig.compilerOptions ||= {};\n nitroTypes.tsConfig.compilerOptions.paths ||= {};\n nitroTypes.tsConfig.compilerOptions.paths[alias] = await writeTypeFiles(\n nitroOptions,\n declarations[alias],\n );\n }\n}\n\nfunction typesDir(nitroOptions: NitroOptions) {\n return join(nitroOptions.buildDir, \"types\");\n}\n\nfunction tsconfigDir(nitroOptions: NitroOptions) {\n const tsConfigPath = resolve(\n nitroOptions.buildDir,\n nitroOptions.typescript.tsconfigPath\n );\n const tsconfigDir = dirname(tsConfigPath);\n return tsconfigDir\n}\n\nasync function writeTypeFiles(nitroOptions: NitroOptions, modules: VirtualModules) {\n const paths: string[] = [];\n const dir = typesDir(nitroOptions);\n for (const filename in modules) {\n const typesFilename = join(dir, filename);\n await writeFile(typesFilename, await getContent(modules[filename]));\n const relativeFilename = relativeWithDot(tsconfigDir(nitroOptions), 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":";;;;AAMA,eAAsB,iBACpB,cACA,YACA,eACA;CACA,WAAW,aAAa,CAAC;CACzB,WAAW,SAAS,YAAY,CAAC;CACjC,MAAM,QAAQ,MAAM,eAAe,cAAc,aAAa;CAC9D,WAAW,SAAS,QAAQ,KAAK,GAAG,KAAK;AAC3C;AAEA,eAAsB,gBACpB,cACA,YACA,cACA;CACA,WAAW,aAAa,CAAC;CAEzB,KAAK,MAAM,SAAS,cAAc;EAChC,WAAW,SAAS,oBAAoB,CAAC;EACzC,WAAW,SAAS,gBAAgB,UAAU,CAAC;EAC/C,WAAW,SAAS,gBAAgB,MAAM,SAAS,MAAM,eACvD,cACA,aAAa,MACf;CACF;AACF;AAEA,SAAS,SAAS,cAA4B;CAC5C,OAAO,KAAK,aAAa,UAAU,OAAO;AAC5C;AAEA,SAAS,YAAY,cAA4B;CAM/C,OADoB,QAJC,QACnB,aAAa,UACb,aAAa,WAAW,YAEa,CACtB;AACnB;AAEA,eAAe,eAAe,cAA4B,SAAyB;CACjF,MAAM,QAAkB,CAAC;CACzB,MAAM,MAAM,SAAS,YAAY;CACjC,KAAK,MAAM,YAAY,SAAS;EAC9B,MAAM,gBAAgB,KAAK,KAAK,QAAQ;EACxC,MAAM,UAAU,eAAe,MAAM,WAAW,QAAQ,SAAS,CAAC;EAClE,MAAM,mBAAmB,gBAAgB,YAAY,YAAY,GAAG,aAAa;EACjF,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 { NitroOptions, NitroTypes, VirtualModule } from \"nitropack/types\";\nimport { dirname, join, resolve } from \"pathe\";\nimport { relativeWithDot } from \"./path\";\nimport { writeFile } from \"./fs\";\nimport type { VirtualModules } from \"nitro-drizzle/shared\";\n\nexport async function addAugmentations(\n nitroOptions: NitroOptions,\n nitroTypes: NitroTypes,\n augmentations: VirtualModules,\n) {\n nitroTypes.tsConfig ||= {};\n nitroTypes.tsConfig.include ||= [];\n const paths = await writeTypeFiles(nitroOptions, augmentations);\n nitroTypes.tsConfig.include.push(...paths);\n}\n\nexport async function addDeclarations(\n nitroOptions: NitroOptions,\n nitroTypes: NitroTypes,\n declarations: Record<string, VirtualModules>,\n) {\n nitroTypes.tsConfig ||= {};\n\n for (const alias in declarations) {\n nitroTypes.tsConfig.compilerOptions ||= {};\n nitroTypes.tsConfig.compilerOptions.paths ||= {};\n nitroTypes.tsConfig.compilerOptions.paths[alias] = await writeTypeFiles(\n nitroOptions,\n declarations[alias],\n );\n }\n}\n\nfunction typesDir(nitroOptions: NitroOptions) {\n return join(nitroOptions.buildDir, \"types\");\n}\n\nfunction tsconfigDir(nitroOptions: NitroOptions) {\n const tsConfigPath = resolve(nitroOptions.buildDir, nitroOptions.typescript.tsconfigPath);\n const tsconfigDir = dirname(tsConfigPath);\n return tsconfigDir;\n}\n\nasync function writeTypeFiles(nitroOptions: NitroOptions, modules: VirtualModules) {\n const paths: string[] = [];\n const dir = typesDir(nitroOptions);\n for (const filename in modules) {\n const typesFilename = join(dir, filename);\n await writeFile(typesFilename, await getContent(modules[filename]));\n const relativeFilename = relativeWithDot(tsconfigDir(nitroOptions), 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":";;;;AAMA,eAAsB,iBACpB,cACA,YACA,eACA;CACA,WAAW,aAAa,CAAC;CACzB,WAAW,SAAS,YAAY,CAAC;CACjC,MAAM,QAAQ,MAAM,eAAe,cAAc,aAAa;CAC9D,WAAW,SAAS,QAAQ,KAAK,GAAG,KAAK;AAC3C;AAEA,eAAsB,gBACpB,cACA,YACA,cACA;CACA,WAAW,aAAa,CAAC;CAEzB,KAAK,MAAM,SAAS,cAAc;EAChC,WAAW,SAAS,oBAAoB,CAAC;EACzC,WAAW,SAAS,gBAAgB,UAAU,CAAC;EAC/C,WAAW,SAAS,gBAAgB,MAAM,SAAS,MAAM,eACvD,cACA,aAAa,MACf;CACF;AACF;AAEA,SAAS,SAAS,cAA4B;CAC5C,OAAO,KAAK,aAAa,UAAU,OAAO;AAC5C;AAEA,SAAS,YAAY,cAA4B;CAG/C,OADoB,QADC,QAAQ,aAAa,UAAU,aAAa,WAAW,YACrC,CACtB;AACnB;AAEA,eAAe,eAAe,cAA4B,SAAyB;CACjF,MAAM,QAAkB,CAAC;CACzB,MAAM,MAAM,SAAS,YAAY;CACjC,KAAK,MAAM,YAAY,SAAS;EAC9B,MAAM,gBAAgB,KAAK,KAAK,QAAQ;EACxC,MAAM,UAAU,eAAe,MAAM,WAAW,QAAQ,SAAS,CAAC;EAClE,MAAM,mBAAmB,gBAAgB,YAAY,YAAY,GAAG,aAAa;EACjF,MAAM,KAAK,gBAAgB;CAC7B;CACA,OAAO;AACT;AAEA,eAAe,WAAW,QAAuB;CAC/C,OAAO,YAAY,OAAO,SAAS,SAAS,MAAM,OAAO;AAC3D"}
package/dist/module.mjs CHANGED
@@ -46,6 +46,7 @@ const module = {
46
46
  await addAugmentations(nitro.options, types, augmentations);
47
47
  const declarations = await context.declarations();
48
48
  await addDeclarations(nitro.options, types, declarations);
49
+ await addAugmentations(nitro.options, types, { "nitro-drizzle/module.d.ts": `import "nitro-drizzle/module";` });
49
50
  });
50
51
  if (nitro.options.imports) nitro.options.imports.imports ||= [];
51
52
  if (moduleOptions.migrations) {
@@ -70,9 +71,14 @@ const module = {
70
71
  });
71
72
  for (const pluginId of enabledPlugins) nitro.options.plugins.push(pluginId);
72
73
  if (enabledPlugins.length) nitro.hooks.hook("types:extend", async (types) => {
73
- await addAugmentations(nitro.options, types, { "nitro-drizzle/plugins.d.ts": enabledPlugins.map((pluginId) => {
74
- return `import "${pluginId}";`;
75
- }).join("\n") });
74
+ await addAugmentations(nitro.options, types, {
75
+ "nitro-drizzle/module.d.ts": `
76
+ import "nitro-drizzle/module";
77
+ `,
78
+ "nitro-drizzle/plugins.d.ts": enabledPlugins.map((pluginId) => {
79
+ return `import "${pluginId}";`;
80
+ }).join("\n")
81
+ });
76
82
  });
77
83
  }
78
84
  };
@@ -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\";\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 * @deprecated Use 'nitro.database' instead.\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.*\", \"drizzle-*.config.*\"],\n migrations: {\n storageBase: \"drizzle:migrations\",\n migrateOnInit: false,\n },\n};\n\nconst module: NitroModule = {\n name: pkgName,\n async setup(nitro) {\n const resolver = createResolver(nitro.options.rootDir, {\n alias: nitro.options.alias,\n });\n const moduleOptions = defu(nitro.options.drizzle, defaultModuleOptions);\n\n const resolvedBaseDir = resolve(\n nitro.options.srcDir,\n resolveAlias(moduleOptions.baseDir, nitro.options.alias),\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 };\n const context = createContext(contextOptions);\n\n // add inline externals\n addInlineExternals(nitro.options);\n\n // specify plugin names to preserve order\n const plugins: Record<\"init\" | \"migrate\", boolean> = {\n migrate: false,\n init: true,\n };\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 nitro.options.typescript = defu(nitro.options.typescript, {\n tsConfig: {\n compilerOptions: {\n paths: {\n \"#nitro-drizzle/*\": [\"./nitro-drizzle/virtual\"],\n },\n },\n },\n });\n\n // extend types\n nitro.hooks.hook(\"types:extend\", async (types) => {\n const augmentations = await context.augmentations();\n await addAugmentations(nitro.options, types, augmentations);\n\n const declarations = await context.declarations();\n await addDeclarations(nitro.options, types, declarations);\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 if (moduleOptions.migrations.migrateOnInit) {\n plugins.migrate = true;\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 // add plugins\n const enabledPlugins = Object.entries(plugins)\n .reduce((plugins, [pluginName, enabled]) => {\n if (enabled) {\n plugins.push(pluginName);\n }\n return plugins;\n }, [] as string[])\n .map((pluginName) => {\n return `nitro-drizzle/plugins/${pluginName}`;\n });\n\n for (const pluginId of enabledPlugins) {\n nitro.options.plugins.push(pluginId);\n }\n\n if (enabledPlugins.length) {\n nitro.hooks.hook(\"types:extend\", async (types) => {\n await addAugmentations(nitro.options, types, {\n \"nitro-drizzle/plugins.d.ts\": enabledPlugins\n .map((pluginId) => {\n return `import \"${pluginId}\";`;\n })\n .join(\"\\n\"),\n });\n });\n }\n },\n};\n\nexport default module;\n"],"mappings":";;;;;;;;;;;;;AAkDA,MAAM,uBAAsC;CAC1C,SAAS;CACT,eAAe,CAAC,oBAAoB,oBAAoB;CACxD,YAAY;EACV,aAAa;EACb,eAAe;CACjB;AACF;AAEA,MAAM,SAAsB;CAC1B,MAAM;CACN,MAAM,MAAM,OAAO;EACjB,MAAM,WAAW,eAAe,MAAM,QAAQ,SAAS,EACrD,OAAO,MAAM,QAAQ,MACvB,CAAC;EACD,MAAM,gBAAgB,KAAK,MAAM,QAAQ,SAAS,oBAAoB;EAEtE,MAAM,kBAAkB,QACtB,MAAM,QAAQ,QACd,aAAa,cAAc,SAAS,MAAM,QAAQ,KAAK,CACzD;EACA,MAAM,iBAAiC;GACrC,KAAK,QAAQ,IAAI;GACP;GACV,SAAS;GACT,QAAQ,MAAM;GACd,eAAe,cAAc;GAC7B,YAAY,EAAE,GAAG,cAAc,YAAY;EAC7C;EACA,MAAM,UAAU,cAAc,cAAc;EAG5C,mBAAmB,MAAM,OAAO;EAGhC,MAAM,UAA+C;GACnD,SAAS;GACT,MAAM;EACR;EAGA,OAAO,OACL,MAAM,QAAQ,SACd,MAAM,QAAQ,eAAe,GAC7B,wBAAwB,MAAM,QAAQ,YAAY,GAAG,cAAc,UAAU,CAC/E;E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O,WAAW,SAAS;GAC7B,CAAC,CAAC,CACD,KAAK,IAAI,EACd,CAAC;EACH,CAAC;CAEL;AACF"}
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\";\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 * @deprecated Use 'nitro.database' instead.\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.*\", \"drizzle-*.config.*\"],\n migrations: {\n storageBase: \"drizzle:migrations\",\n migrateOnInit: false,\n },\n};\n\nconst module: NitroModule = {\n name: pkgName,\n async setup(nitro) {\n const resolver = createResolver(nitro.options.rootDir, {\n alias: nitro.options.alias,\n });\n const moduleOptions = defu(nitro.options.drizzle, defaultModuleOptions);\n\n const resolvedBaseDir = resolve(\n nitro.options.srcDir,\n resolveAlias(moduleOptions.baseDir, nitro.options.alias),\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 };\n const context = createContext(contextOptions);\n\n // add inline externals\n addInlineExternals(nitro.options);\n\n // specify plugin names to preserve order\n const plugins: Record<\"init\" | \"migrate\", boolean> = {\n migrate: false,\n init: true,\n };\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 nitro.options.typescript = defu(nitro.options.typescript, {\n tsConfig: {\n compilerOptions: {\n paths: {\n \"#nitro-drizzle/*\": [\"./nitro-drizzle/virtual\"],\n },\n },\n },\n });\n\n // extend types\n nitro.hooks.hook(\"types:extend\", async (types) => {\n const augmentations = await context.augmentations();\n await addAugmentations(nitro.options, types, augmentations);\n\n const declarations = await context.declarations();\n await addDeclarations(nitro.options, types, declarations);\n\n await addAugmentations(nitro.options, types, {\n \"nitro-drizzle/module.d.ts\": /* ts */ `import \"nitro-drizzle/module\";`,\n });\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 if (moduleOptions.migrations.migrateOnInit) {\n plugins.migrate = true;\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 // add plugins\n const enabledPlugins = Object.entries(plugins)\n .reduce((plugins, [pluginName, enabled]) => {\n if (enabled) {\n plugins.push(pluginName);\n }\n return plugins;\n }, [] as string[])\n .map((pluginName) => {\n return `nitro-drizzle/plugins/${pluginName}`;\n });\n\n for (const pluginId of enabledPlugins) {\n nitro.options.plugins.push(pluginId);\n }\n\n if (enabledPlugins.length) {\n nitro.hooks.hook(\"types:extend\", async (types) => {\n await addAugmentations(nitro.options, types, {\n \"nitro-drizzle/module.d.ts\": /* ts */ `\n import \"nitro-drizzle/module\";\n `,\n \"nitro-drizzle/plugins.d.ts\": enabledPlugins\n .map((pluginId) => {\n return `import \"${pluginId}\";`;\n })\n .join(\"\\n\"),\n });\n });\n }\n },\n};\n\nexport default module;\n"],"mappings":";;;;;;;;;;;;;AAkDA,MAAM,uBAAsC;CAC1C,SAAS;CACT,eAAe,CAAC,oBAAoB,oBAAoB;CACxD,YAAY;EACV,aAAa;EACb,eAAe;CACjB;AACF;AAEA,MAAM,SAAsB;CAC1B,MAAM;CACN,MAAM,MAAM,OAAO;EACjB,MAAM,WAAW,eAAe,MAAM,QAAQ,SAAS,EACrD,OAAO,MAAM,QAAQ,MACvB,CAAC;EACD,MAAM,gBAAgB,KAAK,MAAM,QAAQ,SAAS,oBAAoB;EAEtE,MAAM,kBAAkB,QACtB,MAAM,QAAQ,QACd,aAAa,cAAc,SAAS,MAAM,QAAQ,KAAK,CACzD;EACA,MAAM,iBAAiC;GACrC,KAAK,QAAQ,IAAI;GACP;GACV,SAAS;GACT,QAAQ,MAAM;GACd,eAAe,cAAc;GAC7B,YAAY,EAAE,GAAG,cAAc,YAAY;EAC7C;EACA,MAAM,UAAU,cAAc,cAAc;EAG5C,mBAAmB,MAAM,OAAO;EAGhC,MAAM,UAA+C;GACnD,SAAS;GACT,MAAM;EACR;EAGA,OAAO,OACL,MAAM,QAAQ,SACd,MAAM,QAAQ,eAAe,GAC7B,wBAAwB,MAAM,QAAQ,YAAY,GAAG,cAAc,UAAU,CAC/E;EAEA,MAAM,QAA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OAAO;IAC3C,6BAAsC;;;IAGtC,8BAA8B,eAC3B,KAAK,aAAa;KACjB,OAAO,WAAW,SAAS;IAC7B,CAAC,CAAC,CACD,KAAK,IAAI;GACd,CAAC;EACH,CAAC;CAEL;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nitro-drizzle",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Nitro module to integrate Drizzle ORM with ease.",
5
5
  "homepage": "https://github.com/Myshkouski/nitro-drizzle#readme",
6
6
  "bugs": {
@@ -40,7 +40,6 @@
40
40
  "db0": "^0.3.4",
41
41
  "defu": "^6.1.7",
42
42
  "drizzle-kit": "^0.31.10",
43
- "drizzle-orm": "^0.45.2",
44
43
  "exsolve": "^1.0.8",
45
44
  "h3": "^1.15.11",
46
45
  "jiti": "^2.7.0",
@@ -69,6 +68,7 @@
69
68
  "@cloudflare/workers-types": "^4.20260624.1",
70
69
  "@electric-sql/pglite": "^0.5.1",
71
70
  "better-sqlite3": "^12.10.0",
71
+ "drizzle-orm": "^0.45.2",
72
72
  "h3": "^1.15.5",
73
73
  "mysql2": "^3.22.4",
74
74
  "postgres": "^3.4.9"