Compare commits
10 Commits
studio/all
...
v1.0.5
| Author | SHA1 | Date | |
|---|---|---|---|
| d746f451dd | |||
| 5a7936aac4 | |||
| 64a4fa5383 | |||
| bf7f9db63d | |||
| 71837428dd | |||
| 12d62d873b | |||
| 61cc32381b | |||
| 42b3b8375a | |||
| bdab2c5395 | |||
| d6b8e91f06 |
44
CHANGELOG.md
44
CHANGELOG.md
@ -1,6 +1,50 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
|
||||||
|
## 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
|
## v1.0.3
|
||||||
|
|
||||||
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v1.0.2...v1.0.3)
|
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v1.0.2...v1.0.3)
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||

|

|
||||||
|
|
||||||
<div align="center">
|
<div align="center">
|
||||||
<h1>Nuxt Mongoose</h1>
|
<h1>Nuxt Mongoose</h1>
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "docus-starter",
|
"name": "nuxt-mongoose-docs",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -11,7 +11,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nuxt-themes/docus": "^1.15.0",
|
"@nuxt-themes/docus": "^1.15.0",
|
||||||
"@nuxthq/studio": "^1.0.2",
|
"@nuxthq/studio": "^1.0.8",
|
||||||
"nuxt": "^3.8.0"
|
"nuxt": "^3.9.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
4465
docs/pnpm-lock.yaml
generated
4465
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 After Width: | Height: | Size: 237 KiB |
24
package.json
24
package.json
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "nuxt-mongoose",
|
"name": "nuxt-mongoose",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "1.0.3",
|
"version": "1.0.5",
|
||||||
"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",
|
||||||
@ -49,26 +49,26 @@
|
|||||||
"lint": "eslint . --fix"
|
"lint": "eslint . --fix"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nuxt/devtools-kit": "1.0.0",
|
"@nuxt/devtools-kit": "1.0.8",
|
||||||
"@nuxt/devtools-ui-kit": "1.0.0",
|
"@nuxt/devtools-ui-kit": "1.0.8",
|
||||||
"@nuxt/kit": "^3.9.0",
|
"@nuxt/kit": "^3.9.3",
|
||||||
"@vueuse/core": "^10.7.1",
|
"@vueuse/core": "^10.7.2",
|
||||||
"defu": "^6.1.3",
|
"defu": "^6.1.4",
|
||||||
"fs-extra": "^11.2.0",
|
"fs-extra": "^11.2.0",
|
||||||
"mongoose": "^7.6.7",
|
"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.4"
|
"sirv": "^2.0.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@antfu/eslint-config": "1.0.0-beta.29",
|
"@antfu/eslint-config": "2.6.3",
|
||||||
"@nuxt/module-builder": "^0.5.5",
|
"@nuxt/module-builder": "^0.5.5",
|
||||||
"@types/fs-extra": "^11.0.4",
|
"@types/fs-extra": "^11.0.4",
|
||||||
"@types/pluralize": "^0.0.32",
|
"@types/pluralize": "^0.0.33",
|
||||||
"changelogen": "^0.5.5",
|
"changelogen": "^0.5.5",
|
||||||
"eslint": "8.52.0",
|
"eslint": "8.56.0",
|
||||||
"nuxt": "^3.9.0",
|
"nuxt": "^3.9.3",
|
||||||
"sass": "^1.69.7"
|
"sass": "^1.69.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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>
|
||||||
|
|||||||
2926
pnpm-lock.yaml
generated
2926
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
21
src/runtime/server/services/connection.ts
Normal file
21
src/runtime/server/services/connection.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
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
|
||||||
|
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}`))
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,49 +1,2 @@
|
|||||||
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'
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|||||||
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