nitro-drizzle 0.3.0 → 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/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 +2 -3
- package/dist/context.d.mts +12 -16
- package/dist/context.mjs +7 -8
- 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 +9 -12
- 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 +30 -26
- 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
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Config } from "drizzle-kit";
|
|
2
|
-
//#region src/config/defineConfig.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Define Drizzle config compatible with both 'nitro-drizzle' and 'drizzle-kit' packages.
|
|
5
4
|
* Handles path resolution automatically for schema and output paths.
|
|
@@ -7,7 +6,7 @@ import { Config } from "drizzle-kit";
|
|
|
7
6
|
* @param filename - Pass `import.meta.url` as the filename for correct relative path resolution
|
|
8
7
|
* @returns A DrizzleKit compatible configuration object with resolved paths
|
|
9
8
|
*/
|
|
10
|
-
declare function defineConfig(config: Config, filename: string): {
|
|
9
|
+
export declare function defineConfig(config: Config, filename: string): {
|
|
11
10
|
dialect: "gel" | "mysql" | "postgresql" | "singlestore" | "sqlite" | "turso";
|
|
12
11
|
breakpoints?: boolean;
|
|
13
12
|
tablesFilter?: string | string[];
|
|
@@ -403,7 +402,4 @@ declare function defineConfig(config: Config, filename: string): {
|
|
|
403
402
|
}));
|
|
404
403
|
schema: string | string[] | undefined;
|
|
405
404
|
out: string | undefined;
|
|
406
|
-
};
|
|
407
|
-
//#endregion
|
|
408
|
-
export { defineConfig };
|
|
409
|
-
//# sourceMappingURL=defineConfig.d.mts.map
|
|
405
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { relative, resolve } from "pathe";
|
|
2
2
|
import { cwd } from "node:process";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
|
-
|
|
4
|
+
// src/config/defineConfig.ts
|
|
5
5
|
/**
|
|
6
6
|
* Define Drizzle config compatible with both 'nitro-drizzle' and 'drizzle-kit' packages.
|
|
7
7
|
* Handles path resolution automatically for schema and output paths.
|
|
@@ -28,7 +28,6 @@ function transformToRelative(dirname, cwd, path) {
|
|
|
28
28
|
path = resolve(dirname, path);
|
|
29
29
|
return relative(cwd, path);
|
|
30
30
|
}
|
|
31
|
-
//#endregion
|
|
32
31
|
export { defineConfig };
|
|
33
32
|
|
|
34
33
|
//# sourceMappingURL=defineConfig.mjs.map
|
package/dist/config.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { defineConfig };
|
|
1
|
+
export { defineConfig } from "./config/defineConfig.mjs";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/context/internal/async.ts
|
|
2
2
|
async function* generateAsync(iterable, cb) {
|
|
3
3
|
let index = 0;
|
|
4
4
|
for await (const value of iterable) yield await cb(value, index++);
|
|
@@ -17,7 +17,6 @@ async function mapAsync(iterable, cb) {
|
|
|
17
17
|
for await (const item of generator) items.push(item);
|
|
18
18
|
return items;
|
|
19
19
|
}
|
|
20
|
-
//#endregion
|
|
21
20
|
export { mapAsync };
|
|
22
21
|
|
|
23
22
|
//# sourceMappingURL=async.mjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/context/internal/codegen.ts
|
|
2
2
|
/**
|
|
3
3
|
* Generates a TypeScript type name with optional generic parameters.
|
|
4
4
|
* @param name - The base type name
|
|
@@ -22,7 +22,6 @@ function genTypeName(name, options) {
|
|
|
22
22
|
function genReference(reference) {
|
|
23
23
|
return `/// <reference ${Object.entries(reference).slice(0, 1).map(([prop, value]) => `${prop}="${value}"`).join("")} />`;
|
|
24
24
|
}
|
|
25
|
-
//#endregion
|
|
26
25
|
export { genReference, genTypeName };
|
|
27
26
|
|
|
28
27
|
//# sourceMappingURL=codegen.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { genObjectKey } from "knitwork";
|
|
2
1
|
import { resolve } from "pathe";
|
|
3
|
-
|
|
2
|
+
import { genObjectKey } from "knitwork";
|
|
3
|
+
// src/context/internal/config.ts
|
|
4
4
|
/**
|
|
5
5
|
* Transforms a Drizzle config into a normalized datasource configuration.
|
|
6
6
|
* @param drizzleConfig - The raw DrizzleKit configuration
|
|
@@ -30,7 +30,6 @@ async function transformDrizzleConfig(drizzleConfig, { dirName, path, resolver,
|
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
const DISABLED_DATASOURCE_DIRNAME_REGEX = /^[_-]+/;
|
|
33
|
-
//#endregion
|
|
34
33
|
export { DISABLED_DATASOURCE_DIRNAME_REGEX, transformDrizzleConfig };
|
|
35
34
|
|
|
36
35
|
//# sourceMappingURL=config.mjs.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { dedent } from "strip-indent";
|
|
2
|
-
|
|
2
|
+
// src/context/internal/format.ts
|
|
3
3
|
/**
|
|
4
4
|
* Tagged template literal function that dedents and interpolates values.
|
|
5
5
|
* @param strings - The template strings array
|
|
@@ -21,7 +21,6 @@ function script(strings, ...values) {
|
|
|
21
21
|
}
|
|
22
22
|
return dedent(result);
|
|
23
23
|
}
|
|
24
|
-
//#endregion
|
|
25
24
|
export { script };
|
|
26
25
|
|
|
27
26
|
//# sourceMappingURL=format.mjs.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { glob } from "tinyglobby";
|
|
2
|
-
|
|
2
|
+
// src/context/internal/fs.ts
|
|
3
3
|
/**
|
|
4
4
|
* Resolves file paths matching a glob pattern in a base directory.
|
|
5
5
|
* @param baseDir - The base directory to search in
|
|
@@ -16,7 +16,6 @@ async function resolveFiles(baseDir, pattern, options) {
|
|
|
16
16
|
followSymbolicLinks: options?.followSymbolicLinks
|
|
17
17
|
})).sort((a, b) => a.localeCompare(b));
|
|
18
18
|
}
|
|
19
|
-
//#endregion
|
|
20
19
|
export { resolveFiles };
|
|
21
20
|
|
|
22
21
|
//# sourceMappingURL=fs.mjs.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { colorize } from "consola/utils";
|
|
2
|
-
|
|
2
|
+
// src/context/internal/logger.ts
|
|
3
3
|
function accentColor(text) {
|
|
4
4
|
return colorize("bold", colorize("greenBright", text.toString()));
|
|
5
5
|
}
|
|
@@ -20,7 +20,6 @@ function accent(strings, ...values) {
|
|
|
20
20
|
}
|
|
21
21
|
return result;
|
|
22
22
|
}
|
|
23
|
-
//#endregion
|
|
24
23
|
export { accent };
|
|
25
24
|
|
|
26
25
|
//# sourceMappingURL=logger.mjs.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { script } from "./format.mjs";
|
|
2
|
-
import { genReference, genTypeName } from "./codegen.mjs";
|
|
3
1
|
import { genInlineTypeImport, genObjectFromValues, genString, genTypeImport } from "knitwork";
|
|
4
2
|
import { genVariants } from "nitro-drizzle/shared";
|
|
5
|
-
|
|
3
|
+
import { script } from "./format.mjs";
|
|
4
|
+
import { genReference, genTypeName } from "./codegen.mjs";
|
|
5
|
+
// src/context/internal/templates.ts
|
|
6
6
|
function getConnectorDimensions({ name, driver }) {
|
|
7
7
|
return {
|
|
8
8
|
name,
|
|
@@ -88,7 +88,6 @@ function moduleTypeDeclarations(_datasources) {
|
|
|
88
88
|
function dialectDeclarations(_datasources) {
|
|
89
89
|
return ``;
|
|
90
90
|
}
|
|
91
|
-
//#endregion
|
|
92
91
|
export { dialectDeclarations, moduleTypeDeclarations, runtimeDeclarations, sharedTypeDeclarations };
|
|
93
92
|
|
|
94
93
|
//# sourceMappingURL=templates.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.mjs","names":[],"sources":["../../../src/context/internal/templates.ts"],"sourcesContent":["import { genTypeImport, genString, genObjectFromValues, genInlineTypeImport } from \"knitwork\";\nimport type { DatasourceInfo, DriverOptions } from \"..\";\nimport { genVariants, type Selector, type VirtualModules } from \"nitro-drizzle/shared\";\nimport { script } from \"./format\";\nimport { genReference, genTypeName } from \"./codegen\";\n\ntype ConnectorInfo = {\n name: string;\n driver: DriverOptions;\n};\n\nfunction getConnectorDimensions({ name, driver }: ConnectorInfo) {\n return {\n name,\n dialect: driver.dialect,\n driver: driver.name,\n };\n}\n\nclass ImportedModules {\n readonly #files: string[] = [];\n\n values(): readonly string[] {\n return [...this.#files];\n }\n\n getOrAdd(value: string): number {\n let index = this.#files.indexOf(value);\n if (!~index) {\n index = this.#files.push(value);\n }\n return index;\n }\n}\n\nexport function sharedTypeDeclarations(\n datasources: readonly DatasourceInfo[],\n): VirtualModules<`${string}.d.ts`> {\n const moduleId = \"nitro-drizzle/shared\";\n const connectors = datasources.flatMap(({ name, drivers }) => {\n return drivers.map((driver) => {\n return {\n name,\n driver,\n };\n });\n });\n\n const SCHEMA_PARTS_TYPE = \"SchemaParts\";\n const SCHEMA_TYPE = \"SchemaVariants\";\n const CONNECTOR_TYPE = \"Connectors\";\n const UNWRAP_VARIANT_TYPE = \"UnwrapVariant\";\n const MERGE_SCHEMA_TYPE = \"MergeSchema\";\n\n const schemaFiles = new ImportedModules();\n connectors\n .flatMap((connector) => {\n return connector.driver.imports.schema;\n })\n .forEach((schemaFile) => {\n schemaFiles.getOrAdd(schemaFile);\n });\n\n const driverImports = new ImportedModules();\n connectors.forEach((connector) => {\n driverImports.getOrAdd(connector.driver.imports.connector);\n });\n\n const content = [\n genTypeImport(\"nitro-drizzle/shared\", [\"Variant\", UNWRAP_VARIANT_TYPE]),\n genTypeImport(\"nitro-drizzle/drivers\", [\"Schema\", MERGE_SCHEMA_TYPE]),\n\n script /* ts */ `type ${SCHEMA_PARTS_TYPE} = [\n ${schemaFiles\n .values()\n .map((file) => {\n return `typeof import(${genString(file)})`;\n })\n .join(\",\\n\")}\n ]`,\n\n script /* ts */ `type ${CONNECTOR_TYPE}<TSchema extends Schema> = [\n ${driverImports\n .values()\n .map((file) => {\n return genInlineTypeImport(file) + `<TSchema>`;\n })\n .join(\",\\n\")}\n ]`,\n\n script /**ts */ `type ${SCHEMA_TYPE} = \n ${genVariants({\n variants: connectors.map((connector): [schemaType: string, dimensions: Selector] => {\n return [\n genTypeName(MERGE_SCHEMA_TYPE, {\n generic: [\n SCHEMA_PARTS_TYPE,\n connector.driver.imports.schema\n .map((schemaFile) => {\n return schemaFiles.getOrAdd(schemaFile).toString();\n })\n .join(\" | \") || \"never\",\n ],\n }),\n getConnectorDimensions(connector),\n ];\n }),\n })}\n `,\n\n script /**ts */ `\n declare module ${genString(moduleId)} {\n type ConnectorVariants = ${genVariants({\n variants: connectors.map((connector): [connectorType: string, selector: Selector] => {\n const dimensions = getConnectorDimensions(connector);\n return [\n genTypeName(CONNECTOR_TYPE, {\n generic: [\n genTypeName(UNWRAP_VARIANT_TYPE, {\n generic: [SCHEMA_TYPE, genObjectFromValues(dimensions)],\n }),\n ],\n }) + `[${driverImports.getOrAdd(connector.driver.imports.connector)}]`,\n dimensions,\n ];\n }),\n })};\n }\n `,\n ].join(\"\\n\\n\");\n\n return {\n [`${moduleId}.d.ts`]: content,\n };\n}\n\n/** @deprecated */\nexport function runtimeDeclarations(_datasources: readonly DatasourceInfo[]) {\n return \"\";\n}\n\nexport function moduleTypeDeclarations(\n _datasources: readonly DatasourceInfo[],\n): VirtualModules<`${string}.d.ts`> {\n const moduleId = \"nitro-drizzle/module\";\n\n const content = [genReference({ types: moduleId })].join(\"\\n\");\n\n return {\n \"nitro-drizzle/module.d.ts\": content,\n };\n}\n\n/** @deprecated */\nexport function dialectDeclarations(_datasources: readonly DatasourceInfo[]) {\n return ``;\n}\n"],"mappings":";;;;;AAWA,SAAS,uBAAuB,EAAE,MAAM,UAAyB;CAC/D,OAAO;EACL;EACA,SAAS,OAAO;EAChB,QAAQ,OAAO;CACjB;AACF;AAEA,IAAM,kBAAN,MAAsB;
|
|
1
|
+
{"version":3,"file":"templates.mjs","names":[],"sources":["../../../src/context/internal/templates.ts"],"sourcesContent":["import { genTypeImport, genString, genObjectFromValues, genInlineTypeImport } from \"knitwork\";\nimport type { DatasourceInfo, DriverOptions } from \"..\";\nimport { genVariants, type Selector, type VirtualModules } from \"nitro-drizzle/shared\";\nimport { script } from \"./format\";\nimport { genReference, genTypeName } from \"./codegen\";\n\ntype ConnectorInfo = {\n name: string;\n driver: DriverOptions;\n};\n\nfunction getConnectorDimensions({ name, driver }: ConnectorInfo) {\n return {\n name,\n dialect: driver.dialect,\n driver: driver.name,\n };\n}\n\nclass ImportedModules {\n readonly #files: string[] = [];\n\n values(): readonly string[] {\n return [...this.#files];\n }\n\n getOrAdd(value: string): number {\n let index = this.#files.indexOf(value);\n if (!~index) {\n index = this.#files.push(value);\n }\n return index;\n }\n}\n\nexport function sharedTypeDeclarations(\n datasources: readonly DatasourceInfo[],\n): VirtualModules<`${string}.d.ts`> {\n const moduleId = \"nitro-drizzle/shared\";\n const connectors = datasources.flatMap(({ name, drivers }) => {\n return drivers.map((driver) => {\n return {\n name,\n driver,\n };\n });\n });\n\n const SCHEMA_PARTS_TYPE = \"SchemaParts\";\n const SCHEMA_TYPE = \"SchemaVariants\";\n const CONNECTOR_TYPE = \"Connectors\";\n const UNWRAP_VARIANT_TYPE = \"UnwrapVariant\";\n const MERGE_SCHEMA_TYPE = \"MergeSchema\";\n\n const schemaFiles = new ImportedModules();\n connectors\n .flatMap((connector) => {\n return connector.driver.imports.schema;\n })\n .forEach((schemaFile) => {\n schemaFiles.getOrAdd(schemaFile);\n });\n\n const driverImports = new ImportedModules();\n connectors.forEach((connector) => {\n driverImports.getOrAdd(connector.driver.imports.connector);\n });\n\n const content = [\n genTypeImport(\"nitro-drizzle/shared\", [\"Variant\", UNWRAP_VARIANT_TYPE]),\n genTypeImport(\"nitro-drizzle/drivers\", [\"Schema\", MERGE_SCHEMA_TYPE]),\n\n script /* ts */ `type ${SCHEMA_PARTS_TYPE} = [\n ${schemaFiles\n .values()\n .map((file) => {\n return `typeof import(${genString(file)})`;\n })\n .join(\",\\n\")}\n ]`,\n\n script /* ts */ `type ${CONNECTOR_TYPE}<TSchema extends Schema> = [\n ${driverImports\n .values()\n .map((file) => {\n return genInlineTypeImport(file) + `<TSchema>`;\n })\n .join(\",\\n\")}\n ]`,\n\n script /**ts */ `type ${SCHEMA_TYPE} = \n ${genVariants({\n variants: connectors.map((connector): [schemaType: string, dimensions: Selector] => {\n return [\n genTypeName(MERGE_SCHEMA_TYPE, {\n generic: [\n SCHEMA_PARTS_TYPE,\n connector.driver.imports.schema\n .map((schemaFile) => {\n return schemaFiles.getOrAdd(schemaFile).toString();\n })\n .join(\" | \") || \"never\",\n ],\n }),\n getConnectorDimensions(connector),\n ];\n }),\n })}\n `,\n\n script /**ts */ `\n declare module ${genString(moduleId)} {\n type ConnectorVariants = ${genVariants({\n variants: connectors.map((connector): [connectorType: string, selector: Selector] => {\n const dimensions = getConnectorDimensions(connector);\n return [\n genTypeName(CONNECTOR_TYPE, {\n generic: [\n genTypeName(UNWRAP_VARIANT_TYPE, {\n generic: [SCHEMA_TYPE, genObjectFromValues(dimensions)],\n }),\n ],\n }) + `[${driverImports.getOrAdd(connector.driver.imports.connector)}]`,\n dimensions,\n ];\n }),\n })};\n }\n `,\n ].join(\"\\n\\n\");\n\n return {\n [`${moduleId}.d.ts`]: content,\n };\n}\n\n/** @deprecated */\nexport function runtimeDeclarations(_datasources: readonly DatasourceInfo[]) {\n return \"\";\n}\n\nexport function moduleTypeDeclarations(\n _datasources: readonly DatasourceInfo[],\n): VirtualModules<`${string}.d.ts`> {\n const moduleId = \"nitro-drizzle/module\";\n\n const content = [genReference({ types: moduleId })].join(\"\\n\");\n\n return {\n \"nitro-drizzle/module.d.ts\": content,\n };\n}\n\n/** @deprecated */\nexport function dialectDeclarations(_datasources: readonly DatasourceInfo[]) {\n return ``;\n}\n"],"mappings":";;;;;AAWA,SAAS,uBAAuB,EAAE,MAAM,UAAyB;CAC/D,OAAO;EACL;EACA,SAAS,OAAO;EAChB,QAAQ,OAAO;CACjB;AACF;AAEA,IAAM,kBAAN,MAAsB;CACX,SAAmB,CAAC;CAE7B,SAA4B;EAC1B,OAAO,CAAC,GAAG,KAAK,MAAM;CACxB;CAEA,SAAS,OAAuB;EAC9B,IAAI,QAAQ,KAAK,OAAO,QAAQ,KAAK;EACrC,IAAI,CAAC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nD,CAAC,CAAC,CACD,KAAK,KAAK,KAAK,OACpB,EACF,CAAC,GACD,uBAAuB,SAAS,CAClC;EACF,CAAC,EACH,CAAC,EAAE;;EAGL,MAAgB;uBACG,UAAU,QAAQ,EAAE;mCACR,YAAY,EACrC,UAAU,WAAW,KAAK,cAA2D;GACnF,MAAM,aAAa,uBAAuB,SAAS;GACnD,OAAO,CACL,YAAY,gBAAgB,EAC1B,SAAS,CACP,YAAY,qBAAqB,EAC/B,SAAS,CAAC,aAAa,oBAAoB,UAAU,CAAC,EACxD,CAAC,CACH,EACF,CAAC,IAAI,IAAI,cAAc,SAAS,UAAU,OAAO,QAAQ,SAAS,EAAE,IACpE,UACF;EACF,CAAC,EACH,CAAC,EAAE;;;CAGT,CAAC,CAAC,KAAK,MAAM;CAEb,OAAO,GACJ,GAAG,SAAS,SAAS,QACxB;AACF;;AAGA,SAAgB,oBAAoB,cAAyC;CAC3E,OAAO;AACT;AAEA,SAAgB,uBACd,cACkC;CAKlC,OAAO,EACL,6BAHc,CAAC,aAAa,EAAE,OAAO,uBAAS,CAAC,CAAC,CAAC,CAAC,KAAK,IAGpB,EACrC;AACF;;AAGA,SAAgB,oBAAoB,cAAyC;CAC3E,OAAO;AACT"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { script } from "./format.mjs";
|
|
2
1
|
import { genArrayFromRaw, genExport, genImport, genObjectFromRaw, genObjectFromRawEntries, genSafeVariableName, genString } from "knitwork";
|
|
3
|
-
|
|
2
|
+
import { script } from "./format.mjs";
|
|
3
|
+
// src/context/internal/virtual.ts
|
|
4
4
|
function genConnectorModuleVariableName(dbModuleIndex) {
|
|
5
5
|
return genSafeVariableName(`dbModule${dbModuleIndex}`);
|
|
6
6
|
}
|
|
@@ -138,7 +138,6 @@ function migrationsVirtualModule(datasources, options) {
|
|
|
138
138
|
`);
|
|
139
139
|
return { "#nitro-drizzle/migrations": parts.join("\n") };
|
|
140
140
|
}
|
|
141
|
-
//#endregion
|
|
142
141
|
export { dialectVirtualModules, migrationsVirtualModule, runtimeVirtualModule };
|
|
143
142
|
|
|
144
143
|
//# sourceMappingURL=virtual.mjs.map
|
package/dist/context.d.mts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { ConsolaInstance } from "consola";
|
|
2
|
-
import { MaybePromise, NitroHookName, VirtualModules } from "nitro-drizzle/shared";
|
|
3
2
|
import { Config } from "drizzle-kit";
|
|
3
|
+
import { MaybePromise, NitroHookName, VirtualModules } from "nitro-drizzle/shared";
|
|
4
4
|
import { ServerAssetDir } from "nitropack/types";
|
|
5
5
|
import { ServerAssetDir as ServerAssetDir$1 } from "nitro/types";
|
|
6
|
-
//#region src/context/index.d.ts
|
|
7
6
|
/**
|
|
8
7
|
* Context interface for managing Drizzle datasource configurations.
|
|
9
8
|
*/
|
|
10
|
-
interface Context {
|
|
9
|
+
export interface Context {
|
|
11
10
|
init(): MaybePromise<void>;
|
|
12
11
|
/**
|
|
13
12
|
* Reloads the context, clearing any cached datasource information.
|
|
@@ -21,24 +20,24 @@ interface Context {
|
|
|
21
20
|
/**
|
|
22
21
|
* Glob pattern or array of patterns to match Drizzle configuration files.
|
|
23
22
|
*/
|
|
24
|
-
type ConfigPattern = string | readonly string[];
|
|
23
|
+
export type ConfigPattern = string | readonly string[];
|
|
25
24
|
/**
|
|
26
25
|
* Resolver interface for importing modules and resolving paths.
|
|
27
26
|
*/
|
|
28
|
-
interface Resolver {
|
|
27
|
+
export interface Resolver {
|
|
29
28
|
/**
|
|
30
29
|
* Resolves a module ID to its full path.
|
|
31
30
|
*/
|
|
32
31
|
resolve(id: string): string;
|
|
33
32
|
}
|
|
34
|
-
type ContextHook<TArgs extends readonly any[] = []> = (this: void, ...args: TArgs) => MaybePromise<void>;
|
|
35
|
-
interface MigrationOptions {
|
|
33
|
+
export type ContextHook<TArgs extends readonly any[] = []> = (this: void, ...args: TArgs) => MaybePromise<void>;
|
|
34
|
+
export interface MigrationOptions {
|
|
36
35
|
/** Base storage key path for migrations. */
|
|
37
36
|
storageBase: string;
|
|
38
37
|
/** Whether and which datasources to migrate on initialization. */
|
|
39
38
|
migrateOnInit: boolean | readonly string[];
|
|
40
39
|
}
|
|
41
|
-
interface ContextOptions {
|
|
40
|
+
export interface ContextOptions {
|
|
42
41
|
legacy: boolean;
|
|
43
42
|
logger?: ConsolaInstance;
|
|
44
43
|
/**
|
|
@@ -75,7 +74,7 @@ interface ContextOptions {
|
|
|
75
74
|
description: string;
|
|
76
75
|
}>]>;
|
|
77
76
|
plugins: ContextHook<[plugins: readonly string[]]>;
|
|
78
|
-
|
|
77
|
+
types: ContextHook<[declarations: {
|
|
79
78
|
shared: VirtualModules<`${string}.d.ts`>;
|
|
80
79
|
module: VirtualModules<`${string}.d.ts`>;
|
|
81
80
|
runtime: VirtualModules<`${string}.d.ts`>;
|
|
@@ -90,11 +89,11 @@ interface ContextOptions {
|
|
|
90
89
|
* @param options - Configuration options for the context
|
|
91
90
|
* @returns A Context instance
|
|
92
91
|
*/
|
|
93
|
-
declare function createContext(options: ContextOptions): Context;
|
|
92
|
+
export declare function createContext(options: ContextOptions): Context;
|
|
94
93
|
/**
|
|
95
94
|
* Information about a resolved Drizzle datasource.
|
|
96
95
|
*/
|
|
97
|
-
interface DatasourceInfo {
|
|
96
|
+
export interface DatasourceInfo {
|
|
98
97
|
/** Unique name identifier for the datasource. */
|
|
99
98
|
name: string;
|
|
100
99
|
/** Whether the datasource is enabled (filtered by connector configuration). */
|
|
@@ -103,7 +102,7 @@ interface DatasourceInfo {
|
|
|
103
102
|
drivers: readonly DriverOptions[];
|
|
104
103
|
}
|
|
105
104
|
/** Options for a specific driver within a datasource. */
|
|
106
|
-
type DriverOptions = {
|
|
105
|
+
export type DriverOptions = {
|
|
107
106
|
enabled: boolean;
|
|
108
107
|
name: string;
|
|
109
108
|
dialect: string;
|
|
@@ -117,7 +116,4 @@ type DriverOptions = {
|
|
|
117
116
|
assets?: string;
|
|
118
117
|
config?: Config["migrations"];
|
|
119
118
|
};
|
|
120
|
-
};
|
|
121
|
-
//#endregion
|
|
122
|
-
export { ConfigPattern, Context, ContextHook, ContextOptions, DatasourceInfo, DriverOptions, MigrationOptions, Resolver, createContext };
|
|
123
|
-
//# sourceMappingURL=context.d.mts.map
|
|
119
|
+
};
|
package/dist/context.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import { colorize } from "consola/utils";
|
|
2
|
+
import { loadConfig } from "c12";
|
|
3
|
+
import { pkgDir, pkgName } from "nitro-drizzle/meta";
|
|
1
4
|
import { mapAsync } from "./context/internal/async.mjs";
|
|
2
5
|
import { accent } from "./context/internal/logger.mjs";
|
|
3
6
|
import { resolveFiles } from "./context/internal/fs.mjs";
|
|
4
|
-
import { genReference } from "./context/internal/codegen.mjs";
|
|
5
7
|
import { dialectDeclarations, moduleTypeDeclarations, runtimeDeclarations, sharedTypeDeclarations } from "./context/internal/templates.mjs";
|
|
6
8
|
import { transformDrizzleConfig } from "./context/internal/config.mjs";
|
|
7
9
|
import { dialectVirtualModules, migrationsVirtualModule, runtimeVirtualModule } from "./context/internal/virtual.mjs";
|
|
8
10
|
import { join } from "pathe";
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
import { loadConfig } from "c12";
|
|
12
|
-
//#region src/context/index.ts
|
|
11
|
+
import { genReference } from "./context/internal/codegen.mjs";
|
|
12
|
+
// src/context/index.ts
|
|
13
13
|
var DefaultContext = class {
|
|
14
14
|
#datasources = null;
|
|
15
15
|
#options;
|
|
@@ -27,7 +27,7 @@ var DefaultContext = class {
|
|
|
27
27
|
this.runtimeTypeDeclarations(datasources)
|
|
28
28
|
]);
|
|
29
29
|
await this.#options.virtualModules(virtualModules);
|
|
30
|
-
await this.#options.
|
|
30
|
+
await this.#options.types({
|
|
31
31
|
shared: sharedTypes,
|
|
32
32
|
module: moduleTypes,
|
|
33
33
|
runtime: runtimeTypes,
|
|
@@ -168,7 +168,7 @@ var DefaultContext = class {
|
|
|
168
168
|
if (migrationOptions ? Array.isArray(migrationOptions) ? 0 < migrationOptions.length : true == migrationOptions.migrateOnInit : false) plugins.push("migrate");
|
|
169
169
|
plugins.push("init");
|
|
170
170
|
let pluginIds = plugins;
|
|
171
|
-
if (this.#options.legacy) pluginIds = pluginIds.map((pluginName) =>
|
|
171
|
+
if (this.#options.legacy) pluginIds = pluginIds.map((pluginName) => `${pluginName}/legacy`);
|
|
172
172
|
pluginIds = pluginIds.map((pluginName) => `nitro-drizzle/plugins/${pluginName}`);
|
|
173
173
|
return pluginIds;
|
|
174
174
|
}
|
|
@@ -215,7 +215,6 @@ function driverToDialect(driver) {
|
|
|
215
215
|
function createContext(options) {
|
|
216
216
|
return new DefaultContext(options);
|
|
217
217
|
}
|
|
218
|
-
//#endregion
|
|
219
218
|
export { createContext };
|
|
220
219
|
|
|
221
220
|
//# sourceMappingURL=context.mjs.map
|
package/dist/context.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.mjs","names":[],"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 moduleTypeDeclarations,\n runtimeDeclarations,\n sharedTypeDeclarations,\n} from \"./internal/templates\";\nimport { transformDrizzleConfig } from \"./internal/config\";\nimport {\n dialectVirtualModules,\n migrationsVirtualModule,\n runtimeVirtualModule,\n} from \"./internal/virtual\";\n\nimport type { MaybePromise, NitroHookName, VirtualModules } from \"nitro-drizzle/shared\";\nimport type { ServerAssetDir as LegacyServerAssetDir } from \"nitropack/types\";\nimport type { ServerAssetDir } from \"nitro/types\";\nimport { join } from \"pathe\";\nimport { genReference } from \"./internal/codegen\";\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 [sharedTypes, virtualModules, virtualTypes, moduleTypes, runtimeTypes] =\n await Promise.all([\n sharedTypeDeclarations(datasources),\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 shared: sharedTypes,\n module: moduleTypes,\n runtime: runtimeTypes,\n virtual: virtualTypes,\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 const drizzleConfigs = [\n ...(await mapAsync(drizzleConfigsResolvedPaths, async (path) => {\n const [_, dirName] = path.match(/(.+\\/(.+))\\/.+$/)!.slice(1, 3) as [string, string];\n const { config } = await loadConfig<DrizzleConfig>({\n configFile: path,\n });\n\n return await transformDrizzleConfig(config, {\n cwd: this.#options.cwd,\n path,\n dirName,\n resolver,\n });\n })),\n ].sort((a, b) => {\n if (a.driver && b.driver) {\n return 0;\n }\n return 1;\n });\n\n const datasources: DatasourceInfo[] = Object.entries(datasourceOptions).map(\n ([name, options]) => {\n const connectorOptions = Array.isArray(options.drivers)\n ? (options.drivers as string[]).reduce(\n (acc, driver) => {\n const match = driver.match(/^([_-]*)([^_]+)/);\n if (!match) throw new Error(\"Invalid driver name format\");\n const [_, disabled, driverName] = match;\n return {\n ...acc,\n [driverName]: { enabled: !disabled },\n };\n },\n {} as { [driver: string]: { enabled: boolean } },\n )\n : Object.entries(options.drivers as { [name: string]: boolean }).reduce(\n (acc, [name, enabled]) => {\n return {\n ...acc,\n [name]: { enabled },\n };\n },\n {} as { [driver: string]: { enabled: boolean } },\n );\n\n return {\n name,\n enabled: true,\n drivers: Object.entries(connectorOptions)\n .map(([driverName, options]) => {\n const dialect = driverToDialect(driverName);\n const drizzleConfig = drizzleConfigs.find((config) => {\n return config.name == name && config.dialect == dialect;\n });\n return {\n enabled: options.enabled,\n name: driverName,\n dialect,\n imports: {\n connector: `nitro-drizzle/drivers/${driverName}`,\n helpers: `nitro-drizzle/dialects/${dialect}`,\n schema: drizzleConfig?.imports.schema || [],\n },\n migrations: {\n ...drizzleConfig?.migrations,\n },\n };\n })\n .sort((a, b) => (b.enabled ? 1 : 0) - (a.enabled ? 1 : 0)),\n } satisfies DatasourceInfo;\n },\n );\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 = \"yellow\";\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 \"\\n\\t\",\n colorize(\"yellow\", datasource.name),\n \"(\" +\n datasource.drivers\n .map((driver) => {\n const [color, postfix] = driver.enabled\n ? ([\"greenBright\", \"\"] as const)\n : ([\"strikethrough\", \" (types only)\"] as const);\n\n return colorize(\"gray\", [colorize(color, driver.name), postfix].join(\"\"));\n })\n .join(\", \") +\n \")\",\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 | LegacyServerAssetDir)[]> {\n const migrationOptions = this.#options.migrations;\n\n if (!migrationOptions) {\n return [];\n }\n\n return datasources\n .flatMap((datasource) => {\n return datasource.drivers.map((driver) => {\n return {\n name: datasource.name,\n driver: driver.name,\n dialect: driver.dialect,\n migrations: driver.migrations,\n };\n });\n })\n .reduce(\n (acc, { name, driver, migrations }) => {\n const dir = migrations.assets;\n if (dir) {\n acc.push({\n baseName: [migrationOptions.storageBase, name, driver].join(\":\"),\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 },\n [] as (ServerAssetDir | LegacyServerAssetDir)[],\n );\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 initHooks: this.#options.initHooks,\n }),\n ...dialectVirtualModules(datasources),\n ...migrationsVirtualModule(datasources, this.#options.migrations),\n };\n }\n\n reload() {\n this.#datasources = null;\n }\n}\n\nfunction driverToDialect(driver: string) {\n let dialect = driver;\n if (driver.startsWith(\"d1\")) {\n dialect = \"sqlite\";\n }\n if (driver == \"pglite\") {\n dialect = \"postgresql\";\n }\n return dialect;\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, { drivers: readonly string[] | { [name: string]: boolean } }>;\n\n migrations: MigrationOptions | undefined;\n\n /**\n * Hooks that allowed to call \"drizzle:init\" hook.\n */\n initHooks?: readonly NitroHookName[];\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 shared: VirtualModules<`${string}.d.ts`>;\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 | LegacyServerAssetDir)[]]>;\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 /** Unique name identifier for the datasource. */\n name: string;\n /** Whether the datasource is enabled (filtered by connector configuration). */\n enabled: boolean;\n /** Driver configurations for this datasource. */\n drivers: readonly DriverOptions[];\n}\n\n/** Options for a specific driver within a datasource. */\nexport type DriverOptions = {\n enabled: boolean;\n name: string;\n dialect: string;\n imports: {\n // config: string;\n schema: readonly string[];\n connector: string;\n helpers: string;\n };\n /** Migration configuration for this datasource driver. */\n migrations: {\n assets?: string;\n config?: Config[\"migrations\"];\n };\n};\n"],"mappings":";;;;;;;;;;;;AA2CA,IAAM,iBAAN,MAAwC;CACtC,eAAwC;CACxC;CAEA,YAAY,SAAyB;EACnC,KAAK,WAAW;CAClB;CAEA,MAAM,OAAsB;EAC1B,MAAM,cAAc,MAAM,KAAK,YAAY;EAE3C,MAAM,KAAK,SAAS,QAAQ,KAAK,eAAe,CAAC;EAEjD,MAAM,CAAC,aAAa,gBAAgB,cAAc,aAAa,gBAC7D,MAAM,QAAQ,IAAI;GAChB,uBAAuB,WAAW;GAClC,KAAK,eAAe,WAAW;GAC/B,KAAK,wBAAwB,WAAW;GACxC,KAAK,uBAAuB,WAAW;GACvC,KAAK,wBAAwB,WAAW;EAC1C,CAAC;EAEH,MAAM,KAAK,SAAS,eAAe,cAAc;EAEjD,MAAM,KAAK,SAAS,aAAa;GAC/B,QAAQ;GACR,QAAQ;GACR,SAAS;GACT,SAAS;EACX,CAAC;EAED,IAAI,KAAK,SAAS,YAAY;GAC5B,MAAM,SAAS,MAAM,KAAK,gBAAgB,WAAW;GACrD,IAAI,QACF,MAAM,KAAK,SAAS,OAAO,MAAM;GAGnC,MAAM,KAAK,SAAS,QAAQ,EAC1B,mBAAmB;IACjB,aAAa;IACb,SAAS;GACX,EACF,CAAC;EACH;EAEA,IAAI,KAAK,SAAS,WAAW;GAC3B,MAAM,kBAAkB;IAAC;IAAW;IAAW;GAAY,CAAC,CAAC,SAAS,OAAO;IAC3E,OAAO,CAAC,KAAK,SAAS,EAAE,GAAG,KAAK,QAAQ,QAAQ,EAA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AEA,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,KAAK,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,KAAK,SAAS;IAC3B,mBAAmB;IACnB,WAAW,KAAK,SAAS;GAC3B,CAAC;GACD,GAAG,sBAAsB,WAAW;GACpC,GAAG,wBAAwB,aAAa,KAAK,SAAS,UAAU;EAClE;CACF;CAEA,SAAS;EACP,KAAK,eAAe;CACtB;AACF;AAEA,SAAS,gBAAgB,QAAgB;CACvC,IAAI,UAAU;CACd,IAAI,OAAO,WAAW,IAAI,GACxB,UAAU;CAEZ,IAAI,UAAU,UACZ,UAAU;CAEZ,OAAO;AACT;;;;;;AAkGA,SAAgB,cAAc,SAAkC;CAC9D,OAAO,IAAI,eAAe,OAAO;AACnC"}
|
|
1
|
+
{"version":3,"file":"context.mjs","names":[],"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 moduleTypeDeclarations,\n runtimeDeclarations,\n sharedTypeDeclarations,\n} from \"./internal/templates\";\nimport { transformDrizzleConfig } from \"./internal/config\";\nimport {\n dialectVirtualModules,\n migrationsVirtualModule,\n runtimeVirtualModule,\n} from \"./internal/virtual\";\n\nimport type { MaybePromise, NitroHookName, VirtualModules } from \"nitro-drizzle/shared\";\nimport type { ServerAssetDir as LegacyServerAssetDir } from \"nitropack/types\";\nimport type { ServerAssetDir } from \"nitro/types\";\nimport { join } from \"pathe\";\nimport { genReference } from \"./internal/codegen\";\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 [sharedTypes, virtualModules, virtualTypes, moduleTypes, runtimeTypes] =\n await Promise.all([\n sharedTypeDeclarations(datasources),\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.types({\n shared: sharedTypes,\n module: moduleTypes,\n runtime: runtimeTypes,\n virtual: virtualTypes,\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 const drizzleConfigs = [\n ...(await mapAsync(drizzleConfigsResolvedPaths, async (path) => {\n const [_, dirName] = path.match(/(.+\\/(.+))\\/.+$/)!.slice(1, 3) as [string, string];\n const { config } = await loadConfig<DrizzleConfig>({\n configFile: path,\n });\n\n return await transformDrizzleConfig(config, {\n cwd: this.#options.cwd,\n path,\n dirName,\n resolver,\n });\n })),\n ].sort((a, b) => {\n if (a.driver && b.driver) {\n return 0;\n }\n return 1;\n });\n\n const datasources: DatasourceInfo[] = Object.entries(datasourceOptions).map(\n ([name, options]) => {\n const connectorOptions = Array.isArray(options.drivers)\n ? (options.drivers as string[]).reduce(\n (acc, driver) => {\n const match = driver.match(/^([_-]*)([^_]+)/);\n if (!match) throw new Error(\"Invalid driver name format\");\n const [_, disabled, driverName] = match;\n return {\n ...acc,\n [driverName]: { enabled: !disabled },\n };\n },\n {} as { [driver: string]: { enabled: boolean } },\n )\n : Object.entries(options.drivers as { [name: string]: boolean }).reduce(\n (acc, [name, enabled]) => {\n return {\n ...acc,\n [name]: { enabled },\n };\n },\n {} as { [driver: string]: { enabled: boolean } },\n );\n\n return {\n name,\n enabled: true,\n drivers: Object.entries(connectorOptions)\n .map(([driverName, options]) => {\n const dialect = driverToDialect(driverName);\n const drizzleConfig = drizzleConfigs.find((config) => {\n return config.name == name && config.dialect == dialect;\n });\n return {\n enabled: options.enabled,\n name: driverName,\n dialect,\n imports: {\n connector: `nitro-drizzle/drivers/${driverName}`,\n helpers: `nitro-drizzle/dialects/${dialect}`,\n schema: drizzleConfig?.imports.schema || [],\n },\n migrations: {\n ...drizzleConfig?.migrations,\n },\n };\n })\n .sort((a, b) => (b.enabled ? 1 : 0) - (a.enabled ? 1 : 0)),\n } satisfies DatasourceInfo;\n },\n );\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 = \"yellow\";\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 \"\\n\\t\",\n colorize(\"yellow\", datasource.name),\n \"(\" +\n datasource.drivers\n .map((driver) => {\n const [color, postfix] = driver.enabled\n ? ([\"greenBright\", \"\"] as const)\n : ([\"strikethrough\", \" (types only)\"] as const);\n\n return colorize(\"gray\", [colorize(color, driver.name), postfix].join(\"\"));\n })\n .join(\", \") +\n \")\",\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 | LegacyServerAssetDir)[]> {\n const migrationOptions = this.#options.migrations;\n\n if (!migrationOptions) {\n return [];\n }\n\n return datasources\n .flatMap((datasource) => {\n return datasource.drivers.map((driver) => {\n return {\n name: datasource.name,\n driver: driver.name,\n dialect: driver.dialect,\n migrations: driver.migrations,\n };\n });\n })\n .reduce(\n (acc, { name, driver, migrations }) => {\n const dir = migrations.assets;\n if (dir) {\n acc.push({\n baseName: [migrationOptions.storageBase, name, driver].join(\":\"),\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 },\n [] as (ServerAssetDir | LegacyServerAssetDir)[],\n );\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) => `${pluginName}/legacy`);\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 initHooks: this.#options.initHooks,\n }),\n ...dialectVirtualModules(datasources),\n ...migrationsVirtualModule(datasources, this.#options.migrations),\n };\n }\n\n reload() {\n this.#datasources = null;\n }\n}\n\nfunction driverToDialect(driver: string) {\n let dialect = driver;\n if (driver.startsWith(\"d1\")) {\n dialect = \"sqlite\";\n }\n if (driver == \"pglite\") {\n dialect = \"postgresql\";\n }\n return dialect;\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, { drivers: readonly string[] | { [name: string]: boolean } }>;\n\n migrations: MigrationOptions | undefined;\n\n /**\n * Hooks that allowed to call \"drizzle:init\" hook.\n */\n initHooks?: readonly NitroHookName[];\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 types: ContextHook<\n [\n declarations: {\n shared: VirtualModules<`${string}.d.ts`>;\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 | LegacyServerAssetDir)[]]>;\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 /** Unique name identifier for the datasource. */\n name: string;\n /** Whether the datasource is enabled (filtered by connector configuration). */\n enabled: boolean;\n /** Driver configurations for this datasource. */\n drivers: readonly DriverOptions[];\n}\n\n/** Options for a specific driver within a datasource. */\nexport type DriverOptions = {\n enabled: boolean;\n name: string;\n dialect: string;\n imports: {\n // config: string;\n schema: readonly string[];\n connector: string;\n helpers: string;\n };\n /** Migration configuration for this datasource driver. */\n migrations: {\n assets?: string;\n config?: Config[\"migrations\"];\n };\n};\n"],"mappings":";;;;;;;;;;;;AA2CA,IAAM,iBAAN,MAAwC;CACtC,eAAwC;CAC/B;CAET,YAAY,SAAyB;EACnC,KAAK,WAAW;CAClB;CAEA,MAAM,OAAsB;EAC1B,MAAM,cAAc,MAAM,KAAK,YAAY;EAE3C,MAAM,KAAK,SAAS,QAAQ,KAAK,eAAe,CAAC;EAEjD,MAAM,CAAC,aAAa,gBAAgB,cAAc,aAAa,gBAC7D,MAAM,QAAQ,IAAI;GAChB,uBAAuB,WAAW;GAClC,KAAK,eAAe,WAAW;GAC/B,KAAK,wBAAwB,WAAW;GACxC,KAAK,uBAAuB,WAAW;GACvC,KAAK,wBAAwB,WAAW;EAC1C,CAAC;EAEH,MAAM,KAAK,SAAS,eAAe,cAAc;EAEjD,MAAM,KAAK,SAAS,MAAM;GACxB,QAAQ;GACR,QAAQ;GACR,SAAS;GACT,SAAS;EACX,CAAC;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AEZ,IAAI,UAAU,UACZ,UAAU;CAEZ,OAAO;AACT;;;;;;AAkGA,SAAgB,cAAc,SAAkC;CAC9D,OAAO,IAAI,eAAe,OAAO;AACnC"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { InferMysqlTable } from "./mysql.mjs";
|
|
2
|
-
import { InferPgTable } from "./postgresql.mjs";
|
|
3
|
-
import { InferSqliteTable } from "./sqlite.mjs";
|
|
4
1
|
import { Column, SQL, Table } from "drizzle-orm";
|
|
5
|
-
import { SQLiteInsertBase } from "drizzle-orm/sqlite-core";
|
|
6
2
|
import { MySqlInsertBase } from "drizzle-orm/mysql-core";
|
|
3
|
+
import { InferMysqlTable } from "./mysql.mjs";
|
|
7
4
|
import { PgInsertBase } from "drizzle-orm/pg-core";
|
|
8
|
-
|
|
5
|
+
import { InferPgTable } from "./postgresql.mjs";
|
|
6
|
+
import { SQLiteInsertBase } from "drizzle-orm/sqlite-core";
|
|
7
|
+
import { InferSqliteTable } from "./sqlite.mjs";
|
|
9
8
|
interface OnConflictOptions<TSet extends Record<string, SQL | undefined>> {
|
|
10
9
|
set: TSet;
|
|
11
10
|
}
|
|
@@ -13,26 +12,24 @@ interface OnConflictOptions<TSet extends Record<string, SQL | undefined>> {
|
|
|
13
12
|
* Options for ON CONFLICT DO UPDATE clause.
|
|
14
13
|
* @template T - The insert type
|
|
15
14
|
*/
|
|
16
|
-
type OnConflictDoUpdateOptions<T extends AnyInsert> = OnConflictOptions<{ [K in keyof InferColumns<InferTable<T>>]?: SQL; }>;
|
|
15
|
+
export type OnConflictDoUpdateOptions<T extends AnyInsert> = OnConflictOptions<{ [K in keyof InferColumns<InferTable<T>>]?: SQL; }>;
|
|
17
16
|
/**
|
|
18
17
|
* Infers column types from a Drizzle table.
|
|
19
18
|
* @template TTable - The table type
|
|
20
19
|
*/
|
|
21
|
-
type InferColumns<TTable extends Table> = TTable extends Table<infer TTableConfig> ? TTableConfig["columns"] : never;
|
|
20
|
+
export type InferColumns<TTable extends Table> = TTable extends Table<infer TTableConfig> ? TTableConfig["columns"] : never;
|
|
22
21
|
type AnyInsert = MySqlInsertBase<any, any, any, any, any, any> | PgInsertBase<any, any, any, any, any, any> | SQLiteInsertBase<any, any, any, any, any, any>;
|
|
23
22
|
/**
|
|
24
23
|
* Infers the table type from an insert statement.
|
|
25
24
|
* @template T - The insert type
|
|
26
25
|
*/
|
|
27
|
-
type InferTable<T extends AnyInsert> = T extends MySqlInsertBase<any, any, any, any, any, any> ? InferMysqlTable<T> : T extends PgInsertBase<any, any, any, any, any, any> ? InferPgTable<T> : T extends SQLiteInsertBase<any, any, any, any, any, any> ? InferSqliteTable<T> : never;
|
|
26
|
+
export type InferTable<T extends AnyInsert> = T extends MySqlInsertBase<any, any, any, any, any, any> ? InferMysqlTable<T> : T extends PgInsertBase<any, any, any, any, any, any> ? InferPgTable<T> : T extends SQLiteInsertBase<any, any, any, any, any, any> ? InferSqliteTable<T> : never;
|
|
28
27
|
type RemoveNeverProps<T extends Record<string, any>> = { [K in keyof T as T[K] extends never ? never : K]: T[K]; };
|
|
29
28
|
/**
|
|
30
29
|
* Infers primary key columns from a Drizzle table.
|
|
31
30
|
* @template T - The table type
|
|
32
31
|
*/
|
|
33
|
-
type InferPrimaryColumns<T extends Table> = RemoveNeverProps<{ [K in keyof InferColumns<T>]: InferColumns<T>[K] extends Column<infer TColumnConfig> ? Extract<TColumnConfig, {
|
|
32
|
+
export type InferPrimaryColumns<T extends Table> = RemoveNeverProps<{ [K in keyof InferColumns<T>]: InferColumns<T>[K] extends Column<infer TColumnConfig> ? Extract<TColumnConfig, {
|
|
34
33
|
isPrimaryKey: true;
|
|
35
34
|
}> extends never ? never : InferColumns<T>[K] : never; }>;
|
|
36
|
-
|
|
37
|
-
export { InferColumns, InferPrimaryColumns, InferTable, OnConflictDoUpdateOptions };
|
|
38
|
-
//# sourceMappingURL=index.d.mts.map
|
|
35
|
+
export {};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { InferPrimaryColumns, InferTable, OnConflictDoUpdateOptions } from "./index.mjs";
|
|
2
1
|
import { MySqlInsertBase } from "drizzle-orm/mysql-core";
|
|
3
|
-
|
|
2
|
+
import { InferPrimaryColumns, InferTable, OnConflictDoUpdateOptions } from "./index.mjs";
|
|
4
3
|
/**
|
|
5
4
|
* Adds an ON CONFLICT DO UPDATE clause to a MySQL insert statement.
|
|
6
5
|
* @template TInsert - The insert type
|
|
@@ -9,7 +8,7 @@ import { MySqlInsertBase } from "drizzle-orm/mysql-core";
|
|
|
9
8
|
* @param options - Options containing the SET values
|
|
10
9
|
* @returns The modified insert statement
|
|
11
10
|
*/
|
|
12
|
-
declare function onConflictDoUpdate<TInsert extends MySqlInsertBase<any, any, any, any, any, any>>(_: InferPrimaryColumns<InferTable<TInsert>>, insert: TInsert, options: OnConflictDoUpdateOptions<TInsert>): TInsert | Omit<MySqlInsertBase<TInsert["_"]["table"], TInsert["_"]["queryResult"], TInsert["_"]["preparedQueryHKT"], TInsert["_"]["returning"], any, "$returning" | TInsert["_"]["excludedMethods"]>, "onDuplicateKeyUpdate" | TInsert["_"]["excludedMethods"]>;
|
|
11
|
+
export declare function onConflictDoUpdate<TInsert extends MySqlInsertBase<any, any, any, any, any, any>>(_: InferPrimaryColumns<InferTable<TInsert>>, insert: TInsert, options: OnConflictDoUpdateOptions<TInsert>): TInsert | Omit<MySqlInsertBase<TInsert["_"]["table"], TInsert["_"]["queryResult"], TInsert["_"]["preparedQueryHKT"], TInsert["_"]["returning"], any, "$returning" | TInsert["_"]["excludedMethods"]>, "onDuplicateKeyUpdate" | TInsert["_"]["excludedMethods"]>;
|
|
13
12
|
/**
|
|
14
13
|
* Adds an ON CONFLICT DO NOTHING clause to a MySQL insert statement.
|
|
15
14
|
* Uses ON DUPLICATE KEY UPDATE with the primary key values for equivalent behavior.
|
|
@@ -18,12 +17,9 @@ declare function onConflictDoUpdate<TInsert extends MySqlInsertBase<any, any, an
|
|
|
18
17
|
* @param insert - The insert statement
|
|
19
18
|
* @returns The modified insert statement
|
|
20
19
|
*/
|
|
21
|
-
declare function onConflictDoNothing<TInsert extends MySqlInsertBase<any, any, any, any, any, any>>(target: InferPrimaryColumns<InferTable<TInsert>>, insert: TInsert): TInsert | Omit<MySqlInsertBase<TInsert["_"]["table"], TInsert["_"]["queryResult"], TInsert["_"]["preparedQueryHKT"], TInsert["_"]["returning"], any, "$returning" | TInsert["_"]["excludedMethods"]>, "onDuplicateKeyUpdate" | TInsert["_"]["excludedMethods"]>;
|
|
20
|
+
export declare function onConflictDoNothing<TInsert extends MySqlInsertBase<any, any, any, any, any, any>>(target: InferPrimaryColumns<InferTable<TInsert>>, insert: TInsert): TInsert | Omit<MySqlInsertBase<TInsert["_"]["table"], TInsert["_"]["queryResult"], TInsert["_"]["preparedQueryHKT"], TInsert["_"]["returning"], any, "$returning" | TInsert["_"]["excludedMethods"]>, "onDuplicateKeyUpdate" | TInsert["_"]["excludedMethods"]>;
|
|
22
21
|
/**
|
|
23
22
|
* Infers the table type from a MySQL insert statement.
|
|
24
23
|
* @template T - The insert type
|
|
25
24
|
*/
|
|
26
|
-
type InferMysqlTable<T extends MySqlInsertBase<any, any, any, any, any, any>> = T extends MySqlInsertBase<infer TTable, any, any, any, any, any> ? TTable : never;
|
|
27
|
-
//#endregion
|
|
28
|
-
export { InferMysqlTable, onConflictDoNothing, onConflictDoUpdate };
|
|
29
|
-
//# sourceMappingURL=mysql.d.mts.map
|
|
25
|
+
export type InferMysqlTable<T extends MySqlInsertBase<any, any, any, any, any, any>> = T extends MySqlInsertBase<infer TTable, any, any, any, any, any> ? TTable : never;
|
package/dist/dialects/mysql.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { sql } from "drizzle-orm/sql";
|
|
2
|
-
|
|
2
|
+
// src/dialects/mysql.ts
|
|
3
3
|
/**
|
|
4
4
|
* Adds an ON CONFLICT DO UPDATE clause to a MySQL insert statement.
|
|
5
5
|
* @template TInsert - The insert type
|
|
@@ -24,7 +24,6 @@ function onConflictDoNothing(target, insert) {
|
|
|
24
24
|
return [name, sql`${column}`];
|
|
25
25
|
})) });
|
|
26
26
|
}
|
|
27
|
-
//#endregion
|
|
28
27
|
export { onConflictDoNothing, onConflictDoUpdate };
|
|
29
28
|
|
|
30
29
|
//# sourceMappingURL=mysql.mjs.map
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { InferColumns, InferTable, OnConflictDoUpdateOptions } from "./index.mjs";
|
|
2
1
|
import { PgInsertBase } from "drizzle-orm/pg-core";
|
|
3
|
-
|
|
2
|
+
import { InferColumns, InferTable, OnConflictDoUpdateOptions } from "./index.mjs";
|
|
4
3
|
/**
|
|
5
4
|
* Adds an ON CONFLICT DO UPDATE clause to a PostgreSQL insert statement.
|
|
6
5
|
* @template TInsert - The insert type
|
|
@@ -9,7 +8,7 @@ import { PgInsertBase } from "drizzle-orm/pg-core";
|
|
|
9
8
|
* @param options - Options containing the SET values
|
|
10
9
|
* @returns The modified insert statement
|
|
11
10
|
*/
|
|
12
|
-
declare function onConflictDoUpdate<TInsert extends PgInsertBase<any, any, any>>(target: Partial<InferColumns<InferTable<TInsert>>>, insert: TInsert, options: OnConflictDoUpdateOptions<TInsert>): TInsert | Omit<PgInsertBase<TInsert["_"]["table"], TInsert["_"]["queryResult"], TInsert["_"]["selectedFields"], TInsert["_"]["returning"], any, "onConflictDoNothing" | "onConflictDoUpdate" | TInsert["_"]["excludedMethods"]>, "onConflictDoNothing" | "onConflictDoUpdate" | TInsert["_"]["excludedMethods"]>;
|
|
11
|
+
export declare function onConflictDoUpdate<TInsert extends PgInsertBase<any, any, any>>(target: Partial<InferColumns<InferTable<TInsert>>>, insert: TInsert, options: OnConflictDoUpdateOptions<TInsert>): TInsert | Omit<PgInsertBase<TInsert["_"]["table"], TInsert["_"]["queryResult"], TInsert["_"]["selectedFields"], TInsert["_"]["returning"], any, "onConflictDoNothing" | "onConflictDoUpdate" | TInsert["_"]["excludedMethods"]>, "onConflictDoNothing" | "onConflictDoUpdate" | TInsert["_"]["excludedMethods"]>;
|
|
13
12
|
/**
|
|
14
13
|
* Adds an ON CONFLICT DO NOTHING clause to a PostgreSQL insert statement.
|
|
15
14
|
* @template TInsert - The insert type
|
|
@@ -17,12 +16,9 @@ declare function onConflictDoUpdate<TInsert extends PgInsertBase<any, any, any>>
|
|
|
17
16
|
* @param insert - The insert statement
|
|
18
17
|
* @returns The modified insert statement with DO NOTHING
|
|
19
18
|
*/
|
|
20
|
-
declare function onConflictDoNothing<TInsert extends PgInsertBase<any, any, any>>(target: Partial<InferColumns<InferTable<TInsert>>>, insert: TInsert): TInsert | Omit<PgInsertBase<TInsert["_"]["table"], TInsert["_"]["queryResult"], TInsert["_"]["selectedFields"], TInsert["_"]["returning"], any, "onConflictDoNothing" | "onConflictDoUpdate" | TInsert["_"]["excludedMethods"]>, "onConflictDoNothing" | "onConflictDoUpdate" | TInsert["_"]["excludedMethods"]>;
|
|
19
|
+
export declare function onConflictDoNothing<TInsert extends PgInsertBase<any, any, any>>(target: Partial<InferColumns<InferTable<TInsert>>>, insert: TInsert): TInsert | Omit<PgInsertBase<TInsert["_"]["table"], TInsert["_"]["queryResult"], TInsert["_"]["selectedFields"], TInsert["_"]["returning"], any, "onConflictDoNothing" | "onConflictDoUpdate" | TInsert["_"]["excludedMethods"]>, "onConflictDoNothing" | "onConflictDoUpdate" | TInsert["_"]["excludedMethods"]>;
|
|
21
20
|
/**
|
|
22
21
|
* Infers the table type from a PostgreSQL insert statement.
|
|
23
22
|
* @template T - The insert type
|
|
24
23
|
*/
|
|
25
|
-
type InferPgTable<T extends PgInsertBase<any, any, any, any, any, any>> = T extends PgInsertBase<infer TTable, any, any, any, any, any> ? TTable : never;
|
|
26
|
-
//#endregion
|
|
27
|
-
export { InferPgTable, onConflictDoNothing, onConflictDoUpdate };
|
|
28
|
-
//# sourceMappingURL=postgresql.d.mts.map
|
|
24
|
+
export type InferPgTable<T extends PgInsertBase<any, any, any, any, any, any>> = T extends PgInsertBase<infer TTable, any, any, any, any, any> ? TTable : never;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/dialects/postgresql.ts
|
|
2
2
|
/**
|
|
3
3
|
* Adds an ON CONFLICT DO UPDATE clause to a PostgreSQL insert statement.
|
|
4
4
|
* @template TInsert - The insert type
|
|
@@ -23,7 +23,6 @@ function onConflictDoUpdate(target, insert, options) {
|
|
|
23
23
|
function onConflictDoNothing(target, insert) {
|
|
24
24
|
return insert.onConflictDoNothing({ target: Object.values(target) });
|
|
25
25
|
}
|
|
26
|
-
//#endregion
|
|
27
26
|
export { onConflictDoNothing, onConflictDoUpdate };
|
|
28
27
|
|
|
29
28
|
//# sourceMappingURL=postgresql.mjs.map
|