netlify-cms-lib-util
Advanced tools
Comparing version
@@ -6,2 +6,10 @@ # Change Log | ||
## [2.13.1](https://github.com/netlify/netlify-cms/tree/master/packages/netlify-cms-lib-util/compare/netlify-cms-lib-util@2.13.0...netlify-cms-lib-util@2.13.1) (2021-05-19) | ||
**Note:** Version bump only for package netlify-cms-lib-util | ||
# [2.13.0](https://github.com/netlify/netlify-cms/tree/master/packages/netlify-cms-lib-util/compare/netlify-cms-lib-util@2.12.3...netlify-cms-lib-util@2.13.0) (2021-04-04) | ||
@@ -8,0 +16,0 @@ |
@@ -0,1 +1,8 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = exports.ACCESS_TOKEN_ERROR = void 0; | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
@@ -28,4 +35,6 @@ | ||
export const ACCESS_TOKEN_ERROR = 'ACCESS_TOKEN_ERROR'; | ||
export default class AccessTokenError extends _extendableBuiltin(Error) { | ||
const ACCESS_TOKEN_ERROR = 'ACCESS_TOKEN_ERROR'; | ||
exports.ACCESS_TOKEN_ERROR = ACCESS_TOKEN_ERROR; | ||
class AccessTokenError extends _extendableBuiltin(Error) { | ||
constructor(message) { | ||
@@ -40,2 +49,4 @@ super(message); | ||
} | ||
} | ||
exports.default = AccessTokenError; |
@@ -0,1 +1,22 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.requestWithBackoff = requestWithBackoff; | ||
exports.readFile = readFile; | ||
exports.readFileMetadata = readFileMetadata; | ||
exports.isPreviewContext = isPreviewContext; | ||
exports.getPreviewStatus = getPreviewStatus; | ||
exports.throwOnConflictingBranches = throwOnConflictingBranches; | ||
exports.PreviewState = void 0; | ||
var _asyncLock = require("./asyncLock"); | ||
var _unsentRequest = _interopRequireDefault(require("./unsentRequest")); | ||
var _APIError = _interopRequireDefault(require("./APIError")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
@@ -28,6 +49,2 @@ | ||
import { asyncLock } from "./asyncLock"; | ||
import unsentRequest from "./unsentRequest"; | ||
import APIError from "./APIError"; | ||
class RateLimitError extends _extendableBuiltin(Error) { | ||
@@ -50,3 +67,3 @@ constructor(message, resetSeconds) { | ||
export async function requestWithBackoff(api, req, attempt = 1) { | ||
async function requestWithBackoff(api, req, attempt = 1) { | ||
if (api.rateLimiter) { | ||
@@ -58,3 +75,3 @@ await api.rateLimiter.acquire(); | ||
const builtRequest = await api.buildRequest(req); | ||
const requestFunction = api.requestFunction || unsentRequest.performRequest; | ||
const requestFunction = api.requestFunction || _unsentRequest.default.performRequest; | ||
const response = await requestFunction(builtRequest); | ||
@@ -89,3 +106,3 @@ | ||
console.log(`Pausing requests for ${timeout} ${attempt === 1 ? 'second' : 'seconds'} due to fetch failures:`, err.message); | ||
api.rateLimiter = asyncLock(); | ||
api.rateLimiter = (0, _asyncLock.asyncLock)(); | ||
api.rateLimiter.acquire(); | ||
@@ -105,3 +122,4 @@ setTimeout(() => { | ||
} | ||
export async function readFile(id, fetchContent, localForage, isText) { | ||
async function readFile(id, fetchContent, localForage, isText) { | ||
const key = id ? isText ? `gh.${id}` : `gh.${id}.blob` : null; | ||
@@ -127,3 +145,3 @@ const cached = key ? await localForage.getItem(key) : null; | ||
export async function readFileMetadata(id, fetchMetadata, localForage) { | ||
async function readFileMetadata(id, fetchMetadata, localForage) { | ||
const key = id ? getFileMetadataKey(id) : null; | ||
@@ -148,2 +166,3 @@ const cached = key && (await localForage.getItem(key)); | ||
const PREVIEW_CONTEXT_KEYWORDS = ['deploy']; | ||
@@ -156,3 +175,3 @@ /** | ||
export function isPreviewContext(context, previewContext) { | ||
function isPreviewContext(context, previewContext) { | ||
if (previewContext) { | ||
@@ -164,3 +183,4 @@ return context === previewContext; | ||
} | ||
export let PreviewState; | ||
let PreviewState; | ||
/** | ||
@@ -171,8 +191,10 @@ * Retrieve a deploy preview URL from an array of statuses. By default, a | ||
exports.PreviewState = PreviewState; | ||
(function (PreviewState) { | ||
PreviewState["Other"] = "other"; | ||
PreviewState["Success"] = "success"; | ||
})(PreviewState || (PreviewState = {})); | ||
})(PreviewState || (exports.PreviewState = PreviewState = {})); | ||
export function getPreviewStatus(statuses, previewContext) { | ||
function getPreviewStatus(statuses, previewContext) { | ||
return statuses.find(({ | ||
@@ -196,3 +218,3 @@ context | ||
export async function throwOnConflictingBranches(branchName, getBranch, apiName) { | ||
async function throwOnConflictingBranches(branchName, getBranch, apiName) { | ||
const possibleConflictingBranches = getConflictingBranches(branchName); | ||
@@ -203,4 +225,4 @@ const conflictingBranches = await Promise.all(possibleConflictingBranches.map(b => getBranch(b).then(b => b.name).catch(() => ''))); | ||
if (conflictingBranch) { | ||
throw new APIError(`Failed creating branch '${branchName}' since there is already a branch named '${conflictingBranch}'. Please delete the '${conflictingBranch}' branch and try again`, 500, apiName); | ||
throw new _APIError.default(`Failed creating branch '${branchName}' since there is already a branch named '${conflictingBranch}'. Please delete the '${conflictingBranch}' branch and try again`, 500, apiName); | ||
} | ||
} |
@@ -0,1 +1,8 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = exports.API_ERROR = void 0; | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
@@ -28,4 +35,6 @@ | ||
export const API_ERROR = 'API_ERROR'; | ||
export default class APIError extends _extendableBuiltin(Error) { | ||
const API_ERROR = 'API_ERROR'; | ||
exports.API_ERROR = API_ERROR; | ||
class APIError extends _extendableBuiltin(Error) { | ||
constructor(message, status, api, meta = {}) { | ||
@@ -49,2 +58,4 @@ super(message); | ||
} | ||
} | ||
exports.default = APIError; |
@@ -1,4 +0,20 @@ | ||
export const CMS_BRANCH_PREFIX = 'cms'; | ||
export const DEFAULT_PR_BODY = 'Automatically generated by Netlify CMS'; | ||
export const MERGE_COMMIT_MESSAGE = 'Automatically generated. Merged on Netlify CMS.'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.isCMSLabel = isCMSLabel; | ||
exports.labelToStatus = labelToStatus; | ||
exports.statusToLabel = statusToLabel; | ||
exports.generateContentKey = generateContentKey; | ||
exports.parseContentKey = parseContentKey; | ||
exports.contentKeyFromBranch = contentKeyFromBranch; | ||
exports.branchFromContentKey = branchFromContentKey; | ||
exports.MERGE_COMMIT_MESSAGE = exports.DEFAULT_PR_BODY = exports.CMS_BRANCH_PREFIX = void 0; | ||
const CMS_BRANCH_PREFIX = 'cms'; | ||
exports.CMS_BRANCH_PREFIX = CMS_BRANCH_PREFIX; | ||
const DEFAULT_PR_BODY = 'Automatically generated by Netlify CMS'; | ||
exports.DEFAULT_PR_BODY = DEFAULT_PR_BODY; | ||
const MERGE_COMMIT_MESSAGE = 'Automatically generated. Merged on Netlify CMS.'; | ||
exports.MERGE_COMMIT_MESSAGE = MERGE_COMMIT_MESSAGE; | ||
const DEFAULT_NETLIFY_CMS_LABEL_PREFIX = 'netlify-cms/'; | ||
@@ -10,15 +26,19 @@ | ||
export function isCMSLabel(label, labelPrefix) { | ||
function isCMSLabel(label, labelPrefix) { | ||
return label.startsWith(getLabelPrefix(labelPrefix)); | ||
} | ||
export function labelToStatus(label, labelPrefix) { | ||
function labelToStatus(label, labelPrefix) { | ||
return label.substr(getLabelPrefix(labelPrefix).length); | ||
} | ||
export function statusToLabel(status, labelPrefix) { | ||
function statusToLabel(status, labelPrefix) { | ||
return `${getLabelPrefix(labelPrefix)}${status}`; | ||
} | ||
export function generateContentKey(collectionName, slug) { | ||
function generateContentKey(collectionName, slug) { | ||
return `${collectionName}/${slug}`; | ||
} | ||
export function parseContentKey(contentKey) { | ||
function parseContentKey(contentKey) { | ||
const index = contentKey.indexOf('/'); | ||
@@ -30,7 +50,9 @@ return { | ||
} | ||
export function contentKeyFromBranch(branch) { | ||
function contentKeyFromBranch(branch) { | ||
return branch.substring(`${CMS_BRANCH_PREFIX}/`.length); | ||
} | ||
export function branchFromContentKey(contentKey) { | ||
function branchFromContentKey(contentKey) { | ||
return `${CMS_BRANCH_PREFIX}/${contentKey}`; | ||
} |
@@ -1,5 +0,15 @@ | ||
import semaphore from 'semaphore'; | ||
export function asyncLock() { | ||
let lock = semaphore(1); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.asyncLock = asyncLock; | ||
var _semaphore = _interopRequireDefault(require("semaphore")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function asyncLock() { | ||
let lock = (0, _semaphore.default)(1); | ||
function acquire(timeout = 15000) { | ||
@@ -10,3 +20,3 @@ const promise = new Promise(resolve => { | ||
// we reset the lock in that case to allow future consumers to use it without being blocked | ||
lock = semaphore(1); | ||
lock = (0, _semaphore.default)(1); | ||
resolve(false); | ||
@@ -33,3 +43,3 @@ }, timeout); | ||
console.warn('leave called too many times.'); | ||
lock = semaphore(1); | ||
lock = (0, _semaphore.default)(1); | ||
} | ||
@@ -36,0 +46,0 @@ } |
@@ -1,8 +0,28 @@ | ||
import _map from "lodash/fp/map"; | ||
import _fromPairs from "lodash/fromPairs"; | ||
import _flow from "lodash/flow"; | ||
import { fromJS } from 'immutable'; | ||
import unsentRequest from "./unsentRequest"; | ||
import APIError from "./APIError"; | ||
export function filterByExtension(file, extension) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.filterByExtension = filterByExtension; | ||
exports.parseResponse = parseResponse; | ||
exports.responseParser = responseParser; | ||
exports.parseLinkHeader = parseLinkHeader; | ||
exports.getAllResponses = getAllResponses; | ||
exports.getPathDepth = getPathDepth; | ||
var _map2 = _interopRequireDefault(require("lodash/fp/map")); | ||
var _fromPairs2 = _interopRequireDefault(require("lodash/fromPairs")); | ||
var _flow2 = _interopRequireDefault(require("lodash/flow")); | ||
var _immutable = require("immutable"); | ||
var _unsentRequest = _interopRequireDefault(require("./unsentRequest")); | ||
var _APIError = _interopRequireDefault(require("./APIError")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function filterByExtension(file, extension) { | ||
const path = (file === null || file === void 0 ? void 0 : file.path) || ''; | ||
@@ -22,3 +42,3 @@ return path.endsWith(extension.startsWith('.') ? extension : `.${extension}`); | ||
const responseFormatters = fromJS({ | ||
const responseFormatters = (0, _immutable.fromJS)({ | ||
json: async res => { | ||
@@ -36,3 +56,4 @@ const contentType = res.headers.get('Content-Type') || ''; | ||
}).mapEntries(([format, formatter]) => [format, catchFormatErrors(format, formatter)]); | ||
export async function parseResponse(res, { | ||
async function parseResponse(res, { | ||
expectingOk = true, | ||
@@ -53,3 +74,3 @@ format = 'text', | ||
} catch (err) { | ||
throw new APIError(err.message, res.status, apiName); | ||
throw new _APIError.default(err.message, res.status, apiName); | ||
} | ||
@@ -62,3 +83,3 @@ | ||
const message = isJSON ? body.message || body.msg || ((_body$error = body.error) === null || _body$error === void 0 ? void 0 : _body$error.message) : body; | ||
throw new APIError(isJSON && message ? message : body, res.status, apiName); | ||
throw new _APIError.default(isJSON && message ? message : body, res.status, apiName); | ||
} | ||
@@ -68,6 +89,8 @@ | ||
} | ||
export function responseParser(options) { | ||
function responseParser(options) { | ||
return res => parseResponse(res, options); | ||
} | ||
export function parseLinkHeader(header) { | ||
function parseLinkHeader(header) { | ||
if (!header) { | ||
@@ -77,12 +100,15 @@ return {}; | ||
return _flow([linksString => linksString.split(','), _map(str => str.trim().split(';')), _map(([linkStr, keyStr]) => [keyStr.match(/rel="(.*?)"/)[1], linkStr.trim().match(/<(.*?)>/)[1].replace(/\+/g, '%20')]), _fromPairs])(header); | ||
return (0, _flow2.default)([linksString => linksString.split(','), (0, _map2.default)(str => str.trim().split(';')), (0, _map2.default)(([linkStr, keyStr]) => [keyStr.match(/rel="(.*?)"/)[1], linkStr.trim().match(/<(.*?)>/)[1].replace(/\+/g, '%20')]), _fromPairs2.default])(header); | ||
} | ||
export async function getAllResponses(url, options = {}, linkHeaderRelName, nextUrlProcessor) { | ||
async function getAllResponses(url, options = {}, linkHeaderRelName, nextUrlProcessor) { | ||
const maxResponses = 30; | ||
let responseCount = 1; | ||
let req = unsentRequest.fromFetchArguments(url, options); | ||
let req = _unsentRequest.default.fromFetchArguments(url, options); | ||
const pageResponses = []; | ||
while (req && responseCount < maxResponses) { | ||
const pageResponse = await unsentRequest.performRequest(req); | ||
const pageResponse = await _unsentRequest.default.performRequest(req); | ||
const linkHeader = pageResponse.headers.get('Link'); | ||
@@ -93,3 +119,3 @@ const nextURL = linkHeader && parseLinkHeader(linkHeader)[linkHeaderRelName]; | ||
} = options; | ||
req = nextURL && unsentRequest.fromFetchArguments(nextUrlProcessor(nextURL), { | ||
req = nextURL && _unsentRequest.default.fromFetchArguments(nextUrlProcessor(nextURL), { | ||
headers | ||
@@ -103,5 +129,6 @@ }); | ||
} | ||
export function getPathDepth(path) { | ||
function getPathDepth(path) { | ||
const depth = path.split('/').length; | ||
return depth; | ||
} |
@@ -0,13 +1,20 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.CURSOR_COMPATIBILITY_SYMBOL = exports.default = void 0; | ||
var _immutable = require("immutable"); | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
import { fromJS, Map, Set } from 'immutable'; | ||
function jsToMap(obj) { | ||
if (obj === undefined) { | ||
return Map(); | ||
return (0, _immutable.Map)(); | ||
} | ||
const immutableObj = fromJS(obj); | ||
const immutableObj = (0, _immutable.fromJS)(obj); | ||
if (!Map.isMap(immutableObj)) { | ||
if (!_immutable.Map.isMap(immutableObj)) { | ||
throw new Error('Object must be equivalent to a Map.'); | ||
@@ -19,3 +26,3 @@ } | ||
const knownMetaKeys = Set(['index', 'page', 'count', 'pageSize', 'pageCount', 'usingOldPaginationAPI', 'extension', 'folder', 'depth']); | ||
const knownMetaKeys = (0, _immutable.Set)(['index', 'page', 'count', 'pageSize', 'pageCount', 'usingOldPaginationAPI', 'extension', 'folder', 'depth']); | ||
@@ -43,5 +50,5 @@ function filterUnknownMetaKeys(meta) { | ||
}; | ||
return Map({ | ||
return (0, _immutable.Map)({ | ||
// actions are a Set, rather than a List, to ensure an efficient .has | ||
actions: Set(actions), | ||
actions: (0, _immutable.Set)(actions), | ||
// data and meta are Maps | ||
@@ -58,3 +65,3 @@ data: jsToMap(data), | ||
function getActionHandlers(store, handler) { | ||
return store.get('actions', Set()).toMap().map(action => handler(action)); | ||
return store.get('actions', (0, _immutable.Set)()).toMap().map(action => handler(action)); | ||
} // The cursor logic is entirely functional, so this class simply | ||
@@ -64,3 +71,3 @@ // provides a chainable interface | ||
export default class Cursor { | ||
class Cursor { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
@@ -114,3 +121,3 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
setActions(actions) { | ||
return this.updateStore(store => store.set('actions', Set(actions))); | ||
return this.updateStore(store => store.set('actions', (0, _immutable.Set)(actions))); | ||
} | ||
@@ -143,3 +150,3 @@ | ||
clearData() { | ||
return this.updateStore('data', () => Map()); | ||
return this.updateStore('data', () => (0, _immutable.Map)()); | ||
} | ||
@@ -161,2 +168,5 @@ | ||
export const CURSOR_COMPATIBILITY_SYMBOL = Symbol('cursor key for compatibility with old backends'); | ||
exports.default = Cursor; | ||
const CURSOR_COMPATIBILITY_SYMBOL = Symbol('cursor key for compatibility with old backends'); | ||
exports.CURSOR_COMPATIBILITY_SYMBOL = CURSOR_COMPATIBILITY_SYMBOL; |
@@ -0,1 +1,8 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = exports.EDITORIAL_WORKFLOW_ERROR = void 0; | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
@@ -28,4 +35,6 @@ | ||
export const EDITORIAL_WORKFLOW_ERROR = 'EDITORIAL_WORKFLOW_ERROR'; | ||
export default class EditorialWorkflowError extends _extendableBuiltin(Error) { | ||
const EDITORIAL_WORKFLOW_ERROR = 'EDITORIAL_WORKFLOW_ERROR'; | ||
exports.EDITORIAL_WORKFLOW_ERROR = EDITORIAL_WORKFLOW_ERROR; | ||
class EditorialWorkflowError extends _extendableBuiltin(Error) { | ||
constructor(message, notUnderEditorialWorkflow) { | ||
@@ -43,2 +52,4 @@ super(message); | ||
} | ||
} | ||
exports.default = EditorialWorkflowError; |
@@ -1,3 +0,11 @@ | ||
import { sha256 } from 'js-sha256'; | ||
export default (blob => new Promise((resolve, reject) => { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _jsSha = require("js-sha256"); | ||
var _default = blob => new Promise((resolve, reject) => { | ||
const fr = new FileReader(); | ||
@@ -7,3 +15,3 @@ | ||
target | ||
}) => resolve(sha256((target === null || target === void 0 ? void 0 : target.result) || '')); | ||
}) => resolve((0, _jsSha.sha256)((target === null || target === void 0 ? void 0 : target.result) || '')); | ||
@@ -16,2 +24,4 @@ fr.onerror = err => { | ||
fr.readAsArrayBuffer(blob); | ||
})); | ||
}); | ||
exports.default = _default; |
@@ -1,8 +0,25 @@ | ||
import _map from "lodash/fp/map"; | ||
import _fromPairs from "lodash/fp/fromPairs"; | ||
import _flow from "lodash/fp/flow"; | ||
import _filter from "lodash/fp/filter"; | ||
"use strict"; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.createPointerFile = createPointerFile; | ||
exports.getPointerFileForMediaFileObj = getPointerFileForMediaFileObj; | ||
exports.getLargeMediaFilteredMediaFiles = getLargeMediaFilteredMediaFiles; | ||
exports.getLargeMediaPatternsFromGitAttributesFile = exports.parsePointerFile = void 0; | ||
var _map2 = _interopRequireDefault(require("lodash/fp/map")); | ||
var _fromPairs2 = _interopRequireDefault(require("lodash/fp/fromPairs")); | ||
var _flow2 = _interopRequireDefault(require("lodash/fp/flow")); | ||
var _filter2 = _interopRequireDefault(require("lodash/fp/filter")); | ||
var _getBlobSHA = _interopRequireDefault(require("./getBlobSHA")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
@@ -16,4 +33,2 @@ | ||
import getBlobSHA from "./getBlobSHA"; | ||
function splitIntoLines(str) { | ||
@@ -31,5 +46,4 @@ return str.split('\n'); | ||
const withoutEmptyLines = _flow([_map(str => str.trim()), _filter(isNonEmptyString)]); | ||
export const parsePointerFile = _flow([splitIntoLines, withoutEmptyLines, _map(splitIntoWords), _fromPairs, (_ref) => { | ||
const withoutEmptyLines = (0, _flow2.default)([(0, _map2.default)(str => str.trim()), (0, _filter2.default)(isNonEmptyString)]); | ||
const parsePointerFile = (0, _flow2.default)([splitIntoLines, withoutEmptyLines, (0, _map2.default)(splitIntoWords), _fromPairs2.default, _ref => { | ||
let { | ||
@@ -48,2 +62,4 @@ size, | ||
exports.parsePointerFile = parsePointerFile; | ||
function removeGitAttributesCommentsFromLine(line) { | ||
@@ -70,10 +86,9 @@ return line.split('#')[0]; | ||
const parseGitPatternAttributes = _flow([_map(parseGitPatternAttribute), _fromPairs]); | ||
const parseGitPatternAttributes = (0, _flow2.default)([(0, _map2.default)(parseGitPatternAttribute), _fromPairs2.default]); | ||
const parseGitAttributesPatternLine = (0, _flow2.default)([splitIntoWords, ([pattern, ...attributes]) => [pattern, parseGitPatternAttributes(attributes)]]); | ||
const parseGitAttributesFileToPatternAttributePairs = (0, _flow2.default)([splitIntoLines, (0, _map2.default)(removeGitAttributesCommentsFromLine), withoutEmptyLines, (0, _map2.default)(parseGitAttributesPatternLine)]); | ||
const getLargeMediaPatternsFromGitAttributesFile = (0, _flow2.default)([parseGitAttributesFileToPatternAttributePairs, (0, _filter2.default)(([, attributes]) => attributes.filter === 'lfs' && attributes.diff === 'lfs' && attributes.merge === 'lfs'), (0, _map2.default)(([pattern]) => pattern)]); | ||
exports.getLargeMediaPatternsFromGitAttributesFile = getLargeMediaPatternsFromGitAttributesFile; | ||
const parseGitAttributesPatternLine = _flow([splitIntoWords, ([pattern, ...attributes]) => [pattern, parseGitPatternAttributes(attributes)]]); | ||
const parseGitAttributesFileToPatternAttributePairs = _flow([splitIntoLines, _map(removeGitAttributesCommentsFromLine), withoutEmptyLines, _map(parseGitAttributesPatternLine)]); | ||
export const getLargeMediaPatternsFromGitAttributesFile = _flow([parseGitAttributesFileToPatternAttributePairs, _filter(([, attributes]) => attributes.filter === 'lfs' && attributes.diff === 'lfs' && attributes.merge === 'lfs'), _map(([pattern]) => pattern)]); | ||
export function createPointerFile({ | ||
function createPointerFile({ | ||
size, | ||
@@ -88,3 +103,4 @@ sha | ||
} | ||
export async function getPointerFileForMediaFileObj(client, fileObj, path) { | ||
async function getPointerFileForMediaFileObj(client, fileObj, path) { | ||
const { | ||
@@ -94,3 +110,3 @@ name, | ||
} = fileObj; | ||
const sha = await getBlobSHA(fileObj); | ||
const sha = await (0, _getBlobSHA.default)(fileObj); | ||
await client.uploadResource({ | ||
@@ -108,3 +124,3 @@ sha, | ||
}); | ||
const pointerFileSHA = await getBlobSHA(pointerFile); | ||
const pointerFileSHA = await (0, _getBlobSHA.default)(pointerFile); | ||
return { | ||
@@ -118,3 +134,4 @@ fileObj: pointerFile, | ||
} | ||
export async function getLargeMediaFilteredMediaFiles(client, mediaFiles) { | ||
async function getLargeMediaFilteredMediaFiles(client, mediaFiles) { | ||
return await Promise.all(mediaFiles.map(async mediaFile => { | ||
@@ -121,0 +138,0 @@ const { |
@@ -1,6 +0,29 @@ | ||
import _sortBy from "lodash/sortBy"; | ||
import _unionBy from "lodash/unionBy"; | ||
"use strict"; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.entriesByFolder = entriesByFolder; | ||
exports.entriesByFiles = entriesByFiles; | ||
exports.unpublishedEntries = unpublishedEntries; | ||
exports.blobToFileObj = blobToFileObj; | ||
exports.getMediaAsBlob = getMediaAsBlob; | ||
exports.getMediaDisplayURL = getMediaDisplayURL; | ||
exports.runWithLock = runWithLock; | ||
exports.persistLocalTree = persistLocalTree; | ||
exports.getLocalTree = getLocalTree; | ||
exports.allEntriesByFolder = allEntriesByFolder; | ||
var _sortBy2 = _interopRequireDefault(require("lodash/sortBy")); | ||
var _unionBy2 = _interopRequireDefault(require("lodash/unionBy")); | ||
var _semaphore = _interopRequireDefault(require("semaphore")); | ||
var _path = require("./path"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
@@ -10,8 +33,6 @@ | ||
import semaphore from 'semaphore'; | ||
import { basename } from "./path"; | ||
const MAX_CONCURRENT_DOWNLOADS = 10; | ||
async function fetchFiles(files, readFile, readFileMetadata, apiName) { | ||
const sem = semaphore(MAX_CONCURRENT_DOWNLOADS); | ||
const sem = (0, _semaphore.default)(MAX_CONCURRENT_DOWNLOADS); | ||
const promises = []; | ||
@@ -41,10 +62,12 @@ files.forEach(file => { | ||
export async function entriesByFolder(listFiles, readFile, readFileMetadata, apiName) { | ||
async function entriesByFolder(listFiles, readFile, readFileMetadata, apiName) { | ||
const files = await listFiles(); | ||
return fetchFiles(files, readFile, readFileMetadata, apiName); | ||
} | ||
export async function entriesByFiles(files, readFile, readFileMetadata, apiName) { | ||
async function entriesByFiles(files, readFile, readFileMetadata, apiName) { | ||
return fetchFiles(files, readFile, readFileMetadata, apiName); | ||
} | ||
export async function unpublishedEntries(listEntriesKeys) { | ||
async function unpublishedEntries(listEntriesKeys) { | ||
try { | ||
@@ -61,3 +84,4 @@ const keys = await listEntriesKeys(); | ||
} | ||
export function blobToFileObj(name, blob) { | ||
function blobToFileObj(name, blob) { | ||
const options = name.match(/.svg$/) ? { | ||
@@ -68,3 +92,4 @@ type: 'image/svg+xml' | ||
} | ||
export async function getMediaAsBlob(path, id, readFile) { | ||
async function getMediaAsBlob(path, id, readFile) { | ||
let blob; | ||
@@ -87,3 +112,4 @@ | ||
} | ||
export async function getMediaDisplayURL(displayURL, readFile, semaphore) { | ||
async function getMediaDisplayURL(displayURL, readFile, semaphore) { | ||
const { | ||
@@ -95,3 +121,4 @@ path, | ||
} | ||
export async function runWithLock(lock, func, message) { | ||
async function runWithLock(lock, func, message) { | ||
try { | ||
@@ -110,2 +137,3 @@ const acquired = await lock.acquire(); | ||
} | ||
const LOCAL_KEY = 'git.local'; | ||
@@ -122,3 +150,3 @@ | ||
export async function persistLocalTree({ | ||
async function persistLocalTree({ | ||
localForage, | ||
@@ -138,3 +166,4 @@ localTree, | ||
} | ||
export async function getLocalTree({ | ||
async function getLocalTree({ | ||
localForage, | ||
@@ -172,3 +201,3 @@ branch, | ||
path: d.oldPath, | ||
name: basename(d.oldPath), | ||
name: (0, _path.basename)(d.oldPath), | ||
deleted: true | ||
@@ -178,3 +207,3 @@ }); | ||
path: d.newPath, | ||
name: basename(d.newPath), | ||
name: (0, _path.basename)(d.newPath), | ||
deleted: false | ||
@@ -185,3 +214,3 @@ }); | ||
path: d.oldPath, | ||
name: basename(d.oldPath), | ||
name: (0, _path.basename)(d.oldPath), | ||
deleted: true | ||
@@ -192,3 +221,3 @@ }); | ||
path: d.newPath || d.oldPath, | ||
name: basename(d.newPath || d.oldPath), | ||
name: (0, _path.basename)(d.newPath || d.oldPath), | ||
deleted: false | ||
@@ -215,3 +244,3 @@ }); | ||
export async function allEntriesByFolder({ | ||
async function allEntriesByFolder({ | ||
listAllFiles, | ||
@@ -242,3 +271,3 @@ readFile, | ||
path: f.path, | ||
name: basename(f.path) | ||
name: (0, _path.basename)(f.path) | ||
})) | ||
@@ -300,5 +329,3 @@ }, | ||
}, {}); | ||
const newCopy = _sortBy(_unionBy(diff.filter(d => !deleted[d.path]), localTree.files.filter(f => !deleted[f.path]), file => file.path), file => file.path); | ||
const newCopy = (0, _sortBy2.default)((0, _unionBy2.default)(diff.filter(d => !deleted[d.path]), localTree.files.filter(f => !deleted[f.path]), file => file.path), file => file.path); | ||
await persistLocalTree({ | ||
@@ -305,0 +332,0 @@ localForage, |
@@ -1,70 +0,423 @@ | ||
import APIError from "./APIError"; | ||
import Cursor, { CURSOR_COMPATIBILITY_SYMBOL } from "./Cursor"; | ||
import EditorialWorkflowError, { EDITORIAL_WORKFLOW_ERROR } from "./EditorialWorkflowError"; | ||
import AccessTokenError from "./AccessTokenError"; | ||
import localForage from "./localForage"; | ||
import { isAbsolutePath, basename, fileExtensionWithSeparator, fileExtension } from "./path"; | ||
import { onlySuccessfulPromises, flowAsync, then } from "./promise"; | ||
import unsentRequest from "./unsentRequest"; | ||
import { filterByExtension, getAllResponses, parseLinkHeader, parseResponse, responseParser, getPathDepth } from "./backendUtil"; | ||
import loadScript from "./loadScript"; | ||
import getBlobSHA from "./getBlobSHA"; | ||
import { asyncLock } from "./asyncLock"; | ||
import { entriesByFiles, entriesByFolder, unpublishedEntries, getMediaDisplayURL, getMediaAsBlob, runWithLock, blobToFileObj, allEntriesByFolder } from "./implementation"; | ||
import { readFile, readFileMetadata, isPreviewContext, getPreviewStatus, PreviewState, requestWithBackoff, throwOnConflictingBranches } from "./API"; | ||
import { CMS_BRANCH_PREFIX, generateContentKey, isCMSLabel, labelToStatus, statusToLabel, DEFAULT_PR_BODY, MERGE_COMMIT_MESSAGE, parseContentKey, branchFromContentKey, contentKeyFromBranch } from "./APIUtils"; | ||
import { createPointerFile, getLargeMediaFilteredMediaFiles, getLargeMediaPatternsFromGitAttributesFile, parsePointerFile, getPointerFileForMediaFileObj } from "./git-lfs"; | ||
export const NetlifyCmsLibUtil = { | ||
APIError, | ||
Cursor, | ||
CURSOR_COMPATIBILITY_SYMBOL, | ||
EditorialWorkflowError, | ||
EDITORIAL_WORKFLOW_ERROR, | ||
localForage, | ||
basename, | ||
fileExtensionWithSeparator, | ||
fileExtension, | ||
onlySuccessfulPromises, | ||
flowAsync, | ||
then, | ||
unsentRequest, | ||
filterByExtension, | ||
parseLinkHeader, | ||
parseResponse, | ||
responseParser, | ||
loadScript, | ||
getBlobSHA, | ||
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, | ||
allEntriesByFolder, | ||
AccessTokenError, | ||
throwOnConflictingBranches | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "APIError", { | ||
enumerable: true, | ||
get: function () { | ||
return _APIError.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "Cursor", { | ||
enumerable: true, | ||
get: function () { | ||
return _Cursor.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "CURSOR_COMPATIBILITY_SYMBOL", { | ||
enumerable: true, | ||
get: function () { | ||
return _Cursor.CURSOR_COMPATIBILITY_SYMBOL; | ||
} | ||
}); | ||
Object.defineProperty(exports, "EditorialWorkflowError", { | ||
enumerable: true, | ||
get: function () { | ||
return _EditorialWorkflowError.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "EDITORIAL_WORKFLOW_ERROR", { | ||
enumerable: true, | ||
get: function () { | ||
return _EditorialWorkflowError.EDITORIAL_WORKFLOW_ERROR; | ||
} | ||
}); | ||
Object.defineProperty(exports, "AccessTokenError", { | ||
enumerable: true, | ||
get: function () { | ||
return _AccessTokenError.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "localForage", { | ||
enumerable: true, | ||
get: function () { | ||
return _localForage.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "isAbsolutePath", { | ||
enumerable: true, | ||
get: function () { | ||
return _path.isAbsolutePath; | ||
} | ||
}); | ||
Object.defineProperty(exports, "basename", { | ||
enumerable: true, | ||
get: function () { | ||
return _path.basename; | ||
} | ||
}); | ||
Object.defineProperty(exports, "fileExtensionWithSeparator", { | ||
enumerable: true, | ||
get: function () { | ||
return _path.fileExtensionWithSeparator; | ||
} | ||
}); | ||
Object.defineProperty(exports, "fileExtension", { | ||
enumerable: true, | ||
get: function () { | ||
return _path.fileExtension; | ||
} | ||
}); | ||
Object.defineProperty(exports, "onlySuccessfulPromises", { | ||
enumerable: true, | ||
get: function () { | ||
return _promise.onlySuccessfulPromises; | ||
} | ||
}); | ||
Object.defineProperty(exports, "flowAsync", { | ||
enumerable: true, | ||
get: function () { | ||
return _promise.flowAsync; | ||
} | ||
}); | ||
Object.defineProperty(exports, "then", { | ||
enumerable: true, | ||
get: function () { | ||
return _promise.then; | ||
} | ||
}); | ||
Object.defineProperty(exports, "unsentRequest", { | ||
enumerable: true, | ||
get: function () { | ||
return _unsentRequest.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "filterByExtension", { | ||
enumerable: true, | ||
get: function () { | ||
return _backendUtil.filterByExtension; | ||
} | ||
}); | ||
Object.defineProperty(exports, "getAllResponses", { | ||
enumerable: true, | ||
get: function () { | ||
return _backendUtil.getAllResponses; | ||
} | ||
}); | ||
Object.defineProperty(exports, "parseLinkHeader", { | ||
enumerable: true, | ||
get: function () { | ||
return _backendUtil.parseLinkHeader; | ||
} | ||
}); | ||
Object.defineProperty(exports, "parseResponse", { | ||
enumerable: true, | ||
get: function () { | ||
return _backendUtil.parseResponse; | ||
} | ||
}); | ||
Object.defineProperty(exports, "responseParser", { | ||
enumerable: true, | ||
get: function () { | ||
return _backendUtil.responseParser; | ||
} | ||
}); | ||
Object.defineProperty(exports, "getPathDepth", { | ||
enumerable: true, | ||
get: function () { | ||
return _backendUtil.getPathDepth; | ||
} | ||
}); | ||
Object.defineProperty(exports, "loadScript", { | ||
enumerable: true, | ||
get: function () { | ||
return _loadScript.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "getBlobSHA", { | ||
enumerable: true, | ||
get: function () { | ||
return _getBlobSHA.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "asyncLock", { | ||
enumerable: true, | ||
get: function () { | ||
return _asyncLock.asyncLock; | ||
} | ||
}); | ||
Object.defineProperty(exports, "entriesByFiles", { | ||
enumerable: true, | ||
get: function () { | ||
return _implementation.entriesByFiles; | ||
} | ||
}); | ||
Object.defineProperty(exports, "entriesByFolder", { | ||
enumerable: true, | ||
get: function () { | ||
return _implementation.entriesByFolder; | ||
} | ||
}); | ||
Object.defineProperty(exports, "unpublishedEntries", { | ||
enumerable: true, | ||
get: function () { | ||
return _implementation.unpublishedEntries; | ||
} | ||
}); | ||
Object.defineProperty(exports, "getMediaDisplayURL", { | ||
enumerable: true, | ||
get: function () { | ||
return _implementation.getMediaDisplayURL; | ||
} | ||
}); | ||
Object.defineProperty(exports, "getMediaAsBlob", { | ||
enumerable: true, | ||
get: function () { | ||
return _implementation.getMediaAsBlob; | ||
} | ||
}); | ||
Object.defineProperty(exports, "runWithLock", { | ||
enumerable: true, | ||
get: function () { | ||
return _implementation.runWithLock; | ||
} | ||
}); | ||
Object.defineProperty(exports, "blobToFileObj", { | ||
enumerable: true, | ||
get: function () { | ||
return _implementation.blobToFileObj; | ||
} | ||
}); | ||
Object.defineProperty(exports, "allEntriesByFolder", { | ||
enumerable: true, | ||
get: function () { | ||
return _implementation.allEntriesByFolder; | ||
} | ||
}); | ||
Object.defineProperty(exports, "readFile", { | ||
enumerable: true, | ||
get: function () { | ||
return _API.readFile; | ||
} | ||
}); | ||
Object.defineProperty(exports, "readFileMetadata", { | ||
enumerable: true, | ||
get: function () { | ||
return _API.readFileMetadata; | ||
} | ||
}); | ||
Object.defineProperty(exports, "isPreviewContext", { | ||
enumerable: true, | ||
get: function () { | ||
return _API.isPreviewContext; | ||
} | ||
}); | ||
Object.defineProperty(exports, "getPreviewStatus", { | ||
enumerable: true, | ||
get: function () { | ||
return _API.getPreviewStatus; | ||
} | ||
}); | ||
Object.defineProperty(exports, "PreviewState", { | ||
enumerable: true, | ||
get: function () { | ||
return _API.PreviewState; | ||
} | ||
}); | ||
Object.defineProperty(exports, "requestWithBackoff", { | ||
enumerable: true, | ||
get: function () { | ||
return _API.requestWithBackoff; | ||
} | ||
}); | ||
Object.defineProperty(exports, "throwOnConflictingBranches", { | ||
enumerable: true, | ||
get: function () { | ||
return _API.throwOnConflictingBranches; | ||
} | ||
}); | ||
Object.defineProperty(exports, "CMS_BRANCH_PREFIX", { | ||
enumerable: true, | ||
get: function () { | ||
return _APIUtils.CMS_BRANCH_PREFIX; | ||
} | ||
}); | ||
Object.defineProperty(exports, "generateContentKey", { | ||
enumerable: true, | ||
get: function () { | ||
return _APIUtils.generateContentKey; | ||
} | ||
}); | ||
Object.defineProperty(exports, "isCMSLabel", { | ||
enumerable: true, | ||
get: function () { | ||
return _APIUtils.isCMSLabel; | ||
} | ||
}); | ||
Object.defineProperty(exports, "labelToStatus", { | ||
enumerable: true, | ||
get: function () { | ||
return _APIUtils.labelToStatus; | ||
} | ||
}); | ||
Object.defineProperty(exports, "statusToLabel", { | ||
enumerable: true, | ||
get: function () { | ||
return _APIUtils.statusToLabel; | ||
} | ||
}); | ||
Object.defineProperty(exports, "DEFAULT_PR_BODY", { | ||
enumerable: true, | ||
get: function () { | ||
return _APIUtils.DEFAULT_PR_BODY; | ||
} | ||
}); | ||
Object.defineProperty(exports, "MERGE_COMMIT_MESSAGE", { | ||
enumerable: true, | ||
get: function () { | ||
return _APIUtils.MERGE_COMMIT_MESSAGE; | ||
} | ||
}); | ||
Object.defineProperty(exports, "parseContentKey", { | ||
enumerable: true, | ||
get: function () { | ||
return _APIUtils.parseContentKey; | ||
} | ||
}); | ||
Object.defineProperty(exports, "branchFromContentKey", { | ||
enumerable: true, | ||
get: function () { | ||
return _APIUtils.branchFromContentKey; | ||
} | ||
}); | ||
Object.defineProperty(exports, "contentKeyFromBranch", { | ||
enumerable: true, | ||
get: function () { | ||
return _APIUtils.contentKeyFromBranch; | ||
} | ||
}); | ||
Object.defineProperty(exports, "createPointerFile", { | ||
enumerable: true, | ||
get: function () { | ||
return _gitLfs.createPointerFile; | ||
} | ||
}); | ||
Object.defineProperty(exports, "getLargeMediaFilteredMediaFiles", { | ||
enumerable: true, | ||
get: function () { | ||
return _gitLfs.getLargeMediaFilteredMediaFiles; | ||
} | ||
}); | ||
Object.defineProperty(exports, "getLargeMediaPatternsFromGitAttributesFile", { | ||
enumerable: true, | ||
get: function () { | ||
return _gitLfs.getLargeMediaPatternsFromGitAttributesFile; | ||
} | ||
}); | ||
Object.defineProperty(exports, "parsePointerFile", { | ||
enumerable: true, | ||
get: function () { | ||
return _gitLfs.parsePointerFile; | ||
} | ||
}); | ||
Object.defineProperty(exports, "getPointerFileForMediaFileObj", { | ||
enumerable: true, | ||
get: function () { | ||
return _gitLfs.getPointerFileForMediaFileObj; | ||
} | ||
}); | ||
exports.NetlifyCmsLibUtil = void 0; | ||
var _APIError = _interopRequireDefault(require("./APIError")); | ||
var _Cursor = _interopRequireWildcard(require("./Cursor")); | ||
var _EditorialWorkflowError = _interopRequireWildcard(require("./EditorialWorkflowError")); | ||
var _AccessTokenError = _interopRequireDefault(require("./AccessTokenError")); | ||
var _localForage = _interopRequireDefault(require("./localForage")); | ||
var _path = require("./path"); | ||
var _promise = require("./promise"); | ||
var _unsentRequest = _interopRequireDefault(require("./unsentRequest")); | ||
var _backendUtil = require("./backendUtil"); | ||
var _loadScript = _interopRequireDefault(require("./loadScript")); | ||
var _getBlobSHA = _interopRequireDefault(require("./getBlobSHA")); | ||
var _asyncLock = require("./asyncLock"); | ||
var _implementation = require("./implementation"); | ||
var _API = require("./API"); | ||
var _APIUtils = require("./APIUtils"); | ||
var _gitLfs = require("./git-lfs"); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const NetlifyCmsLibUtil = { | ||
APIError: _APIError.default, | ||
Cursor: _Cursor.default, | ||
CURSOR_COMPATIBILITY_SYMBOL: _Cursor.CURSOR_COMPATIBILITY_SYMBOL, | ||
EditorialWorkflowError: _EditorialWorkflowError.default, | ||
EDITORIAL_WORKFLOW_ERROR: _EditorialWorkflowError.EDITORIAL_WORKFLOW_ERROR, | ||
localForage: _localForage.default, | ||
basename: _path.basename, | ||
fileExtensionWithSeparator: _path.fileExtensionWithSeparator, | ||
fileExtension: _path.fileExtension, | ||
onlySuccessfulPromises: _promise.onlySuccessfulPromises, | ||
flowAsync: _promise.flowAsync, | ||
then: _promise.then, | ||
unsentRequest: _unsentRequest.default, | ||
filterByExtension: _backendUtil.filterByExtension, | ||
parseLinkHeader: _backendUtil.parseLinkHeader, | ||
parseResponse: _backendUtil.parseResponse, | ||
responseParser: _backendUtil.responseParser, | ||
loadScript: _loadScript.default, | ||
getBlobSHA: _getBlobSHA.default, | ||
getPathDepth: _backendUtil.getPathDepth, | ||
entriesByFiles: _implementation.entriesByFiles, | ||
entriesByFolder: _implementation.entriesByFolder, | ||
unpublishedEntries: _implementation.unpublishedEntries, | ||
getMediaDisplayURL: _implementation.getMediaDisplayURL, | ||
getMediaAsBlob: _implementation.getMediaAsBlob, | ||
readFile: _API.readFile, | ||
readFileMetadata: _API.readFileMetadata, | ||
CMS_BRANCH_PREFIX: _APIUtils.CMS_BRANCH_PREFIX, | ||
generateContentKey: _APIUtils.generateContentKey, | ||
isCMSLabel: _APIUtils.isCMSLabel, | ||
labelToStatus: _APIUtils.labelToStatus, | ||
statusToLabel: _APIUtils.statusToLabel, | ||
DEFAULT_PR_BODY: _APIUtils.DEFAULT_PR_BODY, | ||
MERGE_COMMIT_MESSAGE: _APIUtils.MERGE_COMMIT_MESSAGE, | ||
isPreviewContext: _API.isPreviewContext, | ||
getPreviewStatus: _API.getPreviewStatus, | ||
runWithLock: _implementation.runWithLock, | ||
PreviewState: _API.PreviewState, | ||
parseContentKey: _APIUtils.parseContentKey, | ||
createPointerFile: _gitLfs.createPointerFile, | ||
getLargeMediaFilteredMediaFiles: _gitLfs.getLargeMediaFilteredMediaFiles, | ||
getLargeMediaPatternsFromGitAttributesFile: _gitLfs.getLargeMediaPatternsFromGitAttributesFile, | ||
parsePointerFile: _gitLfs.parsePointerFile, | ||
getPointerFileForMediaFileObj: _gitLfs.getPointerFileForMediaFileObj, | ||
branchFromContentKey: _APIUtils.branchFromContentKey, | ||
contentKeyFromBranch: _APIUtils.contentKeyFromBranch, | ||
blobToFileObj: _implementation.blobToFileObj, | ||
requestWithBackoff: _API.requestWithBackoff, | ||
allEntriesByFolder: _implementation.allEntriesByFolder, | ||
AccessTokenError: _AccessTokenError.default, | ||
throwOnConflictingBranches: _API.throwOnConflictingBranches | ||
}; | ||
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, allEntriesByFolder, AccessTokenError, throwOnConflictingBranches }; | ||
exports.NetlifyCmsLibUtil = NetlifyCmsLibUtil; |
@@ -0,5 +1,12 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = loadScript; | ||
/** | ||
* Simple script loader that returns a promise. | ||
*/ | ||
export default function loadScript(url) { | ||
function loadScript(url) { | ||
return new Promise((resolve, reject) => { | ||
@@ -6,0 +13,0 @@ let done = false; |
@@ -1,9 +0,19 @@ | ||
import localForage from "localforage"; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _localforage = _interopRequireDefault(require("localforage")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function localForageTest() { | ||
const testKey = 'localForageTest'; | ||
localForage.setItem(testKey, { | ||
_localforage.default.setItem(testKey, { | ||
expires: Date.now() + 300000 | ||
}).then(() => { | ||
localForage.removeItem(testKey); | ||
_localforage.default.removeItem(testKey); | ||
}).catch(err => { | ||
@@ -20,2 +30,3 @@ if (err.code === 22) { | ||
localForageTest(); | ||
export default localForage; | ||
var _default = _localforage.default; | ||
exports.default = _default; |
@@ -0,1 +1,10 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.isAbsolutePath = isAbsolutePath; | ||
exports.basename = basename; | ||
exports.fileExtensionWithSeparator = fileExtensionWithSeparator; | ||
exports.fileExtension = fileExtension; | ||
const absolutePath = new RegExp('^(?:[a-z]+:)?//', 'i'); | ||
@@ -7,3 +16,3 @@ | ||
export function isAbsolutePath(path) { | ||
function isAbsolutePath(path) { | ||
return absolutePath.test(path); | ||
@@ -23,3 +32,4 @@ } | ||
export function basename(p, ext = '') { | ||
function basename(p, ext = '') { | ||
// Special case: Normalize will modify this to '.' | ||
@@ -62,3 +72,4 @@ if (p === '') { | ||
export function fileExtensionWithSeparator(p) { | ||
function fileExtensionWithSeparator(p) { | ||
p = normalizePath(p); | ||
@@ -94,5 +105,6 @@ const sections = p.split('/'); | ||
export function fileExtension(p) { | ||
function fileExtension(p) { | ||
const ext = fileExtensionWithSeparator(p); | ||
return ext === '' ? ext : ext.substr(1); | ||
} |
@@ -1,7 +0,21 @@ | ||
import flow from 'lodash/flow'; | ||
export function then(fn) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.then = then; | ||
exports.onlySuccessfulPromises = onlySuccessfulPromises; | ||
exports.flowAsync = flowAsync; | ||
var _flow = _interopRequireDefault(require("lodash/flow")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function then(fn) { | ||
return p => Promise.resolve(p).then(fn); | ||
} | ||
const filterPromiseSymbol = Symbol('filterPromiseSymbol'); | ||
export function onlySuccessfulPromises(promises) { | ||
function onlySuccessfulPromises(promises) { | ||
return Promise.all(promises.map(p => p.catch(() => filterPromiseSymbol))).then(results => results.filter(result => result !== filterPromiseSymbol)); | ||
@@ -14,4 +28,4 @@ } | ||
export function flowAsync(fns) { | ||
return flow(fns.map(fn => wrapFlowAsync(fn))); | ||
function flowAsync(fns) { | ||
return (0, _flow.default)(fns.map(fn => wrapFlowAsync(fn))); | ||
} |
@@ -1,3 +0,20 @@ | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _immutable = require("immutable"); | ||
var _curry = _interopRequireDefault(require("lodash/curry")); | ||
var _flow = _interopRequireDefault(require("lodash/flow")); | ||
var _isString = _interopRequireDefault(require("lodash/isString")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
@@ -7,7 +24,2 @@ | ||
import { fromJS, List, Map } from 'immutable'; | ||
import curry from 'lodash/curry'; | ||
import flow from 'lodash/flow'; | ||
import isString from 'lodash/isString'; | ||
function isAbortControllerSupported() { | ||
@@ -45,3 +57,3 @@ if (typeof window !== 'undefined') { | ||
function decodeParams(paramsString) { | ||
return List(paramsString.split('&')).map(s => List(s.split('=')).map(decodeURIComponent)).update(Map); | ||
return (0, _immutable.List)(paramsString.split('&')).map(s => (0, _immutable.List)(s.split('=')).map(decodeURIComponent)).update(_immutable.Map); | ||
} | ||
@@ -51,3 +63,3 @@ | ||
const [url, allParamsString] = wholeURL.split('?'); | ||
return Map(_objectSpread({ | ||
return (0, _immutable.Map)(_objectSpread({ | ||
url | ||
@@ -60,3 +72,3 @@ }, allParamsString ? { | ||
function fromFetchArguments(wholeURL, options) { | ||
return fromURL(wholeURL).merge((options ? fromJS(options) : Map()).remove('url').remove('params')); | ||
return fromURL(wholeURL).merge((options ? (0, _immutable.fromJS)(options) : (0, _immutable.Map)()).remove('url').remove('params')); | ||
} | ||
@@ -77,3 +89,3 @@ | ||
function maybeRequestArg(req) { | ||
if (isString(req)) { | ||
if ((0, _isString.default)(req)) { | ||
return fromURL(req); | ||
@@ -83,6 +95,6 @@ } | ||
if (req) { | ||
return fromJS(req); | ||
return (0, _immutable.fromJS)(req); | ||
} | ||
return Map(); | ||
return (0, _immutable.Map)(); | ||
} | ||
@@ -105,3 +117,3 @@ | ||
const getCurriedRequestProcessor = flow([ensureRequestArg2, curry]); | ||
const getCurriedRequestProcessor = (0, _flow.default)([ensureRequestArg2, _curry.default]); | ||
@@ -113,3 +125,3 @@ function getPropSetFunction(path) { | ||
function getPropMergeFunction(path) { | ||
return getCurriedRequestProcessor((obj, req) => req.updateIn(path, (p = Map()) => p.merge(obj))); | ||
return getCurriedRequestProcessor((obj, req) => req.updateIn(path, (p = (0, _immutable.Map)()) => p.merge(obj))); | ||
} | ||
@@ -131,3 +143,3 @@ | ||
})); | ||
export default { | ||
var _default = { | ||
toURL, | ||
@@ -144,2 +156,3 @@ fromURL, | ||
fetchWithTimeout | ||
}; | ||
}; | ||
exports.default = _default; |
{ | ||
"name": "netlify-cms-lib-util", | ||
"description": "Shared utilities for Netlify CMS.", | ||
"version": "2.13.0", | ||
"version": "2.13.1", | ||
"repository": "https://github.com/netlify/netlify-cms/tree/master/packages/netlify-cms-lib-util", | ||
@@ -28,3 +28,3 @@ "bugs": "https://github.com/netlify/netlify-cms/issues", | ||
}, | ||
"gitHead": "dada37396ba7d24ab20d3c6f7cd379a9aba45bf7" | ||
"gitHead": "bffea12b920501dea8e37703b0e10b96f6e98d5a" | ||
} |
@@ -1,11 +0,22 @@ | ||
# Docs coming soon! | ||
# Lib Util | ||
Netlify CMS was recently converted from a single npm package to a "monorepo" of over 20 packages. | ||
That's over 20 Readme's! We haven't created one for this package yet, but we will soon. | ||
Shared utilities to handle various `netlify-cms-backend-*` backends operations. | ||
In the meantime, you can: | ||
## Code structure | ||
1. Check out the [main readme](https://github.com/netlify/netlify-cms/#readme) or the [documentation | ||
site](https://www.netlifycms.org) for more info. | ||
2. Reach out to the [community chat](https://netlifycms.org/chat/) if you need help. | ||
3. Help out and [write the readme yourself](https://github.com/netlify/netlify-cms/edit/master/packages/netlify-cms-lib-util/README.md)! | ||
This structure should be the same for backends. | ||
At first, look at `Implementation`. This is File Management System API and has factory method for `AuthComponent`. | ||
### File Management System API | ||
An abstraction layer between the CMS and Git-repository manager API. | ||
Used as backend in [cms-core](https://github.com/netlify/netlify-cms/tree/master/packages/netlify-cms-core/README.md). | ||
### Low-level abstractions for Git-repository manager API: | ||
- `API` - used for Entry files | ||
- `git-lfs` - used for Media files | ||
- and over halpful utilities | ||
@@ -0,0 +0,0 @@ import { parseLinkHeader, getAllResponses, getPathDepth, filterByExtension } from '../backendUtil'; |
@@ -6,7 +6,6 @@ import unsentRequest from '../unsentRequest'; | ||
it('should create new request with headers', () => { | ||
expect( | ||
unsentRequest | ||
.withHeaders({ Authorization: 'token' })('path') | ||
.toJS(), | ||
).toEqual({ url: 'path', headers: { Authorization: 'token' } }); | ||
expect(unsentRequest.withHeaders({ Authorization: 'token' })('path').toJS()).toEqual({ | ||
url: 'path', | ||
headers: { Authorization: 'token' }, | ||
}); | ||
}); | ||
@@ -13,0 +12,0 @@ |
@@ -10,3 +10,3 @@ /** | ||
script.src = url; | ||
script.onload = script.onreadystatechange = function() { | ||
script.onload = script.onreadystatechange = function () { | ||
if ( | ||
@@ -13,0 +13,0 @@ !done && |
@@ -63,9 +63,3 @@ import { fromJS, List, Map } from 'immutable'; | ||
function toFetchArguments(req) { | ||
return [ | ||
toURL(req), | ||
req | ||
.remove('url') | ||
.remove('params') | ||
.toJS(), | ||
]; | ||
return [toURL(req), req.remove('url').remove('params').toJS()]; | ||
} | ||
@@ -72,0 +66,0 @@ |
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
864832
1.8%4125
12.86%23
91.67%