Exposed methods and publications to http requests, changed method names

This commit is contained in:
Stefan Zermatten
2020-06-06 12:31:07 +02:00
parent b4da32f9ab
commit 93d566e263
16 changed files with 54 additions and 42 deletions

View File

@@ -50,3 +50,5 @@ akryum:vue-component
accounts-patreon
bozhao:link-accounts
peerlibrary:reactive-publish
simple:rest
simple:rest-method-mixin

View File

@@ -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

View File

@@ -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(),

View File

@@ -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

View File

@@ -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 }

View File

@@ -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 }

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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(),

View File

@@ -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: {

View File

@@ -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: {

View File

@@ -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,

View File

@@ -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,

View File

@@ -0,0 +1,6 @@
import { SimpleRest } from 'meteor/simple:rest';
SimpleRest.configure({
// No default collection methods get end points
collections: [],
});

View File

@@ -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';