Skip to content

Commit

Permalink
refactor: rename utils
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpeterparker committed Mar 7, 2024
1 parent 2399bcc commit 50b988a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions packages/core/src/api/actor.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import type {_SERVICE as SatelliteActor} from '../../declarations/satellite/sate
import {idlFactory} from '../../declarations/satellite/satellite.factory.did.js';
import type {Satellite} from '../types/satellite.types';
import {createActor} from '../utils/actor.utils';
import {mapContainer, mapSatelliteId} from '../utils/env.utils';
import {customOrEnvContainer, customOrEnvSatelliteId} from '../utils/env.utils';

export const getSatelliteActor = async ({
satelliteId: customSatelliteId,
container: customContainer,
...rest
}: Satellite): Promise<SatelliteActor> => {
const {satelliteId} = mapSatelliteId({satelliteId: customSatelliteId});
const {satelliteId} = customOrEnvSatelliteId({satelliteId: customSatelliteId});

assertNonNullish(satelliteId, 'No satellite principal defined.');

const {container} = mapContainer({container: customContainer});
const {container} = customOrEnvContainer({container: customContainer});

return createActor({
satelliteId,
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/utils/env.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export const satelliteUrl = ({
satelliteId: customSatelliteId,
container: customContainer
}: Satellite): string => {
const {satelliteId} = mapSatelliteId({satelliteId: customSatelliteId});
const {container} = mapContainer({container: customContainer});
const {satelliteId} = customOrEnvSatelliteId({satelliteId: customSatelliteId});
const {container} = customOrEnvContainer({container: customContainer});

if (nonNullish(container) && container !== false) {
const {host: containerHost, protocol} = new URL(
Expand All @@ -20,14 +20,14 @@ export const satelliteUrl = ({
return `https://${satelliteId ?? 'unknown'}.icp0.io`;
};

export const mapSatelliteId = ({
export const customOrEnvSatelliteId = ({
satelliteId
}: Pick<Satellite, 'satelliteId'>): Pick<Satellite, 'satelliteId'> =>
nonNullish(satelliteId)
? {satelliteId}
: EnvStore.getInstance().get() ?? {satelliteId: undefined};

export const mapContainer = ({
export const customOrEnvContainer = ({
container: customContainer
}: Pick<Satellite, 'container'>): Pick<Satellite, 'container'> =>
nonNullish(customContainer)
Expand Down

0 comments on commit 50b988a

Please sign in to comment.