@projectinvicta/nails 2.0.15 → 3.0.1

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 (153) hide show
  1. package/README.md +70 -84
  2. package/bin/lib/init.js +0 -4
  3. package/bin/test/test_init.sh +33 -0
  4. package/index.ts +11 -0
  5. package/lib/Controller.ts +207 -0
  6. package/lib/Nails.ts +210 -0
  7. package/lib/Router.ts +180 -0
  8. package/lib/{application.js → application.ts} +8 -3
  9. package/lib/config.ts +74 -0
  10. package/package.json +17 -15
  11. package/templates/default/config/db.ts +13 -0
  12. package/{spec/services/integration_sequelize/config/mimes.js → templates/default/config/mimes.ts} +42 -61
  13. package/templates/default/config/routes.ts +22 -0
  14. package/templates/default/config/{service.js → service.ts} +2 -2
  15. package/templates/default/package.json +8 -2
  16. package/templates/default/public/README.xml +68 -85
  17. package/templates/default/server/controllers/home_controller.js +2 -2
  18. package/templates/{server/controllers/home_controller.js → default/server/controllers/users_controller.ts} +29 -34
  19. package/templates/default/server/models/Dog.ts +8 -0
  20. package/templates/default/server/models/User.ts +14 -0
  21. package/templates/default/spec/User.test.js +7 -5
  22. package/templates/default/spec/home_controller.test.js +3 -3
  23. package/tests/bin/init.spec.js +3 -0
  24. package/tests/controller.spec.js +61 -0
  25. package/tests/nails.spec.js +4 -0
  26. package/tests/router.spec.js +105 -0
  27. package/tests/services/integration/config/db.ts +7 -0
  28. package/{spec/services/integration_sequelize → tests/services/integration}/config/service.js +8 -8
  29. package/{spec → tests}/services/integration/server/controllers/classbased_controller.js +2 -2
  30. package/tests/services/integration/server/controllers/default_json_controller.js +32 -0
  31. package/{spec → tests}/services/integration/server/controllers/error_controller.js +2 -2
  32. package/tests/services/integration/server/controllers/home_controller.js +17 -0
  33. package/{spec → tests}/services/integration/server/controllers/json_controller.js +2 -2
  34. package/{spec → tests}/services/integration/server/controllers/manualrenderasync_controller.js +2 -2
  35. package/tests/services/integration/server/controllers/mjs_controller.mjs +9 -0
  36. package/tests/services/integration/server/controllers/modeltest_controller.js +15 -0
  37. package/{spec → tests}/services/integration/server/controllers/websocket_controller.js +1 -1
  38. package/tests/services/integration/server/models/dog.js +8 -0
  39. package/tests/services/integration/server/models/owner.js +13 -0
  40. package/{spec/services/integration_sequelize → tests/services/integration}/server.js +3 -4
  41. package/tests/services.integration.spec.js +210 -0
  42. package/vite.config.ts +23 -0
  43. package/index.js +0 -6
  44. package/lib/collection.js +0 -6
  45. package/lib/controller.js +0 -182
  46. package/lib/database_connector.js +0 -12
  47. package/lib/firebase_connector.js +0 -94
  48. package/lib/model_v2.js +0 -24
  49. package/lib/mongoose_connector.js +0 -49
  50. package/lib/mongoose_mem_connector.js +0 -21
  51. package/lib/nails.js +0 -244
  52. package/lib/router.js +0 -202
  53. package/lib/sequelize_connector.js +0 -31
  54. package/lib/server.js +0 -1
  55. package/spec/bin/init.spec.js +0 -0
  56. package/spec/controller.spec.js +0 -105
  57. package/spec/model_v2.spec.js +0 -75
  58. package/spec/mongodb_connector.util.js +0 -30
  59. package/spec/mongoose_connector.util.js +0 -20
  60. package/spec/nails.spec.js +0 -0
  61. package/spec/router.spec.js +0 -101
  62. package/spec/sequelize_connector.spec.js +0 -91
  63. package/spec/sequelize_connector.util.js +0 -18
  64. package/spec/services/integration/config/db.js +0 -14
  65. package/spec/services/integration/config/service.js +0 -48
  66. package/spec/services/integration/server/controllers/default_json_controller.js +0 -20
  67. package/spec/services/integration/server/controllers/home_controller.js +0 -39
  68. package/spec/services/integration/server/controllers/mjs_controller.mjs +0 -13
  69. package/spec/services/integration/server/controllers/modeltest_controller.js +0 -18
  70. package/spec/services/integration/server/models/dog.js +0 -6
  71. package/spec/services/integration/server.js +0 -9
  72. package/spec/services/integration_sequelize/README.md +0 -5
  73. package/spec/services/integration_sequelize/client/css/styles.css +0 -0
  74. package/spec/services/integration_sequelize/client/download.jpg +0 -0
  75. package/spec/services/integration_sequelize/client/favicon.ico +0 -0
  76. package/spec/services/integration_sequelize/client/index.html +0 -9
  77. package/spec/services/integration_sequelize/client/js/client.js +0 -0
  78. package/spec/services/integration_sequelize/client/js/components/app.jsx +0 -15
  79. package/spec/services/integration_sequelize/config/db.js +0 -4
  80. package/spec/services/integration_sequelize/config/routes.js +0 -25
  81. package/spec/services/integration_sequelize/config/ssl/certificate.pem +0 -22
  82. package/spec/services/integration_sequelize/config/ssl/csr.csr +0 -17
  83. package/spec/services/integration_sequelize/config/ssl/key.pem +0 -28
  84. package/spec/services/integration_sequelize/config/ssl/private_key.pem +0 -30
  85. package/spec/services/integration_sequelize/config/ssl/public_key.pem +0 -9
  86. package/spec/services/integration_sequelize/package.json +0 -23
  87. package/spec/services/integration_sequelize/server/controllers/default_json_controller.js +0 -21
  88. package/spec/services/integration_sequelize/server/controllers/home_controller.js +0 -39
  89. package/spec/services/integration_sequelize/server/models/dog.js +0 -7
  90. package/spec/services/integration_sequelize/server/models/owner.js +0 -10
  91. package/spec/services/integration_sequelize/server/views/defaultjson/testnojson.ejs +0 -1
  92. package/spec/services/integration_sequelize/server/views/testreact/testreact.ejs +0 -15
  93. package/spec/services.integration.spec.js +0 -296
  94. package/spec/services.integration_sequelize.spec.js +0 -60
  95. package/templates/bin/promote.sh +0 -20
  96. package/templates/bin/rollout.sh +0 -74
  97. package/templates/bin/server.js +0 -6
  98. package/templates/bin/start.sh +0 -16
  99. package/templates/common/readme_fetcher.js +0 -4
  100. package/templates/config/db.js +0 -19
  101. package/templates/config/mimes.js +0 -59
  102. package/templates/config/routes.js +0 -38
  103. package/templates/config/service.js +0 -45
  104. package/templates/config/ssl/certificate.pem +0 -22
  105. package/templates/config/ssl/csr.csr +0 -17
  106. package/templates/config/ssl/key.pem +0 -28
  107. package/templates/config/ssl/private_key.pem +0 -30
  108. package/templates/config/ssl/public_key.pem +0 -9
  109. package/templates/default/config/db.js +0 -19
  110. package/templates/default/config/mimes.js +0 -59
  111. package/templates/default/config/routes.js +0 -38
  112. package/templates/default/server/models/User.js +0 -18
  113. package/templates/package-lock.json +0 -9048
  114. package/templates/package.json +0 -43
  115. package/templates/public/README.xml +0 -332
  116. package/templates/public/css/styles.css +0 -17
  117. package/templates/public/download.jpg +0 -0
  118. package/templates/public/favicon.ico +0 -0
  119. package/templates/public/index.html +0 -9
  120. package/templates/public/js/client.js +0 -1
  121. package/templates/server/models/User.js +0 -18
  122. package/templates/server/views/home/index.ejs +0 -14
  123. package/templates/server/views/partials/javascripts.ejs +0 -1
  124. package/templates/server/views/partials/reactapp.ejs +0 -1
  125. package/templates/server/views/partials/styles.ejs +0 -3
  126. package/templates/spec/User.test.js +0 -20
  127. package/templates/spec/home_controller.test.js +0 -28
  128. package/templates/spec/setupTests.js +0 -0
  129. package/templates/src/AboutPage.jsx +0 -9
  130. package/templates/src/HomePage.jsx +0 -9
  131. package/templates/src/Layout.jsx +0 -78
  132. package/templates/src/ReadmePage.jsx +0 -7
  133. package/templates/src/app.jsx +0 -29
  134. package/templates/src/components/ReadmeLoader.jsx +0 -13
  135. package/templates/src/styles/appstyles.css +0 -3
  136. package/templates/vite.config.ts +0 -42
  137. /package/{spec → tests}/services/integration/README.md +0 -0
  138. /package/{spec → tests}/services/integration/client/css/styles.css +0 -0
  139. /package/{spec → tests}/services/integration/client/download.jpg +0 -0
  140. /package/{spec → tests}/services/integration/client/favicon.ico +0 -0
  141. /package/{spec → tests}/services/integration/client/index.html +0 -0
  142. /package/{spec → tests}/services/integration/client/js/client.js +0 -0
  143. /package/{spec → tests}/services/integration/client/js/components/app.jsx +0 -0
  144. /package/{spec → tests}/services/integration/config/mimes.js +0 -0
  145. /package/{spec → tests}/services/integration/config/routes.js +0 -0
  146. /package/{spec → tests}/services/integration/config/ssl/certificate.pem +0 -0
  147. /package/{spec → tests}/services/integration/config/ssl/csr.csr +0 -0
  148. /package/{spec → tests}/services/integration/config/ssl/key.pem +0 -0
  149. /package/{spec → tests}/services/integration/config/ssl/private_key.pem +0 -0
  150. /package/{spec → tests}/services/integration/config/ssl/public_key.pem +0 -0
  151. /package/{spec → tests}/services/integration/package.json +0 -0
  152. /package/{spec → tests}/services/integration/server/views/defaultjson/testnojson.ejs +0 -0
  153. /package/{spec → tests}/services/integration/server/views/testreact/testreact.ejs +0 -0
@@ -1,105 +0,0 @@
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
- });
@@ -1,75 +0,0 @@
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
- })
@@ -1,30 +0,0 @@
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;
@@ -1,20 +0,0 @@
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
@@ -1,101 +0,0 @@
1
- // var express_app = require('../lib/application.js');
2
- import Router from '../lib/router.js';
3
- import assert from 'assert';
4
- import express_app from '../lib/application.js';
5
-
6
- express_app.set("public_root", import.meta.dirname + "/services/integration/public");
7
- var testRoutes = [
8
- ['GET', '^/$', {controller: 'testController', action: 'testAction'}],
9
- ['GET', /^\/public\/*/, {public: true}]
10
- ];
11
-
12
- var router;
13
-
14
- describe('Router', function() {
15
- describe('route', function() {
16
- beforeEach(function() {
17
- router = new Router(testRoutes);
18
- });
19
- it(`should emit dispatchTo:application if a registered controller does
20
- not match the action`,
21
- function(done) {
22
- var mockRequest = {
23
- method: 'get',
24
- url: 'http://www.test.com/public/test.html'
25
- };
26
- var mockResponse = {};
27
- var expectedAction = '404';
28
- var testFunctionCalled;
29
- router.on('dispatchTo:application', test);
30
-
31
- function test(action, params, request, response) {
32
- testFunctionCalled = true;
33
- assert.equal(action, expectedAction);
34
- assert.equal(typeof(params), 'object');
35
- assert.equal(params.file, undefined);
36
- assert.equal(request, mockRequest);
37
- assert.equal(response, mockResponse);
38
- done();
39
- }
40
- router.route(mockRequest, mockResponse);
41
- if (!testFunctionCalled) done('testFailed');
42
- });
43
- it('should emit dispatch:<controller> event based on the params',
44
- function(done) {
45
- const mockParams = {
46
- _controller: "test",
47
- _action: "testAction"
48
- };
49
- var mockRequest = {
50
- method: 'get',
51
- url: 'http://www.test.com/',
52
- params: mockParams
53
- };
54
- var mockResponse = {};
55
- var expectedAction = 'testAction';
56
- var testFunctionCalled;
57
- router.on('dispatchTo:test', test);
58
-
59
- function test(action, params, request, response) {
60
- testFunctionCalled = true;
61
- assert.equal(action, expectedAction);
62
- assert.equal(params._controller, mockParams._controller);
63
- assert.equal(params._action, mockParams._action);
64
- assert.equal(request, mockRequest);
65
- assert.equal(response, mockResponse);
66
- done();
67
- }
68
- router.route(mockRequest, mockResponse);
69
- if (!testFunctionCalled) done('testFailed');
70
- });
71
- it("should emit dispatch:<controller> event based on the url query",
72
- function(done) {
73
- const mockQuery = {
74
- _controller: "test",
75
- _action: "testAction"
76
- };
77
- var mockRequest = {
78
- method: 'get',
79
- url: 'http://www.test.com/',
80
- query: mockQuery
81
- };
82
- var mockResponse = {};
83
- var expectedAction = 'testAction';
84
- var testFunctionCalled;
85
- router.on('dispatchTo:test', test);
86
-
87
- function test(action, params, request, response) {
88
- testFunctionCalled = true;
89
- assert.equal(action, expectedAction);
90
- assert.equal(params._controller, mockQuery._controller);
91
- assert.equal(params._action, mockQuery._action);
92
- assert.equal(request, mockRequest);
93
- assert.equal(response, mockResponse);
94
- done();
95
- }
96
- router.route(mockRequest, mockResponse);
97
- if (!testFunctionCalled) done('testFailed');
98
- }
99
- );
100
- });
101
- });
@@ -1,91 +0,0 @@
1
- // import SequelizeConnector from '../lib/sequelize_connector.js';
2
- import assert from 'assert';
3
- import Model from '../lib/model_v2.js';
4
- import { DataTypes } from 'sequelize';
5
- import SequelizeConnectorUtil from './sequelize_connector.util.js';
6
-
7
- const TEST_SCHEMA = {
8
- name: DataTypes.STRING,
9
- favoriteColor: {
10
- type: DataTypes.STRING,
11
- defaultValue: 'green',
12
- },
13
- age: DataTypes.INTEGER,
14
- cash: DataTypes.INTEGER,
15
- }
16
- let TestSequelizeModel = null;
17
- let TestSequelizeIndexedModel = null;
18
-
19
- const TEST_OPTIONS = {
20
- schema: {
21
- label: DataTypes.STRING,
22
- value: DataTypes.STRING,
23
- },
24
- options: {
25
- indexes: [
26
- {
27
- unique: true,
28
- fields: ['label', 'value'],
29
- },
30
- ],
31
- },
32
- };
33
-
34
- describe('ModelV2 using SequelizeConnector', function() {
35
- let util;
36
- beforeEach(async function() {
37
- util = new SequelizeConnectorUtil();
38
- const connector = await util.getTestConnector();
39
- Model.setConnector(connector);
40
- TestSequelizeModel =
41
- class TestSequelizeModel extends new Model("TestSequelizeModel", TEST_SCHEMA) {};
42
- TestSequelizeIndexedModel =
43
- class TestSequelizeIndexedModel extends new Model("TestSequelizeIndexedModel", TEST_OPTIONS) {};
44
- await connector.sequelize.sync({ force: true });
45
- });
46
-
47
- it("Should be able to create, save, and retrieve a model", async function() {
48
- const MODEL_NAME = "First test model created";
49
- const testModel = TestSequelizeModel.build({name: MODEL_NAME});
50
- await testModel.save();
51
- const models = await TestSequelizeModel.findAll();
52
- assert(models.length == 1, "Should have one model");
53
- assert(models[0].name == MODEL_NAME, "Name should be consistent");
54
- assert(models[0] instanceof TestSequelizeModel);
55
- });
56
-
57
- it("Should be able to create, save, and retrieve a complex model", async function() {
58
- const MODEL_LABEL = "First test model LABEL";
59
- const MODEL_VALUE = "First test model VALUE";
60
- const testModel = await TestSequelizeIndexedModel.create({label: MODEL_LABEL, value: MODEL_VALUE});
61
- const models = await TestSequelizeIndexedModel.findAll();
62
- assert(models.length == 1, "Should have one model");
63
- assert(models[0].label == MODEL_LABEL, "label should be persisted");
64
- assert(models[0].value == MODEL_VALUE, "value should be persisted");
65
- assert(models[0] instanceof TestSequelizeIndexedModel);
66
- });
67
-
68
- it("Should be able to respect unique indexes", async function() {
69
- const MODEL_LABEL_0 = "MODEL_LABEL_0";
70
- const MODEL_VALUE_0 = "MODEL_VALUE_0";
71
- const MODEL_LABEL_1 = "MODEL_LABEL_1";
72
- const MODEL_VALUE_1 = "MODEL_VALUE_1";
73
- const testModels = await TestSequelizeIndexedModel.bulkCreate(
74
- [
75
- {label: MODEL_LABEL_0, value: MODEL_VALUE_0},
76
- {label: MODEL_LABEL_0, value: MODEL_VALUE_1},
77
- {label: MODEL_LABEL_1, value: MODEL_VALUE_0},
78
- {label: MODEL_LABEL_1, value: MODEL_VALUE_1},
79
- ]
80
- );
81
- assert(testModels.length == 4, "Should creaete 4 models");
82
- let indexWasRespected = true;
83
- try {
84
- await TestSequelizeIndexedModel.create({label: MODEL_LABEL_0, value: MODEL_VALUE_0});
85
- indexWasRespected = false;
86
- } catch(e) {
87
- console.log("Error was thrown as expected");
88
- }
89
- assert(indexWasRespected, "Should have thrown an error")
90
- });
91
- });
@@ -1,18 +0,0 @@
1
- import SequelizeConnector from '../lib/sequelize_connector.js';
2
-
3
- class SequelizeConnectorUtil {
4
- constructor() {
5
- }
6
-
7
- async getTestConnector() {
8
- const dbConnector = new SequelizeConnector();
9
- this.connection = await dbConnector.connect({address: 'sqlite::memory:'});
10
- debugger;
11
- return dbConnector;
12
- }
13
- async cleanup() {
14
- debugger;
15
- }
16
- }
17
-
18
- export default SequelizeConnectorUtil;
@@ -1,14 +0,0 @@
1
- export default {
2
- // connector: 'sqlite3_connector.js',
3
- // connector: 'mongoose_connector.js',
4
- connector: 'mongoose_mem_connector.js',
5
- // url: 'mongodb://localhost',
6
- // port: 4444,
7
-
8
- dbName: 'development',
9
-
10
- // For the sqlite3 connector. Unless a filename is defined, an in-memory
11
- // database is used. In-memory databases are not persisted, and will be lost
12
- // when the server is restarted.
13
- //filename: ':memory:'
14
- }
@@ -1,48 +0,0 @@
1
- // Initializes application before server starts
2
- // Each of these is REQUIRED
3
-
4
- import routes from './routes.js';
5
- import mimes from './mimes.js';
6
- import db from './db.js';
7
-
8
- var SERVER_ROOT = import.meta.dirname + '/..';
9
- var APP_ROOT = SERVER_ROOT + '/server';
10
-
11
- // Only for reading the certificates for SSL
12
- import fs from 'node:fs';
13
- // const fs = require('fs');
14
- const PRIVATE_KEY_FILE = fs.readFileSync(`${import.meta.dirname}/ssl/key.pem`);
15
- const CERTIFICATE_FILE = fs.readFileSync(`${import.meta.dirname}/ssl/certificate.pem`);
16
-
17
- var config = {
18
- APP_ROOT: APP_ROOT,
19
- // root directory for delivering static assets
20
- PUBLIC_ROOT: SERVER_ROOT + '/client',
21
- CONTROLLERS_ROOT: APP_ROOT + '/controllers',
22
- VIEWS_ROOT: APP_ROOT + '/views',
23
- //MODELS_ROOT: APP_ROOT + '/models',
24
- SERVER_ROOT: SERVER_ROOT,
25
-
26
- ENABLE_HTTP: true,
27
- //IP: "0.0.0.0",
28
- PORT: 3333,
29
-
30
- ASYNC: false,
31
-
32
- // For HTTPS
33
- ENABLE_HTTPS: true,
34
- SSL_PORT: 3334,
35
- PRIVATE_KEY: PRIVATE_KEY_FILE,
36
- CERTIFICATE: CERTIFICATE_FILE,
37
- };
38
-
39
- // module.exports.routes = require('./routes.js');
40
- // module.exports.mimes = require('./mimes.js');
41
- // module.exports.db = require('./db.js');
42
-
43
- export default {
44
- config,
45
- routes,
46
- db,
47
- mimes,
48
- }
@@ -1,20 +0,0 @@
1
- import nails from "../../../../../index.js";
2
-
3
- export default class DefaultJsonController extends nails.Controller {
4
- json = true;
5
- routes = [
6
- ['get', 'arbi/trary/testautoaction'],
7
- ['get', 'arbi/trary/testautojson', {action: 'testautojson'}],
8
- ['get', 'arbi/trary/testjsonoverridden', {action: 'testnojson', json: false}],
9
- ];
10
-
11
- testautoaction(params, request, response) {
12
- return {json_testautoaction: true};
13
- }
14
-
15
- testautojson(params, request, response) {
16
- return {json_testautojson: true};
17
- }
18
-
19
- testnojson(params, request, response) {}
20
- }
@@ -1,39 +0,0 @@
1
- export default function HomeController() {
2
- this.index = function(params, request, response) {
3
- console.log("HOME::INDEX");
4
- response.json({
5
- home_index: true
6
- });
7
- };
8
- this.testaction = function(params, request, response) {
9
- response.json({
10
- home_testaction: true
11
- });
12
- }
13
- this.test_ejs = function() {
14
- };
15
- /*
16
- this.public_index = function(params, request, response) {
17
- response.public({path: 'index.html'});
18
- };
19
- this.json = function(params, request, response) {
20
- response.json({test: 'json'});
21
- };
22
- // By setting a method to asynchronous, Nails will wait for an
23
- // explicit response to the client. Otherwise, it will attempt
24
- // to respond with a view immediately after the action terminates.
25
- this.json.async = true;
26
-
27
- this.test_model = function(params, request, response) {
28
- var u = new User();
29
- u.set('created_at', (new Date()).getTime());
30
- u.save();
31
- response.json({new_user_id: u.id.toString()});
32
- };
33
- this.test_id_template = function(params, request, response) {
34
- var varz = {};
35
- varz.id = params.id || "no id set";
36
- response.render('test_id', varz);
37
- };
38
- */
39
- }
@@ -1,13 +0,0 @@
1
- /*
2
- const Controller =
3
- require("../../../../../index.js").Controller;
4
- */
5
- import nails from "../../../../../index.js";
6
- export default class MjsController extends nails.Controller {
7
- // DO NOT OVERRIDE CONSTRUCTOR
8
- index(params, request, response) {
9
- response.json({
10
- classbased_index: true
11
- });
12
- }
13
- }
@@ -1,18 +0,0 @@
1
- import nails from "../../../../../index.js";
2
- import Dog from "../models/dog.js";
3
-
4
- export default class ModeltestController extends nails.Controller {
5
- async createdog(params, request, response) {
6
- let dog = new Dog({good: true, name: params.name});
7
- await dog.save();
8
- return dog._id.toString();
9
- }
10
-
11
- async getdogbyid(params, request, response) {
12
- let dog = await Dog.findById(params.id);
13
- return {
14
- name: dog.name,
15
- good: dog.good
16
- };
17
- }
18
- }
@@ -1,6 +0,0 @@
1
- import nails from '../../../../../index.js';
2
- const dogSchema = {
3
- good: Boolean,
4
- name: String
5
- };
6
- export default class Dog extends new nails.Model("Dog", {schema: dogSchema}) {};
@@ -1,9 +0,0 @@
1
- // var nails = require('../../../index.js');
2
- import nails from '../../../index.js';
3
- import service_config from './config/service.js';
4
-
5
- // See self-documented config files
6
- // var service_config = require('./config/service.js');
7
- // console.log("starting server")
8
- (await nails( service_config )).startServer();
9
- export default nails; // export nails for testing
@@ -1,5 +0,0 @@
1
- Integration testing (Sans DB Connector)
2
- ==============
3
-
4
- The package.json was copied from the example app. This is for integration
5
- testing nails.
@@ -1,9 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- </head>
5
- <body>
6
- <h1>Welcome</h1>
7
- <div></div>
8
- </body>
9
- </html>
@@ -1,15 +0,0 @@
1
- // Use frontend React components to build a single-page webapp
2
- class App extends React.Component {
3
- render() {
4
- return (
5
- <div>
6
- Successfully rendered your homepage!
7
- </div>
8
- );
9
- }
10
- }
11
-
12
- ReactDOM.render(
13
- <App />,
14
- document.getElementById('app')
15
- );
@@ -1,4 +0,0 @@
1
- export default {
2
- connector: 'sequelize_connector.js',
3
- address: 'sqlite::memory:',
4
- }