Skip to content

Commit

Permalink
Merge pull request #77 from bywhitebird/73-manage-project-creation
Browse files Browse the repository at this point in the history
73 manage project creation
  • Loading branch information
arthur-fontaine authored Nov 16, 2023
2 parents 5983422 + 4d5258e commit b8abe0c
Show file tree
Hide file tree
Showing 54 changed files with 1,405 additions and 141 deletions.
3 changes: 3 additions & 0 deletions apps/alakazam/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ logs
# Panda
styled-system
styled-system-static

# EdgeDB
dbschema/edgeql-js
84 changes: 84 additions & 0 deletions apps/alakazam/dbschema/default.esdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
module default {
type UserGitHubConnection {
required githubUsername: str {
constraint exclusive;
}
required githubId: int32 {
constraint exclusive;
}

single link user := .<githubConnection[is User];
}

type User {
required name: str;

single githubConnection: UserGitHubConnection {
readonly := true;
constraint exclusive;
}

multi link organizations := .<user[is OrganizationMember];
}

type OrganizationMember {
required isAdministrator: bool {
default := false;
}

required single user: User;
required single organization: Organization;

constraint exclusive on ((.organization, .user));
}

type Organization {
required name: str;

multi projects: Project {
constraint exclusive;
}

multi link members := .<organization[is OrganizationMember];
}

type Project {
required name: str;

# multi parsers: Parser;
# multi transformers: Transformer;
multi sources: ProjectSource {
constraint exclusive;
};

single link organization := .<projects[is Organization];
}

# scalar type ParserName extending enum<kaz>;
# type Parser {
# required parserName: ParserName;
# parserParameters: json;
# }

# scalar type TransformerName extending enum<react, vue>;
# type Transformer {
# required transformerName: TransformerName;
# transformerParameters: json;
# }

type ProjectSource {
single githubRepository: GitHubRepository {
constraint exclusive;
}

single link project := .<sources[is Project];
}

type GitHubRepository {
required url: str {
constraint regexp(r'^https:\/\/github\.com.*$');
};

single link projectSource := .<githubRepository[is ProjectSource];
}
}
24 changes: 24 additions & 0 deletions apps/alakazam/dbschema/migrations/00001.edgeql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CREATE MIGRATION m1xrvw7ei4qeqrwdbvtsdab4b7mb7xadnreyfj4b25wngj5zze5ewa
ONTO initial
{
CREATE TYPE default::User {
CREATE REQUIRED PROPERTY name: std::str;
};
CREATE TYPE default::UserGitHubConnection {
CREATE REQUIRED PROPERTY githubId: std::int32 {
CREATE CONSTRAINT std::exclusive;
};
CREATE REQUIRED PROPERTY githubUsername: std::str {
CREATE CONSTRAINT std::exclusive;
};
};
ALTER TYPE default::User {
CREATE SINGLE LINK githubConnection: default::UserGitHubConnection {
SET readonly := true;
CREATE CONSTRAINT std::exclusive;
};
};
ALTER TYPE default::UserGitHubConnection {
CREATE SINGLE LINK user := (.<githubConnection[IS default::User]);
};
};
21 changes: 21 additions & 0 deletions apps/alakazam/dbschema/migrations/00002.edgeql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CREATE MIGRATION m1t4s2ey54eij2tqiule2cgysjta4qdtok6mv2g6lfjqhutubdls6q
ONTO m1xrvw7ei4qeqrwdbvtsdab4b7mb7xadnreyfj4b25wngj5zze5ewa
{
CREATE TYPE default::Organization {
CREATE REQUIRED PROPERTY name: std::str;
};
CREATE TYPE default::OrganizationMember {
CREATE REQUIRED SINGLE LINK organization: default::Organization;
CREATE REQUIRED SINGLE LINK user: default::User;
CREATE CONSTRAINT std::exclusive ON ((.organization, .user));
CREATE REQUIRED PROPERTY isAdministrator: std::bool {
SET default := false;
};
};
ALTER TYPE default::Organization {
CREATE MULTI LINK members := (.<organization[IS default::OrganizationMember]);
};
ALTER TYPE default::User {
CREATE MULTI LINK organizations := (.<user[IS default::OrganizationMember]);
};
};
15 changes: 15 additions & 0 deletions apps/alakazam/dbschema/migrations/00003.edgeql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CREATE MIGRATION m16aaj63lzt6n4sfmqerswsti74xr6jftgiimfafmen55o35sn5b4q
ONTO m1t4s2ey54eij2tqiule2cgysjta4qdtok6mv2g6lfjqhutubdls6q
{
CREATE TYPE default::Project {
CREATE REQUIRED PROPERTY name: std::str;
};
ALTER TYPE default::Organization {
CREATE MULTI LINK projects: default::Project {
CREATE CONSTRAINT std::exclusive;
};
};
ALTER TYPE default::Project {
CREATE SINGLE LINK organization := (.<projects[IS default::Organization]);
};
};
25 changes: 25 additions & 0 deletions apps/alakazam/dbschema/migrations/00004.edgeql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
CREATE MIGRATION m13upjhjcylvj2xg6tkbukfqbqzmwst2awsnnbreevejh5wkzhv3ja
ONTO m16aaj63lzt6n4sfmqerswsti74xr6jftgiimfafmen55o35sn5b4q
{
CREATE TYPE default::GitHubRepository {
CREATE REQUIRED PROPERTY url: std::str {
CREATE CONSTRAINT std::regexp(r'^https:\/\/github\.com.*$');
};
};
CREATE TYPE default::ProjectSource {
CREATE SINGLE LINK githubRepository: default::GitHubRepository {
CREATE CONSTRAINT std::exclusive;
};
};
ALTER TYPE default::GitHubRepository {
CREATE SINGLE LINK projectSource := (.<githubRepository[IS default::ProjectSource]);
};
ALTER TYPE default::Project {
CREATE MULTI LINK sources: default::ProjectSource {
CREATE CONSTRAINT std::exclusive;
};
};
ALTER TYPE default::ProjectSource {
CREATE SINGLE LINK project := (.<sources[IS default::Project]);
};
};
2 changes: 2 additions & 0 deletions apps/alakazam/edgedb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[edgedb]
server-version = "4.1"
15 changes: 15 additions & 0 deletions apps/alakazam/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,24 @@ export default defineNuxtConfig({
from: '~/styled-system/css',
imports: ['css'],
},
{
from: '~/shared/utils/database',
imports: ['database'],
},
],
},

nitro: {
imports: {
presets: [
{
from: '~/shared/utils/database',
imports: ['database'],
},
]
},
},

build: {
transpile: ['fsevents'],
},
Expand Down
20 changes: 14 additions & 6 deletions apps/alakazam/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,27 @@
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare",
"prepare": "panda codegen"
},
"dependencies": {
"@whitebird/ui": "workspace:*"
"postinstall": "pnpm prepare",
"prepare:nuxt": "nuxt prepare",
"prepare:panda": "panda codegen",
"prepare:edgedb": "edgedb-generate edgeql-js",
"prepare": "npm-run-all prepare:*",
"migrate-db": "edgedb migration create && edgedb migrate && pnpm prepare:edgedb"
},
"devDependencies": {
"@edgedb/generate": "^0.4.1",
"@nuxt/devtools": "latest",
"@octokit/rest": "^20.0.2",
"@pandacss/dev": "^0.14.0",
"@whitebird/ui": "workspace:*",
"edgedb": "^1.4.1",
"eslint-plugin-vue": "^9.17.0",
"glob": "^10.3.4",
"npm-run-all": "^4.1.5",
"nuxt": "^3.7.1",
"nuxt-auth-utils": "^0.0.5",
"nuxt-typed-router": "^3.3.1"
"nuxt-typed-router": "^3.3.1",
"valibot": "^0.20.1",
"vue": "^3.3.8"
}
}
18 changes: 18 additions & 0 deletions apps/alakazam/src/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<template>
<body
:class="css({
bg: 'appBackground',
color: 'highContrastForeground',
textStyle: 'body',
height: '100dvh',
width: '100dvw',
overflow: 'auto',
scrollbarGutter: 'stable',
})"
>
<NuxtPage />
</body>
</template>
46 changes: 46 additions & 0 deletions apps/alakazam/src/features/auth/composables/use-auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
type AuthService = (
Extract<Parameters<typeof useFetch>[0], `/api/auth/${string}`> extends `/api/auth/${infer Service}`
? Service
: never
)

export const useAuth = () => {
const { loggedIn, user, session, clear: clearSession, fetch: fetchSession } = useUserSession()

async function login(service: AuthService) {
await navigateTo(`/api/auth/${service}`, {
external: true,
open: {
target: '_blank',
},
})
}

function logout() {
clearSession()
}

onMounted(() => {
if (typeof window === "undefined") {
return
}

window.addEventListener(
"message",
(event) => {
if (event.data.type === "auth") {
fetchSession()
}
},
false,
);
})

return {
loggedIn,
user,
session,
login,
logout,
}
}
40 changes: 4 additions & 36 deletions apps/alakazam/src/features/auth/pages/login.vue
Original file line number Diff line number Diff line change
@@ -1,63 +1,31 @@
<script setup lang="ts">
import Button from "@whitebird/ui/vue/button"
const { loggedIn, user, session, clear: clearSession, fetch: fetchSession } = useUserSession()
async function login() {
await navigateTo(`/api/auth/github`, {
external: true,
open: {
target: '_blank',
},
})
}
function logout() {
clearSession()
}
onMounted(() => {
window.addEventListener(
"message",
(event) => {
if (event.data.type === "auth") {
fetchSession()
}
},
false,
);
})
const { loggedIn, user, session, login, logout } = useAuth()
</script>

<template>
<div
:class="css({
bg: 'appBackground',
color: 'highContrastForeground',
height: '100dvh',
width: '100dvw',
height: '100%',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'safe center',
overflow: 'auto',
scrollbarGutter: 'stable',
})"
>
<Button
text="Login with GitHub"
variant="primary"
icon-name="github"
@click="login"
@click="login('github')"
/>
<Button
text="Logout"
variant="secondary"
icon-name="logout-box"
@click="logout"
@click="logout()"
/>
<pre>{{ loggedIn }}</pre>
<pre>{{ session }}</pre>
Expand Down
Loading

0 comments on commit b8abe0c

Please sign in to comment.