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

lambdaorm-base

Package Overview
Dependencies
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lambdaorm-base - npm Package Compare versions

Comparing version 0.1.18 to 0.1.19

204

dev/countries.js

@@ -14,146 +14,120 @@ "use strict";

const h3lp_1 = require("h3lp");
const typ3s_1 = require("typ3s");
const lib_1 = require("../lib");
(() => __awaiter(void 0, void 0, void 0, function* () {
// const data = [
// {
// name: 'Spain',
// region: { name: 'Europe', code: 'EU' },
// languages: [{ name: 'Spanish' }, { name: 'Catalan' }, { name: 'Galician' }, { name: 'Basque' }],
// priority: 1,
// phoneCode: 34,
// timezones: [
// { name: 'Madrid', offset: 1, pos: { lat: 40.4165, log: -3.70256 } },
// { name: 'Ceuta', pos: { lat: 35.8883, log: -5.3162 } },
// { name: 'Canary', offset: 0, pos: { lat: 28.1248, log: -15.43 } }
// ]
// },
// {
// name: 'France',
// region: { name: 'Europe', code: 'EU' },
// languages: [{ name: 'French' }],
// priority: 1,
// phoneCode: 33,
// timezones: [
// { name: 'Paris', offset: 1, pos: { lat: 48.8566, log: 2.3522 } },
// { name: 'Reunion', offset: 4, pos: { lat: -20.8823, log: 55.4504 } },
// { name: 'Guadeloupe', offset: -4, pos: { lat: 16.265, log: -61.551 } }
// ]
// },
// {
// name: 'Germany',
// languages: [{ name: 'German' }],
// region: { name: 'Europe', code: 'EU' },
// priority: 1,
// phoneCode: 49,
// timezones: [
// { name: 'Berlin', offset: 1, pos: { lat: 52.5200, log: 13.4050 } },
// { name: 'Busingen', offset: 1, pos: { lat: 47.6963, log: 8.6927 } }
// ]
// },
// {
// name: 'Portugal',
// languages: [{ name: 'Portuguese' }],
// region: { name: 'Europe', code: 'EU' },
// priority: 1,
// phoneCode: 351,
// timezones: [
// { name: 'Lisbon', offset: 0, pos: { lat: 38.7223, log: -9.1393 } },
// { name: 'Madeira', offset: 0, pos: { lat: 32.7607, log: -16.9595 } },
// { name: 'Azores', offset: -1, pos: { lat: 37.7412, log: -25.6756 } }
// ]
// },
// {
// name: 'United States',
// languages: [{ name: 'English' }],
// region: { name: 'North America', code: 'NA' },
// priority: 1,
// phoneCode: 1,
// timezones: [
// { name: 'New York', offset: -5, pos: { lat: 40.7128, log: -74.0060 } },
// { name: 'Los Angeles', offset: -8, pos: { lat: 34.0522, log: -118.2437 } },
// { name: 'Chicago', offset: -6, pos: { lat: 41.8781, log: -87.6298 } },
// { name: 'Denver', offset: -7, pos: { lat: 39.7392, log: -104.9903 } },
// { name: 'Anchorage', offset: -9, pos: { lat: 61.2181, log: -149.9003 } },
// { name: 'Honolulu', offset: -10, pos: { lat: 21.3069, log: -157.8583 } }
// ]
// },
// {
// name: 'Canada',
// languages: [{ name: 'English' }, { name: 'French' }],
// region: { name: 'North America', code: 'NA' },
// priority: 1,
// phoneCode: 2,
// timezones: [
// { name: 'Toronto', offset: -5, pos: { lat: 43.6532, log: -79.3832 } },
// { name: 'Vancouver', offset: -8, pos: { lat: 49.2827, log: -123.1207 } },
// { name: 'Edmonton', offset: -7, pos: { lat: 53.5461, log: -113.4938 } },
// { name: 'Winnipeg', offset: -6, pos: { lat: 49.8951, log: -97.1384 } },
// { name: 'Yellowknife', offset: -7, pos: { lat: 62.4540, log: -114.3718 } },
// { name: 'Iqaluit', offset: -5, pos: { lat: 63.7467, log: -68.5170 } }
// ]
// },
// {
// name: 'Brasil',
// languages: [{ name: 'Portuguese' }],
// region: { name: 'South America', code: 'SA' },
// priority: 1,
// phoneCode: 55,
// timezones: [
// { name: 'Sao Paulo', offset: -3, pos: { lat: -23.5505, log: -46.6333 } },
// { name: 'Rio de Janeiro', offset: -3, pos: { lat: -22.9068, log: -43.1729 } },
// { name: 'Manaus', offset: -4, pos: { lat: -3.1190, log: -60.0217 } },
// { name: 'Porto Alegre', offset: -3, pos: { lat: -30.0346, log: -51.2177 } },
// { name: 'Fortaleza', offset: -3, pos: { lat: -3.7319, log: -38.5267 } },
// { name: 'Belem', offset: -3, pos: { lat: -1.4558, log: -48.4902 } }
// ]
// },
// {
// name: 'Argentina',
// languages: [{ name: 'Spanish' }],
// region: { name: 'South America', code: 'SA' },
// priority: 1,
// phoneCode: 54,
// timezones: [{ name: 'Buenos Aires', offset: -3, pos: { lat: -34.6037, log: -58.3816 } }]
// }
// ]
const dataTemp = [
const array = [
{
name: 'Spain',
region: { name: 'Europe', code: 'EU' }
region: { name: 'Europe', code: 'EU' },
languages: [{ code: 'SP', name: 'Spanish' }, { code: 'CAT', name: 'Catalan' }, { code: 'GAL', name: 'Galician' }, { code: 'BSQ', name: 'Basque' }],
timezones: [
{ name: 'Madrid', offset: 1, pos: { lat: 40.4165, log: -3.70256 } },
{ name: 'Ceuta', pos: { lat: 35.8883, log: -5.3162 } },
{ name: 'Canary', offset: 0, pos: { lat: 28.1248, log: -15.43 } }
],
priority: 1,
phoneCode: 34
},
{
name: 'France',
region: { name: 'Europe', code: 'EU' }
region: { name: 'Europe', code: 'EU' },
languages: [{ code: 'FR', name: 'French' }],
timezones: [
{ name: 'Paris', offset: 1, pos: { lat: 48.8566, log: 2.3522 } },
{ name: 'Reunion', offset: 4, pos: { lat: -20.8823, log: 55.4504 } },
{ name: 'Guadeloupe', offset: -4, pos: { lat: 16.265, log: -61.551 } }
],
priority: 1,
phoneCode: 33
},
{
name: 'Germany',
region: { name: 'Europe', code: 'EU' }
region: { name: 'Europe', code: 'EU' },
languages: [{ code: 'GER', name: 'German' }],
timezones: [
{ name: 'Berlin', offset: 1, pos: { lat: 52.5200, log: 13.4050 } },
{ name: 'Busingen', offset: 1, pos: { lat: 47.6963, log: 8.6927 } }
],
priority: 1,
phoneCode: 49
},
{
name: 'Portugal',
region: { name: 'Europe', code: 'EU' }
region: { name: 'Europe', code: 'EU' },
languages: [{ code: 'PT', name: 'Portuguese' }],
timezones: [
{ name: 'Lisbon', offset: 0, pos: { lat: 38.7223, log: -9.1393 } },
{ name: 'Madeira', offset: 0, pos: { lat: 32.7607, log: -16.9595 } },
{ name: 'Azores', offset: -1, pos: { lat: 37.7412, log: -25.6756 } }
],
priority: 1,
phoneCode: 351
},
{
name: 'United States',
region: { name: 'North America', code: 'NA' }
region: { name: 'North America', code: 'NA' },
languages: [{ code: 'EN', name: 'English' }],
timezones: [
{ name: 'New York', offset: -5, pos: { lat: 40.7128, log: -74.0060 } },
{ name: 'Los Angeles', offset: -8, pos: { lat: 34.0522, log: -118.2437 } },
{ name: 'Chicago', offset: -6, pos: { lat: 41.8781, log: -87.6298 } },
{ name: 'Denver', offset: -7, pos: { lat: 39.7392, log: -104.9903 } },
{ name: 'Anchorage', offset: -9, pos: { lat: 61.2181, log: -149.9003 } },
{ name: 'Honolulu', offset: -10, pos: { lat: 21.3069, log: -157.8583 } }
],
priority: 1,
phoneCode: 1
},
{
name: 'Canada',
region: { name: 'North America', code: 'NA' }
region: { name: 'North America', code: 'NA' },
languages: [{ code: 'EN', name: 'English' }, { code: 'FR', name: 'French' }],
timezones: [
{ name: 'Toronto', offset: -5, pos: { lat: 43.6532, log: -79.3832 } },
{ name: 'Vancouver', offset: -8, pos: { lat: 49.2827, log: -123.1207 } },
{ name: 'Edmonton', offset: -7, pos: { lat: 53.5461, log: -113.4938 } },
{ name: 'Winnipeg', offset: -6, pos: { lat: 49.8951, log: -97.1384 } },
{ name: 'Yellowknife', offset: -7, pos: { lat: 62.4540, log: -114.3718 } },
{ name: 'Iqaluit', offset: -5, pos: { lat: 63.7467, log: -68.5170 } }
],
priority: 1,
phoneCode: 2
},
{
name: 'Brasil',
region: { name: 'South America', code: 'SA' }
region: { name: 'South America', code: 'SA' },
languages: [{ code: 'PT', name: 'Portuguese' }],
timezones: [
{ name: 'Sao Paulo', offset: -3, pos: { lat: -23.5505, log: -46.6333 } },
{ name: 'Rio de Janeiro', offset: -3, pos: { lat: -22.9068, log: -43.1729 } },
{ name: 'Manaus', offset: -4, pos: { lat: -3.1190, log: -60.0217 } },
{ name: 'Porto Alegre', offset: -3, pos: { lat: -30.0346, log: -51.2177 } },
{ name: 'Fortaleza', offset: -3, pos: { lat: -3.7319, log: -38.5267 } },
{ name: 'Belem', offset: -3, pos: { lat: -1.4558, log: -48.4902 } }
],
priority: 1,
phoneCode: 55
},
{
name: 'Argentina',
region: { name: 'South America', code: 'SA' }
region: { name: 'South America', code: 'SA' },
languages: [{ code: 'SP', name: 'Spanish' }],
timezones: [{ name: 'Buenos Aires', offset: -3, pos: { lat: -34.6037, log: -58.3816 } }],
priority: 1,
phoneCode: 54
}
];
const obj = {
languages: [{ code: 'SP', name: 'Spanish' }, { code: 'CAT', name: 'Catalan' }, { code: 'GAL', name: 'Galician' }, { code: 'BSQ', name: 'Basque' }],
timezones: [
{ name: 'Madrid', offset: 1, pos: { lat: 40.4165, log: -3.70256 } },
{ name: 'Ceuta', pos: { lat: 35.8883, log: -5.3162 } },
{ name: 'Canary', offset: 0, pos: { lat: 28.1248, log: -15.43 } }
]
};
const schemaFacade = new lib_1.SchemaFacadeBuilder(_3xpr_1.expressions, h3lp_1.h3lp).build();
const type = typ3s_1.Type.type(dataTemp, { info: true });
const schema = schemaFacade.create([{ name: 'Country', type }]);
console.log(JSON.stringify(schema, null, 2));
const schema = schemaFacade.create(array, 'Country');
console.log(JSON.stringify(schema.domain.entities, null, 2));
const schema2 = schemaFacade.create(obj);
console.log(JSON.stringify(schema2.domain.entities, null, 2));
}))();
//# sourceMappingURL=countries.js.map

@@ -33,3 +33,4 @@ import { ClauseInfo, SourceRule, Schema, EntityType } from '../domain';

getSource(clauseInfo: ClauseInfo, stage?: string): string;
create(types?: EntityType[]): Schema;
create(data: any): Schema;
create(data: any[], name: string): Schema;
update(schema: Schema, types: EntityType[]): void;

@@ -36,0 +37,0 @@ get(source: string): Promise<Schema | null>;

@@ -37,4 +37,4 @@ "use strict";

}
create(types) {
return this.createSchema.create(types);
create(data, name) {
return this.createSchema.create(data, name);
}

@@ -41,0 +41,0 @@ update(schema, types) {

@@ -14,3 +14,5 @@ import { AppPathsConfig, ApplicationSchema, InfrastructureSchema, DomainSchema, Schema, EntityType } from '../../domain';

private objTypeToEntities;
private getPk;
private getFk;
private getKey;
}

@@ -59,6 +59,6 @@ "use strict";

objTypeToEntities(name, objType) {
var _a;
var _a, _b;
const entities = [];
const key = this.getKey(objType);
const primaryKey = key ? [key.name] : [];
const pk = this.getPk(objType);
const primaryKey = pk ? [pk.name] : [];
const entity = { name, primaryKey, properties: [], uniqueKey: [], required: [], indexes: [], relations: [], dependents: [] };

@@ -69,7 +69,10 @@ for (const prop of objType.properties) {

entity.properties.push(property);
if (prop.type.unique && (pk === undefined || pk.name !== prop.name)) {
entity.uniqueKey.push(prop.name);
}
}
else if (prop.type && typ3s_1.Type.isObj(prop.type) && prop.type.obj) {
const fk = this.getKey(prop.type.obj);
const fk = this.getFk(prop.type.obj);
if (fk && fk.type) {
const propertyName = prop.name + fk.name;
const propertyName = prop.name + this.helper.str.capitalize(fk.name);
const entityName = this.helper.str.capitalize(prop.name);

@@ -79,3 +82,3 @@ const property = { name: propertyName, type: fk.type.primitive, required: (prop.type.nullable === false && prop.type.undefinable === false) };

name: prop.name,
type: domain_1.RelationType.oneToOne,
type: domain_1.RelationType.oneToMany,
from: propertyName,

@@ -88,2 +91,6 @@ entity: entityName,

const relatedEntities = this.typeToEntities(entityName, prop.type);
const relatedEntity = relatedEntities.find(p => p.name === entityName);
if (relatedEntity && relatedEntity.primaryKey.length === 0) {
relatedEntity.primaryKey = [fk.name];
}
if (relatedEntities && relatedEntities.length > 0) {

@@ -95,17 +102,54 @@ entities.push(...relatedEntities);

else if (prop.type && typ3s_1.Type.isList(prop.type) && ((_a = prop.type.list) === null || _a === void 0 ? void 0 : _a.items.obj)) {
const fk = this.getKey(prop.type.list.items.obj);
if (fk && fk.type) {
const propertyName = prop.name + fk.name;
if (pk && pk.type) {
const entityName = this.helper.str.capitalize(prop.name);
const property = { name: propertyName, type: fk.type.primitive, required: (prop.type.nullable === false && prop.type.undefinable === false) };
const relation = {
name: prop.name,
type: domain_1.RelationType.manyToOne,
from: propertyName,
entity: entityName,
to: fk.name
};
entity.properties.push(property);
entity.relations.push(relation);
const relatedEntities = this.typeToEntities(entityName, prop.type);
const relatedEntity = relatedEntities.find(p => p.name === entityName);
if (relatedEntity) {
if (prop.type && prop.type.repeatRate && prop.type.repeatRate > 0.02) {
const rpk = this.getFk((_b = prop.type.list) === null || _b === void 0 ? void 0 : _b.items.obj);
if (rpk && rpk.type) {
// hay que crear una tabla intermediaria con el id de la entidad y el id de la entidad relacionada
const parentPropertyName = this.helper.str.notation(entity.name, 'camel') + this.helper.str.capitalize(pk.name);
const parentProperty = { name: parentPropertyName, type: pk.type.primitive, required: true };
const childPropertyName = this.helper.str.singular(this.helper.str.notation(relatedEntity.name, 'camel')) + this.helper.str.capitalize(rpk.name);
const childProperty = { name: childPropertyName, type: rpk.type.primitive, required: true };
const intermediaEntityName = entity.name + this.helper.str.capitalize(prop.name);
const intermediaPropertyPk = { name: 'id', type: 'integer', required: true, autoIncrement: true };
const intermediaEntity = { intermediate: true, name: intermediaEntityName, primaryKey: ['id'], properties: [intermediaPropertyPk, childProperty, parentProperty], uniqueKey: [parentProperty.name, childProperty.name], required: [], indexes: [], relations: [], dependents: [] };
const parentRelation = {
name: this.helper.str.notation(entity.name, 'camel'),
type: domain_1.RelationType.oneToMany,
from: parentPropertyName,
entity: entity.name,
to: pk.name,
target: this.helper.str.notation(intermediaEntityName, 'camel')
};
const childRelation = {
name: this.helper.str.notation(relatedEntity.name, 'camel'),
type: domain_1.RelationType.oneToMany,
from: childPropertyName,
entity: relatedEntity.name,
to: rpk.name,
target: this.helper.str.notation(intermediaEntityName, 'camel')
};
intermediaEntity.relations.push(parentRelation);
intermediaEntity.relations.push(childRelation);
entities.push(intermediaEntity);
}
}
else {
const propertyName = this.helper.str.notation(entity.name, 'camel') + this.helper.str.capitalize(pk.name);
const relatedProperty = { name: propertyName, type: pk.type.primitive, required: true };
const relation = {
name: this.helper.str.notation(entity.name, 'camel'),
type: domain_1.RelationType.oneToMany,
from: propertyName,
entity: entity.name,
to: pk.name,
target: prop.name
};
relatedEntity.properties.push(relatedProperty);
relatedEntity.relations.push(relation);
}
}
if (relatedEntities && relatedEntities.length > 0) {

@@ -120,4 +164,12 @@ entities.push(...relatedEntities);

}
getKey(objType) {
getPk(objType) {
const uniques = objType.properties.filter(p => { var _a; return ((_a = p.type) === null || _a === void 0 ? void 0 : _a.unique) === true; });
return this.getKey(uniques);
}
getFk(objType) {
const uniques = objType.properties.filter(p => { var _a; return ((_a = p.type) === null || _a === void 0 ? void 0 : _a.onParentDistinctUnique) === true; });
const result = this.getKey(uniques);
return result;
}
getKey(uniques) {
if (uniques.length === 1) {

@@ -127,5 +179,7 @@ return uniques[0];

else if (uniques.length > 1) {
const id = uniques.find(p => ['id', 'name', 'code', 'key'].includes(p.name.toLowerCase()));
if (id) {
return id;
for (const keyName of ['id', 'code', 'key', 'name']) {
const id = uniques.find(p => p.name.toLowerCase() === keyName);
if (id) {
return id;
}
}

@@ -132,0 +186,0 @@ const idNumber = uniques.find(p => { var _a, _b; return ((_a = p.type) === null || _a === void 0 ? void 0 : _a.primitive) === 'number' || ((_b = p.type) === null || _b === void 0 ? void 0 : _b.primitive) === 'integer'; });

@@ -1,2 +0,2 @@

import { Schema, EntityType } from '../../domain';
import { Schema } from '../../domain';
import { SchemaService } from '../services/schemaService';

@@ -6,3 +6,5 @@ export declare class CreateSchema {

constructor(schemaService: SchemaService);
create(types?: EntityType[]): Schema;
create(data: any): Schema;
create(data: any[], name?: string): Schema;
private _create;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CreateSchema = void 0;
const typ3s_1 = require("typ3s");
class CreateSchema {

@@ -9,3 +10,23 @@ // eslint-disable-next-line no-useless-constructor

}
create(types) {
create(data, name) {
if (Array.isArray(data)) {
if (typeof name !== 'string') {
throw new Error('Argument name undefined');
}
const type = typ3s_1.Type.type(data, { info: true });
return this._create([{ name, type }]);
}
else if (typeof data === 'object') {
const types = [];
for (const key in data) {
const type = typ3s_1.Type.type(data[key], { info: true });
types.push({ name: key, type });
}
return this._create(types);
}
else {
throw new Error('Invalid data');
}
}
_create(types) {
const schema = this.schemaService.newSchema();

@@ -12,0 +33,0 @@ if (types && types.length > 0) {

@@ -79,2 +79,3 @@ import { Type } from 'typ3s';

composite?: boolean;
intermediate?: boolean;
}

@@ -81,0 +82,0 @@ export interface RelationInfo {

{
"name": "lambdaorm-base",
"version": "0.1.18",
"version": "0.1.19",
"description": "ORM",

@@ -24,5 +24,5 @@ "author": "Flavio Lionel Rita <flaviolrita@proton.me>",

"dependencies": {
"h3lp": "^1.5.8",
"typ3s": "^0.1.15",
"3xpr": "^1.15.9",
"h3lp": "^1.6.1",
"typ3s": "^0.1.16",
"3xpr": "^1.15.10",
"js-yaml": "^4.1.0",

@@ -29,0 +29,0 @@ "sqlstring": "^2.3.3"

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc