@jahia/data-helper 1.0.5 → 1.0.7

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 (61) hide show
  1. package/esm/fragments/PredefinedFragments.js +21 -221
  2. package/esm/fragments/fragments.utils.js +17 -43
  3. package/esm/fragments/getIsNodeTypeFragment.js +2 -15
  4. package/esm/fragments/getPermissionFragment.js +3 -28
  5. package/esm/hooks/useContentPreview/useContentPreview.gql-queries.js +2 -12
  6. package/esm/hooks/useContentPreview/useContentPreview.js +7 -7
  7. package/esm/hooks/useDeepCompareMemo/useDeepCompareMemo.js +0 -2
  8. package/esm/hooks/useDeepCompareMemo/useDeepCompareMemo.spec.js +0 -1
  9. package/esm/hooks/useNodeChecks/useNodeChecks.js +13 -28
  10. package/esm/hooks/useNodeChecks/useNodeChecks.spec.js +156 -67
  11. package/esm/hooks/useNodeInfo/useMemoRequest.js +49 -0
  12. package/esm/hooks/useNodeInfo/useNodeInfo.gql-queries.js +23 -104
  13. package/esm/hooks/useNodeInfo/useNodeInfo.js +139 -57
  14. package/esm/hooks/useNodeInfo/useNodeInfo.spec.js +429 -233
  15. package/esm/hooks/useNodeInfo/useNodeInfo.utils.js +52 -0
  16. package/esm/hooks/useSchemaFields/useSchemaFields.gql-queries.js +2 -12
  17. package/esm/hooks/useSiteInfo/useSiteInfo.gql-queries.js +2 -12
  18. package/esm/hooks/useSiteInfo/useSiteInfo.js +2 -9
  19. package/esm/hooks/useTreeEntries/useTreeEntries.gql-queries.js +2 -12
  20. package/esm/hooks/useTreeEntries/useTreeEntries.js +18 -40
  21. package/esm/legacy/Picker.gql-fragments.js +4 -34
  22. package/esm/legacy/Picker.js +31 -113
  23. package/js/fragments/PredefinedFragments.js +21 -224
  24. package/js/fragments/encodeName.js +0 -2
  25. package/js/fragments/fragments.utils.js +17 -44
  26. package/js/fragments/getIsNodeTypeFragment.js +2 -23
  27. package/js/fragments/getPermissionFragment.js +3 -38
  28. package/js/fragments/index.js +0 -4
  29. package/js/hooks/index.js +0 -10
  30. package/js/hooks/useContentPreview/index.js +0 -2
  31. package/js/hooks/useContentPreview/useContentPreview.gql-queries.js +2 -16
  32. package/js/hooks/useContentPreview/useContentPreview.js +7 -11
  33. package/js/hooks/useContentPreview/useContentPreview.spec.js +0 -2
  34. package/js/hooks/useDeepCompareMemo/index.js +0 -2
  35. package/js/hooks/useDeepCompareMemo/useDeepCompareMemo.js +0 -7
  36. package/js/hooks/useDeepCompareMemo/useDeepCompareMemo.spec.js +0 -2
  37. package/js/hooks/useNodeChecks/index.js +0 -2
  38. package/js/hooks/useNodeChecks/useNodeChecks.js +13 -30
  39. package/js/hooks/useNodeChecks/useNodeChecks.spec.js +157 -69
  40. package/js/hooks/useNodeInfo/index.js +0 -2
  41. package/js/hooks/useNodeInfo/useMemoRequest.js +56 -0
  42. package/js/hooks/useNodeInfo/useNodeInfo.gql-queries.js +25 -111
  43. package/js/hooks/useNodeInfo/useNodeInfo.js +139 -65
  44. package/js/hooks/useNodeInfo/useNodeInfo.spec.js +430 -236
  45. package/js/hooks/useNodeInfo/useNodeInfo.utils.js +60 -0
  46. package/js/hooks/useSchemaFields/index.js +0 -2
  47. package/js/hooks/useSchemaFields/useSchemaFields.gql-queries.js +2 -15
  48. package/js/hooks/useSchemaFields/useSchemaFields.jsx +0 -4
  49. package/js/hooks/useSiteInfo/index.js +0 -2
  50. package/js/hooks/useSiteInfo/useSiteInfo.gql-queries.js +2 -16
  51. package/js/hooks/useSiteInfo/useSiteInfo.js +2 -12
  52. package/js/hooks/useSiteInfo/useSiteInfo.spec.js +0 -4
  53. package/js/hooks/useTreeEntries/index.js +0 -2
  54. package/js/hooks/useTreeEntries/useTreeEntries.gql-queries.js +2 -16
  55. package/js/hooks/useTreeEntries/useTreeEntries.js +18 -46
  56. package/js/hooks/useTreeEntries/useTreeEntries.spec.js +0 -3
  57. package/js/index.js +0 -6
  58. package/js/legacy/Picker.gql-fragments.js +4 -37
  59. package/js/legacy/Picker.js +31 -134
  60. package/js/legacy/index.js +0 -4
  61. package/package.json +1 -1
@@ -1,20 +1,58 @@
1
1
  "use strict";
2
2
 
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
3
4
  var _index = require("./index.js");
4
-
5
5
  var _reactApollo = require("react-apollo");
6
-
6
+ var _react = _interopRequireDefault(require("react"));
7
+ var _useNodeInfo = require("../useNodeInfo/useNodeInfo.gql-queries");
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
10
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
11
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
12
+ var wait = function wait() {
13
+ var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1000;
14
+ return new Promise(function (resolve) {
15
+ setTimeout(resolve, time);
16
+ });
17
+ };
7
18
  jest.mock('react-apollo', function () {
19
+ var data = {
20
+ data: {
21
+ jcr: {
22
+ nodeByPath: {
23
+ resourceChildren: {
24
+ nodes: []
25
+ },
26
+ site: {}
27
+ }
28
+ }
29
+ },
30
+ loading: false,
31
+ error: null
32
+ };
8
33
  return {
9
34
  useQuery: jest.fn(function () {
35
+ return data;
36
+ }),
37
+ useApolloClient: jest.fn(function () {
10
38
  return {
11
- data: {
12
- jcr: {
13
- nodeByPath: {}
14
- }
39
+ query: function query() {
40
+ return {
41
+ then: function then(inputFcn) {
42
+ return inputFcn(data);
43
+ }
44
+ };
15
45
  },
16
- loading: false,
17
- error: null
46
+ watchQuery: function watchQuery() {
47
+ return {
48
+ subscribe: function subscribe(inputFcn) {
49
+ inputFcn(data);
50
+ return {
51
+ unsubscribe: function unsubscribe() {}
52
+ };
53
+ }
54
+ };
55
+ }
18
56
  };
19
57
  })
20
58
  };
@@ -26,78 +64,128 @@ jest.mock('react', function () {
26
64
  if (!current) {
27
65
  current = v;
28
66
  }
29
-
30
67
  return {
31
68
  current: current
32
69
  };
33
70
  },
34
71
  useMemo: function useMemo(v) {
35
72
  return v();
73
+ },
74
+ useState: function useState(v) {
75
+ return v;
76
+ },
77
+ useEffect: function useEffect(v) {
78
+ return v();
36
79
  }
37
80
  };
38
81
  });
82
+ jest.mock('../useNodeInfo/useNodeInfo.gql-queries', function () {
83
+ var original = jest.requireActual('../useNodeInfo/useNodeInfo.gql-queries');
84
+ return {
85
+ getQuery: jest.fn(original.getQuery),
86
+ validOptions: original.validOptions
87
+ };
88
+ });
39
89
  describe('useNodeChecks', function () {
40
90
  beforeEach(function () {
41
91
  jest.restoreAllMocks();
42
92
  });
43
- it('should request permissions', function () {
44
- (0, _index.useNodeChecks)({
45
- path: '/test',
46
- language: 'en'
47
- }, {
48
- requiredPermission: ['canRead', 'canWrite']
49
- });
50
- expect(_reactApollo.useQuery).toHaveBeenCalled();
51
- var mock = _reactApollo.useQuery.mock;
52
- var call = mock.calls[mock.calls.length - 1];
53
- var variables = call[1].variables;
54
- call[0].definitions[0].variableDefinitions.map(function (v) {
55
- return v.variable.name.value;
56
- }).forEach(function (v) {
57
- return expect(Object.keys(variables)).toContain(v);
58
- });
59
- expect(call[0].definitions.map(function (d) {
60
- return d.name.value;
61
- })).toContain('NodePermission_permission_encoded_Y2FuUmVhZA');
62
- expect(call[0].definitions.find(function (d) {
63
- return d.name.value === 'NodePermission_permission_encoded_Y2FuUmVhZA';
64
- }).selectionSet.selections.map(function (m) {
65
- return m.alias.value;
66
- })).toContain('permission_encoded_Y2FuUmVhZA');
67
- expect(call[0].definitions.find(function (d) {
68
- return d.name.value === 'NodePermission_permission_encoded_Y2FuV3JpdGU';
69
- }).selectionSet.selections.map(function (m) {
70
- return m.alias.value;
71
- })).toContain('permission_encoded_Y2FuV3JpdGU');
72
- });
73
- it('should request site permissions', function () {
74
- (0, _index.useNodeChecks)({
75
- path: '/test',
76
- language: 'en'
77
- }, {
78
- requiredPermission: ['canRead', 'canWrite']
79
- });
80
- expect(_reactApollo.useQuery).toHaveBeenCalled();
81
- var mock = _reactApollo.useQuery.mock;
82
- var call = mock.calls[mock.calls.length - 1];
83
- var variables = call[1].variables;
84
- call[0].definitions[0].variableDefinitions.map(function (v) {
85
- return v.variable.name.value;
86
- }).forEach(function (v) {
87
- return expect(Object.keys(variables)).toContain(v);
88
- });
89
- expect(call[0].definitions.map(function (d) {
90
- return d.name.value;
91
- })).toContain('NodePermission_permission_encoded_Y2FuUmVhZA');
92
- expect(call[0].definitions.find(function (d) {
93
- return d.name.value === 'NodePermission_permission_encoded_Y2FuUmVhZA';
94
- }).selectionSet.selections.map(function (m) {
95
- return m.alias.value;
96
- })).toContain('permission_encoded_Y2FuUmVhZA');
97
- expect(call[0].definitions.find(function (d) {
98
- return d.name.value === 'NodePermission_permission_encoded_Y2FuV3JpdGU';
99
- }).selectionSet.selections.map(function (m) {
100
- return m.alias.value;
101
- })).toContain('permission_encoded_Y2FuV3JpdGU');
102
- });
93
+ it('should request permissions', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
94
+ var setStateMock, useStateMock, mock, result, variables;
95
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
96
+ while (1) {
97
+ switch (_context.prev = _context.next) {
98
+ case 0:
99
+ setStateMock = jest.fn();
100
+ useStateMock = function useStateMock(useState) {
101
+ return [useState, setStateMock];
102
+ };
103
+ jest.spyOn(_react["default"], 'useState').mockImplementation(useStateMock);
104
+ (0, _index.useNodeChecks)({
105
+ path: '/test',
106
+ language: 'en'
107
+ }, {
108
+ requiredPermission: ['canRead', 'canWrite']
109
+ });
110
+ _context.next = 6;
111
+ return wait();
112
+ case 6:
113
+ expect(_useNodeInfo.getQuery).toHaveBeenCalled();
114
+ mock = _useNodeInfo.getQuery.mock;
115
+ result = mock.results[mock.results.length - 1];
116
+ variables = result.value.generatedVariables;
117
+ result.value.query.definitions[0].variableDefinitions.map(function (v) {
118
+ return v.variable.name.value;
119
+ }).forEach(function (v) {
120
+ return expect(Object.keys(variables)).toContain(v);
121
+ });
122
+ expect(result.value.query.definitions.map(function (d) {
123
+ return d.name.value;
124
+ })).toContain('NodePermission_permission_encoded_Y2FuUmVhZA');
125
+ expect(result.value.query.definitions.find(function (d) {
126
+ return d.name.value === 'NodePermission_permission_encoded_Y2FuUmVhZA';
127
+ }).selectionSet.selections.map(function (m) {
128
+ return m.alias.value;
129
+ })).toContain('permission_encoded_Y2FuUmVhZA');
130
+ expect(result.value.query.definitions.find(function (d) {
131
+ return d.name.value === 'NodePermission_permission_encoded_Y2FuV3JpdGU';
132
+ }).selectionSet.selections.map(function (m) {
133
+ return m.alias.value;
134
+ })).toContain('permission_encoded_Y2FuV3JpdGU');
135
+ case 14:
136
+ case "end":
137
+ return _context.stop();
138
+ }
139
+ }
140
+ }, _callee);
141
+ })));
142
+ it('should request site permissions', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
143
+ var setStateMock, useStateMock, mock, result, variables;
144
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
145
+ while (1) {
146
+ switch (_context2.prev = _context2.next) {
147
+ case 0:
148
+ setStateMock = jest.fn();
149
+ useStateMock = function useStateMock(useState) {
150
+ return [useState, setStateMock];
151
+ };
152
+ jest.spyOn(_react["default"], 'useState').mockImplementation(useStateMock);
153
+ (0, _index.useNodeChecks)({
154
+ path: '/test',
155
+ language: 'en'
156
+ }, {
157
+ requiredPermission: ['canRead', 'canWrite']
158
+ });
159
+ _context2.next = 6;
160
+ return wait();
161
+ case 6:
162
+ expect(_useNodeInfo.getQuery).toHaveBeenCalled();
163
+ mock = _useNodeInfo.getQuery.mock;
164
+ result = mock.results[mock.results.length - 1];
165
+ variables = result.value.generatedVariables;
166
+ result.value.query.definitions[0].variableDefinitions.map(function (v) {
167
+ return v.variable.name.value;
168
+ }).forEach(function (v) {
169
+ return expect(Object.keys(variables)).toContain(v);
170
+ });
171
+ expect(result.value.query.definitions.map(function (d) {
172
+ return d.name.value;
173
+ })).toContain('NodePermission_permission_encoded_Y2FuUmVhZA');
174
+ expect(result.value.query.definitions.find(function (d) {
175
+ return d.name.value === 'NodePermission_permission_encoded_Y2FuUmVhZA';
176
+ }).selectionSet.selections.map(function (m) {
177
+ return m.alias.value;
178
+ })).toContain('permission_encoded_Y2FuUmVhZA');
179
+ expect(result.value.query.definitions.find(function (d) {
180
+ return d.name.value === 'NodePermission_permission_encoded_Y2FuV3JpdGU';
181
+ }).selectionSet.selections.map(function (m) {
182
+ return m.alias.value;
183
+ })).toContain('permission_encoded_Y2FuV3JpdGU');
184
+ case 14:
185
+ case "end":
186
+ return _context2.stop();
187
+ }
188
+ }
189
+ }, _callee2);
190
+ })));
103
191
  });
@@ -3,9 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
6
  var _useNodeInfo = require("./useNodeInfo");
8
-
9
7
  Object.keys(_useNodeInfo).forEach(function (key) {
10
8
  if (key === "default" || key === "__esModule") return;
11
9
  if (key in exports && exports[key] === _useNodeInfo[key]) return;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useMemoRequest = useMemoRequest;
7
+ var _useNodeInfo = require("./useNodeInfo.gql-queries");
8
+ var _react = require("react");
9
+ var _fastDeepEqual = _interopRequireDefault(require("fast-deep-equal"));
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
12
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
13
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
14
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
15
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
16
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
17
+ var clean = function clean(obj) {
18
+ return obj && Object.fromEntries(Object.entries(obj).filter(function (_ref) {
19
+ var _ref2 = _slicedToArray(_ref, 2),
20
+ _ = _ref2[0],
21
+ v = _ref2[1];
22
+ return v !== null && v !== undefined;
23
+ }));
24
+ };
25
+ var cleanVariables = function cleanVariables(obj) {
26
+ return obj && Object.fromEntries(Object.entries(obj).filter(function (_ref3) {
27
+ var _ref4 = _slicedToArray(_ref3, 2),
28
+ _ = _ref4[0],
29
+ v = _ref4[1];
30
+ return v !== null && v !== undefined;
31
+ }));
32
+ };
33
+ var cleanOptions = function cleanOptions(obj) {
34
+ return obj && Object.fromEntries(Object.entries(obj).filter(function (_ref5) {
35
+ var _ref6 = _slicedToArray(_ref5, 2),
36
+ k = _ref6[0],
37
+ v = _ref6[1];
38
+ return v !== null && v !== undefined && _useNodeInfo.validOptions.indexOf(k) !== -1;
39
+ }));
40
+ };
41
+ function useMemoRequest(variables, queryOptions, options, setResult) {
42
+ variables = cleanVariables(variables);
43
+ queryOptions = clean(queryOptions);
44
+ options = cleanOptions(options);
45
+ var requestValue = {
46
+ variables: variables,
47
+ queryOptions: queryOptions,
48
+ options: options,
49
+ setResult: setResult
50
+ };
51
+ var requestRef = (0, _react.useRef)(requestValue);
52
+ if (!(0, _fastDeepEqual["default"])(variables, requestRef.current.variables) || !(0, _fastDeepEqual["default"])(queryOptions, requestRef.current.queryOptions) || !(0, _fastDeepEqual["default"])(options, requestRef.current.options)) {
53
+ requestRef.current = requestValue;
54
+ }
55
+ return [requestRef.current, requestRef.current === requestValue];
56
+ }
@@ -3,127 +3,69 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getQuery = void 0;
7
-
6
+ exports.validOptions = exports.getQuery = void 0;
8
7
  var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
9
-
10
8
  var _fragments = require("../../fragments");
11
-
12
9
  var _getPermissionFragment = require("../../fragments/getPermissionFragment");
13
-
14
10
  var _getIsNodeTypeFragment = require("../../fragments/getIsNodeTypeFragment");
15
-
11
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4;
16
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
17
-
18
- function _templateObject4() {
19
- var data = _taggedTemplateLiteral(["\n query NodeByPathInfoQuery($path:String!) {\n jcr {\n nodeByPath(path:$path) {\n name\n ...node\n ...NodeCacheRequiredFields\n }\n }\n }\n ", "\n "]);
20
-
21
- _templateObject4 = function _templateObject4() {
22
- return data;
23
- };
24
-
25
- return data;
26
- }
27
-
28
- function _templateObject3() {
29
- var data = _taggedTemplateLiteral(["\n query NodesByUuidInfoQuery($uuids:[String!]!) {\n jcr {\n nodesById(uuids:$uuids) {\n name\n ...node\n ...NodeCacheRequiredFields\n }\n }\n }\n ", "\n "]);
30
-
31
- _templateObject3 = function _templateObject3() {
32
- return data;
33
- };
34
-
35
- return data;
36
- }
37
-
38
- function _templateObject2() {
39
- var data = _taggedTemplateLiteral(["\n query NodeByUuidInfoQuery($uuid:String!) {\n jcr {\n nodeById(uuid:$uuid) {\n name\n ...node\n ...NodeCacheRequiredFields\n }\n }\n }\n ", "\n "]);
40
-
41
- _templateObject2 = function _templateObject2() {
42
- return data;
43
- };
44
-
45
- return data;
46
- }
47
-
48
- function _templateObject() {
49
- var data = _taggedTemplateLiteral(["\n query NodesByPathInfoQuery($paths:[String!]!) {\n jcr {\n nodesByPath(paths:$paths) {\n name\n ...node\n ...NodeCacheRequiredFields\n }\n }\n }\n ", "\n "]);
50
-
51
- _templateObject = function _templateObject() {
52
- return data;
53
- };
54
-
55
- return data;
56
- }
57
-
58
13
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
59
-
60
14
  var getBaseQueryAndVariables = function getBaseQueryAndVariables(variables) {
61
15
  if (variables.paths) {
62
16
  return {
63
- baseQuery: (0, _graphqlTag["default"])(_templateObject(), _fragments.nodeCacheRequiredFields.gql),
17
+ baseQuery: (0, _graphqlTag["default"])(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n query NodesByPathInfoQuery($paths:[String!]!) {\n jcr {\n nodesByPath(paths:$paths) {\n name\n ...node\n ...NodeCacheRequiredFields\n }\n }\n }\n ", "\n "])), _fragments.nodeCacheRequiredFields.gql),
64
18
  generatedVariables: {
65
19
  paths: variables.paths
66
20
  },
67
21
  skip: false
68
22
  };
69
23
  }
70
-
71
24
  if (variables.uuid && variables.uuid.length > 0) {
72
25
  return {
73
- baseQuery: (0, _graphqlTag["default"])(_templateObject2(), _fragments.nodeCacheRequiredFields.gql),
26
+ baseQuery: (0, _graphqlTag["default"])(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n query NodeByUuidInfoQuery($uuid:String!) {\n jcr {\n nodeById(uuid:$uuid) {\n name\n ...node\n ...NodeCacheRequiredFields\n }\n }\n }\n ", "\n "])), _fragments.nodeCacheRequiredFields.gql),
74
27
  generatedVariables: {
75
28
  uuid: variables.uuid
76
29
  },
77
30
  skip: false
78
31
  };
79
32
  }
80
-
81
33
  if (variables.uuids) {
82
34
  return {
83
- baseQuery: (0, _graphqlTag["default"])(_templateObject3(), _fragments.nodeCacheRequiredFields.gql),
35
+ baseQuery: (0, _graphqlTag["default"])(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n query NodesByUuidInfoQuery($uuids:[String!]!) {\n jcr {\n nodesById(uuids:$uuids) {\n name\n ...node\n ...NodeCacheRequiredFields\n }\n }\n }\n ", "\n "])), _fragments.nodeCacheRequiredFields.gql),
84
36
  generatedVariables: {
85
37
  uuids: variables.uuids
86
38
  },
87
39
  skip: false
88
40
  };
89
41
  }
90
-
91
42
  return {
92
- baseQuery: (0, _graphqlTag["default"])(_templateObject4(), _fragments.nodeCacheRequiredFields.gql),
43
+ baseQuery: (0, _graphqlTag["default"])(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n query NodeByPathInfoQuery($path:String!) {\n jcr {\n nodeByPath(path:$path) {\n name\n ...node\n ...NodeCacheRequiredFields\n }\n }\n }\n ", "\n "])), _fragments.nodeCacheRequiredFields.gql),
93
44
  generatedVariables: {
94
45
  path: variables.path
95
46
  },
96
47
  skip: !variables.path || variables.path.length === 0
97
48
  };
98
49
  };
99
-
50
+ var validOptions = ['getDisplayName', 'getPrimaryNodeType', 'getParent', 'getAggregatedPublicationInfo', 'getOperationSupport', 'getPermissions', 'getSitePermissions', 'getIsNodeTypes', 'getProperties', 'getSiteInstalledModules', 'getSiteLanguages', 'getDisplayableNodePath', 'getLockInfo', 'getChildNodeTypes', 'getContributeTypesRestrictions', 'getSubNodesCount', 'getMimeType'];
51
+ exports.validOptions = validOptions;
100
52
  var getQuery = function getQuery(variables, schemaResult) {
101
53
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
102
54
  var fragments = [];
103
-
104
55
  var _getBaseQueryAndVaria = getBaseQueryAndVariables(variables),
105
- baseQuery = _getBaseQueryAndVaria.baseQuery,
106
- generatedVariables = _getBaseQueryAndVaria.generatedVariables,
107
- skip = _getBaseQueryAndVaria.skip;
108
-
109
- var error = schemaResult.error,
110
- loading = schemaResult.loading,
111
- data = schemaResult.data;
112
-
56
+ baseQuery = _getBaseQueryAndVaria.baseQuery,
57
+ generatedVariables = _getBaseQueryAndVaria.generatedVariables,
58
+ skip = _getBaseQueryAndVaria.skip;
113
59
  if (!skip) {
114
60
  if (options.getDisplayName) {
115
61
  fragments.push(_fragments.displayName);
116
-
117
62
  if (!variables.language) {
118
63
  throw Error('language is required');
119
64
  }
120
-
121
65
  generatedVariables.language = variables.language;
122
66
  }
123
-
124
67
  if (options.getPrimaryNodeType) {
125
68
  fragments.push(_fragments.primaryNodeType);
126
-
127
69
  if (!variables.displayLanguage) {
128
70
  generatedVariables.displayLanguageSet = false;
129
71
  generatedVariables.displayLanguage = '';
@@ -132,121 +74,93 @@ var getQuery = function getQuery(variables, schemaResult) {
132
74
  generatedVariables.displayLanguage = variables.displayLanguage;
133
75
  }
134
76
  }
135
-
136
77
  if (options.getParent) {
137
78
  fragments.push(_fragments.parentNode);
138
79
  }
139
-
140
80
  if (options.getAggregatedPublicationInfo) {
141
- if (!error && !loading && data) {
142
- var supportsExistsInLive = data.__type && data.__type.fields && data.__type.fields.find(function (field) {
143
- return field.name === 'existsInLive';
144
- }) !== undefined;
145
-
146
- if (supportsExistsInLive) {
147
- fragments.push(_fragments.aggregatedPublicationInfoWithExistInLive);
148
- } else {
149
- fragments.push(_fragments.aggregatedPublicationInfo);
150
- }
81
+ var supportsExistsInLive = schemaResult && schemaResult.__type && schemaResult.__type.fields && schemaResult.__type.fields.find(function (field) {
82
+ return field.name === 'existsInLive';
83
+ }) !== undefined;
84
+ if (supportsExistsInLive) {
85
+ fragments.push(_fragments.aggregatedPublicationInfoWithExistInLive);
86
+ } else {
87
+ fragments.push(_fragments.aggregatedPublicationInfo);
151
88
  }
152
-
153
89
  if (!variables.language) {
154
90
  throw Error('language is required');
155
91
  }
156
-
157
92
  generatedVariables.language = variables.language;
158
93
  generatedVariables.aggregatedPublicationInfoSubNodes = Boolean(options.getAggregatedPublicationInfo.subNodes);
159
94
  generatedVariables.aggregatedPublicationInfoIncludeReference = Boolean(options.getAggregatedPublicationInfo.reference);
160
95
  }
161
-
162
96
  if (options.getOperationSupport) {
163
97
  fragments.push(_fragments.operationSupport);
164
98
  }
165
-
166
99
  if (options.getPermissions) {
167
100
  options.getPermissions.forEach(function (name) {
168
101
  var _getPermissionFragmen = (0, _getPermissionFragment.getPermissionFragment)(name),
169
- fragment = _getPermissionFragmen.fragment,
170
- variables = _getPermissionFragmen.variables;
171
-
102
+ fragment = _getPermissionFragmen.fragment,
103
+ variables = _getPermissionFragmen.variables;
172
104
  fragments.push(fragment);
173
105
  Object.assign(generatedVariables, variables);
174
106
  });
175
107
  }
176
-
177
108
  if (options.getSitePermissions) {
178
109
  options.getSitePermissions.forEach(function (name) {
179
110
  var _getSitePermissionFra = (0, _getPermissionFragment.getSitePermissionFragment)(name),
180
- fragment = _getSitePermissionFra.fragment,
181
- variables = _getSitePermissionFra.variables;
182
-
111
+ fragment = _getSitePermissionFra.fragment,
112
+ variables = _getSitePermissionFra.variables;
183
113
  fragments.push(fragment);
184
114
  Object.assign(generatedVariables, variables);
185
115
  });
186
116
  }
187
-
188
117
  if (options.getIsNodeTypes) {
189
118
  options.getIsNodeTypes.forEach(function (name) {
190
119
  var _getNodeTypeFragment = (0, _getIsNodeTypeFragment.getNodeTypeFragment)(name),
191
- fragment = _getNodeTypeFragment.fragment,
192
- variables = _getNodeTypeFragment.variables;
193
-
120
+ fragment = _getNodeTypeFragment.fragment,
121
+ variables = _getNodeTypeFragment.variables;
194
122
  fragments.push(fragment);
195
123
  Object.assign(generatedVariables, variables);
196
124
  });
197
125
  }
198
-
199
126
  if (options.getProperties) {
200
127
  fragments.push(_fragments.getProperties);
201
128
  generatedVariables.getPropertiesNames = options.getProperties;
202
-
203
129
  if (!variables.language) {
204
130
  throw Error('language is required');
205
131
  }
206
-
207
132
  generatedVariables.language = variables.language;
208
133
  }
209
-
210
134
  if (options.getSiteInstalledModules) {
211
135
  fragments.push(_fragments.installedModules);
212
136
  }
213
-
214
137
  if (options.getSiteLanguages) {
215
138
  fragments.push(_fragments.siteLanguages);
216
139
  }
217
-
218
140
  if (options.getDisplayableNodePath) {
219
141
  fragments.push(_fragments.displayableNode);
220
142
  }
221
-
222
143
  if (options.getLockInfo) {
223
144
  fragments.push(_fragments.lockInfo);
224
145
  }
225
-
226
146
  if (options.getChildNodeTypes) {
227
147
  fragments.push(_fragments.childNodeTypes);
228
148
  }
229
-
230
149
  if (options.getContributeTypesRestrictions) {
231
150
  fragments.push(_fragments.contentRestrictions);
232
151
  }
233
-
234
152
  if (options.getSubNodesCount) {
235
153
  fragments.push(_fragments.subNodesCount);
236
154
  generatedVariables.subNodesCountTypes = options.getSubNodesCount.types ? options.getSubNodesCount.types : ['nt:base'];
237
155
  }
238
-
239
156
  if (options.getMimeType) {
240
157
  fragments.push(_fragments.mimeTypes);
241
158
  }
242
159
  }
243
-
244
160
  return {
245
161
  query: (0, _fragments.replaceFragmentsInDocument)(baseQuery, fragments),
246
162
  generatedVariables: generatedVariables,
247
- skip: skip,
248
- loading: loading
163
+ skip: skip
249
164
  };
250
165
  };
251
-
252
166
  exports.getQuery = getQuery;