@mittwald/react-ghostmaker 1.5.2 → 1.5.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.
@@ -40,3 +40,10 @@ test("asGhost() works with generics", () => {
40
40
  asGhost(prop).foo().use();
41
41
  }
42
42
  });
43
+ test("calling function on optional props works", () => {
44
+ const customerNameGhost = ProjectGhost.ofId("Project A")
45
+ .getDetailed()
46
+ .optionalCustomer?.getDetailed()
47
+ .getName();
48
+ expectTypeOf(customerNameGhost).toEqualTypeOf();
49
+ });
@@ -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) {
@@ -186,6 +186,7 @@ let ProjectDetailed = (() => {
186
186
  id;
187
187
  name;
188
188
  customer;
189
+ optionalCustomer;
189
190
  constructor(id, name, customerId) {
190
191
  this.id = id;
191
192
  this.name = name;
@@ -37,6 +37,7 @@ export declare class ProjectDetailed {
37
37
  readonly id: string;
38
38
  readonly name: string;
39
39
  readonly customer: Customer;
40
+ readonly optionalCustomer?: Customer;
40
41
  constructor(id: string, name: string, customerId: string);
41
42
  getName(): string;
42
43
  getStatus(): Promise<string>;
@@ -22,7 +22,7 @@ export declare const transformFnProp: "___transformFn";
22
22
  export declare const isGhostMarker: "___ghostMarker";
23
23
  type GhostProp<V, TOriginal> = V extends AnyFunction ? (...args: Parameters<V>) => ReactGhost<Awaited<ReturnType<V>> | OrOptional<TOriginal>> : ReactGhost<V | OrOptional<TOriginal>>;
24
24
  export type ReactGhost<T> = ReactGhostMethods<T> & {
25
- [K in keyof NonNullable<T>]-?: GhostProp<NonNullable<T>[K], T>;
25
+ [K in keyof NonNullable<T>]-?: Exclude<GhostProp<NonNullable<T>[K], T>, ReactGhost<undefined>>;
26
26
  };
27
27
  export interface GhostChainItem {
28
28
  propName: string | typeof transformFnProp;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mittwald/react-ghostmaker",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
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",