lambdaorm-base
Advanced tools
Comparing version 0.1.20 to 0.1.21
{ | ||
"name": "lambdaorm-base", | ||
"version": "0.1.20", | ||
"version": "0.1.21", | ||
"description": "ORM", | ||
@@ -5,0 +5,0 @@ "author": "Flavio Lionel Rita <flaviolrita@proton.me>", |
@@ -14,2 +14,3 @@ import { AppPathsConfig, ApplicationSchema, InfrastructureSchema, DomainSchema, Schema, EntityType } from '../../domain'; | ||
private objTypeToEntities; | ||
private getLength; | ||
private getPk; | ||
@@ -16,0 +17,0 @@ private getFk; |
@@ -66,3 +66,6 @@ "use strict"; | ||
if (prop.type && typ3s_1.Type.isPrimitive(prop.type)) { | ||
const property = { name: prop.name, type: prop.type.primitive, required: (prop.type.nullable === false && prop.type.undefinable === false) }; | ||
const required = (prop.type.nullable === false && prop.type.undefinable === false); | ||
const length = this.getLength(prop.type); | ||
const type = prop.type.primitive === 'string' && length === undefined ? 'text' : prop.type.primitive; | ||
const property = { name: prop.name, type, required, length }; | ||
entity.properties.push(property); | ||
@@ -78,3 +81,6 @@ if (prop.type.unique && (pk === undefined || pk.name !== prop.name)) { | ||
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 required = (prop.type.nullable === false && prop.type.undefinable === false); | ||
const length = this.getLength(fk.type); | ||
const type = fk.type.primitive === 'string' && length === undefined ? 'text' : fk.type.primitive; | ||
const property = { name: propertyName, type, required, length }; | ||
const relation = { | ||
@@ -161,2 +167,47 @@ name: prop.name, | ||
} | ||
getLength(type) { | ||
if (type.primitive !== 'string') { | ||
return undefined; | ||
} | ||
if (!type.maxLen) { | ||
return 80; | ||
} | ||
if (type.maxLen < 8) { | ||
if (type.maxLen === type.minLen) { | ||
return type.maxLen; | ||
} | ||
return Math.round(type.maxLen * 1.3); | ||
} | ||
const length = Math.round(type.maxLen * 1.3); | ||
if (length < 16) { | ||
return 16; | ||
} | ||
else if (length < 32) { | ||
return 32; | ||
} | ||
else if (length < 64) { | ||
return 64; | ||
} | ||
else if (length < 128) { | ||
return 128; | ||
} | ||
else if (length < 256) { | ||
return 256; | ||
} | ||
else if (length < 512) { | ||
return 512; | ||
} | ||
else if (length < 1024) { | ||
return 1024; | ||
} | ||
else if (length < 2048) { | ||
return 2048; | ||
} | ||
else if (length < 4096) { | ||
return 4096; | ||
} | ||
else { | ||
return undefined; | ||
} | ||
} | ||
getPk(objType) { | ||
@@ -163,0 +214,0 @@ const uniques = objType.properties.filter(p => { var _a; return ((_a = p.type) === null || _a === void 0 ? void 0 : _a.unique) === true; }); |
@@ -15,3 +15,3 @@ "use strict"; | ||
} | ||
const type = typ3s_1.Type.type(data, { info: true }); | ||
const type = typ3s_1.Type.type(data, { info: true, describe: true }); | ||
return this._create([{ name, type }]); | ||
@@ -22,3 +22,3 @@ } | ||
for (const key in data) { | ||
const type = typ3s_1.Type.type(data[key], { info: true }); | ||
const type = typ3s_1.Type.type(data[key], { info: true, describe: true }); | ||
types.push({ name: key, type }); | ||
@@ -25,0 +25,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
222743
3553
0