Creating Lock adapters
Implementing your custom ILockAdapter
In order to create an adapter you need to implement the ILockAdapter contract.
Testing your custom ILockAdapter
We provide a complete test suite to test your lock adapter implementation. Simply use the lockAdapterTestSuite function:
The suite provides preconfigured Vitest test cases with common edge case coverage and standardized lock adapter contract conformance testing.
Usage example:
import { beforeEach, describe, expect, test } from "vitest";
import { lockAdapterTestSuite } from "eridu-tech/lock/test-utilities";
import { MemoryLockAdapter } from "eridu-tech/lock/memory-lock-adapter";
describe("class: MyLockAdapter", () => {
lockAdapterTestSuite({
createAdapter: () => new MemoryLockAdapter(),
test,
beforeEach,
expect,
describe,
});
});
Implementing your custom ILockFactory class
In some cases, you may need to implement a custom LockFactory class to optimize performance for your specific technology stack. You can then directly implement the ILockFactory contract.
Testing your custom ILockFactory class
We provide a complete test suite to verify your custom lock factory class implementation. Simply use the lockFactoryTestSuite function:
The suite provides preconfigured Vitest test cases with common edge case coverage and standardized lock factory contract conformance testing.
Usage example:
import { beforeEach, describe, expect, test } from "vitest";
import { lockFactoryTestSuite } from "eridu-tech/lock/test-utilities";
import { LockFactory } from "eridu-tech/lock";
import { MemoryLockAdapter } from "eridu-tech/lock/memory-lock-adapter";
import { Serde } from "eridu-tech/serde";
import { SuperJsonSerdeAdapter } from "eridu-tech/serde/super-json-serde-adapter";
describe("class: MyLockFactory", () => {
lockFactoryTestSuite({
createLockFactory: () => ({
lockFactory: new LockFactory({
adapter: new MemoryLockAdapter(),
}),
serde: new Serde(new SuperJsonSerdeAdapter()),
}),
test,
beforeEach,
expect,
describe,
});
});
Further information
For further information refer to eridu-tech/lock API docs.