nitro-drizzle 0.2.15 → 0.3.0-beta.1
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/dist/context/internal/async.mjs.map +1 -1
- package/dist/context/internal/virtual.mjs +40 -7
- package/dist/context/internal/virtual.mjs.map +1 -1
- package/dist/context.d.mts +3 -2
- package/dist/context.mjs +16 -8
- package/dist/context.mjs.map +1 -1
- package/dist/meta.d.mts +1 -1
- package/dist/meta.mjs +2 -1
- package/dist/meta.mjs.map +1 -1
- package/dist/middleware/context.d.mts +23 -0
- package/dist/middleware/context.mjs +30 -0
- package/dist/middleware/context.mjs.map +1 -0
- package/dist/migrations/task.d.mts +4 -2
- package/dist/migrations/task.mjs +3 -4
- package/dist/migrations/task.mjs.map +1 -1
- package/dist/migrations/useMigrations.mjs +3 -12
- package/dist/migrations/useMigrations.mjs.map +1 -1
- package/dist/module/internal/reload.mjs.map +1 -1
- package/dist/module/internal/rollup.mjs.map +1 -1
- package/dist/module/internal/types.mjs +11 -9
- package/dist/module/internal/types.mjs.map +1 -1
- package/dist/module/utils/assets.d.mts +2 -1
- package/dist/module/utils/assets.mjs.map +1 -1
- package/dist/module/utils/externals.d.mts +1 -0
- package/dist/module/utils/externals.mjs +6 -1
- package/dist/module/utils/externals.mjs.map +1 -1
- package/dist/module/utils/nitro.d.mts +7 -0
- package/dist/module/utils/nitro.mjs +8 -0
- package/dist/module/utils/nitro.mjs.map +1 -0
- package/dist/module.d.mts +10 -3
- package/dist/module.mjs +26 -10
- package/dist/module.mjs.map +1 -1
- package/dist/plugins/init.d.mts +3 -12
- package/dist/plugins/init.mjs +3 -23
- package/dist/plugins/init.mjs.map +1 -1
- package/dist/plugins/legacy/init.d.mts +24 -0
- package/dist/plugins/legacy/init.mjs +33 -0
- package/dist/plugins/legacy/init.mjs.map +1 -0
- package/dist/plugins/legacy/migrate.d.mts +21 -0
- package/dist/plugins/legacy/migrate.mjs +25 -0
- package/dist/plugins/legacy/migrate.mjs.map +1 -0
- package/dist/plugins/migrate.d.mts +2 -2
- package/dist/plugins/migrate.mjs +9 -4
- package/dist/plugins/migrate.mjs.map +1 -1
- package/dist/runtime/internal/config.mjs +3 -3
- package/dist/runtime/internal/config.mjs.map +1 -1
- package/dist/runtime/useDatasource.mjs +11 -7
- package/dist/runtime/useDatasource.mjs.map +1 -1
- package/dist/runtime.d.mts +9 -1
- package/package.json +6 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async.mjs","names":[],"sources":["../../../src/context/internal/async.ts"],"sourcesContent":["export type MaybeAsyncIterable<T> = Iterable<T> | AsyncIterable<T>;\n\nasync function* generateAsync<T, U>(\n iterable: MaybeAsyncIterable<T>,\n cb: (value: T, index: number) => Promise<U>,\n) {\n let index = 0;\n for await (const value of iterable) {\n yield await cb(value, index++);\n }\n}\n\nexport async function mapAsync<T, U>(\n iterable: MaybeAsyncIterable<T>,\n cb: (value: T, index: number) => Promise<U>,\n) {\n const generator = generateAsync(iterable, cb);\n const items: U[] = [];\n for await (const item of generator) {\n items.push(item);\n }\n return items;\n}\n
|
|
1
|
+
{"version":3,"file":"async.mjs","names":[],"sources":["../../../src/context/internal/async.ts"],"sourcesContent":["export type MaybeAsyncIterable<T> = Iterable<T> | AsyncIterable<T>;\n\nasync function* generateAsync<T, U>(\n iterable: MaybeAsyncIterable<T>,\n cb: (value: T, index: number) => Promise<U>,\n) {\n let index = 0;\n for await (const value of iterable) {\n yield await cb(value, index++);\n }\n}\n\nexport async function mapAsync<T, U>(\n iterable: MaybeAsyncIterable<T>,\n cb: (value: T, index: number) => Promise<U>,\n) {\n const generator = generateAsync(iterable, cb);\n const items: U[] = [];\n for await (const item of generator) {\n items.push(item);\n }\n return items;\n}\n"],"mappings":";AAEA,gBAAgB,cACd,UACA,IACA;CACA,IAAI,QAAQ;CACZ,WAAW,MAAM,SAAS,UACxB,MAAM,MAAM,GAAG,OAAO,OAAO;AAEjC;AAEA,eAAsB,SACpB,UACA,IACA;CACA,MAAM,YAAY,cAAc,UAAU,EAAE;CAC5C,MAAM,QAAa,CAAC;CACpB,WAAW,MAAM,QAAQ,WACvB,MAAM,KAAK,IAAI;CAEjB,OAAO;AACT"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { script } from "./format.mjs";
|
|
1
2
|
import { genArrayFromRaw, genExport, genImport, genObjectFromRaw, genObjectFromRawEntries, genSafeVariableName, genString } from "knitwork";
|
|
2
3
|
//#region src/context/internal/virtual.ts
|
|
3
4
|
function genDatasourceModuleVariableName(dbModuleIndex) {
|
|
@@ -14,8 +15,8 @@ function mergeSchemaModules(schemaIds, dbModuleIndex) {
|
|
|
14
15
|
)
|
|
15
16
|
`;
|
|
16
17
|
}
|
|
17
|
-
function runtimeVirtualModule(datasources) {
|
|
18
|
-
const
|
|
18
|
+
function runtimeVirtualModule(datasources, { legacyNitro, runtimeConfigProp }) {
|
|
19
|
+
const datasourceRegistryParts = datasources.filter((datasource) => datasource.enabled).map(({ name, imports: { schema, connector } }, datasourceIndex) => {
|
|
19
20
|
const datasourceModuleVariableName = genDatasourceModuleVariableName(datasourceIndex);
|
|
20
21
|
const imports = [genImport(connector, datasourceModuleVariableName), ...schema.map((schemaModuleId, schemaIndex) => {
|
|
21
22
|
return genImport(schemaModuleId, {
|
|
@@ -44,16 +45,48 @@ function runtimeVirtualModule(datasources) {
|
|
|
44
45
|
entries: []
|
|
45
46
|
});
|
|
46
47
|
const datasourceRegistryVarName = genSafeVariableName("datasourceRegistry");
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
const nitroRuntimeParts = {
|
|
49
|
+
imports: [legacyNitro ? genImport("nitropack/runtime", ["useNitroApp"]) : genImport("nitro/app", ["useNitroHooks"]), genImport(legacyNitro ? "nitropack/runtime" : "nitro/runtime-config", [{
|
|
50
|
+
name: "useRuntimeConfig",
|
|
51
|
+
as: "useNitroRuntimeConfig"
|
|
52
|
+
}])],
|
|
53
|
+
declarations: [script`
|
|
54
|
+
export function useRuntimeConfig() {
|
|
55
|
+
const runtimeConfig = useNitroRuntimeConfig();
|
|
56
|
+
return runtimeConfig[${genString(runtimeConfigProp)}]
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
${legacyNitro ? script`
|
|
60
|
+
function useNitroHooks() {
|
|
61
|
+
return useNitroApp().hooks;
|
|
62
|
+
}
|
|
63
|
+
` : ""}
|
|
64
|
+
|
|
65
|
+
export function onServerClose(cb) {
|
|
66
|
+
return useNitroHooks().hook("close", cb);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function callConfigHook(name, config) {
|
|
70
|
+
return useNitroHooks().callHook("drizzle:config", name, config);
|
|
71
|
+
}
|
|
72
|
+
`],
|
|
73
|
+
exports: [genExport(legacyNitro ? "nitropack/runtime" : "nitro/storage", ["useStorage"])]
|
|
74
|
+
};
|
|
75
|
+
return script`
|
|
76
|
+
${datasourceRegistryParts.imports.join("\n")}
|
|
77
|
+
${nitroRuntimeParts.imports.join("\n")}
|
|
49
78
|
|
|
50
|
-
${
|
|
79
|
+
${datasourceRegistryParts.schemaDefinitions.join("\n")}
|
|
51
80
|
|
|
52
|
-
const ${datasourceRegistryVarName} = ${genObjectFromRawEntries(
|
|
81
|
+
const ${datasourceRegistryVarName} = ${genObjectFromRawEntries(datasourceRegistryParts.entries)};
|
|
53
82
|
|
|
54
83
|
export function useDatasourceRegistry() {
|
|
55
84
|
return ${datasourceRegistryVarName};
|
|
56
85
|
}
|
|
86
|
+
|
|
87
|
+
${nitroRuntimeParts.declarations.join("\n")}
|
|
88
|
+
|
|
89
|
+
${nitroRuntimeParts.exports.join("\n")}
|
|
57
90
|
`;
|
|
58
91
|
}
|
|
59
92
|
function dialectVirtualModules(datasources) {
|
|
@@ -72,7 +105,7 @@ function migrationsVirtualModule(datasources, options) {
|
|
|
72
105
|
`);
|
|
73
106
|
let migrateOnInit = enabledDatasources.map((d) => d.name);
|
|
74
107
|
if (options && Array.isArray(options.migrateOnInit)) migrateOnInit = migrateOnInit.filter((name) => options.migrateOnInit.includes(name));
|
|
75
|
-
parts.push(`
|
|
108
|
+
parts.push(script`
|
|
76
109
|
export const MIGRATIONS_STORAGE_BASE = ${genString(options.storageBase)};
|
|
77
110
|
export const MIGRATE_ON_INIT = ${genArrayFromRaw(migrateOnInit.map((name) => genString(name)))};
|
|
78
111
|
`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual.mjs","names":[],"sources":["../../../src/context/internal/virtual.ts"],"sourcesContent":["import {\n genArrayFromRaw,\n genExport,\n genImport,\n genObjectFromRaw,\n genObjectFromRawEntries,\n genSafeVariableName,\n genString,\n} from \"knitwork\";\nimport type { DatasourceInfo, MigrationOptions } from \"..\";\nimport type { VirtualModules } from \"nitro-drizzle/shared\";\n\nfunction genDatasourceModuleVariableName(dbModuleIndex: number) {\n return genSafeVariableName(`dbModule${dbModuleIndex}`);\n}\n\nfunction genMergedSchemaVariableName(dbModuleIndex: number) {\n return genSafeVariableName(`mergedSchema${dbModuleIndex}`);\n}\n\nconst genSchemaModuleVariableName = (dbModuleIndex: number, schemaIndex: number) =>\n genSafeVariableName(`schemaModule${dbModuleIndex}_${schemaIndex}`);\n\nfunction mergeSchemaModules(schemaIds: string[], dbModuleIndex: number) {\n return /* js */ `\n Object.assign(\n ${[\n /* js */ `{}`,\n ...schemaIds.map((_, schemaModuleIdIndex) =>\n genSchemaModuleVariableName(dbModuleIndex, schemaModuleIdIndex),\n ),\n ].join(\",\")}\n )\n `;\n}\n\nexport function runtimeVirtualModule(datasources: readonly DatasourceInfo[]) {\n const
|
|
1
|
+
{"version":3,"file":"virtual.mjs","names":[],"sources":["../../../src/context/internal/virtual.ts"],"sourcesContent":["import {\n genArrayFromRaw,\n genExport,\n genImport,\n genObjectFromRaw,\n genObjectFromRawEntries,\n genSafeVariableName,\n genString,\n} from \"knitwork\";\nimport type { DatasourceInfo, MigrationOptions } from \"..\";\nimport type { VirtualModules } from \"nitro-drizzle/shared\";\nimport { script } from \"./format\";\n\nfunction genDatasourceModuleVariableName(dbModuleIndex: number) {\n return genSafeVariableName(`dbModule${dbModuleIndex}`);\n}\n\nfunction genMergedSchemaVariableName(dbModuleIndex: number) {\n return genSafeVariableName(`mergedSchema${dbModuleIndex}`);\n}\n\nconst genSchemaModuleVariableName = (dbModuleIndex: number, schemaIndex: number) =>\n genSafeVariableName(`schemaModule${dbModuleIndex}_${schemaIndex}`);\n\nfunction mergeSchemaModules(schemaIds: string[], dbModuleIndex: number) {\n return /* js */ `\n Object.assign(\n ${[\n /* js */ `{}`,\n ...schemaIds.map((_, schemaModuleIdIndex) =>\n genSchemaModuleVariableName(dbModuleIndex, schemaModuleIdIndex),\n ),\n ].join(\",\")}\n )\n `;\n}\n\nexport function runtimeVirtualModule(\n datasources: readonly DatasourceInfo[],\n { legacyNitro, runtimeConfigProp }: { legacyNitro: boolean; runtimeConfigProp: string },\n) {\n const datasourceRegistryParts = datasources\n .filter((datasource) => datasource.enabled)\n .map(({ name, imports: { schema, connector } }, datasourceIndex) => {\n const datasourceModuleVariableName = genDatasourceModuleVariableName(datasourceIndex);\n\n const imports = [\n genImport(connector, datasourceModuleVariableName),\n ...schema.map((schemaModuleId, schemaIndex) => {\n return genImport(schemaModuleId, {\n name: \"*\",\n as: genSchemaModuleVariableName(datasourceIndex, schemaIndex),\n });\n }),\n ];\n\n const mergedSchemaVariableName = genMergedSchemaVariableName(datasourceIndex);\n const mergedSchemaObject = mergeSchemaModules(schema, datasourceIndex);\n\n const schemaDefinitions = [\n /* js */ `const ${mergedSchemaVariableName} = ${mergedSchemaObject};`,\n ];\n\n const entries: [string, string][] = [\n [\n name,\n genObjectFromRaw({\n create: /* js */ `(config) => ${datasourceModuleVariableName}(config, ${mergedSchemaVariableName})`,\n schema: mergedSchemaVariableName,\n }),\n ],\n ];\n\n return {\n imports,\n schemaDefinitions,\n entries,\n };\n })\n .reduce(\n (acc, { imports, schemaDefinitions, entries }) => {\n return {\n imports: [...acc.imports, ...imports],\n schemaDefinitions: [...acc.schemaDefinitions, ...schemaDefinitions],\n entries: [...acc.entries, ...entries],\n };\n },\n {\n imports: [] as string[],\n schemaDefinitions: [] as string[],\n entries: [] as [string, string][],\n },\n );\n\n const datasourceRegistryVarName = genSafeVariableName(\"datasourceRegistry\");\n\n const nitroRuntimeParts = {\n imports: [\n legacyNitro\n ? genImport(\"nitropack/runtime\", [\"useNitroApp\"])\n : genImport(\"nitro/app\", [\"useNitroHooks\"]),\n genImport(legacyNitro ? \"nitropack/runtime\" : \"nitro/runtime-config\", [\n {\n name: \"useRuntimeConfig\",\n as: \"useNitroRuntimeConfig\",\n },\n ]),\n ],\n declarations: [\n script /* js */ `\n export function useRuntimeConfig() {\n const runtimeConfig = useNitroRuntimeConfig();\n return runtimeConfig[${genString(runtimeConfigProp)}]\n }\n\n ${\n legacyNitro\n ? script /* js */ `\n function useNitroHooks() {\n return useNitroApp().hooks;\n }\n `\n : \"\"\n }\n\n export function onServerClose(cb) {\n return useNitroHooks().hook(\"close\", cb);\n }\n\n export function callConfigHook(name, config) {\n return useNitroHooks().callHook(\"drizzle:config\", name, config);\n }\n `,\n ],\n exports: [genExport(legacyNitro ? \"nitropack/runtime\" : \"nitro/storage\", [\"useStorage\"])],\n };\n\n return script /* js */ `\n ${datasourceRegistryParts.imports.join(\"\\n\")}\n ${nitroRuntimeParts.imports.join(\"\\n\")}\n \n ${datasourceRegistryParts.schemaDefinitions.join(\"\\n\")}\n \n const ${datasourceRegistryVarName} = ${genObjectFromRawEntries(datasourceRegistryParts.entries)};\n\n export function useDatasourceRegistry() {\n return ${datasourceRegistryVarName};\n }\n\n ${nitroRuntimeParts.declarations.join(\"\\n\")}\n\n ${nitroRuntimeParts.exports.join(\"\\n\")}\n `;\n}\n\n// Replaced with aliases\nexport function dialectVirtualModules(\n datasources: readonly DatasourceInfo[],\n): VirtualModules<`#nitro-drizzle/${string}`> {\n return Object.fromEntries(\n datasources\n .filter((d) => d.enabled)\n .map(({ name, dialect }) => {\n return [\n `#nitro-drizzle/dialects/${name}`,\n genExport(`nitro-drizzle/dialects/${dialect}`, \"*\"),\n ] as const;\n }),\n );\n}\n\nexport function migrationsVirtualModule(\n datasources: readonly DatasourceInfo[],\n options: MigrationOptions | undefined,\n): VirtualModules<`#nitro-drizzle/${string}`> {\n if (!options) {\n return {};\n }\n\n const parts: string[] = [];\n\n const enabledDatasources = datasources.filter((d) => d.enabled);\n\n parts.push(/*js*/ `\n export const migrationConfig = ${genObjectFromRawEntries(\n enabledDatasources.map(({ name, migrations }) => {\n return [name, JSON.stringify(migrations.config)];\n }),\n )};\n `);\n\n let migrateOnInit = enabledDatasources.map((d) => d.name);\n if (options && Array.isArray(options.migrateOnInit)) {\n migrateOnInit = migrateOnInit.filter((name) =>\n (options.migrateOnInit as readonly string[]).includes(name),\n );\n }\n\n parts.push(script /*js*/ `\n export const MIGRATIONS_STORAGE_BASE = ${genString(options.storageBase)};\n export const MIGRATE_ON_INIT = ${genArrayFromRaw(migrateOnInit.map((name) => genString(name)))};\n `);\n\n return {\n \"#nitro-drizzle/migrations\": parts.join(\"\\n\"),\n };\n}\n"],"mappings":";;;AAaA,SAAS,gCAAgC,eAAuB;CAC9D,OAAO,oBAAoB,WAAW,eAAe;AACvD;AAEA,SAAS,4BAA4B,eAAuB;CAC1D,OAAO,oBAAoB,eAAe,eAAe;AAC3D;AAEA,MAAM,+BAA+B,eAAuB,gBAC1D,oBAAoB,eAAe,cAAc,GAAG,aAAa;AAEnE,SAAS,mBAAmB,WAAqB,eAAuB;CACtE,OAAgB;;QAEV,CACS,MACT,GAAG,UAAU,KAAK,GAAG,wBACnB,4BAA4B,eAAe,mBAAmB,CAChE,CACF,CAAC,CAAC,KAAK,GAAG,EAAE;;;AAGlB;AAEA,SAAgB,qBACd,aACA,EAAE,aAAa,qBACf;CACA,MAAM,0BAA0B,YAC7B,QAAQ,eAAe,WAAW,OAAO,CAAC,CAC1C,KAAK,EAAE,MAAM,SAAS,EAAE,QAAQ,eAAe,oBAAoB;EAClE,M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Options {
|
|
41
|
+
legacy: boolean;
|
|
41
42
|
logger?: ConsolaInstance;
|
|
42
43
|
/**
|
|
43
44
|
* Current working directory
|
|
@@ -58,7 +59,7 @@ interface ContextOptions {
|
|
|
58
59
|
/**
|
|
59
60
|
* Connector options
|
|
60
61
|
*/
|
|
61
|
-
|
|
62
|
+
datasources: Record<string, {
|
|
62
63
|
connector: string;
|
|
63
64
|
}>;
|
|
64
65
|
migrations: MigrationOptions | undefined;
|
|
@@ -74,7 +75,7 @@ interface ContextOptions {
|
|
|
74
75
|
}]>;
|
|
75
76
|
virtualModules: ContextHook<[modules: VirtualModules]>;
|
|
76
77
|
assets: ContextHook<[assets: readonly ServerAssetDir[]]>;
|
|
77
|
-
|
|
78
|
+
externals?: ContextHook<[modules: readonly string[]]>;
|
|
78
79
|
}
|
|
79
80
|
/**
|
|
80
81
|
* Creates a Context instance for managing Drizzle datasource configurations.
|
package/dist/context.mjs
CHANGED
|
@@ -38,7 +38,7 @@ var DefaultContext = class {
|
|
|
38
38
|
handler: "nitro-drizzle/migrations/task"
|
|
39
39
|
} });
|
|
40
40
|
}
|
|
41
|
-
if (this.#options.
|
|
41
|
+
if (this.#options.externals) {
|
|
42
42
|
const inlineModuleIds = [
|
|
43
43
|
"runtime",
|
|
44
44
|
"plugins",
|
|
@@ -46,11 +46,11 @@ var DefaultContext = class {
|
|
|
46
46
|
].flatMap((id) => {
|
|
47
47
|
return [join(pkgName, id), join(pkgDir, "dist", id)];
|
|
48
48
|
});
|
|
49
|
-
await this.#options.
|
|
49
|
+
await this.#options.externals(inlineModuleIds);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
async datasources() {
|
|
53
|
-
const { logger, baseDir, configPattern, resolver,
|
|
53
|
+
const { logger, baseDir, configPattern, resolver, datasources: datasourceOptions } = this.#options;
|
|
54
54
|
if (!this.#datasources) {
|
|
55
55
|
logger?.info("Searching drizzle datasources in", colorize("blue", baseDir));
|
|
56
56
|
let datasources = await mapAsync(await resolveFiles(baseDir, [configPattern].flat().map((pattern) => "*/" + pattern)), async (path) => {
|
|
@@ -108,23 +108,31 @@ var DefaultContext = class {
|
|
|
108
108
|
const migrationOptions = this.#options.migrations;
|
|
109
109
|
if (migrationOptions ? Array.isArray(migrationOptions) ? 0 < migrationOptions.length : true == migrationOptions.migrateOnInit : false) plugins.push("migrate");
|
|
110
110
|
plugins.push("init");
|
|
111
|
-
|
|
111
|
+
let pluginIds = plugins;
|
|
112
|
+
if (this.#options.legacy) pluginIds = pluginIds.map((pluginName) => `legacy/${pluginName}`);
|
|
113
|
+
pluginIds = pluginIds.map((pluginName) => `nitro-drizzle/plugins/${pluginName}`);
|
|
114
|
+
return pluginIds;
|
|
112
115
|
}
|
|
113
116
|
async moduleTypeDeclarations(datasources) {
|
|
114
117
|
return moduleTypeDeclarations(datasources);
|
|
115
118
|
}
|
|
116
119
|
async runtimeTypeDeclarations(datasources) {
|
|
120
|
+
const references = /* @__PURE__ */ new Set([{ types: "nitro-drizzle/runtime" }, ...this.enabledPlugins().map((pluginId) => {
|
|
121
|
+
return { types: pluginId };
|
|
122
|
+
})]);
|
|
123
|
+
if (!this.#options.legacy) references.add({ types: "nitro-drizzle/middleware/context" });
|
|
117
124
|
return { "nitro-drizzle/runtime.d.ts": [
|
|
118
|
-
...[...
|
|
119
|
-
return { types: pluginId };
|
|
120
|
-
})])).values()].map((reference) => genReference(reference)),
|
|
125
|
+
...[...references.values()].map((reference) => genReference(reference)),
|
|
121
126
|
runtimeDeclarations(datasources),
|
|
122
127
|
`export {};`
|
|
123
128
|
].join("\n") };
|
|
124
129
|
}
|
|
125
130
|
async virtualModules(datasources) {
|
|
126
131
|
return {
|
|
127
|
-
"#nitro-drizzle/runtime": runtimeVirtualModule(datasources
|
|
132
|
+
"#nitro-drizzle/runtime": runtimeVirtualModule(datasources, {
|
|
133
|
+
legacyNitro: this.#options.legacy,
|
|
134
|
+
runtimeConfigProp: "drizzle"
|
|
135
|
+
}),
|
|
128
136
|
...dialectVirtualModules(datasources),
|
|
129
137
|
...migrationsVirtualModule(datasources, this.#options.migrations)
|
|
130
138
|
};
|
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\";\nimport { loadConfig } from \"c12\";\nimport { pkgDir, pkgName } from \"nitro-drizzle/meta\";\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 {\n dialectVirtualModules,\n migrationsVirtualModule,\n runtimeVirtualModule,\n} from \"./internal/virtual\";\n\nimport type { MaybePromise, VirtualModules } from \"nitro-drizzle/shared\";\nimport type { ServerAssetDir } from \"nitropack/types\";\nimport { join } from \"pathe\";\n\n/**\n * Context interface for managing Drizzle datasource configurations.\n */\nexport interface Context {\n init(): MaybePromise<void>;\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\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 init(): Promise<void> {\n const datasources = await this.datasources();\n\n await this.#options.plugins(this.enabledPlugins());\n\n const [virtualModules, virtualTypes, moduleTypes, runtimeTypes] = await Promise.all([\n this.virtualModules(datasources),\n this.virtualTypeDeclarations(datasources),\n this.moduleTypeDeclarations(datasources),\n this.runtimeTypeDeclarations(datasources),\n ]);\n\n await this.#options.virtualModules(virtualModules);\n\n await this.#options.declarations({\n virtual: virtualTypes,\n module: moduleTypes,\n runtime: runtimeTypes,\n });\n\n if (this.#options.migrations) {\n const assets = await this.migrationAssets(datasources);\n if (assets) {\n await this.#options.assets(assets);\n }\n\n await this.#options.tasks?.({\n \"drizzle:migrate\": {\n description: \"Run drizzle migrations for a datasource.\",\n handler: \"nitro-drizzle/migrations/task\",\n },\n });\n }\n\n if (this.#options.inlineExternals) {\n const inlineModuleIds = [\"runtime\", \"plugins\", \"migrations\"].flatMap((id) => {\n return [join(pkgName, id), join(pkgDir, \"dist\", id)];\n });\n\n await this.#options.inlineExternals(inlineModuleIds);\n }\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 private async migrationAssets(\n datasources: readonly DatasourceInfo[],\n ): Promise<readonly ServerAssetDir[]> {\n const migrationOptions = this.#options.migrations;\n\n if (!migrationOptions) {\n return [];\n }\n\n return datasources.reduce((acc, { name, migrations }) => {\n const dir = migrations.assets;\n if (dir) {\n acc.push({\n baseName: `${migrationOptions.storageBase}:${name}`,\n dir,\n /**\n * @todo Doesn't work in dev mode - 'fs' driver does not support 'pattern'\n * Disabled - include all files to use with meta/_journal.json\n */\n // pattern: '*.sql',\n });\n }\n return acc;\n }, [] as ServerAssetDir[]);\n }\n\n private async virtualTypeDeclarations(\n datasources: readonly DatasourceInfo[],\n ): Promise<Record<string, VirtualModules<`${string}.d.ts`>>> {\n return {\n \"#nitro-drizzle/*\": {\n \"nitro-drizzle/virtual.d.ts\": [dialectDeclarations(datasources)].join(\"\\n\"),\n },\n };\n }\n\n private enabledPlugins(): readonly string[] {\n const plugins: (\"init\" | \"migrate\")[] = [];\n\n const migrationOptions = this.#options.migrations;\n const enableMigrationPlugin = migrationOptions\n ? Array.isArray(migrationOptions)\n ? 0 < migrationOptions.length\n : true == migrationOptions.migrateOnInit\n : false;\n\n if (enableMigrationPlugin) {\n plugins.push(\"migrate\");\n }\n\n plugins.push(\"init\");\n\n const pluginIds = plugins.map((pluginName) => `nitro-drizzle/plugins/${pluginName}`);\n\n return pluginIds;\n }\n\n private async moduleTypeDeclarations(\n datasources: readonly DatasourceInfo[],\n ): Promise<VirtualModules> {\n return moduleTypeDeclarations(datasources);\n }\n\n private async runtimeTypeDeclarations(\n datasources: readonly DatasourceInfo[],\n ): Promise<VirtualModules<`${string}.d.ts`>> {\n const references = new Set([\n { types: \"nitro-drizzle/runtime\" },\n ...this.enabledPlugins().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 private async virtualModules(\n datasources: readonly DatasourceInfo[],\n ): Promise<VirtualModules<`#nitro-drizzle/${string}`>> {\n return {\n \"#nitro-drizzle/runtime\": runtimeVirtualModule(datasources),\n ...dialectVirtualModules(datasources),\n ...migrationsVirtualModule(datasources, this.#options.migrations),\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\nexport type ContextHook<TArgs extends readonly any[] = []> = (\n this: void,\n ...args: TArgs\n) => MaybePromise<void>;\n\nexport interface MigrationOptions {\n /** Base storage key path for migrations. */\n storageBase: string;\n /** Whether and which datasources to migrate on initialization. */\n migrateOnInit: boolean | readonly string[];\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 migrations: MigrationOptions | undefined;\n\n tasks?: ContextHook<\n [\n tasks: Record<\n string,\n {\n handler: string;\n description: string;\n }\n >,\n ]\n >;\n\n plugins: ContextHook<[plugins: readonly string[]]>;\n\n declarations: ContextHook<\n [\n declarations: {\n module: VirtualModules<`${string}.d.ts`>;\n runtime: VirtualModules<`${string}.d.ts`>;\n virtual: Record<string, VirtualModules<`${string}.d.ts`>>;\n },\n ]\n >;\n\n virtualModules: ContextHook<[modules: VirtualModules]>;\n\n assets: ContextHook<[assets: readonly ServerAssetDir[]]>;\n\n inlineExternals?: ContextHook<[modules: 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,OAAsB;EAC1B,MAAM,cAAc,MAAM,KAAK,YAAY;EAE3C,MAAM,KAAKA,SAAS,QAAQ,KAAK,eAAe,CAAC;EAEjD,MAAM,CAAC,gBAAgB,cAAc,aAAa,gBAAgB,MAAM,QAAQ,IAAI;GAClF,KAAK,eAAe,WAAW;GAC/B,KAAK,wBAAwB,WAAW;GACxC,KAAK,uBAAuB,WAAW;GACvC,KAAK,wBAAwB,WAAW;EAC1C,CAAC;EAED,MAAM,KAAKA,SAAS,eAAe,cAAc;EAEjD,MAAM,KAAKA,SAAS,aAAa;GAC/B,SA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MAAM,UAAkC,CAAC;EAEzC,MAAM,mBAAmB,KAAKA,SAAS;EAOvC,IAN8B,mBAC1B,MAAM,QAAQ,gBAAgB,IAC5B,IAAI,iBAAiB,SACrB,QAAQ,iBAAiB,gBAC3B,OAGF,QAAQ,KAAK,SAAS;EAGxB,QAAQ,KAAK,MAAM;EAInB,OAFkB,QAAQ,KAAK,eAAe,yBAAyB,YAExD;CACjB;CAEA,MAAc,uBACZ,aACyB;EACzB,OAAO,uBAAuB,WAAW;CAC3C;CAEA,MAAc,wBACZ,aAC2C;EAY3C,OAAO,EACL,8BANc;GACd,GAAG,CAAC,oBAAG,IAPc,IAAI,CACzB,EAAE,OAAO,wBAAwB,GACjC,GAAG,KAAK,eAAe,CAAC,CAAC,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,MAAc,eACZ,aACqD;EACrD,OAAO;GACL,0BAA0B,qBAAqB,WAAW;GAC1D,GAAG,sBAAsB,WAAW;GACpC,GAAG,wBAAwB,aAAa,KAAKA,SAAS,UAAU;EAClE;CACF;CAEA,SAAS;EACP,KAAKC,eAAe;CACtB;AACF;;;;;;AA0FA,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\";\nimport { pkgDir, pkgName } from \"nitro-drizzle/meta\";\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 {\n dialectVirtualModules,\n migrationsVirtualModule,\n runtimeVirtualModule,\n} from \"./internal/virtual\";\n\nimport type { MaybePromise, VirtualModules } from \"nitro-drizzle/shared\";\nimport type { ServerAssetDir } from \"nitropack/types\";\nimport { join } from \"pathe\";\n\n/**\n * Context interface for managing Drizzle datasource configurations.\n */\nexport interface Context {\n init(): MaybePromise<void>;\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\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 init(): Promise<void> {\n const datasources = await this.datasources();\n\n await this.#options.plugins(this.enabledPlugins());\n\n const [virtualModules, virtualTypes, moduleTypes, runtimeTypes] = await Promise.all([\n this.virtualModules(datasources),\n this.virtualTypeDeclarations(datasources),\n this.moduleTypeDeclarations(datasources),\n this.runtimeTypeDeclarations(datasources),\n ]);\n\n await this.#options.virtualModules(virtualModules);\n\n await this.#options.declarations({\n virtual: virtualTypes,\n module: moduleTypes,\n runtime: runtimeTypes,\n });\n\n if (this.#options.migrations) {\n const assets = await this.migrationAssets(datasources);\n if (assets) {\n await this.#options.assets(assets);\n }\n\n await this.#options.tasks?.({\n \"drizzle:migrate\": {\n description: \"Run drizzle migrations for a datasource.\",\n handler: \"nitro-drizzle/migrations/task\",\n },\n });\n }\n\n if (this.#options.externals) {\n const inlineModuleIds = [\"runtime\", \"plugins\", \"migrations\"].flatMap((id) => {\n return [join(pkgName, id), join(pkgDir, \"dist\", id)];\n });\n\n await this.#options.externals(inlineModuleIds);\n }\n }\n\n async datasources() {\n const {\n logger,\n baseDir,\n configPattern,\n resolver,\n datasources: 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 private async migrationAssets(\n datasources: readonly DatasourceInfo[],\n ): Promise<readonly ServerAssetDir[]> {\n const migrationOptions = this.#options.migrations;\n\n if (!migrationOptions) {\n return [];\n }\n\n return datasources.reduce((acc, { name, migrations }) => {\n const dir = migrations.assets;\n if (dir) {\n acc.push({\n baseName: `${migrationOptions.storageBase}:${name}`,\n dir,\n /**\n * @todo Doesn't work in dev mode - 'fs' driver does not support 'pattern'\n * Disabled - include all files to use with meta/_journal.json\n */\n // pattern: '*.sql',\n });\n }\n return acc;\n }, [] as ServerAssetDir[]);\n }\n\n private async virtualTypeDeclarations(\n datasources: readonly DatasourceInfo[],\n ): Promise<Record<string, VirtualModules<`${string}.d.ts`>>> {\n return {\n \"#nitro-drizzle/*\": {\n \"nitro-drizzle/virtual.d.ts\": [dialectDeclarations(datasources)].join(\"\\n\"),\n },\n };\n }\n\n private enabledPlugins(): readonly string[] {\n const plugins: (\"init\" | \"migrate\")[] = [];\n\n const migrationOptions = this.#options.migrations;\n const enableMigrationPlugin = migrationOptions\n ? Array.isArray(migrationOptions)\n ? 0 < migrationOptions.length\n : true == migrationOptions.migrateOnInit\n : false;\n\n if (enableMigrationPlugin) {\n plugins.push(\"migrate\");\n }\n\n plugins.push(\"init\");\n\n let pluginIds: readonly string[] = plugins;\n if (this.#options.legacy) {\n pluginIds = pluginIds.map((pluginName) => `legacy/${pluginName}`);\n }\n pluginIds = pluginIds.map((pluginName) => `nitro-drizzle/plugins/${pluginName}`);\n\n return pluginIds;\n }\n\n private async moduleTypeDeclarations(\n datasources: readonly DatasourceInfo[],\n ): Promise<VirtualModules> {\n return moduleTypeDeclarations(datasources);\n }\n\n private async runtimeTypeDeclarations(\n datasources: readonly DatasourceInfo[],\n ): Promise<VirtualModules<`${string}.d.ts`>> {\n const references = new Set([\n { types: \"nitro-drizzle/runtime\" },\n ...this.enabledPlugins().map((pluginId) => {\n return { types: pluginId };\n }),\n ]);\n if (!this.#options.legacy) {\n references.add({ types: \"nitro-drizzle/middleware/context\" });\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 private async virtualModules(\n datasources: readonly DatasourceInfo[],\n ): Promise<VirtualModules<`#nitro-drizzle/${string}`>> {\n return {\n \"#nitro-drizzle/runtime\": runtimeVirtualModule(datasources, {\n legacyNitro: this.#options.legacy,\n runtimeConfigProp: \"drizzle\",\n }),\n ...dialectVirtualModules(datasources),\n ...migrationsVirtualModule(datasources, this.#options.migrations),\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\nexport type ContextHook<TArgs extends readonly any[] = []> = (\n this: void,\n ...args: TArgs\n) => MaybePromise<void>;\n\nexport interface MigrationOptions {\n /** Base storage key path for migrations. */\n storageBase: string;\n /** Whether and which datasources to migrate on initialization. */\n migrateOnInit: boolean | readonly string[];\n}\n\nexport interface ContextOptions {\n legacy: boolean;\n\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 datasources: Record<string, { connector: string }>;\n\n migrations: MigrationOptions | undefined;\n\n tasks?: ContextHook<\n [\n tasks: Record<\n string,\n {\n handler: string;\n description: string;\n }\n >,\n ]\n >;\n\n plugins: ContextHook<[plugins: readonly string[]]>;\n\n declarations: ContextHook<\n [\n declarations: {\n module: VirtualModules<`${string}.d.ts`>;\n runtime: VirtualModules<`${string}.d.ts`>;\n virtual: Record<string, VirtualModules<`${string}.d.ts`>>;\n },\n ]\n >;\n\n virtualModules: ContextHook<[modules: VirtualModules]>;\n\n assets: ContextHook<[assets: readonly ServerAssetDir[]]>;\n\n externals?: ContextHook<[modules: 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,OAAsB;EAC1B,MAAM,cAAc,MAAM,KAAK,YAAY;EAE3C,MAAM,KAAKA,SAAS,QAAQ,KAAK,eAAe,CAAC;EAEjD,MAAM,CAAC,gBAAgB,cAAc,aAAa,gBAAgB,MAAM,QAAQ,IAAI;GAClF,KAAK,eAAe,WAAW;GAC/B,KAAK,wBAAwB,WAAW;GACxC,KAAK,uBAAuB,WAAW;GACvC,KAAK,wBAAwB,WAAW;EAC1C,CAAC;EAED,MAAM,KAAKA,SAAS,eAAe,cAAc;EAEjD,MAAM,KAAKA,SAAS,aAAa;GAC/B,SAAS;GACT,QAAQ;GACR,SAAS;EACX,CAAC;EAED,IAAI,KAAKA,SAAS,YAAY;GAC5B,MAAM,SAAS,MAAM,KAAK,gBAAgB,WAAW;GACrD,IAAI,QACF,MAAM,KAAKA,SAAS,OAAO,MAAM;GAGnC,MAAM,KAAKA,SAAS,QAAQ,EAC1B,mBAAmB;IACjB,aAAa;I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C,IAAI,KAAKA,SAAS,QAChB,YAAY,UAAU,KAAK,eAAe,UAAU,YAAY;EAElE,YAAY,UAAU,KAAK,eAAe,yBAAyB,YAAY;EAE/E,OAAO;CACT;CAEA,MAAc,uBACZ,aACyB;EACzB,OAAO,uBAAuB,WAAW;CAC3C;CAEA,MAAc,wBACZ,aAC2C;EAC3C,MAAM,6BAAa,IAAI,IAAI,CACzB,EAAE,OAAO,wBAAwB,GACjC,GAAG,KAAK,eAAe,CAAC,CAAC,KAAK,aAAa;GACzC,OAAO,EAAE,OAAO,SAAS;EAC3B,CAAC,CACH,CAAC;EACD,IAAI,CAAC,KAAKA,SAAS,QACjB,WAAW,IAAI,EAAE,OAAO,mCAAmC,CAAC;EAO9D,OAAO,EACL,8BANc;GACd,GAAG,CAAC,GAAG,WAAW,OAAO,CAAC,CAAC,CAAC,KAAK,cAAc,aAAa,SAAS,CAAC;GACtE,oBAAoB,WAAW;GACtB;EACX,CAAC,CAAC,KAAK,IAE+B,EACtC;CACF;CAEA,MAAc,eACZ,aACqD;EACrD,OAAO;GACL,0BAA0B,qBAAqB,aAAa;IAC1D,aAAa,KAAKA,SAAS;IAC3B,mBAAmB;GACrB,CAAC;GACD,GAAG,sBAAsB,WAAW;GACpC,GAAG,wBAAwB,aAAa,KAAKA,SAAS,UAAU;EAClE;CACF;CAEA,SAAS;EACP,KAAKC,eAAe;CACtB;AACF;;;;;;AA4FA,SAAgB,cAAc,SAAkC;CAC9D,OAAO,IAAI,eAAe,OAAO;AACnC"}
|
package/dist/meta.d.mts
CHANGED
package/dist/meta.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { URL, fileURLToPath } from "node:url";
|
|
2
|
-
import
|
|
2
|
+
import packageJson from "nitro-drizzle/package.json" with { type: "json" };
|
|
3
3
|
//#region src/meta.ts
|
|
4
|
+
const { name: pkgName } = packageJson;
|
|
4
5
|
/** Directory path of the package. */
|
|
5
6
|
const pkgDir = fileURLToPath(new URL(".", import.meta.resolve("nitro-drizzle/package.json")));
|
|
6
7
|
//#endregion
|
package/dist/meta.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meta.mjs","names":[],"sources":["../src/meta.ts"],"sourcesContent":["import { fileURLToPath, URL } from \"node:url\";\nimport
|
|
1
|
+
{"version":3,"file":"meta.mjs","names":[],"sources":["../src/meta.ts"],"sourcesContent":["import { fileURLToPath, URL } from \"node:url\";\nimport packageJson from \"nitro-drizzle/package.json\" with { type: \"json\" };\n\nconst { name: pkgName } = packageJson;\n\nexport { pkgName };\n\n/** Directory path of the package. */\nexport const pkgDir: string = fileURLToPath(\n new URL(\".\", import.meta.resolve(\"nitro-drizzle/package.json\")),\n);\n"],"mappings":";;;AAGA,MAAM,EAAE,MAAM,YAAY;;AAK1B,MAAa,SAAiB,cAC5B,IAAI,IAAI,KAAK,OAAO,KAAK,QAAQ,4BAA4B,CAAC,CAChE"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Middleware } from "nitro/h3";
|
|
2
|
+
//#region src/middleware/context.d.ts
|
|
3
|
+
declare const middleware: Middleware;
|
|
4
|
+
type ReadyState = "pending" | "done" | "error";
|
|
5
|
+
type InitHooks = {
|
|
6
|
+
"drizzle:init": () => void;
|
|
7
|
+
};
|
|
8
|
+
declare module "nitro/types" {
|
|
9
|
+
interface NitroRuntimeHooks extends InitHooks {}
|
|
10
|
+
}
|
|
11
|
+
interface DrizzleContext {
|
|
12
|
+
readonly readyState: ReadyState;
|
|
13
|
+
readonly waitReady: () => Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
interface EventContext {
|
|
16
|
+
drizzle: DrizzleContext;
|
|
17
|
+
}
|
|
18
|
+
declare module "srvx" {
|
|
19
|
+
interface ServerRequestContext extends EventContext {}
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { DrizzleContext, EventContext, InitHooks, ReadyState, middleware as default };
|
|
23
|
+
//# sourceMappingURL=context.d.mts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { defineMiddleware } from "nitro";
|
|
2
|
+
import { useNitroHooks } from "nitro/app";
|
|
3
|
+
//#region src/middleware/context.ts
|
|
4
|
+
let eventContext;
|
|
5
|
+
const middleware = defineMiddleware((event) => {
|
|
6
|
+
if (!eventContext) {
|
|
7
|
+
const hooks = useNitroHooks();
|
|
8
|
+
let readyState = "pending";
|
|
9
|
+
let initHook;
|
|
10
|
+
initHook = Promise.resolve(hooks.callHook("drizzle:init")).then(() => {
|
|
11
|
+
readyState = "done";
|
|
12
|
+
}).catch((err) => {
|
|
13
|
+
readyState = "error";
|
|
14
|
+
throw err;
|
|
15
|
+
});
|
|
16
|
+
eventContext = {
|
|
17
|
+
get readyState() {
|
|
18
|
+
return readyState;
|
|
19
|
+
},
|
|
20
|
+
waitReady: async () => {
|
|
21
|
+
await initHook;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
event.context.drizzle = eventContext;
|
|
26
|
+
});
|
|
27
|
+
//#endregion
|
|
28
|
+
export { middleware as default };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=context.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.mjs","names":[],"sources":["../../src/middleware/context.ts"],"sourcesContent":["import { defineMiddleware } from \"nitro\";\nimport { useNitroHooks } from \"nitro/app\";\nimport type { Middleware } from \"nitro/h3\";\n\nlet eventContext: DrizzleContext | undefined;\n\nconst middleware: Middleware = defineMiddleware((event): void => {\n if (!eventContext) {\n const hooks = useNitroHooks();\n\n let readyState: ReadyState = \"pending\";\n let initHook: Promise<void>;\n\n initHook = Promise.resolve(hooks.callHook(\"drizzle:init\"))\n .then(() => {\n readyState = \"done\";\n })\n .catch((err) => {\n readyState = \"error\";\n throw err;\n });\n\n eventContext = {\n get readyState() {\n return readyState;\n },\n waitReady: async () => {\n await initHook;\n },\n };\n }\n\n event.context.drizzle = eventContext;\n});\n\nexport default middleware;\n\nexport type ReadyState = \"pending\" | \"done\" | \"error\";\n\nexport type InitHooks = {\n \"drizzle:init\": () => void;\n};\n\ndeclare module \"nitro/types\" {\n interface NitroRuntimeHooks extends InitHooks {}\n}\n\nexport interface DrizzleContext {\n readonly readyState: ReadyState;\n readonly waitReady: () => Promise<void>;\n}\n\nexport interface EventContext {\n drizzle: DrizzleContext;\n}\n\ndeclare module \"srvx\" {\n interface ServerRequestContext extends EventContext {}\n}\n"],"mappings":";;;AAIA,IAAI;AAEJ,MAAM,aAAyB,kBAAkB,UAAgB;CAC/D,IAAI,CAAC,cAAc;EACjB,MAAM,QAAQ,cAAc;EAE5B,IAAI,aAAyB;EAC7B,IAAI;EAEJ,WAAW,QAAQ,QAAQ,MAAM,SAAS,cAAc,CAAC,CAAC,CACvD,WAAW;GACV,aAAa;EACf,CAAC,CAAC,CACD,OAAO,QAAQ;GACd,aAAa;GACb,MAAM;EACR,CAAC;EAEH,eAAe;GACb,IAAI,aAAa;IACf,OAAO;GACT;GACA,WAAW,YAAY;IACrB,MAAM;GACR;EACF;CACF;CAEA,MAAM,QAAQ,UAAU;AAC1B,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { MigrationResult } from "./migrate.mjs";
|
|
2
|
+
import { Task } from "nitropack/types";
|
|
3
|
+
import { Task as Task$1 } from "nitro/types";
|
|
2
4
|
//#region src/migrations/task.d.ts
|
|
3
|
-
declare const
|
|
5
|
+
declare const task: Task$1<MigrationResult> | Task<MigrationResult>;
|
|
4
6
|
//#endregion
|
|
5
|
-
export {
|
|
7
|
+
export { task as default };
|
|
6
8
|
//# sourceMappingURL=task.d.mts.map
|
package/dist/migrations/task.mjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { migrate } from "./migrate.mjs";
|
|
2
|
-
import { defineTask } from "nitropack/runtime";
|
|
3
2
|
//#region src/migrations/task.ts
|
|
4
|
-
|
|
3
|
+
const task = { async run(event) {
|
|
5
4
|
const { name } = event.payload;
|
|
6
5
|
return { result: await migrate(name) };
|
|
7
|
-
} }
|
|
6
|
+
} };
|
|
8
7
|
//#endregion
|
|
9
|
-
export {
|
|
8
|
+
export { task as default };
|
|
10
9
|
|
|
11
10
|
//# sourceMappingURL=task.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task.mjs","names":[],"sources":["../../src/migrations/task.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"task.mjs","names":[],"sources":["../../src/migrations/task.ts"],"sourcesContent":["import { migrate, type MigrationResult } from \"./migrate\";\nimport type { DatasourceRegistry } from \"nitro-drizzle/runtime\";\nimport type { Task as LegacyTask } from \"nitropack/types\";\nimport type { Task } from \"nitro/types\";\n\nconst task: Task<MigrationResult> | LegacyTask<MigrationResult> = {\n async run(event) {\n const { name } = event.payload as { name: keyof DatasourceRegistry & string };\n const result = await migrate(name);\n return { result };\n },\n};\n\nexport default task;\n"],"mappings":";;AAKA,MAAM,OAA4D,EAChE,MAAM,IAAI,OAAO;CACf,MAAM,EAAE,SAAS,MAAM;CAEvB,OAAO,EAAE,QAAA,MADY,QAAQ,IAAI,EACjB;AAClB,EACF"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { useStorage } from "
|
|
2
|
-
import { createError } from "h3";
|
|
1
|
+
import { useStorage } from "#nitro-drizzle/runtime";
|
|
3
2
|
import { digest } from "ohash";
|
|
4
3
|
import { MIGRATIONS_STORAGE_BASE } from "#nitro-drizzle/migrations";
|
|
5
4
|
//#region src/migrations/useMigrations.ts
|
|
@@ -24,11 +23,7 @@ const JOURNAL_STORAGE_KEY = "meta/_journal.json";
|
|
|
24
23
|
async function useMigrations(name) {
|
|
25
24
|
const storage = useMigrationsStorage(name);
|
|
26
25
|
const journal = await storage.getItem(JOURNAL_STORAGE_KEY);
|
|
27
|
-
if (!journal) throw
|
|
28
|
-
fatal: true,
|
|
29
|
-
message: `Cannot find migration journal for '${name}'`,
|
|
30
|
-
data: { datasource: name }
|
|
31
|
-
});
|
|
26
|
+
if (!journal) throw new Error(`Cannot find migration journal for '${name}'`);
|
|
32
27
|
return generate(journal, storage);
|
|
33
28
|
}
|
|
34
29
|
const STATEMENT_BREAKPOINT = "--> statement-breakpoint";
|
|
@@ -36,11 +31,7 @@ async function* generate(journal, storage) {
|
|
|
36
31
|
for (const { idx, when, tag, breakpoints } of journal.entries) {
|
|
37
32
|
const filename = tag + ".sql";
|
|
38
33
|
const query = await storage.getItem(filename);
|
|
39
|
-
if (!query) throw
|
|
40
|
-
fatal: true,
|
|
41
|
-
message: `Cannot find migration filename: ${filename}`,
|
|
42
|
-
data: { filename }
|
|
43
|
-
});
|
|
34
|
+
if (!query) throw new Error(`Cannot find migration filename: ${filename}`);
|
|
44
35
|
yield {
|
|
45
36
|
filename,
|
|
46
37
|
idx,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMigrations.mjs","names":[],"sources":["../../src/migrations/useMigrations.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useMigrations.mjs","names":[],"sources":["../../src/migrations/useMigrations.ts"],"sourcesContent":["import type { Storage } from \"unstorage\";\nimport { digest } from \"ohash\";\nimport type { DatasourceRegistry } from \"nitro-drizzle/runtime\";\nimport { MIGRATIONS_STORAGE_BASE } from \"#nitro-drizzle/migrations\";\nimport { useStorage } from \"#nitro-drizzle/runtime\";\nimport type { Migration } from \"./internal/migrate\";\n\n/**\n * Gets the storage for a specific datasource's migrations.\n * @template TName - The datasource name\n * @param name - The datasource name\n * @returns Storage instance for migrations\n */\nexport function useMigrationsStorage<TName extends keyof DatasourceRegistry>(\n name: TName,\n): Storage<string> {\n return useStorage(`assets:${MIGRATIONS_STORAGE_BASE}:${name}`);\n}\n\n/** Storage key for the migration journal. */\nexport const JOURNAL_STORAGE_KEY = \"meta/_journal.json\" as const;\n\n/**\n * Gets an async iterable of migrations for a specific datasource.\n * @template TName - The datasource name\n * @param name - The datasource name\n * @returns Async iterable of migrations\n * @throws If migration journal is not found\n */\nexport async function useMigrations<TName extends keyof DatasourceRegistry>(\n name: TName,\n): Promise<AsyncIterable<Migration>> {\n const storage = useMigrationsStorage(name);\n const journal = await storage.getItem<MigrationJournal>(JOURNAL_STORAGE_KEY);\n if (!journal) {\n throw new Error(`Cannot find migration journal for '${name}'`);\n }\n\n return generate(journal, storage);\n}\n\nconst STATEMENT_BREAKPOINT = \"--> statement-breakpoint\" as const;\n\nasync function* generate(journal: MigrationJournal, storage: Storage<string>) {\n for (const { idx, when, tag, breakpoints } of journal.entries) {\n const filename = tag + \".sql\";\n const query = await storage.getItem<string>(filename);\n\n if (!query) {\n throw new Error(`Cannot find migration filename: ${filename}`);\n }\n\n const migration: Migration = {\n filename,\n idx,\n sql: query.split(STATEMENT_BREAKPOINT),\n hash: digest(query),\n folderMillis: when,\n bps: breakpoints,\n };\n\n yield migration;\n }\n}\n\n/** Single entry in the migration journal. */\nexport interface MigrationJournalItem {\n /** Migration index/order number. */\n idx: number;\n /** Migration version string. */\n version: string;\n /** Timestamp when migration was created. */\n when: number;\n /** Migration tag/identifier. */\n tag: string;\n /** Indicates if this entry has breakpoints. */\n breakpoints: true;\n}\n\n/**\n * Migration journal containing all migration entries.\n * @see https://github.com/drizzle-team/drizzle-orm/blob/48e5406027103a9fca6eb66417187c4a8b5c6aa3/drizzle-kit/src/utils.ts#L63\n */\nexport interface MigrationJournal {\n /** List of migration entries. */\n entries: Iterable<MigrationJournalItem>;\n}\n"],"mappings":";;;;;;;;;;AAaA,SAAgB,qBACd,MACiB;CACjB,OAAO,WAAW,UAAU,wBAAwB,GAAG,MAAM;AAC/D;;AAGA,MAAa,sBAAsB;;;;;;;;AASnC,eAAsB,cACpB,MACmC;CACnC,MAAM,UAAU,qBAAqB,IAAI;CACzC,MAAM,UAAU,MAAM,QAAQ,QAA0B,mBAAmB;CAC3E,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,sCAAsC,KAAK,EAAE;CAG/D,OAAO,SAAS,SAAS,OAAO;AAClC;AAEA,MAAM,uBAAuB;AAE7B,gBAAgB,SAAS,SAA2B,SAA0B;CAC5E,KAAK,MAAM,EAAE,KAAK,MAAM,KAAK,iBAAiB,QAAQ,SAAS;EAC7D,MAAM,WAAW,MAAM;EACvB,MAAM,QAAQ,MAAM,QAAQ,QAAgB,QAAQ;EAEpD,IAAI,CAAC,OACH,MAAM,IAAI,MAAM,mCAAmC,UAAU;EAY/D,MAAM;GARJ;GACA;GACA,KAAK,MAAM,MAAM,oBAAoB;GACrC,MAAM,OAAO,KAAK;GAClB,cAAc;GACd,KAAK;EAGO;CAChB;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reload.mjs","names":[],"sources":["../../../src/module/internal/reload.ts"],"sourcesContent":["import type { Nitro } from \"nitropack/core\";\nimport type { Plugin } from \"rollup\";\nimport { pkgName } from \"nitro-drizzle/meta\";\nimport type { ContextOptions } from \"nitro-drizzle/context\";\n\nexport type ReloadPluginOptions = Pick<ContextOptions, \"baseDir\">;\n\nexport function reloadPlugin(nitro: Nitro, options: ReloadPluginOptions): Plugin {\n return {\n name: `${pkgName}:rollup:watch`,\n\n buildStart() {\n this.addWatchFile(options.baseDir);\n },\n\n async watchChange(id) {\n if (id.startsWith(options.baseDir)) {\n await nitro.hooks.callHook(\"restart\");\n }\n },\n };\n}\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"reload.mjs","names":[],"sources":["../../../src/module/internal/reload.ts"],"sourcesContent":["import type { Nitro as NitroV1 } from \"nitropack/core\";\nimport type { Nitro } from \"nitro/types\";\nimport type { Plugin } from \"rollup\";\nimport { pkgName } from \"nitro-drizzle/meta\";\nimport type { ContextOptions } from \"nitro-drizzle/context\";\n\nexport type ReloadPluginOptions = Pick<ContextOptions, \"baseDir\">;\n\nexport function reloadPlugin(nitro: Nitro | NitroV1, options: ReloadPluginOptions): Plugin {\n return {\n name: `${pkgName}:rollup:watch`,\n\n buildStart() {\n this.addWatchFile(options.baseDir);\n },\n\n async watchChange(id) {\n if (id.startsWith(options.baseDir)) {\n await nitro.hooks.callHook(\"restart\");\n }\n },\n };\n}\n"],"mappings":";;AAQA,SAAgB,aAAa,OAAwB,SAAsC;CACzF,OAAO;EACL,MAAM,GAAG,QAAQ;EAEjB,aAAa;GACX,KAAK,aAAa,QAAQ,OAAO;EACnC;EAEA,MAAM,YAAY,IAAI;GACpB,IAAI,GAAG,WAAW,QAAQ,OAAO,GAC/B,MAAM,MAAM,MAAM,SAAS,SAAS;EAExC;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rollup.mjs","names":[],"sources":["../../../src/module/internal/rollup.ts"],"sourcesContent":["import type { RollupConfig } from \"nitropack/types\";\nimport type { Plugin } from \"rollup\";\n\nexport async function addPlugin(rollupConfig: RollupConfig
|
|
1
|
+
{"version":3,"file":"rollup.mjs","names":[],"sources":["../../../src/module/internal/rollup.ts"],"sourcesContent":["import type { RollupConfig as NitropackRollupConfig } from \"nitropack/types\";\nimport type { RollupConfig } from \"nitro/types\";\nimport type { Plugin } from \"rollup\";\n\nexport async function addPlugin(\n rollupConfig: RollupConfig | NitropackRollupConfig,\n plugin: Plugin,\n) {\n const plugins = [await rollupConfig.plugins].flat();\n rollupConfig.plugins = [...plugins, plugin];\n}\n"],"mappings":";AAIA,eAAsB,UACpB,cACA,QACA;CAEA,aAAa,UAAU,CAAC,GADR,CAAC,MAAM,aAAa,OAAO,CAAC,CAAC,KACZ,GAAG,MAAM;AAC5C"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { relativeWithDot } from "./path.mjs";
|
|
2
2
|
import { writeFile } from "./fs.mjs";
|
|
3
|
+
import { isLegacy } from "../utils/nitro.mjs";
|
|
3
4
|
import { dirname, join, resolve } from "pathe";
|
|
4
5
|
//#region src/module/internal/types.ts
|
|
5
6
|
function addTsConfigInclude(nitroTypes, paths) {
|
|
@@ -10,28 +11,29 @@ function addTsConfigInclude(nitroTypes, paths) {
|
|
|
10
11
|
async function addAugmentations(nitroOptions, nitroTypes, augmentations) {
|
|
11
12
|
addTsConfigInclude(nitroTypes, await writeTypeFiles(nitroOptions, augmentations));
|
|
12
13
|
}
|
|
13
|
-
async function addDeclarations(
|
|
14
|
+
async function addDeclarations(nitro, nitroTypes, declarations) {
|
|
14
15
|
nitroTypes.tsConfig ||= {};
|
|
15
16
|
nitroTypes.tsConfig.compilerOptions ||= {};
|
|
16
17
|
nitroTypes.tsConfig.compilerOptions.paths ||= {};
|
|
17
18
|
for (const alias in declarations) {
|
|
18
|
-
const paths = await writeTypeFiles(
|
|
19
|
+
const paths = await writeTypeFiles(nitro, declarations[alias]);
|
|
19
20
|
nitroTypes.tsConfig.compilerOptions.paths[alias] = paths.map((path) => path.replace(/\.d\.ts$/, ""));
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
|
-
function
|
|
23
|
+
function getTypesDir(nitroOptions) {
|
|
23
24
|
return join(nitroOptions.buildDir, "types");
|
|
24
25
|
}
|
|
25
|
-
function
|
|
26
|
-
return dirname(resolve(
|
|
26
|
+
function getTsConfigDir(nitro) {
|
|
27
|
+
return dirname(resolve(isLegacy(nitro) ? nitro.options.buildDir : getTypesDir(nitro.options), nitro.options.typescript.tsconfigPath || "tsconfig.json"));
|
|
27
28
|
}
|
|
28
|
-
async function writeTypeFiles(
|
|
29
|
+
async function writeTypeFiles(nitro, modules) {
|
|
29
30
|
const paths = [];
|
|
30
|
-
const
|
|
31
|
+
const typesDir = getTypesDir(nitro.options);
|
|
32
|
+
const tsConfigDir = getTsConfigDir(nitro);
|
|
31
33
|
for (const filename in modules) {
|
|
32
|
-
const typesFilename = join(
|
|
34
|
+
const typesFilename = join(typesDir, filename);
|
|
33
35
|
await writeFile(typesFilename, await getContent(modules[filename]));
|
|
34
|
-
const relativeFilename = relativeWithDot(
|
|
36
|
+
const relativeFilename = relativeWithDot(tsConfigDir, typesFilename);
|
|
35
37
|
paths.push(relativeFilename);
|
|
36
38
|
}
|
|
37
39
|
return paths;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","names":[],"sources":["../../../src/module/internal/types.ts"],"sourcesContent":["import type { NitroOptions
|
|
1
|
+
{"version":3,"file":"types.mjs","names":[],"sources":["../../../src/module/internal/types.ts"],"sourcesContent":["import type {\n Nitro as LegacyNitro,\n NitroOptions as LegacyNitroOptions,\n NitroTypes as LegacyNitroTypes,\n VirtualModule,\n} from \"nitropack/types\";\nimport type { Nitro, NitroOptions, NitroTypes } from \"nitro/types\";\nimport { dirname, join, resolve } from \"pathe\";\nimport { relativeWithDot } from \"./path\";\nimport { writeFile } from \"./fs\";\nimport type { VirtualModules } from \"nitro-drizzle/shared\";\nimport { isLegacy } from \"../utils/nitro\";\n\nexport function addTsConfigInclude(nitroTypes: LegacyNitroTypes, paths: readonly string[]) {\n nitroTypes.tsConfig ||= {};\n nitroTypes.tsConfig.include ||= [];\n nitroTypes.tsConfig.include.push(...paths);\n}\n\nexport async function addAugmentations(\n nitroOptions: Nitro | LegacyNitro,\n nitroTypes: LegacyNitroTypes,\n augmentations: VirtualModules<`${string}.d.ts`>,\n) {\n const paths = await writeTypeFiles(nitroOptions, augmentations);\n addTsConfigInclude(nitroTypes, paths);\n}\n\nexport async function addDeclarations(\n nitro: Nitro | LegacyNitro,\n nitroTypes: NitroTypes | LegacyNitroTypes,\n declarations: Record<string, VirtualModules<`${string}.d.ts`>>,\n) {\n nitroTypes.tsConfig ||= {};\n nitroTypes.tsConfig.compilerOptions ||= {};\n nitroTypes.tsConfig.compilerOptions.paths ||= {};\n\n for (const alias in declarations) {\n const paths = await writeTypeFiles(nitro, declarations[alias]);\n\n nitroTypes.tsConfig.compilerOptions.paths[alias] = paths.map((path) =>\n path.replace(/\\.d\\.ts$/, \"\"),\n );\n }\n}\n\nfunction getTypesDir(nitroOptions: NitroOptions | LegacyNitroOptions) {\n return join(nitroOptions.buildDir, \"types\");\n}\n\nfunction getTsConfigDir(nitro: Nitro | LegacyNitro) {\n const tsConfigPath = resolve(\n isLegacy(nitro) ? nitro.options.buildDir : getTypesDir(nitro.options),\n nitro.options.typescript.tsconfigPath || \"tsconfig.json\",\n );\n const tsconfigDir = dirname(tsConfigPath);\n return tsconfigDir;\n}\n\nasync function writeTypeFiles(nitro: Nitro | LegacyNitro, modules: VirtualModules) {\n const paths: string[] = [];\n const typesDir = getTypesDir(nitro.options);\n const tsConfigDir = getTsConfigDir(nitro);\n for (const filename in modules) {\n const typesFilename = join(typesDir, filename);\n await writeFile(typesFilename, await getContent(modules[filename]));\n const relativeFilename = relativeWithDot(tsConfigDir, typesFilename);\n paths.push(relativeFilename);\n }\n return paths;\n}\n\nasync function getContent(module: VirtualModule) {\n return \"string\" == typeof module ? module : await module();\n}\n"],"mappings":";;;;;AAaA,SAAgB,mBAAmB,YAA8B,OAA0B;CACzF,WAAW,aAAa,CAAC;CACzB,WAAW,SAAS,YAAY,CAAC;CACjC,WAAW,SAAS,QAAQ,KAAK,GAAG,KAAK;AAC3C;AAEA,eAAsB,iBACpB,cACA,YACA,eACA;CAEA,mBAAmB,YAAY,MADX,eAAe,cAAc,aAAa,CAC1B;AACtC;AAEA,eAAsB,gBACpB,OACA,YACA,cACA;CACA,WAAW,aAAa,CAAC;CACzB,WAAW,SAAS,oBAAoB,CAAC;CACzC,WAAW,SAAS,gBAAgB,UAAU,CAAC;CAE/C,KAAK,MAAM,SAAS,cAAc;EAChC,MAAM,QAAQ,MAAM,eAAe,OAAO,aAAa,MAAM;EAE7D,WAAW,SAAS,gBAAgB,MAAM,SAAS,MAAM,KAAK,SAC5D,KAAK,QAAQ,YAAY,EAAE,CAC7B;CACF;AACF;AAEA,SAAS,YAAY,cAAiD;CACpE,OAAO,KAAK,aAAa,UAAU,OAAO;AAC5C;AAEA,SAAS,eAAe,OAA4B;CAMlD,OADoB,QAJC,QACnB,SAAS,KAAK,IAAI,MAAM,QAAQ,WAAW,YAAY,MAAM,OAAO,GACpE,MAAM,QAAQ,WAAW,gBAAgB,eAEJ,CACtB;AACnB;AAEA,eAAe,eAAe,OAA4B,SAAyB;CACjF,MAAM,QAAkB,CAAC;CACzB,MAAM,WAAW,YAAY,MAAM,OAAO;CAC1C,MAAM,cAAc,eAAe,KAAK;CACxC,KAAK,MAAM,YAAY,SAAS;EAC9B,MAAM,gBAAgB,KAAK,UAAU,QAAQ;EAC7C,MAAM,UAAU,eAAe,MAAM,WAAW,QAAQ,SAAS,CAAC;EAClE,MAAM,mBAAmB,gBAAgB,aAAa,aAAa;EACnE,MAAM,KAAK,gBAAgB;CAC7B;CACA,OAAO;AACT;AAEA,eAAe,WAAW,QAAuB;CAC/C,OAAO,YAAY,OAAO,SAAS,SAAS,MAAM,OAAO;AAC3D"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NitroConfig, ServerAssetDir } from "nitropack/types";
|
|
2
|
+
import { NitroConfig as NitroConfig$1, ServerAssetDir as ServerAssetDir$1 } from "nitro/types";
|
|
2
3
|
//#region src/module/utils/assets.d.ts
|
|
3
|
-
declare function updateServerAssets(config: NitroConfig, assets: readonly ServerAssetDir[]): void;
|
|
4
|
+
declare function updateServerAssets(config: NitroConfig$1 | NitroConfig, assets: readonly (ServerAssetDir$1 | ServerAssetDir)[]): void;
|
|
4
5
|
//#endregion
|
|
5
6
|
export { updateServerAssets };
|
|
6
7
|
//# sourceMappingURL=assets.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assets.mjs","names":[],"sources":["../../../src/module/utils/assets.ts"],"sourcesContent":["import type { NitroConfig, ServerAssetDir } from \"
|
|
1
|
+
{"version":3,"file":"assets.mjs","names":[],"sources":["../../../src/module/utils/assets.ts"],"sourcesContent":["import type {\n NitroConfig as LegacyNitroConfig,\n ServerAssetDir as LegacyServerAssetDir,\n} from \"nitropack/types\";\nimport type { NitroConfig, ServerAssetDir } from \"nitro/types\";\n\nexport function updateServerAssets(\n config: NitroConfig | LegacyNitroConfig,\n assets: readonly (ServerAssetDir | LegacyServerAssetDir)[],\n) {\n config.serverAssets ||= [];\n config.serverAssets = config.serverAssets\n .filter((_assets) => {\n const baseName = _assets?.baseName;\n if (!baseName) {\n return true;\n }\n return assets.some((assets) => baseName == assets.baseName);\n })\n .concat(assets);\n}\n"],"mappings":";AAMA,SAAgB,mBACd,QACA,QACA;CACA,OAAO,iBAAiB,CAAC;CACzB,OAAO,eAAe,OAAO,aAC1B,QAAQ,YAAY;EACnB,MAAM,WAAW,SAAS;EAC1B,IAAI,CAAC,UACH,OAAO;EAET,OAAO,OAAO,MAAM,WAAW,YAAY,OAAO,QAAQ;CAC5D,CAAC,CAAC,CACD,OAAO,MAAM;AAClB"}
|
|
@@ -4,7 +4,12 @@ function addInlineExternals(nitroOptions, moduleIds) {
|
|
|
4
4
|
nitroOptions.externals.inline ||= [];
|
|
5
5
|
nitroOptions.externals.inline.push(...moduleIds);
|
|
6
6
|
}
|
|
7
|
+
function addNoExternals(nitroOptions, moduleIds) {
|
|
8
|
+
if (true === nitroOptions.noExternals) return;
|
|
9
|
+
nitroOptions.noExternals ||= [];
|
|
10
|
+
nitroOptions.noExternals.push(...moduleIds);
|
|
11
|
+
}
|
|
7
12
|
//#endregion
|
|
8
|
-
export { addInlineExternals };
|
|
13
|
+
export { addInlineExternals, addNoExternals };
|
|
9
14
|
|
|
10
15
|
//# sourceMappingURL=externals.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"externals.mjs","names":[],"sources":["../../../src/module/utils/externals.ts"],"sourcesContent":["import type { NitroOptions } from \"nitropack/types\";\n\nexport function addInlineExternals(nitroOptions:
|
|
1
|
+
{"version":3,"file":"externals.mjs","names":[],"sources":["../../../src/module/utils/externals.ts"],"sourcesContent":["import type { NitroOptions as LegacyNitroOptions } from \"nitropack/types\";\nimport type { NitroOptions } from \"nitro/types\";\n\nexport function addInlineExternals(nitroOptions: LegacyNitroOptions, moduleIds: readonly string[]) {\n // @ts-expect-error\n nitroOptions.externals ||= {};\n nitroOptions.externals.inline ||= [];\n nitroOptions.externals.inline.push(...moduleIds);\n}\n\nexport function addNoExternals(nitroOptions: NitroOptions, moduleIds: readonly string[]) {\n if (true === nitroOptions.noExternals) {\n return;\n }\n nitroOptions.noExternals ||= [];\n nitroOptions.noExternals.push(...moduleIds);\n}\n"],"mappings":";AAGA,SAAgB,mBAAmB,cAAkC,WAA8B;CAEjG,aAAa,cAAc,CAAC;CAC5B,aAAa,UAAU,WAAW,CAAC;CACnC,aAAa,UAAU,OAAO,KAAK,GAAG,SAAS;AACjD;AAEA,SAAgB,eAAe,cAA4B,WAA8B;CACvF,IAAI,SAAS,aAAa,aACxB;CAEF,aAAa,gBAAgB,CAAC;CAC9B,aAAa,YAAY,KAAK,GAAG,SAAS;AAC5C"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Nitro } from "nitropack/types";
|
|
2
|
+
import { Nitro as Nitro$1 } from "nitro/types";
|
|
3
|
+
//#region src/module/utils/nitro.d.ts
|
|
4
|
+
declare function isLegacy(nitro: Nitro$1 | Nitro): nitro is Nitro;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { isLegacy };
|
|
7
|
+
//# sourceMappingURL=nitro.d.mts.map
|