@8ms/helpers 2.3.16 → 2.3.18

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.
Binary file
@@ -0,0 +1,20 @@
1
+ import { t as BaseNamespace } from "../../index-DwB8X1lz.mjs";
2
+
3
+ //#region src/drizzle/server/DrizzleNamespace.d.ts
4
+ declare class DrizzleNamespace extends BaseNamespace {
5
+ client: any;
6
+ config: DrizzleConfig;
7
+ ensureInit: () => Promise<void>;
8
+ }
9
+ //#endregion
10
+ //#region src/drizzle/server/drizzle.d.ts
11
+ type DrizzleConfig = {
12
+ url: string;
13
+ isDebug: boolean;
14
+ isPlanetScale: boolean;
15
+ isMysql: boolean;
16
+ isPostgres: boolean;
17
+ };
18
+ declare const drizzleClient: (key?: string, config?: DrizzleConfig) => Promise<DrizzleNamespace>;
19
+ //#endregion
20
+ export { DrizzleConfig, DrizzleNamespace, drizzleClient };
@@ -0,0 +1,65 @@
1
+ import { getError } from "../../util/index.mjs";
2
+ import { BaseNamespace } from "../../_class/index.mjs";
3
+
4
+ //#region src/drizzle/server/DrizzleNamespace.ts
5
+ var DrizzleNamespace = class extends BaseNamespace {
6
+ ensureInit = async () => {
7
+ if (!this.client) {
8
+ let logger = void 0;
9
+ if (this.config.isDebug) {
10
+ const { DefaultLogger } = await import("drizzle-orm/logger");
11
+ logger = new DefaultLogger();
12
+ }
13
+ if (this.config.isPlanetScale) try {
14
+ const { drizzle } = await import("drizzle-orm/planetscale-serverless");
15
+ this.client = drizzle({
16
+ connection: { url: this.config.url },
17
+ logger
18
+ });
19
+ } catch (e) {
20
+ throw new Error(`PlanetScale driver not installed - ${getError(e)}`);
21
+ }
22
+ else if (this.config.isMysql) try {
23
+ const { drizzle } = await import("drizzle-orm/mysql2");
24
+ this.client = drizzle({
25
+ connection: this.config.url,
26
+ logger
27
+ });
28
+ } catch (e) {
29
+ throw new Error(`MySQL2 driver not installed - ${getError(e)}`);
30
+ }
31
+ else if (this.config.isPostgres) try {
32
+ const { drizzle } = await import("drizzle-orm/node-postgres");
33
+ this.client = drizzle({
34
+ connection: this.config.url,
35
+ logger
36
+ });
37
+ } catch (e) {
38
+ throw new Error(`Postgres (pg) driver not installed - ${getError(e)}`);
39
+ }
40
+ else throw new Error(`No database type configured — set DATABASE_IS_PLANETSCALE, DATABASE_IS_MYSQL or DATABASE_IS_POSTGRES to "true"`);
41
+ }
42
+ };
43
+ };
44
+
45
+ //#endregion
46
+ //#region src/drizzle/server/drizzle.ts
47
+ const drizzleNamespaces = /* @__PURE__ */ new Map();
48
+ const drizzleClient = async (key = "default", config) => {
49
+ if (drizzleNamespaces.has(key)) return drizzleNamespaces.get(key);
50
+ if (!config) if (key === "default") config = {
51
+ url: process.env.DATABASE_URL,
52
+ isDebug: "true" === process.env.DATABASE_IS_DEBUG,
53
+ isPlanetScale: "true" === process.env.DATABASE_IS_PLANETSCALE,
54
+ isMysql: "true" === process.env.DATABASE_IS_MYSQL,
55
+ isPostgres: "true" === process.env.DATABASE_IS_POSTGRES
56
+ };
57
+ else throw new Error(`Config required for namespace '${key}'`);
58
+ const namespace = new DrizzleNamespace(key, config);
59
+ await namespace.ensureInit();
60
+ drizzleNamespaces.set(key, namespace);
61
+ return namespace;
62
+ };
63
+
64
+ //#endregion
65
+ export { DrizzleNamespace, drizzleClient };
@@ -1,5 +1,5 @@
1
1
  import { t as BaseNamespace } from "../../../index-DwB8X1lz.mjs";
2
- import { t as GoogleCloudConfig } from "../../../index-jtr7o55v.mjs";
2
+ import { t as GoogleCloudConfig } from "../../../index-DmCSxHCc.mjs";
3
3
  import { BigQuery, DatasetResource, QueryOptions } from "@google-cloud/bigquery";
4
4
  import { GoogleAuthOptions } from "@google-cloud/common";
5
5
 
@@ -1,2 +1,2 @@
1
- import { n as getConfig, t as GoogleCloudConfig } from "../../index-jtr7o55v.mjs";
1
+ import { n as getConfig, t as GoogleCloudConfig } from "../../index-DmCSxHCc.mjs";
2
2
  export { GoogleCloudConfig, getConfig };
@@ -1,5 +1,5 @@
1
1
  import { t as BaseNamespace } from "../../../index-DwB8X1lz.mjs";
2
- import { t as GoogleCloudConfig } from "../../../index-jtr7o55v.mjs";
2
+ import { t as GoogleCloudConfig } from "../../../index-DmCSxHCc.mjs";
3
3
  import * as _googleapis_sheets0 from "@googleapis/sheets";
4
4
  import { GoogleAuth } from "googleapis-common";
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { t as BaseNamespace } from "../../../index-DwB8X1lz.mjs";
2
- import { t as GoogleCloudConfig } from "../../../index-jtr7o55v.mjs";
2
+ import { t as GoogleCloudConfig } from "../../../index-DmCSxHCc.mjs";
3
3
  import * as _google_cloud_storage0 from "@google-cloud/storage";
4
4
  import { Storage } from "@google-cloud/storage";
5
5
  import { GoogleAuthOptions } from "@google-cloud/common";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "2.3.16",
4
+ "version": "2.3.18",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
@@ -41,6 +41,7 @@
41
41
  "@prisma/adapter-pg": "^7.0.0",
42
42
  "@prisma/adapter-planetscale": "^7.0.0",
43
43
  "@prisma/client": "^7.0.0",
44
+ "drizzle-orm": "^0.45.1",
44
45
  "fs-extra": "^11.0.0",
45
46
  "google-ads-api": "^23.0.0",
46
47
  "googleapis-common": "^8.0.0",
@@ -112,6 +113,9 @@
112
113
  "@prisma/client": {
113
114
  "optional": true
114
115
  },
116
+ "drizzle-orm": {
117
+ "optional": true
118
+ },
115
119
  "fs-extra": {
116
120
  "optional": true
117
121
  },
@@ -170,6 +174,7 @@
170
174
  "@types/react": "^19.2.14",
171
175
  "babel-jest": "30.2.0",
172
176
  "dotenv": "^17.3.1",
177
+ "drizzle-orm": "^0.45.1",
173
178
  "fs-extra": "11.3.3",
174
179
  "google-ads-api": "^23.0.0",
175
180
  "googleapis-common": "^8.0.0",
@@ -211,6 +216,7 @@
211
216
  "./crud": "./dist/crud/index.mjs",
212
217
  "./crypto": "./dist/crypto/index.mjs",
213
218
  "./date": "./dist/date/index.mjs",
219
+ "./drizzle/server": "./dist/drizzle/server/index.mjs",
214
220
  "./environment": "./dist/environment/index.mjs",
215
221
  "./eskimi": "./dist/eskimi/index.mjs",
216
222
  "./eskimi/server": "./dist/eskimi/server/index.mjs",