@projectinvicta/nails 2.0.15
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.
- package/README.md +419 -0
- package/bin/lib/init.js +103 -0
- package/bin/lib/nails.c +81 -0
- package/bin/lib/nails.js +23 -0
- package/bin/lib/test.js +4 -0
- package/index.js +6 -0
- package/lib/application.js +24 -0
- package/lib/collection.js +6 -0
- package/lib/controller.js +182 -0
- package/lib/database_connector.js +12 -0
- package/lib/firebase_connector.js +94 -0
- package/lib/model_v2.js +24 -0
- package/lib/mongoose_connector.js +49 -0
- package/lib/mongoose_mem_connector.js +21 -0
- package/lib/nails.js +244 -0
- package/lib/router.js +202 -0
- package/lib/sequelize_connector.js +31 -0
- package/lib/server.js +1 -0
- package/package.json +60 -0
- package/scripts/install.js +57 -0
- package/scripts/uninstall.js +23 -0
- package/spec/bin/init.spec.js +0 -0
- package/spec/controller.spec.js +105 -0
- package/spec/model_v2.spec.js +75 -0
- package/spec/mongodb_connector.util.js +30 -0
- package/spec/mongoose_connector.util.js +20 -0
- package/spec/nails.spec.js +0 -0
- package/spec/router.spec.js +101 -0
- package/spec/sequelize_connector.spec.js +91 -0
- package/spec/sequelize_connector.util.js +18 -0
- package/spec/services/integration/README.md +5 -0
- package/spec/services/integration/client/css/styles.css +0 -0
- package/spec/services/integration/client/download.jpg +0 -0
- package/spec/services/integration/client/favicon.ico +0 -0
- package/spec/services/integration/client/index.html +9 -0
- package/spec/services/integration/client/js/client.js +0 -0
- package/spec/services/integration/client/js/components/app.jsx +15 -0
- package/spec/services/integration/config/db.js +14 -0
- package/spec/services/integration/config/mimes.js +61 -0
- package/spec/services/integration/config/routes.js +41 -0
- package/spec/services/integration/config/service.js +48 -0
- package/spec/services/integration/config/ssl/certificate.pem +22 -0
- package/spec/services/integration/config/ssl/csr.csr +17 -0
- package/spec/services/integration/config/ssl/key.pem +28 -0
- package/spec/services/integration/config/ssl/private_key.pem +30 -0
- package/spec/services/integration/config/ssl/public_key.pem +9 -0
- package/spec/services/integration/package.json +23 -0
- package/spec/services/integration/server/controllers/classbased_controller.js +33 -0
- package/spec/services/integration/server/controllers/default_json_controller.js +20 -0
- package/spec/services/integration/server/controllers/error_controller.js +27 -0
- package/spec/services/integration/server/controllers/home_controller.js +39 -0
- package/spec/services/integration/server/controllers/json_controller.js +15 -0
- package/spec/services/integration/server/controllers/manualrenderasync_controller.js +14 -0
- package/spec/services/integration/server/controllers/mjs_controller.mjs +13 -0
- package/spec/services/integration/server/controllers/modeltest_controller.js +18 -0
- package/spec/services/integration/server/controllers/websocket_controller.js +13 -0
- package/spec/services/integration/server/models/dog.js +6 -0
- package/spec/services/integration/server/views/defaultjson/testnojson.ejs +1 -0
- package/spec/services/integration/server/views/testreact/testreact.ejs +15 -0
- package/spec/services/integration/server.js +9 -0
- package/spec/services/integration_sequelize/README.md +5 -0
- package/spec/services/integration_sequelize/client/css/styles.css +0 -0
- package/spec/services/integration_sequelize/client/download.jpg +0 -0
- package/spec/services/integration_sequelize/client/favicon.ico +0 -0
- package/spec/services/integration_sequelize/client/index.html +9 -0
- package/spec/services/integration_sequelize/client/js/client.js +0 -0
- package/spec/services/integration_sequelize/client/js/components/app.jsx +15 -0
- package/spec/services/integration_sequelize/config/db.js +4 -0
- package/spec/services/integration_sequelize/config/mimes.js +61 -0
- package/spec/services/integration_sequelize/config/routes.js +25 -0
- package/spec/services/integration_sequelize/config/service.js +48 -0
- package/spec/services/integration_sequelize/config/ssl/certificate.pem +22 -0
- package/spec/services/integration_sequelize/config/ssl/csr.csr +17 -0
- package/spec/services/integration_sequelize/config/ssl/key.pem +28 -0
- package/spec/services/integration_sequelize/config/ssl/private_key.pem +30 -0
- package/spec/services/integration_sequelize/config/ssl/public_key.pem +9 -0
- package/spec/services/integration_sequelize/package.json +23 -0
- package/spec/services/integration_sequelize/server/controllers/default_json_controller.js +21 -0
- package/spec/services/integration_sequelize/server/controllers/home_controller.js +39 -0
- package/spec/services/integration_sequelize/server/models/dog.js +7 -0
- package/spec/services/integration_sequelize/server/models/owner.js +10 -0
- package/spec/services/integration_sequelize/server/views/defaultjson/testnojson.ejs +1 -0
- package/spec/services/integration_sequelize/server/views/testreact/testreact.ejs +15 -0
- package/spec/services/integration_sequelize/server.js +9 -0
- package/spec/services.integration.spec.js +296 -0
- package/spec/services.integration_sequelize.spec.js +60 -0
- package/templates/bin/promote.sh +20 -0
- package/templates/bin/rollout.sh +74 -0
- package/templates/bin/server.js +6 -0
- package/templates/bin/start.sh +16 -0
- package/templates/common/readme_fetcher.js +4 -0
- package/templates/config/db.js +19 -0
- package/templates/config/mimes.js +59 -0
- package/templates/config/routes.js +38 -0
- package/templates/config/service.js +45 -0
- package/templates/config/ssl/certificate.pem +22 -0
- package/templates/config/ssl/csr.csr +17 -0
- package/templates/config/ssl/key.pem +28 -0
- package/templates/config/ssl/private_key.pem +30 -0
- package/templates/config/ssl/public_key.pem +9 -0
- package/templates/default/bin/promote.sh +20 -0
- package/templates/default/bin/rollout.sh +74 -0
- package/templates/default/bin/server.js +6 -0
- package/templates/default/bin/start.sh +16 -0
- package/templates/default/common/readme_fetcher.js +4 -0
- package/templates/default/config/db.js +19 -0
- package/templates/default/config/mimes.js +59 -0
- package/templates/default/config/routes.js +38 -0
- package/templates/default/config/service.js +45 -0
- package/templates/default/config/ssl/certificate.pem +22 -0
- package/templates/default/config/ssl/csr.csr +17 -0
- package/templates/default/config/ssl/key.pem +28 -0
- package/templates/default/config/ssl/private_key.pem +30 -0
- package/templates/default/config/ssl/public_key.pem +9 -0
- package/templates/default/package-lock.json +9048 -0
- package/templates/default/package.json +43 -0
- package/templates/default/public/README.xml +332 -0
- package/templates/default/public/css/styles.css +17 -0
- package/templates/default/public/download.jpg +0 -0
- package/templates/default/public/favicon.ico +0 -0
- package/templates/default/public/index.html +9 -0
- package/templates/default/public/js/client.js +1 -0
- package/templates/default/server/controllers/home_controller.js +34 -0
- package/templates/default/server/models/User.js +18 -0
- package/templates/default/server/views/home/index.ejs +14 -0
- package/templates/default/server/views/partials/javascripts.ejs +1 -0
- package/templates/default/server/views/partials/reactapp.ejs +1 -0
- package/templates/default/server/views/partials/styles.ejs +3 -0
- package/templates/default/spec/User.test.js +20 -0
- package/templates/default/spec/home_controller.test.js +28 -0
- package/templates/default/spec/setupTests.js +0 -0
- package/templates/default/src/AboutPage.jsx +9 -0
- package/templates/default/src/HomePage.jsx +9 -0
- package/templates/default/src/Layout.jsx +78 -0
- package/templates/default/src/ReadmePage.jsx +7 -0
- package/templates/default/src/app.jsx +29 -0
- package/templates/default/src/components/ReadmeLoader.jsx +13 -0
- package/templates/default/src/styles/appstyles.css +3 -0
- package/templates/default/vite.config.ts +42 -0
- package/templates/package-lock.json +9048 -0
- package/templates/package.json +43 -0
- package/templates/public/README.xml +332 -0
- package/templates/public/css/styles.css +17 -0
- package/templates/public/download.jpg +0 -0
- package/templates/public/favicon.ico +0 -0
- package/templates/public/index.html +9 -0
- package/templates/public/js/client.js +1 -0
- package/templates/server/controllers/home_controller.js +34 -0
- package/templates/server/models/User.js +18 -0
- package/templates/server/views/home/index.ejs +14 -0
- package/templates/server/views/partials/javascripts.ejs +1 -0
- package/templates/server/views/partials/reactapp.ejs +1 -0
- package/templates/server/views/partials/styles.ejs +3 -0
- package/templates/spec/User.test.js +20 -0
- package/templates/spec/home_controller.test.js +28 -0
- package/templates/spec/setupTests.js +0 -0
- package/templates/src/AboutPage.jsx +9 -0
- package/templates/src/HomePage.jsx +9 -0
- package/templates/src/Layout.jsx +78 -0
- package/templates/src/ReadmePage.jsx +7 -0
- package/templates/src/app.jsx +29 -0
- package/templates/src/components/ReadmeLoader.jsx +13 -0
- package/templates/src/styles/appstyles.css +3 -0
- package/templates/vite.config.ts +42 -0
package/lib/router.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// The Router object which handles incoming urls and executes the correct
|
|
2
|
+
// server-side logic based on the matching route in the Routing Table
|
|
3
|
+
// ( See example/config/routes.js or config/routes.js for a description of the routes )
|
|
4
|
+
|
|
5
|
+
import {EventEmitter} from 'node:events';
|
|
6
|
+
// var EventEmitter = require('events').EventEmitter;
|
|
7
|
+
import URL from 'node:url';
|
|
8
|
+
// var URL = require('url');
|
|
9
|
+
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import querystring from 'node:querystring';
|
|
12
|
+
import express from 'express';
|
|
13
|
+
import expressWs from 'express-ws';
|
|
14
|
+
import app from './application.js'
|
|
15
|
+
// TODO use modular js only
|
|
16
|
+
import {_extend} from 'util';
|
|
17
|
+
|
|
18
|
+
// var path = require('path');
|
|
19
|
+
// var querystring = require('querystring');
|
|
20
|
+
// var expressWs = require('express-ws');
|
|
21
|
+
// var app = require('./application.js');
|
|
22
|
+
// //var nails = require('./nails.js');
|
|
23
|
+
// var _extend = require('util')._extend;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Creates a Router from an Array of route definitions
|
|
27
|
+
* may want to change this to singleton... just to continue paradigm
|
|
28
|
+
* emits: "contoller_name:action" on successful route
|
|
29
|
+
* controllers and the viewer listen to this object for instructions on doing shit
|
|
30
|
+
*
|
|
31
|
+
* @param routes the array of route definitions from the application config.
|
|
32
|
+
* @param application the nails application singleton.
|
|
33
|
+
*/
|
|
34
|
+
class Router extends EventEmitter {
|
|
35
|
+
static get webSocketsEnabled() {
|
|
36
|
+
return this._webSocketsEnabled;
|
|
37
|
+
}
|
|
38
|
+
static set webSocketsEnabled(enabled) {
|
|
39
|
+
this._webSocketsEnabled = enabled;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static set expressWs(ews) {
|
|
43
|
+
this._expressWs = ews;
|
|
44
|
+
}
|
|
45
|
+
static get expressWs() {
|
|
46
|
+
return this._expressWs;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
enableWebSockets() {
|
|
50
|
+
if (Router.webSocketsEnabled) return;
|
|
51
|
+
Router.webSocketsEnabled = true;
|
|
52
|
+
Router.expressWs = expressWs(this.application);
|
|
53
|
+
expressWs(this.express_router);
|
|
54
|
+
// console.log("WS is still:", this.express_router.ws);
|
|
55
|
+
}
|
|
56
|
+
constructor(routes) {
|
|
57
|
+
super();
|
|
58
|
+
this.application = app;
|
|
59
|
+
// this.express_router = express.Router();
|
|
60
|
+
// console.log("the router is:", this.express_router);
|
|
61
|
+
// console.log("the ws is:", this.express_router.ws);
|
|
62
|
+
this.express_router = app.Router();
|
|
63
|
+
this.addRoutes(routes);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
addRoutes(routes) {
|
|
67
|
+
this.routes = routes;
|
|
68
|
+
routes.forEach(this.addRoute.bind(this));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
addRoute(route) {
|
|
72
|
+
var method = route[0].toLowerCase();
|
|
73
|
+
var path_matcher = route[1];
|
|
74
|
+
var consequences = route[2];
|
|
75
|
+
console.log("setting route for", method, path_matcher, consequences);
|
|
76
|
+
if (method.match(/ws/i)) { // For some reason this hangs
|
|
77
|
+
this.enableWebSockets();
|
|
78
|
+
this.express_router.ws(
|
|
79
|
+
path_matcher,
|
|
80
|
+
this.get_websocket_handler(consequences));
|
|
81
|
+
} else if (consequences && consequences.public) // Is a request for public asset
|
|
82
|
+
this.express_router.use(path_matcher,
|
|
83
|
+
this.application.static(this.application.get('public_root')));
|
|
84
|
+
else this.express_router[method](path_matcher,
|
|
85
|
+
this.get_express_route_handler(consequences));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// TODO: override these for shortcutting crud methods
|
|
89
|
+
// Router.prototype.get;
|
|
90
|
+
// Router.prototype.put;
|
|
91
|
+
// Router.prototype.post;
|
|
92
|
+
// Router.prototype.delete;
|
|
93
|
+
// end crud methods
|
|
94
|
+
|
|
95
|
+
// TODO: Combine this with the regular route method
|
|
96
|
+
routeWs(ws, request) {
|
|
97
|
+
console.log(
|
|
98
|
+
'\nSERVER_LOG:: WebSocket Router received request for: ',
|
|
99
|
+
request.method,
|
|
100
|
+
request.url,
|
|
101
|
+
'\n'
|
|
102
|
+
);
|
|
103
|
+
var params = _extend({}, request.params);
|
|
104
|
+
_extend(params, request.querty);
|
|
105
|
+
|
|
106
|
+
var controller = params._controller;
|
|
107
|
+
var action = params._action;
|
|
108
|
+
console.log('the action is:', controller, action, params);
|
|
109
|
+
console.log('the params are:', params);
|
|
110
|
+
console.log('ws router emitting:', 'dispatchTo:' + controller);
|
|
111
|
+
this.emit('dispatchTo:' + controller, action, params, request, null, ws);
|
|
112
|
+
|
|
113
|
+
if (!request.handled_by_controller) {
|
|
114
|
+
params.error = {message: 'controller ' + controller + ' does not exist'};
|
|
115
|
+
console.log('closing websocket');
|
|
116
|
+
return ws.close(1003, "Action Not available: #" + action);
|
|
117
|
+
//this.emit('dispatchTo:application', 404, params, request, null, ws);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
route(request, response) {
|
|
122
|
+
// TODO: use express logging.
|
|
123
|
+
console.log(
|
|
124
|
+
'\nSERVER_LOG:: Router recieved request for: ',
|
|
125
|
+
request.method, request.url, '\n');
|
|
126
|
+
|
|
127
|
+
var params = _extend({}, request.params);
|
|
128
|
+
_extend(params, request.query);
|
|
129
|
+
|
|
130
|
+
var controller = params._controller;
|
|
131
|
+
//var action = routeParams.action || routeParams.file || routeParams.path;
|
|
132
|
+
//var params = routeParams.params || {};
|
|
133
|
+
var action = params._action;
|
|
134
|
+
console.log('the action is:', controller, action, params);
|
|
135
|
+
console.log('the params are:', params);
|
|
136
|
+
|
|
137
|
+
console.log('router emitting:', 'dispatchTo:' + controller);
|
|
138
|
+
this.emit('dispatchTo:' + controller, action, params, request, response);
|
|
139
|
+
// TODO: raise 404 error using express
|
|
140
|
+
params.error = {message: 'controller ' + controller + ' does not exist'};
|
|
141
|
+
if (!request.handled_by_controller)
|
|
142
|
+
this.emit('dispatchTo:application', 404, params, request, response);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
get_websocket_handler(route_options) {
|
|
146
|
+
route_options = route_options || {};
|
|
147
|
+
return (ws, request) => {
|
|
148
|
+
console.log("handling a websocket request");
|
|
149
|
+
var controller = route_options['controller'];
|
|
150
|
+
var action = route_options['action'];
|
|
151
|
+
for (var i = 0; route_options[i]; i++) {
|
|
152
|
+
if (route_options[i] == 'action') action = action || request.params[i];
|
|
153
|
+
else if (route_options[i] == 'controller')
|
|
154
|
+
controller = controller || request.params[i];
|
|
155
|
+
else request.params[route_options[i]] = request.params[i];
|
|
156
|
+
}
|
|
157
|
+
request.params._action = action || request.params.action || "index";
|
|
158
|
+
request.params._controller =
|
|
159
|
+
controller || request.params.controller || "application";
|
|
160
|
+
|
|
161
|
+
this.routeWs(ws, request);
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
get_express_route_handler(route_options) {
|
|
166
|
+
route_options = route_options || {};
|
|
167
|
+
return (request, response) => {
|
|
168
|
+
// See if controller and action are set explicitly.
|
|
169
|
+
var controller = route_options['controller'];
|
|
170
|
+
var action = route_options['action'];
|
|
171
|
+
// TODO: see if there is a way to use mimie types for this.
|
|
172
|
+
var json = !!route_options['json'];
|
|
173
|
+
var path = route_options['path']; // TODO: what to do with this under express.
|
|
174
|
+
var async = route_options['async'];
|
|
175
|
+
var autorender = route_options['disable_autorender'];
|
|
176
|
+
|
|
177
|
+
// Check for controller and action from regex assignments.
|
|
178
|
+
for (var i = 0; route_options[i]; i++) {
|
|
179
|
+
if (route_options[i] == 'action') action = action || request.params[i];
|
|
180
|
+
else if (route_options[i] == 'controller')
|
|
181
|
+
controller = controller || request.params[i];
|
|
182
|
+
else if (route_options[i] == 'json')
|
|
183
|
+
json = json || request.params[i];
|
|
184
|
+
else request.params[route_options[i]] = request.params[i];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Check for controller and action in parameters.
|
|
188
|
+
request.params._action = action || request.params.action || "index";
|
|
189
|
+
request.params._controller =
|
|
190
|
+
controller || request.params.controller || "application";
|
|
191
|
+
request.params._json = json || !!request.params.json;
|
|
192
|
+
request.params._async = async == null || async == undefined ?
|
|
193
|
+
!!this.application.get('nails_config').config.ASYNC : async;
|
|
194
|
+
// autorender should default to true if it is not defined
|
|
195
|
+
request.params._autorender = autorender ? !!autorender : true;
|
|
196
|
+
|
|
197
|
+
this.route(request, response);
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export default Router;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import DbConnector from './database_connector.js';
|
|
2
|
+
import { Sequelize, Model } from 'sequelize';
|
|
3
|
+
|
|
4
|
+
export default class SequelizeConnector extends DbConnector {
|
|
5
|
+
sequelize;
|
|
6
|
+
|
|
7
|
+
async connect(options) {
|
|
8
|
+
this.sequelize = new Sequelize(options.address);
|
|
9
|
+
try {
|
|
10
|
+
await this.sequelize.authenticate();
|
|
11
|
+
console.log('Connection has been established successfully.');
|
|
12
|
+
} catch (error) {
|
|
13
|
+
console.error('Unable to connect to the database:', error);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @returns {Model}
|
|
19
|
+
*/
|
|
20
|
+
generateModelSuperclass(name, options) {
|
|
21
|
+
if (options.schema) {
|
|
22
|
+
return this.sequelize.define(name, options.schema, options.options);
|
|
23
|
+
}
|
|
24
|
+
return this.sequelize.define(name, options);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async afterInitialization() {
|
|
28
|
+
console.log("SEQUELIZE::Writing changes to SQL Database");
|
|
29
|
+
await this.sequelize.sync({alter: {drop: false}});
|
|
30
|
+
}
|
|
31
|
+
}
|
package/lib/server.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// TODO refractor the server to this module
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@projectinvicta/nails",
|
|
3
|
+
"version": "2.0.15",
|
|
4
|
+
"description": "A node.js webserver scaffold",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"nails-boilerplate": "bin/lib/nails.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"copyreadme": "node bin/convertreadmetohtml.js",
|
|
12
|
+
"test": "mocha --exit spec",
|
|
13
|
+
"debug": "mocha --exit debug spec"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+ssh://git@github.com/stantonwjones/nails-boilerplate.git"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"nails",
|
|
21
|
+
"framework",
|
|
22
|
+
"server",
|
|
23
|
+
"mvc",
|
|
24
|
+
"express",
|
|
25
|
+
"rails"
|
|
26
|
+
],
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@babel/core": "*",
|
|
29
|
+
"@babel/preset-react": "*",
|
|
30
|
+
"body-parser": "^2.2.0",
|
|
31
|
+
"cookie-parser": "^1.4.7",
|
|
32
|
+
"ejs": "*",
|
|
33
|
+
"express": "*",
|
|
34
|
+
"express-ws": "*",
|
|
35
|
+
"fs-extra": "^11.3.2",
|
|
36
|
+
"mime": "*",
|
|
37
|
+
"mongodb": "^4.17.2",
|
|
38
|
+
"mongodb-memory-server": "^8.16.0",
|
|
39
|
+
"mongoose": "^6.13.0",
|
|
40
|
+
"react": "*",
|
|
41
|
+
"react-dom": "^16.13.1",
|
|
42
|
+
"sequelize": "^6.37.7",
|
|
43
|
+
"showdown": "^2.1.0",
|
|
44
|
+
"sqlite3": "^5.1.7",
|
|
45
|
+
"ws": "*"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"chai": "*",
|
|
49
|
+
"chai-http": "*",
|
|
50
|
+
"mocha": "^10.2.0",
|
|
51
|
+
"sinon": "*"
|
|
52
|
+
},
|
|
53
|
+
"config": {
|
|
54
|
+
"mongodbMemoryServer": {
|
|
55
|
+
"version": "latest"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"author": "Stanton W. Jones",
|
|
59
|
+
"license": "MIT"
|
|
60
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
NOT USING THIS RIGHT NOW
|
|
3
|
+
save as preinstall script for cross patform compatibility in the future
|
|
4
|
+
**/
|
|
5
|
+
// The install script to add executables
|
|
6
|
+
var execute = require('child_process').exec;
|
|
7
|
+
var fs = require('fs');
|
|
8
|
+
var os = process.platform;
|
|
9
|
+
|
|
10
|
+
// Compile nails.c
|
|
11
|
+
// get the directories
|
|
12
|
+
var sourceloc = __dirname + "/../bin/lib/nails.c";
|
|
13
|
+
var destloc = __dirname + "/../bin/nails";
|
|
14
|
+
|
|
15
|
+
if ( os.match(/win32/i) ) {
|
|
16
|
+
// use a compiler for windows
|
|
17
|
+
} else {
|
|
18
|
+
// use the GNU compiler g++
|
|
19
|
+
execute("g++ " + sourceloc + " -o " + destloc, handleCompile);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function handleCompile( error, stdout, stderr ) {
|
|
23
|
+
if (error) {
|
|
24
|
+
console.log("Error compiling nails.c");
|
|
25
|
+
console.log(error);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
console.log("Successfully compiled Nails binary");
|
|
29
|
+
process.exit(0);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* This is now being handled by npm
|
|
33
|
+
execute('npm bin -g', createSymlinks);
|
|
34
|
+
|
|
35
|
+
function createSymlinks(error, stdout, stderr){
|
|
36
|
+
var symloc = stdout.replace(/\s/g, '');
|
|
37
|
+
|
|
38
|
+
if ( os.match(/win32/i) ) {
|
|
39
|
+
var command = 'mklink ' + symloc + '\\nails.bat ' +
|
|
40
|
+
__dirname +"\\..\\bin\\nails.bat";
|
|
41
|
+
console.log(command);
|
|
42
|
+
execute(command, handleSymlink);
|
|
43
|
+
} else {
|
|
44
|
+
execute('ln -s ' + __dirname +"/../bin/nails.sh" +
|
|
45
|
+
symloc + '/nails', handleSymlink);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function handleSymlink(error, stdout, stderr) {
|
|
51
|
+
if (error) {
|
|
52
|
+
console.log('error adding symbolic link');
|
|
53
|
+
console.log(error);
|
|
54
|
+
}
|
|
55
|
+
else console.log('successfully add symbolic link');
|
|
56
|
+
}
|
|
57
|
+
*/
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// The uninstall script for removing executables// The install script to add executables
|
|
2
|
+
var execute = require('child_process').exec;
|
|
3
|
+
var os = process.platform;
|
|
4
|
+
|
|
5
|
+
execute('npm bin -g', deleteSymlinks);
|
|
6
|
+
|
|
7
|
+
function deleteSymlinks(error, stdout, stderr){
|
|
8
|
+
var symloc = stdout.replace(/\s/g, '');
|
|
9
|
+
|
|
10
|
+
if ( os.match(/win32/i) ) {
|
|
11
|
+
command = 'del ' + symloc + '\\nails.bat';
|
|
12
|
+
console.log(command);
|
|
13
|
+
execute(command, handleDeletion);
|
|
14
|
+
} else {
|
|
15
|
+
execute('rm ' + symloc + '/nails', handleDeletion);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function handleDeletion(error, stdout, stderr) {
|
|
21
|
+
if (error) console.log('error removing symbolic link');
|
|
22
|
+
else console.log('successfully removed symbolic link');
|
|
23
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import Controller from '../lib/controller.js';
|
|
2
|
+
import assert from 'assert';
|
|
3
|
+
import sinon from 'sinon';
|
|
4
|
+
import {EventEmitter} from 'node:events';
|
|
5
|
+
|
|
6
|
+
function TestController() {
|
|
7
|
+
this.testAction = function () {};
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
class TestEs6Controller extends Controller {
|
|
11
|
+
testEs6Action() {
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe('Controller', function() {
|
|
18
|
+
describe('Controller.setRouter', function() {
|
|
19
|
+
it('should set Controller.router to the router', function() {
|
|
20
|
+
var router = {};
|
|
21
|
+
Controller.setRouter(router);
|
|
22
|
+
assert(Controller.router === router);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
describe('Controller.constructor', function() {
|
|
26
|
+
it('should set the appropriate listener on the router',
|
|
27
|
+
function() {
|
|
28
|
+
let mockRouter = new EventEmitter();
|
|
29
|
+
let mockParams = {_controller: "test"};
|
|
30
|
+
let mockRequest = {};
|
|
31
|
+
let mockResponse = {headersSent: true};
|
|
32
|
+
Controller.setRouter(mockRouter);
|
|
33
|
+
let testController = new TestEs6Controller();
|
|
34
|
+
sinon.spy(testController, "testEs6Action");
|
|
35
|
+
|
|
36
|
+
mockRouter.emit(
|
|
37
|
+
'dispatchTo:testes6', 'testEs6Action', mockParams, mockRequest, mockResponse);
|
|
38
|
+
|
|
39
|
+
assert(testController.testEs6Action.calledWith(
|
|
40
|
+
mockParams, mockRequest, mockResponse));
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
describe('Controller.extend', function() {
|
|
44
|
+
it('should error if an anonymous function is passed', function() {
|
|
45
|
+
try {
|
|
46
|
+
let testController = Controller.extend(function(){});
|
|
47
|
+
assert(false); // Fail if we get here.
|
|
48
|
+
} catch(e) {
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('should set the appropriate listener on the router',
|
|
53
|
+
function() {
|
|
54
|
+
let mockRouter = new EventEmitter();
|
|
55
|
+
let mockParams = {_controller: "test"};
|
|
56
|
+
let mockRequest = {};
|
|
57
|
+
let mockResponse = {headersSent: true};
|
|
58
|
+
Controller.setRouter(mockRouter);
|
|
59
|
+
let testController = Controller.extend(TestController);
|
|
60
|
+
sinon.spy(testController, "testAction");
|
|
61
|
+
|
|
62
|
+
mockRouter.emit(
|
|
63
|
+
'dispatchTo:test', 'testAction', mockParams, mockRequest, mockResponse);
|
|
64
|
+
|
|
65
|
+
assert(testController.testAction.calledWith(
|
|
66
|
+
mockParams, mockRequest, mockResponse));
|
|
67
|
+
});
|
|
68
|
+
it('should set itself as the prototype of the passed constructor method',
|
|
69
|
+
function() {
|
|
70
|
+
let mockRouter = new EventEmitter();
|
|
71
|
+
Controller.setRouter(mockRouter);
|
|
72
|
+
let testController = Controller.extend(TestController);
|
|
73
|
+
assert(testController instanceof Controller);
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
it('should return an initialized instance of the constructor', function() {
|
|
77
|
+
let mockRouter = new EventEmitter();
|
|
78
|
+
Controller.setRouter(mockRouter);
|
|
79
|
+
let testController = Controller.extend(TestController);
|
|
80
|
+
assert(testController instanceof TestController);
|
|
81
|
+
});
|
|
82
|
+
it('should raise an error if no router has been set', function() {
|
|
83
|
+
try {
|
|
84
|
+
let testController = Controller.extend(TestController);
|
|
85
|
+
assert(false); // Fail if we get here.
|
|
86
|
+
} catch (expectedError) {
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
describe('#_do', function() {
|
|
91
|
+
it('should call the function on the controller matching the given action');
|
|
92
|
+
it('should call 404 if the action does not exist on the controller instance');
|
|
93
|
+
it('should call 500 if the action throws an error');
|
|
94
|
+
it('should attempt to render a view');
|
|
95
|
+
it('should not render a view if data has already been sent to the client');
|
|
96
|
+
it('should not render a view if _async is true');
|
|
97
|
+
it('should not render a view if async is true on the action');
|
|
98
|
+
});
|
|
99
|
+
describe('#404', function() {
|
|
100
|
+
});
|
|
101
|
+
describe('#500', function() {
|
|
102
|
+
});
|
|
103
|
+
describe('#public', function() {
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import assert from 'assert';
|
|
2
|
+
import Model from '../lib/model_v2.js';
|
|
3
|
+
import MongooseConnectorUtil from './mongoose_connector.util.js';
|
|
4
|
+
|
|
5
|
+
const testSchema = {
|
|
6
|
+
name: String,
|
|
7
|
+
isTrue: Boolean,
|
|
8
|
+
index: Number
|
|
9
|
+
}
|
|
10
|
+
let TestModel = null;
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
describe('ModelV2', function() {
|
|
14
|
+
var util;
|
|
15
|
+
beforeEach(async function() {
|
|
16
|
+
util = new MongooseConnectorUtil();
|
|
17
|
+
let connector = await util.getTestConnector();
|
|
18
|
+
Model.setConnector(connector);
|
|
19
|
+
TestModel =
|
|
20
|
+
class Test extends new Model(
|
|
21
|
+
"" + Math.random(), {schema: testSchema}) {
|
|
22
|
+
whatsMyName() {return this.name};
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
afterEach(async function() {
|
|
26
|
+
await util.cleanup();
|
|
27
|
+
});
|
|
28
|
+
describe('Mongoose Model Inheritance', function() {
|
|
29
|
+
const testAttr = {
|
|
30
|
+
name: "testname",
|
|
31
|
+
isTrue: false,
|
|
32
|
+
index: 7
|
|
33
|
+
};
|
|
34
|
+
it("should be able to create a model", async function() {
|
|
35
|
+
const testModel = new TestModel(testAttr);
|
|
36
|
+
assert(testModel.name == testAttr.name);
|
|
37
|
+
assert(testModel.isTrue == testAttr.isTrue);
|
|
38
|
+
assert(testModel.index == testAttr.index);
|
|
39
|
+
await testModel.save();
|
|
40
|
+
console.log("The ID is:", testModel._id);
|
|
41
|
+
})
|
|
42
|
+
it("should be able to update a model", function() {
|
|
43
|
+
const testModel = new TestModel(testAttr);
|
|
44
|
+
const newName = "newName";
|
|
45
|
+
return testModel.save().then(savedModel => {
|
|
46
|
+
savedModel.name = newName;
|
|
47
|
+
return savedModel.save();
|
|
48
|
+
}).then(secondSavedModel => {
|
|
49
|
+
assert(secondSavedModel.name == newName);
|
|
50
|
+
assert(secondSavedModel._id == testModel._id);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
it("should be able to delete a model", async function() {
|
|
54
|
+
const testModel = new TestModel(testAttr);
|
|
55
|
+
await testModel.save();
|
|
56
|
+
await TestModel.deleteOne({_id: testModel._id});
|
|
57
|
+
assert.equal(await TestModel.findById(testModel._id), null);
|
|
58
|
+
})
|
|
59
|
+
it("should be able to find a model by id", async function() {
|
|
60
|
+
const testModel = new TestModel(testAttr);
|
|
61
|
+
await testModel.save();
|
|
62
|
+
const foundModel = await TestModel.findById(testModel._id);
|
|
63
|
+
assert(testModel._id.toString() == foundModel._id.toString());
|
|
64
|
+
assert.equal(testModel.name, foundModel.name);
|
|
65
|
+
assert.equal(testModel.isTrue, foundModel.isTrue);
|
|
66
|
+
assert.equal(testModel.index, foundModel.index);
|
|
67
|
+
});
|
|
68
|
+
it("should preserve instance methods", async function() {
|
|
69
|
+
const testModel = new TestModel(testAttr);
|
|
70
|
+
await testModel.save();
|
|
71
|
+
const foundModel = await TestModel.findById(testModel._id);
|
|
72
|
+
assert.equal(foundModel.whatsMyName(), testModel.name);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
})
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import MongooseConnector from '../lib/mongoose_connector.js';
|
|
2
|
+
import {MongoMemoryServer} from 'mongodb-memory-server';
|
|
3
|
+
|
|
4
|
+
let singularInstanceCreated = false;
|
|
5
|
+
let promisedMongod = null;
|
|
6
|
+
|
|
7
|
+
class MongoDBConnectorUtil {
|
|
8
|
+
constructor() {
|
|
9
|
+
promisedMongod = MongoMemoryServer.create();
|
|
10
|
+
singularInstanceCreated = true;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async getTestConnector() {
|
|
14
|
+
this.mongod = await promisedMongod;
|
|
15
|
+
const uri = this.mongod.getUri();
|
|
16
|
+
const port = this.mongod.instanceInfo.port;
|
|
17
|
+
const dbPath = this.mongod.instanceInfo.dbPath;
|
|
18
|
+
const dbName = this.mongod.instanceInfo.dbName;
|
|
19
|
+
const dbConfig =
|
|
20
|
+
{uri: uri, port: port, database: dbName, dbPath: dbPath};
|
|
21
|
+
//console.log(JSON.stringify(dbConfig));
|
|
22
|
+
return new MongooseConnector(dbConfig);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async cleanup() {
|
|
26
|
+
await this.mongod.stop();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default MongoDBConnectorUtil;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import MongooseMemoryConnector from '../lib/mongoose_mem_connector.js';
|
|
2
|
+
import mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
class MongooseConnectorUtil {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.mongoose = mongoose;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async getTestConnector() {
|
|
10
|
+
const dbConnector = new MongooseMemoryConnector();
|
|
11
|
+
this.connection = await dbConnector.connect();
|
|
12
|
+
debugger;
|
|
13
|
+
return dbConnector;
|
|
14
|
+
}
|
|
15
|
+
async cleanup() {
|
|
16
|
+
debugger;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default MongooseConnectorUtil;
|
|
File without changes
|