notherbase-fs 2.0.2 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/controllers/creation.js +57 -59
  2. package/controllers/spirit-world.js +55 -72
  3. package/controllers/spirits/contact.js +17 -10
  4. package/controllers/spirits/user.js +144 -112
  5. package/controllers/spirits/util.js +23 -31
  6. package/models/index.js +54 -117
  7. package/models/item.js +80 -0
  8. package/models/send-mail.js +2 -0
  9. package/models/spirit.js +77 -115
  10. package/models/user.js +189 -0
  11. package/notherbase-fs.js +1 -0
  12. package/package.json +1 -1
  13. package/public/styles/main.css +12 -3
  14. package/test/{explorer/coast/tall-beach/nono-cove/styles → coast/tall-beach/nono-cove}/index.css +0 -0
  15. package/test/coast/tall-beach/nono-cove/index.ejs +29 -0
  16. package/test/{explorer/coast/tall-beach/nono-cove/views/nono-og.ejs → coast/tall-beach/nono-cove/nono-og/index.ejs} +2 -2
  17. package/test/{explorer/coast/tall-beach/nono-cove/styles → coast/tall-beach/nono-cove/nono-og}/nono.css +0 -0
  18. package/test/{explorer/coast/tall-beach/nono-cove/local-scripts → coast/tall-beach/nono-cove/nono-og}/nono.js +1 -1
  19. package/test/{explorer/coast/tall-beach/nono-cove/server-scripts → test-page}/emailTime.js +0 -0
  20. package/test/{pages/test.ejs → test-page/index.ejs} +0 -0
  21. package/test/the-front/add-gold.js +35 -0
  22. package/test/the-front/check/add-more-gold.js +3 -0
  23. package/test/the-front/check/emailTime.js +11 -0
  24. package/test/the-front/check/index.ejs +13 -0
  25. package/test/the-front/check/subtract-gold.js +3 -0
  26. package/test/the-front/checks.js +11 -0
  27. package/test/the-front/incTranslation.js +9 -0
  28. package/test/the-front/index.ejs +107 -0
  29. package/test/void/index.ejs +4 -0
  30. package/test/void/void.css +3 -0
  31. package/views/explorer.ejs +32 -41
  32. package/views/menu/account.ejs +39 -0
  33. package/views/menu/inventory.ejs +8 -0
  34. package/views/menu/more.ejs +5 -0
  35. package/views/menu/player.ejs +3 -0
  36. package/views/menu.ejs +20 -62
  37. package/views/scripts/base.js +314 -0
  38. package/controllers/spirits/attribute.js +0 -47
  39. package/controllers/spirits/inventory.js +0 -71
  40. package/controllers/spirits/item.js +0 -41
  41. package/controllers/spirits/serve.js +0 -33
  42. package/public/js/commune.js +0 -22
  43. package/public/js/establishment.js +0 -44
  44. package/public/js/memories.js +0 -44
  45. package/test/explorer/coast/tall-beach/nono-cove/local-scripts/game.js +0 -7
  46. package/test/explorer/coast/tall-beach/nono-cove/local-scripts/items.js +0 -162
  47. package/test/explorer/coast/tall-beach/nono-cove/server-scripts/getTimer.js +0 -31
  48. package/test/explorer/coast/tall-beach/nono-cove/styles/items-floor.css +0 -92
  49. package/test/explorer/coast/tall-beach/nono-cove/views/index.ejs +0 -130
  50. package/test/pages/server-scripts/emailTime.js +0 -15
  51. package/test/the-front/server-scripts/emailTime.js +0 -15
  52. package/test/the-front/server-scripts/getTimer.js +0 -31
  53. package/test/the-front/views/check.ejs +0 -93
  54. package/test/the-front/views/index.ejs +0 -113
  55. package/test/void/styles/void.css +0 -0
  56. package/views/account.ejs +0 -122
  57. package/views/inventory.ejs +0 -117
  58. package/views/more.ejs +0 -16
  59. package/views/player.ejs +0 -60
package/models/index.js CHANGED
@@ -2,6 +2,8 @@ import mongoose from "mongoose";
2
2
  import dotenv from "dotenv";
3
3
  dotenv.config();
4
4
  import Spirit from "./spirit.js";
5
+ import Item from "./item.js";
6
+ import User from "./user.js";
5
7
  import SendMail from "./send-mail.js";
6
8
 
7
9
  mongoose.connection.on('connected', (err) => {
@@ -26,128 +28,63 @@ catch (err) {
26
28
  console.log(`Mongoose on connect: ${err}`);
27
29
  }
28
30
 
29
- class User extends Spirit {
30
- constructor(service, email = null) {
31
- super();
32
- this.body.route = "/";
33
- this.body.service = service;
34
- this.email = email;
35
- }
36
-
37
- recall = async () => {
38
- let result = await this.recallFromData("email", this.email);
39
- return result;
40
- }
41
- }
42
-
43
- class Item extends Spirit {
44
- constructor(name = "") {
45
- super();
46
- this.body.route = "/";
47
- this.body.service = "item";
48
-
49
- this.memory = {
50
- data: {
51
- name: name
52
- }
53
- }
54
- }
55
-
56
- recall = async () => {
57
- let result = await this.recallFromData("name", this.memory.data.name);
58
- return result;
59
- }
60
-
61
- commit = async (data = this.memory.data) => {
62
- let result = await this.commitByData("name", this.memory.data.name, data);
63
- return result;
64
- }
65
-
66
- delete = async () => {
67
- let result = await this.deleteByData("name", this.memory.data.name);
68
- return result;
69
- }
70
- }
71
-
72
-
73
- // migrate
74
- // const user = mongoose.model('users', new mongoose.Schema({
75
- // username: String,
76
- // password: String,
77
- // email: String,
78
- // coin: Number,
79
- // home: String,
80
- // authLevels: [ String ],
81
- // location: String,
82
- // attributes: {
83
- // translation: Number,
84
- // strength: Number,
85
- // agility: Number,
86
- // defense: Number
87
- // },
88
- // reset: {
89
- // token: Number,
90
- // exp: Number
91
- // }
92
- // }));
93
- // const page = mongoose.model('pages', new mongoose.Schema({
94
- // name: String,
95
- // type: String,
96
- // user: {
97
- // type: mongoose.Schema.Types.ObjectId,
98
- // ref: "users",
99
- // required: false
100
- // },
101
- // data: {}
102
- // }));
103
-
104
- // user.find({}, async (err, users) => {
105
- // for (let i = 0; i < users.length; i++) {
106
- // let userSpirit = new User("user", users[i].email);
107
-
108
- // await userSpirit.create({
109
- // username: users[i].username,
110
- // password: users[i].password,
111
- // email: users[i].email,
112
- // coin: users[i].coin,
113
- // home: users[i].home,
114
- // authLevels: users[i].authLevels,
115
- // location: users[i].location,
116
- // attributes: users[i].attributes,
117
- // inventory: []
118
- // });
119
-
120
- // let foundPages = await page.find({ user: users[i]._id });
121
-
122
- // for (let i = 0; i < foundPages.length; i++) {
123
- // let spirit = new Spirit({
124
- // route: `/${foundPages[i].name}`,
125
- // service: foundPages[i].name,
126
- // scope: foundPages[i].type,
127
- // parent: userSpirit.memory._id,
128
- // _lastUpdate: 0,
129
- // data: foundPages[i].data.tickets
130
- // });
31
+ // let migrate = function () {
32
+ // // migrate
33
+
34
+ // const user = mongoose.model('users', new mongoose.Schema({
35
+ // username: String,
36
+ // password: String,
37
+ // email: String,
38
+ // coin: Number,
39
+ // home: String,
40
+ // authLevels: [ String ],
41
+ // location: String,
42
+ // attributes: {
43
+ // translation: Number,
44
+ // strength: Number,
45
+ // agility: Number,
46
+ // defense: Number
47
+ // },
48
+ // reset: {
49
+ // token: Number,
50
+ // exp: Number
51
+ // }
52
+ // }));
53
+ // const page = mongoose.model('pages', new mongoose.Schema({
54
+ // name: String,
55
+ // type: String,
56
+ // user: {
57
+ // type: mongoose.Schema.Types.ObjectId,
58
+ // ref: "users",
59
+ // required: false
60
+ // },
61
+ // data: {}
62
+ // }));
131
63
 
132
- // let found = await spirit.recall();
64
+ // user.find({}, async (err, users) => {
65
+ // for (let i = 0; i < users.length; i++) {
66
+ // let userSpirit = await User.create(
67
+ // users[i].username,
68
+ // users[i].password,
69
+ // users[i].email
70
+ // );
71
+
72
+ // let foundPages = await page.find({ user: users[i]._id });
133
73
 
134
- // if (found) {
135
- // spirit.memory.data.tickets.concat(foundPages[i].data.tickets);
136
- // await spirit.commit();
74
+ // for (let i = 0; i < foundPages.length; i++) {
75
+ // let spirit = await Spirit.create({
76
+ // route: `/${foundPages[i].name}`,
77
+ // service: foundPages[i].name,
78
+ // scope: foundPages[i].type,
79
+ // parent: userSpirit.memory._id,
80
+ // _lastUpdate: 0
81
+ // }, foundPages[i].data.tickets);
137
82
  // }
138
- // else await spirit.create({
139
- // tickets: foundPages[i].data.tickets
140
- // });
141
83
  // }
142
- // }
143
- // });
144
-
145
-
146
-
147
-
148
-
149
-
84
+ // });
85
+ // }
150
86
 
87
+ // migrate();
151
88
 
152
89
  export default {
153
90
  SendMail: SendMail,
package/models/item.js ADDED
@@ -0,0 +1,80 @@
1
+ import Spirit from "./spirit.js";
2
+
3
+ export default class Item extends Spirit {
4
+ static create = async (name, short, long) => {
5
+ let spirit = new Item(name);
6
+
7
+ spirit.memory = await Spirit.db.create({
8
+ route: "/",
9
+ service: "items",
10
+ parent: null,
11
+ scope: "global",
12
+ _lastUpdate: Date.now(),
13
+ data: {
14
+ name,
15
+ short,
16
+ long
17
+ }
18
+ });
19
+
20
+ return spirit;
21
+ }
22
+
23
+ static recallAll = async () => {
24
+ let spirit = new Item();
25
+
26
+ let found = await Spirit.db.find({
27
+ route: "/",
28
+ service: "items",
29
+ parent: null,
30
+ scope: "global"
31
+ });
32
+
33
+ if (found) {
34
+ spirit.memory = found;
35
+
36
+ return spirit;
37
+ }
38
+ else return null;
39
+ }
40
+
41
+ static recallOne = async (name) => {
42
+ let spirit = new Item(name);
43
+
44
+ let query = Spirit.buildQuery({
45
+ route: "/",
46
+ service: "items",
47
+ parent: null,
48
+ scope: "global"
49
+ }, {
50
+ name: name
51
+ });
52
+
53
+ let found = await Spirit.db.findOne(query);
54
+
55
+ if (found) {
56
+ spirit.memory = found;
57
+
58
+ return spirit;
59
+ }
60
+ else return null;
61
+ }
62
+
63
+ static delete = async (name) => {
64
+ let found = await Spirit.db.findAndDelete(Spirit.buildQuery({
65
+ route: "/",
66
+ service: "items",
67
+ parent: null,
68
+ scope: "global"
69
+ }, {
70
+ name: name
71
+ }));
72
+
73
+ return found.deletedCount;
74
+ }
75
+
76
+ constructor(name = "") {
77
+ super();
78
+ this.name = name;
79
+ }
80
+ }
@@ -22,6 +22,8 @@ const passwordReset = async (toEmail, resetToken) => {
22
22
  };
23
23
 
24
24
  const send = async (toEmail, subject, html) => {
25
+ console.log("dfhd");
26
+
25
27
  var transporter = nodemailer.createTransport({
26
28
  service: 'gmail',
27
29
  auth: {
package/models/spirit.js CHANGED
@@ -1,19 +1,6 @@
1
1
  import mongoose from "mongoose";
2
2
 
3
3
  export default class Spirit {
4
- constructor(body = {}) {
5
- this.body = body;
6
- if (!this.body.route) this.body.route = "/";
7
- if (!this.body.service) this.body.service = "default";
8
- if (!this.body.scope) this.body.scope = "global";
9
- if (!this.body.parent) this.body.parent = null;
10
- if (!this.body._lastUpdate) this.body._lastUpdate = 0;
11
- if (!this.body.data) this.body.data = {};
12
- this.memory = {
13
- data: {}
14
- };
15
- }
16
-
17
4
  static db = mongoose.model('spirits', new mongoose.Schema({
18
5
  _lastUpdate: Number,
19
6
  route: String,
@@ -27,133 +14,108 @@ export default class Spirit {
27
14
  data: {}
28
15
  }));
29
16
 
30
- create = async (data = this.memory.data) => {
31
- this.time = Date.now();
32
-
33
- this.memory = await Spirit.db.create({
34
- route: this.body.route,
35
- service: this.body.service,
36
- scope: this.body.scope,
37
- parent: this.body.parent,
38
- _lastUpdate: this.time,
39
- data: data
40
- });
41
-
42
- return true;
17
+ static buildQuery = (options = {}, data = {}, id = null) => {
18
+ let query = {};
19
+
20
+ if (id) query = {
21
+ _id: id
22
+ };
23
+ if (options) query = {
24
+ ...query,
25
+ ...options
26
+ };
27
+ if (data){
28
+ let keys = Object.keys(data);
29
+ for (let i = 0; i < keys.length; i++) {
30
+ query[`data.${keys[i]}`] = data[keys[i]];
31
+ }
32
+ }
33
+
34
+ return query;
43
35
  }
44
36
 
45
- commit = async (data = this.memory.data) => {
46
- this.time = Date.now();
47
-
48
- this.memory = await Spirit.db.updateOne({
49
- route: this.body.route,
50
- service: this.body.service,
51
- scope: this.body.scope,
52
- parent: this.body.parent
53
- }, {
54
- route: this.body.route,
55
- service: this.body.service,
56
- scope: this.body.scope,
57
- parent: this.body.parent,
58
- _lastUpdate: this.time,
37
+ static create = async (options, data) => {
38
+ let spirit = new Spirit();
39
+
40
+ spirit.memory = await Spirit.db.create({
41
+ ...options,
42
+ _lastUpdate: Date.now(),
59
43
  data: data
60
- }, {
61
- upsert: true
62
44
  });
63
45
 
64
- return true;
46
+ return spirit;
65
47
  }
66
48
 
67
- commitByData = async (which, query, data = this.memory.data) => {
68
- this.time = Date.now();
69
-
70
- this.memory = await Spirit.db.updateOne({
71
- route: this.body.route,
72
- service: this.body.service,
73
- scope: this.body.scope,
74
- parent: this.body.parent
75
- }, {
76
- route: this.body.route,
77
- service: this.body.service,
78
- scope: this.body.scope,
79
- parent: this.body.parent,
80
- _lastUpdate: this.time,
81
- data: data
82
- }, {
83
- upsert: true
84
- }).where(`data.${which}`).equals(query);
49
+ static recall = async (options = {}, data = {}, id = null) => {
50
+ let spirit = new Spirit();
85
51
 
86
- return true;
87
- }
88
-
89
- recall = async () => {
90
- let found = await Spirit.db.findOne({
91
- route: this.body.route,
92
- service: this.body.service,
93
- scope: this.body.scope,
94
- parent: this.body.parent
95
- });
52
+ let query = Spirit.buildQuery(options, data, id);
53
+
54
+ let found = await Spirit.db.find(query);
96
55
 
97
- if (found && new Date(found._lastUpdate) > new Date(this.body._lastUpdate)) {
98
- this.memory = found;
99
- this.time = found._lastUpdate;
56
+ if (found) {
57
+ spirit.memory = found;
58
+ if (!spirit.memory.data) spirit.memory.data = {};
100
59
 
101
- return found.data;
60
+ return spirit;
102
61
  }
103
- else return false;
62
+ else return null;
104
63
  }
105
64
 
106
- getAll = async () => {
107
- let found = await Spirit.db.find({
108
- route: this.body.route,
109
- service: this.body.service,
110
- scope: this.body.scope
111
- });
65
+ static recallOne = async (options = {}, data = {}, id = null) => {
66
+ let spirit = new Spirit();
112
67
 
113
- if (found) {
114
- this.memory = found;
115
- this.time = found._lastUpdate;
68
+ let query = Spirit.buildQuery(options, data, id);
116
69
 
117
- let takeout = [];
118
- for (let i = 0; i < found.length; i++) {
119
- takeout.push(found[i].data)
120
- }
70
+ let found = await Spirit.db.findOne(query);
71
+
72
+ if (found) {
73
+ spirit.memory = found;
74
+ if (!spirit.memory.data) spirit.memory.data = {};
121
75
 
122
- return takeout;
76
+ return spirit;
123
77
  }
124
- else return false;
78
+ else return null;
125
79
  }
126
80
 
127
- recallFromData = async (which, query) => {
128
- let found = await Spirit.db.findOne({
129
- route: this.body.route,
130
- service: this.body.service
131
- }).where(`data.${which}`).equals(query);
81
+ static recallOrCreate = async (options = {}, queryData = {}, initdata = {}) => {
82
+ let spirit = new Spirit();
83
+
84
+ let query = Spirit.buildQuery(options, queryData);
85
+
86
+ let found = await Spirit.db.findOne(query);
132
87
 
133
- if (found && new Date(found._lastUpdate) > new Date(this.body._lastUpdate)) {
134
- this.memory = found;
135
- this.time = found._lastUpdate;
88
+ if (found) {
89
+ spirit.memory = found;
90
+ if (!spirit.memory.data) spirit.memory.data = {};
136
91
 
137
- return found.data;
92
+ return spirit;
93
+ }
94
+ else {
95
+ let newSpirit = await Spirit.create(options, initdata);
96
+ return newSpirit;
138
97
  }
139
- else return false;
140
98
  }
141
99
 
142
- delete = async () => {
143
- await Spirit.db.findOneAndDelete({
144
- route: this.body.route,
145
- service: this.body.service,
146
- scope: this.body.scope,
147
- parent: this.body.parent
148
- });
100
+ static delete = async (options = {}, data = {}, id = null) => {
101
+ let found = await Spirit.db.findAndDelete(Spirit.buildQuery(options, data, id));
102
+
103
+ return found.deletedCount;
104
+ }
105
+
106
+ constructor() {
107
+ this.memory = {
108
+ data: {}
109
+ };
149
110
  }
150
111
 
151
- deleteByData = async (which, query) => {
152
- await Spirit.db.findOneAndDelete({
153
- route: this.body.route,
154
- service: this.body.service,
155
- scope: this.body.scope,
156
- parent: this.body.parent
157
- }).where(`data.${which}`).equals(query);
112
+ commit = async (data = this.memory.data) => {
113
+ this.memory._lastUpdate = Date.now();
114
+
115
+ this.memory.data = data;
116
+ this.memory.markModified("data");
117
+ await this.memory.save();
118
+
119
+ return "Updated";
158
120
  }
159
121
  };