retold-data-service 1.0.2 → 1.0.3
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/.config/configstore/update-notifier-npm-check-updates.json +1 -1
- package/.config/configstore/update-notifier-npm.json +1 -1
- package/.config/vscode-sqltools/runningInfo.json +13 -0
- package/.vscode/launch.json +24 -0
- package/.vscode/settings.json +17 -0
- package/Dockerfile_LUXURYCode +94 -0
- package/debug/Harness.js +34 -2
- package/debug/bookstore-configuration.json +29 -0
- package/debug/bookstore-serve-meadow-endpoint-apis.js +41 -0
- package/debug/data/books.csv +10001 -0
- package/debug/model/bookstore-api-endpoint-exercises.paw +0 -0
- package/debug/model/manual_scripts/MySQL-Laden-Entry.sh +17 -0
- package/debug/model/manual_scripts/MySQL-Security.sql +5 -0
- package/debug/model/manual_scripts/my.cnf +4 -0
- package/debug/model/sql_create/BookStore-CreateAndPopulateTables.sql +194 -0
- package/debug/package-lock.json +3999 -0
- package/debug/package.json +13 -0
- package/package.json +47 -17
- package/source/Retold-Data-Service.js +94 -299
- package/test/RetoldDataService_tests.js +16 -36
- package/test/model/fable-configuration.json +16 -0
- package/test/model/meadow/README.md +1 -0
- package/debug/Build-Database.sh +0 -12
- package/debug/Harness-Configuration.json +0 -51
- package/debug/model/doc/Dictionary.md +0 -18
- package/debug/model/doc/Model-Author.md +0 -20
- package/debug/model/doc/Model-Book.md +0 -26
- package/debug/model/doc/Model-BookAuthorJoin.md +0 -14
- package/debug/model/doc/Model-BookPrice.md +0 -25
- package/debug/model/doc/Model-Review.md +0 -22
- package/debug/model/doc/ModelChangeTracking.md +0 -17
- package/debug/model/doc/diagrams/Relationships.dot +0 -13
- package/debug/model/doc/diagrams/Relationships.png +0 -0
- package/debug/model/doc/diagrams/RelationshipsFull.dot +0 -13
- package/debug/model/doc/diagrams/RelationshipsFull.png +0 -0
- package/debug/model/mysql_create/MeadowModel-CreateMySQLDatabase.mysql.sql +0 -116
- package/source/Cumulation-Settings-Default.js +0 -19
- package/source/Cumulation.js +0 -90
- package/source/GraphGet.js +0 -607
- package/source/ProviderHelpers/Meadow-Provider-Helper-ALASQL.js +0 -48
- package/source/ProviderHelpers/Meadow-Provider-Helper-Base.js +0 -46
- package/source/ProviderHelpers/Meadow-Provider-Helper-MySQL.js +0 -62
- package/test/basic_test_configurations/fable-config-load_model.json +0 -45
- package/test/model/meadow_model/BookStore-PICT.json +0 -1
- package/test/model/meadow_model/README.md +0 -1
- /package/debug/model/{MeadowModel-Extended.json → Model-Extended.json} +0 -0
- /package/debug/model/{MeadowModel-PICT.json → Model-PICT.json} +0 -0
- /package/debug/model/{MeadowModel.json → Model.json} +0 -0
- /package/debug/{Model.ddl → model/ddl/BookStore.ddl} +0 -0
- /package/{test → debug}/model/generated_diagram/README.md +0 -0
- /package/{test → debug}/model/generated_diagram/Stricture_Output.dot +0 -0
- /package/{test → debug}/model/generated_diagram/Stricture_Output.png +0 -0
- /package/{test → debug}/model/generated_documentation/Dictionary.md +0 -0
- /package/{test → debug}/model/generated_documentation/Model-Author.md +0 -0
- /package/{test → debug}/model/generated_documentation/Model-Book.md +0 -0
- /package/{test → debug}/model/generated_documentation/Model-BookAuthorJoin.md +0 -0
- /package/{test → debug}/model/generated_documentation/Model-BookPrice.md +0 -0
- /package/{test → debug}/model/generated_documentation/Model-Review.md +0 -0
- /package/{test → debug}/model/generated_documentation/ModelChangeTracking.md +0 -0
- /package/{test → debug}/model/generated_documentation/README.md +0 -0
- /package/{test → debug}/model/manual_scripts/DropTables.sql +0 -0
- /package/{test → debug}/model/manual_scripts/README.md +0 -0
- /package/debug/model/meadow/{MeadowSchemaAuthor.json → Model-MeadowSchema-Author.json} +0 -0
- /package/debug/model/meadow/{MeadowSchemaBook.json → Model-MeadowSchema-Book.json} +0 -0
- /package/debug/model/meadow/{MeadowSchemaBookAuthorJoin.json → Model-MeadowSchema-BookAuthorJoin.json} +0 -0
- /package/debug/model/meadow/{MeadowSchemaBookPrice.json → Model-MeadowSchema-BookPrice.json} +0 -0
- /package/debug/model/meadow/{MeadowSchemaReview.json → Model-MeadowSchema-Review.json} +0 -0
- /package/{test/model/meadow_schema → debug/model/meadow}/README.md +0 -0
- /package/{test → debug}/model/sql_create/BookStore-CreateDatabase.mysql.sql +0 -0
- /package/{test → debug}/model/sql_create/README.md +0 -0
- /package/test/model/{meadow_model/BookStore-Extended.json → Model-Extended.json} +0 -0
- /package/test/model/{meadow_model/BookStore.json → Model.json} +0 -0
- /package/test/model/{meadow_schema/BookStore-MeadowSchema-Author.json → meadow/Model-MeadowSchema-Author.json} +0 -0
- /package/test/model/{meadow_schema/BookStore-MeadowSchema-Book.json → meadow/Model-MeadowSchema-Book.json} +0 -0
- /package/test/model/{meadow_schema/BookStore-MeadowSchema-BookAuthorJoin.json → meadow/Model-MeadowSchema-BookAuthorJoin.json} +0 -0
- /package/test/model/{meadow_schema/BookStore-MeadowSchema-BookPrice.json → meadow/Model-MeadowSchema-BookPrice.json} +0 -0
- /package/test/model/{meadow_schema/BookStore-MeadowSchema-Review.json → meadow/Model-MeadowSchema-Review.json} +0 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "retold-harness",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Harness data import and server.",
|
|
5
|
+
"main": "bookstore-serve-meadow-endpoints-apis.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start": "node bookstore-serve-meadow-endpoint-apis-run.js",
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
|
+
},
|
|
10
|
+
"author": "",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"dependencies": {}
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "retold-data-service",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Serve up a whole model!",
|
|
5
5
|
"main": "source/Retold-Data-Service.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"start": "node source/Retold-Data-Service.js",
|
|
8
|
-
"coverage": "./node_modules/
|
|
9
|
-
"test": "./node_modules/mocha
|
|
10
|
-
"
|
|
8
|
+
"coverage": "./node_modules/.bin/nyc --reporter=lcov --reporter=text-lcov ./node_modules/mocha/bin/_mocha -- -u tdd -R spec",
|
|
9
|
+
"test": "./node_modules/.bin/mocha -u tdd -R spec",
|
|
10
|
+
"build": "./node_modules/.bin/gulp build",
|
|
11
|
+
"build-compatible": "GULP_CUSTOM_BUILD_TARGET=compatible ./node_modules/.bin/gulp build",
|
|
12
|
+
"docker-dev-build": "docker build ./ -f Dockerfile_LUXURYCode -t retold/retold-data-service:local",
|
|
13
|
+
"docker-dev-run": "docker run -it -d --name retold-retold-data-service-dev -p 44444:8080 -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/retold-data-service:local",
|
|
14
|
+
"docker-dev-shell": "docker exec -it retold-retold-data-service-dev /bin/bash"
|
|
15
|
+
},
|
|
16
|
+
"mocha": {
|
|
17
|
+
"diff": true,
|
|
18
|
+
"extension": [
|
|
19
|
+
"js"
|
|
20
|
+
],
|
|
21
|
+
"package": "./package.json",
|
|
22
|
+
"reporter": "spec",
|
|
23
|
+
"slow": "75",
|
|
24
|
+
"timeout": "5000",
|
|
25
|
+
"ui": "tdd",
|
|
26
|
+
"watch-files": [
|
|
27
|
+
"source/**/*.js",
|
|
28
|
+
"test/**/*.js"
|
|
29
|
+
],
|
|
30
|
+
"watch-ignore": [
|
|
31
|
+
"lib/vendor"
|
|
32
|
+
]
|
|
11
33
|
},
|
|
12
34
|
"repository": {
|
|
13
35
|
"type": "git",
|
|
@@ -24,20 +46,28 @@
|
|
|
24
46
|
},
|
|
25
47
|
"homepage": "https://github.com/stevenvelozo/retold-data-service",
|
|
26
48
|
"devDependencies": {
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
49
|
+
"@babel/core": "^7.21.8",
|
|
50
|
+
"@babel/preset-env": "^7.21.5",
|
|
51
|
+
"browserify": "^17.0.0",
|
|
52
|
+
"chai": "4.3.7",
|
|
53
|
+
"gulp": "^4.0.2",
|
|
54
|
+
"gulp-babel": "^8.0.0",
|
|
55
|
+
"gulp-env": "^0.4.0",
|
|
56
|
+
"gulp-sourcemaps": "^3.0.0",
|
|
57
|
+
"gulp-terser": "^2.1.0",
|
|
58
|
+
"gulp-util": "^3.0.8",
|
|
59
|
+
"mocha": "10.2.0",
|
|
60
|
+
"nyc": "^15.1.0",
|
|
61
|
+
"vinyl-buffer": "^1.0.1",
|
|
62
|
+
"vinyl-source-stream": "^2.0.0"
|
|
31
63
|
},
|
|
32
64
|
"dependencies": {
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"meadow-
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"underscore": "^1.13.2",
|
|
41
|
-
"mysql2": "1.2.0"
|
|
65
|
+
"fable": "^3.0.46",
|
|
66
|
+
"fable-serviceproviderbase": "^3.0.4",
|
|
67
|
+
"meadow": "^2.0.5",
|
|
68
|
+
"meadow-connection-mysql": "^1.0.2",
|
|
69
|
+
"meadow-endpoints": "^4.0.2",
|
|
70
|
+
"orator": "^3.0.11",
|
|
71
|
+
"orator-serviceserver-restify": "^1.0.4"
|
|
42
72
|
}
|
|
43
73
|
}
|
|
@@ -1,336 +1,131 @@
|
|
|
1
|
-
// ##### Part of the **[retold](https://stevenvelozo.github.io/retold/)** system
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
* Retold Data Service
|
|
3
|
+
*
|
|
4
|
+
* All-in-one add-ins for fable to provide endpoints.
|
|
5
|
+
*
|
|
6
|
+
* @author Steven Velozo <steven@velozo.com>
|
|
7
|
+
*/
|
|
8
|
+
const libFableServiceProviderBase = require('fable-serviceproviderbase');
|
|
9
|
+
|
|
7
10
|
const libOrator = require('orator');
|
|
8
11
|
const libMeadow = require('meadow');
|
|
9
12
|
const libMeadowEndpoints = require('meadow-endpoints');
|
|
10
13
|
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* solver and other data niceties.
|
|
20
|
-
*
|
|
21
|
-
* Configuration stanza expectation:
|
|
22
|
-
RetoldDataService: {
|
|
23
|
-
SchemaFile: 'SchemaFileLocation',
|
|
24
|
-
-- OR --
|
|
25
|
-
Schema: [{ ... schemas in here ... }, { ... more schemas ... }],
|
|
26
|
-
|
|
27
|
-
AutoLoad: true,
|
|
28
|
-
|
|
29
|
-
MapExtraEndpoints: true,
|
|
30
|
-
|
|
31
|
-
SchemaGraphEndpoint: 'SchemaGraph'
|
|
32
|
-
}
|
|
14
|
+
const defaultDataServiceSettings = (
|
|
15
|
+
{
|
|
16
|
+
FullMeadowSchemaPath: `${process.cwd()}/model/`,
|
|
17
|
+
FullMeadowSchemaFilename: `Model-Extended.json`,
|
|
18
|
+
|
|
19
|
+
DALMeadowSchemaPath: `${process.cwd()}/model/meadow/`,
|
|
20
|
+
DALMeadowSchemaPrefix: `Model-MeadowSchema-`,
|
|
21
|
+
DALMeadowSchemaPostfix: ``,
|
|
33
22
|
|
|
23
|
+
AutoInitializeDataService: true,
|
|
24
|
+
AutoStartOrator: true
|
|
25
|
+
});
|
|
34
26
|
|
|
35
|
-
|
|
36
|
-
* serves the entire schema graph.
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* @class RetoldDataService
|
|
40
|
-
*/
|
|
41
|
-
class RetoldDataService
|
|
27
|
+
class RetoldDataService extends libFableServiceProviderBase
|
|
42
28
|
{
|
|
43
|
-
constructor(
|
|
29
|
+
constructor(pFable, pManifest, pServiceHash)
|
|
44
30
|
{
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
this._Orator = libOrator.new(tmpConfiguration);
|
|
48
|
-
|
|
49
|
-
this._Fable = this._Orator.fable;
|
|
50
|
-
this._Settings = this._Fable.settings;
|
|
31
|
+
super(pFable, pManifest, pServiceHash);
|
|
51
32
|
|
|
52
|
-
|
|
53
|
-
this._MeadowModelGraph = {};
|
|
33
|
+
this.serviceType = 'RetoldDataService';
|
|
54
34
|
|
|
55
|
-
this.
|
|
56
|
-
this._MeadowEndpoints = {};
|
|
35
|
+
this.options = this.fable.Utility.extend(defaultDataServiceSettings, this.options);
|
|
57
36
|
|
|
58
|
-
|
|
37
|
+
// TODO: Check if Fable already has an Orator service provider, otherwise add one.
|
|
38
|
+
// TODO: First switch the new Orator to the new service provider pattern
|
|
39
|
+
// TODO: Make the restify/http stuff optional, so IPC works.
|
|
40
|
+
// Orator is the (usually web) server
|
|
41
|
+
this.fable.Orator = new libOrator(this.fable, require('orator-serviceserver-restify'));
|
|
59
42
|
|
|
60
|
-
this
|
|
61
|
-
|
|
62
|
-
this.log = this._Fable.log;
|
|
63
|
-
|
|
64
|
-
// Load the configurations
|
|
65
|
-
if (this._Settings.hasOwnProperty('Retold'))
|
|
43
|
+
// Because this requires the callback, we will have to add better plumbing for these services to initialie
|
|
44
|
+
this.fable.Orator.initializeServiceServer(() =>
|
|
66
45
|
{
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// One or many full Model file path(s) has been set
|
|
70
|
-
this._Settings.Retold.MeadowModel = `${process.cwd()}/model/MeadowModel.json`;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (this._Settings.Retold.hasOwnProperty('MeadowEntitySchemaPrefix'))
|
|
74
|
-
{
|
|
75
|
-
// One or many Entity Schema file path(s) is set
|
|
76
|
-
this._Settings.Retold.MeadowEntitySchemaPrefix = `${process.cwd()}/model/meadow/MeadowSchema`;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
else
|
|
80
|
-
{
|
|
81
|
-
// Create a retold entry with defaults
|
|
82
|
-
this._Settings.Retold = (
|
|
83
|
-
{
|
|
84
|
-
// This setting will automatically load the model
|
|
85
|
-
"AutoLoadModel": true,
|
|
86
|
-
// This setting will automatically connect the provider via the helper
|
|
87
|
-
// (e.g. connect to MySQL)
|
|
88
|
-
"AutoConnectProvider": true,
|
|
89
|
-
// This setting will automatically connect the backplane endpoints
|
|
90
|
-
"AutoMapBackplaneEndpoints": true,
|
|
91
|
-
// This setting will automatically map the entity endpoints when entities are loaded
|
|
92
|
-
"AutoMapEntityEndpoints": true,
|
|
93
|
-
// This setting autostarts the orator server
|
|
94
|
-
"AutoStartAPIServer": true,
|
|
46
|
+
// TODO: This code will be much cleaner with these as services
|
|
47
|
+
this._Meadow = libMeadow.new(_Fable);
|
|
95
48
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
49
|
+
// Create DAL objects for each table in the schema
|
|
50
|
+
// These will be unnecessary when meadow and meadow-endpoints are full fledged fable services
|
|
51
|
+
this._DAL = {};
|
|
52
|
+
this.fable.DAL = this._DAL;
|
|
53
|
+
this._MeadowEndpoints = {};
|
|
54
|
+
this.fable.MeadowEndpoints = this._MeadowEndpoints;
|
|
100
55
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
56
|
+
// TODO: Change this to an option (e.g. we might want to do ALASQL)
|
|
57
|
+
// Load the mysql connection for meadow if it doesn't exist yet
|
|
58
|
+
_Fable.serviceManager.addAndInstantiateServiceType('MeadowMySQLProvider', require('meadow-connection-mysql'));
|
|
104
59
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
"MeadowModel": `${process.cwd()}/model/MeadowModel.json`,
|
|
108
|
-
"MeadowEntitySchemaPrefix": `${process.cwd()}/model/meadow/MeadowSchema`,
|
|
60
|
+
this.fullModel = false;
|
|
61
|
+
this.entityList = false;
|
|
109
62
|
|
|
110
|
-
|
|
111
|
-
});
|
|
112
|
-
}
|
|
63
|
+
this.serviceInitialized = false;
|
|
113
64
|
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
initialize(fCallback)
|
|
118
|
-
{
|
|
119
|
-
let tmpCallback = (typeof(fCallback) == 'function') ? fCallback : ()=>{};
|
|
120
|
-
libAsync.waterfall(
|
|
121
|
-
[
|
|
122
|
-
(fStageComplete) =>
|
|
123
|
-
{
|
|
124
|
-
if (this._Settings.Retold.AutoLoadModel)
|
|
125
|
-
{
|
|
126
|
-
this.loadModels();
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return fStageComplete();
|
|
130
|
-
},
|
|
131
|
-
(fStageComplete) =>
|
|
132
|
-
{
|
|
133
|
-
if (this._Settings.Retold.AutoConnectProvider)
|
|
134
|
-
{
|
|
135
|
-
this.initializeDefaultProvider();
|
|
136
|
-
}
|
|
137
|
-
return fStageComplete();
|
|
138
|
-
},
|
|
139
|
-
(fStageComplete) =>
|
|
140
|
-
{
|
|
141
|
-
if (this._Settings.Retold.AutoMapBackplaneEndpoints)
|
|
142
|
-
{
|
|
143
|
-
this.mapBackplaneEndpoints();
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return fStageComplete();
|
|
147
|
-
},
|
|
148
|
-
(fStageComplete) =>
|
|
149
|
-
{
|
|
150
|
-
// Initialize the graph solver library
|
|
151
|
-
this.initializeGraphEndpoints();
|
|
152
|
-
// Map the graph endpoints to it
|
|
153
|
-
// TODO: Decide if this follows the Meadow pattern or some other prefix pattern
|
|
154
|
-
this._Orator.webServer.post(`/1.0/GraphRead/:Entity`,
|
|
155
|
-
(pRequest, pResponse, fNext) =>
|
|
156
|
-
{
|
|
157
|
-
let tmpGraphRequestEntity = pRequest.params.Entity;
|
|
158
|
-
let tmpGraphRequestFilter = pRequest.body;
|
|
159
|
-
|
|
160
|
-
// TODO: Discuss how to pass in request settings -- what was in there worked for the web client and works for tokens so maybe it's okay?
|
|
161
|
-
let tmpCumulation = new libCumulation(this._Fable, {});
|
|
162
|
-
|
|
163
|
-
this._GraphSolver.get(tmpGraphRequestEntity, tmpGraphRequestFilter, tmpCumulation,
|
|
164
|
-
(pError, pRecords, pValidFilters, pFinalFilters, pJoinedDataSets, pValidIdentities) =>
|
|
165
|
-
{
|
|
166
|
-
pResponse.send(
|
|
167
|
-
{
|
|
168
|
-
GraphRequestEntity: tmpGraphRequestEntity,
|
|
169
|
-
GraphRequestFilter: tmpGraphRequestFilter,
|
|
170
|
-
|
|
171
|
-
Records: pRecords,
|
|
172
|
-
|
|
173
|
-
ValidFilters: pValidFilters,
|
|
174
|
-
Finalfilters: pFinalFilters,
|
|
175
|
-
|
|
176
|
-
JoinedDataSets: pJoinedDataSets,
|
|
177
|
-
ValidIdentities: pValidIdentities,
|
|
178
|
-
|
|
179
|
-
Error: pError
|
|
180
|
-
});
|
|
181
|
-
return fNext();
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
return fStageComplete();
|
|
186
|
-
},
|
|
187
|
-
(fStageComplete) =>
|
|
188
|
-
{
|
|
189
|
-
if (this._Settings.Retold.AutoStartAPIServer)
|
|
190
|
-
{
|
|
191
|
-
this.start(fStageComplete);
|
|
192
|
-
}
|
|
193
|
-
else
|
|
194
|
-
{
|
|
195
|
-
return fStageComplete();
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
],
|
|
199
|
-
(pError)=>
|
|
65
|
+
if (this.options.AutoInitializeDataService)
|
|
200
66
|
{
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
tmpCallback(pError);
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
initializeDefaultProvider()
|
|
211
|
-
{
|
|
212
|
-
let libProvider = require(`./ProviderHelpers/Meadow-Provider-Helper-${this._Settings.Retold.DefaultMeadowDataProvider}.js`);
|
|
213
|
-
|
|
214
|
-
// This is to support multiple providers
|
|
215
|
-
this._Providers.Default = new libProvider(this._Fable);
|
|
216
|
-
|
|
217
|
-
return this._Providers.Default.connect();
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
initializeGraphEndpoints()
|
|
221
|
-
{
|
|
222
|
-
this._GraphSolver = new libGraphSolver(this._Fable, this._MeadowModelGraph);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
mapBackplaneEndpoints()
|
|
226
|
-
{
|
|
227
|
-
const tmpBackplanePrefix = 'BACKPLANE';
|
|
228
|
-
// Pull version from the config file.
|
|
229
|
-
const tmpEndpointVersion = this._Fable.settings.MeadowEndpointVersion || '1.0';
|
|
230
|
-
|
|
231
|
-
const tmpBackplaneEndpointPrefix = `/${tmpBackplanePrefix}/${tmpEndpointVersion}`;
|
|
67
|
+
this.fable.log.info(`The Retold Data Service is Auto Initializing itself`);
|
|
68
|
+
this.initializeService();
|
|
69
|
+
}
|
|
232
70
|
|
|
233
|
-
|
|
234
|
-
this._Orator.webServer.get(`${tmpBackplaneEndpointPrefix}/Model`,
|
|
235
|
-
(pRequest, pResponse, fNext) =>
|
|
71
|
+
if (this.options.AutoStartOrator)
|
|
236
72
|
{
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
73
|
+
this.fable.log.info(`The Retold Data Service is Auto Starting Orator`);
|
|
74
|
+
this.fable.Orator.startWebServer(
|
|
75
|
+
(pError) =>
|
|
76
|
+
{
|
|
77
|
+
if (pError)
|
|
78
|
+
{
|
|
79
|
+
console.log(`Error auto-starting Orator: ${pError}`, pError);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
});
|
|
240
84
|
}
|
|
241
85
|
|
|
242
|
-
|
|
243
|
-
lockServiceSession(pSessionData)
|
|
86
|
+
initializeService()
|
|
244
87
|
{
|
|
245
|
-
if (
|
|
88
|
+
if (this.serviceInitialized)
|
|
246
89
|
{
|
|
247
|
-
this.log.error(
|
|
248
|
-
return false;
|
|
90
|
+
this.fable.log.error("Retold Data Service Application is being initialized but has already been initialized...");
|
|
249
91
|
}
|
|
250
|
-
|
|
251
|
-
_Fable.log.info(`...Creating Mock User Session and adding it to all requests on Restify/Orator`, pSessionData);
|
|
252
|
-
var fMockAuthentication = (pRequest, pResponse, fNext) =>
|
|
92
|
+
else
|
|
253
93
|
{
|
|
254
|
-
|
|
255
|
-
fNext();
|
|
256
|
-
};
|
|
257
|
-
this._Orator.webServer.use(fMockAuthentication);
|
|
258
|
-
}
|
|
94
|
+
this.fable.log.info("Retold Data Service Application is starting up...");
|
|
259
95
|
|
|
260
|
-
|
|
261
|
-
loadModels()
|
|
262
|
-
{
|
|
263
|
-
if (this._Settings.Retold.MeadowModel)
|
|
264
|
-
{
|
|
265
|
-
this.loadMeadowModelFile(this._Settings.Retold.MeadowModel);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
96
|
+
// Create DAL objects for each table in the schema
|
|
268
97
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
this.loadMeadowModel(this._MeadowModelGraph);
|
|
274
|
-
}
|
|
98
|
+
// 1. Load full compiled schema of the model from stricture
|
|
99
|
+
_Fable.log.info(`...loading full model stricture schema...`);
|
|
100
|
+
this.fullModel = require (`${this.options.FullMeadowSchemaPath}${this.options.FullMeadowSchemaFilename}`);
|
|
101
|
+
_Fable.log.info(`...full model stricture schema loaded.`);
|
|
275
102
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
return false;
|
|
284
|
-
}
|
|
285
|
-
if (!pModelObject.hasOwnProperty('Tables')
|
|
286
|
-
|| typeof(pModelObject.Tables) != 'object')
|
|
287
|
-
{
|
|
288
|
-
this.log.error(`Could not load Meadow model object: Object does not contain a Tables property.`, pModelObject);
|
|
289
|
-
return false;
|
|
290
|
-
}
|
|
291
|
-
// 2. Extract an array of each table in the schema
|
|
292
|
-
let tmpModelTableList = Object.keys(pModelObject.Tables);
|
|
293
|
-
let tmpDefaultProvider = (this._Fable.settings.Retold.DefaultMeadowDataProvider) ? this._Fable.settings.Retold.DefaultMeadowDataProvider : 'Base';
|
|
294
|
-
// 3. Enumerate each entry in the compiled model and load a DAL for that table
|
|
295
|
-
this.log.info(`...Creating ${tmpModelTableList.length} DAL entries...`);
|
|
296
|
-
for (let i = 0; i < tmpModelTableList.length; i++)
|
|
297
|
-
{
|
|
298
|
-
let tmpDALEntityName = tmpModelTableList[i];
|
|
299
|
-
this.log.info(` -> Creating the [${tmpDALEntityName}] DAL...`);
|
|
300
|
-
// 4. Create the DAL for each entry (e.g. it would be at _DAL.Book or _DAL.Author)
|
|
301
|
-
// TODO: I don't like this ... stricture should just generate a huge file of these in an array, which could be loaded with the new injector
|
|
302
|
-
this._DAL[tmpDALEntityName] = this._Meadow.loadFromPackage(`${this._Settings.Retold.MeadowEntitySchemaPrefix}${tmpDALEntityName}.json`);
|
|
303
|
-
// 5. Tell this DAL object to use the default provider
|
|
304
|
-
this._DAL[tmpDALEntityName].setProvider(tmpDefaultProvider);
|
|
305
|
-
// 6. Create a Meadow Endpoints class for this DAL
|
|
306
|
-
this._MeadowEndpoints[tmpDALEntityName] = libMeadowEndpoints.new(this._DAL[tmpDALEntityName]);
|
|
307
|
-
// 7. Expose the meadow endpoints on Orator
|
|
308
|
-
if (this._Fable.settings.Retold.AutoMapEntityEndpoints)
|
|
103
|
+
// 2. Extract an array of each table in the schema
|
|
104
|
+
_Fable.log.info(`...getting entity list...`);
|
|
105
|
+
this.entityList = Object.keys(this.fullModel.Tables);
|
|
106
|
+
|
|
107
|
+
// 3. Enumerate each entry in the compiled model and load a DAL for that table
|
|
108
|
+
_Fable.log.info(`...initializing ${this.entityList.length} DAL objects and corresponding Meadow Endpoints...`);
|
|
109
|
+
for (let i = 0; i < this.entityList.length; i++)
|
|
309
110
|
{
|
|
310
|
-
|
|
311
|
-
this.
|
|
111
|
+
// 4. Create the DAL for each entry (e.g. it would be at _DAL.Movie for the Movie entity)
|
|
112
|
+
let tmpDALEntityName = this.entityList[i];
|
|
113
|
+
let tmpDALPackageFile = `${this.options.DALMeadowSchemaPath}${this.options.DALMeadowSchemaPrefix}${tmpDALEntityName}${this.options.DALMeadowSchemaPostfix}.json`
|
|
114
|
+
_Fable.log.info(`Initializing the ${tmpDALEntityName} DAL from [${tmpDALPackageFile}]...`);
|
|
115
|
+
this._DAL[tmpDALEntityName] = this._Meadow.loadFromPackage(tmpDALPackageFile);
|
|
116
|
+
// 5. Tell this DAL object to use MySQL
|
|
117
|
+
_Fable.log.info(`...defaulting the ${tmpDALEntityName} DAL to use MySQL`);
|
|
118
|
+
this._DAL[tmpDALEntityName].setProvider('MySQL');
|
|
119
|
+
// 6. Create a Meadow Endpoints class for this DAL
|
|
120
|
+
_Fable.log.info(`...initializing the ${tmpDALEntityName} Meadow Endpoints to use MySQL`);
|
|
121
|
+
this._MeadowEndpoints[tmpDALEntityName] = libMeadowEndpoints.new(this._DAL[tmpDALEntityName]);
|
|
122
|
+
// 8. Expose the meadow endpoints on Orator
|
|
123
|
+
_Fable.log.info(`...mapping the ${tmpDALEntityName} Meadow Endpoints to Orator`);
|
|
124
|
+
this._MeadowEndpoints[tmpDALEntityName].connectRoutes(this.fable.Orator.webServer);
|
|
312
125
|
}
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
126
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
this._Orator.startWebServer(fCallback);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
get orator()
|
|
322
|
-
{
|
|
323
|
-
return this._Orator;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
get fable()
|
|
327
|
-
{
|
|
328
|
-
return this._Fable;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
get settings()
|
|
332
|
-
{
|
|
333
|
-
return this._Fable.settings;
|
|
127
|
+
this.serviceInitialized = true;
|
|
128
|
+
}
|
|
334
129
|
}
|
|
335
130
|
}
|
|
336
131
|
|
|
@@ -10,7 +10,9 @@ var Chai = require("chai");
|
|
|
10
10
|
var Expect = Chai.expect;
|
|
11
11
|
var Assert = Chai.assert;
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
const libFable = require('fable');
|
|
14
|
+
|
|
15
|
+
const _Settings = require(`./model/fable-configuration.json`);
|
|
14
16
|
|
|
15
17
|
suite
|
|
16
18
|
(
|
|
@@ -24,47 +26,25 @@ suite
|
|
|
24
26
|
'Object Sanity',
|
|
25
27
|
function()
|
|
26
28
|
{
|
|
27
|
-
test
|
|
28
|
-
(
|
|
29
|
-
'The class should initialize itself into a happy little object.',
|
|
30
|
-
function()
|
|
31
|
-
{
|
|
32
|
-
testService = new libRetoldDataService({"Product":"SimpleInitializationTest"});
|
|
33
|
-
|
|
34
|
-
// Instantiate the logger
|
|
35
|
-
Expect(testService).to.be.an('object', 'The data service should initialize as an object directly from the require statement and minimal configuration.');
|
|
36
|
-
Expect(testService).to.have.a.property('log')
|
|
37
|
-
.that.is.a('object');
|
|
38
|
-
Expect(testService).to.have.a.property('settings')
|
|
39
|
-
.that.is.a('object');
|
|
40
|
-
Expect(testService).to.have.a.property('fable')
|
|
41
|
-
.that.is.a('object');
|
|
42
|
-
Expect(testService).to.have.a.property('orator')
|
|
43
|
-
.that.is.a('object');
|
|
44
|
-
Expect(testService.settings.Product)
|
|
45
|
-
.to.equal('SimpleInitializationTest')
|
|
46
|
-
}
|
|
47
|
-
);
|
|
48
29
|
test
|
|
49
30
|
(
|
|
50
31
|
'Change some settings later...',
|
|
51
32
|
function(fDone)
|
|
52
33
|
{
|
|
53
|
-
|
|
34
|
+
_Fable = new libFable(_Settings);
|
|
35
|
+
_Fable.serviceManager.addServiceType('RetoldDataService', require('../source/Retold-Data-Service.js'));
|
|
36
|
+
let tmpRetoldDataService = _Fable.serviceManager.instantiateServiceProvider('RetoldDataService',
|
|
37
|
+
{
|
|
38
|
+
FullMeadowSchemaPath: `${process.cwd()}/test/model/`,
|
|
39
|
+
DALMeadowSchemaPath: `${process.cwd()}/test/model/meadow/`,
|
|
40
|
+
|
|
41
|
+
AutoInitializeDataService: true,
|
|
42
|
+
AutoStartOrator: true
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
tmpRetoldDataService.initializeService();
|
|
54
46
|
|
|
55
|
-
|
|
56
|
-
.that.is.a('object');
|
|
57
|
-
Expect(testService.settings.Product)
|
|
58
|
-
.to.equal('SimpleSettingsTest');
|
|
59
|
-
Expect(testService.settings.ProductVersion)
|
|
60
|
-
.to.equal('0.0.0');
|
|
61
|
-
// Now change a setting by merging in something new
|
|
62
|
-
testService.fable.settingsManager.merge({Product:'TestProduct'});
|
|
63
|
-
Expect(testService.settings.Product)
|
|
64
|
-
.to.equal('TestProduct');
|
|
65
|
-
Expect(testService.settings.ProductVersion)
|
|
66
|
-
.to.equal('0.0.0');
|
|
67
|
-
fDone();
|
|
47
|
+
return fDone();
|
|
68
48
|
}
|
|
69
49
|
);
|
|
70
50
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Product": "MeadowEndpointsTest",
|
|
3
|
+
|
|
4
|
+
"APIServerPort": 8088,
|
|
5
|
+
|
|
6
|
+
"MySQL":
|
|
7
|
+
{
|
|
8
|
+
"Server": "127.0.0.1",
|
|
9
|
+
"Port": 3306,
|
|
10
|
+
"User": "root",
|
|
11
|
+
"Password": "123456789",
|
|
12
|
+
"Database": "bookstore",
|
|
13
|
+
"ConnectionPoolLimit": 20
|
|
14
|
+
},
|
|
15
|
+
"MeadowConnectionMySQLAutoConnect": true
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
This is where the meadow schema for each table of the data model will generate.
|
package/debug/Build-Database.sh
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
#! /bin/bash
|
|
2
|
-
echo "Example - Database Build Script"
|
|
3
|
-
echo "Contact: Steven Velozo <steven@velozo.com>"
|
|
4
|
-
echo ""
|
|
5
|
-
echo "---"
|
|
6
|
-
echo ""
|
|
7
|
-
|
|
8
|
-
echo "--> Stricture now generates everything automatically"
|
|
9
|
-
echo "--> It loads from ./Model.ddl if no parameters are passed"
|
|
10
|
-
npx stricture
|
|
11
|
-
|
|
12
|
-
echo "--> Database Code generation and compilation complete!"
|