@8ms/helpers 3.2.0 → 3.2.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/aws/server/getAwsConfig.cjs +14 -13
- package/dist/aws/server/getAwsConfig.d.cts +2 -0
- package/dist/aws/server/getAwsConfig.d.mts +2 -0
- package/dist/aws/server/getAwsConfig.mjs +13 -14
- package/dist/aws/server/index.cjs +2 -0
- package/dist/aws/server/index.d.cts +2 -2
- package/dist/aws/server/index.d.mts +2 -2
- package/dist/aws/server/index.mjs +2 -2
- package/dist/drizzle/server/Drizzle.cjs +77 -58
- package/dist/drizzle/server/Drizzle.d.cts +3 -0
- package/dist/drizzle/server/Drizzle.d.mts +3 -0
- package/dist/drizzle/server/Drizzle.mjs +75 -59
- package/dist/drizzle/server/index.cjs +3 -0
- package/dist/drizzle/server/index.d.cts +2 -2
- package/dist/drizzle/server/index.d.mts +2 -2
- package/dist/drizzle/server/index.mjs +2 -2
- package/dist/prisma/server/Prisma.cjs +30 -18
- package/dist/prisma/server/Prisma.d.cts +3 -0
- package/dist/prisma/server/Prisma.d.mts +3 -0
- package/dist/prisma/server/Prisma.mjs +28 -19
- package/dist/prisma/server/index.cjs +3 -0
- package/dist/prisma/server/index.d.cts +2 -2
- package/dist/prisma/server/index.d.mts +2 -2
- package/dist/prisma/server/index.mjs +2 -2
- package/package.json +1 -1
|
@@ -6,7 +6,8 @@ const getGcpOidcToken = async () => {
|
|
|
6
6
|
if (!response.ok) throw new Error(`Failed to fetch GCP OIDC token: ${response.status} ${response.statusText}`);
|
|
7
7
|
return response.text();
|
|
8
8
|
};
|
|
9
|
-
const
|
|
9
|
+
const getGcpAwsConfig = async (props) => {
|
|
10
|
+
const token = await getGcpOidcToken();
|
|
10
11
|
const { STSClient, AssumeRoleWithWebIdentityCommand } = await import("@aws-sdk/client-sts");
|
|
11
12
|
const { Credentials } = await new STSClient({ region: props?.awsRegion || "eu-west-2" }).send(new AssumeRoleWithWebIdentityCommand({
|
|
12
13
|
RoleArn: props.oidcRoleArn,
|
|
@@ -14,25 +15,25 @@ const assumeAwsRoleWithGcpToken = async (token, props) => {
|
|
|
14
15
|
WebIdentityToken: token
|
|
15
16
|
}));
|
|
16
17
|
if (!Credentials?.AccessKeyId || !Credentials?.SecretAccessKey) throw new Error("STS did not return valid credentials");
|
|
17
|
-
return {
|
|
18
|
+
return { credentials: {
|
|
18
19
|
accessKeyId: Credentials.AccessKeyId,
|
|
19
20
|
secretAccessKey: Credentials.SecretAccessKey,
|
|
20
21
|
sessionToken: Credentials.SessionToken
|
|
21
|
-
};
|
|
22
|
+
} };
|
|
23
|
+
};
|
|
24
|
+
const getVercelAwsConfig = async (props) => {
|
|
25
|
+
const { awsCredentialsProvider } = await import("@vercel/oidc-aws-credentials-provider");
|
|
26
|
+
return { credentials: await awsCredentialsProvider({ roleArn: props.oidcRoleArn })() };
|
|
22
27
|
};
|
|
23
28
|
const getAwsConfig = async (props) => {
|
|
24
|
-
|
|
29
|
+
if (props.oidcRoleArn && require_environment__shared_environment.isVercel()) return getVercelAwsConfig(props);
|
|
30
|
+
if (props.oidcRoleArn && require_environment__shared_environment.isGoogleCloud()) return getGcpAwsConfig(props);
|
|
31
|
+
return { credentials: {
|
|
25
32
|
accessKeyId: props?.accessKeyId ?? "",
|
|
26
33
|
secretAccessKey: props?.secretAccessKey ?? ""
|
|
27
|
-
};
|
|
28
|
-
if (props.oidcRoleArn && require_environment__shared_environment.isVercel()) {
|
|
29
|
-
const { awsCredentialsProvider } = await import("@vercel/oidc-aws-credentials-provider");
|
|
30
|
-
credentials = await awsCredentialsProvider({ roleArn: props.oidcRoleArn })();
|
|
31
|
-
} else if (props.oidcRoleArn && require_environment__shared_environment.isGoogleCloud()) {
|
|
32
|
-
const gcpToken = await getGcpOidcToken();
|
|
33
|
-
credentials = await assumeAwsRoleWithGcpToken(gcpToken, props);
|
|
34
|
-
}
|
|
35
|
-
return { credentials };
|
|
34
|
+
} };
|
|
36
35
|
};
|
|
37
36
|
//#endregion
|
|
38
37
|
exports.getAwsConfig = getAwsConfig;
|
|
38
|
+
exports.getGcpAwsConfig = getGcpAwsConfig;
|
|
39
|
+
exports.getVercelAwsConfig = getVercelAwsConfig;
|
|
@@ -13,5 +13,7 @@ type AwsConfig = {
|
|
|
13
13
|
sessionToken?: string;
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
|
+
export declare const getGcpAwsConfig: (props: GetAwsConfigProps) => Promise<AwsConfig>;
|
|
17
|
+
export declare const getVercelAwsConfig: (props: GetAwsConfigProps) => Promise<AwsConfig>;
|
|
16
18
|
export declare const getAwsConfig: (props: GetAwsConfigProps) => Promise<AwsConfig>;
|
|
17
19
|
//#endregion
|
|
@@ -13,5 +13,7 @@ type AwsConfig = {
|
|
|
13
13
|
sessionToken?: string;
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
|
+
export declare const getGcpAwsConfig: (props: GetAwsConfigProps) => Promise<AwsConfig>;
|
|
17
|
+
export declare const getVercelAwsConfig: (props: GetAwsConfigProps) => Promise<AwsConfig>;
|
|
16
18
|
export declare const getAwsConfig: (props: GetAwsConfigProps) => Promise<AwsConfig>;
|
|
17
19
|
//#endregion
|
|
@@ -5,7 +5,8 @@ const getGcpOidcToken = async () => {
|
|
|
5
5
|
if (!response.ok) throw new Error(`Failed to fetch GCP OIDC token: ${response.status} ${response.statusText}`);
|
|
6
6
|
return response.text();
|
|
7
7
|
};
|
|
8
|
-
const
|
|
8
|
+
const getGcpAwsConfig = async (props) => {
|
|
9
|
+
const token = await getGcpOidcToken();
|
|
9
10
|
const { STSClient, AssumeRoleWithWebIdentityCommand } = await import("@aws-sdk/client-sts");
|
|
10
11
|
const { Credentials } = await new STSClient({ region: props?.awsRegion || "eu-west-2" }).send(new AssumeRoleWithWebIdentityCommand({
|
|
11
12
|
RoleArn: props.oidcRoleArn,
|
|
@@ -13,25 +14,23 @@ const assumeAwsRoleWithGcpToken = async (token, props) => {
|
|
|
13
14
|
WebIdentityToken: token
|
|
14
15
|
}));
|
|
15
16
|
if (!Credentials?.AccessKeyId || !Credentials?.SecretAccessKey) throw new Error("STS did not return valid credentials");
|
|
16
|
-
return {
|
|
17
|
+
return { credentials: {
|
|
17
18
|
accessKeyId: Credentials.AccessKeyId,
|
|
18
19
|
secretAccessKey: Credentials.SecretAccessKey,
|
|
19
20
|
sessionToken: Credentials.SessionToken
|
|
20
|
-
};
|
|
21
|
+
} };
|
|
22
|
+
};
|
|
23
|
+
const getVercelAwsConfig = async (props) => {
|
|
24
|
+
const { awsCredentialsProvider } = await import("@vercel/oidc-aws-credentials-provider");
|
|
25
|
+
return { credentials: await awsCredentialsProvider({ roleArn: props.oidcRoleArn })() };
|
|
21
26
|
};
|
|
22
27
|
const getAwsConfig = async (props) => {
|
|
23
|
-
|
|
28
|
+
if (props.oidcRoleArn && isVercel()) return getVercelAwsConfig(props);
|
|
29
|
+
if (props.oidcRoleArn && isGoogleCloud()) return getGcpAwsConfig(props);
|
|
30
|
+
return { credentials: {
|
|
24
31
|
accessKeyId: props?.accessKeyId ?? "",
|
|
25
32
|
secretAccessKey: props?.secretAccessKey ?? ""
|
|
26
|
-
};
|
|
27
|
-
if (props.oidcRoleArn && isVercel()) {
|
|
28
|
-
const { awsCredentialsProvider } = await import("@vercel/oidc-aws-credentials-provider");
|
|
29
|
-
credentials = await awsCredentialsProvider({ roleArn: props.oidcRoleArn })();
|
|
30
|
-
} else if (props.oidcRoleArn && isGoogleCloud()) {
|
|
31
|
-
const gcpToken = await getGcpOidcToken();
|
|
32
|
-
credentials = await assumeAwsRoleWithGcpToken(gcpToken, props);
|
|
33
|
-
}
|
|
34
|
-
return { credentials };
|
|
33
|
+
} };
|
|
35
34
|
};
|
|
36
35
|
//#endregion
|
|
37
|
-
export { getAwsConfig };
|
|
36
|
+
export { getAwsConfig, getGcpAwsConfig, getVercelAwsConfig };
|
|
@@ -2,4 +2,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_aws_server_getAwsConfig = require("./getAwsConfig.cjs");
|
|
3
3
|
const require_aws_server_isResponse200 = require("./isResponse200.cjs");
|
|
4
4
|
exports.getAwsConfig = require_aws_server_getAwsConfig.getAwsConfig;
|
|
5
|
+
exports.getGcpAwsConfig = require_aws_server_getAwsConfig.getGcpAwsConfig;
|
|
6
|
+
exports.getVercelAwsConfig = require_aws_server_getAwsConfig.getVercelAwsConfig;
|
|
5
7
|
exports.isResponse200 = require_aws_server_isResponse200.isResponse200;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { getAwsConfig } from "./getAwsConfig.cjs";
|
|
1
|
+
import { getAwsConfig, getGcpAwsConfig, getVercelAwsConfig } from "./getAwsConfig.cjs";
|
|
2
2
|
import { isResponse200 } from "./isResponse200.cjs";
|
|
3
|
-
export { getAwsConfig, isResponse200 };
|
|
3
|
+
export { getAwsConfig, getGcpAwsConfig, getVercelAwsConfig, isResponse200 };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { getAwsConfig } from "./getAwsConfig.mjs";
|
|
1
|
+
import { getAwsConfig, getGcpAwsConfig, getVercelAwsConfig } from "./getAwsConfig.mjs";
|
|
2
2
|
import { isResponse200 } from "./isResponse200.mjs";
|
|
3
|
-
export { getAwsConfig, isResponse200 };
|
|
3
|
+
export { getAwsConfig, getGcpAwsConfig, getVercelAwsConfig, isResponse200 };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { getAwsConfig } from "./getAwsConfig.mjs";
|
|
1
|
+
import { getAwsConfig, getGcpAwsConfig, getVercelAwsConfig } from "./getAwsConfig.mjs";
|
|
2
2
|
import { isResponse200 } from "./isResponse200.mjs";
|
|
3
|
-
export { getAwsConfig, isResponse200 };
|
|
3
|
+
export { getAwsConfig, getGcpAwsConfig, getVercelAwsConfig, isResponse200 };
|
|
@@ -2,67 +2,83 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_util__shared_getError = require("../../util/_shared/getError.cjs");
|
|
3
3
|
const require__class__shared_BaseNamespace = require("../../_class/_shared/BaseNamespace.cjs");
|
|
4
4
|
//#region src/drizzle/server/Drizzle.ts
|
|
5
|
+
const resolveCommonConfig = async (config) => {
|
|
6
|
+
let logger;
|
|
7
|
+
if (true === config?.isDebug) {
|
|
8
|
+
const { DefaultLogger } = await import("drizzle-orm/logger");
|
|
9
|
+
logger = new DefaultLogger();
|
|
10
|
+
}
|
|
11
|
+
let casing = void 0;
|
|
12
|
+
if ("snake" === config?.casing) casing = "snake_case";
|
|
13
|
+
else if ("camel" === config?.casing) casing = "camelCase";
|
|
14
|
+
return {
|
|
15
|
+
casing,
|
|
16
|
+
logger
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
const getDrizzlePlanetScaleClient = async (config) => {
|
|
20
|
+
const { casing, logger } = await resolveCommonConfig(config);
|
|
21
|
+
try {
|
|
22
|
+
const { drizzle } = await import("drizzle-orm/planetscale-serverless");
|
|
23
|
+
return drizzle({
|
|
24
|
+
casing,
|
|
25
|
+
connection: { url: config?.url },
|
|
26
|
+
relations: config?.relations,
|
|
27
|
+
schema: config?.schema,
|
|
28
|
+
logger
|
|
29
|
+
});
|
|
30
|
+
} catch (e) {
|
|
31
|
+
throw new Error(`PlanetScale driver not installed - ${require_util__shared_getError.getError(e)}`);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const getDrizzleMysqlClient = async (config) => {
|
|
35
|
+
const { casing, logger } = await resolveCommonConfig(config);
|
|
36
|
+
try {
|
|
37
|
+
const { drizzle } = await import("drizzle-orm/mysql2");
|
|
38
|
+
return drizzle((await import("mysql2/promise")).createPool({
|
|
39
|
+
uri: config.url,
|
|
40
|
+
connectionLimit: config.pool?.max ?? 10,
|
|
41
|
+
idleTimeout: config.pool?.idleTimeoutMs ?? 3e4,
|
|
42
|
+
connectTimeout: config.pool?.connectTimeoutMs ?? 5e3,
|
|
43
|
+
waitForConnections: true,
|
|
44
|
+
queueLimit: 0
|
|
45
|
+
}), {
|
|
46
|
+
schema: config.schema,
|
|
47
|
+
relations: config.relations,
|
|
48
|
+
casing,
|
|
49
|
+
logger,
|
|
50
|
+
mode: "default"
|
|
51
|
+
});
|
|
52
|
+
} catch (e) {
|
|
53
|
+
throw new Error(`MySQL2 driver not installed - ${require_util__shared_getError.getError(e)}`);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const getDrizzlePostgresClient = async (config) => {
|
|
57
|
+
const { casing, logger } = await resolveCommonConfig(config);
|
|
58
|
+
try {
|
|
59
|
+
const { drizzle } = await import("drizzle-orm/node-postgres");
|
|
60
|
+
const { Pool } = await import("pg");
|
|
61
|
+
return drizzle(new Pool({
|
|
62
|
+
connectionString: config.url,
|
|
63
|
+
max: config.pool?.max ?? 10,
|
|
64
|
+
idleTimeoutMillis: config.pool?.idleTimeoutMs ?? 3e4,
|
|
65
|
+
connectionTimeoutMillis: config.pool?.connectTimeoutMs ?? 5e3
|
|
66
|
+
}), {
|
|
67
|
+
schema: config.schema,
|
|
68
|
+
relations: config.relations,
|
|
69
|
+
casing,
|
|
70
|
+
logger
|
|
71
|
+
});
|
|
72
|
+
} catch (e) {
|
|
73
|
+
throw new Error(`Postgres (pg) driver not installed - ${require_util__shared_getError.getError(e)}`);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
5
76
|
var Drizzle = class extends require__class__shared_BaseNamespace.BaseNamespace {
|
|
6
77
|
init = async (config) => {
|
|
7
78
|
if (!this.client) {
|
|
8
|
-
|
|
9
|
-
if (true === config?.
|
|
10
|
-
|
|
11
|
-
logger = new DefaultLogger();
|
|
12
|
-
}
|
|
13
|
-
let casing = void 0;
|
|
14
|
-
if ("snake" === config?.casing) casing = "snake_case";
|
|
15
|
-
else if ("camel" === config?.casing) casing = "camelCase";
|
|
16
|
-
if (true === config?.isPlanetScale) try {
|
|
17
|
-
const { drizzle } = await import("drizzle-orm/planetscale-serverless");
|
|
18
|
-
this.client = drizzle({
|
|
19
|
-
casing,
|
|
20
|
-
connection: { url: config?.url },
|
|
21
|
-
relations: config?.relations,
|
|
22
|
-
schema: config?.schema,
|
|
23
|
-
logger
|
|
24
|
-
});
|
|
25
|
-
} catch (e) {
|
|
26
|
-
throw new Error(`PlanetScale driver not installed - ${require_util__shared_getError.getError(e)}`);
|
|
27
|
-
}
|
|
28
|
-
else if (true === config?.isMysql) try {
|
|
29
|
-
const { drizzle } = await import("drizzle-orm/mysql2");
|
|
30
|
-
const pool = (await import("mysql2/promise")).createPool({
|
|
31
|
-
uri: config.url,
|
|
32
|
-
connectionLimit: config.pool?.max ?? 10,
|
|
33
|
-
idleTimeout: config.pool?.idleTimeoutMs ?? 3e4,
|
|
34
|
-
connectTimeout: config.pool?.connectTimeoutMs ?? 5e3,
|
|
35
|
-
waitForConnections: true,
|
|
36
|
-
queueLimit: 0
|
|
37
|
-
});
|
|
38
|
-
this.client = drizzle(pool, {
|
|
39
|
-
schema: config.schema,
|
|
40
|
-
relations: config.relations,
|
|
41
|
-
casing,
|
|
42
|
-
logger,
|
|
43
|
-
mode: "default"
|
|
44
|
-
});
|
|
45
|
-
} catch (e) {
|
|
46
|
-
throw new Error(`MySQL2 driver not installed - ${require_util__shared_getError.getError(e)}`);
|
|
47
|
-
}
|
|
48
|
-
else if (true === config?.isPostgres) try {
|
|
49
|
-
const { drizzle } = await import("drizzle-orm/node-postgres");
|
|
50
|
-
const { Pool } = await import("pg");
|
|
51
|
-
const pool = new Pool({
|
|
52
|
-
connectionString: config.url,
|
|
53
|
-
max: config.pool?.max ?? 10,
|
|
54
|
-
idleTimeoutMillis: config.pool?.idleTimeoutMs ?? 3e4,
|
|
55
|
-
connectionTimeoutMillis: config.pool?.connectTimeoutMs ?? 5e3
|
|
56
|
-
});
|
|
57
|
-
this.client = drizzle(pool, {
|
|
58
|
-
schema: config.schema,
|
|
59
|
-
relations: config.relations,
|
|
60
|
-
casing,
|
|
61
|
-
logger
|
|
62
|
-
});
|
|
63
|
-
} catch (e) {
|
|
64
|
-
throw new Error(`Postgres (pg) driver not installed - ${require_util__shared_getError.getError(e)}`);
|
|
65
|
-
}
|
|
79
|
+
if (true === config?.isPlanetScale) this.client = await getDrizzlePlanetScaleClient(config);
|
|
80
|
+
else if (true === config?.isMysql) this.client = await getDrizzleMysqlClient(config);
|
|
81
|
+
else if (true === config?.isPostgres) this.client = await getDrizzlePostgresClient(config);
|
|
66
82
|
else throw new Error(`No database type configured`);
|
|
67
83
|
this.config = config;
|
|
68
84
|
}
|
|
@@ -71,3 +87,6 @@ var Drizzle = class extends require__class__shared_BaseNamespace.BaseNamespace {
|
|
|
71
87
|
};
|
|
72
88
|
//#endregion
|
|
73
89
|
exports.Drizzle = Drizzle;
|
|
90
|
+
exports.getDrizzleMysqlClient = getDrizzleMysqlClient;
|
|
91
|
+
exports.getDrizzlePlanetScaleClient = getDrizzlePlanetScaleClient;
|
|
92
|
+
exports.getDrizzlePostgresClient = getDrizzlePostgresClient;
|
|
@@ -16,6 +16,9 @@ export type DrizzleConfig<TSchema extends Record<string, unknown> = Record<strin
|
|
|
16
16
|
connectTimeoutMs?: number;
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
|
+
export declare const getDrizzlePlanetScaleClient: <TClient = any>(config: DrizzleConfig) => Promise<TClient>;
|
|
20
|
+
export declare const getDrizzleMysqlClient: <TClient = any>(config: DrizzleConfig) => Promise<TClient>;
|
|
21
|
+
export declare const getDrizzlePostgresClient: <TClient = any>(config: DrizzleConfig) => Promise<TClient>;
|
|
19
22
|
export declare class Drizzle extends BaseNamespace {
|
|
20
23
|
client: any;
|
|
21
24
|
config: DrizzleConfig;
|
|
@@ -16,6 +16,9 @@ export type DrizzleConfig<TSchema extends Record<string, unknown> = Record<strin
|
|
|
16
16
|
connectTimeoutMs?: number;
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
|
+
export declare const getDrizzlePlanetScaleClient: <TClient = any>(config: DrizzleConfig) => Promise<TClient>;
|
|
20
|
+
export declare const getDrizzleMysqlClient: <TClient = any>(config: DrizzleConfig) => Promise<TClient>;
|
|
21
|
+
export declare const getDrizzlePostgresClient: <TClient = any>(config: DrizzleConfig) => Promise<TClient>;
|
|
19
22
|
export declare class Drizzle extends BaseNamespace {
|
|
20
23
|
client: any;
|
|
21
24
|
config: DrizzleConfig;
|
|
@@ -1,67 +1,83 @@
|
|
|
1
1
|
import { getError } from "../../util/_shared/getError.mjs";
|
|
2
2
|
import { BaseNamespace } from "../../_class/_shared/BaseNamespace.mjs";
|
|
3
3
|
//#region src/drizzle/server/Drizzle.ts
|
|
4
|
+
const resolveCommonConfig = async (config) => {
|
|
5
|
+
let logger;
|
|
6
|
+
if (true === config?.isDebug) {
|
|
7
|
+
const { DefaultLogger } = await import("drizzle-orm/logger");
|
|
8
|
+
logger = new DefaultLogger();
|
|
9
|
+
}
|
|
10
|
+
let casing = void 0;
|
|
11
|
+
if ("snake" === config?.casing) casing = "snake_case";
|
|
12
|
+
else if ("camel" === config?.casing) casing = "camelCase";
|
|
13
|
+
return {
|
|
14
|
+
casing,
|
|
15
|
+
logger
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
const getDrizzlePlanetScaleClient = async (config) => {
|
|
19
|
+
const { casing, logger } = await resolveCommonConfig(config);
|
|
20
|
+
try {
|
|
21
|
+
const { drizzle } = await import("drizzle-orm/planetscale-serverless");
|
|
22
|
+
return drizzle({
|
|
23
|
+
casing,
|
|
24
|
+
connection: { url: config?.url },
|
|
25
|
+
relations: config?.relations,
|
|
26
|
+
schema: config?.schema,
|
|
27
|
+
logger
|
|
28
|
+
});
|
|
29
|
+
} catch (e) {
|
|
30
|
+
throw new Error(`PlanetScale driver not installed - ${getError(e)}`);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const getDrizzleMysqlClient = async (config) => {
|
|
34
|
+
const { casing, logger } = await resolveCommonConfig(config);
|
|
35
|
+
try {
|
|
36
|
+
const { drizzle } = await import("drizzle-orm/mysql2");
|
|
37
|
+
return drizzle((await import("mysql2/promise")).createPool({
|
|
38
|
+
uri: config.url,
|
|
39
|
+
connectionLimit: config.pool?.max ?? 10,
|
|
40
|
+
idleTimeout: config.pool?.idleTimeoutMs ?? 3e4,
|
|
41
|
+
connectTimeout: config.pool?.connectTimeoutMs ?? 5e3,
|
|
42
|
+
waitForConnections: true,
|
|
43
|
+
queueLimit: 0
|
|
44
|
+
}), {
|
|
45
|
+
schema: config.schema,
|
|
46
|
+
relations: config.relations,
|
|
47
|
+
casing,
|
|
48
|
+
logger,
|
|
49
|
+
mode: "default"
|
|
50
|
+
});
|
|
51
|
+
} catch (e) {
|
|
52
|
+
throw new Error(`MySQL2 driver not installed - ${getError(e)}`);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const getDrizzlePostgresClient = async (config) => {
|
|
56
|
+
const { casing, logger } = await resolveCommonConfig(config);
|
|
57
|
+
try {
|
|
58
|
+
const { drizzle } = await import("drizzle-orm/node-postgres");
|
|
59
|
+
const { Pool } = await import("pg");
|
|
60
|
+
return drizzle(new Pool({
|
|
61
|
+
connectionString: config.url,
|
|
62
|
+
max: config.pool?.max ?? 10,
|
|
63
|
+
idleTimeoutMillis: config.pool?.idleTimeoutMs ?? 3e4,
|
|
64
|
+
connectionTimeoutMillis: config.pool?.connectTimeoutMs ?? 5e3
|
|
65
|
+
}), {
|
|
66
|
+
schema: config.schema,
|
|
67
|
+
relations: config.relations,
|
|
68
|
+
casing,
|
|
69
|
+
logger
|
|
70
|
+
});
|
|
71
|
+
} catch (e) {
|
|
72
|
+
throw new Error(`Postgres (pg) driver not installed - ${getError(e)}`);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
4
75
|
var Drizzle = class extends BaseNamespace {
|
|
5
76
|
init = async (config) => {
|
|
6
77
|
if (!this.client) {
|
|
7
|
-
|
|
8
|
-
if (true === config?.
|
|
9
|
-
|
|
10
|
-
logger = new DefaultLogger();
|
|
11
|
-
}
|
|
12
|
-
let casing = void 0;
|
|
13
|
-
if ("snake" === config?.casing) casing = "snake_case";
|
|
14
|
-
else if ("camel" === config?.casing) casing = "camelCase";
|
|
15
|
-
if (true === config?.isPlanetScale) try {
|
|
16
|
-
const { drizzle } = await import("drizzle-orm/planetscale-serverless");
|
|
17
|
-
this.client = drizzle({
|
|
18
|
-
casing,
|
|
19
|
-
connection: { url: config?.url },
|
|
20
|
-
relations: config?.relations,
|
|
21
|
-
schema: config?.schema,
|
|
22
|
-
logger
|
|
23
|
-
});
|
|
24
|
-
} catch (e) {
|
|
25
|
-
throw new Error(`PlanetScale driver not installed - ${getError(e)}`);
|
|
26
|
-
}
|
|
27
|
-
else if (true === config?.isMysql) try {
|
|
28
|
-
const { drizzle } = await import("drizzle-orm/mysql2");
|
|
29
|
-
const pool = (await import("mysql2/promise")).createPool({
|
|
30
|
-
uri: config.url,
|
|
31
|
-
connectionLimit: config.pool?.max ?? 10,
|
|
32
|
-
idleTimeout: config.pool?.idleTimeoutMs ?? 3e4,
|
|
33
|
-
connectTimeout: config.pool?.connectTimeoutMs ?? 5e3,
|
|
34
|
-
waitForConnections: true,
|
|
35
|
-
queueLimit: 0
|
|
36
|
-
});
|
|
37
|
-
this.client = drizzle(pool, {
|
|
38
|
-
schema: config.schema,
|
|
39
|
-
relations: config.relations,
|
|
40
|
-
casing,
|
|
41
|
-
logger,
|
|
42
|
-
mode: "default"
|
|
43
|
-
});
|
|
44
|
-
} catch (e) {
|
|
45
|
-
throw new Error(`MySQL2 driver not installed - ${getError(e)}`);
|
|
46
|
-
}
|
|
47
|
-
else if (true === config?.isPostgres) try {
|
|
48
|
-
const { drizzle } = await import("drizzle-orm/node-postgres");
|
|
49
|
-
const { Pool } = await import("pg");
|
|
50
|
-
const pool = new Pool({
|
|
51
|
-
connectionString: config.url,
|
|
52
|
-
max: config.pool?.max ?? 10,
|
|
53
|
-
idleTimeoutMillis: config.pool?.idleTimeoutMs ?? 3e4,
|
|
54
|
-
connectionTimeoutMillis: config.pool?.connectTimeoutMs ?? 5e3
|
|
55
|
-
});
|
|
56
|
-
this.client = drizzle(pool, {
|
|
57
|
-
schema: config.schema,
|
|
58
|
-
relations: config.relations,
|
|
59
|
-
casing,
|
|
60
|
-
logger
|
|
61
|
-
});
|
|
62
|
-
} catch (e) {
|
|
63
|
-
throw new Error(`Postgres (pg) driver not installed - ${getError(e)}`);
|
|
64
|
-
}
|
|
78
|
+
if (true === config?.isPlanetScale) this.client = await getDrizzlePlanetScaleClient(config);
|
|
79
|
+
else if (true === config?.isMysql) this.client = await getDrizzleMysqlClient(config);
|
|
80
|
+
else if (true === config?.isPostgres) this.client = await getDrizzlePostgresClient(config);
|
|
65
81
|
else throw new Error(`No database type configured`);
|
|
66
82
|
this.config = config;
|
|
67
83
|
}
|
|
@@ -69,4 +85,4 @@ var Drizzle = class extends BaseNamespace {
|
|
|
69
85
|
};
|
|
70
86
|
};
|
|
71
87
|
//#endregion
|
|
72
|
-
export { Drizzle };
|
|
88
|
+
export { Drizzle, getDrizzleMysqlClient, getDrizzlePlanetScaleClient, getDrizzlePostgresClient };
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_drizzle_server_Drizzle = require("./Drizzle.cjs");
|
|
3
3
|
exports.Drizzle = require_drizzle_server_Drizzle.Drizzle;
|
|
4
|
+
exports.getDrizzleMysqlClient = require_drizzle_server_Drizzle.getDrizzleMysqlClient;
|
|
5
|
+
exports.getDrizzlePlanetScaleClient = require_drizzle_server_Drizzle.getDrizzlePlanetScaleClient;
|
|
6
|
+
exports.getDrizzlePostgresClient = require_drizzle_server_Drizzle.getDrizzlePostgresClient;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Drizzle, DrizzleConfig } from "./Drizzle.cjs";
|
|
2
|
-
export { Drizzle, DrizzleConfig };
|
|
1
|
+
import { Drizzle, DrizzleConfig, getDrizzleMysqlClient, getDrizzlePlanetScaleClient, getDrizzlePostgresClient } from "./Drizzle.cjs";
|
|
2
|
+
export { Drizzle, DrizzleConfig, getDrizzleMysqlClient, getDrizzlePlanetScaleClient, getDrizzlePostgresClient };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Drizzle, DrizzleConfig } from "./Drizzle.mjs";
|
|
2
|
-
export { Drizzle, DrizzleConfig };
|
|
1
|
+
import { Drizzle, DrizzleConfig, getDrizzleMysqlClient, getDrizzlePlanetScaleClient, getDrizzlePostgresClient } from "./Drizzle.mjs";
|
|
2
|
+
export { Drizzle, DrizzleConfig, getDrizzleMysqlClient, getDrizzlePlanetScaleClient, getDrizzlePostgresClient };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Drizzle } from "./Drizzle.mjs";
|
|
2
|
-
export { Drizzle };
|
|
1
|
+
import { Drizzle, getDrizzleMysqlClient, getDrizzlePlanetScaleClient, getDrizzlePostgresClient } from "./Drizzle.mjs";
|
|
2
|
+
export { Drizzle, getDrizzleMysqlClient, getDrizzlePlanetScaleClient, getDrizzlePostgresClient };
|
|
@@ -2,28 +2,37 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_util__shared_getError = require("../../util/_shared/getError.cjs");
|
|
3
3
|
const require__class__shared_BaseNamespace = require("../../_class/_shared/BaseNamespace.cjs");
|
|
4
4
|
//#region src/prisma/server/Prisma.ts
|
|
5
|
+
const getPrismaPlanetScaleAdapter = async (config) => {
|
|
6
|
+
try {
|
|
7
|
+
const { PrismaPlanetScale } = await import("@prisma/adapter-planetscale");
|
|
8
|
+
return new PrismaPlanetScale({ url: config.url });
|
|
9
|
+
} catch (e) {
|
|
10
|
+
throw new Error(`PlanetScale adapter not installed - ${require_util__shared_getError.getError(e)}`);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const getPrismaMysqlAdapter = async (config) => {
|
|
14
|
+
try {
|
|
15
|
+
const { PrismaMariaDb } = await import("@prisma/adapter-mariadb");
|
|
16
|
+
return new PrismaMariaDb(config.url);
|
|
17
|
+
} catch (e) {
|
|
18
|
+
throw new Error(`MariaDB adapter not installed - ${require_util__shared_getError.getError(e)}`);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const getPrismaPostgresAdapter = async () => {
|
|
22
|
+
try {
|
|
23
|
+
const { PrismaPg } = await import("@prisma/adapter-pg");
|
|
24
|
+
return new PrismaPg({ connectionString: process.env.DATABASE_URL });
|
|
25
|
+
} catch (e) {
|
|
26
|
+
throw new Error(`Postgres adapter not installed - ${require_util__shared_getError.getError(e)}`);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
5
29
|
var Prisma = class extends require__class__shared_BaseNamespace.BaseNamespace {
|
|
6
30
|
init = async (config) => {
|
|
7
31
|
if (!this.client) {
|
|
8
32
|
let adapter = null;
|
|
9
|
-
if (config.isPlanetScale)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} catch (e) {
|
|
13
|
-
throw new Error(`PlanetScale adapter not installed - ${require_util__shared_getError.getError(e)}`);
|
|
14
|
-
}
|
|
15
|
-
if (config.isMysql) try {
|
|
16
|
-
const { PrismaMariaDb } = await import("@prisma/adapter-mariadb");
|
|
17
|
-
adapter = new PrismaMariaDb(config.url);
|
|
18
|
-
} catch (e) {
|
|
19
|
-
throw new Error(`MariaDB adapter not installed - ${require_util__shared_getError.getError(e)}`);
|
|
20
|
-
}
|
|
21
|
-
if (config.isPostgres) try {
|
|
22
|
-
const { PrismaPg } = await import("@prisma/adapter-pg");
|
|
23
|
-
adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL });
|
|
24
|
-
} catch (e) {
|
|
25
|
-
throw new Error(`Postgres adapter not installed - ${require_util__shared_getError.getError(e)}`);
|
|
26
|
-
}
|
|
33
|
+
if (config.isPlanetScale) adapter = await getPrismaPlanetScaleAdapter(config);
|
|
34
|
+
else if (config.isMysql) adapter = await getPrismaMysqlAdapter(config);
|
|
35
|
+
else if (config.isPostgres) adapter = await getPrismaPostgresAdapter();
|
|
27
36
|
try {
|
|
28
37
|
const { PrismaClient } = await import("@prisma/client");
|
|
29
38
|
if (config.isDebug) this.client = new PrismaClient({
|
|
@@ -44,3 +53,6 @@ var Prisma = class extends require__class__shared_BaseNamespace.BaseNamespace {
|
|
|
44
53
|
};
|
|
45
54
|
//#endregion
|
|
46
55
|
exports.Prisma = Prisma;
|
|
56
|
+
exports.getPrismaMysqlAdapter = getPrismaMysqlAdapter;
|
|
57
|
+
exports.getPrismaPlanetScaleAdapter = getPrismaPlanetScaleAdapter;
|
|
58
|
+
exports.getPrismaPostgresAdapter = getPrismaPostgresAdapter;
|
|
@@ -18,6 +18,9 @@ type PrismaConfig = {
|
|
|
18
18
|
isPostgres: boolean;
|
|
19
19
|
url: string;
|
|
20
20
|
};
|
|
21
|
+
export declare const getPrismaPlanetScaleAdapter: (config: PrismaConfig) => Promise<import("@prisma/adapter-planetscale").PrismaPlanetScale>;
|
|
22
|
+
export declare const getPrismaMysqlAdapter: (config: PrismaConfig) => Promise<import("@prisma/adapter-mariadb").PrismaMariaDb>;
|
|
23
|
+
export declare const getPrismaPostgresAdapter: () => Promise<import("@prisma/adapter-pg").PrismaPg>;
|
|
21
24
|
export declare class Prisma extends BaseNamespace {
|
|
22
25
|
client: PrismaClientLike;
|
|
23
26
|
config: PrismaConfig;
|
|
@@ -18,6 +18,9 @@ type PrismaConfig = {
|
|
|
18
18
|
isPostgres: boolean;
|
|
19
19
|
url: string;
|
|
20
20
|
};
|
|
21
|
+
export declare const getPrismaPlanetScaleAdapter: (config: PrismaConfig) => Promise<import("@prisma/adapter-planetscale").PrismaPlanetScale>;
|
|
22
|
+
export declare const getPrismaMysqlAdapter: (config: PrismaConfig) => Promise<import("@prisma/adapter-mariadb").PrismaMariaDb>;
|
|
23
|
+
export declare const getPrismaPostgresAdapter: () => Promise<import("@prisma/adapter-pg").PrismaPg>;
|
|
21
24
|
export declare class Prisma extends BaseNamespace {
|
|
22
25
|
client: PrismaClientLike;
|
|
23
26
|
config: PrismaConfig;
|
|
@@ -1,28 +1,37 @@
|
|
|
1
1
|
import { getError } from "../../util/_shared/getError.mjs";
|
|
2
2
|
import { BaseNamespace } from "../../_class/_shared/BaseNamespace.mjs";
|
|
3
3
|
//#region src/prisma/server/Prisma.ts
|
|
4
|
+
const getPrismaPlanetScaleAdapter = async (config) => {
|
|
5
|
+
try {
|
|
6
|
+
const { PrismaPlanetScale } = await import("@prisma/adapter-planetscale");
|
|
7
|
+
return new PrismaPlanetScale({ url: config.url });
|
|
8
|
+
} catch (e) {
|
|
9
|
+
throw new Error(`PlanetScale adapter not installed - ${getError(e)}`);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const getPrismaMysqlAdapter = async (config) => {
|
|
13
|
+
try {
|
|
14
|
+
const { PrismaMariaDb } = await import("@prisma/adapter-mariadb");
|
|
15
|
+
return new PrismaMariaDb(config.url);
|
|
16
|
+
} catch (e) {
|
|
17
|
+
throw new Error(`MariaDB adapter not installed - ${getError(e)}`);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const getPrismaPostgresAdapter = async () => {
|
|
21
|
+
try {
|
|
22
|
+
const { PrismaPg } = await import("@prisma/adapter-pg");
|
|
23
|
+
return new PrismaPg({ connectionString: process.env.DATABASE_URL });
|
|
24
|
+
} catch (e) {
|
|
25
|
+
throw new Error(`Postgres adapter not installed - ${getError(e)}`);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
4
28
|
var Prisma = class extends BaseNamespace {
|
|
5
29
|
init = async (config) => {
|
|
6
30
|
if (!this.client) {
|
|
7
31
|
let adapter = null;
|
|
8
|
-
if (config.isPlanetScale)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} catch (e) {
|
|
12
|
-
throw new Error(`PlanetScale adapter not installed - ${getError(e)}`);
|
|
13
|
-
}
|
|
14
|
-
if (config.isMysql) try {
|
|
15
|
-
const { PrismaMariaDb } = await import("@prisma/adapter-mariadb");
|
|
16
|
-
adapter = new PrismaMariaDb(config.url);
|
|
17
|
-
} catch (e) {
|
|
18
|
-
throw new Error(`MariaDB adapter not installed - ${getError(e)}`);
|
|
19
|
-
}
|
|
20
|
-
if (config.isPostgres) try {
|
|
21
|
-
const { PrismaPg } = await import("@prisma/adapter-pg");
|
|
22
|
-
adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL });
|
|
23
|
-
} catch (e) {
|
|
24
|
-
throw new Error(`Postgres adapter not installed - ${getError(e)}`);
|
|
25
|
-
}
|
|
32
|
+
if (config.isPlanetScale) adapter = await getPrismaPlanetScaleAdapter(config);
|
|
33
|
+
else if (config.isMysql) adapter = await getPrismaMysqlAdapter(config);
|
|
34
|
+
else if (config.isPostgres) adapter = await getPrismaPostgresAdapter();
|
|
26
35
|
try {
|
|
27
36
|
const { PrismaClient } = await import("@prisma/client");
|
|
28
37
|
if (config.isDebug) this.client = new PrismaClient({
|
|
@@ -42,4 +51,4 @@ var Prisma = class extends BaseNamespace {
|
|
|
42
51
|
};
|
|
43
52
|
};
|
|
44
53
|
//#endregion
|
|
45
|
-
export { Prisma };
|
|
54
|
+
export { Prisma, getPrismaMysqlAdapter, getPrismaPlanetScaleAdapter, getPrismaPostgresAdapter };
|
|
@@ -3,3 +3,6 @@ const require_prisma__shared_getDecimal = require("../_shared/getDecimal.cjs");
|
|
|
3
3
|
const require_prisma_server_Prisma = require("./Prisma.cjs");
|
|
4
4
|
exports.Prisma = require_prisma_server_Prisma.Prisma;
|
|
5
5
|
exports.getDecimal = require_prisma__shared_getDecimal.getDecimal;
|
|
6
|
+
exports.getPrismaMysqlAdapter = require_prisma_server_Prisma.getPrismaMysqlAdapter;
|
|
7
|
+
exports.getPrismaPlanetScaleAdapter = require_prisma_server_Prisma.getPrismaPlanetScaleAdapter;
|
|
8
|
+
exports.getPrismaPostgresAdapter = require_prisma_server_Prisma.getPrismaPostgresAdapter;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { getDecimal } from "../_shared/getDecimal.cjs";
|
|
2
|
-
import { Prisma, PrismaClientLike } from "./Prisma.cjs";
|
|
3
|
-
export { Prisma, PrismaClientLike, getDecimal };
|
|
2
|
+
import { Prisma, PrismaClientLike, getPrismaMysqlAdapter, getPrismaPlanetScaleAdapter, getPrismaPostgresAdapter } from "./Prisma.cjs";
|
|
3
|
+
export { Prisma, PrismaClientLike, getDecimal, getPrismaMysqlAdapter, getPrismaPlanetScaleAdapter, getPrismaPostgresAdapter };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { getDecimal } from "../_shared/getDecimal.mjs";
|
|
2
|
-
import { Prisma, PrismaClientLike } from "./Prisma.mjs";
|
|
3
|
-
export { Prisma, PrismaClientLike, getDecimal };
|
|
2
|
+
import { Prisma, PrismaClientLike, getPrismaMysqlAdapter, getPrismaPlanetScaleAdapter, getPrismaPostgresAdapter } from "./Prisma.mjs";
|
|
3
|
+
export { Prisma, PrismaClientLike, getDecimal, getPrismaMysqlAdapter, getPrismaPlanetScaleAdapter, getPrismaPostgresAdapter };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { getDecimal } from "../_shared/getDecimal.mjs";
|
|
2
|
-
import { Prisma } from "./Prisma.mjs";
|
|
3
|
-
export { Prisma, getDecimal };
|
|
2
|
+
import { Prisma, getPrismaMysqlAdapter, getPrismaPlanetScaleAdapter, getPrismaPostgresAdapter } from "./Prisma.mjs";
|
|
3
|
+
export { Prisma, getDecimal, getPrismaMysqlAdapter, getPrismaPlanetScaleAdapter, getPrismaPostgresAdapter };
|