1 | import { RegistryMetadata } from '../types/registry-metadata';
|
2 | import { fetchFromRegistry } from '../utils/fetch-from-registry';
|
3 |
|
4 | /**
|
5 | * `getRegistryMetadata` returns the metadata describing the registry itself.
|
6 | *
|
7 | * @param registry - URL of the registry (default: npm registry)
|
8 | * @param cached - accept cached responses (default: `true`)
|
9 | *
|
10 | * @example
|
11 | * Get the metadata for the npm registry:
|
12 | *
|
13 | * ```typescript
|
14 | * import { getRegistryMetadata } from 'query-registry';
|
15 | *
|
16 | * (async () => {
|
17 | * const metadata = await getRegistryMetadata();
|
18 | *
|
19 | * // Output: 'registry'
|
20 | * console.log(metadata.db_name);
|
21 | * })();
|
22 | * ```
|
23 | *
|
24 | * @example
|
25 | * Get the metadata for a custom registry:
|
26 | *
|
27 | * ```typescript
|
28 | * import { getRegistryMetadata } from 'query-registry';
|
29 | *
|
30 | * (async () => {
|
31 | * const metadata = await getRegistryMetadata({ registry: 'https://example.com' });
|
32 | * })();
|
33 | * ```
|
34 | *
|
35 | * @see {@link RegistryMetadata}
|
36 | * @see {@link npmRegistry}
|
37 | */
|
38 | export async function getRegistryMetadata({
|
39 | registry,
|
40 | cached,
|
41 | }: {
|
42 | registry?: string;
|
43 | cached?: boolean;
|
44 | } = {}): Promise<RegistryMetadata> {
|
45 | const endpoint = '/';
|
46 | return fetchFromRegistry({ registry, mirrors: [], endpoint, cached });
|
47 | }
|