Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@codeleap/query

Package Overview
Dependencies
Maintainers
2
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codeleap/query - npm Package Compare versions

Comparing version
5.8.7
to
5.8.8
+4
-4
package.json
{
"name": "@codeleap/query",
"version": "5.8.7",
"version": "5.8.8",
"main": "src/index.ts",

@@ -12,4 +12,4 @@ "license": "UNLICENSED",

"devDependencies": {
"@codeleap/config": "5.8.7",
"@codeleap/types": "5.8.7",
"@codeleap/config": "5.8.8",
"@codeleap/types": "5.8.8",
"ts-node-dev": "1.1.8"

@@ -21,3 +21,3 @@ },

"peerDependencies": {
"@codeleap/types": "5.8.7",
"@codeleap/types": "5.8.8",
"typescript": "5.5.2",

@@ -24,0 +24,0 @@ "@tanstack/react-query": "5.89.0"

import { CancelOptions, InfiniteData, InvalidateOptions, InvalidateQueryFilters, Query, QueryFilters, QueryKey, RefetchOptions, RefetchQueryFilters } from '@tanstack/react-query'
import { useMemo } from 'react'
import { TypeGuards } from '@codeleap/types'
import { ListPaginationResponse, ListSelector, PageParam, QueryClient, QueryItem } from '../types'
import { ListPaginationResponse, ListSelector, PageParam, QueryClient, QueryItem, RetrieveDataOptions } from '../types'
import deepEqual from 'fast-deep-equal'

@@ -275,8 +275,22 @@

/**
* Gets retrieve data from cache, with fallback to list data
* @param id - The ID of the item to retrieve
* @param onlyQueryData - If true, only returns data from the specific retrieve query, not from list data
* @returns The item data or undefined if not found
* Retrieves item data from cache with intelligent fallback strategies
*
* @description Searches for an item using a multi-layered approach:
* 1. Direct cache lookup using retrieve query
* 2. Fallback to itemMap from list data (shallow search)
* 3. Deep search through all paginated list queries
*
* @param {QueryItem['id']} id - The unique identifier of the item to retrieve
* @param {RetrieveDataOptions} [options] - Configuration options for retrieval behavior
* @param {boolean} [options.onlyQueryData=false] - If true, only returns data from the specific retrieve query cache, ignoring list data fallbacks
* @param {boolean} [options.deepSearch=true] - If true, performs deep search through paginated queries when item not found in direct cache or itemMap
*
* @returns Item | undefined
*/
getRetrieveData(id: QueryItem['id'], onlyQueryData = false): T | undefined {
getRetrieveData(id: QueryItem['id'], options: RetrieveDataOptions = {}): T | undefined {
const {
onlyQueryData = false,
deepSearch = false,
} = options
if (TypeGuards.isNil(id)) return undefined

@@ -288,3 +302,7 @@

if (!queryData?.id && !onlyQueryData) {
if (queryData?.id) return queryData
if (onlyQueryData) return undefined
if (!deepSearch) {
const { itemMap } = this.getListData()

@@ -295,3 +313,17 @@

return queryData
const queries = this.getAllListQueries()
for (const query of queries) {
const pages = query.state.data?.pages
if (!pages?.length) continue
const item = pages
.filter(Boolean)
.flatMap(page => Array.isArray(page) ? page : [])
.find(item => item?.id === id)
if (item) return item
}
return undefined
}

@@ -298,0 +330,0 @@

@@ -8,1 +8,6 @@ import { QueryKey, UndefinedInitialDataOptions } from '@tanstack/react-query'

>
export type RetrieveDataOptions = {
onlyQueryData?: boolean
deepSearch?: boolean
}

Sorry, the diff of this file is not supported yet