Fix code formatting
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
# Top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
[*.{js,jsx,ts,tsx}]
|
||||
quote_type = single
|
||||
|
||||
[*]
|
||||
# Set default charset to utf-8
|
||||
charset = utf-8
|
||||
|
||||
70
src/cli.js
70
src/cli.js
@@ -1,4 +1,4 @@
|
||||
const yargs = require("yargs");
|
||||
const yargs = require('yargs');
|
||||
|
||||
const usage = `
|
||||
Soul | REST and realtime server for SQLite
|
||||
@@ -6,57 +6,57 @@ Usage: soul [options]
|
||||
`;
|
||||
|
||||
let options = undefined;
|
||||
if (process.env.NO_CLI !== "true") {
|
||||
if (process.env.NO_CLI !== 'true') {
|
||||
options = yargs
|
||||
.usage(usage)
|
||||
.option("d", {
|
||||
alias: "database",
|
||||
describe: "SQLite database file or :memory:",
|
||||
type: "string",
|
||||
.option('d', {
|
||||
alias: 'database',
|
||||
describe: 'SQLite database file or :memory:',
|
||||
type: 'string',
|
||||
demandOption: true,
|
||||
})
|
||||
.option("p", {
|
||||
alias: "port",
|
||||
describe: "Port to listen on",
|
||||
type: "number",
|
||||
.option('p', {
|
||||
alias: 'port',
|
||||
describe: 'Port to listen on',
|
||||
type: 'number',
|
||||
demandOption: false,
|
||||
})
|
||||
.option("r", {
|
||||
alias: "rate-limit-enabled",
|
||||
describe: "Enable rate limiting",
|
||||
type: "boolean",
|
||||
.option('r', {
|
||||
alias: 'rate-limit-enabled',
|
||||
describe: 'Enable rate limiting',
|
||||
type: 'boolean',
|
||||
demandOption: false,
|
||||
})
|
||||
.option("c", {
|
||||
alias: "cors",
|
||||
describe: "CORS whitelist origins",
|
||||
type: "string",
|
||||
.option('c', {
|
||||
alias: 'cors',
|
||||
describe: 'CORS whitelist origins',
|
||||
type: 'string',
|
||||
demandOption: false,
|
||||
})
|
||||
.option("V", {
|
||||
alias: "verbose",
|
||||
describe: "Enable verbose logging",
|
||||
type: "string",
|
||||
.option('V', {
|
||||
alias: 'verbose',
|
||||
describe: 'Enable verbose logging',
|
||||
type: 'string',
|
||||
demandOption: false,
|
||||
choices: ["console", null],
|
||||
choices: ['console', null],
|
||||
})
|
||||
.options("e", {
|
||||
alias: "extensions",
|
||||
describe: "Extensions directory path to load",
|
||||
type: "string",
|
||||
.options('e', {
|
||||
alias: 'extensions',
|
||||
describe: 'Extensions directory path to load',
|
||||
type: 'string',
|
||||
demandOption: false,
|
||||
})
|
||||
.options("a", {
|
||||
alias: "auth",
|
||||
describe: "Enable authentication and authorization",
|
||||
type: "boolean",
|
||||
.options('a', {
|
||||
alias: 'auth',
|
||||
describe: 'Enable authentication and authorization',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
demandOption: false,
|
||||
})
|
||||
.options("S", {
|
||||
alias: "studio",
|
||||
describe: "Start Soul Studio in parallel",
|
||||
type: "boolean",
|
||||
.options('S', {
|
||||
alias: 'studio',
|
||||
describe: 'Start Soul Studio in parallel',
|
||||
type: 'boolean',
|
||||
demandOption: false,
|
||||
})
|
||||
.help(true).argv;
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
const dotenv = require("dotenv");
|
||||
const Joi = require("joi");
|
||||
const path = require("path");
|
||||
const dotenv = require('dotenv');
|
||||
const Joi = require('joi');
|
||||
const path = require('path');
|
||||
|
||||
const { yargs } = require("../cli");
|
||||
const { yargs } = require('../cli');
|
||||
|
||||
const { argv } = yargs;
|
||||
|
||||
dotenv.config({ path: path.join(__dirname, "../../.env") });
|
||||
dotenv.config({ path: path.join(__dirname, '../../.env') });
|
||||
|
||||
const envVarsSchema = Joi.object()
|
||||
.keys({
|
||||
CORE_PORT: Joi.number().positive().default(8000),
|
||||
|
||||
NODE_ENV: Joi.string()
|
||||
.valid("production", "development", "test")
|
||||
.default("production"),
|
||||
.valid('production', 'development', 'test')
|
||||
.default('production'),
|
||||
|
||||
DB: Joi.string().required(),
|
||||
VERBOSE: Joi.string().valid("console", null).default(null),
|
||||
VERBOSE: Joi.string().valid('console', null).default(null),
|
||||
|
||||
CORS_ORIGIN_WHITELIST: Joi.string().default("*"),
|
||||
CORS_ORIGIN_WHITELIST: Joi.string().default('*'),
|
||||
AUTH: Joi.boolean().default(false),
|
||||
|
||||
RATE_LIMIT_ENABLED: Joi.boolean().default(false),
|
||||
@@ -56,12 +56,12 @@ if (argv.auth) {
|
||||
env.AUTH = argv.auth;
|
||||
}
|
||||
|
||||
if (argv["rate-limit-enabled"]) {
|
||||
env.RATE_LIMIT_ENABLED = argv["rate-limit-enabled"];
|
||||
if (argv['rate-limit-enabled']) {
|
||||
env.RATE_LIMIT_ENABLED = argv['rate-limit-enabled'];
|
||||
}
|
||||
|
||||
const { value: envVars, error } = envVarsSchema
|
||||
.prefs({ errors: { label: "key" } })
|
||||
.prefs({ errors: { label: 'key' } })
|
||||
.validate(env);
|
||||
|
||||
if (error) {
|
||||
@@ -71,25 +71,25 @@ if (error) {
|
||||
module.exports = {
|
||||
env: envVars.NODE_ENV,
|
||||
|
||||
isProduction: envVars.NODE_ENV === "production",
|
||||
isDevelopment: envVars.NODE_ENV === "development",
|
||||
isTest: envVars.NODE_ENV === "test",
|
||||
isProduction: envVars.NODE_ENV === 'production',
|
||||
isDevelopment: envVars.NODE_ENV === 'development',
|
||||
isTest: envVars.NODE_ENV === 'test',
|
||||
|
||||
port: argv.port || envVars.CORE_PORT,
|
||||
verbose: argv["verbose"] || envVars.VERBOSE,
|
||||
verbose: argv['verbose'] || envVars.VERBOSE,
|
||||
|
||||
db: {
|
||||
filename: argv.database || envVars.DB || ":memory:",
|
||||
filename: argv.database || envVars.DB || ':memory:',
|
||||
},
|
||||
cors: {
|
||||
origin: argv.cors?.split(",") ||
|
||||
envVars.CORS_ORIGIN_WHITELIST?.split(",") || ["*"],
|
||||
origin: argv.cors?.split(',') ||
|
||||
envVars.CORS_ORIGIN_WHITELIST?.split(',') || ['*'],
|
||||
},
|
||||
|
||||
auth: argv.auth || envVars.AUTH,
|
||||
|
||||
rateLimit: {
|
||||
enabled: argv["rate-limit-enabled"] || envVars.RATE_LIMIT_ENABLED,
|
||||
enabled: argv['rate-limit-enabled'] || envVars.RATE_LIMIT_ENABLED,
|
||||
windowMs: envVars.RATE_LIMIT_WINDOW,
|
||||
max: envVars.RATE_LIMIT_MAX,
|
||||
},
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
module.exports = {
|
||||
roleSchema: [
|
||||
{
|
||||
name: "name",
|
||||
type: "TEXT",
|
||||
name: 'name',
|
||||
type: 'TEXT',
|
||||
primaryKey: false,
|
||||
notNull: true,
|
||||
unique: false,
|
||||
@@ -11,30 +11,30 @@ module.exports = {
|
||||
|
||||
userSchema: [
|
||||
{
|
||||
name: "username",
|
||||
type: "TEXT",
|
||||
name: 'username',
|
||||
type: 'TEXT',
|
||||
primaryKey: false,
|
||||
notNull: true,
|
||||
unique: false,
|
||||
},
|
||||
{
|
||||
name: "hashed_password",
|
||||
type: "TEXT",
|
||||
name: 'hashed_password',
|
||||
type: 'TEXT',
|
||||
primaryKey: false,
|
||||
notNull: true,
|
||||
unique: false,
|
||||
},
|
||||
{
|
||||
name: "salt",
|
||||
type: "NUMERIC",
|
||||
name: 'salt',
|
||||
type: 'NUMERIC',
|
||||
primaryKey: false,
|
||||
notNull: true,
|
||||
unique: false,
|
||||
},
|
||||
|
||||
{
|
||||
name: "is_superuser",
|
||||
type: "BOOLEAN",
|
||||
name: 'is_superuser',
|
||||
type: 'BOOLEAN',
|
||||
primaryKey: false,
|
||||
notNull: true,
|
||||
unique: false,
|
||||
@@ -43,49 +43,49 @@ module.exports = {
|
||||
|
||||
rolePermissionSchema: [
|
||||
{
|
||||
name: "role_id",
|
||||
type: "NUMERIC",
|
||||
name: 'role_id',
|
||||
type: 'NUMERIC',
|
||||
primaryKey: false,
|
||||
notNull: true,
|
||||
unique: false,
|
||||
foreignKey: { table: "_roles", column: "id" },
|
||||
foreignKey: { table: '_roles', column: 'id' },
|
||||
},
|
||||
|
||||
{
|
||||
name: "tableName",
|
||||
type: "TEXT",
|
||||
name: 'tableName',
|
||||
type: 'TEXT',
|
||||
primaryKey: false,
|
||||
notNull: true,
|
||||
unique: false,
|
||||
},
|
||||
|
||||
{
|
||||
name: "create",
|
||||
type: "BOOLEAN",
|
||||
name: 'create',
|
||||
type: 'BOOLEAN',
|
||||
primaryKey: false,
|
||||
notNull: true,
|
||||
unique: false,
|
||||
},
|
||||
|
||||
{
|
||||
name: "read",
|
||||
type: "BOOLEAN",
|
||||
name: 'read',
|
||||
type: 'BOOLEAN',
|
||||
primaryKey: false,
|
||||
notNull: true,
|
||||
unique: false,
|
||||
},
|
||||
|
||||
{
|
||||
name: "update",
|
||||
type: "BOOLEAN",
|
||||
name: 'update',
|
||||
type: 'BOOLEAN',
|
||||
primaryKey: false,
|
||||
notNull: true,
|
||||
unique: false,
|
||||
},
|
||||
|
||||
{
|
||||
name: "delete",
|
||||
type: "BOOLEAN",
|
||||
name: 'delete',
|
||||
type: 'BOOLEAN',
|
||||
primaryKey: false,
|
||||
notNull: true,
|
||||
unique: false,
|
||||
@@ -94,21 +94,21 @@ module.exports = {
|
||||
|
||||
usersRoleSchema: [
|
||||
{
|
||||
name: "user_id",
|
||||
type: "NUMERIC",
|
||||
name: 'user_id',
|
||||
type: 'NUMERIC',
|
||||
primaryKey: false,
|
||||
notNull: true,
|
||||
unique: false,
|
||||
foreignKey: { table: "_users", column: "id" },
|
||||
foreignKey: { table: '_users', column: 'id' },
|
||||
},
|
||||
|
||||
{
|
||||
name: "role_id",
|
||||
type: "NUMERIC",
|
||||
name: 'role_id',
|
||||
type: 'NUMERIC',
|
||||
primaryKey: false,
|
||||
notNull: true,
|
||||
unique: false,
|
||||
foreignKey: { table: "_roles", column: "id" },
|
||||
foreignKey: { table: '_roles', column: 'id' },
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
const dbTables = require("./dbTables");
|
||||
const dbTables = require('./dbTables');
|
||||
|
||||
module.exports = { dbTables };
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
const { tableService } = require("../services");
|
||||
const { dbTables } = require("../constants");
|
||||
const { tableService } = require('../services');
|
||||
const { dbTables } = require('../constants');
|
||||
|
||||
const createDefaultTables = async () => {
|
||||
//1. Check if the default tables are already created
|
||||
const roleTable = tableService.checkTableExists("_roles");
|
||||
const usersTable = tableService.checkTableExists("_users");
|
||||
const roleTable = tableService.checkTableExists('_roles');
|
||||
const usersTable = tableService.checkTableExists('_users');
|
||||
const rolesPermissionTable =
|
||||
tableService.checkTableExists("_roles_permissions");
|
||||
const usersRolesTable = tableService.checkTableExists("_users_roles");
|
||||
tableService.checkTableExists('_roles_permissions');
|
||||
const usersRolesTable = tableService.checkTableExists('_users_roles');
|
||||
|
||||
//2. Create default auth tables
|
||||
if (!roleTable) {
|
||||
tableService.createTable("_roles", dbTables.roleSchema);
|
||||
tableService.createTable('_roles', dbTables.roleSchema);
|
||||
}
|
||||
|
||||
if (!usersTable) {
|
||||
tableService.createTable("_users", dbTables.userSchema);
|
||||
tableService.createTable('_users', dbTables.userSchema);
|
||||
}
|
||||
|
||||
if (!rolesPermissionTable) {
|
||||
tableService.createTable(
|
||||
"_roles_permissions",
|
||||
'_roles_permissions',
|
||||
dbTables.rolePermissionSchema,
|
||||
);
|
||||
}
|
||||
|
||||
if (!usersRolesTable) {
|
||||
tableService.createTable("_users_roles", dbTables.usersRoleSchema);
|
||||
tableService.createTable('_users_roles', dbTables.usersRoleSchema);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -13,13 +13,13 @@ module.exports = (db) => {
|
||||
let column = `'${name}' '${type}'`;
|
||||
|
||||
if (notNull) {
|
||||
column += " NOT NULL";
|
||||
column += ' NOT NULL';
|
||||
}
|
||||
if (unique) {
|
||||
column += " UNIQUE";
|
||||
column += ' UNIQUE';
|
||||
}
|
||||
if (primaryKey) {
|
||||
column += " PRIMARY KEY";
|
||||
column += ' PRIMARY KEY';
|
||||
}
|
||||
if (foreignKey) {
|
||||
column += ` REFERENCES ${foreignKey.table}(${foreignKey.column})`;
|
||||
@@ -33,7 +33,7 @@ module.exports = (db) => {
|
||||
|
||||
return column;
|
||||
})
|
||||
.join(", ");
|
||||
.join(', ');
|
||||
|
||||
// add id if primary key is not defined
|
||||
if (!schema.find((field) => field.primaryKey)) {
|
||||
@@ -65,7 +65,7 @@ module.exports = (db) => {
|
||||
ON ${tableName} (${field})
|
||||
`;
|
||||
})
|
||||
.join(";");
|
||||
.join(';');
|
||||
|
||||
const query = `CREATE TABLE ${tableName} (${schemaString})`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user