@btst/plugin-search 1.0.0-beta.2 → 1.1.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/dist/api/index.cjs +2 -0
- package/dist/api/index.d.cts +3 -2
- package/dist/api/index.d.mts +3 -2
- package/dist/api/index.d.ts +3 -2
- package/dist/api/index.mjs +1 -1
- package/dist/api/operations.cjs +20 -18
- package/dist/api/operations.mjs +15 -13
- package/dist/client/components/index.cjs +2 -0
- package/dist/client/components/index.d.cts +15 -7
- package/dist/client/components/index.d.mts +15 -7
- package/dist/client/components/index.d.ts +15 -7
- package/dist/client/components/index.mjs +1 -0
- package/dist/client/components/pages/search-page.internal.cjs +12 -4
- package/dist/client/components/pages/search-page.internal.mjs +12 -4
- package/dist/client/components/search-dialog.cjs +93 -57
- package/dist/client/components/search-dialog.mjs +94 -58
- package/dist/client/components/search-highlight.cjs +22 -0
- package/dist/client/components/search-highlight.mjs +20 -0
- package/dist/client/components/search-results.cjs +31 -24
- package/dist/client/components/search-results.mjs +32 -25
- package/dist/client/hooks/use-search-state.cjs +1 -1
- package/dist/client/hooks/use-search-state.mjs +1 -1
- package/dist/client/index.d.cts +3 -12
- package/dist/client/index.d.mts +3 -12
- package/dist/client/index.d.ts +3 -12
- package/dist/constants.cjs +11 -0
- package/dist/constants.mjs +6 -0
- package/dist/providers.cjs +21 -2
- package/dist/providers.d.cts +10 -3
- package/dist/providers.d.mts +10 -3
- package/dist/providers.d.ts +10 -3
- package/dist/providers.mjs +20 -3
- package/dist/query-keys.cjs +2 -1
- package/dist/query-keys.mjs +2 -1
- package/dist/response-schema.cjs +57 -0
- package/dist/response-schema.mjs +40 -0
- package/dist/schemas.cjs +10 -9
- package/dist/schemas.d.cts +39 -8
- package/dist/schemas.d.mts +39 -8
- package/dist/schemas.d.ts +39 -8
- package/dist/schemas.mjs +5 -5
- package/dist/shared/plugin-search.BDlgoPEb.d.ts +18 -0
- package/dist/shared/plugin-search.QfsGS8no.d.cts +18 -0
- package/dist/shared/plugin-search.WwLtD6lV.d.mts +18 -0
- package/dist/types.d.cts +4 -2
- package/dist/types.d.mts +4 -2
- package/dist/types.d.ts +4 -2
- package/package.json +4 -4
package/dist/providers.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SearchProvider } from './types.mjs';
|
|
1
|
+
import { SearchProvider, SearchProviderResult } from './types.mjs';
|
|
2
2
|
import '@btst/stack/plugins/api';
|
|
3
3
|
|
|
4
4
|
interface PublicPost {
|
|
@@ -62,8 +62,15 @@ interface SourceOptions<Operations> {
|
|
|
62
62
|
* Bound input before regex work so malformed markup cannot trigger unbounded scans.
|
|
63
63
|
*/
|
|
64
64
|
declare function searchSnippet(value: string): string;
|
|
65
|
+
/** Shared discovery normalization; punctuation and combining marks do not affect rank. */
|
|
66
|
+
declare function normalizeSearchText(value: string): string;
|
|
67
|
+
/** Lower values rank first. Providers still own matching and visibility. */
|
|
68
|
+
declare function searchRelevance(result: SearchProviderResult, query: string): number;
|
|
65
69
|
/** Reuses Blog's publication filter and domain text matching. */
|
|
66
|
-
declare function blogSearchProvider(options: SourceOptions<BlogSearchOperations>
|
|
70
|
+
declare function blogSearchProvider(options: SourceOptions<BlogSearchOperations> & {
|
|
71
|
+
/** Opt into 201 only with a Blog release whose list operation accepts it. */
|
|
72
|
+
batchSize?: 100 | 201;
|
|
73
|
+
}): SearchProvider;
|
|
67
74
|
/** Uses only the public School catalog; lessons never participate. */
|
|
68
75
|
declare function schoolSearchProvider(options: SourceOptions<SchoolSearchOperations>): SearchProvider;
|
|
69
76
|
/** Uses Ecommerce's public product projection, including its visibility rules. */
|
|
@@ -78,5 +85,5 @@ declare function cmsSearchProvider(options: {
|
|
|
78
85
|
search: SearchProvider["search"];
|
|
79
86
|
}): SearchProvider;
|
|
80
87
|
|
|
81
|
-
export { blogSearchProvider, cmsSearchProvider, ecommerceSearchProvider, schoolSearchProvider, searchSnippet };
|
|
88
|
+
export { blogSearchProvider, cmsSearchProvider, ecommerceSearchProvider, normalizeSearchText, schoolSearchProvider, searchRelevance, searchSnippet };
|
|
82
89
|
export type { BlogSearchOperations, EcommerceSearchOperations, SchoolSearchOperations };
|
package/dist/providers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SearchProvider } from './types.js';
|
|
1
|
+
import { SearchProvider, SearchProviderResult } from './types.js';
|
|
2
2
|
import '@btst/stack/plugins/api';
|
|
3
3
|
|
|
4
4
|
interface PublicPost {
|
|
@@ -62,8 +62,15 @@ interface SourceOptions<Operations> {
|
|
|
62
62
|
* Bound input before regex work so malformed markup cannot trigger unbounded scans.
|
|
63
63
|
*/
|
|
64
64
|
declare function searchSnippet(value: string): string;
|
|
65
|
+
/** Shared discovery normalization; punctuation and combining marks do not affect rank. */
|
|
66
|
+
declare function normalizeSearchText(value: string): string;
|
|
67
|
+
/** Lower values rank first. Providers still own matching and visibility. */
|
|
68
|
+
declare function searchRelevance(result: SearchProviderResult, query: string): number;
|
|
65
69
|
/** Reuses Blog's publication filter and domain text matching. */
|
|
66
|
-
declare function blogSearchProvider(options: SourceOptions<BlogSearchOperations>
|
|
70
|
+
declare function blogSearchProvider(options: SourceOptions<BlogSearchOperations> & {
|
|
71
|
+
/** Opt into 201 only with a Blog release whose list operation accepts it. */
|
|
72
|
+
batchSize?: 100 | 201;
|
|
73
|
+
}): SearchProvider;
|
|
67
74
|
/** Uses only the public School catalog; lessons never participate. */
|
|
68
75
|
declare function schoolSearchProvider(options: SourceOptions<SchoolSearchOperations>): SearchProvider;
|
|
69
76
|
/** Uses Ecommerce's public product projection, including its visibility rules. */
|
|
@@ -78,5 +85,5 @@ declare function cmsSearchProvider(options: {
|
|
|
78
85
|
search: SearchProvider["search"];
|
|
79
86
|
}): SearchProvider;
|
|
80
87
|
|
|
81
|
-
export { blogSearchProvider, cmsSearchProvider, ecommerceSearchProvider, schoolSearchProvider, searchSnippet };
|
|
88
|
+
export { blogSearchProvider, cmsSearchProvider, ecommerceSearchProvider, normalizeSearchText, schoolSearchProvider, searchRelevance, searchSnippet };
|
|
82
89
|
export type { BlogSearchOperations, EcommerceSearchOperations, SchoolSearchOperations };
|
package/dist/providers.mjs
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
function searchSnippet(value) {
|
|
2
2
|
return value.slice(0, 2e3).replace(/<[^>]*>/g, " ").replace(/!?\[([^\]]*)\]\([^)]*\)/g, "$1").replace(/[`*_#>~]/g, "").replace(/\s+/g, " ").trim().slice(0, 240);
|
|
3
3
|
}
|
|
4
|
+
function normalizeSearchText(value) {
|
|
5
|
+
return value.normalize("NFKD").toLowerCase().replace(/[^\p{L}\p{N}]/gu, "");
|
|
6
|
+
}
|
|
7
|
+
function searchRelevance(result, query) {
|
|
8
|
+
const q = normalizeSearchText(query);
|
|
9
|
+
if (!q) return 7;
|
|
10
|
+
const title = normalizeSearchText(result.title);
|
|
11
|
+
const aliases = result.aliases?.map(normalizeSearchText) ?? [];
|
|
12
|
+
if (title === q) return 0;
|
|
13
|
+
if (aliases.includes(q)) return 1;
|
|
14
|
+
if (title.startsWith(q)) return 2;
|
|
15
|
+
if (aliases.some((alias) => alias.startsWith(q))) return 3;
|
|
16
|
+
if (title.includes(q)) return 4;
|
|
17
|
+
if (aliases.some((alias) => alias.includes(q))) return 5;
|
|
18
|
+
return normalizeSearchText(result.snippet).includes(q) ? 6 : 7;
|
|
19
|
+
}
|
|
4
20
|
function destination(basePath, slug) {
|
|
5
21
|
return `${basePath.replace(/\/$/, "")}/${encodeURIComponent(slug)}`;
|
|
6
22
|
}
|
|
@@ -10,14 +26,15 @@ function blogSearchProvider(options) {
|
|
|
10
26
|
label: "Blog",
|
|
11
27
|
async search({ q, limit, request }) {
|
|
12
28
|
const operations = options.operations(request);
|
|
29
|
+
const batchSize = options.batchSize ?? 100;
|
|
13
30
|
const items = [];
|
|
14
31
|
let omittedDestination = false;
|
|
15
32
|
let total = 0;
|
|
16
|
-
for (let offset = 0; offset < limit; offset +=
|
|
33
|
+
for (let offset = 0; offset < limit; offset += batchSize) {
|
|
17
34
|
const page = await operations.listPosts({
|
|
18
35
|
query: q,
|
|
19
36
|
published: true,
|
|
20
|
-
limit: Math.min(
|
|
37
|
+
limit: Math.min(batchSize, limit - offset),
|
|
21
38
|
offset
|
|
22
39
|
});
|
|
23
40
|
total = page.total;
|
|
@@ -113,4 +130,4 @@ function cmsSearchProvider(options) {
|
|
|
113
130
|
};
|
|
114
131
|
}
|
|
115
132
|
|
|
116
|
-
export { blogSearchProvider, cmsSearchProvider, ecommerceSearchProvider, schoolSearchProvider, searchSnippet };
|
|
133
|
+
export { blogSearchProvider, cmsSearchProvider, ecommerceSearchProvider, normalizeSearchText, schoolSearchProvider, searchRelevance, searchSnippet };
|
package/dist/query-keys.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const client = require('@btst/stack/plugins/client');
|
|
4
|
+
const responseSchema = require('./response-schema.cjs');
|
|
4
5
|
|
|
5
6
|
const searchResources = {
|
|
6
7
|
searchResults: {
|
|
@@ -22,7 +23,7 @@ const searchResources = {
|
|
|
22
23
|
},
|
|
23
24
|
identity
|
|
24
25
|
],
|
|
25
|
-
select: (data) => data
|
|
26
|
+
select: (data) => responseSchema.searchResponseSchema.parse(data)
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
}
|
package/dist/query-keys.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createResourceQueryKeys } from '@btst/stack/plugins/client';
|
|
2
|
+
import { searchResponseSchema } from './response-schema.mjs';
|
|
2
3
|
|
|
3
4
|
const searchResources = {
|
|
4
5
|
searchResults: {
|
|
@@ -20,7 +21,7 @@ const searchResources = {
|
|
|
20
21
|
},
|
|
21
22
|
identity
|
|
22
23
|
],
|
|
23
|
-
select: (data) => data
|
|
24
|
+
select: (data) => searchResponseSchema.parse(data)
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const z = require('zod/mini');
|
|
4
|
+
const constants = require('./constants.cjs');
|
|
5
|
+
|
|
6
|
+
function _interopNamespaceCompat(e) {
|
|
7
|
+
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
8
|
+
const n = Object.create(null);
|
|
9
|
+
if (e) {
|
|
10
|
+
for (const k in e) {
|
|
11
|
+
n[k] = e[k];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
n.default = e;
|
|
15
|
+
return n;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const z__namespace = /*#__PURE__*/_interopNamespaceCompat(z);
|
|
19
|
+
|
|
20
|
+
const sourceId = z__namespace.string().check(z__namespace.regex(constants.SEARCH_SOURCE_ID_PATTERN));
|
|
21
|
+
const searchProviderResultSchema = z__namespace.object({
|
|
22
|
+
resourceId: z__namespace.string().check(z__namespace.minLength(1), z__namespace.maxLength(200)),
|
|
23
|
+
title: z__namespace.string().check(z__namespace.minLength(1), z__namespace.maxLength(500)),
|
|
24
|
+
snippet: z__namespace.string().check(z__namespace.maxLength(500)),
|
|
25
|
+
href: z__namespace.string().check(
|
|
26
|
+
z__namespace.maxLength(2e3),
|
|
27
|
+
z__namespace.refine(
|
|
28
|
+
(value) => value.startsWith("/") && !value.startsWith("//") && !/[\\\u0000-\u0020]/.test(value),
|
|
29
|
+
"Search destinations must be application-relative paths"
|
|
30
|
+
)
|
|
31
|
+
)
|
|
32
|
+
});
|
|
33
|
+
const searchResponseSchema = z__namespace.object({
|
|
34
|
+
items: z__namespace.array(
|
|
35
|
+
z__namespace.extend(searchProviderResultSchema, {
|
|
36
|
+
key: z__namespace.string().check(z__namespace.minLength(1)),
|
|
37
|
+
sourceId,
|
|
38
|
+
sourceLabel: z__namespace.string().check(z__namespace.minLength(1), z__namespace.maxLength(100))
|
|
39
|
+
})
|
|
40
|
+
).check(z__namespace.maxLength(20)),
|
|
41
|
+
sources: z__namespace.array(
|
|
42
|
+
z__namespace.object({
|
|
43
|
+
id: sourceId,
|
|
44
|
+
label: z__namespace.string().check(z__namespace.minLength(1), z__namespace.maxLength(100))
|
|
45
|
+
})
|
|
46
|
+
).check(z__namespace.maxLength(constants.SEARCH_MAX_SOURCES)),
|
|
47
|
+
page: z__namespace.int().check(z__namespace.minimum(1), z__namespace.maximum(constants.SEARCH_MAX_PAGES)),
|
|
48
|
+
limit: z__namespace.int().check(z__namespace.minimum(1), z__namespace.maximum(20)),
|
|
49
|
+
hasMore: z__namespace.boolean(),
|
|
50
|
+
nextPage: z__namespace.nullable(
|
|
51
|
+
z__namespace.int().check(z__namespace.minimum(1), z__namespace.maximum(constants.SEARCH_MAX_PAGES))
|
|
52
|
+
),
|
|
53
|
+
truncated: z__namespace.boolean()
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
exports.searchProviderResultSchema = searchProviderResultSchema;
|
|
57
|
+
exports.searchResponseSchema = searchResponseSchema;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as z from 'zod/mini';
|
|
2
|
+
import { SEARCH_MAX_PAGES, SEARCH_MAX_SOURCES, SEARCH_SOURCE_ID_PATTERN } from './constants.mjs';
|
|
3
|
+
|
|
4
|
+
const sourceId = z.string().check(z.regex(SEARCH_SOURCE_ID_PATTERN));
|
|
5
|
+
const searchProviderResultSchema = z.object({
|
|
6
|
+
resourceId: z.string().check(z.minLength(1), z.maxLength(200)),
|
|
7
|
+
title: z.string().check(z.minLength(1), z.maxLength(500)),
|
|
8
|
+
snippet: z.string().check(z.maxLength(500)),
|
|
9
|
+
href: z.string().check(
|
|
10
|
+
z.maxLength(2e3),
|
|
11
|
+
z.refine(
|
|
12
|
+
(value) => value.startsWith("/") && !value.startsWith("//") && !/[\\\u0000-\u0020]/.test(value),
|
|
13
|
+
"Search destinations must be application-relative paths"
|
|
14
|
+
)
|
|
15
|
+
)
|
|
16
|
+
});
|
|
17
|
+
const searchResponseSchema = z.object({
|
|
18
|
+
items: z.array(
|
|
19
|
+
z.extend(searchProviderResultSchema, {
|
|
20
|
+
key: z.string().check(z.minLength(1)),
|
|
21
|
+
sourceId,
|
|
22
|
+
sourceLabel: z.string().check(z.minLength(1), z.maxLength(100))
|
|
23
|
+
})
|
|
24
|
+
).check(z.maxLength(20)),
|
|
25
|
+
sources: z.array(
|
|
26
|
+
z.object({
|
|
27
|
+
id: sourceId,
|
|
28
|
+
label: z.string().check(z.minLength(1), z.maxLength(100))
|
|
29
|
+
})
|
|
30
|
+
).check(z.maxLength(SEARCH_MAX_SOURCES)),
|
|
31
|
+
page: z.int().check(z.minimum(1), z.maximum(SEARCH_MAX_PAGES)),
|
|
32
|
+
limit: z.int().check(z.minimum(1), z.maximum(20)),
|
|
33
|
+
hasMore: z.boolean(),
|
|
34
|
+
nextPage: z.nullable(
|
|
35
|
+
z.int().check(z.minimum(1), z.maximum(SEARCH_MAX_PAGES))
|
|
36
|
+
),
|
|
37
|
+
truncated: z.boolean()
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export { searchProviderResultSchema, searchResponseSchema };
|
package/dist/schemas.cjs
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const zod = require('zod');
|
|
4
|
+
const constants = require('./constants.cjs');
|
|
5
|
+
const responseSchema = require('./response-schema.cjs');
|
|
4
6
|
|
|
5
|
-
const
|
|
6
|
-
const SEARCH_MAX_RESULTS = 200;
|
|
7
|
-
const SEARCH_MAX_PAGES = 10;
|
|
8
|
-
const searchSourceIdSchema = zod.z.string().regex(/^[a-z][a-z0-9-]{0,63}$/);
|
|
7
|
+
const searchSourceIdSchema = zod.z.string().regex(constants.SEARCH_SOURCE_ID_PATTERN);
|
|
9
8
|
const searchInputSchema = zod.z.object({
|
|
10
9
|
q: zod.z.string().trim().max(200),
|
|
11
10
|
sources: zod.z.preprocess(
|
|
12
11
|
(value) => typeof value === "string" ? value.split(",").filter(Boolean) : value,
|
|
13
|
-
zod.z.array(searchSourceIdSchema).max(SEARCH_MAX_SOURCES).optional()
|
|
12
|
+
zod.z.array(searchSourceIdSchema).max(constants.SEARCH_MAX_SOURCES).optional()
|
|
14
13
|
),
|
|
15
|
-
page: zod.z.coerce.number().int().min(1).max(SEARCH_MAX_PAGES).default(1),
|
|
14
|
+
page: zod.z.coerce.number().int().min(1).max(constants.SEARCH_MAX_PAGES).default(1),
|
|
16
15
|
limit: zod.z.coerce.number().int().min(1).max(20).default(20)
|
|
17
16
|
});
|
|
18
17
|
|
|
19
|
-
exports.SEARCH_MAX_PAGES = SEARCH_MAX_PAGES;
|
|
20
|
-
exports.SEARCH_MAX_RESULTS = SEARCH_MAX_RESULTS;
|
|
21
|
-
exports.SEARCH_MAX_SOURCES = SEARCH_MAX_SOURCES;
|
|
18
|
+
exports.SEARCH_MAX_PAGES = constants.SEARCH_MAX_PAGES;
|
|
19
|
+
exports.SEARCH_MAX_RESULTS = constants.SEARCH_MAX_RESULTS;
|
|
20
|
+
exports.SEARCH_MAX_SOURCES = constants.SEARCH_MAX_SOURCES;
|
|
21
|
+
exports.searchProviderResultSchema = responseSchema.searchProviderResultSchema;
|
|
22
|
+
exports.searchResponseSchema = responseSchema.searchResponseSchema;
|
|
22
23
|
exports.searchInputSchema = searchInputSchema;
|
|
23
24
|
exports.searchSourceIdSchema = searchSourceIdSchema;
|
package/dist/schemas.d.cts
CHANGED
|
@@ -1,14 +1,45 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
1
|
+
import { z as z$1 } from 'zod';
|
|
2
|
+
import * as z from 'zod/mini';
|
|
2
3
|
|
|
3
4
|
declare const SEARCH_MAX_SOURCES = 8;
|
|
4
5
|
declare const SEARCH_MAX_RESULTS = 200;
|
|
5
6
|
declare const SEARCH_MAX_PAGES = 10;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
|
|
8
|
+
/** Public record bounds shared by providers and client response validation. */
|
|
9
|
+
declare const searchProviderResultSchema: z.ZodMiniObject<{
|
|
10
|
+
resourceId: z.ZodMiniString<string>;
|
|
11
|
+
title: z.ZodMiniString<string>;
|
|
12
|
+
snippet: z.ZodMiniString<string>;
|
|
13
|
+
href: z.ZodMiniString<string>;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
/** Validate successful Search responses before rendering or caching them. */
|
|
16
|
+
declare const searchResponseSchema: z.ZodMiniObject<{
|
|
17
|
+
items: z.ZodMiniArray<z.ZodMiniObject<{
|
|
18
|
+
resourceId: z.ZodMiniString<string>;
|
|
19
|
+
title: z.ZodMiniString<string>;
|
|
20
|
+
snippet: z.ZodMiniString<string>;
|
|
21
|
+
href: z.ZodMiniString<string>;
|
|
22
|
+
key: z.ZodMiniString<string>;
|
|
23
|
+
sourceId: z.ZodMiniString<string>;
|
|
24
|
+
sourceLabel: z.ZodMiniString<string>;
|
|
25
|
+
}, z.core.$strip>>;
|
|
26
|
+
sources: z.ZodMiniArray<z.ZodMiniObject<{
|
|
27
|
+
id: z.ZodMiniString<string>;
|
|
28
|
+
label: z.ZodMiniString<string>;
|
|
29
|
+
}, z.core.$strip>>;
|
|
30
|
+
page: z.ZodMiniInt;
|
|
31
|
+
limit: z.ZodMiniInt;
|
|
32
|
+
hasMore: z.ZodMiniBoolean<boolean>;
|
|
33
|
+
nextPage: z.ZodMiniNullable<z.ZodMiniInt>;
|
|
34
|
+
truncated: z.ZodMiniBoolean<boolean>;
|
|
12
35
|
}, z.core.$strip>;
|
|
13
36
|
|
|
14
|
-
|
|
37
|
+
declare const searchSourceIdSchema: z$1.ZodString;
|
|
38
|
+
declare const searchInputSchema: z$1.ZodObject<{
|
|
39
|
+
q: z$1.ZodString;
|
|
40
|
+
sources: z$1.ZodPreprocess<z$1.ZodOptional<z$1.ZodArray<z$1.ZodString>>, unknown>;
|
|
41
|
+
page: z$1.ZodDefault<z$1.ZodCoercedNumber<unknown>>;
|
|
42
|
+
limit: z$1.ZodDefault<z$1.ZodCoercedNumber<unknown>>;
|
|
43
|
+
}, z$1.core.$strip>;
|
|
44
|
+
|
|
45
|
+
export { SEARCH_MAX_PAGES, SEARCH_MAX_RESULTS, SEARCH_MAX_SOURCES, searchInputSchema, searchProviderResultSchema, searchResponseSchema, searchSourceIdSchema };
|
package/dist/schemas.d.mts
CHANGED
|
@@ -1,14 +1,45 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
1
|
+
import { z as z$1 } from 'zod';
|
|
2
|
+
import * as z from 'zod/mini';
|
|
2
3
|
|
|
3
4
|
declare const SEARCH_MAX_SOURCES = 8;
|
|
4
5
|
declare const SEARCH_MAX_RESULTS = 200;
|
|
5
6
|
declare const SEARCH_MAX_PAGES = 10;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
|
|
8
|
+
/** Public record bounds shared by providers and client response validation. */
|
|
9
|
+
declare const searchProviderResultSchema: z.ZodMiniObject<{
|
|
10
|
+
resourceId: z.ZodMiniString<string>;
|
|
11
|
+
title: z.ZodMiniString<string>;
|
|
12
|
+
snippet: z.ZodMiniString<string>;
|
|
13
|
+
href: z.ZodMiniString<string>;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
/** Validate successful Search responses before rendering or caching them. */
|
|
16
|
+
declare const searchResponseSchema: z.ZodMiniObject<{
|
|
17
|
+
items: z.ZodMiniArray<z.ZodMiniObject<{
|
|
18
|
+
resourceId: z.ZodMiniString<string>;
|
|
19
|
+
title: z.ZodMiniString<string>;
|
|
20
|
+
snippet: z.ZodMiniString<string>;
|
|
21
|
+
href: z.ZodMiniString<string>;
|
|
22
|
+
key: z.ZodMiniString<string>;
|
|
23
|
+
sourceId: z.ZodMiniString<string>;
|
|
24
|
+
sourceLabel: z.ZodMiniString<string>;
|
|
25
|
+
}, z.core.$strip>>;
|
|
26
|
+
sources: z.ZodMiniArray<z.ZodMiniObject<{
|
|
27
|
+
id: z.ZodMiniString<string>;
|
|
28
|
+
label: z.ZodMiniString<string>;
|
|
29
|
+
}, z.core.$strip>>;
|
|
30
|
+
page: z.ZodMiniInt;
|
|
31
|
+
limit: z.ZodMiniInt;
|
|
32
|
+
hasMore: z.ZodMiniBoolean<boolean>;
|
|
33
|
+
nextPage: z.ZodMiniNullable<z.ZodMiniInt>;
|
|
34
|
+
truncated: z.ZodMiniBoolean<boolean>;
|
|
12
35
|
}, z.core.$strip>;
|
|
13
36
|
|
|
14
|
-
|
|
37
|
+
declare const searchSourceIdSchema: z$1.ZodString;
|
|
38
|
+
declare const searchInputSchema: z$1.ZodObject<{
|
|
39
|
+
q: z$1.ZodString;
|
|
40
|
+
sources: z$1.ZodPreprocess<z$1.ZodOptional<z$1.ZodArray<z$1.ZodString>>, unknown>;
|
|
41
|
+
page: z$1.ZodDefault<z$1.ZodCoercedNumber<unknown>>;
|
|
42
|
+
limit: z$1.ZodDefault<z$1.ZodCoercedNumber<unknown>>;
|
|
43
|
+
}, z$1.core.$strip>;
|
|
44
|
+
|
|
45
|
+
export { SEARCH_MAX_PAGES, SEARCH_MAX_RESULTS, SEARCH_MAX_SOURCES, searchInputSchema, searchProviderResultSchema, searchResponseSchema, searchSourceIdSchema };
|
package/dist/schemas.d.ts
CHANGED
|
@@ -1,14 +1,45 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
1
|
+
import { z as z$1 } from 'zod';
|
|
2
|
+
import * as z from 'zod/mini';
|
|
2
3
|
|
|
3
4
|
declare const SEARCH_MAX_SOURCES = 8;
|
|
4
5
|
declare const SEARCH_MAX_RESULTS = 200;
|
|
5
6
|
declare const SEARCH_MAX_PAGES = 10;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
|
|
8
|
+
/** Public record bounds shared by providers and client response validation. */
|
|
9
|
+
declare const searchProviderResultSchema: z.ZodMiniObject<{
|
|
10
|
+
resourceId: z.ZodMiniString<string>;
|
|
11
|
+
title: z.ZodMiniString<string>;
|
|
12
|
+
snippet: z.ZodMiniString<string>;
|
|
13
|
+
href: z.ZodMiniString<string>;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
/** Validate successful Search responses before rendering or caching them. */
|
|
16
|
+
declare const searchResponseSchema: z.ZodMiniObject<{
|
|
17
|
+
items: z.ZodMiniArray<z.ZodMiniObject<{
|
|
18
|
+
resourceId: z.ZodMiniString<string>;
|
|
19
|
+
title: z.ZodMiniString<string>;
|
|
20
|
+
snippet: z.ZodMiniString<string>;
|
|
21
|
+
href: z.ZodMiniString<string>;
|
|
22
|
+
key: z.ZodMiniString<string>;
|
|
23
|
+
sourceId: z.ZodMiniString<string>;
|
|
24
|
+
sourceLabel: z.ZodMiniString<string>;
|
|
25
|
+
}, z.core.$strip>>;
|
|
26
|
+
sources: z.ZodMiniArray<z.ZodMiniObject<{
|
|
27
|
+
id: z.ZodMiniString<string>;
|
|
28
|
+
label: z.ZodMiniString<string>;
|
|
29
|
+
}, z.core.$strip>>;
|
|
30
|
+
page: z.ZodMiniInt;
|
|
31
|
+
limit: z.ZodMiniInt;
|
|
32
|
+
hasMore: z.ZodMiniBoolean<boolean>;
|
|
33
|
+
nextPage: z.ZodMiniNullable<z.ZodMiniInt>;
|
|
34
|
+
truncated: z.ZodMiniBoolean<boolean>;
|
|
12
35
|
}, z.core.$strip>;
|
|
13
36
|
|
|
14
|
-
|
|
37
|
+
declare const searchSourceIdSchema: z$1.ZodString;
|
|
38
|
+
declare const searchInputSchema: z$1.ZodObject<{
|
|
39
|
+
q: z$1.ZodString;
|
|
40
|
+
sources: z$1.ZodPreprocess<z$1.ZodOptional<z$1.ZodArray<z$1.ZodString>>, unknown>;
|
|
41
|
+
page: z$1.ZodDefault<z$1.ZodCoercedNumber<unknown>>;
|
|
42
|
+
limit: z$1.ZodDefault<z$1.ZodCoercedNumber<unknown>>;
|
|
43
|
+
}, z$1.core.$strip>;
|
|
44
|
+
|
|
45
|
+
export { SEARCH_MAX_PAGES, SEARCH_MAX_RESULTS, SEARCH_MAX_SOURCES, searchInputSchema, searchProviderResultSchema, searchResponseSchema, searchSourceIdSchema };
|
package/dist/schemas.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { SEARCH_SOURCE_ID_PATTERN, SEARCH_MAX_PAGES, SEARCH_MAX_SOURCES } from './constants.mjs';
|
|
3
|
+
export { SEARCH_MAX_RESULTS } from './constants.mjs';
|
|
4
|
+
export { searchProviderResultSchema, searchResponseSchema } from './response-schema.mjs';
|
|
2
5
|
|
|
3
|
-
const
|
|
4
|
-
const SEARCH_MAX_RESULTS = 200;
|
|
5
|
-
const SEARCH_MAX_PAGES = 10;
|
|
6
|
-
const searchSourceIdSchema = z.string().regex(/^[a-z][a-z0-9-]{0,63}$/);
|
|
6
|
+
const searchSourceIdSchema = z.string().regex(SEARCH_SOURCE_ID_PATTERN);
|
|
7
7
|
const searchInputSchema = z.object({
|
|
8
8
|
q: z.string().trim().max(200),
|
|
9
9
|
sources: z.preprocess(
|
|
@@ -14,4 +14,4 @@ const searchInputSchema = z.object({
|
|
|
14
14
|
limit: z.coerce.number().int().min(1).max(20).default(20)
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
export { SEARCH_MAX_PAGES,
|
|
17
|
+
export { SEARCH_MAX_PAGES, SEARCH_MAX_SOURCES, searchInputSchema, searchSourceIdSchema };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { SearchResult } from '../types.js';
|
|
3
|
+
|
|
4
|
+
/** Presentation choices for the shared Search UI. */
|
|
5
|
+
interface SearchPluginOverrides {
|
|
6
|
+
/** Label above the results route. */
|
|
7
|
+
title?: string;
|
|
8
|
+
/** Search field prompt. */
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
/** Message shown when a completed query has no matches. */
|
|
11
|
+
emptyMessage?: string;
|
|
12
|
+
/** Presentational row content; use the query with SearchHighlight. Search owns links/options. */
|
|
13
|
+
renderResult?: (item: SearchResult, query: string) => ReactNode;
|
|
14
|
+
/** Visual loading content; Search retains the accessible announcement. */
|
|
15
|
+
renderLoading?: () => ReactNode;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type { SearchPluginOverrides as S };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { SearchResult } from '../types.cjs';
|
|
3
|
+
|
|
4
|
+
/** Presentation choices for the shared Search UI. */
|
|
5
|
+
interface SearchPluginOverrides {
|
|
6
|
+
/** Label above the results route. */
|
|
7
|
+
title?: string;
|
|
8
|
+
/** Search field prompt. */
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
/** Message shown when a completed query has no matches. */
|
|
11
|
+
emptyMessage?: string;
|
|
12
|
+
/** Presentational row content; use the query with SearchHighlight. Search owns links/options. */
|
|
13
|
+
renderResult?: (item: SearchResult, query: string) => ReactNode;
|
|
14
|
+
/** Visual loading content; Search retains the accessible announcement. */
|
|
15
|
+
renderLoading?: () => ReactNode;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type { SearchPluginOverrides as S };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { SearchResult } from '../types.mjs';
|
|
3
|
+
|
|
4
|
+
/** Presentation choices for the shared Search UI. */
|
|
5
|
+
interface SearchPluginOverrides {
|
|
6
|
+
/** Label above the results route. */
|
|
7
|
+
title?: string;
|
|
8
|
+
/** Search field prompt. */
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
/** Message shown when a completed query has no matches. */
|
|
11
|
+
emptyMessage?: string;
|
|
12
|
+
/** Presentational row content; use the query with SearchHighlight. Search owns links/options. */
|
|
13
|
+
renderResult?: (item: SearchResult, query: string) => ReactNode;
|
|
14
|
+
/** Visual loading content; Search retains the accessible announcement. */
|
|
15
|
+
renderLoading?: () => ReactNode;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type { SearchPluginOverrides as S };
|
package/dist/types.d.cts
CHANGED
|
@@ -11,6 +11,8 @@ type SearchProviderResult = {
|
|
|
11
11
|
title: string;
|
|
12
12
|
snippet: string;
|
|
13
13
|
href: string;
|
|
14
|
+
/** Public aliases used for ranking only; omitted from the Search response. */
|
|
15
|
+
aliases?: readonly string[];
|
|
14
16
|
};
|
|
15
17
|
/** Providers must apply visibility before returning records or continuation metadata. */
|
|
16
18
|
interface SearchProvider extends SearchSource {
|
|
@@ -24,8 +26,8 @@ interface SearchProvider extends SearchSource {
|
|
|
24
26
|
hasMore: boolean;
|
|
25
27
|
}>;
|
|
26
28
|
}
|
|
27
|
-
/** Result identity is scoped to its source
|
|
28
|
-
type SearchResult = SearchProviderResult & {
|
|
29
|
+
/** Result identity is scoped to its source; relevance metadata stays provider-side. */
|
|
30
|
+
type SearchResult = Omit<SearchProviderResult, "aliases"> & {
|
|
29
31
|
key: string;
|
|
30
32
|
sourceId: string;
|
|
31
33
|
sourceLabel: string;
|
package/dist/types.d.mts
CHANGED
|
@@ -11,6 +11,8 @@ type SearchProviderResult = {
|
|
|
11
11
|
title: string;
|
|
12
12
|
snippet: string;
|
|
13
13
|
href: string;
|
|
14
|
+
/** Public aliases used for ranking only; omitted from the Search response. */
|
|
15
|
+
aliases?: readonly string[];
|
|
14
16
|
};
|
|
15
17
|
/** Providers must apply visibility before returning records or continuation metadata. */
|
|
16
18
|
interface SearchProvider extends SearchSource {
|
|
@@ -24,8 +26,8 @@ interface SearchProvider extends SearchSource {
|
|
|
24
26
|
hasMore: boolean;
|
|
25
27
|
}>;
|
|
26
28
|
}
|
|
27
|
-
/** Result identity is scoped to its source
|
|
28
|
-
type SearchResult = SearchProviderResult & {
|
|
29
|
+
/** Result identity is scoped to its source; relevance metadata stays provider-side. */
|
|
30
|
+
type SearchResult = Omit<SearchProviderResult, "aliases"> & {
|
|
29
31
|
key: string;
|
|
30
32
|
sourceId: string;
|
|
31
33
|
sourceLabel: string;
|
package/dist/types.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ type SearchProviderResult = {
|
|
|
11
11
|
title: string;
|
|
12
12
|
snippet: string;
|
|
13
13
|
href: string;
|
|
14
|
+
/** Public aliases used for ranking only; omitted from the Search response. */
|
|
15
|
+
aliases?: readonly string[];
|
|
14
16
|
};
|
|
15
17
|
/** Providers must apply visibility before returning records or continuation metadata. */
|
|
16
18
|
interface SearchProvider extends SearchSource {
|
|
@@ -24,8 +26,8 @@ interface SearchProvider extends SearchSource {
|
|
|
24
26
|
hasMore: boolean;
|
|
25
27
|
}>;
|
|
26
28
|
}
|
|
27
|
-
/** Result identity is scoped to its source
|
|
28
|
-
type SearchResult = SearchProviderResult & {
|
|
29
|
+
/** Result identity is scoped to its source; relevance metadata stays provider-side. */
|
|
30
|
+
type SearchResult = Omit<SearchProviderResult, "aliases"> & {
|
|
29
31
|
key: string;
|
|
30
32
|
sourceId: string;
|
|
31
33
|
sourceLabel: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@btst/plugin-search",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -154,7 +154,7 @@
|
|
|
154
154
|
"cmdk": "^1.1.1"
|
|
155
155
|
},
|
|
156
156
|
"peerDependencies": {
|
|
157
|
-
"@btst/stack": ">=6.2.0
|
|
157
|
+
"@btst/stack": ">=6.2.0 <6.3.0",
|
|
158
158
|
"@btst/yar": ">=1.3.2",
|
|
159
159
|
"@tanstack/react-query": "^5.0.0",
|
|
160
160
|
"react": ">=19.2.6",
|
|
@@ -172,10 +172,10 @@
|
|
|
172
172
|
"vitest": "^4.1.12",
|
|
173
173
|
"@btst/adapter-memory": "3.0.1",
|
|
174
174
|
"jsdom": "^28.1.0",
|
|
175
|
-
"@btst/stack": "6.2.
|
|
175
|
+
"@btst/stack": "6.2.2",
|
|
176
176
|
"@workspace/ui": "0.0.0"
|
|
177
177
|
},
|
|
178
|
-
"gitHead": "
|
|
178
|
+
"gitHead": "ec8f741a6722d46974cd2e81034fa8a1a49cf531",
|
|
179
179
|
"scripts": {
|
|
180
180
|
"build": "unbuild --clean",
|
|
181
181
|
"typecheck": "tsc --project tsconfig.json",
|