@modular-rest/server 1.6.5 → 1.7.0
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/README.md +2 -0
- package/package.json +8 -3
- package/src/application.js +32 -68
- package/src/class/collection_definition.js +32 -24
- package/src/class/combinator.js +82 -71
- package/src/class/database_trigger.js +18 -12
- package/src/class/db_schemas.js +11 -11
- package/src/class/security.js +105 -31
- package/src/class/trigger_operator.js +35 -31
- package/src/index.js +2 -25
- package/src/middlewares.js +14 -1
- package/src/services/data_provider/service.js +173 -177
- package/src/services/user_manager/service.js +139 -30
- package/tsconfig.json +10 -0
package/README.md
CHANGED
|
@@ -6,6 +6,8 @@ a nodejs module based on KOAJS for developing Rest-APIs in a modular solution.
|
|
|
6
6
|
this module has one method:
|
|
7
7
|
- `createRest`: is the main functionality of the module.
|
|
8
8
|
|
|
9
|
+
**Note**: active "javascript.implicitProjectConfig.checkJs": true in your vscode settings.
|
|
10
|
+
|
|
9
11
|
## Install
|
|
10
12
|
|
|
11
13
|
Install using [npm](https://www.npmjs.com/package/modular-rest):
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modular-rest/server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "a nodejs module based on KOAJS for developing Rest-APIs in a modular solution.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
+
"generate:types": "tsc"
|
|
8
9
|
},
|
|
10
|
+
"types": "./types/index.d.ts",
|
|
9
11
|
"repository": {
|
|
10
12
|
"type": "git",
|
|
11
13
|
"url": "git+https://github.com/navidshad/modular-rest.git"
|
|
@@ -35,5 +37,8 @@
|
|
|
35
37
|
"mongoose": "^5.10.9",
|
|
36
38
|
"nested-property": "^4.0.0"
|
|
37
39
|
},
|
|
38
|
-
"devDependencies": {
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/koa": "^2.14.0",
|
|
42
|
+
"typescript": "^5.3.3"
|
|
43
|
+
}
|
|
39
44
|
}
|
package/src/application.js
CHANGED
|
@@ -1,89 +1,53 @@
|
|
|
1
|
-
|
|
1
|
+
const koa = require("koa");
|
|
2
2
|
const cors = require("@koa/cors");
|
|
3
3
|
const koaBody = require("koa-body");
|
|
4
4
|
const koaStatic = require("koa-static-server");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const Combination = require("./class/combinator");
|
|
7
|
+
const DataProvider = require("./services/data_provider/service");
|
|
8
|
+
const UserService = require("./services/user_manager/service");
|
|
9
9
|
|
|
10
10
|
let defaultServiceRoot = __dirname + "/services";
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// */
|
|
16
|
-
// rootDir?: string | undefined;
|
|
17
|
-
// /**
|
|
18
|
-
// * optional rewrite path
|
|
19
|
-
// */
|
|
20
|
-
// rootPath?: string | undefined;
|
|
21
|
-
// /**
|
|
22
|
-
// * optional default file to serve if requested static is missing
|
|
23
|
-
// */
|
|
24
|
-
// notFoundFile?: string | undefined;
|
|
25
|
-
// /**
|
|
26
|
-
// * request access log to console
|
|
27
|
-
// */
|
|
28
|
-
// log?: boolean | undefined;
|
|
29
|
-
// /**
|
|
30
|
-
// * don't execute any downstream middleware. defaults to true
|
|
31
|
-
// */
|
|
32
|
-
// last?: boolean | undefined;
|
|
33
|
-
// /**
|
|
34
|
-
// * Browser cache max-age in milliseconds. defaults to 0
|
|
35
|
-
// */
|
|
36
|
-
// maxage?: number | undefined;
|
|
37
|
-
// /**
|
|
38
|
-
// * Allow transfer of hidden files. defaults to false
|
|
39
|
-
// */
|
|
40
|
-
// hidden?: boolean | undefined;
|
|
41
|
-
// /**
|
|
42
|
-
// * Try to serve the gzipped version of a file automatically when gzip is supported by a client and if the requested
|
|
43
|
-
// */
|
|
44
|
-
// gzip?: boolean | undefined;
|
|
45
|
-
// /**
|
|
46
|
-
// * Try to serve the brotli version of a file automatically when brotli is supported by a client and in the requested
|
|
47
|
-
// */
|
|
48
|
-
// brotli?: boolean | undefined;
|
|
49
|
-
// index?: string | undefined;
|
|
50
|
-
// }
|
|
12
|
+
/**
|
|
13
|
+
* @typedef {import('koa')} Koa
|
|
14
|
+
*/
|
|
51
15
|
|
|
52
16
|
/**
|
|
53
17
|
* @param {{
|
|
54
|
-
* cors
|
|
55
|
-
* modulesPath
|
|
56
|
-
*
|
|
57
|
-
* rootDir
|
|
58
|
-
* rootPath
|
|
59
|
-
* notFoundFile
|
|
60
|
-
* log
|
|
61
|
-
* last
|
|
62
|
-
* maxage
|
|
63
|
-
* hidden
|
|
64
|
-
* gzip
|
|
65
|
-
* brotli
|
|
66
|
-
* index
|
|
18
|
+
* cors?: any; // Options for @koa/cors middleware.
|
|
19
|
+
* modulesPath?: string; // Root directory of your router.js/db.js files.
|
|
20
|
+
* staticPath?: {
|
|
21
|
+
* rootDir?: string; // Root directory of your static files.
|
|
22
|
+
* rootPath?: string; // Root path of your static files.
|
|
23
|
+
* notFoundFile?: string; // Not found file.
|
|
24
|
+
* log?: boolean; // Log requests to console.
|
|
25
|
+
* last?: boolean; // Don't execute any downstream middleware.
|
|
26
|
+
* maxage?: number; // Browser cache max-age in milliseconds.
|
|
27
|
+
* hidden?: boolean; // Allow transfer of hidden files.
|
|
28
|
+
* gzip?: boolean; // Try to serve the gzipped version of a file automatically when gzip is supported by a client and if the requested file exists.
|
|
29
|
+
* brotli?: boolean; // Try to serve the brotli version of a file automatically when brotli is supported by a client and if the requested file exists.
|
|
30
|
+
* index?: string; // Index file.
|
|
67
31
|
* };
|
|
68
|
-
* onBeforeInit
|
|
69
|
-
* onAfterInit
|
|
70
|
-
* port
|
|
71
|
-
* dontListen
|
|
72
|
-
* mongo
|
|
32
|
+
* onBeforeInit?: (koaApp:Koa) => void; // A callback called before initializing the Koa server.
|
|
33
|
+
* onAfterInit?: (koaApp:Koa) => void; // A callback called after server initialization.
|
|
34
|
+
* port?: number; // Server port.
|
|
35
|
+
* dontListen?: boolean; // If true, the server will not run and will only return the Koa app object.
|
|
36
|
+
* mongo?: {
|
|
73
37
|
* dbPrefix: string; // A prefix for your database name.
|
|
74
38
|
* mongoBaseAddress: string; // The address of your MongoDB server without any database specification.
|
|
75
|
-
* addressMap
|
|
39
|
+
* addressMap?: string; // Specific addresses for each database.
|
|
76
40
|
* };
|
|
77
|
-
* keypair
|
|
41
|
+
* keypair?: {
|
|
78
42
|
* private: string; // Private key for RSA authentication.
|
|
79
43
|
* public: string; // Public key for RSA authentication.
|
|
80
44
|
* };
|
|
81
|
-
* adminUser
|
|
45
|
+
* adminUser?: {
|
|
82
46
|
* email: string; // Admin user email.
|
|
83
47
|
* password: string; // Admin user password.
|
|
84
48
|
* };
|
|
85
49
|
* verificationCodeGeneratorMethod: () => string; // A method to return a verification code when registering a new user.
|
|
86
|
-
* collectionDefinitions
|
|
50
|
+
* collectionDefinitions?: CollectionDefinition[]; // An array of additional collection definitions.
|
|
87
51
|
* }} options
|
|
88
52
|
*/
|
|
89
53
|
module.exports = async function createRest(options) {
|
|
@@ -121,8 +85,8 @@ module.exports = async function createRest(options) {
|
|
|
121
85
|
/**
|
|
122
86
|
* Plug In KoaStatic
|
|
123
87
|
*/
|
|
124
|
-
if (options.
|
|
125
|
-
app.use(koaStatic(options.
|
|
88
|
+
if (options.staticPath) {
|
|
89
|
+
app.use(koaStatic(options.staticPath));
|
|
126
90
|
}
|
|
127
91
|
|
|
128
92
|
/**
|
|
@@ -1,25 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
* @param {object} option
|
|
7
|
-
* @param {string} option.db database name
|
|
8
|
-
* @param {string} option.collection collection name
|
|
9
|
-
* @param {object} option.schema mongoose schema
|
|
10
|
-
* @param {array} option.permissions a list of Permission for this collection
|
|
11
|
-
* @param {array} option.trigger a DatabaseTrigger
|
|
12
|
-
*/
|
|
13
|
-
constructor({ db, collection, schema, permissions, trigger }) {
|
|
14
|
-
// string
|
|
15
|
-
this.database = db;
|
|
16
|
-
// string
|
|
17
|
-
this.collection = collection;
|
|
18
|
-
// schema object of mongoose
|
|
19
|
-
this.schema = schema;
|
|
20
|
-
// a list of Permission for this collection
|
|
21
|
-
this.permissions = permissions;
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('./security.js').Permission} Permission
|
|
3
|
+
* @typedef {import('./database_trigger.js')} DatabaseTrigger
|
|
4
|
+
*/
|
|
22
5
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
6
|
+
class CollectionDefinition {
|
|
7
|
+
/**
|
|
8
|
+
* This class helps to create a mongoose collection
|
|
9
|
+
* associated with permissions and triggers.
|
|
10
|
+
*
|
|
11
|
+
* @class
|
|
12
|
+
* @param {Object} option
|
|
13
|
+
* @param {string} option.db - Database name
|
|
14
|
+
* @param {string} option.collection - Collection name
|
|
15
|
+
* @param {Object} option.schema - Mongoose schema
|
|
16
|
+
* @param {Array<Permission>} option.permissions - A list of permissions for this collection
|
|
17
|
+
* @param {Array<DatabaseTrigger>} option.trigger - A database trigger
|
|
18
|
+
*/
|
|
19
|
+
constructor({ db, collection, schema, permissions, trigger }) {
|
|
20
|
+
// string
|
|
21
|
+
this.database = db;
|
|
22
|
+
// string
|
|
23
|
+
this.collection = collection;
|
|
24
|
+
// schema object of mongoose
|
|
25
|
+
this.schema = schema;
|
|
26
|
+
// a list of Permission for this collection
|
|
27
|
+
this.permissions = permissions;
|
|
28
|
+
|
|
29
|
+
this.trigger = trigger;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = CollectionDefinition;
|
package/src/class/combinator.js
CHANGED
|
@@ -1,90 +1,101 @@
|
|
|
1
|
-
let Router = require(
|
|
2
|
-
let directory = require(
|
|
1
|
+
let Router = require("koa-router");
|
|
2
|
+
let directory = require("./directory.js");
|
|
3
3
|
|
|
4
4
|
class Combinator {
|
|
5
|
+
async combineRoutesByFilePath(rootDirectory, app) {
|
|
6
|
+
// find route paths
|
|
7
|
+
let option = { name: "router", filter: [".js"] };
|
|
8
|
+
let routerPaths = await directory
|
|
9
|
+
.find(rootDirectory, option)
|
|
10
|
+
.then()
|
|
11
|
+
.catch((e) => {
|
|
12
|
+
console.log(e);
|
|
13
|
+
});
|
|
5
14
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
.catch(e => { console.log(e) });
|
|
15
|
+
// create and combine routes into the app
|
|
16
|
+
for (let i = 0; i < routerPaths.length; i++) {
|
|
17
|
+
let service = require(routerPaths[i]);
|
|
18
|
+
let name = service.name;
|
|
11
19
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let service = require(routerPaths[i]);
|
|
15
|
-
let name = service.name;
|
|
20
|
+
var serviceRouter = new Router();
|
|
21
|
+
serviceRouter.use(`/${name}`, service.main.routes());
|
|
16
22
|
|
|
17
|
-
|
|
18
|
-
var serviceRouter = new Router();
|
|
19
|
-
serviceRouter.use(`/${name}`, service.main.routes());
|
|
20
|
-
|
|
21
|
-
app.use(serviceRouter.routes());
|
|
22
|
-
}
|
|
23
|
+
app.use(serviceRouter.routes());
|
|
23
24
|
}
|
|
25
|
+
}
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @param {object} option
|
|
30
|
+
* @param {string} option.rootDirectory root directory of files
|
|
31
|
+
* @param {object} option.filename an object of {name, extension}
|
|
32
|
+
* @param {string} option.filename.name name of file
|
|
33
|
+
* @param {string} option.filename.extension the extension of the file
|
|
34
|
+
* @param {boolean} option.combineWithRoot combine all file content and return theme as a object
|
|
35
|
+
* @param {boolean} option.convertToArray return file content as an array instead an object
|
|
36
|
+
*/
|
|
37
|
+
async combineModulesByFilePath({
|
|
38
|
+
rootDirectory,
|
|
39
|
+
filename,
|
|
40
|
+
combineWithRoot,
|
|
41
|
+
convertToArray,
|
|
42
|
+
}) {
|
|
43
|
+
// find route paths
|
|
44
|
+
let rootObject_temp;
|
|
45
|
+
let option = { name: filename.name, filter: [filename.extension] };
|
|
46
|
+
let modulesPath = await directory
|
|
47
|
+
.find(rootDirectory, option)
|
|
48
|
+
.then()
|
|
49
|
+
.catch((e) => {
|
|
50
|
+
console.log(e);
|
|
51
|
+
});
|
|
43
52
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
53
|
+
// create and combine routes into the app
|
|
54
|
+
for (let i = 0; i < modulesPath.length; i++) {
|
|
55
|
+
let moduleObject = require(modulesPath[i]);
|
|
47
56
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
delete moduleObject.name;
|
|
57
|
+
//act by otherOption
|
|
58
|
+
if (combineWithRoot) {
|
|
59
|
+
if (moduleObject.name) delete moduleObject.name;
|
|
52
60
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
rootObject_temp = [...rootObject_temp, ...moduleObject];
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
rootObject_temp = this.extendObj(rootObject_temp, moduleObject);
|
|
60
|
-
}
|
|
61
|
-
// else if (typeof)
|
|
62
|
-
}
|
|
63
|
-
// default act
|
|
64
|
-
else {
|
|
65
|
-
let name = moduleObject.name;
|
|
66
|
-
rootObject_temp[name] = moduleObject;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
61
|
+
if (moduleObject.length) {
|
|
62
|
+
if (!rootObject_temp) rootObject_temp = [];
|
|
69
63
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
rootObject_temp = Object.values(rootObject_temp);
|
|
64
|
+
rootObject_temp = [...rootObject_temp, ...moduleObject];
|
|
65
|
+
} else {
|
|
66
|
+
rootObject_temp = this.extendObj(rootObject_temp, moduleObject);
|
|
74
67
|
}
|
|
68
|
+
// else if (typeof)
|
|
69
|
+
}
|
|
70
|
+
// default act
|
|
71
|
+
else {
|
|
72
|
+
let name = moduleObject.name;
|
|
73
|
+
rootObject_temp[name] = moduleObject;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
75
76
|
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
// options
|
|
78
|
+
// convertToArray
|
|
79
|
+
if (convertToArray) {
|
|
80
|
+
rootObject_temp = Object.values(rootObject_temp);
|
|
78
81
|
}
|
|
79
82
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
// set result to main rootObject
|
|
84
|
+
return rootObject_temp;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
extendObj(obj, src) {
|
|
88
|
+
for (var key in src) {
|
|
89
|
+
if (src.hasOwnProperty(key)) obj[key] = src[key];
|
|
86
90
|
}
|
|
91
|
+
return obj;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
static get instance() {
|
|
95
|
+
return instance;
|
|
96
|
+
}
|
|
87
97
|
}
|
|
88
98
|
|
|
89
|
-
|
|
99
|
+
const instance = new Combinator();
|
|
100
|
+
|
|
90
101
|
module.exports = Combinator.instance;
|
|
@@ -1,15 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `DatabaseTrigger` is a class that defines a callback to be called on a specific database transaction.
|
|
3
|
+
*
|
|
4
|
+
* @class
|
|
5
|
+
*/
|
|
1
6
|
class DatabaseTrigger {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new instance of `DatabaseTrigger`.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} operation - The name of the operation on which the callback should be triggered.
|
|
11
|
+
* @param {function} [callback=(query, queryResult) => {}] - The callback function to be triggered. It accepts two parameters:
|
|
12
|
+
* 1. `query` - The query that is being executed.
|
|
13
|
+
* 2. `queryResult` - The result of the query execution.
|
|
14
|
+
*/
|
|
15
|
+
constructor(operation, callback = (query, queryResult) => {}) {
|
|
16
|
+
this.operation = operation;
|
|
17
|
+
this.callback = callback;
|
|
18
|
+
}
|
|
13
19
|
}
|
|
14
20
|
|
|
15
|
-
module.exports = DatabaseTrigger;
|
|
21
|
+
module.exports = DatabaseTrigger;
|
package/src/class/db_schemas.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
var mongoose = require(
|
|
1
|
+
var mongoose = require("mongoose");
|
|
2
2
|
var Schema = mongoose.Schema;
|
|
3
3
|
|
|
4
4
|
module.exports = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
5
|
+
file: new Schema({
|
|
6
|
+
originalName: String,
|
|
7
|
+
fileName: String,
|
|
8
|
+
owner: String,
|
|
9
|
+
format: String,
|
|
10
|
+
// Tag being used as the parent dir for files
|
|
11
|
+
// uploadDir/$format/$tag/timestamp.format
|
|
12
|
+
tag: String,
|
|
13
|
+
}),
|
|
14
|
+
};
|
package/src/class/security.js
CHANGED
|
@@ -1,44 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class representing an access definition.
|
|
3
|
+
*/
|
|
1
4
|
class AccessDefinition {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Create an access definition.
|
|
7
|
+
* @param {Object} options - The options for the access definition.
|
|
8
|
+
* @param {string} options.database - The name of the database.
|
|
9
|
+
* @param {string} options.collection - The name of the collection.
|
|
10
|
+
* @param {Array.<Permission>} options.permissionList - The list of permissions.
|
|
11
|
+
*/
|
|
12
|
+
constructor({ database, collection, permissionList }) {
|
|
13
|
+
this.database = database;
|
|
14
|
+
this.collection = collection;
|
|
15
|
+
this.permissionList = permissionList;
|
|
16
|
+
}
|
|
7
17
|
}
|
|
8
18
|
|
|
19
|
+
/**
|
|
20
|
+
* @typedef {('god_access'|'user_access'|'delete'|'upload_file_access'|'remove_file_access'|'anonymous_access')} PermissionType
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Class representing a permission.
|
|
25
|
+
*/
|
|
9
26
|
class Permission {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Create a permission.
|
|
29
|
+
* @param {Object} options - The options for the permission.
|
|
30
|
+
* @param {PermissionType} options.type - The type of the permission.
|
|
31
|
+
* @param {boolean} [options.read=false] - The read access of the permission.
|
|
32
|
+
* @param {boolean} [options.write=false] - The write access of the permission.
|
|
33
|
+
* @param {boolean} [options.onlyOwnData=false] - If true, users can perform CRUD on documents that they created already.
|
|
34
|
+
*/
|
|
35
|
+
constructor({ type, read = false, write = false, onlyOwnData = false }) {
|
|
36
|
+
this.type = type;
|
|
37
|
+
this.read = read;
|
|
38
|
+
this.write = write;
|
|
39
|
+
this.onlyOwnData = onlyOwnData;
|
|
40
|
+
}
|
|
19
41
|
}
|
|
20
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Class representing different types of permissions.
|
|
45
|
+
* Each static getter returns a string that represents a specific type of permission.
|
|
46
|
+
*/
|
|
21
47
|
class PermissionTypes {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Create permission types.
|
|
50
|
+
* Each property represents a specific type of permission.
|
|
51
|
+
*/
|
|
52
|
+
constructor() {
|
|
53
|
+
this.god_access = "god_access"; // Represents god access permission type
|
|
54
|
+
this.user_access = "user_access"; // Represents user access permission type
|
|
55
|
+
this.upload_file_access = "upload_file_access"; // Represents upload file access permission type
|
|
56
|
+
this.remove_file_access = "remove_file_access"; // Represents remove file access permission type
|
|
57
|
+
this.anonymous_access = "anonymous_access"; // Represents anonymous access permission type
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Get the string representing god access permission type.
|
|
62
|
+
* @return {string} The god access permission type.
|
|
63
|
+
*/
|
|
64
|
+
static get god_access() {
|
|
65
|
+
return "god_access";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Get the string representing user access permission type.
|
|
70
|
+
* @return {string} The user access permission type.
|
|
71
|
+
*/
|
|
72
|
+
static get user_access() {
|
|
73
|
+
return "user_access";
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Get the string representing upload file access permission type.
|
|
78
|
+
* @return {string} The upload file access permission type.
|
|
79
|
+
*/
|
|
80
|
+
static get upload_file_access() {
|
|
81
|
+
return "upload_file_access";
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Get the string representing remove file access permission type.
|
|
86
|
+
* @return {string} The remove file access permission type.
|
|
87
|
+
*/
|
|
88
|
+
static get remove_file_access() {
|
|
89
|
+
return "remove_file_access";
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Get the string representing anonymous access permission type.
|
|
94
|
+
* @return {string} The anonymous access permission type.
|
|
95
|
+
*/
|
|
96
|
+
static get anonymous_access() {
|
|
97
|
+
return "anonymous_access";
|
|
98
|
+
}
|
|
35
99
|
}
|
|
36
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Class representing access types.
|
|
103
|
+
*/
|
|
37
104
|
class AccessTypes {
|
|
38
|
-
|
|
39
|
-
|
|
105
|
+
static get read() {
|
|
106
|
+
return "read";
|
|
107
|
+
}
|
|
108
|
+
static get write() {
|
|
109
|
+
return "write";
|
|
110
|
+
}
|
|
40
111
|
}
|
|
41
112
|
|
|
42
113
|
module.exports = {
|
|
43
|
-
|
|
44
|
-
|
|
114
|
+
AccessDefinition,
|
|
115
|
+
Permission,
|
|
116
|
+
PermissionTypes,
|
|
117
|
+
AccessTypes,
|
|
118
|
+
};
|