@metamask-previews/react-data-query 0.0.0-preview-2d89a26 → 0.0.0-preview-a0caca0c0
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 +0 -4
- package/dist/index.cjs +10 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +7 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +9 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -12
- package/dist/createUIQueryClient.cjs +0 -101
- package/dist/createUIQueryClient.cjs.map +0 -1
- package/dist/createUIQueryClient.d.cts +0 -18
- package/dist/createUIQueryClient.d.cts.map +0 -1
- package/dist/createUIQueryClient.d.mts +0 -18
- package/dist/createUIQueryClient.d.mts.map +0 -1
- package/dist/createUIQueryClient.mjs +0 -97
- package/dist/createUIQueryClient.mjs.map +0 -1
- package/dist/hooks.cjs +0 -29
- package/dist/hooks.cjs.map +0 -1
- package/dist/hooks.d.cts +0 -21
- package/dist/hooks.d.cts.map +0 -1
- package/dist/hooks.d.mts +0 -21
- package/dist/hooks.d.mts.map +0 -1
- package/dist/hooks.mjs +0 -24
- package/dist/hooks.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Example function that returns a greeting for the given name.
|
|
5
|
+
*
|
|
6
|
+
* @param name - The name to greet.
|
|
7
|
+
* @returns The greeting.
|
|
8
|
+
*/
|
|
9
|
+
function greeter(name) {
|
|
10
|
+
return `Hello, ${name}!`;
|
|
11
|
+
}
|
|
12
|
+
exports.default = greeter;
|
|
9
13
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA;;;;;GAKG;AACH,SAAwB,OAAO,CAAC,IAAY;IAC1C,OAAO,UAAU,IAAI,GAAG,CAAC;AAC3B,CAAC;AAFD,0BAEC","sourcesContent":["/**\n * Example function that returns a greeting for the given name.\n *\n * @param name - The name to greet.\n * @returns The greeting.\n */\nexport default function greeter(name: string): string {\n return `Hello, ${name}!`;\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Example function that returns a greeting for the given name.
|
|
3
|
+
*
|
|
4
|
+
* @param name - The name to greet.
|
|
5
|
+
* @returns The greeting.
|
|
6
|
+
*/
|
|
7
|
+
export default function greeter(name: string): string;
|
|
3
8
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Example function that returns a greeting for the given name.
|
|
3
|
+
*
|
|
4
|
+
* @param name - The name to greet.
|
|
5
|
+
* @returns The greeting.
|
|
6
|
+
*/
|
|
7
|
+
export default function greeter(name: string): string;
|
|
3
8
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Example function that returns a greeting for the given name.
|
|
3
|
+
*
|
|
4
|
+
* @param name - The name to greet.
|
|
5
|
+
* @returns The greeting.
|
|
6
|
+
*/
|
|
7
|
+
export default function greeter(name) {
|
|
8
|
+
return `Hello, ${name}!`;
|
|
9
|
+
}
|
|
3
10
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,IAAY;IAC1C,OAAO,UAAU,IAAI,GAAG,CAAC;AAC3B,CAAC","sourcesContent":["/**\n * Example function that returns a greeting for the given name.\n *\n * @param name - The name to greet.\n * @returns The greeting.\n */\nexport default function greeter(name: string): string {\n return `Hello, ${name}!`;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/react-data-query",
|
|
3
|
-
"version": "0.0.0-preview-
|
|
3
|
+
"version": "0.0.0-preview-a0caca0c0",
|
|
4
4
|
"description": "Provides React utilities for consuming data services",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -46,12 +46,6 @@
|
|
|
46
46
|
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
|
|
47
47
|
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
48
48
|
},
|
|
49
|
-
"dependencies": {
|
|
50
|
-
"@metamask/base-data-service": "^0.0.0",
|
|
51
|
-
"@metamask/utils": "^11.9.0",
|
|
52
|
-
"@tanstack/query-core": "^4.43.0",
|
|
53
|
-
"@tanstack/react-query": "^4.43.0"
|
|
54
|
-
},
|
|
55
49
|
"devDependencies": {
|
|
56
50
|
"@metamask/auto-changelog": "^3.4.4",
|
|
57
51
|
"@ts-bridge/cli": "^0.6.4",
|
|
@@ -63,11 +57,6 @@
|
|
|
63
57
|
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
64
58
|
"typescript": "~5.3.3"
|
|
65
59
|
},
|
|
66
|
-
"peerDependencies": {
|
|
67
|
-
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
68
|
-
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
69
|
-
"react-native": "*"
|
|
70
|
-
},
|
|
71
60
|
"engines": {
|
|
72
61
|
"node": "^18.18 || >=20"
|
|
73
62
|
},
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createUIQueryClient = void 0;
|
|
4
|
-
const utils_1 = require("@metamask/utils");
|
|
5
|
-
const query_core_1 = require("@tanstack/query-core");
|
|
6
|
-
/**
|
|
7
|
-
* Create a QueryClient queries and subscribes to data services using the messenger.
|
|
8
|
-
*
|
|
9
|
-
* @param dataServices - A list of data services.
|
|
10
|
-
* @param messenger - A messenger adapter.
|
|
11
|
-
* @returns The QueryClient.
|
|
12
|
-
*/
|
|
13
|
-
function createUIQueryClient(dataServices, messenger) {
|
|
14
|
-
const subscriptions = new Map();
|
|
15
|
-
/**
|
|
16
|
-
* Parse a query key to detect a service name.
|
|
17
|
-
*
|
|
18
|
-
* @param queryKey - The query key.
|
|
19
|
-
* @returns The service name if it parsing succeeded, otherwise null.
|
|
20
|
-
*/
|
|
21
|
-
function parseQueryKey(queryKey) {
|
|
22
|
-
const action = queryKey[0];
|
|
23
|
-
if (typeof action !== 'string') {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
const service = action.split(':')[0];
|
|
27
|
-
if (!dataServices.includes(service)) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
return service;
|
|
31
|
-
}
|
|
32
|
-
const client = new query_core_1.QueryClient({
|
|
33
|
-
defaultOptions: {
|
|
34
|
-
queries: {
|
|
35
|
-
queryFn: async (options) => {
|
|
36
|
-
const { queryKey } = options;
|
|
37
|
-
const action = queryKey[0];
|
|
38
|
-
(0, utils_1.assert)(typeof action === 'string' &&
|
|
39
|
-
dataServices.includes(action.split(':')?.[0]), "Queries must call actions on the messenger provided to createUIQueryClient, e.g. `queryKey: ['ExampleDataService:getAssets', ...]`.");
|
|
40
|
-
return await messenger.call(action, ...options.queryKey.slice(1), options.pageParam);
|
|
41
|
-
},
|
|
42
|
-
staleTime: 0,
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
const cache = client.getQueryCache();
|
|
47
|
-
cache.subscribe((event) => {
|
|
48
|
-
const { query } = event;
|
|
49
|
-
const hash = query.queryHash;
|
|
50
|
-
const hasSubscription = subscriptions.has(hash);
|
|
51
|
-
const observerCount = query.getObserversCount();
|
|
52
|
-
const service = parseQueryKey(query.queryKey);
|
|
53
|
-
if (!service) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
if (!hasSubscription &&
|
|
57
|
-
event.type === 'observerAdded' &&
|
|
58
|
-
observerCount === 1) {
|
|
59
|
-
const cacheListener = (payload) => {
|
|
60
|
-
if (payload.type === 'removed') {
|
|
61
|
-
const currentQuery = cache.get(hash);
|
|
62
|
-
if (currentQuery) {
|
|
63
|
-
cache.remove(currentQuery);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
(0, query_core_1.hydrate)(client, payload.state);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
subscriptions.set(hash, cacheListener);
|
|
71
|
-
messenger.subscribe(`${service}:cacheUpdated:${hash}`, cacheListener);
|
|
72
|
-
}
|
|
73
|
-
else if (event.type === 'observerRemoved' &&
|
|
74
|
-
observerCount === 0 &&
|
|
75
|
-
hasSubscription) {
|
|
76
|
-
const subscriptionListener = subscriptions.get(hash);
|
|
77
|
-
messenger.unsubscribe(`${service}:cacheUpdated:${hash}`, subscriptionListener);
|
|
78
|
-
subscriptions.delete(hash);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
// Override invalidateQueries to ensure the data service is invalidated as well.
|
|
82
|
-
const originalInvalidate = client.invalidateQueries.bind(client);
|
|
83
|
-
// This function is defined in this way to have full support for all function overloads.
|
|
84
|
-
client.invalidateQueries = async (arg1, arg2, arg3) => {
|
|
85
|
-
const [filters, options] = (0, query_core_1.parseFilterArgs)(arg1, arg2, arg3);
|
|
86
|
-
const queries = client.getQueryCache().findAll(filters);
|
|
87
|
-
const services = [
|
|
88
|
-
...new Set(queries.map((query) => parseQueryKey(query.queryKey))),
|
|
89
|
-
];
|
|
90
|
-
await Promise.all(services.map(async (service) => {
|
|
91
|
-
if (!service) {
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
return messenger.call(`${service}:invalidateQueries`, filters, options);
|
|
95
|
-
}));
|
|
96
|
-
return originalInvalidate(filters, options);
|
|
97
|
-
};
|
|
98
|
-
return client;
|
|
99
|
-
}
|
|
100
|
-
exports.createUIQueryClient = createUIQueryClient;
|
|
101
|
-
//# sourceMappingURL=createUIQueryClient.cjs.map
|
|
@@ -1 +0,0 @@
|
|
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ceGranularCacheUpdatedPayload } from '@metamask/base-data-service';\nimport { assert, Json } from '@metamask/utils';\nimport {\n hydrate,\n QueryClient,\n InvalidateQueryFilters,\n InvalidateOptions,\n OmitKeyof,\n parseFilterArgs,\n QueryKey,\n} from '@tanstack/query-core';\n\ntype SubscriptionCallback = (\n payload: DataServiceGranularCacheUpdatedPayload,\n) => void;\n\ntype JsonSubscriptionCallback = (data: Json) => void;\n\n// TODO: Figure out if we can replace with a better Messenger type\ntype MessengerAdapter = {\n call: (method: string, ...params: Json[]) => Promise<Json | void>;\n subscribe: (method: string, callback: JsonSubscriptionCallback) => void;\n unsubscribe: (method: string, callback: JsonSubscriptionCallback) => void;\n};\n\n/**\n * Create a QueryClient queries and subscribes to data services using the messenger.\n *\n * @param dataServices - A list of data services.\n * @param messenger - A messenger adapter.\n * @returns The QueryClient.\n */\nexport function createUIQueryClient(\n dataServices: string[],\n messenger: MessengerAdapter,\n): QueryClient {\n const subscriptions = new Map<string, SubscriptionCallback>();\n\n /**\n * Parse a query key to detect a service name.\n *\n * @param queryKey - The query key.\n * @returns The service name if it parsing succeeded, otherwise null.\n */\n function parseQueryKey(queryKey: QueryKey): string | null {\n const action = queryKey[0];\n\n if (typeof action !== 'string') {\n return null;\n }\n\n const service = action.split(':')[0];\n\n if (!dataServices.includes(service)) {\n return null;\n }\n\n return service;\n }\n\n const client: QueryClient = new QueryClient({\n defaultOptions: {\n queries: {\n queryFn: async (options): Promise<unknown> => {\n const { queryKey } = options;\n\n const action = queryKey[0];\n\n assert(\n typeof action === 'string' &&\n dataServices.includes(action.split(':')?.[0]),\n \"Queries must call actions on the messenger provided to createUIQueryClient, e.g. `queryKey: ['ExampleDataService:getAssets', ...]`.\",\n );\n\n return await messenger.call(\n action,\n ...(options.queryKey.slice(1) as Json[]),\n options.pageParam,\n );\n },\n staleTime: 0,\n },\n },\n });\n\n const cache = client.getQueryCache();\n\n cache.subscribe((event) => {\n const { query } = event;\n\n const hash = query.queryHash;\n const hasSubscription = subscriptions.has(hash);\n const observerCount = query.getObserversCount();\n\n const service = parseQueryKey(query.queryKey);\n\n if (!service) {\n return;\n }\n\n if (\n !hasSubscription &&\n event.type === 'observerAdded' &&\n observerCount === 1\n ) {\n const cacheListener = (\n payload: DataServiceGranularCacheUpdatedPayload,\n ): void => {\n if (payload.type === 'removed') {\n const currentQuery = cache.get(hash);\n\n if (currentQuery) {\n cache.remove(currentQuery);\n }\n } else {\n hydrate(client, payload.state);\n }\n };\n\n subscriptions.set(hash, cacheListener);\n messenger.subscribe(\n `${service}:cacheUpdated:${hash}`,\n cacheListener as JsonSubscriptionCallback,\n );\n } else if (\n event.type === 'observerRemoved' &&\n observerCount === 0 &&\n hasSubscription\n ) {\n const subscriptionListener = subscriptions.get(hash);\n\n messenger.unsubscribe(\n `${service}:cacheUpdated:${hash}`,\n subscriptionListener as JsonSubscriptionCallback,\n );\n subscriptions.delete(hash);\n }\n });\n\n // Override invalidateQueries to ensure the data service is invalidated as well.\n const originalInvalidate = client.invalidateQueries.bind(client);\n\n // This function is defined in this way to have full support for all function overloads.\n client.invalidateQueries = async (\n arg1?: QueryKey | InvalidateQueryFilters,\n arg2?: OmitKeyof<InvalidateQueryFilters, 'queryKey'> | InvalidateOptions,\n arg3?: InvalidateOptions,\n ): Promise<void> => {\n const [filters, options] = parseFilterArgs(arg1, arg2, arg3);\n\n const queries = client.getQueryCache().findAll(filters);\n\n const services = [\n ...new Set(queries.map((query) => parseQueryKey(query.queryKey))),\n ];\n\n await Promise.all(\n services.map(async (service) => {\n if (!service) {\n return null;\n }\n\n return messenger.call(\n `${service}:invalidateQueries`,\n filters as Json,\n options as Json,\n );\n }),\n );\n\n return originalInvalidate(filters, options);\n };\n\n return client;\n}\n"]}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Json } from "@metamask/utils";
|
|
2
|
-
import { QueryClient } from "@tanstack/query-core";
|
|
3
|
-
type JsonSubscriptionCallback = (data: Json) => void;
|
|
4
|
-
type MessengerAdapter = {
|
|
5
|
-
call: (method: string, ...params: Json[]) => Promise<Json | void>;
|
|
6
|
-
subscribe: (method: string, callback: JsonSubscriptionCallback) => void;
|
|
7
|
-
unsubscribe: (method: string, callback: JsonSubscriptionCallback) => void;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* Create a QueryClient queries and subscribes to data services using the messenger.
|
|
11
|
-
*
|
|
12
|
-
* @param dataServices - A list of data services.
|
|
13
|
-
* @param messenger - A messenger adapter.
|
|
14
|
-
* @returns The QueryClient.
|
|
15
|
-
*/
|
|
16
|
-
export declare function createUIQueryClient(dataServices: string[], messenger: MessengerAdapter): QueryClient;
|
|
17
|
-
export {};
|
|
18
|
-
//# sourceMappingURL=createUIQueryClient.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createUIQueryClient.d.cts","sourceRoot":"","sources":["../src/createUIQueryClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,IAAI,EAAE,wBAAwB;AAC/C,OAAO,EAEL,WAAW,EAMZ,6BAA6B;AAM9B,KAAK,wBAAwB,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;AAGrD,KAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IAClE,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,wBAAwB,KAAK,IAAI,CAAC;IACxE,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,wBAAwB,KAAK,IAAI,CAAC;CAC3E,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,MAAM,EAAE,EACtB,SAAS,EAAE,gBAAgB,GAC1B,WAAW,CA2Ib"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Json } from "@metamask/utils";
|
|
2
|
-
import { QueryClient } from "@tanstack/query-core";
|
|
3
|
-
type JsonSubscriptionCallback = (data: Json) => void;
|
|
4
|
-
type MessengerAdapter = {
|
|
5
|
-
call: (method: string, ...params: Json[]) => Promise<Json | void>;
|
|
6
|
-
subscribe: (method: string, callback: JsonSubscriptionCallback) => void;
|
|
7
|
-
unsubscribe: (method: string, callback: JsonSubscriptionCallback) => void;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* Create a QueryClient queries and subscribes to data services using the messenger.
|
|
11
|
-
*
|
|
12
|
-
* @param dataServices - A list of data services.
|
|
13
|
-
* @param messenger - A messenger adapter.
|
|
14
|
-
* @returns The QueryClient.
|
|
15
|
-
*/
|
|
16
|
-
export declare function createUIQueryClient(dataServices: string[], messenger: MessengerAdapter): QueryClient;
|
|
17
|
-
export {};
|
|
18
|
-
//# sourceMappingURL=createUIQueryClient.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createUIQueryClient.d.mts","sourceRoot":"","sources":["../src/createUIQueryClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,IAAI,EAAE,wBAAwB;AAC/C,OAAO,EAEL,WAAW,EAMZ,6BAA6B;AAM9B,KAAK,wBAAwB,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;AAGrD,KAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IAClE,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,wBAAwB,KAAK,IAAI,CAAC;IACxE,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,wBAAwB,KAAK,IAAI,CAAC;CAC3E,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,MAAM,EAAE,EACtB,SAAS,EAAE,gBAAgB,GAC1B,WAAW,CA2Ib"}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { assert } from "@metamask/utils";
|
|
2
|
-
import { hydrate, QueryClient, parseFilterArgs } from "@tanstack/query-core";
|
|
3
|
-
/**
|
|
4
|
-
* Create a QueryClient queries and subscribes to data services using the messenger.
|
|
5
|
-
*
|
|
6
|
-
* @param dataServices - A list of data services.
|
|
7
|
-
* @param messenger - A messenger adapter.
|
|
8
|
-
* @returns The QueryClient.
|
|
9
|
-
*/
|
|
10
|
-
export function createUIQueryClient(dataServices, messenger) {
|
|
11
|
-
const subscriptions = new Map();
|
|
12
|
-
/**
|
|
13
|
-
* Parse a query key to detect a service name.
|
|
14
|
-
*
|
|
15
|
-
* @param queryKey - The query key.
|
|
16
|
-
* @returns The service name if it parsing succeeded, otherwise null.
|
|
17
|
-
*/
|
|
18
|
-
function parseQueryKey(queryKey) {
|
|
19
|
-
const action = queryKey[0];
|
|
20
|
-
if (typeof action !== 'string') {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
const service = action.split(':')[0];
|
|
24
|
-
if (!dataServices.includes(service)) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
return service;
|
|
28
|
-
}
|
|
29
|
-
const client = new QueryClient({
|
|
30
|
-
defaultOptions: {
|
|
31
|
-
queries: {
|
|
32
|
-
queryFn: async (options) => {
|
|
33
|
-
const { queryKey } = options;
|
|
34
|
-
const action = queryKey[0];
|
|
35
|
-
assert(typeof action === 'string' &&
|
|
36
|
-
dataServices.includes(action.split(':')?.[0]), "Queries must call actions on the messenger provided to createUIQueryClient, e.g. `queryKey: ['ExampleDataService:getAssets', ...]`.");
|
|
37
|
-
return await messenger.call(action, ...options.queryKey.slice(1), options.pageParam);
|
|
38
|
-
},
|
|
39
|
-
staleTime: 0,
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
const cache = client.getQueryCache();
|
|
44
|
-
cache.subscribe((event) => {
|
|
45
|
-
const { query } = event;
|
|
46
|
-
const hash = query.queryHash;
|
|
47
|
-
const hasSubscription = subscriptions.has(hash);
|
|
48
|
-
const observerCount = query.getObserversCount();
|
|
49
|
-
const service = parseQueryKey(query.queryKey);
|
|
50
|
-
if (!service) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (!hasSubscription &&
|
|
54
|
-
event.type === 'observerAdded' &&
|
|
55
|
-
observerCount === 1) {
|
|
56
|
-
const cacheListener = (payload) => {
|
|
57
|
-
if (payload.type === 'removed') {
|
|
58
|
-
const currentQuery = cache.get(hash);
|
|
59
|
-
if (currentQuery) {
|
|
60
|
-
cache.remove(currentQuery);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
hydrate(client, payload.state);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
subscriptions.set(hash, cacheListener);
|
|
68
|
-
messenger.subscribe(`${service}:cacheUpdated:${hash}`, cacheListener);
|
|
69
|
-
}
|
|
70
|
-
else if (event.type === 'observerRemoved' &&
|
|
71
|
-
observerCount === 0 &&
|
|
72
|
-
hasSubscription) {
|
|
73
|
-
const subscriptionListener = subscriptions.get(hash);
|
|
74
|
-
messenger.unsubscribe(`${service}:cacheUpdated:${hash}`, subscriptionListener);
|
|
75
|
-
subscriptions.delete(hash);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
// Override invalidateQueries to ensure the data service is invalidated as well.
|
|
79
|
-
const originalInvalidate = client.invalidateQueries.bind(client);
|
|
80
|
-
// This function is defined in this way to have full support for all function overloads.
|
|
81
|
-
client.invalidateQueries = async (arg1, arg2, arg3) => {
|
|
82
|
-
const [filters, options] = parseFilterArgs(arg1, arg2, arg3);
|
|
83
|
-
const queries = client.getQueryCache().findAll(filters);
|
|
84
|
-
const services = [
|
|
85
|
-
...new Set(queries.map((query) => parseQueryKey(query.queryKey))),
|
|
86
|
-
];
|
|
87
|
-
await Promise.all(services.map(async (service) => {
|
|
88
|
-
if (!service) {
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
return messenger.call(`${service}:invalidateQueries`, filters, options);
|
|
92
|
-
}));
|
|
93
|
-
return originalInvalidate(filters, options);
|
|
94
|
-
};
|
|
95
|
-
return client;
|
|
96
|
-
}
|
|
97
|
-
//# sourceMappingURL=createUIQueryClient.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createUIQueryClient.mjs","sourceRoot":"","sources":["../src/createUIQueryClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAQ,wBAAwB;AAC/C,OAAO,EACL,OAAO,EACP,WAAW,EAIX,eAAe,EAEhB,6BAA6B;AAe9B;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,YAAsB,EACtB,SAA2B;IAE3B,MAAM,aAAa,GAAG,IAAI,GAAG,EAAgC,CAAC;IAE9D;;;;;OAKG;IACH,SAAS,aAAa,CAAC,QAAkB;QACvC,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;QAE3B,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC/B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAErC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YACpC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,MAAM,GAAgB,IAAI,WAAW,CAAC;QAC1C,cAAc,EAAE;YACd,OAAO,EAAE;gBACP,OAAO,EAAE,KAAK,EAAE,OAAO,EAAoB,EAAE;oBAC3C,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;oBAE7B,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAA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YAC7B,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,OAAO,IAAI,CAAC;YACd,CAAC;YAED,OAAO,SAAS,CAAC,IAAI,CACnB,GAAG,OAAO,oBAAoB,EAC9B,OAAe,EACf,OAAe,CAChB,CAAC;QACJ,CAAC,CAAC,CACH,CAAC;QAEF,OAAO,kBAAkB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { DataServiceGranularCacheUpdatedPayload } from '@metamask/base-data-service';\nimport { assert, Json } from '@metamask/utils';\nimport {\n hydrate,\n QueryClient,\n InvalidateQueryFilters,\n InvalidateOptions,\n OmitKeyof,\n parseFilterArgs,\n QueryKey,\n} from '@tanstack/query-core';\n\ntype SubscriptionCallback = (\n payload: DataServiceGranularCacheUpdatedPayload,\n) => void;\n\ntype JsonSubscriptionCallback = (data: Json) => void;\n\n// TODO: Figure out if we can replace with a better Messenger type\ntype MessengerAdapter = {\n call: (method: string, ...params: Json[]) => Promise<Json | void>;\n subscribe: (method: string, callback: JsonSubscriptionCallback) => void;\n unsubscribe: (method: string, callback: JsonSubscriptionCallback) => void;\n};\n\n/**\n * Create a QueryClient queries and subscribes to data services using the messenger.\n *\n * @param dataServices - A list of data services.\n * @param messenger - A messenger adapter.\n * @returns The QueryClient.\n */\nexport function createUIQueryClient(\n dataServices: string[],\n messenger: MessengerAdapter,\n): QueryClient {\n const subscriptions = new Map<string, SubscriptionCallback>();\n\n /**\n * Parse a query key to detect a service name.\n *\n * @param queryKey - The query key.\n * @returns The service name if it parsing succeeded, otherwise null.\n */\n function parseQueryKey(queryKey: QueryKey): string | null {\n const action = queryKey[0];\n\n if (typeof action !== 'string') {\n return null;\n }\n\n const service = action.split(':')[0];\n\n if (!dataServices.includes(service)) {\n return null;\n }\n\n return service;\n }\n\n const client: QueryClient = new QueryClient({\n defaultOptions: {\n queries: {\n queryFn: async (options): Promise<unknown> => {\n const { queryKey } = options;\n\n const action = queryKey[0];\n\n assert(\n typeof action === 'string' &&\n dataServices.includes(action.split(':')?.[0]),\n \"Queries must call actions on the messenger provided to createUIQueryClient, e.g. `queryKey: ['ExampleDataService:getAssets', ...]`.\",\n );\n\n return await messenger.call(\n action,\n ...(options.queryKey.slice(1) as Json[]),\n options.pageParam,\n );\n },\n staleTime: 0,\n },\n },\n });\n\n const cache = client.getQueryCache();\n\n cache.subscribe((event) => {\n const { query } = event;\n\n const hash = query.queryHash;\n const hasSubscription = subscriptions.has(hash);\n const observerCount = query.getObserversCount();\n\n const service = parseQueryKey(query.queryKey);\n\n if (!service) {\n return;\n }\n\n if (\n !hasSubscription &&\n event.type === 'observerAdded' &&\n observerCount === 1\n ) {\n const cacheListener = (\n payload: DataServiceGranularCacheUpdatedPayload,\n ): void => {\n if (payload.type === 'removed') {\n const currentQuery = cache.get(hash);\n\n if (currentQuery) {\n cache.remove(currentQuery);\n }\n } else {\n hydrate(client, payload.state);\n }\n };\n\n subscriptions.set(hash, cacheListener);\n messenger.subscribe(\n `${service}:cacheUpdated:${hash}`,\n cacheListener as JsonSubscriptionCallback,\n );\n } else if (\n event.type === 'observerRemoved' &&\n observerCount === 0 &&\n hasSubscription\n ) {\n const subscriptionListener = subscriptions.get(hash);\n\n messenger.unsubscribe(\n `${service}:cacheUpdated:${hash}`,\n subscriptionListener as JsonSubscriptionCallback,\n );\n subscriptions.delete(hash);\n }\n });\n\n // Override invalidateQueries to ensure the data service is invalidated as well.\n const originalInvalidate = client.invalidateQueries.bind(client);\n\n // This function is defined in this way to have full support for all function overloads.\n client.invalidateQueries = async (\n arg1?: QueryKey | InvalidateQueryFilters,\n arg2?: OmitKeyof<InvalidateQueryFilters, 'queryKey'> | InvalidateOptions,\n arg3?: InvalidateOptions,\n ): Promise<void> => {\n const [filters, options] = parseFilterArgs(arg1, arg2, arg3);\n\n const queries = client.getQueryCache().findAll(filters);\n\n const services = [\n ...new Set(queries.map((query) => parseQueryKey(query.queryKey))),\n ];\n\n await Promise.all(\n services.map(async (service) => {\n if (!service) {\n return null;\n }\n\n return messenger.call(\n `${service}:invalidateQueries`,\n filters as Json,\n options as Json,\n );\n }),\n );\n\n return originalInvalidate(filters, options);\n };\n\n return client;\n}\n"]}
|
package/dist/hooks.cjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useInfiniteQuery = exports.useQuery = void 0;
|
|
4
|
-
const react_query_1 = require("@tanstack/react-query");
|
|
5
|
-
// We provide re-exports of the underlying TanStack Query hooks with narrower types,
|
|
6
|
-
// removing `staleTime` and `queryFn` which aren't useful when using data services.
|
|
7
|
-
/**
|
|
8
|
-
* Consume a query from a data service.
|
|
9
|
-
*
|
|
10
|
-
* @param options - The query options. Keep in mind that `staleTime` and `queryFn` are not supported
|
|
11
|
-
* when querying data services.
|
|
12
|
-
* @returns The query results.
|
|
13
|
-
*/
|
|
14
|
-
function useQuery(options) {
|
|
15
|
-
return (0, react_query_1.useQuery)(options);
|
|
16
|
-
}
|
|
17
|
-
exports.useQuery = useQuery;
|
|
18
|
-
/**
|
|
19
|
-
* Consume a paginated query from a data service.
|
|
20
|
-
*
|
|
21
|
-
* @param options - The query options. Keep in mind that `staleTime` and `queryFn` are not supported
|
|
22
|
-
* when querying data services.
|
|
23
|
-
* @returns The paginated query results.
|
|
24
|
-
*/
|
|
25
|
-
function useInfiniteQuery(options) {
|
|
26
|
-
return (0, react_query_1.useInfiniteQuery)(options);
|
|
27
|
-
}
|
|
28
|
-
exports.useInfiniteQuery = useInfiniteQuery;
|
|
29
|
-
//# sourceMappingURL=hooks.cjs.map
|
package/dist/hooks.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.cjs","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":";;;AACA,uDAU+B;AAE/B,oFAAoF;AACpF,mFAAmF;AAEnF;;;;;;GAMG;AACH,SAAgB,QAAQ,CAMtB,OAQC;IAED,OAAO,IAAA,sBAAgB,EAAC,OAAO,CAAC,CAAC;AACnC,CAAC;AAjBD,4BAiBC;AAED;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAM9B,OASC;IAED,OAAO,IAAA,8BAAwB,EAAC,OAAO,CAAC,CAAC;AAC3C,CAAC;AAlBD,4CAkBC","sourcesContent":["import { QueryKey } from '@metamask/base-data-service';\nimport {\n useQuery as useQueryTanStack,\n useInfiniteQuery as useInfiniteQueryTanStack,\n OmitKeyof,\n UseQueryOptions,\n InitialDataFunction,\n NonUndefinedGuard,\n UseInfiniteQueryOptions,\n UseQueryResult,\n UseInfiniteQueryResult,\n} from '@tanstack/react-query';\n\n// We provide re-exports of the underlying TanStack Query hooks with narrower types,\n// removing `staleTime` and `queryFn` which aren't useful when using data services.\n\n/**\n * Consume a query from a data service.\n *\n * @param options - The query options. Keep in mind that `staleTime` and `queryFn` are not supported\n * when querying data services.\n * @returns The query results.\n */\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: OmitKeyof<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'initialData' | 'staleTime' | 'queryFn'\n > & {\n initialData?:\n | undefined\n | InitialDataFunction<NonUndefinedGuard<TQueryFnData>>\n | NonUndefinedGuard<TQueryFnData>;\n },\n): UseQueryResult<TData, TError> {\n return useQueryTanStack(options);\n}\n\n/**\n * Consume a paginated query from a data service.\n *\n * @param options - The query options. Keep in mind that `staleTime` and `queryFn` are not supported\n * when querying data services.\n * @returns The paginated query results.\n */\nexport function useInfiniteQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: OmitKeyof<\n UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryFnData,\n TQueryKey\n >,\n 'staleTime' | 'queryFn'\n >,\n): UseInfiniteQueryResult<TData, TError> {\n return useInfiniteQueryTanStack(options);\n}\n"]}
|
package/dist/hooks.d.cts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { QueryKey } from "@metamask/base-data-service";
|
|
2
|
-
import { OmitKeyof, UseQueryOptions, InitialDataFunction, NonUndefinedGuard, UseInfiniteQueryOptions, UseQueryResult, UseInfiniteQueryResult } from "@tanstack/react-query";
|
|
3
|
-
/**
|
|
4
|
-
* Consume a query from a data service.
|
|
5
|
-
*
|
|
6
|
-
* @param options - The query options. Keep in mind that `staleTime` and `queryFn` are not supported
|
|
7
|
-
* when querying data services.
|
|
8
|
-
* @returns The query results.
|
|
9
|
-
*/
|
|
10
|
-
export declare function useQuery<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: OmitKeyof<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'initialData' | 'staleTime' | 'queryFn'> & {
|
|
11
|
-
initialData?: undefined | InitialDataFunction<NonUndefinedGuard<TQueryFnData>> | NonUndefinedGuard<TQueryFnData>;
|
|
12
|
-
}): UseQueryResult<TData, TError>;
|
|
13
|
-
/**
|
|
14
|
-
* Consume a paginated query from a data service.
|
|
15
|
-
*
|
|
16
|
-
* @param options - The query options. Keep in mind that `staleTime` and `queryFn` are not supported
|
|
17
|
-
* when querying data services.
|
|
18
|
-
* @returns The paginated query results.
|
|
19
|
-
*/
|
|
20
|
-
export declare function useInfiniteQuery<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: OmitKeyof<UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>, 'staleTime' | 'queryFn'>): UseInfiniteQueryResult<TData, TError>;
|
|
21
|
-
//# sourceMappingURL=hooks.d.cts.map
|
package/dist/hooks.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.cts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,oCAAoC;AACvD,OAAO,EAGL,SAAS,EACT,eAAe,EACf,mBAAmB,EACnB,iBAAiB,EACjB,uBAAuB,EACvB,cAAc,EACd,sBAAsB,EACvB,8BAA8B;AAK/B;;;;;;GAMG;AACH,wBAAgB,QAAQ,CACtB,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,OAAO,EAChB,KAAK,GAAG,YAAY,EACpB,SAAS,SAAS,QAAQ,GAAG,QAAQ,EAErC,OAAO,EAAE,SAAS,CAChB,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,EACvD,aAAa,GAAG,WAAW,GAAG,SAAS,CACxC,GAAG;IACF,WAAW,CAAC,EACR,SAAS,GACT,mBAAmB,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC,GACpD,iBAAiB,CAAC,YAAY,CAAC,CAAC;CACrC,GACA,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,CAE/B;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,OAAO,EAChB,KAAK,GAAG,YAAY,EACpB,SAAS,SAAS,QAAQ,GAAG,QAAQ,EAErC,OAAO,EAAE,SAAS,CAChB,uBAAuB,CACrB,YAAY,EACZ,MAAM,EACN,KAAK,EACL,YAAY,EACZ,SAAS,CACV,EACD,WAAW,GAAG,SAAS,CACxB,GACA,sBAAsB,CAAC,KAAK,EAAE,MAAM,CAAC,CAEvC"}
|
package/dist/hooks.d.mts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { QueryKey } from "@metamask/base-data-service";
|
|
2
|
-
import { OmitKeyof, UseQueryOptions, InitialDataFunction, NonUndefinedGuard, UseInfiniteQueryOptions, UseQueryResult, UseInfiniteQueryResult } from "@tanstack/react-query";
|
|
3
|
-
/**
|
|
4
|
-
* Consume a query from a data service.
|
|
5
|
-
*
|
|
6
|
-
* @param options - The query options. Keep in mind that `staleTime` and `queryFn` are not supported
|
|
7
|
-
* when querying data services.
|
|
8
|
-
* @returns The query results.
|
|
9
|
-
*/
|
|
10
|
-
export declare function useQuery<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: OmitKeyof<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'initialData' | 'staleTime' | 'queryFn'> & {
|
|
11
|
-
initialData?: undefined | InitialDataFunction<NonUndefinedGuard<TQueryFnData>> | NonUndefinedGuard<TQueryFnData>;
|
|
12
|
-
}): UseQueryResult<TData, TError>;
|
|
13
|
-
/**
|
|
14
|
-
* Consume a paginated query from a data service.
|
|
15
|
-
*
|
|
16
|
-
* @param options - The query options. Keep in mind that `staleTime` and `queryFn` are not supported
|
|
17
|
-
* when querying data services.
|
|
18
|
-
* @returns The paginated query results.
|
|
19
|
-
*/
|
|
20
|
-
export declare function useInfiniteQuery<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: OmitKeyof<UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>, 'staleTime' | 'queryFn'>): UseInfiniteQueryResult<TData, TError>;
|
|
21
|
-
//# sourceMappingURL=hooks.d.mts.map
|
package/dist/hooks.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.mts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,oCAAoC;AACvD,OAAO,EAGL,SAAS,EACT,eAAe,EACf,mBAAmB,EACnB,iBAAiB,EACjB,uBAAuB,EACvB,cAAc,EACd,sBAAsB,EACvB,8BAA8B;AAK/B;;;;;;GAMG;AACH,wBAAgB,QAAQ,CACtB,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,OAAO,EAChB,KAAK,GAAG,YAAY,EACpB,SAAS,SAAS,QAAQ,GAAG,QAAQ,EAErC,OAAO,EAAE,SAAS,CAChB,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,EACvD,aAAa,GAAG,WAAW,GAAG,SAAS,CACxC,GAAG;IACF,WAAW,CAAC,EACR,SAAS,GACT,mBAAmB,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC,GACpD,iBAAiB,CAAC,YAAY,CAAC,CAAC;CACrC,GACA,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,CAE/B;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,OAAO,EAChB,KAAK,GAAG,YAAY,EACpB,SAAS,SAAS,QAAQ,GAAG,QAAQ,EAErC,OAAO,EAAE,SAAS,CAChB,uBAAuB,CACrB,YAAY,EACZ,MAAM,EACN,KAAK,EACL,YAAY,EACZ,SAAS,CACV,EACD,WAAW,GAAG,SAAS,CACxB,GACA,sBAAsB,CAAC,KAAK,EAAE,MAAM,CAAC,CAEvC"}
|
package/dist/hooks.mjs
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { useQuery as useQueryTanStack, useInfiniteQuery as useInfiniteQueryTanStack } from "@tanstack/react-query";
|
|
2
|
-
// We provide re-exports of the underlying TanStack Query hooks with narrower types,
|
|
3
|
-
// removing `staleTime` and `queryFn` which aren't useful when using data services.
|
|
4
|
-
/**
|
|
5
|
-
* Consume a query from a data service.
|
|
6
|
-
*
|
|
7
|
-
* @param options - The query options. Keep in mind that `staleTime` and `queryFn` are not supported
|
|
8
|
-
* when querying data services.
|
|
9
|
-
* @returns The query results.
|
|
10
|
-
*/
|
|
11
|
-
export function useQuery(options) {
|
|
12
|
-
return useQueryTanStack(options);
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Consume a paginated query from a data service.
|
|
16
|
-
*
|
|
17
|
-
* @param options - The query options. Keep in mind that `staleTime` and `queryFn` are not supported
|
|
18
|
-
* when querying data services.
|
|
19
|
-
* @returns The paginated query results.
|
|
20
|
-
*/
|
|
21
|
-
export function useInfiniteQuery(options) {
|
|
22
|
-
return useInfiniteQueryTanStack(options);
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=hooks.mjs.map
|
package/dist/hooks.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.mjs","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,IAAI,gBAAgB,EAC5B,gBAAgB,IAAI,wBAAwB,EAQ7C,8BAA8B;AAE/B,oFAAoF;AACpF,mFAAmF;AAEnF;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAMtB,OAQC;IAED,OAAO,gBAAgB,CAAC,OAAO,CAAC,CAAC;AACnC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAM9B,OASC;IAED,OAAO,wBAAwB,CAAC,OAAO,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import { QueryKey } from '@metamask/base-data-service';\nimport {\n useQuery as useQueryTanStack,\n useInfiniteQuery as useInfiniteQueryTanStack,\n OmitKeyof,\n UseQueryOptions,\n InitialDataFunction,\n NonUndefinedGuard,\n UseInfiniteQueryOptions,\n UseQueryResult,\n UseInfiniteQueryResult,\n} from '@tanstack/react-query';\n\n// We provide re-exports of the underlying TanStack Query hooks with narrower types,\n// removing `staleTime` and `queryFn` which aren't useful when using data services.\n\n/**\n * Consume a query from a data service.\n *\n * @param options - The query options. Keep in mind that `staleTime` and `queryFn` are not supported\n * when querying data services.\n * @returns The query results.\n */\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: OmitKeyof<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'initialData' | 'staleTime' | 'queryFn'\n > & {\n initialData?:\n | undefined\n | InitialDataFunction<NonUndefinedGuard<TQueryFnData>>\n | NonUndefinedGuard<TQueryFnData>;\n },\n): UseQueryResult<TData, TError> {\n return useQueryTanStack(options);\n}\n\n/**\n * Consume a paginated query from a data service.\n *\n * @param options - The query options. Keep in mind that `staleTime` and `queryFn` are not supported\n * when querying data services.\n * @returns The paginated query results.\n */\nexport function useInfiniteQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: OmitKeyof<\n UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryFnData,\n TQueryKey\n >,\n 'staleTime' | 'queryFn'\n >,\n): UseInfiniteQueryResult<TData, TError> {\n return useInfiniteQueryTanStack(options);\n}\n"]}
|