retold-data-service 2.0.6 → 2.0.8
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/Dockerfile_Service +50 -0
- package/debug/Harness.js +81 -2
- package/package.json +15 -7
- package/source/Retold-Data-Service.js +44 -13
- package/test/RetoldDataService_tests.js +6 -1
- package/test/model/MeadowModel-Extended.json +2567 -0
- package/test/model/{Model.json → MeadowModel.json} +42 -19
- package/{debug/model/generated_documentation → test/model/doc}/Dictionary.md +1 -1
- package/{debug/model/generated_documentation → test/model/doc}/Model-Author.md +5 -5
- package/{debug/model/generated_documentation → test/model/doc}/Model-Book.md +6 -6
- package/{debug/model/generated_documentation → test/model/doc}/Model-BookAuthorJoin.md +4 -4
- package/{debug/model/generated_documentation → test/model/doc}/Model-BookPrice.md +6 -6
- package/{debug/model/generated_documentation → test/model/doc}/Model-Review.md +7 -7
- package/{debug/model/generated_documentation → test/model/doc}/ModelChangeTracking.md +1 -1
- package/{debug/model/generated_diagram/Stricture_Output.dot → test/model/doc/diagrams/Relationships.dot} +1 -1
- package/test/model/doc/diagrams/RelationshipsFull.dot +13 -0
- package/test/model/doc/diagrams/RelationshipsFull.png +0 -0
- package/test/model/meadow/MeadowSchemaAuthor.json +431 -0
- package/test/model/meadow/MeadowSchemaBook.json +527 -0
- package/test/model/meadow/MeadowSchemaBookAuthorJoin.json +335 -0
- package/test/model/meadow/MeadowSchemaBookPrice.json +511 -0
- package/test/model/meadow/MeadowSchemaReview.json +463 -0
- package/{debug/model/sql_create/BookStore-CreateDatabase.mysql.sql → test/model/mysql_create/MeadowModel-CreateMySQLDatabase.mysql.sql} +6 -6
- package/debug/bookstore-configuration.json +0 -30
- package/debug/model/Model-Extended.json +0 -915
- package/debug/model/Model.json +0 -280
- package/debug/model/bookstore-api-endpoint-exercises.paw +0 -0
- package/debug/model/ddl/BookStore.ddl +0 -66
- package/debug/model/generated_diagram/README.md +0 -1
- package/debug/model/generated_documentation/README.md +0 -1
- package/debug/model/manual_scripts/DropTables.sql +0 -5
- package/debug/model/manual_scripts/MySQL-Laden-Entry.sh +0 -17
- package/debug/model/manual_scripts/MySQL-Security.sql +0 -5
- package/debug/model/manual_scripts/README.md +0 -2
- package/debug/model/manual_scripts/my.cnf +0 -4
- package/debug/model/meadow/Model-MeadowSchema-Author.json +0 -220
- package/debug/model/meadow/Model-MeadowSchema-Book.json +0 -268
- package/debug/model/meadow/Model-MeadowSchema-BookAuthorJoin.json +0 -172
- package/debug/model/meadow/Model-MeadowSchema-BookPrice.json +0 -260
- package/debug/model/meadow/Model-MeadowSchema-Review.json +0 -236
- package/debug/model/meadow/README.md +0 -1
- package/debug/model/sql_create/BookStore-CreateAndPopulateTables.sql +0 -194
- package/debug/model/sql_create/README.md +0 -1
- package/test/model/Model-Extended.json +0 -915
- package/test/model/meadow/Model-MeadowSchema-Author.json +0 -220
- package/test/model/meadow/Model-MeadowSchema-Book.json +0 -268
- package/test/model/meadow/Model-MeadowSchema-BookAuthorJoin.json +0 -172
- package/test/model/meadow/Model-MeadowSchema-BookPrice.json +0 -260
- package/test/model/meadow/Model-MeadowSchema-Review.json +0 -236
- /package/{debug/model/Model-PICT.json → test/model/MeadowModel-PICT.json} +0 -0
- /package/{debug/model/generated_diagram/Stricture_Output.png → test/model/doc/diagrams/Relationships.png} +0 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
FROM debian:latest
|
|
2
|
+
MAINTAINER steven velozo
|
|
3
|
+
|
|
4
|
+
RUN echo "...installing debian dependencies..."
|
|
5
|
+
RUN apt update
|
|
6
|
+
RUN apt install vim curl tmux -y
|
|
7
|
+
|
|
8
|
+
RUN echo "Building service image..."
|
|
9
|
+
|
|
10
|
+
RUN echo "...configuring mariadb (mysql) server..."
|
|
11
|
+
RUN apt install default-mysql-server default-mysql-client -y
|
|
12
|
+
RUN sed -i "s|bind-address|#bind-address|g" /etc/mysql/mariadb.conf.d/50-server.cnf
|
|
13
|
+
COPY ./debug/model/manual_scripts/MySQL-Security.sql /root/MySQL-Configure-Security.sql
|
|
14
|
+
COPY ./debug/model/manual_scripts/MySQL-Laden-Entry-ServicesOnly.sh /usr/bin/MySQL-Laden-Entry-NoSudo.sh
|
|
15
|
+
RUN ( mysqld_safe --skip-grant-tables --skip-networking & ) && sleep 5 && mysql -u root < /root/MySQL-Configure-Security.sql
|
|
16
|
+
|
|
17
|
+
# Import the initial database
|
|
18
|
+
COPY ./debug/model/sql_create/BookStore-CreateDatabase.mysql.sql /root/MySQL-Create-Databases.sql
|
|
19
|
+
COPY ./debug/model/sql_create/BookStore-CreateAndPopulateTables.sql /root/BookStore-CreateAndPopulateTables.sql
|
|
20
|
+
RUN service mariadb restart && sleep 5 && mysql -u root -p"123456789" -e "CREATE DATABASE bookstore;"
|
|
21
|
+
RUN echo "...creating and populating database..."
|
|
22
|
+
RUN service mariadb restart && sleep 5 && mysql -u root -p"123456789" bookstore < /root/MySQL-Create-Databases.sql
|
|
23
|
+
RUN service mariadb restart && sleep 5 && mysql -u root -p"123456789" bookstore < /root/BookStore-CreateAndPopulateTables.sql
|
|
24
|
+
RUN echo "...database creation and population complmete."
|
|
25
|
+
|
|
26
|
+
RUN echo "...mapping library specific volumes..."
|
|
27
|
+
|
|
28
|
+
VOLUME /retold-data-service
|
|
29
|
+
|
|
30
|
+
SHELL ["/bin/bash", "-c"]
|
|
31
|
+
|
|
32
|
+
RUN echo "...installing node version manager..."
|
|
33
|
+
|
|
34
|
+
# Because there is a .bashrc chicken/egg problem, we will create one here to simulate logging in. This is not great.
|
|
35
|
+
RUN touch /root/.bashrc && chmod +x /root/.bashrc
|
|
36
|
+
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
|
|
37
|
+
|
|
38
|
+
ENV NODE_VERSION=14
|
|
39
|
+
ENV NVM_DIR=/root/.nvm
|
|
40
|
+
RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION}
|
|
41
|
+
RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION}
|
|
42
|
+
RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION}
|
|
43
|
+
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
|
|
44
|
+
RUN . /root/.nvm/nvm.sh && source /root/.bashrc && node --version
|
|
45
|
+
RUN . /root/.nvm/nvm.sh && npm --version
|
|
46
|
+
|
|
47
|
+
WORKDIR /retold-data-service
|
|
48
|
+
|
|
49
|
+
COPY ./debug/model/manual_scripts/MySQL-Laden-Entry-ServicesOnly.sh /root/MySQL-Laden-Entry-ServicesOnly.sh
|
|
50
|
+
ENTRYPOINT ["/root/MySQL-Laden-Entry-ServicesOnly.sh"]
|
package/debug/Harness.js
CHANGED
|
@@ -1,14 +1,60 @@
|
|
|
1
|
-
const _Settings =
|
|
1
|
+
const _Settings = (
|
|
2
|
+
{
|
|
3
|
+
"Product": "MeadowEndpointsTestHarness",
|
|
4
|
+
|
|
5
|
+
"ProductVersion": "1.0.0",
|
|
6
|
+
"UUID":
|
|
7
|
+
{
|
|
8
|
+
"DataCenter": 0,
|
|
9
|
+
"Worker": 0
|
|
10
|
+
},
|
|
11
|
+
"LogStreams":
|
|
12
|
+
[
|
|
13
|
+
{
|
|
14
|
+
"streamtype": "console"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
|
|
18
|
+
"APIServerPort": 8087,
|
|
19
|
+
|
|
20
|
+
"RetoldDataServiceOptions":
|
|
21
|
+
{
|
|
22
|
+
"StorageProvider": "MySQL",
|
|
23
|
+
"StorageProviderModule": "meadow-connection-mysql",
|
|
24
|
+
|
|
25
|
+
"FullMeadowSchemaPath": `${__dirname}/../test/model/`,
|
|
26
|
+
"FullMeadowSchemaFilename": `MeadowModel-Extended.json`,
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
"MySQL":
|
|
30
|
+
{
|
|
31
|
+
"Server": "127.0.0.1",
|
|
32
|
+
"Port": 31306,
|
|
33
|
+
"User": "root",
|
|
34
|
+
"Password": "123456789",
|
|
35
|
+
"Database": "bookstore",
|
|
36
|
+
"ConnectionPoolLimit": 20
|
|
37
|
+
},
|
|
38
|
+
"MeadowConnectionMySQLAutoConnect": true
|
|
39
|
+
});
|
|
2
40
|
|
|
3
41
|
const libFable = require('fable');
|
|
4
42
|
|
|
5
43
|
_Fable = new libFable(_Settings);
|
|
6
44
|
|
|
7
|
-
_Fable.serviceManager.
|
|
45
|
+
_Fable.serviceManager.addServiceType('RetoldDataService', require('../source/Retold-Data-Service.js'));
|
|
46
|
+
_Fable.serviceManager.instantiateServiceProvider('RetoldDataService', _Settings.RetoldDataServiceOptions);
|
|
8
47
|
|
|
9
48
|
_Fable.RetoldDataService.initializeService(
|
|
10
49
|
(pError) =>
|
|
11
50
|
{
|
|
51
|
+
if (pError)
|
|
52
|
+
{
|
|
53
|
+
_Fable.log.error(`Error initializing the Retold Data Service: ${pError}`);
|
|
54
|
+
throw pError;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Inject a behavior to load all authors for a book on single record read
|
|
12
58
|
_Fable.MeadowEndpoints.Book.controller.BehaviorInjection.setBehavior('Read-PostOperation',
|
|
13
59
|
(pRequest, pRequestState, fComplete) =>
|
|
14
60
|
{
|
|
@@ -37,4 +83,37 @@ _Fable.RetoldDataService.initializeService(
|
|
|
37
83
|
}
|
|
38
84
|
});
|
|
39
85
|
});
|
|
86
|
+
|
|
87
|
+
const fGracefullyStopService = function ()
|
|
88
|
+
{
|
|
89
|
+
if (_Fable.RetoldDataService.serviceInitialized)
|
|
90
|
+
{
|
|
91
|
+
_Fable.RetoldDataService.stopService(
|
|
92
|
+
function (pStopError)
|
|
93
|
+
{
|
|
94
|
+
if (pStopError)
|
|
95
|
+
{
|
|
96
|
+
_Fable.log.error(`Error stopping Retold Data Service: ${pStopError}`);
|
|
97
|
+
}
|
|
98
|
+
else
|
|
99
|
+
{
|
|
100
|
+
_Fable.log.info('Retold Data Service stopped. Exiting.');
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
process.on('SIGINT',
|
|
107
|
+
function ()
|
|
108
|
+
{
|
|
109
|
+
_Fable.log.info('Received SIGINT. Shutting down gracefully...');
|
|
110
|
+
fGracefullyStopService();
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
process.on('SIGTERM',
|
|
114
|
+
function ()
|
|
115
|
+
{
|
|
116
|
+
_Fable.log.info('Received SIGTERM. Shutting down gracefully...');
|
|
117
|
+
fGracefullyStopService();
|
|
118
|
+
});
|
|
40
119
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "retold-data-service",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.8",
|
|
4
4
|
"description": "Serve up a whole model!",
|
|
5
5
|
"main": "source/Retold-Data-Service.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,9 +8,14 @@
|
|
|
8
8
|
"coverage": "./node_modules/.bin/nyc --reporter=lcov --reporter=text-lcov ./node_modules/mocha/bin/_mocha -- -u tdd -R spec",
|
|
9
9
|
"test": "./node_modules/.bin/mocha -u tdd -R spec",
|
|
10
10
|
"build": "npx quack build",
|
|
11
|
+
"build-test-model": "cd test && npx stricture -i model/ddl/BookStore.ddl",
|
|
11
12
|
"docker-dev-build": "docker build ./ -f Dockerfile_LUXURYCode -t retold-data-service-image:local",
|
|
12
13
|
"docker-dev-run": "docker run -it -d --name retold-data-service-dev -p 44444:8080 -p 43306:3306 -p 48086:8086 -v \"$PWD/.config:/home/coder/.config\" -v \"$PWD:/home/coder/retold-data-service\" -u \"$(id -u):$(id -g)\" -e \"DOCKER_USER=$USER\" retold-data-service-image:local",
|
|
13
|
-
"docker-dev-shell": "docker exec -it retold-data-service-dev /bin/bash"
|
|
14
|
+
"docker-dev-shell": "docker exec -it retold-data-service-dev /bin/bash",
|
|
15
|
+
"docker-service-build": "docker build ./ -f Dockerfile_Service -t retold-data-service-server-image:local",
|
|
16
|
+
"docker-service-run-test": "docker run -it --init -d --name retold-data-service -p 8086:8086 -p 43306:3306 -v \"$(pwd):/retold-data-service:z\" -u \"$(id -u):$(id -g)\" retold-data-service-server-image:local",
|
|
17
|
+
"docker-service-run": "docker run -it --init -d --name retold-data-service -p 8086:8086 -p 43306:3306 -v \"$(pwd):/retold-data-service:z\" retold-data-service-server-image:local",
|
|
18
|
+
"docker-service-shell": "docker exec -it retold-data-service /bin/bash"
|
|
14
19
|
},
|
|
15
20
|
"mocha": {
|
|
16
21
|
"diff": true,
|
|
@@ -46,15 +51,18 @@
|
|
|
46
51
|
},
|
|
47
52
|
"homepage": "https://github.com/stevenvelozo/retold-data-service",
|
|
48
53
|
"devDependencies": {
|
|
49
|
-
"quackage": "^1.0.
|
|
54
|
+
"quackage": "^1.0.41",
|
|
55
|
+
"stricture": "^1.0.37"
|
|
50
56
|
},
|
|
51
57
|
"dependencies": {
|
|
52
|
-
"fable": "^3.
|
|
53
|
-
"fable-serviceproviderbase": "^3.0.
|
|
58
|
+
"fable": "^3.1.11",
|
|
59
|
+
"fable-serviceproviderbase": "^3.0.15",
|
|
54
60
|
"meadow": "^2.0.15",
|
|
55
61
|
"meadow-connection-mysql": "^1.0.4",
|
|
56
62
|
"meadow-endpoints": "^4.0.5",
|
|
57
|
-
"orator": "^
|
|
58
|
-
"orator-
|
|
63
|
+
"orator": "^5.0.1",
|
|
64
|
+
"orator-http-proxy": "^1.0.1",
|
|
65
|
+
"orator-serviceserver-restify": "^2.0.4",
|
|
66
|
+
"orator-static-server": "^1.0.1"
|
|
59
67
|
}
|
|
60
68
|
}
|
|
@@ -15,12 +15,11 @@ const libMeadowEndpoints = require('meadow-endpoints');
|
|
|
15
15
|
|
|
16
16
|
const defaultDataServiceSettings = (
|
|
17
17
|
{
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
StorageProvider: 'MySQL',
|
|
19
|
+
StorageProviderModule: 'meadow-connection-mysql',
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
DALMeadowSchemaPostfix: ``,
|
|
21
|
+
FullMeadowSchemaPath: `${process.cwd()}/model/`,
|
|
22
|
+
FullMeadowSchemaFilename: `MeadowModel-Extended.json`,
|
|
24
23
|
|
|
25
24
|
AutoInitializeDataService: true,
|
|
26
25
|
AutoStartOrator: true
|
|
@@ -71,10 +70,12 @@ class RetoldDataService extends libFableServiceProviderBase
|
|
|
71
70
|
{
|
|
72
71
|
return fCallback();
|
|
73
72
|
}
|
|
73
|
+
|
|
74
74
|
onInitialize(fCallback)
|
|
75
75
|
{
|
|
76
76
|
return fCallback();
|
|
77
77
|
}
|
|
78
|
+
|
|
78
79
|
onAfterInitialize(fCallback)
|
|
79
80
|
{
|
|
80
81
|
return fCallback();
|
|
@@ -84,9 +85,10 @@ class RetoldDataService extends libFableServiceProviderBase
|
|
|
84
85
|
{
|
|
85
86
|
// TODO: Change this to an option (e.g. we might want to do ALASQL)
|
|
86
87
|
// Load the mysql connection for meadow if it doesn't exist yet
|
|
87
|
-
this.fable.serviceManager.addAndInstantiateServiceType(
|
|
88
|
+
this.fable.serviceManager.addAndInstantiateServiceType(`Meadow${this.options.StorageProvider}Provider`, require(this.options.StorageProviderModule));
|
|
88
89
|
return fCallback();
|
|
89
90
|
}
|
|
91
|
+
|
|
90
92
|
initializeDataEndpoints(fCallback)
|
|
91
93
|
{
|
|
92
94
|
this.fable.log.info("Retold Data Service initializing Endpoints...");
|
|
@@ -108,14 +110,15 @@ class RetoldDataService extends libFableServiceProviderBase
|
|
|
108
110
|
{
|
|
109
111
|
// 4. Create the DAL for each entry (e.g. it would be at _DAL.Movie for the Movie entity)
|
|
110
112
|
let tmpDALEntityName = this.entityList[i];
|
|
111
|
-
let
|
|
112
|
-
|
|
113
|
-
this.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
this.
|
|
113
|
+
let tmpDALPackageObject = this.fullModel.Tables[tmpDALEntityName];
|
|
114
|
+
// We no longer need to load it from a package file; it's all in the full model
|
|
115
|
+
this.fable.log.info(`Initializing the ${tmpDALEntityName} DAL...`);
|
|
116
|
+
this._DAL[tmpDALEntityName] = this._Meadow.loadFromPackageObject(tmpDALPackageObject.MeadowSchema);
|
|
117
|
+
// 5. Tell this DAL object to use the specified storage provider
|
|
118
|
+
this.fable.log.info(`...defaulting the ${tmpDALEntityName} DAL to use ${this.options.StorageProvider}`);
|
|
119
|
+
this._DAL[tmpDALEntityName].setProvider(this.options.StorageProvider);
|
|
117
120
|
// 6. Create a Meadow Endpoints class for this DAL
|
|
118
|
-
this.fable.log.info(`...initializing the ${tmpDALEntityName} Meadow Endpoints to use
|
|
121
|
+
this.fable.log.info(`...initializing the ${tmpDALEntityName} Meadow Endpoints to use ${this.options.StorageProvider}`);
|
|
119
122
|
this._MeadowEndpoints[tmpDALEntityName] = libMeadowEndpoints.new(this._DAL[tmpDALEntityName]);
|
|
120
123
|
// 8. Expose the meadow endpoints on Orator
|
|
121
124
|
this.fable.log.info(`...mapping the ${tmpDALEntityName} Meadow Endpoints to Orator`);
|
|
@@ -174,6 +177,34 @@ class RetoldDataService extends libFableServiceProviderBase
|
|
|
174
177
|
});
|
|
175
178
|
}
|
|
176
179
|
}
|
|
180
|
+
|
|
181
|
+
stopService(fCallback)
|
|
182
|
+
{
|
|
183
|
+
if (!this.serviceInitialized)
|
|
184
|
+
{
|
|
185
|
+
return fCallback(new Error("Retold Data Service Application is being stopped but is not initialized..."));
|
|
186
|
+
}
|
|
187
|
+
else
|
|
188
|
+
{
|
|
189
|
+
this.fable.log.info(`The Retold Data Service is stopping Orator`);
|
|
190
|
+
|
|
191
|
+
let tmpAnticipate = this.fable.newAnticipate();
|
|
192
|
+
|
|
193
|
+
tmpAnticipate.anticipate(this.fable.Orator.stopWebServer.bind(this.fable.Orator));
|
|
194
|
+
|
|
195
|
+
tmpAnticipate.wait(
|
|
196
|
+
(pError)=>
|
|
197
|
+
{
|
|
198
|
+
if (pError)
|
|
199
|
+
{
|
|
200
|
+
this.log.error(`Error stopping Retold Data Service: ${pError}`);
|
|
201
|
+
return fCallback(pError);
|
|
202
|
+
}
|
|
203
|
+
this.serviceInitialized = false;
|
|
204
|
+
return fCallback();
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
177
208
|
}
|
|
178
209
|
|
|
179
210
|
module.exports = RetoldDataService;
|
|
@@ -42,7 +42,12 @@ suite
|
|
|
42
42
|
AutoStartOrator: true
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
tmpRetoldDataService.initializeService(
|
|
45
|
+
tmpRetoldDataService.initializeService(
|
|
46
|
+
()=>
|
|
47
|
+
{
|
|
48
|
+
// The data service created an orator
|
|
49
|
+
_Fable.Orator.stopService(fDone);
|
|
50
|
+
});
|
|
46
51
|
}
|
|
47
52
|
);
|
|
48
53
|
}
|