@zimic/ws 0.1.0-canary.6 → 0.1.1-canary.0

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.
Files changed (2) hide show
  1. package/dist/index.d.ts +24 -2
  2. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -68,15 +68,37 @@ declare namespace JSONValue {
68
68
  /** A loose version of the JSON value type. JSON objects are not strictly typed. */
69
69
  type Loose<Type extends JSON.Loose = JSON.Loose> = Type;
70
70
  }
71
+ /**
72
+ * Recursively converts a type to its JSON-serialized version. Dates are converted to strings and keys with non-JSON
73
+ * values are excluded.
74
+ *
75
+ * @example
76
+ * import { type JSONSerialized } from '@zimic/http';
77
+ *
78
+ * type SerializedUser = JSONSerialized<{
79
+ * id: string;
80
+ * email: string;
81
+ * createdAt: Date;
82
+ * save: () => Promise<void>;
83
+ * }>;
84
+ * // {
85
+ * // id: string;
86
+ * // email: string;
87
+ * // createdAt: string;
88
+ * // }
89
+ */
90
+ type JSONSerialized<Type> = Type extends JSONValue ? Type : Type extends Date ? string : Type extends (...parameters: never[]) => unknown ? never : Type extends symbol ? never : Type extends Map<infer _Key, infer _Value> ? Record<string, never> : Type extends Set<infer _Value> ? Record<string, never> : Type extends (infer ArrayItem)[] ? JSONSerialized<ArrayItem>[] : Type extends object ? {
91
+ [Key in keyof Type as [JSONSerialized<Type[Key]>] extends [never] ? never : Key]: JSONSerialized<Type[Key]>;
92
+ } : never;
71
93
  declare global {
72
94
  interface JSON {
73
95
  readonly value: unique symbol;
74
96
  stringify<Value>(value: Value, replacer?: ((this: any, key: string, value: Value) => any) | (number | string)[] | null, space?: string | number): JSONStringified$1<Value>;
75
- parse<Value>(text: JSONStringified$1<Value>, reviver?: (this: any, key: string, value: any) => any): Value;
97
+ parse<Value>(text: JSONStringified$1<Value>, reviver?: (this: any, key: string, value: any) => any): JSONSerialized<Value>;
76
98
  }
77
99
  }
78
100
  type JSONStringified$1<Value> = string & {
79
- [JSON.value]: Value;
101
+ [JSON.value]: JSONSerialized<Value>;
80
102
  };
81
103
 
82
104
  /**
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "api",
15
15
  "static"
16
16
  ],
17
- "version": "0.1.0-canary.6",
17
+ "version": "0.1.1-canary.0",
18
18
  "homepage": "https://zimic.dev/docs/ws",
19
19
  "repository": {
20
20
  "type": "git",