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

@sqb/connect

Package Overview
Dependencies
Maintainers
1
Versions
137
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sqb/connect - npm Package Compare versions

Comparing version 4.0.1-beta.2 to 4.0.1-beta.3

dist/orm/metadata/abstract-element-meta.d.ts

64

dist/orm/commands/find.command.js

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

};
/* if (parentContext) {
if (parentContext.entitiesQueried.includes(entity))
throw new Error(`Circular query detected`);
ctx.entitiesQueried.push(...parentContext.entitiesQueried);
}
ctx.entitiesQueried.push(entity); */
// Prepare list of included element names

@@ -58,3 +52,3 @@ if (args.elements && args.elements.length)

//
await this._addEntityElements(ctx, entity, ctx.model, 'T', '');
await this._addEntityElements(ctx, entity, ctx.model, 'T');
// Wrap search filter to operator instances

@@ -98,5 +92,4 @@ let where;

}
static async _addEntityElements(ctx, entity, model, tableAlias, currentPath) {
const pPathLower = currentPath.toLowerCase();
const pPathDot = pPathLower ? pPathLower + '.' : '';
static async _addEntityElements(ctx, entity, model, tableAlias) {
const { excludeElements, requestElements } = ctx;
for (const key of entity.elementKeys) {

@@ -107,12 +100,13 @@ const col = entity.getElement(key);

const colNameLower = col.name.toLowerCase();
// Check if element is excluded
if (ctx.excludeElements &&
ctx.excludeElements.find(x => x === pPathDot + colNameLower || x === pPathLower))
// Ignore element if in excluded list
if (excludeElements && excludeElements.includes(colNameLower))
continue;
// Check if element is requested
if ((data_column_meta_1.isDataColumn(col) || embedded_element_meta_1.isEmbeddedElement(col)) && ctx.requestElements &&
!ctx.requestElements.find(x => x === pPathDot + colNameLower || x === pPathLower))
// Ignore element if not requested
// Relational elements must be explicitly requested.
if (!requestElements && relation_element_meta_1.isRelationElement(col))
continue;
if (requestElements && !requestElements.find(x => x === colNameLower || x.startsWith(colNameLower + '.')))
continue;
// Add field to select list
if (data_column_meta_1.isDataColumn(col)) {
// Add select sql field
const fieldAlias = this._addSelectColumn(ctx, tableAlias, col);

@@ -127,3 +121,3 @@ // Add column to transform model

const subModel = new row_transform_model_1.RowTransformModel(typ, model);
await this._addEntityElements(ctx, typ, subModel, tableAlias, currentPath ? currentPath + '.' + col.name : col.name);
await this._addEntityElements(Object.assign(Object.assign({}, ctx), { requestElements: extractSubElements(colNameLower, requestElements), excludeElements: extractSubElements(colNameLower, excludeElements) }), typ, subModel, tableAlias);
model.addNode(col, subModel);

@@ -133,5 +127,2 @@ continue;

if (relation_element_meta_1.isRelationElement(col)) {
// Relational columns must be explicitly requested.
if (!(ctx.requestElements && ctx.requestElements.find(x => x === pPathDot + colNameLower || x.startsWith(pPathDot + colNameLower + '.'))))
continue;
// Lazy resolver requires key column value.

@@ -151,3 +142,3 @@ // So we need to add key column to result model

// Add join fields to select columns list
await this._addEntityElements(ctx, joinInfo.targetEntity, subModel, joinInfo.joinAlias, currentPath ? currentPath + '.' + col.name : col.name);
await this._addEntityElements(Object.assign(Object.assign({}, ctx), { requestElements: extractSubElements(colNameLower, requestElements), excludeElements: extractSubElements(colNameLower, excludeElements) }), joinInfo.targetEntity, subModel, joinInfo.joinAlias);
continue;

@@ -162,17 +153,2 @@ }

model.addDataElement(keyCol, fieldAlias);
// prepare requested columns and select only paths for target entity
const _reqElements = ctx.requestElements && ctx.requestElements
.reduce((a, x) => {
if (x.startsWith(pPathDot + colNameLower + '.'))
a.push(x.substring(pPathDot.length + colNameLower.length + 1).toLowerCase());
return a;
}, []);
const _excludedElements = ctx.excludeElements && ctx.excludeElements
.reduce((a, x) => {
if (x.toLowerCase() === targetCol.name.toLowerCase())
return a;
if (x.startsWith(pPathDot + colNameLower + '.'))
a.push(x.substring(pPathDot.length + colNameLower.length + 1).toLowerCase());
return a;
}, []);
// Eager operation must contain foreign fields

@@ -183,5 +159,5 @@ // if (_reqElements && !_reqElements.includes(targetCol.name.toLowerCase()))

const prepareOptions = {
elements: _reqElements && _reqElements.length ? _reqElements : undefined,
elements: extractSubElements(colNameLower, requestElements),
include: [targetCol.name],
exclude: _excludedElements && _excludedElements.length ? _excludedElements : undefined,
exclude: extractSubElements(colNameLower, excludeElements),
filter: builder_1.In(targetCol.name, builder_1.Param(fieldAlias)),

@@ -225,1 +201,11 @@ maxEagerFetch: ctx.maxEagerFetch,

exports.FindCommand = FindCommand;
function extractSubElements(colNameLower, elements) {
if (!elements)
return;
const result = elements.reduce((trg, v) => {
if (v.startsWith(colNameLower + '.'))
trg.push(v.substring(colNameLower.length + 1).toLowerCase());
return trg;
}, []);
return result.length ? result : undefined;
}
import { EmbeddedTypeOptions, ConstructorThunk } from '../types';
export declare function Embedded(type: ConstructorThunk, options?: EmbeddedTypeOptions): PropertyDecorator;
export declare function Embedded(type?: ConstructorThunk, options?: EmbeddedTypeOptions): PropertyDecorator;

@@ -9,4 +9,2 @@ "use strict";

throw new Error('Symbol properties are not accepted');
if (typeof type !== 'function')
throw new Error('You must provide "type" argument');
const el = entity_meta_1.EntityMeta.attachTo(target.constructor)

@@ -13,0 +11,0 @@ .setEmbeddedElement(propertyKey, type);

@@ -5,5 +5,5 @@ import 'reflect-metadata';

import { ElementKind, ColumnAutoGenerationStrategy, ColumnTransformFunction, DataColumnOptions, EnumValue, FieldValue, DefaultValueGetter } from '../types';
import { EntityElementMeta } from './entity-element-meta';
import { AbstractElementMeta } from './abstract-element-meta';
export declare function isDataColumn(f: any): f is DataColumnMeta;
export declare class DataColumnMeta extends EntityElementMeta {
export declare class DataColumnMeta extends AbstractElementMeta {
readonly kind: ElementKind;

@@ -10,0 +10,0 @@ fieldName: string;

@@ -9,8 +9,8 @@ "use strict";

const lodash_1 = __importDefault(require("lodash"));
const entity_element_meta_1 = require("./entity-element-meta");
const abstract_element_meta_1 = require("./abstract-element-meta");
function isDataColumn(f) {
return !!(f && f instanceof entity_element_meta_1.EntityElementMeta && f.kind === 'data');
return !!(f && f instanceof abstract_element_meta_1.AbstractElementMeta && f.kind === 'data');
}
exports.isDataColumn = isDataColumn;
class DataColumnMeta extends entity_element_meta_1.EntityElementMeta {
class DataColumnMeta extends abstract_element_meta_1.AbstractElementMeta {
constructor(entity, name, options = {}) {

@@ -17,0 +17,0 @@ super(entity, name);

import { ElementKind, ConstructorThunk, DataColumnOptions } from '../types';
import { EntityElementMeta } from './entity-element-meta';
import { AbstractElementMeta } from './abstract-element-meta';
import { EntityMeta } from './entity-meta';
export declare const isEmbeddedElement: (f: any) => f is EmbeddedElementMeta;
export declare class EmbeddedElementMeta extends EntityElementMeta {
export declare class EmbeddedElementMeta extends AbstractElementMeta {
kind: ElementKind;

@@ -7,0 +7,0 @@ type: ConstructorThunk;

@@ -8,9 +8,9 @@ "use strict";

const lodash_1 = __importDefault(require("lodash"));
const entity_element_meta_1 = require("./entity-element-meta");
const abstract_element_meta_1 = require("./abstract-element-meta");
const helpers_1 = require("../helpers");
const isEmbeddedElement = (f) => {
return !!(f && f instanceof entity_element_meta_1.EntityElementMeta && f.kind === 'embedded');
return !!(f && f instanceof abstract_element_meta_1.AbstractElementMeta && f.kind === 'embedded');
};
exports.isEmbeddedElement = isEmbeddedElement;
class EmbeddedElementMeta extends entity_element_meta_1.EntityElementMeta {
class EmbeddedElementMeta extends abstract_element_meta_1.AbstractElementMeta {
constructor(entity, name, type) {

@@ -17,0 +17,0 @@ super(entity, name);

@@ -8,3 +8,3 @@ import { RelationElementMeta } from './relation-element-meta';

import { EmbeddedElementMeta } from './embedded-element-meta';
declare type ColumnMeta = DataColumnMeta | EmbeddedElementMeta | RelationElementMeta;
export declare type ColumnMeta = DataColumnMeta | EmbeddedElementMeta | RelationElementMeta;
export declare class EntityMeta {

@@ -33,3 +33,3 @@ readonly ctor: Function;

setRelationColumn(name: string, target: ConstructorThunk, options?: RelationColumnOptions): RelationElementMeta;
setEmbeddedElement(name: string, type: ConstructorThunk): EmbeddedElementMeta;
setEmbeddedElement(propertyKey: string, type?: ConstructorThunk): EmbeddedElementMeta;
setPrimaryIndex(column: string | string[], options?: IndexOptions): void;

@@ -52,2 +52,1 @@ addIndex(column: string | string[], options?: IndexOptions): void;

}
export {};

@@ -118,11 +118,12 @@ "use strict";

}
setEmbeddedElement(name, type) {
setEmbeddedElement(propertyKey, type) {
type = type || Reflect.getMetadata("design:type", this.ctor.prototype, propertyKey);
if (typeof type !== 'function')
throw new Error('"type" must be defined');
let col = this.getElement(name);
let col = this.getElement(propertyKey);
if (!col || !embedded_element_meta_1.isEmbeddedElement(col)) {
col = new embedded_element_meta_1.EmbeddedElementMeta(this, name, type);
if (!this.elements.has(name.toLowerCase()))
this.elementKeys.push(name);
this.elements.set(name.toLowerCase(), col);
col = new embedded_element_meta_1.EmbeddedElementMeta(this, propertyKey, type);
if (!this.elements.has(propertyKey.toLowerCase()))
this.elementKeys.push(propertyKey);
this.elements.set(propertyKey.toLowerCase(), col);
}

@@ -129,0 +130,0 @@ return col;

import type { EntityMeta } from './entity-meta';
import { ElementKind, ConstructorThunk, RelationColumnOptions, DataColumnOptions } from '../types';
import { EntityElementMeta } from './entity-element-meta';
import { AbstractElementMeta } from './abstract-element-meta';
import { ForeignKeyMeta } from '../metadata/foreign-key-meta';
export declare const isRelationElement: (f: any) => f is RelationElementMeta;
export declare class RelationElementMeta extends EntityElementMeta {
export declare class RelationElementMeta extends AbstractElementMeta {
readonly kind: ElementKind;

@@ -8,0 +8,0 @@ readonly foreign: ForeignKeyMeta;

@@ -8,9 +8,9 @@ "use strict";

const lodash_1 = __importDefault(require("lodash"));
const entity_element_meta_1 = require("./entity-element-meta");
const abstract_element_meta_1 = require("./abstract-element-meta");
const foreign_key_meta_1 = require("../metadata/foreign-key-meta");
const isRelationElement = (f) => {
return !!(f && f instanceof entity_element_meta_1.EntityElementMeta && f.kind === 'relation');
return !!(f && f instanceof abstract_element_meta_1.AbstractElementMeta && f.kind === 'relation');
};
exports.isRelationElement = isRelationElement;
class RelationElementMeta extends entity_element_meta_1.EntityElementMeta {
class RelationElementMeta extends abstract_element_meta_1.AbstractElementMeta {
constructor(entity, name, target, options) {

@@ -17,0 +17,0 @@ super(entity, name);

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

import type { EntityElementMeta } from './metadata/entity-element-meta';
import type { AbstractElementMeta } from './metadata/abstract-element-meta';
import type { Repository } from './repository';

@@ -9,3 +9,3 @@ import { DataType, Type } from '..';

export declare type ColumnAutoGenerationStrategy = 'increment' | 'uuid' | 'rowid' | 'timestamp' | 'custom';
export declare type ColumnTransformFunction = (value: any, col: EntityElementMeta, row: any) => any;
export declare type ColumnTransformFunction = (value: any, col: AbstractElementMeta, row: any) => any;
export declare type ConstructorResolver<T> = () => Type<T> | Promise<Type<T>>;

@@ -12,0 +12,0 @@ export declare type ConstructorThunk<T = {}> = Type<T> | ConstructorResolver<T>;

import type { QueryExecutor } from '../../client/types';
import type { FieldInfoMap } from '../../client/FieldInfoMap';
import type { EntityMeta } from '../metadata/entity-meta';
import type { EntityElementMeta } from '../metadata/entity-element-meta';
import type { AbstractElementMeta } from '../metadata/abstract-element-meta';
import { RelationElementMeta } from '../metadata/relation-element-meta';

@@ -10,3 +10,3 @@ import { DataColumnMeta } from '../metadata/data-column-meta';

export interface RowTransformItem {
element: EntityElementMeta;
element: AbstractElementMeta;
fieldAlias: string;

@@ -13,0 +13,0 @@ node?: RowTransformModel;

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

import { EntityElementMeta } from '../metadata/entity-element-meta';
export declare function serializeColumn(col: EntityElementMeta, v: any): any;
import { AbstractElementMeta } from '../metadata/abstract-element-meta';
export declare function serializeColumn(col: AbstractElementMeta, v: any): any;
{
"name": "@sqb/connect",
"description": "Multi-dialect database connection framework written with TypeScript",
"version": "4.0.1-beta.2",
"version": "4.0.1-beta.3",
"author": "Panates Ltd.",

@@ -47,3 +47,3 @@ "contributors": [

"peerDependencies": {
"@sqb/builder": "^4.0.1-beta.2"
"@sqb/builder": "^4.0.1-beta.3"
},

@@ -50,0 +50,0 @@ "main": "dist/index.js",

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