-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#198
- Loading branch information
FlavioLionelRita
committed
Nov 19, 2023
1 parent
f4602b3
commit f2f2587
Showing
24 changed files
with
392 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
# Lambda ORM client node | ||
# λORM Client Node | ||
|
||
Lambdaorm client node is an http client to consume [lambdaorm service](https://github.com/FlavioLionelRita/lambdaorm-svc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* eslint-disable @typescript-eslint/ban-types */ | ||
import { MetadataSentence, QueryOptions, Metadata, MetadataModel, MetadataConstraint, MetadataParameter } from '../domain' | ||
export interface ExpressionService { | ||
/** | ||
* Get model of expression | ||
* @param expression query expression | ||
* @returns Model of expression | ||
*/ | ||
model (expression: string|Function): Promise<MetadataModel[]> | ||
|
||
/** | ||
* Get parameters of expression | ||
* @param expression query expression | ||
* @returns Parameters of expression | ||
*/ | ||
parameters (expression: string|Function): Promise<MetadataParameter[]> | ||
|
||
/** | ||
* Get constraints of expression | ||
* @param expression query expression | ||
* @returns Constraints of expression | ||
*/ | ||
constraints (expression: string|Function): Promise<MetadataConstraint> | ||
|
||
/** | ||
* Get metadata of expression | ||
* @param expression query expression | ||
* @returns metadata of expression | ||
*/ | ||
metadata (expression: string|Function): Promise<Metadata> | ||
|
||
/** | ||
* Get getInfo of expression | ||
* @param expression query expression | ||
* @param options options of execution | ||
*/ | ||
sentence (expression: string|Function, options: QueryOptions|undefined): Promise<MetadataSentence> | ||
|
||
/** | ||
* Execute expression | ||
* @param expression query expression | ||
* @param data Data with variables | ||
* @param options options of execution | ||
* @returns Result of execution | ||
*/ | ||
execute (expression: string|Function, data: any, options?: QueryOptions): Promise<any> | ||
|
||
/** | ||
* Execute expression | ||
* @param expression query expression | ||
* @param data Data with variables | ||
* @param options options of execution | ||
* @returns Result of execution | ||
*/ | ||
executeQueued (expression: string|Function, topic:string, data: any, chunk?:number, options?: QueryOptions): Promise<any> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface GeneralService { | ||
ping ():Promise<any> | ||
health ():Promise<any> | ||
metrics ():Promise<any> | ||
} |
8 changes: 7 additions & 1 deletion
8
src/lib/application/ports/IOrm.ts → src/lib/application/IOrm.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Entity, EntityMapping, Enum, Mapping, Stage } from '../domain' | ||
export interface SchemaService { | ||
dataSources ():Promise<{name:string, dialect:string}[]> | ||
entities (): Promise<Entity[]> | ||
entity (entity:string): Promise<Entity|undefined> | ||
enums (): Promise<Enum[]> | ||
enum (_enum:string): Promise<Enum|undefined> | ||
mappings (): Promise<Mapping[]> | ||
mapping (mapping:string): Promise<Mapping|undefined> | ||
entityMapping (mapping:string, entity:string): Promise<EntityMapping|undefined> | ||
stages (): Promise<Stage[]> | ||
stage (stage:string): Promise<Stage|undefined> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { SchemaConfig } from '../domain' | ||
export interface StageService { | ||
exists (stage:string): Promise<boolean> | ||
export (stage:string): Promise<SchemaConfig> | ||
import (stage:string, schemaData:any): Promise<void> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export * from './ports/IOrm' | ||
export * from './services/expressionService' | ||
export * from './services/generalService' | ||
export * from './services/schemaService' | ||
export * from './services/stageService' | ||
export * from './IOrm' | ||
export * from './ExpressionService' | ||
export * from './GeneralService' | ||
export * from './SchemaService' | ||
export * from './StageService' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface SchemaConfigEntity { | ||
entity: string; | ||
rows: any[]; | ||
} | ||
export interface SchemaConfig { | ||
entities: SchemaConfigEntity[]; | ||
} |
123 changes: 123 additions & 0 deletions
123
src/lib/infrastructure/adapters/ExpressionApiService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* eslint-disable @typescript-eslint/ban-types */ | ||
|
||
import { ExpressionApi } from '../api' | ||
import { MetadataSentence, QueryOptions, Metadata, MetadataModel, MetadataConstraint, MetadataParameter } from '../../domain' | ||
import { AxiosResponse } from 'axios' | ||
import { expressions } from '3xpr' | ||
import { ExpressionService } from 'lib/application' | ||
|
||
export class ExpressionApiService implements ExpressionService { | ||
// eslint-disable-next-line no-useless-constructor | ||
constructor (private readonly expressionApi:ExpressionApi) {} | ||
|
||
/** | ||
* Get model of expression | ||
* @param expression query expression | ||
* @returns Model of expression | ||
*/ | ||
public async model(expression:Function): Promise<MetadataModel[]> | ||
public async model(expression:string): Promise<MetadataModel[]> | ||
public async model (expression: string|Function): Promise<MetadataModel[]> { | ||
const _expression = typeof expression !== 'string' ? expressions.toExpression(expression) : expression | ||
const result:AxiosResponse<MetadataModel[], any> = await this.expressionApi.model({ expression: _expression }) | ||
return result.data | ||
} | ||
|
||
/** | ||
* Get parameters of expression | ||
* @param expression query expression | ||
* @returns Parameters of expression | ||
*/ | ||
public async parameters(expression:Function): Promise<MetadataParameter[]>; | ||
public async parameters(expression:string): Promise<MetadataParameter[]>; | ||
public async parameters (expression: string|Function): Promise<MetadataParameter[]> { | ||
const _expression = typeof expression !== 'string' ? expressions.toExpression(expression) : expression | ||
const result:AxiosResponse<MetadataParameter[], any> = await this.expressionApi.parameters({ expression: _expression }) | ||
return result.data | ||
} | ||
|
||
/** | ||
* Get constraints of expression | ||
* @param expression query expression | ||
* @returns Constraints of expression | ||
*/ | ||
public async constraints(expression:Function): Promise<MetadataConstraint>; | ||
public async constraints(expression:string): Promise<MetadataConstraint>; | ||
public async constraints (expression: string|Function): Promise<MetadataConstraint> { | ||
const _expression = typeof expression !== 'string' ? expressions.toExpression(expression) : expression | ||
const result:AxiosResponse<MetadataConstraint, any> = await this.expressionApi.constraints({ expression: _expression }) | ||
return result.data | ||
} | ||
|
||
/** | ||
* Get metadata of expression | ||
* @param expression query expression | ||
* @returns metadata of expression | ||
*/ | ||
public async metadata(expression: Function): Promise<Metadata> | ||
public async metadata (expression:string):Promise<Metadata> | ||
public async metadata (expression: string|Function): Promise<Metadata> { | ||
const _expression = typeof expression !== 'string' ? expressions.toExpression(expression) : expression | ||
const result:AxiosResponse<Metadata, any> = await this.expressionApi.metadata({ expression: _expression }) | ||
return result.data | ||
} | ||
|
||
/** | ||
* Get getInfo of expression | ||
* @param expression query expression | ||
* @param options options of execution | ||
*/ | ||
public async sentence(expression: Function, options?: QueryOptions): Promise<MetadataSentence>; | ||
public async sentence(expression: string, options?: QueryOptions): Promise<MetadataSentence>; | ||
public async sentence (expression: string|Function, options: QueryOptions|undefined): Promise<MetadataSentence> { | ||
const _expression = typeof expression !== 'string' ? expressions.toExpression(expression) : expression | ||
const _options = this.solveOptions(options) | ||
const result:AxiosResponse<MetadataSentence, any> = await this.expressionApi.sentence({ expression: _expression, options: _options }) | ||
return result.data | ||
} | ||
|
||
/** | ||
* Execute expression | ||
* @param expression query expression | ||
* @param data Data with variables | ||
* @param options options of execution | ||
* @returns Result of execution | ||
*/ | ||
public async execute(expression: Function, data?: any, options?: QueryOptions):Promise<any>; | ||
public async execute(expression: string, data?: any, options?: QueryOptions):Promise<any>; | ||
public async execute (expression: string|Function, data: any = {}, options: QueryOptions|undefined = undefined): Promise<any> { | ||
const _expression = typeof expression !== 'string' ? expressions.toExpression(expression) : expression | ||
const _options = this.solveOptions(options) | ||
const result:AxiosResponse<any, any> = await this.expressionApi.execute({ expression: _expression, data, options: _options }) | ||
return result.data | ||
} | ||
|
||
/** | ||
* Execute expression | ||
* @param expression query expression | ||
* @param data Data with variables | ||
* @param options options of execution | ||
* @returns Result of execution | ||
*/ | ||
public async executeQueued(expression: Function, topic:string, data?: any, chunk?:number, options?: QueryOptions):Promise<any>; | ||
public async executeQueued(expression: string, topic:string, data?: any, chunk?:number, options?: QueryOptions):Promise<any>; | ||
public async executeQueued (expression: string|Function, topic:string, data: any = {}, chunk?:number, options: QueryOptions|undefined = undefined): Promise<any> { | ||
const _expression = typeof expression !== 'string' ? expressions.toExpression(expression) : expression | ||
const _options = this.solveOptions(options) | ||
const result:AxiosResponse<any, any> = await this.expressionApi.executeQueued({ expression: _expression, data, options: _options, topic, chunk }) | ||
return result.data | ||
} | ||
|
||
private solveOptions (options?: QueryOptions):QueryOptions { | ||
if (!options) { | ||
options = {} | ||
} | ||
if (!options.stage) { | ||
options.stage = 'default' | ||
} | ||
if (!options.view) { | ||
options.view = 'default' | ||
} | ||
return options | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { GeneralService } from 'lib/application' | ||
import { GeneralApi } from '../api' | ||
import { AxiosResponse } from 'axios' | ||
|
||
export class GeneralApiService implements GeneralService { | ||
// eslint-disable-next-line no-useless-constructor | ||
constructor (private readonly generalApi:GeneralApi) {} | ||
|
||
public async ping ():Promise<any> { | ||
const result:AxiosResponse<any, any> = await this.generalApi.ping() | ||
return result.data | ||
} | ||
|
||
public async health ():Promise<any> { | ||
const result:AxiosResponse<any, any> = await this.generalApi.health() | ||
return result.data | ||
} | ||
|
||
public async metrics ():Promise<any> { | ||
const result:AxiosResponse<any, any> = await this.generalApi.metrics() | ||
return result.data | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { SchemaService } from 'lib/application' | ||
import { Entity, EntityMapping, Enum, Mapping, Stage } from '../../domain' | ||
import { SchemaApi } from '../api' | ||
import { AxiosResponse } from 'axios' | ||
|
||
export class SchemaApiService implements SchemaService { | ||
// eslint-disable-next-line no-useless-constructor | ||
constructor (private readonly schemaApi:SchemaApi) {} | ||
|
||
public async dataSources ():Promise<{name:string, dialect:string}[]> { | ||
const result:AxiosResponse<{name:string, dialect:string}[], any> = await this.schemaApi.dataSources() | ||
return result.data | ||
} | ||
|
||
public async entities (): Promise<Entity[]> { | ||
const result:AxiosResponse<Entity[], any> = await this.schemaApi.entities() | ||
return result.data | ||
} | ||
|
||
public async entity (entity:string): Promise<Entity|undefined> { | ||
const result:AxiosResponse<Entity, any> = await this.schemaApi.entity(entity) | ||
return result.data | ||
} | ||
|
||
public async enums (): Promise<Enum[]> { | ||
const result:AxiosResponse<Enum[], any> = await this.schemaApi.enums() | ||
return result.data | ||
} | ||
|
||
public async enum (_enum:string): Promise<Enum|undefined> { | ||
const result:AxiosResponse<Enum, any> = await this.schemaApi._enum(_enum) | ||
return result.data | ||
} | ||
|
||
public async mappings (): Promise<Mapping[]> { | ||
const result:AxiosResponse<Mapping[], any> = await this.schemaApi.mappings() | ||
return result.data | ||
} | ||
|
||
public async mapping (mapping:string): Promise<Mapping|undefined> { | ||
const result:AxiosResponse<Mapping, any> = await this.schemaApi.mapping(mapping) | ||
return result.data | ||
} | ||
|
||
public async entityMapping (mapping:string, entity:string): Promise<EntityMapping|undefined> { | ||
const result:AxiosResponse<EntityMapping, any> = await this.schemaApi.entityMapping(mapping, entity) | ||
return result.data | ||
} | ||
|
||
public async stages (): Promise<Stage[]> { | ||
const result:AxiosResponse<Stage[], any> = await this.schemaApi.stages() | ||
return result.data | ||
} | ||
|
||
public async stage (stage:string): Promise<Stage|undefined> { | ||
const result:AxiosResponse<Stage, any> = await this.schemaApi.stage(stage) | ||
return result.data | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { StageService } from 'lib/application' | ||
import { SchemaConfig } from '../../domain' | ||
import { StageApi } from '../api' | ||
import { AxiosResponse } from 'axios' | ||
|
||
export class StageApiService implements StageService { | ||
// eslint-disable-next-line no-useless-constructor | ||
constructor (private readonly stageApi:StageApi) {} | ||
|
||
public async exists (stage:string): Promise<boolean> { | ||
const result:AxiosResponse<boolean, any> = await this.stageApi.exists(stage) | ||
return result.data | ||
} | ||
|
||
public async export (stage:string): Promise<SchemaConfig> { | ||
const result:AxiosResponse<SchemaConfig, any> = await this.stageApi._export(stage) | ||
return result.data | ||
} | ||
|
||
public async import (stage:string, schemaData:any): Promise<void> { | ||
const result:AxiosResponse<void, any> = await this.stageApi._import(stage, schemaData) | ||
return result.data | ||
} | ||
} |
Oops, something went wrong.