Skip to content

Commit

Permalink
fix(library): solve create library
Browse files Browse the repository at this point in the history
#201
  • Loading branch information
FlavioLionelRita committed Nov 28, 2023
1 parent 8de6548 commit 70ce19d
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 76 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ All notable changes to this project will be documented in this file.
* **release:** update grunt dist task ([ef973c0](https://github.com/FlavioLionelRita/lambdaorm-client-node/commit/ef973c0967458bfbdbc2e2cfbde2bacc571ae82d)), closes [#176](https://github.com/FlavioLionelRita/lambdaorm/issues/176)

### [0.7.5](https://github.com/FlavioLionelRita/lambdaorm-client-node/compare/v0.7.4...v0.7.5) (2023-11-06)

**Features:**

* add release github workflow ([22aa4db](https://github.com/FlavioLionelRita/lambdaorm/commit/22aa4dba0c22578f80bb95a4f04ae5a4f3e8da0d)), closes [#176](https://github.com/FlavioLionelRita/lambdaorm/issues/176)
Expand Down
123 changes: 68 additions & 55 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 11 additions & 7 deletions src/lib/infrastructure/adapters/ExpressionApiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class ExpressionApiService implements ExpressionService {
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 _expression = typeof expression !== 'string' ? this.toExpression(expression) : expression
const result:AxiosResponse<MetadataModel[], any> = await this.expressionApi.model({ expression: _expression })
return result.data
}
Expand All @@ -31,7 +31,7 @@ export class ExpressionApiService implements ExpressionService {
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 _expression = typeof expression !== 'string' ? this.toExpression(expression) : expression
const result:AxiosResponse<MetadataParameter[], any> = await this.expressionApi.parameters({ expression: _expression })
return result.data
}
Expand All @@ -44,7 +44,7 @@ export class ExpressionApiService implements ExpressionService {
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 _expression = typeof expression !== 'string' ? this.toExpression(expression) : expression
const result:AxiosResponse<MetadataConstraint, any> = await this.expressionApi.constraints({ expression: _expression })
return result.data
}
Expand All @@ -57,7 +57,7 @@ export class ExpressionApiService implements ExpressionService {
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 _expression = typeof expression !== 'string' ? this.toExpression(expression) : expression
const result:AxiosResponse<Metadata, any> = await this.expressionApi.metadata({ expression: _expression })
return result.data
}
Expand All @@ -70,7 +70,7 @@ export class ExpressionApiService implements ExpressionService {
public async plan(expression: Function, options?: QueryOptions): Promise<MetadataPlan>;
public async plan(expression: string, options?: QueryOptions): Promise<MetadataPlan>;
public async plan (expression: string|Function, options: QueryOptions|undefined): Promise<MetadataPlan> {
const _expression = typeof expression !== 'string' ? expressions.toExpression(expression) : expression
const _expression = typeof expression !== 'string' ? this.toExpression(expression) : expression
const _options = this.solveOptions(options)
const result:AxiosResponse<MetadataPlan, any> = await this.expressionApi.plan({ expression: _expression, options: _options })
return result.data
Expand All @@ -86,7 +86,7 @@ export class ExpressionApiService implements ExpressionService {
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 _expression = typeof expression !== 'string' ? this.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
Expand All @@ -102,12 +102,16 @@ export class ExpressionApiService implements ExpressionService {
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 _expression = typeof expression !== 'string' ? this.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 toExpression (expression:string|Function):string {
return typeof expression !== 'string' ? expressions.convert(expression, 'function')[0] : expression
}

private solveOptions (options?: QueryOptions):QueryOptions {
if (!options) {
options = {}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/infrastructure/adapters/orm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class Orm implements IOrm {
if (host) {
this.host = host
}
new SentenceLibrary(expressions.model).load()
new SentenceLibrary(expressions).load()
this.configuration = new Configuration({ basePath: this.host })
this.expressionService = new ExpressionApiService(new ExpressionApi(this.configuration))
this.generalService = new GeneralApiService(new GeneralApi(this.configuration))
Expand Down
26 changes: 13 additions & 13 deletions src/lib/infrastructure/library.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { IModelManager } from '3xpr'
import { Expressions } from '3xpr'
const CryptoJS = require('crypto-js')

export class SentenceLibrary {
// eslint-disable-next-line no-useless-constructor
public constructor (private readonly model:IModelManager) {}
public constructor (private readonly expressions:Expressions) {}

public load ():void {
this.functions()
}

private functions (): void {
this.model.addFunction('toBase64(value:string):string', (value: string):string => CryptoJS.enc.Base64.parse(value))
this.model.addFunction('getBase64(value:string):string', (value: string): string => CryptoJS.enc.Base64.stringify(value))
this.model.addFunction('encrypt(value:string):string', (value: string, key:string):string => CryptoJS.AES.encrypt(value, key).toString())
this.model.addFunction('decrypt(value:string):string', (value: string, key:string):string => {
this.expressions.addFunction('toBase64(value:string):string', (value: string):string => CryptoJS.enc.Base64.parse(value))
this.expressions.addFunction('getBase64(value:string):string', (value: string): string => CryptoJS.enc.Base64.stringify(value))
this.expressions.addFunction('encrypt(value:string):string', (value: string, key:string):string => CryptoJS.AES.encrypt(value, key).toString())
this.expressions.addFunction('decrypt(value:string):string', (value: string, key:string):string => {
const bytes = CryptoJS.AES.decrypt(value, key)
return bytes.toString(CryptoJS.enc.Utf8)
})
this.model.addFunction('update(list: any[], predicate: any):any', ():void => { throw new Error('NotImplemented') })
this.model.addFunction('updateAll(list: any[], predicate: any):any', ():void => { throw new Error('NotImplemented') })
this.model.addFunction('deleteAll(list: any[]):any', ():void => { throw new Error('NotImplemented') })
this.model.addFunction('having(list: T[], predicate: boolean):T[]', ():void => { throw new Error('NotImplemented') })
this.model.addFunction('include(list: any[], predicate: any):any', ():void => { throw new Error('NotImplemented') })
this.model.addFunction('desc(value:any):void', ():void => { throw new Error('NotImplemented') })
this.model.addFunction('asc(value:any):void', ():void => { throw new Error('NotImplemented') })
this.expressions.addFunction('update(list: any[], predicate: any):any', ():void => { throw new Error('NotImplemented') })
this.expressions.addFunction('updateAll(list: any[], predicate: any):any', ():void => { throw new Error('NotImplemented') })
this.expressions.addFunction('deleteAll(list: any[]):any', ():void => { throw new Error('NotImplemented') })
this.expressions.addFunction('having(list: T[], predicate: boolean):T[]', ():void => { throw new Error('NotImplemented') })
this.expressions.addFunction('include(list: any[], predicate: any):any', ():void => { throw new Error('NotImplemented') })
this.expressions.addFunction('desc(value:any):void', ():void => { throw new Error('NotImplemented') })
this.expressions.addFunction('asc(value:any):void', ():void => { throw new Error('NotImplemented') })
}
}

0 comments on commit 70ce19d

Please sign in to comment.