Skip to content

Commit 84efa45

Browse files
feat: provide orbiter ID (if available) to juno run (#433)
Signed-off-by: David Dal Busco <[email protected]>
1 parent e6bb77f commit 84efa45

File tree

2 files changed

+46
-13
lines changed

2 files changed

+46
-13
lines changed

src/services/run.services.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {buildScript, nextArg} from '@junobuild/cli-tools';
44
import {OnRunSchema, type RunFnOrObject, RunFnOrObjectSchema} from '@junobuild/config';
55
import {red, yellow} from 'kleur';
66
import {ENV} from '../env';
7-
import {assertConfigAndLoadSatelliteContext} from '../utils/juno.config.utils';
7+
import {assertConfigAndLoadContext} from '../utils/juno.config.utils';
88

99
export const run = async (args?: string[]) => {
1010
const infile = nextArg({args, option: '-s'}) ?? nextArg({args, option: '--src'});
@@ -41,11 +41,15 @@ export const run = async (args?: string[]) => {
4141
}
4242

4343
const {
44-
satellite: {satelliteId, identity}
45-
} = await assertConfigAndLoadSatelliteContext();
44+
satellite: {
45+
satellite: {satelliteId, identity}
46+
},
47+
orbiter
48+
} = await assertConfigAndLoadContext();
4649

4750
await job.run({
4851
satelliteId: Principal.fromText(satelliteId),
52+
...(nonNullish(orbiter) && {orbiterId: Principal.fromText(orbiter.orbiter.orbiterId)}),
4953
identity,
5054
...(nonNullish(ENV.containerUrl) && {container: ENV.containerUrl})
5155
});

src/utils/juno.config.utils.ts

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {assertNonNullish, isNullish} from '@dfinity/utils';
1+
import {assertNonNullish, isNullish, nonNullish} from '@dfinity/utils';
22
import type {PrincipalText} from '@dfinity/zod-schemas';
33
import type {JunoConfig, JunoConfigEnv, OrbiterConfig, SatelliteConfig} from '@junobuild/config';
44
import {red} from 'kleur';
@@ -18,28 +18,57 @@ interface OrbiterConfigEnv {
1818
env: JunoConfigEnv;
1919
}
2020

21-
export const assertConfigAndLoadSatelliteContext = async (): Promise<{
21+
interface SatelliteContext {
2222
satellite: SatelliteParametersWithId;
2323
satelliteConfig: SatelliteConfig;
24+
}
25+
26+
interface OrbiterContext {
27+
orbiter: OrbiterParametersWithId;
28+
orbiterConfig: OrbiterConfig;
29+
}
30+
31+
export const assertConfigAndLoadContext = async (): Promise<{
32+
satellite: SatelliteContext;
33+
orbiter: OrbiterContext | undefined;
2434
}> => {
35+
const {satellite: satelliteConfig, orbiter: orbiterConfig} = await assertAndReadJunoConfig();
36+
37+
const {satelliteId} = assertAndReadSatelliteId({satellite: satelliteConfig, env: ENV});
38+
39+
// TS guard. assertAndReadSatelliteId exist if satelliteId is undefined.
40+
// Should not happen.
41+
assertNonNullish(satelliteId);
42+
43+
const {orbiterId} = readOrbiterId({orbiter: orbiterConfig, env: ENV});
44+
45+
const parameters = await actorParameters();
46+
47+
return {
48+
satellite: {satellite: {satelliteId, ...parameters}, satelliteConfig},
49+
orbiter:
50+
nonNullish(orbiterId) && nonNullish(orbiterConfig)
51+
? {
52+
orbiter: {orbiterId, ...parameters},
53+
orbiterConfig
54+
}
55+
: undefined
56+
};
57+
};
58+
59+
export const assertConfigAndLoadSatelliteContext = async (): Promise<SatelliteContext> => {
2560
const {satellite: satelliteConfig} = await assertAndReadJunoConfig();
2661

2762
const satellite = await satelliteParameters({satellite: satelliteConfig, env: ENV});
2863

29-
// TS guard. satelliteParameters exit if satelliteId is undefined.
64+
// TS guard. satelliteParameters exist if satelliteId is undefined.
3065
// Should not happen.
3166
assertNonNullish(satellite.satelliteId);
3267

3368
return {satellite, satelliteConfig};
3469
};
3570

36-
export const assertConfigAndLoadOrbiterContext = async (): Promise<
37-
| {
38-
orbiter: OrbiterParametersWithId;
39-
orbiterConfig: OrbiterConfig;
40-
}
41-
| undefined
42-
> => {
71+
export const assertConfigAndLoadOrbiterContext = async (): Promise<OrbiterContext | undefined> => {
4372
const {orbiter: orbiterConfig} = await assertAndReadJunoConfig();
4473

4574
if (isNullish(orbiterConfig)) {

0 commit comments

Comments
 (0)