Compare commits
35 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 37b5e425c4 | |||
| 32deb047c5 | |||
| 4036c56010 | |||
| c62ae2e134 | |||
| eb7ad636dc | |||
| ffb1eb43c7 | |||
| f504c6b79a | |||
| 6b4d1ed0ae | |||
| 3ef0d69ded | |||
| edcf10eea1 | |||
| 89d50bd977 | |||
| 30407511a4 | |||
| 0abeb6b265 | |||
| d746f451dd | |||
| 5a7936aac4 | |||
| 64a4fa5383 | |||
| bf7f9db63d | |||
| 71837428dd | |||
| 12d62d873b | |||
| 61cc32381b | |||
| 42b3b8375a | |||
| bdab2c5395 | |||
| d6b8e91f06 | |||
| 8bb7665af5 | |||
| 644ccc237d | |||
| 84a2c821e9 | |||
| 386c7dac05 | |||
| 1bec7a703d | |||
| 0b575fa322 | |||
| 4c5a0345a8 | |||
| ea7c7b02d6 | |||
| 9296ae7d78 | |||
| 549b2f30be | |||
| 4bc07425b4 | |||
| b0fb2edc24 |
2
.github/workflows/studio.yml
vendored
2
.github/workflows/studio.yml
vendored
@ -58,7 +58,7 @@ jobs:
|
|||||||
cache: ${{ steps.pkgman.outputs.cache }}
|
cache: ${{ steps.pkgman.outputs.cache }}
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: ${{ steps.pkgman.outputs.package_manager }} install
|
run: ${{ steps.pkgman.outputs.package_manager }} install --no-frozen-lockfile
|
||||||
|
|
||||||
- name: Install @nuxthq/studio
|
- name: Install @nuxthq/studio
|
||||||
run: ${{ steps.pkgman.outputs.package_manager }} add -D @nuxthq/studio
|
run: ${{ steps.pkgman.outputs.package_manager }} add -D @nuxthq/studio
|
||||||
|
|||||||
2
.nuxtrc
Normal file
2
.nuxtrc
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# enable TypeScript bundler module resolution - https://www.typescriptlang.org/docs/handbook/modules/reference.html#bundler
|
||||||
|
experimental.typescriptBundlerResolution=true
|
||||||
105
CHANGELOG.md
105
CHANGELOG.md
@ -1,6 +1,111 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
|
||||||
|
## v1.0.6
|
||||||
|
|
||||||
|
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v1.0.4...v1.1.0)
|
||||||
|
|
||||||
|
### 🚀 Enhancements
|
||||||
|
|
||||||
|
- Add discriminator helper ([#47](https://github.com/arashsheyda/nuxt-mongoose/pull/47))
|
||||||
|
|
||||||
|
### 🩹 Fixes
|
||||||
|
|
||||||
|
- Replace consola with logger ([5a7936a](https://github.com/arashsheyda/nuxt-mongoose/commit/5a7936a))
|
||||||
|
- Continue module setup process Without MONGODB_URI ([#54](https://github.com/arashsheyda/nuxt-mongoose/pull/54))
|
||||||
|
|
||||||
|
### 📖 Documentation
|
||||||
|
|
||||||
|
- Update examples ([0abeb6b](https://github.com/arashsheyda/nuxt-mongoose/commit/0abeb6b))
|
||||||
|
- Fix examples list ([3040751](https://github.com/arashsheyda/nuxt-mongoose/commit/3040751))
|
||||||
|
- Use new `nuxi module add` command in installation ([#53](https://github.com/arashsheyda/nuxt-mongoose/pull/53))
|
||||||
|
|
||||||
|
### 🏡 Chore
|
||||||
|
|
||||||
|
- **release:** V1.0.4 ([64a4fa5](https://github.com/arashsheyda/nuxt-mongoose/commit/64a4fa5))
|
||||||
|
- **release:** V1.0.5 ([d746f45](https://github.com/arashsheyda/nuxt-mongoose/commit/d746f45))
|
||||||
|
- Update readme with documentation redirection ([89d50bd](https://github.com/arashsheyda/nuxt-mongoose/commit/89d50bd))
|
||||||
|
- Move docs ([f504c6b](https://github.com/arashsheyda/nuxt-mongoose/commit/f504c6b))
|
||||||
|
- Update readme ([ffb1eb4](https://github.com/arashsheyda/nuxt-mongoose/commit/ffb1eb4))
|
||||||
|
|
||||||
|
### ❤️ Contributors
|
||||||
|
|
||||||
|
- Arash ([@arashsheyda](http://github.com/arashsheyda))
|
||||||
|
- Justin Bellero <jpbellero@gmail.com>
|
||||||
|
- Roryc ([@Coiggahou2002](http://github.com/Coiggahou2002))
|
||||||
|
- Daniel Roe ([@danielroe](http://github.com/danielroe))
|
||||||
|
|
||||||
|
## v1.0.5
|
||||||
|
|
||||||
|
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v1.0.4...v1.0.5)
|
||||||
|
|
||||||
|
### 🩹 Fixes
|
||||||
|
|
||||||
|
- Replace consola with logger ([5a7936a](https://github.com/arashsheyda/nuxt-mongoose/commit/5a7936a))
|
||||||
|
|
||||||
|
### 🏡 Chore
|
||||||
|
|
||||||
|
- **release:** V1.0.4 ([64a4fa5](https://github.com/arashsheyda/nuxt-mongoose/commit/64a4fa5))
|
||||||
|
|
||||||
|
### ❤️ Contributors
|
||||||
|
|
||||||
|
- Arash <arashi.sheyda@gmail.com>
|
||||||
|
|
||||||
|
## v1.0.4
|
||||||
|
|
||||||
|
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v1.0.3...v1.0.5)
|
||||||
|
|
||||||
|
### 💅 Refactors
|
||||||
|
|
||||||
|
- Split services into individual files ([d6b8e91](https://github.com/arashsheyda/nuxt-mongoose/commit/d6b8e91))
|
||||||
|
|
||||||
|
### 📖 Documentation
|
||||||
|
|
||||||
|
- Update dependencies ([12d62d8](https://github.com/arashsheyda/nuxt-mongoose/commit/12d62d8))
|
||||||
|
- Update dependencies ([7183742](https://github.com/arashsheyda/nuxt-mongoose/commit/7183742))
|
||||||
|
|
||||||
|
### 🏡 Chore
|
||||||
|
|
||||||
|
- Test bundler module resolution ([#36](https://github.com/arashsheyda/nuxt-mongoose/pull/36))
|
||||||
|
- Update dependencies ([#38](https://github.com/arashsheyda/nuxt-mongoose/pull/38))
|
||||||
|
- Update dependencies ([bdab2c5](https://github.com/arashsheyda/nuxt-mongoose/commit/bdab2c5))
|
||||||
|
- Update playground ([42b3b83](https://github.com/arashsheyda/nuxt-mongoose/commit/42b3b83))
|
||||||
|
- Update cover ([61cc323](https://github.com/arashsheyda/nuxt-mongoose/commit/61cc323))
|
||||||
|
- Update cover ([bf7f9db](https://github.com/arashsheyda/nuxt-mongoose/commit/bf7f9db))
|
||||||
|
|
||||||
|
### ❤️ Contributors
|
||||||
|
|
||||||
|
- Arash
|
||||||
|
- Amir H. Moayeri
|
||||||
|
- Daniel Roe <daniel@roe.dev>
|
||||||
|
|
||||||
|
## v1.0.3
|
||||||
|
|
||||||
|
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v1.0.2...v1.0.3)
|
||||||
|
|
||||||
|
### 🩹 Fixes
|
||||||
|
|
||||||
|
- Add schema type ([4bc0742](https://github.com/arashsheyda/nuxt-mongoose/commit/4bc0742))
|
||||||
|
|
||||||
|
### 💅 Refactors
|
||||||
|
|
||||||
|
- Update to DevTools v1 ([1bec7a7](https://github.com/arashsheyda/nuxt-mongoose/commit/1bec7a7))
|
||||||
|
|
||||||
|
### 📖 Documentation
|
||||||
|
|
||||||
|
- Update ui ([9296ae7](https://github.com/arashsheyda/nuxt-mongoose/commit/9296ae7))
|
||||||
|
- Fix playground path ([ea7c7b0](https://github.com/arashsheyda/nuxt-mongoose/commit/ea7c7b0))
|
||||||
|
- Fix install workflow ([4c5a034](https://github.com/arashsheyda/nuxt-mongoose/commit/4c5a034))
|
||||||
|
- Update link ([0b575fa](https://github.com/arashsheyda/nuxt-mongoose/commit/0b575fa))
|
||||||
|
|
||||||
|
### 🏡 Chore
|
||||||
|
|
||||||
|
- Remove comment ([549b2f3](https://github.com/arashsheyda/nuxt-mongoose/commit/549b2f3))
|
||||||
|
|
||||||
|
### ❤️ Contributors
|
||||||
|
|
||||||
|
- Arash
|
||||||
|
|
||||||
## v1.0.2
|
## v1.0.2
|
||||||
|
|
||||||
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v1.0.1...v1.0.2)
|
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v1.0.1...v1.0.2)
|
||||||
|
|||||||
61
README.md
61
README.md
@ -1,4 +1,4 @@
|
|||||||

|

|
||||||
|
|
||||||
<div align="center">
|
<div align="center">
|
||||||
<h1>Nuxt Mongoose</h1>
|
<h1>Nuxt Mongoose</h1>
|
||||||
@ -10,7 +10,7 @@
|
|||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pnpm add nuxt-mongoose
|
npx nuxi@latest module add nuxt-mongoose
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@ -29,7 +29,7 @@ export default defineNuxtConfig({
|
|||||||
|
|
||||||
### Configuration
|
### Configuration
|
||||||
|
|
||||||
You can configure the module by adding a `mongoose` section to your `nuxt.config` file.
|
You can configure the module by adding a `mongoose` section to your `nuxt.config` file:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
export default defineNuxtConfig({
|
export default defineNuxtConfig({
|
||||||
@ -41,9 +41,26 @@ export default defineNuxtConfig({
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
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.
|
By default, `nuxt-mongoose` will auto-import your schemas from the `models` directory in the `server` directory. You can change this behavior by setting the `modelsDir` option.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### 🛠️ **Quick Setup Without Configuration**
|
||||||
|
|
||||||
|
If you prefer to use the default configuration, skip adding the `mongoose` section to your `nuxt.config.ts` file. Simply provide your MongoDB connection URI in a `.env` file like this:
|
||||||
|
|
||||||
|
```env
|
||||||
|
MONGODB_URI="mongodb+srv://username:password@cluster0.mongodb.net/<database-name>?retryWrites=true&w=majority"
|
||||||
|
```
|
||||||
|
|
||||||
|
> 🔹 Replace `username`, `password`, and `<database name>` with your MongoDB credentials and database name.
|
||||||
|
|
||||||
|
That's it! The module will automatically use the `MONGODB_URI` and default settings for your connection. No additional configuration is required.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
*For more details about connection options, check out 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
|
||||||
|
|
||||||
@ -86,6 +103,40 @@ export const User = defineMongooseModel({
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
#### Connecting to an Existing Collection
|
||||||
|
|
||||||
|
If you need to connect to an **existing collection** in the database, you must specify the collection name using the `options` field. Otherwise, Mongoose will create a new collection based on the model name.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { defineMongooseModel } from '#nuxt/mongoose'
|
||||||
|
|
||||||
|
export const ProductSchema = defineMongooseModel({
|
||||||
|
name: 'Product',
|
||||||
|
schema: {
|
||||||
|
name: { type: String, required: true },
|
||||||
|
price: { type: Number, required: true },
|
||||||
|
stock: { type: Number, default: 0 },
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
collection: 'products_collection', // Ensure it uses the correct collection name
|
||||||
|
},
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### Important Notes
|
||||||
|
|
||||||
|
- Using the `options.collection` field ensures that the model interacts with the specified collection (`products_collection` in the example above).
|
||||||
|
- Without this option, a new collection will be created using the pluralized version of the model name (e.g., `Products`).
|
||||||
|
|
||||||
|
|
||||||
|
### Configuration
|
||||||
|
|
||||||
|
For detailed [configuration](https://docs.arashsheyda.me/nuxt-mongoose/getting-started/configuration) and usage instructions, please refer to our [documentation](https://docs.arashsheyda.me/nuxt-mongoose).
|
||||||
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
[MIT License](./LICENSE)
|
[MIT License](./LICENSE)
|
||||||
|
|||||||
@ -1,11 +1,6 @@
|
|||||||
<script lang="ts" setup>
|
|
||||||
import './styles/global.css'
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Html>
|
<Html>
|
||||||
<Body h-screen>
|
<Body h-screen>
|
||||||
<Notification />
|
|
||||||
<NuxtLayout>
|
<NuxtLayout>
|
||||||
<NuxtPage />
|
<NuxtPage />
|
||||||
</NuxtLayout>
|
</NuxtLayout>
|
||||||
|
|||||||
@ -249,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-trash-can" n="red" @click="removeField(index)" />
|
<NButton icon="carbon-trash-can" n="red" @click="removeField(index)" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -125,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
|
||||||
@ -155,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>
|
||||||
@ -180,14 +180,14 @@ const copy = useCopy()
|
|||||||
<td>
|
<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 title="Save" icon="carbon-save" @click="saveDocument(selectedDocument, false)" />
|
<NButton title="Save" icon="carbon-save" n="blue" @click="saveDocument(selectedDocument, false)" />
|
||||||
<NIconButton title="Cancel" icon="carbon-close" @click="discardEditing" />
|
<NButton title="Cancel" icon="carbon-close" n="red" @click="discardEditing" />
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<NIconButton title="Edit" icon="carbon-edit" @click="editDocument(document)" />
|
<NButton title="Edit" icon="carbon-edit" n="blue" @click="editDocument(document)" />
|
||||||
<NIconButton title="Delete" icon="carbon-trash-can" @click="deleteDocument(document)" />
|
<NButton title="Delete" icon="carbon-trash-can" n="red" @click="deleteDocument(document)" />
|
||||||
<NIconButton title="Duplicate" icon="carbon-document-multiple-02" @click="saveDocument(document)" />
|
<NButton title="Duplicate" icon="carbon-document-multiple-02" n="cyan" @click="saveDocument(document)" />
|
||||||
<NIconButton title="Copy" n="xs" 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>
|
||||||
@ -198,8 +198,8 @@ const copy = useCopy()
|
|||||||
<input v-else placeholder="ObjectId(_id)" disabled>
|
<input v-else placeholder="ObjectId(_id)" disabled>
|
||||||
</td>
|
</td>
|
||||||
<td flex="~ justify-center gap2">
|
<td flex="~ justify-center gap2">
|
||||||
<NIconButton title="Save" icon="carbon-save" @click="saveDocument(selectedDocument)" />
|
<NButton title="Save" icon="carbon-save" n="green" @click="saveDocument(selectedDocument)" />
|
||||||
<NIconButton title="Cancel" icon="carbon-close" @click="discardEditing" />
|
<NButton title="Cancel" icon="carbon-close" n="red" @click="discardEditing" />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@ -1,57 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { ref } from 'vue'
|
|
||||||
import { onClickOutside, useElementSize } from '@vueuse/core'
|
|
||||||
|
|
||||||
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: ['a', 'button', 'summary', '[role="dialog"]'],
|
|
||||||
})
|
|
||||||
</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"
|
|
||||||
absolute bottom-0 right-0 z-10 z-20 of-auto text-sm glass-effect
|
|
||||||
: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,34 +0,0 @@
|
|||||||
<script setup lang='ts'>
|
|
||||||
const show = ref(false)
|
|
||||||
const icon = ref<string | undefined>()
|
|
||||||
const text = ref<string | undefined>()
|
|
||||||
const classes = ref<string | undefined>()
|
|
||||||
|
|
||||||
provideNotificationFn((data) => {
|
|
||||||
text.value = data.message
|
|
||||||
icon.value = data.icon
|
|
||||||
classes.value = data.classes ?? 'text-green'
|
|
||||||
show.value = true
|
|
||||||
setTimeout(() => {
|
|
||||||
show.value = false
|
|
||||||
}, data.duration ?? 1500)
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div
|
|
||||||
fixed left-0 right-0 top-0 z-999 text-center
|
|
||||||
:class="show ? '' : 'pointer-events-none overflow-hidden'"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
border="~ base"
|
|
||||||
flex="~ inline gap2"
|
|
||||||
m-3 inline-block items-center rounded px-4 py-1 transition-all duration-300 bg-base
|
|
||||||
:style="show ? {} : { transform: 'translateY(-300%)' }"
|
|
||||||
:class="[show ? 'shadow' : 'shadow-none', classes]"
|
|
||||||
>
|
|
||||||
<div v-if="icon" :class="icon" />
|
|
||||||
<div>{{ text }}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
@ -1,33 +0,0 @@
|
|||||||
<script lang="ts" setup>
|
|
||||||
import { computed, ref } from 'vue'
|
|
||||||
import { Pane, Splitpanes } from 'splitpanes'
|
|
||||||
import 'splitpanes/dist/splitpanes.css'
|
|
||||||
|
|
||||||
const props = defineProps<{
|
|
||||||
storageKey?: string
|
|
||||||
leftSize?: number
|
|
||||||
minSize?: number
|
|
||||||
}>()
|
|
||||||
|
|
||||||
const DEFAULT = 30
|
|
||||||
|
|
||||||
const state = ref()
|
|
||||||
const key = props.storageKey
|
|
||||||
const size = key
|
|
||||||
? computed({
|
|
||||||
get: () => state.value[key] || props.leftSize || DEFAULT,
|
|
||||||
set: (v) => { state.value[key] = v },
|
|
||||||
})
|
|
||||||
: ref(props.leftSize || DEFAULT)
|
|
||||||
</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="$slots.right ? (minSize || 10) : 100">
|
|
||||||
<slot name="left" />
|
|
||||||
</Pane>
|
|
||||||
<Pane v-if="$slots.right" relative h-full class="of-auto!" :min-size="minSize || 10">
|
|
||||||
<slot name="right" />
|
|
||||||
</Pane>
|
|
||||||
</Splitpanes>
|
|
||||||
</template>
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
let _showNotification: typeof showNotification
|
|
||||||
|
|
||||||
export function showNotification(data: {
|
|
||||||
message: string
|
|
||||||
icon?: string
|
|
||||||
classes?: string
|
|
||||||
duration?: number
|
|
||||||
}) {
|
|
||||||
_showNotification?.(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function provideNotificationFn(fn: typeof showNotification) {
|
|
||||||
_showNotification = fn
|
|
||||||
}
|
|
||||||
@ -1,14 +1,14 @@
|
|||||||
import { useClipboard } from '@vueuse/core'
|
import { useClipboard } from '@vueuse/core'
|
||||||
import { showNotification } from './dialog'
|
// 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)
|
||||||
showNotification({
|
// devtoolsUiShowNotification({
|
||||||
message: 'Copied to clipboard',
|
// message: 'Copied to clipboard',
|
||||||
icon: 'carbon-copy',
|
// icon: 'carbon-copy',
|
||||||
})
|
// })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,22 +36,22 @@ async function refresh() {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<SplitPanel :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
|
<NuxtLink
|
||||||
v-for="table in filtered"
|
v-for="table in filtered"
|
||||||
:key="table.name"
|
:key="table.name"
|
||||||
:to="{ name: 'index', query: { table: 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
|
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 }"
|
:class="{ 'bg-green bg-opacity-5 text-green': selectedCollection === table.name }"
|
||||||
@click="selectedCollection = table.name"
|
@click="selectedCollection = table.name"
|
||||||
>
|
>
|
||||||
@ -59,9 +59,9 @@ async function refresh() {
|
|||||||
<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-trash-can" @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>
|
||||||
@ -78,8 +78,8 @@ async function refresh() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</SplitPanel>
|
</NSplitPane>
|
||||||
<Drawer 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" />
|
||||||
</Drawer>
|
</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
12
docs/.gitignore
vendored
@ -1,12 +0,0 @@
|
|||||||
node_modules
|
|
||||||
*.iml
|
|
||||||
.idea
|
|
||||||
*.log*
|
|
||||||
.nuxt
|
|
||||||
.vscode
|
|
||||||
.DS_Store
|
|
||||||
coverage
|
|
||||||
dist
|
|
||||||
sw.*
|
|
||||||
.env
|
|
||||||
.output
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
shamefully-hoist=true
|
|
||||||
strict-peer-dependencies=false
|
|
||||||
1
docs/README.md
Normal file
1
docs/README.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
# the docs has been moved to [arashsheyda/docs](https://github.com/arashsheyda/docs/tree/main/content/1.nuxt-mongoose)
|
||||||
@ -1,42 +0,0 @@
|
|||||||
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: 0,
|
|
||||||
collapsed: false,
|
|
||||||
exclude: [],
|
|
||||||
},
|
|
||||||
main: {
|
|
||||||
padded: true,
|
|
||||||
fluid: true,
|
|
||||||
},
|
|
||||||
header: {
|
|
||||||
logo: true,
|
|
||||||
showLinkIcon: true,
|
|
||||||
exclude: [],
|
|
||||||
fluid: true,
|
|
||||||
},
|
|
||||||
footer: {
|
|
||||||
fluid: true,
|
|
||||||
iconLinks: [
|
|
||||||
{
|
|
||||||
href: 'https://nuxt.com',
|
|
||||||
icon: 'simple-icons:nuxtdotjs',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
<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>
|
|
||||||
@ -1,36 +0,0 @@
|
|||||||
---
|
|
||||||
title: Home
|
|
||||||
navigation: false
|
|
||||||
layout: page
|
|
||||||
main:
|
|
||||||
fluid: false
|
|
||||||
---
|
|
||||||
|
|
||||||
:ellipsis{right=0px width=75% blur=150px}
|
|
||||||
|
|
||||||
::block-hero
|
|
||||||
---
|
|
||||||
cta:
|
|
||||||
- Get started
|
|
||||||
- /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
|
|
||||||
::terminal
|
|
||||||
---
|
|
||||||
content:
|
|
||||||
- npm i nuxt-mongoose -D
|
|
||||||
---
|
|
||||||
::
|
|
||||||
::
|
|
||||||
|
|
||||||
<!-- TODO: features -->
|
|
||||||
@ -1,56 +0,0 @@
|
|||||||
# 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](/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
|
|
||||||
```
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
# 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) |
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
icon: tabler:brand-mongodb
|
|
||||||
navigation.redirect: /getting-started/setup
|
|
||||||
@ -1,74 +0,0 @@
|
|||||||
# 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')
|
|
||||||
```
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
# 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"}
|
|
||||||
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
title: API
|
|
||||||
icon: tabler:book
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
export default defineNuxtConfig({
|
|
||||||
extends: '@nuxt-themes/docus',
|
|
||||||
|
|
||||||
app: {
|
|
||||||
head: {
|
|
||||||
link: [
|
|
||||||
{
|
|
||||||
rel: 'icon',
|
|
||||||
type: 'image/x-icon',
|
|
||||||
href: '/mongoose-icon.svg',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
modules: [
|
|
||||||
'@nuxthq/studio',
|
|
||||||
],
|
|
||||||
})
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"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.14.3",
|
|
||||||
"@nuxthq/studio": "^0.13.4",
|
|
||||||
"nuxt": "^3.6.3"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
6754
docs/pnpm-lock.yaml
generated
6754
docs/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
Before Width: | Height: | Size: 46 KiB |
@ -1 +0,0 @@
|
|||||||
<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>
|
|
||||||
|
Before Width: | Height: | Size: 926 B |
@ -1 +0,0 @@
|
|||||||
<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>
|
|
||||||
|
Before Width: | Height: | Size: 851 B |
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": [
|
|
||||||
"@nuxtjs"
|
|
||||||
],
|
|
||||||
"lockFileMaintenance": {
|
|
||||||
"enabled": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
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',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "./.nuxt/tsconfig.json"
|
|
||||||
}
|
|
||||||
39
package.json
39
package.json
@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "nuxt-mongoose",
|
"name": "nuxt-mongoose",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "1.0.2",
|
"version": "1.0.6",
|
||||||
"private": false,
|
"private": false,
|
||||||
"packageManager": "pnpm@8.7.4",
|
"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",
|
"funding": "https://github.com/sponsors/arashsheyda",
|
||||||
"homepage": "https://nuxt-mongoose.nuxt.space",
|
"homepage": "https://docs.arashsheyda.me/nuxt-mongoose",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/arashsheyda/nuxt-mongoose"
|
"url": "git+https://github.com/arashsheyda/nuxt-mongoose"
|
||||||
@ -39,6 +39,7 @@
|
|||||||
"dist"
|
"dist"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"prepare": "npm run build",
|
||||||
"build": "nuxt-module-build && npm run build:client",
|
"build": "nuxt-module-build && npm run build:client",
|
||||||
"build:client": "nuxi generate client",
|
"build:client": "nuxi generate client",
|
||||||
"dev": "nuxi dev playground",
|
"dev": "nuxi dev playground",
|
||||||
@ -49,28 +50,26 @@
|
|||||||
"lint": "eslint . --fix"
|
"lint": "eslint . --fix"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nuxt/devtools-kit": "^0.8.4",
|
"@nuxt/devtools-kit": "^1.3.9",
|
||||||
"@nuxt/devtools-ui-kit": "^0.8.4",
|
"@nuxt/devtools-ui-kit": "^1.3.9",
|
||||||
"@nuxt/kit": "^3.7.3",
|
"@nuxt/kit": "^3.9.3",
|
||||||
"@vueuse/core": "^10.4.1",
|
"@vueuse/core": "^10.7.2",
|
||||||
"defu": "^6.1.2",
|
"defu": "^6.1.4",
|
||||||
"fs-extra": "^11.1.1",
|
"fs-extra": "^11.2.0",
|
||||||
"mongoose": "^7.5.2",
|
"mongoose": "^8.1.0",
|
||||||
"ofetch": "^1.3.3",
|
"ofetch": "^1.3.3",
|
||||||
"pathe": "^1.1.1",
|
"pathe": "^1.1.2",
|
||||||
"pluralize": "^8.0.0",
|
"pluralize": "^8.0.0",
|
||||||
"sirv": "^2.0.3"
|
"sirv": "^2.0.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@antfu/eslint-config": "^0.43.0",
|
"@antfu/eslint-config": "2.6.3",
|
||||||
"@nuxt/module-builder": "^0.5.1",
|
"@nuxt/module-builder": "^0.5.5",
|
||||||
"@types/fs-extra": "^11.0.2",
|
"@types/fs-extra": "^11.0.4",
|
||||||
"@types/pluralize": "^0.0.30",
|
"@types/pluralize": "^0.0.33",
|
||||||
"changelogen": "^0.5.5",
|
"changelogen": "^0.5.5",
|
||||||
"eslint": "8.49.0",
|
"eslint": "8.56.0",
|
||||||
"nuxt": "^3.7.3",
|
"nuxt": "^3.9.3",
|
||||||
"sass": "^1.67.0",
|
"sass": "^1.69.7"
|
||||||
"sass-loader": "^13.3.2",
|
|
||||||
"splitpanes": "^3.1.5"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,14 @@
|
|||||||
<script setup>
|
<script setup lang="ts">
|
||||||
|
const { data } = await useFetch('/api/users')
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
Nuxt module playground!
|
Nuxt module playground!
|
||||||
|
<br>
|
||||||
|
<pre
|
||||||
|
v-html="JSON.stringify(data, null, 2)"
|
||||||
|
style="background: #131313;color: #4EA65A;padding: 20px;border-radius: 7px;text-shadow: 0px 0px 10px #00ff22;"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
5804
pnpm-lock.yaml
generated
5804
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -70,7 +70,6 @@ export default defineNuxtModule<ModuleOptions>({
|
|||||||
|
|
||||||
if (!options.uri) {
|
if (!options.uri) {
|
||||||
logger.warn('Missing MongoDB URI. You can set it in your `nuxt.config` or in your `.env` as `MONGODB_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)
|
||||||
|
|||||||
@ -1,11 +1,17 @@
|
|||||||
import mongoose from 'mongoose'
|
import mongoose from 'mongoose'
|
||||||
import type { DevtoolsServerContext, ServerFunctions } from '../types'
|
import type { DevtoolsServerContext, ServerFunctions } from '../types'
|
||||||
|
import { logger } from '@nuxt/kit'
|
||||||
|
|
||||||
import { setupDatabaseRPC } from './database'
|
import { setupDatabaseRPC } from './database'
|
||||||
import { setupResourceRPC } from './resource'
|
import { setupResourceRPC } from './resource'
|
||||||
|
|
||||||
export function setupRPC(ctx: DevtoolsServerContext): ServerFunctions {
|
export function setupRPC(ctx: DevtoolsServerContext): ServerFunctions {
|
||||||
mongoose.connect(ctx.options.uri, ctx.options.options)
|
if (!ctx.options.uri) {
|
||||||
|
ctx.options.uri = ''
|
||||||
|
logger.warn('MongoDB autoconnect is disabled, configure `uri` to enable.')
|
||||||
|
} else {
|
||||||
|
mongoose.connect(ctx.options.uri, ctx.options.options)
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getOptions() {
|
getOptions() {
|
||||||
|
|||||||
22
src/runtime/server/services/connection.ts
Normal file
22
src/runtime/server/services/connection.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import type { ConnectOptions } from 'mongoose'
|
||||||
|
import { consola } from 'consola'
|
||||||
|
import { colors } from 'consola/utils'
|
||||||
|
import mongoose from 'mongoose'
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
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
|
||||||
|
if (!(mongooseUri as string).trim()) return
|
||||||
|
const mongooseOptions = options || config.options
|
||||||
|
|
||||||
|
try {
|
||||||
|
await mongoose.connect(mongooseUri, { ...mongooseOptions })
|
||||||
|
consola.success('Connected to MongoDB')
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
consola.error(colors.red(`Error connecting to MongoDB: ${err}`))
|
||||||
|
}
|
||||||
|
}
|
||||||
33
src/runtime/server/services/discriminator.ts
Normal file
33
src/runtime/server/services/discriminator.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import type { Model, SchemaDefinition, SchemaOptions } from 'mongoose'
|
||||||
|
import mongoose from 'mongoose'
|
||||||
|
|
||||||
|
export function defineMongooseDiscriminatorModel<T>(
|
||||||
|
nameOrOptions: string | {
|
||||||
|
name: string;
|
||||||
|
baseModel: Model<T>;
|
||||||
|
schema: SchemaDefinition<T>;
|
||||||
|
options?: SchemaOptions;
|
||||||
|
hooks?: (schema: mongoose.Schema<T>) => void;
|
||||||
|
},
|
||||||
|
baseModel?: Model<T>,
|
||||||
|
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
|
||||||
|
baseModel = nameOrOptions.baseModel
|
||||||
|
schema = nameOrOptions.schema
|
||||||
|
options = nameOrOptions.options
|
||||||
|
hooks = nameOrOptions.hooks
|
||||||
|
}
|
||||||
|
|
||||||
|
const newSchema = new mongoose.Schema<T>(schema, options as any)
|
||||||
|
|
||||||
|
if (hooks)
|
||||||
|
hooks(newSchema)
|
||||||
|
|
||||||
|
return baseModel!.discriminator<T>(name, newSchema)
|
||||||
|
}
|
||||||
@ -1,50 +1,3 @@
|
|||||||
import { logger } from '@nuxt/kit'
|
export { defineMongooseConnection } from './connection'
|
||||||
import mongoose from 'mongoose'
|
export { defineMongooseModel } from './model'
|
||||||
import type { ConnectOptions, Model, SchemaDefinition, SchemaOptions } from 'mongoose'
|
export { defineMongooseDiscriminatorModel } from './discriminator'
|
||||||
|
|
||||||
import { useRuntimeConfig } from '#imports'
|
|
||||||
|
|
||||||
export async function defineMongooseConnection({ uri, options }: { uri?: string; options?: ConnectOptions } = {}): Promise<void> {
|
|
||||||
// TODO: types
|
|
||||||
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
|
|
||||||
options?: SchemaOptions
|
|
||||||
hooks?: (schema: mongoose.Schema<T>) => void
|
|
||||||
},
|
|
||||||
schema?: SchemaDefinition,
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|||||||
32
src/runtime/server/services/model.ts
Normal file
32
src/runtime/server/services/model.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import type { Model, SchemaDefinition, SchemaOptions } from 'mongoose'
|
||||||
|
import mongoose from 'mongoose'
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user