Skip to content

Commit

Permalink
Merge pull request #36 from Psychopoulet/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Psychopoulet committed Feb 7, 2020
2 parents 657bd3f + 226ced0 commit 43a3185
Show file tree
Hide file tree
Showing 158 changed files with 6,272 additions and 7,912 deletions.
8 changes: 0 additions & 8 deletions TODO.md

This file was deleted.

17 changes: 2 additions & 15 deletions documentation/Descriptor.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,8 @@ It's loaded and shared by the [Orchestrator](./Orchestrator.md) and used by

### paths

* You only need this section if you want to create an API for your plugin

### parameters

* Supported types for "parameters" are [ "string", "number", "integer", "boolean" ]

### schemas

* Supported types for "schema" are [ "string", "number", "integer", "boolean", "object", "array" ]
* You can add limits ("minLength" & "maxLength") for "string" & "array" types
* You can add limits ("minimum" & "maximum") for "number" & "integer" types

### components

* Only "schemas" and "parameters" are supported.
* There MUST have an "paths" section
* You only need this section if you want to create an API for your plugin, but you have to create an empty object if not

## Descriptor interactions

Expand Down
1 change: 0 additions & 1 deletion documentation/DescriptorUser.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ interface iDescriptorUserOptions {
#### protected

* ``` protected _externalRessourcesDirectory: string; ``` provided by "externalRessourcesDirectory" option, sent by the [Orchestrator](./Orchestrator.md)
* ``` protected _descriptorValidated: boolean; ``` if checkDescriptor is already successfuly executed, do not execute it again (for performances)
* ``` protected _Descriptor: object | null; ``` provided by "descriptor" option, sent by the [Orchestrator](./Orchestrator.md)
* ``` protected _Logger: Function | null; ``` provided by "logger" option, sent by the [Orchestrator](./Orchestrator.md)

Expand Down
20 changes: 13 additions & 7 deletions documentation/Mediator.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ You will have to add all the methods you need here to pilote the targeted use (A
## Interfaces

```typescript
interface iMediatorCheckParametersResult {
"url": object;
"body": object;
interface iUrlParameters {
"url": {
"path": object;
"query": object;
"headers": object;
"cookies": object;
};
}
```

Expand All @@ -32,7 +36,7 @@ interface iMediatorCheckParametersResult {

### Methods

* ``` public checkParameters(operationId: string, urlParams: object, bodyParams: object, contentType: string): Promise<iMediatorCheckParametersResult>; ``` Check sended parameters by method name and formate it if necessary ("true" => true, "1.1" => 1.1, etc...) (used by the [Server](./Server.md))
* ``` public checkParameters(operationId: string, urlParams: iUrlParameters, bodyParams: object): Promise<void>; ``` Check sended parameters by method name (used by the [Server](./Server.md))

### Events

Expand Down Expand Up @@ -135,7 +139,7 @@ class MyPluginMediator extends Mediator {

/**
* Execute "test" search
* @param {object} urlParameters: parameters sended with url (path, query)
* @param {object} urlParameters: parameters sended with url (path, query, cookies, headers)
* @param {object} bodyParameters: parameters sended in the query body
* @param {string} contentType: type of content type detected by the Server and setted in the Descriptor (probably "application/json")
* @return {Promise} operation result
Expand All @@ -144,7 +148,9 @@ class MyPluginMediator extends Mediator {

/*
urlParameters : {
"url-param": string
"query": {
"url-param": string
}
}
*/

Expand All @@ -154,7 +160,7 @@ class MyPluginMediator extends Mediator {
}
*/

return this._query(urlParameters["url-param"] + "_" + bodyParameters.["body-param"]);
return this._query(urlParameters.query["url-param"] + "_" + bodyParameters.["body-param"]);

}

Expand Down
2 changes: 1 addition & 1 deletion documentation/Orchestrator.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ interface iOrchestratorOptions {
--- checkers ---

* ``` checkConf(void): Promise<void>; ``` check plugin's conf (optional, can be re-writted if a specific conf is used)
* ``` isEnable(void): Promise<void>; ``` used to define plugin execution (optional, can be re-writted with a local plugins manager)
* ``` isEnable(void): Promise<void>; ``` used to define plugin execution (optional, can be re-writted with a local plugins manager) (WARNING : it's an asynchronous setter, not a getter)
* ``` checkFiles(void): Promise<void>; ``` check files existance
* ``` checkServer(void): Promise<void>; ``` check server

Expand Down
7 changes: 3 additions & 4 deletions documentation/Server.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,18 @@ Expose the [Mediator](./Mediator.md)'s methods with the [Descriptor](./Descripto
### Callable urls

* Paths must start with plugin name (same as descriptor.info.title)
* If a path contains path parameter (ex : /plugin/api/users/{user-id}), the parameter MUST be defined in the "parameters" section of this path, with the same name, and a "path" type
* Path parameters must only use this pattern : "[a-z-]" (ex : {user-id})
* If a path contains path parameter (ex : /[descriptor.info.title]/api/users/{user-id}), the parameter MUST be defined in the "parameters" section of this path, with the same name, and a "path" type
* "/[descriptor.info.title]/descriptor" [GET] : return json [Descriptor](./Descriptor.md) (already and automaticly setted in parent Server, no need for "operationId" data in the [Descriptor](./Descriptor.md) for this path)
* "/[descriptor.info.title]/api/[path]" : expose API path
* "/[descriptor.info.title]/public/[path]" : expose plugins files (HTML, CSS, etc...)

### Used HTTP statusCode

* [200](https://developer.mozilla.org/fr/docs/Web/HTTP/Status/200) (everything is fine with a content)
* [200](https://developer.mozilla.org/fr/docs/Web/HTTP/Status/200) (everything is fine with content)
* [201](https://developer.mozilla.org/fr/docs/Web/HTTP/Status/201) (everything is fine for PUT request, with or without content)
* [204](https://developer.mozilla.org/fr/docs/Web/HTTP/Status/204) (everything is fine without content)
* [400](https://developer.mozilla.org/fr/docs/Web/HTTP/Status/400) (the request does not match with the [Descriptor](./Descriptor.md))
* [404](https://developer.mozilla.org/fr/docs/Web/HTTP/Status/404) (everything is fine for GET request, without content)
* [404](https://developer.mozilla.org/fr/docs/Web/HTTP/Status/404) (this path does not exist)
* [411](https://developer.mozilla.org/fr/docs/Web/HTTP/Status/411) (the request does not have "Content-length" header)
* [500](https://developer.mozilla.org/fr/docs/Web/HTTP/Status/500) (the [Mediator](./Mediator.md) generate an unknown error)
* [501](https://developer.mozilla.org/fr/docs/Web/HTTP/Status/501) (there is no "operationId" for this path in the [Descriptor](./Descriptor.md) or the [Mediator](./Mediator.md) does not have the "operationId" method given by the [Descriptor](./Descriptor.md))
Expand Down
95 changes: 71 additions & 24 deletions lib/components/DescriptorUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
const { join } = require("path");

// locals

const { checkObject } = require(join(__dirname, "..", "checkers", "main.js"));

const {
checkDescriptorInfos,
checkDescriptorPaths
} = require(join(__dirname, "..", "utils", "checkDescriptor", "main.js"));
checkObject,
checkNonEmptyObject,
checkNonEmptyString
} = require(join(__dirname, "..", "checkers", "main.js"));

// consts

Expand Down Expand Up @@ -68,42 +66,91 @@ module.exports = class DescriptorUser extends Events {

// public

// must be inherited
init () {

return Promise.reject(new Error("\"init\" method must be inherited"));

}

// must be inherited
release () {

return Promise.reject(new Error("\"release\" method must be inherited"));

}

// must be inherited
checkDescriptor () {

// check Descriptor object
return this._descriptorValidated ? Promise.resolve() : Promise.resolve().then(() => {
return this._descriptorValidated ? Promise.resolve() :
checkNonEmptyObject("Descriptor", this._Descriptor).then(() => {

return checkObject("Descriptor", this._Descriptor);
// check info object
return checkNonEmptyObject("Descriptor.info", this._Descriptor.info).then(() => {

// check infos
}).then(() => {
// check title
return checkNonEmptyString("Descriptor.info.title", this._Descriptor.info.title).then(() => {

return checkDescriptorInfos(this._Descriptor);
return this._Descriptor.info.title !== this._Descriptor.info.title.toLowerCase() ?
Promise.reject(new Error(
"The descriptor's title (\"" + this._Descriptor.info.title + "\") " +
"is not equals in lower case (package.json convention)"
)) : Promise.resolve();

// check paths
}).then(() => {
// check version
}).then(() => {
return checkNonEmptyString("Descriptor.info.version", this._Descriptor.info.version);
});

return !this._Descriptor.paths ? Promise.resolve() : checkDescriptorPaths(this._Descriptor);
});

}).then(() => {

this._descriptorValidated = true;
// check paths object
return checkObject("Descriptor.paths", this._Descriptor.paths).then(() => {

});
// check multiple operationIds
return Promise.resolve().then(() => {

}
const operationIds = [];
Object.keys(this._Descriptor.paths).forEach((p) => {

// must be inherited
init () {
Object.keys(this._Descriptor.paths[p]).forEach((m) => {

return Promise.reject(new Error("\"init\" method must be inherited"));
if (this._Descriptor.paths[p][m].operationId) {
operationIds.push(this._Descriptor.paths[p][m].operationId);
}

}
});

// must be inherited
release () {
});

return Promise.reject(new Error("\"release\" method must be inherited"));
let multiple = false;
for (let i = 0; i < operationIds.length - 1; ++i) {

for (let j = i + 1; j < operationIds.length; ++j) {

if (operationIds[i] === operationIds[j]) {
multiple = true; break;
}

}

}

return multiple ? Promise.reject(new Error(
"There is multiple operationIds in [\" " + operationIds.join("\", ") + " \"]"
)) : Promise.resolve();

});

});

}).then(() => {
this._descriptorValidated = true;
});

}

Expand Down
Loading

0 comments on commit 43a3185

Please sign in to comment.