decap-cms-lib-util 3.0.4 → 3.2.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/CHANGELOG.md +12 -0
- package/dist/decap-cms-lib-util.js +1 -1
- package/dist/decap-cms-lib-util.js.map +1 -1
- package/dist/esm/API.js +28 -41
- package/dist/esm/APIError.js +3 -10
- package/dist/esm/APIUtils.js +10 -23
- package/dist/esm/AccessTokenError.js +3 -10
- package/dist/esm/Cursor.js +12 -19
- package/dist/esm/EditorialWorkflowError.js +3 -10
- package/dist/esm/asyncLock.js +5 -12
- package/dist/esm/backendUtil.js +19 -31
- package/dist/esm/getBlobSHA.js +4 -11
- package/dist/esm/git-lfs.js +17 -28
- package/dist/esm/implementation.js +21 -37
- package/dist/esm/index.js +71 -409
- package/dist/esm/loadScript.js +1 -7
- package/dist/esm/localForage.js +4 -11
- package/dist/esm/path.js +4 -13
- package/dist/esm/promise.js +5 -14
- package/dist/esm/stega.js +129 -0
- package/dist/esm/types/semaphore.d.js +0 -1
- package/dist/esm/types.js +7 -0
- package/dist/esm/unsentRequest.js +13 -20
- package/package.json +2 -2
- package/src/API.ts +6 -4
- package/src/stega.ts +134 -0
- package/src/types.ts +9 -0
package/dist/esm/git-lfs.js
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.createPointerFile = createPointerFile;
|
|
7
|
-
exports.getLargeMediaFilteredMediaFiles = getLargeMediaFilteredMediaFiles;
|
|
8
|
-
exports.getLargeMediaPatternsFromGitAttributesFile = void 0;
|
|
9
|
-
exports.getPointerFileForMediaFileObj = getPointerFileForMediaFileObj;
|
|
10
|
-
exports.parsePointerFile = void 0;
|
|
11
|
-
var _map2 = _interopRequireDefault(require("lodash/fp/map"));
|
|
12
|
-
var _fromPairs2 = _interopRequireDefault(require("lodash/fp/fromPairs"));
|
|
13
|
-
var _flow2 = _interopRequireDefault(require("lodash/fp/flow"));
|
|
14
|
-
var _filter2 = _interopRequireDefault(require("lodash/fp/filter"));
|
|
15
|
-
var _getBlobSHA = _interopRequireDefault(require("./getBlobSHA"));
|
|
16
|
-
const _excluded = ["size", "oid"]; //
|
|
1
|
+
import _map from "lodash/fp/map";
|
|
2
|
+
import _fromPairs from "lodash/fp/fromPairs";
|
|
3
|
+
import _flow from "lodash/fp/flow";
|
|
4
|
+
import _filter from "lodash/fp/filter"; //
|
|
17
5
|
// Pointer file parsing
|
|
18
|
-
|
|
6
|
+
const _excluded = ["size", "oid"];
|
|
19
7
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
20
8
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
21
9
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -23,6 +11,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
23
11
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
24
12
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
25
13
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
14
|
+
import getBlobSHA from './getBlobSHA';
|
|
26
15
|
function splitIntoLines(str) {
|
|
27
16
|
return str.split('\n');
|
|
28
17
|
}
|
|
@@ -32,8 +21,8 @@ function splitIntoWords(str) {
|
|
|
32
21
|
function isNonEmptyString(str) {
|
|
33
22
|
return str !== '';
|
|
34
23
|
}
|
|
35
|
-
const withoutEmptyLines = (
|
|
36
|
-
const parsePointerFile =
|
|
24
|
+
const withoutEmptyLines = _flow([_map(str => str.trim()), _filter(isNonEmptyString)]);
|
|
25
|
+
export const parsePointerFile = _flow([splitIntoLines, withoutEmptyLines, _map(splitIntoWords), _fromPairs, _ref => {
|
|
37
26
|
let {
|
|
38
27
|
size,
|
|
39
28
|
oid
|
|
@@ -65,11 +54,11 @@ function parseGitPatternAttribute(attributeString) {
|
|
|
65
54
|
}
|
|
66
55
|
return [attributeString, true];
|
|
67
56
|
}
|
|
68
|
-
const parseGitPatternAttributes = (
|
|
69
|
-
const parseGitAttributesPatternLine = (
|
|
70
|
-
const parseGitAttributesFileToPatternAttributePairs = (
|
|
71
|
-
const getLargeMediaPatternsFromGitAttributesFile =
|
|
72
|
-
function createPointerFile({
|
|
57
|
+
const parseGitPatternAttributes = _flow([_map(parseGitPatternAttribute), _fromPairs]);
|
|
58
|
+
const parseGitAttributesPatternLine = _flow([splitIntoWords, ([pattern, ...attributes]) => [pattern, parseGitPatternAttributes(attributes)]]);
|
|
59
|
+
const parseGitAttributesFileToPatternAttributePairs = _flow([splitIntoLines, _map(removeGitAttributesCommentsFromLine), withoutEmptyLines, _map(parseGitAttributesPatternLine)]);
|
|
60
|
+
export const getLargeMediaPatternsFromGitAttributesFile = _flow([parseGitAttributesFileToPatternAttributePairs, _filter(([, attributes]) => attributes.filter === 'lfs' && attributes.diff === 'lfs' && attributes.merge === 'lfs'), _map(([pattern]) => pattern)]);
|
|
61
|
+
export function createPointerFile({
|
|
73
62
|
size,
|
|
74
63
|
sha
|
|
75
64
|
}) {
|
|
@@ -79,12 +68,12 @@ oid sha256:${sha}
|
|
|
79
68
|
size ${size}
|
|
80
69
|
`;
|
|
81
70
|
}
|
|
82
|
-
async function getPointerFileForMediaFileObj(client, fileObj, path) {
|
|
71
|
+
export async function getPointerFileForMediaFileObj(client, fileObj, path) {
|
|
83
72
|
const {
|
|
84
73
|
name,
|
|
85
74
|
size
|
|
86
75
|
} = fileObj;
|
|
87
|
-
const sha = await (
|
|
76
|
+
const sha = await getBlobSHA(fileObj);
|
|
88
77
|
await client.uploadResource({
|
|
89
78
|
sha,
|
|
90
79
|
size
|
|
@@ -97,7 +86,7 @@ async function getPointerFileForMediaFileObj(client, fileObj, path) {
|
|
|
97
86
|
const pointerFile = new File([pointerFileBlob], name, {
|
|
98
87
|
type: 'text/plain'
|
|
99
88
|
});
|
|
100
|
-
const pointerFileSHA = await (
|
|
89
|
+
const pointerFileSHA = await getBlobSHA(pointerFile);
|
|
101
90
|
return {
|
|
102
91
|
fileObj: pointerFile,
|
|
103
92
|
size: pointerFileBlob.size,
|
|
@@ -106,7 +95,7 @@ async function getPointerFileForMediaFileObj(client, fileObj, path) {
|
|
|
106
95
|
path
|
|
107
96
|
};
|
|
108
97
|
}
|
|
109
|
-
async function getLargeMediaFilteredMediaFiles(client, mediaFiles) {
|
|
98
|
+
export async function getLargeMediaFilteredMediaFiles(client, mediaFiles) {
|
|
110
99
|
return await Promise.all(mediaFiles.map(async mediaFile => {
|
|
111
100
|
const {
|
|
112
101
|
fileObj,
|
|
@@ -1,31 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.allEntriesByFolder = allEntriesByFolder;
|
|
7
|
-
exports.blobToFileObj = blobToFileObj;
|
|
8
|
-
exports.entriesByFiles = entriesByFiles;
|
|
9
|
-
exports.entriesByFolder = entriesByFolder;
|
|
10
|
-
exports.getLocalTree = getLocalTree;
|
|
11
|
-
exports.getMediaAsBlob = getMediaAsBlob;
|
|
12
|
-
exports.getMediaDisplayURL = getMediaDisplayURL;
|
|
13
|
-
exports.persistLocalTree = persistLocalTree;
|
|
14
|
-
exports.runWithLock = runWithLock;
|
|
15
|
-
exports.unpublishedEntries = unpublishedEntries;
|
|
16
|
-
var _sortBy2 = _interopRequireDefault(require("lodash/sortBy"));
|
|
17
|
-
var _unionBy2 = _interopRequireDefault(require("lodash/unionBy"));
|
|
18
|
-
var _semaphore = _interopRequireDefault(require("semaphore"));
|
|
19
|
-
var _path = require("./path");
|
|
20
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1
|
+
import _sortBy from "lodash/sortBy";
|
|
2
|
+
import _unionBy from "lodash/unionBy";
|
|
21
3
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
22
4
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
23
5
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
24
6
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
25
7
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
+
import semaphore from 'semaphore';
|
|
9
|
+
import { basename } from './path';
|
|
26
10
|
const MAX_CONCURRENT_DOWNLOADS = 10;
|
|
27
11
|
async function fetchFiles(files, readFile, readFileMetadata, apiName) {
|
|
28
|
-
const sem = (
|
|
12
|
+
const sem = semaphore(MAX_CONCURRENT_DOWNLOADS);
|
|
29
13
|
const promises = [];
|
|
30
14
|
files.forEach(file => {
|
|
31
15
|
promises.push(new Promise(resolve => sem.take(async () => {
|
|
@@ -49,14 +33,14 @@ async function fetchFiles(files, readFile, readFileMetadata, apiName) {
|
|
|
49
33
|
});
|
|
50
34
|
return Promise.all(promises).then(loadedEntries => loadedEntries.filter(loadedEntry => !loadedEntry.error));
|
|
51
35
|
}
|
|
52
|
-
async function entriesByFolder(listFiles, readFile, readFileMetadata, apiName) {
|
|
36
|
+
export async function entriesByFolder(listFiles, readFile, readFileMetadata, apiName) {
|
|
53
37
|
const files = await listFiles();
|
|
54
38
|
return fetchFiles(files, readFile, readFileMetadata, apiName);
|
|
55
39
|
}
|
|
56
|
-
async function entriesByFiles(files, readFile, readFileMetadata, apiName) {
|
|
40
|
+
export async function entriesByFiles(files, readFile, readFileMetadata, apiName) {
|
|
57
41
|
return fetchFiles(files, readFile, readFileMetadata, apiName);
|
|
58
42
|
}
|
|
59
|
-
async function unpublishedEntries(listEntriesKeys) {
|
|
43
|
+
export async function unpublishedEntries(listEntriesKeys) {
|
|
60
44
|
try {
|
|
61
45
|
const keys = await listEntriesKeys();
|
|
62
46
|
return keys;
|
|
@@ -67,13 +51,13 @@ async function unpublishedEntries(listEntriesKeys) {
|
|
|
67
51
|
throw error;
|
|
68
52
|
}
|
|
69
53
|
}
|
|
70
|
-
function blobToFileObj(name, blob) {
|
|
54
|
+
export function blobToFileObj(name, blob) {
|
|
71
55
|
const options = name.match(/.svg$/) ? {
|
|
72
56
|
type: 'image/svg+xml'
|
|
73
57
|
} : {};
|
|
74
58
|
return new File([blob], name, options);
|
|
75
59
|
}
|
|
76
|
-
async function getMediaAsBlob(path, id, readFile) {
|
|
60
|
+
export async function getMediaAsBlob(path, id, readFile) {
|
|
77
61
|
let blob;
|
|
78
62
|
if (path.match(/.svg$/)) {
|
|
79
63
|
const text = await readFile(path, id, {
|
|
@@ -89,14 +73,14 @@ async function getMediaAsBlob(path, id, readFile) {
|
|
|
89
73
|
}
|
|
90
74
|
return blob;
|
|
91
75
|
}
|
|
92
|
-
async function getMediaDisplayURL(displayURL, readFile, semaphore) {
|
|
76
|
+
export async function getMediaDisplayURL(displayURL, readFile, semaphore) {
|
|
93
77
|
const {
|
|
94
78
|
path,
|
|
95
79
|
id
|
|
96
80
|
} = displayURL;
|
|
97
81
|
return new Promise((resolve, reject) => semaphore.take(() => getMediaAsBlob(path, id, readFile).then(blob => URL.createObjectURL(blob)).then(resolve, reject).finally(() => semaphore.leave())));
|
|
98
82
|
}
|
|
99
|
-
async function runWithLock(lock, func, message) {
|
|
83
|
+
export async function runWithLock(lock, func, message) {
|
|
100
84
|
try {
|
|
101
85
|
const acquired = await lock.acquire();
|
|
102
86
|
if (!acquired) {
|
|
@@ -117,7 +101,7 @@ function getLocalKey({
|
|
|
117
101
|
}) {
|
|
118
102
|
return `${LOCAL_KEY}.${branch}.${folder}.${extension}.${depth}`;
|
|
119
103
|
}
|
|
120
|
-
async function persistLocalTree({
|
|
104
|
+
export async function persistLocalTree({
|
|
121
105
|
localForage,
|
|
122
106
|
localTree,
|
|
123
107
|
branch,
|
|
@@ -132,7 +116,7 @@ async function persistLocalTree({
|
|
|
132
116
|
depth
|
|
133
117
|
}), localTree);
|
|
134
118
|
}
|
|
135
|
-
async function getLocalTree({
|
|
119
|
+
export async function getLocalTree({
|
|
136
120
|
localForage,
|
|
137
121
|
branch,
|
|
138
122
|
folder,
|
|
@@ -163,24 +147,24 @@ async function getDiffFromLocalTree({
|
|
|
163
147
|
if (d.status === 'renamed') {
|
|
164
148
|
acc.push({
|
|
165
149
|
path: d.oldPath,
|
|
166
|
-
name:
|
|
150
|
+
name: basename(d.oldPath),
|
|
167
151
|
deleted: true
|
|
168
152
|
});
|
|
169
153
|
acc.push({
|
|
170
154
|
path: d.newPath,
|
|
171
|
-
name:
|
|
155
|
+
name: basename(d.newPath),
|
|
172
156
|
deleted: false
|
|
173
157
|
});
|
|
174
158
|
} else if (d.status === 'deleted') {
|
|
175
159
|
acc.push({
|
|
176
160
|
path: d.oldPath,
|
|
177
|
-
name:
|
|
161
|
+
name: basename(d.oldPath),
|
|
178
162
|
deleted: true
|
|
179
163
|
});
|
|
180
164
|
} else {
|
|
181
165
|
acc.push({
|
|
182
166
|
path: d.newPath || d.oldPath,
|
|
183
|
-
name:
|
|
167
|
+
name: basename(d.newPath || d.oldPath),
|
|
184
168
|
deleted: false
|
|
185
169
|
});
|
|
186
170
|
}
|
|
@@ -200,7 +184,7 @@ async function getDiffFromLocalTree({
|
|
|
200
184
|
}));
|
|
201
185
|
return diffFilesWithIds;
|
|
202
186
|
}
|
|
203
|
-
async function allEntriesByFolder({
|
|
187
|
+
export async function allEntriesByFolder({
|
|
204
188
|
listAllFiles,
|
|
205
189
|
readFile,
|
|
206
190
|
readFileMetadata,
|
|
@@ -227,7 +211,7 @@ async function allEntriesByFolder({
|
|
|
227
211
|
files: files.map(f => ({
|
|
228
212
|
id: f.id,
|
|
229
213
|
path: f.path,
|
|
230
|
-
name:
|
|
214
|
+
name: basename(f.path)
|
|
231
215
|
}))
|
|
232
216
|
},
|
|
233
217
|
branch: branch.name,
|
|
@@ -278,7 +262,7 @@ async function allEntriesByFolder({
|
|
|
278
262
|
acc[d.path] = d.deleted;
|
|
279
263
|
return acc;
|
|
280
264
|
}, {});
|
|
281
|
-
const newCopy = (
|
|
265
|
+
const newCopy = _sortBy(_unionBy(diff.filter(d => !deleted[d.path]), localTree.files.filter(f => !deleted[f.path]), file => file.path), file => file.path);
|
|
282
266
|
await persistLocalTree({
|
|
283
267
|
localForage,
|
|
284
268
|
localTree: {
|