Skip to content

Commit 5f5d62c

Browse files
committed
wip_resource_id
1 parent dfea2f0 commit 5f5d62c

File tree

22 files changed

+159
-130
lines changed

22 files changed

+159
-130
lines changed

lib/bencher_client/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ from_client!(
4141
Index,
4242
Jwt,
4343
NonEmpty,
44-
ResourceId,
44+
// ResourceId,
4545
ResourceName,
4646
SampleSize,
4747
Slug,

lib/bencher_json/src/lib.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ pub use bencher_context::RunContext;
44
pub use bencher_valid::{
55
BenchmarkName, Boundary, BranchName, CdfBoundary, DateTime, DateTimeMillis, Email, GitHash,
66
Index, IqrBoundary, Jwt, Model, ModelTest, NameId, NonEmpty, PercentageBoundary, ResourceId,
7-
ResourceIdKind, ResourceName, SampleSize, Sanitize, Search, Secret, Slug, Units, Url, UserName,
8-
ValidError, Window,
7+
ResourceName, SampleSize, Sanitize, Search, Secret, Slug, Units, Url, UserName, ValidError,
8+
Window,
99
};
1010
#[cfg(feature = "plus")]
1111
pub use bencher_valid::{
@@ -35,30 +35,40 @@ pub use organization::{plan::JsonPlan, usage::JsonUsage};
3535

3636
pub use big_int::BigInt;
3737
pub use organization::{
38-
JsonNewOrganization, JsonOrganization, JsonOrganizations, OrganizationUuid,
38+
JsonNewOrganization, JsonOrganization, JsonOrganizations, OrganizationResourceId,
39+
OrganizationSlug, OrganizationUuid,
3940
claim::JsonNewClaim,
4041
member::{JsonMember, JsonMembers},
4142
};
4243
pub use pagination::{JsonDirection, JsonPagination};
4344
pub use project::{
44-
JsonNewProject, JsonProject, JsonProjects, ProjectUuid,
45+
JsonNewProject, JsonProject, JsonProjects, ProjectResourceId, ProjectSlug, ProjectUuid,
4546
alert::{AlertUuid, JsonAlert, JsonAlerts},
46-
benchmark::{BenchmarkNameId, BenchmarkSlug, BenchmarkUuid, JsonBenchmark, JsonBenchmarks},
47+
benchmark::{
48+
BenchmarkNameId, BenchmarkResourceId, BenchmarkSlug, BenchmarkUuid, JsonBenchmark,
49+
JsonBenchmarks,
50+
},
4751
boundary::{BoundaryUuid, JsonBoundaries, JsonBoundary},
4852
branch::{
49-
BranchNameId, BranchSlug, BranchUuid, JsonBranch, JsonBranches, JsonNewBranch,
50-
JsonNewStartPoint,
53+
BranchNameId, BranchResourceId, BranchSlug, BranchUuid, JsonBranch, JsonBranches,
54+
JsonNewBranch, JsonNewStartPoint,
5155
},
5256
head::{HeadUuid, JsonHead, JsonStartPoint, VersionUuid},
53-
measure::{JsonMeasure, JsonMeasures, JsonNewMeasure, MeasureNameId, MeasureSlug, MeasureUuid},
57+
measure::{
58+
JsonMeasure, JsonMeasures, JsonNewMeasure, MeasureNameId, MeasureResourceId, MeasureSlug,
59+
MeasureUuid,
60+
},
5461
metric::{
5562
JsonMetric, JsonMetricsMap, JsonNewMetric, JsonOneMetric, JsonResultsMap, MetricUuid,
5663
},
5764
model::{JsonModel, ModelUuid},
5865
perf::{JsonPerf, JsonPerfQuery, ReportBenchmarkUuid},
5966
plot::{JsonNewPlot, JsonPlot, JsonPlots, PlotUuid},
6067
report::{JsonNewReport, JsonReport, JsonReports, ReportUuid},
61-
testbed::{JsonNewTestbed, JsonTestbed, JsonTestbeds, TestbedNameId, TestbedSlug, TestbedUuid},
68+
testbed::{
69+
JsonNewTestbed, JsonTestbed, JsonTestbeds, TestbedNameId, TestbedResourceId, TestbedSlug,
70+
TestbedUuid,
71+
},
6272
threshold::{JsonNewThreshold, JsonThreshold, JsonThresholds, ThresholdUuid},
6373
};
6474
pub use run::JsonNewRun;
@@ -78,7 +88,7 @@ pub use system::{
7888
version::JsonApiVersion,
7989
};
8090
pub use user::{
81-
JsonPubUser, JsonUpdateUser, JsonUser, JsonUsers, UserUuid,
91+
JsonPubUser, JsonUpdateUser, JsonUser, JsonUsers, UserResourceId, UserSlug, UserUuid,
8292
token::{JsonNewToken, JsonToken, JsonTokens, TokenUuid},
8393
};
8494

lib/bencher_json/src/organization/mod.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::fmt;
22

3-
use bencher_valid::{DateTime, ResourceName, Slug};
3+
use bencher_valid::{DateTime, ResourceId, ResourceName, Slug};
44
use derive_more::Display;
55
#[cfg(feature = "schema")]
66
use schemars::JsonSchema;
@@ -9,14 +9,19 @@ use serde::{
99
de::{self, Visitor},
1010
};
1111

12-
use crate::UserUuid;
12+
use crate::{ProjectSlug, UserUuid};
1313

1414
pub mod claim;
1515
pub mod member;
1616
pub mod plan;
1717
pub mod usage;
1818

1919
crate::typed_uuid::typed_uuid!(OrganizationUuid);
20+
crate::typed_slug::typed_slug!(OrganizationSlug, ResourceName);
21+
22+
/// An organization UUID or slug.
23+
#[typeshare::typeshare]
24+
pub type OrganizationResourceId = ResourceId<OrganizationUuid, OrganizationSlug>;
2025

2126
// Create a personal organization for a user.
2227
impl From<UserUuid> for OrganizationUuid {
@@ -25,6 +30,12 @@ impl From<UserUuid> for OrganizationUuid {
2530
}
2631
}
2732

33+
impl From<ProjectSlug> for OrganizationSlug {
34+
fn from(slug: ProjectSlug) -> Self {
35+
Self(Slug::from(slug))
36+
}
37+
}
38+
2839
#[derive(Debug, Clone, Deserialize, Serialize)]
2940
#[cfg_attr(feature = "schema", derive(JsonSchema))]
3041
pub struct JsonNewOrganization {
@@ -35,7 +46,7 @@ pub struct JsonNewOrganization {
3546
/// If not provided, the slug will be generated from the name.
3647
/// If the provided or generated slug is already in use, a unique slug will be generated.
3748
/// Maximum length is 64 characters.
38-
pub slug: Option<Slug>,
49+
pub slug: Option<OrganizationSlug>,
3950
}
4051

4152
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -50,7 +61,7 @@ crate::from_vec!(JsonOrganizations[JsonOrganization]);
5061
pub struct JsonOrganization {
5162
pub uuid: OrganizationUuid,
5263
pub name: ResourceName,
53-
pub slug: Slug,
64+
pub slug: OrganizationSlug,
5465
#[cfg(feature = "plus")]
5566
pub license: Option<bencher_valid::Jwt>,
5667
pub created: DateTime,
@@ -85,7 +96,7 @@ pub struct JsonOrganizationPatch {
8596
pub name: Option<ResourceName>,
8697
/// The preferred new slug for the organization.
8798
/// Maximum length is 64 characters.
88-
pub slug: Option<Slug>,
99+
pub slug: Option<OrganizationSlug>,
89100
/// ➕ Bencher Plus: The new license for the organization.
90101
/// Set to `null` to remove the current license.
91102
#[cfg(feature = "plus")]
@@ -96,7 +107,7 @@ pub struct JsonOrganizationPatch {
96107
#[cfg_attr(feature = "schema", derive(JsonSchema))]
97108
pub struct JsonOrganizationPatchNull {
98109
pub name: Option<ResourceName>,
99-
pub slug: Option<Slug>,
110+
pub slug: Option<OrganizationSlug>,
100111
#[cfg(feature = "plus")]
101112
pub license: (),
102113
}

lib/bencher_json/src/project/benchmark.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::fmt;
22

3-
use bencher_valid::{BenchmarkName, DateTime, NameId};
3+
use bencher_valid::{BenchmarkName, DateTime, NameId, ResourceId};
44
#[cfg(feature = "schema")]
55
use schemars::JsonSchema;
66
use serde::{Deserialize, Serialize};
@@ -10,6 +10,10 @@ use crate::ProjectUuid;
1010
crate::typed_uuid::typed_uuid!(BenchmarkUuid);
1111
crate::typed_slug::typed_slug!(BenchmarkSlug, BenchmarkName);
1212

13+
/// An benchmark UUID or slug.
14+
#[typeshare::typeshare]
15+
pub type BenchmarkResourceId = ResourceId<BenchmarkUuid, BenchmarkSlug>;
16+
1317
/// A benchmark UUID, slug, or name.
1418
#[typeshare::typeshare]
1519
pub type BenchmarkNameId = NameId<BenchmarkUuid, BenchmarkSlug, BenchmarkName>;

lib/bencher_json/src/project/branch.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt;
22
use std::sync::LazyLock;
33

4-
use bencher_valid::{BranchName, DateTime, GitHash, NameId};
4+
use bencher_valid::{BranchName, DateTime, GitHash, NameId, ResourceId};
55
#[cfg(feature = "schema")]
66
use schemars::JsonSchema;
77
use serde::{Deserialize, Serialize};
@@ -35,6 +35,10 @@ static BRANCH_MAIN_SLUG: LazyLock<Option<BranchSlug>> = LazyLock::new(|| {
3535
crate::typed_uuid::typed_uuid!(BranchUuid);
3636
crate::typed_slug::typed_slug!(BranchSlug, BranchName);
3737

38+
/// An branch UUID or slug.
39+
#[typeshare::typeshare]
40+
pub type BranchResourceId = ResourceId<BranchUuid, BranchSlug>;
41+
3842
/// A branch UUID, slug, or name.
3943
#[typeshare::typeshare]
4044
pub type BranchNameId = NameId<BranchUuid, BranchSlug, BranchName>;

lib/bencher_json/src/project/measure/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{fmt, sync::LazyLock};
22

3-
use bencher_valid::{DateTime, NameId, ResourceName};
3+
use bencher_valid::{DateTime, NameId, ResourceId, ResourceName};
44
#[cfg(feature = "schema")]
55
use schemars::JsonSchema;
66
use serde::{Deserialize, Serialize};
@@ -19,6 +19,10 @@ pub static DEFAULT_UNIT: LazyLock<ResourceName> = LazyLock::new(|| {
1919
crate::typed_uuid::typed_uuid!(MeasureUuid);
2020
crate::typed_slug::typed_slug!(MeasureSlug, ResourceName);
2121

22+
/// An measure UUID or slug.
23+
#[typeshare::typeshare]
24+
pub type MeasureResourceId = ResourceId<MeasureUuid, MeasureSlug>;
25+
2226
/// A measure UUID, slug, or name.
2327
#[typeshare::typeshare]
2428
pub type MeasureNameId = NameId<MeasureUuid, MeasureSlug, ResourceName>;

lib/bencher_json/src/project/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{
33
str::FromStr,
44
};
55

6-
use bencher_valid::{DateTime, ResourceName, Slug, Url};
6+
use bencher_valid::{DateTime, ResourceId, ResourceName, Url};
77
#[cfg(feature = "schema")]
88
use schemars::JsonSchema;
99
use serde::{
@@ -28,6 +28,11 @@ pub mod testbed;
2828
pub mod threshold;
2929

3030
crate::typed_uuid::typed_uuid!(ProjectUuid);
31+
crate::typed_slug::typed_slug!(ProjectSlug, ResourceName);
32+
33+
/// An project UUID or slug.
34+
#[typeshare::typeshare]
35+
pub type ProjectResourceId = ResourceId<ProjectUuid, ProjectSlug>;
3136

3237
// Create a project from an organization.
3338
impl From<OrganizationUuid> for ProjectUuid {
@@ -47,7 +52,7 @@ pub struct JsonNewProject {
4752
/// If not provided, the slug will be generated from the name.
4853
/// If the provided or generated slug is already in use, a unique slug will be generated.
4954
/// Maximum length is 64 characters.
50-
pub slug: Option<Slug>,
55+
pub slug: Option<ProjectSlug>,
5156
/// The URL for the project.
5257
/// If the project is public, the URL will be accessible listed on its Perf Page.
5358
pub url: Option<Url>,
@@ -69,7 +74,7 @@ pub struct JsonProject {
6974
pub uuid: ProjectUuid,
7075
pub organization: OrganizationUuid,
7176
pub name: ResourceName,
72-
pub slug: Slug,
77+
pub slug: ProjectSlug,
7378
pub url: Option<Url>,
7479
pub visibility: Visibility,
7580
pub created: DateTime,
@@ -110,7 +115,7 @@ pub struct JsonProjectPatch {
110115
pub name: Option<ResourceName>,
111116
/// The preferred new slug for the project.
112117
/// Maximum length is 64 characters.
113-
pub slug: Option<Slug>,
118+
pub slug: Option<ProjectSlug>,
114119
/// The new URL of the project.
115120
/// Set to `null` to remove the current URL.
116121
pub url: Option<Url>,
@@ -123,7 +128,7 @@ pub struct JsonProjectPatch {
123128
#[cfg_attr(feature = "schema", derive(JsonSchema))]
124129
pub struct JsonProjectPatchNull {
125130
pub name: Option<ResourceName>,
126-
pub slug: Option<Slug>,
131+
pub slug: Option<ProjectSlug>,
127132
pub url: (),
128133
pub visibility: Option<Visibility>,
129134
}

lib/bencher_json/src/project/testbed.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt;
22
use std::sync::LazyLock;
33

4-
use bencher_valid::{DateTime, NameId, ResourceName};
4+
use bencher_valid::{DateTime, NameId, ResourceId, ResourceName};
55
#[cfg(feature = "schema")]
66
use schemars::JsonSchema;
77
use serde::{Deserialize, Serialize};
@@ -33,6 +33,10 @@ static TESTBED_LOCALHOST_SLUG: LazyLock<Option<TestbedSlug>> = LazyLock::new(||
3333
crate::typed_uuid::typed_uuid!(TestbedUuid);
3434
crate::typed_slug::typed_slug!(TestbedSlug, ResourceName);
3535

36+
/// An testbed UUID or slug.
37+
#[typeshare::typeshare]
38+
pub type TestbedResourceId = ResourceId<TestbedUuid, TestbedSlug>;
39+
3640
/// A testbed UUID, slug, or name.
3741
#[typeshare::typeshare]
3842
pub type TestbedNameId = NameId<TestbedUuid, TestbedSlug, ResourceName>;

lib/bencher_json/src/run.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use bencher_context::RunContext;
2-
use bencher_valid::{DateTime, GitHash, ResourceId};
2+
use bencher_valid::{DateTime, GitHash};
33
#[cfg(feature = "schema")]
44
use schemars::JsonSchema;
55
use serde::{Deserialize, Serialize};
66

77
use crate::{
8-
BranchNameId, TestbedNameId,
8+
BranchNameId, ProjectResourceId, TestbedNameId,
99
project::{
1010
branch::JsonUpdateStartPoint,
1111
report::{JsonReportSettings, JsonReportThresholds},
@@ -23,7 +23,7 @@ use crate::{
2323
pub struct JsonNewRun {
2424
/// Project UUID or slug.
2525
/// If the project is not provided or does not exist, it will be created.
26-
pub project: Option<ResourceId>,
26+
pub project: Option<ProjectResourceId>,
2727
/// Branch UUID, slug, or name.
2828
/// If the branch is not provided or does not exist, it will be created.
2929
pub branch: Option<BranchNameId>,

lib/bencher_json/src/system/payment.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
use bencher_valid::{
44
CardCvc, CardNumber, Email, Entitlements, ExpirationMonth, ExpirationYear, NonEmpty, PlanLevel,
5-
ResourceId,
65
};
76
#[cfg(feature = "schema")]
87
use schemars::JsonSchema;
98
use serde::{Deserialize, Serialize};
109

11-
use crate::{OrganizationUuid, UserUuid};
10+
use crate::{OrganizationResourceId, OrganizationUuid, UserUuid};
1211

1312
#[typeshare::typeshare]
1413
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -49,7 +48,7 @@ pub struct JsonPayment {
4948
#[derive(Debug, Clone, Serialize, Deserialize)]
5049
#[cfg_attr(feature = "schema", derive(JsonSchema))]
5150
pub struct JsonNewCheckout {
52-
pub organization: ResourceId,
51+
pub organization: OrganizationResourceId,
5352
pub level: PlanLevel,
5453
pub entitlements: Option<Entitlements>,
5554
pub self_hosted: Option<OrganizationUuid>,

0 commit comments

Comments
 (0)