lambdaorm-base
Advanced tools
Comparing version 0.1.36 to 0.1.37
{ | ||
"name": "lambdaorm-base", | ||
"version": "0.1.36", | ||
"version": "0.1.37", | ||
"description": "ORM", | ||
@@ -5,0 +5,0 @@ "author": "Flavio Lionel Rita <flaviolrita@proton.me>", |
@@ -16,3 +16,2 @@ import { ClauseInfo, SourceRule, Schema, SchemaData, Dialect } from '../domain'; | ||
import { Type } from 'typ3s'; | ||
import { IFileSchemaService } from './ports/fileSchemaService'; | ||
export declare class SchemaFacade { | ||
@@ -31,20 +30,11 @@ readonly source: DataSourceConfigService; | ||
private readonly loadSchema; | ||
private readonly fileService; | ||
private readonly completeSchema; | ||
schema: Schema; | ||
schemaPath?: string; | ||
constructor(source: DataSourceConfigService, domain: DomainConfigService, mapping: MappingsConfigService, stage: StageConfigService, view: ViewsConfigService, schemaService: SchemaService, getSchemaData: GetSchemaSchema, routeService: RouteService, extender: SchemaExtender, createSchema: CreateSchema, updateSchema: UpdateSchema, loadSchema: LoadSchema, fileService: IFileSchemaService, completeSchema: CompleteSchema); | ||
new(dialect?: Dialect, connection?: any): Schema; | ||
constructor(source: DataSourceConfigService, domain: DomainConfigService, mapping: MappingsConfigService, stage: StageConfigService, view: ViewsConfigService, schemaService: SchemaService, getSchemaData: GetSchemaSchema, routeService: RouteService, extender: SchemaExtender, createSchema: CreateSchema, updateSchema: UpdateSchema, loadSchema: LoadSchema, completeSchema: CompleteSchema); | ||
create(dialect?: Dialect, connection?: any): Schema; | ||
updateFromData(schema: Schema, data: any | any[], name: string): SchemaData; | ||
schemaData(source: any, name: string, type: Type): SchemaData; | ||
solve(schema: Schema): Schema; | ||
complete(schema: Schema): void; | ||
evalSourceRule(rule: SourceRule, clauseInfo: ClauseInfo): boolean; | ||
getSource(clauseInfo: ClauseInfo, stage?: string): string; | ||
create(data: any | any[], name: string): [Schema, Type]; | ||
update(schema: Schema, data: any | any[], name: string): Type; | ||
schemaData(source: any, name: string, type: Type): SchemaData; | ||
createAndSchemaData(data: any | any[], name: string): [Schema, SchemaData]; | ||
updateAndSchemaData(schema: Schema, data: any | any[], name: string): SchemaData; | ||
get(source: string): Promise<Schema | null>; | ||
write(schema?: Schema, fullPath?: string): Promise<void>; | ||
initialize(source: string | Schema): Promise<Schema>; | ||
complete(schema: Schema): void; | ||
private _get; | ||
} |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SchemaFacade = void 0; | ||
const domain_1 = require("../domain"); | ||
class SchemaFacade { | ||
constructor(source, domain, mapping, stage, view, schemaService, getSchemaData, routeService, extender, createSchema, updateSchema, loadSchema, fileService, completeSchema) { | ||
// eslint-disable-next-line no-useless-constructor | ||
constructor(source, domain, mapping, stage, view, schemaService, getSchemaData, routeService, extender, createSchema, updateSchema, loadSchema, completeSchema) { | ||
this.source = source; | ||
@@ -28,37 +19,8 @@ this.domain = domain; | ||
this.loadSchema = loadSchema; | ||
this.fileService = fileService; | ||
this.completeSchema = completeSchema; | ||
this.schema = this.schemaService.newSchema(); | ||
} | ||
new(dialect, connection) { | ||
const schema = this.schemaService.newSchema(); | ||
if (dialect && connection) { | ||
schema.infrastructure = this.schemaService.newInfrastructure(); | ||
schema.infrastructure.sources = []; | ||
schema.infrastructure.sources.push({ name: 'default', mapping: 'default', dialect, connection }); | ||
schema.infrastructure.mappings = [{ name: 'default', entities: [] }]; | ||
} | ||
return schema; | ||
create(dialect, connection) { | ||
return this.createSchema.create(dialect, connection); | ||
} | ||
evalSourceRule(rule, clauseInfo) { | ||
return this.routeService.eval(rule, clauseInfo); | ||
} | ||
getSource(clauseInfo, stage) { | ||
return this.routeService.getSource(clauseInfo, stage); | ||
} | ||
create(data, name) { | ||
return this.createSchema.create(data, name); | ||
} | ||
update(schema, data, name) { | ||
return this.updateSchema.update(schema, data, name); | ||
} | ||
schemaData(source, name, type) { | ||
return this.getSchemaData.getData(source, name, type); | ||
} | ||
createAndSchemaData(data, name) { | ||
const [schema, type] = this.create(data, name); | ||
const schemaData = this.schemaData(data, name, type); | ||
return [schema, schemaData]; | ||
} | ||
updateAndSchemaData(schema, data, name) { | ||
updateFromData(schema, data, name) { | ||
const type = this.updateSchema.update(schema, data, name); | ||
@@ -68,50 +30,20 @@ const schemaData = this.schemaData(data, name, type); | ||
} | ||
get(source) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const schemaInfo = yield this._get(source); | ||
if (schemaInfo === null) { | ||
return null; | ||
} | ||
return schemaInfo.schema; | ||
}); | ||
schemaData(source, name, type) { | ||
return this.getSchemaData.getData(source, name, type); | ||
} | ||
write(schema, fullPath) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const schemaToWrite = schema || this.schema; | ||
const fullPathToWrite = fullPath || this.schemaPath; | ||
if (!fullPathToWrite) { | ||
throw new domain_1.SchemaError('No path to write schema'); | ||
} | ||
yield this.fileService.write(schemaToWrite, fullPathToWrite); | ||
}); | ||
solve(schema) { | ||
this.completeSchema.complete(schema); | ||
return this.loadSchema.load(schema); | ||
} | ||
initialize(source) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const schemaInfo = yield this._get(source); | ||
if (schemaInfo === null) { | ||
throw new domain_1.SchemaError(`Schema: ${source} not supported`); | ||
} | ||
this.schema = schemaInfo.schema; | ||
this.schemaPath = schemaInfo.path; | ||
this.completeSchema.complete(this.schema); | ||
this.schema = this.loadSchema.load(this.schema); | ||
return this.schema; | ||
}); | ||
} | ||
complete(schema) { | ||
this.extender.complete(schema); | ||
} | ||
_get(source) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (source && typeof source === 'string') { | ||
return yield this.fileService.read(source); | ||
} | ||
else if (source) { | ||
return { schema: source }; | ||
} | ||
return null; | ||
}); | ||
evalSourceRule(rule, clauseInfo) { | ||
return this.routeService.eval(rule, clauseInfo); | ||
} | ||
getSource(clauseInfo, stage) { | ||
return this.routeService.getSource(clauseInfo, stage); | ||
} | ||
} | ||
exports.SchemaFacade = SchemaFacade; | ||
//# sourceMappingURL=facade.js.map |
@@ -18,1 +18,2 @@ export * from './ports/fileSchemaService'; | ||
export * from './useCases/getSchemaData'; | ||
export * from './state'; |
@@ -34,2 +34,3 @@ "use strict"; | ||
__exportStar(require("./useCases/getSchemaData"), exports); | ||
__exportStar(require("./state"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -24,3 +24,3 @@ "use strict"; | ||
get entities() { | ||
return this.mapping.entities; | ||
return this.mapping.entities || []; | ||
} | ||
@@ -27,0 +27,0 @@ entityMapping(entityName) { |
@@ -403,2 +403,5 @@ "use strict"; | ||
completeMapping(mapping) { | ||
if (mapping.entities === undefined) { | ||
return; | ||
} | ||
for (const entity of mapping.entities) { | ||
@@ -426,2 +429,4 @@ if (this.helper.val.isEmpty(entity.mapping)) { | ||
continue; | ||
if (target.entities === undefined) | ||
target.entities = []; | ||
target.entities.push(sourceEntity); | ||
@@ -438,2 +443,4 @@ } | ||
continue; | ||
if (target.entities === undefined) | ||
target.entities = []; | ||
target.entities.push(sourceEntity); | ||
@@ -440,0 +447,0 @@ } |
@@ -12,3 +12,3 @@ import { AppPathsConfig, ApplicationSchema, InfrastructureSchema, DomainSchema, Schema, Entity } from '../../domain'; | ||
newPathsApp(): AppPathsConfig; | ||
updateSchema(schema: Schema, entities: Entity[]): void; | ||
updateEntities(schema: Schema, entities: Entity[]): void; | ||
getEntityName(name: string): string; | ||
@@ -15,0 +15,0 @@ getPk(objType: ObjType): PropertyType | undefined; |
@@ -24,3 +24,3 @@ "use strict"; | ||
} | ||
updateSchema(schema, entities) { | ||
updateEntities(schema, entities) { | ||
var _a; | ||
@@ -27,0 +27,0 @@ for (const entity of entities) { |
@@ -1,10 +0,7 @@ | ||
import { Schema } from '../../domain'; | ||
import { CreateEntitiesService } from '../services/createEntitiesService'; | ||
import { Type } from 'typ3s'; | ||
import { Dialect, Schema } from '../../domain'; | ||
import { SchemaService } from '../services/schemaService'; | ||
export declare class CreateSchema { | ||
private readonly schemaService; | ||
private readonly createEntitiesService; | ||
constructor(schemaService: SchemaService, createEntitiesService: CreateEntitiesService); | ||
create(data: any | any[], name: string): [Schema, Type]; | ||
constructor(schemaService: SchemaService); | ||
create(dialect?: Dialect, connection?: any): Schema; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CreateSchema = void 0; | ||
const typ3s_1 = require("typ3s"); | ||
class CreateSchema { | ||
// eslint-disable-next-line no-useless-constructor | ||
constructor(schemaService, createEntitiesService) { | ||
constructor(schemaService) { | ||
this.schemaService = schemaService; | ||
this.createEntitiesService = createEntitiesService; | ||
} | ||
create(data, name) { | ||
if (!data || typeof data !== 'object') { | ||
throw new Error('Invalid argument data'); | ||
create(dialect, connection) { | ||
const schema = this.schemaService.newSchema(); | ||
if (dialect && connection) { | ||
schema.infrastructure = this.schemaService.newInfrastructure(); | ||
schema.infrastructure.sources = []; | ||
schema.infrastructure.sources.push({ name: 'default', mapping: 'default', dialect, connection }); | ||
schema.infrastructure.mappings = [{ name: 'default', entities: [] }]; | ||
} | ||
if (typeof name !== 'string') { | ||
throw new Error('Argument name undefined'); | ||
} | ||
const type = typ3s_1.Type.type(data, { info: true, describe: true }); | ||
const entities = this.createEntitiesService.getEntities(name, type); | ||
const schema = this.schemaService.newSchema(); | ||
this.schemaService.updateSchema(schema, entities); | ||
return [schema, type]; | ||
return schema; | ||
} | ||
@@ -24,0 +19,0 @@ } |
@@ -20,3 +20,3 @@ "use strict"; | ||
const entities = this.createEntitiesService.getEntities(name, type); | ||
this.schemaService.updateSchema(schema, entities); | ||
this.schemaService.updateEntities(schema, entities); | ||
return type; | ||
@@ -23,0 +23,0 @@ } |
@@ -91,4 +91,4 @@ import { SentenceAction } from './actions'; | ||
export interface EntityMapping extends Entity { | ||
mapping: string; | ||
sequence: string; | ||
mapping?: string; | ||
sequence?: string; | ||
properties: PropertyMapping[]; | ||
@@ -108,3 +108,3 @@ filter?: string; | ||
name: string; | ||
entities: EntityMapping[]; | ||
entities?: EntityMapping[]; | ||
format?: FormatMapping; | ||
@@ -154,5 +154,5 @@ } | ||
export interface AppPathsConfig { | ||
src: string; | ||
data: string; | ||
domain: string; | ||
src?: string; | ||
data?: string; | ||
domain?: string; | ||
} | ||
@@ -159,0 +159,0 @@ export interface DomainSchema { |
@@ -5,4 +5,2 @@ "use strict"; | ||
const application_1 = require("../application"); | ||
const fileSchemaService_1 = require("./fileSchemaService"); | ||
const schemaFileHelper_1 = require("./schemaFileHelper"); | ||
const schemaService_1 = require("../application/services/schemaService"); | ||
@@ -28,8 +26,7 @@ const interpretSchemaDataService_1 = require("../application/services/interpretSchemaDataService"); | ||
const loadSchema = new application_1.LoadSchema(source, model, mapping, stage, view, extender, this.helper); | ||
const createSchema = new application_1.CreateSchema(schemaService, createEntitiesService); | ||
const createSchema = new application_1.CreateSchema(schemaService); | ||
const updateSchema = new application_1.UpdateSchema(schemaService, createEntitiesService); | ||
const fileSchemaService = new fileSchemaService_1.FileSchemaService(new schemaFileHelper_1.SchemaFileHelper(this.helper), this.helper); | ||
const completeSchema = new application_1.CompleteSchema(schemaService); | ||
const getSchemaData = new application_1.GetSchemaSchema(interpretSchemaDataService); | ||
return new application_1.SchemaFacade(source, model, mapping, stage, view, schemaService, getSchemaData, routeService, extender, createSchema, updateSchema, loadSchema, fileSchemaService, completeSchema); | ||
return new application_1.SchemaFacade(source, model, mapping, stage, view, schemaService, getSchemaData, routeService, extender, createSchema, updateSchema, loadSchema, completeSchema); | ||
} | ||
@@ -36,0 +33,0 @@ } |
export * from './facadeBuilder'; | ||
export * from './stateBuilder'; |
@@ -18,2 +18,3 @@ "use strict"; | ||
__exportStar(require("./facadeBuilder"), exports); | ||
__exportStar(require("./stateBuilder"), exports); | ||
//# sourceMappingURL=index.js.map |
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
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
Sorry, the diff of this file is not supported yet
273049
157
4125