@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.
- package/esm/fragments/PredefinedFragments.js +21 -221
- package/esm/fragments/fragments.utils.js +17 -43
- package/esm/fragments/getIsNodeTypeFragment.js +2 -15
- package/esm/fragments/getPermissionFragment.js +3 -28
- package/esm/hooks/useContentPreview/useContentPreview.gql-queries.js +2 -12
- package/esm/hooks/useContentPreview/useContentPreview.js +7 -7
- package/esm/hooks/useDeepCompareMemo/useDeepCompareMemo.js +0 -2
- package/esm/hooks/useDeepCompareMemo/useDeepCompareMemo.spec.js +0 -1
- package/esm/hooks/useNodeChecks/useNodeChecks.js +13 -28
- package/esm/hooks/useNodeChecks/useNodeChecks.spec.js +156 -67
- package/esm/hooks/useNodeInfo/useMemoRequest.js +49 -0
- package/esm/hooks/useNodeInfo/useNodeInfo.gql-queries.js +23 -104
- package/esm/hooks/useNodeInfo/useNodeInfo.js +139 -57
- package/esm/hooks/useNodeInfo/useNodeInfo.spec.js +429 -233
- package/esm/hooks/useNodeInfo/useNodeInfo.utils.js +52 -0
- package/esm/hooks/useSchemaFields/useSchemaFields.gql-queries.js +2 -12
- package/esm/hooks/useSiteInfo/useSiteInfo.gql-queries.js +2 -12
- package/esm/hooks/useSiteInfo/useSiteInfo.js +2 -9
- package/esm/hooks/useTreeEntries/useTreeEntries.gql-queries.js +2 -12
- package/esm/hooks/useTreeEntries/useTreeEntries.js +18 -40
- package/esm/legacy/Picker.gql-fragments.js +4 -34
- package/esm/legacy/Picker.js +31 -113
- package/js/fragments/PredefinedFragments.js +21 -224
- package/js/fragments/encodeName.js +0 -2
- package/js/fragments/fragments.utils.js +17 -44
- package/js/fragments/getIsNodeTypeFragment.js +2 -23
- package/js/fragments/getPermissionFragment.js +3 -38
- package/js/fragments/index.js +0 -4
- package/js/hooks/index.js +0 -10
- package/js/hooks/useContentPreview/index.js +0 -2
- package/js/hooks/useContentPreview/useContentPreview.gql-queries.js +2 -16
- package/js/hooks/useContentPreview/useContentPreview.js +7 -11
- package/js/hooks/useContentPreview/useContentPreview.spec.js +0 -2
- package/js/hooks/useDeepCompareMemo/index.js +0 -2
- package/js/hooks/useDeepCompareMemo/useDeepCompareMemo.js +0 -7
- package/js/hooks/useDeepCompareMemo/useDeepCompareMemo.spec.js +0 -2
- package/js/hooks/useNodeChecks/index.js +0 -2
- package/js/hooks/useNodeChecks/useNodeChecks.js +13 -30
- package/js/hooks/useNodeChecks/useNodeChecks.spec.js +157 -69
- package/js/hooks/useNodeInfo/index.js +0 -2
- package/js/hooks/useNodeInfo/useMemoRequest.js +56 -0
- package/js/hooks/useNodeInfo/useNodeInfo.gql-queries.js +25 -111
- package/js/hooks/useNodeInfo/useNodeInfo.js +139 -65
- package/js/hooks/useNodeInfo/useNodeInfo.spec.js +430 -236
- package/js/hooks/useNodeInfo/useNodeInfo.utils.js +60 -0
- package/js/hooks/useSchemaFields/index.js +0 -2
- package/js/hooks/useSchemaFields/useSchemaFields.gql-queries.js +2 -15
- package/js/hooks/useSchemaFields/useSchemaFields.jsx +0 -4
- package/js/hooks/useSiteInfo/index.js +0 -2
- package/js/hooks/useSiteInfo/useSiteInfo.gql-queries.js +2 -16
- package/js/hooks/useSiteInfo/useSiteInfo.js +2 -12
- package/js/hooks/useSiteInfo/useSiteInfo.spec.js +0 -4
- package/js/hooks/useTreeEntries/index.js +0 -2
- package/js/hooks/useTreeEntries/useTreeEntries.gql-queries.js +2 -16
- package/js/hooks/useTreeEntries/useTreeEntries.js +18 -46
- package/js/hooks/useTreeEntries/useTreeEntries.spec.js +0 -3
- package/js/index.js +0 -6
- package/js/legacy/Picker.gql-fragments.js +4 -37
- package/js/legacy/Picker.js +31 -134
- package/js/legacy/index.js +0 -4
- package/package.json +1 -1
|
@@ -1,117 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
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 "]);
|
|
3
|
-
|
|
4
|
-
_templateObject4 = function _templateObject4() {
|
|
5
|
-
return data;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
return data;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function _templateObject3() {
|
|
12
|
-
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 "]);
|
|
13
|
-
|
|
14
|
-
_templateObject3 = function _templateObject3() {
|
|
15
|
-
return data;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
return data;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function _templateObject2() {
|
|
22
|
-
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 "]);
|
|
23
|
-
|
|
24
|
-
_templateObject2 = function _templateObject2() {
|
|
25
|
-
return data;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
return data;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function _templateObject() {
|
|
32
|
-
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 "]);
|
|
33
|
-
|
|
34
|
-
_templateObject = function _templateObject() {
|
|
35
|
-
return data;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
return data;
|
|
39
|
-
}
|
|
40
|
-
|
|
1
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4;
|
|
41
2
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
42
|
-
|
|
43
3
|
import gql from 'graphql-tag';
|
|
44
4
|
import { aggregatedPublicationInfoWithExistInLive, aggregatedPublicationInfo, childNodeTypes, contentRestrictions, displayableNode, displayName, getProperties, installedModules, lockInfo, mimeTypes, nodeCacheRequiredFields, operationSupport, parentNode, primaryNodeType, replaceFragmentsInDocument, siteLanguages, subNodesCount } from '../../fragments';
|
|
45
5
|
import { getPermissionFragment, getSitePermissionFragment } from '../../fragments/getPermissionFragment';
|
|
46
6
|
import { getNodeTypeFragment } from '../../fragments/getIsNodeTypeFragment';
|
|
47
|
-
|
|
48
7
|
var getBaseQueryAndVariables = function getBaseQueryAndVariables(variables) {
|
|
49
8
|
if (variables.paths) {
|
|
50
9
|
return {
|
|
51
|
-
baseQuery: gql(_templateObject(), nodeCacheRequiredFields.gql),
|
|
10
|
+
baseQuery: gql(_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 "])), nodeCacheRequiredFields.gql),
|
|
52
11
|
generatedVariables: {
|
|
53
12
|
paths: variables.paths
|
|
54
13
|
},
|
|
55
14
|
skip: false
|
|
56
15
|
};
|
|
57
16
|
}
|
|
58
|
-
|
|
59
17
|
if (variables.uuid && variables.uuid.length > 0) {
|
|
60
18
|
return {
|
|
61
|
-
baseQuery: gql(_templateObject2(), nodeCacheRequiredFields.gql),
|
|
19
|
+
baseQuery: gql(_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 "])), nodeCacheRequiredFields.gql),
|
|
62
20
|
generatedVariables: {
|
|
63
21
|
uuid: variables.uuid
|
|
64
22
|
},
|
|
65
23
|
skip: false
|
|
66
24
|
};
|
|
67
25
|
}
|
|
68
|
-
|
|
69
26
|
if (variables.uuids) {
|
|
70
27
|
return {
|
|
71
|
-
baseQuery: gql(_templateObject3(), nodeCacheRequiredFields.gql),
|
|
28
|
+
baseQuery: gql(_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 "])), nodeCacheRequiredFields.gql),
|
|
72
29
|
generatedVariables: {
|
|
73
30
|
uuids: variables.uuids
|
|
74
31
|
},
|
|
75
32
|
skip: false
|
|
76
33
|
};
|
|
77
34
|
}
|
|
78
|
-
|
|
79
35
|
return {
|
|
80
|
-
baseQuery: gql(_templateObject4(), nodeCacheRequiredFields.gql),
|
|
36
|
+
baseQuery: gql(_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 "])), nodeCacheRequiredFields.gql),
|
|
81
37
|
generatedVariables: {
|
|
82
38
|
path: variables.path
|
|
83
39
|
},
|
|
84
40
|
skip: !variables.path || variables.path.length === 0
|
|
85
41
|
};
|
|
86
42
|
};
|
|
87
|
-
|
|
43
|
+
export var validOptions = ['getDisplayName', 'getPrimaryNodeType', 'getParent', 'getAggregatedPublicationInfo', 'getOperationSupport', 'getPermissions', 'getSitePermissions', 'getIsNodeTypes', 'getProperties', 'getSiteInstalledModules', 'getSiteLanguages', 'getDisplayableNodePath', 'getLockInfo', 'getChildNodeTypes', 'getContributeTypesRestrictions', 'getSubNodesCount', 'getMimeType'];
|
|
88
44
|
export var getQuery = function getQuery(variables, schemaResult) {
|
|
89
45
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
90
46
|
var fragments = [];
|
|
91
|
-
|
|
92
47
|
var _getBaseQueryAndVaria = getBaseQueryAndVariables(variables),
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
var error = schemaResult.error,
|
|
98
|
-
loading = schemaResult.loading,
|
|
99
|
-
data = schemaResult.data;
|
|
100
|
-
|
|
48
|
+
baseQuery = _getBaseQueryAndVaria.baseQuery,
|
|
49
|
+
generatedVariables = _getBaseQueryAndVaria.generatedVariables,
|
|
50
|
+
skip = _getBaseQueryAndVaria.skip;
|
|
101
51
|
if (!skip) {
|
|
102
52
|
if (options.getDisplayName) {
|
|
103
53
|
fragments.push(displayName);
|
|
104
|
-
|
|
105
54
|
if (!variables.language) {
|
|
106
55
|
throw Error('language is required');
|
|
107
56
|
}
|
|
108
|
-
|
|
109
57
|
generatedVariables.language = variables.language;
|
|
110
58
|
}
|
|
111
|
-
|
|
112
59
|
if (options.getPrimaryNodeType) {
|
|
113
60
|
fragments.push(primaryNodeType);
|
|
114
|
-
|
|
115
61
|
if (!variables.displayLanguage) {
|
|
116
62
|
generatedVariables.displayLanguageSet = false;
|
|
117
63
|
generatedVariables.displayLanguage = '';
|
|
@@ -120,119 +66,92 @@ export var getQuery = function getQuery(variables, schemaResult) {
|
|
|
120
66
|
generatedVariables.displayLanguage = variables.displayLanguage;
|
|
121
67
|
}
|
|
122
68
|
}
|
|
123
|
-
|
|
124
69
|
if (options.getParent) {
|
|
125
70
|
fragments.push(parentNode);
|
|
126
71
|
}
|
|
127
|
-
|
|
128
72
|
if (options.getAggregatedPublicationInfo) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
} else {
|
|
137
|
-
fragments.push(aggregatedPublicationInfo);
|
|
138
|
-
}
|
|
73
|
+
var supportsExistsInLive = schemaResult && schemaResult.__type && schemaResult.__type.fields && schemaResult.__type.fields.find(function (field) {
|
|
74
|
+
return field.name === 'existsInLive';
|
|
75
|
+
}) !== undefined;
|
|
76
|
+
if (supportsExistsInLive) {
|
|
77
|
+
fragments.push(aggregatedPublicationInfoWithExistInLive);
|
|
78
|
+
} else {
|
|
79
|
+
fragments.push(aggregatedPublicationInfo);
|
|
139
80
|
}
|
|
140
|
-
|
|
141
81
|
if (!variables.language) {
|
|
142
82
|
throw Error('language is required');
|
|
143
83
|
}
|
|
144
|
-
|
|
145
84
|
generatedVariables.language = variables.language;
|
|
146
85
|
generatedVariables.aggregatedPublicationInfoSubNodes = Boolean(options.getAggregatedPublicationInfo.subNodes);
|
|
147
86
|
generatedVariables.aggregatedPublicationInfoIncludeReference = Boolean(options.getAggregatedPublicationInfo.reference);
|
|
148
87
|
}
|
|
149
|
-
|
|
150
88
|
if (options.getOperationSupport) {
|
|
151
89
|
fragments.push(operationSupport);
|
|
152
90
|
}
|
|
153
|
-
|
|
154
91
|
if (options.getPermissions) {
|
|
155
92
|
options.getPermissions.forEach(function (name) {
|
|
156
93
|
var _getPermissionFragmen = getPermissionFragment(name),
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
94
|
+
fragment = _getPermissionFragmen.fragment,
|
|
95
|
+
variables = _getPermissionFragmen.variables;
|
|
160
96
|
fragments.push(fragment);
|
|
161
97
|
Object.assign(generatedVariables, variables);
|
|
162
98
|
});
|
|
163
99
|
}
|
|
164
|
-
|
|
165
100
|
if (options.getSitePermissions) {
|
|
166
101
|
options.getSitePermissions.forEach(function (name) {
|
|
167
102
|
var _getSitePermissionFra = getSitePermissionFragment(name),
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
103
|
+
fragment = _getSitePermissionFra.fragment,
|
|
104
|
+
variables = _getSitePermissionFra.variables;
|
|
171
105
|
fragments.push(fragment);
|
|
172
106
|
Object.assign(generatedVariables, variables);
|
|
173
107
|
});
|
|
174
108
|
}
|
|
175
|
-
|
|
176
109
|
if (options.getIsNodeTypes) {
|
|
177
110
|
options.getIsNodeTypes.forEach(function (name) {
|
|
178
111
|
var _getNodeTypeFragment = getNodeTypeFragment(name),
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
112
|
+
fragment = _getNodeTypeFragment.fragment,
|
|
113
|
+
variables = _getNodeTypeFragment.variables;
|
|
182
114
|
fragments.push(fragment);
|
|
183
115
|
Object.assign(generatedVariables, variables);
|
|
184
116
|
});
|
|
185
117
|
}
|
|
186
|
-
|
|
187
118
|
if (options.getProperties) {
|
|
188
119
|
fragments.push(getProperties);
|
|
189
120
|
generatedVariables.getPropertiesNames = options.getProperties;
|
|
190
|
-
|
|
191
121
|
if (!variables.language) {
|
|
192
122
|
throw Error('language is required');
|
|
193
123
|
}
|
|
194
|
-
|
|
195
124
|
generatedVariables.language = variables.language;
|
|
196
125
|
}
|
|
197
|
-
|
|
198
126
|
if (options.getSiteInstalledModules) {
|
|
199
127
|
fragments.push(installedModules);
|
|
200
128
|
}
|
|
201
|
-
|
|
202
129
|
if (options.getSiteLanguages) {
|
|
203
130
|
fragments.push(siteLanguages);
|
|
204
131
|
}
|
|
205
|
-
|
|
206
132
|
if (options.getDisplayableNodePath) {
|
|
207
133
|
fragments.push(displayableNode);
|
|
208
134
|
}
|
|
209
|
-
|
|
210
135
|
if (options.getLockInfo) {
|
|
211
136
|
fragments.push(lockInfo);
|
|
212
137
|
}
|
|
213
|
-
|
|
214
138
|
if (options.getChildNodeTypes) {
|
|
215
139
|
fragments.push(childNodeTypes);
|
|
216
140
|
}
|
|
217
|
-
|
|
218
141
|
if (options.getContributeTypesRestrictions) {
|
|
219
142
|
fragments.push(contentRestrictions);
|
|
220
143
|
}
|
|
221
|
-
|
|
222
144
|
if (options.getSubNodesCount) {
|
|
223
145
|
fragments.push(subNodesCount);
|
|
224
146
|
generatedVariables.subNodesCountTypes = options.getSubNodesCount.types ? options.getSubNodesCount.types : ['nt:base'];
|
|
225
147
|
}
|
|
226
|
-
|
|
227
148
|
if (options.getMimeType) {
|
|
228
149
|
fragments.push(mimeTypes);
|
|
229
150
|
}
|
|
230
151
|
}
|
|
231
|
-
|
|
232
152
|
return {
|
|
233
153
|
query: replaceFragmentsInDocument(baseQuery, fragments),
|
|
234
154
|
generatedVariables: generatedVariables,
|
|
235
|
-
skip: skip
|
|
236
|
-
loading: loading
|
|
155
|
+
skip: skip
|
|
237
156
|
};
|
|
238
157
|
};
|
|
@@ -1,84 +1,170 @@
|
|
|
1
|
+
var _excluded = ["data"];
|
|
2
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
3
|
+
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."); }
|
|
4
|
+
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); }
|
|
5
|
+
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; }
|
|
6
|
+
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; }
|
|
7
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
8
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
9
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
1
10
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
-
|
|
3
11
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
-
|
|
5
12
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
10
|
-
|
|
11
|
-
import { useMemo } from 'react';
|
|
12
|
-
import { useQuery } from 'react-apollo';
|
|
13
|
+
import { useEffect, useState } from 'react';
|
|
14
|
+
import { useApolloClient } from 'react-apollo';
|
|
13
15
|
import { getQuery } from './useNodeInfo.gql-queries';
|
|
14
|
-
import { useDeepCompareMemoize } from '../useDeepCompareMemo';
|
|
15
16
|
import { getEncodedPermissionName } from '../../fragments/getPermissionFragment';
|
|
16
17
|
import { getEncodedNodeTypeName } from '../../fragments/getIsNodeTypeFragment';
|
|
17
|
-
import {
|
|
18
|
+
import { SCHEMA_FIELDS_QUERY } from '../useSchemaFields/useSchemaFields.gql-queries';
|
|
19
|
+
import { isSubset, merge } from './useNodeInfo.utils';
|
|
20
|
+
import { useMemoRequest } from './useMemoRequest';
|
|
21
|
+
import deepEquals from 'fast-deep-equal';
|
|
22
|
+
var queue = [];
|
|
23
|
+
var schemaResult;
|
|
24
|
+
var timeout;
|
|
25
|
+
var observedQueries = [];
|
|
26
|
+
function scheduleQueue(client) {
|
|
27
|
+
if (!timeout && schemaResult) {
|
|
28
|
+
timeout = setTimeout(function () {
|
|
29
|
+
timeoutHandler(client);
|
|
30
|
+
clearTimeout(timeout);
|
|
31
|
+
timeout = null;
|
|
32
|
+
}, 0);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
var timeoutHandler = function timeoutHandler(client) {
|
|
36
|
+
var mergedQueue = [];
|
|
37
|
+
queue.forEach(function (request) {
|
|
38
|
+
var toInsert = {
|
|
39
|
+
variables: request.variables,
|
|
40
|
+
queryOptions: request.queryOptions,
|
|
41
|
+
options: request.options,
|
|
42
|
+
originals: [request]
|
|
43
|
+
};
|
|
44
|
+
var mergeable = mergedQueue.find(function (q) {
|
|
45
|
+
return JSON.stringify(q.queryOptions) === JSON.stringify(toInsert.queryOptions) && (isSubset(q.variables, toInsert.variables) || isSubset(toInsert.variables, q.variables));
|
|
46
|
+
});
|
|
47
|
+
if (mergeable) {
|
|
48
|
+
merge(mergeable, toInsert);
|
|
49
|
+
} else {
|
|
50
|
+
mergedQueue.push({
|
|
51
|
+
variables: toInsert.variables && _objectSpread({}, toInsert.variables),
|
|
52
|
+
queryOptions: toInsert.queryOptions && _objectSpread({}, toInsert.queryOptions),
|
|
53
|
+
options: toInsert.options && _objectSpread({}, toInsert.options),
|
|
54
|
+
originals: toInsert.originals
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
observedQueries.forEach(function (obs) {
|
|
59
|
+
return obs.unsubscribe();
|
|
60
|
+
});
|
|
61
|
+
observedQueries = [];
|
|
62
|
+
mergedQueue.forEach(function (mergedRequest) {
|
|
63
|
+
var variables = mergedRequest.variables,
|
|
64
|
+
queryOptions = mergedRequest.queryOptions,
|
|
65
|
+
options = mergedRequest.options,
|
|
66
|
+
originals = mergedRequest.originals;
|
|
67
|
+
var _getQuery = getQuery(variables, schemaResult, options),
|
|
68
|
+
query = _getQuery.query,
|
|
69
|
+
generatedVariables = _getQuery.generatedVariables,
|
|
70
|
+
skip = _getQuery.skip;
|
|
71
|
+
if (skip) {
|
|
72
|
+
// No query to execute
|
|
73
|
+
originals.forEach(function (request) {
|
|
74
|
+
request.setResult({
|
|
75
|
+
loading: false
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
} else {
|
|
79
|
+
var watchedQuery = client.watchQuery(_objectSpread(_objectSpread({
|
|
80
|
+
query: query,
|
|
81
|
+
errorPolicy: 'ignore'
|
|
82
|
+
}, queryOptions), {}, {
|
|
83
|
+
variables: generatedVariables
|
|
84
|
+
})).subscribe(function (_ref) {
|
|
85
|
+
var data = _ref.data,
|
|
86
|
+
others = _objectWithoutProperties(_ref, _excluded);
|
|
87
|
+
var result = getResult(data, others, options, query, generatedVariables);
|
|
88
|
+
originals.forEach(function (request) {
|
|
89
|
+
if (!deepEquals(request.result, result)) {
|
|
90
|
+
request.result = result;
|
|
91
|
+
request.setResult(_objectSpread(_objectSpread({}, result), {}, {
|
|
92
|
+
refetch: function refetch() {
|
|
93
|
+
client.refetchQueries({
|
|
94
|
+
include: [query]
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
observedQueries.push(watchedQuery);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
};
|
|
18
105
|
export var useNodeInfo = function useNodeInfo(variables, options, queryOptions) {
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
skip: skip || loading
|
|
39
|
-
})),
|
|
40
|
-
data = _useQuery.data,
|
|
41
|
-
others = _objectWithoutProperties(_useQuery, ["data"]);
|
|
106
|
+
var _useState = useState({
|
|
107
|
+
loading: true
|
|
108
|
+
}),
|
|
109
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
110
|
+
result = _useState2[0],
|
|
111
|
+
setResult = _useState2[1];
|
|
112
|
+
var client = useApolloClient();
|
|
113
|
+
if (!schemaResult) {
|
|
114
|
+
client.query({
|
|
115
|
+
query: SCHEMA_FIELDS_QUERY,
|
|
116
|
+
variables: {
|
|
117
|
+
type: 'GqlPublicationInfo'
|
|
118
|
+
}
|
|
119
|
+
}).then(function (_ref2) {
|
|
120
|
+
var data = _ref2.data;
|
|
121
|
+
schemaResult = data;
|
|
122
|
+
scheduleQueue(client);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
42
125
|
|
|
126
|
+
// Normalize and memoize request
|
|
127
|
+
var _useMemoRequest = useMemoRequest(variables, queryOptions, options, setResult),
|
|
128
|
+
_useMemoRequest2 = _slicedToArray(_useMemoRequest, 1),
|
|
129
|
+
currentRequest = _useMemoRequest2[0];
|
|
130
|
+
useEffect(function () {
|
|
131
|
+
queue.push(currentRequest);
|
|
132
|
+
scheduleQueue(client);
|
|
133
|
+
return function () {
|
|
134
|
+
queue.splice(queue.indexOf(currentRequest), 1);
|
|
135
|
+
};
|
|
136
|
+
}, [currentRequest]);
|
|
137
|
+
return result;
|
|
138
|
+
};
|
|
139
|
+
var getResult = function getResult(data, others, options, query, generatedVariables) {
|
|
43
140
|
var node = data && data.jcr && (data.jcr.nodeByPath || data.jcr.nodeById) || null;
|
|
44
141
|
var nodes = data && data.jcr && (data.jcr.nodesByPath || data.jcr.nodesById) || null;
|
|
45
|
-
|
|
46
|
-
if (loading) {
|
|
47
|
-
return {
|
|
48
|
-
loading: loading
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
142
|
+
var result = others;
|
|
52
143
|
if (node) {
|
|
53
|
-
|
|
54
|
-
node: decodeResult(node,
|
|
55
|
-
}, others, {
|
|
144
|
+
result = _objectSpread(_objectSpread({
|
|
145
|
+
node: decodeResult(node, options)
|
|
146
|
+
}, others), {}, {
|
|
56
147
|
query: query,
|
|
57
148
|
variables: generatedVariables
|
|
58
149
|
});
|
|
59
150
|
}
|
|
60
|
-
|
|
61
151
|
if (nodes) {
|
|
62
|
-
|
|
152
|
+
result = _objectSpread(_objectSpread({
|
|
63
153
|
nodes: nodes.map(function (n) {
|
|
64
|
-
return decodeResult(n,
|
|
154
|
+
return decodeResult(n, options);
|
|
65
155
|
})
|
|
66
|
-
}, others, {
|
|
156
|
+
}, others), {}, {
|
|
67
157
|
query: query,
|
|
68
158
|
variables: generatedVariables
|
|
69
159
|
});
|
|
70
160
|
}
|
|
71
|
-
|
|
72
|
-
return _objectSpread({}, others);
|
|
161
|
+
return result;
|
|
73
162
|
};
|
|
74
|
-
|
|
75
163
|
var decodeResult = function decodeResult(nodeOrig, options) {
|
|
76
164
|
var node = _objectSpread({}, nodeOrig);
|
|
77
|
-
|
|
78
165
|
if (node.site) {
|
|
79
166
|
node.site = _objectSpread({}, node.site);
|
|
80
167
|
}
|
|
81
|
-
|
|
82
168
|
if (node && options) {
|
|
83
169
|
if (options.getPermissions) {
|
|
84
170
|
options.getPermissions.forEach(function (name) {
|
|
@@ -87,7 +173,6 @@ var decodeResult = function decodeResult(nodeOrig, options) {
|
|
|
87
173
|
node[name] = res;
|
|
88
174
|
});
|
|
89
175
|
}
|
|
90
|
-
|
|
91
176
|
if (options.getSitePermissions) {
|
|
92
177
|
options.getSitePermissions.forEach(function (name) {
|
|
93
178
|
var res = node.site[getEncodedPermissionName(name)];
|
|
@@ -95,7 +180,6 @@ var decodeResult = function decodeResult(nodeOrig, options) {
|
|
|
95
180
|
node.site[name] = res;
|
|
96
181
|
});
|
|
97
182
|
}
|
|
98
|
-
|
|
99
183
|
if (options.getIsNodeTypes) {
|
|
100
184
|
options.getIsNodeTypes.forEach(function (name) {
|
|
101
185
|
var res = node[getEncodedNodeTypeName(name)];
|
|
@@ -103,13 +187,11 @@ var decodeResult = function decodeResult(nodeOrig, options) {
|
|
|
103
187
|
node[name] = res;
|
|
104
188
|
});
|
|
105
189
|
}
|
|
106
|
-
|
|
107
190
|
if (options.getMimeType) {
|
|
108
191
|
var nodes = node.resourceChildren.nodes;
|
|
109
192
|
node.mimeType = nodes.length !== 0 && nodes[0].mimeType.value || null;
|
|
110
193
|
delete node.resourceChildren;
|
|
111
194
|
}
|
|
112
195
|
}
|
|
113
|
-
|
|
114
196
|
return node;
|
|
115
197
|
};
|