New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

supergloo

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

supergloo - npm Package Compare versions

Comparing version 0.10.1 to 0.11.0

807

dist/supergloo.es.js
import es6Promise from 'es6-promise';
import falcorPathParser from 'falcor-path-syntax';
import map from 'lodash/map';
import head from 'lodash/head';
import keys from 'lodash/keys';
import camelCase from 'lodash/camelCase';
import concat from 'lodash/concat';

@@ -12,19 +13,12 @@ import get from 'lodash/get';

import uniq from 'lodash/uniq';
import falcorPathParser from 'falcor-path-syntax';
import map from 'lodash/map';
import isNil from 'lodash/isNil';
import filter from 'lodash/filter';
import isNil from 'lodash/isNil';
import keys from 'lodash/keys';
import camelCase from 'lodash/camelCase';
import head from 'lodash/head';
import isError from 'lodash/isError';
import isFunction from 'lodash/isFunction';
import last from 'lodash/last';
import nth from 'lodash/nth';
import some from 'lodash/some';
var name = 'comment';
var pluralName = 'comments';
var comment = Object.freeze({
name: name,
pluralName: pluralName
});
var DEFAULT_FROM_INDEX = 0;

@@ -59,5 +53,9 @@ var DEFAULT_TO_INDEX = 19;

function entityNameToFilename(name) {
return kebabCase(name);
return kebabCase(name) + '.js';
}
function entityToAPIEnvelopeKey(entity) {
return snakeCase(entity.name);
}
function entityToFalcorListLeaf(entity) {

@@ -71,2 +69,33 @@ return snakeCase(entity.name) + '_list';

function falcorListLeafToEntityName(listLeaf) {
return camelCase(listLeaf.replace(/_list$/, ''));
}
function falcorRootLeafToEntityName(rootLeaf) {
return camelCase(rootLeaf);
}
var name = 'comment';
var pluralName = 'comments';
function invalidateAfterCreate() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var parentEntityName = head(keys(options.parent));
var parentEntity = entities[parentEntityName];
var parentId = options.parent[parentEntityName].id;
var rootLeaf = entityToFalcorRootLeaf(parentEntity);
var paths = [[rootLeaf, parentId, 'comment_list'], [rootLeaf, parentId, 'comment_count']];
return paths;
}
var comment = Object.freeze({
name: name,
pluralName: pluralName,
invalidateAfterCreate: invalidateAfterCreate
});
var name$2 = 'post';

@@ -84,5 +113,3 @@ var pluralName$2 = 'posts';

var name$1 = 'feedPost';
var pluralName$1 = 'feedPosts';
function getMany() {

@@ -130,21 +157,230 @@ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

function getOne$1(entity) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var id = options.id;
var defaultProperties = entity.defaultProperties;
var name$3 = 'moment';
var pluralName$3 = 'moments';
var defaultProperties$1 = ['id', 'description', 'title', 'user.name', 'cover_image_media.id', 'cover_image_media.src'];
if (isNil(id)) {
return new Error('options.id is required when getting one ' + entity.name);
var moment = Object.freeze({
name: name$3,
pluralName: pluralName$3,
defaultProperties: defaultProperties$1
});
var name$5 = 'review';
var pluralName$5 = 'reviews';
var defaultProperties$2 = ['id', 'rating'];
var review = Object.freeze({
name: name$5,
pluralName: pluralName$5,
defaultProperties: defaultProperties$2
});
var name$6 = 'tree';
var pluralName$6 = 'trees';
var treeEntity = Object.freeze({
name: name$6,
pluralName: pluralName$6
});
/*
* This entity is temporary while we figure out how to handle "my" entities
* in a standard entity way. We expect to delete it once we have settled on a
* standard "my" approach.
*/
var name$4 = 'myTreeReview';
var pluralName$4 = 'myTreeReviews';
function getOne() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var tree = options.tree;
if (isNil(tree) || isNil(tree.id)) {
return new Error("options.tree.id is required when getting the current user's tree review");
}
if (isNil(entity.pluralName)) {
return new Error('The ' + entity.name + ' entity must export pluralName');
var properties = buildProperties(defaultProperties$2, options);
var paths = properties.map(function (property) {
var rootLeaf = entityToFalcorRootLeaf(treeEntity);
var path = falcorPathParser(property);
return concat([rootLeaf, tree.id, 'my_review'], path);
});
return paths;
}
function extractOne() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var jsonGraph = arguments[1];
var tree = options.tree;
if (isNil(tree) || isNil(tree.id)) {
return new Error("options.tree.id is required when getting the current user's tree review");
}
if (isNil(defaultProperties)) {
return new Error('The ' + entity.name + ' entity must export defaultProperties');
var rootLeaf = entityToFalcorRootLeaf(treeEntity);
return jsonGraph.json[rootLeaf][tree.id].my_review;
}
var myTreeReview = Object.freeze({
name: name$4,
pluralName: pluralName$4,
defaultProperties: defaultProperties$2,
getOne: getOne,
extractOne: extractOne
});
var name$7 = 'note';
var pluralName$7 = 'notes';
var defaultProperties$3 = ['id', 'body'];
var note = Object.freeze({
name: name$7,
pluralName: pluralName$7,
defaultProperties: defaultProperties$3
});
var name$8 = 'space';
var pluralName$8 = 'spaces';
var space = Object.freeze({
name: name$8,
pluralName: pluralName$8
});
var name$9 = 'timeline';
var pluralName$9 = 'timelines';
var timeline = Object.freeze({
name: name$9,
pluralName: pluralName$9
});
var name$10 = 'topic';
var pluralName$10 = 'topics';
var defaultProperties$4 = ['id', 'name'];
var topic = Object.freeze({
name: name$10,
pluralName: pluralName$10,
defaultProperties: defaultProperties$4
});
var name$11 = 'tourTipView';
var pluralName$11 = 'tourTipViews';
var defaultProperties$5 = ['id', 'state'];
function getMany$1() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var _buildPaging = buildPaging(options),
from = _buildPaging.from,
to = _buildPaging.to;
var properties = buildProperties(defaultProperties$5, options);
var listLeaf = entityToFalcorListLeaf({ name: name$11 });
var paths = map(properties, function (property) {
var propertyPath = falcorPathParser(property);
var path = ['self', listLeaf, { from: from, to: to }, propertyPath];
return path;
});
return paths;
}
function extractMany$1() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var jsonGraph = arguments[1];
var listLeaf = entityToFalcorListLeaf({ name: name$11 });
var viewList = jsonGraph.json.self[listLeaf];
var views = map(viewList, function (view) {
return view;
});
return views;
}
var tourTipView = Object.freeze({
name: name$11,
pluralName: pluralName$11,
defaultProperties: defaultProperties$5,
getMany: getMany$1,
extractMany: extractMany$1
});
var entities = Object.freeze({
comment: comment,
feedPost: feedPost,
moment: moment,
myTreeReview: myTreeReview,
note: note,
post: post,
review: review,
space: space,
timeline: timeline,
topic: topic,
tourTipView: tourTipView,
tree: treeEntity
});
var entitySrc = 'entities';
function entityIsUndefinedError(entityName) {
var filename = entityNameToFilename(entityName);
return new Error('The ' + entityName + ' entity is undefined. Ensure ' + entitySrc + '/' + filename + ' exists and is exported by ' + entitySrc + '/_catalog.js');
}
function entityMustExportError(entityName, property) {
var filename = entityNameToFilename(entityName);
return new Error(entitySrc + '/' + filename + ' must export ' + property);
}
function optionsMustHaveError(property) {
return new Error('options.' + property + ' is required');
}
function entityExports(entity, property) {
return !isNil(entity[property]);
}
function optionsHas(options, property) {
return !isNil(get(options, property));
}
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; }
function getOne$1(entityName, entity) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
if (!entityExports(entity, 'pluralName')) {
return entityMustExportError(entityName, 'pluralName');
}
var properties = buildProperties(defaultProperties, options);
if (!entityExports(entity, 'defaultProperties')) {
return entityMustExportError(entityName, 'defaultProperties');
}
if (!optionsHas(options, 'id')) {
return optionsMustHaveError('id');
}
var properties = buildProperties(entity.defaultProperties, options);
var rootLeaf = entityToFalcorRootLeaf(entity);

@@ -154,3 +390,3 @@

var propertyPath = falcorPathParser(property);
var path = concat([rootLeaf, id], propertyPath);
var path = concat([rootLeaf, options.id], propertyPath);

@@ -163,3 +399,3 @@ return path;

function extractOne(entity) {
function extractOne$1(entity) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

@@ -174,13 +410,15 @@ var jsonGraph = arguments[2];

function getMany$1(entity) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var defaultProperties = entity.defaultProperties;
function getMany$2(entityName, entity) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
if (!entityExports(entity, 'name')) {
return entityMustExportError(entityName, 'name');
}
if (isNil(defaultProperties)) {
return new Error('The ' + entity.name + ' entity must export defaultProperties');
if (!entityExports(entity, 'pluralName')) {
return entityMustExportError(entityName, 'pluralName');
}
if (isNil(entity.pluralName)) {
return new Error('The ' + entity.name + ' entity must export pluralName');
if (!entityExports(entity, 'defaultProperties')) {
return entityMustExportError(entityName, 'defaultProperties');
}

@@ -192,11 +430,10 @@

var properties = buildProperties(defaultProperties, options);
var properties = buildProperties(entity.defaultProperties, options);
var parentEntityName = void 0,
parentOption = void 0,
parentEntity = void 0;
var parentEntity = void 0,
parentOptions = void 0;
if (!isNil(options.parent)) {
parentEntityName = keys(options.parent)[0];
parentOption = options.parent[parentEntityName];
var parentEntityName = head(keys(options.parent));
parentEntity = entities[parentEntityName];
parentOptions = options.parent[parentEntityName];
}

@@ -209,7 +446,7 @@

basePath = [rootLeaf, parentOption.id, listLeaf];
basePath = [rootLeaf, parentOptions.id, listLeaf];
} else {
var _rootLeaf = entityToFalcorRootLeaf(entity);
var _listLeaf = entityToFalcorListLeaf(entity);
basePath = [_rootLeaf];
basePath = [_listLeaf];
}

@@ -227,13 +464,12 @@

function extractMany$1(entity) {
function extractMany$2(entity) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var jsonGraph = arguments[2];
var parentEntityName = void 0,
parentOption = void 0,
parentEntity = void 0;
var parentEntity = void 0,
parentOptions = void 0;
if (!isNil(options.parent)) {
parentEntityName = keys(options.parent)[0];
parentOption = options.parent[parentEntityName];
var parentEntityName = head(keys(options.parent));
parentEntity = entities[parentEntityName];
parentOptions = options.parent[parentEntityName];
}

@@ -246,7 +482,7 @@

entityList = jsonGraph.json[parentRootLeaf][parentOption.id][entityListLeaf];
entityList = jsonGraph.json[parentRootLeaf][parentOptions.id][entityListLeaf];
} else {
var rootLeaf = entityToFalcorRootLeaf(entity);
var listLeaf = entityToFalcorListLeaf(entity);
entityList = jsonGraph.json[rootLeaf];
entityList = jsonGraph.json[listLeaf];
}

@@ -261,178 +497,109 @@

function update(entity) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var id = options.id;
function create(entityName, entity) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
if (isNil(entity.pluralName)) {
return new Error('The ' + entity.name + ' entity must export pluralName');
if (!entityExports(entity, 'name')) {
return entityMustExportError(entityName, 'name');
}
if (isNil(id)) {
return new Error('options.id is required when updating a tree review');
if (!entityExports(entity, 'pluralName')) {
return entityMustExportError(entityName, 'pluralName');
}
if (keys(options).length === 1) {
return new Error('options must include at least one property to update');
if (!optionsHas(options, entityName)) {
return optionsMustHaveError(entityName);
}
var properties = filter(keys(options), function (key) {
return key !== 'id';
});
var rootLeaf = entityToFalcorRootLeaf(entity);
var parentEntity = void 0,
parentOptions = void 0;
if (!isNil(options.parent)) {
var parentEntityName = head(keys(options.parent));
parentEntity = entities[parentEntityName];
parentOptions = options.parent[parentEntityName];
var paths = map(properties, function (property) {
return { path: [rootLeaf, id, property], value: options[property] };
});
if (isNil(parentEntity)) {
return entityIsUndefinedError(parentEntityName);
}
return paths;
}
if (!entityExports(parentEntity, 'pluralName')) {
return entityMustExportError(parentEntityName, 'pluralName');
}
function extractUpdated(entity) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var jsonGraph = arguments[2];
if (!optionsHas(parentOptions, 'id')) {
return optionsMustHaveError('parent.' + parentEntityName + '.id');
}
}
var rootLeaf = entityToFalcorRootLeaf(entity);
var updatedProperties = jsonGraph.json[rootLeaf][options.id];
var path = void 0;
if (parentEntity) {
var rootLeaf = entityToFalcorRootLeaf(parentEntity);
var listLeaf = entityToFalcorListLeaf(entity);
return updatedProperties;
}
path = [rootLeaf, parentOptions.id, listLeaf, 'add'];
} else {
var _rootLeaf = entityToFalcorRootLeaf(entity);
function destroy(entity) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var id = options.id;
if (isNil(entity.pluralName)) {
return new Error('The ' + entity.name + ' entity must export pluralName');
path = [_rootLeaf, 'create'];
}
if (isNil(id)) {
return new Error('options.id is required when destroying one ' + entity.name);
}
var envelopeKey = entityToAPIEnvelopeKey(entity);
var args = [_defineProperty({}, envelopeKey, options[entity.name])];
var rootLeaf = entityToFalcorRootLeaf(entity);
var destroyPath = [rootLeaf, id, 'delete'];
return destroyPath;
return { path: path, args: args };
}
var name$3 = 'moment';
var pluralName$3 = 'moments';
function extractCreated(entity) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var jsonGraph = arguments[2];
var defaultProperties$1 = ['id', 'description', 'title', 'user.name', 'cover_image_media.id', 'cover_image_media.src'];
var rootLeaf = entityToFalcorRootLeaf(entity);
var entities = jsonGraph.json[rootLeaf];
var first = head(keys(entities));
var extractedEntity = entities[first];
function getOne$$1() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var paths = getOne$1({ defaultProperties: defaultProperties$1, pluralName: pluralName$3 }, options);
return paths;
return extractedEntity;
}
var moment = Object.freeze({
name: name$3,
pluralName: pluralName$3,
defaultProperties: defaultProperties$1,
getOne: getOne$$1
});
function invalidateAfterCreate$1(entity) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var name$5 = 'review';
var pluralName$5 = 'reviews';
if (!isNil(options.parent)) {
var parentEntityName = head(keys(options.parent));
var parentEntity = entities[parentEntityName];
var parentId = options.parent[parentEntityName].id;
var defaultProperties$2 = ['id', 'rating'];
var rootLeaf = entityToFalcorRootLeaf(parentEntity);
var listLeaf = entityToFalcorListLeaf(entity);
var review = Object.freeze({
name: name$5,
pluralName: pluralName$5,
defaultProperties: defaultProperties$2
});
var paths = [[rootLeaf, parentId, listLeaf], [rootLeaf, parentId, listLeaf, 'length']];
var name$6 = 'tree';
var pluralName$6 = 'trees';
var treeEntity = Object.freeze({
name: name$6,
pluralName: pluralName$6
});
/*
* This entity is temporary while we figure out how to handle "my" entities
* in a standard entity way. We expect to delete it once we have settled on a
* standard "my" approach.
*/
var name$4 = 'myTreeReview';
var pluralName$4 = 'myTreeReviews';
function getOne$2() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var tree = options.tree;
if (isNil(tree) || isNil(tree.id)) {
return new Error("options.tree.id is required when getting the current user's tree review");
return paths;
}
var properties = buildProperties(defaultProperties$2, options);
var paths = properties.map(function (property) {
var rootLeaf = entityToFalcorRootLeaf(treeEntity);
var path = falcorPathParser(property);
return concat([rootLeaf, tree.id, 'my_review'], path);
});
return paths;
}
function extractOne$1() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var jsonGraph = arguments[1];
var tree = options.tree;
function update(entityName, entity) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
if (!entityExports(entity, 'pluralName')) {
return entityMustExportError(entityName, 'pluralName');
}
if (isNil(tree) || isNil(tree.id)) {
return new Error("options.tree.id is required when getting the current user's tree review");
if (!optionsHas(options, 'id')) {
return optionsMustHaveError('id');
}
var rootLeaf = entityToFalcorRootLeaf(treeEntity);
if (keys(options).length === 1) {
return new Error('options must include at least one property to update');
}
return jsonGraph.json[rootLeaf][tree.id].my_review;
}
var properties = filter(keys(options), function (key) {
return key !== 'id';
});
var rootLeaf = entityToFalcorRootLeaf(entity);
var myTreeReview = Object.freeze({
name: name$4,
pluralName: pluralName$4,
defaultProperties: defaultProperties$2,
getOne: getOne$2,
extractOne: extractOne$1
});
var name$7 = 'timeline';
var pluralName$7 = 'timelines';
var timeline = Object.freeze({
name: name$7,
pluralName: pluralName$7
});
var name$8 = 'tourTipView';
var pluralName$8 = 'tourTipViews';
var defaultProperties$3 = ['id', 'state'];
function getMany$2() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var _buildPaging = buildPaging(options),
from = _buildPaging.from,
to = _buildPaging.to;
var properties = buildProperties(defaultProperties$3, options);
var listLeaf = entityToFalcorListLeaf({ name: name$8 });
var paths = map(properties, function (property) {
var propertyPath = falcorPathParser(property);
var path = ['self', listLeaf, { from: from, to: to }, propertyPath];
var path = {
path: [rootLeaf, options.id, property],
value: options[property]
};

@@ -445,38 +612,29 @@ return path;

function extractMany$2() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var jsonGraph = arguments[1];
function extractUpdated(entity) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var jsonGraph = arguments[2];
var listLeaf = entityToFalcorListLeaf({ name: name$8 });
var viewList = jsonGraph.json.self[listLeaf];
var rootLeaf = entityToFalcorRootLeaf(entity);
var updatedProperties = jsonGraph.json[rootLeaf][options.id];
var views = map(viewList, function (view) {
return view;
});
return views;
return updatedProperties;
}
var tourTipView = Object.freeze({
name: name$8,
pluralName: pluralName$8,
defaultProperties: defaultProperties$3,
getMany: getMany$2,
extractMany: extractMany$2
});
function destroy(entityName, entity) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
if (!entityExports(entity, 'pluralName')) {
return entityMustExportError(entityName, 'pluralName');
}
if (!optionsHas(options, 'id')) {
return optionsMustHaveError('id');
}
var entities = Object.freeze({
comment: comment,
feedPost: feedPost,
moment: moment,
myTreeReview: myTreeReview,
post: post,
review: review,
timeline: timeline,
tourTipView: tourTipView,
tree: treeEntity
});
var rootLeaf = entityToFalcorRootLeaf(entity);
var destroyPath = [rootLeaf, options.id, 'delete'];
return destroyPath;
}
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; }; }();

@@ -530,7 +688,6 @@

if (isNil(entity)) {
var filename = entityNameToFilename(entityName) + '.js';
return Promise.reject(new Error('The ' + entityName + ' entity is undefined. Ensure entities/' + filename + ' exists and is exported by entities/_catalog.js'));
return Promise.reject(entityIsUndefinedError(entityName));
}
var paths = isFunction(entity.getMany) ? entity.getMany(options) : getMany$1(entity, options);
var paths = isFunction(entity.getMany) ? entity.getMany(options) : getMany$2(entityName, entity, options);

@@ -542,8 +699,9 @@ if (isError(paths)) {

return (_falcor = this.falcor).get.apply(_falcor, _toConsumableArray(paths)).then(function (jsonGraph) {
var extractedEntities = void 0;
if (isNil(get(jsonGraph, 'json'))) {
return null;
extractedEntities = null;
} else {
extractedEntities = isFunction(entity.extractMany) ? entity.extractMany(options, jsonGraph) : extractMany$2(entity, options, jsonGraph);
}
var extractedEntities = isFunction(entity.extractMany) ? entity.extractMany(options, jsonGraph) : extractMany$1(entity, options, jsonGraph);
return extractedEntities;

@@ -565,7 +723,6 @@ }).catch(function (response) {

if (isNil(entity)) {
var filename = entityNameToFilename(entityName) + '.js';
return Promise.reject(new Error('The ' + entityName + ' entity is undefined. Ensure entities/' + filename + ' exists and is exported by entities/_catalog.js'));
return Promise.reject(entityIsUndefinedError(entityName));
}
var paths = isFunction(entity.getOne) ? entity.getOne(options) : getOne$1(entity, options);
var paths = isFunction(entity.getOne) ? entity.getOne(options) : getOne$1(entityName, entity, options);

@@ -577,8 +734,9 @@ if (isError(paths)) {

return (_falcor2 = this.falcor).get.apply(_falcor2, _toConsumableArray(paths)).then(function (jsonGraph) {
var extractedEntity = void 0;
if (isNil(get(jsonGraph, 'json'))) {
return null;
extractedEntity = null;
} else {
extractedEntity = isFunction(entity.extractOne) ? entity.extractOne(options, jsonGraph) : extractOne$1(entity, options, jsonGraph);
}
var extractedEntity = isFunction(entity.extractOne) ? entity.extractOne(options, jsonGraph) : extractOne(entity, options, jsonGraph);
return extractedEntity;

@@ -592,12 +750,44 @@ }).catch(function (response) {

key: 'create',
value: function create(entity) {
value: function create$$1(entityName) {
var _this = this;
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var createFunction = camelCase('create_' + entity);
var entity = entities[entityName];
if (!isFunction(this[createFunction])) {
return Promise.reject(new Error('Invalid entity: ' + entity + '. Please check the syntax and try again.'));
if (isNil(entity)) {
return Promise.reject(entityIsUndefinedError(entityName));
}
return this[createFunction](options);
var callOptions = isFunction(entity.create) ? entity.create(options) : create(entityName, entity, options);
if (isError(callOptions)) {
return Promise.reject(callOptions);
}
var path = callOptions.path,
args = callOptions.args;
return this.falcor.call(path, args).then(function (jsonGraph) {
var extractedEntity = void 0;
if (isNil(get(jsonGraph, 'json'))) {
extractedEntity = null;
} else {
extractedEntity = isFunction(entity.extractCreated) ? entity.extractCreated(options, jsonGraph) : extractCreated(entity, options, jsonGraph);
}
var pathsToInvalidate = isFunction(entity.invalidateAfterCreate) ? entity.invalidateAfterCreate(options) : invalidateAfterCreate$1(entity, options);
if (pathsToInvalidate) {
var _falcor3;
(_falcor3 = _this.falcor).invalidate.apply(_falcor3, _toConsumableArray(pathsToInvalidate));
}
return extractedEntity;
}).catch(function (response) {
var message = buildCreateErrorMessage(response);
return Promise.reject(new Error(message));
});
}

@@ -607,3 +797,3 @@ }, {

value: function update$$1(entityName) {
var _falcor3;
var _falcor4;

@@ -615,7 +805,6 @@ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

if (isNil(entity)) {
var filename = entityNameToFilename(entityName) + '.js';
return Promise.reject(new Error('The ' + entityName + ' entity is undefined. Ensure entities/' + filename + ' exists and is exported by entities/_catalog.js'));
return Promise.reject(entityIsUndefinedError(entityName));
}
var paths = isFunction(entity.update) ? entity.update(options) : update(entity, options);
var paths = isFunction(entity.update) ? entity.update(options) : update(entityName, entity, options);

@@ -626,9 +815,10 @@ if (isError(paths)) {

return (_falcor3 = this.falcor).set.apply(_falcor3, _toConsumableArray(paths)).then(function (jsonGraph) {
return (_falcor4 = this.falcor).set.apply(_falcor4, _toConsumableArray(paths)).then(function (jsonGraph) {
var updatedProperties = void 0;
if (isNil(get(jsonGraph, 'json'))) {
return null;
updatedProperties = null;
} else {
updatedProperties = isFunction(entity.extractUpdated) ? entity.extractUpdated(options, jsonGraph) : extractUpdated(entity, options, jsonGraph);
}
var updatedProperties = isFunction(entity.extractUpdated) ? entity.extractUpdated(options, jsonGraph) : extractUpdated(entity, options, jsonGraph);
return updatedProperties;

@@ -648,7 +838,6 @@ }).catch(function (response) {

if (isNil(entity)) {
var filename = entityNameToFilename(entityName) + '.js';
return Promise.reject(new Error('The ' + entityName + ' entity is undefined. Ensure entities/' + filename + ' exists and is exported by entities/_catalog.js'));
return Promise.reject(entityIsUndefinedError(entityName));
}
var destroyPath = isFunction(entity.destroy) ? entity.destroy(options) : destroy(entity, options);
var destroyPath = isFunction(entity.destroy) ? entity.destroy(options) : destroy(entityName, entity, options);

@@ -666,102 +855,2 @@ if (isError(destroyPath)) {

}
/*
* Entity-specific handlers
*/
}, {
key: 'createComment',
value: function createComment() {
var _this = this;
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var postId = options.post.id;
var comment$$1 = options.comment;
// TODO: Account for implicit assumptions in the final API:
// - entities must be wrapped in an entity-name envelope when creating
var requestBody = { comment: comment$$1 };
// What's the diff between this.falcor.call and ngf.callModel?
return this.falcor.call(['posts', postId, 'comment_list', 'add'], [requestBody]).then(function (jsonGraph) {
// TODO: This does NOT support a create-many-at-once model, is that
// doable in Falcor?
var comments = jsonGraph.json.comments;
var first = head(keys(comments));
var createdComment = comments[first];
// TODO: Account for implicit assumptions in the final API:
// - parent resources must be included in the Falcor path
// - parent resources are always indexed with an entityId
// - lists of entities have a entity_count value
// - lists of entities are stored at a entity_list leaf
_this.falcor.invalidate(['posts', postId, 'comment_count']);
_this.falcor.invalidate(['posts', postId, 'comment_list']);
return createdComment;
});
}
}, {
key: 'createTourTipView',
value: function createTourTipView() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var tourTipView$$1 = options.tourTipView;
var wrappedTourTipView = {
tour_tip_view: tourTipView$$1
};
return this.falcor.call(['tour_tip_views', 'create'], [wrappedTourTipView]).then(function (jsonGraph) {
var views = jsonGraph.json.tour_tip_views;
var first = head(keys(views));
var createdView = views[first];
// TODO: Figure out:
// - Should we invalidate ['users', :id, 'tour_tip_view_list'] ?
// - What are the implications of views not being created by users?
return createdView;
}).catch(function (paths) {
var message = buildCreateErrorMessage(paths);
return Promise.reject(new Error(message));
});
}
}, {
key: 'createTreeReview',
value: function createTreeReview() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var review$$1 = options.review,
tree$$1 = options.tree;
if (isNil(review$$1)) {
return Promise.reject(new Error('options.review is required when creating a tree review'));
}
if (isNil(tree$$1) || isNil(tree$$1.id)) {
return Promise.reject(new Error('options.tree.id is required when creating a tree review'));
}
var wrappedReview = {
review: review$$1
};
return this.falcor.call(['trees', tree$$1.id, 'review_list', 'add'], [wrappedReview]).then(function (jsonGraph) {
var reviews = jsonGraph.json.reviews;
var first = head(keys(reviews));
var createdReview = reviews[first];
// TODO: Figure out:
// - do we need to invalidate the ['trees', :id, 'review_list'] or is their an equiv to append?
// - do we need to invalidate ['trees', :id, 'review_list', 'length']?
// - is there anything else we need to consider invalidating?
return createdReview;
}).catch(function (paths) {
var message = buildCreateErrorMessage(paths);
return Promise.reject(new Error(message));
});
}
}]);

@@ -817,10 +906,18 @@

var firstPath = response[0];
var entity = camelCase(firstPath.path[0]);
var originalMessage = firstPath.value;
var firstError = head(response);
var entityName = void 0;
if (last(firstError.path) === 'add') {
var listLeaf = nth(firstError.path, -2);
entityName = falcorListLeafToEntityName(listLeaf);
} else {
var rootLeaf = head(firstError.path);
entityName = falcorRootLeafToEntityName(rootLeaf);
}
var originalMessage = firstError.value;
var code = originalMessage.match(/\d{3}/)[0];
var improvedMessage = codeToMessageMap[code] || codeToMessageMap.default;
return 'Could not create a new ' + entity + ': ' + improvedMessage + ' (' + originalMessage + ')';
return 'Could not create a new ' + entityName + ': ' + improvedMessage + ' (' + originalMessage + ')';
}

@@ -827,0 +924,0 @@

{
"name": "supergloo",
"version": "0.10.1",
"version": "0.11.0",
"description": "Easily work with data on the Gloo platform",

@@ -50,9 +50,9 @@ "keywords": [

"build": "rimraf dist && npm run build:es && npm run build:umd",
"build:umd": "rollup -c rollup-umd.config.js",
"build:es": "rollup -c rollup-es.config.js",
"build:test": "rimraf test/runner/bundle.js && rollup -c rollup-test.config.js",
"build:umd": "rollup -c config/rollup-umd.js",
"build:es": "rollup -c config/rollup-es.js",
"build:test": "rimraf test/runner/bundle.js && rollup -c config/rollup-test.js",
"dev": "nodemon -w src -w test -x 'npm run --silent lint && npm run --silent test'",
"freeze": "npm prune && npm shrinkwrap --dev && shrinkpack",
"lint": "standard {src,test}/*.js {src,test}/**/*.js",
"test:browser": "npm run build:test && easy-sauce -c easy-sauce.config.json",
"test:browser": "npm run build:test && easy-sauce -c config/easy-sauce.json",
"test:list": "mocha --require test/support/require-shim.js",

@@ -59,0 +59,0 @@ "test": "mocha --require test/support/require-shim.js test/{*,**/*}.test.js"

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc