UNPKG

7.82 kBSource Map (JSON)View Raw
1{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/cache/inmemory/helpers.ts"],"names":[],"mappings":"AAUA,OAAO,EAEL,WAAW,EAGX,OAAO,EACP,UAAU,EACV,sBAAsB,EACtB,aAAa,EACb,eAAe,EACf,OAAO,EAGP,iBAAiB,EACjB,sBAAsB,EACtB,OAAO,GACR,MAAM,iBAAiB,CAAC;AAEzB,MAAM,CACJ,IAAgB,MAAM,GACpB,MAAM,CAAC,SAAS,eADI,CACH;AAErB,MAAM,UAAU,SAAS,CAAC,KAAU;IAClC,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,KAAK,CAAC,CAAC;AAC5C,CAAC;AAED,OAAO,EAAE,OAAO,EAAE,CAAC;AAEnB,MAAM,UAAU,uBAAuB,CACrC,EAA8C,EAC9C,OAA0B;QADxB,UAAU,gBAAA,EAAE,EAAE,QAAA,EAAE,GAAG,SAAA;IAGrB,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;QAClC,IAAI,OAAO,EAAE;YACX,OAAO,CAAC,SAAS;gBACf,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,IAAA,EAAE,CAAC,CAAC;oBACzB,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,KAAA,EAAE,CAAC,CAAC;wBAC3B,KAAK,CAAC,CAAC;SACV;QAGD,IAAI,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE;YACpC,EAAE,GAAG,GAAG,CAAC;SACV;QAED,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE;YAClB,OAAO,UAAG,UAAU,cAAI,CACtB,OAAO,EAAE,KAAK,QAAQ;gBACtB,OAAO,EAAE,KAAK,QAAQ,CACvB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CA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DefinitionNode, SelectionSetNode } from 'graphql';\n\nimport {\n NormalizedCache,\n InMemoryCacheConfig,\n} from './types';\n\nimport { KeyFieldsContext } from './policies';\nimport { FragmentRegistryAPI } from './fragmentRegistry';\n\nimport {\n Reference,\n isReference,\n StoreValue,\n StoreObject,\n isField,\n DeepMerger,\n resultKeyNameFromField,\n shouldInclude,\n isNonNullObject,\n compact,\n FragmentMap,\n FragmentMapFunction,\n createFragmentMap,\n getFragmentDefinitions,\n isArray,\n} from '../../utilities';\n\nexport const {\n hasOwnProperty: hasOwn,\n} = Object.prototype;\n\nexport function isNullish(value: any): value is null | undefined {\n return value === null || value === void 0;\n}\n\nexport { isArray };\n\nexport function defaultDataIdFromObject(\n { __typename, id, _id }: Readonly<StoreObject>,\n context?: KeyFieldsContext,\n): string | undefined {\n if (typeof __typename === \"string\") {\n if (context) {\n context.keyObject =\n !isNullish(id) ? { id } :\n !isNullish(_id) ? { _id } :\n void 0;\n }\n\n // If there is no object.id, fall back to object._id.\n if (isNullish(id) && !isNullish(_id)) {\n id = _id;\n }\n\n if (!isNullish(id)) {\n return `${__typename}:${(\n typeof id === \"number\" ||\n typeof id === \"string\"\n ) ? id : JSON.stringify(id)}`;\n }\n }\n}\n\nconst defaultConfig = {\n dataIdFromObject: defaultDataIdFromObject,\n addTypename: true,\n resultCaching: true,\n // Thanks to the shouldCanonizeResults helper, this should be the only line\n // you have to change to reenable canonization by default in the future.\n canonizeResults: false,\n};\n\nexport function normalizeConfig(config: InMemoryCacheConfig) {\n return compact(defaultConfig, config);\n}\n\nexport function shouldCanonizeResults(\n config: Pick<InMemoryCacheConfig, \"canonizeResults\">,\n): boolean {\n const value = config.canonizeResults;\n return value === void 0 ? defaultConfig.canonizeResults : value;\n}\n\nexport function getTypenameFromStoreObject(\n store: NormalizedCache,\n objectOrReference: StoreObject | Reference,\n): string | undefined {\n return isReference(objectOrReference)\n ? store.get(objectOrReference.__ref, \"__typename\") as string\n : objectOrReference && objectOrReference.__typename;\n}\n\nexport const TypeOrFieldNameRegExp = /^[_a-z][_0-9a-z]*/i;\n\nexport function fieldNameFromStoreName(storeFieldName: string): string {\n const match = storeFieldName.match(TypeOrFieldNameRegExp);\n return match ? match[0] : storeFieldName;\n}\n\nexport function selectionSetMatchesResult(\n selectionSet: SelectionSetNode,\n result: Record<string, any>,\n variables?: Record<string, any>,\n): boolean {\n if (isNonNullObject(result)) {\n return isArray(result)\n ? result.every(item => selectionSetMatchesResult(selectionSet, item, variables))\n : selectionSet.selections.every(field => {\n if (isField(field) && shouldInclude(field, variables)) {\n const key = resultKeyNameFromField(field);\n return hasOwn.call(result, key) &&\n (!field.selectionSet ||\n selectionSetMatchesResult(field.selectionSet, result[key], variables));\n }\n // If the selection has been skipped with @skip(true) or\n // @include(false), it should not count against the matching. If\n // the selection is not a field, it must be a fragment (inline or\n // named). We will determine if selectionSetMatchesResult for that\n // fragment when we get to it, so for now we return true.\n return true;\n });\n }\n return false;\n}\n\nexport function storeValueIsStoreObject(\n value: StoreValue,\n): value is StoreObject {\n return isNonNullObject(value) &&\n !isReference(value) &&\n !isArray(value);\n}\n\nexport function makeProcessedFieldsMerger() {\n return new DeepMerger;\n}\n\nexport function extractFragmentContext(\n document: DocumentNode,\n fragments?: FragmentRegistryAPI,\n): {\n fragmentMap: FragmentMap;\n lookupFragment: FragmentMapFunction;\n} {\n // FragmentMap consisting only of fragments defined directly in document, not\n // including other fragments registered in the FragmentRegistry.\n const fragmentMap = createFragmentMap(getFragmentDefinitions(document));\n return {\n fragmentMap,\n lookupFragment(name) {\n let def: FragmentDefinitionNode | null = fragmentMap[name];\n if (!def && fragments) {\n def = fragments.lookup(name);\n }\n return def || null;\n },\n };\n}\n"]}
\No newline at end of file