Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nyffels/mynodeorm

Package Overview
Dependencies
Maintainers
0
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nyffels/mynodeorm - npm Package Compare versions

Comparing version 1.0.0-alpha73 to 1.0.0-alpha74

dist/models/schema.models.d.ts

55

dist/app.js

@@ -33,2 +33,4 @@ #! /usr/bin/env node

const fs = __importStar(require("node:fs"));
const decorators_1 = require("./decorators");
const fs_1 = require("fs");
const args = process.argv.slice(2);

@@ -39,3 +41,3 @@ let workdir = process.cwd();

}
console.log(`Working from ${workdir}.`);
console.log(`• Working from ${workdir}.`);
if (args.includes("--create-config-mysql")) {

@@ -52,3 +54,3 @@ const fileLocationRaw = args.find(a => a.includes('--location='));

if (fs.existsSync(fullPathWithFile)) {
console.log(`MySql config file already exists. Delete existing one...`);
console.log(`• MySql config file already exists. Delete existing one...`);
fs.unlinkSync(fullPathWithFile);

@@ -66,17 +68,17 @@ }

fs.writeFileSync(fullPathWithFile, JSON.stringify(config), { encoding: "utf8" });
console.log("MySQL config file created and saved at " + fullPathWithFile + ".");
const schemaScriptPath = node_path_1.default.join(fullPath, "mynodeorm-migration-config.js");
console.log("• MySQL config file created and saved at " + fullPathWithFile + ".");
const schemaScriptPath = node_path_1.default.join(fullPath, "mynodeorm-migration-config.ts");
if (fs.existsSync(schemaScriptPath)) {
console.log(`Schema config file already exists. Delete existing one...`);
console.log(`• Schema config file already exists. Delete existing one...`);
fs.unlinkSync(schemaScriptPath);
}
let migrationsScript = `
const dbClasses = [];
export const dbClasses = [];
`;
fs.writeFileSync(schemaScriptPath, migrationsScript, { encoding: "utf8" });
console.log("Schema config file created and saved at " + fullPathWithFile + ".");
console.log("• Schema config file created and saved at " + fullPathWithFile + ".");
}
else if (args.includes("--migration")) {
if (!args.some(e => /^--name=*./.test(e))) {
throw Error("Name is required for a migration. Use '--name={{name}}' to declare a name of this migration.");
throw Error("• Name is required for a migration. Use '--name={{name}}' to declare a name of this migration.");
}

@@ -87,5 +89,5 @@ const name = (_p = (_o = args.find((a) => a.includes('--name='))) === null || _o === void 0 ? void 0 : _o.replace('--name=', '')) !== null && _p !== void 0 ? _p : "";

const configurationLocationPath = (_t = (_s = args.find((a) => a.includes('--config-location='))) === null || _s === void 0 ? void 0 : _s.replace('--config-location=', '')) !== null && _t !== void 0 ? _t : "./";
const configurationLocation = node_path_1.default.join(process.cwd(), configurationLocationPath, "mynodeorm-migration-config.js");
const configurationLocation = node_path_1.default.join(process.cwd(), configurationLocationPath, "mynodeorm-migration-config.ts");
if (!fs.existsSync(configurationLocation)) {
console.log(`Configuration not found on location ${configurationLocation}`);
console.log(`• Configuration not found on location ${configurationLocation}`);
process.exit(1);

@@ -96,3 +98,3 @@ }

firstMigration = true;
console.log("Migration location does not exists... Creating folder.");
console.log("• Migration location does not exists... Creating folder.");
fs.mkdirSync(migrationLocation, { recursive: true });

@@ -103,6 +105,33 @@ }

const dbClasses = require(configurationLocation).dbClasses;
console.log(dbClasses);
console.log("• Creating schema...");
const schema = {};
for (const dbClass of dbClasses) {
const table = (0, decorators_1.getTable)(dbClass);
if (!table) {
continue;
}
schema[table] = {
columns: {}
};
const properties = (0, decorators_1.getAllProperties)(dbClass);
for (let property of properties) {
const columnname = (0, decorators_1.getColumn)(dbClass, property);
schema[table].columns[columnname] = {
type: "", // TODO
primary: false, // TODO
nullable: false, // TODO
unique: false, // TODO
unsigned: false, // TODO
autoIncrement: false, // TODO
defaultSql: null, // TODO
foreignKey: null // TODO
};
}
}
console.log("• Schema created.");
(0, fs_1.mkdirSync)(node_path_1.default.join(migrationLocation, migrationName), { recursive: true });
fs.writeFileSync(node_path_1.default.join(migrationLocation, migrationName, "schema.json"), JSON.stringify(schema));
}
else {
console.log("No valid action found!");
console.log("• No valid action found!");
}

@@ -109,0 +138,0 @@ function getDateFormat() {

@@ -7,3 +7,3 @@ import 'reflect-metadata';

};
export declare function type(type: propertyType): {
export declare function type(type: propertyType, length?: string | null): {
(target: Function): void;

@@ -16,3 +16,3 @@ (target: Object, propertyKey: string | symbol): void;

};
export declare function nullable(isNullable: boolean): {
export declare function nullable(isNullable?: boolean): {
(target: Function): void;

@@ -41,2 +41,5 @@ (target: Object, propertyKey: string | symbol): void;

};
/**
* Options for a foreign key connection
*/
export declare enum ForeignKeyOption {

@@ -60,2 +63,8 @@ Restrict = 0,

export declare function getType<T>(sourceObject: Object, propertyKey: keyof T): propertyType;
export declare function getPrimary<T>(sourceObject: Object, propertyKey: keyof T): boolean;
export declare function getNullable<T>(sourceObject: Object, propertyKey: keyof T): boolean;
export declare function getUnique<T>(sourceObject: Object, propertyKey: keyof T): boolean;
export declare function getUnsigned<T>(sourceObject: Object, propertyKey: keyof T): boolean;
export declare function getAutoIncrement<T>(sourceObject: Object, propertyKey: keyof T): boolean;
export declare function getDefaultSql<T>(sourceObject: Object, propertyKey: keyof T): boolean;
//# sourceMappingURL=property.decorator.d.ts.map

@@ -16,2 +16,8 @@ "use strict";

exports.getType = getType;
exports.getPrimary = getPrimary;
exports.getNullable = getNullable;
exports.getUnique = getUnique;
exports.getUnsigned = getUnsigned;
exports.getAutoIncrement = getAutoIncrement;
exports.getDefaultSql = getDefaultSql;
require("reflect-metadata");

@@ -24,3 +30,2 @@ const factory_models_1 = require("../models/factory.models");

const uniqueMetaDatakey = Symbol('unique');
const indexMetaDatakey = Symbol('index');
const unsignedMetaDatakey = Symbol('unsigned');

@@ -33,4 +38,4 @@ const autoIncrementMetaDatakey = Symbol('autoIncrement');

}
function type(type) {
return Reflect.metadata(typeMetaDatakey, type);
function type(type, length = null) {
return Reflect.metadata(typeMetaDatakey, JSON.stringify({ type, length }));
}

@@ -40,3 +45,3 @@ function primary() {

}
function nullable(isNullable) {
function nullable(isNullable = true) {
return Reflect.metadata(nullableMetaDatakey, isNullable);

@@ -59,2 +64,5 @@ }

}
/**
* Options for a foreign key connection
*/
var ForeignKeyOption;

@@ -95,3 +103,4 @@ (function (ForeignKeyOption) {

const targetClass = factory.create(sourceObject);
return Reflect.getMetadata(typeMetaDatakey, targetClass, propertyKey);
const stringifiedValue = Reflect.getMetadata(typeMetaDatakey, targetClass, propertyKey);
return JSON.parse(stringifiedValue).type;
}

@@ -102,2 +111,62 @@ catch (ex) {

}
function getPrimary(sourceObject, propertyKey) {
try {
const factory = new factory_models_1.Factory();
const targetClass = factory.create(sourceObject);
return Reflect.getMetadata(primaryMetaDatakey, targetClass, propertyKey).toLowerCase() == "true";
}
catch (ex) {
return false;
}
}
function getNullable(sourceObject, propertyKey) {
try {
const factory = new factory_models_1.Factory();
const targetClass = factory.create(sourceObject);
return Reflect.getMetadata(nullableMetaDatakey, targetClass, propertyKey).toLowerCase() == "true";
}
catch (ex) {
return true;
}
}
function getUnique(sourceObject, propertyKey) {
try {
const factory = new factory_models_1.Factory();
const targetClass = factory.create(sourceObject);
return Reflect.getMetadata(uniqueMetaDatakey, targetClass, propertyKey).toLowerCase() == "true";
}
catch (ex) {
return true;
}
}
function getUnsigned(sourceObject, propertyKey) {
try {
const factory = new factory_models_1.Factory();
const targetClass = factory.create(sourceObject);
return Reflect.getMetadata(unsignedMetaDatakey, targetClass, propertyKey).toLowerCase() == "true";
}
catch (ex) {
return true;
}
}
function getAutoIncrement(sourceObject, propertyKey) {
try {
const factory = new factory_models_1.Factory();
const targetClass = factory.create(sourceObject);
return Reflect.getMetadata(autoIncrementMetaDatakey, targetClass, propertyKey).toLowerCase() == "true";
}
catch (ex) {
return true;
}
}
function getDefaultSql(sourceObject, propertyKey) {
try {
const factory = new factory_models_1.Factory();
const targetClass = factory.create(sourceObject);
return Reflect.getMetadata(defaultMetaDatakey, targetClass, propertyKey);
}
catch (ex) {
return true;
}
}
//# sourceMappingURL=property.decorator.js.map
{
"name": "@nyffels/mynodeorm",
"version": "1.0.0-alpha73",
"version": "1.0.0-alpha74",
"description": "A full-fledged ORM framework for NodeJS and MySQL with develop friendly code aimed to handle database migrations, MySQL Query builder / helper and property mapping.",

@@ -5,0 +5,0 @@ "private": false,

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc