@sqb/connect
Advanced tools
Comparing version 4.0.1-beta.17 to 4.0.1-beta.18
import { Type } from '../../types'; | ||
export declare function mixinEntities<A, B>(derived: Type, classARef: Type<A>, classBRef: Type<B>): Type<A & B>; | ||
export declare function pickCloneEntity<T, K extends keyof T>(derived: Type, classRef: Type<T>, keys: readonly K[]): Type<Pick<T, typeof keys[number]>>; | ||
export declare function omitCloneEntity<T, K extends keyof T>(derived: Type, classRef: Type<T>, keys: readonly K[]): Type<Omit<T, typeof keys[number]>>; | ||
export declare function UnionEntity<A, B>(classARef: Type<A>, classBRef: Type<B>): Type<A & B>; | ||
export declare function PickEntity<T, K extends keyof T>(classRef: Type<T>, keys: readonly K[]): Type<Pick<T, typeof keys[number]>>; | ||
export declare function OmitEntity<T, K extends keyof T>(classRef: Type<T>, keys: readonly K[]): Type<Pick<T, typeof keys[number]>>; | ||
export declare function OmitEntity<T, K extends keyof T>(classRef: Type<T>, keys: readonly K[]): Type<Omit<T, typeof keys[number]>>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.OmitEntity = exports.PickEntity = exports.UnionEntity = void 0; | ||
exports.OmitEntity = exports.PickEntity = exports.UnionEntity = exports.omitCloneEntity = exports.pickCloneEntity = exports.mixinEntities = void 0; | ||
const entity_model_1 = require("../model/entity-model"); | ||
const association_1 = require("../model/association"); | ||
const index_meta_1 = require("../model/index-meta"); | ||
function UnionEntity(classARef, classBRef) { | ||
class UnionEntityClass { | ||
constructor(...args) { | ||
inheritPropertyInitializers(this, classARef, args); | ||
inheritPropertyInitializers(this, classBRef, args); | ||
} | ||
} | ||
function mixinEntities(derived, classARef, classBRef) { | ||
const aModel = entity_model_1.EntityModel.get(classARef); | ||
const bModel = entity_model_1.EntityModel.get(classBRef); | ||
const entity = entity_model_1.EntityModel.attachTo(UnionEntityClass); | ||
const entity = entity_model_1.EntityModel.attachTo(derived); | ||
for (const fk of [...aModel.foreignKeys, ...bModel.foreignKeys]) { | ||
const newFk = new association_1.Association(fk.name, Object.assign(Object.assign({}, fk), { source: UnionEntityClass })); | ||
const newFk = new association_1.Association(fk.name, Object.assign(Object.assign({}, fk), { source: derived })); | ||
entity.foreignKeys.push(newFk); | ||
@@ -29,17 +23,12 @@ } | ||
bModel.properties.forEach((p, n) => entity.properties.set(n, p)); | ||
return UnionEntityClass; | ||
return derived; | ||
} | ||
exports.UnionEntity = UnionEntity; | ||
function PickEntity(classRef, keys) { | ||
class PickEntityClass { | ||
constructor(...args) { | ||
inheritPropertyInitializers(this, classRef, args); | ||
} | ||
} | ||
exports.mixinEntities = mixinEntities; | ||
function pickCloneEntity(derived, classRef, keys) { | ||
const srcModel = entity_model_1.EntityModel.get(classRef); | ||
const entity = entity_model_1.EntityModel.attachTo(PickEntityClass); | ||
const entity = entity_model_1.EntityModel.attachTo(derived); | ||
const pickKeys = keys; | ||
for (const fk of srcModel.foreignKeys) { | ||
if (fk.sourceKey && pickKeys.includes(fk.sourceKey)) { | ||
const newFk = new association_1.Association(fk.name, Object.assign(Object.assign({}, fk), { source: PickEntityClass })); | ||
const newFk = new association_1.Association(fk.name, Object.assign(Object.assign({}, fk), { source: derived })); | ||
entity.foreignKeys.push(newFk); | ||
@@ -59,17 +48,12 @@ } | ||
}); | ||
return PickEntityClass; | ||
return derived; | ||
} | ||
exports.PickEntity = PickEntity; | ||
function OmitEntity(classRef, keys) { | ||
class PickEntityClass { | ||
constructor(...args) { | ||
inheritPropertyInitializers(this, classRef, args); | ||
} | ||
} | ||
exports.pickCloneEntity = pickCloneEntity; | ||
function omitCloneEntity(derived, classRef, keys) { | ||
const srcModel = entity_model_1.EntityModel.get(classRef); | ||
const entity = entity_model_1.EntityModel.attachTo(PickEntityClass); | ||
const entity = entity_model_1.EntityModel.attachTo(derived); | ||
const omitKeys = keys; | ||
for (const fk of srcModel.foreignKeys) { | ||
if (!(fk.sourceKey && omitKeys.includes(fk.sourceKey))) { | ||
const newFk = new association_1.Association(fk.name, Object.assign(Object.assign({}, fk), { source: PickEntityClass })); | ||
const newFk = new association_1.Association(fk.name, Object.assign(Object.assign({}, fk), { source: derived })); | ||
entity.foreignKeys.push(newFk); | ||
@@ -89,4 +73,32 @@ } | ||
}); | ||
return PickEntityClass; | ||
return derived; | ||
} | ||
exports.omitCloneEntity = omitCloneEntity; | ||
function UnionEntity(classARef, classBRef) { | ||
class UnionEntityClass { | ||
constructor(...args) { | ||
inheritPropertyInitializers(this, classARef, args); | ||
inheritPropertyInitializers(this, classBRef, args); | ||
} | ||
} | ||
return mixinEntities(UnionEntityClass, classARef, classBRef); | ||
} | ||
exports.UnionEntity = UnionEntity; | ||
function PickEntity(classRef, keys) { | ||
class PickEntityClass { | ||
constructor(...args) { | ||
inheritPropertyInitializers(this, classRef, args); | ||
} | ||
} | ||
return pickCloneEntity(PickEntityClass, classRef, keys); | ||
} | ||
exports.PickEntity = PickEntity; | ||
function OmitEntity(classRef, keys) { | ||
class OmitEntityClass { | ||
constructor(...args) { | ||
inheritPropertyInitializers(this, classRef, args); | ||
} | ||
} | ||
return omitCloneEntity(OmitEntityClass, classRef, keys); | ||
} | ||
exports.OmitEntity = OmitEntity; | ||
@@ -93,0 +105,0 @@ function inheritPropertyInitializers(target, sourceClass, constructorArgs, isPropertyInherited) { |
{ | ||
"name": "@sqb/connect", | ||
"description": "Multi-dialect database connection framework written with TypeScript", | ||
"version": "4.0.1-beta.17", | ||
"version": "4.0.1-beta.18", | ||
"author": "Panates Ltd.", | ||
@@ -47,3 +47,3 @@ "contributors": [ | ||
"peerDependencies": { | ||
"@sqb/builder": "^4.0.1-beta.17" | ||
"@sqb/builder": "^4.0.1-beta.18" | ||
}, | ||
@@ -50,0 +50,0 @@ "main": "dist/index.js", |
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
196670
4844