Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial rewrite with nuxt-first approach #273

Draft
wants to merge 43 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e0bb1db
chore: remove unneded deps
sandros94 Aug 24, 2024
7aad419
chore: update all deps
sandros94 Aug 24, 2024
7132e5b
chore: update nuxt/module-builder
sandros94 Aug 24, 2024
bb762a5
chore: update playground package.json
sandros94 Aug 24, 2024
445e8f2
chore(docs): remove pnpm-lock
sandros94 Aug 24, 2024
db0e565
chore: regenerate workspace pnpm-lock
sandros94 Aug 24, 2024
2245bff
feat!: init nuxt-first rewrite
sandros94 Aug 24, 2024
f7bd998
feat: query params
sandros94 Aug 24, 2024
b81230e
feat: global query parameters
sandros94 Aug 25, 2024
a39c100
chore: handle nuxt/image after main rewrite
sandros94 Sep 3, 2024
2ba37d5
fix: missing fetchOptions in $readItem
sandros94 Sep 3, 2024
ec42d5c
fix: $directusFetch and param types
sandros94 Sep 3, 2024
e1d5e2e
chore: update playground
sandros94 Sep 3, 2024
66d2cd4
up
sandros94 Sep 3, 2024
6abac20
feat: add missing useDirectusItems functions
sandros94 Sep 3, 2024
5415764
fix: explicit return type
sandros94 Sep 3, 2024
bb5c866
fix: update url constructor
sandros94 Sep 3, 2024
fb7151e
chore: various type improvements
sandros94 Sep 3, 2024
cfe9955
up
sandros94 Sep 3, 2024
89575cc
up
sandros94 Sep 3, 2024
4f56564
feat: useDirectusCollections
sandros94 Sep 3, 2024
636db49
feat: useDirectusNotifications
sandros94 Sep 13, 2024
e77f3c9
up
sandros94 Sep 13, 2024
db03eea
chore: rename alias
sandros94 Sep 13, 2024
23ed436
refactor: file names and types location
sandros94 Sep 13, 2024
d2320bd
fix: useDirectusItems types
sandros94 Sep 13, 2024
df9cd69
fix: streamline types and utils
sandros94 Sep 13, 2024
5661feb
fix: useDirectusNotifications
sandros94 Sep 13, 2024
3a46551
fix: useDirectusCollections
sandros94 Sep 13, 2024
ef31610
up
sandros94 Sep 13, 2024
f4d73e3
feat: add useDirectusActivity
sandros94 Sep 13, 2024
da7e14d
fix: useDirectusNotifications
sandros94 Sep 13, 2024
9d0eab9
feat: add useDirectusRevisions
sandros94 Sep 13, 2024
ef133f8
refactor: useDirectusFetch
sandros94 Sep 13, 2024
47c58c2
feat: add useDirectusTranslations
sandros94 Sep 13, 2024
513e37b
fix: check directus url
sandros94 Sep 17, 2024
d2f4403
fix: staticToken
sandros94 Oct 2, 2024
5214ac7
fix: missing export for new composables
sandros94 Oct 2, 2024
f9ace35
feat: add useDirectusVersions
sandros94 Oct 2, 2024
16635fd
feat: add useDirectusFetch server util
sandros94 Oct 2, 2024
1154389
feat: public and private static tokens
sandros94 Oct 2, 2024
9c50692
fix: make sure to only export composable's types
sandros94 Oct 2, 2024
b071787
fix: update useDirectusTokens
sandros94 Oct 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9,997 changes: 0 additions & 9,997 deletions docs/pnpm-lock.yaml

This file was deleted.

30 changes: 13 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,23 @@
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@directus/sdk": "^16.1.1",
"@nuxt/devtools-kit": "^1.3.9",
"@nuxt/image": "^1.7.0",
"@nuxt/kit": "^3.12.3",
"@vueuse/core": "^10.11.0",
"ws": "^8.18.0"
"@nuxt/devtools-kit": "^1.3.14",
"@nuxt/kit": "^3.13.0",
"@vueuse/core": "^10.11.1"
},
"devDependencies": {
"@nuxt/devtools": "^1.3.9",
"@nuxt/devtools": "^1.3.14",
"@nuxt/eslint-config": "^0.3.13",
"@nuxt/module-builder": "^0.8.1",
"@nuxt/schema": "^3.12.3",
"@types/node": "^20.14.10",
"@types/ws": "^8.5.11",
"@nuxt/module-builder": "0.8.3",
"@nuxt/schema": "^3.13.0",
"@types/node": "^20.16.1",
"changelogen": "^0.5.5",
"eslint": "^9.5.0",
"nuxt": "^3.12.3",
"eslint": "^9.9.1",
"nuxt": "^3.13.0",
"ohash": "^1.1.3",
"typescript": "^5.4.5",
"ufo": "^1.5.3",
"vue-tsc": "^2.0.26"
"typescript": "^5.5.4",
"ufo": "^1.5.4",
"vue-tsc": "2.0.26"
},
"keywords": [
"nuxt",
Expand All @@ -81,7 +77,7 @@
],
"resolutions": {
"nuxt-directus-next": "workspace:*",
"@nuxt/module-builder": "0.8.1",
"@nuxt/module-builder": "0.8.3",
"vue-tsc": "2.0.26"
},
"packageManager": "[email protected]"
Expand Down
4 changes: 2 additions & 2 deletions playground/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NUXT_PUBLIC_DIRECTUS_STATIC_TOKEN = 3VHNEkyyZvsEoNNgGkdFNZApvK_Bj11v # API-Public
NUXT_PUBLIC_DIRECTUS_URL = http://localhost:8055/
# NUXT_PUBLIC_DIRECTUS_STATIC_TOKEN = 3VHNEkyyZvsEoNNgGkdFNZApvK_Bj11v # API-Public
NUXT_PUBLIC_DIRECTUS_URL = https://directus.pizza/
36 changes: 2 additions & 34 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export default defineNuxtConfig({
ssr: true,

alias: {
'nuxt-directus': '../src/module',
},
Expand All @@ -9,42 +10,9 @@ export default defineNuxtConfig({
authConfig: {
refreshTokenCookieName: 'nuxt-directus_refresh_token',
},
moduleConfig: {
devtools: true,
autoRefresh: {
enableMiddleware: false,
redirectTo: '/login',
to: ['/restricted'],
},
readMeQuery: {
fields: ['id', 'email', 'first_name', 'last_name', 'avatar', 'status'],
},
nuxtImage: {
useAuthToken: false,
useStaticToken: true,
},
},
},

image: {
providers: {
nuxtDirectus: {
options: {
maxAge: 2592000,
modifiers: {
withoutEnlargement: 'true',
transforms: [['blur', 4], ['negate']],
},
},
},
},
},

devtools: { enabled: true },
routeRules: {
'/restricted/**': {
ssr: false,
},
},

compatibilityDate: '2024-07-14',
})
18 changes: 8 additions & 10 deletions playground/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
{
"name": "playground",
"version": "1.0.0",
"description": "",
"main": "index.js",
"private": true,
"name": "nuxt-direcuts-playground",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"dev": "nuxi dev",
"build": "nuxi build",
"generate": "nuxi generate"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"dependencies": {
"nuxt-directus-next": "latest",
"@nuxt/devtools": "^1.3.9"
"nuxt": "^3.13.0"
}
}
147 changes: 7 additions & 140 deletions playground/pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,144 +1,11 @@
<template>
<div>
<div v-if="!!global">
<h1>{{ global.title }}</h1>
<p>{{ global.description }}</p>
</div>
<hr>
<div>
<div v-if="user">
<NuxtLink to="/restricted">
Restricted Area
</NuxtLink>,
<button @click="logout()">
Logout
</button>
</div>
<div v-else>
<NuxtLink to="/restricted">
Restricted Area
</NuxtLink>,
<button @click="navigateTo('/login')">
Login
</button>
</div>
</div>
<hr>
<div>
<h1>Posts</h1>
<button @click="refreshPosts()">
Refresh posts
</button>
<div>
List Posts
<ul style="width: fit-content;">
<li v-for="post in posts" :key="post.id">
<div>
<span
style="width: 100%; display: inline-flex; justify-content: space-between; gap: 1rem; align-items: center;"
>
<h3>{{ post.title }}</h3>
<sub>{{ post.status }}</sub>
</span>
<div>
<sub>{{ post.slug }} | {{ post.id }}</sub>
<p>{{ post.content }}</p>
</div>
</div>
</li>
</ul>
</div>
<div v-if="user" style="display: inline-flex; gap: 4rem;">
<div>
<h3>New Post</h3>
<div>
<input v-model="postNewData.title" type="text" placeholder="Post title">
<input v-model="postNewData.slug" type="text" placeholder="Post slug">
<br>
<textarea v-model="postNewData.content" placeholder="Post content" />
<br>
<label for="newPostStatus">Status</label>
<select id="newPostStatus" v-model="postNewData.status">
<option value="draft">
Draft
</option>
<option value="published">
Published
</option>
<option value="archived">
Archived
</option>
</select>
<button @click="createContent()">
Create Post
</button>
</div>
</div>
<div>
<h3>Update or Delete a Post</h3>
<div>
<div v-for="post in posts" :key="post.id">
<input
:id="`${post.id}`"
v-model="postId"
type="radio"
:value="post.id"
>
<label :for="`${post.id}`">{{ post.title }}</label>
</div>
<input v-model="postUpdateData.title" type="text" placeholder="Post title">
<input v-model="postUpdateData.slug" type="text" placeholder="Post slug">
<br>
<textarea v-model="postUpdateData.content" placeholder="Post content" />
<button @click="updateContent()">
Update Post
</button>
<button @click="deleteItem('posts', postId).then(() => refreshPosts())">
Delete Post
</button>
</div>
</div>
</div>
</div>
<ul>
<li>
<NuxtLink to="/items">
useDirectusItems
</NuxtLink>
</li>
</ul>
</div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import type { Post, Schema } from '../types'
import { navigateTo, useDirectusAuth, useDirectusUsers, useDirectusItems } from '#imports'

const { logout } = useDirectusAuth()
const { user } = useDirectusUsers()

const { createItem, readAsyncItems, readAsyncSingleton, updateItem, deleteItem } = useDirectusItems<Schema>()

const { data: global } = await readAsyncSingleton('global')
const { data: posts, refresh: refreshPosts, error: postsError } = await readAsyncItems('posts', {
query: {
fields: ['title', 'id', 'slug', 'content', 'status'],
},
watch: [user],
key: 'posts',
})
if (!posts.value && postsError.value) {
console.error('Posts fetch error:', postsError.value)
}

const postNewData = ref<Partial<Post>>({
status: 'draft',
})

async function createContent() {
await createItem('posts', postNewData.value)
refreshPosts()
}

const postId = ref<Post['id']>(posts.value?.[0].id || '')
const postUpdateData = ref<Partial<Post>>({})

async function updateContent() {
await updateItem('posts', postId.value, postUpdateData.value)
refreshPosts()
}
</script>
61 changes: 61 additions & 0 deletions playground/pages/items.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<template>
<div>
<div>
<label>
Collection:<br>
<input v-model="collection" type="text">
</label>
<br>
<label>
Search:<br>
<input v-model="search" type="search">
</label>
<br>
<label>
Limit:<br>
<input
v-model="limit"
type="range"
min="-1"
max="10"
step="1"
>
</label>
</div>
<div>
<pre>
{{ data }}
</pre>
</div>
</div>
</template>

<script setup lang="ts">
import { useDirectusItems } from '#imports'

interface Page {
date_created: Date
date_updated: Date
id: string
seo: string
sort: number | null
status: 'published' | 'draft' | 'archived'
title: string
user_created: string
user_updated: string
permalink: string
blocks: string[] | Record<string, unknown>[]
}

const { readItems } = useDirectusItems()
const collection = ref('pages')
const search = ref('')
const limit = ref(-1)

const { data } = await readItems<Page[]>(collection, {
fields: ['id', 'title', 'permalink'],
search,
limit,
watch: [limit, search],
})
</script>
39 changes: 0 additions & 39 deletions playground/pages/login.vue

This file was deleted.

Loading