@btst/plugin-search 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +17 -0
- package/dist/api/index.cjs +17 -0
- package/dist/api/index.d.cts +62 -0
- package/dist/api/index.d.mts +62 -0
- package/dist/api/index.d.ts +62 -0
- package/dist/api/index.mjs +4 -0
- package/dist/api/operations.cjs +127 -0
- package/dist/api/operations.mjs +125 -0
- package/dist/api/plugin.cjs +23 -0
- package/dist/api/plugin.mjs +21 -0
- package/dist/client/components/index.cjs +11 -0
- package/dist/client/components/index.d.cts +35 -0
- package/dist/client/components/index.d.mts +35 -0
- package/dist/client/components/index.d.ts +35 -0
- package/dist/client/components/index.mjs +3 -0
- package/dist/client/components/pages/search-page.cjs +39 -0
- package/dist/client/components/pages/search-page.internal.cjs +100 -0
- package/dist/client/components/pages/search-page.internal.mjs +98 -0
- package/dist/client/components/pages/search-page.mjs +37 -0
- package/dist/client/components/search-dialog.cjs +148 -0
- package/dist/client/components/search-dialog.mjs +145 -0
- package/dist/client/components/search-results.cjs +100 -0
- package/dist/client/components/search-results.mjs +96 -0
- package/dist/client/components/source-filter.cjs +31 -0
- package/dist/client/components/source-filter.mjs +29 -0
- package/dist/client/constants.cjs +5 -0
- package/dist/client/constants.mjs +3 -0
- package/dist/client/hooks/index.cjs +10 -0
- package/dist/client/hooks/index.d.cts +340 -0
- package/dist/client/hooks/index.d.mts +340 -0
- package/dist/client/hooks/index.d.ts +340 -0
- package/dist/client/hooks/index.mjs +3 -0
- package/dist/client/hooks/use-search-state.cjs +36 -0
- package/dist/client/hooks/use-search-state.mjs +34 -0
- package/dist/client/hooks/use-search.cjs +44 -0
- package/dist/client/hooks/use-search.mjs +42 -0
- package/dist/client/index.cjs +7 -0
- package/dist/client/index.d.cts +55 -0
- package/dist/client/index.d.mts +55 -0
- package/dist/client/index.d.ts +55 -0
- package/dist/client/index.mjs +1 -0
- package/dist/client/plugin.cjs +76 -0
- package/dist/client/plugin.mjs +74 -0
- package/dist/client/search-state.cjs +20 -0
- package/dist/client/search-state.mjs +17 -0
- package/dist/permissions.cjs +12 -0
- package/dist/permissions.d.cts +12 -0
- package/dist/permissions.d.mts +12 -0
- package/dist/permissions.d.ts +12 -0
- package/dist/permissions.mjs +10 -0
- package/dist/providers.cjs +122 -0
- package/dist/providers.d.cts +82 -0
- package/dist/providers.d.mts +82 -0
- package/dist/providers.d.ts +82 -0
- package/dist/providers.mjs +116 -0
- package/dist/query-keys.cjs +35 -0
- package/dist/query-keys.d.cts +71 -0
- package/dist/query-keys.d.mts +71 -0
- package/dist/query-keys.d.ts +71 -0
- package/dist/query-keys.mjs +32 -0
- package/dist/schemas.cjs +23 -0
- package/dist/schemas.d.cts +14 -0
- package/dist/schemas.d.mts +14 -0
- package/dist/schemas.d.ts +14 -0
- package/dist/schemas.mjs +17 -0
- package/dist/shared/plugin-search.5GvThkZW.d.cts +20 -0
- package/dist/shared/plugin-search.5GvThkZW.d.mts +20 -0
- package/dist/shared/plugin-search.5GvThkZW.d.ts +20 -0
- package/dist/style.css +2 -0
- package/dist/types.cjs +2 -0
- package/dist/types.d.cts +53 -0
- package/dist/types.d.mts +53 -0
- package/dist/types.d.ts +53 -0
- package/dist/types.mjs +1 -0
- package/dist/ui/src/components/button.cjs +56 -0
- package/dist/ui/src/components/button.mjs +53 -0
- package/dist/ui/src/components/command.cjs +88 -0
- package/dist/ui/src/components/command.mjs +83 -0
- package/dist/ui/src/components/dialog.cjs +127 -0
- package/dist/ui/src/components/dialog.mjs +105 -0
- package/dist/ui/src/components/input.cjs +23 -0
- package/dist/ui/src/components/input.mjs +21 -0
- package/dist/ui/src/lib/utils.cjs +10 -0
- package/dist/ui/src/lib/utils.mjs +8 -0
- package/package.json +181 -3
- package/README.md +0 -3
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const hooks = require('@btst/stack/client/hooks');
|
|
5
|
+
const hooks$1 = require('@btst/stack/plugins/client/hooks');
|
|
6
|
+
const useSearch = require('./use-search.cjs');
|
|
7
|
+
const constants = require('../constants.cjs');
|
|
8
|
+
const searchState = require('../search-state.cjs');
|
|
9
|
+
|
|
10
|
+
function useSearchState({
|
|
11
|
+
sources,
|
|
12
|
+
initialSearch,
|
|
13
|
+
enabled = true
|
|
14
|
+
} = {}) {
|
|
15
|
+
const [urlState, setState] = hooks.useListState(
|
|
16
|
+
constants.SEARCH_PLUGIN_ID,
|
|
17
|
+
searchState.SEARCH_LIST_STATE_SCHEMA
|
|
18
|
+
);
|
|
19
|
+
const state = typeof window === "undefined" && initialSearch ? initialSearch : urlState;
|
|
20
|
+
const q = hooks$1.useDebounce(state.q, 300);
|
|
21
|
+
const fixedSources = sources !== void 0;
|
|
22
|
+
const selectedSources = sources ?? (state.sources ? state.sources.split(",") : void 0);
|
|
23
|
+
const result = useSearch.useSearch(
|
|
24
|
+
{ q, sources: selectedSources, page: state.page, limit: 20 },
|
|
25
|
+
enabled && (!fixedSources || sources.length > 0)
|
|
26
|
+
);
|
|
27
|
+
return {
|
|
28
|
+
state,
|
|
29
|
+
setState,
|
|
30
|
+
fixedSources,
|
|
31
|
+
result: fixedSources && sources.length === 0 ? { ...result, data: void 0 } : result,
|
|
32
|
+
loading: result.isLoading || enabled && q !== state.q
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
exports.useSearchState = useSearchState;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useListState } from '@btst/stack/client/hooks';
|
|
3
|
+
import { useDebounce } from '@btst/stack/plugins/client/hooks';
|
|
4
|
+
import { useSearch } from './use-search.mjs';
|
|
5
|
+
import { SEARCH_PLUGIN_ID } from '../constants.mjs';
|
|
6
|
+
import { SEARCH_LIST_STATE_SCHEMA } from '../search-state.mjs';
|
|
7
|
+
|
|
8
|
+
function useSearchState({
|
|
9
|
+
sources,
|
|
10
|
+
initialSearch,
|
|
11
|
+
enabled = true
|
|
12
|
+
} = {}) {
|
|
13
|
+
const [urlState, setState] = useListState(
|
|
14
|
+
SEARCH_PLUGIN_ID,
|
|
15
|
+
SEARCH_LIST_STATE_SCHEMA
|
|
16
|
+
);
|
|
17
|
+
const state = typeof window === "undefined" && initialSearch ? initialSearch : urlState;
|
|
18
|
+
const q = useDebounce(state.q, 300);
|
|
19
|
+
const fixedSources = sources !== void 0;
|
|
20
|
+
const selectedSources = sources ?? (state.sources ? state.sources.split(",") : void 0);
|
|
21
|
+
const result = useSearch(
|
|
22
|
+
{ q, sources: selectedSources, page: state.page, limit: 20 },
|
|
23
|
+
enabled && (!fixedSources || sources.length > 0)
|
|
24
|
+
);
|
|
25
|
+
return {
|
|
26
|
+
state,
|
|
27
|
+
setState,
|
|
28
|
+
fixedSources,
|
|
29
|
+
result: fixedSources && sources.length === 0 ? { ...result, data: void 0 } : result,
|
|
30
|
+
loading: result.isLoading || enabled && q !== state.q
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { useSearchState };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const react = require('react');
|
|
5
|
+
const reactQuery = require('@tanstack/react-query');
|
|
6
|
+
const context = require('@btst/stack/context');
|
|
7
|
+
const hooks = require('@btst/stack/plugins/client/hooks');
|
|
8
|
+
const queryKeys = require('../../query-keys.cjs');
|
|
9
|
+
const constants = require('../constants.cjs');
|
|
10
|
+
|
|
11
|
+
const search = hooks.createResource({
|
|
12
|
+
plugin: constants.SEARCH_PLUGIN_ID,
|
|
13
|
+
resources: queryKeys.searchResources
|
|
14
|
+
});
|
|
15
|
+
const initialIdentityGenerations = /* @__PURE__ */ new WeakMap();
|
|
16
|
+
function useSearch(params, enabled = true) {
|
|
17
|
+
const { identity, isPending, error } = context.useIdentity();
|
|
18
|
+
const generation = context.useIdentitySourceGeneration();
|
|
19
|
+
const stack = context.useStack();
|
|
20
|
+
const queryClient = reactQuery.useQueryClient(stack.queryClient);
|
|
21
|
+
if (!initialIdentityGenerations.has(queryClient))
|
|
22
|
+
initialIdentityGenerations.set(queryClient, generation);
|
|
23
|
+
const partition = isPending ? `pending:${generation}` : error ? `error:${generation}` : initialIdentityGenerations.get(queryClient) !== generation ? { identity, generation } : identity ?? void 0;
|
|
24
|
+
const partitionKey = JSON.stringify(partition);
|
|
25
|
+
react.useEffect(() => {
|
|
26
|
+
const filters = {
|
|
27
|
+
queryKey: ["searchResults"],
|
|
28
|
+
predicate: (query) => JSON.stringify(query.queryKey[3]) !== partitionKey
|
|
29
|
+
};
|
|
30
|
+
void queryClient.cancelQueries(filters);
|
|
31
|
+
queryClient.removeQueries(filters);
|
|
32
|
+
}, [queryClient, partitionKey]);
|
|
33
|
+
const result = search.searchResults.list.use([params, partition], {
|
|
34
|
+
enabled: enabled && !isPending && !error
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
...result,
|
|
38
|
+
data: isPending || error ? void 0 : result.data,
|
|
39
|
+
error: error ?? result.error,
|
|
40
|
+
isLoading: enabled && (isPending || result.isLoading)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
exports.useSearch = useSearch;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
4
|
+
import { useIdentity, useIdentitySourceGeneration, useStack } from '@btst/stack/context';
|
|
5
|
+
import { createResource } from '@btst/stack/plugins/client/hooks';
|
|
6
|
+
import { searchResources } from '../../query-keys.mjs';
|
|
7
|
+
import { SEARCH_PLUGIN_ID } from '../constants.mjs';
|
|
8
|
+
|
|
9
|
+
const search = createResource({
|
|
10
|
+
plugin: SEARCH_PLUGIN_ID,
|
|
11
|
+
resources: searchResources
|
|
12
|
+
});
|
|
13
|
+
const initialIdentityGenerations = /* @__PURE__ */ new WeakMap();
|
|
14
|
+
function useSearch(params, enabled = true) {
|
|
15
|
+
const { identity, isPending, error } = useIdentity();
|
|
16
|
+
const generation = useIdentitySourceGeneration();
|
|
17
|
+
const stack = useStack();
|
|
18
|
+
const queryClient = useQueryClient(stack.queryClient);
|
|
19
|
+
if (!initialIdentityGenerations.has(queryClient))
|
|
20
|
+
initialIdentityGenerations.set(queryClient, generation);
|
|
21
|
+
const partition = isPending ? `pending:${generation}` : error ? `error:${generation}` : initialIdentityGenerations.get(queryClient) !== generation ? { identity, generation } : identity ?? void 0;
|
|
22
|
+
const partitionKey = JSON.stringify(partition);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
const filters = {
|
|
25
|
+
queryKey: ["searchResults"],
|
|
26
|
+
predicate: (query) => JSON.stringify(query.queryKey[3]) !== partitionKey
|
|
27
|
+
};
|
|
28
|
+
void queryClient.cancelQueries(filters);
|
|
29
|
+
queryClient.removeQueries(filters);
|
|
30
|
+
}, [queryClient, partitionKey]);
|
|
31
|
+
const result = search.searchResults.list.use([params, partition], {
|
|
32
|
+
enabled: enabled && !isPending && !error
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
...result,
|
|
36
|
+
data: isPending || error ? void 0 : result.data,
|
|
37
|
+
error: error ?? result.error,
|
|
38
|
+
isLoading: enabled && (isPending || result.isLoading)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { useSearch };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as _btst_stack_client from '@btst/stack/client';
|
|
2
|
+
import * as _btst_yar from '@btst/yar';
|
|
3
|
+
import * as react from 'react';
|
|
4
|
+
import { ComponentType } from 'react';
|
|
5
|
+
import { SearchIdentityPartition } from '../query-keys.cjs';
|
|
6
|
+
import '@btst/stack/plugins/client';
|
|
7
|
+
import '@btst/stack/context';
|
|
8
|
+
import '../types.cjs';
|
|
9
|
+
import '@btst/stack/plugins/api';
|
|
10
|
+
|
|
11
|
+
/** Presentation choices for the shared Search UI. */
|
|
12
|
+
interface SearchPluginOverrides {
|
|
13
|
+
/** Label above the results route. */
|
|
14
|
+
title?: string;
|
|
15
|
+
/** Search field prompt. */
|
|
16
|
+
placeholder?: string;
|
|
17
|
+
/** Message shown when a completed query has no matches. */
|
|
18
|
+
emptyMessage?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Search route views and request-local SSR state. */
|
|
22
|
+
interface SearchClientConfig {
|
|
23
|
+
/** The request query string, forwarded by the framework's server route. */
|
|
24
|
+
searchParams?: URLSearchParams | string;
|
|
25
|
+
/** Match the identity passed to StackProvider when hydrating private providers. */
|
|
26
|
+
identityPartition?: SearchIdentityPartition;
|
|
27
|
+
/** Replace the route view while retaining search prefetch and metadata. */
|
|
28
|
+
pageComponents?: {
|
|
29
|
+
search?: ComponentType;
|
|
30
|
+
};
|
|
31
|
+
/** Observe server prefetching. Reporter failures never reject route rendering. */
|
|
32
|
+
hooks?: {
|
|
33
|
+
beforeLoad?: () => void | Promise<void>;
|
|
34
|
+
afterLoad?: () => void | Promise<void>;
|
|
35
|
+
onErrorLoad?: (error: unknown) => void | Promise<void>;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
declare const searchClientPlugin: (config?: SearchClientConfig) => _btst_stack_client.ClientPluginDefinition<SearchPluginOverrides, {
|
|
39
|
+
search: _btst_yar.DefinedRoute<"/search", {
|
|
40
|
+
readonly page: () => react.JSX.Element;
|
|
41
|
+
readonly loader: () => Promise<void>;
|
|
42
|
+
readonly meta: () => ({
|
|
43
|
+
title: string;
|
|
44
|
+
name?: undefined;
|
|
45
|
+
content?: undefined;
|
|
46
|
+
} | {
|
|
47
|
+
name: string;
|
|
48
|
+
content: string;
|
|
49
|
+
title?: undefined;
|
|
50
|
+
})[];
|
|
51
|
+
}, _btst_yar.RouteMeta>;
|
|
52
|
+
}, "search", Readonly<Record<string, never>>, never>;
|
|
53
|
+
|
|
54
|
+
export { searchClientPlugin };
|
|
55
|
+
export type { SearchClientConfig, SearchPluginOverrides };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as _btst_stack_client from '@btst/stack/client';
|
|
2
|
+
import * as _btst_yar from '@btst/yar';
|
|
3
|
+
import * as react from 'react';
|
|
4
|
+
import { ComponentType } from 'react';
|
|
5
|
+
import { SearchIdentityPartition } from '../query-keys.mjs';
|
|
6
|
+
import '@btst/stack/plugins/client';
|
|
7
|
+
import '@btst/stack/context';
|
|
8
|
+
import '../types.mjs';
|
|
9
|
+
import '@btst/stack/plugins/api';
|
|
10
|
+
|
|
11
|
+
/** Presentation choices for the shared Search UI. */
|
|
12
|
+
interface SearchPluginOverrides {
|
|
13
|
+
/** Label above the results route. */
|
|
14
|
+
title?: string;
|
|
15
|
+
/** Search field prompt. */
|
|
16
|
+
placeholder?: string;
|
|
17
|
+
/** Message shown when a completed query has no matches. */
|
|
18
|
+
emptyMessage?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Search route views and request-local SSR state. */
|
|
22
|
+
interface SearchClientConfig {
|
|
23
|
+
/** The request query string, forwarded by the framework's server route. */
|
|
24
|
+
searchParams?: URLSearchParams | string;
|
|
25
|
+
/** Match the identity passed to StackProvider when hydrating private providers. */
|
|
26
|
+
identityPartition?: SearchIdentityPartition;
|
|
27
|
+
/** Replace the route view while retaining search prefetch and metadata. */
|
|
28
|
+
pageComponents?: {
|
|
29
|
+
search?: ComponentType;
|
|
30
|
+
};
|
|
31
|
+
/** Observe server prefetching. Reporter failures never reject route rendering. */
|
|
32
|
+
hooks?: {
|
|
33
|
+
beforeLoad?: () => void | Promise<void>;
|
|
34
|
+
afterLoad?: () => void | Promise<void>;
|
|
35
|
+
onErrorLoad?: (error: unknown) => void | Promise<void>;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
declare const searchClientPlugin: (config?: SearchClientConfig) => _btst_stack_client.ClientPluginDefinition<SearchPluginOverrides, {
|
|
39
|
+
search: _btst_yar.DefinedRoute<"/search", {
|
|
40
|
+
readonly page: () => react.JSX.Element;
|
|
41
|
+
readonly loader: () => Promise<void>;
|
|
42
|
+
readonly meta: () => ({
|
|
43
|
+
title: string;
|
|
44
|
+
name?: undefined;
|
|
45
|
+
content?: undefined;
|
|
46
|
+
} | {
|
|
47
|
+
name: string;
|
|
48
|
+
content: string;
|
|
49
|
+
title?: undefined;
|
|
50
|
+
})[];
|
|
51
|
+
}, _btst_yar.RouteMeta>;
|
|
52
|
+
}, "search", Readonly<Record<string, never>>, never>;
|
|
53
|
+
|
|
54
|
+
export { searchClientPlugin };
|
|
55
|
+
export type { SearchClientConfig, SearchPluginOverrides };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as _btst_stack_client from '@btst/stack/client';
|
|
2
|
+
import * as _btst_yar from '@btst/yar';
|
|
3
|
+
import * as react from 'react';
|
|
4
|
+
import { ComponentType } from 'react';
|
|
5
|
+
import { SearchIdentityPartition } from '../query-keys.js';
|
|
6
|
+
import '@btst/stack/plugins/client';
|
|
7
|
+
import '@btst/stack/context';
|
|
8
|
+
import '../types.js';
|
|
9
|
+
import '@btst/stack/plugins/api';
|
|
10
|
+
|
|
11
|
+
/** Presentation choices for the shared Search UI. */
|
|
12
|
+
interface SearchPluginOverrides {
|
|
13
|
+
/** Label above the results route. */
|
|
14
|
+
title?: string;
|
|
15
|
+
/** Search field prompt. */
|
|
16
|
+
placeholder?: string;
|
|
17
|
+
/** Message shown when a completed query has no matches. */
|
|
18
|
+
emptyMessage?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Search route views and request-local SSR state. */
|
|
22
|
+
interface SearchClientConfig {
|
|
23
|
+
/** The request query string, forwarded by the framework's server route. */
|
|
24
|
+
searchParams?: URLSearchParams | string;
|
|
25
|
+
/** Match the identity passed to StackProvider when hydrating private providers. */
|
|
26
|
+
identityPartition?: SearchIdentityPartition;
|
|
27
|
+
/** Replace the route view while retaining search prefetch and metadata. */
|
|
28
|
+
pageComponents?: {
|
|
29
|
+
search?: ComponentType;
|
|
30
|
+
};
|
|
31
|
+
/** Observe server prefetching. Reporter failures never reject route rendering. */
|
|
32
|
+
hooks?: {
|
|
33
|
+
beforeLoad?: () => void | Promise<void>;
|
|
34
|
+
afterLoad?: () => void | Promise<void>;
|
|
35
|
+
onErrorLoad?: (error: unknown) => void | Promise<void>;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
declare const searchClientPlugin: (config?: SearchClientConfig) => _btst_stack_client.ClientPluginDefinition<SearchPluginOverrides, {
|
|
39
|
+
search: _btst_yar.DefinedRoute<"/search", {
|
|
40
|
+
readonly page: () => react.JSX.Element;
|
|
41
|
+
readonly loader: () => Promise<void>;
|
|
42
|
+
readonly meta: () => ({
|
|
43
|
+
title: string;
|
|
44
|
+
name?: undefined;
|
|
45
|
+
content?: undefined;
|
|
46
|
+
} | {
|
|
47
|
+
name: string;
|
|
48
|
+
content: string;
|
|
49
|
+
title?: undefined;
|
|
50
|
+
})[];
|
|
51
|
+
}, _btst_yar.RouteMeta>;
|
|
52
|
+
}, "search", Readonly<Record<string, never>>, never>;
|
|
53
|
+
|
|
54
|
+
export { searchClientPlugin };
|
|
55
|
+
export type { SearchClientConfig, SearchPluginOverrides };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { searchClientPlugin } from './plugin.mjs';
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
const yar = require('@btst/yar');
|
|
5
|
+
const client = require('@btst/stack/plugins/client');
|
|
6
|
+
const queryKeys = require('../query-keys.cjs');
|
|
7
|
+
const searchPage = require('./components/pages/search-page.cjs');
|
|
8
|
+
const constants = require('./constants.cjs');
|
|
9
|
+
const searchState = require('./search-state.cjs');
|
|
10
|
+
|
|
11
|
+
const searchClientPlugin = (config = {}) => client.defineClientPlugin()({
|
|
12
|
+
id: constants.SEARCH_PLUGIN_ID,
|
|
13
|
+
resolve: (runtime) => {
|
|
14
|
+
const state = searchState.parseSearchState(config.searchParams);
|
|
15
|
+
const queries = queryKeys.createSearchQueryKeys(
|
|
16
|
+
client.createApiClient({ ...runtime.api })
|
|
17
|
+
);
|
|
18
|
+
const entry = queries.searchResults.list(
|
|
19
|
+
{
|
|
20
|
+
q: state.q,
|
|
21
|
+
sources: state.sources ? state.sources.split(",") : void 0,
|
|
22
|
+
page: state.page
|
|
23
|
+
},
|
|
24
|
+
config.identityPartition
|
|
25
|
+
);
|
|
26
|
+
const load = async () => {
|
|
27
|
+
if (typeof window !== "undefined") return;
|
|
28
|
+
let error;
|
|
29
|
+
try {
|
|
30
|
+
await config.hooks?.beforeLoad?.();
|
|
31
|
+
await runtime.queryClient.prefetchQuery({ ...entry, retry: false });
|
|
32
|
+
error = runtime.queryClient.getQueryState(entry.queryKey)?.error;
|
|
33
|
+
if (!error) await config.hooks?.afterLoad?.();
|
|
34
|
+
} catch (caught) {
|
|
35
|
+
error = caught;
|
|
36
|
+
}
|
|
37
|
+
if (!error) return;
|
|
38
|
+
await runtime.queryClient.prefetchQuery({
|
|
39
|
+
queryKey: entry.queryKey,
|
|
40
|
+
queryFn: () => {
|
|
41
|
+
throw client.createSanitizedSSRLoaderError();
|
|
42
|
+
},
|
|
43
|
+
retry: false,
|
|
44
|
+
staleTime: 0
|
|
45
|
+
});
|
|
46
|
+
if (client.isConnectionError(error))
|
|
47
|
+
console.warn("[btst/search] API unavailable during SSR prefetch.");
|
|
48
|
+
try {
|
|
49
|
+
await config.hooks?.onErrorLoad?.(error);
|
|
50
|
+
} catch {
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
return {
|
|
54
|
+
routes: () => yar.defineRoutes(
|
|
55
|
+
{
|
|
56
|
+
search: yar.defineRoute("/search", {
|
|
57
|
+
page: () => /* @__PURE__ */ jsxRuntime.jsx(
|
|
58
|
+
searchPage.SearchPageComponent,
|
|
59
|
+
{
|
|
60
|
+
initialSearch: config.searchParams === void 0 ? void 0 : state
|
|
61
|
+
}
|
|
62
|
+
),
|
|
63
|
+
loader: load,
|
|
64
|
+
meta: () => [
|
|
65
|
+
{ title: "Search" },
|
|
66
|
+
{ name: "robots", content: "noindex,follow" }
|
|
67
|
+
]
|
|
68
|
+
})
|
|
69
|
+
},
|
|
70
|
+
{ pages: config.pageComponents }
|
|
71
|
+
)
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
exports.searchClientPlugin = searchClientPlugin;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { defineRoutes, defineRoute } from '@btst/yar';
|
|
3
|
+
import { defineClientPlugin, createApiClient, createSanitizedSSRLoaderError, isConnectionError } from '@btst/stack/plugins/client';
|
|
4
|
+
import { createSearchQueryKeys } from '../query-keys.mjs';
|
|
5
|
+
import { SearchPageComponent } from './components/pages/search-page.mjs';
|
|
6
|
+
import { SEARCH_PLUGIN_ID } from './constants.mjs';
|
|
7
|
+
import { parseSearchState } from './search-state.mjs';
|
|
8
|
+
|
|
9
|
+
const searchClientPlugin = (config = {}) => defineClientPlugin()({
|
|
10
|
+
id: SEARCH_PLUGIN_ID,
|
|
11
|
+
resolve: (runtime) => {
|
|
12
|
+
const state = parseSearchState(config.searchParams);
|
|
13
|
+
const queries = createSearchQueryKeys(
|
|
14
|
+
createApiClient({ ...runtime.api })
|
|
15
|
+
);
|
|
16
|
+
const entry = queries.searchResults.list(
|
|
17
|
+
{
|
|
18
|
+
q: state.q,
|
|
19
|
+
sources: state.sources ? state.sources.split(",") : void 0,
|
|
20
|
+
page: state.page
|
|
21
|
+
},
|
|
22
|
+
config.identityPartition
|
|
23
|
+
);
|
|
24
|
+
const load = async () => {
|
|
25
|
+
if (typeof window !== "undefined") return;
|
|
26
|
+
let error;
|
|
27
|
+
try {
|
|
28
|
+
await config.hooks?.beforeLoad?.();
|
|
29
|
+
await runtime.queryClient.prefetchQuery({ ...entry, retry: false });
|
|
30
|
+
error = runtime.queryClient.getQueryState(entry.queryKey)?.error;
|
|
31
|
+
if (!error) await config.hooks?.afterLoad?.();
|
|
32
|
+
} catch (caught) {
|
|
33
|
+
error = caught;
|
|
34
|
+
}
|
|
35
|
+
if (!error) return;
|
|
36
|
+
await runtime.queryClient.prefetchQuery({
|
|
37
|
+
queryKey: entry.queryKey,
|
|
38
|
+
queryFn: () => {
|
|
39
|
+
throw createSanitizedSSRLoaderError();
|
|
40
|
+
},
|
|
41
|
+
retry: false,
|
|
42
|
+
staleTime: 0
|
|
43
|
+
});
|
|
44
|
+
if (isConnectionError(error))
|
|
45
|
+
console.warn("[btst/search] API unavailable during SSR prefetch.");
|
|
46
|
+
try {
|
|
47
|
+
await config.hooks?.onErrorLoad?.(error);
|
|
48
|
+
} catch {
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
routes: () => defineRoutes(
|
|
53
|
+
{
|
|
54
|
+
search: defineRoute("/search", {
|
|
55
|
+
page: () => /* @__PURE__ */ jsx(
|
|
56
|
+
SearchPageComponent,
|
|
57
|
+
{
|
|
58
|
+
initialSearch: config.searchParams === void 0 ? void 0 : state
|
|
59
|
+
}
|
|
60
|
+
),
|
|
61
|
+
loader: load,
|
|
62
|
+
meta: () => [
|
|
63
|
+
{ title: "Search" },
|
|
64
|
+
{ name: "robots", content: "noindex,follow" }
|
|
65
|
+
]
|
|
66
|
+
})
|
|
67
|
+
},
|
|
68
|
+
{ pages: config.pageComponents }
|
|
69
|
+
)
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
export { searchClientPlugin };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const client = require('@btst/stack/client');
|
|
4
|
+
const constants = require('./constants.cjs');
|
|
5
|
+
|
|
6
|
+
const SEARCH_LIST_STATE_SCHEMA = {
|
|
7
|
+
q: { type: "string", default: "", history: "replace" },
|
|
8
|
+
sources: { type: "string", default: "" },
|
|
9
|
+
page: { type: "number", default: 1 }
|
|
10
|
+
};
|
|
11
|
+
function parseSearchState(searchParams = "") {
|
|
12
|
+
return client.parseListStateFromSearchParams(
|
|
13
|
+
constants.SEARCH_PLUGIN_ID,
|
|
14
|
+
SEARCH_LIST_STATE_SCHEMA,
|
|
15
|
+
searchParams
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
exports.SEARCH_LIST_STATE_SCHEMA = SEARCH_LIST_STATE_SCHEMA;
|
|
20
|
+
exports.parseSearchState = parseSearchState;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { parseListStateFromSearchParams } from '@btst/stack/client';
|
|
2
|
+
import { SEARCH_PLUGIN_ID } from './constants.mjs';
|
|
3
|
+
|
|
4
|
+
const SEARCH_LIST_STATE_SCHEMA = {
|
|
5
|
+
q: { type: "string", default: "", history: "replace" },
|
|
6
|
+
sources: { type: "string", default: "" },
|
|
7
|
+
page: { type: "number", default: 1 }
|
|
8
|
+
};
|
|
9
|
+
function parseSearchState(searchParams = "") {
|
|
10
|
+
return parseListStateFromSearchParams(
|
|
11
|
+
SEARCH_PLUGIN_ID,
|
|
12
|
+
SEARCH_LIST_STATE_SCHEMA,
|
|
13
|
+
searchParams
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { SEARCH_LIST_STATE_SCHEMA, parseSearchState };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const authorization = require('@btst/stack/authorization');
|
|
4
|
+
const zod = require('zod');
|
|
5
|
+
|
|
6
|
+
const searchPermissions = authorization.definePermissions("search", {
|
|
7
|
+
query: {
|
|
8
|
+
read: authorization.permission(zod.z.object({ sources: zod.z.array(zod.z.string()) }))
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
exports.searchPermissions = searchPermissions;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as _btst_stack_authorization from '@btst/stack/authorization';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
declare const searchPermissions: _btst_stack_authorization.PermissionCatalog<"search", {
|
|
5
|
+
readonly query: {
|
|
6
|
+
readonly read: _btst_stack_authorization.PermissionSeed<z.ZodObject<{
|
|
7
|
+
sources: z.ZodArray<z.ZodString>;
|
|
8
|
+
}, z.core.$strip>>;
|
|
9
|
+
};
|
|
10
|
+
}>;
|
|
11
|
+
|
|
12
|
+
export { searchPermissions };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as _btst_stack_authorization from '@btst/stack/authorization';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
declare const searchPermissions: _btst_stack_authorization.PermissionCatalog<"search", {
|
|
5
|
+
readonly query: {
|
|
6
|
+
readonly read: _btst_stack_authorization.PermissionSeed<z.ZodObject<{
|
|
7
|
+
sources: z.ZodArray<z.ZodString>;
|
|
8
|
+
}, z.core.$strip>>;
|
|
9
|
+
};
|
|
10
|
+
}>;
|
|
11
|
+
|
|
12
|
+
export { searchPermissions };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as _btst_stack_authorization from '@btst/stack/authorization';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
declare const searchPermissions: _btst_stack_authorization.PermissionCatalog<"search", {
|
|
5
|
+
readonly query: {
|
|
6
|
+
readonly read: _btst_stack_authorization.PermissionSeed<z.ZodObject<{
|
|
7
|
+
sources: z.ZodArray<z.ZodString>;
|
|
8
|
+
}, z.core.$strip>>;
|
|
9
|
+
};
|
|
10
|
+
}>;
|
|
11
|
+
|
|
12
|
+
export { searchPermissions };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { definePermissions, permission } from '@btst/stack/authorization';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
const searchPermissions = definePermissions("search", {
|
|
5
|
+
query: {
|
|
6
|
+
read: permission(z.object({ sources: z.array(z.string()) }))
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export { searchPermissions };
|