-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathalgolia.ts
46 lines (40 loc) · 1.15 KB
/
algolia.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
/**
* Utilities for uploading and managing algolia indexes.
*
* @module
*/
import { createFetchRequester } from "@algolia/requester-fetch";
import algoliasearch, { type SearchClient } from "algoliasearch";
import { algoliaKeys, readyPromise } from "./auth.ts";
let denoLandApp: SearchClient | undefined;
let searchOnlyClient: SearchClient | undefined;
export enum Source {
StandardLibraryDefault = 200,
ThirdPartyDefault = 400,
}
export async function getDenoLandApp(): Promise<SearchClient> {
if (denoLandApp) {
return denoLandApp;
}
const requester = createFetchRequester();
await readyPromise;
return denoLandApp = algoliasearch(
algoliaKeys.appId,
algoliaKeys.apiKey,
{ requester },
);
}
/** Resolves with a search only client against algolia */
export async function getSearchClient(): Promise<SearchClient> {
if (searchOnlyClient) {
return searchOnlyClient;
}
const requester = createFetchRequester();
await readyPromise;
return searchOnlyClient = algoliasearch(
algoliaKeys.appId,
algoliaKeys.searchApiKey,
{ requester },
);
}