-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
184 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { EnvType } from "../env/env-schema.ts"; | ||
import { EnvSafe } from "../env/env-schema.ts"; | ||
import { createClient } from "@supabase/supabase-js"; | ||
import { Database } from "./databaseTypes.ts"; | ||
|
||
export const getDatabase = (env: EnvType) => { | ||
export const getDatabase = (env: EnvSafe) => { | ||
return createClient<Database>(env.SUPABASE_URL, env.SUPABASE_KEY); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { createJsonResponse } from "./lib/json-response/create-json-response.ts"; | ||
import { getUser } from "./services/get-user.ts"; | ||
import { createAuthFailedResponse } from "./lib/json-response/create-auth-failed-response.ts"; | ||
import { handleError } from "./lib/handle-error/handle-error.ts"; | ||
import { envSchema } from "./env/env-schema.ts"; | ||
import { | ||
DeckCategoryDb, | ||
getAllCategoriesDb, | ||
} from "./db/deck/get-all-categories-db.ts"; | ||
|
||
export type DeckCategoryResponse = { | ||
categories: DeckCategoryDb[]; | ||
}; | ||
|
||
export const onRequest = handleError(async ({ request, env }) => { | ||
const user = await getUser(request, env); | ||
if (!user) return createAuthFailedResponse(); | ||
const envSafe = envSchema.parse(env); | ||
|
||
const categories = await getAllCategoriesDb(envSafe); | ||
|
||
return createJsonResponse<DeckCategoryResponse>({ | ||
categories: categories, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { test, vi, expect } from "vitest"; | ||
import { cachePromise } from "./cache-promise.ts"; | ||
|
||
test("should cache the resolved value of a promise", async () => { | ||
const mockFunction = vi.fn(); | ||
mockFunction.mockResolvedValueOnce("Cached value"); | ||
|
||
const promise = new Promise<string>((resolve) => { | ||
resolve(mockFunction()); | ||
}); | ||
|
||
const cached = cachePromise<string>(); | ||
|
||
// First call, should invoke the promise | ||
const result1 = await cached(promise); | ||
expect(result1).toBe("Cached value"); | ||
expect(mockFunction).toHaveBeenCalledTimes(1); | ||
|
||
// Second call, should use cached value | ||
const result2 = await cached(promise); | ||
expect(result2).toBe("Cached value"); | ||
// The mock function should not have been called again | ||
expect(mockFunction).toHaveBeenCalledTimes(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export const cachePromise = <T>() => { | ||
let cache: T | null = null; | ||
let isCacheSet = false; | ||
|
||
return async function (promise: Promise<T>): Promise<T> { | ||
if (isCacheSet) { | ||
return cache as T; | ||
} | ||
|
||
cache = await promise; | ||
isCacheSet = true; | ||
return cache; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TextField } from "./mobx-form.ts"; | ||
import { makePersistable } from "mobx-persist-store"; | ||
|
||
export const persistableField = <T>( | ||
field: TextField<T>, | ||
storageKey: string, | ||
): TextField<T> => { | ||
makePersistable(field, { | ||
name: storageKey, | ||
properties: ["value"], | ||
storage: window.localStorage, | ||
expireIn: 86400000, // One day in milliseconds | ||
}); | ||
|
||
return field; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.