decap-cms-lib-util 3.3.0 → 3.4.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/decap-cms-lib-util.js +1 -1
- package/dist/decap-cms-lib-util.js.map +1 -1
- package/dist/esm/API.js +1 -22
- package/dist/esm/APIError.js +1 -22
- package/dist/esm/AccessTokenError.js +1 -22
- package/dist/esm/EditorialWorkflowError.js +1 -22
- package/dist/esm/path.js +3 -2
- package/package.json +2 -2
- package/dist/esm/stega.js +0 -129
package/dist/esm/API.js
CHANGED
|
@@ -1,28 +1,7 @@
|
|
|
1
|
-
function _extendableBuiltin(cls) {
|
|
2
|
-
function ExtendableBuiltin() {
|
|
3
|
-
var instance = Reflect.construct(cls, Array.from(arguments));
|
|
4
|
-
Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
|
|
5
|
-
return instance;
|
|
6
|
-
}
|
|
7
|
-
ExtendableBuiltin.prototype = Object.create(cls.prototype, {
|
|
8
|
-
constructor: {
|
|
9
|
-
value: cls,
|
|
10
|
-
enumerable: false,
|
|
11
|
-
writable: true,
|
|
12
|
-
configurable: true
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
if (Object.setPrototypeOf) {
|
|
16
|
-
Object.setPrototypeOf(ExtendableBuiltin, cls);
|
|
17
|
-
} else {
|
|
18
|
-
ExtendableBuiltin.__proto__ = cls;
|
|
19
|
-
}
|
|
20
|
-
return ExtendableBuiltin;
|
|
21
|
-
}
|
|
22
1
|
import { asyncLock } from './asyncLock';
|
|
23
2
|
import unsentRequest from './unsentRequest';
|
|
24
3
|
import APIError from './APIError';
|
|
25
|
-
class RateLimitError extends
|
|
4
|
+
class RateLimitError extends Error {
|
|
26
5
|
constructor(message, resetSeconds) {
|
|
27
6
|
super(message);
|
|
28
7
|
if (resetSeconds < 0) {
|
package/dist/esm/APIError.js
CHANGED
|
@@ -1,26 +1,5 @@
|
|
|
1
|
-
function _extendableBuiltin(cls) {
|
|
2
|
-
function ExtendableBuiltin() {
|
|
3
|
-
var instance = Reflect.construct(cls, Array.from(arguments));
|
|
4
|
-
Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
|
|
5
|
-
return instance;
|
|
6
|
-
}
|
|
7
|
-
ExtendableBuiltin.prototype = Object.create(cls.prototype, {
|
|
8
|
-
constructor: {
|
|
9
|
-
value: cls,
|
|
10
|
-
enumerable: false,
|
|
11
|
-
writable: true,
|
|
12
|
-
configurable: true
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
if (Object.setPrototypeOf) {
|
|
16
|
-
Object.setPrototypeOf(ExtendableBuiltin, cls);
|
|
17
|
-
} else {
|
|
18
|
-
ExtendableBuiltin.__proto__ = cls;
|
|
19
|
-
}
|
|
20
|
-
return ExtendableBuiltin;
|
|
21
|
-
}
|
|
22
1
|
export const API_ERROR = 'API_ERROR';
|
|
23
|
-
export default class APIError extends
|
|
2
|
+
export default class APIError extends Error {
|
|
24
3
|
constructor(message, status, api, meta = {}) {
|
|
25
4
|
super(message);
|
|
26
5
|
this.message = message;
|
|
@@ -1,26 +1,5 @@
|
|
|
1
|
-
function _extendableBuiltin(cls) {
|
|
2
|
-
function ExtendableBuiltin() {
|
|
3
|
-
var instance = Reflect.construct(cls, Array.from(arguments));
|
|
4
|
-
Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
|
|
5
|
-
return instance;
|
|
6
|
-
}
|
|
7
|
-
ExtendableBuiltin.prototype = Object.create(cls.prototype, {
|
|
8
|
-
constructor: {
|
|
9
|
-
value: cls,
|
|
10
|
-
enumerable: false,
|
|
11
|
-
writable: true,
|
|
12
|
-
configurable: true
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
if (Object.setPrototypeOf) {
|
|
16
|
-
Object.setPrototypeOf(ExtendableBuiltin, cls);
|
|
17
|
-
} else {
|
|
18
|
-
ExtendableBuiltin.__proto__ = cls;
|
|
19
|
-
}
|
|
20
|
-
return ExtendableBuiltin;
|
|
21
|
-
}
|
|
22
1
|
export const ACCESS_TOKEN_ERROR = 'ACCESS_TOKEN_ERROR';
|
|
23
|
-
export default class AccessTokenError extends
|
|
2
|
+
export default class AccessTokenError extends Error {
|
|
24
3
|
constructor(message) {
|
|
25
4
|
super(message);
|
|
26
5
|
this.message = message;
|
|
@@ -1,26 +1,5 @@
|
|
|
1
|
-
function _extendableBuiltin(cls) {
|
|
2
|
-
function ExtendableBuiltin() {
|
|
3
|
-
var instance = Reflect.construct(cls, Array.from(arguments));
|
|
4
|
-
Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
|
|
5
|
-
return instance;
|
|
6
|
-
}
|
|
7
|
-
ExtendableBuiltin.prototype = Object.create(cls.prototype, {
|
|
8
|
-
constructor: {
|
|
9
|
-
value: cls,
|
|
10
|
-
enumerable: false,
|
|
11
|
-
writable: true,
|
|
12
|
-
configurable: true
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
if (Object.setPrototypeOf) {
|
|
16
|
-
Object.setPrototypeOf(ExtendableBuiltin, cls);
|
|
17
|
-
} else {
|
|
18
|
-
ExtendableBuiltin.__proto__ = cls;
|
|
19
|
-
}
|
|
20
|
-
return ExtendableBuiltin;
|
|
21
|
-
}
|
|
22
1
|
export const EDITORIAL_WORKFLOW_ERROR = 'EDITORIAL_WORKFLOW_ERROR';
|
|
23
|
-
export default class EditorialWorkflowError extends
|
|
2
|
+
export default class EditorialWorkflowError extends Error {
|
|
24
3
|
constructor(message, notUnderEditorialWorkflow) {
|
|
25
4
|
super(message);
|
|
26
5
|
this.message = message;
|
package/dist/esm/path.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
const absolutePath = new RegExp('^(?:[a-z]+:)
|
|
1
|
+
const absolutePath = new RegExp('^(?:[a-z]+:)?//|^/', 'i');
|
|
2
2
|
function normalizePath(path) {
|
|
3
3
|
return path.replace(/[\\/]+/g, '/');
|
|
4
4
|
}
|
|
5
5
|
export function isAbsolutePath(path) {
|
|
6
|
-
|
|
6
|
+
const result = absolutePath.test(path);
|
|
7
|
+
return result;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "decap-cms-lib-util",
|
|
3
3
|
"description": "Shared utilities for Decap CMS.",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.4.0",
|
|
5
5
|
"repository": "https://github.com/decaporg/decap-cms/tree/main/packages/decap-cms-lib-util",
|
|
6
6
|
"bugs": "https://github.com/decaporg/decap-cms/issues",
|
|
7
7
|
"module": "dist/esm/index.js",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"immutable": "^3.7.6",
|
|
29
29
|
"lodash": "^4.17.11"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "0c1b7c7d63ba6ddb3de3692fbb6b16ac6ebb44d5"
|
|
32
32
|
}
|
package/dist/esm/stega.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { vercelStegaEncode } from '@vercel/stega';
|
|
2
|
-
import { isImmutableMap, isImmutableList } from './types';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Context passed to encode functions, containing the current state of the encoding process
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Get the fields that should be used for encoding nested values
|
|
10
|
-
*/
|
|
11
|
-
function getNestedFields(f) {
|
|
12
|
-
if (f) {
|
|
13
|
-
if ('types' in f) {
|
|
14
|
-
var _f$types;
|
|
15
|
-
return (_f$types = f.types) !== null && _f$types !== void 0 ? _f$types : [];
|
|
16
|
-
}
|
|
17
|
-
if ('fields' in f) {
|
|
18
|
-
var _f$fields;
|
|
19
|
-
return (_f$fields = f.fields) !== null && _f$fields !== void 0 ? _f$fields : [];
|
|
20
|
-
}
|
|
21
|
-
if ('field' in f) {
|
|
22
|
-
return f.field ? [f.field] : [];
|
|
23
|
-
}
|
|
24
|
-
return [f];
|
|
25
|
-
}
|
|
26
|
-
return [];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Encode a string value by appending steganographic data
|
|
31
|
-
* For markdown fields, encode each paragraph separately
|
|
32
|
-
*/
|
|
33
|
-
function encodeString(value, {
|
|
34
|
-
fields,
|
|
35
|
-
path
|
|
36
|
-
}) {
|
|
37
|
-
var _fields$;
|
|
38
|
-
const stega = vercelStegaEncode({
|
|
39
|
-
decap: path
|
|
40
|
-
});
|
|
41
|
-
const isMarkdown = ((_fields$ = fields[0]) === null || _fields$ === void 0 ? void 0 : _fields$.widget) === 'markdown';
|
|
42
|
-
if (isMarkdown && value.includes('\n\n')) {
|
|
43
|
-
const blocks = value.split(/(\n\n+)/);
|
|
44
|
-
return blocks.map(block => block.trim() ? block + stega : block).join('');
|
|
45
|
-
}
|
|
46
|
-
return value + stega;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Encode a list of values, handling both simple values and nested objects/lists
|
|
51
|
-
* For typed lists, use the type field to determine which fields to use
|
|
52
|
-
*/
|
|
53
|
-
function encodeList(list, ctx) {
|
|
54
|
-
let newList = list;
|
|
55
|
-
for (let i = 0; i < newList.size; i++) {
|
|
56
|
-
const item = newList.get(i);
|
|
57
|
-
if (isImmutableMap(item)) {
|
|
58
|
-
const itemType = item.get('type');
|
|
59
|
-
if (typeof itemType === 'string') {
|
|
60
|
-
// For typed items, look up fields based on type
|
|
61
|
-
const field = ctx.fields.find(f => f.name === itemType);
|
|
62
|
-
const newItem = ctx.visit(item, getNestedFields(field), `${ctx.path}.${i}`);
|
|
63
|
-
newList = newList.set(i, newItem);
|
|
64
|
-
} else {
|
|
65
|
-
// For untyped items, use current fields
|
|
66
|
-
const newItem = ctx.visit(item, ctx.fields, `${ctx.path}.${i}`);
|
|
67
|
-
newList = newList.set(i, newItem);
|
|
68
|
-
}
|
|
69
|
-
} else {
|
|
70
|
-
// For simple values, use first field if available
|
|
71
|
-
const field = ctx.fields[0];
|
|
72
|
-
const newItem = ctx.visit(item, field ? [field] : [], `${ctx.path}.${i}`);
|
|
73
|
-
if (newItem !== item) {
|
|
74
|
-
newList = newList.set(i, newItem);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return newList;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Encode a map of values, looking up the appropriate field for each key
|
|
83
|
-
* and recursively encoding nested values
|
|
84
|
-
*/
|
|
85
|
-
function encodeMap(map, ctx) {
|
|
86
|
-
let newMap = map;
|
|
87
|
-
for (const [key, val] of newMap.entrySeq().toArray()) {
|
|
88
|
-
const field = ctx.fields.find(f => f.name === key);
|
|
89
|
-
if (field) {
|
|
90
|
-
const fields = getNestedFields(field);
|
|
91
|
-
const newVal = ctx.visit(val, fields, ctx.path ? `${ctx.path}.${key}` : key);
|
|
92
|
-
if (newVal !== val) {
|
|
93
|
-
newMap = newMap.set(key, newVal);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return newMap;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Main entry point for encoding steganographic data into entry values
|
|
102
|
-
* Uses a visitor pattern with caching to handle recursive structures
|
|
103
|
-
*/
|
|
104
|
-
export function encodeEntry(value, fields) {
|
|
105
|
-
const plainFields = fields.toJS();
|
|
106
|
-
const cache = new Map();
|
|
107
|
-
function visit(value, fields, path = '') {
|
|
108
|
-
const cached = cache.get(path);
|
|
109
|
-
if (cached === value) return value;
|
|
110
|
-
const ctx = {
|
|
111
|
-
fields,
|
|
112
|
-
path,
|
|
113
|
-
visit
|
|
114
|
-
};
|
|
115
|
-
let result;
|
|
116
|
-
if (isImmutableList(value)) {
|
|
117
|
-
result = encodeList(value, ctx);
|
|
118
|
-
} else if (isImmutableMap(value)) {
|
|
119
|
-
result = encodeMap(value, ctx);
|
|
120
|
-
} else if (typeof value === 'string') {
|
|
121
|
-
result = encodeString(value, ctx);
|
|
122
|
-
} else {
|
|
123
|
-
result = value;
|
|
124
|
-
}
|
|
125
|
-
cache.set(path, result);
|
|
126
|
-
return result;
|
|
127
|
-
}
|
|
128
|
-
return visit(value, plainFields);
|
|
129
|
-
}
|