@metamask-previews/keyring-api 11.0.0-22cd5fe → 11.0.0-b85bfaa
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/{api/account.cjs → account.cjs} +3 -8
- package/dist/account.cjs.map +1 -0
- package/dist/{api/account.d.cts → account.d.cts} +1 -6
- package/dist/account.d.cts.map +1 -0
- package/dist/{api/account.d.mts → account.d.mts} +1 -6
- package/dist/account.d.mts.map +1 -0
- package/dist/{api/account.mjs → account.mjs} +3 -8
- package/dist/account.mjs.map +1 -0
- package/dist/balance.cjs +10 -0
- package/dist/balance.cjs.map +1 -0
- package/dist/balance.d.cts.map +1 -0
- package/dist/balance.d.mts.map +1 -0
- package/dist/{api/balance.mjs → balance.mjs} +1 -2
- package/dist/balance.mjs.map +1 -0
- package/dist/{api/caip.cjs → caip.cjs} +3 -3
- package/dist/{api/caip.cjs.map → caip.cjs.map} +1 -1
- package/dist/caip.d.cts.map +1 -0
- package/dist/caip.d.mts.map +1 -0
- package/dist/{api/caip.mjs → caip.mjs} +1 -1
- package/dist/{api/caip.mjs.map → caip.mjs.map} +1 -1
- package/dist/export.cjs.map +1 -0
- package/dist/export.d.cts.map +1 -0
- package/dist/export.d.mts.map +1 -0
- package/dist/export.mjs.map +1 -0
- package/dist/index.cjs +6 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -12
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +7 -12
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +6 -12
- package/dist/index.mjs.map +1 -1
- package/dist/keyring.cjs +5 -0
- package/dist/keyring.cjs.map +1 -0
- package/dist/keyring.d.cts.map +1 -0
- package/dist/keyring.d.mts.map +1 -0
- package/dist/keyring.mjs +4 -0
- package/dist/keyring.mjs.map +1 -0
- package/dist/{api/request.cjs → request.cjs} +6 -7
- package/dist/request.cjs.map +1 -0
- package/dist/{api/request.d.cts → request.d.cts} +3 -3
- package/dist/request.d.cts.map +1 -0
- package/dist/{api/request.d.mts → request.d.mts} +3 -3
- package/dist/request.d.mts.map +1 -0
- package/dist/{api/request.mjs → request.mjs} +1 -2
- package/dist/request.mjs.map +1 -0
- package/dist/{api/response.cjs → response.cjs} +6 -6
- package/dist/{api/response.cjs.map → response.cjs.map} +1 -1
- package/dist/response.d.cts.map +1 -0
- package/dist/response.d.mts.map +1 -0
- package/dist/{api/response.mjs → response.mjs} +1 -1
- package/dist/{api/response.mjs.map → response.mjs.map} +1 -1
- package/package.json +9 -10
- package/dist/JsonRpcRequest.cjs +0 -13
- package/dist/JsonRpcRequest.cjs.map +0 -1
- package/dist/JsonRpcRequest.d.cts +0 -17
- package/dist/JsonRpcRequest.d.cts.map +0 -1
- package/dist/JsonRpcRequest.d.mts +0 -17
- package/dist/JsonRpcRequest.d.mts.map +0 -1
- package/dist/JsonRpcRequest.mjs +0 -10
- package/dist/JsonRpcRequest.mjs.map +0 -1
- package/dist/KeyringClient.cjs +0 -124
- package/dist/KeyringClient.cjs.map +0 -1
- package/dist/KeyringClient.d.cts +0 -29
- package/dist/KeyringClient.d.cts.map +0 -1
- package/dist/KeyringClient.d.mts +0 -29
- package/dist/KeyringClient.d.mts.map +0 -1
- package/dist/KeyringClient.mjs +0 -120
- package/dist/KeyringClient.mjs.map +0 -1
- package/dist/KeyringSnapRpcClient.cjs +0 -68
- package/dist/KeyringSnapRpcClient.cjs.map +0 -1
- package/dist/KeyringSnapRpcClient.d.cts +0 -40
- package/dist/KeyringSnapRpcClient.d.cts.map +0 -1
- package/dist/KeyringSnapRpcClient.d.mts +0 -40
- package/dist/KeyringSnapRpcClient.d.mts.map +0 -1
- package/dist/KeyringSnapRpcClient.mjs +0 -63
- package/dist/KeyringSnapRpcClient.mjs.map +0 -1
- package/dist/api/account.cjs.map +0 -1
- package/dist/api/account.d.cts.map +0 -1
- package/dist/api/account.d.mts.map +0 -1
- package/dist/api/account.mjs.map +0 -1
- package/dist/api/balance.cjs +0 -11
- package/dist/api/balance.cjs.map +0 -1
- package/dist/api/balance.d.cts.map +0 -1
- package/dist/api/balance.d.mts.map +0 -1
- package/dist/api/balance.mjs.map +0 -1
- package/dist/api/caip.d.cts.map +0 -1
- package/dist/api/caip.d.mts.map +0 -1
- package/dist/api/export.cjs.map +0 -1
- package/dist/api/export.d.cts.map +0 -1
- package/dist/api/export.d.mts.map +0 -1
- package/dist/api/export.mjs.map +0 -1
- package/dist/api/index.cjs +0 -23
- package/dist/api/index.cjs.map +0 -1
- package/dist/api/index.d.cts +0 -8
- package/dist/api/index.d.cts.map +0 -1
- package/dist/api/index.d.mts +0 -8
- package/dist/api/index.d.mts.map +0 -1
- package/dist/api/index.mjs +0 -7
- package/dist/api/index.mjs.map +0 -1
- package/dist/api/keyring.cjs +0 -3
- package/dist/api/keyring.cjs.map +0 -1
- package/dist/api/keyring.d.cts.map +0 -1
- package/dist/api/keyring.d.mts.map +0 -1
- package/dist/api/keyring.mjs +0 -2
- package/dist/api/keyring.mjs.map +0 -1
- package/dist/api/request.cjs.map +0 -1
- package/dist/api/request.d.cts.map +0 -1
- package/dist/api/request.d.mts.map +0 -1
- package/dist/api/request.mjs.map +0 -1
- package/dist/api/response.d.cts.map +0 -1
- package/dist/api/response.d.mts.map +0 -1
- package/dist/btc/constants.cjs +0 -13
- package/dist/btc/constants.cjs.map +0 -1
- package/dist/btc/constants.d.cts +0 -9
- package/dist/btc/constants.d.cts.map +0 -1
- package/dist/btc/constants.d.mts +0 -9
- package/dist/btc/constants.d.mts.map +0 -1
- package/dist/btc/constants.mjs +0 -10
- package/dist/btc/constants.mjs.map +0 -1
- package/dist/btc/index.cjs +0 -19
- package/dist/btc/index.cjs.map +0 -1
- package/dist/btc/index.d.cts +0 -3
- package/dist/btc/index.d.cts.map +0 -1
- package/dist/btc/index.d.mts +0 -3
- package/dist/btc/index.d.mts.map +0 -1
- package/dist/btc/index.mjs +0 -3
- package/dist/btc/index.mjs.map +0 -1
- package/dist/btc/types.cjs +0 -40
- package/dist/btc/types.cjs.map +0 -1
- package/dist/btc/types.d.cts +0 -36
- package/dist/btc/types.d.cts.map +0 -1
- package/dist/btc/types.d.mts +0 -36
- package/dist/btc/types.d.mts.map +0 -1
- package/dist/btc/types.mjs +0 -37
- package/dist/btc/types.mjs.map +0 -1
- package/dist/eth/constants.cjs +0 -12
- package/dist/eth/constants.cjs.map +0 -1
- package/dist/eth/constants.d.cts +0 -8
- package/dist/eth/constants.d.cts.map +0 -1
- package/dist/eth/constants.d.mts +0 -8
- package/dist/eth/constants.d.mts.map +0 -1
- package/dist/eth/constants.mjs +0 -9
- package/dist/eth/constants.mjs.map +0 -1
- package/dist/eth/erc4337/index.cjs +0 -18
- package/dist/eth/erc4337/index.cjs.map +0 -1
- package/dist/eth/erc4337/index.d.cts +0 -2
- package/dist/eth/erc4337/index.d.cts.map +0 -1
- package/dist/eth/erc4337/index.d.mts +0 -2
- package/dist/eth/erc4337/index.d.mts.map +0 -1
- package/dist/eth/erc4337/index.mjs +0 -2
- package/dist/eth/erc4337/index.mjs.map +0 -1
- package/dist/eth/erc4337/types.cjs +0 -62
- package/dist/eth/erc4337/types.cjs.map +0 -1
- package/dist/eth/erc4337/types.d.cts +0 -98
- package/dist/eth/erc4337/types.d.cts.map +0 -1
- package/dist/eth/erc4337/types.d.mts +0 -98
- package/dist/eth/erc4337/types.d.mts.map +0 -1
- package/dist/eth/erc4337/types.mjs +0 -59
- package/dist/eth/erc4337/types.mjs.map +0 -1
- package/dist/eth/index.cjs +0 -21
- package/dist/eth/index.cjs.map +0 -1
- package/dist/eth/index.d.cts +0 -5
- package/dist/eth/index.d.cts.map +0 -1
- package/dist/eth/index.d.mts +0 -5
- package/dist/eth/index.d.mts.map +0 -1
- package/dist/eth/index.mjs +0 -5
- package/dist/eth/index.mjs.map +0 -1
- package/dist/eth/types.cjs +0 -73
- package/dist/eth/types.cjs.map +0 -1
- package/dist/eth/types.d.cts +0 -85
- package/dist/eth/types.d.cts.map +0 -1
- package/dist/eth/types.d.mts +0 -85
- package/dist/eth/types.d.mts.map +0 -1
- package/dist/eth/types.mjs +0 -70
- package/dist/eth/types.mjs.map +0 -1
- package/dist/eth/utils.cjs +0 -14
- package/dist/eth/utils.cjs.map +0 -1
- package/dist/eth/utils.d.cts +0 -9
- package/dist/eth/utils.d.cts.map +0 -1
- package/dist/eth/utils.d.mts +0 -9
- package/dist/eth/utils.d.mts.map +0 -1
- package/dist/eth/utils.mjs +0 -11
- package/dist/eth/utils.mjs.map +0 -1
- package/dist/events.cjs +0 -17
- package/dist/events.cjs.map +0 -1
- package/dist/events.d.cts +0 -11
- package/dist/events.d.cts.map +0 -1
- package/dist/events.d.mts +0 -11
- package/dist/events.d.mts.map +0 -1
- package/dist/events.mjs +0 -14
- package/dist/events.mjs.map +0 -1
- package/dist/internal/api.cjs +0 -139
- package/dist/internal/api.cjs.map +0 -1
- package/dist/internal/api.d.cts +0 -431
- package/dist/internal/api.d.cts.map +0 -1
- package/dist/internal/api.d.mts +0 -431
- package/dist/internal/api.d.mts.map +0 -1
- package/dist/internal/api.mjs +0 -136
- package/dist/internal/api.mjs.map +0 -1
- package/dist/internal/eth/EthKeyring.cjs +0 -3
- package/dist/internal/eth/EthKeyring.cjs.map +0 -1
- package/dist/internal/eth/EthKeyring.d.cts +0 -34
- package/dist/internal/eth/EthKeyring.d.cts.map +0 -1
- package/dist/internal/eth/EthKeyring.d.mts +0 -34
- package/dist/internal/eth/EthKeyring.d.mts.map +0 -1
- package/dist/internal/eth/EthKeyring.mjs +0 -2
- package/dist/internal/eth/EthKeyring.mjs.map +0 -1
- package/dist/internal/eth/index.cjs +0 -3
- package/dist/internal/eth/index.cjs.map +0 -1
- package/dist/internal/eth/index.d.cts +0 -2
- package/dist/internal/eth/index.d.cts.map +0 -1
- package/dist/internal/eth/index.d.mts +0 -2
- package/dist/internal/eth/index.d.mts.map +0 -1
- package/dist/internal/eth/index.mjs +0 -2
- package/dist/internal/eth/index.mjs.map +0 -1
- package/dist/internal/events.cjs +0 -72
- package/dist/internal/events.cjs.map +0 -1
- package/dist/internal/events.d.cts +0 -170
- package/dist/internal/events.d.cts.map +0 -1
- package/dist/internal/events.d.mts +0 -170
- package/dist/internal/events.d.mts.map +0 -1
- package/dist/internal/events.mjs +0 -69
- package/dist/internal/events.mjs.map +0 -1
- package/dist/internal/index.cjs +0 -21
- package/dist/internal/index.cjs.map +0 -1
- package/dist/internal/index.d.cts +0 -6
- package/dist/internal/index.d.cts.map +0 -1
- package/dist/internal/index.d.mts +0 -6
- package/dist/internal/index.d.mts.map +0 -1
- package/dist/internal/index.mjs +0 -5
- package/dist/internal/index.mjs.map +0 -1
- package/dist/internal/rpc.cjs +0 -33
- package/dist/internal/rpc.cjs.map +0 -1
- package/dist/internal/rpc.d.cts +0 -26
- package/dist/internal/rpc.d.cts.map +0 -1
- package/dist/internal/rpc.d.mts +0 -26
- package/dist/internal/rpc.d.mts.map +0 -1
- package/dist/internal/rpc.mjs +0 -29
- package/dist/internal/rpc.mjs.map +0 -1
- package/dist/internal/types.cjs +0 -52
- package/dist/internal/types.cjs.map +0 -1
- package/dist/internal/types.d.cts +0 -402
- package/dist/internal/types.d.cts.map +0 -1
- package/dist/internal/types.d.mts +0 -402
- package/dist/internal/types.d.mts.map +0 -1
- package/dist/internal/types.mjs +0 -49
- package/dist/internal/types.mjs.map +0 -1
- package/dist/rpc-handler.cjs +0 -136
- package/dist/rpc-handler.cjs.map +0 -1
- package/dist/rpc-handler.d.cts +0 -30
- package/dist/rpc-handler.d.cts.map +0 -1
- package/dist/rpc-handler.d.mts +0 -30
- package/dist/rpc-handler.d.mts.map +0 -1
- package/dist/rpc-handler.mjs +0 -131
- package/dist/rpc-handler.mjs.map +0 -1
- package/dist/snap-utils.cjs +0 -20
- package/dist/snap-utils.cjs.map +0 -1
- package/dist/snap-utils.d.cts +0 -12
- package/dist/snap-utils.d.cts.map +0 -1
- package/dist/snap-utils.d.mts +0 -12
- package/dist/snap-utils.d.mts.map +0 -1
- package/dist/snap-utils.mjs +0 -17
- package/dist/snap-utils.mjs.map +0 -1
- package/dist/sol/constants.cjs +0 -14
- package/dist/sol/constants.cjs.map +0 -1
- package/dist/sol/constants.d.cts +0 -10
- package/dist/sol/constants.d.cts.map +0 -1
- package/dist/sol/constants.d.mts +0 -10
- package/dist/sol/constants.d.mts.map +0 -1
- package/dist/sol/constants.mjs +0 -11
- package/dist/sol/constants.mjs.map +0 -1
- package/dist/sol/index.cjs +0 -19
- package/dist/sol/index.cjs.map +0 -1
- package/dist/sol/index.d.cts +0 -3
- package/dist/sol/index.d.cts.map +0 -1
- package/dist/sol/index.d.mts +0 -3
- package/dist/sol/index.d.mts.map +0 -1
- package/dist/sol/index.mjs +0 -3
- package/dist/sol/index.mjs.map +0 -1
- package/dist/sol/types.cjs +0 -36
- package/dist/sol/types.cjs.map +0 -1
- package/dist/sol/types.d.cts +0 -41
- package/dist/sol/types.d.cts.map +0 -1
- package/dist/sol/types.d.mts +0 -41
- package/dist/sol/types.d.mts.map +0 -1
- package/dist/sol/types.mjs +0 -33
- package/dist/sol/types.mjs.map +0 -1
- package/dist/superstruct.cjs +0 -80
- package/dist/superstruct.cjs.map +0 -1
- package/dist/superstruct.d.cts +0 -84
- package/dist/superstruct.d.cts.map +0 -1
- package/dist/superstruct.d.mts +0 -84
- package/dist/superstruct.d.mts.map +0 -1
- package/dist/superstruct.mjs +0 -74
- package/dist/superstruct.mjs.map +0 -1
- package/dist/utils/index.cjs +0 -19
- package/dist/utils/index.cjs.map +0 -1
- package/dist/utils/index.d.cts +0 -3
- package/dist/utils/index.d.cts.map +0 -1
- package/dist/utils/index.d.mts +0 -3
- package/dist/utils/index.d.mts.map +0 -1
- package/dist/utils/index.mjs +0 -3
- package/dist/utils/index.mjs.map +0 -1
- package/dist/utils/types.cjs +0 -29
- package/dist/utils/types.cjs.map +0 -1
- package/dist/utils/types.d.cts +0 -18
- package/dist/utils/types.d.cts.map +0 -1
- package/dist/utils/types.d.mts +0 -18
- package/dist/utils/types.d.mts.map +0 -1
- package/dist/utils/types.mjs +0 -26
- package/dist/utils/types.mjs.map +0 -1
- package/dist/utils/typing.cjs +0 -20
- package/dist/utils/typing.cjs.map +0 -1
- package/dist/utils/typing.d.cts +0 -33
- package/dist/utils/typing.d.cts.map +0 -1
- package/dist/utils/typing.d.mts +0 -33
- package/dist/utils/typing.d.mts.map +0 -1
- package/dist/utils/typing.mjs +0 -17
- package/dist/utils/typing.mjs.map +0 -1
- /package/dist/{api/balance.d.cts → balance.d.cts} +0 -0
- /package/dist/{api/balance.d.mts → balance.d.mts} +0 -0
- /package/dist/{api/caip.d.cts → caip.d.cts} +0 -0
- /package/dist/{api/caip.d.mts → caip.d.mts} +0 -0
- /package/dist/{api/export.cjs → export.cjs} +0 -0
- /package/dist/{api/export.d.cts → export.d.cts} +0 -0
- /package/dist/{api/export.d.mts → export.d.mts} +0 -0
- /package/dist/{api/export.mjs → export.mjs} +0 -0
- /package/dist/{api/keyring.d.cts → keyring.d.cts} +0 -0
- /package/dist/{api/keyring.d.mts → keyring.d.mts} +0 -0
- /package/dist/{api/response.d.cts → response.d.cts} +0 -0
- /package/dist/{api/response.d.mts → response.d.mts} +0 -0
package/dist/superstruct.cjs
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.object = object;
|
|
4
|
-
exports.exactOptional = exactOptional;
|
|
5
|
-
exports.definePattern = definePattern;
|
|
6
|
-
exports.strictMask = strictMask;
|
|
7
|
-
const superstruct_1 = require("@metamask/superstruct");
|
|
8
|
-
/**
|
|
9
|
-
* Change the return type of a superstruct object struct to support exact
|
|
10
|
-
* optional properties.
|
|
11
|
-
*
|
|
12
|
-
* @param schema - The object schema.
|
|
13
|
-
* @returns A struct representing an object with a known set of properties.
|
|
14
|
-
*/
|
|
15
|
-
function object(schema) {
|
|
16
|
-
return (0, superstruct_1.object)(schema);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Check if the current property is present in its parent object.
|
|
20
|
-
*
|
|
21
|
-
* @param ctx - The context to check.
|
|
22
|
-
* @returns `true` if the property is present, `false` otherwise.
|
|
23
|
-
*/
|
|
24
|
-
function hasOptional(ctx) {
|
|
25
|
-
const property = ctx.path[ctx.path.length - 1];
|
|
26
|
-
const parent = ctx.branch[ctx.branch.length - 2];
|
|
27
|
-
return property in parent;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Augment a struct to allow exact-optional values. Exact-optional values can
|
|
31
|
-
* be omitted but cannot be `undefined`.
|
|
32
|
-
*
|
|
33
|
-
* ```ts
|
|
34
|
-
* const foo = object({ bar: exactOptional(string()) });
|
|
35
|
-
* type Foo = Infer<typeof foo>;
|
|
36
|
-
* // Foo = { bar?: string }
|
|
37
|
-
* ```
|
|
38
|
-
*
|
|
39
|
-
* @param struct - The struct to augment.
|
|
40
|
-
* @returns The augmented struct.
|
|
41
|
-
*/
|
|
42
|
-
function exactOptional(struct) {
|
|
43
|
-
return new superstruct_1.Struct({
|
|
44
|
-
...struct,
|
|
45
|
-
validator: (value, ctx) => !hasOptional(ctx) || struct.validator(value, ctx),
|
|
46
|
-
refiner: (value, ctx) => !hasOptional(ctx) || struct.refiner(value, ctx),
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Defines a new string-struct matching a regular expression.
|
|
51
|
-
*
|
|
52
|
-
* Example:
|
|
53
|
-
*
|
|
54
|
-
* ```ts
|
|
55
|
-
* const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
* @param name - Type name.
|
|
59
|
-
* @param pattern - Regular expression to match.
|
|
60
|
-
* @returns A new string-struct that matches the given pattern.
|
|
61
|
-
*/
|
|
62
|
-
function definePattern(name, pattern) {
|
|
63
|
-
return (0, superstruct_1.define)(name, (value) => typeof value === 'string' && pattern.test(value));
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Assert that a value is valid according to a struct.
|
|
67
|
-
*
|
|
68
|
-
* It is similar to superstruct's mask function, but it does not ignore extra
|
|
69
|
-
* properties.
|
|
70
|
-
*
|
|
71
|
-
* @param value - Value to check.
|
|
72
|
-
* @param struct - Struct to validate the value against.
|
|
73
|
-
* @param message - Error message to throw if the value is not valid.
|
|
74
|
-
* @returns The value if it is valid.
|
|
75
|
-
*/
|
|
76
|
-
function strictMask(value, struct, message) {
|
|
77
|
-
(0, superstruct_1.assert)(value, struct, message);
|
|
78
|
-
return value;
|
|
79
|
-
}
|
|
80
|
-
//# sourceMappingURL=superstruct.cjs.map
|
package/dist/superstruct.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"superstruct.cjs","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":";;AAiEA,wBAIC;AA4BD,sCAYC;AAeD,sCASC;AAaD,gCAOC;AAzJD,uDAK+B;AAqD/B;;;;;;GAMG;AACH,SAAgB,MAAM,CACpB,MAAc;IAEd,OAAO,IAAA,oBAAQ,EAAC,MAAM,CAAQ,CAAC;AACjC,CAAC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAAC,GAAY;IAC/B,MAAM,QAAQ,GAAW,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACvD,MAAM,MAAM,GAA4B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE1E,OAAO,QAAQ,IAAI,MAAM,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa,CAC3B,MAA4B;IAE5B,OAAO,IAAI,oBAAM,CAAC;QAChB,GAAG,MAAM;QAET,SAAS,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACxB,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC;QAEnD,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACtB,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAa,EAAE,GAAG,CAAC;KAC1D,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa,CAC3B,IAAY,EACZ,OAAe;IAEf,OAAO,IAAA,oBAAM,EACX,IAAI,EACJ,CAAC,KAAc,EAAW,EAAE,CAC1B,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CACnD,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,UAAU,CACxB,KAAc,EACd,MAA4B,EAC5B,OAAgB;IAEhB,IAAA,oBAAM,EAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import {\n Struct,\n assert,\n define,\n object as stObject,\n} from '@metamask/superstruct';\nimport type {\n Infer,\n Context,\n ObjectSchema,\n OmitBy,\n Optionalize,\n PickBy,\n Simplify,\n} from '@metamask/superstruct';\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ndeclare const ExactOptionalSymbol: unique symbol;\n\nexport type ExactOptionalTag = {\n type: typeof ExactOptionalSymbol;\n};\n\n/**\n * Exclude type `Type` from the properties of `Obj`.\n *\n * ```ts\n * type Foo = { a: string | null; b: number };\n * type Bar = ExcludeType<Foo, null>;\n * // Bar = { a: string, b: number }\n * ```\n */\nexport type ExcludeType<Obj, Type> = {\n [K in keyof Obj]: Exclude<Obj[K], Type>;\n};\n\n/**\n * Make optional all properties that have the `ExactOptionalTag` type.\n *\n * ```ts\n * type Foo = { a: string | ExactOptionalTag; b: number};\n * type Bar = ExactOptionalize<Foo>;\n * // Bar = { a?: string; b: number}\n * ```\n */\nexport type ExactOptionalize<Schema extends object> = OmitBy<\n Schema,\n ExactOptionalTag\n> &\n Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;\n\n/**\n * Infer a type from an superstruct object schema.\n */\nexport type ObjectType<Schema extends ObjectSchema> = Simplify<\n ExactOptionalize<Optionalize<{ [K in keyof Schema]: Infer<Schema[K]> }>>\n>;\n\n/**\n * Change the return type of a superstruct object struct to support exact\n * optional properties.\n *\n * @param schema - The object schema.\n * @returns A struct representing an object with a known set of properties.\n */\nexport function object<Schema extends ObjectSchema>(\n schema: Schema,\n): Struct<ObjectType<Schema>, Schema> {\n return stObject(schema) as any;\n}\n\n/**\n * Check if the current property is present in its parent object.\n *\n * @param ctx - The context to check.\n * @returns `true` if the property is present, `false` otherwise.\n */\nfunction hasOptional(ctx: Context): boolean {\n const property: string = ctx.path[ctx.path.length - 1];\n const parent: Record<string, unknown> = ctx.branch[ctx.branch.length - 2];\n\n return property in parent;\n}\n\n/**\n * Augment a struct to allow exact-optional values. Exact-optional values can\n * be omitted but cannot be `undefined`.\n *\n * ```ts\n * const foo = object({ bar: exactOptional(string()) });\n * type Foo = Infer<typeof foo>;\n * // Foo = { bar?: string }\n * ```\n *\n * @param struct - The struct to augment.\n * @returns The augmented struct.\n */\nexport function exactOptional<Type, Schema>(\n struct: Struct<Type, Schema>,\n): Struct<Type | ExactOptionalTag, Schema> {\n return new Struct({\n ...struct,\n\n validator: (value, ctx) =>\n !hasOptional(ctx) || struct.validator(value, ctx),\n\n refiner: (value, ctx) =>\n !hasOptional(ctx) || struct.refiner(value as Type, ctx),\n });\n}\n\n/**\n * Defines a new string-struct matching a regular expression.\n *\n * Example:\n *\n * ```ts\n * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);\n * ```\n *\n * @param name - Type name.\n * @param pattern - Regular expression to match.\n * @returns A new string-struct that matches the given pattern.\n */\nexport function definePattern(\n name: string,\n pattern: RegExp,\n): Struct<string, null> {\n return define<string>(\n name,\n (value: unknown): boolean =>\n typeof value === 'string' && pattern.test(value),\n );\n}\n\n/**\n * Assert that a value is valid according to a struct.\n *\n * It is similar to superstruct's mask function, but it does not ignore extra\n * properties.\n *\n * @param value - Value to check.\n * @param struct - Struct to validate the value against.\n * @param message - Error message to throw if the value is not valid.\n * @returns The value if it is valid.\n */\nexport function strictMask<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n message?: string,\n): Type {\n assert(value, struct, message);\n return value;\n}\n"]}
|
package/dist/superstruct.d.cts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { Struct } from "@metamask/superstruct";
|
|
2
|
-
import type { Infer, ObjectSchema, OmitBy, Optionalize, PickBy, Simplify } from "@metamask/superstruct";
|
|
3
|
-
declare const ExactOptionalSymbol: unique symbol;
|
|
4
|
-
export type ExactOptionalTag = {
|
|
5
|
-
type: typeof ExactOptionalSymbol;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Exclude type `Type` from the properties of `Obj`.
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* type Foo = { a: string | null; b: number };
|
|
12
|
-
* type Bar = ExcludeType<Foo, null>;
|
|
13
|
-
* // Bar = { a: string, b: number }
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
export type ExcludeType<Obj, Type> = {
|
|
17
|
-
[K in keyof Obj]: Exclude<Obj[K], Type>;
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Make optional all properties that have the `ExactOptionalTag` type.
|
|
21
|
-
*
|
|
22
|
-
* ```ts
|
|
23
|
-
* type Foo = { a: string | ExactOptionalTag; b: number};
|
|
24
|
-
* type Bar = ExactOptionalize<Foo>;
|
|
25
|
-
* // Bar = { a?: string; b: number}
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export type ExactOptionalize<Schema extends object> = OmitBy<Schema, ExactOptionalTag> & Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;
|
|
29
|
-
/**
|
|
30
|
-
* Infer a type from an superstruct object schema.
|
|
31
|
-
*/
|
|
32
|
-
export type ObjectType<Schema extends ObjectSchema> = Simplify<ExactOptionalize<Optionalize<{
|
|
33
|
-
[K in keyof Schema]: Infer<Schema[K]>;
|
|
34
|
-
}>>>;
|
|
35
|
-
/**
|
|
36
|
-
* Change the return type of a superstruct object struct to support exact
|
|
37
|
-
* optional properties.
|
|
38
|
-
*
|
|
39
|
-
* @param schema - The object schema.
|
|
40
|
-
* @returns A struct representing an object with a known set of properties.
|
|
41
|
-
*/
|
|
42
|
-
export declare function object<Schema extends ObjectSchema>(schema: Schema): Struct<ObjectType<Schema>, Schema>;
|
|
43
|
-
/**
|
|
44
|
-
* Augment a struct to allow exact-optional values. Exact-optional values can
|
|
45
|
-
* be omitted but cannot be `undefined`.
|
|
46
|
-
*
|
|
47
|
-
* ```ts
|
|
48
|
-
* const foo = object({ bar: exactOptional(string()) });
|
|
49
|
-
* type Foo = Infer<typeof foo>;
|
|
50
|
-
* // Foo = { bar?: string }
|
|
51
|
-
* ```
|
|
52
|
-
*
|
|
53
|
-
* @param struct - The struct to augment.
|
|
54
|
-
* @returns The augmented struct.
|
|
55
|
-
*/
|
|
56
|
-
export declare function exactOptional<Type, Schema>(struct: Struct<Type, Schema>): Struct<Type | ExactOptionalTag, Schema>;
|
|
57
|
-
/**
|
|
58
|
-
* Defines a new string-struct matching a regular expression.
|
|
59
|
-
*
|
|
60
|
-
* Example:
|
|
61
|
-
*
|
|
62
|
-
* ```ts
|
|
63
|
-
* const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);
|
|
64
|
-
* ```
|
|
65
|
-
*
|
|
66
|
-
* @param name - Type name.
|
|
67
|
-
* @param pattern - Regular expression to match.
|
|
68
|
-
* @returns A new string-struct that matches the given pattern.
|
|
69
|
-
*/
|
|
70
|
-
export declare function definePattern(name: string, pattern: RegExp): Struct<string, null>;
|
|
71
|
-
/**
|
|
72
|
-
* Assert that a value is valid according to a struct.
|
|
73
|
-
*
|
|
74
|
-
* It is similar to superstruct's mask function, but it does not ignore extra
|
|
75
|
-
* properties.
|
|
76
|
-
*
|
|
77
|
-
* @param value - Value to check.
|
|
78
|
-
* @param struct - Struct to validate the value against.
|
|
79
|
-
* @param message - Error message to throw if the value is not valid.
|
|
80
|
-
* @returns The value if it is valid.
|
|
81
|
-
*/
|
|
82
|
-
export declare function strictMask<Type, Schema>(value: unknown, struct: Struct<Type, Schema>, message?: string): Type;
|
|
83
|
-
export {};
|
|
84
|
-
//# sourceMappingURL=superstruct.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"superstruct.d.cts","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EAIP,8BAA8B;AAC/B,OAAO,KAAK,EACV,KAAK,EAEL,YAAY,EACZ,MAAM,EACN,WAAW,EACX,MAAM,EACN,QAAQ,EACT,8BAA8B;AAG/B,OAAO,CAAC,MAAM,mBAAmB,EAAE,OAAO,MAAM,CAAC;AAEjD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,OAAO,mBAAmB,CAAC;CAClC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,CAAC,GAAG,EAAE,IAAI,IAAI;KAClC,CAAC,IAAI,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC;CACxC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,gBAAgB,CAAC,MAAM,SAAS,MAAM,IAAI,MAAM,CAC1D,MAAM,EACN,gBAAgB,CACjB,GACC,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAE3E;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,MAAM,SAAS,YAAY,IAAI,QAAQ,CAC5D,gBAAgB,CAAC,WAAW,CAAC;KAAG,CAAC,IAAI,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC,CAAC,CACzE,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,MAAM,SAAS,YAAY,EAChD,MAAM,EAAE,MAAM,GACb,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAEpC;AAeD;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EACxC,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,GAC3B,MAAM,CAAC,IAAI,GAAG,gBAAgB,EAAE,MAAM,CAAC,CAUzC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAMtB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EACrC,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,EAC5B,OAAO,CAAC,EAAE,MAAM,GACf,IAAI,CAGN"}
|
package/dist/superstruct.d.mts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { Struct } from "@metamask/superstruct";
|
|
2
|
-
import type { Infer, ObjectSchema, OmitBy, Optionalize, PickBy, Simplify } from "@metamask/superstruct";
|
|
3
|
-
declare const ExactOptionalSymbol: unique symbol;
|
|
4
|
-
export type ExactOptionalTag = {
|
|
5
|
-
type: typeof ExactOptionalSymbol;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Exclude type `Type` from the properties of `Obj`.
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* type Foo = { a: string | null; b: number };
|
|
12
|
-
* type Bar = ExcludeType<Foo, null>;
|
|
13
|
-
* // Bar = { a: string, b: number }
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
export type ExcludeType<Obj, Type> = {
|
|
17
|
-
[K in keyof Obj]: Exclude<Obj[K], Type>;
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Make optional all properties that have the `ExactOptionalTag` type.
|
|
21
|
-
*
|
|
22
|
-
* ```ts
|
|
23
|
-
* type Foo = { a: string | ExactOptionalTag; b: number};
|
|
24
|
-
* type Bar = ExactOptionalize<Foo>;
|
|
25
|
-
* // Bar = { a?: string; b: number}
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export type ExactOptionalize<Schema extends object> = OmitBy<Schema, ExactOptionalTag> & Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;
|
|
29
|
-
/**
|
|
30
|
-
* Infer a type from an superstruct object schema.
|
|
31
|
-
*/
|
|
32
|
-
export type ObjectType<Schema extends ObjectSchema> = Simplify<ExactOptionalize<Optionalize<{
|
|
33
|
-
[K in keyof Schema]: Infer<Schema[K]>;
|
|
34
|
-
}>>>;
|
|
35
|
-
/**
|
|
36
|
-
* Change the return type of a superstruct object struct to support exact
|
|
37
|
-
* optional properties.
|
|
38
|
-
*
|
|
39
|
-
* @param schema - The object schema.
|
|
40
|
-
* @returns A struct representing an object with a known set of properties.
|
|
41
|
-
*/
|
|
42
|
-
export declare function object<Schema extends ObjectSchema>(schema: Schema): Struct<ObjectType<Schema>, Schema>;
|
|
43
|
-
/**
|
|
44
|
-
* Augment a struct to allow exact-optional values. Exact-optional values can
|
|
45
|
-
* be omitted but cannot be `undefined`.
|
|
46
|
-
*
|
|
47
|
-
* ```ts
|
|
48
|
-
* const foo = object({ bar: exactOptional(string()) });
|
|
49
|
-
* type Foo = Infer<typeof foo>;
|
|
50
|
-
* // Foo = { bar?: string }
|
|
51
|
-
* ```
|
|
52
|
-
*
|
|
53
|
-
* @param struct - The struct to augment.
|
|
54
|
-
* @returns The augmented struct.
|
|
55
|
-
*/
|
|
56
|
-
export declare function exactOptional<Type, Schema>(struct: Struct<Type, Schema>): Struct<Type | ExactOptionalTag, Schema>;
|
|
57
|
-
/**
|
|
58
|
-
* Defines a new string-struct matching a regular expression.
|
|
59
|
-
*
|
|
60
|
-
* Example:
|
|
61
|
-
*
|
|
62
|
-
* ```ts
|
|
63
|
-
* const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);
|
|
64
|
-
* ```
|
|
65
|
-
*
|
|
66
|
-
* @param name - Type name.
|
|
67
|
-
* @param pattern - Regular expression to match.
|
|
68
|
-
* @returns A new string-struct that matches the given pattern.
|
|
69
|
-
*/
|
|
70
|
-
export declare function definePattern(name: string, pattern: RegExp): Struct<string, null>;
|
|
71
|
-
/**
|
|
72
|
-
* Assert that a value is valid according to a struct.
|
|
73
|
-
*
|
|
74
|
-
* It is similar to superstruct's mask function, but it does not ignore extra
|
|
75
|
-
* properties.
|
|
76
|
-
*
|
|
77
|
-
* @param value - Value to check.
|
|
78
|
-
* @param struct - Struct to validate the value against.
|
|
79
|
-
* @param message - Error message to throw if the value is not valid.
|
|
80
|
-
* @returns The value if it is valid.
|
|
81
|
-
*/
|
|
82
|
-
export declare function strictMask<Type, Schema>(value: unknown, struct: Struct<Type, Schema>, message?: string): Type;
|
|
83
|
-
export {};
|
|
84
|
-
//# sourceMappingURL=superstruct.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"superstruct.d.mts","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EAIP,8BAA8B;AAC/B,OAAO,KAAK,EACV,KAAK,EAEL,YAAY,EACZ,MAAM,EACN,WAAW,EACX,MAAM,EACN,QAAQ,EACT,8BAA8B;AAG/B,OAAO,CAAC,MAAM,mBAAmB,EAAE,OAAO,MAAM,CAAC;AAEjD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,OAAO,mBAAmB,CAAC;CAClC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,CAAC,GAAG,EAAE,IAAI,IAAI;KAClC,CAAC,IAAI,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC;CACxC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,gBAAgB,CAAC,MAAM,SAAS,MAAM,IAAI,MAAM,CAC1D,MAAM,EACN,gBAAgB,CACjB,GACC,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAE3E;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,MAAM,SAAS,YAAY,IAAI,QAAQ,CAC5D,gBAAgB,CAAC,WAAW,CAAC;KAAG,CAAC,IAAI,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC,CAAC,CACzE,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,MAAM,SAAS,YAAY,EAChD,MAAM,EAAE,MAAM,GACb,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAEpC;AAeD;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EACxC,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,GAC3B,MAAM,CAAC,IAAI,GAAG,gBAAgB,EAAE,MAAM,CAAC,CAUzC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAMtB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EACrC,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,EAC5B,OAAO,CAAC,EAAE,MAAM,GACf,IAAI,CAGN"}
|
package/dist/superstruct.mjs
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { Struct, assert, define, object as stObject } from "@metamask/superstruct";
|
|
2
|
-
/**
|
|
3
|
-
* Change the return type of a superstruct object struct to support exact
|
|
4
|
-
* optional properties.
|
|
5
|
-
*
|
|
6
|
-
* @param schema - The object schema.
|
|
7
|
-
* @returns A struct representing an object with a known set of properties.
|
|
8
|
-
*/
|
|
9
|
-
export function object(schema) {
|
|
10
|
-
return stObject(schema);
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Check if the current property is present in its parent object.
|
|
14
|
-
*
|
|
15
|
-
* @param ctx - The context to check.
|
|
16
|
-
* @returns `true` if the property is present, `false` otherwise.
|
|
17
|
-
*/
|
|
18
|
-
function hasOptional(ctx) {
|
|
19
|
-
const property = ctx.path[ctx.path.length - 1];
|
|
20
|
-
const parent = ctx.branch[ctx.branch.length - 2];
|
|
21
|
-
return property in parent;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Augment a struct to allow exact-optional values. Exact-optional values can
|
|
25
|
-
* be omitted but cannot be `undefined`.
|
|
26
|
-
*
|
|
27
|
-
* ```ts
|
|
28
|
-
* const foo = object({ bar: exactOptional(string()) });
|
|
29
|
-
* type Foo = Infer<typeof foo>;
|
|
30
|
-
* // Foo = { bar?: string }
|
|
31
|
-
* ```
|
|
32
|
-
*
|
|
33
|
-
* @param struct - The struct to augment.
|
|
34
|
-
* @returns The augmented struct.
|
|
35
|
-
*/
|
|
36
|
-
export function exactOptional(struct) {
|
|
37
|
-
return new Struct({
|
|
38
|
-
...struct,
|
|
39
|
-
validator: (value, ctx) => !hasOptional(ctx) || struct.validator(value, ctx),
|
|
40
|
-
refiner: (value, ctx) => !hasOptional(ctx) || struct.refiner(value, ctx),
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Defines a new string-struct matching a regular expression.
|
|
45
|
-
*
|
|
46
|
-
* Example:
|
|
47
|
-
*
|
|
48
|
-
* ```ts
|
|
49
|
-
* const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* @param name - Type name.
|
|
53
|
-
* @param pattern - Regular expression to match.
|
|
54
|
-
* @returns A new string-struct that matches the given pattern.
|
|
55
|
-
*/
|
|
56
|
-
export function definePattern(name, pattern) {
|
|
57
|
-
return define(name, (value) => typeof value === 'string' && pattern.test(value));
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Assert that a value is valid according to a struct.
|
|
61
|
-
*
|
|
62
|
-
* It is similar to superstruct's mask function, but it does not ignore extra
|
|
63
|
-
* properties.
|
|
64
|
-
*
|
|
65
|
-
* @param value - Value to check.
|
|
66
|
-
* @param struct - Struct to validate the value against.
|
|
67
|
-
* @param message - Error message to throw if the value is not valid.
|
|
68
|
-
* @returns The value if it is valid.
|
|
69
|
-
*/
|
|
70
|
-
export function strictMask(value, struct, message) {
|
|
71
|
-
assert(value, struct, message);
|
|
72
|
-
return value;
|
|
73
|
-
}
|
|
74
|
-
//# sourceMappingURL=superstruct.mjs.map
|
package/dist/superstruct.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"superstruct.mjs","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,IAAI,QAAQ,EACnB,8BAA8B;AAqD/B;;;;;;GAMG;AACH,MAAM,UAAU,MAAM,CACpB,MAAc;IAEd,OAAO,QAAQ,CAAC,MAAM,CAAQ,CAAC;AACjC,CAAC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAAC,GAAY;IAC/B,MAAM,QAAQ,GAAW,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACvD,MAAM,MAAM,GAA4B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE1E,OAAO,QAAQ,IAAI,MAAM,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAC3B,MAA4B;IAE5B,OAAO,IAAI,MAAM,CAAC;QAChB,GAAG,MAAM;QAET,SAAS,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACxB,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC;QAEnD,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACtB,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAa,EAAE,GAAG,CAAC;KAC1D,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAC3B,IAAY,EACZ,OAAe;IAEf,OAAO,MAAM,CACX,IAAI,EACJ,CAAC,KAAc,EAAW,EAAE,CAC1B,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CACnD,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,UAAU,CACxB,KAAc,EACd,MAA4B,EAC5B,OAAgB;IAEhB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import {\n Struct,\n assert,\n define,\n object as stObject,\n} from '@metamask/superstruct';\nimport type {\n Infer,\n Context,\n ObjectSchema,\n OmitBy,\n Optionalize,\n PickBy,\n Simplify,\n} from '@metamask/superstruct';\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ndeclare const ExactOptionalSymbol: unique symbol;\n\nexport type ExactOptionalTag = {\n type: typeof ExactOptionalSymbol;\n};\n\n/**\n * Exclude type `Type` from the properties of `Obj`.\n *\n * ```ts\n * type Foo = { a: string | null; b: number };\n * type Bar = ExcludeType<Foo, null>;\n * // Bar = { a: string, b: number }\n * ```\n */\nexport type ExcludeType<Obj, Type> = {\n [K in keyof Obj]: Exclude<Obj[K], Type>;\n};\n\n/**\n * Make optional all properties that have the `ExactOptionalTag` type.\n *\n * ```ts\n * type Foo = { a: string | ExactOptionalTag; b: number};\n * type Bar = ExactOptionalize<Foo>;\n * // Bar = { a?: string; b: number}\n * ```\n */\nexport type ExactOptionalize<Schema extends object> = OmitBy<\n Schema,\n ExactOptionalTag\n> &\n Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;\n\n/**\n * Infer a type from an superstruct object schema.\n */\nexport type ObjectType<Schema extends ObjectSchema> = Simplify<\n ExactOptionalize<Optionalize<{ [K in keyof Schema]: Infer<Schema[K]> }>>\n>;\n\n/**\n * Change the return type of a superstruct object struct to support exact\n * optional properties.\n *\n * @param schema - The object schema.\n * @returns A struct representing an object with a known set of properties.\n */\nexport function object<Schema extends ObjectSchema>(\n schema: Schema,\n): Struct<ObjectType<Schema>, Schema> {\n return stObject(schema) as any;\n}\n\n/**\n * Check if the current property is present in its parent object.\n *\n * @param ctx - The context to check.\n * @returns `true` if the property is present, `false` otherwise.\n */\nfunction hasOptional(ctx: Context): boolean {\n const property: string = ctx.path[ctx.path.length - 1];\n const parent: Record<string, unknown> = ctx.branch[ctx.branch.length - 2];\n\n return property in parent;\n}\n\n/**\n * Augment a struct to allow exact-optional values. Exact-optional values can\n * be omitted but cannot be `undefined`.\n *\n * ```ts\n * const foo = object({ bar: exactOptional(string()) });\n * type Foo = Infer<typeof foo>;\n * // Foo = { bar?: string }\n * ```\n *\n * @param struct - The struct to augment.\n * @returns The augmented struct.\n */\nexport function exactOptional<Type, Schema>(\n struct: Struct<Type, Schema>,\n): Struct<Type | ExactOptionalTag, Schema> {\n return new Struct({\n ...struct,\n\n validator: (value, ctx) =>\n !hasOptional(ctx) || struct.validator(value, ctx),\n\n refiner: (value, ctx) =>\n !hasOptional(ctx) || struct.refiner(value as Type, ctx),\n });\n}\n\n/**\n * Defines a new string-struct matching a regular expression.\n *\n * Example:\n *\n * ```ts\n * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);\n * ```\n *\n * @param name - Type name.\n * @param pattern - Regular expression to match.\n * @returns A new string-struct that matches the given pattern.\n */\nexport function definePattern(\n name: string,\n pattern: RegExp,\n): Struct<string, null> {\n return define<string>(\n name,\n (value: unknown): boolean =>\n typeof value === 'string' && pattern.test(value),\n );\n}\n\n/**\n * Assert that a value is valid according to a struct.\n *\n * It is similar to superstruct's mask function, but it does not ignore extra\n * properties.\n *\n * @param value - Value to check.\n * @param struct - Struct to validate the value against.\n * @param message - Error message to throw if the value is not valid.\n * @returns The value if it is valid.\n */\nexport function strictMask<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n message?: string,\n): Type {\n assert(value, struct, message);\n return value;\n}\n"]}
|
package/dist/utils/index.cjs
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./types.cjs"), exports);
|
|
18
|
-
__exportStar(require("./typing.cjs"), exports);
|
|
19
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/utils/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAAwB;AACxB,+CAAyB","sourcesContent":["export * from './types';\nexport * from './typing';\n"]}
|
package/dist/utils/index.d.cts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,6BAAyB"}
|
package/dist/utils/index.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,6BAAyB"}
|
package/dist/utils/index.mjs
DELETED
package/dist/utils/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,6BAAyB","sourcesContent":["export * from './types';\nexport * from './typing';\n"]}
|
package/dist/utils/types.cjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StringNumberStruct = exports.UrlStruct = exports.UuidStruct = void 0;
|
|
4
|
-
const superstruct_1 = require("@metamask/superstruct");
|
|
5
|
-
const superstruct_2 = require("../superstruct.cjs");
|
|
6
|
-
/**
|
|
7
|
-
* UUIDv4 struct.
|
|
8
|
-
*/
|
|
9
|
-
exports.UuidStruct = (0, superstruct_2.definePattern)('UuidV4', /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu);
|
|
10
|
-
/**
|
|
11
|
-
* Validates if a given value is a valid URL.
|
|
12
|
-
*
|
|
13
|
-
* @param value - The value to be validated.
|
|
14
|
-
* @returns A boolean indicating if the value is a valid URL.
|
|
15
|
-
*/
|
|
16
|
-
exports.UrlStruct = (0, superstruct_1.define)('Url', (value) => {
|
|
17
|
-
try {
|
|
18
|
-
const url = new URL(value);
|
|
19
|
-
return url.protocol === 'http:' || url.protocol === 'https:';
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
/**
|
|
26
|
-
* A string which contains a positive float number.
|
|
27
|
-
*/
|
|
28
|
-
exports.StringNumberStruct = (0, superstruct_2.definePattern)('StringNumber', /^\d+(\.\d+)?$/u);
|
|
29
|
-
//# sourceMappingURL=types.cjs.map
|
package/dist/utils/types.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":";;;AAAA,uDAA2D;AAE3D,oDAA+C;AAE/C;;GAEG;AACU,QAAA,UAAU,GAAG,IAAA,2BAAa,EACrC,QAAQ,EACR,yEAAyE,CAC1E,CAAC;AAEF;;;;;GAKG;AACU,QAAA,SAAS,GAAG,IAAA,oBAAM,EAAS,KAAK,EAAE,CAAC,KAAc,EAAE,EAAE;IAChE,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAe,CAAC,CAAC;QACrC,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;IAC/D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,CAAC,CAAC;AAEH;;GAEG;AACU,QAAA,kBAAkB,GAAG,IAAA,2BAAa,EAC7C,cAAc,EACd,gBAAgB,CACjB,CAAC","sourcesContent":["import { define, type Infer } from '@metamask/superstruct';\n\nimport { definePattern } from '../superstruct';\n\n/**\n * UUIDv4 struct.\n */\nexport const UuidStruct = definePattern(\n 'UuidV4',\n /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu,\n);\n\n/**\n * Validates if a given value is a valid URL.\n *\n * @param value - The value to be validated.\n * @returns A boolean indicating if the value is a valid URL.\n */\nexport const UrlStruct = define<string>('Url', (value: unknown) => {\n try {\n const url = new URL(value as string);\n return url.protocol === 'http:' || url.protocol === 'https:';\n } catch {\n return false;\n }\n});\n\n/**\n * A string which contains a positive float number.\n */\nexport const StringNumberStruct = definePattern(\n 'StringNumber',\n /^\\d+(\\.\\d+)?$/u,\n);\nexport type StringNumber = Infer<typeof StringNumberStruct>;\n"]}
|
package/dist/utils/types.d.cts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { type Infer } from "@metamask/superstruct";
|
|
2
|
-
/**
|
|
3
|
-
* UUIDv4 struct.
|
|
4
|
-
*/
|
|
5
|
-
export declare const UuidStruct: import("@metamask/superstruct").Struct<string, null>;
|
|
6
|
-
/**
|
|
7
|
-
* Validates if a given value is a valid URL.
|
|
8
|
-
*
|
|
9
|
-
* @param value - The value to be validated.
|
|
10
|
-
* @returns A boolean indicating if the value is a valid URL.
|
|
11
|
-
*/
|
|
12
|
-
export declare const UrlStruct: import("@metamask/superstruct").Struct<string, null>;
|
|
13
|
-
/**
|
|
14
|
-
* A string which contains a positive float number.
|
|
15
|
-
*/
|
|
16
|
-
export declare const StringNumberStruct: import("@metamask/superstruct").Struct<string, null>;
|
|
17
|
-
export type StringNumber = Infer<typeof StringNumberStruct>;
|
|
18
|
-
//# sourceMappingURL=types.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,KAAK,EAAE,8BAA8B;AAI3D;;GAEG;AACH,eAAO,MAAM,UAAU,sDAGtB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,SAAS,sDAOpB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,kBAAkB,sDAG9B,CAAC;AACF,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
|
package/dist/utils/types.d.mts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { type Infer } from "@metamask/superstruct";
|
|
2
|
-
/**
|
|
3
|
-
* UUIDv4 struct.
|
|
4
|
-
*/
|
|
5
|
-
export declare const UuidStruct: import("@metamask/superstruct").Struct<string, null>;
|
|
6
|
-
/**
|
|
7
|
-
* Validates if a given value is a valid URL.
|
|
8
|
-
*
|
|
9
|
-
* @param value - The value to be validated.
|
|
10
|
-
* @returns A boolean indicating if the value is a valid URL.
|
|
11
|
-
*/
|
|
12
|
-
export declare const UrlStruct: import("@metamask/superstruct").Struct<string, null>;
|
|
13
|
-
/**
|
|
14
|
-
* A string which contains a positive float number.
|
|
15
|
-
*/
|
|
16
|
-
export declare const StringNumberStruct: import("@metamask/superstruct").Struct<string, null>;
|
|
17
|
-
export type StringNumber = Infer<typeof StringNumberStruct>;
|
|
18
|
-
//# sourceMappingURL=types.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,KAAK,EAAE,8BAA8B;AAI3D;;GAEG;AACH,eAAO,MAAM,UAAU,sDAGtB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,SAAS,sDAOpB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,kBAAkB,sDAG9B,CAAC;AACF,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
|
package/dist/utils/types.mjs
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { define } from "@metamask/superstruct";
|
|
2
|
-
import { definePattern } from "../superstruct.mjs";
|
|
3
|
-
/**
|
|
4
|
-
* UUIDv4 struct.
|
|
5
|
-
*/
|
|
6
|
-
export const UuidStruct = definePattern('UuidV4', /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu);
|
|
7
|
-
/**
|
|
8
|
-
* Validates if a given value is a valid URL.
|
|
9
|
-
*
|
|
10
|
-
* @param value - The value to be validated.
|
|
11
|
-
* @returns A boolean indicating if the value is a valid URL.
|
|
12
|
-
*/
|
|
13
|
-
export const UrlStruct = define('Url', (value) => {
|
|
14
|
-
try {
|
|
15
|
-
const url = new URL(value);
|
|
16
|
-
return url.protocol === 'http:' || url.protocol === 'https:';
|
|
17
|
-
}
|
|
18
|
-
catch {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
/**
|
|
23
|
-
* A string which contains a positive float number.
|
|
24
|
-
*/
|
|
25
|
-
export const StringNumberStruct = definePattern('StringNumber', /^\d+(\.\d+)?$/u);
|
|
26
|
-
//# sourceMappingURL=types.mjs.map
|
package/dist/utils/types.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAc,8BAA8B;AAE3D,OAAO,EAAE,aAAa,EAAE,2BAAuB;AAE/C;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CACrC,QAAQ,EACR,yEAAyE,CAC1E,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAS,KAAK,EAAE,CAAC,KAAc,EAAE,EAAE;IAChE,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAe,CAAC,CAAC;QACrC,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;IAC/D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAC7C,cAAc,EACd,gBAAgB,CACjB,CAAC","sourcesContent":["import { define, type Infer } from '@metamask/superstruct';\n\nimport { definePattern } from '../superstruct';\n\n/**\n * UUIDv4 struct.\n */\nexport const UuidStruct = definePattern(\n 'UuidV4',\n /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu,\n);\n\n/**\n * Validates if a given value is a valid URL.\n *\n * @param value - The value to be validated.\n * @returns A boolean indicating if the value is a valid URL.\n */\nexport const UrlStruct = define<string>('Url', (value: unknown) => {\n try {\n const url = new URL(value as string);\n return url.protocol === 'http:' || url.protocol === 'https:';\n } catch {\n return false;\n }\n});\n\n/**\n * A string which contains a positive float number.\n */\nexport const StringNumberStruct = definePattern(\n 'StringNumber',\n /^\\d+(\\.\\d+)?$/u,\n);\nexport type StringNumber = Infer<typeof StringNumberStruct>;\n"]}
|
package/dist/utils/typing.cjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.expectTrue = expectTrue;
|
|
4
|
-
/**
|
|
5
|
-
* Assert that a type extends `true`. It can be used, for example, to assert
|
|
6
|
-
* that a given type extends another type.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* expectTrue<Extends<{a: string, b: string}, {a: string}>>(); // Ok
|
|
11
|
-
* expectTrue<Extends<{a: string}, {a: string, b: string}>>(); // Error
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* This function follows the naming pattern used on `tsd`.
|
|
15
|
-
*/
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
17
|
-
function expectTrue() {
|
|
18
|
-
// Intentionally empty
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=typing.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"typing.cjs","sourceRoot":"","sources":["../../src/utils/typing.ts"],"names":[],"mappings":";;AAoCA,gCAEC;AAfD;;;;;;;;;;;GAWG;AACH,6DAA6D;AAC7D,SAAgB,UAAU;IACxB,sBAAsB;AACxB,CAAC","sourcesContent":["/**\n * Omit keys from a union type.\n *\n * The normal `Omit` type does not distribute over unions. So we use this\n * workaround that applies `Omit` to each member of the union.\n *\n * See: <https://github.com/microsoft/TypeScript/issues/31501#issuecomment-1280579305>\n */\nexport type OmitUnion<Type, Key extends keyof any> = Type extends any\n ? Omit<Type, Key>\n : never;\n\n/**\n * Type that resolves to `true` if `Child` extends `Base`, otherwise `false`.\n *\n * @example\n * ```ts\n * type A = Extends<{a: string, b: string}, {a: string}>; // true\n * type B = Extends<{a: string}, {a: string, b: string}>; // false\n * ```\n */\nexport type Extends<Child, Base> = Child extends Base ? true : false;\n\n/**\n * Assert that a type extends `true`. It can be used, for example, to assert\n * that a given type extends another type.\n *\n * @example\n * ```ts\n * expectTrue<Extends<{a: string, b: string}, {a: string}>>(); // Ok\n * expectTrue<Extends<{a: string}, {a: string, b: string}>>(); // Error\n * ```\n *\n * This function follows the naming pattern used on `tsd`.\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function expectTrue<Type extends true>(): void {\n // Intentionally empty\n}\n"]}
|
package/dist/utils/typing.d.cts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Omit keys from a union type.
|
|
3
|
-
*
|
|
4
|
-
* The normal `Omit` type does not distribute over unions. So we use this
|
|
5
|
-
* workaround that applies `Omit` to each member of the union.
|
|
6
|
-
*
|
|
7
|
-
* See: <https://github.com/microsoft/TypeScript/issues/31501#issuecomment-1280579305>
|
|
8
|
-
*/
|
|
9
|
-
export type OmitUnion<Type, Key extends keyof any> = Type extends any ? Omit<Type, Key> : never;
|
|
10
|
-
/**
|
|
11
|
-
* Type that resolves to `true` if `Child` extends `Base`, otherwise `false`.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* type A = Extends<{a: string, b: string}, {a: string}>; // true
|
|
16
|
-
* type B = Extends<{a: string}, {a: string, b: string}>; // false
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export type Extends<Child, Base> = Child extends Base ? true : false;
|
|
20
|
-
/**
|
|
21
|
-
* Assert that a type extends `true`. It can be used, for example, to assert
|
|
22
|
-
* that a given type extends another type.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* expectTrue<Extends<{a: string, b: string}, {a: string}>>(); // Ok
|
|
27
|
-
* expectTrue<Extends<{a: string}, {a: string, b: string}>>(); // Error
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* This function follows the naming pattern used on `tsd`.
|
|
31
|
-
*/
|
|
32
|
-
export declare function expectTrue<Type extends true>(): void;
|
|
33
|
-
//# sourceMappingURL=typing.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"typing.d.cts","sourceRoot":"","sources":["../../src/utils/typing.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,CAAC,IAAI,EAAE,GAAG,SAAS,MAAM,GAAG,IAAI,IAAI,SAAS,GAAG,GACjE,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,GACf,KAAK,CAAC;AAEV;;;;;;;;GAQG;AACH,MAAM,MAAM,OAAO,CAAC,KAAK,EAAE,IAAI,IAAI,KAAK,SAAS,IAAI,GAAG,IAAI,GAAG,KAAK,CAAC;AAErE;;;;;;;;;;;GAWG;AAEH,wBAAgB,UAAU,CAAC,IAAI,SAAS,IAAI,KAAK,IAAI,CAEpD"}
|
package/dist/utils/typing.d.mts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Omit keys from a union type.
|
|
3
|
-
*
|
|
4
|
-
* The normal `Omit` type does not distribute over unions. So we use this
|
|
5
|
-
* workaround that applies `Omit` to each member of the union.
|
|
6
|
-
*
|
|
7
|
-
* See: <https://github.com/microsoft/TypeScript/issues/31501#issuecomment-1280579305>
|
|
8
|
-
*/
|
|
9
|
-
export type OmitUnion<Type, Key extends keyof any> = Type extends any ? Omit<Type, Key> : never;
|
|
10
|
-
/**
|
|
11
|
-
* Type that resolves to `true` if `Child` extends `Base`, otherwise `false`.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* type A = Extends<{a: string, b: string}, {a: string}>; // true
|
|
16
|
-
* type B = Extends<{a: string}, {a: string, b: string}>; // false
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export type Extends<Child, Base> = Child extends Base ? true : false;
|
|
20
|
-
/**
|
|
21
|
-
* Assert that a type extends `true`. It can be used, for example, to assert
|
|
22
|
-
* that a given type extends another type.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* expectTrue<Extends<{a: string, b: string}, {a: string}>>(); // Ok
|
|
27
|
-
* expectTrue<Extends<{a: string}, {a: string, b: string}>>(); // Error
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* This function follows the naming pattern used on `tsd`.
|
|
31
|
-
*/
|
|
32
|
-
export declare function expectTrue<Type extends true>(): void;
|
|
33
|
-
//# sourceMappingURL=typing.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"typing.d.mts","sourceRoot":"","sources":["../../src/utils/typing.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,CAAC,IAAI,EAAE,GAAG,SAAS,MAAM,GAAG,IAAI,IAAI,SAAS,GAAG,GACjE,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,GACf,KAAK,CAAC;AAEV;;;;;;;;GAQG;AACH,MAAM,MAAM,OAAO,CAAC,KAAK,EAAE,IAAI,IAAI,KAAK,SAAS,IAAI,GAAG,IAAI,GAAG,KAAK,CAAC;AAErE;;;;;;;;;;;GAWG;AAEH,wBAAgB,UAAU,CAAC,IAAI,SAAS,IAAI,KAAK,IAAI,CAEpD"}
|
package/dist/utils/typing.mjs
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Assert that a type extends `true`. It can be used, for example, to assert
|
|
3
|
-
* that a given type extends another type.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* expectTrue<Extends<{a: string, b: string}, {a: string}>>(); // Ok
|
|
8
|
-
* expectTrue<Extends<{a: string}, {a: string, b: string}>>(); // Error
|
|
9
|
-
* ```
|
|
10
|
-
*
|
|
11
|
-
* This function follows the naming pattern used on `tsd`.
|
|
12
|
-
*/
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
14
|
-
export function expectTrue() {
|
|
15
|
-
// Intentionally empty
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=typing.mjs.map
|