Skip to content

Commit

Permalink
feat(types): expose QueryCache
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Jan 31, 2025
1 parent 542e15e commit fb4c647
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
12 changes: 11 additions & 1 deletion docs/advanced/plugins.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Plugins
# Plugins

::: warning

Expand Down Expand Up @@ -32,3 +32,13 @@ export function PiniaColadaDebugPlugin(
}
}
```

## Cache Keys

The cache keys are used to identify queries in the cache. The `key` passed to queries get serialized deterministically with the `toCacheKey()` function. You can use this function in plugins if you needed:

```ts twoslash
import { toCacheKey } from '@pinia/colada'

const key = toCacheKey(['users', 1, { type: 'friends' }])
```
2 changes: 1 addition & 1 deletion plugins/delay/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import type { ShallowRef } from 'vue'
import { customRef, shallowRef } from 'vue'
import type { PiniaColadaPlugin, AsyncStatus } from '@pinia/colada'
import { type PiniaColadaPlugin, type AsyncStatus, toCacheKey } from '@pinia/colada'

/**
* Options for the {@link PiniaColadaDelay} plugin.
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export {

export {
hydrateQueryCache,
type QueryCache,
reviveTreeMap,
serialize,
serializeQueryCache,
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export function stringifyFlatObject(obj: _ObjectFlat | _JSONPrimitive): string {
}

/**
* Creates a {@link QueryCache['caches']} key from an entry's {@link UseQueryOptions['key']}.
* Creates a {@link QueryCache}'s `caches` key from an entry's {@link UseQueryOptions#key}.
* @param key - key of the entry
*/
export const toCacheKey = (key: EntryKey): EntryNodeKey[] => key.map(stringifyFlatObject)
Expand Down

0 comments on commit fb4c647

Please sign in to comment.