From 48efe26713bc3e97c41d6c982274b96978f7cac8 Mon Sep 17 00:00:00 2001 From: baranga Date: Tue, 4 Jun 2019 09:39:00 +0200 Subject: [PATCH] Add options builder --- src/options.js | 28 ++++++++++++++++++++++++++++ src/options.test.js | 0 2 files changed, 28 insertions(+) create mode 100644 src/options.js create mode 100644 src/options.test.js 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