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