@metamask-previews/keyring-utils 0.0.1-preview-46bb5ff → 1.0.0-4685a87

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.
Files changed (47) hide show
  1. package/CHANGELOG.md +10 -1
  2. package/dist/JsonRpcRequest.cjs +13 -0
  3. package/dist/JsonRpcRequest.cjs.map +1 -0
  4. package/dist/JsonRpcRequest.d.cts +17 -0
  5. package/dist/JsonRpcRequest.d.cts.map +1 -0
  6. package/dist/JsonRpcRequest.d.mts +17 -0
  7. package/dist/JsonRpcRequest.d.mts.map +1 -0
  8. package/dist/JsonRpcRequest.mjs +10 -0
  9. package/dist/JsonRpcRequest.mjs.map +1 -0
  10. package/dist/{index.js → index.cjs} +5 -4
  11. package/dist/index.cjs.map +1 -0
  12. package/dist/index.d.cts +5 -0
  13. package/dist/index.d.cts.map +1 -0
  14. package/dist/index.d.mts +5 -0
  15. package/dist/index.d.mts.map +1 -0
  16. package/dist/index.mjs +5 -0
  17. package/dist/index.mjs.map +1 -0
  18. package/dist/{superstruct.js → superstruct.cjs} +34 -6
  19. package/dist/superstruct.cjs.map +1 -0
  20. package/dist/{superstruct.d.ts → superstruct.d.cts} +25 -6
  21. package/dist/superstruct.d.cts.map +1 -0
  22. package/dist/superstruct.d.mts +102 -0
  23. package/dist/superstruct.d.mts.map +1 -0
  24. package/dist/superstruct.mjs +102 -0
  25. package/dist/superstruct.mjs.map +1 -0
  26. package/dist/{types.js → types.cjs} +3 -3
  27. package/dist/types.cjs.map +1 -0
  28. package/dist/types.d.cts +42 -0
  29. package/dist/types.d.cts.map +1 -0
  30. package/dist/types.d.mts +42 -0
  31. package/dist/types.d.mts.map +1 -0
  32. package/dist/types.mjs +26 -0
  33. package/dist/types.mjs.map +1 -0
  34. package/dist/{typing.js → typing.cjs} +2 -3
  35. package/dist/{typing.js.map → typing.cjs.map} +1 -1
  36. package/dist/{typing.d.ts → typing.d.cts} +3 -2
  37. package/dist/typing.d.cts.map +1 -0
  38. package/dist/typing.d.mts +33 -0
  39. package/dist/typing.d.mts.map +1 -0
  40. package/dist/typing.mjs +17 -0
  41. package/dist/typing.mjs.map +1 -0
  42. package/package.json +30 -19
  43. package/dist/index.d.ts +0 -3
  44. package/dist/index.js.map +0 -1
  45. package/dist/superstruct.js.map +0 -1
  46. package/dist/types.d.ts +0 -17
  47. package/dist/types.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -7,4 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
- [Unreleased]: https://github.com/MetaMask/accounts/
10
+ ## [1.0.0]
11
+
12
+ ### Changed
13
+
14
+ - Use `ts-bridge/cli@0.6.1` ([#118](https://github.com/MetaMask/accounts/pull/118))
15
+ - This new version fixes a bug with CJS re-exports.
16
+ - Initial release ([#24](https://github.com/MetaMask/accounts/pull/24))
17
+
18
+ [Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-utils@1.0.0...HEAD
19
+ [1.0.0]: https://github.com/MetaMask/accounts/releases/tag/@metamask/keyring-utils@1.0.0
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JsonRpcRequestStruct = void 0;
4
+ const superstruct_1 = require("@metamask/superstruct");
5
+ const utils_1 = require("@metamask/utils");
6
+ const _1 = require("./index.cjs");
7
+ exports.JsonRpcRequestStruct = (0, _1.object)({
8
+ jsonrpc: (0, superstruct_1.literal)('2.0'),
9
+ id: (0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.number)(), (0, superstruct_1.literal)(null)]),
10
+ method: (0, superstruct_1.string)(),
11
+ params: (0, _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
+ });
13
+ //# sourceMappingURL=JsonRpcRequest.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonRpcRequest.cjs","sourceRoot":"","sources":["../src/JsonRpcRequest.ts"],"names":[],"mappings":";;;AAAA,uDAO+B;AAE/B,2CAA6C;AAE7C,kCAA0C;AAE7B,QAAA,oBAAoB,GAAG,IAAA,SAAM,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,gBAAa,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 literal,\n number,\n record,\n string,\n union,\n} from '@metamask/superstruct';\nimport type { Infer } from '@metamask/superstruct';\nimport { JsonStruct } from '@metamask/utils';\n\nimport { exactOptional, object } from '.';\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"]}
@@ -0,0 +1,17 @@
1
+ import type { Infer } from "@metamask/superstruct";
2
+ export declare const JsonRpcRequestStruct: import("@metamask/superstruct").Struct<{
3
+ method: string;
4
+ id: string | number | null;
5
+ jsonrpc: "2.0";
6
+ params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[];
7
+ }, {
8
+ jsonrpc: import("@metamask/superstruct").Struct<"2.0", "2.0">;
9
+ id: import("@metamask/superstruct").Struct<string | number | null, null>;
10
+ method: import("@metamask/superstruct").Struct<string, null>;
11
+ params: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | import("./superstruct.cjs").ExactOptionalTag, null>;
12
+ }>;
13
+ /**
14
+ * JSON-RPC request type.
15
+ */
16
+ export type JsonRpcRequest = Infer<typeof JsonRpcRequestStruct>;
17
+ //# sourceMappingURL=JsonRpcRequest.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonRpcRequest.d.cts","sourceRoot":"","sources":["../src/JsonRpcRequest.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAKnD,eAAO,MAAM,oBAAoB;;;;;;;;;;EAO/B,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { Infer } from "@metamask/superstruct";
2
+ export declare const JsonRpcRequestStruct: import("@metamask/superstruct").Struct<{
3
+ method: string;
4
+ id: string | number | null;
5
+ jsonrpc: "2.0";
6
+ params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[];
7
+ }, {
8
+ jsonrpc: import("@metamask/superstruct").Struct<"2.0", "2.0">;
9
+ id: import("@metamask/superstruct").Struct<string | number | null, null>;
10
+ method: import("@metamask/superstruct").Struct<string, null>;
11
+ params: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | import("./superstruct.mjs").ExactOptionalTag, null>;
12
+ }>;
13
+ /**
14
+ * JSON-RPC request type.
15
+ */
16
+ export type JsonRpcRequest = Infer<typeof JsonRpcRequestStruct>;
17
+ //# sourceMappingURL=JsonRpcRequest.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonRpcRequest.d.mts","sourceRoot":"","sources":["../src/JsonRpcRequest.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAKnD,eAAO,MAAM,oBAAoB;;;;;;;;;;EAO/B,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { array, literal, number, record, string, union } from "@metamask/superstruct";
2
+ import { JsonStruct } from "@metamask/utils";
3
+ import { exactOptional, object } from "./index.mjs";
4
+ export const JsonRpcRequestStruct = object({
5
+ jsonrpc: literal('2.0'),
6
+ id: union([string(), number(), literal(null)]),
7
+ method: string(),
8
+ params: exactOptional(union([array(JsonStruct), record(string(), JsonStruct)])),
9
+ });
10
+ //# sourceMappingURL=JsonRpcRequest.mjs.map
@@ -0,0 +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,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,oBAAU;AAE1C,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 literal,\n number,\n record,\n string,\n union,\n} from '@metamask/superstruct';\nimport type { Infer } from '@metamask/superstruct';\nimport { JsonStruct } from '@metamask/utils';\n\nimport { exactOptional, object } from '.';\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"]}
@@ -14,7 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./types"), exports);
18
- __exportStar(require("./typing"), exports);
19
- __exportStar(require("./superstruct"), exports);
20
- //# sourceMappingURL=index.js.map
17
+ __exportStar(require("./types.cjs"), exports);
18
+ __exportStar(require("./typing.cjs"), exports);
19
+ __exportStar(require("./superstruct.cjs"), exports);
20
+ __exportStar(require("./JsonRpcRequest.cjs"), exports);
21
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAAwB;AACxB,+CAAyB;AACzB,oDAA8B;AAC9B,uDAAiC","sourcesContent":["export * from './types';\nexport * from './typing';\nexport * from './superstruct';\nexport * from './JsonRpcRequest';\n"]}
@@ -0,0 +1,5 @@
1
+ export * from "./types.cjs";
2
+ export * from "./typing.cjs";
3
+ export * from "./superstruct.cjs";
4
+ export * from "./JsonRpcRequest.cjs";
5
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,6BAAyB;AACzB,kCAA8B;AAC9B,qCAAiC"}
@@ -0,0 +1,5 @@
1
+ export * from "./types.mjs";
2
+ export * from "./typing.mjs";
3
+ export * from "./superstruct.mjs";
4
+ export * from "./JsonRpcRequest.mjs";
5
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,6BAAyB;AACzB,kCAA8B;AAC9B,qCAAiC"}
package/dist/index.mjs ADDED
@@ -0,0 +1,5 @@
1
+ export * from "./types.mjs";
2
+ export * from "./typing.mjs";
3
+ export * from "./superstruct.mjs";
4
+ export * from "./JsonRpcRequest.mjs";
5
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,6BAAyB;AACzB,kCAA8B;AAC9B,qCAAiC","sourcesContent":["export * from './types';\nexport * from './typing';\nexport * from './superstruct';\nexport * from './JsonRpcRequest';\n"]}
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.strictMask = exports.definePattern = exports.exactOptional = exports.object = void 0;
3
+ exports.object = object;
4
+ exports.exactOptional = exactOptional;
5
+ exports.definePattern = definePattern;
6
+ exports.strictMask = strictMask;
7
+ exports.selectiveUnion = selectiveUnion;
4
8
  const superstruct_1 = require("@metamask/superstruct");
5
9
  /**
6
10
  * Change the return type of a superstruct object struct to support exact
@@ -12,7 +16,6 @@ const superstruct_1 = require("@metamask/superstruct");
12
16
  function object(schema) {
13
17
  return (0, superstruct_1.object)(schema);
14
18
  }
15
- exports.object = object;
16
19
  /**
17
20
  * Check if the current property is present in its parent object.
18
21
  *
@@ -44,7 +47,6 @@ function exactOptional(struct) {
44
47
  refiner: (value, ctx) => !hasOptional(ctx) || struct.refiner(value, ctx),
45
48
  });
46
49
  }
47
- exports.exactOptional = exactOptional;
48
50
  /**
49
51
  * Defines a new string-struct matching a regular expression.
50
52
  *
@@ -61,7 +63,6 @@ exports.exactOptional = exactOptional;
61
63
  function definePattern(name, pattern) {
62
64
  return (0, superstruct_1.define)(name, (value) => typeof value === 'string' && pattern.test(value));
63
65
  }
64
- exports.definePattern = definePattern;
65
66
  /**
66
67
  * Assert that a value is valid according to a struct.
67
68
  *
@@ -77,5 +78,32 @@ function strictMask(value, struct, message) {
77
78
  (0, superstruct_1.assert)(value, struct, message);
78
79
  return value;
79
80
  }
80
- exports.strictMask = strictMask;
81
- //# sourceMappingURL=superstruct.js.map
81
+ /**
82
+ * Create a custom union struct that uses a `selector` function for choosing
83
+ * the validation path.
84
+ *
85
+ * @param selector - The selector function choosing the struct to validate with.
86
+ * @returns The `superstruct` struct, which validates that the value satisfies
87
+ * one of the structs.
88
+ */
89
+ function selectiveUnion(selector) {
90
+ return new superstruct_1.Struct({
91
+ type: 'union',
92
+ schema: null,
93
+ *entries(value, context) {
94
+ yield* selector(value).entries(value, context);
95
+ },
96
+ *refiner(value, context) {
97
+ yield* selector(value).refiner(value, context);
98
+ },
99
+ coercer(value, context) {
100
+ return selector(value).coercer(value, context);
101
+ },
102
+ validator(value, context) {
103
+ // This only validates the root of the struct, entries does the rest of
104
+ // the work.
105
+ return selector(value).validator(value, context);
106
+ },
107
+ });
108
+ }
109
+ //# sourceMappingURL=superstruct.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"superstruct.cjs","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":";;AAoEA,wBAIC;AA4BD,sCAYC;AAeD,sCASC;AAaD,gCAOC;AAwBD,wCAyBC;AA7MD,uDAK+B;AAwD/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;AAgBD;;;;;;;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","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 AnyStruct,\n} from '@metamask/superstruct';\n\nimport type { Equals } from './types';\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\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<\n StructType extends Struct<any, any>,\n 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"]}
@@ -1,7 +1,8 @@
1
- import { Struct } from '@metamask/superstruct';
2
- import type { Infer, ObjectSchema, OmitBy, Optionalize, PickBy, Simplify } from '@metamask/superstruct';
1
+ import { Struct } from "@metamask/superstruct";
2
+ import type { Infer, ObjectSchema, OmitBy, Optionalize, PickBy, Simplify, AnyStruct } from "@metamask/superstruct";
3
+ import type { Equals } from "./types.cjs";
3
4
  declare const ExactOptionalSymbol: unique symbol;
4
- export declare type ExactOptionalTag = {
5
+ export type ExactOptionalTag = {
5
6
  type: typeof ExactOptionalSymbol;
6
7
  };
7
8
  /**
@@ -13,7 +14,7 @@ export declare type ExactOptionalTag = {
13
14
  * // Bar = { a: string, b: number }
14
15
  * ```
15
16
  */
16
- export declare type ExcludeType<Obj, Type> = {
17
+ export type ExcludeType<Obj, Type> = {
17
18
  [K in keyof Obj]: Exclude<Obj[K], Type>;
18
19
  };
19
20
  /**
@@ -25,11 +26,11 @@ export declare type ExcludeType<Obj, Type> = {
25
26
  * // Bar = { a?: string; b: number}
26
27
  * ```
27
28
  */
28
- export declare type ExactOptionalize<Schema extends object> = OmitBy<Schema, ExactOptionalTag> & Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;
29
+ export type ExactOptionalize<Schema extends object> = OmitBy<Schema, ExactOptionalTag> & Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;
29
30
  /**
30
31
  * Infer a type from an superstruct object schema.
31
32
  */
32
- export declare type ObjectType<Schema extends ObjectSchema> = Simplify<ExactOptionalize<Optionalize<{
33
+ export type ObjectType<Schema extends ObjectSchema> = Simplify<ExactOptionalize<Optionalize<{
33
34
  [K in keyof Schema]: Infer<Schema[K]>;
34
35
  }>>>;
35
36
  /**
@@ -80,4 +81,22 @@ export declare function definePattern(name: string, pattern: RegExp): Struct<str
80
81
  * @returns The value if it is valid.
81
82
  */
82
83
  export declare function strictMask<Type, Schema>(value: unknown, struct: Struct<Type, Schema>, message?: string): Type;
84
+ /**
85
+ * Extracts the type from a struct definition and asserts that it matches the
86
+ * expected type. If the types do not match, the type `never` is returned.
87
+ *
88
+ * @param StructType - The struct type to infer.
89
+ * @param ExpectedType - The expected type.
90
+ */
91
+ export type InferEquals<StructType extends Struct<any, any>, ExpectedType> = Equals<Infer<StructType>, ExpectedType> extends true ? Infer<StructType> : never;
92
+ /**
93
+ * Create a custom union struct that uses a `selector` function for choosing
94
+ * the validation path.
95
+ *
96
+ * @param selector - The selector function choosing the struct to validate with.
97
+ * @returns The `superstruct` struct, which validates that the value satisfies
98
+ * one of the structs.
99
+ */
100
+ export declare function selectiveUnion<Selector extends (value: any) => AnyStruct>(selector: Selector): Struct<Infer<ReturnType<Selector>>, null>;
83
101
  export {};
102
+ //# sourceMappingURL=superstruct.d.cts.map
@@ -0,0 +1 @@
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,EACR,SAAS,EACV,8BAA8B;AAE/B,OAAO,KAAK,EAAE,MAAM,EAAE,oBAAgB;AAGtC,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;AAED;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,CACrB,UAAU,SAAS,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EACnC,YAAY,IACV,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,YAAY,CAAC,SAAS,IAAI,GACpD,KAAK,CAAC,UAAU,CAAC,GACjB,KAAK,CAAC;AAEV;;;;;;;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"}
@@ -0,0 +1,102 @@
1
+ import { Struct } from "@metamask/superstruct";
2
+ import type { Infer, ObjectSchema, OmitBy, Optionalize, PickBy, Simplify, AnyStruct } from "@metamask/superstruct";
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 object struct to support exact
38
+ * 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
+ * Augment a struct to allow exact-optional values. Exact-optional values can
46
+ * be omitted but cannot be `undefined`.
47
+ *
48
+ * ```ts
49
+ * const foo = object({ bar: exactOptional(string()) });
50
+ * type Foo = Infer<typeof foo>;
51
+ * // Foo = { bar?: string }
52
+ * ```
53
+ *
54
+ * @param struct - The struct to augment.
55
+ * @returns The augmented struct.
56
+ */
57
+ export declare function exactOptional<Type, Schema>(struct: Struct<Type, Schema>): Struct<Type | ExactOptionalTag, Schema>;
58
+ /**
59
+ * Defines a new string-struct matching a regular expression.
60
+ *
61
+ * Example:
62
+ *
63
+ * ```ts
64
+ * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);
65
+ * ```
66
+ *
67
+ * @param name - Type name.
68
+ * @param pattern - Regular expression to match.
69
+ * @returns A new string-struct that matches the given pattern.
70
+ */
71
+ export declare function definePattern(name: string, pattern: RegExp): Struct<string, null>;
72
+ /**
73
+ * Assert that a value is valid according to a struct.
74
+ *
75
+ * It is similar to superstruct's mask function, but it does not ignore extra
76
+ * properties.
77
+ *
78
+ * @param value - Value to check.
79
+ * @param struct - Struct to validate the value against.
80
+ * @param message - Error message to throw if the value is not valid.
81
+ * @returns The value if it is valid.
82
+ */
83
+ export declare function strictMask<Type, Schema>(value: unknown, struct: Struct<Type, Schema>, message?: string): Type;
84
+ /**
85
+ * Extracts the type from a struct definition and asserts that it matches the
86
+ * expected type. If the types do not match, the type `never` is returned.
87
+ *
88
+ * @param StructType - The struct type to infer.
89
+ * @param ExpectedType - The expected type.
90
+ */
91
+ export type InferEquals<StructType extends Struct<any, any>, ExpectedType> = Equals<Infer<StructType>, ExpectedType> extends true ? Infer<StructType> : never;
92
+ /**
93
+ * Create a custom union struct that uses a `selector` function for choosing
94
+ * the validation path.
95
+ *
96
+ * @param selector - The selector function choosing the struct to validate with.
97
+ * @returns The `superstruct` struct, which validates that the value satisfies
98
+ * one of the structs.
99
+ */
100
+ export declare function selectiveUnion<Selector extends (value: any) => AnyStruct>(selector: Selector): Struct<Infer<ReturnType<Selector>>, null>;
101
+ export {};
102
+ //# sourceMappingURL=superstruct.d.mts.map
@@ -0,0 +1 @@
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,EACR,SAAS,EACV,8BAA8B;AAE/B,OAAO,KAAK,EAAE,MAAM,EAAE,oBAAgB;AAGtC,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;AAED;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,CACrB,UAAU,SAAS,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EACnC,YAAY,IACV,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,YAAY,CAAC,SAAS,IAAI,GACpD,KAAK,CAAC,UAAU,CAAC,GACjB,KAAK,CAAC;AAEV;;;;;;;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"}
@@ -0,0 +1,102 @@
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
+ /**
75
+ * Create a custom union struct that uses a `selector` function for choosing
76
+ * the validation path.
77
+ *
78
+ * @param selector - The selector function choosing the struct to validate with.
79
+ * @returns The `superstruct` struct, which validates that the value satisfies
80
+ * one of the structs.
81
+ */
82
+ export function selectiveUnion(selector) {
83
+ return new Struct({
84
+ type: 'union',
85
+ schema: null,
86
+ *entries(value, context) {
87
+ yield* selector(value).entries(value, context);
88
+ },
89
+ *refiner(value, context) {
90
+ yield* selector(value).refiner(value, context);
91
+ },
92
+ coercer(value, context) {
93
+ return selector(value).coercer(value, context);
94
+ },
95
+ validator(value, context) {
96
+ // This only validates the root of the struct, entries does the rest of
97
+ // the work.
98
+ return selector(value).validator(value, context);
99
+ },
100
+ });
101
+ }
102
+ //# sourceMappingURL=superstruct.mjs.map
@@ -0,0 +1 @@
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;AAwD/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;AAgBD;;;;;;;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 {\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 AnyStruct,\n} from '@metamask/superstruct';\n\nimport type { Equals } from './types';\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\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<\n StructType extends Struct<any, any>,\n 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"]}
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StringNumberStruct = exports.UrlStruct = exports.UuidStruct = void 0;
4
4
  const superstruct_1 = require("@metamask/superstruct");
5
- const superstruct_2 = require("./superstruct");
5
+ const superstruct_2 = require("./superstruct.cjs");
6
6
  /**
7
7
  * UUIDv4 struct.
8
8
  */
@@ -18,7 +18,7 @@ exports.UrlStruct = (0, superstruct_1.define)('Url', (value) => {
18
18
  const url = new URL(value);
19
19
  return url.protocol === 'http:' || url.protocol === 'https:';
20
20
  }
21
- catch (_) {
21
+ catch {
22
22
  return false;
23
23
  }
24
24
  });
@@ -26,4 +26,4 @@ exports.UrlStruct = (0, superstruct_1.define)('Url', (value) => {
26
26
  * A string which contains a positive float number.
27
27
  */
28
28
  exports.StringNumberStruct = (0, superstruct_2.definePattern)('StringNumber', /^\d+(\.\d+)?$/u);
29
- //# sourceMappingURL=types.js.map
29
+ //# sourceMappingURL=types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA,uDAA2D;AAE3D,mDAA8C;AAE9C;;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\n/**\n * This is a helper type used by the {@link Equals} type.\n */\ntype EqualsHelper<Type> = <Dummy>() => Dummy extends Type ? 1 : 2;\n\n/**\n * A utility type that checks whether two types are exactly the same.\n *\n * This type evaluates to `true` if `TypeA` and `TypeB` are identical,\n * otherwise it evaluates to `false`.\n *\n * @template TypeA - The first type to compare.\n * @template TypeB - The second type to compare.\n *\n * @example\n * ```ts\n * // Example usage:\n * type Test1 = Equals<number, number>; // true\n * type Test2 = Equals<number, string>; // false\n * type Test3 = Equals<{ a: string }, { a: string }>; // true\n * type Test4 = Equals<{ a: string }, { a: number }>; // false\n * ```\n */\nexport type Equals<TypeA, TypeB> =\n EqualsHelper<TypeA> extends EqualsHelper<TypeB> ? true : false;\n"]}
@@ -0,0 +1,42 @@
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
+ /**
19
+ * This is a helper type used by the {@link Equals} type.
20
+ */
21
+ type EqualsHelper<Type> = <Dummy>() => Dummy extends Type ? 1 : 2;
22
+ /**
23
+ * A utility type that checks whether two types are exactly the same.
24
+ *
25
+ * This type evaluates to `true` if `TypeA` and `TypeB` are identical,
26
+ * otherwise it evaluates to `false`.
27
+ *
28
+ * @template TypeA - The first type to compare.
29
+ * @template TypeB - The second type to compare.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * // Example usage:
34
+ * type Test1 = Equals<number, number>; // true
35
+ * type Test2 = Equals<number, string>; // false
36
+ * type Test3 = Equals<{ a: string }, { a: string }>; // true
37
+ * type Test4 = Equals<{ a: string }, { a: number }>; // false
38
+ * ```
39
+ */
40
+ export type Equals<TypeA, TypeB> = EqualsHelper<TypeA> extends EqualsHelper<TypeB> ? true : false;
41
+ export {};
42
+ //# sourceMappingURL=types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/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;AAE5D;;GAEG;AACH,KAAK,YAAY,CAAC,IAAI,IAAI,CAAC,KAAK,OAAO,KAAK,SAAS,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;AAElE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,MAAM,CAAC,KAAK,EAAE,KAAK,IAC7B,YAAY,CAAC,KAAK,CAAC,SAAS,YAAY,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC"}
@@ -0,0 +1,42 @@
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
+ /**
19
+ * This is a helper type used by the {@link Equals} type.
20
+ */
21
+ type EqualsHelper<Type> = <Dummy>() => Dummy extends Type ? 1 : 2;
22
+ /**
23
+ * A utility type that checks whether two types are exactly the same.
24
+ *
25
+ * This type evaluates to `true` if `TypeA` and `TypeB` are identical,
26
+ * otherwise it evaluates to `false`.
27
+ *
28
+ * @template TypeA - The first type to compare.
29
+ * @template TypeB - The second type to compare.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * // Example usage:
34
+ * type Test1 = Equals<number, number>; // true
35
+ * type Test2 = Equals<number, string>; // false
36
+ * type Test3 = Equals<{ a: string }, { a: string }>; // true
37
+ * type Test4 = Equals<{ a: string }, { a: number }>; // false
38
+ * ```
39
+ */
40
+ export type Equals<TypeA, TypeB> = EqualsHelper<TypeA> extends EqualsHelper<TypeB> ? true : false;
41
+ export {};
42
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/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;AAE5D;;GAEG;AACH,KAAK,YAAY,CAAC,IAAI,IAAI,CAAC,KAAK,OAAO,KAAK,SAAS,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;AAElE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,MAAM,CAAC,KAAK,EAAE,KAAK,IAC7B,YAAY,CAAC,KAAK,CAAC,SAAS,YAAY,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC"}
package/dist/types.mjs ADDED
@@ -0,0 +1,26 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAc,8BAA8B;AAE3D,OAAO,EAAE,aAAa,EAAE,0BAAsB;AAE9C;;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\n/**\n * This is a helper type used by the {@link Equals} type.\n */\ntype EqualsHelper<Type> = <Dummy>() => Dummy extends Type ? 1 : 2;\n\n/**\n * A utility type that checks whether two types are exactly the same.\n *\n * This type evaluates to `true` if `TypeA` and `TypeB` are identical,\n * otherwise it evaluates to `false`.\n *\n * @template TypeA - The first type to compare.\n * @template TypeB - The second type to compare.\n *\n * @example\n * ```ts\n * // Example usage:\n * type Test1 = Equals<number, number>; // true\n * type Test2 = Equals<number, string>; // false\n * type Test3 = Equals<{ a: string }, { a: string }>; // true\n * type Test4 = Equals<{ a: string }, { a: number }>; // false\n * ```\n */\nexport type Equals<TypeA, TypeB> =\n EqualsHelper<TypeA> extends EqualsHelper<TypeB> ? true : false;\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.expectTrue = void 0;
3
+ exports.expectTrue = expectTrue;
4
4
  /**
5
5
  * Assert that a type extends `true`. It can be used, for example, to assert
6
6
  * that a given type extends another type.
@@ -17,5 +17,4 @@ exports.expectTrue = void 0;
17
17
  function expectTrue() {
18
18
  // Intentionally empty
19
19
  }
20
- exports.expectTrue = expectTrue;
21
- //# sourceMappingURL=typing.js.map
20
+ //# sourceMappingURL=typing.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"typing.js","sourceRoot":"","sources":["../src/typing.ts"],"names":[],"mappings":";;;AAuBA;;;;;;;;;;;GAWG;AACH,6DAA6D;AAC7D,SAAgB,UAAU;IACxB,sBAAsB;AACxB,CAAC;AAFD,gCAEC","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"]}
1
+ {"version":3,"file":"typing.cjs","sourceRoot":"","sources":["../src/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"]}
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * See: <https://github.com/microsoft/TypeScript/issues/31501#issuecomment-1280579305>
8
8
  */
9
- export declare type OmitUnion<Type, Key extends keyof any> = Type extends any ? Omit<Type, Key> : never;
9
+ export type OmitUnion<Type, Key extends keyof any> = Type extends any ? Omit<Type, Key> : never;
10
10
  /**
11
11
  * Type that resolves to `true` if `Child` extends `Base`, otherwise `false`.
12
12
  *
@@ -16,7 +16,7 @@ export declare type OmitUnion<Type, Key extends keyof any> = Type extends any ?
16
16
  * type B = Extends<{a: string}, {a: string, b: string}>; // false
17
17
  * ```
18
18
  */
19
- export declare type Extends<Child, Base> = Child extends Base ? true : false;
19
+ export type Extends<Child, Base> = Child extends Base ? true : false;
20
20
  /**
21
21
  * Assert that a type extends `true`. It can be used, for example, to assert
22
22
  * that a given type extends another type.
@@ -30,3 +30,4 @@ export declare type Extends<Child, Base> = Child extends Base ? true : false;
30
30
  * This function follows the naming pattern used on `tsd`.
31
31
  */
32
32
  export declare function expectTrue<Type extends true>(): void;
33
+ //# sourceMappingURL=typing.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typing.d.cts","sourceRoot":"","sources":["../src/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"}
@@ -0,0 +1,33 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typing.d.mts","sourceRoot":"","sources":["../src/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"}
@@ -0,0 +1,17 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typing.mjs","sourceRoot":"","sources":["../src/typing.ts"],"names":[],"mappings":"AAuBA;;;;;;;;;;;GAWG;AACH,6DAA6D;AAC7D,MAAM,UAAU,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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/keyring-utils",
3
- "version": "0.0.1-preview-46bb5ff",
3
+ "version": "1.0.0-4685a87",
4
4
  "description": "MetaMask Keyring utils",
5
5
  "keywords": [
6
6
  "metamask",
@@ -14,49 +14,57 @@
14
14
  "type": "git",
15
15
  "url": "https://github.com/MetaMask/accounts.git"
16
16
  },
17
- "main": "./dist/index.js",
18
- "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "import": {
20
+ "types": "./dist/index.d.mts",
21
+ "default": "./dist/index.mjs"
22
+ },
23
+ "require": {
24
+ "types": "./dist/index.d.cts",
25
+ "default": "./dist/index.cjs"
26
+ }
27
+ }
28
+ },
29
+ "main": "./dist/index.cjs",
30
+ "types": "./dist/index.d.cts",
19
31
  "files": [
20
32
  "dist/"
21
33
  ],
22
34
  "scripts": {
23
- "build": "tsc --build tsconfig.build.json",
24
- "build:clean": "rimraf dist && yarn build",
35
+ "build": "ts-bridge --project tsconfig.build.json --no-references",
36
+ "build:clean": "yarn build --clean",
25
37
  "build:docs": "typedoc",
26
- "build:force": "tsc --build tsconfig.build.json --force",
27
38
  "changelog:update": "../../scripts/update-changelog.sh @metamask/keyring-utils",
28
39
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/keyring-utils",
29
40
  "publish:preview": "yarn npm publish --tag preview",
30
41
  "test": "yarn test:source && yarn test:types",
31
42
  "test:clean": "jest --clearCache",
32
43
  "test:source": "jest && jest-it-up",
33
- "test:types": "tsd",
34
- "test:verbose": "jest --verbose",
44
+ "test:types": "../../scripts/tsd-test.sh ./src",
35
45
  "test:watch": "jest --watch"
36
46
  },
37
47
  "dependencies": {
38
48
  "@metamask/superstruct": "^3.1.0",
39
- "@metamask/utils": "^9.1.0",
40
- "@types/uuid": "^9.0.8",
41
- "deepmerge": "^4.2.2",
42
- "uuid": "^9.0.1"
49
+ "@metamask/utils": "^9.3.0"
43
50
  },
44
51
  "devDependencies": {
45
- "@lavamoat/allow-scripts": "^3.0.4",
46
- "@lavamoat/preinstall-always-fail": "^2.0.0",
52
+ "@lavamoat/allow-scripts": "^3.2.1",
53
+ "@lavamoat/preinstall-always-fail": "^2.1.0",
47
54
  "@metamask/auto-changelog": "^3.4.4",
48
- "@metamask/providers": "^17.1.1",
55
+ "@ts-bridge/cli": "^0.6.1",
49
56
  "@types/jest": "^29.5.12",
50
57
  "@types/node": "^20.12.12",
58
+ "deepmerge": "^4.2.2",
51
59
  "depcheck": "^1.4.7",
52
- "jest": "^28.1.3",
60
+ "jest": "^29.5.0",
53
61
  "jest-it-up": "^3.1.0",
54
62
  "rimraf": "^5.0.7",
55
- "ts-jest": "^28.0.8",
63
+ "ts-jest": "^29.0.5",
56
64
  "ts-node": "^10.9.2",
57
65
  "tsd": "^0.31.0",
58
66
  "typedoc": "^0.25.13",
59
- "typescript": "~4.8.4"
67
+ "typescript": "~5.6.3"
60
68
  },
61
69
  "engines": {
62
70
  "node": "^18.18 || >=20"
@@ -71,6 +79,9 @@
71
79
  }
72
80
  },
73
81
  "tsd": {
74
- "directory": "src"
82
+ "directory": "src",
83
+ "compilerOptions": {
84
+ "composite": "false"
85
+ }
75
86
  }
76
87
  }
package/dist/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './types';
2
- export * from './typing';
3
- export * from './superstruct';
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,2CAAyB;AACzB,gDAA8B","sourcesContent":["export * from './types';\nexport * from './typing';\nexport * from './superstruct';\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"superstruct.js","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":";;;AAAA,uDAK+B;AAoD/B;;;;;;GAMG;AACH,SAAgB,MAAM,CACpB,MAAc;IAEd,OAAO,IAAA,oBAAQ,EAAC,MAAM,CAAQ,CAAC;AACjC,CAAC;AAJD,wBAIC;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;AAZD,sCAYC;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;AATD,sCASC;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;AAPD,gCAOC","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\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/types.d.ts DELETED
@@ -1,17 +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 declare type StringNumber = Infer<typeof StringNumberStruct>;
package/dist/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA,uDAA2D;AAE3D,+CAA8C;AAE9C;;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;QACF,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAe,CAAC,CAAC;QACrC,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;KAC9D;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,KAAK,CAAC;KACd;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"]}