1use crate::parser::ast::{self, Spanned};
7use crate::parser::ast_schema as schema;
8use crate::policy::Expression as CoreExpression;
9
10impl From<&ast::FileMetadata> for schema::FileMetadata {
15 fn from(m: &ast::FileMetadata) -> Self {
16 schema::FileMetadata {
17 namespace: m.namespace.clone(),
18 version: m.version.clone(),
19 owner: m.owner.clone(),
20 profile: m.profile.clone(),
21 imports: m.imports.iter().map(|i| i.into()).collect(),
22 }
23 }
24}
25
26impl From<&ast::ImportDecl> for schema::ImportDecl {
27 fn from(i: &ast::ImportDecl) -> Self {
28 schema::ImportDecl {
29 specifier: (&i.specifier).into(),
30 from_module: i.from_module.clone(),
31 }
32 }
33}
34
35impl From<&ast::ImportSpecifier> for schema::ImportSpecifier {
36 fn from(s: &ast::ImportSpecifier) -> Self {
37 match s {
38 ast::ImportSpecifier::Named(items) => schema::ImportSpecifier::Named {
39 items: items.iter().map(|i| i.into()).collect(),
40 },
41 ast::ImportSpecifier::Wildcard(alias) => schema::ImportSpecifier::Wildcard {
42 alias: alias.clone(),
43 },
44 }
45 }
46}
47
48impl From<&ast::ImportItem> for schema::ImportItem {
49 fn from(i: &ast::ImportItem) -> Self {
50 schema::ImportItem {
51 name: i.name.clone(),
52 alias: i.alias.clone(),
53 }
54 }
55}
56
57impl From<&ast::PolicyMetadata> for schema::PolicyMetadata {
62 fn from(m: &ast::PolicyMetadata) -> Self {
63 schema::PolicyMetadata {
64 kind: m.kind.as_ref().map(|k| k.into()),
65 modality: m.modality.as_ref().map(|m| m.into()),
66 priority: m.priority,
67 rationale: m.rationale.clone(),
68 tags: m.tags.clone(),
69 }
70 }
71}
72
73impl From<&ast::PolicyKind> for schema::PolicyKind {
74 fn from(k: &ast::PolicyKind) -> Self {
75 match k {
76 ast::PolicyKind::Constraint => schema::PolicyKind::Constraint,
77 ast::PolicyKind::Derivation => schema::PolicyKind::Derivation,
78 ast::PolicyKind::Obligation => schema::PolicyKind::Obligation,
79 }
80 }
81}
82
83impl From<&ast::PolicyModality> for schema::PolicyModality {
84 fn from(m: &ast::PolicyModality) -> Self {
85 match m {
86 ast::PolicyModality::Obligation => schema::PolicyModality::Obligation,
87 ast::PolicyModality::Prohibition => schema::PolicyModality::Prohibition,
88 ast::PolicyModality::Permission => schema::PolicyModality::Permission,
89 }
90 }
91}
92
93impl From<&ast::MetricMetadata> for schema::MetricMetadata {
98 fn from(m: &ast::MetricMetadata) -> Self {
99 schema::MetricMetadata {
100 refresh_interval: m
101 .refresh_interval
102 .map(|d| format!("PT{}S", d.num_seconds())),
103 unit: m.unit.clone(),
104 threshold: m.threshold.map(|d| d.to_string()),
105 severity: m.severity.as_ref().map(|s| s.into()),
106 target: m.target.map(|d| d.to_string()),
107 window: m.window.map(|d| format!("PT{}S", d.num_seconds())),
108 }
109 }
110}
111
112impl From<&crate::primitives::Severity> for schema::Severity {
113 fn from(s: &crate::primitives::Severity) -> Self {
114 match s {
115 crate::primitives::Severity::Info => schema::Severity::Info,
116 crate::primitives::Severity::Warning => schema::Severity::Warning,
117 crate::primitives::Severity::Error => schema::Severity::Error,
118 _ => schema::Severity::Error,
120 }
121 }
122}
123
124impl From<&ast::TargetFormat> for schema::TargetFormat {
129 fn from(t: &ast::TargetFormat) -> Self {
130 match t {
131 ast::TargetFormat::Calm => schema::TargetFormat::Calm,
132 ast::TargetFormat::Kg => schema::TargetFormat::Kg,
133 ast::TargetFormat::Sbvr => schema::TargetFormat::Sbvr,
134 ast::TargetFormat::Protobuf => schema::TargetFormat::Protobuf,
135 }
136 }
137}
138
139impl From<&ast::MappingRule> for schema::MappingRule {
140 fn from(r: &ast::MappingRule) -> Self {
141 schema::MappingRule {
142 primitive_type: r.primitive_type.clone(),
143 primitive_name: r.primitive_name.clone(),
144 target_type: r.target_type.clone(),
145 fields: r.fields.clone(),
146 }
147 }
148}
149
150impl From<&ast::ProjectionOverride> for schema::ProjectionOverride {
151 fn from(o: &ast::ProjectionOverride) -> Self {
152 schema::ProjectionOverride {
153 primitive_type: o.primitive_type.clone(),
154 primitive_name: o.primitive_name.clone(),
155 fields: o.fields.clone(),
156 }
157 }
158}
159
160impl From<&CoreExpression> for schema::Expression {
165 fn from(e: &CoreExpression) -> Self {
166 match e {
167 CoreExpression::Literal(v) => schema::Expression::Literal { value: v.clone() },
168 CoreExpression::QuantityLiteral { value, unit } => {
169 schema::Expression::QuantityLiteral {
170 value: value.to_string(),
171 unit: unit.clone(),
172 }
173 }
174 CoreExpression::TimeLiteral(ts) => schema::Expression::TimeLiteral {
175 timestamp: ts.clone(),
176 },
177 CoreExpression::IntervalLiteral { start, end } => schema::Expression::IntervalLiteral {
178 start: start.clone(),
179 end: end.clone(),
180 },
181 CoreExpression::Variable(name) => schema::Expression::Variable { name: name.clone() },
182 CoreExpression::GroupBy {
183 variable,
184 collection,
185 filter,
186 key,
187 condition,
188 } => schema::Expression::GroupBy {
189 variable: variable.clone(),
190 collection: Box::new(collection.as_ref().into()),
191 filter: filter.as_ref().map(|f| Box::new(f.as_ref().into())),
192 key: Box::new(key.as_ref().into()),
193 condition: Box::new(condition.as_ref().into()),
194 },
195 CoreExpression::Binary { op, left, right } => schema::Expression::Binary {
196 op: op.into(),
197 left: Box::new(left.as_ref().into()),
198 right: Box::new(right.as_ref().into()),
199 },
200 CoreExpression::Unary { op, operand } => schema::Expression::Unary {
201 op: op.into(),
202 operand: Box::new(operand.as_ref().into()),
203 },
204 CoreExpression::Cast {
205 operand,
206 target_type,
207 } => schema::Expression::Cast {
208 operand: Box::new(operand.as_ref().into()),
209 target_type: target_type.clone(),
210 },
211 CoreExpression::Quantifier {
212 quantifier,
213 variable,
214 collection,
215 condition,
216 } => schema::Expression::Quantifier {
217 quantifier: quantifier.into(),
218 variable: variable.clone(),
219 collection: Box::new(collection.as_ref().into()),
220 condition: Box::new(condition.as_ref().into()),
221 },
222 CoreExpression::MemberAccess { object, member } => schema::Expression::MemberAccess {
223 object: object.clone(),
224 member: member.clone(),
225 },
226 CoreExpression::Aggregation {
227 function,
228 collection,
229 field,
230 filter,
231 } => schema::Expression::Aggregation {
232 function: function.into(),
233 collection: Box::new(collection.as_ref().into()),
234 field: field.clone(),
235 filter: filter.as_ref().map(|f| Box::new(f.as_ref().into())),
236 },
237 CoreExpression::AggregationComprehension {
238 function,
239 variable,
240 collection,
241 window,
242 predicate,
243 projection,
244 target_unit,
245 } => schema::Expression::AggregationComprehension {
246 function: function.into(),
247 variable: variable.clone(),
248 collection: Box::new(collection.as_ref().into()),
249 window: window.as_ref().map(|w| w.into()),
250 predicate: Box::new(predicate.as_ref().into()),
251 projection: Box::new(projection.as_ref().into()),
252 target_unit: target_unit.clone(),
253 },
254 CoreExpression::RoleReference { role } => {
255 schema::Expression::RoleReference { role: role.clone() }
256 }
257 }
258 }
259}
260
261impl From<&crate::policy::BinaryOp> for schema::BinaryOp {
262 fn from(op: &crate::policy::BinaryOp) -> Self {
263 match op {
264 crate::policy::BinaryOp::And => schema::BinaryOp::And,
265 crate::policy::BinaryOp::Or => schema::BinaryOp::Or,
266 crate::policy::BinaryOp::Equal => schema::BinaryOp::Equal,
267 crate::policy::BinaryOp::NotEqual => schema::BinaryOp::NotEqual,
268 crate::policy::BinaryOp::GreaterThan => schema::BinaryOp::GreaterThan,
269 crate::policy::BinaryOp::LessThan => schema::BinaryOp::LessThan,
270 crate::policy::BinaryOp::GreaterThanOrEqual => schema::BinaryOp::GreaterThanOrEqual,
271 crate::policy::BinaryOp::LessThanOrEqual => schema::BinaryOp::LessThanOrEqual,
272 crate::policy::BinaryOp::Plus => schema::BinaryOp::Plus,
273 crate::policy::BinaryOp::Minus => schema::BinaryOp::Minus,
274 crate::policy::BinaryOp::Multiply => schema::BinaryOp::Multiply,
275 crate::policy::BinaryOp::Divide => schema::BinaryOp::Divide,
276 crate::policy::BinaryOp::Contains => schema::BinaryOp::Contains,
277 crate::policy::BinaryOp::StartsWith => schema::BinaryOp::StartsWith,
278 crate::policy::BinaryOp::EndsWith => schema::BinaryOp::EndsWith,
279 crate::policy::BinaryOp::Matches => schema::BinaryOp::Matches,
280 crate::policy::BinaryOp::HasRole => schema::BinaryOp::HasRole,
281 crate::policy::BinaryOp::Before => schema::BinaryOp::Before,
282 crate::policy::BinaryOp::After => schema::BinaryOp::After,
283 crate::policy::BinaryOp::During => schema::BinaryOp::During,
284 }
285 }
286}
287
288impl From<&crate::policy::UnaryOp> for schema::UnaryOp {
289 fn from(op: &crate::policy::UnaryOp) -> Self {
290 match op {
291 crate::policy::UnaryOp::Not => schema::UnaryOp::Not,
292 crate::policy::UnaryOp::Negate => schema::UnaryOp::Negate,
293 }
294 }
295}
296
297impl From<&crate::policy::Quantifier> for schema::Quantifier {
298 fn from(q: &crate::policy::Quantifier) -> Self {
299 match q {
300 crate::policy::Quantifier::ForAll => schema::Quantifier::ForAll,
301 crate::policy::Quantifier::Exists => schema::Quantifier::Exists,
302 crate::policy::Quantifier::ExistsUnique => schema::Quantifier::ExistsUnique,
303 }
304 }
305}
306
307impl From<&crate::policy::AggregateFunction> for schema::AggregateFunction {
308 fn from(f: &crate::policy::AggregateFunction) -> Self {
309 match f {
310 crate::policy::AggregateFunction::Count => schema::AggregateFunction::Count,
311 crate::policy::AggregateFunction::Sum => schema::AggregateFunction::Sum,
312 crate::policy::AggregateFunction::Min => schema::AggregateFunction::Min,
313 crate::policy::AggregateFunction::Max => schema::AggregateFunction::Max,
314 crate::policy::AggregateFunction::Avg => schema::AggregateFunction::Avg,
315 }
316 }
317}
318
319impl From<&crate::policy::WindowSpec> for schema::WindowSpec {
320 fn from(w: &crate::policy::WindowSpec) -> Self {
321 schema::WindowSpec {
322 duration: w.duration,
323 unit: "seconds".to_string(),
324 }
325 }
326}
327
328impl From<&Spanned<ast::AstNode>> for schema::SpannedAstNode {
333 fn from(s: &Spanned<ast::AstNode>) -> Self {
334 schema::SpannedAstNode {
335 node: (&s.node).into(),
336 line: s.line,
337 column: s.column,
338 }
339 }
340}
341
342impl From<&ast::AstNode> for schema::AstNode {
343 fn from(n: &ast::AstNode) -> Self {
344 match n {
345 ast::AstNode::Export(inner) => schema::AstNode::Export {
346 declaration: Box::new(inner.as_ref().into()),
347 },
348 ast::AstNode::Entity {
349 name,
350 version,
351 annotations,
352 domain,
353 body,
354 } => schema::AstNode::Entity {
355 name: name.clone(),
356 version: version.clone(),
357 annotations: annotations.clone(),
358 domain: domain.clone(),
359 body: body.as_ref().map(|b| b.into()),
360 },
361 ast::AstNode::Record(r) => schema::AstNode::Record {
362 declaration: r.into(),
363 },
364 ast::AstNode::Enum(e) => schema::AstNode::Enum {
365 declaration: e.into(),
366 },
367 ast::AstNode::Operation(o) => schema::AstNode::Operation {
368 declaration: o.into(),
369 },
370 ast::AstNode::Resource {
371 name,
372 annotations,
373 unit_name,
374 domain,
375 } => schema::AstNode::Resource {
376 name: name.clone(),
377 annotations: annotations.clone(),
378 unit_name: unit_name.clone(),
379 domain: domain.clone(),
380 },
381 ast::AstNode::Flow {
382 resource_name,
383 annotations,
384 from_entity,
385 to_entity,
386 quantity,
387 } => schema::AstNode::Flow {
388 resource_name: resource_name.clone(),
389 annotations: annotations.clone(),
390 from_entity: from_entity.clone(),
391 to_entity: to_entity.clone(),
392 quantity: quantity.map(|d| d.to_string()),
393 },
394 ast::AstNode::Pattern { name, regex } => schema::AstNode::Pattern {
395 name: name.clone(),
396 regex: regex.clone(),
397 },
398 ast::AstNode::Role { name, domain } => schema::AstNode::Role {
399 name: name.clone(),
400 domain: domain.clone(),
401 },
402 ast::AstNode::Relation {
403 name,
404 subject_role,
405 predicate,
406 object_role,
407 via_flow,
408 } => schema::AstNode::Relation {
409 name: name.clone(),
410 subject_role: subject_role.clone(),
411 predicate: predicate.clone(),
412 object_role: object_role.clone(),
413 via_flow: via_flow.clone(),
414 },
415 ast::AstNode::Dimension { name } => schema::AstNode::Dimension { name: name.clone() },
416 ast::AstNode::UnitDeclaration {
417 symbol,
418 dimension,
419 factor,
420 base_unit,
421 } => schema::AstNode::UnitDeclaration {
422 symbol: symbol.clone(),
423 dimension: dimension.clone(),
424 factor: factor.to_string(),
425 base_unit: base_unit.clone(),
426 },
427 ast::AstNode::Policy {
428 name,
429 version,
430 metadata,
431 expression,
432 } => schema::AstNode::Policy {
433 name: name.clone(),
434 version: version.clone(),
435 metadata: metadata.into(),
436 expression: expression.into(),
437 },
438 ast::AstNode::Instance {
439 name,
440 entity_type,
441 fields,
442 } => schema::AstNode::Instance {
443 name: name.clone(),
444 entity_type: entity_type.clone(),
445 fields: fields.iter().map(|(k, v)| (k.clone(), v.into())).collect(),
446 },
447 ast::AstNode::ConceptChange {
448 name,
449 from_version,
450 to_version,
451 migration_policy,
452 breaking_change,
453 } => schema::AstNode::ConceptChange {
454 name: name.clone(),
455 from_version: from_version.clone(),
456 to_version: to_version.clone(),
457 migration_policy: migration_policy.clone(),
458 breaking_change: *breaking_change,
459 },
460 ast::AstNode::Metric {
461 name,
462 expression,
463 metadata,
464 } => schema::AstNode::Metric {
465 name: name.clone(),
466 expression: expression.into(),
467 metadata: metadata.into(),
468 },
469 ast::AstNode::MappingDecl {
470 name,
471 target,
472 rules,
473 } => schema::AstNode::MappingDecl {
474 name: name.clone(),
475 target: target.into(),
476 rules: rules.iter().map(|r| r.into()).collect(),
477 },
478 ast::AstNode::ProjectionDecl {
479 name,
480 target,
481 overrides,
482 } => schema::AstNode::ProjectionDecl {
483 name: name.clone(),
484 target: target.into(),
485 overrides: overrides.iter().map(|o| o.into()).collect(),
486 },
487 ast::AstNode::Cell { name, annotations } => schema::AstNode::Cell {
488 name: name.clone(),
489 annotations: annotations.clone(),
490 },
491 ast::AstNode::SystemDependency {
492 name,
493 version,
494 annotations,
495 } => schema::AstNode::SystemDependency {
496 name: name.clone(),
497 version: version.clone(),
498 annotations: annotations.clone(),
499 },
500 ast::AstNode::Runtime {
501 name,
502 version,
503 annotations,
504 } => schema::AstNode::Runtime {
505 name: name.clone(),
506 version: version.clone(),
507 annotations: annotations.clone(),
508 },
509 ast::AstNode::Tool {
510 name,
511 version,
512 annotations,
513 } => schema::AstNode::Tool {
514 name: name.clone(),
515 version: version.clone(),
516 annotations: annotations.clone(),
517 },
518 ast::AstNode::DependencySet { name, annotations } => schema::AstNode::DependencySet {
519 name: name.clone(),
520 annotations: annotations.clone(),
521 },
522 ast::AstNode::Service {
523 name,
524 version,
525 annotations,
526 } => schema::AstNode::Service {
527 name: name.clone(),
528 version: version.clone(),
529 annotations: annotations.clone(),
530 },
531 ast::AstNode::Mount { name, annotations } => schema::AstNode::Mount {
532 name: name.clone(),
533 annotations: annotations.clone(),
534 },
535 ast::AstNode::Endpoint { name, annotations } => schema::AstNode::Endpoint {
536 name: name.clone(),
537 annotations: annotations.clone(),
538 },
539 ast::AstNode::NetworkFlow {
540 name,
541 from_ref,
542 to_ref,
543 annotations,
544 } => schema::AstNode::NetworkFlow {
545 name: name.clone(),
546 from_ref: from_ref.clone(),
547 to_ref: to_ref.clone(),
548 annotations: annotations.clone(),
549 },
550 ast::AstNode::Credential { name, annotations } => schema::AstNode::Credential {
551 name: name.clone(),
552 annotations: annotations.clone(),
553 },
554 }
555 }
556}
557
558impl From<&ast::Ast> for schema::Ast {
563 fn from(a: &ast::Ast) -> Self {
564 schema::Ast {
565 metadata: (&a.metadata).into(),
566 declarations: a.declarations.iter().map(|d| d.into()).collect(),
567 }
568 }
569}
570
571impl From<ast::Ast> for schema::Ast {
572 fn from(a: ast::Ast) -> Self {
573 (&a).into()
574 }
575}
576
577impl From<&ast::EntityBody> for schema::EntityBody {
580 fn from(b: &ast::EntityBody) -> Self {
581 schema::EntityBody {
582 fields: b.fields.iter().map(|f| f.into()).collect(),
583 }
584 }
585}
586
587impl From<&ast::FieldDecl> for schema::FieldDecl {
588 fn from(f: &ast::FieldDecl) -> Self {
589 schema::FieldDecl {
590 is_key: f.is_key,
591 name: f.name.clone(),
592 field_type: (&f.field_type).into(),
593 is_optional: f.is_optional,
594 constraints: f.constraints.iter().map(|c| c.into()).collect(),
595 default: f.default.as_ref().map(|e| e.into()),
596 }
597 }
598}
599
600impl From<&ast::FieldType> for schema::FieldType {
601 fn from(t: &ast::FieldType) -> Self {
602 match t {
603 ast::FieldType::Scalar(s) => schema::FieldType::Scalar { symbol: s.into() },
604 ast::FieldType::Quantity(s) => schema::FieldType::Quantity { symbol: s.into() },
605 ast::FieldType::Ref(s) => schema::FieldType::Ref { symbol: s.into() },
606 ast::FieldType::Named(s) => schema::FieldType::Named { symbol: s.into() },
607 ast::FieldType::List(elem) => schema::FieldType::List {
608 element: Box::new(elem.as_ref().into()),
609 },
610 }
611 }
612}
613
614impl From<&ast::FieldTypeRef> for schema::FieldTypeRef {
615 fn from(r: &ast::FieldTypeRef) -> Self {
616 schema::FieldTypeRef {
617 alias: r.alias.clone(),
618 symbol: r.symbol.clone(),
619 }
620 }
621}
622
623impl From<&ast::FieldConstraintDecl> for schema::FieldConstraintDecl {
624 fn from(c: &ast::FieldConstraintDecl) -> Self {
625 match c {
626 ast::FieldConstraintDecl::MinLength(v) => {
627 schema::FieldConstraintDecl::MinLength { value: *v }
628 }
629 ast::FieldConstraintDecl::MaxLength(v) => {
630 schema::FieldConstraintDecl::MaxLength { value: *v }
631 }
632 ast::FieldConstraintDecl::MinItems(v) => {
633 schema::FieldConstraintDecl::MinItems { value: *v }
634 }
635 ast::FieldConstraintDecl::MaxItems(v) => {
636 schema::FieldConstraintDecl::MaxItems { value: *v }
637 }
638 ast::FieldConstraintDecl::ExclusiveMin(v) => {
639 schema::FieldConstraintDecl::ExclusiveMin {
640 value: v.to_string(),
641 }
642 }
643 ast::FieldConstraintDecl::ExclusiveMax(v) => {
644 schema::FieldConstraintDecl::ExclusiveMax {
645 value: v.to_string(),
646 }
647 }
648 ast::FieldConstraintDecl::Min(v) => schema::FieldConstraintDecl::Min {
649 value: v.to_string(),
650 },
651 ast::FieldConstraintDecl::Max(v) => schema::FieldConstraintDecl::Max {
652 value: v.to_string(),
653 },
654 ast::FieldConstraintDecl::Pattern(s) => {
655 schema::FieldConstraintDecl::Pattern { symbol: s.clone() }
656 }
657 }
658 }
659}
660
661impl From<&ast::RecordDecl> for schema::RecordDecl {
662 fn from(r: &ast::RecordDecl) -> Self {
663 schema::RecordDecl {
664 name: r.name.clone(),
665 fields: r.fields.iter().map(|f| f.into()).collect(),
666 }
667 }
668}
669
670impl From<&ast::EnumDecl> for schema::EnumDecl {
671 fn from(e: &ast::EnumDecl) -> Self {
672 schema::EnumDecl {
673 name: e.name.clone(),
674 members: e
675 .members
676 .iter()
677 .map(|m| schema::EnumMember {
678 name: m.name.clone(),
679 wire: m.wire.clone(),
680 })
681 .collect(),
682 }
683 }
684}
685
686impl From<&ast::OperationDecl> for schema::OperationDecl {
687 fn from(o: &ast::OperationDecl) -> Self {
688 schema::OperationDecl {
689 name: o.name.clone(),
690 clauses: o.clauses.iter().map(|c| c.into()).collect(),
691 }
692 }
693}
694
695impl From<&ast::OperationClause> for schema::OperationClause {
696 fn from(c: &ast::OperationClause) -> Self {
697 match c {
698 ast::OperationClause::Intent(text) => {
699 schema::OperationClause::Intent { text: text.clone() }
700 }
701 ast::OperationClause::Direction { kind } => {
702 schema::OperationClause::Direction { kind: kind.clone() }
703 }
704 ast::OperationClause::Actor { actor } => schema::OperationClause::Actor {
705 actor: actor.clone(),
706 },
707 ast::OperationClause::AccessPublic => schema::OperationClause::AccessPublic,
708 ast::OperationClause::AccessPolicyGoverned { bindings } => {
709 schema::OperationClause::AccessPolicyGoverned {
710 bindings: bindings.iter().map(|b| b.into()).collect(),
711 }
712 }
713 ast::OperationClause::Input { reference } => schema::OperationClause::Input {
714 reference: reference.clone(),
715 },
716 ast::OperationClause::Output { reference } => schema::OperationClause::Output {
717 reference: reference.clone(),
718 },
719 ast::OperationClause::State { reference } => schema::OperationClause::State {
720 reference: reference.clone(),
721 },
722 ast::OperationClause::Effect { kind, reference } => schema::OperationClause::Effect {
723 kind: kind.clone(),
724 reference: reference.clone(),
725 },
726 ast::OperationClause::Transaction { kind } => {
727 schema::OperationClause::Transaction { kind: kind.clone() }
728 }
729 ast::OperationClause::Failure {
730 code,
731 kinds,
732 message,
733 } => schema::OperationClause::Failure {
734 code: code.clone(),
735 kinds: kinds.clone(),
736 message: message.clone(),
737 },
738 ast::OperationClause::IdempotencyKeyed { field } => {
739 schema::OperationClause::IdempotencyKeyed {
740 field: field.clone(),
741 }
742 }
743 ast::OperationClause::IdempotencyInherent => {
744 schema::OperationClause::IdempotencyInherent
745 }
746 ast::OperationClause::IdempotencyNotApplicable {
747 reason,
748 explanation,
749 } => schema::OperationClause::IdempotencyNotApplicable {
750 reason: reason.clone(),
751 explanation: explanation.clone(),
752 },
753 ast::OperationClause::ConcurrencyUnique { field } => {
754 schema::OperationClause::ConcurrencyUnique {
755 field: field.clone(),
756 }
757 }
758 ast::OperationClause::ConcurrencyOptimistic { field } => {
759 schema::OperationClause::ConcurrencyOptimistic {
760 field: field.clone(),
761 }
762 }
763 ast::OperationClause::ConcurrencyReadSnapshot => {
764 schema::OperationClause::ConcurrencyReadSnapshot
765 }
766 ast::OperationClause::EvidenceOperationTrace => {
767 schema::OperationClause::EvidenceOperationTrace
768 }
769 ast::OperationClause::LifecycleSynchronousRequestResponse => {
770 schema::OperationClause::LifecycleSynchronousRequestResponse
771 }
772 }
773 }
774}
775
776impl From<&ast::PolicyBinding> for schema::PolicyBinding {
777 fn from(b: &ast::PolicyBinding) -> Self {
778 schema::PolicyBinding {
779 policy: b.policy.clone(),
780 enforcement_point: b.enforcement_point.clone(),
781 failure_code: b.failure_code.clone(),
782 }
783 }
784}