pub struct GeneratedPackage { /* private fields */ }Expand description
An ordered in-memory package with normalized relative paths.
Implementations§
Source§impl GeneratedPackage
impl GeneratedPackage
Sourcepub const fn files(&self) -> &BTreeMap<String, Vec<u8>>
pub const fn files(&self) -> &BTreeMap<String, Vec<u8>>
Return files in bytewise path order.
Examples found in repository?
examples/emit_python_acceptance.rs (line 63)
16fn main() {
17 let mut arguments = env::args_os().skip(1);
18 let schema_path = PathBuf::from(arguments.next().expect("schema path is required"));
19 let output_path = PathBuf::from(arguments.next().expect("output path is required"));
20 assert!(
21 arguments.next().is_none(),
22 "only schema and output paths are accepted"
23 );
24
25 let source = fs::read_to_string(&schema_path).expect("acceptance schema is readable");
26 let documents = SchemaDocumentSet::parse([(
27 DocumentId::new("python-acceptance.yaml").expect("document ID is valid"),
28 source,
29 )])
30 .expect("acceptance schema parses");
31 let declared = normalize_documents(&documents).expect("acceptance schema normalizes");
32 let profile_name = env::var("TYPE_BRIDGE_ACCEPTANCE_SEMANTIC_PROFILE")
33 .unwrap_or_else(|_| "typedb-3.12.1/v1".to_owned());
34 let profile = SemanticProfileId::new(&profile_name).expect("semantic profile is valid");
35 let resolved = resolve(&declared, &profile).expect("acceptance schema resolves");
36 let emitter = PythonEmitter::new();
37 let handlers = emitter.generator_handlers();
38 let resources = emitter.code_resources().expect("emitter resources hash");
39 let projection = project(
40 &resolved,
41 BindingTarget::Python,
42 &ProjectionConfig::python(),
43 &handlers,
44 &resources,
45 )
46 .expect("acceptance schema projects");
47 let available: CapabilitySet = BUILTIN_SCHEMA_CAPABILITY_IDS
48 .iter()
49 .map(|id| CapabilityId::new(*id).expect("built-in capability ID"))
50 .collect();
51 let context = ManagedDeltaContext::new(
52 ManagedScopeId::new("python-generated-acceptance").expect("acceptance scope"),
53 profile,
54 available,
55 );
56 let authority = build_schema_authority(&declared, declared.required_capabilities(), &context)
57 .expect("acceptance authority builds");
58 let package = emitter
59 .emit(&projection, &authority)
60 .expect("Python package emits");
61
62 fs::create_dir_all(&output_path).expect("output directory is created");
63 for (relative, bytes) in package.files() {
64 fs::write(output_path.join(relative), bytes).expect("generated file is written");
65 }
66}More examples
examples/emit_typescript_acceptance.rs (line 63)
16fn main() {
17 let mut arguments = env::args_os().skip(1);
18 let schema_path = PathBuf::from(arguments.next().expect("schema path is required"));
19 let output_path = PathBuf::from(arguments.next().expect("output path is required"));
20 assert!(
21 arguments.next().is_none(),
22 "only schema and output paths are accepted"
23 );
24
25 let source = fs::read_to_string(&schema_path).expect("acceptance schema is readable");
26 let documents = SchemaDocumentSet::parse([(
27 DocumentId::new("typescript-acceptance.yaml").expect("document ID is valid"),
28 source,
29 )])
30 .expect("acceptance schema parses");
31 let declared = normalize_documents(&documents).expect("acceptance schema normalizes");
32 let profile_name = env::var("TYPE_BRIDGE_ACCEPTANCE_SEMANTIC_PROFILE")
33 .unwrap_or_else(|_| "typedb-3.12.1/v1".to_owned());
34 let profile = SemanticProfileId::new(&profile_name).expect("semantic profile is valid");
35 let resolved = resolve(&declared, &profile).expect("acceptance schema resolves");
36 let emitter = TypeScriptEmitter::new();
37 let handlers = emitter.generator_handlers();
38 let resources = emitter.code_resources().expect("emitter resources hash");
39 let projection = project(
40 &resolved,
41 BindingTarget::TypeScript,
42 &ProjectionConfig::typescript(),
43 &handlers,
44 &resources,
45 )
46 .expect("acceptance schema projects");
47 let available: CapabilitySet = BUILTIN_SCHEMA_CAPABILITY_IDS
48 .iter()
49 .map(|id| CapabilityId::new(*id).expect("built-in capability ID"))
50 .collect();
51 let context = ManagedDeltaContext::new(
52 ManagedScopeId::new("node-generated-acceptance").expect("acceptance scope"),
53 profile,
54 available,
55 );
56 let authority = build_schema_authority(&declared, declared.required_capabilities(), &context)
57 .expect("acceptance authority builds");
58 let package = emitter
59 .emit(&projection, &authority)
60 .expect("TypeScript package emits");
61
62 fs::create_dir_all(&output_path).expect("output directory is created");
63 for (relative, bytes) in package.files() {
64 let path = output_path.join(relative);
65 if let Some(parent) = path.parent() {
66 fs::create_dir_all(parent).expect("generated parent directory is created");
67 }
68 fs::write(path, bytes).expect("generated file is written");
69 }
70}Trait Implementations§
Source§impl Clone for GeneratedPackage
impl Clone for GeneratedPackage
Source§fn clone(&self) -> GeneratedPackage
fn clone(&self) -> GeneratedPackage
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for GeneratedPackage
impl Debug for GeneratedPackage
impl Eq for GeneratedPackage
Source§impl PartialEq for GeneratedPackage
impl PartialEq for GeneratedPackage
impl StructuralPartialEq for GeneratedPackage
Auto Trait Implementations§
impl Freeze for GeneratedPackage
impl RefUnwindSafe for GeneratedPackage
impl Send for GeneratedPackage
impl Sync for GeneratedPackage
impl Unpin for GeneratedPackage
impl UnsafeUnpin for GeneratedPackage
impl UnwindSafe for GeneratedPackage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more