nitro-drizzle 0.3.0-beta.5 → 0.3.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,26 +1,34 @@
|
|
|
1
|
-
import { ConnectorSpecifier,
|
|
1
|
+
import { ConnectorSpecifier, UnwrapVariant, Variant } from "nitro-drizzle/shared";
|
|
2
2
|
import { DatasourceVariants, Datasources } from "nitro-drizzle/runtime";
|
|
3
3
|
import { Datasource, Schema } from "nitro-drizzle/drivers";
|
|
4
4
|
//#region src/runtime/useDialect.d.ts
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* Automatically resolves the
|
|
6
|
+
* Executes a callback with type-safe context (datasource, driver, dialect) for the specified datasource.
|
|
7
|
+
* Automatically resolves the active datasource, driver, and dialect based on the runtime configuration.
|
|
8
8
|
* @template TName - The datasource name
|
|
9
|
-
* @template
|
|
9
|
+
* @template TArgs - The dialect callback arguments type
|
|
10
|
+
* @template TReturn - The return type of the callback
|
|
10
11
|
* @param name - The datasource name
|
|
11
|
-
* @param
|
|
12
|
-
* @returns
|
|
12
|
+
* @param callback - The callback function receiving `{ datasource, driver, dialect }`
|
|
13
|
+
* @returns A promise that resolves to the return value of the callback
|
|
13
14
|
*/
|
|
14
|
-
declare function useDialect<TName extends keyof Datasources & string,
|
|
15
|
+
declare function useDialect<TName extends keyof Datasources & string, TArgs extends DialectCallbackArgs<TName>, TReturn>(name: TName, callback: DialectCallback<TName, TArgs, TReturn>): Promise<TReturn>;
|
|
16
|
+
type DialectCallbackArgsMapper<T extends Variant<Datasource<string, any, Schema>, ConnectorSpecifier>> = T extends Variant<infer V, infer S> ? Variant<Pick<S, "dialect" | "driver"> & {
|
|
17
|
+
datasource: V;
|
|
18
|
+
}, Pick<S, "name">> : never;
|
|
19
|
+
type DialectCallbackArgsVariants = DialectCallbackArgsMapper<DatasourceVariants>;
|
|
20
|
+
type DialectCallbackArgs<TName extends keyof Datasources & string> = UnwrapVariant<DialectCallbackArgsVariants, {
|
|
21
|
+
name: TName;
|
|
22
|
+
}>;
|
|
15
23
|
/**
|
|
16
|
-
*
|
|
24
|
+
* Callback function signature for `useDialect`.
|
|
17
25
|
* @template TName - The datasource name
|
|
18
|
-
* @template
|
|
26
|
+
* @template TArgs - The callback argument types
|
|
27
|
+
* @template TReturn - The return type of the callback
|
|
19
28
|
*/
|
|
20
|
-
type
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
type DialectHandlerArgs = ExpandVariants<DialectHandlerVariants, ["name", "dialect"]>;
|
|
29
|
+
type DialectCallback<TName extends keyof Datasources & string, TArgs extends DialectCallbackArgs<TName>, TReturn> = {
|
|
30
|
+
(args: TArgs): TReturn;
|
|
31
|
+
};
|
|
24
32
|
//#endregion
|
|
25
|
-
export { useDialect };
|
|
33
|
+
export { DialectCallback, useDialect };
|
|
26
34
|
//# sourceMappingURL=useDialect.d.mts.map
|
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
import { useDatasourceProvider } from "./internal/createDatasource.mjs";
|
|
2
|
-
import { useDatasource } from "nitro-drizzle/runtime";
|
|
2
|
+
import { useConfig, useDatasource } from "nitro-drizzle/runtime";
|
|
3
3
|
//#region src/runtime/useDialect.ts
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* Automatically resolves the
|
|
5
|
+
* Executes a callback with type-safe context (datasource, driver, dialect) for the specified datasource.
|
|
6
|
+
* Automatically resolves the active datasource, driver, and dialect based on the runtime configuration.
|
|
7
7
|
* @template TName - The datasource name
|
|
8
|
-
* @template
|
|
8
|
+
* @template TArgs - The dialect callback arguments type
|
|
9
|
+
* @template TReturn - The return type of the callback
|
|
9
10
|
* @param name - The datasource name
|
|
10
|
-
* @param
|
|
11
|
-
* @returns
|
|
11
|
+
* @param callback - The callback function receiving `{ datasource, driver, dialect }`
|
|
12
|
+
* @returns A promise that resolves to the return value of the callback
|
|
12
13
|
*/
|
|
13
|
-
async function useDialect(name,
|
|
14
|
+
async function useDialect(name, callback) {
|
|
14
15
|
const datasource = await useDatasource(name);
|
|
15
16
|
const { dialect } = useDatasourceProvider(name);
|
|
16
|
-
|
|
17
|
-
return await
|
|
17
|
+
const { driver } = useConfig(name);
|
|
18
|
+
return await callback({
|
|
19
|
+
datasource,
|
|
20
|
+
driver,
|
|
21
|
+
dialect
|
|
22
|
+
});
|
|
18
23
|
}
|
|
19
24
|
//#endregion
|
|
20
25
|
export { useDialect };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDialect.mjs","names":[],"sources":["../../src/runtime/useDialect.ts"],"sourcesContent":["import type { Datasource, Schema } from \"nitro-drizzle/drivers\";\nimport {
|
|
1
|
+
{"version":3,"file":"useDialect.mjs","names":[],"sources":["../../src/runtime/useDialect.ts"],"sourcesContent":["import type { Datasource, Schema } from \"nitro-drizzle/drivers\";\nimport {\n useConfig,\n useDatasource,\n type Datasources,\n type DatasourceVariants,\n} from \"nitro-drizzle/runtime\";\nimport type { ConnectorSpecifier, UnwrapVariant, Variant } from \"nitro-drizzle/shared\";\nimport { useDatasourceProvider } from \"./internal/createDatasource\";\n\n/**\n * Executes a callback with type-safe context (datasource, driver, dialect) for the specified datasource.\n * Automatically resolves the active datasource, driver, and dialect based on the runtime configuration.\n * @template TName - The datasource name\n * @template TArgs - The dialect callback arguments type\n * @template TReturn - The return type of the callback\n * @param name - The datasource name\n * @param callback - The callback function receiving `{ datasource, driver, dialect }`\n * @returns A promise that resolves to the return value of the callback\n */\nexport async function useDialect<\n TName extends keyof Datasources & string,\n TArgs extends DialectCallbackArgs<TName>,\n TReturn,\n>(name: TName, callback: DialectCallback<TName, TArgs, TReturn>): Promise<TReturn> {\n const datasource = await useDatasource(name);\n const { dialect } = useDatasourceProvider(name);\n const { driver } = useConfig(name);\n\n // @ts-expect-error\n return await callback({\n datasource,\n driver,\n dialect,\n });\n}\n\ntype DialectCallbackArgsMapper<\n T extends Variant<Datasource<string, any, Schema>, ConnectorSpecifier>,\n> =\n T extends Variant<infer V, infer S>\n ? Variant<Pick<S, \"dialect\" | \"driver\"> & { datasource: V }, Pick<S, \"name\">>\n : never;\n\ntype DialectCallbackArgsVariants = DialectCallbackArgsMapper<DatasourceVariants>;\n\ntype DialectCallbackArgs<TName extends keyof Datasources & string> = UnwrapVariant<\n DialectCallbackArgsVariants,\n { name: TName }\n>;\n\n/**\n * Callback function signature for `useDialect`.\n * @template TName - The datasource name\n * @template TArgs - The callback argument types\n * @template TReturn - The return type of the callback\n */\nexport type DialectCallback<\n TName extends keyof Datasources & string,\n TArgs extends DialectCallbackArgs<TName>,\n TReturn,\n> = {\n (args: TArgs): TReturn;\n};\n"],"mappings":";;;;;;;;;;;;;AAoBA,eAAsB,WAIpB,MAAa,UAAoE;CACjF,MAAM,aAAa,MAAM,cAAc,IAAI;CAC3C,MAAM,EAAE,YAAY,sBAAsB,IAAI;CAC9C,MAAM,EAAE,WAAW,UAAU,IAAI;CAGjC,OAAO,MAAM,SAAS;EACpB;EACA;EACA;CACF,CAAC;AACH"}
|
package/dist/runtime.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UseDatasourceOptions, useDatasource } from "./runtime/useDatasource.mjs";
|
|
2
|
-
import { useDialect } from "./runtime/useDialect.mjs";
|
|
2
|
+
import { DialectCallback, useDialect } from "./runtime/useDialect.mjs";
|
|
3
3
|
import { useConfig } from "./runtime/useConfig.mjs";
|
|
4
4
|
import { ConnectorSpecifier, ConnectorVariants, ExpandVariants, MaybePromise, Selector, Variant } from "nitro-drizzle/shared";
|
|
5
5
|
import { Connector, Datasource } from "nitro-drizzle/drivers";
|
|
@@ -32,7 +32,14 @@ type ConfigOf<T extends Connector<any, any, any, any>> = T extends Connector<any
|
|
|
32
32
|
* Extracts the datasource type from a Connector factory.
|
|
33
33
|
* @template T - The Connector type
|
|
34
34
|
*/
|
|
35
|
-
type DatasourceOf<T extends Connector<any, any, any, any>> = T extends ((...args: any) => MaybePromise<infer R>) ? R extends Datasource<any, any, any> ? R : never : never;
|
|
35
|
+
type DatasourceOf<T extends Connector<any, any, any, any>> = T extends ((...args: any) => MaybePromise<infer R>) ? R extends Datasource<any, any, any> ? R : never : T extends ((...args: any) => any) ? Parameters<Parameters<T>[0]>[0] : never;
|
|
36
|
+
/**
|
|
37
|
+
* Infers the transaction type from a datasource, database instance, or transaction function.
|
|
38
|
+
* @template T - The datasource, database instance, or transaction function type
|
|
39
|
+
*/
|
|
40
|
+
type TransactionOf<T> = T extends {
|
|
41
|
+
transaction: (transaction: (tx: infer TTx, ...args: any[]) => any, ...args: any[]) => any;
|
|
42
|
+
} ? TTx : never;
|
|
36
43
|
type DatasourceMapper<T extends Variant<Connector<any, any, any, any>, ConnectorSpecifier>> = T extends any ? Variant<DatasourceOf<T["value"]>, T["selector"]> : never;
|
|
37
44
|
/**
|
|
38
45
|
* Mapped type of all datasources from the registry.
|
|
@@ -99,5 +106,5 @@ declare module "nitro/types" {
|
|
|
99
106
|
interface NitroRuntimeHooks extends ConfigHooks {}
|
|
100
107
|
}
|
|
101
108
|
//#endregion
|
|
102
|
-
export { ConfigHookArgs, ConfigHooks, ConfigOf, DatasourceConfig, DatasourceOf, DatasourceProvider, DatasourceProviderConfig, DatasourceProviderVariants, DatasourceRegistry, DatasourceVariants, Datasources, DriverRuntimeConfig, Primitive, PrimitiveProps, RuntimeConfig, UseDatasourceOptions, useConfig, useDatasource, useDialect };
|
|
109
|
+
export { ConfigHookArgs, ConfigHooks, ConfigOf, DatasourceConfig, DatasourceOf, DatasourceProvider, DatasourceProviderConfig, DatasourceProviderVariants, DatasourceRegistry, DatasourceVariants, Datasources, DialectCallback, DriverRuntimeConfig, Primitive, PrimitiveProps, RuntimeConfig, TransactionOf, UseDatasourceOptions, useConfig, useDatasource, useDialect };
|
|
103
110
|
//# sourceMappingURL=runtime.d.mts.map
|