Skip to content

Commit

Permalink
WIP: Rollback effect
Browse files Browse the repository at this point in the history
Port from effect-ts

Remove effect-ts

WIP: Keep moving into services

Keep moving into services
  • Loading branch information
Nick Tchayka committed Feb 28, 2023
1 parent cd5cdee commit b26c56a
Show file tree
Hide file tree
Showing 85 changed files with 5,898 additions and 4,827 deletions.
4 changes: 3 additions & 1 deletion booster.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,7 @@
"path": "tools/eslint-config"
}
],
"settings": {}
"settings": {
"cSpell.words": ["dangerize", "denormalized", "mellancholize", "mocharc", "rushx"]
}
}
7,190 changes: 4,329 additions & 2,861 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions packages/application-tester/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@
"tslib": "^2.4.0",
"ws": "7.4.5",
"@types/sinon": "10.0.0",
"sinon": "9.2.3",
"@effect-ts/core": "^0.60.4"
"sinon": "9.2.3"
},
"devDependencies": {
"@boostercloud/eslint-config": "workspace:^1.7.0",
Expand Down
145 changes: 72 additions & 73 deletions packages/application-tester/src/effect/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Effect, Has, Layer, succeedWith, Tag } from '@boostercloud/framework-types/dist/effect'
import { ShapeFn } from '@effect-ts/core/Effect'
import { SinonSpy } from 'sinon'
// import { ShapeFn } from '@effect-ts/core/Effect'
// import { SinonSpy } from 'sinon'

/*
* This module exposed testing utilities for working with Effect services in tests.
Expand Down Expand Up @@ -75,83 +74,83 @@ import { SinonSpy } from 'sinon'
* @param fakes - A record of the methods to fake. E.g. `{ cwd: fake.returns(''), exec: fake.returns('') }`.
* @return {FakeServiceUtils} - An object with the layer to use in the dependency graph, and the fakes to assert the service was called with the right parameters.
*/
export const fakeService = <T extends ShapeFn<T>>(tag: Tag<T>, fakes: Fakes<T>): FakeServiceUtils<T> => {
// Assemble the fakes into a service that returns Effects in its functions.
// We disable the `any` warning because at this point the record is empty and TS will complain
// while we assemble it. The alternative was to use a `reduce` method, but the code became much more
// contrived, while not getting too much more type safety, as all the objects were of type unknown and we
// had to cast them explicitly
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const fakeService = {} as any
// export const fakeService = <T extends ShapeFn<T>>(tag: Tag<T>, fakes: Fakes<T>): FakeServiceUtils<T> => {
// // Assemble the fakes into a service that returns Effects in its functions.
// // We disable the `any` warning because at this point the record is empty and TS will complain
// // while we assemble it. The alternative was to use a `reduce` method, but the code became much more
// // contrived, while not getting too much more type safety, as all the objects were of type unknown and we
// // had to cast them explicitly
// // eslint-disable-next-line @typescript-eslint/no-explicit-any
// const fakeService = {} as any

// Object.entries doesn't type properly the keys an values, it returns always string and unknown (yay!)
for (const [k, v] of Object.entries(fakes)) {
// We cast the value to a SinonSpy, as we know that's what we're passing in the `fakes` record.
// We don't really need to type the arguments or the return type, as that is typed by the return type
// of this function.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const fakeFunction = v as SinonSpy<any[], any>
// // Object.entries doesn't type properly the keys an values, it returns always string and unknown (yay!)
// for (const [k, v] of Object.entries(fakes)) {
// // We cast the value to a SinonSpy, as we know that's what we're passing in the `fakes` record.
// // We don't really need to type the arguments or the return type, as that is typed by the return type
// // of this function.
// // eslint-disable-next-line @typescript-eslint/no-explicit-any
// const fakeFunction = v as SinonSpy<any[], any>

// We wrap the fake function in an Effect, so the layer can be used by the functions that require this
// service. We don't need to type the arguments or the return type, as that is typed by the return type.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
fakeService[k] = (...args: any[]) => succeedWith(() => fakeFunction(...args))
}
// // We wrap the fake function in an Effect, so the layer can be used by the functions that require this
// // service. We don't need to type the arguments or the return type, as that is typed by the return type.
// // eslint-disable-next-line @typescript-eslint/no-explicit-any
// fakeService[k] = (...args: any[]) => succeedWith(() => fakeFunction(...args))
// }

// Create a layer with that service as the only dependency, we can combine it with other layers using
// `Layer.all` in the tests.
const layer = Layer.fromValue(tag)(fakeService)
// // Create a layer with that service as the only dependency, we can combine it with other layers using
// // `Layer.all` in the tests.
// const layer = Layer.fromValue(tag)(fakeService)

// Create a reset function to reset all the fakes
const reset = () => {
for (const f of Object.values(fakes)) {
const fake = f as EffectSpy<T, keyof T>
fake.resetHistory()
}
}
// // Create a reset function to reset all the fakes
// const reset = () => {
// for (const f of Object.values(fakes)) {
// const fake = f as EffectSpy<T, keyof T>
// fake.resetHistory()
// }
// }

// Return the layer, fakes, and reset function
return { layer, fakes, reset }
}
// // Return the layer, fakes, and reset function
// return { layer, fakes, reset }
// }

/**
* Utils to mock an entire service, without having to wire up the whole dependency graph.
* This is useful for unit testing, but not for integration testing.
*
* @typedef {Object} FakeServiceUtils
* @property {Layer} layer - The layer that can be used to replace the service in the dependency graph
* @property {Record<string, SinonSpy>} fakes - The fakes that can be used to assert the service was called with the right parameters
* @property {() => void} reset - A function to reset all the fakes
*/
export type FakeServiceUtils<T extends ShapeFn<T>> = {
layer: Layer.Layer<unknown, never, Has<T>>
fakes: Fakes<T>
reset: () => void
}
// /**
// * Utils to mock an entire service, without having to wire up the whole dependency graph.
// * This is useful for unit testing, but not for integration testing.
// *
// * @typedef {Object} FakeServiceUtils
// * @property {Layer} layer - The layer that can be used to replace the service in the dependency graph
// * @property {Record<string, SinonSpy>} fakes - The fakes that can be used to assert the service was called with the right parameters
// * @property {() => void} reset - A function to reset all the fakes
// */
// export type FakeServiceUtils<T extends ShapeFn<T>> = {
// layer: Layer.Layer<unknown, never, Has<T>>
// fakes: Fakes<T>
// reset: () => void
// }

/**
* Gets the result type from an Effect
*/
type EffectResult<T> =
// Disabling `any` warning because we won't be exposing this type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
T extends Effect<any, any, infer A> ? A : never
// /**
// * Gets the result type from an Effect
// */
// type EffectResult<T> =
// // Disabling `any` warning because we won't be exposing this type
// // eslint-disable-next-line @typescript-eslint/no-explicit-any
// T extends Effect<any, any, infer A> ? A : never

/**
* Type to pass fakes on the creation of a fake service.
*/
type Fakes<T extends ShapeFn<T>> = {
[key in keyof T]: EffectSpy<T, key>
}
// /**
// * Type to pass fakes on the creation of a fake service.
// */
// type Fakes<T extends ShapeFn<T>> = {
// [key in keyof T]: EffectSpy<T, key>
// }

/**
* Allows overriding fakes in test service generators
*/
export type FakeOverrides<T extends ShapeFn<T>> = Partial<Fakes<T>>
// /**
// * Allows overriding fakes in test service generators
// */
// export type FakeOverrides<T extends ShapeFn<T>> = Partial<Fakes<T>>

/**
* Spy for a specific service function
*/
type EffectSpy<T extends ShapeFn<T>, key extends keyof T> =
// eslint-disable-next-line @typescript-eslint/no-explicit-any
SinonSpy<any[], EffectResult<ReturnType<T[key]>>>
// /**
// * Spy for a specific service function
// */
// type EffectSpy<T extends ShapeFn<T>, key extends keyof T> =
// // eslint-disable-next-line @typescript-eslint/no-explicit-any
// SinonSpy<any[], EffectResult<ReturnType<T[key]>>>
7 changes: 5 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
"ora": "^3.4.0",
"ts-morph": "15.1.0",
"tslib": "^2.4.0",
"@effect-ts/core": "^0.60.4"
"semver": "^7.3.5",
"winston": "~3.8.2",
"diod": "~2.0.0"
},
"devDependencies": {
"@boostercloud/eslint-config": "workspace:^1.7.0",
Expand Down Expand Up @@ -70,7 +72,8 @@
"sinon-chai": "3.5.0",
"ts-node": "^10.9.1",
"typescript": "4.7.4",
"eslint-plugin-unicorn": "~44.0.2"
"eslint-plugin-unicorn": "~44.0.2",
"@types/semver": "5.5.0"
},
"engines": {
"node": ">=14.0.0"
Expand Down
8 changes: 7 additions & 1 deletion packages/cli/src/commands/add/projection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import * as Oclif from '@oclif/command'
import BaseCommand from '../../common/base-command'
import { HasName, HasProjection, joinParsers, parseName, parseProjectionField } from '../../services/generator/target'
import {
HasName,
HasProjection,
joinParsers,
parseName,
parseProjectionField,
} from '../../services/file-generator/target'
import { Script } from '../../common/script'
import Brand from '../../common/brand'
import { checkCurrentDirIsABoosterProject } from '../../services/project-checker'
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/add/reducer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Oclif from '@oclif/command'
import BaseCommand from '../../common/base-command'
import { HasName, HasReaction, joinParsers, parseName, parseReaction } from '../../services/generator/target'
import { HasName, HasReaction, joinParsers, parseName, parseReaction } from '../../services/file-generator/target'
import { Script } from '../../common/script'
import Brand from '../../common/brand'
import { checkCurrentDirIsABoosterProject } from '../../services/project-checker'
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/build.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { flags } from '@oclif/command'
import BaseCommand from '../common/base-command'
import { compileProject } from '../services/config-service'
import { compileProject } from '../services/user-project/config'
import { checkCurrentDirIsABoosterProject } from '../services/project-checker'
import { Script } from '../common/script'
import Brand from '../common/brand'
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/clean.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { flags } from '@oclif/command'
import BaseCommand from '../common/base-command'
import { cleanProject } from '../services/config-service'
import { cleanProject } from '../services/user-project/config'
import { checkCurrentDirIsABoosterProject } from '../services/project-checker'
import { Script } from '../common/script'
import Brand from '../common/brand'
Expand Down
8 changes: 7 additions & 1 deletion packages/cli/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
cleanDeploymentSandbox,
compileProjectAndLoadConfig,
createDeploymentSandbox,
} from '../services/config-service'
} from '../services/user-project/config'
import { BoosterConfig } from '@boostercloud/framework-types'
import { Script } from '../common/script'
import Brand from '../common/brand'
Expand Down Expand Up @@ -58,3 +58,9 @@ export default class Deploy extends BaseCommand {
return super.catch(fullError)
}
}

class RunDeploy {
constructor() {}

public async run(): Promise<void> {}
}
4 changes: 2 additions & 2 deletions packages/cli/src/commands/new/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import * as Oclif from '@oclif/command'
import BaseCommand from '../../common/base-command'
import { Script } from '../../common/script'
import Brand from '../../common/brand'
import { generate, template } from '../../services/generator'
import { generate, template } from '../../services/file-generator'
import {
HasName,
HasFields,
joinParsers,
parseName,
parseFields,
ImportDeclaration,
} from '../../services/generator/target'
} from '../../services/file-generator/target'
import * as path from 'path'
import { checkCurrentDirIsABoosterProject } from '../../services/project-checker'

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/new/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
parseFields,
parseReaction,
ImportDeclaration,
} from '../../services/generator/target'
} from '../../services/file-generator/target'
import * as path from 'path'
import { generate, template } from '../../services/generator'
import { generate, template } from '../../services/file-generator'
import { checkCurrentDirIsABoosterProject } from '../../services/project-checker'
import { classNameToFileName } from '../../common/filenames'

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/new/event-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
joinParsers,
parseEvent,
parseName,
} from '../../services/generator/target'
} from '../../services/file-generator/target'
import { Script } from '../../common/script'
import Brand from '../../common/brand'
import { checkCurrentDirIsABoosterProject } from '../../services/project-checker'
import { generate, template } from '../../services/generator'
import { generate, template } from '../../services/file-generator'
import * as path from 'path'
import { classNameToFileName } from '../../common/filenames'

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/new/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
parseName,
parseFields,
ImportDeclaration,
} from '../../services/generator/target'
import { generate, template } from '../../services/generator'
} from '../../services/file-generator/target'
import { generate, template } from '../../services/file-generator'
import * as path from 'path'
import { checkCurrentDirIsABoosterProject } from '../../services/project-checker'

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/new/read-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
ImportDeclaration,
HasProjections,
parseProjections,
} from '../../services/generator/target'
} from '../../services/file-generator/target'
import * as path from 'path'
import { generate, template } from '../../services/generator'
import { generate, template } from '../../services/file-generator'
import { checkCurrentDirIsABoosterProject } from '../../services/project-checker'
import { classNameToFileName } from '../../common/filenames'

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/new/scheduled-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as Oclif from '@oclif/command'
import BaseCommand from '../../common/base-command'
import { Script } from '../../common/script'
import Brand from '../../common/brand'
import { generate, template } from '../../services/generator'
import { HasName, joinParsers, parseName, ImportDeclaration } from '../../services/generator/target'
import { generate, template } from '../../services/file-generator'
import { HasName, joinParsers, parseName, ImportDeclaration } from '../../services/file-generator/target'
import * as path from 'path'
import { checkCurrentDirIsABoosterProject } from '../../services/project-checker'

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/new/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as Oclif from '@oclif/command'
import BaseCommand from '../../common/base-command'
import { Script } from '../../common/script'
import Brand from '../../common/brand'
import { HasFields, HasName, joinParsers, parseName, parseFields } from '../../services/generator/target'
import { generate, template } from '../../services/generator'
import { HasFields, HasName, joinParsers, parseName, parseFields } from '../../services/file-generator/target'
import { generate, template } from '../../services/file-generator'
import * as path from 'path'
import { checkCurrentDirIsABoosterProject } from '../../services/project-checker'

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/nuke.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { flags } from '@oclif/command'
import BaseCommand from '../common/base-command'
import { nukeCloudProviderResources } from '../services/provider-service'
import { compileProjectAndLoadConfig } from '../services/config-service'
import { compileProjectAndLoadConfig } from '../services/user-project/config'
import { BoosterConfig } from '@boostercloud/framework-types'
import { Script } from '../common/script'
import Brand from '../common/brand'
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/start.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { flags } from '@oclif/command'
import BaseCommand from '../common/base-command'
import { startProvider } from '../services/provider-service'
import { compileProjectAndLoadConfig } from '../services/config-service'
import { compileProjectAndLoadConfig } from '../services/user-project/config'
import { BoosterConfig } from '@boostercloud/framework-types'
import { Script } from '../common/script'
import Brand from '../common/brand'
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/synth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
cleanDeploymentSandbox,
compileProjectAndLoadConfig,
createDeploymentSandbox,
} from '../services/config-service'
} from '../services/user-project/config'
import { Script } from '../common/script'
import Brand from '../common/brand'
import { currentEnvironment, initializeEnvironment } from '../services/environment'
Expand Down
Loading

0 comments on commit b26c56a

Please sign in to comment.