1 Commits

Author SHA1 Message Date
2ff2445969 chore(deps): update studio non-major dependencies 2024-01-09 21:04:45 +00:00
10 changed files with 4898 additions and 3309 deletions

View File

@ -1,4 +1,4 @@
![nuxt-mongoose](https://raw.githubusercontent.com/arashsheyda/nuxt-mongoose/main/docs/public/cover.jpg)
![nuxt-mongoose](https://nuxt-mongoose.nuxt.space/cover.jpg)
<div align="center">
<h1>Nuxt Mongoose</h1>

View File

@ -1,5 +1,5 @@
{
"name": "nuxt-mongoose-docs",
"name": "docus-starter",
"version": "0.1.0",
"private": true,
"scripts": {
@ -11,7 +11,7 @@
},
"devDependencies": {
"@nuxt-themes/docus": "^1.15.0",
"@nuxthq/studio": "^1.0.8",
"nuxt": "^3.9.3"
"@nuxthq/studio": "^1.0.6",
"nuxt": "^3.9.1"
}
}

5140
docs/pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 237 KiB

After

Width:  |  Height:  |  Size: 46 KiB

View File

@ -49,26 +49,26 @@
"lint": "eslint . --fix"
},
"dependencies": {
"@nuxt/devtools-kit": "1.0.8",
"@nuxt/devtools-ui-kit": "1.0.8",
"@nuxt/kit": "^3.9.3",
"@vueuse/core": "^10.7.2",
"defu": "^6.1.4",
"@nuxt/devtools-kit": "1.0.0",
"@nuxt/devtools-ui-kit": "1.0.0",
"@nuxt/kit": "^3.9.0",
"@vueuse/core": "^10.7.1",
"defu": "^6.1.3",
"fs-extra": "^11.2.0",
"mongoose": "^8.1.0",
"mongoose": "^7.6.7",
"ofetch": "^1.3.3",
"pathe": "^1.1.2",
"pathe": "^1.1.1",
"pluralize": "^8.0.0",
"sirv": "^2.0.4"
},
"devDependencies": {
"@antfu/eslint-config": "2.6.3",
"@antfu/eslint-config": "1.0.0-beta.29",
"@nuxt/module-builder": "^0.5.5",
"@types/fs-extra": "^11.0.4",
"@types/pluralize": "^0.0.33",
"@types/pluralize": "^0.0.32",
"changelogen": "^0.5.5",
"eslint": "8.56.0",
"nuxt": "^3.9.3",
"eslint": "8.52.0",
"nuxt": "^3.9.0",
"sass": "^1.69.7"
}
}

View File

@ -1,14 +1,8 @@
<script setup lang="ts">
const { data } = await useFetch('/api/users')
<script setup>
</script>
<template>
<div>
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>
</template>

2926
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -1,20 +0,0 @@
import type { ConnectOptions } from 'mongoose'
import { logger } from '@nuxt/kit'
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 })
logger.success('Connected to `MongoDB`')
}
catch (err) {
logger.error('Error connecting to `MongoDB`', err)
}
}

View File

@ -1,2 +1,49 @@
export { defineMongooseConnection } from './connection'
export { defineMongooseModel } from './model'
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)
}

View File

@ -1,32 +0,0 @@
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)
}