Socket
Socket
Sign inDemoInstall

decentraland-server

Package Overview
Dependencies
96
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.14.0 to 3.0.0

66

dist/cli/index.js
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.prompt = exports.confirm = exports.runProgram = void 0;
var program = require("commander");
var inquirer = require("inquirer");
const program = require("commander");
const inquirer = require("inquirer");
function runProgram(clients) {
for (var _i = 0, clients_1 = clients; _i < clients_1.length; _i++) {
var client = clients_1[_i];
for (const client of clients) {
client.addCommands(program);

@@ -54,19 +17,10 @@ }

exports.runProgram = runProgram;
function confirm(text, defaultAnswer) {
return __awaiter(this, void 0, void 0, function () {
var res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, inquirer.prompt({
type: 'confirm',
name: 'confirm',
message: text,
default: defaultAnswer
})];
case 1:
res = _a.sent();
return [2, res.confirm];
}
});
async function confirm(text, defaultAnswer) {
const res = await inquirer.prompt({
type: 'confirm',
name: 'confirm',
message: text,
default: defaultAnswer
});
return res.confirm;
}

@@ -73,0 +27,0 @@ exports.confirm = confirm;

2

dist/db/index.js

@@ -14,3 +14,3 @@ "use strict";

exports.clients = void 0;
var postgres_1 = require("./postgres");
const postgres_1 = require("./postgres");
__exportStar(require("./postgres"), exports);

@@ -17,0 +17,0 @@ __exportStar(require("./types"), exports);

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.postgres = exports.Postgres = void 0;
var pg = require("pg");
var Postgres = (function () {
function Postgres() {
const pg = require("pg");
class Postgres {
async connect(connectionString) {
this.client = new pg.Client(connectionString);
await this.client.connect();
return this.client;
}
Postgres.prototype.connect = function (connectionString) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this.client = new pg.Client(connectionString);
return [4, this.client.connect()];
case 1:
_a.sent();
return [2, this.client];
}
});
});
};
Postgres.prototype.query = function (queryString, values) {
return __awaiter(this, void 0, void 0, function () {
var result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.client.query(queryString, values)];
case 1:
result = _a.sent();
return [2, result.rows];
}
});
});
};
Postgres.prototype.count = function (tableName, conditions, extra) {
if (extra === void 0) { extra = ''; }
async query(queryString, values) {
const result = await this.client.query(queryString, values);
return result.rows;
}
count(tableName, conditions, extra = '') {
return this._query('SELECT COUNT(*) as count', tableName, conditions, undefined, extra);
};
Postgres.prototype.select = function (tableName, conditions, orderBy, extra) {
}
select(tableName, conditions, orderBy, extra) {
return this._query('SELECT *', tableName, conditions, orderBy, extra);
};
Postgres.prototype.selectOne = function (tableName, conditions, orderBy) {
return __awaiter(this, void 0, void 0, function () {
var rows;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this._query('SELECT *', tableName, conditions, orderBy, 'LIMIT 1')];
case 1:
rows = _a.sent();
return [2, rows[0]];
}
});
});
};
Postgres.prototype.insert = function (tableName, changes, primaryKey, onConflict) {
if (primaryKey === void 0) { primaryKey = ''; }
if (onConflict === void 0) { onConflict = { target: [], changes: {} }; }
return __awaiter(this, void 0, void 0, function () {
var values, conflictValues, returning;
return __generator(this, function (_a) {
if (!changes) {
throw new Error("Tried to perform an insert on " + tableName + " without any values. Supply a changes object");
}
values = Object.values(changes);
conflictValues = Object.values(onConflict.changes || {});
returning = primaryKey ? "RETURNING " + primaryKey : '';
return [2, this.client.query("INSERT INTO " + tableName + "(\n " + this.toColumnFields(changes) + "\n ) VALUES(\n " + this.toValuePlaceholders(changes) + "\n )\n " + this.toOnConflictUpsert(onConflict, values.length) + "\n " + returning, values.concat(conflictValues))];
});
});
};
Postgres.prototype.update = function (tableName, changes, conditions) {
return __awaiter(this, void 0, void 0, function () {
var changeValues, conditionValues, whereClauses, values;
return __generator(this, function (_a) {
if (!changes) {
throw new Error("Tried to update " + tableName + " without any values. Supply a changes object");
}
if (!conditions) {
throw new Error("Tried to update " + tableName + " without a WHERE clause. Supply a conditions object");
}
changeValues = Object.values(changes);
conditionValues = Object.values(conditions);
whereClauses = this.toAssignmentFields(conditions, changeValues.length);
values = changeValues.concat(conditionValues);
return [2, this.client.query("UPDATE " + tableName + "\n SET " + this.toAssignmentFields(changes) + "\n WHERE " + whereClauses.join(' AND '), values)];
});
});
};
Postgres.prototype.delete = function (tableName, conditions) {
}
async selectOne(tableName, conditions, orderBy) {
const rows = await this._query('SELECT *', tableName, conditions, orderBy, 'LIMIT 1');
return rows[0];
}
async insert(tableName, changes, primaryKey = '', onConflict = { target: [], changes: {} }) {
if (!changes) {
throw new Error(`Tried to perform an insert on ${tableName} without any values. Supply a changes object`);
}
const values = Object.values(changes);
const conflictValues = Object.values(onConflict.changes || {});
const returning = primaryKey ? `RETURNING ${primaryKey}` : '';
return this.client.query(`INSERT INTO ${tableName}(
${this.toColumnFields(changes)}
) VALUES(
${this.toValuePlaceholders(changes)}
)
${this.toOnConflictUpsert(onConflict, values.length)}
${returning}`, values.concat(conflictValues));
}
async update(tableName, changes, conditions) {
if (!changes) {
throw new Error(`Tried to update ${tableName} without any values. Supply a changes object`);
}
if (!conditions) {
throw new Error("Tried to update " + tableName + " without a WHERE clause. Supply a conditions object");
throw new Error(`Tried to update ${tableName} without a WHERE clause. Supply a conditions object`);
}
var values = Object.values(conditions);
return this.client.query("DELETE FROM " + tableName + "\n WHERE " + this.toAssignmentFields(conditions).join(' AND '), values);
};
Postgres.prototype.createTable = function (tableName, rows, options) {
if (options === void 0) { options = {}; }
return __awaiter(this, void 0, void 0, function () {
var _a, sequenceName, _b, primaryKey, primaryKeyClause;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
_a = options.sequenceName, sequenceName = _a === void 0 ? tableName + "_id_seq" : _a, _b = options.primaryKey, primaryKey = _b === void 0 ? '' : _b;
primaryKeyClause = primaryKey ? "PRIMARY KEY (\"" + primaryKey + "\")" : '';
if (!sequenceName) return [3, 2];
return [4, this.createSequence(sequenceName)];
case 1:
_c.sent();
_c.label = 2;
case 2: return [4, this.client.query("CREATE TABLE IF NOT EXISTS \"" + tableName + "\" (\n " + rows + "\n " + primaryKeyClause + "\n );")];
case 3:
_c.sent();
if (!sequenceName) return [3, 5];
return [4, this.alterSequenceOwnership(sequenceName, tableName)];
case 4:
_c.sent();
_c.label = 5;
case 5: return [2];
}
});
});
};
Postgres.prototype.createIndex = function (tableName, name, fields, conditions) {
if (conditions === void 0) { conditions = {}; }
var unique = conditions.unique === true ? 'UNIQUE' : '';
return this.client.query("CREATE " + unique + " INDEX IF NOT EXISTS " + name + " ON " + tableName + " (" + fields.join(',') + ")");
};
Postgres.prototype.createSequence = function (name) {
const changeValues = Object.values(changes);
const conditionValues = Object.values(conditions);
const whereClauses = this.toAssignmentFields(conditions, changeValues.length);
const values = changeValues.concat(conditionValues);
return this.client.query(`UPDATE ${tableName}
SET ${this.toAssignmentFields(changes)}
WHERE ${whereClauses.join(' AND ')}`, values);
}
delete(tableName, conditions) {
if (!conditions) {
throw new Error(`Tried to update ${tableName} without a WHERE clause. Supply a conditions object`);
}
const values = Object.values(conditions);
return this.client.query(`DELETE FROM ${tableName}
WHERE ${this.toAssignmentFields(conditions).join(' AND ')}`, values);
}
async createTable(tableName, rows, options = {}) {
const { sequenceName = `${tableName}_id_seq`, primaryKey = '' } = options;
const primaryKeyClause = primaryKey ? `PRIMARY KEY ("${primaryKey}")` : '';
if (sequenceName)
await this.createSequence(sequenceName);
await this.client.query(`CREATE TABLE IF NOT EXISTS "${tableName}" (
${rows}
${primaryKeyClause}
);`);
if (sequenceName)
await this.alterSequenceOwnership(sequenceName, tableName);
}
createIndex(tableName, name, fields, conditions = {}) {
const unique = conditions.unique === true ? 'UNIQUE' : '';
return this.client.query(`CREATE ${unique} INDEX IF NOT EXISTS ${name} ON ${tableName} (${fields.join(',')})`);
}
createSequence(name) {
try {
return this.client.query("CREATE SEQUENCE " + name + ";");
return this.client.query(`CREATE SEQUENCE ${name};`);
}
catch (e) {
}
};
Postgres.prototype.alterSequenceOwnership = function (name, owner, columnName) {
if (columnName === void 0) { columnName = 'id'; }
return this.client.query("ALTER SEQUENCE " + name + " OWNED BY " + owner + "." + columnName + ";");
};
Postgres.prototype.truncate = function (tableName) {
return this.client.query("TRUNCATE " + tableName + " RESTART IDENTITY;");
};
Postgres.prototype.toOnConflictUpsert = function (_a, indexStart) {
var target = _a.target, changes = _a.changes;
if (indexStart === void 0) { indexStart = 0; }
}
alterSequenceOwnership(name, owner, columnName = 'id') {
return this.client.query(`ALTER SEQUENCE ${name} OWNED BY ${owner}.${columnName};`);
}
truncate(tableName) {
return this.client.query(`TRUNCATE ${tableName} RESTART IDENTITY;`);
}
toOnConflictUpsert({ target, changes }, indexStart = 0) {
return target.length > 0 && changes
? "ON CONFLICT (" + target + ") DO\n UPDATE SET " + this.toAssignmentFields(changes, indexStart)
? `ON CONFLICT (${target}) DO
UPDATE SET ${this.toAssignmentFields(changes, indexStart)}`
: 'ON CONFLICT DO NOTHING';
};
Postgres.prototype.toColumnFields = function (columns) {
var columnNames = Object.keys(columns);
return columnNames.map(function (name) { return "\"" + name + "\""; });
};
Postgres.prototype.toAssignmentFields = function (columns, start) {
if (start === void 0) { start = 0; }
var columnNames = Object.keys(columns);
return columnNames.map(function (column, index) { return "\"" + column + "\" = $" + (index + start + 1); });
};
Postgres.prototype.toValuePlaceholders = function (columns, start) {
if (start === void 0) { start = 0; }
var columnNames = Object.keys(columns);
return columnNames.map(function (_, index) { return "$" + (index + start + 1); });
};
Postgres.prototype.getOrderValues = function (order) {
return Object.keys(order).map(function (column) { return "\"" + column + "\" " + order[column]; });
};
Postgres.prototype.setTypeParser = function (oid, parser) {
}
toColumnFields(columns) {
const columnNames = Object.keys(columns);
return columnNames.map(name => `"${name}"`);
}
toAssignmentFields(columns, start = 0) {
const columnNames = Object.keys(columns);
return columnNames.map((column, index) => `"${column}" = $${index + start + 1}`);
}
toValuePlaceholders(columns, start = 0) {
const columnNames = Object.keys(columns);
return columnNames.map((_, index) => `$${index + start + 1}`);
}
getOrderValues(order) {
return Object.keys(order).map(column => `"${column}" ${order[column]}`);
}
setTypeParser(oid, parser) {
pg.types.setTypeParser(oid, parser);
};
Postgres.prototype.close = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, this.client.end()];
});
});
};
Postgres.prototype._query = function (method, tableName, conditions, orderBy, extra) {
if (extra === void 0) { extra = ''; }
return __awaiter(this, void 0, void 0, function () {
var values, where, order, result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
values = [];
where = '';
order = '';
if (conditions) {
values = Object.values(conditions);
where = "WHERE " + this.toAssignmentFields(conditions).join(' AND ');
}
if (orderBy) {
order = "ORDER BY " + this.getOrderValues(orderBy);
}
return [4, this.client.query(method + " FROM " + tableName + " " + where + " " + order + " " + extra, values)];
case 1:
result = _a.sent();
return [2, result.rows];
}
});
});
};
return Postgres;
}());
}
async close() {
return this.client.end();
}
async _query(method, tableName, conditions, orderBy, extra = '') {
let values = [];
let where = '';
let order = '';
if (conditions) {
values = Object.values(conditions);
where = `WHERE ${this.toAssignmentFields(conditions).join(' AND ')}`;
}
if (orderBy) {
order = `ORDER BY ${this.getOrderValues(orderBy)}`;
}
const result = await this.client.query(`${method} FROM ${tableName} ${where} ${order} ${extra}`, values);
return result.rows;
}
}
exports.Postgres = Postgres;
exports.postgres = new Postgres();
//# sourceMappingURL=postgres.js.map

@@ -14,7 +14,7 @@ "use strict";

exports.server = exports.db = exports.cli = void 0;
var server = require("./server");
const server = require("./server");
exports.server = server;
var cli = require("./cli");
const cli = require("./cli");
exports.cli = cli;
var db = require("./db");
const db = require("./db");
exports.db = db;

@@ -21,0 +21,0 @@ var Model_1 = require("./Model");

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Model = void 0;
var db_1 = require("./db");
var Model = (function () {
function Model(attributes) {
var Constructor = this.getConstructor();
this.tableName = Constructor.tableName;
this.primaryKey = Constructor.primaryKey;
if (attributes) {
this.attributes = attributes;
const db_1 = require("./db");
let Model = (() => {
class Model {
constructor(attributes) {
const Constructor = this.getConstructor();
this.tableName = Constructor.tableName;
this.primaryKey = Constructor.primaryKey;
if (attributes) {
this.attributes = attributes;
}
}
}
Model.setDb = function (clientName) {
if (clientName === void 0) { clientName = 'postgres'; }
this.db = db_1.clients[clientName];
};
Model.find = function (conditions, orderBy, extra) {
return this.db.select(this.tableName, conditions, orderBy, extra);
};
Model.findOne = function (primaryKeyOrCond, orderBy) {
var _a;
var conditions = typeof primaryKeyOrCond === 'object'
? primaryKeyOrCond
: (_a = {}, _a[this.primaryKey] = primaryKeyOrCond, _a);
return this.db.selectOne(this.tableName, conditions, orderBy);
};
Model.count = function (conditions, extra) {
return __awaiter(this, void 0, void 0, function () {
var result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.db.count(this.tableName, conditions, extra)];
case 1:
result = _a.sent();
return [2, result.length ? parseInt(result[0].count, 10) : 0];
static setDb(clientName = 'postgres') {
this.db = db_1.clients[clientName];
}
static find(conditions, orderBy, extra) {
return this.db.select(this.tableName, conditions, orderBy, extra);
}
static findOne(primaryKeyOrCond, orderBy) {
const conditions = typeof primaryKeyOrCond === 'object'
? primaryKeyOrCond
: { [this.primaryKey]: primaryKeyOrCond };
return this.db.selectOne(this.tableName, conditions, orderBy);
}
static async count(conditions, extra) {
const result = await this.db.count(this.tableName, conditions, extra);
return result.length ? parseInt(result[0].count, 10) : 0;
}
static async query(queryString, values) {
return this.db.query(queryString, values);
}
static async create(row) {
return this.insert(row);
}
static async upsert(row, onConflict = { target: [this.primaryKey] }) {
return this.insert(row, onConflict);
}
static update(changes, conditions) {
changes = this.withTimestamps
? { ...changes, updated_at: changes.updated_at || new Date() }
: changes;
return this.db.update(this.tableName, changes, conditions);
}
static delete(conditions) {
return this.db.delete(this.tableName, conditions);
}
static async insert(row, onConflict) {
row = Object.assign({}, row);
if (onConflict) {
const changes = Object.assign({}, onConflict.changes);
onConflict.changes = onConflict.changes ? changes : row;
}
if (this.withTimestamps) {
const now = new Date();
Object.assign(row, {
created_at: row.created_at || now,
updated_at: row.updated_at || now
});
if (onConflict) {
const changes = onConflict.changes || {};
changes.updated_at = changes.updated_at || now;
onConflict.changes = changes;
}
});
});
};
Model.query = function (queryString, values) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, this.db.query(queryString, values)];
});
});
};
Model.create = function (row) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, this.insert(row)];
});
});
};
Model.upsert = function (row, onConflict) {
if (onConflict === void 0) { onConflict = { target: [this.primaryKey] }; }
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, this.insert(row, onConflict)];
});
});
};
Model.update = function (changes, conditions) {
changes = this.withTimestamps
? __assign(__assign({}, changes), { updated_at: changes.updated_at || new Date() }) : changes;
return this.db.update(this.tableName, changes, conditions);
};
Model.delete = function (conditions) {
return this.db.delete(this.tableName, conditions);
};
Model.insert = function (row, onConflict) {
return __awaiter(this, void 0, void 0, function () {
var changes, now, changes, insertion, newRow;
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
row = Object.assign({}, row);
if (onConflict) {
changes = Object.assign({}, onConflict.changes);
onConflict.changes = onConflict.changes ? changes : row;
}
if (this.withTimestamps) {
now = new Date();
Object.assign(row, {
created_at: row.created_at || now,
updated_at: row.updated_at || now
});
if (onConflict) {
changes = onConflict.changes || {};
changes.updated_at = changes.updated_at || now;
onConflict.changes = changes;
}
}
return [4, this.db.insert(this.tableName, row, this.primaryKey, onConflict)];
case 1:
insertion = _b.sent();
newRow = insertion.rows[0];
if (newRow && this.primaryKey) {
Object.assign(row, (_a = {}, _a[this.primaryKey] = newRow[this.primaryKey], _a));
}
return [2, row];
}
});
});
};
Model.prototype.getConstructor = function () {
return this.constructor;
};
Model.prototype.getDefaultQuery = function () {
var query = {};
query[this.primaryKey] = this.get(this.primaryKey);
return query;
};
Model.prototype.retreive = function (conditions) {
return __awaiter(this, void 0, void 0, function () {
var Constructor, query, attributes;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
Constructor = this.getConstructor();
query = conditions ? conditions : this.getDefaultQuery();
return [4, Constructor.findOne(query)];
case 1:
attributes = _a.sent();
if (attributes) {
this.attributes = attributes;
}
return [2, this.attributes];
}
});
});
};
Model.prototype.create = function () {
return __awaiter(this, void 0, void 0, function () {
var row;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.getConstructor().create(this.attributes)];
case 1:
row = _a.sent();
this.set(this.primaryKey, row[this.primaryKey]);
return [2, row];
}
});
});
};
Model.prototype.upsert = function (onConflict) {
return __awaiter(this, void 0, void 0, function () {
var row;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.getConstructor().upsert(this.attributes, onConflict)];
case 1:
row = _a.sent();
this.set(this.primaryKey, row[this.primaryKey]);
return [2, row];
}
});
});
};
Model.prototype.update = function (conditions) {
var query = conditions ? conditions : this.getDefaultQuery();
return this.getConstructor().update(this.attributes, query);
};
Model.prototype.delete = function (conditions) {
var query = conditions ? conditions : this.getDefaultQuery();
return this.getConstructor().delete(query);
};
Model.prototype.isEmpty = function () {
return !this.attributes || Object.keys(this.attributes).length === 0;
};
Model.prototype.get = function (key) {
return this.attributes[key];
};
Model.prototype.getAll = function () {
return this.attributes;
};
Model.prototype.getIn = function (keyPath) {
if (keyPath.length === 0)
return null;
var value = this.attributes;
for (var _i = 0, keyPath_1 = keyPath; _i < keyPath_1.length; _i++) {
var prop = keyPath_1[_i];
if (!value)
return null;
value = value[prop];
}
const insertion = await this.db.insert(this.tableName, row, this.primaryKey, onConflict);
const newRow = insertion.rows[0];
if (newRow && this.primaryKey) {
Object.assign(row, { [this.primaryKey]: newRow[this.primaryKey] });
}
return row;
}
return value;
};
Model.prototype.set = function (key, value) {
this.attributes[key] = value;
return this;
};
Model.prototype.setIn = function (keyPath, value) {
var keyAmount = keyPath.length;
var nested = this.attributes;
for (var i = 0; i < keyAmount; i++) {
if (!nested)
getConstructor() {
return this.constructor;
}
getDefaultQuery() {
const query = {};
query[this.primaryKey] = this.get(this.primaryKey);
return query;
}
async retreive(conditions) {
const Constructor = this.getConstructor();
const query = conditions ? conditions : this.getDefaultQuery();
const attributes = await Constructor.findOne(query);
if (attributes) {
this.attributes = attributes;
}
return this.attributes;
}
async create() {
const row = await this.getConstructor().create(this.attributes);
this.set(this.primaryKey, row[this.primaryKey]);
return row;
}
async upsert(onConflict) {
const row = await this.getConstructor().upsert(this.attributes, onConflict);
this.set(this.primaryKey, row[this.primaryKey]);
return row;
}
update(conditions) {
const query = conditions ? conditions : this.getDefaultQuery();
return this.getConstructor().update(this.attributes, query);
}
delete(conditions) {
const query = conditions ? conditions : this.getDefaultQuery();
return this.getConstructor().delete(query);
}
isEmpty() {
return !this.attributes || Object.keys(this.attributes).length === 0;
}
get(key) {
return this.attributes[key];
}
getAll() {
return this.attributes;
}
getIn(keyPath) {
if (keyPath.length === 0)
return null;
var key = keyPath[i];
if (i + 1 === keyAmount) {
nested[key] = value;
let value = this.attributes;
for (let prop of keyPath) {
if (!value)
return null;
value = value[prop];
}
else {
nested = nested[key];
return value;
}
set(key, value) {
this.attributes[key] = value;
return this;
}
setIn(keyPath, value) {
let keyAmount = keyPath.length;
let nested = this.attributes;
for (let i = 0; i < keyAmount; i++) {
if (!nested)
return null;
let key = keyPath[i];
if (i + 1 === keyAmount) {
nested[key] = value;
}
else {
nested = nested[key];
}
}
return this;
}
return this;
};
Model.prototype.assign = function (template) {
this.attributes = Object.assign({}, this.attributes, template);
return this;
};
assign(template) {
this.attributes = Object.assign({}, this.attributes, template);
return this;
}
}
Model.tableName = '';

@@ -267,4 +159,4 @@ Model.primaryKey = 'id';

return Model;
}());
})();
exports.Model = Model;
//# sourceMappingURL=Model.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.sendError = exports.sendOk = exports.extractFromReq = exports.handleRequest = exports.useRollbar = void 0;
var Rollbar = require("rollbar");
var rollbar;
const Rollbar = require("rollbar");
let rollbar;
function useRollbar(accessToken) {
if (!accessToken)
return;
rollbar = new Rollbar({ accessToken: accessToken });
rollbar = new Rollbar({ accessToken });
}
exports.useRollbar = useRollbar;
function handleRequest(callback) {
var _this = this;
return function (req, res) { return __awaiter(_this, void 0, void 0, function () {
var data, error_1, data, message, statusCode;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4, callback(req, res)];
case 1:
data = _a.sent();
return [2, res.json(sendOk(data))];
case 2:
error_1 = _a.sent();
data = error_1.data || {};
message = error_1.message;
statusCode = error_1.statusCode;
if (rollbar)
rollbar.error(error_1, req);
if (statusCode) {
res.status(statusCode);
}
return [2, res.json(sendError(data, message))];
case 3: return [2];
return async (req, res) => {
try {
const data = await callback(req, res);
return res.json(sendOk(data));
}
catch (error) {
const data = error.data || {};
const message = error.message;
const statusCode = error.statusCode;
if (rollbar)
rollbar.error(error, req);
if (statusCode) {
res.status(statusCode);
}
});
}); };
return res.json(sendError(data, message));
}
};
}
exports.handleRequest = handleRequest;
function extractFromReq(req, param) {
var value;
let value;
if (req.query && req.query[param]) {

@@ -89,3 +44,3 @@ value = req.query[param];

if (!value) {
throw new Error("Could not get " + param + " from request");
throw new Error(`Could not get ${param} from request`);
}

@@ -96,9 +51,9 @@ return value;

function sendOk(data) {
return { ok: true, data: data };
return { ok: true, data };
}
exports.sendOk = sendOk;
function sendError(data, error) {
return { ok: false, data: data, error: error };
return { ok: false, data, error };
}
exports.sendError = sendError;
//# sourceMappingURL=index.js.map
"use strict";
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.raw = exports.SQL = exports.SQLStatement = void 0;
var SQLStatement = (function () {
function SQLStatement(queryParts, values) {
var _a, _b;
class SQLStatement {
constructor(queryParts, values) {
this.queryParts = queryParts.slice(0);
this.values = [];
var index = 0;
var nestedIndex = 0;
let index = 0;
let nestedIndex = 0;
for (; index < values.length; index++, nestedIndex++) {
var statement = values[index];
const statement = values[index];
if (statement instanceof SQLStatement) {
if (statement.values.length > 0) {
var left = this.getLeftQueryPart(statement.queryParts, nestedIndex);
var middle = this.getMiddleQueryParts(statement.queryParts);
var right = this.getRightQueryPart(statement.queryParts, nestedIndex);
(_a = this.queryParts).splice.apply(_a, __spreadArrays([nestedIndex, 2, left], middle, [right]));
(_b = this.values).push.apply(_b, statement.values);
const left = this.getLeftQueryPart(statement.queryParts, nestedIndex);
const middle = this.getMiddleQueryParts(statement.queryParts);
const right = this.getRightQueryPart(statement.queryParts, nestedIndex);
this.queryParts.splice(nestedIndex, 2, left, ...middle, right);
this.values.push(...statement.values);
nestedIndex += middle.length;
}
else {
var fullQueryPart = this.queryParts[nestedIndex] +
const fullQueryPart = this.queryParts[nestedIndex] +
statement.queryParts[0] +

@@ -42,23 +34,19 @@ this.queryParts[nestedIndex + 1];

}
SQLStatement.prototype.getLeftQueryPart = function (queryParts, index) {
getLeftQueryPart(queryParts, index) {
return this.queryParts[index] + queryParts[0];
};
SQLStatement.prototype.getMiddleQueryParts = function (queryParts) {
}
getMiddleQueryParts(queryParts) {
return queryParts.slice(1, queryParts.length - 1);
};
SQLStatement.prototype.getRightQueryPart = function (queryParts, index) {
}
getRightQueryPart(queryParts, index) {
return queryParts[queryParts.length - 1] + this.queryParts[index + 1];
};
Object.defineProperty(SQLStatement.prototype, "text", {
get: function () {
return this.queryParts.reduce(function (prev, curr, index) { return prev + '$' + index + curr; });
},
enumerable: false,
configurable: true
});
SQLStatement.prototype.append = function (statement) {
}
get text() {
return this.queryParts.reduce((prev, curr, index) => prev + '$' + index + curr);
}
append(statement) {
if (statement instanceof SQLStatement) {
this.queryParts[this.queryParts.length - 1] += statement.queryParts[0];
this.queryParts.push.apply(this.queryParts, statement.queryParts.slice(1));
var values = this.values;
const values = this.values;
values.push.apply(this.values, statement.values);

@@ -70,15 +58,10 @@ }

return this;
};
SQLStatement.prototype.setName = function (name) {
}
setName(name) {
this.name = name;
return this;
};
return SQLStatement;
}());
}
}
exports.SQLStatement = SQLStatement;
exports.SQL = function (queryParts) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
exports.SQL = function (queryParts, ...args) {
return new SQLStatement(queryParts, args);

@@ -85,0 +68,0 @@ };

{
"name": "decentraland-server",
"version": "2.14.0",
"description": "Set of common functionality accross Decentraland projects servers.",
"version": "3.0.0",
"description": "Set of common functionality across Decentraland projects servers.",
"main": "./dist/index.js",

@@ -24,2 +24,5 @@ "typings": "./dist/index.d.ts",

},
"engines": {
"node": ">=12"
},
"files": [

@@ -42,14 +45,14 @@ "dist"

"dependencies": {
"@types/express": "^4.17.2",
"@types/inquirer": "^6.5.0",
"@types/pg": "^7.11.2",
"commander": "^7.1.0",
"inquirer": "^7.0.0",
"pg": "^7.12.1",
"rollbar": "^2.14.3"
"inquirer": "^8.1.5",
"pg": "^8.7.1",
"rollbar": "^2.24.0"
},
"devDependencies": {
"@types/chai": "^4.2.4",
"@types/express": "^4.17.13",
"@types/inquirer": "^8.1.3",
"@types/mocha": "^5.2.7",
"@types/node": "^12.12.39",
"@types/pg": "^8.6.1",
"chai": "^4.2.0",

@@ -56,0 +59,0 @@ "dcl-tslint-config-standard": "^2.0.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc