Skip to content

Commit cfe1743

Browse files
authored
Merge pull request #25 from Luidog/persistent-store
Persistent store
2 parents 323e1e7 + 566b7fa commit cfe1743

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+5821
-803
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ node_modules
55
/user
66
!assets/placeholder.json
77
assets/*
8+
*.log
9+
/dapi
10+
/coverage
11+
/clients

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ coverage
2525
.github
2626
#unnecessary directories
2727
examples/
28+
logs/
29+
dapi/
2830
test/
2931
user/
3032
assets/

README.md

Lines changed: 137 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ read from either the `msg` property or the `flow` and `global` contexts. The def
1818
## Table of Contents
1919

2020
- [Installation](#installation)
21+
- [Storage](#storage)
22+
- [Status Node](#status-node)
23+
- [Status Illustration](#status-illustration)
24+
- [Container Data Flow](#status-flow)
2125
- [Login Node](#login-node)
2226
- [Login Illustration](#login-illustration)
2327
- [Login Flow](#login-flow)
@@ -97,6 +101,31 @@ npm install --save node-red-contrib-filemaker
97101

98102
These nodes can also be installed using the Node-RED palette manager.
99103

104+
# Storage
105+
106+
The nodes in this project all depend on a configurable Data API client. By default the client is saved in-memory. When saved in-memory a client will not persist between restarts of the Node-RED runtime. This means that each restart of the Node-RED runtime will cause the client to open new Data API sessions.
107+
108+
To persist a client between Node-RED runtime restarts and allow active session monitoring and maintenance additional datastores can be configured. This project will accept a url property and an options property from a marpat object in the Node-RED settings.js file. Any datastore made available by [marpat](https://github.com/luidog/marpat). The url property accepts the following formats:
109+
110+
- MongoDB:
111+
- Format: mongodb://[username:password@]host[:port][/db-name]
112+
- Filesystem:
113+
- Format: nedb://[directory-path]
114+
- In Memory:
115+
- Format: nedb://memory
116+
117+
## Status Node
118+
119+
The status node will return the current state of the configured client. The status node will return the client's data usage, urls for all pending and queued requests, and currently open sessions.
120+
121+
### Status Illustration
122+
123+
![status Node](https://github.com/Luidog/node-red-contrib-filemaker/blob/master/examples/images/status-node.png?raw=true)
124+
125+
### Status Flow
126+
127+
[![Status Flow](https://img.shields.io/badge/Flow-Status%20Node-red.svg)](https://github.com/Luidog/node-red-contrib-filemaker/blob/master/examples/flows/status-example.json)
128+
100129
## Login Node
101130

102131
The login node will open a FileMaker Data API session. This node will also save the resulting session token for future use by the configured client. You are _not required_ to login before using any other node in a flow.
@@ -137,10 +166,15 @@ The product info node gets server product info. This node gets metadata for the
137166

138167
The databases node gets all the scripts and script folders accesible to the client.
139168

169+
These nodes can be installed from the command line by running the following command in your Node-RED directory:
170+
140171
### Databases Illustration
141172

173+
142174
![Databases Node](https://github.com/Luidog/node-red-contrib-filemaker/blob/master/examples/images/databases-node.png?raw=true)
143175

176+
These nodes can also be installed using the Node-RED palette manager.
177+
144178
### Databases Flow
145179

146180
[![Databases Example Flow](https://img.shields.io/badge/Flow-Databases%20Node-red.svg)](https://github.com/Luidog/node-red-contrib-filemaker/blob/master/examples/flows/databases-example.json)
@@ -357,30 +391,55 @@ npm test
357391
```
358392

359393
```default
360-
> node-red-contrib-filemaker@2.0.0 test /node-red-contrib-filemaker
394+
> node-red-contrib-filemaker@2.2.0 test node-red-contrib-filemaker
361395
> snyk test && nyc _mocha --recursive "test/**/*_spec.js" --timeout=30000 --exit
362396
363-
364397
Testing /node-red-contrib-filemaker...
365398
366-
Organisation: luidog
399+
Organization: luidog
367400
Package manager: npm
368401
Target file: package-lock.json
369402
Open source: yes
370403
Project path: /node-red-contrib-filemaker
371404
Local Snyk policy: found
405+
Licenses: enabled
372406
373-
✓ Tested 363 dependencies for known vulnerabilities, no vulnerable paths found.
407+
✓ Tested 364 dependencies for known issues, no vulnerable paths found.
374408
375409
Client Node
376-
✓ should be loaded
410+
Client Save
411+
✓ should save on close
412+
Reused Client Tests
413+
✓ should be loaded
414+
✓ should create a persistent client (152ms)
415+
✓ should reuse a client (113ms)
416+
✓ should allow a client's server configuration to be modified
417+
✓ should allow a client's database configuration to be modified
418+
✓ should allow a client's account user configuration to be modified
419+
✓ should allow a client's account password configuration to be modified
420+
✓ should allow multiple clients
421+
✓ should create a client of one does not exist
422+
✓ should reuse a client if it exists
423+
✓ should handle datastore errors
424+
New Client Tests
425+
✓ should be loaded
426+
✓ should create a persistent client (215ms)
427+
✓ should reuse a client (113ms)
428+
✓ should allow a client's server configuration to be modified
429+
✓ should allow a client's database configuration to be modified
430+
✓ should allow a client's account user configuration to be modified
431+
✓ should allow a client's account password configuration to be modified
432+
✓ should allow multiple clients
433+
✓ should create a client of one does not exist
434+
✓ should reuse a client if it exists
435+
✓ should handle datastore errors
377436
378437
Container Data Node
379438
✓ should be loaded
380-
✓ should download an object with container data to a buffer (1524ms)
381-
✓ should download an array of objects with container data to a buffer (332ms)
382-
✓ should download an object with container data to the filesystem (329ms)
383-
✓ should download an array of objects with container data to the filesystem (329ms)
439+
✓ should download an object with container data to a buffer (547ms)
440+
✓ should download an array of objects with container data to a buffer (2579ms)
441+
✓ should download an object with container data to the filesystem (1526ms)
442+
✓ should download an array of objects with container data to the filesystem (1430ms)
384443
✓ should throw an error with a message and a code when writing an object to a buffer and an error is triggered
385444
✓ should throw an error with a message and a code when writing an array to a buffer an error is triggered
386445
✓ should handle undefined data input when writing to a buffer
@@ -390,101 +449,119 @@ Local Snyk policy: found
390449
391450
Create Record Node
392451
✓ should be loaded
393-
✓ should create a record (188ms)
394-
✓ should create allow the filemaker response to be merged to the message object (188ms)
395-
✓ should use flow context to create a record. (187ms)
396-
✓ should use global context to create a record. (189ms)
397-
✓ should throw an error with a message and a code (209ms)
452+
✓ should create a record (208ms)
453+
✓ should allow the filemaker response to be merged to the message object (308ms)
454+
✓ should use flow context to create a record. (217ms)
455+
✓ should use global context to create a record. (209ms)
456+
✓ should throw an error with a message and a code (264ms)
398457
399458
Databases Node
400459
✓ should be loaded
401-
✓ should return available databases (87ms)
402-
✓ should reject with an error message and a code (144ms)
460+
✓ should return available databases (89ms)
461+
✓ should reject with an error message and a code (115ms)
462+
✓ should reject if a client can not be initialized
403463
404464
Delete Record Node
405465
✓ should be loaded
406-
✓ should delete a record (309ms)
407-
✓ should throw an error with a message and a code (188ms)
466+
✓ should delete a record (345ms)
467+
✓ should throw an error with a message and a code (214ms)
468+
✓ should handle client initilization errors
408469
409470
Duplicate Record Node
410471
✓ should be loaded
411-
✓ should duplicate a record (298ms)
412-
✓ should reject with an error message and a code (192ms)
472+
✓ should duplicate a record (356ms)
473+
✓ should reject with an error message and a code (206ms)
474+
✓ should rehject with an error if the client cannot be initialized
413475
414476
Edit Record Node
415477
✓ should be loaded
416-
✓ should edit a record (312ms)
417-
✓ should support merging data when editing a record (322ms)
418-
✓ should throw an error with a message and a code (197ms)
478+
✓ should edit a record (357ms)
479+
✓ should support merging data when editing a record (356ms)
480+
✓ should throw an error with a message and a code (225ms)
481+
✓ should reject with an error if a client cannot be initialized
419482
420483
FieldData Utility Node
421484
✓ should be loaded
422-
✓ should transform an array of objects (314ms)
423-
✓ should transform a a single object (330ms)
485+
✓ should transform an array of objects (370ms)
486+
✓ should transform a a single object (386ms)
424487
✓ should reject with an error message and code
425488
426489
Find Records Node
427490
✓ should be loaded
428-
✓ should perform a find (298ms)
429-
✓ should throw an error with a message and a code (216ms)
491+
✓ should perform a find (352ms)
492+
✓ should handle client connection errors
493+
✓ should handle client initialization errors
494+
✓ allows multiple clients
495+
✓ will reuse previous clients
496+
✓ should throw an error with a message and a code (158ms)
430497
431498
Get Record Node
432499
✓ should be loaded
433-
✓ should get a specific record (338ms)
434-
✓ should throw an error with a message and a code (221ms)
500+
✓ should get a specific record (408ms)
501+
✓ should throw an error with a message and a code (144ms)
502+
✓ should handle client connection errors
435503
436504
Set Globals Node
437505
✓ should be loaded
438-
✓ should set globals (222ms)
439-
✓ should throw an error with a message and a code (231ms)
506+
✓ should set globals (169ms)
507+
✓ should throw an error with a message and a code (162ms)
508+
✓ should reject with an error if the client cannot be initialized
440509
441510
Layout Info Node
442511
✓ should be loaded
443-
✓ should get layout information (230ms)
444-
✓ should throw an error with a message and a code (218ms)
512+
✓ should get layout information (168ms)
513+
✓ should throw an error with a message and a code (172ms)
514+
✓ should throw an error with a message and a code
445515
446516
Get Layouts Node
447517
✓ should be loaded
448-
✓ should return a list of layouts (207ms)
518+
✓ should return a list of layouts (168ms)
449519
✓ should reject with an error message and a code
520+
✓ should reject if a client cannot be initialized
450521
451522
List Records Node
452523
✓ should be loaded
453-
✓ should List records (346ms)
454-
✓ should throw an error with a message and a code (227ms)
524+
✓ should List records (405ms)
525+
✓ should throw an error with a message and a code (164ms)
526+
✓ should reject with an error if a client cannot be initialized
455527
456528
Login Node
457529
✓ should be loaded
458-
✓ should login to a Data API session (100ms)
459-
✓ should throw an error with a message and a code (1423ms)
530+
✓ should login to a Data API session (104ms)
531+
✓ should throw an error with a message and a code (1437ms)
532+
✓ should reject with an error if a client cannot be initialized
460533
461534
Logout Node
462535
✓ should be loaded
463-
✓ should close a Data API Session (170ms)
536+
✓ should close a Data API Session (656ms)
464537
✓ should throw an error with a message and a code
538+
✓ should throw an error if a client cannot be initialized
465539
466540
Product Info Node
467541
✓ should be loaded
468-
✓ should return Data API Server Info (76ms)
469-
✓ should reject with an error message and a code (119ms)
542+
✓ should return Data API Server Info (93ms)
543+
✓ should reject with an error message and a code (102ms)
544+
✓ should reject with an error if the client cannot be initialized
470545
471546
Record Id Utility Node
472547
✓ should be loaded
473-
✓ should extract record ids from a single object (287ms)
474-
✓ should extract record ids from an array of objects (280ms)
548+
✓ should extract record ids from a single object (338ms)
549+
✓ should extract record ids from an array of objects (258ms)
475550
✓ should reject with an error message and a code
476551
477552
Trigger Script Node
478553
✓ should be loaded
479-
✓ should trigger a script (230ms)
480-
✓ should parse a script result if it is valid json (245ms)
481-
✓ should not parse a script result if it is not valid json (230ms)
482-
✓ should throw an error with a message and a code (242ms)
554+
✓ should trigger a script (193ms)
555+
✓ should parse a script result if it is valid json (165ms)
556+
✓ should not parse a script result if it is not valid json (182ms)
557+
✓ should throw an error with a message and a code (274ms)
558+
✓ should throw an error if a client cannot be initialized
483559
484560
Get Scripts Node
485561
✓ should be loaded
486-
✓ should return a list of scripts (241ms)
562+
✓ should return a list of scripts (176ms)
487563
✓ should reject with an error message and a code
564+
✓ should throw an error if a client cannot be initialized
488565
489566
Utility Services
490567
merge utility
@@ -513,20 +590,26 @@ Local Snyk policy: found
513590
✓ it should cast multiple string values as booleans
514591
✓ it should only cast strings of true or false
515592
593+
Client Status Node
594+
✓ should be loaded
595+
✓ should return Data API Client Status
596+
✓ should reject with an error if the client cannot be initialized
597+
516598
Transform Utility Node
517599
✓ should be loaded
518-
✓ should transform an array of objects (377ms)
519-
✓ should transform a single object (272ms)
600+
✓ should transform an array of objects (411ms)
601+
✓ should transform a single object (270ms)
520602
✓ should throw an error with a message and a code
521603
522604
Upload File Node
523605
✓ should be loaded
524-
✓ should upload to an existing record (460ms)
525-
✓ should upload to a file to a new record (494ms)
606+
✓ should upload to an existing record (436ms)
607+
✓ should upload to a file to a new record (1455ms)
526608
✓ should throw an error with a message and a code
609+
✓ should throw an error if a client cannot be initialized
527610
528611
529-
102 passing (15s)
612+
146 passing (1m)
530613
531614
-----------------------|----------|----------|----------|----------|-------------------|
532615
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
@@ -554,6 +637,7 @@ All files | 100 | 100 | 100 | 100 |
554637
recordId.js | 100 | 100 | 100 | 100 | |
555638
script.js | 100 | 100 | 100 | 100 | |
556639
scripts.js | 100 | 100 | 100 | 100 | |
640+
status.js | 100 | 100 | 100 | 100 | |
557641
transform.js | 100 | 100 | 100 | 100 | |
558642
upload.js | 100 | 100 | 100 | 100 | |
559643
services | 100 | 100 | 100 | 100 | |

ecosystem.dev.config.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
const path = require("path");
2+
const environment = require("dotenv");
3+
const varium = require("varium");
4+
5+
environment.config();
6+
7+
const manifestPath = path.join(__dirname, "./env.manifest");
8+
9+
varium({ manifestPath });
210

311
module.exports = {
412
apps: [
@@ -7,12 +15,15 @@ module.exports = {
715
script: path.join(__dirname, "./node_modules/.bin/node-red"),
816
args: "-v -s ./red.dev.config.js",
917
instances: 1,
10-
out_file: "./output.log",
18+
out_file: "./logs/output.log",
1119
autorestart: true,
1220
watch: true,
21+
ignore_watch: ["./logs", "./dapi"],
1322
node_args: "--max_old_space_size=8192",
1423
env: {
15-
NODE_ENV: "development"
24+
NODE_ENV: "development",
25+
PORT: process.env.PORT,
26+
DATASTORE: process.env.DATASTORE
1627
}
1728
}
1829
]

env.manifest

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Node RED Configuration
2+
3+
PORT : Int
4+
5+
# MARPAT Configuration
6+
7+
DATASTORE : String | nedb://memory

0 commit comments

Comments
 (0)