π usePluginApi β Plugin API Access Composable β
The usePluginApi composable is the entry point to all plugin APIs.
It provides access to:
$dataβ backend communication$storeβ state management$socketβ real-time events$eventbusβ internal/global communication$logβ structured logging
π§ Core Concept β
const { $data, $store, $socket, $eventbus, $log } = usePluginApi()- Automatically resolves the current plugin context
- Returns scoped API instances
- Can access other plugins
- Allows custom query identification via
actionId
π§ Basic Usage β
import { usePluginApi } from "@raclettejs/core/orchestrator/composables"const { $data } = usePluginApi()π Multiple Instances β
const { $data } = usePluginApi()
const { $data: $globalData } = usePluginApi("raclette__core")π Accessing Other Plugins β
const { $data: $globalData } = usePluginApi("raclette__core")
$globalData.tag.getAll({
params: { isDeleted: false },
})Behavior β
- Uses API of another plugin
- Keeps your
$logcontext - Prevents unintended cross-plugin side effects
βοΈ Parameters β
usePluginApi(params)Type β
type PluginApiParams = {
actionId?: string
$data?: boolean
$store?: boolean
$eventbus?: boolean
$socket?: boolean
pluginKey?: string
}π§© Parameter Usage β
pluginKey β
If you only provide a string as param to usePluginApi, it will be interpreted as a pluginKey
usePluginApi("raclette__core")or
usePluginApi({ pluginKey: "raclette__core" })π actionId β Query Identification (Part 1) β
The actionId defines a base identifier for all $data queries executed from this API instance.
π Default Query ID β
Without actionId, a query ID looks like:
plugin-pacifico__example-todo-116-todo-getAll-b84NStructure:
plugin-<pluginKey>-<instanceId>-<model>-<action>-<nanoId>Example:
plugin-raclette__core-116-tag-getAll-U5RsβοΈ With actionId β
const { $data } = usePluginApi({
actionId: "test",
})Result:
plugin-pacifico__example-todo-test-p5EFWhat changes? β
Replaces:
instanceIdmodelaction
Becomes a custom base identifier
Still appends a random nanoId
π id in $data Calls β Query Identification (Part 2) β
To fully control the query ID, you must also set id in the $data call.
$data.example.getAll({
params: {...},
id: "myFixedId",
})π― Final Query ID Behavior β
| Setup | Result |
|---|---|
no actionId, no id | fully auto-generated |
actionId only | custom base + random nanoId |
actionId + id | fully controlled query ID |
β Fully Controlled Example β
const { $data } = usePluginApi({
actionId: "todoList",
})
$data.todo.getAll({
params: { isDeleted: true },
id: "archive",
})Result:
plugin-pacifico__example-todo-todoList-archiveπ― Why This Matters β
Stable Query IDs β
- predictable store entries
- easier debugging
Shared Queries β
Multiple components can reference the same query
Cache Control β
Avoid duplicate or fragmented cache entries
Debugging β
Readable and meaningful identifiers:
plugin-myPlugin-todoList-mainβ οΈ Important Notes β
actionIdaffects all queries from this API instanceidoverrides the final nanoId- Without
id, randomness still exists - Use both together for full control
π§ Mental Model β
usePluginApiβ defines query namespaceactionIdβ defines query groupidβ defines specific query instance
π Typical Patterns β
Default usage β
const { $data } = usePluginApi()Stable queries β
const { $data } = usePluginApi({
actionId: "todoList",
})
$data.todo.getAll({
id: "main",
})Cross-plugin with control β
const { $data } = usePluginApi({
pluginKey: "raclette__core",
actionId: "coreTags",
})
$data.tag.getAll({
id: "all",
})βοΈ When to Use actionId + id β
Use them when you need:
- stable query identifiers
- shared queries across components
- precise cache control
- better debugging
π« Important Constraints β
- Must be used inside
setup() - Overusing fixed IDs can cause collisions
- Default behavior is fine for most cases
π§ Key Takeaway β
usePluginApi gives you access to all plugin APIs
π actionId + id give you full control over how your queries are identified, cached, and shared