2021-04-19 18:31:47 +02:00
|
|
|
const uuid = require("uuid/v4")
|
|
|
|
|
|
|
|
exports.ViewNames = {
|
|
|
|
USER_BY_EMAIL: "by_email",
|
|
|
|
}
|
|
|
|
|
2021-04-07 12:33:16 +02:00
|
|
|
exports.StaticDatabases = {
|
2021-04-16 19:09:34 +02:00
|
|
|
GLOBAL: {
|
|
|
|
name: "global-db",
|
2021-04-07 12:33:16 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const DocumentTypes = {
|
|
|
|
USER: "us",
|
2021-04-13 14:26:13 +02:00
|
|
|
APP: "app",
|
2021-04-07 12:33:16 +02:00
|
|
|
}
|
|
|
|
|
2021-04-08 12:20:37 +02:00
|
|
|
exports.DocumentTypes = DocumentTypes
|
|
|
|
|
2021-04-07 12:33:16 +02:00
|
|
|
const UNICODE_MAX = "\ufff0"
|
|
|
|
const SEPARATOR = "_"
|
|
|
|
|
2021-04-13 14:26:13 +02:00
|
|
|
exports.SEPARATOR = SEPARATOR
|
|
|
|
|
2021-04-07 12:33:16 +02:00
|
|
|
/**
|
2021-04-19 18:31:47 +02:00
|
|
|
* Generates a new global user ID.
|
2021-04-07 12:33:16 +02:00
|
|
|
* @returns {string} The new user ID which the user doc can be stored under.
|
|
|
|
*/
|
2021-04-19 18:31:47 +02:00
|
|
|
exports.generateUserID = () => {
|
|
|
|
return `${DocumentTypes.USER}${SEPARATOR}${uuid()}`
|
2021-04-12 19:31:58 +02:00
|
|
|
}
|
|
|
|
|
2021-04-07 12:33:16 +02:00
|
|
|
/**
|
|
|
|
* Gets parameters for retrieving users, this is a utility function for the getDocParams function.
|
|
|
|
*/
|
2021-04-19 18:31:47 +02:00
|
|
|
exports.getUserParams = (globalId = "", otherProps = {}) => {
|
|
|
|
if (!globalId) {
|
|
|
|
globalId = ""
|
2021-04-09 16:11:49 +02:00
|
|
|
}
|
2021-04-07 12:33:16 +02:00
|
|
|
return {
|
|
|
|
...otherProps,
|
2021-04-19 18:31:47 +02:00
|
|
|
startkey: `${DocumentTypes.USER}${SEPARATOR}${globalId}`,
|
|
|
|
endkey: `${DocumentTypes.USER}${SEPARATOR}${globalId}${UNICODE_MAX}`,
|
2021-04-07 12:33:16 +02:00
|
|
|
}
|
|
|
|
}
|