Skip to content
This repository has been archived by the owner on Sep 22, 2024. It is now read-only.

Commit

Permalink
chore: udpates
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelrk committed May 24, 2024
1 parent 4b93ec7 commit 8d48d9a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
14 changes: 7 additions & 7 deletions lib/plugins/auth/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
6 changes: 3 additions & 3 deletions lib/plugins/auth/routes/mod.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
18 changes: 9 additions & 9 deletions lib/plugins/auth/utils/providers/mod.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
9 changes: 5 additions & 4 deletions lib/plugins/database/plugin.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/datastore/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/unocss/plugin.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down

0 comments on commit 8d48d9a

Please sign in to comment.