diff --git a/.github/workflows/wibe-server.yml b/.github/workflows/wabe-server.yml similarity index 86% rename from .github/workflows/wibe-server.yml rename to .github/workflows/wabe-server.yml index 071839f2..f52ac34b 100644 --- a/.github/workflows/wibe-server.yml +++ b/.github/workflows/wabe-server.yml @@ -6,7 +6,7 @@ on: - '**' types: [opened, synchronize, reopened, unlabeled] paths: - - 'packages/wibe-server/**' + - 'packages/wabe-server/**' concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} @@ -22,4 +22,4 @@ jobs: with: bun-version: latest - run: bun install - - run: bun --filter wibe-server ci + - run: bun --filter wabe-server ci diff --git a/.gitignore b/.gitignore index 7a7ccd21..5ff912a6 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,6 @@ package-lock.json **/generated/schema.ts -**/generated/wibe.ts +**/generated/wabe.ts + +cache diff --git a/README.md b/README.md index 1211e35e..ea324784 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# wibe +# wabe diff --git a/biome.json b/biome.json index da108191..9a36ef10 100644 --- a/biome.json +++ b/biome.json @@ -1,7 +1,7 @@ { - "$schema": "https://biomejs.dev/schemas/1.7.1/schema.json", + "$schema": "https://biomejs.dev/schemas/1.8.3/schema.json", "files": { - "include": ["**/*.ts", "**/*.js"], + "include": ["**/*.ts", "**/*.js", "**/*.vue", "**/*.tsx"], "ignore": [ "**/dist/**", "**/node_modules/**", diff --git a/bun.lockb b/bun.lockb index 33d0b86e..e7032d88 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 141f37a2..74a7088a 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "main", "version": "1.0.0", "devDependencies": { - "@biomejs/biome": "1.7.1", + "@biomejs/biome": "1.8.3", "lefthook": "1.6.10", "typescript": "5.4.2" }, diff --git a/packages/wabe-documentation/.gitignore b/packages/wabe-documentation/.gitignore new file mode 100644 index 00000000..044373fb --- /dev/null +++ b/packages/wabe-documentation/.gitignore @@ -0,0 +1,25 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? +doc_build diff --git a/packages/wabe-documentation/bun.lockb b/packages/wabe-documentation/bun.lockb new file mode 100755 index 00000000..f1482568 Binary files /dev/null and b/packages/wabe-documentation/bun.lockb differ diff --git a/packages/wabe-documentation/docs/.vitepress/config.ts b/packages/wabe-documentation/docs/.vitepress/config.ts new file mode 100644 index 00000000..39b368cc --- /dev/null +++ b/packages/wabe-documentation/docs/.vitepress/config.ts @@ -0,0 +1,25 @@ +import { defineConfig } from 'vitepress' + +export default defineConfig({ + title: 'Wabe', + themeConfig: { + nav: [ + { text: 'Home', link: '/' }, + { text: 'Examples', link: '/markdown-examples' }, + ], + + sidebar: [ + { + text: 'Examples', + items: [ + { text: 'Markdown Examples', link: '/markdown-examples' }, + { text: 'Runtime API Examples', link: '/api-examples' }, + ], + }, + ], + + socialLinks: [ + { icon: 'github', link: 'https://github.com/vuejs/vitepress' }, + ], + }, +}) diff --git a/packages/wabe-documentation/docs/.vitepress/theme/index.ts b/packages/wabe-documentation/docs/.vitepress/theme/index.ts new file mode 100644 index 00000000..def4cfc8 --- /dev/null +++ b/packages/wabe-documentation/docs/.vitepress/theme/index.ts @@ -0,0 +1,17 @@ +// https://vitepress.dev/guide/custom-theme +import { h } from 'vue' +import type { Theme } from 'vitepress' +import DefaultTheme from 'vitepress/theme' +import './style.css' + +export default { + extends: DefaultTheme, + Layout: () => { + return h(DefaultTheme.Layout, null, { + // https://vitepress.dev/guide/extending-default-theme#layout-slots + }) + }, + enhanceApp({ app, router, siteData }) { + // ... + } +} satisfies Theme diff --git a/packages/wabe-documentation/docs/.vitepress/theme/style.css b/packages/wabe-documentation/docs/.vitepress/theme/style.css new file mode 100644 index 00000000..d63aee82 --- /dev/null +++ b/packages/wabe-documentation/docs/.vitepress/theme/style.css @@ -0,0 +1,139 @@ +/** + * Customize default theme styling by overriding CSS variables: + * https://github.com/vuejs/vitepress/blob/main/src/client/theme-default/styles/vars.css + */ + +/** + * Colors + * + * Each colors have exact same color scale system with 3 levels of solid + * colors with different brightness, and 1 soft color. + * + * - `XXX-1`: The most solid color used mainly for colored text. It must + * satisfy the contrast ratio against when used on top of `XXX-soft`. + * + * - `XXX-2`: The color used mainly for hover state of the button. + * + * - `XXX-3`: The color for solid background, such as bg color of the button. + * It must satisfy the contrast ratio with pure white (#ffffff) text on + * top of it. + * + * - `XXX-soft`: The color used for subtle background such as custom container + * or badges. It must satisfy the contrast ratio when putting `XXX-1` colors + * on top of it. + * + * The soft color must be semi transparent alpha channel. This is crucial + * because it allows adding multiple "soft" colors on top of each other + * to create a accent, such as when having inline code block inside + * custom containers. + * + * - `default`: The color used purely for subtle indication without any + * special meanings attched to it such as bg color for menu hover state. + * + * - `brand`: Used for primary brand colors, such as link text, button with + * brand theme, etc. + * + * - `tip`: Used to indicate useful information. The default theme uses the + * brand color for this by default. + * + * - `warning`: Used to indicate warning to the users. Used in custom + * container, badges, etc. + * + * - `danger`: Used to show error, or dangerous message to the users. Used + * in custom container, badges, etc. + * -------------------------------------------------------------------------- */ + + :root { + --vp-c-default-1: var(--vp-c-gray-1); + --vp-c-default-2: var(--vp-c-gray-2); + --vp-c-default-3: var(--vp-c-gray-3); + --vp-c-default-soft: var(--vp-c-gray-soft); + + --vp-c-brand-1: var(--vp-c-indigo-1); + --vp-c-brand-2: var(--vp-c-indigo-2); + --vp-c-brand-3: var(--vp-c-indigo-3); + --vp-c-brand-soft: var(--vp-c-indigo-soft); + + --vp-c-tip-1: var(--vp-c-brand-1); + --vp-c-tip-2: var(--vp-c-brand-2); + --vp-c-tip-3: var(--vp-c-brand-3); + --vp-c-tip-soft: var(--vp-c-brand-soft); + + --vp-c-warning-1: var(--vp-c-yellow-1); + --vp-c-warning-2: var(--vp-c-yellow-2); + --vp-c-warning-3: var(--vp-c-yellow-3); + --vp-c-warning-soft: var(--vp-c-yellow-soft); + + --vp-c-danger-1: var(--vp-c-red-1); + --vp-c-danger-2: var(--vp-c-red-2); + --vp-c-danger-3: var(--vp-c-red-3); + --vp-c-danger-soft: var(--vp-c-red-soft); +} + +/** + * Component: Button + * -------------------------------------------------------------------------- */ + +:root { + --vp-button-brand-border: transparent; + --vp-button-brand-text: var(--vp-c-white); + --vp-button-brand-bg: var(--vp-c-brand-3); + --vp-button-brand-hover-border: transparent; + --vp-button-brand-hover-text: var(--vp-c-white); + --vp-button-brand-hover-bg: var(--vp-c-brand-2); + --vp-button-brand-active-border: transparent; + --vp-button-brand-active-text: var(--vp-c-white); + --vp-button-brand-active-bg: var(--vp-c-brand-1); +} + +/** + * Component: Home + * -------------------------------------------------------------------------- */ + +:root { + --vp-home-hero-name-color: transparent; + --vp-home-hero-name-background: -webkit-linear-gradient( + 120deg, + #bd34fe 30%, + #41d1ff + ); + + --vp-home-hero-image-background-image: linear-gradient( + -45deg, + #bd34fe 50%, + #47caff 50% + ); + --vp-home-hero-image-filter: blur(44px); +} + +@media (min-width: 640px) { + :root { + --vp-home-hero-image-filter: blur(56px); + } +} + +@media (min-width: 960px) { + :root { + --vp-home-hero-image-filter: blur(68px); + } +} + +/** + * Component: Custom Block + * -------------------------------------------------------------------------- */ + +:root { + --vp-custom-block-tip-border: transparent; + --vp-custom-block-tip-text: var(--vp-c-text-1); + --vp-custom-block-tip-bg: var(--vp-c-brand-soft); + --vp-custom-block-tip-code-bg: var(--vp-c-brand-soft); +} + +/** + * Component: Algolia + * -------------------------------------------------------------------------- */ + +.DocSearch { + --docsearch-primary-color: var(--vp-c-brand-1) !important; +} + diff --git a/packages/wabe-documentation/docs/api-examples.md b/packages/wabe-documentation/docs/api-examples.md new file mode 100644 index 00000000..6bd8bb5c --- /dev/null +++ b/packages/wabe-documentation/docs/api-examples.md @@ -0,0 +1,49 @@ +--- +outline: deep +--- + +# Runtime API Examples + +This page demonstrates usage of some of the runtime APIs provided by VitePress. + +The main `useData()` API can be used to access site, theme, and page data for the current page. It works in both `.md` and `.vue` files: + +```md + + +## Results + +### Theme Data +
{{ theme }}
+ +### Page Data +
{{ page }}
+ +### Page Frontmatter +
{{ frontmatter }}
+``` + + + +## Results + +### Theme Data +
{{ theme }}
+ +### Page Data +
{{ page }}
+ +### Page Frontmatter +
{{ frontmatter }}
+ +## More + +Check out the documentation for the [full list of runtime APIs](https://vitepress.dev/reference/runtime-api#usedata). diff --git a/packages/wabe-documentation/docs/index.md b/packages/wabe-documentation/docs/index.md new file mode 100644 index 00000000..f2b96dfa --- /dev/null +++ b/packages/wabe-documentation/docs/index.md @@ -0,0 +1,15 @@ +--- +title: Wabe - Your backend in minutes not days +layout: page +sidebar: false +head: + - - meta + - property: 'og:title' + content: Elysia - Ergonomic Framework for Humans +--- + + + + diff --git a/packages/wabe-documentation/docs/markdown-examples.md b/packages/wabe-documentation/docs/markdown-examples.md new file mode 100644 index 00000000..f9258a55 --- /dev/null +++ b/packages/wabe-documentation/docs/markdown-examples.md @@ -0,0 +1,85 @@ +# Markdown Extension Examples + +This page demonstrates some of the built-in markdown extensions provided by VitePress. + +## Syntax Highlighting + +VitePress provides Syntax Highlighting powered by [Shiki](https://github.com/shikijs/shiki), with additional features like line-highlighting: + +**Input** + +````md +```js{4} +export default { + data () { + return { + msg: 'Highlighted!' + } + } +} +``` +```` + +**Output** + +```js{4} +export default { + data () { + return { + msg: 'Highlighted!' + } + } +} +``` + +## Custom Containers + +**Input** + +```md +::: info +This is an info box. +::: + +::: tip +This is a tip. +::: + +::: warning +This is a warning. +::: + +::: danger +This is a dangerous warning. +::: + +::: details +This is a details block. +::: +``` + +**Output** + +::: info +This is an info box. +::: + +::: tip +This is a tip. +::: + +::: warning +This is a warning. +::: + +::: danger +This is a dangerous warning. +::: + +::: details +This is a details block. +::: + +## More + +Check out the documentation for the [full list of markdown extensions](https://vitepress.dev/guide/markdown). diff --git a/packages/wabe-documentation/docs/public/logo.jpeg b/packages/wabe-documentation/docs/public/logo.jpeg new file mode 100644 index 00000000..601b6a25 Binary files /dev/null and b/packages/wabe-documentation/docs/public/logo.jpeg differ diff --git a/packages/wabe-documentation/landing/index.vue b/packages/wabe-documentation/landing/index.vue new file mode 100644 index 00000000..b5df753e --- /dev/null +++ b/packages/wabe-documentation/landing/index.vue @@ -0,0 +1,137 @@ + + + diff --git a/packages/wabe-documentation/landing/tailwind.css b/packages/wabe-documentation/landing/tailwind.css new file mode 100644 index 00000000..b5c61c95 --- /dev/null +++ b/packages/wabe-documentation/landing/tailwind.css @@ -0,0 +1,3 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; diff --git a/packages/wabe-documentation/package.json b/packages/wabe-documentation/package.json new file mode 100644 index 00000000..942d9192 --- /dev/null +++ b/packages/wabe-documentation/package.json @@ -0,0 +1,20 @@ +{ + "name": "wabe-documentation", + "type": "module", + "scripts": { + "docs:dev": "vitepress dev docs", + "docs:build": "vitepress build docs", + "docs:preview": "vitepress preview docs" + }, + "devDependencies": { + "vitepress": "1.3.3", + "vue": "3.4.38" + }, + "dependencies": { + "autoprefixer": "10.4.20", + "daisyui": "4.12.10", + "postcss": "8.4.41", + "postcss-nesting": "^13.0.0", + "tailwindcss": "3.4.10" + } +} diff --git a/packages/wabe-documentation/postcss.config.js b/packages/wabe-documentation/postcss.config.js new file mode 100644 index 00000000..c3baaa9a --- /dev/null +++ b/packages/wabe-documentation/postcss.config.js @@ -0,0 +1,9 @@ +// postcss.config.js +export default { + plugins: { + 'postcss-import': {}, + 'tailwindcss/nesting': 'postcss-nesting', + tailwindcss: {}, + autoprefixer: {}, + }, +} diff --git a/packages/wabe-documentation/tailwind.config.js b/packages/wabe-documentation/tailwind.config.js new file mode 100644 index 00000000..e5689cd5 --- /dev/null +++ b/packages/wabe-documentation/tailwind.config.js @@ -0,0 +1,14 @@ +/** @type {import('tailwindcss').Config} */ +module.exports = { + preflight: false, + content: [ + 'landing/**/*.vue', + 'docs/**/*.md', + 'docs/.vitepress/theme/*.vue', + ], + darkMode: 'class', + theme: { + extend: {}, + }, + plugins: [require('daisyui')], +} diff --git a/packages/wibe-mongodb-launcher/index.ts b/packages/wabe-mongodb-launcher/index.ts similarity index 100% rename from packages/wibe-mongodb-launcher/index.ts rename to packages/wabe-mongodb-launcher/index.ts diff --git a/packages/wibe-mongodb-launcher/package.json b/packages/wabe-mongodb-launcher/package.json similarity index 94% rename from packages/wibe-mongodb-launcher/package.json rename to packages/wabe-mongodb-launcher/package.json index 84332ac8..138a5bf4 100644 --- a/packages/wibe-mongodb-launcher/package.json +++ b/packages/wabe-mongodb-launcher/package.json @@ -1,5 +1,5 @@ { - "name": "wibe-mongodb-launcher", + "name": "wabe-mongodb-launcher", "version": "0.0.1", "license": "MIT", "main": "src/index.ts", diff --git a/packages/wibe-mongodb-launcher/tsconfig.json b/packages/wabe-mongodb-launcher/tsconfig.json similarity index 100% rename from packages/wibe-mongodb-launcher/tsconfig.json rename to packages/wabe-mongodb-launcher/tsconfig.json diff --git a/packages/wabe-pluralize/bun.lockb b/packages/wabe-pluralize/bun.lockb new file mode 100755 index 00000000..ef42f7f5 Binary files /dev/null and b/packages/wabe-pluralize/bun.lockb differ diff --git a/packages/wibe-pluralize/index.test.ts b/packages/wabe-pluralize/index.test.ts similarity index 100% rename from packages/wibe-pluralize/index.test.ts rename to packages/wabe-pluralize/index.test.ts diff --git a/packages/wibe-pluralize/index.ts b/packages/wabe-pluralize/index.ts similarity index 100% rename from packages/wibe-pluralize/index.ts rename to packages/wabe-pluralize/index.ts diff --git a/packages/wibe-pluralize/package.json b/packages/wabe-pluralize/package.json similarity index 93% rename from packages/wibe-pluralize/package.json rename to packages/wabe-pluralize/package.json index 359448ba..e215bc8b 100644 --- a/packages/wibe-pluralize/package.json +++ b/packages/wabe-pluralize/package.json @@ -1,5 +1,5 @@ { - "name": "wibe-pluralize", + "name": "wabe-pluralize", "version": "0.0.1", "license": "MIT", "main": "src/index.ts", diff --git a/packages/wibe-pluralize/tsconfig.json b/packages/wabe-pluralize/tsconfig.json similarity index 100% rename from packages/wibe-pluralize/tsconfig.json rename to packages/wabe-pluralize/tsconfig.json diff --git a/packages/wibe-server/bunfig.toml b/packages/wabe-server/bunfig.toml similarity index 100% rename from packages/wibe-server/bunfig.toml rename to packages/wabe-server/bunfig.toml diff --git a/packages/wibe-server/dev/index.ts b/packages/wabe-server/dev/index.ts similarity index 91% rename from packages/wibe-server/dev/index.ts rename to packages/wabe-server/dev/index.ts index 44e0764d..ffad6334 100644 --- a/packages/wibe-server/dev/index.ts +++ b/packages/wabe-server/dev/index.ts @@ -1,19 +1,19 @@ -import { runDatabase } from 'wibe-mongodb-launcher' -import { WibeApp } from '../src' +import { runDatabase } from 'wabe-mongodb-launcher' +import { WabeApp } from '../src' import { DatabaseEnum } from '../src/database' import type { - WibeSchemaEnums, - WibeSchemaScalars, - WibeSchemaTypes, -} from '../generated/wibe' + WabeSchemaEnums, + WabeSchemaScalars, + WabeSchemaTypes, +} from '../generated/wabe' const run = async () => { await runDatabase() - const wibe = new WibeApp<{ - types: WibeSchemaTypes - scalars: WibeSchemaScalars - enums: WibeSchemaEnums + const wabe = new WabeApp<{ + types: WabeSchemaTypes + scalars: WabeSchemaScalars + enums: WabeSchemaEnums }>({ codegen: { enabled: true, @@ -58,7 +58,7 @@ const run = async () => { database: { type: DatabaseEnum.Mongo, url: 'mongodb://127.0.0.1:27045', - name: 'Wibe', + name: 'Wabe', }, port: 3000, schema: { @@ -170,7 +170,7 @@ const run = async () => { }, }) - await wibe.start() + await wabe.start() } run().catch((err) => { diff --git a/packages/wibe-server/generated/schema.graphql b/packages/wabe-server/generated/schema.graphql similarity index 100% rename from packages/wibe-server/generated/schema.graphql rename to packages/wabe-server/generated/schema.graphql diff --git a/packages/wibe-server/package.json b/packages/wabe-server/package.json similarity index 85% rename from packages/wibe-server/package.json rename to packages/wabe-server/package.json index ec31f579..ea212022 100644 --- a/packages/wibe-server/package.json +++ b/packages/wabe-server/package.json @@ -1,7 +1,7 @@ { - "name": "wibe-server", + "name": "wabe-server", "version": "0.0.1", - "description": "wibe-server", + "description": "wabe-server", "main": "dist/index.js", "scripts": { "build": "bun build --outdir dist $(pwd)/src/index.ts --target=bun && bun generate:types", @@ -10,7 +10,7 @@ "lint": "biome lint . --no-errors-on-unmatched --config-path=../../", "ci": "bun check && bun lint $(pwd) && bun test src", "format": "biome format --write .", - "dev": " bun run --watch dev/index.ts" + "dev": "touch generated/wabe.ts && bun run --watch dev/index.ts" }, "dependencies": { "@graphql-codegen/core": "4.0.2", @@ -34,7 +34,7 @@ "graphql-request": "6.1.0", "uuid": "9.0.1", "wait-on": "7.2.0", - "wibe-mongodb-launcher": "workspace:*", - "wibe-pluralize": "workspace:*" + "wabe-mongodb-launcher": "workspace:*", + "wabe-pluralize": "workspace:*" } } diff --git a/packages/wibe-server/src/authentication/Session.test.ts b/packages/wabe-server/src/authentication/Session.test.ts similarity index 95% rename from packages/wibe-server/src/authentication/Session.test.ts rename to packages/wabe-server/src/authentication/Session.test.ts index ca01c79d..04bb4b4d 100644 --- a/packages/wibe-server/src/authentication/Session.test.ts +++ b/packages/wabe-server/src/authentication/Session.test.ts @@ -35,7 +35,7 @@ describe('_Session', () => { const res = await session.meFromAccessToken('accessToken', { isRoot: true, - wibeApp: { databaseController }, + wabeApp: { databaseController }, } as any) expect(res.user).toBeNull() @@ -57,7 +57,7 @@ describe('_Session', () => { 'refreshToken', 'refreshTokenExpiresAt', ], - context: { isRoot: true, wibeApp: { databaseController } }, + context: { isRoot: true, wabeApp: { databaseController } }, }) }) @@ -80,7 +80,7 @@ describe('_Session', () => { const { sessionId, user } = await session.meFromAccessToken( 'accessToken', - { isRoot: true, wibeApp: { databaseController } } as any, + { isRoot: true, wabeApp: { databaseController } } as any, ) expect(mockGetObjects).toHaveBeenCalledTimes(1) @@ -114,7 +114,7 @@ describe('_Session', () => { const thirtyDays = new Date(Date.now() + 1000 * 60 * 60 * 24 * 30) const { accessToken, refreshToken } = await session.create('userId', { - wibeApp: { databaseController }, + wabeApp: { databaseController }, } as any) expect(accessToken).not.toBeUndefined() @@ -159,7 +159,7 @@ describe('_Session', () => { await session.delete({ sessionId: 'sessionId', - wibeApp: { + wabeApp: { databaseController, }, } as any) @@ -169,7 +169,7 @@ describe('_Session', () => { className: '_Session', context: { sessionId: 'sessionId', - wibeApp: { databaseController }, + wabeApp: { databaseController }, }, id: 'sessionId', fields: [], @@ -196,7 +196,7 @@ describe('_Session', () => { const { accessToken, refreshToken } = await session.refresh( 'accessToken', 'refreshToken', - { wibeApp: { databaseController } } as any, + { wabeApp: { databaseController } } as any, ) expect(accessToken).not.toBeUndefined() @@ -263,7 +263,7 @@ describe('_Session', () => { const { accessToken, refreshToken } = await session.refresh( 'accessToken', 'refreshToken', - { wibeApp: { databaseController } } as any, + { wabeApp: { databaseController } } as any, ) expect(accessToken).toBe('accessToken') @@ -289,7 +289,7 @@ describe('_Session', () => { expect( session.refresh('accessToken', 'refreshToken', { - wibeApp: { databaseController }, + wabeApp: { databaseController }, } as any), ).rejects.toThrow('Session not found') @@ -321,7 +321,7 @@ describe('_Session', () => { expect( session.refresh('accessToken', 'refreshToken', { - wibeApp: { databaseController }, + wabeApp: { databaseController }, } as any), ).rejects.toThrow('Refresh token expired') }) @@ -345,7 +345,7 @@ describe('_Session', () => { expect( session.refresh('accessToken', 'wrongRefreshToken', { - wibeApp: { databaseController }, + wabeApp: { databaseController }, } as any), ).rejects.toThrow('Invalid refresh token') }) diff --git a/packages/wibe-server/src/authentication/Session.ts b/packages/wabe-server/src/authentication/Session.ts similarity index 79% rename from packages/wibe-server/src/authentication/Session.ts rename to packages/wabe-server/src/authentication/Session.ts index c6d4ebd7..804c5e8b 100644 --- a/packages/wibe-server/src/authentication/Session.ts +++ b/packages/wabe-server/src/authentication/Session.ts @@ -1,13 +1,13 @@ import jwt from 'jsonwebtoken' -import type { WibeContext } from '../server/interface' -import type { _Session, User } from '../../generated/wibe' -import type { WibeConfig } from '../server' +import type { WabeContext } from '../server/interface' +import type { _Session, User } from '../../generated/wabe' +import type { WabeConfig } from '../server' export class Session { private accessToken: string | undefined = undefined private refreshToken: string | undefined = undefined - getAccessTokenExpireAt(config: WibeConfig) { + getAccessTokenExpireAt(config: WabeConfig) { const customExpiresIn = config?.authentication?.session?.accessTokenExpiresIn @@ -16,7 +16,7 @@ export class Session { return new Date(Date.now() + customExpiresIn) } - getRefreshTokenExpireAt(config: WibeConfig) { + getRefreshTokenExpireAt(config: WabeConfig) { const customExpiresIn = config?.authentication?.session?.refreshTokenExpiresIn @@ -28,9 +28,9 @@ export class Session { async meFromAccessToken( accessToken: string, - context: WibeContext, + context: WabeContext, ): Promise<{ sessionId: string; user: User | null }> { - const sessions = await context.wibeApp.databaseController.getObjects({ + const sessions = await context.wabeApp.databaseController.getObjects({ className: '_Session', where: { accessToken: { equalTo: accessToken }, @@ -56,13 +56,13 @@ export class Session { return { sessionId: session?.id ?? null, user: user ?? null } } - async create(userId: string, context: WibeContext) { + async create(userId: string, context: WabeContext) { this.accessToken = jwt.sign( { userId, iat: Date.now(), exp: this.getAccessTokenExpireAt( - context.wibeApp.config, + context.wabeApp.config, ).getTime(), }, import.meta.env.JWT_SECRET || 'dev', @@ -73,24 +73,24 @@ export class Session { userId, iat: Date.now(), exp: this.getRefreshTokenExpireAt( - context.wibeApp.config, + context.wabeApp.config, ).getTime(), }, import.meta.env.JWT_SECRET || 'dev', ) - const { id } = await context.wibeApp.databaseController.createObject({ + const { id } = await context.wabeApp.databaseController.createObject({ className: '_Session', context, data: { accessToken: this.accessToken, accessTokenExpiresAt: this.getAccessTokenExpireAt( - context.wibeApp.config, + context.wabeApp.config, ), refreshToken: this.refreshToken, refreshTokenExpiresAt: this.getRefreshTokenExpireAt( - context.wibeApp.config, + context.wabeApp.config, ), user: userId, }, @@ -104,10 +104,10 @@ export class Session { } } - async delete(context: WibeContext) { + async delete(context: WabeContext) { if (!context.sessionId) return - await context.wibeApp.databaseController.deleteObject({ + await context.wabeApp.databaseController.deleteObject({ className: '_Session', context, id: context.sessionId, @@ -118,9 +118,9 @@ export class Session { async refresh( accessToken: string, refreshToken: string, - context: WibeContext, + context: WabeContext, ) { - const session = await context.wibeApp.databaseController.getObjects({ + const session = await context.wabeApp.databaseController.getObjects({ className: '_Session', where: { accessToken: { equalTo: accessToken }, @@ -145,7 +145,7 @@ export class Session { throw new Error('Refresh token expired') const refreshTokenExpireIn = this.getRefreshTokenExpireAt( - context.wibeApp.config, + context.wabeApp.config, ).getTime() // We refresh only if the refresh token is about to expire (75% of the time) @@ -166,7 +166,7 @@ export class Session { userId: user?.id, iat: Date.now(), exp: this.getAccessTokenExpireAt( - context.wibeApp.config, + context.wabeApp.config, ).getTime(), }, import.meta.env.JWT_SECRET || 'dev', @@ -177,13 +177,13 @@ export class Session { userId: user?.id, iat: Date.now(), exp: this.getRefreshTokenExpireAt( - context.wibeApp.config, + context.wabeApp.config, ).getTime(), }, import.meta.env.JWT_SECRET || 'dev', ) - await context.wibeApp.databaseController.updateObject({ + await context.wabeApp.databaseController.updateObject({ className: '_Session', context: { ...context, @@ -193,12 +193,12 @@ export class Session { data: { accessToken: newAccessToken, accessTokenExpiresAt: this.getAccessTokenExpireAt( - context.wibeApp.config, + context.wabeApp.config, ), refreshToken: newRefreshToken, refreshTokenExpiresAt: this.getRefreshTokenExpireAt( - context.wibeApp.config, + context.wabeApp.config, ), }, fields: [], diff --git a/packages/wibe-server/src/authentication/defaultAuthentication.ts b/packages/wabe-server/src/authentication/defaultAuthentication.ts similarity index 93% rename from packages/wibe-server/src/authentication/defaultAuthentication.ts rename to packages/wabe-server/src/authentication/defaultAuthentication.ts index c6cfecb0..3afd0ffa 100644 --- a/packages/wibe-server/src/authentication/defaultAuthentication.ts +++ b/packages/wabe-server/src/authentication/defaultAuthentication.ts @@ -1,10 +1,10 @@ -import type { WibeAppTypes } from '..' +import type { WabeAppTypes } from '..' import type { CustomAuthenticationMethods } from './interface' import { Google } from './providers' import { EmailPassword } from './providers/EmailPassword' export const defaultAuthenticationMethods = < - T extends WibeAppTypes, + T extends WabeAppTypes, >(): CustomAuthenticationMethods[] => [ { name: 'emailPassword', diff --git a/packages/wibe-server/src/authentication/index.test.ts b/packages/wabe-server/src/authentication/index.test.ts similarity index 99% rename from packages/wibe-server/src/authentication/index.test.ts rename to packages/wabe-server/src/authentication/index.test.ts index 3a17982e..1d965f0c 100644 --- a/packages/wibe-server/src/authentication/index.test.ts +++ b/packages/wabe-server/src/authentication/index.test.ts @@ -1,8 +1,8 @@ import { afterAll, afterEach, beforeAll, describe, expect, it } from 'bun:test' import { type GraphQLClient, gql } from 'graphql-request' -import type { WibeApp } from '..' +import type { WabeApp } from '..' import { - type DevWibeAppTypes, + type DevWabeAppTypes, closeTests, getAnonymousClient, getGraphqlClient, @@ -68,21 +68,21 @@ const createUserAndUpdateRole = async ({ } describe('Authentication', () => { - let wibe: WibeApp + let wabe: WabeApp let port: number let client: GraphQLClient let rootClient: GraphQLClient beforeAll(async () => { const setup = await setupTests() - wibe = setup.wibe + wabe = setup.wabe port = setup.port client = getAnonymousClient(port) rootClient = getGraphqlClient(port) }) afterAll(async () => { - await closeTests(wibe) + await closeTests(wabe) }) afterEach(async () => { diff --git a/packages/wibe-server/src/authentication/index.ts b/packages/wabe-server/src/authentication/index.ts similarity index 100% rename from packages/wibe-server/src/authentication/index.ts rename to packages/wabe-server/src/authentication/index.ts diff --git a/packages/wibe-server/src/authentication/interface.ts b/packages/wabe-server/src/authentication/interface.ts similarity index 86% rename from packages/wibe-server/src/authentication/interface.ts rename to packages/wabe-server/src/authentication/interface.ts index 66b65e9f..be18dfe2 100644 --- a/packages/wibe-server/src/authentication/interface.ts +++ b/packages/wabe-server/src/authentication/interface.ts @@ -1,7 +1,7 @@ -import type { User } from '../../generated/wibe' -import type { WibeContext } from '../server/interface' +import type { User } from '../../generated/wabe' +import type { WabeContext } from '../server/interface' import type { SchemaFields } from '../schema' -import type { WibeAppTypes } from '../server' +import type { WabeAppTypes } from '../server' export enum ProviderEnum { google = 'google', @@ -15,7 +15,7 @@ export interface ProviderConfig { export type AuthenticationEventsOptions = { input: T - context: WibeContext + context: WabeContext } export type ProviderInterface = { @@ -39,7 +39,7 @@ export type SecondaryProviderInterface = { } export type CustomAuthenticationMethods< - T extends WibeAppTypes, + T extends WabeAppTypes, U = ProviderInterface | SecondaryProviderInterface, K = SchemaFields, W = SchemaFields, @@ -68,7 +68,7 @@ export interface SessionConfig { cookieSession?: boolean } -export interface AuthenticationConfig { +export interface AuthenticationConfig { session?: SessionConfig roles?: RoleConfig successRedirectPath?: string @@ -93,3 +93,7 @@ export interface Provider { ): Promise refreshToken(options: refreshTokenOptions): Promise } + +export enum AuthenticationProvider { + Google = 'Google', +} diff --git a/packages/wibe-server/src/authentication/oauth/Google.test.ts b/packages/wabe-server/src/authentication/oauth/Google.test.ts similarity index 100% rename from packages/wibe-server/src/authentication/oauth/Google.test.ts rename to packages/wabe-server/src/authentication/oauth/Google.test.ts diff --git a/packages/wibe-server/src/authentication/oauth/Google.ts b/packages/wabe-server/src/authentication/oauth/Google.ts similarity index 96% rename from packages/wibe-server/src/authentication/oauth/Google.ts rename to packages/wabe-server/src/authentication/oauth/Google.ts index 1994fb9a..ab6f14b9 100644 --- a/packages/wibe-server/src/authentication/oauth/Google.ts +++ b/packages/wabe-server/src/authentication/oauth/Google.ts @@ -1,5 +1,5 @@ import { OAuth2Client } from '.' -import type { WibeConfig } from '../../server' +import type { WabeConfig } from '../../server' import type { OAuth2ProviderWithPKCE, Tokens } from './utils' const authorizeEndpoint = 'https://accounts.google.com/o/oauth2/v2/auth' @@ -21,7 +21,7 @@ export class Google implements OAuth2ProviderWithPKCE { private client: OAuth2Client private clientSecret: string - constructor(config: WibeConfig) { + constructor(config: WabeConfig) { const googleConfig = config.authentication?.providers?.google if (!googleConfig) throw new Error('Google config not found') diff --git a/packages/wibe-server/src/authentication/oauth/Oauth2Client.test.ts b/packages/wabe-server/src/authentication/oauth/Oauth2Client.test.ts similarity index 99% rename from packages/wibe-server/src/authentication/oauth/Oauth2Client.test.ts rename to packages/wabe-server/src/authentication/oauth/Oauth2Client.test.ts index 132c5d39..7ee4562a 100644 --- a/packages/wibe-server/src/authentication/oauth/Oauth2Client.test.ts +++ b/packages/wabe-server/src/authentication/oauth/Oauth2Client.test.ts @@ -177,7 +177,7 @@ describe('Oauth2Client', () => { expect(receivedRequest.headers.get('accept')).toEqual( 'application/json', ) - expect(receivedRequest.headers.get('user-agent')).toEqual('wibe') + expect(receivedRequest.headers.get('user-agent')).toEqual('wabe') expect(receivedRequest.headers.get('authorization')).toEqual( `Basic ${encodeCredentials}`, ) diff --git a/packages/wibe-server/src/authentication/oauth/Oauth2Client.ts b/packages/wabe-server/src/authentication/oauth/Oauth2Client.ts similarity index 99% rename from packages/wibe-server/src/authentication/oauth/Oauth2Client.ts rename to packages/wabe-server/src/authentication/oauth/Oauth2Client.ts index 442a1e00..ecf0254b 100644 --- a/packages/wibe-server/src/authentication/oauth/Oauth2Client.ts +++ b/packages/wabe-server/src/authentication/oauth/Oauth2Client.ts @@ -111,7 +111,7 @@ export class OAuth2Client { const headers = new Headers() headers.set('Content-Type', 'application/x-www-form-urlencoded') headers.set('Accept', 'application/json') - headers.set('User-Agent', 'wibe') + headers.set('User-Agent', 'wabe') if (options?.credentials !== undefined) { const authenticateWith = diff --git a/packages/wibe-server/src/authentication/oauth/index.ts b/packages/wabe-server/src/authentication/oauth/index.ts similarity index 100% rename from packages/wibe-server/src/authentication/oauth/index.ts rename to packages/wabe-server/src/authentication/oauth/index.ts diff --git a/packages/wibe-server/src/authentication/oauth/utils.test.ts b/packages/wabe-server/src/authentication/oauth/utils.test.ts similarity index 100% rename from packages/wibe-server/src/authentication/oauth/utils.test.ts rename to packages/wabe-server/src/authentication/oauth/utils.test.ts diff --git a/packages/wibe-server/src/authentication/oauth/utils.ts b/packages/wabe-server/src/authentication/oauth/utils.ts similarity index 100% rename from packages/wibe-server/src/authentication/oauth/utils.ts rename to packages/wabe-server/src/authentication/oauth/utils.ts diff --git a/packages/wibe-server/src/authentication/providers/EmailPassword.test.ts b/packages/wabe-server/src/authentication/providers/EmailPassword.test.ts similarity index 91% rename from packages/wibe-server/src/authentication/providers/EmailPassword.test.ts rename to packages/wabe-server/src/authentication/providers/EmailPassword.test.ts index 476cfa8d..94239044 100644 --- a/packages/wibe-server/src/authentication/providers/EmailPassword.test.ts +++ b/packages/wabe-server/src/authentication/providers/EmailPassword.test.ts @@ -31,7 +31,7 @@ describe('Email password', () => { const { authenticationDataToSave: { email, password }, } = await emailPassword.onSignUp({ - context: { wibeApp: { databaseController } } as any, + context: { wabeApp: { databaseController } } as any, input: { email: 'email@test.fr', password: 'password' }, }) @@ -60,7 +60,7 @@ describe('Email password', () => { spyBunPasswordVerify.mockResolvedValue(true) const { user } = await emailPassword.onSignIn({ - context: { wibeApp: { databaseController } } as any, + context: { wabeApp: { databaseController } } as any, input: { email: 'email@test.fr', password: 'password' }, }) @@ -87,7 +87,7 @@ describe('Email password', () => { expect( emailPassword.onSignIn({ - context: { wibeApp: { databaseController } } as any, + context: { wabeApp: { databaseController } } as any, // @ts-expect-error input: { email: 'email@test.fr' }, }), @@ -99,7 +99,7 @@ describe('Email password', () => { expect( emailPassword.onSignIn({ - context: { wibeApp: { databaseController } } as any, + context: { wabeApp: { databaseController } } as any, input: { email: 'invalidEmail@test.fr', password: 'password', @@ -125,7 +125,7 @@ describe('Email password', () => { expect( emailPassword.onSignIn({ - context: { wibeApp: { databaseController } } as any, + context: { wabeApp: { databaseController } } as any, input: { email: 'invalidEmail@test.fr', password: 'password', diff --git a/packages/wibe-server/src/authentication/providers/EmailPassword.ts b/packages/wabe-server/src/authentication/providers/EmailPassword.ts similarity index 93% rename from packages/wibe-server/src/authentication/providers/EmailPassword.ts rename to packages/wabe-server/src/authentication/providers/EmailPassword.ts index 8c320ac9..aff50916 100644 --- a/packages/wibe-server/src/authentication/providers/EmailPassword.ts +++ b/packages/wabe-server/src/authentication/providers/EmailPassword.ts @@ -16,7 +16,7 @@ export class EmailPassword context, }: AuthenticationEventsOptions) { // TODO : Use first here but need to refactor in graphql and mongoadapter to have first and not limit - const users = await context.wibeApp.databaseController.getObjects({ + const users = await context.wabeApp.databaseController.getObjects({ className: 'User', where: { authentication: { @@ -65,7 +65,7 @@ export class EmailPassword input, context, }: AuthenticationEventsOptions) { - const users = await context.wibeApp.databaseController.getObjects({ + const users = await context.wabeApp.databaseController.getObjects({ className: 'User', where: { authentication: { diff --git a/packages/wibe-server/src/authentication/providers/Google.test.ts b/packages/wabe-server/src/authentication/providers/Google.test.ts similarity index 100% rename from packages/wibe-server/src/authentication/providers/Google.test.ts rename to packages/wabe-server/src/authentication/providers/Google.test.ts diff --git a/packages/wibe-server/src/authentication/providers/Google.ts b/packages/wabe-server/src/authentication/providers/Google.ts similarity index 86% rename from packages/wibe-server/src/authentication/providers/Google.ts rename to packages/wabe-server/src/authentication/providers/Google.ts index 5aa65ade..8e048825 100644 --- a/packages/wibe-server/src/authentication/providers/Google.ts +++ b/packages/wabe-server/src/authentication/providers/Google.ts @@ -1,10 +1,8 @@ +import type { UserAuthenticationGoogle } from '../../../generated/wabe' import { AuthenticationProvider, - type UserAuthenticationGoogle, -} from '../../../generated/wibe' -import type { - AuthenticationEventsOptions, - ProviderInterface, + type AuthenticationEventsOptions, + type ProviderInterface, } from '../interface' import { Google as GoogleOauth } from '../oauth/Google' @@ -21,7 +19,7 @@ export class Google implements ProviderInterface { }: AuthenticationEventsOptions) { const { authorizationCode, codeVerifier } = input - const googleOauth = new GoogleOauth(context.wibeApp.config) + const googleOauth = new GoogleOauth(context.wabeApp.config) const { accessToken, @@ -43,7 +41,7 @@ export class Google implements ProviderInterface { idToken, ) - const user = await context.wibeApp.databaseController.getObjects({ + const user = await context.wabeApp.databaseController.getObjects({ className: 'User', where: { authentication: { @@ -65,7 +63,7 @@ export class Google implements ProviderInterface { if (user.length === 0) { const createdUser = - await context.wibeApp.databaseController.createObject({ + await context.wabeApp.databaseController.createObject({ className: 'User', data: { provider: AuthenticationProvider.Google, diff --git a/packages/wibe-server/src/authentication/providers/index.ts b/packages/wabe-server/src/authentication/providers/index.ts similarity index 100% rename from packages/wibe-server/src/authentication/providers/index.ts rename to packages/wabe-server/src/authentication/providers/index.ts diff --git a/packages/wibe-server/src/authentication/resolvers/index.ts b/packages/wabe-server/src/authentication/resolvers/index.ts similarity index 100% rename from packages/wibe-server/src/authentication/resolvers/index.ts rename to packages/wabe-server/src/authentication/resolvers/index.ts diff --git a/packages/wibe-server/src/authentication/resolvers/refreshResolver.test.ts b/packages/wabe-server/src/authentication/resolvers/refreshResolver.test.ts similarity index 85% rename from packages/wibe-server/src/authentication/resolvers/refreshResolver.test.ts rename to packages/wabe-server/src/authentication/resolvers/refreshResolver.test.ts index fc0811cd..4eda6f4f 100644 --- a/packages/wibe-server/src/authentication/resolvers/refreshResolver.test.ts +++ b/packages/wabe-server/src/authentication/resolvers/refreshResolver.test.ts @@ -1,13 +1,13 @@ import { describe, expect, it, spyOn } from 'bun:test' import { refreshResolver } from './refreshResolver' -import type { WibeContext } from '../../server/interface' +import type { WabeContext } from '../../server/interface' import { Session } from '../Session' -const context: WibeContext = { +const context: WabeContext = { sessionId: 'sessionId', user: {} as any, isRoot: false, -} as WibeContext +} as WabeContext describe('refreshResolver', () => { it('should refresh the session', async () => { diff --git a/packages/wibe-server/src/authentication/resolvers/refreshResolver.ts b/packages/wabe-server/src/authentication/resolvers/refreshResolver.ts similarity index 72% rename from packages/wibe-server/src/authentication/resolvers/refreshResolver.ts rename to packages/wabe-server/src/authentication/resolvers/refreshResolver.ts index 083d9f67..fba64191 100644 --- a/packages/wibe-server/src/authentication/resolvers/refreshResolver.ts +++ b/packages/wabe-server/src/authentication/resolvers/refreshResolver.ts @@ -1,11 +1,11 @@ -import type { WibeContext } from '../../server/interface' -import type { DevWibeAppTypes } from '../../utils/helper' +import type { WabeContext } from '../../server/interface' +import type { DevWabeAppTypes } from '../../utils/helper' import { Session } from '../Session' export const refreshResolver = async ( _: any, args: any, - context: WibeContext, + context: WabeContext, ) => { const { input: { refreshToken, accessToken }, diff --git a/packages/wibe-server/src/authentication/resolvers/signInWithResolver.test.ts b/packages/wabe-server/src/authentication/resolvers/signInWithResolver.test.ts similarity index 98% rename from packages/wibe-server/src/authentication/resolvers/signInWithResolver.test.ts rename to packages/wabe-server/src/authentication/resolvers/signInWithResolver.test.ts index 62c5df49..d05cd22a 100644 --- a/packages/wibe-server/src/authentication/resolvers/signInWithResolver.test.ts +++ b/packages/wabe-server/src/authentication/resolvers/signInWithResolver.test.ts @@ -24,7 +24,7 @@ describe('SignInWith', () => { const mockOnVerifyChallenge = mock(() => Promise.resolve(true)) const context = { - wibeApp: { + wabeApp: { config: { authentication: { session: { @@ -117,7 +117,7 @@ describe('SignInWith', () => { }, }, }, - { wibeApp: { config: { authentication: undefined } } } as any, + { wabeApp: { config: { authentication: undefined } } } as any, ), ).rejects.toThrow('No custom authentication methods found') }) @@ -137,7 +137,7 @@ describe('SignInWith', () => { }, }, { - wibeApp: { + wabeApp: { config: { authentication: { customAuthenticationMethods: [ diff --git a/packages/wibe-server/src/authentication/resolvers/signInWithResolver.ts b/packages/wabe-server/src/authentication/resolvers/signInWithResolver.ts similarity index 85% rename from packages/wibe-server/src/authentication/resolvers/signInWithResolver.ts rename to packages/wabe-server/src/authentication/resolvers/signInWithResolver.ts index e2b915ab..f4efff3d 100644 --- a/packages/wibe-server/src/authentication/resolvers/signInWithResolver.ts +++ b/packages/wabe-server/src/authentication/resolvers/signInWithResolver.ts @@ -1,6 +1,6 @@ -import type { SignInWithInput } from '../../../generated/wibe' -import type { WibeContext } from '../../server/interface' -import type { DevWibeAppTypes } from '../../utils/helper' +import type { SignInWithInput } from '../../../generated/wabe' +import type { WabeContext } from '../../server/interface' +import type { DevWabeAppTypes } from '../../utils/helper' import { Session } from '../Session' import type { ProviderInterface, @@ -19,10 +19,10 @@ export const signInWithResolver = async ( }: { input: SignInWithInput }, - context: WibeContext, + context: WabeContext, ) => { const { provider, name } = getAuthenticationMethod< - DevWibeAppTypes, + DevWabeAppTypes, ProviderInterface >(Object.keys(input.authentication || {}), context) @@ -43,7 +43,7 @@ export const signInWithResolver = async ( // 2 - We call the onSendChallenge method of the provider if (input.authentication?.secondaryFactor) { const secondaryProvider = getAuthenticationMethod< - DevWibeAppTypes, + DevWabeAppTypes, SecondaryProviderInterface >([input.authentication.secondaryFactor], context) @@ -66,10 +66,10 @@ export const signInWithResolver = async ( refreshToken, accessToken, accessTokenExpiresAt: session.getAccessTokenExpireAt( - context.wibeApp.config, + context.wabeApp.config, ), refreshTokenExpiresAt: session.getRefreshTokenExpireAt( - context.wibeApp.config, + context.wabeApp.config, ), } } @@ -81,7 +81,7 @@ export const signInWithResolver = async ( refreshTokenExpiresAt, } = await getRefreshAndAccessToken() - if (context.wibeApp.config.authentication?.session?.cookieSession) { + if (context.wabeApp.config.authentication?.session?.cookieSession) { context.response?.setCookie('refreshToken', refreshToken, { httpOnly: true, path: '/', diff --git a/packages/wibe-server/src/authentication/resolvers/signOutResolver.test.ts b/packages/wabe-server/src/authentication/resolvers/signOutResolver.test.ts similarity index 86% rename from packages/wibe-server/src/authentication/resolvers/signOutResolver.test.ts rename to packages/wabe-server/src/authentication/resolvers/signOutResolver.test.ts index 792a69e3..1b53efcb 100644 --- a/packages/wibe-server/src/authentication/resolvers/signOutResolver.test.ts +++ b/packages/wabe-server/src/authentication/resolvers/signOutResolver.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it, spyOn } from 'bun:test' import { signOutResolver } from './signOutResolver' -import type { WibeContext } from '../../server/interface' +import type { WabeContext } from '../../server/interface' import { Session } from '../Session' describe('signOut', () => { @@ -12,7 +12,7 @@ describe('signOut', () => { await signOutResolver(undefined, {}, { sessionId: 'sessionId', - } as WibeContext) + } as WabeContext) expect(spyDeleteSession).toHaveBeenCalledTimes(1) expect(spyDeleteSession).toHaveBeenCalledWith({ diff --git a/packages/wibe-server/src/authentication/resolvers/signOutResolver.ts b/packages/wabe-server/src/authentication/resolvers/signOutResolver.ts similarity index 67% rename from packages/wibe-server/src/authentication/resolvers/signOutResolver.ts rename to packages/wabe-server/src/authentication/resolvers/signOutResolver.ts index 99458824..4143f31f 100644 --- a/packages/wibe-server/src/authentication/resolvers/signOutResolver.ts +++ b/packages/wabe-server/src/authentication/resolvers/signOutResolver.ts @@ -1,11 +1,11 @@ -import type { WibeContext } from '../../server/interface' -import type { DevWibeAppTypes } from '../../utils/helper' +import type { WabeContext } from '../../server/interface' +import type { DevWabeAppTypes } from '../../utils/helper' import { Session } from '../Session' export const signOutResolver = async ( _: any, __: any, - context: WibeContext, + context: WabeContext, ) => { const session = new Session() diff --git a/packages/wibe-server/src/authentication/resolvers/signUpWithResolver.test.ts b/packages/wabe-server/src/authentication/resolvers/signUpWithResolver.test.ts similarity index 98% rename from packages/wibe-server/src/authentication/resolvers/signUpWithResolver.test.ts rename to packages/wabe-server/src/authentication/resolvers/signUpWithResolver.test.ts index fe79c7ef..491d16e6 100644 --- a/packages/wibe-server/src/authentication/resolvers/signUpWithResolver.test.ts +++ b/packages/wabe-server/src/authentication/resolvers/signUpWithResolver.test.ts @@ -47,7 +47,7 @@ describe('SignUpWith', () => { } const context = { - wibeApp: { config, databaseController: mockDatabaseController }, + wabeApp: { config, databaseController: mockDatabaseController }, } as any beforeEach(() => { diff --git a/packages/wibe-server/src/authentication/resolvers/signUpWithResolver.ts b/packages/wabe-server/src/authentication/resolvers/signUpWithResolver.ts similarity index 71% rename from packages/wibe-server/src/authentication/resolvers/signUpWithResolver.ts rename to packages/wabe-server/src/authentication/resolvers/signUpWithResolver.ts index 56658cf6..00d0088c 100644 --- a/packages/wibe-server/src/authentication/resolvers/signUpWithResolver.ts +++ b/packages/wabe-server/src/authentication/resolvers/signUpWithResolver.ts @@ -1,5 +1,5 @@ -import type { SignUpWithInput } from '../../../generated/wibe' -import type { WibeContext } from '../../server/interface' +import type { SignUpWithInput } from '../../../generated/wabe' +import type { WabeContext } from '../../server/interface' import { Session } from '../Session' // 0 - Get the authentication method @@ -13,11 +13,11 @@ export const signUpWithResolver = async ( }: { input: SignUpWithInput }, - context: WibeContext, + context: WabeContext, ) => { // Create object call the provider signUp const { id: userId } = - await context.wibeApp.databaseController.createObject({ + await context.wabeApp.databaseController.createObject({ className: 'User', data: { authentication: input.authentication, @@ -36,19 +36,19 @@ export const signUpWithResolver = async ( isRoot: true, }) - if (context.wibeApp.config.authentication?.session?.cookieSession) { + if (context.wabeApp.config.authentication?.session?.cookieSession) { context.response?.setCookie('refreshToken', refreshToken, { httpOnly: true, path: '/', secure: process.env.NODE_ENV === 'production', - expires: session.getRefreshTokenExpireAt(context.wibeApp.config), + expires: session.getRefreshTokenExpireAt(context.wabeApp.config), }) context.response?.setCookie('accessToken', accessToken, { httpOnly: true, path: '/', secure: process.env.NODE_ENV === 'production', - expires: session.getAccessTokenExpireAt(context.wibeApp.config), + expires: session.getAccessTokenExpireAt(context.wabeApp.config), }) } diff --git a/packages/wibe-server/src/authentication/resolvers/verifyChallenge.test.ts b/packages/wabe-server/src/authentication/resolvers/verifyChallenge.test.ts similarity index 95% rename from packages/wibe-server/src/authentication/resolvers/verifyChallenge.test.ts rename to packages/wabe-server/src/authentication/resolvers/verifyChallenge.test.ts index 71f14fe0..c3d192bf 100644 --- a/packages/wibe-server/src/authentication/resolvers/verifyChallenge.test.ts +++ b/packages/wabe-server/src/authentication/resolvers/verifyChallenge.test.ts @@ -1,17 +1,17 @@ import { describe, expect, it, beforeEach, mock, spyOn } from 'bun:test' import { verifyChallengeResolver } from './verifyChallenge' -import type { WibeContext } from '../../server/interface' +import type { WabeContext } from '../../server/interface' import { Session } from '../Session' describe('verifyChallenge', () => { const mockOnVerifyChallenge = mock(() => Promise.resolve(true)) - const context: WibeContext = { + const context: WabeContext = { sessionId: 'sessionId', user: { id: 'userId', } as any, - wibeApp: { + wabeApp: { config: { authentication: { customAuthenticationMethods: [ diff --git a/packages/wibe-server/src/authentication/resolvers/verifyChallenge.ts b/packages/wabe-server/src/authentication/resolvers/verifyChallenge.ts similarity index 85% rename from packages/wibe-server/src/authentication/resolvers/verifyChallenge.ts rename to packages/wabe-server/src/authentication/resolvers/verifyChallenge.ts index 5ae25442..732b60e0 100644 --- a/packages/wibe-server/src/authentication/resolvers/verifyChallenge.ts +++ b/packages/wabe-server/src/authentication/resolvers/verifyChallenge.ts @@ -1,5 +1,5 @@ -import type { VerifyChallengeInput } from '../../../generated/wibe' -import type { WibeContext } from '../../server/interface' +import type { VerifyChallengeInput } from '../../../generated/wabe' +import type { WabeContext } from '../../server/interface' import { Session } from '../Session' import type { SecondaryProviderInterface } from '../interface' import { getAuthenticationMethod } from '../utils' @@ -11,7 +11,7 @@ export const verifyChallengeResolver = async ( }: { input: VerifyChallengeInput }, - context: WibeContext, + context: WabeContext, ) => { if (!input.factor) throw new Error('One factor is required') diff --git a/packages/wibe-server/src/authentication/roles.test.ts b/packages/wabe-server/src/authentication/roles.test.ts similarity index 93% rename from packages/wibe-server/src/authentication/roles.test.ts rename to packages/wabe-server/src/authentication/roles.test.ts index c76762f7..f4df4501 100644 --- a/packages/wibe-server/src/authentication/roles.test.ts +++ b/packages/wabe-server/src/authentication/roles.test.ts @@ -24,7 +24,7 @@ describe('Roles', () => { expect(mockCreateObjects).toHaveBeenCalledTimes(1) expect(mockCreateObjects).toHaveBeenCalledWith({ className: 'Role', - context: { isRoot: true, wibeApp: { databaseController, config } }, + context: { isRoot: true, wabeApp: { databaseController, config } }, data: [{ name: 'Role1' }, { name: 'Role2' }], fields: [], }) diff --git a/packages/wibe-server/src/authentication/roles.ts b/packages/wabe-server/src/authentication/roles.ts similarity index 74% rename from packages/wibe-server/src/authentication/roles.ts rename to packages/wabe-server/src/authentication/roles.ts index b83b9d3e..43949ce8 100644 --- a/packages/wibe-server/src/authentication/roles.ts +++ b/packages/wabe-server/src/authentication/roles.ts @@ -1,8 +1,8 @@ -import type { DatabaseController, WibeConfig } from '..' +import type { DatabaseController, WabeConfig } from '..' export const initializeRoles = async ( databaseController: DatabaseController, - config: WibeConfig, + config: WabeConfig, ) => { const roles = config?.authentication?.roles || [] @@ -16,7 +16,7 @@ export const initializeRoles = async ( className: 'Role', context: { isRoot: true, - wibeApp: { databaseController, config } as any, + wabeApp: { databaseController, config } as any, }, data: objectsToCreate, fields: [], diff --git a/packages/wibe-server/src/authentication/utils.test.ts b/packages/wabe-server/src/authentication/utils.test.ts similarity index 91% rename from packages/wibe-server/src/authentication/utils.test.ts rename to packages/wabe-server/src/authentication/utils.test.ts index 9835304d..fe0ddc46 100644 --- a/packages/wibe-server/src/authentication/utils.test.ts +++ b/packages/wabe-server/src/authentication/utils.test.ts @@ -54,28 +54,28 @@ describe('Authentication utils', () => { expect(() => getAuthenticationMethod( ['emailPassword', 'otherAuthenticationMethod'], - { wibeApp: { config } } as any, + { wabeApp: { config } } as any, ), ).toThrow('One authentication method is required at the time') }) it('should throw an error if no authentication methods is provided', () => { expect(() => - getAuthenticationMethod([], { wibeApp: { config } } as any), + getAuthenticationMethod([], { wabeApp: { config } } as any), ).toThrow('One authentication method is required at the time') }) it('should throw an error if no one authentication method is found', () => { expect(() => getAuthenticationMethod(['otherAuthenticationMethod'], { - wibeApp: { config }, + wabeApp: { config }, } as any), ).toThrow('No available custom authentication methods found') }) it('should find a secondary factor method', () => { expect( - getAuthenticationMethod(['otp'], { wibeApp: { config } } as any), + getAuthenticationMethod(['otp'], { wabeApp: { config } } as any), ).toEqual({ name: 'otp', input: expect.any(Object), @@ -88,7 +88,7 @@ describe('Authentication utils', () => { it('should return the valid authentication method', () => { expect( getAuthenticationMethod(['emailPassword'], { - wibeApp: { config }, + wabeApp: { config }, } as any), ).toEqual({ name: 'emailPassword', diff --git a/packages/wibe-server/src/authentication/utils.ts b/packages/wabe-server/src/authentication/utils.ts similarity index 85% rename from packages/wibe-server/src/authentication/utils.ts rename to packages/wabe-server/src/authentication/utils.ts index 9b0af247..a1209952 100644 --- a/packages/wibe-server/src/authentication/utils.ts +++ b/packages/wabe-server/src/authentication/utils.ts @@ -1,5 +1,5 @@ -import type { WibeAppTypes } from '../server' -import type { WibeContext } from '../server/interface' +import type { WabeAppTypes } from '../server' +import type { WabeContext } from '../server/interface' import type { CustomAuthenticationMethods, ProviderInterface, @@ -7,14 +7,14 @@ import type { } from './interface' export const getAuthenticationMethod = < - T extends WibeAppTypes, + T extends WabeAppTypes, U extends ProviderInterface | SecondaryProviderInterface, >( listOfMethods: string[], - context: WibeContext, + context: WabeContext, ): CustomAuthenticationMethods => { const customAuthenticationConfig = - context.wibeApp.config?.authentication?.customAuthenticationMethods + context.wabeApp.config?.authentication?.customAuthenticationMethods if (!customAuthenticationConfig) throw new Error('No custom authentication methods found') diff --git a/packages/wibe-server/src/cache/InMemoryCache.test.ts b/packages/wabe-server/src/cache/InMemoryCache.test.ts similarity index 100% rename from packages/wibe-server/src/cache/InMemoryCache.test.ts rename to packages/wabe-server/src/cache/InMemoryCache.test.ts diff --git a/packages/wibe-server/src/cache/InMemoryCache.ts b/packages/wabe-server/src/cache/InMemoryCache.ts similarity index 100% rename from packages/wibe-server/src/cache/InMemoryCache.ts rename to packages/wabe-server/src/cache/InMemoryCache.ts diff --git a/packages/wibe-server/src/database/adapters/MongoAdapter.test.ts b/packages/wabe-server/src/database/adapters/MongoAdapter.test.ts similarity index 98% rename from packages/wibe-server/src/database/adapters/MongoAdapter.test.ts rename to packages/wabe-server/src/database/adapters/MongoAdapter.test.ts index 59af08d4..39c146cc 100644 --- a/packages/wibe-server/src/database/adapters/MongoAdapter.test.ts +++ b/packages/wabe-server/src/database/adapters/MongoAdapter.test.ts @@ -9,38 +9,38 @@ import { } from 'bun:test' import { fail } from 'node:assert' import { ObjectId } from 'mongodb' -import type { WibeApp } from '../..' +import type { WabeApp } from '../..' import { - type DevWibeAppTypes, + type DevWabeAppTypes, closeTests, setupTests, } from '../../utils/helper' import { type MongoAdapter, buildMongoWhereQuery } from './MongoAdapter' -import type { WibeContext } from '../../server/interface' +import type { WabeContext } from '../../server/interface' describe('Mongo adapter', () => { - let mongoAdapter: MongoAdapter - let wibe: WibeApp - let context: WibeContext + let mongoAdapter: MongoAdapter + let wabe: WabeApp + let context: WabeContext beforeAll(async () => { const setup = await setupTests() - wibe = setup.wibe + wabe = setup.wabe // @ts-expect-error - mongoAdapter = wibe.databaseController.adapter + mongoAdapter = wabe.databaseController.adapter context = { isRoot: true, - wibeApp: { - databaseController: wibe.databaseController, - config: wibe.config, + wabeApp: { + databaseController: wabe.databaseController, + config: wabe.config, }, - } as WibeContext + } as WabeContext }) afterAll(async () => { - await closeTests(wibe) + await closeTests(wabe) }) beforeEach(async () => { diff --git a/packages/wibe-server/src/database/adapters/MongoAdapter.ts b/packages/wabe-server/src/database/adapters/MongoAdapter.ts similarity index 94% rename from packages/wibe-server/src/database/adapters/MongoAdapter.ts rename to packages/wabe-server/src/database/adapters/MongoAdapter.ts index a9bb7e3c..3807596a 100644 --- a/packages/wibe-server/src/database/adapters/MongoAdapter.ts +++ b/packages/wabe-server/src/database/adapters/MongoAdapter.ts @@ -14,12 +14,12 @@ import type { OutputType, CountOptions, } from './adaptersInterface' -import type { WibeAppTypes } from '../../server' -import type { WibeContext } from '../../server/interface' +import type { WabeAppTypes } from '../../server' +import type { WabeContext } from '../../server/interface' export const buildMongoWhereQuery = < - T extends keyof WibeAppTypes['types'], - K extends keyof WibeAppTypes['types'][T], + T extends keyof WabeAppTypes['types'], + K extends keyof WabeAppTypes['types'][T], >( where?: WhereType, ): Record => { @@ -115,7 +115,7 @@ export const buildMongoWhereQuery = < ) } -export class MongoAdapter implements DatabaseAdapter { +export class MongoAdapter implements DatabaseAdapter { public options: AdapterOptions public database?: Db private client: MongoClient @@ -137,12 +137,12 @@ export class MongoAdapter implements DatabaseAdapter { async createClassIfNotExist( className: keyof T['types'], - context: WibeContext, + context: WabeContext, ) { if (!this.database) throw new Error('Connection to database is not established') - const schemaClass = context.wibeApp.config.schema.classes.find( + const schemaClass = context.wabeApp.config.schema.classes.find( (currentClass) => currentClass.name === className, ) @@ -292,7 +292,7 @@ export class MongoAdapter implements DatabaseAdapter { const res = await collection.insertOne(data, {}) - const object = await context.wibeApp.databaseController.getObject({ + const object = await context.wabeApp.databaseController.getObject({ className, id: res.insertedId.toString(), context, @@ -322,7 +322,7 @@ export class MongoAdapter implements DatabaseAdapter { }), ) - const allObjects = await context.wibeApp.databaseController.getObjects({ + const allObjects = await context.wabeApp.databaseController.getObjects({ className, where: { OR: orStatement } as WhereType, fields, @@ -360,7 +360,7 @@ export class MongoAdapter implements DatabaseAdapter { if (res.matchedCount === 0) throw new Error('Object not found') - const object = await context.wibeApp.databaseController.getObject({ + const object = await context.wabeApp.databaseController.getObject({ className, context, fields, @@ -386,7 +386,7 @@ export class MongoAdapter implements DatabaseAdapter { const collection = await this.createClassIfNotExist(className, context) const objectsBeforeUpdate = - await context.wibeApp.databaseController.getObjects({ + await context.wabeApp.databaseController.getObjects({ className, where, fields: ['id'], @@ -406,7 +406,7 @@ export class MongoAdapter implements DatabaseAdapter { id: { equalTo: ObjectId.createFromHexString(object.id) }, })) - const objects = await context.wibeApp.databaseController.getObjects({ + const objects = await context.wabeApp.databaseController.getObjects({ className, where: { OR: orStatement, diff --git a/packages/wabe-server/src/database/adapters/adaptersInterface.ts b/packages/wabe-server/src/database/adapters/adaptersInterface.ts new file mode 100644 index 00000000..4382c8ee --- /dev/null +++ b/packages/wabe-server/src/database/adapters/adaptersInterface.ts @@ -0,0 +1,220 @@ +import type { WabeContext } from '../../server/interface' +import type { WabeAppTypes } from '../../server' + +type WhereAggregation< + T extends keyof WabeAppTypes['types'], + K extends keyof WabeAppTypes['types'][T], +> = Record< + K | 'id', + { + equalTo?: any + notEqualTo?: any + greaterThan?: any + lessThan?: any + greaterThanOrEqualTo?: any + lessThanOrEqualTo?: any + in?: any[] + notIn?: any[] + contains?: any + notContains?: any + } +> + +type WhereConditional< + T extends keyof WabeAppTypes['types'], + K extends keyof WabeAppTypes['types'][T], +> = { + OR?: Array> + AND?: Array> +} + +export type WhereType< + T extends keyof WabeAppTypes['types'], + K extends keyof WabeAppTypes['types'][T], +> = Partial> & WhereConditional + +export interface AdapterOptions { + databaseUrl: string + databaseName: string +} + +export type MutationData = Record< + keyof WabeAppTypes['types'][T], + any +> + +export interface CountOptions< + T extends keyof WabeAppTypes['types'], + K extends keyof WabeAppTypes['types'][T], +> { + className: T + where?: WhereType + context: WabeContext +} + +// TODO: It could be cool if fields type supports something like user.id, user.email +export interface GetObjectOptions< + T extends keyof WabeAppTypes['types'], + K extends keyof WabeAppTypes['types'][T], +> { + className: T + id: string + where?: WhereType + fields: Array + context: WabeContext + skipHooks?: boolean +} + +export interface GetObjectsOptions< + T extends keyof WabeAppTypes['types'], + K extends keyof WabeAppTypes['types'][T], + W extends keyof WabeAppTypes['types'][T], +> { + className: T + where?: WhereType + fields: Array + offset?: number + first?: number + context: WabeContext + skipHooks?: boolean +} + +export interface CreateObjectOptions< + T extends keyof WabeAppTypes['types'], + K extends keyof WabeAppTypes['types'][T], + W extends keyof WabeAppTypes['types'][T], +> { + className: T + data: MutationData + fields: Array + context: WabeContext +} +export interface CreateObjectsOptions< + T extends keyof WabeAppTypes['types'], + K extends keyof WabeAppTypes['types'][T], + W extends keyof WabeAppTypes['types'][T], +> { + className: T + data: Array> + fields: Array + offset?: number + first?: number + context: WabeContext +} + +export interface UpdateObjectOptions< + T extends keyof WabeAppTypes['types'], + K extends keyof WabeAppTypes['types'][T], + W extends keyof WabeAppTypes['types'][T], +> { + className: T + id: string + where?: WhereType + data: MutationData + fields: Array + context: WabeContext +} + +export interface UpdateObjectsOptions< + T extends keyof WabeAppTypes['types'], + K extends keyof WabeAppTypes['types'][T], + W extends keyof WabeAppTypes['types'][T], +> { + className: T + where: WhereType + data: MutationData + fields: Array + offset?: number + first?: number + context: WabeContext +} + +export interface DeleteObjectOptions< + T extends keyof WabeAppTypes['types'], + K extends keyof WabeAppTypes['types'][T], + W extends keyof WabeAppTypes['types'][T], +> { + className: T + id: string + where?: WhereType + fields: Array + context: WabeContext +} + +export interface DeleteObjectsOptions< + T extends keyof WabeAppTypes['types'], + K extends keyof WabeAppTypes['types'][T], + W extends keyof WabeAppTypes['types'][T], +> { + className: T + where: WhereType + fields: Array + offset?: number + first?: number + context: WabeContext +} + +export type OutputType< + T extends keyof WabeAppTypes['types'], + K extends keyof WabeAppTypes['types'][T], +> = Pick & { id: string } + +export interface DatabaseAdapter { + connect(): Promise + close(): Promise + + createClassIfNotExist( + className: string, + context: WabeContext, + ): Promise + + clearDatabase(): Promise + + count< + T extends keyof WabeAppTypes['types'], + K extends keyof WabeAppTypes['types'][T], + >(params: CountOptions): Promise + + getObject< + T extends keyof WabeAppTypes['types'], + K extends keyof WabeAppTypes['types'][T], + >(params: GetObjectOptions): Promise> + getObjects< + T extends keyof WabeAppTypes['types'], + K extends keyof WabeAppTypes['types'][T], + W extends keyof WabeAppTypes['types'][T], + >(params: GetObjectsOptions): Promise[]> + + createObject< + T extends keyof WabeAppTypes['types'], + K extends keyof WabeAppTypes['types'][T], + W extends keyof WabeAppTypes['types'][T], + >(params: CreateObjectOptions): Promise> + createObjects< + T extends keyof WabeAppTypes['types'], + K extends keyof WabeAppTypes['types'][T], + W extends keyof WabeAppTypes['types'][T], + >(params: CreateObjectsOptions): Promise[]> + + updateObject< + T extends keyof WabeAppTypes['types'], + K extends keyof WabeAppTypes['types'][T], + W extends keyof WabeAppTypes['types'][T], + >(params: UpdateObjectOptions): Promise> + updateObjects< + T extends keyof WabeAppTypes['types'], + K extends keyof WabeAppTypes['types'][T], + W extends keyof WabeAppTypes['types'][T], + >(params: UpdateObjectsOptions): Promise[]> + + deleteObject< + T extends keyof WabeAppTypes['types'], + K extends keyof WabeAppTypes['types'][T], + W extends keyof WabeAppTypes['types'][T], + >(params: DeleteObjectOptions): Promise + deleteObjects< + T extends keyof WabeAppTypes['types'], + K extends keyof WabeAppTypes['types'][T], + W extends keyof WabeAppTypes['types'][T], + >(params: DeleteObjectsOptions): Promise +} diff --git a/packages/wibe-server/src/database/adapters/index.ts b/packages/wabe-server/src/database/adapters/index.ts similarity index 100% rename from packages/wibe-server/src/database/adapters/index.ts rename to packages/wabe-server/src/database/adapters/index.ts diff --git a/packages/wibe-server/src/database/controllers/DatabaseController.test.ts b/packages/wabe-server/src/database/controllers/DatabaseController.test.ts similarity index 96% rename from packages/wibe-server/src/database/controllers/DatabaseController.test.ts rename to packages/wabe-server/src/database/controllers/DatabaseController.test.ts index f1eee001..d6a877b5 100644 --- a/packages/wibe-server/src/database/controllers/DatabaseController.test.ts +++ b/packages/wabe-server/src/database/controllers/DatabaseController.test.ts @@ -9,7 +9,7 @@ import { } from 'bun:test' import { DatabaseController, type WhereType } from '..' import * as hooks from '../../hooks/index' -import type { WibeContext } from '../../server/interface' +import type { WabeContext } from '../../server/interface' describe('DatabaseController', () => { const mockGetObject = mock(() => {}) @@ -118,7 +118,7 @@ describe('DatabaseController', () => { const context = { isRoot: true, - wibeApp: { config }, + wabeApp: { config }, sessionId: 'sessionId', } as any @@ -170,9 +170,9 @@ describe('DatabaseController', () => { id: { equalTo: 'id' }, } - const context: WibeContext = { + const context: WabeContext = { isRoot: true, - wibeApp: {} as any, + wabeApp: {} as any, user: { id: 'userId', role: { @@ -197,9 +197,9 @@ describe('DatabaseController', () => { id: { equalTo: 'id' }, } - const context: WibeContext = { + const context: WabeContext = { isRoot: false, - wibeApp: {} as any, + wabeApp: {} as any, user: { id: 'userId', role: { @@ -261,9 +261,9 @@ describe('DatabaseController', () => { id: { equalTo: 'id' }, } - const context: WibeContext = { + const context: WabeContext = { isRoot: false, - wibeApp: {} as any, + wabeApp: {} as any, user: { id: 'userId', } as any, @@ -303,9 +303,9 @@ describe('DatabaseController', () => { id: { equalTo: 'id' }, } - const context: WibeContext = { + const context: WabeContext = { isRoot: false, - wibeApp: {} as any, + wabeApp: {} as any, user: {} as any, } @@ -349,7 +349,7 @@ describe('DatabaseController', () => { className: 'TestClass', context: { sessionId: 'sessionId', - wibeApp: { config }, + wabeApp: { config }, isRoot: true, }, }) @@ -382,7 +382,7 @@ describe('DatabaseController', () => { className: 'TestClass', context: { sessionId: 'sessionId', - wibeApp: { config }, + wabeApp: { config }, isRoot: true, }, }) @@ -420,7 +420,7 @@ describe('DatabaseController', () => { className: 'TestClass', context: { sessionId: 'sessionId', - wibeApp: { config }, + wabeApp: { config }, isRoot: true, }, newData: { name: 'test' }, @@ -459,7 +459,7 @@ describe('DatabaseController', () => { className: 'TestClass', context: { sessionId: 'sessionId', - wibeApp: { config }, + wabeApp: { config }, isRoot: true, }, newData: { name: 'test' }, @@ -493,7 +493,7 @@ describe('DatabaseController', () => { className: 'TestClass', context: { sessionId: 'sessionId', - wibeApp: { config }, + wabeApp: { config }, isRoot: true, }, newData: { name: 'test' }, @@ -533,7 +533,7 @@ describe('DatabaseController', () => { className: 'TestClass', context: { sessionId: 'sessionId', - wibeApp: { config }, + wabeApp: { config }, isRoot: true, }, newData: { name: 'test' }, @@ -566,7 +566,7 @@ describe('DatabaseController', () => { className: 'TestClass', context: { sessionId: 'sessionId', - wibeApp: { config }, + wabeApp: { config }, isRoot: true, }, }) @@ -601,7 +601,7 @@ describe('DatabaseController', () => { className: 'TestClass', context: { sessionId: 'sessionId', - wibeApp: { config }, + wabeApp: { config }, isRoot: true, }, }) diff --git a/packages/wibe-server/src/database/controllers/DatabaseController.ts b/packages/wabe-server/src/database/controllers/DatabaseController.ts similarity index 96% rename from packages/wibe-server/src/database/controllers/DatabaseController.ts rename to packages/wabe-server/src/database/controllers/DatabaseController.ts index 4f4013c2..457d8c8f 100644 --- a/packages/wibe-server/src/database/controllers/DatabaseController.ts +++ b/packages/wabe-server/src/database/controllers/DatabaseController.ts @@ -1,7 +1,7 @@ -import type { WibeAppTypes } from '../..' +import type { WabeAppTypes } from '../..' import { InMemoryCache } from '../../cache/InMemoryCache' import { OperationType, initializeHook } from '../../hooks' -import type { WibeContext } from '../../server/interface' +import type { WabeContext } from '../../server/interface' import { notEmpty } from '../../utils/helper' import type { CountOptions, @@ -31,7 +31,7 @@ interface PointerFields { pointers: PointerObject } -export class DatabaseController { +export class DatabaseController { public adapter: DatabaseAdapter public inMemoryCache: InMemoryCache | undefined> @@ -48,16 +48,16 @@ export class DatabaseController { return this.adapter.close() } - async createClassIfNotExist(className: string, context: WibeContext) { + async createClassIfNotExist(className: string, context: WabeContext) { return this.adapter.createClassIfNotExist(className, context) } _getPointerObject( className: keyof T['types'], fields: string[], - context: WibeContext, + context: WabeContext, ): PointerFields { - const realClass = context.wibeApp.config.schema.classes.find( + const realClass = context.wabeApp.config.schema.classes.find( // @ts-expect-error (c) => c.name.toLowerCase() === className.toLowerCase(), ) @@ -102,12 +102,12 @@ export class DatabaseController { _isRelationField( originClassName: U, - context: WibeContext, + context: WabeContext, pointerClassName?: string, ) { if (!pointerClassName) return false - return context.wibeApp.config.schema.classes.some( + return context.wabeApp.config.schema.classes.some( (c) => // @ts-expect-error c.name.toLowerCase() === originClassName.toLowerCase() && @@ -123,12 +123,12 @@ export class DatabaseController { _isPointerField( originClassName: U, - context: WibeContext, + context: WabeContext, pointerClassName?: string, ) { if (!pointerClassName) return false - return context.wibeApp.config.schema.classes.some( + return context.wabeApp.config.schema.classes.some( (c) => // @ts-expect-error c.name.toLowerCase() === originClassName.toLowerCase() && @@ -149,7 +149,7 @@ export class DatabaseController { objectData: OutputType | null, pointersObject: PointerObject, originClassName: U, - context: WibeContext, + context: WabeContext, ): Promise> { return Object.entries(pointersObject).reduce( async ( @@ -215,10 +215,10 @@ export class DatabaseController { async _getWhereObjectWithPointerOrRelation< U extends keyof T['types'], K extends keyof T['types'][U], - >(className: U, where: WhereType, context: WibeContext) { + >(className: U, where: WhereType, context: WabeContext) { const whereKeys = Object.keys(where) as Array> - const realClass = context.wibeApp.config.schema.classes.find( + const realClass = context.wabeApp.config.schema.classes.find( // @ts-expect-error (c) => c.name.toLowerCase() === className.toLowerCase(), ) @@ -280,7 +280,7 @@ export class DatabaseController { K extends keyof T['types'][U], >( where: WhereType, - context: WibeContext, + context: WabeContext, operation: 'write' | 'read', ): WhereType { if (context.isRoot) return where diff --git a/packages/wibe-server/src/database/controllers/index.ts b/packages/wabe-server/src/database/controllers/index.ts similarity index 100% rename from packages/wibe-server/src/database/controllers/index.ts rename to packages/wabe-server/src/database/controllers/index.ts diff --git a/packages/wibe-server/src/database/index.test.ts b/packages/wabe-server/src/database/index.test.ts similarity index 76% rename from packages/wibe-server/src/database/index.test.ts rename to packages/wabe-server/src/database/index.test.ts index cf6a1b81..d91c0b37 100644 --- a/packages/wibe-server/src/database/index.test.ts +++ b/packages/wabe-server/src/database/index.test.ts @@ -9,17 +9,17 @@ import { beforeEach, type Mock, } from 'bun:test' -import type { WibeApp } from '../server' -import { type DevWibeAppTypes, setupTests, closeTests } from '../utils/helper' -import type { WibeContext } from '../server/interface' +import type { WabeApp } from '../server' +import { type DevWabeAppTypes, setupTests, closeTests } from '../utils/helper' +import type { WabeContext } from '../server/interface' import { OperationType, getDefaultHooks } from '../hooks' describe('Database', () => { - let wibe: WibeApp - let context: WibeContext + let wabe: WabeApp + let context: WabeContext const mockUpdateObject = mock(async () => { - await context.wibeApp.databaseController.updateObjects({ + await context.wabeApp.databaseController.updateObjects({ className: 'User', where: { name: { equalTo: 'Lucas' }, @@ -31,7 +31,7 @@ describe('Database', () => { }) const mockAfterUpdate = mock(async () => { - await context.wibeApp.databaseController.createObjects({ + await context.wabeApp.databaseController.createObjects({ className: 'Test2', data: [{ name: 'test' }], context, @@ -44,33 +44,33 @@ describe('Database', () => { beforeAll(async () => { const setup = await setupTests() - wibe = setup.wibe + wabe = setup.wabe context = { isRoot: true, - wibeApp: { - databaseController: wibe.databaseController, - config: wibe.config, + wabeApp: { + databaseController: wabe.databaseController, + config: wabe.config, }, - } as WibeContext + } as WabeContext - spyGetObjects = spyOn(wibe.databaseController, 'getObjects') - spyGetObject = spyOn(wibe.databaseController, 'getObject') + spyGetObjects = spyOn(wabe.databaseController, 'getObjects') + spyGetObject = spyOn(wabe.databaseController, 'getObject') }) afterAll(async () => { - await closeTests(wibe) + await closeTests(wabe) }) beforeEach(async () => { - await wibe.databaseController.deleteObjects({ + await wabe.databaseController.deleteObjects({ className: 'User', where: { name: { equalTo: 'Lucas' } }, context, fields: [], }) - await wibe.databaseController.deleteObjects({ + await wabe.databaseController.deleteObjects({ // @ts-expect-error className: 'Test2', // @ts-expect-error @@ -79,7 +79,7 @@ describe('Database', () => { fields: [], }) - wibe.config.hooks = getDefaultHooks() + wabe.config.hooks = getDefaultHooks() mockUpdateObject.mockClear() mockAfterUpdate.mockClear() @@ -88,7 +88,7 @@ describe('Database', () => { }) it('should create object with subobject (hooks default call authentication before create user)', async () => { - const res = await wibe.databaseController.createObject({ + const res = await wabe.databaseController.createObject({ className: 'User', context, fields: ['*'], @@ -113,9 +113,9 @@ describe('Database', () => { }) it('should not computeObject in runOnSingleObject if there is no hooks to execute on createObject', async () => { - wibe.config.hooks = [] + wabe.config.hooks = [] - await wibe.databaseController.createObject({ + await wabe.databaseController.createObject({ className: 'User', context, data: { name: 'Lucas' }, @@ -126,9 +126,9 @@ describe('Database', () => { }) it('should not computeObjects in runOnMultipleObjects if there is no hooks to execute on createObjects', async () => { - wibe.config.hooks = [] + wabe.config.hooks = [] - await wibe.databaseController.createObjects({ + await wabe.databaseController.createObjects({ className: 'User', context, data: [{ name: 'Lucas' }], @@ -139,9 +139,9 @@ describe('Database', () => { }) it('should not computeObject in runOnSingleObject if there is no hooks to execute on updateObject', async () => { - wibe.config.hooks = [] + wabe.config.hooks = [] - const { id } = await wibe.databaseController.createObject({ + const { id } = await wabe.databaseController.createObject({ className: 'User', context, data: { name: 'Lucas' }, @@ -150,7 +150,7 @@ describe('Database', () => { spyGetObject.mockClear() - await wibe.databaseController.updateObject({ + await wabe.databaseController.updateObject({ className: 'User', context, data: [{ name: 'Lucas' }], @@ -162,9 +162,9 @@ describe('Database', () => { }) it('should not computeObject in runOnMultipleObject if there is no hooks to execute on updateObjects', async () => { - wibe.config.hooks = [] + wabe.config.hooks = [] - const { id } = await wibe.databaseController.createObject({ + const { id } = await wabe.databaseController.createObject({ className: 'User', context, data: { name: 'Lucas' }, @@ -173,7 +173,7 @@ describe('Database', () => { spyGetObjects.mockClear() - await wibe.databaseController.updateObjects({ + await wabe.databaseController.updateObjects({ className: 'User', context, data: { name: 'Lucas' }, @@ -186,9 +186,9 @@ describe('Database', () => { }) it('should not computeObject in runOnSingleObject if there is no hooks to execute on updateObject', async () => { - wibe.config.hooks = [] + wabe.config.hooks = [] - const { id } = await wibe.databaseController.createObject({ + const { id } = await wabe.databaseController.createObject({ className: 'User', context, data: { name: 'Lucas' }, @@ -197,7 +197,7 @@ describe('Database', () => { spyGetObject.mockClear() - await wibe.databaseController.deleteObject({ + await wabe.databaseController.deleteObject({ className: 'User', context, fields: ['id'], @@ -208,9 +208,9 @@ describe('Database', () => { }) it('should not computeObject in runOnMultipleObject if there is no hooks to execute on updateObjects', async () => { - wibe.config.hooks = [] + wabe.config.hooks = [] - const { id } = await wibe.databaseController.createObject({ + const { id } = await wabe.databaseController.createObject({ className: 'User', context, data: { name: 'Lucas' }, @@ -219,7 +219,7 @@ describe('Database', () => { spyGetObjects.mockClear() - await wibe.databaseController.deleteObjects({ + await wabe.databaseController.deleteObjects({ className: 'User', context, fields: ['id'], @@ -230,7 +230,7 @@ describe('Database', () => { }) it('should call getObject adapter only 2 times (lower is better) for one read query (performance test) without mutation in hooks', async () => { - wibe.config.hooks = [ + wabe.config.hooks = [ { className: 'User', operationType: OperationType.AfterCreate, @@ -245,11 +245,11 @@ describe('Database', () => { }, ] const spyGetObjectAdapter = spyOn( - wibe.databaseController.adapter, + wabe.databaseController.adapter, 'getObject', ) - const res = await wibe.databaseController.createObject({ + const res = await wabe.databaseController.createObject({ className: 'User', context, data: { name: 'Lucas' }, @@ -258,7 +258,7 @@ describe('Database', () => { spyGetObjectAdapter.mockClear() - await wibe.databaseController.getObject({ + await wabe.databaseController.getObject({ className: 'User', context, fields: ['id'], @@ -269,7 +269,7 @@ describe('Database', () => { }) it('should get the good value in output of createObject after mutation on after hook', async () => { - wibe.config.hooks = [ + wabe.config.hooks = [ { className: 'User', operationType: OperationType.AfterCreate, @@ -283,7 +283,7 @@ describe('Database', () => { priority: 1, }, ] - const res = await context.wibeApp.databaseController.createObject({ + const res = await context.wabeApp.databaseController.createObject({ className: 'User', data: { name: 'Lucas', age: 20 }, context, @@ -296,7 +296,7 @@ describe('Database', () => { }) it('should get the good value in output of createObjects after mutation on after hook', async () => { - wibe.config.hooks = [ + wabe.config.hooks = [ { className: 'User', operationType: OperationType.AfterCreate, @@ -310,7 +310,7 @@ describe('Database', () => { priority: 1, }, ] - const res = await context.wibeApp.databaseController.createObjects({ + const res = await context.wabeApp.databaseController.createObjects({ className: 'User', data: [{ name: 'Lucas', age: 20 }], context, @@ -323,7 +323,7 @@ describe('Database', () => { }) it('should get the good value in output of updateObjects after mutation on after hook', async () => { - wibe.config.hooks = [ + wabe.config.hooks = [ { className: 'User', operationType: OperationType.AfterCreate, @@ -337,14 +337,14 @@ describe('Database', () => { priority: 1, }, ] - await context.wibeApp.databaseController.createObjects({ + await context.wabeApp.databaseController.createObjects({ className: 'Test2', data: [{ name: 'test', age: 20 }], context, fields: [], }) - const res = await context.wibeApp.databaseController.updateObjects({ + const res = await context.wabeApp.databaseController.updateObjects({ className: 'Test2', context, fields: ['name'], @@ -358,7 +358,7 @@ describe('Database', () => { }) it('should get the good value in output of updateObject after mutation on after hook', async () => { - wibe.config.hooks = [ + wabe.config.hooks = [ { className: 'User', operationType: OperationType.AfterCreate, @@ -372,14 +372,14 @@ describe('Database', () => { priority: 1, }, ] - const res = await context.wibeApp.databaseController.createObjects({ + const res = await context.wabeApp.databaseController.createObjects({ className: 'Test2', data: [{ name: 'test', age: 20 }], context, fields: ['id'], }) - const res2 = await context.wibeApp.databaseController.updateObject({ + const res2 = await context.wabeApp.databaseController.updateObject({ className: 'Test2', context, fields: ['name'], diff --git a/packages/wibe-server/src/database/index.ts b/packages/wabe-server/src/database/index.ts similarity index 100% rename from packages/wibe-server/src/database/index.ts rename to packages/wabe-server/src/database/index.ts diff --git a/packages/wabe-server/src/files/devAdapter.ts b/packages/wabe-server/src/files/devAdapter.ts new file mode 100644 index 00000000..9fa981c2 --- /dev/null +++ b/packages/wabe-server/src/files/devAdapter.ts @@ -0,0 +1,3 @@ +import type { WabeFileAdapter } from '.' + +export const fileDevAdapter: WabeFileAdapter = async (file: File) => file.name diff --git a/packages/wibe-server/src/files/hookUploadFile.ts b/packages/wabe-server/src/files/hookUploadFile.ts similarity index 78% rename from packages/wibe-server/src/files/hookUploadFile.ts rename to packages/wabe-server/src/files/hookUploadFile.ts index 689f7508..a52ea416 100644 --- a/packages/wibe-server/src/files/hookUploadFile.ts +++ b/packages/wabe-server/src/files/hookUploadFile.ts @@ -3,7 +3,7 @@ import type { HookObject } from '../hooks/HookObject' const handleFile = async (hookObject: HookObject) => { const newData = hookObject.getNewData() - const schema = hookObject.context.wibeApp.config.schema.classes.find( + const schema = hookObject.context.wabeApp.config.schema.classes.find( (currentClass) => currentClass.name === hookObject.className, ) @@ -13,10 +13,10 @@ const handleFile = async (hookObject: HookObject) => { Object.keys(newData).map(async (keyName) => { if (schema.fields[keyName].type !== 'File') return - if (hookObject.context.wibeApp.config.file?.adapter !== undefined) + if (hookObject.context.wabeApp.config.file?.adapter !== undefined) hookObject.upsertNewData( keyName, - await hookObject.context.wibeApp.config.file.adapter( + await hookObject.context.wabeApp.config.file.adapter( newData[keyName], ), ) diff --git a/packages/wibe-server/src/files/index.test.ts b/packages/wabe-server/src/files/index.test.ts similarity index 93% rename from packages/wibe-server/src/files/index.test.ts rename to packages/wabe-server/src/files/index.test.ts index bafdbf3a..69dbbeca 100644 --- a/packages/wibe-server/src/files/index.test.ts +++ b/packages/wabe-server/src/files/index.test.ts @@ -7,20 +7,20 @@ import { it, spyOn, } from 'bun:test' -import type { WibeApp } from '..' -import { type DevWibeAppTypes, closeTests, setupTests } from '../utils/helper' +import type { WabeApp } from '..' +import { type DevWabeAppTypes, closeTests, setupTests } from '../utils/helper' describe('File upload', () => { - let wibe: WibeApp + let wabe: WabeApp let port: number let spyFileDevAdapter: any beforeAll(async () => { const setup = await setupTests() - wibe = setup.wibe + wabe = setup.wabe port = setup.port - const fileAdapter = wibe.config.file + const fileAdapter = wabe.config.file if (!fileAdapter) throw new Error('File adapter is not correctly setup in setupTests') @@ -29,7 +29,7 @@ describe('File upload', () => { }) afterAll(async () => { - await closeTests(wibe) + await closeTests(wabe) }) beforeEach(() => { diff --git a/packages/wibe-server/src/files/index.ts b/packages/wabe-server/src/files/index.ts similarity index 73% rename from packages/wibe-server/src/files/index.ts rename to packages/wabe-server/src/files/index.ts index 782ea0e1..f21b63e0 100644 --- a/packages/wibe-server/src/files/index.ts +++ b/packages/wabe-server/src/files/index.ts @@ -3,11 +3,11 @@ * @param file: File * @returns The url of the uploaded file */ -export type WibeFileAdapter = (file: File) => Promise +export type WabeFileAdapter = (file: File) => Promise /** * The file config contains the adapter to use to upload file */ export interface FileConfig { - adapter: WibeFileAdapter + adapter: WabeFileAdapter } diff --git a/packages/wibe-server/src/graphql/GraphQLSchema.test.ts b/packages/wabe-server/src/graphql/GraphQLSchema.test.ts similarity index 94% rename from packages/wibe-server/src/graphql/GraphQLSchema.test.ts rename to packages/wabe-server/src/graphql/GraphQLSchema.test.ts index 08c4836b..b5862a9a 100644 --- a/packages/wibe-server/src/graphql/GraphQLSchema.test.ts +++ b/packages/wabe-server/src/graphql/GraphQLSchema.test.ts @@ -5,17 +5,17 @@ import { gql } from 'graphql-request' import { v4 as uuid } from 'uuid' import { DatabaseEnum } from '../database' import { Schema, type SchemaInterface } from '../schema' -import { WibeApp } from '../server' -import { type DevWibeAppTypes, getGraphqlClient } from '../utils/helper' -import { GraphQLSchema as WibeGraphQLSchema } from './GraphQLSchema' +import { WabeApp } from '../server' +import { type DevWabeAppTypes, getGraphqlClient } from '../utils/helper' +import { GraphQLSchema as WabeGraphQLSchema } from './GraphQLSchema' import { getTypeFromGraphQLSchema } from './parseGraphqlSchema' -const createWibeApp = async (schema: SchemaInterface) => { +const createWabeApp = async (schema: SchemaInterface) => { const databaseId = uuid() const port = await getPort() - const wibeApp = new WibeApp({ + const wabeApp = new WabeApp({ port, schema, rootKey: @@ -27,18 +27,18 @@ const createWibeApp = async (schema: SchemaInterface) => { }, }) - await wibeApp.start() + await wabeApp.start() const client = getGraphqlClient(port) - return { client, wibeApp, port } + return { client, wabeApp, port } } describe('GraphqlSchema', () => { let schema: GraphQLSchema beforeAll(() => { - const wibeSchema = new Schema({ + const wabeSchema = new Schema({ schema: { classes: [ { @@ -169,7 +169,7 @@ describe('GraphqlSchema', () => { }, } as any) - const graphqlSchema = new WibeGraphQLSchema(wibeSchema) + const graphqlSchema = new WabeGraphQLSchema(wabeSchema) const types = graphqlSchema.createSchema() @@ -187,7 +187,7 @@ describe('GraphqlSchema', () => { }) it('should use the searchUsers to search all testClasses for corresponding term', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -291,7 +291,7 @@ describe('GraphqlSchema', () => { expect(res5.testClasses.count).toEqual(1) - await wibeApp.close() + await wabeApp.close() }) it('should contain count elements in query multiple objects', async () => { @@ -305,7 +305,7 @@ describe('GraphqlSchema', () => { }) it('should count all elements corresponding to where object', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -356,11 +356,11 @@ describe('GraphqlSchema', () => { expect(res.testClasses.count).toEqual(1) - await wibeApp.close() + await wabeApp.close() }) it('should request an object with pointer in same class (issue #5)', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [], }) @@ -398,7 +398,7 @@ describe('GraphqlSchema', () => { password: expect.any(String), }) - await wibeApp.close() + await wabeApp.close() }) it('should support file type', async () => { @@ -464,7 +464,7 @@ describe('GraphqlSchema', () => { }) it('should support an array of object in graphql schema', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -504,11 +504,11 @@ describe('GraphqlSchema', () => { { name: 'test2' }, ]) - await wibeApp.close() + await wabeApp.close() }) it('should return an array in a query', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -541,11 +541,11 @@ describe('GraphqlSchema', () => { expect(res.testQuery).toEqual(['test']) - await wibeApp.close() + await wabeApp.close() }) it('should return an object in a query', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -586,11 +586,11 @@ describe('GraphqlSchema', () => { expect(res.testQuery.test).toEqual('test') - await wibeApp.close() + await wabeApp.close() }) it('should return an array in a mutation', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -623,11 +623,11 @@ describe('GraphqlSchema', () => { expect(res.testMutation).toEqual(['test']) - await wibeApp.close() + await wabeApp.close() }) it('should return an object in a mutation', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -668,11 +668,11 @@ describe('GraphqlSchema', () => { expect(res.testMutation.test).toEqual('test') - await wibeApp.close() + await wabeApp.close() }) it('should have a custom enum as value in type', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -736,7 +736,7 @@ describe('GraphqlSchema', () => { expect(resNotEqual.testClasses.edges.length).toBe(0) - await wibeApp.close() + await wabeApp.close() }) it('should have correct WhereInput object', () => { @@ -1048,7 +1048,7 @@ describe('GraphqlSchema', () => { }) it('should create mutation with sub input', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -1097,11 +1097,11 @@ describe('GraphqlSchema', () => { expect(request.customMutation).toBe(3) - await wibeApp.close() + await wabeApp.close() }) it('should create mutation with sub sub input', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -1161,11 +1161,11 @@ describe('GraphqlSchema', () => { expect(request.customMutation).toBe(3) - await wibeApp.close() + await wabeApp.close() }) it('should create custom mutation with sub object and correct input name', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -1237,11 +1237,11 @@ describe('GraphqlSchema', () => { expect(request2.customMutation).toBe(3) - await wibeApp.close() + await wabeApp.close() }) it('should create a sub object with the good type', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -1307,11 +1307,11 @@ describe('GraphqlSchema', () => { expect(request.testClasses.edges[0].node.field1.field2).toBe('test') expect(request.testClasses.edges[0].node.field1.field3).toBe(1) - await wibeApp.close() + await wabeApp.close() }) it('should create an object with a pointer (createAndLink)', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -1363,11 +1363,11 @@ describe('GraphqlSchema', () => { expect(res.createTestClass2.testClass2.name).toBe('name') expect(res.createTestClass2.testClass2.field2.field1).toBe('field1') - await wibeApp.close() + await wabeApp.close() }) it('should link an object to a pointer', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -1438,11 +1438,11 @@ describe('GraphqlSchema', () => { expect(res.createTestClass2.testClass2.name).toBe('name') expect(res.createTestClass2.testClass2.field2.field1).toBe('field1') - await wibeApp.close() + await wabeApp.close() }) it('should link a pointer on create multiple object', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -1500,11 +1500,11 @@ describe('GraphqlSchema', () => { expect(res.createTestClass2s.edges[0].node.name).toBe('name') expect(res.createTestClass2s.edges[0].node.field2.field1).toBe('field1') - await wibeApp.close() + await wabeApp.close() }) it('should filter an object (on query) with pointer field', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -1573,11 +1573,11 @@ describe('GraphqlSchema', () => { expect(queryRes.testClass2s.edges.length).toBe(1) expect(queryRes.testClass2s.edges[0].node.name).toBe('name') - await wibeApp.close() + await wabeApp.close() }) it('should filter an object (on updates) with pointer field', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -1649,11 +1649,11 @@ describe('GraphqlSchema', () => { expect(updateRes.updateTestClass2s.edges.length).toBe(1) expect(updateRes.updateTestClass2s.edges[0].node.name).toBe('name2') - await wibeApp.close() + await wabeApp.close() }) it('should filter an object (on deletes) with pointer field', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -1724,11 +1724,11 @@ describe('GraphqlSchema', () => { expect(deleteRes.deleteTestClass2s.edges.length).toBe(1) expect(deleteRes.deleteTestClass2s.edges[0].node.name).toBe('name') - await wibeApp.close() + await wabeApp.close() }) it('should create and link a pointer on update', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -1808,11 +1808,11 @@ describe('GraphqlSchema', () => { 'field1AfterUpdate', ) - await wibeApp.close() + await wabeApp.close() }) it('should link a pointer on update', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -1895,11 +1895,11 @@ describe('GraphqlSchema', () => { 'field1', ) - await wibeApp.close() + await wabeApp.close() }) it('should link a pointer on update multiple object', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -1976,11 +1976,11 @@ describe('GraphqlSchema', () => { resAfterUpdate.updateTestClass2s.edges[0].node.field2.field1, ).toBe('field1UpdateMultiple') - await wibeApp.close() + await wabeApp.close() }) it('should return pointer data on delete an element', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -2051,11 +2051,11 @@ describe('GraphqlSchema', () => { 'field1', ) - await wibeApp.close() + await wabeApp.close() }) it('should createAndAdd an object on a relation field (on create)', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -2110,11 +2110,11 @@ describe('GraphqlSchema', () => { res.createTestClass2.testClass2.field2.edges[0].node.field1, ).toBe('field1') - await wibeApp.close() + await wabeApp.close() }) it('should add an object on a relation field (on create)', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -2179,11 +2179,11 @@ describe('GraphqlSchema', () => { resAfterAdd.createTestClass2.testClass2.field2.edges[0].node.field1, ).toBe('field1') - await wibeApp.close() + await wabeApp.close() }) it('should createAndAdd an object on a relation field (on createMany)', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -2242,11 +2242,11 @@ describe('GraphqlSchema', () => { res.createTestClass2s.edges[0].node.field2.edges[0].node.field1, ).toBe('field1') - await wibeApp.close() + await wabeApp.close() }) it('should add an object on a relation field (on createMany)', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -2316,11 +2316,11 @@ describe('GraphqlSchema', () => { .field1, ).toBe('field1') - await wibeApp.close() + await wabeApp.close() }) it('should createAndAdd an object on a relation field (on update)', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -2388,11 +2388,11 @@ describe('GraphqlSchema', () => { .field1, ).toBe('field1') - await wibeApp.close() + await wabeApp.close() }) it('should add an object on a relation field (on update)', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -2470,11 +2470,11 @@ describe('GraphqlSchema', () => { .field1, ).toBe('field1') - await wibeApp.close() + await wabeApp.close() }) it('should remove an object on a relation field (on update)', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -2556,11 +2556,11 @@ describe('GraphqlSchema', () => { resAfterUpdate.updateTestClass2.testClass2.field2.edges.length, ).toEqual(0) - await wibeApp.close() + await wabeApp.close() }) it('should createAndAdd an object on a relation field (on updateMany)', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -2630,11 +2630,11 @@ describe('GraphqlSchema', () => { .field1, ).toBe('field1') - await wibeApp.close() + await wabeApp.close() }) it('should add an object on a relation field (on updateMany)', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -2714,11 +2714,11 @@ describe('GraphqlSchema', () => { .field1, ).toBe('field1') - await wibeApp.close() + await wabeApp.close() }) it('should remove an object on a relation field (on updateMany)', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -2802,11 +2802,11 @@ describe('GraphqlSchema', () => { resAfterUpdate.updateTestClass2s.edges[0].node.field2.edges.length, ).toBe(0) - await wibeApp.close() + await wabeApp.close() }) it('should remove an object on a relation field (on updateMany)', async () => { - const { client, wibeApp } = await createWibeApp({ + const { client, wabeApp } = await createWabeApp({ classes: [ { name: 'TestClass', @@ -2890,6 +2890,6 @@ describe('GraphqlSchema', () => { resAfterUpdate.updateTestClass2s.edges[0].node.field2.edges.length, ).toBe(0) - await wibeApp.close() + await wabeApp.close() }) }) diff --git a/packages/wibe-server/src/graphql/GraphQLSchema.ts b/packages/wabe-server/src/graphql/GraphQLSchema.ts similarity index 90% rename from packages/wibe-server/src/graphql/GraphQLSchema.ts rename to packages/wabe-server/src/graphql/GraphQLSchema.ts index 0d286637..c8e63e8d 100644 --- a/packages/wibe-server/src/graphql/GraphQLSchema.ts +++ b/packages/wabe-server/src/graphql/GraphQLSchema.ts @@ -11,8 +11,8 @@ import { GraphQLScalarType, GraphQLString, } from 'graphql' -import { pluralize } from 'wibe-pluralize' -import type { WibeAppTypes } from '..' +import { pluralize } from 'wabe-pluralize' +import type { WabeAppTypes } from '..' import type { ClassInterface, MutationResolver, @@ -20,7 +20,7 @@ import type { Schema, } from '../schema' import { firstLetterInLowerCase } from '../utils' -import type { DevWibeAppTypes } from '../utils/helper' +import type { DevWabeAppTypes } from '../utils/helper' import { GraphqlParser, type GraphqlParserFactory } from './parser' import { mutationToCreateMultipleObjects, @@ -47,7 +47,7 @@ type AllPossibleObject = export type AllObjects = Record> export class GraphQLSchema { - private schemas: Schema + private schemas: Schema private allObjects: AllObjects @@ -66,8 +66,8 @@ export class GraphQLSchema { const graphqlParser = GraphqlParser({ scalars, enums }) - classes.map((wibeClass) => - this.createCompleteObject(graphqlParser, wibeClass), + classes.map((wabeClass) => + this.createCompleteObject(graphqlParser, wabeClass), ) const queriesMutationAndObjects = classes.reduce( @@ -179,8 +179,8 @@ export class GraphQLSchema { createEnums() { return ( - this.schemas.schema.enums?.map((wibeEnum) => { - const enumValues = wibeEnum.values + this.schemas.schema.enums?.map((wabeEnum) => { + const enumValues = wabeEnum.values const values = Object.keys(enumValues).reduce( (acc, value) => { @@ -192,7 +192,7 @@ export class GraphQLSchema { ) return new GraphQLEnumType({ - ...wibeEnum, + ...wabeEnum, values, }) }) || [] @@ -200,13 +200,13 @@ export class GraphQLSchema { } createObject({ - wibeClass, + wabeClass, graphqlParser, }: { - wibeClass: ClassInterface + wabeClass: ClassInterface graphqlParser: GraphqlParserFactory }) { - const { name, fields, description } = wibeClass + const { name, fields, description } = wabeClass const nameWithoutSpace = name.replace(' ', '') @@ -228,13 +228,13 @@ export class GraphQLSchema { } createPointerInputObject({ - wibeClass, + wabeClass, inputCreateFields, }: { - wibeClass: ClassInterface + wabeClass: ClassInterface inputCreateFields: GraphQLInputObjectType }) { - const { name } = wibeClass + const { name } = wabeClass const nameWithoutSpace = name.replace(' ', '') @@ -249,13 +249,13 @@ export class GraphQLSchema { } createRelationInputObject({ - wibeClass, + wabeClass, inputCreateFields, }: { - wibeClass: ClassInterface + wabeClass: ClassInterface inputCreateFields: GraphQLInputObjectType }) { - const { name } = wibeClass + const { name } = wabeClass const nameWithoutSpace = name.replace(' ', '') @@ -277,13 +277,13 @@ export class GraphQLSchema { } createInputObject({ - wibeClass, + wabeClass, graphqlParser, }: { - wibeClass: ClassInterface + wabeClass: ClassInterface graphqlParser: GraphqlParserFactory }) { - const { name, fields, description } = wibeClass + const { name, fields, description } = wabeClass const nameWithoutSpace = name.replace(' ', '') @@ -303,13 +303,13 @@ export class GraphQLSchema { } createCreateInputObject({ - wibeClass, + wabeClass, graphqlParser, }: { - wibeClass: ClassInterface + wabeClass: ClassInterface graphqlParser: GraphqlParserFactory }) { - const { name, fields, description } = wibeClass + const { name, fields, description } = wabeClass const nameWithoutSpace = name.replace(' ', '') @@ -329,13 +329,13 @@ export class GraphQLSchema { } createUpdateInputObject({ - wibeClass, + wabeClass, graphqlParser, }: { - wibeClass: ClassInterface + wabeClass: ClassInterface graphqlParser: GraphqlParserFactory }) { - const { name, fields, description } = wibeClass + const { name, fields, description } = wabeClass const nameWithoutSpace = name.replace(' ', '') @@ -355,13 +355,13 @@ export class GraphQLSchema { } createWhereInputObject({ - wibeClass, + wabeClass, graphqlParser, }: { - wibeClass: ClassInterface + wabeClass: ClassInterface graphqlParser: GraphqlParserFactory }) { - const { name, fields, description } = wibeClass + const { name, fields, description } = wabeClass const nameWithoutSpace = name.replace(' ', '') @@ -395,20 +395,20 @@ export class GraphQLSchema { createConnectionObject({ object, - wibeClass, + wabeClass, }: { object: GraphQLObjectType - wibeClass: ClassInterface + wabeClass: ClassInterface }) { const edgeObject = new GraphQLObjectType({ - name: `${wibeClass.name}Edge`, + name: `${wabeClass.name}Edge`, fields: () => ({ node: { type: new GraphQLNonNull(object) }, }), }) const connectionObject = new GraphQLObjectType({ - name: `${wibeClass.name}Connection`, + name: `${wabeClass.name}Connection`, fields: () => ({ count: { type: GraphQLInt }, edges: { type: new GraphQLList(edgeObject) }, @@ -420,46 +420,46 @@ export class GraphQLSchema { createCompleteObject( graphqlParser: GraphqlParserFactory, - wibeClass: ClassInterface, + wabeClass: ClassInterface, ) { - const object = this.createObject({ graphqlParser, wibeClass }) + const object = this.createObject({ graphqlParser, wabeClass }) const connectionObject = this.createConnectionObject({ object, - wibeClass, + wabeClass, }) const inputObject = this.createInputObject({ graphqlParser, - wibeClass, + wabeClass, }) const createInputObject = this.createCreateInputObject({ graphqlParser, - wibeClass, + wabeClass, }) const pointerInputObject = this.createPointerInputObject({ inputCreateFields: createInputObject, - wibeClass, + wabeClass, }) const relationInputObject = this.createRelationInputObject({ inputCreateFields: createInputObject, - wibeClass, + wabeClass, }) const updateInputObject = this.createUpdateInputObject({ graphqlParser, - wibeClass, + wabeClass, }) const whereInputObject = this.createWhereInputObject({ graphqlParser, - wibeClass, + wabeClass, }) - this.allObjects[wibeClass.name] = { + this.allObjects[wabeClass.name] = { connectionObject, createInputObject, updateInputObject, @@ -475,7 +475,7 @@ export class GraphQLSchema { resolvers, graphqlParser, }: { - resolvers: Record> + resolvers: Record> graphqlParser: GraphqlParserFactory }) { return Object.keys(resolvers).reduce( @@ -552,7 +552,7 @@ export class GraphQLSchema { resolvers, graphqlParser, }: { - resolvers: Record> + resolvers: Record> graphqlParser: GraphqlParserFactory }) { return Object.keys(resolvers).reduce( @@ -755,7 +755,7 @@ export class GraphQLSchema { args, ctx, info, - className as keyof WibeAppTypes['types'], + className as keyof WabeAppTypes['types'], ), }, [`create${pluralize(className)}`]: { @@ -768,7 +768,7 @@ export class GraphQLSchema { args, ctx, info, - className as keyof WibeAppTypes['types'], + className as keyof WabeAppTypes['types'], ), }, [`update${className}`]: { @@ -781,7 +781,7 @@ export class GraphQLSchema { args, ctx, info, - className as keyof WibeAppTypes['types'], + className as keyof WabeAppTypes['types'], ), }, [`update${pluralize(className)}`]: { @@ -794,7 +794,7 @@ export class GraphQLSchema { args, ctx, info, - className as keyof WibeAppTypes['types'], + className as keyof WabeAppTypes['types'], ), }, [`delete${className}`]: { @@ -811,7 +811,7 @@ export class GraphQLSchema { args, ctx, info, - className as keyof WibeAppTypes['types'], + className as keyof WabeAppTypes['types'], ), }, [`delete${pluralize(className)}`]: { @@ -824,7 +824,7 @@ export class GraphQLSchema { args, ctx, info, - className as keyof WibeAppTypes['types'], + className as keyof WabeAppTypes['types'], ), }, } as Record> diff --git a/packages/wibe-server/src/graphql/index.ts b/packages/wabe-server/src/graphql/index.ts similarity index 100% rename from packages/wibe-server/src/graphql/index.ts rename to packages/wabe-server/src/graphql/index.ts diff --git a/packages/wibe-server/src/graphql/parseGraphqlSchema.ts b/packages/wabe-server/src/graphql/parseGraphqlSchema.ts similarity index 100% rename from packages/wibe-server/src/graphql/parseGraphqlSchema.ts rename to packages/wabe-server/src/graphql/parseGraphqlSchema.ts diff --git a/packages/wibe-server/src/graphql/parser.test.ts b/packages/wabe-server/src/graphql/parser.test.ts similarity index 96% rename from packages/wibe-server/src/graphql/parser.test.ts rename to packages/wabe-server/src/graphql/parser.test.ts index d9649f87..934a69ae 100644 --- a/packages/wibe-server/src/graphql/parser.test.ts +++ b/packages/wabe-server/src/graphql/parser.test.ts @@ -64,8 +64,8 @@ const deepCompareGraphQLObjects = ( return true } -describe('WibeGraphqlParser', () => { - it('should parse a wibe object', () => { +describe('WabeGraphqlParser', () => { + it('should parse a wabe object', () => { const graphqlParser = GraphqlParser({ enums: [], scalars: [], @@ -74,7 +74,7 @@ describe('WibeGraphqlParser', () => { graphqlObjectType: {} as any, schemaFields: {} as any, allObjects: {} as any, - })._parseWibeObject({ + })._parseWabeObject({ description: 'A simple object', required: true, objectToParse: { @@ -103,7 +103,7 @@ describe('WibeGraphqlParser', () => { ) }) - it('should parse a recursive wibe object', () => { + it('should parse a recursive wabe object', () => { const graphqlParser = GraphqlParser({ enums: [], scalars: [], @@ -113,7 +113,7 @@ describe('WibeGraphqlParser', () => { graphqlObjectType: {} as any, schemaFields: {} as any, allObjects: {} as any, - })._parseWibeObject({ + })._parseWabeObject({ description: 'A recursive object', required: true, objectToParse: { diff --git a/packages/wibe-server/src/graphql/parser.ts b/packages/wabe-server/src/graphql/parser.ts similarity index 86% rename from packages/wibe-server/src/graphql/parser.ts rename to packages/wabe-server/src/graphql/parser.ts index 1be63293..3c98fdd1 100644 --- a/packages/wibe-server/src/graphql/parser.ts +++ b/packages/wabe-server/src/graphql/parser.ts @@ -26,9 +26,9 @@ import { IntWhereInput, StringWhereInput, } from '../graphql' -import type { ClassInterface, SchemaFields, WibePrimaryTypes } from '../schema' -import type { WibeAppTypes } from '../server' -import type { DevWibeAppTypes } from '../utils/helper' +import type { ClassInterface, SchemaFields, WabePrimaryTypes } from '../schema' +import type { WabeAppTypes } from '../server' +import type { DevWabeAppTypes } from '../utils/helper' type GraphqlObjectType = | 'Object' @@ -46,7 +46,7 @@ type ParseObjectOptions = { type ParseObjectCallback = (options: ParseObjectOptions) => any -export const templateScalarType: Record = { +export const templateScalarType: Record = { String: GraphQLString, Int: GraphQLInt, Float: GraphQLFloat, @@ -57,7 +57,7 @@ export const templateScalarType: Record = { } export const templateWhereInput: Record< - WibePrimaryTypes | 'Array', + WabePrimaryTypes | 'Array', GraphQLInputObjectType > = { String: StringWhereInput, @@ -73,7 +73,7 @@ export const templateWhereInput: Record< interface GraphqlParserFactoryOptions { graphqlObjectType: GraphqlObjectType allObjects: AllObjects - schemaFields: SchemaFields + schemaFields: SchemaFields } interface GraphqlParserConstructorOptions { @@ -82,13 +82,13 @@ interface GraphqlParserConstructorOptions { } export type GraphqlParserFactory = (options: GraphqlParserFactoryOptions) => { - _parseWibeObject(options: ParseObjectOptions): any - _parseWibeWhereInputObject(options: ParseObjectOptions): any - _parseWibeInputObject(options: ParseObjectOptions): any - _parseWibeUpdateInputObject(options: ParseObjectOptions): any + _parseWabeObject(options: ParseObjectOptions): any + _parseWabeWhereInputObject(options: ParseObjectOptions): any + _parseWabeInputObject(options: ParseObjectOptions): any + _parseWabeUpdateInputObject(options: ParseObjectOptions): any getGraphqlType(options: { - type: WibePrimaryTypes | 'Array' - typeValue?: WibePrimaryTypes + type: WabePrimaryTypes | 'Array' + typeValue?: WabePrimaryTypes isWhereType?: boolean }): any getGraphqlFields(nameOfTheObject: string): any @@ -105,7 +105,7 @@ export const GraphqlParser: GraphqlParserConstructor = schemaFields, allObjects, }: GraphqlParserFactoryOptions) => { - // Get graphql fields from a wibe object + // Get graphql fields from a wabe object const _getGraphqlFieldsFromAnObject = ({ objectToParse, callBackForObjectType, @@ -113,7 +113,7 @@ export const GraphqlParser: GraphqlParserConstructor = isWhereType = false, nameOfTheObject, }: { - objectToParse: ClassInterface + objectToParse: ClassInterface forceRequiredToFalse?: boolean isWhereType?: boolean callBackForObjectType: ParseObjectCallback @@ -166,7 +166,7 @@ export const GraphqlParser: GraphqlParserConstructor = const graphqlType = getGraphqlType({ ...currentField, // We never come here, complicated to good type this - type: currentField.type as WibePrimaryTypes, + type: currentField.type as WabePrimaryTypes, isWhereType, }) @@ -188,7 +188,7 @@ export const GraphqlParser: GraphqlParserConstructor = // ------------------ Parsers ------------------ // Parse simple object - const _parseWibeObject = ({ + const _parseWabeObject = ({ required, description, objectToParse, @@ -196,7 +196,7 @@ export const GraphqlParser: GraphqlParserConstructor = }: ParseObjectOptions) => { const graphqlFields = _getGraphqlFieldsFromAnObject({ objectToParse, - callBackForObjectType: _parseWibeObject, + callBackForObjectType: _parseWabeObject, nameOfTheObject, }) @@ -210,7 +210,7 @@ export const GraphqlParser: GraphqlParserConstructor = } // Parse input object - const _parseWibeInputObject = ({ + const _parseWabeInputObject = ({ required, description, objectToParse, @@ -218,7 +218,7 @@ export const GraphqlParser: GraphqlParserConstructor = }: ParseObjectOptions) => { const graphqlFields = _getGraphqlFieldsFromAnObject({ objectToParse, - callBackForObjectType: _parseWibeInputObject, + callBackForObjectType: _parseWabeInputObject, nameOfTheObject, }) @@ -232,7 +232,7 @@ export const GraphqlParser: GraphqlParserConstructor = } // Parse create input object - const _parseWibeCreateInputObject = ({ + const _parseWabeCreateInputObject = ({ required, description, objectToParse, @@ -240,7 +240,7 @@ export const GraphqlParser: GraphqlParserConstructor = }: ParseObjectOptions) => { const graphqlFields = _getGraphqlFieldsFromAnObject({ objectToParse, - callBackForObjectType: _parseWibeCreateInputObject, + callBackForObjectType: _parseWabeCreateInputObject, forceRequiredToFalse: true, nameOfTheObject, }) @@ -255,7 +255,7 @@ export const GraphqlParser: GraphqlParserConstructor = } // Parse update input object - const _parseWibeUpdateInputObject = ({ + const _parseWabeUpdateInputObject = ({ required, description, objectToParse, @@ -263,7 +263,7 @@ export const GraphqlParser: GraphqlParserConstructor = }: ParseObjectOptions) => { const graphqlFields = _getGraphqlFieldsFromAnObject({ objectToParse, - callBackForObjectType: _parseWibeUpdateInputObject, + callBackForObjectType: _parseWabeUpdateInputObject, forceRequiredToFalse: true, nameOfTheObject, }) @@ -278,7 +278,7 @@ export const GraphqlParser: GraphqlParserConstructor = } // Parse where input object - const _parseWibeWhereInputObject = ({ + const _parseWabeWhereInputObject = ({ required, description, objectToParse, @@ -286,7 +286,7 @@ export const GraphqlParser: GraphqlParserConstructor = }: ParseObjectOptions) => { const graphqlFields = _getGraphqlFieldsFromAnObject({ objectToParse, - callBackForObjectType: _parseWibeWhereInputObject, + callBackForObjectType: _parseWabeWhereInputObject, forceRequiredToFalse: true, isWhereType: true, nameOfTheObject, @@ -321,27 +321,27 @@ export const GraphqlParser: GraphqlParserConstructor = } > = { Object: { - callback: _parseWibeObject, + callback: _parseWabeObject, isWhereType: false, forceRequiredToFalse: false, }, InputObject: { - callback: _parseWibeInputObject, + callback: _parseWabeInputObject, isWhereType: false, forceRequiredToFalse: false, }, CreateFieldsInput: { - callback: _parseWibeCreateInputObject, + callback: _parseWabeCreateInputObject, isWhereType: false, forceRequiredToFalse: true, }, UpdateFieldsInput: { - callback: _parseWibeUpdateInputObject, + callback: _parseWabeUpdateInputObject, isWhereType: false, forceRequiredToFalse: true, }, WhereInputObject: { - callback: _parseWibeWhereInputObject, + callback: _parseWabeWhereInputObject, isWhereType: true, forceRequiredToFalse: true, }, @@ -355,11 +355,11 @@ export const GraphqlParser: GraphqlParserConstructor = isWhereType = false, }: { type: - | WibePrimaryTypes + | WabePrimaryTypes | 'Array' - | WibeAppTypes['enums'] - | WibeAppTypes['scalars'] - typeValue?: WibePrimaryTypes + | WabeAppTypes['enums'] + | WabeAppTypes['scalars'] + typeValue?: WabePrimaryTypes requiredValue?: boolean isWhereType?: boolean }) => { @@ -371,7 +371,7 @@ export const GraphqlParser: GraphqlParserConstructor = if (!Object.keys(templateWhereInput).includes(type)) return AnyWhereInput - return templateWhereInput[type as WibePrimaryTypes] + return templateWhereInput[type as WabePrimaryTypes] } if (scalarExist) return scalarExist @@ -394,7 +394,7 @@ export const GraphqlParser: GraphqlParserConstructor = return graphqlType } - // Get Graphql object from a schema fields passed in WibeGraphqlParser + // Get Graphql object from a schema fields passed in WabeGraphqlParser const getGraphqlFields = (nameOfTheObject: string) => { const { callback, forceRequiredToFalse, isWhereType } = _graphqlObjectFactory[graphqlObjectType] @@ -510,9 +510,9 @@ export const GraphqlParser: GraphqlParserConstructor = return { getGraphqlType, getGraphqlFields, - _parseWibeObject, - _parseWibeInputObject, - _parseWibeUpdateInputObject, - _parseWibeWhereInputObject, + _parseWabeObject, + _parseWabeInputObject, + _parseWabeUpdateInputObject, + _parseWabeWhereInputObject, } } diff --git a/packages/wibe-server/src/graphql/pointerAndRelationFunction.ts b/packages/wabe-server/src/graphql/pointerAndRelationFunction.ts similarity index 82% rename from packages/wibe-server/src/graphql/pointerAndRelationFunction.ts rename to packages/wabe-server/src/graphql/pointerAndRelationFunction.ts index 3f17faea..0ed1b053 100644 --- a/packages/wibe-server/src/graphql/pointerAndRelationFunction.ts +++ b/packages/wabe-server/src/graphql/pointerAndRelationFunction.ts @@ -1,5 +1,5 @@ import { getClassFromClassName } from '../utils' -import type { WibeContext } from '../server/interface' +import type { WabeContext } from '../server/interface' type CreateAndLink = any type Link = string @@ -29,15 +29,15 @@ export const createAndLink = async ({ }: { createAndLink: CreateAndLink fieldName: string - context: WibeContext + context: WabeContext className: string }) => { const classInSchema = getClassFromClassName( className, - context.wibeApp.config, + context.wabeApp.config, ) - const { id } = await context.wibeApp.databaseController.createObject({ + const { id } = await context.wabeApp.databaseController.createObject({ // @ts-expect-error className: classInSchema.fields[fieldName].class, data: createAndLink, @@ -56,15 +56,15 @@ export const createAndAdd = async ({ }: { createAndAdd: CreateAndAdd fieldName: string - context: WibeContext + context: WabeContext className: string }) => { const classInSchema = getClassFromClassName( className, - context.wibeApp.config, + context.wabeApp.config, ) - const result = await context.wibeApp.databaseController.createObjects({ + const result = await context.wabeApp.databaseController.createObjects({ // @ts-expect-error className: classInSchema.fields[fieldName].class, data: createAndAdd, @@ -86,7 +86,7 @@ export const add = async ({ }: { add: Add fieldName: string - context: WibeContext + context: WabeContext typeOfExecution: TypeOfExecution id?: string className: string @@ -96,13 +96,13 @@ export const add = async ({ const classInSchema = getClassFromClassName( className, - context.wibeApp.config, + context.wabeApp.config, ) const fieldInClass = classInSchema.fields[fieldName] if (typeOfExecution === 'update' && id) { - const currentValue = await context.wibeApp.databaseController.getObject( + const currentValue = await context.wabeApp.databaseController.getObject( { className, id, @@ -118,7 +118,7 @@ export const add = async ({ // So we doesn't update the field for updateMany if (typeOfExecution === 'updateMany' && where) { const allObjectsMatchedWithWhere = - await context.wibeApp.databaseController.getObjects({ + await context.wabeApp.databaseController.getObjects({ // @ts-expect-error className: fieldInClass.class, where, @@ -130,7 +130,7 @@ export const add = async ({ allObjectsMatchedWithWhere.map(async (object: any) => { const currentValue = object[fieldName] - return context.wibeApp.databaseController.updateObject({ + return context.wabeApp.databaseController.updateObject({ // @ts-expect-error className: classInSchema.fields[fieldName].class, id: object.id, @@ -156,7 +156,7 @@ export const remove = async ({ }: { remove: Remove fieldName: string - context: WibeContext + context: WabeContext typeOfExecution: TypeOfExecution id?: string className: string @@ -165,7 +165,7 @@ export const remove = async ({ if (typeOfExecution === 'create') return [] if (typeOfExecution === 'update' && id) { - const currentValue = await context.wibeApp.databaseController.getObject( + const currentValue = await context.wabeApp.databaseController.getObject( { className, id, @@ -183,7 +183,7 @@ export const remove = async ({ if (typeOfExecution === 'updateMany' && where) { const allObjectsMatchedWithWhere = - await context.wibeApp.databaseController.getObjects({ + await context.wabeApp.databaseController.getObjects({ className, where, fields: ['id'], @@ -194,7 +194,7 @@ export const remove = async ({ allObjectsMatchedWithWhere.map(async (object: any) => { const olderValues = object[fieldName]?.[fieldName] || [] - return context.wibeApp.databaseController.updateObject({ + return context.wabeApp.databaseController.updateObject({ className, id: object.id, data: { diff --git a/packages/wibe-server/src/graphql/resolvers.test.ts b/packages/wabe-server/src/graphql/resolvers.test.ts similarity index 99% rename from packages/wibe-server/src/graphql/resolvers.test.ts rename to packages/wabe-server/src/graphql/resolvers.test.ts index 7ac1b796..2a5d84a0 100644 --- a/packages/wibe-server/src/graphql/resolvers.test.ts +++ b/packages/wabe-server/src/graphql/resolvers.test.ts @@ -51,7 +51,7 @@ describe('Resolver', () => { } const context = { - wibeApp: { + wabeApp: { databaseController, config, }, diff --git a/packages/wibe-server/src/graphql/resolvers.ts b/packages/wabe-server/src/graphql/resolvers.ts similarity index 83% rename from packages/wibe-server/src/graphql/resolvers.ts rename to packages/wabe-server/src/graphql/resolvers.ts index 1a5016e4..fbd2ee2d 100644 --- a/packages/wibe-server/src/graphql/resolvers.ts +++ b/packages/wabe-server/src/graphql/resolvers.ts @@ -1,6 +1,6 @@ import type { GraphQLResolveInfo, SelectionSetNode } from 'graphql' -import type { WibeAppTypes } from '..' -import type { WibeContext } from '../server/interface' +import type { WabeAppTypes } from '..' +import type { WabeContext } from '../server/interface' import { firstLetterInLowerCase, tokenize } from '../utils' import { type InputFields, @@ -69,7 +69,7 @@ export const executeRelationOnFields = async ({ }: { className: string fields: InputFields - context: WibeContext + context: WabeContext id?: string where?: any typeOfExecution?: TypeOfExecution @@ -133,13 +133,13 @@ export const executeRelationOnFields = async ({ export const queryForOneObject = ( _: any, { id }: any, - context: WibeContext, + context: WabeContext, info: GraphQLResolveInfo, - className: keyof WibeAppTypes['types'], + className: keyof WabeAppTypes['types'], ) => { const fields = getFieldsFromInfo(info, className) - return context.wibeApp.databaseController.getObject({ + return context.wabeApp.databaseController.getObject({ className, id, fields, @@ -150,13 +150,13 @@ export const queryForOneObject = ( export const queryForMultipleObject = async ( _: any, { where, offset, first }: any, - context: WibeContext, + context: WabeContext, info: GraphQLResolveInfo, - className: keyof WibeAppTypes['types'], + className: keyof WabeAppTypes['types'], ) => { const fields = getFieldsFromInfo(info, className) - const objects = await context.wibeApp.databaseController.getObjects({ + const objects = await context.wabeApp.databaseController.getObjects({ className, where, fields, @@ -167,7 +167,7 @@ export const queryForMultipleObject = async ( return { count: fields.includes('count') - ? await context.wibeApp.databaseController.count({ + ? await context.wabeApp.databaseController.count({ className, where, context, @@ -182,9 +182,9 @@ export const queryForMultipleObject = async ( export const mutationToCreateObject = async ( _: any, args: any, - context: WibeContext, + context: WabeContext, info: GraphQLResolveInfo, - className: keyof WibeAppTypes['types'], + className: keyof WabeAppTypes['types'], ) => { const fields = getFieldsFromInfo(info, className) @@ -196,7 +196,7 @@ export const mutationToCreateObject = async ( return { [firstLetterInLowerCase(className)]: - await context.wibeApp.databaseController.createObject({ + await context.wabeApp.databaseController.createObject({ className, data: updatedFieldsToCreate, fields, @@ -208,9 +208,9 @@ export const mutationToCreateObject = async ( export const mutationToCreateMultipleObjects = async ( _: any, args: any, - context: WibeContext, + context: WabeContext, info: GraphQLResolveInfo, - className: keyof WibeAppTypes['types'], + className: keyof WabeAppTypes['types'], ) => { const fields = getFieldsFromInfo(info, className) const inputFields = args.input?.fields as Array @@ -225,7 +225,7 @@ export const mutationToCreateMultipleObjects = async ( ), ) - const objects = await context.wibeApp.databaseController.createObjects({ + const objects = await context.wabeApp.databaseController.createObjects({ className, data: updatedFieldsToCreate, fields, @@ -242,9 +242,9 @@ export const mutationToCreateMultipleObjects = async ( export const mutationToUpdateObject = async ( _: any, args: any, - context: WibeContext, + context: WabeContext, info: GraphQLResolveInfo, - className: keyof WibeAppTypes['types'], + className: keyof WabeAppTypes['types'], ) => { const fields = getFieldsFromInfo(info, className) @@ -258,7 +258,7 @@ export const mutationToUpdateObject = async ( return { [firstLetterInLowerCase(className)]: - await context.wibeApp.databaseController.updateObject({ + await context.wabeApp.databaseController.updateObject({ className, id: args.input?.id, data: updatedFields, @@ -271,9 +271,9 @@ export const mutationToUpdateObject = async ( export const mutationToUpdateMultipleObjects = async ( _: any, args: any, - context: WibeContext, + context: WabeContext, info: GraphQLResolveInfo, - className: keyof WibeAppTypes['types'], + className: keyof WabeAppTypes['types'], ) => { const fields = getFieldsFromInfo(info, className) @@ -285,7 +285,7 @@ export const mutationToUpdateMultipleObjects = async ( where: args.input?.where, }) - const objects = await context.wibeApp.databaseController.updateObjects({ + const objects = await context.wabeApp.databaseController.updateObjects({ className, where: args.input?.where, data: updatedFields, @@ -303,15 +303,15 @@ export const mutationToUpdateMultipleObjects = async ( export const mutationToDeleteObject = async ( _: any, args: any, - context: WibeContext, + context: WabeContext, info: GraphQLResolveInfo, - className: keyof WibeAppTypes['types'], + className: keyof WabeAppTypes['types'], ) => { const fields = getFieldsFromInfo(info, className) return { [firstLetterInLowerCase(className)]: - await context.wibeApp.databaseController.deleteObject({ + await context.wabeApp.databaseController.deleteObject({ className, id: args.input?.id, fields, @@ -323,13 +323,13 @@ export const mutationToDeleteObject = async ( export const mutationToDeleteMultipleObjects = async ( _: any, args: any, - context: WibeContext, + context: WabeContext, info: GraphQLResolveInfo, - className: keyof WibeAppTypes['types'], + className: keyof WabeAppTypes['types'], ) => { const fields = getFieldsFromInfo(info, className) - const objects = await context.wibeApp.databaseController.deleteObjects({ + const objects = await context.wabeApp.databaseController.deleteObjects({ className, where: args.input?.where, fields, diff --git a/packages/wibe-server/src/graphql/tests/aggregation.test.ts b/packages/wabe-server/src/graphql/tests/aggregation.test.ts similarity index 99% rename from packages/wibe-server/src/graphql/tests/aggregation.test.ts rename to packages/wabe-server/src/graphql/tests/aggregation.test.ts index 3cb4a312..de7bb240 100644 --- a/packages/wibe-server/src/graphql/tests/aggregation.test.ts +++ b/packages/wabe-server/src/graphql/tests/aggregation.test.ts @@ -1,8 +1,8 @@ import { beforeAll, afterAll, describe, it, expect } from 'bun:test' import { type GraphQLClient, gql } from 'graphql-request' -import type { WibeApp } from '../../server' +import type { WabeApp } from '../../server' import { - type DevWibeAppTypes, + type DevWabeAppTypes, closeTests, getGraphqlClient, setupTests, @@ -42,7 +42,7 @@ const graphql = { } describe('GraphQL : aggregation', () => { - let wibe: WibeApp + let wabe: WabeApp let port: number let client: GraphQLClient @@ -50,7 +50,7 @@ describe('GraphQL : aggregation', () => { beforeAll(async () => { const setup = await setupTests() - wibe = setup.wibe + wabe = setup.wabe port = setup.port client = getGraphqlClient(port) @@ -81,7 +81,7 @@ describe('GraphQL : aggregation', () => { }) afterAll(async () => { - await closeTests(wibe) + await closeTests(wabe) }) it("should support Array's aggregation", async () => { diff --git a/packages/wibe-server/src/graphql/tests/e2e.test.ts b/packages/wabe-server/src/graphql/tests/e2e.test.ts similarity index 98% rename from packages/wibe-server/src/graphql/tests/e2e.test.ts rename to packages/wabe-server/src/graphql/tests/e2e.test.ts index c99cc0a5..dfc5b563 100644 --- a/packages/wibe-server/src/graphql/tests/e2e.test.ts +++ b/packages/wabe-server/src/graphql/tests/e2e.test.ts @@ -7,9 +7,9 @@ import { expect, it, } from 'bun:test' -import type { WibeApp } from '../../server' +import type { WabeApp } from '../../server' import { - type DevWibeAppTypes, + type DevWabeAppTypes, closeTests, getGraphqlClient, setupTests, @@ -28,19 +28,19 @@ const cleanUsers = async (client: GraphQLClient) => { } describe('GraphQL : E2E', () => { - let wibe: WibeApp + let wabe: WabeApp let port: number let client: GraphQLClient beforeAll(async () => { const setup = await setupTests() - wibe = setup.wibe + wabe = setup.wabe port = setup.port client = getGraphqlClient(port) }) afterAll(async () => { - await closeTests(wibe) + await closeTests(wabe) }) beforeEach(async () => { diff --git a/packages/wibe-server/src/graphql/tests/scalars.test.ts b/packages/wabe-server/src/graphql/tests/scalars.test.ts similarity index 97% rename from packages/wibe-server/src/graphql/tests/scalars.test.ts rename to packages/wabe-server/src/graphql/tests/scalars.test.ts index 16c289e5..531f136d 100644 --- a/packages/wibe-server/src/graphql/tests/scalars.test.ts +++ b/packages/wabe-server/src/graphql/tests/scalars.test.ts @@ -1,15 +1,15 @@ import { afterAll, beforeAll, describe, expect, it } from 'bun:test' -import type { WibeApp } from '../../server' +import type { WabeApp } from '../../server' import { type GraphQLClient, gql } from 'graphql-request' import { - type DevWibeAppTypes, + type DevWabeAppTypes, closeTests, getGraphqlClient, setupTests, } from '../../utils/helper' describe('GraphQL : Scalars', () => { - let wibe: WibeApp + let wabe: WabeApp let port: number let client: GraphQLClient @@ -17,13 +17,13 @@ describe('GraphQL : Scalars', () => { beforeAll(async () => { const setup = await setupTests() - wibe = setup.wibe + wabe = setup.wabe port = setup.port client = getGraphqlClient(port) }) afterAll(async () => { - await closeTests(wibe) + await closeTests(wabe) }) describe('Date', () => { diff --git a/packages/wibe-server/src/graphql/types.ts b/packages/wabe-server/src/graphql/types.ts similarity index 100% rename from packages/wibe-server/src/graphql/types.ts rename to packages/wabe-server/src/graphql/types.ts diff --git a/packages/wibe-server/src/hooks/HookObject.test.ts b/packages/wabe-server/src/hooks/HookObject.test.ts similarity index 93% rename from packages/wibe-server/src/hooks/HookObject.test.ts rename to packages/wabe-server/src/hooks/HookObject.test.ts index e95f72ee..7921f6d3 100644 --- a/packages/wibe-server/src/hooks/HookObject.test.ts +++ b/packages/wabe-server/src/hooks/HookObject.test.ts @@ -1,13 +1,13 @@ import { describe, expect, it } from 'bun:test' import { HookObject } from './HookObject' import { OperationType } from '.' -import type { DevWibeAppTypes } from '../utils/helper' +import type { DevWabeAppTypes } from '../utils/helper' describe('HookObject', () => { it('should return correctly value depends on the update state of the field', () => { const userData = { name: 'John Doe' } - const hookObject = new HookObject({ + const hookObject = new HookObject({ className: 'User', newData: userData, context: {} as any, diff --git a/packages/wibe-server/src/hooks/HookObject.ts b/packages/wabe-server/src/hooks/HookObject.ts similarity index 67% rename from packages/wibe-server/src/hooks/HookObject.ts rename to packages/wabe-server/src/hooks/HookObject.ts index d4d51d12..0831b8eb 100644 --- a/packages/wibe-server/src/hooks/HookObject.ts +++ b/packages/wabe-server/src/hooks/HookObject.ts @@ -1,14 +1,14 @@ import type { OperationType } from '.' import type { MutationData } from '../database' -import type { WibeAppTypes } from '../server' -import type { WibeContext } from '../server/interface' +import type { WabeAppTypes } from '../server' +import type { WabeContext } from '../server/interface' -export class HookObject { +export class HookObject { public className: string private newData: MutationData | undefined private operationType: OperationType - public context: WibeContext - public object: Record + public context: WabeContext + public object: Record constructor({ newData, @@ -20,8 +20,8 @@ export class HookObject { className: K newData?: MutationData operationType: OperationType - context: WibeContext - object: Record + context: WabeContext + object: Record }) { this.newData = newData // We need to cast the className to use it in comparaison @@ -36,11 +36,11 @@ export class HookObject { return this.context.user } - isFieldUpdate(field: keyof WibeAppTypes['types'][T]) { + isFieldUpdate(field: keyof WabeAppTypes['types'][T]) { return this.newData && !!this.newData[field] } - upsertNewData(field: keyof WibeAppTypes['types'][T], value: any) { + upsertNewData(field: keyof WabeAppTypes['types'][T], value: any) { if (!this.newData) return if (!this.operationType.includes('before')) diff --git a/packages/wibe-server/src/hooks/authentication.test.ts b/packages/wabe-server/src/hooks/authentication.test.ts similarity index 98% rename from packages/wibe-server/src/hooks/authentication.test.ts rename to packages/wabe-server/src/hooks/authentication.test.ts index bfab8591..a92152d4 100644 --- a/packages/wibe-server/src/hooks/authentication.test.ts +++ b/packages/wabe-server/src/hooks/authentication.test.ts @@ -34,7 +34,7 @@ describe('Hooks authentication', () => { className: 'User', context: { isRoot: true, - wibeApp: { + wabeApp: { config: { authentication: { customAuthenticationMethods, @@ -72,7 +72,7 @@ describe('Hooks authentication', () => { className: 'User', context: { isRoot: true, - wibeApp: { + wabeApp: { config: { authentication: { customAuthenticationMethods, diff --git a/packages/wibe-server/src/hooks/authentication.ts b/packages/wabe-server/src/hooks/authentication.ts similarity index 100% rename from packages/wibe-server/src/hooks/authentication.ts rename to packages/wabe-server/src/hooks/authentication.ts diff --git a/packages/wibe-server/src/hooks/defaultFields.test.ts b/packages/wabe-server/src/hooks/defaultFields.test.ts similarity index 91% rename from packages/wibe-server/src/hooks/defaultFields.test.ts rename to packages/wabe-server/src/hooks/defaultFields.test.ts index 07efc069..8c072014 100644 --- a/packages/wibe-server/src/hooks/defaultFields.test.ts +++ b/packages/wabe-server/src/hooks/defaultFields.test.ts @@ -6,14 +6,14 @@ import { } from './defaultFields' import { HookObject } from './HookObject' import { OperationType } from '.' -import type { DevWibeAppTypes } from '../utils/helper' +import type { DevWabeAppTypes } from '../utils/helper' describe('Default fields', () => { const now = new Date() describe('CreatedAt and UpdatedAt', () => { it('should add createdAt and updatedAt value on insert operation type', async () => { - const hookObject = new HookObject({ + const hookObject = new HookObject({ className: 'User', operationType: OperationType.BeforeCreate, newData: { @@ -55,7 +55,7 @@ describe('Default fields', () => { }) it('shoud add updatedAt value on update operation type', async () => { - const hookObject = new HookObject({ + const hookObject = new HookObject({ className: 'User', operationType: OperationType.BeforeUpdate, newData: { @@ -105,10 +105,10 @@ describe('Default fields', () => { }, } as any - const context = { wibeApp: { config } } as any + const context = { wabeApp: { config } } as any it('should add the value if a default value is defined in schema but not specified', async () => { - const hookObject = new HookObject({ + const hookObject = new HookObject({ className: 'User', operationType: OperationType.BeforeCreate, newData: { @@ -130,7 +130,7 @@ describe('Default fields', () => { }) it('should not add a default value if a value is specified', async () => { - const hookObject = new HookObject({ + const hookObject = new HookObject({ className: 'User', operationType: OperationType.BeforeCreate, newData: { diff --git a/packages/wibe-server/src/hooks/defaultFields.ts b/packages/wabe-server/src/hooks/defaultFields.ts similarity index 86% rename from packages/wibe-server/src/hooks/defaultFields.ts rename to packages/wabe-server/src/hooks/defaultFields.ts index 3bb7dc73..efbb0d61 100644 --- a/packages/wibe-server/src/hooks/defaultFields.ts +++ b/packages/wabe-server/src/hooks/defaultFields.ts @@ -1,5 +1,5 @@ import { getClassFromClassName } from '../utils' -import type { DevWibeAppTypes } from '../utils/helper' +import type { DevWabeAppTypes } from '../utils/helper' import type { HookObject } from './HookObject' export const defaultBeforeCreateForCreatedAt = async ( @@ -18,9 +18,9 @@ export const defaultBeforeUpdateForUpdatedAt = async ( export const defaultBeforeCreateForDefaultValue = async ( object: HookObject, ) => { - const schemaClass = getClassFromClassName( + const schemaClass = getClassFromClassName( object.className, - object.context.wibeApp.config, + object.context.wabeApp.config, ) const allFields = Object.keys(schemaClass.fields) diff --git a/packages/wibe-server/src/hooks/index.test.ts b/packages/wabe-server/src/hooks/index.test.ts similarity index 91% rename from packages/wibe-server/src/hooks/index.test.ts rename to packages/wabe-server/src/hooks/index.test.ts index 4beda094..0cb8fae0 100644 --- a/packages/wibe-server/src/hooks/index.test.ts +++ b/packages/wabe-server/src/hooks/index.test.ts @@ -63,7 +63,7 @@ describe('Hooks', () => { className: 'ClassTest', context: { isRoot: true, - wibeApp: { databaseController, config } as any, + wabeApp: { databaseController, config } as any, }, newData: { name: 'test' }, }) @@ -84,7 +84,7 @@ describe('Hooks', () => { className: 'ClassName', context: { isRoot: true, - wibeApp: { databaseController, config } as any, + wabeApp: { databaseController, config } as any, }, newData: { name: 'test' }, }) @@ -97,7 +97,7 @@ describe('Hooks', () => { expect(mockGetObject).toHaveBeenCalledTimes(1) expect(mockGetObject).toHaveBeenCalledWith({ className: 'ClassName', - context: { isRoot: true, wibeApp: { databaseController, config } }, + context: { isRoot: true, wabeApp: { databaseController, config } }, id: 'id', skipHooks: true, fields: ['*'], @@ -115,7 +115,7 @@ describe('Hooks', () => { expect(hookObject.context).toEqual({ isRoot: true, - wibeApp: { + wabeApp: { databaseController: expect.any(Object), config, }, @@ -127,7 +127,7 @@ describe('Hooks', () => { className: 'ClassName', context: { isRoot: true, - wibeApp: { databaseController, config } as any, + wabeApp: { databaseController, config } as any, }, newData: { name: 'test' }, }) @@ -145,7 +145,7 @@ describe('Hooks', () => { expect(hookObject.context).toEqual({ isRoot: true, - wibeApp: { databaseController: expect.any(Object), config }, + wabeApp: { databaseController: expect.any(Object), config }, }) }) @@ -160,7 +160,7 @@ describe('Hooks', () => { className: 'ClassName', context: { isRoot: true, - wibeApp: { databaseController, config } as any, + wabeApp: { databaseController, config } as any, }, newData: { name: 'test' }, }) @@ -183,7 +183,7 @@ describe('Hooks', () => { className: 'ClassName', context: { isRoot: true, - wibeApp: { databaseController, config } as any, + wabeApp: { databaseController, config } as any, }, newData: { name: 'test' }, }) diff --git a/packages/wibe-server/src/hooks/index.ts b/packages/wabe-server/src/hooks/index.ts similarity index 90% rename from packages/wibe-server/src/hooks/index.ts rename to packages/wabe-server/src/hooks/index.ts index 13b2a414..58f72dcd 100644 --- a/packages/wibe-server/src/hooks/index.ts +++ b/packages/wabe-server/src/hooks/index.ts @@ -3,8 +3,8 @@ import { defaultBeforeCreateUpload, defaultBeforeUpdateUpload, } from '../files/hookUploadFile' -import type { WibeAppTypes, WibeConfig } from '../server' -import type { WibeContext } from '../server/interface' +import type { WabeAppTypes, WabeConfig } from '../server' +import type { WabeContext } from '../server/interface' import { HookObject } from './HookObject' import { defaultCallAuthenticationProviderOnBeforeCreateUser, @@ -37,7 +37,7 @@ export enum OperationType { BeforeRead = 'beforeRead', } -export type Hook = { +export type Hook = { operationType: OperationType // If the className is undefined the hook is called on each class className?: T @@ -48,13 +48,13 @@ export type Hook = { callback: (hookObject: HookObject) => Promise | void } -export type TypedNewData = Record< - keyof WibeAppTypes['types'][T], +export type TypedNewData = Record< + keyof WabeAppTypes['types'][T], any > export const _findHooksByPriority = async < - T extends keyof WibeAppTypes['types'], + T extends keyof WabeAppTypes['types'], >({ className, operationType, @@ -64,7 +64,7 @@ export const _findHooksByPriority = async < operationType: OperationType className: T priority: number - config: WibeConfig + config: WabeConfig }) => config.hooks?.filter( (hook) => @@ -73,7 +73,7 @@ export const _findHooksByPriority = async < (className === hook.className || !hook.className), ) || [] -const _getHooksOrderByPriorities = (config: WibeConfig) => +const _getHooksOrderByPriorities = (config: WabeConfig) => config.hooks ?.reduce((acc, hook) => { if (!acc.includes(hook.priority)) acc.push(hook.priority) @@ -82,14 +82,14 @@ const _getHooksOrderByPriorities = (config: WibeConfig) => }, [] as number[]) .sort((a, b) => a - b) || [] -export const initializeHook = ({ +export const initializeHook = ({ className, newData, context, }: { className: T newData?: TypedNewData - context: WibeContext + context: WabeContext }) => { const computeObject = async ({ id, @@ -107,7 +107,7 @@ export const initializeHook = ({ if (!id) throw new Error('Object not found') - return context.wibeApp.databaseController.getObject({ + return context.wabeApp.databaseController.getObject({ // @ts-expect-error className, context: { @@ -134,7 +134,7 @@ export const initializeHook = ({ // @ts-expect-error if (operationType === OperationType.BeforeCreate) return [newData] - const res = await context.wibeApp.databaseController.getObjects({ + const res = await context.wabeApp.databaseController.getObjects({ className, context: { ...context, @@ -152,7 +152,7 @@ export const initializeHook = ({ } const hooksOrderByPriorities = _getHooksOrderByPriorities( - context.wibeApp.config, + context.wabeApp.config, ) return { @@ -190,7 +190,7 @@ export const initializeHook = ({ className, operationType, priority, - config: context.wibeApp.config, + config: context.wabeApp.config, }) await Promise.all( @@ -238,7 +238,7 @@ export const initializeHook = ({ className, operationType, priority, - config: context.wibeApp.config, + config: context.wabeApp.config, }) await Promise.all( diff --git a/packages/wibe-server/src/hooks/permissions.test.ts b/packages/wabe-server/src/hooks/permissions.test.ts similarity index 93% rename from packages/wibe-server/src/hooks/permissions.test.ts rename to packages/wabe-server/src/hooks/permissions.test.ts index d834b665..4c74b6aa 100644 --- a/packages/wibe-server/src/hooks/permissions.test.ts +++ b/packages/wabe-server/src/hooks/permissions.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it, beforeEach, mock, spyOn } from 'bun:test' import { _getPermissionPropertiesOfAClass, _checkCLP } from './permissions' import { HookObject } from './HookObject' import { OperationType } from '.' -import type { WibeContext } from '../server/interface' +import type { WabeContext } from '../server/interface' import * as permissions from './permissions' describe('Permissions', () => { @@ -42,7 +42,7 @@ describe('Permissions', () => { }, } as any - const context = { wibeApp: { config } } as any + const context = { wabeApp: { config } } as any it('should get the permission for a given className', async () => { const permission = await _getPermissionPropertiesOfAClass({ @@ -66,12 +66,12 @@ describe('Permissions', () => { }) it('should throw permission denied if no session id is provided but class require authentication', async () => { - const context: WibeContext = { + const context: WabeContext = { sessionId: '', // @ts-expect-error user: {}, isRoot: false, - wibeApp: { databaseController, config } as any, + wabeApp: { databaseController, config } as any, } const obj = new HookObject({ @@ -92,7 +92,7 @@ describe('Permissions', () => { user: { id: 'userId' }, } as never) - const context: WibeContext = { + const context: WabeContext = { sessionId: 'sessionId', user: { id: 'userId', @@ -102,7 +102,7 @@ describe('Permissions', () => { } as any, } as any, isRoot: false, - wibeApp: { + wabeApp: { databaseController, config, } as any, @@ -126,7 +126,7 @@ describe('Permissions', () => { user: { id: 'userId' }, } as never) - const context: WibeContext = { + const context: WabeContext = { sessionId: 'sessionId', user: { id: 'userId', @@ -136,7 +136,7 @@ describe('Permissions', () => { } as any, } as any, isRoot: false, - wibeApp: { + wabeApp: { databaseController, config, } as any, @@ -153,13 +153,13 @@ describe('Permissions', () => { }) it('should not throw permission denied if client is root', async () => { - const context: WibeContext = { + const context: WabeContext = { sessionId: '', user: { id: '', } as any, isRoot: true, - wibeApp: { databaseController, config } as any, + wabeApp: { databaseController, config } as any, } const obj = new HookObject({ diff --git a/packages/wibe-server/src/hooks/permissions.ts b/packages/wabe-server/src/hooks/permissions.ts similarity index 89% rename from packages/wibe-server/src/hooks/permissions.ts rename to packages/wabe-server/src/hooks/permissions.ts index 102c4336..1c45fed2 100644 --- a/packages/wibe-server/src/hooks/permissions.ts +++ b/packages/wabe-server/src/hooks/permissions.ts @@ -1,5 +1,5 @@ import type { PermissionsOperations } from '../schema' -import type { WibeContext } from '../server/interface' +import type { WabeContext } from '../server/interface' import type { HookObject } from './HookObject' import { OperationType } from './index' @@ -25,15 +25,15 @@ export const _getPermissionPropertiesOfAClass = async ({ }: { className: string operation: PermissionsOperations - context: WibeContext + context: WabeContext }) => { - const wibeClass = context.wibeApp.config.schema.classes.find( + const wabeClass = context.wabeApp.config.schema.classes.find( (c) => c.name === className, ) - if (!wibeClass) throw new Error(`Class ${className} not found in schema`) + if (!wabeClass) throw new Error(`Class ${className} not found in schema`) - const permission = wibeClass.permissions?.[operation] + const permission = wabeClass.permissions?.[operation] return permission } @@ -65,7 +65,7 @@ export const _checkCLP = async ( `Permission denied to ${permissionOperation} class ${object.className}`, ) - const res = await object.context.wibeApp.databaseController.getObject({ + const res = await object.context.wabeApp.databaseController.getObject({ className: '_Session', id: sessionId, fields: ['id', 'user.id'], diff --git a/packages/wibe-server/src/hooks/searchableFields.test.ts b/packages/wabe-server/src/hooks/searchableFields.test.ts similarity index 91% rename from packages/wibe-server/src/hooks/searchableFields.test.ts rename to packages/wabe-server/src/hooks/searchableFields.test.ts index 882dae25..014f589b 100644 --- a/packages/wibe-server/src/hooks/searchableFields.test.ts +++ b/packages/wabe-server/src/hooks/searchableFields.test.ts @@ -5,7 +5,7 @@ import { stringExtraction, } from './searchableFields' import { HookObject } from './HookObject' -import type { DevWibeAppTypes } from '../utils/helper' +import type { DevWabeAppTypes } from '../utils/helper' import { OperationType } from '.' describe('searchablesFields', () => { @@ -30,7 +30,7 @@ describe('searchablesFields', () => { }) it('should complete the search fields of each object on insert', async () => { - const hookObject = new HookObject({ + const hookObject = new HookObject({ className: 'User', operationType: OperationType.BeforeCreate, newData: { @@ -39,7 +39,7 @@ describe('searchablesFields', () => { age: 20, } as any, context: { - wibeApp: { + wabeApp: { config: { schema: { classes: [ @@ -68,7 +68,7 @@ describe('searchablesFields', () => { }) it('should complete the search fields of each object on update', async () => { - const hookObject = new HookObject({ + const hookObject = new HookObject({ className: 'User', operationType: OperationType.BeforeUpdate, newData: { @@ -77,7 +77,7 @@ describe('searchablesFields', () => { age: 20, } as any, context: { - wibeApp: { + wabeApp: { config: { schema: { classes: [ diff --git a/packages/wibe-server/src/hooks/searchableFields.ts b/packages/wabe-server/src/hooks/searchableFields.ts similarity index 95% rename from packages/wibe-server/src/hooks/searchableFields.ts rename to packages/wabe-server/src/hooks/searchableFields.ts index dd5d6a9f..13567831 100644 --- a/packages/wibe-server/src/hooks/searchableFields.ts +++ b/packages/wabe-server/src/hooks/searchableFields.ts @@ -28,7 +28,7 @@ export const stringExtraction = (value: any): Array => { export const defaultSearchableFieldsBeforeCreate = ( object: HookObject, ) => { - const searchablesFields = object.context.wibeApp.config.schema.classes.find( + const searchablesFields = object.context.wabeApp.config.schema.classes.find( (currentClass) => currentClass.name === object.className, )?.searchableFields @@ -50,7 +50,7 @@ export const defaultSearchableFieldsBeforeCreate = ( export const defaultSearchableFieldsBeforeUpdate = ( object: HookObject, ) => { - const searchablesFields = object.context.wibeApp.config.schema.classes.find( + const searchablesFields = object.context.wabeApp.config.schema.classes.find( (currentClass) => currentClass.name === object.className, )?.searchableFields diff --git a/packages/wibe-server/src/index.ts b/packages/wabe-server/src/index.ts similarity index 100% rename from packages/wibe-server/src/index.ts rename to packages/wabe-server/src/index.ts diff --git a/packages/wibe-server/src/schema/Schema.test.ts b/packages/wabe-server/src/schema/Schema.test.ts similarity index 100% rename from packages/wibe-server/src/schema/Schema.test.ts rename to packages/wabe-server/src/schema/Schema.test.ts diff --git a/packages/wibe-server/src/schema/Schema.ts b/packages/wabe-server/src/schema/Schema.ts similarity index 88% rename from packages/wibe-server/src/schema/Schema.ts rename to packages/wabe-server/src/schema/Schema.ts index 5802c893..75f6b8a9 100644 --- a/packages/wibe-server/src/schema/Schema.ts +++ b/packages/wabe-server/src/schema/Schema.ts @@ -1,11 +1,15 @@ -import { signInWithResolver, signUpWithResolver } from '../authentication' +import { + AuthenticationProvider, + signInWithResolver, + signUpWithResolver, +} from '../authentication' import { refreshResolver } from '../authentication/resolvers/refreshResolver' import { signOutResolver } from '../authentication/resolvers/signOutResolver' import { verifyChallengeResolver } from '../authentication/resolvers/verifyChallenge' -import type { WibeConfig, WibeAppTypes } from '../server' +import type { WabeConfig, WabeAppTypes } from '../server' import { meResolver } from './resolvers/meResolver' -export type WibePrimaryTypes = +export type WabePrimaryTypes = | 'String' | 'Int' | 'Float' @@ -14,27 +18,27 @@ export type WibePrimaryTypes = | 'Date' | 'File' -export type WibeCustomTypes = 'Array' | 'Object' +export type WabeCustomTypes = 'Array' | 'Object' -export type WibeRelationTypes = 'Pointer' | 'Relation' +export type WabeRelationTypes = 'Pointer' | 'Relation' -export type WibeTypes = WibeCustomTypes | WibePrimaryTypes | WibeRelationTypes +export type WabeTypes = WabeCustomTypes | WabePrimaryTypes | WabeRelationTypes -type WibeObject = { +type WabeObject = { name: string fields: SchemaFields description?: string required?: boolean } -type TypeFieldBase = { +type TypeFieldBase = { type: K required?: boolean description?: string defaultValue?: U } -type TypeFieldArray = { +type TypeFieldArray = { type: 'Array' required?: boolean requiredValue?: boolean @@ -44,27 +48,27 @@ type TypeFieldArray = { | { // For the moment we only keep object and not array because we don't // support array of array - typeValue: WibePrimaryTypes + typeValue: WabePrimaryTypes } - | { typeValue: 'Object'; object: WibeObject } + | { typeValue: 'Object'; object: WabeObject } ) -type TypeFieldObject = { +type TypeFieldObject = { type: 'Object' required?: boolean description?: string - object: WibeObject + object: WabeObject defaultValue?: any } -type TypeFieldPointer = { +type TypeFieldPointer = { type: 'Pointer' required?: boolean description?: string class: keyof T['types'] } -type TypeFieldRelation = { +type TypeFieldRelation = { type: 'Relation' required?: boolean description?: string @@ -77,21 +81,21 @@ type TypeFieldFile = { description?: string } -type TypeFieldCustomScalars = { +type TypeFieldCustomScalars = { type: T['scalars'] required?: boolean description?: string defaultValue?: any } -type TypeFieldCustomEnums = { +type TypeFieldCustomEnums = { type: T['enums'] required?: boolean description?: string defaultValue?: any } -export type TypeField = +export type TypeField = | TypeFieldBase | TypeFieldBase | TypeFieldBase @@ -106,20 +110,20 @@ export type TypeField = | TypeFieldCustomScalars | TypeFieldCustomEnums -export type SchemaFields = Record> +export type SchemaFields = Record> -export type QueryResolver = { +export type QueryResolver = { required?: boolean description?: string args?: SchemaFields resolve: (...args: any) => any } & ( - | { type: WibePrimaryTypes } + | { type: WabePrimaryTypes } | { type: 'Object'; outputObject: ClassInterface } - | { type: 'Array'; typeValue: WibePrimaryTypes } + | { type: 'Array'; typeValue: WabePrimaryTypes } ) -export type MutationResolver = { +export type MutationResolver = { required?: boolean description?: string args?: { @@ -127,12 +131,12 @@ export type MutationResolver = { } resolve: (...args: any) => any } & ( - | { type: WibePrimaryTypes } + | { type: WabePrimaryTypes } | { type: 'Object'; outputObject: ClassInterface } - | { type: 'Array'; typeValue: WibePrimaryTypes } + | { type: 'Array'; typeValue: WabePrimaryTypes } ) -export type TypeResolver = { +export type TypeResolver = { queries?: { [key: string]: QueryResolver } @@ -164,7 +168,7 @@ export type ClassIndexes = Array<{ unique?: boolean }> -export interface ClassInterface { +export interface ClassInterface { name: string fields: SchemaFields description?: string @@ -187,18 +191,18 @@ export interface EnumInterface { description?: string } -export interface SchemaInterface { +export interface SchemaInterface { classes: ClassInterface[] scalars?: ScalarInterface[] enums?: EnumInterface[] resolvers?: TypeResolver } -export class Schema { +export class Schema { public schema: SchemaInterface - private config: WibeConfig + private config: WabeConfig - constructor(config: WibeConfig) { + constructor(config: WabeConfig) { this.config = config // TODO : Add default scalars here this.schema = { @@ -213,9 +217,12 @@ export class Schema { return [ { name: 'AuthenticationProvider', - values: { - Google: 'Google', - }, + values: Object.fromEntries( + Object.values(AuthenticationProvider).map((key) => [ + key, + key, + ]), + ), }, { name: 'SecondaryFactor', diff --git a/packages/wibe-server/src/schema/index.ts b/packages/wabe-server/src/schema/index.ts similarity index 100% rename from packages/wibe-server/src/schema/index.ts rename to packages/wabe-server/src/schema/index.ts diff --git a/packages/wibe-server/src/schema/resolvers/meResolver.test.ts b/packages/wabe-server/src/schema/resolvers/meResolver.test.ts similarity index 100% rename from packages/wibe-server/src/schema/resolvers/meResolver.test.ts rename to packages/wabe-server/src/schema/resolvers/meResolver.test.ts diff --git a/packages/wabe-server/src/schema/resolvers/meResolver.ts b/packages/wabe-server/src/schema/resolvers/meResolver.ts new file mode 100644 index 00000000..08fada61 --- /dev/null +++ b/packages/wabe-server/src/schema/resolvers/meResolver.ts @@ -0,0 +1,12 @@ +import type { WabeContext } from '../../server/interface' +import type { DevWabeAppTypes } from '../../utils/helper' + +export const meResolver = async ( + _: any, + __: any, + context: WabeContext, +) => { + return { + user: context.user, + } +} diff --git a/packages/wibe-server/src/server/generateCodegen.ts b/packages/wabe-server/src/server/generateCodegen.ts similarity index 67% rename from packages/wibe-server/src/server/generateCodegen.ts rename to packages/wabe-server/src/server/generateCodegen.ts index 418970b9..8573c1d8 100644 --- a/packages/wibe-server/src/server/generateCodegen.ts +++ b/packages/wabe-server/src/server/generateCodegen.ts @@ -2,8 +2,6 @@ import { codegen } from '@graphql-codegen/core' import * as typescriptPlugin from '@graphql-codegen/typescript' import * as graphqlRequestPlugin from '@graphql-codegen/typescript-graphql-request' import * as graphqlOperationsPlugin from '@graphql-codegen/typescript-operations' -import { loadSchema } from '@graphql-tools/load' -import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader' import { type GraphQLSchema, parse, printSchema } from 'graphql' import type { ClassInterface, @@ -11,32 +9,32 @@ import type { ScalarInterface, SchemaInterface, } from '../schema' -import type { DevWibeAppTypes } from '../utils/helper' +import type { DevWabeAppTypes } from '../utils/helper' -export const generateWibeFile = ({ +export const generateWabeFile = ({ scalars, enums, classes, }: { enums?: EnumInterface[] scalars?: ScalarInterface[] - classes: ClassInterface[] + classes: ClassInterface[] }) => { // Scalars const listOfScalars = scalars?.map((scalar) => `"${scalar.name}"`) || [] - const wibeScalarType = + const wabeScalarType = listOfScalars.length > 0 - ? `export type WibeSchemaScalars = ${listOfScalars.join(' | ')}` + ? `export type WabeSchemaScalars = ${listOfScalars.join(' | ')}` : '' // Enums - const wibeEnumsGlobalTypes = - enums?.map((wibeEnum) => `"${wibeEnum.name}"`) || [] + const wabeEnumsGlobalTypes = + enums?.map((wabeEnum) => `"${wabeEnum.name}"`) || [] - const wibeEnumsGlobalTypesString = - wibeEnumsGlobalTypes.length > 0 - ? `export type WibeSchemaEnums = ${wibeEnumsGlobalTypes.join( + const wabeEnumsGlobalTypesString = + wabeEnumsGlobalTypes.length > 0 + ? `export type WabeSchemaEnums = ${wabeEnumsGlobalTypes.join( ' | ', )}` : '' @@ -46,11 +44,11 @@ export const generateWibeFile = ({ .map((schema) => `${schema.name}: ${schema.name}`) .filter((schema) => schema) - const globalWibeTypeString = `export type WibeSchemaTypes = {\n\t${allNames.join( + const globalWabeTypeString = `export type WabeSchemaTypes = {\n\t${allNames.join( ',\n\t', )}\n}` - return `${wibeScalarType}\n\n${wibeEnumsGlobalTypesString}\n\n${globalWibeTypeString}` + return `${wabeScalarType}\n\n${wabeEnumsGlobalTypesString}\n\n${globalWabeTypeString}` } export const generateGraphqlTypes = async ({ @@ -60,7 +58,7 @@ export const generateGraphqlTypes = async ({ const config = { documents: [], config: {}, - filename: `${path}/wibe.ts`, + filename: `${path}/wabe.ts`, schema: parse(graphqlSchemaContent), plugins: [ { typescript: {} }, @@ -95,22 +93,22 @@ export const generateCodegen = async ({ path, }) - const wibeOutput = generateWibeFile({ + const wabeOutput = generateWabeFile({ scalars: schema.scalars, enums: schema.enums, classes: schema.classes, }) - const content = `${graphqlOutput}\n\n${wibeOutput}` + const content = `${graphqlOutput}\n\n${wabeOutput}` try { - const contentOfActualWibeFile = await Bun.file(`${path}/wibe.ts`).text() + const contentOfActualWabeFile = await Bun.file(`${path}/wabe.ts`).text() // We will need to find a better way to avoid infinite loop of loading // Better solution will be that bun implements watch ignores - if (content === contentOfActualWibeFile) return + if (content === contentOfActualWabeFile) return } catch {} - Bun.write(`${path}/wibe.ts`, `${graphqlOutput}\n\n${wibeOutput}`) + Bun.write(`${path}/wabe.ts`, `${graphqlOutput}\n\n${wabeOutput}`) Bun.write(`${path}/schema.graphql`, graphqlSchemaContent) } diff --git a/packages/wibe-server/src/server/index.test.ts b/packages/wabe-server/src/server/index.test.ts similarity index 84% rename from packages/wibe-server/src/server/index.test.ts rename to packages/wabe-server/src/server/index.test.ts index 7153e80c..335a72f8 100644 --- a/packages/wibe-server/src/server/index.test.ts +++ b/packages/wabe-server/src/server/index.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it, spyOn } from 'bun:test' import { v4 as uuid } from 'uuid' import getPort from 'get-port' -import { WibeApp } from '.' +import { WabeApp } from '.' import { DatabaseEnum } from '../database' import { Schema } from '../schema' @@ -10,7 +10,7 @@ describe('Server', () => { const databaseId = uuid() const port = await getPort() - const wibe = new WibeApp({ + const wabe = new WabeApp({ rootKey: 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc', database: { @@ -29,15 +29,15 @@ describe('Server', () => { }, }) - await wibe.start() + await wabe.start() const res = await fetch(`http://127.0.0.1:${port}/health`) expect(res.status).toEqual(200) - await wibe.close() + await wabe.close() }) - it('should update the schema to static WibeApp after the Schema initialization', async () => { + it('should update the schema to static WabeApp after the Schema initialization', async () => { const spySchemaDefaultClass = spyOn(Schema.prototype, 'defaultClass') const spySchemaDefaultEnum = spyOn(Schema.prototype, 'defaultEnum') @@ -45,7 +45,7 @@ describe('Server', () => { const port = await getPort() - const wibe = new WibeApp({ + const wabe = new WabeApp({ rootKey: 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc', database: { @@ -64,10 +64,10 @@ describe('Server', () => { }, }) - await wibe.start() + await wabe.start() // _Session class is a default class so if it's present the schema is updated - const isSessionClassExist = wibe.config.schema.classes.find( + const isSessionClassExist = wabe.config.schema.classes.find( (schemaClass) => schemaClass.name === '_Session', ) @@ -76,6 +76,6 @@ describe('Server', () => { expect(spySchemaDefaultClass).toHaveBeenCalledTimes(1) expect(spySchemaDefaultEnum).toHaveBeenCalledTimes(1) - await wibe.close() + await wabe.close() }) }) diff --git a/packages/wibe-server/src/server/index.ts b/packages/wabe-server/src/server/index.ts similarity index 86% rename from packages/wibe-server/src/server/index.ts rename to packages/wabe-server/src/server/index.ts index f0bd9a3d..b00326e5 100644 --- a/packages/wibe-server/src/server/index.ts +++ b/packages/wabe-server/src/server/index.ts @@ -3,9 +3,9 @@ import { DatabaseController } from '../database/controllers/DatabaseController' import { MongoAdapter } from '../database/adapters/MongoAdapter' import { Schema, type SchemaInterface } from '../schema/Schema' import { GraphQLObjectType, GraphQLSchema } from 'graphql' -import { GraphQLSchema as WibeGraphQLSchema } from '../graphql' +import { GraphQLSchema as WabeGraphQLSchema } from '../graphql' import type { AuthenticationConfig } from '../authentication/interface' -import { type WibeRoute, defaultRoutes } from './routes' +import { type WabeRoute, defaultRoutes } from './routes' import { type Hook, getDefaultHooks } from '../hooks' import { generateCodegen } from './generateCodegen' import { defaultAuthenticationMethods } from '../authentication/defaultAuthentication' @@ -13,12 +13,12 @@ import { Wobe, cors } from 'wobe' import { WobeGraphqlYogaPlugin } from 'wobe-graphql-yoga' import { Session } from '../authentication/Session' import { getCookieInRequestHeaders } from '../utils' -import type { WibeContext } from './interface' +import type { WabeContext } from './interface' import { initializeRoles } from '../authentication/roles' import type { FileConfig } from '../files' import { fileDevAdapter } from '../files/devAdapter' -export interface WibeConfig { +export interface WabeConfig { port: number schema: SchemaInterface database: DatabaseConfig @@ -29,26 +29,26 @@ export interface WibeConfig { } | { enabled?: false } authentication?: AuthenticationConfig - routes?: WibeRoute[] + routes?: WabeRoute[] rootKey: string hooks?: Hook[] file?: FileConfig } -export type WibeAppTypes = { +export type WabeAppTypes = { types: Record scalars: string enums: string } -export type WobeCustomContext = { - wibe: WibeContext +export type WobeCustomContext = { + wabe: WabeContext } -export class WibeApp { +export class WabeApp { public server: Wobe> - public config: WibeConfig + public config: WabeConfig public databaseController: DatabaseController constructor({ @@ -60,7 +60,7 @@ export class WibeApp { codegen, hooks, file, - }: WibeConfig) { + }: WabeConfig) { this.config = { port, schema, @@ -114,9 +114,9 @@ export class WibeApp { } loadDefaultRoutes() { - const wibeRoutes = defaultRoutes() + const wabeRoutes = defaultRoutes() - wibeRoutes.map((route) => { + wabeRoutes.map((route) => { const { method } = route switch (method) { @@ -141,11 +141,11 @@ export class WibeApp { async start() { await this.databaseController.connect() - const wibeSchema = new Schema(this.config) + const wabeSchema = new Schema(this.config) - this.config.schema = wibeSchema.schema + this.config.schema = wabeSchema.schema - const graphqlSchema = new WibeGraphQLSchema(wibeSchema) + const graphqlSchema = new WabeGraphQLSchema(wabeSchema) const types = graphqlSchema.createSchema() @@ -170,7 +170,7 @@ export class WibeApp { ) generateCodegen({ path: this.config.codegen.path, - schema: wibeSchema.schema, + schema: wabeSchema.schema, graphqlSchema: schema, }) @@ -186,14 +186,14 @@ export class WibeApp { }), ) - // Set the wibe context + // Set the wabe context this.server.beforeHandler(async (ctx) => { const headers = ctx.request.headers - if (headers.get('Wibe-Root-Key') === this.config.rootKey) { - ctx.wibe = { + if (headers.get('Wabe-Root-Key') === this.config.rootKey) { + ctx.wabe = { isRoot: true, - wibeApp: this, + wabeApp: this, } return } @@ -208,15 +208,15 @@ export class WibeApp { ctx.request.headers, ) - return headers.get('Wibe-Access-Token') + return headers.get('Wabe-Access-Token') } const accessToken = getAccessToken() if (!accessToken) { - ctx.wibe = { + ctx.wabe = { isRoot: false, - wibeApp: this, + wabeApp: this, } return } @@ -227,15 +227,15 @@ export class WibeApp { accessToken, { isRoot: true, - wibeApp: this, + wabeApp: this, }, ) - ctx.wibe = { + ctx.wabe = { isRoot: false, sessionId, user, - wibeApp: this, + wabeApp: this, } }) @@ -249,7 +249,7 @@ export class WibeApp { allowedHeaders: ['content-type'], }, graphqlEndpoint: '/graphql', - context: async (ctx): Promise> => ctx.wibe, + context: async (ctx): Promise> => ctx.wabe, graphqlMiddleware: async (resolve, res) => { const response = await resolve() diff --git a/packages/wabe-server/src/server/interface.ts b/packages/wabe-server/src/server/interface.ts new file mode 100644 index 00000000..fcc86277 --- /dev/null +++ b/packages/wabe-server/src/server/interface.ts @@ -0,0 +1,11 @@ +import type { WobeResponse } from 'wobe' +import type { WabeApp, WabeAppTypes } from '.' +import type { User } from '../../generated/wabe' + +export interface WabeContext { + response?: WobeResponse + user?: User | null + sessionId?: string + isRoot: boolean + wabeApp: WabeApp +} diff --git a/packages/wibe-server/src/server/routes/authHandler.test.ts b/packages/wabe-server/src/server/routes/authHandler.test.ts similarity index 100% rename from packages/wibe-server/src/server/routes/authHandler.test.ts rename to packages/wabe-server/src/server/routes/authHandler.test.ts diff --git a/packages/wibe-server/src/server/routes/authHandler.ts b/packages/wabe-server/src/server/routes/authHandler.ts similarity index 86% rename from packages/wibe-server/src/server/routes/authHandler.ts rename to packages/wabe-server/src/server/routes/authHandler.ts index 1c7084cb..4a367092 100644 --- a/packages/wibe-server/src/server/routes/authHandler.ts +++ b/packages/wabe-server/src/server/routes/authHandler.ts @@ -1,5 +1,5 @@ import type { Context } from 'wobe' -import type { WibeContext } from '../interface' +import type { WabeContext } from '../interface' import { ProviderEnum } from '../../authentication/interface' import { getGraphqlClient } from '../../utils/helper' import { gql } from 'graphql-request' @@ -20,7 +20,7 @@ import { generateRandomValues } from '../../authentication/oauth/utils' // https://www.rfc-editor.org/rfc/rfc7636#section-4.4 not precise the storage of codeVerifier export const oauthHandlerCallback = async ( context: Context, - wibeContext: WibeContext, + wabeContext: WabeContext, ) => { try { const state = context.query.state @@ -33,7 +33,7 @@ export const oauthHandlerCallback = async ( const codeVerifier = context.getCookie('code_verifier') const provider = context.getCookie('provider') - await getGraphqlClient(wibeContext.wibeApp.config.port).request( + await getGraphqlClient(wabeContext.wabeApp.config.port).request( gql` mutation signInWith( $authorizationCode: String! @@ -60,13 +60,13 @@ export const oauthHandlerCallback = async ( ) context.redirect( - wibeContext.wibeApp.config.authentication?.successRedirectPath || + wabeContext.wabeApp.config.authentication?.successRedirectPath || '/', ) } catch (error) { console.error(error) // context.redirect( - // wibeContext.wibeApp.config.authentication?.failureRedirectPath || + // wabeContext.wabeApp.config.authentication?.failureRedirectPath || // '/', // ) } @@ -74,10 +74,10 @@ export const oauthHandlerCallback = async ( export const authHandler = async ( context: Context, - wibeContext: WibeContext, + wabeContext: WabeContext, provider: ProviderEnum, ) => { - if (!wibeContext.wibeApp.config) throw new Error('Wibe config not found') + if (!wabeContext.wabeApp.config) throw new Error('Wabe config not found') context.res.setCookie('provider', provider, { httpOnly: true, @@ -88,7 +88,7 @@ export const authHandler = async ( switch (provider) { case ProviderEnum.google: { - const googleOauth = new Google(wibeContext.wibeApp.config) + const googleOauth = new Google(wabeContext.wabeApp.config) const state = generateRandomValues() const codeVerifier = generateRandomValues() diff --git a/packages/wibe-server/src/server/routes/index.ts b/packages/wabe-server/src/server/routes/index.ts similarity index 79% rename from packages/wibe-server/src/server/routes/index.ts rename to packages/wabe-server/src/server/routes/index.ts index 17993600..2a60ab7f 100644 --- a/packages/wibe-server/src/server/routes/index.ts +++ b/packages/wabe-server/src/server/routes/index.ts @@ -3,13 +3,13 @@ import type { ProviderEnum } from '../../authentication/interface' import { authHandler, oauthHandlerCallback } from './authHandler' import type { WobeCustomContext } from '..' -export interface WibeRoute { +export interface WabeRoute { method: 'GET' | 'POST' | 'PUT' | 'DELETE' path: string handler: WobeHandler> } -export const defaultRoutes = (): WibeRoute[] => [ +export const defaultRoutes = (): WabeRoute[] => [ { method: 'GET', path: '/tata/tutu', @@ -27,14 +27,14 @@ export const defaultRoutes = (): WibeRoute[] => [ throw new Error('Authentication failed, provider not found') // TODO: Maybe check if the value is in the enum - return authHandler(context, context.wibe, provider as ProviderEnum) + return authHandler(context, context.wabe, provider as ProviderEnum) }, }, { method: 'GET', path: '/auth/oauth/callback', handler: async (context) => { - return oauthHandlerCallback(context, context.wibe) + return oauthHandlerCallback(context, context.wabe) }, }, ] diff --git a/packages/wibe-server/src/utils/helper.ts b/packages/wabe-server/src/utils/helper.ts similarity index 87% rename from packages/wibe-server/src/utils/helper.ts rename to packages/wabe-server/src/utils/helper.ts index 470f6b8c..aaf3064f 100644 --- a/packages/wibe-server/src/utils/helper.ts +++ b/packages/wabe-server/src/utils/helper.ts @@ -2,12 +2,12 @@ import getPort from 'get-port' import { GraphQLClient } from 'graphql-request' import { v4 as uuid } from 'uuid' import type { - WibeSchemaEnums, - WibeSchemaScalars, - WibeSchemaTypes, -} from '../../generated/wibe' + WabeSchemaEnums, + WabeSchemaScalars, + WabeSchemaTypes, +} from '../../generated/wabe' import { DatabaseEnum } from '../database' -import { WibeApp } from '../server' +import { WabeApp } from '../server' type NotNill = T extends null | undefined ? never : T @@ -23,10 +23,10 @@ export type DeepRequired = T extends Primitive : DeepRequired } -export type DevWibeAppTypes = { - types: WibeSchemaTypes - scalars: WibeSchemaScalars - enums: WibeSchemaEnums +export type DevWabeAppTypes = { + types: WabeSchemaTypes + scalars: WabeSchemaScalars + enums: WabeSchemaEnums } export const notEmpty = (value: T | null | undefined): value is T => @@ -35,7 +35,7 @@ export const notEmpty = (value: T | null | undefined): value is T => export const getGraphqlClient = (port: number): GraphQLClient => { const client = new GraphQLClient(`http://127.0.0.1:${port}/graphql`, { headers: { - 'Wibe-Root-Key': + 'Wabe-Root-Key': '0uwFvUxM$ceFuF1aEtTtZMa7DUN2NZudqgY5ve5W*QCyb58cwMj9JeoaV@d#%29v&aJzswuudVU1%nAT+rxS0Bh&OkgBYc0PH18*', }, }) @@ -55,7 +55,7 @@ export const getUserClient = ( ): GraphQLClient => { const client = new GraphQLClient(`http://127.0.0.1:${port}/graphql`, { headers: { - 'Wibe-Access-Token': accessToken, + 'Wabe-Access-Token': accessToken, }, }) @@ -67,7 +67,7 @@ export const setupTests = async () => { const port = await getPort() - const wibe = new WibeApp({ + const wabe = new WabeApp({ rootKey: '0uwFvUxM$ceFuF1aEtTtZMa7DUN2NZudqgY5ve5W*QCyb58cwMj9JeoaV@d#%29v&aJzswuudVU1%nAT+rxS0Bh&OkgBYc0PH18*', database: { @@ -160,12 +160,12 @@ export const setupTests = async () => { }, }) - await wibe.start() + await wabe.start() - return { wibe, port } + return { wabe, port } } -export const closeTests = async (wibe: WibeApp) => { - await wibe.databaseController.adapter?.close() - await wibe.close() +export const closeTests = async (wabe: WabeApp) => { + await wabe.databaseController.adapter?.close() + await wabe.close() } diff --git a/packages/wibe-server/src/utils/index.test.ts b/packages/wabe-server/src/utils/index.test.ts similarity index 100% rename from packages/wibe-server/src/utils/index.test.ts rename to packages/wabe-server/src/utils/index.test.ts diff --git a/packages/wibe-server/src/utils/index.ts b/packages/wabe-server/src/utils/index.ts similarity index 84% rename from packages/wibe-server/src/utils/index.ts rename to packages/wabe-server/src/utils/index.ts index e0e64be8..e0ece44b 100644 --- a/packages/wibe-server/src/utils/index.ts +++ b/packages/wabe-server/src/utils/index.ts @@ -1,12 +1,12 @@ -import * as wibeFile from '../../generated/wibe' +import * as wabeFile from '../../generated/wabe' import type { ClassInterface } from '../schema' -import type { WibeAppTypes, WibeConfig } from '../server' +import type { WabeAppTypes, WabeConfig } from '../server' import { getGraphqlClient } from './helper' -export const getClient = (config: WibeConfig) => { - // We do this to avoid failing import when wibe.ts is not already generated +export const getClient = (config: WabeConfig) => { + // We do this to avoid failing import when wabe.ts is not already generated // @ts-ignore - const getSdk = wibeFile.getSdk + const getSdk = wabeFile.getSdk if (!getSdk) return @@ -37,9 +37,9 @@ export const firstLetterInLowerCase = (str: string) => { ) } -export const getClassFromClassName = ( +export const getClassFromClassName = ( className: string, - config: WibeConfig, + config: WabeConfig, ): ClassInterface => { const classInSchema = config.schema.classes.find( (schemaClass) => schemaClass.name === className, diff --git a/packages/wibe-server/src/utils/preload.ts b/packages/wabe-server/src/utils/preload.ts similarity index 72% rename from packages/wibe-server/src/utils/preload.ts rename to packages/wabe-server/src/utils/preload.ts index fe69207b..f658b294 100644 --- a/packages/wibe-server/src/utils/preload.ts +++ b/packages/wabe-server/src/utils/preload.ts @@ -1,4 +1,4 @@ -import { runDatabase } from 'wibe-mongodb-launcher' +import { runDatabase } from 'wabe-mongodb-launcher' const setupEnvironment = () => { process.env.JWT_SECRET = 'dev' diff --git a/packages/wibe-server/tsconfig.json b/packages/wabe-server/tsconfig.json similarity index 100% rename from packages/wibe-server/tsconfig.json rename to packages/wabe-server/tsconfig.json diff --git a/packages/wibe-server/src/database/adapters/adaptersInterface.ts b/packages/wibe-server/src/database/adapters/adaptersInterface.ts deleted file mode 100644 index ea4e2596..00000000 --- a/packages/wibe-server/src/database/adapters/adaptersInterface.ts +++ /dev/null @@ -1,220 +0,0 @@ -import type { WibeContext } from '../../server/interface' -import type { WibeAppTypes } from '../../server' - -type WhereAggregation< - T extends keyof WibeAppTypes['types'], - K extends keyof WibeAppTypes['types'][T], -> = Record< - K | 'id', - { - equalTo?: any - notEqualTo?: any - greaterThan?: any - lessThan?: any - greaterThanOrEqualTo?: any - lessThanOrEqualTo?: any - in?: any[] - notIn?: any[] - contains?: any - notContains?: any - } -> - -type WhereConditional< - T extends keyof WibeAppTypes['types'], - K extends keyof WibeAppTypes['types'][T], -> = { - OR?: Array> - AND?: Array> -} - -export type WhereType< - T extends keyof WibeAppTypes['types'], - K extends keyof WibeAppTypes['types'][T], -> = Partial> & WhereConditional - -export interface AdapterOptions { - databaseUrl: string - databaseName: string -} - -export type MutationData = Record< - keyof WibeAppTypes['types'][T], - any -> - -export interface CountOptions< - T extends keyof WibeAppTypes['types'], - K extends keyof WibeAppTypes['types'][T], -> { - className: T - where?: WhereType - context: WibeContext -} - -// TODO: It could be cool if fields type supports something like user.id, user.email -export interface GetObjectOptions< - T extends keyof WibeAppTypes['types'], - K extends keyof WibeAppTypes['types'][T], -> { - className: T - id: string - where?: WhereType - fields: Array - context: WibeContext - skipHooks?: boolean -} - -export interface GetObjectsOptions< - T extends keyof WibeAppTypes['types'], - K extends keyof WibeAppTypes['types'][T], - W extends keyof WibeAppTypes['types'][T], -> { - className: T - where?: WhereType - fields: Array - offset?: number - first?: number - context: WibeContext - skipHooks?: boolean -} - -export interface CreateObjectOptions< - T extends keyof WibeAppTypes['types'], - K extends keyof WibeAppTypes['types'][T], - W extends keyof WibeAppTypes['types'][T], -> { - className: T - data: MutationData - fields: Array - context: WibeContext -} -export interface CreateObjectsOptions< - T extends keyof WibeAppTypes['types'], - K extends keyof WibeAppTypes['types'][T], - W extends keyof WibeAppTypes['types'][T], -> { - className: T - data: Array> - fields: Array - offset?: number - first?: number - context: WibeContext -} - -export interface UpdateObjectOptions< - T extends keyof WibeAppTypes['types'], - K extends keyof WibeAppTypes['types'][T], - W extends keyof WibeAppTypes['types'][T], -> { - className: T - id: string - where?: WhereType - data: MutationData - fields: Array - context: WibeContext -} - -export interface UpdateObjectsOptions< - T extends keyof WibeAppTypes['types'], - K extends keyof WibeAppTypes['types'][T], - W extends keyof WibeAppTypes['types'][T], -> { - className: T - where: WhereType - data: MutationData - fields: Array - offset?: number - first?: number - context: WibeContext -} - -export interface DeleteObjectOptions< - T extends keyof WibeAppTypes['types'], - K extends keyof WibeAppTypes['types'][T], - W extends keyof WibeAppTypes['types'][T], -> { - className: T - id: string - where?: WhereType - fields: Array - context: WibeContext -} - -export interface DeleteObjectsOptions< - T extends keyof WibeAppTypes['types'], - K extends keyof WibeAppTypes['types'][T], - W extends keyof WibeAppTypes['types'][T], -> { - className: T - where: WhereType - fields: Array - offset?: number - first?: number - context: WibeContext -} - -export type OutputType< - T extends keyof WibeAppTypes['types'], - K extends keyof WibeAppTypes['types'][T], -> = Pick & { id: string } - -export interface DatabaseAdapter { - connect(): Promise - close(): Promise - - createClassIfNotExist( - className: string, - context: WibeContext, - ): Promise - - clearDatabase(): Promise - - count< - T extends keyof WibeAppTypes['types'], - K extends keyof WibeAppTypes['types'][T], - >(params: CountOptions): Promise - - getObject< - T extends keyof WibeAppTypes['types'], - K extends keyof WibeAppTypes['types'][T], - >(params: GetObjectOptions): Promise> - getObjects< - T extends keyof WibeAppTypes['types'], - K extends keyof WibeAppTypes['types'][T], - W extends keyof WibeAppTypes['types'][T], - >(params: GetObjectsOptions): Promise[]> - - createObject< - T extends keyof WibeAppTypes['types'], - K extends keyof WibeAppTypes['types'][T], - W extends keyof WibeAppTypes['types'][T], - >(params: CreateObjectOptions): Promise> - createObjects< - T extends keyof WibeAppTypes['types'], - K extends keyof WibeAppTypes['types'][T], - W extends keyof WibeAppTypes['types'][T], - >(params: CreateObjectsOptions): Promise[]> - - updateObject< - T extends keyof WibeAppTypes['types'], - K extends keyof WibeAppTypes['types'][T], - W extends keyof WibeAppTypes['types'][T], - >(params: UpdateObjectOptions): Promise> - updateObjects< - T extends keyof WibeAppTypes['types'], - K extends keyof WibeAppTypes['types'][T], - W extends keyof WibeAppTypes['types'][T], - >(params: UpdateObjectsOptions): Promise[]> - - deleteObject< - T extends keyof WibeAppTypes['types'], - K extends keyof WibeAppTypes['types'][T], - W extends keyof WibeAppTypes['types'][T], - >(params: DeleteObjectOptions): Promise - deleteObjects< - T extends keyof WibeAppTypes['types'], - K extends keyof WibeAppTypes['types'][T], - W extends keyof WibeAppTypes['types'][T], - >(params: DeleteObjectsOptions): Promise -} diff --git a/packages/wibe-server/src/files/devAdapter.ts b/packages/wibe-server/src/files/devAdapter.ts deleted file mode 100644 index f6ccc180..00000000 --- a/packages/wibe-server/src/files/devAdapter.ts +++ /dev/null @@ -1,3 +0,0 @@ -import type { WibeFileAdapter } from '.' - -export const fileDevAdapter: WibeFileAdapter = async (file: File) => file.name diff --git a/packages/wibe-server/src/schema/resolvers/meResolver.ts b/packages/wibe-server/src/schema/resolvers/meResolver.ts deleted file mode 100644 index 4a77aec9..00000000 --- a/packages/wibe-server/src/schema/resolvers/meResolver.ts +++ /dev/null @@ -1,12 +0,0 @@ -import type { WibeContext } from '../../server/interface' -import type { DevWibeAppTypes } from '../../utils/helper' - -export const meResolver = async ( - _: any, - __: any, - context: WibeContext, -) => { - return { - user: context.user, - } -} diff --git a/packages/wibe-server/src/server/interface.ts b/packages/wibe-server/src/server/interface.ts deleted file mode 100644 index 51b9ecdb..00000000 --- a/packages/wibe-server/src/server/interface.ts +++ /dev/null @@ -1,11 +0,0 @@ -import type { WobeResponse } from 'wobe' -import type { WibeApp, WibeAppTypes } from '.' -import type { User } from '../../generated/wibe' - -export interface WibeContext { - response?: WobeResponse - user?: User | null - sessionId?: string - isRoot: boolean - wibeApp: WibeApp -}