1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::CowStr;
14
15#[allow(unused_imports)]
16use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
17use jacquard_common::types::string::Datetime;
18use jacquard_derive::{IntoStatic, lexicon, open_union};
19use jacquard_lexicon::lexicon::LexiconDoc;
20use jacquard_lexicon::schema::LexiconSchema;
21
22#[allow(unused_imports)]
23use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
24use serde::{Serialize, Deserialize};
25use crate::sh_tangled::repo::tree;
26
27#[lexicon]
28#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
29#[serde(rename_all = "camelCase")]
30pub struct LastCommit<'a> {
31 #[serde(skip_serializing_if = "Option::is_none")]
32 #[serde(borrow)]
33 pub author: Option<tree::Signature<'a>>,
34 #[serde(borrow)]
36 pub hash: CowStr<'a>,
37 #[serde(borrow)]
39 pub message: CowStr<'a>,
40 pub when: Datetime,
42}
43
44
45#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
46#[serde(rename_all = "camelCase")]
47pub struct Tree<'a> {
48 #[serde(default = "_default_path")]
50 #[serde(skip_serializing_if = "Option::is_none")]
51 #[serde(borrow)]
52 pub path: Option<CowStr<'a>>,
53 #[serde(borrow)]
54 pub r#ref: CowStr<'a>,
55 #[serde(borrow)]
56 pub repo: CowStr<'a>,
57}
58
59
60#[lexicon]
61#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
62#[serde(rename_all = "camelCase")]
63pub struct TreeOutput<'a> {
64 #[serde(skip_serializing_if = "Option::is_none")]
66 #[serde(borrow)]
67 pub dotdot: Option<CowStr<'a>>,
68 #[serde(borrow)]
69 pub files: Vec<tree::TreeEntry<'a>>,
70 #[serde(skip_serializing_if = "Option::is_none")]
71 #[serde(borrow)]
72 pub last_commit: Option<tree::LastCommit<'a>>,
73 #[serde(skip_serializing_if = "Option::is_none")]
75 #[serde(borrow)]
76 pub parent: Option<CowStr<'a>>,
77 #[serde(skip_serializing_if = "Option::is_none")]
79 #[serde(borrow)]
80 pub readme: Option<tree::Readme<'a>>,
81 #[serde(borrow)]
83 pub r#ref: CowStr<'a>,
84}
85
86
87#[open_union]
88#[derive(
89 Serialize,
90 Deserialize,
91 Debug,
92 Clone,
93 PartialEq,
94 Eq,
95 thiserror::Error,
96 miette::Diagnostic,
97 IntoStatic
98)]
99
100#[serde(tag = "error", content = "message")]
101#[serde(bound(deserialize = "'de: 'a"))]
102pub enum TreeError<'a> {
103 #[serde(rename = "RepoNotFound")]
105 RepoNotFound(Option<CowStr<'a>>),
106 #[serde(rename = "RefNotFound")]
108 RefNotFound(Option<CowStr<'a>>),
109 #[serde(rename = "PathNotFound")]
111 PathNotFound(Option<CowStr<'a>>),
112 #[serde(rename = "InvalidRequest")]
114 InvalidRequest(Option<CowStr<'a>>),
115}
116
117impl core::fmt::Display for TreeError<'_> {
118 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
119 match self {
120 Self::RepoNotFound(msg) => {
121 write!(f, "RepoNotFound")?;
122 if let Some(msg) = msg {
123 write!(f, ": {}", msg)?;
124 }
125 Ok(())
126 }
127 Self::RefNotFound(msg) => {
128 write!(f, "RefNotFound")?;
129 if let Some(msg) = msg {
130 write!(f, ": {}", msg)?;
131 }
132 Ok(())
133 }
134 Self::PathNotFound(msg) => {
135 write!(f, "PathNotFound")?;
136 if let Some(msg) = msg {
137 write!(f, ": {}", msg)?;
138 }
139 Ok(())
140 }
141 Self::InvalidRequest(msg) => {
142 write!(f, "InvalidRequest")?;
143 if let Some(msg) = msg {
144 write!(f, ": {}", msg)?;
145 }
146 Ok(())
147 }
148 Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
149 }
150 }
151}
152
153
154#[lexicon]
155#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
156#[serde(rename_all = "camelCase")]
157pub struct Readme<'a> {
158 #[serde(borrow)]
160 pub contents: CowStr<'a>,
161 #[serde(borrow)]
163 pub filename: CowStr<'a>,
164}
165
166
167#[lexicon]
168#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
169#[serde(rename_all = "camelCase")]
170pub struct Signature<'a> {
171 #[serde(borrow)]
173 pub email: CowStr<'a>,
174 #[serde(borrow)]
176 pub name: CowStr<'a>,
177 pub when: Datetime,
179}
180
181
182#[lexicon]
183#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
184#[serde(rename_all = "camelCase")]
185pub struct TreeEntry<'a> {
186 #[serde(skip_serializing_if = "Option::is_none")]
187 #[serde(borrow)]
188 pub last_commit: Option<tree::LastCommit<'a>>,
189 #[serde(borrow)]
191 pub mode: CowStr<'a>,
192 #[serde(borrow)]
194 pub name: CowStr<'a>,
195 pub size: i64,
197}
198
199impl<'a> LexiconSchema for LastCommit<'a> {
200 fn nsid() -> &'static str {
201 "sh.tangled.repo.tree"
202 }
203 fn def_name() -> &'static str {
204 "lastCommit"
205 }
206 fn lexicon_doc() -> LexiconDoc<'static> {
207 lexicon_doc_sh_tangled_repo_tree()
208 }
209 fn validate(&self) -> Result<(), ConstraintError> {
210 Ok(())
211 }
212}
213
214pub struct TreeResponse;
216impl jacquard_common::xrpc::XrpcResp for TreeResponse {
217 const NSID: &'static str = "sh.tangled.repo.tree";
218 const ENCODING: &'static str = "application/json";
219 type Output<'de> = TreeOutput<'de>;
220 type Err<'de> = TreeError<'de>;
221}
222
223impl<'a> jacquard_common::xrpc::XrpcRequest for Tree<'a> {
224 const NSID: &'static str = "sh.tangled.repo.tree";
225 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
226 type Response = TreeResponse;
227}
228
229pub struct TreeRequest;
231impl jacquard_common::xrpc::XrpcEndpoint for TreeRequest {
232 const PATH: &'static str = "/xrpc/sh.tangled.repo.tree";
233 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
234 type Request<'de> = Tree<'de>;
235 type Response = TreeResponse;
236}
237
238impl<'a> LexiconSchema for Readme<'a> {
239 fn nsid() -> &'static str {
240 "sh.tangled.repo.tree"
241 }
242 fn def_name() -> &'static str {
243 "readme"
244 }
245 fn lexicon_doc() -> LexiconDoc<'static> {
246 lexicon_doc_sh_tangled_repo_tree()
247 }
248 fn validate(&self) -> Result<(), ConstraintError> {
249 Ok(())
250 }
251}
252
253impl<'a> LexiconSchema for Signature<'a> {
254 fn nsid() -> &'static str {
255 "sh.tangled.repo.tree"
256 }
257 fn def_name() -> &'static str {
258 "signature"
259 }
260 fn lexicon_doc() -> LexiconDoc<'static> {
261 lexicon_doc_sh_tangled_repo_tree()
262 }
263 fn validate(&self) -> Result<(), ConstraintError> {
264 Ok(())
265 }
266}
267
268impl<'a> LexiconSchema for TreeEntry<'a> {
269 fn nsid() -> &'static str {
270 "sh.tangled.repo.tree"
271 }
272 fn def_name() -> &'static str {
273 "treeEntry"
274 }
275 fn lexicon_doc() -> LexiconDoc<'static> {
276 lexicon_doc_sh_tangled_repo_tree()
277 }
278 fn validate(&self) -> Result<(), ConstraintError> {
279 Ok(())
280 }
281}
282
283pub mod last_commit_state {
284
285 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
286 #[allow(unused)]
287 use ::core::marker::PhantomData;
288 mod sealed {
289 pub trait Sealed {}
290 }
291 pub trait State: sealed::Sealed {
293 type When;
294 type Hash;
295 type Message;
296 }
297 pub struct Empty(());
299 impl sealed::Sealed for Empty {}
300 impl State for Empty {
301 type When = Unset;
302 type Hash = Unset;
303 type Message = Unset;
304 }
305 pub struct SetWhen<S: State = Empty>(PhantomData<fn() -> S>);
307 impl<S: State> sealed::Sealed for SetWhen<S> {}
308 impl<S: State> State for SetWhen<S> {
309 type When = Set<members::when>;
310 type Hash = S::Hash;
311 type Message = S::Message;
312 }
313 pub struct SetHash<S: State = Empty>(PhantomData<fn() -> S>);
315 impl<S: State> sealed::Sealed for SetHash<S> {}
316 impl<S: State> State for SetHash<S> {
317 type When = S::When;
318 type Hash = Set<members::hash>;
319 type Message = S::Message;
320 }
321 pub struct SetMessage<S: State = Empty>(PhantomData<fn() -> S>);
323 impl<S: State> sealed::Sealed for SetMessage<S> {}
324 impl<S: State> State for SetMessage<S> {
325 type When = S::When;
326 type Hash = S::Hash;
327 type Message = Set<members::message>;
328 }
329 #[allow(non_camel_case_types)]
331 pub mod members {
332 pub struct when(());
334 pub struct hash(());
336 pub struct message(());
338 }
339}
340
341pub struct LastCommitBuilder<'a, S: last_commit_state::State> {
343 _state: PhantomData<fn() -> S>,
344 _fields: (
345 Option<tree::Signature<'a>>,
346 Option<CowStr<'a>>,
347 Option<CowStr<'a>>,
348 Option<Datetime>,
349 ),
350 _lifetime: PhantomData<&'a ()>,
351}
352
353impl<'a> LastCommit<'a> {
354 pub fn new() -> LastCommitBuilder<'a, last_commit_state::Empty> {
356 LastCommitBuilder::new()
357 }
358}
359
360impl<'a> LastCommitBuilder<'a, last_commit_state::Empty> {
361 pub fn new() -> Self {
363 LastCommitBuilder {
364 _state: PhantomData,
365 _fields: (None, None, None, None),
366 _lifetime: PhantomData,
367 }
368 }
369}
370
371impl<'a, S: last_commit_state::State> LastCommitBuilder<'a, S> {
372 pub fn author(mut self, value: impl Into<Option<tree::Signature<'a>>>) -> Self {
374 self._fields.0 = value.into();
375 self
376 }
377 pub fn maybe_author(mut self, value: Option<tree::Signature<'a>>) -> Self {
379 self._fields.0 = value;
380 self
381 }
382}
383
384impl<'a, S> LastCommitBuilder<'a, S>
385where
386 S: last_commit_state::State,
387 S::Hash: last_commit_state::IsUnset,
388{
389 pub fn hash(
391 mut self,
392 value: impl Into<CowStr<'a>>,
393 ) -> LastCommitBuilder<'a, last_commit_state::SetHash<S>> {
394 self._fields.1 = Option::Some(value.into());
395 LastCommitBuilder {
396 _state: PhantomData,
397 _fields: self._fields,
398 _lifetime: PhantomData,
399 }
400 }
401}
402
403impl<'a, S> LastCommitBuilder<'a, S>
404where
405 S: last_commit_state::State,
406 S::Message: last_commit_state::IsUnset,
407{
408 pub fn message(
410 mut self,
411 value: impl Into<CowStr<'a>>,
412 ) -> LastCommitBuilder<'a, last_commit_state::SetMessage<S>> {
413 self._fields.2 = Option::Some(value.into());
414 LastCommitBuilder {
415 _state: PhantomData,
416 _fields: self._fields,
417 _lifetime: PhantomData,
418 }
419 }
420}
421
422impl<'a, S> LastCommitBuilder<'a, S>
423where
424 S: last_commit_state::State,
425 S::When: last_commit_state::IsUnset,
426{
427 pub fn when(
429 mut self,
430 value: impl Into<Datetime>,
431 ) -> LastCommitBuilder<'a, last_commit_state::SetWhen<S>> {
432 self._fields.3 = Option::Some(value.into());
433 LastCommitBuilder {
434 _state: PhantomData,
435 _fields: self._fields,
436 _lifetime: PhantomData,
437 }
438 }
439}
440
441impl<'a, S> LastCommitBuilder<'a, S>
442where
443 S: last_commit_state::State,
444 S::When: last_commit_state::IsSet,
445 S::Hash: last_commit_state::IsSet,
446 S::Message: last_commit_state::IsSet,
447{
448 pub fn build(self) -> LastCommit<'a> {
450 LastCommit {
451 author: self._fields.0,
452 hash: self._fields.1.unwrap(),
453 message: self._fields.2.unwrap(),
454 when: self._fields.3.unwrap(),
455 extra_data: Default::default(),
456 }
457 }
458 pub fn build_with_data(
460 self,
461 extra_data: BTreeMap<
462 jacquard_common::deps::smol_str::SmolStr,
463 jacquard_common::types::value::Data<'a>,
464 >,
465 ) -> LastCommit<'a> {
466 LastCommit {
467 author: self._fields.0,
468 hash: self._fields.1.unwrap(),
469 message: self._fields.2.unwrap(),
470 when: self._fields.3.unwrap(),
471 extra_data: Some(extra_data),
472 }
473 }
474}
475
476fn lexicon_doc_sh_tangled_repo_tree() -> LexiconDoc<'static> {
477 #[allow(unused_imports)]
478 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
479 use jacquard_lexicon::lexicon::*;
480 use alloc::collections::BTreeMap;
481 LexiconDoc {
482 lexicon: Lexicon::Lexicon1,
483 id: CowStr::new_static("sh.tangled.repo.tree"),
484 defs: {
485 let mut map = BTreeMap::new();
486 map.insert(
487 SmolStr::new_static("lastCommit"),
488 LexUserType::Object(LexObject {
489 required: Some(
490 vec![
491 SmolStr::new_static("hash"), SmolStr::new_static("message"),
492 SmolStr::new_static("when")
493 ],
494 ),
495 properties: {
496 #[allow(unused_mut)]
497 let mut map = BTreeMap::new();
498 map.insert(
499 SmolStr::new_static("author"),
500 LexObjectProperty::Ref(LexRef {
501 r#ref: CowStr::new_static("#signature"),
502 ..Default::default()
503 }),
504 );
505 map.insert(
506 SmolStr::new_static("hash"),
507 LexObjectProperty::String(LexString {
508 description: Some(CowStr::new_static("Commit hash")),
509 ..Default::default()
510 }),
511 );
512 map.insert(
513 SmolStr::new_static("message"),
514 LexObjectProperty::String(LexString {
515 description: Some(CowStr::new_static("Commit message")),
516 ..Default::default()
517 }),
518 );
519 map.insert(
520 SmolStr::new_static("when"),
521 LexObjectProperty::String(LexString {
522 description: Some(CowStr::new_static("Commit timestamp")),
523 format: Some(LexStringFormat::Datetime),
524 ..Default::default()
525 }),
526 );
527 map
528 },
529 ..Default::default()
530 }),
531 );
532 map.insert(
533 SmolStr::new_static("main"),
534 LexUserType::XrpcQuery(LexXrpcQuery {
535 parameters: Some(
536 LexXrpcQueryParameter::Params(LexXrpcParameters {
537 required: Some(
538 vec![
539 SmolStr::new_static("repo"), SmolStr::new_static("ref")
540 ],
541 ),
542 properties: {
543 #[allow(unused_mut)]
544 let mut map = BTreeMap::new();
545 map.insert(
546 SmolStr::new_static("path"),
547 LexXrpcParametersProperty::String(LexString {
548 description: Some(
549 CowStr::new_static("Path within the repository tree"),
550 ),
551 ..Default::default()
552 }),
553 );
554 map.insert(
555 SmolStr::new_static("ref"),
556 LexXrpcParametersProperty::String(LexString {
557 description: Some(
558 CowStr::new_static(
559 "Git reference (branch, tag, or commit SHA)",
560 ),
561 ),
562 ..Default::default()
563 }),
564 );
565 map.insert(
566 SmolStr::new_static("repo"),
567 LexXrpcParametersProperty::String(LexString {
568 description: Some(
569 CowStr::new_static(
570 "Repository identifier in format 'did:plc:.../repoName'",
571 ),
572 ),
573 ..Default::default()
574 }),
575 );
576 map
577 },
578 ..Default::default()
579 }),
580 ),
581 ..Default::default()
582 }),
583 );
584 map.insert(
585 SmolStr::new_static("readme"),
586 LexUserType::Object(LexObject {
587 required: Some(
588 vec![
589 SmolStr::new_static("filename"),
590 SmolStr::new_static("contents")
591 ],
592 ),
593 properties: {
594 #[allow(unused_mut)]
595 let mut map = BTreeMap::new();
596 map.insert(
597 SmolStr::new_static("contents"),
598 LexObjectProperty::String(LexString {
599 description: Some(
600 CowStr::new_static("Contents of the readme file"),
601 ),
602 ..Default::default()
603 }),
604 );
605 map.insert(
606 SmolStr::new_static("filename"),
607 LexObjectProperty::String(LexString {
608 description: Some(
609 CowStr::new_static("Name of the readme file"),
610 ),
611 ..Default::default()
612 }),
613 );
614 map
615 },
616 ..Default::default()
617 }),
618 );
619 map.insert(
620 SmolStr::new_static("signature"),
621 LexUserType::Object(LexObject {
622 required: Some(
623 vec![
624 SmolStr::new_static("name"), SmolStr::new_static("email"),
625 SmolStr::new_static("when")
626 ],
627 ),
628 properties: {
629 #[allow(unused_mut)]
630 let mut map = BTreeMap::new();
631 map.insert(
632 SmolStr::new_static("email"),
633 LexObjectProperty::String(LexString {
634 description: Some(CowStr::new_static("Author email")),
635 ..Default::default()
636 }),
637 );
638 map.insert(
639 SmolStr::new_static("name"),
640 LexObjectProperty::String(LexString {
641 description: Some(CowStr::new_static("Author name")),
642 ..Default::default()
643 }),
644 );
645 map.insert(
646 SmolStr::new_static("when"),
647 LexObjectProperty::String(LexString {
648 description: Some(CowStr::new_static("Author timestamp")),
649 format: Some(LexStringFormat::Datetime),
650 ..Default::default()
651 }),
652 );
653 map
654 },
655 ..Default::default()
656 }),
657 );
658 map.insert(
659 SmolStr::new_static("treeEntry"),
660 LexUserType::Object(LexObject {
661 required: Some(
662 vec![
663 SmolStr::new_static("name"), SmolStr::new_static("mode"),
664 SmolStr::new_static("size")
665 ],
666 ),
667 properties: {
668 #[allow(unused_mut)]
669 let mut map = BTreeMap::new();
670 map.insert(
671 SmolStr::new_static("last_commit"),
672 LexObjectProperty::Ref(LexRef {
673 r#ref: CowStr::new_static("#lastCommit"),
674 ..Default::default()
675 }),
676 );
677 map.insert(
678 SmolStr::new_static("mode"),
679 LexObjectProperty::String(LexString {
680 description: Some(CowStr::new_static("File mode")),
681 ..Default::default()
682 }),
683 );
684 map.insert(
685 SmolStr::new_static("name"),
686 LexObjectProperty::String(LexString {
687 description: Some(
688 CowStr::new_static("Relative file or directory name"),
689 ),
690 ..Default::default()
691 }),
692 );
693 map.insert(
694 SmolStr::new_static("size"),
695 LexObjectProperty::Integer(LexInteger {
696 ..Default::default()
697 }),
698 );
699 map
700 },
701 ..Default::default()
702 }),
703 );
704 map
705 },
706 ..Default::default()
707 }
708}
709
710fn _default_path() -> Option<CowStr<'static>> {
711 Some(CowStr::from(""))
712}
713
714pub mod tree_state {
715
716 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
717 #[allow(unused)]
718 use ::core::marker::PhantomData;
719 mod sealed {
720 pub trait Sealed {}
721 }
722 pub trait State: sealed::Sealed {
724 type Ref;
725 type Repo;
726 }
727 pub struct Empty(());
729 impl sealed::Sealed for Empty {}
730 impl State for Empty {
731 type Ref = Unset;
732 type Repo = Unset;
733 }
734 pub struct SetRef<S: State = Empty>(PhantomData<fn() -> S>);
736 impl<S: State> sealed::Sealed for SetRef<S> {}
737 impl<S: State> State for SetRef<S> {
738 type Ref = Set<members::r#ref>;
739 type Repo = S::Repo;
740 }
741 pub struct SetRepo<S: State = Empty>(PhantomData<fn() -> S>);
743 impl<S: State> sealed::Sealed for SetRepo<S> {}
744 impl<S: State> State for SetRepo<S> {
745 type Ref = S::Ref;
746 type Repo = Set<members::repo>;
747 }
748 #[allow(non_camel_case_types)]
750 pub mod members {
751 pub struct r#ref(());
753 pub struct repo(());
755 }
756}
757
758pub struct TreeBuilder<'a, S: tree_state::State> {
760 _state: PhantomData<fn() -> S>,
761 _fields: (Option<CowStr<'a>>, Option<CowStr<'a>>, Option<CowStr<'a>>),
762 _lifetime: PhantomData<&'a ()>,
763}
764
765impl<'a> Tree<'a> {
766 pub fn new() -> TreeBuilder<'a, tree_state::Empty> {
768 TreeBuilder::new()
769 }
770}
771
772impl<'a> TreeBuilder<'a, tree_state::Empty> {
773 pub fn new() -> Self {
775 TreeBuilder {
776 _state: PhantomData,
777 _fields: (None, None, None),
778 _lifetime: PhantomData,
779 }
780 }
781}
782
783impl<'a, S: tree_state::State> TreeBuilder<'a, S> {
784 pub fn path(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
786 self._fields.0 = value.into();
787 self
788 }
789 pub fn maybe_path(mut self, value: Option<CowStr<'a>>) -> Self {
791 self._fields.0 = value;
792 self
793 }
794}
795
796impl<'a, S> TreeBuilder<'a, S>
797where
798 S: tree_state::State,
799 S::Ref: tree_state::IsUnset,
800{
801 pub fn r#ref(
803 mut self,
804 value: impl Into<CowStr<'a>>,
805 ) -> TreeBuilder<'a, tree_state::SetRef<S>> {
806 self._fields.1 = Option::Some(value.into());
807 TreeBuilder {
808 _state: PhantomData,
809 _fields: self._fields,
810 _lifetime: PhantomData,
811 }
812 }
813}
814
815impl<'a, S> TreeBuilder<'a, S>
816where
817 S: tree_state::State,
818 S::Repo: tree_state::IsUnset,
819{
820 pub fn repo(
822 mut self,
823 value: impl Into<CowStr<'a>>,
824 ) -> TreeBuilder<'a, tree_state::SetRepo<S>> {
825 self._fields.2 = Option::Some(value.into());
826 TreeBuilder {
827 _state: PhantomData,
828 _fields: self._fields,
829 _lifetime: PhantomData,
830 }
831 }
832}
833
834impl<'a, S> TreeBuilder<'a, S>
835where
836 S: tree_state::State,
837 S::Ref: tree_state::IsSet,
838 S::Repo: tree_state::IsSet,
839{
840 pub fn build(self) -> Tree<'a> {
842 Tree {
843 path: self._fields.0,
844 r#ref: self._fields.1.unwrap(),
845 repo: self._fields.2.unwrap(),
846 }
847 }
848}
849
850pub mod signature_state {
851
852 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
853 #[allow(unused)]
854 use ::core::marker::PhantomData;
855 mod sealed {
856 pub trait Sealed {}
857 }
858 pub trait State: sealed::Sealed {
860 type Email;
861 type Name;
862 type When;
863 }
864 pub struct Empty(());
866 impl sealed::Sealed for Empty {}
867 impl State for Empty {
868 type Email = Unset;
869 type Name = Unset;
870 type When = Unset;
871 }
872 pub struct SetEmail<S: State = Empty>(PhantomData<fn() -> S>);
874 impl<S: State> sealed::Sealed for SetEmail<S> {}
875 impl<S: State> State for SetEmail<S> {
876 type Email = Set<members::email>;
877 type Name = S::Name;
878 type When = S::When;
879 }
880 pub struct SetName<S: State = Empty>(PhantomData<fn() -> S>);
882 impl<S: State> sealed::Sealed for SetName<S> {}
883 impl<S: State> State for SetName<S> {
884 type Email = S::Email;
885 type Name = Set<members::name>;
886 type When = S::When;
887 }
888 pub struct SetWhen<S: State = Empty>(PhantomData<fn() -> S>);
890 impl<S: State> sealed::Sealed for SetWhen<S> {}
891 impl<S: State> State for SetWhen<S> {
892 type Email = S::Email;
893 type Name = S::Name;
894 type When = Set<members::when>;
895 }
896 #[allow(non_camel_case_types)]
898 pub mod members {
899 pub struct email(());
901 pub struct name(());
903 pub struct when(());
905 }
906}
907
908pub struct SignatureBuilder<'a, S: signature_state::State> {
910 _state: PhantomData<fn() -> S>,
911 _fields: (Option<CowStr<'a>>, Option<CowStr<'a>>, Option<Datetime>),
912 _lifetime: PhantomData<&'a ()>,
913}
914
915impl<'a> Signature<'a> {
916 pub fn new() -> SignatureBuilder<'a, signature_state::Empty> {
918 SignatureBuilder::new()
919 }
920}
921
922impl<'a> SignatureBuilder<'a, signature_state::Empty> {
923 pub fn new() -> Self {
925 SignatureBuilder {
926 _state: PhantomData,
927 _fields: (None, None, None),
928 _lifetime: PhantomData,
929 }
930 }
931}
932
933impl<'a, S> SignatureBuilder<'a, S>
934where
935 S: signature_state::State,
936 S::Email: signature_state::IsUnset,
937{
938 pub fn email(
940 mut self,
941 value: impl Into<CowStr<'a>>,
942 ) -> SignatureBuilder<'a, signature_state::SetEmail<S>> {
943 self._fields.0 = Option::Some(value.into());
944 SignatureBuilder {
945 _state: PhantomData,
946 _fields: self._fields,
947 _lifetime: PhantomData,
948 }
949 }
950}
951
952impl<'a, S> SignatureBuilder<'a, S>
953where
954 S: signature_state::State,
955 S::Name: signature_state::IsUnset,
956{
957 pub fn name(
959 mut self,
960 value: impl Into<CowStr<'a>>,
961 ) -> SignatureBuilder<'a, signature_state::SetName<S>> {
962 self._fields.1 = Option::Some(value.into());
963 SignatureBuilder {
964 _state: PhantomData,
965 _fields: self._fields,
966 _lifetime: PhantomData,
967 }
968 }
969}
970
971impl<'a, S> SignatureBuilder<'a, S>
972where
973 S: signature_state::State,
974 S::When: signature_state::IsUnset,
975{
976 pub fn when(
978 mut self,
979 value: impl Into<Datetime>,
980 ) -> SignatureBuilder<'a, signature_state::SetWhen<S>> {
981 self._fields.2 = Option::Some(value.into());
982 SignatureBuilder {
983 _state: PhantomData,
984 _fields: self._fields,
985 _lifetime: PhantomData,
986 }
987 }
988}
989
990impl<'a, S> SignatureBuilder<'a, S>
991where
992 S: signature_state::State,
993 S::Email: signature_state::IsSet,
994 S::Name: signature_state::IsSet,
995 S::When: signature_state::IsSet,
996{
997 pub fn build(self) -> Signature<'a> {
999 Signature {
1000 email: self._fields.0.unwrap(),
1001 name: self._fields.1.unwrap(),
1002 when: self._fields.2.unwrap(),
1003 extra_data: Default::default(),
1004 }
1005 }
1006 pub fn build_with_data(
1008 self,
1009 extra_data: BTreeMap<
1010 jacquard_common::deps::smol_str::SmolStr,
1011 jacquard_common::types::value::Data<'a>,
1012 >,
1013 ) -> Signature<'a> {
1014 Signature {
1015 email: self._fields.0.unwrap(),
1016 name: self._fields.1.unwrap(),
1017 when: self._fields.2.unwrap(),
1018 extra_data: Some(extra_data),
1019 }
1020 }
1021}
1022
1023pub mod tree_entry_state {
1024
1025 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
1026 #[allow(unused)]
1027 use ::core::marker::PhantomData;
1028 mod sealed {
1029 pub trait Sealed {}
1030 }
1031 pub trait State: sealed::Sealed {
1033 type Mode;
1034 type Name;
1035 type Size;
1036 }
1037 pub struct Empty(());
1039 impl sealed::Sealed for Empty {}
1040 impl State for Empty {
1041 type Mode = Unset;
1042 type Name = Unset;
1043 type Size = Unset;
1044 }
1045 pub struct SetMode<S: State = Empty>(PhantomData<fn() -> S>);
1047 impl<S: State> sealed::Sealed for SetMode<S> {}
1048 impl<S: State> State for SetMode<S> {
1049 type Mode = Set<members::mode>;
1050 type Name = S::Name;
1051 type Size = S::Size;
1052 }
1053 pub struct SetName<S: State = Empty>(PhantomData<fn() -> S>);
1055 impl<S: State> sealed::Sealed for SetName<S> {}
1056 impl<S: State> State for SetName<S> {
1057 type Mode = S::Mode;
1058 type Name = Set<members::name>;
1059 type Size = S::Size;
1060 }
1061 pub struct SetSize<S: State = Empty>(PhantomData<fn() -> S>);
1063 impl<S: State> sealed::Sealed for SetSize<S> {}
1064 impl<S: State> State for SetSize<S> {
1065 type Mode = S::Mode;
1066 type Name = S::Name;
1067 type Size = Set<members::size>;
1068 }
1069 #[allow(non_camel_case_types)]
1071 pub mod members {
1072 pub struct mode(());
1074 pub struct name(());
1076 pub struct size(());
1078 }
1079}
1080
1081pub struct TreeEntryBuilder<'a, S: tree_entry_state::State> {
1083 _state: PhantomData<fn() -> S>,
1084 _fields: (
1085 Option<tree::LastCommit<'a>>,
1086 Option<CowStr<'a>>,
1087 Option<CowStr<'a>>,
1088 Option<i64>,
1089 ),
1090 _lifetime: PhantomData<&'a ()>,
1091}
1092
1093impl<'a> TreeEntry<'a> {
1094 pub fn new() -> TreeEntryBuilder<'a, tree_entry_state::Empty> {
1096 TreeEntryBuilder::new()
1097 }
1098}
1099
1100impl<'a> TreeEntryBuilder<'a, tree_entry_state::Empty> {
1101 pub fn new() -> Self {
1103 TreeEntryBuilder {
1104 _state: PhantomData,
1105 _fields: (None, None, None, None),
1106 _lifetime: PhantomData,
1107 }
1108 }
1109}
1110
1111impl<'a, S: tree_entry_state::State> TreeEntryBuilder<'a, S> {
1112 pub fn last_commit(
1114 mut self,
1115 value: impl Into<Option<tree::LastCommit<'a>>>,
1116 ) -> Self {
1117 self._fields.0 = value.into();
1118 self
1119 }
1120 pub fn maybe_last_commit(mut self, value: Option<tree::LastCommit<'a>>) -> Self {
1122 self._fields.0 = value;
1123 self
1124 }
1125}
1126
1127impl<'a, S> TreeEntryBuilder<'a, S>
1128where
1129 S: tree_entry_state::State,
1130 S::Mode: tree_entry_state::IsUnset,
1131{
1132 pub fn mode(
1134 mut self,
1135 value: impl Into<CowStr<'a>>,
1136 ) -> TreeEntryBuilder<'a, tree_entry_state::SetMode<S>> {
1137 self._fields.1 = Option::Some(value.into());
1138 TreeEntryBuilder {
1139 _state: PhantomData,
1140 _fields: self._fields,
1141 _lifetime: PhantomData,
1142 }
1143 }
1144}
1145
1146impl<'a, S> TreeEntryBuilder<'a, S>
1147where
1148 S: tree_entry_state::State,
1149 S::Name: tree_entry_state::IsUnset,
1150{
1151 pub fn name(
1153 mut self,
1154 value: impl Into<CowStr<'a>>,
1155 ) -> TreeEntryBuilder<'a, tree_entry_state::SetName<S>> {
1156 self._fields.2 = Option::Some(value.into());
1157 TreeEntryBuilder {
1158 _state: PhantomData,
1159 _fields: self._fields,
1160 _lifetime: PhantomData,
1161 }
1162 }
1163}
1164
1165impl<'a, S> TreeEntryBuilder<'a, S>
1166where
1167 S: tree_entry_state::State,
1168 S::Size: tree_entry_state::IsUnset,
1169{
1170 pub fn size(
1172 mut self,
1173 value: impl Into<i64>,
1174 ) -> TreeEntryBuilder<'a, tree_entry_state::SetSize<S>> {
1175 self._fields.3 = Option::Some(value.into());
1176 TreeEntryBuilder {
1177 _state: PhantomData,
1178 _fields: self._fields,
1179 _lifetime: PhantomData,
1180 }
1181 }
1182}
1183
1184impl<'a, S> TreeEntryBuilder<'a, S>
1185where
1186 S: tree_entry_state::State,
1187 S::Mode: tree_entry_state::IsSet,
1188 S::Name: tree_entry_state::IsSet,
1189 S::Size: tree_entry_state::IsSet,
1190{
1191 pub fn build(self) -> TreeEntry<'a> {
1193 TreeEntry {
1194 last_commit: self._fields.0,
1195 mode: self._fields.1.unwrap(),
1196 name: self._fields.2.unwrap(),
1197 size: self._fields.3.unwrap(),
1198 extra_data: Default::default(),
1199 }
1200 }
1201 pub fn build_with_data(
1203 self,
1204 extra_data: BTreeMap<
1205 jacquard_common::deps::smol_str::SmolStr,
1206 jacquard_common::types::value::Data<'a>,
1207 >,
1208 ) -> TreeEntry<'a> {
1209 TreeEntry {
1210 last_commit: self._fields.0,
1211 mode: self._fields.1.unwrap(),
1212 name: self._fields.2.unwrap(),
1213 size: self._fields.3.unwrap(),
1214 extra_data: Some(extra_data),
1215 }
1216 }
1217}