@8ms/helpers 2.4.15 → 2.4.16

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.
@@ -10,11 +10,16 @@ var DrizzleNamespace = class extends require__class_BaseNamespace.BaseNamespace
10
10
  const { DefaultLogger } = await import("drizzle-orm/logger");
11
11
  logger = new DefaultLogger();
12
12
  }
13
+ let casing = void 0;
14
+ if ("snake" === this.config?.casing) casing = "snake_case";
15
+ else if ("camel" === this.config?.casing) casing = "camelCase";
13
16
  if (this.config.isPlanetScale) try {
14
17
  const { drizzle } = await import("drizzle-orm/planetscale-serverless");
15
18
  this.client = drizzle({
19
+ casing,
16
20
  connection: { url: this.config.url },
17
21
  relations: this.config?.relations,
22
+ schema: this.config?.schema,
18
23
  logger
19
24
  });
20
25
  } catch (e) {
@@ -22,19 +27,37 @@ var DrizzleNamespace = class extends require__class_BaseNamespace.BaseNamespace
22
27
  }
23
28
  else if (this.config.isMysql) try {
24
29
  const { drizzle } = await import("drizzle-orm/mysql2");
25
- this.client = drizzle({
26
- connection: this.config.url,
27
- relations: this.config?.relations,
28
- logger
30
+ const pool = (await import("mysql2/promise")).createPool({
31
+ uri: this.config.url,
32
+ connectionLimit: this.config.pool?.max ?? 10,
33
+ idleTimeout: this.config.pool?.idleTimeoutMs ?? 3e4,
34
+ connectTimeout: this.config.pool?.connectTimeoutMs ?? 5e3,
35
+ waitForConnections: true,
36
+ queueLimit: 0
37
+ });
38
+ this.client = drizzle(pool, {
39
+ schema: this.config.schema,
40
+ relations: this.config.relations,
41
+ casing,
42
+ logger,
43
+ mode: "default"
29
44
  });
30
45
  } catch (e) {
31
46
  throw new Error(`MySQL2 driver not installed - ${require_util_getError.getError(e)}`);
32
47
  }
33
48
  else if (this.config.isPostgres) try {
34
49
  const { drizzle } = await import("drizzle-orm/node-postgres");
35
- this.client = drizzle({
36
- connection: this.config.url,
37
- relations: this.config?.relations,
50
+ const { Pool } = await import("pg");
51
+ const pool = new Pool({
52
+ connectionString: this.config.url,
53
+ max: this.config.pool?.max ?? 10,
54
+ idleTimeoutMillis: this.config.pool?.idleTimeoutMs ?? 3e4,
55
+ connectionTimeoutMillis: this.config.pool?.connectTimeoutMs ?? 5e3
56
+ });
57
+ this.client = drizzle(pool, {
58
+ schema: this.config.schema,
59
+ relations: this.config.relations,
60
+ casing,
38
61
  logger
39
62
  });
40
63
  } catch (e) {
@@ -1,5 +1,6 @@
1
1
  import { BaseNamespace } from "../../_class/BaseNamespace.cjs";
2
2
  import { DrizzleConfig } from "./drizzle.cjs";
3
+
3
4
  //#region src/drizzle/server/DrizzleNamespace.d.ts
4
5
  declare class DrizzleNamespace<TClient = any> extends BaseNamespace {
5
6
  client: TClient;
@@ -9,11 +9,16 @@ var DrizzleNamespace = class extends BaseNamespace {
9
9
  const { DefaultLogger } = await import("drizzle-orm/logger");
10
10
  logger = new DefaultLogger();
11
11
  }
12
+ let casing = void 0;
13
+ if ("snake" === this.config?.casing) casing = "snake_case";
14
+ else if ("camel" === this.config?.casing) casing = "camelCase";
12
15
  if (this.config.isPlanetScale) try {
13
16
  const { drizzle } = await import("drizzle-orm/planetscale-serverless");
14
17
  this.client = drizzle({
18
+ casing,
15
19
  connection: { url: this.config.url },
16
20
  relations: this.config?.relations,
21
+ schema: this.config?.schema,
17
22
  logger
18
23
  });
19
24
  } catch (e) {
@@ -21,19 +26,37 @@ var DrizzleNamespace = class extends BaseNamespace {
21
26
  }
22
27
  else if (this.config.isMysql) try {
23
28
  const { drizzle } = await import("drizzle-orm/mysql2");
24
- this.client = drizzle({
25
- connection: this.config.url,
26
- relations: this.config?.relations,
27
- logger
29
+ const pool = (await import("mysql2/promise")).createPool({
30
+ uri: this.config.url,
31
+ connectionLimit: this.config.pool?.max ?? 10,
32
+ idleTimeout: this.config.pool?.idleTimeoutMs ?? 3e4,
33
+ connectTimeout: this.config.pool?.connectTimeoutMs ?? 5e3,
34
+ waitForConnections: true,
35
+ queueLimit: 0
36
+ });
37
+ this.client = drizzle(pool, {
38
+ schema: this.config.schema,
39
+ relations: this.config.relations,
40
+ casing,
41
+ logger,
42
+ mode: "default"
28
43
  });
29
44
  } catch (e) {
30
45
  throw new Error(`MySQL2 driver not installed - ${getError(e)}`);
31
46
  }
32
47
  else if (this.config.isPostgres) try {
33
48
  const { drizzle } = await import("drizzle-orm/node-postgres");
34
- this.client = drizzle({
35
- connection: this.config.url,
36
- relations: this.config?.relations,
49
+ const { Pool } = await import("pg");
50
+ const pool = new Pool({
51
+ connectionString: this.config.url,
52
+ max: this.config.pool?.max ?? 10,
53
+ idleTimeoutMillis: this.config.pool?.idleTimeoutMs ?? 3e4,
54
+ connectionTimeoutMillis: this.config.pool?.connectTimeoutMs ?? 5e3
55
+ });
56
+ this.client = drizzle(pool, {
57
+ schema: this.config.schema,
58
+ relations: this.config.relations,
59
+ casing,
37
60
  logger
38
61
  });
39
62
  } catch (e) {
@@ -4,16 +4,16 @@ const require_drizzle_server_DrizzleNamespace = require("./DrizzleNamespace.cjs"
4
4
  const drizzleNamespaces = /* @__PURE__ */ new Map();
5
5
  const drizzleClient = async (key = "default", config) => {
6
6
  if (drizzleNamespaces.has(key)) return drizzleNamespaces.get(key);
7
- if (!config) if (key === "default") config = {
8
- relations: void 0,
9
- url: process.env.DATABASE_URL,
10
- isDebug: "true" === process.env.DATABASE_IS_DEBUG,
11
- isPlanetScale: "true" === process.env.DATABASE_IS_PLANETSCALE,
12
- isMysql: "true" === process.env.DATABASE_IS_MYSQL,
13
- isPostgres: "true" === process.env.DATABASE_IS_POSTGRES
14
- };
7
+ let finalConfig = config ?? {};
8
+ if (key === "default") {
9
+ finalConfig.url = process.env.DATABASE_URL;
10
+ finalConfig.isDebug = "true" === process.env.DATABASE_IS_DEBUG;
11
+ finalConfig.isPlanetScale = "true" === process.env.DATABASE_IS_PLANETSCALE;
12
+ finalConfig.isMysql = "true" === process.env.DATABASE_IS_MYSQL;
13
+ finalConfig.isPostgres = "true" === process.env.DATABASE_IS_POSTGRES;
14
+ } else if ("default" !== key && config) finalConfig = config;
15
15
  else throw new Error(`Config required for namespace '${key}'`);
16
- const namespace = new require_drizzle_server_DrizzleNamespace.DrizzleNamespace(key, config);
16
+ const namespace = new require_drizzle_server_DrizzleNamespace.DrizzleNamespace(key, finalConfig);
17
17
  await namespace.ensureInit();
18
18
  drizzleNamespaces.set(key, namespace);
19
19
  return namespace;
@@ -2,13 +2,20 @@ import { DrizzleNamespace } from "./DrizzleNamespace.cjs";
2
2
  import { defineRelations } from "drizzle-orm";
3
3
 
4
4
  //#region src/drizzle/server/drizzle.d.ts
5
- type DrizzleConfig = {
5
+ type DrizzleConfig<TSchema extends Record<string, unknown> = Record<string, unknown>> = {
6
+ schema?: TSchema;
6
7
  relations?: ReturnType<typeof defineRelations>;
7
- url: string;
8
- isDebug: boolean;
9
- isPlanetScale: boolean;
10
- isMysql: boolean;
11
- isPostgres: boolean;
8
+ url?: string;
9
+ isDebug?: boolean;
10
+ isPlanetScale?: boolean;
11
+ isMysql?: boolean;
12
+ isPostgres?: boolean;
13
+ casing?: "snake" | "camel";
14
+ pool?: {
15
+ max?: number;
16
+ idleTimeoutMs?: number;
17
+ connectTimeoutMs?: number;
18
+ };
12
19
  };
13
20
  declare const drizzleClient: <TClient = any>(key?: string, config?: DrizzleConfig) => Promise<DrizzleNamespace<TClient>>;
14
21
  //#endregion
@@ -2,13 +2,20 @@ import { DrizzleNamespace } from "./DrizzleNamespace.mjs";
2
2
  import { defineRelations } from "drizzle-orm";
3
3
 
4
4
  //#region src/drizzle/server/drizzle.d.ts
5
- type DrizzleConfig = {
5
+ type DrizzleConfig<TSchema extends Record<string, unknown> = Record<string, unknown>> = {
6
+ schema?: TSchema;
6
7
  relations?: ReturnType<typeof defineRelations>;
7
- url: string;
8
- isDebug: boolean;
9
- isPlanetScale: boolean;
10
- isMysql: boolean;
11
- isPostgres: boolean;
8
+ url?: string;
9
+ isDebug?: boolean;
10
+ isPlanetScale?: boolean;
11
+ isMysql?: boolean;
12
+ isPostgres?: boolean;
13
+ casing?: "snake" | "camel";
14
+ pool?: {
15
+ max?: number;
16
+ idleTimeoutMs?: number;
17
+ connectTimeoutMs?: number;
18
+ };
12
19
  };
13
20
  declare const drizzleClient: <TClient = any>(key?: string, config?: DrizzleConfig) => Promise<DrizzleNamespace<TClient>>;
14
21
  //#endregion
@@ -3,16 +3,16 @@ import { DrizzleNamespace } from "./DrizzleNamespace.mjs";
3
3
  const drizzleNamespaces = /* @__PURE__ */ new Map();
4
4
  const drizzleClient = async (key = "default", config) => {
5
5
  if (drizzleNamespaces.has(key)) return drizzleNamespaces.get(key);
6
- if (!config) if (key === "default") config = {
7
- relations: void 0,
8
- url: process.env.DATABASE_URL,
9
- isDebug: "true" === process.env.DATABASE_IS_DEBUG,
10
- isPlanetScale: "true" === process.env.DATABASE_IS_PLANETSCALE,
11
- isMysql: "true" === process.env.DATABASE_IS_MYSQL,
12
- isPostgres: "true" === process.env.DATABASE_IS_POSTGRES
13
- };
6
+ let finalConfig = config ?? {};
7
+ if (key === "default") {
8
+ finalConfig.url = process.env.DATABASE_URL;
9
+ finalConfig.isDebug = "true" === process.env.DATABASE_IS_DEBUG;
10
+ finalConfig.isPlanetScale = "true" === process.env.DATABASE_IS_PLANETSCALE;
11
+ finalConfig.isMysql = "true" === process.env.DATABASE_IS_MYSQL;
12
+ finalConfig.isPostgres = "true" === process.env.DATABASE_IS_POSTGRES;
13
+ } else if ("default" !== key && config) finalConfig = config;
14
14
  else throw new Error(`Config required for namespace '${key}'`);
15
- const namespace = new DrizzleNamespace(key, config);
15
+ const namespace = new DrizzleNamespace(key, finalConfig);
16
16
  await namespace.ensureInit();
17
17
  drizzleNamespaces.set(key, namespace);
18
18
  return namespace;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "2.4.15",
4
+ "version": "2.4.16",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
@@ -42,7 +42,9 @@
42
42
  "@prisma/client": "^7.0.0",
43
43
  "drizzle-orm": "*",
44
44
  "googleapis-common": "^8.0.0",
45
+ "mysql2": "^3.0.0",
45
46
  "next": "^16.0.0",
47
+ "pg": "^8.0.0",
46
48
  "react": "^19.0.0",
47
49
  "react-intersection-observer": "^10.0.0",
48
50
  "stream-chain": "^3.0.0",
@@ -124,9 +126,15 @@
124
126
  "googleapis-common": {
125
127
  "optional": true
126
128
  },
129
+ "mysql2": {
130
+ "optional": true
131
+ },
127
132
  "next": {
128
133
  "optional": true
129
134
  },
135
+ "pg": {
136
+ "optional": true
137
+ },
130
138
  "react": {
131
139
  "optional": true
132
140
  },
@@ -165,7 +173,7 @@
165
173
  "@prisma/adapter-planetscale": "^7.7.0",
166
174
  "@prisma/client": "^7.7.0",
167
175
  "@types/babel__core": "^7.20.5",
168
- "@types/fs-extra": "11.0.4",
176
+ "@types/fs-extra": "^11.0.4",
169
177
  "@types/jest": "30.0.0",
170
178
  "@types/luxon": "3.7.1",
171
179
  "@types/node": "^24.12.2",
@@ -173,18 +181,20 @@
173
181
  "babel-jest": "30.3.0",
174
182
  "dotenv": "^17.4.1",
175
183
  "drizzle-orm": "beta",
176
- "fs-extra": "11.3.4",
184
+ "fs-extra": "^11.3.4",
177
185
  "googleapis-common": "^8.0.1",
178
- "jest": "30.3.0",
186
+ "jest": "^30.3.0",
187
+ "mysql2": "^3.22.2",
179
188
  "next": "^16.2.3",
180
- "node-fetch": "3.3.2",
189
+ "node-fetch": "^3.3.2",
190
+ "pg": "^8.20.0",
181
191
  "react": "^19.2.5",
182
192
  "react-intersection-observer": "^10.0.3",
183
193
  "stream-chain": "^3.6.1",
184
194
  "swr": "^2.4.1",
185
- "ts-node": "10.9.2",
195
+ "ts-node": "^10.9.2",
186
196
  "tsdown": "^0.21.7",
187
- "tslib": "2.8.1",
197
+ "tslib": "^2.8.0",
188
198
  "typescript": "^6.0.2"
189
199
  },
190
200
  "exports": {