@metamask/snaps-utils 4.0.1 → 5.0.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.
@@ -1,6 +1,6 @@
1
- import type { Failure, Infer } from 'superstruct';
1
+ import type { Failure } from 'superstruct';
2
2
  import { Struct, StructError } from 'superstruct';
3
- import type { AnyStruct, InferStructTuple } from 'superstruct/dist/utils';
3
+ import type { AnyStruct } from 'superstruct/dist/utils';
4
4
  /**
5
5
  * Infer a struct type, only if it matches the specified type. This is useful
6
6
  * for defining types and structs that are related to each other in separate
@@ -24,44 +24,6 @@ import type { AnyStruct, InferStructTuple } from 'superstruct/dist/utils';
24
24
  * ```
25
25
  */
26
26
  export declare type InferMatching<StructType extends Struct<any, any>, Type> = StructType['TYPE'] extends Type ? Type : never;
27
- /**
28
- * A wrapper of `superstruct`'s `literal` struct that also defines the name of
29
- * the struct as the literal value.
30
- *
31
- * This is useful for improving the error messages returned by `superstruct`.
32
- * For example, instead of returning an error like:
33
- *
34
- * ```
35
- * Expected the value to satisfy a union of `literal | literal`, but received: \"baz\"
36
- * ```
37
- *
38
- * This struct will return an error like:
39
- *
40
- * ```
41
- * Expected the value to satisfy a union of `"foo" | "bar"`, but received: \"baz\"
42
- * ```
43
- *
44
- * @param value - The literal value.
45
- * @returns The `superstruct` struct, which validates that the value is equal
46
- * to the literal value.
47
- */
48
- export declare function literal<Type extends string | number | boolean>(value: Type): Struct<Type, null>;
49
- /**
50
- * A wrapper of `superstruct`'s `union` struct that also defines the schema as
51
- * the union of the schemas of the structs.
52
- *
53
- * This is useful for improving the error messages returned by `superstruct`.
54
- *
55
- * @param structs - The structs to union.
56
- * @param structs."0" - The first struct.
57
- * @param structs."1" - The remaining structs.
58
- * @returns The `superstruct` struct, which validates that the value satisfies
59
- * one of the structs.
60
- */
61
- export declare function union<Head extends AnyStruct, Tail extends AnyStruct[]>([head, ...tail]: [head: Head, ...tail: Tail]): Struct<Infer<Head> | InferStructTuple<Tail>[number], [
62
- head: Head,
63
- ...tail: Tail
64
- ]>;
65
27
  /**
66
28
  * A wrapper of `superstruct`'s `string` struct that coerces a value to a string
67
29
  * and resolves it relative to the current working directory. This is useful
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-utils",
3
- "version": "4.0.1",
3
+ "version": "5.0.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/MetaMask/snaps.git"
@@ -69,11 +69,11 @@
69
69
  "@babel/types": "^7.23.0",
70
70
  "@metamask/base-controller": "^3.2.0",
71
71
  "@metamask/key-tree": "^9.0.0",
72
- "@metamask/permission-controller": "^5.0.0",
72
+ "@metamask/permission-controller": "^5.0.1",
73
73
  "@metamask/rpc-errors": "^6.1.0",
74
74
  "@metamask/snaps-registry": "^2.1.0",
75
- "@metamask/snaps-sdk": "^1.1.0",
76
- "@metamask/utils": "^8.1.0",
75
+ "@metamask/snaps-sdk": "^1.2.0",
76
+ "@metamask/utils": "^8.2.1",
77
77
  "@noble/hashes": "^1.3.1",
78
78
  "@scure/base": "^1.1.1",
79
79
  "chalk": "^4.1.2",
package/dist/cjs/enum.js DELETED
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "enumValue", {
6
- enumerable: true,
7
- get: function() {
8
- return enumValue;
9
- }
10
- });
11
- const _structs = require("./structs");
12
- function enumValue(constant) {
13
- return (0, _structs.literal)(constant);
14
- }
15
-
16
- //# sourceMappingURL=enum.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/enum.ts"],"sourcesContent":["import type { EnumToUnion } from '@metamask/snaps-sdk';\nimport type { Struct } from 'superstruct';\n\nimport { literal } from './structs';\n\n/**\n * Superstruct struct for validating an enum value. This allows using both the\n * enum string values and the enum itself as values.\n *\n * @param constant - The enum to validate against.\n * @returns The superstruct struct.\n */\nexport function enumValue<Type extends string>(\n constant: Type,\n): Struct<EnumToUnion<Type>, null> {\n return literal(constant as EnumToUnion<Type>);\n}\n"],"names":["enumValue","constant","literal"],"mappings":";;;;+BAYgBA;;;eAAAA;;;yBATQ;AASjB,SAASA,UACdC,QAAc;IAEd,OAAOC,IAAAA,gBAAO,EAACD;AACjB"}
package/dist/esm/enum.js DELETED
@@ -1,12 +0,0 @@
1
- import { literal } from './structs';
2
- /**
3
- * Superstruct struct for validating an enum value. This allows using both the
4
- * enum string values and the enum itself as values.
5
- *
6
- * @param constant - The enum to validate against.
7
- * @returns The superstruct struct.
8
- */ export function enumValue(constant) {
9
- return literal(constant);
10
- }
11
-
12
- //# sourceMappingURL=enum.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/enum.ts"],"sourcesContent":["import type { EnumToUnion } from '@metamask/snaps-sdk';\nimport type { Struct } from 'superstruct';\n\nimport { literal } from './structs';\n\n/**\n * Superstruct struct for validating an enum value. This allows using both the\n * enum string values and the enum itself as values.\n *\n * @param constant - The enum to validate against.\n * @returns The superstruct struct.\n */\nexport function enumValue<Type extends string>(\n constant: Type,\n): Struct<EnumToUnion<Type>, null> {\n return literal(constant as EnumToUnion<Type>);\n}\n"],"names":["literal","enumValue","constant"],"mappings":"AAGA,SAASA,OAAO,QAAQ,YAAY;AAEpC;;;;;;CAMC,GACD,OAAO,SAASC,UACdC,QAAc;IAEd,OAAOF,QAAQE;AACjB"}
@@ -1,10 +0,0 @@
1
- import type { EnumToUnion } from '@metamask/snaps-sdk';
2
- import type { Struct } from 'superstruct';
3
- /**
4
- * Superstruct struct for validating an enum value. This allows using both the
5
- * enum string values and the enum itself as values.
6
- *
7
- * @param constant - The enum to validate against.
8
- * @returns The superstruct struct.
9
- */
10
- export declare function enumValue<Type extends string>(constant: Type): Struct<EnumToUnion<Type>, null>;