summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/supabase.ts6
-rw-r--r--src/lib/utils/retry.ts57
-rw-r--r--src/lib/utils/setImageUrl.ts17
3 files changed, 39 insertions, 41 deletions
diff --git a/src/lib/supabase.ts b/src/lib/supabase.ts
index 37c828f..dbd66ad 100644
--- a/src/lib/supabase.ts
+++ b/src/lib/supabase.ts
@@ -1,8 +1,8 @@
import { createClient } from '@supabase/supabase-js';
export const supabase = createClient(
- import.meta.env.VITE_SUPABASE_URL as string,
- import.meta.env.VITE_SUPABASE_ANON_KEY as string,
+ import.meta.env.VITE_SUPABASE_URL as string,
+ import.meta.env.VITE_SUPABASE_ANON_KEY as string
);
-export default supabase; \ No newline at end of file
+export default supabase;
diff --git a/src/lib/utils/retry.ts b/src/lib/utils/retry.ts
index 34bc73b..ed78528 100644
--- a/src/lib/utils/retry.ts
+++ b/src/lib/utils/retry.ts
@@ -9,37 +9,36 @@ export const RETRY_JITTER_MAX = 3_000;
const waitFor = (ms: number) => new Promise((res) => setTimeout(res, ms));
const exponentialStrategyWithJitter: RetryStrategyF = (retries: number) =>
- WAIT_MS * Math.pow(RETRY_EXPONENT, RETRY_EXPONENTIAL_FACTOR * retries) +
- RETRY_JITTER_MAX * Math.random();
+ WAIT_MS * Math.pow(RETRY_EXPONENT, RETRY_EXPONENTIAL_FACTOR * retries) +
+ RETRY_JITTER_MAX * Math.random();
export const continueRetryUntilValidation = async <T>(
- promiseFn: () => Promise<T> | T | Promise<void> | void,
- validationFn: (x: T) => Promise<boolean> | boolean = (x: T) =>
- Promise.resolve(!!x),
- maxRetries = MAX_DEFAULT_RETRY_AMOUNT,
- waitTimeStrategy: RetryStrategyF = exponentialStrategyWithJitter,
- retries = 0,
- lastError: undefined | unknown = undefined
+ promiseFn: () => Promise<T> | T | Promise<void> | void,
+ validationFn: (x: T) => Promise<boolean> | boolean = (x: T) => Promise.resolve(!!x),
+ maxRetries = MAX_DEFAULT_RETRY_AMOUNT,
+ waitTimeStrategy: RetryStrategyF = exponentialStrategyWithJitter,
+ retries = 0,
+ lastError: undefined | unknown = undefined
): Promise<T> => {
- if (retries >= maxRetries) {
- if (lastError) throw lastError;
- throw new Error("Exceeded maximum retry amount");
- }
- try {
- if (retries) await waitFor(waitTimeStrategy(retries));
+ if (retries >= maxRetries) {
+ if (lastError) throw lastError;
+ throw new Error('Exceeded maximum retry amount');
+ }
+ try {
+ if (retries) await waitFor(waitTimeStrategy(retries));
- const res = await promiseFn();
- if (res && (await validationFn(res))) return res;
+ const res = await promiseFn();
+ if (res && (await validationFn(res))) return res;
- throw new Error("Validation predicate unsuccessful");
- } catch (e: unknown) {
- return continueRetryUntilValidation(
- promiseFn,
- validationFn,
- maxRetries,
- waitTimeStrategy,
- retries + 1,
- e
- );
- }
-}; \ No newline at end of file
+ throw new Error('Validation predicate unsuccessful');
+ } catch (e: unknown) {
+ return continueRetryUntilValidation(
+ promiseFn,
+ validationFn,
+ maxRetries,
+ waitTimeStrategy,
+ retries + 1,
+ e
+ );
+ }
+};
diff --git a/src/lib/utils/setImageUrl.ts b/src/lib/utils/setImageUrl.ts
index 15566a8..d2db853 100644
--- a/src/lib/utils/setImageUrl.ts
+++ b/src/lib/utils/setImageUrl.ts
@@ -1,12 +1,11 @@
import { supabase } from '../supabase';
export const setImageUrl = (imageSpec) => {
- const { publicURL, error } = supabase
- .storage
- .from('mistymountains')
- .getPublicUrl(imageSpec.image);
- if (!error) {
- return { ...imageSpec, image: publicURL };
- }
- return imageSpec;
-}
+ const { publicURL, error } = supabase.storage
+ .from('mistymountains')
+ .getPublicUrl(imageSpec.image);
+ if (!error) {
+ return { ...imageSpec, image: publicURL };
+ }
+ return imageSpec;
+};