Compare commits
59 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1bec7a703d | |||
| 0b575fa322 | |||
| 4c5a0345a8 | |||
| ea7c7b02d6 | |||
| 9296ae7d78 | |||
| 549b2f30be | |||
| 4bc07425b4 | |||
| b0fb2edc24 | |||
| 9b63877eaa | |||
| ba845931da | |||
| 3d7503e227 | |||
| c570597d06 | |||
| e7c7beb8fd | |||
| 037920620e | |||
| 0f73464afe | |||
| 5bf554fbdf | |||
| b566196c96 | |||
| 4da24986ee | |||
| ced2c77427 | |||
| 431d3784fe | |||
| 033380e051 | |||
| 0db6bddbc4 | |||
| 0dfad07399 | |||
| e6b8b7d0fa | |||
| 0cdba0d764 | |||
| 9c0e0baf95 | |||
| 925d382f2f | |||
| 3ff97569f5 | |||
| 52a5ae9180 | |||
| 4647fbda16 | |||
| 647d26db85 | |||
| 40b8ca91ee | |||
| d92a58b2ad | |||
| 5a43ebe06f | |||
| 56259adaf7 | |||
| 470f272183 | |||
| e2d37c2efe | |||
| 487cca530b | |||
| 9e867fc0b3 | |||
| 23ec1989f7 | |||
| 1c3608743e | |||
| 33bb3cc550 | |||
| fe1807fcd5 | |||
| aaef56cb29 | |||
| 32846c1e44 | |||
| 771e071005 | |||
| 2ba8bdadfc | |||
| 6c057d4cd7 | |||
| 00259fc865 | |||
| 3356ffd052 | |||
| 6ca94dc574 | |||
| 182b760404 | |||
| 66c08e5d52 | |||
| 774d4b6243 | |||
| 86c3c2954e | |||
| 205435e546 | |||
| cf48c2b6df | |||
| ac24680bd4 | |||
| d381058591 |
@ -1,2 +1,5 @@
|
|||||||
dist
|
dist
|
||||||
node_modules
|
node_modules
|
||||||
|
docs
|
||||||
|
.github
|
||||||
|
.vscode
|
||||||
|
|||||||
1
.github/FUNDING.yml
vendored
Normal file
1
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
github: [arashsheyda]
|
||||||
82
.github/workflows/studio.yml
vendored
Normal file
82
.github/workflows/studio.yml
vendored
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
|
||||||
|
name: studio-nuxt-build
|
||||||
|
run-name: studio nuxt build
|
||||||
|
|
||||||
|
on:
|
||||||
|
# Runs on pushes targeting the default branch
|
||||||
|
push:
|
||||||
|
branches: ["main"]
|
||||||
|
|
||||||
|
# Allows you to run this workflow manually from the Actions tab
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
# Add write workflow permissions
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
# Allow one concurrent deployment
|
||||||
|
concurrency:
|
||||||
|
group: "pages"
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
# Build job
|
||||||
|
build-and-deploy:
|
||||||
|
if: startsWith(github.event.head_commit.message, 'docs:')
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: docs
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest]
|
||||||
|
node: [18]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Identify package manager
|
||||||
|
id: pkgman
|
||||||
|
run: |
|
||||||
|
cache=`[ -f "docs/pnpm-lock.yaml" ] && echo "pnpm" || ([ -f "docs/package-lock.json" ] && echo "npm" || ([ -f "docs/yarn.lock" ] && echo "yarn" || echo ""))`
|
||||||
|
package_manager=`[ ! -z "$cache" ] && echo "$cache" || echo "pnpm"`
|
||||||
|
echo "cache=$cache" >> $GITHUB_OUTPUT
|
||||||
|
echo "package_manager=$package_manager" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- uses: pnpm/action-setup@v2.2.4
|
||||||
|
if: ${{ steps.pkgman.outputs.package_manager == 'pnpm' }}
|
||||||
|
name: Install pnpm
|
||||||
|
id: pnpm-install
|
||||||
|
with:
|
||||||
|
version: 7
|
||||||
|
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
version: ${{ matrix.node }}
|
||||||
|
cache: ${{ steps.pkgman.outputs.cache }}
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: ${{ steps.pkgman.outputs.package_manager }} install --no-frozen-lockfile
|
||||||
|
|
||||||
|
- name: Install @nuxthq/studio
|
||||||
|
run: ${{ steps.pkgman.outputs.package_manager }} add -D @nuxthq/studio
|
||||||
|
|
||||||
|
- name: Create .nuxtrc
|
||||||
|
run: echo 'modules[]=@nuxthq/studio' > .nuxtrc
|
||||||
|
|
||||||
|
- name: Generate
|
||||||
|
run: ${{ steps.pkgman.outputs.package_manager }} nuxi generate
|
||||||
|
env:
|
||||||
|
NUXT_PUBLIC_STUDIO_API_URL: https://api.nuxt.studio
|
||||||
|
NUXT_PUBLIC_STUDIO_TOKENS: 6222c5e49391ad99e20e3c1b1a475c656436e8b0877c32021147d8727205c440
|
||||||
|
|
||||||
|
- name: Add .nojekyll file
|
||||||
|
run: touch .output/public/.nojekyll
|
||||||
|
|
||||||
|
# Deployment job
|
||||||
|
- name: Deploy 🚀
|
||||||
|
uses: JamesIves/github-pages-deploy-action@v4
|
||||||
|
with:
|
||||||
|
folder: docs/.output/public
|
||||||
16
.vscode/settings.json
vendored
16
.vscode/settings.json
vendored
@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
"editor.tabSize": 2,
|
|
||||||
"files.exclude": {
|
|
||||||
"**/.git": true,
|
|
||||||
"**/.svn": true,
|
|
||||||
"**/.hg": true,
|
|
||||||
"**/CVS": true,
|
|
||||||
"**/.DS_Store": true,
|
|
||||||
"**/Thumbs.db": true,
|
|
||||||
"**/node_modules": true,
|
|
||||||
"**/.nuxt": true,
|
|
||||||
"**/.output": true,
|
|
||||||
"**/dist": true,
|
|
||||||
"**/.nuxtrc": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
157
CHANGELOG.md
157
CHANGELOG.md
@ -1,6 +1,163 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
|
||||||
|
## v1.0.2
|
||||||
|
|
||||||
|
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v1.0.1...v1.0.2)
|
||||||
|
|
||||||
|
### 🩹 Fixes
|
||||||
|
|
||||||
|
- Resolve build stuck issue with nitro pre-render enabled ([#26](https://github.com/arashsheyda/nuxt-mongoose/pull/26))
|
||||||
|
|
||||||
|
### 📖 Documentation
|
||||||
|
|
||||||
|
- Default connection ([e7c7beb](https://github.com/arashsheyda/nuxt-mongoose/commit/e7c7beb))
|
||||||
|
|
||||||
|
### 🏡 Chore
|
||||||
|
|
||||||
|
- **release:** V1.0.2 ([ba8459](https://github.com/arashsheyda/nuxt-mongoose/commit/ba8459))
|
||||||
|
- Lint ([3d7503e](https://github.com/arashsheyda/nuxt-mongoose/commit/3d7503e))
|
||||||
|
|
||||||
|
### ❤️ Contributors
|
||||||
|
|
||||||
|
- Arash Sheyda <sheidaeearash1999@gmail.com>
|
||||||
|
- Arash
|
||||||
|
|
||||||
|
## v1.0.1
|
||||||
|
|
||||||
|
### 🏡 Chore
|
||||||
|
|
||||||
|
- **release:** V1.0.0 ([b566196](https://github.com/arashsheyda/nuxt-mongoose/commit/b566196))
|
||||||
|
- **release:** V1.0.1 ([5bf554f](https://github.com/arashsheyda/nuxt-mongoose/commit/5bf554f))
|
||||||
|
- Update dependencies ([0f73464](https://github.com/arashsheyda/nuxt-mongoose/commit/0f73464))
|
||||||
|
|
||||||
|
### ❤️ Contributors
|
||||||
|
|
||||||
|
- Arash Sheyda <sheidaeearash1999@gmail.com>
|
||||||
|
|
||||||
|
## v1.0.0
|
||||||
|
|
||||||
|
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v0.0.9...v1.0.0)
|
||||||
|
|
||||||
|
### 🚀 Enhancements
|
||||||
|
|
||||||
|
- Version 1.0.0 ([#21](https://github.com/arashsheyda/nuxt-mongoose/pull/21))
|
||||||
|
|
||||||
|
### 📖 Documentation
|
||||||
|
|
||||||
|
- Update docus ([0db6bdd](https://github.com/arashsheyda/nuxt-mongoose/commit/0db6bdd))
|
||||||
|
|
||||||
|
### ❤️ Contributors
|
||||||
|
|
||||||
|
- Arashsheyda <sheidaeearash1999@gmail.com>
|
||||||
|
|
||||||
|
## v0.0.9
|
||||||
|
|
||||||
|
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v0.0.8...v0.0.9)
|
||||||
|
|
||||||
|
### 🚀 Enhancements
|
||||||
|
|
||||||
|
- Add possibility to type mongoose model ([#8](https://github.com/arashsheyda/nuxt-mongoose/pull/8))
|
||||||
|
- Mongoose schema hooks ([d92a58b](https://github.com/arashsheyda/nuxt-mongoose/commit/d92a58b))
|
||||||
|
|
||||||
|
### 🩹 Fixes
|
||||||
|
|
||||||
|
- Update connection message in logger ([#10](https://github.com/arashsheyda/nuxt-mongoose/pull/10))
|
||||||
|
|
||||||
|
### 📖 Documentation
|
||||||
|
|
||||||
|
- **utils:** Add hooks and improve documentation ([647d26d](https://github.com/arashsheyda/nuxt-mongoose/commit/647d26d))
|
||||||
|
- **utils:** Fix model options type ([3ff9756](https://github.com/arashsheyda/nuxt-mongoose/commit/3ff9756))
|
||||||
|
- Add types link ([9c0e0ba](https://github.com/arashsheyda/nuxt-mongoose/commit/9c0e0ba))
|
||||||
|
|
||||||
|
### 🏡 Chore
|
||||||
|
|
||||||
|
- Fix defineNitroPlugin patch ([#9](https://github.com/arashsheyda/nuxt-mongoose/pull/9))
|
||||||
|
- Example env ([40b8ca9](https://github.com/arashsheyda/nuxt-mongoose/commit/40b8ca9))
|
||||||
|
- Fix defineNitroPlugin patch " ([#9](https://github.com/arashsheyda/nuxt-mongoose/pull/9))
|
||||||
|
- Update dependencies ([925d382](https://github.com/arashsheyda/nuxt-mongoose/commit/925d382))
|
||||||
|
- Lint ([0cdba0d](https://github.com/arashsheyda/nuxt-mongoose/commit/0cdba0d))
|
||||||
|
- Fix tsconfig for build time ([e6b8b7d](https://github.com/arashsheyda/nuxt-mongoose/commit/e6b8b7d))
|
||||||
|
|
||||||
|
### ❤️ Contributors
|
||||||
|
|
||||||
|
- Arash Sheyda <sheidaeearash1999@gmail.com>
|
||||||
|
- Amir-al-mohamad111
|
||||||
|
- Oumar Barry ([@oumarbarry](http://github.com/oumarbarry))
|
||||||
|
|
||||||
|
## v0.0.8
|
||||||
|
|
||||||
|
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v0.0.7...v0.0.8)
|
||||||
|
|
||||||
|
|
||||||
|
### 🚀 Enhancements
|
||||||
|
|
||||||
|
- Documentation ([6ca94dc](https://github.com/arashsheyda/nuxt-mongoose/commit/6ca94dc))
|
||||||
|
|
||||||
|
### 🩹 Fixes
|
||||||
|
|
||||||
|
- Module options type ([182b760](https://github.com/arashsheyda/nuxt-mongoose/commit/182b760))
|
||||||
|
- Run studio action only for docs ([33bb3cc](https://github.com/arashsheyda/nuxt-mongoose/commit/33bb3cc))
|
||||||
|
- Resource generator modelsDir output ([1c36087](https://github.com/arashsheyda/nuxt-mongoose/commit/1c36087))
|
||||||
|
|
||||||
|
### 💅 Refactors
|
||||||
|
|
||||||
|
- Reuse vite's websocket ([aaef56c](https://github.com/arashsheyda/nuxt-mongoose/commit/aaef56c))
|
||||||
|
|
||||||
|
### 📖 Documentation
|
||||||
|
|
||||||
|
- Remove devtools ([6c057d4](https://github.com/arashsheyda/nuxt-mongoose/commit/6c057d4))
|
||||||
|
- **devtools:** Demo video ([2ba8bda](https://github.com/arashsheyda/nuxt-mongoose/commit/2ba8bda))
|
||||||
|
- Style ([23ec198](https://github.com/arashsheyda/nuxt-mongoose/commit/23ec198))
|
||||||
|
- Favicon ([9e867fc](https://github.com/arashsheyda/nuxt-mongoose/commit/9e867fc))
|
||||||
|
|
||||||
|
### 🏡 Chore
|
||||||
|
|
||||||
|
- Playground example ([3356ffd](https://github.com/arashsheyda/nuxt-mongoose/commit/3356ffd))
|
||||||
|
- **deployment:** Add workflow file ([00259fc](https://github.com/arashsheyda/nuxt-mongoose/commit/00259fc))
|
||||||
|
- Update cover ([487cca5](https://github.com/arashsheyda/nuxt-mongoose/commit/487cca5))
|
||||||
|
|
||||||
|
### ❤️ Contributors
|
||||||
|
|
||||||
|
- Arash
|
||||||
|
- Arash Sheyda <sheidaeearash1999@gmail.com>
|
||||||
|
- Arashsheyda <sheidaeearash1999@gmail.com>
|
||||||
|
|
||||||
|
## v0.0.7
|
||||||
|
|
||||||
|
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v0.0.6...v0.0.7)
|
||||||
|
|
||||||
|
|
||||||
|
### 🚀 Enhancements
|
||||||
|
|
||||||
|
- Auto-import schema files ([205435e](https://github.com/arashsheyda/nuxt-mongoose/commit/205435e))
|
||||||
|
|
||||||
|
### 🩹 Fixes
|
||||||
|
|
||||||
|
- Mongoose config ([cf48c2b](https://github.com/arashsheyda/nuxt-mongoose/commit/cf48c2b))
|
||||||
|
|
||||||
|
### 🏡 Chore
|
||||||
|
|
||||||
|
- Improve logger message ([86c3c29](https://github.com/arashsheyda/nuxt-mongoose/commit/86c3c29))
|
||||||
|
- Update dependencies ([774d4b6](https://github.com/arashsheyda/nuxt-mongoose/commit/774d4b6))
|
||||||
|
|
||||||
|
### ❤️ Contributors
|
||||||
|
|
||||||
|
- Arashsheyda <sheidaeearash1999@gmail.com>
|
||||||
|
|
||||||
|
## v0.0.6
|
||||||
|
|
||||||
|
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v0.0.5...v0.0.6)
|
||||||
|
|
||||||
|
|
||||||
|
### 🩹 Fixes
|
||||||
|
|
||||||
|
- Remove useMongoose composable ([d381058](https://github.com/arashsheyda/nuxt-mongoose/commit/d381058))
|
||||||
|
|
||||||
|
### ❤️ Contributors
|
||||||
|
|
||||||
|
- Arashsheyda <sheidaeearash1999@gmail.com>
|
||||||
|
|
||||||
## v0.0.5
|
## v0.0.5
|
||||||
|
|
||||||
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v0.0.4...v0.0.5)
|
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v0.0.4...v0.0.5)
|
||||||
|
|||||||
16
README.md
16
README.md
@ -1,4 +1,4 @@
|
|||||||

|

|
||||||
|
|
||||||
<div align="center">
|
<div align="center">
|
||||||
<h1>Nuxt Mongoose</h1>
|
<h1>Nuxt Mongoose</h1>
|
||||||
@ -36,10 +36,13 @@ export default defineNuxtConfig({
|
|||||||
mongoose: {
|
mongoose: {
|
||||||
uri: 'process.env.MONGODB_URI',
|
uri: 'process.env.MONGODB_URI',
|
||||||
options: {},
|
options: {},
|
||||||
|
modelsDir: 'models',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
by default, `nuxt-mongoose` will auto-import your schemas from the `models` directory from `server` directory. You can change this behavior by setting the `modelsDir` option.
|
||||||
|
|
||||||
* for more information about the options, please refer to the [Mongoose documentation](https://mongoosejs.com/docs/connections.html#options). *
|
* for more information about the options, please refer to the [Mongoose documentation](https://mongoosejs.com/docs/connections.html#options). *
|
||||||
|
|
||||||
## API
|
## API
|
||||||
@ -83,17 +86,6 @@ export const User = defineMongooseModel({
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
### useMongoose
|
|
||||||
|
|
||||||
This composable returns the Mongoose DB instance. Example usage:
|
|
||||||
|
|
||||||
```vue
|
|
||||||
<script lang="ts" setup>
|
|
||||||
const mongoose = useMongoose()
|
|
||||||
const user = await mongoose.db.collection('users').findOne()
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
[MIT License](./LICENSE)
|
[MIT License](./LICENSE)
|
||||||
|
|||||||
@ -1,24 +0,0 @@
|
|||||||
import { defineBuildConfig } from 'unbuild'
|
|
||||||
|
|
||||||
export default defineBuildConfig({
|
|
||||||
entries: [
|
|
||||||
'src/module',
|
|
||||||
// Chunking
|
|
||||||
'src/types',
|
|
||||||
],
|
|
||||||
externals: [
|
|
||||||
'nuxt',
|
|
||||||
'nuxt/schema',
|
|
||||||
'vite',
|
|
||||||
'@nuxt/kit',
|
|
||||||
'@nuxt/schema',
|
|
||||||
// Type only
|
|
||||||
'vue',
|
|
||||||
'vue-router',
|
|
||||||
'unstorage',
|
|
||||||
'nitropack',
|
|
||||||
],
|
|
||||||
rollup: {
|
|
||||||
inlineDependencies: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
@ -1,7 +1,3 @@
|
|||||||
<script lang="ts" setup>
|
|
||||||
import './styles/global.css'
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Html>
|
<Html>
|
||||||
<Body h-screen>
|
<Body h-screen>
|
||||||
|
|||||||
@ -1,33 +1,53 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
defineProps({
|
import { computed } from 'vue'
|
||||||
connection: {
|
|
||||||
|
const props = defineProps({
|
||||||
|
code: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 0,
|
default: 0,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const connections = [
|
||||||
|
{
|
||||||
|
color: 'text-red-5',
|
||||||
|
border: 'border-red-5',
|
||||||
|
status: 'Not Connected',
|
||||||
|
description: 'Please Check Your Connection!',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: 'text-green-5',
|
||||||
|
border: 'border-green-5',
|
||||||
|
status: 'Connected',
|
||||||
|
description: 'Everything is Working Perfectly!',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: 'text-yellow-5',
|
||||||
|
border: 'border-yellow-5',
|
||||||
|
status: 'Connecting',
|
||||||
|
description: 'Just a Moment, We"re Getting There!',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: 'text-orange-5',
|
||||||
|
border: 'border-orange-5',
|
||||||
|
status: 'Disconnecting',
|
||||||
|
description: 'Preparing to Safely Disconnect!',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
const connection = computed(() => connections[props.code])
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<NPanelGrids>
|
<NPanelGrids>
|
||||||
<div flex="~ gap-2" animate-pulse items-center text-yellow>
|
<div flex="~ gap-2" animate-pulse items-center text-lg font-bold :class="connection.color">
|
||||||
<NIcon icon="carbon-flow-connection" />
|
({{ code }}):
|
||||||
Please check your mongodb connection
|
{{ connection.status }},
|
||||||
</div>
|
{{ connection.description }}
|
||||||
<div flex="~ gap-2" items-center text-light>
|
|
||||||
Your current connection is: {{ connection }}
|
|
||||||
</div>
|
</div>
|
||||||
<div absolute bottom-10 left-10 right-10 flex justify-around>
|
<div absolute bottom-10 left-10 right-10 flex justify-around>
|
||||||
<NCard p2 text-red-5>
|
<NCard v-for="item, index of connections" :key="index" p2 :class="[item.color, item.status === connection.status ? item.border : '']">
|
||||||
0: Not connected
|
({{ index }}): {{ item.status }}
|
||||||
</NCard>
|
|
||||||
<NCard p2 text-green-5>
|
|
||||||
1: Connected
|
|
||||||
</NCard>
|
|
||||||
<NCard p2 text-yellow-5>
|
|
||||||
2: Connecting
|
|
||||||
</NCard>
|
|
||||||
<NCard p2 text-orange-5>
|
|
||||||
3: Disconnecting
|
|
||||||
</NCard>
|
</NCard>
|
||||||
</div>
|
</div>
|
||||||
</NPanelGrids>
|
</NPanelGrids>
|
||||||
|
|||||||
@ -1,4 +1,8 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import { useRouter } from 'nuxt/app'
|
||||||
|
import { computed, reactive, ref } from 'vue'
|
||||||
|
import { rpc } from '../composables/rpc'
|
||||||
|
|
||||||
interface ColumnInterface {
|
interface ColumnInterface {
|
||||||
name: string
|
name: string
|
||||||
type: string
|
type: string
|
||||||
@ -115,18 +119,16 @@ const convertedBread = computed(() => {
|
|||||||
const formattedFields = computed(() => {
|
const formattedFields = computed(() => {
|
||||||
return fields.value.map((field) => {
|
return fields.value.map((field) => {
|
||||||
for (const [key, value] of Object.entries(field)) {
|
for (const [key, value] of Object.entries(field)) {
|
||||||
if (!value) {
|
if (!value)
|
||||||
// @ts-expect-error - no need for type checking
|
|
||||||
delete field[key]
|
delete field[key]
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return field
|
return field
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
async function generate() {
|
async function generate() {
|
||||||
await rpc.generateResource(
|
await rpc.value?.generateResource(
|
||||||
{
|
{
|
||||||
name: collection.value,
|
name: collection.value,
|
||||||
fields: schema.value ? formattedFields.value : undefined,
|
fields: schema.value ? formattedFields.value : undefined,
|
||||||
@ -142,6 +144,7 @@ async function generate() {
|
|||||||
const toggleSchema = computed({
|
const toggleSchema = computed({
|
||||||
get() {
|
get() {
|
||||||
if (hasBread.value)
|
if (hasBread.value)
|
||||||
|
// eslint-disable-next-line vue/no-side-effects-in-computed-properties
|
||||||
return schema.value = true
|
return schema.value = true
|
||||||
return schema.value
|
return schema.value
|
||||||
},
|
},
|
||||||
@ -246,8 +249,8 @@ const toggleSchema = computed({
|
|||||||
<NTextInput v-else v-model="column.default" n="orange" />
|
<NTextInput v-else v-model="column.default" n="orange" />
|
||||||
</div>
|
</div>
|
||||||
<div flex justify-center gap2>
|
<div flex justify-center gap2>
|
||||||
<NIconButton icon="carbon-add" n="cyan" @click="addField(index)" />
|
<NButton icon="carbon-add" n="cyan" @click="addField(index)" />
|
||||||
<NIconButton icon="carbon-delete" n="red" @click="removeField(index)" />
|
<NButton icon="carbon-trash-can" n="red" @click="removeField(index)" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -257,5 +260,3 @@ const toggleSchema = computed({
|
|||||||
</NButton>
|
</NButton>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style></style>
|
|
||||||
|
|||||||
@ -1,4 +1,9 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import { computed, reactive, ref, watch } from 'vue'
|
||||||
|
import { computedAsync } from '@vueuse/core'
|
||||||
|
import { rpc } from '../composables/rpc'
|
||||||
|
import { useCopy } from '../composables/editor'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
collection: {
|
collection: {
|
||||||
type: String,
|
type: String,
|
||||||
@ -10,19 +15,19 @@ const props = defineProps({
|
|||||||
const pagination = reactive({ limit: 20, page: 1 })
|
const pagination = reactive({ limit: 20, page: 1 })
|
||||||
|
|
||||||
const countDocuments = computedAsync(async () => {
|
const countDocuments = computedAsync(async () => {
|
||||||
return await rpc.countDocuments(props.collection)
|
return await rpc.value?.countDocuments(props.collection)
|
||||||
})
|
})
|
||||||
|
|
||||||
const documents = computedAsync(async () => {
|
const documents = computedAsync(async () => {
|
||||||
return await rpc.listDocuments(props.collection, pagination)
|
return await rpc.value?.listDocuments(props.collection, pagination)
|
||||||
})
|
})
|
||||||
|
|
||||||
watch(pagination, async () => {
|
watch(pagination, async () => {
|
||||||
documents.value = await rpc.listDocuments(props.collection, pagination)
|
documents.value = await rpc.value?.listDocuments(props.collection, pagination)
|
||||||
})
|
})
|
||||||
|
|
||||||
const schema = computedAsync<any>(async () => {
|
const schema = computedAsync<any>(async () => {
|
||||||
return await rpc.resourceSchema(props.collection)
|
return await rpc.value?.resourceSchema(props.collection)
|
||||||
})
|
})
|
||||||
|
|
||||||
const fields = computed(() => {
|
const fields = computed(() => {
|
||||||
@ -79,14 +84,17 @@ function editDocument(document: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function saveDocument(document: any, create = true) {
|
async function saveDocument(document: any, create = true) {
|
||||||
const method = create ? rpc.createDocument : rpc.updateDocument
|
const method = create ? rpc.value?.createDocument : rpc.value?.updateDocument
|
||||||
|
if (!method)
|
||||||
|
return
|
||||||
const newDocument = await method(props.collection, document)
|
const newDocument = await method(props.collection, document)
|
||||||
|
// TODO: show toast
|
||||||
if (newDocument?.error)
|
if (newDocument?.error)
|
||||||
return alert(newDocument.error.message)
|
return
|
||||||
|
|
||||||
if (create) {
|
if (create) {
|
||||||
if (!documents.value.length) {
|
if (!documents.value.length) {
|
||||||
documents.value = await rpc.listDocuments(props.collection, pagination)
|
documents.value = await rpc.value?.listDocuments(props.collection, pagination)
|
||||||
return discardEditing()
|
return discardEditing()
|
||||||
}
|
}
|
||||||
documents.value.push({ _id: newDocument.insertedId, ...document })
|
documents.value.push({ _id: newDocument.insertedId, ...document })
|
||||||
@ -104,9 +112,10 @@ function discardEditing() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function deleteDocument(document: any) {
|
async function deleteDocument(document: any) {
|
||||||
const newDocument = await rpc.deleteDocument(props.collection, document._id)
|
const newDocument = await rpc.value?.deleteDocument(props.collection, document._id)
|
||||||
|
// TODO: show toast
|
||||||
if (newDocument.deletedCount === 0)
|
if (newDocument.deletedCount === 0)
|
||||||
return alert('Failed to delete document')
|
return
|
||||||
|
|
||||||
documents.value = documents.value.filter((doc: any) => doc._id !== document._id)
|
documents.value = documents.value.filter((doc: any) => doc._id !== document._id)
|
||||||
}
|
}
|
||||||
@ -116,7 +125,7 @@ const copy = useCopy()
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div ref="dbContainer" :class="{ 'h-full': !documents?.length }">
|
<div ref="dbContainer" :class="{ 'h-full': !documents?.length }">
|
||||||
<Navbar v-model:search="search" sticky top-0 px4 py2 backdrop-blur z-10>
|
<NNavbar v-model:search="search" sticky top-0 px4 py2 backdrop-blur z-10>
|
||||||
<template #actions>
|
<template #actions>
|
||||||
<NButton icon="carbon:add" n="green" @click="addDocument">
|
<NButton icon="carbon:add" n="green" @click="addDocument">
|
||||||
Add Document
|
Add Document
|
||||||
@ -146,7 +155,7 @@ const copy = useCopy()
|
|||||||
</NSelect>
|
</NSelect>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Navbar>
|
</NNavbar>
|
||||||
<table v-if="documents?.length || selectedDocument" w-full mb10 :class="{ 'editing-mode': editing }">
|
<table v-if="documents?.length || selectedDocument" w-full mb10 :class="{ 'editing-mode': editing }">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -168,17 +177,17 @@ const copy = useCopy()
|
|||||||
{{ document[field] }}
|
{{ document[field] }}
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="actions">
|
<td>
|
||||||
<div flex justify-center gap2 class="group">
|
<div flex justify-center gap2 class="group">
|
||||||
<template v-if="editing && selectedDocument._id === document._id">
|
<template v-if="editing && selectedDocument._id === document._id">
|
||||||
<NIconButton icon="carbon-save" @click="saveDocument(selectedDocument, false)" />
|
<NButton title="Save" icon="carbon-save" n="blue" @click="saveDocument(selectedDocument, false)" />
|
||||||
<NIconButton icon="carbon-close" @click="discardEditing" />
|
<NButton title="Cancel" icon="carbon-close" n="red" @click="discardEditing" />
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<NIconButton icon="carbon-edit" @click="editDocument(document)" />
|
<NButton title="Edit" icon="carbon-edit" n="blue" @click="editDocument(document)" />
|
||||||
<NIconButton icon="carbon-delete" @click="deleteDocument(document)" />
|
<NButton title="Delete" icon="carbon-trash-can" n="red" @click="deleteDocument(document)" />
|
||||||
<NIconButton icon="carbon-document-multiple-02" @click="saveDocument(document)" />
|
<NButton title="Duplicate" icon="carbon-document-multiple-02" n="cyan" @click="saveDocument(document)" />
|
||||||
<NIconButton absolute right-4 opacity-0 group-hover="opacity-100" transition-all icon="carbon-copy" @click="copy(JSON.stringify(document))" />
|
<NButton title="Copy" n="xs purple" absolute right-4 opacity-0 group-hover="opacity-100" transition-all icon="carbon-copy" @click="copy(JSON.stringify(document))" />
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
@ -188,14 +197,14 @@ const copy = useCopy()
|
|||||||
<input v-if="field !== '_id'" v-model="selectedDocument[field]" :placeholder="field">
|
<input v-if="field !== '_id'" v-model="selectedDocument[field]" :placeholder="field">
|
||||||
<input v-else placeholder="ObjectId(_id)" disabled>
|
<input v-else placeholder="ObjectId(_id)" disabled>
|
||||||
</td>
|
</td>
|
||||||
<td flex justify-center gap2 class="actions">
|
<td flex="~ justify-center gap2">
|
||||||
<NIconButton icon="carbon-save" @click="saveDocument(selectedDocument)" />
|
<NButton title="Save" icon="carbon-save" n="green" @click="saveDocument(selectedDocument)" />
|
||||||
<NIconButton icon="carbon-close" @click="discardEditing" />
|
<NButton title="Cancel" icon="carbon-close" n="red" @click="discardEditing" />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<div v-else flex justify-center items-center h-full text-2xl>
|
<div v-else flex="~ justify-center items-center" h-full text-2xl>
|
||||||
<NIcon icon="carbon-document" mr1 />
|
<NIcon icon="carbon-document" mr1 />
|
||||||
No documents found
|
No documents found
|
||||||
</div>
|
</div>
|
||||||
@ -203,11 +212,6 @@ const copy = useCopy()
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
// TODO:
|
|
||||||
.actions .n-icon {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
table {
|
table {
|
||||||
table-layout: fixed;
|
table-layout: fixed;
|
||||||
tr {
|
tr {
|
||||||
|
|||||||
@ -1,54 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
const props = defineProps<{
|
|
||||||
modelValue?: boolean
|
|
||||||
navbar?: HTMLElement
|
|
||||||
autoClose?: boolean
|
|
||||||
}>()
|
|
||||||
|
|
||||||
const emit = defineEmits<{
|
|
||||||
(e: 'close'): void
|
|
||||||
}>()
|
|
||||||
|
|
||||||
const el = ref<HTMLElement>()
|
|
||||||
|
|
||||||
const { height: top } = useElementSize(() => props.navbar, undefined, { box: 'border-box' })
|
|
||||||
|
|
||||||
onClickOutside(el, () => {
|
|
||||||
if (props.modelValue && props.autoClose)
|
|
||||||
emit('close')
|
|
||||||
}, {
|
|
||||||
ignore: ['#open-drawer-right'],
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
export default {
|
|
||||||
inheritAttrs: false,
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<Transition
|
|
||||||
enter-active-class="duration-200 ease-in"
|
|
||||||
enter-from-class="transform translate-x-1/1"
|
|
||||||
enter-to-class="opacity-100"
|
|
||||||
leave-active-class="duration-200 ease-out"
|
|
||||||
leave-from-class="opacity-100"
|
|
||||||
leave-to-class="transform translate-x-1/1"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
v-if="modelValue"
|
|
||||||
ref="el"
|
|
||||||
border="l base"
|
|
||||||
flex="~ col gap-1"
|
|
||||||
fixed bottom-0 right-0 z-10 z-20 of-auto text-sm backdrop-blur-lg
|
|
||||||
:style="{ top: `${top}px` }"
|
|
||||||
v-bind="$attrs"
|
|
||||||
>
|
|
||||||
<NIconButton absolute right-2 top-2 z-20 text-xl icon="carbon-close" @click="$emit('close')" />
|
|
||||||
<div relative h-full w-full of-auto>
|
|
||||||
<slot />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Transition>
|
|
||||||
</template>
|
|
||||||
@ -1,43 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
defineProps({
|
|
||||||
search: {
|
|
||||||
type: String,
|
|
||||||
default: undefined,
|
|
||||||
},
|
|
||||||
noPadding: {
|
|
||||||
type: Boolean,
|
|
||||||
default: true,
|
|
||||||
},
|
|
||||||
placeholder: {
|
|
||||||
type: String,
|
|
||||||
default: 'Search...',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const emit = defineEmits<{
|
|
||||||
(event: 'update:search', value: string): void
|
|
||||||
}>()
|
|
||||||
|
|
||||||
function update(event: any) {
|
|
||||||
emit('update:search', event.target.value)
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div flex="~ col gap2" border="b base" flex-1 navbar-glass :class="[{ p4: !noPadding }]">
|
|
||||||
<div flex="~ gap4">
|
|
||||||
<slot name="search">
|
|
||||||
<NTextInput
|
|
||||||
:placeholder="placeholder"
|
|
||||||
icon="carbon-search"
|
|
||||||
n="primary" flex-auto
|
|
||||||
:class="{ 'px-5 py-2': !noPadding }"
|
|
||||||
:value="search"
|
|
||||||
@input="update"
|
|
||||||
/>
|
|
||||||
</slot>
|
|
||||||
<slot name="actions" />
|
|
||||||
</div>
|
|
||||||
<slot />
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
@ -1,36 +0,0 @@
|
|||||||
<script lang="ts" setup>
|
|
||||||
import { Pane, Splitpanes } from 'splitpanes'
|
|
||||||
import 'splitpanes/dist/splitpanes.css'
|
|
||||||
|
|
||||||
const props = defineProps({
|
|
||||||
minLeft: {
|
|
||||||
type: Number,
|
|
||||||
default: 10,
|
|
||||||
},
|
|
||||||
minRight: {
|
|
||||||
type: Number,
|
|
||||||
default: 10,
|
|
||||||
},
|
|
||||||
maxLeft: {
|
|
||||||
type: Number,
|
|
||||||
default: 90,
|
|
||||||
},
|
|
||||||
maxRight: {
|
|
||||||
type: Number,
|
|
||||||
default: 90,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const size = ref(props.maxLeft)
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<Splitpanes h-full of-hidden @resize="size = $event[0].size">
|
|
||||||
<Pane border="r base" h-full class="of-auto!" :size="size" :min-size="minLeft" :max-size="maxLeft">
|
|
||||||
<slot name="left" />
|
|
||||||
</Pane>
|
|
||||||
<Pane relative h-full class="of-auto!" :min-size="minRight">
|
|
||||||
<slot name="right" />
|
|
||||||
</Pane>
|
|
||||||
</Splitpanes>
|
|
||||||
</template>
|
|
||||||
@ -1,10 +1,14 @@
|
|||||||
import { useClipboard } from '@vueuse/core'
|
import { useClipboard } from '@vueuse/core'
|
||||||
|
// import { } from '@nuxt/devtools-ui-kit'
|
||||||
|
|
||||||
export function useCopy() {
|
export function useCopy() {
|
||||||
const clipboard = useClipboard()
|
const clipboard = useClipboard()
|
||||||
|
|
||||||
return (text: string) => {
|
return (text: string) => {
|
||||||
clipboard.copy(text)
|
clipboard.copy(text)
|
||||||
// TODO: show toast
|
// devtoolsUiShowNotification({
|
||||||
|
// message: 'Copied to clipboard',
|
||||||
|
// icon: 'carbon-copy',
|
||||||
|
// })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,69 +1,18 @@
|
|||||||
import { createBirpc } from 'birpc'
|
import { onDevtoolsClientConnected } from '@nuxt/devtools-kit/iframe-client'
|
||||||
import { parse, stringify } from 'flatted'
|
import type { BirpcReturn } from 'birpc'
|
||||||
|
import { ref } from 'vue'
|
||||||
|
import type { NuxtDevtoolsClient } from '@nuxt/devtools-kit/dist/types'
|
||||||
import type { ClientFunctions, ServerFunctions } from '../../src/types'
|
import type { ClientFunctions, ServerFunctions } from '../../src/types'
|
||||||
import { PATH_ENTRY } from '../../src/constants'
|
import { RPC_NAMESPACE } from '../../src/constants'
|
||||||
|
|
||||||
const RECONNECT_INTERVAL = 2000
|
export const devtools = ref<NuxtDevtoolsClient>()
|
||||||
|
export const devtoolsRpc = ref<NuxtDevtoolsClient['rpc']>()
|
||||||
|
export const rpc = ref<BirpcReturn<ServerFunctions, ClientFunctions>>()
|
||||||
|
|
||||||
export const wsConnecting = ref(true)
|
onDevtoolsClientConnected(async (client) => {
|
||||||
export const wsError = ref<any>()
|
devtoolsRpc.value = client.devtools.rpc
|
||||||
|
devtools.value = client.devtools
|
||||||
|
|
||||||
let connectPromise = connectWS()
|
rpc.value = client.devtools.extendClientRpc<ServerFunctions, ClientFunctions>(RPC_NAMESPACE, {
|
||||||
let onMessage: Function = () => {}
|
|
||||||
|
|
||||||
export const clientFunctions = {
|
|
||||||
// will be added in app.vue
|
|
||||||
} as ClientFunctions
|
|
||||||
|
|
||||||
export const extendedRpcMap = new Map<string, any>()
|
|
||||||
|
|
||||||
export const rpc = createBirpc<ServerFunctions>(clientFunctions, {
|
|
||||||
post: async (d) => {
|
|
||||||
(await connectPromise).send(d)
|
|
||||||
},
|
|
||||||
on: (fn) => { onMessage = fn },
|
|
||||||
serialize: stringify,
|
|
||||||
deserialize: parse,
|
|
||||||
resolver(name, fn) {
|
|
||||||
if (fn)
|
|
||||||
return fn
|
|
||||||
if (!name.includes(':'))
|
|
||||||
return
|
|
||||||
const [namespace, fnName] = name.split(':')
|
|
||||||
return extendedRpcMap.get(namespace)?.[fnName]
|
|
||||||
},
|
|
||||||
onError(error, name) {
|
|
||||||
console.error(`[nuxt-devtools] RPC error on executing "${name}":`, error)
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
async function connectWS() {
|
|
||||||
const wsUrl = new URL(`ws://host${PATH_ENTRY}`)
|
|
||||||
wsUrl.protocol = location.protocol === 'https:' ? 'wss:' : 'ws:'
|
|
||||||
wsUrl.host = 'localhost:3000'
|
|
||||||
|
|
||||||
const ws = new WebSocket(wsUrl.toString())
|
|
||||||
ws.addEventListener('message', e => onMessage(String(e.data)))
|
|
||||||
ws.addEventListener('error', (e) => {
|
|
||||||
console.error(e)
|
|
||||||
wsError.value = e
|
|
||||||
})
|
})
|
||||||
ws.addEventListener('close', () => {
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log('[nuxt-devtools] WebSocket closed, reconnecting...')
|
|
||||||
wsConnecting.value = true
|
|
||||||
setTimeout(async () => {
|
|
||||||
connectPromise = connectWS()
|
|
||||||
}, RECONNECT_INTERVAL)
|
|
||||||
})
|
|
||||||
wsConnecting.value = true
|
|
||||||
if (ws.readyState !== WebSocket.OPEN)
|
|
||||||
await new Promise(resolve => ws.addEventListener('open', resolve))
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log('[nuxt-devtools] WebSocket connected.')
|
|
||||||
wsConnecting.value = false
|
|
||||||
wsError.value = null
|
|
||||||
|
|
||||||
return ws
|
|
||||||
}
|
|
||||||
|
|||||||
1
client/composables/state.ts
Normal file
1
client/composables/state.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export const selectedCollection = useState('mongo:collection', () => '')
|
||||||
@ -1,10 +1,13 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
const readyState = computedAsync(async () => await rpc.readyState())
|
import { computedAsync } from '@vueuse/core'
|
||||||
|
import { rpc } from '../composables/rpc'
|
||||||
|
|
||||||
|
const readyState = computedAsync(async () => await rpc.value?.readyState())
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div h-full of-auto>
|
<div h-full of-auto>
|
||||||
<slot v-if="readyState === 1" />
|
<slot v-if="readyState === 1" />
|
||||||
<Connection v-else :connection="readyState" />
|
<Connection v-else :code="readyState" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { resolve } from 'pathe'
|
import { resolve } from 'pathe'
|
||||||
import { PATH_CLIENT } from '../src/constants'
|
import { CLIENT_PATH } from '../src/constants'
|
||||||
|
|
||||||
export default defineNuxtConfig({
|
export default defineNuxtConfig({
|
||||||
ssr: false,
|
ssr: false,
|
||||||
@ -22,6 +22,6 @@ export default defineNuxtConfig({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
app: {
|
app: {
|
||||||
baseURL: PATH_CLIENT,
|
baseURL: CLIENT_PATH,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,13 +1,17 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
const route = useRoute()
|
import { computed, ref } from 'vue'
|
||||||
|
import { computedAsync } from '@vueuse/core'
|
||||||
|
import { useRouter } from 'nuxt/app'
|
||||||
|
import { rpc } from '../composables/rpc'
|
||||||
|
import { selectedCollection } from '../composables/state'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
const selectedCollection = ref()
|
|
||||||
const drawer = ref(false)
|
const drawer = ref(false)
|
||||||
const search = ref('')
|
const search = ref('')
|
||||||
|
|
||||||
const collections = computedAsync(async () => {
|
const collections = computedAsync(async () => {
|
||||||
return await rpc.listCollections()
|
return await rpc.value?.listCollections()
|
||||||
})
|
})
|
||||||
|
|
||||||
const filtered = computed(() => {
|
const filtered = computed(() => {
|
||||||
@ -16,46 +20,48 @@ const filtered = computed(() => {
|
|||||||
return collections.value.filter((c: any) => c.name.toLowerCase().includes(search.value.toLowerCase()))
|
return collections.value.filter((c: any) => c.name.toLowerCase().includes(search.value.toLowerCase()))
|
||||||
})
|
})
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
if (route.query.table)
|
|
||||||
selectedCollection.value = route.query.table
|
|
||||||
})
|
|
||||||
|
|
||||||
async function dropCollection(table: any) {
|
async function dropCollection(table: any) {
|
||||||
await rpc.dropCollection(table.name)
|
await rpc.value?.dropCollection(table.name)
|
||||||
collections.value = await rpc.listCollections()
|
collections.value = await rpc.value?.listCollections()
|
||||||
if (selectedCollection.value === table.name) {
|
if (selectedCollection.value === table.name) {
|
||||||
selectedCollection.value = undefined
|
selectedCollection.value = ''
|
||||||
router.push({ name: 'index' })
|
router.push({ name: 'index' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function refresh() {
|
async function refresh() {
|
||||||
collections.value = await rpc.listCollections()
|
collections.value = await rpc.value?.listCollections()
|
||||||
drawer.value = false
|
drawer.value = false
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<PanelLeftRight :min-left="13" :max-left="20">
|
<NSplitPane :min-left="13" :max-left="20">
|
||||||
<template #left>
|
<template #left>
|
||||||
<div px4>
|
<div px4>
|
||||||
<Navbar v-model:search="search" :placeholder="`${collections?.length ?? '-'} collection in total`" mt2>
|
<NNavbar v-model:search="search" :placeholder="`${collections?.length ?? '-'} collection in total`" mt2 no-padding>
|
||||||
<div flex items-center gap2>
|
<div flex items-center gap2>
|
||||||
<NIconButton w-full mb1.5 icon="carbon-reset" title="Refresh" @click="refresh" />
|
<NButton n="blue" w-full mb1.5 icon="carbon-reset" title="Refresh" @click="refresh" />
|
||||||
<NIconButton w-full mb1.5 icon="carbon-data-base" title="Default" text-green-5 />
|
<!-- <NButton w-full mb1.5 icon="carbon-data-base" title="Default" n="green" /> -->
|
||||||
<NIconButton id="open-drawer-right" w-full mb1.5 icon="carbon-add" title="Create Collection" @click="drawer = true" />
|
<NButton n="green" w-full mb1.5 icon="carbon-add" title="Create Collection" @click="drawer = true" />
|
||||||
</div>
|
</div>
|
||||||
</Navbar>
|
</NNavbar>
|
||||||
<div grid gird-cols-1 my2 mx1>
|
<div grid gird-cols-1 my2 mx1>
|
||||||
<NuxtLink v-for="table in filtered" :key="table.name" :to="{ name: 'index', query: { table: table.name } }" flex justify-between p2 my1 hover-bg-green hover-bg-opacity-5 hover-text-green rounded-lg :class="{ 'bg-green bg-opacity-5 text-green': selectedCollection === table.name }" @click="selectedCollection = table.name">
|
<NuxtLink
|
||||||
|
v-for="table in filtered"
|
||||||
|
:key="table.name"
|
||||||
|
:to="{ name: 'index', query: { table: table.name } }"
|
||||||
|
flex items-center justify-between p2 my1 hover-bg-green hover-bg-opacity-5 hover-text-green rounded-lg
|
||||||
|
:class="{ 'bg-green bg-opacity-5 text-green': selectedCollection === table.name }"
|
||||||
|
@click="selectedCollection = table.name"
|
||||||
|
>
|
||||||
<span>
|
<span>
|
||||||
<NIcon icon="carbon-db2-database" />
|
<NIcon icon="carbon-db2-database" />
|
||||||
{{ table.name }}
|
{{ table.name }}
|
||||||
</span>
|
</span>
|
||||||
<div flex gap2>
|
<div flex="~ items-center gap-2">
|
||||||
<NIconButton block n="red" icon="carbon-delete" @click="dropCollection(table)" />
|
<NButton :border="false" n="red" icon="carbon-trash-can" @click="dropCollection(table)" />
|
||||||
<!-- <NIconButton icon="carbon-overflow-menu-horizontal" /> -->
|
<!-- <NButton :border="false" icon="carbon-overflow-menu-horizontal" /> -->
|
||||||
</div>
|
</div>
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</div>
|
</div>
|
||||||
@ -72,8 +78,8 @@ async function refresh() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</PanelLeftRight>
|
</NSplitPane>
|
||||||
<DrawerRight v-model="drawer" style="width: calc(80.5%);" auto-close @close="drawer = false">
|
<NDrawer v-model="drawer" style="width: calc(80.5%);" auto-close @close="drawer = false" z-20>
|
||||||
<CreateResource @refresh="refresh" />
|
<CreateResource @refresh="refresh" />
|
||||||
</DrawerRight>
|
</NDrawer>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
21
client/splitpanes.d.ts
vendored
21
client/splitpanes.d.ts
vendored
@ -1,21 +0,0 @@
|
|||||||
// TODO install @types/splitpanes once updated
|
|
||||||
declare module 'splitpanes' {
|
|
||||||
import { Component } from 'vue'
|
|
||||||
|
|
||||||
export interface SplitpaneProps {
|
|
||||||
horizontal: boolean
|
|
||||||
pushOtherPanes: boolean
|
|
||||||
dblClickSplitter: boolean
|
|
||||||
firstSplitter: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PaneProps {
|
|
||||||
size: number | string
|
|
||||||
minSize: number | string
|
|
||||||
maxSize: number | string
|
|
||||||
}
|
|
||||||
|
|
||||||
export type Pane = Component<PaneProps>
|
|
||||||
export const Pane: Pane
|
|
||||||
export const Splitpanes: Component<SplitpaneProps>
|
|
||||||
}
|
|
||||||
@ -1,35 +0,0 @@
|
|||||||
/* Splitpanes */
|
|
||||||
.splitpanes__splitter {
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
.splitpanes__splitter:before {
|
|
||||||
position: absolute;
|
|
||||||
left: 0;
|
|
||||||
top: 0;
|
|
||||||
transition: .2s ease;
|
|
||||||
content: '';
|
|
||||||
transition: opacity 0.4s;
|
|
||||||
z-index: 1;
|
|
||||||
}
|
|
||||||
.splitpanes__splitter:hover:before {
|
|
||||||
background: #8881;
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
.splitpanes--vertical>.splitpanes__splitter {
|
|
||||||
min-width: 0 !important;
|
|
||||||
width: 0 !important;
|
|
||||||
}
|
|
||||||
.splitpanes--horizontal>.splitpanes__splitter {
|
|
||||||
min-height: 0 !important;
|
|
||||||
height: 0 !important;
|
|
||||||
}
|
|
||||||
.splitpanes--vertical>.splitpanes__splitter:before {
|
|
||||||
left: -5px;
|
|
||||||
right: -4px;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
.splitpanes--horizontal>.splitpanes__splitter:before {
|
|
||||||
top: -5px;
|
|
||||||
bottom: -4px;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
12
docs/.gitignore
vendored
Normal file
12
docs/.gitignore
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
node_modules
|
||||||
|
*.iml
|
||||||
|
.idea
|
||||||
|
*.log*
|
||||||
|
.nuxt
|
||||||
|
.vscode
|
||||||
|
.DS_Store
|
||||||
|
coverage
|
||||||
|
dist
|
||||||
|
sw.*
|
||||||
|
.env
|
||||||
|
.output
|
||||||
2
docs/.npmrc
Normal file
2
docs/.npmrc
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
shamefully-hoist=true
|
||||||
|
strict-peer-dependencies=false
|
||||||
36
docs/app.config.ts
Normal file
36
docs/app.config.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
export default defineAppConfig({
|
||||||
|
docus: {
|
||||||
|
title: 'Nuxt Mongoose',
|
||||||
|
description: 'A Nuxt module for simplifying the use of Mongoose in your project.',
|
||||||
|
image: '/cover.jpg',
|
||||||
|
socials: {
|
||||||
|
twitter: 'arash_sheyda',
|
||||||
|
github: 'arashsheyda/nuxt-mongoose',
|
||||||
|
},
|
||||||
|
github: {
|
||||||
|
dir: 'docs/content',
|
||||||
|
branch: 'main',
|
||||||
|
repo: 'nuxt-mongoose',
|
||||||
|
owner: 'arashsheyda',
|
||||||
|
edit: true,
|
||||||
|
},
|
||||||
|
aside: {
|
||||||
|
level: 1,
|
||||||
|
collapsed: false,
|
||||||
|
exclude: [],
|
||||||
|
},
|
||||||
|
header: {
|
||||||
|
logo: true,
|
||||||
|
showLinkIcon: true,
|
||||||
|
exclude: [],
|
||||||
|
},
|
||||||
|
footer: {
|
||||||
|
iconLinks: [
|
||||||
|
{
|
||||||
|
href: 'https://nuxt.com',
|
||||||
|
icon: 'simple-icons:nuxtdotjs',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
295
docs/components/content/Illustration.vue
Normal file
295
docs/components/content/Illustration.vue
Normal file
@ -0,0 +1,295 @@
|
|||||||
|
<template>
|
||||||
|
<svg
|
||||||
|
width="403"
|
||||||
|
height="226"
|
||||||
|
viewBox="0 0 403 226"
|
||||||
|
fill="none"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
>
|
||||||
|
<g clip-path="url(#clip0_1180_138)">
|
||||||
|
<g opacity="0.54">
|
||||||
|
<path
|
||||||
|
d="M0 12C0 5.37259 5.37258 0 12 0H391C397.627 0 403 5.37258 403 12V214C403 220.627 397.627 226 391 226H12C5.37259 226 0 220.627 0 214V12Z"
|
||||||
|
fill="url(#paint0_linear_1180_138)"
|
||||||
|
fill-opacity="0.3"
|
||||||
|
/>
|
||||||
|
<path
|
||||||
|
d="M12 0.5H391C397.351 0.5 402.5 5.64873 402.5 12V214C402.5 220.351 397.351 225.5 391 225.5H12C5.64873 225.5 0.5 220.351 0.5 214V12C0.5 5.64873 5.64873 0.5 12 0.5Z"
|
||||||
|
stroke="url(#paint1_linear_1180_138)"
|
||||||
|
stroke-opacity="0.4"
|
||||||
|
/>
|
||||||
|
</g>
|
||||||
|
<path
|
||||||
|
opacity="0.54"
|
||||||
|
d="M49.7811 28H57.5876C57.8356 28 58.0792 27.9354 58.2939 27.8125C58.5086 27.6896 58.6869 27.5128 58.8108 27.3C58.9347 27.0871 58.9999 26.8457 58.9998 26.5999C58.9997 26.3542 58.9343 26.1128 58.8102 25.9001L53.5676 16.9001C53.4437 16.6873 53.2654 16.5105 53.0507 16.3877C52.836 16.2648 52.5925 16.2001 52.3446 16.2001C52.0967 16.2001 51.8532 16.2648 51.6385 16.3877C51.4238 16.5105 51.2455 16.6873 51.1216 16.9001L49.7811 19.2028L47.1602 14.6998C47.0361 14.487 46.8578 14.3104 46.6431 14.1875C46.4283 14.0647 46.1847 14 45.9368 14C45.6889 14 45.4453 14.0647 45.2305 14.1875C45.0158 14.3104 44.8375 14.487 44.7134 14.6998L38.1896 25.9001C38.0655 26.1128 38.0001 26.3542 38 26.5999C37.9999 26.8457 38.0651 27.0871 38.189 27.3C38.3129 27.5128 38.4912 27.6896 38.7059 27.8125C38.9207 27.9354 39.1643 28 39.4122 28H44.3125C46.254 28 47.6859 27.1547 48.6711 25.5057L51.063 21.4001L52.3442 19.2028L56.1893 25.8028H51.063L49.7811 28ZM44.2326 25.8005L40.8128 25.7998L45.9391 17.0004L48.4969 21.4001L46.7843 24.3407C46.13 25.4107 45.3867 25.8005 44.2326 25.8005Z"
|
||||||
|
fill="white"
|
||||||
|
fill-opacity="0.1"
|
||||||
|
/>
|
||||||
|
<line
|
||||||
|
opacity="0.54"
|
||||||
|
x1="43.5"
|
||||||
|
y1="75.5"
|
||||||
|
x2="84.5"
|
||||||
|
y2="75.5"
|
||||||
|
stroke="white"
|
||||||
|
stroke-opacity="0.1"
|
||||||
|
stroke-width="5"
|
||||||
|
stroke-linecap="round"
|
||||||
|
/>
|
||||||
|
<line
|
||||||
|
opacity="0.54"
|
||||||
|
x1="43.5"
|
||||||
|
y1="147.5"
|
||||||
|
x2="63.5"
|
||||||
|
y2="147.5"
|
||||||
|
stroke="white"
|
||||||
|
stroke-opacity="0.1"
|
||||||
|
stroke-width="5"
|
||||||
|
stroke-linecap="round"
|
||||||
|
/>
|
||||||
|
<line
|
||||||
|
opacity="0.54"
|
||||||
|
x1="172.5"
|
||||||
|
y1="147.5"
|
||||||
|
x2="192.899"
|
||||||
|
y2="147.5"
|
||||||
|
stroke="white"
|
||||||
|
stroke-opacity="0.1"
|
||||||
|
stroke-width="5"
|
||||||
|
stroke-linecap="round"
|
||||||
|
/>
|
||||||
|
<line
|
||||||
|
opacity="0.54"
|
||||||
|
x1="301.5"
|
||||||
|
y1="147.5"
|
||||||
|
x2="321.5"
|
||||||
|
y2="147.5"
|
||||||
|
stroke="white"
|
||||||
|
stroke-opacity="0.1"
|
||||||
|
stroke-width="5"
|
||||||
|
stroke-linecap="round"
|
||||||
|
/>
|
||||||
|
<line
|
||||||
|
opacity="0.54"
|
||||||
|
x1="143.5"
|
||||||
|
y1="20.5"
|
||||||
|
x2="167.5"
|
||||||
|
y2="20.5"
|
||||||
|
stroke="white"
|
||||||
|
stroke-opacity="0.1"
|
||||||
|
stroke-width="5"
|
||||||
|
stroke-linecap="round"
|
||||||
|
/>
|
||||||
|
<line
|
||||||
|
opacity="0.54"
|
||||||
|
x1="184.5"
|
||||||
|
y1="20.5"
|
||||||
|
x2="208.5"
|
||||||
|
y2="20.5"
|
||||||
|
stroke="white"
|
||||||
|
stroke-opacity="0.1"
|
||||||
|
stroke-width="5"
|
||||||
|
stroke-linecap="round"
|
||||||
|
/>
|
||||||
|
<line
|
||||||
|
opacity="0.54"
|
||||||
|
x1="225.5"
|
||||||
|
y1="20.5"
|
||||||
|
x2="249.5"
|
||||||
|
y2="20.5"
|
||||||
|
stroke="white"
|
||||||
|
stroke-opacity="0.1"
|
||||||
|
stroke-width="5"
|
||||||
|
stroke-linecap="round"
|
||||||
|
/>
|
||||||
|
<line
|
||||||
|
opacity="0.54"
|
||||||
|
x1="43.5"
|
||||||
|
y1="93.5"
|
||||||
|
x2="178.5"
|
||||||
|
y2="93.5"
|
||||||
|
stroke="white"
|
||||||
|
stroke-opacity="0.1"
|
||||||
|
stroke-width="5"
|
||||||
|
stroke-linecap="round"
|
||||||
|
/>
|
||||||
|
<line
|
||||||
|
opacity="0.54"
|
||||||
|
x1="43.5"
|
||||||
|
y1="162.5"
|
||||||
|
x2="115.544"
|
||||||
|
y2="162.5"
|
||||||
|
stroke="white"
|
||||||
|
stroke-opacity="0.1"
|
||||||
|
stroke-width="5"
|
||||||
|
stroke-linecap="round"
|
||||||
|
/>
|
||||||
|
<line
|
||||||
|
opacity="0.54"
|
||||||
|
x1="172.5"
|
||||||
|
y1="162.5"
|
||||||
|
x2="244.5"
|
||||||
|
y2="162.5"
|
||||||
|
stroke="white"
|
||||||
|
stroke-opacity="0.1"
|
||||||
|
stroke-width="5"
|
||||||
|
stroke-linecap="round"
|
||||||
|
/>
|
||||||
|
<line
|
||||||
|
opacity="0.54"
|
||||||
|
x1="301.5"
|
||||||
|
y1="162.5"
|
||||||
|
x2="373.5"
|
||||||
|
y2="162.5"
|
||||||
|
stroke="white"
|
||||||
|
stroke-opacity="0.1"
|
||||||
|
stroke-width="5"
|
||||||
|
stroke-linecap="round"
|
||||||
|
/>
|
||||||
|
<line
|
||||||
|
opacity="0.54"
|
||||||
|
x1="43.5"
|
||||||
|
y1="111.5"
|
||||||
|
x2="178.5"
|
||||||
|
y2="111.5"
|
||||||
|
stroke="white"
|
||||||
|
stroke-opacity="0.1"
|
||||||
|
stroke-width="5"
|
||||||
|
stroke-linecap="round"
|
||||||
|
/>
|
||||||
|
<line
|
||||||
|
opacity="0.54"
|
||||||
|
x1="43.5"
|
||||||
|
y1="177.5"
|
||||||
|
x2="115.5"
|
||||||
|
y2="177.5"
|
||||||
|
stroke="white"
|
||||||
|
stroke-opacity="0.1"
|
||||||
|
stroke-width="5"
|
||||||
|
stroke-linecap="round"
|
||||||
|
/>
|
||||||
|
<line
|
||||||
|
opacity="0.54"
|
||||||
|
x1="172.5"
|
||||||
|
y1="177.5"
|
||||||
|
x2="244.5"
|
||||||
|
y2="177.5"
|
||||||
|
stroke="white"
|
||||||
|
stroke-opacity="0.1"
|
||||||
|
stroke-width="5"
|
||||||
|
stroke-linecap="round"
|
||||||
|
/>
|
||||||
|
<line
|
||||||
|
opacity="0.54"
|
||||||
|
x1="301.5"
|
||||||
|
y1="177.5"
|
||||||
|
x2="373.5"
|
||||||
|
y2="177.5"
|
||||||
|
stroke="white"
|
||||||
|
stroke-opacity="0.1"
|
||||||
|
stroke-width="5"
|
||||||
|
stroke-linecap="round"
|
||||||
|
/>
|
||||||
|
<rect
|
||||||
|
opacity="0.54"
|
||||||
|
x="335.465"
|
||||||
|
y="17.619"
|
||||||
|
width="41.1089"
|
||||||
|
height="11.7454"
|
||||||
|
rx="2.93635"
|
||||||
|
fill="white"
|
||||||
|
fill-opacity="0.1"
|
||||||
|
/>
|
||||||
|
<rect
|
||||||
|
opacity="0.54"
|
||||||
|
x="212"
|
||||||
|
y="70"
|
||||||
|
width="164"
|
||||||
|
height="44"
|
||||||
|
rx="5"
|
||||||
|
fill="url(#paint2_linear_1180_138)"
|
||||||
|
fill-opacity="0.1"
|
||||||
|
/>
|
||||||
|
<!-- Mongo Logo -->
|
||||||
|
<g transform="translate(170, 80) scale(2)">
|
||||||
|
<rect width="32" height="32" rx="7.5" style="fill:#023430" />
|
||||||
|
<path d="M21.4,13.4C20.1,7.6,17.3,6.1,16.6,5a10.1,10.1,0,0,1-.7-1.5,1.6,1.6,0,0,1-.6,1.2,14.1,14.1,0,0,0-4.9,10.5c-.3,6.1,4.5,9.9,5.1,10.3a1.4,1.4,0,0,0,1.4-.2,12.1,12.1,0,0,0,4.5-11.9" style="fill:#10aa50" />
|
||||||
|
<path d="M16.1,22.2a17.8,17.8,0,0,1-.5,3.3s.2,1.5.3,3h.5a30.6,30.6,0,0,1,.5-3.2C16.3,25,16.1,23.6,16.1,22.2Z" style="fill:#b8c4c2" />
|
||||||
|
<path d="M16.9,25.3c-.6-.3-.8-1.7-.8-3.1s.2-4.3.1-6.5,0-10.7-.3-12.1L16.6,5c.7,1.1,3.5,2.6,4.8,8.4A12,12,0,0,1,16.9,25.3Z" style="fill:#12924f" />
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
<defs>
|
||||||
|
<filter
|
||||||
|
id="filter0_d_1180_138"
|
||||||
|
x="162.895"
|
||||||
|
y="74.8947"
|
||||||
|
width="76.2105"
|
||||||
|
height="76.2105"
|
||||||
|
filterUnits="userSpaceOnUse"
|
||||||
|
color-interpolation-filters="sRGB"
|
||||||
|
>
|
||||||
|
<feFlood flood-opacity="0" result="BackgroundImageFix" />
|
||||||
|
<feColorMatrix
|
||||||
|
in="SourceAlpha"
|
||||||
|
type="matrix"
|
||||||
|
values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"
|
||||||
|
result="hardAlpha"
|
||||||
|
/>
|
||||||
|
<feOffset dy="4" />
|
||||||
|
<feGaussianBlur stdDeviation="2" />
|
||||||
|
<feComposite in2="hardAlpha" operator="out" />
|
||||||
|
<feColorMatrix
|
||||||
|
type="matrix"
|
||||||
|
values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.44 0"
|
||||||
|
/>
|
||||||
|
<feBlend
|
||||||
|
mode="normal"
|
||||||
|
in2="BackgroundImageFix"
|
||||||
|
result="effect1_dropShadow_1180_138"
|
||||||
|
/>
|
||||||
|
<feBlend
|
||||||
|
mode="normal"
|
||||||
|
in="SourceGraphic"
|
||||||
|
in2="effect1_dropShadow_1180_138"
|
||||||
|
result="shape"
|
||||||
|
/>
|
||||||
|
</filter>
|
||||||
|
<linearGradient
|
||||||
|
id="paint0_linear_1180_138"
|
||||||
|
x1="201.5"
|
||||||
|
y1="0"
|
||||||
|
x2="201.5"
|
||||||
|
y2="102.822"
|
||||||
|
gradientUnits="userSpaceOnUse"
|
||||||
|
>
|
||||||
|
<stop stop-color="white" />
|
||||||
|
<stop offset="1" stop-color="white" stop-opacity="0" />
|
||||||
|
</linearGradient>
|
||||||
|
<linearGradient
|
||||||
|
id="paint1_linear_1180_138"
|
||||||
|
x1="201.5"
|
||||||
|
y1="-1.34109e-07"
|
||||||
|
x2="201.527"
|
||||||
|
y2="153.598"
|
||||||
|
gradientUnits="userSpaceOnUse"
|
||||||
|
>
|
||||||
|
<stop stop-color="white" />
|
||||||
|
<stop offset="1" stop-color="white" stop-opacity="0" />
|
||||||
|
</linearGradient>
|
||||||
|
<linearGradient
|
||||||
|
id="paint2_linear_1180_138"
|
||||||
|
x1="294"
|
||||||
|
y1="70"
|
||||||
|
x2="294"
|
||||||
|
y2="114"
|
||||||
|
gradientUnits="userSpaceOnUse"
|
||||||
|
>
|
||||||
|
<stop stop-color="white" />
|
||||||
|
<stop offset="1" stop-color="white" stop-opacity="0" />
|
||||||
|
</linearGradient>
|
||||||
|
<clipPath id="clip0_1180_138">
|
||||||
|
<rect width="403" height="226" fill="white" />
|
||||||
|
</clipPath>
|
||||||
|
</defs>
|
||||||
|
</svg>
|
||||||
|
</template>
|
||||||
18
docs/components/content/Logo.vue
Normal file
18
docs/components/content/Logo.vue
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<template>
|
||||||
|
<svg id="NuxtMongooseLogo" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 235.5 33.2">
|
||||||
|
<rect width="32" height="32" rx="7.5" style="fill:#023430" />
|
||||||
|
<path d="M21.4,13.4C20.1,7.6,17.3,6.1,16.6,5a10.1,10.1,0,0,1-.7-1.5,1.6,1.6,0,0,1-.6,1.2,14.1,14.1,0,0,0-4.9,10.5c-.3,6.1,4.5,9.9,5.1,10.3a1.4,1.4,0,0,0,1.4-.2,12.1,12.1,0,0,0,4.5-11.9" style="fill:#10aa50" />
|
||||||
|
<path d="M16.1,22.2a17.8,17.8,0,0,1-.5,3.3s.2,1.5.3,3h.5a30.6,30.6,0,0,1,.5-3.2C16.3,25,16.1,23.6,16.1,22.2Z" style="fill:#b8c4c2" />
|
||||||
|
<path d="M16.9,25.3c-.6-.3-.8-1.7-.8-3.1s.2-4.3.1-6.5,0-10.7-.3-12.1L16.6,5c.7,1.1,3.5,2.6,4.8,8.4A12,12,0,0,1,16.9,25.3Z" style="fill:#12924f" />
|
||||||
|
<text transform="translate(32.8 25.6)" style="font-size:25.818214416503906px;font-family:var(--font-sans);font-weight:700">
|
||||||
|
<tspan fill="currentColor" x="4" y="0">Nuxt</tspan>
|
||||||
|
<tspan x="67.8" y="0" style="fill:#10aa50">Mongoose</tspan>
|
||||||
|
</text>
|
||||||
|
</svg>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.NuxtMongooseLogo {
|
||||||
|
font-family: serif;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
78
docs/content/0.index.md
Normal file
78
docs/content/0.index.md
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
---
|
||||||
|
title: Home
|
||||||
|
navigation: false
|
||||||
|
layout: page
|
||||||
|
main:
|
||||||
|
fluid: false
|
||||||
|
---
|
||||||
|
|
||||||
|
:ellipsis{right=0px width=75% blur=150px}
|
||||||
|
|
||||||
|
::block-hero
|
||||||
|
---
|
||||||
|
cta:
|
||||||
|
- Get started
|
||||||
|
- /docs/getting-started/setup
|
||||||
|
secondary:
|
||||||
|
- Open on GitHub →
|
||||||
|
- https://github.com/arashsheyda/nuxt-mongoose
|
||||||
|
---
|
||||||
|
|
||||||
|
#title
|
||||||
|
Nuxt [Mongoose]{style="color: var(--color-primary-500)"}
|
||||||
|
|
||||||
|
#description
|
||||||
|
A Nuxt module for simplifying the use of [Mongoose](https://mongoosejs.com/) in your project.
|
||||||
|
|
||||||
|
#support
|
||||||
|
:illustration
|
||||||
|
::
|
||||||
|
|
||||||
|
::card-grid
|
||||||
|
#title
|
||||||
|
<h1 class="center">Elevate Your <br/> <span class=highlight> Developer Experience</span></h1>
|
||||||
|
|
||||||
|
#root
|
||||||
|
:ellipsis{left=15rem width=40rem top=10rem blur=140px}
|
||||||
|
|
||||||
|
#default
|
||||||
|
::card{icon=tabler:code}
|
||||||
|
#title
|
||||||
|
Nuxt DevTools Support
|
||||||
|
#description
|
||||||
|
Dive into your database with confidence. Benefit from Nuxt Devtools support, allowing you to inspect and debug your DB operations seamlessly.
|
||||||
|
::
|
||||||
|
|
||||||
|
::card{icon=tabler:cloud-bolt}
|
||||||
|
#title
|
||||||
|
Auto Connection
|
||||||
|
#description
|
||||||
|
Forget about manual connection hassles. This module seamlessly handles the connection to your Mongoose database, making setup a breeze.
|
||||||
|
::
|
||||||
|
|
||||||
|
::card{icon=tabler:plug}
|
||||||
|
#title
|
||||||
|
Extendable & hackable
|
||||||
|
#description
|
||||||
|
This module grants you access to the full spectrum of Mongoose functionalities. Leverage the power of Mongoose in your project.
|
||||||
|
::
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.highlight {
|
||||||
|
color: var(--color-primary-500);
|
||||||
|
}
|
||||||
|
|
||||||
|
.center {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.card svg {
|
||||||
|
height: 3rem!important;
|
||||||
|
width: 3rem!important;
|
||||||
|
}
|
||||||
|
.support {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
56
docs/content/1.docs/1.getting-started/1.setup.md
Normal file
56
docs/content/1.docs/1.getting-started/1.setup.md
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
# Setup
|
||||||
|
|
||||||
|
A Nuxt module for simplifying the use of Mongoose in your project.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
1. Install `nuxt-mongoose` to your dependencies.
|
||||||
|
|
||||||
|
::code-group
|
||||||
|
|
||||||
|
```bash [pnpm]
|
||||||
|
pnpm add nuxt-mongoose -D
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash [npm]
|
||||||
|
npm install nuxt-mongoose -D
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash [yarn]
|
||||||
|
yarn add nuxt-mongoose -D
|
||||||
|
```
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
2. Add `nuxt-mongoose` to the `modules` section of your `nuxt.config` file.
|
||||||
|
|
||||||
|
```ts [nuxt.config]
|
||||||
|
export default defineNuxtConfig({
|
||||||
|
modules: [
|
||||||
|
'nuxt-mongoose',
|
||||||
|
],
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
::alert{ type=success }
|
||||||
|
That's it! You can now use Mongoose in your Nuxt app ✨
|
||||||
|
::
|
||||||
|
|
||||||
|
|
||||||
|
## Options
|
||||||
|
|
||||||
|
You can configure the module by adding a `mongoose` section to your `nuxt.config` file.
|
||||||
|
read more about [Mongoose options](/docs/getting-started/configuration).
|
||||||
|
|
||||||
|
```ts [nuxt.config]
|
||||||
|
export default defineNuxtConfig({
|
||||||
|
mongoose: {
|
||||||
|
// Options
|
||||||
|
},
|
||||||
|
})
|
||||||
|
```
|
||||||
|
If you want to configure only the `uri` just add `MONGODB_URI` in your `.env` file.
|
||||||
|
|
||||||
|
```env
|
||||||
|
MONGODB_URI=YOUR_MONGO_URI
|
||||||
|
```
|
||||||
21
docs/content/1.docs/1.getting-started/2.configuration.md
Normal file
21
docs/content/1.docs/1.getting-started/2.configuration.md
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# Configuration
|
||||||
|
|
||||||
|
Configure Nuxt Mongoose with the `mongoose` property.
|
||||||
|
|
||||||
|
```ts [nuxt.config]
|
||||||
|
export default defineNuxtConfig({
|
||||||
|
mongoose: {
|
||||||
|
uri: 'process.env.MONGODB_URI',
|
||||||
|
options: {},
|
||||||
|
modelsDir: 'models',
|
||||||
|
devtools: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
| **Key** | **Type** | **Default** | **Description** |
|
||||||
|
| ---------------------------- | ---------- | ----------------------- | ---------------------------------------------------------------------------------------------------- |
|
||||||
|
| `uri` | `string` | process.env.MONGODB_URI | Connection Uri String |
|
||||||
|
| `options` | `ConnectOptions` | { } | Connection Options |
|
||||||
|
| `modelsDir` | `string` | models | The models(schema) directory located in `server` for auto-import |
|
||||||
|
| `devtools` | `boolean` | true | Enable Mongoose module in [`Nuxt Devtools`](https://github.com/nuxt/devtools) |
|
||||||
2
docs/content/1.docs/1.getting-started/_dir.yml
Normal file
2
docs/content/1.docs/1.getting-started/_dir.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
icon: tabler:brand-mongodb
|
||||||
|
navigation.redirect: /getting-started/setup
|
||||||
74
docs/content/1.docs/2.api/1.utils.md
Normal file
74
docs/content/1.docs/2.api/1.utils.md
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
# Utils
|
||||||
|
|
||||||
|
Discover all available utils.
|
||||||
|
|
||||||
|
## `defineMongooseModel`
|
||||||
|
|
||||||
|
This function creates a new Mongoose model with schema. Example usage:
|
||||||
|
|
||||||
|
::code-group
|
||||||
|
|
||||||
|
```ts [named parameters]
|
||||||
|
export const User = defineMongooseModel({
|
||||||
|
name: 'User',
|
||||||
|
schema: {
|
||||||
|
email: {
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
unique: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
|
||||||
|
},
|
||||||
|
hooks(schema) {
|
||||||
|
|
||||||
|
},
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts [positional parameters]
|
||||||
|
import { defineMongooseModel } from '#nuxt/mongoose'
|
||||||
|
|
||||||
|
export const User = defineMongooseModel('User', {
|
||||||
|
email: {
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
unique: true,
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
|
||||||
|
}, (schema) => {
|
||||||
|
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
|
||||||
|
| **Key** | **Type** | **Require** | **Description** |
|
||||||
|
| ---------------------------- | ----------- | ----------- | ----- |
|
||||||
|
| `name` | `string` | true | Name of Model |
|
||||||
|
| `schema` | [`SchemaDefinition`](https://mongoosejs.com/docs/schematypes.html) | true | Schema Definition of Model |
|
||||||
|
| `options` | [`SchemaOptions`](https://mongoosejs.com/docs/guide.html#options) | false | Schema Options for Model |
|
||||||
|
| `hooks` | [`(schema: Schema<T>) => void`](https://mongoosejs.com/docs/middleware.html) | false | Schema Hooks Function to customize Model |
|
||||||
|
|
||||||
|
|
||||||
|
::alert
|
||||||
|
you can access the default connection with importing it from mongoose:
|
||||||
|
::
|
||||||
|
```
|
||||||
|
import { connection } from 'mongoose'
|
||||||
|
```
|
||||||
|
|
||||||
|
## `defineMongooseConnection`
|
||||||
|
This function creates a new Mongoose connection.
|
||||||
|
- `nuxt-mongoose` provides a default connection for you, it auto-register a plugin in nitro, so you don't need to use this function unless you want to create a new connection. more info [here](https://github.com/arashsheyda/nuxt-mongoose/blob/main/src/runtime/server/plugins/mongoose.db.ts).
|
||||||
|
|
||||||
|
Example usage:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { defineMongooseConnection } from '#nuxt/mongoose'
|
||||||
|
|
||||||
|
export const connection = defineMongooseConnection('mongodb://127.0.0.1/nuxt-mongoose')
|
||||||
|
```
|
||||||
8
docs/content/1.docs/2.api/2.devtools.md
Normal file
8
docs/content/1.docs/2.api/2.devtools.md
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Devtools (beta)
|
||||||
|
|
||||||
|
`nuxt-mongoose` comes with a [Nuxt Devtools](https://github.com/nuxt/devtools) module that allows you to manage your collections and generate api-endpoints & schemas...
|
||||||
|
|
||||||
|
Here is a demo video:
|
||||||
|
|
||||||
|
:video-player{src="https://www.youtube.com/watch?v=hK0npSfr_Vs"}
|
||||||
|
|
||||||
5
docs/content/1.docs/2.api/3.examples.md
Normal file
5
docs/content/1.docs/2.api/3.examples.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Examples
|
||||||
|
|
||||||
|
Here are a few examples:
|
||||||
|
|
||||||
|
- Nuxt Mongoose Minimal: [:icon{name="tabler:brand-github"} Github](https://github.com/arashsheyda/nuxt-mongoose-minimal) [:icon{name="tabler:world"} Website](https://nuxt-mongoose-minimal.vercel.app/)
|
||||||
2
docs/content/1.docs/2.api/_dir.yml
Normal file
2
docs/content/1.docs/2.api/_dir.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
title: API
|
||||||
|
icon: tabler:book
|
||||||
1
docs/content/1.docs/_dir.yml
Normal file
1
docs/content/1.docs/_dir.yml
Normal file
@ -0,0 +1 @@
|
|||||||
|
icon: tabler:file-description
|
||||||
5
docs/content/2.playground/1.index.md
Normal file
5
docs/content/2.playground/1.index.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Playground
|
||||||
|
|
||||||
|
:ellipsis{right=0px width=75% blur=150px}
|
||||||
|
|
||||||
|
:sandbox{src="https://stackblitz.com/github/arashsheyda/nuxt-mongoose-minimal"}
|
||||||
1
docs/content/2.playground/_dir.yml
Normal file
1
docs/content/2.playground/_dir.yml
Normal file
@ -0,0 +1 @@
|
|||||||
|
icon: tabler:play-volleyball
|
||||||
3
docs/content/3.releases/_dir.yml
Normal file
3
docs/content/3.releases/_dir.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
title: Releases
|
||||||
|
icon: tabler:clipboard-text
|
||||||
|
navigation.redirect: https://github.com/arashsheyda/nuxt-mongoose/releases
|
||||||
0
docs/content/3.releases/index.md
Normal file
0
docs/content/3.releases/index.md
Normal file
19
docs/nuxt.config.ts
Normal file
19
docs/nuxt.config.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
export default defineNuxtConfig({
|
||||||
|
extends: '@nuxt-themes/docus',
|
||||||
|
|
||||||
|
app: {
|
||||||
|
head: {
|
||||||
|
link: [
|
||||||
|
{
|
||||||
|
rel: 'icon',
|
||||||
|
type: 'image/x-icon',
|
||||||
|
href: '/mongoose-icon.svg',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
modules: [
|
||||||
|
'@nuxthq/studio',
|
||||||
|
],
|
||||||
|
})
|
||||||
17
docs/package.json
Normal file
17
docs/package.json
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"name": "docus-starter",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"dev": "nuxi dev",
|
||||||
|
"build": "nuxi build",
|
||||||
|
"generate": "nuxi generate",
|
||||||
|
"preview": "nuxi preview",
|
||||||
|
"lint": "eslint ."
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@nuxt-themes/docus": "^1.15.0",
|
||||||
|
"@nuxthq/studio": "^1.0.2",
|
||||||
|
"nuxt": "^3.8.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
8878
docs/pnpm-lock.yaml
generated
Normal file
8878
docs/pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
BIN
docs/public/cover.jpg
Normal file
BIN
docs/public/cover.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 46 KiB |
1
docs/public/mongoose-icon.svg
Normal file
1
docs/public/mongoose-icon.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 256 256"><g fill="none"><rect width="256" height="256" fill="#023430" rx="60"/><path fill="#10AA50" d="M171.173 107.591c-10.537-46.481-32.497-58.855-38.099-67.602A99.398 99.398 0 0 1 126.949 28c-.296 4.13-.84 6.73-4.35 9.862c-7.047 6.283-36.977 30.673-39.496 83.486c-2.347 49.242 36.2 79.605 41.292 82.744c3.916 1.927 8.685.041 11.012-1.728c18.581-12.752 43.969-46.75 35.786-94.773"/><path fill="#B8C4C2" d="M128.545 177.871c-.97 12.188-1.665 19.27-4.129 26.235c0 0 1.617 11.603 2.753 23.894h4.019a223.446 223.446 0 0 1 4.384-25.732c-5.203-2.56-6.827-13.702-7.027-24.397Z"/><path fill="#12924F" d="M135.565 202.275c-5.258-2.429-6.779-13.806-7.013-24.404a499.824 499.824 0 0 0 1.136-52.545c-.276-9.194.13-85.158-2.265-96.28a92.425 92.425 0 0 0 5.651 10.936c5.602 8.754 27.569 21.128 38.099 67.609c8.203 47.941-17.047 81.849-35.608 94.684Z"/></g></svg>
|
||||||
|
After Width: | Height: | Size: 926 B |
@ -1,26 +1 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 235.5 33.2"><rect width="32" height="32" rx="7.5" style="fill:#023430"/><path d="M21.4,13.4C20.1,7.6,17.3,6.1,16.6,5a10.1,10.1,0,0,1-.7-1.5,1.6,1.6,0,0,1-.6,1.2,14.1,14.1,0,0,0-4.9,10.5c-.3,6.1,4.5,9.9,5.1,10.3a1.4,1.4,0,0,0,1.4-.2,12.1,12.1,0,0,0,4.5-11.9" style="fill:#10aa50"/><path d="M16.1,22.2a17.8,17.8,0,0,1-.5,3.3s.2,1.5.3,3h.5a30.6,30.6,0,0,1,.5-3.2C16.3,25,16.1,23.6,16.1,22.2Z" style="fill:#b8c4c2"/><path d="M16.9,25.3c-.6-.3-.8-1.7-.8-3.1s.2-4.3.1-6.5,0-10.7-.3-12.1L16.6,5c.7,1.1,3.5,2.6,4.8,8.4A12,12,0,0,1,16.9,25.3Z" style="fill:#12924f"/><text transform="translate(32.8 25.6)" style="font-size:25.818214416503906px;font-family:OpenSans-Bold, Open Sans;font-weight:700">Nuxt <tspan x="70.8" y="0" style="fill:#10aa50">Mongoose</tspan></text></svg>
|
||||||
<!-- Generator: Adobe Illustrator 25.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
|
||||||
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
|
||||||
viewBox="0 0 520.1 232.7" style="enable-background:new 0 0 520.1 232.7;" xml:space="preserve">
|
|
||||||
<style type="text/css">
|
|
||||||
.st0{fill:#880000;}
|
|
||||||
.st1{fill:#00DC82;}
|
|
||||||
</style>
|
|
||||||
<path class="st0" d="M323.9,193.5c-47.8-6.5-96.2,6.6-134.1,36.4c-9.7-24.3-21.1-48-34.1-70.8c-10.8-19.1-18.1-29.1-28.6-29.9
|
|
||||||
s-21.3,9.9-25.3,15C94,126,82.2,113.3,71.2,114.3c-6.5,0.6-12,7.6-22.6,21.5C38.3,149.5,31,161.7,25,172.5
|
|
||||||
c-5.4,9.7-12.4,22.7-19.9,38.5C5.3,133.1,6,75,5.8,49.3c0-4.6-0.1-15.1,6.8-22.9c7.3-8.2,18.6-9.1,34.2-10.2
|
|
||||||
c9.6-0.7,23.6-0.8,40.5,2.3c1.2,12,8.2,42,31.4,72.1c14.4,18.7,31.7,31.1,48.4,33.8c-14.4-13.7-33.3-29-48.6-47.3
|
|
||||||
c-13.2-15.6-21.3-34.8-21-56.6c0.2-12.6,5.8-19.8,17.5-18.2c23.3,3.5,46.3,8.9,69.3,13.6c2.5,0.5,4.9,1.7,8.4,0.5L169.6,4.9
|
|
||||||
c0.4-1.4,0.7-2.8,1.1-4.2c114.6-5.8,221.8,26,328.4,65.5c-1.4,7.4-2.5,12.9-3.6,18.4l1.5,0.6l7.1-14c16.3,2.2,18.3,6.4,14.1,20.7
|
|
||||||
c-7.4,25.7-24.1,39.2-50,44.1c-41.3,7.9-82.2,17.2-123.5,25.3C318.2,166.6,317.3,167.5,323.9,193.5z M185,62.7
|
|
||||||
c-16.8-20-51.7-37.3-67.5-34.9c-2.3,22.4,34.4,68.2,57.8,71.7c-2.7-4.4-5.3-8.4-7.8-12.6l6.4-3.5l-15.2-19.8l18.7,7.9l-6.6-13.7
|
|
||||||
L185,62.7z M375.9,66.2l0.2-4.8L285.7,44l-1.3,4.5c14.2,7,27.8,16.7,42.8,20.2C343.4,72.3,360.2,71.5,375.9,66.2L375.9,66.2z
|
|
||||||
M363.3,130.2l-1.6-4.3c-20.4,8.3-41.2,15.8-61,25.3c-11.1,5.3-10.9,14-3,22.5C305.5,138.6,340.3,142.8,363.3,130.2z"/>
|
|
||||||
<path class="st1" d="M103.4,232.7h59.5c1.9,0,3.7-0.5,5.4-1.4c3.3-1.9,5.3-5.5,5.3-9.3c0-1.9-0.5-3.7-1.4-5.3l-40-68.7
|
|
||||||
c-0.9-1.6-2.3-2.9-3.9-3.8c-3.3-2-7.5-2-10.8,0c-1.6,0.9-2.9,2.2-3.9,3.8l-10.2,17.6l-20-34.4c-1-1.6-2.4-2.9-4-3.8
|
|
||||||
c-3.3-2-7.4-2-10.7,0c-1.6,0.9-2.9,2.2-3.9,3.8l-49.9,85.5c-3,5-1.3,11.5,3.7,14.5c1.7,1,3.6,1.5,5.6,1.5h37.4
|
|
||||||
c14.7,0,25.7-6.4,33.3-19l18.2-31.4l9.8-16.7l29.3,50.4h-39.1L103.4,232.7z M61,215.9H34.9L74,148.8l19.5,33.6l-13.1,22.4
|
|
||||||
C75.5,213,69.8,215.9,61,215.9L61,215.9z"/>
|
|
||||||
<path class="st1" d="M375.9,66.2l0.2-4.8L285.7,44l-1.3,4.5c14.2,7,27.8,16.7,42.8,20.2C343.4,72.3,360.2,71.5,375.9,66.2
|
|
||||||
L375.9,66.2z"/>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 851 B |
8
docs/renovate.json
Normal file
8
docs/renovate.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"extends": [
|
||||||
|
"@nuxtjs"
|
||||||
|
],
|
||||||
|
"lockFileMaintenance": {
|
||||||
|
"enabled": true
|
||||||
|
}
|
||||||
|
}
|
||||||
18
docs/tokens.config.ts
Normal file
18
docs/tokens.config.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { defineTheme } from 'pinceau'
|
||||||
|
|
||||||
|
export default defineTheme({
|
||||||
|
color: {
|
||||||
|
primary: {
|
||||||
|
50: '#e8f5e9',
|
||||||
|
100: '#c8e6c9',
|
||||||
|
200: '#a5d6a7',
|
||||||
|
300: '#81c784',
|
||||||
|
400: '#66bb6a',
|
||||||
|
500: '#10a74f',
|
||||||
|
600: '#10a74f',
|
||||||
|
700: '#388e3c',
|
||||||
|
800: '#2e7d32',
|
||||||
|
900: '#1b5e20',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
3
docs/tsconfig.json
Normal file
3
docs/tsconfig.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"extends": "./.nuxt/tsconfig.json"
|
||||||
|
}
|
||||||
15
module.cjs
15
module.cjs
@ -1,15 +0,0 @@
|
|||||||
/* eslint-disable eslint-comments/no-unlimited-disable */
|
|
||||||
/* eslint-disable */
|
|
||||||
module.exports = function (...args) {
|
|
||||||
const nuxt = this.nuxt || args[1]
|
|
||||||
let _a
|
|
||||||
let version = (nuxt == null ? void 0 : nuxt._version) || (nuxt == null ? void 0 : nuxt.version) || ((_a = nuxt == null ? void 0 : nuxt.constructor) == null ? void 0 : _a.version) || ''
|
|
||||||
version = version.replace(/^v/g, '')
|
|
||||||
// Nuxt DevTools is not compatible with Nuxt 2, disabled
|
|
||||||
if (version.startsWith('2.')) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return import('./dist/module.mjs').then(m => m.default.call(this, ...args))
|
|
||||||
}
|
|
||||||
const _meta = module.exports.meta = require('./dist/module.json')
|
|
||||||
module.exports.getMeta = () => Promise.resolve(_meta)
|
|
||||||
89
package.json
89
package.json
@ -1,71 +1,74 @@
|
|||||||
{
|
{
|
||||||
"name": "nuxt-mongoose",
|
"name": "nuxt-mongoose",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "0.0.5",
|
"version": "1.0.2",
|
||||||
|
"private": false,
|
||||||
|
"packageManager": "pnpm@8.7.4",
|
||||||
"description": "Nuxt 3 module for MongoDB with Mongoose",
|
"description": "Nuxt 3 module for MongoDB with Mongoose",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
"funding": "https://github.com/sponsors/arashsheyda",
|
||||||
|
"homepage": "https://nuxt-mongoose.nuxt.space",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/arashsheyda/nuxt-mongoose"
|
"url": "git+https://github.com/arashsheyda/nuxt-mongoose"
|
||||||
},
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/arashsheyda/nuxt-mongoose/issues"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"nuxt",
|
||||||
|
"mongoose",
|
||||||
|
"mongodb",
|
||||||
|
"devtools"
|
||||||
|
],
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"types": "./dist/types.d.ts",
|
"types": "./dist/types.d.ts",
|
||||||
"require": "./module.cjs",
|
"import": "./dist/module.mjs",
|
||||||
"import": "./dist/module.mjs"
|
"require": "./dist/module.cjs"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"./types": {
|
"build": {
|
||||||
"types": "./dist/types.d.ts",
|
"externals": [
|
||||||
"import": "./dist/types.mjs"
|
"ofetch"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"./*": "./*"
|
"main": "./dist/module.cjs",
|
||||||
},
|
|
||||||
"main": "./module.cjs",
|
|
||||||
"types": "./dist/types.d.ts",
|
"types": "./dist/types.d.ts",
|
||||||
"files": [
|
"files": [
|
||||||
"dist"
|
"dist"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "pnpm dev:prepare && pnpm build:module && pnpm build:client",
|
"build": "nuxt-module-build && npm run build:client",
|
||||||
"build:client": "nuxi generate client",
|
"build:client": "nuxi generate client",
|
||||||
"build:module": "nuxt-build-module",
|
|
||||||
"dev": "nuxi dev playground",
|
"dev": "nuxi dev playground",
|
||||||
"dev:prepare": "nuxi prepare client",
|
"dev:prepare": "nuxt-module-build && nuxi prepare client",
|
||||||
"dev:prod": "npm run build && pnpm dev",
|
"dev:client": "nuxi dev client --port 3300",
|
||||||
"release": "npm run lint && npm run build && changelogen --release && npm publish && git push --follow-tags",
|
"dev:prod": "npm run build && npm run dev",
|
||||||
"lint": "eslint .",
|
"release": "npm run lint && npm run build && changelogen --release && npm publish",
|
||||||
"test": "vitest run",
|
"lint": "eslint . --fix"
|
||||||
"test:watch": "vitest watch"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nuxt/devtools-kit": "^0.4.2",
|
"@nuxt/devtools-kit": "1.0.0",
|
||||||
"@nuxt/kit": "^3.4.2",
|
"@nuxt/devtools-ui-kit": "1.0.0",
|
||||||
"@types/fs-extra": "^11.0.1",
|
"@nuxt/kit": "^3.8.0",
|
||||||
"birpc": "^0.2.11",
|
"@vueuse/core": "^10.5.0",
|
||||||
"defu": "^6.1.2",
|
"defu": "^6.1.3",
|
||||||
"flatted": "^3.2.7",
|
|
||||||
"fs-extra": "^11.1.1",
|
"fs-extra": "^11.1.1",
|
||||||
"mongoose": "^7.0.5",
|
"mongoose": "^7.6.3",
|
||||||
|
"ofetch": "^1.3.3",
|
||||||
|
"pathe": "^1.1.1",
|
||||||
"pluralize": "^8.0.0",
|
"pluralize": "^8.0.0",
|
||||||
"sirv": "^2.0.3",
|
"sirv": "^2.0.3"
|
||||||
"tinyws": "^0.1.0",
|
|
||||||
"ws": "^8.13.0"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@antfu/eslint-config": "^0.38.5",
|
"@antfu/eslint-config": "1.0.0-beta.29",
|
||||||
"@nuxt/devtools": "^0.4.2",
|
"@nuxt/module-builder": "^0.5.2",
|
||||||
"@nuxt/devtools-ui-kit": "^0.4.2",
|
"@types/fs-extra": "^11.0.3",
|
||||||
"@nuxt/module-builder": "^0.3.0",
|
"@types/pluralize": "^0.0.32",
|
||||||
"@nuxt/schema": "^3.4.2",
|
"changelogen": "^0.5.5",
|
||||||
"@nuxt/test-utils": "^3.4.2",
|
"eslint": "8.52.0",
|
||||||
"@types/pluralize": "^0.0.29",
|
"nuxt": "^3.8.0",
|
||||||
"@types/ws": "^8.5.4",
|
"sass": "^1.69.5"
|
||||||
"changelogen": "^0.5.3",
|
|
||||||
"eslint": "^8.39.0",
|
|
||||||
"nuxt": "^3.4.2",
|
|
||||||
"sass": "^1.62.1",
|
|
||||||
"sass-loader": "^13.2.2",
|
|
||||||
"splitpanes": "^3.1.5",
|
|
||||||
"vitest": "^0.30.1"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
1
playground/.env.example
Normal file
1
playground/.env.example
Normal file
@ -0,0 +1 @@
|
|||||||
|
MONGODB_URI="mongodb://localhost:27017/nuxt-mongoose"
|
||||||
@ -1,6 +1,33 @@
|
|||||||
|
import { resolve } from 'node:path'
|
||||||
|
import { defineNuxtConfig } from 'nuxt/config'
|
||||||
|
import { defineNuxtModule } from '@nuxt/kit'
|
||||||
|
import { startSubprocess } from '@nuxt/devtools-kit'
|
||||||
|
import { CLIENT_PORT } from '../src/constants'
|
||||||
|
|
||||||
export default defineNuxtConfig({
|
export default defineNuxtConfig({
|
||||||
|
devtools: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
|
||||||
modules: [
|
modules: [
|
||||||
'@nuxt/devtools',
|
|
||||||
'../src/module',
|
'../src/module',
|
||||||
|
defineNuxtModule({
|
||||||
|
setup(_, nuxt) {
|
||||||
|
if (!nuxt.options.dev)
|
||||||
|
return
|
||||||
|
|
||||||
|
startSubprocess(
|
||||||
|
{
|
||||||
|
command: 'npx',
|
||||||
|
args: ['nuxi', 'dev', '--port', CLIENT_PORT.toString()],
|
||||||
|
cwd: resolve(__dirname, '../client'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'nuxt-mongoose:client',
|
||||||
|
name: 'Nuxt Mongoose Client Dev',
|
||||||
|
},
|
||||||
|
)
|
||||||
|
},
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|||||||
5
playground/server/api/hi.get.ts
Normal file
5
playground/server/api/hi.get.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export default defineEventHandler(async () => {
|
||||||
|
return {
|
||||||
|
message: 'hi',
|
||||||
|
}
|
||||||
|
})
|
||||||
8
playground/server/api/users/[_id].delete.ts
Normal file
8
playground/server/api/users/[_id].delete.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
export default defineEventHandler(async (event) => {
|
||||||
|
try {
|
||||||
|
return await UserSchema.findOneAndDelete({ _id: event.context.params?._id })
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
return error
|
||||||
|
}
|
||||||
|
})
|
||||||
8
playground/server/api/users/[_id].get.ts
Normal file
8
playground/server/api/users/[_id].get.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
export default defineEventHandler(async (event) => {
|
||||||
|
try {
|
||||||
|
return await UserSchema.findOne({ _id: event.context.params?._id })
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
return error
|
||||||
|
}
|
||||||
|
})
|
||||||
9
playground/server/api/users/[_id].put.ts
Normal file
9
playground/server/api/users/[_id].put.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
export default defineEventHandler(async (event) => {
|
||||||
|
const body = await readBody(event)
|
||||||
|
try {
|
||||||
|
return await UserSchema.findOneAndUpdate({ _id: event.context.params?._id }, body, { new: true })
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
return error
|
||||||
|
}
|
||||||
|
})
|
||||||
9
playground/server/api/users/create.post.ts
Normal file
9
playground/server/api/users/create.post.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
export default defineEventHandler(async (event) => {
|
||||||
|
const body = await readBody(event)
|
||||||
|
try {
|
||||||
|
return await new UserSchema(body).save()
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
return error
|
||||||
|
}
|
||||||
|
})
|
||||||
8
playground/server/api/users/index.get.ts
Normal file
8
playground/server/api/users/index.get.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
export default defineEventHandler(async () => {
|
||||||
|
try {
|
||||||
|
return await UserSchema.find({})
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
return error
|
||||||
|
}
|
||||||
|
})
|
||||||
26
playground/server/models/user.schema.ts
Normal file
26
playground/server/models/user.schema.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import { defineMongooseModel } from '#nuxt/mongoose'
|
||||||
|
|
||||||
|
export const UserSchema = defineMongooseModel({
|
||||||
|
name: 'User',
|
||||||
|
schema: {
|
||||||
|
name: {
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
email: {
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
unique: false,
|
||||||
|
},
|
||||||
|
password: {
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
hooks(schema) {
|
||||||
|
schema.pre('save', function (this, next) {
|
||||||
|
this.password = `hash.${this.password}.${Math.random()}`
|
||||||
|
next()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
})
|
||||||
3
playground/server/tsconfig.json
Normal file
3
playground/server/tsconfig.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"extends": "../.nuxt/tsconfig.server.json"
|
||||||
|
}
|
||||||
11916
pnpm-lock.yaml
generated
11916
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,3 @@
|
|||||||
export const PATH = '/__nuxt_mongoose__'
|
export const CLIENT_PATH = '/__nuxt-mongoose'
|
||||||
export const PATH_ENTRY = `${PATH}/entry`
|
export const CLIENT_PORT = 3300
|
||||||
export const PATH_CLIENT = `${PATH}/client`
|
export const RPC_NAMESPACE = 'nuxt-mongoose-rpc'
|
||||||
|
|||||||
56
src/devtools.ts
Normal file
56
src/devtools.ts
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
import { existsSync } from 'node:fs'
|
||||||
|
import type { Nuxt } from 'nuxt/schema'
|
||||||
|
import type { Resolver } from '@nuxt/kit'
|
||||||
|
import { extendServerRpc, onDevToolsInitialized } from '@nuxt/devtools-kit'
|
||||||
|
import type { ClientFunctions, ServerFunctions } from './types'
|
||||||
|
import type { ModuleOptions } from './module'
|
||||||
|
import { useViteWebSocket } from './utils'
|
||||||
|
|
||||||
|
import { setupRPC } from './rpc'
|
||||||
|
import { CLIENT_PATH, CLIENT_PORT, RPC_NAMESPACE } from './constants'
|
||||||
|
|
||||||
|
export function setupDevToolsUI(options: ModuleOptions, resolve: Resolver['resolve'], nuxt: Nuxt) {
|
||||||
|
const clientPath = resolve('./client')
|
||||||
|
const isProductionBuild = existsSync(clientPath)
|
||||||
|
|
||||||
|
if (isProductionBuild) {
|
||||||
|
nuxt.hook('vite:serverCreated', async (server) => {
|
||||||
|
const sirv = await import('sirv').then(r => r.default || r)
|
||||||
|
server.middlewares.use(
|
||||||
|
CLIENT_PATH,
|
||||||
|
sirv(clientPath, { dev: true, single: true }),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
nuxt.hook('vite:extendConfig', (config) => {
|
||||||
|
config.server = config.server || {}
|
||||||
|
config.server.proxy = config.server.proxy || {}
|
||||||
|
config.server.proxy[CLIENT_PATH] = {
|
||||||
|
target: `http://localhost:${CLIENT_PORT}${CLIENT_PATH}`,
|
||||||
|
changeOrigin: true,
|
||||||
|
followRedirects: true,
|
||||||
|
rewrite: path => path.replace(CLIENT_PATH, ''),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
nuxt.hook('devtools:customTabs', (tabs) => {
|
||||||
|
tabs.push({
|
||||||
|
name: 'nuxt-mongoose',
|
||||||
|
title: 'Mongoose',
|
||||||
|
icon: 'skill-icons:mongodb',
|
||||||
|
view: {
|
||||||
|
type: 'iframe',
|
||||||
|
src: CLIENT_PATH,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const wsServer = useViteWebSocket(nuxt)
|
||||||
|
onDevToolsInitialized(async () => {
|
||||||
|
const rpcFunctions = setupRPC({ options, wsServer, nuxt })
|
||||||
|
|
||||||
|
extendServerRpc<ClientFunctions, ServerFunctions>(RPC_NAMESPACE, rpcFunctions)
|
||||||
|
})
|
||||||
|
}
|
||||||
132
src/module.ts
132
src/module.ts
@ -1,13 +1,47 @@
|
|||||||
import { addImportsDir, addServerPlugin, addTemplate, createResolver, defineNuxtModule, logger } from '@nuxt/kit'
|
import {
|
||||||
import { pathExists } from 'fs-extra'
|
addServerPlugin,
|
||||||
import { tinyws } from 'tinyws'
|
addTemplate,
|
||||||
import { defu } from 'defu'
|
createResolver,
|
||||||
import sirv from 'sirv'
|
defineNuxtModule,
|
||||||
|
logger,
|
||||||
|
} from '@nuxt/kit'
|
||||||
|
import type { ConnectOptions } from 'mongoose'
|
||||||
|
import defu from 'defu'
|
||||||
|
import { join } from 'pathe'
|
||||||
|
import mongoose from 'mongoose'
|
||||||
|
import { $fetch } from 'ofetch'
|
||||||
|
import { version } from '../package.json'
|
||||||
|
import { setupDevToolsUI } from './devtools'
|
||||||
|
|
||||||
import { PATH_CLIENT, PATH_ENTRY } from './constants'
|
export interface ModuleOptions {
|
||||||
import type { ModuleOptions } from './types'
|
/**
|
||||||
|
* The MongoDB URI connection
|
||||||
import { setupRPC } from './server-rpc'
|
*
|
||||||
|
* @default process.env.MONGODB_URI
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
uri: string | undefined
|
||||||
|
/**
|
||||||
|
* Nuxt DevTools
|
||||||
|
*
|
||||||
|
* @default true
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
devtools: boolean
|
||||||
|
/**
|
||||||
|
* Mongoose Connections
|
||||||
|
*
|
||||||
|
* @default {}
|
||||||
|
*/
|
||||||
|
options?: ConnectOptions
|
||||||
|
/**
|
||||||
|
* Models Directory for auto-import
|
||||||
|
*
|
||||||
|
* @default 'models'
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
modelsDir?: string
|
||||||
|
}
|
||||||
|
|
||||||
export default defineNuxtModule<ModuleOptions>({
|
export default defineNuxtModule<ModuleOptions>({
|
||||||
meta: {
|
meta: {
|
||||||
@ -15,66 +49,54 @@ export default defineNuxtModule<ModuleOptions>({
|
|||||||
configKey: 'mongoose',
|
configKey: 'mongoose',
|
||||||
},
|
},
|
||||||
defaults: {
|
defaults: {
|
||||||
|
// eslint-disable-next-line n/prefer-global/process
|
||||||
uri: process.env.MONGODB_URI as string,
|
uri: process.env.MONGODB_URI as string,
|
||||||
devtools: true,
|
devtools: true,
|
||||||
options: {},
|
options: {},
|
||||||
|
modelsDir: 'models',
|
||||||
},
|
},
|
||||||
setup(options, nuxt) {
|
hooks: {
|
||||||
|
close: () => {
|
||||||
|
mongoose.disconnect()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
async setup(options, nuxt) {
|
||||||
|
if (nuxt.options.dev) {
|
||||||
|
$fetch('https://registry.npmjs.org/nuxt-mongoose/latest').then((release) => {
|
||||||
|
if (release.version > version)
|
||||||
|
logger.info(`A new version of Nuxt Mongoose (v${release.version}) is available: https://github.com/arashsheyda/nuxt-mongoose/releases/latest`)
|
||||||
|
}).catch(() => {})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!options.uri) {
|
||||||
|
logger.warn('Missing MongoDB URI. You can set it in your `nuxt.config` or in your `.env` as `MONGODB_URI`')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const { resolve } = createResolver(import.meta.url)
|
const { resolve } = createResolver(import.meta.url)
|
||||||
|
const config = nuxt.options.runtimeConfig as any
|
||||||
|
|
||||||
addImportsDir(resolve('./runtime/composables'))
|
config.mongoose = defu(config.mongoose || {}, {
|
||||||
|
|
||||||
if (!options.uri)
|
|
||||||
console.warn('Missing `MONGODB_URI` in `.env`')
|
|
||||||
|
|
||||||
// Public runtimeConfig
|
|
||||||
nuxt.options.runtimeConfig.public.mongoose = defu(nuxt.options.runtimeConfig.public.mongoose || {}, {
|
|
||||||
uri: options.uri,
|
uri: options.uri,
|
||||||
options: options.options,
|
options: options.options,
|
||||||
devtools: options.devtools,
|
devtools: options.devtools,
|
||||||
})
|
modelsDir: join(nuxt.options.serverDir, options.modelsDir!),
|
||||||
|
|
||||||
// Setup devtools UI
|
|
||||||
const distResolve = (p: string) => {
|
|
||||||
const cwd = resolve('.')
|
|
||||||
if (cwd.endsWith('/dist'))
|
|
||||||
return resolve(p)
|
|
||||||
return resolve(`../dist/${p}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
const clientPath = distResolve('./client')
|
|
||||||
const { middleware: rpcMiddleware } = setupRPC(nuxt, options)
|
|
||||||
|
|
||||||
nuxt.hook('vite:serverCreated', async (server) => {
|
|
||||||
server.middlewares.use(PATH_ENTRY, tinyws() as any)
|
|
||||||
server.middlewares.use(PATH_ENTRY, rpcMiddleware as any)
|
|
||||||
if (await pathExists(clientPath))
|
|
||||||
server.middlewares.use(PATH_CLIENT, sirv(clientPath, { dev: true, single: true }))
|
|
||||||
})
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
|
||||||
// @ts-ignore runtime type
|
|
||||||
nuxt.hook('devtools:customTabs', (iframeTabs) => {
|
|
||||||
iframeTabs.push({
|
|
||||||
name: 'mongoose',
|
|
||||||
title: 'Mongoose',
|
|
||||||
icon: 'skill-icons:mongodb',
|
|
||||||
view: {
|
|
||||||
type: 'iframe',
|
|
||||||
src: PATH_CLIENT,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// virtual imports
|
// virtual imports
|
||||||
nuxt.hook('nitro:config', (nitroConfig) => {
|
nuxt.hook('nitro:config', (_config) => {
|
||||||
nitroConfig.alias = nitroConfig.alias || {}
|
_config.alias = _config.alias || {}
|
||||||
|
|
||||||
// Inline module runtime in Nitro bundle
|
// Inline module runtime in Nitro bundle
|
||||||
nitroConfig.externals = defu(typeof nitroConfig.externals === 'object' ? nitroConfig.externals : {}, {
|
_config.externals = defu(typeof _config.externals === 'object' ? _config.externals : {}, {
|
||||||
inline: [resolve('./runtime')],
|
inline: [resolve('./runtime')],
|
||||||
})
|
})
|
||||||
nitroConfig.alias['#nuxt/mongoose'] = resolve('./runtime/server/services')
|
_config.alias['#nuxt/mongoose'] = resolve('./runtime/server/services')
|
||||||
|
|
||||||
|
if (_config.imports) {
|
||||||
|
_config.imports.dirs = _config.imports.dirs || []
|
||||||
|
_config.imports.dirs?.push(config.mongoose.modelsDir)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
addTemplate({
|
addTemplate({
|
||||||
@ -91,6 +113,10 @@ export default defineNuxtModule<ModuleOptions>({
|
|||||||
options.references.push({ path: resolve(nuxt.options.buildDir, 'types/nuxt-mongoose.d.ts') })
|
options.references.push({ path: resolve(nuxt.options.buildDir, 'types/nuxt-mongoose.d.ts') })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const isDevToolsEnabled = typeof nuxt.options.devtools === 'boolean' ? nuxt.options.devtools : nuxt.options.devtools.enabled
|
||||||
|
if (nuxt.options.dev && isDevToolsEnabled)
|
||||||
|
setupDevToolsUI(options, resolve, nuxt)
|
||||||
|
|
||||||
// Add server-plugin for database connection
|
// Add server-plugin for database connection
|
||||||
addServerPlugin(resolve('./runtime/server/plugins/mongoose.db'))
|
addServerPlugin(resolve('./runtime/server/plugins/mongoose.db'))
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,8 @@
|
|||||||
import mongoose from 'mongoose'
|
import mongoose from 'mongoose'
|
||||||
import type { NuxtDevtoolsServerContext, ServerFunctions } from '../types'
|
import type { DevtoolsServerContext, ServerFunctions } from '../types'
|
||||||
|
|
||||||
export function setupDatabaseRPC({ options }: NuxtDevtoolsServerContext): any {
|
|
||||||
mongoose.connect(options.uri, options.options)
|
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-empty-pattern
|
||||||
|
export function setupDatabaseRPC({}: DevtoolsServerContext) {
|
||||||
return {
|
return {
|
||||||
async readyState() {
|
async readyState() {
|
||||||
return mongoose.connection.readyState
|
return mongoose.connection.readyState
|
||||||
@ -62,8 +61,8 @@ export function setupDatabaseRPC({ options }: NuxtDevtoolsServerContext): any {
|
|||||||
const skip = (options.page - 1) * options.limit
|
const skip = (options.page - 1) * options.limit
|
||||||
const cursor = mongoose.connection.db.collection(collection).find().skip(skip)
|
const cursor = mongoose.connection.db.collection(collection).find().skip(skip)
|
||||||
if (options.limit !== 0)
|
if (options.limit !== 0)
|
||||||
cursor.limit(options.limit)
|
cursor?.limit(options.limit)
|
||||||
return await cursor.toArray()
|
return await cursor?.toArray()
|
||||||
},
|
},
|
||||||
async getDocument(collection: string, document: any) {
|
async getDocument(collection: string, document: any) {
|
||||||
try {
|
try {
|
||||||
23
src/rpc/index.ts
Normal file
23
src/rpc/index.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import mongoose from 'mongoose'
|
||||||
|
import type { DevtoolsServerContext, ServerFunctions } from '../types'
|
||||||
|
|
||||||
|
import { setupDatabaseRPC } from './database'
|
||||||
|
import { setupResourceRPC } from './resource'
|
||||||
|
|
||||||
|
export function setupRPC(ctx: DevtoolsServerContext): ServerFunctions {
|
||||||
|
mongoose.connect(ctx.options.uri, ctx.options.options)
|
||||||
|
|
||||||
|
return {
|
||||||
|
getOptions() {
|
||||||
|
return ctx.options
|
||||||
|
},
|
||||||
|
|
||||||
|
...setupDatabaseRPC(ctx),
|
||||||
|
...setupResourceRPC(ctx),
|
||||||
|
|
||||||
|
async reset() {
|
||||||
|
const ws = await ctx.wsServer
|
||||||
|
ws.send('nuxt-mongoose:reset')
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,21 +1,22 @@
|
|||||||
import fs from 'fs-extra'
|
import fs from 'fs-extra'
|
||||||
import { resolve } from 'pathe'
|
import { join } from 'pathe'
|
||||||
import type { Collection, NuxtDevtoolsServerContext, Resource, ServerFunctions } from '../types'
|
import mongoose from 'mongoose'
|
||||||
import { generateApiRoute, generateSchemaFile } from '../utils/schematics'
|
import type { Collection, DevtoolsServerContext, Resource, ServerFunctions } from '../types'
|
||||||
import { capitalize, pluralize, singularize } from '../utils/formatting'
|
import { capitalize, generateApiRoute, generateSchemaFile, pluralize, singularize } from '../utils'
|
||||||
|
|
||||||
|
export function setupResourceRPC({ nuxt }: DevtoolsServerContext): any {
|
||||||
|
const config = nuxt.options.runtimeConfig.mongoose
|
||||||
|
|
||||||
export function setupResourceRPC({ nuxt, rpc }: NuxtDevtoolsServerContext): any {
|
|
||||||
return {
|
return {
|
||||||
// TODO: maybe separate functions
|
|
||||||
async generateResource(collection: Collection, resources: Resource[]) {
|
async generateResource(collection: Collection, resources: Resource[]) {
|
||||||
const singular = singularize(collection.name).toLowerCase()
|
const singular = singularize(collection.name).toLowerCase()
|
||||||
const plural = pluralize(collection.name).toLowerCase()
|
const plural = pluralize(collection.name).toLowerCase()
|
||||||
const dbName = capitalize(singular)
|
const dbName = capitalize(singular)
|
||||||
|
|
||||||
if (collection.fields) {
|
if (collection.fields) {
|
||||||
const schemaPath = resolve(nuxt.options.serverDir, 'utils/models', `${singular}.schema.ts`)
|
const schemaPath = join(config.modelsDir, `${singular}.schema.ts`)
|
||||||
if (!fs.existsSync(schemaPath)) {
|
if (!fs.existsSync(schemaPath)) {
|
||||||
fs.ensureDirSync(resolve(nuxt.options.serverDir, 'utils/models'))
|
fs.ensureDirSync(config.modelsDir)
|
||||||
fs.writeFileSync(schemaPath, generateSchemaFile(dbName, collection.fields))
|
fs.writeFileSync(schemaPath, generateSchemaFile(dbName, collection.fields))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,9 +35,9 @@ export function setupResourceRPC({ nuxt, rpc }: NuxtDevtoolsServerContext): any
|
|||||||
? (routeTypes[route.type] as any)(route.by)
|
? (routeTypes[route.type] as any)(route.by)
|
||||||
: routeTypes[route.type]
|
: routeTypes[route.type]
|
||||||
|
|
||||||
const filePath = resolve(nuxt.options.serverDir, 'api', plural, fileName)
|
const filePath = join(nuxt.options.serverDir, 'api', plural, fileName)
|
||||||
if (!fs.existsSync(filePath)) {
|
if (!fs.existsSync(filePath)) {
|
||||||
fs.ensureDirSync(resolve(nuxt.options.serverDir, `api/${plural}`))
|
fs.ensureDirSync(join(nuxt.options.serverDir, `api/${plural}`))
|
||||||
const content = generateApiRoute(route.type, { model, by: route.by })
|
const content = generateApiRoute(route.type, { model, by: route.by })
|
||||||
fs.writeFileSync(filePath, content)
|
fs.writeFileSync(filePath, content)
|
||||||
}
|
}
|
||||||
@ -44,14 +45,13 @@ export function setupResourceRPC({ nuxt, rpc }: NuxtDevtoolsServerContext): any
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create collection if not exists
|
// create collection if not exists
|
||||||
const collections = await rpc.functions.listCollections()
|
const collections = await mongoose.connection.db.listCollections().toArray()
|
||||||
if (!collections.find((c: any) => c.name === plural))
|
if (!collections.find((c: any) => c.name === plural))
|
||||||
await rpc.functions.createCollection(plural)
|
return await mongoose.connection.db.createCollection(plural)
|
||||||
},
|
},
|
||||||
async resourceSchema(collection: string) {
|
async resourceSchema(collection: string) {
|
||||||
// TODO: use magicast
|
|
||||||
const singular = singularize(collection).toLowerCase()
|
const singular = singularize(collection).toLowerCase()
|
||||||
const schemaPath = resolve(nuxt.options.serverDir, 'utils/models', `${singular}.schema.ts`)
|
const schemaPath = join(config.modelsDir, `${singular}.schema.ts`)
|
||||||
if (fs.existsSync(schemaPath)) {
|
if (fs.existsSync(schemaPath)) {
|
||||||
const content = fs.readFileSync(schemaPath, 'utf-8').match(/schema: \{(.|\n)*\}/g)
|
const content = fs.readFileSync(schemaPath, 'utf-8').match(/schema: \{(.|\n)*\}/g)
|
||||||
if (content) {
|
if (content) {
|
||||||
@ -1,8 +0,0 @@
|
|||||||
import type { mongo } from 'mongoose'
|
|
||||||
import { connection } from 'mongoose'
|
|
||||||
|
|
||||||
export function useMongoose(): { db: mongo.Db } {
|
|
||||||
return {
|
|
||||||
db: connection?.db,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,8 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* Due to an upstream bug in Nuxt 3 we need to stub the plugin here, track:https://github.com/nuxt/nuxt/issues/18556
|
* Due to an upstream bug in Nuxt 3 we need to stub the plugin here, track:https://github.com/nuxt/nuxt/issues/18556
|
||||||
* */
|
*/
|
||||||
import type { NitroApp } from 'nitropack'
|
import type { NitroApp } from 'nitropack'
|
||||||
import { defineMongooseConnection } from '../services/mongoose'
|
import { defineMongooseConnection } from '../services'
|
||||||
|
|
||||||
type NitroAppPlugin = (nitro: NitroApp) => void
|
type NitroAppPlugin = (nitro: NitroApp) => void
|
||||||
|
|
||||||
|
|||||||
@ -1 +1,49 @@
|
|||||||
export { defineMongooseConnection, defineMongooseModel } from './mongoose'
|
import { logger } from '@nuxt/kit'
|
||||||
|
import mongoose from 'mongoose'
|
||||||
|
import type { ConnectOptions, Model, SchemaDefinition, SchemaOptions } from 'mongoose'
|
||||||
|
|
||||||
|
import { useRuntimeConfig } from '#imports'
|
||||||
|
|
||||||
|
export async function defineMongooseConnection({ uri, options }: { uri?: string; options?: ConnectOptions } = {}): Promise<void> {
|
||||||
|
const config = useRuntimeConfig().mongoose
|
||||||
|
const mongooseUri = uri || config.uri
|
||||||
|
const mongooseOptions = options || config.options
|
||||||
|
|
||||||
|
try {
|
||||||
|
await mongoose.connect(mongooseUri, { ...mongooseOptions })
|
||||||
|
logger.success('Connected to `MongoDB`')
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
logger.error('Error connecting to `MongoDB`', err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function defineMongooseModel<T>(
|
||||||
|
nameOrOptions: string | {
|
||||||
|
name: string
|
||||||
|
schema: SchemaDefinition<T>
|
||||||
|
options?: SchemaOptions
|
||||||
|
hooks?: (schema: mongoose.Schema<T>) => void
|
||||||
|
},
|
||||||
|
schema?: SchemaDefinition<T>,
|
||||||
|
options?: SchemaOptions,
|
||||||
|
hooks?: (schema: mongoose.Schema<T>) => void,
|
||||||
|
): Model<T> {
|
||||||
|
let name: string
|
||||||
|
if (typeof nameOrOptions === 'string') {
|
||||||
|
name = nameOrOptions
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
name = nameOrOptions.name
|
||||||
|
schema = nameOrOptions.schema
|
||||||
|
options = nameOrOptions.options
|
||||||
|
hooks = nameOrOptions.hooks
|
||||||
|
}
|
||||||
|
|
||||||
|
const newSchema = new mongoose.Schema<T>(schema, options as any)
|
||||||
|
|
||||||
|
if (hooks)
|
||||||
|
hooks(newSchema)
|
||||||
|
|
||||||
|
return mongoose.model<T>(name, newSchema)
|
||||||
|
}
|
||||||
|
|||||||
@ -1,36 +0,0 @@
|
|||||||
import type { ConnectOptions, Model, SchemaDefinition, SchemaOptions } from 'mongoose'
|
|
||||||
import mongoose from 'mongoose'
|
|
||||||
import { logger } from '@nuxt/kit'
|
|
||||||
|
|
||||||
import { useRuntimeConfig } from '#imports'
|
|
||||||
|
|
||||||
export async function defineMongooseConnection({ uri, options }: { uri?: string; options?: ConnectOptions } = {}): Promise<void> {
|
|
||||||
const config = useRuntimeConfig().public.mongoose
|
|
||||||
const mongooseUri = uri || config.uri
|
|
||||||
const mongooseOptions = options || config.options
|
|
||||||
|
|
||||||
try {
|
|
||||||
await mongoose.connect(mongooseUri, { ...mongooseOptions })
|
|
||||||
logger.info('Connected to database')
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
logger.error('Error connecting to database', err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function defineMongooseModel(nameOrOptions: string | { name: string; schema: SchemaDefinition; options?: SchemaOptions }, schema?: SchemaDefinition, options?: SchemaOptions): Model<any> {
|
|
||||||
let name: string
|
|
||||||
if (typeof nameOrOptions === 'string') {
|
|
||||||
name = nameOrOptions
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
name = nameOrOptions.name
|
|
||||||
schema = nameOrOptions.schema
|
|
||||||
options = nameOrOptions.options
|
|
||||||
}
|
|
||||||
|
|
||||||
const newSchema = new mongoose.Schema({
|
|
||||||
...schema,
|
|
||||||
}, { ...options })
|
|
||||||
return mongoose.model(name, newSchema)
|
|
||||||
}
|
|
||||||
@ -1,103 +0,0 @@
|
|||||||
import type { TinyWSRequest } from 'tinyws'
|
|
||||||
import type { NodeIncomingMessage, NodeServerResponse } from 'h3'
|
|
||||||
import type { WebSocket } from 'ws'
|
|
||||||
import { createBirpcGroup } from 'birpc'
|
|
||||||
import type { ChannelOptions } from 'birpc'
|
|
||||||
|
|
||||||
import { parse, stringify } from 'flatted'
|
|
||||||
import type { Nuxt } from 'nuxt/schema'
|
|
||||||
import type { ClientFunctions, ModuleOptions, NuxtDevtoolsServerContext, ServerFunctions } from '../types'
|
|
||||||
import { setupDatabaseRPC } from './database'
|
|
||||||
import { setupResourceRPC } from './resource'
|
|
||||||
|
|
||||||
export function setupRPC(nuxt: Nuxt, options: ModuleOptions): any {
|
|
||||||
const serverFunctions = {} as ServerFunctions
|
|
||||||
const extendedRpcMap = new Map<string, any>()
|
|
||||||
const rpc = createBirpcGroup<ClientFunctions, ServerFunctions>(
|
|
||||||
serverFunctions,
|
|
||||||
[],
|
|
||||||
{
|
|
||||||
resolver: (name, fn) => {
|
|
||||||
if (fn)
|
|
||||||
return fn
|
|
||||||
|
|
||||||
if (!name.includes(':'))
|
|
||||||
return
|
|
||||||
|
|
||||||
const [namespace, fnName] = name.split(':')
|
|
||||||
return extendedRpcMap.get(namespace)?.[fnName]
|
|
||||||
},
|
|
||||||
onError(error, name) {
|
|
||||||
console.error(`[nuxt-devtools] RPC error on executing "${name}":`, error)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
function refresh(event: keyof ServerFunctions) {
|
|
||||||
rpc.broadcast.refresh.asEvent(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
function extendServerRpc(namespace: string, functions: any): any {
|
|
||||||
extendedRpcMap.set(namespace, functions)
|
|
||||||
|
|
||||||
return {
|
|
||||||
broadcast: new Proxy({}, {
|
|
||||||
get: (_, key) => {
|
|
||||||
if (typeof key !== 'string')
|
|
||||||
return
|
|
||||||
return (rpc.broadcast as any)[`${namespace}:${key}`]
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const ctx: NuxtDevtoolsServerContext = {
|
|
||||||
nuxt,
|
|
||||||
options,
|
|
||||||
rpc,
|
|
||||||
refresh,
|
|
||||||
extendServerRpc,
|
|
||||||
}
|
|
||||||
|
|
||||||
// @ts-expect-error untyped
|
|
||||||
nuxt.devtools = ctx
|
|
||||||
|
|
||||||
Object.assign(serverFunctions, {
|
|
||||||
...setupDatabaseRPC(ctx),
|
|
||||||
...setupResourceRPC(ctx),
|
|
||||||
} satisfies Partial<ServerFunctions>)
|
|
||||||
|
|
||||||
const wsClients = new Set<WebSocket>()
|
|
||||||
const middleware = async (req: NodeIncomingMessage & TinyWSRequest, _res: NodeServerResponse, next: Function) => {
|
|
||||||
// Handle WebSocket
|
|
||||||
if (req.ws) {
|
|
||||||
const ws = await req.ws()
|
|
||||||
wsClients.add(ws)
|
|
||||||
const channel: ChannelOptions = {
|
|
||||||
post: d => ws.send(d),
|
|
||||||
on: fn => ws.on('message', fn),
|
|
||||||
serialize: stringify,
|
|
||||||
deserialize: parse,
|
|
||||||
}
|
|
||||||
rpc.updateChannels((c) => {
|
|
||||||
c.push(channel)
|
|
||||||
})
|
|
||||||
ws.on('close', () => {
|
|
||||||
wsClients.delete(ws)
|
|
||||||
rpc.updateChannels((c) => {
|
|
||||||
const index = c.indexOf(channel)
|
|
||||||
if (index >= 0)
|
|
||||||
c.splice(index, 1)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
next()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
middleware,
|
|
||||||
...ctx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,3 +1,47 @@
|
|||||||
export * from './rpc'
|
import type { Nuxt } from 'nuxt/schema'
|
||||||
export * from './server-ctx'
|
import type { WebSocketServer } from 'vite'
|
||||||
export * from './module-options'
|
import type { ModuleOptions } from '../module'
|
||||||
|
|
||||||
|
export interface ServerFunctions {
|
||||||
|
getOptions(): ModuleOptions
|
||||||
|
|
||||||
|
// Database - collections
|
||||||
|
readyState(): Promise<any>
|
||||||
|
createCollection(name: string): Promise<any>
|
||||||
|
listCollections(): Promise<any>
|
||||||
|
getCollection(name: string): Promise<any>
|
||||||
|
dropCollection(name: string): Promise<any>
|
||||||
|
|
||||||
|
// Database - documents
|
||||||
|
createDocument(collection: string, data: any): Promise<any>
|
||||||
|
countDocuments(collection: string): Promise<any>
|
||||||
|
listDocuments(collection: string, options: any): Promise<any>
|
||||||
|
getDocument(collection: string, id: string): Promise<any>
|
||||||
|
updateDocument(collection: string, data: any): Promise<any>
|
||||||
|
deleteDocument(collection: string, id: string): Promise<any>
|
||||||
|
|
||||||
|
// Resource - api-routes & models
|
||||||
|
generateResource(collection: Collection, resources: Resource[]): Promise<any>
|
||||||
|
resourceSchema(collection: string): Promise<any>
|
||||||
|
|
||||||
|
reset(): void
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ClientFunctions {
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DevtoolsServerContext {
|
||||||
|
nuxt: Nuxt
|
||||||
|
options: ModuleOptions
|
||||||
|
wsServer: Promise<WebSocketServer>
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Collection {
|
||||||
|
name: string
|
||||||
|
fields?: object[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Resource {
|
||||||
|
type: 'index' | 'create' | 'show' | 'put' | 'delete'
|
||||||
|
by?: string
|
||||||
|
}
|
||||||
|
|||||||
@ -1,7 +0,0 @@
|
|||||||
import type { ConnectOptions } from 'mongoose'
|
|
||||||
|
|
||||||
export interface ModuleOptions {
|
|
||||||
uri: string
|
|
||||||
devtools: boolean
|
|
||||||
options?: ConnectOptions
|
|
||||||
}
|
|
||||||
@ -1,34 +0,0 @@
|
|||||||
export interface ServerFunctions {
|
|
||||||
// Database - collections
|
|
||||||
readyState(): Promise<any>
|
|
||||||
createCollection(name: string): Promise<any>
|
|
||||||
listCollections(): Promise<any>
|
|
||||||
getCollection(name: string): Promise<any>
|
|
||||||
dropCollection(name: string): Promise<any>
|
|
||||||
|
|
||||||
// Database - documents
|
|
||||||
createDocument(collection: string, data: any): Promise<any>
|
|
||||||
countDocuments(collection: string): Promise<any>
|
|
||||||
listDocuments(collection: string, options: any): Promise<any>
|
|
||||||
getDocument(collection: string, id: string): Promise<any>
|
|
||||||
updateDocument(collection: string, data: any): Promise<any>
|
|
||||||
deleteDocument(collection: string, id: string): Promise<any>
|
|
||||||
|
|
||||||
// Resource - api-routes & models
|
|
||||||
generateResource(collection: Collection, resources: Resource[]): Promise<any>
|
|
||||||
resourceSchema(collection: string): Promise<any>
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ClientFunctions {
|
|
||||||
refresh(type: string): void
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Collection {
|
|
||||||
name: string
|
|
||||||
fields?: {}[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Resource {
|
|
||||||
type: 'index' | 'create' | 'show' | 'put' | 'delete'
|
|
||||||
by?: string
|
|
||||||
}
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
import type { BirpcGroup } from 'birpc'
|
|
||||||
import type { Nuxt } from 'nuxt/schema'
|
|
||||||
import type { ClientFunctions, ServerFunctions } from './rpc'
|
|
||||||
import type { ModuleOptions } from './module-options'
|
|
||||||
|
|
||||||
export interface NuxtDevtoolsServerContext {
|
|
||||||
nuxt: Nuxt
|
|
||||||
options: ModuleOptions
|
|
||||||
|
|
||||||
rpc: BirpcGroup<ClientFunctions, ServerFunctions>
|
|
||||||
|
|
||||||
refresh: (event: keyof ServerFunctions) => void
|
|
||||||
|
|
||||||
extendServerRpc: <ClientFunctions = {}, ServerFunctions = {}>(name: string, functions: ServerFunctions) => BirpcGroup<ClientFunctions, ServerFunctions>
|
|
||||||
}
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
import plrz from 'pluralize'
|
|
||||||
|
|
||||||
export function normalizeToKebabOrSnakeCase(str: string) {
|
|
||||||
const STRING_DASHERIZE_REGEXP = /\s/g
|
|
||||||
const STRING_DECAMELIZE_REGEXP = /([a-z\d])([A-Z])/g
|
|
||||||
return str
|
|
||||||
.replace(STRING_DECAMELIZE_REGEXP, '$1-$2')
|
|
||||||
.toLowerCase()
|
|
||||||
.replace(STRING_DASHERIZE_REGEXP, '-')
|
|
||||||
}
|
|
||||||
|
|
||||||
export function pluralize(str: string) {
|
|
||||||
return plrz.plural(str)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function singularize(str: string) {
|
|
||||||
return plrz.singular(str)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function capitalize(str: string) {
|
|
||||||
return str.charAt(0).toUpperCase() + str.slice(1)
|
|
||||||
}
|
|
||||||
@ -1,4 +1,35 @@
|
|||||||
import { capitalize } from './formatting'
|
import type { WebSocketServer } from 'vite'
|
||||||
|
import type { Nuxt } from 'nuxt/schema'
|
||||||
|
import plrz from 'pluralize'
|
||||||
|
|
||||||
|
export function useViteWebSocket(nuxt: Nuxt) {
|
||||||
|
return new Promise<WebSocketServer>((_resolve) => {
|
||||||
|
nuxt.hooks.hook('vite:serverCreated', (viteServer) => {
|
||||||
|
_resolve(viteServer.ws)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function normalizeToKebabOrSnakeCase(str: string) {
|
||||||
|
const STRING_DASHERIZE_REGEXP = /\s/g
|
||||||
|
const STRING_DECAMELIZE_REGEXP = /([a-z\d])([A-Z])/g
|
||||||
|
return str
|
||||||
|
.replace(STRING_DECAMELIZE_REGEXP, '$1-$2')
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(STRING_DASHERIZE_REGEXP, '-')
|
||||||
|
}
|
||||||
|
|
||||||
|
export function pluralize(str: string) {
|
||||||
|
return plrz.plural(str)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function singularize(str: string) {
|
||||||
|
return plrz.singular(str)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function capitalize(str: string) {
|
||||||
|
return str.charAt(0).toUpperCase() + str.slice(1)
|
||||||
|
}
|
||||||
|
|
||||||
export function generateSchemaFile(name: string, fields: any) {
|
export function generateSchemaFile(name: string, fields: any) {
|
||||||
name = capitalize(name)
|
name = capitalize(name)
|
||||||
@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"extends": "./client/.nuxt/tsconfig.json"
|
"extends": "./playground/.nuxt/tsconfig.json"
|
||||||
}
|
}
|
||||||
|
|||||||
1
types.d.ts
vendored
1
types.d.ts
vendored
@ -1 +0,0 @@
|
|||||||
export * from './dist/types'
|
|
||||||
Reference in New Issue
Block a user