{
  "version": 3,
  "sources": ["../src/resolvers-cache-middleware.ts"],
  "sourcesContent": ["/**\n * External dependencies\n */\nimport type { Middleware } from 'redux';\n\n/**\n * Internal dependencies\n */\nimport type { DataRegistry } from './types';\n\n/**\n * Creates a middleware handling resolvers cache invalidation.\n *\n * @param registry  Registry for which to create the middleware.\n * @param storeName Name of the store for which to create the middleware.\n *\n * @return Middleware function.\n */\nconst createResolversCacheMiddleware =\n\t( registry: DataRegistry, storeName: string ): Middleware =>\n\t() =>\n\t( next ) =>\n\t( action ) => {\n\t\tconst resolvers = registry.select( storeName ).getCachedResolvers();\n\t\tconst resolverEntries =\n\t\t\tObject.entries< Map< string, { status: 'finished' | 'error' } > >(\n\t\t\t\tresolvers\n\t\t\t);\n\t\tresolverEntries.forEach( ( [ selectorName, resolversByArgs ] ) => {\n\t\t\tconst resolver =\n\t\t\t\tregistry.stores[ storeName ]?.resolvers?.[ selectorName ];\n\t\t\tif ( ! resolver || ! resolver.shouldInvalidate ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst { shouldInvalidate } = resolver;\n\t\t\tresolversByArgs.forEach( ( value, args ) => {\n\t\t\t\t// Works around a bug in `EquivalentKeyMap` where `map.delete` merely sets an entry value\n\t\t\t\t// to `undefined` and `map.forEach` then iterates also over these orphaned entries.\n\t\t\t\tif ( value === undefined ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// resolversByArgs is the map Map([ args ] => boolean) storing the cache resolution status for a given selector.\n\t\t\t\t// If the value is \"finished\" or \"error\" it means this resolver has finished its resolution which means we need\n\t\t\t\t// to invalidate it, if it's true it means it's inflight and the invalidation is not necessary.\n\t\t\t\tif ( value.status !== 'finished' && value.status !== 'error' ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( ! shouldInvalidate( action, ...args ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Trigger cache invalidation\n\t\t\t\tregistry\n\t\t\t\t\t.dispatch( storeName )\n\t\t\t\t\t.invalidateResolution( selectorName, args );\n\t\t\t} );\n\t\t} );\n\t\treturn next( action );\n\t};\n\nexport default createResolversCacheMiddleware;\n"],
  "mappings": ";AAkBA,IAAM,iCACL,CAAE,UAAwB,cAC1B,MACA,CAAE,SACF,CAAE,WAAY;AACb,QAAM,YAAY,SAAS,OAAQ,SAAU,EAAE,mBAAmB;AAClE,QAAM,kBACL,OAAO;AAAA,IACN;AAAA,EACD;AACD,kBAAgB,QAAS,CAAE,CAAE,cAAc,eAAgB,MAAO;AACjE,UAAM,WACL,SAAS,OAAQ,SAAU,GAAG,YAAa,YAAa;AACzD,QAAK,CAAE,YAAY,CAAE,SAAS,kBAAmB;AAChD;AAAA,IACD;AACA,UAAM,EAAE,iBAAiB,IAAI;AAC7B,oBAAgB,QAAS,CAAE,OAAO,SAAU;AAG3C,UAAK,UAAU,QAAY;AAC1B;AAAA,MACD;AAKA,UAAK,MAAM,WAAW,cAAc,MAAM,WAAW,SAAU;AAC9D;AAAA,MACD;AAEA,UAAK,CAAE,iBAAkB,QAAQ,GAAG,IAAK,GAAI;AAC5C;AAAA,MACD;AAGA,eACE,SAAU,SAAU,EACpB,qBAAsB,cAAc,IAAK;AAAA,IAC5C,CAAE;AAAA,EACH,CAAE;AACF,SAAO,KAAM,MAAO;AACrB;AAED,IAAO,qCAAQ;",
  "names": []
}
