@nocobase/plugin-backup-restore 1.9.0-beta.8 → 2.0.0-alpha.2
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/client/e4f348aa71db3614.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/externalVersion.js +5 -5
- package/dist/node_modules/@hapi/topo/lib/index.js +1 -1
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/applyToDefaults.d.ts +3 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/applyToDefaults.js +102 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/assert.d.ts +3 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/assert.js +30 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/assertError.d.ts +3 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/assertError.js +18 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/bench.d.ts +3 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/bench.js +29 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/block.d.ts +3 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/block.js +12 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/clone.d.ts +3 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/clone.js +174 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/contain.d.ts +3 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/contain.js +307 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/deepEqual.d.ts +3 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/deepEqual.js +317 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/escapeHeaderAttribute.d.ts +3 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/escapeHeaderAttribute.js +16 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/escapeHtml.d.ts +3 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/escapeHtml.js +87 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/escapeJson.d.ts +3 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/escapeJson.js +28 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/escapeRegex.d.ts +3 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/escapeRegex.js +11 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/flatten.d.ts +3 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/flatten.js +20 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/ignore.d.ts +3 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/ignore.js +6 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/index.d.ts +480 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/index.js +45 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/intersect.d.ts +3 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/intersect.js +41 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/isPromise.d.ts +3 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/isPromise.js +9 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/merge.d.ts +3 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/merge.js +78 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/once.d.ts +3 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/once.js +25 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/reach.d.ts +3 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/reach.js +76 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/reachTemplate.d.ts +3 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/reachTemplate.js +16 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/stringify.d.ts +3 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/stringify.js +14 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/types.js +57 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/utils.js +9 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/wait.d.ts +3 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/lib/wait.js +37 -0
- package/dist/node_modules/@hapi/topo/node_modules/@hapi/hoek/package.json +60 -0
- package/dist/node_modules/@hapi/topo/package.json +1 -1
- package/dist/node_modules/archiver/package.json +1 -1
- package/dist/node_modules/decompress/package.json +1 -1
- package/dist/node_modules/fs-extra/package.json +1 -1
- package/dist/node_modules/moment/package.json +1 -1
- package/dist/node_modules/semver/package.json +1 -1
- package/package.json +8 -8
- package/dist/client/74239cd02b87724f.js +0 -10
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Assert = require('./assert');
|
|
4
|
+
const DeepEqual = require('./deepEqual');
|
|
5
|
+
const EscapeRegex = require('./escapeRegex');
|
|
6
|
+
const Utils = require('./utils');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
const internals = {};
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
module.exports = function (ref, values, options = {}) { // options: { deep, once, only, part, symbols }
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
string -> string(s)
|
|
16
|
+
array -> item(s)
|
|
17
|
+
object -> key(s)
|
|
18
|
+
object -> object (key:value)
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
if (typeof values !== 'object') {
|
|
22
|
+
values = [values];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
Assert(!Array.isArray(values) || values.length, 'Values array cannot be empty');
|
|
26
|
+
|
|
27
|
+
// String
|
|
28
|
+
|
|
29
|
+
if (typeof ref === 'string') {
|
|
30
|
+
return internals.string(ref, values, options);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Array
|
|
34
|
+
|
|
35
|
+
if (Array.isArray(ref)) {
|
|
36
|
+
return internals.array(ref, values, options);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Object
|
|
40
|
+
|
|
41
|
+
Assert(typeof ref === 'object', 'Reference must be string or an object');
|
|
42
|
+
return internals.object(ref, values, options);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
internals.array = function (ref, values, options) {
|
|
47
|
+
|
|
48
|
+
if (!Array.isArray(values)) {
|
|
49
|
+
values = [values];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!ref.length) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (options.only &&
|
|
57
|
+
options.once &&
|
|
58
|
+
ref.length !== values.length) {
|
|
59
|
+
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let compare;
|
|
64
|
+
|
|
65
|
+
// Map values
|
|
66
|
+
|
|
67
|
+
const map = new Map();
|
|
68
|
+
for (const value of values) {
|
|
69
|
+
if (!options.deep ||
|
|
70
|
+
!value ||
|
|
71
|
+
typeof value !== 'object') {
|
|
72
|
+
|
|
73
|
+
const existing = map.get(value);
|
|
74
|
+
if (existing) {
|
|
75
|
+
++existing.allowed;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
map.set(value, { allowed: 1, hits: 0 });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
compare = compare ?? internals.compare(options);
|
|
83
|
+
|
|
84
|
+
let found = false;
|
|
85
|
+
for (const [key, existing] of map.entries()) {
|
|
86
|
+
if (compare(key, value)) {
|
|
87
|
+
++existing.allowed;
|
|
88
|
+
found = true;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (!found) {
|
|
94
|
+
map.set(value, { allowed: 1, hits: 0 });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Lookup values
|
|
100
|
+
|
|
101
|
+
let hits = 0;
|
|
102
|
+
for (const item of ref) {
|
|
103
|
+
let match;
|
|
104
|
+
if (!options.deep ||
|
|
105
|
+
!item ||
|
|
106
|
+
typeof item !== 'object') {
|
|
107
|
+
|
|
108
|
+
match = map.get(item);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
compare = compare ?? internals.compare(options);
|
|
112
|
+
|
|
113
|
+
for (const [key, existing] of map.entries()) {
|
|
114
|
+
if (compare(key, item)) {
|
|
115
|
+
match = existing;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (match) {
|
|
122
|
+
++match.hits;
|
|
123
|
+
++hits;
|
|
124
|
+
|
|
125
|
+
if (options.once &&
|
|
126
|
+
match.hits > match.allowed) {
|
|
127
|
+
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Validate results
|
|
134
|
+
|
|
135
|
+
if (options.only &&
|
|
136
|
+
hits !== ref.length) {
|
|
137
|
+
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
for (const match of map.values()) {
|
|
142
|
+
if (match.hits === match.allowed) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (match.hits < match.allowed &&
|
|
147
|
+
!options.part) {
|
|
148
|
+
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return !!hits;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
internals.object = function (ref, values, options) {
|
|
158
|
+
|
|
159
|
+
Assert(options.once === undefined, 'Cannot use option once with object');
|
|
160
|
+
|
|
161
|
+
const keys = Utils.keys(ref, options);
|
|
162
|
+
if (!keys.length) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Keys list
|
|
167
|
+
|
|
168
|
+
if (Array.isArray(values)) {
|
|
169
|
+
return internals.array(keys, values, options);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Key value pairs
|
|
173
|
+
|
|
174
|
+
const symbols = Object.getOwnPropertySymbols(values).filter((sym) => values.propertyIsEnumerable(sym));
|
|
175
|
+
const targets = [...Object.keys(values), ...symbols];
|
|
176
|
+
|
|
177
|
+
const compare = internals.compare(options);
|
|
178
|
+
const set = new Set(targets);
|
|
179
|
+
|
|
180
|
+
for (const key of keys) {
|
|
181
|
+
if (!set.has(key)) {
|
|
182
|
+
if (options.only) {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (!compare(values[key], ref[key])) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
set.delete(key);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (set.size) {
|
|
197
|
+
return options.part ? set.size < targets.length : false;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return true;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
internals.string = function (ref, values, options) {
|
|
205
|
+
|
|
206
|
+
// Empty string
|
|
207
|
+
|
|
208
|
+
if (ref === '') {
|
|
209
|
+
return values.length === 1 && values[0] === '' || // '' contains ''
|
|
210
|
+
!options.once && !values.some((v) => v !== ''); // '' contains multiple '' if !once
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Map values
|
|
214
|
+
|
|
215
|
+
const map = new Map();
|
|
216
|
+
const patterns = [];
|
|
217
|
+
|
|
218
|
+
for (const value of values) {
|
|
219
|
+
Assert(typeof value === 'string', 'Cannot compare string reference to non-string value');
|
|
220
|
+
|
|
221
|
+
if (value) {
|
|
222
|
+
const existing = map.get(value);
|
|
223
|
+
if (existing) {
|
|
224
|
+
++existing.allowed;
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
map.set(value, { allowed: 1, hits: 0 });
|
|
228
|
+
patterns.push(EscapeRegex(value));
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
else if (options.once ||
|
|
232
|
+
options.only) {
|
|
233
|
+
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (!patterns.length) { // Non-empty string contains unlimited empty string
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Match patterns
|
|
243
|
+
|
|
244
|
+
const regex = new RegExp(`(${patterns.join('|')})`, 'g');
|
|
245
|
+
const leftovers = ref.replace(regex, ($0, $1) => {
|
|
246
|
+
|
|
247
|
+
++map.get($1).hits;
|
|
248
|
+
return ''; // Remove from string
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
// Validate results
|
|
252
|
+
|
|
253
|
+
if (options.only &&
|
|
254
|
+
leftovers) {
|
|
255
|
+
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
let any = false;
|
|
260
|
+
for (const match of map.values()) {
|
|
261
|
+
if (match.hits) {
|
|
262
|
+
any = true;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (match.hits === match.allowed) {
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (match.hits < match.allowed &&
|
|
270
|
+
!options.part) {
|
|
271
|
+
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// match.hits > match.allowed
|
|
276
|
+
|
|
277
|
+
if (options.once) {
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return !!any;
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
internals.compare = function (options) {
|
|
287
|
+
|
|
288
|
+
if (!options.deep) {
|
|
289
|
+
return internals.shallow;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const hasOnly = options.only !== undefined;
|
|
293
|
+
const hasPart = options.part !== undefined;
|
|
294
|
+
|
|
295
|
+
const flags = {
|
|
296
|
+
prototype: hasOnly ? options.only : hasPart ? !options.part : false,
|
|
297
|
+
part: hasOnly ? !options.only : hasPart ? options.part : false
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
return (a, b) => DeepEqual(a, b, flags);
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
internals.shallow = function (a, b) {
|
|
305
|
+
|
|
306
|
+
return a === b;
|
|
307
|
+
};
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Types = require('./types');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const internals = {
|
|
7
|
+
mismatched: null
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
module.exports = function (obj, ref, options) {
|
|
12
|
+
|
|
13
|
+
options = Object.assign({ prototype: true }, options);
|
|
14
|
+
|
|
15
|
+
return !!internals.isDeepEqual(obj, ref, options, []);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
internals.isDeepEqual = function (obj, ref, options, seen) {
|
|
20
|
+
|
|
21
|
+
if (obj === ref) { // Copied from Deep-eql, copyright(c) 2013 Jake Luer, jake@alogicalparadox.com, MIT Licensed, https://github.com/chaijs/deep-eql
|
|
22
|
+
return obj !== 0 || 1 / obj === 1 / ref;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const type = typeof obj;
|
|
26
|
+
|
|
27
|
+
if (type !== typeof ref) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (obj === null ||
|
|
32
|
+
ref === null) {
|
|
33
|
+
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (type === 'function') {
|
|
38
|
+
if (!options.deepFunction ||
|
|
39
|
+
obj.toString() !== ref.toString()) {
|
|
40
|
+
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Continue as object
|
|
45
|
+
}
|
|
46
|
+
else if (type !== 'object') {
|
|
47
|
+
return obj !== obj && ref !== ref; // NaN
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const instanceType = internals.getSharedType(obj, ref, !!options.prototype);
|
|
51
|
+
switch (instanceType) {
|
|
52
|
+
case Types.buffer:
|
|
53
|
+
return Buffer && Buffer.prototype.equals.call(obj, ref); // $lab:coverage:ignore$
|
|
54
|
+
case Types.promise:
|
|
55
|
+
return obj === ref;
|
|
56
|
+
case Types.regex:
|
|
57
|
+
case Types.url:
|
|
58
|
+
return obj.toString() === ref.toString();
|
|
59
|
+
case internals.mismatched:
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
for (let i = seen.length - 1; i >= 0; --i) {
|
|
64
|
+
if (seen[i].isSame(obj, ref)) {
|
|
65
|
+
return true; // If previous comparison failed, it would have stopped execution
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
seen.push(new internals.SeenEntry(obj, ref));
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
return !!internals.isDeepEqualObj(instanceType, obj, ref, options, seen);
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
seen.pop();
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
internals.getSharedType = function (obj, ref, checkPrototype) {
|
|
81
|
+
|
|
82
|
+
if (checkPrototype) {
|
|
83
|
+
if (Object.getPrototypeOf(obj) !== Object.getPrototypeOf(ref)) {
|
|
84
|
+
return internals.mismatched;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return Types.getInternalProto(obj);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const type = Types.getInternalProto(obj);
|
|
91
|
+
if (type !== Types.getInternalProto(ref)) {
|
|
92
|
+
return internals.mismatched;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return type;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
internals.valueOf = function (obj) {
|
|
100
|
+
|
|
101
|
+
const objValueOf = obj.valueOf;
|
|
102
|
+
if (objValueOf === undefined) {
|
|
103
|
+
return obj;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
return objValueOf.call(obj);
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
return err;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
internals.hasOwnEnumerableProperty = function (obj, key) {
|
|
116
|
+
|
|
117
|
+
return Object.prototype.propertyIsEnumerable.call(obj, key);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
internals.isSetSimpleEqual = function (obj, ref) {
|
|
122
|
+
|
|
123
|
+
for (const entry of Set.prototype.values.call(obj)) {
|
|
124
|
+
if (!Set.prototype.has.call(ref, entry)) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return true;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
internals.isDeepEqualObj = function (instanceType, obj, ref, options, seen) {
|
|
134
|
+
|
|
135
|
+
const { isDeepEqual, valueOf, hasOwnEnumerableProperty } = internals;
|
|
136
|
+
const { keys, getOwnPropertySymbols } = Object;
|
|
137
|
+
|
|
138
|
+
if (instanceType === Types.array) {
|
|
139
|
+
if (options.part) {
|
|
140
|
+
|
|
141
|
+
// Check if any index match any other index
|
|
142
|
+
|
|
143
|
+
for (const objValue of obj) {
|
|
144
|
+
for (const refValue of ref) {
|
|
145
|
+
if (isDeepEqual(objValue, refValue, options, seen)) {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
if (obj.length !== ref.length) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
for (let i = 0; i < obj.length; ++i) {
|
|
157
|
+
if (!isDeepEqual(obj[i], ref[i], options, seen)) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else if (instanceType === Types.set) {
|
|
166
|
+
if (obj.size !== ref.size) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (!internals.isSetSimpleEqual(obj, ref)) {
|
|
171
|
+
|
|
172
|
+
// Check for deep equality
|
|
173
|
+
|
|
174
|
+
const ref2 = new Set(Set.prototype.values.call(ref));
|
|
175
|
+
for (const objEntry of Set.prototype.values.call(obj)) {
|
|
176
|
+
if (ref2.delete(objEntry)) {
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
let found = false;
|
|
181
|
+
for (const refEntry of ref2) {
|
|
182
|
+
if (isDeepEqual(objEntry, refEntry, options, seen)) {
|
|
183
|
+
ref2.delete(refEntry);
|
|
184
|
+
found = true;
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (!found) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
else if (instanceType === Types.map) {
|
|
196
|
+
if (obj.size !== ref.size) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
for (const [key, value] of Map.prototype.entries.call(obj)) {
|
|
201
|
+
if (value === undefined && !Map.prototype.has.call(ref, key)) {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (!isDeepEqual(value, Map.prototype.get.call(ref, key), options, seen)) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else if (instanceType === Types.error) {
|
|
211
|
+
|
|
212
|
+
// Always check name and message
|
|
213
|
+
|
|
214
|
+
if (obj.name !== ref.name ||
|
|
215
|
+
obj.message !== ref.message) {
|
|
216
|
+
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Check .valueOf()
|
|
222
|
+
|
|
223
|
+
const valueOfObj = valueOf(obj);
|
|
224
|
+
const valueOfRef = valueOf(ref);
|
|
225
|
+
if ((obj !== valueOfObj || ref !== valueOfRef) &&
|
|
226
|
+
!isDeepEqual(valueOfObj, valueOfRef, options, seen)) {
|
|
227
|
+
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Check properties
|
|
232
|
+
|
|
233
|
+
const objKeys = keys(obj);
|
|
234
|
+
if (!options.part &&
|
|
235
|
+
objKeys.length !== keys(ref).length &&
|
|
236
|
+
!options.skip) {
|
|
237
|
+
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
let skipped = 0;
|
|
242
|
+
for (const key of objKeys) {
|
|
243
|
+
if (options.skip &&
|
|
244
|
+
options.skip.includes(key)) {
|
|
245
|
+
|
|
246
|
+
if (ref[key] === undefined) {
|
|
247
|
+
++skipped;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (!hasOwnEnumerableProperty(ref, key)) {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (!isDeepEqual(obj[key], ref[key], options, seen)) {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (!options.part &&
|
|
263
|
+
objKeys.length - skipped !== keys(ref).length) {
|
|
264
|
+
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Check symbols
|
|
269
|
+
|
|
270
|
+
if (options.symbols !== false) { // Defaults to true
|
|
271
|
+
const objSymbols = getOwnPropertySymbols(obj);
|
|
272
|
+
const refSymbols = new Set(getOwnPropertySymbols(ref));
|
|
273
|
+
|
|
274
|
+
for (const key of objSymbols) {
|
|
275
|
+
if (!options.skip?.includes(key)) {
|
|
276
|
+
|
|
277
|
+
if (hasOwnEnumerableProperty(obj, key)) {
|
|
278
|
+
if (!hasOwnEnumerableProperty(ref, key)) {
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (!isDeepEqual(obj[key], ref[key], options, seen)) {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
else if (hasOwnEnumerableProperty(ref, key)) {
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
refSymbols.delete(key);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
for (const key of refSymbols) {
|
|
295
|
+
if (hasOwnEnumerableProperty(ref, key)) {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
return true;
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
internals.SeenEntry = class {
|
|
306
|
+
|
|
307
|
+
constructor(obj, ref) {
|
|
308
|
+
|
|
309
|
+
this.obj = obj;
|
|
310
|
+
this.ref = ref;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
isSame(obj, ref) {
|
|
314
|
+
|
|
315
|
+
return this.obj === obj && this.ref === ref;
|
|
316
|
+
}
|
|
317
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Assert = require('./assert');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const internals = {};
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
module.exports = function (attribute) {
|
|
10
|
+
|
|
11
|
+
// Allowed value characters: !#$%&'()*+,-./:;<=>?@[]^_`{|}~ and space, a-z, A-Z, 0-9, \, "
|
|
12
|
+
|
|
13
|
+
Assert(/^[ \w\!#\$%&'\(\)\*\+,\-\.\/\:;<\=>\?@\[\]\^`\{\|\}~\"\\]*$/.test(attribute), 'Bad attribute value (' + attribute + ')');
|
|
14
|
+
|
|
15
|
+
return attribute.replace(/\\/g, '\\\\').replace(/\"/g, '\\"'); // Escape quotes and slash
|
|
16
|
+
};
|