mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
feat: change to use commonjs output
This commit is contained in:
1 parent
2bdb804f24
commit
557af91d4b
24 files changed
+35
-18
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import { model, Schema } from 'mongoose'
|
||||
|
||||
const Command = model(
|
||||
'Command',
|
||||
new Schema(
|
||||
{
|
||||
session: {
|
||||
type: Schema.ObjectId,
|
||||
ref: 'Session',
|
||||
required: true,
|
||||
},
|
||||
pwd: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
command: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
output: {
|
||||
type: String,
|
||||
required: false,
|
||||
},
|
||||
error: {
|
||||
type: String,
|
||||
required: false,
|
||||
},
|
||||
stage: {
|
||||
type: String,
|
||||
required: false,
|
||||
},
|
||||
},
|
||||
{ timestamps: true }
|
||||
)
|
||||
)
|
||||
|
||||
export default Command
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Schema } from 'mongoose'
|
||||
import conditionSchema from './condition.js'
|
||||
import responseSchema from './response.js'
|
||||
import hintSchema from './hint.js'
|
||||
|
||||
const commandResponderSchema = new Schema({
|
||||
condition: {
|
||||
type: conditionSchema,
|
||||
required: false,
|
||||
},
|
||||
responses: {
|
||||
type: [responseSchema],
|
||||
required: true,
|
||||
},
|
||||
})
|
||||
|
||||
commandResponderSchema.add(hintSchema)
|
||||
|
||||
export default commandResponderSchema
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Schema } from 'mongoose'
|
||||
|
||||
const fileConditionSchema = new Schema({
|
||||
path: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
type: String,
|
||||
exists: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
})
|
||||
|
||||
const conditionSchema = new Schema({
|
||||
command: [String],
|
||||
output: [String],
|
||||
error: [String],
|
||||
pwd: [String],
|
||||
files: [fileConditionSchema],
|
||||
})
|
||||
|
||||
conditionSchema.add({
|
||||
or: [conditionSchema],
|
||||
not: conditionSchema,
|
||||
})
|
||||
|
||||
export default conditionSchema
|
||||
@@ -0,0 +1,8 @@
|
||||
import { Schema } from 'mongoose'
|
||||
import commandResponderSchema from './commandResponder.js'
|
||||
|
||||
const exceptionSchema = new Schema({})
|
||||
|
||||
exceptionSchema.add(commandResponderSchema)
|
||||
|
||||
export default exceptionSchema
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Schema } from 'mongoose'
|
||||
import exceptionSchema from './exception.js'
|
||||
import requirementSchema from './requirement.js'
|
||||
|
||||
const globalExceptionSchema = new Schema({})
|
||||
|
||||
globalExceptionSchema.add(exceptionSchema)
|
||||
globalExceptionSchema.add(requirementSchema)
|
||||
|
||||
export default globalExceptionSchema
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Schema } from 'mongoose'
|
||||
|
||||
const hintSchema = new Schema({
|
||||
hints: {
|
||||
type: [String],
|
||||
required: true,
|
||||
},
|
||||
})
|
||||
|
||||
export default hintSchema
|
||||
@@ -0,0 +1,15 @@
|
||||
import mongoose from 'mongoose'
|
||||
|
||||
export { default as User } from './user.js'
|
||||
export { default as Quest } from './quest.js'
|
||||
export { default as Session } from './session.js'
|
||||
export { default as Command } from './command.js'
|
||||
export { default as UserProfile } from './userProfile.js'
|
||||
|
||||
export default async function connectDB(uri) {
|
||||
const db = await mongoose.connect(uri, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
})
|
||||
return db.connection.getClient()
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { model, Schema } from 'mongoose'
|
||||
import stageSchema from './stage.js'
|
||||
import globalExceptionSchema from './globalException.js'
|
||||
|
||||
const Quest = model(
|
||||
'Quest',
|
||||
new Schema({
|
||||
_id: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
image: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
requirements: {
|
||||
type: [
|
||||
{
|
||||
type: String,
|
||||
ref: 'Quest',
|
||||
},
|
||||
],
|
||||
required: true,
|
||||
},
|
||||
instruction: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
stages: {
|
||||
type: [stageSchema],
|
||||
required: true,
|
||||
},
|
||||
exceptions: {
|
||||
type: [globalExceptionSchema],
|
||||
required: true,
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
export default Quest
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Schema } from 'mongoose'
|
||||
|
||||
const requirementSchema = new Schema({
|
||||
requirements: [
|
||||
{
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
export default requirementSchema
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Schema } from 'mongoose'
|
||||
|
||||
const responseSchema = new Schema({
|
||||
type: {
|
||||
type: String,
|
||||
enum: ['narrative', 'dialogue'],
|
||||
default: 'dialogue',
|
||||
required: true,
|
||||
},
|
||||
content: {
|
||||
type: [String],
|
||||
required: true,
|
||||
},
|
||||
speaker: { type: String, default: 'Ada' },
|
||||
color: String,
|
||||
})
|
||||
|
||||
export default responseSchema
|
||||
@@ -0,0 +1,72 @@
|
||||
import { model, Schema } from 'mongoose'
|
||||
|
||||
const nodeSchema = new Schema({
|
||||
path: String,
|
||||
type: String,
|
||||
discovered: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
})
|
||||
|
||||
nodeSchema.add({
|
||||
children: [nodeSchema],
|
||||
})
|
||||
|
||||
const taskSchema = new Schema({
|
||||
id: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
completed: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
})
|
||||
|
||||
const Session = model(
|
||||
'Session',
|
||||
new Schema(
|
||||
{
|
||||
user: {
|
||||
type: Schema.ObjectId,
|
||||
ref: 'User',
|
||||
required: true,
|
||||
},
|
||||
quest: {
|
||||
type: String,
|
||||
ref: 'Quest',
|
||||
required: true,
|
||||
},
|
||||
containerId: String,
|
||||
status: {
|
||||
type: String,
|
||||
enum: ['active', 'finished', 'inactive'],
|
||||
required: true,
|
||||
default: 'active',
|
||||
},
|
||||
finishedAt: Date,
|
||||
lastActivityAt: {
|
||||
type: Date,
|
||||
default: Date.now,
|
||||
required: true,
|
||||
},
|
||||
tasks: [taskSchema],
|
||||
hints: [[String]],
|
||||
graph: {
|
||||
type: nodeSchema,
|
||||
default: {
|
||||
path: '/',
|
||||
type: 'folder',
|
||||
},
|
||||
},
|
||||
},
|
||||
{ timestamps: true }
|
||||
)
|
||||
)
|
||||
|
||||
export default Session
|
||||
@@ -0,0 +1,24 @@
|
||||
import { Schema } from 'mongoose'
|
||||
import commandResponderSchema from './commandResponder.js'
|
||||
import stageExceptionSchema from './stageException.js'
|
||||
import requirementSchema from './requirement.js'
|
||||
|
||||
const stageSchema = new Schema({
|
||||
id: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
task: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
exceptions: {
|
||||
type: [stageExceptionSchema],
|
||||
required: true,
|
||||
},
|
||||
})
|
||||
|
||||
stageSchema.add(commandResponderSchema)
|
||||
stageSchema.add(requirementSchema)
|
||||
|
||||
export default stageSchema
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Schema } from 'mongoose'
|
||||
import exceptionSchema from './exception.js'
|
||||
|
||||
const stageExceptionSchema = new Schema({
|
||||
catchAll: {
|
||||
type: Boolean,
|
||||
required: true,
|
||||
default: false,
|
||||
},
|
||||
})
|
||||
|
||||
stageExceptionSchema.add(exceptionSchema)
|
||||
|
||||
export default stageExceptionSchema
|
||||
@@ -0,0 +1,46 @@
|
||||
import { model, Schema } from 'mongoose'
|
||||
|
||||
const socialLoginSchema = new Schema({
|
||||
provider: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
id: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
displayName: {
|
||||
type: String,
|
||||
required: false,
|
||||
},
|
||||
})
|
||||
|
||||
const User = model(
|
||||
'User',
|
||||
new Schema(
|
||||
{
|
||||
username: {
|
||||
type: String,
|
||||
unique: true,
|
||||
required: true,
|
||||
},
|
||||
email: {
|
||||
type: String,
|
||||
unique: true,
|
||||
required: true,
|
||||
},
|
||||
hashedPassword: String,
|
||||
socialLogins: {
|
||||
type: Map,
|
||||
of: socialLoginSchema,
|
||||
default: {},
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
timestamps: true,
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
export default User
|
||||
@@ -0,0 +1,51 @@
|
||||
import { model, Schema } from 'mongoose'
|
||||
|
||||
const progressSchema = new Schema({
|
||||
quest: {
|
||||
type: String,
|
||||
ref: 'Quest',
|
||||
required: true,
|
||||
},
|
||||
sessions: [
|
||||
{
|
||||
type: Schema.ObjectId,
|
||||
ref: 'Session',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
completed: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
required: true,
|
||||
},
|
||||
startedAt: {
|
||||
type: Date,
|
||||
required: true,
|
||||
},
|
||||
finishedAt: Date,
|
||||
})
|
||||
|
||||
const UserProfile = model(
|
||||
'UserProfile',
|
||||
new Schema(
|
||||
{
|
||||
user: {
|
||||
type: Schema.ObjectId,
|
||||
ref: 'User',
|
||||
unique: true,
|
||||
required: true,
|
||||
},
|
||||
progress: {
|
||||
type: Map,
|
||||
of: progressSchema,
|
||||
default: {},
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
timestamps: true,
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
export default UserProfile
|
||||
Reference in new issue
Block a user