From 8d48d9a9eeb6b16c83b4125fda75aae1b6885785 Mon Sep 17 00:00:00 2001 From: Miguel Romero Karam Date: Fri, 24 May 2024 17:39:31 +0200 Subject: [PATCH] chore: udpates --- lib/plugins/auth/plugin.ts | 14 +++++++------- lib/plugins/auth/routes/mod.ts | 6 +++--- lib/plugins/auth/utils/providers/mod.ts | 18 +++++++++--------- lib/plugins/database/plugin.ts | 9 +++++---- lib/plugins/datastore/plugin.ts | 2 +- lib/plugins/unocss/plugin.ts | 2 +- 6 files changed, 26 insertions(+), 25 deletions(-) diff --git a/lib/plugins/auth/plugin.ts b/lib/plugins/auth/plugin.ts index 5093aae0..bcb60d00 100644 --- a/lib/plugins/auth/plugin.ts +++ b/lib/plugins/auth/plugin.ts @@ -2,13 +2,13 @@ import type { FreshContext, Plugin, PluginRoute } from "fresh/server.ts"; import type { OAuth2ClientConfig } from "../../deps/oauth2_client/src/oauth2_client.ts"; import type { NetzoState } from "../../mod.ts"; import { - NetzoStateWithAuth, - assertUserIsMemberOfWorkspaceOfApiKeyIfProviderIsNetzo, - createAssertUserIsAuthorized, - ensureSignedIn, - setAuthState, - setRequestState, - setSessionState, + assertUserIsMemberOfWorkspaceOfApiKeyIfProviderIsNetzo, + createAssertUserIsAuthorized, + ensureSignedIn, + NetzoStateWithAuth, + setAuthState, + setRequestState, + setSessionState, } from "./middlewares/mod.ts"; import createAuth from "./routes/auth.tsx"; import { getRoutesByProvider } from "./routes/mod.ts"; diff --git a/lib/plugins/auth/routes/mod.ts b/lib/plugins/auth/routes/mod.ts index 22c088e9..ed2d9b23 100644 --- a/lib/plugins/auth/routes/mod.ts +++ b/lib/plugins/auth/routes/mod.ts @@ -1,9 +1,9 @@ import type { PluginRoute } from "fresh/server.ts"; import type { AuthConfig } from "../plugin.ts"; import { - getAuthConfig, - getFunctionsByProvider, - getUserByProvider, + getAuthConfig, + getFunctionsByProvider, + getUserByProvider, } from "../utils/providers/mod.ts"; import type { AuthProvider, AuthUser } from "../utils/types.ts"; diff --git a/lib/plugins/auth/utils/providers/mod.ts b/lib/plugins/auth/utils/providers/mod.ts index d7695e4d..6160af53 100644 --- a/lib/plugins/auth/utils/providers/mod.ts +++ b/lib/plugins/auth/utils/providers/mod.ts @@ -1,14 +1,14 @@ import { FreshContext } from "fresh/server.ts"; import { - createAuth0OAuthConfig, - createGitHubOAuthConfig, - createGitLabOAuthConfig, - createGoogleOAuthConfig, - createOktaOAuthConfig, - createSlackOAuthConfig, - handleCallback, - signIn, - signOut, + createAuth0OAuthConfig, + createGitHubOAuthConfig, + createGitLabOAuthConfig, + createGoogleOAuthConfig, + createOktaOAuthConfig, + createSlackOAuthConfig, + handleCallback, + signIn, + signOut, } from "../../../../deps/deno_kv_oauth/mod.ts"; import type { AuthProvider, AuthUserFromProvider } from "../types.ts"; import { getUserAuth0 } from "./auth0.ts"; diff --git a/lib/plugins/database/plugin.ts b/lib/plugins/database/plugin.ts index 7ff6ad1e..dec13641 100644 --- a/lib/plugins/database/plugin.ts +++ b/lib/plugins/database/plugin.ts @@ -1,7 +1,7 @@ // deno-lint-ignore-file no-explicit-any import type { Plugin, PluginRoute } from "fresh/server.ts"; import { createClient } from "npm:@libsql/client@0.6.0"; -import { eq } from "npm:drizzle-orm@0.30.10"; +import { eq, sql } from "npm:drizzle-orm@0.30.10"; import { DrizzleConfig } from "npm:drizzle-orm@0.30.10/utils"; import { database as createDatabase } from "../../database/mod.ts"; import { apiKeyAuthentication, cors } from "../middleware.ts"; @@ -96,14 +96,15 @@ export const database = (config?: DatabaseConfig): Plugin => { POST: async (req, ctx) => { const { tableName } = ctx.params; const table = config.schema![tableName] as any; + const pk = Object.entries(table).find(e => !!e[1]?.primary)?.[0]; const data = await parseRequestBody(req); - // UPSERT: https://orm.drizzle.team/learn/guides/upsert const result = await db .insert(table) .values(data) + // FIXME: this is not working somehow see https://discord.com/channels/1043890932593987624/1243571991945019402/1243571991945019402 .onConflictDoUpdate({ - target: table.id, - set: { id: sql.raw(`excluded.${table.id}`) }, + target: table[pk], + set: { [pk]: sql.raw(`excluded.${table[pk].name}`) }, }) .returning(); return Response.json( diff --git a/lib/plugins/datastore/plugin.ts b/lib/plugins/datastore/plugin.ts index 1b534335..272d5e4e 100644 --- a/lib/plugins/datastore/plugin.ts +++ b/lib/plugins/datastore/plugin.ts @@ -3,7 +3,7 @@ import { deepParseJson } from "npm:deep-parse-json@2.0.0"; import { unflatten } from "npm:flat@6.0.1"; import { datastore as createDatastore } from "../../datastore/mod.ts"; import { apiKeyAuthentication, cors } from "../middleware.ts"; -import { RESPONSES, parseRequestBody } from "../utils.ts"; +import { parseRequestBody, RESPONSES } from "../utils.ts"; export type DatastoreConfig = { /** Wether to require authentication using the provided API key in the diff --git a/lib/plugins/unocss/plugin.ts b/lib/plugins/unocss/plugin.ts index c12d9f9f..fb4991fe 100644 --- a/lib/plugins/unocss/plugin.ts +++ b/lib/plugins/unocss/plugin.ts @@ -1,6 +1,6 @@ import type { Plugin } from "fresh/server.ts"; import { dirname, fromFileUrl, join, walk } from "fresh/src/server/deps.ts"; -import { JSX, VNode, options as preactOptions } from "preact"; +import { JSX, options as preactOptions, VNode } from "preact"; import { UnoGenerator, type UserConfig } from "../../deps/@unocss/core.ts"; import type { Theme } from "../../deps/@unocss/preset-uno.ts"; import { existsSync } from "../../deps/std/fs/exists.ts";