@stainless-api/docs-search 0.1.0-beta.9 → 1.0.0-beta.51
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/context.d.ts +3 -3
- package/dist/context.js +30 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +5 -10
- package/dist/indexer.d.ts +35 -0
- package/dist/{indexer-DBU0POrK.js → indexer.js} +10 -9
- package/dist/mcp.d.ts +3 -7
- package/dist/mcp.js +2 -4
- package/dist/providers/algolia.d.ts +4 -6
- package/dist/providers/algolia.js +69 -4
- package/dist/providers/fuse.d.ts +4 -5
- package/dist/providers/fuse.js +3 -5
- package/dist/providers/pagefind.d.ts +1 -1
- package/dist/providers/pagefind.js +22 -3
- package/dist/providers/walker.d.ts +2 -3
- package/dist/providers/walker.js +3 -5
- package/dist/types-D0suCLuC.d.ts +1598 -0
- package/dist/types.d.ts +2 -2
- package/dist/types.js +33 -3
- package/package.json +26 -19
- package/dist/algolia-D_93RHAi.js +0 -83
- package/dist/context-0GQv8iCh.js +0 -32
- package/dist/pagefind-Dcn-gjDe.js +0 -15
- package/dist/types-BZl4rMG9.js +0 -35
- package/dist/types-BpNxuhM2.d.ts +0 -91
package/dist/context.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
1
|
+
import { d as ResultType, h as SearchSettings, m as SearchParams } from "./types-D0suCLuC.js";
|
|
2
|
+
import * as _$react_jsx_runtime0 from "react/jsx-runtime";
|
|
3
3
|
|
|
4
4
|
//#region src/context.d.ts
|
|
5
5
|
type SearchContextType = {
|
|
@@ -15,6 +15,6 @@ type SearchProviderProps = SearchContextType & {
|
|
|
15
15
|
declare function SearchProvider({
|
|
16
16
|
children,
|
|
17
17
|
...props
|
|
18
|
-
}: SearchProviderProps): react_jsx_runtime0.JSX.Element;
|
|
18
|
+
}: SearchProviderProps): _$react_jsx_runtime0.JSX.Element;
|
|
19
19
|
//#endregion
|
|
20
20
|
export { SearchContextType, SearchProvider, SearchProviderProps, useSearch, useSearchContext };
|
package/dist/context.js
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import "
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { search } from "./providers/algolia.js";
|
|
2
|
+
import { createContext, use, useCallback } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region src/context.tsx
|
|
5
|
+
function createStrictContext(displayName) {
|
|
6
|
+
const Context = createContext(null);
|
|
7
|
+
Context.displayName = displayName;
|
|
8
|
+
function useStrictContext() {
|
|
9
|
+
const context = use(Context);
|
|
10
|
+
if (context === null) throw new Error(`use${displayName} must be used within a ${displayName}Provider`);
|
|
11
|
+
return context;
|
|
12
|
+
}
|
|
13
|
+
return [Context.Provider, useStrictContext];
|
|
14
|
+
}
|
|
15
|
+
const [Provider, useSearchContext] = createStrictContext("SearchContext");
|
|
16
|
+
function useSearch() {
|
|
17
|
+
const { settings } = useSearchContext();
|
|
18
|
+
return useCallback((params) => search({
|
|
19
|
+
settings,
|
|
20
|
+
params
|
|
21
|
+
}), [settings]);
|
|
22
|
+
}
|
|
23
|
+
function SearchProvider({ children, ...props }) {
|
|
24
|
+
return /* @__PURE__ */ jsx(Provider, {
|
|
25
|
+
value: props,
|
|
26
|
+
children
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { SearchProvider, useSearch, useSearchContext };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
1
|
+
import { c as QueryKindsType, l as ResultData } from "./types-D0suCLuC.js";
|
|
2
|
+
import * as _$react_jsx_runtime0 from "react/jsx-runtime";
|
|
3
3
|
|
|
4
4
|
//#region src/form.d.ts
|
|
5
|
-
declare function SearchForm(): react_jsx_runtime0.JSX.Element;
|
|
5
|
+
declare function SearchForm(): _$react_jsx_runtime0.JSX.Element;
|
|
6
6
|
type SearchFilterProps = {
|
|
7
7
|
results: ResultData;
|
|
8
8
|
filterKind: QueryKindsType;
|
|
@@ -12,7 +12,7 @@ declare function SearchFilter({
|
|
|
12
12
|
results,
|
|
13
13
|
filterKind,
|
|
14
14
|
onChange
|
|
15
|
-
}: SearchFilterProps): react_jsx_runtime0.JSX.Element;
|
|
15
|
+
}: SearchFilterProps): _$react_jsx_runtime0.JSX.Element;
|
|
16
16
|
type SearchModalProps = {
|
|
17
17
|
id?: string;
|
|
18
18
|
open?: boolean;
|
|
@@ -20,6 +20,6 @@ type SearchModalProps = {
|
|
|
20
20
|
declare function SearchModal({
|
|
21
21
|
id,
|
|
22
22
|
open: isOpen
|
|
23
|
-
}: SearchModalProps): react_jsx_runtime0.JSX.Element;
|
|
23
|
+
}: SearchModalProps): _$react_jsx_runtime0.JSX.Element;
|
|
24
24
|
//#endregion
|
|
25
25
|
export { SearchFilter, SearchFilterProps, SearchForm, SearchModal, SearchModalProps };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import {
|
|
3
|
-
import "./
|
|
4
|
-
import { n as useSearch, r as useSearchContext } from "./context-0GQv8iCh.js";
|
|
5
|
-
import { t as guideSearch } from "./pagefind-Dcn-gjDe.js";
|
|
1
|
+
import { QueryKinds } from "./types.js";
|
|
2
|
+
import { useSearch, useSearchContext } from "./context.js";
|
|
3
|
+
import { guideSearch } from "./providers/pagefind.js";
|
|
6
4
|
import { createElement, useEffect, useRef, useState } from "react";
|
|
7
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
6
|
import { BookOpenText, Box, Code, Folder, Search, Wrench } from "lucide-react";
|
|
@@ -10,7 +8,6 @@ import { useLanguage } from "@stainless-api/docs-ui/contexts";
|
|
|
10
8
|
import { useComponents } from "@stainless-api/docs-ui/contexts/use-components";
|
|
11
9
|
import style from "@stainless-api/docs-ui/style";
|
|
12
10
|
import { Button } from "@stainless-api/ui-primitives";
|
|
13
|
-
|
|
14
11
|
//#region src/results.tsx
|
|
15
12
|
const QueryKindDisplay = {
|
|
16
13
|
all: {
|
|
@@ -216,7 +213,6 @@ function SearchResultContent({ result }) {
|
|
|
216
213
|
});
|
|
217
214
|
}
|
|
218
215
|
}
|
|
219
|
-
|
|
220
216
|
//#endregion
|
|
221
217
|
//#region src/form.tsx
|
|
222
218
|
function SearchForm() {
|
|
@@ -276,7 +272,7 @@ function SearchForm() {
|
|
|
276
272
|
/* @__PURE__ */ jsx(SearchFilter, {
|
|
277
273
|
results,
|
|
278
274
|
filterKind,
|
|
279
|
-
onChange: (filterKind
|
|
275
|
+
onChange: (filterKind) => setFilterKind(filterKind)
|
|
280
276
|
}),
|
|
281
277
|
/* @__PURE__ */ jsx(Docs.ListView, {
|
|
282
278
|
items: results?.items ?? [],
|
|
@@ -329,6 +325,5 @@ function SearchModal({ id, open: isOpen }) {
|
|
|
329
325
|
children: open && /* @__PURE__ */ jsx(SearchForm, {})
|
|
330
326
|
});
|
|
331
327
|
}
|
|
332
|
-
|
|
333
328
|
//#endregion
|
|
334
|
-
export { SearchFilter, SearchForm, SearchModal };
|
|
329
|
+
export { SearchFilter, SearchForm, SearchModal };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { n as IndexEntry, v as Resource, y as Spec } from "./types-D0suCLuC.js";
|
|
2
|
+
import { DocsLanguage } from "@stainless-api/docs-ui/routing";
|
|
3
|
+
|
|
4
|
+
//#region src/indexer.d.ts
|
|
5
|
+
declare function getResourceNames(resourceIds: string[], topResources?: Record<string, Resource>): string[];
|
|
6
|
+
declare function generateChatIndex(spec: Spec): Generator<{
|
|
7
|
+
language: string;
|
|
8
|
+
title: string;
|
|
9
|
+
content: string;
|
|
10
|
+
url: string;
|
|
11
|
+
name?: undefined;
|
|
12
|
+
endpoint?: undefined;
|
|
13
|
+
httpMethod?: undefined;
|
|
14
|
+
summary?: undefined;
|
|
15
|
+
description?: undefined;
|
|
16
|
+
stainlessPath?: undefined;
|
|
17
|
+
qualified?: undefined;
|
|
18
|
+
ident?: undefined;
|
|
19
|
+
} | {
|
|
20
|
+
language: "cli" | "csharp" | "go" | "http" | "java" | "kotlin" | "node" | "php" | "python" | "ruby" | "terraform" | "typescript";
|
|
21
|
+
title: string;
|
|
22
|
+
name: string;
|
|
23
|
+
endpoint: string;
|
|
24
|
+
httpMethod: string;
|
|
25
|
+
summary: string | undefined;
|
|
26
|
+
description: string | undefined;
|
|
27
|
+
stainlessPath: string;
|
|
28
|
+
qualified: string | undefined;
|
|
29
|
+
ident: string | undefined;
|
|
30
|
+
content: string;
|
|
31
|
+
url: string | null;
|
|
32
|
+
}, void, unknown>;
|
|
33
|
+
declare function generateIndex(spec: Spec, renderMarkdownFn?: (_: string) => string | null, includeTypes?: boolean, languages?: DocsLanguage[]): Generator<IndexEntry>;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { generateChatIndex, generateIndex, getResourceNames };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Languages, generateRoute, parseStainlessPath, walkTree } from "@stainless-api/docs-ui/routing";
|
|
2
2
|
import { printer, renderMarkdown } from "@stainless-api/docs-ui/markdown";
|
|
3
|
-
|
|
3
|
+
import { isResourceEmpty } from "@stainless-api/docs-ui/utils";
|
|
4
4
|
//#region src/indexer.ts
|
|
5
5
|
function getResourceNames(resourceIds, topResources) {
|
|
6
|
-
let element
|
|
6
|
+
let element;
|
|
7
7
|
let resources = topResources;
|
|
8
8
|
const resourceName = [];
|
|
9
9
|
for (const resource of resourceIds) {
|
|
@@ -72,8 +72,9 @@ function* generateChatIndex(spec) {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
function* generateIndex(spec, renderMarkdownFn, includeTypes) {
|
|
75
|
+
function* generateIndex(spec, renderMarkdownFn, includeTypes, languages) {
|
|
76
76
|
const parentCrumbs = {};
|
|
77
|
+
const targetLangs = languages ?? Languages;
|
|
77
78
|
for (const { data } of walkTree(spec, true)) {
|
|
78
79
|
const { kind, name, title, stainlessPath } = data;
|
|
79
80
|
const common = {
|
|
@@ -84,7 +85,8 @@ function* generateIndex(spec, renderMarkdownFn, includeTypes) {
|
|
|
84
85
|
const crumbs = getResourceNames(parseStainlessPath(stainlessPath).resource, spec.resources);
|
|
85
86
|
switch (kind) {
|
|
86
87
|
case "resource":
|
|
87
|
-
|
|
88
|
+
if (isResourceEmpty(data)) break;
|
|
89
|
+
for (const language of targetLangs) {
|
|
88
90
|
if (!data[language]) continue;
|
|
89
91
|
parentCrumbs[stainlessPath] = crumbs;
|
|
90
92
|
const { Name, QualifiedName } = data[language];
|
|
@@ -101,7 +103,7 @@ function* generateIndex(spec, renderMarkdownFn, includeTypes) {
|
|
|
101
103
|
break;
|
|
102
104
|
case "http_method": {
|
|
103
105
|
const { summary, endpoint, httpMethod } = data;
|
|
104
|
-
for (const language of
|
|
106
|
+
for (const language of targetLangs) {
|
|
105
107
|
const found = spec.decls[language]?.[stainlessPath];
|
|
106
108
|
if (!found) continue;
|
|
107
109
|
parentCrumbs[stainlessPath] = [...crumbs, title];
|
|
@@ -123,7 +125,7 @@ function* generateIndex(spec, renderMarkdownFn, includeTypes) {
|
|
|
123
125
|
}
|
|
124
126
|
break;
|
|
125
127
|
}
|
|
126
|
-
case "model": for (const language of
|
|
128
|
+
case "model": for (const language of targetLangs) {
|
|
127
129
|
if (!spec.decls[language]) continue;
|
|
128
130
|
parentCrumbs[stainlessPath] = [...crumbs, title];
|
|
129
131
|
const schema = spec.decls[language]?.[`${stainlessPath} > (schema)`];
|
|
@@ -143,7 +145,7 @@ function* generateIndex(spec, renderMarkdownFn, includeTypes) {
|
|
|
143
145
|
}
|
|
144
146
|
}
|
|
145
147
|
}
|
|
146
|
-
for (const language of
|
|
148
|
+
for (const language of targetLangs) {
|
|
147
149
|
const decls = spec.decls?.[language];
|
|
148
150
|
if (!decls) continue;
|
|
149
151
|
for (const decl of Object.values(decls)) switch (decl.kind) {
|
|
@@ -176,6 +178,5 @@ function* generateIndex(spec, renderMarkdownFn, includeTypes) {
|
|
|
176
178
|
}
|
|
177
179
|
}
|
|
178
180
|
}
|
|
179
|
-
|
|
180
181
|
//#endregion
|
|
181
|
-
export { generateIndex
|
|
182
|
+
export { generateChatIndex, generateIndex, getResourceNames };
|
package/dist/mcp.d.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import { n as IndexEntry, r as IndexMethod } from "./types-
|
|
1
|
+
import { n as IndexEntry, r as IndexMethod, y as Spec } from "./types-D0suCLuC.js";
|
|
2
|
+
import { generateIndex } from "./indexer.js";
|
|
2
3
|
import { DocsLanguage } from "@stainless-api/docs-ui/routing";
|
|
3
|
-
import * as SDKJSON from "@stainless/sdk-json";
|
|
4
4
|
|
|
5
|
-
//#region src/indexer.d.ts
|
|
6
|
-
|
|
7
|
-
declare function generateIndex(spec: SDKJSON.Spec, renderMarkdownFn?: (_: string) => string | null, includeTypes?: boolean): Generator<IndexEntry>;
|
|
8
|
-
//#endregion
|
|
9
5
|
//#region src/mcp.d.ts
|
|
10
6
|
type Item = IndexEntry & IndexMethod;
|
|
11
|
-
declare function render(spec:
|
|
7
|
+
declare function render(spec: Spec, language: DocsLanguage, items: Item[], includeModelProperties: boolean): any;
|
|
12
8
|
//#endregion
|
|
13
9
|
export { generateIndex, render };
|
package/dist/mcp.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { generateIndex } from "./indexer.js";
|
|
2
2
|
import { parseStainlessPath } from "@stainless-api/docs-ui/routing";
|
|
3
3
|
import { renderMarkdown } from "@stainless-api/docs-ui/markdown";
|
|
4
4
|
import { getResourceFromSpec } from "@stainless-api/docs-ui/utils";
|
|
5
|
-
|
|
6
5
|
//#region src/mcp.ts
|
|
7
6
|
function consolidate(results) {
|
|
8
7
|
const resources = /* @__PURE__ */ new Set();
|
|
@@ -31,6 +30,5 @@ function render(spec, language, items, includeModelProperties) {
|
|
|
31
30
|
});
|
|
32
31
|
return Object.fromEntries(output);
|
|
33
32
|
}
|
|
34
|
-
|
|
35
33
|
//#endregion
|
|
36
|
-
export { generateIndex, render };
|
|
34
|
+
export { generateIndex, render };
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as SDKJSON from "@stainless/sdk-json";
|
|
1
|
+
import { d as ResultType, h as SearchSettings, m as SearchParams, n as IndexEntry, y as Spec } from "../types-D0suCLuC.js";
|
|
3
2
|
|
|
4
3
|
//#region src/providers/algolia.d.ts
|
|
5
|
-
declare function buildIndex(appId: string, indexName: string, writeKey: string,
|
|
6
|
-
declare function buildChatIndex(appId: string, indexName: string, writeKey: string, spec:
|
|
7
|
-
declare function buildProseIndex(appId: string, indexName: string, writeKey: string, objects: ProseIndexEntry[]): Promise<void>;
|
|
4
|
+
declare function buildIndex(appId: string, indexName: string, writeKey: string, content: Spec | IndexEntry[], renderMarkdown: (_: string) => string | null): Promise<void>;
|
|
5
|
+
declare function buildChatIndex(appId: string, indexName: string, writeKey: string, spec: Spec): Promise<void>;
|
|
8
6
|
declare function search({
|
|
9
7
|
settings: {
|
|
10
8
|
appId,
|
|
@@ -21,4 +19,4 @@ declare function search({
|
|
|
21
19
|
settings: SearchSettings;
|
|
22
20
|
}): Promise<ResultType | undefined>;
|
|
23
21
|
//#endregion
|
|
24
|
-
export { buildChatIndex, buildIndex,
|
|
22
|
+
export { buildChatIndex, buildIndex, search };
|
|
@@ -1,4 +1,69 @@
|
|
|
1
|
-
import "../indexer
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { generateChatIndex, generateIndex } from "../indexer.js";
|
|
2
|
+
import { SearchableAttributes, SearchableAttributesChat } from "../types.js";
|
|
3
|
+
import { searchClient } from "@algolia/client-search";
|
|
4
|
+
//#region src/providers/algolia.ts
|
|
5
|
+
async function buildIndex(appId, indexName, writeKey, content, renderMarkdown) {
|
|
6
|
+
if (!appId || !indexName || !writeKey) return;
|
|
7
|
+
const objects = Array.isArray(content) ? content : Array.from(generateIndex(content, renderMarkdown));
|
|
8
|
+
const client = searchClient(appId, writeKey);
|
|
9
|
+
await client.setSettings({
|
|
10
|
+
indexName,
|
|
11
|
+
indexSettings: {
|
|
12
|
+
highlightPreTag: "<mark>",
|
|
13
|
+
highlightPostTag: "</mark>",
|
|
14
|
+
customRanking: ["asc(priority)"],
|
|
15
|
+
attributesForFaceting: ["language", "kind"],
|
|
16
|
+
searchableAttributes: [...SearchableAttributes]
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
await client.replaceAllObjects({
|
|
20
|
+
indexName,
|
|
21
|
+
objects
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async function buildChatIndex(appId, indexName, writeKey, spec) {
|
|
25
|
+
if (!appId || !indexName || !writeKey) return;
|
|
26
|
+
const objects = Array.from(generateChatIndex(spec));
|
|
27
|
+
const client = searchClient(appId, writeKey);
|
|
28
|
+
await client.setSettings({
|
|
29
|
+
indexName,
|
|
30
|
+
indexSettings: {
|
|
31
|
+
attributesForFaceting: ["language"],
|
|
32
|
+
attributeForDistinct: "stainlessPath",
|
|
33
|
+
searchableAttributes: SearchableAttributesChat
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
await client.replaceAllObjects({
|
|
37
|
+
indexName,
|
|
38
|
+
objects
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async function search({ settings: { appId, indexName, searchKey }, params: { query, language, kind } }) {
|
|
42
|
+
const client = searchClient(appId, searchKey);
|
|
43
|
+
const filters = language ? `language:${language}` : void 0;
|
|
44
|
+
const facetFilters = kind ? [`kind:${kind}`] : void 0;
|
|
45
|
+
const { results } = await client.search({ requests: [{
|
|
46
|
+
query,
|
|
47
|
+
indexName,
|
|
48
|
+
filters,
|
|
49
|
+
hitsPerPage: 5,
|
|
50
|
+
facets: ["kind"]
|
|
51
|
+
}, {
|
|
52
|
+
query,
|
|
53
|
+
indexName,
|
|
54
|
+
filters,
|
|
55
|
+
facetFilters,
|
|
56
|
+
facets: ["kind"],
|
|
57
|
+
hitsPerPage: 50
|
|
58
|
+
}] });
|
|
59
|
+
if ("hits" in results[0] && "hits" in results[1]) {
|
|
60
|
+
const [{ nbHits, facets }, { hits }] = results;
|
|
61
|
+
return {
|
|
62
|
+
hits,
|
|
63
|
+
nbHits: nbHits ?? 0,
|
|
64
|
+
facets
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { buildChatIndex, buildIndex, search };
|
package/dist/providers/fuse.d.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import { n as IndexEntry } from "../types-
|
|
1
|
+
import { n as IndexEntry, y as Spec } from "../types-D0suCLuC.js";
|
|
2
2
|
import { DocsLanguage } from "@stainless-api/docs-ui/routing";
|
|
3
|
-
import * as fuse_js0 from "fuse.js";
|
|
3
|
+
import * as _$fuse_js0 from "fuse.js";
|
|
4
4
|
import { FuseIndex } from "fuse.js";
|
|
5
|
-
import * as SDKJSON from "@stainless/sdk-json";
|
|
6
5
|
|
|
7
6
|
//#region src/providers/fuse.d.ts
|
|
8
7
|
type FuseIndexData = {
|
|
9
8
|
content: IndexEntry[];
|
|
10
9
|
index: FuseIndex<IndexEntry>;
|
|
11
10
|
};
|
|
12
|
-
declare function buildIndex(spec:
|
|
11
|
+
declare function buildIndex(spec: Spec, language?: DocsLanguage): FuseIndexData;
|
|
13
12
|
declare function search({
|
|
14
13
|
content,
|
|
15
14
|
index
|
|
16
|
-
}: FuseIndexData, query: string, limit?: number): fuse_js0.FuseResult<IndexEntry>[];
|
|
15
|
+
}: FuseIndexData, query: string, limit?: number): _$fuse_js0.FuseResult<IndexEntry>[];
|
|
17
16
|
//#endregion
|
|
18
17
|
export { FuseIndexData, buildIndex, search };
|
package/dist/providers/fuse.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { generateIndex } from "../indexer.js";
|
|
2
|
+
import { SearchableAttributes } from "../types.js";
|
|
3
3
|
import Fuse from "fuse.js";
|
|
4
|
-
|
|
5
4
|
//#region src/providers/fuse.ts
|
|
6
5
|
function buildIndex(spec, language) {
|
|
7
6
|
const idx = Array.from(generateIndex(spec, void 0, false));
|
|
@@ -14,6 +13,5 @@ function buildIndex(spec, language) {
|
|
|
14
13
|
function search({ content, index }, query, limit = 100) {
|
|
15
14
|
return new Fuse(content, { keys: [...SearchableAttributes] }, index).search(query).slice(0, limit);
|
|
16
15
|
}
|
|
17
|
-
|
|
18
16
|
//#endregion
|
|
19
|
-
export { buildIndex, search };
|
|
17
|
+
export { buildIndex, search };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as GuideResultType } from "../types-
|
|
1
|
+
import { t as GuideResultType } from "../types-D0suCLuC.js";
|
|
2
2
|
|
|
3
3
|
//#region src/providers/pagefind.d.ts
|
|
4
4
|
declare function guideSearch(loadPath: string, query: string, limit?: number): Promise<GuideResultType[]>;
|
|
@@ -1,3 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
//#region src/providers/pagefind.ts
|
|
2
|
+
async function loadPagefind(path) {
|
|
3
|
+
return await import(
|
|
4
|
+
/* @vite-ignore */
|
|
5
|
+
new URL(path, import.meta.url).href
|
|
6
|
+
);
|
|
7
|
+
}
|
|
8
|
+
async function guideSearch(loadPath, query, limit) {
|
|
9
|
+
try {
|
|
10
|
+
const response = await (await loadPagefind(loadPath)).search(query);
|
|
11
|
+
const items = limit ? response.results.slice(0, limit) : response.results;
|
|
12
|
+
return Promise.all(items.map((result) => result.data().then((data) => ({
|
|
13
|
+
...result,
|
|
14
|
+
data
|
|
15
|
+
}))));
|
|
16
|
+
} catch (error) {
|
|
17
|
+
console.error(error);
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { guideSearch };
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { n as IndexEntry } from "../types-
|
|
1
|
+
import { n as IndexEntry, y as Spec } from "../types-D0suCLuC.js";
|
|
2
2
|
import { DocsLanguage } from "@stainless-api/docs-ui/routing";
|
|
3
|
-
import * as SDKJSON from "@stainless/sdk-json";
|
|
4
3
|
|
|
5
4
|
//#region src/providers/walker.d.ts
|
|
6
|
-
declare function buildIndex(spec:
|
|
5
|
+
declare function buildIndex(spec: Spec): Generator<IndexEntry, any, any>;
|
|
7
6
|
declare function search(index: Generator<IndexEntry>, language: DocsLanguage, query: string, limit?: number): IndexEntry[];
|
|
8
7
|
//#endregion
|
|
9
8
|
export { buildIndex, search };
|
package/dist/providers/walker.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { generateIndex } from "../indexer.js";
|
|
2
|
+
import { SearchableAttributes } from "../types.js";
|
|
4
3
|
//#region src/providers/walker.ts
|
|
5
4
|
function buildIndex(spec) {
|
|
6
5
|
return generateIndex(spec, void 0, false);
|
|
@@ -18,6 +17,5 @@ function search(index, language, query, limit = 100) {
|
|
|
18
17
|
const results = findEntryInIndex(index, language, query);
|
|
19
18
|
return Array.from(results).sort((a, b) => a.priority - b.priority).slice(0, limit);
|
|
20
19
|
}
|
|
21
|
-
|
|
22
20
|
//#endregion
|
|
23
|
-
export { buildIndex, search };
|
|
21
|
+
export { buildIndex, search };
|