@8ms/helpers 2.4.11 → 2.4.13

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.
@@ -5,7 +5,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
8
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
9
9
  var __copyProps = (to, from, except, desc) => {
10
10
  if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
11
  key = keys[i];
@@ -6,7 +6,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
7
  var __getProtoOf = Object.getPrototypeOf;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
9
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
10
10
  var __copyProps = (to, from, except, desc) => {
11
11
  if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
12
  key = keys[i];
@@ -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;
@@ -7,7 +7,8 @@ var GoogleCloudBigqueryNamespace = class extends require__class_BaseNamespace.Ba
7
7
  ensureInit = async () => {
8
8
  if (!this.client) try {
9
9
  const { BigQuery } = await import("@google-cloud/bigquery");
10
- this.client = new BigQuery(require_googleCloud_server_googleCloud.getConfig(this.config, this.config?.projectId));
10
+ const formattedConfig = require_googleCloud_server_googleCloud.getConfig(this.config, this.config?.projectId);
11
+ this.client = new BigQuery(formattedConfig);
11
12
  } catch (e) {
12
13
  throw new Error("Google BigQuery Client not installed");
13
14
  }
@@ -6,7 +6,8 @@ var GoogleCloudBigqueryNamespace = class extends BaseNamespace {
6
6
  ensureInit = async () => {
7
7
  if (!this.client) try {
8
8
  const { BigQuery } = await import("@google-cloud/bigquery");
9
- this.client = new BigQuery(getConfig(this.config, this.config?.projectId));
9
+ const formattedConfig = getConfig(this.config, this.config?.projectId);
10
+ this.client = new BigQuery(formattedConfig);
10
11
  } catch (e) {
11
12
  throw new Error("Google BigQuery Client not installed");
12
13
  }
@@ -6,7 +6,8 @@ var GoogleCloudStorageNamespace = class extends require__class_BaseNamespace.Bas
6
6
  ensureInit = async () => {
7
7
  if (!this.client) try {
8
8
  const { Storage } = await import("@google-cloud/storage");
9
- this.client = new Storage(require_googleCloud_server_googleCloud.getConfig(this.config, this.config?.projectId));
9
+ const formattedConfig = require_googleCloud_server_googleCloud.getConfig(this.config, this.config?.projectId);
10
+ this.client = new Storage(formattedConfig);
10
11
  } catch (e) {
11
12
  throw new Error("Google Cloud Storage Client not installed");
12
13
  }
@@ -5,7 +5,8 @@ var GoogleCloudStorageNamespace = class extends BaseNamespace {
5
5
  ensureInit = async () => {
6
6
  if (!this.client) try {
7
7
  const { Storage } = await import("@google-cloud/storage");
8
- this.client = new Storage(getConfig(this.config, this.config?.projectId));
8
+ const formattedConfig = getConfig(this.config, this.config?.projectId);
9
+ this.client = new Storage(formattedConfig);
9
10
  } catch (e) {
10
11
  throw new Error("Google Cloud Storage Client not installed");
11
12
  }
@@ -1,3 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_LazyLoad = require("./LazyLoad.cjs");
3
+ const require_nextJs_client_useAsyncEffect = require("./useAsyncEffect.cjs");
3
4
  exports.LazyLoad = require_LazyLoad.LazyLoad;
5
+ exports.useAsyncEffect = require_nextJs_client_useAsyncEffect.useAsyncEffect;
@@ -1,2 +1,3 @@
1
1
  import { LazyLoad } from "./LazyLoad.cjs";
2
- export { LazyLoad };
2
+ import { useAsyncEffect } from "./useAsyncEffect.cjs";
3
+ export { LazyLoad, useAsyncEffect };
@@ -1,2 +1,3 @@
1
1
  import { LazyLoad } from "./LazyLoad.mjs";
2
- export { LazyLoad };
2
+ import { useAsyncEffect } from "./useAsyncEffect.mjs";
3
+ export { LazyLoad, useAsyncEffect };
@@ -1,2 +1,3 @@
1
1
  import { LazyLoad } from "./LazyLoad.mjs";
2
- export { LazyLoad };
2
+ import { useAsyncEffect } from "./useAsyncEffect.mjs";
3
+ export { LazyLoad, useAsyncEffect };
@@ -0,0 +1,22 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("../../_virtual/_rolldown/runtime.cjs");
3
+ let react = require("react");
4
+ //#region src/nextJs/client/useAsyncEffect.ts
5
+ const useAsyncEffect = (effect, destroyOrInputs, inputs) => {
6
+ const hasDestroy = "function" === typeof destroyOrInputs;
7
+ const destroy = hasDestroy ? destroyOrInputs : void 0;
8
+ (0, react.useEffect)(() => {
9
+ let result;
10
+ let mounted = true;
11
+ const maybePromise = effect(() => mounted);
12
+ Promise.resolve(maybePromise).then((value) => {
13
+ result = value;
14
+ });
15
+ return () => {
16
+ mounted = false;
17
+ if (hasDestroy && destroy) destroy(result);
18
+ };
19
+ }, hasDestroy ? inputs : destroyOrInputs);
20
+ };
21
+ //#endregion
22
+ exports.useAsyncEffect = useAsyncEffect;
@@ -0,0 +1,8 @@
1
+ //#region src/nextJs/client/useAsyncEffect.d.ts
2
+ type UseAsyncEffect = {
3
+ (effect: (isMounted: () => boolean) => unknown | Promise<unknown>, inputs?: any[]): void;
4
+ <T>(effect: (isMounted: () => boolean) => T | Promise<T>, destroy?: (result?: T) => void, inputs?: any[]): void;
5
+ };
6
+ declare const useAsyncEffect: UseAsyncEffect;
7
+ //#endregion
8
+ export { useAsyncEffect };
@@ -0,0 +1,8 @@
1
+ //#region src/nextJs/client/useAsyncEffect.d.ts
2
+ type UseAsyncEffect = {
3
+ (effect: (isMounted: () => boolean) => unknown | Promise<unknown>, inputs?: any[]): void;
4
+ <T>(effect: (isMounted: () => boolean) => T | Promise<T>, destroy?: (result?: T) => void, inputs?: any[]): void;
5
+ };
6
+ declare const useAsyncEffect: UseAsyncEffect;
7
+ //#endregion
8
+ export { useAsyncEffect };
@@ -0,0 +1,20 @@
1
+ import { useEffect } from "react";
2
+ //#region src/nextJs/client/useAsyncEffect.ts
3
+ const useAsyncEffect = (effect, destroyOrInputs, inputs) => {
4
+ const hasDestroy = "function" === typeof destroyOrInputs;
5
+ const destroy = hasDestroy ? destroyOrInputs : void 0;
6
+ useEffect(() => {
7
+ let result;
8
+ let mounted = true;
9
+ const maybePromise = effect(() => mounted);
10
+ Promise.resolve(maybePromise).then((value) => {
11
+ result = value;
12
+ });
13
+ return () => {
14
+ mounted = false;
15
+ if (hasDestroy && destroy) destroy(result);
16
+ };
17
+ }, hasDestroy ? inputs : destroyOrInputs);
18
+ };
19
+ //#endregion
20
+ export { useAsyncEffect };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "2.4.11",
4
+ "version": "2.4.13",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
@@ -876,21 +876,13 @@
876
876
  "import": "./dist/nextAuth/nextAuth.mjs",
877
877
  "require": "./dist/nextAuth/nextAuth.cjs"
878
878
  },
879
- "./nextJs": {
880
- "import": "./dist/nextJs/index.mjs",
881
- "require": "./dist/nextJs/index.cjs"
882
- },
883
879
  "./nextJs/client": {
884
880
  "import": "./dist/nextJs/client/index.mjs",
885
881
  "require": "./dist/nextJs/client/index.cjs"
886
882
  },
887
- "./nextJs/nextJs": {
888
- "import": "./dist/nextJs/nextJs.mjs",
889
- "require": "./dist/nextJs/nextJs.cjs"
890
- },
891
- "./nextJs/tests/getIp": {
892
- "import": "./dist/nextJs/tests/getIp.mjs",
893
- "require": "./dist/nextJs/tests/getIp.cjs"
883
+ "./nextJs/client/useAsyncEffect": {
884
+ "import": "./dist/nextJs/client/useAsyncEffect.mjs",
885
+ "require": "./dist/nextJs/client/useAsyncEffect.cjs"
894
886
  },
895
887
  "./number": {
896
888
  "import": "./dist/number/index.mjs",
@@ -1,4 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_nextJs_nextJs = require("./nextJs.cjs");
3
- exports.getIp = require_nextJs_nextJs.getIp;
4
- exports.getUserAgent = require_nextJs_nextJs.getUserAgent;
@@ -1,2 +0,0 @@
1
- import { getIp, getUserAgent } from "./nextJs.cjs";
2
- export { getIp, getUserAgent };
@@ -1,2 +0,0 @@
1
- import { getIp, getUserAgent } from "./nextJs.mjs";
2
- export { getIp, getUserAgent };
@@ -1,2 +0,0 @@
1
- import { getIp, getUserAgent } from "./nextJs.mjs";
2
- export { getIp, getUserAgent };
@@ -1,13 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region src/nextJs/nextJs.ts
3
- /**
4
- * Get the user's remote IP Address
5
- */
6
- const getIp = ({ req }) => String(req.headers?.["x-real-ip"] || "unset");
7
- /**
8
- * Get the user's User Agent
9
- */
10
- const getUserAgent = ({ req }) => String(req.headers["user-agent"] || "unset");
11
- //#endregion
12
- exports.getIp = getIp;
13
- exports.getUserAgent = getUserAgent;
@@ -1,19 +0,0 @@
1
- //#region src/nextJs/nextJs.d.ts
2
- /**
3
- * Get the user's remote IP Address
4
- */
5
- declare const getIp: ({
6
- req
7
- }: {
8
- req: any;
9
- }) => string;
10
- /**
11
- * Get the user's User Agent
12
- */
13
- declare const getUserAgent: ({
14
- req
15
- }: {
16
- req: any;
17
- }) => string;
18
- //#endregion
19
- export { getIp, getUserAgent };
@@ -1,19 +0,0 @@
1
- //#region src/nextJs/nextJs.d.ts
2
- /**
3
- * Get the user's remote IP Address
4
- */
5
- declare const getIp: ({
6
- req
7
- }: {
8
- req: any;
9
- }) => string;
10
- /**
11
- * Get the user's User Agent
12
- */
13
- declare const getUserAgent: ({
14
- req
15
- }: {
16
- req: any;
17
- }) => string;
18
- //#endregion
19
- export { getIp, getUserAgent };
@@ -1,11 +0,0 @@
1
- //#region src/nextJs/nextJs.ts
2
- /**
3
- * Get the user's remote IP Address
4
- */
5
- const getIp = ({ req }) => String(req.headers?.["x-real-ip"] || "unset");
6
- /**
7
- * Get the user's User Agent
8
- */
9
- const getUserAgent = ({ req }) => String(req.headers["user-agent"] || "unset");
10
- //#endregion
11
- export { getIp, getUserAgent };
@@ -1,9 +0,0 @@
1
- const require_nextJs_nextJs = require("../nextJs.cjs");
2
- //#region src/nextJs/tests/getIp.ts
3
- test("getIp - Exists", () => {
4
- expect(require_nextJs_nextJs.getIp({ req: { headers: { "x-real-ip": "value" } } })).toBe("value");
5
- });
6
- test("getIp - Undefined", () => {
7
- expect(require_nextJs_nextJs.getIp({ req: { headers: {} } })).toBe("unset");
8
- });
9
- //#endregion
@@ -1 +0,0 @@
1
- export { };
@@ -1 +0,0 @@
1
- export { };
@@ -1,10 +0,0 @@
1
- import { getIp } from "../nextJs.mjs";
2
- //#region src/nextJs/tests/getIp.ts
3
- test("getIp - Exists", () => {
4
- expect(getIp({ req: { headers: { "x-real-ip": "value" } } })).toBe("value");
5
- });
6
- test("getIp - Undefined", () => {
7
- expect(getIp({ req: { headers: {} } })).toBe("unset");
8
- });
9
- //#endregion
10
- export {};