fast-npm-meta 0.4.0 → 0.4.1
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/index.d.mts +34 -15
- package/dist/index.mjs +2 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -30,51 +30,72 @@ interface PackageError {
|
|
|
30
30
|
error: string;
|
|
31
31
|
}
|
|
32
32
|
type MaybeError<T> = T | PackageError;
|
|
33
|
-
interface ResolvedPackageVersion
|
|
33
|
+
interface ResolvedPackageVersion {
|
|
34
34
|
name: string;
|
|
35
35
|
version: string | null;
|
|
36
36
|
specifier: string;
|
|
37
37
|
publishedAt: string | null;
|
|
38
38
|
lastSynced: number;
|
|
39
39
|
}
|
|
40
|
+
interface ResolvedPackageVersionWithMetadata extends ResolvedPackageVersion, PackageVersionMeta {
|
|
41
|
+
}
|
|
40
42
|
|
|
41
|
-
interface FetchOptions {
|
|
43
|
+
interface FetchOptions<Throw extends boolean = true> {
|
|
44
|
+
/**
|
|
45
|
+
* API endpoint for fetching package versions
|
|
46
|
+
*
|
|
47
|
+
* @default 'https://npm.antfu.dev/'
|
|
48
|
+
*/
|
|
42
49
|
apiEndpoint?: string;
|
|
43
50
|
/**
|
|
44
51
|
* Fetch function
|
|
52
|
+
*
|
|
53
|
+
* @default [globalThis.fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
|
|
45
54
|
*/
|
|
46
55
|
fetch?: typeof fetch;
|
|
47
56
|
/**
|
|
48
57
|
* Should throw error or return error object
|
|
49
58
|
*
|
|
50
|
-
* @default
|
|
59
|
+
* @default true
|
|
51
60
|
*/
|
|
52
|
-
throw?:
|
|
61
|
+
throw?: Throw;
|
|
53
62
|
}
|
|
54
|
-
interface GetVersionsOptions<
|
|
63
|
+
interface GetVersionsOptions<Metadata extends boolean = false, Throw extends boolean = true> extends FetchOptions<Throw> {
|
|
55
64
|
/**
|
|
56
65
|
* By pass cache and get the latest data
|
|
66
|
+
*
|
|
67
|
+
* @default false
|
|
57
68
|
*/
|
|
58
69
|
force?: boolean;
|
|
59
70
|
/**
|
|
60
71
|
* Include all versions that are newer than the specified version
|
|
72
|
+
*
|
|
73
|
+
* @default false
|
|
61
74
|
*/
|
|
62
75
|
loose?: boolean;
|
|
63
76
|
/**
|
|
64
77
|
* Includes metadata, this will change the return type
|
|
78
|
+
*
|
|
79
|
+
* @default false
|
|
65
80
|
*/
|
|
66
|
-
metadata?:
|
|
81
|
+
metadata?: Metadata;
|
|
67
82
|
}
|
|
68
|
-
interface GetLatestVersionOptions extends FetchOptions {
|
|
83
|
+
interface GetLatestVersionOptions<Metadata extends boolean = false, Throw extends boolean = true> extends FetchOptions<Throw> {
|
|
69
84
|
/**
|
|
70
85
|
* By pass cache and get the latest data
|
|
86
|
+
*
|
|
87
|
+
* @default false
|
|
71
88
|
*/
|
|
72
89
|
force?: boolean;
|
|
73
90
|
/**
|
|
74
91
|
* Includes metadata
|
|
92
|
+
*
|
|
93
|
+
* @default false
|
|
75
94
|
*/
|
|
76
|
-
metadata?:
|
|
95
|
+
metadata?: Metadata;
|
|
77
96
|
}
|
|
97
|
+
type InferGetVersionsResult<Metadata, Throw> = Metadata extends true ? Throw extends true ? PackageVersionsInfoWithMetadata : MaybeError<PackageVersionsInfoWithMetadata> : Throw extends true ? PackageVersionsInfo : MaybeError<PackageVersionsInfo>;
|
|
98
|
+
type InferGetLatestVersionResult<Metadata, Throw> = Metadata extends true ? Throw extends true ? ResolvedPackageVersionWithMetadata : MaybeError<ResolvedPackageVersionWithMetadata> : Throw extends true ? ResolvedPackageVersion : MaybeError<ResolvedPackageVersion>;
|
|
78
99
|
declare const defaultOptions: {
|
|
79
100
|
/**
|
|
80
101
|
* API endpoint for fetching package versions
|
|
@@ -83,12 +104,10 @@ declare const defaultOptions: {
|
|
|
83
104
|
*/
|
|
84
105
|
apiEndpoint: string;
|
|
85
106
|
};
|
|
86
|
-
declare function getLatestVersionBatch(packages: string[], options?: GetLatestVersionOptions): Promise<
|
|
87
|
-
declare function getLatestVersion(name: string, options?: GetLatestVersionOptions): Promise<
|
|
88
|
-
declare function getVersionsBatch(packages: string[], options?: GetVersionsOptions<
|
|
89
|
-
declare function
|
|
90
|
-
declare function getVersions(name: string, options?: GetVersionsOptions<false>): Promise<MaybeError<PackageVersionsInfo>>;
|
|
91
|
-
declare function getVersions(name: string, options: GetVersionsOptions<true>): Promise<MaybeError<PackageVersionsInfoWithMetadata>>;
|
|
107
|
+
declare function getLatestVersionBatch<Metadata extends boolean = false, Throw extends boolean = true>(packages: string[], options?: GetLatestVersionOptions<Metadata, Throw>): Promise<InferGetLatestVersionResult<Metadata, Throw>[]>;
|
|
108
|
+
declare function getLatestVersion<Metadata extends boolean = false, Throw extends boolean = true>(name: string, options?: GetLatestVersionOptions<Metadata, Throw>): Promise<InferGetLatestVersionResult<Metadata, Throw>>;
|
|
109
|
+
declare function getVersionsBatch<Metadata extends boolean = false, Throw extends boolean = true>(packages: string[], options?: GetVersionsOptions<Metadata, Throw>): Promise<InferGetVersionsResult<Metadata, Throw>[]>;
|
|
110
|
+
declare function getVersions<Metadata extends boolean = false, Throw extends boolean = true>(name: string, options?: GetVersionsOptions<Metadata, Throw>): Promise<InferGetVersionsResult<Metadata, Throw>>;
|
|
92
111
|
|
|
93
112
|
declare const NPM_REGISTRY = "https://registry.npmjs.org/";
|
|
94
113
|
/**
|
|
@@ -100,4 +119,4 @@ declare const NPM_REGISTRY = "https://registry.npmjs.org/";
|
|
|
100
119
|
*/
|
|
101
120
|
declare function pickRegistry(scope: string | null | undefined, npmConfigs: Record<string, unknown>, defaultRegistry?: string): string;
|
|
102
121
|
|
|
103
|
-
export { type FetchOptions, type GetLatestVersionOptions, type GetVersionsOptions, NPM_REGISTRY, type PackageManifest, type ResolvedPackageVersion, defaultOptions, getLatestVersion, getLatestVersionBatch, getVersions, getVersionsBatch, pickRegistry };
|
|
122
|
+
export { type FetchOptions, type GetLatestVersionOptions, type GetVersionsOptions, type InferGetLatestVersionResult, type InferGetVersionsResult, NPM_REGISTRY, type PackageManifest, type ResolvedPackageVersion, defaultOptions, getLatestVersion, getLatestVersionBatch, getVersions, getVersionsBatch, pickRegistry };
|
package/dist/index.mjs
CHANGED
|
@@ -10,7 +10,7 @@ async function getLatestVersionBatch(packages, options = {}) {
|
|
|
10
10
|
const {
|
|
11
11
|
apiEndpoint = defaultOptions.apiEndpoint,
|
|
12
12
|
fetch: fetchApi = fetch,
|
|
13
|
-
throw: throwError =
|
|
13
|
+
throw: throwError = true
|
|
14
14
|
} = options;
|
|
15
15
|
let query = [
|
|
16
16
|
options.force ? "force=true" : "",
|
|
@@ -31,7 +31,7 @@ async function getVersionsBatch(packages, options = {}) {
|
|
|
31
31
|
const {
|
|
32
32
|
apiEndpoint = defaultOptions.apiEndpoint,
|
|
33
33
|
fetch: fetchApi = fetch,
|
|
34
|
-
throw: throwError =
|
|
34
|
+
throw: throwError = true
|
|
35
35
|
} = options;
|
|
36
36
|
let query = [
|
|
37
37
|
options.force ? "force=true" : "",
|