Skip to content

Commit

Permalink
feat(config): expose util for standard cache directory per config
Browse files Browse the repository at this point in the history
  • Loading branch information
uladkasach committed Dec 26, 2024
1 parent ab8dab6 commit cab8bae
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { DirectoryToPersistTo } from 'simple-on-disk-cache';
import { isPresent } from 'type-fns';

import { getConfig } from './getConfig';

/**
* .what = gets the project's default s3 bucket, based on config
*/
export const getProjectBucket = async (): Promise<string> => {
const config = await getConfig();
const bucket = [
config.project,
config.aws.namespace,
config.environment.access,
].join('-');
return bucket;
};

/**
* .what = gets the project's default cache directory, based on config
*/
export const getCacheDirectory = async (
input: {
scope?: string;
} = {},
): Promise<DirectoryToPersistTo> => ({
s3: {
bucket: await getProjectBucket(),
prefix: ['purpose=cache', input.scope ? `scope=${input.scope}` : undefined]
.filter(isPresent)
.join('/'),
},
});

0 comments on commit cab8bae

Please sign in to comment.