retold-data-service 2.0.7 → 2.0.9

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 (54) hide show
  1. package/.vscode/settings.json +33 -14
  2. package/debug/Harness.js +81 -2
  3. package/package.json +4 -2
  4. package/source/Retold-Data-Service.js +58 -18
  5. package/test/model/{json/MeadowModel-Extended.json → MeadowModel-Extended.json} +969 -5
  6. package/{debug/model/generated_documentation → test/model/doc}/Dictionary.md +1 -1
  7. package/{debug/model/generated_documentation → test/model/doc}/Model-Author.md +5 -5
  8. package/{debug/model/generated_documentation → test/model/doc}/Model-Book.md +6 -6
  9. package/{debug/model/generated_documentation → test/model/doc}/Model-BookAuthorJoin.md +4 -4
  10. package/{debug/model/generated_documentation → test/model/doc}/Model-BookPrice.md +6 -6
  11. package/{debug/model/generated_documentation → test/model/doc}/Model-Review.md +7 -7
  12. package/{debug/model/generated_documentation → test/model/doc}/ModelChangeTracking.md +1 -1
  13. package/{debug/model/generated_diagram/Stricture_Output.dot → test/model/doc/diagrams/Relationships.dot} +1 -1
  14. package/test/model/doc/diagrams/RelationshipsFull.dot +13 -0
  15. package/test/model/doc/diagrams/RelationshipsFull.png +0 -0
  16. package/test/model/meadow/MeadowSchemaAuthor.json +431 -0
  17. package/test/model/meadow/MeadowSchemaBook.json +527 -0
  18. package/test/model/meadow/MeadowSchemaBookAuthorJoin.json +335 -0
  19. package/test/model/meadow/MeadowSchemaBookPrice.json +511 -0
  20. package/test/model/meadow/MeadowSchemaReview.json +463 -0
  21. package/{debug/model/sql_create/BookStore-CreateDatabase.mysql.sql → test/model/mysql_create/MeadowModel-CreateMySQLDatabase.mysql.sql} +6 -6
  22. package/debug/bookstore-configuration.json +0 -26
  23. package/debug/model/Model-Extended.json +0 -915
  24. package/debug/model/Model-PICT.json +0 -1
  25. package/debug/model/Model.json +0 -280
  26. package/debug/model/bookstore-api-endpoint-exercises.paw +0 -0
  27. package/debug/model/ddl/BookStore.ddl +0 -66
  28. package/debug/model/generated_diagram/README.md +0 -1
  29. package/debug/model/generated_documentation/README.md +0 -1
  30. package/debug/model/manual_scripts/DropTables.sql +0 -5
  31. package/debug/model/manual_scripts/MySQL-Laden-Entry-ServicesOnly.sh +0 -28
  32. package/debug/model/manual_scripts/MySQL-Laden-Entry.sh +0 -17
  33. package/debug/model/manual_scripts/MySQL-Security.sql +0 -5
  34. package/debug/model/manual_scripts/README.md +0 -2
  35. package/debug/model/manual_scripts/my.cnf +0 -4
  36. package/debug/model/meadow/Model-MeadowSchema-Author.json +0 -220
  37. package/debug/model/meadow/Model-MeadowSchema-Book.json +0 -268
  38. package/debug/model/meadow/Model-MeadowSchema-BookAuthorJoin.json +0 -172
  39. package/debug/model/meadow/Model-MeadowSchema-BookPrice.json +0 -260
  40. package/debug/model/meadow/Model-MeadowSchema-Review.json +0 -236
  41. package/debug/model/meadow/README.md +0 -1
  42. package/debug/model/sql_create/BookStore-CreateAndPopulateTables.sql +0 -194
  43. package/debug/model/sql_create/README.md +0 -1
  44. package/test/model/Model-Extended.json +0 -915
  45. package/test/model/Model.ddl +0 -66
  46. package/test/model/Model.json +0 -280
  47. package/test/model/meadow/Model-MeadowSchema-Author.json +0 -220
  48. package/test/model/meadow/Model-MeadowSchema-Book.json +0 -268
  49. package/test/model/meadow/Model-MeadowSchema-BookAuthorJoin.json +0 -172
  50. package/test/model/meadow/Model-MeadowSchema-BookPrice.json +0 -260
  51. package/test/model/meadow/Model-MeadowSchema-Review.json +0 -236
  52. /package/test/model/{json/MeadowModel-PICT.json → MeadowModel-PICT.json} +0 -0
  53. /package/test/model/{json/MeadowModel.json → MeadowModel.json} +0 -0
  54. /package/{debug/model/generated_diagram/Stricture_Output.png → test/model/doc/diagrams/Relationships.png} +0 -0
@@ -1,17 +1,36 @@
1
1
  {
2
2
  "sqltools.connections": [
3
- {
4
- "mysqlOptions": {
5
- "authProtocol": "default"
6
- },
7
- "previewLimit": 50,
8
- "server": "localhost",
9
- "port": 3306,
10
- "driver": "MariaDB",
11
- "name": "Local",
12
- "database": "bookstore",
13
- "username": "root",
14
- "password": "123456789"
15
- }
16
- ]
3
+ {
4
+ "mysqlOptions": {
5
+ "authProtocol": "default",
6
+ "enableSsl": "Disabled"
7
+ },
8
+ "ssh": "Disabled",
9
+ "previewLimit": 50,
10
+ "server": "localhost",
11
+ "port": 3306,
12
+ "driver": "MariaDB",
13
+ "name": "Local MariaDB Harness",
14
+ "database": "bookstore",
15
+ "username": "root",
16
+ "password": "123456789",
17
+ "group": "Retold Development"
18
+ },
19
+ {
20
+ "mysqlOptions": {
21
+ "authProtocol": "default",
22
+ "enableSsl": "Disabled"
23
+ },
24
+ "ssh": "Disabled",
25
+ "previewLimit": 50,
26
+ "server": "localhost",
27
+ "port": 31306,
28
+ "driver": "MariaDB",
29
+ "name": "Containerized MariaDB Harness",
30
+ "group": "Retold Development",
31
+ "database": "bookstore",
32
+ "username": "root",
33
+ "password": "123456789"
34
+ }
35
+ ]
17
36
  }
package/debug/Harness.js CHANGED
@@ -1,14 +1,60 @@
1
- const _Settings = require('./bookstore-configuration.json');
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.addAndInstantiateServiceType('RetoldDataService', require('../source/Retold-Data-Service.js'));
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.7",
3
+ "version": "2.0.9",
4
4
  "description": "Serve up a whole model!",
5
5
  "main": "source/Retold-Data-Service.js",
6
6
  "scripts": {
@@ -8,6 +8,7 @@
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
14
  "docker-dev-shell": "docker exec -it retold-data-service-dev /bin/bash",
@@ -50,7 +51,8 @@
50
51
  },
51
52
  "homepage": "https://github.com/stevenvelozo/retold-data-service",
52
53
  "devDependencies": {
53
- "quackage": "^1.0.41"
54
+ "quackage": "^1.0.41",
55
+ "stricture": "^1.0.37"
54
56
  },
55
57
  "dependencies": {
56
58
  "fable": "^3.1.11",
@@ -15,12 +15,11 @@ const libMeadowEndpoints = require('meadow-endpoints');
15
15
 
16
16
  const defaultDataServiceSettings = (
17
17
  {
18
- FullMeadowSchemaPath: `${process.cwd()}/model/`,
19
- FullMeadowSchemaFilename: `Model-Extended.json`,
18
+ StorageProvider: 'MySQL',
19
+ StorageProviderModule: 'meadow-connection-mysql',
20
20
 
21
- DALMeadowSchemaPath: `${process.cwd()}/model/meadow/`,
22
- DALMeadowSchemaPrefix: `Model-MeadowSchema-`,
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('MeadowMySQLProvider', require('meadow-connection-mysql'));
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,18 +110,28 @@ 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 tmpDALPackageFile = `${this.options.DALMeadowSchemaPath}${this.options.DALMeadowSchemaPrefix}${tmpDALEntityName}${this.options.DALMeadowSchemaPostfix}.json`
112
- this.fable.log.info(`Initializing the ${tmpDALEntityName} DAL from [${tmpDALPackageFile}]...`);
113
- this._DAL[tmpDALEntityName] = this._Meadow.loadFromPackage(tmpDALPackageFile);
114
- // 5. Tell this DAL object to use MySQL
115
- this.fable.log.info(`...defaulting the ${tmpDALEntityName} DAL to use MySQL`);
116
- this._DAL[tmpDALEntityName].setProvider('MySQL');
117
- // 6. Create a Meadow Endpoints class for this DAL
118
- this.fable.log.info(`...initializing the ${tmpDALEntityName} Meadow Endpoints to use MySQL`);
119
- this._MeadowEndpoints[tmpDALEntityName] = libMeadowEndpoints.new(this._DAL[tmpDALEntityName]);
120
- // 8. Expose the meadow endpoints on Orator
121
- this.fable.log.info(`...mapping the ${tmpDALEntityName} Meadow Endpoints to Orator`);
122
- this._MeadowEndpoints[tmpDALEntityName].connectRoutes(this.fable.OratorServiceServer);
113
+ try
114
+ {
115
+ let tmpDALSchema = this.fullModel.Tables[tmpDALEntityName];
116
+ let tmpDALMeadowSchema = tmpDALSchema.MeadowSchema;
117
+
118
+ //let tmpDALPackageFile = `${this.options.DALMeadowSchemaPath}${this.options.DALMeadowSchemaPrefix}${tmpDALEntityName}${this.options.DALMeadowSchemaPostfix}.json`
119
+ //this.fable.log.info(`Initializing the ${tmpDALEntityName} DAL from [${tmpDALPackageFile}]...`);
120
+ this._DAL[tmpDALEntityName] = this._Meadow.loadFromPackageObject(tmpDALMeadowSchema);
121
+ // 5. Tell this DAL object to use MySQL
122
+ this.fable.log.info(`...defaulting the ${tmpDALEntityName} DAL to use MySQL`);
123
+ this._DAL[tmpDALEntityName].setProvider('MySQL');
124
+ // 6. Create a Meadow Endpoints class for this DAL
125
+ this.fable.log.info(`...initializing the ${tmpDALEntityName} Meadow Endpoints to use MySQL`);
126
+ this._MeadowEndpoints[tmpDALEntityName] = libMeadowEndpoints.new(this._DAL[tmpDALEntityName]);
127
+ // 8. Expose the meadow endpoints on Orator
128
+ this.fable.log.info(`...mapping the ${tmpDALEntityName} Meadow Endpoints to Orator`);
129
+ this._MeadowEndpoints[tmpDALEntityName].connectRoutes(this.fable.OratorServiceServer);
130
+ }
131
+ catch (pError)
132
+ {
133
+ this.fable.log.error(`Error initializing DAL and Endpoints for entity [${tmpDALEntityName}]: ${pError}`);
134
+ }
123
135
  }
124
136
 
125
137
  return fCallback();
@@ -174,6 +186,34 @@ class RetoldDataService extends libFableServiceProviderBase
174
186
  });
175
187
  }
176
188
  }
189
+
190
+ stopService(fCallback)
191
+ {
192
+ if (!this.serviceInitialized)
193
+ {
194
+ return fCallback(new Error("Retold Data Service Application is being stopped but is not initialized..."));
195
+ }
196
+ else
197
+ {
198
+ this.fable.log.info(`The Retold Data Service is stopping Orator`);
199
+
200
+ let tmpAnticipate = this.fable.newAnticipate();
201
+
202
+ tmpAnticipate.anticipate(this.fable.Orator.stopWebServer.bind(this.fable.Orator));
203
+
204
+ tmpAnticipate.wait(
205
+ (pError)=>
206
+ {
207
+ if (pError)
208
+ {
209
+ this.log.error(`Error stopping Retold Data Service: ${pError}`);
210
+ return fCallback(pError);
211
+ }
212
+ this.serviceInitialized = false;
213
+ return fCallback();
214
+ });
215
+ }
216
+ }
177
217
  }
178
218
 
179
219
  module.exports = RetoldDataService;