fastify-mongoose-rest
Version:
Rest API generator tools for fastify and mongoose
92 lines • 3.61 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const operations_1 = require("./operations");
const utils_1 = require("./utils");
/**
* Create a new FastifyMongooseRest instance
*
* @param basePath Base path for the routes. It will be prefixed to all routes
* @param model Mongoose model to use
* @param options Options for the routes
* @returns FastifyMongooseRest instance
*
* @example
* ```ts
* import FastifyMongooseRest from 'fastify-mongoose-rest';
* import Cat from './models/cat';
*
* // If the base path does not include a slash at the start, it will be added
* const fastifyMongooseRest = FastifyMongooseRest('/cats', Cat);
* ```
*/
function FastifyMongooseRest(basePath, model, options = {}) {
const newBasePath = (0, utils_1.addSlashToPath)(basePath);
return {
/**
* Route for creating a new resource
*
* @description
* Validates input with given {@link FastifyMongooseRestOptions.validationSchema validation schema} and returns the created resource
*
* @see {@link Model.create Mongooose create method}
*/
create: (0, operations_1.Create)(newBasePath, model, options),
/**
* Route for deleting a resource by it's identifier
*
* @description
* Deletes a resource by _id or {@link FastifyMongooseRestOptions.findProperty findProperty option}
*
* @see {@link Model.deleteOne Mongooose deleteOne method}
*/
delete: (0, operations_1.Delete)(newBasePath, model, options),
/**
* Route for displaying a single resource by it's identifier
*
* @description
* Returns a resource by _id or {@link FastifyMongooseRestOptions.findProperty findProperty option}
*
* @see {@link Model.findOne Mongooose findOne method}
*/
details: (0, operations_1.Details)(newBasePath, model, options),
/**
* Route for displaying modifying a resource by it's identifier
*
* @description
* Validates input with given {@link FastifyMongooseRestOptions.validationSchema validation schema} and returns the modified resource
*
* @see {@link Model.findOne Mongooose findOne method}
* @see {@link Model.updateOne Mongooose updateOne method}
*/
modify: (0, operations_1.Modify)(newBasePath, model, options),
/**
* Route for querying a list of resources
*
* @description
* Returns a list of resources defined by the query parameters used in the request
*
* @see {@link Model.find Mongooose find method}
*/
list: (0, operations_1.List)(newBasePath, model, options),
/**
* Route for searching a list of resources
*
* @description
* Returns a list of resources defined by the body used in the request
*
* @see {@link Model.find Mongooose find method}
*/
search: (0, operations_1.Search)(newBasePath, model, options),
/**
* Route for inserting many resources
*
* @description
* Validates input with given {@link FastifyMongooseRestOptions.validationSchema validation schema} and returns the created resources
*
* @see {@link Model.insertMany Mongooose insertMany method}
*/
insertMany: (0, operations_1.InsertMany)(newBasePath, model, options),
};
}
exports.default = FastifyMongooseRest;
//# sourceMappingURL=index.js.map