2.2.1 • Published 6 months ago

@archimedes/arch v2.2.1

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
6 months ago

@archimedes/arch

Different architectural pieces to use:

  • Use Cases
  • Commands
  • Runner
  • Links

Usage

npm i @archimedes/arch -SE

Note: If you want to use cache-link and your framework mangles the name of the classes (like Angular does) you should either disable that option or avoid using that link. For example, to disable that option in Angular when you build the application set NG_BUILD_MANGLE=false.

Runner

The runner configures a chain of responsibility which allows a use case to be processed through links. In order to create the chain you have to do this as soon as possible in your app:

Runner.createChain([loggerLink, executorLink])

You can configure the chain however you can, even dynamically:

if (isProduction) {
    Runner.createChain([executorLink])
} else {
    Runner.createChain([executorLink, loggerLink])
}

Note: The executor-link is always required, even if you use the cache-link.

Links

ExecutorLink

This link merely executes the use case. It is always needed if you want to execute the use cases.

LoggerLink

This link logs information to the console about the execution of the use case, like parameters, result and name of the use case:

BazQry
  Parameters: -
  Result:
      42

NotificationLink

This link is meant to capture errors occurred when executing a use case. This link should be placed after ExecutorLink. When an error occurs it will notify the NotificationCenter. From the UI you can subscribe to the NotificationCenter in order to show the user an error message:

import { NotificationCenter } from './notification-center'
import { Observer } from './subscriber'

class ErrorAlerter implements Observer {
    update(publisher: NotificationCenter) {
        publisher.notifications.map(x => ({
            ...x,
            message: x.message ?? 'Error'
        }))
    }
}

new NotificationCenter().register(new ErrorAlerter())

CacheLink

Cache eviction

You can automatically evict the cache of dependant use cases using the EvictCache decorator in conjunction with the cache-link link. If use case a depends on use case b, and use case b depends on use case c (abc️) if we invalidate the cache of use case a we should evict the cache of use case b and c too. We should add this decorator to all use cases we want this handled.

@EvictCache
export class AQry extends Query {
    constructor(private readonly bQry: BQry) {
        super()
    }

    async internalExecute() {
        return this.bQry.execute()
    }
}

It's important to activate emitDecoratorMetadata to true in the tsconfig.json compiler's options. See the examples directory for more information.

Cache invalidations

If you want to set that certain commands or queries invalidate the cache of other commands and queries you can set the cache invalidations the CacheInvalidations class:

CacheInvalidations.set(FooCmd.name, [BarQry.name])

You can also use these invalidation policies:

  • ALL: The use case will invalidate all the cache of all the use cases
  • NO_CACHE: The use case will never be cached
CacheInvalidations.set(FooCmd.name, [InvalidationPolicy.ALL])
2.2.1-beta.3

6 months ago

2.2.1-beta.2

6 months ago

2.2.0-beta.5

12 months ago

2.2.1

12 months ago

2.2.1-beta.1

12 months ago

2.2.0-beta.3

1 year ago

2.2.0-beta.4

1 year ago

2.2.0

1 year ago

2.2.0-beta.1

2 years ago

2.2.0-beta.2

2 years ago

2.1.1-beta.1

2 years ago

2.1.1-beta.2

2 years ago

2.1.0

2 years ago

2.0.0-beta.8

2 years ago

2.0.0-beta.7

2 years ago

2.0.0-alpha.3

2 years ago

2.0.0-alpha.0

2 years ago

2.0.0-alpha.1

2 years ago

2.0.0-alpha.2

2 years ago

2.0.0-beta.2

2 years ago

2.0.0-beta.1

2 years ago

2.0.0-beta.6

2 years ago

2.0.0-beta.5

2 years ago

2.0.1

2 years ago

2.0.0-beta.4

2 years ago

2.0.0

2 years ago

2.0.0-beta.3

2 years ago

1.0.0-beta.2

2 years ago

1.0.0-beta.3

2 years ago

1.0.0-beta.1

2 years ago

1.5.0

2 years ago

1.4.0

3 years ago

1.3.0-beta.3

3 years ago

1.4.0-beta.1

3 years ago

1.3.0-beta.2

3 years ago

1.3.0-beta.1

3 years ago

1.3.0-beta.0

3 years ago

1.3.0-alpha.0

3 years ago

1.3.0-alpha.2

3 years ago

1.3.0-alpha.1

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.0.1-alpha.69

3 years ago

0.0.1-alpha.68

3 years ago

0.0.1-alpha.70

3 years ago

0.1.2-alpha.0

3 years ago

0.0.1-alpha.38

3 years ago

0.0.1-alpha.37

3 years ago

0.0.1-alpha.27

3 years ago