1 | import es6Promise from 'es6-promise';
|
2 | import head from 'lodash/head';
|
3 | import keys from 'lodash/keys';
|
4 | import camelCase from 'lodash/camelCase';
|
5 | import concat from 'lodash/concat';
|
6 | import get from 'lodash/get';
|
7 | import isArray from 'lodash/isArray';
|
8 | import isEmpty from 'lodash/isEmpty';
|
9 | import kebabCase from 'lodash/kebabCase';
|
10 | import pullAll from 'lodash/pullAll';
|
11 | import snakeCase from 'lodash/snakeCase';
|
12 | import uniq from 'lodash/uniq';
|
13 | import falcorPathParser from 'falcor-path-syntax';
|
14 | import map from 'lodash/map';
|
15 | import isNil from 'lodash/isNil';
|
16 | import { stringify } from 'querystring';
|
17 | import filter from 'lodash/filter';
|
18 | import forEach from 'lodash/forEach';
|
19 | import isError from 'lodash/isError';
|
20 | import isFunction from 'lodash/isFunction';
|
21 | import last from 'lodash/last';
|
22 | import nth from 'lodash/nth';
|
23 | import some from 'lodash/some';
|
24 |
|
25 | var name = 'audioCategory';
|
26 | var pluralName = 'audioCategories';
|
27 |
|
28 | var defaultProperties = ['id', 'name'];
|
29 |
|
30 | var audioCategory = Object.freeze({
|
31 | name: name,
|
32 | pluralName: pluralName,
|
33 | defaultProperties: defaultProperties
|
34 | });
|
35 |
|
36 | var name$1 = 'audioTrack';
|
37 | var pluralName$1 = 'audioTracks';
|
38 |
|
39 | var defaultProperties$1 = ['id', 'name', 'author', 'duration', 'src'];
|
40 |
|
41 | var audioTrack = Object.freeze({
|
42 | name: name$1,
|
43 | pluralName: pluralName$1,
|
44 | defaultProperties: defaultProperties$1
|
45 | });
|
46 |
|
47 | var name$2 = 'champion';
|
48 | var pluralName$2 = 'champions';
|
49 |
|
50 | var defaultProperties$2 = ['id'];
|
51 |
|
52 | var champion = Object.freeze({
|
53 | name: name$2,
|
54 | pluralName: pluralName$2,
|
55 | defaultProperties: defaultProperties$2
|
56 | });
|
57 |
|
58 | var name$3 = 'cohort';
|
59 | var pluralName$3 = 'cohorts';
|
60 |
|
61 | var defaultProperties$3 = ['id', 'name', 'description'];
|
62 |
|
63 | var cohort = Object.freeze({
|
64 | name: name$3,
|
65 | pluralName: pluralName$3,
|
66 | defaultProperties: defaultProperties$3
|
67 | });
|
68 |
|
69 | var DEFAULT_FROM_INDEX = 0;
|
70 | var DEFAULT_TO_INDEX = 19;
|
71 | var MY_PATH_KEYWORD = 'self';
|
72 |
|
73 | function buildPaging(options) {
|
74 | return {
|
75 | from: get(options, 'paging.from') || DEFAULT_FROM_INDEX,
|
76 | to: get(options, 'paging.to') || DEFAULT_TO_INDEX
|
77 | };
|
78 | }
|
79 |
|
80 | function buildProperties(defaults, options) {
|
81 | var properties = concat([], options.properties || defaults);
|
82 |
|
83 | var toAnd = options.andProperties;
|
84 | if (isArray(toAnd) && !isEmpty(toAnd)) {
|
85 | properties = concat(properties, toAnd);
|
86 | }
|
87 |
|
88 | var toNot = options.notProperties;
|
89 | if (isArray(toNot) && !isEmpty(toNot)) {
|
90 | properties = pullAll(properties, toNot);
|
91 | }
|
92 |
|
93 | properties = uniq(properties);
|
94 |
|
95 | return properties;
|
96 | }
|
97 |
|
98 | function entityNameToFilename(name) {
|
99 | return kebabCase(name) + '.js';
|
100 | }
|
101 |
|
102 | function entityToAPIEnvelopeKey(entity) {
|
103 | return snakeCase(entity.name);
|
104 | }
|
105 |
|
106 | function entityToFalcorListLeaf(entity) {
|
107 | return snakeCase(entity.name) + '_list';
|
108 | }
|
109 |
|
110 | function entityToFalcorMembershipsListLeaf(entity) {
|
111 | return 'membership_' + entityToFalcorListLeaf(entity);
|
112 | }
|
113 |
|
114 | function entityToFalcorMyListLeaf(entity) {
|
115 | return 'my_' + entityToFalcorListLeaf(entity);
|
116 | }
|
117 |
|
118 | function entityToFalcorRootLeaf(entity) {
|
119 | return snakeCase(entity.pluralName);
|
120 | }
|
121 |
|
122 | function falcorListLeafToEntityName(listLeaf) {
|
123 | return camelCase(listLeaf.replace(/_list$/, ''));
|
124 | }
|
125 |
|
126 | function falcorRootLeafToEntityName(rootLeaf) {
|
127 | return camelCase(rootLeaf);
|
128 | }
|
129 |
|
130 | function optionsHasQuery(options) {
|
131 | return keys(options.query).length > 0;
|
132 | }
|
133 |
|
134 | var name$4 = 'comment';
|
135 | var pluralName$4 = 'comments';
|
136 |
|
137 | var defaultProperties$4 = ['id', 'body', 'markup_tokens', 'post', 'owner.id', 'owner.first_name', 'owner.last_name', 'owner.name', 'owner.avatar.src', 'created_at'];
|
138 |
|
139 | function invalidateAfterCreate() {
|
140 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
141 |
|
142 | var parentEntityName = head(keys(options.parent));
|
143 | var parentEntity = entities[parentEntityName];
|
144 | var parentId = options.parent[parentEntityName].id;
|
145 |
|
146 | var rootLeaf = entityToFalcorRootLeaf(parentEntity);
|
147 |
|
148 | var paths = [[rootLeaf, parentId, 'comment_list'], [rootLeaf, parentId, 'comment_count']];
|
149 |
|
150 | return paths;
|
151 | }
|
152 |
|
153 |
|
154 |
|
155 | function invalidateAfterDestroy() {
|
156 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
157 |
|
158 | var rootEntityLeaf = entityToFalcorRootLeaf({ pluralName: pluralName$4 });
|
159 | var entityId = options.id;
|
160 |
|
161 | var parentEntityName = head(keys(options.parent));
|
162 | var parentEntity = entities[parentEntityName];
|
163 | var rootParentLeaf = entityToFalcorRootLeaf(parentEntity);
|
164 | var parentId = options.parent[parentEntityName].id;
|
165 |
|
166 | var paths = [[rootEntityLeaf, entityId], [rootParentLeaf, parentId, 'comment_list'], [rootParentLeaf, parentId, 'comment_count']];
|
167 |
|
168 | return paths;
|
169 | }
|
170 |
|
171 | var comment = Object.freeze({
|
172 | name: name$4,
|
173 | pluralName: pluralName$4,
|
174 | defaultProperties: defaultProperties$4,
|
175 | invalidateAfterCreate: invalidateAfterCreate,
|
176 | invalidateAfterDestroy: invalidateAfterDestroy
|
177 | });
|
178 |
|
179 | var name$5 = 'directMessage';
|
180 | var pluralName$5 = 'directMessages';
|
181 |
|
182 | var defaultProperties$5 = ['id', 'name'];
|
183 |
|
184 | var directMessage = Object.freeze({
|
185 | name: name$5,
|
186 | pluralName: pluralName$5,
|
187 | defaultProperties: defaultProperties$5
|
188 | });
|
189 |
|
190 | var name$6 = 'featuredContent';
|
191 | var pluralName$6 = 'featuredContents';
|
192 |
|
193 | var defaultProperties$6 = ['id', 'content_id', 'content_type', 'new', 'position'];
|
194 |
|
195 | var featuredContent = Object.freeze({
|
196 | name: name$6,
|
197 | pluralName: pluralName$6,
|
198 | defaultProperties: defaultProperties$6
|
199 | });
|
200 |
|
201 | var name$8 = 'post';
|
202 | var pluralName$8 = 'posts';
|
203 |
|
204 | var defaultProperties$7 = ['id', 'body'];
|
205 |
|
206 | var post = Object.freeze({
|
207 | name: name$8,
|
208 | pluralName: pluralName$8,
|
209 | defaultProperties: defaultProperties$7
|
210 | });
|
211 |
|
212 | var name$7 = 'feedPost';
|
213 | var pluralName$7 = 'feedPosts';
|
214 | function getMany() {
|
215 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
216 |
|
217 | var _buildPaging = buildPaging(options),
|
218 | from = _buildPaging.from,
|
219 | to = _buildPaging.to;
|
220 |
|
221 | var properties = buildProperties(defaultProperties$7, options);
|
222 | var listLeaf = entityToFalcorListLeaf({ name: name$7 });
|
223 |
|
224 | var paths = map(properties, function (property) {
|
225 | var propertyPath = falcorPathParser(property);
|
226 | var path = concat(['self', listLeaf, { from: from, to: to }], propertyPath);
|
227 |
|
228 | return path;
|
229 | });
|
230 |
|
231 | return paths;
|
232 | }
|
233 |
|
234 | function extractMany() {
|
235 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
236 | var jsonGraph = arguments[1];
|
237 |
|
238 | var listLeaf = entityToFalcorListLeaf({ name: name$7 });
|
239 | var postList = jsonGraph.json.self[listLeaf];
|
240 |
|
241 | var posts = map(postList, function (post) {
|
242 | return post;
|
243 | });
|
244 |
|
245 | return posts;
|
246 | }
|
247 |
|
248 | var feedPost = Object.freeze({
|
249 | name: name$7,
|
250 | pluralName: pluralName$7,
|
251 | defaultProperties: defaultProperties$7,
|
252 | getMany: getMany,
|
253 | extractMany: extractMany
|
254 | });
|
255 |
|
256 | var name$9 = 'growthAction';
|
257 | var pluralName$9 = 'growthActions';
|
258 |
|
259 | var defaultProperties$8 = ['id', 'agent.id', 'agent.name', 'growee.id', 'growee.name', 'relationship.id', 'relationship.owner.id', 'growth_relationship_id', 'state', 'title', 'due_at', 'trigger_prompt_at', 'completed_at', 'progress_current', 'progress_total'];
|
260 |
|
261 | var growthAction = Object.freeze({
|
262 | name: name$9,
|
263 | pluralName: pluralName$9,
|
264 | defaultProperties: defaultProperties$8
|
265 | });
|
266 |
|
267 | var name$10 = 'growthRelationship';
|
268 | var pluralName$10 = 'growthRelationships';
|
269 |
|
270 | var defaultProperties$9 = ['id', 'owner_type', 'owner.id', 'owner.name', 'growee.id', 'growee.name', 'agent.id', 'agent.name'];
|
271 |
|
272 | var growthRelationship = Object.freeze({
|
273 | name: name$10,
|
274 | pluralName: pluralName$10,
|
275 | defaultProperties: defaultProperties$9
|
276 | });
|
277 |
|
278 | var name$11 = 'growthAgentPrompt';
|
279 | var pluralName$11 = 'growthAgentPrompts';
|
280 |
|
281 | var defaultProperties$10 = ['id', 'title', 'state', 'type', 'display_type', 'status', 'action.id', 'action.due_at', 'action.state', 'action.trigger_prompt_at', 'action.progress_total', 'action.progress_current', 'action.growee.id', 'action.growee.name', 'action.growee.email', 'action.growee.avatar.id', 'action.growee.avatar.src', 'action.agent.id', 'action.agent.name', 'action.relationship.id', 'action.relationship.owner.id'];
|
282 |
|
283 | var growthAgentPrompt = Object.freeze({
|
284 | name: name$11,
|
285 | pluralName: pluralName$11,
|
286 | defaultProperties: defaultProperties$10
|
287 | });
|
288 |
|
289 | var name$12 = 'growthAgentResponse';
|
290 | var pluralName$12 = 'growthAgentResponses';
|
291 |
|
292 | var defaultProperties$11 = ['id', 'message'];
|
293 |
|
294 | var growthAgentResponse = Object.freeze({
|
295 | name: name$12,
|
296 | pluralName: pluralName$12,
|
297 | defaultProperties: defaultProperties$11
|
298 | });
|
299 |
|
300 | var name$13 = 'license';
|
301 | var pluralName$13 = 'licenses';
|
302 |
|
303 | var defaultProperties$12 = ['id', 'updated_at'];
|
304 |
|
305 | var license = Object.freeze({
|
306 | name: name$13,
|
307 | pluralName: pluralName$13,
|
308 | defaultProperties: defaultProperties$12
|
309 | });
|
310 |
|
311 | var name$14 = 'licensedCohort';
|
312 | var pluralName$14 = 'licensedCohorts';
|
313 |
|
314 | var defaultProperties$13 = ['id', 'updated_at'];
|
315 |
|
316 | var licensedCohort = Object.freeze({
|
317 | name: name$14,
|
318 | pluralName: pluralName$14,
|
319 | defaultProperties: defaultProperties$13
|
320 | });
|
321 |
|
322 | var name$15 = 'licensedContentItem';
|
323 | var pluralName$15 = 'licensedContentItems';
|
324 |
|
325 | var defaultProperties$14 = ['id', 'updated_at'];
|
326 |
|
327 | var licensedContentItem = Object.freeze({
|
328 | name: name$15,
|
329 | pluralName: pluralName$15,
|
330 | defaultProperties: defaultProperties$14
|
331 | });
|
332 |
|
333 | var name$16 = 'moment';
|
334 | var pluralName$16 = 'moments';
|
335 |
|
336 | var defaultProperties$15 = ['id', 'description', 'title', 'owner_type', 'owner.name', 'owner.avatar.src', 'owner.icon.src', 'cover_image_media.id', 'cover_image_media.src', 'background_music.src', 'background_music.duration', 'background_music.author'];
|
337 |
|
338 | var moment = Object.freeze({
|
339 | name: name$16,
|
340 | pluralName: pluralName$16,
|
341 | defaultProperties: defaultProperties$15
|
342 | });
|
343 |
|
344 | var name$17 = 'myGrowthAgentPrompt';
|
345 | var pluralName$17 = 'myGrowthAgentPrompts';
|
346 |
|
347 | var defaultProperties$16 = ['id', 'title', 'state', 'type', 'display_type', 'status', 'action.id', 'action.due_at', 'action.state', 'action.trigger_prompt_at', 'action.progress_total', 'action.progress_current', 'action.growee.id', 'action.growee.name', 'action.growee.email', 'action.growee.avatar.id', 'action.growee.avatar.src', 'action.agent.id', 'action.agent.name', 'action.relationship.id', 'action.relationship.owner.id'];
|
348 |
|
349 | function getMany$1() {
|
350 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
351 |
|
352 | var _buildPaging = buildPaging(options),
|
353 | from = _buildPaging.from,
|
354 | to = _buildPaging.to;
|
355 |
|
356 | var properties = buildProperties(defaultProperties$16, options);
|
357 | var listLeaf = entityToFalcorListLeaf({ name: name$17 });
|
358 |
|
359 | var paths = map(properties, function (property) {
|
360 | var propertyPath = falcorPathParser(property);
|
361 | var path = concat(['self', listLeaf, { from: from, to: to }], propertyPath);
|
362 |
|
363 | return path;
|
364 | });
|
365 |
|
366 | return paths;
|
367 | }
|
368 |
|
369 | function extractMany$1() {
|
370 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
371 | var jsonGraph = arguments[1];
|
372 |
|
373 | var listLeaf = entityToFalcorListLeaf({ name: name$17 });
|
374 | var viewList = jsonGraph.json.self[listLeaf];
|
375 |
|
376 | var views = map(viewList, function (view) {
|
377 | return view;
|
378 | });
|
379 |
|
380 | return views;
|
381 | }
|
382 |
|
383 | var myGrowthAgentPrompt = Object.freeze({
|
384 | name: name$17,
|
385 | pluralName: pluralName$17,
|
386 | defaultProperties: defaultProperties$16,
|
387 | getMany: getMany$1,
|
388 | extractMany: extractMany$1
|
389 | });
|
390 |
|
391 | var name$19 = 'review';
|
392 | var pluralName$19 = 'reviews';
|
393 |
|
394 | var defaultProperties$17 = ['id', 'rating'];
|
395 |
|
396 | var review = Object.freeze({
|
397 | name: name$19,
|
398 | pluralName: pluralName$19,
|
399 | defaultProperties: defaultProperties$17
|
400 | });
|
401 |
|
402 | var name$20 = 'tree';
|
403 | var pluralName$20 = 'trees';
|
404 |
|
405 | var treeEntity = Object.freeze({
|
406 | name: name$20,
|
407 | pluralName: pluralName$20
|
408 | });
|
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 | var name$18 = 'myTreeReview';
|
417 | var pluralName$18 = 'myTreeReviews';
|
418 | function getOne() {
|
419 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
420 | var tree = options.tree;
|
421 |
|
422 |
|
423 | if (isNil(tree) || isNil(tree.id)) {
|
424 | return new Error("options.tree.id is required when getting the current user's tree review");
|
425 | }
|
426 |
|
427 | var properties = buildProperties(defaultProperties$17, options);
|
428 |
|
429 | var paths = properties.map(function (property) {
|
430 | var rootLeaf = entityToFalcorRootLeaf(treeEntity);
|
431 | var path = falcorPathParser(property);
|
432 |
|
433 | return concat([rootLeaf, tree.id, 'my_review'], path);
|
434 | });
|
435 |
|
436 | return paths;
|
437 | }
|
438 |
|
439 | function extractOne() {
|
440 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
441 | var jsonGraph = arguments[1];
|
442 | var tree = options.tree;
|
443 |
|
444 |
|
445 | if (isNil(tree) || isNil(tree.id)) {
|
446 | return new Error("options.tree.id is required when getting the current user's tree review");
|
447 | }
|
448 |
|
449 | var rootLeaf = entityToFalcorRootLeaf(treeEntity);
|
450 |
|
451 | return jsonGraph.json[rootLeaf][tree.id].my_review;
|
452 | }
|
453 |
|
454 | var myTreeReview = Object.freeze({
|
455 | name: name$18,
|
456 | pluralName: pluralName$18,
|
457 | defaultProperties: defaultProperties$17,
|
458 | getOne: getOne,
|
459 | extractOne: extractOne
|
460 | });
|
461 |
|
462 | var name$21 = 'note';
|
463 | var pluralName$21 = 'notes';
|
464 |
|
465 | var defaultProperties$18 = ['id', 'body'];
|
466 |
|
467 | var note = Object.freeze({
|
468 | name: name$21,
|
469 | pluralName: pluralName$21,
|
470 | defaultProperties: defaultProperties$18
|
471 | });
|
472 |
|
473 | var name$22 = 'progressItem';
|
474 | var pluralName$22 = 'progressItems';
|
475 |
|
476 | var defaultProperties$19 = ['id', 'action', 'title', 'description', 'completed', 'hidden', 'assigner_type', 'linkable_type', 'updated_at', 'date_due'];
|
477 |
|
478 | var progressItem = Object.freeze({
|
479 | name: name$22,
|
480 | pluralName: pluralName$22,
|
481 | defaultProperties: defaultProperties$19
|
482 | });
|
483 |
|
484 | var name$23 = 'space';
|
485 | var pluralName$23 = 'spaces';
|
486 |
|
487 | var defaultProperties$20 = ['id', 'name', 'topic'];
|
488 |
|
489 | var space = Object.freeze({
|
490 | name: name$23,
|
491 | pluralName: pluralName$23,
|
492 | defaultProperties: defaultProperties$20
|
493 | });
|
494 |
|
495 | var name$24 = 'timeline';
|
496 | var pluralName$24 = 'timelines';
|
497 |
|
498 | var timeline = Object.freeze({
|
499 | name: name$24,
|
500 | pluralName: pluralName$24
|
501 | });
|
502 |
|
503 | var name$25 = 'toDoItem';
|
504 | var pluralName$25 = 'toDoItems';
|
505 |
|
506 | var defaultProperties$21 = ['id', 'title', 'description', 'action', 'date_due'];
|
507 |
|
508 | var toDoItem = Object.freeze({
|
509 | name: name$25,
|
510 | pluralName: pluralName$25,
|
511 | defaultProperties: defaultProperties$21
|
512 | });
|
513 |
|
514 | var name$26 = 'toDoList';
|
515 | var pluralName$26 = 'toDoLists';
|
516 |
|
517 | var defaultProperties$22 = ['id', 'name', 'created_at', 'updated_at'];
|
518 |
|
519 | var toDoList = Object.freeze({
|
520 | name: name$26,
|
521 | pluralName: pluralName$26,
|
522 | defaultProperties: defaultProperties$22
|
523 | });
|
524 |
|
525 | var name$27 = 'topic';
|
526 | var pluralName$27 = 'topics';
|
527 |
|
528 | var defaultProperties$23 = ['id', 'name'];
|
529 |
|
530 | var topic = Object.freeze({
|
531 | name: name$27,
|
532 | pluralName: pluralName$27,
|
533 | defaultProperties: defaultProperties$23
|
534 | });
|
535 |
|
536 | var name$28 = 'tourTipView';
|
537 | var pluralName$28 = 'tourTipViews';
|
538 |
|
539 | var defaultProperties$24 = ['id', 'state'];
|
540 |
|
541 | function getMany$2() {
|
542 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
543 |
|
544 | var _buildPaging = buildPaging(options),
|
545 | from = _buildPaging.from,
|
546 | to = _buildPaging.to;
|
547 |
|
548 | var properties = buildProperties(defaultProperties$24, options);
|
549 | var listLeaf = entityToFalcorListLeaf({ name: name$28 });
|
550 |
|
551 | var paths = map(properties, function (property) {
|
552 | var propertyPath = falcorPathParser(property);
|
553 | var path = concat(['self', listLeaf, { from: from, to: to }], propertyPath);
|
554 |
|
555 | return path;
|
556 | });
|
557 |
|
558 | return paths;
|
559 | }
|
560 |
|
561 | function extractMany$2() {
|
562 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
563 | var jsonGraph = arguments[1];
|
564 |
|
565 | var listLeaf = entityToFalcorListLeaf({ name: name$28 });
|
566 | var viewList = jsonGraph.json.self[listLeaf];
|
567 |
|
568 | var views = map(viewList, function (view) {
|
569 | return view;
|
570 | });
|
571 |
|
572 | return views;
|
573 | }
|
574 |
|
575 | var tourTipView = Object.freeze({
|
576 | name: name$28,
|
577 | pluralName: pluralName$28,
|
578 | defaultProperties: defaultProperties$24,
|
579 | getMany: getMany$2,
|
580 | extractMany: extractMany$2
|
581 | });
|
582 |
|
583 | var name$29 = 'user';
|
584 | var pluralName$29 = 'users';
|
585 |
|
586 | var defaultProperties$25 = ['id', 'username', 'name'];
|
587 |
|
588 | var user = Object.freeze({
|
589 | name: name$29,
|
590 | pluralName: pluralName$29,
|
591 | defaultProperties: defaultProperties$25
|
592 | });
|
593 |
|
594 | var name$30 = 'userToDoList';
|
595 | var pluralName$30 = 'userToDoLists';
|
596 |
|
597 | var defaultProperties$26 = ['id', 'name'];
|
598 |
|
599 | var userToDoList = Object.freeze({
|
600 | name: name$30,
|
601 | pluralName: pluralName$30,
|
602 | defaultProperties: defaultProperties$26
|
603 | });
|
604 |
|
605 | var name$31 = 'view';
|
606 | var pluralName$31 = 'views';
|
607 |
|
608 | var defaultProperties$27 = ['id', 'viewable_id', 'viewable_type'];
|
609 |
|
610 | var view = Object.freeze({
|
611 | name: name$31,
|
612 | pluralName: pluralName$31,
|
613 | defaultProperties: defaultProperties$27
|
614 | });
|
615 |
|
616 |
|
617 |
|
618 | var entities = Object.freeze({
|
619 | audioCategory: audioCategory,
|
620 | audioTrack: audioTrack,
|
621 | champion: champion,
|
622 | cohort: cohort,
|
623 | comment: comment,
|
624 | directMessage: directMessage,
|
625 | featuredContent: featuredContent,
|
626 | feedPost: feedPost,
|
627 | growthAction: growthAction,
|
628 | growthRelationship: growthRelationship,
|
629 | growthAgentPrompt: growthAgentPrompt,
|
630 | growthAgentResponse: growthAgentResponse,
|
631 | license: license,
|
632 | licensedCohort: licensedCohort,
|
633 | licensedContentItem: licensedContentItem,
|
634 | moment: moment,
|
635 | myGrowthAgentPrompt: myGrowthAgentPrompt,
|
636 | myTreeReview: myTreeReview,
|
637 | note: note,
|
638 | post: post,
|
639 | progressItem: progressItem,
|
640 | review: review,
|
641 | space: space,
|
642 | timeline: timeline,
|
643 | toDoItem: toDoItem,
|
644 | toDoList: toDoList,
|
645 | topic: topic,
|
646 | tourTipView: tourTipView,
|
647 | tree: treeEntity,
|
648 | user: user,
|
649 | userToDoList: userToDoList,
|
650 | view: view
|
651 | });
|
652 |
|
653 | var entitySrc = 'entities';
|
654 |
|
655 | function entityIsUndefinedError(entityName) {
|
656 | var filename = entityNameToFilename(entityName);
|
657 | return new Error('The ' + entityName + ' entity is undefined. Ensure ' + entitySrc + '/' + filename + ' exists and is exported by ' + entitySrc + '/_catalog.js');
|
658 | }
|
659 |
|
660 | function entityMustExportError(entityName, property) {
|
661 | var filename = entityNameToFilename(entityName);
|
662 | return new Error(entitySrc + '/' + filename + ' must export ' + property);
|
663 | }
|
664 |
|
665 | function optionsMustHaveError(property) {
|
666 | return new Error('options.' + property + ' is required');
|
667 | }
|
668 |
|
669 | function entityExports(entity, property) {
|
670 | return !isNil(entity[property]);
|
671 | }
|
672 |
|
673 |
|
674 |
|
675 | function optionsHas(options, property) {
|
676 | return !isNil(get(options, property));
|
677 | }
|
678 |
|
679 | 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; }
|
680 |
|
681 | function getOne$1(entityName, entity) {
|
682 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
683 |
|
684 | if (!entityExports(entity, 'pluralName')) {
|
685 | return entityMustExportError(entityName, 'pluralName');
|
686 | }
|
687 |
|
688 | if (!entityExports(entity, 'defaultProperties')) {
|
689 | return entityMustExportError(entityName, 'defaultProperties');
|
690 | }
|
691 |
|
692 | if (!optionsHas(options, 'id')) {
|
693 | return optionsMustHaveError('id');
|
694 | }
|
695 |
|
696 | var properties = buildProperties(entity.defaultProperties, options);
|
697 | var rootLeaf = entityToFalcorRootLeaf(entity);
|
698 |
|
699 | var paths = map(properties, function (property) {
|
700 | var propertyPath = falcorPathParser(property);
|
701 | var path = concat([rootLeaf, options.id], propertyPath);
|
702 |
|
703 | return path;
|
704 | });
|
705 |
|
706 | return paths;
|
707 | }
|
708 |
|
709 | function extractOne$1(entity) {
|
710 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
711 | var jsonGraph = arguments[2];
|
712 |
|
713 | var rootLeaf = entityToFalcorRootLeaf(entity);
|
714 | var extractedEntity = jsonGraph.json[rootLeaf][options.id];
|
715 |
|
716 | return extractedEntity;
|
717 | }
|
718 |
|
719 | function getMany$3(entityName, entity) {
|
720 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
721 |
|
722 | if (!entityExports(entity, 'name')) {
|
723 | return entityMustExportError(entityName, 'name');
|
724 | }
|
725 |
|
726 | if (!entityExports(entity, 'pluralName')) {
|
727 | return entityMustExportError(entityName, 'pluralName');
|
728 | }
|
729 |
|
730 | if (!entityExports(entity, 'defaultProperties')) {
|
731 | return entityMustExportError(entityName, 'defaultProperties');
|
732 | }
|
733 |
|
734 | var _buildPaging = buildPaging(options),
|
735 | from = _buildPaging.from,
|
736 | to = _buildPaging.to;
|
737 |
|
738 | var properties = buildProperties(entity.defaultProperties, options);
|
739 |
|
740 | var parentEntity = void 0,
|
741 | parentOptions = void 0;
|
742 | if (!isNil(options.parent)) {
|
743 | var parentEntityName = head(keys(options.parent));
|
744 | parentEntity = entities[parentEntityName];
|
745 | parentOptions = options.parent[parentEntityName];
|
746 | }
|
747 |
|
748 | var basePath = void 0;
|
749 | if (parentEntity) {
|
750 | var rootLeaf = entityToFalcorRootLeaf(parentEntity);
|
751 | var listLeaf = entityToFalcorListLeaf(entity);
|
752 |
|
753 | basePath = [rootLeaf, parentOptions.id, listLeaf];
|
754 | } else {
|
755 | var _listLeaf = entityToFalcorListLeaf(entity);
|
756 |
|
757 | basePath = [_listLeaf];
|
758 | }
|
759 |
|
760 | if (optionsHasQuery(options)) {
|
761 | var qs = stringify(options.query);
|
762 | basePath = concat(basePath, qs);
|
763 | }
|
764 |
|
765 | basePath = concat(basePath, { from: from, to: to });
|
766 |
|
767 | var paths = map(properties, function (property) {
|
768 | var propertyPath = falcorPathParser(property);
|
769 | var path = concat(basePath, propertyPath);
|
770 |
|
771 | return path;
|
772 | });
|
773 |
|
774 | return paths;
|
775 | }
|
776 |
|
777 | function extractMany$3(entity) {
|
778 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
779 | var jsonGraph = arguments[2];
|
780 |
|
781 | var parentEntity = void 0,
|
782 | parentOptions = void 0;
|
783 | if (!isNil(options.parent)) {
|
784 | var parentEntityName = head(keys(options.parent));
|
785 | parentEntity = entities[parentEntityName];
|
786 | parentOptions = options.parent[parentEntityName];
|
787 | }
|
788 |
|
789 | var entityList = void 0;
|
790 | if (parentEntity) {
|
791 | var parentRootLeaf = entityToFalcorRootLeaf(parentEntity);
|
792 | var entityListLeaf = entityToFalcorListLeaf(entity);
|
793 |
|
794 | entityList = jsonGraph.json[parentRootLeaf][parentOptions.id][entityListLeaf];
|
795 | } else {
|
796 | var listLeaf = entityToFalcorListLeaf(entity);
|
797 |
|
798 | entityList = jsonGraph.json[listLeaf];
|
799 | }
|
800 |
|
801 | if (optionsHasQuery(options)) {
|
802 | var qs = stringify(options.query);
|
803 | entityList = entityList[qs];
|
804 | }
|
805 |
|
806 | var extractedEntities = map(entityList, function (entity) {
|
807 | return entity;
|
808 | });
|
809 |
|
810 | return extractedEntities;
|
811 | }
|
812 |
|
813 | function getMy(entityName, entity) {
|
814 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
815 |
|
816 | if (!entityExports(entity, 'name')) {
|
817 | return entityMustExportError(entityName, 'name');
|
818 | }
|
819 |
|
820 | if (!entityExports(entity, 'defaultProperties')) {
|
821 | return entityMustExportError(entityName, 'defaultProperties');
|
822 | }
|
823 |
|
824 | var _buildPaging2 = buildPaging(options),
|
825 | from = _buildPaging2.from,
|
826 | to = _buildPaging2.to;
|
827 |
|
828 | var properties = buildProperties(entity.defaultProperties, options);
|
829 | var listLeaf = entityToFalcorMyListLeaf(entity);
|
830 | var basePath = [MY_PATH_KEYWORD, listLeaf];
|
831 |
|
832 | if (optionsHasQuery(options)) {
|
833 | var qs = stringify(options.query);
|
834 | basePath = concat(basePath, qs);
|
835 | }
|
836 |
|
837 | basePath = concat(basePath, { from: from, to: to });
|
838 |
|
839 | var paths = map(properties, function (property) {
|
840 | var propertyPath = falcorPathParser(property);
|
841 | var path = concat(basePath, propertyPath);
|
842 |
|
843 | return path;
|
844 | });
|
845 |
|
846 | return paths;
|
847 | }
|
848 |
|
849 | function extractMy(entity) {
|
850 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
851 | var jsonGraph = arguments[2];
|
852 |
|
853 | var listLeaf = entityToFalcorMyListLeaf(entity);
|
854 | var entityList = jsonGraph.json[MY_PATH_KEYWORD][listLeaf];
|
855 |
|
856 | if (optionsHasQuery(options)) {
|
857 | var qs = stringify(options.query);
|
858 | entityList = entityList[qs];
|
859 | }
|
860 |
|
861 | var extractedEntities = map(entityList, function (entity) {
|
862 | return entity;
|
863 | });
|
864 |
|
865 | return extractedEntities;
|
866 | }
|
867 |
|
868 | function getMemberships(entityName, entity) {
|
869 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
870 |
|
871 | if (!entityExports(entity, 'name')) {
|
872 | return entityMustExportError(entityName, 'name');
|
873 | }
|
874 |
|
875 | if (!entityExports(entity, 'defaultProperties')) {
|
876 | return entityMustExportError(entityName, 'defaultProperties');
|
877 | }
|
878 |
|
879 | var _buildPaging3 = buildPaging(options),
|
880 | from = _buildPaging3.from,
|
881 | to = _buildPaging3.to;
|
882 |
|
883 | var properties = buildProperties(entity.defaultProperties, options);
|
884 | var listLeaf = entityToFalcorMembershipsListLeaf(entity);
|
885 | var basePath = [MY_PATH_KEYWORD, listLeaf];
|
886 |
|
887 | basePath = concat(basePath, { from: from, to: to });
|
888 |
|
889 | var paths = map(properties, function (property) {
|
890 | var propertyPath = falcorPathParser(property);
|
891 | var path = concat(basePath, propertyPath);
|
892 |
|
893 | return path;
|
894 | });
|
895 |
|
896 | return paths;
|
897 | }
|
898 |
|
899 | function extractMemberships(entity) {
|
900 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
901 | var jsonGraph = arguments[2];
|
902 |
|
903 | var listLeaf = entityToFalcorMembershipsListLeaf(entity);
|
904 | var entityList = jsonGraph.json[MY_PATH_KEYWORD][listLeaf];
|
905 |
|
906 | if (optionsHasQuery(options)) {
|
907 | var qs = stringify(options.query);
|
908 | entityList = entityList[qs];
|
909 | }
|
910 |
|
911 | var extractedEntities = map(entityList, function (entity) {
|
912 | return entity;
|
913 | });
|
914 |
|
915 | return extractedEntities;
|
916 | }
|
917 |
|
918 | function create(entityName, entity) {
|
919 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
920 |
|
921 | if (!entityExports(entity, 'name')) {
|
922 | return entityMustExportError(entityName, 'name');
|
923 | }
|
924 |
|
925 | if (!entityExports(entity, 'pluralName')) {
|
926 | return entityMustExportError(entityName, 'pluralName');
|
927 | }
|
928 |
|
929 | if (!optionsHas(options, entityName)) {
|
930 | return optionsMustHaveError(entityName);
|
931 | }
|
932 |
|
933 | var parentEntity = void 0,
|
934 | parentOptions = void 0;
|
935 | if (!isNil(options.parent)) {
|
936 | var parentEntityName = head(keys(options.parent));
|
937 | parentEntity = entities[parentEntityName];
|
938 | parentOptions = options.parent[parentEntityName];
|
939 |
|
940 | if (isNil(parentEntity)) {
|
941 | return entityIsUndefinedError(parentEntityName);
|
942 | }
|
943 |
|
944 | if (!entityExports(parentEntity, 'pluralName')) {
|
945 | return entityMustExportError(parentEntityName, 'pluralName');
|
946 | }
|
947 |
|
948 | if (!optionsHas(parentOptions, 'id')) {
|
949 | return optionsMustHaveError('parent.' + parentEntityName + '.id');
|
950 | }
|
951 | }
|
952 |
|
953 | var path = void 0;
|
954 | if (parentEntity) {
|
955 | var rootLeaf = entityToFalcorRootLeaf(parentEntity);
|
956 | var listLeaf = entityToFalcorListLeaf(entity);
|
957 |
|
958 | path = [rootLeaf, parentOptions.id, listLeaf, 'add'];
|
959 | } else {
|
960 | var _rootLeaf = entityToFalcorRootLeaf(entity);
|
961 |
|
962 | path = [_rootLeaf, 'create'];
|
963 | }
|
964 |
|
965 | var envelopeKey = entityToAPIEnvelopeKey(entity);
|
966 | var args = [_defineProperty({}, envelopeKey, options[entity.name])];
|
967 |
|
968 | return { path: path, args: args };
|
969 | }
|
970 |
|
971 | function extractCreated(entity) {
|
972 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
973 | var jsonGraph = arguments[2];
|
974 |
|
975 | var rootLeaf = entityToFalcorRootLeaf(entity);
|
976 | var entities = jsonGraph.json[rootLeaf];
|
977 | var first = head(keys(entities));
|
978 | var extractedEntity = entities[first];
|
979 |
|
980 | return extractedEntity;
|
981 | }
|
982 |
|
983 | function invalidateAfterCreate$1(entity) {
|
984 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
985 |
|
986 | if (!isNil(options.parent)) {
|
987 | var parentEntityName = head(keys(options.parent));
|
988 | var parentEntity = entities[parentEntityName];
|
989 | var parentId = options.parent[parentEntityName].id;
|
990 |
|
991 | var rootLeaf = entityToFalcorRootLeaf(parentEntity);
|
992 | var listLeaf = entityToFalcorListLeaf(entity);
|
993 |
|
994 | var paths = [[rootLeaf, parentId, listLeaf], [rootLeaf, parentId, listLeaf, 'length']];
|
995 |
|
996 | return paths;
|
997 | }
|
998 | }
|
999 |
|
1000 | function update(entityName, entity) {
|
1001 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
1002 |
|
1003 | if (!entityExports(entity, 'pluralName')) {
|
1004 | return entityMustExportError(entityName, 'pluralName');
|
1005 | }
|
1006 |
|
1007 | if (!optionsHas(options, 'id')) {
|
1008 | return optionsMustHaveError('id');
|
1009 | }
|
1010 |
|
1011 | if (keys(options).length === 1) {
|
1012 | return new Error('options must include at least one property to update');
|
1013 | }
|
1014 |
|
1015 | var properties = filter(keys(options), function (key) {
|
1016 | return key !== 'id';
|
1017 | });
|
1018 | var rootLeaf = entityToFalcorRootLeaf(entity);
|
1019 |
|
1020 | var paths = map(properties, function (property) {
|
1021 | var path = {
|
1022 | path: [rootLeaf, options.id, property],
|
1023 | value: options[property]
|
1024 | };
|
1025 |
|
1026 | return path;
|
1027 | });
|
1028 |
|
1029 | return paths;
|
1030 | }
|
1031 |
|
1032 | function extractUpdated(entity) {
|
1033 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
1034 | var jsonGraph = arguments[2];
|
1035 |
|
1036 | var rootLeaf = entityToFalcorRootLeaf(entity);
|
1037 | var updatedProperties = jsonGraph.json[rootLeaf][options.id];
|
1038 |
|
1039 | return updatedProperties;
|
1040 | }
|
1041 |
|
1042 | function destroy(entityName, entity) {
|
1043 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
1044 |
|
1045 | if (!entityExports(entity, 'pluralName')) {
|
1046 | return entityMustExportError(entityName, 'pluralName');
|
1047 | }
|
1048 |
|
1049 | if (!optionsHas(options, 'id')) {
|
1050 | return optionsMustHaveError('id');
|
1051 | }
|
1052 |
|
1053 | var rootLeaf = entityToFalcorRootLeaf(entity);
|
1054 | var destroyPath = [rootLeaf, options.id, 'delete'];
|
1055 |
|
1056 | return destroyPath;
|
1057 | }
|
1058 |
|
1059 | function invalidateAfterDestroy$1(entity) {
|
1060 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
1061 |
|
1062 | var rootEntityLeaf = entityToFalcorRootLeaf(entity);
|
1063 | var entityId = options.id;
|
1064 |
|
1065 | var paths = [[rootEntityLeaf, entityId]];
|
1066 |
|
1067 | if (!isNil(options.parent)) {
|
1068 | var parentEntityName = head(keys(options.parent));
|
1069 | var parentEntity = entities[parentEntityName];
|
1070 | var parentId = options.parent[parentEntityName].id;
|
1071 |
|
1072 | var rootParentLeaf = entityToFalcorRootLeaf(parentEntity);
|
1073 | var listLeaf = entityToFalcorListLeaf(entity);
|
1074 |
|
1075 | paths.push([rootParentLeaf, parentId, listLeaf], [rootParentLeaf, parentId, listLeaf, 'length']);
|
1076 | }
|
1077 |
|
1078 | return paths;
|
1079 | }
|
1080 |
|
1081 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
1082 |
|
1083 | function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
1084 |
|
1085 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
1086 |
|
1087 | es6Promise.polyfill();
|
1088 |
|
1089 | var SuperGloo = function () {
|
1090 | function SuperGloo() {
|
1091 | var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
1092 |
|
1093 | _classCallCheck(this, SuperGloo);
|
1094 |
|
1095 | var requiredProperties = ['falcorModel'];
|
1096 |
|
1097 | if (some(requiredProperties, function (_) {
|
1098 | return isNil(get(config, _));
|
1099 | })) {
|
1100 | throw new Error('One of the following required config parameters is undefined: ' + requiredProperties.join(', '));
|
1101 | }
|
1102 |
|
1103 | this.falcor = config.falcorModel;
|
1104 | }
|
1105 |
|
1106 | |
1107 |
|
1108 |
|
1109 |
|
1110 | _createClass(SuperGloo, [{
|
1111 | key: 'setModel',
|
1112 | value: function setModel(model) {
|
1113 | if (isNil(model)) {
|
1114 | throw new Error('When setting the model, the model cannot be null or undefined');
|
1115 | }
|
1116 |
|
1117 | this.falcor = model;
|
1118 | }
|
1119 | }, {
|
1120 | key: 'getOne',
|
1121 | value: function getOne$$1(entityName) {
|
1122 | var _falcor;
|
1123 |
|
1124 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
1125 |
|
1126 | var entity = entities[entityName];
|
1127 |
|
1128 | if (isNil(entity)) {
|
1129 | return Promise.reject(entityIsUndefinedError(entityName));
|
1130 | }
|
1131 |
|
1132 | var paths = isFunction(entity.getOne) ? entity.getOne(options) : getOne$1(entityName, entity, options);
|
1133 |
|
1134 | if (isError(paths)) {
|
1135 | return Promise.reject(paths);
|
1136 | }
|
1137 |
|
1138 | return (_falcor = this.falcor).get.apply(_falcor, _toConsumableArray(paths)).then(function (jsonGraph) {
|
1139 | var extractedEntity = void 0;
|
1140 | if (isNil(get(jsonGraph, 'json'))) {
|
1141 | extractedEntity = null;
|
1142 | } else {
|
1143 | extractedEntity = isFunction(entity.extractOne) ? entity.extractOne(options, jsonGraph) : extractOne$1(entity, options, jsonGraph);
|
1144 | }
|
1145 |
|
1146 | return extractedEntity;
|
1147 | }).catch(function (response) {
|
1148 | var message = buildGetOneErrorMessage(response);
|
1149 | return Promise.reject(new Error(message));
|
1150 | });
|
1151 | }
|
1152 | }, {
|
1153 | key: 'getMany',
|
1154 | value: function getMany$$1(entityName) {
|
1155 | var _falcor2;
|
1156 |
|
1157 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
1158 |
|
1159 | var entity = entities[entityName];
|
1160 |
|
1161 | if (isNil(entity)) {
|
1162 | return Promise.reject(entityIsUndefinedError(entityName));
|
1163 | }
|
1164 |
|
1165 | var paths = isFunction(entity.getMany) ? entity.getMany(options) : getMany$3(entityName, entity, options);
|
1166 |
|
1167 | if (isError(paths)) {
|
1168 | return Promise.reject(paths);
|
1169 | }
|
1170 |
|
1171 | return (_falcor2 = this.falcor).get.apply(_falcor2, _toConsumableArray(paths)).then(function (jsonGraph) {
|
1172 | var extractedEntities = void 0;
|
1173 | if (isNil(get(jsonGraph, 'json'))) {
|
1174 | extractedEntities = null;
|
1175 | } else {
|
1176 | extractedEntities = isFunction(entity.extractMany) ? entity.extractMany(options, jsonGraph) : extractMany$3(entity, options, jsonGraph);
|
1177 | }
|
1178 |
|
1179 | return extractedEntities;
|
1180 | }).catch(function (response) {
|
1181 | var message = buildGetManyErrorMessage(response);
|
1182 | return Promise.reject(new Error(message));
|
1183 | });
|
1184 | }
|
1185 | }, {
|
1186 | key: 'getMy',
|
1187 | value: function getMy$$1(entityName) {
|
1188 | var _falcor3;
|
1189 |
|
1190 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
1191 |
|
1192 | var entity = entities[entityName];
|
1193 |
|
1194 | if (isNil(entity)) {
|
1195 | return Promise.reject(entityIsUndefinedError(entityName));
|
1196 | }
|
1197 |
|
1198 | var paths = isFunction(entity.getMy) ? entity.getMy(options) : getMy(entityName, entity, options);
|
1199 |
|
1200 | if (isError(paths)) {
|
1201 | return Promise.reject(paths);
|
1202 | }
|
1203 |
|
1204 | return (_falcor3 = this.falcor).get.apply(_falcor3, _toConsumableArray(paths)).then(function (jsonGraph) {
|
1205 | var extractedEntities = void 0;
|
1206 | if (isNil(get(jsonGraph, 'json'))) {
|
1207 | extractedEntities = null;
|
1208 | } else {
|
1209 | extractedEntities = isFunction(entity.extractMy) ? entity.extractMy(options, jsonGraph) : extractMy(entity, options, jsonGraph);
|
1210 | }
|
1211 |
|
1212 | return extractedEntities;
|
1213 | }).catch(function (response) {
|
1214 | var message = buildGetMyErrorMessage(response);
|
1215 | return Promise.reject(new Error(message));
|
1216 | });
|
1217 | }
|
1218 | }, {
|
1219 | key: 'getMemberships',
|
1220 | value: function getMemberships$$1(entityName) {
|
1221 | var _falcor4;
|
1222 |
|
1223 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
1224 |
|
1225 | var entity = entities[entityName];
|
1226 |
|
1227 | if (isNil(entity)) {
|
1228 | return Promise.reject(entityIsUndefinedError(entityName));
|
1229 | }
|
1230 |
|
1231 | var paths = isFunction(entity.getMemberships) ? entity.getMemberships(options) : getMemberships(entityName, entity, options);
|
1232 |
|
1233 | if (isError(paths)) {
|
1234 | return Promise.reject(paths);
|
1235 | }
|
1236 |
|
1237 | return (_falcor4 = this.falcor).get.apply(_falcor4, _toConsumableArray(paths)).then(function (jsonGraph) {
|
1238 | var extractedEntities = void 0;
|
1239 | if (isNil(get(jsonGraph, 'json'))) {
|
1240 | extractedEntities = null;
|
1241 | } else {
|
1242 | extractedEntities = isFunction(entity.extractMemberships) ? entity.extractMemberships(options, jsonGraph) : extractMemberships(entity, options, jsonGraph);
|
1243 | }
|
1244 |
|
1245 | return extractedEntities;
|
1246 | }).catch(function (response) {
|
1247 | var message = buildGetMembershipsErrorMessage(response);
|
1248 | return Promise.reject(new Error(message));
|
1249 | });
|
1250 | }
|
1251 | }, {
|
1252 | key: 'create',
|
1253 | value: function create$$1(entityName) {
|
1254 | var _this = this;
|
1255 |
|
1256 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
1257 |
|
1258 | var entity = entities[entityName];
|
1259 |
|
1260 | if (isNil(entity)) {
|
1261 | return Promise.reject(entityIsUndefinedError(entityName));
|
1262 | }
|
1263 |
|
1264 | var callOptions = isFunction(entity.create) ? entity.create(options) : create(entityName, entity, options);
|
1265 |
|
1266 | if (isError(callOptions)) {
|
1267 | return Promise.reject(callOptions);
|
1268 | }
|
1269 |
|
1270 | var path = callOptions.path,
|
1271 | args = callOptions.args;
|
1272 |
|
1273 |
|
1274 | return this.falcor.call(path, args).then(function (jsonGraph) {
|
1275 | var extractedEntity = void 0;
|
1276 | if (isNil(get(jsonGraph, 'json'))) {
|
1277 | extractedEntity = null;
|
1278 | } else {
|
1279 | extractedEntity = isFunction(entity.extractCreated) ? entity.extractCreated(options, jsonGraph) : extractCreated(entity, options, jsonGraph);
|
1280 | }
|
1281 |
|
1282 | var pathsToInvalidate = isFunction(entity.invalidateAfterCreate) ? entity.invalidateAfterCreate(options) : invalidateAfterCreate$1(entity, options);
|
1283 |
|
1284 | if (!isEmpty(pathsToInvalidate)) {
|
1285 | forEach(pathsToInvalidate, function (path) {
|
1286 | _this.falcor.invalidate(path);
|
1287 | });
|
1288 | }
|
1289 |
|
1290 | return extractedEntity;
|
1291 | }).catch(function (response) {
|
1292 | var message = buildCreateErrorMessage(response);
|
1293 | return Promise.reject(new Error(message));
|
1294 | });
|
1295 | }
|
1296 | }, {
|
1297 | key: 'update',
|
1298 | value: function update$$1(entityName) {
|
1299 | var _falcor5;
|
1300 |
|
1301 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
1302 |
|
1303 | var entity = entities[entityName];
|
1304 |
|
1305 | if (isNil(entity)) {
|
1306 | return Promise.reject(entityIsUndefinedError(entityName));
|
1307 | }
|
1308 |
|
1309 | var paths = isFunction(entity.update) ? entity.update(options) : update(entityName, entity, options);
|
1310 |
|
1311 | if (isError(paths)) {
|
1312 | return Promise.reject(paths);
|
1313 | }
|
1314 |
|
1315 | return (_falcor5 = this.falcor).set.apply(_falcor5, _toConsumableArray(paths)).then(function (jsonGraph) {
|
1316 | var updatedProperties = void 0;
|
1317 | if (isNil(get(jsonGraph, 'json'))) {
|
1318 | updatedProperties = null;
|
1319 | } else {
|
1320 | updatedProperties = isFunction(entity.extractUpdated) ? entity.extractUpdated(options, jsonGraph) : extractUpdated(entity, options, jsonGraph);
|
1321 | }
|
1322 |
|
1323 | return updatedProperties;
|
1324 | }).catch(function (response) {
|
1325 | var message = buildUpdateErrorMessage(response);
|
1326 | return Promise.reject(new Error(message));
|
1327 | });
|
1328 | }
|
1329 | }, {
|
1330 | key: 'destroy',
|
1331 | value: function destroy$$1(entityName) {
|
1332 | var _this2 = this;
|
1333 |
|
1334 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
1335 |
|
1336 | var entity = entities[entityName];
|
1337 |
|
1338 | if (isNil(entity)) {
|
1339 | return Promise.reject(entityIsUndefinedError(entityName));
|
1340 | }
|
1341 |
|
1342 | var destroyPath = isFunction(entity.destroy) ? entity.destroy(options) : destroy(entityName, entity, options);
|
1343 |
|
1344 | if (isError(destroyPath)) {
|
1345 | return Promise.reject(destroyPath);
|
1346 | }
|
1347 |
|
1348 | return this.falcor.call(destroyPath).then(function () {
|
1349 | var pathsToInvalidate = isFunction(entity.invalidateAfterDestroy) ? entity.invalidateAfterDestroy(options) : invalidateAfterDestroy$1(entity, options);
|
1350 |
|
1351 | if (!isEmpty(pathsToInvalidate)) {
|
1352 | forEach(pathsToInvalidate, function (path) {
|
1353 | _this2.falcor.invalidate(path);
|
1354 | });
|
1355 | }
|
1356 |
|
1357 | return 'Entity destroyed';
|
1358 | }).catch(function (response) {
|
1359 | var message = buildDestroyErrorMessage(response);
|
1360 | return Promise.reject(new Error(message));
|
1361 | });
|
1362 | }
|
1363 | }]);
|
1364 |
|
1365 | return SuperGloo;
|
1366 | }();
|
1367 |
|
1368 | var codeToMessageMap = {
|
1369 | 400: 'request is malformed',
|
1370 | 401: 'user is not authorized',
|
1371 | 403: 'user is forbidden',
|
1372 | 404: 'entity does not exist',
|
1373 | 422: 'entity is not valid',
|
1374 | default: 'unspecified error encountered'
|
1375 | };
|
1376 |
|
1377 | function buildGetOneErrorMessage(response) {
|
1378 | if (response instanceof Error) {
|
1379 | return response.message;
|
1380 | }
|
1381 |
|
1382 | var firstPath = response[0];
|
1383 | var entity = camelCase(firstPath.path[0]);
|
1384 | var entityId = firstPath.path[1];
|
1385 | var originalMessage = firstPath.value.message || firstPath.value;
|
1386 |
|
1387 | var match = originalMessage.match(/\b[4,5][0-9][0-9]\b/);
|
1388 | var code = !isNil(match) && !isNil(codeToMessageMap[match[0]]) ? match[0] : 'default';
|
1389 |
|
1390 | var improvedMessage = codeToMessageMap[code];
|
1391 |
|
1392 | return 'Could not get ' + entity + ' ' + entityId + ': ' + improvedMessage + ' (' + originalMessage + ')';
|
1393 | }
|
1394 |
|
1395 | function buildGetManyErrorMessage(response) {
|
1396 | if (response instanceof Error) {
|
1397 | return response.message;
|
1398 | }
|
1399 |
|
1400 | var firstPath = response[0];
|
1401 | var entity = camelCase(firstPath.path[0]);
|
1402 | var originalMessage = firstPath.value.message || firstPath.value;
|
1403 |
|
1404 | var match = originalMessage.match(/\b[4,5][0-9][0-9]\b/);
|
1405 | var code = !isNil(match) && !isNil(codeToMessageMap[match[0]]) ? match[0] : 'default';
|
1406 |
|
1407 | var improvedMessage = codeToMessageMap[code];
|
1408 |
|
1409 | return 'Could not get many ' + entity + ': ' + improvedMessage + ' (' + originalMessage + ')';
|
1410 | }
|
1411 |
|
1412 | function buildGetMyErrorMessage(response) {
|
1413 | if (response instanceof Error) {
|
1414 | return response.message;
|
1415 | }
|
1416 |
|
1417 | var firstPath = response[0];
|
1418 | var entity = camelCase(firstPath.path[0]);
|
1419 | var originalMessage = firstPath.value.message || firstPath.value;
|
1420 |
|
1421 | var match = originalMessage.match(/\b[4,5][0-9][0-9]\b/);
|
1422 | var code = !isNil(match) && !isNil(codeToMessageMap[match[0]]) ? match[0] : 'default';
|
1423 |
|
1424 | var improvedMessage = codeToMessageMap[code];
|
1425 |
|
1426 | return 'Could not get my ' + entity + ': ' + improvedMessage + ' (' + originalMessage + ')';
|
1427 | }
|
1428 |
|
1429 | function buildGetMembershipsErrorMessage(response) {
|
1430 | if (response instanceof Error) {
|
1431 | return response.message;
|
1432 | }
|
1433 |
|
1434 | var firstPath = response[0];
|
1435 | var entity = camelCase(firstPath.path[0]);
|
1436 | var originalMessage = firstPath.value.message || firstPath.value;
|
1437 |
|
1438 | var match = originalMessage.match(/\b[4,5][0-9][0-9]\b/);
|
1439 | var code = !isNil(match) && !isNil(codeToMessageMap[match[0]]) ? match[0] : 'default';
|
1440 |
|
1441 | var improvedMessage = codeToMessageMap[code];
|
1442 |
|
1443 | return 'Could not get ' + entity + ' memberships: ' + improvedMessage + ' (' + originalMessage + ')';
|
1444 | }
|
1445 |
|
1446 | function buildCreateErrorMessage(response) {
|
1447 | if (response instanceof Error) {
|
1448 | return response.message;
|
1449 | }
|
1450 |
|
1451 | var firstError = head(response);
|
1452 |
|
1453 | var entityName = void 0;
|
1454 | if (last(firstError.path) === 'add') {
|
1455 | var listLeaf = nth(firstError.path, -2);
|
1456 | entityName = falcorListLeafToEntityName(listLeaf);
|
1457 | } else {
|
1458 | var rootLeaf = head(firstError.path);
|
1459 | entityName = falcorRootLeafToEntityName(rootLeaf);
|
1460 | }
|
1461 |
|
1462 | var originalMessage = firstError.value.message || firstError.value;
|
1463 |
|
1464 | var match = originalMessage.match(/\b[4,5][0-9][0-9]\b/);
|
1465 | var code = !isNil(match) && !isNil(codeToMessageMap[match[0]]) ? match[0] : 'default';
|
1466 |
|
1467 | var improvedMessage = codeToMessageMap[code];
|
1468 |
|
1469 | return 'Could not create a new ' + entityName + ': ' + improvedMessage + ' (' + originalMessage + ')';
|
1470 | }
|
1471 |
|
1472 | function buildUpdateErrorMessage(response) {
|
1473 | if (response instanceof Error) {
|
1474 | return response.message;
|
1475 | }
|
1476 |
|
1477 | var firstPath = response[0];
|
1478 | var entity = camelCase(firstPath.path[0]);
|
1479 | var entityId = firstPath.path[1];
|
1480 | var originalMessage = firstPath.value.message || firstPath.value;
|
1481 |
|
1482 | var match = originalMessage.match(/\b[4,5][0-9][0-9]\b/);
|
1483 | var code = !isNil(match) && !isNil(codeToMessageMap[match[0]]) ? match[0] : 'default';
|
1484 |
|
1485 | var improvedMessage = codeToMessageMap[code];
|
1486 |
|
1487 | return 'Could not update ' + entity + ' ' + entityId + ': ' + improvedMessage + ' (' + originalMessage + ')';
|
1488 | }
|
1489 |
|
1490 | function buildDestroyErrorMessage(response) {
|
1491 | if (response instanceof Error) {
|
1492 | return response.message;
|
1493 | }
|
1494 |
|
1495 | var firstPath = response[0];
|
1496 | var entity = camelCase(firstPath.path[0]);
|
1497 | var entityId = firstPath.path[1];
|
1498 | var originalMessage = firstPath.value.message || firstPath.value;
|
1499 |
|
1500 | var match = originalMessage.match(/\b[4,5][0-9][0-9]\b/);
|
1501 | var code = !isNil(match) && !isNil(codeToMessageMap[match[0]]) ? match[0] : 'default';
|
1502 |
|
1503 | var improvedMessage = codeToMessageMap[code];
|
1504 |
|
1505 | return 'Could not destroy ' + entity + ' ' + entityId + ': ' + improvedMessage + ' (' + originalMessage + ')';
|
1506 | }
|
1507 |
|
1508 | export default SuperGloo;
|