fable 3.0.46 → 3.0.48

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 (43) hide show
  1. package/Dockerfile_LUXURYCode +4 -5
  2. package/dist/fable.compatible.js +9 -3
  3. package/dist/fable.compatible.min.js +2 -2
  4. package/dist/fable.compatible.min.js.map +1 -1
  5. package/dist/fable.js +9 -3
  6. package/dist/fable.min.js +2 -2
  7. package/dist/fable.min.js.map +1 -1
  8. package/package.json +4 -3
  9. package/retold-harness/bookstore-serve-api.js +41 -0
  10. package/retold-harness/configuration-bookstore-serve-api.js +30 -0
  11. package/retold-harness/model/manual_scripts/MySQL-Laden-Entry.sh +17 -0
  12. package/retold-harness/model/manual_scripts/my.cnf +4 -0
  13. package/retold-harness/model/sql_create/BookStore-DeleteAndRepopulateTables.sql +194 -0
  14. package/retold-harness/model/sql_create/MySQL-Security.sql +5 -0
  15. package/source/Fable-ServiceManager.js +19 -0
  16. package/source/services/Fable-Service-Operation-DefaultSettings.js +1 -1
  17. package/source/services/Fable-Service-Operation.js +4 -11
  18. package/test/FableServiceManager_tests.js +3 -0
  19. package/test/RestClient_test.js +1 -1
  20. package/retold-harness/Bookstore-Import-Books.sh +0 -4
  21. package/retold-harness/bookstore-configuration.json +0 -28
  22. package/retold-harness/bookstore-import-books-run.js +0 -9
  23. package/retold-harness/bookstore-import-books.js +0 -214
  24. package/retold-harness/bookstore-serve-meadow-endpoint-apis-IPC.js +0 -137
  25. package/retold-harness/bookstore-serve-meadow-endpoint-apis-run.js +0 -6
  26. package/retold-harness/bookstore-serve-meadow-endpoint-apis.js +0 -129
  27. package/retold-harness/data/books.csv +0 -10001
  28. package/retold-harness/model/json_schema/README.md +0 -1
  29. package/retold-harness/package.json +0 -22
  30. package/retold-harness/test_old/Tests.js +0 -3243
  31. package/retold-harness/test_old/untitled.js +0 -88
  32. /package/retold-harness/{MySQL-Laden-Entry.sh → docker_scripts/MySQL-Laden-Entry.sh} +0 -0
  33. /package/retold-harness/model/{json_schema/BookStore-Extended.json → Model-Extended.json} +0 -0
  34. /package/retold-harness/model/{json_schema/BookStore-PICT.json → Model-PICT.json} +0 -0
  35. /package/retold-harness/model/{json_schema/BookStore.json → Model.json} +0 -0
  36. /package/retold-harness/{bookstore-api-endpoint-exercises.paw → model/bookstore-api-endpoint-exercises.paw} +0 -0
  37. /package/retold-harness/{MySQL-Security.sql → model/manual_scripts/MySQL-Security.sql} +0 -0
  38. /package/retold-harness/model/{meadow_schema/BookStore-MeadowSchema-Author.json → meadow/Model-MeadowSchema-Author.json} +0 -0
  39. /package/retold-harness/model/{meadow_schema/BookStore-MeadowSchema-Book.json → meadow/Model-MeadowSchema-Book.json} +0 -0
  40. /package/retold-harness/model/{meadow_schema/BookStore-MeadowSchema-BookAuthorJoin.json → meadow/Model-MeadowSchema-BookAuthorJoin.json} +0 -0
  41. /package/retold-harness/model/{meadow_schema/BookStore-MeadowSchema-BookPrice.json → meadow/Model-MeadowSchema-BookPrice.json} +0 -0
  42. /package/retold-harness/model/{meadow_schema/BookStore-MeadowSchema-Review.json → meadow/Model-MeadowSchema-Review.json} +0 -0
  43. /package/retold-harness/model/{meadow_schema → meadow}/README.md +0 -0
@@ -0,0 +1,5 @@
1
+ FLUSH PRIVILEGES;
2
+
3
+ ALTER USER 'root'@'localhost' IDENTIFIED BY '123456789';
4
+
5
+ GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456789' WITH GRANT OPTION;
@@ -54,6 +54,25 @@ class FableService extends libFableServiceBase.CoreServiceProviderBase
54
54
  this.instantiateServiceProvider(pServiceType, {}, `${pServiceType}-Default`);
55
55
  }
56
56
 
57
+ // Some servicds expect to be overloaded / customized class.
58
+ instantiateServiceProviderFromPrototype(pServiceType, pOptions, pCustomServiceHash, pServicePrototype)
59
+ {
60
+ // Instantiate the service
61
+ let tmpService = new pServicePrototype(this.fable, pOptions, pCustomServiceHash);
62
+
63
+ // Add the service to the service map
64
+ this.services[pServiceType][tmpService.Hash] = tmpService;
65
+
66
+ // If this is the first service of this type, make it the default
67
+ if (!this.defaultServices.hasOwnProperty(pServiceType))
68
+ {
69
+ this.setDefaultServiceInstantiation(pServiceType, tmpService.Hash)
70
+ }
71
+
72
+ return tmpService;
73
+ }
74
+
75
+
57
76
  instantiateServiceProvider(pServiceType, pOptions, pCustomServiceHash)
58
77
  {
59
78
  // Instantiate the service
@@ -1,7 +1,7 @@
1
1
  module.exports = (
2
2
  {
3
3
  "Metadata": {
4
- "GUID": false,
4
+ "UUID": false,
5
5
  "Hash": false,
6
6
 
7
7
  "Title": "",
@@ -13,20 +13,13 @@ class FableOperation extends libFableServiceBase
13
13
 
14
14
  this.state = JSON.parse(_OperationStatePrototypeString);
15
15
 
16
- this.state.Metadata.GUID = this.fable.getUUID();
16
+ // Match the service instantiation to the operation.
17
17
  this.state.Metadata.Hash = this.Hash;
18
+ this.state.Metadata.UUID = this.UUID;
18
19
 
19
- this.name = (typeof(this.options.Name) == 'string') ? this.options.Name : `Unnamed Operation ${this.state.Metadata.GUID}`;
20
- }
20
+ this.name = (typeof(this.options.Name) == 'string') ? this.options.Name : `Unnamed Operation ${this.state.Metadata.UUID}`;
21
21
 
22
- get GUID()
23
- {
24
- return this.state.Metadata.GUID;
25
- }
26
-
27
- get log()
28
- {
29
- return this;
22
+ this.log = this;
30
23
  }
31
24
 
32
25
  writeOperationLog(pLogLevel, pLogText, pLogObject)
@@ -138,8 +138,11 @@ suite
138
138
  testFable.serviceManager.addServiceType('SimpleService', SimpleService);
139
139
 
140
140
  let tmpService = testFable.serviceManager.instantiateServiceProviderWithoutRegistration('SimpleService', {SomeOption: true}, 'SimpleService-99');
141
+ let tmpServiceFromPrototype = testFable.serviceManager.instantiateServiceProviderFromPrototype('SimpleService', {SomeOption: true}, 'SimpleService-100', SimpleService);
141
142
 
142
143
  Expect(testFable.services.SimpleService['SimpleService-99']).to.be.an('undefined');
144
+ Expect(testFable.services.SimpleService['SimpleService-100']).to.be.an('object');
145
+ Expect(tmpServiceFromPrototype).to.be.an('object');
143
146
 
144
147
  Expect(tmpService).to.be.an('object');
145
148
  }
@@ -43,7 +43,7 @@ suite
43
43
  {
44
44
  Expect(pBody).to.be.an('object');
45
45
  Expect(pBody.hasOwnProperty('Name')).to.equal(true);
46
- Expect(pBody.Name).to.equal('Suzanne Collins');
46
+ Expect(pBody.Name).to.equal('John Green');
47
47
  fTestComplete();
48
48
  });
49
49
  }
@@ -1,4 +0,0 @@
1
- #/bin/bash
2
-
3
- # Eventually this will delete the database too!
4
- node ./bookstore-import-books-run.js
@@ -1,28 +0,0 @@
1
- {
2
- "Product": "MeadowEndpointsTestBookStore",
3
- "ProductVersion": "1.0.0",
4
-
5
- "UUID":
6
- {
7
- "DataCenter": 0,
8
- "Worker": 0
9
- },
10
- "LogStreams":
11
- [
12
- {
13
- "streamtype": "console"
14
- }
15
- ],
16
-
17
- "APIServerPort": 8086,
18
-
19
- "MySQL":
20
- {
21
- "Server": "127.0.0.1",
22
- "Port": 3306,
23
- "User": "root",
24
- "Password": "123456789",
25
- "Database": "bookstore",
26
- "ConnectionPoolLimit": 20
27
- }
28
- }
@@ -1,9 +0,0 @@
1
- let tmpRun = require('./bookstore-import-books.js')(
2
- (pError)=>
3
- {
4
- if (pError)
5
- {
6
- console.log(`ERROR: ${pError}`, pError);
7
- }
8
- process.exit();
9
- });
@@ -1,214 +0,0 @@
1
- /*
2
- Import Books directly from CSV to SQL.
3
-
4
- An example of how to use the Meadow DALs directly.
5
- */
6
- /**
7
- * @author <steven@velozo.com>
8
- */
9
-
10
- // Server Settings
11
- const _Settings = require('./bookstore-configuration.json');
12
- // Fable is logging and settings
13
- const libFable = require('fable');
14
- // Official MySQL Client
15
- const libMySQL = require('mysql2');
16
- // Meadow is the DAL
17
- const libMeadow = require('meadow');
18
-
19
- const libAsync = require('async');
20
-
21
- let _Fable = libFable.new(_Settings);
22
- let _Meadow = libMeadow.new(_Fable);
23
-
24
- _Fable.log.info("Application is starting up...");
25
-
26
- _Fable.log.info("...Creating SQL Connection pools at "+_Fable.settings.MySQL.Server+"...");
27
- // Setup SQL Connection Pool
28
- _Fable.MeadowMySQLConnectionPool = libMySQL.createPool
29
- (
30
- {
31
- connectionLimit: _Fable.settings.MySQL.ConnectionPoolLimit,
32
- host: _Fable.settings.MySQL.Server,
33
- port: _Fable.settings.MySQL.Port,
34
- user: _Fable.settings.MySQL.User,
35
- password: _Fable.settings.MySQL.Password,
36
- database: _Fable.settings.MySQL.Database,
37
- namedPlaceholders: true
38
- }
39
- );
40
-
41
- // Create DAL objects
42
- let _DAL = {};
43
- const _BookStoreModel = require (__dirname+'/model/json_schema/BookStore-Extended.json');
44
- const _BookStoreTableList = Object.keys(_BookStoreModel.Tables);
45
- _Fable.log.info(`...Creating ${_BookStoreTableList.length} DAL entries...`);
46
- for (let i = 0; i < _BookStoreTableList.length; i++)
47
- {
48
- let tmpDALEntityName = _BookStoreTableList[i];
49
- _Fable.log.info(` -> Creating the ${tmpDALEntityName} DAL...`);
50
- _DAL[tmpDALEntityName] = _Meadow.loadFromPackage(__dirname+'/model/meadow_schema/BookStore-MeadowSchema-'+tmpDALEntityName+'.json');
51
- _DAL[tmpDALEntityName].setProvider('MySQL');
52
- _DAL[tmpDALEntityName].setIDUser(99999);
53
- }
54
-
55
- const libPapa = require('papaparse');
56
- const libFS = require('fs');
57
-
58
- const _BookData = libFS.readFileSync(`${__dirname}/data/books.csv`, 'utf8');
59
-
60
- let tmpBookMap = {};
61
- let tmpAuthorMap = {};
62
-
63
- let fImportBooks = (fCallback) =>
64
- {
65
- console.log('Import operation executing...');
66
- let tmpCallback = (typeof(fCallback) == 'function') ? fCallback : ()=>{};
67
-
68
- libPapa.parse(_BookData,
69
- {
70
- delimiter: ",",
71
- header: true,
72
- complete:
73
- (pResults) =>
74
- {
75
- libAsync.waterfall([
76
- (fStageComplete) =>
77
- {
78
- // Enumerate and insert each book
79
- libAsync.eachLimit(pResults.data, 10,
80
- (pBookDataRow, fCallback) =>
81
- {
82
- let tmpRecordToCreate = (
83
- {
84
- Title: pBookDataRow.original_title,
85
- PublicationYear: isNaN(parseInt(pBookDataRow.original_publication_year, 10)) ? 0 : parseInt(pBookDataRow.original_publication_year, 10),
86
- ISBN: pBookDataRow.isbn,
87
- Type: 'Paper',
88
- Genre: 'UNKNOWN',
89
- Language: pBookDataRow.language_code,
90
- ImageURL: pBookDataRow.image_url
91
- });
92
- let tmpQuery = _DAL.Book.query;
93
- //tmpQuery.setLogLevel(5);
94
- tmpQuery.addRecord(tmpRecordToCreate);
95
- _DAL.Book.doCreate(tmpQuery,
96
- (pError, pQuery, pQueryRead, pRecord)=>
97
- {
98
- // Add it to the book map
99
- if (!pError)
100
- {
101
- tmpBookMap[pBookDataRow.id] = pRecord.IDBook;
102
- //_Fable.log.info('Imported book ID '+pRecord.IDBook+' title ['+pRecord.Title+']');
103
- }
104
- fCallback(pError);
105
- });
106
-
107
- },
108
- (pError)=>
109
- {
110
- _Fable.log.info('...Book Import operation complete!');
111
- fStageComplete()
112
- });
113
- },
114
- (fStageComplete) =>
115
- {
116
- // Enumerate and insert each author
117
- libAsync.eachLimit(pResults.data, 10,
118
- (pBookDataRow, fCallback) =>
119
- {
120
- if (!pBookDataRow.hasOwnProperty('authors'))
121
- return fCallback();
122
-
123
- let tmpAuthorsToCreate = pBookDataRow.authors.split(',');
124
-
125
- libAsync.eachLimit(tmpAuthorsToCreate, 1,
126
- (pAuthor, fAuthorInsertCallback)=>
127
- {
128
- if (tmpAuthorMap.hasOwnProperty(pAuthor))
129
- {
130
- return fAuthorInsertCallback();
131
- }
132
- else
133
- {
134
- tmpAuthorMap[pAuthor] = false;
135
- }
136
- let tmpRecordToCreate = (
137
- {
138
- Name: pAuthor
139
- });
140
- let tmpQuery = _DAL.Author.query.addRecord(tmpRecordToCreate);
141
- _DAL.Author.doCreate(tmpQuery,
142
- (pError, pQuery, pQueryRead, pRecord)=>
143
- {
144
- if (!pError)
145
- {
146
- tmpAuthorMap[pRecord.Name] = pRecord.IDAuthor;
147
- //_Fable.log.info('Imported Author ID '+pRecord.IDAuthor+' named ['+pRecord.Name+']');
148
- }
149
- return fAuthorInsertCallback(pError);
150
- });
151
- },
152
- (pError)=>
153
- {
154
- return fCallback(pError);
155
- });
156
- },
157
- (pError)=>
158
- {
159
- _Fable.log.info('...Author Import operation complete!');
160
- fStageComplete();
161
- });
162
- },
163
- (fStageComplete) =>
164
- {
165
- // Create Book->Author joins
166
- libAsync.eachLimit(pResults.data, 10,
167
- (pBookDataRow, fCallback) =>
168
- {
169
- if (!pBookDataRow.hasOwnProperty('authors'))
170
- return fCallback();
171
-
172
- let tmpAuthorJoinsToCreate = pBookDataRow.authors.split(',');
173
-
174
- libAsync.eachLimit(tmpAuthorJoinsToCreate, 1,
175
- (pAuthor, fAuthorJoinInsertCallback)=>
176
- {
177
- let tmpRecordToCreate = (
178
- {
179
- IDBook: tmpBookMap[pBookDataRow.id],
180
- IDAuthor: tmpAuthorMap[pAuthor]
181
- });
182
- let tmpQuery = _DAL.BookAuthorJoin.query.addRecord(tmpRecordToCreate);
183
- _DAL.BookAuthorJoin.doCreate(tmpQuery,
184
- (pError, pQuery, pQueryRead, pRecord)=>
185
- {
186
- if (!pError)
187
- {
188
- //_Fable.log.info(`Joined author ${pAuthor} ID ${pRecord.IDAuthor} to book ID ${pRecord.IDBook}`);
189
- }
190
- return fAuthorJoinInsertCallback(pError);
191
- });
192
- },
193
- (pError)=>
194
- {
195
- return fCallback(pError);
196
- });
197
- },
198
- (pError)=>
199
- {
200
- _Fable.log.info('...Join Import operation complete!');
201
- return fStageComplete(pError);
202
- });
203
- }
204
- ],
205
- (pError)=>
206
- {
207
- _Fable.log.info('Full import operation has completed!')
208
- tmpCallback(pError);
209
- });
210
- }
211
- });
212
- }
213
-
214
- module.exports = fImportBooks;
@@ -1,137 +0,0 @@
1
- /*
2
- An example of Meadow Endpoints, Fable and Orator
3
- */
4
- const libWhyMe = require('why-is-node-running');
5
- /**
6
- * @author <steven@velozo.com>
7
- */
8
-
9
- // Server Settings
10
- const _Settings = require('./bookstore-configuration.json');
11
- // Fable is logging and settings
12
- const libFable = require('fable');
13
- // Orator is the web server
14
- const libOrator = require('orator');
15
- // Official MySQL Client
16
- const libMySQL = require('mysql2');
17
- // Meadow is the DAL
18
- const libMeadow = require('meadow');
19
- // Meadow-endpoints maps the DAL to restify endpoints automagically
20
- const libMeadowEndpoints = require('meadow-endpoints');
21
-
22
- let _Fable = new libFable(_Settings);
23
- let _Orator = new libOrator(_Fable);
24
-
25
- let fStartServiceServer = (fInitializeCallback) =>
26
- {
27
- _Orator.initializeServiceServer((pError) =>
28
- {
29
- let _Meadow = libMeadow.new(_Fable);
30
-
31
- _Fable.log.info("Application is starting up...");
32
-
33
- _Fable.log.info("...Creating SQL Connection pools at "+_Fable.settings.MySQL.Server+"...");
34
- _Fable.MeadowMySQLConnectionPool = libMySQL.createPool
35
- (
36
- {
37
- connectionLimit: _Fable.settings.MySQL.ConnectionPoolLimit,
38
- host: _Fable.settings.MySQL.Server,
39
- port: _Fable.settings.MySQL.Port,
40
- user: _Fable.settings.MySQL.User,
41
- password: _Fable.settings.MySQL.Password,
42
- database: _Fable.settings.MySQL.Database,
43
- namedPlaceholders: true
44
- }
45
- );
46
-
47
- // Create DAL objects for each table in the schema
48
- let _DAL = {};
49
- let _MeadowEndpoints = {};
50
-
51
- // 1. Load full compiled schema of the model from stricture
52
- _Fable.log.info(`...Loading stricture schemas...`);
53
- const _BookStoreModel = require (__dirname+'/model/json_schema/BookStore-Extended.json');
54
-
55
- // 2. Extract an array of each table in the schema
56
- const _BookStoreTableList = Object.keys(_BookStoreModel.Tables);
57
-
58
- // 3. Enumerate each entry in the compiled model and load a DAL for that table
59
- _Fable.log.info(`...Creating ${_BookStoreTableList.length} DAL entries...`);
60
- for (let i = 0; i < _BookStoreTableList.length; i++)
61
- {
62
- let tmpDALEntityName = _BookStoreTableList[i];
63
- _Fable.log.info(` -> Creating the ${tmpDALEntityName} DAL...`);
64
- // 4. Create the DAL for each entry (e.g. it would be at _DAL.Book or _DAL.Author)
65
- _DAL[tmpDALEntityName] = _Meadow.loadFromPackage(__dirname+'/model/meadow_schema/BookStore-MeadowSchema-'+tmpDALEntityName+'.json');
66
- // 5. Tell this DAL object to use MySQL
67
- _DAL[tmpDALEntityName].setProvider('MySQL');
68
- // 6. Set the User ID to 10 just for fun
69
- _DAL[tmpDALEntityName].setIDUser(1);
70
- // 7. Create a Meadow Endpoints class for this DAL
71
- _MeadowEndpoints[tmpDALEntityName] = libMeadowEndpoints.new(_DAL[tmpDALEntityName]);
72
- // 8. Expose the meadow endpoints on Orator
73
- _MeadowEndpoints[tmpDALEntityName].connectRoutes(_Orator.webServer);
74
- }
75
-
76
- // 100. Add a post processing hook to the Book DAL on single reads
77
- /*
78
- This post processing step will look for all book author joins then
79
- load all appropriate authors and stuff them in the book record before
80
- returning it.
81
- */
82
- _MeadowEndpoints.Book.controller.BehaviorInjection.setBehavior('Read-PostOperation',
83
- (pRequest, pRequestState, fComplete) =>
84
- {
85
- // Get the join records
86
- _DAL.BookAuthorJoin.doReads(_DAL.BookAuthorJoin.query.addFilter('IDBook', pRequestState.Record.IDBook),
87
- (pJoinReadError, pJoinReadQuery, pJoinRecords)=>
88
- {
89
- let tmpAuthorList = [];
90
- for (let j = 0; j < pJoinRecords.length; j++)
91
- {
92
- tmpAuthorList.push(pJoinRecords[j].IDAuthor);
93
- }
94
- if (tmpAuthorList.length < 1)
95
- {
96
- pRequestState.Record.Authors = [];
97
- return fComplete();
98
- }
99
- else
100
- {
101
- _DAL.Author.doReads(_DAL.Author.query.addFilter('IDAuthor', tmpAuthorList, 'IN'),
102
- (pReadsError, pReadsQuery, pAuthors)=>
103
- {
104
- pRequestState.Record.Authors = pAuthors;
105
- return fComplete();
106
- });
107
- }
108
- });
109
- });
110
-
111
- // Static site mapping
112
- _Orator.log.info("...Mapping static route for web site...");
113
-
114
- //_Orator.addStaticRoute(__dirname+'/../web/');
115
-
116
- // Start the web server (ctrl+c to end it)
117
- _Orator.startWebServer(
118
- (pError) =>
119
- {
120
- // Now do a GET!
121
- let tmpURI = `/1.0/Book/1`;
122
- _Orator.invoke('GET', tmpURI, null,
123
- (pError, pResponseData) =>
124
- {
125
- _Orator.log.info(`Response to [${tmpURI}] came back from IPC resulting in [${pResponseData}]!`);
126
- _Fable.MeadowMySQLConnectionPool.end();
127
- libWhyMe();
128
- return true;
129
- });
130
- fInitializeCallback(pError);
131
- }
132
- );
133
- });
134
- return _Orator;
135
- }
136
-
137
- module.exports = fStartServiceServer;
@@ -1,6 +0,0 @@
1
- const libServer = require('./bookstore-serve-meadow-endpoint-apis.js');
2
- let _Orator = libServer(
3
- ()=>
4
- {
5
- console.log('API service is started!');
6
- });
@@ -1,129 +0,0 @@
1
- /*
2
- An example of Meadow Endpoints, Fable and Orator
3
- */
4
-
5
- /**
6
- * @license MIT
7
- * @author <steven@velozo.com>
8
- */
9
-
10
- // Server Settings
11
- const _Settings = require('./bookstore-configuration.json');
12
- // Fable is logging and settings
13
- const libFable = require('fable');
14
- // Orator is the web server
15
- const libOrator = require('orator');
16
- const libOratorServiceServerRestify = require('orator-serviceserver-restify');
17
- // Official MySQL Client
18
- const libMySQL = require('mysql2');
19
- // Meadow is the DAL
20
- const libMeadow = require('meadow');
21
- // Meadow-endpoints maps the DAL to restify endpoints automagically
22
- const libMeadowEndpoints = require('meadow-endpoints');
23
-
24
- let _Fable = new libFable(_Settings);
25
- let _Orator = new libOrator(_Fable, libOratorServiceServerRestify);
26
-
27
- let fStartServiceServer = (fInitializeCallback) =>
28
- {
29
- _Orator.initializeServiceServer(() =>
30
- {
31
- let _Meadow = libMeadow.new(_Fable);
32
-
33
- _Fable.log.info("Application is starting up...");
34
-
35
- _Fable.log.info("...Creating SQL Connection pools at "+_Fable.settings.MySQL.Server+"...");
36
- _Fable.MeadowMySQLConnectionPool = libMySQL.createPool
37
- (
38
- {
39
- connectionLimit: _Fable.settings.MySQL.ConnectionPoolLimit,
40
- host: _Fable.settings.MySQL.Server,
41
- port: _Fable.settings.MySQL.Port,
42
- user: _Fable.settings.MySQL.User,
43
- password: _Fable.settings.MySQL.Password,
44
- database: _Fable.settings.MySQL.Database,
45
- namedPlaceholders: true
46
- }
47
- );
48
-
49
- // Create DAL objects for each table in the schema
50
- let _DAL = {};
51
- let _MeadowEndpoints = {};
52
-
53
- // 1. Load full compiled schema of the model from stricture
54
- _Fable.log.info(`...Loading stricture schemas...`);
55
- const _BookStoreModel = require (__dirname+'/model/json_schema/BookStore-Extended.json');
56
-
57
- // 2. Extract an array of each table in the schema
58
- const _BookStoreTableList = Object.keys(_BookStoreModel.Tables);
59
-
60
- // 3. Enumerate each entry in the compiled model and load a DAL for that table
61
- _Fable.log.info(`...Creating ${_BookStoreTableList.length} DAL entries...`);
62
- for (let i = 0; i < _BookStoreTableList.length; i++)
63
- {
64
- let tmpDALEntityName = _BookStoreTableList[i];
65
- _Fable.log.info(` -> Creating the ${tmpDALEntityName} DAL...`);
66
- // 4. Create the DAL for each entry (e.g. it would be at _DAL.Book or _DAL.Author)
67
- _DAL[tmpDALEntityName] = _Meadow.loadFromPackage(__dirname+'/model/meadow_schema/BookStore-MeadowSchema-'+tmpDALEntityName+'.json');
68
- // 5. Tell this DAL object to use MySQL
69
- _DAL[tmpDALEntityName].setProvider('MySQL');
70
- // 6. Set the User ID to 10 just for fun
71
- _DAL[tmpDALEntityName].setIDUser(1);
72
- // 7. Create a Meadow Endpoints class for this DAL
73
- _MeadowEndpoints[tmpDALEntityName] = libMeadowEndpoints.new(_DAL[tmpDALEntityName]);
74
- // 8. Expose the meadow endpoints on Orator
75
- _MeadowEndpoints[tmpDALEntityName].connectRoutes(_Orator.webServer);
76
- }
77
-
78
- // 100. Add a post processing hook to the Book DAL on single reads
79
- /*
80
- This post processing step will look for all book author joins then
81
- load all appropriate authors and stuff them in the book record before
82
- returning it.
83
- */
84
- _MeadowEndpoints.Book.controller.BehaviorInjection.setBehavior('Read-PostOperation',
85
- (pRequest, pRequestState, fComplete) =>
86
- {
87
- // Get the join records
88
- _DAL.BookAuthorJoin.doReads(_DAL.BookAuthorJoin.query.addFilter('IDBook', pRequestState.Record.IDBook),
89
- (pJoinReadError, pJoinReadQuery, pJoinRecords)=>
90
- {
91
- let tmpAuthorList = [];
92
- for (let j = 0; j < pJoinRecords.length; j++)
93
- {
94
- tmpAuthorList.push(pJoinRecords[j].IDAuthor);
95
- }
96
- if (tmpAuthorList.length < 1)
97
- {
98
- pRequestState.Record.Authors = [];
99
- return fComplete();
100
- }
101
- else
102
- {
103
- _DAL.Author.doReads(_DAL.Author.query.addFilter('IDAuthor', tmpAuthorList, 'IN'),
104
- (pReadsError, pReadsQuery, pAuthors)=>
105
- {
106
- pRequestState.Record.Authors = pAuthors;
107
- return fComplete();
108
- });
109
- }
110
- });
111
- });
112
-
113
- // Static site mapping
114
- _Orator.log.info("...Mapping static route for web site...");
115
-
116
- //_Orator.addStaticRoute(__dirname+'/../web/');
117
-
118
- // Start the web server (ctrl+c to end it)
119
- _Orator.startWebServer(
120
- (pError) =>
121
- {
122
- fInitializeCallback(pError);
123
- }
124
- );
125
- });
126
- return _Orator;
127
- }
128
-
129
- module.exports = fStartServiceServer;