@mittwald/react-ghostmaker 1.5.1 → 1.5.3

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.
@@ -1,5 +1,6 @@
1
1
  import { expectTypeOf, test } from "vitest";
2
2
  import { ProjectGhost } from "./testMocks.js";
3
+ import { asGhost } from "./maybeGhost/asGhost.js";
3
4
  test("return type is correct", () => {
4
5
  const customerNameGhost = ProjectGhost.ofId("Project A")
5
6
  .getDetailed()
@@ -23,3 +24,19 @@ test("transform return type is correct", () => {
23
24
  .name.transform(() => 0);
24
25
  expectTypeOf(transformedToNumber).toEqualTypeOf();
25
26
  });
27
+ test("asGhost() works with generics", () => {
28
+ class A {
29
+ foo() {
30
+ //
31
+ }
32
+ }
33
+ class B {
34
+ foo() {
35
+ //
36
+ }
37
+ }
38
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
39
+ function generic(prop) {
40
+ asGhost(prop).foo().use();
41
+ }
42
+ });
@@ -1,8 +1,15 @@
1
1
  import is from "@sindresorhus/is";
2
2
  const store = new Map();
3
+ const isDev = typeof process !== "undefined" && process.env.NODE_ENV !== "production";
3
4
  const testNameConflict = (name) => {
4
5
  if (Array.from(store.values()).some((meta) => meta.name === name)) {
5
- throw new Error(`GhostMakerModel name conflict: A model with the name "${name}" is already registered.`);
6
+ const message = `GhostMakerModel name conflict: A model with the name "${name}" is already registered.`;
7
+ if (isDev) {
8
+ console.warn(message);
9
+ }
10
+ else {
11
+ throw new Error(message);
12
+ }
6
13
  }
7
14
  };
8
15
  export function GhostMakerModel(options) {
@@ -20,8 +20,9 @@ export interface ReactGhostMethods<T> extends Promise<T> {
20
20
  }
21
21
  export declare const transformFnProp: "___transformFn";
22
22
  export declare const isGhostMarker: "___ghostMarker";
23
+ type GhostProp<V, TOriginal> = V extends AnyFunction ? (...args: Parameters<V>) => ReactGhost<Awaited<ReturnType<V>> | OrOptional<TOriginal>> : ReactGhost<V | OrOptional<TOriginal>>;
23
24
  export type ReactGhost<T> = ReactGhostMethods<T> & {
24
- [K in keyof NonNullable<T>]-?: NonNullable<T>[K] extends AnyFunction ? <TParams extends Parameters<NonNullable<T>[K]>>(...args: TParams) => ReactGhost<Awaited<ReturnType<NonNullable<T>[K]>> | OrOptional<T>> : ReactGhost<NonNullable<T>[K] | OrOptional<T>>;
25
+ [K in keyof NonNullable<T>]-?: GhostProp<NonNullable<T>[K], T>;
25
26
  };
26
27
  export interface GhostChainItem {
27
28
  propName: string | typeof transformFnProp;
@@ -42,3 +43,4 @@ export interface UseGhostReturn<T> {
42
43
  }
43
44
  export declare function isReactGhost<T>(something: unknown): something is ReactGhost<T>;
44
45
  export type ModelIdentifier = (model: unknown) => string | undefined;
46
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mittwald/react-ghostmaker",
3
- "version": "1.5.1",
3
+ "version": "1.5.3",
4
4
  "author": "Mittwald CM Service GmbH & Co. KG <opensource@mittwald.de>",
5
5
  "contributors": [
6
6
  "Marco Falkenberg <m.falkenberg@mittwald.de>"
@@ -49,6 +49,7 @@
49
49
  "@tanstack/react-query": "^5.90.20",
50
50
  "@testing-library/dom": "^10.4.1",
51
51
  "@testing-library/react": "^16.3.2",
52
+ "@types/node": "^24.10.12",
52
53
  "@types/react": "^19.2.13",
53
54
  "@types/react-dom": "^19.2.3",
54
55
  "@typescript-eslint/eslint-plugin": "^8.54.0",