trpc-msw 4.13.0 → 4.14.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.
- package/dist/createTRPCMsw.d.ts +1 -1
- package/dist/createTRPCMsw.js +4 -3
- package/dist/models/MswWebSocketAdapter.d.ts +1 -1
- package/dist/models/MswWebSocketAdapter.js +1 -1
- package/dist/models/ProcedureResolver.d.ts +1 -1
- package/dist/models/SubscriptionRegistration.d.ts +1 -1
- package/dist/models/TRPCMswOptions.d.ts +9 -2
- package/dist/vendor/pnpm/tagged-tag@1.0.0/vendor/tagged-tag/index.d.ts +2 -0
- package/dist/vendor/pnpm/type-fest@6.0.3/vendor/type-fest/source/apply-default-options.d.ts +61 -0
- package/dist/vendor/pnpm/type-fest@6.0.3/vendor/type-fest/source/collapse-literals.d.ts +38 -0
- package/dist/vendor/pnpm/type-fest@6.0.3/vendor/type-fest/source/except.d.ts +105 -0
- package/dist/vendor/pnpm/type-fest@6.0.3/vendor/type-fest/source/if.d.ts +94 -0
- package/dist/vendor/pnpm/type-fest@6.0.3/vendor/type-fest/source/internal/object.d.ts +41 -0
- package/dist/vendor/pnpm/type-fest@6.0.3/vendor/type-fest/source/internal/string.d.ts +8 -0
- package/dist/vendor/pnpm/type-fest@6.0.3/vendor/type-fest/source/internal/type.d.ts +60 -0
- package/dist/vendor/pnpm/type-fest@6.0.3/vendor/type-fest/source/is-any.d.ts +31 -0
- package/dist/vendor/pnpm/type-fest@6.0.3/vendor/type-fest/source/is-never.d.ts +54 -0
- package/dist/vendor/pnpm/type-fest@6.0.3/vendor/type-fest/source/keys-of-union.d.ts +44 -0
- package/dist/vendor/pnpm/type-fest@6.0.3/vendor/type-fest/source/matching-key.d.ts +38 -0
- package/dist/vendor/pnpm/type-fest@6.0.3/vendor/type-fest/source/merge.d.ts +11 -0
- package/dist/vendor/pnpm/type-fest@6.0.3/vendor/type-fest/source/numeric.d.ts +24 -0
- package/dist/vendor/pnpm/type-fest@6.0.3/vendor/type-fest/source/omit-index-signature.d.ts +92 -0
- package/dist/vendor/pnpm/type-fest@6.0.3/vendor/type-fest/source/pick-index-signature.d.ts +46 -0
- package/dist/vendor/pnpm/type-fest@6.0.3/vendor/type-fest/source/primitive.d.ts +6 -0
- package/dist/vendor/pnpm/type-fest@6.0.3/vendor/type-fest/source/require-none.d.ts +43 -0
- package/dist/vendor/pnpm/type-fest@6.0.3/vendor/type-fest/source/required-keys-of.d.ts +37 -0
- package/dist/vendor/pnpm/type-fest@6.0.3/vendor/type-fest/source/string-to-number.d.ts +57 -0
- package/dist/vendor/pnpm/type-fest@6.0.3/vendor/type-fest/source/tagged.d.ts +95 -0
- package/dist/vendor/pnpm/type-fest@6.0.3/vendor/type-fest/source/union-member.d.ts +58 -0
- package/dist/vendor/pnpm/type-fest@6.0.3/vendor/type-fest/source/unknown-array.d.ts +25 -0
- package/dist/vendor/pnpm/type-fest@6.0.3/vendor/type-fest/source/unwrap-branded-primitive.d.ts +63 -0
- package/package.json +8 -7
- /package/dist/vendor/pnpm/{type-fest@6.0.2 → type-fest@6.0.3}/vendor/type-fest/source/promisable.d.ts +0 -0
- /package/dist/{packages → work/Esposter/Esposter/packages}/trpc-nuxt-module/dist/runtime/server/models/WebSocketClientAdapter.d.ts +0 -0
- /package/dist/{packages → work/Esposter/Esposter/packages}/trpc-nuxt-module/dist/runtime/server/models/WebSocketClientAdapter.js +0 -0
- /package/dist/{packages → work/Esposter/Esposter/packages}/trpc-nuxt-module/dist/runtime/server/models/WebSocketServerAdapter.js +0 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { KeyToString } from "./internal/string.js";
|
|
2
|
+
/**
|
|
3
|
+
Resolve a property key to the matching key type in an object, converting between numeric and string forms when needed.
|
|
4
|
+
|
|
5
|
+
Useful when composing generic property access utilities that accept either `0` or `'0'` for the same property. Returns `never` if no key matches.
|
|
6
|
+
|
|
7
|
+
Keys assignable to `keyof ObjectType` are returned unchanged, including keys covered by index signatures. Otherwise, numeric keys are tried as strings, and numeric strings as numbers only if converting back preserves their spelling. For example, `'01'` does not match `1`.
|
|
8
|
+
|
|
9
|
+
Distributes over a union of keys. For a union of objects, only keys in `keyof ObjectType` are considered, so a key must be common to all members. Plain strings do not select string enum keys. Array and tuple indices are not bounds-checked.
|
|
10
|
+
|
|
11
|
+
@example
|
|
12
|
+
```
|
|
13
|
+
import type {MatchingKey} from 'type-fest';
|
|
14
|
+
|
|
15
|
+
type StatusMessages = {
|
|
16
|
+
200: 'OK';
|
|
17
|
+
'404': 'Not found';
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type SuccessKey = MatchingKey<StatusMessages, '200'>;
|
|
21
|
+
//=> 200
|
|
22
|
+
|
|
23
|
+
type NotFoundKey = MatchingKey<StatusMessages, 404>;
|
|
24
|
+
//=> '404'
|
|
25
|
+
|
|
26
|
+
type PickByKey<ObjectType extends object, Key extends PropertyKey> = Pick<ObjectType, MatchingKey<ObjectType, Key>>;
|
|
27
|
+
|
|
28
|
+
type Success = PickByKey<StatusMessages, '200'>;
|
|
29
|
+
//=> {200: 'OK'}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
@see {@link PropertyValue} to get the value of the matching property.
|
|
33
|
+
|
|
34
|
+
@category Object
|
|
35
|
+
*/
|
|
36
|
+
export type MatchingKey<ObjectType extends object, Key extends PropertyKey> = Key extends keyof ObjectType ? Key : KeyToString<Key> extends keyof ObjectType ? KeyToString<Key> : Key extends `${infer NumberKey extends number}` ?
|
|
37
|
+
// A numeric-looking string names a number key only when its spelling survives the conversion.
|
|
38
|
+
`${NumberKey}` extends Key ? NumberKey extends keyof ObjectType ? NumberKey : never : never : never;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CallSignatureOf } from "./internal/type.js";
|
|
2
|
+
import { KeyAliases, SimplifyObject } from "./internal/object.js";
|
|
3
|
+
import { OmitIndexSignature } from "./omit-index-signature.js";
|
|
4
|
+
import { PickIndexSignature } from "./pick-index-signature.js";
|
|
5
|
+
export type _Merge<Destination, Source> =
|
|
6
|
+
// The mapped types in `MergeObjects` drop call signatures, so the source's call signature, or else the destination's, is added back. Each branch has its own intersection, so that tooltips show the result rather than `_Merge`.
|
|
7
|
+
unknown extends CallSignatureOf<Source> ? CallSignatureOf<Destination> & MergeObjects<Destination, Source> : CallSignatureOf<Source> & MergeObjects<Destination, Source>;
|
|
8
|
+
// Numeric properties, enum keys, and their string forms name the same property, so normalize the source's named keys before testing overrides.
|
|
9
|
+
// Merges the properties and index signatures of two objects. A key of the destination is dropped when the source overrides it: an index signature only by an index signature, and a property only by a property. The destination is read only once, because each extra read multiplies the work of nested merges, such as in `MergeAll`. The source is rebuilt with key remapping instead of intersected as is, because an intersection with an `any` source is `any`, which loses the properties of the destination.
|
|
10
|
+
type MergeObjects<Destination, Source> = SimplifyObject<{ [Key in keyof Destination as {} extends Record<Key, never> ? Key extends keyof PickIndexSignature<Source> ? never : Key : Key extends KeyAliases<keyof OmitIndexSignature<Source>> ? never : Key]: Destination[Key]; } & { [Key in keyof Source as Key]: Source[Key]; }>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Matches the hidden `Infinity` type.
|
|
3
|
+
|
|
4
|
+
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277) if you want to have this type as a built-in in TypeScript.
|
|
5
|
+
|
|
6
|
+
@see {@link NegativeInfinity}
|
|
7
|
+
|
|
8
|
+
@category Numeric
|
|
9
|
+
*/
|
|
10
|
+
// See https://github.com/microsoft/TypeScript/issues/31752
|
|
11
|
+
// eslint-disable-next-line no-loss-of-precision
|
|
12
|
+
export type PositiveInfinity = 1e999;
|
|
13
|
+
/**
|
|
14
|
+
Matches the hidden `-Infinity` type.
|
|
15
|
+
|
|
16
|
+
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277) if you want to have this type as a built-in in TypeScript.
|
|
17
|
+
|
|
18
|
+
@see {@link PositiveInfinity}
|
|
19
|
+
|
|
20
|
+
@category Numeric
|
|
21
|
+
*/
|
|
22
|
+
// See https://github.com/microsoft/TypeScript/issues/31752
|
|
23
|
+
// eslint-disable-next-line no-loss-of-precision
|
|
24
|
+
export type NegativeInfinity = -1e999;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
3
|
+
|
|
4
|
+
This is the counterpart of `PickIndexSignature`.
|
|
5
|
+
|
|
6
|
+
Use-cases:
|
|
7
|
+
- Remove overly permissive signatures from third-party types.
|
|
8
|
+
|
|
9
|
+
This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
10
|
+
|
|
11
|
+
It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, never>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', never>`.
|
|
12
|
+
|
|
13
|
+
The `never` value type prevents inherited `Object.prototype` members, such as `toString`, from satisfying an explicitly defined key.
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
const indexed: Record<string, never> = {}; // Allowed
|
|
17
|
+
|
|
18
|
+
// @ts-expect-error
|
|
19
|
+
const keyed: Record<'foo' | 'bar', never> = {}; // Error
|
|
20
|
+
// TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", never>': foo, bar
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
type Indexed = {} extends Record<string, never>
|
|
27
|
+
? '✅ `{}` is assignable to `Record<string, never>`'
|
|
28
|
+
: '❌ `{}` is NOT assignable to `Record<string, never>`';
|
|
29
|
+
|
|
30
|
+
type IndexedResult = Indexed;
|
|
31
|
+
//=> '✅ `{}` is assignable to `Record<string, never>`'
|
|
32
|
+
|
|
33
|
+
type Keyed = {} extends Record<'foo' | 'bar', never>
|
|
34
|
+
? '✅ `{}` is assignable to `Record<\'foo\' | \'bar\', never>`'
|
|
35
|
+
: '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', never>`';
|
|
36
|
+
|
|
37
|
+
type KeyedResult = Keyed;
|
|
38
|
+
//=> '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', never>`'
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
type OmitIndexSignature<ObjectType> = {
|
|
45
|
+
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
46
|
+
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
|
47
|
+
};
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, never>`)...
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
type OmitIndexSignature<ObjectType> = {
|
|
54
|
+
[KeyType in keyof ObjectType
|
|
55
|
+
// Is `{}` assignable to `Record<KeyType, never>`?
|
|
56
|
+
as {} extends Record<KeyType, never>
|
|
57
|
+
? never // ✅ `{}` is assignable to `Record<KeyType, never>`
|
|
58
|
+
: KeyType // ❌ `{}` is NOT assignable to `Record<KeyType, never>`
|
|
59
|
+
]: ObjectType[KeyType];
|
|
60
|
+
};
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
|
|
64
|
+
|
|
65
|
+
@example
|
|
66
|
+
```
|
|
67
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
68
|
+
|
|
69
|
+
type Example = {
|
|
70
|
+
// These index signatures will be removed.
|
|
71
|
+
[x: string]: any;
|
|
72
|
+
[x: number]: any;
|
|
73
|
+
[x: symbol]: any;
|
|
74
|
+
[x: `head-${string}`]: string;
|
|
75
|
+
[x: `${string}-tail`]: string;
|
|
76
|
+
[x: `head-${string}-tail`]: string;
|
|
77
|
+
[x: `${bigint}`]: string;
|
|
78
|
+
[x: `embedded-${number}`]: string;
|
|
79
|
+
|
|
80
|
+
// These explicitly defined keys will remain.
|
|
81
|
+
foo: 'bar';
|
|
82
|
+
qux?: 'baz';
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
86
|
+
//=> {foo: 'bar'; qux?: 'baz'}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
@see {@link PickIndexSignature}
|
|
90
|
+
@category Object
|
|
91
|
+
*/
|
|
92
|
+
export type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, never> ? never : KeyType]: ObjectType[KeyType]; };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
3
|
+
|
|
4
|
+
This is the counterpart of `OmitIndexSignature`.
|
|
5
|
+
|
|
6
|
+
@example
|
|
7
|
+
```
|
|
8
|
+
import type {PickIndexSignature} from 'type-fest';
|
|
9
|
+
|
|
10
|
+
declare const symbolKey: unique symbol;
|
|
11
|
+
|
|
12
|
+
type Example = {
|
|
13
|
+
// These index signatures will remain.
|
|
14
|
+
[x: string]: unknown;
|
|
15
|
+
[x: number]: unknown;
|
|
16
|
+
[x: symbol]: unknown;
|
|
17
|
+
[x: `head-${string}`]: string;
|
|
18
|
+
[x: `${string}-tail`]: string;
|
|
19
|
+
[x: `head-${string}-tail`]: string;
|
|
20
|
+
[x: `${bigint}`]: string;
|
|
21
|
+
[x: `embedded-${number}`]: string;
|
|
22
|
+
|
|
23
|
+
// These explicitly defined keys will be removed.
|
|
24
|
+
['kebab-case-key']: string;
|
|
25
|
+
[symbolKey]: string;
|
|
26
|
+
foo: 'bar';
|
|
27
|
+
qux?: 'baz';
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
31
|
+
// {
|
|
32
|
+
// [x: string]: unknown;
|
|
33
|
+
// [x: number]: unknown;
|
|
34
|
+
// [x: symbol]: unknown;
|
|
35
|
+
// [x: `head-${string}`]: string;
|
|
36
|
+
// [x: `${string}-tail`]: string;
|
|
37
|
+
// [x: `head-${string}-tail`]: string;
|
|
38
|
+
// [x: `${bigint}`]: string;
|
|
39
|
+
// [x: `embedded-${number}`]: string;
|
|
40
|
+
// }
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
@see {@link OmitIndexSignature}
|
|
44
|
+
@category Object
|
|
45
|
+
*/
|
|
46
|
+
export type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, never> ? KeyType : never]: ObjectType[KeyType]; };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Create an object type that forbids the given keys, to intersect with another object type.
|
|
3
|
+
|
|
4
|
+
Use it to reject removed options, or to forbid keys on a generic object type, which {@link Except} cannot do because it only accepts keys of the object type. This does not remove properties from the other type.
|
|
5
|
+
|
|
6
|
+
Uses optional `never` properties. With `exactOptionalPropertyTypes` enabled, named keys cannot be supplied, even as `undefined`.
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import type {RequireNone} from 'type-fest';
|
|
11
|
+
|
|
12
|
+
type DeprecatedOptions = RequireNone<'legacyMode' | 'callback'>;
|
|
13
|
+
//=> {legacyMode?: never; callback?: never}
|
|
14
|
+
|
|
15
|
+
type Options = {url: string} & DeprecatedOptions;
|
|
16
|
+
|
|
17
|
+
const options: Options = {url: 'https://example.com'};
|
|
18
|
+
|
|
19
|
+
// @ts-expect-error
|
|
20
|
+
const deprecated: Options = {url: 'https://example.com', legacyMode: true};
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
@example
|
|
24
|
+
```
|
|
25
|
+
import type {RequireNone} from 'type-fest';
|
|
26
|
+
|
|
27
|
+
// The database creates the `id`, so a new row must not have one.
|
|
28
|
+
declare function insert<Row extends object>(row: Row & RequireNone<'id'>): void;
|
|
29
|
+
|
|
30
|
+
insert({name: 'Alice'});
|
|
31
|
+
|
|
32
|
+
// @ts-expect-error
|
|
33
|
+
insert({id: 1, name: 'Alice'});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Note: `RequireNone<never>` produces `{}`, which does not enforce an empty object. Broad keys (`string`, `number`, `symbol`, or template literal patterns) produce index signatures that allow `undefined` values. Properties absent from a value's static type cannot be checked.
|
|
37
|
+
|
|
38
|
+
@see {@link Except} with `{requireExactProps: true}` to remove keys from an object type and forbid them.
|
|
39
|
+
@see {@link MergeExclusive} or {@link ExclusifyUnion} to make object types mutually exclusive.
|
|
40
|
+
|
|
41
|
+
@category Object
|
|
42
|
+
*/
|
|
43
|
+
export type RequireNone<KeysType extends PropertyKey> = { [Key in KeysType]?: never; };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { IsAny } from "./is-any.js";
|
|
2
|
+
/**
|
|
3
|
+
Extract all required keys from the given type.
|
|
4
|
+
|
|
5
|
+
This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
|
|
6
|
+
|
|
7
|
+
@example
|
|
8
|
+
```
|
|
9
|
+
import type {RequiredKeysOf} from 'type-fest';
|
|
10
|
+
|
|
11
|
+
declare function createValidation<
|
|
12
|
+
Entity extends object,
|
|
13
|
+
Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>,
|
|
14
|
+
>(field: Key, validator: (value: Entity[Key]) => boolean): (entity: Entity) => boolean;
|
|
15
|
+
|
|
16
|
+
type User = {
|
|
17
|
+
name: string;
|
|
18
|
+
surname: string;
|
|
19
|
+
luckyNumber?: number;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
23
|
+
const validator2 = createValidation<User>('surname', value => value.length < 25);
|
|
24
|
+
|
|
25
|
+
// @ts-expect-error
|
|
26
|
+
const validator3 = createValidation<User>('luckyNumber', value => value > 0);
|
|
27
|
+
// Error: Argument of type '"luckyNumber"' is not assignable to parameter of type '"name" | "surname"'.
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Known limitations:
|
|
31
|
+
- An index signature is reported as a required key, so `RequiredKeysOf<Record<string, unknown>>` is `string` rather than `never`. The signature satisfies the required-property check against `Record<Key, Type[Key]>`, even though no particular property has to be present.
|
|
32
|
+
- A union reports the keys of each of its members, so the result can name a key that is not a key of the union itself. `keyof` of a union is the intersection of its members' keys, so `RequiredKeysOf<{a: string} | {b: number}>` is `'a' | 'b'` while `keyof` of the same union is `never`. Read one member at a time if you need a key that is valid for the whole union.
|
|
33
|
+
|
|
34
|
+
@category Utilities
|
|
35
|
+
*/
|
|
36
|
+
export type RequiredKeysOf<Type extends object> = IsAny<Type> extends true ? keyof Type : Type extends unknown // For distributing `Type`
|
|
37
|
+
? (keyof { [Key in keyof Type as Type extends Record<Key, Type[Key]> ? Key : never]: never; }) & keyof Type : never; // Should never happen
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { UnwrapBrandedPrimitive } from "./unwrap-branded-primitive.js";
|
|
2
|
+
import { NegativeInfinity, PositiveInfinity } from "./numeric.js";
|
|
3
|
+
/**
|
|
4
|
+
Converts a numeric string to a number.
|
|
5
|
+
|
|
6
|
+
@example
|
|
7
|
+
```
|
|
8
|
+
import type {StringToNumber} from 'type-fest';
|
|
9
|
+
|
|
10
|
+
type PositiveInteger = StringToNumber<'1234'>;
|
|
11
|
+
//=> 1234
|
|
12
|
+
|
|
13
|
+
type NegativeInteger = StringToNumber<'-1234'>;
|
|
14
|
+
//=> -1234
|
|
15
|
+
|
|
16
|
+
type PositiveFloat = StringToNumber<'1234.56'>;
|
|
17
|
+
//=> 1234.56
|
|
18
|
+
|
|
19
|
+
type NegativeFloat = StringToNumber<'-1234.56'>;
|
|
20
|
+
//=> -1234.56
|
|
21
|
+
|
|
22
|
+
type PositiveInfinity = StringToNumber<'Infinity'>;
|
|
23
|
+
//=> Infinity
|
|
24
|
+
|
|
25
|
+
type NegativeInfinity = StringToNumber<'-Infinity'>;
|
|
26
|
+
//=> -Infinity
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Note: Some strings, such as `'1.50'`, `'0b10'`, `'12_345'`, or an integer too large to be represented exactly like `'9007199254740993'`, may look like they can be converted to numbers, but they don't actually have corresponding numeric literals. So, in such cases, this type produces `never`. See [type-fest#1446](https://github.com/sindresorhus/type-fest/pull/1446) for more details.
|
|
30
|
+
|
|
31
|
+
@example
|
|
32
|
+
```
|
|
33
|
+
import type {StringToNumber} from 'type-fest';
|
|
34
|
+
|
|
35
|
+
type FractionalsEndingInZero = StringToNumber<'1.50'>;
|
|
36
|
+
//=> never
|
|
37
|
+
|
|
38
|
+
type NonDecimalBases = StringToNumber<'0b10' | '0o10' | '0x10'>;
|
|
39
|
+
//=> never
|
|
40
|
+
|
|
41
|
+
type NumericSeparators = StringToNumber<'12_345'>;
|
|
42
|
+
//=> never
|
|
43
|
+
|
|
44
|
+
type TooLarge = StringToNumber<'9007199254740993'>;
|
|
45
|
+
//=> never
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
@see {@link StringToBoolean} - For parsing a boolean string.
|
|
49
|
+
|
|
50
|
+
@category String
|
|
51
|
+
@category Numeric
|
|
52
|
+
@category Template literal
|
|
53
|
+
*/
|
|
54
|
+
// The parser already returns `number` for `any` and distributes `never` to `never`.
|
|
55
|
+
export type StringToNumber<S extends string> = _StringToNumber<S extends object ? UnwrapBrandedPrimitive<S> : S>;
|
|
56
|
+
type _StringToNumber<S extends string> = S extends `${infer N extends number}` ? number extends N ? `${number}` extends S ? N : never : N : string extends S ? number : S extends 'Infinity' ? PositiveInfinity : S extends '-Infinity' ? NegativeInfinity : never;
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import tag from "../../../../tagged-tag@1.0.0/vendor/tagged-tag/index.js";
|
|
2
|
+
import { UnionMember } from "./union-member.js";
|
|
3
|
+
// Declaration emit cannot name the `tag` symbol unless the user's file imports it. So exporting a value whose inferred type contains the `[tag]` key directly (for example, after spreading a tagged object) fails with TS4023: https://github.com/microsoft/TypeScript/issues/64812
|
|
4
|
+
// eslint-disable-next-line type-fest/require-exported-types
|
|
5
|
+
export type TagContainer<Token> = {
|
|
6
|
+
readonly [tag]: Token;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
The tag part of a {@link Tagged} type, without the underlying type.
|
|
10
|
+
|
|
11
|
+
`Tagged<Type, TagName, TagMetadata>` is `Type & Tag<TagName, TagMetadata>`. Use `Tagged` to create tagged types. Use `Tag` to accept any type that has a given tag, whatever its underlying type is.
|
|
12
|
+
|
|
13
|
+
TypeScript can also show a tagged type as an intersection with `Tag`, for example in emitted declaration files. This is why `Tag` is exported.
|
|
14
|
+
|
|
15
|
+
@example
|
|
16
|
+
```
|
|
17
|
+
import type {Tag, Tagged} from 'type-fest';
|
|
18
|
+
|
|
19
|
+
type Url = Tagged<string, 'URL'>;
|
|
20
|
+
type UrlObject = Tagged<URL, 'URL'>;
|
|
21
|
+
|
|
22
|
+
// Accepts any type that has the `URL` tag, with any metadata.
|
|
23
|
+
declare function fetchUrl(url: Tag<'URL', unknown>): void;
|
|
24
|
+
|
|
25
|
+
fetchUrl('https://example.com' as Url);
|
|
26
|
+
fetchUrl(new URL('https://example.com') as UrlObject);
|
|
27
|
+
|
|
28
|
+
// @ts-expect-error
|
|
29
|
+
fetchUrl('https://example.com');
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
@category Type
|
|
33
|
+
*/
|
|
34
|
+
// Exported so that declaration emit can name it. TypeScript can reduce a `Tagged` type to `Type & Tag<…>` (for example, `Tagged<T, 'A'> & T`), and package `exports` hide this file, so a user's exported value with that type would otherwise fail with TS4023: https://github.com/sindresorhus/type-fest/pull/1243
|
|
35
|
+
export type Tag<TagName extends PropertyKey, TagMetadata> = TagContainer<{ [Key in TagName]: TagMetadata; }>;
|
|
36
|
+
/**
|
|
37
|
+
Get the untagged portion of a tagged type created with `Tagged`.
|
|
38
|
+
|
|
39
|
+
For nested tags, keep each tag’s metadata in one layer and add one distinct tag name per layer. Reusing a name with different metadata, or nesting multiple layers that each add several names, is not supported.
|
|
40
|
+
|
|
41
|
+
Why is this necessary?
|
|
42
|
+
|
|
43
|
+
1. Use a `Tagged` type as object keys
|
|
44
|
+
2. Prevent TS4058 error: "Return type of exported function has or is using name X from external module Y but cannot be named"
|
|
45
|
+
|
|
46
|
+
@example
|
|
47
|
+
```
|
|
48
|
+
import type {Tagged, UnwrapTagged} from 'type-fest';
|
|
49
|
+
|
|
50
|
+
type AccountType = Tagged<'SAVINGS' | 'CHECKING', 'AccountType'>;
|
|
51
|
+
|
|
52
|
+
const moneyByAccountType: Record<UnwrapTagged<AccountType>, number> = {
|
|
53
|
+
SAVINGS: 99,
|
|
54
|
+
CHECKING: 0.1,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// Without UnwrapTagged, the following expression would throw a type error.
|
|
58
|
+
const money = moneyByAccountType.SAVINGS; // TS error: Property 'SAVINGS' does not exist
|
|
59
|
+
|
|
60
|
+
// Attempting to pass a non-Tagged type to UnwrapTagged will raise a type error.
|
|
61
|
+
// @ts-expect-error
|
|
62
|
+
type WontWork = UnwrapTagged<string>;
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
@example
|
|
66
|
+
```
|
|
67
|
+
import type {Tagged, UnwrapTagged} from 'type-fest';
|
|
68
|
+
|
|
69
|
+
// Keep a tag’s metadata in one layer.
|
|
70
|
+
type CheckedUserId = Tagged<string, 'Checked', {parsed: true; validated: true}>;
|
|
71
|
+
|
|
72
|
+
type UserId = UnwrapTagged<CheckedUserId>;
|
|
73
|
+
//=> string
|
|
74
|
+
|
|
75
|
+
// Use a distinct tag name for another stage.
|
|
76
|
+
type StoredUserId = Tagged<CheckedUserId, 'Stored', {table: 'users'}>;
|
|
77
|
+
|
|
78
|
+
type StoredUserIdValue = UnwrapTagged<StoredUserId>;
|
|
79
|
+
//=> string
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
@category Type
|
|
83
|
+
*/
|
|
84
|
+
// The constraint accepts a bare `TagContainer` too, so that the deprecated `Opaque` form, which tags with a token rather than a keyed object, can be unwrapped as well.
|
|
85
|
+
export type UnwrapTagged<TaggedType extends TagContainer<any>> = RemoveAllTags<TaggedType>;
|
|
86
|
+
type RemoveAllTags<T> = T extends TagContainer<any> ?
|
|
87
|
+
// Every order of removing the tags ends at the same type, so following only one of them avoids branching recursively over every removal order.
|
|
88
|
+
RemoveAllTags<UnionMember<RemoveTag<T>>> : T;
|
|
89
|
+
/**
|
|
90
|
+
Removes a single tag from `T`, returning every possible result.
|
|
91
|
+
|
|
92
|
+
A tag can be applied one tag-name at a time (each application contributes its own layer to the intersection) or as a union of tag names in a single application (one layer holding a multi-key tag object). Because the intersection is only stripped when a layer matches a target tag object exactly, both shapes are peeled here, and only strictly smaller results are kept so that the recursion always makes progress and terminates.
|
|
93
|
+
*/
|
|
94
|
+
type RemoveTag<T extends TagContainer<unknown>> = { [ThisTag in keyof T[typeof tag]]: T extends (infer Underlying) & Tag<ThisTag, T[typeof tag][ThisTag]> ? [Underlying] extends [T] ? never : Underlying : never; }[keyof T[typeof tag]] | (T extends (infer Underlying) & TagContainer<T[typeof tag]> ? [Underlying] extends [T] ? never : Underlying : never);
|
|
95
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { IsNever } from "./is-never.js";
|
|
2
|
+
/**
|
|
3
|
+
Returns an arbitrary member of a union type.
|
|
4
|
+
|
|
5
|
+
Use-cases:
|
|
6
|
+
- Implementing recursive type functions that accept a union type.
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import type {UnionMember, IsNever} from 'type-fest';
|
|
11
|
+
|
|
12
|
+
type UnionLength<T, Acc extends any[] = []> =
|
|
13
|
+
UnionMember<T> extends infer Member
|
|
14
|
+
? IsNever<Member> extends false
|
|
15
|
+
? UnionLength<Exclude<T, Member>, [...Acc, Member]>
|
|
16
|
+
: Acc['length']
|
|
17
|
+
: never;
|
|
18
|
+
|
|
19
|
+
type T1 = UnionLength<'foo' | 'bar' | 'baz'>;
|
|
20
|
+
//=> 3
|
|
21
|
+
|
|
22
|
+
type T2 = UnionLength<{a: string}>;
|
|
23
|
+
//=> 1
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
- Picking an arbitrary member from a union
|
|
27
|
+
|
|
28
|
+
@example
|
|
29
|
+
```
|
|
30
|
+
import type {UnionMember, Primitive, LiteralToPrimitive} from 'type-fest';
|
|
31
|
+
|
|
32
|
+
type IsHomogenous<T extends Primitive> = [T] extends [LiteralToPrimitive<UnionMember<T>>] ? true : false;
|
|
33
|
+
|
|
34
|
+
type T1 = IsHomogenous<1 | 2 | 3 | 4>;
|
|
35
|
+
//=> true
|
|
36
|
+
|
|
37
|
+
type T2 = IsHomogenous<'foo' | 'bar'>;
|
|
38
|
+
//=> true
|
|
39
|
+
|
|
40
|
+
type T3 = IsHomogenous<'foo' | 'bar' | 1>;
|
|
41
|
+
//=> false
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Returns `never` when the input is `never`.
|
|
45
|
+
|
|
46
|
+
@example
|
|
47
|
+
```
|
|
48
|
+
import type {UnionMember} from 'type-fest';
|
|
49
|
+
|
|
50
|
+
type LastNever = UnionMember<never>;
|
|
51
|
+
//=> never
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
@category Type
|
|
55
|
+
*/
|
|
56
|
+
export type UnionMember<T> = IsNever<T> extends true ? never :
|
|
57
|
+
// This infers the intersection itself instead of using `UnionToIntersection`, whose `& Union` makes TypeScript distribute the intersection over every member, which is slow for large unions and for types like `Tagged` that call this in a loop.
|
|
58
|
+
(T extends any ? (member: () => T) => void : never) extends ((member: infer Intersection) => void) ? Intersection extends (() => (infer R)) ? R : never : never;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Represents an array with `unknown` value.
|
|
3
|
+
|
|
4
|
+
Use case: You want a type that all arrays can be assigned to, but you don't care about the value.
|
|
5
|
+
|
|
6
|
+
@example
|
|
7
|
+
```
|
|
8
|
+
import type {UnknownArray} from 'type-fest';
|
|
9
|
+
|
|
10
|
+
type IsArray<T> = T extends UnknownArray ? true : false;
|
|
11
|
+
|
|
12
|
+
type A = IsArray<['foo']>;
|
|
13
|
+
//=> true
|
|
14
|
+
|
|
15
|
+
type B = IsArray<readonly number[]>;
|
|
16
|
+
//=> true
|
|
17
|
+
|
|
18
|
+
type C = IsArray<string>;
|
|
19
|
+
//=> false
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
@category Type
|
|
23
|
+
@category Array
|
|
24
|
+
*/
|
|
25
|
+
export type UnknownArray = readonly unknown[];
|
package/dist/vendor/pnpm/type-fest@6.0.3/vendor/type-fest/source/unwrap-branded-primitive.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { CollapseLiterals } from "./collapse-literals.js";
|
|
2
|
+
import { IfNotAnyOrNever } from "./internal/type.js";
|
|
3
|
+
import { KeysOfUnion } from "./keys-of-union.js";
|
|
4
|
+
import { Primitive } from "./primitive.js";
|
|
5
|
+
import { TagContainer, UnwrapTagged } from "./tagged.js";
|
|
6
|
+
/**
|
|
7
|
+
Remove brand properties from primitive types while preserving literal types.
|
|
8
|
+
|
|
9
|
+
Useful for recovering literal keys from branded types. Unlike {@link LiteralToPrimitive}, this does not widen literals. This distributes over unions. Non-primitive members are returned unchanged, including their brands and nested properties. `any`, `never`, and `unknown` are also returned unchanged.
|
|
10
|
+
|
|
11
|
+
@example
|
|
12
|
+
```
|
|
13
|
+
import type {Tagged, UnwrapBrandedPrimitive} from 'type-fest';
|
|
14
|
+
|
|
15
|
+
type Status = ('draft' | 'published') & {readonly __brand: 'Status'};
|
|
16
|
+
|
|
17
|
+
type StatusName = UnwrapBrandedPrimitive<Status>;
|
|
18
|
+
//=> 'draft' | 'published'
|
|
19
|
+
|
|
20
|
+
type StatusCounts = Record<UnwrapBrandedPrimitive<Status>, number>;
|
|
21
|
+
//=> {draft: number; published: number}
|
|
22
|
+
|
|
23
|
+
type UserId = UnwrapBrandedPrimitive<Tagged<string, 'UserId'>>;
|
|
24
|
+
//=> string
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
@example
|
|
28
|
+
```
|
|
29
|
+
import type {UnwrapBrandedPrimitive} from 'type-fest';
|
|
30
|
+
|
|
31
|
+
type Brand = {readonly __brand: unique symbol};
|
|
32
|
+
|
|
33
|
+
type A = UnwrapBrandedPrimitive<string & Brand>;
|
|
34
|
+
//=> string
|
|
35
|
+
|
|
36
|
+
type B = UnwrapBrandedPrimitive<number & Brand>;
|
|
37
|
+
//=> number
|
|
38
|
+
|
|
39
|
+
type C = UnwrapBrandedPrimitive<PropertyKey & Brand>;
|
|
40
|
+
//=> number | string | symbol
|
|
41
|
+
|
|
42
|
+
type D = UnwrapBrandedPrimitive<(1 | 200n | 'foo' | 'bar') & Brand>;
|
|
43
|
+
//=> 1 | 200n | 'foo' | 'bar'
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Custom brands must use a single object with explicit marker properties, such as `string & {brand: 'Id'}`. Optional markers, including a single {@link Flavor}, are supported. Separate custom intersections, such as `string & BrandA & BrandB`, and marker keys shared with any built-in primitive properties are not supported. Index signatures and call or construct signatures are not supported as custom brands. All extra properties are treated as brands, including methods.
|
|
47
|
+
|
|
48
|
+
Nested {@link Tagged} types follow the limits described in {@link UnwrapTagged}. A single legacy {@link Opaque} layer is supported, except with a `never` token. Use {@link UnwrapTagged} to unwrap tagged objects too.
|
|
49
|
+
|
|
50
|
+
@see {@link UnwrapTagged}
|
|
51
|
+
@see {@link LiteralToPrimitive}
|
|
52
|
+
|
|
53
|
+
@category Type
|
|
54
|
+
*/
|
|
55
|
+
export type UnwrapBrandedPrimitive<Value> = IfNotAnyOrNever<Value, {
|
|
56
|
+
ifNot: UnwrapBrandedPrimitiveImplementation<Value, Primitive>;
|
|
57
|
+
}>;
|
|
58
|
+
type UnwrapBrandedPrimitiveImplementation<Value, Base> = Value extends Primitive ?
|
|
59
|
+
// Separate tag layers do not match a single object containing all brand properties.
|
|
60
|
+
// `CollapseLiterals` removes `& {}` first, because TypeScript defers `keyof` on types like `` `on${string}` & {} ``.
|
|
61
|
+
UnwrapPrimitiveProperties<CollapseLiterals<Value extends TagContainer<unknown> ? UnwrapTagged<Value> : Value>, Base> : Value;
|
|
62
|
+
type UnwrapPrimitiveProperties<Value, Base> = Value extends (infer Unbranded) & Pick<Value, Exclude<keyof Value, KeysOfUnion<Base>>> ? Unbranded : Value;
|
|
63
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trpc-msw",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.14.0",
|
|
4
4
|
"description": "tRPC for Mock Service Worker — answers queries, mutations and subscriptions over HTTP, batching, SSE and WebSockets with tRPC's own handlers, typed off your router.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api-mocking",
|
|
@@ -46,17 +46,17 @@
|
|
|
46
46
|
"typecheck": "tsrs --fast"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@esposter/shared": "4.
|
|
49
|
+
"@esposter/shared": "4.14.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@esposter/configuration": "4.
|
|
52
|
+
"@esposter/configuration": "4.14.0",
|
|
53
53
|
"@standard-schema/spec": "^1.1.0",
|
|
54
54
|
"@trpc/client": "^11.29.5",
|
|
55
55
|
"@types/node": "^26.6.6",
|
|
56
56
|
"superjson": "^2.2.6",
|
|
57
|
-
"trpc-nuxt-module": "4.
|
|
57
|
+
"trpc-nuxt-module": "4.14.0",
|
|
58
58
|
"tsdown": "^0.23.7",
|
|
59
|
-
"type-fest": "^6.0.
|
|
59
|
+
"type-fest": "^6.0.3",
|
|
60
60
|
"zod": "^4.6.7"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
@@ -64,7 +64,8 @@
|
|
|
64
64
|
"msw": "^3.0.7"
|
|
65
65
|
},
|
|
66
66
|
"inlinedDependencies": {
|
|
67
|
-
"
|
|
67
|
+
"tagged-tag": "1.0.0",
|
|
68
|
+
"type-fest": "6.0.3"
|
|
68
69
|
},
|
|
69
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "4bacc78dfc7a663a424cbb5a51f57f4f8d0fee2e"
|
|
70
71
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|