new PersistantDataService(server, route)
- Description:
Implements a persistent data mechanism.
-
A POST service is attached to the given route.
-
This is the server side of a simple client/server mechanism for persistent data.
-
The local service is attached to an express web mechanism, using a construct of the form:
// Loads required packages const express = require("express"); const server = express(); const PersistantDataService = require("./PersistantDataService.js"); // Defines a minimal persistantData service new PersistantDataService(server, "/_persitantData/upload"); server.listen(8080);
-
Parameters:
Name | Type | Default | Description |
---|---|---|---|
server |
express | The express server mechanism. |
|
route |
string |
/_persitantData/upload
|
The route, both :
|
Methods
(inner) getQuery(query) → {string}
- Description:
Implements the date file management query. The data file management queries are:
action=list[&format=json]
:- Returns the data file base names list, separated
\n
.
- Returns the data file base names list, separated
action=load&file=data-file-base-name-without-extension[&format=json]&value=default-value
:- Loads a file with a default-value if the file does not exists.
action=save&file=data-file-base-name-without-extension[&format=json]&value=value&backup=true-or-false
:- Saves a value in a text file, with a git backup possibility.
action=unlink&file=data-file-base-name-without-extension
:- Moves a data in the ./trash directory.
action=newid&where=true-or-false&when=true-or-false&suffix=suffix-string
:- Returns new file ID built from : (i) the date in standard format, if when is true, (ii) the machine MAC address, if where is true, (iii) a suffix is not empty.
Parameters:
Name | Type | Description |
---|---|---|
query |
map.<string, string> | The HTTP query, as a structured |
Returns:
The query response.
- Type
- string
(inner) getNewId(when, where, suffix)
- Description:
Returns a new unique ID
Parameters:
Name | Type | Default | Description |
---|---|---|---|
when |
true
|
If true
|
|
where |
false
|
If true adds the current machine MAC as localisation. |
|
suffix |
If defined, adds a suffix to the ID. |
Returns:
The constructed ID.