diff --git a/src/options.js b/src/options.js new file mode 100644 index 0000000..2d1f8fa --- /dev/null +++ b/src/options.js @@ -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; diff --git a/src/options.test.js b/src/options.test.js new file mode 100644 index 0000000..e69de29