gatsby 4.9.0 → 4.9.3
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.
- package/dist/bootstrap/get-config-file.js +19 -11
- package/dist/bootstrap/get-config-file.js.map +1 -1
- package/dist/datastore/in-memory/indexing.js +1 -1
- package/dist/datastore/in-memory/indexing.js.map +1 -1
- package/dist/schema/graphql-engine/bundle-webpack.js +5 -3
- package/dist/schema/graphql-engine/bundle-webpack.js.map +1 -1
- package/dist/schema/graphql-engine/lmdb-bundling-patch.d.ts +1 -1
- package/dist/schema/graphql-engine/lmdb-bundling-patch.js +20 -6
- package/dist/schema/graphql-engine/lmdb-bundling-patch.js.map +1 -1
- package/package.json +12 -12
|
@@ -34,16 +34,24 @@ async function getConfigFile(siteDirectory, configName, distance = 3) {
|
|
|
34
34
|
configPath = _path.default.join(`${siteDirectory}/${_compileGatsbyFiles.COMPILED_CACHE_DIR}`, configName);
|
|
35
35
|
configFilePath = require.resolve(configPath);
|
|
36
36
|
configModule = require(configFilePath);
|
|
37
|
-
} catch (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
} catch (outerError) {
|
|
38
|
+
var _outerError$requireSt, _outerError$requireSt2, _outerError$requireSt3;
|
|
39
|
+
|
|
40
|
+
// Not all plugins will have a compiled file, so the err.message can look like this:
|
|
41
|
+
// "Cannot find module '<root>/node_modules/gatsby-source-filesystem/.cache/compiled/gatsby-config'"
|
|
42
|
+
// But the compiled file can also have an error like this:
|
|
43
|
+
// "Cannot find module 'foobar'"
|
|
44
|
+
// So this is trying to differentiate between an error we're fine ignoring and an error that we should throw
|
|
45
|
+
const isModuleNotFoundError = outerError.code === `MODULE_NOT_FOUND`;
|
|
46
|
+
const isThisFileRequireError = (_outerError$requireSt = outerError === null || outerError === void 0 ? void 0 : (_outerError$requireSt2 = outerError.requireStack) === null || _outerError$requireSt2 === void 0 ? void 0 : (_outerError$requireSt3 = _outerError$requireSt2[0]) === null || _outerError$requireSt3 === void 0 ? void 0 : _outerError$requireSt3.includes(`get-config-file`)) !== null && _outerError$requireSt !== void 0 ? _outerError$requireSt : true;
|
|
47
|
+
|
|
48
|
+
if (!(isModuleNotFoundError && isThisFileRequireError)) {
|
|
41
49
|
_reporter.default.panic({
|
|
42
50
|
id: `11902`,
|
|
43
|
-
error:
|
|
51
|
+
error: outerError,
|
|
44
52
|
context: {
|
|
45
53
|
configName,
|
|
46
|
-
message:
|
|
54
|
+
message: outerError.message
|
|
47
55
|
}
|
|
48
56
|
});
|
|
49
57
|
} // Fallback to regular rootDir gatsby-config
|
|
@@ -54,26 +62,26 @@ async function getConfigFile(siteDirectory, configName, distance = 3) {
|
|
|
54
62
|
try {
|
|
55
63
|
configFilePath = require.resolve(configPath);
|
|
56
64
|
configModule = require(configFilePath);
|
|
57
|
-
} catch (
|
|
65
|
+
} catch (innerError) {
|
|
58
66
|
// Only then hard fail
|
|
59
67
|
const nearMatch = await _fsExtra.default.readdir(siteDirectory).then(files => files.find(file => {
|
|
60
68
|
const fileName = file.split(siteDirectory).pop();
|
|
61
69
|
return isNearMatch(fileName, configName, distance);
|
|
62
70
|
}));
|
|
63
71
|
|
|
64
|
-
if (!(0, _testRequireError.testRequireError)(configPath,
|
|
72
|
+
if (!(0, _testRequireError.testRequireError)(configPath, innerError)) {
|
|
65
73
|
_reporter.default.panic({
|
|
66
74
|
id: `10123`,
|
|
67
|
-
error:
|
|
75
|
+
error: innerError,
|
|
68
76
|
context: {
|
|
69
77
|
configName,
|
|
70
|
-
message:
|
|
78
|
+
message: innerError.message
|
|
71
79
|
}
|
|
72
80
|
});
|
|
73
81
|
} else if (nearMatch) {
|
|
74
82
|
_reporter.default.panic({
|
|
75
83
|
id: `10124`,
|
|
76
|
-
error:
|
|
84
|
+
error: innerError,
|
|
77
85
|
context: {
|
|
78
86
|
configName,
|
|
79
87
|
nearMatch
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bootstrap/get-config-file.ts"],"names":["isNearMatch","fileName","configName","distance","getConfigFile","siteDirectory","configPath","configFilePath","configModule","path","join","COMPILED_CACHE_DIR","require","resolve","
|
|
1
|
+
{"version":3,"sources":["../../src/bootstrap/get-config-file.ts"],"names":["isNearMatch","fileName","configName","distance","getConfigFile","siteDirectory","configPath","configFilePath","configModule","path","join","COMPILED_CACHE_DIR","require","resolve","outerError","isModuleNotFoundError","code","isThisFileRequireError","requireStack","includes","report","panic","id","error","context","message","innerError","nearMatch","fs","readdir","then","files","find","file","split","pop"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA,SAASA,WAAT,CACEC,QADF,EAEEC,UAFF,EAGEC,QAHF,EAIW;AACT,MAAI,CAACF,QAAL,EAAe,OAAO,KAAP;AACf,SAAO,kCAAYA,QAAZ,EAAsBC,UAAtB,KAAqCC,QAA5C;AACD;;AAEM,eAAeC,aAAf,CACLC,aADK,EAELH,UAFK,EAGLC,QAAgB,GAAG,CAHd,EAOJ;AACD,MAAIG,UAAU,GAAI,EAAlB;AACA,MAAIC,cAAc,GAAI,EAAtB;AACA,MAAIC,YAAJ;;AAEA,MAAI;AACF;AACAF,IAAAA,UAAU,GAAGG,cAAKC,IAAL,CAAW,GAAEL,aAAc,IAAGM,sCAAmB,EAAjD,EAAoDT,UAApD,CAAb;AACAK,IAAAA,cAAc,GAAGK,OAAO,CAACC,OAAR,CAAgBP,UAAhB,CAAjB;AACAE,IAAAA,YAAY,GAAGI,OAAO,CAACL,cAAD,CAAtB;AACD,GALD,CAKE,OAAOO,UAAP,EAAmB;AAAA;;AACnB;AACA;AACA;AACA;AACA;AACA,UAAMC,qBAAqB,GAAGD,UAAU,CAACE,IAAX,KAAqB,kBAAnD;AACA,UAAMC,sBAAsB,4BAC1BH,UAD0B,aAC1BA,UAD0B,iDAC1BA,UAAU,CAAEI,YADc,qFAC1B,uBAA2B,CAA3B,CAD0B,2DAC1B,uBAA+BC,QAA/B,CAAyC,iBAAzC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,UAAAA,KAAK,EAAEG,UAFI;AAGXF,UAAAA,OAAO,EAAE;AACPtB,YAAAA,UADO;AAEPyB,YAAAA;AAFO;AAHE,SAAb;AAQD,OATM,MASA,IACL,0BAAWlB,cAAKC,IAAL,CAAUL,aAAV,EAA0B,KAA1B,EAAgCH,UAAU,GAAI,KAA9C,CAAX,CADK,EAEL;AACAkB,0BAAOC,KAAP,CAAa;AACXC,UAAAA,EAAE,EAAG,OADM;AAEXE,UAAAA,OAAO,EAAE;AACPtB,YAAAA;AADO;AAFE,SAAb;AAMD;AACF;AACF;;AAED,SAAO;AAAEM,IAAAA,YAAF;AAAgBD,IAAAA;AAAhB,GAAP;AACD","sourcesContent":["import { distance as levenshtein } from \"fastest-levenshtein\"\nimport fs from \"fs-extra\"\nimport { testRequireError } from \"../utils/test-require-error\"\nimport report from \"gatsby-cli/lib/reporter\"\nimport path from \"path\"\nimport { sync as existsSync } from \"fs-exists-cached\"\nimport { COMPILED_CACHE_DIR } from \"../utils/parcel/compile-gatsby-files\"\n\nfunction isNearMatch(\n fileName: string | undefined,\n configName: string,\n distance: number\n): boolean {\n if (!fileName) return false\n return levenshtein(fileName, configName) <= distance\n}\n\nexport async function getConfigFile(\n siteDirectory: string,\n configName: string,\n distance: number = 3\n): Promise<{\n configModule: any\n configFilePath: string\n}> {\n let configPath = ``\n let configFilePath = ``\n let configModule: any\n\n try {\n // Try .cache/compiled/gatsby-config first\n configPath = path.join(`${siteDirectory}/${COMPILED_CACHE_DIR}`, configName)\n configFilePath = require.resolve(configPath)\n configModule = require(configFilePath)\n } catch (outerError) {\n // Not all plugins will have a compiled file, so the err.message can look like this:\n // \"Cannot find module '<root>/node_modules/gatsby-source-filesystem/.cache/compiled/gatsby-config'\"\n // But the compiled file can also have an error like this:\n // \"Cannot find module 'foobar'\"\n // So this is trying to differentiate between an error we're fine ignoring and an error that we should throw\n const isModuleNotFoundError = outerError.code === `MODULE_NOT_FOUND`\n const isThisFileRequireError =\n outerError?.requireStack?.[0]?.includes(`get-config-file`) ?? true\n\n if (!(isModuleNotFoundError && isThisFileRequireError)) {\n report.panic({\n id: `11902`,\n error: outerError,\n context: {\n configName,\n message: outerError.message,\n },\n })\n }\n\n // Fallback to regular rootDir gatsby-config\n configPath = path.join(siteDirectory, configName)\n try {\n configFilePath = require.resolve(configPath)\n configModule = require(configFilePath)\n } catch (innerError) {\n // Only then hard fail\n const nearMatch = await fs.readdir(siteDirectory).then(files =>\n files.find(file => {\n const fileName = file.split(siteDirectory).pop()\n return isNearMatch(fileName, configName, distance)\n })\n )\n if (!testRequireError(configPath, innerError)) {\n report.panic({\n id: `10123`,\n error: innerError,\n context: {\n configName,\n message: innerError.message,\n },\n })\n } else if (nearMatch) {\n report.panic({\n id: `10124`,\n error: innerError,\n context: {\n configName,\n nearMatch,\n },\n })\n } else if (\n existsSync(path.join(siteDirectory, `src`, configName + `.js`))\n ) {\n report.panic({\n id: `10125`,\n context: {\n configName,\n },\n })\n }\n }\n }\n\n return { configModule, configFilePath }\n}\n"],"file":"get-config-file.js"}
|
|
@@ -977,7 +977,7 @@ function intersectNodesByCounter(a, b) {
|
|
|
977
977
|
} else if (counterA > counterB) {
|
|
978
978
|
pointerB++;
|
|
979
979
|
} else {
|
|
980
|
-
if (a[pointerA] !== b[pointerB]) {
|
|
980
|
+
if (a[pointerA].id !== b[pointerB].id) {
|
|
981
981
|
throw new Error(`Invariant violation: inconsistent node counters detected`);
|
|
982
982
|
} // nodeA===nodeB. Make sure we didn't just add this node already.
|
|
983
983
|
// Since input arrays are sorted, the same node should be grouped
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/datastore/in-memory/indexing.ts"],"names":["nodeIdToIdentifierMap","Map","getGatsbyNodePartial","node","indexFields","resolvedFields","cacheKey","id","internal","counter","derefPartial","undefined","has","get","deref","_","every","map","field","gatsbyNodePartialInternalData","dottedFields","fieldsToStore","Set","sortFieldIds","getSortFieldIdentifierKeys","fullNodeObject","dottedField","partial","Object","assign","set","WeakRef","sortByIds","a","b","postIndexingMetaSetup","filterCache","op","bucket","byValue","sort","postIndexingMetaSetupNeNin","includes","postIndexingMetaSetupLtLteGtGte","arr","meta","nodesUnordered","forEach","v","nodeId","push","entriesNullable","entries","filter","orderedNodes","orderedValues","offsets","length","valuesAsc","nodesByValueAsc","valueRangesAsc","valuesDesc","nodesByValueDesc","valueRangesDesc","ensureIndexByQuery","filterCacheKey","filterPath","nodeTypeNames","filtersCache","state","store","getState","resolvedNodesCache","iterateNodesByType","addNodeToFilterCache","chain","iterateNodes","type","ensureEmptyFilterCache","orderedByCounter","__gatsby_resolved","typeName","resolvedNodes","resolved","valueOffset","i","nextProp","Array","isArray","markNodeForValue","value","ensureIndexByElemMatch","addNodeToBucketWithElemMatch","valueAtCurrentStep","path","nestedQuery","elem","binarySearchAsc","values","needle","min","max","pivot","Math","floor","binarySearchDesc","getNodesFromCacheByValue","filterValue","wasElemMatch","arrNull","arrUndef","unionNodesByCounter","Error","filterValueArr","add","nodes","expensiveDedupeInline","removeBucketFromSet","RegExp","regex","test","String","ranges","range","slice","point","pivotMin","pivotMax","pivotValue","exclPivot","inclPivot","until","reverse","cache","delete","intersectNodesByCounter","pointerA","pointerB","result","maxA","maxB","lastAdded","counterA","counterB","prev","j","dottedFieldKeys","keys","fieldKeys","some","key","startsWith"],"mappings":";;;;;;;;;;;;AAAA;;AAEA;;AAMA;;AACA;;AACA;;AA6BA,MAAMA,qBAAqB,GAAG,IAAIC,GAAJ,EAA9B;AAKA;AACA;AACA;AACA;AACA;AACA;;AACO,MAAMC,oBAAoB,GAAG,CAClCC,IADkC,EAElCC,WAFkC,EAGlCC,cAHkC,KAIX;AACvB;AACA,QAAMC,QAAQ,GAAI,GAAEH,IAAI,CAACI,EAAG,QAAOJ,IAAI,CAACK,QAAL,CAAcC,OAAQ,EAAzD;AACA,MAAIC,YAA4C,GAAGC,SAAnD;;AACA,MAAIX,qBAAqB,CAACY,GAAtB,CAA0BN,QAA1B,CAAJ,EAAy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BAAT,CAA+BxE,GAA/B,EAAqE;AACnE;AACA;AACA;AACA,MAAIoG,IAAoC,GAAGrI,SAA3C,CAJmE,CAMnE;;AAEA,MAAIsI,CAAC,GAAG,CAAR;;AACA,OAAK,IAAI5D,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGzC,GAAG,CAACa,MAAxB,EAAgC,EAAE4B,CAAlC,EAAqC;AACnC,UAAMlF,IAAI,GAAGyC,GAAG,CAACyC,CAAD,CAAhB;;AACA,QAAIlF,IAAI,KAAK6I,IAAb,EAAmB;AACjB;AACA,UAAI3D,CAAC,KAAK4D,CAAV,EAAa;AACXrG,QAAAA,GAAG,CAACqG,CAAD,CAAH,GAAS9I,IAAT;AACD;;AACD,QAAE8I,CAAF;AACAD,MAAAA,IAAI,GAAG7I,IAAP;AACD;AACF;;AACDyC,EAAAA,GAAG,CAACa,MAAJ,GAAawF,CAAb;AACD;;AAEM,SAASzH,0BAAT,CACLpB,WADK,EAELC,cAFK,EAGU;AACf,QAAMe,YAAY,GAAG,gCAAoBf,cAApB,CAArB;AACA,QAAM6I,eAAe,GAAGtH,MAAM,CAACuH,IAAP,CAAY/H,YAAZ,CAAxB;AACA,QAAMgI,SAAS,GAAGhJ,WAAW,CAACa,GAAZ,CAAgBC,KAAK,IAAI;AACzC,QACEE,YAAY,CAACF,KAAD,CAAZ,IACAgI,eAAe,CAACG,IAAhB,CAAqBC,GAAG,IAAIpI,KAAK,CAACqI,UAAN,CAAiBD,GAAjB,CAA5B,CAFF,EAGE;AACA,aAAQ,qBAAoBpI,KAAM,EAAlC;AACD,KALD,MAKO;AACL,aAAOA,KAAP;AACD;AACF,GATiB,CAAlB;AAWA,SAAOkI,SAAP;AACD","sourcesContent":["import { store } from \"../../redux\"\nimport { IGatsbyNode } from \"../../redux/types\"\nimport {\n IDbQueryElemMatch,\n FilterValue,\n FilterValueNullable,\n objectToDottedField,\n} from \"../common/query\"\nimport { getDataStore, getNode } from \"../\"\nimport _ from \"lodash\"\nimport { getValueAt } from \"../../utils/get-value-at\"\n\n// Only list supported ops here. \"CacheableFilterOp\"\nexport type FilterOp = // TODO: merge with DbComparator ?\n | \"$eq\"\n | \"$ne\"\n | \"$lt\"\n | \"$lte\"\n | \"$gt\"\n | \"$gte\"\n | \"$in\"\n | \"$nin\"\n | \"$regex\" // Note: this includes $glob\n// Note: `undefined` is an encoding for a property that does not exist\n\nexport type FilterCacheKey = string\ntype GatsbyNodeID = string\n\nexport interface IGatsbyNodePartial {\n id: GatsbyNodeID\n internal: {\n counter: number\n }\n gatsbyNodePartialInternalData: {\n indexFields: Set<string>\n }\n [k: string]: any\n}\n\nconst nodeIdToIdentifierMap = new Map<\n GatsbyNodeID,\n WeakRef<IGatsbyNodePartial>\n>()\n\n/**\n * Grabs an instance of IGatsbyNodePartial for the given node.\n * This accepts an IGatsbyNode or IGatsbyNodePartial as input, which allows\n * us to conditionally store index fields on the partial if we encounter\n * one that hasn't been stored on the partial yet.\n */\nexport const getGatsbyNodePartial = (\n node: IGatsbyNode | IGatsbyNodePartial,\n indexFields: Array<string>,\n resolvedFields: Record<string, any>\n): IGatsbyNodePartial => {\n // first, check if we have the partial in the cache\n const cacheKey = `${node.id}_____${node.internal.counter}`\n let derefPartial: IGatsbyNodePartial | undefined = undefined\n if (nodeIdToIdentifierMap.has(cacheKey)) {\n derefPartial = nodeIdToIdentifierMap.get(cacheKey)?.deref()\n\n // now check if we have it in memory and it has all the fields we need\n if (\n derefPartial &&\n _.every(\n indexFields.map(field =>\n derefPartial!.gatsbyNodePartialInternalData.indexFields.has(field)\n )\n )\n ) {\n return derefPartial\n }\n }\n\n // find all the keys of fields and store them and their values on the partial\n // if we've already passed this partial, merge both sets of index fields\n const dottedFields = {}\n const fieldsToStore = derefPartial\n ? new Set([\n ...derefPartial.gatsbyNodePartialInternalData.indexFields,\n ...indexFields,\n ])\n : new Set(indexFields)\n\n const sortFieldIds = getSortFieldIdentifierKeys(\n [...fieldsToStore],\n resolvedFields\n )\n let fullNodeObject: IGatsbyNode | undefined =\n node.gatsbyNodePartialInternalData ? undefined : (node as IGatsbyNode)\n\n for (const dottedField of sortFieldIds) {\n if (dottedField in node) {\n dottedFields[dottedField] = node[dottedField]\n } else {\n // if we haven't gotten the full node object, fetch it once\n if (!fullNodeObject) {\n fullNodeObject = getNode(node.id)!\n }\n\n // use the full node object to fetch the value\n dottedFields[dottedField] = getValueAt(fullNodeObject, dottedField)\n }\n }\n\n // create the partial object\n const partial = Object.assign(dottedFields, {\n id: node.id,\n internal: {\n counter: node.internal.counter,\n },\n gatsbyNodePartialInternalData: {\n indexFields: fieldsToStore,\n },\n })\n\n // set the object in the cache for later fetching\n nodeIdToIdentifierMap.set(cacheKey, new WeakRef<IGatsbyNodePartial>(partial))\n\n return partial\n}\n\nconst sortByIds = (a: IGatsbyNodePartial, b: IGatsbyNodePartial): number =>\n a.internal.counter - b.internal.counter\n\nexport interface IFilterCache {\n op: FilterOp\n // In this map `undefined` values represent nodes that did not have the path\n // The individual arrays are ordered asc by internal.counter which will\n // preserve insertion order and guarantee uniqueness and it's a number so our\n // .sort() calls can subtract one from the other which is nice :)\n // This arrays may contain duplicates (!) because those only get filtered in the\n // last step.\n // TODO: We might decide to make sure these buckets _are_ deduped for eq perf\n byValue: Map<FilterValueNullable, Array<IGatsbyNodePartial>>\n meta: {\n // Used by ne/nin, which will create a Set from this array and then remove another set(s) and sort\n nodesUnordered?: Array<IGatsbyNodePartial>\n // Flat list of all nodes by requested types, ordered by counter (cached for empty filters)\n orderedByCounter?: Array<IGatsbyNodePartial>\n // Ordered list of all values (by `<`) found by this filter. No null / undefs\n valuesAsc?: Array<FilterValue>\n // Flat list of nodes, ordered by valueAsc\n nodesByValueAsc?: Array<IGatsbyNodePartial>\n // Ranges of nodes per value, maps to the nodesByValueAsc array\n valueRangesAsc?: Map<FilterValue, [number, number]>\n // Ordered list of all values (by `>`) found by this filter. No null / undefs\n valuesDesc?: Array<FilterValue>\n // Flat list of nodes, ordered by valueDesc\n nodesByValueDesc?: Array<IGatsbyNodePartial>\n // Ranges of nodes per value, maps to the nodesByValueDesc array\n valueRangesDesc?: Map<FilterValue, [number, number]>\n }\n}\nexport type FiltersCache = Map<FilterCacheKey, IFilterCache>\n\nexport function postIndexingMetaSetup(\n filterCache: IFilterCache,\n op: FilterOp\n): void {\n // Loop through byValue and make sure the buckets are sorted by counter\n // Since we don't do insertion sort, we have to do it afterwards\n for (const bucket of filterCache.byValue) {\n bucket[1].sort(sortByIds)\n }\n\n if (op === `$ne` || op === `$nin`) {\n postIndexingMetaSetupNeNin(filterCache)\n } else if ([`$lt`, `$lte`, `$gt`, `$gte`].includes(op)) {\n postIndexingMetaSetupLtLteGtGte(filterCache, op)\n }\n}\n\nfunction postIndexingMetaSetupNeNin(filterCache: IFilterCache): void {\n // Note: edge cases regarding `null` and `undefined`. Here `undefined` signals\n // that the property did not exist as the filters do not support actual\n // `undefined` values.\n // For $ne, `null` only returns nodes that actually have the property\n // and in that case the property cannot be `null` either. For any other value,\n // $ne will return all nodes where the value is not actually the needle,\n // including nodes where the value is null.\n // A $nin does the same as an $ne except it filters multiple values instead\n // of just one.\n // For `$ne` we will take the list of all targeted nodes and eliminate the\n // bucket of nodes with a particular value, if it exists at all..\n\n const arr: Array<IGatsbyNodePartial> = []\n filterCache.meta.nodesUnordered = arr\n filterCache.byValue.forEach(v => {\n v.forEach(nodeId => {\n arr.push(nodeId)\n })\n })\n}\n\nfunction postIndexingMetaSetupLtLteGtGte(\n filterCache: IFilterCache,\n op: FilterOp\n): void {\n // Create an ordered array of individual nodes, ordered (grouped) by the\n // value to which the filter resolves. Nodes per value are ordered by\n // internal.counter, asc.\n // This way non-eq ops can simply slice the array to get a range.\n\n const entriesNullable: Array<\n [FilterValueNullable, Array<IGatsbyNodePartial>]\n > = [...filterCache.byValue.entries()]\n\n // These range checks never return `null` or `undefined` so filter those out\n // By filtering them out early, the sort should be faster. Could be ...\n const entries: Array<[FilterValue, Array<IGatsbyNodePartial>]> =\n entriesNullable.filter(([v]) => v != null) as Array<\n [FilterValue, Array<IGatsbyNodePartial>]\n >\n\n // Sort all arrays by its value, asc. Ignore/allow potential type casting.\n // Note: while `<` is the inverse of `>=`, the ordering might coerce values.\n // This coercion makes the op no longer idempotent (normally the result of\n // `a < b` is the opposite of `b >= a` for any a or b of the same type). The\n // exception is a number that is `NaN`, which we're ignoring here as it's most\n // likely a bug in the user code. However, when coercing the ops may end up\n // comparing against `NaN`, too. For example: `(\"abc\" <= 12) !== (12 > \"abc\")`\n // which ends up doing `NaN <= 12` and `NaN > \"abc\"`, which will both yield\n // false.\n // So instead we potentially track two ordered lists; ascending and descending\n // and the only difference when comparing the inverse of one to the other\n // should be how these `NaN` cases end up getting ordered.\n // It's fine for `lt` and `lte` to use the same ordered list. Same for gt/gte.\n if (op === `$lt` || op === `$lte`) {\n // Order ascending; first value is lowest\n entries.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))\n } else if (op === `$gt` || op === `$gte`) {\n // Order descending; first value is highest\n entries.sort(([a], [b]) => (a > b ? -1 : a < b ? 1 : 0))\n }\n\n const orderedNodes: Array<IGatsbyNodePartial> = []\n const orderedValues: Array<FilterValue> = []\n const offsets: Map<FilterValue, [number, number]> = new Map()\n entries.forEach(([v, bucket]: [FilterValue, Array<IGatsbyNodePartial>]) => {\n // Record the range containing all nodes with as filter value v\n // The last value of the range should be the offset of the next value\n // (So you should be able to do `nodes.slice(start, stop)` to get them)\n offsets.set(v, [orderedNodes.length, orderedNodes.length + bucket.length])\n // We could do `arr.push(...bucket)` here but that's not safe with very\n // large sets, so we use a regular loop\n bucket.forEach(node => orderedNodes.push(node))\n orderedValues.push(v)\n })\n\n if (op === `$lt` || op === `$lte`) {\n filterCache.meta.valuesAsc = orderedValues\n filterCache.meta.nodesByValueAsc = orderedNodes\n // The nodesByValueAsc is ordered by value, but multiple nodes per value are\n // not ordered. To make lt as fast as lte, we must know the start and stop\n // index for each value. Similarly useful for for `ne`.\n filterCache.meta.valueRangesAsc = offsets\n } else if (op === `$gt` || op === `$gte`) {\n filterCache.meta.valuesDesc = orderedValues\n filterCache.meta.nodesByValueDesc = orderedNodes\n // The nodesByValueDesc is ordered by value, but multiple nodes per value are\n // not ordered. To make gt as fast as gte, we must know the start and stop\n // index for each value. Similarly useful for for `ne`.\n filterCache.meta.valueRangesDesc = offsets\n }\n}\n\n/**\n * Given a single non-elemMatch filter path, a list of node types, and a\n * cache, create a cache that for each resulting value of the filter contains\n * all the Nodes in a list.\n * This cache is used for applying the filter and is a massive improvement over\n * looping over all the nodes, when the number of pages (/nodes) scales up.\n */\nexport const ensureIndexByQuery = (\n op: FilterOp,\n filterCacheKey: FilterCacheKey,\n filterPath: Array<string>,\n nodeTypeNames: Array<string>,\n filtersCache: FiltersCache,\n indexFields: Array<string>,\n resolvedFields: Record<string, any>\n): void => {\n const state = store.getState()\n const resolvedNodesCache = state.resolvedNodesCache\n\n const filterCache: IFilterCache = {\n op,\n byValue: new Map<FilterValueNullable, Array<IGatsbyNodePartial>>(),\n meta: {},\n } as IFilterCache\n filtersCache.set(filterCacheKey, filterCache)\n\n // We cache the subsets of nodes by type, but only one type. So if searching\n // through one node type we can prevent a search through all nodes, otherwise\n // it's probably faster to loop through all nodes. Perhaps. Maybe.\n\n if (nodeTypeNames.length === 1) {\n getDataStore()\n .iterateNodesByType(nodeTypeNames[0])\n .forEach(node => {\n addNodeToFilterCache({\n node,\n chain: filterPath,\n filterCache,\n resolvedNodesCache,\n indexFields,\n resolvedFields,\n })\n })\n } else {\n // Here we must first filter for the node type\n // This loop is expensive at scale (!)\n getDataStore()\n .iterateNodes()\n .forEach(node => {\n if (!nodeTypeNames.includes(node.internal.type)) {\n return\n }\n\n addNodeToFilterCache({\n node,\n chain: filterPath,\n filterCache,\n resolvedNodesCache,\n indexFields,\n resolvedFields,\n })\n })\n }\n\n postIndexingMetaSetup(filterCache, op)\n}\n\nexport function ensureEmptyFilterCache(\n filterCacheKey,\n nodeTypeNames: Array<string>,\n filtersCache: FiltersCache,\n indexFields: Array<string>,\n resolvedFields: Record<string, any>\n): void {\n // This is called for queries without any filters\n // We want to cache the result since it's basically a list of nodes by type(s)\n // There are sites that have multiple queries which are empty\n\n const state = store.getState()\n const resolvedNodesCache = state.resolvedNodesCache\n const orderedByCounter: Array<IGatsbyNodePartial> = []\n\n filtersCache.set(filterCacheKey, {\n op: `$eq`, // Ignore.\n byValue: new Map<FilterValueNullable, Array<IGatsbyNodePartial>>(),\n meta: {\n orderedByCounter, // This is what we want\n },\n })\n\n if (nodeTypeNames.length === 1) {\n getDataStore()\n .iterateNodesByType(nodeTypeNames[0])\n .forEach(node => {\n if (!node.__gatsby_resolved) {\n const typeName = node.internal.type\n const resolvedNodes = resolvedNodesCache.get(typeName)\n const resolved = resolvedNodes?.get(node.id)\n if (resolved !== undefined) {\n node.__gatsby_resolved = resolved\n }\n }\n orderedByCounter.push(\n getGatsbyNodePartial(node, indexFields, resolvedFields)\n )\n })\n } else {\n // Here we must first filter for the node type\n // This loop is expensive at scale (!)\n getDataStore()\n .iterateNodes()\n .forEach(node => {\n if (nodeTypeNames.includes(node.internal.type)) {\n if (!node.__gatsby_resolved) {\n const typeName = node.internal.type\n const resolvedNodes = resolvedNodesCache.get(typeName)\n const resolved = resolvedNodes?.get(node.id)\n if (resolved !== undefined) {\n node.__gatsby_resolved = resolved\n }\n }\n orderedByCounter.push(\n getGatsbyNodePartial(node, indexFields, resolvedFields)\n )\n }\n })\n }\n\n // Since each node can only have one type, we shouldn't have to be concerned\n // about duplicates in this array. Just make sure they're sorted.\n orderedByCounter.sort(sortByIds)\n}\n\nfunction addNodeToFilterCache({\n node,\n chain,\n filterCache,\n resolvedNodesCache,\n indexFields,\n resolvedFields,\n valueOffset = node,\n}: {\n node: IGatsbyNode\n chain: Array<string>\n filterCache: IFilterCache\n resolvedNodesCache: Map<string, any>\n indexFields: Array<string>\n resolvedFields: Record<string, any>\n valueOffset?: any\n}): void {\n // There can be a filter that targets `__gatsby_resolved` so fix that first\n if (!node.__gatsby_resolved) {\n const typeName = node.internal.type\n const resolvedNodes = resolvedNodesCache.get(typeName)\n node.__gatsby_resolved = resolvedNodes?.get(node.id)\n }\n\n // - for plain query, valueOffset === node\n // - for elemMatch, valueOffset is sub-tree of the node to continue matching\n let v = valueOffset as any\n let i = 0\n while (i < chain.length && v) {\n const nextProp = chain[i++]\n v = v[nextProp]\n }\n\n if (\n (typeof v !== `string` &&\n typeof v !== `number` &&\n typeof v !== `boolean` &&\n v !== null) ||\n i !== chain.length\n ) {\n if (i === chain.length && Array.isArray(v)) {\n // The op resolved to an array\n // Add an entry for each element of the array. This would work for ops\n // like eq and ne, but not sure about range ops like lt,lte,gt,gte.\n\n v.forEach(v =>\n markNodeForValue(filterCache, node, v, indexFields, resolvedFields)\n )\n\n return\n }\n\n // This means that either\n // - The filter resolved to `undefined`, or\n // - The filter resolved to something other than a primitive\n // Set the value to `undefined` to mark \"path does not (fully) exist\"\n v = undefined\n }\n\n markNodeForValue(filterCache, node, v, indexFields, resolvedFields)\n}\n\nfunction markNodeForValue(\n filterCache: IFilterCache,\n node: IGatsbyNode,\n value: FilterValueNullable,\n indexFields: Array<string>,\n resolvedFields: Record<string, any>\n): void {\n let arr = filterCache.byValue.get(value)\n if (!arr) {\n arr = []\n filterCache.byValue.set(value, arr)\n }\n\n const partial = getGatsbyNodePartial(node, indexFields, resolvedFields)\n if (!arr.includes(partial)) {\n arr.push(partial)\n }\n}\n\nexport const ensureIndexByElemMatch = (\n op: FilterOp,\n filterCacheKey: FilterCacheKey,\n filter: IDbQueryElemMatch,\n nodeTypeNames: Array<string>,\n filtersCache: FiltersCache,\n indexFields: Array<string>,\n resolvedFields: Record<string, any>\n): void => {\n // Given an elemMatch filter, generate the cache that contains all nodes that\n // matches a given value for that sub-query\n\n const state = store.getState()\n const { resolvedNodesCache } = state\n\n const filterCache: IFilterCache = {\n op,\n byValue: new Map<FilterValueNullable, Array<IGatsbyNodePartial>>(),\n meta: {},\n } as IFilterCache\n filtersCache.set(filterCacheKey, filterCache)\n\n if (nodeTypeNames.length === 1) {\n getDataStore()\n .iterateNodesByType(nodeTypeNames[0])\n .forEach(node => {\n addNodeToBucketWithElemMatch({\n node,\n valueAtCurrentStep: node,\n filter,\n filterCache,\n resolvedNodesCache,\n indexFields,\n resolvedFields,\n })\n })\n } else {\n // Expensive at scale\n getDataStore()\n .iterateNodes()\n .forEach(node => {\n if (!nodeTypeNames.includes(node.internal.type)) {\n return\n }\n\n addNodeToBucketWithElemMatch({\n node,\n valueAtCurrentStep: node,\n filter,\n filterCache,\n resolvedNodesCache,\n indexFields,\n resolvedFields,\n })\n })\n }\n\n postIndexingMetaSetup(filterCache, op)\n}\n\nfunction addNodeToBucketWithElemMatch({\n node,\n valueAtCurrentStep, // Arbitrary step on the path inside the node\n filter,\n filterCache,\n resolvedNodesCache,\n indexFields,\n resolvedFields,\n}: {\n node: IGatsbyNode\n valueAtCurrentStep: any // Arbitrary step on the path inside the node\n filter: IDbQueryElemMatch\n filterCache: IFilterCache\n resolvedNodesCache\n indexFields: Array<string>\n resolvedFields: Record<string, any>\n}): void {\n // There can be a filter that targets `__gatsby_resolved` so fix that first\n if (!node.__gatsby_resolved) {\n const typeName = node.internal.type\n const resolvedNodes = resolvedNodesCache.get(typeName)\n node.__gatsby_resolved = resolvedNodes?.get(node.id)\n }\n\n const { path, nestedQuery } = filter\n\n // Find the value to apply elemMatch to\n let i = 0\n while (i < path.length && valueAtCurrentStep) {\n const nextProp = path[i++]\n valueAtCurrentStep = valueAtCurrentStep[nextProp]\n }\n\n if (path.length !== i) {\n // Found undefined before the end of the path\n return\n }\n\n // `v` should now be an elemMatch target, probably an array (but maybe not)\n if (!Array.isArray(valueAtCurrentStep)) {\n // It's possible to `elemMatch` on a non-array so let's support that too\n valueAtCurrentStep = [valueAtCurrentStep]\n }\n\n // Note: We need to check all elements because the node may need to be added\n // to multiple buckets (`{a:[{b:3},{b:4}]}`, for `a.elemMatch.b/eq` that\n // node ends up in buckets for value 3 and 4. This may lead to duplicate\n // work when elements resolve to the same value, but that can't be helped.\n valueAtCurrentStep.forEach(elem => {\n if (nestedQuery.type === `elemMatch`) {\n addNodeToBucketWithElemMatch({\n node,\n valueAtCurrentStep: elem,\n filter: nestedQuery,\n filterCache,\n resolvedNodesCache,\n indexFields,\n resolvedFields,\n })\n } else {\n // Now take same route as non-elemMatch filters would take\n addNodeToFilterCache({\n node,\n chain: nestedQuery.path,\n filterCache,\n resolvedNodesCache,\n indexFields,\n resolvedFields,\n valueOffset: elem,\n })\n }\n })\n}\n\nconst binarySearchAsc = (\n values: Array<FilterValue>, // Assume ordered asc\n needle: FilterValue\n): [number, number] | undefined => {\n let min = 0\n let max = values.length - 1\n let pivot = Math.floor(values.length / 2)\n while (min <= max) {\n const value = values[pivot]\n if (needle < value) {\n // Move pivot to middle of nodes left of current pivot\n // assert pivot < max\n max = pivot\n } else if (needle > value) {\n // Move pivot to middle of nodes right of current pivot\n // assert pivot > min\n min = pivot\n } else {\n // This means needle === value\n // TODO: except for NaN ... and potentially certain type casting cases\n return [pivot, pivot]\n }\n\n if (max - min <= 1) {\n // End of search. Needle not found (as expected). Use pivot as index.\n // If the needle was not found, max-min==1 and max is returned.\n return [min, max]\n }\n\n pivot = min + Math.floor((max - min) / 2)\n }\n\n // Shouldn't be reachable\n return undefined\n}\nconst binarySearchDesc = (\n values: Array<FilterValue>, // Assume ordered desc\n needle: FilterValue\n): [number, number] | undefined => {\n let min = 0\n let max = values.length - 1\n let pivot = Math.floor(values.length / 2)\n while (min <= max) {\n const value = values[pivot]\n if (needle < value) {\n // Move pivot to middle of nodes right of current pivot\n // assert pivot < min\n min = pivot\n } else if (needle > value) {\n // Move pivot to middle of nodes left of current pivot\n // assert pivot > max\n max = pivot\n } else {\n // This means needle === value\n // TODO: except for NaN ... and potentially certain type casting cases\n return [pivot, pivot]\n }\n\n if (max - min <= 1) {\n // End of search. Needle not found (as expected). Use pivot as index.\n // If the needle was not found, max-min==1 and max is returned.\n return [min, max]\n }\n\n pivot = min + Math.floor((max - min) / 2)\n }\n\n // Shouldn't be reachable\n return undefined\n}\n\n/**\n * Given the cache key for a filter and a target value return the list of nodes\n * that resolve to this value. The returned array should be ordered by id.\n * This returns `undefined` if there is no such node\n *\n * Basically if the filter was {a: {b: {slug: {eq: \"foo/bar\"}}}} then it will\n * return all the nodes that have `node.slug === \"foo/bar\"`. That usually (but\n * not always) at most one node for slug, but this filter can apply to anything.\n *\n * Arrays returned by this function must be ordered by internal.counter and\n * not contain duplicate nodes (!)\n */\nexport const getNodesFromCacheByValue = (\n filterCacheKey: FilterCacheKey,\n filterValue: FilterValueNullable,\n filtersCache: FiltersCache,\n wasElemMatch\n): Array<IGatsbyNodePartial> | undefined => {\n const filterCache = filtersCache.get(filterCacheKey)\n if (!filterCache) {\n return undefined\n }\n\n const op = filterCache.op\n\n if (op === `$eq`) {\n // Arrays in byValue are assumed to be ordered by counter\n\n if (filterValue == null) {\n // Edge case for null; fetch all nodes for `null` and `undefined` because\n // `$eq` also returns nodes without the path when searching for `null`.\n // Not all ops do so, so we map non-existing paths to `undefined`.\n\n const arrNull = filterCache.byValue.get(null) ?? []\n const arrUndef = filterCache.byValue.get(undefined) ?? []\n\n // Merge the two (ordered) arrays and return an ordered deduped array\n // TODO: is there a reason left why we cant just cache this merged list?\n return unionNodesByCounter(arrNull, arrUndef)\n }\n\n return filterCache.byValue.get(filterValue)\n }\n\n if (op === `$in`) {\n if (!Array.isArray(filterValue)) {\n throw new Error(\"The argument to the `in` comparator should be an array\")\n }\n const filterValueArr: Array<FilterValueNullable> = filterValue\n\n const set: Set<IGatsbyNodePartial> = new Set()\n\n // TODO: we can also mergeSort for every step. this may perform worse because of how memory in js works.\n // For every value in the needle array, find the bucket of nodes for\n // that value, add this bucket of nodes to one list, return the list.\n filterValueArr.forEach((v: FilterValueNullable) =>\n filterCache.byValue.get(v)?.forEach(v => set.add(v))\n )\n\n const arr = [...set] // this is bad for perf but will guarantee us a unique set :(\n arr.sort(sortByIds)\n\n // Note: it's very unlikely that the list of filter values is big so .includes should be fine here\n if (filterValueArr.includes(null)) {\n // Like all other ops, `in: [null]` behaves weirdly, allowing all nodes\n // that do not actually have a (complete) path (v=undefined)\n const nodes = filterCache.byValue.get(undefined)\n if (nodes) {\n // This will also dedupe so don't do that immediately\n return unionNodesByCounter(nodes, arr)\n }\n }\n\n // elemMatch can cause a node to appear in multiple buckets so we must dedupe first\n if (wasElemMatch) {\n expensiveDedupeInline(arr)\n }\n\n return arr\n }\n\n if (op === `$nin`) {\n // This is essentially the same as the $ne operator, just with multiple\n // values to exclude.\n\n if (!Array.isArray(filterValue)) {\n throw new Error(`The $nin operator expects an array as value`)\n }\n\n const values: Set<FilterValueNullable> = new Set(filterValue)\n const set = new Set(filterCache.meta.nodesUnordered)\n\n // Do the action for \"$ne\" for each element in the set of values\n values.forEach(filterValue => {\n removeBucketFromSet(filterValue, filterCache, set)\n })\n\n // TODO: there's probably a more efficient algorithm to do set\n // subtraction in such a way that we don't have to re-sort\n return [...set].sort(sortByIds)\n }\n\n if (op === `$ne`) {\n const set = new Set(filterCache.meta.nodesUnordered)\n\n removeBucketFromSet(filterValue, filterCache, set)\n\n // TODO: there's probably a more efficient algorithm to do set\n // subtraction in such a way that we don't have to resort here\n return [...set].sort(sortByIds)\n }\n\n if (op === `$regex`) {\n // Note: $glob is converted to $regex so $glob filters go through here, too\n // Aside from the input pattern format, further behavior is exactly the same.\n\n // The input to the filter must be a string (including leading/trailing slash and regex flags)\n // By the time the filter reaches this point, the filterValue has to be a regex.\n\n if (!(filterValue instanceof RegExp)) {\n throw new Error(\n `The value for the $regex comparator must be an instance of RegExp`\n )\n }\n const regex = filterValue\n\n const arr: Array<IGatsbyNodePartial> = []\n filterCache.byValue.forEach((nodes, value) => {\n // TODO: does the value have to be a string for $regex? Can we auto-ignore any non-strings? Or does it coerce.\n // Note: for legacy reasons partial paths should also be included for regex\n if (value !== undefined && regex.test(String(value))) {\n nodes.forEach(node => arr.push(node))\n }\n })\n\n // TODO: we _can_ cache this list as well. Might make sense if it turns out that $regex is mostly used with literals\n // TODO: it may make sense to first collect all buckets and then to .concat them, or merge sort them\n\n arr.sort(sortByIds)\n\n // elemMatch can cause a node to appear in multiple buckets so we must dedupe\n if (wasElemMatch) {\n expensiveDedupeInline(arr)\n }\n\n return arr\n }\n\n if (filterValue == null) {\n if (op === `$lt` || op === `$gt`) {\n // Nothing is lt/gt null\n return undefined\n }\n\n // This is an edge case and this value should be directly indexed\n // For `lte`/`gte` this should only return nodes for `null`, not a \"range\"\n return filterCache.byValue.get(filterValue)\n }\n\n if (Array.isArray(filterValue)) {\n throw new Error(\n \"Array is an invalid filter value for the `\" + op + \"` comparator\"\n )\n }\n\n if (filterValue instanceof RegExp) {\n // This is most likely an internal error, although it is possible for\n // users to talk to this API more directly.\n throw new Error(\n `A RegExp instance is only valid for $regex and $glob comparators`\n )\n }\n\n if (op === `$lt`) {\n // First try a direct approach. If a value is queried that also exists then\n // we can prevent a binary search through the whole list, O(1) vs O(log n)\n\n const ranges = filterCache.meta.valueRangesAsc\n const nodes = filterCache.meta.nodesByValueAsc\n\n const range = ranges!.get(filterValue)\n if (range) {\n const arr = nodes!.slice(0, range[0])\n arr.sort(sortByIds)\n // elemMatch can cause a node to appear in multiple buckets so we must dedupe\n if (wasElemMatch) {\n expensiveDedupeInline(arr)\n }\n return arr\n }\n\n // Query may ask for a value that doesn't appear in the list, like if the\n // list is [1, 2, 5, 6] and the query is <= 3. In that case we have to\n // apply a search (we'll do binary) to determine the offset to slice from.\n\n // Note: for lte, the valueAsc array must be list at this point\n const values = filterCache.meta.valuesAsc as Array<FilterValue>\n // It shouldn't find the targetValue (but it might) and return the index of\n // the two value between which targetValue sits, or first/last element.\n const point = binarySearchAsc(values, filterValue)\n if (!point) {\n return undefined\n }\n const [pivotMin, pivotMax] = point\n\n // Each pivot index must have a value and a range\n // The returned min/max index may include the lower/upper bound, so we still\n // have to do lte checks for both values.\n let pivotValue = values[pivotMax]\n if (pivotValue > filterValue) {\n pivotValue = values[pivotMin]\n }\n\n // Note: the pivot value _shouldnt_ match the filter value because that\n // means the value was actually found, but those should have been indexed\n // so should have yielded a result in the .get() above.\n\n const [exclPivot, inclPivot] = ranges!.get(pivotValue) as [number, number]\n\n // Note: technically, `5 <= \"5\" === true` but `5` would not be cached.\n // So we have to consider weak comparison and may have to include the pivot\n const until = pivotValue < filterValue ? inclPivot : exclPivot\n const arr = nodes!.slice(0, until)\n arr.sort(sortByIds)\n // elemMatch can cause a node to appear in multiple buckets so we must dedupe\n if (wasElemMatch) {\n expensiveDedupeInline(arr)\n }\n return arr\n }\n\n if (op === `$lte`) {\n // First try a direct approach. If a value is queried that also exists then\n // we can prevent a binary search through the whole list, O(1) vs O(log n)\n\n const ranges = filterCache.meta.valueRangesAsc\n const nodes = filterCache.meta.nodesByValueAsc\n\n const range = ranges!.get(filterValue)\n if (range) {\n const arr = nodes!.slice(0, range[1])\n arr.sort(sortByIds)\n // elemMatch can cause a node to appear in multiple buckets so we must dedupe\n if (wasElemMatch) {\n expensiveDedupeInline(arr)\n }\n return arr\n }\n\n // Query may ask for a value that doesn't appear in the list, like if the\n // list is [1, 2, 5, 6] and the query is <= 3. In that case we have to\n // apply a search (we'll do binary) to determine the offset to slice from.\n\n // Note: for lte, the valueAsc array must be list at this point\n const values = filterCache.meta.valuesAsc as Array<FilterValue>\n // It shouldn't find the targetValue (but it might) and return the index of\n // the two value between which targetValue sits, or first/last element.\n const point = binarySearchAsc(values, filterValue)\n if (!point) {\n return undefined\n }\n const [pivotMin, pivotMax] = point\n\n // Each pivot index must have a value and a range\n // The returned min/max index may include the lower/upper bound, so we still\n // have to do lte checks for both values.\n let pivotValue = values[pivotMax]\n if (pivotValue > filterValue) {\n pivotValue = values[pivotMin]\n }\n\n // Note: the pivot value _shouldnt_ match the filter value because that\n // means the value was actually found, but those should have been indexed\n // so should have yielded a result in the .get() above.\n\n const [exclPivot, inclPivot] = ranges!.get(pivotValue) as [number, number]\n\n // Note: technically, `5 <= \"5\" === true` but `5` would not be cached.\n // So we have to consider weak comparison and may have to include the pivot\n const until = pivotValue <= filterValue ? inclPivot : exclPivot\n const arr = nodes!.slice(0, until)\n arr.sort(sortByIds)\n // elemMatch can cause a node to appear in multiple buckets so we must dedupe\n if (wasElemMatch) {\n expensiveDedupeInline(arr)\n }\n return arr\n }\n\n if (op === `$gt`) {\n // First try a direct approach. If a value is queried that also exists then\n // we can prevent a binary search through the whole list, O(1) vs O(log n)\n\n const ranges = filterCache.meta.valueRangesDesc\n const nodes = filterCache.meta.nodesByValueDesc\n\n const range = ranges!.get(filterValue)\n if (range) {\n const arr = nodes!.slice(0, range[0]).reverse()\n arr.sort(sortByIds)\n // elemMatch can cause a node to appear in multiple buckets so we must dedupe\n if (wasElemMatch) {\n expensiveDedupeInline(arr)\n }\n return arr\n }\n\n // Query may ask for a value that doesn't appear in the list, like if the\n // list is [1, 2, 5, 6] and the query is <= 3. In that case we have to\n // apply a search (we'll do binary) to determine the offset to slice from.\n\n // Note: for gte, the valueDesc array must be list at this point\n const values = filterCache.meta.valuesDesc as Array<FilterValue>\n // It shouldn't find the targetValue (but it might) and return the index of\n // the two value between which targetValue sits, or first/last element.\n const point = binarySearchDesc(values, filterValue)\n if (!point) {\n return undefined\n }\n const [pivotMin, pivotMax] = point\n\n // Each pivot index must have a value and a range\n // The returned min/max index may include the lower/upper bound, so we still\n // have to do gte checks for both values.\n let pivotValue = values[pivotMax]\n if (pivotValue < filterValue) {\n pivotValue = values[pivotMin]\n }\n\n // Note: the pivot value _shouldnt_ match the filter value because that\n // means the value was actually found, but those should have been indexed\n // so should have yielded a result in the .get() above.\n\n const [exclPivot, inclPivot] = ranges!.get(pivotValue) as [number, number]\n\n // Note: technically, `5 >= \"5\" === true` but `5` would not be cached.\n // So we have to consider weak comparison and may have to include the pivot\n const until = pivotValue > filterValue ? inclPivot : exclPivot\n const arr = nodes!.slice(0, until).reverse()\n arr.sort(sortByIds)\n // elemMatch can cause a node to appear in multiple buckets so we must dedupe\n if (wasElemMatch) {\n expensiveDedupeInline(arr)\n }\n return arr\n }\n\n if (op === `$gte`) {\n // First try a direct approach. If a value is queried that also exists then\n // we can prevent a binary search through the whole list, O(1) vs O(log n)\n\n const ranges = filterCache.meta.valueRangesDesc\n const nodes = filterCache.meta.nodesByValueDesc\n\n const range = ranges!.get(filterValue)\n if (range) {\n const arr = nodes!.slice(0, range[1]).reverse()\n arr.sort(sortByIds)\n // elemMatch can cause a node to appear in multiple buckets so we must dedupe\n if (wasElemMatch) {\n expensiveDedupeInline(arr)\n }\n return arr\n }\n\n // Query may ask for a value that doesn't appear in the list, like if the\n // list is [1, 2, 5, 6] and the query is <= 3. In that case we have to\n // apply a search (we'll do binary) to determine the offset to slice from.\n\n // Note: for gte, the valueDesc array must be list at this point\n const values = filterCache.meta.valuesDesc as Array<FilterValue>\n // It shouldn't find the targetValue (but it might) and return the index of\n // the two value between which targetValue sits, or first/last element.\n const point = binarySearchDesc(values, filterValue)\n if (!point) {\n return undefined\n }\n const [pivotMin, pivotMax] = point\n\n // Each pivot index must have a value and a range\n // The returned min/max index may include the lower/upper bound, so we still\n // have to do gte checks for both values.\n let pivotValue = values[pivotMax]\n if (pivotValue < filterValue) {\n pivotValue = values[pivotMin]\n }\n\n // Note: the pivot value _shouldnt_ match the filter value because that\n // means the value was actually found, but those should have been indexed\n // so should have yielded a result in the .get() above.\n\n const [exclPivot, inclPivot] = ranges!.get(pivotValue) as [number, number]\n\n // Note: technically, `5 >= \"5\" === true` but `5` would not be cached.\n // So we have to consider weak comparison and may have to include the pivot\n const until = pivotValue >= filterValue ? inclPivot : exclPivot\n const arr = nodes!.slice(0, until).reverse()\n arr.sort(sortByIds)\n // elemMatch can cause a node to appear in multiple buckets so we must dedupe\n if (wasElemMatch) {\n expensiveDedupeInline(arr)\n }\n return arr\n }\n\n // Unreachable because we checked all values of FilterOp (which op is)\n return undefined\n}\n\nfunction removeBucketFromSet(\n filterValue: FilterValueNullable,\n filterCache: IFilterCache,\n set: Set<IGatsbyNodePartial>\n): void {\n if (filterValue === null) {\n // Edge case: $ne with `null` returns only the nodes that contain the full\n // path and that don't resolve to null, so drop `undefined` as well.\n let cache = filterCache.byValue.get(undefined)\n if (cache) cache.forEach(node => set.delete(node))\n cache = filterCache.byValue.get(null)\n if (cache) cache.forEach(node => set.delete(node))\n } else {\n // Not excluding null so it should include undefined leafs or leafs where\n // only the partial path exists for whatever reason.\n const cache = filterCache.byValue.get(filterValue)\n if (cache) cache.forEach(node => set.delete(node))\n }\n}\n\n/**\n * Finds the intersection of two arrays in O(n) with n = min(a.length, b.length)\n * The returned set should not contain duplicate nodes.\n *\n * The input should be ordered by node.internal.counter and it will return a\n * list that is also ordered by node.internal.counter\n */\nexport function intersectNodesByCounter(\n a: Array<IGatsbyNodePartial>,\n b: Array<IGatsbyNodePartial>\n): Array<IGatsbyNodePartial> {\n let pointerA = 0\n let pointerB = 0\n // TODO: perf check: is it helpful to init the array to min(maxA,maxB) items?\n const result: Array<IGatsbyNodePartial> = []\n const maxA = a.length\n const maxB = b.length\n let lastAdded: IGatsbyNodePartial | undefined = undefined // Used to dedupe the list\n\n while (pointerA < maxA && pointerB < maxB) {\n const counterA = a[pointerA].internal.counter\n const counterB = b[pointerB].internal.counter\n\n if (counterA < counterB) {\n pointerA++\n } else if (counterA > counterB) {\n pointerB++\n } else {\n if (a[pointerA] !== b[pointerB]) {\n throw new Error(\n `Invariant violation: inconsistent node counters detected`\n )\n }\n // nodeA===nodeB. Make sure we didn't just add this node already.\n // Since input arrays are sorted, the same node should be grouped\n // back to back, so even if both input arrays contained the same node\n // twice, this check would prevent the result from getting duplicate nodes\n if (lastAdded !== a[pointerA]) {\n result.push(a[pointerA])\n lastAdded = a[pointerA]\n }\n pointerA++\n pointerB++\n }\n }\n\n return result\n}\n\n/**\n * Merge two lists of nodes.\n * The returned set should not contain duplicate nodes.\n *\n * The input should be ordered by node.internal.counter and it will return a\n * list that is also ordered by node.internal.counter\n */\nexport function unionNodesByCounter(\n a: Array<IGatsbyNodePartial>,\n b: Array<IGatsbyNodePartial>\n): Array<IGatsbyNodePartial> {\n // TODO: perf check: is it helpful to init the array to max(maxA,maxB) items?\n const arr: Array<IGatsbyNodePartial> = []\n let lastAdded: IGatsbyNodePartial | undefined = undefined // Used to dedupe the list\n\n let pointerA = 0\n let pointerB = 0\n const maxA = a.length\n const maxB = b.length\n\n while (pointerA < maxA && pointerB < maxB) {\n const counterA = a[pointerA].internal.counter\n const counterB = b[pointerB].internal.counter\n\n if (counterA < counterB) {\n if (lastAdded !== a[pointerA]) {\n arr.push(a[pointerA])\n lastAdded = a[pointerA]\n }\n pointerA++\n } else if (counterA > counterB) {\n if (lastAdded !== b[pointerB]) {\n arr.push(b[pointerB])\n lastAdded = b[pointerB]\n }\n pointerB++\n } else {\n if (lastAdded !== a[pointerA]) {\n arr.push(a[pointerA])\n lastAdded = a[pointerA]\n }\n pointerA++\n pointerB++\n }\n }\n\n while (pointerA < maxA) {\n if (lastAdded !== a[pointerA]) {\n arr.push(a[pointerA])\n lastAdded = a[pointerA]\n }\n pointerA++\n }\n\n while (pointerB < maxB) {\n if (lastAdded !== b[pointerB]) {\n arr.push(b[pointerB])\n lastAdded = b[pointerB]\n }\n pointerB++\n }\n\n return arr\n}\n\nfunction expensiveDedupeInline(arr: Array<IGatsbyNodePartial>): void {\n // An elemMatch filter may cause duplicates to appear in a bucket.\n // Since the bucket is sorted those should now be back to back\n // Worst case this is a fast O(n) loop that does nothing.\n let prev: IGatsbyNodePartial | undefined = undefined\n\n // We copy-on-find because a splice is expensive and we can't use Sets\n\n let j = 0\n for (let i = 0; i < arr.length; ++i) {\n const node = arr[i]\n if (node !== prev) {\n // Only start copying the remainder of the list once a dupe is found\n if (i !== j) {\n arr[j] = node\n }\n ++j\n prev = node\n }\n }\n arr.length = j\n}\n\nexport function getSortFieldIdentifierKeys(\n indexFields: Array<string>,\n resolvedFields: Record<string, any>\n): Array<string> {\n const dottedFields = objectToDottedField(resolvedFields)\n const dottedFieldKeys = Object.keys(dottedFields)\n const fieldKeys = indexFields.map(field => {\n if (\n dottedFields[field] ||\n dottedFieldKeys.some(key => field.startsWith(key))\n ) {\n return `__gatsby_resolved.${field}`\n } else {\n return field\n }\n })\n\n return fieldKeys\n}\n"],"file":"indexing.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/datastore/in-memory/indexing.ts"],"names":["nodeIdToIdentifierMap","Map","getGatsbyNodePartial","node","indexFields","resolvedFields","cacheKey","id","internal","counter","derefPartial","undefined","has","get","deref","_","every","map","field","gatsbyNodePartialInternalData","dottedFields","fieldsToStore","Set","sortFieldIds","getSortFieldIdentifierKeys","fullNodeObject","dottedField","partial","Object","assign","set","WeakRef","sortByIds","a","b","postIndexingMetaSetup","filterCache","op","bucket","byValue","sort","postIndexingMetaSetupNeNin","includes","postIndexingMetaSetupLtLteGtGte","arr","meta","nodesUnordered","forEach","v","nodeId","push","entriesNullable","entries","filter","orderedNodes","orderedValues","offsets","length","valuesAsc","nodesByValueAsc","valueRangesAsc","valuesDesc","nodesByValueDesc","valueRangesDesc","ensureIndexByQuery","filterCacheKey","filterPath","nodeTypeNames","filtersCache","state","store","getState","resolvedNodesCache","iterateNodesByType","addNodeToFilterCache","chain","iterateNodes","type","ensureEmptyFilterCache","orderedByCounter","__gatsby_resolved","typeName","resolvedNodes","resolved","valueOffset","i","nextProp","Array","isArray","markNodeForValue","value","ensureIndexByElemMatch","addNodeToBucketWithElemMatch","valueAtCurrentStep","path","nestedQuery","elem","binarySearchAsc","values","needle","min","max","pivot","Math","floor","binarySearchDesc","getNodesFromCacheByValue","filterValue","wasElemMatch","arrNull","arrUndef","unionNodesByCounter","Error","filterValueArr","add","nodes","expensiveDedupeInline","removeBucketFromSet","RegExp","regex","test","String","ranges","range","slice","point","pivotMin","pivotMax","pivotValue","exclPivot","inclPivot","until","reverse","cache","delete","intersectNodesByCounter","pointerA","pointerB","result","maxA","maxB","lastAdded","counterA","counterB","prev","j","dottedFieldKeys","keys","fieldKeys","some","key","startsWith"],"mappings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;AACzC,QACEE,YAAY,CAACF,KAAD,CAAZ,IACAgI,eAAe,CAACG,IAAhB,CAAqBC,GAAG,IAAIpI,KAAK,CAACqI,UAAN,CAAiBD,GAAjB,CAA5B,CAFF,EAGE;AACA,aAAQ,qBAAoBpI,KAAM,EAAlC;AACD,KALD,MAKO;AACL,aAAOA,KAAP;AACD;AACF,GATiB,CAAlB;AAWA,SAAOkI,SAAP;AACD","sourcesContent":["import { store } from \"../../redux\"\nimport { IGatsbyNode } from \"../../redux/types\"\nimport {\n IDbQueryElemMatch,\n FilterValue,\n FilterValueNullable,\n objectToDottedField,\n} from \"../common/query\"\nimport { getDataStore, getNode } from \"../\"\nimport _ from \"lodash\"\nimport { getValueAt } from \"../../utils/get-value-at\"\n\n// Only list supported ops here. \"CacheableFilterOp\"\nexport type FilterOp = // TODO: merge with DbComparator ?\n | \"$eq\"\n | \"$ne\"\n | \"$lt\"\n | \"$lte\"\n | \"$gt\"\n | \"$gte\"\n | \"$in\"\n | \"$nin\"\n | \"$regex\" // Note: this includes $glob\n// Note: `undefined` is an encoding for a property that does not exist\n\nexport type FilterCacheKey = string\ntype GatsbyNodeID = string\n\nexport interface IGatsbyNodePartial {\n id: GatsbyNodeID\n internal: {\n counter: number\n }\n gatsbyNodePartialInternalData: {\n indexFields: Set<string>\n }\n [k: string]: any\n}\n\nconst nodeIdToIdentifierMap = new Map<\n GatsbyNodeID,\n WeakRef<IGatsbyNodePartial>\n>()\n\n/**\n * Grabs an instance of IGatsbyNodePartial for the given node.\n * This accepts an IGatsbyNode or IGatsbyNodePartial as input, which allows\n * us to conditionally store index fields on the partial if we encounter\n * one that hasn't been stored on the partial yet.\n */\nexport const getGatsbyNodePartial = (\n node: IGatsbyNode | IGatsbyNodePartial,\n indexFields: Array<string>,\n resolvedFields: Record<string, any>\n): IGatsbyNodePartial => {\n // first, check if we have the partial in the cache\n const cacheKey = `${node.id}_____${node.internal.counter}`\n let derefPartial: IGatsbyNodePartial | undefined = undefined\n if (nodeIdToIdentifierMap.has(cacheKey)) {\n derefPartial = nodeIdToIdentifierMap.get(cacheKey)?.deref()\n\n // now check if we have it in memory and it has all the fields we need\n if (\n derefPartial &&\n _.every(\n indexFields.map(field =>\n derefPartial!.gatsbyNodePartialInternalData.indexFields.has(field)\n )\n )\n ) {\n return derefPartial\n }\n }\n\n // find all the keys of fields and store them and their values on the partial\n // if we've already passed this partial, merge both sets of index fields\n const dottedFields = {}\n const fieldsToStore = derefPartial\n ? new Set([\n ...derefPartial.gatsbyNodePartialInternalData.indexFields,\n ...indexFields,\n ])\n : new Set(indexFields)\n\n const sortFieldIds = getSortFieldIdentifierKeys(\n [...fieldsToStore],\n resolvedFields\n )\n let fullNodeObject: IGatsbyNode | undefined =\n node.gatsbyNodePartialInternalData ? undefined : (node as IGatsbyNode)\n\n for (const dottedField of sortFieldIds) {\n if (dottedField in node) {\n dottedFields[dottedField] = node[dottedField]\n } else {\n // if we haven't gotten the full node object, fetch it once\n if (!fullNodeObject) {\n fullNodeObject = getNode(node.id)!\n }\n\n // use the full node object to fetch the value\n dottedFields[dottedField] = getValueAt(fullNodeObject, dottedField)\n }\n }\n\n // create the partial object\n const partial = Object.assign(dottedFields, {\n id: node.id,\n internal: {\n counter: node.internal.counter,\n },\n gatsbyNodePartialInternalData: {\n indexFields: fieldsToStore,\n },\n })\n\n // set the object in the cache for later fetching\n nodeIdToIdentifierMap.set(cacheKey, new WeakRef<IGatsbyNodePartial>(partial))\n\n return partial\n}\n\nconst sortByIds = (a: IGatsbyNodePartial, b: IGatsbyNodePartial): number =>\n a.internal.counter - b.internal.counter\n\nexport interface IFilterCache {\n op: FilterOp\n // In this map `undefined` values represent nodes that did not have the path\n // The individual arrays are ordered asc by internal.counter which will\n // preserve insertion order and guarantee uniqueness and it's a number so our\n // .sort() calls can subtract one from the other which is nice :)\n // This arrays may contain duplicates (!) because those only get filtered in the\n // last step.\n // TODO: We might decide to make sure these buckets _are_ deduped for eq perf\n byValue: Map<FilterValueNullable, Array<IGatsbyNodePartial>>\n meta: {\n // Used by ne/nin, which will create a Set from this array and then remove another set(s) and sort\n nodesUnordered?: Array<IGatsbyNodePartial>\n // Flat list of all nodes by requested types, ordered by counter (cached for empty filters)\n orderedByCounter?: Array<IGatsbyNodePartial>\n // Ordered list of all values (by `<`) found by this filter. No null / undefs\n valuesAsc?: Array<FilterValue>\n // Flat list of nodes, ordered by valueAsc\n nodesByValueAsc?: Array<IGatsbyNodePartial>\n // Ranges of nodes per value, maps to the nodesByValueAsc array\n valueRangesAsc?: Map<FilterValue, [number, number]>\n // Ordered list of all values (by `>`) found by this filter. No null / undefs\n valuesDesc?: Array<FilterValue>\n // Flat list of nodes, ordered by valueDesc\n nodesByValueDesc?: Array<IGatsbyNodePartial>\n // Ranges of nodes per value, maps to the nodesByValueDesc array\n valueRangesDesc?: Map<FilterValue, [number, number]>\n }\n}\nexport type FiltersCache = Map<FilterCacheKey, IFilterCache>\n\nexport function postIndexingMetaSetup(\n filterCache: IFilterCache,\n op: FilterOp\n): void {\n // Loop through byValue and make sure the buckets are sorted by counter\n // Since we don't do insertion sort, we have to do it afterwards\n for (const bucket of filterCache.byValue) {\n bucket[1].sort(sortByIds)\n }\n\n if (op === `$ne` || op === `$nin`) {\n postIndexingMetaSetupNeNin(filterCache)\n } else if ([`$lt`, `$lte`, `$gt`, `$gte`].includes(op)) {\n postIndexingMetaSetupLtLteGtGte(filterCache, op)\n }\n}\n\nfunction postIndexingMetaSetupNeNin(filterCache: IFilterCache): void {\n // Note: edge cases regarding `null` and `undefined`. Here `undefined` signals\n // that the property did not exist as the filters do not support actual\n // `undefined` values.\n // For $ne, `null` only returns nodes that actually have the property\n // and in that case the property cannot be `null` either. For any other value,\n // $ne will return all nodes where the value is not actually the needle,\n // including nodes where the value is null.\n // A $nin does the same as an $ne except it filters multiple values instead\n // of just one.\n // For `$ne` we will take the list of all targeted nodes and eliminate the\n // bucket of nodes with a particular value, if it exists at all..\n\n const arr: Array<IGatsbyNodePartial> = []\n filterCache.meta.nodesUnordered = arr\n filterCache.byValue.forEach(v => {\n v.forEach(nodeId => {\n arr.push(nodeId)\n })\n })\n}\n\nfunction postIndexingMetaSetupLtLteGtGte(\n filterCache: IFilterCache,\n op: FilterOp\n): void {\n // Create an ordered array of individual nodes, ordered (grouped) by the\n // value to which the filter resolves. Nodes per value are ordered by\n // internal.counter, asc.\n // This way non-eq ops can simply slice the array to get a range.\n\n const entriesNullable: Array<\n [FilterValueNullable, Array<IGatsbyNodePartial>]\n > = [...filterCache.byValue.entries()]\n\n // These range checks never return `null` or `undefined` so filter those out\n // By filtering them out early, the sort should be faster. Could be ...\n const entries: Array<[FilterValue, Array<IGatsbyNodePartial>]> =\n entriesNullable.filter(([v]) => v != null) as Array<\n [FilterValue, Array<IGatsbyNodePartial>]\n >\n\n // Sort all arrays by its value, asc. Ignore/allow potential type casting.\n // Note: while `<` is the inverse of `>=`, the ordering might coerce values.\n // This coercion makes the op no longer idempotent (normally the result of\n // `a < b` is the opposite of `b >= a` for any a or b of the same type). The\n // exception is a number that is `NaN`, which we're ignoring here as it's most\n // likely a bug in the user code. However, when coercing the ops may end up\n // comparing against `NaN`, too. For example: `(\"abc\" <= 12) !== (12 > \"abc\")`\n // which ends up doing `NaN <= 12` and `NaN > \"abc\"`, which will both yield\n // false.\n // So instead we potentially track two ordered lists; ascending and descending\n // and the only difference when comparing the inverse of one to the other\n // should be how these `NaN` cases end up getting ordered.\n // It's fine for `lt` and `lte` to use the same ordered list. Same for gt/gte.\n if (op === `$lt` || op === `$lte`) {\n // Order ascending; first value is lowest\n entries.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))\n } else if (op === `$gt` || op === `$gte`) {\n // Order descending; first value is highest\n entries.sort(([a], [b]) => (a > b ? -1 : a < b ? 1 : 0))\n }\n\n const orderedNodes: Array<IGatsbyNodePartial> = []\n const orderedValues: Array<FilterValue> = []\n const offsets: Map<FilterValue, [number, number]> = new Map()\n entries.forEach(([v, bucket]: [FilterValue, Array<IGatsbyNodePartial>]) => {\n // Record the range containing all nodes with as filter value v\n // The last value of the range should be the offset of the next value\n // (So you should be able to do `nodes.slice(start, stop)` to get them)\n offsets.set(v, [orderedNodes.length, orderedNodes.length + bucket.length])\n // We could do `arr.push(...bucket)` here but that's not safe with very\n // large sets, so we use a regular loop\n bucket.forEach(node => orderedNodes.push(node))\n orderedValues.push(v)\n })\n\n if (op === `$lt` || op === `$lte`) {\n filterCache.meta.valuesAsc = orderedValues\n filterCache.meta.nodesByValueAsc = orderedNodes\n // The nodesByValueAsc is ordered by value, but multiple nodes per value are\n // not ordered. To make lt as fast as lte, we must know the start and stop\n // index for each value. Similarly useful for for `ne`.\n filterCache.meta.valueRangesAsc = offsets\n } else if (op === `$gt` || op === `$gte`) {\n filterCache.meta.valuesDesc = orderedValues\n filterCache.meta.nodesByValueDesc = orderedNodes\n // The nodesByValueDesc is ordered by value, but multiple nodes per value are\n // not ordered. To make gt as fast as gte, we must know the start and stop\n // index for each value. Similarly useful for for `ne`.\n filterCache.meta.valueRangesDesc = offsets\n }\n}\n\n/**\n * Given a single non-elemMatch filter path, a list of node types, and a\n * cache, create a cache that for each resulting value of the filter contains\n * all the Nodes in a list.\n * This cache is used for applying the filter and is a massive improvement over\n * looping over all the nodes, when the number of pages (/nodes) scales up.\n */\nexport const ensureIndexByQuery = (\n op: FilterOp,\n filterCacheKey: FilterCacheKey,\n filterPath: Array<string>,\n nodeTypeNames: Array<string>,\n filtersCache: FiltersCache,\n indexFields: Array<string>,\n resolvedFields: Record<string, any>\n): void => {\n const state = store.getState()\n const resolvedNodesCache = state.resolvedNodesCache\n\n const filterCache: IFilterCache = {\n op,\n byValue: new Map<FilterValueNullable, Array<IGatsbyNodePartial>>(),\n meta: {},\n } as IFilterCache\n filtersCache.set(filterCacheKey, filterCache)\n\n // We cache the subsets of nodes by type, but only one type. So if searching\n // through one node type we can prevent a search through all nodes, otherwise\n // it's probably faster to loop through all nodes. Perhaps. Maybe.\n\n if (nodeTypeNames.length === 1) {\n getDataStore()\n .iterateNodesByType(nodeTypeNames[0])\n .forEach(node => {\n addNodeToFilterCache({\n node,\n chain: filterPath,\n filterCache,\n resolvedNodesCache,\n indexFields,\n resolvedFields,\n })\n })\n } else {\n // Here we must first filter for the node type\n // This loop is expensive at scale (!)\n getDataStore()\n .iterateNodes()\n .forEach(node => {\n if (!nodeTypeNames.includes(node.internal.type)) {\n return\n }\n\n addNodeToFilterCache({\n node,\n chain: filterPath,\n filterCache,\n resolvedNodesCache,\n indexFields,\n resolvedFields,\n })\n })\n }\n\n postIndexingMetaSetup(filterCache, op)\n}\n\nexport function ensureEmptyFilterCache(\n filterCacheKey,\n nodeTypeNames: Array<string>,\n filtersCache: FiltersCache,\n indexFields: Array<string>,\n resolvedFields: Record<string, any>\n): void {\n // This is called for queries without any filters\n // We want to cache the result since it's basically a list of nodes by type(s)\n // There are sites that have multiple queries which are empty\n\n const state = store.getState()\n const resolvedNodesCache = state.resolvedNodesCache\n const orderedByCounter: Array<IGatsbyNodePartial> = []\n\n filtersCache.set(filterCacheKey, {\n op: `$eq`, // Ignore.\n byValue: new Map<FilterValueNullable, Array<IGatsbyNodePartial>>(),\n meta: {\n orderedByCounter, // This is what we want\n },\n })\n\n if (nodeTypeNames.length === 1) {\n getDataStore()\n .iterateNodesByType(nodeTypeNames[0])\n .forEach(node => {\n if (!node.__gatsby_resolved) {\n const typeName = node.internal.type\n const resolvedNodes = resolvedNodesCache.get(typeName)\n const resolved = resolvedNodes?.get(node.id)\n if (resolved !== undefined) {\n node.__gatsby_resolved = resolved\n }\n }\n orderedByCounter.push(\n getGatsbyNodePartial(node, indexFields, resolvedFields)\n )\n })\n } else {\n // Here we must first filter for the node type\n // This loop is expensive at scale (!)\n getDataStore()\n .iterateNodes()\n .forEach(node => {\n if (nodeTypeNames.includes(node.internal.type)) {\n if (!node.__gatsby_resolved) {\n const typeName = node.internal.type\n const resolvedNodes = resolvedNodesCache.get(typeName)\n const resolved = resolvedNodes?.get(node.id)\n if (resolved !== undefined) {\n node.__gatsby_resolved = resolved\n }\n }\n orderedByCounter.push(\n getGatsbyNodePartial(node, indexFields, resolvedFields)\n )\n }\n })\n }\n\n // Since each node can only have one type, we shouldn't have to be concerned\n // about duplicates in this array. Just make sure they're sorted.\n orderedByCounter.sort(sortByIds)\n}\n\nfunction addNodeToFilterCache({\n node,\n chain,\n filterCache,\n resolvedNodesCache,\n indexFields,\n resolvedFields,\n valueOffset = node,\n}: {\n node: IGatsbyNode\n chain: Array<string>\n filterCache: IFilterCache\n resolvedNodesCache: Map<string, any>\n indexFields: Array<string>\n resolvedFields: Record<string, any>\n valueOffset?: any\n}): void {\n // There can be a filter that targets `__gatsby_resolved` so fix that first\n if (!node.__gatsby_resolved) {\n const typeName = node.internal.type\n const resolvedNodes = resolvedNodesCache.get(typeName)\n node.__gatsby_resolved = resolvedNodes?.get(node.id)\n }\n\n // - for plain query, valueOffset === node\n // - for elemMatch, valueOffset is sub-tree of the node to continue matching\n let v = valueOffset as any\n let i = 0\n while (i < chain.length && v) {\n const nextProp = chain[i++]\n v = v[nextProp]\n }\n\n if (\n (typeof v !== `string` &&\n typeof v !== `number` &&\n typeof v !== `boolean` &&\n v !== null) ||\n i !== chain.length\n ) {\n if (i === chain.length && Array.isArray(v)) {\n // The op resolved to an array\n // Add an entry for each element of the array. This would work for ops\n // like eq and ne, but not sure about range ops like lt,lte,gt,gte.\n\n v.forEach(v =>\n markNodeForValue(filterCache, node, v, indexFields, resolvedFields)\n )\n\n return\n }\n\n // This means that either\n // - The filter resolved to `undefined`, or\n // - The filter resolved to something other than a primitive\n // Set the value to `undefined` to mark \"path does not (fully) exist\"\n v = undefined\n }\n\n markNodeForValue(filterCache, node, v, indexFields, resolvedFields)\n}\n\nfunction markNodeForValue(\n filterCache: IFilterCache,\n node: IGatsbyNode,\n value: FilterValueNullable,\n indexFields: Array<string>,\n resolvedFields: Record<string, any>\n): void {\n let arr = filterCache.byValue.get(value)\n if (!arr) {\n arr = []\n filterCache.byValue.set(value, arr)\n }\n\n const partial = getGatsbyNodePartial(node, indexFields, resolvedFields)\n if (!arr.includes(partial)) {\n arr.push(partial)\n }\n}\n\nexport const ensureIndexByElemMatch = (\n op: FilterOp,\n filterCacheKey: FilterCacheKey,\n filter: IDbQueryElemMatch,\n nodeTypeNames: Array<string>,\n filtersCache: FiltersCache,\n indexFields: Array<string>,\n resolvedFields: Record<string, any>\n): void => {\n // Given an elemMatch filter, generate the cache that contains all nodes that\n // matches a given value for that sub-query\n\n const state = store.getState()\n const { resolvedNodesCache } = state\n\n const filterCache: IFilterCache = {\n op,\n byValue: new Map<FilterValueNullable, Array<IGatsbyNodePartial>>(),\n meta: {},\n } as IFilterCache\n filtersCache.set(filterCacheKey, filterCache)\n\n if (nodeTypeNames.length === 1) {\n getDataStore()\n .iterateNodesByType(nodeTypeNames[0])\n .forEach(node => {\n addNodeToBucketWithElemMatch({\n node,\n valueAtCurrentStep: node,\n filter,\n filterCache,\n resolvedNodesCache,\n indexFields,\n resolvedFields,\n })\n })\n } else {\n // Expensive at scale\n getDataStore()\n .iterateNodes()\n .forEach(node => {\n if (!nodeTypeNames.includes(node.internal.type)) {\n return\n }\n\n addNodeToBucketWithElemMatch({\n node,\n valueAtCurrentStep: node,\n filter,\n filterCache,\n resolvedNodesCache,\n indexFields,\n resolvedFields,\n })\n })\n }\n\n postIndexingMetaSetup(filterCache, op)\n}\n\nfunction addNodeToBucketWithElemMatch({\n node,\n valueAtCurrentStep, // Arbitrary step on the path inside the node\n filter,\n filterCache,\n resolvedNodesCache,\n indexFields,\n resolvedFields,\n}: {\n node: IGatsbyNode\n valueAtCurrentStep: any // Arbitrary step on the path inside the node\n filter: IDbQueryElemMatch\n filterCache: IFilterCache\n resolvedNodesCache\n indexFields: Array<string>\n resolvedFields: Record<string, any>\n}): void {\n // There can be a filter that targets `__gatsby_resolved` so fix that first\n if (!node.__gatsby_resolved) {\n const typeName = node.internal.type\n const resolvedNodes = resolvedNodesCache.get(typeName)\n node.__gatsby_resolved = resolvedNodes?.get(node.id)\n }\n\n const { path, nestedQuery } = filter\n\n // Find the value to apply elemMatch to\n let i = 0\n while (i < path.length && valueAtCurrentStep) {\n const nextProp = path[i++]\n valueAtCurrentStep = valueAtCurrentStep[nextProp]\n }\n\n if (path.length !== i) {\n // Found undefined before the end of the path\n return\n }\n\n // `v` should now be an elemMatch target, probably an array (but maybe not)\n if (!Array.isArray(valueAtCurrentStep)) {\n // It's possible to `elemMatch` on a non-array so let's support that too\n valueAtCurrentStep = [valueAtCurrentStep]\n }\n\n // Note: We need to check all elements because the node may need to be added\n // to multiple buckets (`{a:[{b:3},{b:4}]}`, for `a.elemMatch.b/eq` that\n // node ends up in buckets for value 3 and 4. This may lead to duplicate\n // work when elements resolve to the same value, but that can't be helped.\n valueAtCurrentStep.forEach(elem => {\n if (nestedQuery.type === `elemMatch`) {\n addNodeToBucketWithElemMatch({\n node,\n valueAtCurrentStep: elem,\n filter: nestedQuery,\n filterCache,\n resolvedNodesCache,\n indexFields,\n resolvedFields,\n })\n } else {\n // Now take same route as non-elemMatch filters would take\n addNodeToFilterCache({\n node,\n chain: nestedQuery.path,\n filterCache,\n resolvedNodesCache,\n indexFields,\n resolvedFields,\n valueOffset: elem,\n })\n }\n })\n}\n\nconst binarySearchAsc = (\n values: Array<FilterValue>, // Assume ordered asc\n needle: FilterValue\n): [number, number] | undefined => {\n let min = 0\n let max = values.length - 1\n let pivot = Math.floor(values.length / 2)\n while (min <= max) {\n const value = values[pivot]\n if (needle < value) {\n // Move pivot to middle of nodes left of current pivot\n // assert pivot < max\n max = pivot\n } else if (needle > value) {\n // Move pivot to middle of nodes right of current pivot\n // assert pivot > min\n min = pivot\n } else {\n // This means needle === value\n // TODO: except for NaN ... and potentially certain type casting cases\n return [pivot, pivot]\n }\n\n if (max - min <= 1) {\n // End of search. Needle not found (as expected). Use pivot as index.\n // If the needle was not found, max-min==1 and max is returned.\n return [min, max]\n }\n\n pivot = min + Math.floor((max - min) / 2)\n }\n\n // Shouldn't be reachable\n return undefined\n}\nconst binarySearchDesc = (\n values: Array<FilterValue>, // Assume ordered desc\n needle: FilterValue\n): [number, number] | undefined => {\n let min = 0\n let max = values.length - 1\n let pivot = Math.floor(values.length / 2)\n while (min <= max) {\n const value = values[pivot]\n if (needle < value) {\n // Move pivot to middle of nodes right of current pivot\n // assert pivot < min\n min = pivot\n } else if (needle > value) {\n // Move pivot to middle of nodes left of current pivot\n // assert pivot > max\n max = pivot\n } else {\n // This means needle === value\n // TODO: except for NaN ... and potentially certain type casting cases\n return [pivot, pivot]\n }\n\n if (max - min <= 1) {\n // End of search. Needle not found (as expected). Use pivot as index.\n // If the needle was not found, max-min==1 and max is returned.\n return [min, max]\n }\n\n pivot = min + Math.floor((max - min) / 2)\n }\n\n // Shouldn't be reachable\n return undefined\n}\n\n/**\n * Given the cache key for a filter and a target value return the list of nodes\n * that resolve to this value. The returned array should be ordered by id.\n * This returns `undefined` if there is no such node\n *\n * Basically if the filter was {a: {b: {slug: {eq: \"foo/bar\"}}}} then it will\n * return all the nodes that have `node.slug === \"foo/bar\"`. That usually (but\n * not always) at most one node for slug, but this filter can apply to anything.\n *\n * Arrays returned by this function must be ordered by internal.counter and\n * not contain duplicate nodes (!)\n */\nexport const getNodesFromCacheByValue = (\n filterCacheKey: FilterCacheKey,\n filterValue: FilterValueNullable,\n filtersCache: FiltersCache,\n wasElemMatch\n): Array<IGatsbyNodePartial> | undefined => {\n const filterCache = filtersCache.get(filterCacheKey)\n if (!filterCache) {\n return undefined\n }\n\n const op = filterCache.op\n\n if (op === `$eq`) {\n // Arrays in byValue are assumed to be ordered by counter\n\n if (filterValue == null) {\n // Edge case for null; fetch all nodes for `null` and `undefined` because\n // `$eq` also returns nodes without the path when searching for `null`.\n // Not all ops do so, so we map non-existing paths to `undefined`.\n\n const arrNull = filterCache.byValue.get(null) ?? []\n const arrUndef = filterCache.byValue.get(undefined) ?? []\n\n // Merge the two (ordered) arrays and return an ordered deduped array\n // TODO: is there a reason left why we cant just cache this merged list?\n return unionNodesByCounter(arrNull, arrUndef)\n }\n\n return filterCache.byValue.get(filterValue)\n }\n\n if (op === `$in`) {\n if (!Array.isArray(filterValue)) {\n throw new Error(\"The argument to the `in` comparator should be an array\")\n }\n const filterValueArr: Array<FilterValueNullable> = filterValue\n\n const set: Set<IGatsbyNodePartial> = new Set()\n\n // TODO: we can also mergeSort for every step. this may perform worse because of how memory in js works.\n // For every value in the needle array, find the bucket of nodes for\n // that value, add this bucket of nodes to one list, return the list.\n filterValueArr.forEach((v: FilterValueNullable) =>\n filterCache.byValue.get(v)?.forEach(v => set.add(v))\n )\n\n const arr = [...set] // this is bad for perf but will guarantee us a unique set :(\n arr.sort(sortByIds)\n\n // Note: it's very unlikely that the list of filter values is big so .includes should be fine here\n if (filterValueArr.includes(null)) {\n // Like all other ops, `in: [null]` behaves weirdly, allowing all nodes\n // that do not actually have a (complete) path (v=undefined)\n const nodes = filterCache.byValue.get(undefined)\n if (nodes) {\n // This will also dedupe so don't do that immediately\n return unionNodesByCounter(nodes, arr)\n }\n }\n\n // elemMatch can cause a node to appear in multiple buckets so we must dedupe first\n if (wasElemMatch) {\n expensiveDedupeInline(arr)\n }\n\n return arr\n }\n\n if (op === `$nin`) {\n // This is essentially the same as the $ne operator, just with multiple\n // values to exclude.\n\n if (!Array.isArray(filterValue)) {\n throw new Error(`The $nin operator expects an array as value`)\n }\n\n const values: Set<FilterValueNullable> = new Set(filterValue)\n const set = new Set(filterCache.meta.nodesUnordered)\n\n // Do the action for \"$ne\" for each element in the set of values\n values.forEach(filterValue => {\n removeBucketFromSet(filterValue, filterCache, set)\n })\n\n // TODO: there's probably a more efficient algorithm to do set\n // subtraction in such a way that we don't have to re-sort\n return [...set].sort(sortByIds)\n }\n\n if (op === `$ne`) {\n const set = new Set(filterCache.meta.nodesUnordered)\n\n removeBucketFromSet(filterValue, filterCache, set)\n\n // TODO: there's probably a more efficient algorithm to do set\n // subtraction in such a way that we don't have to resort here\n return [...set].sort(sortByIds)\n }\n\n if (op === `$regex`) {\n // Note: $glob is converted to $regex so $glob filters go through here, too\n // Aside from the input pattern format, further behavior is exactly the same.\n\n // The input to the filter must be a string (including leading/trailing slash and regex flags)\n // By the time the filter reaches this point, the filterValue has to be a regex.\n\n if (!(filterValue instanceof RegExp)) {\n throw new Error(\n `The value for the $regex comparator must be an instance of RegExp`\n )\n }\n const regex = filterValue\n\n const arr: Array<IGatsbyNodePartial> = []\n filterCache.byValue.forEach((nodes, value) => {\n // TODO: does the value have to be a string for $regex? Can we auto-ignore any non-strings? Or does it coerce.\n // Note: for legacy reasons partial paths should also be included for regex\n if (value !== undefined && regex.test(String(value))) {\n nodes.forEach(node => arr.push(node))\n }\n })\n\n // TODO: we _can_ cache this list as well. Might make sense if it turns out that $regex is mostly used with literals\n // TODO: it may make sense to first collect all buckets and then to .concat them, or merge sort them\n\n arr.sort(sortByIds)\n\n // elemMatch can cause a node to appear in multiple buckets so we must dedupe\n if (wasElemMatch) {\n expensiveDedupeInline(arr)\n }\n\n return arr\n }\n\n if (filterValue == null) {\n if (op === `$lt` || op === `$gt`) {\n // Nothing is lt/gt null\n return undefined\n }\n\n // This is an edge case and this value should be directly indexed\n // For `lte`/`gte` this should only return nodes for `null`, not a \"range\"\n return filterCache.byValue.get(filterValue)\n }\n\n if (Array.isArray(filterValue)) {\n throw new Error(\n \"Array is an invalid filter value for the `\" + op + \"` comparator\"\n )\n }\n\n if (filterValue instanceof RegExp) {\n // This is most likely an internal error, although it is possible for\n // users to talk to this API more directly.\n throw new Error(\n `A RegExp instance is only valid for $regex and $glob comparators`\n )\n }\n\n if (op === `$lt`) {\n // First try a direct approach. If a value is queried that also exists then\n // we can prevent a binary search through the whole list, O(1) vs O(log n)\n\n const ranges = filterCache.meta.valueRangesAsc\n const nodes = filterCache.meta.nodesByValueAsc\n\n const range = ranges!.get(filterValue)\n if (range) {\n const arr = nodes!.slice(0, range[0])\n arr.sort(sortByIds)\n // elemMatch can cause a node to appear in multiple buckets so we must dedupe\n if (wasElemMatch) {\n expensiveDedupeInline(arr)\n }\n return arr\n }\n\n // Query may ask for a value that doesn't appear in the list, like if the\n // list is [1, 2, 5, 6] and the query is <= 3. In that case we have to\n // apply a search (we'll do binary) to determine the offset to slice from.\n\n // Note: for lte, the valueAsc array must be list at this point\n const values = filterCache.meta.valuesAsc as Array<FilterValue>\n // It shouldn't find the targetValue (but it might) and return the index of\n // the two value between which targetValue sits, or first/last element.\n const point = binarySearchAsc(values, filterValue)\n if (!point) {\n return undefined\n }\n const [pivotMin, pivotMax] = point\n\n // Each pivot index must have a value and a range\n // The returned min/max index may include the lower/upper bound, so we still\n // have to do lte checks for both values.\n let pivotValue = values[pivotMax]\n if (pivotValue > filterValue) {\n pivotValue = values[pivotMin]\n }\n\n // Note: the pivot value _shouldnt_ match the filter value because that\n // means the value was actually found, but those should have been indexed\n // so should have yielded a result in the .get() above.\n\n const [exclPivot, inclPivot] = ranges!.get(pivotValue) as [number, number]\n\n // Note: technically, `5 <= \"5\" === true` but `5` would not be cached.\n // So we have to consider weak comparison and may have to include the pivot\n const until = pivotValue < filterValue ? inclPivot : exclPivot\n const arr = nodes!.slice(0, until)\n arr.sort(sortByIds)\n // elemMatch can cause a node to appear in multiple buckets so we must dedupe\n if (wasElemMatch) {\n expensiveDedupeInline(arr)\n }\n return arr\n }\n\n if (op === `$lte`) {\n // First try a direct approach. If a value is queried that also exists then\n // we can prevent a binary search through the whole list, O(1) vs O(log n)\n\n const ranges = filterCache.meta.valueRangesAsc\n const nodes = filterCache.meta.nodesByValueAsc\n\n const range = ranges!.get(filterValue)\n if (range) {\n const arr = nodes!.slice(0, range[1])\n arr.sort(sortByIds)\n // elemMatch can cause a node to appear in multiple buckets so we must dedupe\n if (wasElemMatch) {\n expensiveDedupeInline(arr)\n }\n return arr\n }\n\n // Query may ask for a value that doesn't appear in the list, like if the\n // list is [1, 2, 5, 6] and the query is <= 3. In that case we have to\n // apply a search (we'll do binary) to determine the offset to slice from.\n\n // Note: for lte, the valueAsc array must be list at this point\n const values = filterCache.meta.valuesAsc as Array<FilterValue>\n // It shouldn't find the targetValue (but it might) and return the index of\n // the two value between which targetValue sits, or first/last element.\n const point = binarySearchAsc(values, filterValue)\n if (!point) {\n return undefined\n }\n const [pivotMin, pivotMax] = point\n\n // Each pivot index must have a value and a range\n // The returned min/max index may include the lower/upper bound, so we still\n // have to do lte checks for both values.\n let pivotValue = values[pivotMax]\n if (pivotValue > filterValue) {\n pivotValue = values[pivotMin]\n }\n\n // Note: the pivot value _shouldnt_ match the filter value because that\n // means the value was actually found, but those should have been indexed\n // so should have yielded a result in the .get() above.\n\n const [exclPivot, inclPivot] = ranges!.get(pivotValue) as [number, number]\n\n // Note: technically, `5 <= \"5\" === true` but `5` would not be cached.\n // So we have to consider weak comparison and may have to include the pivot\n const until = pivotValue <= filterValue ? inclPivot : exclPivot\n const arr = nodes!.slice(0, until)\n arr.sort(sortByIds)\n // elemMatch can cause a node to appear in multiple buckets so we must dedupe\n if (wasElemMatch) {\n expensiveDedupeInline(arr)\n }\n return arr\n }\n\n if (op === `$gt`) {\n // First try a direct approach. If a value is queried that also exists then\n // we can prevent a binary search through the whole list, O(1) vs O(log n)\n\n const ranges = filterCache.meta.valueRangesDesc\n const nodes = filterCache.meta.nodesByValueDesc\n\n const range = ranges!.get(filterValue)\n if (range) {\n const arr = nodes!.slice(0, range[0]).reverse()\n arr.sort(sortByIds)\n // elemMatch can cause a node to appear in multiple buckets so we must dedupe\n if (wasElemMatch) {\n expensiveDedupeInline(arr)\n }\n return arr\n }\n\n // Query may ask for a value that doesn't appear in the list, like if the\n // list is [1, 2, 5, 6] and the query is <= 3. In that case we have to\n // apply a search (we'll do binary) to determine the offset to slice from.\n\n // Note: for gte, the valueDesc array must be list at this point\n const values = filterCache.meta.valuesDesc as Array<FilterValue>\n // It shouldn't find the targetValue (but it might) and return the index of\n // the two value between which targetValue sits, or first/last element.\n const point = binarySearchDesc(values, filterValue)\n if (!point) {\n return undefined\n }\n const [pivotMin, pivotMax] = point\n\n // Each pivot index must have a value and a range\n // The returned min/max index may include the lower/upper bound, so we still\n // have to do gte checks for both values.\n let pivotValue = values[pivotMax]\n if (pivotValue < filterValue) {\n pivotValue = values[pivotMin]\n }\n\n // Note: the pivot value _shouldnt_ match the filter value because that\n // means the value was actually found, but those should have been indexed\n // so should have yielded a result in the .get() above.\n\n const [exclPivot, inclPivot] = ranges!.get(pivotValue) as [number, number]\n\n // Note: technically, `5 >= \"5\" === true` but `5` would not be cached.\n // So we have to consider weak comparison and may have to include the pivot\n const until = pivotValue > filterValue ? inclPivot : exclPivot\n const arr = nodes!.slice(0, until).reverse()\n arr.sort(sortByIds)\n // elemMatch can cause a node to appear in multiple buckets so we must dedupe\n if (wasElemMatch) {\n expensiveDedupeInline(arr)\n }\n return arr\n }\n\n if (op === `$gte`) {\n // First try a direct approach. If a value is queried that also exists then\n // we can prevent a binary search through the whole list, O(1) vs O(log n)\n\n const ranges = filterCache.meta.valueRangesDesc\n const nodes = filterCache.meta.nodesByValueDesc\n\n const range = ranges!.get(filterValue)\n if (range) {\n const arr = nodes!.slice(0, range[1]).reverse()\n arr.sort(sortByIds)\n // elemMatch can cause a node to appear in multiple buckets so we must dedupe\n if (wasElemMatch) {\n expensiveDedupeInline(arr)\n }\n return arr\n }\n\n // Query may ask for a value that doesn't appear in the list, like if the\n // list is [1, 2, 5, 6] and the query is <= 3. In that case we have to\n // apply a search (we'll do binary) to determine the offset to slice from.\n\n // Note: for gte, the valueDesc array must be list at this point\n const values = filterCache.meta.valuesDesc as Array<FilterValue>\n // It shouldn't find the targetValue (but it might) and return the index of\n // the two value between which targetValue sits, or first/last element.\n const point = binarySearchDesc(values, filterValue)\n if (!point) {\n return undefined\n }\n const [pivotMin, pivotMax] = point\n\n // Each pivot index must have a value and a range\n // The returned min/max index may include the lower/upper bound, so we still\n // have to do gte checks for both values.\n let pivotValue = values[pivotMax]\n if (pivotValue < filterValue) {\n pivotValue = values[pivotMin]\n }\n\n // Note: the pivot value _shouldnt_ match the filter value because that\n // means the value was actually found, but those should have been indexed\n // so should have yielded a result in the .get() above.\n\n const [exclPivot, inclPivot] = ranges!.get(pivotValue) as [number, number]\n\n // Note: technically, `5 >= \"5\" === true` but `5` would not be cached.\n // So we have to consider weak comparison and may have to include the pivot\n const until = pivotValue >= filterValue ? inclPivot : exclPivot\n const arr = nodes!.slice(0, until).reverse()\n arr.sort(sortByIds)\n // elemMatch can cause a node to appear in multiple buckets so we must dedupe\n if (wasElemMatch) {\n expensiveDedupeInline(arr)\n }\n return arr\n }\n\n // Unreachable because we checked all values of FilterOp (which op is)\n return undefined\n}\n\nfunction removeBucketFromSet(\n filterValue: FilterValueNullable,\n filterCache: IFilterCache,\n set: Set<IGatsbyNodePartial>\n): void {\n if (filterValue === null) {\n // Edge case: $ne with `null` returns only the nodes that contain the full\n // path and that don't resolve to null, so drop `undefined` as well.\n let cache = filterCache.byValue.get(undefined)\n if (cache) cache.forEach(node => set.delete(node))\n cache = filterCache.byValue.get(null)\n if (cache) cache.forEach(node => set.delete(node))\n } else {\n // Not excluding null so it should include undefined leafs or leafs where\n // only the partial path exists for whatever reason.\n const cache = filterCache.byValue.get(filterValue)\n if (cache) cache.forEach(node => set.delete(node))\n }\n}\n\n/**\n * Finds the intersection of two arrays in O(n) with n = min(a.length, b.length)\n * The returned set should not contain duplicate nodes.\n *\n * The input should be ordered by node.internal.counter and it will return a\n * list that is also ordered by node.internal.counter\n */\nexport function intersectNodesByCounter(\n a: Array<IGatsbyNodePartial>,\n b: Array<IGatsbyNodePartial>\n): Array<IGatsbyNodePartial> {\n let pointerA = 0\n let pointerB = 0\n // TODO: perf check: is it helpful to init the array to min(maxA,maxB) items?\n const result: Array<IGatsbyNodePartial> = []\n const maxA = a.length\n const maxB = b.length\n let lastAdded: IGatsbyNodePartial | undefined = undefined // Used to dedupe the list\n\n while (pointerA < maxA && pointerB < maxB) {\n const counterA = a[pointerA].internal.counter\n const counterB = b[pointerB].internal.counter\n\n if (counterA < counterB) {\n pointerA++\n } else if (counterA > counterB) {\n pointerB++\n } else {\n if (a[pointerA].id !== b[pointerB].id) {\n throw new Error(\n `Invariant violation: inconsistent node counters detected`\n )\n }\n // nodeA===nodeB. Make sure we didn't just add this node already.\n // Since input arrays are sorted, the same node should be grouped\n // back to back, so even if both input arrays contained the same node\n // twice, this check would prevent the result from getting duplicate nodes\n if (lastAdded !== a[pointerA]) {\n result.push(a[pointerA])\n lastAdded = a[pointerA]\n }\n pointerA++\n pointerB++\n }\n }\n\n return result\n}\n\n/**\n * Merge two lists of nodes.\n * The returned set should not contain duplicate nodes.\n *\n * The input should be ordered by node.internal.counter and it will return a\n * list that is also ordered by node.internal.counter\n */\nexport function unionNodesByCounter(\n a: Array<IGatsbyNodePartial>,\n b: Array<IGatsbyNodePartial>\n): Array<IGatsbyNodePartial> {\n // TODO: perf check: is it helpful to init the array to max(maxA,maxB) items?\n const arr: Array<IGatsbyNodePartial> = []\n let lastAdded: IGatsbyNodePartial | undefined = undefined // Used to dedupe the list\n\n let pointerA = 0\n let pointerB = 0\n const maxA = a.length\n const maxB = b.length\n\n while (pointerA < maxA && pointerB < maxB) {\n const counterA = a[pointerA].internal.counter\n const counterB = b[pointerB].internal.counter\n\n if (counterA < counterB) {\n if (lastAdded !== a[pointerA]) {\n arr.push(a[pointerA])\n lastAdded = a[pointerA]\n }\n pointerA++\n } else if (counterA > counterB) {\n if (lastAdded !== b[pointerB]) {\n arr.push(b[pointerB])\n lastAdded = b[pointerB]\n }\n pointerB++\n } else {\n if (lastAdded !== a[pointerA]) {\n arr.push(a[pointerA])\n lastAdded = a[pointerA]\n }\n pointerA++\n pointerB++\n }\n }\n\n while (pointerA < maxA) {\n if (lastAdded !== a[pointerA]) {\n arr.push(a[pointerA])\n lastAdded = a[pointerA]\n }\n pointerA++\n }\n\n while (pointerB < maxB) {\n if (lastAdded !== b[pointerB]) {\n arr.push(b[pointerB])\n lastAdded = b[pointerB]\n }\n pointerB++\n }\n\n return arr\n}\n\nfunction expensiveDedupeInline(arr: Array<IGatsbyNodePartial>): void {\n // An elemMatch filter may cause duplicates to appear in a bucket.\n // Since the bucket is sorted those should now be back to back\n // Worst case this is a fast O(n) loop that does nothing.\n let prev: IGatsbyNodePartial | undefined = undefined\n\n // We copy-on-find because a splice is expensive and we can't use Sets\n\n let j = 0\n for (let i = 0; i < arr.length; ++i) {\n const node = arr[i]\n if (node !== prev) {\n // Only start copying the remainder of the list once a dupe is found\n if (i !== j) {\n arr[j] = node\n }\n ++j\n prev = node\n }\n }\n arr.length = j\n}\n\nexport function getSortFieldIdentifierKeys(\n indexFields: Array<string>,\n resolvedFields: Record<string, any>\n): Array<string> {\n const dottedFields = objectToDottedField(resolvedFields)\n const dottedFieldKeys = Object.keys(dottedFields)\n const fieldKeys = indexFields.map(field => {\n if (\n dottedFields[field] ||\n dottedFieldKeys.some(key => field.startsWith(key))\n ) {\n return `__gatsby_resolved.${field}`\n } else {\n return field\n }\n })\n\n return fieldKeys\n}\n"],"file":"indexing.js"}
|
|
@@ -68,7 +68,7 @@ async function createGraphqlEngineBundle(rootDir, reporter, isVerbose) {
|
|
|
68
68
|
}, {})],
|
|
69
69
|
module: {
|
|
70
70
|
rules: [{
|
|
71
|
-
test:
|
|
71
|
+
test: /node_modules[/\\]lmdb[/\\].*\.[cm]?js/,
|
|
72
72
|
parser: {
|
|
73
73
|
amd: false
|
|
74
74
|
},
|
|
@@ -101,7 +101,7 @@ async function createGraphqlEngineBundle(rootDir, reporter, isVerbose) {
|
|
|
101
101
|
}
|
|
102
102
|
}, {
|
|
103
103
|
// For node binary relocations, include ".node" files as well here
|
|
104
|
-
test: /\.(
|
|
104
|
+
test: /\.([cm]?js|node)$/,
|
|
105
105
|
// it is recommended for Node builds to turn off AMD support
|
|
106
106
|
parser: {
|
|
107
107
|
amd: false
|
|
@@ -122,7 +122,9 @@ async function createGraphqlEngineBundle(rootDir, reporter, isVerbose) {
|
|
|
122
122
|
alias: {
|
|
123
123
|
".cache": process.cwd() + `/.cache/`,
|
|
124
124
|
[require.resolve(`gatsby-cli/lib/reporter/loggers/ink/index.js`)]: false,
|
|
125
|
-
inquirer: false
|
|
125
|
+
inquirer: false,
|
|
126
|
+
// only load one version of lmdb
|
|
127
|
+
lmdb: require.resolve(`lmdb`)
|
|
126
128
|
}
|
|
127
129
|
},
|
|
128
130
|
plugins: [new _webpack.default.DefinePlugin({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/schema/graphql-engine/bundle-webpack.ts"],"names":["extensions","outputDir","path","join","process","cwd","cacheLocation","createGraphqlEngineBundle","rootDir","reporter","isVerbose","schemaSnapshotString","fs","readFile","compiler","name","mode","entry","__dirname","output","filename","libraryTarget","target","externalsPresets","node","cache","type","buildDependencies","config","__filename","externals","mod","builtinModules","reduce","acc","builtinModule","module","rules","test","
|
|
1
|
+
{"version":3,"sources":["../../../src/schema/graphql-engine/bundle-webpack.ts"],"names":["extensions","outputDir","path","join","process","cwd","cacheLocation","createGraphqlEngineBundle","rootDir","reporter","isVerbose","schemaSnapshotString","fs","readFile","compiler","name","mode","entry","__dirname","output","filename","libraryTarget","target","externalsPresets","node","cache","type","buildDependencies","config","__filename","externals","mod","builtinModules","reduce","acc","builtinModule","module","rules","test","parser","amd","use","loader","require","resolve","options","outputAssetBase","byDependency","esm","fullySpecified","exclude","presets","alias","inquirer","lmdb","plugins","webpack","DefinePlugin","SCHEMA_SNAPSHOT","JSON","stringify","env","GATSBY_WEBPACK_LOGGING","includes","WebpackLoggingPlugin","filter","Boolean","Promise","reject","run","err","stats","close","closeErr","compilation"],"mappings":";;;;;;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAPA;AAYA,MAAMA,UAAU,GAAG,CAAE,MAAF,EAAU,KAAV,EAAiB,OAAjB,EAA0B,OAA1B,EAAmC,KAAnC,EAA0C,MAA1C,CAAnB;AAEA,MAAMC,SAAS,GAAGC,IAAI,CAACC,IAAL,CAAUC,OAAO,CAACC,GAAR,EAAV,EAA0B,QAA1B,EAAoC,c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AO,CAAC2B,KAAD,aAACA,KAAD,uBAACA,KAAK,CAAEG,WAAR,CAAd;AACD,OARD;AASD,KAVD;AAWD,GAZM,CAAP;AAaD","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\n\nimport * as path from \"path\"\nimport * as fs from \"fs-extra\"\nimport webpack from \"webpack\"\nimport { printQueryEnginePlugins } from \"./print-plugins\"\nimport mod from \"module\"\nimport { WebpackLoggingPlugin } from \"../../utils/webpack/plugins/webpack-logging\"\nimport reporter from \"gatsby-cli/lib/reporter\"\n\ntype Reporter = typeof reporter\n\nconst extensions = [`.mjs`, `.js`, `.json`, `.node`, `.ts`, `.tsx`]\n\nconst outputDir = path.join(process.cwd(), `.cache`, `query-engine`)\nconst cacheLocation = path.join(\n process.cwd(),\n `.cache`,\n `webpack`,\n `query-engine`\n)\n\nexport async function createGraphqlEngineBundle(\n rootDir: string,\n reporter: Reporter,\n isVerbose?: boolean\n): Promise<webpack.Compilation | undefined> {\n const schemaSnapshotString = await fs.readFile(\n path.join(rootDir, `.cache`, `schema.gql`),\n `utf-8`\n )\n await printQueryEnginePlugins()\n\n const compiler = webpack({\n name: `Query Engine`,\n // mode: `production`,\n mode: `none`,\n entry: path.join(__dirname, `entry.js`),\n output: {\n path: outputDir,\n filename: `index.js`,\n libraryTarget: `commonjs`,\n },\n target: `node`,\n externalsPresets: {\n node: false,\n },\n cache: {\n type: `filesystem`,\n name: `graphql-engine`,\n cacheLocation,\n buildDependencies: {\n config: [__filename],\n },\n },\n // those are required in some runtime paths, but we don't need them\n externals: [\n `cbor-x`, // optional dep of lmdb-store, but we are using `msgpack` (default) encoding, so we don't need it\n `babel-runtime/helpers/asyncToGenerator`, // undeclared dep of yurnalist (but used in code path we don't use)\n `electron`, // :shrug: `got` seems to have electron specific code path\n mod.builtinModules.reduce((acc, builtinModule) => {\n if (builtinModule === `fs`) {\n acc[builtinModule] = `global _actualFsWrapper`\n } else {\n acc[builtinModule] = `commonjs ${builtinModule}`\n }\n\n return acc\n }, {}),\n ],\n module: {\n rules: [\n {\n test: /node_modules[/\\\\]lmdb[/\\\\].*\\.[cm]?js/,\n parser: { amd: false },\n use: [\n {\n loader: require.resolve(`@vercel/webpack-asset-relocator-loader`),\n options: {\n outputAssetBase: `assets`,\n },\n },\n {\n loader: require.resolve(`./lmdb-bundling-patch`),\n },\n ],\n },\n {\n test: /\\.m?js$/,\n type: `javascript/auto`,\n resolve: {\n byDependency: {\n esm: {\n fullySpecified: false,\n },\n },\n },\n },\n {\n test: /\\.ts$/,\n exclude: /node_modules/,\n use: {\n loader: `babel-loader`,\n options: {\n presets: [`@babel/preset-typescript`],\n },\n },\n },\n {\n // For node binary relocations, include \".node\" files as well here\n test: /\\.([cm]?js|node)$/,\n // it is recommended for Node builds to turn off AMD support\n parser: { amd: false },\n use: {\n loader: require.resolve(`@vercel/webpack-asset-relocator-loader`),\n options: {\n outputAssetBase: `assets`,\n },\n },\n },\n {\n test: /\\.txt/,\n type: `asset/resource`,\n },\n ],\n },\n resolve: {\n extensions,\n alias: {\n \".cache\": process.cwd() + `/.cache/`,\n\n [require.resolve(`gatsby-cli/lib/reporter/loggers/ink/index.js`)]:\n false,\n inquirer: false,\n // only load one version of lmdb\n lmdb: require.resolve(`lmdb`),\n },\n },\n plugins: [\n new webpack.DefinePlugin({\n // \"process.env.GATSBY_LOGGER\": JSON.stringify(`yurnalist`),\n \"process.env.GATSBY_EXPERIMENTAL_LMDB_STORE\": `true`,\n \"process.env.GATSBY_SKIP_WRITING_SCHEMA_TO_FILE\": `true`,\n SCHEMA_SNAPSHOT: JSON.stringify(schemaSnapshotString),\n \"process.env.GATSBY_LOGGER\": JSON.stringify(`yurnalist`),\n }),\n process.env.GATSBY_WEBPACK_LOGGING?.includes(`query-engine`) &&\n new WebpackLoggingPlugin(rootDir, reporter, isVerbose),\n ].filter(Boolean) as Array<webpack.WebpackPluginInstance>,\n })\n\n return new Promise((resolve, reject) => {\n compiler.run((err, stats) => {\n compiler.close(closeErr => {\n if (err) {\n return reject(err)\n }\n if (closeErr) {\n return reject(closeErr)\n }\n return resolve(stats?.compilation)\n })\n })\n })\n}\n"],"file":"bundle-webpack.js"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function (source: string): string;
|
|
1
|
+
export default function (this: any, source: string): string;
|
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
exports.__esModule = true;
|
|
4
6
|
exports.default = _default;
|
|
5
7
|
|
|
6
|
-
var
|
|
8
|
+
var _path = require("gatsby-core-utils/path");
|
|
9
|
+
|
|
10
|
+
var _path2 = _interopRequireDefault(require("path"));
|
|
7
11
|
|
|
8
|
-
|
|
12
|
+
/* eslint-disable @babel/no-invalid-this */
|
|
13
|
+
|
|
14
|
+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
15
|
+
// we need to require this module, we can't use import here
|
|
16
|
+
const {
|
|
17
|
+
createRequire
|
|
18
|
+
} = require(`module`); // This is hacky webpack loader that does string replacements to
|
|
9
19
|
// allow lmdb@2 to be bundled by webpack for engines.
|
|
10
20
|
// Currently `@vercel/webpack-asset-relocator-loader doesn't handle
|
|
11
21
|
// the way lmdb is loading binaries and dictionary file
|
|
@@ -20,16 +30,20 @@ var _gatsbyCoreUtils = require("gatsby-core-utils");
|
|
|
20
30
|
// - https://github.com/DoctorEvidence/lmdb-js/blob/544b3fda402f24a70a0e946921e4c9134c5adf85/node-index.js#L14-L16
|
|
21
31
|
// - https://github.com/DoctorEvidence/lmdb-js/blob/544b3fda402f24a70a0e946921e4c9134c5adf85/open.js#L77
|
|
22
32
|
// Reliance on `import.meta.url` + usage of `.replace` is what seems to cause problems currently.
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
+
|
|
35
|
+
|
|
23
36
|
function _default(source) {
|
|
24
37
|
let lmdbBinaryLocation;
|
|
25
38
|
|
|
26
39
|
try {
|
|
27
|
-
|
|
28
|
-
const nodeGypBuild = lmdbRequire(`node-gyp-build`);
|
|
40
|
+
var _this$_module$resourc;
|
|
29
41
|
|
|
30
|
-
const
|
|
42
|
+
const lmdbRoot = (this === null || this === void 0 ? void 0 : (_this$_module$resourc = this._module.resourceResolveData) === null || _this$_module$resourc === void 0 ? void 0 : _this$_module$resourc.descriptionFileRoot) || _path2.default.dirname(this.resourcePath).replace(`/dist`, ``);
|
|
31
43
|
|
|
32
|
-
|
|
44
|
+
const lmdbRequire = createRequire(this.resourcePath);
|
|
45
|
+
const nodeGypBuild = lmdbRequire(`node-gyp-build`);
|
|
46
|
+
lmdbBinaryLocation = (0, _path.slash)(_path2.default.relative(_path2.default.dirname(this.resourcePath), nodeGypBuild.path(lmdbRoot)));
|
|
33
47
|
} catch (e) {
|
|
34
48
|
return source;
|
|
35
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/schema/graphql-engine/lmdb-bundling-patch.ts"],"names":["source","lmdbBinaryLocation","
|
|
1
|
+
{"version":3,"sources":["../../../src/schema/graphql-engine/lmdb-bundling-patch.ts"],"names":["createRequire","require","source","lmdbBinaryLocation","lmdbRoot","_module","resourceResolveData","descriptionFileRoot","path","dirname","resourcePath","replace","lmdbRequire","nodeGypBuild","relative","e","JSON","stringify"],"mappings":";;;;;;;AAEA;;AACA;;AAHA;;AACA;AAIA;AACA,MAAM;AAAEA,EAAAA;AAAF,IAAoBC,OAAO,CAAE,QAAF,CAAjC,C,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;;;AACe,kBAAqBC,MAArB,EAA6C;AAC1D,MAAIC,kBAAJ;;AACA,MAAI;AAAA;;AACF,UAAMC,QAAQ,GACZ,2EAAMC,OAAN,CAAcC,mBAAd,gFAAmCC,mBAAnC,KACAC,eAAKC,OAAL,CAAa,KAAKC,YAAlB,EAAgCC,OAAhC,CAAyC,OAAzC,EAAkD,EAAlD,CAFF;;AAIA,UAAMC,WAAW,GAAGZ,aAAa,CAAC,KAAKU,YAAN,CAAjC;AACA,UAAMG,YAAY,GAAGD,WAAW,CAAE,gBAAF,CAAhC;AAEAT,IAAAA,kBAAkB,GAAG,iBACnBK,eAAKM,QAAL,CACEN,eAAKC,OAAL,CAAa,KAAKC,YAAlB,CADF,EAEEG,YAAY,CAACL,IAAb,CAAkBJ,QAAlB,CAFF,CADmB,CAArB;AAMD,GAdD,CAcE,OAAOW,CAAP,EAAU;AACV,WAAOb,MAAP;AACD;;AACD,SAAOA,MAAM,CACVS,OADI,CAEF,sCAFE,EAGF,WAAUK,IAAI,CAACC,SAAL,CAAed,kBAAf,CAAmC,GAH3C,EAKJQ,OALI,CAMF,sCANE,EAOF,qCAPE,EASJA,OATI,CAUH,+WAVG,EAWF,sDAXE,CAAP;AAaD","sourcesContent":["/* eslint-disable @babel/no-invalid-this */\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nimport { slash } from \"gatsby-core-utils/path\"\nimport path from \"path\"\n\n// we need to require this module, we can't use import here\nconst { createRequire } = require(`module`)\n\n// This is hacky webpack loader that does string replacements to\n// allow lmdb@2 to be bundled by webpack for engines.\n// Currently `@vercel/webpack-asset-relocator-loader doesn't handle\n// the way lmdb is loading binaries and dictionary file\n// (can't statically analyze it). So we perform few localized changes\n// and we replace dynamic values with hardcoded ones to allow\n// asset-relocator to pick those assets up and handle them.\n//\n// Because lmdb code can diverge, we also pin version in gatsby\n// dependencies and will have manually bump it (with renovate most likely).\n//\n// To solve this upstream few things would need to change:\n// - https://github.com/DoctorEvidence/lmdb-js/blob/544b3fda402f24a70a0e946921e4c9134c5adf85/node-index.js#L14-L16\n// - https://github.com/DoctorEvidence/lmdb-js/blob/544b3fda402f24a70a0e946921e4c9134c5adf85/open.js#L77\n// Reliance on `import.meta.url` + usage of `.replace` is what seems to cause problems currently.\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport default function (this: any, source: string): string {\n let lmdbBinaryLocation: string | undefined\n try {\n const lmdbRoot =\n this?._module.resourceResolveData?.descriptionFileRoot ||\n path.dirname(this.resourcePath).replace(`/dist`, ``)\n\n const lmdbRequire = createRequire(this.resourcePath)\n const nodeGypBuild = lmdbRequire(`node-gyp-build`)\n\n lmdbBinaryLocation = slash(\n path.relative(\n path.dirname(this.resourcePath),\n nodeGypBuild.path(lmdbRoot)\n )\n )\n } catch (e) {\n return source\n }\n return source\n .replace(\n `require$1('node-gyp-build')(dirName)`,\n `require(${JSON.stringify(lmdbBinaryLocation)})`\n )\n .replace(\n `require$2.resolve('./dict/dict.txt')`,\n `require.resolve('../dict/dict.txt')`\n )\n .replace(\n /fs\\.readFileSync\\(new URL\\('\\.\\/dict\\/dict\\.txt',\\s*\\(typeof\\s*document\\s*===\\s*'undefined'\\s*\\?\\s*new\\s*\\(require\\('u'\\s*\\+\\s*'rl'\\)\\.URL\\)\\s*\\('file:'\\s*\\+\\s*__filename\\).href\\s*:\\s*\\(document\\.currentScript\\s*&&\\s*document\\.currentScript\\.src\\s*\\|\\|\\s*new URL\\('index\\.cjs',\\s*document\\.baseURI\\)\\.href\\)\\)\\.replace\\(\\/dist\\[\\\\\\\\\\\\\\/\\]index\\.cjs\\$\\/,\\s*''\\)\\)\\)/g,\n `fs.readFileSync(require.resolve('../dict/dict.txt'))`\n )\n}\n"],"file":"lmdb-bundling-patch.js"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gatsby",
|
|
3
3
|
"description": "Blazing fast modern site generator for React",
|
|
4
|
-
"version": "4.9.
|
|
4
|
+
"version": "4.9.3",
|
|
5
5
|
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
|
|
6
6
|
"bin": {
|
|
7
7
|
"gatsby": "./cli.js"
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"babel-plugin-add-module-exports": "^1.0.4",
|
|
36
36
|
"babel-plugin-dynamic-import-node": "^2.3.3",
|
|
37
37
|
"babel-plugin-lodash": "^3.3.4",
|
|
38
|
-
"babel-plugin-remove-graphql-queries": "^4.9.
|
|
39
|
-
"babel-preset-gatsby": "^2.9.
|
|
38
|
+
"babel-plugin-remove-graphql-queries": "^4.9.1",
|
|
39
|
+
"babel-preset-gatsby": "^2.9.1",
|
|
40
40
|
"better-opn": "^2.1.1",
|
|
41
41
|
"bluebird": "^3.7.2",
|
|
42
42
|
"body-parser": "^1.19.0",
|
|
@@ -79,18 +79,18 @@
|
|
|
79
79
|
"find-cache-dir": "^3.3.2",
|
|
80
80
|
"fs-exists-cached": "1.0.0",
|
|
81
81
|
"fs-extra": "^10.0.0",
|
|
82
|
-
"gatsby-cli": "^4.9.
|
|
83
|
-
"gatsby-core-utils": "^3.9.
|
|
82
|
+
"gatsby-cli": "^4.9.1",
|
|
83
|
+
"gatsby-core-utils": "^3.9.1",
|
|
84
84
|
"gatsby-graphiql-explorer": "^2.9.0",
|
|
85
85
|
"gatsby-legacy-polyfills": "^2.9.0",
|
|
86
|
-
"gatsby-link": "^4.9.
|
|
87
|
-
"gatsby-page-utils": "^2.9.
|
|
86
|
+
"gatsby-link": "^4.9.1",
|
|
87
|
+
"gatsby-page-utils": "^2.9.1",
|
|
88
88
|
"gatsby-parcel-config": "^0.0.1",
|
|
89
|
-
"gatsby-plugin-page-creator": "^4.9.
|
|
90
|
-
"gatsby-plugin-typescript": "^4.9.
|
|
89
|
+
"gatsby-plugin-page-creator": "^4.9.1",
|
|
90
|
+
"gatsby-plugin-typescript": "^4.9.1",
|
|
91
91
|
"gatsby-plugin-utils": "^3.3.0",
|
|
92
92
|
"gatsby-react-router-scroll": "^5.9.0",
|
|
93
|
-
"gatsby-telemetry": "^3.9.
|
|
93
|
+
"gatsby-telemetry": "^3.9.1",
|
|
94
94
|
"gatsby-worker": "^1.9.0",
|
|
95
95
|
"glob": "^7.2.0",
|
|
96
96
|
"got": "^11.8.2",
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
"joi": "^17.4.2",
|
|
106
106
|
"json-loader": "^0.5.7",
|
|
107
107
|
"latest-version": "5.1.0",
|
|
108
|
-
"lmdb": "2.2.
|
|
108
|
+
"lmdb": "^2.2.3",
|
|
109
109
|
"lodash": "^4.17.21",
|
|
110
110
|
"md5-file": "^5.0.0",
|
|
111
111
|
"meant": "^1.0.3",
|
|
@@ -264,5 +264,5 @@
|
|
|
264
264
|
"yargs": {
|
|
265
265
|
"boolean-negation": false
|
|
266
266
|
},
|
|
267
|
-
"gitHead": "
|
|
267
|
+
"gitHead": "59e7e0eadfea90ef844b53c0b53d098ad3d51c7a"
|
|
268
268
|
}
|