retold-harness 1.0.2 → 1.0.4

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.
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "optOut": false,
3
- "lastUpdateCheck": 1648097783781
3
+ "lastUpdateCheck": 1699199612265
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "optOut": false,
3
- "lastUpdateCheck": 1698350609982
4
- }
3
+ "lastUpdateCheck": 1698771786960
4
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "numericVersion": 10000,
3
+ "releaseNotes": "https://vscode-sqltools.mteixeira.dev/changelog#v-1-0-0",
4
+ "run": 1699199484050,
5
+ "updated": false,
6
+ "version": "1.0.0",
7
+ "lastNotificationDate": 0,
8
+ "installedExtPlugins": {
9
+ "driver": [
10
+ "mtxr.sqltools-driver-mysql"
11
+ ]
12
+ }
13
+ }
package/README.md CHANGED
@@ -1,7 +1,90 @@
1
- # retold-harness
1
+ # Retold Harness
2
2
 
3
- Easy start with pm2:
3
+ A basic set of API endpoints that contains Books, Authors, Joins and links to
4
+ images for the cover of each book. Useful for more complex harnesses.
4
5
 
5
- `pm2 start /home/coder/retold-harness/source/Retold-Harness.js --restart-delay 100 --name retold-harness`
6
+ Entirely self-contained.
6
7
 
7
- Other option is to login and just run `npm start` but that requires you to stay logged in.
8
+ ## Getting up and Running
9
+
10
+ This package requires Docker to be installed on your workstation. You can get
11
+ things running by typing the following commands:
12
+
13
+ ### 1) Clone the code from github:
14
+
15
+ ```
16
+ git clone https://github.com/stevenvelozo/retold-harness
17
+ ```
18
+
19
+
20
+ ### 2) Build the docker image:
21
+
22
+ _This can take a bit of time, depending on your connection speed and resources._
23
+
24
+ ```
25
+ npm run docker-dev-build
26
+ ```
27
+
28
+ ![Building the docker image](./images/Docker-Build-Image.png)
29
+
30
+ ### 3) Create and launch the docker container:
31
+
32
+ _This can also take a bit of time....._
33
+
34
+ ```
35
+ npm run docker-dev-run
36
+ ```
37
+
38
+ ![Launching the docker container](./images/Docker-Run-Container.png)
39
+
40
+ ![The launched container in the Docker UI](./images/Docker-Container-Launched.png)
41
+
42
+
43
+ ## After the docker container is running there is quite a bit available:
44
+
45
+ * a REST web API serving JSON on port 8086
46
+ * a browser-based visual studio code environment ready to run node applications
47
+ * a mariadb instance, preloaded with 10,000 Book records joined to their Author records
48
+ * a partridge
49
+ * a pear tree
50
+
51
+ ### This all fits in less than 500 meg of RAM, and uses virtually no processor power
52
+
53
+ ![Docker statistics after a few minutes of running](./images/Docker-Container-Resources.png)
54
+
55
+ ## Some REST API Examples
56
+
57
+ The REST endpoints are provided by the [meadow-endpoints](https://www.npmjs.com/package/meadow-endpoints) library on NPM. Some examples of queries you can make:
58
+
59
+ ### List the first 100 Books in the database: (http://localhost:8086/1.0/Books/0/100)
60
+
61
+ ![The first 100 Books](./images/API-Book-List.png)
62
+ ### Get the book with `IDBook` 1: (http://localhost:8086/1.0/Book/1)
63
+
64
+ You will notice that when requesting a single book, there is an `Authors` array populated with the connected authors for the particular book. But in the list, the array was not filled out. This is because in meadow-endpoints there is a post-operation behavior hook only attached to the read single record endpoint. This is reflected in the `/source/Retold-Harness.js` code file in lines 14-41.
65
+
66
+ ![Book 1](./images/API-Book-First.png)
67
+
68
+ ### List the first 10 Authors in the database whose name begins with `Susan`: (http://localhost:8086/1.0/Authors/FilteredTo/FBV~Name~LK~Susan%25/0/10)
69
+
70
+ ![The first 10 Susans](./images/API-Author-Susans.png)
71
+
72
+ ## Luxury Code
73
+
74
+ Luxury code is a set of tools to provide easy debugging and test running regardless of environment. These tools leverage the code-server browser implementation of the Visual Studio Code editor. The first time you launch the browser editor, you will be asked for a password. The password is: `luxury`
75
+
76
+ ![Launching Luxury Code requires a Password: luxury](./images/vscode-Login.png)
77
+
78
+ ![Visual Studio Code Editor with Config and Source](./images/vscode-Editor.png)
79
+
80
+ ## MySQL
81
+
82
+ The docker image also exposes a MySQL server (it's actually MariaDB but nobody is the wiser). You can connect to and query this database directly from your tool of choice or other applications. The user is: `root`, the port is `3306` and the password is: `123456789`
83
+
84
+ ![MySQL Connection Info](./images/SQL-Connection.png)
85
+
86
+ ![MySQL Query](./images/SQL-Query.png)
87
+
88
+ ## Customizing your Environment
89
+
90
+ If you dislike the ports, passwords or anything else about this configuration all the code is readily available. In the `package.json` file, the two convenience docker spin-up commands are there. This is where you would change the port mapping for the API server, SQL server and other services. Remember.... you broke it, you bought it.
@@ -27,13 +27,15 @@ done
27
27
 
28
28
  echo "=> MySQL service startup finished. <="
29
29
 
30
- # Install the latest pm2 process manager
31
- # This is *quite complex* because we want to run as the synthesized user pulled in to match the user in our environment
30
+ # This junk below is *quite complex* because we want to run as the synthesized user pulled in to match the user in our environment
32
31
  # FOR POSTERITY: Running bash in interactive mode, trying to manually source the bashrc, etc. all failed due to
33
32
  # the complex way docker and the base image set the user (we have an explicit user ID). This method
34
33
  # works but is ugly as heck.
34
+ # Install the latest pm2 process manager
35
35
  export HOME=/home/coder
36
36
  bash -i <(echo "npm install pm2 -g")
37
+ # Install the dependencies for node
38
+ bash -i <(echo "npm install")
37
39
  # Now run the harness API within the pm2 process manager
38
40
  # Twiddling for posterity (these didn't work)
39
41
  #bash -c "pm2 start /home/coder/retold-harness/source/Retold-Harness.js"
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,13 +1,17 @@
1
1
  {
2
2
  "name": "retold-harness",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Restful API harness. Serves on 8086.",
5
5
  "main": "source/Retold-Harness.js",
6
6
  "scripts": {
7
- "test": "./node_modules/.bin/mocha -u tdd -R spec",
8
7
  "start": "node source/Retold-Harness.js",
9
- "coverage": "./node_modules/.bin/nyc --reporter=lcov --reporter=text-lcov ./node_modules/mocha/bin/_mocha -- -u tdd -R spec",
8
+
9
+ "test": "npx mocha -u tdd -R spec",
10
+ "tests": "npx mocha -u tdd --exit -R spec --grep",
11
+ "coverage": "npx nyc --reporter=lcov --reporter=text-lcov npx mocha -- -u tdd -R spec",
12
+
10
13
  "build": "npx quack build",
14
+
11
15
  "docker-dev-build": "docker build ./ -f Dockerfile_LUXURYCode -t retold-harness-image:local",
12
16
  "docker-dev-run": "docker run -it -d --name retold-harness-dev -p 20001:8080 -p 8086:8086 -p 3306:3306 -v \"$PWD/.config:/home/coder/.config\" -v \"$PWD:/home/coder/retold-harness\" -u \"$(id -u):$(id -g)\" -e \"DOCKER_USER=$USER\" retold-harness-image:local",
13
17
  "docker-dev-shell": "docker exec -it retold-harness-dev /bin/bash"
@@ -23,10 +27,10 @@
23
27
  },
24
28
  "homepage": "https://github.com/stevenvelozo/retold-harness#readme",
25
29
  "dependencies": {
26
- "retold-data-service": "^1.0.3"
30
+ "retold-data-service": "^1.0.4"
27
31
  },
28
32
  "devDependencies": {
29
- "quackage": "^1.0.7"
33
+ "quackage": "^1.0.24"
30
34
  },
31
35
  "mocha": {
32
36
  "diff": true,
@@ -2,40 +2,62 @@ const _Settings = require('./configuration-bookstore-serve-api.js');
2
2
 
3
3
  const libFable = require('fable');
4
4
 
5
+ // Initialize fable
5
6
  _Fable = new libFable(_Settings);
7
+
8
+ // Add the data service type and initialize it
6
9
  _Fable.serviceManager.addServiceType('RetoldDataService', require('retold-data-service'));
7
- // The RetoldDataService defaults to process.cwd() but we want to run this from wherever.
8
- _Fable.serviceManager.instantiateServiceProvider('RetoldDataService',
10
+ // Initialize it with relative paths for the model from this code folder, regardless of where we run this from
11
+ let libRetoldDataService = _Fable.serviceManager.instantiateServiceProvider('RetoldDataService',
9
12
  {
10
13
  "FullMeadowSchemaPath": `${__dirname}/model/`,
11
14
  "DALMeadowSchemaPath": `${__dirname}/model/meadow/`
12
15
  });
13
16
 
14
- _Fable.MeadowEndpoints.Book.controller.BehaviorInjection.setBehavior('Read-PostOperation',
15
- (pRequest, pRequestState, fComplete) =>
17
+
18
+ libRetoldDataService.onAfterInitializeAsync =
19
+ (fAfterInitializeComplete) =>
16
20
  {
17
- // Get the join records
18
- _Fable.DAL.BookAuthorJoin.doReads(_Fable.DAL.BookAuthorJoin.query.addFilter('IDBook', pRequestState.Record.IDBook),
19
- (pJoinReadError, pJoinReadQuery, pJoinRecords)=>
21
+ // Create a post operation behavior for the book Read singular record endpoint only
22
+ _Fable.MeadowEndpoints.Book.controller.BehaviorInjection.setBehavior('Read-PostOperation',
23
+ (pRequest, pRequestState, fRequestComplete) =>
20
24
  {
21
- let tmpAuthorList = [];
22
- for (let j = 0; j < pJoinRecords.length; j++)
23
- {
24
- tmpAuthorList.push(pJoinRecords[j].IDAuthor);
25
- }
26
- if (tmpAuthorList.length < 1)
27
- {
28
- pRequestState.Record.Authors = [];
29
- return fComplete();
30
- }
31
- else
32
- {
33
- _Fable.DAL.Author.doReads(_Fable.DAL.Author.query.addFilter('IDAuthor', tmpAuthorList, 'IN'),
34
- (pReadsError, pReadsQuery, pAuthors)=>
25
+ // Get the join records
26
+ _Fable.DAL.BookAuthorJoin.doReads(_Fable.DAL.BookAuthorJoin.query.addFilter('IDBook', pRequestState.Record.IDBook),
27
+ (pJoinReadError, pJoinReadQuery, pJoinRecords)=>
28
+ {
29
+ let tmpAuthorList = [];
30
+ for (let j = 0; j < pJoinRecords.length; j++)
31
+ {
32
+ tmpAuthorList.push(pJoinRecords[j].IDAuthor);
33
+ }
34
+ if (tmpAuthorList.length < 1)
35
+ {
36
+ _Fable.log.trace(`Found no authors for IDBook ${pRequestState.Record.IDBook} (${pRequestState.Record.Title}). What even is a book without authors?`)
37
+ pRequestState.Record.Authors = [];
38
+ return fRequestComplete();
39
+ }
40
+ else
35
41
  {
36
- pRequestState.Record.Authors = pAuthors;
37
- return fComplete();
38
- });
39
- }
42
+ _Fable.DAL.Author.doReads(_Fable.DAL.Author.query.addFilter('IDAuthor', tmpAuthorList, 'IN'),
43
+ (pReadsError, pReadsQuery, pAuthors)=>
44
+ {
45
+ pRequestState.Record.Authors = pAuthors;
46
+ _Fable.log.info(`Found ${pAuthors.length} authors for IDBook ${pRequestState.Record.IDBook} (${pRequestState.Record.Title}).`)
47
+ return fRequestComplete();
48
+ });
49
+ }
50
+ });
40
51
  });
52
+
53
+ return fAfterInitializeComplete();
54
+ };
55
+
56
+ libRetoldDataService.initializeAsync(
57
+ (pError) =>
58
+ {
59
+ if (pError)
60
+ {
61
+ _Fable.log.error(`Error initializing `)
62
+ }
41
63
  });