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