@@ -2,25 +2,16 @@ import 'server-only'
22import type { SessionPrincipal } from '@sim/auth/principal'
33import { type DehydratedState , dehydrate } from '@tanstack/react-query'
44import { listSearchHistoryContract } from '@/lib/api/contracts/knowledge/search-history'
5- import { listSearchIntegrationsContract } from '@/lib/api/contracts/knowledge/search-integrations'
6- import { getOrganizationAccountsContract } from '@/lib/api/contracts/organization-accounts'
75import { getSecretSourceContract } from '@/lib/api/contracts/organization-secrets'
86import { listSimLinksContract } from '@/lib/api/contracts/sim-links'
97import { presentSimLinkPage } from '@/lib/api/server/sim-link-presenters'
108import { withinDeadline } from '@/lib/core/utils/deadline'
11- import { getOrganizationAccountsSettings } from '@/lib/credential-groups/application/organization-accounts'
12- import { canReadMemberIntegrations } from '@/lib/credential-groups/member-integrations'
139import { listSearchHistory } from '@/lib/knowledge/application/search-history'
14- import { listSearchIntegrations } from '@/lib/knowledge/application/search-integrations'
1510import { readOrganizationSecretSource } from '@/lib/organization-secrets/application/use-cases'
1611import { listSimLinks } from '@/lib/sim-links/application/use-cases'
1712import type { SimLinkSort } from '@/lib/sim-links/validation'
1813import type { SortDirection } from '@/lib/url-state'
1914import { makeQueryClient } from '@/app/_shell/providers/get-query-client'
20- import {
21- ORGANIZATION_ACCOUNTS_STALE_TIME ,
22- organizationAccountsKeys ,
23- } from '@/hooks/queries/utils/organization-accounts-keys'
2415import {
2516 ORGANIZATION_SECRET_STALE_TIME ,
2617 organizationSecretKeys ,
@@ -29,10 +20,6 @@ import {
2920 SEARCH_HISTORY_STALE_TIME ,
3021 searchHistoryKeys ,
3122} from '@/hooks/queries/utils/search-history-keys'
32- import {
33- SEARCH_INTEGRATIONS_STALE_TIME ,
34- searchIntegrationKeys ,
35- } from '@/hooks/queries/utils/search-integration-keys'
3623import { SIM_LINKS_STALE_TIME , simLinkKeys } from '@/hooks/queries/utils/sim-link-keys'
3724
3825/** A slow read gives up its first-paint seat rather than hold the document; the client fetches it. */
@@ -42,10 +29,6 @@ function withinBudget<T>(read: () => Promise<T>) {
4229 return ( ) => withinDeadline ( read , Date . now ( ) + PREFETCH_TIMEOUT_MS )
4330}
4431
45- type PrefetchSurface = Parameters < typeof canReadMemberIntegrations > [ 0 ] & {
46- organization : { id : string }
47- }
48-
4932interface SimLinksListView {
5033 search : string
5134 sort : SimLinkSort
@@ -56,35 +39,17 @@ interface SimLinksListView {
5639 * The cheap reads behind first paint. Each runs its route's use case and contract schema under its
5740 * hook's key, together rather than in turn. A failed or slow read stays out of hydration for the
5841 * client to retry, and a read the route would refuse this viewer fails the same way here.
42+ *
43+ * Keep these light, since each lands in its route's server graph: the member inventory, which reaches
44+ * the block and tool registries, is apart in `prefetch-member-inventory.ts`.
5945 */
60- function createSeeds ( organizationId : string , principal : SessionPrincipal ) {
46+ export function createSeeds ( organizationId : string , principal : SessionPrincipal ) {
6147 const queryClient = makeQueryClient ( )
6248 const input = { organizationId }
6349 const seed = < T > ( queryKey : readonly unknown [ ] , staleTime : number , read : ( ) => Promise < T > ) =>
6450 queryClient . prefetchQuery ( { queryKey, staleTime, queryFn : withinBudget ( read ) } )
6551 return {
66- memberInventory : ( surface : PrefetchSurface ) =>
67- canReadMemberIntegrations ( surface )
68- ? [
69- seed (
70- organizationAccountsKeys . detail ( organizationId ) ,
71- ORGANIZATION_ACCOUNTS_STALE_TIME ,
72- async ( ) =>
73- getOrganizationAccountsContract . response . schema . parse (
74- await getOrganizationAccountsSettings . execute ( { principal, input } )
75- )
76- ) ,
77- seed (
78- searchIntegrationKeys . list ( organizationId ) ,
79- SEARCH_INTEGRATIONS_STALE_TIME ,
80- async ( ) =>
81- listSearchIntegrationsContract . response . schema . parse ( {
82- success : true ,
83- data : await listSearchIntegrations . execute ( { principal, input } ) ,
84- } ) . data
85- ) ,
86- ]
87- : [ ] ,
52+ seed,
8853 searchHistory : ( ) =>
8954 seed (
9055 searchHistoryKeys . list ( organizationId , principal . userId ) ,
@@ -128,21 +93,6 @@ function createSeeds(organizationId: string, principal: SessionPrincipal) {
12893 }
12994}
13095
131- /**
132- * What decides each Home widget's state, so a viewer with no connection paints their prompt at once.
133- * Provider reads stay on the client: they can take seconds.
134- */
135- export function prefetchHome (
136- surface : PrefetchSurface ,
137- principal : SessionPrincipal
138- ) : Promise < DehydratedState > {
139- const seeds = createSeeds ( surface . organization . id , principal )
140- return seeds . settle ( [
141- ...seeds . memberInventory ( surface ) ,
142- ...( surface . searchAccess . memberScoped ? [ seeds . searchHistory ( ) ] : [ ] ) ,
143- ] )
144- }
145-
14696/** The history under Search's field. Results stay on the client: they are the slow live read. */
14797export function prefetchSearch (
14898 organizationId : string ,
@@ -152,15 +102,6 @@ export function prefetchSearch(
152102 return seeds . settle ( [ seeds . searchHistory ( ) ] )
153103}
154104
155- /** The member inventory and secret source the Integrations pages list. */
156- export function prefetchIntegrations (
157- surface : PrefetchSurface ,
158- principal : SessionPrincipal
159- ) : Promise < DehydratedState > {
160- const seeds = createSeeds ( surface . organization . id , principal )
161- return seeds . settle ( [ ...seeds . memberInventory ( surface ) , seeds . secretSource ( ) ] )
162- }
163-
164105/** The first page of the list the URL asks for. Later pages load as the table scrolls. */
165106export function prefetchSimLinks (
166107 organizationId : string ,
0 commit comments