@graphql-box/connection-resolver 0.1.2 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/lib/browser/index.js +1 -1
  2. package/lib/browser/index.js.map +1 -1
  3. package/lib/browser/production.analysis.txt +29 -29
  4. package/lib/main/helpers/isCursorSupplied.js.map +1 -1
  5. package/lib/main/helpers/requestAndCachePages.js +2 -1
  6. package/lib/main/helpers/requestAndCachePages.js.map +1 -1
  7. package/lib/main/helpers/resolveConnection.js +2 -1
  8. package/lib/main/helpers/resolveConnection.js.map +1 -1
  9. package/lib/main/main/index.js +3 -2
  10. package/lib/main/main/index.js.map +1 -1
  11. package/lib/module/helpers/isCursorSupplied.js.map +1 -1
  12. package/lib/module/helpers/requestAndCachePages.js +5 -2
  13. package/lib/module/helpers/requestAndCachePages.js.map +1 -1
  14. package/lib/module/helpers/resolveConnection.js +5 -2
  15. package/lib/module/helpers/resolveConnection.js.map +1 -1
  16. package/lib/module/main/index.js +6 -3
  17. package/lib/module/main/index.js.map +1 -1
  18. package/lib/types/defs/index.d.ts +25 -22
  19. package/lib/types/defs/index.d.ts.map +1 -1
  20. package/lib/types/helpers/extractNodes.d.ts +1 -1
  21. package/lib/types/helpers/isCursorSupplied.d.ts +2 -2
  22. package/lib/types/helpers/isCursorSupplied.d.ts.map +1 -1
  23. package/lib/types/helpers/requestAndCachePages.d.ts +7 -7
  24. package/lib/types/helpers/requestAndCachePages.d.ts.map +1 -1
  25. package/lib/types/helpers/resolveConnection.d.ts +7 -7
  26. package/lib/types/helpers/resolveConnection.d.ts.map +1 -1
  27. package/lib/types/main/index.d.ts +3 -3
  28. package/lib/types/main/index.d.ts.map +1 -1
  29. package/package-lock.json +18 -0
  30. package/package.json +1 -1
  31. package/src/defs/index.ts +43 -31
  32. package/src/helpers/getPageNumbersToRequest.test.ts +2 -2
  33. package/src/helpers/getStartAndEndIndexes.test.ts +10 -10
  34. package/src/helpers/isCursorSupplied.ts +2 -2
  35. package/src/helpers/requestAndCachePages.ts +8 -6
  36. package/src/helpers/resolveConnection.ts +17 -8
  37. package/src/helpers/retrieveCachedConnection.test.ts +32 -32
  38. package/src/main/index.test.ts +34 -59
  39. package/src/main/index.ts +16 -8
@@ -1,7 +1,8 @@
1
1
  import "core-js/modules/es.promise.js";
2
2
  import cacheCursors from "./cacheCursors";
3
3
  import makeEdges from "./makeEdges";
4
- export default (async (pages, {
4
+
5
+ const requestAndCachePages = async (pages, {
5
6
  cursorCache,
6
7
  getters,
7
8
  groupCursor,
@@ -47,5 +48,7 @@ export default (async (pages, {
47
48
  cachedEdges,
48
49
  errors
49
50
  };
50
- });
51
+ };
52
+
53
+ export default requestAndCachePages;
51
54
  //# sourceMappingURL=requestAndCachePages.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/helpers/requestAndCachePages.ts"],"names":["cacheCursors","makeEdges","pages","cursorCache","getters","groupCursor","makeIDCursor","resourceResolver","errors","cachedEdges","Promise","all","map","page","data","pageResultData","pageResultErrors","headers","pageResultHeaders","length","edges","nodes","node","id","group","totalPages","totalResults","pageNumber","push"],"mappings":";AAEA,OAAOA,YAAP,MAAyB,gBAAzB;AACA,OAAOC,SAAP,MAAsB,aAAtB;AAUA,gBAAe,OACbC,KADa,EAEb;AAAEC,EAAAA,WAAF;AAAeC,EAAAA,OAAf;AAAwBC,EAAAA,WAAxB;AAAqCC,EAAAA,YAArC;AAAmDC,EAAAA;AAAnD,CAFa,KAGV;AACH,QAAMC,MAAe,GAAG,EAAxB;AAEA,QAAMC,WAAW,GAAG,MAAMC,OAAO,CAACC,GAAR,CACxBT,KAAK,CAACU,GAAN,CAAU,MAAMC,IAAN,IAAc;AACtB,UAAM;AAAEC,MAAAA,IAAI,EAAEC,cAAR;AAAwBP,MAAAA,MAAM,EAAEQ,gBAAhC;AAAkDC,MAAAA,OAAO,EAAEC;AAA3D,QAAiF,MAAMX,gBAAgB,CAAC;AAC5GM,MAAAA;AAD4G,KAAD,CAA7G;;AAIA,QAAIE,cAAc,IAAI,EAACC,gBAAD,aAACA,gBAAD,eAACA,gBAAgB,CAAEG,MAAnB,CAAtB,EAAiD;AAC/C,YAAMC,KAAK,GAAGnB,SAAS,CAACG,OAAO,CAACiB,KAAR,CAAcN,cAAd,CAAD,EAAgCO,IAAI,IAAIhB,YAAY,CAACgB,IAAI,CAACC,EAAN,CAApD,CAAvB;AAEA,YAAMvB,YAAY,CAACG,WAAD,EAAc;AAC9BiB,QAAAA,KAD8B;AAE9BI,QAAAA,KAAK,EAAEnB,WAFuB;AAG9BY,QAAAA,OAAO,EAAEC,iBAHqB;AAI9BL,QAAAA,IAJ8B;AAK9BY,QAAAA,UAAU,EAAErB,OAAO,CAACqB,UAAR,CAAmBV,cAAnB,CALkB;AAM9BW,QAAAA,YAAY,EAAEtB,OAAO,CAACsB,YAAR,CAAqBX,cAArB;AANgB,OAAd,CAAlB;AASA,aAAO;AAAEK,QAAAA,KAAF;AAASO,QAAAA,UAAU,EAAEd;AAArB,OAAP;AACD;;AAED,QAAIG,gBAAJ,aAAIA,gBAAJ,eAAIA,gBAAgB,CAAEG,MAAtB,EAA8B;AAC5BX,MAAAA,MAAM,CAACoB,IAAP,CAAY,GAAGZ,gBAAf;AACD;;AAED,WAAO;AAAEI,MAAAA,KAAK,EAAE,EAAT;AAAaO,MAAAA,UAAU,EAAEd;AAAzB,KAAP;AACD,GAzBD,CADwB,CAA1B;AA6BA,SAAO;AAAEJ,IAAAA,WAAF;AAAeD,IAAAA;AAAf,GAAP;AACD,CApCD","sourcesContent":["import Cachemap from \"@cachemap/core\";\nimport { Getters, ResourceResolver } from \"../defs\";\nimport cacheCursors from \"./cacheCursors\";\nimport makeEdges from \"./makeEdges\";\n\nexport type Context = {\n cursorCache: Cachemap;\n getters: Getters;\n groupCursor: string;\n makeIDCursor: (id: string | number) => string;\n resourceResolver: ResourceResolver;\n};\n\nexport default async (\n pages: number[],\n { cursorCache, getters, groupCursor, makeIDCursor, resourceResolver }: Context,\n) => {\n const errors: Error[] = [];\n\n const cachedEdges = await Promise.all(\n pages.map(async page => {\n const { data: pageResultData, errors: pageResultErrors, headers: pageResultHeaders } = await resourceResolver({\n page,\n });\n\n if (pageResultData && !pageResultErrors?.length) {\n const edges = makeEdges(getters.nodes(pageResultData), node => makeIDCursor(node.id));\n\n await cacheCursors(cursorCache, {\n edges,\n group: groupCursor,\n headers: pageResultHeaders,\n page,\n totalPages: getters.totalPages(pageResultData),\n totalResults: getters.totalResults(pageResultData),\n });\n\n return { edges, pageNumber: page };\n }\n\n if (pageResultErrors?.length) {\n errors.push(...pageResultErrors);\n }\n\n return { edges: [], pageNumber: page };\n }),\n );\n\n return { cachedEdges, errors };\n};\n"],"file":"requestAndCachePages.js"}
1
+ {"version":3,"sources":["../../../src/helpers/requestAndCachePages.ts"],"names":["cacheCursors","makeEdges","requestAndCachePages","pages","cursorCache","getters","groupCursor","makeIDCursor","resourceResolver","errors","cachedEdges","Promise","all","map","page","data","pageResultData","pageResultErrors","headers","pageResultHeaders","length","edges","nodes","node","id","group","totalPages","totalResults","pageNumber","push"],"mappings":";AAEA,OAAOA,YAAP,MAAyB,gBAAzB;AACA,OAAOC,SAAP,MAAsB,aAAtB;;AAUA,MAAMC,oBAAoB,GAAG,OAC3BC,KAD2B,EAE3B;AAAEC,EAAAA,WAAF;AAAeC,EAAAA,OAAf;AAAwBC,EAAAA,WAAxB;AAAqCC,EAAAA,YAArC;AAAmDC,EAAAA;AAAnD,CAF2B,KAGxB;AACH,QAAMC,MAAe,GAAG,EAAxB;AAEA,QAAMC,WAAW,GAAG,MAAMC,OAAO,CAACC,GAAR,CACxBT,KAAK,CAACU,GAAN,CAAU,MAAMC,IAAN,IAAc;AACtB,UAAM;AAAEC,MAAAA,IAAI,EAAEC,cAAR;AAAwBP,MAAAA,MAAM,EAAEQ,gBAAhC;AAAkDC,MAAAA,OAAO,EAAEC;AAA3D,QAAiF,MAAMX,gBAAgB,CAAC;AAC5GM,MAAAA;AAD4G,KAAD,CAA7G;;AAIA,QAAIE,cAAc,IAAI,EAACC,gBAAD,aAACA,gBAAD,eAACA,gBAAgB,CAAEG,MAAnB,CAAtB,EAAiD;AAC/C,YAAMC,KAAK,GAAGpB,SAAS,CAACI,OAAO,CAACiB,KAAR,CAAcN,cAAd,CAAD,EAAgCO,IAAI,IAAIhB,YAAY,CAACgB,IAAI,CAACC,EAAN,CAApD,CAAvB;AAEA,YAAMxB,YAAY,CAACI,WAAD,EAAc;AAC9BiB,QAAAA,KAD8B;AAE9BI,QAAAA,KAAK,EAAEnB,WAFuB;AAG9BY,QAAAA,OAAO,EAAEC,iBAHqB;AAI9BL,QAAAA,IAJ8B;AAK9BY,QAAAA,UAAU,EAAErB,OAAO,CAACqB,UAAR,CAAmBV,cAAnB,CALkB;AAM9BW,QAAAA,YAAY,EAAEtB,OAAO,CAACsB,YAAR,CAAqBX,cAArB;AANgB,OAAd,CAAlB;AASA,aAAO;AAAEK,QAAAA,KAAF;AAASO,QAAAA,UAAU,EAAEd;AAArB,OAAP;AACD;;AAED,QAAIG,gBAAJ,aAAIA,gBAAJ,eAAIA,gBAAgB,CAAEG,MAAtB,EAA8B;AAC5BX,MAAAA,MAAM,CAACoB,IAAP,CAAY,GAAGZ,gBAAf;AACD;;AAED,WAAO;AAAEI,MAAAA,KAAK,EAAE,EAAT;AAAaO,MAAAA,UAAU,EAAEd;AAAzB,KAAP;AACD,GAzBD,CADwB,CAA1B;AA6BA,SAAO;AAAEJ,IAAAA,WAAF;AAAeD,IAAAA;AAAf,GAAP;AACD,CApCD;;AAsCA,eAAeP,oBAAf","sourcesContent":["import Cachemap from \"@cachemap/core\";\nimport { Getters, Node, PlainObject, ResourceResolver } from \"../defs\";\nimport cacheCursors from \"./cacheCursors\";\nimport makeEdges from \"./makeEdges\";\n\nexport type Context<Resource extends PlainObject, ResourceNode extends Node> = {\n cursorCache: Cachemap;\n getters: Getters<Resource, ResourceNode>;\n groupCursor: string;\n makeIDCursor: (id: string | number) => string;\n resourceResolver: ResourceResolver<Resource>;\n};\n\nconst requestAndCachePages = async <Resource extends PlainObject, ResourceNode extends Node>(\n pages: number[],\n { cursorCache, getters, groupCursor, makeIDCursor, resourceResolver }: Context<Resource, ResourceNode>,\n) => {\n const errors: Error[] = [];\n\n const cachedEdges = await Promise.all(\n pages.map(async page => {\n const { data: pageResultData, errors: pageResultErrors, headers: pageResultHeaders } = await resourceResolver({\n page,\n });\n\n if (pageResultData && !pageResultErrors?.length) {\n const edges = makeEdges(getters.nodes(pageResultData), node => makeIDCursor(node.id));\n\n await cacheCursors(cursorCache, {\n edges,\n group: groupCursor,\n headers: pageResultHeaders,\n page,\n totalPages: getters.totalPages(pageResultData),\n totalResults: getters.totalResults(pageResultData),\n });\n\n return { edges, pageNumber: page };\n }\n\n if (pageResultErrors?.length) {\n errors.push(...pageResultErrors);\n }\n\n return { edges: [], pageNumber: page };\n }),\n );\n\n return { cachedEdges, errors };\n};\n\nexport default requestAndCachePages;\n"],"file":"requestAndCachePages.js"}
@@ -6,7 +6,8 @@ import { getEndCursor, getStartCursor } from "./getStartAndEndCursors";
6
6
  import mergeCachedEdges from "./mergeCachedEdges";
7
7
  import requestAndCachePages from "./requestAndCachePages";
8
8
  import retrieveCachedConnection from "./retrieveCachedConnection";
9
- export default (async (args, {
9
+
10
+ const resolveConnection = async (args, {
10
11
  cursorCache,
11
12
  getters,
12
13
  groupCursor,
@@ -71,5 +72,7 @@ export default (async (args, {
71
72
  },
72
73
  totalCount: totalResults
73
74
  };
74
- });
75
+ };
76
+
77
+ export default resolveConnection;
75
78
  //# sourceMappingURL=resolveConnection.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/helpers/resolveConnection.ts"],"names":["extractEdges","extractNodes","getInRangeCachedEdges","getEndCursor","getStartCursor","mergeCachedEdges","requestAndCachePages","retrieveCachedConnection","args","cursorCache","getters","groupCursor","makeIDCursor","resourceResolver","resultsPerPage","cachedEdges","hasNextPage","hasPreviousPage","indexes","missingPages","totalResults","length","edges","errors","nodes","pageInfo","endCursor","startCursor","totalCount","missingCachedEdges","mergedCachedEdges","endIndex","end","startIndex","start"],"mappings":";AAEA,OAAOA,YAAP,MAAyB,gBAAzB;AACA,OAAOC,YAAP,MAAyB,gBAAzB;AACA,OAAOC,qBAAP,MAAkC,yBAAlC;AACA,SAASC,YAAT,EAAuBC,cAAvB,QAA6C,yBAA7C;AACA,OAAOC,gBAAP,MAA6B,oBAA7B;AACA,OAAOC,oBAAP,MAAiC,wBAAjC;AACA,OAAOC,wBAAP,MAAqC,4BAArC;AAWA,gBAAe,OACbC,IADa,EAEb;AAAEC,EAAAA,WAAF;AAAeC,EAAAA,OAAf;AAAwBC,EAAAA,WAAxB;AAAqCC,EAAAA,YAArC;AAAmDC,EAAAA,gBAAnD;AAAqEC,EAAAA;AAArE,CAFa,KAGV;AACH,QAAM;AACJC,IAAAA,WADI;AAEJC,IAAAA,WAFI;AAGJC,IAAAA,eAHI;AAIJC,IAAAA,OAJI;AAKJC,IAAAA,YALI;AAMJC,IAAAA;AANI,MAOF,MAAMb,wBAAwB,CAACC,IAAD,EAAO;AACvCC,IAAAA,WADuC;AAEvCE,IAAAA,WAFuC;AAGvCG,IAAAA;AAHuC,GAAP,CAPlC;;AAaA,MAAI,CAACK,YAAY,CAACE,MAAlB,EAA0B;AACxB,UAAMC,KAAK,GAAGtB,YAAY,CAACe,WAAD,CAA1B;AAEA,WAAO;AACLO,MAAAA,KADK;AAELC,MAAAA,MAAM,EAAE,EAFH;AAGLC,MAAAA,KAAK,EAAEvB,YAAY,CAACqB,KAAD,CAHd;AAILG,MAAAA,QAAQ,EAAE;AACRC,QAAAA,SAAS,EAAEvB,YAAY,CAACY,WAAD,CADf;AAERC,QAAAA,WAFQ;AAGRC,QAAAA,eAHQ;AAIRU,QAAAA,WAAW,EAAEvB,cAAc,CAACW,WAAD;AAJnB,OAJL;AAULa,MAAAA,UAAU,EAAER;AAVP,KAAP;AAYD;;AAED,QAAM;AAAEL,IAAAA,WAAW,EAAEc,kBAAf;AAAmCN,IAAAA;AAAnC,MAA8C,MAAMjB,oBAAoB,CAACa,YAAD,EAAe;AAC3FV,IAAAA,WAD2F;AAE3FC,IAAAA,OAF2F;AAG3FC,IAAAA,WAH2F;AAI3FC,IAAAA,YAJ2F;AAK3FC,IAAAA;AAL2F,GAAf,CAA9E;AAQA,QAAMiB,iBAAiB,GAAG5B,qBAAqB,CAACG,gBAAgB,CAACU,WAAD,EAAcc,kBAAd,CAAjB,EAAoD;AACjGE,IAAAA,QAAQ,EAAEb,OAAO,CAACc,GAD+E;AAEjGlB,IAAAA,cAFiG;AAGjGmB,IAAAA,UAAU,EAAEf,OAAO,CAACgB;AAH6E,GAApD,CAA/C;AAMA,QAAMZ,KAAK,GAAGtB,YAAY,CAAC8B,iBAAD,CAA1B;AAEA,SAAO;AACLR,IAAAA,KADK;AAELC,IAAAA,MAFK;AAGLC,IAAAA,KAAK,EAAEvB,YAAY,CAACqB,KAAD,CAHd;AAILG,IAAAA,QAAQ,EAAE;AACRC,MAAAA,SAAS,EAAEvB,YAAY,CAAC2B,iBAAD,CADf;AAERd,MAAAA,WAFQ;AAGRC,MAAAA,eAHQ;AAIRU,MAAAA,WAAW,EAAEvB,cAAc,CAAC0B,iBAAD;AAJnB,KAJL;AAULF,IAAAA,UAAU,EAAER;AAVP,GAAP;AAYD,CA9DD","sourcesContent":["import Cachemap from \"@cachemap/core\";\nimport { ConnectionInputOptions, Getters, ResourceResolver } from \"../defs\";\nimport extractEdges from \"./extractEdges\";\nimport extractNodes from \"./extractNodes\";\nimport getInRangeCachedEdges from \"./getInRangeCachedEdges\";\nimport { getEndCursor, getStartCursor } from \"./getStartAndEndCursors\";\nimport mergeCachedEdges from \"./mergeCachedEdges\";\nimport requestAndCachePages from \"./requestAndCachePages\";\nimport retrieveCachedConnection from \"./retrieveCachedConnection\";\n\nexport type Context = {\n cursorCache: Cachemap;\n getters: Getters;\n groupCursor: string;\n makeIDCursor: (id: string | number) => string;\n resourceResolver: ResourceResolver;\n resultsPerPage: number;\n};\n\nexport default async (\n args: Record<string, any> & ConnectionInputOptions,\n { cursorCache, getters, groupCursor, makeIDCursor, resourceResolver, resultsPerPage }: Context,\n) => {\n const {\n cachedEdges,\n hasNextPage,\n hasPreviousPage,\n indexes,\n missingPages,\n totalResults,\n } = await retrieveCachedConnection(args, {\n cursorCache,\n groupCursor,\n resultsPerPage,\n });\n\n if (!missingPages.length) {\n const edges = extractEdges(cachedEdges);\n\n return {\n edges,\n errors: [],\n nodes: extractNodes(edges),\n pageInfo: {\n endCursor: getEndCursor(cachedEdges),\n hasNextPage,\n hasPreviousPage,\n startCursor: getStartCursor(cachedEdges),\n },\n totalCount: totalResults,\n };\n }\n\n const { cachedEdges: missingCachedEdges, errors } = await requestAndCachePages(missingPages, {\n cursorCache,\n getters,\n groupCursor,\n makeIDCursor,\n resourceResolver,\n });\n\n const mergedCachedEdges = getInRangeCachedEdges(mergeCachedEdges(cachedEdges, missingCachedEdges), {\n endIndex: indexes.end,\n resultsPerPage,\n startIndex: indexes.start,\n });\n\n const edges = extractEdges(mergedCachedEdges);\n\n return {\n edges,\n errors,\n nodes: extractNodes(edges),\n pageInfo: {\n endCursor: getEndCursor(mergedCachedEdges),\n hasNextPage,\n hasPreviousPage,\n startCursor: getStartCursor(mergedCachedEdges),\n },\n totalCount: totalResults,\n };\n};\n"],"file":"resolveConnection.js"}
1
+ {"version":3,"sources":["../../../src/helpers/resolveConnection.ts"],"names":["extractEdges","extractNodes","getInRangeCachedEdges","getEndCursor","getStartCursor","mergeCachedEdges","requestAndCachePages","retrieveCachedConnection","resolveConnection","args","cursorCache","getters","groupCursor","makeIDCursor","resourceResolver","resultsPerPage","cachedEdges","hasNextPage","hasPreviousPage","indexes","missingPages","totalResults","length","edges","errors","nodes","pageInfo","endCursor","startCursor","totalCount","missingCachedEdges","mergedCachedEdges","endIndex","end","startIndex","start"],"mappings":";AAEA,OAAOA,YAAP,MAAyB,gBAAzB;AACA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,OAFmH;AAGnHC,IAAAA,WAHmH;AAInHC,IAAAA,YAJmH;AAKnHC,IAAAA;AALmH,GAAvC,CAA9E;AAQA,QAAMiB,iBAAiB,GAAG7B,qBAAqB,CAACG,gBAAgB,CAACW,WAAD,EAAcc,kBAAd,CAAjB,EAAoD;AACjGE,IAAAA,QAAQ,EAAEb,OAAO,CAACc,GAD+E;AAEjGlB,IAAAA,cAFiG;AAGjGmB,IAAAA,UAAU,EAAEf,OAAO,CAACgB;AAH6E,GAApD,CAA/C;AAMA,QAAMZ,KAAK,GAAGvB,YAAY,CAAC+B,iBAAD,CAA1B;AAEA,SAAO;AACLR,IAAAA,KADK;AAELC,IAAAA,MAFK;AAGLC,IAAAA,KAAK,EAAExB,YAAY,CAACsB,KAAD,CAHd;AAILG,IAAAA,QAAQ,EAAE;AACRC,MAAAA,SAAS,EAAExB,YAAY,CAAC4B,iBAAD,CADf;AAERd,MAAAA,WAFQ;AAGRC,MAAAA,eAHQ;AAIRU,MAAAA,WAAW,EAAExB,cAAc,CAAC2B,iBAAD;AAJnB,KAJL;AAULF,IAAAA,UAAU,EAAER;AAVP,GAAP;AAYD,CArED;;AAuEA,eAAeb,iBAAf","sourcesContent":["import Cachemap from \"@cachemap/core\";\nimport { ConnectionInputOptions, Getters, Node, PlainObject, ResourceResolver } from \"../defs\";\nimport extractEdges from \"./extractEdges\";\nimport extractNodes from \"./extractNodes\";\nimport getInRangeCachedEdges from \"./getInRangeCachedEdges\";\nimport { getEndCursor, getStartCursor } from \"./getStartAndEndCursors\";\nimport mergeCachedEdges from \"./mergeCachedEdges\";\nimport requestAndCachePages from \"./requestAndCachePages\";\nimport retrieveCachedConnection from \"./retrieveCachedConnection\";\n\nexport type Context<Resource extends PlainObject, ResourceNode extends Node> = {\n cursorCache: Cachemap;\n getters: Getters<Resource, ResourceNode>;\n groupCursor: string;\n makeIDCursor: (id: string | number) => string;\n resourceResolver: ResourceResolver<Resource>;\n resultsPerPage: number;\n};\n\nconst resolveConnection = async <Resource extends PlainObject, ResourceNode extends Node>(\n args: PlainObject & ConnectionInputOptions,\n {\n cursorCache,\n getters,\n groupCursor,\n makeIDCursor,\n resourceResolver,\n resultsPerPage,\n }: Context<Resource, ResourceNode>,\n) => {\n const {\n cachedEdges,\n hasNextPage,\n hasPreviousPage,\n indexes,\n missingPages,\n totalResults,\n } = await retrieveCachedConnection(args, {\n cursorCache,\n groupCursor,\n resultsPerPage,\n });\n\n if (!missingPages.length) {\n const edges = extractEdges(cachedEdges);\n\n return {\n edges,\n errors: [],\n nodes: extractNodes(edges),\n pageInfo: {\n endCursor: getEndCursor(cachedEdges),\n hasNextPage,\n hasPreviousPage,\n startCursor: getStartCursor(cachedEdges),\n },\n totalCount: totalResults,\n };\n }\n\n const { cachedEdges: missingCachedEdges, errors } = await requestAndCachePages<Resource, ResourceNode>(missingPages, {\n cursorCache,\n getters,\n groupCursor,\n makeIDCursor,\n resourceResolver,\n });\n\n const mergedCachedEdges = getInRangeCachedEdges(mergeCachedEdges(cachedEdges, missingCachedEdges), {\n endIndex: indexes.end,\n resultsPerPage,\n startIndex: indexes.start,\n });\n\n const edges = extractEdges(mergedCachedEdges);\n\n return {\n edges,\n errors,\n nodes: extractNodes(edges),\n pageInfo: {\n endCursor: getEndCursor(mergedCachedEdges),\n hasNextPage,\n hasPreviousPage,\n startCursor: getStartCursor(mergedCachedEdges),\n },\n totalCount: totalResults,\n };\n};\n\nexport default resolveConnection;\n"],"file":"resolveConnection.js"}
@@ -3,12 +3,13 @@ import isCursorSupplied from "../helpers/isCursorSupplied";
3
3
  import requestAndCachePages from "../helpers/requestAndCachePages";
4
4
  import resolveConnection from "../helpers/resolveConnection";
5
5
  import validateCursor from "../helpers/validateCursor";
6
- export default (({
6
+
7
+ const main = ({
7
8
  cursorCache,
8
9
  createMakeCursors,
9
10
  createResourceResolver,
10
11
  getters,
11
- resolver,
12
+ resolver = result => result,
12
13
  resultsPerPage
13
14
  }) => async (source, args, context, info) => {
14
15
  try {
@@ -78,5 +79,7 @@ export default (({
78
79
  } catch (e) {
79
80
  throw e;
80
81
  }
81
- });
82
+ };
83
+
84
+ export default main;
82
85
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/main/index.ts"],"names":["isCursorSupplied","requestAndCachePages","resolveConnection","validateCursor","cursorCache","createMakeCursors","createResourceResolver","getters","resolver","resultsPerPage","source","args","context","info","makeGroupCursor","makeIDCursor","resourceResolver","groupCursor","cursorError","edges","errors","nodes","pageInfo","hasNextPage","hasPreviousPage","totalCount","has","e"],"mappings":";AAEA,OAAOA,gBAAP,MAA6B,6BAA7B;AACA,OAAOC,oBAAP,MAAiC,iCAAjC;AACA,OAAOC,iBAAP,MAA8B,8BAA9B;AACA,OAAOC,cAAP,MAA2B,2BAA3B;AAEA,gBAAe,CAAC;AACdC,EAAAA,WADc;AAEdC,EAAAA,iBAFc;AAGdC,EAAAA,sBAHc;AAIdC,EAAAA,OAJc;AAKdC,EAAAA,QALc;AAMdC,EAAAA;AANc,CAAD,KAOqB,OAClCC,MADkC,EAElCC,IAFkC,EAGlCC,OAHkC,EAIlCC,IAJkC,KAKV;AACxB,MAAI;AACF,UAAM;AAAEC,MAAAA,eAAF;AAAmBC,MAAAA;AAAnB,QAAoCV,iBAAiB,CAACK,MAAD,EAASC,IAAT,EAAeC,OAAf,EAAwBC,IAAxB,CAA3D;AACA,UAAMG,gBAAgB,GAAGV,sBAAsB,CAACI,MAAD,EAASC,IAAT,EAAeC,OAAf,EAAwBC,IAAxB,CAA/C;AACA,UAAMI,WAAW,GAAGH,eAAe,EAAnC;;AAEA,QAAId,gBAAgB,CAACW,IAAD,CAApB,EAA4B;AAC1B,YAAMO,WAAW,GAAG,MAAMf,cAAc,CAACQ,IAAD,EAAOE,IAAP,EAAa;AACnDT,QAAAA,WADmD;AAEnDa,QAAAA,WAFmD;AAGnDR,QAAAA;AAHmD,OAAb,CAAxC;;AAMA,UAAIS,WAAJ,EAAiB;AACf,eAAOV,QAAQ,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AACD;AACF,CApFD","sourcesContent":["import { GraphQLResolveInfo } from \"graphql\";\nimport { Connection, ConnectionAdapterUserOptions, ConnectionInputOptions } from \"../defs\";\nimport isCursorSupplied from \"../helpers/isCursorSupplied\";\nimport requestAndCachePages from \"../helpers/requestAndCachePages\";\nimport resolveConnection from \"../helpers/resolveConnection\";\nimport validateCursor from \"../helpers/validateCursor\";\n\nexport default ({\n cursorCache,\n createMakeCursors,\n createResourceResolver,\n getters,\n resolver,\n resultsPerPage,\n}: ConnectionAdapterUserOptions) => async (\n source: Record<string, any>,\n args: Record<string, any> & ConnectionInputOptions,\n context: Record<string, any>,\n info: GraphQLResolveInfo,\n): Promise<Connection> => {\n try {\n const { makeGroupCursor, makeIDCursor } = createMakeCursors(source, args, context, info);\n const resourceResolver = createResourceResolver(source, args, context, info);\n const groupCursor = makeGroupCursor();\n\n if (isCursorSupplied(args)) {\n const cursorError = await validateCursor(args, info, {\n cursorCache,\n groupCursor,\n resultsPerPage,\n });\n\n if (cursorError) {\n return resolver({\n edges: [],\n errors: [cursorError],\n nodes: [],\n pageInfo: {\n hasNextPage: false,\n hasPreviousPage: false,\n },\n totalCount: 0,\n });\n }\n\n return resolver(\n await resolveConnection(args, {\n cursorCache,\n getters,\n groupCursor,\n makeIDCursor,\n resourceResolver,\n resultsPerPage,\n }),\n );\n }\n\n if (await cursorCache.has(`${groupCursor}-metadata`)) {\n return resolver(\n await resolveConnection(args, {\n cursorCache,\n getters,\n groupCursor,\n makeIDCursor,\n resourceResolver,\n resultsPerPage,\n }),\n );\n }\n\n await requestAndCachePages([1], {\n cursorCache,\n getters,\n groupCursor,\n makeIDCursor,\n resourceResolver,\n });\n\n return resolver(\n await resolveConnection(args, {\n cursorCache,\n getters,\n groupCursor,\n makeIDCursor,\n resourceResolver,\n resultsPerPage,\n }),\n );\n } catch (e) {\n throw e;\n }\n};\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../src/main/index.ts"],"names":["isCursorSupplied","requestAndCachePages","resolveConnection","validateCursor","main","cursorCache","createMakeCursors","createResourceResolver","getters","resolver","result","resultsPerPage","source","args","context","info","makeGroupCursor","makeIDCursor","resourceResolver","groupCursor","cursorError","edges","errors","nodes","pageInfo","hasNextPage","hasPreviousPage","totalCount","has","e"],"mappings":";AAEA,OAAOA,gBAAP,MAA6B,6BAA7B;AACA,OAAOC,oBAAP,MAAiC,iCAAjC;AACA,OAAOC,iBAAP,MAA8B,8BAA9B;AACA,OAAOC,cAAP,MAA2B,2BAA3B;;AAEA,MAAMC,IAAI,GAAG,CAMX;AACAC,EAAAA,WADA;AAEAC,EAAAA,iBAFA;AAGAC,EAAAA,sBAHA;AAIAC,EAAAA,OAJA;AAKAC,EAAAA,QAAQ,GAAGC,MAAM,IAAIA,MALrB;AAMAC,EAAAA;AANA,CANW,KAamE,OAC9EC,MAD8E,EAE9EC,IAF8E,EAG9EC,OAH8E,EAI9EC,IAJ8E,KAKtD;AACxB,MAAI;AACF,UAAM;AAAEC,MAAAA,eAAF;AAAmBC,MAAAA;AAAnB,QAAoCX,iBAAiB,CAACM,MAAD,EAASC,IAAT,EAAeC,OAAf,EAAwBC,IAAxB,CAA3D;AACA,UAAMG,gBAAgB,GAAGX,sBAAsB,CAACK,MAAD,EAASC,IAAT,EAAeC,OAAf,EAAwBC,IAAxB,CAA/C;AACA,UAAMI,WAAW,GAAGH,eAAe,EAAnC;;AAEA,QAAIhB,gBAAgB,CAACa,IAAD,CAApB,EAA4B;AAC1B,YAAMO,WAAW,GAAG,MAAMjB,cAAc,CAACU,IAAD,EAAOE,IAAP,EAAa;AACnDV,QAAAA,WADmD;AAEnDc,QAAAA,WAFmD;AAGnDR,QAAAA;AAHmD,OAAb,CAAxC;;AAMA,UAAIS,WAAJ,EAAiB;AACf,eAAOX,QAAQ,CAAC;AACdY,UAAAA,KAAK,EAAE,EADO;AAEdC,UAAAA,MAAM,EAAE,CAACF,WAAD,CAFM;AAGdG,UAAAA,KAAK,EAAE,EAHO;AAIdC,UAAAA,QAAQ,EAAE;AACRC,YAAAA,WAAW,EAAE,KADL;AAERC,YAAAA,eAAe,EAAE;AAFT,WAJI;AAQdC,UAAAA,UAAU,EAAE;AARE,SAAD,CAAf;AAUD;;AAED,aAAOlB,QAAQ,CACb,MAAMP,iBAAiB,CAACW,IAAD,EAAO;AAC5BR,QAAAA,WAD4B;AAE5BG,QAAAA,OAF4B;AAG5BW,QAAAA,WAH4B;AAI5BF,QAAAA,YAJ4B;AAK5BC,QAAAA,gBAL4B;AAM5BP,QAAAA;AAN4B,OAAP,CADV,CAAf;AAUD;;AAED,QAAI,MAAMN,WAAW,CAACuB,GAAZ,CAAiB,GAAET,WAAY,WAA/B,CAAV,EAAsD;AACpD,aAAOV,QAAQ,CACb,MAAMP,iBAAiB,CAACW,IAAD,EAAO;AAC5BR,QAAAA,WAD4B;AAE5BG,QAAAA,OAF4B;AAG5BW,QAAAA,WAH4B;AAI5BF,QAAAA,YAJ4B;AAK5BC,QAAAA,gBAL4B;AAM5BP,QAAAA;AAN4B,OAAP,CADV,CAAf;AAUD;;AAED,UAAMV,oBAAoB,CAAyB,CAAC,CAAD,CAAzB,EAA8B;AACtDI,MAAAA,WADsD;AAEtDG,MAAAA,OAFsD;AAGtDW,MAAAA,WAHsD;AAItDF,MAAAA,YAJsD;AAKtDC,MAAAA;AALsD,KAA9B,CAA1B;AAQA,WAAOT,QAAQ,CACb,MAAMP,iBAAiB,CAACW,IAAD,EAAO;AAC5BR,MAAAA,WAD4B;AAE5BG,MAAAA,OAF4B;AAG5BW,MAAAA,WAH4B;AAI5BF,MAAAA,YAJ4B;AAK5BC,MAAAA,gBAL4B;AAM5BP,MAAAA;AAN4B,KAAP,CADV,CAAf;AAUD,GApED,CAoEE,OAAOkB,CAAP,EAAU;AACV,UAAMA,CAAN;AACD;AACF,CA1FD;;AA4FA,eAAezB,IAAf","sourcesContent":["import { GraphQLResolveInfo } from \"graphql\";\nimport { Connection, ConnectionInputOptions, ConnectionResolverUserOptions, Node, PlainObject } from \"../defs\";\nimport isCursorSupplied from \"../helpers/isCursorSupplied\";\nimport requestAndCachePages from \"../helpers/requestAndCachePages\";\nimport resolveConnection from \"../helpers/resolveConnection\";\nimport validateCursor from \"../helpers/validateCursor\";\n\nconst main = <\n Source extends PlainObject,\n Args extends PlainObject,\n Ctx extends PlainObject,\n Resource extends PlainObject,\n ResourceNode extends Node\n>({\n cursorCache,\n createMakeCursors,\n createResourceResolver,\n getters,\n resolver = result => result,\n resultsPerPage,\n}: ConnectionResolverUserOptions<Source, Args, Ctx, Resource, ResourceNode>) => async (\n source: Source,\n args: Args & ConnectionInputOptions,\n context: Ctx,\n info: GraphQLResolveInfo,\n): Promise<Connection> => {\n try {\n const { makeGroupCursor, makeIDCursor } = createMakeCursors(source, args, context, info);\n const resourceResolver = createResourceResolver(source, args, context, info);\n const groupCursor = makeGroupCursor();\n\n if (isCursorSupplied(args)) {\n const cursorError = await validateCursor(args, info, {\n cursorCache,\n groupCursor,\n resultsPerPage,\n });\n\n if (cursorError) {\n return resolver({\n edges: [],\n errors: [cursorError],\n nodes: [],\n pageInfo: {\n hasNextPage: false,\n hasPreviousPage: false,\n },\n totalCount: 0,\n });\n }\n\n return resolver(\n await resolveConnection(args, {\n cursorCache,\n getters,\n groupCursor,\n makeIDCursor,\n resourceResolver,\n resultsPerPage,\n }),\n );\n }\n\n if (await cursorCache.has(`${groupCursor}-metadata`)) {\n return resolver(\n await resolveConnection(args, {\n cursorCache,\n getters,\n groupCursor,\n makeIDCursor,\n resourceResolver,\n resultsPerPage,\n }),\n );\n }\n\n await requestAndCachePages<Resource, ResourceNode>([1], {\n cursorCache,\n getters,\n groupCursor,\n makeIDCursor,\n resourceResolver,\n });\n\n return resolver(\n await resolveConnection(args, {\n cursorCache,\n getters,\n groupCursor,\n makeIDCursor,\n resourceResolver,\n resultsPerPage,\n }),\n );\n } catch (e) {\n throw e;\n }\n};\n\nexport default main;\n"],"file":"index.js"}
@@ -1,10 +1,16 @@
1
1
  import Cachemap from "@cachemap/core";
2
2
  import { GraphQLResolveInfo } from "graphql";
3
+ export declare type PlainObject = {
4
+ [key: string]: any;
5
+ };
6
+ export declare type Node = PlainObject & {
7
+ id: string | number;
8
+ };
3
9
  export declare type Direction = "backward" | "forward";
4
10
  export declare type CursorCacheEntry = {
5
11
  group: string;
6
12
  index: number;
7
- node: Record<string, any>;
13
+ node: Node;
8
14
  page: number;
9
15
  };
10
16
  export declare type CursorGroupMetadata = {
@@ -17,7 +23,7 @@ export declare type CachedEdges = {
17
23
  };
18
24
  export declare type Edge = {
19
25
  cursor: string;
20
- node: Record<string, any>;
26
+ node: Node;
21
27
  };
22
28
  export declare type Indexes = {
23
29
  absolute: number;
@@ -32,39 +38,36 @@ export declare type PageInfo = {
32
38
  export declare type Connection = {
33
39
  edges: Edge[];
34
40
  errors: Error[];
35
- nodes: Record<string, any>[];
41
+ nodes: Node[];
36
42
  pageInfo: PageInfo;
37
43
  totalCount: number;
38
44
  };
39
- export interface ResourceResponse extends Response {
40
- data?: Record<string, any>;
45
+ export interface ResourceResponse<Resource extends PlainObject> extends Response {
46
+ data?: Resource;
41
47
  errors?: Error[];
42
48
  }
43
- export declare type ResourceResolver = (args: {
49
+ export declare type ResourceResolver<Resource extends PlainObject> = (args: {
44
50
  page: number;
45
- }) => Promise<ResourceResponse>;
46
- export declare type CreateResourceResolver = (source: Record<string, any>, args: Record<string, any>, context: Record<string, any>, info: GraphQLResolveInfo) => ResourceResolver;
47
- export declare type Node = Record<string, any> & {
48
- id: string | number;
49
- };
50
- export interface Getters {
51
- nodes: (obj: Record<string, any>) => Node[];
52
- page: (obj: Record<string, any>) => number;
53
- totalPages: (obj: Record<string, any>) => number;
54
- totalResults: (obj: Record<string, any>) => number;
51
+ }) => Promise<ResourceResponse<Resource>>;
52
+ export declare type CreateResourceResolver<Source extends PlainObject, Args extends PlainObject, Ctx extends PlainObject, Resource extends PlainObject> = (source: Source, args: Args, context: Ctx, info: GraphQLResolveInfo) => ResourceResolver<Resource>;
53
+ export interface Getters<Resource extends PlainObject, ResourceNode extends Node> {
54
+ nodes: (obj: Resource) => ResourceNode[];
55
+ page: (obj: Resource) => number;
56
+ totalPages: (obj: Resource) => number;
57
+ totalResults: (obj: Resource) => number;
55
58
  }
56
- export interface ConnectionAdapterUserOptions {
57
- createMakeCursors: (source: Record<string, any>, args: Record<string, any>, context: Record<string, any>, info: GraphQLResolveInfo) => {
59
+ export interface ConnectionResolverUserOptions<Source extends PlainObject, Args extends PlainObject, Ctx extends PlainObject, Resource extends PlainObject, ResourceNode extends Node> {
60
+ createMakeCursors: (source: Source, args: Args, context: Ctx, info: GraphQLResolveInfo) => {
58
61
  makeGroupCursor: () => string;
59
62
  makeIDCursor: (id: string | number) => string;
60
63
  };
61
- createResourceResolver: CreateResourceResolver;
64
+ createResourceResolver: CreateResourceResolver<Source, Args, Ctx, Resource>;
62
65
  cursorCache: Cachemap;
63
- getters: Getters;
64
- resolver: (args: Connection) => Connection;
66
+ getters: Getters<Resource, ResourceNode>;
67
+ resolver?: (args: Connection) => Connection;
65
68
  resultsPerPage: number;
66
69
  }
67
- export declare type ConnectionResolver = (source: Record<string, any>, args: Record<string, any> & ConnectionInputOptions, context: Record<string, any>, info: GraphQLResolveInfo) => Promise<Connection>;
70
+ export declare type ConnectionResolver = (source: PlainObject, args: PlainObject & ConnectionInputOptions, context: PlainObject, info: GraphQLResolveInfo) => Promise<Connection>;
68
71
  export declare type ConnectionInputOptions = {
69
72
  after?: string;
70
73
  before?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/defs/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C,oBAAY,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC;AAE/C,oBAAY,gBAAgB,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,I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AW,EACpB,IAAI,EAAE,kBAAkB,KACrB,OAAO,CAAC,UAAU,CAAC,CAAC;AAEzB,oBAAY,sBAAsB,GAAG;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,oBAAY,OAAO,GAAG;IACpB,KAAK,EAAE,gBAAgB,CAAC;IACxB,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC"}
@@ -1,4 +1,4 @@
1
1
  import { Edge } from "../defs";
2
- declare const _default: (edges: Edge[]) => Record<string, any>[];
2
+ declare const _default: (edges: Edge[]) => import("../defs").Node[];
3
3
  export default _default;
4
4
  //# sourceMappingURL=extractNodes.d.ts.map
@@ -1,4 +1,4 @@
1
- import { ConnectionInputOptions } from "../defs";
2
- declare const _default: ({ after, before }: Record<string, any> & ConnectionInputOptions) => boolean;
1
+ import { ConnectionInputOptions, PlainObject } from "../defs";
2
+ declare const _default: ({ after, before }: PlainObject & ConnectionInputOptions) => boolean;
3
3
  export default _default;
4
4
  //# sourceMappingURL=isCursorSupplied.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"isCursorSupplied.d.ts","sourceRoot":"","sources":["../../../src/helpers/isCursorSupplied.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;4CAEd,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,sBAAsB;AAA/E,wBAAwG"}
1
+ {"version":3,"file":"isCursorSupplied.d.ts","sourceRoot":"","sources":["../../../src/helpers/isCursorSupplied.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;4CAE3B,WAAW,GAAG,sBAAsB;AAAvE,wBAAgG"}
@@ -1,21 +1,21 @@
1
1
  import Cachemap from "@cachemap/core";
2
- import { Getters, ResourceResolver } from "../defs";
3
- export declare type Context = {
2
+ import { Getters, Node, PlainObject, ResourceResolver } from "../defs";
3
+ export declare type Context<Resource extends PlainObject, ResourceNode extends Node> = {
4
4
  cursorCache: Cachemap;
5
- getters: Getters;
5
+ getters: Getters<Resource, ResourceNode>;
6
6
  groupCursor: string;
7
7
  makeIDCursor: (id: string | number) => string;
8
- resourceResolver: ResourceResolver;
8
+ resourceResolver: ResourceResolver<Resource>;
9
9
  };
10
- declare const _default: (pages: number[], { cursorCache, getters, groupCursor, makeIDCursor, resourceResolver }: Context) => Promise<{
10
+ declare const requestAndCachePages: <Resource extends PlainObject, ResourceNode extends Node>(pages: number[], { cursorCache, getters, groupCursor, makeIDCursor, resourceResolver }: Context<Resource, ResourceNode>) => Promise<{
11
11
  cachedEdges: {
12
12
  edges: {
13
- node: import("../defs").Node;
13
+ node: Node;
14
14
  cursor: string;
15
15
  }[];
16
16
  pageNumber: number;
17
17
  }[];
18
18
  errors: Error[];
19
19
  }>;
20
- export default _default;
20
+ export default requestAndCachePages;
21
21
  //# sourceMappingURL=requestAndCachePages.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"requestAndCachePages.d.ts","sourceRoot":"","sources":["../../../src/helpers/requestAndCachePages.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAIpD,oBAAY,OAAO,GAAG;IACpB,WAAW,EAAE,QAAQ,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,KAAK,MAAM,CAAC;IAC9C,gBAAgB,EAAE,gBAAgB,CAAC;CACpC,CAAC;gCAGO,MAAM,EAAE,yEACwD,OAAO;;;;;;;;;;AAFhF,wBAoCE"}
1
+ {"version":3,"file":"requestAndCachePages.d.ts","sourceRoot":"","sources":["../../../src/helpers/requestAndCachePages.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAIvE,oBAAY,OAAO,CAAC,QAAQ,SAAS,WAAW,EAAE,YAAY,SAAS,IAAI,IAAI;IAC7E,WAAW,EAAE,QAAQ,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IACzC,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,KAAK,MAAM,CAAC;IAC9C,gBAAgB,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC;CAC9C,CAAC;AAEF,QAAA,MAAM,oBAAoB,mEACjB,MAAM,EAAE;;;;;;;;;EAmChB,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
@@ -1,17 +1,17 @@
1
1
  import Cachemap from "@cachemap/core";
2
- import { ConnectionInputOptions, Getters, ResourceResolver } from "../defs";
3
- export declare type Context = {
2
+ import { ConnectionInputOptions, Getters, Node, PlainObject, ResourceResolver } from "../defs";
3
+ export declare type Context<Resource extends PlainObject, ResourceNode extends Node> = {
4
4
  cursorCache: Cachemap;
5
- getters: Getters;
5
+ getters: Getters<Resource, ResourceNode>;
6
6
  groupCursor: string;
7
7
  makeIDCursor: (id: string | number) => string;
8
- resourceResolver: ResourceResolver;
8
+ resourceResolver: ResourceResolver<Resource>;
9
9
  resultsPerPage: number;
10
10
  };
11
- declare const _default: (args: Record<string, any> & ConnectionInputOptions, { cursorCache, getters, groupCursor, makeIDCursor, resourceResolver, resultsPerPage }: Context) => Promise<{
11
+ declare const resolveConnection: <Resource extends PlainObject, ResourceNode extends Node>(args: PlainObject & ConnectionInputOptions, { cursorCache, getters, groupCursor, makeIDCursor, resourceResolver, resultsPerPage, }: Context<Resource, ResourceNode>) => Promise<{
12
12
  edges: import("../defs").Edge[];
13
13
  errors: Error[];
14
- nodes: Record<string, any>[];
14
+ nodes: Node[];
15
15
  pageInfo: {
16
16
  endCursor: string;
17
17
  hasNextPage: boolean;
@@ -20,5 +20,5 @@ declare const _default: (args: Record<string, any> & ConnectionInputOptions, { c
20
20
  };
21
21
  totalCount: number;
22
22
  }>;
23
- export default _default;
23
+ export default resolveConnection;
24
24
  //# sourceMappingURL=resolveConnection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolveConnection.d.ts","sourceRoot":"","sources":["../../../src/helpers/resolveConnection.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,sBAAsB,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAS5E,oBAAY,OAAO,GAAG;IACpB,WAAW,EAAE,QAAQ,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,KAAK,MAAM,CAAC;IAC9C,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;+BAGM,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,sBAAsB,yFACqC,OAAO;;;;;;;;;;;;AAFhG,wBA8DE"}
1
+ {"version":3,"file":"resolveConnection.d.ts","sourceRoot":"","sources":["../../../src/helpers/resolveConnection.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,sBAAsB,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAS/F,oBAAY,OAAO,CAAC,QAAQ,SAAS,WAAW,EAAE,YAAY,SAAS,IAAI,IAAI;IAC7E,WAAW,EAAE,QAAQ,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IACzC,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,KAAK,MAAM,CAAC;IAC9C,gBAAgB,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC7C,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,QAAA,MAAM,iBAAiB,kEACf,WAAW,GAAG,sBAAsB;;;;;;;;;;;EAoE3C,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { GraphQLResolveInfo } from "graphql";
2
- import { Connection, ConnectionAdapterUserOptions, ConnectionInputOptions } from "../defs";
3
- declare const _default: ({ cursorCache, createMakeCursors, createResourceResolver, getters, resolver, resultsPerPage, }: ConnectionAdapterUserOptions) => (source: Record<string, any>, args: Record<string, any> & ConnectionInputOptions, context: Record<string, any>, info: GraphQLResolveInfo) => Promise<Connection>;
4
- export default _default;
2
+ import { Connection, ConnectionInputOptions, ConnectionResolverUserOptions, Node, PlainObject } from "../defs";
3
+ declare const main: <Source extends PlainObject, Args extends PlainObject, Ctx extends PlainObject, Resource extends PlainObject, ResourceNode extends Node>({ cursorCache, createMakeCursors, createResourceResolver, getters, resolver, resultsPerPage, }: ConnectionResolverUserOptions<Source, Args, Ctx, Resource, ResourceNode>) => (source: Source, args: Args & ConnectionInputOptions, context: Ctx, info: GraphQLResolveInfo) => Promise<Connection>;
4
+ export default main;
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/main/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,4BAA4B,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;yHAaxF,4BAA4B,cACrB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QACrB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,sBAAsB,WACzC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QACtB,kBAAkB,KACvB,OAAO,CAAC,UAAU,CAAC;AAZtB,wBAoFE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/main/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,sBAAsB,EAAE,6BAA6B,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAM/G,QAAA,MAAM,IAAI,kYAiBF,kBAAkB,KACvB,OAAO,CAAC,UAAU,CAwEpB,CAAC;AAEF,eAAe,IAAI,CAAC"}
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@graphql-box/connection-resolver",
3
+ "version": "0.1.3",
4
+ "lockfileVersion": 1,
5
+ "requires": true,
6
+ "dependencies": {
7
+ "js-base64": {
8
+ "version": "3.6.0",
9
+ "resolved": "https://registry.npmjs.org/js-base64/-/js-base64-3.6.0.tgz",
10
+ "integrity": "sha512-wVdUBYQeY2gY73RIlPrysvpYx+2vheGo8Y1SNQv/BzHToWpAZzJU7Z6uheKMAe+GLSBig5/Ps2nxg/8tRB73xg=="
11
+ },
12
+ "type-fest": {
13
+ "version": "1.1.1",
14
+ "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-1.1.1.tgz",
15
+ "integrity": "sha512-RPDKc5KrIyKTP7Fk75LruUagqG6b+OTgXlCR2Z0aQDJFeIvL4/mhahSEtHmmVzXu4gmA0srkF/8FCH3WOWxTWA=="
16
+ }
17
+ }
18
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-box/connection-resolver",
3
- "version": "0.1.2",
3
+ "version": "0.1.6",
4
4
  "description": "The GraphQL Box connection manager module.",
5
5
  "keywords": [
6
6
  "graphql-box",
package/src/defs/index.ts CHANGED
@@ -1,12 +1,18 @@
1
1
  import Cachemap from "@cachemap/core";
2
2
  import { GraphQLResolveInfo } from "graphql";
3
3
 
4
+ export type PlainObject = {
5
+ [key: string]: any;
6
+ };
7
+
8
+ export type Node = PlainObject & { id: string | number };
9
+
4
10
  export type Direction = "backward" | "forward";
5
11
 
6
12
  export type CursorCacheEntry = {
7
13
  group: string;
8
14
  index: number;
9
- node: Record<string, any>;
15
+ node: Node;
10
16
  page: number;
11
17
  };
12
18
 
@@ -22,7 +28,7 @@ export type CachedEdges = {
22
28
 
23
29
  export type Edge = {
24
30
  cursor: string;
25
- node: Record<string, any>;
31
+ node: Node;
26
32
  };
27
33
 
28
34
  export type Indexes = {
@@ -40,55 +46,61 @@ export type PageInfo = {
40
46
  export type Connection = {
41
47
  edges: Edge[];
42
48
  errors: Error[];
43
- nodes: Record<string, any>[];
49
+ nodes: Node[];
44
50
  pageInfo: PageInfo;
45
51
  totalCount: number;
46
52
  };
47
53
 
48
- export interface ResourceResponse extends Response {
49
- data?: Record<string, any>;
54
+ export interface ResourceResponse<Resource extends PlainObject> extends Response {
55
+ data?: Resource;
50
56
  errors?: Error[];
51
57
  }
52
58
 
53
- export type ResourceResolver = (args: { page: number }) => Promise<ResourceResponse>;
54
-
55
- export type CreateResourceResolver = (
56
- source: Record<string, any>,
57
- args: Record<string, any>,
58
- context: Record<string, any>,
59
- info: GraphQLResolveInfo,
60
- ) => ResourceResolver;
61
-
62
- export type Node = Record<string, any> & { id: string | number };
63
-
64
- export interface Getters {
65
- nodes: (obj: Record<string, any>) => Node[];
66
- page: (obj: Record<string, any>) => number;
67
- totalPages: (obj: Record<string, any>) => number;
68
- totalResults: (obj: Record<string, any>) => number;
59
+ export type ResourceResolver<Resource extends PlainObject> = (args: {
60
+ page: number;
61
+ }) => Promise<ResourceResponse<Resource>>;
62
+
63
+ export type CreateResourceResolver<
64
+ Source extends PlainObject,
65
+ Args extends PlainObject,
66
+ Ctx extends PlainObject,
67
+ Resource extends PlainObject
68
+ > = (source: Source, args: Args, context: Ctx, info: GraphQLResolveInfo) => ResourceResolver<Resource>;
69
+
70
+ export interface Getters<Resource extends PlainObject, ResourceNode extends Node> {
71
+ nodes: (obj: Resource) => ResourceNode[];
72
+ page: (obj: Resource) => number;
73
+ totalPages: (obj: Resource) => number;
74
+ totalResults: (obj: Resource) => number;
69
75
  }
70
76
 
71
- export interface ConnectionAdapterUserOptions {
77
+ export interface ConnectionResolverUserOptions<
78
+ Source extends PlainObject,
79
+ Args extends PlainObject,
80
+ Ctx extends PlainObject,
81
+ Resource extends PlainObject,
82
+ ResourceNode extends Node
83
+ > {
72
84
  createMakeCursors: (
73
- source: Record<string, any>,
74
- args: Record<string, any>,
75
- context: Record<string, any>,
85
+ source: Source,
86
+ args: Args,
87
+ context: Ctx,
76
88
  info: GraphQLResolveInfo,
77
89
  ) => {
78
90
  makeGroupCursor: () => string;
79
91
  makeIDCursor: (id: string | number) => string;
80
92
  };
81
- createResourceResolver: CreateResourceResolver;
93
+ createResourceResolver: CreateResourceResolver<Source, Args, Ctx, Resource>;
82
94
  cursorCache: Cachemap;
83
- getters: Getters;
84
- resolver: (args: Connection) => Connection;
95
+ getters: Getters<Resource, ResourceNode>;
96
+ resolver?: (args: Connection) => Connection;
85
97
  resultsPerPage: number;
86
98
  }
87
99
 
88
100
  export type ConnectionResolver = (
89
- source: Record<string, any>,
90
- args: Record<string, any> & ConnectionInputOptions,
91
- context: Record<string, any>,
101
+ source: PlainObject,
102
+ args: PlainObject & ConnectionInputOptions,
103
+ context: PlainObject,
92
104
  info: GraphQLResolveInfo,
93
105
  ) => Promise<Connection>;
94
106
 
@@ -11,7 +11,7 @@ describe("getPageNumbersToRequest", () => {
11
11
  entry: {
12
12
  group: "group",
13
13
  index: 2,
14
- node: {},
14
+ node: { id: "123" },
15
15
  page: 2,
16
16
  },
17
17
  metadata: {
@@ -35,7 +35,7 @@ describe("getPageNumbersToRequest", () => {
35
35
  entry: {
36
36
  group: "group",
37
37
  index: 3,
38
- node: {},
38
+ node: { id: "123" },
39
39
  page: 4,
40
40
  },
41
41
  metadata: {
@@ -11,7 +11,7 @@ describe("getStartIndex", () => {
11
11
  entry: {
12
12
  group: "qwerty",
13
13
  index: 5,
14
- node: {},
14
+ node: { id: "123" },
15
15
  page: 3,
16
16
  },
17
17
  metadata: {
@@ -35,7 +35,7 @@ describe("getStartIndex", () => {
35
35
  entry: {
36
36
  group: "qwerty",
37
37
  index: 3,
38
- node: {},
38
+ node: { id: "123" },
39
39
  page: 1,
40
40
  },
41
41
  metadata: {
@@ -58,7 +58,7 @@ describe("getStartIndex", () => {
58
58
  entry: {
59
59
  group: "qwerty",
60
60
  index: 4,
61
- node: {},
61
+ node: { id: "123" },
62
62
  page: 1,
63
63
  },
64
64
  metadata: {
@@ -82,7 +82,7 @@ describe("getStartIndex", () => {
82
82
  entry: {
83
83
  group: "qwerty",
84
84
  index: 7,
85
- node: {},
85
+ node: { id: "123" },
86
86
  page: 3,
87
87
  },
88
88
  metadata: {
@@ -105,7 +105,7 @@ describe("getStartIndex", () => {
105
105
  entry: {
106
106
  group: "qwerty",
107
107
  index: 4,
108
- node: {},
108
+ node: { id: "123" },
109
109
  page: 3,
110
110
  },
111
111
  metadata: {
@@ -132,7 +132,7 @@ describe("getEndIndex", () => {
132
132
  entry: {
133
133
  group: "qwerty",
134
134
  index: 5,
135
- node: {},
135
+ node: { id: "123" },
136
136
  page: 3,
137
137
  },
138
138
  metadata: {
@@ -156,7 +156,7 @@ describe("getEndIndex", () => {
156
156
  entry: {
157
157
  group: "qwerty",
158
158
  index: 2,
159
- node: {},
159
+ node: { id: "123" },
160
160
  page: 6,
161
161
  },
162
162
  metadata: {
@@ -179,7 +179,7 @@ describe("getEndIndex", () => {
179
179
  entry: {
180
180
  group: "qwerty",
181
181
  index: 2,
182
- node: {},
182
+ node: { id: "123" },
183
183
  page: 6,
184
184
  },
185
185
  metadata: {
@@ -203,7 +203,7 @@ describe("getEndIndex", () => {
203
203
  entry: {
204
204
  group: "qwerty",
205
205
  index: 2,
206
- node: {},
206
+ node: { id: "123" },
207
207
  page: 4,
208
208
  },
209
209
  metadata: {
@@ -226,7 +226,7 @@ describe("getEndIndex", () => {
226
226
  entry: {
227
227
  group: "qwerty",
228
228
  index: 2,
229
- node: {},
229
+ node: { id: "123" },
230
230
  page: 4,
231
231
  },
232
232
  metadata: {
@@ -1,3 +1,3 @@
1
- import { ConnectionInputOptions } from "../defs";
1
+ import { ConnectionInputOptions, PlainObject } from "../defs";
2
2
 
3
- export default ({ after, before }: Record<string, any> & ConnectionInputOptions) => !!(after || before);
3
+ export default ({ after, before }: PlainObject & ConnectionInputOptions) => !!(after || before);