Skip to main content

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:

  • Preconfigured Vitest test cases
  • Common edge case coverage

Usage example:

// filename: MyLockAdapter.test.ts

import { beforeEach, describe, expect, test } from "vitest";
import { lockAdapterTestSuite } from "eridu-tech/lock/test-utilities";
import { MemoryLockAdapter } from "./MemoryLockAdapter.js";

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:

  • Preconfigured Vitest test cases
  • Standardized lock factory behavior validation
  • Common edge case coverage

Usage example:

// filename: MyLockFactory.test.ts

import { beforeEach, describe, expect, test } from "vitest";
import { lockFactoryTestSuite } from "eridu-tech/lock/test-utilities";
import { MyLockFactory } from "./MyLockFactory.js";

describe("class: MyLockFactory", () => {
lockFactoryTestSuite({
createLockFactory: () => new MyLockFactory(),
test,
beforeEach,
expect,
describe,
});
});

Further information

For further information refer to eridu-tech/lock API docs.