decap-cms-lib-util 3.8.2 → 3.9.0-beta.0
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/esm/backendUtil.js
CHANGED
|
@@ -91,4 +91,29 @@ export async function getAllResponses(url, options = {}, linkHeaderRelName, next
|
|
|
91
91
|
export function getPathDepth(path) {
|
|
92
92
|
const depth = path.split('/').length;
|
|
93
93
|
return depth;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Stable cache key for a files collection.
|
|
98
|
+
*
|
|
99
|
+
* decap-cms-core's `entriesByFiles` receives only the file list, never the
|
|
100
|
+
* collection name, so a backend that caches such a collection has to derive an
|
|
101
|
+
* identity from the paths themselves.
|
|
102
|
+
*
|
|
103
|
+
* Sorted before hashing so key identity does not depend on the order files
|
|
104
|
+
* happen to be listed in config.yml — reordering them must not orphan the
|
|
105
|
+
* cached rows. Hashed so a collection of many paths does not become a
|
|
106
|
+
* multi-kilobyte value repeated on every cached row.
|
|
107
|
+
*
|
|
108
|
+
* FNV-1a rather than a crypto digest: this needs to be deterministic, short and
|
|
109
|
+
* synchronous, not unforgeable. It lives here rather than in one backend
|
|
110
|
+
* because both Turbo backends need exactly the same key.
|
|
111
|
+
*/
|
|
112
|
+
export function collectionKeyForFiles(paths) {
|
|
113
|
+
let hash = 0x811c9dc5;
|
|
114
|
+
for (const char of [...paths].sort().join('\n')) {
|
|
115
|
+
hash ^= char.charCodeAt(0);
|
|
116
|
+
hash = Math.imul(hash, 0x01000193) >>> 0;
|
|
117
|
+
}
|
|
118
|
+
return `files:${paths.length}:${hash.toString(36)}`;
|
|
94
119
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import localForage from './localForage';
|
|
|
6
6
|
import { isAbsolutePath, basename, fileExtensionWithSeparator, fileExtension } from './path';
|
|
7
7
|
import { onlySuccessfulPromises, flowAsync, then } from './promise';
|
|
8
8
|
import unsentRequest from './unsentRequest';
|
|
9
|
-
import { filterByExtension, getAllResponses, parseLinkHeader, parseResponse, responseParser, getPathDepth } from './backendUtil';
|
|
9
|
+
import { filterByExtension, collectionKeyForFiles, getAllResponses, parseLinkHeader, parseResponse, responseParser, getPathDepth } from './backendUtil';
|
|
10
10
|
import loadScript from './loadScript';
|
|
11
11
|
import getBlobSHA from './getBlobSHA';
|
|
12
12
|
import { asyncLock } from './asyncLock';
|
|
@@ -29,6 +29,7 @@ export const DecapCmsLibUtil = {
|
|
|
29
29
|
then,
|
|
30
30
|
unsentRequest,
|
|
31
31
|
filterByExtension,
|
|
32
|
+
collectionKeyForFiles,
|
|
32
33
|
parseLinkHeader,
|
|
33
34
|
parseResponse,
|
|
34
35
|
responseParser,
|
|
@@ -68,4 +69,4 @@ export const DecapCmsLibUtil = {
|
|
|
68
69
|
AccessTokenError,
|
|
69
70
|
throwOnConflictingBranches
|
|
70
71
|
};
|
|
71
|
-
export { APIError, Cursor, CURSOR_COMPATIBILITY_SYMBOL, EditorialWorkflowError, EDITORIAL_WORKFLOW_ERROR, localForage, basename, fileExtensionWithSeparator, fileExtension, onlySuccessfulPromises, flowAsync, then, unsentRequest, filterByExtension, parseLinkHeader, getAllResponses, parseResponse, responseParser, loadScript, getBlobSHA, asyncLock, isAbsolutePath, getPathDepth, entriesByFiles, entriesByFolder, unpublishedEntries, getMediaDisplayURL, getMediaAsBlob, readFile, readFileMetadata, CMS_BRANCH_PREFIX, generateContentKey, isCMSLabel, labelToStatus, statusToLabel, DEFAULT_PR_BODY, MERGE_COMMIT_MESSAGE, isPreviewContext, getPreviewStatus, runWithLock, PreviewState, parseContentKey, createPointerFile, getLargeMediaFilteredMediaFiles, getLargeMediaPatternsFromGitAttributesFile, parsePointerFile, getPointerFileForMediaFileObj, branchFromContentKey, contentKeyFromBranch, blobToFileObj, requestWithBackoff, getDefaultBranchName, allEntriesByFolder, AccessTokenError, throwOnConflictingBranches };
|
|
72
|
+
export { APIError, Cursor, CURSOR_COMPATIBILITY_SYMBOL, EditorialWorkflowError, EDITORIAL_WORKFLOW_ERROR, localForage, basename, fileExtensionWithSeparator, fileExtension, onlySuccessfulPromises, flowAsync, then, unsentRequest, filterByExtension, collectionKeyForFiles, parseLinkHeader, getAllResponses, parseResponse, responseParser, loadScript, getBlobSHA, asyncLock, isAbsolutePath, getPathDepth, entriesByFiles, entriesByFolder, unpublishedEntries, getMediaDisplayURL, getMediaAsBlob, readFile, readFileMetadata, CMS_BRANCH_PREFIX, generateContentKey, isCMSLabel, labelToStatus, statusToLabel, DEFAULT_PR_BODY, MERGE_COMMIT_MESSAGE, isPreviewContext, getPreviewStatus, runWithLock, PreviewState, parseContentKey, createPointerFile, getLargeMediaFilteredMediaFiles, getLargeMediaPatternsFromGitAttributesFile, parsePointerFile, getPointerFileForMediaFileObj, branchFromContentKey, contentKeyFromBranch, blobToFileObj, requestWithBackoff, getDefaultBranchName, allEntriesByFolder, AccessTokenError, throwOnConflictingBranches };
|
package/package.json
CHANGED