@drunkcod/argis 0.0.18 → 0.0.20
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.
- package/lib/Json.d.ts +6 -12
- package/lib/cjs/Json.d.ts +6 -12
- package/package.json +1 -1
package/lib/Json.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyFn, IfOptional, Pretty, Tagged, TagCycle, TagCycles } from './TypeUtils.js';
|
|
1
|
+
import { AnyFn, IfOptional, Pretty, Tagged, TagCycle, TagCycles, IsAny } from './TypeUtils.js';
|
|
2
2
|
export interface Jsonable<Json> {
|
|
3
3
|
toJSON(): Json;
|
|
4
4
|
}
|
|
@@ -9,19 +9,13 @@ export type JsonError<T, Data = {}> = Tagged<typeof JsonError, T, Data>;
|
|
|
9
9
|
export type JsonCycleError<T> = JsonError<'cycle-detected', {
|
|
10
10
|
data: T;
|
|
11
11
|
}>;
|
|
12
|
-
type JsonProperty<T, P extends keyof T
|
|
13
|
-
type
|
|
14
|
-
|
|
15
|
-
required: Exclude<K, Optional>;
|
|
16
|
-
optional: Optional;
|
|
17
|
-
};
|
|
18
|
-
type JsonObject<T> = _JsonObject<T, Keys<T, JsonProperty<T>>>;
|
|
19
|
-
type _JsonObject<T, K extends Keys<T, any>> = {
|
|
20
|
-
[P in K['required']]: Pretty<_Json<T[P]>>;
|
|
12
|
+
type JsonProperty<T, P extends keyof T> = P extends string | number ? (_Json<T[P]> extends never ? never : P) : never;
|
|
13
|
+
type JsonObject<T> = {
|
|
14
|
+
[P in keyof T as IfOptional<T, P, never, JsonProperty<T, P>>]: Pretty<_Json<T[P]>>;
|
|
21
15
|
} & {
|
|
22
|
-
[P in
|
|
16
|
+
[P in keyof T as IfOptional<T, P, JsonProperty<T, P>, never>]?: Pretty<_Json<T[P]>>;
|
|
23
17
|
};
|
|
24
|
-
type _Json<T, IsRoot = true> = T extends TagCycle<infer X> ? (X extends Jsonable<infer J> ? Json<J, false> : JsonCycleError<X>) : T extends Jsonable<infer J> ? (IsRoot extends true ? Json<J, false> : _Json<Omit<T, 'toJSON'>>) : T extends NeverJson ? never : T extends EmptyJson ? Record<string, never> : T extends bigint ? JsonError<'bigint-not-serializeable'> : T extends readonly any[] ? {
|
|
18
|
+
type _Json<T, IsRoot = true> = IsAny<T> extends true ? any : T extends TagCycle<infer X> ? (X extends Jsonable<infer J> ? Json<J, false> : JsonCycleError<X>) : T extends Jsonable<infer J> ? (IsRoot extends true ? Json<J, false> : _Json<Omit<T, 'toJSON'>>) : T extends NeverJson ? never : T extends EmptyJson ? Record<string, never> : T extends bigint ? JsonError<'bigint-not-serializeable'> : T extends readonly any[] ? {
|
|
25
19
|
[I in keyof T]: [_Json<T[I]>] extends [never] ? null : Pretty<_Json<T[I]>>;
|
|
26
20
|
} : T extends object ? JsonObject<T> : T;
|
|
27
21
|
export type Json<T, IsRoot = true> = Pretty<_Json<TagCycles<T>, IsRoot>>;
|
package/lib/cjs/Json.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyFn, IfOptional, Pretty, Tagged, TagCycle, TagCycles } from './TypeUtils.js';
|
|
1
|
+
import { AnyFn, IfOptional, Pretty, Tagged, TagCycle, TagCycles, IsAny } from './TypeUtils.js';
|
|
2
2
|
export interface Jsonable<Json> {
|
|
3
3
|
toJSON(): Json;
|
|
4
4
|
}
|
|
@@ -9,19 +9,13 @@ export type JsonError<T, Data = {}> = Tagged<typeof JsonError, T, Data>;
|
|
|
9
9
|
export type JsonCycleError<T> = JsonError<'cycle-detected', {
|
|
10
10
|
data: T;
|
|
11
11
|
}>;
|
|
12
|
-
type JsonProperty<T, P extends keyof T
|
|
13
|
-
type
|
|
14
|
-
|
|
15
|
-
required: Exclude<K, Optional>;
|
|
16
|
-
optional: Optional;
|
|
17
|
-
};
|
|
18
|
-
type JsonObject<T> = _JsonObject<T, Keys<T, JsonProperty<T>>>;
|
|
19
|
-
type _JsonObject<T, K extends Keys<T, any>> = {
|
|
20
|
-
[P in K['required']]: Pretty<_Json<T[P]>>;
|
|
12
|
+
type JsonProperty<T, P extends keyof T> = P extends string | number ? (_Json<T[P]> extends never ? never : P) : never;
|
|
13
|
+
type JsonObject<T> = {
|
|
14
|
+
[P in keyof T as IfOptional<T, P, never, JsonProperty<T, P>>]: Pretty<_Json<T[P]>>;
|
|
21
15
|
} & {
|
|
22
|
-
[P in
|
|
16
|
+
[P in keyof T as IfOptional<T, P, JsonProperty<T, P>, never>]?: Pretty<_Json<T[P]>>;
|
|
23
17
|
};
|
|
24
|
-
type _Json<T, IsRoot = true> = T extends TagCycle<infer X> ? (X extends Jsonable<infer J> ? Json<J, false> : JsonCycleError<X>) : T extends Jsonable<infer J> ? (IsRoot extends true ? Json<J, false> : _Json<Omit<T, 'toJSON'>>) : T extends NeverJson ? never : T extends EmptyJson ? Record<string, never> : T extends bigint ? JsonError<'bigint-not-serializeable'> : T extends readonly any[] ? {
|
|
18
|
+
type _Json<T, IsRoot = true> = IsAny<T> extends true ? any : T extends TagCycle<infer X> ? (X extends Jsonable<infer J> ? Json<J, false> : JsonCycleError<X>) : T extends Jsonable<infer J> ? (IsRoot extends true ? Json<J, false> : _Json<Omit<T, 'toJSON'>>) : T extends NeverJson ? never : T extends EmptyJson ? Record<string, never> : T extends bigint ? JsonError<'bigint-not-serializeable'> : T extends readonly any[] ? {
|
|
25
19
|
[I in keyof T]: [_Json<T[I]>] extends [never] ? null : Pretty<_Json<T[I]>>;
|
|
26
20
|
} : T extends object ? JsonObject<T> : T;
|
|
27
21
|
export type Json<T, IsRoot = true> = Pretty<_Json<TagCycles<T>, IsRoot>>;
|
package/package.json
CHANGED