1 | # query-registry
|
2 |
|
3 | [![Build status](https://img.shields.io/github/actions/workflow/status/velut/query-registry/main.yml?branch=main)](https://github.com/velut/query-registry/actions?query=workflow%3ACI)
|
4 | [![Coverage](https://img.shields.io/codecov/c/gh/velut/query-registry)](https://codecov.io/gh/velut/query-registry)
|
5 | [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/query-registry)
|
6 | ![Language](https://img.shields.io/github/languages/top/velut/query-registry)
|
7 | [![npm](https://img.shields.io/npm/v/query-registry)](https://www.npmjs.com/package/query-registry)
|
8 | [![License](https://img.shields.io/github/license/velut/query-registry)](https://github.com/velut/query-registry/blob/main/LICENSE)
|
9 |
|
10 | `query-registry` is an API wrapper for the [npm registry API](https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md).
|
11 |
|
12 | ## Features
|
13 |
|
14 | - Provides functions to:
|
15 | - Get registry metadata.
|
16 | - Get registry public keys.
|
17 | - Get packuments (package documents) with full package metadata.
|
18 | - Get abbreviated packuments with installation data only.
|
19 | - Get package manifests for each version of a package.
|
20 | - Get download counts for the registry and for packages.
|
21 | - Search packages by name and other specific criteria.
|
22 | - Works in the browser.
|
23 | - Validates registry responses with [zod](https://www.npmjs.com/package/zod).
|
24 | - Automatically caches registry responses for a short time.
|
25 | - Supports third-party npm-compatible registries.
|
26 |
|
27 | ## Useful resources
|
28 |
|
29 | - [**Explore the API on jsDocs.io**](https://www.jsdocs.io/package/query-registry)
|
30 | - View package contents on [**unpkg**](https://unpkg.com/query-registry/)
|
31 | - View repository on [**GitHub**](https://github.com/velut/query-registry)
|
32 | - Read the changelog on [**GitHub**](https://github.com/velut/query-registry/blob/main/CHANGELOG.md)
|
33 |
|
34 | ## Install
|
35 |
|
36 | Using `npm`:
|
37 |
|
38 | ```
|
39 | npm add query-registry
|
40 | ```
|
41 |
|
42 | Using `yarn`:
|
43 |
|
44 | ```
|
45 | yarn add query-registry
|
46 | ```
|
47 |
|
48 | Using `pnpm`:
|
49 |
|
50 | ```
|
51 | pnpm add query-registry
|
52 | ```
|
53 |
|
54 | Using `bun`:
|
55 |
|
56 | ```
|
57 | bun add query-registry
|
58 | ```
|
59 |
|
60 | ## Usage examples
|
61 |
|
62 | ### Registry
|
63 |
|
64 | Get the metadata about the npm registry itself, if available:
|
65 |
|
66 | ```typescript
|
67 | import { getRegistryMetadata } from "query-registry";
|
68 |
|
69 | const metadata = await getRegistryMetadata();
|
70 | ```
|
71 |
|
72 | Get the public signing keys for the npm registry:
|
73 |
|
74 | ```typescript
|
75 | import { getRegistrySigningKeys } from "query-registry";
|
76 |
|
77 | const { keys } = await getRegistrySigningKeys();
|
78 | ```
|
79 |
|
80 | ### Packuments (Package documents)
|
81 |
|
82 | Get the abbreviated packument containing only the necessary data to install the `react` package:
|
83 |
|
84 | ```typescript
|
85 | import { getAbbreviatedPackument } from "query-registry";
|
86 |
|
87 | const abbrPackument = await getAbbreviatedPackument("react");
|
88 | ```
|
89 |
|
90 | Get the full packument containing all the data available about the `react` package:
|
91 |
|
92 | ```typescript
|
93 | import { getPackument } from "query-registry";
|
94 |
|
95 | const packument = await getPackument("react");
|
96 | ```
|
97 |
|
98 | ### Package manifests
|
99 |
|
100 | Get the manifest containing the original `package.json` data plus additional registry metadata for the `latest` version of the `react` package:
|
101 |
|
102 | ```typescript
|
103 | import { getPackageManifest } from "query-registry";
|
104 |
|
105 | const manifest = await getPackageManifest("react");
|
106 | ```
|
107 |
|
108 | Get the manifest for `react@18.2.0` (semver version):
|
109 |
|
110 | ```typescript
|
111 | import { getPackageManifest } from "query-registry";
|
112 |
|
113 | const manifest = await getPackageManifest("react", "18.2.0");
|
114 | ```
|
115 |
|
116 | Get the manifest for `react@next` (distribution tag):
|
117 |
|
118 | ```typescript
|
119 | import { getPackageManifest } from "query-registry";
|
120 |
|
121 | const manifest = await getPackageManifest("react", "next");
|
122 | ```
|
123 |
|
124 | ### Search packages
|
125 |
|
126 | Search packages related to `react` (e.g., `react`, `react-dom`, ...):
|
127 |
|
128 | ```typescript
|
129 | import { searchPackages } from "query-registry";
|
130 |
|
131 | const results = await searchPackages({ text: "react" });
|
132 | ```
|
133 |
|
134 | ### Download counts
|
135 |
|
136 | Get the total number of downloads for package `react` for the last month:
|
137 |
|
138 | ```typescript
|
139 | import { getPackageDownloads } from "query-registry";
|
140 |
|
141 | const { downloads } = await getPackageDownloads("react", "last-month");
|
142 | ```
|
143 |
|
144 | There are also these other download counts functions available: `getBulkDailyPackageDownloads`, `getBulkPackageDownloads`, `getDailyPackageDownloads`, `getDailyRegistryDownloads` and `getPackageVersionsDownloads`.
|
145 |
|
146 | ### Cache
|
147 |
|
148 | Clear the internal cache.
|
149 |
|
150 | ```typescript
|
151 | import { cache } from "query-registry";
|
152 |
|
153 | cache.clear();
|
154 | ```
|
155 |
|
156 | See the [quick-lru](https://www.npmjs.com/package/quick-lru) package for the cache API.
|
157 |
|
158 | ## License
|
159 |
|
160 | ```
|
161 | MIT
|
162 | ```
|
163 |
|
164 | Copyright (c) 2024 Edoardo Scibona
|
165 |
|
166 | See [LICENSE](./LICENSE) file.
|