Creating shared-lock adapters
Implementing your custom ISharedLockAdapter
In order to create an adapter you need to implement the ISharedLockAdapter contract.
Testing your custom ISharedLockAdapter
We provide a complete test suite to test your shared-lock adapter implementation. Simply use the sharedLockAdapterTestSuite function:
- Preconfigured Vitest test cases
- Common edge case coverage
Usage example:
// filename: MySharedLockAdapter.test.ts
import { beforeEach, describe, expect, test } from "vitest";
import { sharedLockAdapterTestSuite } from "@daiso-tech/core/shared-lock/test-utilities";
import { MemorySharedLockAdapter } from "./MemorySharedLockAdapter.js";
describe("class: MySharedLockAdapter", () => {
sharedLockAdapterTestSuite({
createAdapter: () => new MemorySharedLockAdapter(),
test,
beforeEach,
expect,
describe,
});
});
Implementing your custom IDatabaseSharedLockAdapter
We provide an additional contract IDatabaseSharedLockAdapter for building custom shared-lock adapters tailored to databases.
Testing your custom IDatabaseSharedLockAdapter
We provide a complete test suite to test your database shared-lock adapter implementation. Simply use the databaseSharedLockAdapterTestSuite function:
- Preconfigured Vitest test cases
- Common edge case coverage
Usage example:
import { beforeEach, describe, expect, test } from "vitest";
import { databaseSharedLockAdapterTestSuite } from "@daiso-tech/core/shared-lock/test-utilities";
import { MyDatabaseSharedLockAdapter } from "./MyDatabaseSharedLockAdapter.js";
describe("class: MyDatabaseSharedLockAdapter", () => {
databaseSharedLockAdapterTestSuite({
createAdapter: async () => {
return new MyDatabaseSharedLockAdapter(),
},
test,
beforeEach,
expect,
describe,
});
});
Implementing your custom ISharedLockProvider class
In some cases, you may need to implement a custom SharedLockProvider class to optimize performance for your specific technology stack. You can then directly implement the ISharedLockProvider contract.
Testing your custom ISharedLockProvider class
We provide a complete test suite to verify your custom event bus class implementation. Simply use the sharedLockProviderTestSuite function:
- Preconfigured Vitest test cases
- Standardized event bus behavior validation
- Common edge case coverage
Usage example:
// filename: MySharedLockProvider.test.ts
import { beforeEach, describe, expect, test } from "vitest";
import { sharedLockProviderTestSuite } from "@daiso-tech/core/shared-lock/test-utilities";
import { MySharedLockProvider } from "./MySharedLockProvider.js";
describe("class: MySharedLockProvider", () => {
sharedLockProviderTestSuite({
createSharedLockProvider: () => new MySharedLockProvider(),
test,
beforeEach,
expect,
describe,
});
});
Further information
For further information refer to @daiso-tech/core/shared-lock API docs.