@metamask-previews/base-data-service 2.0.0-preview-ed70ef231 → 2.0.0-preview-ff2ab0583
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/utils.js.map +1 -1
- package/package.json +2 -2
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAIzD;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAClC,QAAkB,EAClB,QAAkB,EAClB,MAAyB;IAEzB,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAEnD,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CACb,uBAAuB,QAAQ,CAAC,CAAC,CAAC,sCAAsC,KAAK,CAAC,OAAO,GAAG,CACzF,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,uBAAuB,CAUrC,WAAwB,EACxB,QAAuB,EACvB,MAAuB;IAavB,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,gEAAgE;QAChE,kEAAkE;QAClE,sEAAsE;QACtE,4EAA4E;QAC5E,4EAA4E;QAC5E,uEAAuE;QACvE,kBAAkB;QAClB,OAAO,QAA+B,CAAC;IACzC,CAAC;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAEnD,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CACb,0BAA0B,WAAW,CAAC,CAAC,CAAC,sCAAsC,KAAK,CAAC,OAAO,GAAG,CAC/F,CAAC;IACJ,CAAC;IAED,6BAA6B;IAC7B,OAAO,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAIzD;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAClC,QAAkB,EAClB,QAAkB,EAClB,MAAyB;IAEzB,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAEnD,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CACb,uBAAuB,QAAQ,CAAC,CAAC,CAAC,sCAAsC,KAAK,CAAC,OAAO,GAAG,CACzF,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,uBAAuB,CAUrC,WAAwB,EACxB,QAAuB,EACvB,MAAuB;IAavB,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,gEAAgE;QAChE,kEAAkE;QAClE,sEAAsE;QACtE,4EAA4E;QAC5E,4EAA4E;QAC5E,uEAAuE;QACvE,kBAAkB;QAClB,OAAO,QAA+B,CAAC;IACzC,CAAC;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAEnD,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CACb,0BAA0B,WAAW,CAAC,CAAC,CAAC,sCAAsC,KAAK,CAAC,OAAO,GAAG,CAC/F,CAAC;IACJ,CAAC;IAED,6BAA6B;IAC7B,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { Struct, validate } from '@metamask/superstruct';\n\nimport type { MutationKey, QueryKey } from './BaseDataService.js';\n\n/**\n * Process query responses, validating them using Superstruct if a struct is defined.\n *\n * @param queryKey - The query key.\n * @param response - The query response\n * @param struct - The struct defining the schema for the query response.\n * @returns The query response, coerced by Superstruct if needed.\n * @throws If the query response does not match the struct.\n */\nexport function processQueryResponse<Response>(\n queryKey: QueryKey,\n response: Response,\n struct?: Struct<Response>,\n): Response {\n if (!struct) {\n return response;\n }\n\n const [error, result] = validate(response, struct);\n\n if (error) {\n throw new Error(\n `Query function for \"${queryKey[0]}\" returned an unexpected response: ${error.message}.`,\n );\n }\n\n return result;\n}\n\n/**\n * Process mutation responses, validating them using Superstruct if a struct is defined.\n *\n * @param mutationKey - The mutation key.\n * @param response - The mutation response\n * @param struct - The struct defining the schema for the mutation response.\n * @returns The mutation response, coerced by Superstruct if needed.\n * @throws If the mutation response does not match the struct.\n * @template InputResponse - The type of the response data being validated, e.g. `Json`.\n * @template ResponseStruct - The struct used to validate and decode the response,\n * e.g. `Struct<FetchOrdersResponse>`, or `undefined` when no validation is needed.\n */\nexport function processMutationResponse<\n InputResponse,\n // We have to use `Struct<any>` here, as using `Struct<InputResponse>` (or\n // even `Struct<unknown>`) would reject a more concrete, \"real world\" struct.\n // The reason is that `Struct` is an object type with methods whose signatures\n // feature the struct's content type, making `Struct` contravariant in its\n // content type. The only way to get around this is to use `any`.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ResponseStruct extends Struct<any> | undefined = undefined,\n>(\n mutationKey: MutationKey,\n response: InputResponse,\n struct?: ResponseStruct,\n // We don't want this to be a type parameter as it should not be customizable\n // (it is only derived).\n): ResponseStruct extends Struct<infer StructType>\n ? StructType\n : InputResponse {\n // Because we aren't defining the return type as a type parameter,\n // we need to restate it so we can reuse it below.\n type Response =\n ResponseStruct extends Struct<infer StructType>\n ? StructType\n : InputResponse;\n\n if (!struct) {\n // Type assertion: TypeScript cannot \"see\" that when `struct` is\n // `undefined`, `response` satisfies the `InputResponse` branch of\n // `Response` (even though we stated this fact in the conditional type\n // above). This is because at this point in time, `ResponseStruct` — being a\n // generic — is unresolved, which makes `Response` unresolved too. This is a\n // limitation of the way that generics work. Therefore, we need to help\n // TypeScript out.\n return response as unknown as Response;\n }\n\n const [error, result] = validate(response, struct);\n\n if (error) {\n throw new Error(\n `Mutation function for \"${mutationKey[0]}\" returned an unexpected response: ${error.message}.`,\n );\n }\n\n // Type assertion: See above.\n return result;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/base-data-service",
|
|
3
|
-
"version": "2.0.0-preview-
|
|
3
|
+
"version": "2.0.0-preview-ff2ab0583",
|
|
4
4
|
"description": "Provides utilities for building data services",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"@types/jest": "^30.0.0",
|
|
67
67
|
"@types/lodash-es": "^4.17.12",
|
|
68
68
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
69
|
-
"deepmerge": "^4.
|
|
69
|
+
"deepmerge": "^4.3.1",
|
|
70
70
|
"jest": "^30.4.2",
|
|
71
71
|
"nock": "^13.5.6",
|
|
72
72
|
"rimraf": "^6.1.3",
|