@paris-ias/trees 2.0.16 → 2.0.17

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.
Files changed (57) hide show
  1. package/dist/form/actions.cjs.js +47 -9
  2. package/dist/form/actions.js +47 -9
  3. package/dist/form/affiliations.cjs.js +47 -9
  4. package/dist/form/affiliations.js +47 -9
  5. package/dist/form/apps.cjs.js +47 -9
  6. package/dist/form/apps.js +47 -9
  7. package/dist/form/disciplines.cjs.js +47 -9
  8. package/dist/form/disciplines.js +47 -9
  9. package/dist/form/events.cjs.js +47 -9
  10. package/dist/form/events.js +47 -9
  11. package/dist/form/fellowships.cjs.js +47 -9
  12. package/dist/form/fellowships.js +47 -9
  13. package/dist/form/files.cjs.js +47 -9
  14. package/dist/form/files.js +47 -9
  15. package/dist/form/mailing.cjs.js +47 -9
  16. package/dist/form/mailing.js +47 -9
  17. package/dist/form/news.cjs.js +47 -9
  18. package/dist/form/news.js +47 -9
  19. package/dist/form/people.cjs.js +47 -9
  20. package/dist/form/people.js +47 -9
  21. package/dist/form/projects.cjs.js +47 -9
  22. package/dist/form/projects.js +47 -9
  23. package/dist/form/publications.cjs.js +47 -9
  24. package/dist/form/publications.js +47 -9
  25. package/dist/form/tags.cjs.js +47 -9
  26. package/dist/form/tags.js +47 -9
  27. package/dist/form/users.cjs.js +47 -9
  28. package/dist/form/users.js +47 -9
  29. package/dist/list/actions.cjs.js +49 -10
  30. package/dist/list/actions.js +49 -10
  31. package/dist/list/affiliations.cjs.js +49 -10
  32. package/dist/list/affiliations.js +49 -10
  33. package/dist/list/apps.cjs.js +49 -10
  34. package/dist/list/apps.js +49 -10
  35. package/dist/list/disciplines.cjs.js +49 -10
  36. package/dist/list/disciplines.js +49 -10
  37. package/dist/list/events.cjs.js +65 -18
  38. package/dist/list/events.js +65 -18
  39. package/dist/list/fellowships.cjs.js +55 -13
  40. package/dist/list/fellowships.js +55 -13
  41. package/dist/list/files.cjs.js +49 -10
  42. package/dist/list/files.js +49 -10
  43. package/dist/list/mailing.cjs.js +49 -10
  44. package/dist/list/mailing.js +49 -10
  45. package/dist/list/news.cjs.js +51 -11
  46. package/dist/list/news.js +51 -11
  47. package/dist/list/people.cjs.js +57 -14
  48. package/dist/list/people.js +57 -14
  49. package/dist/list/projects.cjs.js +51 -11
  50. package/dist/list/projects.js +51 -11
  51. package/dist/list/publications.cjs.js +55 -13
  52. package/dist/list/publications.js +55 -13
  53. package/dist/list/tags.cjs.js +49 -10
  54. package/dist/list/tags.js +49 -10
  55. package/dist/list/users.cjs.js +57 -14
  56. package/dist/list/users.js +57 -14
  57. package/package.json +1 -1
@@ -1,17 +1,55 @@
1
1
  'use strict';
2
2
 
3
3
  // Deep freeze utility to make exports immutable
4
- const deepFreeze = (obj) => {
5
- Object.freeze(obj);
6
- Object.getOwnPropertyNames(obj).forEach(prop => {
7
- if (obj[prop] !== null
8
- && (typeof obj[prop] === "object" || typeof obj[prop] === "function")
9
- && !Object.isFrozen(obj[prop])) {
10
- deepFreeze(obj[prop]);
4
+ const lockAllBut = (obj, mutableKeys = []) => {
5
+ for (const key of Object.getOwnPropertyNames(obj)) {
6
+ if (mutableKeys.includes(key)) continue;
7
+
8
+ const desc = Object.getOwnPropertyDescriptor(obj, key);
9
+ if (!desc) continue;
10
+
11
+ if ("value" in desc) {
12
+ Object.defineProperty(obj, key, {
13
+ ...desc,
14
+ writable: false,
15
+ configurable: false,
16
+ });
17
+ } else {
18
+ Object.defineProperty(obj, key, {
19
+ ...desc,
20
+ configurable: false,
21
+ });
11
22
  }
12
- });
23
+ }
24
+ Object.preventExtensions(obj);
13
25
  return obj;
14
26
  };
27
+ const selectiveDeepFreeze = (obj, path = []) => {
28
+ if (obj === null || typeof obj !== "object") return obj;
29
+
30
+ if (Array.isArray(obj)) {
31
+ obj.forEach((v, i) => selectiveDeepFreeze(v, path.concat(String(i))));
32
+ return Object.freeze(obj);
33
+ }
34
+
35
+ const parentKey = path.length >= 1 ? path[path.length - 1] : null;
36
+ const grandParentKey = path.length >= 2 ? path[path.length - 2] : null;
37
+
38
+ const isFilterEntry = grandParentKey === "filters";
39
+
40
+ if (isFilterEntry) {
41
+ for (const k of Object.getOwnPropertyNames(obj)) {
42
+ if (k === "value") continue; // laisser value libre
43
+ selectiveDeepFreeze(obj[k], path.concat(parentKey, k));
44
+ }
45
+ return lockAllBut(obj, ["value"]);
46
+ }
47
+
48
+ for (const prop of Object.getOwnPropertyNames(obj)) {
49
+ selectiveDeepFreeze(obj[prop], path.concat(prop));
50
+ }
51
+ return Object.freeze(obj);
52
+ };
15
53
 
16
54
  const data = {
17
55
  "_defaults": {
@@ -672,6 +710,6 @@ const data = {
672
710
  }
673
711
  };
674
712
 
675
- var people = deepFreeze(data);
713
+ var people = selectiveDeepFreeze(data);
676
714
 
677
715
  module.exports = people;
@@ -1,15 +1,53 @@
1
1
  // Deep freeze utility to make exports immutable
2
- const deepFreeze = (obj) => {
3
- Object.freeze(obj);
4
- Object.getOwnPropertyNames(obj).forEach(prop => {
5
- if (obj[prop] !== null
6
- && (typeof obj[prop] === "object" || typeof obj[prop] === "function")
7
- && !Object.isFrozen(obj[prop])) {
8
- deepFreeze(obj[prop]);
2
+ const lockAllBut = (obj, mutableKeys = []) => {
3
+ for (const key of Object.getOwnPropertyNames(obj)) {
4
+ if (mutableKeys.includes(key)) continue;
5
+
6
+ const desc = Object.getOwnPropertyDescriptor(obj, key);
7
+ if (!desc) continue;
8
+
9
+ if ("value" in desc) {
10
+ Object.defineProperty(obj, key, {
11
+ ...desc,
12
+ writable: false,
13
+ configurable: false,
14
+ });
15
+ } else {
16
+ Object.defineProperty(obj, key, {
17
+ ...desc,
18
+ configurable: false,
19
+ });
9
20
  }
10
- });
21
+ }
22
+ Object.preventExtensions(obj);
11
23
  return obj;
12
24
  };
25
+ const selectiveDeepFreeze = (obj, path = []) => {
26
+ if (obj === null || typeof obj !== "object") return obj;
27
+
28
+ if (Array.isArray(obj)) {
29
+ obj.forEach((v, i) => selectiveDeepFreeze(v, path.concat(String(i))));
30
+ return Object.freeze(obj);
31
+ }
32
+
33
+ const parentKey = path.length >= 1 ? path[path.length - 1] : null;
34
+ const grandParentKey = path.length >= 2 ? path[path.length - 2] : null;
35
+
36
+ const isFilterEntry = grandParentKey === "filters";
37
+
38
+ if (isFilterEntry) {
39
+ for (const k of Object.getOwnPropertyNames(obj)) {
40
+ if (k === "value") continue; // laisser value libre
41
+ selectiveDeepFreeze(obj[k], path.concat(parentKey, k));
42
+ }
43
+ return lockAllBut(obj, ["value"]);
44
+ }
45
+
46
+ for (const prop of Object.getOwnPropertyNames(obj)) {
47
+ selectiveDeepFreeze(obj[prop], path.concat(prop));
48
+ }
49
+ return Object.freeze(obj);
50
+ };
13
51
 
14
52
  const data = {
15
53
  "_defaults": {
@@ -670,6 +708,6 @@ const data = {
670
708
  }
671
709
  };
672
710
 
673
- var people = deepFreeze(data);
711
+ var people = selectiveDeepFreeze(data);
674
712
 
675
713
  export { people as default };
@@ -1,17 +1,55 @@
1
1
  'use strict';
2
2
 
3
3
  // Deep freeze utility to make exports immutable
4
- const deepFreeze = (obj) => {
5
- Object.freeze(obj);
6
- Object.getOwnPropertyNames(obj).forEach(prop => {
7
- if (obj[prop] !== null
8
- && (typeof obj[prop] === "object" || typeof obj[prop] === "function")
9
- && !Object.isFrozen(obj[prop])) {
10
- deepFreeze(obj[prop]);
4
+ const lockAllBut = (obj, mutableKeys = []) => {
5
+ for (const key of Object.getOwnPropertyNames(obj)) {
6
+ if (mutableKeys.includes(key)) continue;
7
+
8
+ const desc = Object.getOwnPropertyDescriptor(obj, key);
9
+ if (!desc) continue;
10
+
11
+ if ("value" in desc) {
12
+ Object.defineProperty(obj, key, {
13
+ ...desc,
14
+ writable: false,
15
+ configurable: false,
16
+ });
17
+ } else {
18
+ Object.defineProperty(obj, key, {
19
+ ...desc,
20
+ configurable: false,
21
+ });
11
22
  }
12
- });
23
+ }
24
+ Object.preventExtensions(obj);
13
25
  return obj;
14
26
  };
27
+ const selectiveDeepFreeze = (obj, path = []) => {
28
+ if (obj === null || typeof obj !== "object") return obj;
29
+
30
+ if (Array.isArray(obj)) {
31
+ obj.forEach((v, i) => selectiveDeepFreeze(v, path.concat(String(i))));
32
+ return Object.freeze(obj);
33
+ }
34
+
35
+ const parentKey = path.length >= 1 ? path[path.length - 1] : null;
36
+ const grandParentKey = path.length >= 2 ? path[path.length - 2] : null;
37
+
38
+ const isFilterEntry = grandParentKey === "filters";
39
+
40
+ if (isFilterEntry) {
41
+ for (const k of Object.getOwnPropertyNames(obj)) {
42
+ if (k === "value") continue; // laisser value libre
43
+ selectiveDeepFreeze(obj[k], path.concat(parentKey, k));
44
+ }
45
+ return lockAllBut(obj, ["value"]);
46
+ }
47
+
48
+ for (const prop of Object.getOwnPropertyNames(obj)) {
49
+ selectiveDeepFreeze(obj[prop], path.concat(prop));
50
+ }
51
+ return Object.freeze(obj);
52
+ };
15
53
 
16
54
  const data = {
17
55
  "_defaults": {
@@ -352,6 +390,6 @@ const data = {
352
390
  }
353
391
  };
354
392
 
355
- var projects = deepFreeze(data);
393
+ var projects = selectiveDeepFreeze(data);
356
394
 
357
395
  module.exports = projects;
@@ -1,15 +1,53 @@
1
1
  // Deep freeze utility to make exports immutable
2
- const deepFreeze = (obj) => {
3
- Object.freeze(obj);
4
- Object.getOwnPropertyNames(obj).forEach(prop => {
5
- if (obj[prop] !== null
6
- && (typeof obj[prop] === "object" || typeof obj[prop] === "function")
7
- && !Object.isFrozen(obj[prop])) {
8
- deepFreeze(obj[prop]);
2
+ const lockAllBut = (obj, mutableKeys = []) => {
3
+ for (const key of Object.getOwnPropertyNames(obj)) {
4
+ if (mutableKeys.includes(key)) continue;
5
+
6
+ const desc = Object.getOwnPropertyDescriptor(obj, key);
7
+ if (!desc) continue;
8
+
9
+ if ("value" in desc) {
10
+ Object.defineProperty(obj, key, {
11
+ ...desc,
12
+ writable: false,
13
+ configurable: false,
14
+ });
15
+ } else {
16
+ Object.defineProperty(obj, key, {
17
+ ...desc,
18
+ configurable: false,
19
+ });
9
20
  }
10
- });
21
+ }
22
+ Object.preventExtensions(obj);
11
23
  return obj;
12
24
  };
25
+ const selectiveDeepFreeze = (obj, path = []) => {
26
+ if (obj === null || typeof obj !== "object") return obj;
27
+
28
+ if (Array.isArray(obj)) {
29
+ obj.forEach((v, i) => selectiveDeepFreeze(v, path.concat(String(i))));
30
+ return Object.freeze(obj);
31
+ }
32
+
33
+ const parentKey = path.length >= 1 ? path[path.length - 1] : null;
34
+ const grandParentKey = path.length >= 2 ? path[path.length - 2] : null;
35
+
36
+ const isFilterEntry = grandParentKey === "filters";
37
+
38
+ if (isFilterEntry) {
39
+ for (const k of Object.getOwnPropertyNames(obj)) {
40
+ if (k === "value") continue; // laisser value libre
41
+ selectiveDeepFreeze(obj[k], path.concat(parentKey, k));
42
+ }
43
+ return lockAllBut(obj, ["value"]);
44
+ }
45
+
46
+ for (const prop of Object.getOwnPropertyNames(obj)) {
47
+ selectiveDeepFreeze(obj[prop], path.concat(prop));
48
+ }
49
+ return Object.freeze(obj);
50
+ };
13
51
 
14
52
  const data = {
15
53
  "_defaults": {
@@ -350,6 +388,6 @@ const data = {
350
388
  }
351
389
  };
352
390
 
353
- var projects = deepFreeze(data);
391
+ var projects = selectiveDeepFreeze(data);
354
392
 
355
393
  export { projects as default };
@@ -1,17 +1,55 @@
1
1
  'use strict';
2
2
 
3
3
  // Deep freeze utility to make exports immutable
4
- const deepFreeze = (obj) => {
5
- Object.freeze(obj);
6
- Object.getOwnPropertyNames(obj).forEach(prop => {
7
- if (obj[prop] !== null
8
- && (typeof obj[prop] === "object" || typeof obj[prop] === "function")
9
- && !Object.isFrozen(obj[prop])) {
10
- deepFreeze(obj[prop]);
4
+ const lockAllBut = (obj, mutableKeys = []) => {
5
+ for (const key of Object.getOwnPropertyNames(obj)) {
6
+ if (mutableKeys.includes(key)) continue;
7
+
8
+ const desc = Object.getOwnPropertyDescriptor(obj, key);
9
+ if (!desc) continue;
10
+
11
+ if ("value" in desc) {
12
+ Object.defineProperty(obj, key, {
13
+ ...desc,
14
+ writable: false,
15
+ configurable: false,
16
+ });
17
+ } else {
18
+ Object.defineProperty(obj, key, {
19
+ ...desc,
20
+ configurable: false,
21
+ });
11
22
  }
12
- });
23
+ }
24
+ Object.preventExtensions(obj);
13
25
  return obj;
14
26
  };
27
+ const selectiveDeepFreeze = (obj, path = []) => {
28
+ if (obj === null || typeof obj !== "object") return obj;
29
+
30
+ if (Array.isArray(obj)) {
31
+ obj.forEach((v, i) => selectiveDeepFreeze(v, path.concat(String(i))));
32
+ return Object.freeze(obj);
33
+ }
34
+
35
+ const parentKey = path.length >= 1 ? path[path.length - 1] : null;
36
+ const grandParentKey = path.length >= 2 ? path[path.length - 2] : null;
37
+
38
+ const isFilterEntry = grandParentKey === "filters";
39
+
40
+ if (isFilterEntry) {
41
+ for (const k of Object.getOwnPropertyNames(obj)) {
42
+ if (k === "value") continue; // laisser value libre
43
+ selectiveDeepFreeze(obj[k], path.concat(parentKey, k));
44
+ }
45
+ return lockAllBut(obj, ["value"]);
46
+ }
47
+
48
+ for (const prop of Object.getOwnPropertyNames(obj)) {
49
+ selectiveDeepFreeze(obj[prop], path.concat(prop));
50
+ }
51
+ return Object.freeze(obj);
52
+ };
15
53
 
16
54
  const data = {
17
55
  "_defaults": {
@@ -378,6 +416,6 @@ const data = {
378
416
  }
379
417
  };
380
418
 
381
- var publications = deepFreeze(data);
419
+ var publications = selectiveDeepFreeze(data);
382
420
 
383
421
  module.exports = publications;
@@ -1,15 +1,53 @@
1
1
  // Deep freeze utility to make exports immutable
2
- const deepFreeze = (obj) => {
3
- Object.freeze(obj);
4
- Object.getOwnPropertyNames(obj).forEach(prop => {
5
- if (obj[prop] !== null
6
- && (typeof obj[prop] === "object" || typeof obj[prop] === "function")
7
- && !Object.isFrozen(obj[prop])) {
8
- deepFreeze(obj[prop]);
2
+ const lockAllBut = (obj, mutableKeys = []) => {
3
+ for (const key of Object.getOwnPropertyNames(obj)) {
4
+ if (mutableKeys.includes(key)) continue;
5
+
6
+ const desc = Object.getOwnPropertyDescriptor(obj, key);
7
+ if (!desc) continue;
8
+
9
+ if ("value" in desc) {
10
+ Object.defineProperty(obj, key, {
11
+ ...desc,
12
+ writable: false,
13
+ configurable: false,
14
+ });
15
+ } else {
16
+ Object.defineProperty(obj, key, {
17
+ ...desc,
18
+ configurable: false,
19
+ });
9
20
  }
10
- });
21
+ }
22
+ Object.preventExtensions(obj);
11
23
  return obj;
12
24
  };
25
+ const selectiveDeepFreeze = (obj, path = []) => {
26
+ if (obj === null || typeof obj !== "object") return obj;
27
+
28
+ if (Array.isArray(obj)) {
29
+ obj.forEach((v, i) => selectiveDeepFreeze(v, path.concat(String(i))));
30
+ return Object.freeze(obj);
31
+ }
32
+
33
+ const parentKey = path.length >= 1 ? path[path.length - 1] : null;
34
+ const grandParentKey = path.length >= 2 ? path[path.length - 2] : null;
35
+
36
+ const isFilterEntry = grandParentKey === "filters";
37
+
38
+ if (isFilterEntry) {
39
+ for (const k of Object.getOwnPropertyNames(obj)) {
40
+ if (k === "value") continue; // laisser value libre
41
+ selectiveDeepFreeze(obj[k], path.concat(parentKey, k));
42
+ }
43
+ return lockAllBut(obj, ["value"]);
44
+ }
45
+
46
+ for (const prop of Object.getOwnPropertyNames(obj)) {
47
+ selectiveDeepFreeze(obj[prop], path.concat(prop));
48
+ }
49
+ return Object.freeze(obj);
50
+ };
13
51
 
14
52
  const data = {
15
53
  "_defaults": {
@@ -376,6 +414,6 @@ const data = {
376
414
  }
377
415
  };
378
416
 
379
- var publications = deepFreeze(data);
417
+ var publications = selectiveDeepFreeze(data);
380
418
 
381
419
  export { publications as default };
@@ -1,17 +1,55 @@
1
1
  'use strict';
2
2
 
3
3
  // Deep freeze utility to make exports immutable
4
- const deepFreeze = (obj) => {
5
- Object.freeze(obj);
6
- Object.getOwnPropertyNames(obj).forEach(prop => {
7
- if (obj[prop] !== null
8
- && (typeof obj[prop] === "object" || typeof obj[prop] === "function")
9
- && !Object.isFrozen(obj[prop])) {
10
- deepFreeze(obj[prop]);
4
+ const lockAllBut = (obj, mutableKeys = []) => {
5
+ for (const key of Object.getOwnPropertyNames(obj)) {
6
+ if (mutableKeys.includes(key)) continue;
7
+
8
+ const desc = Object.getOwnPropertyDescriptor(obj, key);
9
+ if (!desc) continue;
10
+
11
+ if ("value" in desc) {
12
+ Object.defineProperty(obj, key, {
13
+ ...desc,
14
+ writable: false,
15
+ configurable: false,
16
+ });
17
+ } else {
18
+ Object.defineProperty(obj, key, {
19
+ ...desc,
20
+ configurable: false,
21
+ });
11
22
  }
12
- });
23
+ }
24
+ Object.preventExtensions(obj);
13
25
  return obj;
14
26
  };
27
+ const selectiveDeepFreeze = (obj, path = []) => {
28
+ if (obj === null || typeof obj !== "object") return obj;
29
+
30
+ if (Array.isArray(obj)) {
31
+ obj.forEach((v, i) => selectiveDeepFreeze(v, path.concat(String(i))));
32
+ return Object.freeze(obj);
33
+ }
34
+
35
+ const parentKey = path.length >= 1 ? path[path.length - 1] : null;
36
+ const grandParentKey = path.length >= 2 ? path[path.length - 2] : null;
37
+
38
+ const isFilterEntry = grandParentKey === "filters";
39
+
40
+ if (isFilterEntry) {
41
+ for (const k of Object.getOwnPropertyNames(obj)) {
42
+ if (k === "value") continue; // laisser value libre
43
+ selectiveDeepFreeze(obj[k], path.concat(parentKey, k));
44
+ }
45
+ return lockAllBut(obj, ["value"]);
46
+ }
47
+
48
+ for (const prop of Object.getOwnPropertyNames(obj)) {
49
+ selectiveDeepFreeze(obj[prop], path.concat(prop));
50
+ }
51
+ return Object.freeze(obj);
52
+ };
15
53
 
16
54
  const data = {
17
55
  "_defaults": {
@@ -52,6 +90,6 @@ const data = {
52
90
  }
53
91
  };
54
92
 
55
- var tags = deepFreeze(data);
93
+ var tags = selectiveDeepFreeze(data);
56
94
 
57
95
  module.exports = tags;
package/dist/form/tags.js CHANGED
@@ -1,15 +1,53 @@
1
1
  // Deep freeze utility to make exports immutable
2
- const deepFreeze = (obj) => {
3
- Object.freeze(obj);
4
- Object.getOwnPropertyNames(obj).forEach(prop => {
5
- if (obj[prop] !== null
6
- && (typeof obj[prop] === "object" || typeof obj[prop] === "function")
7
- && !Object.isFrozen(obj[prop])) {
8
- deepFreeze(obj[prop]);
2
+ const lockAllBut = (obj, mutableKeys = []) => {
3
+ for (const key of Object.getOwnPropertyNames(obj)) {
4
+ if (mutableKeys.includes(key)) continue;
5
+
6
+ const desc = Object.getOwnPropertyDescriptor(obj, key);
7
+ if (!desc) continue;
8
+
9
+ if ("value" in desc) {
10
+ Object.defineProperty(obj, key, {
11
+ ...desc,
12
+ writable: false,
13
+ configurable: false,
14
+ });
15
+ } else {
16
+ Object.defineProperty(obj, key, {
17
+ ...desc,
18
+ configurable: false,
19
+ });
9
20
  }
10
- });
21
+ }
22
+ Object.preventExtensions(obj);
11
23
  return obj;
12
24
  };
25
+ const selectiveDeepFreeze = (obj, path = []) => {
26
+ if (obj === null || typeof obj !== "object") return obj;
27
+
28
+ if (Array.isArray(obj)) {
29
+ obj.forEach((v, i) => selectiveDeepFreeze(v, path.concat(String(i))));
30
+ return Object.freeze(obj);
31
+ }
32
+
33
+ const parentKey = path.length >= 1 ? path[path.length - 1] : null;
34
+ const grandParentKey = path.length >= 2 ? path[path.length - 2] : null;
35
+
36
+ const isFilterEntry = grandParentKey === "filters";
37
+
38
+ if (isFilterEntry) {
39
+ for (const k of Object.getOwnPropertyNames(obj)) {
40
+ if (k === "value") continue; // laisser value libre
41
+ selectiveDeepFreeze(obj[k], path.concat(parentKey, k));
42
+ }
43
+ return lockAllBut(obj, ["value"]);
44
+ }
45
+
46
+ for (const prop of Object.getOwnPropertyNames(obj)) {
47
+ selectiveDeepFreeze(obj[prop], path.concat(prop));
48
+ }
49
+ return Object.freeze(obj);
50
+ };
13
51
 
14
52
  const data = {
15
53
  "_defaults": {
@@ -50,6 +88,6 @@ const data = {
50
88
  }
51
89
  };
52
90
 
53
- var tags = deepFreeze(data);
91
+ var tags = selectiveDeepFreeze(data);
54
92
 
55
93
  export { tags as default };
@@ -1,17 +1,55 @@
1
1
  'use strict';
2
2
 
3
3
  // Deep freeze utility to make exports immutable
4
- const deepFreeze = (obj) => {
5
- Object.freeze(obj);
6
- Object.getOwnPropertyNames(obj).forEach(prop => {
7
- if (obj[prop] !== null
8
- && (typeof obj[prop] === "object" || typeof obj[prop] === "function")
9
- && !Object.isFrozen(obj[prop])) {
10
- deepFreeze(obj[prop]);
4
+ const lockAllBut = (obj, mutableKeys = []) => {
5
+ for (const key of Object.getOwnPropertyNames(obj)) {
6
+ if (mutableKeys.includes(key)) continue;
7
+
8
+ const desc = Object.getOwnPropertyDescriptor(obj, key);
9
+ if (!desc) continue;
10
+
11
+ if ("value" in desc) {
12
+ Object.defineProperty(obj, key, {
13
+ ...desc,
14
+ writable: false,
15
+ configurable: false,
16
+ });
17
+ } else {
18
+ Object.defineProperty(obj, key, {
19
+ ...desc,
20
+ configurable: false,
21
+ });
11
22
  }
12
- });
23
+ }
24
+ Object.preventExtensions(obj);
13
25
  return obj;
14
26
  };
27
+ const selectiveDeepFreeze = (obj, path = []) => {
28
+ if (obj === null || typeof obj !== "object") return obj;
29
+
30
+ if (Array.isArray(obj)) {
31
+ obj.forEach((v, i) => selectiveDeepFreeze(v, path.concat(String(i))));
32
+ return Object.freeze(obj);
33
+ }
34
+
35
+ const parentKey = path.length >= 1 ? path[path.length - 1] : null;
36
+ const grandParentKey = path.length >= 2 ? path[path.length - 2] : null;
37
+
38
+ const isFilterEntry = grandParentKey === "filters";
39
+
40
+ if (isFilterEntry) {
41
+ for (const k of Object.getOwnPropertyNames(obj)) {
42
+ if (k === "value") continue; // laisser value libre
43
+ selectiveDeepFreeze(obj[k], path.concat(parentKey, k));
44
+ }
45
+ return lockAllBut(obj, ["value"]);
46
+ }
47
+
48
+ for (const prop of Object.getOwnPropertyNames(obj)) {
49
+ selectiveDeepFreeze(obj[prop], path.concat(prop));
50
+ }
51
+ return Object.freeze(obj);
52
+ };
15
53
 
16
54
  const data = {
17
55
  "_defaults": {
@@ -590,6 +628,6 @@ const data = {
590
628
  }
591
629
  };
592
630
 
593
- var users = deepFreeze(data);
631
+ var users = selectiveDeepFreeze(data);
594
632
 
595
633
  module.exports = users;