@sqb/connect
Advanced tools
Comparing version 4.0.1-beta.24 to 4.0.1-beta.25
import { Pool as LightningPool } from 'lightning-pool'; | ||
import { classes } from '@sqb/builder'; | ||
import StrictEventEmitter from 'strict-event-emitter-types'; | ||
import { ClientConfiguration, QueryExecuteOptions, TransactionFunction, QueryResult, ClientDefaults, ConnectionOptions, QueryRequest } from './types'; | ||
@@ -10,3 +11,13 @@ import { SqbConnection } from './SqbConnection'; | ||
declare const inspect: unique symbol; | ||
export declare class SqbClient extends SafeEventEmitter { | ||
interface Events { | ||
execute: (request: QueryRequest, connection: SqbConnection) => void; | ||
error: (error: Error, connection: SqbConnection) => void; | ||
closing: () => void; | ||
close: () => void; | ||
acquire: (connection: SqbConnection) => void; | ||
terminate: () => void; | ||
} | ||
declare type SqbClientEmitter = StrictEventEmitter<SafeEventEmitter, Events>; | ||
declare const SqbClient_base: Type<SqbClientEmitter>; | ||
export declare class SqbClient extends SqbClient_base { | ||
private readonly _adapter; | ||
@@ -57,87 +68,3 @@ private readonly _pool; | ||
[inspect](): string; | ||
addListener(event: 'execute', listener: (request: QueryRequest, connection: SqbConnection) => void): this; | ||
addListener(event: 'error', listener: (error: Error, connection: SqbConnection) => void): this; | ||
addListener(event: 'error', listener: (error: Error) => void): this; | ||
addListener(event: 'closing', listener: () => void): this; | ||
addListener(event: 'close', listener: () => void): this; | ||
addListener(event: 'acquire', listener: (connection: SqbConnection) => void): this; | ||
addListener(event: 'terminate', listener: () => void): this; | ||
removeListener(event: 'execute', listener: (request: QueryRequest, connection: SqbConnection) => void): this; | ||
removeListener(event: 'error', listener: (error: Error, connection: SqbConnection) => void): this; | ||
removeListener(event: 'error', listener: (error: Error) => void): this; | ||
removeListener(event: 'closing', listener: () => void): this; | ||
removeListener(event: 'close', listener: () => void): this; | ||
removeListener(event: 'acquire', listener: (connection: SqbConnection) => void): this; | ||
removeListener(event: 'terminate', listener: () => void): this; | ||
emit(event: 'execute', request: QueryRequest, connection: SqbConnection): boolean; | ||
emit(event: 'error', error: Error, connection: SqbConnection): boolean; | ||
emit(event: 'error', error: Error): boolean; | ||
emit(event: 'closing'): boolean; | ||
emit(event: 'close'): boolean; | ||
emit(event: 'acquire', connection: SqbConnection): boolean; | ||
emit(event: 'terminate'): boolean; | ||
on(event: 'execute', listener: (request: QueryRequest, connection: SqbConnection) => void): this; | ||
on(event: 'error', listener: (error: Error, connection: SqbConnection) => void): this; | ||
on(event: 'error', listener: (error: Error) => void): this; | ||
on(event: 'closing', listener: () => void): this; | ||
on(event: 'close', listener: () => void): this; | ||
on(event: 'acquire', listener: (connection: SqbConnection) => void): this; | ||
on(event: 'terminate', listener: () => void): this; | ||
once(event: 'execute', listener: (request: QueryRequest, connection: SqbConnection) => void): this; | ||
once(event: 'error', listener: (error: Error, connection: SqbConnection) => void): this; | ||
once(event: 'error', listener: (error: Error) => void): this; | ||
once(event: 'closing', listener: () => void): this; | ||
once(event: 'close', listener: () => void): this; | ||
once(event: 'acquire', listener: (connection: SqbConnection) => void): this; | ||
once(event: 'terminate', listener: () => void): this; | ||
off(event: 'execute', listener: (request: QueryRequest, connection: SqbConnection) => void): this; | ||
off(event: 'error', listener: (error: Error, connection: SqbConnection) => void): this; | ||
off(event: 'error', listener: (error: Error) => void): this; | ||
off(event: 'closing', listener: () => void): this; | ||
off(event: 'close', listener: () => void): this; | ||
off(event: 'acquire', listener: (connection: SqbConnection) => void): this; | ||
off(event: 'terminate', listener: () => void): this; | ||
removeAllListeners(event: 'execute'): this; | ||
removeAllListeners(event: 'error'): this; | ||
removeAllListeners(event: 'error'): this; | ||
removeAllListeners(event: 'closing'): this; | ||
removeAllListeners(event: 'close'): this; | ||
removeAllListeners(event: 'acquire'): this; | ||
removeAllListeners(event: 'terminate'): this; | ||
listeners(event: 'execute'): Function[]; | ||
listeners(event: 'error'): Function[]; | ||
listeners(event: 'error'): Function[]; | ||
listeners(event: 'closing'): Function[]; | ||
listeners(event: 'close'): Function[]; | ||
listeners(event: 'acquire'): Function[]; | ||
listeners(event: 'terminate'): Function[]; | ||
rawListeners(event: 'execute'): Function[]; | ||
rawListeners(event: 'error'): Function[]; | ||
rawListeners(event: 'error'): Function[]; | ||
rawListeners(event: 'closing'): Function[]; | ||
rawListeners(event: 'close'): Function[]; | ||
rawListeners(event: 'acquire'): Function[]; | ||
rawListeners(event: 'terminate'): Function[]; | ||
listenerCount(event: 'execute'): number; | ||
listenerCount(event: 'error'): number; | ||
listenerCount(event: 'error'): number; | ||
listenerCount(event: 'closing'): number; | ||
listenerCount(event: 'close'): number; | ||
listenerCount(event: 'acquire'): number; | ||
listenerCount(event: 'terminate'): number; | ||
prependListener(event: 'execute', listener: (request: QueryRequest, connection: SqbConnection) => void): this; | ||
prependListener(event: 'error', listener: (error: Error, connection: SqbConnection) => void): this; | ||
prependListener(event: 'error', listener: (error: Error) => void): this; | ||
prependListener(event: 'closing', listener: () => void): this; | ||
prependListener(event: 'close', listener: () => void): this; | ||
prependListener(event: 'acquire', listener: (connection: SqbConnection) => void): this; | ||
prependListener(event: 'terminate', listener: () => void): this; | ||
prependOnceListener(event: 'execute', listener: (request: QueryRequest, connection: SqbConnection) => void): this; | ||
prependOnceListener(event: 'error', listener: (error: Error, connection: SqbConnection) => void): this; | ||
prependOnceListener(event: 'error', listener: (error: Error) => void): this; | ||
prependOnceListener(event: 'closing', listener: () => void): this; | ||
prependOnceListener(event: 'close', listener: () => void): this; | ||
prependOnceListener(event: 'acquire', listener: (connection: SqbConnection) => void): this; | ||
prependOnceListener(event: 'terminate', listener: () => void): this; | ||
} | ||
export {}; |
@@ -19,2 +19,3 @@ "use strict"; | ||
constructor(config) { | ||
// eslint-disable-next-line constructor-super | ||
super(); | ||
@@ -170,39 +171,3 @@ this._entities = {}; | ||
} | ||
addListener(event, listener) { | ||
return super.addListener(event, listener); | ||
} | ||
removeListener(event, listener) { | ||
return super.removeListener(event, listener); | ||
} | ||
emit(event, ...args) { | ||
return super.emit(event, ...args); | ||
} | ||
on(event, listener) { | ||
return super.on(event, listener); | ||
} | ||
once(event, listener) { | ||
return super.once(event, listener); | ||
} | ||
off(event, listener) { | ||
return super.off(event, listener); | ||
} | ||
removeAllListeners(event) { | ||
return super.removeAllListeners(event); | ||
} | ||
listeners(event) { | ||
return super.listeners(event); | ||
} | ||
rawListeners(event) { | ||
return super.rawListeners(event); | ||
} | ||
listenerCount(event) { | ||
return super.listenerCount(event); | ||
} | ||
prependListener(event, listener) { | ||
return super.prependListener(event, listener); | ||
} | ||
prependOnceListener(event, listener) { | ||
return super.prependOnceListener(event, listener); | ||
} | ||
} | ||
exports.SqbClient = SqbClient; |
import { classes } from '@sqb/builder'; | ||
import StrictEventEmitter from 'strict-event-emitter-types'; | ||
import { SqbClient } from './SqbClient'; | ||
@@ -8,3 +9,15 @@ import { ConnectionOptions, QueryExecuteOptions, QueryRequest } from './types'; | ||
import { Repository } from '../orm/repository.class'; | ||
export declare class SqbConnection extends SafeEventEmitter { | ||
interface Events { | ||
close: () => void; | ||
execute: (request: QueryRequest) => void; | ||
error: (error: Error) => void; | ||
retain: (refCount: number) => void; | ||
release: (refCount: number) => void; | ||
'start-transaction': () => void; | ||
commit: () => void; | ||
rollback: () => void; | ||
} | ||
declare type SqbConnectionEmitter = StrictEventEmitter<SafeEventEmitter, Events>; | ||
declare const SqbConnection_base: Type<SqbConnectionEmitter>; | ||
export declare class SqbConnection extends SqbConnection_base { | ||
readonly client: SqbClient; | ||
@@ -59,98 +72,3 @@ private _intlcon?; | ||
private _prepareQueryRequest; | ||
emit(event: 'close'): boolean; | ||
emit(event: 'execute', request: QueryRequest): boolean; | ||
emit(event: 'error', error: Error): boolean; | ||
emit(event: 'retain', refCount: number): boolean; | ||
emit(event: 'release', refCount: number): boolean; | ||
emit(event: 'start-transaction'): boolean; | ||
emit(event: 'commit'): boolean; | ||
emit(event: 'rollback'): boolean; | ||
on(event: 'close', listener: () => void): this; | ||
on(event: 'execute', listener: (request: QueryRequest) => void): this; | ||
on(event: 'error', listener: (error: Error) => void): this; | ||
on(event: 'retain', listener: (refCount: number) => void): this; | ||
on(event: 'release', listener: (refCount: number) => void): this; | ||
on(event: 'start-transaction', listener: () => void): this; | ||
on(event: 'commit', listener: () => void): this; | ||
on(event: 'rollback', listener: () => void): this; | ||
once(event: 'close', listener: () => void): this; | ||
once(event: 'execute', listener: (request: QueryRequest) => void): this; | ||
once(event: 'error', listener: (error: Error) => void): this; | ||
once(event: 'retain', listener: (refCount: number) => void): this; | ||
once(event: 'release', listener: (refCount: number) => void): this; | ||
once(event: 'start-transaction', listener: () => void): this; | ||
once(event: 'commit', listener: () => void): this; | ||
once(event: 'rollback', listener: () => void): this; | ||
off(event: 'close', listener: () => void): this; | ||
off(event: 'execute', listener: (request: QueryRequest) => void): this; | ||
off(event: 'error', listener: (error: Error) => void): this; | ||
off(event: 'retain', listener: (refCount: number) => void): this; | ||
off(event: 'release', listener: (refCount: number) => void): this; | ||
off(event: 'start-transaction', listener: () => void): this; | ||
off(event: 'commit', listener: () => void): this; | ||
off(event: 'rollback', listener: () => void): this; | ||
addListener(event: 'close', listener: () => void): this; | ||
addListener(event: 'execute', listener: (request: QueryRequest) => void): this; | ||
addListener(event: 'error', listener: (error: Error) => void): this; | ||
addListener(event: 'retain', listener: (refCount: number) => void): this; | ||
addListener(event: 'release', listener: (refCount: number) => void): this; | ||
addListener(event: 'start-transaction', listener: () => void): this; | ||
addListener(event: 'commit', listener: () => void): this; | ||
addListener(event: 'rollback', listener: () => void): this; | ||
removeListener(event: 'close', listener: () => void): this; | ||
removeListener(event: 'execute', listener: (request: QueryRequest) => void): this; | ||
removeListener(event: 'error', listener: (error: Error) => void): this; | ||
removeListener(event: 'retain', listener: (refCount: number) => void): this; | ||
removeListener(event: 'release', listener: (refCount: number) => void): this; | ||
removeListener(event: 'start-transaction', listener: () => void): this; | ||
removeListener(event: 'commit', listener: () => void): this; | ||
removeListener(event: 'rollback', listener: () => void): this; | ||
removeAllListeners(event: 'close'): this; | ||
removeAllListeners(event: 'execute'): this; | ||
removeAllListeners(event: 'error'): this; | ||
removeAllListeners(event: 'retain'): this; | ||
removeAllListeners(event: 'release'): this; | ||
removeAllListeners(event: 'start-transaction'): this; | ||
removeAllListeners(event: 'commit'): this; | ||
removeAllListeners(event: 'rollback'): this; | ||
listeners(event: 'close'): Function[]; | ||
listeners(event: 'execute'): Function[]; | ||
listeners(event: 'error'): Function[]; | ||
listeners(event: 'retain'): Function[]; | ||
listeners(event: 'release'): Function[]; | ||
listeners(event: 'start-transaction'): Function[]; | ||
listeners(event: 'commit'): Function[]; | ||
listeners(event: 'rollback'): Function[]; | ||
rawListeners(event: 'close'): Function[]; | ||
rawListeners(event: 'execute'): Function[]; | ||
rawListeners(event: 'error'): Function[]; | ||
rawListeners(event: 'retain'): Function[]; | ||
rawListeners(event: 'release'): Function[]; | ||
rawListeners(event: 'start-transaction'): Function[]; | ||
rawListeners(event: 'commit'): Function[]; | ||
rawListeners(event: 'rollback'): Function[]; | ||
listenerCount(event: 'close'): number; | ||
listenerCount(event: 'execute'): number; | ||
listenerCount(event: 'error'): number; | ||
listenerCount(event: 'retain'): number; | ||
listenerCount(event: 'release'): number; | ||
listenerCount(event: 'start-transaction'): number; | ||
listenerCount(event: 'commit'): number; | ||
listenerCount(event: 'rollback'): number; | ||
prependListener(event: 'close', listener: () => void): this; | ||
prependListener(event: 'execute', listener: (request: QueryRequest) => void): this; | ||
prependListener(event: 'error', listener: (error: Error) => void): this; | ||
prependListener(event: 'retain', listener: (refCount: number) => void): this; | ||
prependListener(event: 'release', listener: (refCount: number) => void): this; | ||
prependListener(event: 'start-transaction', listener: () => void): this; | ||
prependListener(event: 'commit', listener: () => void): this; | ||
prependListener(event: 'rollback', listener: () => void): this; | ||
prependOnceListener(event: 'close', listener: () => void): this; | ||
prependOnceListener(event: 'execute', listener: (request: QueryRequest) => void): this; | ||
prependOnceListener(event: 'error', listener: (error: Error) => void): this; | ||
prependOnceListener(event: 'retain', listener: (refCount: number) => void): this; | ||
prependOnceListener(event: 'release', listener: (refCount: number) => void): this; | ||
prependOnceListener(event: 'start-transaction', listener: () => void): this; | ||
prependOnceListener(event: 'commit', listener: () => void): this; | ||
prependOnceListener(event: 'rollback', listener: () => void): this; | ||
} | ||
export {}; |
@@ -20,2 +20,3 @@ "use strict"; | ||
constructor(client, adapterConnection, options) { | ||
// eslint-disable-next-line constructor-super | ||
super(); | ||
@@ -91,3 +92,3 @@ this.client = client; | ||
this.client.pool.release(intlcon) | ||
.catch(e => this.client.emit('error', e)); | ||
.catch(e => this.client.emit('error', e, this)); | ||
debug('[%s] closed', intlcon.sessionId); | ||
@@ -254,39 +255,3 @@ } | ||
} | ||
emit(event, ...args) { | ||
return super.emit(event, ...args); | ||
} | ||
on(event, listener) { | ||
return super.on(event, listener); | ||
} | ||
once(event, listener) { | ||
return super.once(event, listener); | ||
} | ||
off(event, listener) { | ||
return super.off(event, listener); | ||
} | ||
addListener(event, listener) { | ||
return super.addListener(event, listener); | ||
} | ||
removeListener(event, listener) { | ||
return super.removeListener(event, listener); | ||
} | ||
removeAllListeners(event) { | ||
return super.removeAllListeners(event); | ||
} | ||
listeners(event) { | ||
return super.listeners(event); | ||
} | ||
rawListeners(event) { | ||
return super.rawListeners(event); | ||
} | ||
listenerCount(event) { | ||
return super.listenerCount(event); | ||
} | ||
prependListener(event, listener) { | ||
return super.prependListener(event, listener); | ||
} | ||
prependOnceListener(event, listener) { | ||
return super.prependOnceListener(event, listener); | ||
} | ||
} | ||
exports.SqbConnection = SqbConnection; |
@@ -5,3 +5,3 @@ import { EntityModel } from '../model/entity-model'; | ||
export declare namespace Entity { | ||
function getMetadata(ctor: Function): EntityModel; | ||
function getMetadata(ctor: Function): EntityModel | undefined; | ||
} |
@@ -48,3 +48,3 @@ import { IndexOptions, TypeThunk, DataPropertyOptions } from '../orm.type'; | ||
getForeignKeyFor(t: EntityModel): Promise<Maybe<Association>>; | ||
static get(ctor: Function): EntityModel; | ||
static get(ctor: Function): Maybe<EntityModel>; | ||
static attachTo(ctor: Function): EntityModel; | ||
@@ -51,0 +51,0 @@ static getElementNames<T extends Function, K extends keyof T>(ctor: T): K[] | undefined; |
@@ -23,3 +23,3 @@ "use strict"; | ||
get propertyKeys() { | ||
if (!this._propertyKeys) | ||
if (!(this._propertyKeys && this.hasOwnProperty('_propertyKeys'))) | ||
this._propertyKeys = Array.from(this.properties.keys()); | ||
@@ -202,10 +202,10 @@ return this._propertyKeys; | ||
static get(ctor) { | ||
return ctor.hasOwnProperty(orm_const_1.ENTITY_DEFINITION_KEY) && | ||
ctor[orm_const_1.ENTITY_DEFINITION_KEY]; | ||
if (ctor.hasOwnProperty(orm_const_1.ENTITY_DEFINITION_KEY)) | ||
return ctor[orm_const_1.ENTITY_DEFINITION_KEY]; | ||
} | ||
static attachTo(ctor) { | ||
let entity = this.get(ctor); | ||
if (entity) | ||
return entity; | ||
ctor[orm_const_1.ENTITY_DEFINITION_KEY] = entity = new EntityModel(ctor); | ||
const current = this.get(ctor); | ||
if (current) | ||
return current; | ||
const entity = ctor[orm_const_1.ENTITY_DEFINITION_KEY] = new EntityModel(ctor); | ||
// Merge base entity columns into this one | ||
@@ -231,5 +231,5 @@ const baseCtor = Object.getPrototypeOf(ctor); | ||
entity.eventListeners.push(...base.eventListeners); | ||
if (base.primaryIndex) | ||
entity.setPrimaryIndex([...base.primaryIndex.columns]); | ||
} | ||
if (base.primaryIndex) | ||
entity.setPrimaryIndex([...base.primaryIndex.columns]); | ||
ctor.prototype.toJSON = function () { | ||
@@ -236,0 +236,0 @@ const obj = {}; |
@@ -8,6 +8,6 @@ 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 pickEntityInto<T, K extends keyof T>(derived: Type, classRef: Type<T>, keys: readonly K[]): Type<Pick<T, typeof keys[number]>>; | ||
export declare function omitEntityInto<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<Omit<T, typeof keys[number]>>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.OmitEntity = exports.PickEntity = exports.UnionEntity = exports.omitCloneEntity = exports.pickCloneEntity = exports.mixinEntities = void 0; | ||
exports.OmitEntity = exports.PickEntity = exports.UnionEntity = exports.omitEntityInto = exports.pickEntityInto = exports.mixinEntities = void 0; | ||
const entity_model_1 = require("../model/entity-model"); | ||
@@ -8,24 +8,35 @@ const association_1 = require("../model/association"); | ||
function mixinEntities(derived, classARef, classBRef, classCRef, classDRef, classERef, classFRef) { | ||
const entity = entity_model_1.EntityModel.attachTo(derived); | ||
const trg = entity_model_1.EntityModel.attachTo(derived); | ||
for (const classRef of [classARef, classBRef, classCRef, classDRef, classERef, classFRef]) { | ||
if (!classRef) | ||
continue; | ||
const model = entity_model_1.EntityModel.get(classRef); | ||
if (!entity.primaryIndex && model.primaryIndex) { | ||
entity.primaryIndex = new index_meta_1.IndexMeta(entity, model.primaryIndex.columns, model.primaryIndex); | ||
const src = entity_model_1.EntityModel.get(classRef); | ||
if (!src) | ||
return derived; | ||
if (!trg.primaryIndex && src.primaryIndex) { | ||
trg.primaryIndex = new index_meta_1.IndexMeta(trg, src.primaryIndex.columns, src.primaryIndex); | ||
} | ||
for (const fk of model.foreignKeys) { | ||
const newFk = new association_1.Association(fk.name, Object.assign(Object.assign({}, fk), { source: derived })); | ||
entity.foreignKeys.push(newFk); | ||
if (src.foreignKeys) { | ||
trg.foreignKeys = trg.foreignKeys || []; | ||
for (const fk of src.foreignKeys) { | ||
const newFk = new association_1.Association(fk.name, Object.assign(Object.assign({}, fk), { source: derived })); | ||
trg.foreignKeys.push(newFk); | ||
} | ||
} | ||
for (const idx of model.indexes) { | ||
const newIdx = new index_meta_1.IndexMeta(entity, idx.columns, idx); | ||
entity.indexes.push(newIdx); | ||
if (src.indexes) { | ||
trg.indexes = trg.indexes || []; | ||
for (const idx of src.indexes) { | ||
const newIdx = new index_meta_1.IndexMeta(trg, idx.columns, idx); | ||
trg.indexes.push(newIdx); | ||
} | ||
} | ||
entity.eventListeners.push(...model.eventListeners); | ||
model.properties.forEach((p, n) => { | ||
if (src.eventListeners) { | ||
trg.eventListeners = trg.eventListeners || []; | ||
trg.eventListeners.push(...src.eventListeners); | ||
} | ||
src.properties.forEach((p, n) => { | ||
const o = Object.assign({}, p); | ||
o.entity = entity; | ||
o.entity = trg; | ||
Object.setPrototypeOf(o, Object.getPrototypeOf(p)); | ||
entity.properties.set(n, o); | ||
trg.properties.set(n, o); | ||
}); | ||
@@ -36,50 +47,58 @@ } | ||
exports.mixinEntities = mixinEntities; | ||
function pickCloneEntity(derived, classRef, keys) { | ||
const srcModel = entity_model_1.EntityModel.get(classRef); | ||
const entity = entity_model_1.EntityModel.attachTo(derived); | ||
const pickKeys = keys; | ||
for (const fk of srcModel.foreignKeys) { | ||
if (fk.sourceKey && pickKeys.includes(fk.sourceKey)) { | ||
function pickEntityInto(derived, classRef, keys) { | ||
const trg = entity_model_1.EntityModel.attachTo(derived); | ||
const src = entity_model_1.EntityModel.get(classRef); | ||
if (!src) | ||
return derived; | ||
const pickKeys = keys.map(x => x.toLowerCase()); | ||
for (const fk of src.foreignKeys) { | ||
if (fk.sourceKey && pickKeys.includes(fk.sourceKey.toLowerCase())) { | ||
const newFk = new association_1.Association(fk.name, Object.assign(Object.assign({}, fk), { source: derived })); | ||
entity.foreignKeys.push(newFk); | ||
trg.foreignKeys.push(newFk); | ||
} | ||
} | ||
for (const idx of srcModel.indexes) { | ||
if (!idx.columns.find(x => !pickKeys.includes(x))) { | ||
const newIdx = new index_meta_1.IndexMeta(entity, idx.columns, idx); | ||
entity.indexes.push(newIdx); | ||
for (const idx of src.indexes) { | ||
if (!idx.columns.find(x => !pickKeys.includes(x.toLowerCase()))) { | ||
const newIdx = new index_meta_1.IndexMeta(trg, idx.columns, idx); | ||
trg.indexes.push(newIdx); | ||
} | ||
} | ||
entity.eventListeners.push(...srcModel.eventListeners); | ||
srcModel.properties.forEach((p, n) => { | ||
trg.eventListeners.push(...src.eventListeners); | ||
src.properties.forEach((p, n) => { | ||
if (pickKeys.includes(n)) | ||
entity.properties.set(n, p); | ||
trg.properties.set(n, p); | ||
}); | ||
return derived; | ||
} | ||
exports.pickCloneEntity = pickCloneEntity; | ||
function omitCloneEntity(derived, classRef, keys) { | ||
const srcModel = entity_model_1.EntityModel.get(classRef); | ||
const entity = entity_model_1.EntityModel.attachTo(derived); | ||
const omitKeys = keys; | ||
for (const fk of srcModel.foreignKeys) { | ||
if (!(fk.sourceKey && omitKeys.includes(fk.sourceKey))) { | ||
exports.pickEntityInto = pickEntityInto; | ||
function omitEntityInto(derived, classRef, keys) { | ||
const trg = entity_model_1.EntityModel.attachTo(derived); | ||
const src = entity_model_1.EntityModel.get(classRef); | ||
if (!src) | ||
return derived; | ||
const omitKeys = keys.map(x => x.toLowerCase()); | ||
for (const fk of src.foreignKeys) { | ||
if (!(fk.sourceKey && omitKeys.includes(fk.sourceKey.toLowerCase()))) { | ||
const newFk = new association_1.Association(fk.name, Object.assign(Object.assign({}, fk), { source: derived })); | ||
entity.foreignKeys.push(newFk); | ||
trg.foreignKeys.push(newFk); | ||
} | ||
} | ||
for (const idx of srcModel.indexes) { | ||
if (!idx.columns.find(x => omitKeys.includes(x))) { | ||
const newIdx = new index_meta_1.IndexMeta(entity, idx.columns, idx); | ||
entity.indexes.push(newIdx); | ||
for (const idx of src.indexes) { | ||
if (!idx.columns.find(x => omitKeys.includes(x.toLowerCase()))) { | ||
const newIdx = new index_meta_1.IndexMeta(trg, idx.columns, idx); | ||
trg.indexes.push(newIdx); | ||
} | ||
} | ||
entity.eventListeners.push(...srcModel.eventListeners); | ||
srcModel.properties.forEach((p, n) => { | ||
if (!omitKeys.includes(n)) | ||
entity.properties.set(n, p); | ||
trg.eventListeners.push(...src.eventListeners); | ||
src.properties.forEach((p, n) => { | ||
if (!omitKeys.includes(n.toLowerCase())) | ||
trg.properties.set(n.toLowerCase(), p); | ||
}); | ||
trg.properties.forEach((p, n) => { | ||
if (omitKeys.includes(n.toLowerCase())) | ||
trg.properties.delete(n.toLowerCase()); | ||
}); | ||
return derived; | ||
} | ||
exports.omitCloneEntity = omitCloneEntity; | ||
exports.omitEntityInto = omitEntityInto; | ||
function UnionEntity(classARef, classBRef) { | ||
@@ -101,3 +120,3 @@ class UnionEntityClass { | ||
} | ||
return pickCloneEntity(PickEntityClass, classRef, keys); | ||
return pickEntityInto(PickEntityClass, classRef, keys); | ||
} | ||
@@ -111,3 +130,3 @@ exports.PickEntity = PickEntity; | ||
} | ||
return omitCloneEntity(OmitEntityClass, classRef, keys); | ||
return omitEntityInto(OmitEntityClass, classRef, keys); | ||
} | ||
@@ -114,0 +133,0 @@ exports.OmitEntity = OmitEntity; |
@@ -26,2 +26,6 @@ export declare type Maybe<T> = T | undefined; | ||
export declare type PartialWritable<T> = Partial<PickWritable<T>>; | ||
declare type StringKeys<T> = Extract<keyof T, string | symbol>; | ||
export interface TypedEventEmitter<T> { | ||
addListener<K extends StringKeys<T>>(event: K, listener: (...args: any[]) => void): this; | ||
} | ||
export {}; |
{ | ||
"name": "@sqb/connect", | ||
"description": "Multi-dialect database connection framework written with TypeScript", | ||
"version": "4.0.1-beta.24", | ||
"version": "4.0.1-beta.25", | ||
"author": "Panates Ltd.", | ||
@@ -44,6 +44,8 @@ "contributors": [ | ||
"@types/debug": "^4.1.6", | ||
"@types/lodash": "^4.14.171" | ||
"@types/lodash": "^4.14.171", | ||
"typed-emitter": "^1.3.1", | ||
"strict-event-emitter-types": "^2.0.0" | ||
}, | ||
"peerDependencies": { | ||
"@sqb/builder": "^4.0.1-beta.24" | ||
"@sqb/builder": "^4.0.1-beta.25" | ||
}, | ||
@@ -50,0 +52,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
186486
4
4656