Skip to content

Commit

Permalink
feat: show result in stages commands
Browse files Browse the repository at this point in the history
#0
  • Loading branch information
FlavioLionelRita committed May 9, 2024
1 parent b3d2ad9 commit 3dd4e71
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 31 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"json-light": "^1.0.11",
"3xpr": "^1.15.23",
"lambdaorm-client-node": "^0.7.44",
"lambdaorm": "^2.1.0",
"lambdaorm": "^2.2.0",
"dotenv": "^16.3.1",
"js-yaml": "^4.1.0",
"mongodb": "^6.6.1",
Expand Down
13 changes: 7 additions & 6 deletions src/lib/application/ports/orm.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable @typescript-eslint/ban-types */
import {
QueryPlan, QueryOptions, Metadata, MetadataModel, MetadataConstraint, MetadataParameter
, DomainSchema, SchemaData, Entity, Enum, Schema, Mapping, EntityMapping, Stage
, DomainSchema, SchemaData, Entity, Enum, Schema, Mapping, EntityMapping, Stage,
ExecuteResult
} from 'lambdaorm'

export interface CliSchemaService {
Expand Down Expand Up @@ -29,11 +30,11 @@ export interface CliStageService {
export (stage:string, force: boolean): Promise<SchemaData>
import (stage:string, schemaData:any): Promise<void>
fetch (stage:string): Promise<Mapping[]>
introspect (data: any, name:string, stage?: string): Promise<void>
incorporate (data: any, name:string, stage?: string): Promise<void>
pull (stage: string): Promise<void>
drop (stage: string, sentence: boolean, force:boolean): Promise<any>
push (stage: string, sentence: boolean, force:boolean): Promise<any>
introspect (data: any, name:string, stage?: string): Promise<ExecuteResult[]>
incorporate (data: any, name:string, stage?: string): Promise<ExecuteResult[]>
pull (stage: string): Promise<ExecuteResult[]>
drop (stage: string, sentence: boolean, force:boolean): Promise<ExecuteResult[]>
push (stage: string, sentence: boolean, force:boolean): Promise<ExecuteResult[]>
}
export interface BuildArgs {
workspace:string
Expand Down
11 changes: 11 additions & 0 deletions src/lib/application/services/outputService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { JsonLight } from 'json-light'
import { ExecuteResult } from 'lambdaorm'
const yaml = require('js-yaml')

export class OutputService {
Expand All @@ -25,4 +26,14 @@ export class OutputService {
console.error(`error: ${error}`)
}
}

public showExecuteResult (results:ExecuteResult[]) {
results.forEach((result) => {
if (result.error) {
console.error(`${result.description}: ${result.error}`)
} else {
console.log(`${result.description}: ${result.result}`)
}
})
}
}
2 changes: 1 addition & 1 deletion src/lib/application/useCases/drop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class Drop {
await orm.init()
const stageName = await orm.getStageName(stage)
const result = await orm.stage.drop(stageName, _output, force)
console.log(JSON.stringify(result, null, 2))
this.service.output.showExecuteResult(result)
} catch (error) {
console.error(`error: ${error}`)
} finally {
Expand Down
3 changes: 2 additions & 1 deletion src/lib/application/useCases/incorporate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export class Incorporate {
await orm.init()
const _data = await this.service.helper.cli.readData(data)
const _name = name || this.service.helper.cli.nameFromFile(data)
await orm.stage.incorporate(_data, _name, stage)
const result = await orm.stage.incorporate(_data, _name, stage)
this.service.output.showExecuteResult(result)
} catch (error) {
console.error(`error: ${error}`)
} finally {
Expand Down
3 changes: 2 additions & 1 deletion src/lib/application/useCases/introspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export class Introspect {
await orm.init()
const _data = await this.service.helper.cli.readData(data)
const _name = name || this.service.helper.cli.nameFromFile(data)
await orm.stage.introspect(_data, _name, stage)
const result = await orm.stage.introspect(_data, _name, stage)
this.service.output.showExecuteResult(result)
} catch (error) {
console.error(`error: ${error}`)
} finally {
Expand Down
3 changes: 2 additions & 1 deletion src/lib/application/useCases/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export class Pull {
try {
await orm.init()
const stageName = await orm.getStageName(stage)
await orm.stage.pull(stageName)
const result = await orm.stage.pull(stageName)
this.service.output.showExecuteResult(result)
} catch (error) {
console.error(`error: ${error}`)
} finally {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/application/useCases/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class Push {
await orm.init()
const stageName = await orm.getStageName(stage)
const result = await orm.stage.push(stageName, _output, force)
console.log(result)
this.service.output.showExecuteResult(result)
} catch (error) {
console.error(`error: ${error}`)
} finally {
Expand Down
23 changes: 12 additions & 11 deletions src/lib/infrastructure/orm/adapters/lib.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
MetadataModel, MetadataParameter, MetadataConstraint, Metadata, QueryOptions, QueryPlan, IOrm, DomainSchema, Entity, EntityMapping
, Enum, Mapping, Schema, Stage, SchemaData, Orm, SchemaState
, Enum, Mapping, Schema, Stage, SchemaData, Orm, SchemaState,
ExecuteResult
} from 'lambdaorm'
import { OrmService, CliSchemaService, CliStageService } from '../../../application'

Expand Down Expand Up @@ -89,16 +90,16 @@ export class LibStageService implements CliStageService {
return this.orm.stage.fetch({ stage })
}

public async pull (stage: string): Promise<void> {
await this.orm.stage.pull({ stage })
public async pull (stage: string): Promise<ExecuteResult[]> {
return this.orm.stage.pull({ stage })
}

public async introspect (data: any, name:string, stage?: string): Promise<void> {
await this.orm.stage.introspect(data, name, { stage })
public async introspect (data: any, name:string, stage?: string): Promise<ExecuteResult[]> {
return this.orm.stage.introspect(data, name, { stage })
}

public async incorporate (data: any, name:string, stage?: string): Promise<void> {
await this.orm.stage.incorporate(data, name, { stage })
public async incorporate (data: any, name:string, stage?: string): Promise<ExecuteResult[]> {
return this.orm.stage.incorporate(data, name, { stage })
}

public async export (stage: string, force: boolean): Promise<SchemaData> {
Expand All @@ -109,15 +110,15 @@ export class LibStageService implements CliStageService {
return this.orm.stage.import({ stage }).execute(schemaData)
}

public async drop (stage: string, sentence: boolean, force:boolean): Promise<any> {
public async drop (stage: string, sentence: boolean, force:boolean): Promise<ExecuteResult[]|any[]> {
if (sentence) {
return await this.orm.stage.drop({ stage }).sentence()
} else {
return await this.orm.stage.drop({ stage, tryAllCan: force }).execute()
}
}

public async push (stage: string, sentence: boolean, force:boolean): Promise<any> {
public async push (stage: string, sentence: boolean, force:boolean): Promise<ExecuteResult[]|any[]> {
const schema = await this.orm.state.load(this.workspace)
if (schema === null) {
throw new Error(`Can't found schema in ${this.workspace}`)
Expand All @@ -136,9 +137,9 @@ export class LibOrmService implements OrmService {
private _stage?: CliStageService
private readonly orm: IOrm
public constructor (private readonly workspace:string) {
this.orm = new Orm(workspace)
this.orm = new Orm()
this._schema = new LibSchemaService(this.orm.state)
this._stage = new LibStageService(this.orm, workspace)
this._stage = new LibStageService(this.orm, this.workspace)
}

public async init (): Promise<any> {
Expand Down
9 changes: 5 additions & 4 deletions src/lib/infrastructure/orm/adapters/rest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import {
MetadataModel, MetadataParameter, MetadataConstraint, Metadata, QueryOptions, QueryPlan, DomainSchema, Entity, Enum, Mapping, SchemaData, Schema, EntityMapping, Stage
MetadataModel, MetadataParameter, MetadataConstraint, Metadata, QueryOptions, QueryPlan, DomainSchema, Entity, Enum, Mapping, SchemaData, Schema, EntityMapping, Stage,
ExecuteResult
} from 'lambdaorm'
import { OrmService, CliSchemaService, CliStageService } from '../../../application/ports/orm'
import * as client from 'lambdaorm-client-node'
Expand Down Expand Up @@ -94,19 +95,19 @@ export class ClientStageService implements CliStageService {
return this.stageService.import(stage, schemaData)
}

public introspect (data: any, name: string, stage?: string | undefined): Promise<void> {
public introspect (data: any, name: string, stage?: string | undefined): Promise<ExecuteResult[]> {
throw new Error('Functionality not support by rest client.')
}

public incorporate (data: any, name: string, stage?: string | undefined): Promise<void> {
public incorporate (data: any, name: string, stage?: string | undefined): Promise<ExecuteResult[]> {
throw new Error('Functionality not support by rest client.')
}

public fetch (stage: string): Promise<Mapping[]> {
throw new Error('Functionality not support by rest client.')
}

public pull (stage: string): Promise<void> {
public pull (stage: string): Promise<ExecuteResult[]> {
throw new Error('Functionality not support by rest client.')
}

Expand Down

0 comments on commit 3dd4e71

Please sign in to comment.