-
Notifications
You must be signed in to change notification settings - Fork 134
/
Copy pathtypes.rs
85 lines (72 loc) · 2.24 KB
/
types.rs
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2024 the JSR authors. All rights reserved. MIT license.
use indexmap::IndexMap;
use serde::Serialize;
use crate::ids::PackageName;
use crate::ids::ScopeName;
use crate::ids::Version;
// TODO: We don't have the @jsr scope on npm
pub const NPM_SCOPE: &str = "jsr";
pub struct NpmMappedJsrPackageName<'a> {
pub scope: &'a ScopeName,
pub package: &'a PackageName,
}
impl std::fmt::Display for NpmMappedJsrPackageName<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "@{NPM_SCOPE}/{}__{}", self.scope, self.package)
}
}
impl std::fmt::Debug for NpmMappedJsrPackageName<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "@{NPM_SCOPE}/{}__{}", self.scope, self.package)
}
}
impl serde::Serialize for NpmMappedJsrPackageName<'_> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
String::serialize(&format!("{self}"), serializer)
}
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct NpmDistInfo {
pub tarball: String,
pub shasum: String,
pub integrity: String,
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct NpmVersionInfo<'a> {
pub name: NpmMappedJsrPackageName<'a>,
pub version: Version,
pub description: String,
pub dist: NpmDistInfo,
pub dependencies: IndexMap<String, String>,
#[serde(skip_serializing_if = "IndexMap::is_empty")]
pub bin: IndexMap<String, String>,
}
#[derive(Debug, Serialize)]
pub struct NpmPackageInfo<'a> {
pub name: NpmMappedJsrPackageName<'a>,
pub description: String,
#[serde(rename = "dist-tags")]
pub dist_tags: IndexMap<String, Version>,
pub versions: IndexMap<Version, NpmVersionInfo<'a>>,
// Used by `npm show <package>`
pub time: IndexMap<String, String>,
}
#[derive(Debug, Serialize)]
pub struct NpmPackageJson<'a> {
pub name: NpmMappedJsrPackageName<'a>,
pub version: Version,
pub homepage: String,
#[serde(rename = "type")]
pub module_type: String,
pub dependencies: IndexMap<String, String>,
pub exports: IndexMap<String, String>,
#[serde(skip_serializing_if = "IndexMap::is_empty")]
pub bin: IndexMap<String, String>,
#[serde(rename = "_jsr_revision")]
pub revision: u32,
}