From 93d566e26388c502d48a05790a640d116978795e Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Sat, 6 Jun 2020 12:31:07 +0200 Subject: [PATCH] Exposed methods and publications to http requests, changed method names --- app/.meteor/packages | 2 ++ app/.meteor/versions | 3 +++ app/imports/api/creature/CreatureProperties.js | 18 +++++++++--------- app/imports/api/creature/Creatures.js | 4 ++-- .../creature/computation/recomputeCreature.js | 2 +- .../recomputeDamageMultipliers.js | 2 +- .../api/creature/experience/Experiences.js | 6 +++--- app/imports/api/icons/Icons.js | 4 ++-- app/imports/api/library/Libraries.js | 8 ++++---- app/imports/api/library/LibraryNodes.js | 12 ++++++------ app/imports/api/parenting/organizeMethods.js | 4 ++-- app/imports/api/sharing/sharing.js | 4 ++-- app/imports/api/users/Invites.js | 6 +++--- app/imports/api/users/Users.js | 14 +++++++------- app/imports/server/config/SimpleRestConfig.js | 6 ++++++ app/server/main.js | 1 + 16 files changed, 54 insertions(+), 42 deletions(-) create mode 100644 app/imports/server/config/SimpleRestConfig.js diff --git a/app/.meteor/packages b/app/.meteor/packages index 75ad2107..c2382499 100644 --- a/app/.meteor/packages +++ b/app/.meteor/packages @@ -50,3 +50,5 @@ akryum:vue-component accounts-patreon bozhao:link-accounts peerlibrary:reactive-publish +simple:rest +simple:rest-method-mixin diff --git a/app/.meteor/versions b/app/.meteor/versions index a4f0f2b3..c21c1581 100644 --- a/app/.meteor/versions +++ b/app/.meteor/versions @@ -115,6 +115,9 @@ service-configuration@1.0.11 session@1.2.0 sha@1.0.9 shell-server@0.5.0 +simple:json-routes@2.1.0 +simple:rest@1.1.1 +simple:rest-method-mixin@1.0.1 socket-stream-client@0.3.0 spacebars@1.0.15 spacebars-compiler@1.1.3 diff --git a/app/imports/api/creature/CreatureProperties.js b/app/imports/api/creature/CreatureProperties.js index 1011a9bf..20dec2c2 100644 --- a/app/imports/api/creature/CreatureProperties.js +++ b/app/imports/api/creature/CreatureProperties.js @@ -76,7 +76,7 @@ function recomputeCreatures(property){ } const insertProperty = new ValidatedMethod({ - name: 'CreatureProperties.methods.insert', + name: 'creatureProperties.insert', validate: null, run({creatureProperty}) { delete creatureProperty._id; @@ -88,7 +88,7 @@ const insertProperty = new ValidatedMethod({ }); const duplicateProperty = new ValidatedMethod({ - name: 'CreatureProperties.methods.duplicate', + name: 'creatureProperties.duplicate', validate: new SimpleSchema({ _id: { type: String, @@ -105,7 +105,7 @@ const duplicateProperty = new ValidatedMethod({ }); const insertPropertyFromLibraryNode = new ValidatedMethod({ - name: 'CreatureProperties.methods.insertPropertyFromLibraryNode', + name: 'creatureProperties.insertPropertyFromLibraryNode', validate: new SimpleSchema({ nodeId: { type: String, @@ -178,7 +178,7 @@ const insertPropertyFromLibraryNode = new ValidatedMethod({ }) const updateProperty = new ValidatedMethod({ - name: 'CreatureProperties.methods.update', + name: 'creatureProperties.update', validate({_id, path}){ if (!_id) return false; // We cannot change these fields with a simple update @@ -211,7 +211,7 @@ const updateProperty = new ValidatedMethod({ }); const damageProperty = new ValidatedMethod({ - name: 'CreatureProperties.methods.adjust', + name: 'creatureProperties.damage', validate: new SimpleSchema({ _id: SimpleSchema.RegEx.Id, operation: { @@ -265,7 +265,7 @@ const damageProperty = new ValidatedMethod({ }); const adjustQuantity = new ValidatedMethod({ - name: 'CreatureProperties.methods.adjustQuantity', + name: 'creatureProperties.adjustQuantity', validate: new SimpleSchema({ _id: SimpleSchema.RegEx.Id, operation: { @@ -307,7 +307,7 @@ const adjustQuantity = new ValidatedMethod({ }); const pushToProperty = new ValidatedMethod({ - name: 'CreatureProperties.methods.push', + name: 'creatureProperties.push', validate: null, run({_id, path, value}){ let property = CreatureProperties.findOne(_id); @@ -322,7 +322,7 @@ const pushToProperty = new ValidatedMethod({ }); const pullFromProperty = new ValidatedMethod({ - name: 'CreatureProperties.methods.pull', + name: 'creatureProperties.pull', validate: null, run({_id, path, itemId}){ let property = CreatureProperties.findOne(_id); @@ -338,7 +338,7 @@ const pullFromProperty = new ValidatedMethod({ }); const softRemoveProperty = new ValidatedMethod({ - name: 'CreatureProperties.methods.softRemove', + name: 'creatureProperties.softRemove', validate: new SimpleSchema({ _id: SimpleSchema.RegEx.Id }).validator(), diff --git a/app/imports/api/creature/Creatures.js b/app/imports/api/creature/Creatures.js index 23cf5ceb..2e602b8a 100644 --- a/app/imports/api/creature/Creatures.js +++ b/app/imports/api/creature/Creatures.js @@ -120,7 +120,7 @@ Creatures.attachSchema(CreatureSchema); const insertCreature = new ValidatedMethod({ - name: 'Creatures.methods.insertCreature', + name: 'creatures.insertCreature', validate: null, @@ -146,7 +146,7 @@ const insertCreature = new ValidatedMethod({ }); const updateCreature = new ValidatedMethod({ - name: 'Creatures.methods.update', + name: 'creatures.update', validate({_id, path}){ if (!_id) return false; // Allowed fields diff --git a/app/imports/api/creature/computation/recomputeCreature.js b/app/imports/api/creature/computation/recomputeCreature.js index a29c4808..33346d27 100644 --- a/app/imports/api/creature/computation/recomputeCreature.js +++ b/app/imports/api/creature/computation/recomputeCreature.js @@ -11,7 +11,7 @@ import Creatures from '/imports/api/creature/Creatures.js'; export const recomputeCreature = new ValidatedMethod({ - name: 'Creatures.methods.recomputeCreature', + name: 'creatures.recomputeCreature', validate: new SimpleSchema({ charId: { type: String } diff --git a/app/imports/api/creature/damageMultiplierDenormalise/recomputeDamageMultipliers.js b/app/imports/api/creature/damageMultiplierDenormalise/recomputeDamageMultipliers.js index aba990f7..3f60dc82 100644 --- a/app/imports/api/creature/damageMultiplierDenormalise/recomputeDamageMultipliers.js +++ b/app/imports/api/creature/damageMultiplierDenormalise/recomputeDamageMultipliers.js @@ -6,7 +6,7 @@ import getActiveProperties from '/imports/api/creature/getActiveProperties.js'; export const recomputeDamageMultipliers = new ValidatedMethod({ - name: 'Creatures.methods.recomputeDamageMultipliers', + name: 'creatures.recomputeDamageMultipliers', validate: new SimpleSchema({ creatureId: { type: String } diff --git a/app/imports/api/creature/experience/Experiences.js b/app/imports/api/creature/experience/Experiences.js index ba8c9aca..af51d48a 100644 --- a/app/imports/api/creature/experience/Experiences.js +++ b/app/imports/api/creature/experience/Experiences.js @@ -64,7 +64,7 @@ const insertExperienceForCreature = function({experience, creatureId, userId}){ }; const insertExperience = new ValidatedMethod({ - name: 'Experiences.methods.insert', + name: 'experiences.insert', validate: new SimpleSchema({ experience: { type: ExperienceSchema.omit('creatureId'), @@ -99,7 +99,7 @@ const insertExperience = new ValidatedMethod({ }); const removeExperience = new ValidatedMethod({ - name: 'Experiences.methods.remove', + name: 'experiences.remove', validate: new SimpleSchema({ experienceId: { type: String, @@ -139,7 +139,7 @@ const removeExperience = new ValidatedMethod({ }); const recomputeExperiences = new ValidatedMethod({ - name: 'Experiences.methods.recompute', + name: 'experiences.recompute', validate: new SimpleSchema({ creatureId: { type: String, diff --git a/app/imports/api/icons/Icons.js b/app/imports/api/icons/Icons.js index 7a6df2b3..9f4224c6 100644 --- a/app/imports/api/icons/Icons.js +++ b/app/imports/api/icons/Icons.js @@ -48,7 +48,7 @@ Icons.attachSchema(iconsSchema); // This method does not validate icons against the schema, use wisely; const writeIcons = new ValidatedMethod({ - name: 'icons.methods.write', + name: 'icons.write', validate: null, run(icons){ assertAdmin(this.userId); @@ -60,7 +60,7 @@ const writeIcons = new ValidatedMethod({ }); const findIcons = new ValidatedMethod({ - name: 'icons.methods.find', + name: 'icons.find', validate: new SimpleSchema({ search: { type: String, diff --git a/app/imports/api/library/Libraries.js b/app/imports/api/library/Libraries.js index dbbf013c..85ea0b97 100644 --- a/app/imports/api/library/Libraries.js +++ b/app/imports/api/library/Libraries.js @@ -34,7 +34,7 @@ Libraries.attachSchema(LibrarySchema); export default Libraries; const insertLibrary = new ValidatedMethod({ - name: 'Libraries.methods.insert', + name: 'libraries.insert', mixins: [ simpleSchemaMixin, ], @@ -55,7 +55,7 @@ const insertLibrary = new ValidatedMethod({ }); const updateLibraryName = new ValidatedMethod({ - name: 'Libraries.methods.updateName', + name: 'libraries.updateName', validate: new SimpleSchema({ _id: { type: String, @@ -73,7 +73,7 @@ const updateLibraryName = new ValidatedMethod({ }); const setLibraryDefault = new ValidatedMethod({ - name: 'Libraries.methods.makeLibraryDefault', + name: 'libraries.makeLibraryDefault', validate: new SimpleSchema({ _id: { type: String, @@ -92,7 +92,7 @@ const setLibraryDefault = new ValidatedMethod({ }); const removeLibrary = new ValidatedMethod({ - name: 'Libraries.methods.remove', + name: 'libraries.remove', validate: new SimpleSchema({ _id: { type: String, diff --git a/app/imports/api/library/LibraryNodes.js b/app/imports/api/library/LibraryNodes.js index 8cca1c45..edee24c2 100644 --- a/app/imports/api/library/LibraryNodes.js +++ b/app/imports/api/library/LibraryNodes.js @@ -56,7 +56,7 @@ function assertNodeEditPermission(node, userId){ } const insertNode = new ValidatedMethod({ - name: 'LibraryNodes.methods.insert', + name: 'libraryNodes.insert', validate: null, run(libraryNode) { delete libraryNode._id; @@ -66,7 +66,7 @@ const insertNode = new ValidatedMethod({ }); const duplicateNode = new ValidatedMethod({ - name: 'LibraryNodes.methods.duplicate', + name: 'libraryNodes.duplicate', validate: new SimpleSchema({ _id: { type: String, @@ -82,7 +82,7 @@ const duplicateNode = new ValidatedMethod({ }) const updateLibraryNode = new ValidatedMethod({ - name: 'LibraryNodes.methods.update', + name: 'libraryNodes.update', validate({_id, path}){ if (!_id) return false; // We cannot change these fields with a simple update @@ -112,7 +112,7 @@ const updateLibraryNode = new ValidatedMethod({ }); const pushToLibraryNode = new ValidatedMethod({ - name: 'LibraryNodes.methods.push', + name: 'libraryNodes.push', validate: null, run({_id, path, value}){ let node = LibraryNodes.findOne(_id); @@ -126,7 +126,7 @@ const pushToLibraryNode = new ValidatedMethod({ }); const pullFromLibraryNode = new ValidatedMethod({ - name: 'LibraryNodes.methods.pull', + name: 'libraryNodes.pull', validate: null, run({_id, path, itemId}){ let node = LibraryNodes.findOne(_id); @@ -141,7 +141,7 @@ const pullFromLibraryNode = new ValidatedMethod({ }); const softRemoveLibraryNode = new ValidatedMethod({ - name: 'LibraryNodes.methods.softRemove', + name: 'libraryNodes.softRemove', validate: new SimpleSchema({ _id: SimpleSchema.RegEx.Id }).validator(), diff --git a/app/imports/api/parenting/organizeMethods.js b/app/imports/api/parenting/organizeMethods.js index 40bd891c..451f78df 100644 --- a/app/imports/api/parenting/organizeMethods.js +++ b/app/imports/api/parenting/organizeMethods.js @@ -10,7 +10,7 @@ import getCollectionByName from '/imports/api/parenting/getCollectionByName.js'; import { recomputeCreatureById } from '/imports/api/creature/computation/recomputeCreature.js'; const organizeDoc = new ValidatedMethod({ - name: 'organize.methods.organizeDoc', + name: 'organize.organizeDoc', validate: new SimpleSchema({ docRef: RefSchema, parentRef: RefSchema, @@ -54,7 +54,7 @@ const organizeDoc = new ValidatedMethod({ }); const reorderDoc = new ValidatedMethod({ - name: 'organize.methods.reorderDoc', + name: 'organize.reorderDoc', validate: new SimpleSchema({ docRef: RefSchema, order: { diff --git a/app/imports/api/sharing/sharing.js b/app/imports/api/sharing/sharing.js index 5c63c275..e597457f 100644 --- a/app/imports/api/sharing/sharing.js +++ b/app/imports/api/sharing/sharing.js @@ -6,7 +6,7 @@ import { RefSchema } from '/imports/api/parenting/ChildSchema.js'; import { ValidatedMethod } from 'meteor/mdg:validated-method'; const setPublic = new ValidatedMethod({ - name: 'sharing.methods.setPublic', + name: 'sharing.setPublic', validate: new SimpleSchema({ docRef: RefSchema, isPublic: { type: Boolean }, @@ -21,7 +21,7 @@ const setPublic = new ValidatedMethod({ }); const updateUserSharePermissions = new ValidatedMethod({ - name: 'sharing.methods.updateUserSharePermissions', + name: 'sharing.updateUserSharePermissions', validate: new SimpleSchema({ docRef: RefSchema, userId: { diff --git a/app/imports/api/users/Invites.js b/app/imports/api/users/Invites.js index a7293ee1..800aaa48 100644 --- a/app/imports/api/users/Invites.js +++ b/app/imports/api/users/Invites.js @@ -85,7 +85,7 @@ function alignInvitesWithPatreonTier(user){ } const getInviteToken = new ValidatedMethod({ - name: 'Invites.methods.getToken', + name: 'invites.getToken', validate: new SimpleSchema({ inviteId: { type: String, @@ -109,7 +109,7 @@ const getInviteToken = new ValidatedMethod({ }); const acceptInviteToken = new ValidatedMethod({ - name: 'Invites.methods.acceptToken', + name: 'invites.acceptToken', validate: new SimpleSchema({ inviteToken: { type: String, @@ -146,7 +146,7 @@ const acceptInviteToken = new ValidatedMethod({ }); const revokeInvite = new ValidatedMethod({ - name: 'Invites.methods.revokeInvite', + name: 'invites.revokeInvite', validate: new SimpleSchema({ inviteId: { type: String, diff --git a/app/imports/api/users/Users.js b/app/imports/api/users/Users.js index 61bdd9e7..bd479b08 100644 --- a/app/imports/api/users/Users.js +++ b/app/imports/api/users/Users.js @@ -87,7 +87,7 @@ const userSchema = new SimpleSchema({ Meteor.users.attachSchema(userSchema); Meteor.users.generateApiKey = new ValidatedMethod({ - name: 'Users.methods.generateApiKey', + name: 'users.generateApiKey', validate: null, run(){ if(Meteor.isClient) return; @@ -100,7 +100,7 @@ Meteor.users.generateApiKey = new ValidatedMethod({ }); Meteor.users.setDarkMode = new ValidatedMethod({ - name: 'Users.methods.setDarkMode', + name: 'users.setDarkMode', validate: new SimpleSchema({ darkMode: { type: Boolean }, }).validator(), @@ -111,7 +111,7 @@ Meteor.users.setDarkMode = new ValidatedMethod({ }); Meteor.users.sendVerificationEmail = new ValidatedMethod({ - name: 'Users.methods.sendVerificationEmail', + name: 'users.sendVerificationEmail', validate: new SimpleSchema({ userId:{ type: String, @@ -143,7 +143,7 @@ Meteor.users.isAdmin = function(userId){ } Meteor.users.canPickUsername = new ValidatedMethod({ - name: 'Users.methods.canPickUsername', + name: 'users.canPickUsername', validate: userSchema.pick('username').validator(), run({username}){ if (Meteor.isClient) return; @@ -157,7 +157,7 @@ Meteor.users.canPickUsername = new ValidatedMethod({ }); Meteor.users.setUsername = new ValidatedMethod({ - name: 'Users.methods.setUsername', + name: 'users.setUsername', validate: userSchema.pick('username').validator(), run({username}){ if (!this.userId) throw 'Can only set your username if logged in'; @@ -167,7 +167,7 @@ Meteor.users.setUsername = new ValidatedMethod({ }); Meteor.users.subscribeToLibrary = new ValidatedMethod({ - name: 'Users.methods.subscribeToLibrary', + name: 'users.subscribeToLibrary', validate: new SimpleSchema({ libraryId:{ type: String, @@ -192,7 +192,7 @@ Meteor.users.subscribeToLibrary = new ValidatedMethod({ }); Meteor.users.findUserByUsernameOrEmail = new ValidatedMethod({ - name: 'Users.methods.findUserByUsernameOrEmail', + name: 'users.findUserByUsernameOrEmail', validate: new SimpleSchema({ usernameOrEmail:{ type: String, diff --git a/app/imports/server/config/SimpleRestConfig.js b/app/imports/server/config/SimpleRestConfig.js new file mode 100644 index 00000000..a4d746cf --- /dev/null +++ b/app/imports/server/config/SimpleRestConfig.js @@ -0,0 +1,6 @@ +import { SimpleRest } from 'meteor/simple:rest'; + +SimpleRest.configure({ + // No default collection methods get end points + collections: [], +}); diff --git a/app/server/main.js b/app/server/main.js index 24b44f0b..8613003a 100644 --- a/app/server/main.js +++ b/app/server/main.js @@ -1,3 +1,4 @@ +import '/imports/server/config/SimpleRestConfig.js'; import '/imports/server/publications/index.js'; import '/imports/server/config/simpleSchemaDebug.js'; import '/imports/server/cron/deleteSoftRemovedDocuments.js';