@pi-r/mysql 0.7.2 → 0.7.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.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
- ### @pi-r/mysql
2
-
3
- https://e-mc.readthedocs.io/en/latest/db/mysql.html
4
-
5
- ### LICENSE
6
-
1
+ ### @pi-r/mysql
2
+
3
+ https://e-mc.readthedocs.io/en/latest/db/mysql.html
4
+
5
+ ### LICENSE
6
+
7
7
  MIT
package/client/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import type { IDb } from '@e-mc/types/lib';
2
-
3
- import type { IDbSourceClient } from '@e-mc/db/types';
4
-
5
- import type { MySQLCredential, MySQLDataSource } from '../types';
6
-
7
- declare const MySQL: IDbSourceClient<MySQLDataSource> & {
8
- setAuthentication(this: IDb, credential: MySQLCredential): void;
9
- };
10
-
1
+ import type { IDb } from '@e-mc/types/lib';
2
+
3
+ import type { IDbSourceClient } from '@e-mc/db/types';
4
+
5
+ import type { MySQLCredential, MySQLDataSource } from '../types';
6
+
7
+ declare const MySQL: IDbSourceClient<MySQLDataSource> & {
8
+ setAuthentication(this: IDb, credential: MySQLCredential): void;
9
+ };
10
+
11
11
  export = MySQL;
package/client/pool.js ADDED
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ const util_1 = require("@e-mc/db/util");
3
+ const types_1 = require("@e-mc/types");
4
+ const DbPool = require('@e-mc/db/pool');
5
+ const POOL_ACTIVE = new WeakSet();
6
+ class MySQLPool extends DbPool {
7
+ static asString(credential) {
8
+ if ((credential.host || credential.socketPath) && credential.user) {
9
+ return JSON.stringify(this.removeUUIDKey(credential));
10
+ }
11
+ return super.asString(credential);
12
+ }
13
+ static sanitize(credential) {
14
+ if (!POOL_ACTIVE.has(credential) || credential.uuidKey) {
15
+ return credential;
16
+ }
17
+ const ssl = credential.ssl;
18
+ let result = super.sanitize(credential);
19
+ if ((0, types_1.isObject)(ssl)) {
20
+ if (result === credential) {
21
+ result = { ...credential };
22
+ }
23
+ const cert = ssl.cert;
24
+ if ((0, types_1.isString)(cert)) {
25
+ result.ssl = cert;
26
+ }
27
+ else if (Buffer.isBuffer(cert)) {
28
+ result.ssl = cert.toString('utf-8');
29
+ }
30
+ else if ((0, types_1.isArray)(cert)) {
31
+ result.ssl = cert.reduce((a, b) => a + (Buffer.isBuffer(b) ? b.toString('utf-8') : b), '');
32
+ }
33
+ else {
34
+ result.ssl = "Unknown";
35
+ }
36
+ }
37
+ return result;
38
+ }
39
+ async getConnection(credential) {
40
+ if (credential) {
41
+ POOL_ACTIVE.add(credential);
42
+ }
43
+ return this.client.getConnection();
44
+ }
45
+ async close() {
46
+ return this.client.end();
47
+ }
48
+ isEmpty() {
49
+ const pool = this.client.pool;
50
+ return this.closed || (0, util_1.checkEmpty)(pool._allConnections) && (0, util_1.checkEmpty)(pool._connectionQueue);
51
+ }
52
+ get closed() {
53
+ return !!this.client.pool._closed;
54
+ }
55
+ }
56
+ MySQLPool.CACHE_UNUSED = ['connectTimeout', 'queueLimit', 'waitForConnections', 'connectionLimit', 'maxIdle', 'idleTimeout', 'enableKeepAlive', 'keepAliveInitialDelay', 'Promise'];
57
+ module.exports = MySQLPool;
package/package.json CHANGED
@@ -1,28 +1,28 @@
1
- {
2
- "name": "@pi-r/mysql",
3
- "version": "0.7.2",
4
- "description": "MySQL client driver for E-mc.",
5
- "main": "client/index.js",
6
- "types": "client/index.d.ts",
7
- "publishConfig": {
8
- "access": "public"
9
- },
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/anpham6/pi-r.git",
13
- "directory": "src/db/mysql"
14
- },
15
- "keywords": [
16
- "squared",
17
- "e-mc",
18
- "squared-functions"
19
- ],
20
- "author": "An Pham <anpham6@gmail.com>",
21
- "license": "MIT",
22
- "homepage": "https://github.com/anpham6/pi-r#readme",
23
- "dependencies": {
24
- "@e-mc/db": "^0.9.4",
25
- "@e-mc/types": "^0.9.4",
26
- "mysql2": "^3.10.1"
27
- }
28
- }
1
+ {
2
+ "name": "@pi-r/mysql",
3
+ "version": "0.7.4",
4
+ "description": "MySQL client driver for E-mc.",
5
+ "main": "client/index.js",
6
+ "types": "client/index.d.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/anpham6/pi-r.git",
13
+ "directory": "src/db/mysql"
14
+ },
15
+ "keywords": [
16
+ "squared",
17
+ "e-mc",
18
+ "squared-functions"
19
+ ],
20
+ "author": "An Pham <anpham6@gmail.com>",
21
+ "license": "MIT",
22
+ "homepage": "https://github.com/anpham6/pi-r#readme",
23
+ "dependencies": {
24
+ "@e-mc/db": "^0.9.12",
25
+ "@e-mc/types": "^0.9.12",
26
+ "mysql2": "^3.11.3"
27
+ }
28
+ }
package/types/index.d.ts CHANGED
@@ -1,15 +1,15 @@
1
- import type { DbDataSource } from '@e-mc/types/lib/squared';
2
-
3
- import type { ExecuteAction, ServerAuth } from '@e-mc/types/lib/db';
4
-
5
- import type { SecureContextOptions } from 'tls';
6
-
7
- import type { PoolOptions, QueryOptions } from 'mysql2/promise';
8
-
9
- export interface MySQLDataSource<T = unknown> extends DbDataSource<string | QueryOptions, unknown, unknown, MySQLCredential, string>, ExecuteAction<T> {
10
- source: "mysql";
11
- }
12
-
13
- export interface MySQLCredential extends ServerAuth, Omit<PoolOptions, "ssl"> {
14
- ssl?: boolean | string | SecureContextOptions & { rejectUnauthorized?: boolean };
1
+ import type { DbDataSource } from '@e-mc/types/lib/squared';
2
+
3
+ import type { ExecuteAction, ServerAuth } from '@e-mc/types/lib/db';
4
+
5
+ import type { SecureContextOptions } from 'tls';
6
+
7
+ import type { PoolOptions, QueryOptions } from 'mysql2/promise';
8
+
9
+ export interface MySQLDataSource<T = unknown> extends DbDataSource<string | QueryOptions, unknown, unknown, MySQLCredential, string>, ExecuteAction<T> {
10
+ source: "mysql";
11
+ }
12
+
13
+ export interface MySQLCredential extends ServerAuth, Omit<PoolOptions, "ssl"> {
14
+ ssl?: boolean | string | SecureContextOptions & { rejectUnauthorized?: boolean };
15
15
  }