nitro-drizzle 0.3.0-beta.6 → 0.3.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/README.md +3 -3
- package/dist/config/defineConfig.d.mts +2 -6
- package/dist/config/defineConfig.mjs +1 -2
- package/dist/config.mjs +1 -2
- package/dist/context/internal/async.mjs +1 -2
- package/dist/context/internal/codegen.mjs +1 -2
- package/dist/context/internal/config.mjs +2 -3
- package/dist/context/internal/format.mjs +1 -2
- package/dist/context/internal/fs.mjs +1 -2
- package/dist/context/internal/logger.mjs +1 -2
- package/dist/context/internal/templates.mjs +3 -4
- package/dist/context/internal/templates.mjs.map +1 -1
- package/dist/context/internal/virtual.mjs +4 -3
- package/dist/context/internal/virtual.mjs.map +1 -1
- package/dist/context.d.mts +13 -16
- package/dist/context.mjs +34 -13
- package/dist/context.mjs.map +1 -1
- package/dist/dialects/index.d.mts +9 -12
- package/dist/dialects/mysql.d.mts +4 -8
- package/dist/dialects/mysql.mjs +1 -2
- package/dist/dialects/postgresql.d.mts +4 -8
- package/dist/dialects/postgresql.mjs +1 -2
- package/dist/dialects/sqlite.d.mts +4 -8
- package/dist/dialects/sqlite.mjs +1 -2
- package/dist/drivers/d1/dialect.mjs +1 -2
- package/dist/drivers/d1-http.d.mts +7 -10
- package/dist/drivers/d1-http.mjs +3 -4
- package/dist/drivers/d1-http.mjs.map +1 -1
- package/dist/drivers/d1.d.mts +3 -7
- package/dist/drivers/d1.mjs +4 -5
- package/dist/drivers/d1.mjs.map +1 -1
- package/dist/drivers/index.d.mts +6 -10
- package/dist/drivers/index.mjs +1 -2
- package/dist/drivers/internal/sql.mjs +1 -2
- package/dist/drivers/mysql.d.mts +2 -5
- package/dist/drivers/mysql.mjs +3 -4
- package/dist/drivers/pglite.d.mts +2 -5
- package/dist/drivers/pglite.mjs +2 -3
- package/dist/drivers/postgresql.d.mts +3 -6
- package/dist/drivers/postgresql.mjs +3 -4
- package/dist/drivers/sqlite.d.mts +3 -6
- package/dist/drivers/sqlite.mjs +3 -4
- package/dist/index.mjs +1 -2
- package/dist/meta.d.mts +2 -5
- package/dist/meta.mjs +1 -2
- package/dist/middleware/context.d.mts +7 -21
- package/dist/middleware/context.mjs +5 -25
- package/dist/middleware/context.mjs.map +1 -1
- package/dist/migrations/internal/migrate.d.mts +3 -7
- package/dist/migrations/internal/migrate.mjs +1 -2
- package/dist/migrations/internal/migrate.mjs.map +1 -1
- package/dist/migrations/migrate.d.mts +4 -7
- package/dist/migrations/migrate.mjs +3 -4
- package/dist/migrations/task.d.mts +1 -4
- package/dist/migrations/task.mjs +1 -2
- package/dist/migrations/useMigrations.d.mts +8 -12
- package/dist/migrations/useMigrations.mjs +3 -4
- package/dist/module/internal/fs.mjs +5 -6
- package/dist/module/internal/fs.mjs.map +1 -1
- package/dist/module/internal/path.mjs +1 -2
- package/dist/module/internal/reload.mjs +1 -2
- package/dist/module/internal/reload.mjs.map +1 -1
- package/dist/module/internal/resolver.mjs +1 -2
- package/dist/module/internal/resolver.mjs.map +1 -1
- package/dist/module/internal/rollup.mjs +1 -2
- package/dist/module/internal/types.mjs +21 -19
- package/dist/module/internal/types.mjs.map +1 -1
- package/dist/module/utils/assets.d.mts +1 -5
- package/dist/module/utils/assets.mjs +1 -2
- package/dist/module/utils/externals.d.mts +1 -5
- package/dist/module/utils/externals.mjs +1 -2
- package/dist/module/utils/nitro.d.mts +1 -5
- package/dist/module/utils/nitro.mjs +1 -2
- package/dist/module.d.mts +11 -21
- package/dist/module.mjs +27 -19
- package/dist/module.mjs.map +1 -1
- package/dist/plugins/init/index.d.mts +6 -0
- package/dist/plugins/init/index.mjs +20 -0
- package/dist/plugins/init/index.mjs.map +1 -0
- package/dist/plugins/init/legacy.d.mts +15 -0
- package/dist/plugins/init/legacy.mjs +26 -0
- package/dist/plugins/init/legacy.mjs.map +1 -0
- package/dist/plugins/{migrate.d.mts → migrate/hooks.d.mts} +3 -16
- package/dist/plugins/migrate/hooks.mjs +10 -0
- package/dist/plugins/migrate/hooks.mjs.map +1 -0
- package/dist/plugins/migrate/index.d.mts +11 -0
- package/dist/plugins/{migrate.mjs → migrate/index.mjs} +10 -10
- package/dist/plugins/migrate/index.mjs.map +1 -0
- package/dist/plugins/migrate/legacy.d.mts +11 -0
- package/dist/plugins/migrate/legacy.mjs +25 -0
- package/dist/plugins/migrate/legacy.mjs.map +1 -0
- package/dist/runtime/callInitHook.d.mts +8 -0
- package/dist/runtime/callInitHook.mjs +27 -0
- package/dist/runtime/callInitHook.mjs.map +1 -0
- package/dist/runtime/internal/config.mjs +1 -2
- package/dist/runtime/internal/createDatasource.mjs +4 -5
- package/dist/runtime/internal/hooks.d.mts +14 -0
- package/dist/runtime/internal/hooks.mjs +5 -0
- package/dist/runtime/internal/hooks.mjs.map +1 -0
- package/dist/runtime/internal/state.d.mts +10 -0
- package/dist/runtime/internal/state.mjs +28 -0
- package/dist/runtime/internal/state.mjs.map +1 -0
- package/dist/runtime/useConfig.d.mts +2 -6
- package/dist/runtime/useConfig.mjs +1 -2
- package/dist/runtime/useDatasource.d.mts +3 -7
- package/dist/runtime/useDatasource.mjs +2 -3
- package/dist/runtime/useDialect.d.mts +5 -8
- package/dist/runtime/useDialect.mjs +2 -3
- package/dist/runtime.d.mts +22 -22
- package/dist/runtime.mjs +4 -1
- package/dist/shared/variants.d.mts +7 -10
- package/dist/shared/variants.mjs +1 -2
- package/dist/shared.d.mts +7 -10
- package/dist/shared.mjs +1 -2
- package/dist/utils/usePrimaryKey.d.mts +1 -5
- package/dist/utils/usePrimaryKey.mjs +1 -2
- package/dist/utils.mjs +1 -2
- package/package.json +35 -31
- package/dist/drivers/db0.d.mts +0 -21
- package/dist/drivers/db0.mjs +0 -28
- package/dist/drivers/db0.mjs.map +0 -1
- package/dist/plugins/init.d.mts +0 -15
- package/dist/plugins/init.mjs +0 -13
- package/dist/plugins/init.mjs.map +0 -1
- package/dist/plugins/legacy/init.d.mts +0 -24
- package/dist/plugins/legacy/init.mjs +0 -50
- package/dist/plugins/legacy/init.mjs.map +0 -1
- package/dist/plugins/legacy/migrate.d.mts +0 -21
- package/dist/plugins/legacy/migrate.mjs +0 -25
- package/dist/plugins/legacy/migrate.mjs.map +0 -1
- package/dist/plugins/migrate.mjs.map +0 -1
package/dist/module.d.mts
CHANGED
|
@@ -1,25 +1,17 @@
|
|
|
1
|
+
import { NitroModule } from "nitropack/types";
|
|
2
|
+
import { NitroModule as NitroModule$1 } from "nitro/types";
|
|
3
|
+
import { ConfigPattern, MigrationOptions } from "nitro-drizzle/context";
|
|
1
4
|
import { updateServerAssets } from "./module/utils/assets.mjs";
|
|
2
5
|
import { addInlineExternals } from "./module/utils/externals.mjs";
|
|
3
6
|
import { isLegacy } from "./module/utils/nitro.mjs";
|
|
4
|
-
import { ConfigPattern, MigrationOptions } from "nitro-drizzle/context";
|
|
5
|
-
import { ConnectorSpecifier, ConnectorVariants, ExpandVariants, Variant } from "nitro-drizzle/shared";
|
|
6
|
-
import { NitroModule } from "nitropack/types";
|
|
7
|
-
import { NitroModule as NitroModule$1 } from "nitro/types";
|
|
8
|
-
import { Connector } from "nitro-drizzle/drivers";
|
|
9
|
-
//#region src/module/index.d.ts
|
|
10
7
|
/**
|
|
11
|
-
* Datasource-specific configuration options.
|
|
8
|
+
* Datasource-specific configuration options mapped by datasource name.
|
|
12
9
|
*/
|
|
13
|
-
type
|
|
10
|
+
export type DatasourceOptions = Record<string, {
|
|
14
11
|
drivers: readonly string[] | {
|
|
15
12
|
[name: string]: boolean;
|
|
16
13
|
};
|
|
17
|
-
}
|
|
18
|
-
type DatasourceOptionsVariants = DatasourceOptionsMapper<ConnectorVariants>;
|
|
19
|
-
/**
|
|
20
|
-
* Datasource-specific configuration options mapped by datasource name.
|
|
21
|
-
*/
|
|
22
|
-
type DatasourceOptions = ExpandVariants<DatasourceOptionsVariants, ["name"]>;
|
|
14
|
+
}>;
|
|
23
15
|
declare module "nitropack/types" {
|
|
24
16
|
interface NitroOptions {
|
|
25
17
|
drizzle?: ModuleOptions;
|
|
@@ -30,7 +22,7 @@ declare module "nitro/types" {
|
|
|
30
22
|
drizzle?: ModuleOptions;
|
|
31
23
|
}
|
|
32
24
|
}
|
|
33
|
-
interface ModuleOptions {
|
|
25
|
+
export interface ModuleOptions {
|
|
34
26
|
/**
|
|
35
27
|
* Directory to search datasources
|
|
36
28
|
*/
|
|
@@ -48,14 +40,14 @@ interface ModuleOptions {
|
|
|
48
40
|
/**
|
|
49
41
|
* Resolved module configuration with required fields.
|
|
50
42
|
*/
|
|
51
|
-
type ModuleConfig = Required<ModuleOptions> & {
|
|
43
|
+
export type ModuleConfig = Required<ModuleOptions> & {
|
|
52
44
|
migrations: false | Required<MigrationOptions>;
|
|
53
45
|
};
|
|
54
46
|
/**
|
|
55
47
|
* Creates the default module configuration options.
|
|
56
48
|
* @returns The default module configuration
|
|
57
49
|
*/
|
|
58
|
-
declare function createDefaultOptions(): {
|
|
50
|
+
export declare function createDefaultOptions(): {
|
|
59
51
|
readonly baseDir: "./drizzle";
|
|
60
52
|
readonly configPattern: readonly ["drizzle.config.{js,ts}", "drizzle-*.config.{js,ts}"];
|
|
61
53
|
readonly datasources: {};
|
|
@@ -69,8 +61,6 @@ declare function createDefaultOptions(): {
|
|
|
69
61
|
* @param options - Optional module configuration overrides
|
|
70
62
|
* @returns The resolved module configuration
|
|
71
63
|
*/
|
|
72
|
-
declare function defineModuleConfig(options?: ModuleOptions): ModuleConfig;
|
|
64
|
+
export declare function defineModuleConfig(options?: ModuleOptions): ModuleConfig;
|
|
73
65
|
declare const module: NitroModule & NitroModule$1;
|
|
74
|
-
|
|
75
|
-
export { DatasourceOptions, ModuleConfig, ModuleOptions, addInlineExternals, createDefaultOptions, module as default, defineModuleConfig, isLegacy as isLegacyNitro, updateServerAssets };
|
|
76
|
-
//# sourceMappingURL=module.d.mts.map
|
|
66
|
+
export { addInlineExternals, module as default, isLegacy as isLegacyNitro, updateServerAssets };
|
package/dist/module.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { updateServerAssets } from "./module/utils/assets.mjs";
|
|
2
|
-
import { addInlineExternals, addNoExternals } from "./module/utils/externals.mjs";
|
|
3
|
-
import { isLegacy } from "./module/utils/nitro.mjs";
|
|
4
|
-
import { addAugmentations, addDeclarations } from "./module/internal/types.mjs";
|
|
5
|
-
import { createResolver } from "./module/internal/resolver.mjs";
|
|
6
|
-
import { reloadPlugin } from "./module/internal/reload.mjs";
|
|
7
|
-
import { addPlugin } from "./module/internal/rollup.mjs";
|
|
8
1
|
import { defu } from "defu";
|
|
9
2
|
import { resolve } from "pathe";
|
|
10
3
|
import { resolveAlias } from "pathe/utils";
|
|
11
4
|
import { createContext } from "nitro-drizzle/context";
|
|
12
5
|
import { pkgName } from "nitro-drizzle/meta";
|
|
13
|
-
|
|
6
|
+
import { updateServerAssets } from "./module/utils/assets.mjs";
|
|
7
|
+
import { addInlineExternals, addNoExternals } from "./module/utils/externals.mjs";
|
|
8
|
+
import { extendNitroTsConfig } from "./module/internal/types.mjs";
|
|
9
|
+
import { createResolver } from "./module/internal/resolver.mjs";
|
|
10
|
+
import { reloadPlugin } from "./module/internal/reload.mjs";
|
|
11
|
+
import { addPlugin } from "./module/internal/rollup.mjs";
|
|
12
|
+
import { isLegacy } from "./module/utils/nitro.mjs";
|
|
13
|
+
// src/module/index.ts
|
|
14
14
|
/**
|
|
15
15
|
* Creates the default module configuration options.
|
|
16
16
|
* @returns The default module configuration
|
|
@@ -81,15 +81,21 @@ const module = {
|
|
|
81
81
|
virtualModules(modules) {
|
|
82
82
|
Object.assign(nitro.options.virtual, modules);
|
|
83
83
|
},
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
84
|
+
async types(declarations) {
|
|
85
|
+
const virtual = { ...declarations.virtual };
|
|
86
|
+
const augmentations = {
|
|
87
|
+
...declarations.shared,
|
|
88
|
+
...declarations.runtime,
|
|
89
|
+
...declarations.module
|
|
90
|
+
};
|
|
91
|
+
if (isLegacy(nitro)) nitro.hooks.hook("types:extend", async (types) => {
|
|
92
|
+
const tsConfig = types.tsConfig ||= {};
|
|
93
|
+
await extendNitroTsConfig(nitro, tsConfig, augmentations, virtual);
|
|
92
94
|
});
|
|
95
|
+
else {
|
|
96
|
+
const tsConfig = nitro.options.typescript.tsConfig ||= {};
|
|
97
|
+
await extendNitroTsConfig(nitro, tsConfig, augmentations, virtual);
|
|
98
|
+
}
|
|
93
99
|
},
|
|
94
100
|
assets(assets) {
|
|
95
101
|
updateServerAssets(nitro.options, assets);
|
|
@@ -100,14 +106,16 @@ const module = {
|
|
|
100
106
|
}
|
|
101
107
|
};
|
|
102
108
|
const context = createContext(contextOptions);
|
|
103
|
-
if (nitro
|
|
104
|
-
nitro.hooks.hook("rollup:before", async (nitro, config) => {
|
|
109
|
+
if (isLegacy(nitro)) nitro.hooks.hook("rollup:before", async (nitro, config) => {
|
|
105
110
|
await addPlugin(config, reloadPlugin(nitro, { baseDir }));
|
|
106
111
|
});
|
|
112
|
+
else nitro.hooks.hook("build:config", async (nitro, config) => {
|
|
113
|
+
if ("rollup" == config.builder) await addPlugin(config.rollup, reloadPlugin(nitro, { baseDir }));
|
|
114
|
+
else logger.warn(`Watching "${baseDir}" is not yet supported using "${config.builder}" builder.`);
|
|
115
|
+
});
|
|
107
116
|
await context.init();
|
|
108
117
|
}
|
|
109
118
|
};
|
|
110
|
-
//#endregion
|
|
111
119
|
export { addInlineExternals, createDefaultOptions, module as default, defineModuleConfig, isLegacy as isLegacyNitro, updateServerAssets };
|
|
112
120
|
|
|
113
121
|
//# sourceMappingURL=module.mjs.map
|
package/dist/module.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.mjs","names":[],"sources":["../src/module/index.ts"],"sourcesContent":["import type { NitroModule as LegacyNitroModule } from \"nitropack/types\";\nimport type { NitroModule } from \"nitro/types\";\nimport { defu } from \"defu\";\nimport { resolve } from \"pathe\";\nimport { resolveAlias } from \"pathe/utils\";\n\nimport {\n createContext,\n type ConfigPattern,\n type ContextOptions,\n type MigrationOptions,\n} from \"nitro-drizzle/context\";\nimport type {
|
|
1
|
+
{"version":3,"file":"module.mjs","names":[],"sources":["../src/module/index.ts"],"sourcesContent":["import type { NitroModule as LegacyNitroModule } from \"nitropack/types\";\nimport type { NitroModule } from \"nitro/types\";\nimport type { ConsolaInstance } from \"consola\";\nimport { defu } from \"defu\";\nimport { resolve } from \"pathe\";\nimport { resolveAlias } from \"pathe/utils\";\n\nimport {\n createContext,\n type ConfigPattern,\n type ContextOptions,\n type MigrationOptions,\n} from \"nitro-drizzle/context\";\nimport type { VirtualModules, MaybePromise, NitroHookName } from \"nitro-drizzle/shared\";\nimport { pkgName } from \"nitro-drizzle/meta\";\n\nimport { updateServerAssets } from \"./utils/assets\";\nimport { addInlineExternals, addNoExternals } from \"./utils/externals\";\n\nimport { extendNitroTsConfig } from \"./internal/types\";\nimport { createResolver } from \"./internal/resolver\";\nimport { reloadPlugin } from \"./internal/reload\";\nimport { addPlugin } from \"./internal/rollup\";\nimport { isLegacy } from \"./utils/nitro\";\n\n/**\n * Datasource-specific configuration options mapped by datasource name.\n */\nexport type DatasourceOptions = Record<\n string,\n {\n drivers: readonly string[] | { [name: string]: boolean };\n }\n>;\n\ndeclare module \"nitropack/types\" {\n interface NitroOptions {\n drizzle?: ModuleOptions;\n }\n}\n\ndeclare module \"nitro/types\" {\n interface NitroOptions {\n drizzle?: ModuleOptions;\n }\n}\n\nexport interface ModuleOptions {\n /**\n * Directory to search datasources\n */\n baseDir?: string;\n /**\n * Patterns to search Drizzle configs\n */\n configPattern?: ConfigPattern;\n\n datasources?: DatasourceOptions;\n\n /**\n * Enable migrations storage\n */\n migrations?: false | Partial<MigrationOptions>;\n}\n\n/**\n * Resolved module configuration with required fields.\n */\nexport type ModuleConfig = Required<ModuleOptions> & {\n migrations: false | Required<MigrationOptions>;\n};\n\n/**\n * Creates the default module configuration options.\n * @returns The default module configuration\n */\nexport function createDefaultOptions() {\n return {\n baseDir: \"./drizzle\",\n configPattern: [\"drizzle.config.{js,ts}\", \"drizzle-*.config.{js,ts}\"],\n datasources: {},\n migrations: {\n storageBase: \"drizzle:migrations\",\n migrateOnInit: false,\n },\n } as const satisfies ModuleConfig;\n}\n\n/**\n * Merges user-provided module options with defaults.\n * @param options - Optional module configuration overrides\n * @returns The resolved module configuration\n */\nexport function defineModuleConfig(options?: ModuleOptions): ModuleConfig {\n return defu(options, createDefaultOptions());\n}\n\nconst module: LegacyNitroModule & NitroModule = {\n name: pkgName,\n async setup(nitro) {\n const logger = nitro.logger.withTag(pkgName) as ConsolaInstance;\n const moduleConfig = defineModuleConfig(nitro.options.drizzle);\n\n const resolver = createResolver(nitro.options.rootDir, {\n alias: nitro.options.alias,\n });\n\n const serverDir = isLegacy(nitro) ? nitro.options.srcDir : nitro.options.serverDir;\n if (!serverDir) {\n logger.info(\"No server directory configured.\");\n return;\n }\n\n const baseDir = resolve(serverDir, resolveAlias(moduleConfig.baseDir, nitro.options.alias));\n\n if (!isLegacy(nitro)) {\n nitro.options.handlers ||= [];\n nitro.options.handlers.push({\n route: \"/**\",\n handler: resolver.resolve(\"nitro-drizzle/middleware/context\"),\n middleware: true,\n });\n }\n\n const contextOptions: ContextOptions = {\n legacy: isLegacy(nitro),\n cwd: process.cwd(),\n resolver: resolver,\n baseDir,\n logger,\n configPattern: moduleConfig.configPattern,\n datasources: { ...moduleConfig.datasources },\n migrations: moduleConfig.migrations || void 0,\n get initHooks() {\n const hooks: NitroHookName[] = [];\n if (nitro.options.preset.startsWith(\"cloudflare\")) {\n if (nitro.options.preset.endsWith(\"durable\")) {\n hooks.push(\"cloudflare:durable:init\", \"cloudflare:durable:alarm\");\n }\n hooks.push(\n \"request\",\n \"cloudflare:email\",\n \"cloudflare:queue\",\n \"cloudflare:scheduled\",\n \"cloudflare:tail\",\n \"cloudflare:trace\",\n );\n }\n return hooks;\n },\n\n tasks: nitro.options.experimental.tasks\n ? (tasks) => {\n nitro.options.tasks ||= {};\n Object.assign(nitro.options.tasks, tasks);\n }\n : void 0,\n\n plugins(plugins) {\n nitro.options.plugins.push(\n ...plugins.map((plugin) => resolver.resolve(plugin).replace(/\\.mjs$/, \"\")),\n );\n },\n\n virtualModules(modules: VirtualModules): MaybePromise<void> {\n Object.assign(nitro.options.virtual, modules);\n },\n\n async types(declarations): Promise<void> {\n const virtual = {\n ...declarations.virtual,\n };\n\n const augmentations = {\n ...declarations.shared,\n ...declarations.runtime,\n ...declarations.module,\n };\n\n if (isLegacy(nitro)) {\n nitro.hooks.hook(\"types:extend\", async (types) => {\n const tsConfig = (types.tsConfig ||= {});\n await extendNitroTsConfig(nitro, tsConfig, augmentations, virtual);\n });\n } else {\n const tsConfig = (nitro.options.typescript.tsConfig ||= {});\n await extendNitroTsConfig(nitro, tsConfig, augmentations, virtual);\n }\n },\n\n assets(assets) {\n updateServerAssets(nitro.options, assets);\n },\n\n externals(modules) {\n if (isLegacy(nitro)) {\n addInlineExternals(nitro.options, modules);\n } else {\n addNoExternals(nitro.options, modules);\n }\n },\n };\n\n const context = createContext(contextOptions);\n\n if (isLegacy(nitro)) {\n nitro.hooks.hook(\"rollup:before\", async (nitro, config) => {\n await addPlugin(config, reloadPlugin(nitro, { baseDir }));\n });\n } else {\n nitro.hooks.hook(\"build:config\", async (nitro, config) => {\n if (\"rollup\" == config.builder) {\n await addPlugin(config.rollup, reloadPlugin(nitro, { baseDir }));\n } else {\n // TODO: implement\n logger.warn(\n `Watching \"${baseDir}\" is not yet supported using \"${config.builder}\" builder.`,\n );\n }\n });\n }\n\n await context.init();\n },\n};\n\nexport default module;\n\nexport { addInlineExternals, updateServerAssets, isLegacy as isLegacyNitro };\n"],"mappings":"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"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { definePlugin } from "nitro";
|
|
2
|
+
import { callInitHook } from "nitro-drizzle/runtime";
|
|
3
|
+
// src/plugins/init/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* Nitro plugin that triggers the 'drizzle:init' hook during server initialization.
|
|
6
|
+
* Used to run migration plugins at startup.
|
|
7
|
+
*/
|
|
8
|
+
var init_default = definePlugin(async (nitro) => {
|
|
9
|
+
callInitHook({
|
|
10
|
+
callHook: async (name) => {
|
|
11
|
+
await nitro.hooks.callHook(name);
|
|
12
|
+
},
|
|
13
|
+
registerHook: (name, action) => {
|
|
14
|
+
return nitro.hooks.hook(name, action);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
export { init_default as default };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/plugins/init/index.ts"],"sourcesContent":["import { definePlugin } from \"nitro\";\nimport { callInitHook } from \"nitro-drizzle/runtime\";\n\n/**\n * Nitro plugin that triggers the 'drizzle:init' hook during server initialization.\n * Used to run migration plugins at startup.\n */\nexport default definePlugin(async (nitro) => {\n callInitHook({\n callHook: async (name) => {\n await nitro.hooks.callHook(name);\n },\n registerHook: (name, action) => {\n return nitro.hooks.hook(name, action);\n },\n });\n});\n"],"mappings":";;;;;;;AAOA,IAAA,eAAe,aAAa,OAAO,UAAU;CAC3C,aAAa;EACX,UAAU,OAAO,SAAS;GACxB,MAAM,MAAM,MAAM,SAAS,IAAI;EACjC;EACA,eAAe,MAAM,WAAW;GAC9B,OAAO,MAAM,MAAM,KAAK,MAAM,MAAM;EACtC;CACF,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DrizzleInitHooks, DrizzleInitState } from "nitro-drizzle/runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Nitro plugin that triggers the 'drizzle:init' hook during server initialization.
|
|
4
|
+
* Used to run migration plugins at startup.
|
|
5
|
+
*/
|
|
6
|
+
declare const _default: import("nitropack").NitroAppPlugin;
|
|
7
|
+
declare module "nitropack/types" {
|
|
8
|
+
interface NitroRuntimeHooks extends DrizzleInitHooks {}
|
|
9
|
+
}
|
|
10
|
+
declare module "h3" {
|
|
11
|
+
interface H3EventContext {
|
|
12
|
+
drizzle: DrizzleInitState;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export { _default as default };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineNitroPlugin } from "nitropack/runtime";
|
|
2
|
+
import { callInitHook as callInitHook$1 } from "../../runtime/callInitHook.mjs";
|
|
3
|
+
import { useInitState } from "nitro-drizzle/runtime";
|
|
4
|
+
// src/plugins/init/legacy.ts
|
|
5
|
+
/**
|
|
6
|
+
* Nitro plugin that triggers the 'drizzle:init' hook during server initialization.
|
|
7
|
+
* Used to run migration plugins at startup.
|
|
8
|
+
*/
|
|
9
|
+
var legacy_default = defineNitroPlugin((nitro) => {
|
|
10
|
+
callInitHook$1({
|
|
11
|
+
callHook: async (name) => {
|
|
12
|
+
await nitro.hooks.callHookParallel(name);
|
|
13
|
+
},
|
|
14
|
+
registerHook: (name, action) => {
|
|
15
|
+
return nitro.hooks.hook(name, action);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
nitro.hooks.hook("request", (event) => {
|
|
19
|
+
const state = useInitState();
|
|
20
|
+
event.context.drizzle = state;
|
|
21
|
+
event.waitUntil(state.waitReady());
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
export { legacy_default as default };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=legacy.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacy.mjs","names":["callInitHook"],"sources":["../../../src/plugins/init/legacy.ts"],"sourcesContent":["import { defineNitroPlugin } from \"nitropack/runtime\";\nimport { callInitHook } from \"../../runtime/callInitHook\";\nimport { useInitState, type DrizzleInitHooks, type DrizzleInitState } from \"nitro-drizzle/runtime\";\n\n/**\n * Nitro plugin that triggers the 'drizzle:init' hook during server initialization.\n * Used to run migration plugins at startup.\n */\nexport default defineNitroPlugin((nitro) => {\n callInitHook({\n callHook: async (name) => {\n await nitro.hooks.callHookParallel(name);\n },\n registerHook: (name, action) => {\n return nitro.hooks.hook(name, action);\n },\n });\n\n // TODO: should be replaced with middleware\n nitro.hooks.hook(\"request\", (event) => {\n const state = useInitState();\n event.context.drizzle = state;\n event.waitUntil(state.waitReady());\n });\n});\n\ndeclare module \"nitropack/types\" {\n interface NitroRuntimeHooks extends DrizzleInitHooks {}\n}\n\ndeclare module \"h3\" {\n interface H3EventContext {\n drizzle: DrizzleInitState;\n }\n}\n"],"mappings":";;;;;;;;AAQA,IAAA,iBAAe,mBAAmB,UAAU;CAC1CA,eAAa;EACX,UAAU,OAAO,SAAS;GACxB,MAAM,MAAM,MAAM,iBAAiB,IAAI;EACzC;EACA,eAAe,MAAM,WAAW;GAC9B,OAAO,MAAM,MAAM,KAAK,MAAM,MAAM;EACtC;CACF,CAAC;CAGD,MAAM,MAAM,KAAK,YAAY,UAAU;EACrC,MAAM,QAAQ,aAAa;EAC3B,MAAM,QAAQ,UAAU;EACxB,MAAM,UAAU,MAAM,UAAU,CAAC;CACnC,CAAC;AACH,CAAC"}
|
|
@@ -1,21 +1,8 @@
|
|
|
1
|
-
import { DatasourceRegistry } from "nitro-drizzle/runtime";
|
|
2
1
|
import { MigrationResult } from "nitro-drizzle/migrations";
|
|
3
|
-
import {
|
|
4
|
-
//#region src/plugins/migrate.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Nitro plugin that runs migrations on initialization.
|
|
7
|
-
* Registers hooks to run migrations for datasources configured with migrateOnInit.
|
|
8
|
-
*/
|
|
9
|
-
declare const plugin: NitroAppPlugin;
|
|
2
|
+
import { DatasourceRegistry } from "nitro-drizzle/runtime";
|
|
10
3
|
/** Type for migration hooks registered for each datasource. */
|
|
11
|
-
interface
|
|
4
|
+
export interface DrizzleMigrationHooks {
|
|
12
5
|
"drizzle:migrate:before": (datasource: keyof DatasourceRegistry & string) => Promise<void> | void;
|
|
13
6
|
"drizzle:migrate": (datasource: keyof DatasourceRegistry & string) => Promise<void> | void;
|
|
14
7
|
"drizzle:migrate:after": (datasource: keyof DatasourceRegistry & string, result: MigrationResult) => Promise<void> | void;
|
|
15
|
-
}
|
|
16
|
-
declare module "nitro/types" {
|
|
17
|
-
interface NitroRuntimeHooks extends MigrationHooks {}
|
|
18
|
-
}
|
|
19
|
-
//#endregion
|
|
20
|
-
export { MigrationHooks, plugin as default };
|
|
21
|
-
//# sourceMappingURL=migrate.d.mts.map
|
|
8
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/plugins/migrate/hooks.ts
|
|
2
|
+
const MIGRATION_HOOK_KEY = "drizzle:migrate";
|
|
3
|
+
const drizzleMigrationHooks = {
|
|
4
|
+
migrate: MIGRATION_HOOK_KEY,
|
|
5
|
+
beforeMigrate: `${MIGRATION_HOOK_KEY}:before`,
|
|
6
|
+
afterMigrate: `${MIGRATION_HOOK_KEY}:after`
|
|
7
|
+
};
|
|
8
|
+
export { drizzleMigrationHooks };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=hooks.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.mjs","names":[],"sources":["../../../src/plugins/migrate/hooks.ts"],"sourcesContent":["import type { MigrationResult } from \"nitro-drizzle/migrations\";\nimport type { DatasourceRegistry } from \"nitro-drizzle/runtime\";\n\n/** Type for migration hooks registered for each datasource. */\nexport interface DrizzleMigrationHooks {\n \"drizzle:migrate:before\": (datasource: keyof DatasourceRegistry & string) => Promise<void> | void;\n \"drizzle:migrate\": (datasource: keyof DatasourceRegistry & string) => Promise<void> | void;\n \"drizzle:migrate:after\": (\n datasource: keyof DatasourceRegistry & string,\n result: MigrationResult,\n ) => Promise<void> | void;\n}\nconst MIGRATION_HOOK_KEY = \"drizzle:migrate\" as const;\n\nexport const drizzleMigrationHooks = {\n migrate: MIGRATION_HOOK_KEY,\n beforeMigrate: `${MIGRATION_HOOK_KEY}:before`,\n afterMigrate: `${MIGRATION_HOOK_KEY}:after`,\n} as const satisfies Record<string, keyof DrizzleMigrationHooks>;\n"],"mappings":";AAYA,MAAM,qBAAqB;AAE3B,MAAa,wBAAwB;CACnC,SAAS;CACT,eAAe,GAAG,mBAAmB;CACrC,cAAc,GAAG,mBAAmB;AACtC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NitroAppPlugin } from "nitro/types";
|
|
2
|
+
import { DrizzleMigrationHooks } from "./hooks.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Nitro plugin that runs migrations on initialization.
|
|
5
|
+
* Registers hooks to run migrations for datasources configured with migrateOnInit.
|
|
6
|
+
*/
|
|
7
|
+
declare const plugin: NitroAppPlugin;
|
|
8
|
+
declare module "nitro/types" {
|
|
9
|
+
interface NitroRuntimeHooks extends DrizzleMigrationHooks {}
|
|
10
|
+
}
|
|
11
|
+
export { plugin as default };
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { MIGRATE_ON_INIT } from "#nitro-drizzle/migrations";
|
|
2
1
|
import { definePlugin } from "nitro";
|
|
2
|
+
import { MIGRATE_ON_INIT } from "#nitro-drizzle/migrations";
|
|
3
3
|
import { migrate } from "nitro-drizzle/migrations";
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import { drizzleMigrationHooks } from "./hooks.mjs";
|
|
5
|
+
import { drizzleInitHooks } from "nitro-drizzle/runtime";
|
|
6
|
+
// src/plugins/migrate/index.ts
|
|
6
7
|
/**
|
|
7
8
|
* Nitro plugin that runs migrations on initialization.
|
|
8
9
|
* Registers hooks to run migrations for datasources configured with migrateOnInit.
|
|
9
10
|
*/
|
|
10
11
|
const plugin = definePlugin(async (nitro) => {
|
|
11
|
-
nitro.hooks.hook(
|
|
12
|
-
await nitro.hooks.callHook(
|
|
12
|
+
nitro.hooks.hook(drizzleMigrationHooks.migrate, async (name) => {
|
|
13
|
+
await nitro.hooks.callHook(drizzleMigrationHooks.beforeMigrate, name);
|
|
13
14
|
const result = await migrate(name);
|
|
14
|
-
await nitro.hooks.callHook(
|
|
15
|
+
await nitro.hooks.callHook(drizzleMigrationHooks.afterMigrate, name, result);
|
|
15
16
|
});
|
|
16
17
|
let hookCalled = false;
|
|
17
18
|
let removeHook;
|
|
18
|
-
removeHook = nitro.hooks.hook(
|
|
19
|
+
removeHook = nitro.hooks.hook(drizzleInitHooks.init, async () => {
|
|
19
20
|
if (hookCalled) return;
|
|
20
21
|
hookCalled = true;
|
|
21
22
|
removeHook();
|
|
22
23
|
await Promise.all(MIGRATE_ON_INIT.map((name) => {
|
|
23
|
-
return nitro.hooks.callHook(
|
|
24
|
+
return nitro.hooks.callHook(drizzleMigrationHooks.migrate, name);
|
|
24
25
|
}));
|
|
25
26
|
});
|
|
26
27
|
});
|
|
27
|
-
//#endregion
|
|
28
28
|
export { plugin as default };
|
|
29
29
|
|
|
30
|
-
//# sourceMappingURL=
|
|
30
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/plugins/migrate/index.ts"],"sourcesContent":["import { definePlugin } from \"nitro\";\nimport type { NitroAppPlugin } from \"nitro/types\";\n\nimport { MIGRATE_ON_INIT } from \"#nitro-drizzle/migrations\";\nimport { migrate } from \"nitro-drizzle/migrations\";\nimport { drizzleMigrationHooks, type DrizzleMigrationHooks } from \"./hooks\";\nimport { drizzleInitHooks } from \"nitro-drizzle/runtime\";\n\n/**\n * Nitro plugin that runs migrations on initialization.\n * Registers hooks to run migrations for datasources configured with migrateOnInit.\n */\nconst plugin: NitroAppPlugin = definePlugin(async (nitro) => {\n nitro.hooks.hook(drizzleMigrationHooks.migrate, async (name) => {\n await nitro.hooks.callHook(drizzleMigrationHooks.beforeMigrate, name);\n const result = await migrate(name);\n await nitro.hooks.callHook(drizzleMigrationHooks.afterMigrate, name, result);\n });\n\n let hookCalled = false;\n let removeHook: () => void;\n removeHook = nitro.hooks.hook(drizzleInitHooks.init, async () => {\n if (hookCalled) return;\n hookCalled = true;\n removeHook();\n await Promise.all(\n MIGRATE_ON_INIT.map((name) => {\n return nitro.hooks.callHook(drizzleMigrationHooks.migrate, name);\n }),\n );\n });\n});\n\nexport default plugin;\n\ndeclare module \"nitro/types\" {\n interface NitroRuntimeHooks extends DrizzleMigrationHooks {}\n}\n"],"mappings":";;;;;;;;;;AAYA,MAAM,SAAyB,aAAa,OAAO,UAAU;CAC3D,MAAM,MAAM,KAAK,sBAAsB,SAAS,OAAO,SAAS;EAC9D,MAAM,MAAM,MAAM,SAAS,sBAAsB,eAAe,IAAI;EACpE,MAAM,SAAS,MAAM,QAAQ,IAAI;EACjC,MAAM,MAAM,MAAM,SAAS,sBAAsB,cAAc,MAAM,MAAM;CAC7E,CAAC;CAED,IAAI,aAAa;CACjB,IAAI;CACJ,aAAa,MAAM,MAAM,KAAK,iBAAiB,MAAM,YAAY;EAC/D,IAAI,YAAY;EAChB,aAAa;EACb,WAAW;EACX,MAAM,QAAQ,IACZ,gBAAgB,KAAK,SAAS;GAC5B,OAAO,MAAM,MAAM,SAAS,sBAAsB,SAAS,IAAI;EACjE,CAAC,CACH;CACF,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NitroAppPlugin } from "nitropack/types";
|
|
2
|
+
import { DrizzleMigrationHooks } from "./hooks.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Nitro plugin that runs migrations on initialization.
|
|
5
|
+
* Registers hooks to run migrations for datasources configured with migrateOnInit.
|
|
6
|
+
*/
|
|
7
|
+
declare const plugin: NitroAppPlugin;
|
|
8
|
+
declare module "nitropack/types" {
|
|
9
|
+
interface NitroRuntimeHooks extends DrizzleMigrationHooks {}
|
|
10
|
+
}
|
|
11
|
+
export { plugin as default };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { defineNitroPlugin } from "nitropack/runtime";
|
|
2
|
+
import { migrate } from "nitro-drizzle/migrations";
|
|
3
|
+
import { MIGRATE_ON_INIT } from "#nitro-drizzle/migrations";
|
|
4
|
+
import { drizzleMigrationHooks } from "./hooks.mjs";
|
|
5
|
+
import { drizzleInitHooks } from "nitro-drizzle/runtime";
|
|
6
|
+
// src/plugins/migrate/legacy.ts
|
|
7
|
+
/**
|
|
8
|
+
* Nitro plugin that runs migrations on initialization.
|
|
9
|
+
* Registers hooks to run migrations for datasources configured with migrateOnInit.
|
|
10
|
+
*/
|
|
11
|
+
const plugin = defineNitroPlugin(async (nitro) => {
|
|
12
|
+
nitro.hooks.hook(drizzleMigrationHooks.migrate, async (name) => {
|
|
13
|
+
await nitro.hooks.callHook(drizzleMigrationHooks.beforeMigrate, name);
|
|
14
|
+
const result = await migrate(name);
|
|
15
|
+
await nitro.hooks.callHook(drizzleMigrationHooks.afterMigrate, name, result);
|
|
16
|
+
});
|
|
17
|
+
nitro.hooks.hookOnce(drizzleInitHooks.init, async () => {
|
|
18
|
+
await Promise.all(MIGRATE_ON_INIT.map((name) => {
|
|
19
|
+
return nitro.hooks.callHookParallel(drizzleMigrationHooks.migrate, name);
|
|
20
|
+
}));
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
export { plugin as default };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=legacy.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacy.mjs","names":[],"sources":["../../../src/plugins/migrate/legacy.ts"],"sourcesContent":["import { defineNitroPlugin } from \"nitropack/runtime\";\nimport type { NitroAppPlugin } from \"nitropack/types\";\nimport { migrate } from \"nitro-drizzle/migrations\";\n\nimport { MIGRATE_ON_INIT } from \"#nitro-drizzle/migrations\";\nimport { drizzleMigrationHooks, type DrizzleMigrationHooks } from \"./hooks\";\nimport { drizzleInitHooks } from \"nitro-drizzle/runtime\";\n\n/**\n * Nitro plugin that runs migrations on initialization.\n * Registers hooks to run migrations for datasources configured with migrateOnInit.\n */\nconst plugin: NitroAppPlugin = defineNitroPlugin(async (nitro) => {\n nitro.hooks.hook(drizzleMigrationHooks.migrate, async (name) => {\n await nitro.hooks.callHook(drizzleMigrationHooks.beforeMigrate, name);\n const result = await migrate(name);\n await nitro.hooks.callHook(drizzleMigrationHooks.afterMigrate, name, result);\n });\n\n nitro.hooks.hookOnce(drizzleInitHooks.init, async () => {\n await Promise.all(\n MIGRATE_ON_INIT.map((name) => {\n return nitro.hooks.callHookParallel(drizzleMigrationHooks.migrate, name);\n }),\n );\n });\n});\n\nexport default plugin;\n\ndeclare module \"nitropack/types\" {\n interface NitroRuntimeHooks extends DrizzleMigrationHooks {}\n}\n"],"mappings":";;;;;;;;;;AAYA,MAAM,SAAyB,kBAAkB,OAAO,UAAU;CAChE,MAAM,MAAM,KAAK,sBAAsB,SAAS,OAAO,SAAS;EAC9D,MAAM,MAAM,MAAM,SAAS,sBAAsB,eAAe,IAAI;EACpE,MAAM,SAAS,MAAM,QAAQ,IAAI;EACjC,MAAM,MAAM,MAAM,SAAS,sBAAsB,cAAc,MAAM,MAAM;CAC7E,CAAC;CAED,MAAM,MAAM,SAAS,iBAAiB,MAAM,YAAY;EACtD,MAAM,QAAQ,IACZ,gBAAgB,KAAK,SAAS;GAC5B,OAAO,MAAM,MAAM,iBAAiB,sBAAsB,SAAS,IAAI;EACzE,CAAC,CACH;CACF,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { HookOptions } from "./internal/hooks.mjs";
|
|
2
|
+
import { ReadyState } from "./internal/state.mjs";
|
|
3
|
+
export interface CallInitHookOptions extends HookOptions {}
|
|
4
|
+
export interface CallInitHookReturn {
|
|
5
|
+
readonly readyState: () => ReadyState;
|
|
6
|
+
readonly waitReady: () => Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export declare function callInitHook({ callHook, registerHook }: CallInitHookOptions): CallInitHookReturn;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { initHooks } from "#nitro-drizzle/runtime";
|
|
2
|
+
import { useInitState } from "./internal/state.mjs";
|
|
3
|
+
// src/runtime/callInitHook.ts
|
|
4
|
+
function callInitHook({ callHook, registerHook }) {
|
|
5
|
+
const state = useInitState();
|
|
6
|
+
if (initHooks?.length) {
|
|
7
|
+
const cleanups = initHooks.map((hookName) => {
|
|
8
|
+
return registerHook(hookName, () => {
|
|
9
|
+
state.init({ callHook });
|
|
10
|
+
state.waitReady().finally(() => {
|
|
11
|
+
for (const fn of cleanups) fn();
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
} else state.init({ callHook });
|
|
16
|
+
return {
|
|
17
|
+
readyState() {
|
|
18
|
+
return state.readyState;
|
|
19
|
+
},
|
|
20
|
+
async waitReady() {
|
|
21
|
+
await state.waitReady();
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export { callInitHook };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=callInitHook.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callInitHook.mjs","names":[],"sources":["../../src/runtime/callInitHook.ts"],"sourcesContent":["import { initHooks } from \"#nitro-drizzle/runtime\";\nimport type { HookOptions } from \"./internal/hooks\";\nimport { useInitState, type ReadyState } from \"./internal/state\";\n\nexport interface CallInitHookOptions extends HookOptions {}\n\nexport interface CallInitHookReturn {\n readonly readyState: () => ReadyState;\n readonly waitReady: () => Promise<void>;\n}\n\nexport function callInitHook({ callHook, registerHook }: CallInitHookOptions): CallInitHookReturn {\n const state = useInitState();\n\n if (initHooks?.length) {\n const cleanups = initHooks.map((hookName) => {\n return registerHook(hookName, () => {\n state.init({ callHook });\n state.waitReady().finally(() => {\n for (const fn of cleanups) {\n fn();\n }\n });\n });\n });\n } else {\n state.init({ callHook });\n }\n\n return {\n readyState() {\n return state.readyState;\n },\n async waitReady() {\n await state.waitReady();\n },\n };\n}\n"],"mappings":";;;AAWA,SAAgB,aAAa,EAAE,UAAU,gBAAyD;CAChG,MAAM,QAAQ,aAAa;CAE3B,IAAI,WAAW,QAAQ;EACrB,MAAM,WAAW,UAAU,KAAK,aAAa;GAC3C,OAAO,aAAa,gBAAgB;IAClC,MAAM,KAAK,EAAE,SAAS,CAAC;IACvB,MAAM,UAAU,CAAC,CAAC,cAAc;KAC9B,KAAK,MAAM,MAAM,UACf,GAAG;IAEP,CAAC;GACH,CAAC;EACH,CAAC;CACH,OACE,MAAM,KAAK,EAAE,SAAS,CAAC;CAGzB,OAAO;EACL,aAAa;GACX,OAAO,MAAM;EACf;EACA,MAAM,YAAY;GAChB,MAAM,MAAM,UAAU;EACxB;CACF;AACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useConfig } from "../useConfig.mjs";
|
|
2
2
|
import "../../runtime.mjs";
|
|
3
3
|
import { callConfigHook } from "#nitro-drizzle/runtime";
|
|
4
|
-
|
|
4
|
+
// src/runtime/internal/config.ts
|
|
5
5
|
const datasourceConfig = {};
|
|
6
6
|
/**
|
|
7
7
|
* Gets the driver configuration for a datasource, calling the config hook.
|
|
@@ -30,7 +30,6 @@ async function getDriverConfig(name) {
|
|
|
30
30
|
function clearCachedConfig(name) {
|
|
31
31
|
delete datasourceConfig[name];
|
|
32
32
|
}
|
|
33
|
-
//#endregion
|
|
34
33
|
export { clearCachedConfig, getDriverConfig };
|
|
35
34
|
|
|
36
35
|
//# sourceMappingURL=config.mjs.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { getDriverConfig } from "./config.mjs";
|
|
2
|
-
import { useConfig } from "../useConfig.mjs";
|
|
3
|
-
import "../../runtime.mjs";
|
|
4
1
|
import { useDatasourceRegistry } from "#nitro-drizzle/runtime";
|
|
5
|
-
|
|
2
|
+
import "../../runtime.mjs";
|
|
3
|
+
import { useConfig } from "../useConfig.mjs";
|
|
4
|
+
import { getDriverConfig } from "./config.mjs";
|
|
5
|
+
// src/runtime/internal/createDatasource.ts
|
|
6
6
|
/**
|
|
7
7
|
* Creates a datasource instance by name.
|
|
8
8
|
* @internal
|
|
@@ -28,7 +28,6 @@ function useDatasourceProvider(name) {
|
|
|
28
28
|
if (false === driver in datasourceRegistry[name]) throw new Error(`Driver "${driver}" is not supported by "${name}" datasource.`);
|
|
29
29
|
return datasourceRegistry[name][driver];
|
|
30
30
|
}
|
|
31
|
-
//#endregion
|
|
32
31
|
export { createDatasource, useDatasourceProvider };
|
|
33
32
|
|
|
34
33
|
//# sourceMappingURL=createDatasource.mjs.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { InitHookName } from "#nitro-drizzle/runtime";
|
|
2
|
+
export type CleanupFn = () => void;
|
|
3
|
+
export type RegisterHook = (name: InitHookName, action: () => void | Promise<void>) => CleanupFn;
|
|
4
|
+
export type CallHook = (name: "drizzle:init") => void | Promise<void>;
|
|
5
|
+
export interface HookOptions {
|
|
6
|
+
callHook: CallHook;
|
|
7
|
+
registerHook: RegisterHook;
|
|
8
|
+
}
|
|
9
|
+
export interface DrizzleInitHooks {
|
|
10
|
+
"drizzle:init": () => Promise<void> | void;
|
|
11
|
+
}
|
|
12
|
+
export declare const drizzleInitHooks: {
|
|
13
|
+
readonly init: "drizzle:init";
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.mjs","names":[],"sources":["../../../src/runtime/internal/hooks.ts"],"sourcesContent":["import type { InitHookName } from \"#nitro-drizzle/runtime\";\n\nexport type CleanupFn = () => void;\nexport type RegisterHook = (name: InitHookName, action: () => void | Promise<void>) => CleanupFn;\nexport type CallHook = (name: \"drizzle:init\") => void | Promise<void>;\n\nexport interface HookOptions {\n callHook: CallHook;\n registerHook: RegisterHook;\n}\n\nexport interface DrizzleInitHooks {\n \"drizzle:init\": () => Promise<void> | void;\n}\n\nexport const drizzleInitHooks = {\n init: \"drizzle:init\",\n} as const satisfies Record<string, keyof DrizzleInitHooks>;\n"],"mappings":";AAeA,MAAa,mBAAmB,EAC9B,MAAM,eACR"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CallHook } from "./hooks.mjs";
|
|
2
|
+
export type ReadyState = "pending" | "done" | "error";
|
|
3
|
+
export declare function useInitState(): DrizzleInitState;
|
|
4
|
+
export interface DrizzleInitState {
|
|
5
|
+
readonly readyState: ReadyState;
|
|
6
|
+
readonly waitReady: () => Promise<void>;
|
|
7
|
+
init(options: {
|
|
8
|
+
callHook: CallHook;
|
|
9
|
+
}): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { drizzleInitHooks } from "./hooks.mjs";
|
|
2
|
+
// src/runtime/internal/state.ts
|
|
3
|
+
let state;
|
|
4
|
+
function useInitState() {
|
|
5
|
+
if (!state) state = new DefaultDrizzleInitState();
|
|
6
|
+
return state;
|
|
7
|
+
}
|
|
8
|
+
var DefaultDrizzleInitState = class {
|
|
9
|
+
initHook = null;
|
|
10
|
+
readyState = "pending";
|
|
11
|
+
async waitReady() {
|
|
12
|
+
if (!this.initHook) throw new TypeError("waitReady called before init");
|
|
13
|
+
await this.initHook;
|
|
14
|
+
}
|
|
15
|
+
init({ callHook }) {
|
|
16
|
+
if (this.initHook) return;
|
|
17
|
+
this.initHook = Promise.resolve(callHook(drizzleInitHooks.init)).then(() => {
|
|
18
|
+
this.readyState = "done";
|
|
19
|
+
return this.readyState;
|
|
20
|
+
}).catch((err) => {
|
|
21
|
+
this.readyState = "error";
|
|
22
|
+
throw err;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
export { DefaultDrizzleInitState, useInitState };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=state.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.mjs","names":[],"sources":["../../../src/runtime/internal/state.ts"],"sourcesContent":["import { drizzleInitHooks, type CallHook } from \"./hooks\";\n\nexport type ReadyState = \"pending\" | \"done\" | \"error\";\n\nlet state: DrizzleInitState;\n\nexport function useInitState(): DrizzleInitState {\n if (!state) {\n state = new DefaultDrizzleInitState();\n }\n return state;\n}\n\nexport interface DrizzleInitState {\n readonly readyState: ReadyState;\n readonly waitReady: () => Promise<void>;\n init(options: { callHook: CallHook }): void;\n}\n\nexport class DefaultDrizzleInitState implements DrizzleInitState {\n private initHook: Promise<ReadyState> | null = null;\n readyState: ReadyState = \"pending\";\n\n async waitReady() {\n if (!this.initHook) {\n throw new TypeError(\"waitReady called before init\");\n }\n await this.initHook;\n }\n\n init({ callHook }: { callHook: CallHook }): void {\n if (this.initHook) return;\n this.initHook = Promise.resolve(callHook(drizzleInitHooks.init))\n .then(() => {\n this.readyState = \"done\";\n return this.readyState;\n })\n .catch((err) => {\n this.readyState = \"error\";\n throw err;\n });\n }\n}\n"],"mappings":";;AAIA,IAAI;AAEJ,SAAgB,eAAiC;CAC/C,IAAI,CAAC,OACH,QAAQ,IAAI,wBAAwB;CAEtC,OAAO;AACT;AAQA,IAAa,0BAAb,MAAiE;CACvD,WAAuC;CAC/C,aAAyB;CAEzB,MAAM,YAAY;EAChB,IAAI,CAAC,KAAK,UACR,MAAM,IAAI,UAAU,8BAA8B;EAEpD,MAAM,KAAK;CACb;CAEA,KAAK,EAAE,YAA0C;EAC/C,IAAI,KAAK,UAAU;EACnB,KAAK,WAAW,QAAQ,QAAQ,SAAS,iBAAiB,IAAI,CAAC,CAAC,CAC7D,WAAW;GACV,KAAK,aAAa;GAClB,OAAO,KAAK;EACd,CAAC,CAAC,CACD,OAAO,QAAQ;GACd,KAAK,aAAa;GAClB,MAAM;EACR,CAAC;CACL;AACF"}
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import { Datasources, PrimitiveProps } from "../runtime.mjs";
|
|
2
|
-
//#region src/runtime/useConfig.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Retrieves the runtime configuration for a specific datasource.
|
|
5
4
|
* @template TName - The datasource name
|
|
6
5
|
* @param name - The datasource name
|
|
7
6
|
* @returns The driver name and driver-specific configuration
|
|
8
7
|
*/
|
|
9
|
-
declare function useConfig<TName extends keyof Datasources & string>(name: TName): {
|
|
8
|
+
export declare function useConfig<TName extends keyof Datasources & string>(name: TName): {
|
|
10
9
|
driver: string;
|
|
11
10
|
config: PrimitiveProps<{}>;
|
|
12
|
-
};
|
|
13
|
-
//#endregion
|
|
14
|
-
export { useConfig };
|
|
15
|
-
//# sourceMappingURL=useConfig.d.mts.map
|
|
11
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defu } from "defu";
|
|
2
2
|
import { useRuntimeConfig } from "#nitro-drizzle/runtime";
|
|
3
|
-
|
|
3
|
+
// src/runtime/useConfig.ts
|
|
4
4
|
/**
|
|
5
5
|
* Retrieves the runtime configuration for a specific datasource.
|
|
6
6
|
* @template TName - The datasource name
|
|
@@ -16,7 +16,6 @@ function useConfig(name) {
|
|
|
16
16
|
config: defu(config[driver], {})
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
-
//#endregion
|
|
20
19
|
export { useConfig };
|
|
21
20
|
|
|
22
21
|
//# sourceMappingURL=useConfig.mjs.map
|