Skip to content

Commit

Permalink
Add options builder
Browse files Browse the repository at this point in the history
  • Loading branch information
baranga committed Jun 4, 2019
1 parent c1e2d15 commit 48efe26
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @typedef MongoTenantOptions
* @property {string} tenantIdGetter
* @property {string} accessorMethod
* @property {*} tenantIdType
* @property {string} tenantIdKey
* @property {boolean} requireTenantId
*/

/**
* Sanitize plugin options
* @param {object} [input]
* @param {string} [input.tenantIdGetter=tenantId]
* @param {string} [input.accessorMethod=String]
* @param {*} [input.tenantIdType=byTenant]
* @param {string} [input.tenantIdKey=getTenantId]
* @param {string} [input.requireTenantId=true]
* @returns {MongoTenantOptions}
*/
const options = (input = {}) => ({
tenantIdKey: input.tenantIdKey || 'tenantId',
tenantIdType: input.tenantIdType || String,
accessorMethod: input.accessorMethod || 'byTenant',
tenantIdGetter: input.tenantIdGetter || 'getTenantId',
requireTenantId: input.requireTenantId === true,
});

module.exports = options;
Empty file added src/options.test.js
Empty file.

0 comments on commit 48efe26

Please sign in to comment.