Skip to content

Commit

Permalink
docs(architecture): fix and complete architecture docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nfroidure committed Aug 20, 2023
1 parent e97b44f commit cf99370
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 32 deletions.
67 changes: 45 additions & 22 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
## Summary

1. [Services](#1-services)
1. [Logging](#11-logging)
1. [Log](#11-log)
2. [Time](#12-time)
3. [Randomness](#13-randomness)
4. [Delaying](#14-delaying)
6. [Counter](#16-counter)
3. [Random](#13-random)
4. [Delay](#14-delay)
5. [Resolve](#15-resolve)
6. [Importer](#16-importer)
7. [Code generator](#17-code-generator)
8. [Lock](#18-lock)
9. [Counter](#19-counter)


## 1. Services
Expand All @@ -33,9 +35,9 @@ Their goal is to encapsulate unpredictible states and



### 1.1. Logging
### 1.1. Log

I prefer using a unique function with the log type
I prefer using a unique function with the `log` type
in parameter instead of several methods for each
log types. It is far easyer to mock and to assert
on logs in my tests.
Expand All @@ -49,44 +51,50 @@ If provided, I route debug messages to the `debug`

### 1.2. Time

The time service is just proxying [`Date.now`
The `time` service is just proxying [`Date.now`
](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date/now)
in a stubbable manner.

[See in context](./src/time.ts#L12-L17)



### 1.3. Randomness
### 1.3. Random

The random service is just proxying [`Math.random`
The `random` service is just proxying [`Math.random`
](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Math/random)
in a stubbable manner.

[See in context](./src/random.ts#L12-L17)



### 1.4. Delaying
### 1.4. Delay

The delay service is `setTimeout` like I would like it
The `delay` service is `setTimeout` like I would like it
to be.

[See in context](./src/delay.ts#L18-L22)



### 1.6. Counter
### 1.5. Resolve

The `counter` service provide a simple, local and
stubbable counter.
The `resolve` service is just proxying [`import.meta.resolve`
](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Operators/import.meta/resolve)
in a stubbable manner.

The count are returned asynchronously in order
to be easily maintained across several instances
if needed later via another service with the same
surface API.
[See in context](./src/resolve.ts#L8-L13)

[See in context](./src/counter.ts#L23-L32)


### 1.6. Importer

The `importer` service is just proxying [`import`
](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Operators/import)
in a stubbable manner.

[See in context](./src/importer.ts#L9-L14)



Expand All @@ -103,14 +111,29 @@ The `codeGenerator` service provide a service

### 1.8. Lock

This service allows to maintain a lock on a given resource in order
to ensure a sequential access to it in asynchronous code.
The `lock` service allows to maintain a lock on a given
resource in order to ensure a sequential access to it in
asynchronous code.

The release is done by its key and the current lock is removed. There
is no check on the fact the lock is well released. By design, it is
your responsibility to ensure you release the locks properly. That
said, it should not be hard to handle since the actual behavior of
the library makes your code run sequentially.

[See in context](./src/lock.ts#L28-L38)
[See in context](./src/lock.ts#L28-L39)



### 1.9. Counter

The `counter` service provide a simple, local and
stubbable counter.

The count are returned asynchronously in order
to be easily maintained across several instances
if needed later via another service with the same
surface API.

[See in context](./src/counter.ts#L23-L32)

2 changes: 1 addition & 1 deletion src/counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const DEFAULT_COUNTER = {
firstCount: 1,
};

/* Architecture Note #1.6: Counter
/* Architecture Note #1.9: Counter
The `counter` service provide a simple, local and
stubbable counter.
Expand Down
4 changes: 2 additions & 2 deletions src/delay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export interface DelayService {
clear: (promise: Promise<void>) => Promise<void>;
}

/* Architecture Note #1.4: Delaying
/* Architecture Note #1.4: Delay
The delay service is `setTimeout` like I would like it
The `delay` service is `setTimeout` like I would like it
to be.
*/

Expand Down
6 changes: 6 additions & 0 deletions src/importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ function noop(): void {
return undefined;
}

/* Architecture Note #1.6: Importer
The `importer` service is just proxying [`import`
](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Operators/import)
in a stubbable manner.
*/
export default singleton(autoService(initImporter)) as typeof initImporter;

export type ImporterService<M> = (path: string) => Promise<M>;
Expand Down
5 changes: 3 additions & 2 deletions src/lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ export interface LockService<K> {

/* Architecture Note #1.8: Lock
This service allows to maintain a lock on a given resource in order
to ensure a sequential access to it in asynchronous code.
The `lock` service allows to maintain a lock on a given
resource in order to ensure a sequential access to it in
asynchronous code.
The release is done by its key and the current lock is removed. There
is no check on the fact the lock is well released. By design, it is
Expand Down
4 changes: 2 additions & 2 deletions src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export type LogServiceDependencies = LogServiceConfig & {
logger: Logger;
};

/* Architecture Note #1.1: Logging
/* Architecture Note #1.1: Log
I prefer using a unique function with the log type
I prefer using a unique function with the `log` type
in parameter instead of several methods for each
log types. It is far easyer to mock and to assert
on logs in my tests.
Expand Down
4 changes: 2 additions & 2 deletions src/random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export interface RandomService {
(): number;
}

/* Architecture Note #1.3: Randomness
/* Architecture Note #1.3: Random
The random service is just proxying [`Math.random`
The `random` service is just proxying [`Math.random`
](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Math/random)
in a stubbable manner.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ function noop(): void {
return undefined;
}

/* Architecture Note #1.5: Resolve
The `resolve` service is just proxying [`import.meta.resolve`
](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Operators/import.meta/resolve)
in a stubbable manner.
*/
export default singleton(autoService(initResolve));

export type ResolveService = (
Expand Down
2 changes: 1 addition & 1 deletion src/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface TimeService {

/* Architecture Note #1.2: Time
The time service is just proxying [`Date.now`
The `time` service is just proxying [`Date.now`
](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date/now)
in a stubbable manner.
*/
Expand Down

0 comments on commit cf99370

Please sign in to comment.