1 | import { __assign, __rest } from "tslib";
|
2 | import { wrap } from 'optimism';
|
3 | import { getFragmentQueryDocument, } from "../../utilities/index.js";
|
4 | var ApolloCache = (function () {
|
5 | function ApolloCache() {
|
6 | this.getFragmentDoc = wrap(getFragmentQueryDocument);
|
7 | }
|
8 | ApolloCache.prototype.batch = function (options) {
|
9 | var _this = this;
|
10 | var optimisticId = typeof options.optimistic === "string" ? options.optimistic :
|
11 | options.optimistic === false ? null : void 0;
|
12 | var updateResult;
|
13 | this.performTransaction(function () { return updateResult = options.update(_this); }, optimisticId);
|
14 | return updateResult;
|
15 | };
|
16 | ApolloCache.prototype.recordOptimisticTransaction = function (transaction, optimisticId) {
|
17 | this.performTransaction(transaction, optimisticId);
|
18 | };
|
19 | ApolloCache.prototype.transformDocument = function (document) {
|
20 | return document;
|
21 | };
|
22 | ApolloCache.prototype.transformForLink = function (document) {
|
23 | return document;
|
24 | };
|
25 | ApolloCache.prototype.identify = function (object) {
|
26 | return;
|
27 | };
|
28 | ApolloCache.prototype.gc = function () {
|
29 | return [];
|
30 | };
|
31 | ApolloCache.prototype.modify = function (options) {
|
32 | return false;
|
33 | };
|
34 | ApolloCache.prototype.readQuery = function (options, optimistic) {
|
35 | if (optimistic === void 0) { optimistic = !!options.optimistic; }
|
36 | return this.read(__assign(__assign({}, options), { rootId: options.id || 'ROOT_QUERY', optimistic: optimistic }));
|
37 | };
|
38 | ApolloCache.prototype.readFragment = function (options, optimistic) {
|
39 | if (optimistic === void 0) { optimistic = !!options.optimistic; }
|
40 | return this.read(__assign(__assign({}, options), { query: this.getFragmentDoc(options.fragment, options.fragmentName), rootId: options.id, optimistic: optimistic }));
|
41 | };
|
42 | ApolloCache.prototype.writeQuery = function (_a) {
|
43 | var id = _a.id, data = _a.data, options = __rest(_a, ["id", "data"]);
|
44 | return this.write(Object.assign(options, {
|
45 | dataId: id || 'ROOT_QUERY',
|
46 | result: data,
|
47 | }));
|
48 | };
|
49 | ApolloCache.prototype.writeFragment = function (_a) {
|
50 | var id = _a.id, data = _a.data, fragment = _a.fragment, fragmentName = _a.fragmentName, options = __rest(_a, ["id", "data", "fragment", "fragmentName"]);
|
51 | return this.write(Object.assign(options, {
|
52 | query: this.getFragmentDoc(fragment, fragmentName),
|
53 | dataId: id,
|
54 | result: data,
|
55 | }));
|
56 | };
|
57 | ApolloCache.prototype.updateQuery = function (options, update) {
|
58 | return this.batch({
|
59 | update: function (cache) {
|
60 | var value = cache.readQuery(options);
|
61 | var data = update(value);
|
62 | if (data === void 0 || data === null)
|
63 | return value;
|
64 | cache.writeQuery(__assign(__assign({}, options), { data: data }));
|
65 | return data;
|
66 | },
|
67 | });
|
68 | };
|
69 | ApolloCache.prototype.updateFragment = function (options, update) {
|
70 | return this.batch({
|
71 | update: function (cache) {
|
72 | var value = cache.readFragment(options);
|
73 | var data = update(value);
|
74 | if (data === void 0 || data === null)
|
75 | return value;
|
76 | cache.writeFragment(__assign(__assign({}, options), { data: data }));
|
77 | return data;
|
78 | },
|
79 | });
|
80 | };
|
81 | return ApolloCache;
|
82 | }());
|
83 | export { ApolloCache };
|
84 |
|
\ | No newline at end of file |