@nathapp/nestjs-prisma 4.2.2 → 4.2.4
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.
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SqlDriverAdapterFactory } from '@prisma/client/runtime/client';
|
|
2
|
+
export interface MariaDbPoolConfig {
|
|
3
|
+
host: string;
|
|
4
|
+
port: number;
|
|
5
|
+
user: string;
|
|
6
|
+
password: string;
|
|
7
|
+
database: string;
|
|
8
|
+
connectionLimit: number;
|
|
9
|
+
connectTimeout: number;
|
|
10
|
+
acquireTimeout: number;
|
|
11
|
+
timezone: '+00:00';
|
|
12
|
+
ssl?: {
|
|
13
|
+
ca?: string;
|
|
14
|
+
rejectUnauthorized: true;
|
|
15
|
+
};
|
|
16
|
+
allowPublicKeyRetrieval?: true;
|
|
17
|
+
}
|
|
18
|
+
export interface MariaDbAdapterOptions {
|
|
19
|
+
sslCertBaseDir?: string;
|
|
20
|
+
readFile?: (path: string, encoding: 'utf8') => string;
|
|
21
|
+
}
|
|
22
|
+
export declare function parseMysqlUrl(databaseUrl: string, options?: MariaDbAdapterOptions): MariaDbPoolConfig;
|
|
23
|
+
export declare function createMariaDbAdapter(databaseUrl?: string, options?: MariaDbAdapterOptions): SqlDriverAdapterFactory;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseMysqlUrl = parseMysqlUrl;
|
|
4
|
+
exports.createMariaDbAdapter = createMariaDbAdapter;
|
|
5
|
+
const node_os_1 = require("node:os");
|
|
6
|
+
const node_fs_1 = require("node:fs");
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
8
|
+
const nestjs_common_1 = require("@nathapp/nestjs-common");
|
|
9
|
+
const MALFORMED_ESCAPE = 'DATABASE_URL has a malformed percent-escape';
|
|
10
|
+
const SUPPORTED_PARAMETERS = new Set([
|
|
11
|
+
'connection_limit', 'connect_timeout', 'pool_timeout', 'timezone', 'sslaccept', 'sslcert',
|
|
12
|
+
]);
|
|
13
|
+
function decodeComponent(value) {
|
|
14
|
+
try {
|
|
15
|
+
return decodeURIComponent(value);
|
|
16
|
+
}
|
|
17
|
+
catch (_a) {
|
|
18
|
+
throw new Error(MALFORMED_ESCAPE);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function parseSeconds(value, name) {
|
|
22
|
+
const seconds = Number(value);
|
|
23
|
+
if (value.trim() === '' || !Number.isFinite(seconds) || seconds < 0) {
|
|
24
|
+
throw new Error(`DATABASE_URL parameter ${name} must be a non-negative number of seconds`);
|
|
25
|
+
}
|
|
26
|
+
return seconds * 1000;
|
|
27
|
+
}
|
|
28
|
+
function parseMysqlUrl(databaseUrl, options = {}) {
|
|
29
|
+
var _a;
|
|
30
|
+
let url;
|
|
31
|
+
try {
|
|
32
|
+
url = new URL(databaseUrl);
|
|
33
|
+
}
|
|
34
|
+
catch (_b) {
|
|
35
|
+
throw new Error('DATABASE_URL must be a mysql:// URL');
|
|
36
|
+
}
|
|
37
|
+
if (url.protocol !== 'mysql:') {
|
|
38
|
+
throw new Error('DATABASE_URL must be a mysql:// URL');
|
|
39
|
+
}
|
|
40
|
+
const rawDatabase = url.pathname.slice(1);
|
|
41
|
+
if (!rawDatabase) {
|
|
42
|
+
throw new Error('DATABASE_URL must include a database name');
|
|
43
|
+
}
|
|
44
|
+
const user = decodeComponent(url.username);
|
|
45
|
+
const password = decodeComponent(url.password);
|
|
46
|
+
const database = decodeComponent(rawDatabase);
|
|
47
|
+
const diagnosticValue = (value) => [password, url.password].some((secret) => secret !== '' && value.includes(secret))
|
|
48
|
+
? '[REDACTED]'
|
|
49
|
+
: value;
|
|
50
|
+
for (const [name] of url.searchParams) {
|
|
51
|
+
if (!SUPPORTED_PARAMETERS.has(name)) {
|
|
52
|
+
throw new Error(`Unsupported DATABASE_URL parameter: ${diagnosticValue(name)}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const connectionLimitValue = url.searchParams.get('connection_limit');
|
|
56
|
+
let connectionLimit = (0, node_os_1.availableParallelism)() * 2 + 1;
|
|
57
|
+
if (connectionLimitValue !== null) {
|
|
58
|
+
if (!/^\d+$/.test(connectionLimitValue) || Number(connectionLimitValue) <= 0 || !Number.isSafeInteger(Number(connectionLimitValue))) {
|
|
59
|
+
throw new Error('DATABASE_URL parameter connection_limit must be a positive integer');
|
|
60
|
+
}
|
|
61
|
+
connectionLimit = Number(connectionLimitValue);
|
|
62
|
+
}
|
|
63
|
+
const connectTimeoutValue = url.searchParams.get('connect_timeout');
|
|
64
|
+
const poolTimeoutValue = url.searchParams.get('pool_timeout');
|
|
65
|
+
const timezoneValue = url.searchParams.get('timezone');
|
|
66
|
+
if (timezoneValue !== null && !['utc', 'z', '+00:00', ' 00:00'].includes(timezoneValue.toLowerCase())) {
|
|
67
|
+
throw new Error(`DATABASE_URL timezone must be UTC (got ${diagnosticValue(timezoneValue)})`);
|
|
68
|
+
}
|
|
69
|
+
const sslaccept = url.searchParams.get('sslaccept');
|
|
70
|
+
if (sslaccept !== null && sslaccept !== 'strict') {
|
|
71
|
+
throw new Error('DATABASE_URL sslaccept must be sslaccept=strict (certificate verification cannot be turned off)');
|
|
72
|
+
}
|
|
73
|
+
const sslcert = url.searchParams.get('sslcert');
|
|
74
|
+
let ssl;
|
|
75
|
+
if (sslaccept === 'strict' || sslcert !== null) {
|
|
76
|
+
ssl = { rejectUnauthorized: true };
|
|
77
|
+
if (sslcert !== null) {
|
|
78
|
+
let certPath = sslcert;
|
|
79
|
+
if (!(0, node_path_1.isAbsolute)(certPath)) {
|
|
80
|
+
if (!options.sslCertBaseDir) {
|
|
81
|
+
throw new Error('DATABASE_URL sslcert is relative; pass sslCertBaseDir to resolve it');
|
|
82
|
+
}
|
|
83
|
+
certPath = (0, node_path_1.resolve)(options.sslCertBaseDir, certPath);
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
ssl.ca = ((_a = options.readFile) !== null && _a !== void 0 ? _a : ((path, encoding) => (0, node_fs_1.readFileSync)(path, encoding)))(certPath, 'utf8');
|
|
87
|
+
}
|
|
88
|
+
catch (cause) {
|
|
89
|
+
throw Object.assign(new Error(`DATABASE_URL sslcert could not be read: ${diagnosticValue(certPath)}`), { cause });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
host: url.hostname.replace(/^\[|\]$/g, ''),
|
|
95
|
+
port: url.port ? Number(url.port) : 3306,
|
|
96
|
+
user,
|
|
97
|
+
password,
|
|
98
|
+
database,
|
|
99
|
+
connectionLimit,
|
|
100
|
+
connectTimeout: connectTimeoutValue === null ? 5000 : parseSeconds(connectTimeoutValue, 'connect_timeout'),
|
|
101
|
+
acquireTimeout: poolTimeoutValue === null ? 10000 : parseSeconds(poolTimeoutValue, 'pool_timeout'),
|
|
102
|
+
timezone: '+00:00',
|
|
103
|
+
...(ssl ? { ssl } : { allowPublicKeyRetrieval: true }),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function createMariaDbAdapter(databaseUrl, options) {
|
|
107
|
+
const resolvedUrl = databaseUrl || process.env.DATABASE_URL;
|
|
108
|
+
if (!resolvedUrl)
|
|
109
|
+
throw new Error('DATABASE_URL is not set');
|
|
110
|
+
const { PrismaMariaDb } = (0, nestjs_common_1.loadPackage)('@prisma/adapter-mariadb', 'createMariaDbAdapter', () => require('@prisma/adapter-mariadb'));
|
|
111
|
+
return new PrismaMariaDb(parseMysqlUrl(resolvedUrl, options));
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=mariadb-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mariadb-adapter.js","sourceRoot":"","sources":["../../lib/adapter/mariadb-adapter.ts"],"names":[],"mappings":";;AAgDA,sCAqFC;AAED,oDAUC;AAjJD,qCAA+C;AAC/C,qCAAuC;AACvC,yCAAgD;AAChD,0D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MAAM,WAAW,GAAG,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;IAC5D,IAAI,CAAC,WAAW;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7D,MAAM,EAAE,aAAa,EAAE,GAAG,IAAA,2BAAW,EACnC,yBAAyB,EACzB,sBAAsB,EAEtB,GAAG,EAAE,CAAC,OAAO,CAAC,yBAAyB,CAAC,CACzC,CAAC;IACF,OAAO,IAAI,aAAa,CAAC,aAAa,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;AAChE,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -27,4 +27,5 @@ __exportStar(require("./errors/unique-constraint-target"), exports);
|
|
|
27
27
|
__exportStar(require("./filter/prisma-exception.filter"), exports);
|
|
28
28
|
__exportStar(require("./transaction"), exports);
|
|
29
29
|
__exportStar(require("./repository"), exports);
|
|
30
|
+
__exportStar(require("./adapter/mariadb-adapter"), exports);
|
|
30
31
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,sDAAoC;AACpC,kDAAgC;AAChC,mDAAiC;AACjC,qDAAmC;AACnC,kDAAgC;AAChC,+CAA6B;AAC7B,4CAA0B;AAC1B,+DAA6C;AAC7C,oEAAkD;AAClD,mEAAiD;AACjD,gDAA8B;AAC9B,+CAA6B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,sDAAoC;AACpC,kDAAgC;AAChC,mDAAiC;AACjC,qDAAmC;AACnC,kDAAgC;AAChC,+CAA6B;AAC7B,4CAA0B;AAC1B,+DAA6C;AAC7C,oEAAkD;AAClD,mEAAiD;AACjD,gDAA8B;AAC9B,+CAA6B;AAC7B,4DAA0C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nathapp/nestjs-prisma",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.4",
|
|
4
4
|
"description": "NestJS Prisma integration with multi-database support",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rimraf dist/ .turbo/",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"types": "dist/index.d.ts",
|
|
21
21
|
"main": "dist/index.js",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@nathapp/nestjs-common": "^4.2.
|
|
24
|
-
"@nathapp/nestjs-data": "^4.2.
|
|
23
|
+
"@nathapp/nestjs-common": "^4.2.4",
|
|
24
|
+
"@nathapp/nestjs-data": "^4.2.4"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@nathapp/eslint-config": "1.0.1",
|
|
@@ -36,6 +36,12 @@
|
|
|
36
36
|
"@nathapp/nestjs-common": "^4.0.0-rc.0",
|
|
37
37
|
"@nestjs/common": "^10.0.0 || ^11.0.0 || ^12.0.0",
|
|
38
38
|
"@nestjs/core": "^10.0.0 || ^11.0.0 || ^12.0.0",
|
|
39
|
+
"@prisma/adapter-mariadb": "^7.0.0",
|
|
39
40
|
"@prisma/client": "^7.0.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependenciesMeta": {
|
|
43
|
+
"@prisma/adapter-mariadb": {
|
|
44
|
+
"optional": true
|
|
45
|
+
}
|
|
40
46
|
}
|
|
41
47
|
}
|