Skip to content

Commit

Permalink
chore(*): update bun deps
Browse files Browse the repository at this point in the history
  • Loading branch information
MM25Zamanian committed Oct 8, 2024
1 parent 0a46e14 commit 7c49b3c
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"cSpell.words": ["Jsonify", "Jsonize", "promeet", "Virtuals", "Zamanian"]
"cSpell.words": ["gecut", "Jsonify", "Jsonize", "promeet", "Virtuals", "Zamanian"]
}
Binary file modified bun.lockb
Binary file not shown.
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,26 @@
},
"dependencies": {},
"devDependencies": {
"@types/bun": "latest",
"@typescript-eslint/eslint-plugin": "^7.3.1",
"@typescript-eslint/parser": "^7.3.1",
"eslint": "^8.57.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
"prettier": "^3.2.5"
"@types/bun": "^1.1.10",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0",
"eslint": "^8.0.0",
"eslint-import-resolver-typescript": "^3.6.3",
"eslint-plugin-import": "^2.31.0",
"npm-check-updates": "^17.1.3",
"prettier": "^3.3.3"
},
"peerDependencies": {
"typescript": "^5.0.0"
"typescript": "^5.6.2"
},
"workspaces": ["packages/*/*"],
"scripts": {
"update": "ncu -p bun -i -u -ws",
"lint": "eslint --config .eslintrc.yml --ignore-path .gitignore --ext .ts --ext .mjs '.'",

"build:test": "bun --filter '*' build:all --target bun --format esm --splitting --outdir build --minify-syntax --minify-identifiers",

"build:test": "bun --filter '*' build:all --target bun --format esm --splitting --outdir build",
"format": "bun run format:prettier; bun run format:eslint",
"format:eslint": "bun run lint:ts --fix",
"format:eslint": "bun run lint --fix",
"format:prettier": "prettier . --ignore-path .gitignore --write"
},
"packageManager": "pnpm@9.11.0+sha512.0a203ffaed5a3f63242cd064c8fb5892366c103e328079318f78062f24ea8c9d50bc6a47aa3567cabefd824d170e78fa2745ed1f16b132e16436146b7688f19b"
"packageManager": "pnpm@9.12.1"
}
20 changes: 20 additions & 0 deletions packages/common/database/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@promeet/database",
"private": true,
"type": "module",
"dependencies": {
"@promeet/schemas": "workspace:^",
"@promeet/types": "workspace:^",
"mongoose": "^8.7.0"
},
"devDependencies": {
"@gecut/logger": "^2.0.0",
"@gecut/types": "^3.0.0",
"@gecut/utilities": "^6.0.0",
"@types/bun": "latest"
},
"scripts": {
"build": "bun build ./src/index.ts",
"build:all": "bun build ./src/**.ts"
}
}
62 changes: 62 additions & 0 deletions packages/common/database/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { GecutLogger } from '@gecut/logger'
import { $GroupSchema, $SessionSchema, $UserSchema } from '@promeet/schemas'
import mongoose from 'mongoose'

import type { GroupInterface, SessionInterface, UserInterface } from '@promeet/types'

export class Database {
constructor(
private uri: string,
private logger: GecutLogger = new GecutLogger('db-connector'),
private options?: mongoose.ConnectOptions,
) {
this.options = {
dbName: 'test',

...(this.options ?? {}),
}
}

$user = mongoose.model<UserInterface>('user', $UserSchema)
$group = mongoose.model<GroupInterface>('group', $GroupSchema)
$session = mongoose.model<SessionInterface>('session', $SessionSchema)

connector?: typeof mongoose

async connect() {
if (this.uri.startsWith('mongodb://') || this.uri.startsWith('mongodb+srv://')) {
this.logger.method?.('connect')

try {
return (this.connector = await mongoose.connect(this.uri, this.options))
}
catch (error) {
return this.logger.error('connect', 'connect_failed', error)
}
}

this.logger.error('connect', 'uri_not_valid', { uri: this.uri, options: this.options })

return null
}

async initialize() {
if (this.connector == null) return -1

const total = await this.totalDocuments()

this.logger.methodFull?.('initialize', '', total)

return total
}

private async totalDocuments() {
const [user, group, session] = await Promise.all([
this.$user.countDocuments(),
this.$group.countDocuments(),
this.$session.countDocuments(),
])

return { user, group, session }
}
}
3 changes: 3 additions & 0 deletions packages/common/database/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.json"
}
5 changes: 3 additions & 2 deletions packages/common/schemas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
"name": "@promeet/schemas",
"private": true,
"type": "module",
"main": "./src/index.ts",
"dependencies": {
"@promeet/types": "workspace:^",
"mongoose": "^8.7.0"
},
"devDependencies": {
"@gecut/types": "^2.2.2",
"@gecut/utilities": "^5.4.1",
"@gecut/types": "^3.0.0",
"@gecut/utilities": "^6.0.0",
"@types/bun": "latest"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions packages/common/schemas/src/user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { numberUtils } from '@gecut/utilities/data-types/number.js'
import { randomNumber } from '@gecut/utilities/data-types/number.js'
import { uid } from '@gecut/utilities/uid.js'
import { Schema } from 'mongoose'

Expand Down Expand Up @@ -58,7 +58,7 @@ export const $UserSchema = new Schema<
if (this.otp?.code == null || Date.now() > new Date(this.otp.expiredAt).getTime()) delete this.otp

this.otp = {
code: numberUtils.random.number(999999, 111111).toString(),
code: randomNumber(999999, 111111).toString(),
expiredAt: new Date(Date.now() + 300000),
}

Expand Down
2 changes: 1 addition & 1 deletion packages/common/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build:all": "bun build ./src/**.ts"
},
"devDependencies": {
"@gecut/types": "^2.2.2",
"@gecut/types": "^3.0.0",
"@types/bun": "latest",
"mongoose": "^8.7.0"
}
Expand Down

0 comments on commit 7c49b3c

Please sign in to comment.