MCPcopy Create free account
hub / github.com/hashintel/hash / index

Function index

libs/@local/graph/authorization/tests/codegen.rs:10–65  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8
9#[test]
10fn index() -> io::Result<()> {
11 let mut collection = TypeCollection::default();
12 collection.make_branded::<policies::PolicyId>();
13
14 let settings = TypeScriptGeneratorSettings::default();
15 let mut generator = TypeScriptGenerator::new(&settings, &collection);
16
17 generator.add_import_declaration(
18 "@blockprotocol/type-system-rs/types",
19 [
20 "ActorId",
21 "ActorType",
22 "ActorGroupId",
23 "BaseUrl",
24 "EntityUuid",
25 "OntologyTypeVersion",
26 "RoleId",
27 "WebId",
28 ],
29 );
30 generator.add_import_declaration("@blockprotocol/type-system-rs", ["VersionedUrl"]);
31
32 for (type_id, _, type_definition) in collection.iter() {
33 if type_definition
34 .module
35 .starts_with("hash_graph_authorization")
36 {
37 generator.add_type_declaration_by_id(type_id);
38 }
39 }
40
41 insta::with_settings!({
42 description => "Generated TS types",
43 omit_expression => true,
44 snapshot_path => "../types",
45 prepend_module_to_snapshot => false,
46 }, {
47 insta::assert_binary_snapshot!(
48 ".d.ts",
49 format!("// This file was generated from `{}`\n\n{}", file!(), generator.write()).into_bytes()
50 );
51 });
52
53 // We require a `.js` file as otherwise `tsc` won't find the `.d.ts` file
54 let _: fs::File = fs::File::options()
55 .create(true)
56 .write(true)
57 .truncate(true)
58 .open(
59 Path::new(env!("CARGO_MANIFEST_DIR"))
60 .join("types")
61 .join("index.snap.js"),
62 )?;
63
64 Ok(())
65}

Callers

nothing calls this directly

Calls 11

OkInterface · 0.85
openMethod · 0.80
truncateMethod · 0.80
defaultFunction · 0.50
iterMethod · 0.45
starts_withMethod · 0.45
writeMethod · 0.45
createMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected