1 | import { isReference, isField, DeepMerger, resultKeyNameFromField, shouldInclude, isNonNullObject, compact, createFragmentMap, getFragmentDefinitions, isArray, } from "../../utilities/index.js";
|
2 | export var hasOwn = Object.prototype.hasOwnProperty;
|
3 | export function isNullish(value) {
|
4 | return value === null || value === void 0;
|
5 | }
|
6 | export { isArray };
|
7 | export function defaultDataIdFromObject(_a, context) {
|
8 | var __typename = _a.__typename, id = _a.id, _id = _a._id;
|
9 | if (typeof __typename === "string") {
|
10 | if (context) {
|
11 | context.keyObject =
|
12 | !isNullish(id) ? { id: id }
|
13 | : !isNullish(_id) ? { _id: _id }
|
14 | : void 0;
|
15 | }
|
16 |
|
17 | if (isNullish(id) && !isNullish(_id)) {
|
18 | id = _id;
|
19 | }
|
20 | if (!isNullish(id)) {
|
21 | return "".concat(__typename, ":").concat(typeof id === "number" || typeof id === "string" ?
|
22 | id
|
23 | : JSON.stringify(id));
|
24 | }
|
25 | }
|
26 | }
|
27 | var defaultConfig = {
|
28 | dataIdFromObject: defaultDataIdFromObject,
|
29 | addTypename: true,
|
30 | resultCaching: true,
|
31 |
|
32 |
|
33 | canonizeResults: false,
|
34 | };
|
35 | export function normalizeConfig(config) {
|
36 | return compact(defaultConfig, config);
|
37 | }
|
38 | export function shouldCanonizeResults(config) {
|
39 | var value = config.canonizeResults;
|
40 | return value === void 0 ? defaultConfig.canonizeResults : value;
|
41 | }
|
42 | export function getTypenameFromStoreObject(store, objectOrReference) {
|
43 | return isReference(objectOrReference) ?
|
44 | store.get(objectOrReference.__ref, "__typename")
|
45 | : objectOrReference && objectOrReference.__typename;
|
46 | }
|
47 | export var TypeOrFieldNameRegExp = /^[_a-z][_0-9a-z]*/i;
|
48 | export function fieldNameFromStoreName(storeFieldName) {
|
49 | var match = storeFieldName.match(TypeOrFieldNameRegExp);
|
50 | return match ? match[0] : storeFieldName;
|
51 | }
|
52 | export function selectionSetMatchesResult(selectionSet, result, variables) {
|
53 | if (isNonNullObject(result)) {
|
54 | return isArray(result) ?
|
55 | result.every(function (item) {
|
56 | return selectionSetMatchesResult(selectionSet, item, variables);
|
57 | })
|
58 | : selectionSet.selections.every(function (field) {
|
59 | if (isField(field) && shouldInclude(field, variables)) {
|
60 | var key = resultKeyNameFromField(field);
|
61 | return (hasOwn.call(result, key) &&
|
62 | (!field.selectionSet ||
|
63 | selectionSetMatchesResult(field.selectionSet, result[key], variables)));
|
64 | }
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 | return true;
|
71 | });
|
72 | }
|
73 | return false;
|
74 | }
|
75 | export function storeValueIsStoreObject(value) {
|
76 | return isNonNullObject(value) && !isReference(value) && !isArray(value);
|
77 | }
|
78 | export function makeProcessedFieldsMerger() {
|
79 | return new DeepMerger();
|
80 | }
|
81 | export function extractFragmentContext(document, fragments) {
|
82 |
|
83 |
|
84 | var fragmentMap = createFragmentMap(getFragmentDefinitions(document));
|
85 | return {
|
86 | fragmentMap: fragmentMap,
|
87 | lookupFragment: function (name) {
|
88 | var def = fragmentMap[name];
|
89 | if (!def && fragments) {
|
90 | def = fragments.lookup(name);
|
91 | }
|
92 | return def || null;
|
93 | },
|
94 | };
|
95 | }
|
96 |
|
\ | No newline at end of file |