Skip to content

Commit a76ee6a

Browse files
authored
H-4777: Allow exporting types from hash-graph-store (#7404)
1 parent ff90a4b commit a76ee6a

File tree

15 files changed

+111
-6
lines changed

15 files changed

+111
-6
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/hash-ai-worker-ts/docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ RUN apt-get update && \
6363
apt-get install -y --no-install-recommends build-essential && \
6464
apt-get clean && \
6565
rm -rf /var/lib/apt/lists/* && \
66-
mise install node npm:turbo java biome npm:@redocly/cli cargo-binstall cargo:wasm-pack cargo:wasm-opt && \
66+
mise install node npm:turbo java biome npm:@redocly/cli cargo-binstall cargo:wasm-pack cargo:wasm-opt protoc && \
6767
yarn install --immutable && \
6868
yarn cache clean
6969

apps/hash-frontend/vercel-install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ yum install -y mise
1515
eval "$(mise activate bash --shims)"
1616

1717
echo "Installing prerequisites"
18-
mise install node npm:turbo java biome npm:@redocly/cli cargo-binstall cargo:wasm-pack cargo:wasm-opt
18+
mise install node npm:turbo java biome npm:@redocly/cli cargo-binstall cargo:wasm-pack cargo:wasm-opt protoc
1919
mise use --global yq
2020
mise use --global rust[profile=minimal]@$(yq '.toolchain.channel' rust-toolchain.toml)
2121

apps/hash-integration-worker/docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ RUN apt-get update && \
6464
apt-get install -y --no-install-recommends build-essential && \
6565
apt-get clean && \
6666
rm -rf /var/lib/apt/lists/* && \
67-
mise install node npm:turbo java biome npm:@redocly/cli cargo-binstall cargo:wasm-pack cargo:wasm-opt && \
67+
mise install node npm:turbo java biome npm:@redocly/cli cargo-binstall cargo:wasm-pack cargo:wasm-opt protoc && \
6868
yarn install --immutable && \
6969
yarn cache clean
7070

apps/hashdotdesign/vercel-install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ yum install -y mise
1212
eval "$(mise activate bash --shims)"
1313

1414
echo "Installing prerequisites"
15-
mise install node npm:turbo java biome npm:@redocly/cli cargo-binstall cargo:wasm-pack cargo:wasm-opt
15+
mise install node npm:turbo java biome npm:@redocly/cli cargo-binstall cargo:wasm-pack cargo:wasm-opt protoc
1616
mise use --global yq
1717
mise use --global rust[profile=minimal]@$(yq '.toolchain.channel' rust-toolchain.toml)
1818

infra/docker/api/prod/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ RUN apt-get update && \
6363
apt-get install -y --no-install-recommends build-essential && \
6464
apt-get clean && \
6565
rm -rf /var/lib/apt/lists/* && \
66-
mise install node npm:turbo java biome npm:@redocly/cli cargo-binstall cargo:wasm-pack cargo:wasm-opt && \
66+
mise install node npm:turbo java biome npm:@redocly/cli cargo-binstall cargo:wasm-pack cargo:wasm-opt protoc && \
6767
yarn install --immutable && \
6868
yarn cache clean
6969

libs/@local/graph/sdk/typescript/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@local/harpc-client": "0.0.0-private",
3030
"@local/hash-graph-client": "0.0.0-private",
3131
"@rust/hash-graph-authorization": "0.0.0-private",
32+
"@rust/hash-graph-store": "0.0.0-private",
3233
"effect": "3.13.11"
3334
},
3435
"devDependencies": {

libs/@local/graph/store/Cargo.toml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ hash-temporal-client = { workspace = true, public = true }
1515

1616
# Public third-party dependencies
1717
postgres-types = { workspace = true, public = true, optional = true, features = ["derive", "with-serde_json-1", "with-uuid-1"] }
18+
specta = { workspace = true, public = true, optional = true, features = ["derive"] }
1819
tokio-postgres = { workspace = true, public = true, optional = true }
1920
utoipa = { workspace = true, public = true, optional = true }
2021

@@ -36,11 +37,24 @@ tracing = { workspace = true }
3637
uuid = { workspace = true, features = ["v4"] }
3738

3839
[dev-dependencies]
39-
tokio = { workspace = true, features = ["macros"] }
40+
hash-codegen = { workspace = true }
41+
insta = { workspace = true }
42+
tokio = { workspace = true, features = ["macros"] }
43+
44+
[[test]]
45+
name = "codegen"
46+
required-features = ["codegen"]
4047

4148
[features]
49+
codegen = ["dep:specta", "type-system/codegen", "hash-graph-authorization/codegen"]
4250
utoipa = ["hash-graph-temporal-versioning/utoipa", "type-system/utoipa", "dep:utoipa"]
4351
postgres = ["hash-graph-temporal-versioning/postgres", "type-system/postgres", "dep:postgres-types", "dep:tokio-postgres", "dep:bytes"]
4452

4553
[lints]
4654
workspace = true
55+
56+
57+
[package.metadata.sync.turborepo]
58+
extra-dev-dependencies = [
59+
{ name = "@local/tsconfig", version = "0.0.0-private" },
60+
]

libs/@local/graph/store/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,22 @@
33
"version": "0.0.0-private",
44
"private": true,
55
"license": "AGPL-3",
6+
"exports": {
7+
"./types": "./types/index.snap.js"
8+
},
9+
"typesVersions": {
10+
"*": {
11+
"types": [
12+
"./types/index.snap.d.ts"
13+
]
14+
}
15+
},
616
"scripts": {
17+
"build:types": "INSTA_UPDATE=always mise exec --env dev cargo:cargo-insta -- cargo-insta test --features codegen --test codegen",
718
"doc:dependency-diagram": "cargo run -p hash-repo-chores -- dependency-diagram --output docs/dependency-diagram.mmd --root hash-graph-store --root-deps-and-dependents --link-mode non-roots --include-dev-deps --include-build-deps --logging-console-level info",
819
"fix:clippy": "just clippy --fix",
920
"lint:clippy": "just clippy",
21+
"lint:tsc": "tsc --noEmit",
1022
"test:unit": "mise run test:unit @rust/hash-graph-store"
1123
},
1224
"dependencies": {
@@ -17,5 +29,10 @@
1729
"@rust/hash-graph-temporal-versioning": "0.0.0-private",
1830
"@rust/hash-graph-types": "0.0.0-private",
1931
"@rust/hash-temporal-client": "0.0.0-private"
32+
},
33+
"devDependencies": {
34+
"@local/tsconfig": "0.0.0-private",
35+
"@rust/hash-codegen": "0.0.0-private",
36+
"typescript": "5.7.3"
2037
}
2138
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
extern crate hash_graph_store;
2+
3+
use std::{fs, io, path::Path};
4+
5+
use hash_codegen::{
6+
TypeCollection,
7+
typescript::{TypeScriptGenerator, TypeScriptGeneratorSettings},
8+
};
9+
10+
#[test]
11+
fn index() -> io::Result<()> {
12+
let collection = TypeCollection::default();
13+
14+
let settings = TypeScriptGeneratorSettings::default();
15+
let mut generator = TypeScriptGenerator::new(&settings, &collection);
16+
17+
for (type_id, _, type_definition) in collection.iter() {
18+
if type_definition.module.starts_with("hash_graph_store") {
19+
generator.add_type_declaration_by_id(type_id);
20+
}
21+
}
22+
23+
insta::with_settings!({
24+
description => "Generated TS types",
25+
omit_expression => true,
26+
snapshot_path => "../types",
27+
prepend_module_to_snapshot => false,
28+
}, {
29+
insta::assert_binary_snapshot!(
30+
".d.ts",
31+
format!("// This file was generated from `{}`\n\n{}", file!(), generator.write()).into_bytes()
32+
);
33+
});
34+
35+
// We require a `.js` file as otherwise `tsc` won't find the `.d.ts` file
36+
let _: fs::File = fs::File::options()
37+
.create(true)
38+
.write(true)
39+
.truncate(true)
40+
.open(
41+
Path::new(env!("CARGO_MANIFEST_DIR"))
42+
.join("types")
43+
.join("index.snap.js"),
44+
)?;
45+
46+
Ok(())
47+
}

0 commit comments

Comments
 (0)