Socket
Socket
Sign inDemoInstall

cormo

Package Overview
Dependencies
32
Maintainers
4
Versions
169
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.14.1 to 0.14.2-alpha.1

lib/command/check-schemas.d.ts

15

lib/adapters/base.d.ts
import { Transaction } from '../transaction';
import * as types from '../types';
export interface ISchemasColumn {
required: boolean;
type: types.ColumnType | undefined;
}
export interface ISchemasTable {
[column_name: string]: ISchemasColumn;
}
export interface ISchemasIndex {
[index_name: string]: any;
}
export interface ISchemas {
tables: {
[table_name: string]: any;
[table_name: string]: ISchemasTable | 'NO SCHEMA';
};
indexes?: {
[table_name: string]: any;
[table_name: string]: ISchemasIndex;
};

@@ -9,0 +20,0 @@ foreign_keys?: {

@@ -760,2 +760,5 @@ "use strict";

for (const row of rows) {
if (row.name === '_id_') {
continue;
}
indexes[row.name] = row.key;

@@ -762,0 +765,0 @@ }

@@ -728,2 +728,5 @@ "use strict";

for (const row of rows) {
if (row.INDEX_NAME === 'id' || row.INDEX_NAME === 'PRIMARY') {
continue;
}
const indexes_of_table = indexes[row.TABLE_NAME] || (indexes[row.TABLE_NAME] = {});

@@ -730,0 +733,0 @@ (indexes_of_table[row.INDEX_NAME] || (indexes_of_table[row.INDEX_NAME] = {}))[row.COLUMN_NAME] = 1;

@@ -591,2 +591,5 @@ "use strict";

for (const row of result.rows) {
if (row.index_name === `${row.table_name}_pkey`) {
continue;
}
const indexes_of_table = indexes[row.table_name] || (indexes[row.table_name] = {});

@@ -593,0 +596,0 @@ (indexes_of_table[row.index_name] || (indexes_of_table[row.index_name] = {}))[row.column_name] = 1;

2

lib/command/index.d.ts

@@ -9,4 +9,4 @@ /**

*/
static run(argv: string[]): any;
static run(argv: string[]): Promise<any>;
}
export { Command };

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

*/
static run(argv) {
static async run(argv) {
const command = argv[2];

@@ -24,5 +24,5 @@ if (!command) {

// eslint-disable-next-line @typescript-eslint/no-var-requires
const CommandClass = require(path_1.default.resolve(__dirname, '..', 'command', command));
const runner = new CommandClass(argv);
return runner.run();
const CommandClass = require(path_1.default.resolve(__dirname, command)).default;
const runner = new CommandClass(argv.slice(3));
return await runner.run();
}

@@ -29,0 +29,0 @@ catch (error) {

@@ -51,2 +51,6 @@ /// <reference types="node" />

}
export interface ISchemaChange {
message: string;
ignorable?: boolean;
}
interface IAssociation {

@@ -141,2 +145,7 @@ type: 'hasMany' | 'hasOne' | 'belongsTo';

/**
* Returns changes of schama
* @see AdapterBase::applySchema
*/
getSchemaChanges(): Promise<ISchemaChange[]>;
/**
* Drops all model tables

@@ -143,0 +152,0 @@ */

@@ -127,2 +127,3 @@ "use strict";

this._promise_schema_applied = this._promise_connection.then(async () => {
var _a, _b;
try {

@@ -158,4 +159,3 @@ const current = await this._adapter.getSchemas();

for (const index of modelClass._indexes) {
if (!(current.indexes && current.indexes[modelClass.table_name]
&& current.indexes[modelClass.table_name][index.options.name])) {
if (!((_b = (_a = current.indexes) === null || _a === void 0 ? void 0 : _a[modelClass.table_name]) === null || _b === void 0 ? void 0 : _b[index.options.name])) {
if (options.verbose) {

@@ -207,9 +207,16 @@ console.log(`Creating index on ${modelClass.table_name} ${Object.keys(index.columns)}`);

async isApplyingSchemasNecessary() {
const changes = await this.getSchemaChanges();
return lodash_1.default.some(changes, (change) => change.ignorable !== true);
}
/**
* Returns changes of schama
* @see AdapterBase::applySchema
*/
async getSchemaChanges() {
var _a, _b, _c;
this._initializeModels();
if (!this._schema_changed) {
return false;
}
this.applyAssociations();
this._checkArchive();
await this._promise_connection;
const changes = [];
const current = await this._adapter.getSchemas();

@@ -225,5 +232,18 @@ for (const model in this.models) {

if (!currentTable[property._dbname_us]) {
return true;
changes.push({ message: `Add column ${column} to ${modelClass.table_name}` });
}
else if (column !== 'id') {
if (property.required && !currentTable[property._dbname_us].required) {
changes.push({ message: `Change ${modelClass.table_name}.${column} to required`, ignorable: true });
}
else if (!property.required && currentTable[property._dbname_us].required) {
changes.push({ message: `Change ${modelClass.table_name}.${column} to optional`, ignorable: true });
}
}
}
for (const column in currentTable) {
if (!lodash_1.default.find(modelClass._schema, { _dbname_us: column })) {
changes.push({ message: `Remove column ${column} from ${modelClass.table_name}`, ignorable: true });
}
}
}

@@ -233,13 +253,22 @@ for (const model in this.models) {

if (!current.tables[modelClass.table_name]) {
return true;
changes.push({ message: `Add table ${modelClass.table_name}` });
}
}
for (const model in this.models) {
const modelClass = this.models[model];
for (const table_name in current.tables) {
if (!lodash_1.default.find(this.models, { table_name })) {
changes.push({ message: `Remove table ${table_name}`, ignorable: true });
}
}
for (const model_name in this.models) {
const modelClass = this.models[model_name];
for (const index of modelClass._indexes) {
if (!(current.indexes && current.indexes[modelClass.table_name]
&& current.indexes[modelClass.table_name][index.options.name])) {
return true;
if (!((_b = (_a = current.indexes) === null || _a === void 0 ? void 0 : _a[modelClass.table_name]) === null || _b === void 0 ? void 0 : _b[index.options.name])) {
changes.push({ message: `Add index on ${modelClass.table_name} ${Object.keys(index.columns)}` });
}
}
for (const index in (_c = current.indexes) === null || _c === void 0 ? void 0 : _c[modelClass.table_name]) {
if (!lodash_1.default.find(modelClass._indexes, (item) => item.options.name === index)) {
changes.push({ message: `Remove index on ${modelClass.table_name} ${index}`, ignorable: true });
}
}
}

@@ -263,3 +292,5 @@ for (const model in this.models) {

if (!(current_foreign_key && current_foreign_key === integrity.parent.table_name)) {
return true;
const table_name = modelClass.table_name;
const parent_table_name = integrity.parent.table_name;
changes.push({ message: `Add foreign key ${table_name}.${integrity.column} to ${parent_table_name}` });
}

@@ -269,3 +300,3 @@ }

}
return false;
return changes;
}

@@ -272,0 +303,0 @@ /**

{
"name": "cormo",
"description": "ORM framework for Node.js",
"version": "0.14.1",
"version": "0.14.2-alpha.1",
"keywords": [

@@ -39,9 +39,9 @@ "orm",

"chalk": "^3.0.0",
"commander": "^4.1.1",
"inflected": "^2.0.4",
"lodash": "^4.17.15",
"toposort-class": "^1.0.1"
"toposort-class": "^1.0.1",
"yargs": "^15.3.1"
},
"devDependencies": {
"@types/chai": "^4.2.10",
"@types/chai": "^4.2.11",
"@types/inflected": "^1.1.29",

@@ -51,4 +51,5 @@ "@types/lodash": "^4.14.149",

"@types/mongodb": "^3.5.2",
"@types/node": "^13.9.0",
"@types/node": "^13.9.3",
"@types/sinon": "^7.5.2",
"@types/yargs": "^15.0.4",
"benchmark": "^2.1.4",

@@ -60,3 +61,3 @@ "chai": "^4.2.0",

"microtime": "^3.0.0",
"mocha": "^7.1.0",
"mocha": "^7.1.1",
"mongodb": "^3.5.5",

@@ -70,6 +71,5 @@ "mysql": "^2.18.1",

"sqlite3": "^4.1.1",
"ts-node": "^8.6.2",
"ts-node": "^8.8.1",
"typescript": "^3.8.3"
},
"gitHead": "69fb9968c40508d9864694352ae8620b26eb296c"
}
}

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