@quatrain/core 1.0.0-beta2 → 1.0.0-beta20
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/lib/Auth.d.ts +25 -0
- package/lib/Auth.js +9 -0
- package/lib/Backend.d.ts +7 -2
- package/lib/Backend.js +1 -0
- package/lib/Core.d.ts +13 -2
- package/lib/Core.js +39 -1
- package/lib/authentication/AbstractAuthAdapter.d.ts +18 -0
- package/lib/authentication/AbstractAuthAdapter.js +23 -0
- package/lib/authentication/AuthenticationError.d.ts +2 -0
- package/lib/authentication/AuthenticationError.js +6 -0
- package/lib/authentication/index.d.ts +4 -0
- package/lib/authentication/index.js +7 -0
- package/lib/authentication/middlewares/AbstractAuthMiddleware.d.ts +0 -0
- package/lib/authentication/middlewares/AbstractAuthMiddleware.js +1 -0
- package/lib/authentication/middlewares/AuthMiddleware.d.ts +5 -0
- package/lib/authentication/types/AuthInterface.d.ts +9 -0
- package/lib/backends/AbstractAdapter.d.ts +16 -5
- package/lib/backends/AbstractAdapter.js +27 -4
- package/lib/backends/Filters.d.ts +2 -1
- package/lib/backends/Query.d.ts +9 -5
- package/lib/backends/Query.js +13 -4
- package/lib/backends/index.d.ts +2 -1
- package/lib/backends/index.js +26 -1
- package/lib/backends/middlewares/InjectKeywordsMiddleware.d.ts +2 -2
- package/lib/backends/middlewares/InjectMetaMiddleware.d.ts +7 -6
- package/lib/backends/middlewares/InjectMetaMiddleware.js +7 -4
- package/lib/backends/middlewares/Middleware.d.ts +2 -2
- package/lib/backends/middlewares/types/MiddlewareParams.d.ts +3 -0
- package/lib/backends/middlewares/types/MiddlewareParams.js +2 -0
- package/lib/backends/types/BackendInterface.d.ts +1 -1
- package/lib/backends/types/CollectionHierarchy.d.ts +3 -0
- package/lib/backends/types/CollectionHierarchy.js +6 -0
- package/lib/components/AbstractObject.d.ts +3 -1
- package/lib/components/AbstractObject.js +1 -0
- package/lib/components/BaseObject.js +1 -0
- package/lib/components/BaseObjectCore.d.ts +10 -1
- package/lib/components/BaseObjectCore.js +15 -3
- package/lib/components/BaseRepository.d.ts +1 -0
- package/lib/components/BaseRepository.js +21 -3
- package/lib/components/DataObject.d.ts +12 -2
- package/lib/components/DataObject.js +44 -7
- package/lib/components/Entity.d.ts +3 -6
- package/lib/components/Entity.js +31 -31
- package/lib/components/EntityRepository.d.ts +2 -2
- package/lib/components/EntityRepository.js +1 -1
- package/lib/components/ObjectUri.d.ts +20 -1
- package/lib/components/ObjectUri.js +44 -14
- package/lib/components/User.d.ts +3 -3
- package/lib/components/User.js +16 -9
- package/lib/components/UserRepository.d.ts +3 -3
- package/lib/components/UserRepository.js +2 -2
- package/lib/components/index.d.ts +2 -2
- package/lib/components/index.js +4 -2
- package/lib/components/types/DataObjectClass.d.ts +4 -1
- package/lib/components/types/toJSONParams.d.ts +8 -0
- package/lib/components/types/toJSONParams.js +2 -0
- package/lib/index.d.ts +14 -3
- package/lib/index.js +14 -1
- package/lib/properties/ArrayProperty.d.ts +1 -1
- package/lib/properties/ArrayProperty.js +2 -2
- package/lib/properties/BaseProperty.d.ts +4 -1
- package/lib/properties/BaseProperty.js +15 -3
- package/lib/properties/BooleanProperty.d.ts +1 -1
- package/lib/properties/BooleanProperty.js +2 -2
- package/lib/properties/CollectionProperty.d.ts +1 -1
- package/lib/properties/CollectionProperty.js +4 -3
- package/lib/properties/DateTimeProperty.d.ts +1 -1
- package/lib/properties/DateTimeProperty.js +2 -2
- package/lib/properties/EnumProperty.d.ts +1 -1
- package/lib/properties/EnumProperty.js +2 -2
- package/lib/properties/HashProperty.d.ts +1 -1
- package/lib/properties/HashProperty.js +2 -2
- package/lib/properties/MapProperty.d.ts +1 -1
- package/lib/properties/MapProperty.js +2 -2
- package/lib/properties/NumberProperty.d.ts +1 -1
- package/lib/properties/NumberProperty.js +2 -2
- package/lib/properties/ObjectProperty.d.ts +1 -1
- package/lib/properties/ObjectProperty.js +5 -6
- package/lib/properties/StringProperty.d.ts +1 -1
- package/lib/properties/StringProperty.js +2 -2
- package/lib/properties/types/AbstractPropertyType.d.ts +1 -0
- package/lib/properties/types/PropertyClassType.d.ts +3 -1
- package/lib/storages/AbstractStorageAdapter.d.ts +17 -0
- package/lib/storages/AbstractStorageAdapter.js +7 -0
- package/lib/storages/StorageAdapterInterface.d.ts +19 -0
- package/lib/storages/StorageAdapterInterface.js +2 -0
- package/lib/storages/index.d.ts +8 -0
- package/lib/storages/index.js +5 -0
- package/lib/storages/types/BlobMediaType.d.ts +8 -0
- package/lib/storages/types/BlobMediaType.js +2 -0
- package/lib/storages/types/BlobType.d.ts +6 -0
- package/lib/storages/types/BlobType.js +2 -0
- package/lib/storages/types/FileResponseLink.d.ts +7 -0
- package/lib/storages/types/FileResponseLink.js +2 -0
- package/lib/storages/types/FileResponseUrl.d.ts +4 -0
- package/lib/storages/types/FileResponseUrl.js +2 -0
- package/lib/storages/types/FileType.d.ts +15 -0
- package/lib/storages/types/FileType.js +2 -0
- package/lib/storages/types.d.ts +5 -0
- package/lib/storages/types.js +2 -0
- package/lib/utils/DataGenerator.d.ts +2 -3
- package/lib/utils/DataGenerator.js +2 -1
- package/lib/wrappers/cloud/AbstractCloudWrapper.d.ts +4 -0
- package/lib/wrappers/cloud/AbstractCloudWrapper.js +9 -0
- package/lib/wrappers/cloud/types/DatabaseTriggerType.d.ts +8 -0
- package/lib/wrappers/cloud/types/DatabaseTriggerType.js +2 -0
- package/package.json +5 -3
- package/README.md +0 -124
- package/lib/backends/BackendInterface.d.ts +0 -13
- package/lib/backends/middlewares/InjectMetaMiddleware copy.d.ts +0 -12
- package/lib/backends/middlewares/InjectMetaMiddleware copy.js +0 -30
- package/lib/components/BaseObjectProperties.d.ts +0 -13
- package/lib/components/BaseObjectProperties.js +0 -87
- package/lib/components/EntityProperties.d.ts +0 -1
- package/lib/components/EntityProperties.js +0 -54
- package/lib/components/UserProperties.d.ts +0 -1
- package/lib/components/UserProperties.js +0 -103
- package/lib/components/types/UserClass.d.ts +0 -3
- /package/lib/{backends/BackendInterface.js → authentication/middlewares/AuthMiddleware.js} +0 -0
- /package/lib/{components/types/UserClass.js → authentication/types/AuthInterface.js} +0 -0
package/lib/Auth.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import Middleware from './authentication/middlewares/AuthMiddleware';
|
|
2
|
+
export declare enum AuthAction {
|
|
3
|
+
SIGNIN = "signin",
|
|
4
|
+
SIGNUP = "signup",
|
|
5
|
+
SIGNOUT = "signout"
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Authentication Parameters acceptable keys
|
|
9
|
+
*/
|
|
10
|
+
export type AuthParametersKeys = 'host' | 'alias' | 'mapping' | 'middlewares' | 'config' | 'fixtures' | 'debug';
|
|
11
|
+
/**
|
|
12
|
+
* Backend parameters interface
|
|
13
|
+
*/
|
|
14
|
+
export interface AuthParameters {
|
|
15
|
+
host?: string;
|
|
16
|
+
alias?: string;
|
|
17
|
+
mapping?: {
|
|
18
|
+
[x: string]: any;
|
|
19
|
+
};
|
|
20
|
+
middlewares?: Middleware[];
|
|
21
|
+
config?: any;
|
|
22
|
+
fixtures?: any;
|
|
23
|
+
softDelete?: boolean;
|
|
24
|
+
debug?: boolean;
|
|
25
|
+
}
|
package/lib/Auth.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthAction = void 0;
|
|
4
|
+
var AuthAction;
|
|
5
|
+
(function (AuthAction) {
|
|
6
|
+
AuthAction["SIGNIN"] = "signin";
|
|
7
|
+
AuthAction["SIGNUP"] = "signup";
|
|
8
|
+
AuthAction["SIGNOUT"] = "signout";
|
|
9
|
+
})(AuthAction || (exports.AuthAction = AuthAction = {}));
|
package/lib/Backend.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import Middleware from
|
|
1
|
+
import Middleware from './backends/middlewares/Middleware';
|
|
2
2
|
export declare enum BackendAction {
|
|
3
3
|
CREATE = "create",
|
|
4
4
|
READ = "read",
|
|
5
5
|
UPDATE = "update",
|
|
6
|
-
DELETE = "delete"
|
|
6
|
+
DELETE = "delete",
|
|
7
|
+
WRITE = "write"
|
|
7
8
|
}
|
|
8
9
|
/**
|
|
9
10
|
* Default interface for a backend record
|
|
@@ -23,6 +24,9 @@ export type BackendParametersKeys = 'host' | 'alias' | 'mapping' | 'middlewares'
|
|
|
23
24
|
export interface BackendParameters {
|
|
24
25
|
host?: string;
|
|
25
26
|
alias?: string;
|
|
27
|
+
hierarchy?: {
|
|
28
|
+
[collection: string]: any;
|
|
29
|
+
};
|
|
26
30
|
mapping?: {
|
|
27
31
|
[x: string]: any;
|
|
28
32
|
};
|
|
@@ -30,5 +34,6 @@ export interface BackendParameters {
|
|
|
30
34
|
config?: any;
|
|
31
35
|
fixtures?: any;
|
|
32
36
|
softDelete?: boolean;
|
|
37
|
+
useNativeForeignKeys?: boolean;
|
|
33
38
|
debug?: boolean;
|
|
34
39
|
}
|
package/lib/Backend.js
CHANGED
package/lib/Core.d.ts
CHANGED
|
@@ -1,26 +1,37 @@
|
|
|
1
|
+
import { AbstractAuthAdapter } from './authentication';
|
|
1
2
|
import { AbstractAdapter } from './backends/AbstractAdapter';
|
|
2
|
-
import {
|
|
3
|
+
import { User } from './components/User';
|
|
3
4
|
import { DataObjectClass } from './components/types/DataObjectClass';
|
|
4
5
|
export type BackendRegistry<T extends AbstractAdapter> = {
|
|
5
6
|
[x: string]: T;
|
|
6
7
|
};
|
|
8
|
+
export interface AuthAdapter extends AbstractAuthAdapter {
|
|
9
|
+
}
|
|
7
10
|
export declare class Core {
|
|
11
|
+
static storagePrefix: string;
|
|
8
12
|
static defaultBackend: string;
|
|
9
|
-
static
|
|
13
|
+
static defaultStorage: string;
|
|
14
|
+
static userClass: typeof User;
|
|
10
15
|
static classRegistry: {
|
|
11
16
|
[key: string]: any;
|
|
12
17
|
};
|
|
13
18
|
static logger: Console;
|
|
19
|
+
static auth: AuthAdapter | AbstractAuthAdapter;
|
|
14
20
|
static timestamp: () => string;
|
|
15
21
|
protected static _backends: BackendRegistry<any>;
|
|
22
|
+
protected static _storages: BackendRegistry<any>;
|
|
16
23
|
static definition(key: string): {
|
|
17
24
|
manifest: {
|
|
18
25
|
type: StringConstructor;
|
|
19
26
|
mandatory: boolean;
|
|
20
27
|
};
|
|
21
28
|
};
|
|
29
|
+
static addConfig(key: string, value: any): Promise<void>;
|
|
30
|
+
static getConfig(key: string): Promise<any>;
|
|
22
31
|
static addBackend(backend: AbstractAdapter, alias: string, setDefault?: boolean): void;
|
|
23
32
|
static getBackend<T extends AbstractAdapter>(alias?: string): T;
|
|
33
|
+
static addStorage(backend: AbstractAdapter, alias: string, setDefault?: boolean): void;
|
|
34
|
+
static getStorage<T extends AbstractAdapter>(alias?: string): T;
|
|
24
35
|
static addClass(name: string, obj: any): void;
|
|
25
36
|
static getClass(name: string): any;
|
|
26
37
|
/**
|
package/lib/Core.js
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.Core = void 0;
|
|
4
13
|
const DataObject_1 = require("./components/DataObject");
|
|
5
14
|
const User_1 = require("./components/User");
|
|
15
|
+
const storage = require('node-persist');
|
|
16
|
+
storage.init( /* options ... */);
|
|
6
17
|
class Core {
|
|
7
18
|
static definition(key) {
|
|
8
19
|
return {
|
|
@@ -12,6 +23,16 @@ class Core {
|
|
|
12
23
|
},
|
|
13
24
|
};
|
|
14
25
|
}
|
|
26
|
+
static addConfig(key, value) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
yield storage.set(`${this.storagePrefix}_${key}`, value);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
static getConfig(key) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
return yield storage.get(`${this.storagePrefix}_${key}`);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
15
36
|
static addBackend(backend, alias, setDefault = false) {
|
|
16
37
|
Core._backends[alias] = backend;
|
|
17
38
|
if (setDefault) {
|
|
@@ -26,6 +47,20 @@ class Core {
|
|
|
26
47
|
throw new Error(`Unknown backend alias: '${alias}'`);
|
|
27
48
|
}
|
|
28
49
|
}
|
|
50
|
+
static addStorage(backend, alias, setDefault = false) {
|
|
51
|
+
Core._storages[alias] = backend;
|
|
52
|
+
if (setDefault) {
|
|
53
|
+
Core.defaultStorage = alias;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
static getStorage(alias = this.defaultStorage) {
|
|
57
|
+
if (this._storages[alias]) {
|
|
58
|
+
return this._storages[alias];
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
throw new Error(`Unknown storage alias: '${alias}'`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
29
64
|
static addClass(name, obj) {
|
|
30
65
|
Core.classRegistry[name] = obj;
|
|
31
66
|
}
|
|
@@ -51,10 +86,13 @@ class Core {
|
|
|
51
86
|
}
|
|
52
87
|
}
|
|
53
88
|
exports.Core = Core;
|
|
89
|
+
Core.storagePrefix = 'core';
|
|
54
90
|
Core.defaultBackend = '@default';
|
|
55
|
-
Core.
|
|
91
|
+
Core.defaultStorage = '@default';
|
|
92
|
+
Core.userClass = User_1.User;
|
|
56
93
|
Core.classRegistry = {};
|
|
57
94
|
Core.logger = console;
|
|
58
95
|
// How timestamp are formatted
|
|
59
96
|
Core.timestamp = () => new Date().toISOString();
|
|
60
97
|
Core._backends = {};
|
|
98
|
+
Core._storages = {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AuthParameters, AuthParametersKeys } from '../Auth';
|
|
2
|
+
import { User } from '../components/User';
|
|
3
|
+
import { AuthInterface } from './types/AuthInterface';
|
|
4
|
+
export declare abstract class AbstractAuthAdapter implements AuthInterface {
|
|
5
|
+
protected _alias: string;
|
|
6
|
+
protected _params: AuthParameters;
|
|
7
|
+
constructor(params?: AuthParameters);
|
|
8
|
+
setParam(key: AuthParametersKeys, value: any): void;
|
|
9
|
+
getParam(key: AuthParametersKeys): any;
|
|
10
|
+
set alias(alias: string);
|
|
11
|
+
get alias(): string;
|
|
12
|
+
abstract register(user: User): Promise<any>;
|
|
13
|
+
abstract signup(login: string, password: string): Promise<any>;
|
|
14
|
+
abstract signout(user: User): Promise<any>;
|
|
15
|
+
abstract update(user: User, updatable: any): Promise<any>;
|
|
16
|
+
abstract delete(user: User): Promise<any>;
|
|
17
|
+
abstract getAuthToken(token: string): any;
|
|
18
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractAuthAdapter = void 0;
|
|
4
|
+
class AbstractAuthAdapter {
|
|
5
|
+
constructor(params = {}) {
|
|
6
|
+
this._alias = '';
|
|
7
|
+
this._params = {};
|
|
8
|
+
this._alias = params.alias || '';
|
|
9
|
+
}
|
|
10
|
+
setParam(key, value) {
|
|
11
|
+
this._params[key] = value;
|
|
12
|
+
}
|
|
13
|
+
getParam(key) {
|
|
14
|
+
return this._params[key];
|
|
15
|
+
}
|
|
16
|
+
set alias(alias) {
|
|
17
|
+
this._alias = alias;
|
|
18
|
+
}
|
|
19
|
+
get alias() {
|
|
20
|
+
return this._alias;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.AbstractAuthAdapter = AbstractAuthAdapter;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthenticationError = exports.AbstractAuthAdapter = void 0;
|
|
4
|
+
const AbstractAuthAdapter_1 = require("./AbstractAuthAdapter");
|
|
5
|
+
Object.defineProperty(exports, "AbstractAuthAdapter", { enumerable: true, get: function () { return AbstractAuthAdapter_1.AbstractAuthAdapter; } });
|
|
6
|
+
const AuthenticationError_1 = require("./AuthenticationError");
|
|
7
|
+
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return AuthenticationError_1.AuthenticationError; } });
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { User } from '../../components/User';
|
|
2
|
+
export interface AuthInterface {
|
|
3
|
+
register(user: User): Promise<any>;
|
|
4
|
+
signup(login: string, password: string): Promise<any>;
|
|
5
|
+
signout(user: User): Promise<any>;
|
|
6
|
+
update(user: User, updatable: any): Promise<any>;
|
|
7
|
+
delete(user: User): Promise<any>;
|
|
8
|
+
getAuthToken(token: string): any;
|
|
9
|
+
}
|
|
@@ -5,15 +5,25 @@ import { Filter } from './Filter';
|
|
|
5
5
|
import { Filters } from './Filters';
|
|
6
6
|
import { Query, QueryResultType } from './Query';
|
|
7
7
|
import { SortAndLimit } from './SortAndLimit';
|
|
8
|
-
import
|
|
8
|
+
import BackendMiddleware from './middlewares/Middleware';
|
|
9
|
+
import { MiddlewareParams } from './middlewares/types/MiddlewareParams';
|
|
10
|
+
interface BM extends BackendMiddleware {
|
|
11
|
+
}
|
|
9
12
|
export declare abstract class AbstractAdapter implements BackendInterface {
|
|
13
|
+
static PKEY_IDENTIFIER: any;
|
|
10
14
|
protected _alias: string;
|
|
11
15
|
protected _params: BackendParameters;
|
|
12
|
-
protected _middlewares:
|
|
16
|
+
protected _middlewares: BM[];
|
|
13
17
|
constructor(params?: BackendParameters);
|
|
14
18
|
setParam(key: BackendParametersKeys, value: any): void;
|
|
15
19
|
getParam(key: BackendParametersKeys): any;
|
|
16
|
-
addMiddleware(middleware:
|
|
20
|
+
addMiddleware(middleware: BM): void;
|
|
21
|
+
/**
|
|
22
|
+
* Returns true if a given middleware is attached
|
|
23
|
+
* @param className
|
|
24
|
+
* @returns boolean
|
|
25
|
+
*/
|
|
26
|
+
hasMiddleware(className: string): boolean;
|
|
17
27
|
set alias(alias: string);
|
|
18
28
|
get alias(): string;
|
|
19
29
|
getCollection(dao: DataObjectClass<any>): string | undefined;
|
|
@@ -28,7 +38,8 @@ export declare abstract class AbstractAdapter implements BackendInterface {
|
|
|
28
38
|
* @returns Array
|
|
29
39
|
*/
|
|
30
40
|
query(query: Query<any>): Promise<QueryResultType<DataObjectClass<any>>>;
|
|
31
|
-
abstract find(dataObject: DataObjectClass<any>, filters: Filters | Filter[] | undefined, pagination: SortAndLimit | undefined): Promise<QueryResultType<any>>;
|
|
41
|
+
abstract find(dataObject: DataObjectClass<any>, filters: Filters | Filter[] | undefined, pagination: SortAndLimit | undefined, parent: any): Promise<QueryResultType<any>>;
|
|
32
42
|
log(message: string): void;
|
|
33
|
-
executeMiddlewares(dataObject: DataObjectClass<any>, action: BackendAction): Promise<DataObjectClass<any>>;
|
|
43
|
+
executeMiddlewares(dataObject: DataObjectClass<any>, action: BackendAction, params?: MiddlewareParams): Promise<DataObjectClass<any>>;
|
|
34
44
|
}
|
|
45
|
+
export {};
|
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.AbstractAdapter = void 0;
|
|
13
|
+
const BackendError_1 = require("./BackendError");
|
|
13
14
|
class AbstractAdapter {
|
|
14
15
|
constructor(params = {}) {
|
|
15
16
|
this._alias = '';
|
|
@@ -17,6 +18,7 @@ class AbstractAdapter {
|
|
|
17
18
|
this._middlewares = [];
|
|
18
19
|
this._alias = params.alias || '';
|
|
19
20
|
this._middlewares = params.middlewares || [];
|
|
21
|
+
this._params = params;
|
|
20
22
|
}
|
|
21
23
|
setParam(key, value) {
|
|
22
24
|
this._params[key] = value;
|
|
@@ -25,8 +27,25 @@ class AbstractAdapter {
|
|
|
25
27
|
return this._params[key];
|
|
26
28
|
}
|
|
27
29
|
addMiddleware(middleware) {
|
|
30
|
+
if (this.hasMiddleware(middleware.constructor.name)) {
|
|
31
|
+
throw new BackendError_1.BackendError(`Middleware '${middleware.constructor.name}' is already attached`);
|
|
32
|
+
}
|
|
28
33
|
this._middlewares.push(middleware);
|
|
29
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Returns true if a given middleware is attached
|
|
37
|
+
* @param className
|
|
38
|
+
* @returns boolean
|
|
39
|
+
*/
|
|
40
|
+
hasMiddleware(className) {
|
|
41
|
+
let has = false;
|
|
42
|
+
this._middlewares.forEach((middleware) => {
|
|
43
|
+
if (middleware.constructor.name === className) {
|
|
44
|
+
has = true;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return has;
|
|
48
|
+
}
|
|
30
49
|
set alias(alias) {
|
|
31
50
|
this._alias = alias;
|
|
32
51
|
}
|
|
@@ -34,7 +53,7 @@ class AbstractAdapter {
|
|
|
34
53
|
return this._alias;
|
|
35
54
|
}
|
|
36
55
|
getCollection(dao) {
|
|
37
|
-
return dao.uri.collection;
|
|
56
|
+
return dao.uri.collection;
|
|
38
57
|
}
|
|
39
58
|
/**
|
|
40
59
|
* Process Query instance and return result
|
|
@@ -43,7 +62,10 @@ class AbstractAdapter {
|
|
|
43
62
|
*/
|
|
44
63
|
query(query) {
|
|
45
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
|
|
65
|
+
const dao = yield query.obj.daoFactory();
|
|
66
|
+
if (query.parent) {
|
|
67
|
+
}
|
|
68
|
+
return yield this.find(dao, query.filters, query.sortAndLimit, query.parent);
|
|
47
69
|
});
|
|
48
70
|
}
|
|
49
71
|
log(message) {
|
|
@@ -51,13 +73,14 @@ class AbstractAdapter {
|
|
|
51
73
|
console.log(message);
|
|
52
74
|
}
|
|
53
75
|
}
|
|
54
|
-
executeMiddlewares(dataObject, action) {
|
|
76
|
+
executeMiddlewares(dataObject, action, params) {
|
|
55
77
|
return __awaiter(this, void 0, void 0, function* () {
|
|
56
78
|
for (const middleware of this._middlewares) {
|
|
57
|
-
yield middleware.execute(dataObject, action);
|
|
79
|
+
yield middleware.execute(dataObject, action, params);
|
|
58
80
|
}
|
|
59
81
|
return dataObject;
|
|
60
82
|
});
|
|
61
83
|
}
|
|
62
84
|
}
|
|
63
85
|
exports.AbstractAdapter = AbstractAdapter;
|
|
86
|
+
AbstractAdapter.PKEY_IDENTIFIER = 'id';
|
|
@@ -2,9 +2,10 @@ import { Filter } from './Filter';
|
|
|
2
2
|
export interface FiltersType {
|
|
3
3
|
or?: Filter[];
|
|
4
4
|
and?: Filter[];
|
|
5
|
+
base?: string;
|
|
5
6
|
}
|
|
6
7
|
export declare class Filters implements FiltersType {
|
|
7
8
|
or?: Filter[];
|
|
8
9
|
and?: Filter[];
|
|
9
|
-
constructor(or
|
|
10
|
+
constructor(or?: Filter[], and?: Filter[]);
|
|
10
11
|
}
|
package/lib/backends/Query.d.ts
CHANGED
|
@@ -28,16 +28,20 @@ export declare enum returnAs {
|
|
|
28
28
|
}
|
|
29
29
|
export declare class Query<T extends typeof BaseObjectCore> {
|
|
30
30
|
protected _obj: T;
|
|
31
|
-
protected
|
|
31
|
+
protected _parent: T | undefined;
|
|
32
32
|
filters: Filter[];
|
|
33
33
|
sortings: Sorting[];
|
|
34
34
|
limits: Limits;
|
|
35
35
|
meta: any;
|
|
36
|
-
constructor(obj: T,
|
|
37
|
-
[x: string]: any;
|
|
38
|
-
});
|
|
36
|
+
constructor(obj: T, parent?: T);
|
|
39
37
|
get obj(): T;
|
|
40
|
-
|
|
38
|
+
get parent(): T | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Declare query parent record
|
|
41
|
+
* This may be need in some NoSQL backend to query subcollections
|
|
42
|
+
*/
|
|
43
|
+
set parent(parent: T | undefined);
|
|
44
|
+
where(param: Filter | string | any, value?: any, operator?: any): this;
|
|
41
45
|
sortBy(param: Sorting | string, order?: any): this;
|
|
42
46
|
setLimits(limits: Limits): this;
|
|
43
47
|
offset(offset?: number): this;
|
package/lib/backends/Query.js
CHANGED
|
@@ -26,9 +26,9 @@ var returnAs;
|
|
|
26
26
|
returnAs["AS_IS"] = "asIs";
|
|
27
27
|
})(returnAs || (exports.returnAs = returnAs = {}));
|
|
28
28
|
class Query {
|
|
29
|
-
constructor(obj,
|
|
29
|
+
constructor(obj, parent) {
|
|
30
30
|
this._obj = obj;
|
|
31
|
-
this.
|
|
31
|
+
this._parent = parent;
|
|
32
32
|
this.filters = [];
|
|
33
33
|
this.sortings = [];
|
|
34
34
|
this.limits = new Limits_1.Limits();
|
|
@@ -37,8 +37,17 @@ class Query {
|
|
|
37
37
|
get obj() {
|
|
38
38
|
return this._obj;
|
|
39
39
|
}
|
|
40
|
+
get parent() {
|
|
41
|
+
return this._parent;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Declare query parent record
|
|
45
|
+
* This may be need in some NoSQL backend to query subcollections
|
|
46
|
+
*/
|
|
47
|
+
set parent(parent) {
|
|
48
|
+
this._parent = parent;
|
|
49
|
+
}
|
|
40
50
|
where(param, value = null, operator = 'equals') {
|
|
41
|
-
console.log(`received value`, value);
|
|
42
51
|
if (typeof param == 'object') {
|
|
43
52
|
this.filters.push(param);
|
|
44
53
|
}
|
|
@@ -96,7 +105,7 @@ class Query {
|
|
|
96
105
|
return { items: instances, meta };
|
|
97
106
|
});
|
|
98
107
|
}
|
|
99
|
-
execute(as = returnAs.AS_DATAOBJECTS, backend = Core_1.Core.getBackend()) {
|
|
108
|
+
execute(as = returnAs.AS_DATAOBJECTS, backend = Core_1.Core.getBackend(this._obj.DEFAULT_BACKEND)) {
|
|
100
109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
101
110
|
//<DataObjectClass<any>[] | ObjectUri[] | Persisted<BaseObject>[]> {
|
|
102
111
|
//</any><Array<T2> | Array<DataObject> | Array<ObjectUri>> {
|
package/lib/backends/index.d.ts
CHANGED
|
@@ -2,10 +2,11 @@ import { AbstractAdapter } from './AbstractAdapter';
|
|
|
2
2
|
import { MockAdapter } from './MockAdapter';
|
|
3
3
|
import { BackendError } from './BackendError';
|
|
4
4
|
import { BackendInterface } from './types/BackendInterface';
|
|
5
|
+
import * as CollectionHierarchy from './types/CollectionHierarchy';
|
|
5
6
|
import { Query, QueryResultType, QueryMetaType } from './Query';
|
|
6
7
|
import { Filter } from './Filter';
|
|
7
8
|
import { Filters } from './Filters';
|
|
8
9
|
import { Sorting } from './Sorting';
|
|
9
10
|
import { Limits } from './Limits';
|
|
10
11
|
import { SortAndLimit } from './SortAndLimit';
|
|
11
|
-
export { BackendInterface, AbstractAdapter, BackendError, MockAdapter, Query, QueryResultType, QueryMetaType, Filter, Filters, Sorting, Limits, SortAndLimit, };
|
|
12
|
+
export { BackendInterface, AbstractAdapter, BackendError, MockAdapter, Query, QueryResultType, QueryMetaType, Filter, Filters, Sorting, Limits, SortAndLimit, CollectionHierarchy, };
|
package/lib/backends/index.js
CHANGED
|
@@ -1,12 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SortAndLimit = exports.Limits = exports.Sorting = exports.Filters = exports.Filter = exports.Query = exports.MockAdapter = exports.BackendError = exports.AbstractAdapter = void 0;
|
|
26
|
+
exports.CollectionHierarchy = exports.SortAndLimit = exports.Limits = exports.Sorting = exports.Filters = exports.Filter = exports.Query = exports.MockAdapter = exports.BackendError = exports.AbstractAdapter = void 0;
|
|
4
27
|
const AbstractAdapter_1 = require("./AbstractAdapter");
|
|
5
28
|
Object.defineProperty(exports, "AbstractAdapter", { enumerable: true, get: function () { return AbstractAdapter_1.AbstractAdapter; } });
|
|
6
29
|
const MockAdapter_1 = require("./MockAdapter");
|
|
7
30
|
Object.defineProperty(exports, "MockAdapter", { enumerable: true, get: function () { return MockAdapter_1.MockAdapter; } });
|
|
8
31
|
const BackendError_1 = require("./BackendError");
|
|
9
32
|
Object.defineProperty(exports, "BackendError", { enumerable: true, get: function () { return BackendError_1.BackendError; } });
|
|
33
|
+
const CollectionHierarchy = __importStar(require("./types/CollectionHierarchy"));
|
|
34
|
+
exports.CollectionHierarchy = CollectionHierarchy;
|
|
10
35
|
const Query_1 = require("./Query");
|
|
11
36
|
Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return Query_1.Query; } });
|
|
12
37
|
const Filter_1 = require("./Filter");
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { DataObjectClass } from '../../components';
|
|
2
2
|
import { BackendAction } from '../../Backend';
|
|
3
|
-
import
|
|
3
|
+
import BackendMiddleware from './Middleware';
|
|
4
4
|
export interface InjectKeywordsMiddlewareParams {
|
|
5
5
|
}
|
|
6
|
-
export declare class InjectKeywordsMiddleware implements
|
|
6
|
+
export declare class InjectKeywordsMiddleware implements BackendMiddleware {
|
|
7
7
|
execute(dataObject: DataObjectClass<any>, action: BackendAction): void;
|
|
8
8
|
protected _createKeywords(dataObject: DataObjectClass<any>): string[];
|
|
9
9
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { DataObjectClass } from '../../components';
|
|
2
2
|
import { BackendAction } from '../../Backend';
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
3
|
+
import { User } from '../../components/User';
|
|
4
|
+
import BackendMiddleware from './Middleware';
|
|
5
|
+
import { MiddlewareParams } from './types/MiddlewareParams';
|
|
5
6
|
export interface InjectMetaMiddlewareParams {
|
|
6
|
-
user:
|
|
7
|
+
user: User;
|
|
7
8
|
}
|
|
8
|
-
export declare class InjectMetaMiddleware implements
|
|
9
|
-
protected _user:
|
|
9
|
+
export declare class InjectMetaMiddleware implements BackendMiddleware {
|
|
10
|
+
protected _user: User;
|
|
10
11
|
constructor(params: InjectMetaMiddlewareParams);
|
|
11
|
-
execute(dataObject: DataObjectClass<any>, action: BackendAction): void;
|
|
12
|
+
execute(dataObject: DataObjectClass<any>, action: BackendAction, params?: MiddlewareParams): void;
|
|
12
13
|
}
|
|
@@ -2,24 +2,27 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InjectMetaMiddleware = void 0;
|
|
4
4
|
const Backend_1 = require("../../Backend");
|
|
5
|
+
const Core_1 = require("../../Core");
|
|
5
6
|
class InjectMetaMiddleware {
|
|
6
7
|
constructor(params) {
|
|
7
8
|
this._user = params.user;
|
|
8
9
|
}
|
|
9
|
-
execute(dataObject, action) {
|
|
10
|
+
execute(dataObject, action, params) {
|
|
11
|
+
Core_1.Core.log(`[MDW] Executing Middleware ${this.constructor.name}`);
|
|
12
|
+
const date = params && params.useDateFormat ? (new Date()).toISOString() : Date.now();
|
|
10
13
|
switch (action) {
|
|
11
14
|
// add properties existence validation
|
|
12
15
|
case Backend_1.BackendAction.CREATE:
|
|
13
16
|
dataObject.set('createdBy', this._user);
|
|
14
|
-
dataObject.set('createdAt',
|
|
17
|
+
dataObject.set('createdAt', date);
|
|
15
18
|
break;
|
|
16
19
|
case Backend_1.BackendAction.UPDATE:
|
|
17
20
|
dataObject.set('updatedBy', this._user);
|
|
18
|
-
dataObject.set('updatedAt',
|
|
21
|
+
dataObject.set('updatedAt', date);
|
|
19
22
|
break;
|
|
20
23
|
case Backend_1.BackendAction.DELETE:
|
|
21
24
|
dataObject.set('deletedBy', this._user);
|
|
22
|
-
dataObject.set('deletedAt',
|
|
25
|
+
dataObject.set('deletedAt', date);
|
|
23
26
|
break;
|
|
24
27
|
default:
|
|
25
28
|
break;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BackendAction } from '../../Backend';
|
|
2
2
|
import { DataObjectClass } from '../../components';
|
|
3
|
-
export default interface
|
|
4
|
-
execute: (dataObject: DataObjectClass<any>, action: BackendAction) => void;
|
|
3
|
+
export default interface BackendMiddleware {
|
|
4
|
+
execute: (dataObject: DataObjectClass<any>, action: BackendAction, params?: any) => void;
|
|
5
5
|
}
|
|
@@ -9,5 +9,5 @@ export interface BackendInterface {
|
|
|
9
9
|
update(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
10
10
|
delete(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
11
11
|
query(query: Query<any>): Promise<QueryResultType<DataObjectClass<any>>>;
|
|
12
|
-
find(dataObject: DataObjectClass<any>, filters: Filters | Filter[] | undefined, pagination: SortAndLimit | undefined): Promise<QueryResultType<DataObjectClass<any>>>;
|
|
12
|
+
find(dataObject: DataObjectClass<any>, filters: Filters | Filter[] | undefined, pagination: SortAndLimit | undefined, parent: any): Promise<QueryResultType<DataObjectClass<any>>>;
|
|
13
13
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { DataObjectClass } from './types/DataObjectClass';
|
|
2
|
-
import { DataObjectProperties } from '../properties
|
|
2
|
+
import { DataObjectProperties } from '../properties';
|
|
3
3
|
export declare abstract class AbstractObject {
|
|
4
4
|
static PROPS_DEFINITION: DataObjectProperties;
|
|
5
5
|
static COLLECTION: string | undefined;
|
|
6
|
+
static PARENT_PROP: string | undefined;
|
|
7
|
+
static DEFAULT_BACKEND: string;
|
|
6
8
|
static LABEL_KEY: string;
|
|
7
9
|
protected _dataObject: DataObjectClass<any>;
|
|
8
10
|
constructor(dao: DataObjectClass<any>);
|