@metamask-previews/keyring-utils 3.3.1-52bd218 → 3.3.1-5951828
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/CHANGELOG.md +5 -0
- package/dist/JsonRpcRequest.cjs +2 -3
- package/dist/JsonRpcRequest.cjs.map +1 -1
- package/dist/JsonRpcRequest.d.cts +1 -1
- package/dist/JsonRpcRequest.d.cts.map +1 -1
- package/dist/JsonRpcRequest.d.mts +1 -1
- package/dist/JsonRpcRequest.d.mts.map +1 -1
- package/dist/JsonRpcRequest.mjs +1 -2
- package/dist/JsonRpcRequest.mjs.map +1 -1
- package/dist/superstruct.cjs +1 -56
- package/dist/superstruct.cjs.map +1 -1
- package/dist/superstruct.d.cts +1 -65
- package/dist/superstruct.d.cts.map +1 -1
- package/dist/superstruct.d.mts +1 -65
- package/dist/superstruct.d.mts.map +1 -1
- package/dist/superstruct.mjs +1 -53
- package/dist/superstruct.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Removed
|
|
11
|
+
|
|
12
|
+
- **BREAKING:** Removed `object`, `type` and `exactOptional` superstruct support ([#580](https://github.com/MetaMask/accounts/pull/580))
|
|
13
|
+
- Use `@metamask/superstruct` instead.
|
|
14
|
+
|
|
10
15
|
## [3.3.1]
|
|
11
16
|
|
|
12
17
|
### Fixed
|
package/dist/JsonRpcRequest.cjs
CHANGED
|
@@ -3,11 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.JsonRpcRequestStruct = void 0;
|
|
4
4
|
const superstruct_1 = require("@metamask/superstruct");
|
|
5
5
|
const utils_1 = require("@metamask/utils");
|
|
6
|
-
|
|
7
|
-
exports.JsonRpcRequestStruct = (0, _1.object)({
|
|
6
|
+
exports.JsonRpcRequestStruct = (0, superstruct_1.object)({
|
|
8
7
|
jsonrpc: (0, superstruct_1.literal)('2.0'),
|
|
9
8
|
id: (0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.number)(), (0, superstruct_1.literal)(null)]),
|
|
10
9
|
method: (0, superstruct_1.string)(),
|
|
11
|
-
params: (0,
|
|
10
|
+
params: (0, superstruct_1.exactOptional)((0, superstruct_1.union)([(0, superstruct_1.array)(utils_1.JsonStruct), (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct)])),
|
|
12
11
|
});
|
|
13
12
|
//# sourceMappingURL=JsonRpcRequest.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonRpcRequest.cjs","sourceRoot":"","sources":["../src/JsonRpcRequest.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"JsonRpcRequest.cjs","sourceRoot":"","sources":["../src/JsonRpcRequest.ts"],"names":[],"mappings":";;;AAAA,uDAS+B;AAE/B,2CAA6C;AAEhC,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EAAC;IACzC,OAAO,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;IACvB,EAAE,EAAE,IAAA,mBAAK,EAAC,CAAC,IAAA,oBAAM,GAAE,EAAE,IAAA,oBAAM,GAAE,EAAE,IAAA,qBAAO,EAAC,IAAI,CAAC,CAAC,CAAC;IAC9C,MAAM,EAAE,IAAA,oBAAM,GAAE;IAChB,MAAM,EAAE,IAAA,2BAAa,EACnB,IAAA,mBAAK,EAAC,CAAC,IAAA,mBAAK,EAAC,kBAAU,CAAC,EAAE,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC,CAAC,CAAC,CACzD;CACF,CAAC,CAAC","sourcesContent":["import {\n array,\n exactOptional,\n literal,\n number,\n object,\n record,\n string,\n union,\n} from '@metamask/superstruct';\nimport type { Infer } from '@metamask/superstruct';\nimport { JsonStruct } from '@metamask/utils';\n\nexport const JsonRpcRequestStruct = object({\n jsonrpc: literal('2.0'),\n id: union([string(), number(), literal(null)]),\n method: string(),\n params: exactOptional(\n union([array(JsonStruct), record(string(), JsonStruct)]),\n ),\n});\n\n/**\n * JSON-RPC request type.\n */\nexport type JsonRpcRequest = Infer<typeof JsonRpcRequestStruct>;\n"]}
|
|
@@ -8,7 +8,7 @@ export declare const JsonRpcRequestStruct: import("@metamask/superstruct").Struc
|
|
|
8
8
|
jsonrpc: import("@metamask/superstruct").Struct<"2.0", "2.0">;
|
|
9
9
|
id: import("@metamask/superstruct").Struct<string | number | null, null>;
|
|
10
10
|
method: import("@metamask/superstruct").Struct<string, null>;
|
|
11
|
-
params: import("@metamask/superstruct").
|
|
11
|
+
params: import("@metamask/superstruct").ExactOptionalStruct<Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[], null>;
|
|
12
12
|
}>;
|
|
13
13
|
/**
|
|
14
14
|
* JSON-RPC request type.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonRpcRequest.d.cts","sourceRoot":"","sources":["../src/JsonRpcRequest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"JsonRpcRequest.d.cts","sourceRoot":"","sources":["../src/JsonRpcRequest.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAGnD,eAAO,MAAM,oBAAoB;;;;;;;;;;EAO/B,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
|
|
@@ -8,7 +8,7 @@ export declare const JsonRpcRequestStruct: import("@metamask/superstruct").Struc
|
|
|
8
8
|
jsonrpc: import("@metamask/superstruct").Struct<"2.0", "2.0">;
|
|
9
9
|
id: import("@metamask/superstruct").Struct<string | number | null, null>;
|
|
10
10
|
method: import("@metamask/superstruct").Struct<string, null>;
|
|
11
|
-
params: import("@metamask/superstruct").
|
|
11
|
+
params: import("@metamask/superstruct").ExactOptionalStruct<Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[], null>;
|
|
12
12
|
}>;
|
|
13
13
|
/**
|
|
14
14
|
* JSON-RPC request type.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonRpcRequest.d.mts","sourceRoot":"","sources":["../src/JsonRpcRequest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"JsonRpcRequest.d.mts","sourceRoot":"","sources":["../src/JsonRpcRequest.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAGnD,eAAO,MAAM,oBAAoB;;;;;;;;;;EAO/B,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
|
package/dist/JsonRpcRequest.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { array, literal, number, record, string, union } from "@metamask/superstruct";
|
|
1
|
+
import { array, exactOptional, literal, number, object, record, string, union } from "@metamask/superstruct";
|
|
2
2
|
import { JsonStruct } from "@metamask/utils";
|
|
3
|
-
import { exactOptional, object } from "./index.mjs";
|
|
4
3
|
export const JsonRpcRequestStruct = object({
|
|
5
4
|
jsonrpc: literal('2.0'),
|
|
6
5
|
id: union([string(), number(), literal(null)]),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonRpcRequest.mjs","sourceRoot":"","sources":["../src/JsonRpcRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,OAAO,EACP,MAAM,EACN,MAAM,EACN,MAAM,EACN,KAAK,EACN,8BAA8B;AAE/B,OAAO,EAAE,UAAU,EAAE,wBAAwB;AAE7C,
|
|
1
|
+
{"version":3,"file":"JsonRpcRequest.mjs","sourceRoot":"","sources":["../src/JsonRpcRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,aAAa,EACb,OAAO,EACP,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,KAAK,EACN,8BAA8B;AAE/B,OAAO,EAAE,UAAU,EAAE,wBAAwB;AAE7C,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC;IACzC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC;IACvB,EAAE,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9C,MAAM,EAAE,MAAM,EAAE;IAChB,MAAM,EAAE,aAAa,CACnB,KAAK,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC,CACzD;CACF,CAAC,CAAC","sourcesContent":["import {\n array,\n exactOptional,\n literal,\n number,\n object,\n record,\n string,\n union,\n} from '@metamask/superstruct';\nimport type { Infer } from '@metamask/superstruct';\nimport { JsonStruct } from '@metamask/utils';\n\nexport const JsonRpcRequestStruct = object({\n jsonrpc: literal('2.0'),\n id: union([string(), number(), literal(null)]),\n method: string(),\n params: exactOptional(\n union([array(JsonStruct), record(string(), JsonStruct)]),\n ),\n});\n\n/**\n * JSON-RPC request type.\n */\nexport type JsonRpcRequest = Infer<typeof JsonRpcRequestStruct>;\n"]}
|
package/dist/superstruct.cjs
CHANGED
|
@@ -1,62 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.selectiveUnion = exports.strictMask =
|
|
3
|
+
exports.selectiveUnion = exports.strictMask = void 0;
|
|
4
4
|
const superstruct_1 = require("@metamask/superstruct");
|
|
5
|
-
/**
|
|
6
|
-
* Change the return type of a superstruct's `object` function to support
|
|
7
|
-
* exact optional properties.
|
|
8
|
-
*
|
|
9
|
-
* @param schema - The object schema.
|
|
10
|
-
* @returns A struct representing an object with a known set of properties.
|
|
11
|
-
*/
|
|
12
|
-
function object(schema) {
|
|
13
|
-
return (0, superstruct_1.object)(schema);
|
|
14
|
-
}
|
|
15
|
-
exports.object = object;
|
|
16
|
-
/**
|
|
17
|
-
* Change the return type of a superstruct's `type` function to support
|
|
18
|
-
* exact optional properties.
|
|
19
|
-
*
|
|
20
|
-
* @param schema - The object schema.
|
|
21
|
-
* @returns A struct representing an object with a known set of properties
|
|
22
|
-
* and ignore unknown properties.
|
|
23
|
-
*/
|
|
24
|
-
function type(schema) {
|
|
25
|
-
return (0, superstruct_1.type)(schema);
|
|
26
|
-
}
|
|
27
|
-
exports.type = type;
|
|
28
|
-
/**
|
|
29
|
-
* Check if the current property is present in its parent object.
|
|
30
|
-
*
|
|
31
|
-
* @param ctx - The context to check.
|
|
32
|
-
* @returns `true` if the property is present, `false` otherwise.
|
|
33
|
-
*/
|
|
34
|
-
function hasOptional(ctx) {
|
|
35
|
-
const property = ctx.path[ctx.path.length - 1];
|
|
36
|
-
const parent = ctx.branch[ctx.branch.length - 2];
|
|
37
|
-
return property in parent;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Augment a struct to allow exact-optional values. Exact-optional values can
|
|
41
|
-
* be omitted but cannot be `undefined`.
|
|
42
|
-
*
|
|
43
|
-
* ```ts
|
|
44
|
-
* const foo = object({ bar: exactOptional(string()) });
|
|
45
|
-
* type Foo = Infer<typeof foo>;
|
|
46
|
-
* // Foo = { bar?: string }
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* @param struct - The struct to augment.
|
|
50
|
-
* @returns The augmented struct.
|
|
51
|
-
*/
|
|
52
|
-
function exactOptional(struct) {
|
|
53
|
-
return new superstruct_1.Struct({
|
|
54
|
-
...struct,
|
|
55
|
-
validator: (value, ctx) => !hasOptional(ctx) || struct.validator(value, ctx),
|
|
56
|
-
refiner: (value, ctx) => !hasOptional(ctx) || struct.refiner(value, ctx),
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
exports.exactOptional = exactOptional;
|
|
60
5
|
/**
|
|
61
6
|
* Assert that a value is valid according to a struct.
|
|
62
7
|
*
|
package/dist/superstruct.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"superstruct.cjs","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"superstruct.cjs","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":";;;AAAA,uDAAuD;AAKvD;;;;;;;;;;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;AAPD,gCAOC;AAcD;;;;;;;GAOG;AACH,SAAgB,cAAc,CAC5B,QAAkB;IAElB,OAAO,IAAI,oBAAM,CAAC;QAChB,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,IAAI;QAEZ,CAAC,OAAO,CAAC,KAAU,EAAE,OAAY;YAC/B,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACjD,CAAC;QAED,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO;YACrB,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACjD,CAAC;QAED,OAAO,CAAC,KAAK,EAAE,OAAO;YACpB,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACjD,CAAC;QAED,SAAS,CAAC,KAAK,EAAE,OAAO;YACtB,uEAAuE;YACvE,YAAY;YACZ,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACnD,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAzBD,wCAyBC","sourcesContent":["import { Struct, assert } from '@metamask/superstruct';\nimport type { Infer, AnyStruct } from '@metamask/superstruct';\n\nimport type { Equals } from './types';\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\n/**\n * Extracts the type from a struct definition and asserts that it matches the\n * expected type. If the types do not match, the type `never` is returned.\n *\n * @param StructType - The struct type to infer.\n * @param ExpectedType - The expected type.\n */\nexport type InferEquals<StructType extends Struct<any, any>, ExpectedType> =\n Equals<Infer<StructType>, ExpectedType> extends true\n ? Infer<StructType>\n : never;\n\n/**\n * Create a custom union struct that uses a `selector` function for choosing\n * the validation path.\n *\n * @param selector - The selector function choosing the struct to validate with.\n * @returns The `superstruct` struct, which validates that the value satisfies\n * one of the structs.\n */\nexport function selectiveUnion<Selector extends (value: any) => AnyStruct>(\n selector: Selector,\n): Struct<Infer<ReturnType<Selector>>, null> {\n return new Struct({\n type: 'union',\n schema: null,\n\n *entries(value: any, context: any): ReturnType<Struct['entries']> {\n yield* selector(value).entries(value, context);\n },\n\n *refiner(value, context): ReturnType<Struct['refiner']> {\n yield* selector(value).refiner(value, context);\n },\n\n coercer(value, context): ReturnType<Struct['coercer']> {\n return selector(value).coercer(value, context);\n },\n\n validator(value, context): ReturnType<Struct['validator']> {\n // This only validates the root of the struct, entries does the rest of\n // the work.\n return selector(value).validator(value, context);\n },\n });\n}\n"]}
|
package/dist/superstruct.d.cts
CHANGED
|
@@ -1,69 +1,6 @@
|
|
|
1
1
|
import { Struct } from "@metamask/superstruct";
|
|
2
|
-
import type { Infer,
|
|
2
|
+
import type { Infer, AnyStruct } from "@metamask/superstruct";
|
|
3
3
|
import type { Equals } from "./types.cjs";
|
|
4
|
-
declare const ExactOptionalSymbol: unique symbol;
|
|
5
|
-
export type ExactOptionalTag = {
|
|
6
|
-
type: typeof ExactOptionalSymbol;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Exclude type `Type` from the properties of `Obj`.
|
|
10
|
-
*
|
|
11
|
-
* ```ts
|
|
12
|
-
* type Foo = { a: string | null; b: number };
|
|
13
|
-
* type Bar = ExcludeType<Foo, null>;
|
|
14
|
-
* // Bar = { a: string, b: number }
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export type ExcludeType<Obj, Type> = {
|
|
18
|
-
[K in keyof Obj]: Exclude<Obj[K], Type>;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Make optional all properties that have the `ExactOptionalTag` type.
|
|
22
|
-
*
|
|
23
|
-
* ```ts
|
|
24
|
-
* type Foo = { a: string | ExactOptionalTag; b: number};
|
|
25
|
-
* type Bar = ExactOptionalize<Foo>;
|
|
26
|
-
* // Bar = { a?: string; b: number}
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
export type ExactOptionalize<Schema extends object> = OmitBy<Schema, ExactOptionalTag> & Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;
|
|
30
|
-
/**
|
|
31
|
-
* Infer a type from an superstruct object schema.
|
|
32
|
-
*/
|
|
33
|
-
export type ObjectType<Schema extends ObjectSchema> = Simplify<ExactOptionalize<Optionalize<{
|
|
34
|
-
[K in keyof Schema]: Infer<Schema[K]>;
|
|
35
|
-
}>>>;
|
|
36
|
-
/**
|
|
37
|
-
* Change the return type of a superstruct's `object` function to support
|
|
38
|
-
* exact optional properties.
|
|
39
|
-
*
|
|
40
|
-
* @param schema - The object schema.
|
|
41
|
-
* @returns A struct representing an object with a known set of properties.
|
|
42
|
-
*/
|
|
43
|
-
export declare function object<Schema extends ObjectSchema>(schema: Schema): Struct<ObjectType<Schema>, Schema>;
|
|
44
|
-
/**
|
|
45
|
-
* Change the return type of a superstruct's `type` function to support
|
|
46
|
-
* exact optional properties.
|
|
47
|
-
*
|
|
48
|
-
* @param schema - The object schema.
|
|
49
|
-
* @returns A struct representing an object with a known set of properties
|
|
50
|
-
* and ignore unknown properties.
|
|
51
|
-
*/
|
|
52
|
-
export declare function type<Schema extends ObjectSchema>(schema: Schema): Struct<ObjectType<Schema>, Schema>;
|
|
53
|
-
/**
|
|
54
|
-
* Augment a struct to allow exact-optional values. Exact-optional values can
|
|
55
|
-
* be omitted but cannot be `undefined`.
|
|
56
|
-
*
|
|
57
|
-
* ```ts
|
|
58
|
-
* const foo = object({ bar: exactOptional(string()) });
|
|
59
|
-
* type Foo = Infer<typeof foo>;
|
|
60
|
-
* // Foo = { bar?: string }
|
|
61
|
-
* ```
|
|
62
|
-
*
|
|
63
|
-
* @param struct - The struct to augment.
|
|
64
|
-
* @returns The augmented struct.
|
|
65
|
-
*/
|
|
66
|
-
export declare function exactOptional<Type, Schema>(struct: Struct<Type, Schema>): Struct<Type | ExactOptionalTag, Schema>;
|
|
67
4
|
/**
|
|
68
5
|
* Assert that a value is valid according to a struct.
|
|
69
6
|
*
|
|
@@ -93,5 +30,4 @@ export type InferEquals<StructType extends Struct<any, any>, ExpectedType> = Equ
|
|
|
93
30
|
* one of the structs.
|
|
94
31
|
*/
|
|
95
32
|
export declare function selectiveUnion<Selector extends (value: any) => AnyStruct>(selector: Selector): Struct<Infer<ReturnType<Selector>>, null>;
|
|
96
|
-
export {};
|
|
97
33
|
//# sourceMappingURL=superstruct.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"superstruct.d.cts","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"superstruct.d.cts","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,8BAA8B;AACvD,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,8BAA8B;AAE9D,OAAO,KAAK,EAAE,MAAM,EAAE,oBAAgB;AAEtC;;;;;;;;;;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;AAED;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,CAAC,UAAU,SAAS,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,YAAY,IACvE,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,YAAY,CAAC,SAAS,IAAI,GAChD,KAAK,CAAC,UAAU,CAAC,GACjB,KAAK,CAAC;AAEZ;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,QAAQ,SAAS,CAAC,KAAK,EAAE,GAAG,KAAK,SAAS,EACvE,QAAQ,EAAE,QAAQ,GACjB,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,CAuB3C"}
|
package/dist/superstruct.d.mts
CHANGED
|
@@ -1,69 +1,6 @@
|
|
|
1
1
|
import { Struct } from "@metamask/superstruct";
|
|
2
|
-
import type { Infer,
|
|
2
|
+
import type { Infer, AnyStruct } from "@metamask/superstruct";
|
|
3
3
|
import type { Equals } from "./types.mjs";
|
|
4
|
-
declare const ExactOptionalSymbol: unique symbol;
|
|
5
|
-
export type ExactOptionalTag = {
|
|
6
|
-
type: typeof ExactOptionalSymbol;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Exclude type `Type` from the properties of `Obj`.
|
|
10
|
-
*
|
|
11
|
-
* ```ts
|
|
12
|
-
* type Foo = { a: string | null; b: number };
|
|
13
|
-
* type Bar = ExcludeType<Foo, null>;
|
|
14
|
-
* // Bar = { a: string, b: number }
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export type ExcludeType<Obj, Type> = {
|
|
18
|
-
[K in keyof Obj]: Exclude<Obj[K], Type>;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Make optional all properties that have the `ExactOptionalTag` type.
|
|
22
|
-
*
|
|
23
|
-
* ```ts
|
|
24
|
-
* type Foo = { a: string | ExactOptionalTag; b: number};
|
|
25
|
-
* type Bar = ExactOptionalize<Foo>;
|
|
26
|
-
* // Bar = { a?: string; b: number}
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
export type ExactOptionalize<Schema extends object> = OmitBy<Schema, ExactOptionalTag> & Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;
|
|
30
|
-
/**
|
|
31
|
-
* Infer a type from an superstruct object schema.
|
|
32
|
-
*/
|
|
33
|
-
export type ObjectType<Schema extends ObjectSchema> = Simplify<ExactOptionalize<Optionalize<{
|
|
34
|
-
[K in keyof Schema]: Infer<Schema[K]>;
|
|
35
|
-
}>>>;
|
|
36
|
-
/**
|
|
37
|
-
* Change the return type of a superstruct's `object` function to support
|
|
38
|
-
* exact optional properties.
|
|
39
|
-
*
|
|
40
|
-
* @param schema - The object schema.
|
|
41
|
-
* @returns A struct representing an object with a known set of properties.
|
|
42
|
-
*/
|
|
43
|
-
export declare function object<Schema extends ObjectSchema>(schema: Schema): Struct<ObjectType<Schema>, Schema>;
|
|
44
|
-
/**
|
|
45
|
-
* Change the return type of a superstruct's `type` function to support
|
|
46
|
-
* exact optional properties.
|
|
47
|
-
*
|
|
48
|
-
* @param schema - The object schema.
|
|
49
|
-
* @returns A struct representing an object with a known set of properties
|
|
50
|
-
* and ignore unknown properties.
|
|
51
|
-
*/
|
|
52
|
-
export declare function type<Schema extends ObjectSchema>(schema: Schema): Struct<ObjectType<Schema>, Schema>;
|
|
53
|
-
/**
|
|
54
|
-
* Augment a struct to allow exact-optional values. Exact-optional values can
|
|
55
|
-
* be omitted but cannot be `undefined`.
|
|
56
|
-
*
|
|
57
|
-
* ```ts
|
|
58
|
-
* const foo = object({ bar: exactOptional(string()) });
|
|
59
|
-
* type Foo = Infer<typeof foo>;
|
|
60
|
-
* // Foo = { bar?: string }
|
|
61
|
-
* ```
|
|
62
|
-
*
|
|
63
|
-
* @param struct - The struct to augment.
|
|
64
|
-
* @returns The augmented struct.
|
|
65
|
-
*/
|
|
66
|
-
export declare function exactOptional<Type, Schema>(struct: Struct<Type, Schema>): Struct<Type | ExactOptionalTag, Schema>;
|
|
67
4
|
/**
|
|
68
5
|
* Assert that a value is valid according to a struct.
|
|
69
6
|
*
|
|
@@ -93,5 +30,4 @@ export type InferEquals<StructType extends Struct<any, any>, ExpectedType> = Equ
|
|
|
93
30
|
* one of the structs.
|
|
94
31
|
*/
|
|
95
32
|
export declare function selectiveUnion<Selector extends (value: any) => AnyStruct>(selector: Selector): Struct<Infer<ReturnType<Selector>>, null>;
|
|
96
|
-
export {};
|
|
97
33
|
//# sourceMappingURL=superstruct.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"superstruct.d.mts","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"superstruct.d.mts","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,8BAA8B;AACvD,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,8BAA8B;AAE9D,OAAO,KAAK,EAAE,MAAM,EAAE,oBAAgB;AAEtC;;;;;;;;;;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;AAED;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,CAAC,UAAU,SAAS,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,YAAY,IACvE,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,YAAY,CAAC,SAAS,IAAI,GAChD,KAAK,CAAC,UAAU,CAAC,GACjB,KAAK,CAAC;AAEZ;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,QAAQ,SAAS,CAAC,KAAK,EAAE,GAAG,KAAK,SAAS,EACvE,QAAQ,EAAE,QAAQ,GACjB,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,CAuB3C"}
|
package/dist/superstruct.mjs
CHANGED
|
@@ -1,56 +1,4 @@
|
|
|
1
|
-
import { Struct, assert
|
|
2
|
-
/**
|
|
3
|
-
* Change the return type of a superstruct's `object` function to support
|
|
4
|
-
* exact 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
|
-
* Change the return type of a superstruct's `type` function to support
|
|
14
|
-
* exact optional properties.
|
|
15
|
-
*
|
|
16
|
-
* @param schema - The object schema.
|
|
17
|
-
* @returns A struct representing an object with a known set of properties
|
|
18
|
-
* and ignore unknown properties.
|
|
19
|
-
*/
|
|
20
|
-
export function type(schema) {
|
|
21
|
-
return stType(schema);
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Check if the current property is present in its parent object.
|
|
25
|
-
*
|
|
26
|
-
* @param ctx - The context to check.
|
|
27
|
-
* @returns `true` if the property is present, `false` otherwise.
|
|
28
|
-
*/
|
|
29
|
-
function hasOptional(ctx) {
|
|
30
|
-
const property = ctx.path[ctx.path.length - 1];
|
|
31
|
-
const parent = ctx.branch[ctx.branch.length - 2];
|
|
32
|
-
return property in parent;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Augment a struct to allow exact-optional values. Exact-optional values can
|
|
36
|
-
* be omitted but cannot be `undefined`.
|
|
37
|
-
*
|
|
38
|
-
* ```ts
|
|
39
|
-
* const foo = object({ bar: exactOptional(string()) });
|
|
40
|
-
* type Foo = Infer<typeof foo>;
|
|
41
|
-
* // Foo = { bar?: string }
|
|
42
|
-
* ```
|
|
43
|
-
*
|
|
44
|
-
* @param struct - The struct to augment.
|
|
45
|
-
* @returns The augmented struct.
|
|
46
|
-
*/
|
|
47
|
-
export function exactOptional(struct) {
|
|
48
|
-
return new Struct({
|
|
49
|
-
...struct,
|
|
50
|
-
validator: (value, ctx) => !hasOptional(ctx) || struct.validator(value, ctx),
|
|
51
|
-
refiner: (value, ctx) => !hasOptional(ctx) || struct.refiner(value, ctx),
|
|
52
|
-
});
|
|
53
|
-
}
|
|
1
|
+
import { Struct, assert } from "@metamask/superstruct";
|
|
54
2
|
/**
|
|
55
3
|
* Assert that a value is valid according to a struct.
|
|
56
4
|
*
|
package/dist/superstruct.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"superstruct.mjs","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"superstruct.mjs","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,8BAA8B;AAKvD;;;;;;;;;;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;AAcD;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAC5B,QAAkB;IAElB,OAAO,IAAI,MAAM,CAAC;QAChB,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,IAAI;QAEZ,CAAC,OAAO,CAAC,KAAU,EAAE,OAAY;YAC/B,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACjD,CAAC;QAED,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO;YACrB,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACjD,CAAC;QAED,OAAO,CAAC,KAAK,EAAE,OAAO;YACpB,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACjD,CAAC;QAED,SAAS,CAAC,KAAK,EAAE,OAAO;YACtB,uEAAuE;YACvE,YAAY;YACZ,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACnD,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { Struct, assert } from '@metamask/superstruct';\nimport type { Infer, AnyStruct } from '@metamask/superstruct';\n\nimport type { Equals } from './types';\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\n/**\n * Extracts the type from a struct definition and asserts that it matches the\n * expected type. If the types do not match, the type `never` is returned.\n *\n * @param StructType - The struct type to infer.\n * @param ExpectedType - The expected type.\n */\nexport type InferEquals<StructType extends Struct<any, any>, ExpectedType> =\n Equals<Infer<StructType>, ExpectedType> extends true\n ? Infer<StructType>\n : never;\n\n/**\n * Create a custom union struct that uses a `selector` function for choosing\n * the validation path.\n *\n * @param selector - The selector function choosing the struct to validate with.\n * @returns The `superstruct` struct, which validates that the value satisfies\n * one of the structs.\n */\nexport function selectiveUnion<Selector extends (value: any) => AnyStruct>(\n selector: Selector,\n): Struct<Infer<ReturnType<Selector>>, null> {\n return new Struct({\n type: 'union',\n schema: null,\n\n *entries(value: any, context: any): ReturnType<Struct['entries']> {\n yield* selector(value).entries(value, context);\n },\n\n *refiner(value, context): ReturnType<Struct['refiner']> {\n yield* selector(value).refiner(value, context);\n },\n\n coercer(value, context): ReturnType<Struct['coercer']> {\n return selector(value).coercer(value, context);\n },\n\n validator(value, context): ReturnType<Struct['validator']> {\n // This only validates the root of the struct, entries does the rest of\n // the work.\n return selector(value).validator(value, context);\n },\n });\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/keyring-utils",
|
|
3
|
-
"version": "3.3.1-
|
|
3
|
+
"version": "3.3.1-5951828",
|
|
4
4
|
"description": "MetaMask Keyring utils",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"keyring",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@ethereumjs/tx": "^5.4.0",
|
|
59
|
-
"@metamask/superstruct": "^3.
|
|
59
|
+
"@metamask/superstruct": "^3.3.0",
|
|
60
60
|
"@metamask/utils": "^11.11.0",
|
|
61
61
|
"bitcoin-address-validation": "^2.2.3"
|
|
62
62
|
},
|