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