Skip to content

Commit 258963c

Browse files
authored
fix(docs): a couple of things (#8)
* fix a couple of things - fix Verrou options (rename `drivers` to `stores`) - fix url of `implementing DatabaseAdapter` on Driver page - reformat tables - small typos left and right * remove extra space
1 parent 542f6ab commit 258963c

5 files changed

Lines changed: 17 additions & 17 deletions

File tree

docs/content/docs/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Accept an optional object with the following properties:
2727

2828
- `retry`: An object with the following properties:
2929
- `timeout`: The maximum time to wait for the lock to be acquired. Defaults to `Infinity`.
30-
- `delay`: The delay in miliseconds between each retry. Defaults to `250`
30+
- `delay`: The delay in milliseconds between each retry. Defaults to `250`
3131
- `attempts`: The maximum number of attempts to acquire the lock.
3232

3333
`acquire` will return a boolean indicating if the lock was acquired or not

docs/content/docs/drivers.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { redisStore } from '@verrou/core/drivers/redis'
3030
const redis = new Redis({ host: 'localhost', port: 6379 })
3131
const verrou = new Verrou({
3232
default: 'redis',
33-
drivers: {
33+
stores: {
3434
redis: {
3535
driver: redisStore({ connection: redis }),
3636
},
@@ -54,7 +54,7 @@ const lockFactory = new LockFactory(store)
5454
### Options
5555

5656
| Option | Description | Default |
57-
| ------------ | ------------------------ | ------- |
57+
|--------------|--------------------------|---------|
5858
| `connection` | An instance of `ioredis` | N/A |
5959

6060
### Implementation details
@@ -76,7 +76,7 @@ import { memoryStore } from '@verrou/core/drivers/memory'
7676

7777
const verrou = new Verrou({
7878
default: 'memory',
79-
drivers: {
79+
stores: {
8080
memory: { driver: memoryStore() },
8181
},
8282
})
@@ -140,12 +140,12 @@ const lockFactory = new LockFactory(store)
140140

141141
:::
142142

143-
The DynamoDB table will be automatically created if it does not exists. Otherwise, you can create it manually and specify the name of the table in the options.
143+
The DynamoDB table will be automatically created if it does not exist. Otherwise, you can create it manually and specify the name of the table in the options.
144144

145145
### Options
146146

147147
| Option | Description | Default |
148-
| ------------ | ----------------------------------------------------------- | ------- |
148+
|--------------|-------------------------------------------------------------|---------|
149149
| `table.name` | The name of the table that will be used to store the cache. | `cache` |
150150
| `connection` | An instance of `DynamoDBClient` | N/A |
151151

@@ -155,14 +155,14 @@ We offer several drivers to use a database as the locks store. The database stor
155155

156156
:::note
157157

158-
Note that you can easily create your own adapter by implementing the `DatabaseAdapter` interface if you are using another library not supported by Verrou. See the [documentation](/docs/advanced/custom-adapters) for more details.
158+
Note that you can easily create your own adapter by implementing the `DatabaseAdapter` interface if you are using another library not supported by Verrou. See the [documentation](/docs/custom-lock-store#create-an-adapter-for-the-databasestore) for more details.
159159

160160
:::
161161

162162
All Database drivers accept the following common options:
163163

164164
| Option | Description | Default |
165-
| ----------------- | ------------------------------------------------------------------ | -------- |
165+
|-------------------|--------------------------------------------------------------------|----------|
166166
| `tableName` | The name of the table that will be used to store the locks. | `verrou` |
167167
| `autoCreateTable` | If the table should be automatically created if it does not exist. | `true` |
168168

docs/content/docs/extend/custom_lock_store.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface LockStore {
1717

1818
Feel free to take a look at [the existing drivers](https://github.com/Julien-R44/verrou/tree/develop/src/drivers) implementations for inspiration.
1919

20-
Once you defined you driver, you can create a factory function that will be used by Verrou to create instances of your driver at runtime. The factory function must be something like this:
20+
Once you defined your driver, you can create a factory function that will be used by Verrou to create instances of your driver at runtime. The factory function must be something like this:
2121

2222
```ts
2323
import type { CreateDriverResult } from '@verrou/core/types'

docs/content/docs/introduction.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { memoryStore } from '@verrou/core/drivers/memory'
2727

2828
const verrou = new Verrou({
2929
default: 'redis',
30-
drivers: {
30+
stores: {
3131
redis: { driver: redisStore() },
3232
memory: { driver: memoryStore() }
3333
}
@@ -62,7 +62,7 @@ await lock.run(async () => {
6262

6363
Main advantage of Verrou is that it provides a consistent API across all drivers. This means that you can switch from one driver to another without having to change your code. It also means you can switch to an in-memory in your test environment, making tests faster and easier to setup (no infrastructure or anything fancy to setup).
6464

65-
Having a consistent API also means that you don't have to learn a new API when switching from one driver to another. Today, in the node ecosystem, we have different npm packages to manage locks, but they all have differents APIs and behaviors.
65+
Having a consistent API also means that you don't have to learn a new API when switching from one driver to another. Today, in the node ecosystem, we have different npm packages to manage locks, but they all have different APIs and behaviors.
6666

6767
But having a consistent API doesn't mean having a less powerful API. Verrou provides every features you would expect from a locking library, and even more.
6868

@@ -73,7 +73,7 @@ Well, locks is a very common pattern in software development. It is used to prev
7373
Let's say you are writing code for a banking system. You have a function that transfer money from one account to another. We gonna implement it very naively, and then we will see what can go wrong.
7474

7575
```ts
76-
router.get('/transfer', () => {
76+
router.get('/transfer', async () => {
7777
const fromAccount = getAccountFromDb(request.input('from'))
7878
const toAccount = getAccountFromDb(request.input('to'))
7979

@@ -108,7 +108,7 @@ As a result, we lost 100$ somewhere. And that's not good. This is what we also c
108108
They are multiple ways to solve this problem. But let's use a lock here. By adding a lock, we are preventing concurrent requests from accessing the same piece of code at the same time :
109109

110110
```ts
111-
router.get('/transfer', () => {
111+
router.get('/transfer', async () => {
112112
// Other requests will wait just here until the lock is released
113113
await verrou.createLock('transfer').run(async () => {
114114
const fromAccount = getAccountFromDb(request.input('from'))

docs/content/docs/usage.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { verrou } from './verrou.js'
1616
const lock = verrou.createLock('my-resource', '1s')
1717
```
1818

19-
The first argument is the resource/key to lock. This is an arbitrary string that will be used to identify the lock. The second argument is the duration of the lock. It can be a number of milliseconds, a string like `1s` or `1m` ( see [lukeed/ms documentation](https://github.com/lukeed/ms), or even `null` if you want to create a lock that never expires.
19+
The first argument is the resource/key to lock. This is an arbitrary string that will be used to identify the lock. The second argument is the duration of the lock. It can be a number of milliseconds, a string like `1s` or `1m` (see [lukeed/ms documentation](https://github.com/lukeed/ms)), or even `null` if you want to create a lock that never expires.
2020

2121
Note that the duration you are passing is the duration of the lease. This means that the lock will be automatically released after this duration. This is safe to always pass a duration, even if you are releasing the lock manually afterwards ( see below ). Having a duration will prevent the lock from being stuck forever if the process crashes before releasing it ( We call this a **Deadlock** ).
2222

@@ -47,7 +47,7 @@ if (await lock.acquire()) {
4747
}
4848
```
4949

50-
But we are still missing error handling. What if my `doSomething` method throws an error? The lock will never be released. To prevent this, always make sure to wrap your code with a try/catch/finaly block.
50+
But we are still missing error handling. What if my `doSomething` method throws an error? The lock will never be released. To prevent this, always make sure to wrap your code with a try/catch/finally block.
5151

5252
```ts
5353
import { verrou } from './verrou.js'
@@ -177,12 +177,12 @@ import { verrou } from './verrou.js'
177177

178178
myQueue.on('process-payment', async ({ paymentId, lock }) => {
179179
// First we **restore** the lock with the lock owner
180-
const lock = verrou.restoreLock(lock)
180+
const restoredLock = verrou.restoreLock(lock)
181181

182182
processPayment(paymentId)
183183

184184
// Then we can release it
185-
await lock.release()
185+
await restoredLock.release()
186186
})
187187
```
188188

0 commit comments

Comments
 (0)