Change endpoint from persons to people

This commit is contained in:
xfarrow
2025-03-23 21:00:08 +01:00
parent 4ae263662c
commit d005193f63
7158 changed files with 700476 additions and 735 deletions

View File

@ -0,0 +1,57 @@
const Client = require('../../client');
const { SUPPORTED_CLIENTS } = require('../../constants');
const parseConnection = require('./parse-connection');
const { getDialectByNameOrAlias } = require('../../dialects');
function resolveConfig(config) {
let Dialect;
let resolvedConfig;
// If config is a string, try to parse it
const parsedConfig =
typeof config === 'string'
? Object.assign(parseConnection(config), arguments[2])
: config;
// If user provided no relevant parameters, use generic client
if (
arguments.length === 0 ||
(!parsedConfig.client && !parsedConfig.dialect)
) {
Dialect = Client;
}
// If user provided Client constructor as a parameter, use it
else if (typeof parsedConfig.client === 'function') {
Dialect = parsedConfig.client;
}
// If neither applies, let's assume user specified name of a client or dialect as a string
else {
const clientName = parsedConfig.client || parsedConfig.dialect;
if (!SUPPORTED_CLIENTS.includes(clientName)) {
throw new Error(
`knex: Unknown configuration option 'client' value ${clientName}. Note that it is case-sensitive, check documentation for supported values.`
);
}
Dialect = getDialectByNameOrAlias(clientName);
}
// If config connection parameter is passed as string, try to parse it
if (typeof parsedConfig.connection === 'string') {
resolvedConfig = Object.assign({}, parsedConfig, {
connection: parseConnection(parsedConfig.connection).connection,
});
} else {
resolvedConfig = Object.assign({}, parsedConfig);
}
return {
resolvedConfig,
Dialect,
};
}
module.exports = {
resolveConfig,
};

View File

@ -0,0 +1,87 @@
const { parse } = require('pg-connection-string');
const parsePG = parse;
const isWindows = process && process.platform && process.platform === 'win32';
/**
* @param str
* @returns {URL}
*/
function tryParse(str) {
try {
return new URL(str);
} catch (e) {
return null;
}
}
module.exports = function parseConnectionString(str) {
const parsed = tryParse(str);
const isDriveLetter = isWindows && parsed && parsed.protocol.length === 2;
if (!parsed || isDriveLetter) {
return {
client: 'sqlite3',
connection: {
filename: str,
},
};
}
let { protocol } = parsed;
if (protocol.slice(-1) === ':') {
protocol = protocol.slice(0, -1);
}
const isPG = ['postgresql', 'postgres'].includes(protocol);
return {
client: protocol,
connection: isPG ? parsePG(str) : connectionObject(parsed),
};
};
/**
* @param {URL} parsed
* @returns {{}}
*/
function connectionObject(parsed) {
const connection = {};
let db = parsed.pathname;
if (db[0] === '/') {
db = db.slice(1);
}
connection.database = db;
if (parsed.hostname) {
if (parsed.protocol.indexOf('mssql') === 0) {
connection.server = parsed.hostname;
} else {
connection.host = parsed.hostname;
}
}
if (parsed.port) {
connection.port = parsed.port;
}
if (parsed.username || parsed.password) {
connection.user = decodeURIComponent(parsed.username);
}
if (parsed.password) {
connection.password = decodeURIComponent(parsed.password);
}
if (parsed.searchParams) {
for (const [key, value] of parsed.searchParams.entries()) {
const isNestedConfigSupported = ['mysql:', 'mariadb:', 'mssql:'].includes(
parsed.protocol
);
if (isNestedConfigSupported) {
try {
connection[key] = JSON.parse(value);
} catch (err) {
connection[key] = value;
}
} else {
connection[key] = value;
}
}
}
return connection;
}