@metamask-previews/base-data-service 1.0.0-preview-8bfa290fb → 2.0.0-preview-0a30e47
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 +10 -8
- package/dist/{BaseDataService.d.mts → BaseDataService.d.ts} +10 -41
- package/dist/BaseDataService.d.ts.map +1 -0
- package/dist/BaseDataService.js +212 -0
- package/dist/BaseDataService.js.map +1 -0
- package/dist/{createServicePolicy.d.mts → createServicePolicy.d.ts} +3 -3
- package/dist/createServicePolicy.d.ts.map +1 -0
- package/dist/{createServicePolicy.mjs → createServicePolicy.js} +3 -3
- package/dist/createServicePolicy.js.map +1 -0
- package/dist/{index.d.cts → index.d.ts} +7 -7
- package/dist/index.d.ts.map +1 -0
- package/dist/{index.mjs → index.js} +4 -4
- package/dist/index.js.map +1 -0
- package/dist/utils.d.ts +13 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +21 -0
- package/dist/utils.js.map +1 -0
- package/package.json +16 -20
- package/dist/BaseDataService.cjs +0 -300
- package/dist/BaseDataService.cjs.map +0 -1
- package/dist/BaseDataService.d.cts +0 -146
- package/dist/BaseDataService.d.cts.map +0 -1
- package/dist/BaseDataService.d.mts.map +0 -1
- package/dist/BaseDataService.mjs +0 -301
- package/dist/BaseDataService.mjs.map +0 -1
- package/dist/createServicePolicy.cjs +0 -228
- package/dist/createServicePolicy.cjs.map +0 -1
- package/dist/createServicePolicy.d.cts +0 -179
- package/dist/createServicePolicy.d.cts.map +0 -1
- package/dist/createServicePolicy.d.mts.map +0 -1
- package/dist/createServicePolicy.mjs.map +0 -1
- package/dist/index.cjs +0 -20
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts +0 -7
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/loggers.cjs +0 -7
- package/dist/loggers.cjs.map +0 -1
- package/dist/loggers.d.cts +0 -5
- package/dist/loggers.d.cts.map +0 -1
- package/dist/loggers.d.mts +0 -5
- package/dist/loggers.d.mts.map +0 -1
- package/dist/loggers.mjs +0 -4
- package/dist/loggers.mjs.map +0 -1
- package/dist/utils.cjs +0 -56
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.d.cts +0 -26
- package/dist/utils.d.cts.map +0 -1
- package/dist/utils.d.mts +0 -26
- package/dist/utils.d.mts.map +0 -1
- package/dist/utils.mjs +0 -51
- package/dist/utils.mjs.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/base-data-service",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-preview-0a30e47",
|
|
4
4
|
"description": "Provides utilities for building data services",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -18,19 +18,12 @@
|
|
|
18
18
|
"files": [
|
|
19
19
|
"dist/"
|
|
20
20
|
],
|
|
21
|
+
"type": "module",
|
|
21
22
|
"sideEffects": false,
|
|
22
|
-
"main": "./dist/index.cjs",
|
|
23
|
-
"types": "./dist/index.d.cts",
|
|
24
23
|
"exports": {
|
|
25
24
|
".": {
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
"default": "./dist/index.mjs"
|
|
29
|
-
},
|
|
30
|
-
"require": {
|
|
31
|
-
"types": "./dist/index.d.cts",
|
|
32
|
-
"default": "./dist/index.cjs"
|
|
33
|
-
}
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
34
27
|
},
|
|
35
28
|
"./package.json": "./package.json"
|
|
36
29
|
},
|
|
@@ -39,9 +32,11 @@
|
|
|
39
32
|
"registry": "https://registry.npmjs.org/"
|
|
40
33
|
},
|
|
41
34
|
"scripts": {
|
|
42
|
-
"build": "
|
|
43
|
-
"build:all": "
|
|
35
|
+
"build": "tsc --project tsconfig.build.json",
|
|
36
|
+
"build:all": "tsc --build tsconfig.build.json --verbose",
|
|
37
|
+
"build:clean": "yarn build:only-clean && yarn build",
|
|
44
38
|
"build:docs": "typedoc",
|
|
39
|
+
"build:only-clean": "rimraf './dist' './tsconfig.build.tsbuildinfo'",
|
|
45
40
|
"changelog:update": "../../scripts/update-changelog.sh @metamask/base-data-service",
|
|
46
41
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/base-data-service",
|
|
47
42
|
"lint:tsconfigs": "tsx ../../scripts/lint-tsconfigs/lint-tsconfigs.mts",
|
|
@@ -56,30 +51,31 @@
|
|
|
56
51
|
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
57
52
|
},
|
|
58
53
|
"dependencies": {
|
|
59
|
-
"@metamask/messenger": "^
|
|
60
|
-
"@metamask/storage-service": "^
|
|
54
|
+
"@metamask/messenger": "^3.0.0",
|
|
55
|
+
"@metamask/storage-service": "^2.0.0",
|
|
61
56
|
"@metamask/superstruct": "^3.4.1",
|
|
62
57
|
"@metamask/utils": "^11.12.0",
|
|
63
58
|
"@tanstack/query-core": "^5.62.16",
|
|
64
59
|
"cockatiel": "^3.1.2",
|
|
65
60
|
"fast-deep-equal": "^3.1.3",
|
|
66
|
-
"lodash": "^4.17.21"
|
|
61
|
+
"lodash-es": "^4.17.21"
|
|
67
62
|
},
|
|
68
63
|
"devDependencies": {
|
|
69
64
|
"@metamask/auto-changelog": "^6.1.0",
|
|
70
|
-
"@ts-bridge/cli": "^0.6.4",
|
|
71
65
|
"@types/jest": "^30.0.0",
|
|
72
|
-
"@types/lodash": "^4.
|
|
66
|
+
"@types/lodash-es": "^4.17.12",
|
|
67
|
+
"@typescript/native": "npm:typescript@^7.0.2",
|
|
73
68
|
"deepmerge": "^4.2.2",
|
|
74
69
|
"jest": "^30.4.2",
|
|
75
70
|
"nock": "^13.3.1",
|
|
71
|
+
"rimraf": "^5.0.5",
|
|
76
72
|
"ts-jest": "^29.4.11",
|
|
77
73
|
"tsx": "^4.20.5",
|
|
78
74
|
"typedoc": "^0.25.13",
|
|
79
75
|
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
80
|
-
"typescript": "
|
|
76
|
+
"typescript": "npm:@typescript/typescript6@^6.0.2"
|
|
81
77
|
},
|
|
82
78
|
"engines": {
|
|
83
|
-
"node": "^
|
|
79
|
+
"node": "^22.14.0 || ^24"
|
|
84
80
|
}
|
|
85
81
|
}
|
package/dist/BaseDataService.cjs
DELETED
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
var _BaseDataService_instances, _BaseDataService_messenger, _BaseDataService_externalMessenger, _BaseDataService_policy, _BaseDataService_queryClient, _BaseDataService_queryCacheUnsubscribe, _BaseDataService_mutationCacheUnsubscribe, _BaseDataService_debouncedPersist, _BaseDataService_persistenceConfig, _BaseDataService_publishCacheUpdate, _BaseDataService_persistCache, _BaseDataService_loadCache;
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.BaseDataService = exports.STORAGE_SERVICE_KEY = void 0;
|
|
19
|
-
const messenger_1 = require("@metamask/messenger");
|
|
20
|
-
const superstruct_1 = require("@metamask/superstruct");
|
|
21
|
-
const utils_1 = require("@metamask/utils");
|
|
22
|
-
const query_core_1 = require("@tanstack/query-core");
|
|
23
|
-
const fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
|
|
24
|
-
const lodash_1 = require("lodash");
|
|
25
|
-
const createServicePolicy_js_1 = require("./createServicePolicy.cjs");
|
|
26
|
-
const loggers_js_1 = require("./loggers.cjs");
|
|
27
|
-
const utils_js_1 = require("./utils.cjs");
|
|
28
|
-
const log = (0, loggers_js_1.createModuleLogger)(loggers_js_1.projectLogger, 'BaseDataService');
|
|
29
|
-
/*
|
|
30
|
-
* Defaults to apply to all data service queries if no default option specified.
|
|
31
|
-
*/
|
|
32
|
-
const QUERY_CLIENT_DEFAULTS = {
|
|
33
|
-
queries: {
|
|
34
|
-
retry: false,
|
|
35
|
-
staleTime: (0, utils_1.inMilliseconds)(1, utils_1.Duration.Minute),
|
|
36
|
-
},
|
|
37
|
-
mutations: {
|
|
38
|
-
retry: false,
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
exports.STORAGE_SERVICE_KEY = 'cache';
|
|
42
|
-
class BaseDataService {
|
|
43
|
-
constructor({ name, messenger, queryClientConfig = {}, policyOptions, persistenceConfig, }) {
|
|
44
|
-
_BaseDataService_instances.add(this);
|
|
45
|
-
_BaseDataService_messenger.set(this, void 0);
|
|
46
|
-
_BaseDataService_externalMessenger.set(this, void 0);
|
|
47
|
-
_BaseDataService_policy.set(this, void 0);
|
|
48
|
-
_BaseDataService_queryClient.set(this, void 0);
|
|
49
|
-
_BaseDataService_queryCacheUnsubscribe.set(this, void 0);
|
|
50
|
-
_BaseDataService_mutationCacheUnsubscribe.set(this, void 0);
|
|
51
|
-
_BaseDataService_debouncedPersist.set(this, void 0);
|
|
52
|
-
_BaseDataService_persistenceConfig.set(this, void 0);
|
|
53
|
-
this.name = name;
|
|
54
|
-
// We store two narrowly-typed messengers alongside the generic public one:
|
|
55
|
-
// - #messenger handles the service's own action registration and event publishing
|
|
56
|
-
// - #externalMessenger handles calls to external actions
|
|
57
|
-
// Splitting them avoids TypeScript issues with mixing template-literals with regular strings
|
|
58
|
-
__classPrivateFieldSet(this, _BaseDataService_messenger, messenger, "f");
|
|
59
|
-
__classPrivateFieldSet(this, _BaseDataService_externalMessenger, messenger, "f");
|
|
60
|
-
this.messenger = messenger;
|
|
61
|
-
__classPrivateFieldSet(this, _BaseDataService_queryClient, new query_core_1.QueryClient({
|
|
62
|
-
...queryClientConfig,
|
|
63
|
-
defaultOptions: {
|
|
64
|
-
queries: {
|
|
65
|
-
...QUERY_CLIENT_DEFAULTS.queries,
|
|
66
|
-
...queryClientConfig.defaultOptions?.queries,
|
|
67
|
-
},
|
|
68
|
-
mutations: {
|
|
69
|
-
...QUERY_CLIENT_DEFAULTS.mutations,
|
|
70
|
-
...queryClientConfig.defaultOptions?.mutations,
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
}), "f");
|
|
74
|
-
__classPrivateFieldSet(this, _BaseDataService_persistenceConfig, persistenceConfig, "f");
|
|
75
|
-
__classPrivateFieldSet(this, _BaseDataService_policy, (0, createServicePolicy_js_1.createServicePolicy)(policyOptions), "f");
|
|
76
|
-
__classPrivateFieldSet(this, _BaseDataService_debouncedPersist, __classPrivateFieldGet(this, _BaseDataService_persistenceConfig, "f") &&
|
|
77
|
-
(0, lodash_1.debounce)(() => {
|
|
78
|
-
__classPrivateFieldGet(this, _BaseDataService_instances, "m", _BaseDataService_persistCache).call(this).catch(
|
|
79
|
-
/* istanbul ignore next */
|
|
80
|
-
(error) => __classPrivateFieldGet(this, _BaseDataService_messenger, "f").captureException?.(error));
|
|
81
|
-
}, __classPrivateFieldGet(this, _BaseDataService_persistenceConfig, "f").writeDelay ??
|
|
82
|
-
(0, utils_1.inMilliseconds)(10, utils_1.Duration.Second), {
|
|
83
|
-
maxWait: __classPrivateFieldGet(this, _BaseDataService_persistenceConfig, "f").maxWriteDelay ??
|
|
84
|
-
(0, utils_1.inMilliseconds)(1, utils_1.Duration.Minute),
|
|
85
|
-
}), "f");
|
|
86
|
-
__classPrivateFieldSet(this, _BaseDataService_queryCacheUnsubscribe, __classPrivateFieldGet(this, _BaseDataService_queryClient, "f")
|
|
87
|
-
.getQueryCache()
|
|
88
|
-
.subscribe((event) => {
|
|
89
|
-
log('Query cache event emitted', event);
|
|
90
|
-
if (['added', 'updated', 'removed'].includes(event.type)) {
|
|
91
|
-
__classPrivateFieldGet(this, _BaseDataService_instances, "m", _BaseDataService_publishCacheUpdate).call(this, 'query', event.type, event.query.queryHash);
|
|
92
|
-
__classPrivateFieldGet(this, _BaseDataService_debouncedPersist, "f")?.call(this);
|
|
93
|
-
}
|
|
94
|
-
}), "f");
|
|
95
|
-
log('Subscribing to mutation cache');
|
|
96
|
-
__classPrivateFieldSet(this, _BaseDataService_mutationCacheUnsubscribe, __classPrivateFieldGet(this, _BaseDataService_queryClient, "f")
|
|
97
|
-
.getMutationCache()
|
|
98
|
-
.subscribe((event) => {
|
|
99
|
-
log('Mutation cache event emitted', event);
|
|
100
|
-
if (['added', 'updated', 'removed'].includes(event.type) &&
|
|
101
|
-
event.mutation?.options.mutationKey !== undefined) {
|
|
102
|
-
const mutationHash = (0, query_core_1.hashKey)(event.mutation.options.mutationKey);
|
|
103
|
-
__classPrivateFieldGet(this, _BaseDataService_instances, "m", _BaseDataService_publishCacheUpdate).call(this, 'mutation', event.type, mutationHash);
|
|
104
|
-
__classPrivateFieldGet(this, _BaseDataService_debouncedPersist, "f")?.call(this);
|
|
105
|
-
}
|
|
106
|
-
}), "f");
|
|
107
|
-
__classPrivateFieldGet(this, _BaseDataService_messenger, "f").registerActionHandler(`${this.name}:invalidateQueries`, this.invalidateQueries.bind(this));
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Fetch a query.
|
|
111
|
-
*
|
|
112
|
-
* @param options - The options defining the query. Keep in mind that `queryKey` and `queryFn` are required when using data services.
|
|
113
|
-
* Additionally `retry` and `retryDelay` are not available, retries can be customized using the `servicePolicyOptions`.
|
|
114
|
-
* @param options.queryFn - The query function.
|
|
115
|
-
* @param options.responseStruct - An optional struct for validating the response of the query function.
|
|
116
|
-
* @returns The query results.
|
|
117
|
-
*/
|
|
118
|
-
async fetchQuery({ queryFn, responseStruct, ...options }) {
|
|
119
|
-
return __classPrivateFieldGet(this, _BaseDataService_queryClient, "f").fetchQuery({
|
|
120
|
-
...options,
|
|
121
|
-
queryFn: async (context) => {
|
|
122
|
-
const response = await __classPrivateFieldGet(this, _BaseDataService_policy, "f").execute(() => queryFn(context));
|
|
123
|
-
return (0, utils_js_1.processQueryResponse)(options.queryKey, response, responseStruct);
|
|
124
|
-
},
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Fetch a paginated query.
|
|
129
|
-
*
|
|
130
|
-
* @param options - The options defining the query. Keep in mind that `queryKey` and `queryFn` are required when using data services.
|
|
131
|
-
* Additionally `retry` and `retryDelay` are not available, retries can be customized using the `servicePolicyOptions`.
|
|
132
|
-
* @param options.responseStruct - An optional struct for validating the response of the query function.
|
|
133
|
-
* @param pageParam - An optional page parameter.
|
|
134
|
-
* @returns The query result, exclusively the requested page is returned.
|
|
135
|
-
*/
|
|
136
|
-
async fetchInfiniteQuery({ responseStruct, ...options }, pageParam) {
|
|
137
|
-
const cache = __classPrivateFieldGet(this, _BaseDataService_queryClient, "f").getQueryCache();
|
|
138
|
-
const query = cache.find({
|
|
139
|
-
queryKey: options.queryKey,
|
|
140
|
-
});
|
|
141
|
-
if (!query?.state.data || !pageParam) {
|
|
142
|
-
const result = await __classPrivateFieldGet(this, _BaseDataService_queryClient, "f").fetchInfiniteQuery({
|
|
143
|
-
...options,
|
|
144
|
-
initialPageParam: pageParam ?? options.initialPageParam,
|
|
145
|
-
queryFn: async (context) => {
|
|
146
|
-
const response = await __classPrivateFieldGet(this, _BaseDataService_policy, "f").execute(async () => options.queryFn({
|
|
147
|
-
...context,
|
|
148
|
-
pageParam: context.meta?.pageParam ?? context.pageParam,
|
|
149
|
-
}));
|
|
150
|
-
return (0, utils_js_1.processQueryResponse)(options.queryKey, response, responseStruct);
|
|
151
|
-
},
|
|
152
|
-
});
|
|
153
|
-
return result.pages[0];
|
|
154
|
-
}
|
|
155
|
-
const { pages, pageParams } = query.state.data;
|
|
156
|
-
const next = options.getNextPageParam(pages[pages.length - 1], pages, pageParams[pageParams.length - 1], pageParams);
|
|
157
|
-
const direction = (0, fast_deep_equal_1.default)(pageParam, next) ? 'forward' : 'backward';
|
|
158
|
-
const result = await query.fetch({ ...query.options, meta: { pageParam } }, { meta: { fetchMore: { direction } } });
|
|
159
|
-
const pageIndex = result.pageParams.findIndex((param) => (0, fast_deep_equal_1.default)(param, pageParam));
|
|
160
|
-
return result.pages[pageIndex];
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Execute a mutation (e.g. a request that is expected to change server-side data).
|
|
164
|
-
* Unlike `fetchQuery`, the request will not be cached or retried.
|
|
165
|
-
*
|
|
166
|
-
* @param options - The options defining the mutation. Keep in mind that `mutationKey` and `mutationFn` are required when using data services.
|
|
167
|
-
* Additionally, `retry` and `retryDelay` are not available.
|
|
168
|
-
* @param options.mutationFn - The mutation function.
|
|
169
|
-
* @param options.responseStruct - An optional struct for validating the response of the mutation function.
|
|
170
|
-
* @param options.globalId - A string which uniquely identifies this mutation
|
|
171
|
-
* across different query clients — specifically, the one in this data service
|
|
172
|
-
* and the one that `createUIQueryClient` in `@metamask/react-data-query`
|
|
173
|
-
* holds (in fact usually you don't need to pass this — `createUIQueryClient`
|
|
174
|
-
* will do it automatically). This global ID will be stored in the new
|
|
175
|
-
* mutation `meta` data and included in `:cacheUpdated` payloads.
|
|
176
|
-
* @returns The mutation results.
|
|
177
|
-
*/
|
|
178
|
-
async executeMutation({ mutationFn, responseStruct, globalId, ...options }) {
|
|
179
|
-
const mutationCache = __classPrivateFieldGet(this, _BaseDataService_queryClient, "f").getMutationCache();
|
|
180
|
-
const mutation = mutationCache.build(__classPrivateFieldGet(this, _BaseDataService_queryClient, "f"), {
|
|
181
|
-
...options,
|
|
182
|
-
...(globalId !== undefined && {
|
|
183
|
-
meta: { ...options.meta, globalId },
|
|
184
|
-
}),
|
|
185
|
-
mutationFn: async (...args) => {
|
|
186
|
-
// To guard against mutations being retried, we deliberately execute the
|
|
187
|
-
// mutation function through the circuit breaker policy alone, rather
|
|
188
|
-
// than through `this.#policy` (which is a combination of both a
|
|
189
|
-
// circuit breaker policy and retry policy).
|
|
190
|
-
const response = await __classPrivateFieldGet(this, _BaseDataService_policy, "f").circuitBreakerPolicy.execute(() => mutationFn(...args));
|
|
191
|
-
return (0, utils_js_1.processMutationResponse)(options.mutationKey, response, responseStruct);
|
|
192
|
-
},
|
|
193
|
-
});
|
|
194
|
-
// We purposely pass an empty set of variables because this method is
|
|
195
|
-
// intended to be used internally by the data service, not end users, and
|
|
196
|
-
// the data service has full control of `mutationFn` anyway.
|
|
197
|
-
return await mutation.execute({});
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Invalidate queries serviced by this data service.
|
|
201
|
-
*
|
|
202
|
-
* @param filters - Optional filter for selecting specific queries.
|
|
203
|
-
* @param options - Additional optional options for query invalidations.
|
|
204
|
-
* @returns Nothing.
|
|
205
|
-
*/
|
|
206
|
-
async invalidateQueries(filters, options) {
|
|
207
|
-
return __classPrivateFieldGet(this, _BaseDataService_queryClient, "f").invalidateQueries(filters, options);
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Initialize the service, rehydrating the cache with persisted data if possible.
|
|
211
|
-
*/
|
|
212
|
-
init() {
|
|
213
|
-
__classPrivateFieldGet(this, _BaseDataService_instances, "m", _BaseDataService_loadCache).call(this).catch(
|
|
214
|
-
/* istanbul ignore next */
|
|
215
|
-
(error) => __classPrivateFieldGet(this, _BaseDataService_messenger, "f").captureException?.(error));
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Prepares the service for garbage collection. This should be extended
|
|
219
|
-
* by any subclasses to clean up any additional connections or events.
|
|
220
|
-
*/
|
|
221
|
-
destroy() {
|
|
222
|
-
__classPrivateFieldGet(this, _BaseDataService_debouncedPersist, "f")?.cancel();
|
|
223
|
-
__classPrivateFieldGet(this, _BaseDataService_queryCacheUnsubscribe, "f").call(this);
|
|
224
|
-
__classPrivateFieldGet(this, _BaseDataService_mutationCacheUnsubscribe, "f").call(this);
|
|
225
|
-
// `QueryClient.clear()` clears both caches, but `MutationCache.clear()`
|
|
226
|
-
// only drops its references to mutations without clearing their pending
|
|
227
|
-
// garbage-collection timers. We destroy each mutation first so those timers
|
|
228
|
-
// are cleared and do not keep the process alive.
|
|
229
|
-
for (const mutation of __classPrivateFieldGet(this, _BaseDataService_queryClient, "f").getMutationCache().getAll()) {
|
|
230
|
-
mutation.destroy();
|
|
231
|
-
}
|
|
232
|
-
__classPrivateFieldGet(this, _BaseDataService_queryClient, "f").clear();
|
|
233
|
-
this.messenger.clearSubscriptions();
|
|
234
|
-
this.messenger.clearActions();
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
exports.BaseDataService = BaseDataService;
|
|
238
|
-
_BaseDataService_messenger = new WeakMap(), _BaseDataService_externalMessenger = new WeakMap(), _BaseDataService_policy = new WeakMap(), _BaseDataService_queryClient = new WeakMap(), _BaseDataService_queryCacheUnsubscribe = new WeakMap(), _BaseDataService_mutationCacheUnsubscribe = new WeakMap(), _BaseDataService_debouncedPersist = new WeakMap(), _BaseDataService_persistenceConfig = new WeakMap(), _BaseDataService_instances = new WeakSet(), _BaseDataService_publishCacheUpdate = function _BaseDataService_publishCacheUpdate(objectType, eventType, hash) {
|
|
239
|
-
const state = eventType === 'added' || eventType === 'updated'
|
|
240
|
-
? (0, query_core_1.dehydrate)(__classPrivateFieldGet(this, _BaseDataService_queryClient, "f"), {
|
|
241
|
-
shouldDehydrateQuery: (query) => objectType === 'query' && query.queryHash === hash,
|
|
242
|
-
shouldDehydrateMutation: (mutation) => objectType === 'mutation' &&
|
|
243
|
-
mutation.options.mutationKey !== undefined &&
|
|
244
|
-
(0, query_core_1.hashKey)(mutation.options.mutationKey) === hash,
|
|
245
|
-
})
|
|
246
|
-
: null;
|
|
247
|
-
__classPrivateFieldGet(this, _BaseDataService_messenger, "f").publish(`${this.name}:cacheUpdated`, {
|
|
248
|
-
type: eventType,
|
|
249
|
-
objectType,
|
|
250
|
-
hash,
|
|
251
|
-
state,
|
|
252
|
-
});
|
|
253
|
-
__classPrivateFieldGet(this, _BaseDataService_messenger, "f").publish(`${this.name}:cacheUpdated:${hash}`, {
|
|
254
|
-
type: eventType,
|
|
255
|
-
objectType,
|
|
256
|
-
state,
|
|
257
|
-
});
|
|
258
|
-
}, _BaseDataService_persistCache =
|
|
259
|
-
/**
|
|
260
|
-
* Persist the query client cache using the StorageService, if the cache is not empty.
|
|
261
|
-
*
|
|
262
|
-
* @returns Nothing.
|
|
263
|
-
*/
|
|
264
|
-
async function _BaseDataService_persistCache() {
|
|
265
|
-
const state = (0, query_core_1.dehydrate)(__classPrivateFieldGet(this, _BaseDataService_queryClient, "f"), {
|
|
266
|
-
// This is the default, but we specify it to be explicit.
|
|
267
|
-
shouldDehydrateQuery: (query) => query.state.status === 'success',
|
|
268
|
-
});
|
|
269
|
-
if (state.queries.length === 0 && state.mutations.length === 0) {
|
|
270
|
-
await __classPrivateFieldGet(this, _BaseDataService_externalMessenger, "f").call('StorageService:removeItem', this.name, exports.STORAGE_SERVICE_KEY);
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
const cache = {
|
|
274
|
-
timestamp: Date.now(),
|
|
275
|
-
state,
|
|
276
|
-
};
|
|
277
|
-
await __classPrivateFieldGet(this, _BaseDataService_externalMessenger, "f").call('StorageService:setItem', this.name, exports.STORAGE_SERVICE_KEY, cache);
|
|
278
|
-
}, _BaseDataService_loadCache =
|
|
279
|
-
/**
|
|
280
|
-
* Load the query client cache from the StorageService, if persistence is configured
|
|
281
|
-
* and the persisted cache is not expired.
|
|
282
|
-
*
|
|
283
|
-
* @returns Nothing.
|
|
284
|
-
*/
|
|
285
|
-
async function _BaseDataService_loadCache() {
|
|
286
|
-
if (!__classPrivateFieldGet(this, _BaseDataService_persistenceConfig, "f")) {
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
const { result: untypedCache } = await __classPrivateFieldGet(this, _BaseDataService_externalMessenger, "f").call('StorageService:getItem', this.name, exports.STORAGE_SERVICE_KEY);
|
|
290
|
-
if (!untypedCache) {
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
const cache = untypedCache;
|
|
294
|
-
if (Date.now() - cache.timestamp >= __classPrivateFieldGet(this, _BaseDataService_persistenceConfig, "f").maxAge) {
|
|
295
|
-
await __classPrivateFieldGet(this, _BaseDataService_externalMessenger, "f").call('StorageService:removeItem', this.name, exports.STORAGE_SERVICE_KEY);
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
(0, query_core_1.hydrate)(__classPrivateFieldGet(this, _BaseDataService_queryClient, "f"), cache.state);
|
|
299
|
-
};
|
|
300
|
-
//# sourceMappingURL=BaseDataService.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BaseDataService.cjs","sourceRoot":"","sources":["../src/BaseDataService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,mDAM6B;AAM7B,uDAA+C;AAC/C,2CAA2D;AAE3D,qDAmB8B;AAC9B,sEAAwC;AACxC,mCAAiD;AAEjD,sEAIkC;AAClC,8CAAiE;AACjE,0CAA2E;AAE3E,MAAM,GAAG,GAAG,IAAA,+BAAkB,EAAC,0BAAa,EAAE,iBAAiB,CAAC,CAAC;AAmFjE;;GAEG;AACH,MAAM,qBAAqB,GAAm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B,CACzB,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,KAAK;IACH,IAAI,CAAC,uBAAA,IAAI,0CAAmB,EAAE,CAAC;QAC7B,OAAO;IACT,CAAC;IAED,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,uBAAA,IAAI,0CAAmB,CAAC,IAAI,CACjE,wBAAwB,EACxB,IAAI,CAAC,IAAI,EACT,2BAAmB,CACpB,CAAC;IAEF,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO;IACT,CAAC;IAED,MAAM,KAAK,GAAG,YAAyC,CAAC;IAExD,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,SAAS,IAAI,uBAAA,IAAI,0CAAmB,CAAC,MAAM,EAAE,CAAC;QACnE,MAAM,uBAAA,IAAI,0CAAmB,CAAC,IAAI,CAChC,2BAA2B,EAC3B,IAAI,CAAC,IAAI,EACT,2BAAmB,CACpB,CAAC;QACF,OAAO;IACT,CAAC;IAED,IAAA,oBAAO,EAAC,uBAAA,IAAI,oCAAa,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["import {\n Messenger,\n ActionConstraint,\n EventConstraint,\n MessengerActions,\n MessengerEvents,\n} from '@metamask/messenger';\nimport type {\n StorageServiceGetItemAction,\n StorageServiceRemoveItemAction,\n StorageServiceSetItemAction,\n} from '@metamask/storage-service';\nimport { Struct } from '@metamask/superstruct';\nimport { Duration, inMilliseconds } from '@metamask/utils';\nimport type { Json } from '@metamask/utils';\nimport {\n DefaultError,\n DefaultOptions,\n DehydratedState,\n FetchQueryOptions,\n InfiniteData,\n InfiniteQueryPageParamsOptions,\n InvalidateOptions,\n InvalidateQueryFilters,\n MutationOptions,\n OmitKeyof,\n QueryClient,\n QueryClientConfig,\n QueryFunction,\n WithRequired,\n dehydrate,\n hydrate,\n hashKey,\n MutationFunction,\n} from '@tanstack/query-core';\nimport deepEqual from 'fast-deep-equal';\nimport { debounce, DebouncedFunc } from 'lodash';\n\nimport {\n createServicePolicy,\n CreateServicePolicyOptions,\n ServicePolicy,\n} from './createServicePolicy.js';\nimport { createModuleLogger, projectLogger } from './loggers.js';\nimport { processMutationResponse, processQueryResponse } from './utils.js';\n\nconst log = createModuleLogger(projectLogger, 'BaseDataService');\n\n/**\n * Data service mutations and queries use the following format:\n * `['${ServiceName}:${ActionName}', ...params]`\n */\ntype Key = [string, ...Json[]] | readonly [string, ...Json[]];\n\n/*\n * Data service queries use the following format:\n * `['${ServiceName}:${ActionName}', ...params]`\n */\nexport type QueryKey = Key;\n\n/*\n * Data service mutations use the following format:\n * `['${ServiceName}:${ActionName}', ...params]`\n */\nexport type MutationKey = Key;\n\n/**\n * The supertype of all messengers, scoped to a namespace.\n *\n * @template Namespace - The namespace for the messenger's own actions and\n * events.\n */\nexport type BaseMessenger<Namespace extends string> = Messenger<\n Namespace,\n ActionConstraint,\n EventConstraint,\n // Use `any` to allow any parent to be set. `any` is harmless in a type constraint anyway,\n // it's the one totally safe place to use it.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any\n>;\n\nexport type DataServiceGranularCacheUpdatedPayload = {\n objectType: 'query' | 'mutation';\n} & (\n | { type: 'added' | 'updated'; state: DehydratedState }\n | {\n type: 'removed';\n state: null;\n }\n);\n\nexport type DataServiceCacheUpdatedPayload =\n DataServiceGranularCacheUpdatedPayload & {\n hash: string;\n };\n\ntype CacheUpdatedType = DataServiceCacheUpdatedPayload['type'];\n\nexport type DataServiceInvalidateQueriesAction<ServiceName extends string> = {\n type: `${ServiceName}:invalidateQueries`;\n handler: BaseDataService<\n ServiceName,\n BaseMessenger<ServiceName>\n >['invalidateQueries'];\n};\n\nexport type DataServiceActions<ServiceName extends string> =\n DataServiceInvalidateQueriesAction<ServiceName>;\n\ntype DataServiceAllowedActions =\n | StorageServiceGetItemAction\n | StorageServiceSetItemAction\n | StorageServiceRemoveItemAction;\n\nexport type DataServiceCacheUpdatedEvent<ServiceName extends string> = {\n type: `${ServiceName}:cacheUpdated`;\n payload: [DataServiceCacheUpdatedPayload];\n};\n\nexport type DataServiceGranularCacheUpdatedEvent<ServiceName extends string> = {\n type: `${ServiceName}:cacheUpdated:${string}`;\n payload: [DataServiceGranularCacheUpdatedPayload];\n};\n\nexport type DataServiceEvents<ServiceName extends string> =\n | DataServiceCacheUpdatedEvent<ServiceName>\n | DataServiceGranularCacheUpdatedEvent<ServiceName>;\n\n/*\n * Defaults to apply to all data service queries if no default option specified.\n */\nconst QUERY_CLIENT_DEFAULTS: DefaultOptions = {\n queries: {\n retry: false,\n staleTime: inMilliseconds(1, Duration.Minute),\n },\n mutations: {\n retry: false,\n },\n};\n\nexport const STORAGE_SERVICE_KEY = 'cache';\n\n/**\n * Options for persistence configuration.\n */\nexport type PersistenceConfiguration = {\n /**\n * The maximum age before the cache is treated as expired in milliseconds.\n * This is relevant for rehydrating the state during initialization,\n * if the cached state is too old it will be discarded.\n */\n maxAge: number;\n /**\n * The number of milliseconds to wait before triggering persistence following a cache update.\n */\n writeDelay?: number;\n /**\n * The maximum number of milliseconds to wait between persistence writes.\n */\n maxWriteDelay?: number;\n};\n\ntype PersistedCache = {\n state: DehydratedState;\n timestamp: number;\n};\n\nexport class BaseDataService<\n ServiceName extends string,\n ServiceMessenger extends BaseMessenger<ServiceName>,\n> {\n public readonly name: ServiceName;\n\n readonly #messenger: Messenger<\n ServiceName,\n DataServiceActions<ServiceName>,\n DataServiceEvents<ServiceName>\n >;\n\n readonly #externalMessenger: Messenger<\n ServiceName,\n DataServiceAllowedActions\n >;\n\n protected messenger: ServiceMessenger;\n\n readonly #policy: ServicePolicy;\n\n readonly #queryClient: QueryClient;\n\n readonly #queryCacheUnsubscribe: () => void;\n\n readonly #mutationCacheUnsubscribe: () => void;\n\n readonly #debouncedPersist?: DebouncedFunc<() => void>;\n\n readonly #persistenceConfig?: PersistenceConfiguration;\n\n constructor({\n name,\n messenger,\n queryClientConfig = {},\n policyOptions,\n persistenceConfig,\n }: {\n name: ServiceName;\n messenger: DataServiceActions<ServiceName>['type'] extends\n | MessengerActions<ServiceMessenger>['type']\n | DataServiceAllowedActions['type']\n ? DataServiceEvents<ServiceName>['type'] extends MessengerEvents<ServiceMessenger>['type']\n ? ServiceMessenger\n : never\n : never;\n queryClientConfig?: QueryClientConfig;\n policyOptions?: CreateServicePolicyOptions;\n persistenceConfig?: PersistenceConfiguration;\n }) {\n this.name = name;\n\n // We store two narrowly-typed messengers alongside the generic public one:\n // - #messenger handles the service's own action registration and event publishing\n // - #externalMessenger handles calls to external actions\n // Splitting them avoids TypeScript issues with mixing template-literals with regular strings\n this.#messenger = messenger as unknown as Messenger<\n ServiceName,\n DataServiceActions<ServiceName>,\n DataServiceEvents<ServiceName>\n >;\n this.#externalMessenger = messenger as unknown as Messenger<\n ServiceName,\n DataServiceAllowedActions\n >;\n this.messenger = messenger;\n\n this.#queryClient = new QueryClient({\n ...queryClientConfig,\n defaultOptions: {\n queries: {\n ...QUERY_CLIENT_DEFAULTS.queries,\n ...queryClientConfig.defaultOptions?.queries,\n },\n mutations: {\n ...QUERY_CLIENT_DEFAULTS.mutations,\n ...queryClientConfig.defaultOptions?.mutations,\n },\n },\n });\n\n this.#persistenceConfig = persistenceConfig;\n\n this.#policy = createServicePolicy(policyOptions);\n\n this.#debouncedPersist =\n this.#persistenceConfig &&\n debounce(\n () => {\n this.#persistCache().catch(\n /* istanbul ignore next */\n (error) => this.#messenger.captureException?.(error),\n );\n },\n this.#persistenceConfig.writeDelay ??\n inMilliseconds(10, Duration.Second),\n {\n maxWait:\n this.#persistenceConfig.maxWriteDelay ??\n inMilliseconds(1, Duration.Minute),\n },\n );\n\n this.#queryCacheUnsubscribe = this.#queryClient\n .getQueryCache()\n .subscribe((event) => {\n log('Query cache event emitted', event);\n if (['added', 'updated', 'removed'].includes(event.type)) {\n this.#publishCacheUpdate(\n 'query',\n event.type as CacheUpdatedType,\n event.query.queryHash,\n );\n\n this.#debouncedPersist?.();\n }\n });\n\n log('Subscribing to mutation cache');\n this.#mutationCacheUnsubscribe = this.#queryClient\n .getMutationCache()\n .subscribe((event) => {\n log('Mutation cache event emitted', event);\n if (\n ['added', 'updated', 'removed'].includes(event.type) &&\n event.mutation?.options.mutationKey !== undefined\n ) {\n const mutationHash = hashKey(event.mutation.options.mutationKey);\n this.#publishCacheUpdate(\n 'mutation',\n event.type as CacheUpdatedType,\n mutationHash,\n );\n\n this.#debouncedPersist?.();\n }\n });\n\n this.#messenger.registerActionHandler(\n `${this.name}:invalidateQueries`,\n this.invalidateQueries.bind(this),\n );\n }\n\n /**\n * Fetch a query.\n *\n * @param options - The options defining the query. Keep in mind that `queryKey` and `queryFn` are required when using data services.\n * Additionally `retry` and `retryDelay` are not available, retries can be customized using the `servicePolicyOptions`.\n * @param options.queryFn - The query function.\n * @param options.responseStruct - An optional struct for validating the response of the query function.\n * @returns The query results.\n */\n protected async fetchQuery<\n TQueryFnData extends Json,\n TError = DefaultError,\n TDataStruct extends Struct<TQueryFnData> | undefined = undefined,\n TData = TDataStruct extends Struct<infer StructType>\n ? StructType\n : TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >({\n queryFn,\n responseStruct,\n ...options\n }: WithRequired<\n OmitKeyof<\n FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'retry' | 'retryDelay' | 'queryFn'\n >,\n 'queryKey'\n > & {\n queryFn: QueryFunction<TQueryFnData, TQueryKey>;\n responseStruct?: TDataStruct;\n }): Promise<TData> {\n return this.#queryClient.fetchQuery({\n ...options,\n queryFn: async (context) => {\n const response = await this.#policy.execute(() => queryFn(context));\n return processQueryResponse(options.queryKey, response, responseStruct);\n },\n });\n }\n\n /**\n * Fetch a paginated query.\n *\n * @param options - The options defining the query. Keep in mind that `queryKey` and `queryFn` are required when using data services.\n * Additionally `retry` and `retryDelay` are not available, retries can be customized using the `servicePolicyOptions`.\n * @param options.responseStruct - An optional struct for validating the response of the query function.\n * @param pageParam - An optional page parameter.\n * @returns The query result, exclusively the requested page is returned.\n */\n protected async fetchInfiniteQuery<\n TQueryFnData extends Json,\n TError = DefaultError,\n TDataStruct extends Struct<TQueryFnData> | undefined = undefined,\n TData extends TQueryFnData = TDataStruct extends Struct<infer StructType>\n ? StructType\n : TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam extends Json = Json,\n >(\n {\n responseStruct,\n ...options\n }: WithRequired<\n OmitKeyof<\n FetchQueryOptions<\n TQueryFnData,\n TError,\n InfiniteData<TData, TPageParam>,\n TQueryKey,\n TPageParam\n >,\n 'retry' | 'retryDelay' | 'queryFn' | 'initialPageParam'\n >,\n 'queryKey'\n > &\n InfiniteQueryPageParamsOptions<TQueryFnData, TPageParam> & {\n queryFn: QueryFunction<TQueryFnData, TQueryKey, TPageParam>;\n responseStruct?: TDataStruct;\n },\n pageParam?: TPageParam,\n ): Promise<TData> {\n const cache = this.#queryClient.getQueryCache();\n\n const query = cache.find<\n TQueryFnData,\n TError,\n InfiniteData<TData, TPageParam>\n >({\n queryKey: options.queryKey,\n });\n\n if (!query?.state.data || !pageParam) {\n const result = await this.#queryClient.fetchInfiniteQuery({\n ...options,\n initialPageParam: pageParam ?? options.initialPageParam,\n queryFn: async (context) => {\n const response = await this.#policy.execute(async () =>\n options.queryFn({\n ...context,\n pageParam: context.meta?.pageParam ?? context.pageParam,\n }),\n );\n return processQueryResponse(\n options.queryKey,\n response,\n responseStruct,\n );\n },\n });\n\n return result.pages[0];\n }\n\n const { pages, pageParams } = query.state.data;\n const next = options.getNextPageParam(\n pages[pages.length - 1],\n pages,\n pageParams[pageParams.length - 1],\n pageParams,\n );\n\n const direction = deepEqual(pageParam, next) ? 'forward' : 'backward';\n\n const result = await query.fetch(\n { ...query.options, meta: { pageParam } },\n { meta: { fetchMore: { direction } } },\n );\n\n const pageIndex = result.pageParams.findIndex((param) =>\n deepEqual(param, pageParam),\n );\n\n return result.pages[pageIndex];\n }\n\n /**\n * Execute a mutation (e.g. a request that is expected to change server-side data).\n * Unlike `fetchQuery`, the request will not be cached or retried.\n *\n * @param options - The options defining the mutation. Keep in mind that `mutationKey` and `mutationFn` are required when using data services.\n * Additionally, `retry` and `retryDelay` are not available.\n * @param options.mutationFn - The mutation function.\n * @param options.responseStruct - An optional struct for validating the response of the mutation function.\n * @param options.globalId - A string which uniquely identifies this mutation\n * across different query clients — specifically, the one in this data service\n * and the one that `createUIQueryClient` in `@metamask/react-data-query`\n * holds (in fact usually you don't need to pass this — `createUIQueryClient`\n * will do it automatically). This global ID will be stored in the new\n * mutation `meta` data and included in `:cacheUpdated` payloads.\n * @returns The mutation results.\n */\n protected async executeMutation<\n TMutationFnData extends Json,\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 TDataStruct extends Struct<any> | undefined = undefined,\n TData = TDataStruct extends Struct<infer StructType>\n ? StructType\n : TMutationFnData,\n TError = DefaultError,\n TOnMutateResult = unknown,\n TMutationKey extends MutationKey = MutationKey,\n >({\n mutationFn,\n responseStruct,\n globalId,\n ...options\n }: OmitKeyof<\n MutationOptions<TData, TError, Record<never, never>, TOnMutateResult>,\n 'retry' | 'retryDelay' | 'mutationKey' | 'mutationFn'\n > & {\n mutationKey: TMutationKey;\n mutationFn: MutationFunction<TMutationFnData, Record<never, never>>;\n responseStruct?: TDataStruct;\n globalId?: string;\n }): Promise<TData> {\n const mutationCache = this.#queryClient.getMutationCache();\n const mutation = mutationCache.build<\n TData,\n TError,\n Record<never, never>,\n TOnMutateResult\n >(this.#queryClient, {\n ...options,\n ...(globalId !== undefined && {\n meta: { ...options.meta, globalId },\n }),\n mutationFn: async (...args) => {\n // To guard against mutations being retried, we deliberately execute the\n // mutation function through the circuit breaker policy alone, rather\n // than through `this.#policy` (which is a combination of both a\n // circuit breaker policy and retry policy).\n const response = await this.#policy.circuitBreakerPolicy.execute(() =>\n mutationFn(...args),\n );\n return processMutationResponse(\n options.mutationKey,\n response,\n responseStruct,\n );\n },\n });\n // We purposely pass an empty set of variables because this method is\n // intended to be used internally by the data service, not end users, and\n // the data service has full control of `mutationFn` anyway.\n return await mutation.execute({});\n }\n\n /**\n * Invalidate queries serviced by this data service.\n *\n * @param filters - Optional filter for selecting specific queries.\n * @param options - Additional optional options for query invalidations.\n * @returns Nothing.\n */\n async invalidateQueries(\n filters?: InvalidateQueryFilters<QueryKey>,\n options?: InvalidateOptions,\n ): Promise<void> {\n return this.#queryClient.invalidateQueries(filters, options);\n }\n\n /**\n * Initialize the service, rehydrating the cache with persisted data if possible.\n */\n init(): void {\n this.#loadCache().catch(\n /* istanbul ignore next */\n (error) => this.#messenger.captureException?.(error),\n );\n }\n\n /**\n * Prepares the service for garbage collection. This should be extended\n * by any subclasses to clean up any additional connections or events.\n */\n destroy(): void {\n this.#debouncedPersist?.cancel();\n this.#queryCacheUnsubscribe();\n this.#mutationCacheUnsubscribe();\n // `QueryClient.clear()` clears both caches, but `MutationCache.clear()`\n // only drops its references to mutations without clearing their pending\n // garbage-collection timers. We destroy each mutation first so those timers\n // are cleared and do not keep the process alive.\n for (const mutation of this.#queryClient.getMutationCache().getAll()) {\n mutation.destroy();\n }\n this.#queryClient.clear();\n this.messenger.clearSubscriptions();\n this.messenger.clearActions();\n }\n\n /**\n * Publish `cacheUpdated` events when the query or mutation cache is updated.\n *\n * @param objectType - The type of object updated (\"query\" or \"mutation\").\n * @param eventType - What happened to the query or mutation (\"added\" or \"updated\").\n * @param hash - The hash of the query or mutation.\n */\n #publishCacheUpdate(\n objectType: 'query' | 'mutation',\n eventType: CacheUpdatedType,\n hash: string,\n ): void {\n const state =\n eventType === 'added' || eventType === 'updated'\n ? dehydrate(this.#queryClient, {\n shouldDehydrateQuery: (query) =>\n objectType === 'query' && query.queryHash === hash,\n shouldDehydrateMutation: (mutation) =>\n objectType === 'mutation' &&\n mutation.options.mutationKey !== undefined &&\n hashKey(mutation.options.mutationKey) === hash,\n })\n : null;\n\n this.#messenger.publish(\n `${this.name}:cacheUpdated` as const,\n {\n type: eventType,\n objectType,\n hash,\n state,\n } as DataServiceCacheUpdatedPayload,\n );\n this.#messenger.publish(\n `${this.name}:cacheUpdated:${hash}` as const,\n {\n type: eventType,\n objectType,\n state,\n } as DataServiceGranularCacheUpdatedPayload,\n );\n }\n\n /**\n * Persist the query client cache using the StorageService, if the cache is not empty.\n *\n * @returns Nothing.\n */\n async #persistCache(): Promise<void> {\n const state = dehydrate(this.#queryClient, {\n // This is the default, but we specify it to be explicit.\n shouldDehydrateQuery: (query) => query.state.status === 'success',\n });\n\n if (state.queries.length === 0 && state.mutations.length === 0) {\n await this.#externalMessenger.call(\n 'StorageService:removeItem',\n this.name,\n STORAGE_SERVICE_KEY,\n );\n return;\n }\n\n const cache: PersistedCache = {\n timestamp: Date.now(),\n state,\n };\n\n await this.#externalMessenger.call(\n 'StorageService:setItem',\n this.name,\n STORAGE_SERVICE_KEY,\n cache as unknown as Json,\n );\n }\n\n /**\n * Load the query client cache from the StorageService, if persistence is configured\n * and the persisted cache is not expired.\n *\n * @returns Nothing.\n */\n async #loadCache(): Promise<void> {\n if (!this.#persistenceConfig) {\n return;\n }\n\n const { result: untypedCache } = await this.#externalMessenger.call(\n 'StorageService:getItem',\n this.name,\n STORAGE_SERVICE_KEY,\n );\n\n if (!untypedCache) {\n return;\n }\n\n const cache = untypedCache as unknown as PersistedCache;\n\n if (Date.now() - cache.timestamp >= this.#persistenceConfig.maxAge) {\n await this.#externalMessenger.call(\n 'StorageService:removeItem',\n this.name,\n STORAGE_SERVICE_KEY,\n );\n return;\n }\n\n hydrate(this.#queryClient, cache.state);\n }\n}\n"]}
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { Messenger, ActionConstraint, EventConstraint, MessengerActions, MessengerEvents } from "@metamask/messenger";
|
|
2
|
-
import type { StorageServiceGetItemAction, StorageServiceRemoveItemAction, StorageServiceSetItemAction } from "@metamask/storage-service";
|
|
3
|
-
import { Struct } from "@metamask/superstruct";
|
|
4
|
-
import type { Json } from "@metamask/utils";
|
|
5
|
-
import { DefaultError, DehydratedState, FetchQueryOptions, InfiniteData, InfiniteQueryPageParamsOptions, InvalidateOptions, InvalidateQueryFilters, MutationOptions, OmitKeyof, QueryClientConfig, QueryFunction, WithRequired, MutationFunction } from "@tanstack/query-core";
|
|
6
|
-
import { CreateServicePolicyOptions } from "./createServicePolicy.cjs";
|
|
7
|
-
/**
|
|
8
|
-
* Data service mutations and queries use the following format:
|
|
9
|
-
* `['${ServiceName}:${ActionName}', ...params]`
|
|
10
|
-
*/
|
|
11
|
-
type Key = [string, ...Json[]] | readonly [string, ...Json[]];
|
|
12
|
-
export type QueryKey = Key;
|
|
13
|
-
export type MutationKey = Key;
|
|
14
|
-
/**
|
|
15
|
-
* The supertype of all messengers, scoped to a namespace.
|
|
16
|
-
*
|
|
17
|
-
* @template Namespace - The namespace for the messenger's own actions and
|
|
18
|
-
* events.
|
|
19
|
-
*/
|
|
20
|
-
export type BaseMessenger<Namespace extends string> = Messenger<Namespace, ActionConstraint, EventConstraint, any>;
|
|
21
|
-
export type DataServiceGranularCacheUpdatedPayload = {
|
|
22
|
-
objectType: 'query' | 'mutation';
|
|
23
|
-
} & ({
|
|
24
|
-
type: 'added' | 'updated';
|
|
25
|
-
state: DehydratedState;
|
|
26
|
-
} | {
|
|
27
|
-
type: 'removed';
|
|
28
|
-
state: null;
|
|
29
|
-
});
|
|
30
|
-
export type DataServiceCacheUpdatedPayload = DataServiceGranularCacheUpdatedPayload & {
|
|
31
|
-
hash: string;
|
|
32
|
-
};
|
|
33
|
-
export type DataServiceInvalidateQueriesAction<ServiceName extends string> = {
|
|
34
|
-
type: `${ServiceName}:invalidateQueries`;
|
|
35
|
-
handler: BaseDataService<ServiceName, BaseMessenger<ServiceName>>['invalidateQueries'];
|
|
36
|
-
};
|
|
37
|
-
export type DataServiceActions<ServiceName extends string> = DataServiceInvalidateQueriesAction<ServiceName>;
|
|
38
|
-
type DataServiceAllowedActions = StorageServiceGetItemAction | StorageServiceSetItemAction | StorageServiceRemoveItemAction;
|
|
39
|
-
export type DataServiceCacheUpdatedEvent<ServiceName extends string> = {
|
|
40
|
-
type: `${ServiceName}:cacheUpdated`;
|
|
41
|
-
payload: [DataServiceCacheUpdatedPayload];
|
|
42
|
-
};
|
|
43
|
-
export type DataServiceGranularCacheUpdatedEvent<ServiceName extends string> = {
|
|
44
|
-
type: `${ServiceName}:cacheUpdated:${string}`;
|
|
45
|
-
payload: [DataServiceGranularCacheUpdatedPayload];
|
|
46
|
-
};
|
|
47
|
-
export type DataServiceEvents<ServiceName extends string> = DataServiceCacheUpdatedEvent<ServiceName> | DataServiceGranularCacheUpdatedEvent<ServiceName>;
|
|
48
|
-
export declare const STORAGE_SERVICE_KEY = "cache";
|
|
49
|
-
/**
|
|
50
|
-
* Options for persistence configuration.
|
|
51
|
-
*/
|
|
52
|
-
export type PersistenceConfiguration = {
|
|
53
|
-
/**
|
|
54
|
-
* The maximum age before the cache is treated as expired in milliseconds.
|
|
55
|
-
* This is relevant for rehydrating the state during initialization,
|
|
56
|
-
* if the cached state is too old it will be discarded.
|
|
57
|
-
*/
|
|
58
|
-
maxAge: number;
|
|
59
|
-
/**
|
|
60
|
-
* The number of milliseconds to wait before triggering persistence following a cache update.
|
|
61
|
-
*/
|
|
62
|
-
writeDelay?: number;
|
|
63
|
-
/**
|
|
64
|
-
* The maximum number of milliseconds to wait between persistence writes.
|
|
65
|
-
*/
|
|
66
|
-
maxWriteDelay?: number;
|
|
67
|
-
};
|
|
68
|
-
export declare class BaseDataService<ServiceName extends string, ServiceMessenger extends BaseMessenger<ServiceName>> {
|
|
69
|
-
#private;
|
|
70
|
-
readonly name: ServiceName;
|
|
71
|
-
protected messenger: ServiceMessenger;
|
|
72
|
-
constructor({ name, messenger, queryClientConfig, policyOptions, persistenceConfig, }: {
|
|
73
|
-
name: ServiceName;
|
|
74
|
-
messenger: DataServiceActions<ServiceName>['type'] extends MessengerActions<ServiceMessenger>['type'] | DataServiceAllowedActions['type'] ? DataServiceEvents<ServiceName>['type'] extends MessengerEvents<ServiceMessenger>['type'] ? ServiceMessenger : never : never;
|
|
75
|
-
queryClientConfig?: QueryClientConfig;
|
|
76
|
-
policyOptions?: CreateServicePolicyOptions;
|
|
77
|
-
persistenceConfig?: PersistenceConfiguration;
|
|
78
|
-
});
|
|
79
|
-
/**
|
|
80
|
-
* Fetch a query.
|
|
81
|
-
*
|
|
82
|
-
* @param options - The options defining the query. Keep in mind that `queryKey` and `queryFn` are required when using data services.
|
|
83
|
-
* Additionally `retry` and `retryDelay` are not available, retries can be customized using the `servicePolicyOptions`.
|
|
84
|
-
* @param options.queryFn - The query function.
|
|
85
|
-
* @param options.responseStruct - An optional struct for validating the response of the query function.
|
|
86
|
-
* @returns The query results.
|
|
87
|
-
*/
|
|
88
|
-
protected fetchQuery<TQueryFnData extends Json, TError = DefaultError, TDataStruct extends Struct<TQueryFnData> | undefined = undefined, TData = TDataStruct extends Struct<infer StructType> ? StructType : TQueryFnData, TQueryKey extends QueryKey = QueryKey>({ queryFn, responseStruct, ...options }: WithRequired<OmitKeyof<FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'retry' | 'retryDelay' | 'queryFn'>, 'queryKey'> & {
|
|
89
|
-
queryFn: QueryFunction<TQueryFnData, TQueryKey>;
|
|
90
|
-
responseStruct?: TDataStruct;
|
|
91
|
-
}): Promise<TData>;
|
|
92
|
-
/**
|
|
93
|
-
* Fetch a paginated query.
|
|
94
|
-
*
|
|
95
|
-
* @param options - The options defining the query. Keep in mind that `queryKey` and `queryFn` are required when using data services.
|
|
96
|
-
* Additionally `retry` and `retryDelay` are not available, retries can be customized using the `servicePolicyOptions`.
|
|
97
|
-
* @param options.responseStruct - An optional struct for validating the response of the query function.
|
|
98
|
-
* @param pageParam - An optional page parameter.
|
|
99
|
-
* @returns The query result, exclusively the requested page is returned.
|
|
100
|
-
*/
|
|
101
|
-
protected fetchInfiniteQuery<TQueryFnData extends Json, TError = DefaultError, TDataStruct extends Struct<TQueryFnData> | undefined = undefined, TData extends TQueryFnData = TDataStruct extends Struct<infer StructType> ? StructType : TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam extends Json = Json>({ responseStruct, ...options }: WithRequired<OmitKeyof<FetchQueryOptions<TQueryFnData, TError, InfiniteData<TData, TPageParam>, TQueryKey, TPageParam>, 'retry' | 'retryDelay' | 'queryFn' | 'initialPageParam'>, 'queryKey'> & InfiniteQueryPageParamsOptions<TQueryFnData, TPageParam> & {
|
|
102
|
-
queryFn: QueryFunction<TQueryFnData, TQueryKey, TPageParam>;
|
|
103
|
-
responseStruct?: TDataStruct;
|
|
104
|
-
}, pageParam?: TPageParam): Promise<TData>;
|
|
105
|
-
/**
|
|
106
|
-
* Execute a mutation (e.g. a request that is expected to change server-side data).
|
|
107
|
-
* Unlike `fetchQuery`, the request will not be cached or retried.
|
|
108
|
-
*
|
|
109
|
-
* @param options - The options defining the mutation. Keep in mind that `mutationKey` and `mutationFn` are required when using data services.
|
|
110
|
-
* Additionally, `retry` and `retryDelay` are not available.
|
|
111
|
-
* @param options.mutationFn - The mutation function.
|
|
112
|
-
* @param options.responseStruct - An optional struct for validating the response of the mutation function.
|
|
113
|
-
* @param options.globalId - A string which uniquely identifies this mutation
|
|
114
|
-
* across different query clients — specifically, the one in this data service
|
|
115
|
-
* and the one that `createUIQueryClient` in `@metamask/react-data-query`
|
|
116
|
-
* holds (in fact usually you don't need to pass this — `createUIQueryClient`
|
|
117
|
-
* will do it automatically). This global ID will be stored in the new
|
|
118
|
-
* mutation `meta` data and included in `:cacheUpdated` payloads.
|
|
119
|
-
* @returns The mutation results.
|
|
120
|
-
*/
|
|
121
|
-
protected executeMutation<TMutationFnData extends Json, TDataStruct extends Struct<any> | undefined = undefined, TData = TDataStruct extends Struct<infer StructType> ? StructType : TMutationFnData, TError = DefaultError, TOnMutateResult = unknown, TMutationKey extends MutationKey = MutationKey>({ mutationFn, responseStruct, globalId, ...options }: OmitKeyof<MutationOptions<TData, TError, Record<never, never>, TOnMutateResult>, 'retry' | 'retryDelay' | 'mutationKey' | 'mutationFn'> & {
|
|
122
|
-
mutationKey: TMutationKey;
|
|
123
|
-
mutationFn: MutationFunction<TMutationFnData, Record<never, never>>;
|
|
124
|
-
responseStruct?: TDataStruct;
|
|
125
|
-
globalId?: string;
|
|
126
|
-
}): Promise<TData>;
|
|
127
|
-
/**
|
|
128
|
-
* Invalidate queries serviced by this data service.
|
|
129
|
-
*
|
|
130
|
-
* @param filters - Optional filter for selecting specific queries.
|
|
131
|
-
* @param options - Additional optional options for query invalidations.
|
|
132
|
-
* @returns Nothing.
|
|
133
|
-
*/
|
|
134
|
-
invalidateQueries(filters?: InvalidateQueryFilters<QueryKey>, options?: InvalidateOptions): Promise<void>;
|
|
135
|
-
/**
|
|
136
|
-
* Initialize the service, rehydrating the cache with persisted data if possible.
|
|
137
|
-
*/
|
|
138
|
-
init(): void;
|
|
139
|
-
/**
|
|
140
|
-
* Prepares the service for garbage collection. This should be extended
|
|
141
|
-
* by any subclasses to clean up any additional connections or events.
|
|
142
|
-
*/
|
|
143
|
-
destroy(): void;
|
|
144
|
-
}
|
|
145
|
-
export {};
|
|
146
|
-
//# sourceMappingURL=BaseDataService.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BaseDataService.d.cts","sourceRoot":"","sources":["../src/BaseDataService.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,eAAe,EAChB,4BAA4B;AAC7B,OAAO,KAAK,EACV,2BAA2B,EAC3B,8BAA8B,EAC9B,2BAA2B,EAC5B,kCAAkC;AACnC,OAAO,EAAE,MAAM,EAAE,8BAA8B;AAE/C,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAC5C,OAAO,EACL,YAAY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