|
1 | 1 | "use strict"; |
| 2 | +var __assign = (this && this.__assign) || function () { |
| 3 | + __assign = Object.assign || function(t) { |
| 4 | + for (var s, i = 1, n = arguments.length; i < n; i++) { |
| 5 | + s = arguments[i]; |
| 6 | + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) |
| 7 | + t[p] = s[p]; |
| 8 | + } |
| 9 | + return t; |
| 10 | + }; |
| 11 | + return __assign.apply(this, arguments); |
| 12 | +}; |
| 13 | +var __read = (this && this.__read) || function (o, n) { |
| 14 | + var m = typeof Symbol === "function" && o[Symbol.iterator]; |
| 15 | + if (!m) return o; |
| 16 | + var i = m.call(o), r, ar = [], e; |
| 17 | + try { |
| 18 | + while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); |
| 19 | + } |
| 20 | + catch (error) { e = { error: error }; } |
| 21 | + finally { |
| 22 | + try { |
| 23 | + if (r && !r.done && (m = i["return"])) m.call(i); |
| 24 | + } |
| 25 | + finally { if (e) throw e.error; } |
| 26 | + } |
| 27 | + return ar; |
| 28 | +}; |
| 29 | +var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { |
| 30 | + if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { |
| 31 | + if (ar || !(i in from)) { |
| 32 | + if (!ar) ar = Array.prototype.slice.call(from, 0, i); |
| 33 | + ar[i] = from[i]; |
| 34 | + } |
| 35 | + } |
| 36 | + return to.concat(ar || Array.prototype.slice.call(from)); |
| 37 | +}; |
2 | 38 | exports.__esModule = true; |
3 | 39 | exports.injectHooks = void 0; |
4 | | -function injectListHooks(declaration, injectFunctions) { |
| 40 | +function injectListHooks(sourceDeclaration, injectFunctions) { |
| 41 | + var declaration = __assign({}, sourceDeclaration); |
5 | 42 | // If the list is resolved by a custom function, we don't need to inject hooks |
6 | 43 | if ('type' in declaration || |
7 | 44 | ((declaration === null || declaration === void 0 ? void 0 : declaration.list) && 'resolve' in (declaration === null || declaration === void 0 ? void 0 : declaration.list))) { |
8 | | - return; |
| 45 | + return declaration; |
9 | 46 | } |
10 | 47 | if (!declaration.list) { |
11 | 48 | declaration.list = {}; |
12 | 49 | } |
| 50 | + else { |
| 51 | + declaration.list = __assign({}, declaration.list); |
| 52 | + } |
13 | 53 | var beforeList = Array.isArray(declaration.list.beforeList) |
14 | | - ? declaration.list.beforeList |
15 | | - : declaration.list.beforeList |
16 | | - ? [declaration.list.beforeList] |
17 | | - : []; |
| 54 | + ? __spreadArray([], __read(declaration.list.beforeList), false) : declaration.list.beforeList |
| 55 | + ? [declaration.list.beforeList] |
| 56 | + : []; |
18 | 57 | declaration.list.beforeList = injectFunctions.listBefore |
19 | 58 | ? injectFunctions.listBefore(declaration.model, beforeList) |
20 | 59 | : beforeList; |
21 | 60 | var afterList = Array.isArray(declaration.list.afterList) |
22 | | - ? declaration.list.afterList |
23 | | - : declaration.list.afterList |
24 | | - ? [declaration.list.afterList] |
25 | | - : []; |
| 61 | + ? __spreadArray([], __read(declaration.list.afterList), false) : declaration.list.afterList |
| 62 | + ? [declaration.list.afterList] |
| 63 | + : []; |
26 | 64 | declaration.list.afterList = injectFunctions.listAfter |
27 | 65 | ? injectFunctions.listAfter(declaration.model, afterList) |
28 | 66 | : afterList; |
| 67 | + return declaration; |
29 | 68 | } |
30 | | -function injectUpdateHooks(declaration, injectFunctions) { |
| 69 | +function injectUpdateHooks(sourceDeclaration, injectFunctions) { |
31 | 70 | var _a; |
| 71 | + var declaration = __assign({}, sourceDeclaration); |
32 | 72 | if ('actions' in declaration && !((_a = declaration.actions) === null || _a === void 0 ? void 0 : _a.includes('update'))) |
33 | | - return; |
| 73 | + return declaration; |
34 | 74 | // If the update is resolved by a custom function, we don't need to inject hooks |
35 | 75 | if ('update' in declaration && |
36 | 76 | (declaration === null || declaration === void 0 ? void 0 : declaration.update) && |
37 | 77 | 'resolve' in (declaration === null || declaration === void 0 ? void 0 : declaration.update)) { |
38 | | - return; |
| 78 | + return declaration; |
39 | 79 | } |
40 | 80 | if ('type' in declaration || |
41 | 81 | ((declaration === null || declaration === void 0 ? void 0 : declaration.update) && 'resolve' in (declaration === null || declaration === void 0 ? void 0 : declaration.update))) { |
42 | | - return; |
| 82 | + return declaration; |
43 | 83 | } |
44 | 84 | if ('update' in declaration && |
45 | 85 | (declaration === null || declaration === void 0 ? void 0 : declaration.update) && |
46 | 86 | 'resolve' in (declaration === null || declaration === void 0 ? void 0 : declaration.update)) { |
47 | | - return; |
| 87 | + return declaration; |
48 | 88 | } |
49 | 89 | if (!declaration.update) { |
50 | 90 | declaration.update = {}; |
51 | 91 | } |
| 92 | + else { |
| 93 | + declaration.update = __assign({}, declaration.update); |
| 94 | + } |
52 | 95 | declaration.update = declaration.update; |
53 | 96 | var beforeUpdateFetch = Array.isArray(declaration.update.beforeUpdateFetch) |
54 | | - ? declaration.update.beforeUpdateFetch |
55 | | - : declaration.update.beforeUpdateFetch |
56 | | - ? [declaration.update.beforeUpdateFetch] |
57 | | - : []; |
| 97 | + ? __spreadArray([], __read(declaration.update.beforeUpdateFetch), false) : declaration.update.beforeUpdateFetch |
| 98 | + ? [declaration.update.beforeUpdateFetch] |
| 99 | + : []; |
58 | 100 | declaration.update.beforeUpdateFetch = injectFunctions.updateBeforeFetch |
59 | 101 | ? injectFunctions.updateBeforeFetch(declaration.model, beforeUpdateFetch) |
60 | 102 | : beforeUpdateFetch; |
61 | 103 | var beforeUpdate = Array.isArray(declaration.update.beforeUpdate) |
62 | | - ? declaration.update.beforeUpdate |
63 | | - : declaration.update.beforeUpdate |
64 | | - ? [declaration.update.beforeUpdate] |
65 | | - : []; |
| 104 | + ? __spreadArray([], __read(declaration.update.beforeUpdate), false) : declaration.update.beforeUpdate |
| 105 | + ? [declaration.update.beforeUpdate] |
| 106 | + : []; |
66 | 107 | declaration.update.beforeUpdate = injectFunctions.updateBefore |
67 | 108 | ? injectFunctions.updateBefore(declaration.model, beforeUpdate) |
68 | 109 | : beforeUpdate; |
69 | 110 | var afterUpdate = Array.isArray(declaration.update.afterUpdate) |
70 | | - ? declaration.update.afterUpdate |
71 | | - : declaration.update.afterUpdate |
72 | | - ? [declaration.update.afterUpdate] |
73 | | - : []; |
| 111 | + ? __spreadArray([], __read(declaration.update.afterUpdate), false) : declaration.update.afterUpdate |
| 112 | + ? [declaration.update.afterUpdate] |
| 113 | + : []; |
74 | 114 | declaration.update.afterUpdate = injectFunctions.updateAfter |
75 | 115 | ? injectFunctions.updateAfter(declaration.model, afterUpdate) |
76 | 116 | : afterUpdate; |
| 117 | + return declaration; |
77 | 118 | } |
78 | | -function injectCreateHooks(declaration, injectFunctions) { |
| 119 | +function injectCreateHooks(sourceDeclaration, injectFunctions) { |
79 | 120 | var _a; |
| 121 | + var declaration = __assign({}, sourceDeclaration); |
80 | 122 | if ('actions' in declaration && !((_a = declaration.actions) === null || _a === void 0 ? void 0 : _a.includes('create'))) |
81 | | - return; |
| 123 | + return declaration; |
82 | 124 | // If the create is resolved by a custom function, we don't need to inject hooks |
83 | 125 | if ('create' in declaration && |
84 | 126 | (declaration === null || declaration === void 0 ? void 0 : declaration.create) && |
85 | 127 | 'resolve' in (declaration === null || declaration === void 0 ? void 0 : declaration.create)) { |
86 | | - return; |
| 128 | + return declaration; |
87 | 129 | } |
88 | 130 | if ('type' in declaration || |
89 | 131 | ((declaration === null || declaration === void 0 ? void 0 : declaration.create) && 'resolve' in (declaration === null || declaration === void 0 ? void 0 : declaration.create))) { |
90 | | - return; |
| 132 | + return declaration; |
91 | 133 | } |
92 | 134 | if (!declaration.create) { |
93 | 135 | declaration.create = {}; |
94 | 136 | } |
| 137 | + else { |
| 138 | + declaration.create = __assign({}, declaration.create); |
| 139 | + } |
95 | 140 | declaration.create = declaration.create; |
96 | 141 | var beforeCreate = Array.isArray(declaration.create.beforeCreate) |
97 | | - ? declaration.create.beforeCreate |
98 | | - : declaration.create.beforeCreate |
99 | | - ? [declaration.create.beforeCreate] |
100 | | - : []; |
| 142 | + ? __spreadArray([], __read(declaration.create.beforeCreate), false) : declaration.create.beforeCreate |
| 143 | + ? [declaration.create.beforeCreate] |
| 144 | + : []; |
101 | 145 | declaration.create.beforeCreate = injectFunctions.createBefore |
102 | 146 | ? injectFunctions.createBefore(declaration.model, beforeCreate) |
103 | 147 | : beforeCreate; |
104 | 148 | var afterCreate = Array.isArray(declaration.create.afterCreate) |
105 | | - ? declaration.create.afterCreate |
106 | | - : declaration.create.afterCreate |
107 | | - ? [declaration.create.afterCreate] |
108 | | - : []; |
| 149 | + ? __spreadArray([], __read(declaration.create.afterCreate), false) : declaration.create.afterCreate |
| 150 | + ? [declaration.create.afterCreate] |
| 151 | + : []; |
109 | 152 | declaration.create.afterCreate = injectFunctions.createAfter |
110 | 153 | ? injectFunctions.createAfter(declaration.model, afterCreate) |
111 | 154 | : afterCreate; |
| 155 | + return declaration; |
112 | 156 | } |
113 | | -function injectDeleteHooks(declaration, injectFunctions) { |
| 157 | +function injectDeleteHooks(sourceDeclaration, injectFunctions) { |
114 | 158 | var _a; |
| 159 | + var declaration = __assign({}, sourceDeclaration); |
115 | 160 | if ('actions' in declaration && !((_a = declaration.actions) === null || _a === void 0 ? void 0 : _a.includes('delete'))) |
116 | | - return; |
| 161 | + return declaration; |
117 | 162 | // If the delete is resolved by a custom function, we don't need to inject hooks |
118 | 163 | if ('delete' in declaration && |
119 | 164 | (declaration === null || declaration === void 0 ? void 0 : declaration["delete"]) && |
120 | 165 | 'resolve' in (declaration === null || declaration === void 0 ? void 0 : declaration["delete"])) { |
121 | | - return; |
| 166 | + return declaration; |
122 | 167 | } |
123 | 168 | if ('type' in declaration || |
124 | 169 | ((declaration === null || declaration === void 0 ? void 0 : declaration["delete"]) && 'resolve' in (declaration === null || declaration === void 0 ? void 0 : declaration["delete"]))) { |
125 | | - return; |
| 170 | + return declaration; |
126 | 171 | } |
127 | 172 | if (!declaration["delete"]) { |
128 | 173 | declaration["delete"] = {}; |
129 | 174 | } |
| 175 | + else { |
| 176 | + declaration["delete"] = __assign({}, declaration["delete"]); |
| 177 | + } |
130 | 178 | declaration["delete"] = declaration["delete"]; |
131 | 179 | var beforeDelete = Array.isArray(declaration["delete"].beforeDelete) |
132 | | - ? declaration["delete"].beforeDelete |
133 | | - : declaration["delete"].beforeDelete |
134 | | - ? [declaration["delete"].beforeDelete] |
135 | | - : []; |
| 180 | + ? __spreadArray([], __read(declaration["delete"].beforeDelete), false) : declaration["delete"].beforeDelete |
| 181 | + ? [declaration["delete"].beforeDelete] |
| 182 | + : []; |
136 | 183 | declaration["delete"].beforeDelete = injectFunctions.deleteBefore |
137 | 184 | ? injectFunctions.deleteBefore(declaration.model, beforeDelete) |
138 | 185 | : beforeDelete; |
139 | 186 | var beforeDeleteFetch = Array.isArray(declaration["delete"].beforeDeleteFetch) |
140 | | - ? declaration["delete"].beforeDeleteFetch |
141 | | - : declaration["delete"].beforeDeleteFetch |
142 | | - ? [declaration["delete"].beforeDeleteFetch] |
143 | | - : []; |
| 187 | + ? __spreadArray([], __read(declaration["delete"].beforeDeleteFetch), false) : declaration["delete"].beforeDeleteFetch |
| 188 | + ? [declaration["delete"].beforeDeleteFetch] |
| 189 | + : []; |
144 | 190 | declaration["delete"].beforeDeleteFetch = injectFunctions.deleteBeforeFetch |
145 | 191 | ? injectFunctions.deleteBeforeFetch(declaration.model, beforeDeleteFetch) |
146 | 192 | : beforeDeleteFetch; |
147 | 193 | var afterDelete = Array.isArray(declaration["delete"].afterDelete) |
148 | | - ? declaration["delete"].afterDelete |
149 | | - : declaration["delete"].afterDelete |
150 | | - ? [declaration["delete"].afterDelete] |
151 | | - : []; |
| 194 | + ? __spreadArray([], __read(declaration["delete"].afterDelete), false) : declaration["delete"].afterDelete |
| 195 | + ? [declaration["delete"].afterDelete] |
| 196 | + : []; |
152 | 197 | declaration["delete"].afterDelete = injectFunctions.deleteAfter |
153 | 198 | ? injectFunctions.deleteAfter(declaration.model, afterDelete) |
154 | 199 | : afterDelete; |
| 200 | + return declaration; |
155 | 201 | } |
156 | 202 | // Injects a function that will be called with the model and the hooks |
157 | 203 | // The function can return a new list of hooks to be used instead of the original ones |
158 | 204 | function injectHooks(_a) { |
159 | 205 | var graphqlSchemaDeclaration = _a.graphqlSchemaDeclaration, injectFunctions = _a.injectFunctions; |
160 | | - for (var key in graphqlSchemaDeclaration) { |
161 | | - var declaration = graphqlSchemaDeclaration[key]; |
| 206 | + var graphqlSchemaDeclarationWithHooksInjected = __assign({}, graphqlSchemaDeclaration); |
| 207 | + for (var key in graphqlSchemaDeclarationWithHooksInjected) { |
| 208 | + var declaration = graphqlSchemaDeclarationWithHooksInjected[key]; |
162 | 209 | if ('model' in declaration) { |
163 | | - injectListHooks(declaration, injectFunctions); |
164 | | - injectUpdateHooks(declaration, injectFunctions); |
165 | | - injectCreateHooks(declaration, injectFunctions); |
166 | | - injectDeleteHooks(declaration, injectFunctions); |
| 210 | + declaration = injectListHooks(declaration, injectFunctions); |
| 211 | + declaration = injectUpdateHooks(declaration, injectFunctions); |
| 212 | + declaration = injectCreateHooks(declaration, injectFunctions); |
| 213 | + declaration = injectDeleteHooks(declaration, injectFunctions); |
167 | 214 | } |
| 215 | + graphqlSchemaDeclarationWithHooksInjected[key] = declaration; |
168 | 216 | } |
169 | | - return graphqlSchemaDeclaration; |
| 217 | + return graphqlSchemaDeclarationWithHooksInjected; |
170 | 218 | } |
171 | 219 | exports.injectHooks = injectHooks; |
0 commit comments