Files
AFFiNE-Mirror/blocksuite/docs/api/@blocksuite/store/classes/Extension.md
renovate 883d5e6f33 chore: bump up all non-major dependencies (#11121)
This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [@capgo/inappbrowser](https://redirect.github.com/Cap-go/capacitor-inappbrowser) | [`7.6.0` -> `7.6.4`](https://renovatebot.com/diffs/npm/@capgo%2finappbrowser/7.6.0/7.6.4) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@capgo%2finappbrowser/7.6.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@capgo%2finappbrowser/7.6.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@capgo%2finappbrowser/7.6.0/7.6.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@capgo%2finappbrowser/7.6.0/7.6.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) |
| [@swc/core](https://swc.rs) ([source](https://redirect.github.com/swc-project/swc)) | [`1.11.11` -> `1.11.13`](https://renovatebot.com/diffs/npm/@swc%2fcore/1.11.11/1.11.13) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@swc%2fcore/1.11.13?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@swc%2fcore/1.11.13?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@swc%2fcore/1.11.11/1.11.13?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@swc%2fcore/1.11.11/1.11.13?slim=true)](https://docs.renovatebot.com/merge-confidence/) |
| [bullmq](https://bullmq.io/) ([source](https://redirect.github.com/taskforcesh/bullmq)) | [`5.44.2` -> `5.44.3`](https://renovatebot.com/diffs/npm/bullmq/5.44.2/5.44.3) | [![age](https://developer.mend.io/api/mc/badges/age/npm/bullmq/5.44.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/bullmq/5.44.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/bullmq/5.44.2/5.44.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/bullmq/5.44.2/5.44.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) |
| [lib0](https://redirect.github.com/dmonad/lib0) | [`0.2.99` -> `0.2.100`](https://renovatebot.com/diffs/npm/lib0/0.2.99/0.2.100) | [![age](https://developer.mend.io/api/mc/badges/age/npm/lib0/0.2.100?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/lib0/0.2.100?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/lib0/0.2.99/0.2.100?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/lib0/0.2.99/0.2.100?slim=true)](https://docs.renovatebot.com/merge-confidence/) |
| [typedoc-plugin-markdown](https://typedoc-plugin-markdown.org) ([source](https://redirect.github.com/typedoc2md/typedoc-plugin-markdown/tree/HEAD/packages/typedoc-plugin-markdown)) | [`4.5.2` -> `4.6.0`](https://renovatebot.com/diffs/npm/typedoc-plugin-markdown/4.5.2/4.6.0) | [![age](https://developer.mend.io/api/mc/badges/age/npm/typedoc-plugin-markdown/4.6.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/typedoc-plugin-markdown/4.6.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/typedoc-plugin-markdown/4.5.2/4.6.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/typedoc-plugin-markdown/4.5.2/4.6.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>Cap-go/capacitor-inappbrowser (@&#8203;capgo/inappbrowser)</summary>

### [`v7.6.4`](https://redirect.github.com/Cap-go/capacitor-inappbrowser/blob/HEAD/CHANGELOG.md#764-2025-03-24)

[Compare Source](https://redirect.github.com/Cap-go/capacitor-inappbrowser/compare/7.6.3...7.6.4)

### [`v7.6.3`](https://redirect.github.com/Cap-go/capacitor-inappbrowser/blob/HEAD/CHANGELOG.md#763-2025-03-23)

[Compare Source](https://redirect.github.com/Cap-go/capacitor-inappbrowser/compare/7.6.2...7.6.3)

### [`v7.6.2`](https://redirect.github.com/Cap-go/capacitor-inappbrowser/blob/HEAD/CHANGELOG.md#762-2025-03-23)

[Compare Source](https://redirect.github.com/Cap-go/capacitor-inappbrowser/compare/7.6.1...7.6.2)

### [`v7.6.1`](https://redirect.github.com/Cap-go/capacitor-inappbrowser/blob/HEAD/CHANGELOG.md#761-2025-03-23)

[Compare Source](https://redirect.github.com/Cap-go/capacitor-inappbrowser/compare/7.6.0...7.6.1)

</details>

<details>
<summary>swc-project/swc (@&#8203;swc/core)</summary>

### [`v1.11.13`](https://redirect.github.com/swc-project/swc/blob/HEAD/CHANGELOG.md#11113---2025-03-24)

[Compare Source](https://redirect.github.com/swc-project/swc/compare/v1.11.12...v1.11.13)

##### Features

-   **(es/minifier)** Merge alt's cons with cons ([#&#8203;10256](https://redirect.github.com/swc-project/swc/issues/10256)) ([589bcd7](589bcd70c4))

-   **(swc_core)** Expose features of `swc_parallel` ([#&#8203;10258](https://redirect.github.com/swc-project/swc/issues/10258)) ([042f19f](042f19ff66))

##### Performance

-   **(es/minifier)** Merge `expr_simplifier` into pure optimizer ([#&#8203;10202](https://redirect.github.com/swc-project/swc/issues/10202)) ([9c9b0ba](9c9b0baaac))

### [`v1.11.12`](https://redirect.github.com/swc-project/swc/blob/HEAD/CHANGELOG.md#11112---2025-03-23)

[Compare Source](https://redirect.github.com/swc-project/swc/compare/v1.11.11...v1.11.12)

##### Bug Fixes

-   **(es/minifier)** Make `inline_globals` noop by default ([#&#8203;10231](https://redirect.github.com/swc-project/swc/issues/10231)) ([b192dc8](b192dc82e6))

-   **(es/minifier)** Fix access to `GLOBALS` in char freq compute ([#&#8203;10239](https://redirect.github.com/swc-project/swc/issues/10239)) ([6286663](6286663868))

-   **(es/parser)** Fix span of wrong `await` tokens ([#&#8203;10252](https://redirect.github.com/swc-project/swc/issues/10252)) ([5c28dc3](5c28dc3964))

-   **(es/types)** Fix broken types ([#&#8203;10224](https://redirect.github.com/swc-project/swc/issues/10224)) ([540bdf8](540bdf868d))

##### Documentation

-   **(es)** Improve documentation ([#&#8203;10247](https://redirect.github.com/swc-project/swc/issues/10247)) ([549e38d](549e38db9e))

##### Features

-   **(es/fast-lexer)** Enhance identifier handling with Unicode support ([#&#8203;10226](https://redirect.github.com/swc-project/swc/issues/10226)) ([482b63a](482b63a905))

-   **(es/minifier)** Invoke IIFE into block ([#&#8203;10220](https://redirect.github.com/swc-project/swc/issues/10220)) ([c9a6c23](c9a6c23787))

-   **(es/minifier)** Remove needless blocks ([#&#8203;10234](https://redirect.github.com/swc-project/swc/issues/10234)) ([0817970](08179702bf))

-   **(swc_parallel)** Introduce `rayon` mode ([#&#8203;10237](https://redirect.github.com/swc-project/swc/issues/10237)) ([3c2213c](3c2213c829))

-   **(ts/fast-strip)** Add start/end span information ([#&#8203;10251](https://redirect.github.com/swc-project/swc/issues/10251)) ([ab39a62](ab39a62528))

-   **(ts/fast-strip)** Improve error message snippet ([#&#8203;10253](https://redirect.github.com/swc-project/swc/issues/10253)) ([f4f426c](f4f426c9c9))

-   **(ts/fast-strip)** Remove line numbers ([#&#8203;10254](https://redirect.github.com/swc-project/swc/issues/10254)) ([40e216d](40e216db82))

##### Performance

-   **(es/minifier)** Merge `dead_branch_remover` into pure optimizer ([#&#8203;10201](https://redirect.github.com/swc-project/swc/issues/10201)) ([6841523](6841523977))

</details>

<details>
<summary>taskforcesh/bullmq (bullmq)</summary>

### [`v5.44.3`](https://redirect.github.com/taskforcesh/bullmq/releases/tag/v5.44.3)

[Compare Source](https://redirect.github.com/taskforcesh/bullmq/compare/v5.44.2...v5.44.3)

##### Bug Fixes

-   **flow:** only validate pending dependencies when moving to completed ([#&#8203;3164](https://redirect.github.com/taskforcesh/bullmq/issues/3164)) ([d3c397f](d3c397fa3f))

</details>

<details>
<summary>dmonad/lib0 (lib0)</summary>

### [`v0.2.100`](https://redirect.github.com/dmonad/lib0/releases/tag/v0.2.100)

[Compare Source](https://redirect.github.com/dmonad/lib0/compare/v0.2.99...v0.2.100)

-   \[testing] properly compare objects that don't have a constructor  [`a2433fc`](https://redirect.github.com/dmonad/lib0/commit/a2433fc)
-   \[sha256] docs  [`5ee9bf2`](https://redirect.github.com/dmonad/lib0/commit/5ee9bf2)
-   Merge pull request [#&#8203;96](https://redirect.github.com/dmonad/lib0/issues/96) from jthemphill/fix-condititons-spelling  [`08fe7d5`](https://redirect.github.com/dmonad/lib0/commit/08fe7d5)
-   Fix references to nonexistent files in package.json  [`2cb51c4`](https://redirect.github.com/dmonad/lib0/commit/2cb51c4)

***

</details>

<details>
<summary>typedoc2md/typedoc-plugin-markdown (typedoc-plugin-markdown)</summary>

### [`v4.6.0`](https://redirect.github.com/typedoc2md/typedoc-plugin-markdown/blob/HEAD/packages/typedoc-plugin-markdown/CHANGELOG.md#460-2025-03-23)

[Compare Source](https://redirect.github.com/typedoc2md/typedoc-plugin-markdown/compare/typedoc-plugin-markdown@4.5.2...typedoc-plugin-markdown@4.6.0)

This release continues the effort to further align to TypeDoc’s default theme, with improvements that make the plugin more consistent and predictable.

##### Architectural Changes

-   Introduced support for TypeDoc core routers. This allows output files to be generated in the same structure as the default HTML theme, while still using the plugin’s Markdown theme.
-   Exported routers to the public API, enabling customization by other plugins.

##### Structural Changes

-   Package readme's (when "entryPointStrategy" is "packages") are now merged with the package index page producing a single entrypoint for packages with an associated readme.
    This aligns with the default theme and improves navigation.
-   To support core routers, a "Hierarchy Summary" page has been introduced to all routers. This feature is turned off by default but can be enabled by setting "includeHierarchySummary" to "true".
-   When "includeHierarchySummary" is "true", symbols with an available hierarchy now include an associated "Hierarchy" Markdown heading with a "View Summary" link as per the default theme.
-   Class constructor headings now read "Constructor". This aligns to the TypeDoc internal reflection name and fixes issues with internal anchoring not resolving correctly.

##### Minor Changes

-   Implemented support for consuming TypeDoc core routers.
-   Exported routers to public api.
-   Implemented a hierarchy summary page as per default theme.
-   Updated "Constructor" titles of classes to fix internal anchor issues.

##### Patch Changes

-   Fix incompatibility when used with "outputs" ([#&#8203;788](https://redirect.github.com/typedoc2md/typedoc-plugin-markdown/issues/788)).
-   Utilize "anchorPrefix" option to ensure unique anchors linking if required ([#&#8203;764](https://redirect.github.com/typedoc2md/typedoc-plugin-markdown/issues/764)).

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://redirect.github.com/renovatebot/renovate/discussions) if that's undesired.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/toeverything/AFFiNE).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4yMDcuMSIsInVwZGF0ZWRJblZlciI6IjM5LjIwNy4xIiwidGFyZ2V0QnJhbmNoIjoiY2FuYXJ5IiwibGFiZWxzIjpbImRlcGVuZGVuY2llcyJdfQ==-->
2025-03-24 07:19:44 +00:00

3.6 KiB

BlockSuite API Documentation


BlockSuite API Documentation / @blocksuite/store / Extension

Class: abstract Extension

Understanding Extensions

Extensions provide a way to extend the functionality of a system using dependency injection. They allow you to register services, implementations, and factories in the DI container, which can then be retrieved and used by different parts of the application.

Extensions are particularly useful for:

  • Registering different implementations for different types
  • Creating pluggable architecture where components can be added or removed
  • Managing dependencies between different parts of the application

Usage Example: Fruit Processing System

Let's consider a fruit processing system where different types of fruits need different processing methods. We'll show how to implement this using extensions.

Step 1: Define the interfaces

interface FruitProcessor {
  process(fruit: Fruit): void;
}

interface Fruit {
  type: string;
  // other properties
}

Step 2: Create a service identifier

import { createIdentifier } from '@blocksuite/global/di';

const FruitProcessorProvider = createIdentifier<FruitProcessor>('fruit-processor-provider');

Step 3: Create implementations

class AppleProcessor implements FruitProcessor {
  process(fruit: Fruit): void {
    console.log('Slicing apple');
    // Apple-specific processing
  }
}

class BananaProcessor implements FruitProcessor {
  process(fruit: Fruit): void {
    console.log('Peeling banana');
    // Banana-specific processing
  }
}

Step 4: Create an extension factory

const FruitProcessorExtension = (
  fruitType: string,
  implementation: new () => FruitProcessor
): ExtensionType => {
  return {
    setup: di => {
      di.addImpl(FruitProcessorProvider(fruitType), implementation);
    }
  };
};

Step 5: Create concrete extensions

export const AppleProcessorExtension = FruitProcessorExtension('apple', AppleProcessor);
export const BananaProcessorExtension = FruitProcessorExtension('banana', BananaProcessor);

Step 6: Use the extensions

import { Container } from '@blocksuite/global/di';

class FruitProcessingSystem {
  provider: ServiceProvider;

  constructor(extensions: ExtensionType[]) {
    const container = new Container();

    // Set up all extensions
    extensions.forEach(ext => ext.setup(container));

    // Create a provider from the container
    this.provider = container.provider();
  }

  processFruit(fruit: Fruit) {
    // Get the appropriate processor based on fruit type
    const processor = this.provider.get(FruitProcessorProvider(fruit.type));

    // Process the fruit
    processor.process(fruit);
  }
}

// Initialize the system with extensions
const system = new FruitProcessingSystem([
  AppleProcessorExtension,
  BananaProcessorExtension
]);

// Use the system
system.processFruit({ type: 'apple' });  // Output: Slicing apple
system.processFruit({ type: 'banana' }); // Output: Peeling banana

Note: We deliberately used a non-block specific example here. In BlockSuite, the extension pattern can be applied to any entity that can be configured by third parties, not just blocks. This includes different tools in the whiteboard, different column types in database blocks, and many other extensible components. The pattern remains the same regardless of what you're extending.

Extended by