Skip to content

Commit bb80840

Browse files
committed
feat(cli/sdk): set prefix when the typegraph is loaded
1 parent 11225de commit bb80840

File tree

6 files changed

+31
-14
lines changed

6 files changed

+31
-14
lines changed

meta-cli/src/cli/serialize.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ impl Action for Serialize {
6767
};
6868

6969
// Minimum setup
70-
ServerStore::with(Some(Command::Serialize), Some(config.clone()));
70+
ServerStore::with(Some(Command::Serialize), Some(config.to_owned()));
71+
ServerStore::set_prefix(self.prefix.to_owned());
7172

7273
let config = Arc::new(config);
7374

@@ -105,14 +106,7 @@ impl Action for Serialize {
105106
}
106107
}
107108

108-
if let Some(prefix) = self.prefix.as_ref() {
109-
for tg in loaded.iter_mut() {
110-
tg.meta.prefix = Some(prefix.clone());
111-
}
112-
}
113-
114109
let tgs = loaded;
115-
116110
if let Some(tg_name) = self.typegraph.as_ref() {
117111
if let Some(tg) = tgs.iter().find(|tg| &tg.name().unwrap() == tg_name) {
118112
self.write(&self.to_string(&tg)?).await?;

meta-cli/src/com/server.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ async fn config(req: HttpRequest) -> impl Responder {
4141
let endpoint = ServerStore::get_endpoint();
4242
let secrets = ServerStore::get_secrets();
4343
let migration_action = ServerStore::get_migration_action();
44+
let prefix = ServerStore::get_prefix();
4445

4546
match ServerStore::get_config() {
4647
Some(config) => {
@@ -50,7 +51,7 @@ async fn config(req: HttpRequest) -> impl Responder {
5051
"auth": endpoint.auth
5152
},
5253
"secrets": secrets,
53-
// "prefix": config.prefix,
54+
"prefix": prefix,
5455
"artifactsConfig": json!({
5556
"dir": config.base_dir.display().to_string(),
5657
"prismaMigration": {
@@ -67,7 +68,7 @@ async fn config(req: HttpRequest) -> impl Responder {
6768
None => HttpResponse::Ok()
6869
.status(StatusCode::INTERNAL_SERVER_ERROR)
6970
.json(CLIResponseError {
70-
error: "Could not get config".to_string(),
71+
error: "Could not get config from meta-cli".to_string(),
7172
}),
7273
}
7374
}
@@ -83,7 +84,7 @@ async fn command() -> impl Responder {
8384
None => HttpResponse::Ok()
8485
.status(StatusCode::INTERNAL_SERVER_ERROR)
8586
.json(CLIResponseError {
86-
error: "Could not get command".to_string(),
87+
error: "Could not get command from meta-cli".to_string(),
8788
}),
8889
}
8990
}

meta-cli/src/com/store.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub struct ServerStore {
5858
migration_action: MigrationAction,
5959
secrets: HashMap<String, String>,
6060
endpoint: Endpoint,
61+
prefix: Option<String>,
6162
sdk_responses: HashMap<PathBuf, Arc<SDKResponse>>,
6263
}
6364

@@ -126,4 +127,12 @@ impl ServerStore {
126127
pub fn get_migration_action() -> MigrationAction {
127128
with_store(|s| s.migration_action.to_owned())
128129
}
130+
131+
pub fn set_prefix(prefix: Option<String>) {
132+
with_store_mut(|s| s.prefix = prefix)
133+
}
134+
135+
pub fn get_prefix() -> Option<String> {
136+
with_store(|s| s.prefix.to_owned())
137+
}
129138
}

typegraph/core/src/typegraph.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ pub fn finalize(res_config: Option<ArtifactResolutionConfig>) -> Result<String>
216216
};
217217

218218
if let Some(config) = res_config {
219+
// Typically happens when the cli is used
220+
if let Some(prefix) = config.prefix.clone() {
221+
tg.meta.prefix = Some(prefix);
222+
}
223+
219224
TypegraphPostProcessor::new(config).postprocess(&mut tg)?;
220225
}
221226

typegraph/core/wit/typegraph.wit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ interface core {
4747

4848
record artifact-resolution-config {
4949
dir: option<string>, // cwd() if none
50+
prefix: option<string>, // overrides tg.meta.prefix field if defined
5051
prisma-migration: migration-config
5152
}
5253

typegraph/node/sdk/src/tg_manage.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type CLIConfigRequest = {
2626
password: string;
2727
};
2828
};
29+
prefix?: string;
2930
secrets: Record<string, string>;
3031
artifactsConfig: ArtifactResolutionConfig;
3132
};
@@ -109,14 +110,17 @@ export class Manager {
109110
await this.#relayResultToCLI(
110111
"serialize",
111112
async () => {
112-
const json = this.#typegraph.serialize(config.artifactsConfig);
113+
const json = this.#typegraph.serialize({
114+
...config.artifactsConfig,
115+
prefix: config.prefix,
116+
});
113117
return JSON.parse(json);
114118
},
115119
);
116120
}
117121

118122
async #deploy(
119-
{ typegate, artifactsConfig, secrets }: CLIConfigRequest,
123+
{ typegate, artifactsConfig, secrets, prefix }: CLIConfigRequest,
120124
): Promise<void> {
121125
const { endpoint, auth } = typegate;
122126
if (!auth) {
@@ -129,7 +133,10 @@ export class Manager {
129133
async () => {
130134
const { typegate } = await tgDeploy(this.#typegraph, {
131135
baseUrl: endpoint,
132-
artifactsConfig,
136+
artifactsConfig: {
137+
...artifactsConfig,
138+
prefix,
139+
},
133140
cliVersion: VERSION,
134141
secrets,
135142
auth: new BasicAuth(auth.username, auth.password),

0 commit comments

Comments
 (0)