@quatrain/core 0.2.0 → 0.4.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/lib/Backend.d.ts +5 -0
- package/lib/Backend.js +7 -0
- package/lib/Core.d.ts +23 -3
- package/lib/Core.js +24 -5
- package/lib/backends/AbstractAdapter.d.ts +29 -13
- package/lib/backends/AbstractAdapter.js +31 -3
- package/lib/backends/Filter.d.ts +5 -3
- package/lib/backends/Filter.js +1 -1
- package/lib/backends/MockAdapter.d.ts +11 -12
- package/lib/backends/MockAdapter.js +126 -35
- package/lib/backends/NotFoundError.d.ts +2 -0
- package/lib/backends/NotFoundError.js +6 -0
- package/lib/backends/Query.d.ts +11 -3
- package/lib/backends/Query.js +30 -4
- package/lib/backends/middlewares/AbstractMiddleware.d.ts +0 -0
- package/lib/backends/middlewares/AbstractMiddleware.js +1 -0
- package/lib/backends/middlewares/InjectMetaMiddleware.d.ts +11 -0
- package/lib/backends/middlewares/InjectMetaMiddleware.js +50 -0
- package/lib/components/AbstractObject.d.ts +13 -10
- package/lib/components/AbstractObject.js +11 -2
- package/lib/components/BaseObject.d.ts +10 -11
- package/lib/components/BaseObject.js +42 -33
- package/lib/components/BaseObjectProperties.d.ts +6 -8
- package/lib/components/BaseObjectProperties.js +14 -9
- package/lib/components/DataObject.d.ts +25 -18
- package/lib/components/DataObject.js +63 -33
- package/lib/components/Entity.d.ts +6 -0
- package/lib/components/Entity.js +26 -0
- package/lib/components/EntityProperties.d.ts +1 -0
- package/lib/components/EntityProperties.js +47 -0
- package/lib/components/ObjectUri.d.ts +5 -2
- package/lib/components/ObjectUri.js +23 -8
- package/lib/components/User.d.ts +6 -4
- package/lib/components/User.js +78 -8
- package/lib/components/UserProperties.d.ts +1 -0
- package/lib/components/UserProperties.js +103 -0
- package/lib/components/index.d.ts +6 -3
- package/lib/components/index.js +5 -2
- package/lib/components/types/AbstractObjectClass.d.ts +6 -0
- package/lib/components/types/AbstractObjectClass.js +2 -0
- package/lib/components/types/BaseObjectClass.d.ts +6 -0
- package/lib/components/types/BaseObjectClass.js +2 -0
- package/lib/components/types/DataObjectClass.d.ts +23 -0
- package/lib/components/types/DataObjectClass.js +2 -0
- package/lib/components/types/EntityClass.d.ts +3 -0
- package/lib/components/types/EntityClass.js +2 -0
- package/lib/components/types/UserClass.d.ts +3 -0
- package/lib/components/types/UserClass.js +2 -0
- package/lib/index.d.ts +5 -1
- package/lib/index.js +7 -1
- package/lib/properties/ArrayProperty.d.ts +1 -0
- package/lib/properties/ArrayProperty.js +6 -5
- package/lib/properties/BaseProperty.d.ts +10 -4
- package/lib/properties/BaseProperty.js +11 -1
- package/lib/properties/BooleanProperty.d.ts +2 -1
- package/lib/properties/BooleanProperty.js +3 -2
- package/lib/properties/CollectionProperty.d.ts +32 -0
- package/lib/properties/CollectionProperty.js +63 -0
- package/lib/properties/DateTimeProperty.d.ts +1 -0
- package/lib/properties/DateTimeProperty.js +1 -0
- package/lib/properties/EnumProperty.d.ts +2 -0
- package/lib/properties/EnumProperty.js +5 -1
- package/lib/properties/HashProperty.d.ts +1 -0
- package/lib/properties/HashProperty.js +1 -0
- package/lib/properties/MapProperty.d.ts +8 -0
- package/lib/properties/MapProperty.js +17 -0
- package/lib/properties/NumberProperty.d.ts +1 -0
- package/lib/properties/NumberProperty.js +1 -0
- package/lib/properties/ObjectProperty.d.ts +4 -7
- package/lib/properties/ObjectProperty.js +4 -1
- package/lib/properties/Property.d.ts +3 -7
- package/lib/properties/Property.js +13 -15
- package/lib/properties/StringProperty.d.ts +10 -0
- package/lib/properties/StringProperty.js +42 -21
- package/lib/properties/index.d.ts +4 -2
- package/lib/properties/index.js +5 -1
- package/lib/properties/types/PropertyClassType.d.ts +4 -2
- package/lib/properties/types/PropertyHTMLType.d.ts +10 -0
- package/lib/properties/types/PropertyHTMLType.js +14 -0
- package/lib/properties/types/PropertyTypes.d.ts +4 -1
- package/lib/utils/DataGenerator.d.ts +9 -0
- package/lib/utils/DataGenerator.js +98 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +5 -0
- package/package.json +3 -1
package/lib/Backend.d.ts
ADDED
package/lib/Backend.js
ADDED
package/lib/Core.d.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import { AbstractAdapter } from './backends';
|
|
1
|
+
import { AbstractAdapter } from './backends/AbstractAdapter';
|
|
2
|
+
import { DataObjectClass } from './components/types/DataObjectClass';
|
|
3
|
+
import { UserClass } from './components/types/UserClass';
|
|
2
4
|
export declare type BackendRegistry<T extends AbstractAdapter> = {
|
|
3
5
|
[x: string]: T;
|
|
4
6
|
};
|
|
5
7
|
export declare class Core {
|
|
6
8
|
static defaultBackend: string;
|
|
9
|
+
static currentUser: UserClass;
|
|
10
|
+
static logger: {
|
|
11
|
+
(...data: any[]): void;
|
|
12
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
13
|
+
};
|
|
7
14
|
protected static _backends: BackendRegistry<any>;
|
|
8
15
|
static definition(key: string): {
|
|
9
16
|
manifest: {
|
|
@@ -11,6 +18,19 @@ export declare class Core {
|
|
|
11
18
|
mandatory: boolean;
|
|
12
19
|
};
|
|
13
20
|
};
|
|
14
|
-
static addBackend(backend: AbstractAdapter, alias: string): void;
|
|
15
|
-
static getBackend(alias?: string):
|
|
21
|
+
static addBackend(backend: AbstractAdapter, alias: string, setDefault?: boolean): void;
|
|
22
|
+
static getBackend<T extends AbstractAdapter>(alias?: string): T;
|
|
23
|
+
/**
|
|
24
|
+
* Returns the class to use for a data object
|
|
25
|
+
* This is currently just a stub that will be implemented from config in the future
|
|
26
|
+
* @returns DataObjectClass
|
|
27
|
+
*/
|
|
28
|
+
static getDataObjectClass(): DataObjectClass<any>;
|
|
29
|
+
/**
|
|
30
|
+
* Log message using defined logger
|
|
31
|
+
* This is currently just a stub that will be implemented from config in the future
|
|
32
|
+
* @param message string
|
|
33
|
+
* @param level string
|
|
34
|
+
*/
|
|
35
|
+
static log(message: string, src?: string, level?: string): void;
|
|
16
36
|
}
|
package/lib/Core.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Core = void 0;
|
|
4
|
-
const
|
|
4
|
+
const DataObject_1 = require("./components/DataObject");
|
|
5
5
|
class Core {
|
|
6
6
|
static definition(key) {
|
|
7
7
|
return {
|
|
@@ -11,8 +11,11 @@ class Core {
|
|
|
11
11
|
},
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
-
static addBackend(backend, alias) {
|
|
14
|
+
static addBackend(backend, alias, setDefault = false) {
|
|
15
15
|
Core._backends[alias] = backend;
|
|
16
|
+
if (setDefault) {
|
|
17
|
+
Core.defaultBackend = alias;
|
|
18
|
+
}
|
|
16
19
|
}
|
|
17
20
|
static getBackend(alias = this.defaultBackend) {
|
|
18
21
|
if (this._backends[alias]) {
|
|
@@ -22,9 +25,25 @@ class Core {
|
|
|
22
25
|
throw new Error(`Unknown backend alias: '${alias}'`);
|
|
23
26
|
}
|
|
24
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns the class to use for a data object
|
|
30
|
+
* This is currently just a stub that will be implemented from config in the future
|
|
31
|
+
* @returns DataObjectClass
|
|
32
|
+
*/
|
|
33
|
+
static getDataObjectClass() {
|
|
34
|
+
return DataObject_1.DataObject.prototype;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Log message using defined logger
|
|
38
|
+
* This is currently just a stub that will be implemented from config in the future
|
|
39
|
+
* @param message string
|
|
40
|
+
* @param level string
|
|
41
|
+
*/
|
|
42
|
+
static log(message, src = 'Core', level = 'NOTICE') {
|
|
43
|
+
Core.logger(`[${src}] ${message}`, level);
|
|
44
|
+
}
|
|
25
45
|
}
|
|
26
46
|
exports.Core = Core;
|
|
27
47
|
Core.defaultBackend = '@default';
|
|
28
|
-
Core.
|
|
29
|
-
|
|
30
|
-
};
|
|
48
|
+
Core.logger = console.log;
|
|
49
|
+
Core._backends = {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DataObjectClass } from '../components/types/DataObjectClass';
|
|
2
2
|
import { Filter } from './Filter';
|
|
3
3
|
import { Filters } from './Filters';
|
|
4
4
|
import { Query } from './Query';
|
|
@@ -8,42 +8,58 @@ import { SortAndLimit } from './SortAndLimit';
|
|
|
8
8
|
*/
|
|
9
9
|
export interface BackendRecordType {
|
|
10
10
|
uid: string | undefined;
|
|
11
|
-
|
|
11
|
+
path: string | undefined;
|
|
12
|
+
[key: string]: any;
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
14
15
|
* Backend Parameters acceptable keys
|
|
15
16
|
*/
|
|
16
|
-
export declare type BackendParametersKeys = 'alias' | 'mapping' | '
|
|
17
|
+
export declare type BackendParametersKeys = 'host' | 'alias' | 'mapping' | 'middlewares' | 'config' | 'fixtures' | 'softDelete' | 'debug';
|
|
17
18
|
/**
|
|
18
19
|
* Backend parameters interface
|
|
19
20
|
*/
|
|
20
21
|
export interface BackendParameters {
|
|
22
|
+
host?: string;
|
|
21
23
|
alias?: string;
|
|
22
24
|
mapping?: {
|
|
23
25
|
[x: string]: any;
|
|
24
26
|
};
|
|
25
|
-
|
|
27
|
+
middlewares?: any[];
|
|
26
28
|
config?: any;
|
|
27
29
|
fixtures?: any;
|
|
28
30
|
softDelete?: boolean;
|
|
29
31
|
debug?: boolean;
|
|
30
32
|
}
|
|
31
|
-
export interface BackendInterface
|
|
32
|
-
create(dataObject:
|
|
33
|
-
read(param: string |
|
|
34
|
-
update(dataObject:
|
|
35
|
-
delete(dataObject:
|
|
36
|
-
query(query: Query<
|
|
37
|
-
find(dataObject:
|
|
33
|
+
export interface BackendInterface {
|
|
34
|
+
create(dataObject: DataObjectClass<any>, desiredUid: string | undefined): Promise<DataObjectClass<any>>;
|
|
35
|
+
read(param: string | DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
36
|
+
update(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
37
|
+
delete(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
38
|
+
query(query: Query<any>): Promise<DataObjectClass<any>[]>;
|
|
39
|
+
find(dataObject: DataObjectClass<any>, filters: Filters | Filter[] | undefined, pagination: SortAndLimit | undefined): Promise<DataObjectClass<any>[]>;
|
|
38
40
|
}
|
|
39
41
|
export declare abstract class AbstractAdapter {
|
|
40
42
|
protected _alias: string;
|
|
41
43
|
protected _params: BackendParameters;
|
|
42
|
-
protected
|
|
43
|
-
constructor(params
|
|
44
|
+
protected _middlewares: any[];
|
|
45
|
+
constructor(params?: BackendParameters);
|
|
44
46
|
setParam(key: BackendParametersKeys, value: any): void;
|
|
45
47
|
getParam(key: BackendParametersKeys): any;
|
|
46
48
|
set alias(alias: string);
|
|
47
49
|
get alias(): string;
|
|
50
|
+
getCollection(dao: DataObjectClass<any>): any;
|
|
51
|
+
abstract create(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
52
|
+
abstract read(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
53
|
+
abstract update(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
54
|
+
abstract delete(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
55
|
+
abstract deleteCollection(collection: string, batchSize?: number): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Process Query instance and return result
|
|
58
|
+
* @param query
|
|
59
|
+
* @returns Array
|
|
60
|
+
*/
|
|
61
|
+
query(query: Query<any>): Promise<DataObjectClass<any>[]>;
|
|
62
|
+
abstract find(dataObject: DataObjectClass<any>, filters: Filters | Filter[] | undefined, pagination: SortAndLimit | undefined): Promise<DataObjectClass<any>[]>;
|
|
48
63
|
log(message: string): void;
|
|
64
|
+
executeMiddlewares(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
49
65
|
}
|
|
@@ -1,13 +1,22 @@
|
|
|
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.AbstractAdapter = void 0;
|
|
4
13
|
class AbstractAdapter {
|
|
5
|
-
constructor(params) {
|
|
14
|
+
constructor(params = {}) {
|
|
6
15
|
this._alias = '';
|
|
7
16
|
this._params = {};
|
|
8
|
-
this.
|
|
17
|
+
this._middlewares = [];
|
|
9
18
|
this._alias = params.alias || '';
|
|
10
|
-
this.
|
|
19
|
+
this._middlewares = params.middlewares || [];
|
|
11
20
|
}
|
|
12
21
|
setParam(key, value) {
|
|
13
22
|
this._params[key] = value;
|
|
@@ -21,10 +30,29 @@ class AbstractAdapter {
|
|
|
21
30
|
get alias() {
|
|
22
31
|
return this._alias;
|
|
23
32
|
}
|
|
33
|
+
getCollection(dao) {
|
|
34
|
+
return dao.uri.class.name.toLowerCase();
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Process Query instance and return result
|
|
38
|
+
* @param query
|
|
39
|
+
* @returns Array
|
|
40
|
+
*/
|
|
41
|
+
query(query) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
return this.find(yield query.obj.daoFactory(), query.filters, query.sortAndLimit);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
24
46
|
log(message) {
|
|
25
47
|
if (this._params['debug'] === true) {
|
|
26
48
|
console.log(message);
|
|
27
49
|
}
|
|
28
50
|
}
|
|
51
|
+
executeMiddlewares(dataObject) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
this._middlewares.forEach((middleware) => __awaiter(this, void 0, void 0, function* () { return yield middleware.execute(dataObject); }));
|
|
54
|
+
return dataObject;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
29
57
|
}
|
|
30
58
|
exports.AbstractAdapter = AbstractAdapter;
|
package/lib/backends/Filter.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { BaseObject } from '../components';
|
|
1
2
|
import { FilterOperatorType } from './FilterOperators';
|
|
3
|
+
export declare type FilterValueType<T extends BaseObject> = T | number | string | string[] | null;
|
|
2
4
|
export interface FilterType {
|
|
3
5
|
prop: string;
|
|
4
6
|
operator: FilterOperatorType | undefined;
|
|
5
|
-
value:
|
|
7
|
+
value: FilterValueType<any>;
|
|
6
8
|
}
|
|
7
9
|
/**
|
|
8
10
|
* Filter object
|
|
@@ -10,6 +12,6 @@ export interface FilterType {
|
|
|
10
12
|
export declare class Filter implements FilterType {
|
|
11
13
|
prop: string;
|
|
12
14
|
operator: FilterOperatorType;
|
|
13
|
-
value:
|
|
14
|
-
constructor(prop: string, value
|
|
15
|
+
value: FilterValueType<any>;
|
|
16
|
+
constructor(prop: string, value: FilterValueType<any>, operator?: FilterOperatorType);
|
|
15
17
|
}
|
package/lib/backends/Filter.js
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
import { AbstractAdapter, BackendInterface } from './';
|
|
2
|
-
import { BaseObject, DataObject } from '../components';
|
|
1
|
+
import { AbstractAdapter, BackendInterface } from './AbstractAdapter';
|
|
3
2
|
import { BackendRecordType } from './AbstractAdapter';
|
|
4
|
-
import { Query } from './Query';
|
|
5
3
|
import { Filter } from './Filter';
|
|
6
4
|
import { Filters } from './Filters';
|
|
7
5
|
import { SortAndLimit } from './SortAndLimit';
|
|
8
|
-
|
|
6
|
+
import { DataObjectClass } from '../components/types/DataObjectClass';
|
|
7
|
+
export declare class MockAdapter extends AbstractAdapter implements BackendInterface {
|
|
9
8
|
protected static _fixtures: any;
|
|
10
9
|
/**
|
|
11
10
|
* Inject fixtures data to backend adapter
|
|
12
|
-
* Force this backend to be default one
|
|
13
11
|
* @param data BackendRecordType
|
|
14
12
|
*/
|
|
15
13
|
static inject(data: BackendRecordType): void;
|
|
16
|
-
static
|
|
14
|
+
static dao2backend(data: BackendRecordType): Promise<any>;
|
|
15
|
+
static getFixtures(): any[];
|
|
17
16
|
static getFixture(key: string): any;
|
|
18
|
-
create(dataObject:
|
|
19
|
-
read(dataObject:
|
|
20
|
-
update(dataObject:
|
|
21
|
-
delete(dataObject:
|
|
22
|
-
|
|
23
|
-
find(dataObject:
|
|
17
|
+
create(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
18
|
+
read(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
19
|
+
update(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
20
|
+
delete(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
21
|
+
deleteCollection(collection: string, batchSize?: number | undefined): Promise<void>;
|
|
22
|
+
find(dataObject: DataObjectClass<any>, filters?: Filters | Filter[] | undefined, pagination?: SortAndLimit | undefined): Promise<DataObjectClass<any>[]>;
|
|
24
23
|
}
|
|
@@ -10,70 +10,161 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.MockAdapter = void 0;
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
13
|
+
const AbstractAdapter_1 = require("./AbstractAdapter");
|
|
14
|
+
const ObjectUri_1 = require("../components/ObjectUri");
|
|
15
|
+
const faker_1 = require("@faker-js/faker");
|
|
16
|
+
const BackendError_1 = require("./BackendError");
|
|
17
|
+
const NotFoundError_1 = require("./NotFoundError");
|
|
18
|
+
class MockAdapter extends AbstractAdapter_1.AbstractAdapter {
|
|
17
19
|
/**
|
|
18
20
|
* Inject fixtures data to backend adapter
|
|
19
|
-
* Force this backend to be default one
|
|
20
21
|
* @param data BackendRecordType
|
|
21
22
|
*/
|
|
22
23
|
static inject(data) {
|
|
23
|
-
if (data.
|
|
24
|
-
MockAdapter._fixtures[data.
|
|
25
|
-
Core_1.Core.defaultBackend = '@mock';
|
|
24
|
+
if (data.path) {
|
|
25
|
+
MockAdapter._fixtures[data.path] = this.dao2backend(data);
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
|
-
throw new Error(`Can't inject data without
|
|
28
|
+
throw new Error(`Can't inject data without a path`);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
+
static dao2backend(data) {
|
|
32
|
+
const processed = {};
|
|
33
|
+
Object.keys(data).forEach((key) => {
|
|
34
|
+
if (data[key] !== null &&
|
|
35
|
+
typeof data[key] === 'object' &&
|
|
36
|
+
data[key].name === 'BaseObject') {
|
|
37
|
+
processed[key] = data[key].dataObject.uri.toReference();
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
processed[key] = data[key];
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return processed;
|
|
44
|
+
}
|
|
31
45
|
static getFixtures() {
|
|
32
46
|
return MockAdapter._fixtures;
|
|
33
47
|
}
|
|
34
48
|
static getFixture(key) {
|
|
35
49
|
return MockAdapter._fixtures[key];
|
|
36
50
|
}
|
|
37
|
-
create(dataObject
|
|
38
|
-
const uri =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
create(dataObject) {
|
|
52
|
+
const uri = `${this.getCollection(dataObject)}/${faker_1.faker.random.alphaNumeric(12)}`;
|
|
53
|
+
dataObject.uri = new ObjectUri_1.ObjectUri(uri);
|
|
54
|
+
return new Promise((resolve, reject) => {
|
|
55
|
+
try {
|
|
56
|
+
MockAdapter.inject(Object.assign(Object.assign({}, dataObject.toJSON()), { uid: uri, path: uri }));
|
|
57
|
+
resolve(dataObject);
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
reject(new BackendError_1.BackendError(err.message));
|
|
61
|
+
}
|
|
62
|
+
});
|
|
43
63
|
}
|
|
44
64
|
read(dataObject) {
|
|
45
65
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
66
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const path = dataObject.path;
|
|
68
|
+
const data = MockAdapter._fixtures[path];
|
|
69
|
+
if (data === undefined) {
|
|
70
|
+
reject(new NotFoundError_1.NotFoundError(`[Mock] No data for ${path}`));
|
|
71
|
+
}
|
|
72
|
+
this.log(`[DAO] Populating ${dataObject.path}`);
|
|
73
|
+
resolve(yield dataObject.populate(data));
|
|
74
|
+
}));
|
|
53
75
|
});
|
|
54
76
|
}
|
|
55
77
|
update(dataObject) {
|
|
56
|
-
return
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
const path = dataObject.path;
|
|
81
|
+
const data = MockAdapter._fixtures[path];
|
|
82
|
+
if (data === undefined) {
|
|
83
|
+
reject(new NotFoundError_1.NotFoundError(`[Mock] No data for ${path}`));
|
|
84
|
+
}
|
|
85
|
+
this.log(`[DAO] Updating ${dataObject.path}`);
|
|
86
|
+
MockAdapter._fixtures[path] = Object.assign(Object.assign({}, data), dataObject.toJSON());
|
|
87
|
+
resolve(dataObject);
|
|
88
|
+
}));
|
|
89
|
+
});
|
|
57
90
|
}
|
|
58
91
|
delete(dataObject) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
return new Promise((resolve, reject) => {
|
|
94
|
+
const path = dataObject.path;
|
|
95
|
+
const data = MockAdapter._fixtures[path];
|
|
96
|
+
if (data === undefined) {
|
|
97
|
+
reject(new NotFoundError_1.NotFoundError(`[Mock] No data for ${path}`));
|
|
98
|
+
}
|
|
99
|
+
delete MockAdapter._fixtures[dataObject.path];
|
|
100
|
+
dataObject.uri = new ObjectUri_1.ObjectUri();
|
|
101
|
+
resolve(dataObject);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
68
104
|
}
|
|
69
|
-
|
|
105
|
+
deleteCollection(collection, batchSize) {
|
|
70
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
|
|
107
|
+
for (let key in MockAdapter._fixtures) {
|
|
108
|
+
if (key.startsWith(`${collection}/`)) {
|
|
109
|
+
delete MockAdapter._fixtures[key];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return new Promise(() => null);
|
|
72
113
|
});
|
|
73
114
|
}
|
|
74
115
|
find(dataObject, filters = undefined, pagination = undefined) {
|
|
75
116
|
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
-
|
|
117
|
+
const limit = (pagination === null || pagination === void 0 ? void 0 : pagination.limits.batch) || 1e10;
|
|
118
|
+
let result = [];
|
|
119
|
+
const collection = this.getCollection(dataObject);
|
|
120
|
+
// TODO filter only records matchinf collection
|
|
121
|
+
for (let key in MockAdapter.getFixtures()) {
|
|
122
|
+
let keep = true;
|
|
123
|
+
if (key.startsWith(`${collection}/`) && result.length <= limit) {
|
|
124
|
+
const dao = yield dataObject.clone(MockAdapter.getFixture(key));
|
|
125
|
+
if (filters) {
|
|
126
|
+
if (Array.isArray(filters)) {
|
|
127
|
+
filters.forEach((filter) => {
|
|
128
|
+
const prop = dao.get(filter.prop);
|
|
129
|
+
const val = prop.val();
|
|
130
|
+
//console.log(filter.prop, prop)
|
|
131
|
+
if (typeof prop === 'object') {
|
|
132
|
+
if (prop.constructor.name === 'ObjectProperty') {
|
|
133
|
+
if (filter.value instanceof ObjectUri_1.ObjectUri &&
|
|
134
|
+
val &&
|
|
135
|
+
val.ref !== filter.value.path) {
|
|
136
|
+
keep = false;
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else if (prop.constructor.name === 'CollectionProperty') {
|
|
141
|
+
if (filter.value instanceof ObjectUri_1.ObjectUri &&
|
|
142
|
+
prop.val() !== filter.value.path) {
|
|
143
|
+
keep = false;
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
if (prop.val() !== filter.value) {
|
|
150
|
+
keep = false;
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (keep) {
|
|
158
|
+
dao.uri = new ObjectUri_1.ObjectUri(key);
|
|
159
|
+
result.push(dao);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (pagination && pagination.sortings.length > 0) {
|
|
164
|
+
result = result.sort((a, b) => Number(a.val(pagination.sortings[0].prop) >
|
|
165
|
+
b.val(pagination.sortings[0].prop)));
|
|
166
|
+
}
|
|
167
|
+
return result;
|
|
77
168
|
});
|
|
78
169
|
}
|
|
79
170
|
}
|
package/lib/backends/Query.d.ts
CHANGED
|
@@ -3,8 +3,16 @@ import { Limits } from './Limits';
|
|
|
3
3
|
import { Sorting } from './Sorting';
|
|
4
4
|
import { SortAndLimit } from './SortAndLimit';
|
|
5
5
|
import { BackendInterface } from './AbstractAdapter';
|
|
6
|
-
import {
|
|
7
|
-
export declare
|
|
6
|
+
import { AbstractObject } from '../components';
|
|
7
|
+
export declare const AS_OBJECTURIS = "objectUris";
|
|
8
|
+
export declare const AS_DATAOBJECTS = "dataObjects";
|
|
9
|
+
export declare const AS_INSTANCES = "classInstances";
|
|
10
|
+
export declare enum returnAs {
|
|
11
|
+
AS_OBJECTURIS = "objectUris",
|
|
12
|
+
AS_DATAOBJECTS = "dataObjects",
|
|
13
|
+
AS_INSTANCES = "classInstances"
|
|
14
|
+
}
|
|
15
|
+
export declare class Query<T extends typeof AbstractObject> {
|
|
8
16
|
protected _obj: T;
|
|
9
17
|
protected _params: any;
|
|
10
18
|
filters: Filter[];
|
|
@@ -20,5 +28,5 @@ export declare class Query<T extends BaseObject> {
|
|
|
20
28
|
offset(offset?: number): this;
|
|
21
29
|
batch(batch?: number): this;
|
|
22
30
|
get sortAndLimit(): SortAndLimit;
|
|
23
|
-
execute(backend
|
|
31
|
+
execute(as?: returnAs, backend?: BackendInterface): Promise<any>;
|
|
24
32
|
}
|
package/lib/backends/Query.js
CHANGED
|
@@ -9,15 +9,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.Query = void 0;
|
|
12
|
+
exports.Query = exports.returnAs = exports.AS_INSTANCES = exports.AS_DATAOBJECTS = exports.AS_OBJECTURIS = void 0;
|
|
13
13
|
const Filter_1 = require("./Filter");
|
|
14
14
|
const Limits_1 = require("./Limits");
|
|
15
15
|
const Sorting_1 = require("./Sorting");
|
|
16
16
|
const SortAndLimit_1 = require("./SortAndLimit");
|
|
17
|
+
const Core_1 = require("../Core");
|
|
18
|
+
exports.AS_OBJECTURIS = 'objectUris';
|
|
19
|
+
exports.AS_DATAOBJECTS = 'dataObjects';
|
|
20
|
+
exports.AS_INSTANCES = 'classInstances';
|
|
21
|
+
var returnAs;
|
|
22
|
+
(function (returnAs) {
|
|
23
|
+
returnAs["AS_OBJECTURIS"] = "objectUris";
|
|
24
|
+
returnAs["AS_DATAOBJECTS"] = "dataObjects";
|
|
25
|
+
returnAs["AS_INSTANCES"] = "classInstances";
|
|
26
|
+
})(returnAs = exports.returnAs || (exports.returnAs = {}));
|
|
17
27
|
class Query {
|
|
18
28
|
constructor(obj, params = {}) {
|
|
19
29
|
this._obj = obj;
|
|
20
|
-
//Object.keys(params).forEach((key: string) => (obj[key] = params[key]))
|
|
21
30
|
this._params = params; // just in case
|
|
22
31
|
this.filters = [];
|
|
23
32
|
this.sortings = [];
|
|
@@ -63,9 +72,26 @@ class Query {
|
|
|
63
72
|
get sortAndLimit() {
|
|
64
73
|
return new SortAndLimit_1.SortAndLimit(this.sortings, this.limits);
|
|
65
74
|
}
|
|
66
|
-
execute(backend) {
|
|
75
|
+
execute(as = returnAs.AS_DATAOBJECTS, backend = Core_1.Core.getBackend()) {
|
|
67
76
|
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
|
|
77
|
+
try {
|
|
78
|
+
const result = yield backend.query(this);
|
|
79
|
+
switch (as) {
|
|
80
|
+
case exports.AS_DATAOBJECTS:
|
|
81
|
+
return result;
|
|
82
|
+
case exports.AS_OBJECTURIS:
|
|
83
|
+
return yield Promise.all(result.map((dao) => dao.uri));
|
|
84
|
+
case exports.AS_INSTANCES:
|
|
85
|
+
//console.log(this._obj)
|
|
86
|
+
return yield Promise.all(result.map((dao) => Reflect.construct(this._obj, [dao])));
|
|
87
|
+
default:
|
|
88
|
+
throw new Error(`Unknown output mode`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
console.log(err);
|
|
93
|
+
throw err;
|
|
94
|
+
}
|
|
69
95
|
});
|
|
70
96
|
}
|
|
71
97
|
}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DataObjectClass } from '../../components';
|
|
2
|
+
import { UserClass } from '../../components/types/UserClass';
|
|
3
|
+
import * as actions from '../../Backend';
|
|
4
|
+
export interface InjectMetaMiddlewareParams {
|
|
5
|
+
user: UserClass;
|
|
6
|
+
}
|
|
7
|
+
export declare class InjectMetaMiddleware {
|
|
8
|
+
protected _user: UserClass;
|
|
9
|
+
constructor(params: InjectMetaMiddlewareParams);
|
|
10
|
+
execute(dataObject: DataObjectClass<any>, action: actions.BackendActions): void;
|
|
11
|
+
}
|